@augmentd-labs/canvas-web 2.26.19 → 2.26.20

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 (155) hide show
  1. package/dist/assets/DocumentBodyEditor-CE2S2X6g.js +1 -0
  2. package/dist/assets/DocumentIcon-BS10SIP6.js +1 -0
  3. package/dist/assets/EditorOverlay-BUToR_av.js +1 -0
  4. package/dist/assets/FileForm-BxTixeDm.js +1 -0
  5. package/dist/assets/FiltersApplet-BpqITV13.js +1 -0
  6. package/dist/assets/HomeFab-BAKOAkpE.js +3 -0
  7. package/dist/assets/IdentityFields-C2MPM-Ab.js +1 -0
  8. package/dist/assets/LensApplet-DNTGwgZs.js +1 -0
  9. package/dist/assets/LinkToCard-BZwwE-Dv.js +1 -0
  10. package/dist/assets/LinkToSidePanel-eCy3nW4R.js +1 -0
  11. package/dist/assets/{LocationTab-BONJQfYM.js → LocationTab-DAtqAQ3l.js} +1 -1
  12. package/dist/assets/{MarkdownEditor-CkobBLtI.js → MarkdownEditor-7OqSDr7E.js} +1 -1
  13. package/dist/assets/MessageComposerDialog-DzLhkHyh.js +4 -0
  14. package/dist/assets/{NextShell-Byg6OtC2.js → NextShell-D9gvlKY2.js} +1 -1
  15. package/dist/assets/NotesApplet-gMAMneRi.js +1 -0
  16. package/dist/assets/ObjectPropertiesCard-C3jt40tM.css +1 -0
  17. package/dist/assets/ObjectPropertiesCard-DDcRLpsW.js +8 -0
  18. package/dist/assets/PathPickerField-cVs5sZuG.js +1 -0
  19. package/dist/assets/PickDocumentsCard-BlicxMqC.js +1 -0
  20. package/dist/assets/SketchApplet-D8mkYmK9.js +1 -0
  21. package/dist/assets/{SketchEditor-C9_lu3Ot.js → SketchEditor-zMrm1npg.js} +4 -4
  22. package/dist/assets/TerminalApplet-BO2HRp0z.js +20 -0
  23. package/dist/assets/TerminalApplet-BrP-ENHg.css +1 -0
  24. package/dist/assets/TextDocumentEditor-7V4aFL8i.js +1 -0
  25. package/dist/assets/TodosApplet-swdaBT-2.js +1 -0
  26. package/dist/assets/TodosWidget-BXF8fYer.js +1 -0
  27. package/dist/assets/UploadProgressList-B2xCVzFR.js +1 -0
  28. package/dist/assets/_agentId_-Ci4j4UYy.js +0 -0
  29. package/dist/assets/_contextId_-DDFyhgV2.js +1 -0
  30. package/dist/assets/_workspaceName_-DO9ZBx7N.js +1 -0
  31. package/dist/assets/about-B1_n4Iu8.js +1 -0
  32. package/dist/assets/add-BnwWcDlO.js +1 -0
  33. package/dist/assets/admin-Bhg9QBHL.js +5 -0
  34. package/dist/assets/agents-ClK3Y2x0.js +1 -0
  35. package/dist/assets/agents-DquOfkFX.js +1 -0
  36. package/dist/assets/alert-dialog-DIA-tAP5.js +1 -0
  37. package/dist/assets/api-CA6WiiYM.js +1 -0
  38. package/dist/assets/api-tokens-O5iFESo0.js +1 -0
  39. package/dist/assets/appearance-C2vu3ALt.js +1 -0
  40. package/dist/assets/applet-target-DnTa2VAT.js +1 -0
  41. package/dist/assets/apps-BZrw8Cqo.js +1 -0
  42. package/dist/assets/auth-Bx9fAZmz.js +1 -0
  43. package/dist/assets/auth-CUdpxbLV.js +1 -0
  44. package/dist/assets/backend-sync-progress-DU-e9TWi.css +1 -0
  45. package/dist/assets/backend-sync-progress-DWR42uQV.js +7 -0
  46. package/dist/assets/blobs-WiXP9QRi.js +1 -0
  47. package/dist/assets/button-Bv4zA1qr.js +1 -0
  48. package/dist/assets/chunk-62JRHF6Z-vspAGgtK.js +3 -0
  49. package/dist/assets/{chunk-K2UTITRG-zQFDOW3Q.js → chunk-K2UTITRG-BvHe9UPk.js} +3 -3
  50. package/dist/assets/code-editor-BOIngd5F.js +40 -0
  51. package/dist/assets/color-DFEH4BfK.js +1 -0
  52. package/dist/assets/content-app-view-C33Ip_rx.js +1 -0
  53. package/dist/assets/context-D_K4g9SQ.js +1 -0
  54. package/dist/assets/contexts-B6d6Axza.js +1 -0
  55. package/dist/assets/contexts-CgydYDn-2.js +1 -0
  56. package/dist/assets/date-time-picker-BZaA3M9_.js +1 -0
  57. package/dist/assets/desk-dI_FvLsK.js +1 -0
  58. package/dist/assets/devices-CAa1bRxk.js +1 -0
  59. package/dist/assets/devices-D3-_UWM0.js +1 -0
  60. package/dist/assets/document-BG_mODBn.js +1 -0
  61. package/dist/assets/document-list-BiogH4tf.js +2 -0
  62. package/dist/assets/document-list-DAYdk5vh.css +1 -0
  63. package/dist/assets/document-open-mode-DoImW-xs.js +1 -0
  64. package/dist/assets/embedding-Cjrxh6MN.js +1 -0
  65. package/dist/assets/embedding-m8SZH4oN.js +1 -0
  66. package/dist/assets/form-panel-Dz96K7Lv.js +1 -0
  67. package/dist/assets/geo-CZfs0E-x.js +1 -0
  68. package/dist/assets/home-pS7q4Wl4.js +1 -0
  69. package/dist/assets/image-GAAHSSAO-CI-0hUck.js +1 -0
  70. package/dist/assets/index-C10UNpew.css +2 -0
  71. package/dist/assets/index-exXolIqD.js +16 -0
  72. package/dist/assets/inferd-config-editor-DagMmwW4.js +1 -0
  73. package/dist/assets/input-BOtCd4HP.js +1 -0
  74. package/dist/assets/key-bindings-BOtykyXR.js +1 -0
  75. package/dist/assets/label-CNoJOoe0.js +1 -0
  76. package/dist/assets/last-path-BbXWC3b3.js +1 -0
  77. package/dist/assets/layer-style-Byl5LNFR.js +1 -0
  78. package/dist/assets/lazy-editor-Cbva8Pe2.js +2 -0
  79. package/dist/assets/logs-CdbfY8_H.js +1 -0
  80. package/dist/assets/{markdown-html-XoABNf32.js → markdown-html-CZMGihx6.js} +1 -1
  81. package/dist/assets/markdown-view-BBBZtNSR.js +2 -0
  82. package/dist/assets/note-save-status-DPz4VzL6.js +1 -0
  83. package/dist/assets/offline-BjMpUv3N.js +1 -0
  84. package/dist/assets/page-header-GtTr9Ff_.js +1 -0
  85. package/dist/assets/public-share-DT9Tgn_Y.js +1 -0
  86. package/dist/assets/query-debug-tVbB_8Z6.js +1 -0
  87. package/dist/assets/react-BHzhHVTZ.js +164 -0
  88. package/dist/assets/registry-6tE_1KPV.js +2 -0
  89. package/dist/assets/relation-events-CKio19hE.js +1 -0
  90. package/dist/assets/remotes-DR_iJClb.js +1 -0
  91. package/dist/assets/role-C5I0Plgn.js +1 -0
  92. package/dist/assets/roles-DERIgujv.js +2 -0
  93. package/dist/assets/roles-DswT1Lv0.js +2 -0
  94. package/dist/assets/settings-Cc6OMCOX.js +14 -0
  95. package/dist/assets/settings-D7K7z_JD.js +1 -0
  96. package/dist/assets/settings-Du8r1SXC.js +1 -0
  97. package/dist/assets/settings-vosK_LI-.js +1 -0
  98. package/dist/assets/share-target-Df10J5JB.js +1 -0
  99. package/dist/assets/shared-1dpCuibu.js +1 -0
  100. package/dist/assets/shared-C7b3QOUP.js +1 -0
  101. package/dist/assets/sketch-lazy-Q58-vPF-.js +2 -0
  102. package/dist/assets/socket-CtH3EU9m.js +1 -0
  103. package/dist/assets/subtree-transfer-dialog-B7s4r78T.js +1 -0
  104. package/dist/assets/tags-YamdPoBK.js +1 -0
  105. package/dist/assets/text-documents-D_zDMyhB.js +2 -0
  106. package/dist/assets/{ui-BqHBdBU4.js → ui-BSqPn1LJ.js} +2 -2
  107. package/dist/assets/url-params-n7kU_WZ-.js +1 -0
  108. package/dist/assets/use-applet-docs-Cry2SFsG.js +1 -0
  109. package/dist/assets/use-applet-target-mkjQujx6.js +1 -0
  110. package/dist/assets/use-canvas-pins-C57Vbkrq.css +1 -0
  111. package/dist/assets/use-canvas-pins-CZBfEB5E.js +3 -0
  112. package/dist/assets/use-create-panel-DhSNIGtr.js +1 -0
  113. package/dist/assets/use-document-modal-PG8bQyIB.js +1 -0
  114. package/dist/assets/use-menu-BVkqNEIx.js +1 -0
  115. package/dist/assets/use-mobile-Db-vWu9Y.js +1 -0
  116. package/dist/assets/use-settings-back-Dk-DJEUO.js +1 -0
  117. package/dist/assets/use-sortable-data-DYIDDI8c.js +1 -0
  118. package/dist/assets/{use-theme-Bd8sb5Ox.js → use-theme-DaxpiICf.js} +1 -1
  119. package/dist/assets/use-toast-BlLDqSUO.js +1 -0
  120. package/dist/assets/use-toolbox-Ck_cLGgf.js +1 -0
  121. package/dist/assets/use-workspace-identity-BVpGHkZq.js +1 -0
  122. package/dist/assets/useAddTarget-CVRPElxz.js +1 -0
  123. package/dist/assets/useAgentModels-DI41aFY3.js +3 -0
  124. package/dist/assets/useDocumentThumbnail-C_rq2rXs.js +1 -0
  125. package/dist/assets/useEditNoteFields-Bigs9ZG8.js +1 -0
  126. package/dist/assets/useEscapeClose-DR_xKT_k.js +1 -0
  127. package/dist/assets/useSocketSubscription-ifW-vnlb.js +1 -0
  128. package/dist/assets/useToastHelpers-CRrpIIdY.js +1 -0
  129. package/dist/assets/users-C9N-O1QA.js +1 -0
  130. package/dist/assets/workspace-BydSRtST.js +1 -0
  131. package/dist/assets/workspace-CJ1PWQ29.js +1 -0
  132. package/dist/assets/workspace-access-C9nZlBBZ.js +1 -0
  133. package/dist/assets/workspace-area-menu-Ba_9bGKs.js +1 -0
  134. package/dist/assets/workspace-content-gate-D8bzGD9i.js +1 -0
  135. package/dist/assets/workspace-import-form-D5JA8gzx.js +1 -0
  136. package/dist/assets/workspaces-C9Wtka2V.js +1 -0
  137. package/dist/assets/workspaces-Dx5_N57M.js +1 -0
  138. package/dist/index.html +69 -14
  139. package/dist/sw.js +1 -1
  140. package/package.json +2 -2
  141. package/dist/assets/EditorOverlay-B384ALjA.js +0 -1
  142. package/dist/assets/TextDocumentEditor-DBVWuJaR.js +0 -1
  143. package/dist/assets/alert-dialog-BC58hyW-.js +0 -1
  144. package/dist/assets/blobs-CtDkR2hC.js +0 -1
  145. package/dist/assets/code-editor-BQnKd3jw.js +0 -40
  146. package/dist/assets/document-list-BmUv3zzK.js +0 -19
  147. package/dist/assets/document-list-r-TfV16D.css +0 -1
  148. package/dist/assets/image-GAAHSSAO-BoD-NvEF.js +0 -1
  149. package/dist/assets/index-BhcdilCi.css +0 -2
  150. package/dist/assets/index-DRji5GQn.js +0 -61
  151. package/dist/assets/react-BzqgEMSQ.js +0 -164
  152. package/dist/assets/subtree-transfer-dialog-DRz8kLqY.js +0 -1
  153. package/dist/assets/text-documents-BvR9-zf4.js +0 -3
  154. package/dist/assets/useAddTarget-CgZfKokT.js +0 -1
  155. package/dist/assets/workspace-BSXnX2Me.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/subset-worker.chunk-D4w07nYk.js","assets/chunk-SRAX5OIU-Dhm3gOdh.js","assets/rolldown-runtime-C0FnF6B9.js","assets/chunk-EIO257PC-CAhBf1ig.js","assets/subset-shared.chunk-CzQ5JF2O.js","assets/image-GAAHSSAO-BoD-NvEF.js","assets/pica-XznpCgP2.js"])))=>i.map(i=>d[i]);
