motion-dom 12.6.1 → 12.6.3-alpha.0
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 +1 -1
- package/dist/es/value/index.mjs +1 -1
- package/dist/motion-dom.dev.js +1 -1
- package/dist/motion-dom.js +1 -1
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -895,7 +895,7 @@ class MotionValue {
|
|
|
895
895
|
* This will be replaced by the build step with the latest version number.
|
|
896
896
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
897
897
|
*/
|
|
898
|
-
this.version = "12.6.
|
|
898
|
+
this.version = "12.6.3-alpha.0";
|
|
899
899
|
/**
|
|
900
900
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
901
901
|
* if the value is numerical, but we might be able to widen the scope here and support
|
package/dist/es/value/index.mjs
CHANGED
|
@@ -30,7 +30,7 @@ class MotionValue {
|
|
|
30
30
|
* This will be replaced by the build step with the latest version number.
|
|
31
31
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
32
32
|
*/
|
|
33
|
-
this.version = "12.6.
|
|
33
|
+
this.version = "12.6.3-alpha.0";
|
|
34
34
|
/**
|
|
35
35
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
36
36
|
* if the value is numerical, but we might be able to widen the scope here and support
|
package/dist/motion-dom.dev.js
CHANGED
|
@@ -895,7 +895,7 @@
|
|
|
895
895
|
* This will be replaced by the build step with the latest version number.
|
|
896
896
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
897
897
|
*/
|
|
898
|
-
this.version = "12.6.
|
|
898
|
+
this.version = "12.6.3-alpha.0";
|
|
899
899
|
/**
|
|
900
900
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
901
901
|
* if the value is numerical, but we might be able to widen the scope here and support
|
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(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 h(e,n){const i=t.memo(e);return()=>{var e;return null!==(e=d[n])&&void 0!==e?e:i()}}const m=h(()=>{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&&m()?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:h,postRender:m}=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),h.process(s),m.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.3-alpha.0",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=m()?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 he(){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(he)}))}function me(){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)||he()}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(me)}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&&m()||!t||"string"==typeof t&&(t in v||m())||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=m,e.supportsScrollTimeline=n,e.time=L}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motion-dom",
|
|
3
|
-
"version": "12.6.
|
|
3
|
+
"version": "12.6.3-alpha.0",
|
|
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-alpha.0"
|
|
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": "ad91b03af6fb96f83c94e8d7b94dae3f379ba5d2"
|
|
28
28
|
}
|