motion-dom 12.4.11 → 12.5.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 +659 -26
- package/dist/es/frameloop/batcher.mjs +69 -0
- package/dist/es/frameloop/frame.mjs +6 -0
- package/dist/es/frameloop/microtask.mjs +6 -0
- package/dist/es/frameloop/order.mjs +10 -0
- package/dist/es/frameloop/render-step.mjs +92 -0
- package/dist/es/frameloop/sync-time.mjs +31 -0
- package/dist/es/index.mjs +12 -4
- package/dist/es/stats/animation-count.mjs +7 -0
- package/dist/es/stats/buffer.mjs +6 -0
- package/dist/es/stats/index.mjs +113 -0
- package/dist/es/utils/supports/scroll-timeline.mjs +1 -1
- package/dist/es/value/index.mjs +311 -0
- package/dist/index.d.ts +340 -20
- package/dist/motion-dom.dev.js +659 -26
- package/dist/motion-dom.js +1 -1
- package/package.json +5 -4
package/dist/motion-dom.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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=>"finished"in t?t.finished:t))}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")}}function o(t,e){return t?t[e]||t.default||t:void 0}function r(t){let e=0;let n=t.next(e);for(;!n.done&&e<2e4;)e+=50,n=t.next(e);return e>=2e4?1/0:e}function a(t,n=100,i){const o=i({...t,keyframes:[0,n]}),a=Math.min(r(o),2e4);return{type:"keyframes",ease:t=>o.next(a*t).value/n,duration:e.millisecondsToSeconds(a)}}function s(t){return"function"==typeof t}function u(t,e){t.timeline=e,t.onfinish=null}class l{constructor(t){this.animation=t}get duration(){var t,n,i;const o=(null===(n=null===(t=this.animation)||void 0===t?void 0:t.effect)||void 0===n?void 0:n.getComputedTiming().duration)||(null===(i=this.options)||void 0===i?void 0:i.duration)||300;return e.millisecondsToSeconds(Number(o))}get time(){var t;return this.animation?e.millisecondsToSeconds((null===(t=this.animation)||void 0===t?void 0:t.currentTime)||0):0}set time(t){this.animation&&(this.animation.currentTime=e.secondsToMilliseconds(t))}get speed(){return this.animation?this.animation.playbackRate:1}set speed(t){this.animation&&(this.animation.playbackRate=t)}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 t,e;this.animation&&(null===(t=this.options)||void 0===t?void 0:t.allowFlatten)&&(null===(e=this.animation.effect)||void 0===e||e.updateTiming({easing:"linear"}))}attachTimeline(t){return this.animation&&u(this.animation,t),e.noop}complete(){this.animation&&this.animation.finish()}cancel(){try{this.animation&&this.animation.cancel()}catch(t){}}}const c=t=>Array.isArray(t)&&"number"==typeof t[0],d={linearEasing:void 0};function m(t,n){const i=e.memo(t);return()=>{var t;return null!==(t=d[n])&&void 0!==t?t:i()}}const f=m(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0},"linearEasing"),h=(t,n,i=10)=>{let o="";const r=Math.max(Math.round(n/i),2);for(let n=0;n<r;n++)o+=t(e.progress(0,r-1,n))+", ";return`linear(${o.substring(0,o.length-2)})`};const p=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,y={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:p([0,.65,.55,1]),circOut:p([.55,0,1,.45]),backIn:p([.31,.01,.66,-.59]),backOut:p([.33,1.53,.69,.99])};function g(t,e){return t?"function"==typeof t&&f()?h(t,e):c(t)?p(t):Array.isArray(t)?t.map(t=>g(t,e)||y.easeOut):y[t]:void 0}const v={x:!1,y:!1};function T(){return v.x||v.y}function E(t,e,n){var i;if(t instanceof EventTarget)return[t];if("string"==typeof t){let o=document;e&&(o=e.current);const r=null!==(i=null==n?void 0:n[t])&&void 0!==i?i:o.querySelectorAll(t);return r?Array.from(r):[]}return Array.from(t)}function w(t,e){const n=E(t),i=new AbortController;return[n,{passive:!0,...e,signal:i.signal},()=>i.abort()]}function A(t){return!("touch"===t.pointerType||T())}function b(t,e){const n=e+"PointerCapture";if(t.target instanceof Element&&n in t.target&&void 0!==t.pointerId)try{t.target[n](t.pointerId)}catch(t){}}const x=(t,e)=>!!e&&(t===e||x(t,e.parentElement)),k=t=>"mouse"===t.pointerType?"number"!=typeof t.button||t.button<=0:!1!==t.isPrimary,L=new Set(["BUTTON","INPUT","SELECT","TEXTAREA","A"]);const P=new WeakSet;function M(t){return e=>{"Enter"===e.key&&t(e)}}function S(t,e){t.dispatchEvent(new PointerEvent("pointer"+e,{isPrimary:!0,bubbles:!0}))}function O(t){return k(t)&&!T()}function C(t){var n;if(s(t.type)){const n=a(t,100,t.type);t.ease=f()?n.ease:"easeOut",t.duration=e.secondsToMilliseconds(n.duration),t.type="keyframes"}else t.duration=e.secondsToMilliseconds(null!==(n=t.duration)&&void 0!==n?n:.3),t.ease=t.ease||"easeOut"}class I extends l{constructor(t,n,i,o,r){const a=function(t,n,i){var o;const r={},a={fill:"both",easing:"linear",composite:"replace"};a.delay=e.secondsToMilliseconds(null!==(o=i.delay)&&void 0!==o?o:0),C(i),a.duration=i.duration;const{ease:s,times:u}=i;u&&(r.offset=u),r[t]=n;const l=g(s,i.duration);return Array.isArray(l)?r.easing=l:a.easing=l,{keyframes:r,options:a}}(i,o,r);super(t.animate(a.keyframes,{pseudoElement:n,...a.options}))}}function $(t){return"layout"===t?"group":"enter"===t||"new"===t?"new":"exit"===t||"old"===t?"old":"group"}let B={},D=null;const N=(t,e)=>{B[t]=e},R=()=>{D||(D=document.createElement("style"),D.id="motion-view");let t="";for(const e in B){const n=B[e];t+=e+" {\n";for(const[e,i]of Object.entries(n))t+=` ${e}: ${i};\n`;t+="}\n"}D.textContent=t,document.head.appendChild(D),B={}},G=()=>{D&&D.parentElement&&D.parentElement.removeChild(D)};function W(t){const e=t.match(/::view-transition-(old|new|group|image-pair)\((.*?)\)/);return e?{layer:e[2],type:e[1]}:null}function j(t){var e;const{effect:n}=t;return!!n&&(n.target===document.documentElement&&(null===(e=n.pseudoElement)||void 0===e?void 0:e.startsWith("::view-transition")))}const V=["layout","enter","exit","new","old"];function q(t,n,r){if(!document.startViewTransition)return new Promise(async e=>{await t(),e(new i([]))});(function(t,e){return e.has(t)&&Object.keys(e.get(t)).length>0})("root",r)||N(":root",{"view-transition-name":"none"}),N("::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*)",{"animation-timing-function":"linear !important"}),R();const a=document.startViewTransition(async()=>{await t()});return a.finished.finally(()=>{G()}),new Promise(t=>{a.ready.then(()=>{var a;const s=document.getAnimations().filter(j),u=[];r.forEach((t,e)=>{for(const i of V){if(!t[i])continue;const{keyframes:r,options:a}=t[i];for(let[t,s]of Object.entries(r)){if(!s)continue;const r={...o(n,t),...o(a,t)},l=$(i);if("opacity"===t&&!Array.isArray(s)){s=["new"===l?0:1,s]}"function"==typeof r.delay&&(r.delay=r.delay(0,1));const c=new I(document.documentElement,`::view-transition-${l}(${e})`,t,s,r);u.push(c)}}});for(const t of s){if("finished"===t.playState)continue;const{effect:i}=t;if(!(i&&i instanceof KeyframeEffect))continue;const{pseudoElement:s}=i;if(!s)continue;const c=W(s);if(!c)continue;const d=r.get(c.layer);if(d)z(d,"enter")&&z(d,"exit")&&i.getKeyframes().some(t=>t.mixBlendMode)?u.push(new l(t)):t.cancel();else{const r="group"===c.type?"layout":"",s={...o(n,r)};C(s);const d=g(s.ease,s.duration);i.updateTiming({delay:e.secondsToMilliseconds(null!==(a=s.delay)&&void 0!==a?a:0),duration:s.duration,easing:d}),u.push(new l(t))}}t(new i(u))})})}function z(t,e){var n;return null===(n=null==t?void 0:t[e])||void 0===n?void 0:n.keyframes.opacity}class U{constructor(t,n={}){this.currentTarget="root",this.targets=new Map,this.notifyReady=e.noop,this.readyPromise=new Promise(t=>{this.notifyReady=t}),queueMicrotask(()=>{q(t,n,this.targets).then(t=>this.notifyReady(t))})}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:o}=this;o.has(i)||o.set(i,{});o.get(i)[t]={keyframes:e,options:n}}then(t,e){return this.readyPromise.then(t,e)}}t.GroupPlaybackControls=class extends i{then(t,e){return Promise.all(this.animations).then(t).catch(e)}},t.NativeAnimationControls=l,t.ViewTransitionBuilder=U,t.attachTimeline=u,t.calcGeneratorDuration=r,t.capturePointer=b,t.createGeneratorEasing=a,t.cubicBezierAsString=p,t.generateLinearEasing=h,t.getValueTransition=o,t.hover=function(t,e,n={}){const[i,o,r]=w(t,n),a=t=>{if(!A(t))return;const{target:n}=t,i=e(n,t);if("function"!=typeof i||!n)return;const r=t=>{A(t)&&(i(t),n.removeEventListener("pointerleave",r))};n.addEventListener("pointerleave",r,o)};return i.forEach(t=>{t.addEventListener("pointerenter",a,o)}),r},t.isBezierDefinition=c,t.isDragActive=T,t.isDragging=v,t.isGenerator=s,t.isNodeOrChild=x,t.isPrimaryPointer=k,t.isWaapiSupportedEasing=function t(e){return Boolean("function"==typeof e&&f()||!e||"string"==typeof e&&(e in y||f())||c(e)||Array.isArray(e)&&e.every(t))},t.mapEasingToNativeEasing=g,t.maxGeneratorDuration=2e4,t.press=function(t,e,n={}){const[i,o,r]=w(t,n),a=t=>{const n=t.currentTarget;if(!n||!O(t)||P.has(n))return;P.add(n),b(t,"set");const i=e(n,t),r=(t,e)=>{n.removeEventListener("pointerup",a),n.removeEventListener("pointercancel",s),b(t,"release"),O(t)&&P.has(n)&&(P.delete(n),"function"==typeof i&&i(t,{success:e}))},a=t=>{const e=!!t.isTrusted&&(i=t,o=n instanceof Element?n.getBoundingClientRect():{left:0,top:0,right:window.innerWidth,bottom:window.innerHeight},i.clientX<o.left||i.clientX>o.right||i.clientY<o.top||i.clientY>o.bottom);var i,o;r(t,!e&&(!(n instanceof Element)||x(n,t.target)))},s=t=>{r(t,!1)};n.addEventListener("pointerup",a,o),n.addEventListener("pointercancel",s,o),n.addEventListener("lostpointercapture",s,o)};return i.forEach(t=>{let e=!1;var i;(t=n.useGlobalTarget?window:t)instanceof HTMLElement&&(e=!0,i=t,L.has(i.tagName)||-1!==i.tabIndex||null!==t.getAttribute("tabindex")||(t.tabIndex=0)),t.addEventListener("pointerdown",a,o),e&&t.addEventListener("focus",t=>((t,e)=>{const n=t.currentTarget;if(!n)return;const i=M(()=>{if(P.has(n))return;S(n,"down");const t=M(()=>{S(n,"up")});n.addEventListener("keyup",t,e),n.addEventListener("blur",()=>S(n,"cancel"),e)});n.addEventListener("keydown",i,e),n.addEventListener("blur",()=>n.removeEventListener("keydown",i),e)})(t,o),o)}),r},t.resolveElements=E,t.setDragLock=function(t){return"x"===t||"y"===t?v[t]?null:(v[t]=!0,()=>{v[t]=!1}):v.x||v.y?null:(v.x=v.y=!0,()=>{v.x=v.y=!1})},t.supportedWaapiEasing=y,t.supportsFlags=d,t.supportsLinearEasing=f,t.supportsScrollTimeline=n,t.view=function(t,e={}){return new U(t,e)}}));
|
|
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=>"finished"in t?t.finished:t))}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")}}function a(t,e){return t?t[e]||t.default||t:void 0}function s(t){let e=0;let n=t.next(e);for(;!n.done&&e<2e4;)e+=50,n=t.next(e);return e>=2e4?1/0:e}function o(t,n=100,i){const a=i({...t,keyframes:[0,n]}),o=Math.min(s(a),2e4);return{type:"keyframes",ease:t=>a.next(o*t).value/n,duration:e.millisecondsToSeconds(o)}}function r(t){return"function"==typeof t}function c(t,e){t.timeline=e,t.onfinish=null}class u{constructor(t){this.animation=t}get duration(){var t,n,i;const a=(null===(n=null===(t=this.animation)||void 0===t?void 0:t.effect)||void 0===n?void 0:n.getComputedTiming().duration)||(null===(i=this.options)||void 0===i?void 0:i.duration)||300;return e.millisecondsToSeconds(Number(a))}get time(){var t;return this.animation?e.millisecondsToSeconds((null===(t=this.animation)||void 0===t?void 0:t.currentTime)||0):0}set time(t){this.animation&&(this.animation.currentTime=e.secondsToMilliseconds(t))}get speed(){return this.animation?this.animation.playbackRate:1}set speed(t){this.animation&&(this.animation.playbackRate=t)}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 t,e;this.animation&&(null===(t=this.options)||void 0===t?void 0:t.allowFlatten)&&(null===(e=this.animation.effect)||void 0===e||e.updateTiming({easing:"linear"}))}attachTimeline(t){return this.animation&&c(this.animation,t),e.noop}complete(){this.animation&&this.animation.finish()}cancel(){try{this.animation&&this.animation.cancel()}catch(t){}}}const l=t=>Array.isArray(t)&&"number"==typeof t[0],d={linearEasing:void 0};function h(t,n){const i=e.memo(t);return()=>{var t;return null!==(t=d[n])&&void 0!==t?t:i()}}const m=h(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0},"linearEasing"),p=(t,n,i=10)=>{let a="";const s=Math.max(Math.round(n/i),2);for(let n=0;n<s;n++)a+=t(e.progress(0,s-1,n))+", ";return`linear(${a.substring(0,a.length-2)})`};const f=([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: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(t,e){return t?"function"==typeof t&&m()?p(t,e):l(t)?f(t):Array.isArray(t)?t.map(t=>y(t,e)||v.easeOut):v[t]:void 0}const g=["read","resolveKeyframes","update","preRender","render","postRender"],T={value:null,addProjectionMetrics:null};function w(t,n){let i=!1,a=!0;const s={delta:0,timestamp:0,isProcessing:!1},o=()=>i=!0,r=g.reduce((t,e)=>(t[e]=function(t,e){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(e){o.has(e)&&(l.schedule(e),t()),c++,e(r)}const l={schedule:(t,e=!1,s=!1)=>{const r=s&&a?n:i;return e&&o.add(t),r.has(t)||r.add(t),t},cancel:t=>{i.delete(t),o.delete(t)},process:t=>{r=t,a?s=!0:(a=!0,[n,i]=[i,n],n.forEach(u),e&&T.value&&T.value.frameloop[e].push(c),c=0,n.clear(),a=!1,s&&(s=!1,l.process(t)))}};return l}(o,n?e:void 0),t),{}),{read:c,resolveKeyframes:u,update:l,preRender:d,render:h,postRender:m}=r,p=()=>{const o=e.MotionGlobalConfig.useManualTiming?s.timestamp:performance.now();i=!1,e.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,t(p))};return{schedule:g.reduce((e,n)=>{const o=r[n];return e[n]=(e,n=!1,r=!1)=>(i||(i=!0,a=!0,s.isProcessing||t(p)),o.schedule(e,n,r)),e},{}),cancel:t=>{for(let e=0;e<g.length;e++)r[g[e]].cancel(t)},state:s,steps:r}}const{schedule:E,cancel:A,state:P,steps:b}=w("undefined"!=typeof requestAnimationFrame?requestAnimationFrame:e.noop,!0),{schedule:x,cancel:M}=w(queueMicrotask,!1);let k;function S(){k=void 0}const C={now:()=>(void 0===k&&C.set(P.isProcessing||e.MotionGlobalConfig.useManualTiming?P.timestamp:performance.now()),k),set:t=>{k=t,queueMicrotask(S)}},L={x:!1,y:!1};function R(){return L.x||L.y}function V(t,e,n){var i;if(t instanceof EventTarget)return[t];if("string"==typeof t){let a=document;e&&(a=e.current);const s=null!==(i=null==n?void 0:n[t])&&void 0!==i?i:a.querySelectorAll(t);return s?Array.from(s):[]}return Array.from(t)}function j(t,e){const n=V(t),i=new AbortController;return[n,{passive:!0,...e,signal:i.signal},()=>i.abort()]}function F(t){return!("touch"===t.pointerType||R())}function D(t,e){const n=e+"PointerCapture";if(t.target instanceof Element&&n in t.target&&void 0!==t.pointerId)try{t.target[n](t.pointerId)}catch(t){}}const N=(t,e)=>!!e&&(t===e||N(t,e.parentElement)),O=t=>"mouse"===t.pointerType?"number"!=typeof t.button||t.button<=0:!1!==t.isPrimary,B=new Set(["BUTTON","INPUT","SELECT","TEXTAREA","A"]);const q=new WeakSet;function G(t){return e=>{"Enter"===e.key&&t(e)}}function I(t,e){t.dispatchEvent(new PointerEvent("pointer"+e,{isPrimary:!0,bubbles:!0}))}function $(t){return O(t)&&!R()}const K={layout:0,mainThread:0,waapi:0};function U(){const{value:t}=T;null!==t?(t.frameloop.rate.push(P.delta),t.animations.mainThread.push(K.mainThread),t.animations.waapi.push(K.waapi),t.animations.layout.push(K.layout)):A(U)}function W(t){return t.reduce((t,e)=>t+e,0)/t.length}function z(t,e=W){return 0===t.length?{min:0,max:0,avg:0}:{min:Math.min(...t),max:Math.max(...t),avg:e(t)}}const X=t=>Math.round(1e3/t);function H(){T.value=null,T.addProjectionMetrics=null}function Y(){const{value:t}=T;if(!t)throw new Error("Stats are not being measured");H(),A(U);const e={frameloop:{rate:z(t.frameloop.rate),read:z(t.frameloop.read),resolveKeyframes:z(t.frameloop.resolveKeyframes),update:z(t.frameloop.update),preRender:z(t.frameloop.preRender),render:z(t.frameloop.render),postRender:z(t.frameloop.postRender)},animations:{mainThread:z(t.animations.mainThread),waapi:z(t.animations.waapi),layout:z(t.animations.layout)},layoutProjection:{nodes:z(t.layoutProjection.nodes),calculatedTargetDeltas:z(t.layoutProjection.calculatedTargetDeltas),calculatedProjections:z(t.layoutProjection.calculatedProjections)}},{rate:n}=e.frameloop;return n.min=X(n.min),n.max=X(n.max),n.avg=X(n.avg),[n.min,n.max]=[n.max,n.min],e}const J={current:void 0};class Q{constructor(t,e={}){this.version="12.5.0",this.canTrackVelocity=null,this.events={},this.updateAndNotify=(t,e=!0)=>{const n=C.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=C.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(),E.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 J.current&&J.current.push(this),this.current}getPrevious(){return this.prev}getVelocity(){const t=C.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 Z(t){var n;if(r(t.type)){const n=o(t,100,t.type);t.ease=m()?n.ease:"easeOut",t.duration=e.secondsToMilliseconds(n.duration),t.type="keyframes"}else t.duration=e.secondsToMilliseconds(null!==(n=t.duration)&&void 0!==n?n:.3),t.ease=t.ease||"easeOut"}class _ extends u{constructor(t,n,i,a,s){const o=function(t,n,i){var a;const s={},o={fill:"both",easing:"linear",composite:"replace"};o.delay=e.secondsToMilliseconds(null!==(a=i.delay)&&void 0!==a?a:0),Z(i),o.duration=i.duration;const{ease:r,times:c}=i;c&&(s.offset=c),s[t]=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(t.animate(o.keyframes,{pseudoElement:n,...o.options}))}}function tt(t){return"layout"===t?"group":"enter"===t||"new"===t?"new":"exit"===t||"old"===t?"old":"group"}let et={},nt=null;const it=(t,e)=>{et[t]=e},at=()=>{nt||(nt=document.createElement("style"),nt.id="motion-view");let t="";for(const e in et){const n=et[e];t+=e+" {\n";for(const[e,i]of Object.entries(n))t+=` ${e}: ${i};\n`;t+="}\n"}nt.textContent=t,document.head.appendChild(nt),et={}},st=()=>{nt&&nt.parentElement&&nt.parentElement.removeChild(nt)};function ot(t){const e=t.match(/::view-transition-(old|new|group|image-pair)\((.*?)\)/);return e?{layer:e[2],type:e[1]}:null}function rt(t){var e;const{effect:n}=t;return!!n&&(n.target===document.documentElement&&(null===(e=n.pseudoElement)||void 0===e?void 0:e.startsWith("::view-transition")))}const ct=["layout","enter","exit","new","old"];function ut(t,n,s){if(!document.startViewTransition)return new Promise(async e=>{await t(),e(new i([]))});(function(t,e){return e.has(t)&&Object.keys(e.get(t)).length>0})("root",s)||it(":root",{"view-transition-name":"none"}),it("::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*)",{"animation-timing-function":"linear !important"}),at();const o=document.startViewTransition(async()=>{await t()});return o.finished.finally(()=>{st()}),new Promise(t=>{o.ready.then(()=>{var o;const r=document.getAnimations().filter(rt),c=[];s.forEach((t,e)=>{for(const i of ct){if(!t[i])continue;const{keyframes:s,options:o}=t[i];for(let[t,r]of Object.entries(s)){if(!r)continue;const s={...a(n,t),...a(o,t)},u=tt(i);if("opacity"===t&&!Array.isArray(r)){r=["new"===u?0:1,r]}"function"==typeof s.delay&&(s.delay=s.delay(0,1));const l=new _(document.documentElement,`::view-transition-${u}(${e})`,t,r,s);c.push(l)}}});for(const t of r){if("finished"===t.playState)continue;const{effect:i}=t;if(!(i&&i instanceof KeyframeEffect))continue;const{pseudoElement:r}=i;if(!r)continue;const l=ot(r);if(!l)continue;const d=s.get(l.layer);if(d)lt(d,"enter")&<(d,"exit")&&i.getKeyframes().some(t=>t.mixBlendMode)?c.push(new u(t)):t.cancel();else{const s="group"===l.type?"layout":"",r={...a(n,s)};Z(r);const d=y(r.ease,r.duration);i.updateTiming({delay:e.secondsToMilliseconds(null!==(o=r.delay)&&void 0!==o?o:0),duration:r.duration,easing:d}),c.push(new u(t))}}t(new i(c))})})}function lt(t,e){var n;return null===(n=null==t?void 0:t[e])||void 0===n?void 0:n.keyframes.opacity}class dt{constructor(t,n={}){this.currentTarget="root",this.targets=new Map,this.notifyReady=e.noop,this.readyPromise=new Promise(t=>{this.notifyReady=t}),queueMicrotask(()=>{ut(t,n,this.targets).then(t=>this.notifyReady(t))})}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.GroupPlaybackControls=class extends i{then(t,e){return Promise.all(this.animations).then(t).catch(e)}},t.MotionValue=Q,t.NativeAnimationControls=u,t.ViewTransitionBuilder=dt,t.activeAnimations=K,t.attachTimeline=c,t.calcGeneratorDuration=s,t.cancelFrame=A,t.cancelMicrotask=M,t.capturePointer=D,t.collectMotionValues=J,t.createGeneratorEasing=o,t.createRenderBatcher=w,t.cubicBezierAsString=f,t.frame=E,t.frameData=P,t.frameSteps=b,t.generateLinearEasing=p,t.getValueTransition=a,t.hover=function(t,e,n={}){const[i,a,s]=j(t,n),o=t=>{if(!F(t))return;const{target:n}=t,i=e(n,t);if("function"!=typeof i||!n)return;const s=t=>{F(t)&&(i(t),n.removeEventListener("pointerleave",s))};n.addEventListener("pointerleave",s,a)};return i.forEach(t=>{t.addEventListener("pointerenter",o,a)}),s},t.isBezierDefinition=l,t.isDragActive=R,t.isDragging=L,t.isGenerator=r,t.isNodeOrChild=N,t.isPrimaryPointer=O,t.isWaapiSupportedEasing=function t(e){return Boolean("function"==typeof e&&m()||!e||"string"==typeof e&&(e in v||m())||l(e)||Array.isArray(e)&&e.every(t))},t.mapEasingToNativeEasing=y,t.maxGeneratorDuration=2e4,t.microtask=x,t.motionValue=function(t,e){return new Q(t,e)},t.press=function(t,e,n={}){const[i,a,s]=j(t,n),o=t=>{const n=t.currentTarget;if(!n||!$(t)||q.has(n))return;q.add(n),D(t,"set");const i=e(n,t),s=(t,e)=>{n.removeEventListener("pointerup",o),n.removeEventListener("pointercancel",r),D(t,"release"),$(t)&&q.has(n)&&(q.delete(n),"function"==typeof i&&i(t,{success:e}))},o=t=>{const e=!!t.isTrusted&&(i=t,a=n instanceof Element?n.getBoundingClientRect():{left:0,top:0,right:window.innerWidth,bottom:window.innerHeight},i.clientX<a.left||i.clientX>a.right||i.clientY<a.top||i.clientY>a.bottom);var i,a;s(t,!e&&(!(n instanceof Element)||N(n,t.target)))},r=t=>{s(t,!1)};n.addEventListener("pointerup",o,a),n.addEventListener("pointercancel",r,a),n.addEventListener("lostpointercapture",r,a)};return i.forEach(t=>{let e=!1;var i;(t=n.useGlobalTarget?window:t)instanceof HTMLElement&&(e=!0,i=t,B.has(i.tagName)||-1!==i.tabIndex||null!==t.getAttribute("tabindex")||(t.tabIndex=0)),t.addEventListener("pointerdown",o,a),e&&t.addEventListener("focus",t=>((t,e)=>{const n=t.currentTarget;if(!n)return;const i=G(()=>{if(q.has(n))return;I(n,"down");const t=G(()=>{I(n,"up")});n.addEventListener("keyup",t,e),n.addEventListener("blur",()=>I(n,"cancel"),e)});n.addEventListener("keydown",i,e),n.addEventListener("blur",()=>n.removeEventListener("keydown",i),e)})(t,a),a)}),s},t.recordStats=function(){if(T.value)throw H(),new Error("Stats are already being measured");const t=T;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)},E.postRender(U,!0),Y},t.resolveElements=V,t.setDragLock=function(t){return"x"===t||"y"===t?L[t]?null:(L[t]=!0,()=>{L[t]=!1}):L.x||L.y?null:(L.x=L.y=!0,()=>{L.x=L.y=!1})},t.statsBuffer=T,t.supportedWaapiEasing=v,t.supportsFlags=d,t.supportsLinearEasing=m,t.supportsScrollTimeline=n,t.time=C,t.view=function(t,e={}){return new dt(t,e)}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motion-dom",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.5.0",
|
|
4
4
|
"author": "Matt Perry",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/motiondivision/motion",
|
|
@@ -16,12 +16,13 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"motion-utils": "^12.
|
|
19
|
+
"motion-utils": "^12.5.0"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"clean": "rm -rf types dist lib",
|
|
23
23
|
"build": "yarn clean && tsc -p . && rollup -c",
|
|
24
|
-
"dev": "concurrently -c blue,red -n tsc,rollup --kill-others \"tsc --watch -p . --preserveWatchOutput\" \"rollup --config --watch --no-watch.clearScreen\""
|
|
24
|
+
"dev": "concurrently -c blue,red -n tsc,rollup --kill-others \"tsc --watch -p . --preserveWatchOutput\" \"rollup --config --watch --no-watch.clearScreen\"",
|
|
25
|
+
"test": "jest --config jest.config.json --max-workers=2 motion-value.test"
|
|
25
26
|
},
|
|
26
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "cd754fc49a206e7dd4572c0cd9620bbad629e89a"
|
|
27
28
|
}
|