2
- import{o as e,t}from"./rolldown-runtime-C0FnF6B9.js";import{l as n,u as r}from"./code-editor-BQnKd3jw.js";import{t as i}from"./preload-helper-Czpn1I53.js";import{t as a}from"./utils-BxVxyehK.js";import{i as o}from"./chunk-SRAX5OIU-Dhm3gOdh.js";var s={VITE_APP_BACKEND_V2_GET_URL:`https://json.excalidraw.com/api/v2/`,VITE_APP_BACKEND_V2_POST_URL:`https://json.excalidraw.com/api/v2/post/`,VITE_APP_LIBRARY_URL:`https://libraries.excalidraw.com`,VITE_APP_LIBRARY_BACKEND:`https://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries`,VITE_APP_PLUS_LP:`https://plus.excalidraw.com`,VITE_APP_PLUS_APP:`https://app.excalidraw.com`,VITE_APP_AI_BACKEND:`https://oss-ai.excalidraw.com`,VITE_APP_WS_SERVER_URL:`https://oss-collab.excalidraw.com`,VITE_APP_FIREBASE_CONFIG:`{"apiKey":"AIzaSyAd15pYlMci_xIp9ko6wkEsDzAAA0Dn0RU","authDomain":"excalidraw-room-persistence.firebaseapp.com","databaseURL":"https://excalidraw-room-persistence.firebaseio.com","projectId":"excalidraw-room-persistence","storageBucket":"excalidraw-room-persistence.appspot.com","messagingSenderId":"654800341332","appId":"1:654800341332:web:4a692de832b55bd57ce0c1"}`,VITE_APP_ENABLE_TRACKING:`false`,VITE_APP_PLUS_EXPORT_PUBLIC_KEY:`MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApQ0jM9Qz8TdFLzcuAZZX
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/subset-worker.chunk-D4w07nYk.js","assets/chunk-SRAX5OIU-Dhm3gOdh.js","assets/rolldown-runtime-C0FnF6B9.js","assets/chunk-EIO257PC-CAhBf1ig.js","assets/subset-shared.chunk-CzQ5JF2O.js","assets/image-GAAHSSAO-CI-0hUck.js","assets/pica-XznpCgP2.js"])))=>i.map(i=>d[i]);
2
+ import{o as e,t}from"./rolldown-runtime-C0FnF6B9.js";import{l as n,u as r}from"./code-editor-BOIngd5F.js";import{t as i}from"./preload-helper-Czpn1I53.js";import{t as a}from"./utils-BxVxyehK.js";import{i as o}from"./chunk-SRAX5OIU-Dhm3gOdh.js";var s={VITE_APP_BACKEND_V2_GET_URL:`https://json.excalidraw.com/api/v2/`,VITE_APP_BACKEND_V2_POST_URL:`https://json.excalidraw.com/api/v2/post/`,VITE_APP_LIBRARY_URL:`https://libraries.excalidraw.com`,VITE_APP_LIBRARY_BACKEND:`https://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries`,VITE_APP_PLUS_LP:`https://plus.excalidraw.com`,VITE_APP_PLUS_APP:`https://app.excalidraw.com`,VITE_APP_AI_BACKEND:`https://oss-ai.excalidraw.com`,VITE_APP_WS_SERVER_URL:`https://oss-collab.excalidraw.com`,VITE_APP_FIREBASE_CONFIG:`{"apiKey":"AIzaSyAd15pYlMci_xIp9ko6wkEsDzAAA0Dn0RU","authDomain":"excalidraw-room-persistence.firebaseapp.com","databaseURL":"https://excalidraw-room-persistence.firebaseio.com","projectId":"excalidraw-room-persistence","storageBucket":"excalidraw-room-persistence.appspot.com","messagingSenderId":"654800341332","appId":"1:654800341332:web:4a692de832b55bd57ce0c1"}`,VITE_APP_ENABLE_TRACKING:`false`,VITE_APP_PLUS_EXPORT_PUBLIC_KEY:`MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApQ0jM9Qz8TdFLzcuAZZX
3
3
  /WvuKSOJxiw6AR/ZcE3eFQWM/mbFdhQgyK8eHGkKQifKzH1xUZjCxyXcxW6ZO02t
4
4
  kPOPxhz+nxUrIoWCD/V4NGmUA1lxwHuO21HN1gzKrN3xHg5EGjyouR9vibT9VDGF
5
5
  gq6+4Ic/kJX+AD2MM7Yre2+FsOdysrmuW2Fu3ahuC1uQE7pOe1j0k7auNP0y1q53
@@ -38,4 +38,4 @@ PQIDAQAB`,VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX:`false`,VITE_APP_COL
38
38
  `,w=v.ownerDocument.createElementNS(N,`style`);if(w.classList.add(`style-fonts`),w.appendChild(document.createTextNode(`${C}${S.join(C)}`)),y.appendChild(w),t.exportBackground&&s){let e=v.ownerDocument.createElementNS(N,`rect`);e.setAttribute(`x`,`0`),e.setAttribute(`y`,`0`),e.setAttribute(`width`,`${m}`),e.setAttribute(`height`,`${h}`),e.setAttribute(`fill`,s),v.appendChild(e)}let T=no.svg(v),E=r?.renderEmbeddables??!1;return mS(d,Vu(_u(d)),T,v,n||{},{offsetX:g,offsetY:_,isExporting:!0,exportWithDarkMode:o,renderEmbeddables:E,frameRendering:i,canvasBackgroundColor:s,embedsValidationStatus:E?new Map(d.filter(e=>ed(e)).map(e=>[e.id,!0])):new Map,reuseImages:r?.reuseImages??!0}),v},aC=({payload:e,metadataElement:t})=>{let n=gD(JSON.stringify(vD({text:e})),!0);t.appendChild(rC(`payload-type:${M.excalidraw}`)),t.appendChild(rC(`payload-version:2`)),t.appendChild(rC(`payload-start`)),t.appendChild(document.createTextNode(n)),t.appendChild(rC(`payload-end`))},oC=({svg:e})=>{if(e.includes(`payload-type:${M.excalidraw}`)){let t=e.match(/<!-- payload-start -->\s*(.+?)\s*<!-- payload-end -->/);if(!t)throw Error(`INVALID`);let n=(e.match(/<!-- payload-version:(\d+) -->/)?.[1]||`1`)!==`1`;try{let e=_D(t[1],n),r=JSON.parse(e);if(!(`encoded`in r)){if(`type`in r&&r.type===Js.excalidraw)return e;throw Error(`FAILED`)}return yD(r)}catch(e){throw console.error(e),Error(`FAILED`)}}throw Error(`INVALID`)},sC=(e,t)=>{let[n,r,i,a]=av(e);return[n,r,Ql(n,i)+t*2,Ql(r,a)+t*2]},cC=(e,t,n)=>{let[,,r,i]=sC(e,t).map(e=>Math.trunc(e*n));return[r,i]},lC=class{constructor(e){this.scoreFunction=e,o(this,`content`,[])}sinkDown(e){let t=this.content[e];for(;e>0;){let n=(e+1>>1)-1,r=this.content[n];if(this.scoreFunction(t)<this.scoreFunction(r))this.content[n]=t,this.content[e]=r,e=n;else break}}bubbleUp(e){let t=this.content.length,n=this.content[e],r=this.scoreFunction(n);for(;;){let i=e+1<<1,a=i-1,o=null,s=0;if(a<t){let e=this.content[a];s=this.scoreFunction(e),s<r&&(o=a)}if(i<t){let e=this.content[i];this.scoreFunction(e)<(o===null?r:s)&&(o=i)}if(o!==null)this.content[e]=this.content[o],this.content[o]=n,e=o;else break}}push(e){this.content.push(e),this.sinkDown(this.content.length-1)}pop(){if(this.content.length===0)return null;let e=this.content[0],t=this.content.pop();return this.content.length>0&&(this.content[0]=t,this.bubbleUp(0)),e}remove(e){if(this.content.length===0)return;let t=this.content.indexOf(e),n=this.content.pop();t<this.content.length&&(this.content[t]=n,this.scoreFunction(n)<this.scoreFunction(e)?this.sinkDown(t):this.bubbleUp(t))}size(){return this.content.length}rescoreElement(e){this.sinkDown(this.content.indexOf(e))}},uC=1,Z=40,dC=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let r=[];e.points.map(t=>I(e.x+t[0],e.y+t[1])).forEach((t,i,a)=>{if(i<2)return r.push(t);if(k_(D_(t,a[i-1]),D_(a[i-1],a[i-2]))){let t=n?.findIndex(e=>e.index===i-1)??-1,o=n?.findIndex(e=>e.index===i)??-1;o!==-1&&(n[o].start=I(a[i-2][0]-e.x,a[i-2][1]-e.y)),t!==-1&&n.splice(t,1),r.splice(-1,1),n.forEach(e=>{e.index>i-1&&--e.index})}return r.push(t)});let i=[];r.forEach((e,t,r)=>{if(t<3)return i.push(e);if(cl(r[t-2],r[t-1])<uC){let a=n?.findIndex(e=>e.index===t-2)??-1,o=n?.findIndex(e=>e.index===t-1)??-1;o!==-1&&n.splice(o,1),a!==-1&&n.splice(a,1),i.splice(-2,2),n.forEach(e=>{e.index>t-2&&(e.index-=2)});let s=O_(e,r[t-1]);return i.push(I(s?e[0]:r[t-2][0],s?r[t-2][1]:e[1]))}i.push(e)});let a=n.filter(e=>e.index!==1&&e.index!==i.length-1);return a.length===0?jC(MC(NC(_C(e,gC(e,t,i.map(t=>I(t[0]-e.x,t[1]-e.y)),e.startBinding&&AC(e.startBinding.elementId,t),e.endBinding&&AC(e.endBinding.elementId,t)))??[])),a,null,null):(s.DEV&&Nu(zC(i),`Invalid elbow points with fixed segments`),jC(i,a,e.startIsSpecial,e.endIsSpecial))}return{x:e.x,y:e.y,points:e.points,fixedSegments:e.fixedSegments,startIsSpecial:e.startIsSpecial,endIsSpecial:e.endIsSpecial}},fC=(e,t,n)=>{let r=t.map(e=>e.index),i=(e.fixedSegments?.map(e=>e.index)??[]).findIndex(e=>!r.includes(e));if(i===-1||!e.fixedSegments?.[i])return{points:e.points};let a=e.fixedSegments[i].index,o=e.fixedSegments[i-1],s=e.fixedSegments[i+1],c=e.x+(o?o.end[0]:0),l=e.y+(o?o.end[1]:0),u=o?null:e.startBinding,d=s?null:e.endBinding,{startHeading:f,endHeading:p,startGlobalPoint:m,endGlobalPoint:h,hoveredStartElement:g,hoveredEndElement:_,...v}=gC({x:c,y:l,startBinding:u,endBinding:d,startArrowhead:null,endArrowhead:null,points:e.points},n,[I(0,0),I(e.x+(s?.start[0]??e.points[e.points.length-1][0])-c,e.y+(s?.start[1]??e.points[e.points.length-1][1])-l)],u&&AC(u.elementId,n),d&&AC(d.elementId,n),{isDragging:!1}),{points:y}=jC(MC(NC(_C(e,{startHeading:f,endHeading:p,startGlobalPoint:m,endGlobalPoint:h,hoveredStartElement:g,hoveredEndElement:_,...v})??[])),t,null,null),b=[];if(o)for(let t=0;t<o.index;t++)b.push(I(e.x+e.points[t][0],e.y+e.points[t][1]));if(y.forEach(t=>{b.push(I(e.x+(o?o.end[0]:0)+t[0],e.y+(o?o.end[1]:0)+t[1]))}),s)for(let t=s.index;t<e.points.length;t++)b.push(I(e.x+e.points[t][0],e.y+e.points[t][1]));let x=(s?.index??e.points.length)-(o?.index??0)-1,S=t.map(e=>e.index>a?{...e,index:e.index-x+(y.length-1)}:e);return jC(b.flatMap((e,t)=>{let n=b[t-1],r=b[t+1];if(n&&r){let i=D_(e,n),a=D_(r,e);if(k_(i,a))return S.forEach(e=>{e.index>t&&--e.index}),[];if(k_(i,M_(a)))return S.forEach(e=>{e.index>t&&(e.index+=1)}),[e,e]}return[e]}),S,!1,!1)},pC=(e,t,n,r,i,a)=>{let o=t.map((t,n)=>e.fixedSegments==null||e.fixedSegments[n]===void 0||e.fixedSegments[n].index!==t.index||(t.start[0]!==e.fixedSegments[n].start[0]&&t.end[0]!==e.fixedSegments[n].end[0])!=(t.start[1]!==e.fixedSegments[n].start[1]&&t.end[1]!==e.fixedSegments[n].end[1])?n:null).filter(e=>e!==null).shift();if(o==null)return{points:e.points};let s=e.fixedSegments?.findIndex(e=>e.index===1)??-1,c=e.fixedSegments?.findIndex(t=>t.index===e.points.length-1)??-1,l=cl(t[o].start,t[o].end),u=l<Z+5;if(s===-1&&t[o].index===1&&i){let e=A_(n),r=(e?k_(n,x_):k_(n,S_))?u?l/2:Z:u?-l/2:-Z;t[o].start=I(t[o].start[0]+(e?r:0),t[o].start[1]+(e?0:r))}if(c===-1&&t[o].index===e.points.length-1&&a){let e=A_(r),n=(e?k_(r,x_):k_(r,S_))?u?l/2:Z:u?-l/2:-Z;t[o].end=I(t[o].end[0]+(e?n:0),t[o].end[1]+(e?0:n))}let d=t.map(t=>({...t,start:I(e.x+t.start[0],e.y+t.start[1]),end:I(e.x+t.end[0],e.y+t.end[1])})),f=e.points.map((t,n)=>I(e.x+t[0],e.y+t[1])),p=d[o].index-1,m=d[o].index,h=d[o].start,g=d[o].end,_=f[p-1]&&!al(f[p],f[p-1])?O_(f[p-1],f[p]):void 0,v=f[m+1]&&!al(f[m],f[m+1])?O_(f[m+1],f[m]):void 0;if(_!==void 0){let e=+!!_;f[p-1][e]=h[e]}if(f[p]=h,f[m]=g,v!==void 0){let e=+!!v;f[m+1][e]=g[e]}let y=d.findIndex(e=>e.index===p);if(y!==-1){let e=+!!O_(d[y].end,d[y].start);d[y].start[e]=h[e],d[y].end=h}let b=d.findIndex(e=>e.index===m+1);if(b!==-1){let e=+!!O_(d[b].end,d[b].start);d[b].end[e]=g[e],d[b].start=g}if(s===-1&&p===0){let t=i?A_(n):O_(f[1],f[0]);f.unshift(I(t?h[0]:e.x+e.points[0][0],t?e.y+e.points[0][1]:h[1])),i&&f.unshift(I(e.x+e.points[0][0],e.y+e.points[0][1]));for(let e of d)e.index+=i?2:1}if(c===-1&&m===e.points.length-1){let t=A_(r);f.push(I(t?g[0]:e.x+e.points[e.points.length-1][0],t?e.y+e.points[e.points.length-1][1]:g[1])),a&&f.push(I(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return jC(f,d.map(t=>({...t,start:I(t.start[0]-e.x,t.start[1]-e.y),end:I(t.end[0]-e.x,t.end[1]-e.y)})),!1,!1)},mC=(e,t,n,r,i,a,o,s,c)=>{let l=e.startIsSpecial??null,u=e.endIsSpecial??null,d=t.map((n,r)=>r===0||r===t.length-1?I(e.x+n[0],e.y+n[1]):I(e.x+e.points[r][0],e.y+e.points[r][1])),f=n.map(n=>({...n,start:I(e.x+(n.start[0]-t[0][0]),e.y+(n.start[1]-t[0][1])),end:I(e.x+(n.end[0]-t[0][0]),e.y+(n.end[1]-t[0][1]))})),p=[],m=2+ +!!l,h=2+ +!!u;for(;p.length+m<d.length-h;)p.push(d[p.length+m]);{let e=d[l?2:1],t=d[l?3:2],n=A_(r),i=A_(E_(F(e,t)));if(s&&n===i){let e=n?k_(r,x_):k_(r,S_);if(p.unshift(I(i?a[0]+(e?Z:-Z):t[0],i?t[1]:a[1]+(e?Z:-Z))),p.unshift(I(n?a[0]+(e?Z:-Z):a[0],n?a[1]:a[1]+(e?Z:-Z))),!l){l=!0;for(let e of f)e.index>1&&(e.index+=1)}}else if(p.unshift(I(i?a[0]:e[0],i?e[1]:a[1])),l){l=!1;for(let e of f)e.index>1&&--e.index}p.unshift(a)}{let e=d[d.length-(u?3:2)],t=d[d.length-(u?4:3)],n=A_(i),r=O_(t,e);if(c&&n===r){let e=n?k_(i,x_):k_(i,S_);p.push(I(r?o[0]+(e?Z:-Z):t[0],r?t[1]:o[1]+(e?Z:-Z))),p.push(I(n?o[0]+(e?Z:-Z):o[0],n?o[1]:o[1]+(e?Z:-Z))),u||=!0}else p.push(I(r?o[0]:e[0],r?e[1]:o[1])),u&&=!1}return p.push(o),jC(p,f.map(({index:e})=>({index:e,start:p[e-1],end:p[e]})).map(e=>({...e,start:I(e.start[0]-a[0],e.start[1]-a[1]),end:I(e.end[0]-a[0],e.end[1]-a[1])})),l,u)},Q=1e6,hC=(e,t,n,r)=>{if(e.points.length<2)return{points:n.points??e.points};(e.x<-Q||e.x>Q||e.y<-Q||e.y>Q||e.x+(n?.points?.[n?.points?.length-1]?.[0]??0)<-Q||e.x+(n?.points?.[n?.points?.length-1]?.[0]??0)>Q||e.y+(n?.points?.[n?.points?.length-1]?.[1]??0)<-Q||e.y+(n?.points?.[n?.points?.length-1]?.[1]??0)>Q||e.x+(e?.points?.[e?.points?.length-1]?.[0]??0)<-Q||e.x+(e?.points?.[e?.points?.length-1]?.[0]??0)>Q||e.y+(e?.points?.[e?.points?.length-1]?.[1]??0)<-Q||e.y+(e?.points?.[e?.points?.length-1]?.[1]??0)>Q)&&console.error(`Elbow arrow (or update) is outside reasonable bounds (> 1e6)`,{arrow:e,updates:n}),e.x=P(e.x,-Q,Q),e.y=P(e.y,-Q,Q),n.points&&=n.points.map(([e,t])=>I(P(e,-Q,Q),P(t,-Q,Q))),s.PROD||(Nu(!n.points||n.points.length>=2,`Updated point array length must match the arrow point length, contain exactly the new start and end points or not be specified at all (i.e. you can't add new points between start and end manually to elbow arrows)`),Nu(!e.fixedSegments||e.fixedSegments.map(e=>e.start[0]===e.end[0]||e.start[1]===e.end[1]).every(Boolean),`Fixed segments must be either horizontal or vertical`),Nu(!n.fixedSegments||n.fixedSegments.map(e=>e.start[0]===e.end[0]||e.start[1]===e.end[1]).every(Boolean),`Updates to fixed segments must be either horizontal or vertical`),Nu(e.points.slice(1).map((t,n)=>t[0]===e.points[n][0]||t[1]===e.points[n][1]),`Elbow arrow segments must be either horizontal or vertical`));let i=n.points?n.points&&n.points.length===2?e.points.map((t,r)=>r===0?n.points[0]:r===e.points.length-1?n.points[1]:t):n.points.slice():e.points.slice(),a=typeof n.startBinding<`u`?n.startBinding:e.startBinding,o=typeof n.endBinding<`u`?n.endBinding:e.endBinding,c=a&&AC(a.elementId,t),l=o&&AC(o.elementId,t);if(t.size===0&&zC(i)||c?.id!==a?.elementId||l?.id!==o?.elementId)return jC(i.map(t=>I(e.x+t[0],e.y+t[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:u,endHeading:d,startGlobalPoint:f,endGlobalPoint:p,hoveredStartElement:m,hoveredEndElement:h,...g}=gC({x:e.x,y:e.y,startBinding:a,endBinding:o,startArrowhead:e.startArrowhead,endArrowhead:e.endArrowhead,points:e.points},t,i,c,l,r),_=n.fixedSegments??e.fixedSegments??[];return!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?dC(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((t,n)=>al(t,e.points[n]??I(1/0,1/0)))?{}:_.length===0?jC(MC(NC(_C(e,{startHeading:u,endHeading:d,startGlobalPoint:f,endGlobalPoint:p,hoveredStartElement:m,hoveredEndElement:h,...g})??[])),_,null,null):(e.fixedSegments?.length??0)>_.length?fC(e,_,t):n.points?n.points&&n.fixedSegments?n:mC(e,i,_,u,d,f,p,m,h):pC(e,_,u,d,m,h)},gC=(e,t,n,r,i,a)=>{let o=ol(n[0],Jc(e.x,e.y)),s=ol(n[n.length-1],Jc(e.x,e.y)),c=r,l=i;if(a?.isDragging){let e=Array.from(t.values());c=LC(o,t,e,a?.zoom)||r,l=LC(s,t,e,a?.zoom)||i}let u=FC({...e,elbowed:!0,points:n},`start`,e.startBinding?.fixedPoint,o,r,c,a?.isDragging),d=FC({...e,elbowed:!0,points:n},`end`,e.endBinding?.fixedPoint,s,i,l,a?.isDragging),f=IC(u,d,t,c,o),p=IC(d,u,t,l,s),m=[u[0]-2,u[1]-2,u[0]+2,u[1]+2],h=[d[0]-2,d[1]-2,d[0]+2,d[1]+2],g=c?Ng(c,vC(f,e.startArrowhead?Y*6:Y*2,1)):m,_=l?Ng(l,vC(p,e.endArrowhead?Y*6:Y*2,1)):h,v=Pg(u,l?Ng(l,vC(p,Z,Z)):h)||Pg(d,c?Ng(c,vC(f,Z,Z)):m),y=kC(v?[m,h]:[g,_]),b=SC(v?m:g,v?h:_,y,v?vC(f,!c&&!l?0:Z,0):vC(f,!c&&!l?0:Z-(e.startArrowhead?Y*6:Y*2),Z),v?vC(p,!c&&!l?0:Z,0):vC(p,!c&&!l?0:Z-(e.endArrowhead?Y*6:Y*2),Z),v,c&&Ng(c),l&&Ng(l));return{dynamicAABBs:b,startDonglePosition:wC(b[0],f,u),startGlobalPoint:u,startHeading:f,endDonglePosition:wC(b[1],p,d),endGlobalPoint:d,endHeading:p,commonBounds:y,hoveredStartElement:c,hoveredEndElement:l,boundsOverlap:v,startElementBounds:g,endElementBounds:_}},_C=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:r,startGlobalPoint:i,startHeading:a,endDonglePosition:o,endGlobalPoint:s,endHeading:c,commonBounds:l,hoveredEndElement:u}=t,d=CC(n,r||i,a,o||s,c,l),f=r&&OC(r,d),p=o&&OC(o,d),m=OC(s,d);m&&u&&(m.closed=!0);let h=OC(i,d);h&&e.startBinding&&(h.closed=!0);let g=f&&p&&(Pg(f.pos,n[1])||Pg(p.pos,n[0])),_=yC(f||h,p||m,d,a||x_,c||x_,g?[]:n);if(_){let e=_.map(e=>[e.pos[0],e.pos[1]]);return f&&e.unshift(i),p&&e.push(s),e}return null},vC=(e,t,n)=>{switch(e){case w_:return[t,n,n,n];case x_:return[n,t,n,n];case S_:return[n,n,t,n]}return[n,n,n,t]},yC=(e,t,n,r,i,a)=>{let o=xC(e.pos,t.pos),s=new lC(e=>e.f);for(s.push(e);s.size()>0;){let c=s.pop();if(!c||c.closed)continue;if(c===t)return bC(e,c);c.closed=!0;let l=EC(c.addr,n);for(let n=0;n<4;n++){let u=l[n];if(!u||u.closed)continue;let d=ul(u.pos,c.pos,.5);if(Uu(...a.map(e=>Pg(d,e))))continue;let f=PC(n),p=c.parent?E_(F(c.pos,c.parent.pos)):r;if(k_(M_(p),f)||RC(e.addr,u.addr)&&k_(f,r)||RC(t.addr,u.addr)&&k_(f,i))continue;let m=p!==f,h=c.g+xC(u.pos,c.pos)+(m?o**3:0),g=u.visited;if(!g||h<u.g){let e=TC(u,t,f,i);u.visited=!0,u.parent=c,u.h=xC(t.pos,u.pos)+e*o**2,u.g=h,u.f=u.g+u.h,g?s.rescoreElement(u):s.push(u)}}}return null},bC=(e,t)=>{let n=t,r=[];for(;n.parent;)r.unshift(n),n=n.parent;return r.unshift(e),r},xC=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),SC=(e,t,n,r,i,a,o,s)=>{let c=o??e,l=s??t,[u,d,f,p]=r??[0,0,0,0],[m,h,g,_]=i??[0,0,0,0],v=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((c[0]+l[2])/2,e[0]-p):(c[0]+l[2])/2:e[0]>t[0]?e[0]-p:n[0]-p,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((c[1]+l[3])/2,e[1]-u):(c[1]+l[3])/2:e[1]>t[1]?e[1]-u:n[1]-u,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((c[2]+l[0])/2,e[2]+d):(c[2]+l[0])/2:e[2]<t[2]?e[2]+d:n[2]+d,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((c[3]+l[1])/2,e[3]+f):(c[3]+l[1])/2:e[3]<t[3]?e[3]+f:n[3]+f],y=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((l[0]+c[2])/2,t[0]-_):(l[0]+c[2])/2:t[0]>e[0]?t[0]-_:n[0]-_,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((l[1]+c[3])/2,t[1]-m):(l[1]+c[3])/2:t[1]>e[1]?t[1]-m:n[1]-m,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((l[2]+c[0])/2,t[2]+h):(l[2]+c[0])/2:t[2]<e[2]?t[2]+h:n[2]+h,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((l[3]+c[1])/2,t[3]+g):(l[3]+c[1])/2:t[3]<e[3]?t[3]+g:n[3]+g],b=kC([v,y]);if(!a&&v[2]-v[0]+y[2]-y[0]>b[2]-b[0]+1e-11&&v[3]-v[1]+y[3]-y[1]>b[3]-b[1]+1e-11){let[n,r]=[(y[0]+y[2])/2,(y[1]+y[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let t=v[2]+(y[0]-v[2])/2,i=y[3]+(v[1]-y[3])/2;return Yc(Jc(e[2]-n,e[1]-r),Jc(e[0]-n,e[3]-r))>0?[[v[0],v[1],t,v[3]],[t,y[1],y[2],y[3]]]:[[v[0],i,v[2],v[3]],[y[0],y[1],y[2],i]]}if(e[2]<t[0]&&e[3]<t[1]){let t=v[2]+(y[0]-v[2])/2,i=v[3]+(y[1]-v[3])/2;return Yc(Jc(e[0]-n,e[1]-r),Jc(e[2]-n,e[3]-r))>0?[[v[0],v[1],v[2],i],[y[0],i,y[2],y[3]]]:[[v[0],v[1],t,v[3]],[t,y[1],y[2],y[3]]]}if(e[0]>t[2]&&e[3]<t[1]){let t=y[2]+(v[0]-y[2])/2,i=v[3]+(y[1]-v[3])/2;return Yc(Jc(e[2]-n,e[1]-r),Jc(e[0]-n,e[3]-r))>0?[[t,v[1],v[2],v[3]],[y[0],y[1],t,y[3]]]:[[v[0],v[1],v[2],i],[y[0],i,y[2],y[3]]]}if(e[0]>t[2]&&e[1]>t[3]){let t=y[2]+(v[0]-y[2])/2,i=y[3]+(v[1]-y[3])/2;return Yc(Jc(e[0]-n,e[1]-r),Jc(e[2]-n,e[3]-r))>0?[[t,v[1],v[2],v[3]],[y[0],y[1],t,y[3]]]:[[v[0],i,v[2],v[3]],[y[0],y[1],y[2],i]]}}return[v,y]},CC=(e,t,n,r,i,a)=>{let o=new Set,s=new Set;n===C_||n===x_?s.add(t[1]):o.add(t[0]),i===C_||i===x_?s.add(r[1]):o.add(r[0]),e.forEach(e=>{o.add(e[0]),o.add(e[2]),s.add(e[1]),s.add(e[3])}),o.add(a[0]),o.add(a[2]),s.add(a[1]),s.add(a[3]);let c=Array.from(s).sort((e,t)=>e-t),l=Array.from(o).sort((e,t)=>e-t);return{row:c.length,col:l.length,data:c.flatMap((e,t)=>l.map((n,r)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[r,t],pos:[n,e]})))}},wC=(e,t,n)=>{switch(t){case w_:return I(n[0],e[1]);case x_:return I(e[2],n[1]);case S_:return I(n[0],e[3])}return I(e[0],n[1])},TC=(e,t,n,r)=>{if(r===x_)switch(n){case x_:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case w_:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case S_:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case C_:return e.pos[1]===t.pos[1]?4:2}else if(r===C_)switch(n){case x_:return e.pos[1]===t.pos[1]?4:2;case w_:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case S_:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case C_:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(r===w_)switch(n){case x_:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case w_:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case S_:return e.pos[0]===t.pos[0]?4:2;case C_:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(r===S_)switch(n){case x_:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case w_:return e.pos[0]===t.pos[0]?4:2;case S_:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case C_:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},EC=([e,t],n)=>[DC([e,t-1],n),DC([e+1,t],n),DC([e,t+1],n),DC([e-1,t],n)],DC=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,OC=(e,t)=>{for(let n=0;n<t.col;n++)for(let r=0;r<t.row;r++){let i=DC([n,r],t);if(i&&e[0]===i.pos[0]&&e[1]===i.pos[1])return i}return null},kC=e=>[Math.min(...e.map(e=>e[0])),Math.min(...e.map(e=>e[1])),Math.max(...e.map(e=>e[2])),Math.max(...e.map(e=>e[3]))],AC=(e,t)=>{let n=t.get(e);return n&&sd(n)?n:null},jC=(e,t,n,r)=>{let i=e[0][0],a=e[0][1],o=e.map(t=>ol(t,$c(F(e[0]),-1)));return(i<-Q||i>Q||a<-Q||a>Q||i+o[o.length-1][0]<-Q||a+o[o.length-1][0]>Q||i+o[o.length-1][1]<-Q||a+o[o.length-1][1]>Q)&&console.error(`Elbow arrow normalization is outside reasonable bounds (> 1e6)`,{x:i,y:a,points:o,...V_(o)}),o=o.map(([e,t])=>I(P(e,-1e6,1e6),P(t,-1e6,1e6))),{points:o,x:P(i,-1e6,1e6),y:P(a,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...V_(o),startIsSpecial:n,endIsSpecial:r}},MC=e=>{if(e.length>1){let t=Math.abs(e[0][1]-e[1][1])<Math.abs(e[0][0]-e[1][0]);return e.filter((n,r)=>{if(r===0||r===e.length-1)return!0;let i=e[r+1],a=Math.abs(n[1]-i[1])<Math.abs(n[0]-i[0]);return t===a?(t=a,!1):(t=a,!0)})}return e},NC=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let r=e[n-1];return cl(r,t)>uC}):e,PC=e=>{switch(e){case 0:return w_;case 1:return x_;case 2:return S_}return C_},FC=(e,t,n,r,i,a,o)=>{if(o)return a?Jv(a,Gv(e,a,t)):r;if(i){let r=py(n||[0,0],i);return Math.abs(mv(i,r)-Y)>.01?Gv(e,i,t):r}return r},IC=(e,t,n,r,i)=>Uv(e,t,r,r&&Ng(r,[,,,,].fill(mv(r,e))),n,i),LC=(e,t,n,r)=>Iv(ou(e),n,t,r,!0,!0),RC=(e,t)=>e[0]===t[0]&&e[1]===t[1],zC=(e,t=uC)=>e.slice(1).map((n,r)=>Math.abs(n[0]-e[r][0])<t||Math.abs(n[1]-e[r][1])<t).every(Boolean),BC={selection:!0,text:!0,rectangle:!0,diamond:!0,ellipse:!0,line:!0,image:!0,arrow:!0,freedraw:!0,eraser:!1,custom:!0,frame:!0,embeddable:!0,hand:!0,laser:!1,magicframe:!1},VC=e=>Object.keys(js).includes(e)?js[e]:Ls,HC=(e,t)=>{if(!t)return null;let n=t.focus||0;return H(e)?vd(t)?{...t,focus:n,fixedPoint:gy(t.fixedPoint??[0,0])}:null:{...t,focus:n}},UC=(e,t)=>{let n={type:t.type||e.type,version:e.version||1,versionNonce:e.versionNonce??0,index:e.index??null,isDeleted:e.isDeleted??!1,id:e.id||tx(),fillStyle:e.fillStyle||_c.fillStyle,strokeWidth:e.strokeWidth||_c.strokeWidth,strokeStyle:e.strokeStyle??_c.strokeStyle,roughness:e.roughness??_c.roughness,opacity:e.opacity==null?_c.opacity:e.opacity,angle:e.angle||0,x:t.x??e.x??0,y:t.y??e.y??0,strokeColor:e.strokeColor||_c.strokeColor,backgroundColor:e.backgroundColor||_c.backgroundColor,width:e.width||0,height:e.height||0,seed:e.seed??1,groupIds:e.groupIds??[],frameId:e.frameId??null,roundness:e.roundness?e.roundness:e.strokeSharpness===`round`?{type:md(e.type)?mc.LEGACY:mc.PROPORTIONAL_RADIUS}:null,boundElements:e.boundElementIds?e.boundElementIds.map(e=>({type:`arrow`,id:e})):e.boundElements??[],updated:e.updated??gu(),link:e.link?Ib(e.link):null,locked:e.locked??!1};return(`customData`in e||`customData`in t)&&(n.customData=`customData`in t?t.customData:e.customData),{...e,...n,...YT(n),...t}},WC=e=>{switch(e={...e},e.type){case`text`:delete e.rawText;let t=e.fontSize,n=e.fontFamily;if(`font`in e){let[r,i]=e.font.split(` `);t=parseFloat(r),n=VC(i)}let r=typeof e.text==`string`&&e.text||``,i=e.lineHeight||(e.height?Ed(e):Ih(e.fontFamily));return e=UC(e,{fontSize:t,fontFamily:n,text:r,textAlign:e.textAlign||`left`,verticalAlign:e.verticalAlign||`top`,containerId:e.containerId??null,originalText:e.originalText||r,autoResize:e.autoResize??!0,lineHeight:i}),!r&&!e.isDeleted&&(e={...e,originalText:r,isDeleted:!0},e=UT(e)),e;case`freedraw`:return UC(e,{points:e.points,lastCommittedPoint:null,simulatePressure:e.simulatePressure,pressures:e.pressures});case`image`:return UC(e,{status:e.status||`pending`,fileId:e.fileId,scale:e.scale||[1,1],crop:e.crop??null});case`line`:case`draw`:let{startArrowhead:a=null,endArrowhead:o=null}=e,s=e.x,c=e.y,l=!Array.isArray(e.points)||e.points.length<2?[I(0,0),I(e.width,e.height)]:e.points;return(l[0][0]!==0||l[0][1]!==0)&&({points:l,x:s,y:c}=X.getNormalizedPoints(e)),UC(e,{type:e.type===`draw`?`line`:e.type,startBinding:HC(e,e.startBinding),endBinding:HC(e,e.endBinding),lastCommittedPoint:null,startArrowhead:a,endArrowhead:o,points:l,x:s,y:c,...V_(l)});case`arrow`:{let{startArrowhead:t=null,endArrowhead:n=`arrow`}=e,r=e.x,i=e.y,a=!Array.isArray(e.points)||e.points.length<2?[I(0,0),I(e.width,e.height)]:e.points;(a[0][0]!==0||a[0][1]!==0)&&({points:a,x:r,y:i}=X.getNormalizedPoints(e));let o={type:e.type,startBinding:HC(e,e.startBinding),endBinding:HC(e,e.endBinding),lastCommittedPoint:null,startArrowhead:t,endArrowhead:n,points:a,x:r,y:i,elbowed:e.elbowed,...V_(a)};return H(e)?UC(e,{...o,elbowed:!0,startBinding:HC(e,e.startBinding),endBinding:HC(e,e.endBinding),fixedSegments:e.fixedSegments,startIsSpecial:e.startIsSpecial,endIsSpecial:e.endIsSpecial}):UC(e,o)}case`ellipse`:case`rectangle`:case`diamond`:case`iframe`:case`embeddable`:return UC(e,{});case`magicframe`:case`frame`:return UC(e,{name:e.name??null})}return null},GC=(e,t)=>{if(e.boundElements){let n=e.boundElements.slice(),r=new Set;e.boundElements=n.reduce((n,i)=>{let a=t.get(i.id);if(a&&!r.has(i.id)){if(r.add(i.id),a.isDeleted)return n;n.push(i),B(a)&&!a.containerId&&(a.containerId=e.id)}return n},[])}},KC=(e,t)=>{let n=e.containerId?t.get(e.containerId):null;if(!n){e.containerId=null;return}if(!e.isDeleted&&n.boundElements&&!n.boundElements.find(t=>t.id===e.id)){let t=(n.boundElements||=[]).slice();t.push({type:`text`,id:e.id}),n.boundElements=t}},qC=(e,t)=>{e.frameId&&(t.get(e.frameId)||(e.frameId=null))},JC=(e,t,n)=>{let r=new Set,i=t?_u(t):null,a=Ex((e||[]).reduce((e,t)=>{if(t.type!==`selection`&&!WT(t)){let n=WC(t);if(n){let a=i?.get(t.id);a&&a.version>n.version&&(n=UT(n,a.version)),r.has(n.id)&&(n={...n,id:tx()}),r.add(n.id),e.push(n)}}return e},[]));if(!n?.repairBindings)return a;let o=_u(a);for(let e of a)e.frameId&&qC(e,o),B(e)&&e.containerId?KC(e,o):e.boundElements&&GC(e,o),n.refreshDimensions&&B(e)&&Object.assign(e,fx(e,wb(e,o),o)),rd(e)&&(e.startBinding&&(!o.has(e.startBinding.elementId)||!V(e))&&(e.startBinding=null),e.endBinding&&(!o.has(e.endBinding.elementId)||!V(e))&&(e.endBinding=null));return a.map(e=>{if(H(e)&&e.startBinding==null&&e.endBinding==null&&!zC(e.points))return{...e,...hC(e,o,{points:[I(0,0),e.points[e.points.length-1]]}),index:e.index};if(H(e)&&e.startBinding&&e.endBinding&&e.startBinding.elementId===e.endBinding.elementId&&e.points.length>1&&e.points.some(([e,t])=>Math.abs(e)>1e6||Math.abs(t)>1e6)){console.error(`Fixing self-bound elbow arrow`,e.id);let t=o.get(e.startBinding.elementId);return t?{...e,x:t.x+t.width/2,y:t.y-5,width:t.width,height:t.height,points:[I(0,0),I(0,-10),I(t.width/2+5,-10),I(t.width/2+5,t.height/2+5)]}:(console.error(`Bound element not found`,e.startBinding.elementId),e)}return e})},YC=(e,t,n)=>{let r=t[e];return r===void 0?n[e]:r},XC={isSidebarDocked:(e,t)=>[`defaultSidebarDockedPreference`,e.isSidebarDocked??YC(`defaultSidebarDockedPreference`,e,t)]},ZC=(e,t)=>{e||={};let n=Mc(),r={};for(let t of Object.keys(XC))if(t in e){let[i,a]=XC[t](e,n);r[i]=a}for(let[i,a]of Object.entries(n)){let n=e[i],o=t?t[i]:void 0;r[i]=n===void 0?o===void 0?a:o:n}return{...r,cursorButton:t?.cursorButton||`up`,penDetected:t?.penDetected??(e.penMode?e.penDetected??!1:!1),activeTool:{...$l(n,r.activeTool.type&&BC[r.activeTool.type]?r.activeTool:{type:`selection`}),lastActiveTool:null,locked:r.activeTool.locked??!1},zoom:{value:by(Hc(e.zoom)?e.zoom:e.zoom?.value??n.zoom.value)},openSidebar:typeof e.openSidebar==`string`?{name:bc.name}:r.openSidebar,gridSize:xy(Hc(e.gridSize)?e.gridSize:20),gridStep:Sy(Hc(e.gridStep)?e.gridStep:Ws),editingFrame:null}},QC=(e,t,n,r)=>({elements:JC(e?.elements,n,r),appState:ZC(e?.appState,t||null),files:e?.files||{}}),$C=e=>{let t=JC(LE(e.elements),null);return t.length?{...e,elements:t}:null},ew=(e=[],t)=>{let n=[];for(let r of e)if(Array.isArray(r)){let e=$C({status:t,elements:r,id:tx(),created:Date.now()});e&&n.push(e)}else{let e=r,i=$C({...e,id:e.id||tx(),status:e.status||t,created:e.created||Date.now()});i&&n.push(i)}return n},tw=32,nw=12,rw=256,iw=50,aw=`NOT_SPREADSHEET`,ow=`VALID_SPREADSHEET`,sw=e=>{let t=/^([-+]?)[$€£¥₩]?([-+]?)([\d.,]+)[%]?$/.exec(e);return t?parseFloat(`${(t[1]||t[2])+t[3]}`.replace(/,/g,``)):null},cw=(e,t)=>e.slice(1).every(e=>sw(e[t])!==null),lw=e=>{let t=e[0].length;if(t>2)return{type:aw,reason:`More than 2 columns`};if(t===1){if(!cw(e,0))return{type:aw,reason:`Value is not numeric`};let t=sw(e[0][0])===null,n=(t?e.slice(1):e).map(e=>sw(e[0]));return n.length<2?{type:aw,reason:`Less than two rows`}:{type:ow,spreadsheet:{title:t?e[0][0]:null,labels:null,values:n}}}let n=cw(e,0),r=cw(e,1);if(!n&&!r)return{type:aw,reason:`Value is not numeric`};let[i,a]=r?[0,1]:[1,0],o=sw(e[0][a])===null,s=o?e.slice(1):e;return s.length<2?{type:aw,reason:`Less than 2 rows`}:{type:ow,spreadsheet:{title:o?e[0][a]:null,labels:s.map(e=>e[i]),values:s.map(e=>sw(e[a]))}}},uw=e=>{let t=[];for(let n=0;n<e[0].length;n++){let r=[];for(let t=0;t<e.length;t++)r.push(e[t][n]);t.push(r)}return t},dw=e=>{let t=e.trim().split(`
39
39
  `).map(e=>e.trim().split(` `));if(t.length&&t[0].length!==2&&(t=e.trim().split(`
40
40
  `).map(e=>e.trim().split(`,`))),t.length===0)return{type:aw,reason:`No values`};let n=t[0].length;if(!t.every(e=>e.length===n))return{type:aw,reason:`All rows don't have same number of columns`};let r=lw(t);if(r.type!==ow){let e=lw(uw(t));if(e.type===ow)return e}return r},fw=us(ts),pw={fillStyle:`hachure`,fontFamily:Ls,fontSize:20,opacity:100,roughness:1,strokeColor:j.black,roundness:null,strokeStyle:`solid`,strokeWidth:1,verticalAlign:lc.MIDDLE,locked:!1},mw=e=>({chartWidth:(tw+nw)*e.values.length+nw,chartHeight:rw+nw*2}),hw=(e,t,n,r,i)=>e.labels?.map((e,a)=>lx({groupIds:[r],backgroundColor:i,...pw,text:e.length>8?`${e.slice(0,5)}...`:e,x:t+a*(tw+nw)+nw*2,y:n+nw/2,width:tw,angle:5.87,fontSize:16,textAlign:`center`,verticalAlign:`top`}))||[],gw=(e,t,n,r,i)=>{let a=lx({groupIds:[r],backgroundColor:i,...pw,x:t-nw,y:n-nw,text:`0`,textAlign:`right`});return[a,lx({groupIds:[r],backgroundColor:i,...pw,x:t-nw,y:n-rw-a.height/2,text:Math.max(...e.values).toLocaleString(),textAlign:`right`})]},_w=(e,t,n,r,i)=>{let{chartWidth:a,chartHeight:o}=mw(e);return[mx({backgroundColor:i,groupIds:[r],...pw,type:`line`,x:t,y:n,width:a,points:[I(0,0),I(a,0)]}),mx({backgroundColor:i,groupIds:[r],...pw,type:`line`,x:t,y:n,height:o,points:[I(0,0),I(0,-o)]}),mx({backgroundColor:i,groupIds:[r],...pw,type:`line`,x:t,y:n-rw-nw,strokeStyle:`dotted`,width:a,opacity:iw,points:[I(0,0),I(a,0)]})]},vw=(e,t,n,r,i,a)=>{let{chartWidth:o,chartHeight:s}=mw(e),c=e.title?lx({backgroundColor:i,groupIds:[r],...pw,text:e.title,x:t+o/2,y:n-rw-nw*2-20,roundness:null,textAlign:`center`}):null,l=a?rx({backgroundColor:i,groupIds:[r],...pw,type:`rectangle`,x:t,y:n-s,width:o,height:s,strokeColor:j.black,fillStyle:`solid`,opacity:6}):null;return[...l?[l]:[],...c?[c]:[],...hw(e,t,n,r,i),...gw(e,t,n,r,i),..._w(e,t,n,r,i)]},yw=(e,t,n)=>{let r=Math.max(...e.values),i=tx(),a=fw[Math.floor(Math.random()*fw.length)];return[...e.values.map((e,o)=>{let s=e/r*rw;return rx({backgroundColor:a,groupIds:[i],...pw,type:`rectangle`,x:t+o*(tw+nw)+nw,y:n-s-nw,width:tw,height:s})}),...vw(e,t,n,i,a,s.DEV)]},bw=(e,t,n)=>{let r=Math.max(...e.values),i=tx(),a=fw[Math.floor(Math.random()*fw.length)],o=0,c=[];for(let t of e.values){let e=o*(tw+nw),n=-(t/r)*rw;c.push([e,n]),o++}let l=Math.max(...c.map(e=>e[0])),u=Math.max(...c.map(e=>e[1])),d=Math.min(...c.map(e=>e[0])),f=Math.min(...c.map(e=>e[1])),p=mx({backgroundColor:a,groupIds:[i],...pw,type:`line`,x:t+nw+tw/2,y:n-nw,height:u-f,width:l-d,strokeWidth:2,points:c}),m=e.values.map((e,o)=>{let s=o*(tw+nw)+nw/2,c=-(e/r)*rw+nw/2;return rx({backgroundColor:a,groupIds:[i],...pw,fillStyle:`solid`,strokeWidth:2,type:`ellipse`,x:t+s+tw/2,y:n+c-nw*2,width:nw,height:nw})}),h=e.values.map((e,o)=>{let s=o*(tw+nw)+nw/2,c=e/r*rw+nw/2+nw;return mx({backgroundColor:a,groupIds:[i],...pw,type:`line`,x:t+s+tw/2+nw/2,y:n-c,height:c,strokeStyle:`dotted`,opacity:iw,points:[I(0,0),I(0,c)]})});return[...vw(e,t,n,i,a,s.DEV),p,...h,...m]},xw=(e,t,n,r)=>e===`line`?bw(t,n,r):yw(t,n,r);`clipboard`in navigator&&`readText`in navigator.clipboard;var Sw=`clipboard`in navigator&&`writeText`in navigator.clipboard,Cw=`clipboard`in navigator&&`write`in navigator.clipboard&&`ClipboardItem`in window&&`toBlob`in HTMLCanvasElement.prototype,ww=e=>!!([Js.excalidraw,Js.excalidrawClipboard,Js.excalidrawClipboardWithAPI].includes(e?.type)&&Array.isArray(e.elements)),Tw=({types:e,files:t})=>{!e&&!t&&console.warn(`createPasteEvent: no types or files provided`);let n=new ClipboardEvent(`paste`,{clipboardData:new DataTransfer});if(e)for(let[r,i]of Object.entries(e)){if(typeof i!=`string`){t||=[],t.push(i);continue}try{if(n.clipboardData?.setData(r,i),n.clipboardData?.getData(r)!==i)throw Error(`Failed to set "${r}" as clipboardData item`)}catch(e){throw Error(e.message)}}if(t){let e=-1;for(let r of t){e++;try{if(n.clipboardData?.items.add(r),n.clipboardData?.files[e]!==r)throw Error(`Failed to set file "${r.name}" as clipboardData item`)}catch(e){throw Error(e.message)}}}return n},Ew=({elements:e,files:t})=>{let n=_u(e),r=new Set(e.filter(e=>ed(e))),i=!1,a=e.reduce((e,n)=>(qu(n)&&(i=!0,t&&t[n.fileId]&&(e[n.fileId]=t[n.fileId])),e),{});i&&!t&&console.warn("copyToClipboard: attempting to file element(s) without providing associated `files` object.");let o={type:Js.excalidrawClipboard,elements:e.map(e=>{if(mT(e,n)&&!r.has(mT(e,n))){let t=vx(e);return $(t,{frameId:null}),t}return e}),files:t?a:void 0};return JSON.stringify(o)},Dw=async(e,t,n)=>{await Fw(Ew({elements:e,files:t}),n)},Ow=e=>{let t=dw(e);return t.type===ow?{spreadsheet:t.spreadsheet}:null};function kw(e){let t=[];for(let n of e.childNodes)if(n.nodeType===3){let e=n.textContent?.trim();e&&t.push({type:`text`,value:e})}else if(n instanceof HTMLImageElement){let e=n.getAttribute(`src`);e&&e.startsWith(`http`)&&t.push({type:`imageUrl`,value:e})}else t=t.concat(kw(n));return t}var Aw=e=>{let t=e.clipboardData?.getData(M.html);if(!t)return null;try{let e=kw(new DOMParser().parseFromString(t,M.html).body);if(e.length)return{type:`mixedContent`,value:e}}catch(e){console.error(`error in parseHTMLFromPaste: ${e.message}`)}return null},jw=async()=>{let e={},t;try{t=await navigator.clipboard?.read()}catch(t){try{if(navigator.clipboard?.readText){console.warn(`navigator.clipboard.readText() failed (${t.message}). Failling back to navigator.clipboard.read()`);let e=await navigator.clipboard?.readText();if(e)return{[M.text]:e}}}catch(t){if(navigator.clipboard?.read)console.warn(`navigator.clipboard.readText() failed (${t.message}). Failling back to navigator.clipboard.read()`);else{if(t.name===`DataError`)return console.warn(`navigator.clipboard.read() error, clipboard is probably empty: ${t.message}`),e;throw t}}throw t}for(let n of t)for(let t of n.types)if(Fu(Ks,t))try{if(t===M.text||t===M.html)e[t]=await(await n.getType(t)).text();else if(KE(t))e[t]=uD(await n.getType(t),t,void 0);else throw new uh(`Unsupported clipboard type: ${t}`)}catch(e){console.warn(e instanceof uh?e.message:`Cannot retrieve ${t} from clipboardItem: ${e.message}`)}return Object.keys(e).length===0&&console.warn(`No clipboard data found from clipboard.read().`),e},Mw=async(e,t=!1)=>{try{let n=!t&&e&&Aw(e);return n?n.value.every(e=>e.type===`text`)?{type:`text`,value:e.clipboardData?.getData(M.text)||n.value.map(e=>e.value).join(`
41
- `).trim()}:n:{type:`text`,value:(e.clipboardData?.getData(M.text)||``).trim()}}catch{return{type:`text`,value:``}}},Nw=async(e,t=!1)=>{let n=await Mw(e,t);if(n.type===`mixedContent`)return{mixedContent:n.value};try{let e=!t&&Ow(n.value);if(e)return e}catch(e){console.error(e)}try{let e=JSON.parse(n.value),r=e.type===Js.excalidrawClipboardWithAPI;if(ww(e))return{elements:e.elements,files:e.files,text:t?JSON.stringify(e.elements,null,2):void 0,programmaticAPI:r}}catch{}return{text:n.value}},Pw=async e=>{try{await navigator.clipboard.write([new window.ClipboardItem({[M.png]:e})])}catch(t){if(Du(e))await navigator.clipboard.write([new window.ClipboardItem({[M.png]:await e})]);else throw t}},Fw=async(e,t)=>{if(Sw)try{await navigator.clipboard.writeText(e||``);return}catch(e){console.error(e)}try{if(t){if(t.clipboardData?.setData(M.text,e||``),t.clipboardData?.getData(M.text)!==e)throw Error(`Failed to setData on clipboardEvent`);return}}catch(e){console.error(e)}if(!Iw(e))throw Error(`Error copying to clipboard.`)},Iw=e=>{e||=` `;let t=document.documentElement.getAttribute(`dir`)===`rtl`,n=document.createElement(`textarea`);n.style.border=`0`,n.style.padding=`0`,n.style.margin=`0`,n.style.position=`absolute`,n.style[t?`right`:`left`]=`-9999px`;let r=window.pageYOffset||document.documentElement.scrollTop;n.style.top=`${r}px`,n.style.fontSize=`12pt`,n.setAttribute(`readonly`,``),n.value=e,document.body.appendChild(n);let i=!1;try{n.select(),n.setSelectionRange(0,n.value.length),i=document.execCommand(`copy`)}catch(e){console.error(e)}return n.remove(),i},Lw=({elements:e,appState:t,files:n,maxWidthOrHeight:r,getDimensions:i,exportPadding:a,exportingFrame:o})=>{let{elements:s,appState:c}=QC({elements:e,appState:t},null,null),{exportBackground:l,viewBackgroundColor:u}=c;return nC(s,{...c,offsetTop:0,offsetLeft:0,width:0,height:0},n||{},{exportBackground:l,exportPadding:a,viewBackgroundColor:u,exportingFrame:o},(e,n)=>{let a=document.createElement(`canvas`);if(r){typeof i==`function`&&console.warn("`getDimensions()` is ignored when `maxWidthOrHeight` is supplied.");let o=Math.max(e,n),s=r<o?r/o:t?.exportScale??1;return a.width=e*s,a.height=n*s,{canvas:a,scale:s}}let o=i?.(e,n)||{width:e,height:n};return a.width=o.width,a.height=o.height,{canvas:a,scale:o.scale??1}})},Rw=async e=>{let{mimeType:t=M.png,quality:n}=e;t===M.png&&typeof n==`number`&&console.warn(`"quality" will be ignored for "${M.png}" mimeType`),t===`image/jpg`&&(t=M.jpg),t===M.jpg&&!e.appState?.exportBackground&&(console.warn(`Defaulting "exportBackground" to "true" for "${M.jpg}" mimeType`),e={...e,appState:{...e.appState,exportBackground:!0}});let r=await Lw(e);return n||=/image\/jpe?g/.test(t)?.92:.8,new Promise((i,a)=>{r.toBlob(async n=>{if(!n)return a(Error(`couldn't export to blob`));n&&t===M.png&&e.appState?.exportEmbedScene&&(n=await xD({blob:n,metadata:yS(e.elements,e.appState,e.files||{},`local`)})),i(n)},t,n)})},zw=async({elements:e,appState:t=Mc(),files:n={},exportPadding:r,renderEmbeddables:i,exportingFrame:a,skipInliningFonts:o,reuseImages:s})=>{let{elements:c,appState:l}=QC({elements:e,appState:t},null,null);return iC(c,{...l,exportPadding:r},n,{exportingFrame:a,renderEmbeddables:i,skipInliningFonts:o,reuseImages:s})},Bw=e=>e.type===`diamond`?[I(e.width/2,0),I(e.width,e.height/2),I(e.width/2,e.height),I(0,e.height/2)]:[I(0,0),I(0+e.width,0),I(0+e.width,e.height),I(0,e.height)],Vw=e=>rd(e)||td(e)?e.points:Bw(e),Hw=e=>{let t=e.reduce((e,[t,n])=>(e.minY=Math.min(e.minY,n),e.minX=Math.min(e.minX,t),e.maxX=Math.max(e.maxX,t),e.maxY=Math.max(e.maxY,n),e),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,cx:0,cy:0});return t.cx=(t.maxX+t.minX)/2,t.cy=(t.maxY+t.minY)/2,t},Uw=e=>{let t=Vw(e),{cx:n,cy:r}=Hw(t),i=I(n,r),{minX:a,minY:o,maxX:s,maxY:c}=Hw(t.map(t=>R(t,i,e.angle)));return[a+e.x,o+e.y,s+e.x,c+e.y]},Ww=(e,t,n=!1)=>{let r=Uw(e),i=t[0]<=r[0]&&t[2]>=r[2]&&t[1]<=r[1]&&t[3]>=r[3];return n?i?!0:r[0]<=t[0]&&r[2]>=t[2]&&r[1]<=t[1]&&r[3]>=t[3]:i},Gw=(e,t)=>{let n=Uw(e);return(Il(n[0],Nl(t[0],t[2]))||Il(t[0],Nl(n[0],n[2])))&&(Il(n[1],Nl(t[1],t[3]))||Il(t[1],Nl(n[1],n[3])))},Kw=({elements:e,bounds:t,type:n,errorMargin:r=0})=>{ud(t)&&(t=iv(t,_u(e)));let i=[t[0]-r,t[1]-r,t[2]+r,t[3]+r],a=new Set;for(let t of e)if(!a.has(t.id)&&(n===`overlap`?Gw(t,i):n===`inside`?Ww(t,i):Ww(t,i,!0))){if(a.add(t.id),t.boundElements)for(let e of t.boundElements)a.add(e.id);B(t)&&t.containerId&&a.add(t.containerId),V(t)&&(t.startBinding&&a.add(t.startBinding.elementId),t.endBinding&&a.add(t.endBinding?.elementId))}return e.filter(e=>a.has(e.id))};function qw(e){return[Math.min(e[0][0],e[1][0]),Math.min(e[0][1],e[1][1]),Math.max(e[0][0],e[1][0]),Math.max(e[0][1],e[1][1])]}function Jw(e,t){return e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1]}var Yw=1e-6;function Xw(e,t){let n=Yc(F(e[1],e[0]),F(t,e[0]));return Math.abs(n)<Yw}function Zw(e,t){return Yc(F(e[1],e[0]),F(t,e[0]))<0}function Qw(e,t){return Xw(e,t[0])||Xw(e,t[1])||(Zw(e,t[0])?!Zw(e,t[1]):Zw(e,t[1]))}function $w(e,t){return Jw(qw(e),qw(t))&&Qw(e,t)&&Qw(t,e)}var eT=(e,t,n)=>{let r=_u(e);for(let e of t)if(e.frameId){let t=n.get(e.id),i=n.get(e.frameId);if(t){let n=r.get(t);n&&$(n,{frameId:i??e.frameId},!1)}}};function tT(e,t,n){let r=G_(t,n),i=G_(e,n);return r.some(e=>i.some(t=>$w(e,t)))}var nT=(e,t,n)=>xT(kT(e,t,n,!1)).filter(e=>!ed(e)&&!e.frameId||e.frameId===t.id),rT=(e,t,n)=>kT([t],e,n).some(e=>e.id===t.id),iT=(e,t,n)=>{let[r,i,a,o]=J(t,n),[s,c,l,u]=av(e);return r<=s&&i<=c&&a>=l&&o>=u},aT=(e,t,n)=>iT([e],t,n)||tT(e,t,n)||rT(e,t,n),oT=(e,t,n)=>{let[r,i,a,o]=J(t,n);return dl(I(r,i),I(e.x,e.y),I(a,o))},sT=e=>{let t=new Map;for(let n of e){let r=ed(n)?n.id:n.frameId;r&&!t.has(r)&&t.set(r,cT(e,r))}return t},cT=(e,t)=>{let n=[];for(let r of e.values())r.frameId===t&&n.push(r);return n},lT=e=>e.filter(e=>ed(e)),uT=e=>{let t=_u(lT(e));return e.filter(e=>t.has(e.id)||!e.frameId||!t.has(e.frameId))},dT=(e,t,n,r)=>{let i=cT(e,t.id),a=new Set(i),o=new Set([...nT(e,t,r),...i.filter(e=>rT(e,t,r))]),s=i.filter(e=>!o.has(e)),c=new Set(Array.from(o).flatMap(e=>e.groupIds));for(let e of s)if(!tT(e,t,r))e.groupIds.length===0&&a.delete(e);else if(e.groupIds.length>0)for(let t of e.groupIds)c.add(t);for(let e of s)if(e.groupIds.length>0){let t=!0;for(let n of e.groupIds)c.has(n)&&(t=!1);t&&a.delete(e)}let l=Array.from(o).filter(e=>e.groupIds.length===0);for(let e of l)a.add(e);let u=Oy(Array.from(o).filter(e=>e.groupIds.length>0),n);for(let[n,i]of Object.entries(u))if(i){let i=jy(e,n);if(iT(i,t,r))for(let e of i)a.add(e)}return[...a].filter(e=>!(B(e)&&e.containerId))},fT=(e,t,n)=>pT(xT(e,nT(e,t,n)),t,n),pT=(e,t,n)=>{let r=[],i=new Map;for(let a of e){let e=!1;if(a.groupIds.length>0){if(a.groupIds.some(e=>i.get(e)))e=!0;else{let r=new Set(a.groupIds.flatMap(e=>jy(n,e)));e=!iT(Array.from(r),t,n)}a.groupIds.forEach(t=>{i.set(t,e)})}e||r.push(a)}return r},mT=(e,t)=>e.frameId&&t.get(e.frameId)||null,hT=(e,t)=>{let n=new Set,r=_u(e);e=xT(e);for(let r of e)ed(r)&&r.id!==t.id&&n.add(r.id);let i=new Set,a=[];for(let o of e)if(!(ed(o)||o.frameId&&n.has(o.frameId))){if(o.groupIds.length){let n=o.groupIds.at(-1);if(!i.has(n)){i.add(n);let o=jy(e,n);if(o.some(e=>aT(e,t,r)))for(let e of o)a.push(e)}}else aT(o,t,r)&&a.push(o)}return a},gT=(e,t,n,r)=>{let i=_u(e),a=new Map;for(let t of e.values())t.frameId===n.id&&a.set(t.id,!0);let o=new Set(t.map(e=>e.id)),s=[],c=new Set;for(let e of t)ed(e)&&e.id!==n.id&&c.add(e.id);for(let n of xT(e,t)){if(ed(n)||n.frameId&&c.has(n.frameId)||n.frameId&&r.selectedElementIds[n.id]&&r.selectedElementIds[n.frameId])continue;a.has(n.id)||s.push(n);let e=Cb(n,i);e&&!o.has(e.id)&&!a.has(e.id)&&s.push(e)}for(let e of s)$(e,{frameId:n.id},!1);return e},_T=(e,t)=>{let n=new Map,r=new Map;for(let i of e)if(i.frameId){n.set(i.id,i);let e=r.get(i.frameId)||[];e.push(i);let a=Cb(i,t);a&&(n.set(a.id,a),e.push(a)),r.set(i.frameId,e)}for(let[,e]of n)$(e,{frameId:null},!1)},vT=(e,t)=>(_T(cT(e,t.id),_u(e)),e),yT=(e,t,n,r)=>gT(vT(e,n),t,n,r.state).slice(),bT=(e,t,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,elements:e}),i=new Set(r);if(t.editingGroupId)for(let t of r)t.groupIds.length===0?i.add(t):t.groupIds.flatMap(t=>jy(e,t)).forEach(e=>i.add(e));let a=new Set,o=_u(e);return i.forEach(e=>{e.frameId&&!ed(e)&&!CT(e,o,t)&&a.add(e)}),a.size>0&&_T(a,o),e},xT=(e,t)=>{let n=new Set,r=t||e;for(let e of r.values()){let t=e.groupIds[e.groupIds.length-1];t&&n.add(t)}let i=new Set;for(let t of n)jy(e,t).some(e=>ed(e))&&i.add(t);let a=[];for(let e of r.values())i.has(e.groupIds[e.groupIds.length-1])||a.push(e);return a},ST=(e,t,n)=>{let r=B(e)&&wb(e,t)||e;return r.frameId&&n.selectedElementIds[r.id]&&n.selectedElementIds[r.frameId]?mT(r,t):n.selectedElementIds[r.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:mT(r,t)},CT=(e,t,n,r)=>{let i=r?.targetFrame??ST(e,t,n);if(!i)return!1;let a=B(e)&&wb(e,t)||e,o=e=>{r?.checkedGroups&&a.groupIds.forEach(t=>{r.checkedGroups?.set(t,e)})};if(!n.selectedElementIds[a.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[a.id]&&n.selectedElementIds[i.id])return!0;if(a.groupIds.length===0)return aT(a,i,t);for(let e of a.groupIds)if(r?.checkedGroups?.has(e))return r.checkedGroups.get(e);let s=new Set(a.groupIds.filter(e=>!r?.checkedGroups||!r.checkedGroups.has(e)).flatMap(e=>jy(t,e)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let e=new Set(NT(t,n));if(n.frameToHighlight!==null)return!0;e.forEach(e=>{s.delete(e)})}for(let e of s)if(ed(e))return o(!1),!1;for(let e of s)if(aT(e,i,t))return o(!0),!0;return!1},wT=(e,t,n,r,i)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let a=tT(e,t,r)||rT(e,t,r);if(a){for(let t of e.groupIds)i?.set(t,!0);return!0}if(!a&&e.groupIds.length>0&&!iT([e],t,r)){let a=!1;if(n.selectedElementsAreBeingDragged)a=CT(e,r,n,{targetFrame:t,checkedGroups:i});else{a=e.frameId===t.id;for(let t of e.groupIds)i?.set(t,a)}for(let t of e.groupIds)i?.set(t,a);return a}return!1},TT=e=>e.name===null?Qu(e)?`Frame`:`AI Frame`:e.name,ET=(e,t)=>Kw({elements:e,bounds:t,type:`overlap`}).filter(e=>!e.frameId||e.frameId===t.id),DT=e=>{let t=_u(e);return e.length>1&&e.some(e=>e.frameId&&t.has(e.frameId))},OT=e=>{let t=new Set;return e.forEach(e=>{ed(e)&&t.add(e.id)}),e.filter(e=>!(e.frameId&&t.has(e.frameId)))},kT=(e,t,n,r=!0)=>{let[i,a,o,s]=J(t,n),c=e.filter(e=>{let[t,r,c,l]=iv(e,n),u=mT(e,n);if(u){let[e,i,a,o]=iv(u,n);t=Math.max(e,t),r=Math.max(i,r),c=Math.min(a,c),l=Math.min(o,l)}return e.locked===!1&&e.type!==`selection`&&!pd(e)&&i<=t&&a<=r&&o>=c&&s>=l});return c=r?OT(c):c,c=c.filter(e=>{let t=mT(e,n);return!t||aT(e,t,n)}),c},AT=(e,t,n,r)=>{let i=new Set(t.map(e=>e.id));return e.filter(e=>{let t=GT(e,n.width,n.height,n,r);return!i.has(e.id)&&t})},jT=function(){let e=null,t=null,n=null,r=(r,i)=>(n!=null&&r===e&&i.selectedElementIds===t||(n=r.some(e=>i.selectedElementIds[e.id]),e=r,t=i.selectedElementIds),n);return r.clearCache=()=>{e=null,t=null,n=null},r}(),MT=(e,t,n)=>{let r=Array.from(new Set(NT(e,t).map(e=>n(e))));return r.length===1?r[0]:null},NT=(e,t,n)=>{let r=new Set,i=[];for(let a of e.values()){if(t.selectedElementIds[a.id]){i.push(a),r.add(a.id);continue}if(n?.includeBoundTextElement&&pd(a)&&t.selectedElementIds[a?.containerId]){i.push(a),r.add(a.id);continue}}if(n?.includeElementsInFrames){let t=[];return i.forEach(n=>{ed(n)&&cT(e,n.id).forEach(e=>!r.has(e.id)&&t.push(e)),t.push(n)}),t}return i},PT=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:NT(e,t,{includeBoundTextElement:!0}),FT=(e,t)=>Au(t.selectedElementIds,e)?t.selectedElementIds:e,IT=e=>{let t=new Map,n=[];for(let r of e)r.isDeleted||(n.push(r),t.set(r.id,r));return{elementsMap:t,elements:n}},LT=(0,Fi.default)(e=>{(s.DEV||s.MODE===Ds.TEST||window?.DEBUG_FRACTIONAL_INDICES)&&Cx(e,{shouldThrow:s.DEV||s.MODE===Ds.TEST,includeBoundTextValidation:!0})},6e4,{leading:!0,trailing:!1}),RT=e=>{let t=[`includeBoundTextElement`,`includeElementsInFrames`],n=``;for(let r of t)n+=`${r}:${e[r]?`1`:`0`}`;return n},zT=e=>typeof e==`string`,BT=class e{constructor(){o(this,`callbacks`,new Set),o(this,`nonDeletedElements`,[]),o(this,`nonDeletedElementsMap`,Vu(new Map)),o(this,`elements`,[]),o(this,`nonDeletedFramesLikes`,[]),o(this,`frames`,[]),o(this,`elementsMap`,Vu(new Map)),o(this,`selectedElementsCache`,{selectedElementIds:null,elements:null,cache:new Map}),o(this,`sceneNonce`),o(this,`insertElement`,e=>{let t=e.frameId?this.getElementIndex(e.frameId):this.elements.length;this.insertElementAtIndex(e,t)}),o(this,`insertElements`,e=>{if(!e.length)return;let t=e[0]?.frameId?this.getElementIndex(e[0].frameId):this.elements.length;this.insertElementsAtIndex(e,t)}),o(this,`getContainerElement`,e=>e&&e.containerId&&this.getElement(e.containerId)||null),o(this,`getElementsFromId`,e=>{let t=this.getNonDeletedElementsMap(),n=t.get(e);return n?[n]:jy(t,e)})}static mapElementToScene(e,t){zT(e)?this.sceneMapById.set(e,t):(this.sceneMapByElement.set(e,t),this.sceneMapById.set(e.id,t))}static getScene(e){return zT(e)?this.sceneMapById.get(e)||null:this.sceneMapByElement.get(e)||null}getSceneNonce(){return this.sceneNonce}getNonDeletedElementsMap(){return this.nonDeletedElementsMap}getElementsIncludingDeleted(){return this.elements}getElementsMapIncludingDeleted(){return this.elementsMap}getNonDeletedElements(){return this.nonDeletedElements}getFramesIncludingDeleted(){return this.frames}getSelectedElements(e){let t=RT(e),n=e?.elements||this.nonDeletedElements;if(this.selectedElementsCache.elements===n&&this.selectedElementsCache.selectedElementIds===e.selectedElementIds){let e=this.selectedElementsCache.cache.get(t);if(e)return e}else e?.elements??this.selectedElementsCache.cache.clear();let r=NT(n,{selectedElementIds:e.selectedElementIds},e);return e?.elements??(this.selectedElementsCache.selectedElementIds=e.selectedElementIds,this.selectedElementsCache.elements=this.nonDeletedElements,this.selectedElementsCache.cache.set(t,r)),r}getNonDeletedFramesLikes(){return this.nonDeletedFramesLikes}getElement(e){return this.elementsMap.get(e)||null}getNonDeletedElement(e){let t=this.getElement(e);return t&&RE(t)?t:null}mapElements(e){let t=!1,n=this.elements.map(n=>{let r=e(n);return r!==n&&(t=!0),r});return t&&this.replaceAllElements(n),t}replaceAllElements(t){let n=t instanceof Array?t:Array.from(t.values()),r=[];LT(n),this.elements=Ex(n),this.elementsMap.clear(),this.elements.forEach(t=>{ed(t)&&r.push(t),this.elementsMap.set(t.id,t),e.mapElementToScene(t,this)});let i=IT(this.elements);this.nonDeletedElements=i.elements,this.nonDeletedElementsMap=i.elementsMap,this.frames=r,this.nonDeletedFramesLikes=IT(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=ex();for(let e of Array.from(this.callbacks))e()}onUpdate(e){if(this.callbacks.has(e))throw Error();return this.callbacks.add(e),()=>{if(!this.callbacks.has(e))throw Error();this.callbacks.delete(e)}}destroy(){this.elements=[],this.nonDeletedElements=[],this.nonDeletedFramesLikes=[],this.frames=[],this.elementsMap.clear(),this.selectedElementsCache.selectedElementIds=null,this.selectedElementsCache.elements=null,this.selectedElementsCache.cache.clear(),e.sceneMapById.forEach((t,n)=>{t===this&&e.sceneMapById.delete(n)}),this.callbacks.clear()}insertElementAtIndex(e,t){if(!Number.isFinite(t)||t<0)throw Error(`insertElementAtIndex can only be called with index >= 0`);let n=[...this.elements.slice(0,t),e,...this.elements.slice(t)];Tx(n,_u([e])),this.replaceAllElements(n)}insertElementsAtIndex(e,t){if(!e.length)return;if(!Number.isFinite(t)||t<0)throw Error(`insertElementAtIndex can only be called with index >= 0`);let n=[...this.elements.slice(0,t),...e,...this.elements.slice(t)];Tx(n,_u(e)),this.replaceAllElements(n)}getElementIndex(e){return this.elements.findIndex(t=>t.id===e)}};o(BT,`sceneMapByElement`,new WeakMap),o(BT,`sceneMapById`,new Map);var VT=BT,$=(e,t,n=!0,r)=>{let i=!1,{points:a,fixedSegments:o,fileId:s,startBinding:c,endBinding:l}=t;if(H(e)&&(Object.keys(t).length===0||typeof a<`u`||typeof o<`u`||typeof c<`u`||typeof l<`u`)){let n=Vu(VT.getScene(e)?.getNonDeletedElementsMap()??new Map);t={...t,angle:0,...hC({...e,x:t.x||e.x,y:t.y||e.y},n,{fixedSegments:o,points:a,startBinding:c,endBinding:l},{isDragging:r?.isDragging})}}else typeof a<`u`&&(t={...V_(a),...t});for(let n in t){let r=t[n];if(typeof r<`u`){if(e[n]===r&&(typeof r!=`object`||!r||n===`groupIds`||n===`scale`))continue;if(n===`scale`){let t=e[n],i=r;if(t[0]===i[0]&&t[1]===i[1])continue}else if(n===`points`){let t=e[n],i=r;if(t.length===i.length){let e=!1,n=t.length;for(;--n;){let r=t[n],a=i[n];if(r[0]!==a[0]||r[1]!==a[1]){e=!0;break}}if(!e)continue}}e[n]=r,i=!0}}return i&&((typeof t.height<`u`||typeof t.width<`u`||typeof s<`u`||typeof a<`u`)&&rf.delete(e),e.version++,e.versionNonce=ex(),e.updated=gu(),n&&VT.getScene(e)?.triggerUpdate()),e},HT=(e,t,n=!1)=>{let r=!1;for(let n in t){let i=t[n];if(typeof i<`u`){if(e[n]===i&&(typeof i!=`object`||!i))continue;r=!0}}return!r&&!n?e:{...e,...t,updated:gu(),version:e.version+1,versionNonce:ex()}},UT=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=ex(),e.updated=gu(),e),WT=e=>rd(e)||td(e)?e.points.length<2:e.width===0&&e.height===0,GT=(e,t,n,r,i)=>{let[a,o,s,c]=iv(e,i),l=tu({clientX:r.offsetLeft,clientY:r.offsetTop},r),u=tu({clientX:r.offsetLeft+t,clientY:r.offsetTop+n},r);return l.x<=s&&l.y<=c&&u.x>=a&&u.y>=o},KT=(e,t,n,r,i,a)=>{let[o,s,c,l]=av(e,i),u=tu({clientX:r.offsetLeft+(a?.left||0),clientY:r.offsetTop+(a?.top||0)},r),d=tu({clientX:r.offsetLeft+t-(a?.right||0),clientY:r.offsetTop+n-(a?.bottom||0)},r);return o>=u.x&&s>=u.y&&c<=d.x&&l<=d.y},qT=(e,t,n)=>{let r=Math.abs(t),i=Math.abs(n);if(e===`line`||e===`arrow`||e===`freedraw`){let e=Math.round(Math.atan(i/r)/Ss)*Ss;e===0?n=0:e===Math.PI/2?t=0:n=r*Math.tan(e)*Math.sign(n)||n}else e!==`selection`&&(n=r*Math.sign(n));return{width:t,height:n}},JT=(e,t,n,r)=>{let i=n-e,a=r-t,o=Math.round(Math.atan(a/i)/Ss)*Ss;if(o===0)a=0;else if(o===Math.PI/2)i=0;else{let s=Math.tan(o),c=t-s*e,l=-1/s,u=r-l*n,d=(-1*u- -1*c)/(s*-1-l*-1),f=(c*l-u*s)/(s*-1-l*-1);i=d-e,a=f-t}return{width:i,height:a}},YT=e=>{let t={width:e.width,height:e.height,x:e.x,y:e.y};if(e.width<0){let n=Math.abs(e.width);t.width=n,t.x=e.x-n}if(e.height<0){let n=Math.abs(e.height);t.height=n,t.y=e.y-n}return t},XT={mouse:8,pen:16,touch:28},ZT=16,QT={e:!0,s:!0,n:!0,w:!0},$T={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},eE={e:!0,s:!0,n:!0,w:!0},tE=(e,t,n,r,i,a,o)=>{let[s,c]=R(I(e+n/2,t+r/2),I(i,a),o);return[s-n/2,c-r/2,n,r]},nE=e=>!(e.viewport.isMobile||e.isTouchScreen&&(ms||_s)),rE=e=>nE(e)?QT:{},iE=([e,t,n,r,i,a],o,s,c,l={},u=4,d=2)=>{let f=XT[c],p=f/s.value,m=f/s.value,h=f/s.value,g=f/s.value,_=n-e,v=r-t,y=u/s.value,b=(f-d*2)/(2*s.value),x={nw:l.nw?void 0:tE(e-y-h+b,t-y-g+b,p,m,i,a,o),ne:l.ne?void 0:tE(n+y-b,t-y-g+b,p,m,i,a,o),sw:l.sw?void 0:tE(e-y-h+b,r+y-b,p,m,i,a,o),se:l.se?void 0:tE(n+y-b,r+y-b,p,m,i,a,o),rotation:l.rotation?void 0:tE(e+_/2-p/2,t-y-g+b-ZT/s.value,p,m,i,a,o)},S=5*XT.mouse/s.value;return Math.abs(_)>S&&(l.n||(x.n=tE(e+_/2-p/2,t-y-g+b,p,m,i,a,o)),l.s||(x.s=tE(e+_/2-p/2,r+y-b,p,m,i,a,o))),Math.abs(v)>S&&(l.w||(x.w=tE(e-y-h+b,t+v/2-m/2,p,m,i,a,o)),l.e||(x.e=tE(n+y-b,t+v/2-m/2,p,m,i,a,o))),x},aE=(e,t,n,r=`mouse`,i=QT)=>{if(e.locked||H(e))return{};if(e.type===`freedraw`||rd(e)){if(e.points.length===2){let[,t]=e.points;t[0]===0||t[1]===0?i=eE:t[0]>0&&t[1]<0?i=$T:t[0]>0&&t[1]>0?i=eE:t[0]<0&&t[1]>0?i=$T:t[0]<0&&t[1]<0&&(i=eE)}}else ed(e)&&(i={...i,rotation:!0});let a=rd(e)?10:Ju(e)?0:2;return iE(J(e,n,!0),e.angle,t,r,i,a,Ju(e)?0:void 0)},oE=(e,t)=>{if(t.editingLinearElement)return!1;if(e.length>1)return!0;let n=e[0];return H(n)?!1:!rd(n)||n.points.length>2},sE=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],cE=(e,t,n,r,i,a,o,s)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:c,...l}=aE(e,a,t,o,rE(s));if(c&&sE(c,r,i))return`rotation`;let u=Object.keys(l).filter(e=>{let t=l[e];return t?sE(t,r,i):!1});if(u.length>0)return u[0];if(nE(s)){let[n,o,s,c,l,u]=J(e,t);if(!(rd(e)&&e.points.length<=2)){let t=Ju(e)?0:zs/a.value,d=zs/a.value,f=mE(I(n-t,o-t),I(s+t,c+t),I(l,u),e.angle);for(let[e,t]of Object.entries(f))if(ml(I(r,i),t,d))return e}}return!1},lE=(e,t,n,r,i,a,o,s)=>e.reduce((e,c)=>{if(e)return e;let l=cE(c,o,t,n,r,i,a,s);return l?{element:c,transformHandleType:l}:null},null),uE=([e,t,n,r],i,a,o,s,c)=>{let l=iE([e,t,n,r,(e+n)/2,(t+r)/2],0,o,s,rE(c)),u=Object.keys(l).find(e=>{let t=l[e];return t&&sE(t,i,a)});if(u)return u;if(nE(c)){let s=(e+n)/2,c=(t+r)/2,l=zs/o.value,u=mE(I(e-l,t-l),I(n+l,r+l),I(s,c),0);for(let[e,t]of Object.entries(u))if(ml(I(i,a),t,l))return e}return!1},dE=[`ns`,`nesw`,`ew`,`nwse`],fE=(e,t)=>{let n=dE.indexOf(e);return n>=0&&(e=dE[(n+Math.round(t/(Math.PI/4)))%dE.length]),e},pE=e=>{let{element:t,transformHandleType:n}=e,r=t&&Math.sign(t.height)*Math.sign(t.width)===-1,i=null;switch(n){case`n`:case`s`:i=`ns`;break;case`w`:case`e`:i=`ew`;break;case`nw`:case`se`:i=r?`nesw`:`nwse`;break;case`ne`:case`sw`:i=r?`nwse`:`nesw`;break;case`rotation`:return`grab`}return i&&t&&(i=fE(i,t.angle)),i?`${i}-resize`:``},mE=([e,t],[n,r],i,a)=>{let o=R(I(e,t),i,a),s=R(I(n,t),i,a),c=R(I(e,r),i,a),l=R(I(n,r),i,a);return{n:[o,s],e:[s,l],s:[l,c],w:[c,o]}},hE=(e,t,n,r,i,a,o,s,c,l,u,d)=>{if(n.length===1){let[u]=n;if(t===`rotation`)H(u)||(gE(u,r,i,c,l,a),Bv(u,r));else{if(B(u)&&t)return yE(e,u,r,t,o,c,l),Bv(u,r),!0;if(t){let i=n[0].id,a=r.get(i),u=e.get(i);if(a&&u){let{nextWidth:n,nextHeight:i}=EE(a,u,r,e,t,c,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:o});TE(n,i,a,u,r,e,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:o})}}}return!0}if(n.length>1){if(t===`rotation`)return bE(e,n,r,i,c,l,a,u,d),!0;if(t){let{nextWidth:a,nextHeight:u,flipByX:d,flipByY:f,originalBoundingBox:p}=DE(n,e,r,t,c,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:o});return OE(n,r,t,i,e,{shouldResizeFromCenter:o,shouldMaintainAspectRatio:s,flipByX:d,flipByY:f,nextWidth:a,nextHeight:u,originalBoundingBox:p}),!0}}return!1},gE=(e,t,n,r,i,a)=>{let[o,s,c,l]=J(e,t),u=(o+c)/2,d=(s+l)/2,f;ed(e)?f=0:(f=5*Math.PI/2+Math.atan2(i-d,r-u),a&&(f+=Ss/2,f-=f%Ss),f=Wc(f));let p=Sb(e);if($(e,{angle:f}),p){let t=n.getElement(p);t&&!V(e)&&$(t,{angle:f})}},_E=(e,t,n,r)=>rd(e)||td(e)?{points:H_(0,t,H_(1,n,e.points,r),r)}:{},vE=(e,t,n)=>{let r=e.width;if(pd(e)){let n=wb(e,t);n&&(r=Nb(n,e))}let i=e.fontSize*(n/r);return i<Is?null:{size:i}},yE=(e,t,n,r,i,a,o)=>{let[s,c,l,u,d,f]=J(t,n),[p,m]=R(I(a,o),I(d,f),-t.angle),h=0,g=0;r!==`e`&&r!==`w`&&(r.includes(`e`)&&(h=(p-s)/(l-s)),r.includes(`w`)&&(h=(l-p)/(l-s)),r.includes(`n`)&&(g=(u-m)/(u-c)),r.includes(`s`)&&(g=(m-c)/(u-c)));let _=Math.max(h,g);if(_>0){let e=t.width*_,a=t.height*_,o=vE(t,n,e);if(o===null)return;let p=[s,c],m=[l,u],h=[d,f],g=I(s,c);if([`n`,`w`,`nw`].includes(r)&&(g=I(m[0]-Math.abs(e),m[1]-Math.abs(a))),r===`ne`){let e=[p[0],m[1]];g=I(e[0],e[1]-Math.abs(a))}if(r===`sw`){let t=[m[0],p[1]];g=I(t[0]-Math.abs(e),t[1])}[`s`,`n`].includes(r)&&(g[0]=h[0]-e/2),[`e`,`w`].includes(r)&&(g[1]=h[1]-a/2),i&&(g[0]=h[0]-Math.abs(e)/2,g[1]=h[1]-Math.abs(a)/2);let v=t.angle;g=R(R(g,I(d,f),v),R(I(g[0]+Math.abs(e)/2,g[1]+Math.abs(a)/2),I(d,f),v),-v);let[y,b]=g;$(t,{fontSize:o.size,width:e,height:a,x:y,y:b})}if(r===`e`||r===`w`){let n=e.get(t.id),[i,s,c,l]=sv(n,n.width,n.height,!0),u=I(i,s),d=I(c,l),f=sl(u,d),p=R(I(a,o),f,-n.angle),[m,,h]=sv(t,t.width,t.height,!0),g=h-m,_=d[0]-u[0],v=Sd(Gl({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),y=_/g;r.includes(`e`)&&(y=(p[0]-u[0])/g),r.includes(`w`)&&(y=(d[0]-p[0])/g);let b=t.width*y<v?v:t.width*y,x=Xd(t.originalText,Gl(t),Math.abs(b)),S=yd(x,Gl(t),t.lineHeight),C=S.height,[w,T,E,D]=sv(n,b,C,!0),ee=E-w,te=D-T,ne=[...u];[`n`,`w`,`nw`].includes(r)&&(ne=[d[0]-Math.abs(ee),u[1]]);let re=n.angle;ne=R(R(ne,f,re),R(I(ne[0]+Math.abs(ee)/2,ne[1]+Math.abs(te)/2),f,re),-re),$(t,{width:Math.abs(b),height:Math.abs(S.height),x:ne[0],y:ne[1],text:x,autoResize:!1})}},bE=(e,t,n,r,i,a,o,s,c)=>{let l=5*Math.PI/2+Math.atan2(a-c,i-s);o&&(l+=Ss/2,l-=l%Ss);for(let r of t)if(!ed(r)){let[i,a,o,u]=J(r,n),d=(i+o)/2,f=(a+u)/2,p=e.get(r.id)?.angle??r.angle,[m,h]=R(I(d,f),I(s,c),l+p-r.angle);H(r)?$(r,{points:hy(r,n)}):$(r,{x:r.x+(m-d),y:r.y+(h-f),angle:Wc(l+p)},!1),Bv(r,n,{simultaneouslyUpdated:t});let g=Cb(r,n);g&&!V(r)&&$(g,{x:g.x+(m-d),y:g.y+(h-f),angle:Wc(l+p)},!1)}r.triggerUpdate()},xE=(e,t,n,r,i)=>{let[a,o,s,c]=t.length===1?J(t[0],n):av(t),l=(a+s)/2,u=(o+c)/2,d=t.length===1?t[0].angle:0;switch([r,i]=R(I(r,i),I(l,u),-d),e){case`n`:return R(I(r-(a+s)/2,i-o),I(0,0),d);case`s`:return R(I(r-(a+s)/2,i-c),I(0,0),d);case`w`:return R(I(r-a,i-(o+c)/2),I(0,0),d);case`e`:return R(I(r-s,i-(o+c)/2),I(0,0),d);case`nw`:return R(I(r-a,i-o),I(0,0),d);case`ne`:return R(I(r-s,i-o),I(0,0),d);case`sw`:return R(I(r-a,i-c),I(0,0),d);case`se`:return R(I(r-s,i-c),I(0,0),d);default:return[0,0]}},SE=(e,t)=>{let[,[n,r]]=t.points;return e===`nw`&&(n<0||r<0)||e===`ne`&&n>=0||e===`sw`&&n<=0||e===`se`&&(n>0||r>0)?`end`:`origin`},CE=(e,t,n)=>{if(n)return`center`;if(t)switch(e){case`n`:return`south-side`;case`e`:return`west-side`;case`s`:return`north-side`;case`w`:return`east-side`;case`ne`:return`bottom-left`;case`nw`:return`bottom-right`;case`se`:return`top-left`;case`sw`:return`top-right`}return[`e`,`se`,`s`].includes(e)?`top-left`:[`n`,`nw`,`w`].includes(e)?`bottom-right`:e===`ne`?`bottom-left`:`top-right`},wE=(e,t,n,r,i,a,o,s,c)=>{let l=CE(o,s,c),[u,d]=e;switch(l){case`top-left`:return{x:u+(t-r)/2+(r-t)/2*Math.cos(a)+(n-i)/2*Math.sin(a),y:d+(n-i)/2+(r-t)/2*Math.sin(a)+(i-n)/2*Math.cos(a)};case`top-right`:return{x:u+(t-r)/2*(Math.cos(a)+1)+(n-i)/2*Math.sin(a),y:d+(n-i)/2+(t-r)/2*Math.sin(a)+(i-n)/2*Math.cos(a)};case`bottom-left`:return{x:u+(t-r)/2*(1-Math.cos(a))+(i-n)/2*Math.sin(a),y:d+(n-i)/2*(Math.cos(a)+1)+(r-t)/2*Math.sin(a)};case`bottom-right`:return{x:u+(t-r)/2*(Math.cos(a)+1)+(i-n)/2*Math.sin(a),y:d+(n-i)/2*(Math.cos(a)+1)+(t-r)/2*Math.sin(a)};case`center`:return{x:u-(r-t)/2,y:d-(i-n)/2};case`east-side`:return{x:u+(t-r)/2*(Math.cos(a)+1),y:d+(t-r)/2*Math.sin(a)+(n-i)/2};case`west-side`:return{x:u+(t-r)/2*(1-Math.cos(a)),y:d+(r-t)/2*Math.sin(a)+(n-i)/2};case`north-side`:return{x:u+(t-r)/2+(n-i)/2*Math.sin(a),y:d+(i-n)/2*(Math.cos(a)-1)};case`south-side`:return{x:u+(t-r)/2+(i-n)/2*Math.sin(a),y:d+(n-i)/2*(Math.cos(a)+1)}}},TE=(e,t,n,r,i,a,o,{shouldInformMutation:s=!0,shouldMaintainAspectRatio:c=!1,shouldResizeFromCenter:l=!1}={})=>{let u={},d=Cb(n,i);if(d){let r=a.get(d.id);if(r&&(u={fontSize:r.fontSize}),c){let r=vE(d,i,Nb({...n,width:e,height:t},d));if(r===null)return;u={fontSize:r.size}}else{let n=xd(Gl(d),d.lineHeight),r=Od(d.fontSize,d.lineHeight);e=Math.max(e,n),t=Math.max(t,r)}}let f=_E(r,e,t,!0),p=I(r.x,r.y);if(rd(r)){let[e,t]=iv(r,a);p=I(e,t)}let m=wE(p,r.width,r.height,e,t,r.angle,o,c,l);if(rd(r)&&f.points){let e=r.x-p[0],t=r.y-p[1];m.x+=e,m.y+=t;let n=f.points[0][0],i=f.points[0][1];m.x+=n,m.y+=i,f.points=f.points.map(e=>I(e[0]-n,e[1]-i))}if(e<0&&(m.x+=e),t<0&&(m.y+=t),`scale`in n&&`scale`in r&&$(n,{scale:[(Math.sign(e)||r.scale[0])*r.scale[0],(Math.sign(t)||r.scale[1])*r.scale[1]]}),V(n)&&d&&c){let t=e/n.width*d.fontSize;if(t<Is)return;u.fontSize=t}e!==0&&t!==0&&Number.isFinite(m.x)&&Number.isFinite(m.y)&&($(n,{...m,width:Math.abs(e),height:Math.abs(t),...f},s),Bv(n,i,{newSize:{width:e,height:t}}),d&&u!=null&&$(d,{fontSize:u.fontSize}),bb(n,i,o,c))},EE=(e,t,n,r,i,a,o,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:c=!1}={})=>{let[l,u,d,f]=sv(t,t.width,t.height,!0),p=I(l,u),m=I(d,f),h=sl(p,m),g=R(I(a,o),h,-t.angle),[_,v,y,b]=sv(e,e.width,e.height,!0),x=y-_,S=b-v,C=m[0]-p[0],w=m[1]-p[1],T=C/x,E=w/S;i.includes(`e`)&&(T=(g[0]-p[0])/x),i.includes(`s`)&&(E=(g[1]-p[1])/S),i.includes(`w`)&&(T=(m[0]-g[0])/x),i.includes(`n`)&&(E=(m[1]-g[1])/S);let D=e.width*T,ee=e.height*E;if(c&&(D=2*D-t.width,ee=2*ee-t.height),s){let e=Math.abs(D)/t.width,n=Math.abs(ee)/t.height;if(i.length===1&&(ee*=e,D*=n),i.length===2){let r=Math.max(e,n);D=t.width*r*Math.sign(D),ee=t.height*r*Math.sign(ee)}}return{nextWidth:D,nextHeight:ee}},DE=(e,t,n,r,i,a,{shouldMaintainAspectRatio:o=!1,shouldResizeFromCenter:s=!1}={})=>{let c=e.map(e=>t.get(e.id)),l=c.reduce((e,r)=>{if(!rd(r))return e;let i=Sb(r);if(!i)return e;let a=t.get(i)??null;return pd(a)?[...e,{...a,...X.getBoundTextElementPosition(r,a,n)}]:e},[]),u=uv(c.map(e=>e).concat(l)),{minX:d,minY:f,maxX:p,maxY:m,midX:h,midY:g}=u,_=p-d,v=m-f,y={ne:[d,m],se:[d,f],sw:[p,f],nw:[p,m],e:[d,f+v/2],w:[p,f+v/2],n:[d+_/2,m],s:[d+_/2,f]},[b,x]=s?[h,g]:y[r],S=s?2:1,C=Math.max(Math.abs(i-b)/_||0,Math.abs(a-x)/v||0)*S,w=r.includes(`e`)||r.includes(`w`)?Math.abs(i-b)*S:_,T=r.includes(`n`)||r.includes(`s`)?Math.abs(a-x)*S:v;o&&(w=_*C*Math.sign(i-b),T=v*C*Math.sign(a-x));let[E,D]={ne:[i<b,a>x],se:[i<b,a<x],sw:[i>b,a<x],nw:[i>b,a>x],e:[i<b,!1],w:[i>b,!1],n:[!1,a>x],s:[!1,a<x]}[r].map(e=>e);return{originalBoundingBox:u,nextWidth:w,nextHeight:T,flipByX:E,flipByY:D}},OE=(e,t,n,r,i,{shouldMaintainAspectRatio:a=!1,shouldResizeFromCenter:o=!1,flipByX:s=!1,flipByY:c=!1,nextHeight:l,nextWidth:u,originalBoundingBox:d}={})=>{if(u===void 0&&l===void 0&&s===void 0&&c===void 0||l===0||u===0)return;i||=t;let f=e.reduce((e,t)=>{let n=i.get(t.id);return n&&e.push({orig:n,latest:t}),e},[]),p;if(d)p=d;else{let e=f.reduce((e,{orig:n})=>{if(!rd(n))return e;let r=Sb(n);if(!r)return e;let a=i.get(r)??null;return pd(a)?[...e,{...a,...X.getBoundTextElementPosition(n,a,t)}]:e},[]);p=uv(f.map(({orig:e})=>e).concat(e))}let{minX:m,minY:h,maxX:g,maxY:_,midX:v,midY:y}=p,b=g-m,x=_-h;if(u===void 0&&l===void 0&&(u=b,l=x),a&&(u===void 0?u=b/x*l:l===void 0?l=x/b*u:Math.abs(u/l-b/x)>.001&&(u=b/x*l)),u&&l){let e=n.includes(`e`)||n.includes(`w`)?Math.abs(u)/b:1,d=n.includes(`n`)||n.includes(`s`)?Math.abs(l)/x:1,p;p=n.length===1?n.includes(`e`)||n.includes(`w`)?e:d:Math.max(Math.abs(u)/b||0,Math.abs(l)/x||0);let S={ne:[m,_],se:[m,h],sw:[g,h],nw:[g,_],e:[m,h+x/2],w:[g,h+x/2],n:[m+b/2,_],s:[m+b/2,h]},[C,w]=o?[v,y]:S[n],T=a||f.some(e=>e.latest.angle!==0||B(e.latest)||zy(e.latest));T&&(e=p,d=p);let[E,D]=[s?-1:1,c?-1:1],ee=[];for(let{orig:n,latest:r}of f){if(B(n)&&pd(n))continue;let a=n.width*e,o=n.height*d,l=Wc(n.angle*E*D),u=rd(n)||td(n),f=n.x-C,m=n.y-w,h=s&&!u?a:0,g=c&&!u?o:0,_=C+E*(f*e+h),v=w+D*(m*d+g),y=_E(n,a*E,o*D,!1),b={x:_,y:v,width:a,height:o,angle:l,...y};if(H(n)&&(n.startBinding&&(b.startBinding={...n.startBinding,fixedPoint:[s?-n.startBinding.fixedPoint[0]+1:n.startBinding.fixedPoint[0],c?-n.startBinding.fixedPoint[1]+1:n.startBinding.fixedPoint[1]]}),n.endBinding&&(b.endBinding={...n.endBinding,fixedPoint:[s?-n.endBinding.fixedPoint[0]+1:n.endBinding.fixedPoint[0],c?-n.endBinding.fixedPoint[1]+1:n.endBinding.fixedPoint[1]]}),n.fixedSegments&&y.points&&(b.fixedSegments=n.fixedSegments.map(e=>({...e,start:y.points[e.index-1],end:y.points[e.index]})))),Ju(n)&&(b.scale=[n.scale[0]*E,n.scale[1]*D]),B(n)){let e=vE(n,t,a);if(!e)return;b.fontSize=e.size}let x=i.get(Sb(n)??``);if(x){if(T){let e=x.fontSize*p;if(e<Is)return;b.boundTextFontSize=e}else b.boundTextFontSize=x.fontSize}ee.push({element:r,update:b})}let te=ee.map(({element:e})=>e);for(let{element:e,update:{boundTextFontSize:r,...i}}of ee){let{width:a,height:o,angle:s}=i;$(e,i,!1,{isDragging:!0}),Bv(e,t,{simultaneouslyUpdated:te,newSize:{width:a,height:o}});let c=Cb(e,t);c&&r&&($(c,{fontSize:r,angle:rd(e)?void 0:s},!1),bb(e,t,n,!0))}r.triggerUpdate()}},kE=(e,t,n,r,i,a)=>{if(t.length===1&&H(t[0])&&(t[0].startBinding||t[0].endBinding))return;let o=t.filter(e=>{if(H(e)&&e.startBinding&&e.endBinding){let n=t.find(t=>t.id===e.startBinding?.elementId),r=t.find(t=>t.id===e.endBinding?.elementId);return n&&r}return!0}),s=new Set(o),c=o.filter(e=>ed(e)).map(e=>e.id);if(c.length>0)for(let e of r.getNonDeletedElements())e.frameId!==null&&c.includes(e.frameId)&&s.add(e);let l=AE(av(Array.from(s).map(t=>e.originalElements.get(t.id)??t)),n,i,a);s.forEach(t=>{if(jE(e,t,l),!V(t)){let n=Cb(t,r.getNonDeletedElementsMap());n&&jE(e,n,l),Bv(t,r.getElementsMapIncludingDeleted(),{simultaneouslyUpdated:Array.from(s)})}})},AE=(e,t,n,r)=>{let[i,a]=e,o=i+t.x+n.x,s=a+t.y+n.y;if(n.x===0||n.y===0){let[e,c]=ub(i+t.x,a+t.y,r);n.x===0&&(o=e),n.y===0&&(s=c)}return{x:o-i,y:s-a}},jE=(e,t,n)=>{let r=e.originalElements.get(t.id)??t;$(t,{x:r.x+n.x,y:r.y+n.y})},ME=(e,t,n)=>{let[r,i]=av(e);return[t-r,n-i]},NE=({newElement:e,elementType:t,originX:n,originY:r,x:i,y:a,width:o,height:s,shouldMaintainAspectRatio:c,shouldResizeFromCenter:l,zoom:u,widthAspectRatio:d=null,originOffset:f=null,informMutation:p=!0})=>{c&&e.type!==`selection`&&(d?s=o/d:(Math.abs(a-r)>Math.abs(i-n)?{width:o,height:s}=qT(t,s,i<n?-o:o):{width:o,height:s}=qT(t,o,a<r?-s:s),s<0&&(s=-s)));let m=i<n?n-o:n,h=a<r?r-s:r;l&&(o+=o,s+=s,m=n-o/2,h=r-s/2);let g=null;if(B(e)){s=e.height;let t=Sd(Gl({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);o=Math.max(o,t),Math.abs(i-n)>xs/u&&(g={autoResize:!1}),h=r,l&&(m=n-o/2)}if(o!==0&&s!==0){let t=null;Ju(e)&&(t={initialWidth:o,initialHeight:s}),$(e,{x:m+(f?.x??0),y:h+(f?.y??0),width:o,height:s,...g,...t},p)}},PE=(e,t)=>!!(!e.viewModeEnabled&&e.openDialog?.name!==`elementLinkSelector`&&(e.activeTool.type!==`custom`&&(e.editingTextElement||e.activeTool.type!==`selection`&&e.activeTool.type!==`eraser`&&e.activeTool.type!==`hand`&&e.activeTool.type!==`laser`)||NT(t,e).length)),FE=e=>{let t=5381;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t=(t<<5)+t+r}return t>>>0},IE=e=>e.filter(e=>!e.isDeleted&&!WT(e)),LE=e=>e.filter(e=>!e.isDeleted),RE=e=>!e.isDeleted,zE=e=>LE(e).map(e=>id(e.type)?{...e,lastCommittedPoint:null}:e),BE=e=>zE(e),VE=e=>zE(e),HE=async e=>{let t;if(e.type===M.png)try{return await(await i(async()=>{let{decodePngMetadata:e}=await import(`./image-GAAHSSAO-BoD-NvEF.js`);return{decodePngMetadata:e}},__vite__mapDeps([5,1,2]))).decodePngMetadata(e)}catch(e){throw e.message===`INVALID`?new oh(`Image doesn't contain scene`,`IMAGE_NOT_CONTAINS_SCENE_DATA`):new oh(`Error: cannot restore image`)}if(t=`text`in Blob?await e.text():await new Promise(t=>{let n=new FileReader;n.readAsText(e,`utf8`),n.onloadend=()=>{n.readyState===FileReader.DONE&&t(n.result)}}),e.type===M.svg)try{return oC({svg:t})}catch(e){throw e.message===`INVALID`?new oh(`Image doesn't contain scene`,`IMAGE_NOT_CONTAINS_SCENE_DATA`):new oh(`Error: cannot restore image`)}return t},UE=e=>e&&e.name.match(/\.(json|excalidraw|png|svg)$/)?.[1]||null,WE=e=>e===`png`||e===`svg`,GE=e=>{let t=UE(e);return t===`png`||t===`svg`},KE=e=>!!e&&Object.values(Gs).includes(e),qE=e=>{let{type:t}=e||{};return KE(t)},JE=async(e,t,n,r)=>{let i=await HE(e),a;try{try{a=JSON.parse(i)}catch(t){throw qE(e)?new oh(`Image doesn't contain scene`,`IMAGE_NOT_CONTAINS_SCENE_DATA`):t}if(SS(a))return{type:M.excalidraw,data:QC({elements:VE(a.elements||[]),appState:{theme:t?.theme,fileHandle:r||e.handle||null,...Fc(a.appState||{}),...t?yy(a.elements||[],t):{}},files:a.files},t,n,{repairBindings:!0,refreshDimensions:!1})};if(CS(a))return{type:M.excalidrawlib,data:a};throw Error(`Error: invalid file`)}catch(e){throw e instanceof oh?e:Error(`Error: invalid file`)}},YE=async(e,t,n,r)=>{let i=await JE(e,t,n,r);if(i.type!==M.excalidraw)throw Error(`Error: invalid file`);return i.data},XE=(e,t=`unpublished`)=>{let n=JSON.parse(e);if(!CS(n))throw Error(`Invalid library`);return ew(n.libraryItems||n.library,t)},ZE=async(e,t=`unpublished`)=>XE(await HE(e),t),QE=async e=>new Promise(async(t,n)=>{try{Du(e)&&(e=await e),e.toBlob(e=>{if(!e)return n(new ih(`Error: Canvas too big`,`CANVAS_POSSIBLY_TOO_BIG`));t(e)})}catch(e){n(e)}}),$E=async e=>{try{let t=await window.crypto.subtle.digest(`SHA-1`,await fD(e));return hu(new Uint8Array(t))}catch(e){return console.error(e),Mi(40)}},eD=async e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let e=r.result;t(e)},r.onerror=e=>n(e),r.readAsDataURL(e)}),tD=(e,t)=>`data:${t};base64,${gD(pD(e),!0)}`,nD=(e,t=``)=>{let n=e.indexOf(`,`),r=atob(e.slice(n+1)),i=e.slice(0,n).split(`:`)[1].split(`;`)[0],a=new ArrayBuffer(r.length),o=new Uint8Array(a);for(let e=0;e<r.length;e++)o[e]=r.charCodeAt(e);return new File([a],t,{type:i})},rD=e=>_D(e.slice(e.indexOf(`,`)+1)),iD=async(t,n)=>{if(t.type===M.svg)return t;let[r,a]=await Promise.all([i(()=>import(`./pica-XznpCgP2.js`).then(t=>e(t.default,1)).then(e=>e.default),__vite__mapDeps([6,2])),i(()=>import(`./image-blob-reduce.esm-Dj7YBvMv.js`).then(e=>e.default),[])]),o=a({pica:r({features:[`js`,`wasm`]})});if(n.outputType){let{outputType:e}=n;o._create_blob=function(t){return this.pica.toBlob(t.out_canvas,e,.8).then(e=>(t.out_blob=e,t))}}if(!qE(t))throw Error(`Error: unsupported file type`,{cause:`UNSUPPORTED`});return new File([await o.toBlob(t,{max:n.maxWidthOrHeight,alpha:!0})],t.name,{type:n.outputType||t.type})},aD=(e,t=``)=>new File([new TextEncoder().encode(e)],t,{type:M.svg}),oD=async(e,t=``)=>{let n;try{n=await fetch(e)}catch{throw Error(`Error: failed to fetch image`,{cause:`FETCH_ERROR`})}if(!n.ok)throw Error(`Error: failed to fetch image`,{cause:`FETCH_ERROR`});let r=await n.blob();if(r.type&&qE(r)){let e=t||r.name||``;return new File([r],e,{type:r.type})}throw Error(`Error: unsupported file type`,{cause:`UNSUPPORTED`})},sD=async e=>{let t=e.dataTransfer.files.item(0),n=await cD(e);return{file:t?await dD(t):null,fileHandle:n}},cD=async e=>{if(Yo)try{return await e.dataTransfer.items[0].getAsFileSystemHandle()||null}catch(e){return console.warn(e.name,e.message),null}return null},lD=e=>{let t=null,n=`${[...new Uint8Array(e).slice(0,8)].join(` `)} `,r={png:`137 80 78 71 13 10 26 10 `,jpg:`255 216 255 `,gif:`71 73 70 56 57 97 `};return n===r.png?t=M.png:n.startsWith(r.jpg)?t=M.jpg:n.startsWith(r.gif)&&(t=M.gif),t},uD=(e,t,n)=>new File([e],n||``,{type:t}),dD=async e=>{if(e.type){if(qE(e)){let t=await fD(e),n=lD(t);n&&n!==e.type&&(e=uD(t,n,e.name))}}else if(e?.name?.endsWith(`.excalidrawlib`))e=uD(await fD(e),M.excalidrawlib,e.name);else if(e?.name?.endsWith(`.excalidraw`))e=uD(await fD(e),M.excalidraw,e.name);else{let t=await fD(e),n=lD(t);n&&(e=uD(t,n,e.name))}return e},fD=e=>`arrayBuffer`in e?e.arrayBuffer():new Promise((t,n)=>{let r=new FileReader;r.onload=e=>{if(!e.target?.result)return n(Error(`Couldn't convert blob to ArrayBuffer`));t(e.target.result)},r.readAsArrayBuffer(e)}),pD=e=>{let t=typeof e==`string`?new TextEncoder().encode(e):e instanceof Uint8Array?e:new Uint8Array(e),n=``;for(let e of t)n+=String.fromCharCode(e);return n},mD=e=>{let t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let t=0,r=e.length;t<r;t++)n[t]=e.charCodeAt(t);return t},hD=e=>new TextDecoder(`utf-8`).decode(mD(e)),gD=(e,t=!1)=>t?window.btoa(e):window.btoa(pD(e)),_D=(e,t=!1)=>t?window.atob(e):hD(window.atob(e)),vD=({text:e,compress:t})=>{let n;if(t!==!1)try{n=pD(ki(e))}catch(e){console.error(`encode: cannot deflate`,e)}return{version:`1`,encoding:`bstring`,compressed:!!n,encoded:n||pD(e)}},yD=e=>{let t;switch(e.encoding){case`bstring`:t=e.compressed?e.encoded:hD(e.encoded);break;default:throw Error(`decode: unknown encoding "${e.encoding}"`)}return e.compressed?Ai(new Uint8Array(mD(t)),{to:`string`}):t},bD=async e=>{let t=(0,h.default)(new Uint8Array(await fD(e))).find(e=>e.name===`tEXt`);return t?g.decode(t.data):null},xD=async({blob:e,metadata:t})=>{let n=(0,h.default)(new Uint8Array(await fD(e))),r=g.encode(M.excalidraw,JSON.stringify(vD({text:t,compress:!0})));return n.splice(-1,0,r),new Blob([(0,_.default)(n)],{type:M.png})},SD=async e=>{let t=await bD(e);if(t?.keyword===M.excalidraw)try{let e=JSON.parse(t.text);if(!(`encoded`in e)){if(`type`in e&&e.type===Js.excalidraw)return t.text;throw Error(`FAILED`)}return yD(e)}catch(e){throw console.error(e),Error(`FAILED`)}throw Error(`INVALID`)};export{tu as $,vc as $a,oc as $c,bD as $i,HT as $l,JC as $n,Sc as $o,Gy as $r,lc as $s,js as $t,Jc as A,NE as Aa,Cb as Ac,Pm as Ai,dD as Al,Eg as An,Bx as Ao,Fs as Ar,wd as As,US as At,YE as Au,Ys as B,Vf as Ba,lu as Bc,Bm as Bi,fp as Bl,Qc as Bn,DS as Bo,Au as Br,Gp as Bs,FT as Bt,no as Bu,Tm as C,hx as Ca,Rc as Cc,em as Ci,nu as Cl,_d as Cn,vs as Co,mx as Cr,Fw as Cs,Dp as Ct,vy as Cu,rD as D,Tx as Da,C_ as Dc,eh as Di,Tg as Dl,Sd as Dn,op as Do,OE as Dr,ps as Ds,zf as Dt,Gc as Du,FS as E,Dd as Ea,LS as Ec,sf as Ei,np as El,g_ as En,Zl as Eo,Hf as Er,SD as Es,Ls as Et,Gs as Eu,Bf as F,Op as Fa,Oy as Fc,Rs as Fi,eT as Fl,AS as Fn,ls as Fo,Lf as Fr,Fg as Fs,Zf as Ft,w_ as Fu,Vl as G,rd as Ga,xg as Gc,mT as Gi,uf as Gl,vm as Gn,OT as Go,PT as Gr,px as Gs,Gf as Gt,rc as H,hs as Ha,ay as Hc,Bc as Hi,ou as Hl,rE as Hn,_S as Ho,xb as Hr,B as Hs,Mp as Ht,Mi as Hu,J as I,bb as Ia,cm as Ic,ub as Ii,xw as Il,Ay as In,Wl as Io,q as Ir,Jm as Is,M as It,Up as Iu,Tw as J,WT as Ja,ax as Jc,Ec as Ji,a_ as Jl,Ey as Jn,oE as Jo,kf as Jr,Tc as Js,Us as Jt,Xs as K,Ul as Ka,j_ as Kc,Hp as Ki,Sm as Kl,SE as Kn,kb as Ko,x_ as Kr,Ps as Ks,hb as Kt,yg as L,Xu as La,wS as Lc,ex as Li,Jl as Ll,Od as Ln,V as Lo,Hm as Lr,Um as Ls,Am as Lt,RE as Lu,Iv as M,Ov as Ma,HS as Mc,JT as Mi,Wm as Ml,ym as Mn,Ql as Mo,hC as Mr,Hl as Ms,zp as Mt,os as Mu,Yu as N,iD as Na,mc as Nc,Cd as Ni,I as Nl,cb as Nn,Zm as No,Jg as Nr,QC as Ns,CT as Nt,aS as Nu,xv as O,wc as Oa,Gm as Oc,bg as Oi,yS as Ol,Ig as On,jv as Oo,$s as Or,KT as Os,Lm as Ot,Sf as Ou,Pw as P,yy as Pa,qm as Pc,Ip as Pi,ES as Pl,Cw as Pn,Kp as Po,ad as Pr,NS as Ps,vx as Pt,xx as Pu,xp as Q,um as Qa,Lp as Qc,Im as Qi,Cp as Ql,Hc as Qn,Gv as Qo,ZE as Qr,bc as Qs,jT as Qt,Nm as R,xD as Ra,jb as Rc,Jf as Ri,$c as Rl,Iu as Rn,tp as Ro,ss as Rr,cs as Rs,JE as Rt,Dc as Ru,Uf as S,Cx as Sa,id as Sc,Hg as Si,ds as Sl,Sy as Sn,yb as So,kp as Sr,aT as Ss,S_ as St,xS as Su,Dv as T,Vp as Ta,oh as Tc,lp as Ti,_u as Tl,iE as Tn,ed as To,xu as Tr,Zp as Ts,Du as Tt,wu as Tu,hg as U,wy as Ua,nC as Uc,_b as Ui,fs as Ul,Mf as Un,Rh as Uo,gm as Ur,Rm as Us,qE as Ut,ji as Uu,ah as V,tm as Va,dp as Vc,as as Vi,kT as Vl,ew as Vn,Bg as Vo,$f as Vr,ep as Vs,Kb as Vt,Ni as Vu,bm as W,Nv as Wa,lf as Wc,gx as Wi,iC as Wl,zb as Wn,sm as Wo,eb as Wr,Sw as Ws,__ as Wt,s as Wu,Md as X,Ym as Xa,Mb as Xc,Qf as Xi,k_ as Xl,yp as Xn,cu as Xo,TE as Xr,GT as Xs,DT as Xt,WE as Y,NT as Ya,zS as Yc,uu as Yi,QE as Yl,Pu as Yn,dv as Yo,xm as Yr,Ih as Ys,Xy as Yt,Lu as Z,Ry as Za,wb as Zc,H as Zi,zu as Zl,Cg as Zn,up as Zo,jw as Zr,UT as Zs,TS as Zt,Ap as _,qf as _a,Cs as _c,Af as _i,ap as _l,UE as _n,ZS as _o,ic as _r,Qu as _s,ec as _t,sd as _u,wp as a,_T as aa,Lg as ac,Rb as ai,zw as al,XE as an,mp as ao,tD as ar,fT as as,VS as at,MT as au,Pb as b,zm as ba,Jp as bc,Ob as bi,qp as bl,IS as bn,Xv as bo,by as br,Ix as bs,nD as bt,Hs as bu,If as c,$ as ca,cp as cc,cC as ci,N as cl,Iy as cn,YT as co,Ep as cr,vu as cs,dT as ct,Of as cu,ac as d,Cc as da,ws as dc,Cy as di,Km as dl,Np as dn,Tb as do,Cf as dr,mf as ds,hp as dt,Bs as du,ox as ea,am as ec,Ru as ei,mb as el,Tu as en,PS as eo,jf as er,cf as es,aE as et,Ff as eu,ey as f,uS as fa,oT as fc,xd as fi,nm as fl,b_ as fn,ys as fo,Rf as fr,Xc as fs,ET as ft,hT as fu,gd as g,Sb as ga,Hu as gc,Nb as gi,Xl as gl,km as gn,cT as go,PE as gr,bS as gs,ld as gt,V_ as gu,Nu as h,Pp as ha,Wy as hc,VT as hi,P as hl,Kf as hn,sp as ho,Dm as hr,yT as hs,wm as ht,sg as hu,Ku as i,uc as ia,My as ic,R as ii,_E as il,jm as in,mu as io,h_ as ir,Os as is,dm as it,Qy as iu,iT as j,tc as ja,Bl as jc,ix as ji,Vu as jl,Bb as jn,lT as jo,Tp as jr,cl as js,fx as jt,Vm as ju,Fb as k,Em as ka,Xp as kc,oS as ki,OS as kl,Wf as kn,Ib as ko,eD as kr,wg as ks,sx as kt,X as ku,lg as l,vg as la,$m as lc,ob as li,zl as ll,qb as ln,ff as lo,Ph as lr,gp as ls,Fu as lt,pm as lu,wf as m,Ju as ma,pp as mc,zc as mi,Ty as ml,Bv as mn,eu as mo,Hx as mr,Vs as ms,pf as mt,_p as mu,$E as n,vb as na,Db as nc,Mu as ni,Yf as nl,Qs as nn,sT as no,od as nr,uE as ns,Nf as nt,hm as nu,Kl as o,rx as oa,$p as oc,_m as oi,ud as ol,xc as on,fd as oo,uv as or,Sg as os,lE as ot,Eu as ou,oD as p,Xb as pa,pu as pc,ju as pi,gs as pl,Zs as pn,ky as po,F as pr,pE as ps,LE as pt,bu as pu,lb as q,jy as qa,Fm as qc,Yh as qi,Nw as ql,sb as qn,Fy as qo,Ou as qr,Bp as qs,mm as qt,av as r,Rp as ra,bs as rc,Pf as ri,Yp as rl,Df as rn,cg as ro,kE as rr,Lb as rs,zy as rt,qs as ru,$l as s,Xf as sa,ru as sc,xE as si,Kc as sl,lS as sn,TT as so,pd as sr,Bu as ss,Es as st,Ng as su,Zb as t,BS as ta,gT as tc,Sp as ti,lx as tl,vp as tn,Ts as to,Cm as tr,fm as ts,tx as tt,gb as tu,Om as u,Mm as ua,lm as uc,v_ as ui,RS as ul,nl as un,im as uo,Dw as ur,Zu as us,Gl as ut,XS as uu,m_ as v,j as va,Mc as vc,om as vi,Ky as vl,gc as vn,uT as vo,kv as vr,rf as vs,vv as vt,hf as vu,ME as w,Js as wa,Rl as wc,su as wi,Lc as wl,jp as wn,Dy as wo,md as wr,yd as ws,o_ as wt,$u as wu,qu as x,Sx as xa,Rw as xc,Py as xi,Lw as xl,sD as xn,rm as xo,dd as xr,ug as xs,yv as xt,bT as xu,Ex as y,gS as ya,df as yc,vT as yi,Xm as yl,ny as yn,Qm as yo,aD as yr,Su as ys,y_ as yt,hE as yu,Fp as z,_s as za,ql as zc,GE as zi,fu as zl,bp as zn,Xd as zo,Wp as zr,Ds as zs,yc as zt,Yo as zu};
41
+ `).trim()}:n:{type:`text`,value:(e.clipboardData?.getData(M.text)||``).trim()}}catch{return{type:`text`,value:``}}},Nw=async(e,t=!1)=>{let n=await Mw(e,t);if(n.type===`mixedContent`)return{mixedContent:n.value};try{let e=!t&&Ow(n.value);if(e)return e}catch(e){console.error(e)}try{let e=JSON.parse(n.value),r=e.type===Js.excalidrawClipboardWithAPI;if(ww(e))return{elements:e.elements,files:e.files,text:t?JSON.stringify(e.elements,null,2):void 0,programmaticAPI:r}}catch{}return{text:n.value}},Pw=async e=>{try{await navigator.clipboard.write([new window.ClipboardItem({[M.png]:e})])}catch(t){if(Du(e))await navigator.clipboard.write([new window.ClipboardItem({[M.png]:await e})]);else throw t}},Fw=async(e,t)=>{if(Sw)try{await navigator.clipboard.writeText(e||``);return}catch(e){console.error(e)}try{if(t){if(t.clipboardData?.setData(M.text,e||``),t.clipboardData?.getData(M.text)!==e)throw Error(`Failed to setData on clipboardEvent`);return}}catch(e){console.error(e)}if(!Iw(e))throw Error(`Error copying to clipboard.`)},Iw=e=>{e||=` `;let t=document.documentElement.getAttribute(`dir`)===`rtl`,n=document.createElement(`textarea`);n.style.border=`0`,n.style.padding=`0`,n.style.margin=`0`,n.style.position=`absolute`,n.style[t?`right`:`left`]=`-9999px`;let r=window.pageYOffset||document.documentElement.scrollTop;n.style.top=`${r}px`,n.style.fontSize=`12pt`,n.setAttribute(`readonly`,``),n.value=e,document.body.appendChild(n);let i=!1;try{n.select(),n.setSelectionRange(0,n.value.length),i=document.execCommand(`copy`)}catch(e){console.error(e)}return n.remove(),i},Lw=({elements:e,appState:t,files:n,maxWidthOrHeight:r,getDimensions:i,exportPadding:a,exportingFrame:o})=>{let{elements:s,appState:c}=QC({elements:e,appState:t},null,null),{exportBackground:l,viewBackgroundColor:u}=c;return nC(s,{...c,offsetTop:0,offsetLeft:0,width:0,height:0},n||{},{exportBackground:l,exportPadding:a,viewBackgroundColor:u,exportingFrame:o},(e,n)=>{let a=document.createElement(`canvas`);if(r){typeof i==`function`&&console.warn("`getDimensions()` is ignored when `maxWidthOrHeight` is supplied.");let o=Math.max(e,n),s=r<o?r/o:t?.exportScale??1;return a.width=e*s,a.height=n*s,{canvas:a,scale:s}}let o=i?.(e,n)||{width:e,height:n};return a.width=o.width,a.height=o.height,{canvas:a,scale:o.scale??1}})},Rw=async e=>{let{mimeType:t=M.png,quality:n}=e;t===M.png&&typeof n==`number`&&console.warn(`"quality" will be ignored for "${M.png}" mimeType`),t===`image/jpg`&&(t=M.jpg),t===M.jpg&&!e.appState?.exportBackground&&(console.warn(`Defaulting "exportBackground" to "true" for "${M.jpg}" mimeType`),e={...e,appState:{...e.appState,exportBackground:!0}});let r=await Lw(e);return n||=/image\/jpe?g/.test(t)?.92:.8,new Promise((i,a)=>{r.toBlob(async n=>{if(!n)return a(Error(`couldn't export to blob`));n&&t===M.png&&e.appState?.exportEmbedScene&&(n=await xD({blob:n,metadata:yS(e.elements,e.appState,e.files||{},`local`)})),i(n)},t,n)})},zw=async({elements:e,appState:t=Mc(),files:n={},exportPadding:r,renderEmbeddables:i,exportingFrame:a,skipInliningFonts:o,reuseImages:s})=>{let{elements:c,appState:l}=QC({elements:e,appState:t},null,null);return iC(c,{...l,exportPadding:r},n,{exportingFrame:a,renderEmbeddables:i,skipInliningFonts:o,reuseImages:s})},Bw=e=>e.type===`diamond`?[I(e.width/2,0),I(e.width,e.height/2),I(e.width/2,e.height),I(0,e.height/2)]:[I(0,0),I(0+e.width,0),I(0+e.width,e.height),I(0,e.height)],Vw=e=>rd(e)||td(e)?e.points:Bw(e),Hw=e=>{let t=e.reduce((e,[t,n])=>(e.minY=Math.min(e.minY,n),e.minX=Math.min(e.minX,t),e.maxX=Math.max(e.maxX,t),e.maxY=Math.max(e.maxY,n),e),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,cx:0,cy:0});return t.cx=(t.maxX+t.minX)/2,t.cy=(t.maxY+t.minY)/2,t},Uw=e=>{let t=Vw(e),{cx:n,cy:r}=Hw(t),i=I(n,r),{minX:a,minY:o,maxX:s,maxY:c}=Hw(t.map(t=>R(t,i,e.angle)));return[a+e.x,o+e.y,s+e.x,c+e.y]},Ww=(e,t,n=!1)=>{let r=Uw(e),i=t[0]<=r[0]&&t[2]>=r[2]&&t[1]<=r[1]&&t[3]>=r[3];return n?i?!0:r[0]<=t[0]&&r[2]>=t[2]&&r[1]<=t[1]&&r[3]>=t[3]:i},Gw=(e,t)=>{let n=Uw(e);return(Il(n[0],Nl(t[0],t[2]))||Il(t[0],Nl(n[0],n[2])))&&(Il(n[1],Nl(t[1],t[3]))||Il(t[1],Nl(n[1],n[3])))},Kw=({elements:e,bounds:t,type:n,errorMargin:r=0})=>{ud(t)&&(t=iv(t,_u(e)));let i=[t[0]-r,t[1]-r,t[2]+r,t[3]+r],a=new Set;for(let t of e)if(!a.has(t.id)&&(n===`overlap`?Gw(t,i):n===`inside`?Ww(t,i):Ww(t,i,!0))){if(a.add(t.id),t.boundElements)for(let e of t.boundElements)a.add(e.id);B(t)&&t.containerId&&a.add(t.containerId),V(t)&&(t.startBinding&&a.add(t.startBinding.elementId),t.endBinding&&a.add(t.endBinding?.elementId))}return e.filter(e=>a.has(e.id))};function qw(e){return[Math.min(e[0][0],e[1][0]),Math.min(e[0][1],e[1][1]),Math.max(e[0][0],e[1][0]),Math.max(e[0][1],e[1][1])]}function Jw(e,t){return e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1]}var Yw=1e-6;function Xw(e,t){let n=Yc(F(e[1],e[0]),F(t,e[0]));return Math.abs(n)<Yw}function Zw(e,t){return Yc(F(e[1],e[0]),F(t,e[0]))<0}function Qw(e,t){return Xw(e,t[0])||Xw(e,t[1])||(Zw(e,t[0])?!Zw(e,t[1]):Zw(e,t[1]))}function $w(e,t){return Jw(qw(e),qw(t))&&Qw(e,t)&&Qw(t,e)}var eT=(e,t,n)=>{let r=_u(e);for(let e of t)if(e.frameId){let t=n.get(e.id),i=n.get(e.frameId);if(t){let n=r.get(t);n&&$(n,{frameId:i??e.frameId},!1)}}};function tT(e,t,n){let r=G_(t,n),i=G_(e,n);return r.some(e=>i.some(t=>$w(e,t)))}var nT=(e,t,n)=>xT(kT(e,t,n,!1)).filter(e=>!ed(e)&&!e.frameId||e.frameId===t.id),rT=(e,t,n)=>kT([t],e,n).some(e=>e.id===t.id),iT=(e,t,n)=>{let[r,i,a,o]=J(t,n),[s,c,l,u]=av(e);return r<=s&&i<=c&&a>=l&&o>=u},aT=(e,t,n)=>iT([e],t,n)||tT(e,t,n)||rT(e,t,n),oT=(e,t,n)=>{let[r,i,a,o]=J(t,n);return dl(I(r,i),I(e.x,e.y),I(a,o))},sT=e=>{let t=new Map;for(let n of e){let r=ed(n)?n.id:n.frameId;r&&!t.has(r)&&t.set(r,cT(e,r))}return t},cT=(e,t)=>{let n=[];for(let r of e.values())r.frameId===t&&n.push(r);return n},lT=e=>e.filter(e=>ed(e)),uT=e=>{let t=_u(lT(e));return e.filter(e=>t.has(e.id)||!e.frameId||!t.has(e.frameId))},dT=(e,t,n,r)=>{let i=cT(e,t.id),a=new Set(i),o=new Set([...nT(e,t,r),...i.filter(e=>rT(e,t,r))]),s=i.filter(e=>!o.has(e)),c=new Set(Array.from(o).flatMap(e=>e.groupIds));for(let e of s)if(!tT(e,t,r))e.groupIds.length===0&&a.delete(e);else if(e.groupIds.length>0)for(let t of e.groupIds)c.add(t);for(let e of s)if(e.groupIds.length>0){let t=!0;for(let n of e.groupIds)c.has(n)&&(t=!1);t&&a.delete(e)}let l=Array.from(o).filter(e=>e.groupIds.length===0);for(let e of l)a.add(e);let u=Oy(Array.from(o).filter(e=>e.groupIds.length>0),n);for(let[n,i]of Object.entries(u))if(i){let i=jy(e,n);if(iT(i,t,r))for(let e of i)a.add(e)}return[...a].filter(e=>!(B(e)&&e.containerId))},fT=(e,t,n)=>pT(xT(e,nT(e,t,n)),t,n),pT=(e,t,n)=>{let r=[],i=new Map;for(let a of e){let e=!1;if(a.groupIds.length>0){if(a.groupIds.some(e=>i.get(e)))e=!0;else{let r=new Set(a.groupIds.flatMap(e=>jy(n,e)));e=!iT(Array.from(r),t,n)}a.groupIds.forEach(t=>{i.set(t,e)})}e||r.push(a)}return r},mT=(e,t)=>e.frameId&&t.get(e.frameId)||null,hT=(e,t)=>{let n=new Set,r=_u(e);e=xT(e);for(let r of e)ed(r)&&r.id!==t.id&&n.add(r.id);let i=new Set,a=[];for(let o of e)if(!(ed(o)||o.frameId&&n.has(o.frameId))){if(o.groupIds.length){let n=o.groupIds.at(-1);if(!i.has(n)){i.add(n);let o=jy(e,n);if(o.some(e=>aT(e,t,r)))for(let e of o)a.push(e)}}else aT(o,t,r)&&a.push(o)}return a},gT=(e,t,n,r)=>{let i=_u(e),a=new Map;for(let t of e.values())t.frameId===n.id&&a.set(t.id,!0);let o=new Set(t.map(e=>e.id)),s=[],c=new Set;for(let e of t)ed(e)&&e.id!==n.id&&c.add(e.id);for(let n of xT(e,t)){if(ed(n)||n.frameId&&c.has(n.frameId)||n.frameId&&r.selectedElementIds[n.id]&&r.selectedElementIds[n.frameId])continue;a.has(n.id)||s.push(n);let e=Cb(n,i);e&&!o.has(e.id)&&!a.has(e.id)&&s.push(e)}for(let e of s)$(e,{frameId:n.id},!1);return e},_T=(e,t)=>{let n=new Map,r=new Map;for(let i of e)if(i.frameId){n.set(i.id,i);let e=r.get(i.frameId)||[];e.push(i);let a=Cb(i,t);a&&(n.set(a.id,a),e.push(a)),r.set(i.frameId,e)}for(let[,e]of n)$(e,{frameId:null},!1)},vT=(e,t)=>(_T(cT(e,t.id),_u(e)),e),yT=(e,t,n,r)=>gT(vT(e,n),t,n,r.state).slice(),bT=(e,t,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,elements:e}),i=new Set(r);if(t.editingGroupId)for(let t of r)t.groupIds.length===0?i.add(t):t.groupIds.flatMap(t=>jy(e,t)).forEach(e=>i.add(e));let a=new Set,o=_u(e);return i.forEach(e=>{e.frameId&&!ed(e)&&!CT(e,o,t)&&a.add(e)}),a.size>0&&_T(a,o),e},xT=(e,t)=>{let n=new Set,r=t||e;for(let e of r.values()){let t=e.groupIds[e.groupIds.length-1];t&&n.add(t)}let i=new Set;for(let t of n)jy(e,t).some(e=>ed(e))&&i.add(t);let a=[];for(let e of r.values())i.has(e.groupIds[e.groupIds.length-1])||a.push(e);return a},ST=(e,t,n)=>{let r=B(e)&&wb(e,t)||e;return r.frameId&&n.selectedElementIds[r.id]&&n.selectedElementIds[r.frameId]?mT(r,t):n.selectedElementIds[r.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:mT(r,t)},CT=(e,t,n,r)=>{let i=r?.targetFrame??ST(e,t,n);if(!i)return!1;let a=B(e)&&wb(e,t)||e,o=e=>{r?.checkedGroups&&a.groupIds.forEach(t=>{r.checkedGroups?.set(t,e)})};if(!n.selectedElementIds[a.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[a.id]&&n.selectedElementIds[i.id])return!0;if(a.groupIds.length===0)return aT(a,i,t);for(let e of a.groupIds)if(r?.checkedGroups?.has(e))return r.checkedGroups.get(e);let s=new Set(a.groupIds.filter(e=>!r?.checkedGroups||!r.checkedGroups.has(e)).flatMap(e=>jy(t,e)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let e=new Set(NT(t,n));if(n.frameToHighlight!==null)return!0;e.forEach(e=>{s.delete(e)})}for(let e of s)if(ed(e))return o(!1),!1;for(let e of s)if(aT(e,i,t))return o(!0),!0;return!1},wT=(e,t,n,r,i)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let a=tT(e,t,r)||rT(e,t,r);if(a){for(let t of e.groupIds)i?.set(t,!0);return!0}if(!a&&e.groupIds.length>0&&!iT([e],t,r)){let a=!1;if(n.selectedElementsAreBeingDragged)a=CT(e,r,n,{targetFrame:t,checkedGroups:i});else{a=e.frameId===t.id;for(let t of e.groupIds)i?.set(t,a)}for(let t of e.groupIds)i?.set(t,a);return a}return!1},TT=e=>e.name===null?Qu(e)?`Frame`:`AI Frame`:e.name,ET=(e,t)=>Kw({elements:e,bounds:t,type:`overlap`}).filter(e=>!e.frameId||e.frameId===t.id),DT=e=>{let t=_u(e);return e.length>1&&e.some(e=>e.frameId&&t.has(e.frameId))},OT=e=>{let t=new Set;return e.forEach(e=>{ed(e)&&t.add(e.id)}),e.filter(e=>!(e.frameId&&t.has(e.frameId)))},kT=(e,t,n,r=!0)=>{let[i,a,o,s]=J(t,n),c=e.filter(e=>{let[t,r,c,l]=iv(e,n),u=mT(e,n);if(u){let[e,i,a,o]=iv(u,n);t=Math.max(e,t),r=Math.max(i,r),c=Math.min(a,c),l=Math.min(o,l)}return e.locked===!1&&e.type!==`selection`&&!pd(e)&&i<=t&&a<=r&&o>=c&&s>=l});return c=r?OT(c):c,c=c.filter(e=>{let t=mT(e,n);return!t||aT(e,t,n)}),c},AT=(e,t,n,r)=>{let i=new Set(t.map(e=>e.id));return e.filter(e=>{let t=GT(e,n.width,n.height,n,r);return!i.has(e.id)&&t})},jT=function(){let e=null,t=null,n=null,r=(r,i)=>(n!=null&&r===e&&i.selectedElementIds===t||(n=r.some(e=>i.selectedElementIds[e.id]),e=r,t=i.selectedElementIds),n);return r.clearCache=()=>{e=null,t=null,n=null},r}(),MT=(e,t,n)=>{let r=Array.from(new Set(NT(e,t).map(e=>n(e))));return r.length===1?r[0]:null},NT=(e,t,n)=>{let r=new Set,i=[];for(let a of e.values()){if(t.selectedElementIds[a.id]){i.push(a),r.add(a.id);continue}if(n?.includeBoundTextElement&&pd(a)&&t.selectedElementIds[a?.containerId]){i.push(a),r.add(a.id);continue}}if(n?.includeElementsInFrames){let t=[];return i.forEach(n=>{ed(n)&&cT(e,n.id).forEach(e=>!r.has(e.id)&&t.push(e)),t.push(n)}),t}return i},PT=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:NT(e,t,{includeBoundTextElement:!0}),FT=(e,t)=>Au(t.selectedElementIds,e)?t.selectedElementIds:e,IT=e=>{let t=new Map,n=[];for(let r of e)r.isDeleted||(n.push(r),t.set(r.id,r));return{elementsMap:t,elements:n}},LT=(0,Fi.default)(e=>{(s.DEV||s.MODE===Ds.TEST||window?.DEBUG_FRACTIONAL_INDICES)&&Cx(e,{shouldThrow:s.DEV||s.MODE===Ds.TEST,includeBoundTextValidation:!0})},6e4,{leading:!0,trailing:!1}),RT=e=>{let t=[`includeBoundTextElement`,`includeElementsInFrames`],n=``;for(let r of t)n+=`${r}:${e[r]?`1`:`0`}`;return n},zT=e=>typeof e==`string`,BT=class e{constructor(){o(this,`callbacks`,new Set),o(this,`nonDeletedElements`,[]),o(this,`nonDeletedElementsMap`,Vu(new Map)),o(this,`elements`,[]),o(this,`nonDeletedFramesLikes`,[]),o(this,`frames`,[]),o(this,`elementsMap`,Vu(new Map)),o(this,`selectedElementsCache`,{selectedElementIds:null,elements:null,cache:new Map}),o(this,`sceneNonce`),o(this,`insertElement`,e=>{let t=e.frameId?this.getElementIndex(e.frameId):this.elements.length;this.insertElementAtIndex(e,t)}),o(this,`insertElements`,e=>{if(!e.length)return;let t=e[0]?.frameId?this.getElementIndex(e[0].frameId):this.elements.length;this.insertElementsAtIndex(e,t)}),o(this,`getContainerElement`,e=>e&&e.containerId&&this.getElement(e.containerId)||null),o(this,`getElementsFromId`,e=>{let t=this.getNonDeletedElementsMap(),n=t.get(e);return n?[n]:jy(t,e)})}static mapElementToScene(e,t){zT(e)?this.sceneMapById.set(e,t):(this.sceneMapByElement.set(e,t),this.sceneMapById.set(e.id,t))}static getScene(e){return zT(e)?this.sceneMapById.get(e)||null:this.sceneMapByElement.get(e)||null}getSceneNonce(){return this.sceneNonce}getNonDeletedElementsMap(){return this.nonDeletedElementsMap}getElementsIncludingDeleted(){return this.elements}getElementsMapIncludingDeleted(){return this.elementsMap}getNonDeletedElements(){return this.nonDeletedElements}getFramesIncludingDeleted(){return this.frames}getSelectedElements(e){let t=RT(e),n=e?.elements||this.nonDeletedElements;if(this.selectedElementsCache.elements===n&&this.selectedElementsCache.selectedElementIds===e.selectedElementIds){let e=this.selectedElementsCache.cache.get(t);if(e)return e}else e?.elements??this.selectedElementsCache.cache.clear();let r=NT(n,{selectedElementIds:e.selectedElementIds},e);return e?.elements??(this.selectedElementsCache.selectedElementIds=e.selectedElementIds,this.selectedElementsCache.elements=this.nonDeletedElements,this.selectedElementsCache.cache.set(t,r)),r}getNonDeletedFramesLikes(){return this.nonDeletedFramesLikes}getElement(e){return this.elementsMap.get(e)||null}getNonDeletedElement(e){let t=this.getElement(e);return t&&RE(t)?t:null}mapElements(e){let t=!1,n=this.elements.map(n=>{let r=e(n);return r!==n&&(t=!0),r});return t&&this.replaceAllElements(n),t}replaceAllElements(t){let n=t instanceof Array?t:Array.from(t.values()),r=[];LT(n),this.elements=Ex(n),this.elementsMap.clear(),this.elements.forEach(t=>{ed(t)&&r.push(t),this.elementsMap.set(t.id,t),e.mapElementToScene(t,this)});let i=IT(this.elements);this.nonDeletedElements=i.elements,this.nonDeletedElementsMap=i.elementsMap,this.frames=r,this.nonDeletedFramesLikes=IT(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=ex();for(let e of Array.from(this.callbacks))e()}onUpdate(e){if(this.callbacks.has(e))throw Error();return this.callbacks.add(e),()=>{if(!this.callbacks.has(e))throw Error();this.callbacks.delete(e)}}destroy(){this.elements=[],this.nonDeletedElements=[],this.nonDeletedFramesLikes=[],this.frames=[],this.elementsMap.clear(),this.selectedElementsCache.selectedElementIds=null,this.selectedElementsCache.elements=null,this.selectedElementsCache.cache.clear(),e.sceneMapById.forEach((t,n)=>{t===this&&e.sceneMapById.delete(n)}),this.callbacks.clear()}insertElementAtIndex(e,t){if(!Number.isFinite(t)||t<0)throw Error(`insertElementAtIndex can only be called with index >= 0`);let n=[...this.elements.slice(0,t),e,...this.elements.slice(t)];Tx(n,_u([e])),this.replaceAllElements(n)}insertElementsAtIndex(e,t){if(!e.length)return;if(!Number.isFinite(t)||t<0)throw Error(`insertElementAtIndex can only be called with index >= 0`);let n=[...this.elements.slice(0,t),...e,...this.elements.slice(t)];Tx(n,_u(e)),this.replaceAllElements(n)}getElementIndex(e){return this.elements.findIndex(t=>t.id===e)}};o(BT,`sceneMapByElement`,new WeakMap),o(BT,`sceneMapById`,new Map);var VT=BT,$=(e,t,n=!0,r)=>{let i=!1,{points:a,fixedSegments:o,fileId:s,startBinding:c,endBinding:l}=t;if(H(e)&&(Object.keys(t).length===0||typeof a<`u`||typeof o<`u`||typeof c<`u`||typeof l<`u`)){let n=Vu(VT.getScene(e)?.getNonDeletedElementsMap()??new Map);t={...t,angle:0,...hC({...e,x:t.x||e.x,y:t.y||e.y},n,{fixedSegments:o,points:a,startBinding:c,endBinding:l},{isDragging:r?.isDragging})}}else typeof a<`u`&&(t={...V_(a),...t});for(let n in t){let r=t[n];if(typeof r<`u`){if(e[n]===r&&(typeof r!=`object`||!r||n===`groupIds`||n===`scale`))continue;if(n===`scale`){let t=e[n],i=r;if(t[0]===i[0]&&t[1]===i[1])continue}else if(n===`points`){let t=e[n],i=r;if(t.length===i.length){let e=!1,n=t.length;for(;--n;){let r=t[n],a=i[n];if(r[0]!==a[0]||r[1]!==a[1]){e=!0;break}}if(!e)continue}}e[n]=r,i=!0}}return i&&((typeof t.height<`u`||typeof t.width<`u`||typeof s<`u`||typeof a<`u`)&&rf.delete(e),e.version++,e.versionNonce=ex(),e.updated=gu(),n&&VT.getScene(e)?.triggerUpdate()),e},HT=(e,t,n=!1)=>{let r=!1;for(let n in t){let i=t[n];if(typeof i<`u`){if(e[n]===i&&(typeof i!=`object`||!i))continue;r=!0}}return!r&&!n?e:{...e,...t,updated:gu(),version:e.version+1,versionNonce:ex()}},UT=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=ex(),e.updated=gu(),e),WT=e=>rd(e)||td(e)?e.points.length<2:e.width===0&&e.height===0,GT=(e,t,n,r,i)=>{let[a,o,s,c]=iv(e,i),l=tu({clientX:r.offsetLeft,clientY:r.offsetTop},r),u=tu({clientX:r.offsetLeft+t,clientY:r.offsetTop+n},r);return l.x<=s&&l.y<=c&&u.x>=a&&u.y>=o},KT=(e,t,n,r,i,a)=>{let[o,s,c,l]=av(e,i),u=tu({clientX:r.offsetLeft+(a?.left||0),clientY:r.offsetTop+(a?.top||0)},r),d=tu({clientX:r.offsetLeft+t-(a?.right||0),clientY:r.offsetTop+n-(a?.bottom||0)},r);return o>=u.x&&s>=u.y&&c<=d.x&&l<=d.y},qT=(e,t,n)=>{let r=Math.abs(t),i=Math.abs(n);if(e===`line`||e===`arrow`||e===`freedraw`){let e=Math.round(Math.atan(i/r)/Ss)*Ss;e===0?n=0:e===Math.PI/2?t=0:n=r*Math.tan(e)*Math.sign(n)||n}else e!==`selection`&&(n=r*Math.sign(n));return{width:t,height:n}},JT=(e,t,n,r)=>{let i=n-e,a=r-t,o=Math.round(Math.atan(a/i)/Ss)*Ss;if(o===0)a=0;else if(o===Math.PI/2)i=0;else{let s=Math.tan(o),c=t-s*e,l=-1/s,u=r-l*n,d=(-1*u- -1*c)/(s*-1-l*-1),f=(c*l-u*s)/(s*-1-l*-1);i=d-e,a=f-t}return{width:i,height:a}},YT=e=>{let t={width:e.width,height:e.height,x:e.x,y:e.y};if(e.width<0){let n=Math.abs(e.width);t.width=n,t.x=e.x-n}if(e.height<0){let n=Math.abs(e.height);t.height=n,t.y=e.y-n}return t},XT={mouse:8,pen:16,touch:28},ZT=16,QT={e:!0,s:!0,n:!0,w:!0},$T={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},eE={e:!0,s:!0,n:!0,w:!0},tE=(e,t,n,r,i,a,o)=>{let[s,c]=R(I(e+n/2,t+r/2),I(i,a),o);return[s-n/2,c-r/2,n,r]},nE=e=>!(e.viewport.isMobile||e.isTouchScreen&&(ms||_s)),rE=e=>nE(e)?QT:{},iE=([e,t,n,r,i,a],o,s,c,l={},u=4,d=2)=>{let f=XT[c],p=f/s.value,m=f/s.value,h=f/s.value,g=f/s.value,_=n-e,v=r-t,y=u/s.value,b=(f-d*2)/(2*s.value),x={nw:l.nw?void 0:tE(e-y-h+b,t-y-g+b,p,m,i,a,o),ne:l.ne?void 0:tE(n+y-b,t-y-g+b,p,m,i,a,o),sw:l.sw?void 0:tE(e-y-h+b,r+y-b,p,m,i,a,o),se:l.se?void 0:tE(n+y-b,r+y-b,p,m,i,a,o),rotation:l.rotation?void 0:tE(e+_/2-p/2,t-y-g+b-ZT/s.value,p,m,i,a,o)},S=5*XT.mouse/s.value;return Math.abs(_)>S&&(l.n||(x.n=tE(e+_/2-p/2,t-y-g+b,p,m,i,a,o)),l.s||(x.s=tE(e+_/2-p/2,r+y-b,p,m,i,a,o))),Math.abs(v)>S&&(l.w||(x.w=tE(e-y-h+b,t+v/2-m/2,p,m,i,a,o)),l.e||(x.e=tE(n+y-b,t+v/2-m/2,p,m,i,a,o))),x},aE=(e,t,n,r=`mouse`,i=QT)=>{if(e.locked||H(e))return{};if(e.type===`freedraw`||rd(e)){if(e.points.length===2){let[,t]=e.points;t[0]===0||t[1]===0?i=eE:t[0]>0&&t[1]<0?i=$T:t[0]>0&&t[1]>0?i=eE:t[0]<0&&t[1]>0?i=$T:t[0]<0&&t[1]<0&&(i=eE)}}else ed(e)&&(i={...i,rotation:!0});let a=rd(e)?10:Ju(e)?0:2;return iE(J(e,n,!0),e.angle,t,r,i,a,Ju(e)?0:void 0)},oE=(e,t)=>{if(t.editingLinearElement)return!1;if(e.length>1)return!0;let n=e[0];return H(n)?!1:!rd(n)||n.points.length>2},sE=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],cE=(e,t,n,r,i,a,o,s)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:c,...l}=aE(e,a,t,o,rE(s));if(c&&sE(c,r,i))return`rotation`;let u=Object.keys(l).filter(e=>{let t=l[e];return t?sE(t,r,i):!1});if(u.length>0)return u[0];if(nE(s)){let[n,o,s,c,l,u]=J(e,t);if(!(rd(e)&&e.points.length<=2)){let t=Ju(e)?0:zs/a.value,d=zs/a.value,f=mE(I(n-t,o-t),I(s+t,c+t),I(l,u),e.angle);for(let[e,t]of Object.entries(f))if(ml(I(r,i),t,d))return e}}return!1},lE=(e,t,n,r,i,a,o,s)=>e.reduce((e,c)=>{if(e)return e;let l=cE(c,o,t,n,r,i,a,s);return l?{element:c,transformHandleType:l}:null},null),uE=([e,t,n,r],i,a,o,s,c)=>{let l=iE([e,t,n,r,(e+n)/2,(t+r)/2],0,o,s,rE(c)),u=Object.keys(l).find(e=>{let t=l[e];return t&&sE(t,i,a)});if(u)return u;if(nE(c)){let s=(e+n)/2,c=(t+r)/2,l=zs/o.value,u=mE(I(e-l,t-l),I(n+l,r+l),I(s,c),0);for(let[e,t]of Object.entries(u))if(ml(I(i,a),t,l))return e}return!1},dE=[`ns`,`nesw`,`ew`,`nwse`],fE=(e,t)=>{let n=dE.indexOf(e);return n>=0&&(e=dE[(n+Math.round(t/(Math.PI/4)))%dE.length]),e},pE=e=>{let{element:t,transformHandleType:n}=e,r=t&&Math.sign(t.height)*Math.sign(t.width)===-1,i=null;switch(n){case`n`:case`s`:i=`ns`;break;case`w`:case`e`:i=`ew`;break;case`nw`:case`se`:i=r?`nesw`:`nwse`;break;case`ne`:case`sw`:i=r?`nwse`:`nesw`;break;case`rotation`:return`grab`}return i&&t&&(i=fE(i,t.angle)),i?`${i}-resize`:``},mE=([e,t],[n,r],i,a)=>{let o=R(I(e,t),i,a),s=R(I(n,t),i,a),c=R(I(e,r),i,a),l=R(I(n,r),i,a);return{n:[o,s],e:[s,l],s:[l,c],w:[c,o]}},hE=(e,t,n,r,i,a,o,s,c,l,u,d)=>{if(n.length===1){let[u]=n;if(t===`rotation`)H(u)||(gE(u,r,i,c,l,a),Bv(u,r));else{if(B(u)&&t)return yE(e,u,r,t,o,c,l),Bv(u,r),!0;if(t){let i=n[0].id,a=r.get(i),u=e.get(i);if(a&&u){let{nextWidth:n,nextHeight:i}=EE(a,u,r,e,t,c,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:o});TE(n,i,a,u,r,e,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:o})}}}return!0}if(n.length>1){if(t===`rotation`)return bE(e,n,r,i,c,l,a,u,d),!0;if(t){let{nextWidth:a,nextHeight:u,flipByX:d,flipByY:f,originalBoundingBox:p}=DE(n,e,r,t,c,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:o});return OE(n,r,t,i,e,{shouldResizeFromCenter:o,shouldMaintainAspectRatio:s,flipByX:d,flipByY:f,nextWidth:a,nextHeight:u,originalBoundingBox:p}),!0}}return!1},gE=(e,t,n,r,i,a)=>{let[o,s,c,l]=J(e,t),u=(o+c)/2,d=(s+l)/2,f;ed(e)?f=0:(f=5*Math.PI/2+Math.atan2(i-d,r-u),a&&(f+=Ss/2,f-=f%Ss),f=Wc(f));let p=Sb(e);if($(e,{angle:f}),p){let t=n.getElement(p);t&&!V(e)&&$(t,{angle:f})}},_E=(e,t,n,r)=>rd(e)||td(e)?{points:H_(0,t,H_(1,n,e.points,r),r)}:{},vE=(e,t,n)=>{let r=e.width;if(pd(e)){let n=wb(e,t);n&&(r=Nb(n,e))}let i=e.fontSize*(n/r);return i<Is?null:{size:i}},yE=(e,t,n,r,i,a,o)=>{let[s,c,l,u,d,f]=J(t,n),[p,m]=R(I(a,o),I(d,f),-t.angle),h=0,g=0;r!==`e`&&r!==`w`&&(r.includes(`e`)&&(h=(p-s)/(l-s)),r.includes(`w`)&&(h=(l-p)/(l-s)),r.includes(`n`)&&(g=(u-m)/(u-c)),r.includes(`s`)&&(g=(m-c)/(u-c)));let _=Math.max(h,g);if(_>0){let e=t.width*_,a=t.height*_,o=vE(t,n,e);if(o===null)return;let p=[s,c],m=[l,u],h=[d,f],g=I(s,c);if([`n`,`w`,`nw`].includes(r)&&(g=I(m[0]-Math.abs(e),m[1]-Math.abs(a))),r===`ne`){let e=[p[0],m[1]];g=I(e[0],e[1]-Math.abs(a))}if(r===`sw`){let t=[m[0],p[1]];g=I(t[0]-Math.abs(e),t[1])}[`s`,`n`].includes(r)&&(g[0]=h[0]-e/2),[`e`,`w`].includes(r)&&(g[1]=h[1]-a/2),i&&(g[0]=h[0]-Math.abs(e)/2,g[1]=h[1]-Math.abs(a)/2);let v=t.angle;g=R(R(g,I(d,f),v),R(I(g[0]+Math.abs(e)/2,g[1]+Math.abs(a)/2),I(d,f),v),-v);let[y,b]=g;$(t,{fontSize:o.size,width:e,height:a,x:y,y:b})}if(r===`e`||r===`w`){let n=e.get(t.id),[i,s,c,l]=sv(n,n.width,n.height,!0),u=I(i,s),d=I(c,l),f=sl(u,d),p=R(I(a,o),f,-n.angle),[m,,h]=sv(t,t.width,t.height,!0),g=h-m,_=d[0]-u[0],v=Sd(Gl({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),y=_/g;r.includes(`e`)&&(y=(p[0]-u[0])/g),r.includes(`w`)&&(y=(d[0]-p[0])/g);let b=t.width*y<v?v:t.width*y,x=Xd(t.originalText,Gl(t),Math.abs(b)),S=yd(x,Gl(t),t.lineHeight),C=S.height,[w,T,E,D]=sv(n,b,C,!0),ee=E-w,te=D-T,ne=[...u];[`n`,`w`,`nw`].includes(r)&&(ne=[d[0]-Math.abs(ee),u[1]]);let re=n.angle;ne=R(R(ne,f,re),R(I(ne[0]+Math.abs(ee)/2,ne[1]+Math.abs(te)/2),f,re),-re),$(t,{width:Math.abs(b),height:Math.abs(S.height),x:ne[0],y:ne[1],text:x,autoResize:!1})}},bE=(e,t,n,r,i,a,o,s,c)=>{let l=5*Math.PI/2+Math.atan2(a-c,i-s);o&&(l+=Ss/2,l-=l%Ss);for(let r of t)if(!ed(r)){let[i,a,o,u]=J(r,n),d=(i+o)/2,f=(a+u)/2,p=e.get(r.id)?.angle??r.angle,[m,h]=R(I(d,f),I(s,c),l+p-r.angle);H(r)?$(r,{points:hy(r,n)}):$(r,{x:r.x+(m-d),y:r.y+(h-f),angle:Wc(l+p)},!1),Bv(r,n,{simultaneouslyUpdated:t});let g=Cb(r,n);g&&!V(r)&&$(g,{x:g.x+(m-d),y:g.y+(h-f),angle:Wc(l+p)},!1)}r.triggerUpdate()},xE=(e,t,n,r,i)=>{let[a,o,s,c]=t.length===1?J(t[0],n):av(t),l=(a+s)/2,u=(o+c)/2,d=t.length===1?t[0].angle:0;switch([r,i]=R(I(r,i),I(l,u),-d),e){case`n`:return R(I(r-(a+s)/2,i-o),I(0,0),d);case`s`:return R(I(r-(a+s)/2,i-c),I(0,0),d);case`w`:return R(I(r-a,i-(o+c)/2),I(0,0),d);case`e`:return R(I(r-s,i-(o+c)/2),I(0,0),d);case`nw`:return R(I(r-a,i-o),I(0,0),d);case`ne`:return R(I(r-s,i-o),I(0,0),d);case`sw`:return R(I(r-a,i-c),I(0,0),d);case`se`:return R(I(r-s,i-c),I(0,0),d);default:return[0,0]}},SE=(e,t)=>{let[,[n,r]]=t.points;return e===`nw`&&(n<0||r<0)||e===`ne`&&n>=0||e===`sw`&&n<=0||e===`se`&&(n>0||r>0)?`end`:`origin`},CE=(e,t,n)=>{if(n)return`center`;if(t)switch(e){case`n`:return`south-side`;case`e`:return`west-side`;case`s`:return`north-side`;case`w`:return`east-side`;case`ne`:return`bottom-left`;case`nw`:return`bottom-right`;case`se`:return`top-left`;case`sw`:return`top-right`}return[`e`,`se`,`s`].includes(e)?`top-left`:[`n`,`nw`,`w`].includes(e)?`bottom-right`:e===`ne`?`bottom-left`:`top-right`},wE=(e,t,n,r,i,a,o,s,c)=>{let l=CE(o,s,c),[u,d]=e;switch(l){case`top-left`:return{x:u+(t-r)/2+(r-t)/2*Math.cos(a)+(n-i)/2*Math.sin(a),y:d+(n-i)/2+(r-t)/2*Math.sin(a)+(i-n)/2*Math.cos(a)};case`top-right`:return{x:u+(t-r)/2*(Math.cos(a)+1)+(n-i)/2*Math.sin(a),y:d+(n-i)/2+(t-r)/2*Math.sin(a)+(i-n)/2*Math.cos(a)};case`bottom-left`:return{x:u+(t-r)/2*(1-Math.cos(a))+(i-n)/2*Math.sin(a),y:d+(n-i)/2*(Math.cos(a)+1)+(r-t)/2*Math.sin(a)};case`bottom-right`:return{x:u+(t-r)/2*(Math.cos(a)+1)+(i-n)/2*Math.sin(a),y:d+(n-i)/2*(Math.cos(a)+1)+(t-r)/2*Math.sin(a)};case`center`:return{x:u-(r-t)/2,y:d-(i-n)/2};case`east-side`:return{x:u+(t-r)/2*(Math.cos(a)+1),y:d+(t-r)/2*Math.sin(a)+(n-i)/2};case`west-side`:return{x:u+(t-r)/2*(1-Math.cos(a)),y:d+(r-t)/2*Math.sin(a)+(n-i)/2};case`north-side`:return{x:u+(t-r)/2+(n-i)/2*Math.sin(a),y:d+(i-n)/2*(Math.cos(a)-1)};case`south-side`:return{x:u+(t-r)/2+(i-n)/2*Math.sin(a),y:d+(n-i)/2*(Math.cos(a)+1)}}},TE=(e,t,n,r,i,a,o,{shouldInformMutation:s=!0,shouldMaintainAspectRatio:c=!1,shouldResizeFromCenter:l=!1}={})=>{let u={},d=Cb(n,i);if(d){let r=a.get(d.id);if(r&&(u={fontSize:r.fontSize}),c){let r=vE(d,i,Nb({...n,width:e,height:t},d));if(r===null)return;u={fontSize:r.size}}else{let n=xd(Gl(d),d.lineHeight),r=Od(d.fontSize,d.lineHeight);e=Math.max(e,n),t=Math.max(t,r)}}let f=_E(r,e,t,!0),p=I(r.x,r.y);if(rd(r)){let[e,t]=iv(r,a);p=I(e,t)}let m=wE(p,r.width,r.height,e,t,r.angle,o,c,l);if(rd(r)&&f.points){let e=r.x-p[0],t=r.y-p[1];m.x+=e,m.y+=t;let n=f.points[0][0],i=f.points[0][1];m.x+=n,m.y+=i,f.points=f.points.map(e=>I(e[0]-n,e[1]-i))}if(e<0&&(m.x+=e),t<0&&(m.y+=t),`scale`in n&&`scale`in r&&$(n,{scale:[(Math.sign(e)||r.scale[0])*r.scale[0],(Math.sign(t)||r.scale[1])*r.scale[1]]}),V(n)&&d&&c){let t=e/n.width*d.fontSize;if(t<Is)return;u.fontSize=t}e!==0&&t!==0&&Number.isFinite(m.x)&&Number.isFinite(m.y)&&($(n,{...m,width:Math.abs(e),height:Math.abs(t),...f},s),Bv(n,i,{newSize:{width:e,height:t}}),d&&u!=null&&$(d,{fontSize:u.fontSize}),bb(n,i,o,c))},EE=(e,t,n,r,i,a,o,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:c=!1}={})=>{let[l,u,d,f]=sv(t,t.width,t.height,!0),p=I(l,u),m=I(d,f),h=sl(p,m),g=R(I(a,o),h,-t.angle),[_,v,y,b]=sv(e,e.width,e.height,!0),x=y-_,S=b-v,C=m[0]-p[0],w=m[1]-p[1],T=C/x,E=w/S;i.includes(`e`)&&(T=(g[0]-p[0])/x),i.includes(`s`)&&(E=(g[1]-p[1])/S),i.includes(`w`)&&(T=(m[0]-g[0])/x),i.includes(`n`)&&(E=(m[1]-g[1])/S);let D=e.width*T,ee=e.height*E;if(c&&(D=2*D-t.width,ee=2*ee-t.height),s){let e=Math.abs(D)/t.width,n=Math.abs(ee)/t.height;if(i.length===1&&(ee*=e,D*=n),i.length===2){let r=Math.max(e,n);D=t.width*r*Math.sign(D),ee=t.height*r*Math.sign(ee)}}return{nextWidth:D,nextHeight:ee}},DE=(e,t,n,r,i,a,{shouldMaintainAspectRatio:o=!1,shouldResizeFromCenter:s=!1}={})=>{let c=e.map(e=>t.get(e.id)),l=c.reduce((e,r)=>{if(!rd(r))return e;let i=Sb(r);if(!i)return e;let a=t.get(i)??null;return pd(a)?[...e,{...a,...X.getBoundTextElementPosition(r,a,n)}]:e},[]),u=uv(c.map(e=>e).concat(l)),{minX:d,minY:f,maxX:p,maxY:m,midX:h,midY:g}=u,_=p-d,v=m-f,y={ne:[d,m],se:[d,f],sw:[p,f],nw:[p,m],e:[d,f+v/2],w:[p,f+v/2],n:[d+_/2,m],s:[d+_/2,f]},[b,x]=s?[h,g]:y[r],S=s?2:1,C=Math.max(Math.abs(i-b)/_||0,Math.abs(a-x)/v||0)*S,w=r.includes(`e`)||r.includes(`w`)?Math.abs(i-b)*S:_,T=r.includes(`n`)||r.includes(`s`)?Math.abs(a-x)*S:v;o&&(w=_*C*Math.sign(i-b),T=v*C*Math.sign(a-x));let[E,D]={ne:[i<b,a>x],se:[i<b,a<x],sw:[i>b,a<x],nw:[i>b,a>x],e:[i<b,!1],w:[i>b,!1],n:[!1,a>x],s:[!1,a<x]}[r].map(e=>e);return{originalBoundingBox:u,nextWidth:w,nextHeight:T,flipByX:E,flipByY:D}},OE=(e,t,n,r,i,{shouldMaintainAspectRatio:a=!1,shouldResizeFromCenter:o=!1,flipByX:s=!1,flipByY:c=!1,nextHeight:l,nextWidth:u,originalBoundingBox:d}={})=>{if(u===void 0&&l===void 0&&s===void 0&&c===void 0||l===0||u===0)return;i||=t;let f=e.reduce((e,t)=>{let n=i.get(t.id);return n&&e.push({orig:n,latest:t}),e},[]),p;if(d)p=d;else{let e=f.reduce((e,{orig:n})=>{if(!rd(n))return e;let r=Sb(n);if(!r)return e;let a=i.get(r)??null;return pd(a)?[...e,{...a,...X.getBoundTextElementPosition(n,a,t)}]:e},[]);p=uv(f.map(({orig:e})=>e).concat(e))}let{minX:m,minY:h,maxX:g,maxY:_,midX:v,midY:y}=p,b=g-m,x=_-h;if(u===void 0&&l===void 0&&(u=b,l=x),a&&(u===void 0?u=b/x*l:l===void 0?l=x/b*u:Math.abs(u/l-b/x)>.001&&(u=b/x*l)),u&&l){let e=n.includes(`e`)||n.includes(`w`)?Math.abs(u)/b:1,d=n.includes(`n`)||n.includes(`s`)?Math.abs(l)/x:1,p;p=n.length===1?n.includes(`e`)||n.includes(`w`)?e:d:Math.max(Math.abs(u)/b||0,Math.abs(l)/x||0);let S={ne:[m,_],se:[m,h],sw:[g,h],nw:[g,_],e:[m,h+x/2],w:[g,h+x/2],n:[m+b/2,_],s:[m+b/2,h]},[C,w]=o?[v,y]:S[n],T=a||f.some(e=>e.latest.angle!==0||B(e.latest)||zy(e.latest));T&&(e=p,d=p);let[E,D]=[s?-1:1,c?-1:1],ee=[];for(let{orig:n,latest:r}of f){if(B(n)&&pd(n))continue;let a=n.width*e,o=n.height*d,l=Wc(n.angle*E*D),u=rd(n)||td(n),f=n.x-C,m=n.y-w,h=s&&!u?a:0,g=c&&!u?o:0,_=C+E*(f*e+h),v=w+D*(m*d+g),y=_E(n,a*E,o*D,!1),b={x:_,y:v,width:a,height:o,angle:l,...y};if(H(n)&&(n.startBinding&&(b.startBinding={...n.startBinding,fixedPoint:[s?-n.startBinding.fixedPoint[0]+1:n.startBinding.fixedPoint[0],c?-n.startBinding.fixedPoint[1]+1:n.startBinding.fixedPoint[1]]}),n.endBinding&&(b.endBinding={...n.endBinding,fixedPoint:[s?-n.endBinding.fixedPoint[0]+1:n.endBinding.fixedPoint[0],c?-n.endBinding.fixedPoint[1]+1:n.endBinding.fixedPoint[1]]}),n.fixedSegments&&y.points&&(b.fixedSegments=n.fixedSegments.map(e=>({...e,start:y.points[e.index-1],end:y.points[e.index]})))),Ju(n)&&(b.scale=[n.scale[0]*E,n.scale[1]*D]),B(n)){let e=vE(n,t,a);if(!e)return;b.fontSize=e.size}let x=i.get(Sb(n)??``);if(x){if(T){let e=x.fontSize*p;if(e<Is)return;b.boundTextFontSize=e}else b.boundTextFontSize=x.fontSize}ee.push({element:r,update:b})}let te=ee.map(({element:e})=>e);for(let{element:e,update:{boundTextFontSize:r,...i}}of ee){let{width:a,height:o,angle:s}=i;$(e,i,!1,{isDragging:!0}),Bv(e,t,{simultaneouslyUpdated:te,newSize:{width:a,height:o}});let c=Cb(e,t);c&&r&&($(c,{fontSize:r,angle:rd(e)?void 0:s},!1),bb(e,t,n,!0))}r.triggerUpdate()}},kE=(e,t,n,r,i,a)=>{if(t.length===1&&H(t[0])&&(t[0].startBinding||t[0].endBinding))return;let o=t.filter(e=>{if(H(e)&&e.startBinding&&e.endBinding){let n=t.find(t=>t.id===e.startBinding?.elementId),r=t.find(t=>t.id===e.endBinding?.elementId);return n&&r}return!0}),s=new Set(o),c=o.filter(e=>ed(e)).map(e=>e.id);if(c.length>0)for(let e of r.getNonDeletedElements())e.frameId!==null&&c.includes(e.frameId)&&s.add(e);let l=AE(av(Array.from(s).map(t=>e.originalElements.get(t.id)??t)),n,i,a);s.forEach(t=>{if(jE(e,t,l),!V(t)){let n=Cb(t,r.getNonDeletedElementsMap());n&&jE(e,n,l),Bv(t,r.getElementsMapIncludingDeleted(),{simultaneouslyUpdated:Array.from(s)})}})},AE=(e,t,n,r)=>{let[i,a]=e,o=i+t.x+n.x,s=a+t.y+n.y;if(n.x===0||n.y===0){let[e,c]=ub(i+t.x,a+t.y,r);n.x===0&&(o=e),n.y===0&&(s=c)}return{x:o-i,y:s-a}},jE=(e,t,n)=>{let r=e.originalElements.get(t.id)??t;$(t,{x:r.x+n.x,y:r.y+n.y})},ME=(e,t,n)=>{let[r,i]=av(e);return[t-r,n-i]},NE=({newElement:e,elementType:t,originX:n,originY:r,x:i,y:a,width:o,height:s,shouldMaintainAspectRatio:c,shouldResizeFromCenter:l,zoom:u,widthAspectRatio:d=null,originOffset:f=null,informMutation:p=!0})=>{c&&e.type!==`selection`&&(d?s=o/d:(Math.abs(a-r)>Math.abs(i-n)?{width:o,height:s}=qT(t,s,i<n?-o:o):{width:o,height:s}=qT(t,o,a<r?-s:s),s<0&&(s=-s)));let m=i<n?n-o:n,h=a<r?r-s:r;l&&(o+=o,s+=s,m=n-o/2,h=r-s/2);let g=null;if(B(e)){s=e.height;let t=Sd(Gl({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);o=Math.max(o,t),Math.abs(i-n)>xs/u&&(g={autoResize:!1}),h=r,l&&(m=n-o/2)}if(o!==0&&s!==0){let t=null;Ju(e)&&(t={initialWidth:o,initialHeight:s}),$(e,{x:m+(f?.x??0),y:h+(f?.y??0),width:o,height:s,...g,...t},p)}},PE=(e,t)=>!!(!e.viewModeEnabled&&e.openDialog?.name!==`elementLinkSelector`&&(e.activeTool.type!==`custom`&&(e.editingTextElement||e.activeTool.type!==`selection`&&e.activeTool.type!==`eraser`&&e.activeTool.type!==`hand`&&e.activeTool.type!==`laser`)||NT(t,e).length)),FE=e=>{let t=5381;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t=(t<<5)+t+r}return t>>>0},IE=e=>e.filter(e=>!e.isDeleted&&!WT(e)),LE=e=>e.filter(e=>!e.isDeleted),RE=e=>!e.isDeleted,zE=e=>LE(e).map(e=>id(e.type)?{...e,lastCommittedPoint:null}:e),BE=e=>zE(e),VE=e=>zE(e),HE=async e=>{let t;if(e.type===M.png)try{return await(await i(async()=>{let{decodePngMetadata:e}=await import(`./image-GAAHSSAO-CI-0hUck.js`);return{decodePngMetadata:e}},__vite__mapDeps([5,1,2]))).decodePngMetadata(e)}catch(e){throw e.message===`INVALID`?new oh(`Image doesn't contain scene`,`IMAGE_NOT_CONTAINS_SCENE_DATA`):new oh(`Error: cannot restore image`)}if(t=`text`in Blob?await e.text():await new Promise(t=>{let n=new FileReader;n.readAsText(e,`utf8`),n.onloadend=()=>{n.readyState===FileReader.DONE&&t(n.result)}}),e.type===M.svg)try{return oC({svg:t})}catch(e){throw e.message===`INVALID`?new oh(`Image doesn't contain scene`,`IMAGE_NOT_CONTAINS_SCENE_DATA`):new oh(`Error: cannot restore image`)}return t},UE=e=>e&&e.name.match(/\.(json|excalidraw|png|svg)$/)?.[1]||null,WE=e=>e===`png`||e===`svg`,GE=e=>{let t=UE(e);return t===`png`||t===`svg`},KE=e=>!!e&&Object.values(Gs).includes(e),qE=e=>{let{type:t}=e||{};return KE(t)},JE=async(e,t,n,r)=>{let i=await HE(e),a;try{try{a=JSON.parse(i)}catch(t){throw qE(e)?new oh(`Image doesn't contain scene`,`IMAGE_NOT_CONTAINS_SCENE_DATA`):t}if(SS(a))return{type:M.excalidraw,data:QC({elements:VE(a.elements||[]),appState:{theme:t?.theme,fileHandle:r||e.handle||null,...Fc(a.appState||{}),...t?yy(a.elements||[],t):{}},files:a.files},t,n,{repairBindings:!0,refreshDimensions:!1})};if(CS(a))return{type:M.excalidrawlib,data:a};throw Error(`Error: invalid file`)}catch(e){throw e instanceof oh?e:Error(`Error: invalid file`)}},YE=async(e,t,n,r)=>{let i=await JE(e,t,n,r);if(i.type!==M.excalidraw)throw Error(`Error: invalid file`);return i.data},XE=(e,t=`unpublished`)=>{let n=JSON.parse(e);if(!CS(n))throw Error(`Invalid library`);return ew(n.libraryItems||n.library,t)},ZE=async(e,t=`unpublished`)=>XE(await HE(e),t),QE=async e=>new Promise(async(t,n)=>{try{Du(e)&&(e=await e),e.toBlob(e=>{if(!e)return n(new ih(`Error: Canvas too big`,`CANVAS_POSSIBLY_TOO_BIG`));t(e)})}catch(e){n(e)}}),$E=async e=>{try{let t=await window.crypto.subtle.digest(`SHA-1`,await fD(e));return hu(new Uint8Array(t))}catch(e){return console.error(e),Mi(40)}},eD=async e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let e=r.result;t(e)},r.onerror=e=>n(e),r.readAsDataURL(e)}),tD=(e,t)=>`data:${t};base64,${gD(pD(e),!0)}`,nD=(e,t=``)=>{let n=e.indexOf(`,`),r=atob(e.slice(n+1)),i=e.slice(0,n).split(`:`)[1].split(`;`)[0],a=new ArrayBuffer(r.length),o=new Uint8Array(a);for(let e=0;e<r.length;e++)o[e]=r.charCodeAt(e);return new File([a],t,{type:i})},rD=e=>_D(e.slice(e.indexOf(`,`)+1)),iD=async(t,n)=>{if(t.type===M.svg)return t;let[r,a]=await Promise.all([i(()=>import(`./pica-XznpCgP2.js`).then(t=>e(t.default,1)).then(e=>e.default),__vite__mapDeps([6,2])),i(()=>import(`./image-blob-reduce.esm-Dj7YBvMv.js`).then(e=>e.default),[])]),o=a({pica:r({features:[`js`,`wasm`]})});if(n.outputType){let{outputType:e}=n;o._create_blob=function(t){return this.pica.toBlob(t.out_canvas,e,.8).then(e=>(t.out_blob=e,t))}}if(!qE(t))throw Error(`Error: unsupported file type`,{cause:`UNSUPPORTED`});return new File([await o.toBlob(t,{max:n.maxWidthOrHeight,alpha:!0})],t.name,{type:n.outputType||t.type})},aD=(e,t=``)=>new File([new TextEncoder().encode(e)],t,{type:M.svg}),oD=async(e,t=``)=>{let n;try{n=await fetch(e)}catch{throw Error(`Error: failed to fetch image`,{cause:`FETCH_ERROR`})}if(!n.ok)throw Error(`Error: failed to fetch image`,{cause:`FETCH_ERROR`});let r=await n.blob();if(r.type&&qE(r)){let e=t||r.name||``;return new File([r],e,{type:r.type})}throw Error(`Error: unsupported file type`,{cause:`UNSUPPORTED`})},sD=async e=>{let t=e.dataTransfer.files.item(0),n=await cD(e);return{file:t?await dD(t):null,fileHandle:n}},cD=async e=>{if(Yo)try{return await e.dataTransfer.items[0].getAsFileSystemHandle()||null}catch(e){return console.warn(e.name,e.message),null}return null},lD=e=>{let t=null,n=`${[...new Uint8Array(e).slice(0,8)].join(` `)} `,r={png:`137 80 78 71 13 10 26 10 `,jpg:`255 216 255 `,gif:`71 73 70 56 57 97 `};return n===r.png?t=M.png:n.startsWith(r.jpg)?t=M.jpg:n.startsWith(r.gif)&&(t=M.gif),t},uD=(e,t,n)=>new File([e],n||``,{type:t}),dD=async e=>{if(e.type){if(qE(e)){let t=await fD(e),n=lD(t);n&&n!==e.type&&(e=uD(t,n,e.name))}}else if(e?.name?.endsWith(`.excalidrawlib`))e=uD(await fD(e),M.excalidrawlib,e.name);else if(e?.name?.endsWith(`.excalidraw`))e=uD(await fD(e),M.excalidraw,e.name);else{let t=await fD(e),n=lD(t);n&&(e=uD(t,n,e.name))}return e},fD=e=>`arrayBuffer`in e?e.arrayBuffer():new Promise((t,n)=>{let r=new FileReader;r.onload=e=>{if(!e.target?.result)return n(Error(`Couldn't convert blob to ArrayBuffer`));t(e.target.result)},r.readAsArrayBuffer(e)}),pD=e=>{let t=typeof e==`string`?new TextEncoder().encode(e):e instanceof Uint8Array?e:new Uint8Array(e),n=``;for(let e of t)n+=String.fromCharCode(e);return n},mD=e=>{let t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let t=0,r=e.length;t<r;t++)n[t]=e.charCodeAt(t);return t},hD=e=>new TextDecoder(`utf-8`).decode(mD(e)),gD=(e,t=!1)=>t?window.btoa(e):window.btoa(pD(e)),_D=(e,t=!1)=>t?window.atob(e):hD(window.atob(e)),vD=({text:e,compress:t})=>{let n;if(t!==!1)try{n=pD(ki(e))}catch(e){console.error(`encode: cannot deflate`,e)}return{version:`1`,encoding:`bstring`,compressed:!!n,encoded:n||pD(e)}},yD=e=>{let t;switch(e.encoding){case`bstring`:t=e.compressed?e.encoded:hD(e.encoded);break;default:throw Error(`decode: unknown encoding "${e.encoding}"`)}return e.compressed?Ai(new Uint8Array(mD(t)),{to:`string`}):t},bD=async e=>{let t=(0,h.default)(new Uint8Array(await fD(e))).find(e=>e.name===`tEXt`);return t?g.decode(t.data):null},xD=async({blob:e,metadata:t})=>{let n=(0,h.default)(new Uint8Array(await fD(e))),r=g.encode(M.excalidraw,JSON.stringify(vD({text:t,compress:!0})));return n.splice(-1,0,r),new Blob([(0,_.default)(n)],{type:M.png})},SD=async e=>{let t=await bD(e);if(t?.keyword===M.excalidraw)try{let e=JSON.parse(t.text);if(!(`encoded`in e)){if(`type`in e&&e.type===Js.excalidraw)return t.text;throw Error(`FAILED`)}return yD(e)}catch(e){throw console.error(e),Error(`FAILED`)}throw Error(`INVALID`)};export{tu as $,vc as $a,oc as $c,bD as $i,HT as $l,JC as $n,Sc as $o,Gy as $r,lc as $s,js as $t,Jc as A,NE as Aa,Cb as Ac,Pm as Ai,dD as Al,Eg as An,Bx as Ao,Fs as Ar,wd as As,US as At,YE as Au,Ys as B,Vf as Ba,lu as Bc,Bm as Bi,fp as Bl,Qc as Bn,DS as Bo,Au as Br,Gp as Bs,FT as Bt,no as Bu,Tm as C,hx as Ca,Rc as Cc,em as Ci,nu as Cl,_d as Cn,vs as Co,mx as Cr,Fw as Cs,Dp as Ct,vy as Cu,rD as D,Tx as Da,C_ as Dc,eh as Di,Tg as Dl,Sd as Dn,op as Do,OE as Dr,ps as Ds,zf as Dt,Gc as Du,FS as E,Dd as Ea,LS as Ec,sf as Ei,np as El,g_ as En,Zl as Eo,Hf as Er,SD as Es,Ls as Et,Gs as Eu,Bf as F,Op as Fa,Oy as Fc,Rs as Fi,eT as Fl,AS as Fn,ls as Fo,Lf as Fr,Fg as Fs,Zf as Ft,w_ as Fu,Vl as G,rd as Ga,xg as Gc,mT as Gi,uf as Gl,vm as Gn,OT as Go,PT as Gr,px as Gs,Gf as Gt,rc as H,hs as Ha,ay as Hc,Bc as Hi,ou as Hl,rE as Hn,_S as Ho,xb as Hr,B as Hs,Mp as Ht,Mi as Hu,J as I,bb as Ia,cm as Ic,ub as Ii,xw as Il,Ay as In,Wl as Io,q as Ir,Jm as Is,M as It,Up as Iu,Tw as J,WT as Ja,ax as Jc,Ec as Ji,a_ as Jl,Ey as Jn,oE as Jo,kf as Jr,Tc as Js,Us as Jt,Xs as K,Ul as Ka,j_ as Kc,Hp as Ki,Sm as Kl,SE as Kn,kb as Ko,x_ as Kr,Ps as Ks,hb as Kt,yg as L,Xu as La,wS as Lc,ex as Li,Jl as Ll,Od as Ln,V as Lo,Hm as Lr,Um as Ls,Am as Lt,RE as Lu,Iv as M,Ov as Ma,HS as Mc,JT as Mi,Wm as Ml,ym as Mn,Ql as Mo,hC as Mr,Hl as Ms,zp as Mt,os as Mu,Yu as N,iD as Na,mc as Nc,Cd as Ni,I as Nl,cb as Nn,Zm as No,Jg as Nr,QC as Ns,CT as Nt,aS as Nu,xv as O,wc as Oa,Gm as Oc,bg as Oi,yS as Ol,Ig as On,jv as Oo,$s as Or,KT as Os,Lm as Ot,Sf as Ou,Pw as P,yy as Pa,qm as Pc,Ip as Pi,ES as Pl,Cw as Pn,Kp as Po,ad as Pr,NS as Ps,vx as Pt,xx as Pu,xp as Q,um as Qa,Lp as Qc,Im as Qi,Cp as Ql,Hc as Qn,Gv as Qo,ZE as Qr,bc as Qs,jT as Qt,Nm as R,xD as Ra,jb as Rc,Jf as Ri,$c as Rl,Iu as Rn,tp as Ro,ss as Rr,cs as Rs,JE as Rt,Dc as Ru,Uf as S,Cx as Sa,id as Sc,Hg as Si,ds as Sl,Sy as Sn,yb as So,kp as Sr,aT as Ss,S_ as St,xS as Su,Dv as T,Vp as Ta,oh as Tc,lp as Ti,_u as Tl,iE as Tn,ed as To,xu as Tr,Zp as Ts,Du as Tt,wu as Tu,hg as U,wy as Ua,nC as Uc,_b as Ui,fs as Ul,Mf as Un,Rh as Uo,gm as Ur,Rm as Us,qE as Ut,ji as Uu,ah as V,tm as Va,dp as Vc,as as Vi,kT as Vl,ew as Vn,Bg as Vo,$f as Vr,ep as Vs,Kb as Vt,Ni as Vu,bm as W,Nv as Wa,lf as Wc,gx as Wi,iC as Wl,zb as Wn,sm as Wo,eb as Wr,Sw as Ws,__ as Wt,s as Wu,Md as X,Ym as Xa,Mb as Xc,Qf as Xi,k_ as Xl,yp as Xn,cu as Xo,TE as Xr,GT as Xs,DT as Xt,WE as Y,NT as Ya,zS as Yc,uu as Yi,QE as Yl,Pu as Yn,dv as Yo,xm as Yr,Ih as Ys,Xy as Yt,Lu as Z,Ry as Za,wb as Zc,H as Zi,zu as Zl,Cg as Zn,up as Zo,jw as Zr,UT as Zs,TS as Zt,Ap as _,qf as _a,Cs as _c,Af as _i,ap as _l,UE as _n,ZS as _o,ic as _r,Qu as _s,ec as _t,sd as _u,wp as a,_T as aa,Lg as ac,Rb as ai,zw as al,XE as an,mp as ao,tD as ar,fT as as,VS as at,MT as au,Pb as b,zm as ba,Jp as bc,Ob as bi,qp as bl,IS as bn,Xv as bo,by as br,Ix as bs,nD as bt,Hs as bu,If as c,$ as ca,cp as cc,cC as ci,N as cl,Iy as cn,YT as co,Ep as cr,vu as cs,dT as ct,Of as cu,ac as d,Cc as da,ws as dc,Cy as di,Km as dl,Np as dn,Tb as do,Cf as dr,mf as ds,hp as dt,Bs as du,ox as ea,am as ec,Ru as ei,mb as el,Tu as en,PS as eo,jf as er,cf as es,aE as et,Ff as eu,ey as f,uS as fa,oT as fc,xd as fi,nm as fl,b_ as fn,ys as fo,Rf as fr,Xc as fs,ET as ft,hT as fu,gd as g,Sb as ga,Hu as gc,Nb as gi,Xl as gl,km as gn,cT as go,PE as gr,bS as gs,ld as gt,V_ as gu,Nu as h,Pp as ha,Wy as hc,VT as hi,P as hl,Kf as hn,sp as ho,Dm as hr,yT as hs,wm as ht,sg as hu,Ku as i,uc as ia,My as ic,R as ii,_E as il,jm as in,mu as io,h_ as ir,Os as is,dm as it,Qy as iu,iT as j,tc as ja,Bl as jc,ix as ji,Vu as jl,Bb as jn,lT as jo,Tp as jr,cl as js,fx as jt,Vm as ju,Fb as k,Em as ka,Xp as kc,oS as ki,OS as kl,Wf as kn,Ib as ko,eD as kr,wg as ks,sx as kt,X as ku,lg as l,vg as la,$m as lc,ob as li,zl as ll,qb as ln,ff as lo,Ph as lr,gp as ls,Fu as lt,pm as lu,wf as m,Ju as ma,pp as mc,zc as mi,Ty as ml,Bv as mn,eu as mo,Hx as mr,Vs as ms,pf as mt,_p as mu,$E as n,vb as na,Db as nc,Mu as ni,Yf as nl,Qs as nn,sT as no,od as nr,uE as ns,Nf as nt,hm as nu,Kl as o,rx as oa,$p as oc,_m as oi,ud as ol,xc as on,fd as oo,uv as or,Sg as os,lE as ot,Eu as ou,oD as p,Xb as pa,pu as pc,ju as pi,gs as pl,Zs as pn,ky as po,F as pr,pE as ps,LE as pt,bu as pu,lb as q,jy as qa,Fm as qc,Yh as qi,Nw as ql,sb as qn,Fy as qo,Ou as qr,Bp as qs,mm as qt,av as r,Rp as ra,bs as rc,Pf as ri,Yp as rl,Df as rn,cg as ro,kE as rr,Lb as rs,zy as rt,qs as ru,$l as s,Xf as sa,ru as sc,xE as si,Kc as sl,lS as sn,TT as so,pd as sr,Bu as ss,Es as st,Ng as su,Zb as t,BS as ta,gT as tc,Sp as ti,lx as tl,vp as tn,Ts as to,Cm as tr,fm as ts,tx as tt,gb as tu,Om as u,Mm as ua,lm as uc,v_ as ui,RS as ul,nl as un,im as uo,Dw as ur,Zu as us,Gl as ut,XS as uu,m_ as v,j as va,Mc as vc,om as vi,Ky as vl,gc as vn,uT as vo,kv as vr,rf as vs,vv as vt,hf as vu,ME as w,Js as wa,Rl as wc,su as wi,Lc as wl,jp as wn,Dy as wo,md as wr,yd as ws,o_ as wt,$u as wu,qu as x,Sx as xa,Rw as xc,Py as xi,Lw as xl,sD as xn,rm as xo,dd as xr,ug as xs,yv as xt,bT as xu,Ex as y,gS as ya,df as yc,vT as yi,Xm as yl,ny as yn,Qm as yo,aD as yr,Su as ys,y_ as yt,hE as yu,Fp as z,_s as za,ql as zc,GE as zi,fu as zl,bp as zn,Xd as zo,Wp as zr,Ds as zs,yc as zt,Yo as zu};