@tindtechnologies/universalviewer
Version:
The Universal Viewer is a community-developed open source project on a mission to help you share your 📚📜📰📽️📻🗿 with the 🌎
2 lines (1 loc) • 8.81 kB
JavaScript
import{c as w}from"./chunk-MYFOSXPU.js";import{e as g}from"./chunk-4DAZ7WDM.js";import{a as C,e as d,f as E,i as _,l as F,o as x}from"./chunk-VNJCZCB4.js";import"./chunk-L67DAW3A.js";var H=function(s,i,t,n){return new(t||(t=Promise))(function(o,e){function a(r){try{h(n.next(r))}catch(l){e(l)}}function c(r){try{h(n.throw(r))}catch(l){e(l)}}function h(r){r.done?o(r.value):new t(function(l){l(r.value)}).then(a,c)}h((n=n.apply(s,i||[])).next())})},A=function(s,i){var t={label:0,sent:function(){if(e[0]&1)throw e[1];return e[1]},trys:[],ops:[]},n,o,e,a;return a={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function c(r){return function(l){return h([r,l])}}function h(r){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,o&&(e=r[0]&2?o.return:r[0]?o.throw||((e=o.return)&&e.call(o),0):o.next)&&!(e=e.call(o,r[1])).done)return e;switch(o=0,e&&(r=[r[0]&2,e.value]),r[0]){case 0:case 1:e=r;break;case 4:return t.label++,{value:r[1],done:!1};case 5:t.label++,o=r[1],r=[0];continue;case 7:r=t.ops.pop(),t.trys.pop();continue;default:if(e=t.trys,!(e=e.length>0&&e[e.length-1])&&(r[0]===6||r[0]===2)){t=0;continue}if(r[0]===3&&(!e||r[1]>e[0]&&r[1]<e[3])){t.label=r[1];break}if(r[0]===6&&t.label<e[1]){t.label=e[1],e=r;break}if(e&&t.label<e[2]){t.label=e[2],t.ops.push(r);break}e[2]&&t.ops.pop(),t.trys.pop();continue}r=i.call(s,t)}catch(l){r=[6,l],o=0}finally{n=e=0}if(r[0]&5)throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}},R=function(){function s(i){C(this,i),this.optHeight=0,this.rotateFactor=0,this.scaleFactor=1,this.velocity=0,this.y=0,this.noAnimate=!0,this.ionPickerColChange=_(this,"ionPickerColChange",7)}return s.prototype.colChanged=function(){this.refresh()},s.prototype.connectedCallback=function(){return H(this,void 0,void 0,function(){var i,t,n,o,e=this;return A(this,function(a){switch(a.label){case 0:return i=0,t=.81,n=x(this),n==="ios"&&(i=-.46,t=1),this.rotateFactor=i,this.scaleFactor=t,o=this,[4,import("./index-14bae62d-RHNU7WUM.js")];case 1:return o.gesture=a.sent().createGesture({el:this.el,gestureName:"picker-swipe",gesturePriority:100,threshold:0,onStart:function(c){return e.onStart(c)},onMove:function(c){return e.onMove(c)},onEnd:function(c){return e.onEnd(c)}}),this.gesture.setDisabled(!1),this.tmrId=setTimeout(function(){e.noAnimate=!1,e.refresh(!0)},250),[2]}})})},s.prototype.componentDidLoad=function(){var i=this.optsEl;i&&(this.optHeight=i.firstElementChild?i.firstElementChild.clientHeight:0),this.refresh()},s.prototype.disconnectedCallback=function(){cancelAnimationFrame(this.rafId),clearTimeout(this.tmrId),this.gesture&&(this.gesture.destroy(),this.gesture=void 0)},s.prototype.emitColChange=function(){this.ionPickerColChange.emit(this.col)},s.prototype.setSelected=function(i,t){var n=i>-1?-(i*this.optHeight):0;this.velocity=0,cancelAnimationFrame(this.rafId),this.update(n,t,!0),this.emitColChange()},s.prototype.update=function(i,t,n){if(this.optsEl){for(var o=0,e=0,a=this,c=a.col,h=a.rotateFactor,r=c.selectedIndex=this.indexForY(-i),l=t===0?"":t+"ms",S="scale("+this.scaleFactor+")",y=this.optsEl.children,f=0;f<y.length;f++){var v=y[f],p=c.options[f],b=f*this.optHeight+i,u="";if(h!==0){var k=b*h;Math.abs(k)<=90?(o=0,e=90,u="rotateX("+k+"deg) "):o=-9999}else e=0,o=b;var m=r===f;u+="translate3d(0px,"+o+"px,"+e+"px) ",this.scaleFactor!==1&&!m&&(u+=S),this.noAnimate?(p.duration=0,v.style.transitionDuration=""):t!==p.duration&&(p.duration=t,v.style.transitionDuration=l),u!==p.transform&&(p.transform=u,v.style.transform=u),m!==p.selected&&(p.selected=m,m?v.classList.add(I):v.classList.remove(I))}this.col.prevSelected=r,n&&(this.y=i),this.lastIndex!==r&&(w(),this.lastIndex=r)}},s.prototype.decelerate=function(){var i=this;if(this.velocity!==0){this.velocity*=P,this.velocity=this.velocity>0?Math.max(this.velocity,1):Math.min(this.velocity,-1);var t=this.y+this.velocity;t>this.minY?(t=this.minY,this.velocity=0):t<this.maxY&&(t=this.maxY,this.velocity=0),this.update(t,0,!0);var n=Math.round(t)%this.optHeight!==0||Math.abs(this.velocity)>1;n?this.rafId=requestAnimationFrame(function(){return i.decelerate()}):(this.velocity=0,this.emitColChange())}else if(this.y%this.optHeight!==0){var o=Math.abs(this.y%this.optHeight);this.velocity=o>this.optHeight/2?1:-1,this.decelerate()}},s.prototype.indexForY=function(i){return Math.min(Math.max(Math.abs(Math.round(i/this.optHeight)),0),this.col.options.length-1)},s.prototype.onStart=function(i){i.event.preventDefault(),i.event.stopPropagation(),cancelAnimationFrame(this.rafId);for(var t=this.col.options,n=t.length-1,o=0,e=0;e<t.length;e++)t[e].disabled||(n=Math.min(n,e),o=Math.max(o,e));this.minY=-(n*this.optHeight),this.maxY=-(o*this.optHeight)},s.prototype.onMove=function(i){i.event.preventDefault(),i.event.stopPropagation();var t=this.y+i.deltaY;t>this.minY?(t=Math.pow(t,.8),this.bounceFrom=t):t<this.maxY?(t+=Math.pow(this.maxY-t,.9),this.bounceFrom=t):this.bounceFrom=0,this.update(t,0,!1)},s.prototype.onEnd=function(i){if(this.bounceFrom>0){this.update(this.minY,100,!0),this.emitColChange();return}else if(this.bounceFrom<0){this.update(this.maxY,100,!0),this.emitColChange();return}if(this.velocity=g(-M,i.velocityY*23,M),this.velocity===0&&i.deltaY===0){var t=i.event.target.closest(".picker-opt");t&&t.hasAttribute("opt-index")&&this.setSelected(parseInt(t.getAttribute("opt-index"),10),Y)}else this.y+=i.deltaY,this.decelerate()},s.prototype.refresh=function(i){for(var t=this.col.options.length-1,n=0,o=this.col.options,e=0;e<o.length;e++)o[e].disabled||(t=Math.min(t,e),n=Math.max(n,e));if(this.velocity===0){var a=g(t,this.col.selectedIndex||0,n);if(this.col.prevSelected!==a||i){var c=a*this.optHeight*-1;this.velocity=0,this.update(c,Y,!0)}}},s.prototype.render=function(){var i,t=this,n=this.col,o="button",e=x(this);return d(E,{class:(i={},i[e]=!0,i["picker-col"]=!0,i["picker-opts-left"]=this.col.align==="left",i["picker-opts-right"]=this.col.align==="right",i),style:{"max-width":this.col.columnWidth}},n.prefix&&d("div",{class:"picker-prefix",style:{width:n.prefixWidth}},n.prefix),d("div",{class:"picker-opts",style:{maxWidth:n.optionsWidth},ref:function(a){return t.optsEl=a}},n.options.map(function(a,c){return d(o,{type:"button",class:{"picker-opt":!0,"picker-opt-disabled":!!a.disabled},"opt-index":c},a.text)})),n.suffix&&d("div",{class:"picker-suffix",style:{width:n.suffixWidth}},n.suffix))},Object.defineProperty(s.prototype,"el",{get:function(){return F(this)},enumerable:!0,configurable:!0}),Object.defineProperty(s,"watchers",{get:function(){return{col:["colChanged"]}},enumerable:!0,configurable:!0}),Object.defineProperty(s,"style",{get:function(){return".picker-col{display:-ms-flexbox;display:flex;position:relative;-ms-flex:1;flex:1;-ms-flex-pack:center;justify-content:center;height:100%;-webkit-box-sizing:content-box;box-sizing:content-box;contain:content}.picker-opts{position:relative;-ms-flex:1;flex:1;max-width:100%}.picker-opt{left:0;top:0;display:block;position:absolute;width:100%;border:0;text-align:center;text-overflow:ellipsis;white-space:nowrap;contain:strict;overflow:hidden;will-change:transform}:host-context([dir=rtl]) .picker-opt,[dir=rtl] .picker-opt{left:unset;right:unset;right:0}.picker-opt.picker-opt-disabled{pointer-events:none}.picker-opt-disabled{opacity:0}.picker-opts-left{-ms-flex-pack:start;justify-content:flex-start}.picker-opts-right{-ms-flex-pack:end;justify-content:flex-end}.picker-opt:active,.picker-opt:focus{outline:none}.picker-prefix{text-align:end}.picker-prefix,.picker-suffix{position:relative;-ms-flex:1;flex:1;white-space:nowrap}.picker-suffix{text-align:start}.picker-col{padding-left:8px;padding-right:8px;padding-top:0;padding-bottom:0;-webkit-transform-style:preserve-3d;transform-style:preserve-3d}@supports ((-webkit-margin-start:0) or (margin-inline-start:0)) or (-webkit-margin-start:0){.picker-col{padding-left:unset;padding-right:unset;-webkit-padding-start:8px;padding-inline-start:8px;-webkit-padding-end:8px;padding-inline-end:8px}}.picker-opts,.picker-prefix,.picker-suffix{top:77px;-webkit-transform-style:preserve-3d;transform-style:preserve-3d;color:inherit;font-size:22px;line-height:42px;pointer-events:none}.picker-opt{margin-left:0;margin-right:0;margin-top:0;margin-bottom:0;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;height:43px;-webkit-transition-timing-function:ease-out;transition-timing-function:ease-out;background:transparent;color:inherit;font-size:22px;line-height:42px;-webkit-backface-visibility:hidden;backface-visibility:hidden;pointer-events:auto}.picker-opt.picker-opt-selected,.picker-prefix,.picker-suffix{color:var(--ion-color-primary,#3880ff)}"},enumerable:!0,configurable:!0}),s}(),I="picker-opt-selected",P=.97,M=90,Y=150;export{R as ion_picker_column};