@freqhole/playlistz 0.0.1
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/.changeset/config.json +11 -0
- package/.changeset/nice-wolves-thank.md +5 -0
- package/.freqhole-versions.json +4 -0
- package/.github/copilot-instructions.md +201 -0
- package/.github/workflows/changesets.yml +50 -0
- package/.github/workflows/npm-publish.yml +124 -0
- package/.github/workflows/pr-checks.yml +103 -0
- package/README.md +30 -0
- package/build-component.js +141 -0
- package/build-zip-bundle-lib.js +44 -0
- package/config/playwright.config.ts +47 -0
- package/config/vite.config.ts +44 -0
- package/config/vitest.config.ts +39 -0
- package/dist/assets/automerge_wasm_bg-Cik4BF9l.wasm +0 -0
- package/dist/assets/index-CbOXzGiA.js +216 -0
- package/dist/assets/index-CbOXzGiA.js.map +1 -0
- package/dist/assets/index-TvJ6RFpy.css +1 -0
- package/dist/assets/midden-DceCrT_L.js +2 -0
- package/dist/assets/midden-DceCrT_L.js.map +1 -0
- package/dist/assets/midden_bg-BLhfGIU-.wasm +0 -0
- package/dist/index.html +55 -0
- package/dist/sw.js +134 -0
- package/docs/AUTOMERGE_P2P_PLAN.md +233 -0
- package/docs/COLLABORATIVE_SHARING_PLAN.md +188 -0
- package/docs/E2E_TESTID_PLAN.md +234 -0
- package/docs/IROH_P2P_PLAN.md +302 -0
- package/docs/ROADMAP.md +695 -0
- package/docs/TODO.md +167 -0
- package/docs/bundle-embedding-plan.md +134 -0
- package/docs/standalone-refactor.md +184 -0
- package/e2e/all-playlists.spec.ts +220 -0
- package/e2e/audio-player.spec.ts +226 -0
- package/e2e/collaborative-features.spec.ts +229 -0
- package/e2e/contexts.ts +238 -0
- package/e2e/edit-panel.spec.ts +87 -0
- package/e2e/fixtures/bare-glitch-1s.m4a +0 -0
- package/e2e/fixtures/bare-glitch-1s.mp3 +0 -0
- package/e2e/fixtures/bare-glitch-1s.ogg +0 -0
- package/e2e/fixtures/chord-stack-3s.wav +0 -0
- package/e2e/fixtures/cover-anim.gif +0 -0
- package/e2e/fixtures/cover-blue.png +0 -0
- package/e2e/fixtures/cover-checkers.png +0 -0
- package/e2e/fixtures/cover-gradient.jpg +0 -0
- package/e2e/fixtures/cover-mono.gif +0 -0
- package/e2e/fixtures/cover-noise.png +0 -0
- package/e2e/fixtures/cover-plasma.webp +0 -0
- package/e2e/fixtures/cover-portrait.jpg +0 -0
- package/e2e/fixtures/cover-red.png +0 -0
- package/e2e/fixtures/cover-thumb.jpg +0 -0
- package/e2e/fixtures/cover-wide.webp +0 -0
- package/e2e/fixtures/generate.mjs +257 -0
- package/e2e/fixtures/long-drone-90s.mp3 +0 -0
- package/e2e/fixtures/noisy-binaural-8s.mp3 +0 -0
- package/e2e/fixtures/tagged-a3-4s.m4a +0 -0
- package/e2e/fixtures/tagged-a3-4s.mp3 +0 -0
- package/e2e/fixtures/tagged-a3-4s.ogg +0 -0
- package/e2e/fixtures/tagged-c5-3s.m4a +0 -0
- package/e2e/fixtures/tagged-c5-3s.mp3 +0 -0
- package/e2e/fixtures/tagged-c5-3s.ogg +0 -0
- package/e2e/fixtures/tagged-f4-6s.m4a +0 -0
- package/e2e/fixtures/tagged-f4-6s.mp3 +0 -0
- package/e2e/fixtures/tagged-f4-6s.ogg +0 -0
- package/e2e/fixtures/tone-220hz-10s.wav +0 -0
- package/e2e/fixtures/tone-440hz-2s.wav +0 -0
- package/e2e/fixtures/tone-880hz-5s.wav +0 -0
- package/e2e/fixtures/tone-stereo-3s.wav +0 -0
- package/e2e/fixtures/user-provided/README.md +1 -0
- package/e2e/helpers/app.ts +143 -0
- package/e2e/helpers/hooks.ts +133 -0
- package/e2e/helpers/index.ts +12 -0
- package/e2e/helpers/media.ts +125 -0
- package/e2e/helpers.ts +10 -0
- package/e2e/p2p-collaboration.spec.ts +356 -0
- package/e2e/p2p-multi-peer.spec.ts +723 -0
- package/e2e/p2p-states.spec.ts +302 -0
- package/e2e/playback.spec.ts +56 -0
- package/e2e/playlist-crud.spec.ts +126 -0
- package/e2e/share-link-autoplay.spec.ts +129 -0
- package/e2e/sharing-access.spec.ts +205 -0
- package/e2e/sharing.spec.ts +195 -0
- package/e2e/song-cache-state.spec.ts +202 -0
- package/e2e/zip-bundle.spec.ts +855 -0
- package/eslint.config.js +114 -0
- package/index.html +54 -0
- package/package.json +119 -0
- package/public/sw.js +134 -0
- package/scripts/use-local.mjs +37 -0
- package/scripts/use-published.mjs +37 -0
- package/src/App.tsx +9 -0
- package/src/cli/check.ts +164 -0
- package/src/cli/generate.ts +184 -0
- package/src/cli/http.ts +88 -0
- package/src/cli/index.ts +65 -0
- package/src/cli/init.ts +18 -0
- package/src/components/AllPlaylistsPanel.tsx +713 -0
- package/src/components/AudioPlayer.tsx +122 -0
- package/src/components/MarqueeText.tsx +101 -0
- package/src/components/PlaylistCoverModal.tsx +519 -0
- package/src/components/PlaylistEditPanel.tsx +803 -0
- package/src/components/PlaylistSharePanel.tsx +1020 -0
- package/src/components/ShareLinkKnockPanel.tsx +144 -0
- package/src/components/SharePanel.tsx +584 -0
- package/src/components/SongEditModal.tsx +453 -0
- package/src/components/SongEditPanel.tsx +578 -0
- package/src/components/SongRow.tsx +689 -0
- package/src/components/index.tsx +494 -0
- package/src/components/playlist/index.tsx +1203 -0
- package/src/context/PlaylistzContext.tsx +74 -0
- package/src/dev-hooks.ts +35 -0
- package/src/hooks/createDocIndexQuery.ts +53 -0
- package/src/hooks/createDocStore.test.ts +303 -0
- package/src/hooks/createDocStore.ts +90 -0
- package/src/hooks/useDragAndDrop.test.ts +474 -0
- package/src/hooks/useDragAndDrop.ts +400 -0
- package/src/hooks/useImageModal.test.ts +174 -0
- package/src/hooks/useImageModal.ts +201 -0
- package/src/hooks/usePlaylistManager.test.ts +453 -0
- package/src/hooks/usePlaylistManager.ts +685 -0
- package/src/hooks/usePlaylistsQuery.test.tsx +120 -0
- package/src/hooks/usePlaylistsQuery.ts +44 -0
- package/src/hooks/useSongState.test.ts +236 -0
- package/src/hooks/useSongState.ts +114 -0
- package/src/hooks/useUIState.ts +71 -0
- package/src/index.tsx +18 -0
- package/src/services/audioService.dev.ts +22 -0
- package/src/services/audioService.test.ts +1226 -0
- package/src/services/audioService.ts +1395 -0
- package/src/services/automergeRepo.test.ts +269 -0
- package/src/services/automergeRepo.ts +226 -0
- package/src/services/blobTransferService.dev.ts +119 -0
- package/src/services/blobTransferService.test.ts +441 -0
- package/src/services/blobTransferService.ts +702 -0
- package/src/services/docIndexService.test.ts +179 -0
- package/src/services/docIndexService.ts +118 -0
- package/src/services/fileProcessingService.test.ts +554 -0
- package/src/services/fileProcessingService.ts +239 -0
- package/src/services/imageService.test.ts +701 -0
- package/src/services/imageService.ts +365 -0
- package/src/services/indexedDBService.integration.test.ts +104 -0
- package/src/services/indexedDBService.test.ts +202 -0
- package/src/services/indexedDBService.ts +436 -0
- package/src/services/offlineService.test.ts +661 -0
- package/src/services/offlineService.ts +382 -0
- package/src/services/p2pService.test.ts +305 -0
- package/src/services/p2pService.ts +344 -0
- package/src/services/playlistDocService.test.ts +448 -0
- package/src/services/playlistDocService.ts +707 -0
- package/src/services/playlistDownloadService.test.ts +674 -0
- package/src/services/playlistDownloadService.ts +389 -0
- package/src/services/sharingService.test.ts +812 -0
- package/src/services/sharingService.ts +1073 -0
- package/src/services/sharingState.ts +161 -0
- package/src/services/songReactivity.test.ts +620 -0
- package/src/services/songReactivity.ts +145 -0
- package/src/services/standaloneService.test.ts +1025 -0
- package/src/services/standaloneService.ts +588 -0
- package/src/services/streamingAudioService.test.ts +275 -0
- package/src/services/streamingAudioService.ts +166 -0
- package/src/styles.css +428 -0
- package/src/test-setup.ts +547 -0
- package/src/types/global.d.ts +40 -0
- package/src/types/playlist.ts +99 -0
- package/src/utils/hashUtils.ts +41 -0
- package/src/utils/log.ts +97 -0
- package/src/utils/m3u.test.ts +172 -0
- package/src/utils/m3u.ts +136 -0
- package/src/utils/mockData.ts +166 -0
- package/src/utils/standaloneTemplates.test.ts +175 -0
- package/src/utils/standaloneTemplates.ts +83 -0
- package/src/utils/swTemplate.ts +84 -0
- package/src/utils/timeUtils.ts +166 -0
- package/src/utils/typeGuards.ts +171 -0
- package/src/web-component.tsx +98 -0
- package/src/zip-bundle/index.ts +7 -0
- package/src/zip-bundle/m3u.ts +45 -0
- package/src/zip-bundle/types.ts +50 -0
- package/src/zip-bundle/utils.ts +33 -0
- package/src/zip-bundle/zipBuilder.ts +309 -0
- package/tailwind.config.js +55 -0
- package/tsconfig.json +43 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
let l_;let __tla=(async()=>{(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(i){if(i.ep)return;i.ep=!0;const s=n(i);fetch(i.href,s)}})();const Yb=!1,Xb=(e,t)=>e===t,Qb=Symbol("solid-track"),Ga={equals:Xb};let Vp=Kp;const Rr=1,Ya=2,Wp={owned:null,cleanups:null,context:null,owner:null},ul={};var dt=null;let dl=null,ew=null,xt=null,ln=null,Or=null,Oc=0;function Aa(e,t){const n=xt,r=dt,i=e.length===0,s=t===void 0?r:t,o=i?Wp:{owned:null,cleanups:null,context:s?s.context:null,owner:s},a=i?e:()=>e(()=>Wn(()=>go(o)));dt=o,xt=null;try{return Tr(a,!0)}finally{xt=n,dt=r}}function Q(e,t){t=t?Object.assign({},Ga,t):Ga;const n={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0},r=i=>(typeof i=="function"&&(i=i(n.value)),Jp(n,i));return[qp.bind(n),r]}function tw(e,t,n){const r=Pc(e,t,!0,Rr);Os(r)}function we(e,t,n){const r=Pc(e,t,!1,Rr);Os(r)}function zt(e,t,n){Vp=dw;const r=Pc(e,t,!1,Rr);r.user=!0,Or?Or.push(r):Os(r)}function tr(e,t,n){n=n?Object.assign({},Ga,n):Ga;const r=Pc(e,t,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=n.equals||void 0,Os(r),qp.bind(r)}function nw(e){return e&&typeof e=="object"&&"then"in e}function hh(e,t,n){let r,i,s;typeof t=="function"?(r=e,i=t,s={}):(r=!0,i=e,s=t||{});let o=null,a=ul,c=!1,l="initialValue"in s,f=typeof r=="function"&&tr(r);const u=new Set,[h,d]=(s.storage||Q)(s.initialValue),[g,p]=Q(void 0),[m,b]=Q(void 0,{equals:!1}),[x,_]=Q(l?"ready":"unresolved");function E(I,R,N,D){return o===I&&(o=null,D!==void 0&&(l=!0),(I===a||R===a)&&s.onHydrated&&queueMicrotask(()=>s.onHydrated(D,{value:R})),a=ul,k(R,N)),R}function k(I,R){Tr(()=>{R===void 0&&d(()=>I),_(R!==void 0?"errored":l?"ready":"unresolved"),p(R);for(const N of u.keys())N.decrement();u.clear()},!1)}function C(){const I=cw,R=h(),N=g();if(N!==void 0&&!o)throw N;return xt&&xt.user,R}function T(I=!0){if(I!==!1&&c)return;c=!1;const R=f?f():r;if(R==null||R===!1){E(o,Wn(h));return}let N;const D=a!==ul?a:Wn(()=>{try{return i(R,{value:h(),refetching:I})}catch(y){N=y}});if(N!==void 0){E(o,void 0,Ca(N),R);return}else if(!nw(D))return E(o,D,void 0,R),D;return o=D,"v"in D?(D.s===1?E(o,D.v,void 0,R):E(o,void 0,Ca(D.v),R),D):(c=!0,queueMicrotask(()=>c=!1),Tr(()=>{_(l?"refreshing":"pending"),b()},!1),D.then(y=>E(D,y,void 0,R),y=>E(D,void 0,Ca(y),R)))}Object.defineProperties(C,{state:{get:()=>x()},error:{get:()=>g()},loading:{get(){const I=x();return I==="pending"||I==="refreshing"}},latest:{get(){if(!l)return C();const I=g();if(I&&!o)throw I;return h()}}});let j=dt;return f?tw(()=>(j=dt,T(!1))):T(!1),[C,{refetch:I=>iw(j,()=>T(I)),mutate:d}]}function rw(e){return Tr(e,!1)}function Wn(e){if(xt===null)return e();const t=xt;xt=null;try{return e()}finally{xt=t}}function Ia(e,t,n){const r=Array.isArray(e);let i;return s=>{let o;if(r){o=Array(e.length);for(let c=0;c<e.length;c++)o[c]=e[c]()}else o=e();const a=Wn(()=>t(o,i,s));return i=o,a}}function sr(e){zt(()=>Wn(e))}function rn(e){return dt===null||(dt.cleanups===null?dt.cleanups=[e]:dt.cleanups.push(e)),e}function iw(e,t){const n=dt,r=xt;dt=e,xt=null;try{return Tr(t,!0)}catch(i){jd(i)}finally{dt=n,xt=r}}const[wj,vj]=Q(!1);function sw(e,t){const n=Symbol("context");return{id:n,Provider:fw(n),defaultValue:e}}function ow(e){let t;return dt&&dt.context&&(t=dt.context[e.id])!==void 0?t:e.defaultValue}function aw(e){const t=tr(e),n=tr(()=>mu(t()));return n.toArray=()=>{const r=n();return Array.isArray(r)?r:r!=null?[r]:[]},n}let cw;function qp(){if(this.sources&&this.state)if(this.state===Rr)Os(this);else{const e=ln;ln=null,Tr(()=>Qa(this),!1),ln=e}if(xt){const e=this.observers?this.observers.length:0;xt.sources?(xt.sources.push(this),xt.sourceSlots.push(e)):(xt.sources=[this],xt.sourceSlots=[e]),this.observers?(this.observers.push(xt),this.observerSlots.push(xt.sources.length-1)):(this.observers=[xt],this.observerSlots=[xt.sources.length-1])}return this.value}function Jp(e,t,n){let r=e.value;return(!e.comparator||!e.comparator(r,t))&&(e.value=t,e.observers&&e.observers.length&&Tr(()=>{for(let i=0;i<e.observers.length;i+=1){const s=e.observers[i],o=dl&&dl.running;o&&dl.disposed.has(s),(o?!s.tState:!s.state)&&(s.pure?ln.push(s):Or.push(s),s.observers&&Gp(s)),o||(s.state=Rr)}if(ln.length>1e6)throw ln=[],new Error},!1)),t}function Os(e){if(!e.fn)return;go(e);const t=Oc;lw(e,e.value,t)}function lw(e,t,n){let r;const i=dt,s=xt;xt=dt=e;try{r=e.fn(t)}catch(o){return e.pure&&(e.state=Rr,e.owned&&e.owned.forEach(go),e.owned=null),e.updatedAt=n+1,jd(o)}finally{xt=s,dt=i}(!e.updatedAt||e.updatedAt<=n)&&(e.updatedAt!=null&&"observers"in e?Jp(e,r):e.value=r,e.updatedAt=n)}function Pc(e,t,n,r=Rr,i){const s={fn:e,state:r,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:dt,context:dt?dt.context:null,pure:n};return dt===null||dt!==Wp&&(dt.owned?dt.owned.push(s):dt.owned=[s]),s}function Xa(e){if(e.state===0)return;if(e.state===Ya)return Qa(e);if(e.suspense&&Wn(e.suspense.inFallback))return e.suspense.effects.push(e);const t=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt<Oc);)e.state&&t.push(e);for(let n=t.length-1;n>=0;n--)if(e=t[n],e.state===Rr)Os(e);else if(e.state===Ya){const r=ln;ln=null,Tr(()=>Qa(e,t[0]),!1),ln=r}}function Tr(e,t){if(ln)return e();let n=!1;t||(ln=[]),Or?n=!0:Or=[],Oc++;try{const r=e();return uw(n),r}catch(r){n||(Or=null),ln=null,jd(r)}}function uw(e){if(ln&&(Kp(ln),ln=null),e)return;const t=Or;Or=null,t.length&&Tr(()=>Vp(t),!1)}function Kp(e){for(let t=0;t<e.length;t++)Xa(e[t])}function dw(e){let t,n=0;for(t=0;t<e.length;t++){const r=e[t];r.user?e[n++]=r:Xa(r)}for(t=0;t<n;t++)Xa(e[t])}function Qa(e,t){e.state=0;for(let n=0;n<e.sources.length;n+=1){const r=e.sources[n];if(r.sources){const i=r.state;i===Rr?r!==t&&(!r.updatedAt||r.updatedAt<Oc)&&Xa(r):i===Ya&&Qa(r,t)}}}function Gp(e){for(let t=0;t<e.observers.length;t+=1){const n=e.observers[t];n.state||(n.state=Ya,n.pure?ln.push(n):Or.push(n),n.observers&&Gp(n))}}function go(e){let t;if(e.sources)for(;e.sources.length;){const n=e.sources.pop(),r=e.sourceSlots.pop(),i=n.observers;if(i&&i.length){const s=i.pop(),o=n.observerSlots.pop();r<i.length&&(s.sourceSlots[o]=r,i[r]=s,n.observerSlots[r]=o)}}if(e.tOwned){for(t=e.tOwned.length-1;t>=0;t--)go(e.tOwned[t]);delete e.tOwned}if(e.owned){for(t=e.owned.length-1;t>=0;t--)go(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}e.state=0}function Ca(e){return e instanceof Error?e:new Error(typeof e=="string"?e:"Unknown error",{cause:e})}function jd(e,t=dt){throw Ca(e)}function mu(e){if(typeof e=="function"&&!e.length)return mu(e());if(Array.isArray(e)){const t=[];for(let n=0;n<e.length;n++){const r=mu(e[n]);Array.isArray(r)?t.push.apply(t,r):t.push(r)}return t}return e}function fw(e,t){return function(r){let i;return we(()=>i=Wn(()=>(dt.context={...dt.context,[e]:r.value},aw(()=>r.children))),void 0),i}}const hw=Symbol("fallback");function gh(e){for(let t=0;t<e.length;t++)e[t]()}function gw(e,t,n={}){let r=[],i=[],s=[],o=0,a=t.length>1?[]:null;return rn(()=>gh(s)),()=>{let c=e()||[],l=c.length,f,u;return c[Qb],Wn(()=>{let d,g,p,m,b,x,_,E,k;if(l===0)o!==0&&(gh(s),s=[],r=[],i=[],o=0,a&&(a=[])),n.fallback&&(r=[hw],i[0]=Aa(C=>(s[0]=C,n.fallback())),o=1);else if(o===0){for(i=new Array(l),u=0;u<l;u++)r[u]=c[u],i[u]=Aa(h);o=l}else{for(p=new Array(l),m=new Array(l),a&&(b=new Array(l)),x=0,_=Math.min(o,l);x<_&&r[x]===c[x];x++);for(_=o-1,E=l-1;_>=x&&E>=x&&r[_]===c[E];_--,E--)p[E]=i[_],m[E]=s[_],a&&(b[E]=a[_]);for(d=new Map,g=new Array(E+1),u=E;u>=x;u--)k=c[u],f=d.get(k),g[u]=f===void 0?-1:f,d.set(k,u);for(f=x;f<=_;f++)k=r[f],u=d.get(k),u!==void 0&&u!==-1?(p[u]=i[f],m[u]=s[f],a&&(b[u]=a[f]),u=g[u],d.set(k,u)):s[f]();for(u=x;u<l;u++)u in p?(i[u]=p[u],s[u]=m[u],a&&(a[u]=b[u],a[u](u))):i[u]=Aa(h);i=i.slice(0,o=l),r=c.slice(0)}return i});function h(d){if(s[u]=d,a){const[g,p]=Q(u);return a[u]=p,t(c[u],g)}return t(c[u])}}}function re(e,t){return Wn(()=>e(t||{}))}const pw=e=>`Stale read from <${e}>.`;function Gr(e){const t="fallback"in e&&{fallback:()=>e.fallback};return tr(gw(()=>e.each,e.children,t||void 0))}function he(e){const t=e.keyed,n=tr(()=>e.when,void 0,void 0),r=t?n:tr(n,void 0,{equals:(i,s)=>!i==!s});return tr(()=>{const i=r();if(i){const s=e.children;return typeof s=="function"&&s.length>0?Wn(()=>s(t?i:()=>{if(!Wn(r))throw pw("Show");return n()})):s}return e.fallback},void 0,void 0)}const Ct=e=>tr(()=>e());function mw(e,t,n){let r=n.length,i=t.length,s=r,o=0,a=0,c=t[i-1].nextSibling,l=null;for(;o<i||a<s;){if(t[o]===n[a]){o++,a++;continue}for(;t[i-1]===n[s-1];)i--,s--;if(i===o){const f=s<r?a?n[a-1].nextSibling:n[s-a]:c;for(;a<s;)e.insertBefore(n[a++],f)}else if(s===a)for(;o<i;)(!l||!l.has(t[o]))&&t[o].remove(),o++;else if(t[o]===n[s-1]&&n[a]===t[i-1]){const f=t[--i].nextSibling;e.insertBefore(n[a++],t[o++].nextSibling),e.insertBefore(n[--s],f),t[i]=n[s]}else{if(!l){l=new Map;let u=a;for(;u<s;)l.set(n[u],u++)}const f=l.get(t[o]);if(f!=null)if(a<f&&f<s){let u=o,h=1,d;for(;++u<i&&u<s&&!((d=l.get(t[u]))==null||d!==f+h);)h++;if(h>f-a){const g=t[o];for(;a<f;)e.insertBefore(n[a++],g)}else e.replaceChild(n[a++],t[o++])}else o++;else t[o++].remove()}}}const ph="_$DX_DELEGATE";function _w(e,t,n,r={}){let i;return Aa(s=>{i=s,t===document?e():Z(t,e(),t.firstChild?null:void 0,n)},r.owner),()=>{i(),t.textContent=""}}function ee(e,t,n,r){let i;const s=()=>{const a=document.createElement("template");return a.innerHTML=e,a.content.firstChild},o=()=>(i||(i=s())).cloneNode(!0);return o.cloneNode=o,o}function Fr(e,t=window.document){const n=t[ph]||(t[ph]=new Set);for(let r=0,i=e.length;r<i;r++){const s=e[r];n.has(s)||(n.add(s),t.addEventListener(s,yw))}}function Ne(e,t,n){n==null?e.removeAttribute(t):e.setAttribute(t,n)}function ht(e,t){t==null?e.removeAttribute("class"):e.className=t}function nn(e,t,n,r){if(r)Array.isArray(n)?(e[`$$${t}`]=n[0],e[`$$${t}Data`]=n[1]):e[`$$${t}`]=n;else if(Array.isArray(n)){const i=n[0];e.addEventListener(t,n[0]=s=>i.call(e,n[1],s))}else e.addEventListener(t,n,typeof n!="function"&&n)}function $r(e,t,n){if(!t)return n?Ne(e,"style"):t;const r=e.style;if(typeof t=="string")return r.cssText=t;typeof n=="string"&&(r.cssText=n=void 0),n||(n={}),t||(t={});let i,s;for(s in n)t[s]==null&&r.removeProperty(s),delete n[s];for(s in t)i=t[s],i!==n[s]&&(r.setProperty(s,i),n[s]=i);return n}function Qn(e,t,n){n!=null?e.style.setProperty(t,n):e.style.removeProperty(t)}function po(e,t,n){return Wn(()=>e(t,n))}function Z(e,t,n,r){if(n!==void 0&&!r&&(r=[]),typeof t!="function")return ec(e,t,r,n);we(i=>ec(e,t(),i,n),r)}function yw(e){let t=e.target;const n=`$$${e.type}`,r=e.target,i=e.currentTarget,s=c=>Object.defineProperty(e,"target",{configurable:!0,value:c}),o=()=>{const c=t[n];if(c&&!t.disabled){const l=t[`${n}Data`];if(l!==void 0?c.call(t,l,e):c.call(t,e),e.cancelBubble)return}return t.host&&typeof t.host!="string"&&!t.host._$host&&t.contains(e.target)&&s(t.host),!0},a=()=>{for(;o()&&(t=t._$host||t.parentNode||t.host););};if(Object.defineProperty(e,"currentTarget",{configurable:!0,get(){return t||document}}),e.composedPath){const c=e.composedPath();s(c[0]);for(let l=0;l<c.length-2&&(t=c[l],!!o());l++){if(t._$host){t=t._$host,a();break}if(t.parentNode===i)break}}else a();s(r)}function ec(e,t,n,r,i){for(;typeof n=="function";)n=n();if(t===n)return n;const s=typeof t,o=r!==void 0;if(e=o&&n[0]&&n[0].parentNode||e,s==="string"||s==="number"){if(s==="number"&&(t=t.toString(),t===n))return n;if(o){let a=n[0];a&&a.nodeType===3?a.data!==t&&(a.data=t):a=document.createTextNode(t),n=Yi(e,n,r,a)}else n!==""&&typeof n=="string"?n=e.firstChild.data=t:n=e.textContent=t}else if(t==null||s==="boolean")n=Yi(e,n,r);else{if(s==="function")return we(()=>{let a=t();for(;typeof a=="function";)a=a();n=ec(e,a,n,r)}),()=>n;if(Array.isArray(t)){const a=[],c=n&&Array.isArray(n);if(_u(a,t,n,i))return we(()=>n=ec(e,a,n,r,!0)),()=>n;if(a.length===0){if(n=Yi(e,n,r),o)return n}else c?n.length===0?mh(e,a,r):mw(e,n,a):(n&&Yi(e),mh(e,a));n=a}else if(t.nodeType){if(Array.isArray(n)){if(o)return n=Yi(e,n,r,t);Yi(e,n,null,t)}else n==null||n===""||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);n=t}}return n}function _u(e,t,n,r){let i=!1;for(let s=0,o=t.length;s<o;s++){let a=t[s],c=n&&n[e.length],l;if(!(a==null||a===!0||a===!1))if((l=typeof a)=="object"&&a.nodeType)e.push(a);else if(Array.isArray(a))i=_u(e,a,c)||i;else if(l==="function")if(r){for(;typeof a=="function";)a=a();i=_u(e,Array.isArray(a)?a:[a],Array.isArray(c)?c:[c])||i}else e.push(a),i=!0;else{const f=String(a);c&&c.nodeType===3&&c.data===f?e.push(c):e.push(document.createTextNode(f))}}return i}function mh(e,t,n=null){for(let r=0,i=t.length;r<i;r++)e.insertBefore(t[r],n)}function Yi(e,t,n,r){if(n===void 0)return e.textContent="";const i=r||document.createTextNode("");if(t.length){let s=!1;for(let o=t.length-1;o>=0;o--){const a=t[o];if(i!==a){const c=a.parentNode===e;!s&&!o?c?e.replaceChild(i,a):e.insertBefore(i,n):c&&a.remove()}else s=!0}}else e.insertBefore(i,n);return[i]}const bw="modulepreload",ww=function(e){return"/"+e},_h={},Xr=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(l){return Promise.all(l.map(f=>Promise.resolve(f).then(u=>({status:"fulfilled",value:u}),u=>({status:"rejected",reason:u}))))};document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),c=a?.nonce||a?.getAttribute("nonce");i=o(n.map(l=>{if(l=ww(l),l in _h)return;_h[l]=!0;const f=l.endsWith(".css"),u=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${l}"]${u}`))return;const h=document.createElement("link");if(h.rel=f?"stylesheet":bw,f||(h.as="script"),h.crossOrigin="",h.href=l,c&&h.setAttribute("nonce",c),document.head.appendChild(h),f)return new Promise((d,g)=>{h.addEventListener("load",d),h.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${l}`)))})}))}function s(o){const a=new Event("vite:preloadError",{cancelable:!0});if(a.payload=o,window.dispatchEvent(a),!a.defaultPrevented)throw o}return i.then(o=>{for(const a of o||[])a.status==="rejected"&&s(a.reason);return t().catch(s)})},yu=(e,t)=>t.some(n=>e instanceof n);let yh,bh;function vw(){return yh||(yh=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function xw(){return bh||(bh=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const bu=new WeakMap,fl=new WeakMap,Tc=new WeakMap;function Sw(e){const t=new Promise((n,r)=>{const i=()=>{e.removeEventListener("success",s),e.removeEventListener("error",o)},s=()=>{n(Ai(e.result)),i()},o=()=>{r(e.error),i()};e.addEventListener("success",s),e.addEventListener("error",o)});return Tc.set(t,e),t}function $w(e){if(bu.has(e))return;const t=new Promise((n,r)=>{const i=()=>{e.removeEventListener("complete",s),e.removeEventListener("error",o),e.removeEventListener("abort",o)},s=()=>{n(),i()},o=()=>{r(e.error||new DOMException("AbortError","AbortError")),i()};e.addEventListener("complete",s),e.addEventListener("error",o),e.addEventListener("abort",o)});bu.set(e,t)}let wu={get(e,t,n){if(e instanceof IDBTransaction){if(t==="done")return bu.get(e);if(t==="store")return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return Ai(e[t])},set(e,t,n){return e[t]=n,!0},has(e,t){return e instanceof IDBTransaction&&(t==="done"||t==="store")?!0:t in e}};function Yp(e){wu=e(wu)}function kw(e){return xw().includes(e)?function(...t){return e.apply(vu(this),t),Ai(this.request)}:function(...t){return Ai(e.apply(vu(this),t))}}function Ew(e){return typeof e=="function"?kw(e):(e instanceof IDBTransaction&&$w(e),yu(e,vw())?new Proxy(e,wu):e)}function Ai(e){if(e instanceof IDBRequest)return Sw(e);if(fl.has(e))return fl.get(e);const t=Ew(e);return t!==e&&(fl.set(e,t),Tc.set(t,e)),t}const vu=e=>Tc.get(e);function Xp(e,t,{blocked:n,upgrade:r,blocking:i,terminated:s}={}){const o=indexedDB.open(e,t),a=Ai(o);return r&&o.addEventListener("upgradeneeded",c=>{r(Ai(o.result),c.oldVersion,c.newVersion,Ai(o.transaction),c)}),n&&o.addEventListener("blocked",c=>n(c.oldVersion,c.newVersion,c)),a.then(c=>{s&&c.addEventListener("close",()=>s()),i&&c.addEventListener("versionchange",l=>i(l.oldVersion,l.newVersion,l))}).catch(()=>{}),a}const Aw=["get","getKey","getAll","getAllKeys","count"],Iw=["put","add","delete","clear"],hl=new Map;function wh(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&typeof t=="string"))return;if(hl.get(t))return hl.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,i=Iw.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(i||Aw.includes(n)))return;const s=async function(o,...a){const c=this.transaction(o,i?"readwrite":"readonly");let l=c.store;return r&&(l=l.index(a.shift())),(await Promise.all([l[n](...a),i&&c.done]))[0]};return hl.set(t,s),s}Yp(e=>({...e,get:(t,n,r)=>wh(t,n)||e.get(t,n,r),has:(t,n)=>!!wh(t,n)||e.has(t,n)}));const Cw=["continue","continuePrimaryKey","advance"],vh={},xu=new WeakMap,Qp=new WeakMap,zw={get(e,t){if(!Cw.includes(t))return e[t];let n=vh[t];return n||(n=vh[t]=function(...r){xu.set(this,Qp.get(this)[t](...r))}),n}};async function*Ow(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;t=t;const n=new Proxy(t,zw);for(Qp.set(n,t),Tc.set(n,vu(t));t;)yield n,t=await (xu.get(n)||t.continue()),xu.delete(n)}function xh(e,t){return t===Symbol.asyncIterator&&yu(e,[IDBIndex,IDBObjectStore,IDBCursor])||t==="iterate"&&yu(e,[IDBIndex,IDBObjectStore])}Yp(e=>({...e,get(t,n,r){return xh(t,n)?Ow:e.get(t,n,r)},has(t,n){return xh(t,n)||e.has(t,n)}}));const Md="musicPlaylistDB",Pw=1,mo="playbackPositions",tc="lastPlayed",nc="settings",oi="docIndex",rc="knocks",bs="accessGrants";let ta=null;async function on(){return ta||(ta=Xp(Md,Pw,{upgrade(e){e.objectStoreNames.contains(mo)||e.createObjectStore(mo,{keyPath:"songId"}),e.objectStoreNames.contains(tc)||e.createObjectStore(tc,{keyPath:"playlistId"}),e.objectStoreNames.contains(nc)||e.createObjectStore(nc,{keyPath:"key"}),e.objectStoreNames.contains(oi)||e.createObjectStore(oi,{keyPath:"docId"}),e.objectStoreNames.contains(rc)||e.createObjectStore(rc,{keyPath:"id"}),e.objectStoreNames.contains(bs)||e.createObjectStore(bs,{keyPath:"nodeId"})}}),ta)}async function Tw(){try{const t=await (await on()).getAll(mo),n=new Map;for(const r of t)n.set(r.songId,r.position);return n}catch(e){return console.warn("error loading playback positions:",e),new Map}}async function Ld(e,t){try{await (await on()).put(mo,{songId:e,position:t,updatedAt:Date.now()})}catch(n){console.warn(`error saving playback position for ${e}:`,n)}}async function Dw(e){try{await (await on()).delete(mo,e)}catch(t){console.warn(`error deleting playback position for ${e}:`,t)}}async function Rw(e,t){try{await (await on()).put(tc,{playlistId:e,songId:t,updatedAt:Date.now()})}catch(n){console.warn(`error saving last played for playlist ${e}:`,n)}}async function Fw(e){try{return(await (await on()).get(tc,e))?.songId??null}catch(t){return console.warn(`error loading last played for playlist ${e}:`,t),null}}async function _o(e,t){try{await (await on()).put(nc,{key:e,value:t,updatedAt:Date.now()})}catch(n){console.warn(`error saving setting ${e}:`,n)}}async function Dc(e){try{const n=await (await on()).get(nc,e);return n===void 0?null:n.value}catch(t){return console.warn(`error loading setting ${e}:`,t),null}}const Su={trace:-1,debug:0,info:1,warn:2,error:3};function Bw(){const n=(typeof localStorage<"u"&&typeof localStorage.getItem=="function"?localStorage.getItem("logLevel"):null)??void 0??"warn";return Su[n]??Su.warn}function Uw(){const n=(typeof localStorage<"u"&&typeof localStorage.getItem=="function"?localStorage.getItem("logFilter"):null)??void 0??"";return n?n.split(",").map(r=>r.trim()).filter(Boolean):[]}function jw(e){const t=Uw();return t.length===0?!0:t.some(n=>e===n||e.startsWith(n+"."))}function Vs(e,t,n,...r){if(Su[e]<Bw()||!jw(t))return;const i=`[${t}]`;e==="error"?console.error(i,n,...r):e==="warn"?console.warn(i,n,...r):console.log(i,n,...r)}const Fe={trace:(e,t,...n)=>Vs("trace",e,t,...n),debug:(e,t,...n)=>Vs("debug",e,t,...n),info:(e,t,...n)=>Vs("info",e,t,...n),warn:(e,t,...n)=>Vs("warn",e,t,...n),error:(e,t,...n)=>Vs("error",e,t,...n)},$u="playlistz:docindex-changed";function em(){Fe.trace("idb.docindex","broadcast mutation"),typeof window<"u"&&window.dispatchEvent(new CustomEvent($u));try{const e=new BroadcastChannel(`${Md}-changes`);e.postMessage({type:"mutation",store:oi}),e.close()}catch{}}async function or(e){Fe.trace("idb.docindex","addEntry",e.docId),await (await on()).put(oi,e),em()}async function Mw(e){Fe.trace("idb.docindex","removeEntry",e),await (await on()).delete(oi,e),em()}async function Oi(e){return(await on()).get(oi,e)}async function Br(){return(await on()).getAll(oi)}async function ws(e){await (await on()).put(rc,e)}async function vs(){return(await on()).getAll(rc)}async function Rc(e){await (await on()).put(bs,e)}async function Qs(e){return(await on()).get(bs,e)}async function gl(){return(await on()).getAll(bs)}async function Lw(e){await (await on()).delete(bs,e)}function Nw(){const[e,t]=Q([],{equals:!1});let n=0;async function r(){n++,Fe.debug("docindex","refresh #",String(n));const o=await Br();Fe.debug("docindex","refresh #",String(n),"got",String(o.length),"entries"),t(o)}r();const i=new BroadcastChannel(`${Md}-changes`);i.onmessage=o=>{o.data?.type==="mutation"&&o.data.store===oi&&(Fe.debug("docindex","broadcast invalidation received"),r())};const s=()=>{r()};return window.addEventListener($u,s),rn(()=>{i.close(),window.removeEventListener($u,s)}),e}const Fc=Symbol.for("_am_meta"),yo=Symbol.for("_am_trace"),bo=Symbol.for("_am_objectId"),Nd=Symbol.for("_am_isProxy"),Hd=Symbol.for("_am_clearCache"),Hw=Symbol.for("_am_uint"),Zw=Symbol.for("_am_int"),Vw=Symbol.for("_am_f64"),tm=Symbol.for("_am_counter"),nm=Symbol.for("_am_immutableString");class ku{constructor(t){this.value=t||0,Reflect.defineProperty(this,tm,{value:!0})}valueOf(){return this.value}toString(){return this.valueOf().toString()}toJSON(){return this.value}increment(t){throw new Error("Counters should not be incremented outside of a change callback")}decrement(t){throw new Error("Counters should not be decremented outside of a change callback")}}class Ww extends ku{constructor(t,n,r,i,s){super(t),this.context=n,this.path=r,this.objectId=i,this.key=s}increment(t){return t=typeof t=="number"?t:1,this.context.increment(this.objectId,this.key,t),this.value+=t,this.value}decrement(t){return this.increment(typeof t=="number"?-t:-1)}}function qw(e,t,n,r,i){return new Ww(e,t,n,r,i)}var rm;class im{constructor(t){this[rm]=!0,this.val=t}toString(){return this.val}toJSON(){return this.val}}rm=nm;const Jw=BigInt("9223372036854775807");function xs(e,t,n){if(e===void 0)throw new RangeError([`Cannot assign undefined value at ${Eu(n)}, `,"You might consider setting the property's value to `null`, ","or using `delete` to remove it altogether."].join(""));if(!(e===null||typeof e!=="object")){if(t&&No(e,t))throw new RangeError("Cannot create a reference to an existing document object");if(e instanceof Array)for(let i=0;i<e.length;i++)xs(e[i],t,[...n,i]);else if(Object.prototype.toString.call(e)==="[object Object]")for(const i in e)xs(e[i],t,[...n,i])}}function Ar(e){if(typeof e=="string"&&/^[0-9]+$/.test(e)&&(e=parseInt(e,10)),typeof e!="number")return e;if(e<0||isNaN(e)||e===1/0||e===-1/0)throw new RangeError("A list index must be positive, but you passed "+e);return e}function Cn(e,t){const{context:n,objectId:r,path:i}=e,s=n.getWithType(r,t);if(s===null)return;const o=s[0],a=s[1];switch(o){case void 0:return;case"map":return sm(n,a,[...i,t]);case"list":return Yw(n,a,[...i,t]);case"text":return n.text(a);case"str":return new im(a);case"uint":return a;case"int":return a;case"f64":return a;case"boolean":return a;case"null":return null;case"bytes":return a;case"timestamp":return a;case"counter":return qw(a,n,i,r,t);default:throw RangeError(`datatype ${o} unimplemented`)}}function Zd(e,t,n){const r=typeof e;switch(r){case"object":if(e==null)return[null,"null"];if(e[Hw])return[e.value,"uint"];if(e[Zw])return[e.value,"int"];if(e[Vw])return[e.value,"f64"];if(e[tm])return[e.value,"counter"];if(e instanceof Date)return[e.getTime(),"timestamp"];if(om(e))return[e.toString(),"str"];if(e instanceof Uint8Array)return[e,"bytes"];if(e instanceof Array)return[e,"list"];if(Object.prototype.toString.call(e)==="[object Object]")return[e,"map"];throw No(e,n)?new RangeError("Cannot create a reference to an existing document object"):new RangeError(`Cannot assign unknown object: ${e}`);case"boolean":return[e,"boolean"];case"bigint":return e>Jw?[e,"uint"]:[e,"int"];case"number":return Number.isInteger(e)?[e,"int"]:[e,"f64"];case"string":return[e,"text"];case"undefined":throw new RangeError([`Cannot assign undefined value at ${Eu(t)}, `,"because `undefined` is not a valid JSON data type. ","You might consider setting the property's value to `null`, ","or using `delete` to remove it altogether."].join(""));default:throw new RangeError([`Cannot assign ${r} value at ${Eu(t)}. `,"All JSON primitive datatypes (object, array, string, number, boolean, null) ",`are supported in an Automerge document; ${r} values are not. `].join(""))}}function No(e,t){var n,r;return e instanceof Date?!1:!!(e&&((r=(n=e[Fc])===null||n===void 0?void 0:n.handle)===null||r===void 0?void 0:r.__wbg_ptr)===t.__wbg_ptr)}const Kw={get(e,t){const{context:n,objectId:r,cache:i}=e;return t===Symbol.toStringTag?e[Symbol.toStringTag]:t===bo?r:t===Nd?!0:t===yo?e.trace:t===Fc?{handle:n}:(i[t]||(i[t]=Cn(e,t)),i[t])},set(e,t,n){const{context:r,objectId:i,path:s}=e;if(e.cache={},No(n,r))throw new RangeError("Cannot create a reference to an existing document object");if(t===yo)return e.trace=n,!0;if(t===Hd)return!0;const[o,a]=Zd(n,[...s,t],r);switch(a){case"list":case"map":{xs(o,r,[...s,t]),r.putObjectFromHydrate(i,t,o);break}case"text":{r.putObject(i,t,o);break}default:r.put(i,t,o,a)}return!0},deleteProperty(e,t){const{context:n,objectId:r}=e;return e.cache={},n.delete(r,t),!0},has(e,t){return this.get(e,t)!==void 0},getOwnPropertyDescriptor(e,t){const n=this.get(e,t);if(typeof n<"u")return{configurable:!0,enumerable:!0,value:n}},ownKeys(e){const{context:t,objectId:n}=e,r=t.keys(n);return[...new Set(r)]}},Gw={get(e,t){const{context:n,objectId:r}=e;return t=Ar(t),t===Symbol.hasInstance?i=>Array.isArray(i):t===Symbol.toStringTag?e[Symbol.toStringTag]:t===bo?r:t===Nd?!0:t===yo?e.trace:t===Fc?{handle:n}:t==="length"?n.length(r):typeof t=="number"?Cn(e,t):Qw(e)[t]},set(e,t,n){const{context:r,objectId:i,path:s}=e;if(t=Ar(t),No(n,r))throw new RangeError("Cannot create a reference to an existing document object");if(t===Hd)return!0;if(t===yo)return e.trace=n,!0;if(typeof t=="string")throw new RangeError("list index must be a number");const[o,a]=Zd(n,[...s,t],r);switch(a){case"list":case"map":{xs(o,r,[...s,t]),t>=r.length(i)?r.insertObjectFromHydrate(i,t,o):r.putObjectFromHydrate(i,t,o);break}case"text":{t>=r.length(i)?r.insertObject(i,t,o):r.putObject(i,t,o);break}default:t>=r.length(i)?r.insert(i,t,o,a):r.put(i,t,o,a)}return!0},deleteProperty(e,t){const{context:n,objectId:r}=e;t=Ar(t);const i=n.get(r,t);if(i!=null&&i[0]=="counter")throw new TypeError("Unsupported operation: deleting a counter from a list");return n.delete(r,t),!0},has(e,t){const{context:n,objectId:r}=e;return t=Ar(t),typeof t=="number"?t<n.length(r):t==="length"},getOwnPropertyDescriptor(e,t){const{context:n,objectId:r}=e;return t==="length"?{writable:!0,value:n.length(r)}:t===bo?{configurable:!1,enumerable:!1,value:r}:(t=Ar(t),{configurable:!0,enumerable:!0,value:Cn(e,t)})},getPrototypeOf(e){return Object.getPrototypeOf(e)},ownKeys(){const e=[];return e.push("length"),e}};function sm(e,t,n){const r={context:e,objectId:t,path:n||[],cache:{}},i={};return Object.assign(i,r),new Proxy(i,Kw)}function Yw(e,t,n){const r={context:e,objectId:t,path:n||[],cache:{}},i=[];return Object.assign(i,r),new Proxy(i,Gw)}function Xw(e){return sm(e,"_root",[])}function Qw(e){const{context:t,objectId:n,path:r}=e;return{at(s){return Cn(e,s)},deleteAt(s,o){return typeof o=="number"?t.splice(n,s,o):t.delete(n,s),this},fill(s,o,a){const[c,l]=Zd(s,[...r,o],t),f=t.length(n);o=Ar(o||0),a=Ar(a||f);for(let u=o;u<Math.min(a,f);u++)l==="list"||l==="map"||l==="text"?t.putObject(n,u,c):t.put(n,u,c,l);return this},indexOf(s,o=0){const a=t.length(n);for(let c=o;c<a;c++){const l=t.getWithType(n,c);if(!l)continue;const[f,u]=l;if(!["map","list","text"].includes(f)){if(u===s)return c;continue}if(f==="text"&&typeof s=="string"&&s===Cn(e,c)||s[bo]===u)return c}return-1},insertAt(s,...o){return this.splice(s,0,...o),this},pop(){const s=t.length(n);if(s==0)return;const o=Cn(e,s-1);return t.delete(n,s-1),o},push(...s){const o=t.length(n);return this.splice(o,0,...s),t.length(n)},shift(){if(t.length(n)==0)return;const s=Cn(e,0);return t.delete(n,0),s},splice(s,o,...a){s=Ar(s),typeof o!="number"&&(o=t.length(n)-s),o=Ar(o);for(const l of a)if(No(l,t))throw new RangeError("Cannot create a reference to an existing document object");const c=[];for(let l=0;l<o;l++){const f=Cn(e,s+l);f!==void 0&&c.push(f)}for(let l=0;l<a.length;l++)try{xs(a[l],t,[...r,s+l])}catch(f){throw f instanceof RangeError?new RangeError(`${f.message} (at index ${l} in the input)`):f}return t.spliceFromHydrate(n,s,o,a),c},unshift(...s){return this.splice(0,0,...s),t.length(n)},entries(){let s=0;return{next:()=>{const a=Cn(e,s);return a===void 0?{value:void 0,done:!0}:{value:[s++,a],done:!1}},[Symbol.iterator](){return this}}},keys(){let s=0;const o=t.length(n);return{next:()=>s<o?{value:s++,done:!1}:{value:void 0,done:!0},[Symbol.iterator](){return this}}},values(){let s=0;return{next:()=>{const a=Cn(e,s++);return a===void 0?{value:void 0,done:!0}:{value:a,done:!1}},[Symbol.iterator](){return this}}},toArray(){const s=[];let o;do o=Cn(e,s.length),o!==void 0&&s.push(o);while(o!==void 0);return s},map(s){return this.toArray().map(s)},toString(){return this.toArray().toString()},toLocaleString(){return this.toArray().toLocaleString()},forEach(s){return this.toArray().forEach(s)},concat(s){return this.toArray().concat(s)},every(s){return this.toArray().every(s)},filter(s){return this.toArray().filter(s)},find(s){let o=0;for(const a of this){if(s(a,o))return a;o+=1}},findIndex(s){let o=0;for(const a of this){if(s(a,o))return o;o+=1}return-1},includes(s){return this.find(o=>o===s)!==void 0},join(s){return this.toArray().join(s)},reduce(s,o){return this.toArray().reduce(s,o)},reduceRight(s,o){return this.toArray().reduceRight(s,o)},lastIndexOf(s,o=1/0){return this.toArray().lastIndexOf(s,o)},slice(s,o){return this.toArray().slice(s,o)},some(s){let o=0;for(const a of this){if(s(a,o))return!0;o+=1}return!1},[Symbol.iterator]:function*(){let s=0,o=Cn(e,s);for(;o!==void 0;)yield o,s+=1,o=Cn(e,s)}}}function Eu(e){const t=e.map(n=>{if(typeof n=="number")return n.toString();if(typeof n=="string")return n.replace(/~/g,"~0").replace(/\//g,"~1")});return e.length===0?"":"/"+t.join("/")}function om(e){return typeof e=="object"&&e!==null&&Object.prototype.hasOwnProperty.call(e,nm)}let Sh=class Au{static __wrap(t){t=t>>>0;const n=Object.create(Au.prototype);return n.__wbg_ptr=t,$h.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,$h.unregister(this),t}free(){const t=this.__destroy_into_raw();zn.__wbg_syncstate_free(t,0)}clone(){const t=zn.syncstate_clone(this.__wbg_ptr);return Au.__wrap(t)}get lastSentHeads(){return zn.syncstate_lastSentHeads(this.__wbg_ptr)}get peerReadOnly(){return zn.syncstate_peerReadOnly(this.__wbg_ptr)!==0}get readOnly(){return zn.syncstate_readOnly(this.__wbg_ptr)!==0}set lastSentHeads(t){const n=zn.syncstate_set_lastSentHeads(this.__wbg_ptr,t);if(n[1])throw kh(n[0])}set readOnly(t){zn.syncstate_set_readOnly(this.__wbg_ptr,t)}set sentHashes(t){const n=zn.syncstate_set_sentHashes(this.__wbg_ptr,t);if(n[1])throw kh(n[0])}get sharedHeads(){return zn.syncstate_sharedHeads(this.__wbg_ptr)}};Symbol.dispose&&(Sh.prototype[Symbol.dispose]=Sh.prototype.free);typeof FinalizationRegistry>"u"||new FinalizationRegistry(e=>zn.__wbg_automerge_free(e>>>0,1));const $h=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>zn.__wbg_syncstate_free(e>>>0,1));function kh(e){const t=zn.__wbindgen_externrefs.get(e);return zn.__externref_table_dealloc(e),t}let e1=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});e1.decode();const pl=new TextEncoder;"encodeInto"in pl||(pl.encodeInto=function(e,t){const n=pl.encode(e);return t.set(n),{read:e.length,written:n.length}});let zn,t1=[];function n1(e){for(const t in e)mn[t]=e[t];for(const t of t1)t()}const mn={create(e){throw new RangeError("Automerge.use() not called")},load(e,t){throw new RangeError("Automerge.use() not called (load)")},encodeChange(e){throw new RangeError("Automerge.use() not called (encodeChange)")},decodeChange(e){throw new RangeError("Automerge.use() not called (decodeChange)")},initSyncState(){throw new RangeError("Automerge.use() not called (initSyncState)")},encodeSyncMessage(e){throw new RangeError("Automerge.use() not called (encodeSyncMessage)")},decodeSyncMessage(e){throw new RangeError("Automerge.use() not called (decodeSyncMessage)")},encodeSyncState(e){throw new RangeError("Automerge.use() not called (encodeSyncState)")},decodeSyncState(e){throw new RangeError("Automerge.use() not called (decodeSyncState)")},exportSyncState(e){throw new RangeError("Automerge.use() not called (exportSyncState)")},importSyncState(e){throw new RangeError("Automerge.use() not called (importSyncState)")},readBundle(e){throw new RangeError("Automerge.use() not called (readBundle)")},wasmReleaseInfo(){throw new RangeError("Automerge.use() not called (wasmReleaseInfo)")}},r1="a11222254d2f86ec9df0738e7002f15a930fe9b4";function Et(e,t=!0){if(typeof e!="object")throw new RangeError("must be the document root");const n=Reflect.get(e,Fc);if(n===void 0||n==null||t&&lm(e)!=="_root")throw new RangeError("must be the document root");return n}function am(e){Reflect.set(e,Hd,!0)}function cm(e){return Reflect.get(e,yo)}function lm(e){return typeof e!="object"||e===null?null:Reflect.get(e,bo)}function Ps(e){return!!Reflect.get(e,Nd)}var i1=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n};function Vd(e){return typeof e=="object"?e:{actor:e}}function s1(e,t,n){if(typeof n=="string"){if(/^-?[0-9]+@[0-9a-zA-Z]+$|^[se]$/.test(n))return e.handle.getCursorPosition(t,n);throw new RangeError("index must be a number or cursor")}else return n}function Hn(e){const t=Vd(e),n=!!t.freeze,r=t.patchCallback,i=t.actor,s=mn.create({actor:i});return s.enableFreeze(!!t.freeze),hm(s),s.materialize("/",void 0,{handle:s,heads:void 0,freeze:n,patchCallback:r})}function o1(e,t){const n=Et(e),r=n.handle;return n.handle.materialize("/",t,Object.assign(Object.assign({},n),{handle:r,heads:t}))}function ic(e,t){const n=Et(e),r=n.heads,i=Vd(t),s=n.handle.fork(i.actor,r);s.updateDiffCursor();const{heads:o}=n,a=i1(n,["heads"]);return a.patchCallback=i.patchCallback,s.applyPatches(e,Object.assign(Object.assign({},a),{handle:s}))}function Eh(e,t){(typeof e!="object"||Array.isArray(e))&&(e=Object.assign({},e)),xs(e,null,[]);const n=Hn(t);return wo(n,"from",{},r=>(Et(n).handle.initRootFromHydrate(e),r)).newDoc}function a1(e,t,n){if(typeof t=="function")return wo(e,"change",{},t).newDoc;if(typeof n=="function")return typeof t=="string"&&(t={message:t}),wo(e,"change",t,n).newDoc;throw RangeError("Invalid args for change")}function c1(e,t,n,r){if(typeof n=="function")return wo(e,"changeAt",{},n,t);if(typeof r=="function")return typeof n=="string"&&(n={message:n}),wo(e,"changeAt",n,r,t);throw RangeError("Invalid args for changeAt")}function Ho(e,t,n,r){if(n==null)return e;const i=Et(e),s=Object.assign(Object.assign({},i),{heads:void 0}),{value:o,patches:a}=i.handle.applyAndReturnPatches(e,s);if(a.length>0){r?.(a,{before:e,after:o,source:t});const c=Et(o);c.mostRecentPatch={before:Et(e).heads,after:c.handle.getHeads(),patches:a}}return i.heads=n,o}function wo(e,t,n,r,i){if(typeof r!="function")throw new RangeError("invalid change function");const s=Et(e);if(e===void 0||s===void 0)throw new RangeError("must be the document root");if(s.heads)throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy.");if(Ps(e))throw new RangeError("Calls to Automerge.change cannot be nested");let o=s.handle.getHeads();i&&u1(i,o)&&(i=void 0),i&&(s.handle.isolate(i),o=i),"time"in n||(n.time=Math.floor(Date.now()/1e3));try{s.heads=o;const a=Xw(s.handle);if(r(a),s.handle.pendingOps()===0)return s.heads=void 0,i&&s.handle.integrate(),{newDoc:e,newHeads:null};{const c=s.handle.commit(n.message,n.time);return s.handle.integrate(),{newDoc:Ho(e,t,o,n.patchCallback||s.patchCallback),newHeads:c!=null?[c]:null}}}catch(a){throw s.heads=void 0,s.handle.rollback(),a}}function Ah(e,t){t===void 0&&(t={}),typeof t=="string"&&(t={message:t}),"time"in t||(t.time=Math.floor(Date.now()/1e3));const n=Et(e);if(n.heads)throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy.");if(Ps(e))throw new RangeError("Calls to Automerge.change cannot be nested");const r=n.handle.getHeads();return n.handle.emptyChange(t.message,t.time),Ho(e,"emptyChange",r)}function l1(e,t){const n=Vd(t);if(n.patchCallback)return Wd(Hn(n),e);const r=n.actor,i=n.patchCallback,s=n.unchecked||!1,o=n.allowMissingChanges||!1,a=n.convertImmutableStringsToText||!1,c=mn.load(e,{actor:r,unchecked:s,allowMissingDeps:o,convertImmutableStringsToText:a});return c.enableFreeze(!!n.freeze),hm(c),c.materialize("/",void 0,{handle:c,heads:void 0,patchCallback:i})}function Wd(e,t,n){n||(n={});const r=Et(e);if(r.heads)throw new RangeError("Attempting to change an out of date document - set at: "+cm(e));if(Ps(e))throw new RangeError("Calls to Automerge.change cannot be nested");const i=r.handle.getHeads();return r.handle.loadIncremental(t),Ho(e,"loadIncremental",i,n.patchCallback||r.patchCallback)}function um(e){return Et(e).handle.save()}function Ih(e,t){const n=Et(e);if(n.heads)throw new RangeError("Attempting to change an out of date document - set at: "+cm(e));const r=n.handle.getHeads(),i=Et(t),s=n.handle.getChangesAdded(i.handle);return n.handle.applyChanges(s),Ho(e,"merge",r,n.patchCallback)}function ml(e,t,n){Ch(t,"before heads"),Ch(n,"after heads");const r=Et(e);return r.mostRecentPatch&&Iu(r.mostRecentPatch.before,t)&&Iu(r.mostRecentPatch.after,n)?r.mostRecentPatch.patches:r.handle.diff(t,n)}function u1(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Ch(e,t){if(!Array.isArray(e))throw new Error(`invalid ${t}: must be an array`)}function Iu(e,t){if(!zh(e)||!zh(t))return e===t;const n=Object.keys(e).sort(),r=Object.keys(t).sort();if(n.length!==r.length)return!1;for(let i=0;i<n.length;i++)if(n[i]!==r[i]||!Iu(e[n[i]],t[r[i]]))return!1;return!0}function dm(e){const t=mn.importSyncState(e),n=mn.encodeSyncState(t);return t.free(),n}function fm(e){const t=mn.decodeSyncState(e),n=mn.exportSyncState(t);return t.free(),n}function d1(e,t){const n=Et(e),r=mn.importSyncState(t),i=n.handle.generateSyncMessage(r);return[mn.exportSyncState(r),i]}function f1(e,t,n,r){const i=mn.importSyncState(t);r||(r={});const s=Et(e);if(s.heads)throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy.");if(Ps(e))throw new RangeError("Calls to Automerge.change cannot be nested");const o=s.handle.getHeads();s.handle.receiveSyncMessage(i,n);const a=mn.exportSyncState(i);return[Ho(e,"receiveSyncMessage",o,r.patchCallback||s.patchCallback),a,null]}function h1(e){return mn.exportSyncState(mn.initSyncState())}function g1(e){return mn.decodeSyncMessage(e)}function Bn(e){const t=Et(e);return t.heads||t.handle.getHeads()}function zh(e){return typeof e=="object"&&e!==null}function p1(e,t){return Et(e).handle.saveSince(t)}function hm(e){e.registerDatatype("counter",t=>new ku(t),t=>{if(t instanceof ku)return t.value}),e.registerDatatype("str",t=>new im(t),t=>{if(om(t))return t.val})}function m1(e){return Et(e).handle.topoHistoryTraversal()}function _1(e,t){return Et(e).handle.getDecodedChangeByHash(t)}function qd(e){var t,n,r,i,s,o;const c=Et(e).handle.stats(),l=y1();return Object.assign(Object.assign({},c),{cargoPackageName:(n=(t=l.wasm)===null||t===void 0?void 0:t.cargoPackageName)!==null&&n!==void 0?n:"unknown",cargoPackageVersion:(i=(r=l.wasm)===null||r===void 0?void 0:r.cargoPackageVersion)!==null&&i!==void 0?i:"unknown",rustcVersion:(o=(s=l.wasm)===null||s===void 0?void 0:s.rustcVersion)!==null&&o!==void 0?o:"unknown"})}function y1(){let e=null;try{e=mn.wasmReleaseInfo()}catch{}return{js:{gitHead:r1},wasm:e}}function gm(e,t,n,r,i){const s=Bc(e,t,"splice");if(!Ps(e))throw new RangeError("object cannot be modified outside of a change block");const o=Et(e,!1);am(e),n=s1(o,s,n);try{return o.handle.splice(s,n,r,i)}catch(a){throw new RangeError(`Cannot splice: ${a}`)}}function b1(e,t,n){const r=Bc(e,t,"updateText");if(!Ps(e))throw new RangeError("object cannot be modified outside of a change block");const i=Et(e,!1);am(e);try{return i.handle.updateText(r,n)}catch(s){throw new RangeError(`Cannot updateText: ${s}`)}}function Oh(e,t,n,r){const i=Bc(e,t,"getCursor"),s=Et(e,!1);try{return s.handle.getCursor(i,n,s.heads,r)}catch(o){throw new RangeError(`Cannot getCursor: ${o}`)}}function Ph(e,t,n){const r=Bc(e,t,"getCursorPosition"),i=Et(e,!1);try{return i.handle.getCursorPosition(r,n,i.heads)}catch(s){throw new RangeError(`Cannot getCursorPosition: ${s}`)}}function Bc(e,t,n){t=t.slice();const r=lm(e);if(!r)throw new RangeError(`invalid object for ${n}`);return t.unshift(r),t.join("/")}var na=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ts(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ra={exports:{}},_l,Th;function w1(){if(Th)return _l;Th=1;var e=1e3,t=e*60,n=t*60,r=n*24,i=r*7,s=r*365.25;_l=function(f,u){u=u||{};var h=typeof f;if(h==="string"&&f.length>0)return o(f);if(h==="number"&&isFinite(f))return u.long?c(f):a(f);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(f))};function o(f){if(f=String(f),!(f.length>100)){var u=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(f);if(u){var h=parseFloat(u[1]),d=(u[2]||"ms").toLowerCase();switch(d){case"years":case"year":case"yrs":case"yr":case"y":return h*s;case"weeks":case"week":case"w":return h*i;case"days":case"day":case"d":return h*r;case"hours":case"hour":case"hrs":case"hr":case"h":return h*n;case"minutes":case"minute":case"mins":case"min":case"m":return h*t;case"seconds":case"second":case"secs":case"sec":case"s":return h*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return h;default:return}}}}function a(f){var u=Math.abs(f);return u>=r?Math.round(f/r)+"d":u>=n?Math.round(f/n)+"h":u>=t?Math.round(f/t)+"m":u>=e?Math.round(f/e)+"s":f+"ms"}function c(f){var u=Math.abs(f);return u>=r?l(f,u,r,"day"):u>=n?l(f,u,n,"hour"):u>=t?l(f,u,t,"minute"):u>=e?l(f,u,e,"second"):f+" ms"}function l(f,u,h,d){var g=u>=h*1.5;return Math.round(f/h)+" "+d+(g?"s":"")}return _l}var yl,Dh;function v1(){if(Dh)return yl;Dh=1;function e(t){r.debug=r,r.default=r,r.coerce=l,r.disable=a,r.enable=s,r.enabled=c,r.humanize=w1(),r.destroy=f,Object.keys(t).forEach(u=>{r[u]=t[u]}),r.names=[],r.skips=[],r.formatters={};function n(u){let h=0;for(let d=0;d<u.length;d++)h=(h<<5)-h+u.charCodeAt(d),h|=0;return r.colors[Math.abs(h)%r.colors.length]}r.selectColor=n;function r(u){let h,d=null,g,p;function m(...b){if(!m.enabled)return;const x=m,_=Number(new Date),E=_-(h||_);x.diff=E,x.prev=h,x.curr=_,h=_,b[0]=r.coerce(b[0]),typeof b[0]!="string"&&b.unshift("%O");let k=0;b[0]=b[0].replace(/%([a-zA-Z%])/g,(T,j)=>{if(T==="%%")return"%";k++;const I=r.formatters[j];if(typeof I=="function"){const R=b[k];T=I.call(x,R),b.splice(k,1),k--}return T}),r.formatArgs.call(x,b),(x.log||r.log).apply(x,b)}return m.namespace=u,m.useColors=r.useColors(),m.color=r.selectColor(u),m.extend=i,m.destroy=r.destroy,Object.defineProperty(m,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(g!==r.namespaces&&(g=r.namespaces,p=r.enabled(u)),p),set:b=>{d=b}}),typeof r.init=="function"&&r.init(m),m}function i(u,h){const d=r(this.namespace+(typeof h>"u"?":":h)+u);return d.log=this.log,d}function s(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];const h=(typeof u=="string"?u:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const d of h)d[0]==="-"?r.skips.push(d.slice(1)):r.names.push(d)}function o(u,h){let d=0,g=0,p=-1,m=0;for(;d<u.length;)if(g<h.length&&(h[g]===u[d]||h[g]==="*"))h[g]==="*"?(p=g,m=d,g++):(d++,g++);else if(p!==-1)g=p+1,m++,d=m;else return!1;for(;g<h.length&&h[g]==="*";)g++;return g===h.length}function a(){const u=[...r.names,...r.skips.map(h=>"-"+h)].join(",");return r.enable(""),u}function c(u){for(const h of r.skips)if(o(u,h))return!1;for(const h of r.names)if(o(u,h))return!0;return!1}function l(u){return u instanceof Error?u.stack||u.message:u}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.enable(r.load()),r}return yl=e,yl}var Rh;function x1(){return Rh||(Rh=1,(function(e,t){var n={};t.formatArgs=i,t.save=s,t.load=o,t.useColors=r,t.storage=a(),t.destroy=(()=>{let l=!1;return()=>{l||(l=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function r(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let l;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(l=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(l[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function i(l){if(l[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+l[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const f="color: "+this.color;l.splice(1,0,f,"color: inherit");let u=0,h=0;l[0].replace(/%[a-zA-Z%]/g,d=>{d!=="%%"&&(u++,d==="%c"&&(h=u))}),l.splice(h,0,f)}t.log=console.debug||console.log||(()=>{});function s(l){try{l?t.storage.setItem("debug",l):t.storage.removeItem("debug")}catch{}}function o(){let l;try{l=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch{}return!l&&typeof process<"u"&&"env"in process&&(l=n.DEBUG),l}function a(){try{return localStorage}catch{}}e.exports=v1()(t);const{formatters:c}=e.exports;c.j=function(l){try{return JSON.stringify(l)}catch(f){return"[UnexpectedJSONParseError]: "+f.message}}})(ra,ra.exports)),ra.exports}var S1=x1();const Ui=Ts(S1);var bl={exports:{}},Fh;function $1(){return Fh||(Fh=1,(function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function i(c,l,f){this.fn=c,this.context=l,this.once=f||!1}function s(c,l,f,u,h){if(typeof f!="function")throw new TypeError("The listener must be a function");var d=new i(f,u||c,h),g=n?n+l:l;return c._events[g]?c._events[g].fn?c._events[g]=[c._events[g],d]:c._events[g].push(d):(c._events[g]=d,c._eventsCount++),c}function o(c,l){--c._eventsCount===0?c._events=new r:delete c._events[l]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var l=[],f,u;if(this._eventsCount===0)return l;for(u in f=this._events)t.call(f,u)&&l.push(n?u.slice(1):u);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(f)):l},a.prototype.listeners=function(l){var f=n?n+l:l,u=this._events[f];if(!u)return[];if(u.fn)return[u.fn];for(var h=0,d=u.length,g=new Array(d);h<d;h++)g[h]=u[h].fn;return g},a.prototype.listenerCount=function(l){var f=n?n+l:l,u=this._events[f];return u?u.fn?1:u.length:0},a.prototype.emit=function(l,f,u,h,d,g){var p=n?n+l:l;if(!this._events[p])return!1;var m=this._events[p],b=arguments.length,x,_;if(m.fn){switch(m.once&&this.removeListener(l,m.fn,void 0,!0),b){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,f),!0;case 3:return m.fn.call(m.context,f,u),!0;case 4:return m.fn.call(m.context,f,u,h),!0;case 5:return m.fn.call(m.context,f,u,h,d),!0;case 6:return m.fn.call(m.context,f,u,h,d,g),!0}for(_=1,x=new Array(b-1);_<b;_++)x[_-1]=arguments[_];m.fn.apply(m.context,x)}else{var E=m.length,k;for(_=0;_<E;_++)switch(m[_].once&&this.removeListener(l,m[_].fn,void 0,!0),b){case 1:m[_].fn.call(m[_].context);break;case 2:m[_].fn.call(m[_].context,f);break;case 3:m[_].fn.call(m[_].context,f,u);break;case 4:m[_].fn.call(m[_].context,f,u,h);break;default:if(!x)for(k=1,x=new Array(b-1);k<b;k++)x[k-1]=arguments[k];m[_].fn.apply(m[_].context,x)}}return!0},a.prototype.on=function(l,f,u){return s(this,l,f,u,!1)},a.prototype.once=function(l,f,u){return s(this,l,f,u,!0)},a.prototype.removeListener=function(l,f,u,h){var d=n?n+l:l;if(!this._events[d])return this;if(!f)return o(this,d),this;var g=this._events[d];if(g.fn)g.fn===f&&(!h||g.once)&&(!u||g.context===u)&&o(this,d);else{for(var p=0,m=[],b=g.length;p<b;p++)(g[p].fn!==f||h&&!g[p].once||u&&g[p].context!==u)&&m.push(g[p]);m.length?this._events[d]=m.length===1?m[0]:m:o(this,d)}return this},a.prototype.removeAllListeners=function(l){var f;return l?(f=n?n+l:l,this._events[f]&&o(this,f)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a})(bl)),bl.exports}var k1=$1();const ji=Ts(k1);function E1(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function A1(){const e=E1();if(e.__xstate__)return e.__xstate__}const I1=e=>{if(typeof window>"u")return;const t=A1();t&&t.register(e)};class Bh{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const n={value:t,next:null};if(this._current){this._last.next=n,this._last=n;return}this._current=n,this._last=n,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const pm=".",C1="",mm="",z1="#",O1="*",_m="xstate.init",P1="xstate.error",Cu="xstate.stop";function T1(e,t){return{type:`xstate.after.${e}.${t}`}}function zu(e,t){return{type:`xstate.done.state.${e}`,output:t}}function D1(e,t){return{type:`xstate.done.actor.${e}`,output:t,actorId:e}}function ym(e,t){return{type:`xstate.error.actor.${e}`,error:t,actorId:e}}function bm(e){return{type:_m,input:e}}function gr(e){setTimeout(()=>{throw e})}const R1=typeof Symbol=="function"&&Symbol.observable||"@@observable";function wm(e,t){const n=Uh(e),r=Uh(t);return typeof r=="string"?typeof n=="string"?r===n:!1:typeof n=="string"?n in r:Object.keys(n).every(i=>i in r?wm(n[i],r[i]):!1)}function Jd(e){if(xm(e))return e;const t=[];let n="";for(let r=0;r<e.length;r++){switch(e.charCodeAt(r)){case 92:n+=e[r+1],r++;continue;case 46:t.push(n),n="";continue}n+=e[r]}return t.push(n),t}function Uh(e){if(_v(e))return e.value;if(typeof e!="string")return e;const t=Jd(e);return F1(t)}function F1(e){if(e.length===1)return e[0];const t={};let n=t;for(let r=0;r<e.length-1;r++)if(r===e.length-2)n[e[r]]=e[r+1];else{const i=n;n={},i[e[r]]=n}return t}function jh(e,t){const n={},r=Object.keys(e);for(let i=0;i<r.length;i++){const s=r[i];n[s]=t(e[s],s,e,i)}return n}function vm(e){return xm(e)?e:[e]}function Ir(e){return e===void 0?[]:vm(e)}function Ou(e,t,n,r){return typeof e=="function"?e({context:t,event:n,self:r}):e}function xm(e){return Array.isArray(e)}function B1(e){return e.type.startsWith("xstate.error.actor")}function ss(e){return vm(e).map(t=>typeof t>"u"||typeof t=="string"?{target:t}:t)}function Sm(e){if(!(e===void 0||e===C1))return Ir(e)}function za(e,t,n){const r=typeof e=="object",i=r?e:void 0;return{next:(r?e.next:e)?.bind(i),error:(r?e.error:t)?.bind(i),complete:(r?e.complete:n)?.bind(i)}}function Mh(e,t){return`${t}.${e}`}function Kd(e,t){const n=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!n)return e.implementations.actors[t];const[,r,i]=n,o=e.getStateNodeById(i).config.invoke;return(Array.isArray(o)?o[r]:o).src}function $m(e,t){if(t===e||t===O1)return!0;if(!t.endsWith(".*"))return!1;const n=t.split("."),r=e.split(".");for(let i=0;i<n.length;i++){const s=n[i],o=r[i];if(s==="*")return i===n.length-1;if(s!==o)return!1}return!0}function Lh(e,t){return`${e.sessionId}.${t}`}let U1=0;function j1(e,t){const n=new Map,r=new Map,i=new WeakMap,s=new Set,o={},{clock:a,logger:c}=t,l={schedule:(h,d,g,p,m=Math.random().toString(36).slice(2))=>{const b={source:h,target:d,event:g,delay:p,id:m,startedAt:Date.now()},x=Lh(h,m);u._snapshot._scheduledEvents[x]=b;const _=a.setTimeout(()=>{delete o[x],delete u._snapshot._scheduledEvents[x],u._relay(h,d,g)},p);o[x]=_},cancel:(h,d)=>{const g=Lh(h,d),p=o[g];delete o[g],delete u._snapshot._scheduledEvents[g],p!==void 0&&a.clearTimeout(p)},cancelAll:h=>{for(const d in u._snapshot._scheduledEvents){const g=u._snapshot._scheduledEvents[d];g.source===h&&l.cancel(h,g.id)}}},f=h=>{if(!s.size)return;const d={...h,rootId:e.sessionId};s.forEach(g=>g.next?.(d))},u={_snapshot:{_scheduledEvents:(t?.snapshot&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${U1++}`,_register:(h,d)=>(n.set(h,d),h),_unregister:h=>{n.delete(h.sessionId);const d=i.get(h);d!==void 0&&(r.delete(d),i.delete(h))},get:h=>r.get(h),getAll:()=>Object.fromEntries(r.entries()),_set:(h,d)=>{const g=r.get(h);if(g&&g!==d)throw new Error(`Actor with system ID '${h}' already exists.`);r.set(h,d),i.set(d,h)},inspect:h=>{const d=za(h);return s.add(d),{unsubscribe(){s.delete(d)}}},_sendInspectionEvent:f,_relay:(h,d,g)=>{u._sendInspectionEvent({type:"@xstate.event",sourceRef:h,actorRef:d,event:g}),d._send(g)},scheduler:l,getSnapshot:()=>({_scheduledEvents:{...u._snapshot._scheduledEvents}}),start:()=>{const h=u._snapshot._scheduledEvents;u._snapshot._scheduledEvents={};for(const d in h){const{source:g,target:p,event:m,delay:b,id:x}=h[d];l.schedule(g,p,m,b,x)}},_clock:a,_logger:c};return u}let wl=!1;const Gd=1;let bn=(function(e){return e[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped",e})({});const M1={clock:{setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e)},logger:console.log.bind(console),devTools:!1};class L1{constructor(t,n){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new Bh(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=bn.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this.systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const r={...M1,...n},{clock:i,logger:s,parent:o,syncSnapshot:a,id:c,systemId:l,inspect:f}=r;this.system=o?o.system:j1(this,{clock:i,logger:s}),f&&!o&&this.system.inspect(za(f)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=n?.logger??this.system._logger,this.clock=n?.clock??this.system._clock,this._parent=o,this._syncSnapshot=a,this.options=r,this.src=r.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:u=>{this._deferred.push(u)},system:this.system,stopChild:u=>{if(u._parent!==this)throw new Error(`Cannot stop child actor ${u.id} of ${this.id} because it is not a child`);u._stop()},emit:u=>{const h=this.eventListeners.get(u.type),d=this.eventListeners.get("*");if(!h&&!d)return;const g=[...h?h.values():[],...d?d.values():[]];for(const p of g)try{p(u)}catch(m){gr(m)}},actionExecutor:u=>{const h=()=>{if(this._actorScope.system._sendInspectionEvent({type:"@xstate.action",actorRef:this,action:{type:u.type,params:u.params}}),!u.exec)return;const d=wl;try{wl=!0,u.exec(u.info,u.params)}finally{wl=d}};this._processingStatus===bn.Running?h():this._deferred.push(h)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),l&&(this.systemId=l,this.system._set(l,this)),this._initState(n?.snapshot??n?.state),l&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(t){try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(n){this._snapshot={status:"error",output:void 0,error:n}}}update(t,n){this._snapshot=t;let r;for(;r=this._deferred.shift();)try{r()}catch(i){this._deferred.length=0,this._snapshot={...t,status:"error",error:i}}switch(this._snapshot.status){case"active":for(const i of this.observers)try{i.next?.(t)}catch(s){gr(s)}break;case"done":for(const i of this.observers)try{i.next?.(t)}catch(s){gr(s)}this._stopProcedure(),this._complete(),this._doneEvent=D1(this.id,this._snapshot.output),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error);break}this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:n,snapshot:t})}subscribe(t,n,r){const i=za(t,n,r);if(this._processingStatus!==bn.Stopped)this.observers.add(i);else switch(this._snapshot.status){case"done":try{i.complete?.()}catch(s){gr(s)}break;case"error":{const s=this._snapshot.error;if(!i.error)gr(s);else try{i.error(s)}catch(o){gr(o)}break}}return{unsubscribe:()=>{this.observers.delete(i)}}}on(t,n){let r=this.eventListeners.get(t);r||(r=new Set,this.eventListeners.set(t,r));const i=n.bind(void 0);return r.add(i),{unsubscribe:()=>{r.delete(i)}}}select(t,n=Object.is){return{subscribe:r=>{const i=za(r),s=this.getSnapshot();let o=t(s);return this.subscribe(a=>{const c=t(a);n(o,c)||(o=c,i.next?.(c))})},get:()=>t(this.getSnapshot())}}start(){if(this._processingStatus===bn.Running)return this;this._syncSnapshot&&this.subscribe({next:r=>{r.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:r})},error:()=>{}}),this.system._register(this.sessionId,this),this.systemId&&this.system._set(this.systemId,this),this._processingStatus=bn.Running;const t=bm(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t}),this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(r){return this._snapshot={...this._snapshot,status:"error",error:r},this._error(r),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let n,r;try{n=this.logic.transition(this._snapshot,t,this._actorScope)}catch(i){r={err:i}}if(r){const{err:i}=r;this._snapshot={...this._snapshot,status:"error",error:i},this._error(i);return}this.update(n,t),t.type===Cu&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===bn.Stopped?this:(this.mailbox.clear(),this._processingStatus===bn.NotStarted?(this._processingStatus=bn.Stopped,this):(this.mailbox.enqueue({type:Cu}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(n){gr(n)}this.observers.clear(),this.eventListeners.clear()}_reportError(t){if(!this.observers.size){this._parent||gr(t),this.eventListeners.clear();return}let n=!1;for(const r of this.observers){const i=r.error;n||=!i;try{i?.(t)}catch(s){gr(s)}}this.observers.clear(),this.eventListeners.clear(),n&&gr(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,ym(this.id,t))}_stopProcedure(){return this._processingStatus!==bn.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new Bh(this._process.bind(this)),this._processingStatus=bn.Stopped,this.system._unregister(this),this)}_send(t){this._processingStatus!==bn.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;t&&(typeof t=="function"?t:I1)(this)}toJSON(){return{xstate$$type:Gd,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[R1](){return this}getSnapshot(){return this._snapshot}}function vo(e,...[t]){return new L1(e,t)}function N1(e,t,n,r,{sendId:i}){const s=typeof i=="function"?i(n,r):i;return[t,{sendId:s},void 0]}function H1(e,t){e.defer(()=>{e.system.scheduler.cancel(e.self,t.sendId)})}function Yd(e){function t(n,r){}return t.type="xstate.cancel",t.sendId=e,t.resolve=N1,t.execute=H1,t}function Z1(e,t,n,r,{id:i,systemId:s,src:o,input:a,syncSnapshot:c}){const l=typeof o=="string"?Kd(t.machine,o):o,f=typeof i=="function"?i(n):i;let u,h;return l&&(h=typeof a=="function"?a({context:t.context,event:n.event,self:e.self}):a,u=vo(l,{id:f,src:o,parent:e.self,syncSnapshot:c,systemId:s,input:h})),[Pi(t,{children:{...t.children,[f]:u}}),{id:i,systemId:s,actorRef:u,src:o,input:h},void 0]}function V1(e,{actorRef:t}){t&&e.defer(()=>{t._processingStatus!==bn.Stopped&&t.start()})}function Xd(...[e,{id:t,systemId:n,input:r,syncSnapshot:i=!1}={}]){function s(o,a){}return s.type="xstate.spawnChild",s.id=t,s.systemId=n,s.src=e,s.input=r,s.syncSnapshot=i,s.resolve=Z1,s.execute=V1,s}function W1(e,t,n,r,{actorRef:i}){const s=typeof i=="function"?i(n,r):i,o=typeof s=="string"?t.children[s]:s;let a=t.children;return o&&(a={...a},delete a[o.id]),[Pi(t,{children:a}),o,void 0]}function km(e,t){const n=t.getSnapshot();if(n&&"children"in n)for(const r of Object.values(n.children))km(e,r);e.system._unregister(t)}function q1(e,t){if(t){if(km(e,t),t._processingStatus!==bn.Running){e.stopChild(t);return}e.defer(()=>{e.stopChild(t)})}}function Uc(e){function t(n,r){}return t.type="xstate.stopChild",t.actorRef=e,t.resolve=W1,t.execute=q1,t}function J1(e,{context:t,event:n},{guards:r}){return r.every(i=>Zo(i,t,n,e))}function K1(e){function t(n,r){return!1}return t.check=J1,t.guards=e,t}function Zo(e,t,n,r){const{machine:i}=r,s=typeof e=="function",o=s?e:i.implementations.guards[typeof e=="string"?e:e.type];if(!s&&!o)throw new Error(`Guard '${typeof e=="string"?e:e.type}' is not implemented.'.`);if(typeof o!="function")return Zo(o,t,n,r);const a={context:t,event:n},c=s||typeof e=="string"?void 0:"params"in e?typeof e.params=="function"?e.params({context:t,event:n}):e.params:void 0;return"check"in o?o.check(r,a,o):o(a,c)}function Qd(e){return e.type==="atomic"||e.type==="final"}function Ss(e){return Object.values(e.states).filter(t=>t.type!=="history")}function Vo(e,t){const n=[];if(t===e)return n;let r=e.parent;for(;r&&r!==t;)n.push(r),r=r.parent;return n}function sc(e){const t=new Set(e),n=Am(t);for(const r of t)if(r.type==="compound"&&(!n.get(r)||!n.get(r).length))Nh(r).forEach(i=>t.add(i));else if(r.type==="parallel"){for(const i of Ss(r))if(i.type!=="history"&&!t.has(i)){const s=Nh(i);for(const o of s)t.add(o)}}for(const r of t){let i=r.parent;for(;i;)t.add(i),i=i.parent}return t}function Em(e,t){const n=t.get(e);if(!n)return{};if(e.type==="compound"){const i=n[0];if(i){if(Qd(i))return i.key}else return{}}const r={};for(const i of n)r[i.key]=Em(i,t);return r}function Am(e){const t=new Map;for(const n of e)t.has(n)||t.set(n,[]),n.parent&&(t.has(n.parent)||t.set(n.parent,[]),t.get(n.parent).push(n));return t}function Im(e,t){const n=sc(t);return Em(e,Am(n))}function ef(e,t){return t.type==="compound"?Ss(t).some(n=>n.type==="final"&&e.has(n)):t.type==="parallel"?Ss(t).every(n=>ef(e,n)):t.type==="final"}const jc=e=>e[0]===z1;function G1(e,t){return e.transitions.get(t)||[...e.transitions.keys()].filter(r=>$m(t,r)).sort((r,i)=>i.length-r.length).flatMap(r=>e.transitions.get(r))}function Y1(e){const t=e.config.after;if(!t)return[];const n=i=>{const s=T1(i,e.id),o=s.type;return e.entry.push(rf(s,{id:o,delay:i})),e.exit.push(Yd(o)),o};return Object.keys(t).flatMap(i=>{const s=t[i],o=typeof s=="string"?{target:s}:s,a=Number.isNaN(+i)?i:+i,c=n(a);return Ir(o).map(l=>({...l,event:c,delay:a}))}).map(i=>{const{delay:s}=i;return{...Yr(e,i.event,i),delay:s}})}function Yr(e,t,n){const r=Sm(n.target),i=n.reenter??!1,s=tv(e,r),o={...n,actions:Ir(n.actions),guard:n.guard,target:s,source:e,reenter:i,eventType:t,toJSON:()=>({...o,source:`#${e.id}`,target:s?s.map(a=>`#${a.id}`):void 0})};return o}function X1(e){const t=new Map;if(e.config.on)for(const n of Object.keys(e.config.on)){if(n===mm)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const r=e.config.on[n];t.set(n,ss(r).map(i=>Yr(e,n,i)))}if(e.config.onDone){const n=`xstate.done.state.${e.id}`;t.set(n,ss(e.config.onDone).map(r=>Yr(e,n,r)))}for(const n of e.invoke){if(n.onDone){const r=`xstate.done.actor.${n.id}`;t.set(r,ss(n.onDone).map(i=>Yr(e,r,i)))}if(n.onError){const r=`xstate.error.actor.${n.id}`;t.set(r,ss(n.onError).map(i=>Yr(e,r,i)))}if(n.onSnapshot){const r=`xstate.snapshot.${n.id}`;t.set(r,ss(n.onSnapshot).map(i=>Yr(e,r,i)))}}for(const n of e.after){let r=t.get(n.eventType);r||(r=[],t.set(n.eventType,r)),r.push(n)}return t}function Q1(e){const t=[],n=r=>{Object.values(r).forEach(i=>{if(i.config.route&&i.config.id){const s=i.config.id,o=i.config.route.guard,a=({event:l})=>l.to===`#${s}`,c={...i.config.route,guard:o?K1([a,o]):a,target:`#${s}`};t.push(Yr(e,"xstate.route",c))}i.states&&n(i.states)})};n(e.states),t.length>0&&e.transitions.set("xstate.route",t)}function ev(e,t){const n=typeof t=="string"?e.states[t]:t?e.states[t.target]:void 0;if(!n&&t)throw new Error(`Initial state node "${t}" not found on parent state node #${e.id}`);const r={source:e,actions:!t||typeof t=="string"?[]:Ir(t.actions),eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...r,source:`#${e.id}`,target:n?[`#${n.id}`]:[]})};return r}function tv(e,t){if(t!==void 0)return t.map(n=>{if(typeof n!="string")return n;if(jc(n))return e.machine.getStateNodeById(n);const r=n[0]===pm;if(r&&!e.parent)return oc(e,n.slice(1));const i=r?e.key+n:n;if(e.parent)try{return oc(e.parent,i)}catch(s){throw new Error(`Invalid transition definition for state node '${e.id}':
|
|
2
|
+
${s.message}`)}else throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`)})}function Cm(e){const t=Sm(e.config.target);return t?{target:t.map(n=>typeof n=="string"?oc(e.parent,n):n)}:e.parent.initial}function $i(e){return e.type==="history"}function Nh(e){const t=zm(e);for(const n of t)for(const r of Vo(n,e))t.add(r);return t}function zm(e){const t=new Set;function n(r){if(!t.has(r)){if(t.add(r),r.type==="compound")n(r.initial.target[0]);else if(r.type==="parallel")for(const i of Ss(r))n(i)}}return n(e),t}function $s(e,t){if(jc(t))return e.machine.getStateNodeById(t);if(!e.states)throw new Error(`Unable to retrieve child state '${t}' from '${e.id}'; no child states exist.`);const n=e.states[t];if(!n)throw new Error(`Child state '${t}' does not exist on '${e.id}'`);return n}function oc(e,t){if(typeof t=="string"&&jc(t))try{return e.machine.getStateNodeById(t)}catch{}const n=Jd(t).slice();let r=e;for(;n.length;){const i=n.shift();if(!i.length)break;r=$s(r,i)}return r}function ac(e,t){if(typeof t=="string"){const i=e.states[t];if(!i)throw new Error(`State '${t}' does not exist on '${e.id}'`);return[e,i]}const n=Object.keys(t),r=n.map(i=>$s(e,i)).filter(Boolean);return[e.machine.root,e].concat(r,n.reduce((i,s)=>{const o=$s(e,s);if(!o)return i;const a=ac(o,t[s]);return i.concat(a)},[]))}function nv(e,t,n,r){const s=$s(e,t).next(n,r);return!s||!s.length?e.next(n,r):s}function rv(e,t,n,r){const i=Object.keys(t),s=$s(e,i[0]),o=tf(s,t[i[0]],n,r);return!o||!o.length?e.next(n,r):o}function iv(e,t,n,r){const i=[];for(const s of Object.keys(t)){const o=t[s];if(!o)continue;const a=$s(e,s),c=tf(a,o,n,r);c&&i.push(...c)}return i.length?i:e.next(n,r)}function tf(e,t,n,r){return typeof t=="string"?nv(e,t,n,r):Object.keys(t).length===1?rv(e,t,n,r):iv(e,t,n,r)}function sv(e){return Object.keys(e.states).map(t=>e.states[t]).filter(t=>t.type==="history")}function ai(e,t){let n=e;for(;n.parent&&n.parent!==t;)n=n.parent;return n.parent===t}function ov(e,t){const n=new Set(e),r=new Set(t);for(const i of n)if(r.has(i))return!0;for(const i of r)if(n.has(i))return!0;return!1}function Om(e,t,n){const r=new Set;for(const i of e){let s=!1;const o=new Set;for(const a of r)if(ov(Pu([i],t,n),Pu([a],t,n)))if(ai(i.source,a.source))o.add(a);else{s=!0;break}if(!s){for(const a of o)r.delete(a);r.add(i)}}return Array.from(r)}function av(e){const[t,...n]=e;for(const r of Vo(t,void 0))if(n.every(i=>ai(i,r)))return r}function nf(e,t){if(!e.target)return[];const n=new Set;for(const r of e.target)if($i(r))if(t[r.id])for(const i of t[r.id])n.add(i);else for(const i of nf(Cm(r),t))n.add(i);else n.add(r);return[...n]}function Pm(e,t){const n=nf(e,t);if(!n)return;if(!e.reenter&&n.every(i=>i===e.source||ai(i,e.source)))return e.source;const r=av(n.concat(e.source));if(r)return r;if(!e.reenter)return e.source.machine.root}function Pu(e,t,n){const r=new Set;for(const i of e)if(i.target?.length){const s=Pm(i,n);i.reenter&&i.source===s&&r.add(s);for(const o of t)ai(o,s)&&r.add(o)}return[...r]}function cv(e,t){if(e.length!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function lv(e,t,n,r,i){return Tu([{target:[...zm(e)],source:e,reenter:!0,actions:[],eventType:null,toJSON:null}],t,n,r,!0,i)}function Tu(e,t,n,r,i,s){const o=[];if(!e.length)return[t,o];const a=n.actionExecutor;n.actionExecutor=c=>{o.push(c),a(c)};try{const c=new Set(t._nodes);let l=t.historyValue;const f=Om(e,c,l);let u=t;i||([u,l]=hv(u,r,n,f,c,l,s,n.actionExecutor)),u=ks(u,r,n,f.flatMap(d=>d.actions),s,void 0),u=dv(u,r,n,f,c,s,l,i);const h=[...c];u.status==="done"&&(u=ks(u,r,n,h.sort((d,g)=>g.order-d.order).flatMap(d=>d.exit),s,void 0));try{return l===t.historyValue&&cv(t._nodes,c)?[u,o]:[Pi(u,{_nodes:h,historyValue:l}),o]}catch(d){throw d}}finally{n.actionExecutor=a}}function uv(e,t,n,r,i){if(r.output===void 0)return;const s=zu(i.id,i.output!==void 0&&i.parent?Ou(i.output,e.context,t,n.self):void 0);return Ou(r.output,e.context,s,n.self)}function dv(e,t,n,r,i,s,o,a){let c=e;const l=new Set,f=new Set;fv(r,o,f,l),a&&f.add(e.machine.root);const u=new Set;for(const h of[...l].sort((d,g)=>d.order-g.order)){i.add(h);const d=[];d.push(...h.entry);for(const g of h.invoke)d.push(Xd(g.src,{...g,syncSnapshot:!!g.onSnapshot}));if(f.has(h)){const g=h.initial.actions;d.push(...g)}if(c=ks(c,t,n,d,s,h.invoke.map(g=>g.id)),h.type==="final"){const g=h.parent;let p=g?.type==="parallel"?g:g?.parent,m=p||h;for(g?.type==="compound"&&s.push(zu(g.id,h.output!==void 0?Ou(h.output,c.context,t,n.self):void 0));p?.type==="parallel"&&!u.has(p)&&ef(i,p);)u.add(p),s.push(zu(p.id)),m=p,p=p.parent;if(p)continue;c=Pi(c,{status:"done",output:uv(c,t,n,c.machine.root,m)})}}return c}function fv(e,t,n,r){for(const i of e){const s=Pm(i,t);for(const a of i.target||[])!$i(a)&&(i.source!==a||i.source!==s||i.reenter)&&(r.add(a),n.add(a)),as(a,t,n,r);const o=nf(i,t);for(const a of o){const c=Vo(a,s);s?.type==="parallel"&&c.push(s),Tm(r,t,n,c,!i.source.parent&&i.reenter?void 0:s)}}}function as(e,t,n,r){if($i(e))if(t[e.id]){const i=t[e.id];for(const s of i)r.add(s),as(s,t,n,r);for(const s of i)vl(s,e.parent,r,t,n)}else{const i=Cm(e);for(const s of i.target)r.add(s),i===e.parent?.initial&&n.add(e.parent),as(s,t,n,r);for(const s of i.target)vl(s,e.parent,r,t,n)}else if(e.type==="compound"){const[i]=e.initial.target;$i(i)||(r.add(i),n.add(i)),as(i,t,n,r),vl(i,e,r,t,n)}else if(e.type==="parallel")for(const i of Ss(e).filter(s=>!$i(s)))[...r].some(s=>ai(s,i))||($i(i)||(r.add(i),n.add(i)),as(i,t,n,r))}function Tm(e,t,n,r,i){for(const s of r)if((!i||ai(s,i))&&e.add(s),s.type==="parallel")for(const o of Ss(s).filter(a=>!$i(a)))[...e].some(a=>ai(a,o))||(e.add(o),as(o,t,n,e))}function vl(e,t,n,r,i){Tm(n,r,i,Vo(e,t))}function hv(e,t,n,r,i,s,o,a){let c=e;const l=Pu(r,i,s);l.sort((u,h)=>h.order-u.order);let f;for(const u of l)for(const h of sv(u)){let d;h.history==="deep"?d=g=>Qd(g)&&ai(g,u):d=g=>g.parent===u,f??={...s},f[h.id]=Array.from(i).filter(d)}for(const u of l)c=ks(c,t,n,[...u.exit,...u.invoke.map(h=>Uc(h.id))],o,void 0),i.delete(u);return[c,f||s]}function gv(e,t){return e.implementations.actions[t]}function Dm(e,t,n,r,i,s){const{machine:o}=e;let a=e;for(const c of r){const l=typeof c=="function",f=l?c:gv(o,typeof c=="string"?c:c.type),u={context:a.context,event:t,self:n.self,system:n.system},h=l||typeof c=="string"?void 0:"params"in c?typeof c.params=="function"?c.params({context:a.context,event:t}):c.params:void 0;if(!f||!("resolve"in f)){n.actionExecutor({type:typeof c=="string"?c:typeof c=="object"?c.type:c.name||"(anonymous)",info:u,params:h,exec:f});continue}const d=f,[g,p,m]=d.resolve(n,a,u,h,f,i);a=g,"retryResolve"in d&&s?.push([d,p]),"execute"in d&&n.actionExecutor({type:d.type,info:u,params:p,exec:d.execute.bind(null,n,p)}),m&&(a=Dm(a,t,n,m,i,s))}return a}function ks(e,t,n,r,i,s){const o=s?[]:void 0,a=Dm(e,t,n,r,{internalQueue:i,deferredActorIds:s},o);return o?.forEach(([c,l])=>{c.retryResolve(n,a,l)}),a}function xl(e,t,n,r){let i=e;const s=[];function o(u,h,d){n.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:n.self,event:h,snapshot:u[0],_transitions:d}),s.push(u)}if(t.type===Cu)return i=Pi(Hh(i,t,n),{status:"stopped"}),o([i,[]],t,[]),{snapshot:i,microsteps:s};let a=t;if(a.type!==_m){const u=a,h=B1(u),d=Zh(u,i);if(h&&!d.length)return i=Pi(e,{status:"error",error:u.error}),o([i,[]],u,[]),{snapshot:i,microsteps:s};const g=Tu(d,e,n,a,!1,r);i=g[0],o(g,u,d)}let c=!0;const l=e.machine.options?.maxIterations??1/0;let f=0;for(;i.status==="active";){if(f++,f>l)throw new Error(`Infinite loop detected: the machine has processed more than ${l} microsteps without reaching a stable state. This usually happens when there's a cycle of transitions (e.g., eventless transitions or raised events causing state A -> B -> C -> A).`);let u=c?pv(i,a):[];const h=u.length?i:void 0;if(!u.length){if(!r.length)break;a=r.shift(),u=Zh(a,i)}const d=Tu(u,i,n,a,!1,r);i=d[0],c=i!==h,o(d,a,u)}return i.status!=="active"&&Hh(i,a,n),{snapshot:i,microsteps:s}}function Hh(e,t,n){return ks(e,t,n,Object.values(e.children).map(r=>Uc(r)),[],void 0)}function Zh(e,t){return t.machine.getTransitionData(t,e)}function pv(e,t){const n=new Set,r=e._nodes.filter(Qd);for(const i of r)e:for(const s of[i].concat(Vo(i,void 0)))if(s.always){for(const o of s.always)if(o.guard===void 0||Zo(o.guard,e.context,t,e)){n.add(o);break e}}return Om(Array.from(n),new Set(e._nodes),e.historyValue)}function mv(e,t){const n=sc(ac(e,t));return Im(e,[...n])}function _v(e){return!!e&&typeof e=="object"&&"machine"in e&&"value"in e}const yv=function(t){return wm(t,this.value)},bv=function(t){return this.tags.has(t)},wv=function(t){const n=this.machine.getTransitionData(this,t);return!!n?.length&&n.some(r=>r.target!==void 0||r.actions.length)},vv=function(){const{_nodes:t,tags:n,machine:r,getMeta:i,toJSON:s,can:o,hasTag:a,matches:c,...l}=this;return{...l,tags:Array.from(n)}},xv=function(){return this._nodes.reduce((t,n)=>(n.meta!==void 0&&(t[n.id]=n.meta),t),{})};function Oa(e,t){return{status:e.status,output:e.output,error:e.error,machine:t,context:e.context,_nodes:e._nodes,value:Im(t.root,e._nodes),tags:new Set(e._nodes.flatMap(n=>n.tags)),children:e.children,historyValue:e.historyValue||{},matches:yv,hasTag:bv,can:wv,getMeta:xv,toJSON:vv}}function Pi(e,t={}){return Oa({...e,...t},e.machine)}function Sv(e){if(typeof e!="object"||e===null)return{};const t={};for(const n in e){const r=e[n];Array.isArray(r)&&(t[n]=r.map(i=>({id:i.id})))}return t}function $v(e,t){const{_nodes:n,tags:r,machine:i,children:s,context:o,can:a,hasTag:c,matches:l,getMeta:f,toJSON:u,...h}=e,d={};for(const p in s){const m=s[p];d[p]={snapshot:m.getPersistedSnapshot(t),src:m.src,systemId:m.systemId,syncSnapshot:m._syncSnapshot}}return{...h,context:Rm(o),children:d,historyValue:Sv(h.historyValue)}}function Rm(e){let t;for(const n in e){const r=e[n];if(r&&typeof r=="object")if("sessionId"in r&&"send"in r&&"ref"in r)t??=Array.isArray(e)?e.slice():{...e},t[n]={xstate$$type:Gd,id:r.id};else{const i=Rm(r);i!==r&&(t??=Array.isArray(e)?e.slice():{...e},t[n]=i)}}return t??e}function kv(e,t,n,r,{event:i,id:s,delay:o},{internalQueue:a}){const c=t.machine.implementations.delays;if(typeof i=="string")throw new Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);const l=typeof i=="function"?i(n,r):i;let f;if(typeof o=="string"){const u=c&&c[o];f=typeof u=="function"?u(n,r):u}else f=typeof o=="function"?o(n,r):o;return typeof f!="number"&&a.push(l),[t,{event:l,id:s,delay:f},void 0]}function Ev(e,t){const{event:n,delay:r,id:i}=t;if(typeof r=="number"){e.defer(()=>{const s=e.self;e.system.scheduler.schedule(s,s,n,r,i)});return}}function rf(e,t){function n(r,i){}return n.type="xstate.raise",n.event=e,n.id=t?.id,n.delay=t?.delay,n.resolve=kv,n.execute=Ev,n}function Av(e,{machine:t,context:n},r,i){const s=(o,a)=>{if(typeof o=="string"){const c=Kd(t,o);if(!c)throw new Error(`Actor logic '${o}' not implemented in machine '${t.id}'`);const l=vo(c,{id:a?.id,parent:e.self,syncSnapshot:a?.syncSnapshot,input:typeof a?.input=="function"?a.input({context:n,event:r,self:e.self}):a?.input,src:o,systemId:a?.systemId});return i[l.id]=l,l}else return vo(o,{id:a?.id,parent:e.self,syncSnapshot:a?.syncSnapshot,input:a?.input,src:o,systemId:a?.systemId})};return(o,a)=>{const c=s(o,a);return i[c.id]=c,e.defer(()=>{c._processingStatus!==bn.Stopped&&c.start()}),c}}function Iv(e,t,n,r,{assignment:i}){if(!t.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const s={},o={context:t.context,event:n.event,spawn:Av(e,t,n.event,s),self:e.self,system:e.system};let a={};if(typeof i=="function")a=i(o,r);else for(const l of Object.keys(i)){const f=i[l];a[l]=typeof f=="function"?f(o,r):f}const c=Object.assign({},t.context,a);return[Pi(t,{context:c,children:Object.keys(s).length?{...t.children,...s}:t.children}),void 0,void 0]}function ki(e){function t(n,r){}return t.type="xstate.assign",t.assignment=e,t.resolve=Iv,t}const Vh=new WeakMap;function Xi(e,t,n){let r=Vh.get(e);return r?t in r||(r[t]=n()):(r={[t]:n()},Vh.set(e,r)),r[t]}const Cv={},Ws=e=>typeof e=="string"?{type:e}:typeof e=="function"?"resolve"in e?{type:e.type}:{type:e.name}:e;class cc{constructor(t,n){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(pm),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?jh(this.config.states,(r,i)=>new cc(r,{_parent:this,_key:i,_machine:this.machine})):Cv,this.type==="compound"&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=this.config.history===!0?"shallow":this.config.history||!1,this.entry=Ir(this.config.entry).slice(),this.exit=Ir(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=Ir(t.tags).slice()}_initialize(){this.transitions=X1(this),this.config.always&&(this.always=ss(this.config.always).map(t=>Yr(this,mm,t))),Object.keys(this.states).forEach(t=>{this.states[t]._initialize()})}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(Ws),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(t=>`#${t.id}`),source:`#${this.id}`,actions:this.initial.actions.map(Ws),eventType:null})}:void 0,history:this.history,states:jh(this.states,t=>t.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(t=>({...t,actions:t.actions.map(Ws)})),entry:this.entry.map(Ws),exit:this.exit.map(Ws),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return Xi(this,"invoke",()=>Ir(this.config.invoke).map((t,n)=>{const{src:r,systemId:i}=t,s=t.id??Mh(this.id,n),o=typeof r=="string"?r:`xstate.invoke.${Mh(this.id,n)}`;return{...t,src:o,id:s,systemId:i,toJSON(){const{onDone:a,onError:c,...l}=t;return{...l,type:"xstate.invoke",src:o,id:s}}}}))}get on(){return Xi(this,"on",()=>[...this.transitions].flatMap(([n,r])=>r.map(i=>[n,i])).reduce((n,[r,i])=>(n[r]=n[r]||[],n[r].push(i),n),{}))}get after(){return Xi(this,"delayedTransitions",()=>Y1(this))}get initial(){return Xi(this,"initial",()=>ev(this,this.config.initial))}next(t,n){const r=n.type,i=[];let s;const o=Xi(this,`candidates-${r}`,()=>G1(this,r));for(const a of o){const{guard:c}=a,l=t.context;let f=!1;try{f=!c||Zo(c,l,n,t)}catch(u){const h=typeof c=="string"?c:typeof c=="object"?c.type:void 0;throw new Error(`Unable to evaluate guard ${h?`'${h}' `:""}in transition for event '${r}' in state node '${this.id}':
|
|
3
|
+
${u.message}`)}if(f){i.push(...a.actions),s=a;break}}return s?[s]:void 0}get events(){return Xi(this,"events",()=>{const{states:t}=this,n=new Set(this.ownEvents);if(t)for(const r of Object.keys(t)){const i=t[r];if(i.states)for(const s of i.events)n.add(`${s}`)}return Array.from(n)})}get ownEvents(){const t=Object.keys(Object.fromEntries(this.transitions)),n=new Set(t.filter(r=>this.transitions.get(r).some(i=>!(!i.target&&!i.actions.length&&!i.reenter))));return Array.from(n)}}const zv="#";class sf{constructor(t,n){this.config=t,this.version=void 0,this.schemas=void 0,this.implementations=void 0,this.options=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.id=t.id||"(machine)",this.implementations={actors:n?.actors??{},actions:n?.actions??{},delays:n?.delays??{},guards:n?.guards??{}},this.version=this.config.version,this.schemas=this.config.schemas,this.options={maxIterations:1/0,...this.config.options},this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new cc(t,{_key:this.id,_machine:this}),this.root._initialize(),Q1(this.root),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:n,guards:r,actors:i,delays:s}=this.implementations;return new sf(this.config,{actions:{...n,...t.actions},guards:{...r,...t.guards},actors:{...i,...t.actors},delays:{...s,...t.delays}})}resolveState(t){const n=mv(this.root,t.value),r=sc(ac(this.root,n));return Oa({_nodes:[...r],context:t.context||{},children:{},status:ef(r,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,n,r){return xl(t,n,r,[]).snapshot}microstep(t,n,r){return xl(t,n,r,[]).microsteps.map(([i])=>i)}getTransitionData(t,n){return tf(this.root,t.value,t,n)||[]}_getPreInitialState(t,n,r){const{context:i}=this.config,s=Oa({context:typeof i!="function"&&i?i:{},_nodes:[this.root],children:{},status:"active"},this);return typeof i=="function"?ks(s,n,t,[ki(({spawn:a,event:c,self:l})=>i({spawn:a,input:c.input,self:l}))],r,void 0):s}getInitialSnapshot(t,n){const r=bm(n),i=[],s=this._getPreInitialState(t,r,i),[o]=lv(this.root,s,t,r,i),{snapshot:a}=xl(o,r,t,i);return a}start(t){Object.values(t.children).forEach(n=>{n.getSnapshot().status==="active"&&n.start()})}getStateNodeById(t){const n=Jd(t),r=n.slice(1),i=jc(n[0])?n[0].slice(zv.length):n[0],s=this.idMap.get(i);if(!s)throw new Error(`Child state node '#${i}' does not exist on machine '${this.id}'`);return oc(s,r)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,n){return $v(t,n)}restoreSnapshot(t,n){const r={},i=t.children;Object.keys(i).forEach(u=>{const h=i[u],d=h.snapshot,g=h.src,p=typeof g=="string"?Kd(this,g):g;if(!p)return;const m=vo(p,{id:u,parent:n.self,syncSnapshot:h.syncSnapshot,snapshot:d,src:g,systemId:h.systemId});r[u]=m});function s(u,h){if(h instanceof cc)return h;try{return u.machine.getStateNodeById(h.id)}catch{}}function o(u,h){if(!h||typeof h!="object")return{};const d={};for(const g in h){const p=h[g];for(const m of p){const b=s(u,m);b&&(d[g]??=[],d[g].push(b))}}return d}const a=o(this.root,t.historyValue),c=Oa({...t,children:r,_nodes:Array.from(sc(ac(this.root,t.value))),historyValue:a},this),l=new Set;function f(u,h){if(!l.has(u)){l.add(u);for(const d in u){const g=u[d];if(g&&typeof g=="object"){if("xstate$$type"in g&&g.xstate$$type===Gd){u[d]=h[g.id];continue}f(g,h)}}}}return f(c.context,r),c}}function Ov(e,t,n,r,{event:i}){const s=typeof i=="function"?i(n,r):i;return[t,{event:s},void 0]}function Pv(e,{event:t}){e.defer(()=>e.emit(t))}function Fm(e){function t(n,r){}return t.type="xstate.emit",t.event=e,t.resolve=Ov,t.execute=Pv,t}let Du=(function(e){return e.Parent="#_parent",e.Internal="#_internal",e})({});function Tv(e,t,n,r,{to:i,event:s,id:o,delay:a},c){const l=t.machine.implementations.delays;if(typeof s=="string")throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${s}" }) instead`);const f=typeof s=="function"?s(n,r):s;let u;if(typeof a=="string"){const g=l&&l[a];u=typeof g=="function"?g(n,r):g}else u=typeof a=="function"?a(n,r):a;const h=typeof i=="function"?i(n,r):i;let d;if(typeof h=="string"){if(h===Du.Parent?d=e.self._parent:h===Du.Internal?d=e.self:h.startsWith("#_")?d=t.children[h.slice(2)]:d=c.deferredActorIds?.includes(h)?h:t.children[h],!d)throw new Error(`Unable to send event to actor '${h}' from machine '${t.machine.id}'.`)}else d=h||e.self;return[t,{to:d,targetId:typeof h=="string"?h:void 0,event:f,id:o,delay:u},void 0]}function Dv(e,t,n){typeof n.to=="string"&&(n.to=t.children[n.to])}function Rv(e,t){e.defer(()=>{const{to:n,event:r,delay:i,id:s}=t;if(typeof i=="number"){e.system.scheduler.schedule(e.self,n,r,i,s);return}e.system._relay(e.self,n,r.type===P1?ym(e.self.id,r.data):r)})}function of(e,t,n){function r(i,s){}return r.type="xstate.sendTo",r.to=e,r.event=t,r.id=n?.id,r.delay=n?.delay,r.resolve=Tv,r.retryResolve=Dv,r.execute=Rv,r}function Fv(e,t){return of(Du.Parent,e,t)}function Bv(e,t,n,r,{collect:i}){const s=[],o=function(c){s.push(c)};return o.assign=(...a)=>{s.push(ki(...a))},o.cancel=(...a)=>{s.push(Yd(...a))},o.raise=(...a)=>{s.push(rf(...a))},o.sendTo=(...a)=>{s.push(of(...a))},o.sendParent=(...a)=>{s.push(Fv(...a))},o.spawnChild=(...a)=>{s.push(Xd(...a))},o.stopChild=(...a)=>{s.push(Uc(...a))},o.emit=(...a)=>{s.push(Fm(...a))},i({context:n.context,event:n.event,enqueue:o,check:a=>Zo(a,t.context,n.event,t),self:e.self,system:e.system},r),[t,void 0,s]}function Uv(e){function t(n,r){}return t.type="xstate.enqueueActions",t.collect=e,t.resolve=Bv,t}function jv(e,t,n,r,{value:i,label:s}){return[t,{value:typeof i=="function"?i(n,r):i,label:s},void 0]}function Mv({logger:e},{value:t,label:n}){n?e(n,t):e(t)}function Lv(e=({context:n,event:r})=>({context:n,event:r}),t){function n(r,i){}return n.type="xstate.log",n.value=e,n.label=t,n.resolve=jv,n.execute=Mv,n}function Nv(e,t){const n=Ir(t);if(!n.some(i=>$m(e.type,i))){const i=n.length===1?`type matching "${n[0]}"`:`one of types matching "${n.join('", "')}"`;throw new Error(`Expected event ${JSON.stringify(e)} to have ${i}`)}}function Hv(e,t){return new sf(e,t)}function Bm({schemas:e,actors:t,actions:n,guards:r,delays:i}){return{assign:ki,sendTo:of,raise:rf,log:Lv,cancel:Yd,stopChild:Uc,enqueueActions:Uv,emit:Fm,spawnChild:Xd,createStateConfig:s=>s,createAction:s=>s,createMachine:s=>Hv({...s,schemas:e},{actors:t,actions:n,guards:r,delays:i}),extend:s=>Bm({schemas:e,actors:t,actions:{...n,...s.actions},guards:{...r,...s.guards},delays:{...i,...s.delays}})}}const Zv={timeout:1/0};function Vv(e,t,n){const r={...Zv,...n};return new Promise((i,s)=>{const{signal:o}=r;if(o?.aborted){s(o.reason);return}let a=!1;const c=r.timeout===1/0?void 0:setTimeout(()=>{l(),s(new Error(`Timeout of ${r.timeout} ms exceeded`))},r.timeout),l=()=>{clearTimeout(c),a=!0,h?.unsubscribe(),u&&o.removeEventListener("abort",u)};function f(d){t(d)&&(l(),i(d))}let u,h;f(e.getSnapshot()),!a&&(o&&(u=()=>{l(),s(o.reason)},o.addEventListener("abort",u)),h=e.subscribe({next:f,error:d=>{l(),s(d)},complete:()=>{l(),s(new Error("Actor terminated without satisfying predicate"))}}),a&&h.unsubscribe())})}let ia;const Wv=new Uint8Array(16);function qv(){if(!ia&&(ia=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ia))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ia(Wv)}const Jv=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Um(e){return typeof e=="string"&&Jv.test(e)}const tn=[];for(let e=0;e<256;++e)tn.push((e+256).toString(16).slice(1));function Kv(e,t=0){return tn[e[t+0]]+tn[e[t+1]]+tn[e[t+2]]+tn[e[t+3]]+"-"+tn[e[t+4]]+tn[e[t+5]]+"-"+tn[e[t+6]]+tn[e[t+7]]+"-"+tn[e[t+8]]+tn[e[t+9]]+"-"+tn[e[t+10]]+tn[e[t+11]]+tn[e[t+12]]+tn[e[t+13]]+tn[e[t+14]]+tn[e[t+15]]}function Gv(e){if(!Um(e))throw TypeError("Invalid UUID");let t;const n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=t&255,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=t&255,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=t&255,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=t&255,n[10]=(t=parseInt(e.slice(24,36),16))/0x10000000000&255,n[11]=t/0x100000000&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=t&255,n}const Yv=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Wh={randomUUID:Yv};function jm(e,t,n){if(Wh.randomUUID&&!t&&!e)return Wh.randomUUID();e=e||{};const r=e.random||(e.rng||qv)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){n=n||0;for(let i=0;i<16;++i)t[n+i]=r[i];return t}return Kv(r)}var Yn={},pt={},an={},Sl={},qs={},qh;function Xv(){return qh||(qh=1,Object.defineProperty(qs,"__esModule",{value:!0}),qs.crypto=void 0,qs.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0),qs}var Jh;function Mm(){return Jh||(Jh=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.wrapXOFConstructorWithOpts=e.wrapConstructorWithOpts=e.wrapConstructor=e.Hash=e.nextTick=e.swap32IfBE=e.byteSwapIfBE=e.swap8IfBE=e.isLE=void 0,e.isBytes=n,e.anumber=r,e.abytes=i,e.ahash=s,e.aexists=o,e.aoutput=a,e.u8=c,e.u32=l,e.clean=f,e.createView=u,e.rotr=h,e.rotl=d,e.byteSwap=g,e.byteSwap32=p,e.bytesToHex=x,e.hexToBytes=k,e.asyncLoop=T,e.utf8ToBytes=j,e.bytesToUtf8=I,e.toBytes=R,e.kdfInputToBytes=N,e.concatBytes=D,e.checkOpts=y,e.createHasher=$,e.createOptHasher=P,e.createXOFer=A,e.randomBytes=J;const t=Xv();function n(S){return S instanceof Uint8Array||ArrayBuffer.isView(S)&&S.constructor.name==="Uint8Array"}function r(S){if(!Number.isSafeInteger(S)||S<0)throw new Error("positive integer expected, got "+S)}function i(S,...U){if(!n(S))throw new Error("Uint8Array expected");if(U.length>0&&!U.includes(S.length))throw new Error("Uint8Array expected of length "+U+", got length="+S.length)}function s(S){if(typeof S!="function"||typeof S.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");r(S.outputLen),r(S.blockLen)}function o(S,U=!0){if(S.destroyed)throw new Error("Hash instance has been destroyed");if(U&&S.finished)throw new Error("Hash#digest() has already been called")}function a(S,U){i(S);const O=U.outputLen;if(S.length<O)throw new Error("digestInto() expects output buffer of length at least "+O)}function c(S){return new Uint8Array(S.buffer,S.byteOffset,S.byteLength)}function l(S){return new Uint32Array(S.buffer,S.byteOffset,Math.floor(S.byteLength/4))}function f(...S){for(let U=0;U<S.length;U++)S[U].fill(0)}function u(S){return new DataView(S.buffer,S.byteOffset,S.byteLength)}function h(S,U){return S<<32-U|S>>>U}function d(S,U){return S<<U|S>>>32-U>>>0}e.isLE=new Uint8Array(new Uint32Array([0x11223344]).buffer)[0]===68;function g(S){return S<<24&0xff000000|S<<8&0xff0000|S>>>8&65280|S>>>24&255}e.swap8IfBE=e.isLE?S=>S:S=>g(S),e.byteSwapIfBE=e.swap8IfBE;function p(S){for(let U=0;U<S.length;U++)S[U]=g(S[U]);return S}e.swap32IfBE=e.isLE?S=>S:p;const m=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",b=Array.from({length:256},(S,U)=>U.toString(16).padStart(2,"0"));function x(S){if(i(S),m)return S.toHex();let U="";for(let O=0;O<S.length;O++)U+=b[S[O]];return U}const _={_0:48,_9:57,A:65,F:70,a:97,f:102};function E(S){if(S>=_._0&&S<=_._9)return S-_._0;if(S>=_.A&&S<=_.F)return S-(_.A-10);if(S>=_.a&&S<=_.f)return S-(_.a-10)}function k(S){if(typeof S!="string")throw new Error("hex string expected, got "+typeof S);if(m)return Uint8Array.fromHex(S);const U=S.length,O=U/2;if(U%2)throw new Error("hex string expected, got unpadded hex of length "+U);const F=new Uint8Array(O);for(let X=0,ie=0;X<O;X++,ie+=2){const se=E(S.charCodeAt(ie)),$e=E(S.charCodeAt(ie+1));if(se===void 0||$e===void 0){const Ce=S[ie]+S[ie+1];throw new Error('hex string expected, got non-hex character "'+Ce+'" at index '+ie)}F[X]=se*16+$e}return F}const C=async()=>{};e.nextTick=C;async function T(S,U,O){let F=Date.now();for(let X=0;X<S;X++){O(X);const ie=Date.now()-F;ie>=0&&ie<U||(await (0,e.nextTick)(),F+=ie)}}function j(S){if(typeof S!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(S))}function I(S){return new TextDecoder().decode(S)}function R(S){return typeof S=="string"&&(S=j(S)),i(S),S}function N(S){return typeof S=="string"&&(S=j(S)),i(S),S}function D(...S){let U=0;for(let F=0;F<S.length;F++){const X=S[F];i(X),U+=X.length}const O=new Uint8Array(U);for(let F=0,X=0;F<S.length;F++){const ie=S[F];O.set(ie,X),X+=ie.length}return O}function y(S,U){if(U!==void 0&&{}.toString.call(U)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(S,U)}class w{}e.Hash=w;function $(S){const U=F=>S().update(R(F)).digest(),O=S();return U.outputLen=O.outputLen,U.blockLen=O.blockLen,U.create=()=>S(),U}function P(S){const U=(F,X)=>S(X).update(R(F)).digest(),O=S({});return U.outputLen=O.outputLen,U.blockLen=O.blockLen,U.create=F=>S(F),U}function A(S){const U=(F,X)=>S(X).update(R(F)).digest(),O=S({});return U.outputLen=O.outputLen,U.blockLen=O.blockLen,U.create=F=>S(F),U}e.wrapConstructor=$,e.wrapConstructorWithOpts=P,e.wrapXOFConstructorWithOpts=A;function J(S=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(S));if(t.crypto&&typeof t.crypto.randomBytes=="function")return Uint8Array.from(t.crypto.randomBytes(S));throw new Error("crypto.getRandomValues must be defined")}})(Sl)),Sl}var Kh;function Qv(){if(Kh)return an;Kh=1,Object.defineProperty(an,"__esModule",{value:!0}),an.SHA512_IV=an.SHA384_IV=an.SHA224_IV=an.SHA256_IV=an.HashMD=void 0,an.setBigUint64=t,an.Chi=n,an.Maj=r;const e=Mm();function t(s,o,a,c){if(typeof s.setBigUint64=="function")return s.setBigUint64(o,a,c);const l=BigInt(32),f=BigInt(0xffffffff),u=Number(a>>l&f),h=Number(a&f),d=c?4:0,g=c?0:4;s.setUint32(o+d,u,c),s.setUint32(o+g,h,c)}function n(s,o,a){return s&o^~s&a}function r(s,o,a){return s&o^s&a^o&a}class i extends e.Hash{constructor(o,a,c,l){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=o,this.outputLen=a,this.padOffset=c,this.isLE=l,this.buffer=new Uint8Array(o),this.view=(0,e.createView)(this.buffer)}update(o){(0,e.aexists)(this),o=(0,e.toBytes)(o),(0,e.abytes)(o);const{view:a,buffer:c,blockLen:l}=this,f=o.length;for(let u=0;u<f;){const h=Math.min(l-this.pos,f-u);if(h===l){const d=(0,e.createView)(o);for(;l<=f-u;u+=l)this.process(d,u);continue}c.set(o.subarray(u,u+h),this.pos),this.pos+=h,u+=h,this.pos===l&&(this.process(a,0),this.pos=0)}return this.length+=o.length,this.roundClean(),this}digestInto(o){(0,e.aexists)(this),(0,e.aoutput)(o,this),this.finished=!0;const{buffer:a,view:c,blockLen:l,isLE:f}=this;let{pos:u}=this;a[u++]=128,(0,e.clean)(this.buffer.subarray(u)),this.padOffset>l-u&&(this.process(c,0),u=0);for(let m=u;m<l;m++)a[m]=0;t(c,l-8,BigInt(this.length*8),f),this.process(c,0);const h=(0,e.createView)(o),d=this.outputLen;if(d%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const g=d/4,p=this.get();if(g>p.length)throw new Error("_sha2: outputLen bigger than state");for(let m=0;m<g;m++)h.setUint32(4*m,p[m],f)}digest(){const{buffer:o,outputLen:a}=this;this.digestInto(o);const c=o.slice(0,a);return this.destroy(),c}_cloneInto(o){o||(o=new this.constructor),o.set(...this.get());const{blockLen:a,buffer:c,length:l,finished:f,destroyed:u,pos:h}=this;return o.destroyed=u,o.finished=f,o.length=l,o.pos=h,l%a&&o.buffer.set(c),o}clone(){return this._cloneInto()}}return an.HashMD=i,an.SHA256_IV=Uint32Array.from([0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19]),an.SHA224_IV=Uint32Array.from([0xc1059ed8,0x367cd507,0x3070dd17,0xf70e5939,0xffc00b31,0x68581511,0x64f98fa7,0xbefa4fa4]),an.SHA384_IV=Uint32Array.from([0xcbbb9d5d,0xc1059ed8,0x629a292a,0x367cd507,0x9159015a,0x3070dd17,0x152fecd8,0xf70e5939,0x67332667,0xffc00b31,0x8eb44a87,0x68581511,0xdb0c2e0d,0x64f98fa7,0x47b5481d,0xbefa4fa4]),an.SHA512_IV=Uint32Array.from([0x6a09e667,0xf3bcc908,0xbb67ae85,0x84caa73b,0x3c6ef372,0xfe94f82b,0xa54ff53a,0x5f1d36f1,0x510e527f,0xade682d1,0x9b05688c,0x2b3e6c1f,0x1f83d9ab,0xfb41bd6b,0x5be0cd19,0x137e2179]),an}var Je={},Gh;function e2(){if(Gh)return Je;Gh=1,Object.defineProperty(Je,"__esModule",{value:!0}),Je.toBig=Je.shrSL=Je.shrSH=Je.rotrSL=Je.rotrSH=Je.rotrBL=Je.rotrBH=Je.rotr32L=Je.rotr32H=Je.rotlSL=Je.rotlSH=Je.rotlBL=Je.rotlBH=Je.add5L=Je.add5H=Je.add4L=Je.add4H=Je.add3L=Je.add3H=void 0,Je.add=b,Je.fromBig=n,Je.split=r;const e=BigInt(2**32-1),t=BigInt(32);function n(I,R=!1){return R?{h:Number(I&e),l:Number(I>>t&e)}:{h:Number(I>>t&e)|0,l:Number(I&e)|0}}function r(I,R=!1){const N=I.length;let D=new Uint32Array(N),y=new Uint32Array(N);for(let w=0;w<N;w++){const{h:$,l:P}=n(I[w],R);[D[w],y[w]]=[$,P]}return[D,y]}const i=(I,R)=>BigInt(I>>>0)<<t|BigInt(R>>>0);Je.toBig=i;const s=(I,R,N)=>I>>>N;Je.shrSH=s;const o=(I,R,N)=>I<<32-N|R>>>N;Je.shrSL=o;const a=(I,R,N)=>I>>>N|R<<32-N;Je.rotrSH=a;const c=(I,R,N)=>I<<32-N|R>>>N;Je.rotrSL=c;const l=(I,R,N)=>I<<64-N|R>>>N-32;Je.rotrBH=l;const f=(I,R,N)=>I>>>N-32|R<<64-N;Je.rotrBL=f;const u=(I,R)=>R;Je.rotr32H=u;const h=(I,R)=>I;Je.rotr32L=h;const d=(I,R,N)=>I<<N|R>>>32-N;Je.rotlSH=d;const g=(I,R,N)=>R<<N|I>>>32-N;Je.rotlSL=g;const p=(I,R,N)=>R<<N-32|I>>>64-N;Je.rotlBH=p;const m=(I,R,N)=>I<<N-32|R>>>64-N;Je.rotlBL=m;function b(I,R,N,D){const y=(R>>>0)+(D>>>0);return{h:I+N+(y/2**32|0)|0,l:y|0}}const x=(I,R,N)=>(I>>>0)+(R>>>0)+(N>>>0);Je.add3L=x;const _=(I,R,N,D)=>R+N+D+(I/2**32|0)|0;Je.add3H=_;const E=(I,R,N,D)=>(I>>>0)+(R>>>0)+(N>>>0)+(D>>>0);Je.add4L=E;const k=(I,R,N,D,y)=>R+N+D+y+(I/2**32|0)|0;Je.add4H=k;const C=(I,R,N,D,y)=>(I>>>0)+(R>>>0)+(N>>>0)+(D>>>0)+(y>>>0);Je.add5L=C;const T=(I,R,N,D,y,w)=>R+N+D+y+w+(I/2**32|0)|0;Je.add5H=T;const j={fromBig:n,split:r,toBig:i,shrSH:s,shrSL:o,rotrSH:a,rotrSL:c,rotrBH:l,rotrBL:f,rotr32H:u,rotr32L:h,rotlSH:d,rotlSL:g,rotlBH:p,rotlBL:m,add:b,add3L:x,add3H:_,add4L:E,add4H:k,add5H:T,add5L:C};return Je.default=j,Je}var Yh;function t2(){if(Yh)return pt;Yh=1,Object.defineProperty(pt,"__esModule",{value:!0}),pt.sha512_224=pt.sha512_256=pt.sha384=pt.sha512=pt.sha224=pt.sha256=pt.SHA512_256=pt.SHA512_224=pt.SHA384=pt.SHA512=pt.SHA224=pt.SHA256=void 0;const e=Qv(),t=e2(),n=Mm(),r=Uint32Array.from([0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0xfc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x6ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2]),i=new Uint32Array(64);class s extends e.HashMD{constructor(_=32){super(64,_,8,!1),this.A=e.SHA256_IV[0]|0,this.B=e.SHA256_IV[1]|0,this.C=e.SHA256_IV[2]|0,this.D=e.SHA256_IV[3]|0,this.E=e.SHA256_IV[4]|0,this.F=e.SHA256_IV[5]|0,this.G=e.SHA256_IV[6]|0,this.H=e.SHA256_IV[7]|0}get(){const{A:_,B:E,C:k,D:C,E:T,F:j,G:I,H:R}=this;return[_,E,k,C,T,j,I,R]}set(_,E,k,C,T,j,I,R){this.A=_|0,this.B=E|0,this.C=k|0,this.D=C|0,this.E=T|0,this.F=j|0,this.G=I|0,this.H=R|0}process(_,E){for(let y=0;y<16;y++,E+=4)i[y]=_.getUint32(E,!1);for(let y=16;y<64;y++){const w=i[y-15],$=i[y-2],P=(0,n.rotr)(w,7)^(0,n.rotr)(w,18)^w>>>3,A=(0,n.rotr)($,17)^(0,n.rotr)($,19)^$>>>10;i[y]=A+i[y-7]+P+i[y-16]|0}let{A:k,B:C,C:T,D:j,E:I,F:R,G:N,H:D}=this;for(let y=0;y<64;y++){const w=(0,n.rotr)(I,6)^(0,n.rotr)(I,11)^(0,n.rotr)(I,25),$=D+w+(0,e.Chi)(I,R,N)+r[y]+i[y]|0,A=((0,n.rotr)(k,2)^(0,n.rotr)(k,13)^(0,n.rotr)(k,22))+(0,e.Maj)(k,C,T)|0;D=N,N=R,R=I,I=j+$|0,j=T,T=C,C=k,k=$+A|0}k=k+this.A|0,C=C+this.B|0,T=T+this.C|0,j=j+this.D|0,I=I+this.E|0,R=R+this.F|0,N=N+this.G|0,D=D+this.H|0,this.set(k,C,T,j,I,R,N,D)}roundClean(){(0,n.clean)(i)}destroy(){this.set(0,0,0,0,0,0,0,0),(0,n.clean)(this.buffer)}}pt.SHA256=s;class o extends s{constructor(){super(28),this.A=e.SHA224_IV[0]|0,this.B=e.SHA224_IV[1]|0,this.C=e.SHA224_IV[2]|0,this.D=e.SHA224_IV[3]|0,this.E=e.SHA224_IV[4]|0,this.F=e.SHA224_IV[5]|0,this.G=e.SHA224_IV[6]|0,this.H=e.SHA224_IV[7]|0}}pt.SHA224=o;const a=t.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(x=>BigInt(x))),c=a[0],l=a[1],f=new Uint32Array(80),u=new Uint32Array(80);class h extends e.HashMD{constructor(_=64){super(128,_,16,!1),this.Ah=e.SHA512_IV[0]|0,this.Al=e.SHA512_IV[1]|0,this.Bh=e.SHA512_IV[2]|0,this.Bl=e.SHA512_IV[3]|0,this.Ch=e.SHA512_IV[4]|0,this.Cl=e.SHA512_IV[5]|0,this.Dh=e.SHA512_IV[6]|0,this.Dl=e.SHA512_IV[7]|0,this.Eh=e.SHA512_IV[8]|0,this.El=e.SHA512_IV[9]|0,this.Fh=e.SHA512_IV[10]|0,this.Fl=e.SHA512_IV[11]|0,this.Gh=e.SHA512_IV[12]|0,this.Gl=e.SHA512_IV[13]|0,this.Hh=e.SHA512_IV[14]|0,this.Hl=e.SHA512_IV[15]|0}get(){const{Ah:_,Al:E,Bh:k,Bl:C,Ch:T,Cl:j,Dh:I,Dl:R,Eh:N,El:D,Fh:y,Fl:w,Gh:$,Gl:P,Hh:A,Hl:J}=this;return[_,E,k,C,T,j,I,R,N,D,y,w,$,P,A,J]}set(_,E,k,C,T,j,I,R,N,D,y,w,$,P,A,J){this.Ah=_|0,this.Al=E|0,this.Bh=k|0,this.Bl=C|0,this.Ch=T|0,this.Cl=j|0,this.Dh=I|0,this.Dl=R|0,this.Eh=N|0,this.El=D|0,this.Fh=y|0,this.Fl=w|0,this.Gh=$|0,this.Gl=P|0,this.Hh=A|0,this.Hl=J|0}process(_,E){for(let O=0;O<16;O++,E+=4)f[O]=_.getUint32(E),u[O]=_.getUint32(E+=4);for(let O=16;O<80;O++){const F=f[O-15]|0,X=u[O-15]|0,ie=t.rotrSH(F,X,1)^t.rotrSH(F,X,8)^t.shrSH(F,X,7),se=t.rotrSL(F,X,1)^t.rotrSL(F,X,8)^t.shrSL(F,X,7),$e=f[O-2]|0,Ce=u[O-2]|0,Oe=t.rotrSH($e,Ce,19)^t.rotrBH($e,Ce,61)^t.shrSH($e,Ce,6),ye=t.rotrSL($e,Ce,19)^t.rotrBL($e,Ce,61)^t.shrSL($e,Ce,6),ve=t.add4L(se,ye,u[O-7],u[O-16]),me=t.add4H(ve,ie,Oe,f[O-7],f[O-16]);f[O]=me|0,u[O]=ve|0}let{Ah:k,Al:C,Bh:T,Bl:j,Ch:I,Cl:R,Dh:N,Dl:D,Eh:y,El:w,Fh:$,Fl:P,Gh:A,Gl:J,Hh:S,Hl:U}=this;for(let O=0;O<80;O++){const F=t.rotrSH(y,w,14)^t.rotrSH(y,w,18)^t.rotrBH(y,w,41),X=t.rotrSL(y,w,14)^t.rotrSL(y,w,18)^t.rotrBL(y,w,41),ie=y&$^~y&A,se=w&P^~w&J,$e=t.add5L(U,X,se,l[O],u[O]),Ce=t.add5H($e,S,F,ie,c[O],f[O]),Oe=$e|0,ye=t.rotrSH(k,C,28)^t.rotrBH(k,C,34)^t.rotrBH(k,C,39),ve=t.rotrSL(k,C,28)^t.rotrBL(k,C,34)^t.rotrBL(k,C,39),me=k&T^k&I^T&I,_e=C&j^C&R^j&R;S=A|0,U=J|0,A=$|0,J=P|0,$=y|0,P=w|0,{h:y,l:w}=t.add(N|0,D|0,Ce|0,Oe|0),N=I|0,D=R|0,I=T|0,R=j|0,T=k|0,j=C|0;const xe=t.add3L(Oe,ve,_e);k=t.add3H(xe,Ce,ye,me),C=xe|0}({h:k,l:C}=t.add(this.Ah|0,this.Al|0,k|0,C|0)),{h:T,l:j}=t.add(this.Bh|0,this.Bl|0,T|0,j|0),{h:I,l:R}=t.add(this.Ch|0,this.Cl|0,I|0,R|0),{h:N,l:D}=t.add(this.Dh|0,this.Dl|0,N|0,D|0),{h:y,l:w}=t.add(this.Eh|0,this.El|0,y|0,w|0),{h:$,l:P}=t.add(this.Fh|0,this.Fl|0,$|0,P|0),{h:A,l:J}=t.add(this.Gh|0,this.Gl|0,A|0,J|0),{h:S,l:U}=t.add(this.Hh|0,this.Hl|0,S|0,U|0),this.set(k,C,T,j,I,R,N,D,y,w,$,P,A,J,S,U)}roundClean(){(0,n.clean)(f,u)}destroy(){(0,n.clean)(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}pt.SHA512=h;class d extends h{constructor(){super(48),this.Ah=e.SHA384_IV[0]|0,this.Al=e.SHA384_IV[1]|0,this.Bh=e.SHA384_IV[2]|0,this.Bl=e.SHA384_IV[3]|0,this.Ch=e.SHA384_IV[4]|0,this.Cl=e.SHA384_IV[5]|0,this.Dh=e.SHA384_IV[6]|0,this.Dl=e.SHA384_IV[7]|0,this.Eh=e.SHA384_IV[8]|0,this.El=e.SHA384_IV[9]|0,this.Fh=e.SHA384_IV[10]|0,this.Fl=e.SHA384_IV[11]|0,this.Gh=e.SHA384_IV[12]|0,this.Gl=e.SHA384_IV[13]|0,this.Hh=e.SHA384_IV[14]|0,this.Hl=e.SHA384_IV[15]|0}}pt.SHA384=d;const g=Uint32Array.from([0x8c3d37c8,0x19544da2,0x73e19966,0x89dcd4d6,0x1dfab7ae,0x32ff9c82,0x679dd514,0x582f9fcf,0xf6d2b69,0x7bd44da8,0x77e36f73,0x4c48942,0x3f9d85a8,0x6a1d36c8,0x1112e6ad,0x91d692a1]),p=Uint32Array.from([0x22312194,0xfc2bf72c,0x9f555fa3,0xc84c64c2,0x2393b86b,0x6f53b151,0x96387719,0x5940eabd,0x96283ee2,0xa88effe3,0xbe5e1e25,0x53863992,0x2b0199fc,0x2c85b8aa,0xeb72ddc,0x81c52ca2]);class m extends h{constructor(){super(28),this.Ah=g[0]|0,this.Al=g[1]|0,this.Bh=g[2]|0,this.Bl=g[3]|0,this.Ch=g[4]|0,this.Cl=g[5]|0,this.Dh=g[6]|0,this.Dl=g[7]|0,this.Eh=g[8]|0,this.El=g[9]|0,this.Fh=g[10]|0,this.Fl=g[11]|0,this.Gh=g[12]|0,this.Gl=g[13]|0,this.Hh=g[14]|0,this.Hl=g[15]|0}}pt.SHA512_224=m;class b extends h{constructor(){super(32),this.Ah=p[0]|0,this.Al=p[1]|0,this.Bh=p[2]|0,this.Bl=p[3]|0,this.Ch=p[4]|0,this.Cl=p[5]|0,this.Dh=p[6]|0,this.Dl=p[7]|0,this.Eh=p[8]|0,this.El=p[9]|0,this.Fh=p[10]|0,this.Fl=p[11]|0,this.Gh=p[12]|0,this.Gl=p[13]|0,this.Hh=p[14]|0,this.Hl=p[15]|0}}return pt.SHA512_256=b,pt.sha256=(0,n.createHasher)(()=>new s),pt.sha224=(0,n.createHasher)(()=>new o),pt.sha512=(0,n.createHasher)(()=>new h),pt.sha384=(0,n.createHasher)(()=>new d),pt.sha512_256=(0,n.createHasher)(()=>new b),pt.sha512_224=(0,n.createHasher)(()=>new m),pt}var Xh;function n2(){if(Xh)return Yn;Xh=1,Object.defineProperty(Yn,"__esModule",{value:!0}),Yn.sha224=Yn.SHA224=Yn.sha256=Yn.SHA256=void 0;const e=t2();return Yn.SHA256=e.SHA256,Yn.sha256=e.sha256,Yn.SHA224=e.SHA224,Yn.sha224=e.sha224,Yn}var $l,Qh;function r2(){if(Qh)return $l;Qh=1;function e(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[o]=i}var a=t.length,c=t.charAt(0),l=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var p=0,m=0,b=0,x=g.length;b!==x&&g[b]===0;)b++,p++;for(var _=(x-b)*f+1>>>0,E=new Uint8Array(_);b!==x;){for(var k=g[b],C=0,T=_-1;(k!==0||C<m)&&T!==-1;T--,C++)k+=256*E[T]>>>0,E[T]=k%a>>>0,k=k/a>>>0;if(k!==0)throw new Error("Non-zero carry");m=C,b++}for(var j=_-m;j!==_&&E[j]===0;)j++;for(var I=c.repeat(p);j<_;++j)I+=t.charAt(E[j]);return I}function h(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;for(var p=0,m=0,b=0;g[p]===c;)m++,p++;for(var x=(g.length-p)*l+1>>>0,_=new Uint8Array(x);g[p];){var E=g.charCodeAt(p);if(E>255)return;var k=n[E];if(k===255)return;for(var C=0,T=x-1;(k!==0||C<b)&&T!==-1;T--,C++)k+=a*_[T]>>>0,_[T]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");b=C,p++}for(var j=x-b;j!==x&&_[j]===0;)j++;for(var I=new Uint8Array(m+(x-j)),R=m;j!==x;)I[R++]=_[j++];return I}function d(g){var p=h(g);if(p)return p;throw new Error("Non-base"+a+" character")}return{encode:u,decodeUnsafe:h,decode:d}}return $l=e,$l}var kl,eg;function i2(){return eg||(eg=1,kl=r2()("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")),kl}var El,tg;function s2(){if(tg)return El;tg=1;var e=i2();return El=function(t){function n(o){var a=Uint8Array.from(o),c=t(a),l=a.length+4,f=new Uint8Array(l);return f.set(a,0),f.set(c.subarray(0,4),a.length),e.encode(f,l)}function r(o){var a=o.slice(0,-4),c=o.slice(-4),l=t(a);if(!(c[0]^l[0]|c[1]^l[1]|c[2]^l[2]|c[3]^l[3]))return a}function i(o){var a=e.decodeUnsafe(o);if(a)return r(a)}function s(o){var a=e.decode(o),c=r(a);if(!c)throw new Error("Invalid checksum");return c}return{encode:n,decode:s,decodeUnsafe:i}},El}var Al,ng;function o2(){if(ng)return Al;ng=1;var{sha256:e}=n2(),t=s2();function n(r){return e(e(r))}return Al=t(n),Al}var a2=o2();const Mi=Ts(a2),c2=e=>{if(e.length%2!==0)throw new Error("Hex string must have an even length");const t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n>>1]=parseInt(e.slice(n,n+2),16);return t},Lm=e=>Array.from(e,t=>t.toString(16).padStart(2,"0")).join(""),lc="automerge:",nr=e=>{const[t,n,...r]=e.split("#");if(r.length>0)throw new Error("Invalid URL: contains multiple heads sections");const i=new RegExp(`^${lc}(\\w+)$`),[,s]=t.match(i)||[],o=s,a=Vm(o);if(!a)throw new Error("Invalid document URL: "+e);if(n===void 0)return{binaryDocumentId:a,documentId:o};const c=n===""?[]:n.split("|"),l=c.map(f=>{try{return Lm(Mi.decode(f))}catch{throw new Error(`Invalid head in URL: ${f}`)}});return{binaryDocumentId:a,hexHeads:l,documentId:o,heads:c}},Nm=e=>{if(e instanceof Uint8Array||typeof e=="string")return lc+(e instanceof Uint8Array?xo(e):e);const{documentId:t,heads:n=void 0}=e;if(t===void 0)throw new Error("Invalid documentId: "+t);const r=t instanceof Uint8Array?xo(t):t;let i=`${lc}${r}`;return n!==void 0&&(n.forEach(s=>{try{Mi.decode(s)}catch{throw new Error(`Invalid head: ${s}`)}}),i+="#"+n.join("|")),i},Hm=e=>{if(typeof e!="string"||!e||!e.startsWith(lc))return!1;try{const{documentId:t,heads:n}=nr(e);return!(!Zm(t)||n&&!n.every(r=>{try{return Mi.decode(r),!0}catch{return!1}}))}catch{return!1}},Zm=e=>typeof e!="string"?!1:Vm(e)!==void 0,l2=e=>typeof e=="string"&&Um(e),rg=()=>{const e=jm(null,new Uint8Array(16));return Nm({documentId:e})},Vm=e=>Mi.decodeUnsafe(e),xo=e=>Mi.encode(e),Tn=e=>e.map(t=>Mi.encode(c2(t))),Wr=e=>e.map(t=>Lm(Mi.decode(t))),sa=e=>{if(e instanceof Uint8Array)return xo(e);if(Hm(e))return nr(e).documentId;if(Zm(e))return e;if(l2(e)){console.warn("Future versions will not support UUIDs as document IDs; use Automerge URLs instead.");const t=Gv(e);return xo(t)}throw new Error(`Invalid AutomergeUrl: '${e}'`)};let Ru;try{Ru=new TextDecoder}catch{}let De,Ii,le=0;const u2=105,d2=57342,f2=57343,ig=57337,sg=6,Qi={};let Js=11281e4,kr=1681e4,tt={},Rt,uc,dc=0,So=0,Kt,Un,Zt=[],Fu=[],vn,gn,eo,og={useRecords:!1,mapsAsObjects:!0},$o=!1,Wm=2;try{new Function("")}catch{Wm=1/0}let qm=class Bu{constructor(t){if(t&&((t.keyMap||t._keyMap)&&!t.useRecords&&(t.useRecords=!1,t.mapsAsObjects=!0),t.useRecords===!1&&t.mapsAsObjects===void 0&&(t.mapsAsObjects=!0),t.getStructures&&(t.getShared=t.getStructures),t.getShared&&!t.structures&&((t.structures=[]).uninitialized=!0),t.keyMap)){this.mapKey=new Map;for(let[n,r]of Object.entries(t.keyMap))this.mapKey.set(r,n)}Object.assign(this,t)}decodeKey(t){return this.keyMap&&this.mapKey.get(t)||t}encodeKey(t){return this.keyMap&&this.keyMap.hasOwnProperty(t)?this.keyMap[t]:t}encodeKeys(t){if(!this._keyMap)return t;let n=new Map;for(let[r,i]of Object.entries(t))n.set(this._keyMap.hasOwnProperty(r)?this._keyMap[r]:r,i);return n}decodeKeys(t){if(!this._keyMap||t.constructor.name!="Map")return t;if(!this._mapKey){this._mapKey=new Map;for(let[r,i]of Object.entries(this._keyMap))this._mapKey.set(i,r)}let n={};return t.forEach((r,i)=>n[jn(this._mapKey.has(i)?this._mapKey.get(i):i)]=r),n}mapDecode(t,n){let r=this.decode(t);if(this._keyMap)switch(r.constructor.name){case"Array":return r.map(i=>this.decodeKeys(i))}return r}decode(t,n){if(De)return Ym(()=>(Lu(),this?this.decode(t,n):Bu.prototype.decode.call(og,t,n)));Ii=n>-1?n:t.length,le=0,So=0,uc=null,Kt=null,De=t;try{gn=t.dataView||(t.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength))}catch(r){throw De=null,t instanceof Uint8Array?r:new Error("Source must be a Uint8Array or Buffer but was a "+(t&&typeof t=="object"?t.constructor.name:typeof t))}if(this instanceof Bu){if(tt=this,vn=this.sharedValues&&(this.pack?new Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues),this.structures)return Rt=this.structures,oa();(!Rt||Rt.length>0)&&(Rt=[])}else tt=og,(!Rt||Rt.length>0)&&(Rt=[]),vn=null;return oa()}decodeMultiple(t,n){let r,i=0;try{let s=t.length;$o=!0;let o=this?this.decode(t,s):lf.decode(t,s);if(n){if(n(o)===!1)return;for(;le<s;)if(i=le,n(oa())===!1)return}else{for(r=[o];le<s;)i=le,r.push(oa());return r}}catch(s){throw s.lastPosition=i,s.values=r,s}finally{$o=!1,Lu()}}};function oa(){try{let e=rt();if(Kt){if(le>=Kt.postBundlePosition){let t=new Error("Unexpected bundle position");throw t.incomplete=!0,t}le=Kt.postBundlePosition,Kt=null}if(le==Ii)Rt=null,De=null,Un&&(Un=null);else if(le>Ii){let t=new Error("Unexpected end of CBOR data");throw t.incomplete=!0,t}else if(!$o)throw new Error("Data read, but end of buffer not reached");return e}catch(e){throw Lu(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer"))&&(e.incomplete=!0),e}}function rt(){let e=De[le++],t=e>>5;if(e=e&31,e>23)switch(e){case 24:e=De[le++];break;case 25:if(t==7)return m2();e=gn.getUint16(le),le+=2;break;case 26:if(t==7){let n=gn.getFloat32(le);if(tt.useFloat32>2){let r=cf[(De[le]&127)<<1|De[le+1]>>7];return le+=4,(r*n+(n>0?.5:-.5)>>0)/r}return le+=4,n}if(e=gn.getUint32(le),le+=4,t===1)return-1-e;break;case 27:if(t==7){let n=gn.getFloat64(le);return le+=8,n}if(t>1){if(gn.getUint32(le)>0)throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");e=gn.getUint32(le+4)}else tt.int64AsNumber?(e=gn.getUint32(le)*0x100000000,e+=gn.getUint32(le+4)):e=gn.getBigUint64(le);le+=8;break;case 31:switch(t){case 2:case 3:throw new Error("Indefinite length not supported for byte or text strings");case 4:let n=[],r,i=0;for(;(r=rt())!=Qi;){if(i>=Js)throw new Error(`Array length exceeds ${Js}`);n[i++]=r}return t==4?n:t==3?n.join(""):Buffer.concat(n);case 5:let s;if(tt.mapsAsObjects){let o={},a=0;if(tt.keyMap)for(;(s=rt())!=Qi;){if(a++>=kr)throw new Error(`Property count exceeds ${kr}`);o[jn(tt.decodeKey(s))]=rt()}else for(;(s=rt())!=Qi;){if(a++>=kr)throw new Error(`Property count exceeds ${kr}`);o[jn(s)]=rt()}return o}else{eo&&(tt.mapsAsObjects=!0,eo=!1);let o=new Map;if(tt.keyMap){let a=0;for(;(s=rt())!=Qi;){if(a++>=kr)throw new Error(`Map size exceeds ${kr}`);o.set(tt.decodeKey(s),rt())}}else{let a=0;for(;(s=rt())!=Qi;){if(a++>=kr)throw new Error(`Map size exceeds ${kr}`);o.set(s,rt())}}return o}case 7:return Qi;default:throw new Error("Invalid major type for indefinite length "+t)}default:throw new Error("Unknown token "+e)}switch(t){case 0:return e;case 1:return~e;case 2:return p2(e);case 3:if(So>=le)return uc.slice(le-dc,(le+=e)-dc);if(So==0&&Ii<140&&e<32){let i=e<16?Jm(e):g2(e);if(i!=null)return i}return h2(e);case 4:if(e>=Js)throw new Error(`Array length exceeds ${Js}`);let n=new Array(e);for(let i=0;i<e;i++)n[i]=rt();return n;case 5:if(e>=kr)throw new Error(`Map size exceeds ${Js}`);if(tt.mapsAsObjects){let i={};if(tt.keyMap)for(let s=0;s<e;s++)i[jn(tt.decodeKey(rt()))]=rt();else for(let s=0;s<e;s++)i[jn(rt())]=rt();return i}else{eo&&(tt.mapsAsObjects=!0,eo=!1);let i=new Map;if(tt.keyMap)for(let s=0;s<e;s++)i.set(tt.decodeKey(rt()),rt());else for(let s=0;s<e;s++)i.set(rt(),rt());return i}case 6:if(e>=ig){let i=Rt[e&8191];if(i)return i.read||(i.read=Uu(i)),i.read();if(e<65536){if(e==f2){let s=cs(),o=rt(),a=rt();Mu(o,a);let c={};if(tt.keyMap)for(let l=2;l<s;l++){let f=tt.decodeKey(a[l-2]);c[jn(f)]=rt()}else for(let l=2;l<s;l++){let f=a[l-2];c[jn(f)]=rt()}return c}else if(e==d2){let s=cs(),o=rt();for(let a=2;a<s;a++)Mu(o++,rt());return rt()}else if(e==ig)return x2();if(tt.getShared&&(af(),i=Rt[e&8191],i))return i.read||(i.read=Uu(i)),i.read()}}let r=Zt[e];if(r)return r.handlesRead?r(rt):r(rt());{let i=rt();for(let s=0;s<Fu.length;s++){let o=Fu[s](e,i);if(o!==void 0)return o}return new Ti(i,e)}case 7:switch(e){case 20:return!1;case 21:return!0;case 22:return null;case 23:return;case 31:default:let i=(vn||bi())[e];if(i!==void 0)return i;throw new Error("Unknown token "+e)}default:if(isNaN(e)){let i=new Error("Unexpected end of CBOR data");throw i.incomplete=!0,i}throw new Error("Unknown CBOR token "+e)}}const ag=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function Uu(e){if(!e)throw new Error("Structure is required in record definition");function t(){let n=De[le++];if(n=n&31,n>23)switch(n){case 24:n=De[le++];break;case 25:n=gn.getUint16(le),le+=2;break;case 26:n=gn.getUint32(le),le+=4;break;default:throw new Error("Expected array header, but got "+De[le-1])}let r=this.compiledReader;for(;r;){if(r.propertyCount===n)return r(rt);r=r.next}if(this.slowReads++>=Wm){let s=this.length==n?this:this.slice(0,n);return r=tt.keyMap?new Function("r","return {"+s.map(o=>tt.decodeKey(o)).map(o=>ag.test(o)?jn(o)+":r()":"["+JSON.stringify(o)+"]:r()").join(",")+"}"):new Function("r","return {"+s.map(o=>ag.test(o)?jn(o)+":r()":"["+JSON.stringify(o)+"]:r()").join(",")+"}"),this.compiledReader&&(r.next=this.compiledReader),r.propertyCount=n,this.compiledReader=r,r(rt)}let i={};if(tt.keyMap)for(let s=0;s<n;s++)i[jn(tt.decodeKey(this[s]))]=rt();else for(let s=0;s<n;s++)i[jn(this[s])]=rt();return i}return e.slowReads=0,t}function jn(e){if(typeof e=="string")return e==="__proto__"?"__proto_":e;if(typeof e=="number"||typeof e=="boolean"||typeof e=="bigint")return e.toString();if(e==null)return e+"";throw new Error("Invalid property name type "+typeof e)}let h2=ju;function ju(e){let t;if(e<16&&(t=Jm(e)))return t;if(e>64&&Ru)return Ru.decode(De.subarray(le,le+=e));const n=le+e,r=[];for(t="";le<n;){const i=De[le++];if((i&128)===0)r.push(i);else if((i&224)===192){const s=De[le++]&63,o=(i&31)<<6|s;o<128?r.push(65533):r.push(o)}else if((i&240)===224){const s=De[le++]&63,o=De[le++]&63,a=(i&31)<<12|s<<6|o;a<2048||a>=55296&&a<=57343?r.push(65533):r.push(a)}else if((i&248)===240){const s=De[le++]&63,o=De[le++]&63,a=De[le++]&63;let c=(i&7)<<18|s<<12|o<<6|a;c<65536||c>1114111?r.push(65533):(c>65535&&(c-=65536,r.push(c>>>10&1023|55296),c=56320|c&1023),r.push(c))}else r.push(65533);r.length>=4096&&(t+=Xt.apply(String,r),r.length=0)}return r.length>0&&(t+=Xt.apply(String,r)),t}let Xt=String.fromCharCode;function g2(e){let t=le,n=new Array(e);for(let r=0;r<e;r++){const i=De[le++];if((i&128)>0){le=t;return}n[r]=i}return Xt.apply(String,n)}function Jm(e){if(e<4)if(e<2){if(e===0)return"";{let t=De[le++];if((t&128)>1){le-=1;return}return Xt(t)}}else{let t=De[le++],n=De[le++];if((t&128)>0||(n&128)>0){le-=2;return}if(e<3)return Xt(t,n);let r=De[le++];if((r&128)>0){le-=3;return}return Xt(t,n,r)}else{let t=De[le++],n=De[le++],r=De[le++],i=De[le++];if((t&128)>0||(n&128)>0||(r&128)>0||(i&128)>0){le-=4;return}if(e<6){if(e===4)return Xt(t,n,r,i);{let s=De[le++];if((s&128)>0){le-=5;return}return Xt(t,n,r,i,s)}}else if(e<8){let s=De[le++],o=De[le++];if((s&128)>0||(o&128)>0){le-=6;return}if(e<7)return Xt(t,n,r,i,s,o);let a=De[le++];if((a&128)>0){le-=7;return}return Xt(t,n,r,i,s,o,a)}else{let s=De[le++],o=De[le++],a=De[le++],c=De[le++];if((s&128)>0||(o&128)>0||(a&128)>0||(c&128)>0){le-=8;return}if(e<10){if(e===8)return Xt(t,n,r,i,s,o,a,c);{let l=De[le++];if((l&128)>0){le-=9;return}return Xt(t,n,r,i,s,o,a,c,l)}}else if(e<12){let l=De[le++],f=De[le++];if((l&128)>0||(f&128)>0){le-=10;return}if(e<11)return Xt(t,n,r,i,s,o,a,c,l,f);let u=De[le++];if((u&128)>0){le-=11;return}return Xt(t,n,r,i,s,o,a,c,l,f,u)}else{let l=De[le++],f=De[le++],u=De[le++],h=De[le++];if((l&128)>0||(f&128)>0||(u&128)>0||(h&128)>0){le-=12;return}if(e<14){if(e===12)return Xt(t,n,r,i,s,o,a,c,l,f,u,h);{let d=De[le++];if((d&128)>0){le-=13;return}return Xt(t,n,r,i,s,o,a,c,l,f,u,h,d)}}else{let d=De[le++],g=De[le++];if((d&128)>0||(g&128)>0){le-=14;return}if(e<15)return Xt(t,n,r,i,s,o,a,c,l,f,u,h,d,g);let p=De[le++];if((p&128)>0){le-=15;return}return Xt(t,n,r,i,s,o,a,c,l,f,u,h,d,g,p)}}}}}function p2(e){return tt.copyBuffers?Uint8Array.prototype.slice.call(De,le,le+=e):De.subarray(le,le+=e)}let Km=new Float32Array(1),aa=new Uint8Array(Km.buffer,0,4);function m2(){let e=De[le++],t=De[le++],n=(e&127)>>2;if(n===31)return t||e&3?NaN:e&128?-1/0:1/0;if(n===0){let r=((e&3)<<8|t)/0x1000000;return e&128?-r:r}return aa[3]=e&128|(n>>1)+56,aa[2]=(e&7)<<5|t>>3,aa[1]=t<<5,aa[0]=0,Km[0]}new Array(4096);let Ti=class{constructor(t,n){this.value=t,this.tag=n}};Zt[0]=e=>new Date(e);Zt[1]=e=>new Date(Math.round(e*1e3));Zt[2]=e=>{let t=BigInt(0);for(let n=0,r=e.byteLength;n<r;n++)t=BigInt(e[n])+(t<<BigInt(8));return t};Zt[3]=e=>BigInt(-1)-Zt[2](e);Zt[4]=e=>+(e[1]+"e"+e[0]);Zt[5]=e=>e[1]*Math.exp(e[0]*Math.log(2));const Mu=(e,t)=>{e=e-57344;let n=Rt[e];n&&n.isShared&&((Rt.restoreStructures||(Rt.restoreStructures=[]))[e]=n),Rt[e]=t,t.read=Uu(t)};Zt[u2]=e=>{let t=e.length,n=e[1];Mu(e[0],n);let r={};for(let i=2;i<t;i++){let s=n[i-2];r[jn(s)]=e[i]}return r};Zt[14]=e=>Kt?Kt[0].slice(Kt.position0,Kt.position0+=e):new Ti(e,14);Zt[15]=e=>Kt?Kt[1].slice(Kt.position1,Kt.position1+=e):new Ti(e,15);let _2={Error,RegExp};Zt[27]=e=>(_2[e[0]]||Error)(e[1],e[2]);const Gm=e=>{if(De[le++]!=132){let n=new Error("Packed values structure must be followed by a 4 element array");throw De.length<le&&(n.incomplete=!0),n}let t=e();if(!t||!t.length){let n=new Error("Packed values structure must be followed by a 4 element array");throw n.incomplete=!0,n}return vn=vn?t.concat(vn.slice(t.length)):t,vn.prefixes=e(),vn.suffixes=e(),e()};Gm.handlesRead=!0;Zt[51]=Gm;Zt[sg]=e=>{if(!vn)if(tt.getShared)af();else return new Ti(e,sg);if(typeof e=="number")return vn[16+(e>=0?2*e:-2*e-1)];let t=new Error("No support for non-integer packed references yet");throw e===void 0&&(t.incomplete=!0),t};Zt[28]=e=>{Un||(Un=new Map,Un.id=0);let t=Un.id++,n=le,r=De[le],i;r>>5==4?i=[]:i={};let s={target:i};Un.set(t,s);let o=e();return s.used?(Object.getPrototypeOf(i)!==Object.getPrototypeOf(o)&&(le=n,i=o,Un.set(t,{target:i}),o=e()),Object.assign(i,o)):(s.target=o,o)};Zt[28].handlesRead=!0;Zt[29]=e=>{let t=Un.get(e);return t.used=!0,t.target};Zt[258]=e=>new Set(e);(Zt[259]=e=>(tt.mapsAsObjects&&(tt.mapsAsObjects=!1,eo=!0),e())).handlesRead=!0;function es(e,t){return typeof e=="string"?e+t:e instanceof Array?e.concat(t):Object.assign({},e,t)}function bi(){if(!vn)if(tt.getShared)af();else throw new Error("No packed values available");return vn}const y2=0x53687264;Fu.push((e,t)=>{if(e>=225&&e<=255)return es(bi().prefixes[e-224],t);if(e>=28704&&e<=32767)return es(bi().prefixes[e-28672],t);if(e>=0x70001000&&e<=0x7fffffff)return es(bi().prefixes[e-0x70000000],t);if(e>=216&&e<=223)return es(t,bi().suffixes[e-216]);if(e>=27647&&e<=28671)return es(t,bi().suffixes[e-27639]);if(e>=0x6c000400&&e<=0x6fffffff)return es(t,bi().suffixes[e-0x6c000000]);if(e==y2)return{packedValues:vn,structures:Rt.slice(0),version:t};if(e==55799)return t});const b2=new Uint8Array(new Uint16Array([1]).buffer)[0]==1,cg=[Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?{name:"BigUint64Array"}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?{name:"BigInt64Array"}:BigInt64Array,Float32Array,Float64Array],w2=[64,68,69,70,71,72,77,78,79,85,86];for(let e=0;e<cg.length;e++)v2(cg[e],w2[e]);function v2(e,t){let n="get"+e.name.slice(0,-5),r;typeof e=="function"?r=e.BYTES_PER_ELEMENT:e=null;for(let i=0;i<2;i++){if(!i&&r==1)continue;let s=r==2?1:r==4?2:r==8?3:0;Zt[i?t:t-4]=r==1||i==b2?o=>{if(!e)throw new Error("Could not find typed array for code "+t);return!tt.copyBuffers&&(r===1||r===2&&!(o.byteOffset&1)||r===4&&!(o.byteOffset&3)||r===8&&!(o.byteOffset&7))?new e(o.buffer,o.byteOffset,o.byteLength>>s):new e(Uint8Array.prototype.slice.call(o,0).buffer)}:o=>{if(!e)throw new Error("Could not find typed array for code "+t);let a=new DataView(o.buffer,o.byteOffset,o.byteLength),c=o.length>>s,l=new e(c),f=a[n];for(let u=0;u<c;u++)l[u]=f.call(a,u<<s,i);return l}}}function x2(){let e=cs(),t=le+rt();for(let r=2;r<e;r++){let i=cs();le+=i}let n=le;return le=t,Kt=[ju(cs()),ju(cs())],Kt.position0=0,Kt.position1=0,Kt.postBundlePosition=le,le=n,rt()}function cs(){let e=De[le++]&31;if(e>23)switch(e){case 24:e=De[le++];break;case 25:e=gn.getUint16(le),le+=2;break;case 26:e=gn.getUint32(le),le+=4;break}return e}function af(){if(tt.getShared){let e=Ym(()=>(De=null,tt.getShared()))||{},t=e.structures||[];tt.sharedVersion=e.version,vn=tt.sharedValues=e.packedValues,Rt===!0?tt.structures=Rt=t:Rt.splice.apply(Rt,[0,t.length].concat(t))}}function Ym(e){let t=Ii,n=le,r=dc,i=So,s=uc,o=Un,a=Kt,c=new Uint8Array(De.slice(0,Ii)),l=Rt,f=tt,u=$o,h=e();return Ii=t,le=n,dc=r,So=i,uc=s,Un=o,Kt=a,De=c,$o=u,Rt=l,tt=f,gn=new DataView(De.buffer,De.byteOffset,De.byteLength),h}function Lu(){De=null,Un=null,Rt=null}const cf=new Array(147);for(let e=0;e<256;e++)cf[e]=+("1e"+Math.floor(45.15-e*.30103));let lf=new qm({useRecords:!1});const S2=lf.decode;lf.decodeMultiple;let Pa;try{Pa=new TextEncoder}catch{}let Nu,Xm;const Mc=typeof globalThis=="object"&&globalThis.Buffer,Wo=typeof Mc<"u",Il=Wo?Mc.allocUnsafeSlow:Uint8Array,lg=Wo?Mc:Uint8Array,ug=256,dg=Wo?0x100000000:0x7fd00000;let Cl,K,yt,W=0,Nr,Wt=null;const $2=61440,k2=/[\u0080-\uFFFF]/,An=Symbol("record-id");let Qm=class extends qm{constructor(t){super(t),this.offset=0;let n,r,i,s,o;t=t||{};let a=lg.prototype.utf8Write?function(y,w){return K.utf8Write(y,w,K.byteLength-w)}:Pa&&Pa.encodeInto?function(y,w){return Pa.encodeInto(y,K.subarray(w)).written}:!1,c=this,l=t.structures||t.saveStructures,f=t.maxSharedStructures;if(f==null&&(f=l?128:0),f>8190)throw new Error("Maximum maxSharedStructure is 8190");let u=t.sequential;u&&(f=0),this.structures||(this.structures=[]),this.saveStructures&&(this.saveShared=this.saveStructures);let h,d,g=t.sharedValues,p;if(g){p=Object.create(null);for(let y=0,w=g.length;y<w;y++)p[g[y]]=y}let m=[],b=0,x=0;this.mapEncode=function(y,w){if(this._keyMap&&!this._mapped)switch(y.constructor.name){case"Array":y=y.map($=>this.encodeKeys($));break}return this.encode(y,w)},this.encode=function(y,w){if(K||(K=new Il(8192),yt=new DataView(K.buffer,0,8192),W=0),Nr=K.length-10,Nr-W<2048?(K=new Il(K.length),yt=new DataView(K.buffer,0,K.length),Nr=K.length-10,W=0):w===gg&&(W=W+7&0x7ffffff8),n=W,c.useSelfDescribedHeader&&(yt.setUint32(W,0xd9d9f700),W+=3),o=c.structuredClone?new Map:null,c.bundleStrings&&typeof y!="string"?(Wt=[],Wt.size=1/0):Wt=null,r=c.structures,r){if(r.uninitialized){let P=c.getShared()||{};c.structures=r=P.structures||[],c.sharedVersion=P.version;let A=c.sharedValues=P.packedValues;if(A){p={};for(let J=0,S=A.length;J<S;J++)p[A[J]]=J}}let $=r.length;if($>f&&!u&&($=f),!r.transitions){r.transitions=Object.create(null);for(let P=0;P<$;P++){let A=r[P];if(!A)continue;let J,S=r.transitions;for(let U=0,O=A.length;U<O;U++){S[An]===void 0&&(S[An]=P);let F=A[U];J=S[F],J||(J=S[F]=Object.create(null)),S=J}S[An]=P|1048576}}u||(r.nextId=$)}if(i&&(i=!1),s=r||[],d=p,t.pack){let $=new Map;if($.values=[],$.encoder=c,$.maxValues=t.maxPrivatePackedValues||(p?16:1/0),$.objectMap=p||!1,$.samplingPackedValues=h,Ta(y,$),$.values.length>0){K[W++]=216,K[W++]=51,_r(4);let P=$.values;_(P),_r(0),_r(0),d=Object.create(p||null);for(let A=0,J=P.length;A<J;A++)d[P[A]]=A}}Cl=w&Ol;try{if(Cl)return;if(_(y),Wt&&hg(n,_),c.offset=W,o&&o.idsToInsert){W+=o.idsToInsert.length*2,W>Nr&&k(W),c.offset=W;let $=I2(K.subarray(n,W),o.idsToInsert);return o=null,$}return w&gg?(K.start=n,K.end=W,K):K.subarray(n,W)}finally{if(r){if(x<10&&x++,r.length>f&&(r.length=f),b>1e4)r.transitions=null,x=0,b=0,m.length>0&&(m=[]);else if(m.length>0&&!u){for(let $=0,P=m.length;$<P;$++)m[$][An]=void 0;m=[]}}if(i&&c.saveShared){c.structures.length>f&&(c.structures=c.structures.slice(0,f));let $=K.subarray(n,W);return c.updateSharedData()===!1?c.encode(y):$}w&C2&&(W=n)}},this.findCommonStringsToPack=()=>(h=new Map,p||(p=Object.create(null)),y=>{let w=y&&y.threshold||4,$=this.pack?y.maxPrivatePackedValues||16:0;g||(g=this.sharedValues=[]);for(let[P,A]of h)A.count>w&&(p[P]=$++,g.push(P),i=!0);for(;this.saveShared&&this.updateSharedData()===!1;);h=null});const _=y=>{W>Nr&&(K=k(W));var w=typeof y,$;if(w==="string"){if(d){let S=d[y];if(S>=0){S<16?K[W++]=S+224:(K[W++]=198,S&1?_(15-S>>1):_(S-16>>1));return}else if(h&&!t.pack){let U=h.get(y);U?U.count++:h.set(y,{count:1})}}let P=y.length;if(Wt&&P>=4&&P<1024){if((Wt.size+=P)>$2){let U,O=(Wt[0]?Wt[0].length*3+Wt[1].length:0)+10;W+O>Nr&&(K=k(W+O)),K[W++]=217,K[W++]=223,K[W++]=249,K[W++]=Wt.position?132:130,K[W++]=26,U=W-n,W+=4,Wt.position&&hg(n,_),Wt=["",""],Wt.size=0,Wt.position=U}let S=k2.test(y);Wt[S?0:1]+=y,K[W++]=S?206:207,_(P);return}let A;P<32?A=1:P<256?A=2:P<65536?A=3:A=5;let J=P*3;if(W+J>Nr&&(K=k(W+J)),P<64||!a){let S,U,O,F=W+A;for(S=0;S<P;S++)U=y.charCodeAt(S),U<128?K[F++]=U:U<2048?(K[F++]=U>>6|192,K[F++]=U&63|128):(U&64512)===55296&&((O=y.charCodeAt(S+1))&64512)===56320?(U=65536+((U&1023)<<10)+(O&1023),S++,K[F++]=U>>18|240,K[F++]=U>>12&63|128,K[F++]=U>>6&63|128,K[F++]=U&63|128):(K[F++]=U>>12|224,K[F++]=U>>6&63|128,K[F++]=U&63|128);$=F-W-A}else $=a(y,W+A,J);$<24?K[W++]=96|$:$<256?(A<2&&K.copyWithin(W+2,W+1,W+1+$),K[W++]=120,K[W++]=$):$<65536?(A<3&&K.copyWithin(W+3,W+2,W+2+$),K[W++]=121,K[W++]=$>>8,K[W++]=$&255):(A<5&&K.copyWithin(W+5,W+3,W+3+$),K[W++]=122,yt.setUint32(W,$),W+=4),W+=$}else if(w==="number")if(!this.alwaysUseFloat&&y>>>0===y)y<24?K[W++]=y:y<256?(K[W++]=24,K[W++]=y):y<65536?(K[W++]=25,K[W++]=y>>8,K[W++]=y&255):(K[W++]=26,yt.setUint32(W,y),W+=4);else if(!this.alwaysUseFloat&&y>>0===y)y>=-24?K[W++]=31-y:y>=-256?(K[W++]=56,K[W++]=~y):y>=-65536?(K[W++]=57,yt.setUint16(W,~y),W+=2):(K[W++]=58,yt.setUint32(W,~y),W+=4);else if(!this.alwaysUseFloat&&y<0&&y>=-0x100000000&&Math.floor(y)===y)K[W++]=58,yt.setUint32(W,-1-y),W+=4;else{let P;if((P=this.useFloat32)>0&&y<0x100000000&&y>=-0x80000000){K[W++]=250,yt.setFloat32(W,y);let A;if(P<4||(A=y*cf[(K[W]&127)<<1|K[W+1]>>7])>>0===A){W+=4;return}else W--}K[W++]=251,yt.setFloat64(W,y),W+=8}else if(w==="object")if(!y)K[W++]=246;else{if(o){let A=o.get(y);if(A){if(K[W++]=216,K[W++]=29,K[W++]=25,!A.references){let J=o.idsToInsert||(o.idsToInsert=[]);A.references=[],J.push(A)}A.references.push(W-n),W+=2;return}else o.set(y,{offset:W-n})}let P=y.constructor;if(P===Object)this.skipFunction===!0&&(y=Object.fromEntries([...Object.keys(y).filter(A=>typeof y[A]!="function").map(A=>[A,y[A]])])),E(y);else if(P===Array){$=y.length,$<24?K[W++]=128|$:_r($);for(let A=0;A<$;A++)_(y[A])}else if(P===Map)if((this.mapsAsObjects?this.useTag259ForMaps!==!1:this.useTag259ForMaps)&&(K[W++]=217,K[W++]=1,K[W++]=3),$=y.size,$<24?K[W++]=160|$:$<256?(K[W++]=184,K[W++]=$):$<65536?(K[W++]=185,K[W++]=$>>8,K[W++]=$&255):(K[W++]=186,yt.setUint32(W,$),W+=4),c.keyMap)for(let[A,J]of y)_(c.encodeKey(A)),_(J);else for(let[A,J]of y)_(A),_(J);else{for(let A=0,J=Nu.length;A<J;A++){let S=Xm[A];if(y instanceof S){let U=Nu[A],O=U.tag;O==null&&(O=U.getTag&&U.getTag.call(this,y)),O<24?K[W++]=192|O:O<256?(K[W++]=216,K[W++]=O):O<65536?(K[W++]=217,K[W++]=O>>8,K[W++]=O&255):O>-1&&(K[W++]=218,yt.setUint32(W,O),W+=4),U.encode.call(this,y,_,k);return}}if(y[Symbol.iterator]){if(Cl){let A=new Error("Iterable should be serialized as iterator");throw A.iteratorNotHandled=!0,A}K[W++]=159;for(let A of y)_(A);K[W++]=255;return}if(y[Symbol.asyncIterator]||zl(y)){let A=new Error("Iterable/blob should be serialized as iterator");throw A.iteratorNotHandled=!0,A}if(this.useToJSON&&y.toJSON){const A=y.toJSON();if(A!==y)return _(A)}E(y)}}else if(w==="boolean")K[W++]=y?245:244;else if(w==="bigint"){if(y<BigInt(1)<<BigInt(64)&&y>=0)K[W++]=27,yt.setBigUint64(W,y);else if(y>-(BigInt(1)<<BigInt(64))&&y<0)K[W++]=59,yt.setBigUint64(W,-y-BigInt(1));else if(this.largeBigIntToFloat)K[W++]=251,yt.setFloat64(W,Number(y));else{y>=BigInt(0)?K[W++]=194:(K[W++]=195,y=BigInt(-1)-y);let P=[];for(;y;)P.push(Number(y&BigInt(255))),y>>=BigInt(8);Hu(new Uint8Array(P.reverse()),k);return}W+=8}else if(w==="undefined")K[W++]=247;else throw new Error("Unknown type: "+w)},E=this.useRecords===!1?this.variableMapSize?y=>{let w=Object.keys(y),$=Object.values(y),P=w.length;if(P<24?K[W++]=160|P:P<256?(K[W++]=184,K[W++]=P):P<65536?(K[W++]=185,K[W++]=P>>8,K[W++]=P&255):(K[W++]=186,yt.setUint32(W,P),W+=4),c.keyMap)for(let A=0;A<P;A++)_(c.encodeKey(w[A])),_($[A]);else for(let A=0;A<P;A++)_(w[A]),_($[A])}:y=>{K[W++]=185;let w=W-n;W+=2;let $=0;if(c.keyMap)for(let P in y)(typeof y.hasOwnProperty!="function"||y.hasOwnProperty(P))&&(_(c.encodeKey(P)),_(y[P]),$++);else for(let P in y)(typeof y.hasOwnProperty!="function"||y.hasOwnProperty(P))&&(_(P),_(y[P]),$++);K[w+++n]=$>>8,K[w+n]=$&255}:(y,w)=>{let $,P=s.transitions||(s.transitions=Object.create(null)),A=0,J=0,S,U;if(this.keyMap){U=Object.keys(y).map(F=>this.encodeKey(F)),J=U.length;for(let F=0;F<J;F++){let X=U[F];$=P[X],$||($=P[X]=Object.create(null),A++),P=$}}else for(let F in y)(typeof y.hasOwnProperty!="function"||y.hasOwnProperty(F))&&($=P[F],$||(P[An]&1048576&&(S=P[An]&65535),$=P[F]=Object.create(null),A++),P=$,J++);let O=P[An];if(O!==void 0)O&=65535,K[W++]=217,K[W++]=O>>8|224,K[W++]=O&255;else if(U||(U=P.__keys__||(P.__keys__=Object.keys(y))),S===void 0?(O=s.nextId++,O||(O=0,s.nextId=1),O>=ug&&(s.nextId=(O=f)+1)):O=S,s[O]=U,O<f){K[W++]=217,K[W++]=O>>8|224,K[W++]=O&255,P=s.transitions;for(let F=0;F<J;F++)(P[An]===void 0||P[An]&1048576)&&(P[An]=O),P=P[U[F]];P[An]=O|1048576,i=!0}else{if(P[An]=O,yt.setUint32(W,0xd9dfff00),W+=3,A&&(b+=x*A),m.length>=ug-f&&(m.shift()[An]=void 0),m.push(P),_r(J+2),_(57344+O),_(U),w)return;for(let F in y)(typeof y.hasOwnProperty!="function"||y.hasOwnProperty(F))&&_(y[F]);return}if(J<24?K[W++]=128|J:_r(J),!w)for(let F in y)(typeof y.hasOwnProperty!="function"||y.hasOwnProperty(F))&&_(y[F])},k=y=>{let w;if(y>0x1000000){if(y-n>dg)throw new Error("Encoded buffer would be larger than maximum buffer size");w=Math.min(dg,Math.round(Math.max((y-n)*(y>0x4000000?1.25:2),4194304)/4096)*4096)}else w=(Math.max(y-n<<2,K.length-1)>>12)+1<<12;let $=new Il(w);return yt=new DataView($.buffer,0,w),K.copy?K.copy($,0,n,y):$.set(K.slice(n,y)),W-=n,n=0,Nr=$.length-10,K=$};let C=100,T=1e3;this.encodeAsIterable=function(y,w){return N(y,w,j)},this.encodeAsAsyncIterable=function(y,w){return N(y,w,D)};function*j(y,w,$){let P=y.constructor;if(P===Object){let A=c.useRecords!==!1;A?E(y,!0):fg(Object.keys(y).length,160);for(let J in y){let S=y[J];A||_(J),S&&typeof S=="object"?w[J]?yield*j(S,w[J]):yield*I(S,w,J):_(S)}}else if(P===Array){let A=y.length;_r(A);for(let J=0;J<A;J++){let S=y[J];S&&(typeof S=="object"||W-n>C)?w.element?yield*j(S,w.element):yield*I(S,w,"element"):_(S)}}else if(y[Symbol.iterator]&&!y.buffer){K[W++]=159;for(let A of y)A&&(typeof A=="object"||W-n>C)?w.element?yield*j(A,w.element):yield*I(A,w,"element"):_(A);K[W++]=255}else zl(y)?(fg(y.size,64),yield K.subarray(n,W),yield y,R()):y[Symbol.asyncIterator]?(K[W++]=159,yield K.subarray(n,W),yield y,R(),K[W++]=255):_(y);$&&W>n?yield K.subarray(n,W):W-n>C&&(yield K.subarray(n,W),R())}function*I(y,w,$){let P=W-n;try{_(y),W-n>C&&(yield K.subarray(n,W),R())}catch(A){if(A.iteratorNotHandled)w[$]={},W=n+P,yield*j.call(this,y,w[$]);else throw A}}function R(){C=T,c.encode(null,Ol)}function N(y,w,$){return w&&w.chunkThreshold?C=T=w.chunkThreshold:C=100,y&&typeof y=="object"?(c.encode(null,Ol),$(y,c.iterateProperties||(c.iterateProperties={}),!0)):[c.encode(y)]}async function*D(y,w){for(let $ of j(y,w,!0)){let P=$.constructor;if(P===lg||P===Uint8Array)yield $;else if(zl($)){let A=$.stream().getReader(),J;for(;!(J=await A.read()).done;)yield J.value}else if($[Symbol.asyncIterator])for await(let A of $)R(),A?yield*D(A,w.async||(w.async={})):yield c.encode(A);else yield $}}}useBuffer(t){K=t,yt=new DataView(K.buffer,K.byteOffset,K.byteLength),W=0}clearSharedData(){this.structures&&(this.structures=[]),this.sharedValues&&(this.sharedValues=void 0)}updateSharedData(){let t=this.sharedVersion||0;this.sharedVersion=t+1;let n=this.structures.slice(0),r=new e_(n,this.sharedValues,this.sharedVersion),i=this.saveShared(r,s=>(s&&s.version||0)==t);return i===!1?(r=this.getShared()||{},this.structures=r.structures||[],this.sharedValues=r.packedValues,this.sharedVersion=r.version,this.structures.nextId=this.structures.length):n.forEach((s,o)=>this.structures[o]=s),i}};function fg(e,t){e<24?K[W++]=t|e:e<256?(K[W++]=t|24,K[W++]=e):e<65536?(K[W++]=t|25,K[W++]=e>>8,K[W++]=e&255):(K[W++]=t|26,yt.setUint32(W,e),W+=4)}let e_=class{constructor(t,n,r){this.structures=t,this.packedValues=n,this.version=r}};function _r(e){e<24?K[W++]=128|e:e<256?(K[W++]=152,K[W++]=e):e<65536?(K[W++]=153,K[W++]=e>>8,K[W++]=e&255):(K[W++]=154,yt.setUint32(W,e),W+=4)}const E2=typeof Blob>"u"?function(){}:Blob;function zl(e){if(e instanceof E2)return!0;let t=e[Symbol.toStringTag];return t==="Blob"||t==="File"}function Ta(e,t){switch(typeof e){case"string":if(e.length>3){if(t.objectMap[e]>-1||t.values.length>=t.maxValues)return;let r=t.get(e);if(r)++r.count==2&&t.values.push(e);else if(t.set(e,{count:1}),t.samplingPackedValues){let i=t.samplingPackedValues.get(e);i?i.count++:t.samplingPackedValues.set(e,{count:1})}}break;case"object":if(e)if(e instanceof Array)for(let r=0,i=e.length;r<i;r++)Ta(e[r],t);else{let r=!t.encoder.useRecords;for(var n in e)e.hasOwnProperty(n)&&(r&&Ta(n,t),Ta(e[n],t))}break;case"function":console.log(e)}}const A2=new Uint8Array(new Uint16Array([1]).buffer)[0]==1;Xm=[Date,Set,Error,RegExp,Ti,ArrayBuffer,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?function(){}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?function(){}:BigInt64Array,Float32Array,Float64Array,e_];Nu=[{tag:1,encode(e,t){let n=e.getTime()/1e3;(this.useTimestamp32||e.getMilliseconds()===0)&&n>=0&&n<0x100000000?(K[W++]=26,yt.setUint32(W,n),W+=4):(K[W++]=251,yt.setFloat64(W,n),W+=8)}},{tag:258,encode(e,t){let n=Array.from(e);t(n)}},{tag:27,encode(e,t){t([e.name,e.message])}},{tag:27,encode(e,t){t(["RegExp",e.source,e.flags])}},{getTag(e){return e.tag},encode(e,t){t(e.value)}},{encode(e,t,n){Hu(e,n)}},{getTag(e){if(e.constructor===Uint8Array&&(this.tagUint8Array||Wo&&this.tagUint8Array!==!1))return 64},encode(e,t,n){Hu(e,n)}},pr(68,1),pr(69,2),pr(70,4),pr(71,8),pr(72,1),pr(77,2),pr(78,4),pr(79,8),pr(85,4),pr(86,8),{encode(e,t){let n=e.packedValues||[],r=e.structures||[];if(n.values.length>0){K[W++]=216,K[W++]=51,_r(4);let i=n.values;t(i),_r(0),_r(0),packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let s=0,o=i.length;s<o;s++)packedObjectMap[i[s]]=s}if(r){yt.setUint32(W,0xd9dffe00),W+=3;let i=r.slice(0);i.unshift(57344),i.push(new Ti(e.version,0x53687264)),t(i)}else t(new Ti(e.version,0x53687264))}}];function pr(e,t){return!A2&&t>1&&(e-=4),{tag:e,encode:function(r,i){let s=r.byteLength,o=r.byteOffset||0,a=r.buffer||r;i(Wo?Mc.from(a,o,s):new Uint8Array(a,o,s))}}}function Hu(e,t){let n=e.byteLength;n<24?K[W++]=64+n:n<256?(K[W++]=88,K[W++]=n):n<65536?(K[W++]=89,K[W++]=n>>8,K[W++]=n&255):(K[W++]=90,yt.setUint32(W,n),W+=4),W+n>=K.length&&t(W+n),K.set(e.buffer?e:new Uint8Array(e),W),W+=n}function I2(e,t){let n,r=t.length*2,i=e.length-r;t.sort((s,o)=>s.offset>o.offset?1:-1);for(let s=0;s<t.length;s++){let o=t[s];o.id=s;for(let a of o.references)e[a++]=s>>8,e[a]=s&255}for(;n=t.pop();){let s=n.offset;e.copyWithin(s+r,s,i),r-=2;let o=s+r;e[o++]=216,e[o++]=28,i=s}return e}function hg(e,t){yt.setUint32(Wt.position+e,W-Wt.position-e+1);let n=Wt;Wt=null,t(n[0]),t(n[1])}let uf=new Qm({useRecords:!1});uf.encode;uf.encodeAsIterable;uf.encodeAsAsyncIterable;const gg=512,C2=1024,Ol=2048;function z2(e){return new Qm({tagUint8Array:!1,useRecords:!1}).encode(e)}const O2=(e,t)=>e.length===t.length&&e.every((n,r)=>n===t[r]),Lc=(e,t)=>O2(e,t),P2=async(e,t)=>{let n;const r=new Promise((i,s)=>{n=setTimeout(()=>s(new T2(`withTimeout: timed out after ${t}ms`)),t)});try{return await Promise.race([e,r])}finally{clearTimeout(n)}};class T2 extends Error{constructor(t){super(t),this.name="TimeoutError"}}class Nc extends DOMException{constructor(t){super(t??"Operation aborted","AbortError")}}const D2=e=>e instanceof Nc||(e instanceof Error||DOMException&&e instanceof DOMException)&&e.name==="AbortError";function pg(e,t){if(t?.aborted)return Promise.reject(t.reason);let n=!1;return new Promise((r,i)=>{const s=()=>{n||i(new Nc)};t?.addEventListener("abort",s,{once:!0}),e.then(o=>{r(o)}).catch(o=>{i(o)}).finally(()=>{n=!0,t?.removeEventListener("abort",s)})})}class fc extends ji{documentId;#e;#t;#r;#n=Hn();#s=6e4;#o={};#a=new Map;#c=new Map;#i;constructor(t,n,r={}){super(),this.documentId=t,this.#i=n,"timeoutDelay"in r&&r.timeoutDelay&&(this.#s=r.timeoutDelay),"heads"in r&&(this.#r=r.heads);const i=Hn();this.#e=Ui(`automerge-repo:dochandle:${this.documentId.slice(0,5)}`);const s=this.#s,o=Bm({actions:{onUpdate:ki(({context:a,event:c})=>{const l=a.doc;Nv(c,_g);const{callback:f}=c.payload;return{doc:f(l)}}),onDelete:ki(()=>(this.emit("delete",{handle:this}),{doc:Hn()})),onUnavailable:ki(()=>({doc:Hn()})),onUnload:ki(()=>({doc:Hn()}))}}).createMachine({initial:"idle",context:{documentId:t,doc:i},on:{UPDATE:{actions:"onUpdate"},UNLOAD:".unloaded",DELETE:".deleted"},states:{idle:{on:{BEGIN:"loading"}},loading:{on:{REQUEST:"requesting",DOC_READY:"ready"},after:{[s]:"unavailable"}},requesting:{on:{DOC_UNAVAILABLE:"unavailable",DOC_READY:"ready"},after:{[s]:"unavailable"}},unavailable:{entry:"onUnavailable",on:{DOC_READY:"ready"}},ready:{},unloaded:{entry:"onUnload",on:{RELOAD:"loading"}},deleted:{entry:"onDelete",type:"final"}}});this.#t=vo(o),this.#t.subscribe(a=>{const c=this.#n,l=a.context.doc;this.#e(`→ ${a.value} %o`,l),this.#p(c,l)}),this.#t.start(),this.begin()}get #l(){return this.#t?.getSnapshot().context.doc}get #f(){return this.#t?.getSnapshot().value}#h(t,n){const r=Array.isArray(t)?t:[t];return Vv(this.#t,i=>r.some(s=>i.matches(s)),{timeout:this.#s*2,...n})}#u(t){let n=null;if(this.#t.send({type:_g,payload:{callback:r=>{try{return t(r)}catch(i){return n=i,r}}}}),n)throw n}#p(t,n){const r=Bn(t),i=Bn(n);if(!Lc(Tn(i),Tn(r))){this.emit("heads-changed",{handle:this,doc:n});const o=ml(n,r,i);o.length>0&&this.emit("change",{handle:this,doc:n,patches:o,patchInfo:{before:t,after:n,source:"change"}}),this.isReady()||this.#t.send({type:mg})}this.#n=n}get url(){return Nm({documentId:this.documentId,heads:this.#r})}isReady=()=>this.inState(["ready"]);isUnloaded=()=>this.inState(["unloaded"]);isDeleted=()=>this.inState(["deleted"]);isUnavailable=()=>this.inState(["unavailable"]);inState=t=>t.some(n=>this.#t.getSnapshot().matches(n));get state(){return this.#t.getSnapshot().value}async whenReady(t=["ready"],n){try{await P2(this.#h(t,n),this.#s)}catch(r){throw D2(r)?new Nc:(console.log(`error waiting for ${this.documentId} to be in one of states: ${t.join(", ")}`),r)}}doc(){if(!this.isReady())throw new Error("DocHandle is not ready");return this.#r?o1(this.#l,Wr(this.#r)):this.#l}docSync(){return console.warn("docSync is deprecated. Use doc() instead. This function will be removed as part of the 2.0 release."),this.doc()}heads(){if(!this.isReady())throw new Error("DocHandle is not ready");return this.#r?this.#r:Tn(Bn(this.#l))}begin(){this.#t.send({type:B2})}history(){if(this.isReady())return m1(this.#l).map(t=>Tn([t]))}view(t){if(!this.isReady())throw new Error(`DocHandle#${this.documentId} is not ready. Check \`handle.isReady()\` before calling view().`);const n=JSON.stringify(t),r=this.#a.get(n);if(r)return r;const i=new fc(this.documentId,this.#i,{heads:t,timeoutDelay:this.#s});return i.update(()=>ic(this.#l)),i.doneLoading(),this.#a.set(n,i),i}diff(t,n){if(!this.isReady())throw new Error(`DocHandle#${this.documentId} is not ready. Check \`handle.isReady()\` before calling diff().`);const r=this.#l;if(!r)throw new Error("Document not available");if(t instanceof fc){if(!t.isReady())throw new Error("Cannot diff against a handle that isn't ready");const o=t.heads();if(!o)throw new Error("Other document's heads not available");const a=Ih(ic(r),t.doc());return ml(a,Wr(this.heads()),Wr(o))}const i=n?t:this.heads()||[],s=n||t;return ml(r,Wr(i),Wr(s))}metadata(t){if(this.isReady())return t||(t=this.heads()[0]),_1(this.#l,Wr([t])[0])||void 0}update(t){this.#u(t)}doneLoading(){this.#t.send({type:mg})}setSyncInfo(t,n){this.#o[t]=n,this.emit("remote-heads",{storageId:t,heads:n.lastHeads,timestamp:n.lastSyncTimestamp})}getRemoteHeads(t){return this.#o[t]?.lastHeads}getSyncInfo(t){return this.#o[t]}change(t,n={}){if(!this.isReady())throw new Error(`DocHandle#${this.documentId} is in ${this.state} and not ready. Check \`handle.isReady()\` before accessing the document.`);if(this.#r)throw new Error(`DocHandle#${this.documentId} is in view-only mode at specific heads. Use clone() to create a new document from this state.`);this.#u(r=>a1(r,n,t))}changeAt(t,n,r={}){if(!this.isReady())throw new Error(`DocHandle#${this.documentId} is not ready. Check \`handle.isReady()\` before accessing the document.`);if(this.#r)throw new Error(`DocHandle#${this.documentId} is in view-only mode at specific heads. Use clone() to create a new document from this state.`);let i;return this.#u(s=>{const o=c1(s,Wr(t),r,n);return i=o.newHeads?Tn(o.newHeads):void 0,o.newDoc}),i}isReadOnly(){return!!this.#r}merge(t){if(!this.isReady()||!t.isReady())throw new Error("Both handles must be ready to merge");if(this.#r)throw new Error(`DocHandle#${this.documentId} is in view-only mode at specific heads. Use clone() to create a new document from this state.`);const n=t.doc();this.update(r=>Ih(r,n))}unavailable(){this.#t.send({type:N2})}request(){this.#f==="loading"&&this.#t.send({type:U2})}unload(){this.#t.send({type:j2})}reload(){this.#t.send({type:M2})}delete(){this.#t.send({type:L2})}broadcast(t){this.emit("ephemeral-message-outbound",{handle:this,data:new Uint8Array(z2(t))})}metrics(){return qd(this.#l)}ref(...t){const n=this.#d(t),r=this.#c.get(n)?.deref();if(r)return r;const i=this.#i(this,t);return this.#c.set(n,new WeakRef(i)),i}#d(t){return t.map(n=>typeof n=="string"?`s:${n}`:typeof n=="number"?`n:${n}`:typeof n=="object"&&n!==null?`o:${JSON.stringify(n)}`:`?:${String(n)}`).join("/")}}const R2={REQUESTING:"requesting",READY:"ready",UNLOADED:"unloaded",DELETED:"deleted",UNAVAILABLE:"unavailable"},{REQUESTING:ca,READY:yr,UNLOADED:F2,DELETED:la,UNAVAILABLE:On}=R2,B2="BEGIN",U2="REQUEST",mg="DOC_READY",_g="UPDATE",j2="UNLOAD",M2="RELOAD",L2="DELETE",N2="DOC_UNAVAILABLE";class H2 extends ji{#e=new Map;#t=new Set;#r=new Map;#n=new Set;#s=new Map;#o=Ui("automerge-repo:remote-heads-subscriptions");subscribeToRemotes(t){this.#o("subscribeToRemotes",t);const n=[];for(const r of t)this.#t.has(r)||(this.#t.add(r),n.push(r));n.length>0&&this.emit("change-remote-subs",{add:n,peers:Array.from(this.#n)})}unsubscribeFromRemotes(t){this.#o("subscribeToRemotes",t);const n=[];for(const r of t)this.#t.has(r)&&(this.#t.delete(r),this.#r.has(r)||n.push(r));n.length>0&&this.emit("change-remote-subs",{remove:n,peers:Array.from(this.#n)})}handleControlMessage(t){const n=[],r=[],i=[];if(this.#o("handleControlMessage",t),t.add)for(const s of t.add){let o=this.#r.get(s);(this.#t.has(s)||o)&&i.push(s),o||(o=new Set,this.#r.set(s,o),this.#t.has(s)||n.push(s)),o.add(t.senderId)}if(t.remove)for(const s of t.remove){const o=this.#r.get(s);o&&(o.delete(t.senderId),o.size==0&&!this.#t.has(s)&&r.push(s))}(n.length>0||r.length>0)&&this.emit("change-remote-subs",{peers:Array.from(this.#n),add:n,remove:r});for(const s of i){const o=this.#s.get(t.senderId);if(o)for(const a of o){const c=this.#e.get(a);if(!c)continue;const l=c.get(s);l&&this.emit("notify-remote-heads",{targetId:t.senderId,documentId:a,heads:l.lastHeads,timestamp:l.lastSyncTimestamp,storageId:s})}}}handleRemoteHeads(t){this.#o("handleRemoteHeads",t);const n=this.#c(t);for(const r of n)this.#t.has(r.storageId)&&this.emit("remote-heads-changed",r);for(const r of n)for(const i of this.#n)i!==t.senderId&&this.emit("notify-remote-heads",{targetId:i,documentId:r.documentId,heads:r.remoteHeads,timestamp:r.timestamp,storageId:r.storageId});for(const r of n){const i=this.#r.get(r.storageId);if(i)for(const s of i)this.#a(s,r.documentId)&&this.emit("notify-remote-heads",{targetId:s,documentId:r.documentId,heads:r.remoteHeads,timestamp:r.timestamp,storageId:r.storageId})}}handleImmediateRemoteHeadsChanged(t,n,r){this.#o("handleLocalHeadsChanged",t,n,r);const i=this.#e.get(t),s=Date.now();if(!i)this.#e.set(t,new Map([[n,{lastSyncTimestamp:s,lastHeads:r}]]));else{const a=i.get(n);(!a||a.lastSyncTimestamp<Date.now())&&i.set(n,{lastSyncTimestamp:Date.now(),lastHeads:r})}const o=this.#r.get(n);if(o)for(const a of o)this.#a(a,t)&&this.emit("notify-remote-heads",{targetId:a,documentId:t,heads:r,timestamp:s,storageId:n})}addGenerousPeer(t){this.#o("addGenerousPeer",t),this.#n.add(t),this.#t.size>0&&this.emit("change-remote-subs",{add:Array.from(this.#t),peers:[t]});for(const[n,r]of this.#e)for(const[i,{lastHeads:s,lastSyncTimestamp:o}]of r)this.emit("notify-remote-heads",{targetId:t,documentId:n,heads:s,timestamp:o,storageId:i})}removePeer(t){this.#o("removePeer",t);const n=[];this.#n.delete(t),this.#s.delete(t);for(const[r,i]of this.#r)i.has(t)&&(i.delete(t),i.size==0&&(n.push(r),this.#r.delete(r)));n.length>0&&this.emit("change-remote-subs",{remove:n,peers:Array.from(this.#n)})}subscribePeerToDoc(t,n){let r=this.#s.get(t);r||(r=new Set,this.#s.set(t,r)),r.add(n);const i=this.#e.get(n);if(i)for(const[s,o]of i){const a=this.#r.get(s);a&&a.has(t)&&this.emit("notify-remote-heads",{targetId:t,documentId:n,heads:o.lastHeads,timestamp:o.lastSyncTimestamp,storageId:s})}}#a(t,n){const r=this.#s.get(t);return r&&r.has(n)}#c(t){const n=[],{documentId:r,newHeads:i}=t;for(const[s,{heads:o,timestamp:a}]of Object.entries(i)){if(!this.#t.has(s)&&!this.#r.has(s))continue;let c=this.#e.get(r);c||(c=new Map,this.#e.set(r,c));const l=c.get(s);l&&l.lastSyncTimestamp>=a||(c.set(s,{lastSyncTimestamp:a,lastHeads:o}),n.push({documentId:r,storageId:s,remoteHeads:o,timestamp:a}))}return n}}const Zu=(e,t)=>{let n=Date.now(),r,i;return async function(...s){if(i)try{await i}catch{}r&&clearTimeout(r);const o=n+t-Date.now();return new Promise((a,c)=>{r=setTimeout(async()=>{try{i=e(...s),a(await i)}catch(l){c(l)}finally{n=Date.now(),i=void 0,r=void 0}},o)})}},Z2=e=>W2(e)||n_(e)||t_(e)||V2(e)||q2(e)||J2(e),V2=e=>e.type==="doc-unavailable",t_=e=>e.type==="request",W2=e=>e.type==="sync",n_=e=>e.type==="ephemeral",q2=e=>e.type==="remote-subscription-change",J2=e=>e.type==="remote-heads-changed",K2=e=>`${e.senderId}:${e.sessionId}`;class G2 extends ji{peerId;peerMetadata;#e;#t={};#r=0;#n=Math.random().toString(36).slice(2);#s={};adapters=[];constructor(t,n,r){super(),this.peerId=n,this.peerMetadata=r,this.#e=Ui(`automerge-repo:network:${this.peerId}`),t.forEach(i=>this.addNetworkAdapter(i))}disconnect(){this.adapters.forEach(t=>t.disconnect())}reconnect(){this.adapters.forEach(t=>t.connect(this.peerId))}addNetworkAdapter(t){this.adapters.push(t),t.on("peer-candidate",({peerId:n,peerMetadata:r})=>{this.#e(`peer candidate: ${n} `),this.#t[n]||(this.#t[n]=t),this.emit("peer",{peerId:n,peerMetadata:r})}),t.on("peer-disconnected",({peerId:n})=>{this.#e(`peer disconnected: ${n} `),delete this.#t[n],this.emit("peer-disconnected",{peerId:n})}),t.on("message",n=>{if(!Z2(n)){this.#e(`invalid message: ${JSON.stringify(n)}`);return}if(this.#e(`message from ${n.senderId}`),n_(n)){const r=K2(n);(this.#s[r]===void 0||n.count>this.#s[r])&&(this.#s[r]=n.count,this.emit("message",n));return}this.emit("message",n)}),t.on("close",()=>{this.#e("adapter closed"),Object.entries(this.#t).forEach(([n,r])=>{r===t&&delete this.#t[n]}),this.adapters=this.adapters.filter(n=>n!==t)}),this.peerMetadata.then(n=>{t.connect(this.peerId,n)}).catch(n=>{this.#e("error connecting to network",n)})}removeNetworkAdapter(t){this.adapters=this.adapters.filter(n=>n!==t),t.disconnect()}send(t){const n=this.#t[t.targetId];if(!n){this.#e(`Tried to send message but peer not found: ${t.targetId}`);return}const i=(s=>s.type==="ephemeral"?"count"in s?s:{...s,count:++this.#r,sessionId:this.#n,senderId:this.peerId}:{...s,senderId:this.peerId})(t);this.#e("sending message %o",i),n.send(i)}isReady=()=>this.adapters.every(t=>t.isReady());whenReady=async()=>Promise.all(this.adapters.map(t=>t.whenReady()))}function r_(e){let t=0;e.forEach(i=>{t+=i.length});const n=new Uint8Array(t);let r=0;return e.forEach(i=>{n.set(i,r),r+=i.length}),n}var Da={exports:{}},Y2=Da.exports,yg;function X2(){return yg||(yg=1,(function(e){(function(t,n){var r={};n(r);var i=r.default;for(var s in r)i[s]=r[s];e.exports=i})(Y2,function(t){t.__esModule=!0,t.digestLength=32,t.blockSize=64;var n=new Uint32Array([0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0xfc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x6ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2]);function r(h,d,g,p,m){for(var b,x,_,E,k,C,T,j,I,R,N,D,y;m>=64;){for(b=d[0],x=d[1],_=d[2],E=d[3],k=d[4],C=d[5],T=d[6],j=d[7],R=0;R<16;R++)N=p+R*4,h[R]=(g[N]&255)<<24|(g[N+1]&255)<<16|(g[N+2]&255)<<8|g[N+3]&255;for(R=16;R<64;R++)I=h[R-2],D=(I>>>17|I<<15)^(I>>>19|I<<13)^I>>>10,I=h[R-15],y=(I>>>7|I<<25)^(I>>>18|I<<14)^I>>>3,h[R]=(D+h[R-7]|0)+(y+h[R-16]|0);for(R=0;R<64;R++)D=(((k>>>6|k<<26)^(k>>>11|k<<21)^(k>>>25|k<<7))+(k&C^~k&T)|0)+(j+(n[R]+h[R]|0)|0)|0,y=((b>>>2|b<<30)^(b>>>13|b<<19)^(b>>>22|b<<10))+(b&x^b&_^x&_)|0,j=T,T=C,C=k,k=E+D|0,E=_,_=x,x=b,b=D+y|0;d[0]+=b,d[1]+=x,d[2]+=_,d[3]+=E,d[4]+=k,d[5]+=C,d[6]+=T,d[7]+=j,p+=64,m-=64}return p}var i=(function(){function h(){this.digestLength=t.digestLength,this.blockSize=t.blockSize,this.state=new Int32Array(8),this.temp=new Int32Array(64),this.buffer=new Uint8Array(128),this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this.reset()}return h.prototype.reset=function(){return this.state[0]=0x6a09e667,this.state[1]=0xbb67ae85,this.state[2]=0x3c6ef372,this.state[3]=0xa54ff53a,this.state[4]=0x510e527f,this.state[5]=0x9b05688c,this.state[6]=0x1f83d9ab,this.state[7]=0x5be0cd19,this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this},h.prototype.clean=function(){for(var d=0;d<this.buffer.length;d++)this.buffer[d]=0;for(var d=0;d<this.temp.length;d++)this.temp[d]=0;this.reset()},h.prototype.update=function(d,g){if(g===void 0&&(g=d.length),this.finished)throw new Error("SHA256: can't update because hash was finished.");var p=0;if(this.bytesHashed+=g,this.bufferLength>0){for(;this.bufferLength<64&&g>0;)this.buffer[this.bufferLength++]=d[p++],g--;this.bufferLength===64&&(r(this.temp,this.state,this.buffer,0,64),this.bufferLength=0)}for(g>=64&&(p=r(this.temp,this.state,d,p,g),g%=64);g>0;)this.buffer[this.bufferLength++]=d[p++],g--;return this},h.prototype.finish=function(d){if(!this.finished){var g=this.bytesHashed,p=this.bufferLength,m=g/0x20000000|0,b=g<<3,x=g%64<56?64:128;this.buffer[p]=128;for(var _=p+1;_<x-8;_++)this.buffer[_]=0;this.buffer[x-8]=m>>>24&255,this.buffer[x-7]=m>>>16&255,this.buffer[x-6]=m>>>8&255,this.buffer[x-5]=m>>>0&255,this.buffer[x-4]=b>>>24&255,this.buffer[x-3]=b>>>16&255,this.buffer[x-2]=b>>>8&255,this.buffer[x-1]=b>>>0&255,r(this.temp,this.state,this.buffer,0,x),this.finished=!0}for(var _=0;_<8;_++)d[_*4+0]=this.state[_]>>>24&255,d[_*4+1]=this.state[_]>>>16&255,d[_*4+2]=this.state[_]>>>8&255,d[_*4+3]=this.state[_]>>>0&255;return this},h.prototype.digest=function(){var d=new Uint8Array(this.digestLength);return this.finish(d),d},h.prototype._saveState=function(d){for(var g=0;g<this.state.length;g++)d[g]=this.state[g]},h.prototype._restoreState=function(d,g){for(var p=0;p<this.state.length;p++)this.state[p]=d[p];this.bytesHashed=g,this.finished=!1,this.bufferLength=0},h})();t.Hash=i;var s=(function(){function h(d){this.inner=new i,this.outer=new i,this.blockSize=this.inner.blockSize,this.digestLength=this.inner.digestLength;var g=new Uint8Array(this.blockSize);if(d.length>this.blockSize)new i().update(d).finish(g).clean();else for(var p=0;p<d.length;p++)g[p]=d[p];for(var p=0;p<g.length;p++)g[p]^=54;this.inner.update(g);for(var p=0;p<g.length;p++)g[p]^=106;this.outer.update(g),this.istate=new Uint32Array(8),this.ostate=new Uint32Array(8),this.inner._saveState(this.istate),this.outer._saveState(this.ostate);for(var p=0;p<g.length;p++)g[p]=0}return h.prototype.reset=function(){return this.inner._restoreState(this.istate,this.inner.blockSize),this.outer._restoreState(this.ostate,this.outer.blockSize),this},h.prototype.clean=function(){for(var d=0;d<this.istate.length;d++)this.ostate[d]=this.istate[d]=0;this.inner.clean(),this.outer.clean()},h.prototype.update=function(d){return this.inner.update(d),this},h.prototype.finish=function(d){return this.outer.finished?this.outer.finish(d):(this.inner.finish(d),this.outer.update(d,this.digestLength).finish(d)),this},h.prototype.digest=function(){var d=new Uint8Array(this.digestLength);return this.finish(d),d},h})();t.HMAC=s;function o(h){var d=new i().update(h),g=d.digest();return d.clean(),g}t.hash=o,t.default=o;function a(h,d){var g=new s(h).update(d),p=g.digest();return g.clean(),p}t.hmac=a;function c(h,d,g,p){var m=p[0];if(m===0)throw new Error("hkdf: cannot expand more");d.reset(),m>1&&d.update(h),g&&d.update(g),d.update(p),d.finish(h),p[0]++}var l=new Uint8Array(t.digestLength);function f(h,d,g,p){d===void 0&&(d=l),p===void 0&&(p=32);for(var m=new Uint8Array([1]),b=a(d,h),x=new s(b),_=new Uint8Array(x.digestLength),E=_.length,k=new Uint8Array(p),C=0;C<p;C++)E===_.length&&(c(_,x,g,m),E=0),k[C]=_[E++];return x.clean(),_.fill(0),m.fill(0),k}t.hkdf=f;function u(h,d,g,p){for(var m=new s(h),b=m.digestLength,x=new Uint8Array(4),_=new Uint8Array(b),E=new Uint8Array(b),k=new Uint8Array(p),C=0;C*b<p;C++){var T=C+1;x[0]=T>>>24&255,x[1]=T>>>16&255,x[2]=T>>>8&255,x[3]=T>>>0&255,m.reset(),m.update(d),m.update(x),m.finish(E);for(var j=0;j<b;j++)_[j]=E[j];for(var j=2;j<=g;j++){m.reset(),m.update(E).finish(E);for(var I=0;I<b;I++)_[I]^=E[I]}for(var j=0;j<b&&C*b+j<p;j++)k[C*b+j]=_[j]}for(var C=0;C<b;C++)_[C]=E[C]=0;for(var C=0;C<4;C++)x[C]=0;return m.clean(),k}t.pbkdf2=u})})(Da)),Da.exports}var Q2=X2();function i_(e){const t=Q2.hash(e);return tx(t)}function ex(e){const t=new TextEncoder,n=r_(e.map(r=>t.encode(r)));return i_(n)}function tx(e){return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}class nx{#e=0;#t=new Map;lastSavedHeads(t){return new rx(t,++this.#e,this.#t)}}class rx{#e;#t;#r;#n=null;constructor(t,n,r){this.#e=t,this.#t=n,this.#r=r}get value(){return this.#r.get(this.#e)?.heads??null}update(t){if(this.#n&&!Lc(Tn(t),Tn(this.#n)))throw new Error("attempting to reuase a heads update with different heads");this.#n=t;const n=this.#r.get(this.#e)?.seq??0;this.#t>=n&&this.#r.set(this.#e,{heads:t,seq:this.#t})}}class ix extends ji{#e;#t=new nx;#r=new Map;#n=!1;#s=Ui("automerge-repo:storage-subsystem");constructor(t){super(),this.#e=t}async id(){const t=await this.#e.load(["storage-adapter-id"]);let n;return t?n=new TextDecoder().decode(t):(n=jm(),await this.#e.save(["storage-adapter-id"],new TextEncoder().encode(n))),n}async load(t,n){const r=[t,n];return await this.#e.load(r)}async save(t,n,r){const i=[t,n];await this.#e.save(i,r)}async remove(t,n){const r=[t,n];await this.#e.remove(r)}async loadDocData(t){const n=await this.#e.loadRange([t,"snapshot"]),r=await this.#e.loadRange([t,"incremental"]),i=[],s=[];for(const o of n)o.data!==void 0&&(s.push({key:o.key,type:"snapshot",size:o.data.length}),i.push(o.data));for(const o of r)o.data!==void 0&&(s.push({key:o.key,type:"incremental",size:o.data.length}),i.push(o.data));return this.#r.set(t,s),i.length===0?null:r_(i)}async loadDoc(t){const n=this.#t.lastSavedHeads(t),r=await this.loadDocData(t);if(!r)return null;const i=performance.now(),s=Wd(Hn(),r),o=performance.now();return this.emit("document-loaded",{documentId:t,durationMillis:o-i,...qd(s)}),n.update(Bn(s)),s}async saveDoc(t,n){if(!this.#c(t,n))return;const r=this.#r.get(t)??[];this.#i(r)?await this.#a(t,n,r):await this.#o(t,n)}async removeDoc(t){await this.#e.removeRange([t,"snapshot"]),await this.#e.removeRange([t,"incremental"]),await this.#e.removeRange([t,"sync-state"])}async #o(t,n){const r=this.#t.lastSavedHeads(t),i=r.value;if(!i||i.length===0){await this.#a(t,n,this.#r.get(t)??[]);return}const s=performance.now(),o=p1(n,i),a=performance.now();if(this.emit("doc-saved",{documentId:t,durationMillis:a-s,sinceHeads:i,savedHeads:Bn(n)}),o&&o.length>0){const c=[t,"incremental",i_(o)];this.#s(`Saving incremental ${c} for document ${t}`),await this.#e.save(c,o),this.#r.has(t)||this.#r.set(t,[]),this.#r.get(t).push({key:c,type:"incremental",size:o.length}),r.update(Bn(n))}else return Promise.resolve()}async #a(t,n,r){this.#n=!0;const i=this.#t.lastSavedHeads(t),s=performance.now(),o=um(n),a=performance.now();this.emit("doc-compacted",{documentId:t,durationMillis:a-s,savedHeads:Bn(n)});const c=ex(Bn(n)),l=[t,"snapshot",c],f=new Set(r.map(h=>h.key).filter(h=>h[2]!==c));this.#s(`Saving snapshot ${l} for document ${t}`),this.#s(`deleting old chunks ${Array.from(f)}`),await this.#e.save(l,o);for(const h of f)await this.#e.remove(h);const u=this.#r.get(t)?.filter(h=>!f.has(h.key))??[];u.push({key:l,type:"snapshot",size:o.length}),this.#r.set(t,u),i.update(Bn(n)),this.#n=!1}async loadSyncState(t,n){const r=[t,"sync-state",n];try{const i=await this.#e.load(r);return i?fm(i):void 0}catch{this.#s(`Error loading sync state for ${t} from ${n}`);return}}async saveSyncState(t,n,r){const i=[t,"sync-state",n];await this.#e.save(i,dm(r))}#c(t,n){const r=this.#t.lastSavedHeads(t).value;if(!r)return!0;const i=Bn(n);return!Lc(Tn(i),Tn(r))}#i(t){if(this.#n)return!1;let n=0,r=0;for(const i of t)i.type==="snapshot"?n+=i.size:r+=i.size;return n<1024||r>=n}}class s_ extends ji{}class sx extends s_{#e;syncDebounceRate=100;#t=[];#r={};#n={};#s={};#o=[];#a;#c=!1;#i;#l;constructor({handle:t,peerId:n,onLoadSyncState:r}){super(),this.#a=n,this.#i=t,this.#l=r??(()=>Promise.resolve(void 0));const i=t.documentId.slice(0,5);this.#e=Ui(`automerge-repo:docsync:${i}`),t.on("change",Zu(()=>this.#f(),this.syncDebounceRate)),t.on("ephemeral-message-outbound",s=>this.#h(s)),(async()=>this.#w())()}get peerStates(){return this.#n}get documentId(){return this.#i.documentId}async #f(){try{await this.#i.whenReady();const t=this.#i.doc();this.#t.forEach(n=>this.#y(n,t))}catch{console.log("sync with peers threw an exception")}}async #h({data:t}){this.#e("broadcastToPeers",this.#t),this.#t.forEach(n=>this.#u(n,t))}#u(t,n){this.#e(`sendEphemeralMessage ->${t}`);const r={type:"ephemeral",targetId:t,documentId:this.#i.documentId,data:n};this.emit("message",r)}#p(t,n){this.#d(t),t in this.#n||(this.#n[t]="unknown");const r=this.#s[t];if(r){n(r);return}let i=this.#r[t];i||(this.#l(t).then(s=>{this.#m(t,s??h1())}).catch(s=>{this.#e(`Error loading sync state for ${t}: ${s}`)}),i=this.#r[t]=[]),i.push(n)}#d(t){this.#t.includes(t)||(this.#t.push(t),this.emit("open-doc",{documentId:this.documentId,peerId:t}))}#m(t,n){const r=this.#r[t];if(r)for(const i of r)i(n);delete this.#r[t],this.#s[t]=n}#g(t,n){this.#s[t]=n,this.emit("sync-state",{peerId:t,syncState:n,documentId:this.#i.documentId})}#y(t,n){this.#e(`sendSyncMessage ->${t}`),this.#p(t,r=>{const i=performance.now(),[s,o]=d1(n,r),a=performance.now();if(this.emit("metrics",{type:"generate-sync-message",documentId:this.#i.documentId,durationMillis:a-i,forPeer:t}),this.#g(t,s),o){const c=Bn(n).length===0;!this.#i.isReady()&&c&&s.sharedHeads.length===0&&!Object.values(this.#n).includes("has")&&this.#n[t]==="unknown"?this.emit("message",{type:"request",targetId:t,documentId:this.#i.documentId,data:o}):this.emit("message",{type:"sync",targetId:t,data:o,documentId:this.#i.documentId}),c||(this.#n[t]="has")}})}hasPeer(t){return this.#t.includes(t)}async beginSync(t){this.#i.whenReady([yr,ca,On]).then(()=>{this.#c=!0,this.#_()}).catch(r=>{console.log("caught whenready",r),this.#c=!0,this.#_()}),this.#t.some(r=>this.#n[r]=="has")&&await this.#i.whenReady(),t.forEach(r=>{this.#p(r,i=>{const s=fm(dm(i));this.#g(r,s),this.#i.whenReady([yr,ca,On]).then(()=>{const o=this.#i.isReady()?this.#i.doc():Hn(),a=t.every(l=>this.#n[l]in["unavailable","wants"]);o===void 0&&a||this.#y(r,o??Hn())}).catch(o=>{this.#e(`Error loading doc for ${r}: ${o}`)})})})}endSync(t){this.#e(`removing peer ${t}`),this.#t=this.#t.filter(n=>n!==t),delete this.#n[t],this.#_()}receiveMessage(t){switch(t.type){case"sync":case"request":this.receiveSyncMessage(t);break;case"ephemeral":this.receiveEphemeralMessage(t);break;case"doc-unavailable":this.#n[t.senderId]="unavailable",this.#_();break;default:throw new Error(`unknown message type: ${t}`)}}receiveEphemeralMessage(t){if(t.documentId!==this.#i.documentId)throw new Error("channelId doesn't match documentId");const{senderId:n,data:r}=t,i=S2(new Uint8Array(r));this.#i.emit("ephemeral-message",{handle:this.#i,senderId:n,message:i}),this.#t.forEach(s=>{s!==n&&this.emit("message",{...t,targetId:s})})}receiveSyncMessage(t){if(t.documentId!==this.#i.documentId)throw new Error("channelId doesn't match documentId");if(!this.#i.inState([yr,ca,On])){this.#o.push({message:t,received:new Date});return}this.#w(),this.#b(t)}#b(t){t_(t)&&(this.#n[t.senderId]="wants"),this.#_(),g1(t.data).heads.length>0&&(this.#n[t.senderId]="has"),this.#p(t.senderId,n=>{this.#i.update(r=>{const i=performance.now(),[s,o]=f1(r,n,t.data),a=performance.now();return this.emit("metrics",{type:"receive-sync-message",documentId:this.#i.documentId,durationMillis:a-i,fromPeer:t.senderId,...qd(r)}),this.#g(t.senderId,o),this.#y(t.senderId,r),s}),this.#_()})}#_(){this.#c&&this.#i.inState([ca,On])&&this.#t.every(t=>this.#n[t]==="unavailable"||this.#n[t]==="wants")&&(this.#t.filter(t=>this.#n[t]==="wants").forEach(t=>{this.#n[t]="unavailable";const n={type:"doc-unavailable",documentId:this.#i.documentId,targetId:t};this.emit("message",n)}),this.#i.unavailable())}#w(){for(const t of this.#o)this.#b(t.message);this.#o=[]}metrics(){return{peers:this.#t,size:this.#i.metrics()}}}const Hr=Ui("automerge-repo:collectionsync");class ox extends s_{repo;#e=new Set;docSynchronizers={};#t={};#r;#n=new Map;constructor(t,n=[]){super(),this.repo=t,this.#r=n.map(r=>nr(r).documentId)}#s(t){return this.docSynchronizers[t.documentId]||(this.docSynchronizers[t.documentId]=this.#o(t)),this.docSynchronizers[t.documentId]}#o(t){const n=new sx({handle:t,peerId:this.repo.networkSubsystem.peerId,onLoadSyncState:async r=>{if(!this.repo.storageSubsystem)return;const{storageId:i,isEphemeral:s}=this.repo.peerMetadataByPeerId[r]||{};if(!(!i||s))return this.repo.storageSubsystem.loadSyncState(t.documentId,i)}});return n.on("message",r=>this.emit("message",r)),n.on("open-doc",r=>this.emit("open-doc",r)),n.on("sync-state",r=>this.emit("sync-state",r)),n.on("metrics",r=>this.emit("metrics",r)),n}async #a(t){const n=Array.from(this.#e),r=[];for(const i of n)await this.#c(i,t)&&r.push(i);return r}async receiveMessage(t){Hr(`onSyncMessage: ${t.senderId}, ${t.documentId}, ${"data"in t?t.data.byteLength+"bytes":""}`);const n=t.documentId;if(!n)throw new Error("received a message with an invalid documentId");if(this.#r.includes(n)){this.emit("metrics",{type:"doc-denied",documentId:n}),this.emit("message",{type:"doc-unavailable",documentId:n,targetId:t.senderId});return}if((t.type==="request"||t.type==="sync")&&(this.#n.has(n)||this.#n.set(n,new Set),this.#n.get(n)?.add(t.senderId)),!await this.repo.shareConfig.access(t.senderId,n)){Hr("access denied"),this.emit("message",{type:"doc-unavailable",documentId:n,targetId:t.senderId});return}this.#t[n]=!0;const i=await this.repo.find(n,{allowableStates:["ready","unavailable","requesting"]}),s=this.#s(i);s.receiveMessage(t);const o=await this.#a(n);s.beginSync(o.filter(a=>!s.hasPeer(a)))}addDocument(t){if(this.#t[t.documentId])return;this.#t[t.documentId]=!0;const n=this.#s(t);this.#a(t.documentId).then(r=>{n.beginSync(r)})}removeDocument(t){Hr(`removing document ${t}`);const n=this.docSynchronizers[t];n!==void 0&&this.peers.forEach(r=>n.endSync(r)),delete this.docSynchronizers[t],delete this.#t[t]}addPeer(t){if(Hr(`adding ${t} & synchronizing with them`),!this.#e.has(t)){this.#e.add(t);for(const n of Object.values(this.docSynchronizers)){const{documentId:r}=n;this.#c(t,r).then(i=>{i&&n.beginSync([t])})}}}removePeer(t){Hr(`removing peer ${t}`),this.#e.delete(t);for(const n of this.#n.values())n.delete(t);for(const n of Object.values(this.docSynchronizers))n.endSync(t)}get peers(){return Array.from(this.#e)}async reevaluateDocumentShare(){const t=Array.from(this.#e),n=[];for(const r of Object.values(this.docSynchronizers)){const i=r.documentId;n.push((async()=>{for(const s of t){const o=await this.#c(s,i),a=r.hasPeer(s);Hr(`reevaluateDocumentShare: ${s} for ${i}, shouldShare: ${o}, isAlreadySyncing: ${a}`),o&&!a?(Hr(`reevaluateDocumentShare: starting sync with ${s} for ${i}`),r.beginSync([s])):!o&&a&&(Hr(`reevaluateDocumentShare: stopping sync with ${s} for ${i}`),r.endSync(s))}})().catch(s=>{console.log(`error reevaluating document share for ${i}: ${s}`)}))}await Promise.allSettled(n)}metrics(){return Object.fromEntries(Object.entries(this.docSynchronizers).map(([t,n])=>[t,n.metrics()]))}async #c(t,n){const[r,i]=await Promise.all([this.repo.shareConfig.announce(t,n),this.repo.shareConfig.access(t,n)]),s=this.#n.get(n)?.has(t)??!1;return r||i&&s}}const Nt="AUTOMERGE_REF_KIND",ax="AUTOMERGE_REF_CURSOR_MARKER",cx="automerge:",Ra="\\",ua="%5C",o_="@",Fa="[",Pl="]",bg="-",wg=[Ra,o_,"{",Fa],vg=/^@(\d+)$/,lx={kind:"index",match:e=>vg.test(e),parse:e=>{const t=e.match(vg);if(!t)throw new Error(`Invalid index: ${e}`);return{[Nt]:"index",index:parseInt(t[1],10)}},serialize:e=>`${o_}${e.index}`},ux={kind:"match",match:e=>e.startsWith("{")||e.startsWith("%7B"),parse:e=>{try{const t=decodeURIComponent(e),n=JSON.parse(t);if(typeof n!="object"||n===null||Array.isArray(n))throw new Error("Match pattern must be a plain object");return{[Nt]:"match",match:n}}catch(t){throw new Error(`Invalid match pattern: ${e}. ${t instanceof Error?t.message:""}`)}},serialize:e=>encodeURIComponent(JSON.stringify(e.match))},dx={kind:"cursors",match:e=>e.startsWith(Fa)&&e.endsWith(Pl),parse:e=>{const t=e.slice(1,-1);if(!t)throw new Error("Invalid cursor range: empty brackets");const n=t.indexOf(bg);if(n===-1){const s=t;return{[Nt]:"cursors",start:s,end:s}}const r=t.slice(0,n),i=t.slice(n+1);if(!r||!i)throw new Error(`Invalid cursor range: ${e}. Expected format: [cursor] or [start-end]`);return{[Nt]:"cursors",start:r,end:i}},serialize:e=>e.start===e.end?`${Fa}${e.start}${Pl}`:`${Fa}${e.start}${bg}${e.end}${Pl}`},fx={kind:"key",match:e=>{if(e.startsWith(ua)||e.startsWith(Ra))return!0;const t=hx(e);return!wg.some(n=>e.startsWith(n)||t.startsWith(n))},parse:e=>e.startsWith(ua)?{[Nt]:"key",key:decodeURIComponent(e.slice(ua.length))}:e.startsWith(Ra)?{[Nt]:"key",key:decodeURIComponent(e.slice(Ra.length))}:{[Nt]:"key",key:decodeURIComponent(e)},serialize:e=>{const t=wg.some(r=>e.key.startsWith(r)),n=encodeURIComponent(e.key);return t?`${ua}${n}`:n}};function hx(e){try{return decodeURIComponent(e)}catch{return e}}const gx=[lx,ux,dx,fx];function px(e){for(const t of gx)if(e[Nt]===t.kind)return t.serialize(e);throw new Error(`No codec found for segment kind: ${e[Nt]}`)}function mx(e){return e.map(px).join("/")}function _x(e){return e.length>0?`#${e.join("|")}`:""}function yx(e,t,n){const r=mx(t),i=n?_x(n):"";return`${cx}${e}/${r}${i}`}function df(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function a_(e){return df(e)&&Nt in e}function c_(e){return df(e)&&ax in e}function bx(e){return df(e)&&!a_(e)&&!c_(e)}function xg(e,t){return Object.entries(t).every(([n,r])=>e[n]===r)}function wx(e,t,n){const r={splice(i,s,o){gm(e,t,i,s,o)},updateText(i){b1(e,t,i)}};return new Proxy(r,{get(i,s){if(s in i)return i[s];const a=n[s];return typeof a=="function"?a.bind(n):a},getPrototypeOf(){return String.prototype}})}const vx=new FinalizationRegistry(e=>e());class xx{docHandle;path;range;#e=new Set;#t;constructor(t,n){this.docHandle=t;const r=t.doc(),{path:i,range:s}=this.#s(r,n);this.path=i,this.range=s,this.#t=()=>{const o=this.docHandle.doc();this.#c(o)},this.docHandle.on("change",this.#t),vx.register(this,()=>this.#r(),this)}#r(){this.docHandle.off("change",this.#t);for(const t of this.#e)this.docHandle.off("change",t);this.#e.clear()}get rangePositions(){if(!this.range)return;const t=this.#h();if(!t)return;const n=this.doc();return this.#g(n,t,this.range)}viewAt(t){return this.docHandle.view(Tn(t)).ref(...this.path)}value(){const t=this.doc(),n=this.#h();if(!n)return;const r=this.#u(t,n);return this.range?this.#p(t,n,r,this.range):r}doc(){return this.docHandle.doc()}change(t){if(this.docHandle.isReadOnly())throw new Error("Cannot change a Ref on a read-only handle");const n=typeof t=="function"?t:()=>t;this.docHandle.change(r=>{if(this.path.length===0&&!this.range){n(r);return}const i=this.#h();if(!i)throw new Error("Cannot resolve path");let s;if(this.range){const c=this.#u(r,i);if(typeof c!="string")throw new Error("Range refs can only be used on string values");s=this.#p(r,i,c,this.range)}else s=this.#u(r,i);const o=typeof s=="string"?wx(r,i,s):s,a=n(o);a!==void 0&&(a===null||typeof a=="string"||typeof a=="number"||typeof a=="boolean"||typeof a=="bigint"||console.warn("Ref.change() returned a non-primitive value. For objects and arrays, you should mutate them in place rather than returning a new instance. Returning new instances loses granular change tracking."),this.range?this.#m(r,i,this.range,a):this.#d(r,i,a))})}remove(){if(this.docHandle.isReadOnly())throw new Error("Cannot remove from a Ref on a read-only handle");if(this.path.length===0&&!this.range)throw new Error("Cannot remove the root document");this.docHandle.change(t=>{const n=this.#h();if(!n||n.length===0)throw new Error("Cannot resolve path for removal");if(this.range){this.#m(t,n,this.range,"");return}const r=n.slice(0,-1),i=n[n.length-1],s=r.length===0?t:this.#u(t,r);if(s==null)throw new Error("Cannot remove: parent is null or undefined");if(Array.isArray(s)){if(typeof i!="number")throw new Error("Cannot remove from array: key is not a number");s.splice(i,1)}else delete s[i]})}onChange(t){const n=i=>{if(this.#y(i.patches)){const s=this.value();t(s,i)}};return this.docHandle.on("change",n),this.#e.add(n),()=>{this.docHandle.off("change",n),this.#e.delete(n)}}get url(){const t=this.range?[...this.path,this.range]:this.path,n=this.docHandle.isReadOnly()?Wr(this.docHandle.heads()):void 0;return yx(this.docHandle.documentId,t,n)}equals(t){return this.url===t.url}contains(t){if(this.docHandle.documentId!==t.docHandle.documentId||this.docHandle.url!==t.docHandle.url||this.path.length>=t.path.length)return!1;for(let n=0;n<this.path.length;n++)if(!this.#i(this.path[n],t.path[n]))return!1;return!0}isChildOf(t){if(this.docHandle.documentId!==t.docHandle.documentId||this.docHandle.url!==t.docHandle.url||this.path.length<t.path.length)return!1;for(let n=0;n<t.path.length;n++)if(!this.#i(this.path[n],t.path[n]))return!1;return this.path.length===t.path.length?this.range!==void 0&&t.range===void 0:this.path.length===t.path.length+1}overlaps(t){if(this.docHandle.documentId!==t.docHandle.documentId||this.docHandle.url!==t.docHandle.url||!this.range||!t.range||this.path.length!==t.path.length)return!1;for(let f=0;f<this.path.length;f++)if(!this.#i(this.path[f],t.path[f]))return!1;const n=this.doc(),r=this.#h();if(!r)return!1;const i=this.#g(n,r,this.range),s=this.#g(n,r,t.range);if(!i||!s)return!1;const[o,a]=i,[c,l]=s;return o<l&&c<a}isEquivalent(t){if(this===t)return!0;if(this.docHandle.documentId!==t.docHandle.documentId||!this.#n(t)||this.path.length!==t.path.length||this.range===void 0!=(t.range===void 0))return!1;let n=!0;for(let r=0;r<this.path.length;r++)if(!this.#i(this.path[r],t.path[r])){n=!1;break}if(n)return!this.range&&!t.range?!0:this.range.start===t.range.start&&this.range.end===t.range.end;for(let r=0;r<this.path.length;r++){const i=this.path[r].prop,s=t.path[r].prop;if(i===void 0||s===void 0||i!==s)return!1}return!this.range&&!t.range?!0:this.range.start===t.range.start&&this.range.end===t.range.end}valueOf(){return this.url}toString(){return this.url}#n(t){if(this.docHandle.url===t.docHandle.url)return!0;const n=this.docHandle.heads().join(","),r=t.docHandle.heads().join(",");return n===r}#s(t,n){const r=[],i=[];let s=t,o;for(let a=0;a<n.length;a++){const c=n[a];if(c_(c)){if(a<n.length-1)throw new Error("cursor() must be the last segment in a ref path. Segments after cursor() are not allowed.");o=this.#f(t,i,s,c);break}const l=a_(c)?this.#o(s,c):this.#l(s,c);if(l[Nt]==="cursors"){if(a<n.length-1)throw new Error("Cursor range must be the last segment in a ref path. Segments after cursor range are not allowed.");o=l;break}r.push(l),l.prop!==void 0&&s!==void 0&&s!==null&&(i.push(l.prop),s=s[l.prop])}return{path:r,range:o}}#o(t,n){const r=this.#a(t,n);return{...n,prop:r}}#a(t,n){if(t!=null)switch(n[Nt]){case"key":return n.key;case"index":return n.index;case"match":{if(!Array.isArray(t))return;const r=t.findIndex(i=>xg(i,n.match));return r!==-1?r:void 0}case"cursors":return;default:return}}#c(t){let n=t;for(const r of this.path){const i=this.#a(n,r);if(r.prop=i,i!==void 0&&n!==void 0&&n!==null)n=n[i];else break}}#i(t,n){if(t[Nt]!==n[Nt])return!1;switch(t[Nt]){case"key":return t.key===n.key;case"index":return t.index===n.index;case"match":{const r=Object.keys(t.match),i=Object.keys(n.match);return r.length!==i.length?!1:r.every(s=>t.match[s]===n.match[s])}default:return!1}}#l(t,n){if(typeof n=="string")return{[Nt]:"key",key:n,prop:n};if(typeof n=="number")return{[Nt]:"index",index:n,prop:n};if(bx(n)){if(!Array.isArray(t))return{[Nt]:"match",match:n,prop:void 0};const r=t.findIndex(i=>xg(i,n));return{[Nt]:"match",match:n,prop:r!==-1?r:void 0}}throw new Error(`Unsupported path input type: ${typeof n}. Expected string, number, or plain object.`)}#f(t,n,r,i){const{start:s,end:o}=i;if(typeof r!="string")throw new Error(`cursor() can only be used on string values, got ${typeof r}`);const a=Oh(t,n,s),c=Oh(t,n,o);if(!a||!c)throw new Error(`Failed to create cursors at positions ${s}-${o}.`);return{[Nt]:"cursors",start:a,end:c}}#h(){const t=[];for(const n of this.path){if(n.prop===void 0)return;t.push(n.prop)}return t}#u(t,n){let r=t;for(const i of n){if(r==null)return;r=r[i]}return r}#p(t,n,r,i){const s=this.#g(t,n,i);if(s)return r.slice(s[0],s[1])}#d(t,n,r){if(n.length===0)throw new Error("Internal error: #setValueAt called with empty path. Root document changes should be handled by the caller.");const i=this.#u(t,n.slice(0,-1));if(i==null)throw new Error("Cannot set value: parent is null or undefined");i[n[n.length-1]]=r}#m(t,n,r,i){const s=this.#g(t,n,r);if(!s)throw new Error("Cannot resolve range positions");const[o,a]=s;gm(t,n,o,a-o,i)}#g(t,n,r){const i=Ph(t,n,r.start),s=Ph(t,n,r.end);return i!==void 0&&s!==void 0?[i,s]:void 0}#y(t){const n=[];for(const r of this.path){if(r.prop===void 0)break;n.push(r.prop)}return n.length===0?!1:t.some(r=>this.#b(r.path,n))}#b(t,n){const r=Math.min(t.length,n.length);return t.slice(0,r).every((i,s)=>i===n[s])}}const Sg=new Promise(()=>{}),Sx=()=>{},Tl=async()=>!0;function $x(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}const kx=e=>{for(const t in e)if(Object.hasOwn(e,t))return!0;return!1};function Ex(){return"peer-"+Math.random().toString(36).slice(4)}class Ax extends ji{#e;networkSubsystem;storageSubsystem;#t;#r;#n={};synchronizer;#s={announce:Tl,access:Tl};peerMetadataByPeerId={};#o=new H2;#a=!1;#c={};#i={};#l;constructor({storage:t,network:n=[],peerId:r=Ex(),sharePolicy:i,shareConfig:s,isEphemeral:o=t===void 0,enableRemoteHeadsGossiping:a=!1,denylist:c=[],saveDebounceRate:l=100,idFactory:f}={}){if(super(),this.#a=a,this.#e=Ui("automerge-repo:repo"),this.#l=f||null,i!=null&&s!=null)throw new Error("cannot provide both sharePolicy and shareConfig at once");i&&(this.#s={announce:i,access:Tl}),s&&(this.#s=s),this.on("delete-document",({documentId:g})=>{this.synchronizer.removeDocument(g),u&&u.removeDoc(g).catch(p=>{this.#e("error deleting document",{documentId:g,err:p})})}),this.synchronizer=new ox(this,c),this.synchronizer.on("message",g=>{this.#e(`sending ${g.type} message to ${g.targetId}`),d.send(g)}),this.synchronizer.on("metrics",g=>this.emit("doc-metrics",g)),this.#a&&this.synchronizer.on("open-doc",({peerId:g,documentId:p})=>{this.#o.subscribePeerToDoc(g,p)});const u=t?new ix(t):void 0;u&&(u.on("document-loaded",g=>this.emit("doc-metrics",{type:"doc-loaded",...g})),u.on("doc-compacted",g=>this.emit("doc-metrics",{type:"doc-compacted",...g})),u.on("doc-saved",g=>this.emit("doc-metrics",{type:"doc-saved",...g}))),this.storageSubsystem=u,this.#t=l,this.storageSubsystem?this.#r=({handle:g,doc:p})=>{let m=this.#i[g.documentId];m||(m=this.#i[g.documentId]=Zu(({doc:b,handle:x})=>this.storageSubsystem.saveDoc(x.documentId,b),this.#t)),m({handle:g,doc:p})}:this.#r=Sx;const h=(async()=>({storageId:await u?.id(),isEphemeral:o}))(),d=new G2(n,r,h);this.networkSubsystem=d,d.on("peer",async({peerId:g,peerMetadata:p})=>{this.#e("peer connected",{peerId:g}),p&&(this.peerMetadataByPeerId[g]={...p}),this.#s.announce(g).then(m=>{m&&this.#a&&this.#o.addGenerousPeer(g)}).catch(m=>{console.log("error in share policy",{err:m})}),this.synchronizer.addPeer(g)}),d.on("peer-disconnected",({peerId:g})=>{this.synchronizer.removePeer(g),this.#o.removePeer(g)}),d.on("message",async g=>{this.#h(g)}),this.synchronizer.on("sync-state",g=>{this.#p(g);const p=this.#n[g.documentId],{storageId:m}=this.peerMetadataByPeerId[g.peerId]||{};if(!m)return;const b=p.getSyncInfo(m)?.lastHeads;g.syncState.theirHeads&&(!b||!Lc(b,Tn(g.syncState.theirHeads)))&&g.syncState.theirHeads&&(p.setSyncInfo(m,{lastHeads:Tn(g.syncState.theirHeads),lastSyncTimestamp:Date.now()}),m&&this.#a&&this.#o.handleImmediateRemoteHeadsChanged(g.documentId,m,Tn(g.syncState.theirHeads)))}),this.#a&&(this.#o.on("notify-remote-heads",g=>{this.networkSubsystem.send({type:"remote-heads-changed",targetId:g.targetId,documentId:g.documentId,newHeads:{[g.storageId]:{heads:g.heads,timestamp:g.timestamp}}})}),this.#o.on("change-remote-subs",g=>{this.#e("change-remote-subs",g);for(const p of g.peers)this.networkSubsystem.send({type:"remote-subscription-change",targetId:p,add:g.add,remove:g.remove})}),this.#o.on("remote-heads-changed",({documentId:g,storageId:p,remoteHeads:m,timestamp:b})=>{this.#n[g].setSyncInfo(p,{lastHeads:m,lastSyncTimestamp:b})}))}#f(t){this.storageSubsystem&&(t.listeners("heads-changed").some(r=>r===this.#r)||t.on("heads-changed",this.#r)),this.synchronizer.addDocument(t)}#h(t){switch(t.type){case"remote-subscription-change":this.#a&&this.#o.handleControlMessage(t);break;case"remote-heads-changed":this.#a&&this.#o.handleRemoteHeads(t);break;case"sync":case"request":case"ephemeral":case"doc-unavailable":this.synchronizer.receiveMessage(t).catch(n=>{console.log("error receiving message",{err:n,message:t})})}}#u={};#p(t){if(!this.storageSubsystem)return;const{storageId:n,isEphemeral:r}=this.peerMetadataByPeerId[t.peerId]||{};if(!n||r)return;let i=this.#u[n];i||(i=this.#u[n]=Zu(({documentId:s,syncState:o})=>this.storageSubsystem.saveSyncState(s,n,o),this.#t)),i(t)}#d({documentId:t}){if(this.#n[t])return this.#n[t];if(!t)throw new Error(`Invalid documentId ${t}`);const n=new fc(t,(r,i)=>new xx(r,i));return this.#n[t]=n,n}get handles(){return this.#n}get peers(){return this.synchronizer.peers}get peerId(){return this.networkSubsystem.peerId}get sharePolicy(){return this.#s.announce}set sharePolicy(t){this.#s.announce=t}get shareConfig(){return this.#s}set shareConfig(t){this.#s=t}getStorageIdOfPeer(t){return this.peerMetadataByPeerId[t]?.storageId}create(t){let n;$x(t)&&kx(t)?n=Eh(t):n=Ah(Hn());const{documentId:r}=nr(rg()),i=this.#d({documentId:r});return this.#f(i),i.update(()=>n),i.doneLoading(),i}async create2(t){let n;t?n=Eh(t):n=Ah(Hn());let{documentId:r}=nr(rg());if(this.#l){const s=await this.#l(Bn(n));r=xo(s)}const i=this.#d({documentId:r});return this.#f(i),i.update(()=>n),i.doneLoading(),i}clone(t){if(!t.isReady())throw new Error(`Cloned handle is not yet in ready state.
|
|
4
|
+
(Try await handle.whenReady() first.)`);const n=t.doc(),r=this.create();return r.update(()=>ic(n)),r}findWithProgress(t,n={}){const{signal:r}=n,{documentId:i,heads:s}=Hm(t)?nr(t):{documentId:sa(t),heads:void 0};if(this.#n[i]){const u=this.#n[i];if(u.state===On)return{state:"unavailable",error:new Error(`Document ${t} is unavailable`),handle:u};if(u.state===la)return{state:"failed",error:new Error(`Document ${t} was deleted`),handle:u};if(u.state===yr)return{state:"ready",handle:s?u.view(s):u}}const o=this.#c[i];if(o){const u=this.#n[i];if(u&&(u.state===yr||u.state===On||u.state===la||u.state==="loading"))return o}const a=this.#d({documentId:i}),c={state:"loading",progress:0,handle:a},l={subscribers:new Set,currentProgress:void 0,notify:u=>{l.currentProgress=u,l.subscribers.forEach(h=>h(u)),this.#c[i]=u},peek:()=>l.currentProgress||c,subscribe:u=>(l.subscribers.add(u),()=>l.subscribers.delete(u))};l.notify(c),this.#m(t,i,a,l,r?pg(Sg,r):Sg);const f={...c,peek:l.peek,subscribe:l.subscribe};return this.#c[i]=f,f}async #m(t,n,r,i,s){try{i.notify({state:"loading",progress:25,handle:r});const o=await (this.storageSubsystem?this.storageSubsystem.loadDoc(r.documentId):Promise.resolve(null)),a=await Promise.race([o,s]);if(a?(r.update(()=>a),r.doneLoading(),i.notify({state:"loading",progress:50,handle:r})):(await Promise.race([this.networkSubsystem.whenReady(),s]),r.request(),i.notify({state:"loading",progress:75,handle:r})),this.#f(r),await Promise.race([r.whenReady([yr,On]),s]),r.state===On){const c={state:"unavailable",handle:r};i.notify(c);return}if(r.state===la)throw new Error(`Document ${t} was deleted`);i.notify({state:"ready",handle:r})}catch(o){i.notify({state:"failed",error:o instanceof Error||o instanceof DOMException?o:new Error(String(o)),handle:this.#d({documentId:n})})}}async find(t,n={}){const{allowableStates:r=["ready"],signal:i}=n;if(i?.aborted)throw new Nc;const s=this.findWithProgress(t,{signal:i});if("subscribe"in s)return this.#f(s.handle),new Promise((o,a)=>{const c=s.subscribe(l=>{r.includes(l.handle.state)?(c(),o(l.handle)):l.state==="unavailable"?(c(),a(new Error(`Document ${t} is unavailable`))):l.state==="failed"&&(c(),a(l.error))})});if(s.handle.state===yr)return s.handle;if(await s.handle.whenReady([yr,On]),s.handle.state==="unavailable"&&!r.includes(On))throw new Error(`Document ${t} is unavailable`);return s.handle}async #g(t){if(this.#n[t])return this.#n[t];const n=this.#d({documentId:t}),r=await (this.storageSubsystem?this.storageSubsystem.loadDoc(n.documentId):Promise.resolve(null));return r?(n.update(()=>r),n.doneLoading()):(await this.networkSubsystem.whenReady(),n.request()),this.#f(n),n}async findClassic(t,n={}){const r=sa(t),{allowableStates:i,signal:s}=n;return pg((async()=>{const o=await this.#g(r);if(!i&&(await o.whenReady([yr,On]),o.state===On&&!s?.aborted))throw new Error(`Document ${t} is unavailable`);return o})(),s)}delete(t){const n=sa(t);this.#d({documentId:n}).delete(),delete this.#n[n],delete this.#c[n],delete this.#i[n],this.emit("delete-document",{documentId:n})}async export(t){const n=sa(t),i=(await this.find(n)).doc();return um(i)}import(t,n){const r=n?.docId;if(r!=null){const i=this.#d({documentId:r});return i.update(s=>Wd(s,t)),this.#f(i),i}else{const i=l1(t),s=this.create();return s.update(()=>ic(i)),s}}subscribeToRemotes=t=>{this.#a?(this.#e("subscribeToRemotes",{remotes:t}),this.#o.subscribeToRemotes(t)):this.#e("WARN: subscribeToRemotes called but remote heads gossiping is not enabled")};storageId=async()=>{if(this.storageSubsystem)return this.storageSubsystem.id()};async flush(t){if(!this.storageSubsystem)return;const n=t?t.map(r=>this.#n[r]):Object.values(this.#n);await Promise.all(n.map(async r=>this.storageSubsystem.saveDoc(r.documentId,r.doc())))}async removeFromCache(t){if(!this.#n[t]){this.#e(`WARN: removeFromCache called but handle not found in handleCache for documentId: ${t}`);return}const n=this.#d({documentId:t});await n.whenReady([yr,F2,la,On]),n.doc()?(n.isReady()?n.unload():this.#e(`WARN: removeFromCache called but handle for documentId: ${t} in unexpected state: ${n.state}`),delete this.#n[t],delete this.#c[t],delete this.#i[t],this.synchronizer.removeDocument(t)):this.#e(`WARN: removeFromCache called but doc undefined for documentId: ${t}`)}shutdown(){return this.networkSubsystem.adapters.forEach(t=>{t.disconnect()}),this.flush()}metrics(){return{documents:this.synchronizer.metrics()}}shareConfigChanged(){this.synchronizer.reevaluateDocumentShare()}}let Ix=class extends ji{peerId;peerMetadata};let Cx;Cx="/assets/automerge_wasm_bg-Cik4BF9l.wasm";l_=async(e={},t)=>{let n;if(t.startsWith("data:")){const r=t.replace(/^data:.*?base64,/,"");let i;if(typeof Buffer=="function"&&typeof Buffer.from=="function")i=Buffer.from(r,"base64");else if(typeof atob=="function"){const s=atob(r);i=new Uint8Array(s.length);for(let o=0;o<s.length;o++)i[o]=s.charCodeAt(o)}else throw new Error("Cannot decode base64-encoded data URL");n=await WebAssembly.instantiate(i,e)}else{const r=await fetch(t),i=r.headers.get("Content-Type")||"";if("instantiateStreaming"in WebAssembly&&i.startsWith("application/wasm"))n=await WebAssembly.instantiateStreaming(r,e);else{const s=await r.arrayBuffer();n=await WebAssembly.instantiate(s,e)}}return n.instance.exports};class Mn{static __wrap(t){t=t>>>0;const n=Object.create(Mn.prototype);return n.__wbg_ptr=t,$g.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,$g.unregister(this),t}free(){const t=this.__destroy_into_raw();ne.__wbg_automerge_free(t,0)}applyAndReturnPatches(t,n){const r=ne.automerge_applyAndReturnPatches(this.__wbg_ptr,t,n);if(r[2])throw pe(r[1]);return pe(r[0])}applyChanges(t){const n=ne.automerge_applyChanges(this.__wbg_ptr,t);if(n[1])throw pe(n[0])}applyPatches(t,n){const r=ne.automerge_applyPatches(this.__wbg_ptr,t,n);if(r[2])throw pe(r[1]);return pe(r[0])}clone(t){var n=wn(t)?0:er(t,ne.__wbindgen_malloc,ne.__wbindgen_realloc),r=Dn;const i=ne.automerge_clone(this.__wbg_ptr,n,r);if(i[2])throw pe(i[1]);return Mn.__wrap(i[0])}commit(t,n){var r=wn(t)?0:er(t,ne.__wbindgen_malloc,ne.__wbindgen_realloc),i=Dn;return ne.automerge_commit(this.__wbg_ptr,r,i,!wn(n),wn(n)?0:n)}delete(t,n){const r=ne.automerge_delete(this.__wbg_ptr,t,n);if(r[1])throw pe(r[0])}diff(t,n){const r=ne.automerge_diff(this.__wbg_ptr,t,n);if(r[2])throw pe(r[1]);return pe(r[0])}diffIncremental(){const t=ne.automerge_diffIncremental(this.__wbg_ptr);if(t[2])throw pe(t[1]);return pe(t[0])}diffPath(t,n,r,i){const s=ne.automerge_diffPath(this.__wbg_ptr,t,n,r,i);if(s[2])throw pe(s[1]);return pe(s[0])}dump(){ne.automerge_dump(this.__wbg_ptr)}emptyChange(t,n){var r=wn(t)?0:er(t,ne.__wbindgen_malloc,ne.__wbindgen_realloc),i=Dn;return ne.automerge_emptyChange(this.__wbg_ptr,r,i,!wn(n),wn(n)?0:n)}enableFreeze(t){const n=ne.automerge_enableFreeze(this.__wbg_ptr,t);if(n[2])throw pe(n[1]);return n[0]!==0}fork(t,n){var r=wn(t)?0:er(t,ne.__wbindgen_malloc,ne.__wbindgen_realloc),i=Dn;const s=ne.automerge_fork(this.__wbg_ptr,r,i,n);if(s[2])throw pe(s[1]);return Mn.__wrap(s[0])}generateSyncMessage(t){return xi(t,rr),ne.automerge_generateSyncMessage(this.__wbg_ptr,t.__wbg_ptr)}get(t,n,r){const i=ne.automerge_get(this.__wbg_ptr,t,n,r);if(i[2])throw pe(i[1]);return pe(i[0])}getActorId(){let t,n;try{const r=ne.automerge_getActorId(this.__wbg_ptr);return t=r[0],n=r[1],Zn(r[0],r[1])}finally{ne.__wbindgen_free(t,n,1)}}getAll(t,n,r){const i=ne.automerge_getAll(this.__wbg_ptr,t,n,r);if(i[2])throw pe(i[1]);return pe(i[0])}getBlock(t,n,r){const i=ne.automerge_getBlock(this.__wbg_ptr,t,n,r);if(i[2])throw pe(i[1]);return pe(i[0])}getChangeByHash(t){const n=ne.automerge_getChangeByHash(this.__wbg_ptr,t);if(n[2])throw pe(n[1]);return pe(n[0])}getChangeMetaByHash(t){const n=ne.automerge_getChangeMetaByHash(this.__wbg_ptr,t);if(n[2])throw pe(n[1]);return pe(n[0])}getChanges(t){const n=ne.automerge_getChanges(this.__wbg_ptr,t);if(n[2])throw pe(n[1]);return pe(n[0])}getChangesAdded(t){return xi(t,Mn),ne.automerge_getChangesAdded(this.__wbg_ptr,t.__wbg_ptr)}getChangesMeta(t){const n=ne.automerge_getChangesMeta(this.__wbg_ptr,t);if(n[2])throw pe(n[1]);return pe(n[0])}getCursor(t,n,r,i){let s,o;try{const l=ne.automerge_getCursor(this.__wbg_ptr,t,n,r,i);var a=l[0],c=l[1];if(l[3])throw a=0,c=0,pe(l[2]);return s=a,o=c,Zn(a,c)}finally{ne.__wbindgen_free(s,o,1)}}getCursorPosition(t,n,r){const i=ne.automerge_getCursorPosition(this.__wbg_ptr,t,n,r);if(i[2])throw pe(i[1]);return i[0]}getDecodedChangeByHash(t){const n=ne.automerge_getDecodedChangeByHash(this.__wbg_ptr,t);if(n[2])throw pe(n[1]);return pe(n[0])}getHeads(){return ne.automerge_getHeads(this.__wbg_ptr)}getLastLocalChange(){return ne.automerge_getLastLocalChange(this.__wbg_ptr)}getMissingDeps(t){const n=ne.automerge_getMissingDeps(this.__wbg_ptr,t);if(n[2])throw pe(n[1]);return pe(n[0])}getWithType(t,n,r){const i=ne.automerge_getWithType(this.__wbg_ptr,t,n,r);if(i[2])throw pe(i[1]);return pe(i[0])}hasOurChanges(t){return xi(t,rr),ne.automerge_hasOurChanges(this.__wbg_ptr,t.__wbg_ptr)!==0}increment(t,n,r){const i=ne.automerge_increment(this.__wbg_ptr,t,n,r);if(i[1])throw pe(i[0])}initRootFromHydrate(t){const n=ne.automerge_initRootFromHydrate(this.__wbg_ptr,t);if(n[1])throw pe(n[0])}insert(t,n,r,i){const s=ne.automerge_insert(this.__wbg_ptr,t,n,r,i);if(s[1])throw pe(s[0])}insertObject(t,n,r){let i,s;try{const c=ne.automerge_insertObject(this.__wbg_ptr,t,n,r);var o=c[0],a=c[1];if(c[3])throw o=0,a=0,pe(c[2]);return i=o,s=a,Zn(o,a)}finally{ne.__wbindgen_free(i,s,1)}}insertObjectFromHydrate(t,n,r){const i=ne.automerge_insertObjectFromHydrate(this.__wbg_ptr,t,n,r);if(i[2])throw pe(i[1]);return pe(i[0])}integrate(){ne.automerge_integrate(this.__wbg_ptr)}isolate(t){const n=ne.automerge_isolate(this.__wbg_ptr,t);if(n[1])throw pe(n[0])}joinBlock(t,n){const r=ne.automerge_joinBlock(this.__wbg_ptr,t,n);if(r[1])throw pe(r[0])}keys(t,n){const r=ne.automerge_keys(this.__wbg_ptr,t,n);if(r[2])throw pe(r[1]);return pe(r[0])}length(t,n){const r=ne.automerge_length(this.__wbg_ptr,t,n);if(r[2])throw pe(r[1]);return r[0]}loadIncremental(t){const n=ne.automerge_loadIncremental(this.__wbg_ptr,t);if(n[2])throw pe(n[1]);return n[0]}mark(t,n,r,i,s){const o=ne.automerge_mark(this.__wbg_ptr,t,n,r,i,s);if(o[1])throw pe(o[0])}marks(t,n){const r=ne.automerge_marks(this.__wbg_ptr,t,n);if(r[2])throw pe(r[1]);return pe(r[0])}marksAt(t,n,r){const i=ne.automerge_marksAt(this.__wbg_ptr,t,n,r);if(i[2])throw pe(i[1]);return pe(i[0])}materialize(t,n,r){const i=ne.automerge_materialize(this.__wbg_ptr,t,n,r);if(i[2])throw pe(i[1]);return pe(i[0])}merge(t){xi(t,Mn);const n=ne.automerge_merge(this.__wbg_ptr,t.__wbg_ptr);if(n[2])throw pe(n[1]);return pe(n[0])}static new(t){var n=wn(t)?0:er(t,ne.__wbindgen_malloc,ne.__wbindgen_realloc),r=Dn;const i=ne.automerge_new(n,r);if(i[2])throw pe(i[1]);return Mn.__wrap(i[0])}objInfo(t,n){const r=ne.automerge_objInfo(this.__wbg_ptr,t,n);if(r[2])throw pe(r[1]);return pe(r[0])}pendingOps(){return ne.automerge_pendingOps(this.__wbg_ptr)}push(t,n,r){const i=ne.automerge_push(this.__wbg_ptr,t,n,r);if(i[1])throw pe(i[0])}pushObject(t,n){let r,i;try{const a=ne.automerge_pushObject(this.__wbg_ptr,t,n);var s=a[0],o=a[1];if(a[3])throw s=0,o=0,pe(a[2]);return r=s,i=o,Zn(s,o)}finally{ne.__wbindgen_free(r,i,1)}}put(t,n,r,i){const s=ne.automerge_put(this.__wbg_ptr,t,n,r,i);if(s[1])throw pe(s[0])}putObject(t,n,r){const i=ne.automerge_putObject(this.__wbg_ptr,t,n,r);if(i[2])throw pe(i[1]);return pe(i[0])}putObjectFromHydrate(t,n,r){const i=ne.automerge_putObjectFromHydrate(this.__wbg_ptr,t,n,r);if(i[2])throw pe(i[1]);return pe(i[0])}receiveSyncMessage(t,n){xi(t,rr);const r=ne.automerge_receiveSyncMessage(this.__wbg_ptr,t.__wbg_ptr,n);if(r[1])throw pe(r[0])}registerDatatype(t,n,r){const i=ne.automerge_registerDatatype(this.__wbg_ptr,t,n,r);if(i[1])throw pe(i[0])}resetDiffCursor(){ne.automerge_resetDiffCursor(this.__wbg_ptr)}rollback(){return ne.automerge_rollback(this.__wbg_ptr)}save(){return ne.automerge_save(this.__wbg_ptr)}saveAndVerify(){const t=ne.automerge_saveAndVerify(this.__wbg_ptr);if(t[2])throw pe(t[1]);return pe(t[0])}saveBundle(t){const n=ne.automerge_saveBundle(this.__wbg_ptr,t);if(n[2])throw pe(n[1]);return pe(n[0])}saveIncremental(){return ne.automerge_saveIncremental(this.__wbg_ptr)}saveNoCompress(){return ne.automerge_saveNoCompress(this.__wbg_ptr)}saveSince(t){const n=ne.automerge_saveSince(this.__wbg_ptr,t);if(n[2])throw pe(n[1]);return pe(n[0])}spans(t,n){const r=ne.automerge_spans(this.__wbg_ptr,t,n);if(r[2])throw pe(r[1]);return pe(r[0])}splice(t,n,r,i){const s=ne.automerge_splice(this.__wbg_ptr,t,n,r,i);if(s[1])throw pe(s[0])}spliceFromHydrate(t,n,r,i){const s=ne.automerge_spliceFromHydrate(this.__wbg_ptr,t,n,r,i);if(s[1])throw pe(s[0])}splitBlock(t,n,r){const i=ne.automerge_splitBlock(this.__wbg_ptr,t,n,r);if(i[1])throw pe(i[0])}stats(){return ne.automerge_stats(this.__wbg_ptr)}text(t,n){let r,i;try{const a=ne.automerge_text(this.__wbg_ptr,t,n);var s=a[0],o=a[1];if(a[3])throw s=0,o=0,pe(a[2]);return r=s,i=o,Zn(s,o)}finally{ne.__wbindgen_free(r,i,1)}}toJS(t){const n=ne.automerge_toJS(this.__wbg_ptr,t);if(n[2])throw pe(n[1]);return pe(n[0])}topoHistoryTraversal(){return ne.automerge_topoHistoryTraversal(this.__wbg_ptr)}unmark(t,n,r){const i=ne.automerge_unmark(this.__wbg_ptr,t,n,r);if(i[1])throw pe(i[0])}updateBlock(t,n,r){const i=ne.automerge_updateBlock(this.__wbg_ptr,t,n,r);if(i[1])throw pe(i[0])}updateDiffCursor(){ne.automerge_updateDiffCursor(this.__wbg_ptr)}updateSpans(t,n,r){const i=ne.automerge_updateSpans(this.__wbg_ptr,t,n,r);if(i[1])throw pe(i[0])}updateText(t,n){const r=ne.automerge_updateText(this.__wbg_ptr,t,n);if(r[1])throw pe(r[0])}}Symbol.dispose&&(Mn.prototype[Symbol.dispose]=Mn.prototype.free);let rr=class Vu{static __wrap(t){t=t>>>0;const n=Object.create(Vu.prototype);return n.__wbg_ptr=t,kg.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,kg.unregister(this),t}free(){const t=this.__destroy_into_raw();ne.__wbg_syncstate_free(t,0)}clone(){const t=ne.syncstate_clone(this.__wbg_ptr);return Vu.__wrap(t)}get lastSentHeads(){return ne.syncstate_lastSentHeads(this.__wbg_ptr)}get peerReadOnly(){return ne.syncstate_peerReadOnly(this.__wbg_ptr)!==0}get readOnly(){return ne.syncstate_readOnly(this.__wbg_ptr)!==0}set lastSentHeads(t){const n=ne.syncstate_set_lastSentHeads(this.__wbg_ptr,t);if(n[1])throw pe(n[0])}set readOnly(t){ne.syncstate_set_readOnly(this.__wbg_ptr,t)}set sentHashes(t){const n=ne.syncstate_set_sentHashes(this.__wbg_ptr,t);if(n[1])throw pe(n[0])}get sharedHeads(){return ne.syncstate_sharedHeads(this.__wbg_ptr)}};Symbol.dispose&&(rr.prototype[Symbol.dispose]=rr.prototype.free);function zx(e){const t=ne.create(e);if(t[2])throw pe(t[1]);return Mn.__wrap(t[0])}function Ox(e){const t=ne.decodeChange(e);if(t[2])throw pe(t[1]);return pe(t[0])}function Px(e){const t=ne.decodeSyncMessage(e);if(t[2])throw pe(t[1]);return pe(t[0])}function Tx(e){const t=ne.decodeSyncState(e);if(t[2])throw pe(t[1]);return rr.__wrap(t[0])}function Dx(e){const t=ne.encodeChange(e);if(t[2])throw pe(t[1]);return pe(t[0])}function Rx(e){const t=ne.encodeSyncMessage(e);if(t[2])throw pe(t[1]);return pe(t[0])}function Fx(e){return xi(e,rr),ne.encodeSyncState(e.__wbg_ptr)}function Bx(e){return xi(e,rr),ne.exportSyncState(e.__wbg_ptr)}function Ux(e){const t=ne.importSyncState(e);if(t[2])throw pe(t[1]);return rr.__wrap(t[0])}function jx(){const e=ne.initSyncState();return rr.__wrap(e)}function Mx(e,t){const n=ne.load(e,t);if(n[2])throw pe(n[1]);return Mn.__wrap(n[0])}function Lx(e){const t=ne.readBundle(e);if(t[2])throw pe(t[1]);return pe(t[0])}function Nx(){return ne.wasmReleaseInfo()}function Hx(e){return BigInt(e)}function Zx(e,t){return Error(Zn(e,t))}function Vx(e,t){const n=String(t),r=er(n,ne.__wbindgen_malloc,ne.__wbindgen_realloc),i=Dn;Sn().setInt32(e+4,i,!0),Sn().setInt32(e+0,r,!0)}function Wx(e){const t=e,n=typeof t=="boolean"?t:void 0;return wn(n)?0xffffff:n?1:0}function qx(e,t){const n=Wu(t),r=er(n,ne.__wbindgen_malloc,ne.__wbindgen_realloc),i=Dn;Sn().setInt32(e+4,i,!0),Sn().setInt32(e+0,r,!0)}function Jx(e,t){return e>t}function Kx(e){return typeof e=="bigint"}function Gx(e){return typeof e=="function"}function Yx(e){return e===null}function Xx(e){const t=e;return typeof t=="object"&&t!==null}function Qx(e){return typeof e=="string"}function eS(e){return e===void 0}function tS(e,t){return e==t}function nS(e,t){return e<t}function rS(e){return-e}function iS(e,t){const n=t,r=typeof n=="number"?n:void 0;Sn().setFloat64(e+8,wn(r)?0:r,!0),Sn().setInt32(e+0,!wn(r),!0)}function sS(e,t){const n=t,r=typeof n=="string"?n:void 0;var i=wn(r)?0:er(r,ne.__wbindgen_malloc,ne.__wbindgen_realloc),s=Dn;Sn().setInt32(e+4,s,!0),Sn().setInt32(e+0,i,!0)}function oS(e,t){throw new Error(Zn(e,t))}function aS(){return cr(function(e,t,n){return Reflect.apply(e,t,n)},arguments)}function cS(e,t){return Object.assign(e,t)}function lS(){return cr(function(e,t){return e.call(t)},arguments)}function uS(){return cr(function(e,t,n){return e.call(t,n)},arguments)}function dS(e,t){return e.concat(t)}function fS(e,t,n){return Object.defineProperty(e,t,n)}function hS(){return cr(function(e,t){return Reflect.deleteProperty(e,t)},arguments)}function gS(e){return e.done}function pS(e){return Object.entries(e)}function mS(e,t){let n,r;try{n=e,r=t,console.error(Zn(e,t))}finally{ne.__wbindgen_free(n,r,1)}}function _S(e,t){return Symbol.for(Zn(e,t))}function yS(e){return Object.freeze(e)}function bS(e){return Array.from(e)}function wS(){return cr(function(e,t){globalThis.crypto.getRandomValues(ff(e,t))},arguments)}function vS(e){return e.getTime()}function xS(){return cr(function(e,t){return Reflect.get(e,t)},arguments)}function SS(){return cr(function(e,t){return Reflect.get(e,t)},arguments)}function $S(e,t){return e[t>>>0]}function kS(e,t){return e[t>>>0]}function ES(e){let t;try{t=e instanceof ArrayBuffer}catch{t=!1}return t}function AS(e){let t;try{t=e instanceof Date}catch{t=!1}return t}function IS(e){let t;try{t=e instanceof Object}catch{t=!1}return t}function CS(e){let t;try{t=e instanceof Uint8Array}catch{t=!1}return t}function zS(e){return Array.isArray(e)}function OS(e){return Array.isArray(e)}function PS(){return Symbol.iterator}function TS(e){return Object.keys(e)}function DS(e){return e.length}function RS(e){return e.length}function FS(e){return e.length}function BS(e){console.log(e)}function US(e,t){console.log(e,t)}function jS(e){return new Uint8Array(e)}function MS(e,t){return new RangeError(Zn(e,t))}function LS(){return new Error}function NS(e,t){return new Error(Zn(e,t))}function HS(){return new Array}function ZS(e){return new Date(e)}function VS(){return new Object}function WS(e,t){return new Uint8Array(ff(e,t))}function qS(){return cr(function(e){return e.next()},arguments)}function JS(e){return e.next}function KS(){return cr(function(e){return Reflect.ownKeys(e)},arguments)}function GS(e,t,n){Uint8Array.prototype.set.call(ff(e,t),n)}function YS(e,t){return e.push(t)}function XS(){return cr(function(e,t,n){return Reflect.set(e,t,n)},arguments)}function QS(e,t,n){e[t>>>0]=n}function e$(e,t,n){e[t]=n}function t$(e,t,n){return e.slice(t>>>0,n>>>0)}function n$(e,t){const n=t.stack,r=er(n,ne.__wbindgen_malloc,ne.__wbindgen_realloc),i=Dn;Sn().setInt32(e+4,i,!0),Sn().setInt32(e+0,r,!0)}function r$(e,t){const n=JSON.stringify(t);var r=wn(n)?0:er(n,ne.__wbindgen_malloc,ne.__wbindgen_realloc),i=Dn;Sn().setInt32(e+4,i,!0),Sn().setInt32(e+0,r,!0)}function i$(e){return e.toString()}function s$(){return cr(function(e,t){return e.toString(t)},arguments)}function o$(e,t,n){const r=t.toString(n),i=er(r,ne.__wbindgen_malloc,ne.__wbindgen_realloc),s=Dn;Sn().setInt32(e+4,s,!0),Sn().setInt32(e+0,i,!0)}function a$(e,t){return e.unshift(t)}function c$(e){return e.value}function l$(e){return Object.values(e)}function u$(e){return e}function d$(e){return e}function f$(e,t){return Zn(e,t)}function h$(e){return BigInt.asUintN(64,e)}function g$(){const e=ne.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)}const $g=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>ne.__wbg_automerge_free(e>>>0,1)),kg=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>ne.__wbg_syncstate_free(e>>>0,1));function p$(e){const t=ne.__externref_table_alloc();return ne.__wbindgen_externrefs.set(t,e),t}function xi(e,t){if(!(e instanceof t))throw new Error(`expected instance of ${t.name}`)}function Wu(e){const t=typeof e;if(t=="number"||t=="boolean"||e==null)return`${e}`;if(t=="string")return`"${e}"`;if(t=="symbol"){const i=e.description;return i==null?"Symbol":`Symbol(${i})`}if(t=="function"){const i=e.name;return typeof i=="string"&&i.length>0?`Function(${i})`:"Function"}if(Array.isArray(e)){const i=e.length;let s="[";i>0&&(s+=Wu(e[0]));for(let o=1;o<i;o++)s+=", "+Wu(e[o]);return s+="]",s}const n=/\[object ([^\]]+)\]/.exec(toString.call(e));let r;if(n&&n.length>1)r=n[1];else return toString.call(e);if(r=="Object")try{return"Object("+JSON.stringify(e)+")"}catch{return"Object"}return e instanceof Error?`${e.name}: ${e.message}
|
|
5
|
+
${e.stack}`:r}function ff(e,t){return e=e>>>0,oo().subarray(e/1,e/1+t)}let ts=null;function Sn(){return(ts===null||ts.buffer.detached===!0||ts.buffer.detached===void 0&&ts.buffer!==ne.memory.buffer)&&(ts=new DataView(ne.memory.buffer)),ts}function Zn(e,t){return e=e>>>0,_$(e,t)}let da=null;function oo(){return(da===null||da.byteLength===0)&&(da=new Uint8Array(ne.memory.buffer)),da}function cr(e,t){try{return e.apply(this,t)}catch(n){const r=p$(n);ne.__wbindgen_exn_store(r)}}function wn(e){return e==null}function er(e,t,n){if(n===void 0){const a=ao.encode(e),c=t(a.length,1)>>>0;return oo().subarray(c,c+a.length).set(a),Dn=a.length,c}let r=e.length,i=t(r,1)>>>0;const s=oo();let o=0;for(;o<r;o++){const a=e.charCodeAt(o);if(a>127)break;s[i+o]=a}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;const a=oo().subarray(i+o,i+r),c=ao.encodeInto(e,a);o+=c.written,i=n(i,r,o,1)>>>0}return Dn=o,i}function pe(e){const t=ne.__wbindgen_externrefs.get(e);return ne.__externref_table_dealloc(e),t}let Ba=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});Ba.decode();const m$=0x7ff00000;let Dl=0;function _$(e,t){return Dl+=t,Dl>=m$&&(Ba=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),Ba.decode(),Dl=t),Ba.decode(oo().subarray(e,e+t))}const ao=new TextEncoder;"encodeInto"in ao||(ao.encodeInto=function(e,t){const n=ao.encode(e);return t.set(n),{read:e.length,written:n.length}});let Dn=0,ne;function y$(e){ne=e}URL=globalThis.URL;const b$=await l_({"./automerge_wasm_bg.js":{__wbg_get_unchecked_17f53dad852b9588:kS,__wbg_get_8360291721e2339f:$S,__wbg_push_471a5b068a5295f6:YS,__wbg_set_3bf1de9fab0cd644:QS,__wbg_freeze_c79f45721998bbbc:yS,__wbg_instanceof_Object_7c99480a1cdfb911:IS,__wbg_defineProperty_aeb95d0434ce03d0:fS,__wbg_length_3d4ecd04bd8d22f1:DS,__wbg_keys_2fd1bfdda7e278ca:TS,__wbg_values_301a77363cf6c773:l$,__wbg_call_a24592a6f349a97e:uS,__wbg_assign_752c2af1512cc7fd:cS,__wbg_next_0340c4ae324393c3:qS,__wbg_done_9158f7cc8751ba32:gS,__wbg_value_ee3a06f4579184fa:c$,__wbg_deleteProperty_d5f7bd763acbdb44:hS,__wbg_unshift_951ea71d9d2dc660:a$,__wbg_apply_329b2a440415c2e6:aS,__wbg_new_227d7c05414eb861:LS,__wbg_stack_3b0d974bbf31e44f:n$,__wbg_error_a6fa202b58aa1cd3:mS,__wbg_String_8564e559799eccda:Vx,__wbg_set_6be42768c690e380:e$,__wbg_getRandomValues_76dfc69825c9c552:wS,__wbg_log_7e1aa9064a1dbdbd:BS,__wbg_log_dfa1efedf266562e:US,__wbg_new_682678e2f47e32bc:HS,__wbg_new_aa8d0fa9762c29bd:VS,__wbg_BigInt_65bcea251e788083:Hx,__wbg_next_7646edaa39458ef7:JS,__wbg_iterator_013bc09ec998c2a7:PS,__wbg_get_1affdbdd5573b16a:xS,__wbg_call_14b169f759b26747:lS,__wbg_length_6a846b3b23b74aca:RS,__wbg_from_0dbf29f09e7fb200:bS,__wbg_isArray_c3109d14ffc06469:OS,__wbg_instanceof_ArrayBuffer_7c8433c6ed14ffe3:ES,__wbg_toString_c3061af2bf859d19:s$,__wbg_toString_c96dc76d5547a715:o$,__wbg_new_5e360d2ff7b9e1c3:NS,__wbg_instanceof_Date_81b75f5ed36b30ea:AS,__wbg_getTime_da7c55f52b71e8c6:vS,__wbg_new_7913666fe5070684:ZS,__wbg_entries_e0b73aa8571ddb56:pS,__wbg_new_191521fecb171639:MS,__wbg_get_6011fa3a58f61074:SS,__wbg_ownKeys_0231887680f0f945:KS,__wbg_set_022bee52d0b05b19:XS,__wbg_concat_1cef5380372e969d:dS,__wbg_slice_45916ed2fae7e0ea:t$,__wbg_for_b0616d1de7774be9:_S,__wbg_toString_5a84b8552b34a19d:i$,__wbg_length_9f1775224cf1d815:FS,__wbg_prototypesetcall_a6b02eb00b0f4ce2:GS,__wbg_new_0c7403db6e782f19:jS,__wbg_instanceof_Uint8Array_152ba1f289edcf3f:CS,__wbg_new_from_slice_b5ea43e23f6008c0:WS,__wbg___wbindgen_string_get_7ed5322991caaec5:sS,__wbg___wbindgen_boolean_get_6ea149f0a8dcc5ff:Wx,__wbg___wbindgen_number_get_c7f42aed0525c451:iS,__wbg___wbindgen_is_undefined_29a43b4d42920abd:eS,__wbg___wbindgen_debug_string_ab4b34d23d6778bd:qx,__wbg_isArray_2790516aa848bf18:zS,__wbg_Error_960c155d3d49e4c2:Zx,__wbg_stringify_057c4027271f8007:r$,__wbg___wbindgen_is_null_52ff4ec04186736f:Yx,__wbg___wbindgen_is_object_63322ec0cd6ea4ef:Xx,__wbg___wbindgen_is_function_3baa9db1a987f47d:Gx,__wbg___wbindgen_is_string_6df3bf7ef1164ed3:Qx,__wbg___wbindgen_is_bigint_ec25c7f91b4d9e93:Kx,__wbg___wbindgen_neg_8d39d23ef65c9fdb:rS,__wbg___wbindgen_lt_78bab382628fb48f:nS,__wbg___wbindgen_gt_fd08d8cbe0a8551c:Jx,__wbg___wbindgen_throw_6b64449b9b9ed33c:oS,__wbg___wbindgen_jsval_loose_eq_cac3565e89b4134c:tS,__wbindgen_init_externref_table:g$,__wbindgen_cast_0000000000000001:u$,__wbindgen_cast_0000000000000002:d$,__wbindgen_cast_0000000000000003:f$,__wbindgen_cast_0000000000000004:h$}},Cx),{memory:w$,__wbg_syncstate_free:v$,syncstate_sharedHeads:x$,syncstate_lastSentHeads:S$,syncstate_set_lastSentHeads:$$,syncstate_set_sentHashes:k$,syncstate_readOnly:E$,syncstate_set_readOnly:A$,syncstate_peerReadOnly:I$,syncstate_clone:C$,__wbg_automerge_free:z$,automerge_new:O$,automerge_initRootFromHydrate:P$,automerge_clone:T$,automerge_fork:D$,automerge_pendingOps:R$,automerge_commit:F$,automerge_merge:B$,automerge_rollback:U$,automerge_keys:j$,automerge_text:M$,automerge_spans:L$,automerge_splice:N$,automerge_updateText:H$,automerge_updateSpans:Z$,automerge_push:V$,automerge_pushObject:W$,automerge_insert:q$,automerge_splitBlock:J$,automerge_joinBlock:K$,automerge_updateBlock:G$,automerge_getBlock:Y$,automerge_insertObject:X$,automerge_put:Q$,automerge_putObject:ek,automerge_putObjectFromHydrate:tk,automerge_insertObjectFromHydrate:nk,automerge_spliceFromHydrate:rk,automerge_increment:ik,automerge_get:sk,automerge_getWithType:ok,automerge_objInfo:ak,automerge_getAll:ck,automerge_enableFreeze:lk,automerge_registerDatatype:uk,automerge_applyPatches:dk,automerge_applyAndReturnPatches:fk,automerge_diffIncremental:hk,automerge_updateDiffCursor:gk,automerge_resetDiffCursor:pk,automerge_diff:mk,automerge_diffPath:_k,automerge_isolate:yk,automerge_integrate:bk,automerge_length:wk,automerge_delete:vk,automerge_save:xk,automerge_saveIncremental:Sk,automerge_saveSince:$k,automerge_saveNoCompress:kk,automerge_saveAndVerify:Ek,automerge_loadIncremental:Ak,automerge_applyChanges:Ik,automerge_getChanges:Ck,automerge_getChangesMeta:zk,automerge_getChangeByHash:Ok,automerge_getChangeMetaByHash:Pk,automerge_getDecodedChangeByHash:Tk,automerge_getChangesAdded:Dk,automerge_getHeads:Rk,automerge_getActorId:Fk,automerge_getLastLocalChange:Bk,automerge_dump:Uk,automerge_getMissingDeps:jk,automerge_receiveSyncMessage:Mk,automerge_generateSyncMessage:Lk,automerge_toJS:Nk,automerge_materialize:Hk,automerge_getCursor:Zk,automerge_getCursorPosition:Vk,automerge_emptyChange:Wk,automerge_mark:qk,automerge_unmark:Jk,automerge_marks:Kk,automerge_marksAt:Gk,automerge_hasOurChanges:Yk,automerge_topoHistoryTraversal:Xk,automerge_stats:Qk,automerge_saveBundle:e3,create:t3,load:n3,wasmReleaseInfo:r3,encodeChange:i3,decodeChange:s3,initSyncState:o3,importSyncState:a3,exportSyncState:c3,encodeSyncMessage:l3,decodeSyncMessage:u3,encodeSyncState:d3,decodeSyncState:f3,readBundle:h3,__wbindgen_malloc:g3,__wbindgen_realloc:p3,__wbindgen_exn_store:m3,__externref_table_alloc:_3,__wbindgen_externrefs:y3,__wbindgen_free:b3,__externref_table_dealloc:w3,__wbindgen_start:u_}=b$,v3=Object.freeze(Object.defineProperty({__proto__:null,__externref_table_alloc:_3,__externref_table_dealloc:w3,__wbg_automerge_free:z$,__wbg_syncstate_free:v$,__wbindgen_exn_store:m3,__wbindgen_externrefs:y3,__wbindgen_free:b3,__wbindgen_malloc:g3,__wbindgen_realloc:p3,__wbindgen_start:u_,automerge_applyAndReturnPatches:fk,automerge_applyChanges:Ik,automerge_applyPatches:dk,automerge_clone:T$,automerge_commit:F$,automerge_delete:vk,automerge_diff:mk,automerge_diffIncremental:hk,automerge_diffPath:_k,automerge_dump:Uk,automerge_emptyChange:Wk,automerge_enableFreeze:lk,automerge_fork:D$,automerge_generateSyncMessage:Lk,automerge_get:sk,automerge_getActorId:Fk,automerge_getAll:ck,automerge_getBlock:Y$,automerge_getChangeByHash:Ok,automerge_getChangeMetaByHash:Pk,automerge_getChanges:Ck,automerge_getChangesAdded:Dk,automerge_getChangesMeta:zk,automerge_getCursor:Zk,automerge_getCursorPosition:Vk,automerge_getDecodedChangeByHash:Tk,automerge_getHeads:Rk,automerge_getLastLocalChange:Bk,automerge_getMissingDeps:jk,automerge_getWithType:ok,automerge_hasOurChanges:Yk,automerge_increment:ik,automerge_initRootFromHydrate:P$,automerge_insert:q$,automerge_insertObject:X$,automerge_insertObjectFromHydrate:nk,automerge_integrate:bk,automerge_isolate:yk,automerge_joinBlock:K$,automerge_keys:j$,automerge_length:wk,automerge_loadIncremental:Ak,automerge_mark:qk,automerge_marks:Kk,automerge_marksAt:Gk,automerge_materialize:Hk,automerge_merge:B$,automerge_new:O$,automerge_objInfo:ak,automerge_pendingOps:R$,automerge_push:V$,automerge_pushObject:W$,automerge_put:Q$,automerge_putObject:ek,automerge_putObjectFromHydrate:tk,automerge_receiveSyncMessage:Mk,automerge_registerDatatype:uk,automerge_resetDiffCursor:pk,automerge_rollback:U$,automerge_save:xk,automerge_saveAndVerify:Ek,automerge_saveBundle:e3,automerge_saveIncremental:Sk,automerge_saveNoCompress:kk,automerge_saveSince:$k,automerge_spans:L$,automerge_splice:N$,automerge_spliceFromHydrate:rk,automerge_splitBlock:J$,automerge_stats:Qk,automerge_text:M$,automerge_toJS:Nk,automerge_topoHistoryTraversal:Xk,automerge_unmark:Jk,automerge_updateBlock:G$,automerge_updateDiffCursor:gk,automerge_updateSpans:Z$,automerge_updateText:H$,create:t3,decodeChange:s3,decodeSyncMessage:u3,decodeSyncState:f3,encodeChange:i3,encodeSyncMessage:l3,encodeSyncState:d3,exportSyncState:c3,importSyncState:a3,initSyncState:o3,load:n3,memory:w$,readBundle:h3,syncstate_clone:C$,syncstate_lastSentHeads:S$,syncstate_peerReadOnly:I$,syncstate_readOnly:E$,syncstate_set_lastSentHeads:$$,syncstate_set_readOnly:A$,syncstate_set_sentHashes:k$,syncstate_sharedHeads:x$,wasmReleaseInfo:r3},Symbol.toStringTag,{value:"Module"}));y$(v3);u_();const x3=Object.freeze(Object.defineProperty({__proto__:null,Automerge:Mn,SyncState:rr,create:zx,decodeChange:Ox,decodeSyncMessage:Px,decodeSyncState:Tx,encodeChange:Dx,encodeSyncMessage:Rx,encodeSyncState:Fx,exportSyncState:Bx,importSyncState:Ux,initSyncState:jx,load:Mx,readBundle:Lx,wasmReleaseInfo:Nx},Symbol.toStringTag,{value:"Module"}));n1(x3);class S3{database;store;dbPromise;constructor(t="automerge",n="documents"){this.database=t,this.store=n,this.dbPromise=this.createDatabasePromise()}createDatabasePromise(){return new Promise((t,n)=>{const r=indexedDB.open(this.database,1);r.onerror=()=>{n(r.error)},r.onupgradeneeded=i=>{i.target.result.createObjectStore(this.store)},r.onsuccess=i=>{const s=i.target.result;t(s)}})}async load(t){const r=(await this.dbPromise).transaction(this.store),s=r.objectStore(this.store).get(t);return new Promise((o,a)=>{r.onerror=()=>{a(s.error)},s.onsuccess=c=>{const l=c.target.result;l&&typeof l=="object"&&"binary"in l?o(l.binary):o(void 0)}})}async save(t,n){const i=(await this.dbPromise).transaction(this.store,"readwrite");return i.objectStore(this.store).put({key:t,binary:n},t),new Promise((o,a)=>{i.onerror=()=>{a(i.error)},i.oncomplete=()=>{o()}})}async remove(t){const r=(await this.dbPromise).transaction(this.store,"readwrite");return r.objectStore(this.store).delete(t),new Promise((s,o)=>{r.onerror=()=>{o(r.error)},r.oncomplete=()=>{s()}})}async loadRange(t){const n=await this.dbPromise,r=t,i=[...t,""],s=IDBKeyRange.bound(r,i),o=n.transaction(this.store),c=o.objectStore(this.store).openCursor(s),l=[];return new Promise((f,u)=>{o.onerror=()=>{u(c.error)},c.onsuccess=h=>{const d=h.target.result;d?(l.push({data:d.value.binary,key:d.key}),d.continue()):f(l)}})}async removeRange(t){const n=await this.dbPromise,r=t,i=[...t,""],s=IDBKeyRange.bound(r,i),o=n.transaction(this.store,"readwrite");return o.objectStore(this.store).delete(s),new Promise((c,l)=>{o.onerror=()=>{l(o.error)},o.oncomplete=()=>{c()}})}}class $3 extends Ix{#e;#t=!1;#r=!1;#n=()=>{};#s;#o;#a=[];isReady(){return this.#r}whenReady(){return this.#s}constructor(t){super(),this.#o={channelName:"broadcast",peerWaitMs:1e3,...t??{}},this.#e=new BroadcastChannel(this.#o.channelName),this.#s=new Promise(n=>{this.#n=()=>{this.#r=!0,n()},setTimeout(()=>this.#n(),this.#o.peerWaitMs)})}connect(t,n){this.peerId=t,this.peerMetadata=n,this.#t=!1,this.#e.addEventListener("message",r=>{const i=r.data;if("targetId"in i&&i.targetId!==this.peerId||this.#t)return;const{senderId:s,type:o}=i;switch(o){case"arrive":{const{peerMetadata:a}=i;this.#e.postMessage({senderId:this.peerId,targetId:s,type:"welcome",peerMetadata:this.peerMetadata}),this.#c(s,a)}break;case"welcome":{const{peerMetadata:a}=i;this.#c(s,a)}break;case"leave":this.#a=this.#a.filter(a=>a!==s),this.emit("peer-disconnected",{peerId:s});break;default:if(!("data"in i))this.emit("message",i);else{if(!i.data)throw new Error("We got a message without data, we can't send this.");const a=i.data;this.emit("message",{...i,data:new Uint8Array(a)})}break}}),this.#e.postMessage({senderId:this.peerId,type:"arrive",peerMetadata:n})}#c(t,n){this.#n(),this.#a.push(t),this.emit("peer-candidate",{peerId:t,peerMetadata:n})}send(t){if(this.#t)return!1;"data"in t?this.#e.postMessage({...t,data:t.data?t.data.buffer.slice(t.data.byteOffset,t.data.byteOffset+t.data.byteLength):void 0}):this.#e.postMessage(t)}disconnect(){this.#e.postMessage({senderId:this.peerId,type:"leave"});for(const t of this.#a)this.emit("peer-disconnected",{peerId:t});this.#t=!0}}BigInt("9223372036854775807");let Eg=class qu{static __wrap(t){t=t>>>0;const n=Object.create(qu.prototype);return n.__wbg_ptr=t,Ag.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,Ag.unregister(this),t}free(){const t=this.__destroy_into_raw();Pn.__wbg_syncstate_free(t,0)}clone(){const t=Pn.syncstate_clone(this.__wbg_ptr);return qu.__wrap(t)}get lastSentHeads(){return Pn.syncstate_lastSentHeads(this.__wbg_ptr)}get peerReadOnly(){return Pn.syncstate_peerReadOnly(this.__wbg_ptr)!==0}get readOnly(){return Pn.syncstate_readOnly(this.__wbg_ptr)!==0}set lastSentHeads(t){const n=Pn.syncstate_set_lastSentHeads(this.__wbg_ptr,t);if(n[1])throw Ig(n[0])}set readOnly(t){Pn.syncstate_set_readOnly(this.__wbg_ptr,t)}set sentHashes(t){const n=Pn.syncstate_set_sentHashes(this.__wbg_ptr,t);if(n[1])throw Ig(n[0])}get sharedHeads(){return Pn.syncstate_sharedHeads(this.__wbg_ptr)}};Symbol.dispose&&(Eg.prototype[Symbol.dispose]=Eg.prototype.free);typeof FinalizationRegistry>"u"||new FinalizationRegistry(e=>Pn.__wbg_automerge_free(e>>>0,1));const Ag=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>Pn.__wbg_syncstate_free(e>>>0,1));function Ig(e){const t=Pn.__wbindgen_externrefs.get(e);return Pn.__externref_table_dealloc(e),t}let k3=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});k3.decode();const Rl=new TextEncoder;"encodeInto"in Rl||(Rl.encodeInto=function(e,t){const n=Rl.encode(e);return t.set(n),{read:e.length,written:n.length}});let Pn,E3=[];function A3(e){for(const t of E3)t()}var fa={exports:{}},Fl,Cg;function I3(){if(Cg)return Fl;Cg=1;var e=1e3,t=e*60,n=t*60,r=n*24,i=r*7,s=r*365.25;Fl=function(f,u){u=u||{};var h=typeof f;if(h==="string"&&f.length>0)return o(f);if(h==="number"&&isFinite(f))return u.long?c(f):a(f);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(f))};function o(f){if(f=String(f),!(f.length>100)){var u=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(f);if(u){var h=parseFloat(u[1]),d=(u[2]||"ms").toLowerCase();switch(d){case"years":case"year":case"yrs":case"yr":case"y":return h*s;case"weeks":case"week":case"w":return h*i;case"days":case"day":case"d":return h*r;case"hours":case"hour":case"hrs":case"hr":case"h":return h*n;case"minutes":case"minute":case"mins":case"min":case"m":return h*t;case"seconds":case"second":case"secs":case"sec":case"s":return h*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return h;default:return}}}}function a(f){var u=Math.abs(f);return u>=r?Math.round(f/r)+"d":u>=n?Math.round(f/n)+"h":u>=t?Math.round(f/t)+"m":u>=e?Math.round(f/e)+"s":f+"ms"}function c(f){var u=Math.abs(f);return u>=r?l(f,u,r,"day"):u>=n?l(f,u,n,"hour"):u>=t?l(f,u,t,"minute"):u>=e?l(f,u,e,"second"):f+" ms"}function l(f,u,h,d){var g=u>=h*1.5;return Math.round(f/h)+" "+d+(g?"s":"")}return Fl}var Bl,zg;function C3(){if(zg)return Bl;zg=1;function e(t){r.debug=r,r.default=r,r.coerce=l,r.disable=a,r.enable=s,r.enabled=c,r.humanize=I3(),r.destroy=f,Object.keys(t).forEach(u=>{r[u]=t[u]}),r.names=[],r.skips=[],r.formatters={};function n(u){let h=0;for(let d=0;d<u.length;d++)h=(h<<5)-h+u.charCodeAt(d),h|=0;return r.colors[Math.abs(h)%r.colors.length]}r.selectColor=n;function r(u){let h,d=null,g,p;function m(...b){if(!m.enabled)return;const x=m,_=Number(new Date),E=_-(h||_);x.diff=E,x.prev=h,x.curr=_,h=_,b[0]=r.coerce(b[0]),typeof b[0]!="string"&&b.unshift("%O");let k=0;b[0]=b[0].replace(/%([a-zA-Z%])/g,(T,j)=>{if(T==="%%")return"%";k++;const I=r.formatters[j];if(typeof I=="function"){const R=b[k];T=I.call(x,R),b.splice(k,1),k--}return T}),r.formatArgs.call(x,b),(x.log||r.log).apply(x,b)}return m.namespace=u,m.useColors=r.useColors(),m.color=r.selectColor(u),m.extend=i,m.destroy=r.destroy,Object.defineProperty(m,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(g!==r.namespaces&&(g=r.namespaces,p=r.enabled(u)),p),set:b=>{d=b}}),typeof r.init=="function"&&r.init(m),m}function i(u,h){const d=r(this.namespace+(typeof h>"u"?":":h)+u);return d.log=this.log,d}function s(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];const h=(typeof u=="string"?u:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const d of h)d[0]==="-"?r.skips.push(d.slice(1)):r.names.push(d)}function o(u,h){let d=0,g=0,p=-1,m=0;for(;d<u.length;)if(g<h.length&&(h[g]===u[d]||h[g]==="*"))h[g]==="*"?(p=g,m=d,g++):(d++,g++);else if(p!==-1)g=p+1,m++,d=m;else return!1;for(;g<h.length&&h[g]==="*";)g++;return g===h.length}function a(){const u=[...r.names,...r.skips.map(h=>"-"+h)].join(",");return r.enable(""),u}function c(u){for(const h of r.skips)if(o(u,h))return!1;for(const h of r.names)if(o(u,h))return!0;return!1}function l(u){return u instanceof Error?u.stack||u.message:u}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.enable(r.load()),r}return Bl=e,Bl}var Og;function z3(){return Og||(Og=1,(function(e,t){var n={};t.formatArgs=i,t.save=s,t.load=o,t.useColors=r,t.storage=a(),t.destroy=(()=>{let l=!1;return()=>{l||(l=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function r(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let l;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(l=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(l[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function i(l){if(l[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+l[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const f="color: "+this.color;l.splice(1,0,f,"color: inherit");let u=0,h=0;l[0].replace(/%[a-zA-Z%]/g,d=>{d!=="%%"&&(u++,d==="%c"&&(h=u))}),l.splice(h,0,f)}t.log=console.debug||console.log||(()=>{});function s(l){try{l?t.storage.setItem("debug",l):t.storage.removeItem("debug")}catch{}}function o(){let l;try{l=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch{}return!l&&typeof process<"u"&&"env"in process&&(l=n.DEBUG),l}function a(){try{return localStorage}catch{}}e.exports=C3()(t);const{formatters:c}=e.exports;c.j=function(l){try{return JSON.stringify(l)}catch(f){return"[UnexpectedJSONParseError]: "+f.message}}})(fa,fa.exports)),fa.exports}var O3=z3();const P3=Ts(O3);var Ul={exports:{}},Pg;function T3(){return Pg||(Pg=1,(function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function i(c,l,f){this.fn=c,this.context=l,this.once=f||!1}function s(c,l,f,u,h){if(typeof f!="function")throw new TypeError("The listener must be a function");var d=new i(f,u||c,h),g=n?n+l:l;return c._events[g]?c._events[g].fn?c._events[g]=[c._events[g],d]:c._events[g].push(d):(c._events[g]=d,c._eventsCount++),c}function o(c,l){--c._eventsCount===0?c._events=new r:delete c._events[l]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var l=[],f,u;if(this._eventsCount===0)return l;for(u in f=this._events)t.call(f,u)&&l.push(n?u.slice(1):u);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(f)):l},a.prototype.listeners=function(l){var f=n?n+l:l,u=this._events[f];if(!u)return[];if(u.fn)return[u.fn];for(var h=0,d=u.length,g=new Array(d);h<d;h++)g[h]=u[h].fn;return g},a.prototype.listenerCount=function(l){var f=n?n+l:l,u=this._events[f];return u?u.fn?1:u.length:0},a.prototype.emit=function(l,f,u,h,d,g){var p=n?n+l:l;if(!this._events[p])return!1;var m=this._events[p],b=arguments.length,x,_;if(m.fn){switch(m.once&&this.removeListener(l,m.fn,void 0,!0),b){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,f),!0;case 3:return m.fn.call(m.context,f,u),!0;case 4:return m.fn.call(m.context,f,u,h),!0;case 5:return m.fn.call(m.context,f,u,h,d),!0;case 6:return m.fn.call(m.context,f,u,h,d,g),!0}for(_=1,x=new Array(b-1);_<b;_++)x[_-1]=arguments[_];m.fn.apply(m.context,x)}else{var E=m.length,k;for(_=0;_<E;_++)switch(m[_].once&&this.removeListener(l,m[_].fn,void 0,!0),b){case 1:m[_].fn.call(m[_].context);break;case 2:m[_].fn.call(m[_].context,f);break;case 3:m[_].fn.call(m[_].context,f,u);break;case 4:m[_].fn.call(m[_].context,f,u,h);break;default:if(!x)for(k=1,x=new Array(b-1);k<b;k++)x[k-1]=arguments[k];m[_].fn.apply(m[_].context,x)}}return!0},a.prototype.on=function(l,f,u){return s(this,l,f,u,!1)},a.prototype.once=function(l,f,u){return s(this,l,f,u,!0)},a.prototype.removeListener=function(l,f,u,h){var d=n?n+l:l;if(!this._events[d])return this;if(!f)return o(this,d),this;var g=this._events[d];if(g.fn)g.fn===f&&(!h||g.once)&&(!u||g.context===u)&&o(this,d);else{for(var p=0,m=[],b=g.length;p<b;p++)(g[p].fn!==f||h&&!g[p].once||u&&g[p].context!==u)&&m.push(g[p]);m.length?this._events[d]=m.length===1?m[0]:m:o(this,d)}return this},a.prototype.removeAllListeners=function(l){var f;return l?(f=n?n+l:l,this._events[f]&&o(this,f)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a})(Ul)),Ul.exports}var D3=T3();const R3=Ts(D3);var Xn={},mt={},cn={},jl={},Ks={},Tg;function F3(){return Tg||(Tg=1,Object.defineProperty(Ks,"__esModule",{value:!0}),Ks.crypto=void 0,Ks.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0),Ks}var Dg;function d_(){return Dg||(Dg=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.wrapXOFConstructorWithOpts=e.wrapConstructorWithOpts=e.wrapConstructor=e.Hash=e.nextTick=e.swap32IfBE=e.byteSwapIfBE=e.swap8IfBE=e.isLE=void 0,e.isBytes=n,e.anumber=r,e.abytes=i,e.ahash=s,e.aexists=o,e.aoutput=a,e.u8=c,e.u32=l,e.clean=f,e.createView=u,e.rotr=h,e.rotl=d,e.byteSwap=g,e.byteSwap32=p,e.bytesToHex=x,e.hexToBytes=k,e.asyncLoop=T,e.utf8ToBytes=j,e.bytesToUtf8=I,e.toBytes=R,e.kdfInputToBytes=N,e.concatBytes=D,e.checkOpts=y,e.createHasher=$,e.createOptHasher=P,e.createXOFer=A,e.randomBytes=J;const t=F3();function n(S){return S instanceof Uint8Array||ArrayBuffer.isView(S)&&S.constructor.name==="Uint8Array"}function r(S){if(!Number.isSafeInteger(S)||S<0)throw new Error("positive integer expected, got "+S)}function i(S,...U){if(!n(S))throw new Error("Uint8Array expected");if(U.length>0&&!U.includes(S.length))throw new Error("Uint8Array expected of length "+U+", got length="+S.length)}function s(S){if(typeof S!="function"||typeof S.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");r(S.outputLen),r(S.blockLen)}function o(S,U=!0){if(S.destroyed)throw new Error("Hash instance has been destroyed");if(U&&S.finished)throw new Error("Hash#digest() has already been called")}function a(S,U){i(S);const O=U.outputLen;if(S.length<O)throw new Error("digestInto() expects output buffer of length at least "+O)}function c(S){return new Uint8Array(S.buffer,S.byteOffset,S.byteLength)}function l(S){return new Uint32Array(S.buffer,S.byteOffset,Math.floor(S.byteLength/4))}function f(...S){for(let U=0;U<S.length;U++)S[U].fill(0)}function u(S){return new DataView(S.buffer,S.byteOffset,S.byteLength)}function h(S,U){return S<<32-U|S>>>U}function d(S,U){return S<<U|S>>>32-U>>>0}e.isLE=new Uint8Array(new Uint32Array([0x11223344]).buffer)[0]===68;function g(S){return S<<24&0xff000000|S<<8&0xff0000|S>>>8&65280|S>>>24&255}e.swap8IfBE=e.isLE?S=>S:S=>g(S),e.byteSwapIfBE=e.swap8IfBE;function p(S){for(let U=0;U<S.length;U++)S[U]=g(S[U]);return S}e.swap32IfBE=e.isLE?S=>S:p;const m=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",b=Array.from({length:256},(S,U)=>U.toString(16).padStart(2,"0"));function x(S){if(i(S),m)return S.toHex();let U="";for(let O=0;O<S.length;O++)U+=b[S[O]];return U}const _={_0:48,_9:57,A:65,F:70,a:97,f:102};function E(S){if(S>=_._0&&S<=_._9)return S-_._0;if(S>=_.A&&S<=_.F)return S-(_.A-10);if(S>=_.a&&S<=_.f)return S-(_.a-10)}function k(S){if(typeof S!="string")throw new Error("hex string expected, got "+typeof S);if(m)return Uint8Array.fromHex(S);const U=S.length,O=U/2;if(U%2)throw new Error("hex string expected, got unpadded hex of length "+U);const F=new Uint8Array(O);for(let X=0,ie=0;X<O;X++,ie+=2){const se=E(S.charCodeAt(ie)),$e=E(S.charCodeAt(ie+1));if(se===void 0||$e===void 0){const Ce=S[ie]+S[ie+1];throw new Error('hex string expected, got non-hex character "'+Ce+'" at index '+ie)}F[X]=se*16+$e}return F}const C=async()=>{};e.nextTick=C;async function T(S,U,O){let F=Date.now();for(let X=0;X<S;X++){O(X);const ie=Date.now()-F;ie>=0&&ie<U||(await (0,e.nextTick)(),F+=ie)}}function j(S){if(typeof S!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(S))}function I(S){return new TextDecoder().decode(S)}function R(S){return typeof S=="string"&&(S=j(S)),i(S),S}function N(S){return typeof S=="string"&&(S=j(S)),i(S),S}function D(...S){let U=0;for(let F=0;F<S.length;F++){const X=S[F];i(X),U+=X.length}const O=new Uint8Array(U);for(let F=0,X=0;F<S.length;F++){const ie=S[F];O.set(ie,X),X+=ie.length}return O}function y(S,U){if(U!==void 0&&{}.toString.call(U)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(S,U)}class w{}e.Hash=w;function $(S){const U=F=>S().update(R(F)).digest(),O=S();return U.outputLen=O.outputLen,U.blockLen=O.blockLen,U.create=()=>S(),U}function P(S){const U=(F,X)=>S(X).update(R(F)).digest(),O=S({});return U.outputLen=O.outputLen,U.blockLen=O.blockLen,U.create=F=>S(F),U}function A(S){const U=(F,X)=>S(X).update(R(F)).digest(),O=S({});return U.outputLen=O.outputLen,U.blockLen=O.blockLen,U.create=F=>S(F),U}e.wrapConstructor=$,e.wrapConstructorWithOpts=P,e.wrapXOFConstructorWithOpts=A;function J(S=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(S));if(t.crypto&&typeof t.crypto.randomBytes=="function")return Uint8Array.from(t.crypto.randomBytes(S));throw new Error("crypto.getRandomValues must be defined")}})(jl)),jl}var Rg;function B3(){if(Rg)return cn;Rg=1,Object.defineProperty(cn,"__esModule",{value:!0}),cn.SHA512_IV=cn.SHA384_IV=cn.SHA224_IV=cn.SHA256_IV=cn.HashMD=void 0,cn.setBigUint64=t,cn.Chi=n,cn.Maj=r;const e=d_();function t(s,o,a,c){if(typeof s.setBigUint64=="function")return s.setBigUint64(o,a,c);const l=BigInt(32),f=BigInt(0xffffffff),u=Number(a>>l&f),h=Number(a&f),d=c?4:0,g=c?0:4;s.setUint32(o+d,u,c),s.setUint32(o+g,h,c)}function n(s,o,a){return s&o^~s&a}function r(s,o,a){return s&o^s&a^o&a}class i extends e.Hash{constructor(o,a,c,l){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=o,this.outputLen=a,this.padOffset=c,this.isLE=l,this.buffer=new Uint8Array(o),this.view=(0,e.createView)(this.buffer)}update(o){(0,e.aexists)(this),o=(0,e.toBytes)(o),(0,e.abytes)(o);const{view:a,buffer:c,blockLen:l}=this,f=o.length;for(let u=0;u<f;){const h=Math.min(l-this.pos,f-u);if(h===l){const d=(0,e.createView)(o);for(;l<=f-u;u+=l)this.process(d,u);continue}c.set(o.subarray(u,u+h),this.pos),this.pos+=h,u+=h,this.pos===l&&(this.process(a,0),this.pos=0)}return this.length+=o.length,this.roundClean(),this}digestInto(o){(0,e.aexists)(this),(0,e.aoutput)(o,this),this.finished=!0;const{buffer:a,view:c,blockLen:l,isLE:f}=this;let{pos:u}=this;a[u++]=128,(0,e.clean)(this.buffer.subarray(u)),this.padOffset>l-u&&(this.process(c,0),u=0);for(let m=u;m<l;m++)a[m]=0;t(c,l-8,BigInt(this.length*8),f),this.process(c,0);const h=(0,e.createView)(o),d=this.outputLen;if(d%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const g=d/4,p=this.get();if(g>p.length)throw new Error("_sha2: outputLen bigger than state");for(let m=0;m<g;m++)h.setUint32(4*m,p[m],f)}digest(){const{buffer:o,outputLen:a}=this;this.digestInto(o);const c=o.slice(0,a);return this.destroy(),c}_cloneInto(o){o||(o=new this.constructor),o.set(...this.get());const{blockLen:a,buffer:c,length:l,finished:f,destroyed:u,pos:h}=this;return o.destroyed=u,o.finished=f,o.length=l,o.pos=h,l%a&&o.buffer.set(c),o}clone(){return this._cloneInto()}}return cn.HashMD=i,cn.SHA256_IV=Uint32Array.from([0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19]),cn.SHA224_IV=Uint32Array.from([0xc1059ed8,0x367cd507,0x3070dd17,0xf70e5939,0xffc00b31,0x68581511,0x64f98fa7,0xbefa4fa4]),cn.SHA384_IV=Uint32Array.from([0xcbbb9d5d,0xc1059ed8,0x629a292a,0x367cd507,0x9159015a,0x3070dd17,0x152fecd8,0xf70e5939,0x67332667,0xffc00b31,0x8eb44a87,0x68581511,0xdb0c2e0d,0x64f98fa7,0x47b5481d,0xbefa4fa4]),cn.SHA512_IV=Uint32Array.from([0x6a09e667,0xf3bcc908,0xbb67ae85,0x84caa73b,0x3c6ef372,0xfe94f82b,0xa54ff53a,0x5f1d36f1,0x510e527f,0xade682d1,0x9b05688c,0x2b3e6c1f,0x1f83d9ab,0xfb41bd6b,0x5be0cd19,0x137e2179]),cn}var Ke={},Fg;function U3(){if(Fg)return Ke;Fg=1,Object.defineProperty(Ke,"__esModule",{value:!0}),Ke.toBig=Ke.shrSL=Ke.shrSH=Ke.rotrSL=Ke.rotrSH=Ke.rotrBL=Ke.rotrBH=Ke.rotr32L=Ke.rotr32H=Ke.rotlSL=Ke.rotlSH=Ke.rotlBL=Ke.rotlBH=Ke.add5L=Ke.add5H=Ke.add4L=Ke.add4H=Ke.add3L=Ke.add3H=void 0,Ke.add=b,Ke.fromBig=n,Ke.split=r;const e=BigInt(2**32-1),t=BigInt(32);function n(I,R=!1){return R?{h:Number(I&e),l:Number(I>>t&e)}:{h:Number(I>>t&e)|0,l:Number(I&e)|0}}function r(I,R=!1){const N=I.length;let D=new Uint32Array(N),y=new Uint32Array(N);for(let w=0;w<N;w++){const{h:$,l:P}=n(I[w],R);[D[w],y[w]]=[$,P]}return[D,y]}const i=(I,R)=>BigInt(I>>>0)<<t|BigInt(R>>>0);Ke.toBig=i;const s=(I,R,N)=>I>>>N;Ke.shrSH=s;const o=(I,R,N)=>I<<32-N|R>>>N;Ke.shrSL=o;const a=(I,R,N)=>I>>>N|R<<32-N;Ke.rotrSH=a;const c=(I,R,N)=>I<<32-N|R>>>N;Ke.rotrSL=c;const l=(I,R,N)=>I<<64-N|R>>>N-32;Ke.rotrBH=l;const f=(I,R,N)=>I>>>N-32|R<<64-N;Ke.rotrBL=f;const u=(I,R)=>R;Ke.rotr32H=u;const h=(I,R)=>I;Ke.rotr32L=h;const d=(I,R,N)=>I<<N|R>>>32-N;Ke.rotlSH=d;const g=(I,R,N)=>R<<N|I>>>32-N;Ke.rotlSL=g;const p=(I,R,N)=>R<<N-32|I>>>64-N;Ke.rotlBH=p;const m=(I,R,N)=>I<<N-32|R>>>64-N;Ke.rotlBL=m;function b(I,R,N,D){const y=(R>>>0)+(D>>>0);return{h:I+N+(y/2**32|0)|0,l:y|0}}const x=(I,R,N)=>(I>>>0)+(R>>>0)+(N>>>0);Ke.add3L=x;const _=(I,R,N,D)=>R+N+D+(I/2**32|0)|0;Ke.add3H=_;const E=(I,R,N,D)=>(I>>>0)+(R>>>0)+(N>>>0)+(D>>>0);Ke.add4L=E;const k=(I,R,N,D,y)=>R+N+D+y+(I/2**32|0)|0;Ke.add4H=k;const C=(I,R,N,D,y)=>(I>>>0)+(R>>>0)+(N>>>0)+(D>>>0)+(y>>>0);Ke.add5L=C;const T=(I,R,N,D,y,w)=>R+N+D+y+w+(I/2**32|0)|0;Ke.add5H=T;const j={fromBig:n,split:r,toBig:i,shrSH:s,shrSL:o,rotrSH:a,rotrSL:c,rotrBH:l,rotrBL:f,rotr32H:u,rotr32L:h,rotlSH:d,rotlSL:g,rotlBH:p,rotlBL:m,add:b,add3L:x,add3H:_,add4L:E,add4H:k,add5H:T,add5L:C};return Ke.default=j,Ke}var Bg;function j3(){if(Bg)return mt;Bg=1,Object.defineProperty(mt,"__esModule",{value:!0}),mt.sha512_224=mt.sha512_256=mt.sha384=mt.sha512=mt.sha224=mt.sha256=mt.SHA512_256=mt.SHA512_224=mt.SHA384=mt.SHA512=mt.SHA224=mt.SHA256=void 0;const e=B3(),t=U3(),n=d_(),r=Uint32Array.from([0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0xfc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x6ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2]),i=new Uint32Array(64);class s extends e.HashMD{constructor(_=32){super(64,_,8,!1),this.A=e.SHA256_IV[0]|0,this.B=e.SHA256_IV[1]|0,this.C=e.SHA256_IV[2]|0,this.D=e.SHA256_IV[3]|0,this.E=e.SHA256_IV[4]|0,this.F=e.SHA256_IV[5]|0,this.G=e.SHA256_IV[6]|0,this.H=e.SHA256_IV[7]|0}get(){const{A:_,B:E,C:k,D:C,E:T,F:j,G:I,H:R}=this;return[_,E,k,C,T,j,I,R]}set(_,E,k,C,T,j,I,R){this.A=_|0,this.B=E|0,this.C=k|0,this.D=C|0,this.E=T|0,this.F=j|0,this.G=I|0,this.H=R|0}process(_,E){for(let y=0;y<16;y++,E+=4)i[y]=_.getUint32(E,!1);for(let y=16;y<64;y++){const w=i[y-15],$=i[y-2],P=(0,n.rotr)(w,7)^(0,n.rotr)(w,18)^w>>>3,A=(0,n.rotr)($,17)^(0,n.rotr)($,19)^$>>>10;i[y]=A+i[y-7]+P+i[y-16]|0}let{A:k,B:C,C:T,D:j,E:I,F:R,G:N,H:D}=this;for(let y=0;y<64;y++){const w=(0,n.rotr)(I,6)^(0,n.rotr)(I,11)^(0,n.rotr)(I,25),$=D+w+(0,e.Chi)(I,R,N)+r[y]+i[y]|0,A=((0,n.rotr)(k,2)^(0,n.rotr)(k,13)^(0,n.rotr)(k,22))+(0,e.Maj)(k,C,T)|0;D=N,N=R,R=I,I=j+$|0,j=T,T=C,C=k,k=$+A|0}k=k+this.A|0,C=C+this.B|0,T=T+this.C|0,j=j+this.D|0,I=I+this.E|0,R=R+this.F|0,N=N+this.G|0,D=D+this.H|0,this.set(k,C,T,j,I,R,N,D)}roundClean(){(0,n.clean)(i)}destroy(){this.set(0,0,0,0,0,0,0,0),(0,n.clean)(this.buffer)}}mt.SHA256=s;class o extends s{constructor(){super(28),this.A=e.SHA224_IV[0]|0,this.B=e.SHA224_IV[1]|0,this.C=e.SHA224_IV[2]|0,this.D=e.SHA224_IV[3]|0,this.E=e.SHA224_IV[4]|0,this.F=e.SHA224_IV[5]|0,this.G=e.SHA224_IV[6]|0,this.H=e.SHA224_IV[7]|0}}mt.SHA224=o;const a=t.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(x=>BigInt(x))),c=a[0],l=a[1],f=new Uint32Array(80),u=new Uint32Array(80);class h extends e.HashMD{constructor(_=64){super(128,_,16,!1),this.Ah=e.SHA512_IV[0]|0,this.Al=e.SHA512_IV[1]|0,this.Bh=e.SHA512_IV[2]|0,this.Bl=e.SHA512_IV[3]|0,this.Ch=e.SHA512_IV[4]|0,this.Cl=e.SHA512_IV[5]|0,this.Dh=e.SHA512_IV[6]|0,this.Dl=e.SHA512_IV[7]|0,this.Eh=e.SHA512_IV[8]|0,this.El=e.SHA512_IV[9]|0,this.Fh=e.SHA512_IV[10]|0,this.Fl=e.SHA512_IV[11]|0,this.Gh=e.SHA512_IV[12]|0,this.Gl=e.SHA512_IV[13]|0,this.Hh=e.SHA512_IV[14]|0,this.Hl=e.SHA512_IV[15]|0}get(){const{Ah:_,Al:E,Bh:k,Bl:C,Ch:T,Cl:j,Dh:I,Dl:R,Eh:N,El:D,Fh:y,Fl:w,Gh:$,Gl:P,Hh:A,Hl:J}=this;return[_,E,k,C,T,j,I,R,N,D,y,w,$,P,A,J]}set(_,E,k,C,T,j,I,R,N,D,y,w,$,P,A,J){this.Ah=_|0,this.Al=E|0,this.Bh=k|0,this.Bl=C|0,this.Ch=T|0,this.Cl=j|0,this.Dh=I|0,this.Dl=R|0,this.Eh=N|0,this.El=D|0,this.Fh=y|0,this.Fl=w|0,this.Gh=$|0,this.Gl=P|0,this.Hh=A|0,this.Hl=J|0}process(_,E){for(let O=0;O<16;O++,E+=4)f[O]=_.getUint32(E),u[O]=_.getUint32(E+=4);for(let O=16;O<80;O++){const F=f[O-15]|0,X=u[O-15]|0,ie=t.rotrSH(F,X,1)^t.rotrSH(F,X,8)^t.shrSH(F,X,7),se=t.rotrSL(F,X,1)^t.rotrSL(F,X,8)^t.shrSL(F,X,7),$e=f[O-2]|0,Ce=u[O-2]|0,Oe=t.rotrSH($e,Ce,19)^t.rotrBH($e,Ce,61)^t.shrSH($e,Ce,6),ye=t.rotrSL($e,Ce,19)^t.rotrBL($e,Ce,61)^t.shrSL($e,Ce,6),ve=t.add4L(se,ye,u[O-7],u[O-16]),me=t.add4H(ve,ie,Oe,f[O-7],f[O-16]);f[O]=me|0,u[O]=ve|0}let{Ah:k,Al:C,Bh:T,Bl:j,Ch:I,Cl:R,Dh:N,Dl:D,Eh:y,El:w,Fh:$,Fl:P,Gh:A,Gl:J,Hh:S,Hl:U}=this;for(let O=0;O<80;O++){const F=t.rotrSH(y,w,14)^t.rotrSH(y,w,18)^t.rotrBH(y,w,41),X=t.rotrSL(y,w,14)^t.rotrSL(y,w,18)^t.rotrBL(y,w,41),ie=y&$^~y&A,se=w&P^~w&J,$e=t.add5L(U,X,se,l[O],u[O]),Ce=t.add5H($e,S,F,ie,c[O],f[O]),Oe=$e|0,ye=t.rotrSH(k,C,28)^t.rotrBH(k,C,34)^t.rotrBH(k,C,39),ve=t.rotrSL(k,C,28)^t.rotrBL(k,C,34)^t.rotrBL(k,C,39),me=k&T^k&I^T&I,_e=C&j^C&R^j&R;S=A|0,U=J|0,A=$|0,J=P|0,$=y|0,P=w|0,{h:y,l:w}=t.add(N|0,D|0,Ce|0,Oe|0),N=I|0,D=R|0,I=T|0,R=j|0,T=k|0,j=C|0;const xe=t.add3L(Oe,ve,_e);k=t.add3H(xe,Ce,ye,me),C=xe|0}({h:k,l:C}=t.add(this.Ah|0,this.Al|0,k|0,C|0)),{h:T,l:j}=t.add(this.Bh|0,this.Bl|0,T|0,j|0),{h:I,l:R}=t.add(this.Ch|0,this.Cl|0,I|0,R|0),{h:N,l:D}=t.add(this.Dh|0,this.Dl|0,N|0,D|0),{h:y,l:w}=t.add(this.Eh|0,this.El|0,y|0,w|0),{h:$,l:P}=t.add(this.Fh|0,this.Fl|0,$|0,P|0),{h:A,l:J}=t.add(this.Gh|0,this.Gl|0,A|0,J|0),{h:S,l:U}=t.add(this.Hh|0,this.Hl|0,S|0,U|0),this.set(k,C,T,j,I,R,N,D,y,w,$,P,A,J,S,U)}roundClean(){(0,n.clean)(f,u)}destroy(){(0,n.clean)(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}mt.SHA512=h;class d extends h{constructor(){super(48),this.Ah=e.SHA384_IV[0]|0,this.Al=e.SHA384_IV[1]|0,this.Bh=e.SHA384_IV[2]|0,this.Bl=e.SHA384_IV[3]|0,this.Ch=e.SHA384_IV[4]|0,this.Cl=e.SHA384_IV[5]|0,this.Dh=e.SHA384_IV[6]|0,this.Dl=e.SHA384_IV[7]|0,this.Eh=e.SHA384_IV[8]|0,this.El=e.SHA384_IV[9]|0,this.Fh=e.SHA384_IV[10]|0,this.Fl=e.SHA384_IV[11]|0,this.Gh=e.SHA384_IV[12]|0,this.Gl=e.SHA384_IV[13]|0,this.Hh=e.SHA384_IV[14]|0,this.Hl=e.SHA384_IV[15]|0}}mt.SHA384=d;const g=Uint32Array.from([0x8c3d37c8,0x19544da2,0x73e19966,0x89dcd4d6,0x1dfab7ae,0x32ff9c82,0x679dd514,0x582f9fcf,0xf6d2b69,0x7bd44da8,0x77e36f73,0x4c48942,0x3f9d85a8,0x6a1d36c8,0x1112e6ad,0x91d692a1]),p=Uint32Array.from([0x22312194,0xfc2bf72c,0x9f555fa3,0xc84c64c2,0x2393b86b,0x6f53b151,0x96387719,0x5940eabd,0x96283ee2,0xa88effe3,0xbe5e1e25,0x53863992,0x2b0199fc,0x2c85b8aa,0xeb72ddc,0x81c52ca2]);class m extends h{constructor(){super(28),this.Ah=g[0]|0,this.Al=g[1]|0,this.Bh=g[2]|0,this.Bl=g[3]|0,this.Ch=g[4]|0,this.Cl=g[5]|0,this.Dh=g[6]|0,this.Dl=g[7]|0,this.Eh=g[8]|0,this.El=g[9]|0,this.Fh=g[10]|0,this.Fl=g[11]|0,this.Gh=g[12]|0,this.Gl=g[13]|0,this.Hh=g[14]|0,this.Hl=g[15]|0}}mt.SHA512_224=m;class b extends h{constructor(){super(32),this.Ah=p[0]|0,this.Al=p[1]|0,this.Bh=p[2]|0,this.Bl=p[3]|0,this.Ch=p[4]|0,this.Cl=p[5]|0,this.Dh=p[6]|0,this.Dl=p[7]|0,this.Eh=p[8]|0,this.El=p[9]|0,this.Fh=p[10]|0,this.Fl=p[11]|0,this.Gh=p[12]|0,this.Gl=p[13]|0,this.Hh=p[14]|0,this.Hl=p[15]|0}}return mt.SHA512_256=b,mt.sha256=(0,n.createHasher)(()=>new s),mt.sha224=(0,n.createHasher)(()=>new o),mt.sha512=(0,n.createHasher)(()=>new h),mt.sha384=(0,n.createHasher)(()=>new d),mt.sha512_256=(0,n.createHasher)(()=>new b),mt.sha512_224=(0,n.createHasher)(()=>new m),mt}var Ug;function M3(){if(Ug)return Xn;Ug=1,Object.defineProperty(Xn,"__esModule",{value:!0}),Xn.sha224=Xn.SHA224=Xn.sha256=Xn.SHA256=void 0;const e=j3();return Xn.SHA256=e.SHA256,Xn.sha256=e.sha256,Xn.SHA224=e.SHA224,Xn.sha224=e.sha224,Xn}var Ml,jg;function L3(){if(jg)return Ml;jg=1;function e(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[o]=i}var a=t.length,c=t.charAt(0),l=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var p=0,m=0,b=0,x=g.length;b!==x&&g[b]===0;)b++,p++;for(var _=(x-b)*f+1>>>0,E=new Uint8Array(_);b!==x;){for(var k=g[b],C=0,T=_-1;(k!==0||C<m)&&T!==-1;T--,C++)k+=256*E[T]>>>0,E[T]=k%a>>>0,k=k/a>>>0;if(k!==0)throw new Error("Non-zero carry");m=C,b++}for(var j=_-m;j!==_&&E[j]===0;)j++;for(var I=c.repeat(p);j<_;++j)I+=t.charAt(E[j]);return I}function h(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;for(var p=0,m=0,b=0;g[p]===c;)m++,p++;for(var x=(g.length-p)*l+1>>>0,_=new Uint8Array(x);g[p];){var E=g.charCodeAt(p);if(E>255)return;var k=n[E];if(k===255)return;for(var C=0,T=x-1;(k!==0||C<b)&&T!==-1;T--,C++)k+=a*_[T]>>>0,_[T]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");b=C,p++}for(var j=x-b;j!==x&&_[j]===0;)j++;for(var I=new Uint8Array(m+(x-j)),R=m;j!==x;)I[R++]=_[j++];return I}function d(g){var p=h(g);if(p)return p;throw new Error("Non-base"+a+" character")}return{encode:u,decodeUnsafe:h,decode:d}}return Ml=e,Ml}var Ll,Mg;function N3(){return Mg||(Mg=1,Ll=L3()("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")),Ll}var Nl,Lg;function H3(){if(Lg)return Nl;Lg=1;var e=N3();return Nl=function(t){function n(o){var a=Uint8Array.from(o),c=t(a),l=a.length+4,f=new Uint8Array(l);return f.set(a,0),f.set(c.subarray(0,4),a.length),e.encode(f,l)}function r(o){var a=o.slice(0,-4),c=o.slice(-4),l=t(a);if(!(c[0]^l[0]|c[1]^l[1]|c[2]^l[2]|c[3]^l[3]))return a}function i(o){var a=e.decodeUnsafe(o);if(a)return r(a)}function s(o){var a=e.decode(o),c=r(a);if(!c)throw new Error("Invalid checksum");return c}return{encode:n,decode:s,decodeUnsafe:i}},Nl}var Hl,Ng;function Z3(){if(Ng)return Hl;Ng=1;var{sha256:e}=M3(),t=H3();function n(r){return e(e(r))}return Hl=t(n),Hl}Z3();let Ju;try{Ju=new TextDecoder}catch{}let Re,Ci,ue=0;const V3=105,W3=57342,q3=57343,Hg=57337,Zg=6,ns={};let Gs=11281e4,Er=1681e4,nt={},Ft,hc,gc=0,ko=0,Gt,Ln,Vt=[],Ku=[],xn,pn,to,Vg={useRecords:!1,mapsAsObjects:!0},Eo=!1,f_=2;try{new Function("")}catch{f_=1/0}class Ao{constructor(t){if(t&&((t.keyMap||t._keyMap)&&!t.useRecords&&(t.useRecords=!1,t.mapsAsObjects=!0),t.useRecords===!1&&t.mapsAsObjects===void 0&&(t.mapsAsObjects=!0),t.getStructures&&(t.getShared=t.getStructures),t.getShared&&!t.structures&&((t.structures=[]).uninitialized=!0),t.keyMap)){this.mapKey=new Map;for(let[n,r]of Object.entries(t.keyMap))this.mapKey.set(r,n)}Object.assign(this,t)}decodeKey(t){return this.keyMap&&this.mapKey.get(t)||t}encodeKey(t){return this.keyMap&&this.keyMap.hasOwnProperty(t)?this.keyMap[t]:t}encodeKeys(t){if(!this._keyMap)return t;let n=new Map;for(let[r,i]of Object.entries(t))n.set(this._keyMap.hasOwnProperty(r)?this._keyMap[r]:r,i);return n}decodeKeys(t){if(!this._keyMap||t.constructor.name!="Map")return t;if(!this._mapKey){this._mapKey=new Map;for(let[r,i]of Object.entries(this._keyMap))this._mapKey.set(i,r)}let n={};return t.forEach((r,i)=>n[Nn(this._mapKey.has(i)?this._mapKey.get(i):i)]=r),n}mapDecode(t,n){let r=this.decode(t);if(this._keyMap)switch(r.constructor.name){case"Array":return r.map(i=>this.decodeKeys(i))}return r}decode(t,n){if(Re)return m_(()=>(Qu(),this?this.decode(t,n):Ao.prototype.decode.call(Vg,t,n)));Ci=n>-1?n:t.length,ue=0,ko=0,hc=null,Gt=null,Re=t;try{pn=t.dataView||(t.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength))}catch(r){throw Re=null,t instanceof Uint8Array?r:new Error("Source must be a Uint8Array or Buffer but was a "+(t&&typeof t=="object"?t.constructor.name:typeof t))}if(this instanceof Ao){if(nt=this,xn=this.sharedValues&&(this.pack?new Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues),this.structures)return Ft=this.structures,ha();(!Ft||Ft.length>0)&&(Ft=[])}else nt=Vg,(!Ft||Ft.length>0)&&(Ft=[]),xn=null;return ha()}decodeMultiple(t,n){let r,i=0;try{let s=t.length;Eo=!0;let o=this?this.decode(t,s):pf.decode(t,s);if(n){if(n(o)===!1)return;for(;ue<s;)if(i=ue,n(ha())===!1)return}else{for(r=[o];ue<s;)i=ue,r.push(ha());return r}}catch(s){throw s.lastPosition=i,s.values=r,s}finally{Eo=!1,Qu()}}}function ha(){try{let e=it();if(Gt){if(ue>=Gt.postBundlePosition){let t=new Error("Unexpected bundle position");throw t.incomplete=!0,t}ue=Gt.postBundlePosition,Gt=null}if(ue==Ci)Ft=null,Re=null,Ln&&(Ln=null);else if(ue>Ci){let t=new Error("Unexpected end of CBOR data");throw t.incomplete=!0,t}else if(!Eo)throw new Error("Data read, but end of buffer not reached");return e}catch(e){throw Qu(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer"))&&(e.incomplete=!0),e}}function it(){let e=Re[ue++],t=e>>5;if(e=e&31,e>23)switch(e){case 24:e=Re[ue++];break;case 25:if(t==7)return Y3();e=pn.getUint16(ue),ue+=2;break;case 26:if(t==7){let n=pn.getFloat32(ue);if(nt.useFloat32>2){let r=gf[(Re[ue]&127)<<1|Re[ue+1]>>7];return ue+=4,(r*n+(n>0?.5:-.5)>>0)/r}return ue+=4,n}if(e=pn.getUint32(ue),ue+=4,t===1)return-1-e;break;case 27:if(t==7){let n=pn.getFloat64(ue);return ue+=8,n}if(t>1){if(pn.getUint32(ue)>0)throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");e=pn.getUint32(ue+4)}else nt.int64AsNumber?(e=pn.getUint32(ue)*0x100000000,e+=pn.getUint32(ue+4)):e=pn.getBigUint64(ue);ue+=8;break;case 31:switch(t){case 2:case 3:throw new Error("Indefinite length not supported for byte or text strings");case 4:let n=[],r,i=0;for(;(r=it())!=ns;){if(i>=Gs)throw new Error(`Array length exceeds ${Gs}`);n[i++]=r}return t==4?n:t==3?n.join(""):Buffer.concat(n);case 5:let s;if(nt.mapsAsObjects){let o={},a=0;if(nt.keyMap)for(;(s=it())!=ns;){if(a++>=Er)throw new Error(`Property count exceeds ${Er}`);o[Nn(nt.decodeKey(s))]=it()}else for(;(s=it())!=ns;){if(a++>=Er)throw new Error(`Property count exceeds ${Er}`);o[Nn(s)]=it()}return o}else{to&&(nt.mapsAsObjects=!0,to=!1);let o=new Map;if(nt.keyMap){let a=0;for(;(s=it())!=ns;){if(a++>=Er)throw new Error(`Map size exceeds ${Er}`);o.set(nt.decodeKey(s),it())}}else{let a=0;for(;(s=it())!=ns;){if(a++>=Er)throw new Error(`Map size exceeds ${Er}`);o.set(s,it())}}return o}case 7:return ns;default:throw new Error("Invalid major type for indefinite length "+t)}default:throw new Error("Unknown token "+e)}switch(t){case 0:return e;case 1:return~e;case 2:return G3(e);case 3:if(ko>=ue)return hc.slice(ue-gc,(ue+=e)-gc);if(ko==0&&Ci<140&&e<32){let i=e<16?h_(e):K3(e);if(i!=null)return i}return J3(e);case 4:if(e>=Gs)throw new Error(`Array length exceeds ${Gs}`);let n=new Array(e);for(let i=0;i<e;i++)n[i]=it();return n;case 5:if(e>=Er)throw new Error(`Map size exceeds ${Gs}`);if(nt.mapsAsObjects){let i={};if(nt.keyMap)for(let s=0;s<e;s++)i[Nn(nt.decodeKey(it()))]=it();else for(let s=0;s<e;s++)i[Nn(it())]=it();return i}else{to&&(nt.mapsAsObjects=!0,to=!1);let i=new Map;if(nt.keyMap)for(let s=0;s<e;s++)i.set(nt.decodeKey(it()),it());else for(let s=0;s<e;s++)i.set(it(),it());return i}case 6:if(e>=Hg){let i=Ft[e&8191];if(i)return i.read||(i.read=Gu(i)),i.read();if(e<65536){if(e==q3){let s=ls(),o=it(),a=it();Xu(o,a);let c={};if(nt.keyMap)for(let l=2;l<s;l++){let f=nt.decodeKey(a[l-2]);c[Nn(f)]=it()}else for(let l=2;l<s;l++){let f=a[l-2];c[Nn(f)]=it()}return c}else if(e==W3){let s=ls(),o=it();for(let a=2;a<s;a++)Xu(o++,it());return it()}else if(e==Hg)return r4();if(nt.getShared&&(hf(),i=Ft[e&8191],i))return i.read||(i.read=Gu(i)),i.read()}}let r=Vt[e];if(r)return r.handlesRead?r(it):r(it());{let i=it();for(let s=0;s<Ku.length;s++){let o=Ku[s](e,i);if(o!==void 0)return o}return new Di(i,e)}case 7:switch(e){case 20:return!1;case 21:return!0;case 22:return null;case 23:return;case 31:default:let i=(xn||wi())[e];if(i!==void 0)return i;throw new Error("Unknown token "+e)}default:if(isNaN(e)){let i=new Error("Unexpected end of CBOR data");throw i.incomplete=!0,i}throw new Error("Unknown CBOR token "+e)}}const Wg=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function Gu(e){if(!e)throw new Error("Structure is required in record definition");function t(){let n=Re[ue++];if(n=n&31,n>23)switch(n){case 24:n=Re[ue++];break;case 25:n=pn.getUint16(ue),ue+=2;break;case 26:n=pn.getUint32(ue),ue+=4;break;default:throw new Error("Expected array header, but got "+Re[ue-1])}let r=this.compiledReader;for(;r;){if(r.propertyCount===n)return r(it);r=r.next}if(this.slowReads++>=f_){let s=this.length==n?this:this.slice(0,n);return r=nt.keyMap?new Function("r","return {"+s.map(o=>nt.decodeKey(o)).map(o=>Wg.test(o)?Nn(o)+":r()":"["+JSON.stringify(o)+"]:r()").join(",")+"}"):new Function("r","return {"+s.map(o=>Wg.test(o)?Nn(o)+":r()":"["+JSON.stringify(o)+"]:r()").join(",")+"}"),this.compiledReader&&(r.next=this.compiledReader),r.propertyCount=n,this.compiledReader=r,r(it)}let i={};if(nt.keyMap)for(let s=0;s<n;s++)i[Nn(nt.decodeKey(this[s]))]=it();else for(let s=0;s<n;s++)i[Nn(this[s])]=it();return i}return e.slowReads=0,t}function Nn(e){if(typeof e=="string")return e==="__proto__"?"__proto_":e;if(typeof e=="number"||typeof e=="boolean"||typeof e=="bigint")return e.toString();if(e==null)return e+"";throw new Error("Invalid property name type "+typeof e)}let J3=Yu;function Yu(e){let t;if(e<16&&(t=h_(e)))return t;if(e>64&&Ju)return Ju.decode(Re.subarray(ue,ue+=e));const n=ue+e,r=[];for(t="";ue<n;){const i=Re[ue++];if((i&128)===0)r.push(i);else if((i&224)===192){const s=Re[ue++]&63,o=(i&31)<<6|s;o<128?r.push(65533):r.push(o)}else if((i&240)===224){const s=Re[ue++]&63,o=Re[ue++]&63,a=(i&31)<<12|s<<6|o;a<2048||a>=55296&&a<=57343?r.push(65533):r.push(a)}else if((i&248)===240){const s=Re[ue++]&63,o=Re[ue++]&63,a=Re[ue++]&63;let c=(i&7)<<18|s<<12|o<<6|a;c<65536||c>1114111?r.push(65533):(c>65535&&(c-=65536,r.push(c>>>10&1023|55296),c=56320|c&1023),r.push(c))}else r.push(65533);r.length>=4096&&(t+=Qt.apply(String,r),r.length=0)}return r.length>0&&(t+=Qt.apply(String,r)),t}let Qt=String.fromCharCode;function K3(e){let t=ue,n=new Array(e);for(let r=0;r<e;r++){const i=Re[ue++];if((i&128)>0){ue=t;return}n[r]=i}return Qt.apply(String,n)}function h_(e){if(e<4)if(e<2){if(e===0)return"";{let t=Re[ue++];if((t&128)>1){ue-=1;return}return Qt(t)}}else{let t=Re[ue++],n=Re[ue++];if((t&128)>0||(n&128)>0){ue-=2;return}if(e<3)return Qt(t,n);let r=Re[ue++];if((r&128)>0){ue-=3;return}return Qt(t,n,r)}else{let t=Re[ue++],n=Re[ue++],r=Re[ue++],i=Re[ue++];if((t&128)>0||(n&128)>0||(r&128)>0||(i&128)>0){ue-=4;return}if(e<6){if(e===4)return Qt(t,n,r,i);{let s=Re[ue++];if((s&128)>0){ue-=5;return}return Qt(t,n,r,i,s)}}else if(e<8){let s=Re[ue++],o=Re[ue++];if((s&128)>0||(o&128)>0){ue-=6;return}if(e<7)return Qt(t,n,r,i,s,o);let a=Re[ue++];if((a&128)>0){ue-=7;return}return Qt(t,n,r,i,s,o,a)}else{let s=Re[ue++],o=Re[ue++],a=Re[ue++],c=Re[ue++];if((s&128)>0||(o&128)>0||(a&128)>0||(c&128)>0){ue-=8;return}if(e<10){if(e===8)return Qt(t,n,r,i,s,o,a,c);{let l=Re[ue++];if((l&128)>0){ue-=9;return}return Qt(t,n,r,i,s,o,a,c,l)}}else if(e<12){let l=Re[ue++],f=Re[ue++];if((l&128)>0||(f&128)>0){ue-=10;return}if(e<11)return Qt(t,n,r,i,s,o,a,c,l,f);let u=Re[ue++];if((u&128)>0){ue-=11;return}return Qt(t,n,r,i,s,o,a,c,l,f,u)}else{let l=Re[ue++],f=Re[ue++],u=Re[ue++],h=Re[ue++];if((l&128)>0||(f&128)>0||(u&128)>0||(h&128)>0){ue-=12;return}if(e<14){if(e===12)return Qt(t,n,r,i,s,o,a,c,l,f,u,h);{let d=Re[ue++];if((d&128)>0){ue-=13;return}return Qt(t,n,r,i,s,o,a,c,l,f,u,h,d)}}else{let d=Re[ue++],g=Re[ue++];if((d&128)>0||(g&128)>0){ue-=14;return}if(e<15)return Qt(t,n,r,i,s,o,a,c,l,f,u,h,d,g);let p=Re[ue++];if((p&128)>0){ue-=15;return}return Qt(t,n,r,i,s,o,a,c,l,f,u,h,d,g,p)}}}}}function G3(e){return nt.copyBuffers?Uint8Array.prototype.slice.call(Re,ue,ue+=e):Re.subarray(ue,ue+=e)}let g_=new Float32Array(1),ga=new Uint8Array(g_.buffer,0,4);function Y3(){let e=Re[ue++],t=Re[ue++],n=(e&127)>>2;if(n===31)return t||e&3?NaN:e&128?-1/0:1/0;if(n===0){let r=((e&3)<<8|t)/0x1000000;return e&128?-r:r}return ga[3]=e&128|(n>>1)+56,ga[2]=(e&7)<<5|t>>3,ga[1]=t<<5,ga[0]=0,g_[0]}new Array(4096);class Di{constructor(t,n){this.value=t,this.tag=n}}Vt[0]=e=>new Date(e);Vt[1]=e=>new Date(Math.round(e*1e3));Vt[2]=e=>{let t=BigInt(0);for(let n=0,r=e.byteLength;n<r;n++)t=BigInt(e[n])+(t<<BigInt(8));return t};Vt[3]=e=>BigInt(-1)-Vt[2](e);Vt[4]=e=>+(e[1]+"e"+e[0]);Vt[5]=e=>e[1]*Math.exp(e[0]*Math.log(2));const Xu=(e,t)=>{e=e-57344;let n=Ft[e];n&&n.isShared&&((Ft.restoreStructures||(Ft.restoreStructures=[]))[e]=n),Ft[e]=t,t.read=Gu(t)};Vt[V3]=e=>{let t=e.length,n=e[1];Xu(e[0],n);let r={};for(let i=2;i<t;i++){let s=n[i-2];r[Nn(s)]=e[i]}return r};Vt[14]=e=>Gt?Gt[0].slice(Gt.position0,Gt.position0+=e):new Di(e,14);Vt[15]=e=>Gt?Gt[1].slice(Gt.position1,Gt.position1+=e):new Di(e,15);let X3={Error,RegExp};Vt[27]=e=>(X3[e[0]]||Error)(e[1],e[2]);const p_=e=>{if(Re[ue++]!=132){let n=new Error("Packed values structure must be followed by a 4 element array");throw Re.length<ue&&(n.incomplete=!0),n}let t=e();if(!t||!t.length){let n=new Error("Packed values structure must be followed by a 4 element array");throw n.incomplete=!0,n}return xn=xn?t.concat(xn.slice(t.length)):t,xn.prefixes=e(),xn.suffixes=e(),e()};p_.handlesRead=!0;Vt[51]=p_;Vt[Zg]=e=>{if(!xn)if(nt.getShared)hf();else return new Di(e,Zg);if(typeof e=="number")return xn[16+(e>=0?2*e:-2*e-1)];let t=new Error("No support for non-integer packed references yet");throw e===void 0&&(t.incomplete=!0),t};Vt[28]=e=>{Ln||(Ln=new Map,Ln.id=0);let t=Ln.id++,n=ue,r=Re[ue],i;r>>5==4?i=[]:i={};let s={target:i};Ln.set(t,s);let o=e();return s.used?(Object.getPrototypeOf(i)!==Object.getPrototypeOf(o)&&(ue=n,i=o,Ln.set(t,{target:i}),o=e()),Object.assign(i,o)):(s.target=o,o)};Vt[28].handlesRead=!0;Vt[29]=e=>{let t=Ln.get(e);return t.used=!0,t.target};Vt[258]=e=>new Set(e);(Vt[259]=e=>(nt.mapsAsObjects&&(nt.mapsAsObjects=!1,to=!0),e())).handlesRead=!0;function rs(e,t){return typeof e=="string"?e+t:e instanceof Array?e.concat(t):Object.assign({},e,t)}function wi(){if(!xn)if(nt.getShared)hf();else throw new Error("No packed values available");return xn}const Q3=0x53687264;Ku.push((e,t)=>{if(e>=225&&e<=255)return rs(wi().prefixes[e-224],t);if(e>=28704&&e<=32767)return rs(wi().prefixes[e-28672],t);if(e>=0x70001000&&e<=0x7fffffff)return rs(wi().prefixes[e-0x70000000],t);if(e>=216&&e<=223)return rs(t,wi().suffixes[e-216]);if(e>=27647&&e<=28671)return rs(t,wi().suffixes[e-27639]);if(e>=0x6c000400&&e<=0x6fffffff)return rs(t,wi().suffixes[e-0x6c000000]);if(e==Q3)return{packedValues:xn,structures:Ft.slice(0),version:t};if(e==55799)return t});const e4=new Uint8Array(new Uint16Array([1]).buffer)[0]==1,qg=[Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?{name:"BigUint64Array"}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?{name:"BigInt64Array"}:BigInt64Array,Float32Array,Float64Array],t4=[64,68,69,70,71,72,77,78,79,85,86];for(let e=0;e<qg.length;e++)n4(qg[e],t4[e]);function n4(e,t){let n="get"+e.name.slice(0,-5),r;typeof e=="function"?r=e.BYTES_PER_ELEMENT:e=null;for(let i=0;i<2;i++){if(!i&&r==1)continue;let s=r==2?1:r==4?2:r==8?3:0;Vt[i?t:t-4]=r==1||i==e4?o=>{if(!e)throw new Error("Could not find typed array for code "+t);return!nt.copyBuffers&&(r===1||r===2&&!(o.byteOffset&1)||r===4&&!(o.byteOffset&3)||r===8&&!(o.byteOffset&7))?new e(o.buffer,o.byteOffset,o.byteLength>>s):new e(Uint8Array.prototype.slice.call(o,0).buffer)}:o=>{if(!e)throw new Error("Could not find typed array for code "+t);let a=new DataView(o.buffer,o.byteOffset,o.byteLength),c=o.length>>s,l=new e(c),f=a[n];for(let u=0;u<c;u++)l[u]=f.call(a,u<<s,i);return l}}}function r4(){let e=ls(),t=ue+it();for(let r=2;r<e;r++){let i=ls();ue+=i}let n=ue;return ue=t,Gt=[Yu(ls()),Yu(ls())],Gt.position0=0,Gt.position1=0,Gt.postBundlePosition=ue,ue=n,it()}function ls(){let e=Re[ue++]&31;if(e>23)switch(e){case 24:e=Re[ue++];break;case 25:e=pn.getUint16(ue),ue+=2;break;case 26:e=pn.getUint32(ue),ue+=4;break}return e}function hf(){if(nt.getShared){let e=m_(()=>(Re=null,nt.getShared()))||{},t=e.structures||[];nt.sharedVersion=e.version,xn=nt.sharedValues=e.packedValues,Ft===!0?nt.structures=Ft=t:Ft.splice.apply(Ft,[0,t.length].concat(t))}}function m_(e){let t=Ci,n=ue,r=gc,i=ko,s=hc,o=Ln,a=Gt,c=new Uint8Array(Re.slice(0,Ci)),l=Ft,f=nt,u=Eo,h=e();return Ci=t,ue=n,gc=r,ko=i,hc=s,Ln=o,Gt=a,Re=c,Eo=u,Ft=l,nt=f,pn=new DataView(Re.buffer,Re.byteOffset,Re.byteLength),h}function Qu(){Re=null,Ln=null,Ft=null}const gf=new Array(147);for(let e=0;e<256;e++)gf[e]=+("1e"+Math.floor(45.15-e*.30103));let pf=new Ao({useRecords:!1});const i4=pf.decode;pf.decodeMultiple;let Ua;try{Ua=new TextEncoder}catch{}let ed,__;const Hc=typeof globalThis=="object"&&globalThis.Buffer,qo=typeof Hc<"u",Zl=qo?Hc.allocUnsafeSlow:Uint8Array,Jg=qo?Hc:Uint8Array,Kg=256,Gg=qo?0x100000000:0x7fd00000;let Vl,G,bt,q=0,Zr,qt=null;const s4=61440,o4=/[\u0080-\uFFFF]/,In=Symbol("record-id");class y_ extends Ao{constructor(t){super(t),this.offset=0;let n,r,i,s,o;t=t||{};let a=Jg.prototype.utf8Write?function(y,w){return G.utf8Write(y,w,G.byteLength-w)}:Ua&&Ua.encodeInto?function(y,w){return Ua.encodeInto(y,G.subarray(w)).written}:!1,c=this,l=t.structures||t.saveStructures,f=t.maxSharedStructures;if(f==null&&(f=l?128:0),f>8190)throw new Error("Maximum maxSharedStructure is 8190");let u=t.sequential;u&&(f=0),this.structures||(this.structures=[]),this.saveStructures&&(this.saveShared=this.saveStructures);let h,d,g=t.sharedValues,p;if(g){p=Object.create(null);for(let y=0,w=g.length;y<w;y++)p[g[y]]=y}let m=[],b=0,x=0;this.mapEncode=function(y,w){if(this._keyMap&&!this._mapped)switch(y.constructor.name){case"Array":y=y.map($=>this.encodeKeys($));break}return this.encode(y,w)},this.encode=function(y,w){if(G||(G=new Zl(8192),bt=new DataView(G.buffer,0,8192),q=0),Zr=G.length-10,Zr-q<2048?(G=new Zl(G.length),bt=new DataView(G.buffer,0,G.length),Zr=G.length-10,q=0):w===Qg&&(q=q+7&0x7ffffff8),n=q,c.useSelfDescribedHeader&&(bt.setUint32(q,0xd9d9f700),q+=3),o=c.structuredClone?new Map:null,c.bundleStrings&&typeof y!="string"?(qt=[],qt.size=1/0):qt=null,r=c.structures,r){if(r.uninitialized){let P=c.getShared()||{};c.structures=r=P.structures||[],c.sharedVersion=P.version;let A=c.sharedValues=P.packedValues;if(A){p={};for(let J=0,S=A.length;J<S;J++)p[A[J]]=J}}let $=r.length;if($>f&&!u&&($=f),!r.transitions){r.transitions=Object.create(null);for(let P=0;P<$;P++){let A=r[P];if(!A)continue;let J,S=r.transitions;for(let U=0,O=A.length;U<O;U++){S[In]===void 0&&(S[In]=P);let F=A[U];J=S[F],J||(J=S[F]=Object.create(null)),S=J}S[In]=P|1048576}}u||(r.nextId=$)}if(i&&(i=!1),s=r||[],d=p,t.pack){let $=new Map;if($.values=[],$.encoder=c,$.maxValues=t.maxPrivatePackedValues||(p?16:1/0),$.objectMap=p||!1,$.samplingPackedValues=h,ja(y,$),$.values.length>0){G[q++]=216,G[q++]=51,br(4);let P=$.values;_(P),br(0),br(0),d=Object.create(p||null);for(let A=0,J=P.length;A<J;A++)d[P[A]]=A}}Vl=w&ql;try{if(Vl)return;if(_(y),qt&&Xg(n,_),c.offset=q,o&&o.idsToInsert){q+=o.idsToInsert.length*2,q>Zr&&k(q),c.offset=q;let $=l4(G.subarray(n,q),o.idsToInsert);return o=null,$}return w&Qg?(G.start=n,G.end=q,G):G.subarray(n,q)}finally{if(r){if(x<10&&x++,r.length>f&&(r.length=f),b>1e4)r.transitions=null,x=0,b=0,m.length>0&&(m=[]);else if(m.length>0&&!u){for(let $=0,P=m.length;$<P;$++)m[$][In]=void 0;m=[]}}if(i&&c.saveShared){c.structures.length>f&&(c.structures=c.structures.slice(0,f));let $=G.subarray(n,q);return c.updateSharedData()===!1?c.encode(y):$}w&u4&&(q=n)}},this.findCommonStringsToPack=()=>(h=new Map,p||(p=Object.create(null)),y=>{let w=y&&y.threshold||4,$=this.pack?y.maxPrivatePackedValues||16:0;g||(g=this.sharedValues=[]);for(let[P,A]of h)A.count>w&&(p[P]=$++,g.push(P),i=!0);for(;this.saveShared&&this.updateSharedData()===!1;);h=null});const _=y=>{q>Zr&&(G=k(q));var w=typeof y,$;if(w==="string"){if(d){let S=d[y];if(S>=0){S<16?G[q++]=S+224:(G[q++]=198,S&1?_(15-S>>1):_(S-16>>1));return}else if(h&&!t.pack){let U=h.get(y);U?U.count++:h.set(y,{count:1})}}let P=y.length;if(qt&&P>=4&&P<1024){if((qt.size+=P)>s4){let U,O=(qt[0]?qt[0].length*3+qt[1].length:0)+10;q+O>Zr&&(G=k(q+O)),G[q++]=217,G[q++]=223,G[q++]=249,G[q++]=qt.position?132:130,G[q++]=26,U=q-n,q+=4,qt.position&&Xg(n,_),qt=["",""],qt.size=0,qt.position=U}let S=o4.test(y);qt[S?0:1]+=y,G[q++]=S?206:207,_(P);return}let A;P<32?A=1:P<256?A=2:P<65536?A=3:A=5;let J=P*3;if(q+J>Zr&&(G=k(q+J)),P<64||!a){let S,U,O,F=q+A;for(S=0;S<P;S++)U=y.charCodeAt(S),U<128?G[F++]=U:U<2048?(G[F++]=U>>6|192,G[F++]=U&63|128):(U&64512)===55296&&((O=y.charCodeAt(S+1))&64512)===56320?(U=65536+((U&1023)<<10)+(O&1023),S++,G[F++]=U>>18|240,G[F++]=U>>12&63|128,G[F++]=U>>6&63|128,G[F++]=U&63|128):(G[F++]=U>>12|224,G[F++]=U>>6&63|128,G[F++]=U&63|128);$=F-q-A}else $=a(y,q+A,J);$<24?G[q++]=96|$:$<256?(A<2&&G.copyWithin(q+2,q+1,q+1+$),G[q++]=120,G[q++]=$):$<65536?(A<3&&G.copyWithin(q+3,q+2,q+2+$),G[q++]=121,G[q++]=$>>8,G[q++]=$&255):(A<5&&G.copyWithin(q+5,q+3,q+3+$),G[q++]=122,bt.setUint32(q,$),q+=4),q+=$}else if(w==="number")if(!this.alwaysUseFloat&&y>>>0===y)y<24?G[q++]=y:y<256?(G[q++]=24,G[q++]=y):y<65536?(G[q++]=25,G[q++]=y>>8,G[q++]=y&255):(G[q++]=26,bt.setUint32(q,y),q+=4);else if(!this.alwaysUseFloat&&y>>0===y)y>=-24?G[q++]=31-y:y>=-256?(G[q++]=56,G[q++]=~y):y>=-65536?(G[q++]=57,bt.setUint16(q,~y),q+=2):(G[q++]=58,bt.setUint32(q,~y),q+=4);else if(!this.alwaysUseFloat&&y<0&&y>=-0x100000000&&Math.floor(y)===y)G[q++]=58,bt.setUint32(q,-1-y),q+=4;else{let P;if((P=this.useFloat32)>0&&y<0x100000000&&y>=-0x80000000){G[q++]=250,bt.setFloat32(q,y);let A;if(P<4||(A=y*gf[(G[q]&127)<<1|G[q+1]>>7])>>0===A){q+=4;return}else q--}G[q++]=251,bt.setFloat64(q,y),q+=8}else if(w==="object")if(!y)G[q++]=246;else{if(o){let A=o.get(y);if(A){if(G[q++]=216,G[q++]=29,G[q++]=25,!A.references){let J=o.idsToInsert||(o.idsToInsert=[]);A.references=[],J.push(A)}A.references.push(q-n),q+=2;return}else o.set(y,{offset:q-n})}let P=y.constructor;if(P===Object)this.skipFunction===!0&&(y=Object.fromEntries([...Object.keys(y).filter(A=>typeof y[A]!="function").map(A=>[A,y[A]])])),E(y);else if(P===Array){$=y.length,$<24?G[q++]=128|$:br($);for(let A=0;A<$;A++)_(y[A])}else if(P===Map)if((this.mapsAsObjects?this.useTag259ForMaps!==!1:this.useTag259ForMaps)&&(G[q++]=217,G[q++]=1,G[q++]=3),$=y.size,$<24?G[q++]=160|$:$<256?(G[q++]=184,G[q++]=$):$<65536?(G[q++]=185,G[q++]=$>>8,G[q++]=$&255):(G[q++]=186,bt.setUint32(q,$),q+=4),c.keyMap)for(let[A,J]of y)_(c.encodeKey(A)),_(J);else for(let[A,J]of y)_(A),_(J);else{for(let A=0,J=ed.length;A<J;A++){let S=__[A];if(y instanceof S){let U=ed[A],O=U.tag;O==null&&(O=U.getTag&&U.getTag.call(this,y)),O<24?G[q++]=192|O:O<256?(G[q++]=216,G[q++]=O):O<65536?(G[q++]=217,G[q++]=O>>8,G[q++]=O&255):O>-1&&(G[q++]=218,bt.setUint32(q,O),q+=4),U.encode.call(this,y,_,k);return}}if(y[Symbol.iterator]){if(Vl){let A=new Error("Iterable should be serialized as iterator");throw A.iteratorNotHandled=!0,A}G[q++]=159;for(let A of y)_(A);G[q++]=255;return}if(y[Symbol.asyncIterator]||Wl(y)){let A=new Error("Iterable/blob should be serialized as iterator");throw A.iteratorNotHandled=!0,A}if(this.useToJSON&&y.toJSON){const A=y.toJSON();if(A!==y)return _(A)}E(y)}}else if(w==="boolean")G[q++]=y?245:244;else if(w==="bigint"){if(y<BigInt(1)<<BigInt(64)&&y>=0)G[q++]=27,bt.setBigUint64(q,y);else if(y>-(BigInt(1)<<BigInt(64))&&y<0)G[q++]=59,bt.setBigUint64(q,-y-BigInt(1));else if(this.largeBigIntToFloat)G[q++]=251,bt.setFloat64(q,Number(y));else{y>=BigInt(0)?G[q++]=194:(G[q++]=195,y=BigInt(-1)-y);let P=[];for(;y;)P.push(Number(y&BigInt(255))),y>>=BigInt(8);td(new Uint8Array(P.reverse()),k);return}q+=8}else if(w==="undefined")G[q++]=247;else throw new Error("Unknown type: "+w)},E=this.useRecords===!1?this.variableMapSize?y=>{let w=Object.keys(y),$=Object.values(y),P=w.length;if(P<24?G[q++]=160|P:P<256?(G[q++]=184,G[q++]=P):P<65536?(G[q++]=185,G[q++]=P>>8,G[q++]=P&255):(G[q++]=186,bt.setUint32(q,P),q+=4),c.keyMap)for(let A=0;A<P;A++)_(c.encodeKey(w[A])),_($[A]);else for(let A=0;A<P;A++)_(w[A]),_($[A])}:y=>{G[q++]=185;let w=q-n;q+=2;let $=0;if(c.keyMap)for(let P in y)(typeof y.hasOwnProperty!="function"||y.hasOwnProperty(P))&&(_(c.encodeKey(P)),_(y[P]),$++);else for(let P in y)(typeof y.hasOwnProperty!="function"||y.hasOwnProperty(P))&&(_(P),_(y[P]),$++);G[w+++n]=$>>8,G[w+n]=$&255}:(y,w)=>{let $,P=s.transitions||(s.transitions=Object.create(null)),A=0,J=0,S,U;if(this.keyMap){U=Object.keys(y).map(F=>this.encodeKey(F)),J=U.length;for(let F=0;F<J;F++){let X=U[F];$=P[X],$||($=P[X]=Object.create(null),A++),P=$}}else for(let F in y)(typeof y.hasOwnProperty!="function"||y.hasOwnProperty(F))&&($=P[F],$||(P[In]&1048576&&(S=P[In]&65535),$=P[F]=Object.create(null),A++),P=$,J++);let O=P[In];if(O!==void 0)O&=65535,G[q++]=217,G[q++]=O>>8|224,G[q++]=O&255;else if(U||(U=P.__keys__||(P.__keys__=Object.keys(y))),S===void 0?(O=s.nextId++,O||(O=0,s.nextId=1),O>=Kg&&(s.nextId=(O=f)+1)):O=S,s[O]=U,O<f){G[q++]=217,G[q++]=O>>8|224,G[q++]=O&255,P=s.transitions;for(let F=0;F<J;F++)(P[In]===void 0||P[In]&1048576)&&(P[In]=O),P=P[U[F]];P[In]=O|1048576,i=!0}else{if(P[In]=O,bt.setUint32(q,0xd9dfff00),q+=3,A&&(b+=x*A),m.length>=Kg-f&&(m.shift()[In]=void 0),m.push(P),br(J+2),_(57344+O),_(U),w)return;for(let F in y)(typeof y.hasOwnProperty!="function"||y.hasOwnProperty(F))&&_(y[F]);return}if(J<24?G[q++]=128|J:br(J),!w)for(let F in y)(typeof y.hasOwnProperty!="function"||y.hasOwnProperty(F))&&_(y[F])},k=y=>{let w;if(y>0x1000000){if(y-n>Gg)throw new Error("Encoded buffer would be larger than maximum buffer size");w=Math.min(Gg,Math.round(Math.max((y-n)*(y>0x4000000?1.25:2),4194304)/4096)*4096)}else w=(Math.max(y-n<<2,G.length-1)>>12)+1<<12;let $=new Zl(w);return bt=new DataView($.buffer,0,w),G.copy?G.copy($,0,n,y):$.set(G.slice(n,y)),q-=n,n=0,Zr=$.length-10,G=$};let C=100,T=1e3;this.encodeAsIterable=function(y,w){return N(y,w,j)},this.encodeAsAsyncIterable=function(y,w){return N(y,w,D)};function*j(y,w,$){let P=y.constructor;if(P===Object){let A=c.useRecords!==!1;A?E(y,!0):Yg(Object.keys(y).length,160);for(let J in y){let S=y[J];A||_(J),S&&typeof S=="object"?w[J]?yield*j(S,w[J]):yield*I(S,w,J):_(S)}}else if(P===Array){let A=y.length;br(A);for(let J=0;J<A;J++){let S=y[J];S&&(typeof S=="object"||q-n>C)?w.element?yield*j(S,w.element):yield*I(S,w,"element"):_(S)}}else if(y[Symbol.iterator]&&!y.buffer){G[q++]=159;for(let A of y)A&&(typeof A=="object"||q-n>C)?w.element?yield*j(A,w.element):yield*I(A,w,"element"):_(A);G[q++]=255}else Wl(y)?(Yg(y.size,64),yield G.subarray(n,q),yield y,R()):y[Symbol.asyncIterator]?(G[q++]=159,yield G.subarray(n,q),yield y,R(),G[q++]=255):_(y);$&&q>n?yield G.subarray(n,q):q-n>C&&(yield G.subarray(n,q),R())}function*I(y,w,$){let P=q-n;try{_(y),q-n>C&&(yield G.subarray(n,q),R())}catch(A){if(A.iteratorNotHandled)w[$]={},q=n+P,yield*j.call(this,y,w[$]);else throw A}}function R(){C=T,c.encode(null,ql)}function N(y,w,$){return w&&w.chunkThreshold?C=T=w.chunkThreshold:C=100,y&&typeof y=="object"?(c.encode(null,ql),$(y,c.iterateProperties||(c.iterateProperties={}),!0)):[c.encode(y)]}async function*D(y,w){for(let $ of j(y,w,!0)){let P=$.constructor;if(P===Jg||P===Uint8Array)yield $;else if(Wl($)){let A=$.stream().getReader(),J;for(;!(J=await A.read()).done;)yield J.value}else if($[Symbol.asyncIterator])for await(let A of $)R(),A?yield*D(A,w.async||(w.async={})):yield c.encode(A);else yield $}}}useBuffer(t){G=t,bt=new DataView(G.buffer,G.byteOffset,G.byteLength),q=0}clearSharedData(){this.structures&&(this.structures=[]),this.sharedValues&&(this.sharedValues=void 0)}updateSharedData(){let t=this.sharedVersion||0;this.sharedVersion=t+1;let n=this.structures.slice(0),r=new b_(n,this.sharedValues,this.sharedVersion),i=this.saveShared(r,s=>(s&&s.version||0)==t);return i===!1?(r=this.getShared()||{},this.structures=r.structures||[],this.sharedValues=r.packedValues,this.sharedVersion=r.version,this.structures.nextId=this.structures.length):n.forEach((s,o)=>this.structures[o]=s),i}}function Yg(e,t){e<24?G[q++]=t|e:e<256?(G[q++]=t|24,G[q++]=e):e<65536?(G[q++]=t|25,G[q++]=e>>8,G[q++]=e&255):(G[q++]=t|26,bt.setUint32(q,e),q+=4)}class b_{constructor(t,n,r){this.structures=t,this.packedValues=n,this.version=r}}function br(e){e<24?G[q++]=128|e:e<256?(G[q++]=152,G[q++]=e):e<65536?(G[q++]=153,G[q++]=e>>8,G[q++]=e&255):(G[q++]=154,bt.setUint32(q,e),q+=4)}const a4=typeof Blob>"u"?function(){}:Blob;function Wl(e){if(e instanceof a4)return!0;let t=e[Symbol.toStringTag];return t==="Blob"||t==="File"}function ja(e,t){switch(typeof e){case"string":if(e.length>3){if(t.objectMap[e]>-1||t.values.length>=t.maxValues)return;let r=t.get(e);if(r)++r.count==2&&t.values.push(e);else if(t.set(e,{count:1}),t.samplingPackedValues){let i=t.samplingPackedValues.get(e);i?i.count++:t.samplingPackedValues.set(e,{count:1})}}break;case"object":if(e)if(e instanceof Array)for(let r=0,i=e.length;r<i;r++)ja(e[r],t);else{let r=!t.encoder.useRecords;for(var n in e)e.hasOwnProperty(n)&&(r&&ja(n,t),ja(e[n],t))}break;case"function":console.log(e)}}const c4=new Uint8Array(new Uint16Array([1]).buffer)[0]==1;__=[Date,Set,Error,RegExp,Di,ArrayBuffer,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?function(){}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?function(){}:BigInt64Array,Float32Array,Float64Array,b_];ed=[{tag:1,encode(e,t){let n=e.getTime()/1e3;(this.useTimestamp32||e.getMilliseconds()===0)&&n>=0&&n<0x100000000?(G[q++]=26,bt.setUint32(q,n),q+=4):(G[q++]=251,bt.setFloat64(q,n),q+=8)}},{tag:258,encode(e,t){let n=Array.from(e);t(n)}},{tag:27,encode(e,t){t([e.name,e.message])}},{tag:27,encode(e,t){t(["RegExp",e.source,e.flags])}},{getTag(e){return e.tag},encode(e,t){t(e.value)}},{encode(e,t,n){td(e,n)}},{getTag(e){if(e.constructor===Uint8Array&&(this.tagUint8Array||qo&&this.tagUint8Array!==!1))return 64},encode(e,t,n){td(e,n)}},mr(68,1),mr(69,2),mr(70,4),mr(71,8),mr(72,1),mr(77,2),mr(78,4),mr(79,8),mr(85,4),mr(86,8),{encode(e,t){let n=e.packedValues||[],r=e.structures||[];if(n.values.length>0){G[q++]=216,G[q++]=51,br(4);let i=n.values;t(i),br(0),br(0),packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let s=0,o=i.length;s<o;s++)packedObjectMap[i[s]]=s}if(r){bt.setUint32(q,0xd9dffe00),q+=3;let i=r.slice(0);i.unshift(57344),i.push(new Di(e.version,0x53687264)),t(i)}else t(new Di(e.version,0x53687264))}}];function mr(e,t){return!c4&&t>1&&(e-=4),{tag:e,encode:function(r,i){let s=r.byteLength,o=r.byteOffset||0,a=r.buffer||r;i(qo?Hc.from(a,o,s):new Uint8Array(a,o,s))}}}function td(e,t){let n=e.byteLength;n<24?G[q++]=64+n:n<256?(G[q++]=88,G[q++]=n):n<65536?(G[q++]=89,G[q++]=n>>8,G[q++]=n&255):(G[q++]=90,bt.setUint32(q,n),q+=4),q+n>=G.length&&t(q+n),G.set(e.buffer?e:new Uint8Array(e),q),q+=n}function l4(e,t){let n,r=t.length*2,i=e.length-r;t.sort((s,o)=>s.offset>o.offset?1:-1);for(let s=0;s<t.length;s++){let o=t[s];o.id=s;for(let a of o.references)e[a++]=s>>8,e[a]=s&255}for(;n=t.pop();){let s=n.offset;e.copyWithin(s+r,s,i),r-=2;let o=s+r;e[o++]=216,e[o++]=28,i=s}return e}function Xg(e,t){bt.setUint32(qt.position+e,q-qt.position-e+1);let n=qt;qt=null,t(n[0]),t(n[1])}let mf=new y_({useRecords:!1});mf.encode;mf.encodeAsIterable;mf.encodeAsAsyncIterable;const Qg=512,u4=1024,ql=2048;function d4(e){return new y_({tagUint8Array:!1,useRecords:!1}).encode(e)}function f4(e){return i4(e)}var Ma={exports:{}},h4=Ma.exports,e0;function g4(){return e0||(e0=1,(function(e){(function(t,n){var r={};n(r);var i=r.default;for(var s in r)i[s]=r[s];e.exports=i})(h4,function(t){t.__esModule=!0,t.digestLength=32,t.blockSize=64;var n=new Uint32Array([0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0xfc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x6ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2]);function r(h,d,g,p,m){for(var b,x,_,E,k,C,T,j,I,R,N,D,y;m>=64;){for(b=d[0],x=d[1],_=d[2],E=d[3],k=d[4],C=d[5],T=d[6],j=d[7],R=0;R<16;R++)N=p+R*4,h[R]=(g[N]&255)<<24|(g[N+1]&255)<<16|(g[N+2]&255)<<8|g[N+3]&255;for(R=16;R<64;R++)I=h[R-2],D=(I>>>17|I<<15)^(I>>>19|I<<13)^I>>>10,I=h[R-15],y=(I>>>7|I<<25)^(I>>>18|I<<14)^I>>>3,h[R]=(D+h[R-7]|0)+(y+h[R-16]|0);for(R=0;R<64;R++)D=(((k>>>6|k<<26)^(k>>>11|k<<21)^(k>>>25|k<<7))+(k&C^~k&T)|0)+(j+(n[R]+h[R]|0)|0)|0,y=((b>>>2|b<<30)^(b>>>13|b<<19)^(b>>>22|b<<10))+(b&x^b&_^x&_)|0,j=T,T=C,C=k,k=E+D|0,E=_,_=x,x=b,b=D+y|0;d[0]+=b,d[1]+=x,d[2]+=_,d[3]+=E,d[4]+=k,d[5]+=C,d[6]+=T,d[7]+=j,p+=64,m-=64}return p}var i=(function(){function h(){this.digestLength=t.digestLength,this.blockSize=t.blockSize,this.state=new Int32Array(8),this.temp=new Int32Array(64),this.buffer=new Uint8Array(128),this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this.reset()}return h.prototype.reset=function(){return this.state[0]=0x6a09e667,this.state[1]=0xbb67ae85,this.state[2]=0x3c6ef372,this.state[3]=0xa54ff53a,this.state[4]=0x510e527f,this.state[5]=0x9b05688c,this.state[6]=0x1f83d9ab,this.state[7]=0x5be0cd19,this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this},h.prototype.clean=function(){for(var d=0;d<this.buffer.length;d++)this.buffer[d]=0;for(var d=0;d<this.temp.length;d++)this.temp[d]=0;this.reset()},h.prototype.update=function(d,g){if(g===void 0&&(g=d.length),this.finished)throw new Error("SHA256: can't update because hash was finished.");var p=0;if(this.bytesHashed+=g,this.bufferLength>0){for(;this.bufferLength<64&&g>0;)this.buffer[this.bufferLength++]=d[p++],g--;this.bufferLength===64&&(r(this.temp,this.state,this.buffer,0,64),this.bufferLength=0)}for(g>=64&&(p=r(this.temp,this.state,d,p,g),g%=64);g>0;)this.buffer[this.bufferLength++]=d[p++],g--;return this},h.prototype.finish=function(d){if(!this.finished){var g=this.bytesHashed,p=this.bufferLength,m=g/0x20000000|0,b=g<<3,x=g%64<56?64:128;this.buffer[p]=128;for(var _=p+1;_<x-8;_++)this.buffer[_]=0;this.buffer[x-8]=m>>>24&255,this.buffer[x-7]=m>>>16&255,this.buffer[x-6]=m>>>8&255,this.buffer[x-5]=m>>>0&255,this.buffer[x-4]=b>>>24&255,this.buffer[x-3]=b>>>16&255,this.buffer[x-2]=b>>>8&255,this.buffer[x-1]=b>>>0&255,r(this.temp,this.state,this.buffer,0,x),this.finished=!0}for(var _=0;_<8;_++)d[_*4+0]=this.state[_]>>>24&255,d[_*4+1]=this.state[_]>>>16&255,d[_*4+2]=this.state[_]>>>8&255,d[_*4+3]=this.state[_]>>>0&255;return this},h.prototype.digest=function(){var d=new Uint8Array(this.digestLength);return this.finish(d),d},h.prototype._saveState=function(d){for(var g=0;g<this.state.length;g++)d[g]=this.state[g]},h.prototype._restoreState=function(d,g){for(var p=0;p<this.state.length;p++)this.state[p]=d[p];this.bytesHashed=g,this.finished=!1,this.bufferLength=0},h})();t.Hash=i;var s=(function(){function h(d){this.inner=new i,this.outer=new i,this.blockSize=this.inner.blockSize,this.digestLength=this.inner.digestLength;var g=new Uint8Array(this.blockSize);if(d.length>this.blockSize)new i().update(d).finish(g).clean();else for(var p=0;p<d.length;p++)g[p]=d[p];for(var p=0;p<g.length;p++)g[p]^=54;this.inner.update(g);for(var p=0;p<g.length;p++)g[p]^=106;this.outer.update(g),this.istate=new Uint32Array(8),this.ostate=new Uint32Array(8),this.inner._saveState(this.istate),this.outer._saveState(this.ostate);for(var p=0;p<g.length;p++)g[p]=0}return h.prototype.reset=function(){return this.inner._restoreState(this.istate,this.inner.blockSize),this.outer._restoreState(this.ostate,this.outer.blockSize),this},h.prototype.clean=function(){for(var d=0;d<this.istate.length;d++)this.ostate[d]=this.istate[d]=0;this.inner.clean(),this.outer.clean()},h.prototype.update=function(d){return this.inner.update(d),this},h.prototype.finish=function(d){return this.outer.finished?this.outer.finish(d):(this.inner.finish(d),this.outer.update(d,this.digestLength).finish(d)),this},h.prototype.digest=function(){var d=new Uint8Array(this.digestLength);return this.finish(d),d},h})();t.HMAC=s;function o(h){var d=new i().update(h),g=d.digest();return d.clean(),g}t.hash=o,t.default=o;function a(h,d){var g=new s(h).update(d),p=g.digest();return g.clean(),p}t.hmac=a;function c(h,d,g,p){var m=p[0];if(m===0)throw new Error("hkdf: cannot expand more");d.reset(),m>1&&d.update(h),g&&d.update(g),d.update(p),d.finish(h),p[0]++}var l=new Uint8Array(t.digestLength);function f(h,d,g,p){d===void 0&&(d=l),p===void 0&&(p=32);for(var m=new Uint8Array([1]),b=a(d,h),x=new s(b),_=new Uint8Array(x.digestLength),E=_.length,k=new Uint8Array(p),C=0;C<p;C++)E===_.length&&(c(_,x,g,m),E=0),k[C]=_[E++];return x.clean(),_.fill(0),m.fill(0),k}t.hkdf=f;function u(h,d,g,p){for(var m=new s(h),b=m.digestLength,x=new Uint8Array(4),_=new Uint8Array(b),E=new Uint8Array(b),k=new Uint8Array(p),C=0;C*b<p;C++){var T=C+1;x[0]=T>>>24&255,x[1]=T>>>16&255,x[2]=T>>>8&255,x[3]=T>>>0&255,m.reset(),m.update(d),m.update(x),m.finish(E);for(var j=0;j<b;j++)_[j]=E[j];for(var j=2;j<=g;j++){m.reset(),m.update(E).finish(E);for(var I=0;I<b;I++)_[I]^=E[I]}for(var j=0;j<b&&C*b+j<p;j++)k[C*b+j]=_[j]}for(var C=0;C<b;C++)_[C]=E[C]=0;for(var C=0;C<4;C++)x[C]=0;return m.clean(),k}t.pbkdf2=u})})(Ma)),Ma.exports}g4();P3("automerge-repo:collectionsync");new FinalizationRegistry(e=>e());new Promise(()=>{});class p4 extends R3{peerId;peerMetadata}const m4="/assets/automerge_wasm_bg-Cik4BF9l.wasm";class Io{static __wrap(t){t=t>>>0;const n=Object.create(Io.prototype);return n.__wbg_ptr=t,t0.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,t0.unregister(this),t}free(){const t=this.__destroy_into_raw();st.__wbg_syncstate_free(t,0)}clone(){const t=st.syncstate_clone(this.__wbg_ptr);return Io.__wrap(t)}get lastSentHeads(){return st.syncstate_lastSentHeads(this.__wbg_ptr)}get peerReadOnly(){return st.syncstate_peerReadOnly(this.__wbg_ptr)!==0}get readOnly(){return st.syncstate_readOnly(this.__wbg_ptr)!==0}set lastSentHeads(t){const n=st.syncstate_set_lastSentHeads(this.__wbg_ptr,t);if(n[1])throw n0(n[0])}set readOnly(t){st.syncstate_set_readOnly(this.__wbg_ptr,t)}set sentHashes(t){const n=st.syncstate_set_sentHashes(this.__wbg_ptr,t);if(n[1])throw n0(n[0])}get sharedHeads(){return st.syncstate_sharedHeads(this.__wbg_ptr)}}Symbol.dispose&&(Io.prototype[Symbol.dispose]=Io.prototype.free);function _4(e){return BigInt(e)}function y4(e,t){return Error(Li(e,t))}function b4(e,t){const n=String(t),r=Ds(n,st.__wbindgen_malloc,st.__wbindgen_realloc),i=ci;$n().setInt32(e+4,i,!0),$n().setInt32(e+0,r,!0)}function w4(e){const t=e,n=typeof t=="boolean"?t:void 0;return Co(n)?0xffffff:n?1:0}function v4(e,t){const n=nd(t),r=Ds(n,st.__wbindgen_malloc,st.__wbindgen_realloc),i=ci;$n().setInt32(e+4,i,!0),$n().setInt32(e+0,r,!0)}function x4(e,t){return e>t}function S4(e){return typeof e=="bigint"}function $4(e){return typeof e=="function"}function k4(e){return e===null}function E4(e){const t=e;return typeof t=="object"&&t!==null}function A4(e){return typeof e=="string"}function I4(e){return e===void 0}function C4(e,t){return e==t}function z4(e,t){return e<t}function O4(e){return-e}function P4(e,t){const n=t,r=typeof n=="number"?n:void 0;$n().setFloat64(e+8,Co(r)?0:r,!0),$n().setInt32(e+0,!Co(r),!0)}function T4(e,t){const n=t,r=typeof n=="string"?n:void 0;var i=Co(r)?0:Ds(r,st.__wbindgen_malloc,st.__wbindgen_realloc),s=ci;$n().setInt32(e+4,s,!0),$n().setInt32(e+0,i,!0)}function D4(e,t){throw new Error(Li(e,t))}function R4(){return lr(function(e,t,n){return Reflect.apply(e,t,n)},arguments)}function F4(e,t){return Object.assign(e,t)}function B4(){return lr(function(e,t){return e.call(t)},arguments)}function U4(){return lr(function(e,t,n){return e.call(t,n)},arguments)}function j4(e,t){return e.concat(t)}function M4(e,t,n){return Object.defineProperty(e,t,n)}function L4(){return lr(function(e,t){return Reflect.deleteProperty(e,t)},arguments)}function N4(e){return e.done}function H4(e){return Object.entries(e)}function Z4(e,t){let n,r;try{n=e,r=t,console.error(Li(e,t))}finally{st.__wbindgen_free(n,r,1)}}function V4(e,t){return Symbol.for(Li(e,t))}function W4(e){return Object.freeze(e)}function q4(e){return Array.from(e)}function J4(){return lr(function(e,t){globalThis.crypto.getRandomValues(_f(e,t))},arguments)}function K4(e){return e.getTime()}function G4(){return lr(function(e,t){return Reflect.get(e,t)},arguments)}function Y4(){return lr(function(e,t){return Reflect.get(e,t)},arguments)}function X4(e,t){return e[t>>>0]}function Q4(e,t){return e[t>>>0]}function e5(e){let t;try{t=e instanceof ArrayBuffer}catch{t=!1}return t}function t5(e){let t;try{t=e instanceof Date}catch{t=!1}return t}function n5(e){let t;try{t=e instanceof Object}catch{t=!1}return t}function r5(e){let t;try{t=e instanceof Uint8Array}catch{t=!1}return t}function i5(e){return Array.isArray(e)}function s5(e){return Array.isArray(e)}function o5(){return Symbol.iterator}function a5(e){return Object.keys(e)}function c5(e){return e.length}function l5(e){return e.length}function u5(e){return e.length}function d5(e){console.log(e)}function f5(e,t){console.log(e,t)}function h5(e){return new Uint8Array(e)}function g5(e,t){return new RangeError(Li(e,t))}function p5(){return new Error}function m5(e,t){return new Error(Li(e,t))}function _5(){return new Array}function y5(e){return new Date(e)}function b5(){return new Object}function w5(e,t){return new Uint8Array(_f(e,t))}function v5(){return lr(function(e){return e.next()},arguments)}function x5(e){return e.next}function S5(){return lr(function(e){return Reflect.ownKeys(e)},arguments)}function $5(e,t,n){Uint8Array.prototype.set.call(_f(e,t),n)}function k5(e,t){return e.push(t)}function E5(){return lr(function(e,t,n){return Reflect.set(e,t,n)},arguments)}function A5(e,t,n){e[t>>>0]=n}function I5(e,t,n){e[t]=n}function C5(e,t,n){return e.slice(t>>>0,n>>>0)}function z5(e,t){const n=t.stack,r=Ds(n,st.__wbindgen_malloc,st.__wbindgen_realloc),i=ci;$n().setInt32(e+4,i,!0),$n().setInt32(e+0,r,!0)}function O5(e,t){const n=JSON.stringify(t);var r=Co(n)?0:Ds(n,st.__wbindgen_malloc,st.__wbindgen_realloc),i=ci;$n().setInt32(e+4,i,!0),$n().setInt32(e+0,r,!0)}function P5(e){return e.toString()}function T5(){return lr(function(e,t){return e.toString(t)},arguments)}function D5(e,t,n){const r=t.toString(n),i=Ds(r,st.__wbindgen_malloc,st.__wbindgen_realloc),s=ci;$n().setInt32(e+4,s,!0),$n().setInt32(e+0,i,!0)}function R5(e,t){return e.unshift(t)}function F5(e){return e.value}function B5(e){return Object.values(e)}function U5(e){return e}function j5(e){return e}function M5(e,t){return Li(e,t)}function L5(e){return BigInt.asUintN(64,e)}function N5(){const e=st.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)}typeof FinalizationRegistry>"u"||new FinalizationRegistry(e=>st.__wbg_automerge_free(e>>>0,1));const t0=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>st.__wbg_syncstate_free(e>>>0,1));function H5(e){const t=st.__externref_table_alloc();return st.__wbindgen_externrefs.set(t,e),t}function nd(e){const t=typeof e;if(t=="number"||t=="boolean"||e==null)return`${e}`;if(t=="string")return`"${e}"`;if(t=="symbol"){const i=e.description;return i==null?"Symbol":`Symbol(${i})`}if(t=="function"){const i=e.name;return typeof i=="string"&&i.length>0?`Function(${i})`:"Function"}if(Array.isArray(e)){const i=e.length;let s="[";i>0&&(s+=nd(e[0]));for(let o=1;o<i;o++)s+=", "+nd(e[o]);return s+="]",s}const n=/\[object ([^\]]+)\]/.exec(toString.call(e));let r;if(n&&n.length>1)r=n[1];else return toString.call(e);if(r=="Object")try{return"Object("+JSON.stringify(e)+")"}catch{return"Object"}return e instanceof Error?`${e.name}: ${e.message}
|
|
6
|
+
${e.stack}`:r}function _f(e,t){return e=e>>>0,co().subarray(e/1,e/1+t)}let is=null;function $n(){return(is===null||is.buffer.detached===!0||is.buffer.detached===void 0&&is.buffer!==st.memory.buffer)&&(is=new DataView(st.memory.buffer)),is}function Li(e,t){return e=e>>>0,V5(e,t)}let pa=null;function co(){return(pa===null||pa.byteLength===0)&&(pa=new Uint8Array(st.memory.buffer)),pa}function lr(e,t){try{return e.apply(this,t)}catch(n){const r=H5(n);st.__wbindgen_exn_store(r)}}function Co(e){return e==null}function Ds(e,t,n){if(n===void 0){const a=lo.encode(e),c=t(a.length,1)>>>0;return co().subarray(c,c+a.length).set(a),ci=a.length,c}let r=e.length,i=t(r,1)>>>0;const s=co();let o=0;for(;o<r;o++){const a=e.charCodeAt(o);if(a>127)break;s[i+o]=a}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;const a=co().subarray(i+o,i+r),c=lo.encodeInto(e,a);o+=c.written,i=n(i,r,o,1)>>>0}return ci=o,i}function n0(e){const t=st.__wbindgen_externrefs.get(e);return st.__externref_table_dealloc(e),t}let La=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});La.decode();const Z5=0x7ff00000;let Jl=0;function V5(e,t){return Jl+=t,Jl>=Z5&&(La=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),La.decode(),Jl=t),La.decode(co().subarray(e,e+t))}const lo=new TextEncoder;"encodeInto"in lo||(lo.encodeInto=function(e,t){const n=lo.encode(e);return t.set(n),{read:e.length,written:n.length}});let ci=0,st;function W5(e){st=e}URL=globalThis.URL;const q5=await l_({"./automerge_wasm_bg.js":{__wbg_get_unchecked_17f53dad852b9588:Q4,__wbg_get_8360291721e2339f:X4,__wbg_push_471a5b068a5295f6:k5,__wbg_set_3bf1de9fab0cd644:A5,__wbg_freeze_c79f45721998bbbc:W4,__wbg_instanceof_Object_7c99480a1cdfb911:n5,__wbg_defineProperty_aeb95d0434ce03d0:M4,__wbg_length_3d4ecd04bd8d22f1:c5,__wbg_keys_2fd1bfdda7e278ca:a5,__wbg_values_301a77363cf6c773:B5,__wbg_call_a24592a6f349a97e:U4,__wbg_assign_752c2af1512cc7fd:F4,__wbg_next_0340c4ae324393c3:v5,__wbg_done_9158f7cc8751ba32:N4,__wbg_value_ee3a06f4579184fa:F5,__wbg_deleteProperty_d5f7bd763acbdb44:L4,__wbg_unshift_951ea71d9d2dc660:R5,__wbg_apply_329b2a440415c2e6:R4,__wbg_new_227d7c05414eb861:p5,__wbg_stack_3b0d974bbf31e44f:z5,__wbg_error_a6fa202b58aa1cd3:Z4,__wbg_String_8564e559799eccda:b4,__wbg_set_6be42768c690e380:I5,__wbg_getRandomValues_76dfc69825c9c552:J4,__wbg_log_7e1aa9064a1dbdbd:d5,__wbg_log_dfa1efedf266562e:f5,__wbg_new_682678e2f47e32bc:_5,__wbg_new_aa8d0fa9762c29bd:b5,__wbg_BigInt_65bcea251e788083:_4,__wbg_next_7646edaa39458ef7:x5,__wbg_iterator_013bc09ec998c2a7:o5,__wbg_get_1affdbdd5573b16a:G4,__wbg_call_14b169f759b26747:B4,__wbg_length_6a846b3b23b74aca:l5,__wbg_from_0dbf29f09e7fb200:q4,__wbg_isArray_c3109d14ffc06469:s5,__wbg_instanceof_ArrayBuffer_7c8433c6ed14ffe3:e5,__wbg_toString_c3061af2bf859d19:T5,__wbg_toString_c96dc76d5547a715:D5,__wbg_new_5e360d2ff7b9e1c3:m5,__wbg_instanceof_Date_81b75f5ed36b30ea:t5,__wbg_getTime_da7c55f52b71e8c6:K4,__wbg_new_7913666fe5070684:y5,__wbg_entries_e0b73aa8571ddb56:H4,__wbg_new_191521fecb171639:g5,__wbg_get_6011fa3a58f61074:Y4,__wbg_ownKeys_0231887680f0f945:S5,__wbg_set_022bee52d0b05b19:E5,__wbg_concat_1cef5380372e969d:j4,__wbg_slice_45916ed2fae7e0ea:C5,__wbg_for_b0616d1de7774be9:V4,__wbg_toString_5a84b8552b34a19d:P5,__wbg_length_9f1775224cf1d815:u5,__wbg_prototypesetcall_a6b02eb00b0f4ce2:$5,__wbg_new_0c7403db6e782f19:h5,__wbg_instanceof_Uint8Array_152ba1f289edcf3f:r5,__wbg_new_from_slice_b5ea43e23f6008c0:w5,__wbg___wbindgen_string_get_7ed5322991caaec5:T4,__wbg___wbindgen_boolean_get_6ea149f0a8dcc5ff:w4,__wbg___wbindgen_number_get_c7f42aed0525c451:P4,__wbg___wbindgen_is_undefined_29a43b4d42920abd:I4,__wbg___wbindgen_debug_string_ab4b34d23d6778bd:v4,__wbg_isArray_2790516aa848bf18:i5,__wbg_Error_960c155d3d49e4c2:y4,__wbg_stringify_057c4027271f8007:O5,__wbg___wbindgen_is_null_52ff4ec04186736f:k4,__wbg___wbindgen_is_object_63322ec0cd6ea4ef:E4,__wbg___wbindgen_is_function_3baa9db1a987f47d:$4,__wbg___wbindgen_is_string_6df3bf7ef1164ed3:A4,__wbg___wbindgen_is_bigint_ec25c7f91b4d9e93:S4,__wbg___wbindgen_neg_8d39d23ef65c9fdb:O4,__wbg___wbindgen_lt_78bab382628fb48f:z4,__wbg___wbindgen_gt_fd08d8cbe0a8551c:x4,__wbg___wbindgen_throw_6b64449b9b9ed33c:D4,__wbg___wbindgen_jsval_loose_eq_cac3565e89b4134c:C4,__wbindgen_init_externref_table:N5,__wbindgen_cast_0000000000000001:U5,__wbindgen_cast_0000000000000002:j5,__wbindgen_cast_0000000000000003:M5,__wbindgen_cast_0000000000000004:L5}},m4),{memory:J5,__wbg_syncstate_free:K5,syncstate_sharedHeads:G5,syncstate_lastSentHeads:Y5,syncstate_set_lastSentHeads:X5,syncstate_set_sentHashes:Q5,syncstate_readOnly:e6,syncstate_set_readOnly:t6,syncstate_peerReadOnly:n6,syncstate_clone:r6,__wbg_automerge_free:i6,automerge_new:s6,automerge_initRootFromHydrate:o6,automerge_clone:a6,automerge_fork:c6,automerge_pendingOps:l6,automerge_commit:u6,automerge_merge:d6,automerge_rollback:f6,automerge_keys:h6,automerge_text:g6,automerge_spans:p6,automerge_splice:m6,automerge_updateText:_6,automerge_updateSpans:y6,automerge_push:b6,automerge_pushObject:w6,automerge_insert:v6,automerge_splitBlock:x6,automerge_joinBlock:S6,automerge_updateBlock:$6,automerge_getBlock:k6,automerge_insertObject:E6,automerge_put:A6,automerge_putObject:I6,automerge_putObjectFromHydrate:C6,automerge_insertObjectFromHydrate:z6,automerge_spliceFromHydrate:O6,automerge_increment:P6,automerge_get:T6,automerge_getWithType:D6,automerge_objInfo:R6,automerge_getAll:F6,automerge_enableFreeze:B6,automerge_registerDatatype:U6,automerge_applyPatches:j6,automerge_applyAndReturnPatches:M6,automerge_diffIncremental:L6,automerge_updateDiffCursor:N6,automerge_resetDiffCursor:H6,automerge_diff:Z6,automerge_diffPath:V6,automerge_isolate:W6,automerge_integrate:q6,automerge_length:J6,automerge_delete:K6,automerge_save:G6,automerge_saveIncremental:Y6,automerge_saveSince:X6,automerge_saveNoCompress:Q6,automerge_saveAndVerify:e8,automerge_loadIncremental:t8,automerge_applyChanges:n8,automerge_getChanges:r8,automerge_getChangesMeta:i8,automerge_getChangeByHash:s8,automerge_getChangeMetaByHash:o8,automerge_getDecodedChangeByHash:a8,automerge_getChangesAdded:c8,automerge_getHeads:l8,automerge_getActorId:u8,automerge_getLastLocalChange:d8,automerge_dump:f8,automerge_getMissingDeps:h8,automerge_receiveSyncMessage:g8,automerge_generateSyncMessage:p8,automerge_toJS:m8,automerge_materialize:_8,automerge_getCursor:y8,automerge_getCursorPosition:b8,automerge_emptyChange:w8,automerge_mark:v8,automerge_unmark:x8,automerge_marks:S8,automerge_marksAt:$8,automerge_hasOurChanges:k8,automerge_topoHistoryTraversal:E8,automerge_stats:A8,automerge_saveBundle:I8,create:C8,load:z8,wasmReleaseInfo:O8,encodeChange:P8,decodeChange:T8,initSyncState:D8,importSyncState:R8,exportSyncState:F8,encodeSyncMessage:B8,decodeSyncMessage:U8,encodeSyncState:j8,decodeSyncState:M8,readBundle:L8,__wbindgen_malloc:N8,__wbindgen_realloc:H8,__wbindgen_exn_store:Z8,__externref_table_alloc:V8,__wbindgen_externrefs:W8,__wbindgen_free:q8,__externref_table_dealloc:J8,__wbindgen_start:w_}=q5,K8=Object.freeze(Object.defineProperty({__proto__:null,__externref_table_alloc:V8,__externref_table_dealloc:J8,__wbg_automerge_free:i6,__wbg_syncstate_free:K5,__wbindgen_exn_store:Z8,__wbindgen_externrefs:W8,__wbindgen_free:q8,__wbindgen_malloc:N8,__wbindgen_realloc:H8,__wbindgen_start:w_,automerge_applyAndReturnPatches:M6,automerge_applyChanges:n8,automerge_applyPatches:j6,automerge_clone:a6,automerge_commit:u6,automerge_delete:K6,automerge_diff:Z6,automerge_diffIncremental:L6,automerge_diffPath:V6,automerge_dump:f8,automerge_emptyChange:w8,automerge_enableFreeze:B6,automerge_fork:c6,automerge_generateSyncMessage:p8,automerge_get:T6,automerge_getActorId:u8,automerge_getAll:F6,automerge_getBlock:k6,automerge_getChangeByHash:s8,automerge_getChangeMetaByHash:o8,automerge_getChanges:r8,automerge_getChangesAdded:c8,automerge_getChangesMeta:i8,automerge_getCursor:y8,automerge_getCursorPosition:b8,automerge_getDecodedChangeByHash:a8,automerge_getHeads:l8,automerge_getLastLocalChange:d8,automerge_getMissingDeps:h8,automerge_getWithType:D6,automerge_hasOurChanges:k8,automerge_increment:P6,automerge_initRootFromHydrate:o6,automerge_insert:v6,automerge_insertObject:E6,automerge_insertObjectFromHydrate:z6,automerge_integrate:q6,automerge_isolate:W6,automerge_joinBlock:S6,automerge_keys:h6,automerge_length:J6,automerge_loadIncremental:t8,automerge_mark:v8,automerge_marks:S8,automerge_marksAt:$8,automerge_materialize:_8,automerge_merge:d6,automerge_new:s6,automerge_objInfo:R6,automerge_pendingOps:l6,automerge_push:b6,automerge_pushObject:w6,automerge_put:A6,automerge_putObject:I6,automerge_putObjectFromHydrate:C6,automerge_receiveSyncMessage:g8,automerge_registerDatatype:U6,automerge_resetDiffCursor:H6,automerge_rollback:f6,automerge_save:G6,automerge_saveAndVerify:e8,automerge_saveBundle:I8,automerge_saveIncremental:Y6,automerge_saveNoCompress:Q6,automerge_saveSince:X6,automerge_spans:p6,automerge_splice:m6,automerge_spliceFromHydrate:O6,automerge_splitBlock:x6,automerge_stats:A8,automerge_text:g6,automerge_toJS:m8,automerge_topoHistoryTraversal:E8,automerge_unmark:x8,automerge_updateBlock:$6,automerge_updateDiffCursor:N6,automerge_updateSpans:y6,automerge_updateText:_6,create:C8,decodeChange:T8,decodeSyncMessage:U8,decodeSyncState:M8,encodeChange:P8,encodeSyncMessage:B8,encodeSyncState:j8,exportSyncState:F8,importSyncState:R8,initSyncState:D8,load:z8,memory:J5,readBundle:L8,syncstate_clone:r6,syncstate_lastSentHeads:Y5,syncstate_peerReadOnly:n6,syncstate_readOnly:e6,syncstate_set_lastSentHeads:X5,syncstate_set_readOnly:t6,syncstate_set_sentHashes:Q5,syncstate_sharedHeads:G5,wasmReleaseInfo:O8},Symbol.toStringTag,{value:"Module"}));W5(K8);w_();A3();const G8=1e3,Y8=3e4,Kl=8,X8=1e3,Q8="iroh/automerge-repo/1",kt="[freqhole:iroh-adapter]";class eE extends p4{constructor(t){super(),this.midden=null,this.streams=new Map,this.readLoops=new Map,this._ready=!1,this._disconnected=!1,this._acceptLoopRunning=!1,this.identityUnsub=null,this.intendedPeers=new Set,this.reconnectState=new Map,this.connectionStateListeners=[],this.failedPeers=new Set,this.alpnHandlers=new Map,this.peerConnectListeners=[],this.peerDisconnectListeners=[],this.opts=t,this.syncAlpn=t.syncAlpn??Q8,this._readyPromise=new Promise(n=>{this._resolveReady=n})}isReady(){return this._ready}whenReady(){return this._readyPromise}connect(t,n){this.peerId=t,this.peerMetadata=n,this._ready=!0,this._resolveReady(),this.checkIdentityAndStart().catch(r=>{console.error(kt,"identity check failed:",r)})}send(t){const n=t.targetId,r=this.streams.get(n);if(!r){console.warn(kt,"no stream for peer:",n.slice(0,16)+"...");return}const i=d4(t),s=new Uint8Array(i.buffer,i.byteOffset,i.byteLength);r.write_message(s).catch(o=>{console.error(kt,"write failed for peer:",n.slice(0,16)+"...",o),this.removePeer(n)})}disconnect(){this._disconnected=!0;for(const[t,n]of this.streams)n.close(),this.emit("peer-disconnected",{peerId:t});this.streams.clear(),this.readLoops.clear(),this.intendedPeers.clear(),this.failedPeers.clear(),this.alpnHandlers.clear();for(const[,t]of this.reconnectState)t.timer!==null&&clearTimeout(t.timer);this.reconnectState.clear(),this.connectionStateListeners.length=0,this.peerConnectListeners.length=0,this.peerDisconnectListeners.length=0,this.identityUnsub&&(this.identityUnsub(),this.identityUnsub=null),this.emit("close")}async addPeer(t){if(this._disconnected)throw new Error("adapter is disconnected");if(this.intendedPeers.add(t),this.failedPeers.delete(t),this.emitConnectionStateChange(),this.clearReconnectState(t),this.streams.has(t)){console.log(kt,"already connected to:",t.slice(0,16)+"...");return}const r=await (await this.ensureMidden()).open_bi(t,this.syncAlpn);this.registerStream(t,r)}forgetPeer(t){this.intendedPeers.delete(t),this.failedPeers.delete(t),this.clearReconnectState(t),this.removePeer(t),this.emitConnectionStateChange()}isConnected(t){return this.streams.has(t)}getConnectionSummary(){let t=0,n=0;for(const r of this.intendedPeers)this.streams.has(r)?t++:this.reconnectState.has(r)&&n++;return{connected:t,reconnecting:n,failed:this.failedPeers.size}}onConnectionStateChange(t){return this.connectionStateListeners.push(t),()=>{const n=this.connectionStateListeners.indexOf(t);n>=0&&this.connectionStateListeners.splice(n,1)}}onPeerConnect(t){return this.peerConnectListeners.push(t),()=>{const n=this.peerConnectListeners.indexOf(t);n>=0&&this.peerConnectListeners.splice(n,1)}}onPeerDisconnect(t){return this.peerDisconnectListeners.push(t),()=>{const n=this.peerDisconnectListeners.indexOf(t);n>=0&&this.peerDisconnectListeners.splice(n,1)}}retryFailedPeers(){if(this._disconnected)return;const t=[...this.failedPeers];this.failedPeers.clear();for(const n of t)this.intendedPeers.add(n),this.scheduleReconnect(n);this.emitConnectionStateChange()}registerAlpnHandler(t,n){this.alpnHandlers.set(t,n)}async getNode(){return this.ensureMidden()}async checkIdentityAndStart(){await this.opts.getIdentity()?(console.log(kt,"identity found, starting P2P transport"),await this.initialize()):this.opts.onIdentityChange?(console.log(kt,"no identity yet, deferring P2P transport"),this.identityUnsub=this.opts.onIdentityChange(n=>{n&&!this.midden&&!this._disconnected&&(console.log(kt,"identity created, starting P2P transport"),this.initialize().catch(r=>{console.error(kt,"deferred initialization failed:",r)}))})):console.log(kt,"no identity and no onIdentityChange provided, adapter is passive")}async initialize(){try{await this.ensureMidden(),this.startAcceptLoop()}catch(t){throw console.error(kt,"failed to initialize midden:",t),t}}async ensureMidden(){return this.midden?this.midden:(this.midden=await this.opts.getNode(),this.midden)}startAcceptLoop(){if(this._acceptLoopRunning)return;this._acceptLoopRunning=!0,(async()=>{const n=await this.ensureMidden();for(;!this._disconnected;)try{const r=await n.accept();if(!r){console.log(kt,"accept loop: endpoint closed");break}const i=r.alpn(),s=r.peer_node_id();if(i===this.syncAlpn)console.log(kt,"accepted sync connection from:",s.slice(0,16)+"..."),this.registerStream(s,r);else{const o=this.alpnHandlers.get(i);o?(console.log(kt,"dispatching",i,"stream from:",s.slice(0,16)+"..."),o(r)):(console.warn(kt,"dropping inbound stream - no handler registered for ALPN:",i,"registered handlers:",Array.from(this.alpnHandlers.keys())),r.close())}}catch(r){if(this._disconnected)break;console.error(kt,"accept loop error:",r),await new Promise(i=>setTimeout(i,1e3))}this._acceptLoopRunning=!1})().catch(n=>{console.error(kt,"accept loop crashed:",n),this._acceptLoopRunning=!1})}registerStream(t,n){const r=this.streams.get(t);r&&(console.log(kt,"replacing existing stream for peer:",t.slice(0,16)+"..."),r.close()),this.streams.set(t,n),this.clearReconnectState(t),this.emitConnectionStateChange();for(const i of this.peerConnectListeners)i(t);this.emit("peer-candidate",{peerId:t,peerMetadata:{isEphemeral:!1}}),this.startReadLoop(t,n)}startReadLoop(t,n){this.readLoops.set(t,!0),(async()=>{for(;this.readLoops.get(t)&&!this._disconnected;)try{const i=await n.read_message();if(!i){console.log(kt,"stream closed by peer:",t.slice(0,16)+"...");break}const s=f4(i);s.senderId=t,this.emit("message",s)}catch(i){if(this._disconnected)break;console.error(kt,"read error from peer:",t.slice(0,16)+"...",i);break}this.streams.get(t)===n&&this.removePeer(t)})().catch(i=>{console.error(kt,"read loop crashed for peer:",t.slice(0,16)+"...",i),this.streams.get(t)===n&&this.removePeer(t)})}removePeer(t){const n=this.streams.get(t);if(n){n.close(),this.streams.delete(t),this.emitConnectionStateChange();for(const r of this.peerDisconnectListeners)r(t)}this.readLoops.delete(t),this._disconnected||(this.emit("peer-disconnected",{peerId:t}),this.intendedPeers.has(t)&&this.scheduleReconnect(t))}scheduleReconnect(t){if(this._disconnected||this.streams.has(t))return;let n=this.reconnectState.get(t);if(n||(n={attempt:0,timer:null},this.reconnectState.set(t,n)),n.attempt>=Kl){console.warn(kt,"giving up reconnection to peer after",Kl,"attempts:",t.slice(0,16)+"..."),this.intendedPeers.delete(t),this.failedPeers.add(t),this.clearReconnectState(t),this.emitConnectionStateChange();return}const r=G8*Math.pow(2,n.attempt),i=Math.min(r,Y8),s=Math.floor(Math.random()*X8),o=i+s;console.log(kt,"scheduling reconnect to peer:",t.slice(0,16)+"...",`(attempt ${n.attempt+1}/${Kl}, delay ${o}ms)`),n.timer!==null&&clearTimeout(n.timer),n.timer=setTimeout(()=>{n.timer=null,this.attemptReconnect(t)},o)}async attemptReconnect(t){if(this._disconnected)return;if(this.streams.has(t)){this.clearReconnectState(t);return}if(!this.intendedPeers.has(t))return;const n=this.reconnectState.get(t);n&&(n.attempt+=1);try{const i=await (await this.ensureMidden()).open_bi(t,this.syncAlpn);console.log(kt,"reconnected to peer:",t.slice(0,16)+"..."),this.registerStream(t,i)}catch(r){console.warn(kt,"reconnect attempt failed for peer:",t.slice(0,16)+"...",r),this.scheduleReconnect(t)}}clearReconnectState(t){const n=this.reconnectState.get(t);n&&(n.timer!==null&&clearTimeout(n.timer),this.reconnectState.delete(t))}emitConnectionStateChange(){for(const t of this.connectionStateListeners)t()}}function ae(e,t,n){function r(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:o,traits:new Set},enumerable:!1}),a._zod.traits.has(e))return;a._zod.traits.add(e),t(a,c);const l=o.prototype,f=Object.keys(l);for(let u=0;u<f.length;u++){const h=f[u];h in a||(a[h]=l[h].bind(a))}}const i=n?.Parent??Object;class s extends i{}Object.defineProperty(s,"name",{value:e});function o(a){var c;const l=n?.Parent?new s:this;r(l,a),(c=l._zod).deferred??(c.deferred=[]);for(const f of l._zod.deferred)f();return l}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:a=>n?.Parent&&a instanceof n.Parent?!0:a?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}let ps=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}},v_=class extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}};const x_={};function li(e){return x_}function S_(e){const t=Object.values(e).filter(r=>typeof r=="number");return Object.entries(e).filter(([r,i])=>t.indexOf(+r)===-1).map(([r,i])=>i)}function rd(e,t){return typeof t=="bigint"?t.toString():t}function Zc(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function yf(e){return e==null}function bf(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function tE(e,t){const n=(e.toString().split(".")[1]||"").length,r=t.toString();let i=(r.split(".")[1]||"").length;if(i===0&&/\d?e-\d?/.test(r)){const c=r.match(/\d?e-(\d?)/);c?.[1]&&(i=Number.parseInt(c[1]))}const s=n>i?n:i,o=Number.parseInt(e.toFixed(s).replace(".","")),a=Number.parseInt(t.toFixed(s).replace(".",""));return o%a/10**s}const r0=Symbol("evaluating");function ct(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==r0)return r===void 0&&(r=r0,r=n()),r},set(i){Object.defineProperty(e,t,{value:i})},configurable:!0})}function Ni(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function hi(...e){const t={};for(const n of e){const r=Object.getOwnPropertyDescriptors(n);Object.assign(t,r)}return Object.defineProperties({},t)}function i0(e){return JSON.stringify(e)}function nE(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const $_="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function zo(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const rE=Zc(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function Es(e){if(zo(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(zo(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function k_(e){return Es(e)?{...e}:Array.isArray(e)?[...e]:e}const iE=new Set(["string","number","symbol"]);function As(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function gi(e,t,n){const r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function Me(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function sE(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const oE={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-0x80000000,0x7fffffff],uint32:[0,0xffffffff],float32:[-3402823466385289e23,3402823466385289e23],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function aE(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const s=hi(e._zod.def,{get shape(){const o={};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&(o[a]=n.shape[a])}return Ni(this,"shape",o),o},checks:[]});return gi(e,s)}function cE(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const s=hi(e._zod.def,{get shape(){const o={...e._zod.def.shape};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&delete o[a]}return Ni(this,"shape",o),o},checks:[]});return gi(e,s)}function lE(e,t){if(!Es(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const s=e._zod.def.shape;for(const o in t)if(Object.getOwnPropertyDescriptor(s,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const i=hi(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t};return Ni(this,"shape",s),s}});return gi(e,i)}function uE(e,t){if(!Es(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=hi(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t};return Ni(this,"shape",r),r}});return gi(e,n)}function dE(e,t){const n=hi(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t._zod.def.shape};return Ni(this,"shape",r),r},get catchall(){return t._zod.def.catchall},checks:[]});return gi(e,n)}function fE(e,t,n){const i=t._zod.def.checks;if(i&&i.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=hi(t._zod.def,{get shape(){const a=t._zod.def.shape,c={...a};if(n)for(const l in n){if(!(l in a))throw new Error(`Unrecognized key: "${l}"`);n[l]&&(c[l]=e?new e({type:"optional",innerType:a[l]}):a[l])}else for(const l in a)c[l]=e?new e({type:"optional",innerType:a[l]}):a[l];return Ni(this,"shape",c),c},checks:[]});return gi(t,o)}function hE(e,t,n){const r=hi(t._zod.def,{get shape(){const i=t._zod.def.shape,s={...i};if(n)for(const o in n){if(!(o in s))throw new Error(`Unrecognized key: "${o}"`);n[o]&&(s[o]=new e({type:"nonoptional",innerType:i[o]}))}else for(const o in i)s[o]=new e({type:"nonoptional",innerType:i[o]});return Ni(this,"shape",s),s}});return gi(t,r)}function us(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function ds(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function ma(e){return typeof e=="string"?e:e?.message}function ui(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const i=ma(e.inst?._zod.def?.error?.(e))??ma(t?.error?.(e))??ma(n.customError?.(e))??ma(n.localeError?.(e))??"Invalid input";r.message=i}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function wf(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function Oo(...e){const[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}const E_=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,rd,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},A_=ae("$ZodError",E_),I_=ae("$ZodError",E_,{Parent:Error});function gE(e,t=n=>n.message){const n={},r=[];for(const i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function pE(e,t=n=>n.message){const n={_errors:[]},r=i=>{for(const s of i.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map(o=>r({issues:o}));else if(s.code==="invalid_key")r({issues:s.issues});else if(s.code==="invalid_element")r({issues:s.issues});else if(s.path.length===0)n._errors.push(t(s));else{let o=n,a=0;for(;a<s.path.length;){const c=s.path[a];a===s.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(t(s))):o[c]=o[c]||{_errors:[]},o=o[c],a++}}};return r(e),n}const vf=e=>(t,n,r,i)=>{const s=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},s);if(o instanceof Promise)throw new ps;if(o.issues.length){const a=new(i?.Err??e)(o.issues.map(c=>ui(c,s,li())));throw $_(a,i?.callee),a}return o.value},xf=e=>async(t,n,r,i)=>{const s=r?Object.assign(r,{async:!0}):{async:!0};let o=t._zod.run({value:n,issues:[]},s);if(o instanceof Promise&&(o=await o),o.issues.length){const a=new(i?.Err??e)(o.issues.map(c=>ui(c,s,li())));throw $_(a,i?.callee),a}return o.value},Vc=e=>(t,n,r)=>{const i=r?{...r,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw new ps;return s.issues.length?{success:!1,error:new(e??A_)(s.issues.map(o=>ui(o,i,li())))}:{success:!0,data:s.value}},mE=Vc(I_),Wc=e=>async(t,n,r)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},i);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new e(s.issues.map(o=>ui(o,i,li())))}:{success:!0,data:s.value}},_E=Wc(I_),yE=e=>(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return vf(e)(t,n,i)},bE=e=>(t,n,r)=>vf(e)(t,n,r),wE=e=>async(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return xf(e)(t,n,i)},vE=e=>async(t,n,r)=>xf(e)(t,n,r),xE=e=>(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Vc(e)(t,n,i)},SE=e=>(t,n,r)=>Vc(e)(t,n,r),$E=e=>async(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Wc(e)(t,n,i)},kE=e=>async(t,n,r)=>Wc(e)(t,n,r),EE=/^[cC][^\s-]{8,}$/,AE=/^[0-9a-z]+$/,IE=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,CE=/^[0-9a-vA-V]{20}$/,zE=/^[A-Za-z0-9]{27}$/,OE=/^[a-zA-Z0-9_-]{21}$/,PE=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,TE=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,s0=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,DE=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,RE="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function FE(){return new RegExp(RE,"u")}const BE=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,UE=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,jE=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,ME=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,LE=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,C_=/^[A-Za-z0-9_-]*$/,NE=/^\+[1-9]\d{6,14}$/,z_="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",HE=new RegExp(`^${z_}$`);function O_(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function ZE(e){return new RegExp(`^${O_(e)}$`)}function VE(e){const t=O_({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${z_}T(?:${r})$`)}const WE=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},qE=/^-?\d+$/,P_=/^-?\d+(?:\.\d+)?$/,JE=/^(?:true|false)$/i,KE=/^[^A-Z]*$/,GE=/^[^a-z]*$/,kn=ae("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),T_={number:"number",bigint:"bigint",object:"date"},D_=ae("$ZodCheckLessThan",(e,t)=>{kn.init(e,t);const n=T_[typeof t.value];e._zod.onattach.push(r=>{const i=r._zod.bag,s=(t.inclusive?i.maximum:i.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<s&&(t.inclusive?i.maximum=t.value:i.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),R_=ae("$ZodCheckGreaterThan",(e,t)=>{kn.init(e,t);const n=T_[typeof t.value];e._zod.onattach.push(r=>{const i=r._zod.bag,s=(t.inclusive?i.minimum:i.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>s&&(t.inclusive?i.minimum=t.value:i.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),YE=ae("$ZodCheckMultipleOf",(e,t)=>{kn.init(e,t),e._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%t.value===BigInt(0):tE(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),XE=ae("$ZodCheckNumberFormat",(e,t)=>{kn.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[i,s]=oE[t.format];e._zod.onattach.push(o=>{const a=o._zod.bag;a.format=t.format,a.minimum=i,a.maximum=s,n&&(a.pattern=qE)}),e._zod.check=o=>{const a=o.value;if(n){if(!Number.isInteger(a)){o.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:a,inst:e});return}if(!Number.isSafeInteger(a)){a>0?o.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}a<i&&o.issues.push({origin:"number",input:a,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),a>s&&o.issues.push({origin:"number",input:a,code:"too_big",maximum:s,inclusive:!0,inst:e,continue:!t.abort})}}),QE=ae("$ZodCheckMaxLength",(e,t)=>{var n;kn.init(e,t),(n=e._zod.def).when??(n.when=r=>{const i=r.value;return!yf(i)&&i.length!==void 0}),e._zod.onattach.push(r=>{const i=r._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<i&&(r._zod.bag.maximum=t.maximum)}),e._zod.check=r=>{const i=r.value;if(i.length<=t.maximum)return;const o=wf(i);r.issues.push({origin:o,code:"too_big",maximum:t.maximum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),eA=ae("$ZodCheckMinLength",(e,t)=>{var n;kn.init(e,t),(n=e._zod.def).when??(n.when=r=>{const i=r.value;return!yf(i)&&i.length!==void 0}),e._zod.onattach.push(r=>{const i=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>i&&(r._zod.bag.minimum=t.minimum)}),e._zod.check=r=>{const i=r.value;if(i.length>=t.minimum)return;const o=wf(i);r.issues.push({origin:o,code:"too_small",minimum:t.minimum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),tA=ae("$ZodCheckLengthEquals",(e,t)=>{var n;kn.init(e,t),(n=e._zod.def).when??(n.when=r=>{const i=r.value;return!yf(i)&&i.length!==void 0}),e._zod.onattach.push(r=>{const i=r._zod.bag;i.minimum=t.length,i.maximum=t.length,i.length=t.length}),e._zod.check=r=>{const i=r.value,s=i.length;if(s===t.length)return;const o=wf(i),a=s>t.length;r.issues.push({origin:o,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),qc=ae("$ZodCheckStringFormat",(e,t)=>{var n,r;kn.init(e,t),e._zod.onattach.push(i=>{const s=i._zod.bag;s.format=t.format,t.pattern&&(s.patterns??(s.patterns=new Set),s.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=i=>{t.pattern.lastIndex=0,!t.pattern.test(i.value)&&i.issues.push({origin:"string",code:"invalid_format",format:t.format,input:i.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),nA=ae("$ZodCheckRegex",(e,t)=>{qc.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),rA=ae("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=KE),qc.init(e,t)}),iA=ae("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=GE),qc.init(e,t)}),sA=ae("$ZodCheckIncludes",(e,t)=>{kn.init(e,t);const n=As(t.includes),r=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(i=>{const s=i._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(r)}),e._zod.check=i=>{i.value.includes(t.includes,t.position)||i.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:i.value,inst:e,continue:!t.abort})}}),oA=ae("$ZodCheckStartsWith",(e,t)=>{kn.init(e,t);const n=new RegExp(`^${As(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const i=r._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(n)}),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),aA=ae("$ZodCheckEndsWith",(e,t)=>{kn.init(e,t);const n=new RegExp(`.*${As(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const i=r._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(n)}),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),cA=ae("$ZodCheckOverwrite",(e,t)=>{kn.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});let lA=class{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const r=t.split(`
|
|
7
|
+
`).filter(o=>o),i=Math.min(...r.map(o=>o.length-o.trimStart().length)),s=r.map(o=>o.slice(i)).map(o=>" ".repeat(this.indent*2)+o);for(const o of s)this.content.push(o)}compile(){const t=Function,n=this?.args,i=[...(this?.content??[""]).map(s=>` ${s}`)];return new t(...n,i.join(`
|
|
8
|
+
`))}};const uA={major:4,minor:3,patch:5},Ot=ae("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=uA;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const i of r)for(const s of i._zod.onattach)s(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const i=(o,a,c)=>{let l=us(o),f;for(const u of a){if(u._zod.def.when){if(!u._zod.def.when(o))continue}else if(l)continue;const h=o.issues.length,d=u._zod.check(o);if(d instanceof Promise&&c?.async===!1)throw new ps;if(f||d instanceof Promise)f=(f??Promise.resolve()).then(async()=>{await d,o.issues.length!==h&&(l||(l=us(o,h)))});else{if(o.issues.length===h)continue;l||(l=us(o,h))}}return f?f.then(()=>o):o},s=(o,a,c)=>{if(us(o))return o.aborted=!0,o;const l=i(a,r,c);if(l instanceof Promise){if(c.async===!1)throw new ps;return l.then(f=>e._zod.parse(f,c))}return e._zod.parse(l,c)};e._zod.run=(o,a)=>{if(a.skipChecks)return e._zod.parse(o,a);if(a.direction==="backward"){const l=e._zod.parse({value:o.value,issues:[]},{...a,skipChecks:!0});return l instanceof Promise?l.then(f=>s(f,o,a)):s(l,o,a)}const c=e._zod.parse(o,a);if(c instanceof Promise){if(a.async===!1)throw new ps;return c.then(l=>i(l,r,a))}return i(c,r,a)}}ct(e,"~standard",()=>({validate:i=>{try{const s=mE(e,i);return s.success?{value:s.data}:{issues:s.error?.issues}}catch{return _E(e,i).then(o=>o.success?{value:o.data}:{issues:o.error?.issues})}},vendor:"zod",version:1}))}),Sf=ae("$ZodString",(e,t)=>{Ot.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??WE(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),At=ae("$ZodStringFormat",(e,t)=>{qc.init(e,t),Sf.init(e,t)}),dA=ae("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=TE),At.init(e,t)}),fA=ae("$ZodUUID",(e,t)=>{if(t.version){const r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(r===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=s0(r))}else t.pattern??(t.pattern=s0());At.init(e,t)}),hA=ae("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=DE),At.init(e,t)}),gA=ae("$ZodURL",(e,t)=>{At.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(":")?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=i.href:n.value=r;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),pA=ae("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=FE()),At.init(e,t)}),mA=ae("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=OE),At.init(e,t)}),_A=ae("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=EE),At.init(e,t)}),yA=ae("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=AE),At.init(e,t)}),bA=ae("$ZodULID",(e,t)=>{t.pattern??(t.pattern=IE),At.init(e,t)}),wA=ae("$ZodXID",(e,t)=>{t.pattern??(t.pattern=CE),At.init(e,t)}),vA=ae("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=zE),At.init(e,t)}),xA=ae("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=VE(t)),At.init(e,t)}),SA=ae("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=HE),At.init(e,t)}),$A=ae("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=ZE(t)),At.init(e,t)}),kA=ae("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=PE),At.init(e,t)}),EA=ae("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=BE),At.init(e,t),e._zod.bag.format="ipv4"}),AA=ae("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=UE),At.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),IA=ae("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=jE),At.init(e,t)}),CA=ae("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=ME),At.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[i,s]=r;if(!s)throw new Error;const o=Number(s);if(`${o}`!==s)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${i}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function F_(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const zA=ae("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=LE),At.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{F_(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function OA(e){if(!C_.test(e))return!1;const t=e.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return F_(n)}const PA=ae("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=C_),At.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{OA(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),TA=ae("$ZodE164",(e,t)=>{t.pattern??(t.pattern=NE),At.init(e,t)});function DA(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[r]=n;if(!r)return!1;const i=JSON.parse(atob(r));return!("typ"in i&&i?.typ!=="JWT"||!i.alg||t&&(!("alg"in i)||i.alg!==t))}catch{return!1}}const RA=ae("$ZodJWT",(e,t)=>{At.init(e,t),e._zod.check=n=>{DA(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),B_=ae("$ZodNumber",(e,t)=>{Ot.init(e,t),e._zod.pattern=e._zod.bag.pattern??P_,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const i=n.value;if(typeof i=="number"&&!Number.isNaN(i)&&Number.isFinite(i))return n;const s=typeof i=="number"?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...s?{received:s}:{}}),n}}),FA=ae("$ZodNumberFormat",(e,t)=>{XE.init(e,t),B_.init(e,t)}),BA=ae("$ZodBoolean",(e,t)=>{Ot.init(e,t),e._zod.pattern=JE,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}const i=n.value;return typeof i=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:e}),n}}),UA=ae("$ZodUnknown",(e,t)=>{Ot.init(e,t),e._zod.parse=n=>n}),jA=ae("$ZodNever",(e,t)=>{Ot.init(e,t),e._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function o0(e,t,n){e.issues.length&&t.issues.push(...ds(n,e.issues)),t.value[n]=e.value}const MA=ae("$ZodArray",(e,t)=>{Ot.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=Array(i.length);const s=[];for(let o=0;o<i.length;o++){const a=i[o],c=t.element._zod.run({value:a,issues:[]},r);c instanceof Promise?s.push(c.then(l=>o0(l,n,o))):o0(c,n,o)}return s.length?Promise.all(s).then(()=>n):n}});function pc(e,t,n,r,i){if(e.issues.length){if(i&&!(n in r))return;t.issues.push(...ds(n,e.issues))}e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function U_(e){const t=Object.keys(e.shape);for(const r of t)if(!e.shape?.[r]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${r}": expected a Zod schema`);const n=sE(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function j_(e,t,n,r,i,s){const o=[],a=i.keySet,c=i.catchall._zod,l=c.def.type,f=c.optout==="optional";for(const u in t){if(a.has(u))continue;if(l==="never"){o.push(u);continue}const h=c.run({value:t[u],issues:[]},r);h instanceof Promise?e.push(h.then(d=>pc(d,n,u,t,f))):pc(h,n,u,t,f)}return o.length&&n.issues.push({code:"unrecognized_keys",keys:o,input:t,inst:s}),e.length?Promise.all(e).then(()=>n):n}const LA=ae("$ZodObject",(e,t)=>{if(Ot.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const a=t.shape;Object.defineProperty(t,"shape",{get:()=>{const c={...a};return Object.defineProperty(t,"shape",{value:c}),c}})}const r=Zc(()=>U_(t));ct(e._zod,"propValues",()=>{const a=t.shape,c={};for(const l in a){const f=a[l]._zod;if(f.values){c[l]??(c[l]=new Set);for(const u of f.values)c[l].add(u)}}return c});const i=zo,s=t.catchall;let o;e._zod.parse=(a,c)=>{o??(o=r.value);const l=a.value;if(!i(l))return a.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),a;a.value={};const f=[],u=o.shape;for(const h of o.keys){const d=u[h],g=d._zod.optout==="optional",p=d._zod.run({value:l[h],issues:[]},c);p instanceof Promise?f.push(p.then(m=>pc(m,a,h,l,g))):pc(p,a,h,l,g)}return s?j_(f,l,a,c,r.value,e):f.length?Promise.all(f).then(()=>a):a}}),NA=ae("$ZodObjectJIT",(e,t)=>{LA.init(e,t);const n=e._zod.parse,r=Zc(()=>U_(t)),i=h=>{const d=new lA(["shape","payload","ctx"]),g=r.value,p=_=>{const E=i0(_);return`shape[${E}]._zod.run({ value: input[${E}], issues: [] }, ctx)`};d.write("const input = payload.value;");const m=Object.create(null);let b=0;for(const _ of g.keys)m[_]=`key_${b++}`;d.write("const newResult = {};");for(const _ of g.keys){const E=m[_],k=i0(_),T=h[_]?._zod?.optout==="optional";d.write(`const ${E} = ${p(_)};`),T?d.write(`
|
|
9
|
+
if (${E}.issues.length) {
|
|
10
|
+
if (${k} in input) {
|
|
11
|
+
payload.issues = payload.issues.concat(${E}.issues.map(iss => ({
|
|
12
|
+
...iss,
|
|
13
|
+
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
14
|
+
})));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (${E}.value === undefined) {
|
|
19
|
+
if (${k} in input) {
|
|
20
|
+
newResult[${k}] = undefined;
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
newResult[${k}] = ${E}.value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
`):d.write(`
|
|
27
|
+
if (${E}.issues.length) {
|
|
28
|
+
payload.issues = payload.issues.concat(${E}.issues.map(iss => ({
|
|
29
|
+
...iss,
|
|
30
|
+
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
31
|
+
})));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (${E}.value === undefined) {
|
|
35
|
+
if (${k} in input) {
|
|
36
|
+
newResult[${k}] = undefined;
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
newResult[${k}] = ${E}.value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
`)}d.write("payload.value = newResult;"),d.write("return payload;");const x=d.compile();return(_,E)=>x(h,_,E)};let s;const o=zo,a=!x_.jitless,l=a&&rE.value,f=t.catchall;let u;e._zod.parse=(h,d)=>{u??(u=r.value);const g=h.value;return o(g)?a&&l&&d?.async===!1&&d.jitless!==!0?(s||(s=i(t.shape)),h=s(h,d),f?j_([],g,h,d,u,e):h):n(h,d):(h.issues.push({expected:"object",code:"invalid_type",input:g,inst:e}),h)}});function a0(e,t,n,r){for(const s of e)if(s.issues.length===0)return t.value=s.value,t;const i=e.filter(s=>!us(s));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(s=>s.issues.map(o=>ui(o,r,li())))}),t)}const M_=ae("$ZodUnion",(e,t)=>{Ot.init(e,t),ct(e._zod,"optin",()=>t.options.some(i=>i._zod.optin==="optional")?"optional":void 0),ct(e._zod,"optout",()=>t.options.some(i=>i._zod.optout==="optional")?"optional":void 0),ct(e._zod,"values",()=>{if(t.options.every(i=>i._zod.values))return new Set(t.options.flatMap(i=>Array.from(i._zod.values)))}),ct(e._zod,"pattern",()=>{if(t.options.every(i=>i._zod.pattern)){const i=t.options.map(s=>s._zod.pattern);return new RegExp(`^(${i.map(s=>bf(s.source)).join("|")})$`)}});const n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(i,s)=>{if(n)return r(i,s);let o=!1;const a=[];for(const c of t.options){const l=c._zod.run({value:i.value,issues:[]},s);if(l instanceof Promise)a.push(l),o=!0;else{if(l.issues.length===0)return l;a.push(l)}}return o?Promise.all(a).then(c=>a0(c,i,e,s)):a0(a,i,e,s)}}),HA=ae("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,M_.init(e,t);const n=e._zod.parse;ct(e._zod,"propValues",()=>{const i={};for(const s of t.options){const o=s._zod.propValues;if(!o||Object.keys(o).length===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(s)}"`);for(const[a,c]of Object.entries(o)){i[a]||(i[a]=new Set);for(const l of c)i[a].add(l)}}return i});const r=Zc(()=>{const i=t.options,s=new Map;for(const o of i){const a=o._zod.propValues?.[t.discriminator];if(!a||a.size===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(o)}"`);for(const c of a){if(s.has(c))throw new Error(`Duplicate discriminator value "${String(c)}"`);s.set(c,o)}}return s});e._zod.parse=(i,s)=>{const o=i.value;if(!zo(o))return i.issues.push({code:"invalid_type",expected:"object",input:o,inst:e}),i;const a=r.value.get(o?.[t.discriminator]);return a?a._zod.run(i,s):t.unionFallback?n(i,s):(i.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,input:o,path:[t.discriminator],inst:e}),i)}}),ZA=ae("$ZodIntersection",(e,t)=>{Ot.init(e,t),e._zod.parse=(n,r)=>{const i=n.value,s=t.left._zod.run({value:i,issues:[]},r),o=t.right._zod.run({value:i,issues:[]},r);return s instanceof Promise||o instanceof Promise?Promise.all([s,o]).then(([c,l])=>c0(n,c,l)):c0(n,s,o)}});function id(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Es(e)&&Es(t)){const n=Object.keys(t),r=Object.keys(e).filter(s=>n.indexOf(s)!==-1),i={...e,...t};for(const s of r){const o=id(e[s],t[s]);if(!o.valid)return{valid:!1,mergeErrorPath:[s,...o.mergeErrorPath]};i[s]=o.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const i=e[r],s=t[r],o=id(i,s);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function c0(e,t,n){const r=new Map;let i;for(const a of t.issues)if(a.code==="unrecognized_keys"){i??(i=a);for(const c of a.keys)r.has(c)||r.set(c,{}),r.get(c).l=!0}else e.issues.push(a);for(const a of n.issues)if(a.code==="unrecognized_keys")for(const c of a.keys)r.has(c)||r.set(c,{}),r.get(c).r=!0;else e.issues.push(a);const s=[...r].filter(([,a])=>a.l&&a.r).map(([a])=>a);if(s.length&&i&&e.issues.push({...i,keys:s}),us(e))return e;const o=id(t.value,n.value);if(!o.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const VA=ae("$ZodRecord",(e,t)=>{Ot.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Es(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:e}),n;const s=[],o=t.keyType._zod.values;if(o){n.value={};const a=new Set;for(const l of o)if(typeof l=="string"||typeof l=="number"||typeof l=="symbol"){a.add(typeof l=="number"?l.toString():l);const f=t.valueType._zod.run({value:i[l],issues:[]},r);f instanceof Promise?s.push(f.then(u=>{u.issues.length&&n.issues.push(...ds(l,u.issues)),n.value[l]=u.value})):(f.issues.length&&n.issues.push(...ds(l,f.issues)),n.value[l]=f.value)}let c;for(const l in i)a.has(l)||(c=c??[],c.push(l));c&&c.length>0&&n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:c})}else{n.value={};for(const a of Reflect.ownKeys(i)){if(a==="__proto__")continue;let c=t.keyType._zod.run({value:a,issues:[]},r);if(c instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof a=="string"&&P_.test(a)&&c.issues.length&&c.issues.some(u=>u.code==="invalid_type"&&u.expected==="number")){const u=t.keyType._zod.run({value:Number(a),issues:[]},r);if(u instanceof Promise)throw new Error("Async schemas not supported in object keys currently");u.issues.length===0&&(c=u)}if(c.issues.length){t.mode==="loose"?n.value[a]=i[a]:n.issues.push({code:"invalid_key",origin:"record",issues:c.issues.map(u=>ui(u,r,li())),input:a,path:[a],inst:e});continue}const f=t.valueType._zod.run({value:i[a],issues:[]},r);f instanceof Promise?s.push(f.then(u=>{u.issues.length&&n.issues.push(...ds(a,u.issues)),n.value[c.value]=u.value})):(f.issues.length&&n.issues.push(...ds(a,f.issues)),n.value[c.value]=f.value)}}return s.length?Promise.all(s).then(()=>n):n}}),WA=ae("$ZodEnum",(e,t)=>{Ot.init(e,t);const n=S_(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(i=>iE.has(typeof i)).map(i=>typeof i=="string"?As(i):i.toString()).join("|")})$`),e._zod.parse=(i,s)=>{const o=i.value;return r.has(o)||i.issues.push({code:"invalid_value",values:n,input:o,inst:e}),i}}),qA=ae("$ZodLiteral",(e,t)=>{if(Ot.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(r=>typeof r=="string"?As(r):r?As(r.toString()):String(r)).join("|")})$`),e._zod.parse=(r,i)=>{const s=r.value;return n.has(s)||r.issues.push({code:"invalid_value",values:t.values,input:s,inst:e}),r}}),JA=ae("$ZodTransform",(e,t)=>{Ot.init(e,t),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new v_(e.constructor.name);const i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(o=>(n.value=o,n));if(i instanceof Promise)throw new ps;return n.value=i,n}});function l0(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const L_=ae("$ZodOptional",(e,t)=>{Ot.init(e,t),e._zod.optin="optional",e._zod.optout="optional",ct(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),ct(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${bf(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>{if(t.innerType._zod.optin==="optional"){const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>l0(s,n.value)):l0(i,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,r)}}),KA=ae("$ZodExactOptional",(e,t)=>{L_.init(e,t),ct(e._zod,"values",()=>t.innerType._zod.values),ct(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,r)=>t.innerType._zod.run(n,r)}),GA=ae("$ZodNullable",(e,t)=>{Ot.init(e,t),ct(e._zod,"optin",()=>t.innerType._zod.optin),ct(e._zod,"optout",()=>t.innerType._zod.optout),ct(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${bf(n.source)}|null)$`):void 0}),ct(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,r)=>n.value===null?n:t.innerType._zod.run(n,r)}),YA=ae("$ZodDefault",(e,t)=>{Ot.init(e,t),e._zod.optin="optional",ct(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);if(n.value===void 0)return n.value=t.defaultValue,n;const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>u0(s,t)):u0(i,t)}});function u0(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const XA=ae("$ZodPrefault",(e,t)=>{Ot.init(e,t),e._zod.optin="optional",ct(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,r))}),QA=ae("$ZodNonOptional",(e,t)=>{Ot.init(e,t),ct(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),e._zod.parse=(n,r)=>{const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>d0(s,e)):d0(i,e)}});function d0(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const eI=ae("$ZodCatch",(e,t)=>{Ot.init(e,t),ct(e._zod,"optin",()=>t.innerType._zod.optin),ct(e._zod,"optout",()=>t.innerType._zod.optout),ct(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>(n.value=s.value,s.issues.length&&(n.value=t.catchValue({...n,error:{issues:s.issues.map(o=>ui(o,r,li()))},input:n.value}),n.issues=[]),n)):(n.value=i.value,i.issues.length&&(n.value=t.catchValue({...n,error:{issues:i.issues.map(s=>ui(s,r,li()))},input:n.value}),n.issues=[]),n)}}),tI=ae("$ZodPipe",(e,t)=>{Ot.init(e,t),ct(e._zod,"values",()=>t.in._zod.values),ct(e._zod,"optin",()=>t.in._zod.optin),ct(e._zod,"optout",()=>t.out._zod.optout),ct(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,r)=>{if(r.direction==="backward"){const s=t.out._zod.run(n,r);return s instanceof Promise?s.then(o=>_a(o,t.in,r)):_a(s,t.in,r)}const i=t.in._zod.run(n,r);return i instanceof Promise?i.then(s=>_a(s,t.out,r)):_a(i,t.out,r)}});function _a(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const nI=ae("$ZodReadonly",(e,t)=>{Ot.init(e,t),ct(e._zod,"propValues",()=>t.innerType._zod.propValues),ct(e._zod,"values",()=>t.innerType._zod.values),ct(e._zod,"optin",()=>t.innerType?._zod?.optin),ct(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(f0):f0(i)}});function f0(e){return e.value=Object.freeze(e.value),e}const rI=ae("$ZodCustom",(e,t)=>{kn.init(e,t),Ot.init(e,t),e._zod.parse=(n,r)=>n,e._zod.check=n=>{const r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(s=>h0(s,n,r,e));h0(i,n,r,e)}});function h0(e,t,n,r){if(!e){const i={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(i.params=r._zod.def.params),t.issues.push(Oo(i))}}var g0;let iI=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const r=n[0];return this._map.set(t,r),r&&typeof r=="object"&&"id"in r&&this._idmap.set(r.id,t),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const r={...this.get(n)??{}};delete r.id;const i={...r,...this._map.get(t)};return Object.keys(i).length?i:void 0}return this._map.get(t)}has(t){return this._map.has(t)}};function sI(){return new iI}(g0=globalThis).__zod_globalRegistry??(g0.__zod_globalRegistry=sI());const no=globalThis.__zod_globalRegistry;function oI(e,t){return new e({type:"string",...Me(t)})}function aI(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...Me(t)})}function p0(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...Me(t)})}function cI(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...Me(t)})}function lI(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...Me(t)})}function uI(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...Me(t)})}function dI(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...Me(t)})}function fI(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...Me(t)})}function hI(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...Me(t)})}function gI(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...Me(t)})}function pI(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...Me(t)})}function mI(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...Me(t)})}function _I(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...Me(t)})}function yI(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...Me(t)})}function bI(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...Me(t)})}function wI(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...Me(t)})}function vI(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...Me(t)})}function xI(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...Me(t)})}function SI(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...Me(t)})}function $I(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...Me(t)})}function kI(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...Me(t)})}function EI(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...Me(t)})}function AI(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...Me(t)})}function II(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...Me(t)})}function CI(e,t){return new e({type:"string",format:"date",check:"string_format",...Me(t)})}function zI(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...Me(t)})}function OI(e,t){return new e({type:"string",format:"duration",check:"string_format",...Me(t)})}function PI(e,t){return new e({type:"number",checks:[],...Me(t)})}function TI(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...Me(t)})}function DI(e,t){return new e({type:"boolean",...Me(t)})}function RI(e){return new e({type:"unknown"})}function FI(e,t){return new e({type:"never",...Me(t)})}function m0(e,t){return new D_({check:"less_than",...Me(t),value:e,inclusive:!1})}function Gl(e,t){return new D_({check:"less_than",...Me(t),value:e,inclusive:!0})}function _0(e,t){return new R_({check:"greater_than",...Me(t),value:e,inclusive:!1})}function Yl(e,t){return new R_({check:"greater_than",...Me(t),value:e,inclusive:!0})}function y0(e,t){return new YE({check:"multiple_of",...Me(t),value:e})}function N_(e,t){return new QE({check:"max_length",...Me(t),maximum:e})}function mc(e,t){return new eA({check:"min_length",...Me(t),minimum:e})}function H_(e,t){return new tA({check:"length_equals",...Me(t),length:e})}function BI(e,t){return new nA({check:"string_format",format:"regex",...Me(t),pattern:e})}function UI(e){return new rA({check:"string_format",format:"lowercase",...Me(e)})}function jI(e){return new iA({check:"string_format",format:"uppercase",...Me(e)})}function MI(e,t){return new sA({check:"string_format",format:"includes",...Me(t),includes:e})}function LI(e,t){return new oA({check:"string_format",format:"starts_with",...Me(t),prefix:e})}function NI(e,t){return new aA({check:"string_format",format:"ends_with",...Me(t),suffix:e})}function Rs(e){return new cA({check:"overwrite",tx:e})}function HI(e){return Rs(t=>t.normalize(e))}function ZI(){return Rs(e=>e.trim())}function VI(){return Rs(e=>e.toLowerCase())}function WI(){return Rs(e=>e.toUpperCase())}function qI(){return Rs(e=>nE(e))}function JI(e,t,n){return new e({type:"array",element:t,...Me(n)})}function KI(e,t,n){return new e({type:"custom",check:"custom",fn:t,...Me(n)})}function GI(e){const t=YI(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(Oo(r,n.value,t._zod.def));else{const i=r;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),i.input??(i.input=n.value),i.inst??(i.inst=t),i.continue??(i.continue=!t._zod.def.abort),n.issues.push(Oo(i))}},e(n.value,n)));return t}function YI(e,t){const n=new kn({check:"custom",...Me(t)});return n._zod.check=e,n}function Z_(e){let t=e?.target??"draft-2020-12";return t==="draft-4"&&(t="draft-04"),t==="draft-7"&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:e?.metadata??no,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,cycles:e?.cycles??"ref",reused:e?.reused??"inline",external:e?.external??void 0}}function Ht(e,t,n={path:[],schemaPath:[]}){var r;const i=e._zod.def,s=t.seen.get(e);if(s)return s.count++,n.schemaPath.includes(e)&&(s.cycle=n.path),s.schema;const o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);const a=e._zod.toJSONSchema?.();if(a)o.schema=a;else{const f={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,f);else{const h=o.schema,d=t.processors[i.type];if(!d)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);d(e,t,h,f)}const u=e._zod.parent;u&&(o.ref||(o.ref=u),Ht(u,t,f),t.seen.get(u).isParent=!0)}const c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io==="input"&&fn(e)&&(delete o.schema.examples,delete o.schema.default),t.io==="input"&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function V_(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const o of e.seen.entries()){const a=e.metadataRegistry.get(o[0])?.id;if(a){const c=r.get(a);if(c&&c!==o[0])throw new Error(`Duplicate schema id "${a}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(a,o[0])}}const i=o=>{const a=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){const u=e.external.registry.get(o[0])?.id,h=e.external.uri??(g=>g);if(u)return{ref:h(u)};const d=o[1].defId??o[1].schema.id??`schema${e.counter++}`;return o[1].defId=d,{defId:d,ref:`${h("__shared")}#/${a}/${d}`}}if(o[1]===n)return{ref:"#"};const l=`#/${a}/`,f=o[1].schema.id??`__schema${e.counter++}`;return{defId:f,ref:l+f}},s=o=>{if(o[1].schema.$ref)return;const a=o[1],{ref:c,defId:l}=i(o);a.def={...a.schema},l&&(a.defId=l);const f=a.schema;for(const u in f)delete f[u];f.$ref=c};if(e.cycles==="throw")for(const o of e.seen.entries()){const a=o[1];if(a.cycle)throw new Error(`Cycle detected: #/${a.cycle?.join("/")}/<root>
|
|
43
|
+
|
|
44
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const o of e.seen.entries()){const a=o[1];if(t===o[0]){s(o);continue}if(e.external){const l=e.external.registry.get(o[0])?.id;if(t!==o[0]&&l){s(o);continue}}if(e.metadataRegistry.get(o[0])?.id){s(o);continue}if(a.cycle){s(o);continue}if(a.count>1&&e.reused==="ref"){s(o);continue}}}function W_(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=o=>{const a=e.seen.get(o);if(a.ref===null)return;const c=a.def??a.schema,l={...c},f=a.ref;if(a.ref=null,f){r(f);const h=e.seen.get(f),d=h.schema;if(d.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(c.allOf=c.allOf??[],c.allOf.push(d)):Object.assign(c,d),Object.assign(c,l),o._zod.parent===f)for(const p in c)p==="$ref"||p==="allOf"||p in l||delete c[p];if(d.$ref)for(const p in c)p==="$ref"||p==="allOf"||p in h.def&&JSON.stringify(c[p])===JSON.stringify(h.def[p])&&delete c[p]}const u=o._zod.parent;if(u&&u!==f){r(u);const h=e.seen.get(u);if(h?.schema.$ref&&(c.$ref=h.schema.$ref,h.def))for(const d in c)d==="$ref"||d==="allOf"||d in h.def&&JSON.stringify(c[d])===JSON.stringify(h.def[d])&&delete c[d]}e.override({zodSchema:o,jsonSchema:c,path:a.path??[]})};for(const o of[...e.seen.entries()].reverse())r(o[0]);const i={};if(e.target==="draft-2020-12"?i.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?i.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?i.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){const o=e.external.registry.get(t)?.id;if(!o)throw new Error("Schema is missing an `id` property");i.$id=e.external.uri(o)}Object.assign(i,n.def??n.schema);const s=e.external?.defs??{};for(const o of e.seen.entries()){const a=o[1];a.def&&a.defId&&(s[a.defId]=a.def)}e.external||Object.keys(s).length>0&&(e.target==="draft-2020-12"?i.$defs=s:i.definitions=s);try{const o=JSON.parse(JSON.stringify(i));return Object.defineProperty(o,"~standard",{value:{...t["~standard"],jsonSchema:{input:_c(t,"input",e.processors),output:_c(t,"output",e.processors)}},enumerable:!1,writable:!1}),o}catch{throw new Error("Error converting schema to JSON.")}}function fn(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return fn(r.element,n);if(r.type==="set")return fn(r.valueType,n);if(r.type==="lazy")return fn(r.getter(),n);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault")return fn(r.innerType,n);if(r.type==="intersection")return fn(r.left,n)||fn(r.right,n);if(r.type==="record"||r.type==="map")return fn(r.keyType,n)||fn(r.valueType,n);if(r.type==="pipe")return fn(r.in,n)||fn(r.out,n);if(r.type==="object"){for(const i in r.shape)if(fn(r.shape[i],n))return!0;return!1}if(r.type==="union"){for(const i of r.options)if(fn(i,n))return!0;return!1}if(r.type==="tuple"){for(const i of r.items)if(fn(i,n))return!0;return!!(r.rest&&fn(r.rest,n))}return!1}const XI=(e,t={})=>n=>{const r=Z_({...n,processors:t});return Ht(e,r),V_(r,e),W_(r,e)},_c=(e,t,n={})=>r=>{const{libraryOptions:i,target:s}=r??{},o=Z_({...i??{},target:s,io:t,processors:n});return Ht(e,o),V_(o,e),W_(o,e)},QI={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},eC=(e,t,n,r)=>{const i=n;i.type="string";const{minimum:s,maximum:o,format:a,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof s=="number"&&(i.minLength=s),typeof o=="number"&&(i.maxLength=o),a&&(i.format=QI[a]??a,i.format===""&&delete i.format,a==="time"&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){const f=[...c];f.length===1?i.pattern=f[0].source:f.length>1&&(i.allOf=[...f.map(u=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:u.source}))])}},tC=(e,t,n,r)=>{const i=n,{minimum:s,maximum:o,format:a,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:f}=e._zod.bag;typeof a=="string"&&a.includes("int")?i.type="integer":i.type="number",typeof f=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(i.minimum=f,i.exclusiveMinimum=!0):i.exclusiveMinimum=f),typeof s=="number"&&(i.minimum=s,typeof f=="number"&&t.target!=="draft-04"&&(f>=s?delete i.minimum:delete i.exclusiveMinimum)),typeof l=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l),typeof o=="number"&&(i.maximum=o,typeof l=="number"&&t.target!=="draft-04"&&(l<=o?delete i.maximum:delete i.exclusiveMaximum)),typeof c=="number"&&(i.multipleOf=c)},nC=(e,t,n,r)=>{n.type="boolean"},rC=(e,t,n,r)=>{n.not={}},iC=(e,t,n,r)=>{},sC=(e,t,n,r)=>{const i=e._zod.def,s=S_(i.entries);s.every(o=>typeof o=="number")&&(n.type="number"),s.every(o=>typeof o=="string")&&(n.type="string"),n.enum=s},oC=(e,t,n,r)=>{const i=e._zod.def,s=[];for(const o of i.values)if(o===void 0){if(t.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof o=="bigint"){if(t.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");s.push(Number(o))}else s.push(o);if(s.length!==0)if(s.length===1){const o=s[0];n.type=o===null?"null":typeof o,t.target==="draft-04"||t.target==="openapi-3.0"?n.enum=[o]:n.const=o}else s.every(o=>typeof o=="number")&&(n.type="number"),s.every(o=>typeof o=="string")&&(n.type="string"),s.every(o=>typeof o=="boolean")&&(n.type="boolean"),s.every(o=>o===null)&&(n.type="null"),n.enum=s},aC=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},cC=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},lC=(e,t,n,r)=>{const i=n,s=e._zod.def,{minimum:o,maximum:a}=e._zod.bag;typeof o=="number"&&(i.minItems=o),typeof a=="number"&&(i.maxItems=a),i.type="array",i.items=Ht(s.element,t,{...r,path:[...r.path,"items"]})},uC=(e,t,n,r)=>{const i=n,s=e._zod.def;i.type="object",i.properties={};const o=s.shape;for(const l in o)i.properties[l]=Ht(o[l],t,{...r,path:[...r.path,"properties",l]});const a=new Set(Object.keys(o)),c=new Set([...a].filter(l=>{const f=s.shape[l]._zod;return t.io==="input"?f.optin===void 0:f.optout===void 0}));c.size>0&&(i.required=Array.from(c)),s.catchall?._zod.def.type==="never"?i.additionalProperties=!1:s.catchall?s.catchall&&(i.additionalProperties=Ht(s.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):t.io==="output"&&(i.additionalProperties=!1)},dC=(e,t,n,r)=>{const i=e._zod.def,s=i.inclusive===!1,o=i.options.map((a,c)=>Ht(a,t,{...r,path:[...r.path,s?"oneOf":"anyOf",c]}));s?n.oneOf=o:n.anyOf=o},fC=(e,t,n,r)=>{const i=e._zod.def,s=Ht(i.left,t,{...r,path:[...r.path,"allOf",0]}),o=Ht(i.right,t,{...r,path:[...r.path,"allOf",1]}),a=l=>"allOf"in l&&Object.keys(l).length===1,c=[...a(s)?s.allOf:[s],...a(o)?o.allOf:[o]];n.allOf=c},hC=(e,t,n,r)=>{const i=n,s=e._zod.def;i.type="object";const o=s.keyType,c=o._zod.bag?.patterns;if(s.mode==="loose"&&c&&c.size>0){const f=Ht(s.valueType,t,{...r,path:[...r.path,"patternProperties","*"]});i.patternProperties={};for(const u of c)i.patternProperties[u.source]=f}else(t.target==="draft-07"||t.target==="draft-2020-12")&&(i.propertyNames=Ht(s.keyType,t,{...r,path:[...r.path,"propertyNames"]})),i.additionalProperties=Ht(s.valueType,t,{...r,path:[...r.path,"additionalProperties"]});const l=o._zod.values;if(l){const f=[...l].filter(u=>typeof u=="string"||typeof u=="number");f.length>0&&(i.required=f)}},gC=(e,t,n,r)=>{const i=e._zod.def,s=Ht(i.innerType,t,r),o=t.seen.get(e);t.target==="openapi-3.0"?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[s,{type:"null"}]},pC=(e,t,n,r)=>{const i=e._zod.def;Ht(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType},mC=(e,t,n,r)=>{const i=e._zod.def;Ht(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},_C=(e,t,n,r)=>{const i=e._zod.def;Ht(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType,t.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},yC=(e,t,n,r)=>{const i=e._zod.def;Ht(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=o},bC=(e,t,n,r)=>{const i=e._zod.def,s=t.io==="input"?i.in._zod.def.type==="transform"?i.out:i.in:i.out;Ht(s,t,r);const o=t.seen.get(e);o.ref=s},wC=(e,t,n,r)=>{const i=e._zod.def;Ht(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType,n.readOnly=!0},q_=(e,t,n,r)=>{const i=e._zod.def;Ht(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType},vC=ae("ZodISODateTime",(e,t)=>{xA.init(e,t),Tt.init(e,t)});function xC(e){return II(vC,e)}const SC=ae("ZodISODate",(e,t)=>{SA.init(e,t),Tt.init(e,t)});function $C(e){return CI(SC,e)}const kC=ae("ZodISOTime",(e,t)=>{$A.init(e,t),Tt.init(e,t)});function EC(e){return zI(kC,e)}const AC=ae("ZodISODuration",(e,t)=>{kA.init(e,t),Tt.init(e,t)});function IC(e){return OI(AC,e)}const J_=(e,t)=>{A_.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>pE(e,n)},flatten:{value:n=>gE(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,rd,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,rd,2)}},isEmpty:{get(){return e.issues.length===0}}})},CC=ae("ZodError",J_),Jn=ae("ZodError",J_,{Parent:Error}),zC=vf(Jn),OC=xf(Jn),PC=Vc(Jn),TC=Wc(Jn),DC=yE(Jn),RC=bE(Jn),FC=wE(Jn),BC=vE(Jn),UC=xE(Jn),jC=SE(Jn),MC=$E(Jn),LC=kE(Jn),Pt=ae("ZodType",(e,t)=>(Ot.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:_c(e,"input"),output:_c(e,"output")}}),e.toJSONSchema=XI(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(hi(t,{checks:[...t.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0}),e.with=e.check,e.clone=(n,r)=>gi(e,n,r),e.brand=()=>e,e.register=((n,r)=>(n.add(e,r),e)),e.parse=(n,r)=>zC(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>PC(e,n,r),e.parseAsync=async(n,r)=>OC(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>TC(e,n,r),e.spa=e.safeParseAsync,e.encode=(n,r)=>DC(e,n,r),e.decode=(n,r)=>RC(e,n,r),e.encodeAsync=async(n,r)=>FC(e,n,r),e.decodeAsync=async(n,r)=>BC(e,n,r),e.safeEncode=(n,r)=>UC(e,n,r),e.safeDecode=(n,r)=>jC(e,n,r),e.safeEncodeAsync=async(n,r)=>MC(e,n,r),e.safeDecodeAsync=async(n,r)=>LC(e,n,r),e.refine=(n,r)=>e.check(Rz(n,r)),e.superRefine=n=>e.check(Fz(n)),e.overwrite=n=>e.check(Rs(n)),e.optional=()=>x0(e),e.exactOptional=()=>xz(e),e.nullable=()=>S0(e),e.nullish=()=>x0(S0(e)),e.nonoptional=n=>Iz(e,n),e.array=()=>Pr(e),e.or=n=>Po([e,n]),e.and=n=>mz(e,n),e.transform=n=>$0(e,wz(n)),e.default=n=>kz(e,n),e.prefault=n=>Az(e,n),e.catch=n=>zz(e,n),e.pipe=n=>$0(e,n),e.readonly=()=>Tz(e),e.describe=n=>{const r=e.clone();return no.add(r,{description:n}),r},Object.defineProperty(e,"description",{get(){return no.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return no.get(e);const r=e.clone();return no.add(r,n[0]),r},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=n=>n(e),e)),K_=ae("_ZodString",(e,t)=>{Sf.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(r,i,s)=>eC(e,r,i);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...r)=>e.check(BI(...r)),e.includes=(...r)=>e.check(MI(...r)),e.startsWith=(...r)=>e.check(LI(...r)),e.endsWith=(...r)=>e.check(NI(...r)),e.min=(...r)=>e.check(mc(...r)),e.max=(...r)=>e.check(N_(...r)),e.length=(...r)=>e.check(H_(...r)),e.nonempty=(...r)=>e.check(mc(1,...r)),e.lowercase=r=>e.check(UI(r)),e.uppercase=r=>e.check(jI(r)),e.trim=()=>e.check(ZI()),e.normalize=(...r)=>e.check(HI(...r)),e.toLowerCase=()=>e.check(VI()),e.toUpperCase=()=>e.check(WI()),e.slugify=()=>e.check(qI())}),NC=ae("ZodString",(e,t)=>{Sf.init(e,t),K_.init(e,t),e.email=n=>e.check(aI(HC,n)),e.url=n=>e.check(fI(ZC,n)),e.jwt=n=>e.check(AI(sz,n)),e.emoji=n=>e.check(hI(VC,n)),e.guid=n=>e.check(p0(b0,n)),e.uuid=n=>e.check(cI(ya,n)),e.uuidv4=n=>e.check(lI(ya,n)),e.uuidv6=n=>e.check(uI(ya,n)),e.uuidv7=n=>e.check(dI(ya,n)),e.nanoid=n=>e.check(gI(WC,n)),e.guid=n=>e.check(p0(b0,n)),e.cuid=n=>e.check(pI(qC,n)),e.cuid2=n=>e.check(mI(JC,n)),e.ulid=n=>e.check(_I(KC,n)),e.base64=n=>e.check($I(nz,n)),e.base64url=n=>e.check(kI(rz,n)),e.xid=n=>e.check(yI(GC,n)),e.ksuid=n=>e.check(bI(YC,n)),e.ipv4=n=>e.check(wI(XC,n)),e.ipv6=n=>e.check(vI(QC,n)),e.cidrv4=n=>e.check(xI(ez,n)),e.cidrv6=n=>e.check(SI(tz,n)),e.e164=n=>e.check(EI(iz,n)),e.datetime=n=>e.check(xC(n)),e.date=n=>e.check($C(n)),e.time=n=>e.check(EC(n)),e.duration=n=>e.check(IC(n))});function Ze(e){return oI(NC,e)}const Tt=ae("ZodStringFormat",(e,t)=>{At.init(e,t),K_.init(e,t)}),HC=ae("ZodEmail",(e,t)=>{hA.init(e,t),Tt.init(e,t)}),b0=ae("ZodGUID",(e,t)=>{dA.init(e,t),Tt.init(e,t)}),ya=ae("ZodUUID",(e,t)=>{fA.init(e,t),Tt.init(e,t)}),ZC=ae("ZodURL",(e,t)=>{gA.init(e,t),Tt.init(e,t)}),VC=ae("ZodEmoji",(e,t)=>{pA.init(e,t),Tt.init(e,t)}),WC=ae("ZodNanoID",(e,t)=>{mA.init(e,t),Tt.init(e,t)}),qC=ae("ZodCUID",(e,t)=>{_A.init(e,t),Tt.init(e,t)}),JC=ae("ZodCUID2",(e,t)=>{yA.init(e,t),Tt.init(e,t)}),KC=ae("ZodULID",(e,t)=>{bA.init(e,t),Tt.init(e,t)}),GC=ae("ZodXID",(e,t)=>{wA.init(e,t),Tt.init(e,t)}),YC=ae("ZodKSUID",(e,t)=>{vA.init(e,t),Tt.init(e,t)}),XC=ae("ZodIPv4",(e,t)=>{EA.init(e,t),Tt.init(e,t)}),QC=ae("ZodIPv6",(e,t)=>{AA.init(e,t),Tt.init(e,t)}),ez=ae("ZodCIDRv4",(e,t)=>{IA.init(e,t),Tt.init(e,t)}),tz=ae("ZodCIDRv6",(e,t)=>{CA.init(e,t),Tt.init(e,t)}),nz=ae("ZodBase64",(e,t)=>{zA.init(e,t),Tt.init(e,t)}),rz=ae("ZodBase64URL",(e,t)=>{PA.init(e,t),Tt.init(e,t)}),iz=ae("ZodE164",(e,t)=>{TA.init(e,t),Tt.init(e,t)}),sz=ae("ZodJWT",(e,t)=>{RA.init(e,t),Tt.init(e,t)}),G_=ae("ZodNumber",(e,t)=>{B_.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(r,i,s)=>tC(e,r,i),e.gt=(r,i)=>e.check(_0(r,i)),e.gte=(r,i)=>e.check(Yl(r,i)),e.min=(r,i)=>e.check(Yl(r,i)),e.lt=(r,i)=>e.check(m0(r,i)),e.lte=(r,i)=>e.check(Gl(r,i)),e.max=(r,i)=>e.check(Gl(r,i)),e.int=r=>e.check(w0(r)),e.safe=r=>e.check(w0(r)),e.positive=r=>e.check(_0(0,r)),e.nonnegative=r=>e.check(Yl(0,r)),e.negative=r=>e.check(m0(0,r)),e.nonpositive=r=>e.check(Gl(0,r)),e.multipleOf=(r,i)=>e.check(y0(r,i)),e.step=(r,i)=>e.check(y0(r,i)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Qr(e){return PI(G_,e)}const oz=ae("ZodNumberFormat",(e,t)=>{FA.init(e,t),G_.init(e,t)});function w0(e){return TI(oz,e)}const az=ae("ZodBoolean",(e,t)=>{BA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>nC(e,n,r)});function uo(e){return DI(az,e)}const cz=ae("ZodUnknown",(e,t)=>{UA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>iC()});function v0(){return RI(cz)}const lz=ae("ZodNever",(e,t)=>{jA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>rC(e,n,r)});function uz(e){return FI(lz,e)}const dz=ae("ZodArray",(e,t)=>{MA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>lC(e,n,r,i),e.element=t.element,e.min=(n,r)=>e.check(mc(n,r)),e.nonempty=n=>e.check(mc(1,n)),e.max=(n,r)=>e.check(N_(n,r)),e.length=(n,r)=>e.check(H_(n,r)),e.unwrap=()=>e.element});function Pr(e,t){return JI(dz,e,t)}const fz=ae("ZodObject",(e,t)=>{NA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>uC(e,n,r,i),ct(e,"shape",()=>t.shape),e.keyof=()=>$f(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:v0()}),e.loose=()=>e.clone({...e._zod.def,catchall:v0()}),e.strict=()=>e.clone({...e._zod.def,catchall:uz()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>lE(e,n),e.safeExtend=n=>uE(e,n),e.merge=n=>dE(e,n),e.pick=n=>aE(e,n),e.omit=n=>cE(e,n),e.partial=(...n)=>fE(X_,e,n[0]),e.required=(...n)=>hE(Q_,e,n[0])});function Yt(e,t){const n={type:"object",shape:e??{},...Me(t)};return new fz(n)}const Y_=ae("ZodUnion",(e,t)=>{M_.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>dC(e,n,r,i),e.options=t.options});function Po(e,t){return new Y_({type:"union",options:e,...Me(t)})}const hz=ae("ZodDiscriminatedUnion",(e,t)=>{Y_.init(e,t),HA.init(e,t)});function gz(e,t,n){return new hz({type:"union",options:t,discriminator:e,...Me(n)})}const pz=ae("ZodIntersection",(e,t)=>{ZA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>fC(e,n,r,i)});function mz(e,t){return new pz({type:"intersection",left:e,right:t})}const _z=ae("ZodRecord",(e,t)=>{VA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>hC(e,n,r,i),e.keyType=t.keyType,e.valueType=t.valueType});function Xl(e,t,n){return new _z({type:"record",keyType:e,valueType:t,...Me(n)})}const sd=ae("ZodEnum",(e,t)=>{WA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(r,i,s)=>sC(e,r,i),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(r,i)=>{const s={};for(const o of r)if(n.has(o))s[o]=t.entries[o];else throw new Error(`Key ${o} not found in enum`);return new sd({...t,checks:[],...Me(i),entries:s})},e.exclude=(r,i)=>{const s={...t.entries};for(const o of r)if(n.has(o))delete s[o];else throw new Error(`Key ${o} not found in enum`);return new sd({...t,checks:[],...Me(i),entries:s})}});function $f(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new sd({type:"enum",entries:n,...Me(t)})}const yz=ae("ZodLiteral",(e,t)=>{qA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>oC(e,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Xe(e,t){return new yz({type:"literal",values:Array.isArray(e)?e:[e],...Me(t)})}const bz=ae("ZodTransform",(e,t)=>{JA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>cC(e,n),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new v_(e.constructor.name);n.addIssue=s=>{if(typeof s=="string")n.issues.push(Oo(s,n.value,t));else{const o=s;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=e),n.issues.push(Oo(o))}};const i=t.transform(n.value,n);return i instanceof Promise?i.then(s=>(n.value=s,n)):(n.value=i,n)}});function wz(e){return new bz({type:"transform",transform:e})}const X_=ae("ZodOptional",(e,t)=>{L_.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>q_(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function x0(e){return new X_({type:"optional",innerType:e})}const vz=ae("ZodExactOptional",(e,t)=>{KA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>q_(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function xz(e){return new vz({type:"optional",innerType:e})}const Sz=ae("ZodNullable",(e,t)=>{GA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>gC(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function S0(e){return new Sz({type:"nullable",innerType:e})}const $z=ae("ZodDefault",(e,t)=>{YA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>mC(e,n,r,i),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function kz(e,t){return new $z({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():k_(t)}})}const Ez=ae("ZodPrefault",(e,t)=>{XA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>_C(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function Az(e,t){return new Ez({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():k_(t)}})}const Q_=ae("ZodNonOptional",(e,t)=>{QA.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>pC(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function Iz(e,t){return new Q_({type:"nonoptional",innerType:e,...Me(t)})}const Cz=ae("ZodCatch",(e,t)=>{eI.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>yC(e,n,r,i),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function zz(e,t){return new Cz({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const Oz=ae("ZodPipe",(e,t)=>{tI.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>bC(e,n,r,i),e.in=t.in,e.out=t.out});function $0(e,t){return new Oz({type:"pipe",in:e,out:t})}const Pz=ae("ZodReadonly",(e,t)=>{nI.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>wC(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function Tz(e){return new Pz({type:"readonly",innerType:e})}const Dz=ae("ZodCustom",(e,t)=>{rI.init(e,t),Pt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>aC(e,n)});function Rz(e,t={}){return KI(Dz,e,t)}function Fz(e){return GI(e)}const Bz=Po([Xe("original"),Xe("thumbnail"),Xe("waveform"),Xe("preview")]),ey=Yt({blobId:Ze(),isPrimary:uo(),blobType:Bz}),ty=Yt({id:Ze().optional(),name:Ze().optional(),url:Ze()}),Uz=Yt({id:Ze(),title:Ze(),artist:Ze(),album:Ze(),duration:Qr(),mimeType:Ze(),fileSize:Qr(),sha256:Ze(),blake3:Ze().optional(),images:Pr(ey).default([]),urls:Pr(ty).default([]),lyrics:Ze().optional()}),od=Yt({version:Xe(1).default(1),title:Ze().default(""),description:Ze().default(""),createdAt:Ze().default(()=>new Date().toISOString()),lastModified:Ze().default(()=>new Date().toISOString()),lastModifiedBy:Ze().default(""),images:Pr(ey).default([]),urls:Pr(ty).default([]),songs:Xl(Ze(),Uz).default({}),order:Pr(Ze()).default([]),peers:Xl(Ze(),Yt({nodeId:Ze(),joinedAt:Ze(),lastSeenAt:Ze().optional()})).default({}),acl:Xl(Ze(),Yt({role:Po([Xe("owner"),Xe("editor"),Xe("viewer")])})).optional(),deleted:uo().optional(),sharingMode:Po([Xe("public"),Xe("knock")]).optional(),bgFilterEnabled:uo().optional(),bgFilterBlur:Qr().optional(),bgFilterContrast:Qr().optional(),bgFilterBrightness:Qr().optional(),coverFilterEnabled:uo().optional(),coverFilterBlur:Qr().optional(),bgSize:Ze().optional(),bgPosition:Ze().optional(),bgRepeat:Ze().optional()});function ad(e){if(Array.isArray(e))return e.map(ad);if(e&&typeof e=="object"){const t={};for(const n of Object.keys(e))t[n]=ad(e[n]);return t}return e}function un(e){try{return od.parse(ad(e??{}))}catch(t){return console.warn("[playlistz:schema] parse failed - falling back to defaults. error:",t instanceof CC?t.issues:t,"raw keys:",e&&typeof e=="object"?Object.keys(e):"null"),od.parse({})}}function Jc(e){const t=new Date().toISOString();return od.parse({createdAt:t,lastModified:t,...e})}function ny(){return new Date().toISOString()}function Fs(e,t){e.lastModified=ny()}function kf(e,t,n){e.songs[t.id]=t,e.order.includes(t.id)||e.order.push(t.id),Fs(e)}function jz(e,t,n){delete e.songs[t];const r=e.order.indexOf(t);r!==-1&&e.order.splice(r,1),Fs(e)}function Mz(e,t,n,r){const i=e.order.indexOf(t);if(i===-1)return;e.order.splice(i,1);const s=Math.max(0,Math.min(n,e.order.length));e.order.splice(s,0,t),Fs(e)}function ry(e,t,n){t.title!==void 0&&(e.title=t.title),t.description!==void 0&&(e.description=t.description);for(const r of["bgFilterEnabled","bgFilterBlur","bgFilterContrast","bgFilterBrightness","coverFilterEnabled","coverFilterBlur","bgSize","bgPosition","bgRepeat"])t[r]!==void 0&&(e[r]=t[r]);Fs(e)}function iy(e,t,n,r){const i=n?.songId!=null?e.songs[n.songId]?.images:e.images;if(i){if(t.isPrimary)for(const s of i)s.isPrimary=!1;i.push(t),Fs(e)}}function To(e,t){e.peers[t]||(e.peers[t]={nodeId:t,joinedAt:ny()})}function Lz(e,t){e.deleted=!0,Fs(e)}const Nz=Yt({v:Xe(1),n:Ze().min(1),d:Ze().min(1),t:Ze().optional(),m:$f(["public","knock"]).optional()});function Hz(e){return e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Zz(e){let t=e.replace(/-/g,"+").replace(/_/g,"/");for(;t.length%4!==0;)t+="=";return t}function sy(e){const t=JSON.stringify(e),n=btoa(t);return Hz(n)}function oy(e){try{let t=e.trim();const n=t.indexOf("#share/");n!==-1?t=t.slice(n+7):t.startsWith("share/")&&(t=t.slice(6));const r=t.indexOf("&");if(r!==-1&&(t=t.slice(0,r)),!t)return null;const i=Zz(t),s=atob(i),o=JSON.parse(s),a=Nz.safeParse(o);return a.success?a.data:null}catch{return null}}function Vz(e){return`#share/${sy(e)}`}const Kc="freqhole-playlistz/1",ay="iroh/automerge-repo/1",Wz=Yt({v:Xe(1),type:Xe("hello"),nodeId:Ze(),name:Ze().optional(),avatarBlobId:Ze().optional()}),qz=Yt({v:Xe(1),type:Xe("hello_ok"),nodeId:Ze(),name:Ze().optional(),avatarDataUrl:Ze().optional(),public:uo()}),Jz=Yt({v:Xe(1),type:Xe("list_playlists")}),Kz=Yt({docId:Ze(),title:Ze(),songCount:Qr()}),Gz=Yt({v:Xe(1),type:Xe("playlists"),items:Pr(Kz)}),Yz=Yt({v:Xe(1),type:Xe("knock"),nodeId:Ze(),name:Ze().optional(),message:Ze().optional(),knockType:$f(["browse","doc_access"]).optional(),docId:Ze().optional()}),Xz=Yt({v:Xe(1),type:Xe("knock_status"),status:Po([Xe("pending"),Xe("accepted"),Xe("denied")]),grantedDocIds:Pr(Ze()).optional()}),Qz=Yt({v:Xe(1),type:Xe("blob_request"),sha256:Ze()}),e9=Yt({v:Xe(1),type:Xe("blob_ready"),sha256:Ze(),blake3:Ze(),size:Qr()}),t9=Yt({v:Xe(1),type:Xe("error"),code:Ze(),message:Ze()}),n9=Yt({v:Xe(1),type:Xe("knock_notify"),status:Xe("accepted"),docIds:Pr(Ze()),ownerNodeId:Ze()}),r9=Yt({v:Xe(1),type:Xe("identity_update"),name:Ze().optional(),avatarDataUrl:Ze().optional()}),i9=gz("type",[Wz,qz,Jz,Gz,Yz,Xz,Qz,e9,t9,n9,r9]);class Ql extends Error{constructor(t,n){super(n),this.name="ProtocolError",this.code=t}}const s9=new TextEncoder,o9=new TextDecoder;function a9(e){return s9.encode(JSON.stringify(e))}function c9(e){let t;try{t=o9.decode(e)}catch(i){throw new Ql("decode_error",`failed to decode utf-8: ${i instanceof Error?i.message:String(i)}`)}let n;try{n=JSON.parse(t)}catch(i){throw new Ql("parse_error",`failed to parse json: ${i instanceof Error?i.message:String(i)}`)}const r=i9.safeParse(n);if(!r.success){const i=r.error.issues[0];throw new Ql("schema_error",`invalid message: ${i?.message??"unknown"}`)}return r.data}async function jt(e,t){await e.write_message(a9(t))}async function di(e){const t=await e.read_message();return t===null?null:c9(t)}const cd=(e,t)=>t.some(n=>e instanceof n);let k0,E0;function l9(){return k0||(k0=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function u9(){return E0||(E0=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const ld=new WeakMap,eu=new WeakMap,Gc=new WeakMap;function d9(e){const t=new Promise((n,r)=>{const i=()=>{e.removeEventListener("success",s),e.removeEventListener("error",o)},s=()=>{n(zi(e.result)),i()},o=()=>{r(e.error),i()};e.addEventListener("success",s),e.addEventListener("error",o)});return Gc.set(t,e),t}function f9(e){if(ld.has(e))return;const t=new Promise((n,r)=>{const i=()=>{e.removeEventListener("complete",s),e.removeEventListener("error",o),e.removeEventListener("abort",o)},s=()=>{n(),i()},o=()=>{r(e.error||new DOMException("AbortError","AbortError")),i()};e.addEventListener("complete",s),e.addEventListener("error",o),e.addEventListener("abort",o)});ld.set(e,t)}let ud={get(e,t,n){if(e instanceof IDBTransaction){if(t==="done")return ld.get(e);if(t==="store")return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return zi(e[t])},set(e,t,n){return e[t]=n,!0},has(e,t){return e instanceof IDBTransaction&&(t==="done"||t==="store")?!0:t in e}};function cy(e){ud=e(ud)}function h9(e){return u9().includes(e)?function(...t){return e.apply(dd(this),t),zi(this.request)}:function(...t){return zi(e.apply(dd(this),t))}}function g9(e){return typeof e=="function"?h9(e):(e instanceof IDBTransaction&&f9(e),cd(e,l9())?new Proxy(e,ud):e)}function zi(e){if(e instanceof IDBRequest)return d9(e);if(eu.has(e))return eu.get(e);const t=g9(e);return t!==e&&(eu.set(e,t),Gc.set(t,e)),t}const dd=e=>Gc.get(e);function p9(e,t,{blocked:n,upgrade:r,blocking:i,terminated:s}={}){const o=indexedDB.open(e,t),a=zi(o);return r&&o.addEventListener("upgradeneeded",c=>{r(zi(o.result),c.oldVersion,c.newVersion,zi(o.transaction),c)}),n&&o.addEventListener("blocked",c=>n(c.oldVersion,c.newVersion,c)),a.then(c=>{s&&c.addEventListener("close",()=>s()),i&&c.addEventListener("versionchange",l=>i(l.oldVersion,l.newVersion,l))}).catch(()=>{}),a}const m9=["get","getKey","getAll","getAllKeys","count"],_9=["put","add","delete","clear"],tu=new Map;function A0(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&typeof t=="string"))return;if(tu.get(t))return tu.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,i=_9.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(i||m9.includes(n)))return;const s=async function(o,...a){const c=this.transaction(o,i?"readwrite":"readonly");let l=c.store;return r&&(l=l.index(a.shift())),(await Promise.all([l[n](...a),i&&c.done]))[0]};return tu.set(t,s),s}cy(e=>({...e,get:(t,n,r)=>A0(t,n)||e.get(t,n,r),has:(t,n)=>!!A0(t,n)||e.has(t,n)}));const y9=["continue","continuePrimaryKey","advance"],I0={},fd=new WeakMap,ly=new WeakMap,b9={get(e,t){if(!y9.includes(t))return e[t];let n=I0[t];return n||(n=I0[t]=function(...r){fd.set(this,ly.get(this)[t](...r))}),n}};async function*w9(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;t=t;const n=new Proxy(t,b9);for(ly.set(n,t),Gc.set(n,dd(t));t;)yield n,t=await (fd.get(n)||t.continue()),fd.delete(n)}function C0(e,t){return t===Symbol.asyncIterator&&cd(e,[IDBIndex,IDBObjectStore,IDBCursor])||t==="iterate"&&cd(e,[IDBIndex,IDBObjectStore])}cy(e=>({...e,get(t,n,r){return C0(t,n)?w9:e.get(t,n,r)},has(t,n){return C0(t,n)||e.has(t,n)}}));const uy="freqhole_blobs",v9=1,Is="blobs",Ef="freqhole-blobs",yc=new Map;let ba=null;async function Af(){return ba||(ba=await p9(uy,v9,{upgrade(e){e.objectStoreNames.contains(Is)||e.createObjectStore(Is,{keyPath:"blob_id"})}}),ba)}async function x9(){try{return navigator.storage?.getDirectory?(await navigator.storage.getDirectory(),!0):!1}catch{return!1}}async function S9(e,t){const s=await (await (await (await navigator.storage.getDirectory()).getDirectoryHandle("blobs",{create:!0})).getFileHandle(e,{create:!0})).createWritable();return await s.write(t),await s.close(),`/blobs/${e}`}async function $9(e){try{const n=await (await navigator.storage.getDirectory()).getDirectoryHandle("blobs"),r=e.split("/").pop();return await (await n.getFileHandle(r)).getFile()}catch{return null}}async function k9(e,t,n){const r=await caches.open(Ef),i=`https://blob.local/${e}`,s=new Response(t,{headers:{"Content-Type":n}});return await r.put(i,s),i}async function E9(e){try{const n=await (await caches.open(Ef)).match(e);return n?await n.blob():null}catch{return null}}async function fi(e,t){const n=await Af(),r=await e.arrayBuffer(),i=await crypto.subtle.digest("SHA-256",r),o=Array.from(new Uint8Array(i)).map(h=>h.toString(16).padStart(2,"0")).join("");if(await n.get(Is,o))return o;const c=await x9(),l=c?"opfs":"cache",f=c?await S9(o,e):await k9(o,e,t),u={blob_id:o,storage_type:l,storage_path:f,mime_type:t,file_size:e.size,created_at:Date.now()};return await n.put(Is,u),o}async function Ur(e){return await (await Af()).get(Is,e)||null}async function Yc(e){const t=await Ur(e);return t?t.storage_type==="opfs"?await $9(t.storage_path):await E9(t.storage_path):null}async function Cs(e){if(!e)return null;const t=yc.get(e);if(t)return t;const n=await Yc(e);if(!n)return null;const r=URL.createObjectURL(n);return yc.set(e,r),r}function dy(){yc.forEach(e=>URL.revokeObjectURL(e)),yc.clear()}typeof window<"u"&&window.addEventListener("beforeunload",()=>{dy()});async function fy(e){const t=await Ur(e);if(!t)return;if(t.storage_type==="opfs")try{const i=await (await navigator.storage.getDirectory()).getDirectoryHandle("blobs"),s=t.storage_path.split("/").pop();await i.removeEntry(s)}catch{}else try{await (await caches.open(Ef)).delete(t.storage_path)}catch{}await (await Af()).delete(Is,e)}const ms="freqhole_app",Do="app_state",hy="p2p_identity";async function gy(){if(typeof indexedDB.databases=="function")try{return(await indexedDB.databases()).some(t=>t.name===ms)}catch{}return new Promise(e=>{const t=indexedDB.open(ms);let n=!0;t.onupgradeneeded=r=>{n=!1,r.target.transaction?.abort()},t.onsuccess=()=>{t.result.close(),n||indexedDB.deleteDatabase(ms),e(n)},t.onerror=()=>{e(n)}})}async function py(){return new Promise(e=>{const t=indexedDB.open(ms);t.onupgradeneeded=()=>{t.transaction?.abort(),e(!1)},t.onsuccess=()=>{const n=t.result,r=n.objectStoreNames.contains(Do);n.close(),e(r)},t.onerror=()=>e(!1)})}function A9(){return new Promise(e=>{const t=indexedDB.open(ms);t.onupgradeneeded=()=>{t.transaction?.abort(),e(null)},t.onsuccess=()=>{const n=t.result,i=n.transaction(Do,"readonly").objectStore(Do).get(hy);i.onsuccess=()=>{n.close(),e(i.result??null)},i.onerror=()=>{n.close(),e(null)}},t.onerror=()=>e(null)})}function I9(e){return new Promise((t,n)=>{const r=indexedDB.open(ms);r.onupgradeneeded=()=>{r.transaction?.abort(),n(new Error("freqhole_app unexpectedly absent during write"))},r.onsuccess=()=>{const i=r.result,o=i.transaction(Do,"readwrite").objectStore(Do).put(e,hy);o.onsuccess=()=>{i.close(),t()},o.onerror=()=>{i.close(),n(o.error)}},r.onerror=()=>n(r.error)})}async function If(e){if(await gy()&&await py()){const n=await A9();if(n)return n}return e.get()}async function Cf(e,t){if(await gy()&&await py()){await I9(e);return}await t.set(e)}const hd="freqhole-iroh-node";function my(e){const{onAcquired:t,onStateChange:n}=e;if(typeof navigator>"u"||!navigator.locks)return n?.("unsupported"),Promise.resolve().then(()=>t()),()=>{};let r=!1,i=null;const s=new AbortController;function o(){r=!0,s.abort(),i?.()}return navigator.locks.request(hd,{ifAvailable:!0},async a=>{if(!r)if(a!==null)n?.("leader"),await t(),await new Promise(c=>{i=c});else{n?.("waiting");try{await navigator.locks.request(hd,{signal:s.signal},async()=>{r||(n?.("leader"),await t(),await new Promise(c=>{i=c}))})}catch{}}}),o}const _y=Object.freeze(Object.defineProperty({__proto__:null,BLOB_DB_NAME:uy,LOCK_NAME:hd,acquireNodeLeadership:my,clearBlobUrlCache:dy,deleteBlob:fy,getBlob:Yc,getBlobMetadata:Ur,getBlobObjectURL:Cs,persistIdentity:Cf,resolveIdentity:If,storeBlob:fi},Symbol.toStringTag,{value:"Module"})),C9="freqhole-playlistz-settings",wa="settings",z0="p2p_identity";function z9(){let e=null;async function t(){return e||(e=await Xp(C9,1,{upgrade(n){n.objectStoreNames.contains(wa)||n.createObjectStore(wa)}})),e}return{async get(){return await (await t()).get(wa,z0)??null},async set(n){await (await t()).put(wa,n,z0)}}}let nu=null;function bc(){return nu||(nu=z9()),nu}let Ei=null,Ri=null,ni=!1,fo=!1,gd=null,Na="unknown";const wc=new Set;function O0(e){for(const t of wc)t(e);wc.clear()}const pd=new Set,md=new Set;function P0(){for(const e of pd)try{e(Ei)}catch{}}function _d(){for(const e of md)try{e(ni)}catch{}}async function O9(){const e=await If(bc());if(e)return e;const t=new Uint8Array(32);crypto.getRandomValues(t);const n={id:"p2p_identity",secret_key:t,node_id:"",created_at:Date.now()};return await Cf(n,bc()),n}async function P9(e){try{return await (await Xr(()=>import("./midden-DceCrT_L.js").then(async m=>{await m.__tla;return m}),[])).MiddenNode.create_with_alpns(e,[ay,Kc])}catch(t){return console.warn("[p2p] midden boot failed - p2p unavailable:",t),null}}async function T9(){if(fo)return;fo=!0;try{Ei=await O9(),P0()}catch(t){console.warn("[p2p] identity resolution failed:",t),fo=!1;return}const e=Ei;gd=my({onAcquired:async()=>{ni=!0,Na="leader",_d();const t=await P9(e.secret_key);if(t){Ri=t;const n=t.node_id();if(n!==e.node_id){Ei={...e,node_id:n};try{await Cf(Ei,bc())}catch{}}P0()}O0(t)},onStateChange:t=>{t==="waiting"?(Na="waiting",O0(null)):t==="unsupported"&&(Na="unsupported"),t!=="leader"&&ni&&(ni=!1,_d())}})}function D9(){fo=!1,gd?.(),gd=null,Ri=null,ni&&(ni=!1,_d())}function yy(){return Ri}function R9(e=3e4){return Ri?Promise.resolve(Ri):!fo||Na==="waiting"?Promise.resolve(null):new Promise(t=>{const n=setTimeout(()=>{wc.delete(r),t(null)},e),r=i=>{clearTimeout(n),t(i)};wc.add(r)})}function _n(){return Ei}async function by(){try{return await If(bc())!==null}catch{return!1}}function T0(){return ni}function wy(e){return md.add(e),e(ni),()=>{md.delete(e)}}function zf(e){return pd.add(e),()=>{pd.delete(e)}}function F9(){return{getNode:async()=>{if(!Ri)throw new Error("p2p: midden node is not available (not leader or not started)");return Ri},getIdentity:async()=>Ei,onIdentityChange:e=>zf(e),syncAlpn:ay}}const Ro=new Map;function D0(e,t){const n=un(t);Ro.set(e,{peers:new Set(Object.keys(n.peers)),acl:new Set(Object.keys(n.acl??{}))})}async function B9(e,t){if(!t)return!1;const n=Ro.get(t);return n?n.peers.has(e)||n.acl.has(e):!1}let ru=null,yd=null;function U9(){Fe.trace("automerge.repo","buildRepo: constructing");const e=new S3("freqhole-automerge"),t=new $3,n=new eE(F9());return yd=n,new Ax({storage:e,network:[t,n],sharePolicy:B9})}function Jo(){return ru||(ru=U9()),ru}function wr(){return yd||Jo(),yd}const R0=new Set;function vy(e,t){let n;try{n=e.doc()}catch{n=void 0}n!==void 0&&D0(t,n),R0.has(t)||(R0.add(t),e.on("change",({doc:r})=>{Fe.trace("automerge.repo","doc change event",t),D0(t,r)}))}function Of(e){const t=Jo(),n=Jc(e),r=t.create(n);Fe.trace("automerge.repo","createPlaylistDoc:",r.url);const{documentId:i}=nr(r.url);return vy(r,i),{docId:r.url,handle:r}}function xy(e,t){const{documentId:n}=nr(e),r=Ro.get(n)??{peers:new Set,acl:new Set};r.peers.add(t),Ro.set(n,r)}const bd=new Map;let F0=0;async function lt(e){const t=bd.get(e);if(t)return t;F0++,Fe.trace("automerge.repo","findPlaylistDoc call #",String(F0),e);const n=(async()=>{const i=await Jo().find(e);Fe.trace("automerge.repo","findPlaylistDoc resolved",e);const{documentId:s}=nr(i.url);return vy(i,s),i})();return bd.set(e,n),n}async function j9(e){bd.delete(e);const t=Jo();(await t.find(e)).change(i=>Lz(i));const{documentId:r}=nr(e);Ro.delete(r),t.delete(e)}async function dn(e){const t=Jo(),{documentId:n}=nr(e);await t.flush([n])}const[Sy,M9]=Q(0),Fo=new Map,_s=new Map;function L9(e){M9(t=>t+1),e&&Fo.set(e,Date.now())}function N9(){return Sy()}function B0(e){_s.has(e)||_s.set(e,Q(0));const[t]=_s.get(e);return t}function Ko(e){if(_s.has(e)){const[,t]=_s.get(e);t(n=>n+1)}Fo.set(e,Date.now())}function H9(){Fo.clear(),_s.clear()}function Z9(){return{totalUpdates:Sy(),trackedSongs:Fo.size,recentUpdates:Array.from(Fo.entries()).sort(([,e],[,t])=>t-e).slice(0,10)}}typeof globalThis<"u"&&globalThis.__DEV__&&(globalThis.__songReactivity={getSongUpdateTrigger:N9,getUpdateStats:Z9,clearUpdateHistory:H9,triggerSongUpdate:L9});function Pf(){return yy()}const Ha=new Map,V9=600*1e3;let wd=0;function W9(e,t){const n=Ha.get(e);n&&clearTimeout(n.releaseTimer);const r=setTimeout(()=>{Ha.delete(e);try{Pf()?.release_blob(t)}catch{}},V9);Ha.set(e,{blake3:t,releaseTimer:r})}async function q9(e,t){wd++,xc();try{await J9(e,t)}finally{wd--,xc()}}async function J9(e,t){const n=Pf();if(!n){await jt(e,{v:1,type:"error",code:"no_node",message:"p2p node is not running"});return}const r=await Yc(t);if(!r){await jt(e,{v:1,type:"error",code:"blob_not_found",message:`no blob with sha256 ${t}`});return}let i=Ha.get(t)?.blake3;if(!i){const s=new Uint8Array(await r.arrayBuffer());i=await n.import_blob(s)}W9(t,i),await jt(e,{v:1,type:"blob_ready",sha256:t,blake3:i,size:r.size})}const[K9,Tf]=Q(new Map,{equals:!1}),$y=K9;function vd(e,t){Tf(n=>{const r=new Map(n);return t===null?r.delete(e):r.set(e,t),r})}const G9=2,vc=new Map,xd=new Map;function Y9(e){const t=vc.get(e)??0;return t<G9?(vc.set(e,t+1),Promise.resolve()):new Promise(n=>{let r=xd.get(e);r||(r=[],xd.set(e,r)),r.push(n)})}function X9(e){const t=xd.get(e);if(t&&t.length>0){t.shift()();return}const n=vc.get(e)??1;vc.set(e,Math.max(0,n-1))}const Za=new Map;let Q9=3e4;const Sd=new Set;function xc(){for(const e of Sd)try{e()}catch{}}function eO(e){return Sd.add(e),()=>Sd.delete(e)}function tO(){return Za.size+wd}async function nO(e){return e?await Ur(e)!==null:!1}async function rO(e,t,n,r){const i=Pf();if(!i)return null;let s,o;await Y9(e);const a=await i.open_bi(e,Kc);try{await jt(a,{v:1,type:"blob_request",sha256:t});const u=await di(a);if(u?.type!=="blob_ready")return null;s=u.blake3,o=u.size}finally{a.close(),X9(e)}const c=[];await i.download_verified_streaming(e,s,o,u=>{c.push(u.slice())},u=>{r?.({sha256:t,fraction:u})});const l=new Blob(c,{type:n}),f=await fi(l,n);return f!==t&&console.warn("[blobs] stored blob hash mismatch: expected",t,"got",f),f}async function Xc(e,t,n,r){if(await Ur(t))return t;const i=Za.get(t);if(i)return i;const s=(async()=>{const c=_n()?.node_id??"";let l=[];try{const h=(await lt(e)).doc();l=Object.keys(h?.peers??{}).filter(d=>d&&d!==c)}catch{return null}if(l.length===0)return null;const f=wr();l.sort((u,h)=>{const d=f.isConnected(u)?0:1,g=f.isConnected(h)?0:1;return d-g});for(const u of l)for(let h=0;h<2;h++)try{const d=await rO(u,t,n,r);if(d)return d;break}catch(d){h===0?await new Promise(g=>setTimeout(g,500)):console.warn("[blobs] fetch from peer failed (giving up):",u.slice(0,16),d)}return null})(),o=new Promise((c,l)=>{const f=setTimeout(()=>l(new Error("blob fetch timeout")),Q9);s.finally(()=>clearTimeout(f))}),a=Promise.race([s,o]);Za.set(t,a),vd(t,"downloading"),xc();try{return await a}catch{return vd(t,"error"),null}finally{Za.delete(t),Tf(c=>{if(c.get(t)==="downloading"){const l=new Map(c);return l.delete(t),l}return c}),xc()}}async function Df(e,t){const n=e.sha??e.sha256;return!n||!e.playlistId?null:Xc(e.playlistId,n,e.mimeType||"audio/mpeg",t)}const iO=1800,U0=3;let iu=0;function ky(e,t,n=0){const r=++iu;(async()=>{const i=await Hi(e.id).catch(()=>[]),s=i.findIndex(f=>f.id===t);if(s===-1)return;let o=iO-n;const a=[],c=[],l=()=>{for(const f of c)Tf(u=>{if(u.get(f)==="pending"){const h=new Map(u);return h.delete(f),h}return u})};for(let f=s+1;f<i.length&&o>0;f++){if(r!==iu){l();return}const u=i[f];o-=u.duration||0;const h=u.sha??u.sha256;h&&(await Ur(h)||(vd(h,"pending"),c.push(h),a.push(u)))}for(let f=0;f<a.length;f+=U0){if(r!==iu){l();return}const u=a.slice(f,f+U0);await Promise.allSettled(u.map(h=>Df(h)))}l()})()}async function sO(e,t){const n=e.id,r=await Ey(e);let i=0;for(let s=0;s<r.length;s++){const o=r[s];t?.({done:s,total:r.length,currentTitle:o.title,fraction:r.length===0?1:s/r.length}),await Xc(n,o.sha,o.mime,c=>{t?.({done:s,total:r.length,currentTitle:o.title,fraction:(s+c.fraction)/r.length})})&&i++}return t?.({done:r.length,total:r.length,currentTitle:"",fraction:1}),i}async function j0(e){return(await Ey(e)).length>0}async function Ey(e){const t=e.id,n=[],r=[],i=[],s=await Hi(t).catch(()=>[]);for(const l of s){const f=l.sha??l.sha256;f&&r.push({sha:f,mime:l.mimeType||"audio/mpeg",title:l.title});for(const u of l.images??[])u.blobId&&i.push({sha:u.blobId,mime:"image/jpeg",title:`${l.title} (image)`})}try{const f=(await lt(t)).doc();for(const u of f?.images??[])u.blobId&&n.push({sha:u.blobId,mime:"image/jpeg",title:"playlist cover"})}catch{}const o=[...n,...i,...r],a=new Set,c=[];for(const l of o)a.has(l.sha)||(a.add(l.sha),await Ur(l.sha)||c.push(l));return c}const ri=new Map;function Bs(e,t){for(let n=0;n<t.order.length;n++){const r=t.order[n],i=t.songs[r];i&&ri.set(r,{docId:e,entry:i,index:n})}for(const[n,r]of ri.entries())r.docId===e&&!t.songs[n]&&ri.delete(n)}function oO(e){return{"audio/mpeg":"mp3","audio/mp3":"mp3","audio/wav":"wav","audio/wave":"wav","audio/x-wav":"wav","audio/ogg":"ogg","audio/flac":"flac","audio/x-flac":"flac","audio/aac":"aac","audio/mp4":"m4a","audio/x-m4a":"m4a"}[e]??"bin"}function Rf(e){return e==null?e:JSON.parse(JSON.stringify(e))}function Go(e,t){return{id:e,title:t.title||"untitled playlist",description:t.description||void 0,createdAt:t.createdAt?new Date(t.createdAt).getTime():Date.now(),updatedAt:t.lastModified?new Date(t.lastModified).getTime():Date.now(),songIds:[...t.order],imageData:void 0,thumbnailData:void 0,imageType:void 0,_primaryImageSha:(t.images.find(n=>n.isPrimary)??t.images[0])?.blobId,bgFilterEnabled:t.bgFilterEnabled,bgFilterBlur:t.bgFilterBlur,bgFilterContrast:t.bgFilterContrast,bgFilterBrightness:t.bgFilterBrightness,coverFilterEnabled:t.coverFilterEnabled,coverFilterBlur:t.coverFilterBlur,bgSize:t.bgSize,bgPosition:t.bgPosition,bgRepeat:t.bgRepeat}}function Sc(e,t,n){return{id:e.id,title:e.title,artist:e.artist,album:e.album,duration:e.duration,mimeType:e.mimeType,fileSize:e.fileSize,originalFilename:`${e.title}.${oO(e.mimeType)}`,position:n,playlistId:t,sha:e.sha256,sha256:e.sha256,createdAt:Date.now(),updatedAt:Date.now(),imageData:void 0,thumbnailData:void 0,imageType:void 0,images:e.images}}async function Ff(e){const t=e.images?.find(n=>n.isPrimary)??e.images?.[0];if(!t)return e;try{const n=await Cs(t.blobId);if(!n)return e.playlistId&&Xc(e.playlistId,t.blobId,t.blobType??"image/jpeg").then(i=>{i&&Ko(e.id)}).catch(()=>{}),e;const r=await Ur(t.blobId);e.imageFilePath=n,e.imageType=r?.mime_type??"image/jpeg"}catch{}return e}async function M0(e,t){const n=Go(e,t);if(n._primaryImageSha)try{const r=await Cs(n._primaryImageSha);if(r){n.imageFilePath=r;const i=await Ur(n._primaryImageSha);n.imageType=i?.mime_type??"image/jpeg"}else Xc(e,n._primaryImageSha,"image/jpeg").catch(()=>{})}catch{}return n}async function Hi(e){const t=await lt(e);return Ay(e,t)}async function Ay(e,t){const n=t.doc();if(!n)return Fe.warn("playlist.doc","getSongsFromHandle: handle.doc() returned null"),[];const r=un(n);Fe.trace("playlist.doc","getSongsFromHandle order=",String(r.order.length),"songs=",String(Object.keys(r.songs).length)),Bs(e,r);const i=r.order.map((s,o)=>{const a=r.songs[s];return a?Sc(a,e,o):null}).filter(s=>s!==null);return Promise.all(i.map(Ff))}let va=null;async function aO(e){let t=ri.get(e);return t||(va||(va=(async()=>{const n=await Br();for(const r of n)try{const s=(await lt(r.docId)).doc();if(!s)continue;Bs(r.docId,un(s))}catch{continue}})().finally(()=>{va=null})),await va,t=ri.get(e)),t?Ff(Sc(t.entry,t.docId,t.index)):null}async function $d(e){Fe.trace("playlist.doc","createPlaylist",e.title??"(untitled)");const{docId:t,handle:n}=Of(Jc({title:e.title??"new playlist",description:e.description??""})),r={docId:t,title:e.title??"new playlist",addedAt:Date.now(),source:"local"};await or(r);const i=n.doc(),s=un(i??{});return await dn(t),Go(t,s)}async function Bf(e,t){Fe.trace("playlist.doc","updatePlaylist",e);const n=await lt(e),{rev:r,...i}=Rf(t);if(n.change(s=>ry(s,i)),await dn(e),t.title!==void 0){Fe.trace("playlist.doc","updatePlaylist: title changed, updating docIndex");const s=await Oi(e);s&&await or({...s,title:t.title})}}async function cO(e){const t=await Br(),n=new Set;return await Promise.allSettled(t.filter(r=>r.docId!==e).map(async r=>{try{const s=(await lt(r.docId)).doc();if(!s)return;const o=un(s);for(const a of Object.values(o.songs)){a?.sha256&&n.add(a.sha256);for(const c of a?.images??[])n.add(c.blobId)}for(const a of o.images??[])n.add(a.blobId)}catch{}})),n}async function Iy(e){let t=[];try{const r=(await lt(e)).doc();if(r){const i=un(r);for(const s of Object.values(i.songs)){s?.sha256&&t.push(s.sha256);for(const o of s?.images??[])t.push(o.blobId)}for(const s of i.images??[])t.push(s.blobId)}}catch{}await j9(e),await Mw(e);for(const[n,r]of ri.entries())r.docId===e&&ri.delete(n);if(t.length>0){const n=await cO(e);await Promise.allSettled(t.filter(r=>!n.has(r)).map(r=>fy(r)))}}async function Cy(e){const n=(await lt(e)).doc(),r=un(n??{}),i=Object.fromEntries(Object.entries({title:r.title,description:r.description,images:r.images,urls:r.urls,songs:r.songs,order:r.order,bgFilterEnabled:r.bgFilterEnabled,bgFilterBlur:r.bgFilterBlur,bgFilterContrast:r.bgFilterContrast,bgFilterBrightness:r.bgFilterBrightness,coverFilterEnabled:r.coverFilterEnabled,coverFilterBlur:r.coverFilterBlur,bgSize:r.bgSize,bgPosition:r.bgPosition,bgRepeat:r.bgRepeat}).filter(([,f])=>f!==void 0)),s=Jc(i),{docId:o,handle:a}=Of(s);await or({docId:o,title:r.title||"forked playlist",addedAt:Date.now(),source:"local"});const c=await Oi(e);c&&await or({...c,isForked:!0});const l=un(a.doc()??{});return await dn(o),Bs(o,l),Go(o,l)}async function kd(e,t,n={}){const r=crypto.randomUUID(),i=new Blob([await t.arrayBuffer()],{type:t.type}),s=await fi(i,t.type),o=[];if(n.imageData&&n.imageType){const m=new Blob([n.imageData],{type:n.imageType}),b=await fi(m,n.imageType);o.push({blobId:b,isPrimary:!0,blobType:"original"})}const a={id:r,title:n.title||t.name.replace(/\.[^/.]+$/,"")||"untitled",artist:n.artist||"unknown artist",album:n.album||"unknown album",duration:n.duration||0,mimeType:t.type||"audio/mpeg",fileSize:t.size,sha256:s,images:o,urls:[]},c=await lt(e),l=c.doc(),f=un(l??{}),u=Object.keys(f.songs).find(m=>f.songs[m]?.sha256===s);if(u){Fe.debug("playlist.doc","addSongToPlaylist: dedup, sha already in doc",s);const m=f.order.indexOf(u);return Ff(Sc(f.songs[u],e,m>=0?m:0))}c.change(m=>kf(m,Rf(a))),await dn(e);const h=c.doc(),d=un(h??{});Bs(e,d);const g=d.order.indexOf(r),p=Sc(a,e,g>=0?g:d.order.length-1);return Ko(r),p}async function lO(e,t,n){Fe.trace("playlist.doc","updateSongInDoc",e,t);const r=await lt(e);let i;if(n.imageData&&n.imageType){const u=new Blob([n.imageData],{type:n.imageType});i={blobId:await fi(u,n.imageType),isPrimary:!0,blobType:"original"}}const s=n.title,o=n.artist,a=n.album,c=n.duration;r.change(u=>{const h=u.songs[t];h&&(s!==void 0&&(h.title=s),o!==void 0&&(h.artist=o),a!==void 0&&(h.album=a),c!==void 0&&(h.duration=c),i&&(h.images.splice(0,h.images.length),h.images.push(Rf(i))))}),await dn(e);const l=r.doc(),f=un(l??{});Bs(e,f),Ko(t)}async function uO(e,t){(await lt(e)).change(r=>jz(r,t)),await dn(e),ri.delete(t),Ko(t)}async function dO(e,t,n){const r=await lt(e);r.change(o=>{const a=o.order[t];a!==void 0&&Mz(o,a,n)}),await dn(e);const i=r.doc(),s=un(i??{});Bs(e,s)}async function zy(e,t,n){const r=new Blob([t],{type:n}),i=await fi(r,n);(await lt(e)).change(o=>{iy(o,{blobId:i,isPrimary:!0,blobType:"original"})}),await dn(e)}async function fO(e){(await lt(e)).change(n=>{n.images.splice(0,n.images.length)}),await dn(e)}async function hO(e,t,n,r){const i=new Blob([n],{type:r}),s=await fi(i,r);(await lt(e)).change(a=>{iy(a,{blobId:s,isPrimary:!0,blobType:"original"},{songId:t})}),await dn(e),Ko(t)}async function gO(e,t,n){try{const r=t,i=Oy(e,t,n);return{blobUrl:r,downloadPromise:i}}catch(r){throw console.error("error in streamaudiowithcaching:",r),r}}async function Oy(e,t,n){try{if(e.sha??e.sha256)try{const{getBlobMetadata:u}=await Xr(async()=>{const{getBlobMetadata:d}=await Promise.resolve().then(()=>_y);return{getBlobMetadata:d}},void 0);if(await u(e.sha??e.sha256))return!0}catch(u){console.error("error checking blob store cache status:",u)}const r=await fetch(t);if(!r.ok)throw new Error(`failed to fetch: ${r.status} ${r.statusText}`);const i=r.headers.get("content-length"),s=i?parseInt(i,10):0;let o=0;const a=r.body?.getReader();if(!a)throw new Error("response body is not readable");const c=[];for(;;){const{done:u,value:h}=await a.read();if(u)break;h&&(o+=h.length,c.push(h),n&&s>0&&n({loaded:o,total:s,percentage:Math.round(o/s*100)}))}const l=e.mimeType||r.headers.get("content-type")||"audio/mpeg",f=new Blob(c,{type:l});return await fi(f,l),!0}catch(r){return console.error(`error downloading and caching audio for ${e.id}:`,r),!1}}const Va=new Map;function pO(e){return Va.has(e)}async function Py(e,t,n){const r=Va.get(e.id);if(r)return r;if(e.sha??e.sha256)try{const{getBlobMetadata:s}=await Xr(async()=>{const{getBlobMetadata:a}=await Promise.resolve().then(()=>_y);return{getBlobMetadata:a}},void 0);if(await s(e.sha??e.sha256))return!0}catch(s){console.error("error checking blob store cache status:",s)}const i=Oy(e,t,n);return Va.set(e.id,i),i.finally(()=>{Va.delete(e.id)}),i}const[zj,vi]=Q(null),Qc=new Map,Uf=new Map,jf=new Map,[mO,Wa]=Q(null);function Bo(e){const t=e.split(".").pop()?.toLowerCase();return t?{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",avif:"image/avif"}[t]:void 0}function Mf(e){return e.map(t=>{const n=Uf.get(t.id);return{...t,standaloneFilePath:t.standaloneFilePath??Qc.get(t.id),imageFilePath:t.imageFilePath??n?.imageFilePath,imageType:t.imageType??n?.imageType}})}function L0(e){const t=jf.get(e.id);return t?{...e,imageFilePath:e.imageFilePath??t.imageFilePath,imageType:e.imageType??t.imageType}:e}function Ty(e){return e.filePath??`data/${e.safeFilename??e.originalFilename}`}async function _O(e){const{docId:t,handle:n}=Of(Jc({title:e.playlist.title,description:e.playlist.description??""}));return n.change(r=>{for(const i of e.songs){const s={id:i.id,title:i.title,artist:i.artist,album:i.album,duration:i.duration,mimeType:i.mimeType??"audio/mpeg",fileSize:i.fileSize,sha256:i.sha??"",images:[],urls:[]};kf(r,s)}}),await or({docId:t,title:e.playlist.title,addedAt:Date.now(),source:"local"}),t}async function yO(e,t){(await lt(e)).change(r=>{ry(r,{title:t.playlist.title,description:t.playlist.description??""});for(const i of t.songs){const s={id:i.id,title:i.title,artist:i.artist,album:i.album,duration:i.duration,mimeType:i.mimeType??"audio/mpeg",fileSize:i.fileSize,sha256:i.sha??"",images:[],urls:[]};kf(r,s)}})}function bO(e,t){return e.songs.map((n,r)=>{const i=Ty(n);Qc.set(n.id,i);const s=n.imageFilePath??(n.imageExtension?`data/${(n.safeFilename??n.originalFilename).replace(/\.[^.]+$/,"")}-cover${n.imageExtension}`:void 0);if(s){const a=n.imageMimeType??Bo(s);Uf.set(n.id,{imageFilePath:s,imageType:a})}return{id:n.id,title:n.title,artist:n.artist,album:n.album,duration:n.duration,mimeType:n.mimeType??"audio/mpeg",fileSize:n.fileSize,originalFilename:n.originalFilename,position:r,createdAt:0,updatedAt:0,playlistId:t,sha:n.sha,sha256:n.sha,standaloneFilePath:i,needsImageLoad:!!s,imageFilePath:s,imageType:n.imageMimeType??(s?Bo(s):void 0),images:[]}})}function su(e,t){const n=e.playlist.imageFilePath??(e.playlist.imageExtension?`data/playlist-cover${e.playlist.imageExtension}`:void 0),r=e.playlist.imageMimeType??(n?Bo(n):void 0);jf.set(t,{imageFilePath:n,imageType:r})}function wO(e,t){const n=e.playlist.imageFilePath??(e.playlist.imageExtension?`data/playlist-cover${e.playlist.imageExtension}`:void 0);return jf.set(t,{imageFilePath:n,imageType:e.playlist.imageMimeType??(n?Bo(n):void 0)}),{id:t,title:e.playlist.title,description:e.playlist.description,createdAt:Date.now(),updatedAt:Date.now(),songIds:e.songs.map(r=>r.id),rev:e.playlist.rev,needsImageLoad:!!n,imageFilePath:n,imageType:e.playlist.imageMimeType??(n?Bo(n):void 0),bgFilterEnabled:e.playlist.bgFilterEnabled,bgFilterBlur:e.playlist.bgFilterBlur,bgFilterContrast:e.playlist.bgFilterContrast,bgFilterBrightness:e.playlist.bgFilterBrightness,coverFilterEnabled:e.playlist.coverFilterEnabled,coverFilterBlur:e.playlist.coverFilterBlur}}async function vO(e,t,n,r,i){if(window.location.protocol!=="file:")try{let s=!1;if(n.imageFilePath)try{const o=await fetch(n.imageFilePath);if(o.ok){const a=await o.arrayBuffer(),c=n.imageType??"image/jpeg";await zy(t,a,c),s=!0}}catch(o){console.warn(`could not load playlist cover from ${n.imageFilePath}:`,o)}for(const o of r)if(o.imageFilePath)try{const a=await fetch(o.imageFilePath);if(a.ok){const c=await a.arrayBuffer(),l=o.imageType??"image/jpeg";await hO(t,o.id,c,l),s=!0}}catch(a){console.warn(`could not load song image from ${o.imageFilePath}:`,a)}if(s){const a=(await Hi(t)).map(u=>({...u,standaloneFilePath:Qc.get(u.id)}));i.setPlaylistSongs(a);const l=(await lt(t)).doc(),f=un(l??{});i.setSelectedPlaylist(Go(t,f))}}catch(s){console.warn("error loading standalone images:",s)}}async function xO(e,t){try{if(!e?.playlist||!e?.songs){console.error("error initializing standalone playlist: invalid playlist data"),t.setError("invalid playlist data provided");return}if(!t.setError||typeof t.setError!="function")throw new Error("callbacks.setError is not a function");if(!t.setPlaylistSongs||typeof t.setPlaylistSongs!="function")throw new Error("callbacks.setPlaylistSongs is not a function");for(const c of e.songs){Qc.set(c.id,Ty(c));const l=c.imageFilePath??(c.imageExtension?`data/${(c.safeFilename??c.originalFilename).replace(/\.[^.]+$/,"")}-cover${c.imageExtension}`:void 0);l&&Uf.set(c.id,{imageFilePath:l,imageType:c.imageMimeType})}vi({current:0,total:e.songs.length,currentSong:"initializing...",phase:"initializing"});const n=`standalone:${e.playlist.id}`,r=await Dc(n),i=e.playlist.rev??0;let s;r?i>r.rev?(vi({current:0,total:e.songs.length,currentSong:"updating playlist revision...",phase:"reloading"}),s=r.docId,su(e,s),Wa(s),await yO(s,e),await _o(n,{rev:i,docId:s})):(s=r.docId,su(e,s),Wa(s),vi({current:0,total:e.songs.length,currentSong:"loading playlist...",phase:"checking"})):(vi({current:0,total:e.songs.length,currentSong:"creating playlist...",phase:"initializing"}),s=await _O(e),su(e,s),Wa(s),await _o(n,{rev:i,docId:s})),await Hi(s);const o=bO(e,s),a=wO(e,s);t.setSelectedPlaylist(a),t.setPlaylistSongs(o),setTimeout(()=>vi(null),500),setTimeout(()=>vO(e,s,a,o,t),1e3)}catch(n){console.error("error initializing standalone playlist:",n),t.setError("failed to load standalone playlist"),vi(null)}}function SO(){vi(null)}async function $O(e,t){for(const n of e)await xO(n,t)}const[ii,Dy]=Q(null),[zs,Lf]=Q(null),[qn,Ry]=Q([]),[el,Cr]=Q(!1),[kO,$c]=Q(0),[EO,Nf]=Q(0),[Us,Dr]=Q(-1),[Fy,Oj]=Q(1),[Hf,fs]=Q(!1),[By,zr]=Q(new Set),[Uy,Yo]=Q(null),[Zf,ro]=Q(null);let ou=!1;const[tl,Pj]=Q("none"),[AO,Tj]=Q(!1),[jy,qr]=Q(new Map),[My,Jr]=Q(new Set),[Vf,Uo]=Q(new Map);let hs=0,N0=!1,H0=!1;async function nl(){if(H0)return;H0=!0;const e=await Tw();e.size>0&&Uo(e)}nl().catch(()=>{});function Ed(){const e=ii(),t=ut?.currentTime??0;e&&t>1&&Ld(e.id,t).catch(()=>{})}let ut=null;function IO(){return ut||(ut=new Audio,ut.volume=Fy(),ut.preload="metadata",nl().catch(()=>{}),window.addEventListener("beforeunload",Ed),ut.addEventListener("loadstart",()=>{fs(!0)}),ut.addEventListener("canplay",()=>{fs(!1)}),ut.addEventListener("loadedmetadata",()=>{const e=ut?.duration||0;Nf(e),fs(!1),hs>0&&ut&&(ut.currentTime=hs,$c(hs),hs=0),si()}),ut.addEventListener("timeupdate",()=>{const e=ut?.currentTime||0;$c(e);const t=ii();t&&e>0&&Uo(r=>{const i=new Map(r);return i.set(t.id,e),i});const n=ut?.duration||0;n>0&&e/n>=.5&&!ou&&(ou=!0,TO())}),ut.addEventListener("play",()=>{Cr(!0),ou=!1,Hf()||si()}),ut.addEventListener("pause",()=>{Cr(!1),Ed(),si()}),ut.addEventListener("ended",()=>{Cr(!1);const e=ii(),t=ut?.duration??0;e&&t>0&&(Uo(n=>{const r=new Map(n);return r.set(e.id,t),r}),Ld(e.id,t).catch(()=>{})),PO()}),ut.addEventListener("error",e=>{console.error("onoz! audio error:",e),Cr(!1),fs(!1),zr(new Set),rl()}),ut.addEventListener("seeked",()=>{const e=zs(),t=ii();if(!e||!t||!el())return;const n=ut?.currentTime??0,r=ut?.duration??t.duration??0,i=Math.max(0,r-n);ky(e,t.id,i)}),ut)}function CO(e){return URL.createObjectURL(e)}function Ly(e){URL.revokeObjectURL(e)}function rl(){const e=ii();e?document.title=`${e.title} - ${e.artist||"unknown artist"} | P L A Y L I S T Z`:document.title="P L A Y L I S T Z"}async function si(){if(!("mediaSession"in navigator))return;const e=ii(),t=zs(),n=Hf();if(e){const r=await zO(e,t||void 0);navigator.mediaSession.metadata=null,navigator.mediaSession.metadata=new MediaMetadata({title:n?`loading... ${e.title}`:e.title,artist:e.artist||"unknown artist",album:e.album||t?.title||"unknown album",artwork:r}),navigator.mediaSession.playbackState=n?"paused":el()?"playing":"paused",navigator.mediaSession.setActionHandler("play",()=>{jo()}),navigator.mediaSession.setActionHandler("pause",()=>{jo()}),navigator.mediaSession.setActionHandler("previoustrack",()=>{Vy()}),navigator.mediaSession.setActionHandler("nexttrack",()=>{Jf()}),navigator.mediaSession.setActionHandler("seekto",o=>{o.seekTime!==void 0&&!n&&Kf(o.seekTime)});const i=Ye.duration(),s=Ye.currentTime();if(i>0&&!n)navigator.mediaSession.setPositionState({duration:i,playbackRate:1,position:s});else if(n)try{navigator.mediaSession.setPositionState({duration:0,playbackRate:1,position:0})}catch{}}else navigator.mediaSession.metadata=null,navigator.mediaSession.playbackState="none";rl()}async function Z0(e,t){return e.byteLength<5e5?e:new Promise(n=>{const r=new Blob([e],{type:t}),i=new Image,s=document.createElement("canvas"),o=s.getContext("2d");i.onload=()=>{let{width:c,height:l}=i;if(c>300||l>300){const f=Math.min(300/c,300/l);c*=f,l*=f}s.width=c,s.height=l,o?(o.drawImage(i,0,0,c,l),s.toBlob(f=>{f?f.arrayBuffer().then(n):n(e)},t,.8)):n(e)},i.onerror=()=>{n(e)},i.src=URL.createObjectURL(r)})}async function zO(e,t){const n=[],r=e.thumbnailData||e.imageData;if(r&&e.imageType){const i=await Z0(r,e.imageType),s=new Blob([i],{type:e.imageType}),o=URL.createObjectURL(s);n.push({src:o,sizes:"512x512",type:e.imageType}),n.push({src:o,sizes:"256x256",type:e.imageType}),n.push({src:o,sizes:"96x96",type:e.imageType})}else{const i=t?.thumbnailData||t?.imageData;if(i&&t?.imageType){const s=await Z0(i,t.imageType),o=new Blob([s],{type:t.imageType}),a=URL.createObjectURL(o);n.push({src:a,sizes:"512x512",type:t.imageType}),n.push({src:a,sizes:"256x256",type:t.imageType}),n.push({src:a,sizes:"96x96",type:t.imageType})}}return n}async function Wf(e){try{const t=await Hi(e.id);Ry(Mf(t)),Lf(e)}catch(t){throw console.error("error loading playlist queue:",t),t}}async function Ny(e){try{const t=Ye.currentSong();if(await Wf(e),t){const r=qn().findIndex(i=>i.id===t.id);Dr(r>=0?r:-1)}}catch(t){throw console.error("Error refreshing playlist queue:",t),t}}function OO(){const e=qn(),t=Us();if(e.length===0)return null;const n=tl();if(n==="one")return t>=0&&e[t]||null;const r=t+1;return r<e.length?e[r]||null:n==="all"&&e[0]||null}async function Hy(){const e=qn(),t=Us(),n=tl();let r=t+1;const i=e.length;let s=0;for(;s<i;){if(r>=e.length)if(n==="all")r=0;else{Cr(!1),si();return}if(r===t){Cr(!1),si();return}const o=e[r];if(!o){r++,s++;continue}try{Dr(r),Yo(o.id),await Zi(o);return}catch(a){console.error(`onoz! failed to play song "${o.title}":`,a),r++,s++}}console.error("oopz! all remaining songs failed to load, stopping playback"),Cr(!1),si()}async function PO(){if(OO())try{await Jf()}catch(t){console.error("error during auto-advance:",t),await Hy()}else Cr(!1),si()}async function Zi(e,t=!1){const n=IO();try{await nl(),Ed(),Yo(e.id),zr(f=>new Set(Array.from(f).concat([e.id]))),Zf()===e.id&&ro(null),N0&&n.src&&n.src.startsWith("blob:")&&Ly(n.src),$c(0),Nf(0),n.currentTime=0;const r=t?0:Vf().get(e.id)??0,i=e.duration??0;if(r>0&&(i===0||r<i*.95)?hs=r:(hs=0,r>0&&Uo(f=>{const u=new Map(f);return u.delete(e.id),u})),fs(!0),Dy(e),await si(),"mediaSession"in navigator){navigator.mediaSession.playbackState="paused";try{navigator.mediaSession.setPositionState({duration:0,playbackRate:1,position:0})}catch{}}const o=qn().findIndex(f=>f.id===e.id);if(o>=0){Dr(o);const f=zs();f&&Rw(f.id,e.id)}else Lf(null),Ry([]),Dr(-1);let a=e.blobUrl,c=!1;if(!a&&e.file&&(a=CO(e.file),c=!0),!a)if(window.location.protocol==="file:"&&e.standaloneFilePath){const f=e.standaloneFilePath;a=new URL(f,window.location.href).href;const u=document.createElement("audio");u.src=a,u.addEventListener("error",h=>{console.error("audio file test failed:",h),console.error("audio error:",u.error)}),u.load()}else{let f=null;const u=e.sha??e.sha256;if(u&&(f=await Cs(u)),!f&&u&&e.playlistId&&!e.standaloneFilePath){Jr(h=>new Set(Array.from(h).concat([e.id])));try{await Df(e,d=>{qr(g=>{const p=new Map(g);return p.set(e.id,Math.round(d.fraction*100)),p})})&&(f=await Cs(u))}catch(h){console.warn("p2p audio fetch failed:",h)}finally{qr(h=>{const d=new Map(h);return d.delete(e.id),d}),Jr(h=>{const d=new Set(h);return d.delete(e.id),d})}}if(f)a=f;else if(e.standaloneFilePath){const h=e.standaloneFilePath;if(window.location.protocol==="file:")a=new URL(h,window.location.href).href;else try{const{blobUrl:d,downloadPromise:g}=await gO(e,h,p=>{qr(m=>{const b=new Map(m);return b.set(e.id,p.percentage),b})});Jr(p=>new Set(Array.from(p).concat([e.id]))),a=d,c=!0,g.then(p=>{p?console.debug(`successfully cached ${e.title}`):console.warn(`failed to cache ${e.title}`)}).catch(p=>{console.error(`error caching ${e.title}:`,p)}).finally(()=>{qr(p=>{const m=new Map(p);return m.delete(e.id),m}),Jr(p=>{const m=new Set(p);return m.delete(e.id),m})})}catch(d){console.error("streaming approach failed, using direct url:",d),a=h,Jr(g=>new Set(Array.from(g).concat([e.id]))),Py(e,h,g=>{qr(p=>{const m=new Map(p);return m.set(e.id,g.percentage),m})}).finally(()=>{qr(g=>{const p=new Map(g);return p.delete(e.id),p}),Jr(g=>{const p=new Set(g);return p.delete(e.id),p})})}}}if(!a)throw new Error(`no audio source available for song: ${e.title}. check that audio files are accessible.`);if(Uy()!==e.id){zr(f=>{const u=new Set(f);return u.delete(e.id),u});return}N0=c,n.src=a,n.addEventListener("error",f=>{console.error("audio loading error:",f),console.error("audio error details:",n.error)},{once:!0}),await n.play(),zr(f=>{const u=new Set(f);return u.delete(e.id),u});const l=zs();if(l){const f=ut?.currentTime??0,u=ut?.duration??e.duration??0,h=Math.max(0,u-f);ky(l,e.id,h)}}catch(r){throw console.error("error playing song:",r),fs(!1),zr(i=>{const s=new Set(i);return s.delete(e.id),s}),rl(),r}}async function Zy(e,t){const n=zs();(!n||n.id!==t.id||qn().length===0)&&await Wf(t);const i=qn().findIndex(s=>s.id===e.id);i>=0&&Dr(i),await Zi(e)}async function qf(e,t=0){await Wf(e);const n=qn();if(!n.length)return;await nl();const r=await Fw(e.id);if(r){const i=n.findIndex(s=>s.id===r);if(i>=0){const s=n[i],o=Vf().get(r)??0,a=s.duration??0;if(a>0&&o>=a*.95){const l=i+1<n.length?i+1:0;await au(l);return}else{await au(i);return}}}t>=n.length||t<0||await au(t)}async function au(e){const n=qn()[e];if(n)try{Dr(e),Yo(n.id),await Zi(n)}catch(r){console.error(`failed to play song "${n.title}":`,r),await Hy()}}async function Jf(){const e=qn(),t=Us();if(e.length===0)return;const n=tl();let r;if(n==="one")r=t;else if(t+1<e.length)r=t+1;else if(n==="all")r=0;else return;const i=e[r];if(i){Dr(r),Yo(i.id);try{await Zi(i,!0)}catch(s){throw console.error("error playing next song:",s),s}}}async function Vy(){const e=qn(),t=Us();if(e.length===0||t<=0)return;const n=t-1,r=e[n];r&&(Dr(n),Yo(r.id),await Zi(r))}async function jo(){const e=ut;if(e)try{el()?e.pause():await e.play()}catch(t){console.error("onoz! error toggling playback:",t)}}function Ad(){const e=ut;e&&(e.pause(),e.currentTime=0,e.src&&e.src.startsWith("blob:")&&Ly(e.src),e.src=""),Dy(null),Lf(null),Cr(!1),$c(0),Nf(0),Dr(0),rl()}function Kf(e){const t=ut;if(t&&!isNaN(t.duration)){const n=Math.max(0,Math.min(e,t.duration));t.currentTime=n;const r=ii();r&&Uo(i=>{const s=new Map(i);return n<1?(s.delete(r.id),Dw(r.id).catch(()=>{})):(s.set(r.id,n),Ld(r.id,n).catch(()=>{})),s})}}const Ye={currentSong:ii,currentPlaylist:zs,playlistQueue:qn,isPlaying:el,currentTime:kO,duration:EO,currentIndex:Us,volume:Fy,isLoading:Hf,loadingSongIds:By,selectedSongId:Uy,preloadingSongId:Zf,repeatMode:tl,isShuffled:AO,downloadProgress:jy,cachingSongIds:My,songPlaybackPositions:Vf};async function TO(){const e=qn(),t=Us();if(e.length===0||t<0)return;const n=t+1;if(n>=e.length)return;const r=e[n];if(r&&!(By().has(r.id)||Zf()===r.id)){ro(r.id),zr(i=>new Set(Array.from(i).concat([r.id])));try{if(r.sha??r.sha256?await Cs(r.sha??r.sha256):null){zr(s=>{const o=new Set(s);return o.delete(r.id),o}),ro(null);return}if(pO(r.id)){zr(s=>{const o=new Set(s);return o.delete(r.id),o}),ro(null);return}r.standaloneFilePath&&(Jr(s=>new Set(Array.from(s).concat([r.id]))),Py(r,r.standaloneFilePath,s=>{qr(o=>{const a=new Map(o);return a.set(r.id,s.percentage),a})}).then(s=>{s?console.debug(`successfully preloaded ${r.title}`):console.warn(`failed to preload ${r.title}`)}).catch(s=>{console.error(`error preloading ${r.title}:`,s)}).finally(()=>{qr(s=>{const o=new Map(s);return o.delete(r.id),o}),Jr(s=>{const o=new Set(s);return o.delete(r.id),o})}))}catch{}finally{zr(i=>{const s=new Set(i);return s.delete(r.id),s}),ro(null)}}}function Wy(e){return jy().get(e)||0}function qy(e){return My().has(e)}const V0=Object.freeze(Object.defineProperty({__proto__:null,audioState:Ye,getSongDownloadProgress:Wy,isSongCaching:qy,playNext:Jf,playPlaylist:qf,playPrevious:Vy,playSong:Zi,playSongFromPlaylist:Zy,refreshPlaylistQueue:Ny,seek:Kf,stop:Ad,togglePlayback:jo},Symbol.toStringTag,{value:"Module"}));async function DO(e){try{const t=await e.arrayBuffer(),n=new DataView(t);if(t.byteLength<10)return{success:!1,error:"File too small to contain ID3 tags"};if(String.fromCharCode(n.getUint8(0),n.getUint8(1),n.getUint8(2))!=="ID3")return{success:!1,error:"No ID3v2 tag found"};const i=n.getUint8(3),s=(n.getUint8(6)&127)<<21|(n.getUint8(7)&127)<<14|(n.getUint8(8)&127)<<7|n.getUint8(9)&127;let o=10;const a=Math.min(10+s,t.byteLength);for(;o<a-10;){if(String.fromCharCode(n.getUint8(o),n.getUint8(o+1),n.getUint8(o+2),n.getUint8(o+3))==="APIC"){const f=i===4?(n.getUint8(o+4)&127)<<21|(n.getUint8(o+5)&127)<<14|(n.getUint8(o+6)&127)<<7|n.getUint8(o+7)&127:n.getUint8(o+4)<<24|n.getUint8(o+5)<<16|n.getUint8(o+6)<<8|n.getUint8(o+7);let u=o+10;u++;let h="";for(;u<a&&n.getUint8(u)!==0;)h+=String.fromCharCode(n.getUint8(u)),u++;for(u++,u++;u<a&&n.getUint8(u)!==0;)u++;u++;const d=f-(u-o-10);if(d>0&&u+d<=t.byteLength){const g=t.slice(u,u+d),p=new Blob([g],{type:h});return{success:!0,albumArt:URL.createObjectURL(p)}}}const l=i===4?(n.getUint8(o+4)&127)<<21|(n.getUint8(o+5)&127)<<14|(n.getUint8(o+6)&127)<<7|n.getUint8(o+7)&127:n.getUint8(o+4)<<24|n.getUint8(o+5)<<16|n.getUint8(o+6)<<8|n.getUint8(o+7);o+=10+l}return{success:!1,error:"No album art found in ID3 tags"}}catch(t){return console.error("Error extracting album art:",t),{success:!1,error:t instanceof Error?t.message:"Unknown error"}}}async function Gf(e){try{if(!e.type.startsWith("image/"))return{success:!1,error:"File is not an image"};const t=10*1024*1024;if(e.size>t)return{success:!1,error:"Image file too large (max 10MB)"};const n=await e.arrayBuffer(),r=new Image,i=URL.createObjectURL(e);return new Promise(s=>{r.onload=async()=>{try{const o={width:r.width,height:r.height,format:e.type,size:e.size},a=await RO(r,300,300,e.type);URL.revokeObjectURL(i),s({success:!0,imageData:n,thumbnailData:a,metadata:o})}catch(o){URL.revokeObjectURL(i),s({success:!1,error:o instanceof Error?o.message:"Processing failed"})}},r.onerror=()=>{URL.revokeObjectURL(i),s({success:!1,error:"Invalid image file"})},r.src=i})}catch(t){return console.error("Error processing playlist cover:",t),{success:!1,error:t instanceof Error?t.message:"Unknown error"}}}async function RO(e,t,n,r="image/jpeg"){const i=document.createElement("canvas"),s=i.getContext("2d");if(!s)throw new Error("Cannot create canvas context");let{width:o,height:a}=e;if(o>t||a>n){const c=Math.min(t/o,n/a);o*=c,a*=c}return i.width=o,i.height=a,s.drawImage(e,0,0,o,a),new Promise((c,l)=>{i.toBlob(async f=>{if(f){const u=await f.arrayBuffer();c(u)}else l(new Error("Failed to create thumbnail data"))},r,.8)})}function Jy(e){return["image/jpeg","image/png","image/gif","image/webp"].includes(e.type)?e.size>0xa00000?{valid:!1,error:"Image file too large. Maximum size is 10MB."}:{valid:!0}:{valid:!1,error:"Unsupported image format. Use JPEG, PNG, GIF, or WebP."}}function ei(e,t="image/jpeg"){const n=new Blob([e],{type:t});return URL.createObjectURL(n)}function Vn(e,t="thumbnail"){if(!e?.imageType&&!e?.imageFilePath)return null;const{thumbnailData:n,imageData:r,imageType:i,imageFilePath:s}=e;if(t==="background"||t==="modal"){if(r)return ei(r,i??"image/jpeg");if(n)return ei(n,i??"image/jpeg")}return n?ei(n,i??"image/jpeg"):r?ei(r,i??"image/jpeg"):s||null}function FO(e){return e.type.startsWith("audio/")}function BO(e){const t=e.replace(/\.[^/.]+$/,""),n=t.split(" - ");return n.length===2?{artist:n[0]?.trim(),title:n[1]?.trim()}:n.length===3?{artist:n[0]?.trim(),album:n[1]?.trim(),title:n[2]?.trim()}:{title:t.trim()}}async function UO(e){return new Promise(t=>{try{const n=new Audio,r=URL.createObjectURL(e);n.addEventListener("loadedmetadata",()=>{URL.revokeObjectURL(r),t(n.duration||0)}),n.addEventListener("error",i=>{URL.revokeObjectURL(r),console.warn("could not extract duration from audio file:",i),t(0)}),n.src=r}catch(n){console.warn("failed to create blob URL for duration extraction:",n),t(0)}})}async function jO(e){try{const t=await DO(e);if(t.success&&t.albumArt){const r=await (await fetch(t.albumArt)).arrayBuffer(),i=new Blob([r],{type:"image/jpeg"}),s=new File([i],"albumart.jpg",{type:"image/jpeg"});URL.revokeObjectURL(t.albumArt);const o=await Gf(s);return o.success&&o.imageData&&o.thumbnailData?{fullSizeData:o.imageData,thumbnailData:o.thumbnailData,type:o.metadata?.format||"image/jpeg"}:{fullSizeData:r,thumbnailData:r,type:"image/jpeg"}}return}catch(t){console.warn(`o noz! could not extract album art from ${e.name}:`,t);return}}async function MO(e){const t=BO(e.name);try{const n=await UO(e),r=await jO(e);return{title:t.title||"unknown title",artist:t.artist||"unknown artist",album:t.album||"unknown album",duration:n,coverArtData:r?.fullSizeData,coverArtThumbnailData:r?.thumbnailData,coverArtType:r?.type}}catch(n){return console.error("Error extracting metadata:",n),{title:t.title||"unknown title",artist:t.artist||"unknown artist",album:t.album||"unknown album",duration:0}}}function qa(e){return Array.from(e).filter(FO)}function xa(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var cu={exports:{}};var W0;function LO(){return W0||(W0=1,(function(e,t){(function(n){e.exports=n()})(function(){return(function n(r,i,s){function o(l,f){if(!i[l]){if(!r[l]){var u=typeof xa=="function"&&xa;if(!f&&u)return u(l,!0);if(a)return a(l,!0);var h=new Error("Cannot find module '"+l+"'");throw h.code="MODULE_NOT_FOUND",h}var d=i[l]={exports:{}};r[l][0].call(d.exports,function(g){var p=r[l][1][g];return o(p||g)},d,d.exports,n,r,i,s)}return i[l].exports}for(var a=typeof xa=="function"&&xa,c=0;c<s.length;c++)o(s[c]);return o})({1:[function(n,r,i){var s=n("./utils"),o=n("./support"),a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";i.encode=function(c){for(var l,f,u,h,d,g,p,m=[],b=0,x=c.length,_=x,E=s.getTypeOf(c)!=="string";b<c.length;)_=x-b,u=E?(l=c[b++],f=b<x?c[b++]:0,b<x?c[b++]:0):(l=c.charCodeAt(b++),f=b<x?c.charCodeAt(b++):0,b<x?c.charCodeAt(b++):0),h=l>>2,d=(3&l)<<4|f>>4,g=1<_?(15&f)<<2|u>>6:64,p=2<_?63&u:64,m.push(a.charAt(h)+a.charAt(d)+a.charAt(g)+a.charAt(p));return m.join("")},i.decode=function(c){var l,f,u,h,d,g,p=0,m=0,b="data:";if(c.substr(0,b.length)===b)throw new Error("Invalid base64 input, it looks like a data url.");var x,_=3*(c=c.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(c.charAt(c.length-1)===a.charAt(64)&&_--,c.charAt(c.length-2)===a.charAt(64)&&_--,_%1!=0)throw new Error("Invalid base64 input, bad content length.");for(x=o.uint8array?new Uint8Array(0|_):new Array(0|_);p<c.length;)l=a.indexOf(c.charAt(p++))<<2|(h=a.indexOf(c.charAt(p++)))>>4,f=(15&h)<<4|(d=a.indexOf(c.charAt(p++)))>>2,u=(3&d)<<6|(g=a.indexOf(c.charAt(p++))),x[m++]=l,d!==64&&(x[m++]=f),g!==64&&(x[m++]=u);return x}},{"./support":30,"./utils":32}],2:[function(n,r,i){var s=n("./external"),o=n("./stream/DataWorker"),a=n("./stream/Crc32Probe"),c=n("./stream/DataLengthProbe");function l(f,u,h,d,g){this.compressedSize=f,this.uncompressedSize=u,this.crc32=h,this.compression=d,this.compressedContent=g}l.prototype={getContentWorker:function(){var f=new o(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new c("data_length")),u=this;return f.on("end",function(){if(this.streamInfo.data_length!==u.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),f},getCompressedWorker:function(){return new o(s.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},l.createWorkerFrom=function(f,u,h){return f.pipe(new a).pipe(new c("uncompressedSize")).pipe(u.compressWorker(h)).pipe(new c("compressedSize")).withStreamInfo("compression",u)},r.exports=l},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(n,r,i){var s=n("./stream/GenericWorker");i.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},i.DEFLATE=n("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(n,r,i){var s=n("./utils"),o=(function(){for(var a,c=[],l=0;l<256;l++){a=l;for(var f=0;f<8;f++)a=1&a?0xedb88320^a>>>1:a>>>1;c[l]=a}return c})();r.exports=function(a,c){return a!==void 0&&a.length?s.getTypeOf(a)!=="string"?(function(l,f,u,h){var d=o,g=h+u;l^=-1;for(var p=h;p<g;p++)l=l>>>8^d[255&(l^f[p])];return-1^l})(0|c,a,a.length,0):(function(l,f,u,h){var d=o,g=h+u;l^=-1;for(var p=h;p<g;p++)l=l>>>8^d[255&(l^f.charCodeAt(p))];return-1^l})(0|c,a,a.length,0):0}},{"./utils":32}],5:[function(n,r,i){i.base64=!1,i.binary=!1,i.dir=!1,i.createFolders=!0,i.date=null,i.compression=null,i.compressionOptions=null,i.comment=null,i.unixPermissions=null,i.dosPermissions=null},{}],6:[function(n,r,i){var s=null;s=typeof Promise<"u"?Promise:n("lie"),r.exports={Promise:s}},{lie:37}],7:[function(n,r,i){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",o=n("pako"),a=n("./utils"),c=n("./stream/GenericWorker"),l=s?"uint8array":"array";function f(u,h){c.call(this,"FlateWorker/"+u),this._pako=null,this._pakoAction=u,this._pakoOptions=h,this.meta={}}i.magic="\b\0",a.inherits(f,c),f.prototype.processChunk=function(u){this.meta=u.meta,this._pako===null&&this._createPako(),this._pako.push(a.transformTo(l,u.data),!1)},f.prototype.flush=function(){c.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},f.prototype.cleanUp=function(){c.prototype.cleanUp.call(this),this._pako=null},f.prototype._createPako=function(){this._pako=new o[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var u=this;this._pako.onData=function(h){u.push({data:h,meta:u.meta})}},i.compressWorker=function(u){return new f("Deflate",u)},i.uncompressWorker=function(){return new f("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(n,r,i){function s(d,g){var p,m="";for(p=0;p<g;p++)m+=String.fromCharCode(255&d),d>>>=8;return m}function o(d,g,p,m,b,x){var _,E,k=d.file,C=d.compression,T=x!==l.utf8encode,j=a.transformTo("string",x(k.name)),I=a.transformTo("string",l.utf8encode(k.name)),R=k.comment,N=a.transformTo("string",x(R)),D=a.transformTo("string",l.utf8encode(R)),y=I.length!==k.name.length,w=D.length!==R.length,$="",P="",A="",J=k.dir,S=k.date,U={crc32:0,compressedSize:0,uncompressedSize:0};g&&!p||(U.crc32=d.crc32,U.compressedSize=d.compressedSize,U.uncompressedSize=d.uncompressedSize);var O=0;g&&(O|=8),T||!y&&!w||(O|=2048);var F=0,X=0;J&&(F|=16),b==="UNIX"?(X=798,F|=(function(se,$e){var Ce=se;return se||(Ce=$e?16893:33204),(65535&Ce)<<16})(k.unixPermissions,J)):(X=20,F|=(function(se){return 63&(se||0)})(k.dosPermissions)),_=S.getUTCHours(),_<<=6,_|=S.getUTCMinutes(),_<<=5,_|=S.getUTCSeconds()/2,E=S.getUTCFullYear()-1980,E<<=4,E|=S.getUTCMonth()+1,E<<=5,E|=S.getUTCDate(),y&&(P=s(1,1)+s(f(j),4)+I,$+="up"+s(P.length,2)+P),w&&(A=s(1,1)+s(f(N),4)+D,$+="uc"+s(A.length,2)+A);var ie="";return ie+=`
|
|
45
|
+
\0`,ie+=s(O,2),ie+=C.magic,ie+=s(_,2),ie+=s(E,2),ie+=s(U.crc32,4),ie+=s(U.compressedSize,4),ie+=s(U.uncompressedSize,4),ie+=s(j.length,2),ie+=s($.length,2),{fileRecord:u.LOCAL_FILE_HEADER+ie+j+$,dirRecord:u.CENTRAL_FILE_HEADER+s(X,2)+ie+s(N.length,2)+"\0\0\0\0"+s(F,4)+s(m,4)+j+$+N}}var a=n("../utils"),c=n("../stream/GenericWorker"),l=n("../utf8"),f=n("../crc32"),u=n("../signature");function h(d,g,p,m){c.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=g,this.zipPlatform=p,this.encodeFileName=m,this.streamFiles=d,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}a.inherits(h,c),h.prototype.push=function(d){var g=d.meta.percent||0,p=this.entriesCount,m=this._sources.length;this.accumulate?this.contentBuffer.push(d):(this.bytesWritten+=d.data.length,c.prototype.push.call(this,{data:d.data,meta:{currentFile:this.currentFile,percent:p?(g+100*(p-m-1))/p:100}}))},h.prototype.openedSource=function(d){this.currentSourceOffset=this.bytesWritten,this.currentFile=d.file.name;var g=this.streamFiles&&!d.file.dir;if(g){var p=o(d,g,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:p.fileRecord,meta:{percent:0}})}else this.accumulate=!0},h.prototype.closedSource=function(d){this.accumulate=!1;var g=this.streamFiles&&!d.file.dir,p=o(d,g,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(p.dirRecord),g)this.push({data:(function(m){return u.DATA_DESCRIPTOR+s(m.crc32,4)+s(m.compressedSize,4)+s(m.uncompressedSize,4)})(d),meta:{percent:100}});else for(this.push({data:p.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},h.prototype.flush=function(){for(var d=this.bytesWritten,g=0;g<this.dirRecords.length;g++)this.push({data:this.dirRecords[g],meta:{percent:100}});var p=this.bytesWritten-d,m=(function(b,x,_,E,k){var C=a.transformTo("string",k(E));return u.CENTRAL_DIRECTORY_END+"\0\0\0\0"+s(b,2)+s(b,2)+s(x,4)+s(_,4)+s(C.length,2)+C})(this.dirRecords.length,p,d,this.zipComment,this.encodeFileName);this.push({data:m,meta:{percent:100}})},h.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},h.prototype.registerPrevious=function(d){this._sources.push(d);var g=this;return d.on("data",function(p){g.processChunk(p)}),d.on("end",function(){g.closedSource(g.previous.streamInfo),g._sources.length?g.prepareNextSource():g.end()}),d.on("error",function(p){g.error(p)}),this},h.prototype.resume=function(){return!!c.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},h.prototype.error=function(d){var g=this._sources;if(!c.prototype.error.call(this,d))return!1;for(var p=0;p<g.length;p++)try{g[p].error(d)}catch{}return!0},h.prototype.lock=function(){c.prototype.lock.call(this);for(var d=this._sources,g=0;g<d.length;g++)d[g].lock()},r.exports=h},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(n,r,i){var s=n("../compressions"),o=n("./ZipFileWorker");i.generateWorker=function(a,c,l){var f=new o(c.streamFiles,l,c.platform,c.encodeFileName),u=0;try{a.forEach(function(h,d){u++;var g=(function(x,_){var E=x||_,k=s[E];if(!k)throw new Error(E+" is not a valid compression method !");return k})(d.options.compression,c.compression),p=d.options.compressionOptions||c.compressionOptions||{},m=d.dir,b=d.date;d._compressWorker(g,p).withStreamInfo("file",{name:h,dir:m,date:b,comment:d.comment||"",unixPermissions:d.unixPermissions,dosPermissions:d.dosPermissions}).pipe(f)}),f.entriesCount=u}catch(h){f.error(h)}return f}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(n,r,i){function s(){if(!(this instanceof s))return new s;if(arguments.length)throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");this.files=Object.create(null),this.comment=null,this.root="",this.clone=function(){var o=new s;for(var a in this)typeof this[a]!="function"&&(o[a]=this[a]);return o}}(s.prototype=n("./object")).loadAsync=n("./load"),s.support=n("./support"),s.defaults=n("./defaults"),s.version="3.10.1",s.loadAsync=function(o,a){return new s().loadAsync(o,a)},s.external=n("./external"),r.exports=s},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(n,r,i){var s=n("./utils"),o=n("./external"),a=n("./utf8"),c=n("./zipEntries"),l=n("./stream/Crc32Probe"),f=n("./nodejsUtils");function u(h){return new o.Promise(function(d,g){var p=h.decompressed.getContentWorker().pipe(new l);p.on("error",function(m){g(m)}).on("end",function(){p.streamInfo.crc32!==h.decompressed.crc32?g(new Error("Corrupted zip : CRC32 mismatch")):d()}).resume()})}r.exports=function(h,d){var g=this;return d=s.extend(d||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:a.utf8decode}),f.isNode&&f.isStream(h)?o.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):s.prepareContent("the loaded zip file",h,!0,d.optimizedBinaryString,d.base64).then(function(p){var m=new c(d);return m.load(p),m}).then(function(p){var m=[o.Promise.resolve(p)],b=p.files;if(d.checkCRC32)for(var x=0;x<b.length;x++)m.push(u(b[x]));return o.Promise.all(m)}).then(function(p){for(var m=p.shift(),b=m.files,x=0;x<b.length;x++){var _=b[x],E=_.fileNameStr,k=s.resolve(_.fileNameStr);g.file(k,_.decompressed,{binary:!0,optimizedBinaryString:!0,date:_.date,dir:_.dir,comment:_.fileCommentStr.length?_.fileCommentStr:null,unixPermissions:_.unixPermissions,dosPermissions:_.dosPermissions,createFolders:d.createFolders}),_.dir||(g.file(k).unsafeOriginalName=E)}return m.zipComment.length&&(g.comment=m.zipComment),g})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(n,r,i){var s=n("../utils"),o=n("../stream/GenericWorker");function a(c,l){o.call(this,"Nodejs stream input adapter for "+c),this._upstreamEnded=!1,this._bindStream(l)}s.inherits(a,o),a.prototype._bindStream=function(c){var l=this;(this._stream=c).pause(),c.on("data",function(f){l.push({data:f,meta:{percent:0}})}).on("error",function(f){l.isPaused?this.generatedError=f:l.error(f)}).on("end",function(){l.isPaused?l._upstreamEnded=!0:l.end()})},a.prototype.pause=function(){return!!o.prototype.pause.call(this)&&(this._stream.pause(),!0)},a.prototype.resume=function(){return!!o.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},r.exports=a},{"../stream/GenericWorker":28,"../utils":32}],13:[function(n,r,i){var s=n("readable-stream").Readable;function o(a,c,l){s.call(this,c),this._helper=a;var f=this;a.on("data",function(u,h){f.push(u)||f._helper.pause(),l&&l(h)}).on("error",function(u){f.emit("error",u)}).on("end",function(){f.push(null)})}n("../utils").inherits(o,s),o.prototype._read=function(){this._helper.resume()},r.exports=o},{"../utils":32,"readable-stream":16}],14:[function(n,r,i){r.exports={isNode:typeof Buffer<"u",newBufferFrom:function(s,o){if(Buffer.from&&Buffer.from!==Uint8Array.from)return Buffer.from(s,o);if(typeof s=="number")throw new Error('The "data" argument must not be a number');return new Buffer(s,o)},allocBuffer:function(s){if(Buffer.alloc)return Buffer.alloc(s);var o=new Buffer(s);return o.fill(0),o},isBuffer:function(s){return Buffer.isBuffer(s)},isStream:function(s){return s&&typeof s.on=="function"&&typeof s.pause=="function"&&typeof s.resume=="function"}}},{}],15:[function(n,r,i){function s(k,C,T){var j,I=a.getTypeOf(C),R=a.extend(T||{},f);R.date=R.date||new Date,R.compression!==null&&(R.compression=R.compression.toUpperCase()),typeof R.unixPermissions=="string"&&(R.unixPermissions=parseInt(R.unixPermissions,8)),R.unixPermissions&&16384&R.unixPermissions&&(R.dir=!0),R.dosPermissions&&16&R.dosPermissions&&(R.dir=!0),R.dir&&(k=b(k)),R.createFolders&&(j=m(k))&&x.call(this,j,!0);var N=I==="string"&&R.binary===!1&&R.base64===!1;T&&T.binary!==void 0||(R.binary=!N),(C instanceof u&&C.uncompressedSize===0||R.dir||!C||C.length===0)&&(R.base64=!1,R.binary=!0,C="",R.compression="STORE",I="string");var D=null;D=C instanceof u||C instanceof c?C:g.isNode&&g.isStream(C)?new p(k,C):a.prepareContent(k,C,R.binary,R.optimizedBinaryString,R.base64);var y=new h(k,D,R);this.files[k]=y}var o=n("./utf8"),a=n("./utils"),c=n("./stream/GenericWorker"),l=n("./stream/StreamHelper"),f=n("./defaults"),u=n("./compressedObject"),h=n("./zipObject"),d=n("./generate"),g=n("./nodejsUtils"),p=n("./nodejs/NodejsStreamInputAdapter"),m=function(k){k.slice(-1)==="/"&&(k=k.substring(0,k.length-1));var C=k.lastIndexOf("/");return 0<C?k.substring(0,C):""},b=function(k){return k.slice(-1)!=="/"&&(k+="/"),k},x=function(k,C){return C=C!==void 0?C:f.createFolders,k=b(k),this.files[k]||s.call(this,k,null,{dir:!0,createFolders:C}),this.files[k]};function _(k){return Object.prototype.toString.call(k)==="[object RegExp]"}var E={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(k){var C,T,j;for(C in this.files)j=this.files[C],(T=C.slice(this.root.length,C.length))&&C.slice(0,this.root.length)===this.root&&k(T,j)},filter:function(k){var C=[];return this.forEach(function(T,j){k(T,j)&&C.push(j)}),C},file:function(k,C,T){if(arguments.length!==1)return k=this.root+k,s.call(this,k,C,T),this;if(_(k)){var j=k;return this.filter(function(R,N){return!N.dir&&j.test(R)})}var I=this.files[this.root+k];return I&&!I.dir?I:null},folder:function(k){if(!k)return this;if(_(k))return this.filter(function(I,R){return R.dir&&k.test(I)});var C=this.root+k,T=x.call(this,C),j=this.clone();return j.root=T.name,j},remove:function(k){k=this.root+k;var C=this.files[k];if(C||(k.slice(-1)!=="/"&&(k+="/"),C=this.files[k]),C&&!C.dir)delete this.files[k];else for(var T=this.filter(function(I,R){return R.name.slice(0,k.length)===k}),j=0;j<T.length;j++)delete this.files[T[j].name];return this},generate:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(k){var C,T={};try{if((T=a.extend(k||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:o.utf8encode})).type=T.type.toLowerCase(),T.compression=T.compression.toUpperCase(),T.type==="binarystring"&&(T.type="string"),!T.type)throw new Error("No output type specified.");a.checkSupport(T.type),T.platform!=="darwin"&&T.platform!=="freebsd"&&T.platform!=="linux"&&T.platform!=="sunos"||(T.platform="UNIX"),T.platform==="win32"&&(T.platform="DOS");var j=T.comment||this.comment||"";C=d.generateWorker(this,T,j)}catch(I){(C=new c("error")).error(I)}return new l(C,T.type||"string",T.mimeType)},generateAsync:function(k,C){return this.generateInternalStream(k).accumulate(C)},generateNodeStream:function(k,C){return(k=k||{}).type||(k.type="nodebuffer"),this.generateInternalStream(k).toNodejsStream(C)}};r.exports=E},{"./compressedObject":2,"./defaults":5,"./generate":9,"./nodejs/NodejsStreamInputAdapter":12,"./nodejsUtils":14,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31,"./utils":32,"./zipObject":35}],16:[function(n,r,i){r.exports=n("stream")},{stream:void 0}],17:[function(n,r,i){var s=n("./DataReader");function o(a){s.call(this,a);for(var c=0;c<this.data.length;c++)a[c]=255&a[c]}n("../utils").inherits(o,s),o.prototype.byteAt=function(a){return this.data[this.zero+a]},o.prototype.lastIndexOfSignature=function(a){for(var c=a.charCodeAt(0),l=a.charCodeAt(1),f=a.charCodeAt(2),u=a.charCodeAt(3),h=this.length-4;0<=h;--h)if(this.data[h]===c&&this.data[h+1]===l&&this.data[h+2]===f&&this.data[h+3]===u)return h-this.zero;return-1},o.prototype.readAndCheckSignature=function(a){var c=a.charCodeAt(0),l=a.charCodeAt(1),f=a.charCodeAt(2),u=a.charCodeAt(3),h=this.readData(4);return c===h[0]&&l===h[1]&&f===h[2]&&u===h[3]},o.prototype.readData=function(a){if(this.checkOffset(a),a===0)return[];var c=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,c},r.exports=o},{"../utils":32,"./DataReader":18}],18:[function(n,r,i){var s=n("../utils");function o(a){this.data=a,this.length=a.length,this.index=0,this.zero=0}o.prototype={checkOffset:function(a){this.checkIndex(this.index+a)},checkIndex:function(a){if(this.length<this.zero+a||a<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+a+"). Corrupted zip ?")},setIndex:function(a){this.checkIndex(a),this.index=a},skip:function(a){this.setIndex(this.index+a)},byteAt:function(){},readInt:function(a){var c,l=0;for(this.checkOffset(a),c=this.index+a-1;c>=this.index;c--)l=(l<<8)+this.byteAt(c);return this.index+=a,l},readString:function(a){return s.transformTo("string",this.readData(a))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var a=this.readInt(4);return new Date(Date.UTC(1980+(a>>25&127),(a>>21&15)-1,a>>16&31,a>>11&31,a>>5&63,(31&a)<<1))}},r.exports=o},{"../utils":32}],19:[function(n,r,i){var s=n("./Uint8ArrayReader");function o(a){s.call(this,a)}n("../utils").inherits(o,s),o.prototype.readData=function(a){this.checkOffset(a);var c=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,c},r.exports=o},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(n,r,i){var s=n("./DataReader");function o(a){s.call(this,a)}n("../utils").inherits(o,s),o.prototype.byteAt=function(a){return this.data.charCodeAt(this.zero+a)},o.prototype.lastIndexOfSignature=function(a){return this.data.lastIndexOf(a)-this.zero},o.prototype.readAndCheckSignature=function(a){return a===this.readData(4)},o.prototype.readData=function(a){this.checkOffset(a);var c=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,c},r.exports=o},{"../utils":32,"./DataReader":18}],21:[function(n,r,i){var s=n("./ArrayReader");function o(a){s.call(this,a)}n("../utils").inherits(o,s),o.prototype.readData=function(a){if(this.checkOffset(a),a===0)return new Uint8Array(0);var c=this.data.subarray(this.zero+this.index,this.zero+this.index+a);return this.index+=a,c},r.exports=o},{"../utils":32,"./ArrayReader":17}],22:[function(n,r,i){var s=n("../utils"),o=n("../support"),a=n("./ArrayReader"),c=n("./StringReader"),l=n("./NodeBufferReader"),f=n("./Uint8ArrayReader");r.exports=function(u){var h=s.getTypeOf(u);return s.checkSupport(h),h!=="string"||o.uint8array?h==="nodebuffer"?new l(u):o.uint8array?new f(s.transformTo("uint8array",u)):new a(s.transformTo("array",u)):new c(u)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(n,r,i){i.LOCAL_FILE_HEADER="PK\x03\x04",i.CENTRAL_FILE_HEADER="PK\x01\x02",i.CENTRAL_DIRECTORY_END="PK\x05\x06",i.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK\x06\x07",i.ZIP64_CENTRAL_DIRECTORY_END="PK\x06\x06",i.DATA_DESCRIPTOR="PK\x07\b"},{}],24:[function(n,r,i){var s=n("./GenericWorker"),o=n("../utils");function a(c){s.call(this,"ConvertWorker to "+c),this.destType=c}o.inherits(a,s),a.prototype.processChunk=function(c){this.push({data:o.transformTo(this.destType,c.data),meta:c.meta})},r.exports=a},{"../utils":32,"./GenericWorker":28}],25:[function(n,r,i){var s=n("./GenericWorker"),o=n("../crc32");function a(){s.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}n("../utils").inherits(a,s),a.prototype.processChunk=function(c){this.streamInfo.crc32=o(c.data,this.streamInfo.crc32||0),this.push(c)},r.exports=a},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(n,r,i){var s=n("../utils"),o=n("./GenericWorker");function a(c){o.call(this,"DataLengthProbe for "+c),this.propName=c,this.withStreamInfo(c,0)}s.inherits(a,o),a.prototype.processChunk=function(c){if(c){var l=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=l+c.data.length}o.prototype.processChunk.call(this,c)},r.exports=a},{"../utils":32,"./GenericWorker":28}],27:[function(n,r,i){var s=n("../utils"),o=n("./GenericWorker");function a(c){o.call(this,"DataWorker");var l=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,c.then(function(f){l.dataIsReady=!0,l.data=f,l.max=f&&f.length||0,l.type=s.getTypeOf(f),l.isPaused||l._tickAndRepeat()},function(f){l.error(f)})}s.inherits(a,o),a.prototype.cleanUp=function(){o.prototype.cleanUp.call(this),this.data=null},a.prototype.resume=function(){return!!o.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,s.delay(this._tickAndRepeat,[],this)),!0)},a.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(s.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},a.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var c=null,l=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":c=this.data.substring(this.index,l);break;case"uint8array":c=this.data.subarray(this.index,l);break;case"array":case"nodebuffer":c=this.data.slice(this.index,l)}return this.index=l,this.push({data:c,meta:{percent:this.max?this.index/this.max*100:0}})},r.exports=a},{"../utils":32,"./GenericWorker":28}],28:[function(n,r,i){function s(o){this.name=o||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}s.prototype={push:function(o){this.emit("data",o)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(o){this.emit("error",o)}return!0},error:function(o){return!this.isFinished&&(this.isPaused?this.generatedError=o:(this.isFinished=!0,this.emit("error",o),this.previous&&this.previous.error(o),this.cleanUp()),!0)},on:function(o,a){return this._listeners[o].push(a),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(o,a){if(this._listeners[o])for(var c=0;c<this._listeners[o].length;c++)this._listeners[o][c].call(this,a)},pipe:function(o){return o.registerPrevious(this)},registerPrevious:function(o){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.streamInfo=o.streamInfo,this.mergeStreamInfo(),this.previous=o;var a=this;return o.on("data",function(c){a.processChunk(c)}),o.on("end",function(){a.end()}),o.on("error",function(c){a.error(c)}),this},pause:function(){return!this.isPaused&&!this.isFinished&&(this.isPaused=!0,this.previous&&this.previous.pause(),!0)},resume:function(){if(!this.isPaused||this.isFinished)return!1;var o=this.isPaused=!1;return this.generatedError&&(this.error(this.generatedError),o=!0),this.previous&&this.previous.resume(),!o},flush:function(){},processChunk:function(o){this.push(o)},withStreamInfo:function(o,a){return this.extraStreamInfo[o]=a,this.mergeStreamInfo(),this},mergeStreamInfo:function(){for(var o in this.extraStreamInfo)Object.prototype.hasOwnProperty.call(this.extraStreamInfo,o)&&(this.streamInfo[o]=this.extraStreamInfo[o])},lock:function(){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.isLocked=!0,this.previous&&this.previous.lock()},toString:function(){var o="Worker "+this.name;return this.previous?this.previous+" -> "+o:o}},r.exports=s},{}],29:[function(n,r,i){var s=n("../utils"),o=n("./ConvertWorker"),a=n("./GenericWorker"),c=n("../base64"),l=n("../support"),f=n("../external"),u=null;if(l.nodestream)try{u=n("../nodejs/NodejsStreamOutputAdapter")}catch{}function h(g,p){return new f.Promise(function(m,b){var x=[],_=g._internalType,E=g._outputType,k=g._mimeType;g.on("data",function(C,T){x.push(C),p&&p(T)}).on("error",function(C){x=[],b(C)}).on("end",function(){try{var C=(function(T,j,I){switch(T){case"blob":return s.newBlob(s.transformTo("arraybuffer",j),I);case"base64":return c.encode(j);default:return s.transformTo(T,j)}})(E,(function(T,j){var I,R=0,N=null,D=0;for(I=0;I<j.length;I++)D+=j[I].length;switch(T){case"string":return j.join("");case"array":return Array.prototype.concat.apply([],j);case"uint8array":for(N=new Uint8Array(D),I=0;I<j.length;I++)N.set(j[I],R),R+=j[I].length;return N;case"nodebuffer":return Buffer.concat(j);default:throw new Error("concat : unsupported type '"+T+"'")}})(_,x),k);m(C)}catch(T){b(T)}x=[]}).resume()})}function d(g,p,m){var b=p;switch(p){case"blob":case"arraybuffer":b="uint8array";break;case"base64":b="string"}try{this._internalType=b,this._outputType=p,this._mimeType=m,s.checkSupport(b),this._worker=g.pipe(new o(b)),g.lock()}catch(x){this._worker=new a("error"),this._worker.error(x)}}d.prototype={accumulate:function(g){return h(this,g)},on:function(g,p){var m=this;return g==="data"?this._worker.on(g,function(b){p.call(m,b.data,b.meta)}):this._worker.on(g,function(){s.delay(p,arguments,m)}),this},resume:function(){return s.delay(this._worker.resume,[],this._worker),this},pause:function(){return this._worker.pause(),this},toNodejsStream:function(g){if(s.checkSupport("nodestream"),this._outputType!=="nodebuffer")throw new Error(this._outputType+" is not supported by this method");return new u(this,{objectMode:this._outputType!=="nodebuffer"},g)}},r.exports=d},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(n,r,i){if(i.base64=!0,i.array=!0,i.string=!0,i.arraybuffer=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u",i.nodebuffer=typeof Buffer<"u",i.uint8array=typeof Uint8Array<"u",typeof ArrayBuffer>"u")i.blob=!1;else{var s=new ArrayBuffer(0);try{i.blob=new Blob([s],{type:"application/zip"}).size===0}catch{try{var o=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);o.append(s),i.blob=o.getBlob("application/zip").size===0}catch{i.blob=!1}}}try{i.nodestream=!!n("readable-stream").Readable}catch{i.nodestream=!1}},{"readable-stream":16}],31:[function(n,r,i){for(var s=n("./utils"),o=n("./support"),a=n("./nodejsUtils"),c=n("./stream/GenericWorker"),l=new Array(256),f=0;f<256;f++)l[f]=252<=f?6:248<=f?5:240<=f?4:224<=f?3:192<=f?2:1;l[254]=l[254]=1;function u(){c.call(this,"utf-8 decode"),this.leftOver=null}function h(){c.call(this,"utf-8 encode")}i.utf8encode=function(d){return o.nodebuffer?a.newBufferFrom(d,"utf-8"):(function(g){var p,m,b,x,_,E=g.length,k=0;for(x=0;x<E;x++)(64512&(m=g.charCodeAt(x)))==55296&&x+1<E&&(64512&(b=g.charCodeAt(x+1)))==56320&&(m=65536+(m-55296<<10)+(b-56320),x++),k+=m<128?1:m<2048?2:m<65536?3:4;for(p=o.uint8array?new Uint8Array(k):new Array(k),x=_=0;_<k;x++)(64512&(m=g.charCodeAt(x)))==55296&&x+1<E&&(64512&(b=g.charCodeAt(x+1)))==56320&&(m=65536+(m-55296<<10)+(b-56320),x++),m<128?p[_++]=m:(m<2048?p[_++]=192|m>>>6:(m<65536?p[_++]=224|m>>>12:(p[_++]=240|m>>>18,p[_++]=128|m>>>12&63),p[_++]=128|m>>>6&63),p[_++]=128|63&m);return p})(d)},i.utf8decode=function(d){return o.nodebuffer?s.transformTo("nodebuffer",d).toString("utf-8"):(function(g){var p,m,b,x,_=g.length,E=new Array(2*_);for(p=m=0;p<_;)if((b=g[p++])<128)E[m++]=b;else if(4<(x=l[b]))E[m++]=65533,p+=x-1;else{for(b&=x===2?31:x===3?15:7;1<x&&p<_;)b=b<<6|63&g[p++],x--;1<x?E[m++]=65533:b<65536?E[m++]=b:(b-=65536,E[m++]=55296|b>>10&1023,E[m++]=56320|1023&b)}return E.length!==m&&(E.subarray?E=E.subarray(0,m):E.length=m),s.applyFromCharCode(E)})(d=s.transformTo(o.uint8array?"uint8array":"array",d))},s.inherits(u,c),u.prototype.processChunk=function(d){var g=s.transformTo(o.uint8array?"uint8array":"array",d.data);if(this.leftOver&&this.leftOver.length){if(o.uint8array){var p=g;(g=new Uint8Array(p.length+this.leftOver.length)).set(this.leftOver,0),g.set(p,this.leftOver.length)}else g=this.leftOver.concat(g);this.leftOver=null}var m=(function(x,_){var E;for((_=_||x.length)>x.length&&(_=x.length),E=_-1;0<=E&&(192&x[E])==128;)E--;return E<0||E===0?_:E+l[x[E]]>_?E:_})(g),b=g;m!==g.length&&(o.uint8array?(b=g.subarray(0,m),this.leftOver=g.subarray(m,g.length)):(b=g.slice(0,m),this.leftOver=g.slice(m,g.length))),this.push({data:i.utf8decode(b),meta:d.meta})},u.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:i.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},i.Utf8DecodeWorker=u,s.inherits(h,c),h.prototype.processChunk=function(d){this.push({data:i.utf8encode(d.data),meta:d.meta})},i.Utf8EncodeWorker=h},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(n,r,i){var s=n("./support"),o=n("./base64"),a=n("./nodejsUtils"),c=n("./external");function l(p){return p}function f(p,m){for(var b=0;b<p.length;++b)m[b]=255&p.charCodeAt(b);return m}n("setimmediate"),i.newBlob=function(p,m){i.checkSupport("blob");try{return new Blob([p],{type:m})}catch{try{var b=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return b.append(p),b.getBlob(m)}catch{throw new Error("Bug : can't construct the Blob.")}}};var u={stringifyByChunk:function(p,m,b){var x=[],_=0,E=p.length;if(E<=b)return String.fromCharCode.apply(null,p);for(;_<E;)m==="array"||m==="nodebuffer"?x.push(String.fromCharCode.apply(null,p.slice(_,Math.min(_+b,E)))):x.push(String.fromCharCode.apply(null,p.subarray(_,Math.min(_+b,E)))),_+=b;return x.join("")},stringifyByChar:function(p){for(var m="",b=0;b<p.length;b++)m+=String.fromCharCode(p[b]);return m},applyCanBeUsed:{uint8array:(function(){try{return s.uint8array&&String.fromCharCode.apply(null,new Uint8Array(1)).length===1}catch{return!1}})(),nodebuffer:(function(){try{return s.nodebuffer&&String.fromCharCode.apply(null,a.allocBuffer(1)).length===1}catch{return!1}})()}};function h(p){var m=65536,b=i.getTypeOf(p),x=!0;if(b==="uint8array"?x=u.applyCanBeUsed.uint8array:b==="nodebuffer"&&(x=u.applyCanBeUsed.nodebuffer),x)for(;1<m;)try{return u.stringifyByChunk(p,b,m)}catch{m=Math.floor(m/2)}return u.stringifyByChar(p)}function d(p,m){for(var b=0;b<p.length;b++)m[b]=p[b];return m}i.applyFromCharCode=h;var g={};g.string={string:l,array:function(p){return f(p,new Array(p.length))},arraybuffer:function(p){return g.string.uint8array(p).buffer},uint8array:function(p){return f(p,new Uint8Array(p.length))},nodebuffer:function(p){return f(p,a.allocBuffer(p.length))}},g.array={string:h,array:l,arraybuffer:function(p){return new Uint8Array(p).buffer},uint8array:function(p){return new Uint8Array(p)},nodebuffer:function(p){return a.newBufferFrom(p)}},g.arraybuffer={string:function(p){return h(new Uint8Array(p))},array:function(p){return d(new Uint8Array(p),new Array(p.byteLength))},arraybuffer:l,uint8array:function(p){return new Uint8Array(p)},nodebuffer:function(p){return a.newBufferFrom(new Uint8Array(p))}},g.uint8array={string:h,array:function(p){return d(p,new Array(p.length))},arraybuffer:function(p){return p.buffer},uint8array:l,nodebuffer:function(p){return a.newBufferFrom(p)}},g.nodebuffer={string:h,array:function(p){return d(p,new Array(p.length))},arraybuffer:function(p){return g.nodebuffer.uint8array(p).buffer},uint8array:function(p){return d(p,new Uint8Array(p.length))},nodebuffer:l},i.transformTo=function(p,m){if(m=m||"",!p)return m;i.checkSupport(p);var b=i.getTypeOf(m);return g[b][p](m)},i.resolve=function(p){for(var m=p.split("/"),b=[],x=0;x<m.length;x++){var _=m[x];_==="."||_===""&&x!==0&&x!==m.length-1||(_===".."?b.pop():b.push(_))}return b.join("/")},i.getTypeOf=function(p){return typeof p=="string"?"string":Object.prototype.toString.call(p)==="[object Array]"?"array":s.nodebuffer&&a.isBuffer(p)?"nodebuffer":s.uint8array&&p instanceof Uint8Array?"uint8array":s.arraybuffer&&p instanceof ArrayBuffer?"arraybuffer":void 0},i.checkSupport=function(p){if(!s[p.toLowerCase()])throw new Error(p+" is not supported by this platform")},i.MAX_VALUE_16BITS=65535,i.MAX_VALUE_32BITS=-1,i.pretty=function(p){var m,b,x="";for(b=0;b<(p||"").length;b++)x+="\\x"+((m=p.charCodeAt(b))<16?"0":"")+m.toString(16).toUpperCase();return x},i.delay=function(p,m,b){setImmediate(function(){p.apply(b||null,m||[])})},i.inherits=function(p,m){function b(){}b.prototype=m.prototype,p.prototype=new b},i.extend=function(){var p,m,b={};for(p=0;p<arguments.length;p++)for(m in arguments[p])Object.prototype.hasOwnProperty.call(arguments[p],m)&&b[m]===void 0&&(b[m]=arguments[p][m]);return b},i.prepareContent=function(p,m,b,x,_){return c.Promise.resolve(m).then(function(E){return s.blob&&(E instanceof Blob||["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(E))!==-1)&&typeof FileReader<"u"?new c.Promise(function(k,C){var T=new FileReader;T.onload=function(j){k(j.target.result)},T.onerror=function(j){C(j.target.error)},T.readAsArrayBuffer(E)}):E}).then(function(E){var k=i.getTypeOf(E);return k?(k==="arraybuffer"?E=i.transformTo("uint8array",E):k==="string"&&(_?E=o.decode(E):b&&x!==!0&&(E=(function(C){return f(C,s.uint8array?new Uint8Array(C.length):new Array(C.length))})(E))),E):c.Promise.reject(new Error("Can't read the data of '"+p+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(n,r,i){var s=n("./reader/readerFor"),o=n("./utils"),a=n("./signature"),c=n("./zipEntry"),l=n("./support");function f(u){this.files=[],this.loadOptions=u}f.prototype={checkSignature:function(u){if(!this.reader.readAndCheckSignature(u)){this.reader.index-=4;var h=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+o.pretty(h)+", expected "+o.pretty(u)+")")}},isSignature:function(u,h){var d=this.reader.index;this.reader.setIndex(u);var g=this.reader.readString(4)===h;return this.reader.setIndex(d),g},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2);var u=this.reader.readData(this.zipCommentLength),h=l.uint8array?"uint8array":"array",d=o.transformTo(h,u);this.zipComment=this.loadOptions.decodeFileName(d)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.reader.skip(4),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var u,h,d,g=this.zip64EndOfCentralSize-44;0<g;)u=this.reader.readInt(2),h=this.reader.readInt(4),d=this.reader.readData(h),this.zip64ExtensibleData[u]={id:u,length:h,value:d}},readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),1<this.disksCount)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var u,h;for(u=0;u<this.files.length;u++)h=this.files[u],this.reader.setIndex(h.localHeaderOffset),this.checkSignature(a.LOCAL_FILE_HEADER),h.readLocalPart(this.reader),h.handleUTF8(),h.processAttributes()},readCentralDir:function(){var u;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(a.CENTRAL_FILE_HEADER);)(u=new c({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(u);if(this.centralDirRecords!==this.files.length&&this.centralDirRecords!==0&&this.files.length===0)throw new Error("Corrupted zip or bug: expected "+this.centralDirRecords+" records in central dir, got "+this.files.length)},readEndOfCentral:function(){var u=this.reader.lastIndexOfSignature(a.CENTRAL_DIRECTORY_END);if(u<0)throw this.isSignature(0,a.LOCAL_FILE_HEADER)?new Error("Corrupted zip: can't find end of central directory"):new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html");this.reader.setIndex(u);var h=u;if(this.checkSignature(a.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===o.MAX_VALUE_16BITS||this.diskWithCentralDirStart===o.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===o.MAX_VALUE_16BITS||this.centralDirRecords===o.MAX_VALUE_16BITS||this.centralDirSize===o.MAX_VALUE_32BITS||this.centralDirOffset===o.MAX_VALUE_32BITS){if(this.zip64=!0,(u=this.reader.lastIndexOfSignature(a.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(u),this.checkSignature(a.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,a.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(a.ZIP64_CENTRAL_DIRECTORY_END),this.relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(a.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var d=this.centralDirOffset+this.centralDirSize;this.zip64&&(d+=20,d+=12+this.zip64EndOfCentralSize);var g=h-d;if(0<g)this.isSignature(h,a.CENTRAL_FILE_HEADER)||(this.reader.zero=g);else if(g<0)throw new Error("Corrupted zip: missing "+Math.abs(g)+" bytes.")},prepareReader:function(u){this.reader=s(u)},load:function(u){this.prepareReader(u),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},r.exports=f},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(n,r,i){var s=n("./reader/readerFor"),o=n("./utils"),a=n("./compressedObject"),c=n("./crc32"),l=n("./utf8"),f=n("./compressions"),u=n("./support");function h(d,g){this.options=d,this.loadOptions=g}h.prototype={isEncrypted:function(){return(1&this.bitFlag)==1},useUTF8:function(){return(2048&this.bitFlag)==2048},readLocalPart:function(d){var g,p;if(d.skip(22),this.fileNameLength=d.readInt(2),p=d.readInt(2),this.fileName=d.readData(this.fileNameLength),d.skip(p),this.compressedSize===-1||this.uncompressedSize===-1)throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)");if((g=(function(m){for(var b in f)if(Object.prototype.hasOwnProperty.call(f,b)&&f[b].magic===m)return f[b];return null})(this.compressionMethod))===null)throw new Error("Corrupted zip : compression "+o.pretty(this.compressionMethod)+" unknown (inner file : "+o.transformTo("string",this.fileName)+")");this.decompressed=new a(this.compressedSize,this.uncompressedSize,this.crc32,g,d.readData(this.compressedSize))},readCentralPart:function(d){this.versionMadeBy=d.readInt(2),d.skip(2),this.bitFlag=d.readInt(2),this.compressionMethod=d.readString(2),this.date=d.readDate(),this.crc32=d.readInt(4),this.compressedSize=d.readInt(4),this.uncompressedSize=d.readInt(4);var g=d.readInt(2);if(this.extraFieldsLength=d.readInt(2),this.fileCommentLength=d.readInt(2),this.diskNumberStart=d.readInt(2),this.internalFileAttributes=d.readInt(2),this.externalFileAttributes=d.readInt(4),this.localHeaderOffset=d.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");d.skip(g),this.readExtraFields(d),this.parseZIP64ExtraField(d),this.fileComment=d.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var d=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),d==0&&(this.dosPermissions=63&this.externalFileAttributes),d==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!=="/"||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var d=s(this.extraFields[1].value);this.uncompressedSize===o.MAX_VALUE_32BITS&&(this.uncompressedSize=d.readInt(8)),this.compressedSize===o.MAX_VALUE_32BITS&&(this.compressedSize=d.readInt(8)),this.localHeaderOffset===o.MAX_VALUE_32BITS&&(this.localHeaderOffset=d.readInt(8)),this.diskNumberStart===o.MAX_VALUE_32BITS&&(this.diskNumberStart=d.readInt(4))}},readExtraFields:function(d){var g,p,m,b=d.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});d.index+4<b;)g=d.readInt(2),p=d.readInt(2),m=d.readData(p),this.extraFields[g]={id:g,length:p,value:m};d.setIndex(b)},handleUTF8:function(){var d=u.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=l.utf8decode(this.fileName),this.fileCommentStr=l.utf8decode(this.fileComment);else{var g=this.findExtraFieldUnicodePath();if(g!==null)this.fileNameStr=g;else{var p=o.transformTo(d,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(p)}var m=this.findExtraFieldUnicodeComment();if(m!==null)this.fileCommentStr=m;else{var b=o.transformTo(d,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(b)}}},findExtraFieldUnicodePath:function(){var d=this.extraFields[28789];if(d){var g=s(d.value);return g.readInt(1)!==1||c(this.fileName)!==g.readInt(4)?null:l.utf8decode(g.readData(d.length-5))}return null},findExtraFieldUnicodeComment:function(){var d=this.extraFields[25461];if(d){var g=s(d.value);return g.readInt(1)!==1||c(this.fileComment)!==g.readInt(4)?null:l.utf8decode(g.readData(d.length-5))}return null}},r.exports=h},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(n,r,i){function s(g,p,m){this.name=g,this.dir=m.dir,this.date=m.date,this.comment=m.comment,this.unixPermissions=m.unixPermissions,this.dosPermissions=m.dosPermissions,this._data=p,this._dataBinary=m.binary,this.options={compression:m.compression,compressionOptions:m.compressionOptions}}var o=n("./stream/StreamHelper"),a=n("./stream/DataWorker"),c=n("./utf8"),l=n("./compressedObject"),f=n("./stream/GenericWorker");s.prototype={internalStream:function(g){var p=null,m="string";try{if(!g)throw new Error("No output type specified.");var b=(m=g.toLowerCase())==="string"||m==="text";m!=="binarystring"&&m!=="text"||(m="string"),p=this._decompressWorker();var x=!this._dataBinary;x&&!b&&(p=p.pipe(new c.Utf8EncodeWorker)),!x&&b&&(p=p.pipe(new c.Utf8DecodeWorker))}catch(_){(p=new f("error")).error(_)}return new o(p,m,"")},async:function(g,p){return this.internalStream(g).accumulate(p)},nodeStream:function(g,p){return this.internalStream(g||"nodebuffer").toNodejsStream(p)},_compressWorker:function(g,p){if(this._data instanceof l&&this._data.compression.magic===g.magic)return this._data.getCompressedWorker();var m=this._decompressWorker();return this._dataBinary||(m=m.pipe(new c.Utf8EncodeWorker)),l.createWorkerFrom(m,g,p)},_decompressWorker:function(){return this._data instanceof l?this._data.getContentWorker():this._data instanceof f?this._data:new a(this._data)}};for(var u=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],h=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},d=0;d<u.length;d++)s.prototype[u[d]]=h;r.exports=s},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(n,r,i){(function(s){var o,a,c=s.MutationObserver||s.WebKitMutationObserver;if(c){var l=0,f=new c(g),u=s.document.createTextNode("");f.observe(u,{characterData:!0}),o=function(){u.data=l=++l%2}}else if(s.setImmediate||s.MessageChannel===void 0)o="document"in s&&"onreadystatechange"in s.document.createElement("script")?function(){var p=s.document.createElement("script");p.onreadystatechange=function(){g(),p.onreadystatechange=null,p.parentNode.removeChild(p),p=null},s.document.documentElement.appendChild(p)}:function(){setTimeout(g,0)};else{var h=new s.MessageChannel;h.port1.onmessage=g,o=function(){h.port2.postMessage(0)}}var d=[];function g(){var p,m;a=!0;for(var b=d.length;b;){for(m=d,d=[],p=-1;++p<b;)m[p]();b=d.length}a=!1}r.exports=function(p){d.push(p)!==1||a||o()}}).call(this,typeof na<"u"?na:typeof self<"u"?self:typeof window<"u"?window:{})},{}],37:[function(n,r,i){var s=n("immediate");function o(){}var a={},c=["REJECTED"],l=["FULFILLED"],f=["PENDING"];function u(b){if(typeof b!="function")throw new TypeError("resolver must be a function");this.state=f,this.queue=[],this.outcome=void 0,b!==o&&p(this,b)}function h(b,x,_){this.promise=b,typeof x=="function"&&(this.onFulfilled=x,this.callFulfilled=this.otherCallFulfilled),typeof _=="function"&&(this.onRejected=_,this.callRejected=this.otherCallRejected)}function d(b,x,_){s(function(){var E;try{E=x(_)}catch(k){return a.reject(b,k)}E===b?a.reject(b,new TypeError("Cannot resolve promise with itself")):a.resolve(b,E)})}function g(b){var x=b&&b.then;if(b&&(typeof b=="object"||typeof b=="function")&&typeof x=="function")return function(){x.apply(b,arguments)}}function p(b,x){var _=!1;function E(T){_||(_=!0,a.reject(b,T))}function k(T){_||(_=!0,a.resolve(b,T))}var C=m(function(){x(k,E)});C.status==="error"&&E(C.value)}function m(b,x){var _={};try{_.value=b(x),_.status="success"}catch(E){_.status="error",_.value=E}return _}(r.exports=u).prototype.finally=function(b){if(typeof b!="function")return this;var x=this.constructor;return this.then(function(_){return x.resolve(b()).then(function(){return _})},function(_){return x.resolve(b()).then(function(){throw _})})},u.prototype.catch=function(b){return this.then(null,b)},u.prototype.then=function(b,x){if(typeof b!="function"&&this.state===l||typeof x!="function"&&this.state===c)return this;var _=new this.constructor(o);return this.state!==f?d(_,this.state===l?b:x,this.outcome):this.queue.push(new h(_,b,x)),_},h.prototype.callFulfilled=function(b){a.resolve(this.promise,b)},h.prototype.otherCallFulfilled=function(b){d(this.promise,this.onFulfilled,b)},h.prototype.callRejected=function(b){a.reject(this.promise,b)},h.prototype.otherCallRejected=function(b){d(this.promise,this.onRejected,b)},a.resolve=function(b,x){var _=m(g,x);if(_.status==="error")return a.reject(b,_.value);var E=_.value;if(E)p(b,E);else{b.state=l,b.outcome=x;for(var k=-1,C=b.queue.length;++k<C;)b.queue[k].callFulfilled(x)}return b},a.reject=function(b,x){b.state=c,b.outcome=x;for(var _=-1,E=b.queue.length;++_<E;)b.queue[_].callRejected(x);return b},u.resolve=function(b){return b instanceof this?b:a.resolve(new this(o),b)},u.reject=function(b){var x=new this(o);return a.reject(x,b)},u.all=function(b){var x=this;if(Object.prototype.toString.call(b)!=="[object Array]")return this.reject(new TypeError("must be an array"));var _=b.length,E=!1;if(!_)return this.resolve([]);for(var k=new Array(_),C=0,T=-1,j=new this(o);++T<_;)I(b[T],T);return j;function I(R,N){x.resolve(R).then(function(D){k[N]=D,++C!==_||E||(E=!0,a.resolve(j,k))},function(D){E||(E=!0,a.reject(j,D))})}},u.race=function(b){var x=this;if(Object.prototype.toString.call(b)!=="[object Array]")return this.reject(new TypeError("must be an array"));var _=b.length,E=!1;if(!_)return this.resolve([]);for(var k=-1,C=new this(o);++k<_;)T=b[k],x.resolve(T).then(function(j){E||(E=!0,a.resolve(C,j))},function(j){E||(E=!0,a.reject(C,j))});var T;return C}},{immediate:36}],38:[function(n,r,i){var s={};(0,n("./lib/utils/common").assign)(s,n("./lib/deflate"),n("./lib/inflate"),n("./lib/zlib/constants")),r.exports=s},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(n,r,i){var s=n("./zlib/deflate"),o=n("./utils/common"),a=n("./utils/strings"),c=n("./zlib/messages"),l=n("./zlib/zstream"),f=Object.prototype.toString,u=0,h=-1,d=0,g=8;function p(b){if(!(this instanceof p))return new p(b);this.options=o.assign({level:h,method:g,chunkSize:16384,windowBits:15,memLevel:8,strategy:d,to:""},b||{});var x=this.options;x.raw&&0<x.windowBits?x.windowBits=-x.windowBits:x.gzip&&0<x.windowBits&&x.windowBits<16&&(x.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new l,this.strm.avail_out=0;var _=s.deflateInit2(this.strm,x.level,x.method,x.windowBits,x.memLevel,x.strategy);if(_!==u)throw new Error(c[_]);if(x.header&&s.deflateSetHeader(this.strm,x.header),x.dictionary){var E;if(E=typeof x.dictionary=="string"?a.string2buf(x.dictionary):f.call(x.dictionary)==="[object ArrayBuffer]"?new Uint8Array(x.dictionary):x.dictionary,(_=s.deflateSetDictionary(this.strm,E))!==u)throw new Error(c[_]);this._dict_set=!0}}function m(b,x){var _=new p(x);if(_.push(b,!0),_.err)throw _.msg||c[_.err];return _.result}p.prototype.push=function(b,x){var _,E,k=this.strm,C=this.options.chunkSize;if(this.ended)return!1;E=x===~~x?x:x===!0?4:0,typeof b=="string"?k.input=a.string2buf(b):f.call(b)==="[object ArrayBuffer]"?k.input=new Uint8Array(b):k.input=b,k.next_in=0,k.avail_in=k.input.length;do{if(k.avail_out===0&&(k.output=new o.Buf8(C),k.next_out=0,k.avail_out=C),(_=s.deflate(k,E))!==1&&_!==u)return this.onEnd(_),!(this.ended=!0);k.avail_out!==0&&(k.avail_in!==0||E!==4&&E!==2)||(this.options.to==="string"?this.onData(a.buf2binstring(o.shrinkBuf(k.output,k.next_out))):this.onData(o.shrinkBuf(k.output,k.next_out)))}while((0<k.avail_in||k.avail_out===0)&&_!==1);return E===4?(_=s.deflateEnd(this.strm),this.onEnd(_),this.ended=!0,_===u):E!==2||(this.onEnd(u),!(k.avail_out=0))},p.prototype.onData=function(b){this.chunks.push(b)},p.prototype.onEnd=function(b){b===u&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=b,this.msg=this.strm.msg},i.Deflate=p,i.deflate=m,i.deflateRaw=function(b,x){return(x=x||{}).raw=!0,m(b,x)},i.gzip=function(b,x){return(x=x||{}).gzip=!0,m(b,x)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(n,r,i){var s=n("./zlib/inflate"),o=n("./utils/common"),a=n("./utils/strings"),c=n("./zlib/constants"),l=n("./zlib/messages"),f=n("./zlib/zstream"),u=n("./zlib/gzheader"),h=Object.prototype.toString;function d(p){if(!(this instanceof d))return new d(p);this.options=o.assign({chunkSize:16384,windowBits:0,to:""},p||{});var m=this.options;m.raw&&0<=m.windowBits&&m.windowBits<16&&(m.windowBits=-m.windowBits,m.windowBits===0&&(m.windowBits=-15)),!(0<=m.windowBits&&m.windowBits<16)||p&&p.windowBits||(m.windowBits+=32),15<m.windowBits&&m.windowBits<48&&(15&m.windowBits)==0&&(m.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new f,this.strm.avail_out=0;var b=s.inflateInit2(this.strm,m.windowBits);if(b!==c.Z_OK)throw new Error(l[b]);this.header=new u,s.inflateGetHeader(this.strm,this.header)}function g(p,m){var b=new d(m);if(b.push(p,!0),b.err)throw b.msg||l[b.err];return b.result}d.prototype.push=function(p,m){var b,x,_,E,k,C,T=this.strm,j=this.options.chunkSize,I=this.options.dictionary,R=!1;if(this.ended)return!1;x=m===~~m?m:m===!0?c.Z_FINISH:c.Z_NO_FLUSH,typeof p=="string"?T.input=a.binstring2buf(p):h.call(p)==="[object ArrayBuffer]"?T.input=new Uint8Array(p):T.input=p,T.next_in=0,T.avail_in=T.input.length;do{if(T.avail_out===0&&(T.output=new o.Buf8(j),T.next_out=0,T.avail_out=j),(b=s.inflate(T,c.Z_NO_FLUSH))===c.Z_NEED_DICT&&I&&(C=typeof I=="string"?a.string2buf(I):h.call(I)==="[object ArrayBuffer]"?new Uint8Array(I):I,b=s.inflateSetDictionary(this.strm,C)),b===c.Z_BUF_ERROR&&R===!0&&(b=c.Z_OK,R=!1),b!==c.Z_STREAM_END&&b!==c.Z_OK)return this.onEnd(b),!(this.ended=!0);T.next_out&&(T.avail_out!==0&&b!==c.Z_STREAM_END&&(T.avail_in!==0||x!==c.Z_FINISH&&x!==c.Z_SYNC_FLUSH)||(this.options.to==="string"?(_=a.utf8border(T.output,T.next_out),E=T.next_out-_,k=a.buf2string(T.output,_),T.next_out=E,T.avail_out=j-E,E&&o.arraySet(T.output,T.output,_,E,0),this.onData(k)):this.onData(o.shrinkBuf(T.output,T.next_out)))),T.avail_in===0&&T.avail_out===0&&(R=!0)}while((0<T.avail_in||T.avail_out===0)&&b!==c.Z_STREAM_END);return b===c.Z_STREAM_END&&(x=c.Z_FINISH),x===c.Z_FINISH?(b=s.inflateEnd(this.strm),this.onEnd(b),this.ended=!0,b===c.Z_OK):x!==c.Z_SYNC_FLUSH||(this.onEnd(c.Z_OK),!(T.avail_out=0))},d.prototype.onData=function(p){this.chunks.push(p)},d.prototype.onEnd=function(p){p===c.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=p,this.msg=this.strm.msg},i.Inflate=d,i.inflate=g,i.inflateRaw=function(p,m){return(m=m||{}).raw=!0,g(p,m)},i.ungzip=g},{"./utils/common":41,"./utils/strings":42,"./zlib/constants":44,"./zlib/gzheader":47,"./zlib/inflate":49,"./zlib/messages":51,"./zlib/zstream":53}],41:[function(n,r,i){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Int32Array<"u";i.assign=function(c){for(var l=Array.prototype.slice.call(arguments,1);l.length;){var f=l.shift();if(f){if(typeof f!="object")throw new TypeError(f+"must be non-object");for(var u in f)f.hasOwnProperty(u)&&(c[u]=f[u])}}return c},i.shrinkBuf=function(c,l){return c.length===l?c:c.subarray?c.subarray(0,l):(c.length=l,c)};var o={arraySet:function(c,l,f,u,h){if(l.subarray&&c.subarray)c.set(l.subarray(f,f+u),h);else for(var d=0;d<u;d++)c[h+d]=l[f+d]},flattenChunks:function(c){var l,f,u,h,d,g;for(l=u=0,f=c.length;l<f;l++)u+=c[l].length;for(g=new Uint8Array(u),l=h=0,f=c.length;l<f;l++)d=c[l],g.set(d,h),h+=d.length;return g}},a={arraySet:function(c,l,f,u,h){for(var d=0;d<u;d++)c[h+d]=l[f+d]},flattenChunks:function(c){return[].concat.apply([],c)}};i.setTyped=function(c){c?(i.Buf8=Uint8Array,i.Buf16=Uint16Array,i.Buf32=Int32Array,i.assign(i,o)):(i.Buf8=Array,i.Buf16=Array,i.Buf32=Array,i.assign(i,a))},i.setTyped(s)},{}],42:[function(n,r,i){var s=n("./common"),o=!0,a=!0;try{String.fromCharCode.apply(null,[0])}catch{o=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{a=!1}for(var c=new s.Buf8(256),l=0;l<256;l++)c[l]=252<=l?6:248<=l?5:240<=l?4:224<=l?3:192<=l?2:1;function f(u,h){if(h<65537&&(u.subarray&&a||!u.subarray&&o))return String.fromCharCode.apply(null,s.shrinkBuf(u,h));for(var d="",g=0;g<h;g++)d+=String.fromCharCode(u[g]);return d}c[254]=c[254]=1,i.string2buf=function(u){var h,d,g,p,m,b=u.length,x=0;for(p=0;p<b;p++)(64512&(d=u.charCodeAt(p)))==55296&&p+1<b&&(64512&(g=u.charCodeAt(p+1)))==56320&&(d=65536+(d-55296<<10)+(g-56320),p++),x+=d<128?1:d<2048?2:d<65536?3:4;for(h=new s.Buf8(x),p=m=0;m<x;p++)(64512&(d=u.charCodeAt(p)))==55296&&p+1<b&&(64512&(g=u.charCodeAt(p+1)))==56320&&(d=65536+(d-55296<<10)+(g-56320),p++),d<128?h[m++]=d:(d<2048?h[m++]=192|d>>>6:(d<65536?h[m++]=224|d>>>12:(h[m++]=240|d>>>18,h[m++]=128|d>>>12&63),h[m++]=128|d>>>6&63),h[m++]=128|63&d);return h},i.buf2binstring=function(u){return f(u,u.length)},i.binstring2buf=function(u){for(var h=new s.Buf8(u.length),d=0,g=h.length;d<g;d++)h[d]=u.charCodeAt(d);return h},i.buf2string=function(u,h){var d,g,p,m,b=h||u.length,x=new Array(2*b);for(d=g=0;d<b;)if((p=u[d++])<128)x[g++]=p;else if(4<(m=c[p]))x[g++]=65533,d+=m-1;else{for(p&=m===2?31:m===3?15:7;1<m&&d<b;)p=p<<6|63&u[d++],m--;1<m?x[g++]=65533:p<65536?x[g++]=p:(p-=65536,x[g++]=55296|p>>10&1023,x[g++]=56320|1023&p)}return f(x,g)},i.utf8border=function(u,h){var d;for((h=h||u.length)>u.length&&(h=u.length),d=h-1;0<=d&&(192&u[d])==128;)d--;return d<0||d===0?h:d+c[u[d]]>h?d:h}},{"./common":41}],43:[function(n,r,i){r.exports=function(s,o,a,c){for(var l=65535&s|0,f=s>>>16&65535|0,u=0;a!==0;){for(a-=u=2e3<a?2e3:a;f=f+(l=l+o[c++]|0)|0,--u;);l%=65521,f%=65521}return l|f<<16|0}},{}],44:[function(n,r,i){r.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],45:[function(n,r,i){var s=(function(){for(var o,a=[],c=0;c<256;c++){o=c;for(var l=0;l<8;l++)o=1&o?0xedb88320^o>>>1:o>>>1;a[c]=o}return a})();r.exports=function(o,a,c,l){var f=s,u=l+c;o^=-1;for(var h=l;h<u;h++)o=o>>>8^f[255&(o^a[h])];return-1^o}},{}],46:[function(n,r,i){var s,o=n("../utils/common"),a=n("./trees"),c=n("./adler32"),l=n("./crc32"),f=n("./messages"),u=0,h=4,d=0,g=-2,p=-1,m=4,b=2,x=8,_=9,E=286,k=30,C=19,T=2*E+1,j=15,I=3,R=258,N=R+I+1,D=42,y=113,w=1,$=2,P=3,A=4;function J(v,V){return v.msg=f[V],V}function S(v){return(v<<1)-(4<v?9:0)}function U(v){for(var V=v.length;0<=--V;)v[V]=0}function O(v){var V=v.state,L=V.pending;L>v.avail_out&&(L=v.avail_out),L!==0&&(o.arraySet(v.output,V.pending_buf,V.pending_out,L,v.next_out),v.next_out+=L,V.pending_out+=L,v.total_out+=L,v.avail_out-=L,V.pending-=L,V.pending===0&&(V.pending_out=0))}function F(v,V){a._tr_flush_block(v,0<=v.block_start?v.block_start:-1,v.strstart-v.block_start,V),v.block_start=v.strstart,O(v.strm)}function X(v,V){v.pending_buf[v.pending++]=V}function ie(v,V){v.pending_buf[v.pending++]=V>>>8&255,v.pending_buf[v.pending++]=255&V}function se(v,V){var L,B,z=v.max_chain_length,H=v.strstart,Y=v.prev_length,oe=v.nice_match,M=v.strstart>v.w_size-N?v.strstart-(v.w_size-N):0,te=v.window,ge=v.w_mask,de=v.prev,Se=v.strstart+R,Pe=te[H+Y-1],Te=te[H+Y];v.prev_length>=v.good_match&&(z>>=2),oe>v.lookahead&&(oe=v.lookahead);do if(te[(L=V)+Y]===Te&&te[L+Y-1]===Pe&&te[L]===te[H]&&te[++L]===te[H+1]){H+=2,L++;do;while(te[++H]===te[++L]&&te[++H]===te[++L]&&te[++H]===te[++L]&&te[++H]===te[++L]&&te[++H]===te[++L]&&te[++H]===te[++L]&&te[++H]===te[++L]&&te[++H]===te[++L]&&H<Se);if(B=R-(Se-H),H=Se-R,Y<B){if(v.match_start=V,oe<=(Y=B))break;Pe=te[H+Y-1],Te=te[H+Y]}}while((V=de[V&ge])>M&&--z!=0);return Y<=v.lookahead?Y:v.lookahead}function $e(v){var V,L,B,z,H,Y,oe,M,te,ge,de=v.w_size;do{if(z=v.window_size-v.lookahead-v.strstart,v.strstart>=de+(de-N)){for(o.arraySet(v.window,v.window,de,de,0),v.match_start-=de,v.strstart-=de,v.block_start-=de,V=L=v.hash_size;B=v.head[--V],v.head[V]=de<=B?B-de:0,--L;);for(V=L=de;B=v.prev[--V],v.prev[V]=de<=B?B-de:0,--L;);z+=de}if(v.strm.avail_in===0)break;if(Y=v.strm,oe=v.window,M=v.strstart+v.lookahead,te=z,ge=void 0,ge=Y.avail_in,te<ge&&(ge=te),L=ge===0?0:(Y.avail_in-=ge,o.arraySet(oe,Y.input,Y.next_in,ge,M),Y.state.wrap===1?Y.adler=c(Y.adler,oe,ge,M):Y.state.wrap===2&&(Y.adler=l(Y.adler,oe,ge,M)),Y.next_in+=ge,Y.total_in+=ge,ge),v.lookahead+=L,v.lookahead+v.insert>=I)for(H=v.strstart-v.insert,v.ins_h=v.window[H],v.ins_h=(v.ins_h<<v.hash_shift^v.window[H+1])&v.hash_mask;v.insert&&(v.ins_h=(v.ins_h<<v.hash_shift^v.window[H+I-1])&v.hash_mask,v.prev[H&v.w_mask]=v.head[v.ins_h],v.head[v.ins_h]=H,H++,v.insert--,!(v.lookahead+v.insert<I)););}while(v.lookahead<N&&v.strm.avail_in!==0)}function Ce(v,V){for(var L,B;;){if(v.lookahead<N){if($e(v),v.lookahead<N&&V===u)return w;if(v.lookahead===0)break}if(L=0,v.lookahead>=I&&(v.ins_h=(v.ins_h<<v.hash_shift^v.window[v.strstart+I-1])&v.hash_mask,L=v.prev[v.strstart&v.w_mask]=v.head[v.ins_h],v.head[v.ins_h]=v.strstart),L!==0&&v.strstart-L<=v.w_size-N&&(v.match_length=se(v,L)),v.match_length>=I)if(B=a._tr_tally(v,v.strstart-v.match_start,v.match_length-I),v.lookahead-=v.match_length,v.match_length<=v.max_lazy_match&&v.lookahead>=I){for(v.match_length--;v.strstart++,v.ins_h=(v.ins_h<<v.hash_shift^v.window[v.strstart+I-1])&v.hash_mask,L=v.prev[v.strstart&v.w_mask]=v.head[v.ins_h],v.head[v.ins_h]=v.strstart,--v.match_length!=0;);v.strstart++}else v.strstart+=v.match_length,v.match_length=0,v.ins_h=v.window[v.strstart],v.ins_h=(v.ins_h<<v.hash_shift^v.window[v.strstart+1])&v.hash_mask;else B=a._tr_tally(v,0,v.window[v.strstart]),v.lookahead--,v.strstart++;if(B&&(F(v,!1),v.strm.avail_out===0))return w}return v.insert=v.strstart<I-1?v.strstart:I-1,V===h?(F(v,!0),v.strm.avail_out===0?P:A):v.last_lit&&(F(v,!1),v.strm.avail_out===0)?w:$}function Oe(v,V){for(var L,B,z;;){if(v.lookahead<N){if($e(v),v.lookahead<N&&V===u)return w;if(v.lookahead===0)break}if(L=0,v.lookahead>=I&&(v.ins_h=(v.ins_h<<v.hash_shift^v.window[v.strstart+I-1])&v.hash_mask,L=v.prev[v.strstart&v.w_mask]=v.head[v.ins_h],v.head[v.ins_h]=v.strstart),v.prev_length=v.match_length,v.prev_match=v.match_start,v.match_length=I-1,L!==0&&v.prev_length<v.max_lazy_match&&v.strstart-L<=v.w_size-N&&(v.match_length=se(v,L),v.match_length<=5&&(v.strategy===1||v.match_length===I&&4096<v.strstart-v.match_start)&&(v.match_length=I-1)),v.prev_length>=I&&v.match_length<=v.prev_length){for(z=v.strstart+v.lookahead-I,B=a._tr_tally(v,v.strstart-1-v.prev_match,v.prev_length-I),v.lookahead-=v.prev_length-1,v.prev_length-=2;++v.strstart<=z&&(v.ins_h=(v.ins_h<<v.hash_shift^v.window[v.strstart+I-1])&v.hash_mask,L=v.prev[v.strstart&v.w_mask]=v.head[v.ins_h],v.head[v.ins_h]=v.strstart),--v.prev_length!=0;);if(v.match_available=0,v.match_length=I-1,v.strstart++,B&&(F(v,!1),v.strm.avail_out===0))return w}else if(v.match_available){if((B=a._tr_tally(v,0,v.window[v.strstart-1]))&&F(v,!1),v.strstart++,v.lookahead--,v.strm.avail_out===0)return w}else v.match_available=1,v.strstart++,v.lookahead--}return v.match_available&&(B=a._tr_tally(v,0,v.window[v.strstart-1]),v.match_available=0),v.insert=v.strstart<I-1?v.strstart:I-1,V===h?(F(v,!0),v.strm.avail_out===0?P:A):v.last_lit&&(F(v,!1),v.strm.avail_out===0)?w:$}function ye(v,V,L,B,z){this.good_length=v,this.max_lazy=V,this.nice_length=L,this.max_chain=B,this.func=z}function ve(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=x,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new o.Buf16(2*T),this.dyn_dtree=new o.Buf16(2*(2*k+1)),this.bl_tree=new o.Buf16(2*(2*C+1)),U(this.dyn_ltree),U(this.dyn_dtree),U(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new o.Buf16(j+1),this.heap=new o.Buf16(2*E+1),U(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new o.Buf16(2*E+1),U(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function me(v){var V;return v&&v.state?(v.total_in=v.total_out=0,v.data_type=b,(V=v.state).pending=0,V.pending_out=0,V.wrap<0&&(V.wrap=-V.wrap),V.status=V.wrap?D:y,v.adler=V.wrap===2?0:1,V.last_flush=u,a._tr_init(V),d):J(v,g)}function _e(v){var V=me(v);return V===d&&(function(L){L.window_size=2*L.w_size,U(L.head),L.max_lazy_match=s[L.level].max_lazy,L.good_match=s[L.level].good_length,L.nice_match=s[L.level].nice_length,L.max_chain_length=s[L.level].max_chain,L.strstart=0,L.block_start=0,L.lookahead=0,L.insert=0,L.match_length=L.prev_length=I-1,L.match_available=0,L.ins_h=0})(v.state),V}function xe(v,V,L,B,z,H){if(!v)return g;var Y=1;if(V===p&&(V=6),B<0?(Y=0,B=-B):15<B&&(Y=2,B-=16),z<1||_<z||L!==x||B<8||15<B||V<0||9<V||H<0||m<H)return J(v,g);B===8&&(B=9);var oe=new ve;return(v.state=oe).strm=v,oe.wrap=Y,oe.gzhead=null,oe.w_bits=B,oe.w_size=1<<oe.w_bits,oe.w_mask=oe.w_size-1,oe.hash_bits=z+7,oe.hash_size=1<<oe.hash_bits,oe.hash_mask=oe.hash_size-1,oe.hash_shift=~~((oe.hash_bits+I-1)/I),oe.window=new o.Buf8(2*oe.w_size),oe.head=new o.Buf16(oe.hash_size),oe.prev=new o.Buf16(oe.w_size),oe.lit_bufsize=1<<z+6,oe.pending_buf_size=4*oe.lit_bufsize,oe.pending_buf=new o.Buf8(oe.pending_buf_size),oe.d_buf=1*oe.lit_bufsize,oe.l_buf=3*oe.lit_bufsize,oe.level=V,oe.strategy=H,oe.method=L,_e(v)}s=[new ye(0,0,0,0,function(v,V){var L=65535;for(L>v.pending_buf_size-5&&(L=v.pending_buf_size-5);;){if(v.lookahead<=1){if($e(v),v.lookahead===0&&V===u)return w;if(v.lookahead===0)break}v.strstart+=v.lookahead,v.lookahead=0;var B=v.block_start+L;if((v.strstart===0||v.strstart>=B)&&(v.lookahead=v.strstart-B,v.strstart=B,F(v,!1),v.strm.avail_out===0)||v.strstart-v.block_start>=v.w_size-N&&(F(v,!1),v.strm.avail_out===0))return w}return v.insert=0,V===h?(F(v,!0),v.strm.avail_out===0?P:A):(v.strstart>v.block_start&&(F(v,!1),v.strm.avail_out),w)}),new ye(4,4,8,4,Ce),new ye(4,5,16,8,Ce),new ye(4,6,32,32,Ce),new ye(4,4,16,16,Oe),new ye(8,16,32,32,Oe),new ye(8,16,128,128,Oe),new ye(8,32,128,256,Oe),new ye(32,128,258,1024,Oe),new ye(32,258,258,4096,Oe)],i.deflateInit=function(v,V){return xe(v,V,x,15,8,0)},i.deflateInit2=xe,i.deflateReset=_e,i.deflateResetKeep=me,i.deflateSetHeader=function(v,V){return v&&v.state?v.state.wrap!==2?g:(v.state.gzhead=V,d):g},i.deflate=function(v,V){var L,B,z,H;if(!v||!v.state||5<V||V<0)return v?J(v,g):g;if(B=v.state,!v.output||!v.input&&v.avail_in!==0||B.status===666&&V!==h)return J(v,v.avail_out===0?-5:g);if(B.strm=v,L=B.last_flush,B.last_flush=V,B.status===D)if(B.wrap===2)v.adler=0,X(B,31),X(B,139),X(B,8),B.gzhead?(X(B,(B.gzhead.text?1:0)+(B.gzhead.hcrc?2:0)+(B.gzhead.extra?4:0)+(B.gzhead.name?8:0)+(B.gzhead.comment?16:0)),X(B,255&B.gzhead.time),X(B,B.gzhead.time>>8&255),X(B,B.gzhead.time>>16&255),X(B,B.gzhead.time>>24&255),X(B,B.level===9?2:2<=B.strategy||B.level<2?4:0),X(B,255&B.gzhead.os),B.gzhead.extra&&B.gzhead.extra.length&&(X(B,255&B.gzhead.extra.length),X(B,B.gzhead.extra.length>>8&255)),B.gzhead.hcrc&&(v.adler=l(v.adler,B.pending_buf,B.pending,0)),B.gzindex=0,B.status=69):(X(B,0),X(B,0),X(B,0),X(B,0),X(B,0),X(B,B.level===9?2:2<=B.strategy||B.level<2?4:0),X(B,3),B.status=y);else{var Y=x+(B.w_bits-8<<4)<<8;Y|=(2<=B.strategy||B.level<2?0:B.level<6?1:B.level===6?2:3)<<6,B.strstart!==0&&(Y|=32),Y+=31-Y%31,B.status=y,ie(B,Y),B.strstart!==0&&(ie(B,v.adler>>>16),ie(B,65535&v.adler)),v.adler=1}if(B.status===69)if(B.gzhead.extra){for(z=B.pending;B.gzindex<(65535&B.gzhead.extra.length)&&(B.pending!==B.pending_buf_size||(B.gzhead.hcrc&&B.pending>z&&(v.adler=l(v.adler,B.pending_buf,B.pending-z,z)),O(v),z=B.pending,B.pending!==B.pending_buf_size));)X(B,255&B.gzhead.extra[B.gzindex]),B.gzindex++;B.gzhead.hcrc&&B.pending>z&&(v.adler=l(v.adler,B.pending_buf,B.pending-z,z)),B.gzindex===B.gzhead.extra.length&&(B.gzindex=0,B.status=73)}else B.status=73;if(B.status===73)if(B.gzhead.name){z=B.pending;do{if(B.pending===B.pending_buf_size&&(B.gzhead.hcrc&&B.pending>z&&(v.adler=l(v.adler,B.pending_buf,B.pending-z,z)),O(v),z=B.pending,B.pending===B.pending_buf_size)){H=1;break}H=B.gzindex<B.gzhead.name.length?255&B.gzhead.name.charCodeAt(B.gzindex++):0,X(B,H)}while(H!==0);B.gzhead.hcrc&&B.pending>z&&(v.adler=l(v.adler,B.pending_buf,B.pending-z,z)),H===0&&(B.gzindex=0,B.status=91)}else B.status=91;if(B.status===91)if(B.gzhead.comment){z=B.pending;do{if(B.pending===B.pending_buf_size&&(B.gzhead.hcrc&&B.pending>z&&(v.adler=l(v.adler,B.pending_buf,B.pending-z,z)),O(v),z=B.pending,B.pending===B.pending_buf_size)){H=1;break}H=B.gzindex<B.gzhead.comment.length?255&B.gzhead.comment.charCodeAt(B.gzindex++):0,X(B,H)}while(H!==0);B.gzhead.hcrc&&B.pending>z&&(v.adler=l(v.adler,B.pending_buf,B.pending-z,z)),H===0&&(B.status=103)}else B.status=103;if(B.status===103&&(B.gzhead.hcrc?(B.pending+2>B.pending_buf_size&&O(v),B.pending+2<=B.pending_buf_size&&(X(B,255&v.adler),X(B,v.adler>>8&255),v.adler=0,B.status=y)):B.status=y),B.pending!==0){if(O(v),v.avail_out===0)return B.last_flush=-1,d}else if(v.avail_in===0&&S(V)<=S(L)&&V!==h)return J(v,-5);if(B.status===666&&v.avail_in!==0)return J(v,-5);if(v.avail_in!==0||B.lookahead!==0||V!==u&&B.status!==666){var oe=B.strategy===2?(function(M,te){for(var ge;;){if(M.lookahead===0&&($e(M),M.lookahead===0)){if(te===u)return w;break}if(M.match_length=0,ge=a._tr_tally(M,0,M.window[M.strstart]),M.lookahead--,M.strstart++,ge&&(F(M,!1),M.strm.avail_out===0))return w}return M.insert=0,te===h?(F(M,!0),M.strm.avail_out===0?P:A):M.last_lit&&(F(M,!1),M.strm.avail_out===0)?w:$})(B,V):B.strategy===3?(function(M,te){for(var ge,de,Se,Pe,Te=M.window;;){if(M.lookahead<=R){if($e(M),M.lookahead<=R&&te===u)return w;if(M.lookahead===0)break}if(M.match_length=0,M.lookahead>=I&&0<M.strstart&&(de=Te[Se=M.strstart-1])===Te[++Se]&&de===Te[++Se]&&de===Te[++Se]){Pe=M.strstart+R;do;while(de===Te[++Se]&&de===Te[++Se]&&de===Te[++Se]&&de===Te[++Se]&&de===Te[++Se]&&de===Te[++Se]&&de===Te[++Se]&&de===Te[++Se]&&Se<Pe);M.match_length=R-(Pe-Se),M.match_length>M.lookahead&&(M.match_length=M.lookahead)}if(M.match_length>=I?(ge=a._tr_tally(M,1,M.match_length-I),M.lookahead-=M.match_length,M.strstart+=M.match_length,M.match_length=0):(ge=a._tr_tally(M,0,M.window[M.strstart]),M.lookahead--,M.strstart++),ge&&(F(M,!1),M.strm.avail_out===0))return w}return M.insert=0,te===h?(F(M,!0),M.strm.avail_out===0?P:A):M.last_lit&&(F(M,!1),M.strm.avail_out===0)?w:$})(B,V):s[B.level].func(B,V);if(oe!==P&&oe!==A||(B.status=666),oe===w||oe===P)return v.avail_out===0&&(B.last_flush=-1),d;if(oe===$&&(V===1?a._tr_align(B):V!==5&&(a._tr_stored_block(B,0,0,!1),V===3&&(U(B.head),B.lookahead===0&&(B.strstart=0,B.block_start=0,B.insert=0))),O(v),v.avail_out===0))return B.last_flush=-1,d}return V!==h?d:B.wrap<=0?1:(B.wrap===2?(X(B,255&v.adler),X(B,v.adler>>8&255),X(B,v.adler>>16&255),X(B,v.adler>>24&255),X(B,255&v.total_in),X(B,v.total_in>>8&255),X(B,v.total_in>>16&255),X(B,v.total_in>>24&255)):(ie(B,v.adler>>>16),ie(B,65535&v.adler)),O(v),0<B.wrap&&(B.wrap=-B.wrap),B.pending!==0?d:1)},i.deflateEnd=function(v){var V;return v&&v.state?(V=v.state.status)!==D&&V!==69&&V!==73&&V!==91&&V!==103&&V!==y&&V!==666?J(v,g):(v.state=null,V===y?J(v,-3):d):g},i.deflateSetDictionary=function(v,V){var L,B,z,H,Y,oe,M,te,ge=V.length;if(!v||!v.state||(H=(L=v.state).wrap)===2||H===1&&L.status!==D||L.lookahead)return g;for(H===1&&(v.adler=c(v.adler,V,ge,0)),L.wrap=0,ge>=L.w_size&&(H===0&&(U(L.head),L.strstart=0,L.block_start=0,L.insert=0),te=new o.Buf8(L.w_size),o.arraySet(te,V,ge-L.w_size,L.w_size,0),V=te,ge=L.w_size),Y=v.avail_in,oe=v.next_in,M=v.input,v.avail_in=ge,v.next_in=0,v.input=V,$e(L);L.lookahead>=I;){for(B=L.strstart,z=L.lookahead-(I-1);L.ins_h=(L.ins_h<<L.hash_shift^L.window[B+I-1])&L.hash_mask,L.prev[B&L.w_mask]=L.head[L.ins_h],L.head[L.ins_h]=B,B++,--z;);L.strstart=B,L.lookahead=I-1,$e(L)}return L.strstart+=L.lookahead,L.block_start=L.strstart,L.insert=L.lookahead,L.lookahead=0,L.match_length=L.prev_length=I-1,L.match_available=0,v.next_in=oe,v.input=M,v.avail_in=Y,L.wrap=H,d},i.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(n,r,i){r.exports=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}},{}],48:[function(n,r,i){r.exports=function(s,o){var a,c,l,f,u,h,d,g,p,m,b,x,_,E,k,C,T,j,I,R,N,D,y,w,$;a=s.state,c=s.next_in,w=s.input,l=c+(s.avail_in-5),f=s.next_out,$=s.output,u=f-(o-s.avail_out),h=f+(s.avail_out-257),d=a.dmax,g=a.wsize,p=a.whave,m=a.wnext,b=a.window,x=a.hold,_=a.bits,E=a.lencode,k=a.distcode,C=(1<<a.lenbits)-1,T=(1<<a.distbits)-1;e:do{_<15&&(x+=w[c++]<<_,_+=8,x+=w[c++]<<_,_+=8),j=E[x&C];t:for(;;){if(x>>>=I=j>>>24,_-=I,(I=j>>>16&255)===0)$[f++]=65535&j;else{if(!(16&I)){if((64&I)==0){j=E[(65535&j)+(x&(1<<I)-1)];continue t}if(32&I){a.mode=12;break e}s.msg="invalid literal/length code",a.mode=30;break e}R=65535&j,(I&=15)&&(_<I&&(x+=w[c++]<<_,_+=8),R+=x&(1<<I)-1,x>>>=I,_-=I),_<15&&(x+=w[c++]<<_,_+=8,x+=w[c++]<<_,_+=8),j=k[x&T];n:for(;;){if(x>>>=I=j>>>24,_-=I,!(16&(I=j>>>16&255))){if((64&I)==0){j=k[(65535&j)+(x&(1<<I)-1)];continue n}s.msg="invalid distance code",a.mode=30;break e}if(N=65535&j,_<(I&=15)&&(x+=w[c++]<<_,(_+=8)<I&&(x+=w[c++]<<_,_+=8)),d<(N+=x&(1<<I)-1)){s.msg="invalid distance too far back",a.mode=30;break e}if(x>>>=I,_-=I,(I=f-u)<N){if(p<(I=N-I)&&a.sane){s.msg="invalid distance too far back",a.mode=30;break e}if(y=b,(D=0)===m){if(D+=g-I,I<R){for(R-=I;$[f++]=b[D++],--I;);D=f-N,y=$}}else if(m<I){if(D+=g+m-I,(I-=m)<R){for(R-=I;$[f++]=b[D++],--I;);if(D=0,m<R){for(R-=I=m;$[f++]=b[D++],--I;);D=f-N,y=$}}}else if(D+=m-I,I<R){for(R-=I;$[f++]=b[D++],--I;);D=f-N,y=$}for(;2<R;)$[f++]=y[D++],$[f++]=y[D++],$[f++]=y[D++],R-=3;R&&($[f++]=y[D++],1<R&&($[f++]=y[D++]))}else{for(D=f-N;$[f++]=$[D++],$[f++]=$[D++],$[f++]=$[D++],2<(R-=3););R&&($[f++]=$[D++],1<R&&($[f++]=$[D++]))}break}}break}}while(c<l&&f<h);c-=R=_>>3,x&=(1<<(_-=R<<3))-1,s.next_in=c,s.next_out=f,s.avail_in=c<l?l-c+5:5-(c-l),s.avail_out=f<h?h-f+257:257-(f-h),a.hold=x,a.bits=_}},{}],49:[function(n,r,i){var s=n("../utils/common"),o=n("./adler32"),a=n("./crc32"),c=n("./inffast"),l=n("./inftrees"),f=1,u=2,h=0,d=-2,g=1,p=852,m=592;function b(D){return(D>>>24&255)+(D>>>8&65280)+((65280&D)<<8)+((255&D)<<24)}function x(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new s.Buf16(320),this.work=new s.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function _(D){var y;return D&&D.state?(y=D.state,D.total_in=D.total_out=y.total=0,D.msg="",y.wrap&&(D.adler=1&y.wrap),y.mode=g,y.last=0,y.havedict=0,y.dmax=32768,y.head=null,y.hold=0,y.bits=0,y.lencode=y.lendyn=new s.Buf32(p),y.distcode=y.distdyn=new s.Buf32(m),y.sane=1,y.back=-1,h):d}function E(D){var y;return D&&D.state?((y=D.state).wsize=0,y.whave=0,y.wnext=0,_(D)):d}function k(D,y){var w,$;return D&&D.state?($=D.state,y<0?(w=0,y=-y):(w=1+(y>>4),y<48&&(y&=15)),y&&(y<8||15<y)?d:($.window!==null&&$.wbits!==y&&($.window=null),$.wrap=w,$.wbits=y,E(D))):d}function C(D,y){var w,$;return D?($=new x,(D.state=$).window=null,(w=k(D,y))!==h&&(D.state=null),w):d}var T,j,I=!0;function R(D){if(I){var y;for(T=new s.Buf32(512),j=new s.Buf32(32),y=0;y<144;)D.lens[y++]=8;for(;y<256;)D.lens[y++]=9;for(;y<280;)D.lens[y++]=7;for(;y<288;)D.lens[y++]=8;for(l(f,D.lens,0,288,T,0,D.work,{bits:9}),y=0;y<32;)D.lens[y++]=5;l(u,D.lens,0,32,j,0,D.work,{bits:5}),I=!1}D.lencode=T,D.lenbits=9,D.distcode=j,D.distbits=5}function N(D,y,w,$){var P,A=D.state;return A.window===null&&(A.wsize=1<<A.wbits,A.wnext=0,A.whave=0,A.window=new s.Buf8(A.wsize)),$>=A.wsize?(s.arraySet(A.window,y,w-A.wsize,A.wsize,0),A.wnext=0,A.whave=A.wsize):($<(P=A.wsize-A.wnext)&&(P=$),s.arraySet(A.window,y,w-$,P,A.wnext),($-=P)?(s.arraySet(A.window,y,w-$,$,0),A.wnext=$,A.whave=A.wsize):(A.wnext+=P,A.wnext===A.wsize&&(A.wnext=0),A.whave<A.wsize&&(A.whave+=P))),0}i.inflateReset=E,i.inflateReset2=k,i.inflateResetKeep=_,i.inflateInit=function(D){return C(D,15)},i.inflateInit2=C,i.inflate=function(D,y){var w,$,P,A,J,S,U,O,F,X,ie,se,$e,Ce,Oe,ye,ve,me,_e,xe,v,V,L,B,z=0,H=new s.Buf8(4),Y=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!D||!D.state||!D.output||!D.input&&D.avail_in!==0)return d;(w=D.state).mode===12&&(w.mode=13),J=D.next_out,P=D.output,U=D.avail_out,A=D.next_in,$=D.input,S=D.avail_in,O=w.hold,F=w.bits,X=S,ie=U,V=h;e:for(;;)switch(w.mode){case g:if(w.wrap===0){w.mode=13;break}for(;F<16;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}if(2&w.wrap&&O===35615){H[w.check=0]=255&O,H[1]=O>>>8&255,w.check=a(w.check,H,2,0),F=O=0,w.mode=2;break}if(w.flags=0,w.head&&(w.head.done=!1),!(1&w.wrap)||(((255&O)<<8)+(O>>8))%31){D.msg="incorrect header check",w.mode=30;break}if((15&O)!=8){D.msg="unknown compression method",w.mode=30;break}if(F-=4,v=8+(15&(O>>>=4)),w.wbits===0)w.wbits=v;else if(v>w.wbits){D.msg="invalid window size",w.mode=30;break}w.dmax=1<<v,D.adler=w.check=1,w.mode=512&O?10:12,F=O=0;break;case 2:for(;F<16;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}if(w.flags=O,(255&w.flags)!=8){D.msg="unknown compression method",w.mode=30;break}if(57344&w.flags){D.msg="unknown header flags set",w.mode=30;break}w.head&&(w.head.text=O>>8&1),512&w.flags&&(H[0]=255&O,H[1]=O>>>8&255,w.check=a(w.check,H,2,0)),F=O=0,w.mode=3;case 3:for(;F<32;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}w.head&&(w.head.time=O),512&w.flags&&(H[0]=255&O,H[1]=O>>>8&255,H[2]=O>>>16&255,H[3]=O>>>24&255,w.check=a(w.check,H,4,0)),F=O=0,w.mode=4;case 4:for(;F<16;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}w.head&&(w.head.xflags=255&O,w.head.os=O>>8),512&w.flags&&(H[0]=255&O,H[1]=O>>>8&255,w.check=a(w.check,H,2,0)),F=O=0,w.mode=5;case 5:if(1024&w.flags){for(;F<16;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}w.length=O,w.head&&(w.head.extra_len=O),512&w.flags&&(H[0]=255&O,H[1]=O>>>8&255,w.check=a(w.check,H,2,0)),F=O=0}else w.head&&(w.head.extra=null);w.mode=6;case 6:if(1024&w.flags&&(S<(se=w.length)&&(se=S),se&&(w.head&&(v=w.head.extra_len-w.length,w.head.extra||(w.head.extra=new Array(w.head.extra_len)),s.arraySet(w.head.extra,$,A,se,v)),512&w.flags&&(w.check=a(w.check,$,se,A)),S-=se,A+=se,w.length-=se),w.length))break e;w.length=0,w.mode=7;case 7:if(2048&w.flags){if(S===0)break e;for(se=0;v=$[A+se++],w.head&&v&&w.length<65536&&(w.head.name+=String.fromCharCode(v)),v&&se<S;);if(512&w.flags&&(w.check=a(w.check,$,se,A)),S-=se,A+=se,v)break e}else w.head&&(w.head.name=null);w.length=0,w.mode=8;case 8:if(4096&w.flags){if(S===0)break e;for(se=0;v=$[A+se++],w.head&&v&&w.length<65536&&(w.head.comment+=String.fromCharCode(v)),v&&se<S;);if(512&w.flags&&(w.check=a(w.check,$,se,A)),S-=se,A+=se,v)break e}else w.head&&(w.head.comment=null);w.mode=9;case 9:if(512&w.flags){for(;F<16;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}if(O!==(65535&w.check)){D.msg="header crc mismatch",w.mode=30;break}F=O=0}w.head&&(w.head.hcrc=w.flags>>9&1,w.head.done=!0),D.adler=w.check=0,w.mode=12;break;case 10:for(;F<32;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}D.adler=w.check=b(O),F=O=0,w.mode=11;case 11:if(w.havedict===0)return D.next_out=J,D.avail_out=U,D.next_in=A,D.avail_in=S,w.hold=O,w.bits=F,2;D.adler=w.check=1,w.mode=12;case 12:if(y===5||y===6)break e;case 13:if(w.last){O>>>=7&F,F-=7&F,w.mode=27;break}for(;F<3;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}switch(w.last=1&O,F-=1,3&(O>>>=1)){case 0:w.mode=14;break;case 1:if(R(w),w.mode=20,y!==6)break;O>>>=2,F-=2;break e;case 2:w.mode=17;break;case 3:D.msg="invalid block type",w.mode=30}O>>>=2,F-=2;break;case 14:for(O>>>=7&F,F-=7&F;F<32;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}if((65535&O)!=(O>>>16^65535)){D.msg="invalid stored block lengths",w.mode=30;break}if(w.length=65535&O,F=O=0,w.mode=15,y===6)break e;case 15:w.mode=16;case 16:if(se=w.length){if(S<se&&(se=S),U<se&&(se=U),se===0)break e;s.arraySet(P,$,A,se,J),S-=se,A+=se,U-=se,J+=se,w.length-=se;break}w.mode=12;break;case 17:for(;F<14;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}if(w.nlen=257+(31&O),O>>>=5,F-=5,w.ndist=1+(31&O),O>>>=5,F-=5,w.ncode=4+(15&O),O>>>=4,F-=4,286<w.nlen||30<w.ndist){D.msg="too many length or distance symbols",w.mode=30;break}w.have=0,w.mode=18;case 18:for(;w.have<w.ncode;){for(;F<3;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}w.lens[Y[w.have++]]=7&O,O>>>=3,F-=3}for(;w.have<19;)w.lens[Y[w.have++]]=0;if(w.lencode=w.lendyn,w.lenbits=7,L={bits:w.lenbits},V=l(0,w.lens,0,19,w.lencode,0,w.work,L),w.lenbits=L.bits,V){D.msg="invalid code lengths set",w.mode=30;break}w.have=0,w.mode=19;case 19:for(;w.have<w.nlen+w.ndist;){for(;ye=(z=w.lencode[O&(1<<w.lenbits)-1])>>>16&255,ve=65535&z,!((Oe=z>>>24)<=F);){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}if(ve<16)O>>>=Oe,F-=Oe,w.lens[w.have++]=ve;else{if(ve===16){for(B=Oe+2;F<B;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}if(O>>>=Oe,F-=Oe,w.have===0){D.msg="invalid bit length repeat",w.mode=30;break}v=w.lens[w.have-1],se=3+(3&O),O>>>=2,F-=2}else if(ve===17){for(B=Oe+3;F<B;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}F-=Oe,v=0,se=3+(7&(O>>>=Oe)),O>>>=3,F-=3}else{for(B=Oe+7;F<B;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}F-=Oe,v=0,se=11+(127&(O>>>=Oe)),O>>>=7,F-=7}if(w.have+se>w.nlen+w.ndist){D.msg="invalid bit length repeat",w.mode=30;break}for(;se--;)w.lens[w.have++]=v}}if(w.mode===30)break;if(w.lens[256]===0){D.msg="invalid code -- missing end-of-block",w.mode=30;break}if(w.lenbits=9,L={bits:w.lenbits},V=l(f,w.lens,0,w.nlen,w.lencode,0,w.work,L),w.lenbits=L.bits,V){D.msg="invalid literal/lengths set",w.mode=30;break}if(w.distbits=6,w.distcode=w.distdyn,L={bits:w.distbits},V=l(u,w.lens,w.nlen,w.ndist,w.distcode,0,w.work,L),w.distbits=L.bits,V){D.msg="invalid distances set",w.mode=30;break}if(w.mode=20,y===6)break e;case 20:w.mode=21;case 21:if(6<=S&&258<=U){D.next_out=J,D.avail_out=U,D.next_in=A,D.avail_in=S,w.hold=O,w.bits=F,c(D,ie),J=D.next_out,P=D.output,U=D.avail_out,A=D.next_in,$=D.input,S=D.avail_in,O=w.hold,F=w.bits,w.mode===12&&(w.back=-1);break}for(w.back=0;ye=(z=w.lencode[O&(1<<w.lenbits)-1])>>>16&255,ve=65535&z,!((Oe=z>>>24)<=F);){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}if(ye&&(240&ye)==0){for(me=Oe,_e=ye,xe=ve;ye=(z=w.lencode[xe+((O&(1<<me+_e)-1)>>me)])>>>16&255,ve=65535&z,!(me+(Oe=z>>>24)<=F);){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}O>>>=me,F-=me,w.back+=me}if(O>>>=Oe,F-=Oe,w.back+=Oe,w.length=ve,ye===0){w.mode=26;break}if(32&ye){w.back=-1,w.mode=12;break}if(64&ye){D.msg="invalid literal/length code",w.mode=30;break}w.extra=15&ye,w.mode=22;case 22:if(w.extra){for(B=w.extra;F<B;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}w.length+=O&(1<<w.extra)-1,O>>>=w.extra,F-=w.extra,w.back+=w.extra}w.was=w.length,w.mode=23;case 23:for(;ye=(z=w.distcode[O&(1<<w.distbits)-1])>>>16&255,ve=65535&z,!((Oe=z>>>24)<=F);){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}if((240&ye)==0){for(me=Oe,_e=ye,xe=ve;ye=(z=w.distcode[xe+((O&(1<<me+_e)-1)>>me)])>>>16&255,ve=65535&z,!(me+(Oe=z>>>24)<=F);){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}O>>>=me,F-=me,w.back+=me}if(O>>>=Oe,F-=Oe,w.back+=Oe,64&ye){D.msg="invalid distance code",w.mode=30;break}w.offset=ve,w.extra=15&ye,w.mode=24;case 24:if(w.extra){for(B=w.extra;F<B;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}w.offset+=O&(1<<w.extra)-1,O>>>=w.extra,F-=w.extra,w.back+=w.extra}if(w.offset>w.dmax){D.msg="invalid distance too far back",w.mode=30;break}w.mode=25;case 25:if(U===0)break e;if(se=ie-U,w.offset>se){if((se=w.offset-se)>w.whave&&w.sane){D.msg="invalid distance too far back",w.mode=30;break}$e=se>w.wnext?(se-=w.wnext,w.wsize-se):w.wnext-se,se>w.length&&(se=w.length),Ce=w.window}else Ce=P,$e=J-w.offset,se=w.length;for(U<se&&(se=U),U-=se,w.length-=se;P[J++]=Ce[$e++],--se;);w.length===0&&(w.mode=21);break;case 26:if(U===0)break e;P[J++]=w.length,U--,w.mode=21;break;case 27:if(w.wrap){for(;F<32;){if(S===0)break e;S--,O|=$[A++]<<F,F+=8}if(ie-=U,D.total_out+=ie,w.total+=ie,ie&&(D.adler=w.check=w.flags?a(w.check,P,ie,J-ie):o(w.check,P,ie,J-ie)),ie=U,(w.flags?O:b(O))!==w.check){D.msg="incorrect data check",w.mode=30;break}F=O=0}w.mode=28;case 28:if(w.wrap&&w.flags){for(;F<32;){if(S===0)break e;S--,O+=$[A++]<<F,F+=8}if(O!==(0xffffffff&w.total)){D.msg="incorrect length check",w.mode=30;break}F=O=0}w.mode=29;case 29:V=1;break e;case 30:V=-3;break e;case 31:return-4;case 32:default:return d}return D.next_out=J,D.avail_out=U,D.next_in=A,D.avail_in=S,w.hold=O,w.bits=F,(w.wsize||ie!==D.avail_out&&w.mode<30&&(w.mode<27||y!==4))&&N(D,D.output,D.next_out,ie-D.avail_out)?(w.mode=31,-4):(X-=D.avail_in,ie-=D.avail_out,D.total_in+=X,D.total_out+=ie,w.total+=ie,w.wrap&&ie&&(D.adler=w.check=w.flags?a(w.check,P,ie,D.next_out-ie):o(w.check,P,ie,D.next_out-ie)),D.data_type=w.bits+(w.last?64:0)+(w.mode===12?128:0)+(w.mode===20||w.mode===15?256:0),(X==0&&ie===0||y===4)&&V===h&&(V=-5),V)},i.inflateEnd=function(D){if(!D||!D.state)return d;var y=D.state;return y.window&&(y.window=null),D.state=null,h},i.inflateGetHeader=function(D,y){var w;return D&&D.state?(2&(w=D.state).wrap)==0?d:((w.head=y).done=!1,h):d},i.inflateSetDictionary=function(D,y){var w,$=y.length;return D&&D.state?(w=D.state).wrap!==0&&w.mode!==11?d:w.mode===11&&o(1,y,$,0)!==w.check?-3:N(D,y,$,$)?(w.mode=31,-4):(w.havedict=1,h):d},i.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./inffast":48,"./inftrees":50}],50:[function(n,r,i){var s=n("../utils/common"),o=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],a=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],c=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],l=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];r.exports=function(f,u,h,d,g,p,m,b){var x,_,E,k,C,T,j,I,R,N=b.bits,D=0,y=0,w=0,$=0,P=0,A=0,J=0,S=0,U=0,O=0,F=null,X=0,ie=new s.Buf16(16),se=new s.Buf16(16),$e=null,Ce=0;for(D=0;D<=15;D++)ie[D]=0;for(y=0;y<d;y++)ie[u[h+y]]++;for(P=N,$=15;1<=$&&ie[$]===0;$--);if($<P&&(P=$),$===0)return g[p++]=0x1400000,g[p++]=0x1400000,b.bits=1,0;for(w=1;w<$&&ie[w]===0;w++);for(P<w&&(P=w),D=S=1;D<=15;D++)if(S<<=1,(S-=ie[D])<0)return-1;if(0<S&&(f===0||$!==1))return-1;for(se[1]=0,D=1;D<15;D++)se[D+1]=se[D]+ie[D];for(y=0;y<d;y++)u[h+y]!==0&&(m[se[u[h+y]]++]=y);if(T=f===0?(F=$e=m,19):f===1?(F=o,X-=257,$e=a,Ce-=257,256):(F=c,$e=l,-1),D=w,C=p,J=y=O=0,E=-1,k=(U=1<<(A=P))-1,f===1&&852<U||f===2&&592<U)return 1;for(;;){for(j=D-J,R=m[y]<T?(I=0,m[y]):m[y]>T?(I=$e[Ce+m[y]],F[X+m[y]]):(I=96,0),x=1<<D-J,w=_=1<<A;g[C+(O>>J)+(_-=x)]=j<<24|I<<16|R|0,_!==0;);for(x=1<<D-1;O&x;)x>>=1;if(x!==0?(O&=x-1,O+=x):O=0,y++,--ie[D]==0){if(D===$)break;D=u[h+m[y]]}if(P<D&&(O&k)!==E){for(J===0&&(J=P),C+=w,S=1<<(A=D-J);A+J<$&&!((S-=ie[A+J])<=0);)A++,S<<=1;if(U+=1<<A,f===1&&852<U||f===2&&592<U)return 1;g[E=O&k]=P<<24|A<<16|C-p|0}}return O!==0&&(g[C+O]=D-J<<24|64<<16|0),b.bits=P,0}},{"../utils/common":41}],51:[function(n,r,i){r.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],52:[function(n,r,i){var s=n("../utils/common"),o=0,a=1;function c(z){for(var H=z.length;0<=--H;)z[H]=0}var l=0,f=29,u=256,h=u+1+f,d=30,g=19,p=2*h+1,m=15,b=16,x=7,_=256,E=16,k=17,C=18,T=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],j=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],I=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],R=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],N=new Array(2*(h+2));c(N);var D=new Array(2*d);c(D);var y=new Array(512);c(y);var w=new Array(256);c(w);var $=new Array(f);c($);var P,A,J,S=new Array(d);function U(z,H,Y,oe,M){this.static_tree=z,this.extra_bits=H,this.extra_base=Y,this.elems=oe,this.max_length=M,this.has_stree=z&&z.length}function O(z,H){this.dyn_tree=z,this.max_code=0,this.stat_desc=H}function F(z){return z<256?y[z]:y[256+(z>>>7)]}function X(z,H){z.pending_buf[z.pending++]=255&H,z.pending_buf[z.pending++]=H>>>8&255}function ie(z,H,Y){z.bi_valid>b-Y?(z.bi_buf|=H<<z.bi_valid&65535,X(z,z.bi_buf),z.bi_buf=H>>b-z.bi_valid,z.bi_valid+=Y-b):(z.bi_buf|=H<<z.bi_valid&65535,z.bi_valid+=Y)}function se(z,H,Y){ie(z,Y[2*H],Y[2*H+1])}function $e(z,H){for(var Y=0;Y|=1&z,z>>>=1,Y<<=1,0<--H;);return Y>>>1}function Ce(z,H,Y){var oe,M,te=new Array(m+1),ge=0;for(oe=1;oe<=m;oe++)te[oe]=ge=ge+Y[oe-1]<<1;for(M=0;M<=H;M++){var de=z[2*M+1];de!==0&&(z[2*M]=$e(te[de]++,de))}}function Oe(z){var H;for(H=0;H<h;H++)z.dyn_ltree[2*H]=0;for(H=0;H<d;H++)z.dyn_dtree[2*H]=0;for(H=0;H<g;H++)z.bl_tree[2*H]=0;z.dyn_ltree[2*_]=1,z.opt_len=z.static_len=0,z.last_lit=z.matches=0}function ye(z){8<z.bi_valid?X(z,z.bi_buf):0<z.bi_valid&&(z.pending_buf[z.pending++]=z.bi_buf),z.bi_buf=0,z.bi_valid=0}function ve(z,H,Y,oe){var M=2*H,te=2*Y;return z[M]<z[te]||z[M]===z[te]&&oe[H]<=oe[Y]}function me(z,H,Y){for(var oe=z.heap[Y],M=Y<<1;M<=z.heap_len&&(M<z.heap_len&&ve(H,z.heap[M+1],z.heap[M],z.depth)&&M++,!ve(H,oe,z.heap[M],z.depth));)z.heap[Y]=z.heap[M],Y=M,M<<=1;z.heap[Y]=oe}function _e(z,H,Y){var oe,M,te,ge,de=0;if(z.last_lit!==0)for(;oe=z.pending_buf[z.d_buf+2*de]<<8|z.pending_buf[z.d_buf+2*de+1],M=z.pending_buf[z.l_buf+de],de++,oe===0?se(z,M,H):(se(z,(te=w[M])+u+1,H),(ge=T[te])!==0&&ie(z,M-=$[te],ge),se(z,te=F(--oe),Y),(ge=j[te])!==0&&ie(z,oe-=S[te],ge)),de<z.last_lit;);se(z,_,H)}function xe(z,H){var Y,oe,M,te=H.dyn_tree,ge=H.stat_desc.static_tree,de=H.stat_desc.has_stree,Se=H.stat_desc.elems,Pe=-1;for(z.heap_len=0,z.heap_max=p,Y=0;Y<Se;Y++)te[2*Y]!==0?(z.heap[++z.heap_len]=Pe=Y,z.depth[Y]=0):te[2*Y+1]=0;for(;z.heap_len<2;)te[2*(M=z.heap[++z.heap_len]=Pe<2?++Pe:0)]=1,z.depth[M]=0,z.opt_len--,de&&(z.static_len-=ge[2*M+1]);for(H.max_code=Pe,Y=z.heap_len>>1;1<=Y;Y--)me(z,te,Y);for(M=Se;Y=z.heap[1],z.heap[1]=z.heap[z.heap_len--],me(z,te,1),oe=z.heap[1],z.heap[--z.heap_max]=Y,z.heap[--z.heap_max]=oe,te[2*M]=te[2*Y]+te[2*oe],z.depth[M]=(z.depth[Y]>=z.depth[oe]?z.depth[Y]:z.depth[oe])+1,te[2*Y+1]=te[2*oe+1]=M,z.heap[1]=M++,me(z,te,1),2<=z.heap_len;);z.heap[--z.heap_max]=z.heap[1],(function(Te,ke){var Ue,Qe,be,Ee,Ae,Ie,Ve=ke.dyn_tree,ot=ke.max_code,et=ke.stat_desc.static_tree,We=ke.stat_desc.has_stree,at=ke.stat_desc.extra_bits,Be=ke.stat_desc.extra_base,ce=ke.stat_desc.max_length,je=0;for(Ee=0;Ee<=m;Ee++)Te.bl_count[Ee]=0;for(Ve[2*Te.heap[Te.heap_max]+1]=0,Ue=Te.heap_max+1;Ue<p;Ue++)ce<(Ee=Ve[2*Ve[2*(Qe=Te.heap[Ue])+1]+1]+1)&&(Ee=ce,je++),Ve[2*Qe+1]=Ee,ot<Qe||(Te.bl_count[Ee]++,Ae=0,Be<=Qe&&(Ae=at[Qe-Be]),Ie=Ve[2*Qe],Te.opt_len+=Ie*(Ee+Ae),We&&(Te.static_len+=Ie*(et[2*Qe+1]+Ae)));if(je!==0){do{for(Ee=ce-1;Te.bl_count[Ee]===0;)Ee--;Te.bl_count[Ee]--,Te.bl_count[Ee+1]+=2,Te.bl_count[ce]--,je-=2}while(0<je);for(Ee=ce;Ee!==0;Ee--)for(Qe=Te.bl_count[Ee];Qe!==0;)ot<(be=Te.heap[--Ue])||(Ve[2*be+1]!==Ee&&(Te.opt_len+=(Ee-Ve[2*be+1])*Ve[2*be],Ve[2*be+1]=Ee),Qe--)}})(z,H),Ce(te,Pe,z.bl_count)}function v(z,H,Y){var oe,M,te=-1,ge=H[1],de=0,Se=7,Pe=4;for(ge===0&&(Se=138,Pe=3),H[2*(Y+1)+1]=65535,oe=0;oe<=Y;oe++)M=ge,ge=H[2*(oe+1)+1],++de<Se&&M===ge||(de<Pe?z.bl_tree[2*M]+=de:M!==0?(M!==te&&z.bl_tree[2*M]++,z.bl_tree[2*E]++):de<=10?z.bl_tree[2*k]++:z.bl_tree[2*C]++,te=M,Pe=(de=0)===ge?(Se=138,3):M===ge?(Se=6,3):(Se=7,4))}function V(z,H,Y){var oe,M,te=-1,ge=H[1],de=0,Se=7,Pe=4;for(ge===0&&(Se=138,Pe=3),oe=0;oe<=Y;oe++)if(M=ge,ge=H[2*(oe+1)+1],!(++de<Se&&M===ge)){if(de<Pe)for(;se(z,M,z.bl_tree),--de!=0;);else M!==0?(M!==te&&(se(z,M,z.bl_tree),de--),se(z,E,z.bl_tree),ie(z,de-3,2)):de<=10?(se(z,k,z.bl_tree),ie(z,de-3,3)):(se(z,C,z.bl_tree),ie(z,de-11,7));te=M,Pe=(de=0)===ge?(Se=138,3):M===ge?(Se=6,3):(Se=7,4)}}c(S);var L=!1;function B(z,H,Y,oe){ie(z,(l<<1)+(oe?1:0),3),(function(M,te,ge,de){ye(M),X(M,ge),X(M,~ge),s.arraySet(M.pending_buf,M.window,te,ge,M.pending),M.pending+=ge})(z,H,Y)}i._tr_init=function(z){L||((function(){var H,Y,oe,M,te,ge=new Array(m+1);for(M=oe=0;M<f-1;M++)for($[M]=oe,H=0;H<1<<T[M];H++)w[oe++]=M;for(w[oe-1]=M,M=te=0;M<16;M++)for(S[M]=te,H=0;H<1<<j[M];H++)y[te++]=M;for(te>>=7;M<d;M++)for(S[M]=te<<7,H=0;H<1<<j[M]-7;H++)y[256+te++]=M;for(Y=0;Y<=m;Y++)ge[Y]=0;for(H=0;H<=143;)N[2*H+1]=8,H++,ge[8]++;for(;H<=255;)N[2*H+1]=9,H++,ge[9]++;for(;H<=279;)N[2*H+1]=7,H++,ge[7]++;for(;H<=287;)N[2*H+1]=8,H++,ge[8]++;for(Ce(N,h+1,ge),H=0;H<d;H++)D[2*H+1]=5,D[2*H]=$e(H,5);P=new U(N,T,u+1,h,m),A=new U(D,j,0,d,m),J=new U(new Array(0),I,0,g,x)})(),L=!0),z.l_desc=new O(z.dyn_ltree,P),z.d_desc=new O(z.dyn_dtree,A),z.bl_desc=new O(z.bl_tree,J),z.bi_buf=0,z.bi_valid=0,Oe(z)},i._tr_stored_block=B,i._tr_flush_block=function(z,H,Y,oe){var M,te,ge=0;0<z.level?(z.strm.data_type===2&&(z.strm.data_type=(function(de){var Se,Pe=0xf3ffc07f;for(Se=0;Se<=31;Se++,Pe>>>=1)if(1&Pe&&de.dyn_ltree[2*Se]!==0)return o;if(de.dyn_ltree[18]!==0||de.dyn_ltree[20]!==0||de.dyn_ltree[26]!==0)return a;for(Se=32;Se<u;Se++)if(de.dyn_ltree[2*Se]!==0)return a;return o})(z)),xe(z,z.l_desc),xe(z,z.d_desc),ge=(function(de){var Se;for(v(de,de.dyn_ltree,de.l_desc.max_code),v(de,de.dyn_dtree,de.d_desc.max_code),xe(de,de.bl_desc),Se=g-1;3<=Se&&de.bl_tree[2*R[Se]+1]===0;Se--);return de.opt_len+=3*(Se+1)+5+5+4,Se})(z),M=z.opt_len+3+7>>>3,(te=z.static_len+3+7>>>3)<=M&&(M=te)):M=te=Y+5,Y+4<=M&&H!==-1?B(z,H,Y,oe):z.strategy===4||te===M?(ie(z,2+(oe?1:0),3),_e(z,N,D)):(ie(z,4+(oe?1:0),3),(function(de,Se,Pe,Te){var ke;for(ie(de,Se-257,5),ie(de,Pe-1,5),ie(de,Te-4,4),ke=0;ke<Te;ke++)ie(de,de.bl_tree[2*R[ke]+1],3);V(de,de.dyn_ltree,Se-1),V(de,de.dyn_dtree,Pe-1)})(z,z.l_desc.max_code+1,z.d_desc.max_code+1,ge+1),_e(z,z.dyn_ltree,z.dyn_dtree)),Oe(z),oe&&ye(z)},i._tr_tally=function(z,H,Y){return z.pending_buf[z.d_buf+2*z.last_lit]=H>>>8&255,z.pending_buf[z.d_buf+2*z.last_lit+1]=255&H,z.pending_buf[z.l_buf+z.last_lit]=255&Y,z.last_lit++,H===0?z.dyn_ltree[2*Y]++:(z.matches++,H--,z.dyn_ltree[2*(w[Y]+u+1)]++,z.dyn_dtree[2*F(H)]++),z.last_lit===z.lit_bufsize-1},i._tr_align=function(z){ie(z,2,3),se(z,_,N),(function(H){H.bi_valid===16?(X(H,H.bi_buf),H.bi_buf=0,H.bi_valid=0):8<=H.bi_valid&&(H.pending_buf[H.pending++]=255&H.bi_buf,H.bi_buf>>=8,H.bi_valid-=8)})(z)}},{"../utils/common":41}],53:[function(n,r,i){r.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(n,r,i){(function(s){(function(o,a){if(!o.setImmediate){var c,l,f,u,h=1,d={},g=!1,p=o.document,m=Object.getPrototypeOf&&Object.getPrototypeOf(o);m=m&&m.setTimeout?m:o,c={}.toString.call(o.process)==="[object process]"?function(E){process.nextTick(function(){x(E)})}:(function(){if(o.postMessage&&!o.importScripts){var E=!0,k=o.onmessage;return o.onmessage=function(){E=!1},o.postMessage("","*"),o.onmessage=k,E}})()?(u="setImmediate$"+Math.random()+"$",o.addEventListener?o.addEventListener("message",_,!1):o.attachEvent("onmessage",_),function(E){o.postMessage(u+E,"*")}):o.MessageChannel?((f=new MessageChannel).port1.onmessage=function(E){x(E.data)},function(E){f.port2.postMessage(E)}):p&&"onreadystatechange"in p.createElement("script")?(l=p.documentElement,function(E){var k=p.createElement("script");k.onreadystatechange=function(){x(E),k.onreadystatechange=null,l.removeChild(k),k=null},l.appendChild(k)}):function(E){setTimeout(x,0,E)},m.setImmediate=function(E){typeof E!="function"&&(E=new Function(""+E));for(var k=new Array(arguments.length-1),C=0;C<k.length;C++)k[C]=arguments[C+1];var T={callback:E,args:k};return d[h]=T,c(h),h++},m.clearImmediate=b}function b(E){delete d[E]}function x(E){if(g)setTimeout(x,0,E);else{var k=d[E];if(k){g=!0;try{(function(C){var T=C.callback,j=C.args;switch(j.length){case 0:T();break;case 1:T(j[0]);break;case 2:T(j[0],j[1]);break;case 3:T(j[0],j[1],j[2]);break;default:T.apply(a,j)}})(k)}finally{b(E),g=!1}}}}function _(E){E.source===o&&typeof E.data=="string"&&E.data.indexOf(u)===0&&x(+E.data.slice(u.length))}})(typeof self>"u"?s===void 0?this:s:self)}).call(this,typeof na<"u"?na:typeof self<"u"?self:typeof window<"u"?window:{})},{}]},{},[10])(10)})})(cu)),cu.exports}var NO=LO();const HO=Ts(NO);var ir=Uint8Array,Ky=Uint16Array,ZO=Int32Array,VO=new ir([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),WO=new ir([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Gy=function(e,t){for(var n=new Ky(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new ZO(n[30]),r=1;r<30;++r)for(var s=n[r];s<n[r+1];++s)i[s]=s-n[r]<<5|r;return{b:n,r:i}},Yy=Gy(VO,2),qO=Yy.b,JO=Yy.r;qO[28]=258,JO[258]=28;Gy(WO,0);var KO=new Ky(32768);for(var St=0;St<32768;++St){var Vr=(St&43690)>>1|(St&21845)<<1;Vr=(Vr&52428)>>2|(Vr&13107)<<2,Vr=(Vr&61680)>>4|(Vr&3855)<<4,KO[St]=((Vr&65280)>>8|(Vr&255)<<8)>>1}var il=new ir(288);for(var St=0;St<144;++St)il[St]=8;for(var St=144;St<256;++St)il[St]=9;for(var St=256;St<280;++St)il[St]=7;for(var St=280;St<288;++St)il[St]=8;var GO=new ir(32);for(var St=0;St<32;++St)GO[St]=5;var YO=function(e,t,n){return(n==null||n>e.length)&&(n=e.length),new ir(e.subarray(t,n))},XO=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],ti=function(e,t,n){var r=new Error(t||XO[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,ti),!n)throw r;return r},QO=new ir(0),eP=(function(){for(var e=new Int32Array(256),t=0;t<256;++t){for(var n=t,r=9;--r;)n=(n&1&&-0x12477ce0)^n>>>1;e[t]=n}return e})(),tP=function(){var e=-1;return{p:function(t){for(var n=e,r=0;r<t.length;++r)n=eP[n&255^t[r]]^n>>>8;e=n},d:function(){return~e}}},nP=function(e,t){var n={};for(var r in e)n[r]=e[r];for(var r in t)n[r]=t[r];return n},Ut=function(e,t,n){for(;n;++t)e[t]=n,n>>>=8},q0=typeof TextEncoder<"u"&&new TextEncoder,rP=typeof TextDecoder<"u"&&new TextDecoder,iP=0;try{rP.decode(QO,{stream:!0}),iP=1}catch{}function J0(e,t){var n;if(q0)return q0.encode(e);for(var r=e.length,i=new ir(e.length+(e.length>>1)),s=0,o=function(l){i[s++]=l},n=0;n<r;++n){if(s+5>i.length){var a=new ir(s+8+(r-n<<1));a.set(i),i=a}var c=e.charCodeAt(n);c<128||t?o(c):c<2048?(o(192|c>>6),o(128|c&63)):c>55295&&c<57344?(c=65536+(c&1047552)|e.charCodeAt(++n)&1023,o(240|c>>18),o(128|c>>12&63),o(128|c>>6&63),o(128|c&63)):(o(224|c>>12),o(128|c>>6&63),o(128|c&63))}return YO(i,0,s)}var Ja=function(e){var t=0;if(e)for(var n in e){var r=e[n].length;r>65535&&ti(9),t+=r+4}return t},K0=function(e,t,n,r,i,s,o,a){var c=r.length,l=n.extra,f=a&&a.length,u=Ja(l);Ut(e,t,o!=null?0x2014b50:0x4034b50),t+=4,o!=null&&(e[t++]=20,e[t++]=n.os),e[t]=20,t+=2,e[t++]=n.flag<<1|(s<0&&8),e[t++]=i&&8,e[t++]=n.compression&255,e[t++]=n.compression>>8;var h=new Date(n.mtime==null?Date.now():n.mtime),d=h.getFullYear()-1980;if((d<0||d>119)&&ti(10),Ut(e,t,d<<25|h.getMonth()+1<<21|h.getDate()<<16|h.getHours()<<11|h.getMinutes()<<5|h.getSeconds()>>1),t+=4,s!=-1&&(Ut(e,t,n.crc),Ut(e,t+4,s<0?-s-2:s),Ut(e,t+8,n.size)),Ut(e,t+12,c),Ut(e,t+14,u),t+=16,o!=null&&(Ut(e,t,f),Ut(e,t+6,n.attrs),Ut(e,t+10,o),t+=14),e.set(r,t),t+=c,u)for(var g in l){var p=l[g],m=p.length;Ut(e,t,+g),Ut(e,t+2,m),e.set(p,t+4),t+=4+m}return f&&(e.set(a,t),t+=f),t},sP=function(e,t,n,r,i){Ut(e,t,0x6054b50),Ut(e,t+8,n),Ut(e,t+10,n),Ut(e,t+12,r),Ut(e,t+16,i)},G0=(function(){function e(t){this.filename=t,this.c=tP(),this.size=0,this.compression=0}return e.prototype.process=function(t,n){this.ondata(null,t,n)},e.prototype.push=function(t,n){this.ondata||ti(5),this.c.p(t),this.size+=t.length,n&&(this.crc=this.c.d()),this.process(t,n||!1)},e})(),Y0=(function(){function e(t){this.ondata=t,this.u=[],this.d=1}return e.prototype.add=function(t){var n=this;if(this.ondata||ti(5),this.d&2)this.ondata(ti(4+(this.d&1)*8,0,1),null,!1);else{var r=J0(t.filename),i=r.length,s=t.comment,o=s&&J0(s),a=i!=t.filename.length||o&&s.length!=o.length,c=i+Ja(t.extra)+30;i>65535&&this.ondata(ti(11,0,1),null,!1);var l=new ir(c);K0(l,0,t,r,a,-1);var f=[l],u=function(){for(var m=0,b=f;m<b.length;m++){var x=b[m];n.ondata(null,x,!1)}f=[]},h=this.d;this.d=0;var d=this.u.length,g=nP(t,{f:r,u:a,o,t:function(){t.terminate&&t.terminate()},r:function(){if(u(),h){var m=n.u[d+1];m?m.r():n.d=1}h=1}}),p=0;t.ondata=function(m,b,x){if(m)n.ondata(m,b,x),n.terminate();else if(p+=b.length,f.push(b),x){var _=new ir(16);Ut(_,0,0x8074b50),Ut(_,4,t.crc),Ut(_,8,p),Ut(_,12,t.size),f.push(_),g.c=p,g.b=c+p+16,g.crc=t.crc,g.size=t.size,h&&g.r(),h=1}else h&&u()},this.u.push(g)}},e.prototype.end=function(){var t=this;if(this.d&2){this.ondata(ti(4+(this.d&1)*8,0,1),null,!0);return}this.d?this.e():this.u.push({r:function(){t.d&1&&(t.u.splice(-1,1),t.e())},t:function(){}}),this.d=3},e.prototype.e=function(){for(var t=0,n=0,r=0,i=0,s=this.u;i<s.length;i++){var o=s[i];r+=46+o.f.length+Ja(o.extra)+(o.o?o.o.length:0)}for(var a=new ir(r+22),c=0,l=this.u;c<l.length;c++){var o=l[c];K0(a,t,o,o.f,o.u,-o.c-2,n,o.o),t+=46+o.f.length+Ja(o.extra)+(o.o?o.o.length:0),n+=o.b}sP(a,t,this.u.length,r,n),this.ondata(null,a,!0),this.d=2},e.prototype.terminate=function(){for(var t=0,n=this.u;t<n.length;t++){var r=n[t];r.t()}this.d=2},e})();function X0(e){return e.replace(/[<>:"/\\|?*\x00-\x1f]/g,"_").replace(/\s+/g,"_").substring(0,200)}function oP(e){return e.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").toLowerCase().substring(0,100)}function lu(e){return{"audio/mpeg":".mp3","audio/mp4":".m4a","audio/wav":".wav","audio/flac":".flac","audio/ogg":".ogg","audio/webm":".webm","image/jpeg":".jpg","image/png":".png","image/gif":".gif","image/webp":".webp"}[e]??".bin"}function aP(e,t){let n=`#EXTM3U
|
|
46
|
+
`;n+=`# Playlist: ${e.title}
|
|
47
|
+
`,n+=`# PlaylistId: ${e.id}
|
|
48
|
+
`,n+=`# PlaylistRev: ${e.rev??0}
|
|
49
|
+
`,e.description&&(n+=`# Description: ${e.description}
|
|
50
|
+
`),e.imagePath&&(n+=`# PlaylistImage: ${e.imagePath}
|
|
51
|
+
`),n+=`
|
|
52
|
+
`;for(const r of t){const i=Math.round(r.duration);n+=`#EXTINF:${i}, ${r.artist} - ${r.title}
|
|
53
|
+
`,n+=`# Title: ${r.title}
|
|
54
|
+
`,n+=`# Artist: ${r.artist}
|
|
55
|
+
`,n+=`# Album: ${r.album}
|
|
56
|
+
`,r.imagePath&&(n+=`# Image: ${r.imagePath}
|
|
57
|
+
`),n+=`${r.audioPath}
|
|
58
|
+
|
|
59
|
+
`}return n}var Q0;function fe(e,t,n){function r(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:o,traits:new Set},enumerable:!1}),a._zod.traits.has(e))return;a._zod.traits.add(e),t(a,c);const l=o.prototype,f=Object.keys(l);for(let u=0;u<f.length;u++){const h=f[u];h in a||(a[h]=l[h].bind(a))}}const i=n?.Parent??Object;class s extends i{}Object.defineProperty(s,"name",{value:e});function o(a){var c;const l=n?.Parent?new s:this;r(l,a),(c=l._zod).deferred??(c.deferred=[]);for(const f of l._zod.deferred)f();return l}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:a=>n?.Parent&&a instanceof n.Parent?!0:a?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}class ys extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Xy extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}(Q0=globalThis).__zod_globalConfig??(Q0.__zod_globalConfig={});const Yf=globalThis.__zod_globalConfig;function Fi(e){return Yf}function Qy(e){const t=Object.values(e).filter(r=>typeof r=="number");return Object.entries(e).filter(([r,i])=>t.indexOf(+r)===-1).map(([r,i])=>i)}function Id(e,t){return typeof t=="bigint"?t.toString():t}function Xf(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function Qf(e){return e==null}function eh(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function cP(e,t){const n=e/t,r=Math.round(n),i=Number.EPSILON*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}const ep=Symbol("evaluating");function gt(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==ep)return r===void 0&&(r=ep,r=n()),r},set(i){Object.defineProperty(e,t,{value:i})},configurable:!0})}function Vi(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function pi(...e){const t={};for(const n of e){const r=Object.getOwnPropertyDescriptors(n);Object.assign(t,r)}return Object.defineProperties({},t)}function tp(e){return JSON.stringify(e)}function lP(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const eb="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function kc(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const uP=Xf(()=>{if(Yf.jitless||typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function Mo(e){if(kc(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(kc(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function tb(e){return Mo(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const dP=new Set(["string","number","symbol"]);function sl(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function mi(e,t,n){const r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function He(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function fP(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const hP={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-0x80000000,0x7fffffff],uint32:[0,0xffffffff],float32:[-3402823466385289e23,3402823466385289e23],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function gP(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const s=pi(e._zod.def,{get shape(){const o={};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&(o[a]=n.shape[a])}return Vi(this,"shape",o),o},checks:[]});return mi(e,s)}function pP(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const s=pi(e._zod.def,{get shape(){const o={...e._zod.def.shape};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&delete o[a]}return Vi(this,"shape",o),o},checks:[]});return mi(e,s)}function mP(e,t){if(!Mo(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const s=e._zod.def.shape;for(const o in t)if(Object.getOwnPropertyDescriptor(s,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const i=pi(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t};return Vi(this,"shape",s),s}});return mi(e,i)}function _P(e,t){if(!Mo(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=pi(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t};return Vi(this,"shape",r),r}});return mi(e,n)}function yP(e,t){if(e._zod.def.checks?.length)throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");const n=pi(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t._zod.def.shape};return Vi(this,"shape",r),r},get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return mi(e,n)}function bP(e,t,n){const i=t._zod.def.checks;if(i&&i.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=pi(t._zod.def,{get shape(){const a=t._zod.def.shape,c={...a};if(n)for(const l in n){if(!(l in a))throw new Error(`Unrecognized key: "${l}"`);n[l]&&(c[l]=e?new e({type:"optional",innerType:a[l]}):a[l])}else for(const l in a)c[l]=e?new e({type:"optional",innerType:a[l]}):a[l];return Vi(this,"shape",c),c},checks:[]});return mi(t,o)}function wP(e,t,n){const r=pi(t._zod.def,{get shape(){const i=t._zod.def.shape,s={...i};if(n)for(const o in n){if(!(o in s))throw new Error(`Unrecognized key: "${o}"`);n[o]&&(s[o]=new e({type:"nonoptional",innerType:i[o]}))}else for(const o in i)s[o]=new e({type:"nonoptional",innerType:i[o]});return Vi(this,"shape",s),s}});return mi(t,r)}function gs(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function vP(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function nb(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function Sa(e){return typeof e=="string"?e:e?.message}function Bi(e,t,n){const r=e.message?e.message:Sa(e.inst?._zod.def?.error?.(e))??Sa(t?.error?.(e))??Sa(n.customError?.(e))??Sa(n.localeError?.(e))??"Invalid input",{inst:i,continue:s,input:o,...a}=e;return a.path??(a.path=[]),a.message=r,t?.reportInput&&(a.input=o),a}function th(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function Lo(...e){const[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}const rb=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,Id,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},ib=fe("$ZodError",rb),sb=fe("$ZodError",rb,{Parent:Error});function xP(e,t=n=>n.message){const n={},r=[];for(const i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function SP(e,t=n=>n.message){const n={_errors:[]},r=(i,s=[])=>{for(const o of i.issues)if(o.code==="invalid_union"&&o.errors.length)o.errors.map(a=>r({issues:a},[...s,...o.path]));else if(o.code==="invalid_key")r({issues:o.issues},[...s,...o.path]);else if(o.code==="invalid_element")r({issues:o.issues},[...s,...o.path]);else{const a=[...s,...o.path];if(a.length===0)n._errors.push(t(o));else{let c=n,l=0;for(;l<a.length;){const f=a[l];l===a.length-1?(c[f]=c[f]||{_errors:[]},c[f]._errors.push(t(o))):c[f]=c[f]||{_errors:[]},c=c[f],l++}}}};return r(e),n}const nh=e=>(t,n,r,i)=>{const s=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},s);if(o instanceof Promise)throw new ys;if(o.issues.length){const a=new(i?.Err??e)(o.issues.map(c=>Bi(c,s,Fi())));throw eb(a,i?.callee),a}return o.value},rh=e=>async(t,n,r,i)=>{const s=r?{...r,async:!0}:{async:!0};let o=t._zod.run({value:n,issues:[]},s);if(o instanceof Promise&&(o=await o),o.issues.length){const a=new(i?.Err??e)(o.issues.map(c=>Bi(c,s,Fi())));throw eb(a,i?.callee),a}return o.value},ol=e=>(t,n,r)=>{const i=r?{...r,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw new ys;return s.issues.length?{success:!1,error:new(e??ib)(s.issues.map(o=>Bi(o,i,Fi())))}:{success:!0,data:s.value}},$P=ol(sb),al=e=>async(t,n,r)=>{const i=r?{...r,async:!0}:{async:!0};let s=t._zod.run({value:n,issues:[]},i);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new e(s.issues.map(o=>Bi(o,i,Fi())))}:{success:!0,data:s.value}},kP=al(sb),EP=e=>(t,n,r)=>{const i=r?{...r,direction:"backward"}:{direction:"backward"};return nh(e)(t,n,i)},AP=e=>(t,n,r)=>nh(e)(t,n,r),IP=e=>async(t,n,r)=>{const i=r?{...r,direction:"backward"}:{direction:"backward"};return rh(e)(t,n,i)},CP=e=>async(t,n,r)=>rh(e)(t,n,r),zP=e=>(t,n,r)=>{const i=r?{...r,direction:"backward"}:{direction:"backward"};return ol(e)(t,n,i)},OP=e=>(t,n,r)=>ol(e)(t,n,r),PP=e=>async(t,n,r)=>{const i=r?{...r,direction:"backward"}:{direction:"backward"};return al(e)(t,n,i)},TP=e=>async(t,n,r)=>al(e)(t,n,r),DP=/^[cC][0-9a-z]{6,}$/,RP=/^[0-9a-z]+$/,FP=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,BP=/^[0-9a-vA-V]{20}$/,UP=/^[A-Za-z0-9]{27}$/,jP=/^[a-zA-Z0-9_-]{21}$/,MP=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,LP=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,np=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,NP=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,HP="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function ZP(){return new RegExp(HP,"u")}const VP=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,WP=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,qP=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,JP=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,KP=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,ob=/^[A-Za-z0-9_-]*$/,GP=/^https?$/,YP=/^\+[1-9]\d{6,14}$/,ab="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",XP=new RegExp(`^${ab}$`);function cb(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function QP(e){return new RegExp(`^${cb(e)}$`)}function eT(e){const t=cb({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${ab}T(?:${r})$`)}const tT=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},nT=/^-?\d+$/,rT=/^-?\d+(?:\.\d+)?$/,iT=/^(?:true|false)$/i,sT=/^[^A-Z]*$/,oT=/^[^a-z]*$/,En=fe("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),lb={number:"number",bigint:"bigint",object:"date"},ub=fe("$ZodCheckLessThan",(e,t)=>{En.init(e,t);const n=lb[typeof t.value];e._zod.onattach.push(r=>{const i=r._zod.bag,s=(t.inclusive?i.maximum:i.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<s&&(t.inclusive?i.maximum=t.value:i.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),db=fe("$ZodCheckGreaterThan",(e,t)=>{En.init(e,t);const n=lb[typeof t.value];e._zod.onattach.push(r=>{const i=r._zod.bag,s=(t.inclusive?i.minimum:i.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>s&&(t.inclusive?i.minimum=t.value:i.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),aT=fe("$ZodCheckMultipleOf",(e,t)=>{En.init(e,t),e._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%t.value===BigInt(0):cP(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),cT=fe("$ZodCheckNumberFormat",(e,t)=>{En.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[i,s]=hP[t.format];e._zod.onattach.push(o=>{const a=o._zod.bag;a.format=t.format,a.minimum=i,a.maximum=s,n&&(a.pattern=nT)}),e._zod.check=o=>{const a=o.value;if(n){if(!Number.isInteger(a)){o.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:a,inst:e});return}if(!Number.isSafeInteger(a)){a>0?o.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}a<i&&o.issues.push({origin:"number",input:a,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),a>s&&o.issues.push({origin:"number",input:a,code:"too_big",maximum:s,inclusive:!0,inst:e,continue:!t.abort})}}),lT=fe("$ZodCheckMaxLength",(e,t)=>{var n;En.init(e,t),(n=e._zod.def).when??(n.when=r=>{const i=r.value;return!Qf(i)&&i.length!==void 0}),e._zod.onattach.push(r=>{const i=r._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<i&&(r._zod.bag.maximum=t.maximum)}),e._zod.check=r=>{const i=r.value;if(i.length<=t.maximum)return;const o=th(i);r.issues.push({origin:o,code:"too_big",maximum:t.maximum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),uT=fe("$ZodCheckMinLength",(e,t)=>{var n;En.init(e,t),(n=e._zod.def).when??(n.when=r=>{const i=r.value;return!Qf(i)&&i.length!==void 0}),e._zod.onattach.push(r=>{const i=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>i&&(r._zod.bag.minimum=t.minimum)}),e._zod.check=r=>{const i=r.value;if(i.length>=t.minimum)return;const o=th(i);r.issues.push({origin:o,code:"too_small",minimum:t.minimum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),dT=fe("$ZodCheckLengthEquals",(e,t)=>{var n;En.init(e,t),(n=e._zod.def).when??(n.when=r=>{const i=r.value;return!Qf(i)&&i.length!==void 0}),e._zod.onattach.push(r=>{const i=r._zod.bag;i.minimum=t.length,i.maximum=t.length,i.length=t.length}),e._zod.check=r=>{const i=r.value,s=i.length;if(s===t.length)return;const o=th(i),a=s>t.length;r.issues.push({origin:o,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),cl=fe("$ZodCheckStringFormat",(e,t)=>{var n,r;En.init(e,t),e._zod.onattach.push(i=>{const s=i._zod.bag;s.format=t.format,t.pattern&&(s.patterns??(s.patterns=new Set),s.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=i=>{t.pattern.lastIndex=0,!t.pattern.test(i.value)&&i.issues.push({origin:"string",code:"invalid_format",format:t.format,input:i.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),fT=fe("$ZodCheckRegex",(e,t)=>{cl.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),hT=fe("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=sT),cl.init(e,t)}),gT=fe("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=oT),cl.init(e,t)}),pT=fe("$ZodCheckIncludes",(e,t)=>{En.init(e,t);const n=sl(t.includes),r=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(i=>{const s=i._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(r)}),e._zod.check=i=>{i.value.includes(t.includes,t.position)||i.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:i.value,inst:e,continue:!t.abort})}}),mT=fe("$ZodCheckStartsWith",(e,t)=>{En.init(e,t);const n=new RegExp(`^${sl(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const i=r._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(n)}),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),_T=fe("$ZodCheckEndsWith",(e,t)=>{En.init(e,t);const n=new RegExp(`.*${sl(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const i=r._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(n)}),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),yT=fe("$ZodCheckOverwrite",(e,t)=>{En.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class bT{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const r=t.split(`
|
|
60
|
+
`).filter(o=>o),i=Math.min(...r.map(o=>o.length-o.trimStart().length)),s=r.map(o=>o.slice(i)).map(o=>" ".repeat(this.indent*2)+o);for(const o of s)this.content.push(o)}compile(){const t=Function,n=this?.args,i=[...(this?.content??[""]).map(s=>` ${s}`)];return new t(...n,i.join(`
|
|
61
|
+
`))}}const wT={major:4,minor:4,patch:3},Mt=fe("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=wT;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const i of r)for(const s of i._zod.onattach)s(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const i=(o,a,c)=>{let l=gs(o),f;for(const u of a){if(u._zod.def.when){if(vP(o)||!u._zod.def.when(o))continue}else if(l)continue;const h=o.issues.length,d=u._zod.check(o);if(d instanceof Promise&&c?.async===!1)throw new ys;if(f||d instanceof Promise)f=(f??Promise.resolve()).then(async()=>{await d,o.issues.length!==h&&(l||(l=gs(o,h)))});else{if(o.issues.length===h)continue;l||(l=gs(o,h))}}return f?f.then(()=>o):o},s=(o,a,c)=>{if(gs(o))return o.aborted=!0,o;const l=i(a,r,c);if(l instanceof Promise){if(c.async===!1)throw new ys;return l.then(f=>e._zod.parse(f,c))}return e._zod.parse(l,c)};e._zod.run=(o,a)=>{if(a.skipChecks)return e._zod.parse(o,a);if(a.direction==="backward"){const l=e._zod.parse({value:o.value,issues:[]},{...a,skipChecks:!0});return l instanceof Promise?l.then(f=>s(f,o,a)):s(l,o,a)}const c=e._zod.parse(o,a);if(c instanceof Promise){if(a.async===!1)throw new ys;return c.then(l=>i(l,r,a))}return i(c,r,a)}}gt(e,"~standard",()=>({validate:i=>{try{const s=$P(e,i);return s.success?{value:s.data}:{issues:s.error?.issues}}catch{return kP(e,i).then(o=>o.success?{value:o.data}:{issues:o.error?.issues})}},vendor:"zod",version:1}))}),ih=fe("$ZodString",(e,t)=>{Mt.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??tT(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),It=fe("$ZodStringFormat",(e,t)=>{cl.init(e,t),ih.init(e,t)}),vT=fe("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=LP),It.init(e,t)}),xT=fe("$ZodUUID",(e,t)=>{if(t.version){const r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(r===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=np(r))}else t.pattern??(t.pattern=np());It.init(e,t)}),ST=fe("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=NP),It.init(e,t)}),$T=fe("$ZodURL",(e,t)=>{It.init(e,t),e._zod.check=n=>{try{const r=n.value.trim();if(!t.normalize&&t.protocol?.source===GP.source&&!/^https?:\/\//i.test(r)){n.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:n.value,inst:e,continue:!t.abort});return}const i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(":")?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=i.href:n.value=r;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),kT=fe("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=ZP()),It.init(e,t)}),ET=fe("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=jP),It.init(e,t)}),AT=fe("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=DP),It.init(e,t)}),IT=fe("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=RP),It.init(e,t)}),CT=fe("$ZodULID",(e,t)=>{t.pattern??(t.pattern=FP),It.init(e,t)}),zT=fe("$ZodXID",(e,t)=>{t.pattern??(t.pattern=BP),It.init(e,t)}),OT=fe("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=UP),It.init(e,t)}),PT=fe("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=eT(t)),It.init(e,t)}),TT=fe("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=XP),It.init(e,t)}),DT=fe("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=QP(t)),It.init(e,t)}),RT=fe("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=MP),It.init(e,t)}),FT=fe("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=VP),It.init(e,t),e._zod.bag.format="ipv4"}),BT=fe("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=WP),It.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),UT=fe("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=qP),It.init(e,t)}),jT=fe("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=JP),It.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[i,s]=r;if(!s)throw new Error;const o=Number(s);if(`${o}`!==s)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${i}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function fb(e){if(e==="")return!0;if(/\s/.test(e)||e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const MT=fe("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=KP),It.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{fb(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function LT(e){if(!ob.test(e))return!1;const t=e.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return fb(n)}const NT=fe("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=ob),It.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{LT(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),HT=fe("$ZodE164",(e,t)=>{t.pattern??(t.pattern=YP),It.init(e,t)});function ZT(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[r]=n;if(!r)return!1;const i=JSON.parse(atob(r));return!("typ"in i&&i?.typ!=="JWT"||!i.alg||t&&(!("alg"in i)||i.alg!==t))}catch{return!1}}const VT=fe("$ZodJWT",(e,t)=>{It.init(e,t),e._zod.check=n=>{ZT(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),hb=fe("$ZodNumber",(e,t)=>{Mt.init(e,t),e._zod.pattern=e._zod.bag.pattern??rT,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const i=n.value;if(typeof i=="number"&&!Number.isNaN(i)&&Number.isFinite(i))return n;const s=typeof i=="number"?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...s?{received:s}:{}}),n}}),WT=fe("$ZodNumberFormat",(e,t)=>{cT.init(e,t),hb.init(e,t)}),qT=fe("$ZodBoolean",(e,t)=>{Mt.init(e,t),e._zod.pattern=iT,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}const i=n.value;return typeof i=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:e}),n}}),JT=fe("$ZodUnknown",(e,t)=>{Mt.init(e,t),e._zod.parse=n=>n}),KT=fe("$ZodNever",(e,t)=>{Mt.init(e,t),e._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function rp(e,t,n){e.issues.length&&t.issues.push(...nb(n,e.issues)),t.value[n]=e.value}const GT=fe("$ZodArray",(e,t)=>{Mt.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=Array(i.length);const s=[];for(let o=0;o<i.length;o++){const a=i[o],c=t.element._zod.run({value:a,issues:[]},r);c instanceof Promise?s.push(c.then(l=>rp(l,n,o))):rp(c,n,o)}return s.length?Promise.all(s).then(()=>n):n}});function Ec(e,t,n,r,i,s){const o=n in r;if(e.issues.length){if(i&&s&&!o)return;t.issues.push(...nb(n,e.issues))}if(!o&&!i){e.issues.length||t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[n]});return}e.value===void 0?o&&(t.value[n]=void 0):t.value[n]=e.value}function gb(e){const t=Object.keys(e.shape);for(const r of t)if(!e.shape?.[r]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${r}": expected a Zod schema`);const n=fP(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function pb(e,t,n,r,i,s){const o=[],a=i.keySet,c=i.catchall._zod,l=c.def.type,f=c.optin==="optional",u=c.optout==="optional";for(const h in t){if(h==="__proto__"||a.has(h))continue;if(l==="never"){o.push(h);continue}const d=c.run({value:t[h],issues:[]},r);d instanceof Promise?e.push(d.then(g=>Ec(g,n,h,t,f,u))):Ec(d,n,h,t,f,u)}return o.length&&n.issues.push({code:"unrecognized_keys",keys:o,input:t,inst:s}),e.length?Promise.all(e).then(()=>n):n}const YT=fe("$ZodObject",(e,t)=>{if(Mt.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const a=t.shape;Object.defineProperty(t,"shape",{get:()=>{const c={...a};return Object.defineProperty(t,"shape",{value:c}),c}})}const r=Xf(()=>gb(t));gt(e._zod,"propValues",()=>{const a=t.shape,c={};for(const l in a){const f=a[l]._zod;if(f.values){c[l]??(c[l]=new Set);for(const u of f.values)c[l].add(u)}}return c});const i=kc,s=t.catchall;let o;e._zod.parse=(a,c)=>{o??(o=r.value);const l=a.value;if(!i(l))return a.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),a;a.value={};const f=[],u=o.shape;for(const h of o.keys){const d=u[h],g=d._zod.optin==="optional",p=d._zod.optout==="optional",m=d._zod.run({value:l[h],issues:[]},c);m instanceof Promise?f.push(m.then(b=>Ec(b,a,h,l,g,p))):Ec(m,a,h,l,g,p)}return s?pb(f,l,a,c,r.value,e):f.length?Promise.all(f).then(()=>a):a}}),XT=fe("$ZodObjectJIT",(e,t)=>{YT.init(e,t);const n=e._zod.parse,r=Xf(()=>gb(t)),i=h=>{const d=new bT(["shape","payload","ctx"]),g=r.value,p=_=>{const E=tp(_);return`shape[${E}]._zod.run({ value: input[${E}], issues: [] }, ctx)`};d.write("const input = payload.value;");const m=Object.create(null);let b=0;for(const _ of g.keys)m[_]=`key_${b++}`;d.write("const newResult = {};");for(const _ of g.keys){const E=m[_],k=tp(_),C=h[_],T=C?._zod?.optin==="optional",j=C?._zod?.optout==="optional";d.write(`const ${E} = ${p(_)};`),T&&j?d.write(`
|
|
62
|
+
if (${E}.issues.length) {
|
|
63
|
+
if (${k} in input) {
|
|
64
|
+
payload.issues = payload.issues.concat(${E}.issues.map(iss => ({
|
|
65
|
+
...iss,
|
|
66
|
+
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
67
|
+
})));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (${E}.value === undefined) {
|
|
72
|
+
if (${k} in input) {
|
|
73
|
+
newResult[${k}] = undefined;
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
newResult[${k}] = ${E}.value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
`):T?d.write(`
|
|
80
|
+
if (${E}.issues.length) {
|
|
81
|
+
payload.issues = payload.issues.concat(${E}.issues.map(iss => ({
|
|
82
|
+
...iss,
|
|
83
|
+
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
84
|
+
})));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (${E}.value === undefined) {
|
|
88
|
+
if (${k} in input) {
|
|
89
|
+
newResult[${k}] = undefined;
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
newResult[${k}] = ${E}.value;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
`):d.write(`
|
|
96
|
+
const ${E}_present = ${k} in input;
|
|
97
|
+
if (${E}.issues.length) {
|
|
98
|
+
payload.issues = payload.issues.concat(${E}.issues.map(iss => ({
|
|
99
|
+
...iss,
|
|
100
|
+
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
101
|
+
})));
|
|
102
|
+
}
|
|
103
|
+
if (!${E}_present && !${E}.issues.length) {
|
|
104
|
+
payload.issues.push({
|
|
105
|
+
code: "invalid_type",
|
|
106
|
+
expected: "nonoptional",
|
|
107
|
+
input: undefined,
|
|
108
|
+
path: [${k}]
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (${E}_present) {
|
|
113
|
+
if (${E}.value === undefined) {
|
|
114
|
+
newResult[${k}] = undefined;
|
|
115
|
+
} else {
|
|
116
|
+
newResult[${k}] = ${E}.value;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
`)}d.write("payload.value = newResult;"),d.write("return payload;");const x=d.compile();return(_,E)=>x(h,_,E)};let s;const o=kc,a=!Yf.jitless,l=a&&uP.value,f=t.catchall;let u;e._zod.parse=(h,d)=>{u??(u=r.value);const g=h.value;return o(g)?a&&l&&d?.async===!1&&d.jitless!==!0?(s||(s=i(t.shape)),h=s(h,d),f?pb([],g,h,d,u,e):h):n(h,d):(h.issues.push({expected:"object",code:"invalid_type",input:g,inst:e}),h)}});function ip(e,t,n,r){for(const s of e)if(s.issues.length===0)return t.value=s.value,t;const i=e.filter(s=>!gs(s));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(s=>s.issues.map(o=>Bi(o,r,Fi())))}),t)}const QT=fe("$ZodUnion",(e,t)=>{Mt.init(e,t),gt(e._zod,"optin",()=>t.options.some(r=>r._zod.optin==="optional")?"optional":void 0),gt(e._zod,"optout",()=>t.options.some(r=>r._zod.optout==="optional")?"optional":void 0),gt(e._zod,"values",()=>{if(t.options.every(r=>r._zod.values))return new Set(t.options.flatMap(r=>Array.from(r._zod.values)))}),gt(e._zod,"pattern",()=>{if(t.options.every(r=>r._zod.pattern)){const r=t.options.map(i=>i._zod.pattern);return new RegExp(`^(${r.map(i=>eh(i.source)).join("|")})$`)}});const n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let s=!1;const o=[];for(const a of t.options){const c=a._zod.run({value:r.value,issues:[]},i);if(c instanceof Promise)o.push(c),s=!0;else{if(c.issues.length===0)return c;o.push(c)}}return s?Promise.all(o).then(a=>ip(a,r,e,i)):ip(o,r,e,i)}}),e7=fe("$ZodIntersection",(e,t)=>{Mt.init(e,t),e._zod.parse=(n,r)=>{const i=n.value,s=t.left._zod.run({value:i,issues:[]},r),o=t.right._zod.run({value:i,issues:[]},r);return s instanceof Promise||o instanceof Promise?Promise.all([s,o]).then(([c,l])=>sp(n,c,l)):sp(n,s,o)}});function Cd(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Mo(e)&&Mo(t)){const n=Object.keys(t),r=Object.keys(e).filter(s=>n.indexOf(s)!==-1),i={...e,...t};for(const s of r){const o=Cd(e[s],t[s]);if(!o.valid)return{valid:!1,mergeErrorPath:[s,...o.mergeErrorPath]};i[s]=o.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const i=e[r],s=t[r],o=Cd(i,s);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function sp(e,t,n){const r=new Map;let i;for(const a of t.issues)if(a.code==="unrecognized_keys"){i??(i=a);for(const c of a.keys)r.has(c)||r.set(c,{}),r.get(c).l=!0}else e.issues.push(a);for(const a of n.issues)if(a.code==="unrecognized_keys")for(const c of a.keys)r.has(c)||r.set(c,{}),r.get(c).r=!0;else e.issues.push(a);const s=[...r].filter(([,a])=>a.l&&a.r).map(([a])=>a);if(s.length&&i&&e.issues.push({...i,keys:s}),gs(e))return e;const o=Cd(t.value,n.value);if(!o.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const t7=fe("$ZodEnum",(e,t)=>{Mt.init(e,t);const n=Qy(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(i=>dP.has(typeof i)).map(i=>typeof i=="string"?sl(i):i.toString()).join("|")})$`),e._zod.parse=(i,s)=>{const o=i.value;return r.has(o)||i.issues.push({code:"invalid_value",values:n,input:o,inst:e}),i}}),n7=fe("$ZodTransform",(e,t)=>{Mt.init(e,t),e._zod.optin="optional",e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Xy(e.constructor.name);const i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(o=>(n.value=o,n.fallback=!0,n));if(i instanceof Promise)throw new ys;return n.value=i,n.fallback=!0,n}});function op(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}const mb=fe("$ZodOptional",(e,t)=>{Mt.init(e,t),e._zod.optin="optional",e._zod.optout="optional",gt(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),gt(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${eh(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>{if(t.innerType._zod.optin==="optional"){const i=n.value,s=t.innerType._zod.run(n,r);return s instanceof Promise?s.then(o=>op(o,i)):op(s,i)}return n.value===void 0?n:t.innerType._zod.run(n,r)}}),r7=fe("$ZodExactOptional",(e,t)=>{mb.init(e,t),gt(e._zod,"values",()=>t.innerType._zod.values),gt(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,r)=>t.innerType._zod.run(n,r)}),i7=fe("$ZodNullable",(e,t)=>{Mt.init(e,t),gt(e._zod,"optin",()=>t.innerType._zod.optin),gt(e._zod,"optout",()=>t.innerType._zod.optout),gt(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${eh(n.source)}|null)$`):void 0}),gt(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,r)=>n.value===null?n:t.innerType._zod.run(n,r)}),s7=fe("$ZodDefault",(e,t)=>{Mt.init(e,t),e._zod.optin="optional",gt(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);if(n.value===void 0)return n.value=t.defaultValue,n;const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>ap(s,t)):ap(i,t)}});function ap(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const o7=fe("$ZodPrefault",(e,t)=>{Mt.init(e,t),e._zod.optin="optional",gt(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,r))}),a7=fe("$ZodNonOptional",(e,t)=>{Mt.init(e,t),gt(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),e._zod.parse=(n,r)=>{const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>cp(s,e)):cp(i,e)}});function cp(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const c7=fe("$ZodCatch",(e,t)=>{Mt.init(e,t),e._zod.optin="optional",gt(e._zod,"optout",()=>t.innerType._zod.optout),gt(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>(n.value=s.value,s.issues.length&&(n.value=t.catchValue({...n,error:{issues:s.issues.map(o=>Bi(o,r,Fi()))},input:n.value}),n.issues=[],n.fallback=!0),n)):(n.value=i.value,i.issues.length&&(n.value=t.catchValue({...n,error:{issues:i.issues.map(s=>Bi(s,r,Fi()))},input:n.value}),n.issues=[],n.fallback=!0),n)}}),l7=fe("$ZodPipe",(e,t)=>{Mt.init(e,t),gt(e._zod,"values",()=>t.in._zod.values),gt(e._zod,"optin",()=>t.in._zod.optin),gt(e._zod,"optout",()=>t.out._zod.optout),gt(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,r)=>{if(r.direction==="backward"){const s=t.out._zod.run(n,r);return s instanceof Promise?s.then(o=>$a(o,t.in,r)):$a(s,t.in,r)}const i=t.in._zod.run(n,r);return i instanceof Promise?i.then(s=>$a(s,t.out,r)):$a(i,t.out,r)}});function $a(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}const u7=fe("$ZodReadonly",(e,t)=>{Mt.init(e,t),gt(e._zod,"propValues",()=>t.innerType._zod.propValues),gt(e._zod,"values",()=>t.innerType._zod.values),gt(e._zod,"optin",()=>t.innerType?._zod?.optin),gt(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(lp):lp(i)}});function lp(e){return e.value=Object.freeze(e.value),e}const d7=fe("$ZodCustom",(e,t)=>{En.init(e,t),Mt.init(e,t),e._zod.parse=(n,r)=>n,e._zod.check=n=>{const r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(s=>up(s,n,r,e));up(i,n,r,e)}});function up(e,t,n,r){if(!e){const i={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(i.params=r._zod.def.params),t.issues.push(Lo(i))}}var dp;class f7{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const r=n[0];return this._map.set(t,r),r&&typeof r=="object"&&"id"in r&&this._idmap.set(r.id,t),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const r={...this.get(n)??{}};delete r.id;const i={...r,...this._map.get(t)};return Object.keys(i).length?i:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function h7(){return new f7}(dp=globalThis).__zod_globalRegistry??(dp.__zod_globalRegistry=h7());const io=globalThis.__zod_globalRegistry;function g7(e,t){return new e({type:"string",...He(t)})}function p7(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...He(t)})}function fp(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...He(t)})}function m7(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...He(t)})}function _7(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...He(t)})}function y7(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...He(t)})}function b7(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...He(t)})}function w7(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...He(t)})}function v7(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...He(t)})}function x7(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...He(t)})}function S7(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...He(t)})}function $7(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...He(t)})}function k7(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...He(t)})}function E7(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...He(t)})}function A7(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...He(t)})}function I7(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...He(t)})}function C7(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...He(t)})}function z7(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...He(t)})}function O7(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...He(t)})}function P7(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...He(t)})}function T7(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...He(t)})}function D7(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...He(t)})}function R7(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...He(t)})}function F7(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...He(t)})}function B7(e,t){return new e({type:"string",format:"date",check:"string_format",...He(t)})}function U7(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...He(t)})}function j7(e,t){return new e({type:"string",format:"duration",check:"string_format",...He(t)})}function M7(e,t){return new e({type:"number",checks:[],...He(t)})}function L7(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...He(t)})}function N7(e,t){return new e({type:"boolean",...He(t)})}function H7(e){return new e({type:"unknown"})}function Z7(e,t){return new e({type:"never",...He(t)})}function hp(e,t){return new ub({check:"less_than",...He(t),value:e,inclusive:!1})}function uu(e,t){return new ub({check:"less_than",...He(t),value:e,inclusive:!0})}function gp(e,t){return new db({check:"greater_than",...He(t),value:e,inclusive:!1})}function du(e,t){return new db({check:"greater_than",...He(t),value:e,inclusive:!0})}function pp(e,t){return new aT({check:"multiple_of",...He(t),value:e})}function _b(e,t){return new lT({check:"max_length",...He(t),maximum:e})}function Ac(e,t){return new uT({check:"min_length",...He(t),minimum:e})}function yb(e,t){return new dT({check:"length_equals",...He(t),length:e})}function V7(e,t){return new fT({check:"string_format",format:"regex",...He(t),pattern:e})}function W7(e){return new hT({check:"string_format",format:"lowercase",...He(e)})}function q7(e){return new gT({check:"string_format",format:"uppercase",...He(e)})}function J7(e,t){return new pT({check:"string_format",format:"includes",...He(t),includes:e})}function K7(e,t){return new mT({check:"string_format",format:"starts_with",...He(t),prefix:e})}function G7(e,t){return new _T({check:"string_format",format:"ends_with",...He(t),suffix:e})}function js(e){return new yT({check:"overwrite",tx:e})}function Y7(e){return js(t=>t.normalize(e))}function X7(){return js(e=>e.trim())}function Q7(){return js(e=>e.toLowerCase())}function eD(){return js(e=>e.toUpperCase())}function tD(){return js(e=>lP(e))}function nD(e,t,n){return new e({type:"array",element:t,...He(n)})}function rD(e,t,n){return new e({type:"custom",check:"custom",fn:t,...He(n)})}function iD(e,t){const n=sD(r=>(r.addIssue=i=>{if(typeof i=="string")r.issues.push(Lo(i,r.value,n._zod.def));else{const s=i;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),s.input??(s.input=r.value),s.inst??(s.inst=n),s.continue??(s.continue=!n._zod.def.abort),r.issues.push(Lo(s))}},e(r.value,r)),t);return n}function sD(e,t){const n=new En({check:"custom",...He(t)});return n._zod.check=e,n}function bb(e){let t=e?.target??"draft-2020-12";return t==="draft-4"&&(t="draft-04"),t==="draft-7"&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:e?.metadata??io,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,cycles:e?.cycles??"ref",reused:e?.reused??"inline",external:e?.external??void 0}}function sn(e,t,n={path:[],schemaPath:[]}){var r;const i=e._zod.def,s=t.seen.get(e);if(s)return s.count++,n.schemaPath.includes(e)&&(s.cycle=n.path),s.schema;const o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);const a=e._zod.toJSONSchema?.();if(a)o.schema=a;else{const f={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,f);else{const h=o.schema,d=t.processors[i.type];if(!d)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);d(e,t,h,f)}const u=e._zod.parent;u&&(o.ref||(o.ref=u),sn(u,t,f),t.seen.get(u).isParent=!0)}const c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io==="input"&&hn(e)&&(delete o.schema.examples,delete o.schema.default),t.io==="input"&&"_prefault"in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function wb(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const o of e.seen.entries()){const a=e.metadataRegistry.get(o[0])?.id;if(a){const c=r.get(a);if(c&&c!==o[0])throw new Error(`Duplicate schema id "${a}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(a,o[0])}}const i=o=>{const a=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){const u=e.external.registry.get(o[0])?.id,h=e.external.uri??(g=>g);if(u)return{ref:h(u)};const d=o[1].defId??o[1].schema.id??`schema${e.counter++}`;return o[1].defId=d,{defId:d,ref:`${h("__shared")}#/${a}/${d}`}}if(o[1]===n)return{ref:"#"};const l=`#/${a}/`,f=o[1].schema.id??`__schema${e.counter++}`;return{defId:f,ref:l+f}},s=o=>{if(o[1].schema.$ref)return;const a=o[1],{ref:c,defId:l}=i(o);a.def={...a.schema},l&&(a.defId=l);const f=a.schema;for(const u in f)delete f[u];f.$ref=c};if(e.cycles==="throw")for(const o of e.seen.entries()){const a=o[1];if(a.cycle)throw new Error(`Cycle detected: #/${a.cycle?.join("/")}/<root>
|
|
121
|
+
|
|
122
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const o of e.seen.entries()){const a=o[1];if(t===o[0]){s(o);continue}if(e.external){const l=e.external.registry.get(o[0])?.id;if(t!==o[0]&&l){s(o);continue}}if(e.metadataRegistry.get(o[0])?.id){s(o);continue}if(a.cycle){s(o);continue}if(a.count>1&&e.reused==="ref"){s(o);continue}}}function vb(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=a=>{const c=e.seen.get(a);if(c.ref===null)return;const l=c.def??c.schema,f={...l},u=c.ref;if(c.ref=null,u){r(u);const d=e.seen.get(u),g=d.schema;if(g.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(l.allOf=l.allOf??[],l.allOf.push(g)):Object.assign(l,g),Object.assign(l,f),a._zod.parent===u)for(const m in l)m==="$ref"||m==="allOf"||m in f||delete l[m];if(g.$ref&&d.def)for(const m in l)m==="$ref"||m==="allOf"||m in d.def&&JSON.stringify(l[m])===JSON.stringify(d.def[m])&&delete l[m]}const h=a._zod.parent;if(h&&h!==u){r(h);const d=e.seen.get(h);if(d?.schema.$ref&&(l.$ref=d.schema.$ref,d.def))for(const g in l)g==="$ref"||g==="allOf"||g in d.def&&JSON.stringify(l[g])===JSON.stringify(d.def[g])&&delete l[g]}e.override({zodSchema:a,jsonSchema:l,path:c.path??[]})};for(const a of[...e.seen.entries()].reverse())r(a[0]);const i={};if(e.target==="draft-2020-12"?i.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?i.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?i.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){const a=e.external.registry.get(t)?.id;if(!a)throw new Error("Schema is missing an `id` property");i.$id=e.external.uri(a)}Object.assign(i,n.def??n.schema);const s=e.metadataRegistry.get(t)?.id;s!==void 0&&i.id===s&&delete i.id;const o=e.external?.defs??{};for(const a of e.seen.entries()){const c=a[1];c.def&&c.defId&&(c.def.id===c.defId&&delete c.def.id,o[c.defId]=c.def)}e.external||Object.keys(o).length>0&&(e.target==="draft-2020-12"?i.$defs=o:i.definitions=o);try{const a=JSON.parse(JSON.stringify(i));return Object.defineProperty(a,"~standard",{value:{...t["~standard"],jsonSchema:{input:Ic(t,"input",e.processors),output:Ic(t,"output",e.processors)}},enumerable:!1,writable:!1}),a}catch{throw new Error("Error converting schema to JSON.")}}function hn(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return hn(r.element,n);if(r.type==="set")return hn(r.valueType,n);if(r.type==="lazy")return hn(r.getter(),n);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault")return hn(r.innerType,n);if(r.type==="intersection")return hn(r.left,n)||hn(r.right,n);if(r.type==="record"||r.type==="map")return hn(r.keyType,n)||hn(r.valueType,n);if(r.type==="pipe")return e._zod.traits.has("$ZodCodec")?!0:hn(r.in,n)||hn(r.out,n);if(r.type==="object"){for(const i in r.shape)if(hn(r.shape[i],n))return!0;return!1}if(r.type==="union"){for(const i of r.options)if(hn(i,n))return!0;return!1}if(r.type==="tuple"){for(const i of r.items)if(hn(i,n))return!0;return!!(r.rest&&hn(r.rest,n))}return!1}const oD=(e,t={})=>n=>{const r=bb({...n,processors:t});return sn(e,r),wb(r,e),vb(r,e)},Ic=(e,t,n={})=>r=>{const{libraryOptions:i,target:s}=r??{},o=bb({...i??{},target:s,io:t,processors:n});return sn(e,o),wb(o,e),vb(o,e)},aD={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},cD=(e,t,n,r)=>{const i=n;i.type="string";const{minimum:s,maximum:o,format:a,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof s=="number"&&(i.minLength=s),typeof o=="number"&&(i.maxLength=o),a&&(i.format=aD[a]??a,i.format===""&&delete i.format,a==="time"&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){const f=[...c];f.length===1?i.pattern=f[0].source:f.length>1&&(i.allOf=[...f.map(u=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:u.source}))])}},lD=(e,t,n,r)=>{const i=n,{minimum:s,maximum:o,format:a,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:f}=e._zod.bag;typeof a=="string"&&a.includes("int")?i.type="integer":i.type="number";const u=typeof f=="number"&&f>=(s??Number.NEGATIVE_INFINITY),h=typeof l=="number"&&l<=(o??Number.POSITIVE_INFINITY),d=t.target==="draft-04"||t.target==="openapi-3.0";u?d?(i.minimum=f,i.exclusiveMinimum=!0):i.exclusiveMinimum=f:typeof s=="number"&&(i.minimum=s),h?d?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l:typeof o=="number"&&(i.maximum=o),typeof c=="number"&&(i.multipleOf=c)},uD=(e,t,n,r)=>{n.type="boolean"},dD=(e,t,n,r)=>{n.not={}},fD=(e,t,n,r)=>{},hD=(e,t,n,r)=>{const i=e._zod.def,s=Qy(i.entries);s.every(o=>typeof o=="number")&&(n.type="number"),s.every(o=>typeof o=="string")&&(n.type="string"),n.enum=s},gD=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},pD=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},mD=(e,t,n,r)=>{const i=n,s=e._zod.def,{minimum:o,maximum:a}=e._zod.bag;typeof o=="number"&&(i.minItems=o),typeof a=="number"&&(i.maxItems=a),i.type="array",i.items=sn(s.element,t,{...r,path:[...r.path,"items"]})},_D=(e,t,n,r)=>{const i=n,s=e._zod.def;i.type="object",i.properties={};const o=s.shape;for(const l in o)i.properties[l]=sn(o[l],t,{...r,path:[...r.path,"properties",l]});const a=new Set(Object.keys(o)),c=new Set([...a].filter(l=>{const f=s.shape[l]._zod;return t.io==="input"?f.optin===void 0:f.optout===void 0}));c.size>0&&(i.required=Array.from(c)),s.catchall?._zod.def.type==="never"?i.additionalProperties=!1:s.catchall?s.catchall&&(i.additionalProperties=sn(s.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):t.io==="output"&&(i.additionalProperties=!1)},yD=(e,t,n,r)=>{const i=e._zod.def,s=i.inclusive===!1,o=i.options.map((a,c)=>sn(a,t,{...r,path:[...r.path,s?"oneOf":"anyOf",c]}));s?n.oneOf=o:n.anyOf=o},bD=(e,t,n,r)=>{const i=e._zod.def,s=sn(i.left,t,{...r,path:[...r.path,"allOf",0]}),o=sn(i.right,t,{...r,path:[...r.path,"allOf",1]}),a=l=>"allOf"in l&&Object.keys(l).length===1,c=[...a(s)?s.allOf:[s],...a(o)?o.allOf:[o]];n.allOf=c},wD=(e,t,n,r)=>{const i=e._zod.def,s=sn(i.innerType,t,r),o=t.seen.get(e);t.target==="openapi-3.0"?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[s,{type:"null"}]},vD=(e,t,n,r)=>{const i=e._zod.def;sn(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType},xD=(e,t,n,r)=>{const i=e._zod.def;sn(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},SD=(e,t,n,r)=>{const i=e._zod.def;sn(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType,t.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},$D=(e,t,n,r)=>{const i=e._zod.def;sn(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=o},kD=(e,t,n,r)=>{const i=e._zod.def,s=i.in._zod.traits.has("$ZodTransform"),o=t.io==="input"?s?i.out:i.in:i.out;sn(o,t,r);const a=t.seen.get(e);a.ref=o},ED=(e,t,n,r)=>{const i=e._zod.def;sn(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType,n.readOnly=!0},xb=(e,t,n,r)=>{const i=e._zod.def;sn(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType},AD=fe("ZodISODateTime",(e,t)=>{PT.init(e,t),Dt.init(e,t)});function ID(e){return F7(AD,e)}const CD=fe("ZodISODate",(e,t)=>{TT.init(e,t),Dt.init(e,t)});function zD(e){return B7(CD,e)}const OD=fe("ZodISOTime",(e,t)=>{DT.init(e,t),Dt.init(e,t)});function PD(e){return U7(OD,e)}const TD=fe("ZodISODuration",(e,t)=>{RT.init(e,t),Dt.init(e,t)});function DD(e){return j7(TD,e)}const RD=(e,t)=>{ib.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>SP(e,n)},flatten:{value:n=>xP(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,Id,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,Id,2)}},isEmpty:{get(){return e.issues.length===0}}})},Kn=fe("ZodError",RD,{Parent:Error}),FD=nh(Kn),BD=rh(Kn),UD=ol(Kn),jD=al(Kn),MD=EP(Kn),LD=AP(Kn),ND=IP(Kn),HD=CP(Kn),ZD=zP(Kn),VD=OP(Kn),WD=PP(Kn),qD=TP(Kn),mp=new WeakMap;function Xo(e,t,n){const r=Object.getPrototypeOf(e);let i=mp.get(r);if(i||(i=new Set,mp.set(r,i)),!i.has(t)){i.add(t);for(const s in n){const o=n[s];Object.defineProperty(r,s,{configurable:!0,enumerable:!1,get(){const a=o.bind(this);return Object.defineProperty(this,s,{configurable:!0,writable:!0,enumerable:!0,value:a}),a},set(a){Object.defineProperty(this,s,{configurable:!0,writable:!0,enumerable:!0,value:a})}})}}}const Lt=fe("ZodType",(e,t)=>(Mt.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:Ic(e,"input"),output:Ic(e,"output")}}),e.toJSONSchema=oD(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(n,r)=>FD(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>UD(e,n,r),e.parseAsync=async(n,r)=>BD(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>jD(e,n,r),e.spa=e.safeParseAsync,e.encode=(n,r)=>MD(e,n,r),e.decode=(n,r)=>LD(e,n,r),e.encodeAsync=async(n,r)=>ND(e,n,r),e.decodeAsync=async(n,r)=>HD(e,n,r),e.safeEncode=(n,r)=>ZD(e,n,r),e.safeDecode=(n,r)=>VD(e,n,r),e.safeEncodeAsync=async(n,r)=>WD(e,n,r),e.safeDecodeAsync=async(n,r)=>qD(e,n,r),Xo(e,"ZodType",{check(...n){const r=this.def;return this.clone(pi(r,{checks:[...r.checks??[],...n.map(i=>typeof i=="function"?{_zod:{check:i,def:{check:"custom"},onattach:[]}}:i)]}),{parent:!0})},with(...n){return this.check(...n)},clone(n,r){return mi(this,n,r)},brand(){return this},register(n,r){return n.add(this,r),this},refine(n,r){return this.check(MR(n,r))},superRefine(n,r){return this.check(LR(n,r))},overwrite(n){return this.check(js(n))},optional(){return vp(this)},exactOptional(){return AR(this)},nullable(){return xp(this)},nullish(){return vp(xp(this))},nonoptional(n){return TR(this,n)},array(){return kb(this)},or(n){return wR([this,n])},and(n){return xR(this,n)},transform(n){return Sp(this,kR(n))},default(n){return zR(this,n)},prefault(n){return PR(this,n)},catch(n){return RR(this,n)},pipe(n){return Sp(this,n)},readonly(){return UR(this)},describe(n){const r=this.clone();return io.add(r,{description:n}),r},meta(...n){if(n.length===0)return io.get(this);const r=this.clone();return io.add(r,n[0]),r},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(n){return n(this)}}),Object.defineProperty(e,"description",{get(){return io.get(e)?.description},configurable:!0}),e)),Sb=fe("_ZodString",(e,t)=>{ih.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(r,i,s)=>cD(e,r,i);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,Xo(e,"_ZodString",{regex(...r){return this.check(V7(...r))},includes(...r){return this.check(J7(...r))},startsWith(...r){return this.check(K7(...r))},endsWith(...r){return this.check(G7(...r))},min(...r){return this.check(Ac(...r))},max(...r){return this.check(_b(...r))},length(...r){return this.check(yb(...r))},nonempty(...r){return this.check(Ac(1,...r))},lowercase(r){return this.check(W7(r))},uppercase(r){return this.check(q7(r))},trim(){return this.check(X7())},normalize(...r){return this.check(Y7(...r))},toLowerCase(){return this.check(Q7())},toUpperCase(){return this.check(eD())},slugify(){return this.check(tD())}})}),JD=fe("ZodString",(e,t)=>{ih.init(e,t),Sb.init(e,t),e.email=n=>e.check(p7(KD,n)),e.url=n=>e.check(w7(GD,n)),e.jwt=n=>e.check(R7(dR,n)),e.emoji=n=>e.check(v7(YD,n)),e.guid=n=>e.check(fp(_p,n)),e.uuid=n=>e.check(m7(ka,n)),e.uuidv4=n=>e.check(_7(ka,n)),e.uuidv6=n=>e.check(y7(ka,n)),e.uuidv7=n=>e.check(b7(ka,n)),e.nanoid=n=>e.check(x7(XD,n)),e.guid=n=>e.check(fp(_p,n)),e.cuid=n=>e.check(S7(QD,n)),e.cuid2=n=>e.check($7(eR,n)),e.ulid=n=>e.check(k7(tR,n)),e.base64=n=>e.check(P7(cR,n)),e.base64url=n=>e.check(T7(lR,n)),e.xid=n=>e.check(E7(nR,n)),e.ksuid=n=>e.check(A7(rR,n)),e.ipv4=n=>e.check(I7(iR,n)),e.ipv6=n=>e.check(C7(sR,n)),e.cidrv4=n=>e.check(z7(oR,n)),e.cidrv6=n=>e.check(O7(aR,n)),e.e164=n=>e.check(D7(uR,n)),e.datetime=n=>e.check(ID(n)),e.date=n=>e.check(zD(n)),e.time=n=>e.check(PD(n)),e.duration=n=>e.check(DD(n))});function Jt(e){return g7(JD,e)}const Dt=fe("ZodStringFormat",(e,t)=>{It.init(e,t),Sb.init(e,t)}),KD=fe("ZodEmail",(e,t)=>{ST.init(e,t),Dt.init(e,t)}),_p=fe("ZodGUID",(e,t)=>{vT.init(e,t),Dt.init(e,t)}),ka=fe("ZodUUID",(e,t)=>{xT.init(e,t),Dt.init(e,t)}),GD=fe("ZodURL",(e,t)=>{$T.init(e,t),Dt.init(e,t)}),YD=fe("ZodEmoji",(e,t)=>{kT.init(e,t),Dt.init(e,t)}),XD=fe("ZodNanoID",(e,t)=>{ET.init(e,t),Dt.init(e,t)}),QD=fe("ZodCUID",(e,t)=>{AT.init(e,t),Dt.init(e,t)}),eR=fe("ZodCUID2",(e,t)=>{IT.init(e,t),Dt.init(e,t)}),tR=fe("ZodULID",(e,t)=>{CT.init(e,t),Dt.init(e,t)}),nR=fe("ZodXID",(e,t)=>{zT.init(e,t),Dt.init(e,t)}),rR=fe("ZodKSUID",(e,t)=>{OT.init(e,t),Dt.init(e,t)}),iR=fe("ZodIPv4",(e,t)=>{FT.init(e,t),Dt.init(e,t)}),sR=fe("ZodIPv6",(e,t)=>{BT.init(e,t),Dt.init(e,t)}),oR=fe("ZodCIDRv4",(e,t)=>{UT.init(e,t),Dt.init(e,t)}),aR=fe("ZodCIDRv6",(e,t)=>{jT.init(e,t),Dt.init(e,t)}),cR=fe("ZodBase64",(e,t)=>{MT.init(e,t),Dt.init(e,t)}),lR=fe("ZodBase64URL",(e,t)=>{NT.init(e,t),Dt.init(e,t)}),uR=fe("ZodE164",(e,t)=>{HT.init(e,t),Dt.init(e,t)}),dR=fe("ZodJWT",(e,t)=>{VT.init(e,t),Dt.init(e,t)}),$b=fe("ZodNumber",(e,t)=>{hb.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(r,i,s)=>lD(e,r,i),Xo(e,"ZodNumber",{gt(r,i){return this.check(gp(r,i))},gte(r,i){return this.check(du(r,i))},min(r,i){return this.check(du(r,i))},lt(r,i){return this.check(hp(r,i))},lte(r,i){return this.check(uu(r,i))},max(r,i){return this.check(uu(r,i))},int(r){return this.check(yp(r))},safe(r){return this.check(yp(r))},positive(r){return this.check(gp(0,r))},nonnegative(r){return this.check(du(0,r))},negative(r){return this.check(hp(0,r))},nonpositive(r){return this.check(uu(0,r))},multipleOf(r,i){return this.check(pp(r,i))},step(r,i){return this.check(pp(r,i))},finite(){return this}});const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Si(e){return M7($b,e)}const fR=fe("ZodNumberFormat",(e,t)=>{WT.init(e,t),$b.init(e,t)});function yp(e){return L7(fR,e)}const hR=fe("ZodBoolean",(e,t)=>{qT.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>uD(e,n,r)});function bp(e){return N7(hR,e)}const gR=fe("ZodUnknown",(e,t)=>{JT.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>fD()});function wp(){return H7(gR)}const pR=fe("ZodNever",(e,t)=>{KT.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>dD(e,n,r)});function mR(e){return Z7(pR,e)}const _R=fe("ZodArray",(e,t)=>{GT.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>mD(e,n,r,i),e.element=t.element,Xo(e,"ZodArray",{min(n,r){return this.check(Ac(n,r))},nonempty(n){return this.check(Ac(1,n))},max(n,r){return this.check(_b(n,r))},length(n,r){return this.check(yb(n,r))},unwrap(){return this.element}})});function kb(e,t){return nD(_R,e,t)}const yR=fe("ZodObject",(e,t)=>{XT.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>_D(e,n,r,i),gt(e,"shape",()=>t.shape),Xo(e,"ZodObject",{keyof(){return SR(Object.keys(this._zod.def.shape))},catchall(n){return this.clone({...this._zod.def,catchall:n})},passthrough(){return this.clone({...this._zod.def,catchall:wp()})},loose(){return this.clone({...this._zod.def,catchall:wp()})},strict(){return this.clone({...this._zod.def,catchall:mR()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(n){return mP(this,n)},safeExtend(n){return _P(this,n)},merge(n){return yP(this,n)},pick(n){return gP(this,n)},omit(n){return pP(this,n)},partial(...n){return bP(Eb,this,n[0])},required(...n){return wP(Ab,this,n[0])}})});function sh(e,t){const n={type:"object",shape:e??{},...He(t)};return new yR(n)}const bR=fe("ZodUnion",(e,t)=>{QT.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>yD(e,n,r,i),e.options=t.options});function wR(e,t){return new bR({type:"union",options:e,...He(t)})}const vR=fe("ZodIntersection",(e,t)=>{e7.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>bD(e,n,r,i)});function xR(e,t){return new vR({type:"intersection",left:e,right:t})}const zd=fe("ZodEnum",(e,t)=>{t7.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(r,i,s)=>hD(e,r,i),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(r,i)=>{const s={};for(const o of r)if(n.has(o))s[o]=t.entries[o];else throw new Error(`Key ${o} not found in enum`);return new zd({...t,checks:[],...He(i),entries:s})},e.exclude=(r,i)=>{const s={...t.entries};for(const o of r)if(n.has(o))delete s[o];else throw new Error(`Key ${o} not found in enum`);return new zd({...t,checks:[],...He(i),entries:s})}});function SR(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new zd({type:"enum",entries:n,...He(t)})}const $R=fe("ZodTransform",(e,t)=>{n7.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>pD(e,n),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Xy(e.constructor.name);n.addIssue=s=>{if(typeof s=="string")n.issues.push(Lo(s,n.value,t));else{const o=s;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=e),n.issues.push(Lo(o))}};const i=t.transform(n.value,n);return i instanceof Promise?i.then(s=>(n.value=s,n.fallback=!0,n)):(n.value=i,n.fallback=!0,n)}});function kR(e){return new $R({type:"transform",transform:e})}const Eb=fe("ZodOptional",(e,t)=>{mb.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>xb(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function vp(e){return new Eb({type:"optional",innerType:e})}const ER=fe("ZodExactOptional",(e,t)=>{r7.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>xb(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function AR(e){return new ER({type:"optional",innerType:e})}const IR=fe("ZodNullable",(e,t)=>{i7.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>wD(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function xp(e){return new IR({type:"nullable",innerType:e})}const CR=fe("ZodDefault",(e,t)=>{s7.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>xD(e,n,r,i),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function zR(e,t){return new CR({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():tb(t)}})}const OR=fe("ZodPrefault",(e,t)=>{o7.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>SD(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function PR(e,t){return new OR({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():tb(t)}})}const Ab=fe("ZodNonOptional",(e,t)=>{a7.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>vD(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function TR(e,t){return new Ab({type:"nonoptional",innerType:e,...He(t)})}const DR=fe("ZodCatch",(e,t)=>{c7.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>$D(e,n,r,i),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function RR(e,t){return new DR({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const FR=fe("ZodPipe",(e,t)=>{l7.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>kD(e,n,r,i),e.in=t.in,e.out=t.out});function Sp(e,t){return new FR({type:"pipe",in:e,out:t})}const BR=fe("ZodReadonly",(e,t)=>{u7.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>ED(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function UR(e){return new BR({type:"readonly",innerType:e})}const jR=fe("ZodCustom",(e,t)=>{d7.init(e,t),Lt.init(e,t),e._zod.processJSONSchema=(n,r,i)=>gD(e,n)});function MR(e,t={}){return rD(jR,e,t)}function LR(e,t){return iD(e,t)}const NR=sh({id:Jt(),title:Jt(),artist:Jt(),album:Jt(),duration:Si(),originalFilename:Jt(),fileSize:Si(),sha:Jt().optional(),imageExtension:Jt().optional(),imageMimeType:Jt().optional(),imageFilePath:Jt().optional(),filePath:Jt().optional(),safeFilename:Jt().optional(),mimeType:Jt().optional()}),HR=sh({id:Jt(),title:Jt(),description:Jt().optional(),rev:Si().optional(),imageExtension:Jt().optional(),imageMimeType:Jt().optional(),imageFilePath:Jt().optional(),safeFilename:Jt().optional(),bgFilterEnabled:bp().optional(),bgFilterBlur:Si().optional(),bgFilterContrast:Si().optional(),bgFilterBrightness:Si().optional(),coverFilterEnabled:bp().optional(),coverFilterBlur:Si().optional()});sh({playlist:HR,songs:kb(NR)});function ZR(e){return`(function(){var el=document.querySelector('freqhole-playlistz');if(el)el.setAttribute('data-playlistz',${JSON.stringify(JSON.stringify(e))});})();
|
|
123
|
+
`}function VR(){return`<!DOCTYPE html>
|
|
124
|
+
<html lang="en">
|
|
125
|
+
<head>
|
|
126
|
+
<meta charset="UTF-8" />
|
|
127
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
128
|
+
<title>playlistz</title>
|
|
129
|
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
130
|
+
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
|
131
|
+
<meta name="mobile-web-app-capable" content="yes">
|
|
132
|
+
<meta name="theme-color" content="#000000">
|
|
133
|
+
</head>
|
|
134
|
+
<body>
|
|
135
|
+
<freqhole-playlistz></freqhole-playlistz>
|
|
136
|
+
<script src="playlistz.js" defer></script>
|
|
137
|
+
<script src="freqhole-playlistz.js" defer></script>
|
|
138
|
+
</body>
|
|
139
|
+
</html>
|
|
140
|
+
`}const WR=`// playlistz service worker
|
|
141
|
+
//
|
|
142
|
+
// caches the app shell files (freqhole-playlistz.js, playlistz.js, index.html, sw.js).
|
|
143
|
+
// audio and image files in data/ are NOT pre-cached; the app ui handles that separately.
|
|
144
|
+
//
|
|
145
|
+
// bumping CACHE_VERSION forces all clients to receive fresh app files on next load.
|
|
146
|
+
const CACHE_VERSION = "v2";
|
|
147
|
+
const CACHE_NAME = \`playlistz-\${CACHE_VERSION}\`;
|
|
148
|
+
|
|
149
|
+
const APP_SHELL = [
|
|
150
|
+
"freqhole-playlistz.js",
|
|
151
|
+
"playlistz.js",
|
|
152
|
+
"index.html",
|
|
153
|
+
"sw.js",
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
self.addEventListener("install", (event) => {
|
|
157
|
+
event.waitUntil(
|
|
158
|
+
caches.open(CACHE_NAME).then((cache) =>
|
|
159
|
+
cache.addAll(APP_SHELL).catch((err) => {
|
|
160
|
+
console.warn("playlistz sw: pre-cache partial failure:", err);
|
|
161
|
+
}),
|
|
162
|
+
).then(() => self.skipWaiting()),
|
|
163
|
+
);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
self.addEventListener("activate", (event) => {
|
|
167
|
+
event.waitUntil(
|
|
168
|
+
caches.keys()
|
|
169
|
+
.then((names) =>
|
|
170
|
+
Promise.all(
|
|
171
|
+
names
|
|
172
|
+
.filter((n) => n.startsWith("playlistz-") && n !== CACHE_NAME)
|
|
173
|
+
.map((n) => caches.delete(n)),
|
|
174
|
+
),
|
|
175
|
+
)
|
|
176
|
+
.then(() => self.clients.claim()),
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
self.addEventListener("fetch", (event) => {
|
|
181
|
+
const url = new URL(event.request.url);
|
|
182
|
+
const filename = url.pathname.split("/").pop() ?? "";
|
|
183
|
+
const isAppShell = APP_SHELL.includes(filename) || url.pathname === "/" || url.pathname === "";
|
|
184
|
+
|
|
185
|
+
if (!isAppShell) return;
|
|
186
|
+
|
|
187
|
+
event.respondWith(
|
|
188
|
+
caches.match(event.request).then((cached) => {
|
|
189
|
+
if (cached) return cached;
|
|
190
|
+
return fetch(event.request).then((response) => {
|
|
191
|
+
if (response.ok) {
|
|
192
|
+
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, response.clone()));
|
|
193
|
+
}
|
|
194
|
+
return response;
|
|
195
|
+
});
|
|
196
|
+
}).catch(() => caches.match("index.html")),
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
self.addEventListener("message", (event) => {
|
|
201
|
+
if (event.data?.type === "PLAYLISTZ_RESET") {
|
|
202
|
+
event.waitUntil(
|
|
203
|
+
caches.keys()
|
|
204
|
+
.then((names) => Promise.all(names.map((n) => caches.delete(n))))
|
|
205
|
+
.then(() => self.clients.matchAll())
|
|
206
|
+
.then((clients) => clients.forEach((c) => c.postMessage({ type: "PLAYLISTZ_RESET_DONE" }))),
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
`;function qR(){return WR}function $p(e){const t=e.split(".").pop()?.toLowerCase(),n={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",avif:"image/avif"};return t&&n[t]?n[t]:"image/jpeg"}const Ys=new TextEncoder;async function JR(){if(typeof navigator<"u"&&typeof navigator.storage?.getDirectory=="function"&&!(typeof window<"u"&&"__TAURI_INTERNALS__"in window))try{const o=await navigator.storage.getDirectory(),a=`playlistz-dl-${Date.now()}.zip`,c=await o.getFileHandle(a,{create:!0}),l=await c.createWritable();let f=Promise.resolve(),u,h;const d=new Promise((p,m)=>{u=p,h=m}),g=new Y0((p,m,b)=>{if(p){h(p);return}f=f.then(()=>l.write(m)),b&&f.then(()=>l.close()).then(u,h)});return{tempName:a,async addFile(p,m){const b=new G0(p);g.add(b),b.push(m,!0),await f},async finish(){return g.end(),await d,c.getFile()}}}catch{}const t=[];let n,r;const i=new Promise((o,a)=>{n=o,r=a}),s=new Y0((o,a,c)=>{if(o){r(o);return}t.push(a),c&&n()});return{async addFile(o,a){const c=new G0(o);s.add(c),c.push(a,!0)},async finish(){s.end(),await i;const o=t.reduce((l,f)=>l+f.length,0),a=new Uint8Array(o);let c=0;for(const l of t)a.set(l,c),c+=l.length;return new Blob([a],{type:"application/zip"})}}}async function KR(e,t,n={}){const{includeImages:r=!0,generateM3U:i=!0,includeHTML:s=!0,appBundleUrl:o}=n,a=oP(e.playlist.title)||"playlist",c=await JR();let l;if(r&&e.playlist.imageSha){const h=await t(e.playlist.imageSha);h&&(l=`data/${`playlist-cover${lu(e.playlist.imageType??"image/jpeg")}`}`,await c.addFile(`${a}/${l}`,new Uint8Array(h)))}const f=[];for(const h of e.songs){const d=h.originalFilename?X0(h.originalFilename):X0(`${h.title}.${lu(h.mimeType).slice(1)}`),g=d.replace(/\.[^.]+$/,""),p=`data/${d}`;let m=h.fileSize??0;if(h.sha){const x=await t(h.sha);x&&(m=x.byteLength,await c.addFile(`${a}/${p}`,new Uint8Array(x)))}let b;if(r&&h.imageSha){const x=await t(h.imageSha);if(x){const _=lu(h.imageType??"image/jpeg");b=`data/${`${g}-cover${_}`}`,await c.addFile(`${a}/${b}`,new Uint8Array(x))}}f.push({song:h,audioPath:p,imagePath:b,safeFilename:d,fileSize:m})}const u=[{playlist:{id:e.playlist.id,title:e.playlist.title,description:e.playlist.description,rev:e.playlist.rev,imageMimeType:e.playlist.imageType??(l?$p(l):void 0),imageFilePath:l,safeFilename:a,bgFilterEnabled:e.playlist.bgFilterEnabled,bgFilterBlur:e.playlist.bgFilterBlur,bgFilterContrast:e.playlist.bgFilterContrast,bgFilterBrightness:e.playlist.bgFilterBrightness,coverFilterEnabled:e.playlist.coverFilterEnabled,coverFilterBlur:e.playlist.coverFilterBlur},songs:f.map(h=>({id:h.song.id,title:h.song.title,artist:h.song.artist??"",album:h.song.album??"",duration:h.song.duration,originalFilename:h.song.originalFilename,filePath:h.audioPath,safeFilename:h.safeFilename,fileSize:h.fileSize,mimeType:h.song.mimeType,sha:h.song.sha,imageMimeType:h.song.imageType??(h.imagePath?$p(h.imagePath):void 0),imageFilePath:h.imagePath}))}];if(await c.addFile(`${a}/playlistz.js`,Ys.encode(ZR(u))),i){const h=aP({id:e.playlist.id,title:e.playlist.title,description:e.playlist.description,rev:e.playlist.rev,imagePath:l},f.map(d=>({title:d.song.title,artist:d.song.artist??"",album:d.song.album??"",duration:d.song.duration,audioPath:d.audioPath,imagePath:d.imagePath})));await c.addFile(`${a}/data/${a}.m3u8`,Ys.encode(h))}if(s){await c.addFile(`${a}/index.html`,Ys.encode(VR())),await c.addFile(`${a}/sw.js`,Ys.encode(qR()));const h=o!==void 0?o:typeof window<"u"?`${window.location.origin}/freqhole-playlistz.js`:null;if(h)try{const d=await fetch(h);if(d.ok){const g=await d.text();g.trimStart().startsWith("<!")?console.warn("freqhole-playlistz.js fetch returned HTML (vite dev mode?). run `npm run build:standalone` first, then retry the zip download."):await c.addFile(`${a}/freqhole-playlistz.js`,Ys.encode(g))}else console.warn("could not fetch freqhole-playlistz.js for zip bundle:",d.status)}catch(d){console.warn("could not include freqhole-playlistz.js in zip:",d)}}return c.finish()}async function GR(e){try{await (await navigator.storage.getDirectory()).removeEntry(e)}catch{}}async function YR(e){return(await Yc(e))?.arrayBuffer()}function XR(e,t){return{playlist:{id:e.id,title:e.title,description:e.description,rev:e.rev,imageSha:e._primaryImageSha,imageType:e.imageType,bgFilterEnabled:e.bgFilterEnabled,bgFilterBlur:e.bgFilterBlur,bgFilterContrast:e.bgFilterContrast,bgFilterBrightness:e.bgFilterBrightness,coverFilterEnabled:e.coverFilterEnabled,coverFilterBlur:e.coverFilterBlur},songs:t.map(n=>{const r=n.images?.find(i=>i.isPrimary)??n.images?.[0];return{id:n.id,title:n.title,artist:n.artist,album:n.album,duration:n.duration??0,originalFilename:n.originalFilename??"",mimeType:n.mimeType??"audio/mpeg",fileSize:n.fileSize,sha:n.sha??n.sha256,imageSha:r?.blobId,imageType:n.imageType}})}}function QR(e,t){const n=URL.createObjectURL(e),r=document.createElement("a");r.href=n,r.download=t,r.click(),setTimeout(()=>{URL.revokeObjectURL(n),"name"in e&&typeof e.name=="string"&&GR(e.name)},1e3)}async function Ib(e,t={includeImages:!0,generateM3U:!0,includeHTML:!0}){const n=(e.rev??0)+1;await Bf(e.id,{rev:n});const i=(await lt(e.id)).doc(),s=i?Go(e.id,un(i)):null,o={...e,rev:n,_primaryImageSha:s?._primaryImageSha??e._primaryImageSha,imageType:e.imageType??s?.imageType},a=await Hi(e.id),c=XR(o,a),f=Array.from(document.querySelectorAll("script[src]")).find(d=>d.src.includes("freqhole-playlistz.js"))?.src??`${window.location.origin}/freqhole-playlistz.js`,u=await KR(c,YR,{...t,appBundleUrl:f}),h=c.playlist.title.replace(/[^a-zA-Z0-9_-]/g,"_")||"playlist";QR(u,`${h}.zip`)}async function Cb(e){try{const n=await new HO().loadAsync(e);let r=null,i,s;const o=[];let a=null,c=n.file(/^[^/]+\/data\/playlist\.json$/i);if(c.length===0){const d=n.file("data/playlist.json");d&&(c=[d])}if(c.length>0){const d=await c[0].async("string");a=JSON.parse(d),r=a?.playlist||null}else{const d=n.file("playlist-info.json");if(d){const g=await d.async("string");r=JSON.parse(g)}}let l=n.file(/^[^/]+\/data\/playlist-cover\.(jpg|jpeg|png|gif|webp)$/i);l.length===0&&(l=n.file(/^data\/playlist-cover\.(jpg|jpeg|png|gif|webp)$/i)),l.length===0&&(l=n.file(/^playlist-cover\.(jpg|jpeg|png|gif|webp)$/i)),l.length>0?(i=await l[0].async("arraybuffer"),s=fu(l[0].name)):a&&a.playlist?.imageBase64&&(i=kp(a.playlist.imageBase64),s=a.playlist.imageMimeType||void 0);const f=n.file(/\.m3u8?$/i);f.length>0&&await f[0].async("string");let u=n.file(/^[^/]+\/data\/[^/]+\.(mp3|m4a|wav|flac|ogg|webm)$/i);u.length===0&&(u=n.file(/^data\/[^/]+\.(mp3|m4a|wav|flac|ogg|webm)$/i)),u.length===0&&(u=n.file(/^[^/]+\.(mp3|m4a|wav|flac|ogg|webm)$/i));for(const d of u){const g=await d.async("arraybuffer"),p=d.name.split("/").pop()||"",m=p.replace(/\.[^.]+$/,"");let b={};if(a&&a.songs){const T=a.songs.find(j=>j.safeFilename===p||j.originalFilename===p);T&&(b={id:T.id,title:T.title,artist:T.artist,album:T.album,duration:T.duration,originalFilename:T.originalFilename,imageBase64:T.imageBase64,imageMimeType:T.imageMimeType})}else{const T=n.file(`${m}-metadata.json`);if(T){const j=await T.async("string");b=JSON.parse(j)}}let x,_;if(b.imageBase64)x=kp(b.imageBase64),_=b.imageMimeType||void 0;else{let T=n.file(new RegExp(`^[^/]+/data/${m.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}-cover\\.(jpg|jpeg|png|gif|webp)$`,"i"));T.length===0&&(T=n.file(new RegExp(`^data/${m.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}-cover\\.(jpg|jpeg|png|gif|webp)$`,"i"))),T.length===0&&(T=n.file(new RegExp(`^${m.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}-cover\\.(jpg|jpeg|png|gif|webp)$`,"i"))),T.length>0&&(x=await T[0].async("arraybuffer"),_=fu(T[0].name))}const[E,k]=m.includes(" - ")?m.split(" - ",2):["Unknown Artist",m],C={audioData:g,mimeType:fu(p),originalFilename:b.originalFilename||p,title:b.title||k.replace(/_/g," "),artist:b.artist||E.replace(/_/g," "),album:b.album||"Unknown Album",duration:b.duration||0,position:o.length,imageData:x,imageType:_};o.push(C)}return{playlist:{title:r?.title||e.name.replace(/\.zip$/i,""),description:r?.description||"",imageData:i,imageType:s,songIds:[]},songs:o}}catch(t){throw console.error("error parsing playlist zip:",t),t instanceof Error&&(t.message.includes("Corrupted ZIP")||t.message.includes("Invalid JSON")||t.message.includes("Missing playlist"))?t:new Error("Failed to parse playlist ZIP file")}}function fu(e){const t=e.toLowerCase().split(".").pop();return{mp3:"audio/mpeg",m4a:"audio/mp4",wav:"audio/wav",flac:"audio/flac",ogg:"audio/ogg",webm:"audio/webm",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp"}[t||""]||"application/octet-stream"}function kp(e){const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n.buffer}const[Dj,eF]=Q(navigator.onLine),[Rj,tF]=Q(!1),[Fj,Ep]=Q(!1),zb="playlistz-cache-v1";async function nF(){try{if("storage"in navigator&&"persist"in navigator.storage){const e=await navigator.storage.persist();return Ep(!!e),e}else return!1}catch(e){return console.error("Error requesting persistent storage:",e),!1}}function Ob(e,t){const n=e||"playlistz";let r,i;t?(r=t,t.endsWith(".png")?i="image/png":t.endsWith(".webp")?i="image/webp":i="image/jpeg"):(r=`data:image/svg+xml,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="192" height="192" viewBox="0 0 192 192"><rect width="192" height="192" fill="#000000"/><text x="96" y="125" text-anchor="middle" font-size="100" font-family="Arial,sans-serif" font-weight="bold" fill="magenta">z</text></svg>')}`,i="image/svg+xml");const s={name:n,short_name:n.length>12?n.substring(0,12):n,description:"Offline music playlist manager",start_url:"./",display:"standalone",background_color:"#000000",theme_color:"#000000",icons:[{src:r,sizes:"192x192",type:i}]},o=document.querySelector('link[rel="manifest"]');o&&o.remove(),document.querySelectorAll('link[rel="apple-touch-icon"]').forEach(m=>m.remove());const c=JSON.stringify(s),l=new Blob([c],{type:"application/manifest+json"}),f=URL.createObjectURL(l),u=document.createElement("link");u.rel="manifest",u.href=f,document.head.appendChild(u),[{name:"apple-mobile-web-app-capable",content:"yes"},{name:"apple-mobile-web-app-status-bar-style",content:"black-translucent"},{name:"apple-mobile-web-app-title",content:n},{name:"theme-color",content:"#000000"}].forEach(({name:m,content:b})=>{let x=document.querySelector(`meta[name="${m}"]`);x||(x=document.createElement("meta"),x.setAttribute("name",m),document.head.appendChild(x)),x.setAttribute("content",b)});const d=["57x57","60x60","72x72","76x76","114x114","120x120","144x144","152x152","180x180"],g=t||`data:image/svg+xml,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="180" height="180" viewBox="0 0 180 180"><rect width="180" height="180" fill="#000000"/><text x="90" y="117" text-anchor="middle" font-size="94" font-family="Arial,sans-serif" font-weight="bold" fill="magenta">z</text></svg>')}`;d.forEach(m=>{const b=document.createElement("link");b.rel="apple-touch-icon",b.sizes=m,b.href=`${g}#${Date.now()}`,document.head.appendChild(b)});const p=document.createElement("link");p.rel="apple-touch-icon",p.href=`${g}#${Date.now()}`,document.head.appendChild(p)}function rF(e){if(!e.imageData||!e.imageType)return;let t=".jpg";return e.imageType==="image/png"?t=".png":e.imageType==="image/webp"?t=".webp":e.imageType==="image/gif"&&(t=".gif"),`/data/playlist-cover${t}`}function Ap(e,t){console.log("[trace] updatePWAManifest",e);const n=t?rF(t):void 0;Ob(e,n)}async function iF(){try{if(!("serviceWorker"in navigator))return!1;const t=await navigator.serviceWorker.register("/sw.js");if(await navigator.serviceWorker.ready,tF(!0),navigator.serviceWorker.addEventListener("message",n=>{const{type:r}=n.data;r==="SW_READY"&&Ip()}),navigator.serviceWorker.controller)Ip();else{const n=t.active||t.installing||t.waiting;n&&n.postMessage({type:"CLAIM_CLIENTS"})}return!0}catch(e){return console.warn("service worker registration failed:",e),!1}}async function Ip(){try{const e=await caches.open(zb),t=window.location.href;await e.match(t)||await e.add(t)}catch(e){console.warn("⚠️ Failed to auto-cache page:",e)}}async function sF(e,t){try{if(!("caches"in window))throw new Error("Cache API not supported");if(window.location.protocol==="file:")return;if(navigator.serviceWorker&&navigator.serviceWorker.controller){navigator.serviceWorker.controller.postMessage({type:"CACHE_URL",data:{url:e}});return}await (await caches.open(zb)).add(e)}catch(n){throw console.error(`Failed to cache audio file ${t}:`,n),n}}async function Cp(e,t){const n=()=>{eF(navigator.onLine)};window.addEventListener("online",n),window.addEventListener("offline",n),Ob(e,void 0),await nF(),await iF()}const zp="selectedPlaylistId";function oF(){const[e,t]=Q([]),[n,r]=Q(null),i=tr(()=>e().find(v=>v.id===n())??null),s=v=>{v&&t(V=>V.some(L=>L.id===v.id)?V:[...V,v]),r(v?.id??null)},[o,a]=Q([]),[c,l]=Q(!1),[f,u]=Q(null);zt(()=>{const v=n();v&&_o(zp,v)});const[h,d]=Q(!1),[g,p]=Q(!1),[m,b]=Q(0),[x,_]=Q(!1),[E,k]=Q(!1),[C,T]=Q(!1),[j,I]=Q(null),[R]=Q(new Map),[N,D]=Q(null),[y,w]=Q(null),$=Nw();let P=null,A=0;async function J(v){A++;const V=A;Fe.debug("playlist.sync","syncPlaylists #",String(V),"entries:",String(v.length));try{const L=await Promise.all(v.map(async z=>{try{const Y=(await lt(z.docId)).doc(),oe=un(Y??{}),M=await M0(z.docId,oe);return M.remoteNodeId=z.remoteNodeId,M.remoteName=z.remoteName,M.remoteAvatarDataUrl=z.remoteAvatarDataUrl,M.isForked=z.isForked,M}catch{return{id:z.docId,title:z.title,description:void 0,createdAt:z.addedAt,updatedAt:z.addedAt,songIds:[],remoteNodeId:z.remoteNodeId,remoteName:z.remoteName,remoteAvatarDataUrl:z.remoteAvatarDataUrl,isForked:z.isForked}}}));Fe.debug("playlist.sync","syncPlaylists #",String(V),"resolved",String(L.length)),t(L.map(L0));const B=n();if(B)L.some(H=>H.id===B)||r(L.length>0?L[0].id:null);else{const z=await Dc(zp),H=z?L.find(Y=>Y.id===z):null;r(H?H.id:L.length>0?L[0].id:null)}}catch(L){Fe.error("playlist.sync","error syncing playlists from doc index:",L)}}const S=async()=>{try{if(u(null),window.STANDALONE_MODE){await Cp(),await Ap("Playlistz",void 0);const v=window.DEFERRED_PLAYLIST_DATA;if(v&&v.length>0)try{await $O(v,{setSelectedPlaylist:s,setPlaylistSongs:a,setSidebarCollapsed:()=>{},setError:u}),delete window.DEFERRED_PLAYLIST_DATA}catch(V){Fe.error("playlist.init","error initializing deferred playlist:",V),u("failed to initialize playlist!")}SO()}try{await Cp()}catch(v){Fe.warn("playlist.init","offline support initialization failed:",v)}l(!0)}catch(v){Fe.error("playlist.init","error initializing playlist manager:",v),u("failed to initialize playlist")}},U=async(v="new playlist")=>{try{return u(null),await $d({title:v,description:""})}catch(V){return Fe.error("playlist.create","error creating playlist:",V),u("failed to create new playlist!"),null}},O=async(v,V)=>{try{if(u(null),v.length===1&&v[0]?.name.toLowerCase().endsWith(".zip")){const z=v[0];return(await Cb(z)).playlist}const L=qa(Array.from(v));if(L.length===0)return u("no audio filez found!"),null;let B=V;if(!B){const z=await U("dropped filez");if(!z)return null;B=z.id}for(const z of L)await kd(B,z);return B}catch(L){return Fe.error("playlist.drop","error handling file drop:",L),u("failed to process dropped files"),null}};zt(()=>{const v=$();Fe.debug("playlist.docindex","docIndex effect fired, entries:",String(v.length)),J(v)}),zt(()=>{const v=mO();v&&e().some(V=>V.id===v)&&(r(v),Wa(null))}),zt(Ia(n,v=>{if(Fe.debug("playlist.select","selection effect fired:",v??"null"),P&&(P(),P=null),!v){a([]);return}let V=!1,L=0;const B=async z=>{L++,Fe.debug("playlist.select","selected-doc refresh #",String(L),v);try{const H=z.doc(),Y=un(H??{}),oe=await M0(v,Y);t(te=>te.map(ge=>ge.id!==v?ge:L0({...oe,remoteNodeId:ge.remoteNodeId,remoteName:ge.remoteName,remoteAvatarDataUrl:ge.remoteAvatarDataUrl,isForked:ge.isForked})));const M=await Ay(v,z);V||a(Mf(M))}catch(H){Fe.error("playlist.select","error refreshing selected playlist doc:",H)}};(async()=>{try{const z=await lt(v);if(V)return;const H=()=>{Fe.debug("playlist.select","selected-doc change event -> refresh",v),B(z)};z.on("change",H),P=()=>z.off("change",H),await B(z)}catch(z){Fe.error("playlist.select","error subscribing to playlist doc:",z),V||a([])}})(),rn(()=>{V=!0})})),zt(()=>{const v=N(),V=Ye.currentSong(),L=Ye.currentPlaylist(),B=i(),z=R();let H=null,Y=null;v&&v!=="cover"&&v.imageType?(Y=`song-${v.id}`,z.has(Y)?H=z.get(Y):(H=Vn(v,"background"),H&&z.set(Y,H))):v==="cover"&&B?.imageType?(Y=`playlist-${B.id}`,z.has(Y)?H=z.get(Y):(H=Vn(B,"background"),H&&z.set(Y,H))):V?.imageType?(Y=`song-${V.id}`,z.has(Y)?H=z.get(Y):(H=Vn(V,"background"),H&&z.set(Y,H))):V&&L?.imageType?(Y=`playlist-${L.id}`,z.has(Y)?H=z.get(Y):(H=Vn(L,"background"),H&&z.set(Y,H))):B?.imageType&&(Y=`playlist-${B.id}`,z.has(Y)?H=z.get(Y):(H=Vn(B,"background"),H&&z.set(Y,H))),j()!==H&&I(H),w(Y)}),zt(()=>{const v=i();v&&(Fe.debug("playlist.manifest","PWA manifest effect fired",v.id),Ap(v.title,v))});const F=v=>e().find(V=>V.id===v),X=v=>e().some(V=>V.id===v),ie=()=>e().length,se=v=>{if(!v.trim())return e();const V=v.toLowerCase();return e().filter(L=>L.title.toLowerCase().includes(V)||(L.description||"").toLowerCase().includes(V))},$e=v=>{r(v?.id??null)},Ce=v=>{r(v)},Oe=async v=>{const V=i();if(V){Fe.debug("playlist.update","handlePlaylistUpdate",V.id,JSON.stringify(v));try{u(null),await Bf(V.id,{title:v.title,description:v.description})}catch(L){Fe.error("playlist.update","error updating playlist:",L),u("failed to update playlist!")}}},ye=async()=>{const v=i();if(v)try{u(null);const V=Ye.currentSong();V&&V.playlistId===v.id&&Ad(),await Iy(v.id),s(null),p(!1)}catch(V){Fe.error("playlist.delete","error deleting playlist:",V),u("failed to delete playlist!")}},ve=async()=>{const v=i();if(v){_(!0);try{u(null),await Ib(v,{includeImages:!0,generateM3U:!0,includeHTML:!0})}catch(V){Fe.error("playlist.download","error downloading playlist:",V),u("failed to download playlist!")}finally{_(!1)}}},me=async(v,V)=>{const L=i();if(L)try{u(null);const B=Ye.currentSong();B&&B.id===v&&Ad(),await uO(L.id,v),V&&V()}catch(B){Fe.error("playlist.songs","error removing song from playlist:",B),u("failed to remove song from playlist!")}},_e=async(v,V)=>{const L=i();if(L)try{u(null),await dO(L.id,v,V);const B=Ye.currentPlaylist();if(B&&B.id===L.id){const z=i();z&&await Ny(z)}}catch(B){Fe.error("playlist.songs","error reordering songz:",B),u("failed to reorder songz")}},xe=async()=>{const v=o();if(v.length!==0){k(!0);try{u(null);for(const V of v){const L=V.blobUrl;if(L&&V.id)try{await sF(L,V.title||"unknown song")}catch{}}T(!0)}catch(V){Fe.error("playlist.cache","error caching playlist:",V),u("failed to cache playlist for offline use!")}finally{k(!1)}}};return sr(S),rn(()=>{P&&(P(),P=null);const v=R();v.forEach(V=>{V.startsWith("blob:")&&URL.revokeObjectURL(V)}),v.clear()}),zt(()=>{if(f()){const V=setTimeout(()=>{u(null)},1e4);rn(()=>clearTimeout(V))}}),{playlists:e,selectedPlaylist:i,playlistSongs:o,isInitialized:c,error:f,backgroundImageUrl:j,backgroundSource:y,imageUrlCache:R,showImageModal:h,showDeleteConfirm:g,modalImageIndex:m,isDownloading:x,isCaching:E,allSongsCached:C,setSelectedPlaylist:s,setPlaylistSongs:a,setShowImageModal:d,setShowDeleteConfirm:p,setModalImageIndex:b,setBackgroundOverride:D,initialize:S,createNewPlaylist:U,handleFileDrop:O,selectPlaylist:$e,selectById:Ce,handlePlaylistUpdate:Oe,handleDeletePlaylist:ye,handleDownloadPlaylist:ve,handleRemoveSong:me,handleReorderSongs:_e,handleCachePlaylist:xe,getPlaylistById:F,playlistExists:X,getPlaylistCount:ie,searchPlaylists:se}}function aF(){const[e,t]=Q(null),[n,r]=Q(!1),i=()=>e()!==null||n(),[s,o]=Q(null);return{editingSong:e,editingPlaylist:n,isEditMode:i,error:s,setEditingSong:t,setEditingPlaylist:r,handleEditSong:p=>{t(p)},handleEditPlaylist:()=>{t(null),r(!0)},handleCloseEdit:()=>{rw(()=>{t(null),r(!1)})},handleSongSaved:async p=>{try{o(null),await lO(p.playlistId,p.id,p),t(p)}catch(m){Fe.error("song.save","error saving song:",m),o("failed to save song changes")}},handlePlaySong:async(p,m)=>{try{o(null),m?await Zy(p,m):await Zi(p)}catch(b){Fe.error("song.play","error playing song:",b),o("failed to play song")}},handlePauseSong:async()=>{try{o(null),await jo()}catch(p){Fe.error("song.play","error pausing song:",p),o("Failed to pause song")}},isSongPlaying:p=>Ye.currentSong()?.id===p&&Ye.isPlaying(),isSongSelected:p=>Ye.currentSong()?.id===p}}function cF(){const[e,t]=Q(!1),[n,r]=Q(!1),[i,s]=Q(null),[o]=Q(new Map),a=()=>{const f=window.innerWidth<900;t(f)},c=()=>{a()},l=f=>{if(f.key==="Escape")return{key:f.key,preventDefault:()=>f.preventDefault()}};return sr(()=>{a(),window.addEventListener("resize",c),document.addEventListener("keydown",l),rn(()=>{window.removeEventListener("resize",c),document.removeEventListener("keydown",l)})}),rn(()=>{const f=o();f.forEach(u=>{u.startsWith("blob:")&&URL.revokeObjectURL(u)}),f.clear()}),{isMobile:e,isDragOver:n,backgroundImageUrl:i,imageUrlCache:o,setIsMobile:t,setIsDragOver:r,setBackgroundImageUrl:s,checkMobile:a}}function lF(){const[e,t]=Q(!1),[n,r]=Q({type:"unknown",itemCount:0}),[i,s]=Q(null),o=m=>{const b=m.dataTransfer?.types;if(b&&b.includes("text/plain")&&!b.includes("Files"))return{type:"song-reorder",itemCount:1};if(b&&b.includes("Files"))return{type:"audio-files",itemCount:1};const x=m.dataTransfer?.getData("text/plain");if(x&&!isNaN(parseInt(x,10)))return{type:"song-reorder",itemCount:1};const _=m.dataTransfer?.getData("application/json");if(_)try{if(JSON.parse(_).type==="song-reorder")return{type:"song-reorder",itemCount:1}}catch{}const E=m.dataTransfer?.items;if(E&&E.length>0&&Array.from(E).some(T=>T.kind==="file"))return{type:"audio-files",itemCount:E.length};const k=m.dataTransfer?.files;if(k&&k.length>0){const C=Array.from(k).filter(j=>j.type==="application/zip"||j.name.toLowerCase().endsWith(".zip"));if(C.length>0)return{type:"audio-files",itemCount:C.length};const T=qa(k);return T.length>0?{type:"audio-files",itemCount:T.length}:{type:"non-audio-files",itemCount:k.length}}return{type:"unknown",itemCount:0}},a=m=>{m.preventDefault(),m.stopPropagation();const b=o(m);r(b),b.type!=="song-reorder"&&t(!0)},c=m=>{m.preventDefault(),m.stopPropagation();const b=n();b.type==="audio-files"||b.type==="song-reorder"?m.dataTransfer.dropEffect="copy":m.dataTransfer.dropEffect="none"},l=m=>{if(m.preventDefault(),m.stopPropagation(),n().type==="song-reorder")return;const x=m.currentTarget.getBoundingClientRect(),_=m.clientX,E=m.clientY;(_<x.left||_>x.right||E<x.top||E>x.bottom)&&(t(!1),r({type:"unknown",itemCount:0}))},f=async(m,b)=>{m.preventDefault(),m.stopPropagation(),t(!1);const x=n();if(r({type:"unknown",itemCount:0}),x.type==="song-reorder")return;const _=m.dataTransfer?.files;if(_)try{s(null);const E=Array.from(_).filter(C=>C.type==="application/zip"||C.name.toLowerCase().endsWith(".zip"));if(E.length>0){await h(E,b);return}const k=qa(_);if(k.length===0){g(x);return}await d(k,b)}catch(E){throw Fe.error("drag.drop","error handling file drop:",E),s("Failed to process dropped files"),setTimeout(()=>s(null),5e3),E}},u=async(m,b)=>{const x=m.filter(E=>E.type==="application/zip"||E.name.toLowerCase().endsWith(".zip"));if(x.length>0){await h(x,b);return}const _=qa(m);_.length>0&&await d(_,b)},h=async(m,b)=>{for(const x of m){const{playlist:_,songs:E}=await Cb(x);if(Fe.debug("handleZipFiles",`parsed zip: title="${_.title}" songs=${E.length} existing playlists=${b.playlists.length}`),b.playlists.find(T=>T.title===_.title&&T.songIds.length===E.length)){Fe.debug("handleZipFiles",`dedup match: "${_.title}" already exists`),s(`Playlist "${_.title}" already exists`),setTimeout(()=>s(null),3e3);continue}const C=await $d({title:_.title,description:_.description});Fe.debug("handleZipFiles",`created playlist ${C.id}, adding ${E.length} songs`);for(const T of E){Fe.debug("handleZipFiles",`adding song "${T.title}" audioData=${T.audioData?.byteLength??"none"}`);const j=new Blob([T.audioData],{type:T.mimeType}),I=new File([j],T.originalFilename||`${T.artist} - ${T.title}`,{type:T.mimeType});await kd(C.id,I,{title:T.title,artist:T.artist,album:T.album,duration:T.duration,imageData:T.imageData,imageType:T.imageType})}b.onPlaylistCreated?.(C),b.onPlaylistSelected?.(C)}},d=async(m,b)=>{let x=b.selectedPlaylist;x||(x=await $d({title:"new playlist",description:`created from ${m.length} dropped file${m.length>1?"z":""}`}),b.onPlaylistCreated?.(x),b.onPlaylistSelected?.(x));for(const _ of m){const E=await MO(_);await kd(x.id,_,E)}},g=m=>{m.type==="non-audio-files"?s("only audio filez and ZIP playlist filez can be added. supported formatz: MP3, WAV, M4A, FLAC, OGG, ZIP"):s("no audio filez or ZIP playlist filez found in the dropped itemz!"),setTimeout(()=>s(null),3e3)};return sr(()=>{const m=b=>{b.preventDefault(),b.stopPropagation()};document.addEventListener("dragenter",m),document.addEventListener("dragover",m),document.addEventListener("dragleave",m),document.addEventListener("drop",m),rn(()=>{document.removeEventListener("dragenter",m),document.removeEventListener("dragover",m),document.removeEventListener("dragleave",m),document.removeEventListener("drop",m)})}),zt(()=>{if(i()){const b=setTimeout(()=>{s(null)},1e4);rn(()=>clearTimeout(b))}}),{isDragOver:e,dragInfo:n,error:i,setIsDragOver:t,handleDragEnter:a,handleDragOver:c,handleDragLeave:l,handleDrop:f,handleFileDrop:async(m,b)=>{try{await f(m,b)}catch(x){Fe.error("drag.drop","error in handleFileDrop:",x),t(!1)}},processFileImport:u,analyzeDragData:o}}function uF(){const[e,t]=Q(!1),[n,r]=Q(0),[i,s]=Q([]),o=(_,E=[])=>{const k=[];if(_?.imageType||_?.imageFilePath){const C=Vn(_,"modal");C&&k.push({url:C,title:_.title,type:"playlist",id:_.id})}return E.forEach(C=>{if(C.imageType||C.imageFilePath){const T=Vn(C,"modal");T&&k.push({url:T,title:C.title,type:"song",id:C.id})}}),k},a=(_,E=[],k=0)=>{const C=o(_,E);C.length!==0&&(s(C),r(Math.min(k,C.length-1)),t(!0))},c=()=>{t(!1),r(0),s([])},l=()=>{const _=i();_.length<=1||r(E=>(E+1)%_.length)},f=()=>{const _=i();_.length<=1||r(E=>(E-1+_.length)%_.length)},u=_=>{const E=i();_>=0&&_<E.length&&r(_)},h=()=>{const _=i(),E=n();return _[E]?.url||null},d=()=>{const _=i(),E=n();return _[E]||null},g=()=>{const _=i(),E=n();return _[E]?.title||null},p=()=>i().length,m=()=>n()+1,b=()=>i().length>1,x=_=>{if(e())switch(_.key){case"Escape":_.preventDefault(),c();break;case"ArrowLeft":_.preventDefault(),f();break;case"ArrowRight":_.preventDefault(),l();break;case"Home":_.preventDefault(),u(0);break;case"End":_.preventDefault(),u(p()-1);break;default:{const E=parseInt(_.key);if(!isNaN(E)&&E>=1&&E<=9){const k=E-1;k<p()&&(_.preventDefault(),u(k))}break}}};return zt(()=>{e()&&(document.addEventListener("keydown",x),rn(()=>{document.removeEventListener("keydown",x)}))}),{showImageModal:e,modalImageIndex:n,modalImages:i,setShowImageModal:t,setModalImageIndex:r,openImageModal:a,closeImageModal:c,handleNextImage:l,handlePrevImage:f,goToImage:u,getCurrentImageUrl:h,getCurrentImageMetadata:d,getCurrentImageTitle:g,getImageCount:p,getCurrentImageNumber:m,hasMultipleImages:b,generateImageList:o}}const Pb=sw(),dF=e=>{const t=oF(),n=aF(),r=cF(),i=lF(),s=uF(),o={playlistManager:t,songState:n,uiState:r,dragAndDrop:i,imageModal:s};return re(Pb.Provider,{value:o,get children(){return e.children}})};function Qo(){const e=ow(Pb);if(!e)throw new Error("usePlaylistzContext must be used within a PlaylistzProvider");return e}function Ms(){return Qo().playlistManager}function Tb(){return Qo().songState}function Db(){return Qo().uiState}function Rb(){return Qo().dragAndDrop}function Fb(){return Qo().imageModal}const Bb="p2p:endpoint";async function jr(){return await Dc(Bb)??{name:"",mode:"knock"}}async function Ub(e){await _o(Bb,e),fF(e)}async function fF(e){if(!Od)return;let t;try{t=wr()}catch{return}const n=await Br().catch(()=>[]),r=new Set,i=_n()?.node_id??"";for(const s of n){const o=s.remoteNodeId;!o||o===i||r.has(o)||(r.add(o),t.isConnected(o)&&(async()=>{try{const a=await Wi(o);try{await jt(a,{v:1,type:"identity_update",...e.name?{name:e.name}:{},...e.avatarDataUrl?{avatarDataUrl:e.avatarDataUrl}:{}})}finally{a.close()}}catch{}})())}}let Od=!1,Op=!1,Pp=!1,Tp=null;const Pd=new Set;function oh(e){return Pd.add(e),()=>{Pd.delete(e)}}function Cc(){for(const e of Pd)try{e()}catch{}}async function ar(){await T9(),Od||(Od=!0,wr().registerAlpnHandler(Kc,t=>{Zb(t)})),Pp||(Pp=!0,wy(e=>{e&&!Op&&(Op=!0,Td(),Tp||(Tp=setInterval(()=>void Td(),9e4)))})),await R9()}async function hF(){await by()&&await ar()}async function gF(e){const t=_n(),n=await jr().catch(()=>({name:"",mode:"knock"}));let r,i;try{const a=await Wi(e);try{await jt(a,{v:1,type:"hello",nodeId:t?.node_id??"",...n.name?{name:n.name}:{}});const c=await di(a);c?.type==="hello_ok"&&(r=c.name,i=c.avatarDataUrl)}finally{a.close()}}catch{return}if(!r&&!i)return;const s=await Br().catch(()=>[]);for(const a of s)a.remoteNodeId===e&&await or({...a,...r?{remoteName:r}:{},...i?{remoteAvatarDataUrl:i}:{}}).catch(()=>{});const o=await Qs(e).catch(()=>{});o&&await Rc({...o,...r?{name:r}:{},...i?{avatarDataUrl:i}:{}}).catch(()=>{})}async function Td(){const t=_n()?.node_id??"",n=wr(),r=await Br(),i=new Set;for(const s of r)s.remoteNodeId&&s.remoteNodeId!==t&&xy(s.docId,s.remoteNodeId);for(const s of r)try{const a=(await lt(s.docId)).doc();if(!a)continue;for(const c of Object.keys(a.peers??{}))c&&c!==t&&!i.has(c)&&(i.add(c),n.addPeer(c).then(async()=>{gF(c)}).catch(l=>{Fe.warn("p2p.reconnect","reconnect to peer failed:",c.slice(0,16),l)}))}catch{}}async function jb(e,t){await ar();const n=_n();if(!n?.node_id)throw new Error("p2p node is not running - cannot create a share link without a node id");const r=await jr(),i={v:1,n:n.node_id,d:e,...t?{t}:{},...r.mode==="knock"?{m:"knock"}:{}},s=sy(i),o=Vz(i),a=`${window.location.origin}${window.location.pathname}`;return{token:s,url:`${a}${o}`,fragment:o}}async function Mb(e){const t=_n(),n=wr(),r=await jr();xy(e.d,e.n);let i,s;try{const u=await Wi(e.n);try{await jt(u,{v:1,type:"hello",nodeId:t?.node_id??"",...r.name?{name:r.name}:{}});const h=await di(u);h?.type==="hello_ok"&&(i=h.name,s=h.avatarDataUrl)}finally{u.close()}}catch{}if(!await Oi(e.d).catch(()=>null))for(let u=0;;u++)try{await n.addPeer(e.n);break}catch(h){if(u>=5){Fe.warn("p2p.connect","could not connect to sharing peer:",h);break}await new Promise(d=>setTimeout(d,5e3))}const a=await lt(e.d),c=a.doc(),l=t?.node_id;if(c){const u=c.peers??{},h=!!l&&!(l in u),d=!(e.n in u);(h||d)&&(a.change(g=>{h&&l&&To(g,l),d&&To(g,e.n)}),await dn(e.d))}const f=await Oi(e.d);return f?(i||s)&&await or({...f,...i?{remoteName:i}:{},...s?{remoteAvatarDataUrl:s}:{}}):await or({docId:e.d,title:c?.title||e.t||"shared playlist",addedAt:Date.now(),source:"shared",remoteNodeId:e.n,remoteName:i,remoteAvatarDataUrl:s}),{status:"synced",docId:e.d}}async function ll(e){const t=oy(e);if(!t)throw new Error("invalid share link");return await ar(),await Oi(t.d).catch(()=>null)?{status:"synced",docId:t.d}:t.m==="knock"?{status:"knock_required",ownerNodeId:t.n,docId:t.d,title:t.t}:Mb(t)}async function pF(){const e=window.location.hash;if(!e.startsWith("#share/"))return null;try{const t=await ll(e);return history.replaceState(null,"",window.location.pathname),t}catch(t){throw Fe.error("share.fragment","failed to open share link:",t),history.replaceState(null,"",window.location.pathname),t}}async function Wi(e){await ar();const t=yy();if(!t)throw new Error("p2p node is not running in this tab");return await t.open_bi(e,Kc)}async function Lb(e){const t=_n(),n=await jr(),r=await Wi(e);try{await jt(r,{v:1,type:"hello",nodeId:t?.node_id??"",...n.name?{name:n.name}:{}});const i=await di(r);if(i?.type!=="hello_ok")throw new Error("peer did not answer hello");await jt(r,{v:1,type:"list_playlists"});const s=await di(r);if(s?.type==="playlists")return{nodeId:e,name:i.name,avatarDataUrl:i.avatarDataUrl,public:i.public,items:s.items,knockRequired:!1};if(s?.type==="error"&&s.code==="knock_required")return{nodeId:e,name:i.name,avatarDataUrl:i.avatarDataUrl,public:i.public,items:[],knockRequired:!0};throw new Error("unexpected reply to list_playlists")}finally{r.close()}}async function ah(e,t){const n=_n(),r=await jr(),i=await Wi(e);let s;try{await jt(i,{v:1,type:"knock",nodeId:n?.node_id??"",...r.name?{name:r.name}:{},...t?{message:t}:{}}),s=await di(i)}finally{i.close()}if(s?.type!=="knock_status")throw new Error("peer did not answer knock");await ws({id:`out:${e}`,nodeId:e,direction:"outbound",name:"",message:t??"",status:s.status==="denied"?"rejected":s.status,createdAt:Date.now(),...s.status!=="pending"?{processedAt:Date.now()}:{}});const o=s.grantedDocIds??[];if(s.status==="accepted"&&o.length>0){await wr().addPeer(e).catch(()=>{});for(const c of o)try{const l=await lt(c),f=l.doc(),u=n?.node_id;u&&f&&!(u in(f.peers??{}))&&(l.change(h=>To(h,u)),await dn(c)),await Oi(c)||await or({docId:c,title:f?.title||"shared playlist",addedAt:Date.now(),source:"shared",remoteNodeId:e})}catch(l){Fe.warn("p2p.knock","failed to open granted doc:",c,l)}}return{status:s.status,docIds:o}}async function zc(e,t,n,r){const i=_n(),s=await jr(),o=await Wi(e);let a;try{await jt(o,{v:1,type:"knock",nodeId:i?.node_id??"",...s.name?{name:s.name}:{},...n?{message:n}:{},knockType:"doc_access",docId:t}),a=await di(o)}finally{o.close()}if(a?.type!=="knock_status")throw new Error("peer did not answer knock");return await ws({id:`out:${e}:doc:${t}`,nodeId:e,direction:"outbound",name:"",message:n,status:a.status==="denied"?"rejected":a.status,createdAt:Date.now(),knockType:"doc_access",requestedDocId:t,...a.status!=="pending"?{processedAt:Date.now()}:{}}),a.status==="accepted"&&(a.grantedDocIds??[t]).includes(t)&&await Mb({v:1,n:e,d:t,...r?{t:r}:{}}),{status:a.status}}async function Nb(e,t){const r=(await vs()).find(c=>c.id===e);if(!r)throw new Error("knock not found");const s=(await Br().catch(()=>[])).find(c=>c.remoteNodeId===r.nodeId);await Rc({nodeId:r.nodeId,name:r.name,grantedAt:Date.now(),docIds:t,...s?.remoteAvatarDataUrl?{avatarDataUrl:s.remoteAvatarDataUrl}:{}}),await ws({...r,status:"accepted",processedAt:Date.now()});for(const c of t)try{const l=await lt(c),f=l.doc();f&&!(r.nodeId in(f.peers??{}))&&(l.change(u=>To(u,r.nodeId)),await dn(c))}catch(l){Fe.warn("p2p.knock","failed to record peer in doc:",c,l)}await wr().addPeer(r.nodeId).catch(()=>{});const a=_n();(async()=>{try{const c=await Wi(r.nodeId);try{await jt(c,{v:1,type:"knock_notify",status:"accepted",docIds:t,ownerNodeId:a?.node_id??""})}finally{c.close()}}catch{}})(),Cc()}async function Hb(e){const n=(await vs()).find(r=>r.id===e);n&&(await ws({...n,status:"rejected",processedAt:Date.now()}),Cc())}async function ch(){return(await vs()).filter(t=>t.direction==="inbound").sort((t,n)=>n.createdAt-t.createdAt)}async function lh(){return(await vs()).filter(t=>t.direction==="outbound").sort((t,n)=>n.createdAt-t.createdAt)}async function mF(){const e=await Br(),t=[];for(const n of e)try{const i=(await lt(n.docId)).doc();t.push({docId:n.docId,title:i?.title||n.title,songCount:i?Object.keys(i.songs??{}).length:0})}catch{t.push({docId:n.docId,title:n.title,songCount:0})}return t}async function Zb(e){const t=e.peer_node_id();try{for(;;){const n=await di(e);if(n===null)break;await _F(e,t,n)}}catch(n){Fe.warn("p2p.protocol","protocol stream error:",n)}finally{try{e.close()}catch{}}}async function _F(e,t,n){const r=_n(),i=await jr();switch(n.type){case"hello":{await jt(e,{v:1,type:"hello_ok",nodeId:r?.node_id??"",...i.name?{name:i.name}:{},...i.avatarDataUrl?{avatarDataUrl:i.avatarDataUrl}:{},public:i.mode==="public"});break}case"list_playlists":{const s=await Qs(t);if(i.mode!=="public"&&!s){await jt(e,{v:1,type:"error",code:"knock_required",message:"this node requires a knock before listing playlists"});break}let o=await mF();if(i.mode!=="public"&&s?.docIds){const a=new Set(s.docIds);o=o.filter(c=>a.has(c.docId))}await jt(e,{v:1,type:"playlists",items:o});break}case"knock":{const s=n.knockType==="doc_access"&&!!n.docId,o=await Qs(n.nodeId);if(s&&n.docId){let l=!1;try{l=!!(await lt(n.docId)).doc()?.collaborative}catch{}const f=i.mode==="public"||o&&(!o.docIds||o.docIds.includes(n.docId));if(l&&f){await jt(e,{v:1,type:"knock_status",status:"accepted",grantedDocIds:[n.docId]});break}}else if(o){await jt(e,{v:1,type:"knock_status",status:"accepted",grantedDocIds:o.docIds??[]});break}const c=(await vs()).find(l=>l.direction==="inbound"&&l.nodeId===n.nodeId&&(s?l.knockType==="doc_access"&&l.requestedDocId===n.docId:l.knockType!=="doc_access"));if(c?.status==="rejected"){await jt(e,{v:1,type:"knock_status",status:"denied"});break}c||(await ws({id:crypto.randomUUID(),nodeId:n.nodeId,direction:"inbound",name:n.name??"",message:n.message??"",status:"pending",createdAt:Date.now(),knockType:s?"doc_access":"browse",...s&&n.docId?{requestedDocId:n.docId}:{}}),Cc()),await jt(e,{v:1,type:"knock_status",status:"pending"});break}case"blob_request":{const s=await Qs(t);if(i.mode!=="public"&&!s){await jt(e,{v:1,type:"error",code:"knock_required",message:"access denied: knock required before requesting blobs"});break}await q9(e,n.sha256);break}case"knock_notify":{const s=_n()?.node_id??"";for(const a of n.docIds)try{const c=await lt(a),l=c.doc();s&&l&&!(s in(l.peers??{}))&&(c.change(f=>To(f,s)),await dn(a)),await Oi(a)||await or({docId:a,title:l?.title||"shared playlist",addedAt:Date.now(),source:"shared",remoteNodeId:n.ownerNodeId})}catch(c){Fe.warn("p2p.knock","failed to sync granted doc from notify:",a,c)}const o=await vs();for(const a of o)a.direction==="outbound"&&a.nodeId===t&&a.status==="pending"&&await ws({...a,status:"accepted",processedAt:Date.now()});Cc();break}case"identity_update":{const s=[],o=await Br();for(const c of o){if(c.remoteNodeId!==t)continue;const l={...c,...n.name!==void 0?{remoteName:n.name}:{},...n.avatarDataUrl!==void 0?{remoteAvatarDataUrl:n.avatarDataUrl}:{}};s.push(or(l))}const a=await Qs(t).catch(()=>{});a&&s.push(Rc({...a,...n.name!==void 0?{name:n.name}:{},...n.avatarDataUrl!==void 0?{avatarDataUrl:n.avatarDataUrl}:{}})),await Promise.allSettled(s);break}default:await jt(e,{v:1,type:"error",code:"unexpected_message",message:`unexpected message type: ${n.type}`})}}const Dd=Object.freeze(Object.defineProperty({__proto__:null,acceptKnock:Nb,buildShareLink:jb,denyKnock:Hb,ensureSharingReady:ar,getInboundKnocks:ch,getOutboundKnocks:lh,getShareSettings:jr,handlePlaylistzStream:Zb,handleShareFragment:pF,knockForDocAccess:zc,knockOnPeer:ah,onKnocksChanged:oh,openShareLink:ll,queryPeerPlaylists:Lb,reconnectKnownPeers:Td,resumeSharingIfEnabled:hF,saveShareSettings:Ub},Symbol.toStringTag,{value:"Module"})),Vb="p2p:endpoint_enabled",[Rd,Fd]=Q(!1),[Dp,yF]=Q(0),[os,Wb]=Q(!1),[Kr,qb]=Q(0),[hu,bF]=Q(!1),[gu,Ka]=Q(!!_n()?.node_id),[Rp,wF]=Q(0);let Fp=!1;async function Bp(){try{const e=await ch();yF(e.filter(n=>n.status==="pending").length);const t=await lh();wF(t.filter(n=>n.status==="pending").length)}catch{}}function Up(){try{const e=wr().getConnectionSummary();qb(e.connected)}catch{}}function Jb(){Fp||(Fp=!0,oh(()=>void Bp()),Bp(),setInterval(Up,3e3),Up(),eO(()=>{bF(tO()>0)}),Dc(Vb).then(e=>{!!_n()?.node_id?Ka(!0):by().then(n=>{n&&Ka(!0)}),e===!0&&(Wb(!0),ar().then(()=>Fd(!0)).catch(()=>{})),zf(n=>{n?.node_id&&Ka(!0)})}))}async function vF(){const e=!os();Wb(e),await _o(Vb,e),e?(await ar(),Fd(!0),Ka(!0)):(D9(),Fd(!1),qb(0))}var xF=ee('<svg class="w-6 h-6 animate-spin"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15">'),SF=ee("<button data-testid=btn-play-playlist>"),$F=ee('<svg class="w-10 h-10"fill=currentColor viewBox="0 0 20 20"><path fill-rule=evenodd d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zM7 8a1 1 0 012 0v4a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v4a1 1 0 102 0V8a1 1 0 00-1-1z"clip-rule=evenodd>'),kF=ee('<svg class="w-10 h-10 ml-0.5"fill=currentColor viewBox="0 0 20 20"><path fill-opacity=1.0 fill-rule=evenodd d="M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z"clip-rule=evenodd>');function EF(e){const t=async()=>{try{if(!e.playlist||e.playlist.songIds.length===0)return;const o=Ye.currentPlaylist();o&&o.id===e.playlist.id?await jo():await qf(e.playlist)}catch(o){console.error("error in audio player:",o)}},n=()=>Ye.currentSong()?.id===Ye.selectedSongId()&&Ye.isLoading(),r=()=>{const o=Ye.currentSong()?.sha??Ye.currentSong()?.sha256;return o?$y().get(o)==="downloading":!1},i=()=>n()||r(),s=()=>{if(!e.playlist)return!1;const o=Ye.currentPlaylist();return Ye.isPlaying()&&o&&o.id===e.playlist.id};return(()=>{var o=SF();return o.$$click=t,Z(o,re(he,{get when(){return i()},get fallback(){return re(he,{get when(){return s()},get fallback(){return kF()},get children(){return $F()}})},get children(){return xF()}})),we(a=>{var c=s()?"true":"false",l=i(),f=`inline-flex items-center justify-center ${e.size||"w-12 h-12"} disabled:bg-gray-600 disabled:cursor-not-allowed rounded-full text-white hover:text-magenta-200 transition-colors mx-2 ${s()?"bg-magenta-500":"hover:bg-magenta-500"}`;return c!==a.e&&Ne(o,"aria-pressed",a.e=c),l!==a.t&&Ne(o,"aria-busy",a.t=l),f!==a.a&&ht(o,a.a=f),a},{e:void 0,t:void 0,a:void 0}),o})()}Fr(["click"]);const so=new Set;let ho=null;function AF(){ho||(ho=window.setInterval(()=>{so.forEach(e=>e())},6e4))}function IF(){ho&&(window.clearInterval(ho),ho=null)}function Kb(e){const[t,n]=Q("");function r(){const o=Date.now()-e;let a;if(o<6e4)a="just now";else if(o<36e5){const c=Math.floor(o/6e4);a=`${c} ${c===1?"minute":"minutes"} ago`}else if(o<864e5){const c=Math.floor(o/36e5);a=`${c} ${c===1?"hour":"hours"} ago`}else if(o<6048e5){const c=Math.floor(o/864e5);a=`${c} ${c===1?"day":"days"} ago`}else if(o<2629746e3){const c=Math.floor(o/6048e5);a=`${c} ${c===1?"week":"weeks"} ago`}else if(o<31556952e3){const c=Math.floor(o/2629746e3);a=`${c} ${c===1?"month":"months"} ago`}else{const c=Math.floor(o/31556952e3);a=`${c} ${c===1?"year":"years"} ago`}n(a)}return r(),so.add(r),so.size===1&&AF(),{signal:t,destroy:()=>{so.delete(r),so.size===0&&IF()},update:r}}function Bd(e){if(isNaN(e)||e<0)return"0:00";const t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=Math.floor(e%60);return t>0?`${t}:${n.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`:`${n}:${r.toString().padStart(2,"0")}`}var CF=ee('<div class="flex items-center p-3 bg-gray-800 bg-opacity-30 animate-pulse"><div class="w-12 h-12 bg-gray-700 mr-4"></div><div class=flex-1><div class="h-4 bg-gray-700 rounded mb-2 w-3/4"></div><div class="h-3 bg-gray-700 rounded w-1/2"></div></div><div class="w-16 h-4 bg-gray-700 rounded">'),zF=ee('<div class="flex items-center p-3 bg-red-900 bg-opacity-20 border border-red-500 border-opacity-30"><div class="w-12 h-12 bg-red-800 mr-4 flex items-center justify-center"><svg class="w-6 h-6 text-red-400"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.732-.833-2.5 0L4.268 16.5c-.77.833.192 2.5 1.732 2.5z"></path></svg></div><div class=flex-1><div class="text-red-400 font-medium">song not found</div><div class="text-red-300 text-sm">id: '),OF=ee('<svg class="absolute inset-0 w-8 h-8 transform -rotate-90"viewBox="0 0 32 32"><circle cx=16 cy=16 r=14 stroke="rgba(255, 255, 255, 0.2)"stroke-width=2 fill=none></circle><circle cx=16 cy=16 r=14 stroke-width=2 fill=none stroke-linecap=round class="transition-all duration-300">'),PF=ee('<div class="absolute inset-0 bg-black bg-opacity-50 flex items-center justify-center z-1"><div class="relative w-8 h-8"><svg fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15">'),TF=ee('<svg class="w-5 h-5"fill=currentColor viewBox="0 0 24 24"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z">'),DF=ee('<button class="absolute inset-0 bg-transparent flex items-center justify-center transition-opacity hover:bg-opacity-80 text-magenta-300 hover:text-magenta-100">'),RF=ee('<span class="font-mono w-12 text-right tabular-nums">'),FF=ee('<div class="text-xs mt-1 text-magenta-200 flex items-center"><span class="font-mono w-12 text-left tabular-nums"></span><div class="flex-1 relative h-4 flex items-center seek-bar-container"><input type=range min=0 class="w-full h-2 bg-gray-700 rounded-full appearance-none cursor-pointer hover:bg-gray-600 transition-colors seek-slider">'),BF=ee('<div class="text-xs mt-1 text-magenta-200">added '),UF=ee('<button data-testid=btn-remove-song class="p-1 text-red-400 hover:text-red-300 transition-colors hover:bg-red-600 hover:bg-opacity-30"title="remove from playlist"><svg class="w-3 h-3"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16">'),jF=ee('<div class="absolute right-2 top-1/2 transform -translate-y-1/2 flex items-center gap-1 bg-black bg-opacity-80 px-2 py-1 z-50"><button data-testid=btn-edit-song class="p-1 text-gray-400 hover:text-white transition-colors hover:bg-gray-600"title="edit song"><svg class="w-3 h-3"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg></button><div data-testid=btn-drag-song title="drag to reorder"><svg class="w-3 h-3"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 6h16M4 12h16M4 18h16">'),MF=ee('<div data-testid=song-row style=-webkit-tap-highlight-color:transparent><div class="absolute inset-0 transition-all duration-200"style=pointer-events:none></div><div class="relative flex items-center w-full"><div class="relative w-12 h-12 mr-4 flex-shrink-0 bg-black"><div class="absolute inset-0 flex justify-center items-center font-mono group-hover:text-transparent"><span class=bg-black></span></div></div><div class="flex-1 min-w-0 text-lg"><div></div><div></div></div></div><div data-testid=song-duration>'),jp=ee('<div class="w-12 h-12 bg-transparent flex items-center justify-center">'),LF=ee('<img class="w-12 h-12 object-cover">'),NF=ee('<svg class="w-5 h-5"fill=currentColor viewBox="0 0 24 24"><path d="M8 5v14l11-7z">'),HF=ee("<span class=mx-2>•");function ZF(e){const[t,n]=Q(!1),[r,i]=Q(!1),[s,o]=Q(!1),[a,c]=Q(!1),[l,f]=Q(!1);sr(()=>{c("ontouchstart"in window||navigator.maxTouchPoints>0);const $=()=>{o(!1),i(!1)};document.addEventListener("dragend",$),rn(()=>{document.removeEventListener("dragend",$)})});const[u]=hh(()=>[e.songId,B0(e.songId)()],async([$,P])=>{try{const A=await aO($);return A?Mf([A])[0]??null:null}catch(A){return console.error(`Error fetching song ${$}:`,A),null}}),h=()=>{const $=Ye.currentSong(),P=Ye.isPlaying();return $?.id===e.songId&&P},d=()=>Ye.selectedSongId()===e.songId,g=()=>Ye.loadingSongIds().has(e.songId),p=()=>Ye.preloadingSongId()===e.songId,m=()=>Wy(e.songId),b=()=>qy(e.songId),x=()=>u()?.sha??u()?.sha256,[_]=hh(()=>{const $=x();return $?[$,B0(e.songId)()]:null},async([$])=>nO($)),E=()=>{const $=x();return $?$y().get($)??null:null},k=()=>!!u()?.standaloneFilePath||window.location.protocol==="file:"||!!window.STANDALONE_MODE,C=$=>{if(!$)return"0:00";const P=Math.floor($/60),A=Math.floor($%60);return`${P}:${A.toString().padStart(2,"0")}`},T=$=>{const P=Math.floor($/60),A=Math.floor($%60);return`${P}:${A.toString().padStart(2,"0")}`},j=()=>{const $=u();$&&(h()?e.onPause?.():e.onPlay?.($))},I=$=>{i(!0),$.dataTransfer.effectAllowed="move",$.dataTransfer.setData("text/plain",e.index.toString())},R=()=>{i(!1),o(!1)},N=$=>{$.preventDefault(),$.stopPropagation(),$.dataTransfer.dropEffect="move",o(!0)},D=$=>{$.stopPropagation();const P=$.currentTarget.getBoundingClientRect(),A=$.clientX,J=$.clientY;(A<P.left||A>P.right||J<P.top||J>P.bottom)&&o(!1)},y=$=>{$.preventDefault(),$.stopPropagation(),o(!1);const P=parseInt($.dataTransfer.getData("text/plain"),10),A=e.index;P!==A&&e.onReorder&&e.onReorder(P,A)},w=()=>{const $=u();$&&e.onEdit?.($)};return re(he,{get when(){return!u.loading},get fallback(){return CF()},get children(){return re(he,{get when(){return u()},get fallback(){return(()=>{var $=zF(),P=$.firstChild,A=P.nextSibling,J=A.firstChild,S=J.nextSibling;return S.firstChild,Z(S,()=>e.songId,null),$})()},children:$=>{const P=Kb($().createdAt),A=()=>{if(Ye.currentSong()?.id===$().id){const F=Ye.duration(),X=Ye.currentTime();return F>0?X/F*100:0}const U=Ye.songPlaybackPositions().get($().id)??0,O=$().duration??0;return U>0&&O>0?U/O*100:0},J=()=>h()?!0:A()>5;return(()=>{var S=MF(),U=S.firstChild,O=U.nextSibling,F=O.firstChild,X=F.firstChild,ie=X.firstChild,se=F.nextSibling,$e=se.firstChild,Ce=$e.nextSibling,Oe=O.nextSibling;return S.$$contextmenu=ye=>{ye.preventDefault(),w()},nn(S,"dblclick",a()?void 0:j,!0),nn(S,"click",a()?j:void 0,!0),S.addEventListener("mouseleave",()=>!a()&&n(!1)),S.addEventListener("mouseenter",()=>!a()&&n(!0)),S.addEventListener("drop",y),S.addEventListener("dragleave",D),S.addEventListener("dragover",N),S.addEventListener("dragend",R),S.addEventListener("dragstart",I),Z(ie,()=>e.index.toString().padStart(3,"0")),Z(F,re(he,{get when(){return $().imageType},get fallback(){return jp()},get children(){return(()=>{const ye=Vn($(),"thumbnail");return re(he,{when:ye,get fallback(){return jp()},get children(){var ve=LF();return Ne(ve,"src",ye||void 0),we(()=>Ne(ve,"alt",`${$().title} album art`)),ve}})})()}}),null),Z(F,re(he,{get when(){return g()||p()||b()},get children(){var ye=PF(),ve=ye.firstChild,me=ve.firstChild;return Z(ve,re(he,{get when(){return Ct(()=>m()>0)()&&m()<100},get children(){var _e=OF(),xe=_e.firstChild,v=xe.nextSibling;return we(V=>{var L=p()?"#9ca3af":"#ec4899",B=`${m()/100*87.96} 87.96`;return L!==V.e&&Ne(v,"stroke",V.e=L),B!==V.t&&Ne(v,"stroke-dasharray",V.t=B),V},{e:void 0,t:void 0}),_e}}),me),we(()=>Ne(me,"class",`w-4 h-4 animate-spin absolute inset-0 m-auto ${p()?"text-gray-400":"text-magenta-300"}`)),ye}}),null),Z(F,re(he,{get when(){return Ct(()=>!!(!g()&&!p()&&!b()&&t()))()&&!a()},get children(){var ye=DF();return ye.$$click=j,Z(ye,re(he,{get when(){return h()},get fallback(){return NF()},get children(){return TF()}})),ye}}),null),Z($e,()=>$().title),Z(Ce,()=>$().artist,null),Z(Ce,(()=>{var ye=Ct(()=>!!$().album);return()=>ye()&&HF()})(),null),Z(Ce,()=>$().album,null),Z(se,re(he,{get when(){return Ct(()=>!!d())()&&(t()||a())},get children(){var ye=FF(),ve=ye.firstChild,me=ve.nextSibling,_e=me.firstChild;return Z(ve,(()=>{var xe=Ct(()=>!!d());return()=>xe()?T(Ye.currentTime()):"0:00"})()),me.addEventListener("mouseleave",()=>f(!1)),me.$$mouseup=()=>f(!1),me.$$mousedown=()=>f(!0),_e.$$mouseup=()=>f(!1),_e.$$mousedown=()=>f(!0),_e.$$input=xe=>{if(d()){const v=parseFloat(xe.currentTarget.value);Kf(v)}},Z(ye,re(he,{get when(){return!a()},get children(){var xe=RF();return Z(xe,()=>C($().duration)),xe}}),null),we(xe=>{var v=$().duration||0,V=d()?`linear-gradient(to right, #ec4899 0%, #ec4899 ${Ye.currentTime()/($().duration||1)*100}%, #374151 ${Ye.currentTime()/($().duration||1)*100}%, #374151 100%)`:"#374151";return v!==xe.e&&Ne(_e,"max",xe.e=v),V!==xe.t&&Qn(_e,"background",xe.t=V),xe},{e:void 0,t:void 0}),we(()=>_e.value=d()?Ye.currentTime():0),ye}}),null),Z(se,re(he,{get when(){return Ct(()=>!!(h()||d()))()&&!t()},get children(){var ye=BF();return ye.firstChild,Z(ye,()=>P.signal(),null),ye}}),null),nn(Oe,"click",E()==="error"?()=>{Df(u())}:void 0,!0),Z(Oe,()=>C($().duration)),Z(S,re(he,{get when(){return Ct(()=>!!t())()&&!a()},get children(){var ye=jF(),ve=ye.firstChild,me=ve.nextSibling;return ve.$$click=_e=>{_e.stopPropagation(),_e.preventDefault();const xe=u();xe&&e.onEdit?.(xe)},Z(ye,re(he,{get when(){return e.showRemoveButton},get children(){var _e=UF();return _e.$$click=xe=>{xe.stopPropagation(),xe.preventDefault(),e.onRemove?.(e.songId)},_e}}),me),we(()=>ht(me,`p-1 text-gray-400 transition-colors cursor-grab ${r()?"cursor-grabbing text-magenta-400":"hover:text-gray-300"}`)),ye}}),null),we(ye=>{var ve=`group relative flex items-center p-3 group-hover:bg-opacity-70 hover:bg-magenta-500 transition-all duration-200 overflow-hidden ${h()||d()?"bg-black":s()?"border border-magenta-400 border-dashed":r()?"border border-gray-500":"border border-transparent"}`,me=!l(),_e=J()?`linear-gradient(to right, rgba(236, 72, 153, ${h()?"0.5":"0.3"}) ${A()}%, transparent ${A()}%)`:d()?"rgba(236, 72, 153, 0.3)":s()?"rgba(220, 38, 127, 0.2)":r()?"rgba(107, 114, 128, 0.3)":"transparent",xe=`break-words ${h()||d()?"text-magenta-200":"text-white"}`,v=`text-sm break-words ${h()||d()?"text-magenta-200":"text-white"}`,V=E()??void 0,L=x()??void 0,B=`text-sm font-mono mr-4 ${E()==="error"?"cursor-pointer":""} ${E()==="downloading"?"text-blue-400 animate-pulse":E()==="pending"?"text-gray-500":E()==="error"?"text-red-400":b()||g()&&_()===!1?"text-gray-400 animate-pulse":h()||d()?k()||_()===!0||!x()?"text-magenta-200 underline underline-offset-2":_()===void 0?"text-gray-500 animate-pulse":"text-magenta-200":_()===!0||k()||!x()?"text-white underline underline-offset-2":"text-gray-500 group-hover:text-white transition-colors"}`;return ve!==ye.e&&ht(S,ye.e=ve),me!==ye.t&&Ne(S,"draggable",ye.t=me),_e!==ye.a&&Qn(U,"background",ye.a=_e),xe!==ye.o&&ht($e,ye.o=xe),v!==ye.i&&ht(Ce,ye.i=v),V!==ye.n&&Ne(Oe,"data-download-state",ye.n=V),L!==ye.s&&Ne(Oe,"data-sha256",ye.s=L),B!==ye.h&&ht(Oe,ye.h=B),ye},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0}),S})()}})}})}Fr(["click","dblclick","contextmenu","mousedown","mouseup","input"]);var VF=ee(`<button data-testid=btn-set-bg-cover class="relative block w-full group cursor-pointer"title="set the page background to this playlist's cover image"><img alt="playlist cover"class="w-full h-auto"><span class="absolute bottom-0 inset-x-0 px-3 py-2 bg-black/70 text-white text-sm font-medium text-center opacity-0 group-hover:opacity-100 transition-opacity">show cover background preview`),WF=ee('<button class="block w-full px-3 py-1.5 bg-red-700 hover:bg-red-800 text-white text-sm font-medium transition-colors text-center">remove cover image'),qF=ee('<p class="text-xs text-gray-400">'),JF=ee('<div class="space-y-2 border border-gray-700 p-3"><p class="text-xs text-gray-400">this is a subscribed playlist from <span class=text-gray-200></span>. you can make your own editable copy or request edit access from the owner.</p><div class="flex gap-2"><button data-testid=btn-fork-playlist class="flex-1 px-3 py-1.5 bg-gray-700 hover:bg-gray-600 disabled:opacity-50 text-white text-sm transition-colors">make my own copy</button><button data-testid=btn-request-collaboration class="flex-1 px-3 py-1.5 bg-gray-700 hover:bg-gray-600 disabled:opacity-50 text-white text-sm transition-colors">request collaboration</button></div><textarea data-testid=input-collab-message placeholder="optional message to the owner..."rows=2 class="w-full bg-black text-white text-xs border border-gray-700 px-2 py-1.5 focus:outline-none focus:border-magenta-500 resize-none disabled:opacity-50">'),KF=ee('<svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z">'),GF=ee('<button data-testid=btn-download-zip class="w-full px-4 py-2 bg-gray-700 hover:bg-gray-600 disabled:bg-gray-400 text-white text-sm font-medium transition-colors flex items-center justify-center gap-2">'),YF=ee('<button class="w-full px-4 py-2 bg-red-600 hover:bg-red-700 disabled:bg-red-400 text-white text-sm font-medium transition-colors flex items-center justify-center gap-2"><svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg>delete playlist'),XF=ee('<div class="bg-red-900/30 border border-red-500 p-3"><div class="text-red-400 text-sm">'),QF=ee('<div data-testid=edit-panel class="bg-black/40 overflow-hidden min-w-0"><div class="p-4 border-none grid grid-cols-1 min-w-0 sm:grid-cols-[minmax(0,500px)_min(40%,24rem)] sm:justify-between gap-6"><div class="flex flex-col gap-3 min-w-0 sm:order-2"><input type=file accept=image/* class=hidden id=cover-upload-panel><label for=cover-upload-panel class="mt-auto block w-full px-3 py-1.5 bg-magenta-500 hover:bg-magenta-600 text-white cursor-pointer text-sm font-medium transition-colors text-center">upload image</label></div><div class="flex flex-col gap-5 min-w-0 sm:order-1"><div class=space-y-3><div class="flex items-center gap-2"><label class="text-sm font-medium text-gray-300">background filter</label><input type=checkbox class=accent-magenta-500><button class="ml-auto px-2 py-0.5 text-xs text-gray-400 hover:text-white border border-gray-700 hover:border-gray-500 transition-colors">reset</button></div><div><div class="grid grid-cols-[5rem_1fr_3rem] items-center gap-2"><label class="text-xs text-gray-400">blur</label><input type=range min=0 max=20 step=0.5 class=accent-magenta-500><span class="text-xs text-gray-400 tabular-nums">px</span></div><div class="grid grid-cols-[5rem_1fr_3rem] items-center gap-2"><label class="text-xs text-gray-400">contrast</label><input type=range min=0 max=10 step=0.1 class=accent-magenta-500><span class="text-xs text-gray-400 tabular-nums"></span></div><div class="grid grid-cols-[5rem_1fr_3rem] items-center gap-2"><label class="text-xs text-gray-400">brightness</label><input type=range min=0 max=2 step=0.05 class=accent-magenta-500><span class="text-xs text-gray-400 tabular-nums"></span></div></div></div><div class=space-y-3><div class="flex items-center gap-2"><label class="text-sm font-medium text-gray-300">cover blur</label><input type=checkbox class=accent-magenta-500><button class="ml-auto px-2 py-0.5 text-xs text-gray-400 hover:text-white border border-gray-700 hover:border-gray-500 transition-colors">reset</button></div><div><label class="text-xs text-gray-400">blur</label><input type=range min=0 max=20 step=0.5 class=accent-magenta-500><span class="text-xs text-gray-400 tabular-nums">px</span></div></div><div class=space-y-3><div class="flex items-center gap-2"><label class="text-sm font-medium text-gray-300">background image</label><button class="ml-auto px-2 py-0.5 text-xs text-gray-400 hover:text-white border border-gray-700 hover:border-gray-500 transition-colors">reset</button></div><div class="grid grid-cols-[5rem_1fr] items-center gap-2"><label class="text-xs text-gray-400">size</label><select class="bg-black text-white text-xs border border-gray-700 px-2 py-1 focus:outline-none focus:border-magenta-500"></select></div><div class="grid grid-cols-[5rem_1fr] items-center gap-2"><label class="text-xs text-gray-400">position</label><select class="bg-black text-white text-xs border border-gray-700 px-2 py-1 focus:outline-none focus:border-magenta-500"></select></div><div class="grid grid-cols-[5rem_1fr] items-center gap-2"><label class="text-xs text-gray-400">repeat</label><select class="bg-black text-white text-xs border border-gray-700 px-2 py-1 focus:outline-none focus:border-magenta-500"></select></div></div><div class="bg-black p-3 text-xs text-gray-400 space-y-1 mt-auto"><div>title: </div><div>id: </div><div>rev: </div><div>songz: </div><div>with album art: </div></div><div class="flex flex-col gap-2">'),eB=ee('<div class="w-full aspect-square bg-gray-700 flex items-center justify-center"><svg class="w-8 h-8 text-gray-400"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3">'),tB=ee('<img alt="playlist cover"class="w-full h-auto">'),pu=ee("<option>"),nB=ee('<div class="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin">'),rB=ee('<div class="bg-red-900/30 border border-red-500 p-2 space-y-2"><p class="text-white text-sm">delete this playlist?</p><div class="flex gap-2"><button class="flex-1 px-3 py-1.5 bg-red-600 hover:bg-red-700 disabled:bg-red-400 text-white text-sm font-medium transition-colors">yes, delete</button><button class="flex-1 px-3 py-1.5 bg-gray-600 hover:bg-gray-700 text-white text-sm font-medium transition-colors">cancel');function iB(e){const t=Ms(),{backgroundSource:n,setBackgroundOverride:r}=t,{handleDownloadPlaylist:i,isDownloading:s}=t,[o,a]=Q(),[c,l]=Q(!1),[f,u]=Q(null),[h,d]=Q(!1);sr(()=>{Jb()}),zt(()=>{if(e.playlist.imageData&&e.playlist.imageType){const L=e.playlist.thumbnailData||e.playlist.imageData;a(ei(L,e.playlist.imageType))}else e.playlist.imageFilePath&&a(e.playlist.imageFilePath)});const g=async L=>{const z=L.target.files?.[0];if(!z)return;const H=Jy(z);if(!H.valid){u(H.error||"invalid image file");return}try{l(!0),u(null);const Y=await Gf(z);if(Y.success&&Y.thumbnailData&&Y.imageData){const oe=o();oe&&URL.revokeObjectURL(oe),a(ei(Y.thumbnailData,z.type));const M={imageData:Y.imageData,thumbnailData:Y.thumbnailData,imageType:z.type,updatedAt:Date.now()};await zy(e.playlist.id,Y.imageData,z.type);const{image:te,...ge}=e.playlist;e.onSave({...ge,...M})}else u(Y.error||"failed to process image")}catch(Y){u("error uploading image"),console.error("image upload error:",Y)}finally{l(!1)}},p=async()=>{const L=o();L&&URL.revokeObjectURL(L),a(void 0);try{l(!0),u(null);const B={imageData:void 0,thumbnailData:void 0,imageType:void 0,updatedAt:Date.now()};await fO(e.playlist.id);const{image:z,...H}=e.playlist;e.onSave({...H,...B})}catch{u("failed to remove image")}finally{l(!1)}},m=async()=>{try{l(!0),u(null),await Iy(e.playlist.id),d(!1),e.onDelete?.(),e.onClose()}catch(L){u("failed to delete playlist"),console.error("delete error:",L)}finally{l(!1)}},[b,x]=Q(!1),[_,E]=Q(null),[k,C]=Q(""),T=()=>!!e.playlist.remoteNodeId&&!e.playlist.isForked,j=async()=>{try{x(!0),E(null);const L=await Cy(e.playlist.id);e.onFork?.(L.id),e.onClose()}catch(L){E("fork failed"),console.error("fork error:",L)}finally{x(!1)}},I=async()=>{const L=e.playlist.remoteNodeId;if(L)try{x(!0),E(null),await ar();const{knockForDocAccess:B}=await Xr(async()=>{const{knockForDocAccess:H}=await Promise.resolve().then(()=>Dd);return{knockForDocAccess:H}},void 0),z=await B(L,e.playlist.id,k()||"requesting collaboration access to: "+(e.playlist.title||"playlist"),e.playlist.title);z.status==="accepted"?E("access granted - you can now collaborate"):z.status==="pending"?E("knock sent - waiting for owner to accept"):E("request denied by owner")}catch(B){E("knock failed"),console.error("collab knock error:",B)}finally{x(!1)}},R=()=>e.playlistSongs.filter(L=>L.imageType||L.imageFilePath),[N,D]=Q(e.playlist.bgFilterEnabled??!0),[y,w]=Q(e.playlist.bgFilterBlur??3),[$,P]=Q(e.playlist.bgFilterContrast??3),[A,J]=Q(e.playlist.bgFilterBrightness??.4),[S,U]=Q(e.playlist.coverFilterEnabled??!0),[O,F]=Q(e.playlist.coverFilterBlur??3),[X,ie]=Q(e.playlist.bgSize??"cover"),[se,$e]=Q(e.playlist.bgPosition??"top"),[Ce,Oe]=Q(e.playlist.bgRepeat??"no-repeat"),ye=["cover","contain","auto","100% 100%","50%"],ve=["top","center","bottom","left","right","left top","right top"],me=["no-repeat","repeat","repeat-x","repeat-y"],_e=async L=>{try{await Bf(e.playlist.id,{bgFilterEnabled:L.bgFilterEnabled,bgFilterBlur:L.bgFilterBlur,bgFilterContrast:L.bgFilterContrast,bgFilterBrightness:L.bgFilterBrightness,coverFilterEnabled:L.coverFilterEnabled,coverFilterBlur:L.coverFilterBlur,bgSize:L.bgSize,bgPosition:L.bgPosition,bgRepeat:L.bgRepeat})}catch(B){u("failed to save filter settings"),console.error("filter save error:",B)}},xe=L=>{const{image:B,...z}=e.playlist;e.onSave({...z,...L,updatedAt:Date.now()})},v=()=>{D(!0),w(3),P(3),J(.4);const L={bgFilterEnabled:!0,bgFilterBlur:3,bgFilterContrast:3,bgFilterBrightness:.4};xe(L),_e(L)},V=()=>{U(!0),F(3);const L={coverFilterEnabled:!0,coverFilterBlur:3};xe(L),_e(L)};return(()=>{var L=QF(),B=L.firstChild,z=B.firstChild,H=z.firstChild;H.nextSibling;var Y=z.nextSibling,oe=Y.firstChild,M=oe.firstChild,te=M.firstChild,ge=te.nextSibling,de=ge.nextSibling,Se=M.nextSibling,Pe=Se.firstChild,Te=Pe.firstChild,ke=Te.nextSibling,Ue=ke.nextSibling,Qe=Ue.firstChild,be=Pe.nextSibling,Ee=be.firstChild,Ae=Ee.nextSibling,Ie=Ae.nextSibling,Ve=be.nextSibling,ot=Ve.firstChild,et=ot.nextSibling,We=et.nextSibling,at=oe.nextSibling,Be=at.firstChild,ce=Be.firstChild,je=ce.nextSibling,Ge=je.nextSibling,qe=Be.nextSibling,wt=qe.firstChild,ft=wt.nextSibling,vt=ft.nextSibling,yn=vt.firstChild,ur=at.nextSibling,dr=ur.firstChild,vr=dr.firstChild,fr=vr.nextSibling,xr=dr.nextSibling,Rn=xr.firstChild,hr=Rn.nextSibling,Bt=xr.nextSibling,_t=Bt.firstChild,$t=_t.nextSibling,en=Bt.nextSibling,qi=en.firstChild,Ji=qi.nextSibling,ea=ur.nextSibling,Gn=ea.firstChild;Gn.firstChild;var Mr=Gn.nextSibling;Mr.firstChild;var _i=Mr.nextSibling;_i.firstChild;var Ls=_i.nextSibling;Ls.firstChild;var Ns=Ls.nextSibling;Ns.firstChild;var yi=ea.nextSibling;return Z(z,re(he,{get when(){return o()},get fallback(){return eB()},get children(){return re(he,{get when(){return Ct(()=>!!e.playlist.imageType)()&&n()!==`playlist-${e.playlist.id}`},get fallback(){return(()=>{var ze=tB();return we(()=>Ne(ze,"src",o())),ze})()},get children(){var ze=VF(),Le=ze.firstChild;return ze.$$click=()=>r("cover"),we(()=>Ne(Le,"src",o())),ze}})}}),H),H.addEventListener("change",g),Z(z,re(he,{get when(){return o()},get children(){var ze=WF();return ze.$$click=p,we(()=>ze.disabled=c()),ze}}),null),Z(Y,re(he,{get when(){return T()},get children(){var ze=JF(),Le=ze.firstChild,Ki=Le.firstChild,Lr=Ki.nextSibling,Hs=Le.nextSibling,Sr=Hs.firstChild,Zs=Sr.nextSibling,Gi=Hs.nextSibling;return Z(Lr,()=>e.playlist.remoteName||e.playlist.remoteNodeId?.slice(0,8)+"..."),Sr.$$click=()=>void j(),Zs.$$click=()=>void I(),Gi.$$input=Fn=>C(Fn.currentTarget.value),Z(ze,re(he,{get when(){return _()},get children(){var Fn=qF();return Z(Fn,_),Fn}}),null),we(Fn=>{var uh=b(),dh=b(),fh=b();return uh!==Fn.e&&(Sr.disabled=Fn.e=uh),dh!==Fn.t&&(Zs.disabled=Fn.t=dh),fh!==Fn.a&&(Gi.disabled=Fn.a=fh),Fn},{e:void 0,t:void 0,a:void 0}),we(()=>Gi.value=k()),ze}}),oe),ge.addEventListener("change",ze=>{const Le=ze.currentTarget.checked;D(Le),xe({bgFilterEnabled:Le}),_e({bgFilterEnabled:Le})}),de.$$click=v,ke.addEventListener("change",ze=>_e({bgFilterBlur:Number(ze.currentTarget.value)})),ke.$$input=ze=>{const Le=Number(ze.currentTarget.value);w(Le),xe({bgFilterBlur:Le,bgFilterEnabled:N(),bgFilterContrast:$(),bgFilterBrightness:A()})},Z(Ue,y,Qe),Ae.addEventListener("change",ze=>_e({bgFilterContrast:Number(ze.currentTarget.value)})),Ae.$$input=ze=>{const Le=Number(ze.currentTarget.value);P(Le),xe({bgFilterContrast:Le,bgFilterEnabled:N(),bgFilterBlur:y(),bgFilterBrightness:A()})},Z(Ie,()=>$().toFixed(1)),et.addEventListener("change",ze=>_e({bgFilterBrightness:Number(ze.currentTarget.value)})),et.$$input=ze=>{const Le=Number(ze.currentTarget.value);J(Le),xe({bgFilterBrightness:Le,bgFilterEnabled:N(),bgFilterBlur:y(),bgFilterContrast:$()})},Z(We,()=>A().toFixed(2)),je.addEventListener("change",ze=>{const Le=ze.currentTarget.checked;U(Le),xe({coverFilterEnabled:Le}),_e({coverFilterEnabled:Le})}),Ge.$$click=V,ft.addEventListener("change",ze=>_e({coverFilterBlur:Number(ze.currentTarget.value)})),ft.$$input=ze=>{const Le=Number(ze.currentTarget.value);F(Le),xe({coverFilterBlur:Le,coverFilterEnabled:S()})},Z(vt,O,yn),fr.$$click=()=>{ie("cover"),$e("top"),Oe("no-repeat");const ze={bgSize:"cover",bgPosition:"top",bgRepeat:"no-repeat"};xe(ze),_e(ze)},hr.addEventListener("change",ze=>{const Le=ze.currentTarget.value;ie(Le),xe({bgSize:Le}),_e({bgSize:Le})}),Z(hr,()=>ye.map(ze=>(()=>{var Le=pu();return Le.value=ze,Z(Le,ze),Le})())),$t.addEventListener("change",ze=>{const Le=ze.currentTarget.value;$e(Le),xe({bgPosition:Le}),_e({bgPosition:Le})}),Z($t,()=>ve.map(ze=>(()=>{var Le=pu();return Le.value=ze,Z(Le,ze),Le})())),Ji.addEventListener("change",ze=>{const Le=ze.currentTarget.value;Oe(Le),xe({bgRepeat:Le}),_e({bgRepeat:Le})}),Z(Ji,()=>me.map(ze=>(()=>{var Le=pu();return Le.value=ze,Z(Le,ze),Le})())),Z(Gn,()=>e.playlist.title,null),Z(Mr,()=>e.playlist.id,null),Z(_i,()=>e.playlist.rev||0,null),Z(Ls,()=>e.playlist.songIds.length,null),Z(Ns,()=>R().length,null),Z(yi,re(he,{get when(){return window.location.protocol!=="file:"},get children(){var ze=GF();return nn(ze,"click",i,!0),Z(ze,re(he,{get when(){return!s()},get fallback(){return nB()},get children(){return KF()}}),null),Z(ze,()=>s()?"downloading...":"download playlist",null),we(()=>ze.disabled=s()||c()),ze}}),null),Z(yi,re(he,{get when(){return!h()},get fallback(){return(()=>{var ze=rB(),Le=ze.firstChild,Ki=Le.nextSibling,Lr=Ki.firstChild,Hs=Lr.nextSibling;return Lr.$$click=m,Hs.$$click=()=>d(!1),we(Sr=>{var Zs=c(),Gi=c();return Zs!==Sr.e&&(Lr.disabled=Sr.e=Zs),Gi!==Sr.t&&(Hs.disabled=Sr.t=Gi),Sr},{e:void 0,t:void 0}),ze})()},get children(){var ze=YF();return ze.$$click=()=>d(!0),we(()=>ze.disabled=c()),ze}}),null),Z(Y,re(he,{get when(){return f()},get children(){var ze=XF(),Le=ze.firstChild;return Z(Le,f),ze}}),null),we(ze=>{var Le=c(),Ki=`space-y-2 ${N()?"":"opacity-40 pointer-events-none"}`,Lr=`grid grid-cols-[5rem_1fr_3rem] items-center gap-2 ${S()?"":"opacity-40 pointer-events-none"}`;return Le!==ze.e&&(H.disabled=ze.e=Le),Ki!==ze.t&&ht(Se,ze.t=Ki),Lr!==ze.a&&ht(qe,ze.a=Lr),ze},{e:void 0,t:void 0,a:void 0}),we(()=>ge.checked=N()),we(()=>ke.value=y()),we(()=>Ae.value=$()),we(()=>et.value=A()),we(()=>je.checked=S()),we(()=>ft.value=O()),we(()=>hr.value=X()),we(()=>$t.value=se()),we(()=>Ji.value=Ce()),L})()}Fr(["click","input"]);var sB=ee('<img class="w-full h-full object-cover">'),oB=ee('<button class="p-1.5 text-gray-400 hover:text-white hover:bg-gray-700 disabled:text-gray-600 disabled:hover:bg-transparent transition-colors flex-shrink-0"><svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M15 19l-7-7 7-7">'),aB=ee('<button class="p-1.5 text-gray-400 hover:text-white hover:bg-gray-700 disabled:text-gray-600 disabled:hover:bg-transparent transition-colors flex-shrink-0"><svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M9 5l7 7-7 7">'),cB=ee('<img alt="album art"class="w-full h-auto">'),lB=ee('<button class="block w-full px-3 py-1.5 bg-red-700 hover:bg-red-800 text-white text-sm font-medium transition-colors text-center">remove image'),uB=ee('<button class="text-xs text-gray-500 hover:text-white transition-colors"title="reset title">reset'),dB=ee('<button class="text-xs text-gray-500 hover:text-white transition-colors"title="reset artist">reset'),fB=ee('<button class="text-xs text-gray-500 hover:text-white transition-colors"title="reset album">reset'),hB=ee("<div>size: <!> mb"),gB=ee("<div class=break-all>sha: "),pB=ee('<div class="sm:col-span-2 bg-red-900/30 border border-red-500 p-3"><div class="text-red-400 text-sm">'),mB=ee('<div class="bg-red-900/30 border-t border-red-500 px-4 py-3 space-y-2"><p class="text-white text-sm">delete this song? cannot be undone.</p><div class="flex gap-2"><button class="flex-1 px-4 py-2 bg-red-600 hover:bg-red-700 disabled:bg-red-400 text-white text-sm font-medium transition-colors">yes, delete</button><button class="flex-1 px-4 py-2 bg-gray-600 hover:bg-gray-700 disabled:bg-gray-400 text-white text-sm font-medium transition-colors">cancel'),_B=ee('<div data-testid=song-edit-panel class="bg-black/40 border-none overflow-hidden min-w-0 w-full"><div class="flex items-center gap-2 px-3 py-3 bg-black border-none select-none min-w-0"><button class="p-1 text-gray-400 hover:text-white transition-colors flex-shrink-0"title=close><svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M6 18L18 6M6 6l12 12"></path></svg></button><div class="relative w-10 h-10 flex-shrink-0 bg-black overflow-hidden"><div class="absolute inset-0 flex justify-center items-center font-mono text-sm text-gray-300"><span class=bg-black></span></div></div><div class=min-w-0><div class="text-white text-sm font-medium truncate"></div><div class="text-gray-400 text-xs truncate"></div></div><span class="text-gray-400 text-sm flex-shrink-0"></span><div class=flex-1></div></div><div class="p-4 grid grid-cols-1 sm:grid-cols-[minmax(0,500px)_min(40%,24rem)] sm:justify-between gap-4"><div class="flex flex-col gap-2 sm:order-2"><input type=file accept=image/* class=hidden id=song-image-upload-panel><label for=song-image-upload-panel class="mt-auto block w-full px-3 py-1.5 bg-magenta-500 hover:bg-magenta-600 text-white cursor-pointer text-sm font-medium transition-colors text-center">choose image</label></div><div class="flex flex-col gap-3 sm:order-1"><div><div class="flex items-center justify-between mb-1"><label class="text-xs font-medium text-gray-400">title</label></div><input type=text class="w-full bg-black text-white px-3 py-2 border border-gray-600 focus:border-magenta-500 focus:ring-1 focus:ring-magenta-500 focus:outline-none transition-colors text-sm"placeholder="song title"></div><div><div class="flex items-center justify-between mb-1"><label class="text-xs font-medium text-gray-400">artist</label></div><input type=text class="w-full bg-black text-white px-3 py-2 border border-gray-600 focus:border-magenta-500 focus:ring-1 focus:ring-magenta-500 focus:outline-none transition-colors text-sm"placeholder="artist name"></div><div><div class="flex items-center justify-between mb-1"><label class="text-xs font-medium text-gray-400">album</label></div><input type=text class="w-full bg-black text-white px-3 py-2 border border-gray-600 focus:border-magenta-500 focus:ring-1 focus:ring-magenta-500 focus:outline-none transition-colors text-sm"placeholder="album name"></div><div class="bg-black p-3 text-xs text-gray-400 space-y-1 mt-auto"><div>filename: </div><div>duration: '),yB=ee('<div class="w-full h-full flex items-center justify-center"><svg class="w-5 h-5 text-gray-500"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3">'),bB=ee('<div class="w-full aspect-square bg-gray-700 flex items-center justify-center"><svg class="w-8 h-8 text-gray-400"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3">'),wB=ee('<svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M19 21H5a2 2 0 01-2-2V5a2 2 0 012-2h11l5 5v11a2 2 0 01-2 2zM17 21v-8H7v8M7 3v5h8">'),vB=ee('<button class="px-4 py-2 bg-gray-700 hover:bg-gray-600 disabled:bg-gray-500 text-white font-medium transition-colors flex items-center gap-2"title="save and go to next song">save<svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M14 5l7 7m0 0l-7 7m7-7H3">'),xB=ee('<div class="flex items-center gap-3 px-4 py-3 border-none"><button class="px-3 py-2 bg-red-700 hover:bg-red-800 disabled:bg-red-400 text-white text-sm font-medium transition-colors flex items-center gap-2"title="delete song"><svg class="w-4 h-4 flex-shrink-0"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg><span class="hidden sm:inline">delete</span></button><div class=flex-1></div><button class="px-4 py-2 sm:px-6 bg-magenta-500 hover:bg-magenta-600 disabled:bg-magenta-400 text-white font-medium transition-colors flex items-center gap-2"><span class="hidden sm:inline">save'),SB=ee('<div class="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin">');function $B(e){const[t,n]=Q(""),[r,i]=Q(""),[s,o]=Q(""),[a,c]=Q(),[l,f]=Q(),[u,h]=Q(),[d,g]=Q(),[p,m]=Q(!1),[b,x]=Q(!1),[_,E]=Q(null),k=Ms(),{handleRemoveSong:C}=k;sr(()=>{if(n(e.song.title),i(e.song.artist||""),o(e.song.album||""),c(void 0),f(void 0),h(void 0),g(void 0),(e.song.imageData||e.song.thumbnailData)&&e.song.imageType){c(e.song.imageData),f(e.song.thumbnailData),h(e.song.imageType);const P=e.song.imageData||e.song.thumbnailData;P&&g(ei(P,e.song.imageType))}else e.song.imageFilePath&&(h(e.song.imageType),g(e.song.imageFilePath))});const j=()=>t().trim()!==e.song.title||r().trim()!==(e.song.artist||"")||s().trim()!==(e.song.album||"")||a()!==e.song.imageData||u()!==e.song.imageType,I="save or reset changes first";sr(()=>{const P=A=>{const J=A.target,S=J?.tagName;S==="INPUT"||S==="TEXTAREA"||J?.isContentEditable||j()||(A.key==="ArrowLeft"&&e.prevSong?(A.preventDefault(),e.onNavigate?.(e.prevSong)):A.key==="ArrowRight"&&e.nextSong&&(A.preventDefault(),e.onNavigate?.(e.nextSong)))};document.addEventListener("keydown",P),rn(()=>document.removeEventListener("keydown",P))});const R=async P=>{const J=P.target.files?.[0];if(!J)return;const S=Jy(J);if(!S.valid){E(S.error||"invalid image file");return}try{m(!0),E(null);const U=await Gf(J);if(U.success&&U.imageData&&U.thumbnailData){const O=d();O&&URL.revokeObjectURL(O),c(U.imageData),f(U.thumbnailData),h(J.type),g(ei(U.imageData,J.type))}else E(U.error||"failed to process image")}catch(U){E("error uploading image"),console.error("image upload error:",U)}finally{m(!1)}},N=async()=>{if(!t().trim()){E("title is required");return}try{m(!0),E(null);const P={...e.song,title:t().trim(),artist:r().trim()||"unknown artist",album:s().trim()||"unknown album",imageData:a(),thumbnailData:l(),imageType:u(),updatedAt:Date.now()};await e.onSave(P)}catch(P){E("failed to save"),console.error("save error:",P)}finally{m(!1)}},D=async()=>{await N(),!_()&&e.nextSong&&e.onNavigate?.(e.nextSong)},y=()=>{const P=d();P?.startsWith("blob:")&&URL.revokeObjectURL(P),E(null),e.onClose()},w=()=>{const P=d();P&&URL.revokeObjectURL(P),c(void 0),f(void 0),h(void 0),g(void 0)},$=()=>d()??Vn(e.song,"thumbnail")??void 0;return(()=>{var P=_B(),A=P.firstChild,J=A.firstChild,S=J.nextSibling,U=S.firstChild,O=U.firstChild,F=S.nextSibling,X=F.firstChild,ie=X.nextSibling,se=F.nextSibling;se.nextSibling;var $e=A.nextSibling,Ce=$e.firstChild,Oe=Ce.firstChild;Oe.nextSibling;var ye=Ce.nextSibling,ve=ye.firstChild,me=ve.firstChild;me.firstChild;var _e=me.nextSibling,xe=ve.nextSibling,v=xe.firstChild;v.firstChild;var V=v.nextSibling,L=xe.nextSibling,B=L.firstChild;B.firstChild;var z=B.nextSibling,H=L.nextSibling,Y=H.firstChild;Y.firstChild;var oe=Y.nextSibling;return oe.firstChild,J.$$click=y,Z(S,re(he,{get when(){return $()},get fallback(){return yB()},get children(){var M=sB();return we(te=>{var ge=$(),de=t();return ge!==te.e&&Ne(M,"src",te.e=ge),de!==te.t&&Ne(M,"alt",te.t=de),te},{e:void 0,t:void 0}),M}}),U),Z(O,()=>e.index.toString().padStart(3,"0")),Z(X,()=>t()||"(no title)"),Z(ie,()=>r()||"",null),Z(ie,()=>r()&&s()?" - ":"",null),Z(ie,()=>s()||"",null),Z(se,()=>Bd(e.song.duration)),Z(A,re(he,{get when(){return e.prevSong},get children(){var M=oB();return M.$$click=()=>e.onNavigate?.(e.prevSong),we(te=>{var ge=j(),de=j()?I:"edit previous song";return ge!==te.e&&(M.disabled=te.e=ge),de!==te.t&&Ne(M,"title",te.t=de),te},{e:void 0,t:void 0}),M}}),null),Z(A,re(he,{get when(){return e.nextSong},get children(){var M=aB();return M.$$click=()=>e.onNavigate?.(e.nextSong),we(te=>{var ge=j(),de=j()?I:"edit next song";return ge!==te.e&&(M.disabled=te.e=ge),de!==te.t&&Ne(M,"title",te.t=de),te},{e:void 0,t:void 0}),M}}),null),Z(Ce,re(he,{get when(){return d()},get fallback(){return bB()},get children(){var M=cB();return we(()=>Ne(M,"src",d())),M}}),Oe),Oe.addEventListener("change",R),Z(Ce,re(he,{get when(){return a()},get children(){var M=lB();return M.$$click=w,we(()=>M.disabled=p()),M}}),null),Z(me,re(he,{get when(){return t().trim()!==e.song.title},get children(){var M=uB();return M.$$click=()=>n(e.song.title),M}}),null),_e.$$input=M=>n(M.currentTarget.value),Z(v,re(he,{get when(){return r().trim()!==(e.song.artist||"")},get children(){var M=dB();return M.$$click=()=>i(e.song.artist||""),M}}),null),V.$$input=M=>i(M.currentTarget.value),Z(B,re(he,{get when(){return s().trim()!==(e.song.album||"")},get children(){var M=fB();return M.$$click=()=>o(e.song.album||""),M}}),null),z.$$input=M=>o(M.currentTarget.value),Z(Y,()=>e.song.originalFilename||"unknown",null),Z(H,re(he,{get when(){return e.song.fileSize},get children(){var M=hB(),te=M.firstChild,ge=te.nextSibling;return ge.nextSibling,Z(M,()=>Math.round(e.song.fileSize/1024/1024*100)/100,ge),M}}),oe),Z(oe,()=>Bd(e.song.duration),null),Z(H,re(he,{get when(){return e.song.sha},get children(){var M=gB();return M.firstChild,Z(M,()=>e.song.sha,null),M}}),null),Z($e,re(he,{get when(){return _()},get children(){var M=pB(),te=M.firstChild;return Z(te,_),M}}),null),Z(P,re(he,{get when(){return b()},get fallback(){return(()=>{var M=xB(),te=M.firstChild,ge=te.nextSibling,de=ge.nextSibling,Se=de.firstChild;return te.$$click=()=>x(!0),de.$$click=N,Z(de,re(he,{get when(){return!p()},get fallback(){return SB()},get children(){return wB()}}),Se),Z(M,re(he,{get when(){return e.nextSong},get children(){var Pe=vB();return Pe.$$click=D,we(()=>Pe.disabled=p()),Pe}}),null),we(Pe=>{var Te=p(),ke=p();return Te!==Pe.e&&(te.disabled=Pe.e=Te),ke!==Pe.t&&(de.disabled=Pe.t=ke),Pe},{e:void 0,t:void 0}),M})()},get children(){var M=mB(),te=M.firstChild,ge=te.nextSibling,de=ge.firstChild,Se=de.nextSibling;return de.$$click=()=>C(e.song.id,e.onClose),Se.$$click=()=>x(!1),we(Pe=>{var Te=p(),ke=p();return Te!==Pe.e&&(de.disabled=Pe.e=Te),ke!==Pe.t&&(Se.disabled=Pe.t=ke),Pe},{e:void 0,t:void 0}),M}}),null),we(M=>{var te=p(),ge=p(),de=p(),Se=p();return te!==M.e&&(Oe.disabled=M.e=te),ge!==M.t&&(_e.disabled=M.t=ge),de!==M.a&&(V.disabled=M.a=de),Se!==M.o&&(z.disabled=M.o=Se),M},{e:void 0,t:void 0,a:void 0,o:void 0}),we(()=>_e.value=t()),we(()=>V.value=r()),we(()=>z.value=s()),P})()}Fr(["click","input"]);var kB=ee('<div data-testid=share-link-error class="p-2 border border-red-500 text-red-400 text-sm"><span class="bg-black/80 px-1">'),EB=ee('<button data-testid=btn-enable-sharing class="w-full px-4 py-3 bg-magenta-500 hover:bg-magenta-600 disabled:bg-magenta-400 text-white font-medium">'),AB=ee('<img alt=avatar class="w-full h-full object-cover">'),IB=ee("<span data-testid=sharing-status>"),CB=ee('<div class="flex items-center gap-1 flex-1 min-w-0"><input data-testid=input-node-name type=text placeholder=anonymous autofocus class="flex-1 min-w-0 bg-black text-white px-2 py-0.5 text-sm border border-magenta-500 focus:outline-none"><button type=button class="flex-shrink-0 text-gray-400 hover:text-white px-1"aria-label="close name editor">✕'),zB=ee('<span data-testid=connected-peer-count class="text-xs text-green-400 bg-black/80 px-1"> connected'),OB=ee('<div class="flex items-center gap-2 mt-2"><div class="relative flex-shrink-0 w-8 h-8"><button type=button class="w-8 h-8 rounded-full overflow-hidden border border-gray-700 hover:border-magenta-500 transition-colors focus:outline-none"></button></div><input type=file accept=image/* class=hidden><div class="flex-1 min-w-0"><div class="flex items-center gap-2 mt-1"><button data-testid=btn-toggle-endpoint type=button>'),PB=ee('<p data-testid=collab-request-status class="text-xs px-1 text-magenta-400">'),TB=ee('<div><label class="block text-xs mb-1"><span class="bg-black px-1 text-gray-400">request collaboration access</span></label><div class=space-y-2><input data-testid=input-collab-request-message type=text placeholder="optional message to the owner"class="w-full bg-black text-white px-2 py-1.5 text-xs border border-gray-700 hover:border-gray-500 focus:border-magenta-500 focus:outline-none transition-colors"><button data-testid=btn-request-collab-access class="w-full px-3 py-2 text-sm border border-gray-600 hover:border-magenta-500 text-gray-300 hover:text-white disabled:opacity-50 transition-colors">'),DB=ee('<div class="flex gap-2"><input data-testid=input-share-link type=text readonly title="copy p2p share link"class="flex-1 bg-black text-white px-3 py-2 text-xs border border-magenta-200 hover:border-magenta-400 focus:outline-none truncate min-w-0 transition-colors"><button data-testid=btn-copy-share-link title="copy share link"class="px-4 py-2 bg-magenta-500 hover:bg-magenta-600 text-white text-sm whitespace-nowrap flex-shrink-0">'),RB=ee('<div><label class="block text-xs mb-1"><span class="bg-black px-1 text-gray-400">share this playlist'),FB=ee('<div class=space-y-3><div><label class="block text-xs mb-1"><span class="bg-black px-1 text-gray-400">who can browse this playlist?</span></label><div class="flex gap-2"><button data-testid=btn-mode-public>anyone (public)</button><button data-testid=btn-mode-knock>knock first</button></div><div class=mt-2><button data-testid=btn-toggle-collaborative type=button title="when on, peers with access can edit without a separate approval">collaborative editing '),BB=ee('<div><label data-testid=knock-inbox class="block text-xs mb-1"><span class="bg-black px-1 text-gray-400">knock inbox<span class="ml-2 text-magenta-400">(<!> pending)'),UB=ee('<div><label class="block text-xs mb-1"><span class="bg-black px-1 text-gray-400">waiting for access<span class="ml-2 text-yellow-400">(<!> pending)'),jB=ee('<div><label class="block text-xs mb-1"><span class="bg-black px-1 text-gray-400">granted peers (<!>)'),MB=ee('<div data-testid=share-panel class="px-4 pb-6 pt-2 space-y-5 font-mono text-white overflow-x-hidden min-w-0"><div>'),LB=ee('<div class="w-full h-full flex items-center justify-center text-white text-sm font-bold">'),NB=ee('<button type=button class="px-2 py-0.5 text-sm bg-black border border-gray-700 hover:border-magenta-500 text-white truncate max-w-[180px] transition-colors"title="click to edit display name">'),HB=ee("<span class=text-gray-500>anonymous"),ZB=ee('<div class="text-xs text-gray-600"><span class="bg-black/80 px-1">building link...'),VB=ee('<div class="text-gray-400 text-xs mb-2"><span class="bg-black/80 px-1">"<!>"'),WB=ee('<div class="border border-gray-700 p-3 mb-2 text-sm"><div class=mb-1><span class="text-white bg-black/80 px-1"></span><span class="text-gray-500 text-xs ml-2 bg-black/80 px-1">...</span><span class="text-xs ml-2 bg-black/80 px-1 text-magenta-400"></span></div><div class="flex items-center justify-between text-xs text-gray-500 mb-1"><span class="bg-black/80 px-1">grant access to:</span><div class="flex gap-2"><button type=button class="text-magenta-400 hover:text-magenta-300">all</button><button type=button class="text-gray-500 hover:text-gray-300">none</button></div></div><div class="max-h-24 overflow-y-auto mb-2"></div><div class="flex gap-2"><button class="flex-1 px-3 py-1 bg-magenta-500 hover:bg-magenta-600 disabled:bg-magenta-400 text-white text-xs"></button><button class="flex-1 px-3 py-1 border border-gray-600 text-gray-300 hover:border-gray-400 hover:text-white hover:bg-white/5 disabled:opacity-50 text-xs transition-colors">deny'),qB=ee('<label class="flex items-center gap-2 text-xs text-gray-300 py-0.5 cursor-pointer"><input type=checkbox><span class="bg-black/80 px-1">'),JB=ee('<p class="text-xs text-magenta-400 mb-1 bg-black/80 px-1">'),KB=ee('<div class="border border-gray-700 border-dashed p-3 mb-2 text-sm"><div class=mb-1><span class="text-gray-300 bg-black/80 px-1 text-xs">...</span><span class="text-xs ml-2 text-yellow-400">waiting</span></div><button class="w-full px-3 py-1 border border-gray-600 hover:border-gray-400 text-gray-300 hover:text-white hover:bg-white/5 disabled:opacity-50 text-xs transition-colors">'),GB=ee('<img class="w-full h-full object-cover">'),YB=ee('<div class="mt-2 space-y-1"><div class="flex items-center justify-between text-gray-500 mb-1"><span>access to:</span><button type=button class="text-magenta-400 hover:text-magenta-300">select all</button></div><div class="max-h-24 overflow-y-auto"></div><button class="w-full mt-1 px-3 py-1 bg-magenta-500 hover:bg-magenta-600 text-white text-xs">save'),XB=ee('<div class="border border-gray-700 p-3 mb-2 text-xs"><div class="flex items-center justify-between mb-1"><div class="flex items-center gap-2"><div class="relative w-7 h-7 shrink-0"><div class="w-7 h-7 rounded-full overflow-hidden bg-gray-700 flex items-center justify-center text-xs font-bold text-white"></div><span></span></div><div><span class="text-gray-200 bg-black/80 px-1"></span><span class="text-gray-600 ml-2">...</span></div></div><div class="flex gap-2"><button type=button class="text-gray-400 hover:text-white"></button><button type=button class="text-red-500 hover:text-red-400">revoke'),QB=ee("<span>"),eU=ee('<label class="flex items-center gap-2 text-gray-300 py-0.5 cursor-pointer"><input type=checkbox><span class="bg-black/80 px-1">');function tU(e){const[t,n]=Q({name:"",mode:"knock"}),[r,i]=Q(!1),[s,o]=Q(!1),a=()=>Rd(),[c,l]=Q({connected:0,reconnecting:0,failed:0}),[f,u]=Q(""),[h,d]=Q(!1),[g,p]=Q([]),[m,b]=Q([]),[x,_]=Q(null),[E,k]=Q([]),[C,T]=Q({}),[j,I]=Q(null),[R,N]=Q({}),[D,y]=Q(null),[w,$]=Q({}),[P,A]=Q(null),[J,S]=Q(!1),[U,O]=Q(!1),F=()=>!!e.playlist().remoteNodeId&&!e.playlist().isForked,[X,ie]=Q(""),[se,$e]=Q(null),[Ce,Oe]=Q(!1),ye=be=>{c();try{return wr().isConnected(be)}catch{return!1}};let ve,me=null,_e=null,xe=null,v=null;const V=["#e91e8c","#7c3aed","#0ea5e9","#10b981","#f59e0b","#ef4444"],L=be=>{const Ee=be.split("").reduce((Ae,Ie)=>Ae+Ie.charCodeAt(0),0);return V[Ee%V.length]??V[0]},B=be=>{const Ee=be.currentTarget.files?.[0];if(!Ee)return;const Ae=new FileReader;Ae.onload=()=>{typeof Ae.result=="string"&&M({avatarDataUrl:Ae.result})},Ae.readAsDataURL(Ee)};async function z(){const be=await ch();p(be),b(await lh()),k(await gl()),T(Ee=>{const Ae={...Ee};for(const Ie of be)Ie.status==="pending"&&Ie.knockType==="doc_access"&&Ie.requestedDocId&&!Ae[Ie.id]&&(Ae[Ie.id]=new Set([Ie.requestedDocId]));return Ae})}function H(){try{l(wr().getConnectionSummary())}catch{}}async function Y(){try{const be=await jb(e.playlist().id,e.playlist().title);u(be.url)}catch(be){Fe.warn("share.panel","could not build share link:",be)}}zt(()=>{(async()=>{const be=await jr();try{const Ie=(await lt(e.playlist().id)).doc(),Ve=Ie?.sharingMode;(Ve==="public"||Ve==="knock")&&(be.mode=Ve),O(!!Ie?.collaborative)}catch{}n(be),await z(),_n()?.node_id&&await Y(),i(T0()),H()})(),me=oh(()=>void z()),_e=wy(be=>i(be)),xe=zf(be=>{be?.node_id&&Y()}),v=setInterval(H,3e3),rn(()=>{me?.(),_e?.(),xe?.(),v&&clearInterval(v)})}),zt(()=>{const be=a(),Ee=e.playlist().id;be&&Ee&&Y()});const oe=async()=>{o(!0),A(null);try{await vF(),i(T0()),await Y()}catch(be){A(be instanceof Error?be.message:"failed to start p2p")}finally{o(!1)}},M=async be=>{const Ee={...t(),...be};if(n(Ee),await Ub(Ee),be.mode!==void 0)try{(await lt(e.playlist().id)).change(Ie=>{Ie.sharingMode=be.mode}),await dn(e.playlist().id)}catch(Ae){Fe.warn("share.panel","failed to write sharingMode to doc:",Ae)}},te=async()=>{const be=!U();O(be);try{(await lt(e.playlist().id)).change(Ae=>{Ae.collaborative=be}),await dn(e.playlist().id)}catch(Ee){Fe.warn("share.panel","failed to write collaborative to doc:",Ee),O(!be)}},ge=async()=>{if(Ce())return;const be=e.playlist().remoteNodeId;if(be){Oe(!0),$e(null);try{const Ee=await zc(be,e.playlist().id,X(),e.playlist().title);Ee.status==="accepted"?$e("access granted - you can now collaborate"):Ee.status==="denied"?$e("access denied"):$e("request sent - waiting for owner approval")}catch(Ee){$e(Ee instanceof Error?Ee.message:"request failed")}finally{Oe(!1),await z()}}},de=async()=>{try{await navigator.clipboard.writeText(f()),d(!0),setTimeout(()=>d(!1),1500)}catch{}};function Se(be,Ee){T(Ae=>{const Ie={...Ae},Ve=new Set(Ie[be]??[]);return Ve.has(Ee)?Ve.delete(Ee):Ve.add(Ee),Ie[be]=Ve,Ie})}function Pe(be){T(Ee=>({...Ee,[be]:new Set(e.playlists.map(Ae=>Ae.id))}))}function Te(be){T(Ee=>({...Ee,[be]:new Set}))}const ke=async be=>{if(x())return;_(be.id);let Ee=[...C()[be.id]??[]];be.knockType==="doc_access"&&be.requestedDocId&&!Ee.includes(be.requestedDocId)&&(Ee=[be.requestedDocId,...Ee]);try{await Nb(be.id,Ee.length>0?Ee:[])}finally{_(null)}await z()},Ue=async be=>{await Hb(be.id),await z()},Qe=()=>g().filter(be=>be.status==="pending");return(()=>{var be=MB(),Ee=be.firstChild;return Z(be,re(he,{get when(){return P()},get children(){var Ae=kB(),Ie=Ae.firstChild;return Z(Ie,P),Ae}}),Ee),Z(Ee,re(he,{get when(){return!gu()},get children(){var Ae=EB();return Ae.$$click=()=>void oe(),Z(Ae,()=>s()?"starting p2p node...":"enable p2p sharing"),we(()=>Ae.disabled=s()),Ae}}),null),Z(Ee,re(he,{get when(){return gu()},get children(){var Ae=OB(),Ie=Ae.firstChild,Ve=Ie.firstChild,ot=Ie.nextSibling,et=ot.nextSibling,We=et.firstChild,at=We.firstChild;Ve.$$click=()=>ve.click(),Z(Ve,re(he,{get when(){return t().avatarDataUrl},get fallback(){return(()=>{var ce=LB();return Z(ce,()=>(t().name?.[0]??"?").toUpperCase()),we(je=>Qn(ce,"background-color",L(t().name||"?"))),ce})()},get children(){var ce=AB();return we(()=>Ne(ce,"src",t().avatarDataUrl)),ce}})),Z(Ie,re(he,{get when(){return gu()},get children(){var ce=IB();return we(()=>ht(ce,`absolute bottom-0 right-0 w-2.5 h-2.5 rounded-full border-2 border-black ${a()?c().failed>0&&c().connected===0?"bg-red-500":c().reconnecting>0?"bg-yellow-400":"bg-green-500":"bg-gray-600"}`)),ce}}),null),ot.addEventListener("change",B);var Be=ve;return typeof Be=="function"?po(Be,ot):ve=ot,Z(et,re(he,{get when(){return J()},get fallback(){return(()=>{var ce=NB();return ce.$$click=()=>S(!0),Z(ce,()=>t().name||HB()),ce})()},get children(){var ce=CB(),je=ce.firstChild,Ge=je.nextSibling;return je.$$keydown=qe=>{(qe.key==="Enter"||qe.key==="Escape")&&S(!1)},je.$$input=qe=>void M({name:qe.currentTarget.value}),Ge.$$click=()=>S(!1),we(()=>je.value=t().name),ce}}),We),Z(We,re(he,{get when(){return Ct(()=>!!os())()&&Kr()>0},get children(){var ce=zB(),je=ce.firstChild;return Z(ce,Kr,je),ce}}),at),at.$$click=()=>void oe(),Z(at,(()=>{var ce=Ct(()=>!!s());return()=>ce()?"...":os()?"on":"off"})()),we(ce=>{var je=(()=>{if(!a())return"click to change avatar";const vt=c(),yn=[r()?"this tab runs the p2p node":"another tab holds the p2p node"];return vt.connected>0&&yn.push(`${vt.connected} connected`),vt.reconnecting>0&&yn.push(`${vt.reconnecting} reconnecting`),vt.failed>0&&yn.push(`${vt.failed} failed`),yn.join(" \xb7 ")})(),Ge=os(),qe=s(),wt=`text-xs px-2 py-0.5 border transition-colors disabled:opacity-50 ${os()?"border-gray-600 text-gray-400 hover:text-red-400 hover:border-red-500":"border-magenta-500 text-magenta-400 hover:text-white hover:border-magenta-400"}`,ft=os()?"turn off p2p":"turn on p2p";return je!==ce.e&&Ne(Ve,"title",ce.e=je),Ge!==ce.t&&Ne(at,"aria-pressed",ce.t=Ge),qe!==ce.a&&(at.disabled=ce.a=qe),wt!==ce.o&&ht(at,ce.o=wt),ft!==ce.i&&Ne(at,"title",ce.i=ft),ce},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),Ae}}),null),Z(be,re(he,{get when(){return Ct(()=>!!F())()&&a()},get children(){var Ae=TB(),Ie=Ae.firstChild,Ve=Ie.nextSibling,ot=Ve.firstChild,et=ot.nextSibling;return ot.$$input=We=>ie(We.currentTarget.value),et.$$click=()=>void ge(),Z(et,()=>Ce()?"sending request...":"request edit access"),Z(Ve,re(he,{get when(){return se()},get children(){var We=PB();return Z(We,se),We}}),null),we(()=>et.disabled=Ce()),we(()=>ot.value=X()),Ae}}),null),Z(be,re(he,{get when(){return a()},get children(){var Ae=RB();return Ae.firstChild,Z(Ae,re(he,{get when(){return f()},get fallback(){return ZB()},get children(){var Ie=DB(),Ve=Ie.firstChild,ot=Ve.nextSibling;return Ve.addEventListener("focus",et=>et.currentTarget.select()),ot.$$click=()=>void de(),Z(ot,()=>h()?"copied!":"copy"),we(()=>Ve.value=f()),Ie}}),null),Ae}}),null),Z(be,re(he,{get when(){return a()},get children(){var Ae=FB(),Ie=Ae.firstChild,Ve=Ie.firstChild,ot=Ve.nextSibling,et=ot.firstChild,We=et.nextSibling,at=ot.nextSibling,Be=at.firstChild;return Be.firstChild,et.$$click=()=>void M({mode:"public"}),We.$$click=()=>void M({mode:"knock"}),Be.$$click=()=>void te(),Z(Be,()=>U()?"(on)":"(off)",null),we(ce=>{var je=t().mode==="public",Ge=`flex-1 px-3 py-2 text-sm border transition-colors ${t().mode==="public"?"border-magenta-500 bg-magenta-500/20 text-white":"border-gray-600 text-gray-400 hover:border-magenta-500 hover:text-gray-200 hover:bg-white/5"}`,qe=t().mode==="knock",wt=`flex-1 px-3 py-2 text-sm border transition-colors ${t().mode==="knock"?"border-magenta-500 bg-magenta-500/20 text-white":"border-gray-600 text-gray-400 hover:border-magenta-500 hover:text-gray-200 hover:bg-white/5"}`,ft=U(),vt=`w-full px-3 py-2 text-sm border transition-colors ${U()?"border-magenta-500 bg-magenta-500/20 text-white":"border-gray-600 text-gray-400 hover:border-magenta-500 hover:text-gray-200 hover:bg-white/5"}`;return je!==ce.e&&Ne(et,"aria-pressed",ce.e=je),Ge!==ce.t&&ht(et,ce.t=Ge),qe!==ce.a&&Ne(We,"aria-pressed",ce.a=qe),wt!==ce.o&&ht(We,ce.o=wt),ft!==ce.i&&Ne(Be,"aria-pressed",ce.i=ft),vt!==ce.n&&ht(Be,ce.n=vt),ce},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),Ae}}),null),Z(be,re(he,{get when(){return Qe().length>0},get children(){var Ae=BB(),Ie=Ae.firstChild,Ve=Ie.firstChild,ot=Ve.firstChild,et=ot.nextSibling,We=et.firstChild,at=We.nextSibling;return at.nextSibling,Z(et,()=>Qe().length,at),Z(Ae,re(Gr,{get each(){return Qe()},children:Be=>(()=>{var ce=WB(),je=ce.firstChild,Ge=je.firstChild,qe=Ge.nextSibling,wt=qe.firstChild,ft=qe.nextSibling,vt=je.nextSibling,yn=vt.firstChild,ur=yn.nextSibling,dr=ur.firstChild,vr=dr.nextSibling,fr=vt.nextSibling,xr=fr.nextSibling,Rn=xr.firstChild,hr=Rn.nextSibling;return Z(Ge,()=>Be.name||"anonymous"),Z(qe,()=>Be.nodeId.slice(0,16),wt),Z(ft,()=>Be.knockType==="doc_access"?"wants playlist access":"wants to browse"),Z(ce,re(he,{get when(){return Be.message},get children(){var Bt=VB(),_t=Bt.firstChild,$t=_t.firstChild,en=$t.nextSibling;return en.nextSibling,Z(_t,()=>Be.message,en),Bt}}),vt),dr.$$click=()=>Pe(Be.id),vr.$$click=()=>Te(Be.id),Z(fr,re(Gr,{get each(){return e.playlists},children:Bt=>(()=>{var _t=qB(),$t=_t.firstChild,en=$t.nextSibling;return $t.addEventListener("change",()=>Se(Be.id,Bt.id)),Z(en,()=>Bt.title),we(()=>$t.checked=C()[Be.id]?.has(Bt.id)??!1),_t})()})),Rn.$$click=()=>void ke(Be),Z(Rn,(()=>{var Bt=Ct(()=>x()===Be.id);return()=>Bt()?"accepting...":`accept${(C()[Be.id]?.size??0)>0?` (${C()[Be.id].size})`:" (all)"}`})()),hr.$$click=()=>void Ue(Be),we(Bt=>{var _t=x()===Be.id,$t=(C()[Be.id]?.size??0)>0?"grant selected playlistz":"grant all playlistz",en=!!x();return _t!==Bt.e&&(Rn.disabled=Bt.e=_t),$t!==Bt.t&&Ne(Rn,"title",Bt.t=$t),en!==Bt.a&&(hr.disabled=Bt.a=en),Bt},{e:void 0,t:void 0,a:void 0}),ce})()}),null),Ae}}),null),Z(be,re(he,{get when(){return m().some(Ae=>Ae.status==="pending")},get children(){var Ae=UB(),Ie=Ae.firstChild,Ve=Ie.firstChild,ot=Ve.firstChild,et=ot.nextSibling,We=et.firstChild,at=We.nextSibling;return at.nextSibling,Z(et,()=>m().filter(Be=>Be.status==="pending").length,at),Z(Ae,re(Gr,{get each(){return m().filter(Be=>Be.status==="pending")},children:Be=>{const ce=async()=>{if(!j()){I(Be.id),N(je=>({...je,[Be.id]:""}));try{let je;Be.knockType==="doc_access"&&Be.requestedDocId?je=await zc(Be.nodeId,Be.requestedDocId,Be.message):je=await ah(Be.nodeId,Be.message||void 0),je.status==="accepted"?(N(Ge=>({...Ge,[Be.id]:"access granted!"})),await z(),Be.requestedDocId&&e.onPlaylistAdded?.(Be.requestedDocId)):je.status==="denied"?(N(Ge=>({...Ge,[Be.id]:"access denied"})),await z()):N(Ge=>({...Ge,[Be.id]:"still pending"}))}catch(je){N(Ge=>({...Ge,[Be.id]:je instanceof Error?je.message:"retry failed"}))}finally{I(null)}}};return(()=>{var je=KB(),Ge=je.firstChild,qe=Ge.firstChild,wt=qe.firstChild,ft=Ge.nextSibling;return Z(qe,()=>Be.nodeId.slice(0,20),wt),Z(je,re(he,{get when(){return R()[Be.id]},get children(){var vt=JB();return Z(vt,()=>R()[Be.id]),vt}}),ft),ft.$$click=()=>void ce(),Z(ft,()=>j()===Be.id?"checking...":"check if accepted"),we(()=>ft.disabled=j()===Be.id),je})()}}),null),Ae}}),null),Z(be,re(he,{get when(){return E().length>0},get children(){var Ae=jB(),Ie=Ae.firstChild,Ve=Ie.firstChild,ot=Ve.firstChild,et=ot.nextSibling;return et.nextSibling,Z(Ve,()=>E().length,et),Z(Ae,re(Gr,{get each(){return E()},children:We=>{const at=()=>D()===We.nodeId,Be=()=>w()[We.nodeId]??new Set(We.docIds??e.playlists.map(qe=>qe.id)),ce=()=>{$(qe=>({...qe,[We.nodeId]:new Set(We.docIds??e.playlists.map(wt=>wt.id))})),y(We.nodeId)},je=async()=>{await Rc({...We,docIds:[...Be()]}),y(null),k(await gl())},Ge=async()=>{await Lw(We.nodeId),k(await gl())};return(()=>{var qe=XB(),wt=qe.firstChild,ft=wt.firstChild,vt=ft.firstChild,yn=vt.firstChild,ur=yn.nextSibling,dr=vt.nextSibling,vr=dr.firstChild,fr=vr.nextSibling,xr=fr.firstChild,Rn=ft.nextSibling,hr=Rn.firstChild,Bt=hr.nextSibling;return Z(yn,re(he,{get when(){return We.avatarDataUrl},get fallback(){return(()=>{var _t=QB();return Z(_t,()=>(We.name||"?")[0]?.toUpperCase()),_t})()},get children(){var _t=GB();return we($t=>{var en=We.avatarDataUrl,qi=We.name;return en!==$t.e&&Ne(_t,"src",$t.e=en),qi!==$t.t&&Ne(_t,"alt",$t.t=qi),$t},{e:void 0,t:void 0}),_t}})),Z(vr,()=>We.name||"anonymous"),Z(fr,()=>We.nodeId.slice(0,12),xr),hr.$$click=()=>at()?y(null):ce(),Z(hr,()=>at()?"close":"edit"),Bt.$$click=()=>void Ge(),Z(qe,re(he,{get when(){return at()},get children(){var _t=YB(),$t=_t.firstChild,en=$t.firstChild,qi=en.nextSibling,Ji=$t.nextSibling,ea=Ji.nextSibling;return qi.$$click=()=>$(Gn=>({...Gn,[We.nodeId]:new Set(e.playlists.map(Mr=>Mr.id))})),Z(Ji,re(Gr,{get each(){return e.playlists},children:Gn=>(()=>{var Mr=eU(),_i=Mr.firstChild,Ls=_i.nextSibling;return _i.addEventListener("change",()=>$(Ns=>{const yi=new Set(Ns[We.nodeId]??Be());return yi.has(Gn.id)?yi.delete(Gn.id):yi.add(Gn.id),{...Ns,[We.nodeId]:yi}})),Z(Ls,()=>Gn.title),we(()=>_i.checked=Be().has(Gn.id)),Mr})()})),ea.$$click=()=>void je(),_t}}),null),we(_t=>{var $t=`absolute bottom-0 right-0 w-2.5 h-2.5 rounded-full border-2 border-gray-900 ${ye(We.nodeId)?"bg-green-400":"bg-gray-500"}`,en=ye(We.nodeId)?"online":"offline";return $t!==_t.e&&ht(ur,_t.e=$t),en!==_t.t&&Ne(ur,"title",_t.t=en),_t},{e:void 0,t:void 0}),qe})()}}),null),Ae}}),null),be})()}Fr(["click","input","keydown"]);var nU=ee('<div><span class="block whitespace-nowrap">');let Mp=!1;function rU(){if(Mp)return;Mp=!0;const e=document.createElement("style");e.textContent=`
|
|
211
|
+
@keyframes marquee-scroll {
|
|
212
|
+
0%, 5% { transform: translateX(0); }
|
|
213
|
+
45%, 55% { transform: translateX(var(--marquee-offset)); }
|
|
214
|
+
95%, 100%{ transform: translateX(0); }
|
|
215
|
+
}
|
|
216
|
+
`,document.head.appendChild(e)}function Lp(e){const[t,n]=Q(!1),[r,i]=Q(0),[s,o]=Q(!1);let a,c;const l=()=>{const d=e.isHovering;return d===void 0?s():typeof d=="function"?d():d},f=()=>{if(!a||!c)return;const d=a.offsetWidth,g=c.scrollWidth,p=g>d;n(p),p&&i(d-g-8)};sr(()=>{rU(),requestAnimationFrame(f)}),zt(()=>{e.text,requestAnimationFrame(f)});const u=()=>Math.max(2,2+Math.abs(r())*.02),h=tr(()=>!t()||!l()?"none":`marquee-scroll ${u()}s ease-in-out infinite`);return(()=>{var d=nU(),g=d.firstChild;nn(d,"mouseleave",e.isHovering===void 0?()=>o(!1):void 0),nn(d,"mouseenter",e.isHovering===void 0?()=>o(!0):void 0);var p=a;typeof p=="function"?po(p,d):a=d;var m=c;return typeof m=="function"?po(m,g):c=g,Z(g,()=>e.text),we(b=>{var x=`overflow-hidden ${e.class??""}`,_=e.title??e.text,E=`${r()}px`,k=h();return x!==b.e&&ht(d,b.e=x),_!==b.t&&Ne(d,"title",b.t=_),E!==b.a&&Qn(g,"--marquee-offset",b.a=E),k!==b.o&&Qn(g,"animation",b.o=k),b},{e:void 0,t:void 0,a:void 0,o:void 0}),d})()}var iU=ee('<span class=text-white>"<!>"'),sU=ee('<p class="text-red-400 text-xs">'),oU=ee('<div class=space-y-2><label class="block text-xs text-gray-400">message to owner (optional)</label><textarea data-testid=input-knock-message placeholder="hi, found your link and would love to listen..."rows=3 class="w-full bg-black text-white text-xs border border-gray-700 px-2 py-1.5 focus:outline-none focus:border-magenta-500 resize-none disabled:opacity-50">'),aU=ee('<div class="flex gap-2"><button data-testid=btn-send-knock class="flex-1 px-3 py-2 bg-magenta-500 hover:bg-magenta-600 disabled:bg-magenta-400 text-white text-sm transition-colors"></button><button class="px-3 py-2 border border-gray-700 hover:border-gray-500 text-gray-400 hover:text-white text-sm transition-colors">cancel'),cU=ee('<div class=space-y-3><p class="text-gray-300 text-xs">knock sent - waiting for <span class=text-white></span> to accept. you can dismiss this and try again later.</p><button class="w-full px-3 py-2 border border-gray-700 hover:border-gray-500 text-gray-400 hover:text-white text-sm transition-colors">dismiss'),lU=ee('<div class=space-y-3><p class="text-red-400 text-xs">access denied by the playlist owner.</p><button class="w-full px-3 py-2 border border-gray-700 hover:border-gray-500 text-gray-400 hover:text-white text-sm transition-colors">dismiss'),uU=ee('<div data-testid=share-knock-panel class="fixed inset-0 flex items-center justify-center z-50 bg-black/80 backdrop-blur-sm"><div class="bg-black border border-gray-700 p-6 max-w-sm w-full mx-4 space-y-4 font-mono"><h2 class="text-white text-sm font-medium">knock to access playlist</h2><div class=space-y-1><p class="text-gray-400 text-xs"><span class=text-gray-200></span> has shared <!> with access control enabled. send a knock to request access.'),dU=ee("<span>a playlist");function Gb(e){const[t,n]=Q(""),[r,i]=Q("idle"),[s,o]=Q(""),a=async()=>{i("sending"),o("");try{await ar();const l=await zc(e.ownerNodeId,e.docId,t(),e.title);l.status==="accepted"?e.onAccepted(e.docId):l.status==="denied"?i("denied"):i("pending")}catch(l){o(l instanceof Error?l.message:"knock failed"),i("error")}},c=()=>e.ownerName||e.ownerNodeId.slice(0,12)+"...";return(()=>{var l=uU(),f=l.firstChild,u=f.firstChild,h=u.nextSibling,d=h.firstChild,g=d.firstChild,p=g.nextSibling,m=p.nextSibling;return m.nextSibling,Z(g,c),Z(d,re(he,{get when(){return e.title},get fallback(){return dU()},get children(){var b=iU(),x=b.firstChild,_=x.nextSibling;return _.nextSibling,Z(b,()=>e.title,_),b}}),m),Z(f,re(he,{get when(){return r()==="idle"||r()==="sending"||r()==="error"},get children(){return[(()=>{var b=oU(),x=b.firstChild,_=x.nextSibling;return _.$$input=E=>n(E.currentTarget.value),Z(b,re(he,{get when(){return s()},get children(){var E=sU();return Z(E,s),E}}),null),we(()=>_.disabled=r()==="sending"),we(()=>_.value=t()),b})(),(()=>{var b=aU(),x=b.firstChild,_=x.nextSibling;return x.$$click=()=>void a(),Z(x,()=>r()==="sending"?"sending...":"send knock"),nn(_,"click",e.onDismiss,!0),we(E=>{var k=r()==="sending",C=r()==="sending";return k!==E.e&&(x.disabled=E.e=k),C!==E.t&&(_.disabled=E.t=C),E},{e:void 0,t:void 0}),b})()]}}),null),Z(f,re(he,{get when(){return r()==="pending"},get children(){var b=cU(),x=b.firstChild,_=x.firstChild,E=_.nextSibling,k=x.nextSibling;return Z(E,c),nn(k,"click",e.onDismiss,!0),b}}),null),Z(f,re(he,{get when(){return r()==="denied"},get children(){var b=lU(),x=b.firstChild,_=x.nextSibling;return nn(_,"click",e.onDismiss,!0),b}}),null),l})()}Fr(["input","click"]);var fU=ee('<div class="mt-1 text-xs text-magenta-400 px-1"><span class="bg-black/80 px-1">'),hU=ee('<p class="text-xs text-magenta-400 bg-black/80 px-1">'),gU=ee(`<div class="mt-2 px-3 space-y-1.5"><p class="text-xs text-yellow-500 bg-black/80 px-1">this peer requires a knock to view their playlistz</p><textarea data-testid=input-knock-message placeholder="say who you are and why you're knocking..."rows=2 class="w-full bg-black/60 text-white px-2 py-1.5 text-xs border border-white/10 focus:border-magenta-500 focus:outline-none placeholder-gray-600 resize-none"></textarea><button data-testid=btn-send-knock class="w-full px-3 py-1.5 bg-gray-800 hover:bg-gray-700 disabled:opacity-50 text-white text-xs transition-colors border border-white/10">`),pU=ee('<svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M12 4v16m8-8H4">'),mU=ee('<div class="flex flex-col h-full"data-testid=all-playlists-panel><div class="px-3 pt-2 pb-1 flex-shrink-0"><input data-testid=input-search-playlists type=text placeholder="search, paste share link, or node id..."class="w-full bg-black/60 text-white px-3 py-2 text-xs border border-white/10 hover:border-white/30 focus:border-magenta-500 focus:outline-none placeholder-gray-600 transition-colors"></div><div class="flex-1 overflow-y-auto"><div class="sticky bottom-0"><button data-testid=btn-new-playlist class="w-full flex items-center gap-3 px-4 py-3 text-gray-500 hover:text-white hover:bg-magenta-500/75 disabled:opacity-50 transition-colors border-t border-white/10 bg-black/40 text-sm"><div class="flex-shrink-0 w-10 h-10 flex items-center justify-center border border-dashed border-gray-600"></div><span class="px-1 py-0.5 bg-black text-white">'),_U=ee('<div class="px-3 pt-1 pb-0.5 text-xs text-gray-500"><span class="bg-black/80 px-1">'),yU=ee('<div class="px-4 py-3 text-xs text-gray-500"><span class="bg-black/80 px-1">no playlistz shared by this peer'),bU=ee('<div class="w-3.5 h-3.5 border-2 border-current border-t-transparent rounded-full animate-spin">'),wU=ee('<div class="group flex items-center gap-3 px-4 py-3 hover:bg-magenta-500/75 transition-colors"><div class="flex-shrink-0 w-10 h-10 bg-black/40 flex items-center justify-center"><svg width=20 height=20 viewBox="0 0 100 100"fill=none><path d="M50 81L25 31L75 31L60.7222 68.1429L50 81Z"fill=#FF00FF></path></svg></div><div class="flex-1 min-w-0"><div class="text-sm font-medium text-white truncate"><span class="bg-black px-1"></span></div><div class="text-xs text-gray-500 mt-0.5"><span class="bg-black px-1"></span></div></div><button class="flex-shrink-0 px-3 py-1 text-xs border border-magenta-500 text-magenta-400 hover:bg-magenta-500/20 disabled:opacity-50 transition-colors">'),vU=ee('<div data-testid=row-playing-indicator class="absolute inset-0 z-10 flex items-center justify-center bg-black/50"title=playing><svg class="w-4 h-4 text-magenta-400 animate-pulse"fill=currentColor viewBox="0 0 20 20"><path d="M6.3 4.06a1 1 0 011.02.04l7 4.5a1 1 0 010 1.7l-7 4.5A1 1 0 016 14V5a1 1 0 01.3-.94z">'),xU=ee('<img class="w-full h-full object-cover">'),Np=ee('<span class="text-xs text-gray-700 bg-black px-0.5">\xb7'),SU=ee('<span class="text-xs text-gray-500 px-1 bg-black">'),$U=ee('<img class="w-3 h-3 rounded-full object-cover">'),kU=ee('<button data-testid=btn-browse-sharer class="flex items-center gap-0.5 text-xs text-gray-500 px-1 bg-black hover:text-magenta-400 transition-colors"><span>'),EU=ee('<svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z">'),AU=ee('<button data-testid=btn-download-zip-row class="p-3 text-gray-500 hover:text-green-400 transition-colors disabled:opacity-40"title="download playlist as zip">'),IU=ee('<div class="group relative flex items-center gap-3 px-4 py-3 cursor-pointer transition-colors hover:bg-magenta-500/75"><div class="relative flex-shrink-0 w-10 h-10 overflow-hidden bg-black/40"></div><div class="flex-1 min-w-0 overflow-hidden"><div class="flex items-center gap-1 mt-0.5 flex-wrap"><span data-testid=row-song-count class="text-xs text-gray-500 px-1 bg-black"></span><span class="text-xs text-gray-700 bg-black px-0.5">\xb7</span><span class="text-xs text-gray-500 px-1 bg-black"></span></div></div><div><button data-testid=btn-play-playlist-row class="p-3 text-gray-500 hover:text-magenta-400 transition-colors"><svg class="w-4 h-4"fill=currentColor viewBox="0 0 20 20"><path d="M6.3 4.06a1 1 0 011.02.04l7 4.5a1 1 0 010 1.7l-7 4.5A1 1 0 016 14V5a1 1 0 01.3-.94z"></path></svg></button><button data-testid=btn-edit-playlist-row class="p-3 text-gray-500 hover:text-white transition-colors"title="edit playlist"><svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg></button><button data-testid=btn-share-playlist-row class="p-3 text-gray-500 hover:text-magenta-400 transition-colors"title="share playlist"><svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><line x1=7 y1=11.5 x2=17 y2=5.5 stroke-width=1.5></line><line x1=7 y1=12.5 x2=17 y2=18.5 stroke-width=1.5></line><circle cx=5 cy=12 r=2.5 stroke-width=1.5></circle><circle cx=19 cy=5 r=2.5 stroke-width=1.5></circle><circle cx=19 cy=19 r=2.5 stroke-width=1.5>'),CU=ee('<div class="w-full h-full flex items-center justify-center"><svg width=24 height=24 viewBox="0 0 100 100"fill=none><path d="M50 81L25 31L75 31L60.7222 68.1429L50 81Z"fill=#FF00FF>'),zU=ee('<span class="inline-flex items-center justify-center w-3 h-3 bg-magenta-700/60 text-white text-[7px] font-bold rounded-full overflow-hidden">'),OU=ee('<svg class="w-4 h-4 animate-spin"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15">');function PU(e){const{playlists:t,selectedPlaylist:n,selectPlaylist:r,selectById:i,createNewPlaylist:s}=Ms(),[o,a]=Q(!1),[c,l]=Q({}),[f,u]=Q(e.initialQuery??""),[h,d]=Q(null),[g,p]=Q(null),[m,b]=Q(null),[x,_]=Q(""),[E,k]=Q(!1),[C,T]=Q(null),j=$=>/^[0-9a-f]{64}$/i.test($.trim()),I=$=>oy($.trim())!==null,R=()=>{const $=n(),P=$?t().filter(J=>J.id!==$.id):t(),A=f().trim().toLowerCase();return!A||g()?P:P.filter(J=>J.title.toLowerCase().includes(A)||(J.description??"").toLowerCase().includes(A))},N=async $=>{u($),d(null),p(null);const P=$.trim();if(P){if(I(P)){d("opening...");try{const A=await ll(P);if(A.status==="knock_required"){d(null),u(""),b(A);return}u(""),d(null),i(A.docId),e.onPlaylistAdded?.(A.docId),e.onClose()}catch(A){d(A instanceof Error?A.message:"could not open share link")}return}if(j(P)){d("connecting to peer...");try{await ar();const A=await Lb(P);p(A),d(null)}catch(A){d(A instanceof Error?A.message:"could not reach peer")}}}};sr(()=>{e.initialQuery&&N(e.initialQuery);const $=R();Promise.allSettled($.map(async P=>{const A=await Hi(P.id);l(J=>({...J,[P.id]:A}))}))});const D=$=>{r($),e.onClose()},y=$=>{r($),e.onClose(),qf($)},w=async()=>{if(!o()){a(!0);try{const $=await s("new playlist");$&&(r($),e.onClose())}finally{a(!1)}}};return(()=>{var $=mU(),P=$.firstChild,A=P.firstChild,J=P.nextSibling,S=J.firstChild,U=S.firstChild,O=U.firstChild,F=O.nextSibling;return Z($,re(he,{get when(){return m()},get children(){return re(Gb,{get ownerNodeId(){return m().ownerNodeId},get docId(){return m().docId},get title(){return m().title},get ownerName(){return m().ownerName},onAccepted:X=>{b(null),i(X),e.onPlaylistAdded?.(X),e.onClose()},onDismiss:()=>b(null)})}}),P),A.$$keydown=X=>{X.key==="Escape"&&(u(""),p(null),d(null))},A.$$input=X=>void N(X.currentTarget.value),Z(P,re(he,{get when(){return h()},get children(){var X=fU(),ie=X.firstChild;return Z(ie,h),X}}),null),Z(P,re(he,{get when(){return g()?.knockRequired},get children(){var X=gU(),ie=X.firstChild,se=ie.nextSibling,$e=se.nextSibling;return se.$$input=Ce=>_(Ce.currentTarget.value),$e.$$click=async()=>{const Ce=f().trim();if(!(!Ce||E())){k(!0),T(null);try{await ar(),await ah(Ce,x()||void 0),T("knock sent - waiting for owner to accept")}catch(Oe){T(Oe instanceof Error?Oe.message:"knock failed")}finally{k(!1)}}},Z($e,()=>E()?"knocking...":"send knock"),Z(X,re(he,{get when(){return C()},get children(){var Ce=hU();return Z(Ce,C),Ce}}),null),we(()=>$e.disabled=E()),we(()=>se.value=x()),X}}),null),Z(J,re(he,{get when(){return g()},get fallback(){return re(he,{get when(){return R().length>0},get children(){return re(Gr,{get each(){return R()},children:X=>re(DU,{playlist:X,get songs(){return c()[X.id]},onSelect:D,onPlay:y,get onEdit(){return e.onEdit},get onShare(){return e.onShare},onBrowsePeer:ie=>{u(ie),N(ie)}})})}})},children:X=>re(he,{get when(){return X().items.length>0},get fallback(){return yU()},get children(){return[(()=>{var ie=_U(),se=ie.firstChild;return Z(se,(()=>{var $e=Ct(()=>!!X().name);return()=>$e()?`${X().name}'s playlistz`:"peer's playlistz"})()),ie})(),re(Gr,{get each(){return X().items},children:ie=>re(TU,{item:ie,get nodeId(){return X().nodeId},onAdd:async se=>{i(se),e.onPlaylistAdded?.(se),e.onClose()},onError:se=>d(se)})})]}})}),S),U.$$click=w,Z(O,re(he,{get when(){return!o()},get fallback(){return bU()},get children(){return pU()}})),Z(F,()=>o()?"creating...":"new playlist"),we(()=>U.disabled=o()),we(()=>A.value=f()),$})()}function TU(e){const[t,n]=Q(!1),r=async()=>{if(!t()){n(!0);try{const i=btoa(JSON.stringify({v:1,n:e.nodeId,d:e.item.docId,t:e.item.title})).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,""),s=await ll(`#share/${i}`);s.status==="synced"&&await e.onAdd(s.docId)}catch(i){e.onError(i instanceof Error?i.message:"failed to add playlist")}finally{n(!1)}}};return(()=>{var i=wU(),s=i.firstChild,o=s.nextSibling,a=o.firstChild,c=a.firstChild,l=a.nextSibling,f=l.firstChild,u=o.nextSibling;return Z(c,()=>e.item.title),Z(f,(()=>{var h=Ct(()=>e.item.songCount===1);return()=>h()?"1 song":`${e.item.songCount} songz`})()),u.$$click=()=>void r(),Z(u,()=>t()?"adding...":"add"),we(()=>u.disabled=t()),i})()}function DU(e){const t=()=>Ye.isPlaying()&&Ye.currentPlaylist()?.id===e.playlist.id,n=Kb(e.playlist.updatedAt),r=()=>{const u=e.playlist.songIds?.length??0;return u===1?"1 song":`${u} songz`},i=()=>{const u=e.songs;if(!u||u.length===0)return null;const h=u.reduce((d,g)=>d+(g.duration||0),0);return h===0?null:Bd(h)},s=()=>Vn(e.playlist,"thumbnail"),[o,a]=Q(!1),[c,l]=Q(!1),f=async u=>{if(u.stopPropagation(),!c()){l(!0);try{await Ib(e.playlist,{includeMetadata:!0,includeImages:!0,generateM3U:!0,includeHTML:!0})}finally{l(!1)}}};return(()=>{var u=IU(),h=u.firstChild,d=h.nextSibling,g=d.firstChild,p=g.firstChild,m=p.nextSibling,b=m.nextSibling,x=d.nextSibling,_=x.firstChild,E=_.nextSibling,k=E.nextSibling;return u.addEventListener("mouseleave",()=>a(!1)),u.addEventListener("mouseenter",()=>a(!0)),u.$$dblclick=C=>{C.stopPropagation(),e.onPlay(e.playlist)},u.$$click=()=>e.onSelect(e.playlist),Z(h,re(he,{get when(){return t()},get children(){return vU()}}),null),Z(h,re(he,{get when(){return s()},get fallback(){return CU()},get children(){var C=xU();return we(T=>{var j=s(),I=e.playlist.title;return j!==T.e&&Ne(C,"src",T.e=j),I!==T.t&&Ne(C,"alt",T.t=I),T},{e:void 0,t:void 0}),C}}),null),Z(d,re(Lp,{get text(){return e.playlist.title},isHovering:o,class:"text-sm font-medium text-white [&>span]:px-1 [&>span]:bg-black"}),g),Z(d,re(he,{get when(){return e.playlist.description},get children(){return re(Lp,{get text(){return e.playlist.description},isHovering:o,class:"text-xs text-gray-400 mt-0.5 [&>span]:px-1 [&>span]:bg-black"})}}),g),Z(p,r),Z(g,re(he,{get when(){return i()},get children(){return[Np(),(()=>{var C=SU();return Z(C,i),C})()]}}),m),Z(b,()=>n.signal()),Z(g,re(he,{get when(){return e.playlist.remoteNodeId},get children(){return[Np(),(()=>{var C=kU(),T=C.firstChild;return C.$$click=j=>{j.stopPropagation(),e.playlist.remoteNodeId&&e.onBrowsePeer?.(e.playlist.remoteNodeId)},Z(C,re(he,{get when(){return e.playlist.remoteAvatarDataUrl},get fallback(){return(()=>{var j=zU();return Z(j,()=>(e.playlist.remoteName||e.playlist.remoteNodeId||"").slice(0,1).toUpperCase()),j})()},get children(){var j=$U();return we(I=>{var R=e.playlist.remoteAvatarDataUrl,N=e.playlist.remoteName||"peer";return R!==I.e&&Ne(j,"src",I.e=R),N!==I.t&&Ne(j,"alt",I.t=N),I},{e:void 0,t:void 0}),j}}),T),Z(T,()=>e.playlist.remoteName||e.playlist.remoteNodeId?.slice(0,8)),we(()=>Ne(C,"title",`browse ${e.playlist.remoteName||e.playlist.remoteNodeId?.slice(0,16)}'s playlistz`)),C})()]}}),null),_.$$click=C=>{C.stopPropagation(),e.onPlay(e.playlist)},E.$$click=C=>{C.stopPropagation(),e.onEdit(e.playlist)},k.$$click=C=>{C.stopPropagation(),e.onShare(e.playlist)},Z(x,re(he,{get when(){return window.location.protocol!=="file:"},get children(){var C=AU();return C.$$click=f,Z(C,re(he,{get when(){return!c()},get fallback(){return OU()},get children(){return EU()}})),we(()=>C.disabled=c()),C}}),null),we(C=>{var T=`flex-shrink-0 flex items-center bg-black transition-opacity ${o()?"opacity-100":"opacity-0"}`,j=`play ${e.playlist.title}`;return T!==C.e&&ht(x,C.e=T),j!==C.t&&Ne(_,"title",C.t=j),C},{e:void 0,t:void 0}),u})()}Fr(["input","keydown","click","dblclick"]);var Xs=ee("<div>"),RU=ee('<div><div><button class="w-full h-full overflow-hidden hover:bg-gray-900 flex items-center justify-center transition-colors group"title="view playlist images"></button></div><div class="flex items-center gap-4 w-full"><div class=flex-1><div class="bg-black bg-opacity-80"><input data-testid=input-playlist-title type=text class="text-3xl font-bold text-white bg-transparent border-none outline-none focus:bg-gray-800 px-2 py-1 rounded w-full disabled:opacity-60 disabled:cursor-not-allowed"placeholder="playlist title"></div><div class="bg-black bg-opacity-80"><input data-testid=input-playlist-description type=text placeholder="add description..."class="text-white bg-transparent border-none focus:bg-gray-800 px-2 py-1 rounded w-full disabled:opacity-60 disabled:cursor-not-allowed">'),Ea=ee('<div class=text-center><svg width=100 height=100 viewBox="0 0 100 100"fill=none xmlns=http://www.w3.org/2000/svg><path d="M50 81L25 31L75 31L60.7222 68.1429L50 81Z"fill=#FF00FF>'),Hp=ee('<img alt="playlist cover"class="w-full h-full object-cover">'),FU=ee('<img class="w-4 h-4 rounded-full object-cover shrink-0">'),BU=ee('<button data-testid=btn-browse-sharer class="flex items-center gap-1 bg-black/80 px-1.5 py-2 text-xs text-gray-400 hover:text-magenta-300 hover:bg-black transition-colors"><span class="truncate max-w-[6rem]">'),UU=ee('<span class="absolute -top-1.5 -right-1.5 min-w-[14px] h-[14px] px-0.5 rounded-full bg-magenta-500 text-white text-[9px] leading-[14px] text-center font-bold">'),jU=ee('<button data-testid=btn-cache-offline class="p-2 text-gray-400 hover:text-magenta-400 hover:bg-gray-700 transition-colors bg-black/90 disabled:opacity-50 disabled:cursor-not-allowed"title="download songz for offline use">'),MU=ee('<svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3">'),LU=ee('<button data-testid=btn-p2p-save-offline class="p-2 text-gray-400 hover:text-magenta-400 hover:bg-gray-700 transition-colors bg-black/90 disabled:opacity-50">'),NU=ee('<label data-testid=btn-add-songs title="add songz"class="p-2 text-gray-400 hover:text-green-400 hover:bg-gray-700 transition-colors bg-black/90 cursor-pointer"><input type=file accept=audio/*,.mp3,.wav,.flac,.ogg,.m4a,.aiff,.zip multiple class=hidden><svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2.5 d="M12 4v16m8-8H4">'),HU=ee(`<div class="grid gap-3"style="grid-template-columns:auto 1fr;grid-template-areas:'player info' 'player buttons'"><div class="flex items-center justify-center"style=grid-area:player></div><div id=song-info class="flex items-center justify-end text-sm gap-0"style=grid-area:info><span data-testid=playlist-song-count class="bg-black bg-opacity-80 p-2"> song</span><span data-testid=playlist-total-time class="bg-black bg-opacity-80 p-2"></span></div><div class="flex items-center justify-end gap-2"style=grid-area:buttons><button data-testid=btn-all-playlists title="all playlistz"><svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 6h16M4 12h16M4 18h16"></path></svg></button><button data-testid=btn-edit-playlist><svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg></button><button data-testid=btn-share-playlist title="share playlist"><svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><line x1=7 y1=11.5 x2=17 y2=5.5 stroke-width=1.5></line><line x1=7 y1=12.5 x2=17 y2=18.5 stroke-width=1.5></line><circle cx=5 cy=12 r=2.5 stroke-width=1.5></circle><circle cx=19 cy=5 r=2.5 stroke-width=1.5></circle><circle cx=19 cy=19 r=2.5 stroke-width=1.5>`),ZU=ee('<span class="inline-flex items-center justify-center w-4 h-4 bg-magenta-700/60 text-white text-[9px] font-bold shrink-0 overflow-hidden rounded-full">'),Zp=ee('<svg class="w-4 h-4 animate-spin"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15">'),VU=ee('<div><button class="w-39 h-39 overflow-hidden hover:bg-gray-900 flex items-center justify-center transition-colors group"title="view playlist imagez">'),WU=ee('<div class="sticky top-0 z-[110] bg-black py-1">'),qU=ee('<div data-testid=empty-songs><div class="text-gray-400 text-xl mb-4">no songz yet</div><p class="text-gray-400 mb-4">drag and drop audio filez (or a .zip file!) here to add them to this playlist</p><div class="text-xs text-gray-500 space-y-1"><div>playlist id: </div><div>supported formatz: mp3, wav, flac, aiff, ogg, mp4'),JU=ee('<div class="flex-1 overflow-y-auto min-h-0"><div>'),KU=ee("<div><div>"),GU=ee('<span class="w-full text-red-400">'),YU=ee('<div data-testid=subscribed-banner class="flex flex-wrap items-center gap-x-2 gap-y-1 px-2 py-1.5 bg-black/70 border-t border-gray-800 text-xs"><span class="text-yellow-500/80 font-medium">read only</span><span class=text-gray-600>\xb7</span><span class=text-gray-500>from </span><div class="flex items-center gap-2 ml-auto"><button data-testid=btn-fork-playlist-banner class="px-2 py-0.5 text-gray-300 hover:text-white border border-gray-700 hover:border-gray-500 disabled:opacity-50 transition-colors">');function XU(e){const t=Ms(),n=Tb(),r=Db(),i=Fb(),s=Rb();sr(()=>Jb());const{playlists:o,playlistSongs:a,isDownloading:c,isCaching:l,allSongsCached:f,handlePlaylistUpdate:u,handleDownloadPlaylist:h,handleCachePlaylist:d,handleRemoveSong:g,handleReorderSongs:p,setBackgroundOverride:m}=t,b=()=>!!e.playlist().remoteNodeId&&!e.playlist().isForked,{handleEditSong:x,handleEditPlaylist:_,handlePlaySong:E,handlePauseSong:k,editingSong:C,editingPlaylist:T,setEditingSong:j,handleCloseEdit:I,handleSongSaved:R}=n,N=async M=>{await E(M,e.playlist())},[D,y]=Q(null),[w,$]=Q(!1);zt(Ia(()=>[e.playlist().id,a().length,D()===null],()=>{j0(e.playlist()).then($).catch(()=>$(!1))}));const P=async()=>{if(!D()){y({done:0,total:0,currentTitle:"",fraction:0});try{await sO(e.playlist(),M=>y(M)),$(await j0(e.playlist()).catch(()=>!1))}catch(M){Fe.warn("p2p.save","p2p save offline failed:",M)}finally{y(null)}}},{isMobile:A}=r,{openImageModal:J}=i,[S,U]=Q(!1),[O,F]=Q(!1),[X,ie]=Q(void 0),se=()=>{U(!1)},$e=tr(()=>C()!==null||T()||S()||O()),Ce=()=>{const M=C();return M?e.playlist().songIds.indexOf(M.id):-1},Oe=M=>{const te=Ce();if(te<0)return;const ge=e.playlist().songIds[te+M];if(ge)return a().find(de=>de.id===ge)},ye=100,ve=M=>M<5?M*20:50+(M-5)*5,me=M=>{if(T()||O())return"rowFlyDown";const te=Ce();return te>=0&&M<te?"rowFlyUp":"rowFlyDown"},[_e,xe]=Q(!1);let v;zt(()=>{$e()&&v?.scrollTo({top:0})}),zt(()=>{if(!T())return;const M=e.playlist().songIds||[],te=C();if(te&&M.includes(te.id))return;const ge=M.length?a().find(de=>de.id===M[0]):void 0;j(ge??null)}),zt(Ia([T,C],([M,te])=>{M&&te?.imageType?m(te):m(null)})),rn(()=>m(null)),sr(()=>{const M=te=>{if(te.key==="Escape"){if(O()){F(!1);return}if(S()){se();return}$e()&&I()}};document.addEventListener("keydown",M),rn(()=>document.removeEventListener("keydown",M))}),zt(Ia($e,(M,te)=>{if(Fe.debug("playlist.rows","rowsGone effect",JSON.stringify({editing:M,prevEditing:te})),M&&!te){xe(!1);const ge=ve(2)+ye,de=setTimeout(()=>{Fe.debug("playlist.rows","rowsGone -> true"),xe(!0)},ge);rn(()=>clearTimeout(de))}else M||xe(!1)}));const V=()=>_e()?{"max-height":"0px",overflow:"hidden"}:{"max-height":"400px"},L=M=>{if($e()&&!_e()){const te=ve(M);return{animation:`${me(M)} ${ye}ms ease ${te}ms both`}}return $e()?{}:{animation:`rowFlyIn ${ye}ms ease both`}},B=()=>C()&&!T()?{transition:"max-height 350ms ease, opacity 300ms ease","max-height":"0px",overflow:"hidden",opacity:"0","pointer-events":"none"}:{transition:"max-height 350ms ease, opacity 300ms ease","max-height":"1200px",opacity:"1","pointer-events":"auto"},z=()=>({animation:"slideDown 150ms ease both"});let H;const[Y,oe]=Q(0);return zt(()=>{if(!A()){oe(0);return}const M=H;if(!M)return;oe(M.offsetHeight);const te=new ResizeObserver(()=>oe(M.offsetHeight));te.observe(M),rn(()=>te.disconnect())}),(()=>{var M=Xs();return Z(M,()=>{const te=()=>(()=>{var Se=RU(),Pe=Se.firstChild,Te=Pe.firstChild,ke=Pe.nextSibling,Ue=ke.firstChild,Qe=Ue.firstChild,be=Qe.firstChild,Ee=Qe.nextSibling,Ae=Ee.firstChild;return Te.$$click=()=>{J(e.playlist(),a(),0)},Z(Te,re(he,{get when(){return e.playlist().imageType},get fallback(){return Ea()},get children(){return(()=>{const Ie=Vn(e.playlist(),"modal");return Ie?(()=>{var Ve=Hp();return Ne(Ve,"src",Ie),Ve})():Ea()})()}})),be.$$input=Ie=>{u({title:Ie.currentTarget.value})},Ae.$$input=Ie=>{u({description:Ie.currentTarget.value})},Z(Ue,re(he,{get when(){return b()},get children(){return re(QU,{get playlist(){return e.playlist()},onFork:Ie=>{t.selectById(Ie)}})}}),null),Z(Ue,re(he,{get when(){return!A()},get children(){return ge()}}),null),Z(Se,de,null),we(Ie=>{var Ve=B(),ot=`flex items-center justify-between ${A()?"flex-col":"p-6"}`,et=`${A()&&!$e()?"":"hidden"}`,We=b(),at=b();return Ie.e=$r(Se,Ve,Ie.e),ot!==Ie.t&&ht(Se,Ie.t=ot),et!==Ie.a&&ht(Pe,Ie.a=et),We!==Ie.o&&(be.disabled=Ie.o=We),at!==Ie.i&&(Ae.disabled=Ie.i=at),Ie},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),we(()=>be.value=e.playlist().title),we(()=>Ae.value=e.playlist().description||""),Se})();function ge(){return(()=>{var Se=HU(),Pe=Se.firstChild,Te=Pe.nextSibling,ke=Te.firstChild,Ue=ke.firstChild,Qe=ke.nextSibling,be=Te.nextSibling,Ee=be.firstChild,Ae=Ee.nextSibling,Ie=Ae.nextSibling,Ve=Ie.firstChild,ot=Ve.firstChild,et=ot.nextSibling,We=et.nextSibling,at=We.nextSibling,Be=at.nextSibling;return Z(Pe,re(EF,{get playlist(){return e.playlist()},size:"w-12 h-12"})),Z(Te,re(he,{get when(){return e.playlist().remoteNodeId},get children(){var ce=BU(),je=ce.firstChild;return ce.$$click=()=>{S()&&se(),(T()||C())&&I(),ie(e.playlist().remoteNodeId),F(!0)},Z(ce,re(he,{get when(){return e.playlist().remoteAvatarDataUrl},get fallback(){return(()=>{var Ge=ZU();return Z(Ge,()=>(e.playlist().remoteName||e.playlist().remoteNodeId||"").slice(0,1).toUpperCase()),Ge})()},get children(){var Ge=FU();return we(qe=>{var wt=e.playlist().remoteAvatarDataUrl,ft=e.playlist().remoteName||"peer";return wt!==qe.e&&Ne(Ge,"src",qe.e=wt),ft!==qe.t&&Ne(Ge,"alt",qe.t=ft),qe},{e:void 0,t:void 0}),Ge}}),je),Z(je,()=>e.playlist().remoteName||e.playlist().remoteNodeId?.slice(0,8)),we(()=>Ne(ce,"title",`browse ${e.playlist().remoteName||e.playlist().remoteNodeId?.slice(0,16)}'s playlistz`)),ce}}),ke),Z(ke,()=>e.playlist().songIds?.length||0,Ue),Z(ke,()=>(e.playlist().songIds?.length||0)!==1?"z":"",null),Z(Qe,()=>{const ce=a().reduce((wt,ft)=>wt+(ft.duration||0),0),je=Math.floor(ce/3600),Ge=Math.floor(ce%3600/60),qe=Math.floor(ce%60);return je>0?`${je}:${Ge.toString().padStart(2,"0")}:${qe.toString().padStart(2,"0")}`:`${Ge}:${qe.toString().padStart(2,"0")}`}),Ee.$$click=()=>{S()&&se(),(T()||C())&&I(),F(ce=>!ce)},Ae.$$click=()=>{O()&&F(!1),S()&&se(),T()?I():_()},Ie.$$click=()=>{S()?se():(O()&&F(!1),T()&&I(),U(!0))},Z(Ie,re(he,{get when(){return Dp()>0||Rp()>0},get children(){var ce=UU();return Z(ce,()=>Dp()+Rp()),ce}}),null),Z(be,re(he,{get when(){return Ct(()=>!!window.STANDALONE_MODE)()&&window.location.protocol!=="file:"},get children(){return re(he,{get when(){return!f()},get children(){var ce=jU();return nn(ce,"click",d,!0),Z(ce,re(he,{get when(){return!l()},get fallback(){return Zp()},children:"SAVE OFFLINE"})),we(()=>ce.disabled=l()||a().length===0),ce}})}}),null),Z(be,re(he,{get when(){return Ct(()=>!!(!window.STANDALONE_MODE&&Rd()))()&&w()},get children(){var ce=LU();return ce.$$click=()=>void P(),Z(ce,re(he,{get when(){return!D()},get fallback(){return Zp()},get children(){return MU()}})),we(je=>{var Ge=D()!==null,qe=D()?`fetching ${D().currentTitle} (${D().done}/${D().total})`:"save offline (fetch from peerz)";return Ge!==je.e&&(ce.disabled=je.e=Ge),qe!==je.t&&Ne(ce,"title",je.t=qe),je},{e:void 0,t:void 0}),ce}}),null),Z(be,re(he,{get when(){return window.location.protocol!=="file:"},get children(){var ce=NU(),je=ce.firstChild;return je.addEventListener("change",async Ge=>{const qe=Array.from(Ge.currentTarget.files??[]);qe.length&&(await s.processFileImport(qe,{selectedPlaylist:e.playlist(),playlists:t.playlists(),onPlaylistSelected:wt=>t.selectPlaylist(wt)}),Ge.currentTarget.value="")}),ce}}),null),we(ce=>{var je=O(),Ge=`p-2 hover:text-white hover:bg-gray-700 transition-colors bg-black/90 border ${O()?"text-magenta-400 border-magenta-500":"text-gray-400 border-transparent"}`,qe=T(),wt=`p-2 hover:text-white hover:bg-gray-700 transition-colors bg-black/90 border ${T()?"text-magenta-400 border-magenta-500":"text-gray-400 border-transparent"}`,ft=T()?"close edit panel":"edit playlist",vt=S(),yn=`relative p-2 hover:text-white hover:bg-gray-700 transition-colors bg-black/90 border ${S()?"text-magenta-400 border-magenta-500":Rd()?"text-magenta-400 border-transparent":"text-gray-400 border-transparent"}`,ur=Kr()>=1?"currentColor":"none",dr=Kr()>=1&&hu()?"animate-pulse":"",vr=Kr()>=2?"currentColor":"none",fr=Kr()>=2&&hu()?"animate-pulse":"",xr=Kr()>=3?"currentColor":"none",Rn=Kr()>=3&&hu()?"animate-pulse":"";return je!==ce.e&&Ne(Ee,"aria-expanded",ce.e=je),Ge!==ce.t&&ht(Ee,ce.t=Ge),qe!==ce.a&&Ne(Ae,"aria-expanded",ce.a=qe),wt!==ce.o&&ht(Ae,ce.o=wt),ft!==ce.i&&Ne(Ae,"title",ce.i=ft),vt!==ce.n&&Ne(Ie,"aria-expanded",ce.n=vt),yn!==ce.s&&ht(Ie,ce.s=yn),ur!==ce.h&&Ne(We,"fill",ce.h=ur),dr!==ce.r&&Ne(We,"class",ce.r=dr),vr!==ce.d&&Ne(at,"fill",ce.d=vr),fr!==ce.l&&Ne(at,"class",ce.l=fr),xr!==ce.u&&Ne(Be,"fill",ce.u=xr),Rn!==ce.c&&Ne(Be,"class",ce.c=Rn),ce},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0,l:void 0,u:void 0,c:void 0}),Se})()}function de(){return(()=>{var Se=VU(),Pe=Se.firstChild;return Pe.addEventListener("mouseleave",Te=>{const ke=e.playlist();if(ke.coverFilterEnabled===!1)Te.currentTarget.style.filter="none";else{const Ue=ke.coverFilterBlur??3;Te.currentTarget.style.filter=`blur(${Ue}px) contrast(3) brightness(0.4)`}}),Pe.addEventListener("mouseenter",Te=>Te.currentTarget.style.filter="none"),Pe.$$click=()=>{J(e.playlist(),a(),0)},Z(Pe,re(he,{get when(){return e.playlist().imageType},get fallback(){return Ea()},get children(){return(()=>{const Te=Vn(e.playlist(),"modal");return Te?(()=>{var ke=Hp();return Ne(ke,"src",Te),ke})():Ea()})()}})),we(Te=>{var ke=`${A()?"hidden":"ml-4"}`,Ue=(()=>{const Qe=e.playlist();return Qe.coverFilterEnabled===!1?"none":`blur(${Qe.coverFilterBlur??3}px) contrast(3) brightness(0.4)`})();return ke!==Te.e&&ht(Se,Te.e=ke),Ue!==Te.t&&Qn(Pe,"filter",Te.t=Ue),Te},{e:void 0,t:void 0}),Se})()}return[re(he,{get when(){return!A()},get children(){return te()}}),(()=>{var Se=JU(),Pe=Se.firstChild,Te=v;return typeof Te=="function"?po(Te,Se):v=Se,Z(Se,re(he,{get when(){return A()},get children(){return[Ct(()=>te()),(()=>{var ke=WU(),Ue=H;return typeof Ue=="function"?po(Ue,ke):H=ke,Z(ke,ge),we(Qe=>$r(ke,B(),Qe)),ke})()]}}),Pe),Z(Se,re(he,{get when(){return Ct(()=>!!(S()&&_e()))()?e.playlist().id:null},keyed:!0,get children(){var ke=Xs();return Z(ke,re(tU,{get playlist(){return e.playlist},get playlists(){return o()},onClose:se,onPlaylistAdded:Ue=>{t.selectById(Ue),se()}})),we(Ue=>$r(ke,z(),Ue)),ke}}),Pe),Z(Se,re(he,{get when(){return Ct(()=>!!O())()&&_e()},get children(){var ke=Xs();return Z(ke,re(PU,{onClose:()=>{F(!1),ie(void 0)},onEdit:Ue=>{t.selectPlaylist(Ue),F(!1),ie(void 0),setTimeout(()=>_(),0)},onShare:Ue=>{t.selectPlaylist(Ue),F(!1),ie(void 0),setTimeout(()=>U(!0),0)},onPlaylistAdded:Ue=>{t.selectById(Ue),F(!1),ie(void 0)},get initialQuery(){return X()}})),we(Ue=>$r(ke,z(),Ue)),ke}}),Pe),Z(Se,re(he,{get when(){return Ct(()=>!!(T()&&_e()))()?e.playlist().id:null},keyed:!0,get children(){var ke=Xs();return Z(ke,re(iB,{get playlist(){return e.playlist()},get playlistSongs(){return a()},onClose:I,onSave:Ue=>t.selectPlaylist(Ue),onFork:Ue=>{t.selectById(Ue),I()}})),we(Ue=>{var Qe=z(),be=A()?"p-2":"px-6 pt-2 pb-4";return Ue.e=$r(ke,Qe,Ue.e),be!==Ue.t&&ht(ke,Ue.t=be),Ue},{e:void 0,t:void 0}),ke}}),Pe),Z(Se,re(he,{get when(){return Ct(()=>!!(C()&&_e()))()?C().id:null},keyed:!0,get children(){var ke=Xs();return Z(ke,re($B,{get song(){return C()},get index(){return Ce()},onClose:I,onSave:R,get prevSong(){return Oe(-1)},get nextSong(){return Oe(1)},onNavigate:x})),we(Ue=>{var Qe=z(),be=A()?"":"px-6 pt-2 pb-4";return Ue.e=$r(ke,Qe,Ue.e),be!==Ue.t&&ht(ke,Ue.t=be),Ue},{e:void 0,t:void 0}),ke}}),Pe),Z(Pe,re(he,{get when(){return Ct(()=>!$e())()&&(!e.playlist().songIds||e.playlist().songIds.length===0)},get children(){var ke=qU(),Ue=ke.firstChild,Qe=Ue.nextSibling,be=Qe.nextSibling,Ee=be.firstChild;return Ee.firstChild,Z(Ee,()=>e.playlist().id,null),we(()=>ht(ke,`${A()?"":"ml-42 mr-42"} text-center p-8 bg-black/75`)),ke}}),null),Z(Pe,re(Gr,{get each(){return e.playlist().songIds},children:(ke,Ue)=>{const Qe=()=>C()?.id===ke,be=()=>Ye.selectedSongId()===ke||Ye.currentSong()?.id===ke&&Ye.isPlaying();return re(he,{get when(){return!Qe()},get children(){var Ee=KU(),Ae=Ee.firstChild;return Z(Ae,re(ZF,{songId:ke,get index(){return Ue()},get showRemoveButton(){return!b()},onRemove:g,onPlay:N,onPause:k,onEdit:x,get onReorder(){return b()?void 0:p}})),we(Ie=>{var Ve={...V(),...be()?{top:`${Y()}px`}:{}},ot=be()?"sticky bottom-0 z-100":"",et=L(Ue());return Ie.e=$r(Ee,Ve,Ie.e),ot!==Ie.t&&ht(Ee,Ie.t=ot),Ie.a=$r(Ae,et,Ie.a),Ie},{e:void 0,t:void 0,a:void 0}),Ee}})}}),null),we(ke=>{var Ue=`${A()?"space-y-1":"p-6 space-y-2"}`,Qe=_e()?{display:"none"}:{};return Ue!==ke.e&&ht(Pe,ke.e=Ue),ke.t=$r(Pe,Qe,ke.t),ke},{e:void 0,t:void 0}),Se})()]}),we(()=>ht(M,`flex-1 flex flex-col min-h-0 [overflow-x:clip] ${A()?"p-2":"p-6"}`)),M})()}function QU(e){const[t,n]=Q(!1),[r,i]=Q(null),s=async()=>{if(!t()){n(!0),i(null);try{const a=await Cy(e.playlist.id);e.onFork(a.id)}catch(a){i("fork failed"),console.error("fork error:",a)}finally{n(!1)}}},o=()=>e.playlist.remoteName||e.playlist.remoteNodeId?.slice(0,16)||"peer";return(()=>{var a=YU(),c=a.firstChild,l=c.nextSibling,f=l.nextSibling;f.firstChild;var u=f.nextSibling,h=u.firstChild;return Z(f,o,null),h.$$click=()=>void s(),Z(h,()=>t()?"forking...":"fork my copy"),Z(a,re(he,{get when(){return r()},get children(){var d=GU();return Z(d,r),d}}),null),we(()=>h.disabled=t()),a})()}Fr(["click","input"]);var ej=ee('<div class="absolute inset-0 bg-no-repeat transition-opacity duration-1000 ease-out"style=z-index:0>'),tj=ee('<div class="absolute inset-0 bg-black/20"style=z-index:1>'),nj=ee('<div class="absolute inset-0 opacity-5"style="background-image:radial-gradient(circle at 25% 25%, #ff00ff 2px, transparent 2px);background-size:50px 50px;z-index:0">'),rj=ee("<h1 class=sr-only data-testid=app-ready>playlistz"),ij=ee('<div class="relative flex h-full min-w-0"style=z-index:2><div class="flex-1 flex flex-col min-h-0 min-w-0">'),sj=ee('<div class="fixed inset-0 bg-black bg-opacity-80 flex items-center justify-center z-50 backdrop-blur-sm"><div class=text-center><div class="text-4xl mb-6 font-bold">drop zone</div><h2 class="text-4xl font-light mb-4 text-magenta-400">drop your filez here</h2><p class="text-xl text-gray-300">release to add filez to '),oj=ee('<div class="fixed bottom-4 right-4 z-50 max-w-sm"><div class="bg-red-900 bg-opacity-90 border border-red-500 p-4 shadow-lg"><div class="text-red-200 text-sm">'),aj=ee('<div class="fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50"><div class="bg-gray-900 border border-gray-600 p-6 max-w-md w-full mx-4"><h3 class="text-lg font-semibold text-white mb-4">delete playlist?</h3><p class="text-gray-300 mb-6">are you sure you want to delete "<!>"? this action cannot be undone.</p><div class="flex gap-3 justify-end"><button class="px-4 py-2 text-gray-300 hover:text-white bg-gray-700 hover:bg-gray-600 rounded transition-colors">cancel</button><button class="px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded transition-colors">delete'),cj=ee('<div class="absolute bottom-4 left-1/2 transform -translate-x-1/2 text-white bg-black bg-opacity-50 px-3 py-1"><span class=text-xs>/'),lj=ee('<div class="relative w-full h-full flex items-center justify-center p-4"><img class="max-w-full max-h-full object-contain">'),uj=ee('<div class="fixed inset-0 bg-black bg-opacity-90 flex items-center justify-center z-50"><button class="absolute top-4 right-4 text-white hover:text-magenta-400 transition-colors z-10 p-2 bg-black bg-opacity-50 rounded"title="close (esc)"><svg class="w-6 h-6"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M6 18L18 6M6 6l12 12">'),dj=ee('<div data-testid=app-root class="relative bg-black text-white h-screen overflow-hidden">'),fj=ee('<div class="flex items-center justify-center h-full"><div class=text-center><div class="inline-block animate-spin rounded-full h-8 w-8"></div><p class=text-lg>loading playlistz...'),hj=ee('<svg class="w-4 h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M12 4v16m8-8H4">'),gj=ee('<div class="flex items-center justify-center h-full text-gray-400 text-sm"><div class=text-center><p class="mb-6 text-gray-500"data-testid=empty-playlists>no playlistz yet</p><button data-testid=btn-new-playlist class="flex items-center gap-2 px-4 py-2 bg-magenta-500 hover:bg-magenta-600 disabled:opacity-60 text-white text-sm font-medium transition-colors mx-auto"><span>'),pj=ee('<div class="w-3.5 h-3.5 border-2 border-white border-t-transparent rounded-full animate-spin">');function mj(){const e=Ms(),t=Tb(),n=Db(),r=Rb(),i=Fb(),{playlists:s,selectedPlaylist:o,isInitialized:a,error:c,backgroundImageUrl:l,selectPlaylist:f}=e,{showDeleteConfirm:u,setShowDeleteConfirm:h,handleDeletePlaylist:d}=e,{editingPlaylist:g,error:p}=t,{isMobile:m}=n,{isDragOver:b,handleDragEnter:x,handleDragOver:_,handleDragLeave:E,handleFileDrop:k,processFileImport:C,setIsDragOver:T,error:j}=r,{showImageModal:I,closeImageModal:R,handleNextImage:N,handlePrevImage:D,getCurrentImageUrl:y,getCurrentImageTitle:w,getImageCount:$,getCurrentImageNumber:P,hasMultipleImages:A}=i,J=()=>c()||p()||j(),S=()=>{const ve=o();if(!ve)return"blur(3px) contrast(3) brightness(0.4)";if(ve.bgFilterEnabled===!1)return"none";const me=ve.bgFilterBlur??3,_e=ve.bgFilterContrast??3,xe=ve.bgFilterBrightness??.4;return`blur(${me}px) contrast(${_e}) brightness(${xe})`},U=()=>o()?.bgSize??"cover",O=()=>o()?.bgPosition??"top",F=()=>o()?.bgRepeat??"no-repeat",X=async ve=>{const me=o();me?.remoteNodeId&&!me?.isForked||await k(ve,{selectedPlaylist:o(),playlists:s(),onPlaylistCreated:()=>{},onPlaylistSelected:_e=>{f(_e)}})};let ie=!1;const[se,$e]=Q(null),[Ce,Oe]=Q(null);zt(()=>{!a()||ie||window.location.hash.startsWith("#share/")&&(ie=!0,(async()=>{try{const{handleShareFragment:ve}=await Xr(async()=>{const{handleShareFragment:_e}=await Promise.resolve().then(()=>Dd);return{handleShareFragment:_e}},void 0),me=await ve();if(me?.status==="synced"){const _e=s().find(xe=>xe.id===me.docId);if(_e){f(_e);const{playPlaylist:xe,audioState:v}=await Xr(async()=>{const{playPlaylist:V,audioState:L}=await Promise.resolve().then(()=>V0);return{playPlaylist:V,audioState:L}},void 0);v.isPlaying()||xe(_e)}else $e(me.docId)}else me?.status==="knock_required"&&Oe(me)}catch(ve){Fe.warn("share.fragment","share link open failed:",ve)}})())}),zt(()=>{const ve=se();if(!ve)return;const me=s().find(_e=>_e.id===ve);me&&($e(null),f(me),(async()=>{const{playPlaylist:_e,audioState:xe}=await Xr(async()=>{const{playPlaylist:v,audioState:V}=await Promise.resolve().then(()=>V0);return{playPlaylist:v,audioState:V}},void 0);xe.isPlaying()||_e(me)})())});let ye=!1;return zt(()=>{!a()||ye||(ye=!0,(async()=>{try{const{resumeSharingIfEnabled:ve}=await Xr(async()=>{const{resumeSharingIfEnabled:me}=await Promise.resolve().then(()=>Dd);return{resumeSharingIfEnabled:me}},void 0);await ve()}catch(ve){Fe.warn("p2p.resume","p2p resume failed:",ve)}})())}),(()=>{var ve=dj();return ve.addEventListener("drop",X),nn(ve,"dragleave",E),nn(ve,"dragover",_),nn(ve,"dragenter",x),Z(ve,re(he,{get when(){return l()},get children(){return[(()=>{var me=ej();return we(_e=>{var xe=`url(${l()})`,v=U(),V=O(),L=F(),B=S();return xe!==_e.e&&Qn(me,"background-image",_e.e=xe),v!==_e.t&&Qn(me,"background-size",_e.t=v),V!==_e.a&&Qn(me,"background-position",_e.a=V),L!==_e.o&&Qn(me,"background-repeat",_e.o=L),B!==_e.i&&Qn(me,"filter",_e.i=B),_e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),me})(),tj()]}}),null),Z(ve,re(he,{get when(){return!l()},get children(){return nj()}}),null),Z(ve,re(he,{get when(){return a()},get fallback(){return fj()},get children(){return[rj(),re(he,{get when(){return Ce()},get children(){return re(Gb,{get ownerNodeId(){return Ce().ownerNodeId},get docId(){return Ce().docId},get title(){return Ce().title},get ownerName(){return Ce().ownerName},onAccepted:me=>{Oe(null),$e(me)},onDismiss:()=>Oe(null)})}}),(()=>{var me=ij(),_e=me.firstChild;return Z(_e,re(he,{get when(){return o()},get fallback(){return re(_j,{})},children:xe=>re(XU,{playlist:xe})})),me})()]}}),null),Z(ve,re(he,{get when(){return b()},get children(){var me=sj(),_e=me.firstChild,xe=_e.firstChild,v=xe.nextSibling,V=v.nextSibling;return V.firstChild,me.$$click=()=>{T(!1)},Z(V,()=>o()?.title||"a new playlist",null),me}}),null),Z(ve,re(he,{get when(){return J()},get children(){var me=oj(),_e=me.firstChild,xe=_e.firstChild;return Z(xe,J),me}}),null),Z(ve,re(he,{get when(){return u()},get children(){var me=aj(),_e=me.firstChild,xe=_e.firstChild,v=xe.nextSibling,V=v.firstChild,L=V.nextSibling;L.nextSibling;var B=v.nextSibling,z=B.firstChild,H=z.nextSibling;return Z(v,()=>o()?.title,L),z.$$click=()=>h(!1),nn(H,"click",d,!0),me}}),null),Z(ve,re(he,{get when(){return I()},get children(){var me=uj(),_e=me.firstChild;return nn(_e,"click",R,!0),Z(me,re(he,{get when(){return y()},get children(){var xe=lj(),v=xe.firstChild;return nn(v,"contextmenu",m()?D:void 0,!0),nn(v,"click",N,!0),Z(xe,re(he,{get when(){return A()},get children(){var V=cj(),L=V.firstChild,B=L.firstChild;return Z(V,re(he,{get when(){return w()},get children(){return[Ct(()=>w())," "]}}),L),Z(L,P,B),Z(L,$,null),V}}),null),we(V=>{var L=y(),B=w()||"song image";return L!==V.e&&Ne(v,"src",V.e=L),B!==V.t&&Ne(v,"alt",V.t=B),V},{e:void 0,t:void 0}),xe}}),null),me}}),null),ve})()}function _j(){const{createNewPlaylist:e,selectPlaylist:t}=Ms(),[n,r]=Q(!1),i=async()=>{if(!n()){r(!0);try{const s=await e("new playlist");s&&t(s)}finally{r(!1)}}};return(()=>{var s=gj(),o=s.firstChild,a=o.firstChild,c=a.nextSibling,l=c.firstChild;return c.$$click=i,Z(c,re(he,{get when(){return!n()},get fallback(){return pj()},get children(){return hj()}}),l),Z(l,()=>n()?"creating...":"new playlist"),we(()=>c.disabled=n()),s})()}function yj(){return re(dF,{get children(){return re(mj,{})}})}Fr(["click","contextmenu"]);const bj=()=>re(yj,{}),Ud=document.getElementById("root");Ud&&(Ud.innerHTML="");_w(()=>re(bj,{}),Ud)})();export{l_ as _,__tla};
|