"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var te=Object.defineProperty,J=Object.getOwnPropertySymbols,re=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable,Q=(e,t,r)=>t in e?te(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,se=(e,t)=>{for(var r in t||(t={}))re.call(t,r)&&Q(e,r,t[r]);if(J)for(var r of J(t))ne.call(t,r)&&Q(e,r,t[r]);return e};function ie(){const e=[];function t(u){if(e.length!==0)for(const c of e.slice())c(u)}function r(u){const c=e.indexOf(u);c!==-1&&e.splice(c,1)}function i(u){return e.indexOf(u)===-1&&e.push(u),()=>r(u)}function s(u){const c=i(d=>{c(),u(d)});return c}return{emit:t,subscribe:i,subscribeOnce:s,nOfSubscriptions(){return e.length}}}function oe(e,t){return t.content()}/** * @license * Copyright (c) 2016-22 [these people](https://github.com/sveltejs/svelte/graphs/contributors) * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */const U={storeCount:0};function I(e,t){var r;let i=e;const s=ie();let u;const c=typeof t=="function"?t:t==null?void 0:t.start,d=(r=typeof t=="function"||t==null?void 0:t.comparator)!=null?r:(l,b)=>l===b,a=()=>{if(s.nOfSubscriptions()>0)return i;let l;return y(A=>l=A)(),l},f=l=>{i!==void 0&&d(i,l)||(i=l,s.emit(i))},y=l=>{s.nOfSubscriptions()===0&&(u=c==null?void 0:c(f));const b=s.subscribe(l);return l(i),()=>{b(),s.nOfSubscriptions()===0&&(u==null||u(),u=void 0)}},v=l=>{f(l(a()))};U.storeCount++;const m=U.storeCount;return{content:a,set:f,watch:()=>oe(m,{content:a,subscribe:y}),subscribe:y,update:v,nOfSubscriptions:s.nOfSubscriptions}}function ce(e,t){const{content:r,nOfSubscriptions:i,subscribe:s,watch:u}=I(e,t);return{content:r,nOfSubscriptions:i,subscribe:s,watch:u}}/** * @license * Copyright (c) 2016-22 [these people](https://github.com/sveltejs/svelte/graphs/contributors) * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */function ue(e,t,r){const i=Array.isArray(e),s=!i&&"subscribe"in e&&"nOfSubscriptions"in e&&"content"in e,u=s?1:i?e.length:Object.keys(e).length;return ce(void 0,{comparator:r==null?void 0:r.comparator,start:u===0?d=>{d(t(i?[]:{}))}:s?d=>e.subscribe(f=>d(t(f))):i?d=>{let a=new Array(e.length),f=0;const y=e.map((v,m)=>v.subscribe(l=>{if(f{for(const v of y)v();f=0}}:d=>{let a={},f=0;const y=Object.entries(e).map(([v,m])=>m.subscribe(l=>{if(f{for(const v of y)v();f=0}}})}function V(e,t,r){const i=r?new Float32Array(e):e;for(let s=0;s{};class W extends Error{constructor(){super("[spring store] physics simulation skipped")}}class le extends Error{constructor(){super("[spring store] physics simulation skipped")}}function pe(e){return function(r){const i=e||(typeof requestAnimationFrame!="undefined"?{request:c=>requestAnimationFrame(c),cancel:c=>cancelAnimationFrame(c)}:{request:c=>setTimeout(()=>c(performance.now()),16.666666666666668),cancel:c=>clearTimeout(c)});let s;return new Promise((c,d)=>{if(r!=null&&r.aborted){d(r.reason);return}const a=()=>{s!==void 0&&i.cancel(s),d(r==null?void 0:r.reason)};r==null||r.addEventListener("abort",a,{once:!0}),s=i.request(f=>{r==null||r.removeEventListener("abort",a),s=void 0,c(f)})})}}function fe(e,t){var Z,z,B,G;let r=(Z=t==null?void 0:t.damping)!=null?Z:30,i=(z=t==null?void 0:t.stiffness)!=null?z:300,s=(B=t==null?void 0:t.precision)!=null?B:.1;const u=pe(t==null?void 0:t.requestAnimationFrameImplementation),c=typeof e=="number"?[]:Object.keys(e),d=typeof e=="number"?n=>n:Array.isArray(e)?n=>[...n]:n=>({...n}),a=typeof e=="number"?n=>new Float32Array([n]):n=>{const o=new Float32Array(c.length);for(let p=0;pn[0]:n=>{const o=d(y);for(let p=0;p0:()=>{const n=d(e);for(let o=0;oae(a(n)));let w={velocity:a(y),value:a(e)},k={velocity:a(y),value:a(e)};const O=I(e),K=I(e);let N=!0;K.subscribe(n=>{if(v=a(n),N){N=!1;return}M().catch(o=>console.error("[spring store] unable to follow target",o))}),m.subscribe(n=>{n==="idle"?(C(),l=void 0,C=h):l||(l=new Promise(o=>C=o))});function S(n,o){const p=P(R,i,!0),x=P(o.velocity,r,!0),F=X(p,x,!1),_=P(F,n,!1),E=V(_,o.velocity,!1),ee=P(E,n,!0);return{value:V(ee,o.value,!1),velocity:E}}function L(){return R=a(y),{velocity:a(y),value:new Float32Array(v)}}let R=a(y);const D=(t==null?void 0:t.dt)||1/300,g=(G=t==null?void 0:t.maxDt)!=null?G:1/24;async function M(){if(m.content()==="idle")try{m.set("running");let n=!1,o;for(;!n;){switch(m.content()){case"skipping":{w=L(),k=w,n=!0;break}case"pausing":{j(),m.set("paused");try{await b,m.set("running")}catch(p){if(p instanceof W)w=L(),k=w,n=!0;else throw p}break}case"running":{o=o!=null?o:await u();const p=await u();let x=Math.min(g,(p-o)/1e3||D);o=p;let F=w;for(;x>0;)R=X(v,w.value,!0),F=w,w=S(D,F),x-=D;const _=1+x/D;k={value:V(P(w.value,_,!0),P(F.value,1-_,!0),!1),velocity:V(P(w.velocity,_,!0),P(F.velocity,1-_,!0),!1)},R.some(E=>Math.abs(E)>=s)||w.velocity.some(E=>Math.abs(E)>=s)||(w=L(),k=w,n=!0);break}case"idle":case"paused":break}O.set(f(k.value)),H.set(f(k.velocity))}}finally{m.set("idle")}}return{precision(n){return n!==void 0&&(s=n),s},damping(n){return n!==void 0&&(r=n),r},stiffness(n){return n!==void 0&&(i=n),i},nOfSubscriptions:O.nOfSubscriptions,content:O.content,speed$:Y,state$:m,subscribe:O.subscribe,watch:O.watch,velocity$:H,async pause(){m.content()==="running"&&(m.set("pausing"),A=new Promise((n,o)=>{j=()=>{A=void 0,j=h,$=h,n()},$=p=>{A=void 0,j=h,$=h,o(p)}}),b=new Promise((n,o)=>{q=()=>{b=void 0,q=h,T=h,n()},T=p=>{b=void 0,q=h,T=h,o(p)}})),await A},resume(){q()},async skip(){const n=m.content();if((n==="running"||n==="pausing"||n==="paused")&&l){m.set("skipping");const o=new W;T(o),$(o),await l}},target$:K,async idle(){await l}}}exports.SpringStorePauseError=le;exports.SpringStoreSkipError=W;exports.makeSpringStore=fe;