@ssgoi/core 7.3.0-beta.1 → 7.3.0-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssgoi/core",
3
- "version": "7.3.0-beta.1",
3
+ "version": "7.3.0-beta.3",
4
4
  "description": "Core animation engine for SSGOI - Native app-like page transitions with spring physics",
5
5
  "private": false,
6
6
  "type": "module",
@@ -1 +0,0 @@
1
- "use strict";var ht=Object.defineProperty;var ct=(s,r,t)=>r in s?ht(s,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[r]=t;var h=(s,r,t)=>ct(s,typeof r!="symbol"?r+"":r,t);const A=require("./provider-JDtJ5Jzf.cjs"),x={reason:"finished",owns:()=>!0};class Z extends A.Animation{constructor(){super(...arguments);h(this,"_startCondition");h(this,"onDispose");h(this,"deferDisposal",!1)}getMotionTracks(){return[]}validate(){}get supportsInterruption(){return!1}stop(){this.pause()}cancel(t){var e;this.isComplete||this.complete(),(e=this.onDispose)==null||e.call(this,t)}get startCondition(){return this._startCondition}set(t){if(t.startAt){const{after:e,at:i}=t.startAt;if(e===this)throw new Error("An animation cannot start after itself");if(i!=="settled"&&(!Number.isFinite(i)||i<0||i>1))throw new Error("startAt.at must be a progress from 0 to 1 or settled")}if(t.integrator!==void 0){if(typeof t.integrator.step!="function"||typeof t.integrator.isSettled!="function")throw new Error("An integrator must implement step and isSettled");this.setIntegrator(t.integrator)}return t.startAt!==void 0&&(this._startCondition=t.startAt?{...t.startAt}:void 0),this}setIntegrator(t){throw new Error("This animation does not support replacing its integrator")}}function ut(s){return new Promise(r=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{r()})})})}const U=[1,0,0,1,0,0],nt=(s,r)=>[s[0]*r[0]+s[2]*r[1],s[1]*r[0]+s[3]*r[1],s[0]*r[2]+s[2]*r[3],s[1]*r[2]+s[3]*r[3],s[0]*r[4]+s[2]*r[5]+s[4],s[1]*r[4]+s[3]*r[5]+s[5]];function tt(s){const r=s[0]*s[3]-s[1]*s[2];return Math.abs(r)<1e-10?null:[s[3]/r,-s[1]/r,-s[2]/r,s[0]/r,(s[2]*s[5]-s[3]*s[4])/r,(s[1]*s[4]-s[0]*s[5])/r]}const B=(s,r)=>[1,0,0,1,s,r],K=(s,r)=>[s,0,0,r,0,0];function dt(s,r,t){if(!s||s==="none")return[...U];let e=[...U];const i=/([a-zA-Z][a-zA-Z0-9]*)\(([^()]*)\)/g;let o="";for(const c of s.matchAll(i)){o+=c[0];const d=c[1].toLowerCase(),u=c[2].trim().split(/\s*,\s*|\s+/);if(u.some(n=>!/^[-+]?(?:\d*\.\d+|\d+\.?\d*)(?:e[-+]?\d+)?(?:px|%|deg|rad|turn)?$/i.test(n)))return null;const p=u.map(Number.parseFloat);if(p.some(n=>!Number.isFinite(n)))return null;const g=(n,y)=>{var l;return p[n]*((l=u[n])!=null&&l.endsWith("%")?y/100:1)},f=n=>{var y,l;return p[n]*((y=u[n])!=null&&y.endsWith("rad")?1:(l=u[n])!=null&&l.endsWith("turn")?2*Math.PI:Math.PI/180)};let a;if(d==="matrix"&&p.length===6)a=p;else if(d==="translate"||d==="translate3d"){if(d==="translate3d"&&p[2]!==0)return null;a=B(g(0,r),u[1]?g(1,t):0)}else if(d==="translatex")a=B(g(0,r),0);else if(d==="translatey")a=B(0,g(0,t));else if(d==="translatez"&&p[0]===0)a=[...U];else if(d==="scale")a=K(p[0],p[1]??p[0]);else if(d==="scalex")a=K(p[0],1);else if(d==="scaley")a=K(1,p[0]);else if(d==="rotate"||d==="rotatez"){const n=f(0);a=[Math.cos(n),Math.sin(n),-Math.sin(n),Math.cos(n),0,0]}else return null;e=nt(e,a)}return o.replace(/\s/g,"")===s.replace(/\s/g,"")?e:null}function et(s,r){return{schema:s,value:r,velocity:r.map(()=>0)}}const st=/[-+]?(?:\d*\.\d+|\d+\.?\d*)(?:e[-+]?\d+)?/gi,M=s=>[s[0],s[2],s[4],s[1],s[3],s[5],0,0,1];function O(s,r){return Array.from({length:9},(t,e)=>{const i=Math.floor(e/3),o=e%3;return s[i*3]*r[o]+s[i*3+1]*r[o+3]+s[i*3+2]*r[o+6]})}function at(s){return Math.abs(s[8])<1e-8||!s.every(Number.isFinite)?null:s.map(r=>r/s[8])}function it(s,r,t){const e=dt(s,r,t);if(e)return M(e);if(typeof DOMMatrix>"u")return null;const i=s.replace(/(translate(?:3d|X|Y)?)\(([^()]*)\)/gi,(o,c,d)=>{const u=d.split(/\s*,\s*|\s+/).map((p,g)=>{if(!p.endsWith("%"))return p;const f=c.toLowerCase()==="translatey"||g===1?t:r;return`${Number.parseFloat(p)*f/100}px`});return`${c}(${u.join(",")})`});try{const o=new DOMMatrix(i);return at([o.m11,o.m21,o.m41,o.m12,o.m22,o.m42,o.m14,o.m24,o.m44])}catch{return null}}const rt="viewport-plane-v1";function j(s){var C;const r=s.offsetWidth||1,t=s.offsetHeight||1,e=typeof getComputedStyle=="function"?getComputedStyle(s):null,i=((e==null?void 0:e.transformOrigin)||`${r/2}px ${t/2}px`).split(" "),o=Number.parseFloat(i[0])||0,c=Number.parseFloat(i[1])||0;let d=!0;if(typeof getComputedStyle=="function")for(let w=s.parentElement;w;w=w.parentElement){const S=getComputedStyle(w);if(S.transform&&S.transform!=="none"||S.perspective&&S.perspective!=="none"){d=!1;break}}const u=(C=s.getBoundingClientRect)==null?void 0:C.call(s),p=it((e==null?void 0:e.transform)||"",r,t)??M(U),g=O(O(M(B(o,c)),p),M(B(-o,-c))),f=[[0,0],[r,0],[0,t],[r,t]].map(([w,S])=>{const F=g[6]*w+g[7]*S+g[8];return[(g[0]*w+g[1]*S+g[2])/F,(g[3]*w+g[4]*S+g[5])/F]}),a=((u==null?void 0:u.left)??0)-Math.min(...f.map(w=>w[0])),n=((u==null?void 0:u.top)??0)-Math.min(...f.map(w=>w[1])),y=B(a+o,n+c),l=nt(B(-o,-c),K(r,t)),m=M(tt(y)),b=M(tt(l));return{frame:d?{left:a,top:n,width:r,height:t}:void 0,read(w){const S={};for(const[F,_]of Object.entries(w)){const k=String(_);if(F==="transform"){if(!d)continue;const T=it(k,r,t),V=T&&at(O(O(M(y),T),M(l)));if(V){const[W,N,P,E,D,I,q,v]=V,z=W-P*q,L=E-I*q,J=N-P*v,Q=D-I*v,$=Math.hypot(z,L);if($>1e-8){S[F]=et(rt,[P,I,Math.atan2(L,z),$,(z*Q-L*J)/$,(z*J+L*Q)/$,q,v]);continue}}}const R=[...k.matchAll(st)].map(T=>Number(T[0]));R.length&&R.every(Number.isFinite)&&(S[F]=et(`css:${k.replace(st,"#")}`,R))}return S},write(w){const S={};for(const[F,_]of Object.entries(w))if(F==="transform"&&_.schema===rt){const[k,R,T,V,W,N,P,E]=_.value,D=Math.cos(T),I=Math.sin(T),q=[D*V+k*P,D*N-I*W+k*E,k,I*V+R*P,I*N+D*W+R*E,R,P,E,1],v=O(O(m,q),b);Math.abs(v[6])+Math.abs(v[7])<1e-10&&Math.abs(v[8]-1)<1e-10?S[F]=`matrix(${[v[0],v[3],v[1],v[4],v[2],v[5]].join(",")})`:S[F]=`matrix3d(${[v[0],v[3],0,v[6],v[1],v[4],0,v[7],0,0,1,0,v[2],v[5],0,v[8]].join(",")})`}else if(_.schema.startsWith("css:")){let k=0;S[F]=_.schema.slice(4).replace(/#/g,()=>String(_.value[k++]))}return S}}}const pt=1e3/60,ot=1e3/30,ft=ot+1;class mt{constructor(){h(this,"drivers",new Set);h(this,"observers",new Set);h(this,"frameRequest",null);h(this,"previousTimestamp",null);h(this,"tick",r=>{this.frameRequest=null;const t=this.previousTimestamp===null?pt:Math.max(0,r-this.previousTimestamp);this.previousTimestamp=r;const e={delta:Math.min(t,ot),rawDelta:t};this.runPhase(this.drivers,e),this.runPhase(this.observers,e),this.hasCallbacks()?this.requestFrame():this.previousTimestamp=null})}subscribe(r,t="drive"){const e=t==="drive"?this.drivers:this.observers;return e.add(r),this.requestFrame(),()=>{e.delete(r),this.stopIfIdle()}}requestFrame(){this.frameRequest!==null||!this.hasCallbacks()||(this.frameRequest=requestAnimationFrame(this.tick))}runPhase(r,t){for(const e of[...r])r.has(e)&&e(t)}hasCallbacks(){return this.drivers.size>0||this.observers.size>0}stopIfIdle(){this.hasCallbacks()||(this.frameRequest!==null&&typeof cancelAnimationFrame<"u"&&cancelAnimationFrame(this.frameRequest),this.frameRequest=null,this.previousTimestamp=null)}}const lt=new mt,gt=2;class Y extends Z{constructor(t){super();h(this,"_element");h(this,"_integrator");h(this,"label");h(this,"styleFn");h(this,"lowerBound");h(this,"upperBound");h(this,"currentValue");h(this,"currentVelocity",0);h(this,"solverState");h(this,"solverTarget",1);h(this,"presentationTime",0);h(this,"renderedStyles",[]);h(this,"frames",[]);h(this,"waapi",null);h(this,"runId",0);h(this,"waitingForStart",!1);h(this,"startReady",!1);h(this,"pendingFirstFrame");h(this,"stopStartupClock",null);h(this,"startupStableFrames",0);h(this,"running",!1);h(this,"paused",!1);h(this,"settled",!1);h(this,"reversing",!1);h(this,"disposed",!1);h(this,"legacyCompletionCleanup");h(this,"motion");h(this,"codec");h(this,"adopted");h(this,"presentationFrames",[]);h(this,"hold",null);h(this,"fallbackCopy",null);h(this,"fallbackChannels",new Set);h(this,"fallbackMode");this._element=t.element,this._integrator=t.integrator,this.label=t.label,this.styleFn=t.style,this.lowerBound=t.lowerBound??0,this.upperBound=t.upperBound??1,this.currentValue=this.lowerBound,this.onUpdate=t.onUpdate,this.legacyCompletionCleanup=!!t.onComplete&&!t.onDispose,this.onComplete=t.onComplete,this.onDispose=t.onDispose,this.motion=t.motion??{}}get handoffFallbackMode(){return this.fallbackMode}get handoffFallbacks(){return[...this.fallbackChannels]}get element(){return this._element}get integrator(){return this._integrator}set integrator(t){this._integrator=t,this.solverState=void 0}setIntegrator(t){this._integrator=t,this.solverState=void 0}play(){var e;const t=this.reversing;if(this.reversing=!1,this.paused&&this.waapi&&!t){if(this.paused=!1,this.running=!0,this.waitingForStart){this.startReady&&this.startFramePacedPlayback(this.waapi);return}this.waapi.play(),(e=this.fallbackCopy)==null||e.play();return}this.runToward(this.upperBound)}reverse(){this.reversing=!0,this.runToward(this.lowerBound)}pause(){var t,e,i;this.running&&(this.captureLiveState(),(t=this.waapi)==null||t.pause(),(e=this.fallbackCopy)==null||e.pause(),(i=this.stopStartupClock)==null||i.call(this),this.stopStartupClock=null,this.running=!1,this.paused=!0)}complete(){this.settled||(this.clearWaapi(),this.running=!1,this.paused=!1,this.currentValue=this.upperBound,this.currentVelocity=0,this.applyStyleAt(this.currentValue),this.settled=!0,this.finish())}validate(){const t=this.motion.handoffDuration??280;if(!Number.isFinite(t)||t<0||t>1e4)throw new Error("handoffDuration must be finite and between 0 and 10000 ms")}getMotionTracks(){return[this]}get supportsInterruption(){return!this.legacyCompletionCleanup}stop(){var t,e;this.captureLiveState(),this.clearWaapi(),(t=this.hold)==null||t.cancel(),this.hold=null,(e=this.fallbackCopy)==null||e.cancel({reason:"disposed",owns:()=>!0}),this.fallbackCopy=null,this.running=!1,this.paused=!1}cancel(t){this.stop(),this.disposeResources(t)}disposeResources(t){var e;if(!this.disposed&&(this.disposed=!0,t.owns(this.element)))try{(e=this.onDispose)==null||e.call(this,t)}catch(i){console.error("[ssgoi] animation cleanup failed",i)}}finish(){var t,e,i,o;this.presentationTime=((t=this.frames[this.frames.length-1])==null?void 0:t.time)??0,this.solverState=void 0,(e=this.hold)==null||e.cancel(),this.hold=null,this.applyStyleAt(this.currentValue),this.clearWaapi(),(i=this.fallbackCopy)==null||i.cancel({reason:"disposed",owns:()=>!0}),this.fallbackCopy=null,this.deferDisposal||this.disposeResources(x),(o=this.onComplete)==null||o.call(this)}get motionIdentity(){return{target:this.element,key:this.motion.key,role:this.motion.role,space:this.motion.space,lifetime:this.motion.lifetime}}getMotionSnapshot(){var o,c;this.running&&this.captureLiveState();const t=this.samplePresentation(H(this.waapi)??this.presentationTime),e=this.paused||this.waitingForStart&&!H(this.waapi)?0:this.playbackRate,i={...this.styleFn(this.currentValue,this.lowerBound+this.upperBound-this.currentValue),...(o=this.codec)==null?void 0:o.write(t)};return{...this.motionIdentity,displayStyle:i,inlineStyle:this.element.style.cssText,frame:(c=this.codec)==null?void 0:c.frame,channels:Object.fromEntries(Object.entries(t).map(([d,u])=>[d,{...u,velocity:u.velocity.map(p=>p*e)}]))}}adopt(t){var d,u,p,g,f;this.codec??(this.codec=this.motion.codec??j(this.element)),this.adopted=t;const e=this.codec.read({transform:"none",opacity:1,...this.styleFn(this.currentValue,this.lowerBound+this.upperBound-this.currentValue)});this.fallbackChannels.clear(),this.fallbackMode=void 0;const i=this.styleFn(this.currentValue,this.lowerBound+this.upperBound-this.currentValue),o=t.displayStyle;for(const[a,n]of Object.entries(o??{}))a in i&&String(n)!==String(i[a])&&(!t.channels[a]||!e[a])&&this.fallbackChannels.add(a);for(const[a,n]of Object.entries(t.channels)){const y=e[a];y&&!A.compatibleChannel(n,y)&&this.fallbackChannels.add(a)}if(this.fallbackChannels.size&&(this.fallbackMode="finish"),this.fallbackChannels.size&&this.motion.fallback!=="finish"){const a=t;if(a.frame&&a.displayStyle&&t.target.cloneNode&&t.target.parentElement&&!t.target.shadowRoot&&!((u=(d=t.target).matches)!=null&&u.call(d,"canvas, video, audio, iframe, object, embed"))&&!((g=(p=t.target).querySelector)!=null&&g.call(p,"canvas, video, audio, iframe, object, embed"))){this.fallbackMode="crossfade";const n=t.target.cloneNode(!0);n.removeAttribute("id"),n.removeAttribute("data-ssgoi-transition");for(const l of n.querySelectorAll("[id], [data-ssgoi-transition]"))l.removeAttribute("id"),l.removeAttribute("data-ssgoi-transition");n.style.cssText=a.inlineStyle??"",Object.assign(n.style,a.displayStyle,{position:"fixed",left:`${a.frame.left}px`,top:`${a.frame.top}px`,width:`${a.frame.width}px`,height:`${a.frame.height}px`,margin:"0",pointerEvents:"none",zIndex:"2147483646"}),n.setAttribute("aria-hidden","true"),n.inert=!0,t.target.parentElement.appendChild(n);const y=Number(a.displayStyle.opacity??1);this.fallbackCopy=new Y({element:n,integrator:{step:(l,m,b)=>({position:Math.min(m,l.position+b/.18),velocity:0}),isSettled:(l,m)=>l.position>=m},style:(l,m)=>({opacity:y*m}),onDispose:()=>n.remove()}),this.adopted={...t,channels:{...t.channels,opacity:{schema:"css:#",value:[0],velocity:[0]}}}}}const c=this.codec.write(this.adopted.channels);(f=this.hold)==null||f.cancel(),Object.keys(c).length&&(this.hold=this.element.animate([c],{duration:1,fill:"both"}),this.hold.pause(),this.hold.currentTime=0)}channelsAt(t){const e=this.presentationFrames[t];if(e)return e.channels;const i=this.frames[t];return this.codec??(this.codec=this.motion.codec??j(this.element)),this.codec.read({transform:"none",opacity:1,...this.styleFn(i.position,this.lowerBound+this.upperBound-i.position)})}samplePresentation(t){const e=this.frames;if(!e.length)return this.adopted?{...this.adopted.channels}:(this.codec??(this.codec=this.motion.codec??j(this.element)),this.codec.read({transform:"none",opacity:1,...this.styleFn(this.currentValue,this.lowerBound+this.upperBound-this.currentValue)}));let i=e.findIndex(n=>n.time>t);i<0&&(i=e.length-1);const o=Math.max(0,i-1),c=e[o],d=e[i],u=this.channelsAt(o),p=o===i?u:this.channelsAt(i),g=(d.time-c.time)/1e3,f=g?Math.max(0,Math.min(1,(t-c.time)/(g*1e3))):0,a={};for(const[n,y]of Object.entries(u)){const l=p[n];if(!l||!A.compatibleChannel(y,l)){a[n]=y;continue}a[n]={schema:y.schema,value:y.value.map((m,b)=>m+(l.value[b]-m)*f),velocity:y.value.map((m,b)=>t>=e[e.length-1].time||!g?0:(l.value[b]-m)/g)}}return a}releaseFill(){this.clearWaapi()}get isAnimating(){return this.running}get isPaused(){return this.paused}get isComplete(){return this.settled}get isReversing(){return this.reversing}get progress(){this.running&&this.captureLiveState();const t=this.upperBound-this.lowerBound;if(t===0)return 0;const e=(this.currentValue-this.lowerBound)/t;return e<0?0:e>1?1:e}findTimeForProgress(t){if(this.frames.length<2)return null;const e=this.upperBound-this.lowerBound;if(e===0)return 0;for(const i of this.frames)if((i.position-this.lowerBound)/e>=t)return i.time;return this.frames[this.frames.length-1].time}get playbackRate(){return super.playbackRate}set playbackRate(t){super.playbackRate=t,this.waapi&&(this.waapi.playbackRate=t)}getPose(){return this.running&&this.captureLiveState(),[{element:this._element,value:this.currentValue,velocity:this.currentVelocity}]}getTimeline(){const t=this.frames.map((e,i)=>{const o=e.position,c=this.lowerBound+this.upperBound-o;return{time:e.time,value:e.position,velocity:e.velocity,style:this.renderedStyles[i]??this.styleFn(o,c)}});return[{element:this._element,frames:t}]}matchInto(t){const e=t.find(i=>i.element===this._element);e&&(this.currentValue=e.value,this.currentVelocity=e.velocity,this.solverState=void 0)}runToward(t){var g,f;if(this.validate(),this.running||this.paused){const a=this.getMotionSnapshot();this.captureLiveState(),this.adopted=a}if(this.clearWaapi(),this.running=!1,this.paused=!1,this.settled=!1,this.disposed=!1,this.presentationTime=0,this.presentationFrames=[],this.solverTarget=t,this.frames=A.simulate(this._integrator,this.currentValue,t,this.currentVelocity,this.solverState,!0),this.frames.length===0&&this.adopted&&(this.frames=[{time:0,position:t,velocity:0}]),this.frames.length===0){this.currentValue=t,this.currentVelocity=0,this.applyStyleAt(t),this.settled=!0,this.finish();return}const e=a=>this.styleFn(a.position,this.lowerBound+this.upperBound-a.position),i=this.adopted?this.bridgeKeyframes(e):this.frames.map(a=>e(a));this.renderedStyles=i,this.adopted=void 0;const o=i[0],c=this.frames[this.frames.length-1],d=c.time,u=++this.runId,p=this._element.animate(i,{duration:d,fill:"both",easing:"linear",composite:"replace"});p.playbackRate=this.playbackRate,p.currentTime=0,p.pause(),this.waapi=p,(g=this.fallbackCopy)==null||g.play(),(f=this.hold)==null||f.cancel(),this.hold=null,this.waitingForStart=!0,this.startReady=!1,this.pendingFirstFrame=o,this.running=!0,p.onfinish=()=>{!this.running||this.waapi!==p||(this.running=!1,this.settled=!0,this.currentValue=c.position,this.currentVelocity=0,this.finish())},this.startWhenReady(p,u)}bridgeKeyframes(t){var g;this.codec=this.motion.codec??j(this.element);const e=this.codec,i=Math.max(16,this.motion.handoffDuration??280),o=this.frames[this.frames.length-1];for(let f=o.time+1e3/60;f<i+1e3/60;f+=1e3/60)this.frames.push({time:f,position:o.position,velocity:0});const c=this.frames.map(f=>e.read({transform:"none",opacity:1,...t(f)}));for(let f=1;f<c.length;f++){const a=c[f-1].transform,n=c[f].transform;if((a==null?void 0:a.schema)==="viewport-plane-v1"&&(n==null?void 0:n.schema)===a.schema){const y=[...n.value];y[2]=a.value[2]+Math.atan2(Math.sin(y[2]-a.value[2]),Math.cos(y[2]-a.value[2])),c[f].transform={...n,value:y}}}const d=c[0],u=c[1]??d,p={};for(const[f,a]of Object.entries(((g=this.adopted)==null?void 0:g.channels)??{})){let n=d[f];if(!n){const l=f==="transform"?{transform:"none"}:f==="opacity"?{opacity:1}:{};if(n=e.read(l)[f],n)for(const m of c)m[f]=n}if(!n||!A.compatibleChannel(a,n))continue;const y=u[f]??n;p[f]={offset:a.value.map((l,m)=>{let b=l-n.value[m];return f==="transform"&&a.schema==="viewport-plane-v1"&&m===2&&(b=Math.atan2(Math.sin(b),Math.cos(b))),b}),velocity:a.velocity.map((l,m)=>l/Math.max(Math.abs(this.playbackRate),1e-4)-(y.value[m]-n.value[m])*60)}}return this.presentationFrames=this.frames.map((f,a)=>{const n={...c[a]};for(const[y,l]of Object.entries(p)){const m=n[y];n[y]={...m,value:m.value.map((b,C)=>b+A.residualAt(l.offset[C],l.velocity[C],f.time/1e3,i/1e3).value)}}return{time:f.time,channels:n}}),this.frames.map((f,a)=>{const n=this.presentationFrames[a].channels;return{...t(f),...e.write(Object.fromEntries(Object.keys(p).map(y=>[y,n[y]])))}})}clearWaapi(){var t,e;this.runId++,(t=this.waapi)==null||t.cancel(),this.waapi=null,this.waitingForStart=!1,this.startReady=!1,this.pendingFirstFrame=void 0,(e=this.stopStartupClock)==null||e.call(this),this.stopStartupClock=null,this.startupStableFrames=0}captureLiveState(){if(this.frames.length===0)return;const t=H(this.waapi);if(t===null)return;this.presentationTime=t;const{position:e,velocity:i}=A.interpolateFrame(this.frames,t);this.currentValue=e,this.currentVelocity=i,this.solverState=A.sampleIntegratorState(this.frames,t,this._integrator,this.solverTarget)}async startWhenReady(t,e){try{await t.ready,typeof requestAnimationFrame<"u"&&await ut(this._element)}catch{return}this.runId!==e||this.waapi!==t||(this.startReady=!0,!(!this.running||this.paused)&&this.startFramePacedPlayback(t))}startFramePacedPlayback(t){if(!(this.waapi!==t||!this.waitingForStart||!this.startReady||this.stopStartupClock)){if(this.pendingFirstFrame)for(const e of Object.keys(this.pendingFirstFrame))this._element.style[e]="";if(this.pendingFirstFrame=void 0,typeof requestAnimationFrame>"u"||this.playbackRate<0){this.handOffToWaapi(t);return}this.startupStableFrames=0,this.stopStartupClock=lt.subscribe(e=>{this.advanceFramePacedStartup(t,e)})}}advanceFramePacedStartup(t,e){if(this.waapi!==t||!this.running||this.paused||!this.waitingForStart)return;const i=this.frames[this.frames.length-1];if(!i)return;const o=H(t)??0,c=Math.min(i.time,o+e.delta*Math.max(0,this.playbackRate));if(t.currentTime=c,this.captureLiveState(),c>=i.time){this.finishFramePacedRun(t,i);return}e.rawDelta<=ft?this.startupStableFrames++:this.startupStableFrames=0,!(this.startupStableFrames<gt)&&this.handOffToWaapi(t)}handOffToWaapi(t){var e;this.waapi!==t||!this.running||this.paused||((e=this.stopStartupClock)==null||e.call(this),this.stopStartupClock=null,this.waitingForStart=!1,this.startReady=!1,this.startupStableFrames=0,t.play())}finishFramePacedRun(t,e){var i;this.waapi!==t||!this.running||((i=this.stopStartupClock)==null||i.call(this),this.stopStartupClock=null,this.waitingForStart=!1,this.startReady=!1,this.startupStableFrames=0,this.running=!1,this.settled=!0,this.currentValue=e.position,this.currentVelocity=0,this.finish())}applyStyleAt(t){const e=this.lowerBound+this.upperBound-t,i=this.styleFn(t,e);for(const[o,c]of Object.entries(i))this._element.style[o]=typeof c=="number"?String(c):c}}function H(s){const r=s==null?void 0:s.currentTime;return typeof r=="number"?r:null}function yt(s){return typeof s.step=="function"?s:A.IntegratorProvider.from(s)}class G extends Z{constructor(t,e={}){super();h(this,"_children");h(this,"progressChildren");h(this,"_startAt");h(this,"namedChildren");h(this,"restoreChildCallbacks",[]);h(this,"runId",0);h(this,"pendingComplete",0);h(this,"running",!1);h(this,"disposed",!1);h(this,"settled",!1);h(this,"startedChildren",new Set);h(this,"lastMethod","play");h(this,"pausedRun",!1);h(this,"pendingStartObservers",[]);this.namedChildren=new Map(Array.isArray(t)?[]:Object.entries(t)),this._children=Array.isArray(t)?[...t]:[...this.namedChildren.values()];for(const i of this._children)i.deferDisposal=!0;this.progressChildren=this._children.filter(i=>!(i instanceof G)||i.progressChildren.length>0),(e.mode??"parallel")==="sequence"?this._startAt=this._children.map((i,o)=>o===0?0:1):this._startAt=e.startAt??[]}get children(){return this._children}get startAt(){return this._startAt}set startAt(t){this._startAt=t}tracks(){return this._children.flatMap(t=>[...t.getMotionTracks()])}getMotionTracks(){return this.tracks()}validate(){this.buildDependencies();for(const t of this._children)t.validate()}select(t){const e=this.namedChildren.get(t);if(!e)throw new Error(`Unknown animation child: ${t}`);return e}set(t,e){if(typeof t=="string"){const i=this.select(t);return(e==null?void 0:e.integrator)!==void 0&&i.set({integrator:yt(e.integrator)}),this}return super.set(t)}setIntegrator(t){for(const e of this._children)e.set({integrator:t})}play(){this.startRun("play")}reverse(){this.startRun("reverse")}pause(){this.pausedRun=this.running||this.pausedRun,this.running=!1,this.clearPendingStartObservers();for(const t of this._children)t.pause()}complete(){var t;if(!this.settled){this.settled=!0,this.running=!1,this.clearPendingStartObservers(),this.restoreCompletionHandlers();for(const e of this._children)e.complete();if(!this.deferDisposal){for(const e of this._children)e.cancel(x);this.disposeResources(x)}(t=this.onComplete)==null||t.call(this)}}get supportsInterruption(){return this._children.every(t=>t.supportsInterruption)}stop(){this.runId++,this.running=!1,this.clearPendingStartObservers(),this.restoreCompletionHandlers();for(const t of this._children)t.stop()}cancel(t){this.stop();for(const e of this._children)e.cancel(t);this.disposeResources(t)}disposeResources(t){var e;if(!this.disposed){this.disposed=!0;try{(e=this.onDispose)==null||e.call(this,t)}catch(i){console.error("[ssgoi] composite cleanup failed",i)}}}get progress(){if(this.progressChildren.length===0)return 0;let t=0;for(const e of this.progressChildren)t+=e.progress;return t/this.progressChildren.length}getPose(){return this._children.flatMap(t=>t.getPose())}getTimeline(){return this._children.flatMap(t=>t.getTimeline())}matchInto(t){for(const e of this._children)e.matchInto(t)}get isAnimating(){return this._children.some(t=>t.isAnimating)}get isPaused(){return this._children.some(t=>t.isPaused)&&this._children.every(t=>t.isPaused||t.isComplete)}get isComplete(){return this.settled}get isReversing(){return this._children.some(t=>t.isReversing)}get playbackRate(){return super.playbackRate}set playbackRate(t){super.playbackRate=t;for(const e of this._children)e.playbackRate=t}startRun(t){const e=this.buildDependencies(),i=this.pausedRun&&t===this.lastMethod,o=t!==this.lastMethod,c=new Set(this.startedChildren),d=new Set(this._children.filter(l=>l.isComplete)),u=t==="reverse"&&c.size?this._children.filter(l=>c.has(l)):[...this._children],p=t==="reverse"?[...u].reverse():u,g=new Map;if(t==="reverse")for(const[l,m]of e){if(!u.includes(l)||!u.includes(m.after))continue;const b=g.get(m.after)??[];b.push({after:l,at:m.at==="settled"?"settled":1-m.at}),g.set(m.after,b)}else for(const[l,m]of e)g.set(l,[m]);if(o||i)for(const l of c)d.has(l)||g.delete(l);this.running&&this.pause(),this.restoreCompletionHandlers();const f=++this.runId;if(this.running=!0,this.pausedRun=!1,this.lastMethod=t,this.disposed=!1,this.settled=!1,this.pendingComplete=u.length,!i&&!o&&this.startedChildren.clear(),this.pendingComplete===0){this.handleFinished();return}const a=new Set,n=new Set;if(i)for(const l of u)c.has(l)&&d.has(l)&&(n.add(l),a.add(l),this.pendingComplete--);for(const l of u){const m=l.onComplete,b=()=>{if(!(this.runId!==f||!this.running||a.has(l))){try{m==null||m()}catch(C){console.error("[ssgoi] animation completion failed",C)}a.add(l),--this.pendingComplete===0&&this.handleFinished()}};l.onComplete=b,this.restoreChildCallbacks.push(()=>{l.onComplete===b&&(l.onComplete=m)})}const y=()=>{let l=!0;for(;this.running&&this.runId===f&&l;){l=!1;for(const m of p)!this.running||n.has(m)||(g.get(m)??[]).some(C=>!n.has(C.after)||!this.hasReachedThreshold(C.after,C.at,t))||(n.add(m),this.startedChildren.add(m),m[t](),l=!0)}n.size===u.length&&this.clearPendingStartObservers()};y(),this.pendingComplete===0&&this.handleFinished(),this.running&&n.size!==u.length&&this.pendingStartObservers.push(lt.subscribe(y,"observe"))}buildDependencies(){const t=new Map,e=new Set(this._children);if(e.size!==this._children.length)throw new Error("Each child animation must occur once in a MultiAnimation");this._children.forEach((d,u)=>{const p=d.startCondition;if(p){if(!e.has(p.after))throw new Error("startAt.after must reference a sibling in the same MultiAnimation");t.set(d,{...p})}else u>0&&this._startAt.some(g=>g>0)&&t.set(d,{after:this._children[u-1],at:this._startAt[u]??0})});const i=new Set,o=new Set,c=d=>{if(o.has(d))throw new Error("Animation startAt dependencies form a cycle");if(i.has(d))return;o.add(d);const u=t.get(d);u&&c(u.after),o.delete(d),i.add(d)};return this._children.forEach(c),t}hasReachedThreshold(t,e,i){return t.isComplete?!0:e==="settled"?!1:e<=0?!0:(i==="play"?t.progress:1-t.progress)>=e}clearPendingStartObservers(){for(const t of this.pendingStartObservers)t();this.pendingStartObservers=[]}restoreCompletionHandlers(){for(const t of this.restoreChildCallbacks)t();this.restoreChildCallbacks=[]}handleFinished(){var t;if(this.running){if(this.running=!1,this.settled=!0,this.clearPendingStartObservers(),this.restoreCompletionHandlers(),!this.deferDisposal){for(const e of this._children)e.cancel(x);this.disposeResources(x)}(t=this.onComplete)==null||t.call(this)}}findTimeForProgress(t){return null}}const X=new WeakMap;function vt(s){const r=X.get(s)??{value:s.style.getPropertyValue("opacity"),priority:s.style.getPropertyPriority("opacity"),opacity:typeof getComputedStyle=="function"?Number.parseFloat(getComputedStyle(s).opacity):Number.NaN,users:new Set},t={};r.users.add(t),X.set(s,r);let e=!1;return{opacity:Number.isFinite(r.opacity)?r.opacity:1,set:i=>{t.value=i,s.style.opacity=String(i)},restore:()=>{if(!e){if(e=!0,r.users.delete(t),r.users.size>0){const i=Array.from(r.users),o=i[i.length-1];(o==null?void 0:o.value)!==void 0&&(s.style.opacity=String(o.value));return}r.value?s.style.setProperty("opacity",r.value,r.priority):s.style.removeProperty("opacity"),X.delete(s)}}}}exports.Animation=Z;exports.MultiAnimation=G;exports.WebAnimation=Y;exports.createWebPresentationCodec=j;exports.finishedDisposal=x;exports.retainOpacity=vt;