UNPKG

@larva.io/webcomponents

Version:

Fentrica SmartUnits WebComponents package

5 lines 11.1 kB
/*! * (C) Fentrica http://fentrica.com - Seee LICENSE.md */ function t(t,s){let i;const e={passive:true};function n(){if(i){i()}}function h(i){if(t===i.target){n();s(i)}}if(t){t.addEventListener("webkitTransitionEnd",h,e);t.addEventListener("transitionend",h,e);i=()=>{t.removeEventListener("webkitTransitionEnd",h,e);t.removeEventListener("transitionend",h,e)}}return n}const s=/(^-?\d*\.?\d*)(.*)/;const i=32;const e=400;const n={translateX:1,translateY:1,translateZ:1,scale:1,scaleX:1,scaleY:1,scaleZ:1,rotate:1,rotateX:1,rotateY:1,rotateZ:1,skewX:1,skewY:1,perspective:1};const h=typeof window!=="undefined"?window:{};const o=h.requestAnimationFrame?h.requestAnimationFrame.bind(h):t=>t(Date.now());class r{constructor(){this._hasDur=false;this._hasTweenEffect=false;this._isAsync=false;this._isReverse=false;this._destroyed=false;this.hasChildren=false;this.isPlaying=false;this.hasCompleted=false}addElement(t){if(t!=null){if(t.length>0){for(let s=0;s<t.length;s++){this._addEl(t[s])}}else{this._addEl(t)}}return this}_addEl(t){if(t.nodeType===1){(this._elements=this._elements||[]).push(t)}}add(t){t.parent=this;this.hasChildren=true;(this._childAnimations=this._childAnimations||[]).push(t);return this}getDuration(t){if(t&&t.duration!==undefined){return t.duration}else if(this._duration!==undefined){return this._duration}else if(this.parent){return this.parent.getDuration()}return 0}isRoot(){return!this.parent}duration(t){this._duration=t;return this}getEasing(){if(this._isReverse&&this._reversedEasingName!==undefined){return this._reversedEasingName}return this._easingName!==undefined?this._easingName:this.parent&&this.parent.getEasing()||null}easing(t){this._easingName=t;return this}easingReverse(t){this._reversedEasingName=t;return this}from(t,s){this._addProp("from",t,s);return this}to(t,s,i=false){const e=this._addProp("to",t,s);if(i){this.afterClearStyles([e.trans?"transform":t])}return this}fromTo(t,s,i,e){return this.from(t,s).to(t,i,e)}_getProp(t){if(this._fxProperties){return this._fxProperties.find((s=>s.effectName===t))}return undefined}_addProp(t,i,e){let h=this._getProp(i);if(!h){const t=n[i]===1;h={effectName:i,trans:t,wc:t?"transform":i};(this._fxProperties=this._fxProperties||[]).push(h)}const o={val:e,num:0,effectUnit:""};h[t]=o;if(typeof e==="string"&&e.indexOf(" ")<0){const t=e.match(s);if(t){const s=parseFloat(t[1]);if(!isNaN(s)){o.num=s}o.effectUnit=t[0]!==t[2]?t[2]:""}}else if(typeof e==="number"){o.num=e}return h}beforeAddClass(t){(this._beforeAddClasses=this._beforeAddClasses||[]).push(t);return this}beforeRemoveClass(t){(this._beforeRemoveClasses=this._beforeRemoveClasses||[]).push(t);return this}beforeStyles(t){this._beforeStyles=t;return this}beforeClearStyles(t){this._beforeStyles=this._beforeStyles||{};for(const s of t){this._beforeStyles[s]=""}return this}beforeAddRead(t){(this._readCallbacks=this._readCallbacks||[]).push(t);return this}beforeAddWrite(t){(this._writeCallbacks=this._writeCallbacks||[]).push(t);return this}afterAddClass(t){(this._afterAddClasses=this._afterAddClasses||[]).push(t);return this}afterRemoveClass(t){(this._afterRemoveClasses=this._afterRemoveClasses||[]).push(t);return this}afterStyles(t){this._afterStyles=t;return this}afterClearStyles(t){this._afterStyles=this._afterStyles||{};for(const s of t){this._afterStyles[s]=""}return this}play(t){if(this._destroyed){return}this._isAsync=this._hasDuration(t);this._clearAsync();this._playInit(t);o((()=>{o((()=>{this._playDomInspect(t)}))}))}playAsync(t){return new Promise((s=>{this.onFinish(s,{oneTimeCallback:true,clearExistingCallbacks:true});this.play(t);return this}))}playSync(){if(!this._destroyed){const t={duration:0};this._isAsync=false;this._clearAsync();this._playInit(t);this._playDomInspect(t)}}_playInit(t){this._hasTweenEffect=false;this.isPlaying=true;this.hasCompleted=false;this._hasDur=this.getDuration(t)>i;const s=this._childAnimations;if(s){for(const i of s){i._playInit(t)}}if(this._hasDur){this._progress(0);this._willChange(true)}}_playDomInspect(t){this._beforeAnimation();const s=this.getDuration(t);if(this._isAsync){this._asyncEnd(s,true)}this._playProgress(t);if(this._isAsync&&!this._destroyed){o((()=>{this._playToStep(1)}))}}_playProgress(t){const s=this._childAnimations;if(s){for(const i of s){i._playProgress(t)}}if(this._hasDur){this._setTrans(this.getDuration(t),false)}else{this._progress(1);this._setAfterStyles();this._didFinish(true)}}_playToStep(t){if(!this._destroyed){const s=this._childAnimations;if(s){for(const i of s){i._playToStep(t)}}if(this._hasDur){this._progress(t)}}}_asyncEnd(s,i){const n=this;function h(){n._clearAsync();n._playEnd();n._didFinishAll(i,true,false)}function o(){console.debug("Animation onTransitionFallback, CSS onTransitionEnd did not fire!");n._timerId=undefined;n._clearAsync();n._playEnd(i?1:0);n._didFinishAll(i,true,false)}n._unregisterTrnsEnd=t(n._transEl(),h);n._timerId=setTimeout(o,s+e)}_playEnd(t){const s=this._childAnimations;if(s){for(const i of s){i._playEnd(t)}}if(this._hasDur){if(t!==undefined){this._setTrans(0,true);this._progress(t)}this._setAfterStyles();this._willChange(false)}}_hasDuration(t){if(this.getDuration(t)>i){return true}const s=this._childAnimations;if(s){for(const i of s){if(i._hasDuration(t)){return true}}}return false}_hasDomReads(){if(this._readCallbacks&&this._readCallbacks.length>0){return true}const t=this._childAnimations;if(t){for(const s of t){if(s._hasDomReads()){return true}}}return false}stop(t=1){this._clearAsync();this._hasDur=true;this._playEnd(t)}_clearAsync(){if(this._unregisterTrnsEnd){this._unregisterTrnsEnd()}if(this._timerId){clearTimeout(this._timerId)}this._timerId=this._unregisterTrnsEnd=undefined}_progress(t){let s;const i=this._elements;const e=this._fxProperties;if(!i||i.length===0||!e||this._destroyed){return}if(this._isReverse){t=1-t}let n=0;let h=0;let o="";let r;for(n=0;n<e.length;n++){r=e[n];if(r.from&&r.to){const e=r.from.num;const n=r.to.num;const f=e!==n;if(f){this._hasTweenEffect=true}if(t===0){s=r.from.val}else if(t===1){s=r.to.val}else if(f){const i=(n-e)*t+e;const h=r.to.effectUnit;s=i+h}if(s!==null){const t=r.effectName;if(r.trans){o+=t+"("+s+") "}else{for(h=0;h<i.length;h++){i[h].style.setProperty(t,s)}}}}}if(o.length>0){if(!this._isReverse&&t!==1||this._isReverse&&t!==0){o+="translateZ(0px)"}for(n=0;n<i.length;n++){i[n].style.setProperty("transform",o)}}}_setTrans(t,s){const i=this._elements;if(!i||i.length===0||!this._fxProperties){return}const e=s?"linear":this.getEasing();const n=t+"ms";for(const{style:s}of i){if(t>0){s.transitionDuration=n;if(e!==null){s.transitionTimingFunction=e}}else{s.transitionDuration="0"}}}_beforeAnimation(){this._fireBeforeReadFunc();this._fireBeforeWriteFunc();this._setBeforeStyles()}_setBeforeStyles(){const t=this._childAnimations;if(t){for(const s of t){s._setBeforeStyles()}}const s=this._elements;if(!s||s.length===0||this._isReverse){return}const i=this._beforeAddClasses;const e=this._beforeRemoveClasses;for(const t of s){const s=t.classList;if(i){for(const t of i){s.add(t)}}if(e){for(const t of e){s.remove(t)}}if(this._beforeStyles){for(const[s,i]of Object.entries(this._beforeStyles)){t.style.setProperty(s,i)}}}}_fireBeforeReadFunc(){const t=this._childAnimations;if(t){for(const s of t){s._fireBeforeReadFunc()}}const s=this._readCallbacks;if(s){for(const t of s){t()}}}_fireBeforeWriteFunc(){const t=this._childAnimations;if(t){for(const s of t){s._fireBeforeWriteFunc()}}const s=this._writeCallbacks;if(s){for(const t of s){t()}}}_setAfterStyles(){const t=this._elements;if(!t){return}for(const s of t){const t=s.classList;s.style.transitionDuration=s.style.transitionTimingFunction="";if(this._isReverse){const i=this._beforeAddClasses;if(i){for(const s of i){t.remove(s)}}const e=this._beforeRemoveClasses;if(e){for(const s of e){t.add(s)}}const n=this._beforeStyles;if(n){for(const t of Object.keys(n)){s.style.removeProperty(t)}}}else{const i=this._afterAddClasses;if(i){for(const s of i){t.add(s)}}const e=this._afterRemoveClasses;if(e){for(const s of e){t.remove(s)}}const n=this._afterStyles;if(n){for(const[t,i]of Object.entries(n)){s.style.setProperty(t,i)}}}}}_willChange(t){let s;const i=this._fxProperties;let e;if(t&&i){s=[];for(const t of i){const i=t.wc;if(i==="webkitTransform"){s.push("transform","-webkit-transform")}else if(i!==undefined){s.push(i)}}e=s.join(",")}else{e=""}const n=this._elements;if(n){for(const t of n){t.style.setProperty("will-change",e)}}}progressStart(){this._clearAsync();this._beforeAnimation();this._progressStart()}_progressStart(){const t=this._childAnimations;if(t){for(const s of t){s._progressStart()}}this._setTrans(0,true);this._willChange(true)}progressStep(t){t=Math.min(1,Math.max(0,t));const s=this._childAnimations;if(s){for(const i of s){i.progressStep(t)}}this._progress(t)}progressEnd(t,s,i=-1){if(this._isReverse){s=1-s}const e=t?1:0;const n=Math.abs(s-e);if(i<0){i=this._duration||0}else if(n<.05){i=0}this._isAsync=i>30;this._progressEnd(t,e,i,this._isAsync);if(this._isAsync){this._asyncEnd(i,t);if(!this._destroyed){o((()=>{this._playToStep(e)}))}}}_progressEnd(t,s,i,e){const n=this._childAnimations;if(n){for(const h of n){h._progressEnd(t,s,i,e)}}if(!e){this._progress(s);this._willChange(false);this._setAfterStyles();this._didFinish(t)}else{this.isPlaying=true;this.hasCompleted=false;this._hasDur=true;this._willChange(true);this._setTrans(i,false)}}onFinish(t,s){if(s&&s.clearExistingCallbacks){this._onFinishCallbacks=this._onFinishOneTimeCallbacks=undefined}if(s&&s.oneTimeCallback){this._onFinishOneTimeCallbacks=this._onFinishOneTimeCallbacks||[];this._onFinishOneTimeCallbacks.push(t)}else{this._onFinishCallbacks=this._onFinishCallbacks||[];this._onFinishCallbacks.push(t)}return this}_didFinishAll(t,s,i){const e=this._childAnimations;if(e){for(const n of e){n._didFinishAll(t,s,i)}}if(s&&this._isAsync||i&&!this._isAsync){this._didFinish(t)}}_didFinish(t){this.isPlaying=false;this.hasCompleted=t;if(this._onFinishCallbacks){for(const t of this._onFinishCallbacks){t(this)}}if(this._onFinishOneTimeCallbacks){for(const t of this._onFinishOneTimeCallbacks){t(this)}this._onFinishOneTimeCallbacks.length=0}}reverse(t=true){const s=this._childAnimations;if(s){for(const i of s){i.reverse(t)}}this._isReverse=!!t;return this}destroy(){this._didFinish(false);this._destroyed=true;const t=this._childAnimations;if(t){for(const s of t){s.destroy()}}this._clearAsync();if(this._elements){this._elements.length=0}if(this._readCallbacks){this._readCallbacks.length=0}if(this._writeCallbacks){this._writeCallbacks.length=0}this.parent=undefined;if(this._childAnimations){this._childAnimations.length=0}if(this._onFinishCallbacks){this._onFinishCallbacks.length=0}if(this._onFinishOneTimeCallbacks){this._onFinishOneTimeCallbacks.length=0}}_transEl(){const t=this._childAnimations;if(t){for(const s of t){const t=s._transEl();if(t){return t}}}return this._hasTweenEffect&&this._hasDur&&this._elements!==undefined&&this._elements.length>0?this._elements[0]:null}}function f(t,s,i){if(t){return t(r,s,i)}return Promise.resolve(new r)}export{f as create}; //# sourceMappingURL=p-Beh6uSne.js.map