clipoox-render 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/server-text/titleRaster.js +1394 -0
  2. package/package.json +5 -3
  3. package/scripts/render-local.mjs +1514 -1379
  4. package/shared/transitionStarterPack.json +261 -0
  5. package/web/assets/{FxEmbed-BymBArNa.js → FxEmbed-D7k1ThAF.js} +1 -1
  6. package/web/assets/{GLTFLoader-Dy6SrZg8.js → GLTFLoader-BHWu1lKg.js} +1 -1
  7. package/web/assets/{MotionEmbed-PmXWSWe5.js → MotionEmbed-DFni5IAh.js} +1 -1
  8. package/web/assets/PluginStore-BrupM_8E.js +3 -0
  9. package/web/assets/{ShotComposer-Dprx-Yi7.js → ShotComposer-BLztjSKy.js} +4 -4
  10. package/web/assets/TemplateEmbed-BbAimhLj.js +2 -0
  11. package/web/assets/TimelinePlugins-BI1bE9pX.js +5 -0
  12. package/web/assets/TimelinePlugins-DYarX9RK.css +1 -0
  13. package/web/assets/TimelineShotFx-CQN3WIfN.js +2 -0
  14. package/web/assets/TransitionEmbed-CmoIrHVr.js +1 -0
  15. package/web/assets/{Whiteboard-DybaKCdo.js → Whiteboard-DMk0unYK.js} +3 -3
  16. package/web/assets/aerial-DT_gUtSh.js +2 -0
  17. package/web/assets/{agentTools-CxZqRLeR.js → agentTools-qOww5RUs.js} +2 -2
  18. package/web/assets/analyzerRun-B2FLUp4G.js +1 -0
  19. package/web/assets/{analyzerSandbox-DO5ZTv5q.js → analyzerSandbox-CJVsEhrg.js} +2 -2
  20. package/web/assets/{api-BsKbf3l3.js → api-QBI5GJTZ.js} +148 -148
  21. package/web/assets/auraTrack-CEs_Q9EP.js +1 -0
  22. package/web/assets/{breakthrough-Dv1bndQb.js → breakthrough-DvkxvNK9.js} +2 -2
  23. package/web/assets/{cameraPresets-B234aNzE.js → cameraPresets-4pFeF2YG.js} +1 -1
  24. package/web/assets/{captionLayout-CNgb471H.js → captionLayout-C67EMVI1.js} +1 -1
  25. package/web/assets/{clientExport-NtJmxOYP.js → clientExport-C4VgAJtO.js} +1 -1
  26. package/web/assets/{depthEstimate-wVYSJtW8.js → depthEstimate-mnXDZMW-.js} +1 -1
  27. package/web/assets/{directorTools-BqFcShgT.js → directorTools-BOHZjcww.js} +1 -1
  28. package/web/assets/{distortFrames-D3TQNcJA.js → distortFrames-Csuj2jHE.js} +2 -2
  29. package/web/assets/{distortGL-BklPDXPq.js → distortGL-BaXfN0IK.js} +2 -2
  30. package/web/assets/{editTools-BQlG5WB_.js → editTools-m0VGPmfF.js} +1 -1
  31. package/web/assets/{exportEncode-CaKEPgsy.js → exportEncode-D9OT7_5k.js} +1 -1
  32. package/web/assets/{exportGlb-DstxwzH5.js → exportGlb-CLfTnbMG.js} +1 -1
  33. package/web/assets/faceTracker-W0iZSiMe.js +1 -0
  34. package/web/assets/fightDirector-CECPf2iH.js +1 -0
  35. package/web/assets/{fightDrama-G7bXfpQu.js → fightDrama-CqNoa5XI.js} +2 -2
  36. package/web/assets/{frameSink-Dj71jCRb.js → frameSink-BGRj7wqY.js} +3 -3
  37. package/web/assets/{gpuCompose-DIxBHlTa.js → gpuCompose-CIEoLFem.js} +1 -1
  38. package/web/assets/gpuExport-uyOAyrhm.js +190 -0
  39. package/web/assets/handMatte-mHxZwLZD.js +1 -0
  40. package/web/assets/handTracker-dTVeSUzt.js +2 -0
  41. package/web/assets/{index-CZn97Ygs.js → index-D7M5t2re.js} +1 -1
  42. package/web/assets/layer-worker-Cp0pjurp.js +5 -0
  43. package/web/assets/library-Dsz_MLyd.js +1 -0
  44. package/web/assets/{lottieLayer-CfUPParC.js → lottieLayer-CDCGeJyv.js} +5 -5
  45. package/web/assets/{lottie_light_canvas-7iv3btPX.js → lottie_light_canvas-BblLU4nU.js} +1 -1
  46. package/web/assets/main-BQ8IY0WV.css +1 -0
  47. package/web/assets/{main-M1vRa-gd.js → main-CVRIuDW2.js} +76 -76
  48. package/web/assets/{mapBake-lPNhNZgv.js → mapBake-CNMOKXA7.js} +1 -1
  49. package/web/assets/maskTrack-Dtv6Jr06.js +1 -0
  50. package/web/assets/matteFixRun-BLDH2AjH.js +1 -0
  51. package/web/assets/{objectLocate-BDqfSo9J.js → objectLocate-Cy3IFBSF.js} +1 -1
  52. package/web/assets/{objectTrack.worker-ENzKeSiV.js → objectTrack.worker-BlZkgpOX.js} +483 -352
  53. package/web/assets/pendingMatte-C2AWApuv.js +2 -0
  54. package/web/assets/personAi-DPUnoymj.js +2 -0
  55. package/web/assets/plateCamera-C96L5GKm.js +1 -0
  56. package/web/assets/{plateCameraMatch-D41LQrsm.js → plateCameraMatch-Chk-ZjDi.js} +2 -2
  57. package/web/assets/{plateFollow-CNfi4xuP.js → plateFollow-B9_QTgvo.js} +2 -2
  58. package/web/assets/plateMatte-BiqyI_8x.js +2 -0
  59. package/web/assets/{pluginAutomation-BtQ_w2TB.js → pluginAutomation-5DYldFrb.js} +1 -1
  60. package/web/assets/poseTracker-PuI8vWpR.js +1 -0
  61. package/web/assets/{productTools-r2RgILaA.js → productTools-B1h5cgyt.js} +2 -2
  62. package/web/assets/remote-BJdzzFZg.js +1241 -0
  63. package/web/assets/{rigTrack-Bx9QHlFv.js → rigTrack-CUt4O67J.js} +1 -1
  64. package/web/assets/{rotoMaskStore-pxpRt5Cj.js → rotoMaskStore-DIi45swK.js} +1 -1
  65. package/web/assets/{rotoMatte-DyXlW4jK.js → rotoMatte-013RKqHu.js} +1 -1
  66. package/web/assets/{rotoscope-GORCSVBr.js → rotoscope-d_TUxa-J.js} +1 -1
  67. package/web/assets/{sceneTrack.worker-CEvCN5OB.js → sceneTrack.worker-CT4uoTKn.js} +475 -344
  68. package/web/assets/{shot-worker-B8JWkmBz.js → shot-worker-B1iZT6F5.js} +1 -1
  69. package/web/assets/{shotFxAgent-CzHfe75S.js → shotFxAgent-BDfe73TP.js} +2 -2
  70. package/web/assets/{skin-BkaT2QuX.js → skin-GDY3QPkV.js} +1 -1
  71. package/web/assets/{spark.module-BRT8yMS4.js → spark.module-DdwuJ_hb.js} +1 -1
  72. package/web/assets/{spellDuel-BUy289OT.js → spellDuel-DjNN00bv.js} +2 -2
  73. package/web/assets/{store-BSSbvpzr.js → store-2zneEhhu.js} +1 -1
  74. package/web/assets/{surfaceLight-CMaBhZ_d.js → surfaceLight-B_SYg_f8.js} +1 -1
  75. package/web/assets/surfacePin-zDPmq-hH.js +2 -0
  76. package/web/assets/{textAnimators-Cihw35O8.js → textAnimators-Bdt5LWXk.js} +1 -1
  77. package/web/assets/{thumb-Cs636sYt.js → thumb-byAKvhQP.js} +1 -1
  78. package/web/assets/timeline3d-YIIk_Kn2.js +2 -0
  79. package/web/assets/timeline3dExport-CEH1RjNf.js +1 -0
  80. package/web/assets/{timelineComp-CRRzLazc.js → timelineComp-B73i_8vD.js} +1 -1
  81. package/web/assets/{timelineProps-tN2YsMYN.js → timelineProps-B2pnudeT.js} +1 -1
  82. package/web/assets/{timelineText-CkoUgWcY.js → timelineText-BcL4Pw3C.js} +1 -1
  83. package/web/assets/{titleArt-CcTdJuOC.js → titleArt-hb_T45WJ.js} +5 -5
  84. package/web/assets/{titleFrameBudget-3MFHWIT6.js → titleFrameBudget-Cml-MO53.js} +970 -839
  85. package/web/assets/titleFrames-Dw0PEBdV.js +1 -0
  86. package/web/assets/{tool-BhIsq238.js → tool-Bt9bclIf.js} +1 -1
  87. package/web/assets/{tools-DMUnabc_.js → tools-BXeJbgZJ.js} +1 -1
  88. package/web/assets/{toonTools-CICrV3QB.js → toonTools-u7Y9fdEZ.js} +2 -2
  89. package/web/assets/trackAnchor-9MnVHe4S.js +1 -0
  90. package/web/assets/{userFonts-BZ4QL-zq.js → userFonts-BHduCNtc.js} +1 -1
  91. package/web/assets/{vfxAlpha-D3Dk1tfF.js → vfxAlpha-DpV4rbI-.js} +1 -1
  92. package/web/assets/vfxBackground-Ddviync5.js +2 -0
  93. package/web/assets/{videoExport-l5MGvMn_.js → videoExport-z5WjM0hw.js} +1 -1
  94. package/web/assets/{views-BdWnG2xK.js → views-CsrYzCSR.js} +1 -1
  95. package/web/assets/weaponDuel-CLLgv5A4.js +1 -0
  96. package/web/assets/{windowFrames-CoIyWqxr.js → windowFrames-BQEWQkEs.js} +1 -1
  97. package/web/layer-worker.html +3 -3
  98. package/web/assets/PluginStore-BVsm6n6N.js +0 -3
  99. package/web/assets/TemplateEmbed-CrZXoUk_.js +0 -2
  100. package/web/assets/TimelinePlugins-B1KGtbmb.js +0 -5
  101. package/web/assets/TimelinePlugins-B5WmAawO.css +0 -1
  102. package/web/assets/TimelineShotFx-DoLx312Y.js +0 -2
  103. package/web/assets/TransitionEmbed-C5SUosv2.js +0 -1
  104. package/web/assets/aerial-DSt_mJNA.js +0 -2
  105. package/web/assets/analyzerRun-DCJwb_-Z.js +0 -1
  106. package/web/assets/auraTrack-QR0WqBHp.js +0 -1
  107. package/web/assets/desktop-BWhFnYwd.js +0 -1
  108. package/web/assets/faceTracker-DWxxieVC.js +0 -1
  109. package/web/assets/fightDirector-OMlPZgjv.js +0 -1
  110. package/web/assets/gpuExport-CPSw_dmq.js +0 -189
  111. package/web/assets/handMatte-DHsHHz4m.js +0 -1
  112. package/web/assets/handTracker-D_O-C4Dw.js +0 -2
  113. package/web/assets/layer-worker-Bar7WgOA.js +0 -5
  114. package/web/assets/library-BtBrCaFk.js +0 -1
  115. package/web/assets/main-BPmr0TOL.css +0 -1
  116. package/web/assets/maskTrack-D2jUh7aw.js +0 -1
  117. package/web/assets/matteFixRun-B7tWV9Y1.js +0 -1
  118. package/web/assets/pendingMatte-q35zVaiB.js +0 -2
  119. package/web/assets/personAi-ZjQVo-80.js +0 -2
  120. package/web/assets/plateCamera-A2E_WO_x.js +0 -1
  121. package/web/assets/plateMatte-BdIxGhw5.js +0 -2
  122. package/web/assets/poseTracker-DVX__OK7.js +0 -1
  123. package/web/assets/remote-sTZauTqM.js +0 -1220
  124. package/web/assets/surfacePin-DM9b9ubh.js +0 -2
  125. package/web/assets/timeline3d-BEuZZOxM.js +0 -2
  126. package/web/assets/timeline3dExport-CmSI_pjv.js +0 -1
  127. package/web/assets/titleFrames-w-iWje9N.js +0 -1
  128. package/web/assets/trackAnchor-D2bB5mZE.js +0 -1
  129. package/web/assets/vfxBackground-CHlCg8lb.js +0 -2
  130. package/web/assets/vfxTrack-CqiQDEYm.js +0 -1
  131. package/web/assets/weaponDuel-B2wTffPC.js +0 -1
