Files

2 lines
122 KiB
JavaScript
Raw Permalink Normal View History

!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=["setup","read","resolveKeyframes","preUpdate","update","preRender","render","postRender"];function i(t,i){let s=!1,o=!0;const r={delta:0,timestamp:0,isProcessing:!1},a=()=>s=!0,l=n.reduce((t,e)=>(t[e]=function(t){let e=new Set,n=new Set,i=!1,s=!1;const o=new WeakSet;let r={delta:0,timestamp:0,isProcessing:!1};function a(e){o.has(e)&&(l.schedule(e),t()),e(r)}const l={schedule:(t,s=!1,r=!1)=>{const a=r&&i?e:n;return s&&o.add(t),a.add(t),t},cancel:t=>{n.delete(t),o.delete(t)},process:t=>{if(r=t,i)return void(s=!0);i=!0;const o=e;e=n,n=o,e.forEach(a),e.clear(),i=!1,s&&(s=!1,l.process(t))}};return l}(a),t),{}),{setup:c,read:u,resolveKeyframes:h,preUpdate:d,update:p,preRender:m,render:f,postRender:y}=l,g=()=>{const n=e.MotionGlobalConfig.useManualTiming,a=n?r.timestamp:performance.now();s=!1,n||(r.delta=o?1e3/60:Math.max(Math.min(a-r.timestamp,40),1)),r.timestamp=a,r.isProcessing=!0,c.process(r),u.process(r),h.process(r),d.process(r),p.process(r),m.process(r),f.process(r),y.process(r),r.isProcessing=!1,s&&i&&(o=!1,t(g))};return{schedule:n.reduce((e,n)=>{const i=l[n];return e[n]=(e,n=!1,a=!1)=>(s||(s=!0,o=!0,r.isProcessing||t(g)),i.schedule(e,n,a)),e},{}),cancel:t=>{for(let e=0;e<n.length;e++)l[n[e]].cancel(t)},state:r,steps:l}}const{schedule:s,cancel:o,state:r,steps:a}=i("undefined"!=typeof requestAnimationFrame?requestAnimationFrame:e.noop,!0);let l;function c(){l=void 0}const u={now:()=>(void 0===l&&u.set(r.isProcessing||e.MotionGlobalConfig.useManualTiming?r.timestamp:performance.now()),l),set:t=>{l=t,queueMicrotask(c)}},h=t=>e=>"string"==typeof e&&e.startsWith(t),d=h("--"),p=h("var(--"),m=t=>!!p(t)&&f.test(t.split("/*")[0].trim()),f=/var\(--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)$/iu;function y(t){return"string"==typeof t&&t.split("/*")[0].includes("var(--")}const g={test:t=>"number"==typeof t,parse:parseFloat,transform:t=>t},v={...g,transform:t=>e.clamp(0,1,t)},x={...g,default:1},T=t=>Math.round(1e5*t)/1e5,w=/-?(?:\d+(?:\.\d+)?|\.\d+)/gu;const b=/^(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))$/iu,S=(t,e)=>n=>Boolean("string"==typeof n&&b.test(n)&&n.startsWith(t)||e&&!function(t){return null==t}(n)&&Object.prototype.hasOwnProperty.call(n,e)),A=(t,e,n)=>i=>{if("string"!=typeof i)return i;const[s,o,r,a]=i.match(w);return{[t]:parseFloat(s),[e]:parseFloat(o),[n]:parseFloat(r),alpha:void 0!==a?parseFloat(a):1}},V={...g,transform:t=>Math.round((t=>e.clamp(0,255,t))(t))},P={test:S("rgb","red"),parse:A("red","green","blue"),transform:({red:t,green:e,blue:n,alpha:i=1})=>"rgba("+V.transform(t)+", "+V.transform(e)+", "+V.transform(n)+", "+T(v.transform(i))+")"};const M={test:S("#"),parse:function(t){let e="",n="",i="",s="";return t.length>5?(e=t.substring(1,3),n=t.substring(3,5),i=t.substring(5,7),s=t.substring(7,9)):(e=t.substring(1,2),n=t.substring(2,3),i=t.substring(3,4),s=t.substring(4,5),e+=e,n+=n,i+=i,s+=s),{red:parseInt(e,16),green:parseInt(n,16),blue:parseInt(i,16),alpha:s?parseInt(s,16)/255:1}},transform:P.transform},k=t=>({test:e=>"string"==typeof e&&e.endsWith(t)&&1===e.split(" ").length,parse:parseFloat,transform:e=>`${e}${t}`}),E=k("deg"),D=k("%"),C=k("px"),R=k("vh"),B=k("vw"),j=(()=>({...D,parse:t=>D.parse(t)/100,transform:t=>D.transform(100*t)}))(),L={test:S("hsl","hue"),parse:A("hue","saturation","lightness"),transform:({hue:t,saturation:e,lightness:n,alpha:i=1})=>"hsla("+Math.round(t)+", "+D.transform(T(e))+", "+D.transform(T(n))+", "+T(v.transform(i))+")"},F={test:t=>P.test(t)||M.test(t)||L.test(t),parse:t=>P.test(t)?P.parse(t):L.test(t)?L.parse(t):M.parse(t),transform:t=>"string"==typeof t?t:t.hasOwnProperty("red")?P.transform(t):L.transform(t),getAnimatableNone:t=>{const e=F.parse(t);return e.alpha=0,F.transform(e)}}