@ssgoi/core 3.0.0 → 3.1.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/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var K=Object.defineProperty;var W=(n,i,t)=>i in n?K(n,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[i]=t;var d=(n,i,t)=>W(n,typeof i!="symbol"?i+"":i,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("./types.cjs"),U=require("./jaemin-BG8HRXG1.cjs");class G{constructor(){d(this,"listeners",new Set);d(this,"rafId",null);d(this,"isRunning",!1);d(this,"startTime",Date.now());d(this,"lastUpdate",this.startTime);d(this,"elapsed",0);d(this,"lagThreshold",500);d(this,"adjustedLag",33);d(this,"maxDeltaTime",33);d(this,"gap",1e3/240);d(this,"nextTime",this.gap);d(this,"tick",()=>{const i=Date.now();let e=i-this.lastUpdate;e>this.lagThreshold||e<0?(this.startTime+=e-this.adjustedLag,e=this.adjustedLag):e>this.maxDeltaTime&&(e=this.maxDeltaTime),this.lastUpdate=i;const r=i-this.startTime,o=r-this.nextTime;if(o>0){const s=e/1e3;this.elapsed=r/1e3,this.nextTime+=o+(o>=this.gap?4:this.gap-o),this.listeners.forEach(c=>{c(s,this.elapsed)})}this.listeners.size>0?this.rafId=requestAnimationFrame(this.tick):(this.isRunning=!1,this.rafId=null)})}subscribe(i){return this.listeners.add(i),this.isRunning||(this.isRunning=!0,this.rafId=requestAnimationFrame(this.tick)),()=>{this.unsubscribe(i)}}unsubscribe(i){this.listeners.delete(i),this.listeners.size===0&&this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.isRunning=!1,this.rafId=null)}lagSmoothing(i,t){this.lagThreshold=i,this.adjustedLag=Math.min(t,i)}fps(i){this.gap=1e3/i,this.nextTime=this.elapsed*1e3+this.gap}getListenerCount(){return this.listeners.size}getElapsed(){return this.elapsed}}const P=new G;function L(n){const i=n.stiffness,t=n.damping,e=1,r=Math.sqrt(i/e),o=t/(2*Math.sqrt(i*e));return{omega:r,zeta:o}}function _(n,i,t,e){const{omega:r,zeta:o}=t,{position:s,velocity:c}=n,a=Math.min(e,.033),u=-2*a*o*r*c,h=a*r*r*(i-s),l=c+u+h;return{position:s+a*l,velocity:l}}const B=.01,J=.01,N=.05;function H(n,i){const t=Math.abs(i-n.position),e=Math.abs(n.velocity);return t<B&&e<J}function Q(n){const{from:i,to:t,spring:e,velocity:r=0,onUpdate:o,onComplete:s,onStart:c}=n;let a={position:i,velocity:r},u=!0,h=0,l=!1;const g=L(e),w=p=>{if(u){if(l||(l=!0,c==null||c()),a=_(a,t,g,p),H(a,t)){if(h+=Math.min(p,.033),h>=N){a={position:t,velocity:0},u=!1,o(a.position),P.unsubscribe(w),s();return}}else h=0;o(a.position)}};return P.subscribe(w),{stop:()=>{u&&(u=!1,P.unsubscribe(w))},getPosition:()=>a.position,getVelocity:()=>a.velocity,isRunning:()=>u}}const V=1e3/60;function Z(n,i,t,e=0){const r=L(t),o=600;let s={position:n,velocity:e},c=0;const a=[];for(let u=0;u<o;u++){const h=u*V;if(a.push({time:h,position:s.position,velocity:s.velocity}),s=_(s,i,r,V/1e3),H(s,i)){if(c+=V/1e3,c>=N){a.push({time:(u+1)*V,position:i,velocity:0});break}}else c=0}return a}function F(n,i){if(n.length===0)return{position:0,velocity:0};const t=n[0],e=n[n.length-1];if(i<=0)return{position:t.position,velocity:t.velocity};if(i>=e.time)return{position:e.position,velocity:e.velocity};let r=0,o=n.length-1;for(;r<o-1;){const u=Math.floor((r+o)/2);n[u].time<=i?r=u:o=u}const s=n[r],c=n[o],a=(i-s.time)/(c.time-s.time);return{position:s.position+(c.position-s.position)*a,velocity:s.velocity+(c.velocity-s.velocity)*a}}function tt(n,i){return n.map(t=>i(t.position))}function et(n){const{element:i,from:t,to:e,spring:r,velocity:o=0,style:s,onComplete:c,onStart:a}=n,u=Z(t,e,r,o);if(u.length===0)return a==null||a(),c(),{stop:()=>{},getPosition:()=>e,getVelocity:()=>0,isRunning:()=>!1};const h=tt(u,s),l=u[u.length-1],g=l.time,w=i.animate(h,{duration:g,fill:"forwards",easing:"linear"});let p=!0;const y=performance.now();return a==null||a(),w.onfinish=()=>{p&&(p=!1,c())},{stop:()=>{p&&(p=!1,w.cancel())},getPosition:()=>{if(!p)return l.position;const m=performance.now()-y;return F(u,m).position},getVelocity:()=>{if(!p)return 0;const m=performance.now()-y;return F(u,m).velocity},isRunning:()=>p}}function it(n){const{from:i,to:t,spring:e,velocity:r,onComplete:o,onStart:s,tick:c,css:a}=n;if(c&&a)throw new Error("Cannot use both 'tick' and 'css' options together");return!c&&!a?(s==null||s(),o(),{stop:()=>{},getPosition:()=>t,getVelocity:()=>0,isRunning:()=>!1}):a?et({element:a.element,from:i,to:t,spring:e,velocity:r,style:a.style,onComplete:o,onStart:s}):Q({from:i,to:t,spring:e,velocity:r,onUpdate:c,onComplete:o,onStart:s})}class q{}class k extends q{constructor(t){super();d(this,"options");d(this,"controls",null);d(this,"isAnimating",!1);d(this,"currentValue");d(this,"currentVelocity",0);if(t.tick&&t.css)throw new Error("Cannot use both 'tick' and 'css' options together");this.options={from:t.from??0,to:t.to??1,spring:t.spring??{stiffness:300,damping:30},tick:t.tick,css:t.css,onComplete:t.onComplete??(()=>{}),onStart:t.onStart},this.currentValue=this.options.from}runAnimation(t){this.isAnimating=!0,this.controls=it({from:this.currentValue,to:t,spring:this.options.spring,velocity:this.currentVelocity,tick:this.options.tick,css:this.options.css,onStart:this.options.onStart,onComplete:()=>{this.currentValue=t,this.currentVelocity=0,this.isAnimating=!1,this.controls=null,this.options.onComplete()}})}forward(){this.stop(),this.runAnimation(this.options.to)}backward(){this.stop(),this.runAnimation(this.options.from)}reverse(){const t=this.options.from;this.options.from=this.options.to,this.options.to=t,this.isAnimating&&(this.stop(),this.runAnimation(this.options.to))}stop(){this.controls&&(this.currentValue=this.controls.getPosition(),this.currentVelocity=this.controls.getVelocity(),this.controls.stop(),this.controls=null),this.isAnimating=!1}getVelocity(){var t;return((t=this.controls)==null?void 0:t.getVelocity())??this.currentVelocity}getCurrentValue(){var t;return((t=this.controls)==null?void 0:t.getPosition())??this.currentValue}getIsAnimating(){return this.isAnimating}getCurrentState(){return{position:this.getCurrentValue(),velocity:this.getVelocity(),from:this.options.from,to:this.options.to}}setValue(t){this.currentValue=t}setVelocity(t){this.currentVelocity=t}updateOptions(t){this.options={...this.options,...t}}static fromState(t,e){const r=new k(e);return r.setValue(t.position),r.setVelocity(t.velocity),r}}class M extends q{constructor(t){super();d(this,"config");d(this,"animators",new Map);d(this,"springOrder",[]);d(this,"completedCount",0);d(this,"completedAnimators",new Set);d(this,"direction","forward");d(this,"idCounter",0);d(this,"rafId",null);d(this,"element");d(this,"from");d(this,"to");this.config=t.config,this.from=t.from,this.to=t.to,this.element=t.element,this.initializeAnimators()}generateId(){return`spring_${this.idCounter++}`}initializeAnimators(){this.config.springs.forEach(t=>{const e=this.generateId(),r=new k({from:this.from,to:this.to,spring:t.spring,tick:t.tick,css:t.css&&this.element?{element:this.element,style:t.css}:void 0,onComplete:()=>this.onAnimatorComplete(e),onStart:t.onStart});this.animators.set(e,{id:e,item:t,animator:r,started:!1}),this.springOrder.push(e)})}getAnimatorProgress(t){const e=t.animator.getCurrentState(),r=Math.abs(e.to-e.from);return r===0?1:Math.abs(e.position-e.from)/r}getOrderedIds(){return this.direction==="forward"?this.springOrder:[...this.springOrder].reverse()}onAnimatorComplete(t){var r,o,s,c,a,u;const e=this.animators.get(t);!e||this.completedAnimators.has(t)||(this.completedAnimators.add(t),this.completedCount++,(o=(r=e.item).onComplete)==null||o.call(r),(c=(s=this.config).onProgress)==null||c.call(s,this.completedCount,this.config.springs.length),this.completedCount===this.config.springs.length&&(this.stopScheduler(),(u=(a=this.config).onEnd)==null||u.call(a)))}checkAndStartSprings(){const t=this.getOrderedIds();for(let e=0;e<t.length;e++){const r=t[e],o=this.animators.get(r);if(!o||o.started)continue;if(e===0){this.startAnimator(r);continue}const s=t[e-1],c=this.animators.get(s);if(!c||!c.started)continue;const a=this.getAnimatorProgress(c),u=o.item.normalizedOffset;a>=u&&this.startAnimator(r)}}startAnimator(t){const e=this.animators.get(t);!e||e.started||(e.started=!0,this.direction==="forward"?e.animator.forward():e.animator.backward())}startScheduler(){const t=()=>{this.checkAndStartSprings(),this.getIsAnimating()&&(this.rafId=requestAnimationFrame(t))};this.rafId=requestAnimationFrame(t)}stopScheduler(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}getFirstAnimator(){var e;const t=this.springOrder[0];return t?((e=this.animators.get(t))==null?void 0:e.animator)??null:null}forward(){var t,e;this.stop(),this.direction="forward",this.completedCount=0,this.completedAnimators.clear(),this.resetStartedFlags(),(e=(t=this.config).onStart)==null||e.call(t),this.startScheduler()}backward(){var t,e;this.stop(),this.direction="backward",this.completedCount=0,this.completedAnimators.clear(),this.resetStartedFlags(),(e=(t=this.config).onStart)==null||e.call(t),this.startScheduler()}resetStartedFlags(){this.animators.forEach(t=>{t.started=!1})}stop(){this.stopScheduler(),this.animators.forEach(t=>{t.animator.stop(),t.started=!1})}reverse(){this.direction=this.direction==="forward"?"backward":"forward",this.animators.forEach(t=>{if(!t.started)return;const e=t.animator.getCurrentState();if(e.position===e.to){const o=t.item.css&&this.element?{element:this.element,style:t.item.css}:void 0,s=k.fromState({position:this.to,velocity:0},{from:this.to,to:this.from,spring:t.item.spring,tick:t.item.tick,css:o,onComplete:()=>this.onAnimatorComplete(t.id),onStart:t.item.onStart});s.forward(),t.animator=s}else t.animator.reverse()})}getCurrentState(){const t=this.getFirstAnimator();return t?t.getCurrentState():{position:0,velocity:0,from:0,to:1}}getCurrentValue(){const t=this.getFirstAnimator();return(t==null?void 0:t.getCurrentValue())??0}getVelocity(){const t=this.getFirstAnimator();return(t==null?void 0:t.getVelocity())??0}setValue(t){const e=this.getFirstAnimator();e==null||e.setValue(t)}setVelocity(t){const e=this.getFirstAnimator();e==null||e.setVelocity(t)}getIsAnimating(){for(const t of this.animators.values())if(t.animator.getIsAnimating())return!0;return!1}static fromState(t,e){const r=new M(e);return r.setValue(t.position),r.setVelocity(t.velocity),r}}const O=Symbol.for("TRANSITION_STRATEGY"),Y=n=>({runIn:async i=>{const{currentAnimation:t}=n;if(t&&t.direction==="out"){const r=t.controller.getCurrentValue(),o=t.controller.getVelocity();if(t.controller.stop(),i.out)return{config:i.out,state:{position:r,velocity:o},from:1,to:0,direction:"backward"}}const e=i.in;return e?{config:e,state:{position:0,velocity:0},from:0,to:1,direction:"forward"}:{state:{position:0,velocity:0},from:0,to:1,direction:"forward"}},runOut:async i=>{const{currentAnimation:t}=n;if(t&&t.direction==="in"){const r=t.controller.getCurrentValue(),o=t.controller.getVelocity();if(t.controller.stop(),i.in)return{config:i.in,state:{position:r,velocity:o},from:0,to:1,direction:"backward"}}const e=i.out;return e?{config:e,state:{position:1,velocity:0},from:1,to:0,direction:"forward"}:{state:{position:1,velocity:0},from:1,to:0,direction:"forward"}}}),j=()=>({runIn:async n=>{const i=n.in;return i?{config:i,state:{position:0,velocity:0},from:0,to:1,direction:"forward"}:{state:{position:0,velocity:0},from:0,to:1,direction:"forward"}},runOut:async n=>{const i=n.out;return i?{config:i,state:{position:1,velocity:0},from:1,to:0,direction:"forward"}:{state:{position:1,velocity:0},from:1,to:0,direction:"forward"}}});function nt(n,i){var h;let t=null,e=null,r=null,o=null;const s={get currentAnimation(){return t}},c=((h=i==null?void 0:i.strategy)==null?void 0:h.call(i,s))||Y(s),a=async l=>{var A;e&&(e.remove(),e=null);const g=n(),w=g.in&&await g.in(l),p=!(i!=null&&i.strategy)&&g.out?await g.out(l):void 0;if(!w)return;const y={in:S.normalizeToMultiSpring(w),out:p?S.normalizeToMultiSpring(p):void 0},m=await c.runIn(y);if(!m.config){t&&(t.direction="in");return}const f=m.config;(A=f.prepare)==null||A.call(f,l),f.wait&&await f.wait();const C=S.normalizeMultiSpringSchedule({...f,onEnd:()=>{var T;t=null,(T=f.onEnd)==null||T.call(f)}}),v=M.fromState(m.state,{config:C,from:m.from,to:m.to,element:l});t={controller:v,direction:"in"},m.direction==="forward"?v.forward():v.backward()},u=async l=>{var T;e=l;const g=n(),w=!(i!=null&&i.strategy)&&g.in?await g.in(l):void 0,p=g.out&&await g.out(l);if(!p)return;const y={in:w?S.normalizeToMultiSpring(w):void 0,out:S.normalizeToMultiSpring(p)},m=await c.runOut(y);if(!m.config){t&&(t.direction="out"),e&&(e.remove(),e=null);return}const f=m.config;(T=f.prepare)==null||T.call(f,l),A(),f.wait&&await f.wait();const C=S.normalizeMultiSpringSchedule({...f,onEnd:()=>{var I,E;(I=f.onEnd)==null||I.call(f),e&&(e.remove(),e=null),t=null,(E=i==null?void 0:i.onCleanupEnd)==null||E.call(i)}}),v=M.fromState(m.state,{config:C,from:m.from,to:m.to,element:l});t={controller:v,direction:"out"},m.direction==="forward"?v.forward():v.backward();function A(){!r||!e||(o&&r.contains(o)?r.insertBefore(e,o):r.appendChild(e))}};return l=>{if(l)return r=l.parentElement,o=l.nextElementSibling,a(l),()=>{if(l.isConnected){const g=l.cloneNode(!0);u(g)}else u(l)}}}const ot=3,rt=n=>{if(!n)return null;const i=n.split(`
2
- `).map(t=>t.trim());for(let t=ot;t<Math.min(i.length,6);t++){const e=i[t],r=e==null?void 0:e.match(/\(?([^):]+):(\d+):(\d+)\)?$/);if(!r)continue;const o=r[1]??"",s=r[2]??"0",c=r[3]??"0";return{file:o.split(/[\\/]/).pop()||o,line:s,column:c}}return null},R=new Map,x=new Map;function st(n,i,t){R.set(n,i);let e=x.get(n);return e||(e=nt(()=>{const r=R.get(n);return r||(console.warn(`Transition "${String(n)}" not found`),{})},{strategy:t,onCleanupEnd:()=>X(n)}),x.set(n,e),e)}function X(n){R.delete(n),x.delete(n)}function $(){const n=rt(new Error().stack);return n?`auto_${n.file}_${n.line}_${n.column}`:Symbol(`ssgoi_auto_${Date.now()}`)}const z=globalThis.FinalizationRegistry,D=z?new z(n=>{try{X(n)}catch{}}):void 0;function at(n){const i=n.key??$();if(n.ref&&D)try{D.register(n.ref,i)}catch{}return st(i,{in:n.in,out:n.out},n[O])}function ct(n){const i=n.filter(t=>t.symmetric).map(t=>({from:t.to,to:t.from,transition:t.transition}));return[...n,...i]}function lt(n){let i=!1,t=0,e=0,r=!1;const o=50,s=p=>{if(!n)return;const y=p.touches[0];y&&(r=y.clientX<o,r&&(t=y.clientX,e=y.clientY))},c=p=>{if(!n||!r)return;const y=p.touches[0];if(!y)return;const m=y.clientX-t,f=y.clientY-e;m>window.outerWidth/2-5&&Math.abs(m)>Math.abs(f)?i=!0:i=!1},a=()=>{n&&(r=!1,t=0,e=0)},u=()=>i,h=()=>{typeof window>"u"||n&&(window.addEventListener("touchstart",s,{passive:!0}),window.addEventListener("touchmove",c,{passive:!0}),window.addEventListener("touchend",a,{passive:!0}))},l=()=>{typeof window>"u"||(window.removeEventListener("touchstart",s),window.removeEventListener("touchmove",c),window.removeEventListener("touchend",a))};let g=0;return{initialize:h,cleanup:l,isSwipePending:u,resetSwipeDetection:()=>{g++,g>1&&(g=0,i=!1)}}}const ut=n=>{let i=n.parentElement;for(;i&&i!==document.body;){const t=window.getComputedStyle(i),e=t.overflow+t.overflowY+t.overflowX;if(e.includes("auto")||e.includes("scroll")||i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth)return i;i=i.parentElement}return document.documentElement},ft=n=>{let i=n.parentElement;for(;i&&i!==document.body;){const t=window.getComputedStyle(i).position;if(t==="relative"||t==="absolute"||t==="fixed"||t==="sticky")return i;i=i.parentElement}return document.body};function mt(){let n=null,i=null;const t=new Map;let e=null;const r=()=>{n&&e&&t.set(e,{x:n.scrollLeft,y:n.scrollTop})};return{initializeContext:(h,l)=>{i=h,n||(n=ut(h),(n===document.documentElement?window:n).addEventListener("scroll",r,{passive:!0})),e=l},calculateScrollOffset:(h,l)=>{const g=h&&t.has(h)?t.get(h):{x:0,y:0},w=l&&t.has(l)?t.get(l):{x:0,y:0};return{x:-w.x+g.x,y:-w.y+g.y}},getScrollContainer:()=>n,getPositionedParentElement:()=>i?ft(i):document.body,getScrollPosition:h=>h&&t.has(h)?t.get(h):{x:0,y:0}}}function b(n,i){if(i==="*")return!0;if(i.endsWith("/*")){const t=i.slice(0,-2);return n===t||n.startsWith(t+"/")}return n===i}function dt(n,i,t){for(const e of t)if(b(n,e.from)&&b(i,e.to))return e.transition;for(const e of t)if((e.from==="*"||b(n,e.from))&&(e.to==="*"||b(i,e.to)))return e.transition;return null}function ht(n){const{transitions:i=[],defaultTransition:t,middleware:e=(m,f)=>({from:m,to:f}),skipOnIosSwipe:r=!0}=n;let o=null;const s=ct(i),{initializeContext:c,calculateScrollOffset:a,getScrollContainer:u,getPositionedParentElement:h,getScrollPosition:l}=mt(),g=lt(r);g.initialize();function w(){if(o!=null&&o.from&&(o!=null&&o.to)){const{from:m,to:f}=e(o.from,o.to),v=dt(m,f,s)||t,A=a(o.from,o.to),T={scrollOffset:A,scroll:l(o.from),get scrollingElement(){return u()||document.documentElement},get positionedParent(){return h()}},I={scrollOffset:A,get scroll(){return o?l(o.to):{x:0,y:0}},get scrollingElement(){return u()||document.documentElement},get positionedParent(){return h()}};v&&(v.out&&o.outResolve&&o.outResolve(E=>v.out(E,T)),v.in&&o.inResolve&&o.inResolve(E=>v.in(E,I))),o=null}}const p=async(m,f)=>g.isSwipePending()?(g.resetSwipeDetection(),()=>({})):f==="in"&&(!o||!o.from)?()=>({}):(o||(o={}),f==="out"?(o.from=m,new Promise(C=>{o.outResolve=C,w()})):(o.to=m,new Promise(C=>{o.inResolve=C,w()})));return m=>({key:m,in:async f=>(c(f,m),(await p(m,"in"))(f)),out:async f=>(await p(m,"out"))(f),[O]:j})}exports.isCssAnimation=S.isCssAnimation;exports.isMultiSpring=S.isMultiSpring;exports.isSingleSpring=S.isSingleSpring;exports.isTickAnimation=S.isTickAnimation;exports.normalizeMultiSpringSchedule=S.normalizeMultiSpringSchedule;exports.normalizeToMultiSpring=S.normalizeToMultiSpring;exports.validateAnimationMode=S.validateAnimationMode;exports.validateSpringItem=S.validateSpringItem;exports.jaeminInternal=U.jaeminInternal;exports.TRANSITION_STRATEGY=O;exports.createDefaultStrategy=Y;exports.createPageTransitionStrategy=j;exports.createSggoiTransitionContext=ht;exports.generateAutoKey=$;exports.transition=at;
1
+ "use strict";var J=Object.defineProperty;var Q=(n,e,t)=>e in n?J(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var m=(n,e,t)=>Q(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("./types.cjs"),Z=require("./jaemin-BG8HRXG1.cjs");class tt{constructor(){m(this,"listeners",new Set);m(this,"rafId",null);m(this,"isRunning",!1);m(this,"startTime",Date.now());m(this,"lastUpdate",this.startTime);m(this,"elapsed",0);m(this,"lagThreshold",500);m(this,"adjustedLag",33);m(this,"maxDeltaTime",33);m(this,"gap",1e3/240);m(this,"nextTime",this.gap);m(this,"tick",()=>{const e=Date.now();let i=e-this.lastUpdate;i>this.lagThreshold||i<0?(this.startTime+=i-this.adjustedLag,i=this.adjustedLag):i>this.maxDeltaTime&&(i=this.maxDeltaTime),this.lastUpdate=e;const r=e-this.startTime,o=r-this.nextTime;if(o>0){const s=i/1e3;this.elapsed=r/1e3,this.nextTime+=o+(o>=this.gap?4:this.gap-o),this.listeners.forEach(c=>{c(s,this.elapsed)})}this.listeners.size>0?this.rafId=requestAnimationFrame(this.tick):(this.isRunning=!1,this.rafId=null)})}subscribe(e){return this.listeners.add(e),this.isRunning||(this.isRunning=!0,this.rafId=requestAnimationFrame(this.tick)),()=>{this.unsubscribe(e)}}unsubscribe(e){this.listeners.delete(e),this.listeners.size===0&&this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.isRunning=!1,this.rafId=null)}lagSmoothing(e,t){this.lagThreshold=e,this.adjustedLag=Math.min(t,e)}fps(e){this.gap=1e3/e,this.nextTime=this.elapsed*1e3+this.gap}getListenerCount(){return this.listeners.size}getElapsed(){return this.elapsed}}const V=new tt;function N(n){const e=n.stiffness,t=n.damping,i=1,r=Math.sqrt(e/i),o=t/(2*Math.sqrt(e*i));return{omega:r,zeta:o}}function Y(n,e,t,i){const{omega:r,zeta:o}=t,{position:s,velocity:c}=n,a=Math.min(i,.033),l=-2*a*o*r*c,f=a*r*r*(e-s),w=c+l+f;return{position:s+a*w,velocity:w}}const et=.01,it=.01,H=.05;function j(n,e){const t=Math.abs(e-n.position),i=Math.abs(n.velocity);return t<et&&i<it}function nt(n){const{from:e,to:t,spring:i,velocity:r=0,onUpdate:o,onComplete:s,onStart:c}=n;let a={position:e,velocity:r},l=!0,f=0,w=!1;const u=N(i),h=p=>{if(l){if(w||(w=!0,c==null||c()),a=Y(a,t,u,p),j(a,t)){if(f+=Math.min(p,.033),f>=H){a={position:t,velocity:0},l=!1,o(a.position),V.unsubscribe(h),s();return}}else f=0;o(a.position)}};return V.subscribe(h),{stop:()=>{l&&(l=!1,V.unsubscribe(h))},getPosition:()=>a.position,getVelocity:()=>a.velocity,isRunning:()=>l}}const b=1e3/60;function ot(n,e,t,i=0){const r=N(t),o=600;let s={position:n,velocity:i},c=0;const a=[];for(let l=0;l<o;l++){const f=l*b;if(a.push({time:f,position:s.position,velocity:s.velocity}),s=Y(s,e,r,b/1e3),j(s,e)){if(c+=b/1e3,c>=H){a.push({time:(l+1)*b,position:e,velocity:0});break}}else c=0}return a}function D(n,e){if(n.length===0)return{position:0,velocity:0};const t=n[0],i=n[n.length-1];if(e<=0)return{position:t.position,velocity:t.velocity};if(e>=i.time)return{position:i.position,velocity:i.velocity};let r=0,o=n.length-1;for(;r<o-1;){const l=Math.floor((r+o)/2);n[l].time<=e?r=l:o=l}const s=n[r],c=n[o],a=(e-s.time)/(c.time-s.time);return{position:s.position+(c.position-s.position)*a,velocity:s.velocity+(c.velocity-s.velocity)*a}}function rt(n,e){return n.map(t=>e(t.position))}function st(n){const{element:e,from:t,to:i,spring:r,velocity:o=0,style:s,onComplete:c,onStart:a}=n,l=ot(t,i,r,o);if(l.length===0)return a==null||a(),c(),{stop:()=>{},getPosition:()=>i,getVelocity:()=>0,isRunning:()=>!1};const f=rt(l,s),w=l[l.length-1],u=w.time,h=e.animate(f,{duration:u,fill:"forwards",easing:"linear"});let p=!0;const S=performance.now();return a==null||a(),h.onfinish=()=>{p&&(p=!1,c())},{stop:()=>{p&&(p=!1,h.cancel())},getPosition:()=>{if(!p)return w.position;const y=performance.now()-S;return D(l,y).position},getVelocity:()=>{if(!p)return 0;const y=performance.now()-S;return D(l,y).velocity},isRunning:()=>p}}function at(n){const{from:e,to:t,spring:i,velocity:r,onComplete:o,onStart:s,tick:c,css:a}=n;if(c&&a)throw new Error("Cannot use both 'tick' and 'css' options together");return!c&&!a?(s==null||s(),o(),{stop:()=>{},getPosition:()=>t,getVelocity:()=>0,isRunning:()=>!1}):a?st({element:a.element,from:e,to:t,spring:i,velocity:r,style:a.style,onComplete:o,onStart:s}):nt({from:e,to:t,spring:i,velocity:r,onUpdate:c,onComplete:o,onStart:s})}class X{}class I extends X{constructor(t){super();m(this,"options");m(this,"controls",null);m(this,"isAnimating",!1);m(this,"currentValue");m(this,"currentVelocity",0);if(t.tick&&t.css)throw new Error("Cannot use both 'tick' and 'css' options together");this.options={from:t.from??0,to:t.to??1,spring:t.spring??{stiffness:300,damping:30},tick:t.tick,css:t.css,onComplete:t.onComplete??(()=>{}),onStart:t.onStart},this.currentValue=this.options.from}runAnimation(t){this.isAnimating=!0,this.controls=at({from:this.currentValue,to:t,spring:this.options.spring,velocity:this.currentVelocity,tick:this.options.tick,css:this.options.css,onStart:this.options.onStart,onComplete:()=>{this.currentValue=t,this.currentVelocity=0,this.isAnimating=!1,this.controls=null,this.options.onComplete()}})}forward(){this.stop(),this.runAnimation(this.options.to)}backward(){this.stop(),this.runAnimation(this.options.from)}reverse(){const t=this.options.from;this.options.from=this.options.to,this.options.to=t,this.isAnimating&&(this.stop(),this.runAnimation(this.options.to))}stop(){this.controls&&(this.currentValue=this.controls.getPosition(),this.currentVelocity=this.controls.getVelocity(),this.controls.stop(),this.controls=null),this.isAnimating=!1}getVelocity(){var t;return((t=this.controls)==null?void 0:t.getVelocity())??this.currentVelocity}getCurrentValue(){var t;return((t=this.controls)==null?void 0:t.getPosition())??this.currentValue}getIsAnimating(){return this.isAnimating}getCurrentState(){return{position:this.getCurrentValue(),velocity:this.getVelocity(),from:this.options.from,to:this.options.to}}setValue(t){this.currentValue=t}setVelocity(t){this.currentVelocity=t}updateOptions(t){this.options={...this.options,...t}}static fromState(t,i){const r=new I(i);return r.setValue(t.position),r.setVelocity(t.velocity),r}}class M extends X{constructor(t){super();m(this,"config");m(this,"animators",new Map);m(this,"springOrder",[]);m(this,"completedCount",0);m(this,"completedAnimators",new Set);m(this,"direction","forward");m(this,"idCounter",0);m(this,"rafId",null);m(this,"element");m(this,"from");m(this,"to");this.config=t.config,this.from=t.from,this.to=t.to,this.element=t.element,this.initializeAnimators()}generateId(){return`spring_${this.idCounter++}`}initializeAnimators(){this.config.springs.forEach(t=>{const i=this.generateId(),r=new I({from:this.from,to:this.to,spring:t.spring,tick:t.tick,css:t.css&&this.element?{element:this.element,style:t.css}:void 0,onComplete:()=>this.onAnimatorComplete(i),onStart:t.onStart});this.animators.set(i,{id:i,item:t,animator:r,started:!1}),this.springOrder.push(i)})}getAnimatorProgress(t){const i=t.animator.getCurrentState(),r=Math.abs(i.to-i.from);return r===0?1:Math.abs(i.position-i.from)/r}getOrderedIds(){return this.direction==="forward"?this.springOrder:[...this.springOrder].reverse()}onAnimatorComplete(t){var r,o,s,c,a,l;const i=this.animators.get(t);!i||this.completedAnimators.has(t)||(this.completedAnimators.add(t),this.completedCount++,(o=(r=i.item).onComplete)==null||o.call(r),(c=(s=this.config).onProgress)==null||c.call(s,this.completedCount,this.config.springs.length),this.completedCount===this.config.springs.length&&(this.stopScheduler(),(l=(a=this.config).onEnd)==null||l.call(a)))}checkAndStartSprings(){const t=this.getOrderedIds();for(let i=0;i<t.length;i++){const r=t[i],o=this.animators.get(r);if(!o||o.started)continue;if(i===0){this.startAnimator(r);continue}const s=t[i-1],c=this.animators.get(s);if(!c||!c.started)continue;const a=this.getAnimatorProgress(c),l=o.item.normalizedOffset;a>=l&&this.startAnimator(r)}}startAnimator(t){const i=this.animators.get(t);!i||i.started||(i.started=!0,this.direction==="forward"?i.animator.forward():i.animator.backward())}startScheduler(){const t=()=>{this.checkAndStartSprings(),this.getIsAnimating()&&(this.rafId=requestAnimationFrame(t))};this.rafId=requestAnimationFrame(t)}stopScheduler(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}getFirstAnimator(){var i;const t=this.springOrder[0];return t?((i=this.animators.get(t))==null?void 0:i.animator)??null:null}forward(){var t,i;this.stop(),this.direction="forward",this.completedCount=0,this.completedAnimators.clear(),this.resetStartedFlags(),(i=(t=this.config).onStart)==null||i.call(t),this.startScheduler()}backward(){var t,i;this.stop(),this.direction="backward",this.completedCount=0,this.completedAnimators.clear(),this.resetStartedFlags(),(i=(t=this.config).onStart)==null||i.call(t),this.startScheduler()}resetStartedFlags(){this.animators.forEach(t=>{t.started=!1})}stop(){this.stopScheduler(),this.animators.forEach(t=>{t.animator.stop(),t.started=!1})}reverse(){this.direction=this.direction==="forward"?"backward":"forward",this.animators.forEach(t=>{if(!t.started)return;const i=t.animator.getCurrentState();if(i.position===i.to){const o=t.item.css&&this.element?{element:this.element,style:t.item.css}:void 0,s=I.fromState({position:this.to,velocity:0},{from:this.to,to:this.from,spring:t.item.spring,tick:t.item.tick,css:o,onComplete:()=>this.onAnimatorComplete(t.id),onStart:t.item.onStart});s.forward(),t.animator=s}else t.animator.reverse()})}getCurrentState(){const t=this.getFirstAnimator();return t?t.getCurrentState():{position:0,velocity:0,from:0,to:1}}getCurrentValue(){const t=this.getFirstAnimator();return(t==null?void 0:t.getCurrentValue())??0}getVelocity(){const t=this.getFirstAnimator();return(t==null?void 0:t.getVelocity())??0}setValue(t){const i=this.getFirstAnimator();i==null||i.setValue(t)}setVelocity(t){const i=this.getFirstAnimator();i==null||i.setVelocity(t)}getIsAnimating(){for(const t of this.animators.values())if(t.animator.getIsAnimating())return!0;return!1}static fromState(t,i){const r=new M(i);return r.setValue(t.position),r.setVelocity(t.velocity),r}}const x=Symbol.for("TRANSITION_STRATEGY"),$=n=>({runIn:async e=>{const{currentAnimation:t}=n;if(t&&t.direction==="out"){const r=t.controller.getCurrentValue(),o=t.controller.getVelocity();if(t.controller.stop(),e.out)return{config:await e.out,state:{position:r,velocity:o},from:1,to:0,direction:"backward"}}return e.in?{config:await e.in,state:{position:0,velocity:0},from:0,to:1,direction:"forward"}:{state:{position:0,velocity:0},from:0,to:1,direction:"forward"}},runOut:async e=>{const{currentAnimation:t}=n;if(t&&t.direction==="in"){const r=t.controller.getCurrentValue(),o=t.controller.getVelocity();if(t.controller.stop(),e.in)return{config:await e.in,state:{position:r,velocity:o},from:0,to:1,direction:"backward"}}return e.out?{config:await e.out,state:{position:1,velocity:0},from:1,to:0,direction:"forward"}:{state:{position:1,velocity:0},from:1,to:0,direction:"forward"}}}),K=()=>({runIn:async n=>n.in?{config:await n.in,state:{position:0,velocity:0},from:0,to:1,direction:"forward"}:{state:{position:0,velocity:0},from:0,to:1,direction:"forward"},runOut:async n=>n.out?{config:await n.out,state:{position:1,velocity:0},from:1,to:0,direction:"forward"}:{state:{position:1,velocity:0},from:1,to:0,direction:"forward"}}),F="data-ssgoi-scope",z="data-ssgoi-scope-ready";function ct(){return n=>{if(n)return n.setAttribute(F,""),queueMicrotask(()=>{queueMicrotask(()=>{n.setAttribute(z,"true")})}),()=>{}}}function W(n){return n.hasAttribute(z)}function U(n){return n.closest(`[${F}]`)}function lt(n,e){var w;let t=null,i=null,r=null,o=null;const s={get currentAnimation(){return t}},c=((w=e==null?void 0:e.strategy)==null?void 0:w.call(e,s))||$(s),a=async u=>{var E;i&&(i.remove(),i=null);const h=n(),p=h.in&&h.in(u),S=!(e!=null&&e.strategy)&&h.out?h.out(u):void 0;if(!p)return;const y={in:v.normalizeToMultiSpring(p),out:S?v.normalizeToMultiSpring(S):void 0},d=await c.runIn(y);if(!d.config){t&&(t.direction="in");return}const g=d.config;(E=g.prepare)==null||E.call(g,u),g.wait&&await g.wait();const A=v.normalizeMultiSpringSchedule({...g,onEnd:()=>{var T;t=null,(T=g.onEnd)==null||T.call(g)}}),C=M.fromState(d.state,{config:A,from:d.from,to:d.to,element:u});t={controller:C,direction:"in"},d.direction==="forward"?C.forward():C.backward()},l=async u=>{var T;i=u;const h=n(),p=!(e!=null&&e.strategy)&&h.in?h.in(u):void 0,S=h.out&&h.out(u);if(!S)return;const y={in:p?v.normalizeToMultiSpring(p):void 0,out:v.normalizeToMultiSpring(S)},d=await c.runOut(y);if(!d.config){t&&(t.direction="out"),i&&(i.remove(),i=null);return}const g=d.config;(T=g.prepare)==null||T.call(g,u),E(),g.wait&&await g.wait();const A=v.normalizeMultiSpringSchedule({...g,onEnd:()=>{var R,_;(R=g.onEnd)==null||R.call(g),i&&(i.remove(),i=null),t=null,(_=e==null?void 0:e.onCleanupEnd)==null||_.call(e)}}),C=M.fromState(d.state,{config:A,from:d.from,to:d.to,element:u});t={controller:C,direction:"out"},d.direction==="forward"?C.forward():C.backward();function E(){!r||!i||(o&&r.contains(o)?r.insertBefore(i,o):r.appendChild(i))}};let f=null;return u=>{if(u)return r=u.parentElement,o=u.nextElementSibling,(e==null?void 0:e.scope)==="local"?queueMicrotask(()=>{f=U(u),!(f&&!W(f))&&a(u)}):a(u),()=>{const h=u.isConnected?u.cloneNode(!0):u;f?queueMicrotask(()=>{document.contains(f)&&l(h)}):l(h)}}}const ut=3,ft=n=>{if(!n)return null;const e=n.split(`
2
+ `).map(t=>t.trim());for(let t=ut;t<Math.min(e.length,6);t++){const i=e[t],r=i==null?void 0:i.match(/\(?([^):]+):(\d+):(\d+)\)?$/);if(!r)continue;const o=r[1]??"",s=r[2]??"0",c=r[3]??"0";return{file:o.split(/[\\/]/).pop()||o,line:s,column:c}}return null},P=new Map,O=new Map;function mt(n,e,t){P.set(n,e);let i=O.get(n);return i||(i=lt(()=>{const r=P.get(n);return r||(console.warn(`Transition "${String(n)}" not found`),{})},{strategy:t==null?void 0:t.strategy,scope:t==null?void 0:t.scope,onCleanupEnd:()=>G(n)}),O.set(n,i),i)}function G(n){P.delete(n),O.delete(n)}function B(){const n=ft(new Error().stack);return n?`auto_${n.file}_${n.line}_${n.column}`:Symbol(`ssgoi_auto_${Date.now()}`)}const L=globalThis.FinalizationRegistry,q=L?new L(n=>{try{G(n)}catch{}}):void 0;function dt(n){const e=n.key??B();if(n.ref&&q)try{q.register(n.ref,e)}catch{}return mt(e,{in:n.in,out:n.out},{strategy:n[x],scope:n.scope})}function ht(n){const e=n.filter(t=>t.symmetric).map(t=>({from:t.to,to:t.from,transition:t.transition}));return[...n,...e]}function gt(n){let e=!1,t=0,i=0,r=!1;const o=50,s=p=>{if(!n)return;const S=p.touches[0];S&&(r=S.clientX<o,r&&(t=S.clientX,i=S.clientY))},c=p=>{if(!n||!r)return;const S=p.touches[0];if(!S)return;const y=S.clientX-t,d=S.clientY-i;y>window.outerWidth/2-5&&Math.abs(y)>Math.abs(d)?e=!0:e=!1},a=()=>{n&&(r=!1,t=0,i=0)},l=()=>e,f=()=>{typeof window>"u"||n&&(window.addEventListener("touchstart",s,{passive:!0}),window.addEventListener("touchmove",c,{passive:!0}),window.addEventListener("touchend",a,{passive:!0}))},w=()=>{typeof window>"u"||(window.removeEventListener("touchstart",s),window.removeEventListener("touchmove",c),window.removeEventListener("touchend",a))};let u=0;return{initialize:f,cleanup:w,isSwipePending:l,resetSwipeDetection:()=>{u++,u>1&&(u=0,e=!1)}}}const pt=n=>{let e=n.parentElement;for(;e&&e!==document.body;){const t=window.getComputedStyle(e),i=t.overflow+t.overflowY+t.overflowX;if(i.includes("auto")||i.includes("scroll")||e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth)return e;e=e.parentElement}return document.documentElement},wt=n=>{let e=n.parentElement;for(;e&&e!==document.body;){const t=window.getComputedStyle(e).position;if(t==="relative"||t==="absolute"||t==="fixed"||t==="sticky")return e;e=e.parentElement}return document.body};function yt(){let n=null,e=null;const t=new Map;let i=null;const r=()=>{n&&i&&t.set(i,{x:n.scrollLeft,y:n.scrollTop})};return{initializeContext:(f,w)=>{e=f,n||(n=pt(f),(n===document.documentElement?window:n).addEventListener("scroll",r,{passive:!0})),i=w},calculateScrollOffset:(f,w)=>{const u=f&&t.has(f)?t.get(f):{x:0,y:0},h=w&&t.has(w)?t.get(w):{x:0,y:0};return{x:-h.x+u.x,y:-h.y+u.y}},getScrollContainer:()=>n,getPositionedParentElement:()=>e?wt(e):document.body,getScrollPosition:f=>f&&t.has(f)?t.get(f):{x:0,y:0}}}function k(n,e){if(e==="*")return!0;if(e.endsWith("/*")){const t=e.slice(0,-2);return n===t||n.startsWith(t+"/")}return n===e}function St(n,e,t){for(const i of t)if(k(n,i.from)&&k(e,i.to))return i.transition;for(const i of t)if((i.from==="*"||k(n,i.from))&&(i.to==="*"||k(e,i.to)))return i.transition;return null}function vt(n){const{transitions:e=[],defaultTransition:t,middleware:i=(y,d)=>({from:y,to:d}),skipOnIosSwipe:r=!0}=n;let o=null;const s=ht(e),{initializeContext:c,calculateScrollOffset:a,getScrollContainer:l,getPositionedParentElement:f,getScrollPosition:w}=yt(),u=gt(r);u.initialize();function h(){if(o!=null&&o.from&&(o!=null&&o.to)){const{from:y,to:d}=i(o.from,o.to),A=St(y,d,s)||t,C=a(o.from,o.to),E={scrollOffset:C,scroll:w(o.from),get scrollingElement(){return l()||document.documentElement},get positionedParent(){return f()}},T={scrollOffset:C,get scroll(){return o?w(o.to):{x:0,y:0}},get scrollingElement(){return l()||document.documentElement},get positionedParent(){return f()}};A&&(A.out&&o.outResolve&&o.outResolve(R=>A.out(R,E)),A.in&&o.inResolve&&o.inResolve(R=>A.in(R,T))),o=null}}const p=async(y,d)=>u.isSwipePending()?(u.resetSwipeDetection(),()=>({})):d==="in"&&(!o||!o.from)?()=>({}):(o||(o={}),d==="out"?(o.from=y,new Promise(g=>{o.outResolve=g,h()})):(o.to=y,new Promise(g=>{o.inResolve=g,h()})));return y=>({key:y,in:async d=>(c(d,y),(await p(y,"in"))(d)),out:async d=>(await p(y,"out"))(d),[x]:K})}exports.isCssAnimation=v.isCssAnimation;exports.isMultiSpring=v.isMultiSpring;exports.isSingleSpring=v.isSingleSpring;exports.isTickAnimation=v.isTickAnimation;exports.normalizeMultiSpringSchedule=v.normalizeMultiSpringSchedule;exports.normalizeToMultiSpring=v.normalizeToMultiSpring;exports.validateAnimationMode=v.validateAnimationMode;exports.validateSpringItem=v.validateSpringItem;exports.jaeminInternal=Z.jaeminInternal;exports.SCOPE_ATTR=F;exports.SCOPE_READY_ATTR=z;exports.TRANSITION_STRATEGY=x;exports.createDefaultStrategy=$;exports.createPageTransitionStrategy=K;exports.createSggoiTransitionContext=vt;exports.createTransitionScope=ct;exports.findScope=U;exports.generateAutoKey=B;exports.isScopeReady=W;exports.transition=dt;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './types';
2
2
  export * from './transition/transition';
3
+ export * from './transition/transition-scope';
3
4
  export * from './ssgoi-transition/create-ssgoi-transition-context';
4
5
  export * from './transition/transition-strategy';
5
6
  export { jaeminInternal } from './view-transitions/jaemin';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,oDAAoD,CAAC;AACnE,cAAc,kCAAkC,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oDAAoD,CAAC;AACnE,cAAc,kCAAkC,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC"}