@ssgoi/core 7.3.0-beta.2 → 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.2",
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")}}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 ut(s,r,t){if(!s||s==="none")return[...U];let e=[...U];const i=/([a-zA-Z][a-zA-Z0-9]*)\(([^()]*)\)/g;let a="";for(const c of s.matchAll(i)){a+=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 m=u.map(Number.parseFloat);if(m.some(n=>!Number.isFinite(n)))return null;const g=(n,y)=>{var o;return m[n]*((o=u[n])!=null&&o.endsWith("%")?y/100:1)},p=n=>{var y,o;return m[n]*((y=u[n])!=null&&y.endsWith("rad")?1:(o=u[n])!=null&&o.endsWith("turn")?2*Math.PI:Math.PI/180)};let l;if(d==="matrix"&&m.length===6)l=m;else if(d==="translate"||d==="translate3d"){if(d==="translate3d"&&m[2]!==0)return null;l=B(g(0,r),u[1]?g(1,t):0)}else if(d==="translatex")l=B(g(0,r),0);else if(d==="translatey")l=B(0,g(0,t));else if(d==="translatez"&&m[0]===0)l=[...U];else if(d==="scale")l=K(m[0],m[1]??m[0]);else if(d==="scalex")l=K(m[0],1);else if(d==="scaley")l=K(1,m[0]);else if(d==="rotate"||d==="rotatez"){const n=p(0);l=[Math.cos(n),Math.sin(n),-Math.sin(n),Math.cos(n),0,0]}else return null;e=nt(e,l)}return a.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),a=e%3;return s[i*3]*r[a]+s[i*3+1]*r[a+3]+s[i*3+2]*r[a+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=ut(s,r,t);if(e)return M(e);if(typeof DOMMatrix>"u")return null;const i=s.replace(/(translate(?:3d|X|Y)?)\(([^()]*)\)/gi,(a,c,d)=>{const u=d.split(/\s*,\s*|\s+/).map((m,g)=>{if(!m.endsWith("%"))return m;const p=c.toLowerCase()==="translatey"||g===1?t:r;return`${Number.parseFloat(m)*p/100}px`});return`${c}(${u.join(",")})`});try{const a=new DOMMatrix(i);return at([a.m11,a.m21,a.m41,a.m12,a.m22,a.m42,a.m14,a.m24,a.m44])}catch{return null}}const rt="viewport-plane-v1";function N(s){var w;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(" "),a=Number.parseFloat(i[0])||0,c=Number.parseFloat(i[1])||0;let d=!0;if(typeof getComputedStyle=="function")for(let C=s.parentElement;C;C=C.parentElement){const S=getComputedStyle(C);if(S.transform&&S.transform!=="none"||S.perspective&&S.perspective!=="none"){d=!1;break}}const u=(w=s.getBoundingClientRect)==null?void 0:w.call(s),m=it((e==null?void 0:e.transform)||"",r,t)??M(U),g=O(O(M(B(a,c)),m),M(B(-a,-c))),p=[[0,0],[r,0],[0,t],[r,t]].map(([C,S])=>{const F=g[6]*C+g[7]*S+g[8];return[(g[0]*C+g[1]*S+g[2])/F,(g[3]*C+g[4]*S+g[5])/F]}),l=((u==null?void 0:u.left)??0)-Math.min(...p.map(C=>C[0])),n=((u==null?void 0:u.top)??0)-Math.min(...p.map(C=>C[1])),y=B(l+a,n+c),o=nt(B(-a,-c),K(r,t)),f=M(tt(y)),b=M(tt(o));return{frame:d?{left:l,top:n,width:r,height:t}:void 0,read(C){const S={};for(const[F,_]of Object.entries(C)){const k=String(_);if(F==="transform"){if(!d)continue;const T=it(k,r,t),V=T&&at(O(O(M(y),T),M(o)));if(V){const[W,z,P,E,D,I,j,v]=V,L=W-P*j,$=E-I*j,J=z-P*v,Q=D-I*v,H=Math.hypot(L,$);if(H>1e-8){S[F]=et(rt,[P,I,Math.atan2($,L),H,(L*Q-$*J)/H,(L*J+$*Q)/H,j,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(C){const S={};for(const[F,_]of Object.entries(C))if(F==="transform"&&_.schema===rt){const[k,R,T,V,W,z,P,E]=_.value,D=Math.cos(T),I=Math.sin(T),j=[D*V+k*P,D*z-I*W+k*E,k,I*V+R*P,I*z+D*W+R*E,R,P,E,1],v=O(O(f,j),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 dt=1e3/60,ot=1e3/30,pt=ot+1;class ft{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?dt: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 ft,mt=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,a;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),(a=this.onComplete)==null||a.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 a,c;this.running&&this.captureLiveState();const t=this.samplePresentation(q(this.waapi)??this.presentationTime),e=this.paused||this.waitingForStart&&!q(this.waapi)?0:this.playbackRate,i={...this.styleFn(this.currentValue,this.lowerBound+this.upperBound-this.currentValue),...(a=this.codec)==null?void 0:a.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(m=>m*e)}]))}}adopt(t){var d,u,m,g,p;this.codec??(this.codec=this.motion.codec??N(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),a=t.displayStyle;for(const[l,n]of Object.entries(a??{}))l in i&&String(n)!==String(i[l])&&(!t.channels[l]||!e[l])&&this.fallbackChannels.add(l);for(const[l,n]of Object.entries(t.channels)){const y=e[l];y&&!A.compatibleChannel(n,y)&&this.fallbackChannels.add(l)}if(this.fallbackChannels.size&&(this.fallbackMode="finish"),this.fallbackChannels.size&&this.motion.fallback!=="finish"){const l=t;if(l.frame&&l.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=(m=t.target).querySelector)!=null&&g.call(m,"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 o of n.querySelectorAll("[id], [data-ssgoi-transition]"))o.removeAttribute("id"),o.removeAttribute("data-ssgoi-transition");n.style.cssText=l.inlineStyle??"",Object.assign(n.style,l.displayStyle,{position:"fixed",left:`${l.frame.left}px`,top:`${l.frame.top}px`,width:`${l.frame.width}px`,height:`${l.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(l.displayStyle.opacity??1);this.fallbackCopy=new Y({element:n,integrator:{step:(o,f,b)=>({position:Math.min(f,o.position+b/.18),velocity:0}),isSettled:(o,f)=>o.position>=f},style:(o,f)=>({opacity:y*f}),onDispose:()=>n.remove()}),this.adopted={...t,channels:{...t.channels,opacity:{schema:"css:#",value:[0],velocity:[0]}}}}}const c=this.codec.write(this.adopted.channels);(p=this.hold)==null||p.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??N(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??N(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 a=Math.max(0,i-1),c=e[a],d=e[i],u=this.channelsAt(a),m=a===i?u:this.channelsAt(i),g=(d.time-c.time)/1e3,p=g?Math.max(0,Math.min(1,(t-c.time)/(g*1e3))):0,l={};for(const[n,y]of Object.entries(u)){const o=m[n];if(!o||!A.compatibleChannel(y,o)){l[n]=y;continue}l[n]={schema:y.schema,value:y.value.map((f,b)=>f+(o.value[b]-f)*p),velocity:y.value.map((f,b)=>t>=e[e.length-1].time||!g?0:(o.value[b]-f)/g)}}return l}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 a=e.position,c=this.lowerBound+this.upperBound-a;return{time:e.time,value:e.position,velocity:e.velocity,style:this.renderedStyles[i]??this.styleFn(a,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 m,g;if(this.validate(),this.running||this.paused){const p=this.getMotionSnapshot();this.captureLiveState(),this.adopted=p}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=p=>this.styleFn(p.position,this.lowerBound+this.upperBound-p.position),i=this.adopted?this.bridgeKeyframes(e):this.frames.map(p=>e(p));this.renderedStyles=i,this.adopted=void 0;const a=i[0],c=this.frames[this.frames.length-1],d=c.time;this.runId++;const u=this._element.animate(i,{duration:d,fill:"both",easing:"linear",composite:"replace"});u.playbackRate=this.playbackRate,u.currentTime=0,u.pause(),this.waapi=u,(m=this.fallbackCopy)==null||m.play(),(g=this.hold)==null||g.cancel(),this.hold=null,this.waitingForStart=!0,this.startReady=!0,this.pendingFirstFrame=a,this.running=!0,u.onfinish=()=>{!this.running||this.waapi!==u||(this.running=!1,this.settled=!0,this.currentValue=c.position,this.currentVelocity=0,this.finish())},this.startFramePacedPlayback(u)}bridgeKeyframes(t){var g;this.codec=this.motion.codec??N(this.element);const e=this.codec,i=Math.max(16,this.motion.handoffDuration??280),a=this.frames[this.frames.length-1];for(let p=a.time+1e3/60;p<i+1e3/60;p+=1e3/60)this.frames.push({time:p,position:a.position,velocity:0});const c=this.frames.map(p=>e.read({transform:"none",opacity:1,...t(p)}));for(let p=1;p<c.length;p++){const l=c[p-1].transform,n=c[p].transform;if((l==null?void 0:l.schema)==="viewport-plane-v1"&&(n==null?void 0:n.schema)===l.schema){const y=[...n.value];y[2]=l.value[2]+Math.atan2(Math.sin(y[2]-l.value[2]),Math.cos(y[2]-l.value[2])),c[p].transform={...n,value:y}}}const d=c[0],u=c[1]??d,m={};for(const[p,l]of Object.entries(((g=this.adopted)==null?void 0:g.channels)??{})){let n=d[p];if(!n){const o=p==="transform"?{transform:"none"}:p==="opacity"?{opacity:1}:{};if(n=e.read(o)[p],n)for(const f of c)f[p]=n}if(!n||!A.compatibleChannel(l,n))continue;const y=u[p]??n;m[p]={offset:l.value.map((o,f)=>{let b=o-n.value[f];return p==="transform"&&l.schema==="viewport-plane-v1"&&f===2&&(b=Math.atan2(Math.sin(b),Math.cos(b))),b}),velocity:l.velocity.map((o,f)=>o/Math.max(Math.abs(this.playbackRate),1e-4)-(y.value[f]-n.value[f])*60)}}return this.presentationFrames=this.frames.map((p,l)=>{const n={...c[l]};for(const[y,o]of Object.entries(m)){const f=n[y];n[y]={...f,value:f.value.map((b,w)=>b+A.residualAt(o.offset[w],o.velocity[w],p.time/1e3,i/1e3).value)}}return{time:p.time,channels:n}}),this.frames.map((p,l)=>{const n=this.presentationFrames[l].channels;return{...t(p),...e.write(Object.fromEntries(Object.keys(m).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=q(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)}startFramePacedPlayback(t){if(!(this.waapi!==t||!this.waitingForStart||!this.startReady||this.stopStartupClock)){if(typeof requestAnimationFrame>"u"||this.playbackRate<0){this.clearStartStyles(),this.handOffToWaapi(t);return}this.startupStableFrames=0,this.stopStartupClock=lt.subscribe(e=>{this.advanceFramePacedStartup(t,e)})}}clearStartStyles(){if(this.pendingFirstFrame)for(const t of Object.keys(this.pendingFirstFrame))this._element.style[t]="";this.pendingFirstFrame=void 0}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 a=q(t)??0,c=Math.min(i.time,a+e.delta*Math.max(0,this.playbackRate));if(t.currentTime=c,this.clearStartStyles(),this.captureLiveState(),c>=i.time){this.finishFramePacedRun(t,i);return}e.rawDelta<=pt?this.startupStableFrames++:this.startupStableFrames=0,!(this.startupStableFrames<mt)&&this.handOffToWaapi(t)}handOffToWaapi(t){var c,d;if(this.waapi!==t||!this.running||this.paused)return;(c=this.stopStartupClock)==null||c.call(this),this.stopStartupClock=null,this.waitingForStart=!1,this.startReady=!1,this.startupStableFrames=0;const e=(d=t.timeline)==null?void 0:d.currentTime,i=q(t),a=this.playbackRate;if(typeof e=="number"&&i!==null&&a!==0){t.startTime=e-i/a;return}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[a,c]of Object.entries(i))this._element.style[a]=typeof c=="number"?String(c):c}}function q(s){const r=s==null?void 0:s.currentTime;return typeof r=="number"?r:null}function gt(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,a)=>a===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:gt(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,a=t!==this.lastMethod,c=new Set(this.startedChildren),d=new Set(this._children.filter(o=>o.isComplete)),u=t==="reverse"&&c.size?this._children.filter(o=>c.has(o)):[...this._children],m=t==="reverse"?[...u].reverse():u,g=new Map;if(t==="reverse")for(const[o,f]of e){if(!u.includes(o)||!u.includes(f.after))continue;const b=g.get(f.after)??[];b.push({after:o,at:f.at==="settled"?"settled":1-f.at}),g.set(f.after,b)}else for(const[o,f]of e)g.set(o,[f]);if(a||i)for(const o of c)d.has(o)||g.delete(o);this.running&&this.pause(),this.restoreCompletionHandlers();const p=++this.runId;if(this.running=!0,this.pausedRun=!1,this.lastMethod=t,this.disposed=!1,this.settled=!1,this.pendingComplete=u.length,!i&&!a&&this.startedChildren.clear(),this.pendingComplete===0){this.handleFinished();return}const l=new Set,n=new Set;if(i)for(const o of u)c.has(o)&&d.has(o)&&(n.add(o),l.add(o),this.pendingComplete--);for(const o of u){const f=o.onComplete,b=()=>{if(!(this.runId!==p||!this.running||l.has(o))){try{f==null||f()}catch(w){console.error("[ssgoi] animation completion failed",w)}l.add(o),--this.pendingComplete===0&&this.handleFinished()}};o.onComplete=b,this.restoreChildCallbacks.push(()=>{o.onComplete===b&&(o.onComplete=f)})}const y=()=>{let o=!0;for(;this.running&&this.runId===p&&o;){o=!1;for(const f of m)!this.running||n.has(f)||(g.get(f)??[]).some(w=>!n.has(w.after)||!this.hasReachedThreshold(w.after,w.at,t))||(n.add(f),this.startedChildren.add(f),f[t](),o=!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 m=d.startCondition;if(m){if(!e.has(m.after))throw new Error("startAt.after must reference a sibling in the same MultiAnimation");t.set(d,{...m})}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,a=new Set,c=d=>{if(a.has(d))throw new Error("Animation startAt dependencies form a cycle");if(i.has(d))return;a.add(d);const u=t.get(d);u&&c(u.after),a.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 yt(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),a=i[i.length-1];(a==null?void 0:a.value)!==void 0&&(s.style.opacity=String(a.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=N;exports.finishedDisposal=x;exports.retainOpacity=yt;