@@ -0,0 +1,5 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/rotoMaskStore-DIi45swK.js","assets/titleFrameBudget-Cml-MO53.js","assets/api-QBI5GJTZ.js","assets/timeline3dExport-CEH1RjNf.js","assets/timeline3d-YIIk_Kn2.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-BHWu1lKg.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/frameSink-BGRj7wqY.js","assets/titleFrames-Dw0PEBdV.js","assets/titleArt-hb_T45WJ.js","assets/textAnimators-Bdt5LWXk.js","assets/lottieLayer-CDCGeJyv.js","assets/rigTrack-CUt4O67J.js","assets/rotoMatte-013RKqHu.js","assets/store-2zneEhhu.js","assets/windowFrames-BQEWQkEs.js","assets/gpuExport-uyOAyrhm.js","assets/timelineComp-B73i_8vD.js","assets/gpuCompose-CIEoLFem.js","assets/motionBlur-uAm030t9.js","assets/exportEncode-D9OT7_5k.js","assets/distortGL-BaXfN0IK.js","assets/id3-BCR9Bqgo.js","assets/output-BwZzMbp-.js","assets/clientExport-C4VgAJtO.js"])))=>i.map(i=>d[i]);
2
+ import{_ as l,b$ as v,iM as $}from"./titleFrameBudget-Cml-MO53.js";import{FrameSink as b,SKIPPED_FRAME as P}from"./frameSink-BGRj7wqY.js";class x extends b{want;next=new Map;last=new Map;out={};constructor(o){super({put:async()=>{throw Error("a pick sink keeps its frames")}}),this.want=new Map;for(const[c,s]of Object.entries(o))for(const[r,n]of Object.entries(s||{}))this.want.set(`${c}
3
+ ${r}`,new Set(n));this.wants=(c,s,r)=>{const n=this.want.get(`${c}
4
+ ${s}`);return!!n&&(r===void 0||n.has(r))}}async push(o,c,s){const r=`${o}
5
+ ${c}`,n=this.next.get(r)??0;if(this.next.set(r,n+1),s===P)return;const a=s==="="?this.last.get(r):s;a!==void 0&&(this.last.set(r,a),this.want.get(r)?.has(n)&&(((this.out[o]??={})[c]??={})[n]=a))}picked(){return this.out}}const F=(i,o)=>Object.keys(i[o]||{}).length>0,O={async frames({clips:i,format:o,camera:c=null,want:s}){const{unpackMasks:r}=await l(async()=>{const{unpackMasks:e}=await import("./rotoMaskStore-DIi45swK.js").then(w=>w.X);return{unpackMasks:e}},__vite__mapDeps([0,1,2])),n=await r(i);i=n.clips;const a=new x(s),g={},p=v(o).fps,d=a.wants,h=async(e,w,_)=>{for(const f of w){a.wants=(u,k,y)=>u===e&&k===f&&d(u,k,y);try{await _()}catch(u){g[f]=String(u?.message||u).slice(0,200)}finally{a.wants=d}}},E=e=>Object.keys(s[e]||{});if(F(s,"modelFrames")){const{render3DFrames:e}=await l(async()=>{const{render3DFrames:w}=await import("./timeline3dExport-CEH1RjNf.js");return{render3DFrames:w}},__vite__mapDeps([3,1,4,5,6,2,7,8]));await h("modelFrames",E("modelFrames"),()=>e(i,o,a,void 0,c))}if(F(s,"titleFrames")){const{renderTitleFrames:e}=await l(async()=>{const{renderTitleFrames:_}=await import("./titleFrames-Dw0PEBdV.js");return{renderTitleFrames:_}},__vite__mapDeps([9,1,10,11,12,13,2,8])),w=[...i,...$(i)];await h("titleFrames",E("titleFrames"),()=>e(w,o,a,void 0,c))}if(F(s,"matteFrames")){const e=await l(()=>import("./rotoMatte-013RKqHu.js").then(_=>_.r),__vite__mapDeps([14,1,2,15])),w=[...i,...e.maskedCopies(i)];await h("matteFrames",E("matteFrames"),()=>e.renderMatteFrames(w,p,a))}if(F(s,"windowFrames")){const e=await l(()=>import("./windowFrames-BQEWQkEs.js"),__vite__mapDeps([16,1,14,2,15]));await h("windowFrames",E("windowFrames"),()=>e.renderWindowFrames(i,p,a))}return{frames:a.picked(),failed:g,missingMasks:n.missing}},async gpuExport({clips:i,format:o,tracks:c={},camera:s=null,encode:r=null,range:n,only:a,name:g="film.mp4",softwareEncoder:p=!1}){const d=await l(()=>import("./gpuExport-uyOAyrhm.js"),__vite__mapDeps([17,1,18,19,20,21,2,22,23,24]));if(p){if(a!=="video"||!await d.canEncodeH264(o))throw Object.assign(new Error("no H.264 encoder in this browser"),{name:"NoEncoder"})}else if(!await d.gpuExportSupported(o,r))throw Object.assign(new Error("no hardware video encoder in this browser"),{name:"NoEncoder"});const{softwareRetry:h}=await l(async()=>{const{softwareRetry:t}=await import("./clientExport-C4VgAJtO.js");return{softwareRetry:t}},__vite__mapDeps([25,1,18])),E=t=>{try{window.__clipooxProgress?.(t)}catch{}};let e=p;const w=`/__clipoox/out/${encodeURIComponent(g)}`,_=()=>new WritableStream({async write(t){const m=await fetch(`${w}?at=${t.position}`,{method:"PATCH",body:t.data});if(!m.ok)throw new Error(`the film could not be handed over (${m.status})`)}}),f=t=>d.exportOnGpu(i,{format:o,encode:r,tracks:c,camera:s,onProgress:E,software:t,liveMotion:!0,range:n,only:a,sink:_()}),u=t=>{const m=t instanceof Error?`${t.name}: ${t.message}`:String(t);return new Error(`${d.gpuExportStage()||"start"}${n?` (frames ${n.from}–${n.to})`:""}: ${m}`)},k=await f(p).catch(t=>{if(!h(t,d.gpuExportStage(),r))throw u(t);return e=!0,f(!0).catch(m=>{throw u(m)})});let y="";try{const t=document.createElement("canvas").getContext("webgl2"),m=t?.getExtension("WEBGL_debug_renderer_info");y=String(m&&t?t.getParameter(m.UNMASKED_RENDERER_WEBGL):"").slice(0,120)}catch{}return{ms:k.ms,software:e,gpu:y}}};window.__layerWorker=O;
@@ -0,0 +1 @@
1
+ import{gw as f}from"./remote-BJdzzFZg.js";import{i6 as q,hq as G,i7 as L,i8 as P}from"./remote-BJdzzFZg.js";import{e as l}from"./skin-GDY3QPkV.js";import"./api-QBI5GJTZ.js";import"./titleFrameBudget-Cml-MO53.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-2zneEhhu.js";import"./rotoMaskStore-DIi45swK.js";import"./textAnimators-Bdt5LWXk.js";import"./timelineComp-B73i_8vD.js";import"./rigTrack-CUt4O67J.js";async function S(o,s,a,m=2e4){let e;for(const t=Date.now()+m;!e&&Date.now()<t;){const i=o.getStage().items.find(r=>r.id===s);if(!i||i.rig!==a)return!1;e=o.engine()?.objects?.children.find(r=>r.userData.id===s)?.children[0],e||await new Promise(r=>setTimeout(r,150))}if(!e)return!1;const p=f(a,{positions:l(e).positions});let n=!1;return o.setStage(t=>({...t,items:t.items.map(i=>i.id===s&&i.rig===a?(n=!0,{...i,rig:p}):i)})),n}export{S as fitLibraryFingers,q as libraryModelFields,G as libraryModelItem,L as libraryRig,P as wantsFingers};
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-CZn97Ygs.js","assets/api-BsKbf3l3.js","assets/titleFrameBudget-3MFHWIT6.js","assets/opentype.module-DcKU8U04.js","assets/GLTFLoader-Dy6SrZg8.js","assets/three.module-Bx43vjkH.js","assets/lottie_light_canvas-7iv3btPX.js"])))=>i.map(i=>d[i]);
2
- import{hH as Dt,lS as Bt,js as Nt,lT as pn,lU as Ft,lV as dn,lW as mn,N as gn,lX as yn,lY as wn,lZ as bn,_ as U,l_ as Mn,hG as _n,l$ as kn,m0 as Sn,m1 as An,m2 as ft,m3 as En,f_ as tt,gz as Tn,g0 as nt,gA as xn,fA as V,gt as ct,gB as vn,cB as Ce,m4 as On,go as rt,m5 as Ln,gp as Gt,gC as Pn,m6 as $n,m7 as Rn,m8 as Cn,m9 as In,ma as jn,mb as Dn,mc as Bn,md as Ht,me as Nn,mf as Fn,mg as Gn,br as Hn,bB as zn,mh as Wn,mi as fe,mj as qn,mk as Un,ml as Kn,mm as Vn,mn as Jn,mo as ce,mp as Ie,mq as ht,mr as Yn,ms as Xn,bx as Zn,mt as Qn,mu as ut,mv as er,mw as tr,gr as nr,cK as rr,fn as sr,gq as zt,c0 as or,g$ as ar,eb as oe,iq as ir,eQ as lr,fl as fr,b_ as we,ec as je,ed as pt,mx as cr,my as W,hF as hr,kS as ur}from"./titleFrameBudget-3MFHWIT6.js";import{W as pr,X as dr,r as mr}from"./rigTrack-Bx9QHlFv.js";import{t as le,bU as gr,az as yr,s as wr}from"./api-BsKbf3l3.js";function De(e){if(typeof e!="string")return null;const t=(o,a=!1)=>o.split(",").map(i=>i.trim()).filter(Boolean).map(i=>{const[l,f]=i.split(/\s+as\s+/);return a?f?`${f}:${l}`:l:f?`${l}:${f}`:l}).join(",");let n=e.replace(/^import\s*\{([^}]*)\}\s*from\s*['"]three['"];?/m,(o,a)=>`const {${t(a)}}=THREE;`);if(n=n.replace(/^import\s*\{([^}]*)\}\s*from\s*['"]\.\.\/utils\/([A-Za-z]+)\.js['"];?/mg,(o,a,i)=>`const {${t(a)}}=__deps.${i};`),/^\s*import\s/m.test(n))return null;const r=/^export\s*\{([^}]*)\};?[ \t]*$/m,s=r.exec(n);return!s||(n=n.replace(r,`return {${t(s[1],!0)}};`),/^export\s/m.test(n))?null:'"use strict";'+n}const Wt=`async(THREE,items,LOADERS,flip)=>{
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-D7M5t2re.js","assets/api-QBI5GJTZ.js","assets/titleFrameBudget-Cml-MO53.js","assets/opentype.module-DcKU8U04.js","assets/GLTFLoader-BHWu1lKg.js","assets/three.module-Bx43vjkH.js","assets/lottie_light_canvas-BblLU4nU.js"])))=>i.map(i=>d[i]);
2
+ import{hH as Dt,lZ as Bt,js as Nt,l_ as pn,l$ as Ft,m0 as dn,m1 as mn,N as gn,m2 as yn,m3 as wn,m4 as bn,_ as U,m5 as Mn,hG as _n,m6 as kn,m7 as An,m8 as Sn,m9 as ft,ma as En,f_ as tt,gz as Tn,g0 as nt,gA as xn,fA as V,gt as ct,gB as vn,cB as Ce,mb as On,go as rt,mc as Ln,gp as Gt,gC as Pn,md as $n,me as Rn,mf as Cn,mg as In,mh as jn,mi as Dn,mj as Bn,mk as Ht,ml as Nn,mm as Fn,mn as Gn,br as Hn,bB as zn,mo as Wn,mp as fe,mq as qn,mr as Un,ms as Kn,mt as Vn,mu as Jn,mv as ce,mw as Ie,mx as ht,my as Yn,mz as Xn,bx as Zn,mA as Qn,mB as ut,mC as er,mD as tr,gr as nr,cK as rr,fn as sr,gq as zt,c0 as or,g$ as ar,eb as oe,iq as ir,eQ as lr,fl as fr,b_ as we,ec as je,ed as pt,mE as cr,mF as W,hF as hr,kV as ur}from"./titleFrameBudget-Cml-MO53.js";import{W as pr,X as dr,r as mr}from"./rigTrack-CUt4O67J.js";import{t as le,bU as gr,az as yr,s as wr}from"./api-QBI5GJTZ.js";function De(e){if(typeof e!="string")return null;const t=(o,a=!1)=>o.split(",").map(i=>i.trim()).filter(Boolean).map(i=>{const[l,f]=i.split(/\s+as\s+/);return a?f?`${f}:${l}`:l:f?`${l}:${f}`:l}).join(",");let n=e.replace(/^import\s*\{([^}]*)\}\s*from\s*['"]three['"];?/m,(o,a)=>`const {${t(a)}}=THREE;`);if(n=n.replace(/^import\s*\{([^}]*)\}\s*from\s*['"]\.\.\/utils\/([A-Za-z]+)\.js['"];?/mg,(o,a,i)=>`const {${t(a)}}=__deps.${i};`),/^\s*import\s/m.test(n))return null;const r=/^export\s*\{([^}]*)\};?[ \t]*$/m,s=r.exec(n);return!s||(n=n.replace(r,`return {${t(s[1],!0)}};`),/^export\s/m.test(n))?null:'"use strict";'+n}const Wt=`async(THREE,items,LOADERS,flip)=>{
3
3
  const out=new Map()
4
4
  const bmp=(data)=>createImageBitmap(new Blob([data]),flip?{imageOrientation:'flipY',premultiplyAlpha:'none'}:{})
5
5
  for(const it of items){
@@ -57,7 +57,7 @@ import{hH as Dt,lS as Bt,js as Nt,lT as pn,lU as Ft,lV as dn,lW as mn,N as gn,lX
57
57
  if(obj.userData.__clip!==clip){mixer.stopAllAction();action.play();obj.userData.__clip=clip}
58
58
  const d=clip.duration||1,s=(t||0)*(o.speed??1);action.time=o.loop===false?Math.min(d,Math.max(0,s)):((s%d)+d)%d;mixer.update(0);return true}
59
59
  return {asset,texture,sprite,sequence,lut,play}
60
- }`,_r=e=>typeof e=="string"?{uri:e}:e&&typeof e=="object"?e:null,N=1024*1024,B=Object.freeze({packageBytes:200*N,inflatedBytes:400*N,files:400,glbBytes:20*N,triangles:3e5,vertices:2e6,glbImages:16,glbJsonBytes:4*N,nodes:1e4,depth:64,imagePx:4096,textureBytes:8*N,spriteFrames:256,seqFrames:240,seqFrameW:1920,seqFrameH:1080,seqBytes:40*N,lutBytes:12*N,lutSize:65,itemBytes:60*N,itemPixelBytes:256*N,uses:24}),kr=Object.freeze(["model","texture","sprite","sequence","lut"]),Sr=Object.freeze(["KHR_materials_emissive_strength","KHR_materials_transmission","KHR_materials_clearcoat","KHR_materials_ior","KHR_materials_specular","KHR_materials_sheen","KHR_materials_volume","KHR_materials_unlit","KHR_materials_iridescence","KHR_materials_anisotropy","KHR_materials_dispersion","KHR_texture_transform","KHR_mesh_quantization","EXT_texture_webp","KHR_lights_punctual"]),Ar=["KHR_draco_mesh_compression","EXT_meshopt_compression","KHR_meshopt_compression","KHR_texture_basisu","EXT_mesh_gpu_instancing"],Er=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/,Tr=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}\.(png|webp)$/i,xr={glb:"model",png:"texture",webp:"texture",jpg:"texture",jpeg:"texture",cube:"lut"},F=e=>!!e&&typeof e=="object"&&!Array.isArray(e),j=(e,t=[],n="")=>Object.assign(new Error(n||e),{code:e,args:t.map(String),plugin:!0}),x=(e,t,n=[])=>j("asset",[e,t,...n],`assets/${e}: ${t}${n.length?` (${n.join(", ")})`:""}`),qt=e=>String(e).split(".").pop().toLowerCase();function vr(e){return e.length>24&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e[4]===13&&e[5]===10&&e[6]===26&&e[7]===10?"image/png":e.length>3&&e[0]===255&&e[1]===216&&e[2]===255?"image/jpeg":e.length>16&&e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80?"image/webp":null}const Be=(e,t)=>e[t]<<8|e[t+1],dt=(e,t)=>(e[t]<<24>>>0)+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];function Ut(e){const t=vr(e);if(!t)return null;if(t==="image/png")return String.fromCharCode(e[12],e[13],e[14],e[15])!=="IHDR"?null:{type:t,width:dt(e,16),height:dt(e,20)};if(t==="image/jpeg"){let r=2;for(;r+9<e.length;){if(e[r]!==255){r++;continue}const s=e[r+1];if(s===255){r++;continue}if(s===216||s===1||s>=208&&s<=215){r+=2;continue}const o=Be(e,r+2);if(o<2)return null;if(s>=192&&s<=207&&s!==196&&s!==200&&s!==204)return{type:t,width:Be(e,r+7),height:Be(e,r+5)};r+=2+o}return null}const n=String.fromCharCode(e[12],e[13],e[14],e[15]);if(n==="VP8 "&&e.length>=30)return e[23]!==157||e[24]!==1||e[25]!==42?null:{type:t,width:(e[26]|e[27]<<8)&16383,height:(e[28]|e[29]<<8)&16383};if(n==="VP8L"&&e.length>=25){if(e[20]!==47)return null;const r=e[21]|e[22]<<8|e[23]<<16|e[24]<<24;return{type:t,width:(r&16383)+1,height:(r>>>14&16383)+1}}return n==="VP8X"&&e.length>=30?{type:t,width:1+(e[24]|e[25]<<8|e[26]<<16),height:1+(e[27]|e[28]<<8|e[29]<<16)}:null}const Or={png:"image/png",webp:"image/webp",jpg:"image/jpeg",jpeg:"image/jpeg"};function mt(e,t,{maxW:n=B.imagePx,maxH:r=B.imagePx,maxBytes:s=B.textureBytes}={}){if(t.length>s)throw x(e,"too_large",[Math.round(s/N)]);const o=Ut(t),a=Or[qt(e)];if(!o||!a)throw x(e,"not_image");if(o.type!==a)throw x(e,"magic",[o.type.slice(6)]);if(!(o.width>0&&o.height>0))throw x(e,"not_image");if(o.width>n||o.height>r)throw x(e,"image_size",[`${o.width}×${o.height}`,`${n}×${r}`]);return o}const K=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0,gt={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},yt={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};function Ye(e,t=0){if(t>40)return"deep";if(Array.isArray(e)){for(const n of e){const r=n&&typeof n=="object"?Ye(n,t+1):null;if(r)return r}return null}if(!F(e))return null;for(const[n,r]of Object.entries(e)){if(n==="__proto__"||n==="constructor"||n==="prototype")return"key";if(n==="uri")return typeof r=="string"?r.slice(0,60):"uri";if(r&&typeof r=="object"){const s=Ye(r,t+1);if(s)return s}}return null}const q=(e,t)=>Number.isInteger(e)&&e>=0&&e<t;function Lr(e,t="model.glb"){const n=B;if(!(e instanceof Uint8Array))throw x(t,"glb_header");if(e.length>n.glbBytes)throw x(t,"too_large",[Math.round(n.glbBytes/N)]);if(e.length<20||K(e,0)!==1179937895)throw x(t,"glb_header");if(K(e,4)!==2)throw x(t,"glb_version",[K(e,4)]);if(K(e,8)!==e.length)throw x(t,"glb_length");const r=K(e,12);if(K(e,16)!==1313821514||r<2||20+r>e.length)throw x(t,"glb_header");if(r>n.glbJsonBytes)throw x(t,"glb_json_large");let s;try{s=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e.subarray(20,20+r)))}catch{throw x(t,"glb_json")}if(!F(s))throw x(t,"glb_json");let o=0,a=0;const i=20+r+(4-r%4)%4;if(i+8<=e.length){const m=K(e,i);if(K(e,i+4)!==5130562||i+8+m>e.length)throw x(t,"glb_header");o=i+8,a=m}const l=Ye(s);if(l)throw x(t,"glb_uri",[l]);const f=Array.isArray(s.extensionsUsed)?s.extensionsUsed.map(String):[],h=Array.isArray(s.extensionsRequired)?s.extensionsRequired.map(String):[],c=[...f,...h].find(m=>Ar.includes(m));if(c)throw x(t,"glb_compressed",[c]);const u=h.find(m=>!Sr.includes(m));if(u)throw x(t,"glb_extension",[u.slice(0,60)]);const p=m=>{const b=s[m];if(b===void 0)return[];if(!Array.isArray(b))throw x(t,"glb_json");return b},k=p("buffers"),E=p("bufferViews"),d=p("accessors"),S=p("meshes"),w=p("nodes"),g=p("images"),_=p("textures"),M=p("scenes"),y=p("animations");if(k.length>1||k.length&&(!F(k[0])||!Number.isInteger(k[0].byteLength)||k[0].byteLength>a))throw x(t,"glb_buffers");if(w.length>n.nodes)throw x(t,"glb_nodes",[n.nodes]);const A=k.length?k[0].byteLength:0;E.forEach((m,b)=>{const O=m?.byteOffset??0,$=m?.byteLength;if(!F(m)||m.buffer!==0||!Number.isInteger(O)||O<0||!Number.isInteger($)||$<1||O+$>A)throw x(t,"glb_range",[`bufferViews[${b}]`]);if(m.byteStride!==void 0&&!(Number.isInteger(m.byteStride)&&m.byteStride>=4&&m.byteStride<=252))throw x(t,"glb_range",[`bufferViews[${b}]`])}),d.forEach((m,b)=>{if(!F(m)||!gt[m.componentType]||!yt[m.type]||!Number.isInteger(m.count)||m.count<1||m.count>5e6)throw x(t,"glb_range",[`accessors[${b}]`]);if(m.sparse!==void 0)throw x(t,"glb_sparse");if(m.bufferView===void 0)return;if(!q(m.bufferView,E.length))throw x(t,"glb_range",[`accessors[${b}]`]);const O=E[m.bufferView],$=gt[m.componentType]*yt[m.type],D=O.byteStride||$,H=m.byteOffset??0;if(!Number.isInteger(H)||H<0||H+(m.count-1)*D+$>O.byteLength)throw x(t,"glb_range",[`accessors[${b}]`])});const P=S.map((m,b)=>{if(!F(m)||!Array.isArray(m.primitives)||!m.primitives.length)throw x(t,"glb_range",[`meshes[${b}]`]);let O=0,$=0;for(const D of m.primitives){if(!F(D)||!F(D.attributes)||!q(D.attributes.POSITION,d.length))throw x(t,"glb_range",[`meshes[${b}]`]);for(const it of Object.values(D.attributes))if(!q(it,d.length))throw x(t,"glb_range",[`meshes[${b}]`]);if(D.indices!==void 0&&!q(D.indices,d.length))throw x(t,"glb_range",[`meshes[${b}]`]);if(D.material!==void 0&&!(Number.isInteger(D.material)&&D.material>=0))throw x(t,"glb_range",[`meshes[${b}]`]);const H=D.indices!==void 0?d[D.indices].count:d[D.attributes.POSITION].count,X=D.mode??4;$+=d[D.attributes.POSITION].count,O+=X===4?Math.floor(H/3):X===5||X===6?Math.max(0,H-2):0}return{tris:O,verts:$}});let L=0,T=0,R=0;const C=(m,b,O)=>{if(!q(m,w.length))throw x(t,"glb_range",["nodes"]);if(b>n.depth||O.has(m))throw x(t,"glb_nodes",[n.depth]);if(++R>n.nodes*4)throw x(t,"glb_nodes",[n.nodes]);const $=w[m];if(!F($))throw x(t,"glb_range",["nodes"]);if($.mesh!==void 0){if(!q($.mesh,S.length))throw x(t,"glb_range",["nodes"]);L+=P[$.mesh].tris,T+=P[$.mesh].verts}if($.children!==void 0){if(!Array.isArray($.children))throw x(t,"glb_range",["nodes"]);O.add(m);for(const D of $.children)C(D,b+1,O);O.delete(m)}};if(M.length)for(const m of M){if(!F(m))throw x(t,"glb_json");for(const b of m.nodes??[])C(b,0,new Set)}else P.forEach(m=>{L+=m.tris,T+=m.verts});if(L>n.triangles)throw x(t,"glb_triangles",[L,n.triangles]);if(T>n.vertices)throw x(t,"glb_vertices",[T,n.vertices]);if(g.length>n.glbImages)throw x(t,"glb_images",[g.length,n.glbImages]);const I=g.map((m,b)=>{if(!F(m)||!q(m.bufferView,E.length)||!["image/png","image/jpeg","image/webp"].includes(m.mimeType))throw x(t,"glb_image",[b]);const O=E[m.bufferView],$=o+(O.byteOffset??0),D=e.subarray($,$+O.byteLength),H=Ut(D);if(!H||H.type!==m.mimeType)throw x(t,"glb_image",[b]);if(H.width>n.imagePx||H.height>n.imagePx)throw x(t,"image_size",[`${H.width}×${H.height}`,`${n.imagePx}×${n.imagePx}`]);return H});_.forEach((m,b)=>{if(!F(m))throw x(t,"glb_range",[`textures[${b}]`]);const O=m.extensions?.EXT_texture_webp?.source??m.source;if(O!==void 0&&!q(O,g.length))throw x(t,"glb_range",[`textures[${b}]`])});const v=y.map((m,b)=>{if(!F(m)||!Array.isArray(m.channels)||!Array.isArray(m.samplers))throw x(t,"glb_range",[`animations[${b}]`]);for(const O of m.samplers)if(!F(O)||!q(O.input,d.length)||!q(O.output,d.length))throw x(t,"glb_range",[`animations[${b}]`]);for(const O of m.channels)if(!F(O)||!q(O.sampler,m.samplers.length)||!F(O.target)||O.target.node!==void 0&&!q(O.target.node,w.length))throw x(t,"glb_range",[`animations[${b}]`]);return typeof m.name=="string"&&m.name?m.name.slice(0,60):`Animation ${b+1}`});return{bytes:e.length,triangles:L,vertices:T,meshes:S.length,nodes:w.length,images:I,animations:v,pixelBytes:I.reduce((m,b)=>m+b.width*b.height*4,0)}}const Kt=[67,88,83,81];function Pr(e){const t=new Uint8Array(8+e.length*4),n=new DataView(t.buffer);t.set(Kt,0),n.setUint32(4,e.length,!0),e.forEach((o,a)=>n.setUint32(8+a*4,o.length,!0));const r=new Uint8Array(t.length+e.reduce((o,a)=>o+a.length,0));r.set(t,0);let s=t.length;for(const o of e)r.set(o,s),s+=o.length;return r}function $r(e){if(!(e instanceof Uint8Array)||e.length<8||Kt.some((s,o)=>e[o]!==s))throw j("asset",["sequence","seq_format"]);const t=K(e,4);if(t<1||t>B.seqFrames||8+t*4>e.length)throw j("asset",["sequence","seq_format"]);const n=[];let r=8+t*4;for(let s=0;s<t;s++){const o=K(e,8+s*4);if(o<1||r+o>e.length)throw j("asset",["sequence","seq_format"]);n.push(e.subarray(r,r+o)),r+=o}if(r!==e.length)throw j("asset",["sequence","seq_format"]);return n}function Rr(e){if(e===void 0)return[];if(!Array.isArray(e)||e.length>B.files)throw j("manifest_field",["assets","length"],`manifest.assets: up to ${B.files} entries`);const t=new Set;return e.map((n,r)=>{const s=`assets[${r}]`;if(typeof n=="string"&&(n={name:n}),!F(n)||Object.keys(n).some(f=>!["name","kind","sprite","fps"].includes(f)))throw j("unknown_key",[s]);if(typeof n.name!="string"||!Er.test(n.name))throw j("manifest_field",[`${s}.name`,"format"],`${s}.name: a file name under assets/ like "jet.glb" (a-z 0-9 . _ -)`);const o=t.has(n.name.toLowerCase());if(t.add(n.name.toLowerCase()),o)throw j("manifest_field",[`${s}.name`,"duplicate"]);const a=xr[qt(n.name)];let i=n.kind??a;if(n.kind!==void 0&&!kr.includes(n.kind))throw j("manifest_field",[`${s}.kind`,"format"]);if(i==="sequence"){if(n.name.includes("."))throw j("manifest_field",[`${s}.name`,"format"],`${s}: a sequence is a folder name (no extension)`)}else if(a){if(i==="sprite"?a!=="texture":i!==a)throw j("manifest_field",[`${s}.kind`,"format"])}else throw j("manifest_field",[`${s}.name`,"format"],`${s}.name: .glb · .png · .webp · .jpg · .cube`);const l={name:n.name,kind:i};if(i==="sprite"){const f=n.sprite;if(!F(f)||Object.keys(f).some(p=>!["cols","rows","frames","fps"].includes(p)))throw j("manifest_field",[`${s}.sprite`,"type"]);const h=(p,k,E)=>Number.isInteger(p)&&p>=k&&p<=E;if(!h(f.cols,1,64)||!h(f.rows,1,64)||f.cols*f.rows>B.spriteFrames)throw j("manifest_field",[`${s}.sprite`,"range"]);const c=f.frames??f.cols*f.rows;if(!h(c,1,f.cols*f.rows))throw j("manifest_field",[`${s}.sprite.frames`,"range"]);const u=f.fps??24;if(!h(u,1,60))throw j("manifest_field",[`${s}.sprite.fps`,"range"]);l.sprite={cols:f.cols,rows:f.rows,frames:c,fps:u}}else if(n.sprite!==void 0)throw j("unknown_key",[`${s}.sprite`]);if(i==="sequence"){const f=n.fps??24;if(!(Number.isInteger(f)&&f>=1&&f<=60))throw j("manifest_field",[`${s}.fps`,"range"]);l.fps=f}else if(n.fps!==void 0)throw j("unknown_key",[`${s}.fps`]);return l})}function ho(e,t){const n=new Map(e.map(s=>[s.name,[]])),r=new Map(e.map(s=>[s.name,s]));for(const s of t){if(!s.startsWith("assets/"))continue;const o=s.slice(7),a=o.split("/");if(a.length===1&&r.has(a[0])&&r.get(a[0]).kind!=="sequence"){n.get(a[0]).push(s);continue}if(a.length===2&&r.get(a[0])?.kind==="sequence"&&Tr.test(a[1])){n.get(a[0]).push(s);continue}throw j("extra_file",[s.slice(0,80)])}for(const[s,o]of n){if(!o.length)throw j("no_entry",[`assets/${s}`]);o.sort()}return n}function uo(e,t,n){const{name:r,kind:s}=e;if(s==="model"){const h=n(t[0]);return{stored:h,facts:Lr(h,r)}}if(s==="texture"||s==="sprite"){const h=n(t[0]),c=mt(r,h);return{stored:h,facts:{bytes:h.length,width:c.width,height:c.height,type:c.type,pixelBytes:c.width*c.height*4*1}}}if(s==="lut"){const h=n(t[0]);if(h.length>B.lutBytes)throw x(r,"too_large",[Math.round(B.lutBytes/N)]);let c;try{c=new TextDecoder("utf-8",{fatal:!0}).decode(h)}catch{throw x(r,"lut")}let u;try{u=Dt(c)}catch(p){throw x(r,"lut",[String(p.message).slice(0,80)])}if(u.size>B.lutSize)throw x(r,"lut_size",[u.size,B.lutSize]);return{stored:h,facts:{bytes:h.length,size:u.size,pixelBytes:0}}}if(t.length>B.seqFrames)throw x(r,"seq_frames",[t.length,B.seqFrames]);let o=0,a=0,i=0;const l=[];for(const h of t){const c=n(h);if(i+=c.length,i>B.seqBytes)throw x(r,"too_large",[Math.round(B.seqBytes/N)]);const u=mt(`${r}/${h.split("/").pop()}`,c,{maxW:B.seqFrameW,maxH:B.seqFrameH});if(l.length&&(u.width!==o||u.height!==a))throw x(r,"seq_size");o=u.width,a=u.height,l.push(c)}const f=Pr(l);return{stored:f,facts:{bytes:f.length,frames:l.length,width:o,height:a,pixelBytes:o*a*4*l.length}}}function po(e,t,n){if(e===void 0)return[];if(!Array.isArray(e)||e.length>B.uses||e.some(o=>typeof o!="string"))throw j("manifest_field",["uses","length"],`${n}: uses lists up to ${B.uses} asset names`);if(new Set(e).size!==e.length)throw j("manifest_field",["uses","duplicate"]);const r=new Map(t.map(o=>[o.name,o]));for(const o of e)if(!r.has(o))throw j("use_asset",[n,o.slice(0,64)],`${n}: uses "${o.slice(0,64)}" but the pack has no such asset`);const s=e.map(o=>r.get(o)).filter(o=>o.bytes!==void 0);if(s.length===e.length){const o=s.reduce((i,l)=>i+l.bytes,0),a=s.reduce((i,l)=>i+(l.pixelBytes||0),0);if(o>B.itemBytes)throw j("item_budget",[n,Math.round(o/N),Math.round(B.itemBytes/N)],`${n}: its assets are ${Math.round(o/N)} MB (max ${Math.round(B.itemBytes/N)} MB per item)`);if(a>B.itemPixelBytes)throw j("item_pixels",[n,Math.round(a/N),Math.round(B.itemPixelBytes/N)],`${n}: its pictures decode to ${Math.round(a/N)} MB (max ${Math.round(B.itemPixelBytes/N)} MB per item)`)}return[...e]}function mo(e){const[t]=Rr([{name:e?.name,kind:e?.kind,...e?.sprite?{sprite:e.sprite}:{},...e?.fps!==void 0?{fps:e.fps}:{}}]);if(!Number.isInteger(e.bytes)||e.bytes<1||!/^[a-f0-9]{64}$/.test(String(e.sha256))||!(Number.isFinite(e.pixelBytes)&&e.pixelBytes>=0))throw j("bad_package");const n=F(e.facts)?e.facts:{};return{...t,bytes:e.bytes,sha256:e.sha256,pixelBytes:e.pixelBytes,facts:n}}const Vt=4e3,Jt=9e4,Cr=2e4,Yt="WEBGL_UNAVAILABLE",Ir=`const SPACE_PROJECT=${pn.toString()};${Bt}self.__MOTION_STICKERS=new Map();let ASSETS=new Map();const DECODE=${Wt};const M=Object.freeze({...${Nt},...(${br})({get:n=>ASSETS.get(n)})});const FONTS=Object.freeze(${JSON.stringify(Ft)});let render=null,key=null,canvas=null,ctx=null,ready=Promise.resolve()
60
+ }`,_r=e=>typeof e=="string"?{uri:e}:e&&typeof e=="object"?e:null,N=1024*1024,B=Object.freeze({packageBytes:200*N,inflatedBytes:400*N,files:400,glbBytes:20*N,triangles:3e5,vertices:2e6,glbImages:16,glbJsonBytes:4*N,nodes:1e4,depth:64,imagePx:4096,textureBytes:8*N,spriteFrames:256,seqFrames:240,seqFrameW:1920,seqFrameH:1080,seqBytes:40*N,lutBytes:12*N,lutSize:65,itemBytes:60*N,itemPixelBytes:256*N,uses:24}),kr=Object.freeze(["model","texture","sprite","sequence","lut"]),Ar=Object.freeze(["KHR_materials_emissive_strength","KHR_materials_transmission","KHR_materials_clearcoat","KHR_materials_ior","KHR_materials_specular","KHR_materials_sheen","KHR_materials_volume","KHR_materials_unlit","KHR_materials_iridescence","KHR_materials_anisotropy","KHR_materials_dispersion","KHR_texture_transform","KHR_mesh_quantization","EXT_texture_webp","KHR_lights_punctual"]),Sr=["KHR_draco_mesh_compression","EXT_meshopt_compression","KHR_meshopt_compression","KHR_texture_basisu","EXT_mesh_gpu_instancing"],Er=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/,Tr=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}\.(png|webp)$/i,xr={glb:"model",png:"texture",webp:"texture",jpg:"texture",jpeg:"texture",cube:"lut"},F=e=>!!e&&typeof e=="object"&&!Array.isArray(e),j=(e,t=[],n="")=>Object.assign(new Error(n||e),{code:e,args:t.map(String),plugin:!0}),x=(e,t,n=[])=>j("asset",[e,t,...n],`assets/${e}: ${t}${n.length?` (${n.join(", ")})`:""}`),qt=e=>String(e).split(".").pop().toLowerCase();function vr(e){return e.length>24&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e[4]===13&&e[5]===10&&e[6]===26&&e[7]===10?"image/png":e.length>3&&e[0]===255&&e[1]===216&&e[2]===255?"image/jpeg":e.length>16&&e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80?"image/webp":null}const Be=(e,t)=>e[t]<<8|e[t+1],dt=(e,t)=>(e[t]<<24>>>0)+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];function Ut(e){const t=vr(e);if(!t)return null;if(t==="image/png")return String.fromCharCode(e[12],e[13],e[14],e[15])!=="IHDR"?null:{type:t,width:dt(e,16),height:dt(e,20)};if(t==="image/jpeg"){let r=2;for(;r+9<e.length;){if(e[r]!==255){r++;continue}const s=e[r+1];if(s===255){r++;continue}if(s===216||s===1||s>=208&&s<=215){r+=2;continue}const o=Be(e,r+2);if(o<2)return null;if(s>=192&&s<=207&&s!==196&&s!==200&&s!==204)return{type:t,width:Be(e,r+7),height:Be(e,r+5)};r+=2+o}return null}const n=String.fromCharCode(e[12],e[13],e[14],e[15]);if(n==="VP8 "&&e.length>=30)return e[23]!==157||e[24]!==1||e[25]!==42?null:{type:t,width:(e[26]|e[27]<<8)&16383,height:(e[28]|e[29]<<8)&16383};if(n==="VP8L"&&e.length>=25){if(e[20]!==47)return null;const r=e[21]|e[22]<<8|e[23]<<16|e[24]<<24;return{type:t,width:(r&16383)+1,height:(r>>>14&16383)+1}}return n==="VP8X"&&e.length>=30?{type:t,width:1+(e[24]|e[25]<<8|e[26]<<16),height:1+(e[27]|e[28]<<8|e[29]<<16)}:null}const Or={png:"image/png",webp:"image/webp",jpg:"image/jpeg",jpeg:"image/jpeg"};function mt(e,t,{maxW:n=B.imagePx,maxH:r=B.imagePx,maxBytes:s=B.textureBytes}={}){if(t.length>s)throw x(e,"too_large",[Math.round(s/N)]);const o=Ut(t),a=Or[qt(e)];if(!o||!a)throw x(e,"not_image");if(o.type!==a)throw x(e,"magic",[o.type.slice(6)]);if(!(o.width>0&&o.height>0))throw x(e,"not_image");if(o.width>n||o.height>r)throw x(e,"image_size",[`${o.width}×${o.height}`,`${n}×${r}`]);return o}const K=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0,gt={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},yt={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};function Ye(e,t=0){if(t>40)return"deep";if(Array.isArray(e)){for(const n of e){const r=n&&typeof n=="object"?Ye(n,t+1):null;if(r)return r}return null}if(!F(e))return null;for(const[n,r]of Object.entries(e)){if(n==="__proto__"||n==="constructor"||n==="prototype")return"key";if(n==="uri")return typeof r=="string"?r.slice(0,60):"uri";if(r&&typeof r=="object"){const s=Ye(r,t+1);if(s)return s}}return null}const q=(e,t)=>Number.isInteger(e)&&e>=0&&e<t;function Lr(e,t="model.glb"){const n=B;if(!(e instanceof Uint8Array))throw x(t,"glb_header");if(e.length>n.glbBytes)throw x(t,"too_large",[Math.round(n.glbBytes/N)]);if(e.length<20||K(e,0)!==1179937895)throw x(t,"glb_header");if(K(e,4)!==2)throw x(t,"glb_version",[K(e,4)]);if(K(e,8)!==e.length)throw x(t,"glb_length");const r=K(e,12);if(K(e,16)!==1313821514||r<2||20+r>e.length)throw x(t,"glb_header");if(r>n.glbJsonBytes)throw x(t,"glb_json_large");let s;try{s=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e.subarray(20,20+r)))}catch{throw x(t,"glb_json")}if(!F(s))throw x(t,"glb_json");let o=0,a=0;const i=20+r+(4-r%4)%4;if(i+8<=e.length){const m=K(e,i);if(K(e,i+4)!==5130562||i+8+m>e.length)throw x(t,"glb_header");o=i+8,a=m}const l=Ye(s);if(l)throw x(t,"glb_uri",[l]);const f=Array.isArray(s.extensionsUsed)?s.extensionsUsed.map(String):[],h=Array.isArray(s.extensionsRequired)?s.extensionsRequired.map(String):[],c=[...f,...h].find(m=>Sr.includes(m));if(c)throw x(t,"glb_compressed",[c]);const u=h.find(m=>!Ar.includes(m));if(u)throw x(t,"glb_extension",[u.slice(0,60)]);const p=m=>{const b=s[m];if(b===void 0)return[];if(!Array.isArray(b))throw x(t,"glb_json");return b},k=p("buffers"),E=p("bufferViews"),d=p("accessors"),A=p("meshes"),w=p("nodes"),g=p("images"),_=p("textures"),M=p("scenes"),y=p("animations");if(k.length>1||k.length&&(!F(k[0])||!Number.isInteger(k[0].byteLength)||k[0].byteLength>a))throw x(t,"glb_buffers");if(w.length>n.nodes)throw x(t,"glb_nodes",[n.nodes]);const S=k.length?k[0].byteLength:0;E.forEach((m,b)=>{const O=m?.byteOffset??0,$=m?.byteLength;if(!F(m)||m.buffer!==0||!Number.isInteger(O)||O<0||!Number.isInteger($)||$<1||O+$>S)throw x(t,"glb_range",[`bufferViews[${b}]`]);if(m.byteStride!==void 0&&!(Number.isInteger(m.byteStride)&&m.byteStride>=4&&m.byteStride<=252))throw x(t,"glb_range",[`bufferViews[${b}]`])}),d.forEach((m,b)=>{if(!F(m)||!gt[m.componentType]||!yt[m.type]||!Number.isInteger(m.count)||m.count<1||m.count>5e6)throw x(t,"glb_range",[`accessors[${b}]`]);if(m.sparse!==void 0)throw x(t,"glb_sparse");if(m.bufferView===void 0)return;if(!q(m.bufferView,E.length))throw x(t,"glb_range",[`accessors[${b}]`]);const O=E[m.bufferView],$=gt[m.componentType]*yt[m.type],D=O.byteStride||$,H=m.byteOffset??0;if(!Number.isInteger(H)||H<0||H+(m.count-1)*D+$>O.byteLength)throw x(t,"glb_range",[`accessors[${b}]`])});const P=A.map((m,b)=>{if(!F(m)||!Array.isArray(m.primitives)||!m.primitives.length)throw x(t,"glb_range",[`meshes[${b}]`]);let O=0,$=0;for(const D of m.primitives){if(!F(D)||!F(D.attributes)||!q(D.attributes.POSITION,d.length))throw x(t,"glb_range",[`meshes[${b}]`]);for(const it of Object.values(D.attributes))if(!q(it,d.length))throw x(t,"glb_range",[`meshes[${b}]`]);if(D.indices!==void 0&&!q(D.indices,d.length))throw x(t,"glb_range",[`meshes[${b}]`]);if(D.material!==void 0&&!(Number.isInteger(D.material)&&D.material>=0))throw x(t,"glb_range",[`meshes[${b}]`]);const H=D.indices!==void 0?d[D.indices].count:d[D.attributes.POSITION].count,X=D.mode??4;$+=d[D.attributes.POSITION].count,O+=X===4?Math.floor(H/3):X===5||X===6?Math.max(0,H-2):0}return{tris:O,verts:$}});let L=0,T=0,R=0;const C=(m,b,O)=>{if(!q(m,w.length))throw x(t,"glb_range",["nodes"]);if(b>n.depth||O.has(m))throw x(t,"glb_nodes",[n.depth]);if(++R>n.nodes*4)throw x(t,"glb_nodes",[n.nodes]);const $=w[m];if(!F($))throw x(t,"glb_range",["nodes"]);if($.mesh!==void 0){if(!q($.mesh,A.length))throw x(t,"glb_range",["nodes"]);L+=P[$.mesh].tris,T+=P[$.mesh].verts}if($.children!==void 0){if(!Array.isArray($.children))throw x(t,"glb_range",["nodes"]);O.add(m);for(const D of $.children)C(D,b+1,O);O.delete(m)}};if(M.length)for(const m of M){if(!F(m))throw x(t,"glb_json");for(const b of m.nodes??[])C(b,0,new Set)}else P.forEach(m=>{L+=m.tris,T+=m.verts});if(L>n.triangles)throw x(t,"glb_triangles",[L,n.triangles]);if(T>n.vertices)throw x(t,"glb_vertices",[T,n.vertices]);if(g.length>n.glbImages)throw x(t,"glb_images",[g.length,n.glbImages]);const I=g.map((m,b)=>{if(!F(m)||!q(m.bufferView,E.length)||!["image/png","image/jpeg","image/webp"].includes(m.mimeType))throw x(t,"glb_image",[b]);const O=E[m.bufferView],$=o+(O.byteOffset??0),D=e.subarray($,$+O.byteLength),H=Ut(D);if(!H||H.type!==m.mimeType)throw x(t,"glb_image",[b]);if(H.width>n.imagePx||H.height>n.imagePx)throw x(t,"image_size",[`${H.width}×${H.height}`,`${n.imagePx}×${n.imagePx}`]);return H});_.forEach((m,b)=>{if(!F(m))throw x(t,"glb_range",[`textures[${b}]`]);const O=m.extensions?.EXT_texture_webp?.source??m.source;if(O!==void 0&&!q(O,g.length))throw x(t,"glb_range",[`textures[${b}]`])});const v=y.map((m,b)=>{if(!F(m)||!Array.isArray(m.channels)||!Array.isArray(m.samplers))throw x(t,"glb_range",[`animations[${b}]`]);for(const O of m.samplers)if(!F(O)||!q(O.input,d.length)||!q(O.output,d.length))throw x(t,"glb_range",[`animations[${b}]`]);for(const O of m.channels)if(!F(O)||!q(O.sampler,m.samplers.length)||!F(O.target)||O.target.node!==void 0&&!q(O.target.node,w.length))throw x(t,"glb_range",[`animations[${b}]`]);return typeof m.name=="string"&&m.name?m.name.slice(0,60):`Animation ${b+1}`});return{bytes:e.length,triangles:L,vertices:T,meshes:A.length,nodes:w.length,images:I,animations:v,pixelBytes:I.reduce((m,b)=>m+b.width*b.height*4,0)}}const Kt=[67,88,83,81];function Pr(e){const t=new Uint8Array(8+e.length*4),n=new DataView(t.buffer);t.set(Kt,0),n.setUint32(4,e.length,!0),e.forEach((o,a)=>n.setUint32(8+a*4,o.length,!0));const r=new Uint8Array(t.length+e.reduce((o,a)=>o+a.length,0));r.set(t,0);let s=t.length;for(const o of e)r.set(o,s),s+=o.length;return r}function $r(e){if(!(e instanceof Uint8Array)||e.length<8||Kt.some((s,o)=>e[o]!==s))throw j("asset",["sequence","seq_format"]);const t=K(e,4);if(t<1||t>B.seqFrames||8+t*4>e.length)throw j("asset",["sequence","seq_format"]);const n=[];let r=8+t*4;for(let s=0;s<t;s++){const o=K(e,8+s*4);if(o<1||r+o>e.length)throw j("asset",["sequence","seq_format"]);n.push(e.subarray(r,r+o)),r+=o}if(r!==e.length)throw j("asset",["sequence","seq_format"]);return n}function Rr(e){if(e===void 0)return[];if(!Array.isArray(e)||e.length>B.files)throw j("manifest_field",["assets","length"],`manifest.assets: up to ${B.files} entries`);const t=new Set;return e.map((n,r)=>{const s=`assets[${r}]`;if(typeof n=="string"&&(n={name:n}),!F(n)||Object.keys(n).some(f=>!["name","kind","sprite","fps"].includes(f)))throw j("unknown_key",[s]);if(typeof n.name!="string"||!Er.test(n.name))throw j("manifest_field",[`${s}.name`,"format"],`${s}.name: a file name under assets/ like "jet.glb" (a-z 0-9 . _ -)`);const o=t.has(n.name.toLowerCase());if(t.add(n.name.toLowerCase()),o)throw j("manifest_field",[`${s}.name`,"duplicate"]);const a=xr[qt(n.name)];let i=n.kind??a;if(n.kind!==void 0&&!kr.includes(n.kind))throw j("manifest_field",[`${s}.kind`,"format"]);if(i==="sequence"){if(n.name.includes("."))throw j("manifest_field",[`${s}.name`,"format"],`${s}: a sequence is a folder name (no extension)`)}else if(a){if(i==="sprite"?a!=="texture":i!==a)throw j("manifest_field",[`${s}.kind`,"format"])}else throw j("manifest_field",[`${s}.name`,"format"],`${s}.name: .glb · .png · .webp · .jpg · .cube`);const l={name:n.name,kind:i};if(i==="sprite"){const f=n.sprite;if(!F(f)||Object.keys(f).some(p=>!["cols","rows","frames","fps"].includes(p)))throw j("manifest_field",[`${s}.sprite`,"type"]);const h=(p,k,E)=>Number.isInteger(p)&&p>=k&&p<=E;if(!h(f.cols,1,64)||!h(f.rows,1,64)||f.cols*f.rows>B.spriteFrames)throw j("manifest_field",[`${s}.sprite`,"range"]);const c=f.frames??f.cols*f.rows;if(!h(c,1,f.cols*f.rows))throw j("manifest_field",[`${s}.sprite.frames`,"range"]);const u=f.fps??24;if(!h(u,1,60))throw j("manifest_field",[`${s}.sprite.fps`,"range"]);l.sprite={cols:f.cols,rows:f.rows,frames:c,fps:u}}else if(n.sprite!==void 0)throw j("unknown_key",[`${s}.sprite`]);if(i==="sequence"){const f=n.fps??24;if(!(Number.isInteger(f)&&f>=1&&f<=60))throw j("manifest_field",[`${s}.fps`,"range"]);l.fps=f}else if(n.fps!==void 0)throw j("unknown_key",[`${s}.fps`]);return l})}function ho(e,t){const n=new Map(e.map(s=>[s.name,[]])),r=new Map(e.map(s=>[s.name,s]));for(const s of t){if(!s.startsWith("assets/"))continue;const o=s.slice(7),a=o.split("/");if(a.length===1&&r.has(a[0])&&r.get(a[0]).kind!=="sequence"){n.get(a[0]).push(s);continue}if(a.length===2&&r.get(a[0])?.kind==="sequence"&&Tr.test(a[1])){n.get(a[0]).push(s);continue}throw j("extra_file",[s.slice(0,80)])}for(const[s,o]of n){if(!o.length)throw j("no_entry",[`assets/${s}`]);o.sort()}return n}function uo(e,t,n){const{name:r,kind:s}=e;if(s==="model"){const h=n(t[0]);return{stored:h,facts:Lr(h,r)}}if(s==="texture"||s==="sprite"){const h=n(t[0]),c=mt(r,h);return{stored:h,facts:{bytes:h.length,width:c.width,height:c.height,type:c.type,pixelBytes:c.width*c.height*4*1}}}if(s==="lut"){const h=n(t[0]);if(h.length>B.lutBytes)throw x(r,"too_large",[Math.round(B.lutBytes/N)]);let c;try{c=new TextDecoder("utf-8",{fatal:!0}).decode(h)}catch{throw x(r,"lut")}let u;try{u=Dt(c)}catch(p){throw x(r,"lut",[String(p.message).slice(0,80)])}if(u.size>B.lutSize)throw x(r,"lut_size",[u.size,B.lutSize]);return{stored:h,facts:{bytes:h.length,size:u.size,pixelBytes:0}}}if(t.length>B.seqFrames)throw x(r,"seq_frames",[t.length,B.seqFrames]);let o=0,a=0,i=0;const l=[];for(const h of t){const c=n(h);if(i+=c.length,i>B.seqBytes)throw x(r,"too_large",[Math.round(B.seqBytes/N)]);const u=mt(`${r}/${h.split("/").pop()}`,c,{maxW:B.seqFrameW,maxH:B.seqFrameH});if(l.length&&(u.width!==o||u.height!==a))throw x(r,"seq_size");o=u.width,a=u.height,l.push(c)}const f=Pr(l);return{stored:f,facts:{bytes:f.length,frames:l.length,width:o,height:a,pixelBytes:o*a*4*l.length}}}function po(e,t,n){if(e===void 0)return[];if(!Array.isArray(e)||e.length>B.uses||e.some(o=>typeof o!="string"))throw j("manifest_field",["uses","length"],`${n}: uses lists up to ${B.uses} asset names`);if(new Set(e).size!==e.length)throw j("manifest_field",["uses","duplicate"]);const r=new Map(t.map(o=>[o.name,o]));for(const o of e)if(!r.has(o))throw j("use_asset",[n,o.slice(0,64)],`${n}: uses "${o.slice(0,64)}" but the pack has no such asset`);const s=e.map(o=>r.get(o)).filter(o=>o.bytes!==void 0);if(s.length===e.length){const o=s.reduce((i,l)=>i+l.bytes,0),a=s.reduce((i,l)=>i+(l.pixelBytes||0),0);if(o>B.itemBytes)throw j("item_budget",[n,Math.round(o/N),Math.round(B.itemBytes/N)],`${n}: its assets are ${Math.round(o/N)} MB (max ${Math.round(B.itemBytes/N)} MB per item)`);if(a>B.itemPixelBytes)throw j("item_pixels",[n,Math.round(a/N),Math.round(B.itemPixelBytes/N)],`${n}: its pictures decode to ${Math.round(a/N)} MB (max ${Math.round(B.itemPixelBytes/N)} MB per item)`)}return[...e]}function mo(e){const[t]=Rr([{name:e?.name,kind:e?.kind,...e?.sprite?{sprite:e.sprite}:{},...e?.fps!==void 0?{fps:e.fps}:{}}]);if(!Number.isInteger(e.bytes)||e.bytes<1||!/^[a-f0-9]{64}$/.test(String(e.sha256))||!(Number.isFinite(e.pixelBytes)&&e.pixelBytes>=0))throw j("bad_package");const n=F(e.facts)?e.facts:{};return{...t,bytes:e.bytes,sha256:e.sha256,pixelBytes:e.pixelBytes,facts:n}}const Vt=4e3,Jt=9e4,Cr=2e4,Yt="WEBGL_UNAVAILABLE",Ir=`const SPACE_PROJECT=${pn.toString()};${Bt}self.__MOTION_STICKERS=new Map();let ASSETS=new Map();const DECODE=${Wt};const M=Object.freeze({...${Nt},...(${br})({get:n=>ASSETS.get(n)})});const FONTS=Object.freeze(${JSON.stringify(Ft)});let render=null,key=null,canvas=null,ctx=null,ready=Promise.resolve()
61
61
  self.onmessage=async e=>{const m=e.data
62
62
  if(m.type==='fonts'){ready=Promise.all(m.fonts.map(async f=>{try{const ff=new FontFace(f.family,f.data,{weight:f.weight,style:f.style});await ff.load();self.fonts.add(ff)}catch(x){}}));return}
63
63
  if(m.type==='stickers'){const prev=ready;ready=prev.then(()=>Promise.all(m.items.map(async s=>{try{if(!self.__MOTION_STICKERS.has(s.id))self.__MOTION_STICKERS.set(s.id,await createImageBitmap(new Blob([s.data],{type:'image/webp'})))}catch(x){}})));return}
@@ -151,8 +151,8 @@ onmessage=e=>{if(e.source!==parent)return;const m=e.data
151
151
  const timer=setTimeout(()=>kill(m.layer,'Motion code took longer than '+ms/1000+'s for one frame (endless loop?)'),ms)
152
152
  inflight.set(m.req,{layer:m.layer,timer});x.w.postMessage(m)}
153
153
  parent.postMessage({type:'boot'},'*')
154
- <\/script>`;let G=null,ee=null,Br=0;const Ae=new Map,Ee=new Map;function Nr(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)+":"+e.length}let te=null;function Fr(){return te||(te=Promise.all(wn.map(async t=>{const n=await fetch(bn+t.file);if(!n.ok)throw Error(t.file);return{family:t.family,weight:t.weight,style:t.style,data:await n.arrayBuffer()}})).catch(()=>(te=null,[])),te)}let Ne=null,be=null;function Gr(){return Ne??=Promise.all([U(()=>import("./three-D7Ssject.js"),[]),U(()=>import("./RoomEnvironment-grxZ6k9f.js"),[])]).then(([e,t])=>({src:e.default,room:Mn(t.default)})).catch(e=>{throw Ne=null,e}),Ne}function Hr(){return be??=Gr().then(e=>{G?.contentWindow?.postMessage({type:"three",src:e.src,room:e.room},"*")}).catch(e=>{throw be=null,e}),be}let Fe=null,Me=null;function zr(){return Fe??=Promise.all([U(()=>import("./opentype-D4-4HGq7.js"),[]),...Object.entries(kn).map(async([e,t])=>{const n=await fetch(t);if(!n.ok)throw Error(`Font ${n.status}`);return{key:e,data:await n.arrayBuffer()}})]).then(([e,...t])=>({src:e.default,fonts:t})).catch(e=>{throw Fe=null,e}),Fe}function Wr(){return Me??=zr().then(e=>{G?.contentWindow?.postMessage({type:"glyphs",src:e.src,fonts:e.fonts.map(t=>({key:t.key,data:t.data.slice(0)}))},"*")}).catch(e=>{throw Me=null,e}),Me}const Ge=new Map;let _e=new Map;function qr(e){return Promise.all(e.map(t=>{let n=_e.get(t);if(!n){let r=Ge.get(t);r||(r=fetch(dr(t)).then(s=>s.ok?s.arrayBuffer():null).catch(()=>null),Ge.set(t,r)),n=r.then(s=>{if(!s){Ge.delete(t),_e.delete(t);return}G?.contentWindow?.postMessage({type:"stickers",items:[{id:t,data:s.slice(0)}]},"*")}),_e.set(t,n)}return n}))}let He=null,ke=null;function Ur(){return He??=Promise.all([U(()=>import("./GLTFLoader-DYtnVu-I.js"),[]),U(()=>import("./BufferGeometryUtils-_ZXHoOh1.js"),[]),U(()=>import("./SkeletonUtils-CfWUgbiL.js"),[])]).then(([e,t,n])=>{const r=De(e.default),s=De(t.default),o=De(n.default);if(!r||!s||!o)throw Error("GLTFLoader shape changed");return{gltf:r,bgu:s,skel:o}}).catch(e=>{throw He=null,e}),He}function Kr(){return ke??=Ur().then(e=>{G?.contentWindow?.postMessage({type:"gltf",...e},"*")}).catch(e=>{throw ke=null,e}),ke}const Te=new Map,J=new Map;function go(e,t){const n=t.slice().buffer;Te.set(e,n),J.delete(`local:${e}`)}function yo(e){for(const t of[...Te.keys()])t.startsWith(e)&&(Te.delete(t),J.delete(`local:${t}`))}let ne=null;function Vr(e){if(!ne){const t={uris:new Set,run:Promise.resolve({})};t.run=new Promise(n=>setTimeout(n,0)).then(()=>(ne=null,gr([...t.uris]))),ne=t}return ne.uris.add(e),ne.run.then(t=>{const n=t[e];if(!n)throw Error(le("Không tải được tài nguyên của lớp plug-in ({0}).",[e.split("/").pop()||"?"]));return n})}function Jr(e){let t=J.get(e);return t||(t=e.startsWith("local:")?Promise.resolve().then(()=>{const n=Te.get(e.slice(6));if(!n)throw Error("local asset missing");return n}):Vr(e).then(n=>fetch(n)).then(n=>{if(!n.ok)throw Error(le("Không tải được tài nguyên của lớp plug-in ({0}).",[e.split("/").pop()||"?"]));return n.arrayBuffer()}),J.set(e,t),t.catch(()=>J.delete(e)),J.size>64&&J.delete(J.keys().next().value)),t}async function Yr(e,t){const n=_r(t),r=await Jr(n.uri),s=new Uint8Array(r),o={...n.grid?{grid:n.grid}:{},...n.fps?{fps:n.fps}:{}};if(s[0]===103&&s[1]===108&&s[2]===84&&s[3]===70)return{name:e,kind:"model",data:r.slice(0)};if(s[0]===67&&s[1]===88&&s[2]===83&&s[3]===81)return{name:e,kind:"sequence",frames:$r(s).map(a=>a.slice().buffer),...o};if(/\.cube$/i.test(e)||/\.cube$/i.test(n.uri)){const a=_n(Dt(new TextDecoder().decode(s)));return{name:e,kind:"lut",size:a.size,data:a.data.buffer.slice(0)}}return{name:e,kind:"image",data:r.slice(0),...o}}const xe=new Map;async function Xr(e,t,n){const r=t.assets;if(!r||!Object.keys(r).length)return;const s=JSON.stringify(r);if(xe.get(e)===s)return;n&&await Kr().catch(()=>{throw Error(le("Không tải được bộ đọc mô hình 3D — kiểm tra mạng rồi thử lại."))});const a=(await Promise.all(Object.entries(r).map(([i,l])=>Yr(i,l)))).map(i=>i.kind==="lut"?{...i,data:new Float32Array(i.data)}:i);G?.contentWindow?.postMessage({type:"assets",layer:e,items:a},"*"),xe.set(e,s)}function Zr(){if(ee&&G?.isConnected)return ee;G?.remove(),Ee.clear(),ae.clear(),_e=new Map,be=null,Me=null,ke=null,xe.clear();const e=document.createElement("iframe");return G=e,e.setAttribute("sandbox","allow-scripts"),e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e.title="motion-sandbox",e.style.cssText="position:fixed;width:1px;height:1px;left:-10px;top:-10px;border:0;opacity:0;pointer-events:none",e.srcdoc=Dr,ee=new Promise((t,n)=>{const r=window.setTimeout(()=>{window.removeEventListener("message",s),G===e&&(G.remove(),G=null,ee=null),n(Error("Motion sandbox did not start"))},8e3),s=o=>{o.source===e.contentWindow&&o.data?.type==="boot"&&(window.clearTimeout(r),window.removeEventListener("message",s),Fr().then(a=>{e.contentWindow?.postMessage({type:"fonts",fonts:a},"*"),t()}))};window.addEventListener("message",s)}),document.body.appendChild(e),ee}window.addEventListener("message",e=>{if(!G||e.source!==G.contentWindow||e.data?.type!=="frame")return;const t=Ae.get(e.data.req);t&&(Ae.delete(e.data.req),window.clearTimeout(t.timer),e.data.bmp?t.resolve(e.data.bmp):t.reject(Error(e.data.error===Yt?le("Trình duyệt không chạy được WebGL nên không vẽ được lớp Motion 3D. Hãy bật tăng tốc phần cứng hoặc dùng Chrome / Edge bản mới."):String(e.data.error||"Motion frame failed"))))});const ae=new Map,ve=new Map,Qr=1500;let Oe=Promise.resolve(),wt=Promise.resolve(),Xe=0,Ze=-1/0;async function es(){for(;;){const e=Oe;if(await e,e!==Oe)continue;const t=Ze+Qr-performance.now();if(!Xe&&t<=0)return;await new Promise(n=>window.setTimeout(n,Math.max(100,t)))}}async function wo(e){await Zr();const t=gn(e.motion.code),n=e.motion.kind==="three",r=Nr(e.motion.assets?t+"\0"+JSON.stringify(e.motion.assets):t);n&&await Hr(),await Xr(e.layer,e.motion,n),n&&yn(t)&&await Wr().catch(()=>{throw Error(le("Không tải được phông chữ cho chữ 3D nổi — kiểm tra mạng rồi thử lại."))});const s=n?[]:pr(t,e.motion.params||{});if(s.length&&await qr(s),!n)return Qe(e,t,r);if(!e.background){Xe++,Ze=performance.now();try{return await bt(e,t,r)}finally{Xe--,Ze=performance.now()}}return bt(e,t,r)}function bt(e,t,n){const r=n+"|"+JSON.stringify(e.motion.params||{})+"|"+e.width+"x"+e.height;if(ae.get(e.layer)===r)return Qe(e,t,n);const s=ve.get(e.layer)??0,o=G,a=()=>{if((ve.get(e.layer)??0)!==s||G!==o)throw Error("dropped");return Qe(e,t,n).then(l=>(G===o&&ae.set(e.layer,r),l),l=>{throw ae.delete(e.layer),l})};if(e.background){const l=wt.then(es).then(a);return wt=l.catch(()=>{}),l}const i=Oe.then(a);return Oe=i.catch(()=>{}),i}function Qe(e,t,n){const r=e.motion.kind==="three",s=++Br,o=Ee.get(e.layer)!==n;return Ee.set(e.layer,n),new Promise((a,i)=>{const l=window.setTimeout(()=>{Ae.delete(s),i(Error("Motion frame timed out"))},(r?Jt:o?Cr:Vt)+2e3);Ae.set(s,{resolve:a,reject:i,timer:l}),G.contentWindow.postMessage({type:"frame",req:s,layer:e.layer,key:n,code:t,params:e.motion.params||{},t:e.t,width:e.width,height:e.height,duration:e.duration,fps:e.fps??30,...r?{kind:"three",surface:e.surface??null}:{space:e.space??null}},"*")})}function bo(e){ve.set(e,(ve.get(e)??0)+1),ae.delete(e),xe.delete(e),G?.contentWindow&&Ee.delete(e)&&G.contentWindow.postMessage({type:"drop",layer:e},"*")}function z(e,t){let n=Math.imul(e^2654435769,2246822507)^Math.imul(t+1,3266489909);return n^=n>>>13,n=Math.imul(n,668265263),n^=n>>>16,(n>>>0)/4294967296}const Xt=(e,t)=>{const n=Math.floor(e),r=e-n,s=r*r*(3-2*r);return(z(n,t)*(1-s)+z(n+1,t)*s)*2-1},Zt=e=>{let t=7;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return t>>>0},he=new Map;function Qt(e,t,n,r){const s=`${e}|${t.toFixed(2)}|${n%7}|${r}`;let o=he.get(s);if(o)return o;he.size>64&&he.clear();const a=128,i=n%7;o=Object.assign(document.createElement("canvas"),{width:a,height:a});const l=o.getContext("2d"),f=l.createImageData(a,a),[h,c,u]=[1,3,5].map(d=>parseInt(e.slice(d,d+2),16)),p=new Float32Array(a*a);for(let d=0;d<a*a;d++)p[d]=z(d,i+9);const k=(d,S)=>p[(S+a)%a*a+(d+a)%a],E=r?1-t*.35:t*.4;for(let d=0;d<a;d++)for(let S=0;S<a;S++){let w=0;for(let M=-1;M<=1;M++)for(let y=-1;y<=1;y++)w+=k(S+y,d+M);const g=Math.min(1,Math.max(0,((w/9-.5)*2.4+.5)*.6+.4*k(S,d))),_=(d*a+S)*4;f.data[_]=h,f.data[_+1]=c,f.data[_+2]=u,f.data[_+3]=g>E?r?Math.round(160+95*(g-E)/(1-E+1e-6)):255:0}return l.putImageData(f,0,0),he.set(s,o),o}function ts(e,t,n,r=0){return e.createPattern(Qt(t,Math.max(0,Math.min(1,n)),r,!1),"repeat")??t}function ue(e,t,n,r=0){return e.createPattern(Qt(t,Math.max(0,Math.min(1,n)),r,!0),"repeat")??t}function en(e,t,n,r,s,o){const a=r.amount??.5,i=r.scale??1,l=r.color??An(s,null),[f,h,c,u]=n,p=(f+c)/2,k=(h+u)/2,E=Math.hypot(c-f,u-h)/2+4,d=(r.angle??0)*Math.PI/180;e.save(),r.type==="riso"&&(e.save(),e.globalAlpha*=.42*a,e.globalCompositeOperation="multiply",e.translate(4*i,-3*i),e.fillStyle=l,e.fill(t),e.restore()),e.clip(t);const S=(w,g,_,M)=>{e.save(),e.globalAlpha*=M,e.strokeStyle=l,e.lineWidth=_,e.lineCap="butt",e.translate(p,k),e.rotate(w),e.beginPath();for(let y=-E;y<=E;y+=g){const A=Xt(y/g,o+5)*g*.12;e.moveTo(-E,y+A),e.lineTo(E,y-A)}e.stroke(),e.restore()};switch(r.type){case"hatch":S(d,13*i,1.4+a*2.6,.35+a*.55);break;case"crosshatch":S(d,12*i,1.2+a*2,.3+a*.5),S(d+Math.PI/2,12*i,1.2+a*2,.25+a*.45);break;case"halftone":case"riso":{const w=(r.type==="riso"?9:12)*i;e.save(),e.fillStyle=l,e.globalAlpha*=r.type==="riso"?.5:.85,e.translate(p,k),e.rotate(d),e.beginPath();for(let g=-E;g<=E;g+=w)for(let _=-E;_<=E;_+=w){const M=.25+.75*Math.max(0,Math.min(1,(_+g)/(2*E)+.5)),y=w*.5*Math.sqrt(a*M);y>.3&&(e.moveTo(_+y,g),e.arc(_,g,y,0,Math.PI*2))}e.fill(),e.restore(),r.type==="riso"&&(e.globalAlpha*=.5,e.fillStyle=ue(e,"#ffffff",.3+a*.4,o),e.fillRect(f-4,h-4,c-f+8,u-h+8));break}case"grain":e.globalAlpha*=.3+a*.3,e.fillStyle=ue(e,l,.2+a*.5,o),e.fillRect(f-4,h-4,c-f+8,u-h+8);break;case"stipple":{const w=10*i,g=Math.min(4e3,Math.round((c-f)*(u-h)/(w*w)*a*1.6));e.fillStyle=l,e.globalAlpha*=.8,e.beginPath();for(let _=0;_<g;_++){const M=f+z(_,o+1)*(c-f),y=h+z(_,o+2)*(u-h),A=.9+z(_,o+3)*1.4*i;e.moveTo(M+A,y),e.arc(M,y,A,0,Math.PI*2)}e.fill();break}case"wash":{for(let w=0;w<3;w++){const g=f+(c-f)*(.2+.6*z(w,o+4)),_=h+(u-h)*(.2+.6*z(w,o+6)),M=Math.max(8,Math.min(c-f,u-h)*(.35+.3*z(w,o+8))),y=e.createRadialGradient(g,_,0,g,_,M);y.addColorStop(0,l),y.addColorStop(1,l+"00"),e.save(),e.globalAlpha*=.22*a,e.fillStyle=y,e.fillRect(g-M,_-M,M*2,M*2),e.restore()}e.save(),e.globalAlpha*=.5*a,e.strokeStyle=l,e.lineWidth=7*i,e.lineJoin="round",e.stroke(t),e.restore(),e.globalAlpha*=.25,e.fillStyle=ue(e,l,.3,o),e.fillRect(f-4,h-4,c-f+8,u-h+8);break}case"paper":{e.save(),e.globalAlpha*=.2+a*.2,e.fillStyle=ue(e,l,.2+a*.4,o),e.fillRect(f-4,h-4,c-f+8,u-h+8),e.restore();const w=Math.min(900,Math.round((c-f)*(u-h)/4e3*a*i));e.strokeStyle=l,e.lineWidth=.7,e.globalAlpha*=.18,e.beginPath();for(let g=0;g<w;g++){const _=f+z(g,o+11)*(c-f),M=h+z(g,o+12)*(u-h),y=z(g,o+13)*Math.PI*2,A=6+z(g,o+14)*14;e.moveTo(_,M),e.quadraticCurveTo(_+Math.cos(y+.6)*A*.6,M+Math.sin(y+.6)*A*.6,_+Math.cos(y)*A,M+Math.sin(y)*A)}e.stroke();break}case"grid":{const w=40*i;e.strokeStyle=l,e.beginPath();const g=Math.floor(f/w)*w,_=Math.floor(h/w)*w;for(let M=g;M<=c;M+=w)e.moveTo(M,h),e.lineTo(M,u);for(let M=_;M<=u;M+=w)e.moveTo(f,M),e.lineTo(c,M);e.lineWidth=1.2,e.globalAlpha*=.35*a+.1,e.stroke(),e.beginPath();for(let M=Math.floor(f/(w*5))*w*5;M<=c;M+=w*5)e.moveTo(M,h),e.lineTo(M,u);for(let M=Math.floor(h/(w*5))*w*5;M<=u;M+=w*5)e.moveTo(f,M),e.lineTo(c,M);e.lineWidth=2.4,e.stroke();break}}e.restore()}const tn=(e,t,n,r)=>t*Xt(e/38,r+n*977);function ns(e,t,n,r){const s=Math.floor(n*t.fps+1e-6),o=Zt(r)+(t.seed??0)*131|0;return e.map((a,i)=>{const l=Sn(a.pts,a.closed,10);if(l.length<2)return a;const f=[];let h=0;const c=a.closed&&l.length>2?l.length-1:l.length;for(let u=0;u<c;u++){u&&(h+=Math.hypot(l[u][0]-l[u-1][0],l[u][1]-l[u-1][1]));const p=l[Math.max(0,u-1)],k=l[Math.min(l.length-1,u+1)],E=k[0]-p[0],d=k[1]-p[1],S=Math.hypot(E,d)||1,w=tn(h,t.amount,s,o+i*17);f.push([l[u][0]-d/S*w,l[u][1]+E/S*w])}return{pts:f,closed:a.closed}})}const pe=new Map;function nn(e,t,n,r){const s=Math.floor(n*t.fps+1e-6),o=`${s}|${r}|${t.amount}|${e}`;let a=pe.get(o);if(a)return a;pe.size>600&&pe.clear();const i=as(e);if(a=new Path2D,!i.L)return a.addPath(new Path2D(e)),a;const l=new Set;let f=0;const h=c=>{if(!(c-f+1<2)){for(let p=f;p<=c;p++){const k=Math.max(f,p-1),E=Math.min(c,p+1),d=i.xs[E]-i.xs[k],S=i.ys[E]-i.ys[k],w=Math.hypot(d,S)||1,g=tn(i.ss[p],t.amount,s,r),_=i.xs[p]-S/w*g,M=i.ys[p]+d/w*g;p===f?a.moveTo(_,M):a.lineTo(_,M)}Math.hypot(i.xs[c]-i.xs[f],i.ys[c]-i.ys[f])<i.step*2&&(a.closePath(),l.add(f))}};for(let c=1;c<i.ss.length;c++)Math.hypot(i.xs[c]-i.xs[c-1],i.ys[c]-i.ys[c-1])>i.step*3&&(h(c-1),f=c);return h(i.ss.length-1),pe.set(o,a),a}const de=new Map,rs=e=>{let t=de.get(e);return t||(de.size>2e3&&de.clear(),t=new Path2D(e),de.set(e,t)),t},Mt=e=>{const t=Math.max(0,Math.min(1,e));return t*t*(3-2*t)};function ss(e,t,n,r,s,o){const a=t.params,i={...a,parts:a.rig?mr(t,r):a.parts??[]},l=t.stroke,f=t.fill,h=f.type!=="none",c=M=>!!l&&l.width>0&&M.line!==!1&&(M.fill===null||i.outline!==!1),u=Math.max(0,Math.min(1,n.end)-Math.max(0,n.start)),p=u>=1&&!n.offset,k=i.parts.map(M=>p?1:Math.max(1,Le(M.d))),E=i.parts.map((M,y)=>c(M)?k[y]:p?1:Math.max(40,k[y]*.35)),d=E.reduce((M,y)=>M+y,0)||1,S=Math.max(0,n.start)*d,w=S+u*d,g=Zt(t.id)+(o?.seed??0)*131;let _=0;i.parts.forEach((M,y)=>{const A=E[y],P=_;_=_+A;const T=p?1:Math.max(0,Math.min(1,(w-P)/A))-Math.max(0,Math.min(1,(S-P)/A));if(T<=0)return;const R=o?nn(M.d,o,r,g+y*29):rs(M.d),C=v=>{if(!c(M)||!l)return;e.globalAlpha=s*t.opacity*(l.opacity??1)*(M.o??1);const m=Le(M.d),b=p?m:m*T,O=l.width*(M.lw??1)*(v?2:1);if(l.hand){const $={...l.hand,...o?{boil:Math.max(l.hand.boil??0,o.fps)}:{}};ot(e,M.d,{color:l.color,width:O,from:p?0:Math.max(0,(S-P)/A)*m,len:b,hand:$,time:r})}else e.strokeStyle=l.color,e.lineWidth=O,e.lineCap=l.cap??"round",e.lineJoin=l.join??"round",p||!m?e.setLineDash([]):(e.setLineDash([b,m*2]),e.lineDashOffset=-Math.max(0,(S-P)/A)*m),e.stroke(R),e.setLineDash([])},I=h&&!!M.fill;if(I&&C(!0),I){if(e.globalAlpha=s*t.opacity*(f.opacity??1)*(M.o??1)*(p?1:c(M)?Mt((T-.6)/.4):Mt(T)),e.globalAlpha>0){e.fillStyle=M.fill,M.eo?e.fill(R,"evenodd"):e.fill(R);const v=f.texture;v&&(e.save(),M.eo&&e.clip(R,"evenodd"),en(e,R,os(M.d),v,M.fill,g+y),e.restore())}}else C(!1)})}const me=new Map;function os(e){let t=me.get(e);if(t)return t;const n=e.match(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi)?.map(Number)??[];let r=1/0,s=1/0,o=-1/0,a=-1/0;for(let i=0;i+1<n.length;i+=2)r=Math.min(r,n[i]),o=Math.max(o,n[i]),s=Math.min(s,n[i+1]),a=Math.max(a,n[i+1]);return t=Number.isFinite(r)?[r,s,o,a]:[-50,-50,50,50],me.size>2e3&&me.clear(),me.set(e,t),t}const re=new Map;function st(e){let t=re.get(e);if(t)return t;re.size>400&&re.clear();const n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d",e);let r=0;try{r=n.getTotalLength()}catch{r=0}if(!Number.isFinite(r)||r<=0)return t={xs:new Float32Array(0),ys:new Float32Array(0),ss:new Float32Array(0),L:0,step:1},re.set(e,t),t;const s=Math.max(1.5,r/900),o=Math.ceil(r/s)+1,a=new Float32Array(o),i=new Float32Array(o),l=new Float32Array(o);for(let f=0;f<o;f++){const h=Math.min(r,f*s),c=n.getPointAtLength(h);a[f]=c.x,i[f]=c.y,l[f]=h}return t={xs:a,ys:i,ss:l,L:r,step:s},re.set(e,t),t}const Le=e=>st(e).L,as=e=>st(e);function _t(e,t){let n=Math.imul(e^2654435769,2246822507)^Math.imul(t+1,3266489909);return n^=n>>>13,n=Math.imul(n,668265263),n^=n>>>16,(n>>>0)/4294967296*2-1}function kt(e,t){const n=Math.floor(e),r=e-n,s=r*r*(3-2*r);return _t(n,t)*(1-s)+_t(n+1,t)*s}const St=e=>{const t=Math.max(0,Math.min(1,e));return t*t*(3-2*t)};function At(e,t,n,r,s,o,a,i,l,f=0){if(r-n+1<2)return;const c=t.ss[r]-t.ss[n],u=[],p=[],k=Math.max(.001,Math.min(c*.15,s*3)),E=Math.max(.001,Math.min(c*.22,s*4));for(let d=n;d<=r;d++){const S=Math.max(n,d-1),w=Math.min(r,d+1),g=t.xs[w]-t.xs[S],_=t.ys[w]-t.ys[S],M=Math.hypot(g,_)||1,y=-_/M,A=g/M,P=t.ss[d],L=P-t.ss[n],T=kt(P/(s*3+24),a)*o.wobble*s,R=1+o.press*kt(P/(s*6+48),a+7),C=o.tip+(1-o.tip)*Math.min(St(L/k),St((c-L)/E)),I=Math.max(.15,s/2*R*C),v=t.xs[d]+y*T,m=t.ys[d]+A*T;u.push(v+y*I,m+A*I),p.push(v-y*I,m-A*I)}e.beginPath(),e.moveTo(u[0],u[1]);for(let d=2;d<u.length;d+=2)e.lineTo(u[d],u[d+1]);for(let d=p.length-2;d>=0;d-=2)e.lineTo(p[d],p[d+1]);if(e.closePath(),e.fill(),f>0){const d=e.globalAlpha;e.globalAlpha=d*f,e.lineWidth=Math.max(.4,s*.07),e.lineJoin="round",e.strokeStyle=e.fillStyle,e.stroke(),e.globalAlpha=d}}function ot(e,t,n){const r=st(t);if(!r.L||n.len<=0)return;let s=ft[n.hand.style]??En[n.hand.style]??ft.marker;(n.hand.taper!==void 0||n.hand.press!==void 0)&&(s={...s,...n.hand.taper!==void 0?{tip:Math.max(.02,1-n.hand.taper)}:{},...n.hand.press!==void 0?{press:n.hand.press*.6}:{}});const o=Math.max(.5,n.width*s.width),a=n.hand.boil?Math.floor(n.time*n.hand.boil+1e-6):0,i=(n.hand.seed??0)*131+a*977|0,l=r.L,f=Math.max(0,Math.min(l,n.from)),h=Math.min(l,n.len),c=f+h<=l+1e-6?[[f,Math.min(l,f+h)]]:[[f,l],[0,f+h-l]],u=e.globalAlpha;e.save(),e.fillStyle=s.grain?ts(e,n.color,s.grain,n.hand.seed??0):n.color;const p=s.wet?[[1,s.alpha*.5,i],[.9,s.alpha*.4,i+11],[1.08,s.alpha*.3,i+23]]:[[1,s.alpha,i]];s.retrace&&p.push([.45,s.alpha*.35,i+3]);for(const[k,E,d]of p){e.globalAlpha=u*E;for(const[S,w]of c){let g=-1;for(let _=0;_<r.ss.length;_++){const M=r.ss[_]>=S-1e-6&&r.ss[_]<=w+1e-6,y=g>=0&&_>g&&Math.hypot(r.xs[_]-r.xs[_-1],r.ys[_]-r.ys[_-1])>r.step*3;g>=0&&(!M||y)&&(At(e,r,g,_-1,o*k,s,d,!0,!0,s.wet?.5:0),g=-1),M&&g<0&&(g=_)}g>=0&&At(e,r,g,r.ss.length-1,o*k,s,d,!0,!0,s.wet?.5:0)}}e.restore()}const Mo=e=>"paths"in e?e.trim?.offset??0:0,rn=1280,Se=720,_o=e=>e&&"size"in e&&e.size?{W:e.size[0],H:e.size[1]}:e?.square?{W:Se,H:Se}:{W:rn,H:Se},Et=new Map;function sn(e){let t=Et.get(e);if(t===void 0){const n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d",e);try{t=n.getTotalLength()}catch{t=0}Et.set(e,t=Number.isFinite(t)?t:0)}return t}function ko(e,t,n,r=rn,s=Se,o=0){const a=Math.min(r,s)/V,i=(r-V*a)/2,l=(s-V*a)/2;if(tt(t)){const c=t.step&&t.step>1?Tn(o,t.step):o,u=t.boil&&t.boil.amount>0?t.boil:null,p=t.items.map(E=>nt(E,c)),k=xn(t.items,p);e.save(),e.translate(i,l),e.scale(a,a),t.items.forEach((E,d)=>{if(E.hidden||E.span&&(o<E.span[0]-1e-6||o>=E.span[1]-1e-6))return;const S=k.get(E.id);S?(e.save(),e.transform(...S),Tt(e,p[d],n,c,a,u),e.restore()):Tt(e,p[d],n,c,a,u)}),e.restore();return}const f=Math.max(0,Math.min(1,n.end)-Math.max(0,n.start)),h=n.offset??0;e.save(),e.translate(i,l),e.scale(a,a);for(const c of t.paths){const u=new Path2D(c.d),p=c.opacity??1;if(e.filter=c.blur?`blur(${(c.blur*a).toFixed(2)}px)`:"none",c.fill&&f>0&&(e.globalAlpha=Math.min(1,f)*p,e.fillStyle=c.fill,c.rule?e.fill(u,c.rule):e.fill(u),e.globalAlpha=1),!c.stroke||f<=0)continue;if(e.globalAlpha=p,c.hand){const w=Le(c.d);ot(e,c.d,{color:c.stroke,width:c.strokeWidth??18,from:((n.start+h)%1+1)%1*w,len:f*w,hand:c.hand,time:o}),e.globalAlpha=1;continue}if(e.strokeStyle=c.stroke,e.lineWidth=c.strokeWidth??18,e.lineCap=c.cap??"round",e.lineJoin="round",f>=1&&h===0){e.setLineDash([]),e.stroke(u),e.globalAlpha=1;continue}const k=sn(c.d);if(!k)continue;const E=((n.start+h)%1+1)%1*k,d=f*k,S=Math.min(d,k-E);e.setLineDash([S,k*2]),e.lineDashOffset=-E,e.stroke(u),d>S&&(e.setLineDash([d-S,k*2]),e.lineDashOffset=0,e.stroke(u))}e.setLineDash([]),e.globalAlpha=1,e.filter="none",e.restore()}const is={add:"source-over",subtract:"destination-out",intersect:"destination-in",exclude:"xor"};function Tt(e,t,n,r,s=1,o=null){const a=o&&!t.params.d&&t.type!=="art"?ns(ct(t,r),o,r,t.id):ct(t,r),i=t.fill,l=t.stroke,f=vn(t.ops,n),h=t.params.d?o?nn(t.params.d,o,r,t.id.length*131+t.id.charCodeAt(t.id.length-1)):new Path2D(t.params.d):new Path2D(a.map(E=>Ce(E.pts,E.closed)).join(" ")),c=Math.max(0,Math.min(1,f.end)-Math.max(0,f.start)),u=f.offset??0,p=!(c>=1&&u===0),k=On(t.ops);e.save(),k&&(e.globalCompositeOperation=is[k]),e.transform(...rt(t));for(const E of Ln(t.ops)){if(e.save(),e.transform(...E.m),t.type==="art"){c>0&&ss(e,t,f,r,E.alpha,o),e.setLineDash([]),e.filter="none",e.restore();continue}if(i.type!=="none"&&c>0&&t.type!=="line"&&(e.globalAlpha=t.opacity*(i.opacity??1)*Math.min(1,c)*E.alpha,e.fillStyle=ls(e,t,r),e.fill(h),i.texture&&en(e,h,Gt(t,r),i.texture,i.color??i.stops?.[0]?.[0]??"#c6f432",t.id.length*97+t.id.charCodeAt(0))),l&&l.width>0&&c>0)if(e.globalAlpha=t.opacity*(l.opacity??1)*E.alpha,e.strokeStyle=l.color,e.lineWidth=l.width,e.lineCap=l.cap??"round",e.lineJoin=l.join??"round",e.miterLimit=10,l.blur&&(e.filter=`blur(${(l.blur*s*Math.abs(t.scale[0]||1)).toFixed(2)}px)`),l.hand){const d=o?{...l.hand,boil:Math.max(l.hand.boil??0,o.fps)}:l.hand;for(const S of t.params.d?[t.params.d]:a.map(w=>Ce(w.pts,w.closed))){const w=Le(S);ot(e,S,{color:l.color,width:l.width,from:((f.start+u)%1+1)%1*w,len:c*w,hand:d,time:r})}}else if(!p)l.dash&&l.dash[0]+l.dash[1]>0?(e.setLineDash(l.dash),e.lineDashOffset=-(l.dashOffset??0)):e.setLineDash([]),e.stroke(h);else if(t.params.d&&t.params.box){const d=sn(t.params.d);if(d){const S=((f.start+u)%1+1)%1*d,w=c*d,g=Math.min(w,d-S);e.setLineDash([g,d*2]),e.lineDashOffset=-S,e.stroke(h),w>g&&(e.setLineDash([w-g,d*2]),e.lineDashOffset=0,e.stroke(h))}}else for(const d of t.params.d?[]:a){const S=Pn(d.pts,d.closed);if(!S)continue;const w=new Path2D(Ce(d.pts,d.closed)),g=((f.start+u)%1+1)%1*S,_=c*S,M=Math.min(_,S-g),y=A=>{const P=l.dash;if(!P||P[0]+P[1]<=0)return[A,S*2];const L=P[0]+P[1],T=[];let R=0;for(let C=((l.dashOffset??0)%L+L)%L-L;C<A&&T.length<4e3;C+=L){const I=Math.max(0,C),v=Math.min(A,C+P[0]);v<=I||(T.length?T.push(I-R,v-I):(I>0&&T.push(0,I),T.push(v-I)),R=v)}return T.length?[...T,S*2]:[0,S*2]};e.setLineDash(y(M)),e.lineDashOffset=-g,e.stroke(w),_>M&&(e.setLineDash(y(_-M)),e.lineDashOffset=0,e.stroke(w))}e.setLineDash([]),e.filter="none",e.restore()}e.restore()}function ls(e,t,n){const r=t.fill;if(r.type==="color"||!r.stops)return r.color??"#c6f432";const[s,o,a,i]=Gt(t,n),l=s+(a-s)*(r.cx??.5),f=o+(i-o)*(r.cy??.5);let h;if(r.type==="radial")h=e.createRadialGradient(l,f,0,l,f,Math.max(1,Math.hypot(a-s,i-o)/2));else{const c=(r.angle??0)*Math.PI/180,u=Math.cos(c),p=Math.sin(c),k=Math.abs(u)*(a-s)/2+Math.abs(p)*(i-o)/2;h=e.createLinearGradient(l-u*k,f-p*k,l+u*k,f+p*k)}for(const[c,u]of r.stops)h.addColorStop(u,c);return h}function So(e,t,n,r,s){const o=-r/2,a=-s/2,i=Math.max(0,Math.min(1,n));if(e.beginPath(),t==="wipe-left")e.rect(o,a,r*i,s);else if(t==="wipe-right")e.rect(o+r*(1-i),a,r*i,s);else if(t==="wipe-down")e.rect(o,a,r,s*i);else if(t==="wipe-up")e.rect(o,a+s*(1-i),r,s*i);else if(t==="iris")e.arc(0,0,i*Math.hypot(r,s)/2,0,Math.PI*2);else if(t==="split-h")e.rect(-r*i/2,a,r*i,s);else if(t==="split-v")e.rect(o,-s*i/2,r,s*i);else if(t==="split-h-edges"){const l=r*i/2;e.rect(o,a,l,s),e.rect(r/2-l,a,l,s)}else if(t==="watercolor")if(i>=1)e.rect(o,a,r,s);else{const l=$n(i)*Math.hypot(r,s)/2;for(let f=0;f<256;f++){const h=f/256*Math.PI*2,c=l*(1+Rn(h)),u=Math.sin(h)*c,p=-Math.cos(h)*c;f?e.lineTo(u,p):e.moveTo(u,p)}e.closePath()}else if(i>=1&&/^(torn|blocks)/.test(t))e.rect(o,a,r,s);else if(t==="torn"||t==="torn-back"){const l=Cn(t==="torn"?i:1-i),f=In().map(c=>[o+(l-jn(c))*r,a+c*s]),h=t==="torn"?o-r:o+2*r;e.moveTo(h,a);for(const[c,u]of f)e.lineTo(c,u);e.lineTo(h,a+s),e.closePath()}else if(t==="blocks"||t==="blocks-back"){const l=Dn.n,f=Math.max(r,s)/800;for(let h=0;h<l;h++)for(let c=0;c<l;c++){const u=Bn(c,h);(t==="blocks"?u<i:u>=1-i)&&e.rect(o+c*r/l-f,a+h*s/l-f,r/l+2*f,s/l+2*f)}}else e.moveTo(0,0),e.arc(0,0,Math.hypot(r,s),-Math.PI/2,-Math.PI/2+i*Math.PI*2),e.closePath();e.clip()}let xt=null;const fs=()=>xt??=Promise.all(Fn.map(async e=>{const t=await fetch(e.url);if(!t.ok)throw Error(`Font ${e.url}: HTTP ${t.status}`);return{name:e.name,weight:e.weight,style:"normal",data:await t.arrayBuffer()}})).catch(e=>{throw xt=null,e});let vt=null;const cs=()=>vt??=U(()=>import("./index-CZn97Ygs.js"),__vite__mapDeps([0,1,2,3])).then(e=>e.default).catch(e=>{throw vt=null,e}),hs=48,ze=new Map,We=new Map,on=(e,t,n)=>(e.set(t,n),e.size>hs&&e.delete(e.keys().next().value),n);function us(e){const t=Ht(e);return ze.get(t)??on(ze,t,(async()=>{const[n,r]=await Promise.all([cs(),fs()]);return n(Nn(e),{width:e.width,height:e.height,fonts:r})})().catch(n=>{throw ze.delete(t),n}))}const ps=e=>Math.min(2,2560/Math.max(e.width,e.height));function Ao(e){const t=Ht(e);return We.get(t)??on(We,t,(async()=>{const n=await us(e),r=new Image,s=ps(e);r.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`,await r.decode();const o=Object.assign(document.createElement("canvas"),{width:Math.round(e.width*s),height:Math.round(e.height*s)}),a=o.getContext("2d");if(!a)throw Error("Canvas unavailable");return a.drawImage(r,0,0,o.width,o.height),o})().catch(n=>{throw We.delete(t),n}))}const ds=Object.freeze({dark:"dark",light:"positron",atlas:"liberty",neon:"dark",lime:"dark",paper:"positron",mono:"positron",satellite:"positron"}),ms="https://tiles.maps.eox.at/wmts/1.0.0/s2cloudless_3857/default/g/{z}/{y}/{x}.jpg",gs=14,ys="EOxCloudless 2016 https://cloudless.eox.at by EOX IT Services GmbH (Contains modified Copernicus Sentinel data 2016)",ie=Object.freeze({source:"sentinel",tiles:ms,maxzoom:gs,credit:ys}),ws="Powered by Esri · Source: Esri, Vantor, GeoEye, Earthstar Geographics, CNES/Airbus DS, USDA, USGS, AeroGRID, IGN, and the GIS User Community",ge=(e,t,n,r,s,o,a,i,l,f,h,c)=>({bg:e,land:t,park:n,water:r,waterLine:s,building:o,road:a,roadMajor:i,rail:l,boundary:f,text:h,halo:c}),bs=Object.freeze({neon:ge("#070b1a","#0b1226","#0c1a2a","#02040c","#0a2a55","#121c3a","#1b3b7a","#00e5ff","#233060","#ff2fd0","#bfe9ff","#050814"),lime:ge("#0b0d0a","#0f120d","#121a10","#050605","#1d2a16","#171c13","#2a3322","#c6ff3d","#2a3322","#9bcc2e","#e9ffc4","#070806"),paper:ge("#efe4cc","#e9dcc0","#d8d3a6","#b9cfc9","#9fbab4","#dccaa5","#fbf5e6","#c98f4a","#b8a888","#8a5a3c","#4a3a28","#f4ead4"),mono:ge("#f2f2f2","#ececec","#e2e2e2","#cfcfcf","#bdbdbd","#dedede","#ffffff","#9a9a9a","#c8c8c8","#6e6e6e","#3a3a3a","#f7f7f7")}),Ms=/motorway|trunk|primary|major/;function an(e){const t=e["source-layer"]??"",n=e.id??"";return e.type==="background"?"bg":e.type==="symbol"?"label":t==="water"?"water":t==="waterway"?"waterLine":t==="park"||t==="landcover"?"park":t==="landuse"||t==="aeroway"?e.type==="line"?"road":"land":t==="building"?"building":t==="transportation"?/rail|transit/.test(n)?"rail":Ms.test(n)?"roadMajor":"road":t==="boundary"?"boundary":"other"}function _s(e,t){const n=an(e),r={...e.paint??{}};if(n==="other")return e.type==="raster"||e.type==="hillshade"?null:e;if(n==="label")return r["text-color"]=t.text,r["text-halo-color"]=t.halo,{...e,paint:r};const s=n==="bg"?t.bg:t[n];return e.type==="background"?r["background-color"]=s:e.type==="fill"?(r["fill-color"]=s,delete r["fill-pattern"],"fill-outline-color"in r&&(r["fill-outline-color"]=s)):e.type==="fill-extrusion"?(r["fill-extrusion-color"]=s,delete r["fill-extrusion-pattern"]):e.type==="line"&&(r["line-color"]=s,delete r["line-pattern"]),{...e,paint:r}}function ks(e,t=ie){const n=[];for(const r of e.layers){const s=an(r);if(s==="label")n.push({...r,paint:{...r.paint??{},"text-color":"#ffffff","text-halo-color":"rgba(0,0,0,.85)","text-halo-width":1.6}});else if(s==="boundary"&&r.type==="line"){const o=["<=",["get","admin_level"],4];n.push({...r,filter:r.filter?["all",r.filter,o]:o,paint:{...r.paint??{},"line-color":"rgba(255,255,255,.55)"}})}else s==="roadMajor"&&r.type==="line"&&n.push({...r,paint:{...r.paint??{},"line-color":"rgba(255,236,170,.22)"}})}return{...e,sources:{...e.sources,"cx-sat":{type:"raster",tiles:[t.tiles],tileSize:256,maxzoom:t.maxzoom,attribution:t.credit}},layers:[{id:"cx-sat-bg",type:"background",paint:{"background-color":"#0b0f12"}},{id:"cx-sat",type:"raster",source:"cx-sat",paint:{"raster-fade-duration":0}},...n]}}const Ot=Object.freeze({dark:"#30353f",light:"#e4e1da",atlas:"#ddd6cc",neon:"#26367a",lime:"#323d27",paper:"#dccaa5",mono:"#dcdcdc",satellite:"#d6d0c6"});function Lt(e,t=null,n=1){const r=typeof t=="string"&&/^#[0-9a-f]{6}$/i.test(t)?t:Ot[e]??Ot.dark,s=Math.max(0,Math.min(2,Number(n)||1));return"#"+[1,3,5].map(o=>Math.min(255,Math.round(parseInt(r.slice(o,o+2),16)*s)).toString(16).padStart(2,"0")).join("")}function Ss(e,t,n=ie){if(e==="satellite")return ks(t,n??ie);const r=bs[e];return r?{...t,layers:t.layers.map(s=>_s(s,r)).filter(Boolean)}:t}function As(e,t,n=ie){return e==="satellite"?[(n??ie).credit,t]:[t]}function Es(e,t,n){const r=[];for(const s of e){let o="";for(const a of String(s).split(" ")){const i=o?o+" "+a:a;o&&t(i)>n?(r.push(o),o=a):o=i}o&&r.push(o)}return r}const Ts=e=>Hn[e];function xs(e,t,n,r,s,o){Gn(e,t,n,r,s,o,Ts)}const Pt=Object.fromEntries(Object.entries(ds).map(([e,t])=>[e,`https://tiles.openfreemap.org/styles/${t}`])),vs="OpenFreeMap © OpenMapTiles · Data © OpenStreetMap contributors",Os=[110.8,15.4,113.2,17.4],Ls=[111.2,6,118,12.2],$t=([e,t,n,r])=>[[e,t],[n,t],[n,r],[e,r],[e,t]],Rt={type:"MultiPolygon",coordinates:[[$t(Os)],[$t(Ls)]]},Ps=e=>({type:"FeatureCollection",features:[{type:"Feature",properties:{name:e==="vi"?`Quần đảo Hoàng Sa
154
+ <\/script>`;let G=null,ee=null,Br=0;const Se=new Map,Ee=new Map;function Nr(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)+":"+e.length}let te=null;function Fr(){return te||(te=Promise.all(wn.map(async t=>{const n=await fetch(bn+t.file);if(!n.ok)throw Error(t.file);return{family:t.family,weight:t.weight,style:t.style,data:await n.arrayBuffer()}})).catch(()=>(te=null,[])),te)}let Ne=null,be=null;function Gr(){return Ne??=Promise.all([U(()=>import("./three-D7Ssject.js"),[]),U(()=>import("./RoomEnvironment-grxZ6k9f.js"),[])]).then(([e,t])=>({src:e.default,room:Mn(t.default)})).catch(e=>{throw Ne=null,e}),Ne}function Hr(){return be??=Gr().then(e=>{G?.contentWindow?.postMessage({type:"three",src:e.src,room:e.room},"*")}).catch(e=>{throw be=null,e}),be}let Fe=null,Me=null;function zr(){return Fe??=Promise.all([U(()=>import("./opentype-D4-4HGq7.js"),[]),...Object.entries(kn).map(async([e,t])=>{const n=await fetch(t);if(!n.ok)throw Error(`Font ${n.status}`);return{key:e,data:await n.arrayBuffer()}})]).then(([e,...t])=>({src:e.default,fonts:t})).catch(e=>{throw Fe=null,e}),Fe}function Wr(){return Me??=zr().then(e=>{G?.contentWindow?.postMessage({type:"glyphs",src:e.src,fonts:e.fonts.map(t=>({key:t.key,data:t.data.slice(0)}))},"*")}).catch(e=>{throw Me=null,e}),Me}const Ge=new Map;let _e=new Map;function qr(e){return Promise.all(e.map(t=>{let n=_e.get(t);if(!n){let r=Ge.get(t);r||(r=fetch(dr(t)).then(s=>s.ok?s.arrayBuffer():null).catch(()=>null),Ge.set(t,r)),n=r.then(s=>{if(!s){Ge.delete(t),_e.delete(t);return}G?.contentWindow?.postMessage({type:"stickers",items:[{id:t,data:s.slice(0)}]},"*")}),_e.set(t,n)}return n}))}let He=null,ke=null;function Ur(){return He??=Promise.all([U(()=>import("./GLTFLoader-DYtnVu-I.js"),[]),U(()=>import("./BufferGeometryUtils-_ZXHoOh1.js"),[]),U(()=>import("./SkeletonUtils-CfWUgbiL.js"),[])]).then(([e,t,n])=>{const r=De(e.default),s=De(t.default),o=De(n.default);if(!r||!s||!o)throw Error("GLTFLoader shape changed");return{gltf:r,bgu:s,skel:o}}).catch(e=>{throw He=null,e}),He}function Kr(){return ke??=Ur().then(e=>{G?.contentWindow?.postMessage({type:"gltf",...e},"*")}).catch(e=>{throw ke=null,e}),ke}const Te=new Map,J=new Map;function go(e,t){const n=t.slice().buffer;Te.set(e,n),J.delete(`local:${e}`)}function yo(e){for(const t of[...Te.keys()])t.startsWith(e)&&(Te.delete(t),J.delete(`local:${t}`))}let ne=null;function Vr(e){if(!ne){const t={uris:new Set,run:Promise.resolve({})};t.run=new Promise(n=>setTimeout(n,0)).then(()=>(ne=null,gr([...t.uris]))),ne=t}return ne.uris.add(e),ne.run.then(t=>{const n=t[e];if(!n)throw Error(le("Không tải được tài nguyên của lớp plug-in ({0}).",[e.split("/").pop()||"?"]));return n})}function Jr(e){let t=J.get(e);return t||(t=e.startsWith("local:")?Promise.resolve().then(()=>{const n=Te.get(e.slice(6));if(!n)throw Error("local asset missing");return n}):Vr(e).then(n=>fetch(n)).then(n=>{if(!n.ok)throw Error(le("Không tải được tài nguyên của lớp plug-in ({0}).",[e.split("/").pop()||"?"]));return n.arrayBuffer()}),J.set(e,t),t.catch(()=>J.delete(e)),J.size>64&&J.delete(J.keys().next().value)),t}async function Yr(e,t){const n=_r(t),r=await Jr(n.uri),s=new Uint8Array(r),o={...n.grid?{grid:n.grid}:{},...n.fps?{fps:n.fps}:{}};if(s[0]===103&&s[1]===108&&s[2]===84&&s[3]===70)return{name:e,kind:"model",data:r.slice(0)};if(s[0]===67&&s[1]===88&&s[2]===83&&s[3]===81)return{name:e,kind:"sequence",frames:$r(s).map(a=>a.slice().buffer),...o};if(/\.cube$/i.test(e)||/\.cube$/i.test(n.uri)){const a=_n(Dt(new TextDecoder().decode(s)));return{name:e,kind:"lut",size:a.size,data:a.data.buffer.slice(0)}}return{name:e,kind:"image",data:r.slice(0),...o}}const xe=new Map;async function Xr(e,t,n){const r=t.assets;if(!r||!Object.keys(r).length)return;const s=JSON.stringify(r);if(xe.get(e)===s)return;n&&await Kr().catch(()=>{throw Error(le("Không tải được bộ đọc mô hình 3D — kiểm tra mạng rồi thử lại."))});const a=(await Promise.all(Object.entries(r).map(([i,l])=>Yr(i,l)))).map(i=>i.kind==="lut"?{...i,data:new Float32Array(i.data)}:i);G?.contentWindow?.postMessage({type:"assets",layer:e,items:a},"*"),xe.set(e,s)}function Zr(){if(ee&&G?.isConnected)return ee;G?.remove(),Ee.clear(),ae.clear(),_e=new Map,be=null,Me=null,ke=null,xe.clear();const e=document.createElement("iframe");return G=e,e.setAttribute("sandbox","allow-scripts"),e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e.title="motion-sandbox",e.style.cssText="position:fixed;width:1px;height:1px;left:-10px;top:-10px;border:0;opacity:0;pointer-events:none",e.srcdoc=Dr,ee=new Promise((t,n)=>{const r=window.setTimeout(()=>{window.removeEventListener("message",s),G===e&&(G.remove(),G=null,ee=null),n(Error("Motion sandbox did not start"))},8e3),s=o=>{o.source===e.contentWindow&&o.data?.type==="boot"&&(window.clearTimeout(r),window.removeEventListener("message",s),Fr().then(a=>{e.contentWindow?.postMessage({type:"fonts",fonts:a},"*"),t()}))};window.addEventListener("message",s)}),document.body.appendChild(e),ee}window.addEventListener("message",e=>{if(!G||e.source!==G.contentWindow||e.data?.type!=="frame")return;const t=Se.get(e.data.req);t&&(Se.delete(e.data.req),window.clearTimeout(t.timer),e.data.bmp?t.resolve(e.data.bmp):t.reject(Error(e.data.error===Yt?le("Trình duyệt không chạy được WebGL nên không vẽ được lớp Motion 3D. Hãy bật tăng tốc phần cứng hoặc dùng Chrome / Edge bản mới."):String(e.data.error||"Motion frame failed"))))});const ae=new Map,ve=new Map,Qr=1500;let Oe=Promise.resolve(),wt=Promise.resolve(),Xe=0,Ze=-1/0;async function es(){for(;;){const e=Oe;if(await e,e!==Oe)continue;const t=Ze+Qr-performance.now();if(!Xe&&t<=0)return;await new Promise(n=>window.setTimeout(n,Math.max(100,t)))}}async function wo(e){await Zr();const t=gn(e.motion.code),n=e.motion.kind==="three",r=Nr(e.motion.assets?t+"\0"+JSON.stringify(e.motion.assets):t);n&&await Hr(),await Xr(e.layer,e.motion,n),n&&yn(t)&&await Wr().catch(()=>{throw Error(le("Không tải được phông chữ cho chữ 3D nổi — kiểm tra mạng rồi thử lại."))});const s=n?[]:pr(t,e.motion.params||{});if(s.length&&await qr(s),!n)return Qe(e,t,r);if(!e.background){Xe++,Ze=performance.now();try{return await bt(e,t,r)}finally{Xe--,Ze=performance.now()}}return bt(e,t,r)}function bt(e,t,n){const r=n+"|"+JSON.stringify(e.motion.params||{})+"|"+e.width+"x"+e.height;if(ae.get(e.layer)===r)return Qe(e,t,n);const s=ve.get(e.layer)??0,o=G,a=()=>{if((ve.get(e.layer)??0)!==s||G!==o)throw Error("dropped");return Qe(e,t,n).then(l=>(G===o&&ae.set(e.layer,r),l),l=>{throw ae.delete(e.layer),l})};if(e.background){const l=wt.then(es).then(a);return wt=l.catch(()=>{}),l}const i=Oe.then(a);return Oe=i.catch(()=>{}),i}function Qe(e,t,n){const r=e.motion.kind==="three",s=++Br,o=Ee.get(e.layer)!==n;return Ee.set(e.layer,n),new Promise((a,i)=>{const l=window.setTimeout(()=>{Se.delete(s),i(Error("Motion frame timed out"))},(r?Jt:o?Cr:Vt)+2e3);Se.set(s,{resolve:a,reject:i,timer:l}),G.contentWindow.postMessage({type:"frame",req:s,layer:e.layer,key:n,code:t,params:e.motion.params||{},t:e.t,width:e.width,height:e.height,duration:e.duration,fps:e.fps??30,...r?{kind:"three",surface:e.surface??null}:{space:e.space??null}},"*")})}function bo(e){ve.set(e,(ve.get(e)??0)+1),ae.delete(e),xe.delete(e),G?.contentWindow&&Ee.delete(e)&&G.contentWindow.postMessage({type:"drop",layer:e},"*")}function z(e,t){let n=Math.imul(e^2654435769,2246822507)^Math.imul(t+1,3266489909);return n^=n>>>13,n=Math.imul(n,668265263),n^=n>>>16,(n>>>0)/4294967296}const Xt=(e,t)=>{const n=Math.floor(e),r=e-n,s=r*r*(3-2*r);return(z(n,t)*(1-s)+z(n+1,t)*s)*2-1},Zt=e=>{let t=7;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return t>>>0},he=new Map;function Qt(e,t,n,r){const s=`${e}|${t.toFixed(2)}|${n%7}|${r}`;let o=he.get(s);if(o)return o;he.size>64&&he.clear();const a=128,i=n%7;o=Object.assign(document.createElement("canvas"),{width:a,height:a});const l=o.getContext("2d"),f=l.createImageData(a,a),[h,c,u]=[1,3,5].map(d=>parseInt(e.slice(d,d+2),16)),p=new Float32Array(a*a);for(let d=0;d<a*a;d++)p[d]=z(d,i+9);const k=(d,A)=>p[(A+a)%a*a+(d+a)%a],E=r?1-t*.35:t*.4;for(let d=0;d<a;d++)for(let A=0;A<a;A++){let w=0;for(let M=-1;M<=1;M++)for(let y=-1;y<=1;y++)w+=k(A+y,d+M);const g=Math.min(1,Math.max(0,((w/9-.5)*2.4+.5)*.6+.4*k(A,d))),_=(d*a+A)*4;f.data[_]=h,f.data[_+1]=c,f.data[_+2]=u,f.data[_+3]=g>E?r?Math.round(160+95*(g-E)/(1-E+1e-6)):255:0}return l.putImageData(f,0,0),he.set(s,o),o}function ts(e,t,n,r=0){return e.createPattern(Qt(t,Math.max(0,Math.min(1,n)),r,!1),"repeat")??t}function ue(e,t,n,r=0){return e.createPattern(Qt(t,Math.max(0,Math.min(1,n)),r,!0),"repeat")??t}function en(e,t,n,r,s,o){const a=r.amount??.5,i=r.scale??1,l=r.color??Sn(s,null),[f,h,c,u]=n,p=(f+c)/2,k=(h+u)/2,E=Math.hypot(c-f,u-h)/2+4,d=(r.angle??0)*Math.PI/180;e.save(),r.type==="riso"&&(e.save(),e.globalAlpha*=.42*a,e.globalCompositeOperation="multiply",e.translate(4*i,-3*i),e.fillStyle=l,e.fill(t),e.restore()),e.clip(t);const A=(w,g,_,M)=>{e.save(),e.globalAlpha*=M,e.strokeStyle=l,e.lineWidth=_,e.lineCap="butt",e.translate(p,k),e.rotate(w),e.beginPath();for(let y=-E;y<=E;y+=g){const S=Xt(y/g,o+5)*g*.12;e.moveTo(-E,y+S),e.lineTo(E,y-S)}e.stroke(),e.restore()};switch(r.type){case"hatch":A(d,13*i,1.4+a*2.6,.35+a*.55);break;case"crosshatch":A(d,12*i,1.2+a*2,.3+a*.5),A(d+Math.PI/2,12*i,1.2+a*2,.25+a*.45);break;case"halftone":case"riso":{const w=(r.type==="riso"?9:12)*i;e.save(),e.fillStyle=l,e.globalAlpha*=r.type==="riso"?.5:.85,e.translate(p,k),e.rotate(d),e.beginPath();for(let g=-E;g<=E;g+=w)for(let _=-E;_<=E;_+=w){const M=.25+.75*Math.max(0,Math.min(1,(_+g)/(2*E)+.5)),y=w*.5*Math.sqrt(a*M);y>.3&&(e.moveTo(_+y,g),e.arc(_,g,y,0,Math.PI*2))}e.fill(),e.restore(),r.type==="riso"&&(e.globalAlpha*=.5,e.fillStyle=ue(e,"#ffffff",.3+a*.4,o),e.fillRect(f-4,h-4,c-f+8,u-h+8));break}case"grain":e.globalAlpha*=.3+a*.3,e.fillStyle=ue(e,l,.2+a*.5,o),e.fillRect(f-4,h-4,c-f+8,u-h+8);break;case"stipple":{const w=10*i,g=Math.min(4e3,Math.round((c-f)*(u-h)/(w*w)*a*1.6));e.fillStyle=l,e.globalAlpha*=.8,e.beginPath();for(let _=0;_<g;_++){const M=f+z(_,o+1)*(c-f),y=h+z(_,o+2)*(u-h),S=.9+z(_,o+3)*1.4*i;e.moveTo(M+S,y),e.arc(M,y,S,0,Math.PI*2)}e.fill();break}case"wash":{for(let w=0;w<3;w++){const g=f+(c-f)*(.2+.6*z(w,o+4)),_=h+(u-h)*(.2+.6*z(w,o+6)),M=Math.max(8,Math.min(c-f,u-h)*(.35+.3*z(w,o+8))),y=e.createRadialGradient(g,_,0,g,_,M);y.addColorStop(0,l),y.addColorStop(1,l+"00"),e.save(),e.globalAlpha*=.22*a,e.fillStyle=y,e.fillRect(g-M,_-M,M*2,M*2),e.restore()}e.save(),e.globalAlpha*=.5*a,e.strokeStyle=l,e.lineWidth=7*i,e.lineJoin="round",e.stroke(t),e.restore(),e.globalAlpha*=.25,e.fillStyle=ue(e,l,.3,o),e.fillRect(f-4,h-4,c-f+8,u-h+8);break}case"paper":{e.save(),e.globalAlpha*=.2+a*.2,e.fillStyle=ue(e,l,.2+a*.4,o),e.fillRect(f-4,h-4,c-f+8,u-h+8),e.restore();const w=Math.min(900,Math.round((c-f)*(u-h)/4e3*a*i));e.strokeStyle=l,e.lineWidth=.7,e.globalAlpha*=.18,e.beginPath();for(let g=0;g<w;g++){const _=f+z(g,o+11)*(c-f),M=h+z(g,o+12)*(u-h),y=z(g,o+13)*Math.PI*2,S=6+z(g,o+14)*14;e.moveTo(_,M),e.quadraticCurveTo(_+Math.cos(y+.6)*S*.6,M+Math.sin(y+.6)*S*.6,_+Math.cos(y)*S,M+Math.sin(y)*S)}e.stroke();break}case"grid":{const w=40*i;e.strokeStyle=l,e.beginPath();const g=Math.floor(f/w)*w,_=Math.floor(h/w)*w;for(let M=g;M<=c;M+=w)e.moveTo(M,h),e.lineTo(M,u);for(let M=_;M<=u;M+=w)e.moveTo(f,M),e.lineTo(c,M);e.lineWidth=1.2,e.globalAlpha*=.35*a+.1,e.stroke(),e.beginPath();for(let M=Math.floor(f/(w*5))*w*5;M<=c;M+=w*5)e.moveTo(M,h),e.lineTo(M,u);for(let M=Math.floor(h/(w*5))*w*5;M<=u;M+=w*5)e.moveTo(f,M),e.lineTo(c,M);e.lineWidth=2.4,e.stroke();break}}e.restore()}const tn=(e,t,n,r)=>t*Xt(e/38,r+n*977);function ns(e,t,n,r){const s=Math.floor(n*t.fps+1e-6),o=Zt(r)+(t.seed??0)*131|0;return e.map((a,i)=>{const l=An(a.pts,a.closed,10);if(l.length<2)return a;const f=[];let h=0;const c=a.closed&&l.length>2?l.length-1:l.length;for(let u=0;u<c;u++){u&&(h+=Math.hypot(l[u][0]-l[u-1][0],l[u][1]-l[u-1][1]));const p=l[Math.max(0,u-1)],k=l[Math.min(l.length-1,u+1)],E=k[0]-p[0],d=k[1]-p[1],A=Math.hypot(E,d)||1,w=tn(h,t.amount,s,o+i*17);f.push([l[u][0]-d/A*w,l[u][1]+E/A*w])}return{pts:f,closed:a.closed}})}const pe=new Map;function nn(e,t,n,r){const s=Math.floor(n*t.fps+1e-6),o=`${s}|${r}|${t.amount}|${e}`;let a=pe.get(o);if(a)return a;pe.size>600&&pe.clear();const i=as(e);if(a=new Path2D,!i.L)return a.addPath(new Path2D(e)),a;const l=new Set;let f=0;const h=c=>{if(!(c-f+1<2)){for(let p=f;p<=c;p++){const k=Math.max(f,p-1),E=Math.min(c,p+1),d=i.xs[E]-i.xs[k],A=i.ys[E]-i.ys[k],w=Math.hypot(d,A)||1,g=tn(i.ss[p],t.amount,s,r),_=i.xs[p]-A/w*g,M=i.ys[p]+d/w*g;p===f?a.moveTo(_,M):a.lineTo(_,M)}Math.hypot(i.xs[c]-i.xs[f],i.ys[c]-i.ys[f])<i.step*2&&(a.closePath(),l.add(f))}};for(let c=1;c<i.ss.length;c++)Math.hypot(i.xs[c]-i.xs[c-1],i.ys[c]-i.ys[c-1])>i.step*3&&(h(c-1),f=c);return h(i.ss.length-1),pe.set(o,a),a}const de=new Map,rs=e=>{let t=de.get(e);return t||(de.size>2e3&&de.clear(),t=new Path2D(e),de.set(e,t)),t},Mt=e=>{const t=Math.max(0,Math.min(1,e));return t*t*(3-2*t)};function ss(e,t,n,r,s,o){const a=t.params,i={...a,parts:a.rig?mr(t,r):a.parts??[]},l=t.stroke,f=t.fill,h=f.type!=="none",c=M=>!!l&&l.width>0&&M.line!==!1&&(M.fill===null||i.outline!==!1),u=Math.max(0,Math.min(1,n.end)-Math.max(0,n.start)),p=u>=1&&!n.offset,k=i.parts.map(M=>p?1:Math.max(1,Le(M.d))),E=i.parts.map((M,y)=>c(M)?k[y]:p?1:Math.max(40,k[y]*.35)),d=E.reduce((M,y)=>M+y,0)||1,A=Math.max(0,n.start)*d,w=A+u*d,g=Zt(t.id)+(o?.seed??0)*131;let _=0;i.parts.forEach((M,y)=>{const S=E[y],P=_;_=_+S;const T=p?1:Math.max(0,Math.min(1,(w-P)/S))-Math.max(0,Math.min(1,(A-P)/S));if(T<=0)return;const R=o?nn(M.d,o,r,g+y*29):rs(M.d),C=v=>{if(!c(M)||!l)return;e.globalAlpha=s*t.opacity*(l.opacity??1)*(M.o??1);const m=Le(M.d),b=p?m:m*T,O=l.width*(M.lw??1)*(v?2:1);if(l.hand){const $={...l.hand,...o?{boil:Math.max(l.hand.boil??0,o.fps)}:{}};ot(e,M.d,{color:l.color,width:O,from:p?0:Math.max(0,(A-P)/S)*m,len:b,hand:$,time:r})}else e.strokeStyle=l.color,e.lineWidth=O,e.lineCap=l.cap??"round",e.lineJoin=l.join??"round",p||!m?e.setLineDash([]):(e.setLineDash([b,m*2]),e.lineDashOffset=-Math.max(0,(A-P)/S)*m),e.stroke(R),e.setLineDash([])},I=h&&!!M.fill;if(I&&C(!0),I){if(e.globalAlpha=s*t.opacity*(f.opacity??1)*(M.o??1)*(p?1:c(M)?Mt((T-.6)/.4):Mt(T)),e.globalAlpha>0){e.fillStyle=M.fill,M.eo?e.fill(R,"evenodd"):e.fill(R);const v=f.texture;v&&(e.save(),M.eo&&e.clip(R,"evenodd"),en(e,R,os(M.d),v,M.fill,g+y),e.restore())}}else C(!1)})}const me=new Map;function os(e){let t=me.get(e);if(t)return t;const n=e.match(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi)?.map(Number)??[];let r=1/0,s=1/0,o=-1/0,a=-1/0;for(let i=0;i+1<n.length;i+=2)r=Math.min(r,n[i]),o=Math.max(o,n[i]),s=Math.min(s,n[i+1]),a=Math.max(a,n[i+1]);return t=Number.isFinite(r)?[r,s,o,a]:[-50,-50,50,50],me.size>2e3&&me.clear(),me.set(e,t),t}const re=new Map;function st(e){let t=re.get(e);if(t)return t;re.size>400&&re.clear();const n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d",e);let r=0;try{r=n.getTotalLength()}catch{r=0}if(!Number.isFinite(r)||r<=0)return t={xs:new Float32Array(0),ys:new Float32Array(0),ss:new Float32Array(0),L:0,step:1},re.set(e,t),t;const s=Math.max(1.5,r/900),o=Math.ceil(r/s)+1,a=new Float32Array(o),i=new Float32Array(o),l=new Float32Array(o);for(let f=0;f<o;f++){const h=Math.min(r,f*s),c=n.getPointAtLength(h);a[f]=c.x,i[f]=c.y,l[f]=h}return t={xs:a,ys:i,ss:l,L:r,step:s},re.set(e,t),t}const Le=e=>st(e).L,as=e=>st(e);function _t(e,t){let n=Math.imul(e^2654435769,2246822507)^Math.imul(t+1,3266489909);return n^=n>>>13,n=Math.imul(n,668265263),n^=n>>>16,(n>>>0)/4294967296*2-1}function kt(e,t){const n=Math.floor(e),r=e-n,s=r*r*(3-2*r);return _t(n,t)*(1-s)+_t(n+1,t)*s}const At=e=>{const t=Math.max(0,Math.min(1,e));return t*t*(3-2*t)};function St(e,t,n,r,s,o,a,i,l,f=0){if(r-n+1<2)return;const c=t.ss[r]-t.ss[n],u=[],p=[],k=Math.max(.001,Math.min(c*.15,s*3)),E=Math.max(.001,Math.min(c*.22,s*4));for(let d=n;d<=r;d++){const A=Math.max(n,d-1),w=Math.min(r,d+1),g=t.xs[w]-t.xs[A],_=t.ys[w]-t.ys[A],M=Math.hypot(g,_)||1,y=-_/M,S=g/M,P=t.ss[d],L=P-t.ss[n],T=kt(P/(s*3+24),a)*o.wobble*s,R=1+o.press*kt(P/(s*6+48),a+7),C=o.tip+(1-o.tip)*Math.min(At(L/k),At((c-L)/E)),I=Math.max(.15,s/2*R*C),v=t.xs[d]+y*T,m=t.ys[d]+S*T;u.push(v+y*I,m+S*I),p.push(v-y*I,m-S*I)}e.beginPath(),e.moveTo(u[0],u[1]);for(let d=2;d<u.length;d+=2)e.lineTo(u[d],u[d+1]);for(let d=p.length-2;d>=0;d-=2)e.lineTo(p[d],p[d+1]);if(e.closePath(),e.fill(),f>0){const d=e.globalAlpha;e.globalAlpha=d*f,e.lineWidth=Math.max(.4,s*.07),e.lineJoin="round",e.strokeStyle=e.fillStyle,e.stroke(),e.globalAlpha=d}}function ot(e,t,n){const r=st(t);if(!r.L||n.len<=0)return;let s=ft[n.hand.style]??En[n.hand.style]??ft.marker;(n.hand.taper!==void 0||n.hand.press!==void 0)&&(s={...s,...n.hand.taper!==void 0?{tip:Math.max(.02,1-n.hand.taper)}:{},...n.hand.press!==void 0?{press:n.hand.press*.6}:{}});const o=Math.max(.5,n.width*s.width),a=n.hand.boil?Math.floor(n.time*n.hand.boil+1e-6):0,i=(n.hand.seed??0)*131+a*977|0,l=r.L,f=Math.max(0,Math.min(l,n.from)),h=Math.min(l,n.len),c=f+h<=l+1e-6?[[f,Math.min(l,f+h)]]:[[f,l],[0,f+h-l]],u=e.globalAlpha;e.save(),e.fillStyle=s.grain?ts(e,n.color,s.grain,n.hand.seed??0):n.color;const p=s.wet?[[1,s.alpha*.5,i],[.9,s.alpha*.4,i+11],[1.08,s.alpha*.3,i+23]]:[[1,s.alpha,i]];s.retrace&&p.push([.45,s.alpha*.35,i+3]);for(const[k,E,d]of p){e.globalAlpha=u*E;for(const[A,w]of c){let g=-1;for(let _=0;_<r.ss.length;_++){const M=r.ss[_]>=A-1e-6&&r.ss[_]<=w+1e-6,y=g>=0&&_>g&&Math.hypot(r.xs[_]-r.xs[_-1],r.ys[_]-r.ys[_-1])>r.step*3;g>=0&&(!M||y)&&(St(e,r,g,_-1,o*k,s,d,!0,!0,s.wet?.5:0),g=-1),M&&g<0&&(g=_)}g>=0&&St(e,r,g,r.ss.length-1,o*k,s,d,!0,!0,s.wet?.5:0)}}e.restore()}const Mo=e=>"paths"in e?e.trim?.offset??0:0,rn=1280,Ae=720,_o=e=>e&&"size"in e&&e.size?{W:e.size[0],H:e.size[1]}:e?.square?{W:Ae,H:Ae}:{W:rn,H:Ae},Et=new Map;function sn(e){let t=Et.get(e);if(t===void 0){const n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d",e);try{t=n.getTotalLength()}catch{t=0}Et.set(e,t=Number.isFinite(t)?t:0)}return t}function ko(e,t,n,r=rn,s=Ae,o=0){const a=Math.min(r,s)/V,i=(r-V*a)/2,l=(s-V*a)/2;if(tt(t)){const c=t.step&&t.step>1?Tn(o,t.step):o,u=t.boil&&t.boil.amount>0?t.boil:null,p=t.items.map(E=>nt(E,c)),k=xn(t.items,p);e.save(),e.translate(i,l),e.scale(a,a),t.items.forEach((E,d)=>{if(E.hidden||E.span&&(o<E.span[0]-1e-6||o>=E.span[1]-1e-6))return;const A=k.get(E.id);A?(e.save(),e.transform(...A),Tt(e,p[d],n,c,a,u),e.restore()):Tt(e,p[d],n,c,a,u)}),e.restore();return}const f=Math.max(0,Math.min(1,n.end)-Math.max(0,n.start)),h=n.offset??0;e.save(),e.translate(i,l),e.scale(a,a);for(const c of t.paths){const u=new Path2D(c.d),p=c.opacity??1;if(e.filter=c.blur?`blur(${(c.blur*a).toFixed(2)}px)`:"none",c.fill&&f>0&&(e.globalAlpha=Math.min(1,f)*p,e.fillStyle=c.fill,c.rule?e.fill(u,c.rule):e.fill(u),e.globalAlpha=1),!c.stroke||f<=0)continue;if(e.globalAlpha=p,c.hand){const w=Le(c.d);ot(e,c.d,{color:c.stroke,width:c.strokeWidth??18,from:((n.start+h)%1+1)%1*w,len:f*w,hand:c.hand,time:o}),e.globalAlpha=1;continue}if(e.strokeStyle=c.stroke,e.lineWidth=c.strokeWidth??18,e.lineCap=c.cap??"round",e.lineJoin="round",f>=1&&h===0){e.setLineDash([]),e.stroke(u),e.globalAlpha=1;continue}const k=sn(c.d);if(!k)continue;const E=((n.start+h)%1+1)%1*k,d=f*k,A=Math.min(d,k-E);e.setLineDash([A,k*2]),e.lineDashOffset=-E,e.stroke(u),d>A&&(e.setLineDash([d-A,k*2]),e.lineDashOffset=0,e.stroke(u))}e.setLineDash([]),e.globalAlpha=1,e.filter="none",e.restore()}const is={add:"source-over",subtract:"destination-out",intersect:"destination-in",exclude:"xor"};function Tt(e,t,n,r,s=1,o=null){const a=o&&!t.params.d&&t.type!=="art"?ns(ct(t,r),o,r,t.id):ct(t,r),i=t.fill,l=t.stroke,f=vn(t.ops,n),h=t.params.d?o?nn(t.params.d,o,r,t.id.length*131+t.id.charCodeAt(t.id.length-1)):new Path2D(t.params.d):new Path2D(a.map(E=>Ce(E.pts,E.closed)).join(" ")),c=Math.max(0,Math.min(1,f.end)-Math.max(0,f.start)),u=f.offset??0,p=!(c>=1&&u===0),k=On(t.ops);e.save(),k&&(e.globalCompositeOperation=is[k]),e.transform(...rt(t));for(const E of Ln(t.ops)){if(e.save(),e.transform(...E.m),t.type==="art"){c>0&&ss(e,t,f,r,E.alpha,o),e.setLineDash([]),e.filter="none",e.restore();continue}if(i.type!=="none"&&c>0&&t.type!=="line"&&(e.globalAlpha=t.opacity*(i.opacity??1)*Math.min(1,c)*E.alpha,e.fillStyle=ls(e,t,r),e.fill(h),i.texture&&en(e,h,Gt(t,r),i.texture,i.color??i.stops?.[0]?.[0]??"#c6f432",t.id.length*97+t.id.charCodeAt(0))),l&&l.width>0&&c>0)if(e.globalAlpha=t.opacity*(l.opacity??1)*E.alpha,e.strokeStyle=l.color,e.lineWidth=l.width,e.lineCap=l.cap??"round",e.lineJoin=l.join??"round",e.miterLimit=10,l.blur&&(e.filter=`blur(${(l.blur*s*Math.abs(t.scale[0]||1)).toFixed(2)}px)`),l.hand){const d=o?{...l.hand,boil:Math.max(l.hand.boil??0,o.fps)}:l.hand;for(const A of t.params.d?[t.params.d]:a.map(w=>Ce(w.pts,w.closed))){const w=Le(A);ot(e,A,{color:l.color,width:l.width,from:((f.start+u)%1+1)%1*w,len:c*w,hand:d,time:r})}}else if(!p)l.dash&&l.dash[0]+l.dash[1]>0?(e.setLineDash(l.dash),e.lineDashOffset=-(l.dashOffset??0)):e.setLineDash([]),e.stroke(h);else if(t.params.d&&t.params.box){const d=sn(t.params.d);if(d){const A=((f.start+u)%1+1)%1*d,w=c*d,g=Math.min(w,d-A);e.setLineDash([g,d*2]),e.lineDashOffset=-A,e.stroke(h),w>g&&(e.setLineDash([w-g,d*2]),e.lineDashOffset=0,e.stroke(h))}}else for(const d of t.params.d?[]:a){const A=Pn(d.pts,d.closed);if(!A)continue;const w=new Path2D(Ce(d.pts,d.closed)),g=((f.start+u)%1+1)%1*A,_=c*A,M=Math.min(_,A-g),y=S=>{const P=l.dash;if(!P||P[0]+P[1]<=0)return[S,A*2];const L=P[0]+P[1],T=[];let R=0;for(let C=((l.dashOffset??0)%L+L)%L-L;C<S&&T.length<4e3;C+=L){const I=Math.max(0,C),v=Math.min(S,C+P[0]);v<=I||(T.length?T.push(I-R,v-I):(I>0&&T.push(0,I),T.push(v-I)),R=v)}return T.length?[...T,A*2]:[0,A*2]};e.setLineDash(y(M)),e.lineDashOffset=-g,e.stroke(w),_>M&&(e.setLineDash(y(_-M)),e.lineDashOffset=0,e.stroke(w))}e.setLineDash([]),e.filter="none",e.restore()}e.restore()}function ls(e,t,n){const r=t.fill;if(r.type==="color"||!r.stops)return r.color??"#c6f432";const[s,o,a,i]=Gt(t,n),l=s+(a-s)*(r.cx??.5),f=o+(i-o)*(r.cy??.5);let h;if(r.type==="radial")h=e.createRadialGradient(l,f,0,l,f,Math.max(1,Math.hypot(a-s,i-o)/2));else{const c=(r.angle??0)*Math.PI/180,u=Math.cos(c),p=Math.sin(c),k=Math.abs(u)*(a-s)/2+Math.abs(p)*(i-o)/2;h=e.createLinearGradient(l-u*k,f-p*k,l+u*k,f+p*k)}for(const[c,u]of r.stops)h.addColorStop(u,c);return h}function Ao(e,t,n,r,s){const o=-r/2,a=-s/2,i=Math.max(0,Math.min(1,n));if(e.beginPath(),t==="wipe-left")e.rect(o,a,r*i,s);else if(t==="wipe-right")e.rect(o+r*(1-i),a,r*i,s);else if(t==="wipe-down")e.rect(o,a,r,s*i);else if(t==="wipe-up")e.rect(o,a+s*(1-i),r,s*i);else if(t==="iris")e.arc(0,0,i*Math.hypot(r,s)/2,0,Math.PI*2);else if(t==="split-h")e.rect(-r*i/2,a,r*i,s);else if(t==="split-v")e.rect(o,-s*i/2,r,s*i);else if(t==="split-h-edges"){const l=r*i/2;e.rect(o,a,l,s),e.rect(r/2-l,a,l,s)}else if(t==="watercolor")if(i>=1)e.rect(o,a,r,s);else{const l=$n(i)*Math.hypot(r,s)/2;for(let f=0;f<256;f++){const h=f/256*Math.PI*2,c=l*(1+Rn(h)),u=Math.sin(h)*c,p=-Math.cos(h)*c;f?e.lineTo(u,p):e.moveTo(u,p)}e.closePath()}else if(i>=1&&/^(torn|blocks)/.test(t))e.rect(o,a,r,s);else if(t==="torn"||t==="torn-back"){const l=Cn(t==="torn"?i:1-i),f=In().map(c=>[o+(l-jn(c))*r,a+c*s]),h=t==="torn"?o-r:o+2*r;e.moveTo(h,a);for(const[c,u]of f)e.lineTo(c,u);e.lineTo(h,a+s),e.closePath()}else if(t==="blocks"||t==="blocks-back"){const l=Dn.n,f=Math.max(r,s)/800;for(let h=0;h<l;h++)for(let c=0;c<l;c++){const u=Bn(c,h);(t==="blocks"?u<i:u>=1-i)&&e.rect(o+c*r/l-f,a+h*s/l-f,r/l+2*f,s/l+2*f)}}else e.moveTo(0,0),e.arc(0,0,Math.hypot(r,s),-Math.PI/2,-Math.PI/2+i*Math.PI*2),e.closePath();e.clip()}let xt=null;const fs=()=>xt??=Promise.all(Fn.map(async e=>{const t=await fetch(e.url);if(!t.ok)throw Error(`Font ${e.url}: HTTP ${t.status}`);return{name:e.name,weight:e.weight,style:"normal",data:await t.arrayBuffer()}})).catch(e=>{throw xt=null,e});let vt=null;const cs=()=>vt??=U(()=>import("./index-D7M5t2re.js"),__vite__mapDeps([0,1,2,3])).then(e=>e.default).catch(e=>{throw vt=null,e}),hs=48,ze=new Map,We=new Map,on=(e,t,n)=>(e.set(t,n),e.size>hs&&e.delete(e.keys().next().value),n);function us(e){const t=Ht(e);return ze.get(t)??on(ze,t,(async()=>{const[n,r]=await Promise.all([cs(),fs()]);return n(Nn(e),{width:e.width,height:e.height,fonts:r})})().catch(n=>{throw ze.delete(t),n}))}const ps=e=>Math.min(2,2560/Math.max(e.width,e.height));function So(e){const t=Ht(e);return We.get(t)??on(We,t,(async()=>{const n=await us(e),r=new Image,s=ps(e);r.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`,await r.decode();const o=Object.assign(document.createElement("canvas"),{width:Math.round(e.width*s),height:Math.round(e.height*s)}),a=o.getContext("2d");if(!a)throw Error("Canvas unavailable");return a.drawImage(r,0,0,o.width,o.height),o})().catch(n=>{throw We.delete(t),n}))}const ds=Object.freeze({dark:"dark",light:"positron",atlas:"liberty",neon:"dark",lime:"dark",paper:"positron",mono:"positron",satellite:"positron"}),ms="https://tiles.maps.eox.at/wmts/1.0.0/s2cloudless_3857/default/g/{z}/{y}/{x}.jpg",gs=14,ys="EOxCloudless 2016 https://cloudless.eox.at by EOX IT Services GmbH (Contains modified Copernicus Sentinel data 2016)",ie=Object.freeze({source:"sentinel",tiles:ms,maxzoom:gs,credit:ys}),ws="Powered by Esri · Source: Esri, Vantor, GeoEye, Earthstar Geographics, CNES/Airbus DS, USDA, USGS, AeroGRID, IGN, and the GIS User Community",ge=(e,t,n,r,s,o,a,i,l,f,h,c)=>({bg:e,land:t,park:n,water:r,waterLine:s,building:o,road:a,roadMajor:i,rail:l,boundary:f,text:h,halo:c}),bs=Object.freeze({neon:ge("#070b1a","#0b1226","#0c1a2a","#02040c","#0a2a55","#121c3a","#1b3b7a","#00e5ff","#233060","#ff2fd0","#bfe9ff","#050814"),lime:ge("#0b0d0a","#0f120d","#121a10","#050605","#1d2a16","#171c13","#2a3322","#c6ff3d","#2a3322","#9bcc2e","#e9ffc4","#070806"),paper:ge("#efe4cc","#e9dcc0","#d8d3a6","#b9cfc9","#9fbab4","#dccaa5","#fbf5e6","#c98f4a","#b8a888","#8a5a3c","#4a3a28","#f4ead4"),mono:ge("#f2f2f2","#ececec","#e2e2e2","#cfcfcf","#bdbdbd","#dedede","#ffffff","#9a9a9a","#c8c8c8","#6e6e6e","#3a3a3a","#f7f7f7")}),Ms=/motorway|trunk|primary|major/;function an(e){const t=e["source-layer"]??"",n=e.id??"";return e.type==="background"?"bg":e.type==="symbol"?"label":t==="water"?"water":t==="waterway"?"waterLine":t==="park"||t==="landcover"?"park":t==="landuse"||t==="aeroway"?e.type==="line"?"road":"land":t==="building"?"building":t==="transportation"?/rail|transit/.test(n)?"rail":Ms.test(n)?"roadMajor":"road":t==="boundary"?"boundary":"other"}function _s(e,t){const n=an(e),r={...e.paint??{}};if(n==="other")return e.type==="raster"||e.type==="hillshade"?null:e;if(n==="label")return r["text-color"]=t.text,r["text-halo-color"]=t.halo,{...e,paint:r};const s=n==="bg"?t.bg:t[n];return e.type==="background"?r["background-color"]=s:e.type==="fill"?(r["fill-color"]=s,delete r["fill-pattern"],"fill-outline-color"in r&&(r["fill-outline-color"]=s)):e.type==="fill-extrusion"?(r["fill-extrusion-color"]=s,delete r["fill-extrusion-pattern"]):e.type==="line"&&(r["line-color"]=s,delete r["line-pattern"]),{...e,paint:r}}function ks(e,t=ie){const n=[];for(const r of e.layers){const s=an(r);if(s==="label")n.push({...r,paint:{...r.paint??{},"text-color":"#ffffff","text-halo-color":"rgba(0,0,0,.85)","text-halo-width":1.6}});else if(s==="boundary"&&r.type==="line"){const o=["<=",["get","admin_level"],4];n.push({...r,filter:r.filter?["all",r.filter,o]:o,paint:{...r.paint??{},"line-color":"rgba(255,255,255,.55)"}})}else s==="roadMajor"&&r.type==="line"&&n.push({...r,paint:{...r.paint??{},"line-color":"rgba(255,236,170,.22)"}})}return{...e,sources:{...e.sources,"cx-sat":{type:"raster",tiles:[t.tiles],tileSize:256,maxzoom:t.maxzoom,attribution:t.credit}},layers:[{id:"cx-sat-bg",type:"background",paint:{"background-color":"#0b0f12"}},{id:"cx-sat",type:"raster",source:"cx-sat",paint:{"raster-fade-duration":0}},...n]}}const Ot=Object.freeze({dark:"#30353f",light:"#e4e1da",atlas:"#ddd6cc",neon:"#26367a",lime:"#323d27",paper:"#dccaa5",mono:"#dcdcdc",satellite:"#d6d0c6"});function Lt(e,t=null,n=1){const r=typeof t=="string"&&/^#[0-9a-f]{6}$/i.test(t)?t:Ot[e]??Ot.dark,s=Math.max(0,Math.min(2,Number(n)||1));return"#"+[1,3,5].map(o=>Math.min(255,Math.round(parseInt(r.slice(o,o+2),16)*s)).toString(16).padStart(2,"0")).join("")}function As(e,t,n=ie){if(e==="satellite")return ks(t,n??ie);const r=bs[e];return r?{...t,layers:t.layers.map(s=>_s(s,r)).filter(Boolean)}:t}function Ss(e,t,n=ie){return e==="satellite"?[(n??ie).credit,t]:[t]}function Es(e,t,n){const r=[];for(const s of e){let o="";for(const a of String(s).split(" ")){const i=o?o+" "+a:a;o&&t(i)>n?(r.push(o),o=a):o=i}o&&r.push(o)}return r}const Ts=e=>Hn[e];function xs(e,t,n,r,s,o){Gn(e,t,n,r,s,o,Ts)}const Pt=Object.fromEntries(Object.entries(ds).map(([e,t])=>[e,`https://tiles.openfreemap.org/styles/${t}`])),vs="OpenFreeMap © OpenMapTiles · Data © OpenStreetMap contributors",Os=[110.8,15.4,113.2,17.4],Ls=[111.2,6,118,12.2],$t=([e,t,n,r])=>[[e,t],[n,t],[n,r],[e,r],[e,t]],Rt={type:"MultiPolygon",coordinates:[[$t(Os)],[$t(Ls)]]},Ps=e=>({type:"FeatureCollection",features:[{type:"Feature",properties:{name:e==="vi"?`Quần đảo Hoàng Sa
155
155
  (Việt Nam)`:`Hoang Sa Islands
156
156
  (Viet Nam)`},geometry:{type:"Point",coordinates:[112.1,16.45]}},{type:"Feature",properties:{name:e==="vi"?`Quần đảo Trường Sa
157
157
  (Việt Nam)`:`Truong Sa Islands
158
- (Viet Nam)`},geometry:{type:"Point",coordinates:[114.2,9.9]}}]});function $s(e,t="vi"){const n=structuredClone(e),s=["case",["==",["get","name:en"],"South China Sea"],t==="vi"?"Biển Đông":"East Sea (Bien Dong)",t==="vi"?["coalesce",["get","name:vi"],["get","name:latin"],["get","name"]]:["coalesce",["get","name:en"],["get","name_en"],["get","name:latin"],["get","name"]]];for(const a of n.layers)/disputed/.test(a.id)&&(a.layout={...a.layout,visibility:"none"}),a.type==="symbol"&&a.layout?.["text-field"]&&(a.layout={...a.layout,"text-field":s},a.filter=a.filter?["all",a.filter,["!",["within",Rt]]]:["!",["within",Rt]]);const o=n.layers.find(a=>a.type==="symbol"&&a.layout?.["text-font"])?.layout["text-font"]??["Noto Sans Bold"];return n.sources["cx-vn"]={type:"geojson",data:Ps(t)},n.glyphs&&n.layers.push({id:"cx-vn-islands",type:"symbol",source:"cx-vn",minzoom:3.5,layout:{"text-field":["get","name"],"text-font":o,"text-size":["interpolate",["linear"],["zoom"],4,15,8,20],"text-allow-overlap":!0},paint:{"text-color":"#e8f1ff","text-halo-color":"rgba(10,20,40,.9)","text-halo-width":1.8}}),n}const ln=e=>({source:"esri",tiles:`${location.origin}/api/geo/hd/${e.id}/{z}/{y}/{x}`,maxzoom:e.maxZoom,credit:ws}),qe=new Map;async function Rs(e,t,n=null){const r=`${e}:${t}:${n?.id??""}:${n?.maxZoom??""}`;let s=qe.get(r);return s||(s=(async()=>{const o=await fetch(Pt[e]??Pt.dark).then(a=>{if(!a.ok)throw Error(`Map style HTTP ${a.status}`);return a.json()});return $s(Ss(e,o,n&&e==="satellite"?ln(n):null),t)})(),qe.set(r,s),s.catch(()=>qe.delete(r))),s}const Cs=e=>[{id:"cx-route-glow",type:"line",source:"cx-route",layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["get","color"],"line-width":["*",["get","width"],3],"line-opacity":.28,"line-blur":6}},{id:"cx-route",type:"line",source:"cx-route",layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["get","color"],"line-width":["get","width"]}},{id:"cx-pin-ring",type:"circle",source:"cx-pins",paint:{"circle-radius":["*",13,["get","scale"]],"circle-color":["get","color"],"circle-opacity":.25}},{id:"cx-pin",type:"circle",source:"cx-pins",paint:{"circle-radius":["*",7,["get","scale"]],"circle-color":["get","color"],"circle-stroke-color":"#ffffff","circle-stroke-width":2.5}},{id:"cx-pin-label",type:"symbol",source:"cx-pins",layout:{"text-field":["get","label"],"text-font":e,"text-size":["*",22,["min",1,["get","scale"]]],"text-offset":[0,-1.5],"text-anchor":"bottom","text-allow-overlap":!0,"text-ignore-placement":!0},paint:{"text-color":"#ffffff","text-halo-color":"rgba(0,0,0,.85)","text-halo-width":2}}];let Is=null;const at=()=>Is??=Promise.all([U(()=>import("./three.module-Bx43vjkH.js"),[]),U(()=>import("./GLTFLoader-Dy6SrZg8.js").then(e=>e.a),__vite__mapDeps([4,5]))]),Ue=new Map;function Ct(e){let t=Ue.get(e);return t||(t=(async()=>{const[n,{GLTFLoader:r}]=await at(),s=await new r().loadAsync(await yr(e));s.scene.traverse(h=>{h.frustumCulled=!1});const o=new n.Box3().setFromObject(s.scene),a=o.getSize(new n.Vector3);if(!(a.y>0))throw Error("GLB không có hình học hợp lệ");const i=1/a.y,l=o.getCenter(new n.Vector3);s.scene.scale.setScalar(i),s.scene.position.set(-l.x*i,-o.min.y*i,-l.z*i);const f=new n.Group;return f.add(s.scene),f.userData.size=[a.x*i,a.z*i],f})(),Ue.set(e,t),t.catch(()=>Ue.delete(e))),t}const Ke=new Map;function js(e){let t=Ke.get(e);return t||(t=(async()=>{const[n]=await at(),r=await wr({gcsUri:e}),s=new n.TextureLoader;s.setCrossOrigin("anonymous");const o=await s.loadAsync(r);return o.colorSpace=n.SRGBColorSpace,o.anisotropy=8,o})(),Ke.set(e,t),t.catch(()=>Ke.delete(e))),t}function Ds(e,[t,n],r){const s=new e.Group,o=t*1.08,a=n*1.08,i=new e.Mesh(new e.BoxGeometry(o,.004,a),new e.MeshBasicMaterial({color:r,transparent:!0,opacity:.35,blending:e.AdditiveBlending,depthWrite:!1})),l=new e.LineSegments(new e.EdgesGeometry(new e.BoxGeometry(o,.004,a)),new e.LineBasicMaterial({color:r,transparent:!0,opacity:1,blending:e.AdditiveBlending,depthWrite:!1}));return s.add(i,l),s.traverse(f=>{f.frustumCulled=!1}),s}function Bs(e,t){let n=null;const r=new e.Scene,s=new e.Camera,o=new e.HemisphereLight(16777215,3817552,2.4);o.position.set(0,0,1),r.add(o);const a=new e.DirectionalLight(16777215,2.6);return a.position.set(.6,-.8,1.4),r.add(a),{id:"cx-models",type:"custom",renderingMode:"3d",onAdd(i,l){n=new e.WebGLRenderer({canvas:i.getCanvas(),context:l,antialias:!0}),n.autoClear=!1},render(i,l){const f=t();if(!n||!f)return;const h=new e.Matrix4().fromArray(l.defaultProjectionData.mainMatrix);n.resetState();for(const{holder:c,m:u,scale:p,cut:k,glow:E,scan:d}of f.placed.values()){if(!(p>0))continue;const{origin:S,local:w}=tr(u,p);c.matrixAutoUpdate=!1,c.matrix.fromArray(w),s.projectionMatrix.copy(h).multiply(new e.Matrix4().makeTranslation(S[0],S[1],S[2])),n.clippingPlanes=k<1?[new e.Plane(new e.Vector3(0,0,-1),Math.max(1e-12,k*w[6]))]:[],d&&(d.visible=E>0,d.position.y=k,d.traverse(g=>{const _=g.material;_&&(_.opacity=(g.type==="LineSegments"?1:.35)*E)})),r.add(c),n.render(r,s),r.remove(c),n.clippingPlanes=[]}}}}const Z=new Map;let Ns=null;const Fs=()=>Ns??=Promise.all([U(()=>import("./maplibre-gl-Dngacpy6.js"),[]),U(()=>import("./maplibre-gl-worker-CD34yISW.js"),[])]).then(([e,t])=>(e.setWorkerUrl(t.default),e));async function Gs(e,t,n,r,s=null){const[o,a]=await Promise.all([Fs(),Rs(e,t,s)]),i=Object.assign(document.createElement("div"),{className:"tl-geo-offscreen"});Object.assign(i.style,{position:"fixed",left:"-20000px",top:"0",width:`${n}px`,height:`${r}px`,pointerEvents:"none"}),document.body.appendChild(i);const l=new o.Map({container:i,style:a,interactive:!1,attributionControl:!1,fadeDuration:0,pixelRatio:1,maxPitch:Math.max(60,Zn.maxPitch),canvasContextAttributes:{preserveDrawingBuffer:!0,antialias:!0},center:[0,0],zoom:1});await new Promise((c,u)=>{const p=setTimeout(()=>u(Error("Bản đồ không tải được (hết thời gian)")),2e4);l.once("load",()=>{clearTimeout(p),c()}),l.once("error",k=>{l.loaded()||(clearTimeout(p),u(Error(String(k.error?.message??"map error"))))})});const f=a.layers.find(c=>c.type==="symbol"&&c.layout?.["text-font"])?.layout["text-font"]??["Noto Sans Bold"];l.addSource("cx-route",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),l.addSource("cx-pins",{type:"geojson",data:{type:"FeatureCollection",features:[]}});for(const c of Cs(f))(c.type!=="symbol"||a.glyphs)&&l.addLayer(c);const h={map:l,canvas:l.getCanvas(),box:i,style:e,W:n,H:r,placed:new Map,three:(await at())[0],city:""};return l.addLayer(Bs(h.three,()=>h),l.getLayer("cx-pin-ring")?"cx-pin-ring":void 0),h}const Y="cx-buildings",It=new WeakMap;function Hs(e){return e.getStyle().layers.filter(t=>t["source-layer"]==="building"&&t.id!==Y)}function zs(e,t,n){const{map:r}=e,s=t?`${t.color??""}:${t.opacity}:${t.light}`:"";if(s!==e.city){const o=Hs(r),a=It.get(e)??new Map(o.map(i=>[i.id,i.layout?.visibility??"visible"]));It.set(e,a),r.getLayer(Y)&&r.removeLayer(Y);for(const i of o)r.setLayoutProperty(i.id,"visibility",t?"none":a.get(i.id)??"visible");if(t){const i=o[0]?.source??Object.entries(r.getStyle().sources).find(([,l])=>l.type==="vector")?.[0];if(i){const l=Qn(t.light,e.style),f=r.getStyle().layers.find(h=>h.type==="symbol")?.id;r.addLayer({id:Y,type:"fill-extrusion",source:i,"source-layer":"building",minzoom:13,filter:["!=",["get","hide_3d"],!0],paint:{"fill-extrusion-color":l.top&&!t.color?["interpolate",["linear"],["coalesce",["get","render_height"],0],0,Lt(e.style,null,l.tint),220,l.top]:Lt(e.style,t.color,l.tint),"fill-extrusion-opacity":t.opacity,"fill-extrusion-vertical-gradient":!0,"fill-extrusion-height":0,"fill-extrusion-base":0}},f),r.setLight(l.light),r.setSky(l.sky)}}else r.setSky({});e.city=s}if(t&&r.getLayer(Y)){const o=t.height*n;r.setPaintProperty(Y,"fill-extrusion-height",["*",["max",["coalesce",["get","render_height"],0],6],o]),r.setPaintProperty(Y,"fill-extrusion-base",["*",["coalesce",["get","render_min_height"],0],o])}}function Ws(e,t){return new Promise(n=>{const r=()=>{clearTimeout(s),n()},s=setTimeout(r,t);e.once("idle",r),e.triggerRepaint()})}async function Eo(e,t,n,r,s,{wait:o=2e4,lang:a="vi",duration:i=1/0,live:l=!1}={}){const f=zn(t,i)?t.hd:null,h=`${t.style}:${a}:${n.W}x${n.H}:${f?.id??""}`,c=Z.get(e);let u=c?.p;if(!c||c.sig!==h){c&&c.p.then(fn,()=>{});const y=Gs(t.style,a,n.W,n.H,f);u=y,Z.set(e,{sig:h,p:y}),y.catch(()=>{Z.get(e)?.p===y&&Z.delete(e)})}const p=await u,{map:k}=p;Re.set(e,{pl:p,W:n.W,H:n.H});const E=new Set;for(const[y,A]of(t.models??[]).entries()){const P=Wn(A,r),L=`${y}:${A.gcsUri}`;E.add(L);let T=p.placed.get(L);if(!T){const R=await Ct(A.gcsUri);T={holder:new p.three.Group().add(R.clone(!0)),m:A,scale:0,cut:1,glow:0},p.placed.set(L,T)}if(A.reveal==="build"&&!T.scan){const R=await Ct(A.gcsUri);T.scan=Ds(p.three,R.userData.size??[1,1],A.color??"#5ef3ff"),T.holder.add(T.scan)}T.m=A,T.scale=P?P.scale:0,T.cut=P?.cut??1,T.glow=P?.glow??0}const d=fe(t,r,[n.W,n.H]).bearing??0;for(const[y,A]of(t.images??[]).entries()){const P=qn(A,r),L=`img:${y}:${A.gcsUri}`;E.add(L);let T=p.placed.get(L);if(!T){const C=p.three,I=await js(A.gcsUri),v=I.image,m=v?.width&&v?.height?v.height/v.width:A.aspect,b=new C.MeshBasicMaterial({map:I,transparent:!0,side:C.DoubleSide,alphaTest:.03,toneMapped:!1}),O=new C.Mesh(new C.PlaneGeometry(1,m).translate(0,m/2,0),b);O.frustumCulled=!1;const $=new C.Group().add(O);T={holder:new C.Group().add($),m:{at:A.at,height:A.width,rotation:0},scale:0,cut:1,glow:0,tilter:$,aspect:m,mat:b},p.placed.set(L,T)}const R=(P?.tilt??A.tilt)*Math.PI/180;T.tilter.rotation.x=-(Math.PI/2-R),T.tilter.position.z=T.aspect/2*Math.cos(R),T.mat.opacity=P?.alpha??0,T.m={at:A.at,height:A.width,rotation:(A.face==="camera"?d:0)+A.rotation},T.scale=P?P.scale:0}for(const y of[...p.placed.keys()])E.has(y)||p.placed.delete(y);k.jumpTo(fe(t,r,[n.W,n.H])),zs(p,t.buildings,Un(t,r)?.k??0);const S=Kn(t,r),w=t.route?.look==="saber"||t.route?.look==="electric"||t.route?.look==="trail";k.getSource("cx-route").setData({type:"FeatureCollection",features:S&&t.route&&!w?[{type:"Feature",properties:{color:t.route.color,width:t.route.width},geometry:{type:"LineString",coordinates:S}}]:[]}),k.getSource("cx-pins").setData({type:"FeatureCollection",features:Vn(t,r).map(y=>({type:"Feature",properties:{label:y.label,color:y.color,scale:y.scale},geometry:{type:"Point",coordinates:y.at}}))}),t.route&&!w&&k.setPaintProperty("cx-route","line-dasharray",t.route.look==="dashed"?[2,1.5]:[1,0]),l?k.redraw():await Ws(k,o);const g=s.getContext("2d");if(!g)return;g.clearRect(0,0,s.width,s.height),g.drawImage(p.canvas,0,0,s.width,s.height);const _=y=>{const A=k.project(y);return[A.x*s.width/n.W,A.y*s.height/n.H]};for(const y of t.areas??[]){const A=Jn(y,r);if(!A)continue;const P=y.paths.map(T=>T.map(_));if(A.fill>0){g.save(),g.fillStyle=y.color,g.globalAlpha=A.fill,g.beginPath();for(const T of P){g.moveTo(T[0][0],T[0][1]);for(const R of T.slice(1))g.lineTo(R[0],R[1]);g.closePath()}g.fill("evenodd"),g.restore()}const L=y.width*s.width/n.W;for(const[T,R]of A.paths.entries()){const C=R.map(_);if(y.look==="line"||y.look==="dashed"){g.save(),g.strokeStyle=y.color,g.lineWidth=L,g.lineJoin="round",g.setLineDash(y.look==="dashed"?[L*3,L*2]:[]),g.beginPath(),g.moveTo(C[0][0],C[0][1]);for(const I of C.slice(1))g.lineTo(I[0],I[1]);g.stroke(),g.restore()}else ye(g,y.look==="electric"?Ie(C,r,{amp:L*1.6,step:L*4,seed:3+T}):C,y.color,L,ce(r+T*.13),A.done||T>0)}}if(t.route?.look==="trail"&&r>=t.route.start){const y=fe(t,r,[n.W,n.H]),A=Math.max(30,ht(y.zoom,y.center[1])*t.route.width*16);qs(g,Yn(t.route.points,9,A).map(P=>P.map(_)),t.route,r,t.route.width*s.width/n.W)}else if(w&&S&&t.route){const y=s.width/n.W,A=s.height/n.H,P=S.map(L=>{const T=k.project(L);return[T.x*y,T.y*A]});if(t.route.look==="electric"){const L=t.route.width*y;ye(g,Ie(P,r,{amp:L*1.8,step:L*3,seed:1}),t.route.color,L,ce(r),!1),ye(g,Ie(P,r,{amp:L*2.6,step:L*2.2,seed:7}),t.route.color,L*.45,ce(r+.37)*.8,!0)}else ye(g,P,t.route.color,t.route.width*y,ce(r))}if(t.icons?.length){const y=fe(t,r,[n.W,n.H]),A=s.height/720,P=ht(y.zoom,y.center[1])*n.H/720,L=t.icons.map(v=>({ic:v,st:Xn(v,r),p:_(v.at)})).filter(v=>v.st&&v.p[0]>-240*A&&v.p[0]<s.width+240*A&&v.p[1]>-60*A&&v.p[1]<s.height+260*A),T=v=>v==="tag"||v==="beacon"||v==="sign",R=new Map(t.icons.map((v,m)=>[v,m])),C=[],I=new Set;for(const v of[...L].sort((m,b)=>Number(T(b.ic.look))-Number(T(m.ic.look))||m.ic.show-b.ic.show||R.get(m.ic)-R.get(b.ic))){if(!v.ic.label&&!v.ic.sub){I.add(v);continue}const m=A*v.ic.size,b=Math.max(70,Math.max(v.ic.label?.length??0,v.ic.sub?.length??0)*8.4)*m,O=v.p[1]-(T(v.ic.look)?130:100)*m,$=[v.p[0]-(T(v.ic.look)?16*m:b/2),O,v.p[0]+(T(v.ic.look)?b:b/2),v.p[1]-(T(v.ic.look)?60:52)*m];C.some(D=>$[0]<D[2]&&$[2]>D[0]&&$[1]<D[3]&&$[3]>D[1])||(C.push($),I.add(v))}for(const v of L.sort((m,b)=>m.p[1]-b.p[1])){const{ic:m,st:b,p:O}=v,$=P*70*m.size,D=Math.cos(m.at[1]*Math.PI/180),H=X=>Array.from({length:40},(it,un)=>{const lt=un/40*Math.PI*2;return _([m.at[0]+$*X*Math.cos(lt)/(111320*D),m.at[1]+$*X*Math.sin(lt)/111320])});xs(g,m,I.has(v)?b:{...b,label:0},O,A*m.size,H)}}const M=er(r);if(M>0){const y=Math.max(10,Math.round(s.height/60));g.save(),g.globalAlpha=M,g.font=`500 ${y}px system-ui, sans-serif`,g.textAlign="right",g.textBaseline="bottom",g.shadowColor="rgba(0,0,0,.8)",g.shadowBlur=y*.35,g.fillStyle="rgba(255,255,255,.92)",Es(As(t.style,vs,f?ln(f):null),A=>g.measureText(A).width,s.width-y*1.2).reverse().forEach((A,P)=>g.fillText(A,s.width-y*.6,s.height-y*.4-P*y*1.35)),g.restore()}}function ye(e,t,n,r,s=1,o=!1){if(t.length<2)return;const a=()=>{e.beginPath(),e.moveTo(t[0][0],t[0][1]);for(const u of t.slice(1))e.lineTo(u[0],u[1])};e.save(),e.globalCompositeOperation="lighter",e.lineCap="round",e.lineJoin="round";const i=[[14,34,.14],[7,18,.26],[3.6,8,.5],[1.9,3,.85]];for(const[u,p,k]of i)e.filter=`blur(${p*Math.max(.6,r/5)}px)`,e.strokeStyle=n,e.globalAlpha=Math.min(1,k*s),e.lineWidth=r*u,a(),e.stroke();if(e.filter="none",e.globalAlpha=1,e.strokeStyle="#ffffff",e.lineWidth=Math.max(1.2,r*.55),a(),e.stroke(),o){e.restore();return}const[l,f]=t[t.length-1],h=r*4.5*s,c=e.createRadialGradient(l,f,0,l,f,h);c.addColorStop(0,"rgba(255,255,255,1)"),c.addColorStop(.25,n),c.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=c,e.beginPath(),e.arc(l,f,h,0,Math.PI*2),e.fill(),e.restore()}function Ve(e,t,n){const r=[0];for(let f=1;f<e.length;f++)r.push(r[f-1]+Math.hypot(e[f][0]-e[f-1][0],e[f][1]-e[f-1][1]));const s=r[r.length-1];if(!(s>0)||n<=t)return[];const o=f=>{let h=1;for(;h<r.length-1&&r[h]<f;)h++;const c=(f-r[h-1])/(r[h]-r[h-1]||1);return[e[h-1][0]+(e[h][0]-e[h-1][0])*c,e[h-1][1]+(e[h][1]-e[h-1][1])*c]},a=t*s,i=n*s,l=[o(a)];for(let f=1;f<e.length-1;f++)r[f]>a&&r[f]<i&&l.push(e[f]);return l.push(o(i)),l}function qs(e,t,n,r,s){if(t.length<2)return;const o=c=>{if(c.length<2)return!1;e.beginPath(),e.moveTo(c[0][0],c[0][1]);for(const u of c.slice(1))e.lineTo(u[0],u[1]);return!0},a=Math.max(1,s*.3),i=t[t.length>>1],l=i.length>>1,f=Math.hypot(t[0][l][0]-t[t.length-1][l][0],t[0][l][1]-t[t.length-1][l][1]);e.save(),e.globalCompositeOperation="lighter",e.lineCap="round",e.lineJoin="round";const h=ut(n,t.length>>1,r);h&&o(Ve(i,0,h.drawn))&&(e.filter=`blur(${Math.max(2,f*.45)}px)`,e.strokeStyle=n.color,e.globalAlpha=.1,e.lineWidth=f*1.15,e.stroke(),e.filter="none"),t.forEach((c,u)=>{const p=ut(n,u,r);if(!p)return;const k=a*(u%3===1?1.6:1);o(Ve(c,0,p.drawn))&&(e.globalCompositeOperation="source-over",e.strokeStyle=n.color,e.filter=`blur(${k}px)`,e.globalAlpha=.45,e.lineWidth=k*2.2,e.stroke(),e.filter="none",e.globalAlpha=1,e.lineWidth=k,e.stroke(),e.globalCompositeOperation="lighter"),p.streak&&o(Ve(c,p.streak.a,p.streak.b))&&(e.strokeStyle="#fff6cf",e.filter=`blur(${k}px)`,e.globalAlpha=.75,e.lineWidth=k*2.6,e.stroke(),e.filter="none",e.globalAlpha=1,e.lineWidth=k*1.4,e.stroke())}),e.restore()}function fn(e){try{e.map.remove()}catch{}e.box.remove()}function To(e){Re.delete(e);const t=Z.get(e);t&&(Z.delete(e),t.p.then(fn,()=>{}))}const Re=new Map;function xo(e,t,n){const r=Re.get(e);if(!r)return null;const s=r.pl.map.unproject([t*r.W,n*r.H]);return Number.isFinite(s.lng)&&Number.isFinite(s.lat)?[+s.lng.toFixed(6),+s.lat.toFixed(6)]:null}function vo(e,t){const n=Re.get(e);if(!n)return null;const r=n.pl.map.project(t);return[r.x/n.W,r.y/n.H]}const jt=e=>Math.round(e*1e4)/1e4,cn=e=>e?.square?{SW:720,SH:720}:{SW:1280,SH:720};function Us(e,t,n,r,[s,o]){const{SW:a,SH:i}=cn(e.shape),l=Math.min(a,i)/V,f=(a-V*l)/2+s*l,h=(i-V*l)/2+o*l,c=we(e,f/a,h/i,t,n,r,a,i);return[c.px,c.py]}function Ks(e,t,n,r,s,o){const{SW:a,SH:i}=cn(e.shape),l=Math.min(a,i)/V,f=or(e,s,o,t,n,r,a,i);return[(f.u*a-(a-V*l)/2)/l,(f.v*i-(i-V*l)/2)/l]}const Vs=e=>tt(e)&&e.items.some(t=>t.pins&&Object.keys(t.pins).length);function Oo(e,t,n,r=1280,s=720){const o=e.shape;return Vs(o)?{...o,items:o.items.map(a=>{if(!a.pins||!a.params.pts)return a;const i=nt(a,n,{motion:!1}),l=nr(rt(i)),f=i.params.pts.map((u,p)=>{const k=a.pins[p]!==void 0&&t.find(S=>S.id===a.pins[p]&&rr(S));if(!k)return u;const E=sr(k,Math.max(0,Math.min(k.duration,e.start+n-k.start)),r,s),d=zt(l,...Ks(e,n,r,s,r/2+E.x*r,s/2+E.y*s));return u.length===6?[d[0],d[1],...u.slice(2)]:d}),{keys:h,...c}=i;return{...c,params:{...i.params,pts:f}}})}:o}function Lo(e,t,n,r,s,o,{chain:a=!1,makeId:i,labels:l}){if(!tt(t.shape))throw Error("Chọn một layer Shape");const f=t.shape.items.find(d=>d.id===n);if(!f||f.type!=="path"||!f.params.pts)throw Error("Chọn một đường Pen trong layer Shape");const h=nt(f,r,{motion:!1}),c=h.params.pts,u=rt(h);if(a&&c.length<2)throw Error("Đường cần ít nhất 2 điểm");if(c.length>32)throw Error("Đường có quá nhiều điểm (tối đa 32)");let p=[...e];const k=[],E={};return c.forEach((d,S)=>{const[w,g]=Us(t,r,s,o,zt(u,d[0],d[1]));let _=ar({id:i(S),track:t.track,start:t.start,duration:t.duration,label:l(S)});if(_={..._,...oe(_,"x",jt((w-s/2)/s),0)},_={..._,...oe(_,"y",jt((g-o/2)/o),0)},p=[...p,_],a&&S>0){const M=k[S-1].id;_={..._,...ir(p,_,M,Math.max(0,Math.min(_.duration,r)),s,o)},p=p.map(y=>y.id===_.id?_:y)}k.push(_),E[S]=_.id}),lr(e),{nulls:k,shape:{...t.shape,items:t.shape.items.map(d=>d.id===n?{...d,pins:E}:d)}}}function Po(e,t,n,r,s,o,a){if(["x","y","zoom"].some(b=>fr(e,b)))throw Error("Layer có key vị trí / tỉ lệ: bỏ key trước khi cắt sát nội dung");const i=e.crop??{left:0,right:0,top:0,bottom:0},l={left:Math.max(i.left,t.left),top:Math.max(i.top,t.top),right:Math.max(i.right,t.right),bottom:Math.max(i.bottom,t.bottom)};if(1-l.left-l.right<.02||1-l.top-l.bottom<.02)throw Error("Không tìm thấy nội dung để cắt");if(["left","top","right","bottom"].every(b=>Math.abs(l[b]-i[b])<1e-4))throw Error("Layer đã sát nội dung");const f=b=>Math.round(b*1e4)/1e4,h=Object.fromEntries(Object.entries(l).map(([b,O])=>[b,f(O)])),c=1-i.left-i.right,u=1-i.top-i.bottom,p=b=>(b-i.left)/c,k=b=>(b-i.top)/u,E=[[p(l.left),k(l.top)],[p(1-l.right),k(l.top)],[p(1-l.right),k(1-l.bottom)]].map(([b,O])=>we(e,b,O,n,r,s,o,a)),d=b=>Math.hypot(b[1].px-b[0].px,b[1].py-b[0].py),S=b=>[(b[0].px+b[2].px)/2,(b[0].py+b[2].py)/2];let w={...e,crop:h};const g=[[0,0],[1,0],[1,1]].map(([b,O])=>we(w,b,O,n,r,s,o,a)),_=je(e,"zoom",n)*d(E)/d(g);if(!(_>0)||_>pt)throw Error(`Cắt sát nội dung cần tỉ lệ layer ngoài giới hạn (tối đa ${pt*100}%)`);w={...w,...oe(w,"zoom",f(_),n)};const M=[[0,0],[1,0],[1,1]].map(([b,O])=>we(w,b,O,n,r,s,o,a)),[y,A]=S(E),[P,L]=S(M),T=cr(e,e.start+n,r,s),R=-T.rot*Math.PI/180,C=(y-P)/(T.zoom||1),I=(A-L)/(T.zoom||1),v=C*Math.cos(R)-I*Math.sin(R),m=C*Math.sin(R)+I*Math.cos(R);return w={...w,...oe(w,"x",f(je(e,"x",n)+v/r),n)},w={...w,...oe(w,"y",f(je(e,"y",n)+m/s),n)},{crop:h,...Object.fromEntries(Object.keys(w).filter(b=>w[b]!==e[b]&&b!=="crop").map(b=>[b,w[b]]))}}function $o(e,t,n,{alpha:r=8,dark:s=16}={}){let o=!1;for(let c=3;c<e.length;c+=4)if(e[c]<250){o=!0;break}const a=c=>o?e[c+3]>r:Math.max(e[c],e[c+1],e[c+2])>s;let i=t,l=n,f=-1,h=-1;for(let c=0;c<n;c++)for(let u=0;u<t;u++)a((c*t+u)*4)&&(u<i&&(i=u),u>f&&(f=u),c<l&&(l=c),c>h&&(h=c));return f<0?null:{left:i/t,top:l/n,right:(t-1-f)/t,bottom:(n-1-h)/n}}const Pe=5*1024*1024,$e=10*1024*1024,Js=200,Ys="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==",Xs=/^data:image\/(png|jpe?g|webp|gif);base64,[A-Za-z0-9+/=\s]*$/,se=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Zs(e){if(!se(e))throw W("Not a Lottie animation");const t=structuredClone(e),{w:n,h:r,fr:s,ip:o,op:a}=t;if(!Array.isArray(t.layers)||!t.layers.length)throw W("Not a Lottie animation (no layers)");const i=ur({w:Math.round(n),h:Math.round(r),fr:s,ip:o,op:a});if(t.assets!==void 0&&!Array.isArray(t.assets))throw W("Invalid Lottie assets");const l={expressions:0,assets:0,fonts:0},f=[[t,0]];for(;f.length;){const[h,c]=f.pop();if(c>Js)throw W("Lottie file is nested too deeply");if(Array.isArray(h)){for(const u of h)u&&typeof u=="object"&&f.push([u,c+1]);continue}typeof h.x=="string"&&(delete h.x,l.expressions++);for(const u of Object.keys(h)){const p=h[u];p&&typeof p=="object"&&f.push([p,c+1])}}for(const h of t.assets||[]){if(!se(h))throw W("Invalid Lottie assets");Array.isArray(h.layers)||h.p!==void 0&&((typeof h.p!="string"||!Xs.test(h.p))&&(h.p=Ys,l.assets++),h.u="",h.e=1)}if(se(t.fonts)&&Array.isArray(t.fonts.list))for(const h of t.fonts.list)se(h)&&(h.fPath!==void 0&&(delete h.fPath,l.fonts++),h.fOrigin="n",h.origin=0);return{data:t,meta:i,removed:l}}const et=e=>new TextDecoder("utf-8",{fatal:!0}).decode(e),Qs=e=>{let t="";for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)},eo=e=>e.length>4&&e[0]===80&&e[1]===75&&e[2]===3&&e[3]===4,to={png:"png",jpg:"jpeg",jpeg:"jpeg",webp:"webp",gif:"gif"};function no(e){if(e.length>$e)throw W("Lottie file is too large");let t;try{t=hr(e,{filter:i=>i.originalSize<=Pe&&(i.name==="manifest.json"||/^(animations|a|images|i)\/[^/]+$/.test(i.name))})}catch{throw W("Invalid .lottie file")}let n=0;for(const i of Object.values(t))if(n+=i.length,i.length>Pe||n>$e*2)throw W("Lottie file is too large");let r=null;if(t["manifest.json"])try{const i=JSON.parse(et(t["manifest.json"]));r=Array.isArray(i?.animations)&&typeof i.animations[0]?.id=="string"?i.animations[0].id:null}catch{}const s=Object.keys(t).filter(i=>/^(animations|a)\/[^/]+\.json$/.test(i)).sort(),o=r&&s.find(i=>i===`animations/${r}.json`||i===`a/${r}.json`)||s[0];if(!o)throw W("No animation in the .lottie file");const a=JSON.parse(et(t[o]));for(const i of Array.isArray(a?.assets)?a.assets:[]){if(!se(i)||typeof i.p!="string"||i.e===1||i.p.startsWith("data:"))continue;const l=t[`images/${i.p}`]??t[`i/${i.p}`],f=to[i.p.split(".").pop()?.toLowerCase()??""];l&&f&&(i.p=`data:image/${f};base64,${Qs(l)}`,i.u="",i.e=1)}return a}function hn(e){if(!(e instanceof Uint8Array))throw W("Not a Lottie animation");let t;if(eo(e))t=no(e);else{if(e.length>Pe)throw W("Lottie file is too large");try{t=JSON.parse(et(e))}catch{throw W("Not a Lottie animation")}}const n=Zs(t),r=JSON.stringify(n.data);if(r.length>Pe)throw W("Lottie file is too large");return{...n,text:r}}const Je=new Map;function ro(e){let t=Je.get(e);return t||(t=(async()=>{const n=await fetch(e);if(!n.ok)throw Error(`HTTP ${n.status}`);if(Number(n.headers.get("content-length"))>$e)throw Error("Lottie file is too large");return hn(new Uint8Array(await n.arrayBuffer())).data})(),Je.set(e,t),t.catch(()=>Je.delete(e))),t}const Q=new Map;let so=null;const oo=()=>so??=U(()=>import("./lottie_light_canvas-7iv3btPX.js").then(e=>e.l),__vite__mapDeps([6,1,2])).then(e=>e.default),ao=()=>({play(){},seek(){},playing(){},rate(){},setVolume(){}});async function io(e,t,n){const[r,s]=await Promise.all([oo(),ro(e)]),o=Object.assign(document.createElement("canvas"),{width:t,height:n}),a=o.getContext("2d");if(!a)throw Error("Canvas unavailable");const i=r.loadAnimation({renderer:"canvas",loop:!1,autoplay:!1,animationData:structuredClone(s),audioFactory:ao,rendererSettings:{context:a,clearCanvas:!0,preserveAspectRatio:"xMidYMid meet",dpr:1}});return i.isLoaded||await new Promise(l=>{const f=setTimeout(l,8e3);i.addEventListener("DOMLoaded",()=>{clearTimeout(f),l()})}),{canvas:o,anim:i}}async function Ro(e,t,n,r,s){const o=Q.get(e);let a=o?.p;if(!o||o.url!==t||o.W!==n.W||o.H!==n.H){o&&o.p.then(h=>h.anim.destroy(),()=>{});const f=io(t,n.W,n.H);a=f,Q.set(e,{url:t,W:n.W,H:n.H,p:f}),f.catch(()=>{Q.get(e)?.p===f&&Q.delete(e)})}const i=await a;i.anim.goToAndStop(r,!0);const l=s.getContext("2d");l&&(l.clearRect(0,0,s.width,s.height),l.drawImage(i.canvas,0,0,s.width,s.height))}function Co(e){const t=Q.get(e);t&&(Q.delete(e),t.p.then(n=>n.anim.destroy(),()=>{}))}async function Io(e){if(e.size>$e)throw Error("Lottie file is too large");const t=hn(new Uint8Array(await e.arrayBuffer())),n=`${e.name.replace(/\.(json|lottie)$/i,"")||"lottie"}.json`;return{file:new File([t.text],n,{type:"application/json"}),meta:t.meta,removed:t.removed}}const jo=e=>/\.(json|lottie)$/i.test(e.name)||e.type==="application/json"||e.type==="application/zip+dotlottie";export{B as A,hn as B,ho as C,uo as D,go as E,yo as F,ro as G,Pe as L,rn as S,ko as a,xs as b,us as c,bo as d,To as e,Eo as f,vo as g,xo as h,Vs as i,Ao as j,Co as k,Ro as l,wo as m,So as n,Se as o,Oo as p,$o as q,Lo as r,_o as s,Mo as t,Po as u,jo as v,Io as w,mo as x,po as y,Rr as z};
158
+ (Viet Nam)`},geometry:{type:"Point",coordinates:[114.2,9.9]}}]});function $s(e,t="vi"){const n=structuredClone(e),s=["case",["==",["get","name:en"],"South China Sea"],t==="vi"?"Biển Đông":"East Sea (Bien Dong)",t==="vi"?["coalesce",["get","name:vi"],["get","name:latin"],["get","name"]]:["coalesce",["get","name:en"],["get","name_en"],["get","name:latin"],["get","name"]]];for(const a of n.layers)/disputed/.test(a.id)&&(a.layout={...a.layout,visibility:"none"}),a.type==="symbol"&&a.layout?.["text-field"]&&(a.layout={...a.layout,"text-field":s},a.filter=a.filter?["all",a.filter,["!",["within",Rt]]]:["!",["within",Rt]]);const o=n.layers.find(a=>a.type==="symbol"&&a.layout?.["text-font"])?.layout["text-font"]??["Noto Sans Bold"];return n.sources["cx-vn"]={type:"geojson",data:Ps(t)},n.glyphs&&n.layers.push({id:"cx-vn-islands",type:"symbol",source:"cx-vn",minzoom:3.5,layout:{"text-field":["get","name"],"text-font":o,"text-size":["interpolate",["linear"],["zoom"],4,15,8,20],"text-allow-overlap":!0},paint:{"text-color":"#e8f1ff","text-halo-color":"rgba(10,20,40,.9)","text-halo-width":1.8}}),n}const ln=e=>({source:"esri",tiles:`${location.origin}/api/geo/hd/${e.id}/{z}/{y}/{x}`,maxzoom:e.maxZoom,credit:ws}),qe=new Map;async function Rs(e,t,n=null){const r=`${e}:${t}:${n?.id??""}:${n?.maxZoom??""}`;let s=qe.get(r);return s||(s=(async()=>{const o=await fetch(Pt[e]??Pt.dark).then(a=>{if(!a.ok)throw Error(`Map style HTTP ${a.status}`);return a.json()});return $s(As(e,o,n&&e==="satellite"?ln(n):null),t)})(),qe.set(r,s),s.catch(()=>qe.delete(r))),s}const Cs=e=>[{id:"cx-route-glow",type:"line",source:"cx-route",layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["get","color"],"line-width":["*",["get","width"],3],"line-opacity":.28,"line-blur":6}},{id:"cx-route",type:"line",source:"cx-route",layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["get","color"],"line-width":["get","width"]}},{id:"cx-pin-ring",type:"circle",source:"cx-pins",paint:{"circle-radius":["*",13,["get","scale"]],"circle-color":["get","color"],"circle-opacity":.25}},{id:"cx-pin",type:"circle",source:"cx-pins",paint:{"circle-radius":["*",7,["get","scale"]],"circle-color":["get","color"],"circle-stroke-color":"#ffffff","circle-stroke-width":2.5}},{id:"cx-pin-label",type:"symbol",source:"cx-pins",layout:{"text-field":["get","label"],"text-font":e,"text-size":["*",22,["min",1,["get","scale"]]],"text-offset":[0,-1.5],"text-anchor":"bottom","text-allow-overlap":!0,"text-ignore-placement":!0},paint:{"text-color":"#ffffff","text-halo-color":"rgba(0,0,0,.85)","text-halo-width":2}}];let Is=null;const at=()=>Is??=Promise.all([U(()=>import("./three.module-Bx43vjkH.js"),[]),U(()=>import("./GLTFLoader-BHWu1lKg.js").then(e=>e.a),__vite__mapDeps([4,5]))]),Ue=new Map;function Ct(e){let t=Ue.get(e);return t||(t=(async()=>{const[n,{GLTFLoader:r}]=await at(),s=await new r().loadAsync(await yr(e));s.scene.traverse(h=>{h.frustumCulled=!1});const o=new n.Box3().setFromObject(s.scene),a=o.getSize(new n.Vector3);if(!(a.y>0))throw Error("GLB không có hình học hợp lệ");const i=1/a.y,l=o.getCenter(new n.Vector3);s.scene.scale.setScalar(i),s.scene.position.set(-l.x*i,-o.min.y*i,-l.z*i);const f=new n.Group;return f.add(s.scene),f.userData.size=[a.x*i,a.z*i],f})(),Ue.set(e,t),t.catch(()=>Ue.delete(e))),t}const Ke=new Map;function js(e){let t=Ke.get(e);return t||(t=(async()=>{const[n]=await at(),r=await wr({gcsUri:e}),s=new n.TextureLoader;s.setCrossOrigin("anonymous");const o=await s.loadAsync(r);return o.colorSpace=n.SRGBColorSpace,o.anisotropy=8,o})(),Ke.set(e,t),t.catch(()=>Ke.delete(e))),t}function Ds(e,[t,n],r){const s=new e.Group,o=t*1.08,a=n*1.08,i=new e.Mesh(new e.BoxGeometry(o,.004,a),new e.MeshBasicMaterial({color:r,transparent:!0,opacity:.35,blending:e.AdditiveBlending,depthWrite:!1})),l=new e.LineSegments(new e.EdgesGeometry(new e.BoxGeometry(o,.004,a)),new e.LineBasicMaterial({color:r,transparent:!0,opacity:1,blending:e.AdditiveBlending,depthWrite:!1}));return s.add(i,l),s.traverse(f=>{f.frustumCulled=!1}),s}function Bs(e,t){let n=null;const r=new e.Scene,s=new e.Camera,o=new e.HemisphereLight(16777215,3817552,2.4);o.position.set(0,0,1),r.add(o);const a=new e.DirectionalLight(16777215,2.6);return a.position.set(.6,-.8,1.4),r.add(a),{id:"cx-models",type:"custom",renderingMode:"3d",onAdd(i,l){n=new e.WebGLRenderer({canvas:i.getCanvas(),context:l,antialias:!0}),n.autoClear=!1},render(i,l){const f=t();if(!n||!f)return;const h=new e.Matrix4().fromArray(l.defaultProjectionData.mainMatrix);n.resetState();for(const{holder:c,m:u,scale:p,cut:k,glow:E,scan:d}of f.placed.values()){if(!(p>0))continue;const{origin:A,local:w}=tr(u,p);c.matrixAutoUpdate=!1,c.matrix.fromArray(w),s.projectionMatrix.copy(h).multiply(new e.Matrix4().makeTranslation(A[0],A[1],A[2])),n.clippingPlanes=k<1?[new e.Plane(new e.Vector3(0,0,-1),Math.max(1e-12,k*w[6]))]:[],d&&(d.visible=E>0,d.position.y=k,d.traverse(g=>{const _=g.material;_&&(_.opacity=(g.type==="LineSegments"?1:.35)*E)})),r.add(c),n.render(r,s),r.remove(c),n.clippingPlanes=[]}}}}const Z=new Map;let Ns=null;const Fs=()=>Ns??=Promise.all([U(()=>import("./maplibre-gl-Dngacpy6.js"),[]),U(()=>import("./maplibre-gl-worker-CD34yISW.js"),[])]).then(([e,t])=>(e.setWorkerUrl(t.default),e));async function Gs(e,t,n,r,s=null){const[o,a]=await Promise.all([Fs(),Rs(e,t,s)]),i=Object.assign(document.createElement("div"),{className:"tl-geo-offscreen"});Object.assign(i.style,{position:"fixed",left:"-20000px",top:"0",width:`${n}px`,height:`${r}px`,pointerEvents:"none"}),document.body.appendChild(i);const l=new o.Map({container:i,style:a,interactive:!1,attributionControl:!1,fadeDuration:0,pixelRatio:1,maxPitch:Math.max(60,Zn.maxPitch),canvasContextAttributes:{preserveDrawingBuffer:!0,antialias:!0},center:[0,0],zoom:1});await new Promise((c,u)=>{const p=setTimeout(()=>u(Error("Bản đồ không tải được (hết thời gian)")),2e4);l.once("load",()=>{clearTimeout(p),c()}),l.once("error",k=>{l.loaded()||(clearTimeout(p),u(Error(String(k.error?.message??"map error"))))})});const f=a.layers.find(c=>c.type==="symbol"&&c.layout?.["text-font"])?.layout["text-font"]??["Noto Sans Bold"];l.addSource("cx-route",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),l.addSource("cx-pins",{type:"geojson",data:{type:"FeatureCollection",features:[]}});for(const c of Cs(f))(c.type!=="symbol"||a.glyphs)&&l.addLayer(c);const h={map:l,canvas:l.getCanvas(),box:i,style:e,W:n,H:r,placed:new Map,three:(await at())[0],city:""};return l.addLayer(Bs(h.three,()=>h),l.getLayer("cx-pin-ring")?"cx-pin-ring":void 0),h}const Y="cx-buildings",It=new WeakMap;function Hs(e){return e.getStyle().layers.filter(t=>t["source-layer"]==="building"&&t.id!==Y)}function zs(e,t,n){const{map:r}=e,s=t?`${t.color??""}:${t.opacity}:${t.light}`:"";if(s!==e.city){const o=Hs(r),a=It.get(e)??new Map(o.map(i=>[i.id,i.layout?.visibility??"visible"]));It.set(e,a),r.getLayer(Y)&&r.removeLayer(Y);for(const i of o)r.setLayoutProperty(i.id,"visibility",t?"none":a.get(i.id)??"visible");if(t){const i=o[0]?.source??Object.entries(r.getStyle().sources).find(([,l])=>l.type==="vector")?.[0];if(i){const l=Qn(t.light,e.style),f=r.getStyle().layers.find(h=>h.type==="symbol")?.id;r.addLayer({id:Y,type:"fill-extrusion",source:i,"source-layer":"building",minzoom:13,filter:["!=",["get","hide_3d"],!0],paint:{"fill-extrusion-color":l.top&&!t.color?["interpolate",["linear"],["coalesce",["get","render_height"],0],0,Lt(e.style,null,l.tint),220,l.top]:Lt(e.style,t.color,l.tint),"fill-extrusion-opacity":t.opacity,"fill-extrusion-vertical-gradient":!0,"fill-extrusion-height":0,"fill-extrusion-base":0}},f),r.setLight(l.light),r.setSky(l.sky)}}else r.setSky({});e.city=s}if(t&&r.getLayer(Y)){const o=t.height*n;r.setPaintProperty(Y,"fill-extrusion-height",["*",["max",["coalesce",["get","render_height"],0],6],o]),r.setPaintProperty(Y,"fill-extrusion-base",["*",["coalesce",["get","render_min_height"],0],o])}}function Ws(e,t){return new Promise(n=>{const r=()=>{clearTimeout(s),n()},s=setTimeout(r,t);e.once("idle",r),e.triggerRepaint()})}async function Eo(e,t,n,r,s,{wait:o=2e4,lang:a="vi",duration:i=1/0,live:l=!1}={}){const f=zn(t,i)?t.hd:null,h=`${t.style}:${a}:${n.W}x${n.H}:${f?.id??""}`,c=Z.get(e);let u=c?.p;if(!c||c.sig!==h){c&&c.p.then(fn,()=>{});const y=Gs(t.style,a,n.W,n.H,f);u=y,Z.set(e,{sig:h,p:y}),y.catch(()=>{Z.get(e)?.p===y&&Z.delete(e)})}const p=await u,{map:k}=p;Re.set(e,{pl:p,W:n.W,H:n.H});const E=new Set;for(const[y,S]of(t.models??[]).entries()){const P=Wn(S,r),L=`${y}:${S.gcsUri}`;E.add(L);let T=p.placed.get(L);if(!T){const R=await Ct(S.gcsUri);T={holder:new p.three.Group().add(R.clone(!0)),m:S,scale:0,cut:1,glow:0},p.placed.set(L,T)}if(S.reveal==="build"&&!T.scan){const R=await Ct(S.gcsUri);T.scan=Ds(p.three,R.userData.size??[1,1],S.color??"#5ef3ff"),T.holder.add(T.scan)}T.m=S,T.scale=P?P.scale:0,T.cut=P?.cut??1,T.glow=P?.glow??0}const d=fe(t,r,[n.W,n.H]).bearing??0;for(const[y,S]of(t.images??[]).entries()){const P=qn(S,r),L=`img:${y}:${S.gcsUri}`;E.add(L);let T=p.placed.get(L);if(!T){const C=p.three,I=await js(S.gcsUri),v=I.image,m=v?.width&&v?.height?v.height/v.width:S.aspect,b=new C.MeshBasicMaterial({map:I,transparent:!0,side:C.DoubleSide,alphaTest:.03,toneMapped:!1}),O=new C.Mesh(new C.PlaneGeometry(1,m).translate(0,m/2,0),b);O.frustumCulled=!1;const $=new C.Group().add(O);T={holder:new C.Group().add($),m:{at:S.at,height:S.width,rotation:0},scale:0,cut:1,glow:0,tilter:$,aspect:m,mat:b},p.placed.set(L,T)}const R=(P?.tilt??S.tilt)*Math.PI/180;T.tilter.rotation.x=-(Math.PI/2-R),T.tilter.position.z=T.aspect/2*Math.cos(R),T.mat.opacity=P?.alpha??0,T.m={at:S.at,height:S.width,rotation:(S.face==="camera"?d:0)+S.rotation},T.scale=P?P.scale:0}for(const y of[...p.placed.keys()])E.has(y)||p.placed.delete(y);k.jumpTo(fe(t,r,[n.W,n.H])),zs(p,t.buildings,Un(t,r)?.k??0);const A=Kn(t,r),w=t.route?.look==="saber"||t.route?.look==="electric"||t.route?.look==="trail";k.getSource("cx-route").setData({type:"FeatureCollection",features:A&&t.route&&!w?[{type:"Feature",properties:{color:t.route.color,width:t.route.width},geometry:{type:"LineString",coordinates:A}}]:[]}),k.getSource("cx-pins").setData({type:"FeatureCollection",features:Vn(t,r).map(y=>({type:"Feature",properties:{label:y.label,color:y.color,scale:y.scale},geometry:{type:"Point",coordinates:y.at}}))}),t.route&&!w&&k.setPaintProperty("cx-route","line-dasharray",t.route.look==="dashed"?[2,1.5]:[1,0]),l?k.redraw():await Ws(k,o);const g=s.getContext("2d");if(!g)return;g.clearRect(0,0,s.width,s.height),g.drawImage(p.canvas,0,0,s.width,s.height);const _=y=>{const S=k.project(y);return[S.x*s.width/n.W,S.y*s.height/n.H]};for(const y of t.areas??[]){const S=Jn(y,r);if(!S)continue;const P=y.paths.map(T=>T.map(_));if(S.fill>0){g.save(),g.fillStyle=y.color,g.globalAlpha=S.fill,g.beginPath();for(const T of P){g.moveTo(T[0][0],T[0][1]);for(const R of T.slice(1))g.lineTo(R[0],R[1]);g.closePath()}g.fill("evenodd"),g.restore()}const L=y.width*s.width/n.W;for(const[T,R]of S.paths.entries()){const C=R.map(_);if(y.look==="line"||y.look==="dashed"){g.save(),g.strokeStyle=y.color,g.lineWidth=L,g.lineJoin="round",g.setLineDash(y.look==="dashed"?[L*3,L*2]:[]),g.beginPath(),g.moveTo(C[0][0],C[0][1]);for(const I of C.slice(1))g.lineTo(I[0],I[1]);g.stroke(),g.restore()}else ye(g,y.look==="electric"?Ie(C,r,{amp:L*1.6,step:L*4,seed:3+T}):C,y.color,L,ce(r+T*.13),S.done||T>0)}}if(t.route?.look==="trail"&&r>=t.route.start){const y=fe(t,r,[n.W,n.H]),S=Math.max(30,ht(y.zoom,y.center[1])*t.route.width*16);qs(g,Yn(t.route.points,9,S).map(P=>P.map(_)),t.route,r,t.route.width*s.width/n.W)}else if(w&&A&&t.route){const y=s.width/n.W,S=s.height/n.H,P=A.map(L=>{const T=k.project(L);return[T.x*y,T.y*S]});if(t.route.look==="electric"){const L=t.route.width*y;ye(g,Ie(P,r,{amp:L*1.8,step:L*3,seed:1}),t.route.color,L,ce(r),!1),ye(g,Ie(P,r,{amp:L*2.6,step:L*2.2,seed:7}),t.route.color,L*.45,ce(r+.37)*.8,!0)}else ye(g,P,t.route.color,t.route.width*y,ce(r))}if(t.icons?.length){const y=fe(t,r,[n.W,n.H]),S=s.height/720,P=ht(y.zoom,y.center[1])*n.H/720,L=t.icons.map(v=>({ic:v,st:Xn(v,r),p:_(v.at)})).filter(v=>v.st&&v.p[0]>-240*S&&v.p[0]<s.width+240*S&&v.p[1]>-60*S&&v.p[1]<s.height+260*S),T=v=>v==="tag"||v==="beacon"||v==="sign",R=new Map(t.icons.map((v,m)=>[v,m])),C=[],I=new Set;for(const v of[...L].sort((m,b)=>Number(T(b.ic.look))-Number(T(m.ic.look))||m.ic.show-b.ic.show||R.get(m.ic)-R.get(b.ic))){if(!v.ic.label&&!v.ic.sub){I.add(v);continue}const m=S*v.ic.size,b=Math.max(70,Math.max(v.ic.label?.length??0,v.ic.sub?.length??0)*8.4)*m,O=v.p[1]-(T(v.ic.look)?130:100)*m,$=[v.p[0]-(T(v.ic.look)?16*m:b/2),O,v.p[0]+(T(v.ic.look)?b:b/2),v.p[1]-(T(v.ic.look)?60:52)*m];C.some(D=>$[0]<D[2]&&$[2]>D[0]&&$[1]<D[3]&&$[3]>D[1])||(C.push($),I.add(v))}for(const v of L.sort((m,b)=>m.p[1]-b.p[1])){const{ic:m,st:b,p:O}=v,$=P*70*m.size,D=Math.cos(m.at[1]*Math.PI/180),H=X=>Array.from({length:40},(it,un)=>{const lt=un/40*Math.PI*2;return _([m.at[0]+$*X*Math.cos(lt)/(111320*D),m.at[1]+$*X*Math.sin(lt)/111320])});xs(g,m,I.has(v)?b:{...b,label:0},O,S*m.size,H)}}const M=er(r);if(M>0){const y=Math.max(10,Math.round(s.height/60));g.save(),g.globalAlpha=M,g.font=`500 ${y}px system-ui, sans-serif`,g.textAlign="right",g.textBaseline="bottom",g.shadowColor="rgba(0,0,0,.8)",g.shadowBlur=y*.35,g.fillStyle="rgba(255,255,255,.92)",Es(Ss(t.style,vs,f?ln(f):null),S=>g.measureText(S).width,s.width-y*1.2).reverse().forEach((S,P)=>g.fillText(S,s.width-y*.6,s.height-y*.4-P*y*1.35)),g.restore()}}function ye(e,t,n,r,s=1,o=!1){if(t.length<2)return;const a=()=>{e.beginPath(),e.moveTo(t[0][0],t[0][1]);for(const u of t.slice(1))e.lineTo(u[0],u[1])};e.save(),e.globalCompositeOperation="lighter",e.lineCap="round",e.lineJoin="round";const i=[[14,34,.14],[7,18,.26],[3.6,8,.5],[1.9,3,.85]];for(const[u,p,k]of i)e.filter=`blur(${p*Math.max(.6,r/5)}px)`,e.strokeStyle=n,e.globalAlpha=Math.min(1,k*s),e.lineWidth=r*u,a(),e.stroke();if(e.filter="none",e.globalAlpha=1,e.strokeStyle="#ffffff",e.lineWidth=Math.max(1.2,r*.55),a(),e.stroke(),o){e.restore();return}const[l,f]=t[t.length-1],h=r*4.5*s,c=e.createRadialGradient(l,f,0,l,f,h);c.addColorStop(0,"rgba(255,255,255,1)"),c.addColorStop(.25,n),c.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=c,e.beginPath(),e.arc(l,f,h,0,Math.PI*2),e.fill(),e.restore()}function Ve(e,t,n){const r=[0];for(let f=1;f<e.length;f++)r.push(r[f-1]+Math.hypot(e[f][0]-e[f-1][0],e[f][1]-e[f-1][1]));const s=r[r.length-1];if(!(s>0)||n<=t)return[];const o=f=>{let h=1;for(;h<r.length-1&&r[h]<f;)h++;const c=(f-r[h-1])/(r[h]-r[h-1]||1);return[e[h-1][0]+(e[h][0]-e[h-1][0])*c,e[h-1][1]+(e[h][1]-e[h-1][1])*c]},a=t*s,i=n*s,l=[o(a)];for(let f=1;f<e.length-1;f++)r[f]>a&&r[f]<i&&l.push(e[f]);return l.push(o(i)),l}function qs(e,t,n,r,s){if(t.length<2)return;const o=c=>{if(c.length<2)return!1;e.beginPath(),e.moveTo(c[0][0],c[0][1]);for(const u of c.slice(1))e.lineTo(u[0],u[1]);return!0},a=Math.max(1,s*.3),i=t[t.length>>1],l=i.length>>1,f=Math.hypot(t[0][l][0]-t[t.length-1][l][0],t[0][l][1]-t[t.length-1][l][1]);e.save(),e.globalCompositeOperation="lighter",e.lineCap="round",e.lineJoin="round";const h=ut(n,t.length>>1,r);h&&o(Ve(i,0,h.drawn))&&(e.filter=`blur(${Math.max(2,f*.45)}px)`,e.strokeStyle=n.color,e.globalAlpha=.1,e.lineWidth=f*1.15,e.stroke(),e.filter="none"),t.forEach((c,u)=>{const p=ut(n,u,r);if(!p)return;const k=a*(u%3===1?1.6:1);o(Ve(c,0,p.drawn))&&(e.globalCompositeOperation="source-over",e.strokeStyle=n.color,e.filter=`blur(${k}px)`,e.globalAlpha=.45,e.lineWidth=k*2.2,e.stroke(),e.filter="none",e.globalAlpha=1,e.lineWidth=k,e.stroke(),e.globalCompositeOperation="lighter"),p.streak&&o(Ve(c,p.streak.a,p.streak.b))&&(e.strokeStyle="#fff6cf",e.filter=`blur(${k}px)`,e.globalAlpha=.75,e.lineWidth=k*2.6,e.stroke(),e.filter="none",e.globalAlpha=1,e.lineWidth=k*1.4,e.stroke())}),e.restore()}function fn(e){try{e.map.remove()}catch{}e.box.remove()}function To(e){Re.delete(e);const t=Z.get(e);t&&(Z.delete(e),t.p.then(fn,()=>{}))}const Re=new Map;function xo(e,t,n){const r=Re.get(e);if(!r)return null;const s=r.pl.map.unproject([t*r.W,n*r.H]);return Number.isFinite(s.lng)&&Number.isFinite(s.lat)?[+s.lng.toFixed(6),+s.lat.toFixed(6)]:null}function vo(e,t){const n=Re.get(e);if(!n)return null;const r=n.pl.map.project(t);return[r.x/n.W,r.y/n.H]}const jt=e=>Math.round(e*1e4)/1e4,cn=e=>e?.square?{SW:720,SH:720}:{SW:1280,SH:720};function Us(e,t,n,r,[s,o]){const{SW:a,SH:i}=cn(e.shape),l=Math.min(a,i)/V,f=(a-V*l)/2+s*l,h=(i-V*l)/2+o*l,c=we(e,f/a,h/i,t,n,r,a,i);return[c.px,c.py]}function Ks(e,t,n,r,s,o){const{SW:a,SH:i}=cn(e.shape),l=Math.min(a,i)/V,f=or(e,s,o,t,n,r,a,i);return[(f.u*a-(a-V*l)/2)/l,(f.v*i-(i-V*l)/2)/l]}const Vs=e=>tt(e)&&e.items.some(t=>t.pins&&Object.keys(t.pins).length);function Oo(e,t,n,r=1280,s=720){const o=e.shape;return Vs(o)?{...o,items:o.items.map(a=>{if(!a.pins||!a.params.pts)return a;const i=nt(a,n,{motion:!1}),l=nr(rt(i)),f=i.params.pts.map((u,p)=>{const k=a.pins[p]!==void 0&&t.find(A=>A.id===a.pins[p]&&rr(A));if(!k)return u;const E=sr(k,Math.max(0,Math.min(k.duration,e.start+n-k.start)),r,s),d=zt(l,...Ks(e,n,r,s,r/2+E.x*r,s/2+E.y*s));return u.length===6?[d[0],d[1],...u.slice(2)]:d}),{keys:h,...c}=i;return{...c,params:{...i.params,pts:f}}})}:o}function Lo(e,t,n,r,s,o,{chain:a=!1,makeId:i,labels:l}){if(!tt(t.shape))throw Error("Chọn một layer Shape");const f=t.shape.items.find(d=>d.id===n);if(!f||f.type!=="path"||!f.params.pts)throw Error("Chọn một đường Pen trong layer Shape");const h=nt(f,r,{motion:!1}),c=h.params.pts,u=rt(h);if(a&&c.length<2)throw Error("Đường cần ít nhất 2 điểm");if(c.length>32)throw Error("Đường có quá nhiều điểm (tối đa 32)");let p=[...e];const k=[],E={};return c.forEach((d,A)=>{const[w,g]=Us(t,r,s,o,zt(u,d[0],d[1]));let _=ar({id:i(A),track:t.track,start:t.start,duration:t.duration,label:l(A)});if(_={..._,...oe(_,"x",jt((w-s/2)/s),0)},_={..._,...oe(_,"y",jt((g-o/2)/o),0)},p=[...p,_],a&&A>0){const M=k[A-1].id;_={..._,...ir(p,_,M,Math.max(0,Math.min(_.duration,r)),s,o)},p=p.map(y=>y.id===_.id?_:y)}k.push(_),E[A]=_.id}),lr(e),{nulls:k,shape:{...t.shape,items:t.shape.items.map(d=>d.id===n?{...d,pins:E}:d)}}}function Po(e,t,n,r,s,o,a){if(["x","y","zoom"].some(b=>fr(e,b)))throw Error("Layer có key vị trí / tỉ lệ: bỏ key trước khi cắt sát nội dung");const i=e.crop??{left:0,right:0,top:0,bottom:0},l={left:Math.max(i.left,t.left),top:Math.max(i.top,t.top),right:Math.max(i.right,t.right),bottom:Math.max(i.bottom,t.bottom)};if(1-l.left-l.right<.02||1-l.top-l.bottom<.02)throw Error("Không tìm thấy nội dung để cắt");if(["left","top","right","bottom"].every(b=>Math.abs(l[b]-i[b])<1e-4))throw Error("Layer đã sát nội dung");const f=b=>Math.round(b*1e4)/1e4,h=Object.fromEntries(Object.entries(l).map(([b,O])=>[b,f(O)])),c=1-i.left-i.right,u=1-i.top-i.bottom,p=b=>(b-i.left)/c,k=b=>(b-i.top)/u,E=[[p(l.left),k(l.top)],[p(1-l.right),k(l.top)],[p(1-l.right),k(1-l.bottom)]].map(([b,O])=>we(e,b,O,n,r,s,o,a)),d=b=>Math.hypot(b[1].px-b[0].px,b[1].py-b[0].py),A=b=>[(b[0].px+b[2].px)/2,(b[0].py+b[2].py)/2];let w={...e,crop:h};const g=[[0,0],[1,0],[1,1]].map(([b,O])=>we(w,b,O,n,r,s,o,a)),_=je(e,"zoom",n)*d(E)/d(g);if(!(_>0)||_>pt)throw Error(`Cắt sát nội dung cần tỉ lệ layer ngoài giới hạn (tối đa ${pt*100}%)`);w={...w,...oe(w,"zoom",f(_),n)};const M=[[0,0],[1,0],[1,1]].map(([b,O])=>we(w,b,O,n,r,s,o,a)),[y,S]=A(E),[P,L]=A(M),T=cr(e,e.start+n,r,s),R=-T.rot*Math.PI/180,C=(y-P)/(T.zoom||1),I=(S-L)/(T.zoom||1),v=C*Math.cos(R)-I*Math.sin(R),m=C*Math.sin(R)+I*Math.cos(R);return w={...w,...oe(w,"x",f(je(e,"x",n)+v/r),n)},w={...w,...oe(w,"y",f(je(e,"y",n)+m/s),n)},{crop:h,...Object.fromEntries(Object.keys(w).filter(b=>w[b]!==e[b]&&b!=="crop").map(b=>[b,w[b]]))}}function $o(e,t,n,{alpha:r=8,dark:s=16}={}){let o=!1;for(let c=3;c<e.length;c+=4)if(e[c]<250){o=!0;break}const a=c=>o?e[c+3]>r:Math.max(e[c],e[c+1],e[c+2])>s;let i=t,l=n,f=-1,h=-1;for(let c=0;c<n;c++)for(let u=0;u<t;u++)a((c*t+u)*4)&&(u<i&&(i=u),u>f&&(f=u),c<l&&(l=c),c>h&&(h=c));return f<0?null:{left:i/t,top:l/n,right:(t-1-f)/t,bottom:(n-1-h)/n}}const Pe=5*1024*1024,$e=10*1024*1024,Js=200,Ys="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==",Xs=/^data:image\/(png|jpe?g|webp|gif);base64,[A-Za-z0-9+/=\s]*$/,se=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Zs(e){if(!se(e))throw W("Not a Lottie animation");const t=structuredClone(e),{w:n,h:r,fr:s,ip:o,op:a}=t;if(!Array.isArray(t.layers)||!t.layers.length)throw W("Not a Lottie animation (no layers)");const i=ur({w:Math.round(n),h:Math.round(r),fr:s,ip:o,op:a});if(t.assets!==void 0&&!Array.isArray(t.assets))throw W("Invalid Lottie assets");const l={expressions:0,assets:0,fonts:0},f=[[t,0]];for(;f.length;){const[h,c]=f.pop();if(c>Js)throw W("Lottie file is nested too deeply");if(Array.isArray(h)){for(const u of h)u&&typeof u=="object"&&f.push([u,c+1]);continue}typeof h.x=="string"&&(delete h.x,l.expressions++);for(const u of Object.keys(h)){const p=h[u];p&&typeof p=="object"&&f.push([p,c+1])}}for(const h of t.assets||[]){if(!se(h))throw W("Invalid Lottie assets");Array.isArray(h.layers)||h.p!==void 0&&((typeof h.p!="string"||!Xs.test(h.p))&&(h.p=Ys,l.assets++),h.u="",h.e=1)}if(se(t.fonts)&&Array.isArray(t.fonts.list))for(const h of t.fonts.list)se(h)&&(h.fPath!==void 0&&(delete h.fPath,l.fonts++),h.fOrigin="n",h.origin=0);return{data:t,meta:i,removed:l}}const et=e=>new TextDecoder("utf-8",{fatal:!0}).decode(e),Qs=e=>{let t="";for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)},eo=e=>e.length>4&&e[0]===80&&e[1]===75&&e[2]===3&&e[3]===4,to={png:"png",jpg:"jpeg",jpeg:"jpeg",webp:"webp",gif:"gif"};function no(e){if(e.length>$e)throw W("Lottie file is too large");let t;try{t=hr(e,{filter:i=>i.originalSize<=Pe&&(i.name==="manifest.json"||/^(animations|a|images|i)\/[^/]+$/.test(i.name))})}catch{throw W("Invalid .lottie file")}let n=0;for(const i of Object.values(t))if(n+=i.length,i.length>Pe||n>$e*2)throw W("Lottie file is too large");let r=null;if(t["manifest.json"])try{const i=JSON.parse(et(t["manifest.json"]));r=Array.isArray(i?.animations)&&typeof i.animations[0]?.id=="string"?i.animations[0].id:null}catch{}const s=Object.keys(t).filter(i=>/^(animations|a)\/[^/]+\.json$/.test(i)).sort(),o=r&&s.find(i=>i===`animations/${r}.json`||i===`a/${r}.json`)||s[0];if(!o)throw W("No animation in the .lottie file");const a=JSON.parse(et(t[o]));for(const i of Array.isArray(a?.assets)?a.assets:[]){if(!se(i)||typeof i.p!="string"||i.e===1||i.p.startsWith("data:"))continue;const l=t[`images/${i.p}`]??t[`i/${i.p}`],f=to[i.p.split(".").pop()?.toLowerCase()??""];l&&f&&(i.p=`data:image/${f};base64,${Qs(l)}`,i.u="",i.e=1)}return a}function hn(e){if(!(e instanceof Uint8Array))throw W("Not a Lottie animation");let t;if(eo(e))t=no(e);else{if(e.length>Pe)throw W("Lottie file is too large");try{t=JSON.parse(et(e))}catch{throw W("Not a Lottie animation")}}const n=Zs(t),r=JSON.stringify(n.data);if(r.length>Pe)throw W("Lottie file is too large");return{...n,text:r}}const Je=new Map;function ro(e){let t=Je.get(e);return t||(t=(async()=>{const n=await fetch(e);if(!n.ok)throw Error(`HTTP ${n.status}`);if(Number(n.headers.get("content-length"))>$e)throw Error("Lottie file is too large");return hn(new Uint8Array(await n.arrayBuffer())).data})(),Je.set(e,t),t.catch(()=>Je.delete(e))),t}const Q=new Map;let so=null;const oo=()=>so??=U(()=>import("./lottie_light_canvas-BblLU4nU.js").then(e=>e.l),__vite__mapDeps([6,1,2])).then(e=>e.default),ao=()=>({play(){},seek(){},playing(){},rate(){},setVolume(){}});async function io(e,t,n){const[r,s]=await Promise.all([oo(),ro(e)]),o=Object.assign(document.createElement("canvas"),{width:t,height:n}),a=o.getContext("2d");if(!a)throw Error("Canvas unavailable");const i=r.loadAnimation({renderer:"canvas",loop:!1,autoplay:!1,animationData:structuredClone(s),audioFactory:ao,rendererSettings:{context:a,clearCanvas:!0,preserveAspectRatio:"xMidYMid meet",dpr:1}});return i.isLoaded||await new Promise(l=>{const f=setTimeout(l,8e3);i.addEventListener("DOMLoaded",()=>{clearTimeout(f),l()})}),{canvas:o,anim:i}}async function Ro(e,t,n,r,s){const o=Q.get(e);let a=o?.p;if(!o||o.url!==t||o.W!==n.W||o.H!==n.H){o&&o.p.then(h=>h.anim.destroy(),()=>{});const f=io(t,n.W,n.H);a=f,Q.set(e,{url:t,W:n.W,H:n.H,p:f}),f.catch(()=>{Q.get(e)?.p===f&&Q.delete(e)})}const i=await a;i.anim.goToAndStop(r,!0);const l=s.getContext("2d");l&&(l.clearRect(0,0,s.width,s.height),l.drawImage(i.canvas,0,0,s.width,s.height))}function Co(e){const t=Q.get(e);t&&(Q.delete(e),t.p.then(n=>n.anim.destroy(),()=>{}))}async function Io(e){if(e.size>$e)throw Error("Lottie file is too large");const t=hn(new Uint8Array(await e.arrayBuffer())),n=`${e.name.replace(/\.(json|lottie)$/i,"")||"lottie"}.json`;return{file:new File([t.text],n,{type:"application/json"}),meta:t.meta,removed:t.removed}}const jo=e=>/\.(json|lottie)$/i.test(e.name)||e.type==="application/json"||e.type==="application/zip+dotlottie";export{B as A,hn as B,ho as C,uo as D,go as E,yo as F,ro as G,Pe as L,rn as S,ko as a,xs as b,us as c,bo as d,To as e,Eo as f,vo as g,xo as h,Vs as i,So as j,Co as k,Ro as l,wo as m,Ao as n,Ae as o,Oo as p,$o as q,Lo as r,_o as s,Mo as t,Po as u,jo as v,Io as w,mo as x,po as y,Rr as z};