motion-dom 12.6.1 → 12.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +381 -236
- package/dist/es/animation/{controls/BaseGroup.mjs → GroupAnimation.mjs} +4 -5
- package/dist/es/animation/GroupAnimationWithThen.mjs +9 -0
- package/dist/es/animation/NativeAnimation.mjs +159 -0
- package/dist/es/animation/generators/utils/is-generator.mjs +1 -1
- package/dist/es/animation/keyframes/get-final.mjs +12 -0
- package/dist/es/animation/keyframes/hydrate.mjs +26 -0
- package/dist/es/animation/utils/get-value-transition.mjs +3 -5
- package/dist/es/animation/waapi/easing/cubic-bezier.mjs +3 -0
- package/dist/es/animation/waapi/easing/is-supported.mjs +14 -0
- package/dist/es/animation/waapi/easing/map-easing.mjs +26 -0
- package/dist/es/animation/waapi/easing/supported.mjs +15 -0
- package/dist/es/animation/waapi/start-waapi-animation.mjs +37 -0
- package/dist/es/animation/waapi/supports/partial-keyframes.mjs +13 -0
- package/dist/es/animation/waapi/utils/apply-generator.mjs +14 -0
- package/dist/es/animation/waapi/utils/linear.mjs +1 -3
- package/dist/es/animation/waapi/utils/px-values.mjs +39 -0
- package/dist/es/gestures/press/index.mjs +1 -1
- package/dist/es/index.mjs +8 -3
- package/dist/es/render/dom/style.mjs +15 -0
- package/dist/es/utils/resolve-elements.mjs +2 -7
- package/dist/es/utils/supports/flags.mjs +1 -3
- package/dist/es/utils/supports/memo.mjs +1 -1
- package/dist/es/value/index.mjs +1 -1
- package/dist/es/view/queue.mjs +1 -2
- package/dist/es/view/start.mjs +22 -17
- package/dist/es/view/utils/get-view-animations.mjs +1 -2
- package/dist/index.d.ts +90 -43
- package/dist/motion-dom.dev.js +381 -236
- package/dist/motion-dom.js +1 -1
- package/package.json +3 -3
- package/dist/es/animation/controls/Group.mjs +0 -13
- package/dist/es/animation/waapi/NativeAnimationControls.mjs +0 -83
- package/dist/es/animation/waapi/PseudoAnimation.mjs +0 -15
- package/dist/es/animation/waapi/utils/convert-options.mjs +0 -55
- package/dist/es/animation/waapi/utils/easing.mjs +0 -44
package/dist/motion-dom.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("motion-utils")):"function"==typeof define&&define.amd?define(["exports","motion-utils"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).MotionDom={},e.MotionUtils)}(this,(function(e,t){"use strict";const n=t.memo(()=>void 0!==window.ScrollTimeline);class i{constructor(e){this.stop=()=>this.runAll("stop"),this.animations=e.filter(Boolean)}get finished(){return Promise.all(this.animations.map(e=>"finished"in e?e.finished:e))}getAll(e){return this.animations[0][e]}setAll(e,t){for(let n=0;n<this.animations.length;n++)this.animations[n][e]=t}attachTimeline(e,t){const i=this.animations.map(i=>n()&&i.attachTimeline?i.attachTimeline(e):"function"==typeof t?t(i):void 0);return()=>{i.forEach((e,t)=>{e&&e(),this.animations[t].stop()})}}get time(){return this.getAll("time")}set time(e){this.setAll("time",e)}get speed(){return this.getAll("speed")}set speed(e){this.setAll("speed",e)}get startTime(){return this.getAll("startTime")}get duration(){let e=0;for(let t=0;t<this.animations.length;t++)e=Math.max(e,this.animations[t].duration);return e}runAll(e){this.animations.forEach(t=>t[e]())}flatten(){this.runAll("flatten")}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}function a(e,t){return e?e[t]||e.default||e:void 0}function s(e){let t=0;let n=e.next(t);for(;!n.done&&t<2e4;)t+=50,n=e.next(t);return t>=2e4?1/0:t}function o(e,n=100,i){const a=i({...e,keyframes:[0,n]}),o=Math.min(s(a),2e4);return{type:"keyframes",ease:e=>a.next(o*e).value/n,duration:t.millisecondsToSeconds(o)}}function r(e){return"function"==typeof e}function c(e,t){e.timeline=t,e.onfinish=null}class u{constructor(e){this.animation=e}get duration(){var e,n,i;const a=(null===(n=null===(e=this.animation)||void 0===e?void 0:e.effect)||void 0===n?void 0:n.getComputedTiming().duration)||(null===(i=this.options)||void 0===i?void 0:i.duration)||300;return t.millisecondsToSeconds(Number(a))}get time(){var e;return this.animation?t.millisecondsToSeconds((null===(e=this.animation)||void 0===e?void 0:e.currentTime)||0):0}set time(e){this.animation&&(this.animation.currentTime=t.secondsToMilliseconds(e))}get speed(){return this.animation?this.animation.playbackRate:1}set speed(e){this.animation&&(this.animation.playbackRate=e)}get state(){return this.animation?this.animation.playState:"finished"}get startTime(){return this.animation?this.animation.startTime:null}get finished(){return this.animation?this.animation.finished:Promise.resolve()}play(){this.animation&&this.animation.play()}pause(){this.animation&&this.animation.pause()}stop(){this.animation&&"idle"!==this.state&&"finished"!==this.state&&(this.animation.commitStyles&&this.animation.commitStyles(),this.cancel())}flatten(){var e,t;this.animation&&(null===(e=this.options)||void 0===e?void 0:e.allowFlatten)&&(null===(t=this.animation.effect)||void 0===t||t.updateTiming({easing:"linear"}))}attachTimeline(e){return this.animation&&c(this.animation,e),t.noop}complete(){this.animation&&this.animation.finish()}cancel(){try{this.animation&&this.animation.cancel()}catch(e){}}}const l=e=>Array.isArray(e)&&"number"==typeof e[0],d={linearEasing:void 0};function m(e,n){const i=t.memo(e);return()=>{var e;return null!==(e=d[n])&&void 0!==e?e:i()}}const h=m(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(e){return!1}return!0},"linearEasing"),p=(e,n,i=10)=>{let a="";const s=Math.max(Math.round(n/i),2);for(let n=0;n<s;n++)a+=e(t.progress(0,s-1,n))+", ";return`linear(${a.substring(0,a.length-2)})`};const f=([e,t,n,i])=>`cubic-bezier(${e}, ${t}, ${n}, ${i})`,v={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:f([0,.65,.55,1]),circOut:f([.55,0,1,.45]),backIn:f([.31,.01,.66,-.59]),backOut:f([.33,1.53,.69,.99])};function y(e,t){return e?"function"==typeof e&&h()?p(e,t):l(e)?f(e):Array.isArray(e)?e.map(e=>y(e,t)||v.easeOut):v[e]:void 0}const g=["read","resolveKeyframes","update","preRender","render","postRender"],w={value:null,addProjectionMetrics:null};function T(e,n){let i=!1,a=!0;const s={delta:0,timestamp:0,isProcessing:!1},o=()=>i=!0,r=g.reduce((e,t)=>(e[t]=function(e,t){let n=new Set,i=new Set,a=!1,s=!1;const o=new WeakSet;let r={delta:0,timestamp:0,isProcessing:!1},c=0;function u(t){o.has(t)&&(l.schedule(t),e()),c++,t(r)}const l={schedule:(e,t=!1,s=!1)=>{const r=s&&a?n:i;return t&&o.add(e),r.has(e)||r.add(e),e},cancel:e=>{i.delete(e),o.delete(e)},process:e=>{r=e,a?s=!0:(a=!0,[n,i]=[i,n],n.forEach(u),t&&w.value&&w.value.frameloop[t].push(c),c=0,n.clear(),a=!1,s&&(s=!1,l.process(e)))}};return l}(o,n?t:void 0),e),{}),{read:c,resolveKeyframes:u,update:l,preRender:d,render:m,postRender:h}=r,p=()=>{const o=t.MotionGlobalConfig.useManualTiming?s.timestamp:performance.now();i=!1,t.MotionGlobalConfig.useManualTiming||(s.delta=a?1e3/60:Math.max(Math.min(o-s.timestamp,40),1)),s.timestamp=o,s.isProcessing=!0,c.process(s),u.process(s),l.process(s),d.process(s),m.process(s),h.process(s),s.isProcessing=!1,i&&n&&(a=!1,e(p))};return{schedule:g.reduce((t,n)=>{const o=r[n];return t[n]=(t,n=!1,r=!1)=>(i||(i=!0,a=!0,s.isProcessing||e(p)),o.schedule(t,n,r)),t},{}),cancel:e=>{for(let t=0;t<g.length;t++)r[g[t]].cancel(e)},state:s,steps:r}}const{schedule:E,cancel:A,state:P,steps:b}=T("undefined"!=typeof requestAnimationFrame?requestAnimationFrame:t.noop,!0),{schedule:x,cancel:M}=T(queueMicrotask,!1);let k;function S(){k=void 0}const L={now:()=>(void 0===k&&L.set(P.isProcessing||t.MotionGlobalConfig.useManualTiming?P.timestamp:performance.now()),k),set:e=>{k=e,queueMicrotask(S)}},V={x:!1,y:!1};function C(){return V.x||V.y}function R(e,t,n){var i;if(e instanceof EventTarget)return[e];if("string"==typeof e){let a=document;t&&(a=t.current);const s=null!==(i=null==n?void 0:n[e])&&void 0!==i?i:a.querySelectorAll(e);return s?Array.from(s):[]}return Array.from(e)}function j(e,t){const n=R(e),i=new AbortController;return[n,{passive:!0,...t,signal:i.signal},()=>i.abort()]}function F(e){return!("touch"===e.pointerType||C())}const D=(e,t)=>!!t&&(e===t||D(e,t.parentElement)),N=e=>"mouse"===e.pointerType?"number"!=typeof e.button||e.button<=0:!1!==e.isPrimary,O=new Set(["BUTTON","INPUT","SELECT","TEXTAREA","A"]);const G=new WeakSet;function B(e){return t=>{"Enter"===t.key&&e(t)}}function I(e,t){e.dispatchEvent(new PointerEvent("pointer"+t,{isPrimary:!0,bubbles:!0}))}function $(e){return N(e)&&!C()}const q={layout:0,mainThread:0,waapi:0};function K(){const{value:e}=w;null!==e?(e.frameloop.rate.push(P.delta),e.animations.mainThread.push(q.mainThread),e.animations.waapi.push(q.waapi),e.animations.layout.push(q.layout)):A(K)}function U(e){return e.reduce((e,t)=>e+t,0)/e.length}function W(e,t=U){return 0===e.length?{min:0,max:0,avg:0}:{min:Math.min(...e),max:Math.max(...e),avg:t(e)}}const z=e=>Math.round(1e3/e);function H(){w.value=null,w.addProjectionMetrics=null}function X(){const{value:e}=w;if(!e)throw new Error("Stats are not being measured");H(),A(K);const t={frameloop:{rate:W(e.frameloop.rate),read:W(e.frameloop.read),resolveKeyframes:W(e.frameloop.resolveKeyframes),update:W(e.frameloop.update),preRender:W(e.frameloop.preRender),render:W(e.frameloop.render),postRender:W(e.frameloop.postRender)},animations:{mainThread:W(e.animations.mainThread),waapi:W(e.animations.waapi),layout:W(e.animations.layout)},layoutProjection:{nodes:W(e.layoutProjection.nodes),calculatedTargetDeltas:W(e.layoutProjection.calculatedTargetDeltas),calculatedProjections:W(e.layoutProjection.calculatedProjections)}},{rate:n}=t.frameloop;return n.min=z(n.min),n.max=z(n.max),n.avg=z(n.avg),[n.min,n.max]=[n.max,n.min],t}const J={current:void 0};class Q{constructor(e,t={}){this.version="12.6.1",this.canTrackVelocity=null,this.events={},this.updateAndNotify=(e,t=!0)=>{const n=L.now();this.updatedAt!==n&&this.setPrevFrameValue(),this.prev=this.current,this.setCurrent(e),this.current!==this.prev&&this.events.change&&this.events.change.notify(this.current),t&&this.events.renderRequest&&this.events.renderRequest.notify(this.current)},this.hasAnimated=!1,this.setCurrent(e),this.owner=t.owner}setCurrent(e){var t;this.current=e,this.updatedAt=L.now(),null===this.canTrackVelocity&&void 0!==e&&(this.canTrackVelocity=(t=this.current,!isNaN(parseFloat(t))))}setPrevFrameValue(e=this.current){this.prevFrameValue=e,this.prevUpdatedAt=this.updatedAt}onChange(e){return this.on("change",e)}on(e,n){this.events[e]||(this.events[e]=new t.SubscriptionManager);const i=this.events[e].add(n);return"change"===e?()=>{i(),E.read(()=>{this.events.change.getSize()||this.stop()})}:i}clearListeners(){for(const e in this.events)this.events[e].clear()}attach(e,t){this.passiveEffect=e,this.stopPassiveEffect=t}set(e,t=!0){t&&this.passiveEffect?this.passiveEffect(e,this.updateAndNotify):this.updateAndNotify(e,t)}setWithVelocity(e,t,n){this.set(t),this.prev=void 0,this.prevFrameValue=e,this.prevUpdatedAt=this.updatedAt-n}jump(e,t=!0){this.updateAndNotify(e),this.prev=e,this.prevUpdatedAt=this.prevFrameValue=void 0,t&&this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}get(){return J.current&&J.current.push(this),this.current}getPrevious(){return this.prev}getVelocity(){const e=L.now();if(!this.canTrackVelocity||void 0===this.prevFrameValue||e-this.updatedAt>30)return 0;const n=Math.min(this.updatedAt-this.prevUpdatedAt,30);return t.velocityPerSecond(parseFloat(this.current)-parseFloat(this.prevFrameValue),n)}start(e){return this.stop(),new Promise(t=>{this.hasAnimated=!0,this.animation=e(t),this.events.animationStart&&this.events.animationStart.notify()}).then(()=>{this.events.animationComplete&&this.events.animationComplete.notify(),this.clearAnimation()})}stop(){this.animation&&(this.animation.stop(),this.events.animationCancel&&this.events.animationCancel.notify()),this.clearAnimation()}isAnimating(){return!!this.animation}clearAnimation(){delete this.animation}destroy(){this.clearListeners(),this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}}function Y(e){var n;if(r(e.type)){const n=o(e,100,e.type);e.ease=h()?n.ease:"easeOut",e.duration=t.secondsToMilliseconds(n.duration),e.type="keyframes"}else e.duration=t.secondsToMilliseconds(null!==(n=e.duration)&&void 0!==n?n:.3),e.ease=e.ease||"easeOut"}class Z extends u{constructor(e,n,i,a,s){const o=function(e,n,i){var a;const s={},o={fill:"both",easing:"linear",composite:"replace"};o.delay=t.secondsToMilliseconds(null!==(a=i.delay)&&void 0!==a?a:0),Y(i),o.duration=i.duration;const{ease:r,times:c}=i;c&&(s.offset=c),s[e]=n;const u=y(r,i.duration);return Array.isArray(u)?s.easing=u:o.easing=u,{keyframes:s,options:o}}(i,a,s);super(e.animate(o.keyframes,{pseudoElement:n,...o.options}))}}function _(e){return"layout"===e?"group":"enter"===e||"new"===e?"new":"exit"===e||"old"===e?"old":"group"}let ee={},te=null;const ne=(e,t)=>{ee[e]=t},ie=()=>{te||(te=document.createElement("style"),te.id="motion-view");let e="";for(const t in ee){const n=ee[t];e+=t+" {\n";for(const[t,i]of Object.entries(n))e+=` ${t}: ${i};\n`;e+="}\n"}te.textContent=e,document.head.appendChild(te),ee={}},ae=()=>{te&&te.parentElement&&te.parentElement.removeChild(te)};function se(e){const t=e.match(/::view-transition-(old|new|group|image-pair)\((.*?)\)/);return t?{layer:t[2],type:t[1]}:null}function oe(e){var t;const{effect:n}=e;return!!n&&(n.target===document.documentElement&&(null===(t=n.pseudoElement)||void 0===t?void 0:t.startsWith("::view-transition")))}const re=["layout","enter","exit","new","old"];function ce(e){const{update:n,targets:s,options:o}=e;if(!document.startViewTransition)return new Promise(async e=>{await n(),e(new i([]))});(function(e,t){return t.has(e)&&Object.keys(t.get(e)).length>0})("root",s)||ne(":root",{"view-transition-name":"none"}),ne("::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*)",{"animation-timing-function":"linear !important"}),ie();const r=document.startViewTransition(async()=>{await n()});return r.finished.finally(()=>{ae()}),new Promise(e=>{r.ready.then(()=>{var n;const r=document.getAnimations().filter(oe),c=[];s.forEach((e,t)=>{for(const n of re){if(!e[n])continue;const{keyframes:i,options:s}=e[n];for(let[e,r]of Object.entries(i)){if(!r)continue;const i={...a(o,e),...a(s,e)},u=_(n);if("opacity"===e&&!Array.isArray(r)){r=["new"===u?0:1,r]}"function"==typeof i.delay&&(i.delay=i.delay(0,1));const l=new Z(document.documentElement,`::view-transition-${u}(${t})`,e,r,i);c.push(l)}}});for(const e of r){if("finished"===e.playState)continue;const{effect:i}=e;if(!(i&&i instanceof KeyframeEffect))continue;const{pseudoElement:r}=i;if(!r)continue;const l=se(r);if(!l)continue;const d=s.get(l.layer);if(d)ue(d,"enter")&&ue(d,"exit")&&i.getKeyframes().some(e=>e.mixBlendMode)?c.push(new u(e)):e.cancel();else{const s="group"===l.type?"layout":"",r={...a(o,s)};Y(r);const d=y(r.ease,r.duration);i.updateTiming({delay:t.secondsToMilliseconds(null!==(n=r.delay)&&void 0!==n?n:0),duration:r.duration,easing:d}),c.push(new u(e))}}e(new i(c))})})}function ue(e,t){var n;return null===(n=null==e?void 0:e[t])||void 0===n?void 0:n.keyframes.opacity}let le=[],de=null;function me(){de=null;const[e]=le;var n;e&&(n=e,t.removeItem(le,n),de=n,ce(n).then(e=>{n.notifyReady(e),e.finished.finally(me)}))}function he(){var e;for(let e=le.length-1;e>=0;e--){const t=le[e],{interrupt:n}=t.options;if("immediate"===n){const n=le.slice(0,e+1).map(e=>e.update),i=le.slice(e+1);t.update=()=>{n.forEach(e=>e())},le=[t,...i];break}}de&&"immediate"!==(null===(e=le[0])||void 0===e?void 0:e.options.interrupt)||me()}class pe{constructor(e,n={}){var i;this.currentTarget="root",this.targets=new Map,this.notifyReady=t.noop,this.readyPromise=new Promise(e=>{this.notifyReady=e}),this.update=e,this.options={interrupt:"wait",...n},i=this,le.push(i),x.render(he)}get(e){return this.currentTarget=e,this}layout(e,t){return this.updateTarget("layout",e,t),this}new(e,t){return this.updateTarget("new",e,t),this}old(e,t){return this.updateTarget("old",e,t),this}enter(e,t){return this.updateTarget("enter",e,t),this}exit(e,t){return this.updateTarget("exit",e,t),this}crossfade(e){return this.updateTarget("enter",{opacity:1},e),this.updateTarget("exit",{opacity:0},e),this}updateTarget(e,t,n={}){const{currentTarget:i,targets:a}=this;a.has(i)||a.set(i,{});a.get(i)[e]={keyframes:t,options:n}}then(e,t){return this.readyPromise.then(e,t)}}e.GroupPlaybackControls=class extends i{then(e,t){return Promise.all(this.animations).then(e).catch(t)}},e.MotionValue=Q,e.NativeAnimationControls=u,e.ViewTransitionBuilder=pe,e.activeAnimations=q,e.animateView=function(e,t={}){return new pe(e,t)},e.attachTimeline=c,e.calcGeneratorDuration=s,e.cancelFrame=A,e.cancelMicrotask=M,e.collectMotionValues=J,e.createGeneratorEasing=o,e.createRenderBatcher=T,e.cubicBezierAsString=f,e.frame=E,e.frameData=P,e.frameSteps=b,e.generateLinearEasing=p,e.getValueTransition=a,e.hover=function(e,t,n={}){const[i,a,s]=j(e,n),o=e=>{if(!F(e))return;const{target:n}=e,i=t(n,e);if("function"!=typeof i||!n)return;const s=e=>{F(e)&&(i(e),n.removeEventListener("pointerleave",s))};n.addEventListener("pointerleave",s,a)};return i.forEach(e=>{e.addEventListener("pointerenter",o,a)}),s},e.isBezierDefinition=l,e.isDragActive=C,e.isDragging=V,e.isGenerator=r,e.isNodeOrChild=D,e.isPrimaryPointer=N,e.isWaapiSupportedEasing=function e(t){return Boolean("function"==typeof t&&h()||!t||"string"==typeof t&&(t in v||h())||l(t)||Array.isArray(t)&&t.every(e))},e.mapEasingToNativeEasing=y,e.maxGeneratorDuration=2e4,e.microtask=x,e.motionValue=function(e,t){return new Q(e,t)},e.press=function(e,t,n={}){const[i,a,s]=j(e,n),o=e=>{const i=e.currentTarget;if(!$(e)||G.has(i))return;G.add(i);const s=t(i,e),o=(e,t)=>{window.removeEventListener("pointerup",r),window.removeEventListener("pointercancel",c),$(e)&&G.has(i)&&(G.delete(i),"function"==typeof s&&s(e,{success:t}))},r=e=>{o(e,i===window||i===document||n.useGlobalTarget||D(i,e.target))},c=e=>{o(e,!1)};window.addEventListener("pointerup",r,a),window.addEventListener("pointercancel",c,a)};return i.forEach(e=>{var t;(n.useGlobalTarget?window:e).addEventListener("pointerdown",o,a),e instanceof HTMLElement&&(e.addEventListener("focus",e=>((e,t)=>{const n=e.currentTarget;if(!n)return;const i=B(()=>{if(G.has(n))return;I(n,"down");const e=B(()=>{I(n,"up")});n.addEventListener("keyup",e,t),n.addEventListener("blur",()=>I(n,"cancel"),t)});n.addEventListener("keydown",i,t),n.addEventListener("blur",()=>n.removeEventListener("keydown",i),t)})(e,a)),t=e,O.has(t.tagName)||-1!==t.tabIndex||null!==e.tabIndex||(e.tabIndex=0))}),s},e.recordStats=function(){if(w.value)throw H(),new Error("Stats are already being measured");const e=w;return e.value={frameloop:{rate:[],read:[],resolveKeyframes:[],update:[],preRender:[],render:[],postRender:[]},animations:{mainThread:[],waapi:[],layout:[]},layoutProjection:{nodes:[],calculatedTargetDeltas:[],calculatedProjections:[]}},e.addProjectionMetrics=t=>{const{layoutProjection:n}=e.value;n.nodes.push(t.nodes),n.calculatedTargetDeltas.push(t.calculatedTargetDeltas),n.calculatedProjections.push(t.calculatedProjections)},E.postRender(K,!0),X},e.resolveElements=R,e.setDragLock=function(e){return"x"===e||"y"===e?V[e]?null:(V[e]=!0,()=>{V[e]=!1}):V.x||V.y?null:(V.x=V.y=!0,()=>{V.x=V.y=!1})},e.statsBuffer=w,e.supportedWaapiEasing=v,e.supportsFlags=d,e.supportsLinearEasing=h,e.supportsScrollTimeline=n,e.time=L}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("motion-utils")):"function"==typeof define&&define.amd?define(["exports","motion-utils"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).MotionDom={},t.MotionUtils)}(this,(function(t,e){"use strict";const n=e.memo((()=>void 0!==window.ScrollTimeline));class i{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map((t=>t.finished)))}getAll(t){return this.animations[0][t]}setAll(t,e){for(let n=0;n<this.animations.length;n++)this.animations[n][t]=e}attachTimeline(t,e){const i=this.animations.map((i=>n()&&i.attachTimeline?i.attachTimeline(t):"function"==typeof e?e(i):void 0));return()=>{i.forEach(((t,e)=>{t&&t(),this.animations[e].stop()}))}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get startTime(){return this.getAll("startTime")}get duration(){let t=0;for(let e=0;e<this.animations.length;e++)t=Math.max(t,this.animations[e].duration);return t}runAll(t){this.animations.forEach((e=>e[t]()))}flatten(){this.runAll("flatten")}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}const a=t=>t.startsWith("--"),r=(t,e,n)=>{a(e)?t.style.setProperty(e,n):t.style[e]=n},o=(t,e)=>a(e)?t.style.getPropertyValue(e):t.style[e],s=t=>null!==t;const u=e.memo((()=>{try{document.createElement("div").animate({opacity:[1]})}catch(t){return!1}return!0})),c=new Set(["borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderRadius","radius","borderTopLeftRadius","borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius","width","maxWidth","height","maxHeight","top","right","bottom","left","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","margin","marginTop","marginRight","marginBottom","marginLeft","backgroundPositionX","backgroundPositionY"]);const l={layout:0,mainThread:0,waapi:0},d={value:null,addProjectionMetrics:null},m=t=>Array.isArray(t)&&"number"==typeof t[0],h={};function p(t,n){const i=e.memo(t);return()=>h[n]??i()}const f=p((()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0}),"linearEasing"),y=(t,e,n=10)=>{let i="";const a=Math.max(Math.round(e/n),2);for(let e=0;e<a;e++)i+=t(e/(a-1))+", ";return`linear(${i.substring(0,i.length-2)})`},g=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,v={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:g([0,.65,.55,1]),circOut:g([.55,0,1,.45]),backIn:g([.31,.01,.66,-.59]),backOut:g([.33,1.53,.69,.99])};function w(t,e){return t?"function"==typeof t&&f()?y(t,e):m(t)?g(t):Array.isArray(t)?t.map((t=>w(t,e)||v.easeOut)):v[t]:void 0}function T(t,e,n,{delay:i=0,duration:a=300,repeat:r=0,repeatType:o="loop",ease:s="easeInOut",times:u}={},c=void 0){const m={[e]:n};u&&(m.offset=u);const h=w(s,a);Array.isArray(h)&&(m.easing=h),d.value&&l.waapi++;const p=t.animate(m,{delay:i,duration:a,easing:Array.isArray(h)?"linear":h,fill:"both",iterations:r+1,direction:"reverse"===o?"alternate":"normal",pseudoElement:c});return d.value&&p.finished.finally((()=>{l.waapi--})),p}function A(t){return"function"==typeof t&&"applyToOptions"in t}function E({type:t,...e}){return A(t)?t.applyToOptions(e):(e.duration??(e.duration=300),e.ease??(e.ease="easeOut"),e)}const b=new WeakMap;class P{constructor(t){if("animation"in t)return void(this.animation=t.animation);const{element:n,name:i,keyframes:a,pseudoElement:l,allowFlatten:d=!1}=t;let{transition:m}=t;this.allowFlatten=d;const h=function(t){const e=b.get(t)||new Map;return b.set(t,e),e}(n),p=((t,e)=>`${t}:${e}`)(i,l||""),f=h.get(p);f&&f.stop();const y=function(t,e,n,i){Array.isArray(n)||(n=[n]);for(let a=0;a<n.length;a++)null===n[a]&&(n[a]=0!==a||i?n[a-1]:o(t,e)),"number"==typeof n[a]&&c.has(e)&&(n[a]=n[a]+"px");return!i&&!u()&&n.length<2&&n.unshift(o(t,e)),n}(n,i,a,l);e.invariant("string"!=typeof m.type,'animateMini doesn\'t support "type" as a string. Did you mean to import { spring } from "motion"?'),m=E(m),this.animation=T(n,i,y,m,l),!1===m.autoplay&&this.animation.pause(),this.removeAnimation=()=>h.delete(p),this.animation.onfinish=()=>{l?this.commitStyles():r(n,i,function(t,{repeat:e,repeatType:n="loop"},i){const a=t.filter(s),r=e&&"loop"!==n&&e%2==1?0:a.length-1;return r&&void 0!==i?i:a[r]}(y,m)),this.cancel()},h.set(p,this)}play(){this.animation.play()}pause(){this.animation.pause()}complete(){this.animation.finish()}cancel(){try{this.animation.cancel()}catch(t){}this.removeAnimation()}stop(){const{state:t}=this;"idle"!==t&&"finished"!==t&&(this.commitStyles(),this.cancel())}commitStyles(){this.animation.commitStyles?.()}get duration(){console.log(this.animation.effect?.getComputedTiming());const t=this.animation.effect?.getComputedTiming().duration||0;return e.millisecondsToSeconds(Number(t))}get time(){return e.millisecondsToSeconds(Number(this.animation.currentTime)||0)}set time(t){this.animation.currentTime=e.secondsToMilliseconds(t)}get speed(){return this.animation.playbackRate}set speed(t){this.animation.playbackRate=t}get state(){return this.animation.playState}get startTime(){return Number(this.animation.startTime)}get finished(){return this.animation.finished}flatten(){this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"})}attachTimeline(t){return this.animation.timeline=t,this.animation.onfinish=null,e.noop}then(t,e){return this.finished.then(t).catch(e)}}function x(t,e){return t?.[e]??t?.default??t}const M=2e4;function k(t){let e=0;let n=t.next(e);for(;!n.done&&e<M;)e+=50,n=t.next(e);return e>=M?1/0:e}const R=["read","resolveKeyframes","update","preRender","render","postRender"];function S(t,n){let i=!1,a=!0;const r={delta:0,timestamp:0,isProcessing:!1},o=()=>i=!0,s=R.reduce(((t,e)=>(t[e]=function(t,e){let n=new Set,i=new Set,a=!1,r=!1;const o=new WeakSet;let s={delta:0,timestamp:0,isProcessing:!1},u=0;function c(e){o.has(e)&&(l.schedule(e),t()),u++,e(s)}const l={schedule:(t,e=!1,r=!1)=>{const s=r&&a?n:i;return e&&o.add(t),s.has(t)||s.add(t),t},cancel:t=>{i.delete(t),o.delete(t)},process:t=>{s=t,a?r=!0:(a=!0,[n,i]=[i,n],n.forEach(c),e&&d.value&&d.value.frameloop[e].push(u),u=0,n.clear(),a=!1,r&&(r=!1,l.process(t)))}};return l}(o,n?e:void 0),t)),{}),{read:u,resolveKeyframes:c,update:l,preRender:m,render:h,postRender:p}=s,f=()=>{const o=e.MotionGlobalConfig.useManualTiming?r.timestamp:performance.now();i=!1,e.MotionGlobalConfig.useManualTiming||(r.delta=a?1e3/60:Math.max(Math.min(o-r.timestamp,40),1)),r.timestamp=o,r.isProcessing=!0,u.process(r),c.process(r),l.process(r),m.process(r),h.process(r),p.process(r),r.isProcessing=!1,i&&n&&(a=!1,t(f))};return{schedule:R.reduce(((e,n)=>{const o=s[n];return e[n]=(e,n=!1,s=!1)=>(i||(i=!0,a=!0,r.isProcessing||t(f)),o.schedule(e,n,s)),e}),{}),cancel:t=>{for(let e=0;e<R.length;e++)s[R[e]].cancel(t)},state:r,steps:s}}const{schedule:L,cancel:V,state:j,steps:C}=S("undefined"!=typeof requestAnimationFrame?requestAnimationFrame:e.noop,!0),{schedule:F,cancel:W}=S(queueMicrotask,!1);let N;function B(){N=void 0}const D={now:()=>(void 0===N&&D.set(j.isProcessing||e.MotionGlobalConfig.useManualTiming?j.timestamp:performance.now()),N),set:t=>{N=t,queueMicrotask(B)}},O={x:!1,y:!1};function $(){return O.x||O.y}function G(t,e,n){if(t instanceof EventTarget)return[t];if("string"==typeof t){let i=document;e&&(i=e.current);const a=n?.[t]??i.querySelectorAll(t);return a?Array.from(a):[]}return Array.from(t)}function I(t,e){const n=G(t),i=new AbortController;return[n,{passive:!0,...e,signal:i.signal},()=>i.abort()]}function q(t){return!("touch"===t.pointerType||$())}const K=(t,e)=>!!e&&(t===e||K(t,e.parentElement)),U=t=>"mouse"===t.pointerType?"number"!=typeof t.button||t.button<=0:!1!==t.isPrimary,z=new Set(["BUTTON","INPUT","SELECT","TEXTAREA","A"]);const H=new WeakSet;function X(t){return e=>{"Enter"===e.key&&t(e)}}function Y(t,e){t.dispatchEvent(new PointerEvent("pointer"+e,{isPrimary:!0,bubbles:!0}))}function J(t){return U(t)&&!$()}function Q(){const{value:t}=d;null!==t?(t.frameloop.rate.push(j.delta),t.animations.mainThread.push(l.mainThread),t.animations.waapi.push(l.waapi),t.animations.layout.push(l.layout)):V(Q)}function Z(t){return t.reduce(((t,e)=>t+e),0)/t.length}function _(t,e=Z){return 0===t.length?{min:0,max:0,avg:0}:{min:Math.min(...t),max:Math.max(...t),avg:e(t)}}const tt=t=>Math.round(1e3/t);function et(){d.value=null,d.addProjectionMetrics=null}function nt(){const{value:t}=d;if(!t)throw new Error("Stats are not being measured");et(),V(Q);const e={frameloop:{rate:_(t.frameloop.rate),read:_(t.frameloop.read),resolveKeyframes:_(t.frameloop.resolveKeyframes),update:_(t.frameloop.update),preRender:_(t.frameloop.preRender),render:_(t.frameloop.render),postRender:_(t.frameloop.postRender)},animations:{mainThread:_(t.animations.mainThread),waapi:_(t.animations.waapi),layout:_(t.animations.layout)},layoutProjection:{nodes:_(t.layoutProjection.nodes),calculatedTargetDeltas:_(t.layoutProjection.calculatedTargetDeltas),calculatedProjections:_(t.layoutProjection.calculatedProjections)}},{rate:n}=e.frameloop;return n.min=tt(n.min),n.max=tt(n.max),n.avg=tt(n.avg),[n.min,n.max]=[n.max,n.min],e}const it={current:void 0};class at{constructor(t,e={}){this.version="12.6.3",this.canTrackVelocity=null,this.events={},this.updateAndNotify=(t,e=!0)=>{const n=D.now();this.updatedAt!==n&&this.setPrevFrameValue(),this.prev=this.current,this.setCurrent(t),this.current!==this.prev&&this.events.change&&this.events.change.notify(this.current),e&&this.events.renderRequest&&this.events.renderRequest.notify(this.current)},this.hasAnimated=!1,this.setCurrent(t),this.owner=e.owner}setCurrent(t){var e;this.current=t,this.updatedAt=D.now(),null===this.canTrackVelocity&&void 0!==t&&(this.canTrackVelocity=(e=this.current,!isNaN(parseFloat(e))))}setPrevFrameValue(t=this.current){this.prevFrameValue=t,this.prevUpdatedAt=this.updatedAt}onChange(t){return this.on("change",t)}on(t,n){this.events[t]||(this.events[t]=new e.SubscriptionManager);const i=this.events[t].add(n);return"change"===t?()=>{i(),L.read((()=>{this.events.change.getSize()||this.stop()}))}:i}clearListeners(){for(const t in this.events)this.events[t].clear()}attach(t,e){this.passiveEffect=t,this.stopPassiveEffect=e}set(t,e=!0){e&&this.passiveEffect?this.passiveEffect(t,this.updateAndNotify):this.updateAndNotify(t,e)}setWithVelocity(t,e,n){this.set(e),this.prev=void 0,this.prevFrameValue=t,this.prevUpdatedAt=this.updatedAt-n}jump(t,e=!0){this.updateAndNotify(t),this.prev=t,this.prevUpdatedAt=this.prevFrameValue=void 0,e&&this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}get(){return it.current&&it.current.push(this),this.current}getPrevious(){return this.prev}getVelocity(){const t=D.now();if(!this.canTrackVelocity||void 0===this.prevFrameValue||t-this.updatedAt>30)return 0;const n=Math.min(this.updatedAt-this.prevUpdatedAt,30);return e.velocityPerSecond(parseFloat(this.current)-parseFloat(this.prevFrameValue),n)}start(t){return this.stop(),new Promise((e=>{this.hasAnimated=!0,this.animation=t(e),this.events.animationStart&&this.events.animationStart.notify()})).then((()=>{this.events.animationComplete&&this.events.animationComplete.notify(),this.clearAnimation()}))}stop(){this.animation&&(this.animation.stop(),this.events.animationCancel&&this.events.animationCancel.notify()),this.clearAnimation()}isAnimating(){return!!this.animation}clearAnimation(){delete this.animation}destroy(){this.clearListeners(),this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}}function rt(t){return"layout"===t?"group":"enter"===t||"new"===t?"new":"exit"===t||"old"===t?"old":"group"}let ot={},st=null;const ut=(t,e)=>{ot[t]=e},ct=()=>{st||(st=document.createElement("style"),st.id="motion-view");let t="";for(const e in ot){const n=ot[e];t+=`${e} {\n`;for(const[e,i]of Object.entries(n))t+=` ${e}: ${i};\n`;t+="}\n"}st.textContent=t,document.head.appendChild(st),ot={}},lt=()=>{st&&st.parentElement&&st.parentElement.removeChild(st)};function dt(t){const e=t.match(/::view-transition-(old|new|group|image-pair)\((.*?)\)/);return e?{layer:e[2],type:e[1]}:null}function mt(t){const{effect:e}=t;return!!e&&(e.target===document.documentElement&&e.pseudoElement?.startsWith("::view-transition"))}const ht=["layout","enter","exit","new","old"];function pt(t){const{update:n,targets:a,options:r}=t;if(!document.startViewTransition)return new Promise((async t=>{await n(),t(new i([]))}));(function(t,e){return e.has(t)&&Object.keys(e.get(t)).length>0})("root",a)||ut(":root",{"view-transition-name":"none"}),ut("::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*)",{"animation-timing-function":"linear !important"}),ct();const o=document.startViewTransition((async()=>{await n()}));return o.finished.finally((()=>{lt()})),new Promise((t=>{o.ready.then((()=>{const n=document.getAnimations().filter(mt),o=[];a.forEach(((t,e)=>{for(const n of ht){if(!t[n])continue;const{keyframes:i,options:a}=t[n];for(let[t,s]of Object.entries(i)){if(!s)continue;const i={...x(r,t),...x(a,t)},u=rt(n);if("opacity"===t&&!Array.isArray(s)){s=["new"===u?0:1,s]}"function"==typeof i.delay&&(i.delay=i.delay(0,1));const c=new P({element:document.documentElement,name:t,pseudoElement:`::view-transition-${u}(${e})`,keyframes:s,transition:i});o.push(c)}}}));for(const t of n){if("finished"===t.playState)continue;const{effect:n}=t;if(!(n&&n instanceof KeyframeEffect))continue;const{pseudoElement:i}=n;if(!i)continue;const s=dt(i);if(!s)continue;const u=a.get(s.layer);if(u)ft(u,"enter")&&ft(u,"exit")&&n.getKeyframes().some((t=>t.mixBlendMode))?o.push(new P({animation:t})):t.cancel();else{const i="group"===s.type?"layout":"";let a={...x(r,i)};a.duration&&(a.duration=e.secondsToMilliseconds(a.duration)),a=E(a);const u=w(a.ease,a.duration);n.updateTiming({delay:e.secondsToMilliseconds(a.delay??0),duration:a.duration,easing:u}),o.push(new P({animation:t}))}}t(new i(o))}))}))}function ft(t,e){return t?.[e]?.keyframes.opacity}let yt=[],gt=null;function vt(){gt=null;const[t]=yt;var n;t&&(n=t,e.removeItem(yt,n),gt=n,pt(n).then((t=>{n.notifyReady(t),t.finished.finally(vt)})))}function wt(){for(let t=yt.length-1;t>=0;t--){const e=yt[t],{interrupt:n}=e.options;if("immediate"===n){const n=yt.slice(0,t+1).map((t=>t.update)),i=yt.slice(t+1);e.update=()=>{n.forEach((t=>t()))},yt=[e,...i];break}}gt&&"immediate"!==yt[0]?.options.interrupt||vt()}class Tt{constructor(t,n={}){var i;this.currentTarget="root",this.targets=new Map,this.notifyReady=e.noop,this.readyPromise=new Promise((t=>{this.notifyReady=t})),this.update=t,this.options={interrupt:"wait",...n},i=this,yt.push(i),F.render(wt)}get(t){return this.currentTarget=t,this}layout(t,e){return this.updateTarget("layout",t,e),this}new(t,e){return this.updateTarget("new",t,e),this}old(t,e){return this.updateTarget("old",t,e),this}enter(t,e){return this.updateTarget("enter",t,e),this}exit(t,e){return this.updateTarget("exit",t,e),this}crossfade(t){return this.updateTarget("enter",{opacity:1},t),this.updateTarget("exit",{opacity:0},t),this}updateTarget(t,e,n={}){const{currentTarget:i,targets:a}=this;a.has(i)||a.set(i,{});a.get(i)[t]={keyframes:e,options:n}}then(t,e){return this.readyPromise.then(t,e)}}t.GroupAnimation=i,t.GroupAnimationWithThen=class extends i{then(t,e){return this.finished.finally(t).then((()=>{}))}},t.MotionValue=at,t.NativeAnimation=P,t.ViewTransitionBuilder=Tt,t.activeAnimations=l,t.animateView=function(t,e={}){return new Tt(t,e)},t.attachTimeline=function(t,e){t.timeline=e,t.onfinish=null},t.calcGeneratorDuration=k,t.cancelFrame=V,t.cancelMicrotask=W,t.collectMotionValues=it,t.createGeneratorEasing=function(t,n=100,i){const a=i({...t,keyframes:[0,n]}),r=Math.min(k(a),M);return{type:"keyframes",ease:t=>a.next(r*t).value/n,duration:e.millisecondsToSeconds(r)}},t.createRenderBatcher=S,t.cubicBezierAsString=g,t.frame=L,t.frameData=j,t.frameSteps=C,t.generateLinearEasing=y,t.getValueTransition=x,t.hover=function(t,e,n={}){const[i,a,r]=I(t,n),o=t=>{if(!q(t))return;const{target:n}=t,i=e(n,t);if("function"!=typeof i||!n)return;const r=t=>{q(t)&&(i(t),n.removeEventListener("pointerleave",r))};n.addEventListener("pointerleave",r,a)};return i.forEach((t=>{t.addEventListener("pointerenter",o,a)})),r},t.isBezierDefinition=m,t.isDragActive=$,t.isDragging=O,t.isGenerator=A,t.isNodeOrChild=K,t.isPrimaryPointer=U,t.isWaapiSupportedEasing=function t(e){return Boolean("function"==typeof e&&f()||!e||"string"==typeof e&&(e in v||f())||m(e)||Array.isArray(e)&&e.every(t))},t.mapEasingToNativeEasing=w,t.maxGeneratorDuration=M,t.microtask=F,t.motionValue=function(t,e){return new at(t,e)},t.press=function(t,e,n={}){const[i,a,r]=I(t,n),o=t=>{const i=t.currentTarget;if(!J(t)||H.has(i))return;H.add(i);const r=e(i,t),o=(t,e)=>{window.removeEventListener("pointerup",s),window.removeEventListener("pointercancel",u),J(t)&&H.has(i)&&(H.delete(i),"function"==typeof r&&r(t,{success:e}))},s=t=>{o(t,i===window||i===document||n.useGlobalTarget||K(i,t.target))},u=t=>{o(t,!1)};window.addEventListener("pointerup",s,a),window.addEventListener("pointercancel",u,a)};return i.forEach((t=>{var e;(n.useGlobalTarget?window:t).addEventListener("pointerdown",o,a),t instanceof HTMLElement&&(t.addEventListener("focus",(t=>((t,e)=>{const n=t.currentTarget;if(!n)return;const i=X((()=>{if(H.has(n))return;Y(n,"down");const t=X((()=>{Y(n,"up")}));n.addEventListener("keyup",t,e),n.addEventListener("blur",(()=>Y(n,"cancel")),e)}));n.addEventListener("keydown",i,e),n.addEventListener("blur",(()=>n.removeEventListener("keydown",i)),e)})(t,a))),e=t,z.has(e.tagName)||-1!==e.tabIndex||t.hasAttribute("tabindex")||(t.tabIndex=0))})),r},t.recordStats=function(){if(d.value)throw et(),new Error("Stats are already being measured");const t=d;return t.value={frameloop:{rate:[],read:[],resolveKeyframes:[],update:[],preRender:[],render:[],postRender:[]},animations:{mainThread:[],waapi:[],layout:[]},layoutProjection:{nodes:[],calculatedTargetDeltas:[],calculatedProjections:[]}},t.addProjectionMetrics=e=>{const{layoutProjection:n}=t.value;n.nodes.push(e.nodes),n.calculatedTargetDeltas.push(e.calculatedTargetDeltas),n.calculatedProjections.push(e.calculatedProjections)},L.postRender(Q,!0),nt},t.resolveElements=G,t.setDragLock=function(t){return"x"===t||"y"===t?O[t]?null:(O[t]=!0,()=>{O[t]=!1}):O.x||O.y?null:(O.x=O.y=!0,()=>{O.x=O.y=!1})},t.startWaapiAnimation=T,t.statsBuffer=d,t.supportedWaapiEasing=v,t.supportsFlags=h,t.supportsLinearEasing=f,t.supportsScrollTimeline=n,t.time=D}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motion-dom",
|
|
3
|
-
"version": "12.6.
|
|
3
|
+
"version": "12.6.3",
|
|
4
4
|
"author": "Matt Perry",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/motiondivision/motion",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"motion-utils": "^12.
|
|
19
|
+
"motion-utils": "^12.6.3"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"clean": "rm -rf types dist lib",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"dev": "concurrently -c blue,red -n tsc,rollup --kill-others \"tsc --watch -p . --preserveWatchOutput\" \"rollup --config --watch --no-watch.clearScreen\"",
|
|
25
25
|
"test": "jest --config jest.config.json --max-workers=2 motion-value.test"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "490a378259dcfb7bb8486b460da4c367002bc598"
|
|
28
28
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { BaseGroupPlaybackControls } from './BaseGroup.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* TODO: This is a temporary class to support the legacy
|
|
5
|
-
* thennable API
|
|
6
|
-
*/
|
|
7
|
-
class GroupPlaybackControls extends BaseGroupPlaybackControls {
|
|
8
|
-
then(onResolve, onReject) {
|
|
9
|
-
return Promise.all(this.animations).then(onResolve).catch(onReject);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { GroupPlaybackControls };
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { millisecondsToSeconds, secondsToMilliseconds, noop } from 'motion-utils';
|
|
2
|
-
import { attachTimeline } from './utils/attach-timeline.mjs';
|
|
3
|
-
|
|
4
|
-
class NativeAnimationControls {
|
|
5
|
-
constructor(animation) {
|
|
6
|
-
this.animation = animation;
|
|
7
|
-
}
|
|
8
|
-
get duration() {
|
|
9
|
-
var _a, _b, _c;
|
|
10
|
-
const durationInMs = ((_b = (_a = this.animation) === null || _a === void 0 ? void 0 : _a.effect) === null || _b === void 0 ? void 0 : _b.getComputedTiming().duration) ||
|
|
11
|
-
((_c = this.options) === null || _c === void 0 ? void 0 : _c.duration) ||
|
|
12
|
-
300;
|
|
13
|
-
return millisecondsToSeconds(Number(durationInMs));
|
|
14
|
-
}
|
|
15
|
-
get time() {
|
|
16
|
-
var _a;
|
|
17
|
-
if (this.animation) {
|
|
18
|
-
return millisecondsToSeconds(((_a = this.animation) === null || _a === void 0 ? void 0 : _a.currentTime) || 0);
|
|
19
|
-
}
|
|
20
|
-
return 0;
|
|
21
|
-
}
|
|
22
|
-
set time(newTime) {
|
|
23
|
-
if (this.animation) {
|
|
24
|
-
this.animation.currentTime = secondsToMilliseconds(newTime);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
get speed() {
|
|
28
|
-
return this.animation ? this.animation.playbackRate : 1;
|
|
29
|
-
}
|
|
30
|
-
set speed(newSpeed) {
|
|
31
|
-
if (this.animation) {
|
|
32
|
-
this.animation.playbackRate = newSpeed;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
get state() {
|
|
36
|
-
return this.animation ? this.animation.playState : "finished";
|
|
37
|
-
}
|
|
38
|
-
get startTime() {
|
|
39
|
-
return this.animation ? this.animation.startTime : null;
|
|
40
|
-
}
|
|
41
|
-
get finished() {
|
|
42
|
-
return this.animation ? this.animation.finished : Promise.resolve();
|
|
43
|
-
}
|
|
44
|
-
play() {
|
|
45
|
-
this.animation && this.animation.play();
|
|
46
|
-
}
|
|
47
|
-
pause() {
|
|
48
|
-
this.animation && this.animation.pause();
|
|
49
|
-
}
|
|
50
|
-
stop() {
|
|
51
|
-
if (!this.animation ||
|
|
52
|
-
this.state === "idle" ||
|
|
53
|
-
this.state === "finished") {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (this.animation.commitStyles) {
|
|
57
|
-
this.animation.commitStyles();
|
|
58
|
-
}
|
|
59
|
-
this.cancel();
|
|
60
|
-
}
|
|
61
|
-
flatten() {
|
|
62
|
-
var _a, _b;
|
|
63
|
-
if (!this.animation || !((_a = this.options) === null || _a === void 0 ? void 0 : _a.allowFlatten))
|
|
64
|
-
return;
|
|
65
|
-
(_b = this.animation.effect) === null || _b === void 0 ? void 0 : _b.updateTiming({ easing: "linear" });
|
|
66
|
-
}
|
|
67
|
-
attachTimeline(timeline) {
|
|
68
|
-
if (this.animation)
|
|
69
|
-
attachTimeline(this.animation, timeline);
|
|
70
|
-
return noop;
|
|
71
|
-
}
|
|
72
|
-
complete() {
|
|
73
|
-
this.animation && this.animation.finish();
|
|
74
|
-
}
|
|
75
|
-
cancel() {
|
|
76
|
-
try {
|
|
77
|
-
this.animation && this.animation.cancel();
|
|
78
|
-
}
|
|
79
|
-
catch (e) { }
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export { NativeAnimationControls };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { NativeAnimationControls } from './NativeAnimationControls.mjs';
|
|
2
|
-
import { convertMotionOptionsToNative } from './utils/convert-options.mjs';
|
|
3
|
-
|
|
4
|
-
class PseudoAnimation extends NativeAnimationControls {
|
|
5
|
-
constructor(target, pseudoElement, valueName, keyframes, options) {
|
|
6
|
-
const animationOptions = convertMotionOptionsToNative(valueName, keyframes, options);
|
|
7
|
-
const animation = target.animate(animationOptions.keyframes, {
|
|
8
|
-
pseudoElement,
|
|
9
|
-
...animationOptions.options,
|
|
10
|
-
});
|
|
11
|
-
super(animation);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { PseudoAnimation };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { secondsToMilliseconds } from 'motion-utils';
|
|
2
|
-
import { supportsLinearEasing } from '../../../utils/supports/linear-easing.mjs';
|
|
3
|
-
import { createGeneratorEasing } from '../../generators/utils/create-generator-easing.mjs';
|
|
4
|
-
import { isGenerator } from '../../generators/utils/is-generator.mjs';
|
|
5
|
-
import { mapEasingToNativeEasing } from './easing.mjs';
|
|
6
|
-
|
|
7
|
-
const defaultEasing = "easeOut";
|
|
8
|
-
function applyGeneratorOptions(options) {
|
|
9
|
-
var _a;
|
|
10
|
-
if (isGenerator(options.type)) {
|
|
11
|
-
const generatorOptions = createGeneratorEasing(options, 100, options.type);
|
|
12
|
-
options.ease = supportsLinearEasing()
|
|
13
|
-
? generatorOptions.ease
|
|
14
|
-
: defaultEasing;
|
|
15
|
-
options.duration = secondsToMilliseconds(generatorOptions.duration);
|
|
16
|
-
options.type = "keyframes";
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
options.duration = secondsToMilliseconds((_a = options.duration) !== null && _a !== void 0 ? _a : 0.3);
|
|
20
|
-
options.ease = options.ease || defaultEasing;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
// TODO: Reuse for NativeAnimation
|
|
24
|
-
function convertMotionOptionsToNative(valueName, keyframes, options) {
|
|
25
|
-
var _a;
|
|
26
|
-
const nativeKeyframes = {};
|
|
27
|
-
const nativeOptions = {
|
|
28
|
-
fill: "both",
|
|
29
|
-
easing: "linear",
|
|
30
|
-
composite: "replace",
|
|
31
|
-
};
|
|
32
|
-
nativeOptions.delay = secondsToMilliseconds((_a = options.delay) !== null && _a !== void 0 ? _a : 0);
|
|
33
|
-
applyGeneratorOptions(options);
|
|
34
|
-
nativeOptions.duration = options.duration;
|
|
35
|
-
const { ease, times } = options;
|
|
36
|
-
if (times)
|
|
37
|
-
nativeKeyframes.offset = times;
|
|
38
|
-
nativeKeyframes[valueName] = keyframes;
|
|
39
|
-
const easing = mapEasingToNativeEasing(ease, options.duration);
|
|
40
|
-
/**
|
|
41
|
-
* If this is an easing array, apply to keyframes, not animation as a whole
|
|
42
|
-
*/
|
|
43
|
-
if (Array.isArray(easing)) {
|
|
44
|
-
nativeKeyframes.easing = easing;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
nativeOptions.easing = easing;
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
keyframes: nativeKeyframes,
|
|
51
|
-
options: nativeOptions,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export { applyGeneratorOptions, convertMotionOptionsToNative };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { isBezierDefinition } from '../../../utils/is-bezier-definition.mjs';
|
|
2
|
-
import { supportsLinearEasing } from '../../../utils/supports/linear-easing.mjs';
|
|
3
|
-
import { generateLinearEasing } from './linear.mjs';
|
|
4
|
-
|
|
5
|
-
function isWaapiSupportedEasing(easing) {
|
|
6
|
-
return Boolean((typeof easing === "function" && supportsLinearEasing()) ||
|
|
7
|
-
!easing ||
|
|
8
|
-
(typeof easing === "string" &&
|
|
9
|
-
(easing in supportedWaapiEasing || supportsLinearEasing())) ||
|
|
10
|
-
isBezierDefinition(easing) ||
|
|
11
|
-
(Array.isArray(easing) && easing.every(isWaapiSupportedEasing)));
|
|
12
|
-
}
|
|
13
|
-
const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
|
|
14
|
-
const supportedWaapiEasing = {
|
|
15
|
-
linear: "linear",
|
|
16
|
-
ease: "ease",
|
|
17
|
-
easeIn: "ease-in",
|
|
18
|
-
easeOut: "ease-out",
|
|
19
|
-
easeInOut: "ease-in-out",
|
|
20
|
-
circIn: /*@__PURE__*/ cubicBezierAsString([0, 0.65, 0.55, 1]),
|
|
21
|
-
circOut: /*@__PURE__*/ cubicBezierAsString([0.55, 0, 1, 0.45]),
|
|
22
|
-
backIn: /*@__PURE__*/ cubicBezierAsString([0.31, 0.01, 0.66, -0.59]),
|
|
23
|
-
backOut: /*@__PURE__*/ cubicBezierAsString([0.33, 1.53, 0.69, 0.99]),
|
|
24
|
-
};
|
|
25
|
-
function mapEasingToNativeEasing(easing, duration) {
|
|
26
|
-
if (!easing) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
else if (typeof easing === "function" && supportsLinearEasing()) {
|
|
30
|
-
return generateLinearEasing(easing, duration);
|
|
31
|
-
}
|
|
32
|
-
else if (isBezierDefinition(easing)) {
|
|
33
|
-
return cubicBezierAsString(easing);
|
|
34
|
-
}
|
|
35
|
-
else if (Array.isArray(easing)) {
|
|
36
|
-
return easing.map((segmentEasing) => mapEasingToNativeEasing(segmentEasing, duration) ||
|
|
37
|
-
supportedWaapiEasing.easeOut);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return supportedWaapiEasing[easing];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export { cubicBezierAsString, isWaapiSupportedEasing, mapEasingToNativeEasing, supportedWaapiEasing };
|