@chaibuilder/sdk 4.0.0-beta.49 → 4.0.0-beta.51

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 (156) hide show
  1. package/README.md +35 -52
  2. package/dist/{2SSKDMRQ-CjvuNdPo.cjs → 2SSKDMRQ-BSYe_xPq.cjs} +1 -1
  3. package/dist/{2SSKDMRQ-Dvf9zadl.js → 2SSKDMRQ-Dv-C_YAA.js} +3 -3
  4. package/dist/{AP7HFJJL-DYFttFoI.cjs → AP7HFJJL-BJolKJBt.cjs} +1 -1
  5. package/dist/{AP7HFJJL-q4dJdyFs.js → AP7HFJJL-DhdVstVC.js} +1 -1
  6. package/dist/{IconPicker-Bf163F7t.js → IconPicker-BBkl0T8b.js} +13 -13
  7. package/dist/{IconPicker-JWhYq2Gp.cjs → IconPicker-C0WWlb8t.cjs} +1 -1
  8. package/dist/{WDYDFRGG-O9GIrtX0.js → WDYDFRGG-CJs2MxSq.js} +4 -4
  9. package/dist/{WDYDFRGG-BEksfGMC.cjs → WDYDFRGG-DRt6Zg7Q.cjs} +1 -1
  10. package/dist/{actions-registery-BHbZHkE3.cjs → actions-registery-CLL3KrNv.cjs} +2 -2
  11. package/dist/{actions-registery-gJb_wq2F.js → actions-registery-CrGIlqUX.js} +88 -88
  12. package/dist/actions.cjs +1 -1
  13. package/dist/actions.js +2 -2
  14. package/dist/{add-new-language-page-BfUp5Ua2.cjs → add-new-language-page-ByMSfRcN.cjs} +1 -1
  15. package/dist/{add-new-language-page-CRR93tLq.js → add-new-language-page-DtVoDNfI.js} +35 -35
  16. package/dist/{add-new-page-B8NGK6WS.cjs → add-new-page-CnuChfJz.cjs} +1 -1
  17. package/dist/add-new-page-DanzzvYo.js +31 -0
  18. package/dist/{ai-panel-default-lang-BXYQye3N.js → ai-panel-default-lang-BaPz2d_6.js} +35 -35
  19. package/dist/{ai-panel-default-lang-VhgmHFoQ.cjs → ai-panel-default-lang-CoIQSz_Y.cjs} +2 -2
  20. package/dist/{ai-panel-other-lang-DaCf-cq4.js → ai-panel-other-lang--i-5z4e2.js} +22 -22
  21. package/dist/{ai-panel-other-lang-Ds0EXeUC.cjs → ai-panel-other-lang-ChlMVodg.cjs} +1 -1
  22. package/dist/{ai-prompt-input-7iWk72w5.js → ai-prompt-input-BQi0VDJC.js} +77 -77
  23. package/dist/{ai-prompt-input-nZ5_Dm7X.cjs → ai-prompt-input-BT5426AB.cjs} +1 -1
  24. package/dist/{ai-translation-prompt-1OUs1P7n.js → ai-translation-prompt-BN78s33t.js} +8 -8
  25. package/dist/{ai-translation-prompt-B16cK-1Q.cjs → ai-translation-prompt-BQPaekp3.cjs} +1 -1
  26. package/dist/{apply-binding-CBSjMYSk.cjs → apply-binding-Cjh1kqMO.cjs} +1 -1
  27. package/dist/{apply-binding-vAuN-TGV.js → apply-binding-v_W4uR3U.js} +28 -28
  28. package/dist/{plugin-BSjgGgwo.js → chai-theme-helpers-BEf2rwE4.js} +83 -83
  29. package/dist/chai-theme-helpers-q3nwoNht.cjs +22 -0
  30. package/dist/{change-password-modal-D5eXjiYq.cjs → change-password-modal-DHUrrKw7.cjs} +1 -1
  31. package/dist/{change-password-modal-CdvJR1Ln.js → change-password-modal-pEp-nMNb.js} +30 -30
  32. package/dist/{code-display-DdWcOQ_i.js → code-display-BaLKScgW.js} +5 -5
  33. package/dist/{code-display-BR-gij5j.cjs → code-display-i7jb2kmw.cjs} +1 -1
  34. package/dist/{code-editor-CyLjDiEp.js → code-editor-CRoniyP0.js} +12 -12
  35. package/dist/{code-editor-SWbfFj1E.cjs → code-editor-gwFRjQ2_.cjs} +1 -1
  36. package/dist/core.cjs +1 -1
  37. package/dist/core.d.ts +0 -5
  38. package/dist/core.js +49 -49
  39. package/dist/{css-import-modal-Be47CBJn.js → css-import-modal-B3qxX9Iv.js} +14 -14
  40. package/dist/{css-import-modal-Bdwgd05S.cjs → css-import-modal-nAB5FSwn.cjs} +2 -2
  41. package/dist/{delete-page-C99K2qzS.js → delete-page-DbawNFf7.js} +13 -13
  42. package/dist/{delete-page-DLohaU-U.cjs → delete-page-YP1HEAoD.cjs} +1 -1
  43. package/dist/{digital-asset-manager-BZMb6sC7.js → digital-asset-manager-DTD5mf24.js} +388 -357
  44. package/dist/digital-asset-manager-kJnuMqpw.cjs +1 -0
  45. package/dist/{duplicate-page-D5Gtvqdv.cjs → duplicate-page-CxqW_EO7.cjs} +1 -1
  46. package/dist/{duplicate-page-CDc2X0eW.js → duplicate-page-DnRb1y6K.js} +19 -19
  47. package/dist/{dynamic-page-selector-DZHhX008.cjs → dynamic-page-selector-2EqJhUrB.cjs} +1 -1
  48. package/dist/{dynamic-page-selector-DvNBXo6o.js → dynamic-page-selector-D6VLDIN9.js} +17 -17
  49. package/dist/{get-chai-builder-tailwind-config-7CxFxEYL.cjs → get-chai-builder-tailwind-config-DNp8Vhme.cjs} +1 -1
  50. package/dist/{get-chai-builder-tailwind-config-DC4sDOYK.js → get-chai-builder-tailwind-config-k8l5sdcw.js} +3 -3
  51. package/dist/{get-chai-builder-theme-BpuwSLeS.js → get-chai-builder-theme-DLpviqPJ.js} +1 -1
  52. package/dist/get-chai-builder-theme-Du4ARJlw.cjs +1 -0
  53. package/dist/{image-editor-DwhTYkVR.cjs → image-editor-BQcOGsli.cjs} +1 -1
  54. package/dist/{image-editor-BBvvi9Vm.js → image-editor-CMf731xL.js} +15 -15
  55. package/dist/index-BYrRPW_c.cjs +5 -0
  56. package/dist/index-D-r_K4yA.cjs +160 -0
  57. package/dist/{index-OuHV9Ann.js → index-DPV6NiJ-.js} +5894 -6049
  58. package/dist/index-DqzFD1CG.js +4861 -0
  59. package/dist/{mark-as-template-CP_F9ZQ4.js → mark-as-template-D7jqSCXw.js} +28 -28
  60. package/dist/{mark-as-template-B9yLcasI.cjs → mark-as-template-DyB56HzI.cjs} +1 -1
  61. package/dist/{nested-path-selector-content-DmtCI3q9.js → nested-path-selector-content-dwSikrsV.js} +2 -2
  62. package/dist/{nested-path-selector-content-aTdu-o0e.cjs → nested-path-selector-content-g9_Tq_sR.cjs} +1 -1
  63. package/dist/no-language-page-content-BRITuyfN.js +43 -0
  64. package/dist/{no-language-page-content-C-MCdPXt.cjs → no-language-page-content-ZvMNVY-Y.cjs} +1 -1
  65. package/dist/{no-language-page-dialog-D4QIAHnE.cjs → no-language-page-dialog-Cndq8xRP.cjs} +1 -1
  66. package/dist/no-language-page-dialog-D7L9nVb9.js +10 -0
  67. package/dist/page-creator-BAIbU14q.js +652 -0
  68. package/dist/page-creator-qL3-M8g3.cjs +1 -0
  69. package/dist/{page-manager-new-ah6QYar2.cjs → page-manager-new-By3eGO3i.cjs} +1 -1
  70. package/dist/{page-manager-new-ttsrxdW9.js → page-manager-new-YRG89y4f.js} +63 -63
  71. package/dist/page-manager-search-and-filter-BbdgOU9V.cjs +1 -0
  72. package/dist/page-manager-search-and-filter-Cllju4CV.js +184 -0
  73. package/dist/pages.cjs +1 -1
  74. package/dist/pages.d.ts +0 -15
  75. package/dist/pages.js +20 -21
  76. package/dist/{publish-pages-content-KZVMHT6V.js → publish-pages-content-CG5LBUnY.js} +48 -48
  77. package/dist/{publish-pages-content-BrajJUcP.cjs → publish-pages-content-DxMiBxNU.cjs} +1 -1
  78. package/dist/{register-chai-top-bar-DyW9GPzV.cjs → register-chai-top-bar-CCssW5dL.cjs} +1 -1
  79. package/dist/{register-chai-top-bar-D6GjnauV.js → register-chai-top-bar-DWmJ2efT.js} +11 -11
  80. package/dist/render.cjs +1 -1
  81. package/dist/render.js +54 -54
  82. package/dist/{rte-widget-modal-CiTwsXTr.cjs → rte-widget-modal-CsTqFJc_.cjs} +1 -1
  83. package/dist/{rte-widget-modal-IU8JzPuZ.js → rte-widget-modal-DoeTMRtX.js} +2 -2
  84. package/dist/runtime-client.cjs +1 -1
  85. package/dist/runtime-client.js +1 -1
  86. package/dist/runtime.cjs +1 -1
  87. package/dist/runtime.js +1 -1
  88. package/dist/sdk.css +1 -1
  89. package/dist/{selected-block-display-CidmQ-wz.js → selected-block-display-Ck1kkNEi.js} +17 -28
  90. package/dist/{selected-block-display-CAFEOrLV.cjs → selected-block-display-DSow6N4b.cjs} +1 -1
  91. package/dist/seo-panel---mYZmLD.js +559 -0
  92. package/dist/seo-panel-mfX63fua.cjs +1 -0
  93. package/dist/{shared-json-ld-uvMmwCYp.js → shared-json-ld-B3I_RLE2.js} +46 -46
  94. package/dist/{shared-json-ld-CMH-eRUq.cjs → shared-json-ld-CGgwUOlW.cjs} +1 -1
  95. package/dist/{slug-input-DLWTMTsO.js → slug-input-DQ4t3-Tt.js} +5 -5
  96. package/dist/{slug-input-CiHC5l3r.cjs → slug-input-DaNbl597.cjs} +1 -1
  97. package/dist/supabase-actions.cjs +1 -1
  98. package/dist/supabase-actions.js +2 -2
  99. package/dist/types.d.ts +0 -96
  100. package/dist/{unmark-as-template-F7TdgWjI.cjs → unmark-as-template-CZ65AE4v.cjs} +1 -1
  101. package/dist/{unmark-as-template-C5ovsEBP.js → unmark-as-template-DvmoTbVu.js} +11 -11
  102. package/dist/unpublish-page-3--vO5b0.js +28 -0
  103. package/dist/{unpublish-page-CUr8Xub6.cjs → unpublish-page-B46TiWlU.cjs} +1 -1
  104. package/dist/{unpublished-partials-modal-BhNAub_z.js → unpublished-partials-modal-DVMz3q83.js} +18 -15
  105. package/dist/{unpublished-partials-modal-Cv5R9-hi.cjs → unpublished-partials-modal-U5lKBOSR.cjs} +1 -1
  106. package/dist/utils.cjs +1 -1
  107. package/dist/utils.js +2 -2
  108. package/dist/web-blocks.cjs +1 -1
  109. package/dist/web-blocks.js +2 -2
  110. package/dist/{web-preview-D9pXonAv.js → web-preview-D5o5XQo0.js} +2 -2
  111. package/dist/{web-preview-CuMYekVJ.cjs → web-preview-Da3RhcjQ.cjs} +1 -1
  112. package/package.json +1 -1
  113. package/dist/active-in-another-tab-B4Ur0JP7.js +0 -35
  114. package/dist/active-in-another-tab-BPdx4lWh.cjs +0 -1
  115. package/dist/add-new-page-Ppy5-y5j.js +0 -31
  116. package/dist/continue-editing-in-this-client-BrSvK-Ay.js +0 -25
  117. package/dist/continue-editing-in-this-client-Cmi-GkYZ.cjs +0 -1
  118. package/dist/design-token-usage-D1lWCJ3L.js +0 -114
  119. package/dist/design-token-usage-eY2wQ0l3.cjs +0 -1
  120. package/dist/digital-asset-manager-Z5aJxkq0.cjs +0 -1
  121. package/dist/get-chai-builder-theme-B5RkBTsB.cjs +0 -1
  122. package/dist/image-compression-DPFITwOL.js +0 -37
  123. package/dist/image-compression-UaU7Bwqe.cjs +0 -1
  124. package/dist/index-BVwFJWDq.cjs +0 -5
  125. package/dist/index-DCJDQs1a.cjs +0 -160
  126. package/dist/index-LBTm1Jmk.js +0 -5199
  127. package/dist/json-diff-viewer-Cb1CmRqP.cjs +0 -8
  128. package/dist/json-diff-viewer-DG6qMOBS.js +0 -261
  129. package/dist/lang-panel-B3USOxGq.js +0 -216
  130. package/dist/lang-panel-DxoJ0v4y.cjs +0 -1
  131. package/dist/manage-design-tokens-6YGIctip.js +0 -446
  132. package/dist/manage-design-tokens-modal-BSSCXH8Y.cjs +0 -1
  133. package/dist/manage-design-tokens-modal-CzsnN49F.js +0 -161
  134. package/dist/manage-design-tokens-udLBvkHA.cjs +0 -1
  135. package/dist/no-language-page-content-D8t5dfgh.js +0 -43
  136. package/dist/no-language-page-dialog-C_fHI2zI.js +0 -10
  137. package/dist/page-creator-Cz_ah-qE.cjs +0 -1
  138. package/dist/page-creator-DKEkuGCO.js +0 -796
  139. package/dist/page-lock-CwZKJ4IE.js +0 -30
  140. package/dist/page-lock-DdCvtA-I.cjs +0 -1
  141. package/dist/page-locked-dialog-CrTDBoC4.cjs +0 -1
  142. package/dist/page-locked-dialog-DqLlooUz.js +0 -136
  143. package/dist/page-manager-search-and-filter-D7AupT6_.cjs +0 -1
  144. package/dist/page-manager-search-and-filter-bsqZ6wnI.js +0 -210
  145. package/dist/page-revisions-content-B6hsIla7.cjs +0 -1
  146. package/dist/page-revisions-content-C5O8_Fms.js +0 -459
  147. package/dist/plugin-DHpuZZXz.cjs +0 -22
  148. package/dist/save-to-lib-DMnv7ENo.js +0 -429
  149. package/dist/save-to-lib-Dc700Aop.cjs +0 -1
  150. package/dist/seo-panel-Br8gxDxu.js +0 -789
  151. package/dist/seo-panel-CMY-adM-.cjs +0 -2
  152. package/dist/take-over-request-IRLgF1dG.cjs +0 -1
  153. package/dist/take-over-request-KdR1_h_K.js +0 -64
  154. package/dist/translation-warning-modal-CLZ9tC1F.cjs +0 -1
  155. package/dist/translation-warning-modal-CzNt6LDO.js +0 -27
  156. package/dist/unpublish-page-0fR1o0b7.js +0 -28
@@ -0,0 +1,160 @@
1
+ "use strict";var zc=Object.defineProperty;var Hc=(t,e,n)=>e in t?zc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var kt=(t,e,n)=>Hc(t,typeof e!="symbol"?e+"":e,n);const i=require("react/jsx-runtime"),d=require("lodash-es"),g=require("react"),Nt=require("react-error-boundary"),T=require("./register-chai-top-bar-CCssW5dL.cjs"),Vc=require("react-wrap-balancer"),Us=require("@floating-ui/dom"),zo=require("@floating-ui/react-dom"),w=require("@radix-ui/react-icons"),xe=require("@react-hookz/web"),z=require("react-i18next"),Wc=require("@radix-ui/react-dropdown-menu"),K=require("./core-czmLeR0h.cjs"),Gc=require("@rjsf/core"),Uc=require("@rjsf/validator-ajv8"),S=require("jotai"),U=require("./STRINGS-FNnfjF5H.cjs"),Ho=require("@rjsf/utils"),He=require("jotai/utils"),ce=require("./common-functions-B3a4xKt_.cjs"),qc=require("tree-model"),Kc=require("undo-manager"),Yc=require("@radix-ui/react-dialog"),ne=require("./apply-binding-Cjh1kqMO.cjs"),Sr=require("class-variance-authority"),Jc=require("@radix-ui/react-tooltip"),ft=require("i18next"),Me=require("cmdk"),Xc=require("@radix-ui/react-popover"),ss=require("@tiptap/react"),Zc=require("@tiptap/extension-text-style"),Qc=require("@tiptap/extension-highlight"),ed=require("@tiptap/extension-link"),td=require("@tiptap/extension-placeholder"),nd=require("@tiptap/extension-text-align"),sd=require("@tiptap/extension-underline"),rd=require("@tiptap/starter-kit"),Li=require("clsx"),Di=require("tailwind-merge"),od=require("react-colorful"),Xe=require("./chai-theme-helpers-q3nwoNht.cjs"),cr=require("react-dom"),id=require("@radix-ui/react-switch"),ad=require("@radix-ui/react-accordion"),Mi=require("fuse.js"),ld=require("@radix-ui/react-hover-card"),cd=require("react-autosuggest"),le=require("sonner"),dd=require("@radix-ui/react-scroll-area"),ud=require("@radix-ui/react-tabs"),pd=require("@radix-ui/react-label"),fd=require("@radix-ui/react-select"),hd=require("react-arborist"),md=require("@radix-ui/react-alert-dialog"),gd=require("@radix-ui/react-separator"),xd=require("@radix-ui/react-slider"),Nr=require("./fonts-D5fTqvSS.cjs"),Vo=require("himalaya");require("nanoid");require("@mhsdesign/jit-browser-tailwindcss");const bd=require("@tailwindcss/aspect-ratio"),yd=require("@tailwindcss/container-queries"),kd=require("@tailwindcss/forms"),vd=require("@tailwindcss/typography"),Vn=require("framer-motion"),Oi=require("lucide-react"),wd=require("./get-chai-builder-tailwind-config-DNp8Vhme.cjs"),rt=require("react-hotkeys-hook");function Re(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const O=Re(g),ke=Re(Wc),pe=Re(Yc),Yt=Re(Jc),yn=Re(Xc),dr=Re(id),Tt=Re(ad),ks=Re(ld),Et=Re(dd),Lt=Re(ud),$i=Re(pd),ye=Re(fd),Pe=Re(md),Fi=Re(gd),cn=Re(xd);function Jt({className:t,...e}){return i.jsx("div",{className:T.cn("animate-pulse rounded-md bg-primary/10",t),...e})}const Er=({className:t="h-full w-full",onClick:e=d.noop})=>i.jsx("svg",{className:t,viewBox:"0 0 256 256",fill:"currentColor",onClick:e,children:i.jsx("path",{d:"m198.39 128.986-52.16-19.216-19.216-52.16a16 16 0 0 0-30.028 0L77.77 109.77l-52.16 19.216a16 16 0 0 0 0 30.028l52.16 19.216 19.216 52.16a16 16 0 0 0 30.028 0l19.216-52.16 52.16-19.216a16 16 0 0 0 0-30.028m-57.69 34.23a15.97 15.97 0 0 0-9.483 9.483l-19.22 52.152-19.214-52.15a15.97 15.97 0 0 0-9.482-9.484l-52.152-19.22 52.15-19.214a15.97 15.97 0 0 0 9.484-9.482l19.22-52.152 19.214 52.15a15.97 15.97 0 0 0 9.482 9.484l52.152 19.22ZM144 40a8 8 0 0 1 8-8h16V16a8 8 0 0 1 16 0v16h16a8 8 0 0 1 0 16h-16v16a8 8 0 0 1-16 0V48h-16a8 8 0 0 1-8-8m104 48a8 8 0 0 1-8 8h-8v8a8 8 0 0 1-16 0v-8h-8a8 8 0 0 1 0-16h8v-8a8 8 0 0 1 16 0v8h8a8 8 0 0 1 8 8"})}),gt=ke.Root,xt=ke.Trigger,Cd=O.forwardRef(({className:t,inset:e,children:n,...s},o)=>i.jsxs(ke.SubTrigger,{ref:o,className:T.cn("flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",e&&"pl-8",t),...s,children:[n,i.jsx(w.ChevronRightIcon,{className:"ml-auto h-4 w-4"})]}));Cd.displayName=ke.SubTrigger.displayName;const jd=O.forwardRef(({className:t,...e},n)=>i.jsx(ke.SubContent,{ref:n,className:T.cn("z-50 min-w-[8rem] origin-[--radix-dropdown-menu-content-transform-origin] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...e}));jd.displayName=ke.SubContent.displayName;const Ze=O.forwardRef(({className:t,sideOffset:e=4,...n},s)=>i.jsx(ke.Portal,{children:i.jsx(ke.Content,{ref:s,sideOffset:e,className:T.cn("z-50 max-h-[var(--radix-dropdown-menu-content-available-height)] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","origin-[--radix-dropdown-menu-content-transform-origin] data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...n})}));Ze.displayName=ke.Content.displayName;const ge=O.forwardRef(({className:t,inset:e,...n},s)=>i.jsx(ke.Item,{ref:s,className:T.cn("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",e&&"pl-8",t),...n}));ge.displayName=ke.Item.displayName;const zi=O.forwardRef(({className:t,children:e,checked:n,...s},o)=>i.jsxs(ke.CheckboxItem,{ref:o,className:T.cn("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),checked:n,...s,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(ke.ItemIndicator,{children:i.jsx(w.CheckIcon,{className:"h-4 w-4"})})}),e]}));zi.displayName=ke.CheckboxItem.displayName;const Sd=O.forwardRef(({className:t,children:e,...n},s)=>i.jsxs(ke.RadioItem,{ref:s,className:T.cn("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...n,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(ke.ItemIndicator,{children:i.jsx(w.CircleIcon,{className:"h-2 w-2 fill-current"})})}),e]}));Sd.displayName=ke.RadioItem.displayName;const Ar=O.forwardRef(({className:t,inset:e,...n},s)=>i.jsx(ke.Label,{ref:s,className:T.cn("px-2 py-1.5 text-sm font-semibold",e&&"pl-8",t),...n}));Ar.displayName=ke.Label.displayName;const _r=O.forwardRef(({className:t,...e},n)=>i.jsx(ke.Separator,{ref:n,className:T.cn("-mx-1 my-1 h-px bg-muted",t),...e}));_r.displayName=ke.Separator.displayName;const Y={OPEN_ADD_BLOCK:"OPEN_ADD_BLOCK",CLOSE_ADD_BLOCK:"CLOSE_ADD_BLOCK",GOTO_BLOCK_SETTINGS:"GOTO_BLOCK_SETTINGS",OPEN_AI_PANEL:"OPEN_AI_PANEL",CLEAR_CANVAS_SELECTION:"CLEAR_CANVAS_SELECTION",CANVAS_BLOCK_SELECTED:"CANVAS_BLOCK_SELECTED",CANVAS_BLOCK_STYLE_SELECTED:"CANVAS_BLOCK_STYLE_SELECTED",OPEN_EXPORT_CODE:"OPEN_EXPORT_CODE"},Qe=(t,e)=>{if(!t)return!0;const n=K.getRegisteredChaiBlock(t);return n&&n.canAcceptBlock?n.canAcceptBlock(e):!1},rs=t=>{const e=K.getRegisteredChaiBlock(t);return e?d.has(e,"canAcceptBlock"):!1},Nd=(t,e)=>{const n=K.getRegisteredChaiBlock(e);return n&&n.canBeNested?n.canBeNested(t):!0},Ir=t=>{const e=K.getRegisteredChaiBlock(t);return e&&e.canDuplicate?e.canDuplicate():!0},Tr=t=>{const e=K.getRegisteredChaiBlock(t);return e&&e.canDelete?e.canDelete():!0};class Ed{constructor(){kt(this,"subscribers",new Map)}subscribe(e,n){return this.subscribers.has(e)||this.subscribers.set(e,new Set),this.subscribers.get(e).add(n),()=>{const s=this.subscribers.get(e);s&&(s.delete(n),s.size===0&&this.subscribers.delete(e))}}publish(e,n){const s=this.subscribers.get(e);s&&s.forEach(o=>o(n))}}const oe=new Ed;function Hi(t,e,n){const s=d.filter(t,r=>r._parent===e),o=[];for(let r=0;r<s.length;r++)if(d.filter(t,{_parent:s[r]._id}).length>0){const a=ce.generateUUID();o.push({...s[r],oldId:s[r]._id,_id:a,_parent:n}),o.push(d.flatten(Hi(t,s[r]._id,a)))}else o.push({...s[r],oldId:s[r]._id,_id:ce.generateUUID(),_parent:n});return d.flatten(o)}function Br(t){const e={};t.forEach(s=>{e[s._id]={...s,children:[]}});const n=[];return t.forEach(s=>{if(s._parent){const o=e[s._parent];o&&o.children.push(e[s._id])}else n.push(e[s._id])}),n}const ur=(t,e,n=null)=>{let s=d.find(t,{_id:e});s={...s,oldId:s._id,_id:ce.generateUUID()},n!==(s==null?void 0:s._parent)&&(s={...s,_parent:n});const o=[s];return d.filter(t,{_parent:e}).length>0&&o.push(d.flatten(Hi(t,e,s._id))),d.flatten(o)},Ne=S.atom([]);Ne.debugLabel="presentBlocksAtom";const Vi=S.atom(t=>{const e=t(Ne);return Br([...e])});Vi.debugLabel="treeDSBlocks";const Nn=He.splitAtom(Ne);Nn.debugLabel="pageBlocksAtomsAtom";const Ad=S.atom("");Ad.debugLabel="builderActivePageAtom";const _d=S.atom(-1);_d.debugLabel="destinationDropIndexAtom";const Wi=S.atom([]);Wi.debugLabel="buildingBlocksAtom";const Id=S.atom(t=>{const e=t(Wi);return d.filter(e,n=>d.has(n,"blockId"))});Id.debugLabel="globalBlocksAtom";const Zt=S.atom([]);Zt.debugLabel="structureErrorsAtom";const Rr=S.atom(!0);Rr.debugLabel="structureValidationValidAtom";const Pr=S.atom(!1);Pr.debugLabel="hasStructureErrorsAtom";const Lr=S.atom(!1);Lr.debugLabel="hasStructureWarningsAtom";const Gi=S.atom(t=>t(Zt).filter(n=>n.severity==="error").length);Gi.debugLabel="structureErrorCountAtom";const Ui=S.atom(t=>t(Zt).filter(n=>n.severity==="warning").length);Ui.debugLabel="structureWarningCountAtom";const qi=S.atom(t=>{const e=t(Zt),n={};return e.forEach(s=>{s.blockId&&(n[s.blockId]||(n[s.blockId]=[]),n[s.blockId].push(s))}),n});qi.debugLabel="structureErrorsByBlockAtom";const $e=S.getDefaultStore(),Td=()=>$e.get(Ne),$=(t,e)=>{const n=S.useAtomValue(Fr);return g.useMemo(()=>d.get(n,t,e),[n,t,e])},Ki=S.atom("");Ki.debugLabel="selectedLanguageAtom";const Te=()=>{const t=$("languages",[]),e=$("fallbackLang","en"),[n,s]=S.useAtom(Ki),o=r=>{s(e===r?"":r)};return{languages:t==null?void 0:t.filter(r=>r!==e),fallbackLang:e,selectedLang:n,setSelectedLang:o}},vs=S.atom([]);vs.debugLabel="selectedBlockIdsAtom";const Dr=S.atom(t=>{const e=t(Ne),n=t(vs);return d.map(d.filter(e,({_id:s})=>d.includes(n,s)),s=>({...s}))});Dr.debugLabel="selectedBlocksAtom";const ws=S.atom(t=>{const e=t(Dr);if(e.length!==0&&e.length===1)return e[0]});ws.debugLabel="selectedBlockAtom";const J=()=>S.useAtomValue(ws),Bd=t=>d.get(t,"_parent",null),Rd=S.atom(t=>{const e=t(Dr),n=d.map(e,Bd);return d.filter(t(Ne),s=>d.includes(n,s._id))});Rd.debugLabel="selectedBlocksParentsAtom";const Yi=S.atom(()=>!1);Yi.debugLabel="selectedBlockFlexChildAtom";const Ji=S.atom(()=>!1);Ji.debugLabel="selectedBlockGridChildAtom";const Mr=S.atom("");Mr.debugLabel="styleStateAtom";const Xi=He.atomWithStorage("styleBreakpoint","xs");Xi.debugLabel="styleBreakpointAtom";const Pd=()=>({flexChild:S.useAtomValue(Yi),gridChild:S.useAtomValue(Ji)}),Ld=S.atom(t=>{const e=t(ws),n=t(Ne);let s=e;const o=[e];do{const r=n.find(({_id:a})=>a===(s==null?void 0:s._parent));s=r,r&&o.push(r)}while(s!=null&&s._parent);return o}),Dd=()=>d.compact(S.useAtomValue(Ld)),q=()=>{const[t,e]=S.useAtom(vs),n=g.useCallback(s=>{e(o=>d.includes(o,s)?d.without(o,s):[...o,s])},[e]);return[t,e,n]},Zi=(t,e,n)=>{const s=K.getRegisteredChaiBlock(d.get(n,"_type",""));if(!s)return t;const o={...t};return d.forEach(d.keys(t),r=>{if(d.includes(d.get(s,"i18nProps",[]),r)&&!d.isEmpty(e)){const a=`${r}-${e}`;d.set(o,a,t[r]),d.unset(o,r)}}),o},Ke=()=>{const{updateBlocks:t}=Ee(),{selectedLang:e}=Te(),n=J();return g.useCallback((s,o,r)=>{const a=Zi(o,e,n);t(s,a,r)},[e,n,t])},Md=()=>{const{updateMultipleBlocksProps:t}=Ee();return g.useCallback(e=>{t(e)},[t])},Od=()=>{const{updateBlocksRuntime:t}=Ee();return g.useCallback(async(e,n,s=30)=>{const o=d.keys(d.omit(n,["_id"]));for(const r of o){const a=n[r];if(d.isString(a)){const l=d.chunk(a.split(""),12);let c="";t([e],{[r]:""});for(let u=0;u<l.length;u++)c+=l[u].join(""),t([e],{[r]:c}),await new Promise(p=>setTimeout(p,s))}}},[t])},Qi=()=>{const{updateMultipleBlocksProps:t}=Ee(),e=Od();return g.useCallback(async n=>{for(const s of n)await e(s._id,s);t(n)},[e,t])},Or=()=>{const{updateBlocksRuntime:t}=Ee(),{selectedLang:e}=Te(),n=J();return g.useCallback((s,o)=>{const r=Zi(o,e,n);t(s,r)},[e,n,t])},$r=S.atom({});$r.debugLabel="blockRepeaterDataAtom";const ea=()=>S.useAtom($r),$d=(t,e,n,s)=>{const[o,r]=g.useState({status:"idle",props:{},error:void 0}),a=Or(),l=$("getBlockAsyncProps",async m=>({})),c=S.useSetAtom($r),u=JSON.stringify([t==null?void 0:t._id,...d.values(d.pick(t,n??[]))]),p=(t==null?void 0:t._type)==="Repeater"&&d.startsWith(t.repeaterItems,`{{${U.COLLECTION_PREFIX}`),f=(t==null?void 0:t._type)!=="Repeater"&&e==="live";return g.useEffect(()=>{if(e==="mock"){if(d.isFunction(s)){r(x=>({...x,status:"loading",props:{}}));const m=s({block:t});if(!Ho.isObject(m))throw new Error("mockDataProvider should return an object");r(x=>({...x,status:"loaded",props:m}))}return}e==="live"&&(!p&&!f||(r(m=>({...m,status:"loading",props:{}})),l({block:t}).then((m={})=>{p?(c(x=>({...x,[t._id]:{status:"loaded",props:d.get(m,"items",[]),repeaterItems:t.repeaterItems}})),r(x=>({...x,status:"loaded",props:{totalItems:d.get(m,"totalItems")}})),a([t._id],{totalItems:d.get(m,"totalItems")})):r(x=>({...x,status:"loaded",props:Ho.isObject(m)?m:{}}))}).catch(m=>{p?(c(x=>({...x,[t._id]:{status:"error",error:m,props:[]}})),r(x=>({...x,status:"error",error:m,props:{}}))):r(x=>({...x,status:"error",error:m,props:{}}))})))},[t==null?void 0:t._id,u,p,f,s,e]),{$loading:d.get(o,"status")==="loading",...t?d.get(o,"props",{}):{}}},Fr=S.atom(null);Fr.debugLabel="chaiBuilderPropsAtom";const Fd=S.atom({});Fd.debugLabel="chaiExternalDataAtom";const zd=S.atom({});zd.debugLabel="chaiRjsfFieldsAtom";const Hd=S.atom({});Hd.debugLabel="chaiRjsfWidgetsAtom";const Vd=S.atom({});Vd.debugLabel="chaiRjsfTemplatesAtom";const zr=S.atom({});zr.debugLabel="chaiPageExternalDataAtom";const Qt=S.atom({});Qt.debugLabel="chaiDesignTokensAtom";const Dt=()=>{const[t]=ea(),e=g.useMemo(()=>{const s={};return Object.entries(t).forEach(([o,r])=>{r.status==="loaded"&&r.repeaterItems&&(s[r.repeaterItems.replace("}}",`/${o}`).replace("{{","")]=r.props)}),s},[t]);return{...S.useAtomValue(zr),...e}},Cs=S.atom(0),ta=S.atom({isOpen:!1,blockId:null}),Wd=[{name:"no-nested-div-in-p",description:"Prevents div elements from being nested inside paragraph elements",validate:(t,e)=>{const n=[],s=(o,r=!1)=>{o.forEach(a=>{const l=a._type==="Paragraph";a._type==="Box"&&r&&n.push({id:`div-in-paragraph-${a._id}`,message:"Box (div) cannot be nested inside Paragraph elements",severity:"error",blockId:a._id}),a.children&&a.children.length>0&&s(a.children,l)})};return s(e),n}},{name:"no-interactive-nesting",description:"Prevents interactive elements (links, buttons with href) from being nested inside other interactive elements",validate:(t,e)=>{const n=[],s=(r,a=!1,l=[])=>{r.forEach(c=>{const u=[...l,c._id],p=c._type==="Link",f=c._type==="Button"&&c.link&&c.link.href&&c.link.href.trim()!=="",h=p||f;if(h&&a){const m=p?"Link":"Button with href";n.push({id:`nested-interactive-tree-${c._id}`,message:`${m} cannot be nested inside another interactive element (link or button with href)`,severity:"error",blockId:c._id})}c.children&&c.children.length>0&&s(c.children,h,u)})},o=r=>{r.filter(l=>l._type==="Link"||l._type==="Button"&&l.link&&l.link.href&&l.link.href.trim()!=="").forEach(l=>{if(l._parent){const c=r.find(h=>h._id===l._parent),u=c&&c._type==="Link",p=c&&c._type==="Button"&&c.link&&c.link.href&&c.link.href.trim()!=="";if(u||p){const h=l._type==="Link"?"Link":"Button with href",m=u?"Link":"Button with href";n.push({id:`nested-interactive-parent-${l._id}`,message:`${h} cannot be nested inside ${m}`,severity:"error",blockId:l._id})}let f=c;for(;f&&f._parent;){const h=r.find(m=>m._id===f._parent);if(h){const m=h._type==="Link",x=h._type==="Button"&&h.link&&h.link.href&&h.link.href.trim()!=="";if(m||x){const b=l._type==="Link"?"Link":"Button with href",y=m?"Link":"Button with href";n.push({id:`nested-interactive-ancestor-${l._id}`,message:`${b} cannot be nested inside ${y}`,severity:"error",blockId:l._id});break}}f=h}}})};return s(e),o(t),n}},{name:"listitem-in-list",description:"Ensures ListItems are only inside List containers",validate:(t,e)=>{const n=[],s=(o,r=null)=>{o.forEach(a=>{a._type==="ListItem"&&r!=="List"&&n.push({id:`listitem-outside-list-${a._id}`,message:"List Item must be inside a List container",severity:"error",blockId:a._id}),a.children&&a.children.length>0&&s(a.children,a._type)})};return s(e),n}},{name:"table-cell-structure",description:"Validates proper table hierarchy (TableCell -> TableRow -> TableHead/Body -> Table)",validate:(t,e)=>{const n=[],s=(o,r=[])=>{o.forEach(a=>{const l=[...r,a._type];if(a._type==="TableCell"){const c=l.includes("TableRow"),u=l.includes("TableHead")||l.includes("TableBody"),p=l.includes("Table");(!c||!u||!p)&&n.push({id:`table-cell-structure-${a._id}`,message:"Table Cell must be inside a Table Row, which must be inside Table Head/Body, which must be inside a Table",severity:"error",blockId:a._id})}a._type==="TableRow"&&!l.slice(0,-1).includes("Table")&&n.push({id:`table-row-outside-table-${a._id}`,message:"Table Row must be inside a Table (Table Head or Table Body)",severity:"error",blockId:a._id}),(a._type==="TableHead"||a._type==="TableBody")&&!l.slice(0,-1).includes("Table")&&n.push({id:`table-section-outside-table-${a._id}`,message:"Table Head/Body must be inside a Table",severity:"error",blockId:a._id}),a.children&&a.children.length>0&&s(a.children,l)})};return s(e),n}},{name:"no-nested-buttons",description:"Prevents buttons from being nested inside other buttons",validate:(t,e)=>{const n=[],s=(o,r=!1)=>{o.forEach(a=>{const l=a._type==="Button";l&&r&&n.push({id:`nested-button-${a._id}`,message:"Button cannot be nested inside another button",severity:"error",blockId:a._id}),a.children&&a.children.length>0&&s(a.children,l)})};return s(e),n}},{name:"no-nested-paragraphs",description:"Prevents paragraph elements from being nested inside other paragraph elements at any level",validate:(t,e)=>{const n=[],s=(o,r=[])=>{o.forEach(a=>{const l=a._type==="Paragraph";if(l&&r.length>0&&n.push({id:`nested-paragraph-${a._id}`,message:"Paragraph cannot be nested inside another paragraph",severity:"error",blockId:a._id}),a.children&&a.children.length>0){const c=l?[...r,a._id]:r;s(a.children,c)}})};return s(e),n}},{name:"heading-structure",description:"Checks for proper heading hierarchy and warns about skipped levels",validate:(t,e)=>{const n=[],s=[],o=(r,a=[])=>{r.forEach(l=>{if(l._type==="Heading"){const c=l.tag||"h2",u=parseInt(c.replace("h",""))||2;s.push({level:u,blockId:l._id,path:[...a,l._id]})}l.children&&l.children.length>0&&o(l.children,[...a,l._id])})};o(e);for(let r=1;r<s.length;r++){const a=s[r],l=s[r-1];a.level>l.level+1&&n.push({id:`heading-level-skip-${a.blockId}`,message:`Heading level skipped: h${l.level} followed by h${a.level}. Consider using h${l.level+1}`,severity:"warning",blockId:a.blockId})}return n}}],Gd=[{name:"image-alt-text",description:"Warns if images are missing alt text",validate:(t,e)=>{const n=[],s=o=>{o.forEach(r=>{r._type==="Image"&&!r.alt&&n.push({id:`image-missing-alt-${r._id}`,message:"Image should have alt text for accessibility",severity:"warning",blockId:r._id}),r.children&&r.children.length>0&&s(r.children)})};return s(e),n}},{name:"button-accessibility",description:"Ensures buttons have accessible labels",validate:(t,e)=>{const n=[],s=o=>{o.forEach(r=>{r._type==="Button"&&(r.content||r.children&&r.children.length>0||n.push({id:`button-no-label-${r._id}`,message:"Button should have accessible content (text or icon)",severity:"warning",blockId:r._id})),r.children&&r.children.length>0&&s(r.children)})};return s(e),n}}];class Ud{constructor(){kt(this,"rules",[...Wd])}addRule(e){this.rules.push(e)}removeRule(e){const n=this.rules.findIndex(s=>s.name===e);return n>-1?(this.rules.splice(n,1),!0):!1}getRules(){return[...this.rules]}enableAccessibilityRules(){this.rules.push(...Gd)}getRuleNames(){return this.rules.map(e=>e.name)}}const qs=new Ud,Hr=(t={})=>{const e=$("flags.validateStructure",!0),n=S.useSetAtom(Zt),s=S.useSetAtom(Rr),o=S.useSetAtom(Pr),r=S.useSetAtom(Lr),a=g.useCallback(c=>{const u=c;if(!e||!u||u.length===0)return;const p=Br(u),f=[];let h=qs.getRules();t.enableAccessibilityRules&&(qs.enableAccessibilityRules(),h=qs.getRules()),t.customRules&&t.customRules.length>0&&h.push(...t.customRules),h.forEach(y=>{try{const k=y.validate(u,p);f.push(...k)}catch(k){console.error(`Error running structure rule "${y.name}":`,k)}});const m=f.filter(y=>y.severity==="error").length>0,x=f.filter(y=>y.severity==="warning").length>0,b=!m;n(f),s(b),o(m),r(x)},[e,t,n,s,o,r]);return xe.useDebouncedCallback(a,[e,t,n,s,o,r],1e3)},qd=["hover","focus","focus-within","focus-visible","active","visited","target","first","last","only","odd","even","first-of-type","last-of-type","only-of-type","empty","disabled","checked","indeterminate","default","required","valid","invalid","in-range","out-of-range","placeholder-shown","autofill","read-only","open","before","after","first-letter","first-line","marker","selection","file","placeholder","hs-collapse-open","hs-accordion-active"],pr={bodyFont:"Arial",headingFont:"Arial",roundedCorners:5,primaryColor:"#570df8",secondaryColor:"#f002b8",bodyBgDarkColor:"#031022",bodyBgLightColor:"#fcfcfc",bodyTextDarkColor:"#ffffff",bodyTextLightColor:"#000000"},Kd=S.atom(pr);S.atom(null);const Yd=()=>{const[t,e]=S.useAtom(Kd);return[d.isObject(t)?{...pr,...t}:pr,e]},Jd=S.atom(null),Xd=()=>({currentPage:S.useAtomValue(Jd)}),Zd=d.memoize(t=>{const e=K.getRegisteredChaiBlock(t),n=d.get(e,"schema.properties",{});return d.compact(Object.keys(n).map(s=>d.get(n[s],"builderProp",!1)||d.get(n[s],"runtime",!1)?s:null))}),Qd=()=>{const[t]=Yd(),{currentPage:e}=Xd(),[n]=Z();return g.useCallback(()=>{const s=d.map(n,o=>d.omit(o,Zd(o._type)));return{currentPage:e,blocks:s}},[t,e,n])},na=S.atom(!1),eu=()=>S.useAtom(na),Ge=()=>{const t=$("permissions",null);return{hasPermission:g.useCallback(n=>t?t.includes(n):!0,[t])}},js=S.atom({}),tu=S.atom({}),sa=t=>d.filter(t.map(e=>e._type==="PartialBlock"||e._type==="GlobalBlock"?d.get(e,"partialBlockId",d.get(e,"globalBlock","")):null),Boolean);function ra(t,e,n,s=new Set){if(t===e)return!0;if(s.has(e))return!1;s.add(e);const o=n[e]||[];for(const r of o)if(r===t||ra(t,r,n,s))return!0;return!1}function fr(t,e,n=new Set){if(n.has(t))return 0;n.add(t);const s=e[t]||[];return s.length===0?1:1+Math.max(...s.map(o=>fr(o,e,new Set(n))))}const oa=()=>{const[t,e]=g.useState(!1),[n,s]=g.useState(null),[o,r]=S.useAtom(tu),a=$("getPartialBlocks",async()=>({})),l=g.useCallback(async()=>{e(!0),s(null);try{const c=await a();r(c),e(!1)}catch(c){s(c instanceof Error?c.message:"Failed to fetch partial blocks"),e(!1)}},[a,r]);return g.useEffect(()=>{l()},[]),{data:o,isLoading:t,refetch:l,error:n}},Vr=()=>{const[t,e]=S.useAtom(js),n=g.useCallback(o=>d.get(t,`${o}.blocks`,[]),[t]),s=g.useCallback(()=>e({}),[e]);return{getPartialBlocks:n,reset:s}},is=4,nu=()=>{const[t]=S.useAtom(js);return g.useMemo(()=>{const e={};return Object.entries(t).forEach(([n,s])=>{e[n]=s.dependencies}),e},[t])},ia=()=>{const t=$("pageId",""),e=nu();return g.useCallback(n=>{if(!t)return{canAdd:!0};if(t===n)return{canAdd:!1,reason:"Cannot add a partial inside itself"};if(ra(t,n,e))return{canAdd:!1,reason:"Adding this partial would create a circular reference"};const s=fr(t,e),o=fr(n,e);return Math.max(s,1+o)>is?{canAdd:!1,reason:`Maximum nesting depth (${is} levels) would be exceeded`}:{canAdd:!0}},[t,e])},su=()=>{const[t]=Z(),[e,n]=S.useAtom(js),s=$("getPartialBlockBlocks",async c=>[]),o=g.useRef(new Set),r=g.useMemo(()=>t.filter(c=>c._type==="PartialBlock"||c._type==="GlobalBlock").map(c=>d.get(c,"partialBlockId",d.get(c,"globalBlock",""))).filter(Boolean),[t]),a=g.useMemo(()=>{const c=[];return Object.values(e).forEach(u=>{u.status==="loaded"&&c.push(...u.dependencies)}),c},[e]),l=g.useMemo(()=>[...new Set([...r,...a])],[r,a]);g.useEffect(()=>{const c=l.filter(u=>{const p=e[u],f=o.current.has(u);return(!p||p.status==="idle")&&!f});c.length!==0&&(c.forEach(u=>o.current.add(u)),n(u=>{const p={};return c.forEach(f=>{p[f]={blocks:[],dependencies:[],status:"loading"}}),{...u,...p}}),Promise.all(c.map(async u=>{try{const p=await s(u),f=sa(p);n(h=>({...h,[u]:{blocks:p,dependencies:f,status:"loaded"}}))}catch(p){n(f=>({...f,[u]:{blocks:[],dependencies:[],status:"error",error:p instanceof Error?p.message:"Failed to fetch"}}))}finally{o.current.delete(u)}})))},[l,e,n,s])},Ss=S.atom("SAVED");Ss.debugLabel="builderSaveStateAtom";const ru=(t,e)=>e?t.some(n=>{if(!(n!=null&&n._type)||n._type==="PartialBlock")return!1;try{const s=K.getRegisteredChaiBlock(n._type);return s?(d.has(s,"i18nProps")?s.i18nProps??[]:[]).some(r=>{const a=`${r}-${e}`;return!n[a]||d.isEmpty(n[a])}):!1}catch(s){return console.warn(`Failed to get block definition for type: ${n._type}`,s),!1}}):!1,en=()=>{const[t,e]=S.useAtom(Ss),n=$("onSave",async A=>{}),s=$("onSaveStateChange",d.noop),o=Qd(),{hasPermission:r}=Ge(),{selectedLang:a,fallbackLang:l}=Te(),[c]=eu(),u=S.useAtomValue(js),p=Hr(),[,f]=S.useAtom(Cs),h=()=>{const A=o();return!a||a===l?!1:ru(A.blocks||[],a)},m=g.useCallback(A=>{const v=new Set,j=sa(A);for(;j.length>0;){const I=j.shift();if(v.has(I))continue;v.add(I);const N=u[I];(N==null?void 0:N.status)==="loaded"&&N.dependencies.length>0&&j.push(...N.dependencies)}return[...v]},[u]),x=g.useCallback(A=>{const v=JSON.stringify(A),j=/pageType:[^:]+:([a-f0-9-]{36})/gi,I=[];let N;for(;(N=j.exec(v))!==null;)N[1]&&I.push(N[1]);return d.compact([...new Set(I)])},[]),b=g.useCallback(A=>{const v=/dt#[^ "]+/g,j={};for(const I of A){const N=JSON.stringify(I);let E;for(;(E=v.exec(N))!==null;)if(E[0]){const _=E[0];j[_]||(j[_]={}),j[_][I._id]=I._name||I._type}}return j},[]),y=g.useCallback(A=>!A&&(!r("save_page")||!c)||!A&&t==="SAVED",[r,c,t]);return{savePage:xe.useThrottledCallback(async(A=!1,v=!1)=>{if(y(v))return;const j=o();return j!=null&&j.blocks&&p(j.blocks),e("SAVING"),s("SAVING"),f(0),await n({autoSave:A,blocks:j.blocks,needTranslations:h(),partialIds:m(j.blocks||[]),linkPageIds:x(j.blocks||[]),designTokens:b(j.blocks||[])}),setTimeout(()=>{e("SAVED"),s("SAVED")},100),!0},[y,o,e,f,n,s,c,p,m,x,b],3e3),savePageAsync:async(A=!1)=>{if(y(A))return;e("SAVING"),s("SAVING");const v=o();return f(0),await n({autoSave:!0,blocks:v.blocks,needTranslations:h(),partialIds:m(v.blocks||[]),linkPageIds:x(v.blocks||[]),designTokens:b(v.blocks||[])}),setTimeout(()=>{e("SAVED"),s("SAVED")},100),!0},saveState:t,setSaveState:e,needTranslations:h}},ou=()=>{const{savePage:t,saveState:e}=en(),n=$("autoSave",!0),s=$("autoSaveActionsCount",10),[o]=S.useAtom(Cs);g.useEffect(()=>{n&&(e==="SAVED"||e==="SAVING"||o>=s&&t(!0))},[n,t,e,o,s])},iu=()=>{const[,t]=S.useAtom(Cs),{setSaveState:e}=en();return g.useCallback(()=>{t(n=>n+1),e(n=>n!=="UNSAVED"?"UNSAVED":n)},[t,e])};function au(t,e,n,s){const o=[...e];let r=[...t];if(n){const u=t.find(p=>p._id===n);if(u&&u.content!==void 0&&u.content!==""&&!t.some(f=>f._parent===n)){const h={_id:ce.generateUUID(),_parent:n,_type:"Text",content:u.content};Object.keys(u).forEach(m=>{m.startsWith("content-")&&(h[m]=u[m])}),o.unshift(h),r=r.map(m=>{if(m._id===n){const x={...m,content:""};return Object.keys(x).forEach(b=>{b.startsWith("content-")&&(x[b]="")}),x}return m})}}let a=r.filter(u=>!u._parent);n&&(a=r.filter(u=>u._parent===n));const l=s!==void 0&&!isNaN(s)&&s>-1?Math.min(s,a.length):a.length;let c=r.length;for(let u=0,p=0;u<r.length;u++)if(n!==void 0?r[u]._parent===n:!r[u]._parent){if(p===l){c=u;break}p++}return!n&&s!==void 0&&s>=a.length&&(c=r.length),[...r.slice(0,c),...o,...r.slice(c)]}function lu(t){return Br(t)}function cu(t){let e=[];return t.walk(n=>(delete n.model.children,e.push(n.model),!0)),e}function Wo(t,e){return t.first(n=>n.model._id===e)||null}function du(t,e,n,s){var u,p;const o=Wo(t,e),r=Wo(t,n);if(!o||!r)return!1;r.children||(r.model.children=[]);let a=(u=r==null?void 0:r.children)==null?void 0:u.findIndex(f=>f.model._id===e);o.drop(),a=Math.max(a,0);const c=(((p=o==null?void 0:o.model)==null?void 0:p._parent)||"root")===n&&a<=s?s-1:s;try{r.addChildAtIndex(o,c)}catch(f){return console.error("Error adding child to parent:",f),!1}return!0}function uu(t,e){if(!e||!e._parent)return t;const n=e._parent,s=t.find(r=>r._id===n);if(!s)return t;const o=t.filter(r=>r._parent===n);if(o.length===2){const r=o.find(a=>a._id!==e._id);if(r&&r._type==="Text"&&"content"in s)return t.map(l=>{if(l._id===n){const c={...l,content:r.content};return Object.keys(r).forEach(u=>{u.startsWith("content-")&&(c[u]=r[u])}),c}return l}).filter(l=>l._id!==r._id)}return t}function pu(t,e,n){if(!n||n==="root")return t;const s=t.find(o=>o._id===n);if(!s)return t;if(s.content!==void 0&&s.content!==""&&!t.some(r=>r._parent===n&&r._id!==e._id)){const a={_id:ce.generateUUID(),_parent:n,_type:"Text",content:s.content};Object.keys(s).forEach(u=>{u.startsWith("content-")&&(a[u]=s[u])});const l=t.map(u=>{if(u._id===n){const p={...u,content:""};return Object.keys(p).forEach(f=>{f.startsWith("content-")&&(p[f]="")}),p}return u}),c=l.findIndex(u=>u._id===e._id);return c!==-1?[...l.slice(0,c),a,...l.slice(c)]:[a,...l]}return t}function fu(t,e,n,s){if(!e)return t;const o=t.find(u=>u._id===e);if(!o)return t;let r=uu(t,o);const a=n||"root",c=new qc().parse({_id:"root",children:lu(r)});if(du(c,e,a,s)){let u=cu(c);const p=u.find(f=>f._id===e);return p&&(p._parent=a==="root"?null:a),u.shift(),n&&(u=pu(u,o,n)),u}return r}const dn=new BroadcastChannel("chaibuilder"),aa=()=>{const t=$("pageId","chaibuilder_page");return{postMessage:xe.useDebouncedCallback(n=>dn.postMessage({...n,pageId:t}),[t],200)}},hu=()=>{const[,t]=Z(),e=$("pageId","chaibuilder_page"),{updateBlocksProps:n}=la();g.useEffect(()=>(dn.onmessageerror=s=>{console.log("error",s)},dn.onmessage=s=>{s.data.type==="blocks-updated"&&s.data.pageId===e&&t(s.data.blocks),s.data.type==="blocks-props-updated"&&s.data.pageId===e&&n(s.data.blocks)},()=>{dn.onmessage=null,dn.onmessageerror=null}),[t,e])},Wr=(t,e)=>{let n=[...t],s=[];e.forEach(l=>{const c=n.find(f=>f._id===l);if(!c||!c._parent)return;const u=c._parent,p=n.filter(f=>f._parent===u);if(p.length===2){const f=p.find(h=>h._id!==l);if(f&&f._type==="Text"){const h=n.find(m=>m._id===u);h&&"content"in h&&(n=n.map(m=>{if(m._id===u){const x={...m,content:f.content};return Object.keys(f).forEach(b=>{b.startsWith("content-")&&(x[b]=f[b])}),x}return m}),s.push(f._id))}}});const o=[...e,...s],r=[],a=d.filter(n,l=>d.includes(o,l._id)||d.includes(o,l._parent)?(r.push(l._id),!1):!0);return d.isEmpty(r)?a:Wr(a,r)},Ns=()=>{const[t]=Z(),[e,n]=q(),{setNewBlocks:s}=Ee(),{hasPermission:o}=Ge();return g.useCallback(r=>{var l;if(!o(be.DELETE_BLOCK))return;const a=((l=d.find(t,{_id:r[0]}))==null?void 0:l._parent)||null;s(Wr(t,r)),setTimeout(()=>n(a?[a]:[]),200)},[t,n,e,o])},mu=S.atom(null,(t,e,{id:n,props:s})=>{const o=t(Nn),r=d.find(o,a=>t(a)._id===n);return r?e(r,{...t(r),...s}):null}),gu=()=>S.useSetAtom(mu),xu=t=>He.useAtomCallback(g.useCallback((e,n,s)=>{const o=e(t);if(!o||!o.length)return console.warn("No blocks available in splitAtoms"),null;const r=d.find(o,a=>e(a)._id===(d.isString(s)?s:e(s)._id));return r||(console.warn(`Block with id ${s} not found`),null)},[t]),{store:$e}),la=()=>{const[,t]=Z(),{postMessage:e}=aa(),n=gu(),s=Hr(),o=iu();return{setNewBlocks:r=>{t(r),e({type:"blocks-updated",blocks:r})},addBlocks:(r,a,l)=>{t(c=>{const u=au(c,r,a,l);return e({type:"blocks-updated",blocks:u}),s(u),o(),u})},removeBlocks:r=>{t(a=>{const l=Wr(a,r);return e({type:"blocks-updated",blocks:l}),s(l),o(),l})},moveBlocks:(r,a,l)=>{t(c=>{let u=[...c];for(let p=0;p<r.length;p++)u=fu(u,r[p],a,l);return d.each(r,p=>{const f=d.find(u,h=>h._id===p);f&&n({id:p,props:{_parent:f._parent||null}})}),e({type:"blocks-updated",blocks:u}),s(u),o(),u})},updateBlocksProps:r=>{r.forEach(a=>{const l=d.omit(a,"_id");n({id:a._id,props:l})}),e({type:"blocks-props-updated",blocks:r}),o()}}},qe=new Kc;qe.setLimit(50);const bu=S.atom({canUndo:!1,canRedo:!1}),En=()=>{const[,t]=S.useAtom(Ss),[e,n]=S.useAtom(bu),s=$("onSaveStateChange",d.noop),o=g.useCallback(()=>{const u={canUndo:qe.hasUndo(),canRedo:qe.hasRedo()};n(u),t("UNSAVED"),s("UNSAVED")},[n,t,s]);g.useEffect(()=>(qe.setCallback(o),()=>{qe.setCallback(d.noop)}),[o]);const r=g.useCallback(u=>{qe.add(u),o()},[o]),a=g.useCallback(()=>{qe.undo(),o()},[o]),l=g.useCallback(()=>{qe.redo(),o()},[o]),c=g.useCallback(()=>{qe.clear(),n({canUndo:!1,canRedo:!1})},[n]);return g.useMemo(()=>({add:r,undo:a,redo:l,hasUndo:()=>e.canUndo,hasRedo:()=>e.canRedo,clear:c}),[r,a,l,e.canUndo,e.canRedo,c])},Z=()=>S.useAtom(Ne),Ee=()=>{const{add:t}=En(),{setNewBlocks:e,addBlocks:n,removeBlocks:s,moveBlocks:o,updateBlocksProps:r}=la();return{moveBlocks:(m,x,b)=>{const y=$e.get(Ne),k=d.map(m,A=>{const j=y.find(E=>E._id===A)._parent||null,N=y.filter(E=>j?E._parent===j:!E._parent).map(E=>E._id).indexOf(A);return{_id:A,oldParent:j,oldPosition:N}}),C=k.find(({_id:A})=>A===m[0]);C&&C.oldParent===x&&C.oldPosition===b||(o(m,x??null,b),t({undo:()=>d.each(k,({_id:A,oldParent:v,oldPosition:j})=>{o([A],v??null,j)}),redo:()=>o(m,x??null,b)}))},addBlocks:(m,x,b)=>{n(m,x,b),t({undo:()=>s(d.map(m,"_id")),redo:()=>n(m,x,b)})},removeBlocks:m=>{var C;const x=$e.get(Ne),b=(C=d.first(m))==null?void 0:C._parent,k=x.filter(A=>b?A._parent===b:!A._parent).indexOf(d.first(m));s(d.map(m,"_id")),t({undo:()=>n(m,b??void 0,k),redo:()=>s(d.map(m,"_id"))})},updateBlocks:(m,x,b)=>{const y=$e.get(Ne);let k=[];if(b)k=d.map(m,C=>({_id:C,...b}));else{const C=d.keys(x);k=d.map(m,A=>{const v=y.find(I=>I._id===A),j={_id:A};return d.each(C,I=>j[I]=v[I]),j})}r(d.map(m,C=>({_id:C,...x}))),t({undo:()=>r(k),redo:()=>r(d.map(m,C=>({_id:C,...x})))})},updateBlocksRuntime:(m,x)=>{r(d.map(m,b=>({_id:b,...x})))},setNewBlocks:m=>{const x=$e.get(Ne);e(m),t({undo:()=>e(x),redo:()=>e(m)})},updateMultipleBlocksProps:m=>{const x=$e.get(Ne);let b=[];b=d.map(m,y=>{const k=d.keys(y),C=x.find(v=>v._id===y._id),A={};return d.each(k,v=>A[v]=C==null?void 0:C[v]),A}),r(m),t({undo:()=>r(b),redo:()=>r(m)})}}},yu=({block:t,children:e})=>{const{t:n}=z.useTranslation(),[s]=Z(),{hasPermission:o}=Ge(),r=d.get(t,"_id"),a=d.get(t,"_parent"),l=d.filter(s,f=>a?d.get(f,"_parent")===a:!d.get(f,"_parent")),c=rs(d.get(t,"_type","")),u=d.findIndex(l,{_id:r}),p=f=>{if(f==="CHILD")oe.publish(Y.OPEN_ADD_BLOCK,t);else{const h={_id:a||"",position:l==null?void 0:l.length};f==="BEFORE"?h.position=Math.max(u,0):f==="AFTER"&&(h.position=u+1),oe.publish(Y.OPEN_ADD_BLOCK,h)}};return o(be.ADD_BLOCK)?i.jsxs(gt,{children:[i.jsx(xt,{children:e}),i.jsxs(Ze,{className:"border border-blue-500 bg-primary text-white shadow-2xl",children:[c&&i.jsx(ge,{className:"cursor-pointer text-xs",onClick:()=>p("CHILD"),children:n("Add inside")}),i.jsx(ge,{className:"cursor-pointer text-xs",onClick:()=>p("BEFORE"),children:n("Add before")}),i.jsx(ge,{className:"cursor-pointer text-xs",onClick:()=>p("AFTER"),children:n("Add after")})]})]}):null},Es=S.atom(null),An=S.atom({isVisible:!1,isValid:!1,position:"inside",placeholderOrientation:"horizontal",isEmpty:!1,top:0,left:0,width:0,height:0});let Gt=!1;const Gr=t=>{Gt=t},Ur=S.atom(0),ku=S.atom(!1);ku.debugLabel="readOnlyModeAtom";const vu=S.atom("online");vu.debugLabel="networkModeAtom";S.atom("");const wu=S.atom(!1);wu.debugLabel="editLayerNameAtom";const Cu=S.atom("");Cu.debugLabel="activeLanguageAtom";const ju=S.atom("");ju.debugLabel="primaryLanguageAtom";const As=S.atom(null);As.debugLabel="canvasIframeAtom";const Su=S.atom("outline");Su.debugLabel="activePanelAtom";const ca=S.atom("");ca.debugLabel="showPredefinedBlockCategoryAtom";const Nu=S.atom(!1);Nu.debugLabel="draggingFlagAtom";const qr=S.atom(null);qr.debugLabel="treeRefAtom";const Eu=S.atom({});Eu.debugLabel="canvasSettingsAtom";const da=S.atom(!1);da.debugLabel="aiAssistantActiveAtom";const Au=S.atom(!1);Au.debugLabel="codeEditorOpenAtom";const _u=He.atomWithStorage("codeEditorHeight",500);_u.debugLabel="codeEditorHeightAtom";const Iu=S.atom([]);Iu.debugLabel="xShowBlocksAtom";const Kr=He.atomWithStorage("_selectedLibrary",null);Kr.debugLabel="selectedLibraryAtom";const Yr=S.atom(!0);Yr.debugLabel="dataBindingActiveAtom";const Tu=He.atomWithStorage("chai-builder-theme",Xe.defaultThemeValues),tn=()=>S.useAtom(As);let re=null,ot=null;function Bu(t,e){const n=t.getAttribute("data-block-name"),s=t.getAttribute("data-block-type"),o=n||s||"Container",r=e.createElement("div");return r.className="chai-drag-parent-label",r.textContent=o,r.className="absolute top-0 -left-0.5 -translate-x-0.5 -translate-y-full -mt-1 bg-green-500/95 text-white px-2 py-1 text-xs font-semibold font-sans leading-tight whitespace-nowrap shadow-lg z-[999999] pointer-events-none select-none",r}function Ks(){ot&&ot.parentNode&&(ot.parentNode.removeChild(ot),ot=null)}const Jr=()=>{const[t]=tn(),e=g.useMemo(()=>{var o;return(t==null?void 0:t.contentDocument)||((o=t==null?void 0:t.contentWindow)==null?void 0:o.document)},[t]),n=g.useCallback(o=>{if(!e)return;let r=null;if(!o){re&&(re.style.outline="",re.style.outlineOffset="",re.style.backgroundColor="",re.style.position="",re=null),Ks();return}typeof o!="string"?r=o:r=e.querySelector(`[data-block-id="${o}"]`),!(r===re&&ot&&ot.parentNode)&&(re&&re!==r&&(re.style.outline="",re.style.outlineOffset="",re.style.backgroundColor="",re.style.position=""),Ks(),r?(r.style.outline="2px dashed rgba(34, 197, 94, 1)",r.style.outlineOffset="2px",r.style.backgroundColor="rgba(34, 197, 94, 0.05)",window.getComputedStyle(r).position==="static"&&(r.style.position="relative"),ot=Bu(r,e),r.appendChild(ot),re=r):re=null)},[e]),s=g.useCallback(()=>{re&&(re.style.outline="",re.style.outlineOffset="",re.style.backgroundColor="",window.getComputedStyle(re).position==="relative"&&re.style.position==="relative"&&(re.style.position=""),re=null),Ks()},[]);return{highlightParent:n,clearParentHighlight:s,lastDragHighlighted:re}},Ru=()=>{const[,t]=S.useAtom(Es),[,e]=S.useAtom(An),[n]=tn(),{clearParentHighlight:s}=Jr(),[o,r]=S.useAtom(Ur),a=n==null?void 0:n.contentDocument;return g.useCallback(()=>{t(null),e({isVisible:!1,isValid:!1,position:"inside",placeholderOrientation:"horizontal",isEmpty:!1,top:0,left:0,width:0,height:0}),Pu(a),s(),a&&a.querySelectorAll("[data-dragging]").forEach(c=>{c.removeAttribute("data-dragging")}),Gr(!1),r(o+1)},[t,e,a,s,o,r])};function Pu(t){if(!t)return;t.querySelectorAll("[data-drop-target]").forEach(n=>n.removeAttribute("data-drop-target"))}function Bt(t,e=null){const n=window.getComputedStyle(t),s=e?window.getComputedStyle(e):null,o=n.display,r=s?s.display:null;if(o==="flex"||o==="inline-flex"){const a=n.flexDirection;return a==="column"||a==="column-reverse"?"vertical":"horizontal"}else if(o==="grid"){const a=n.gridAutoFlow,l=n.gridTemplateColumns;return a.includes("column")||l&&l!=="none"&&l!==""&&!l.includes("calc")&&l.split(" ").length<=1?"vertical":"horizontal"}else if(r==="inline-block"||r==="inline")return"horizontal";return"vertical"}const Lu=["Heading","Text","Image","Paragraph","Icon","Input","Radio","Checkbox","Select","CustomHTML","TextArea","Divider","Repeater","Video"];function Du(t){try{return Lu.includes(t)}catch{return!1}}const Je={MIN_EDGE_ZONE:10,MAX_EDGE_ZONE:30,EDGE_ZONE_PERCENTAGE:.2,GAP_THRESHOLD:8,MIN_SIZE_FOR_EDGE_ZONES:50,PARENT_EDGE_PROXIMITY:20};function Go(t){try{if(t<Je.MIN_SIZE_FOR_EDGE_ZONES)return 0;const e=t*Je.EDGE_ZONE_PERCENTAGE;return Math.max(Je.MIN_EDGE_ZONE,Math.min(Je.MAX_EDGE_ZONE,e))}catch{return Je.MIN_EDGE_ZONE}}function ht(t){try{const e=[],n=t.children;for(let s=0;s<n.length;s++){const o=n[s];o.hasAttribute("data-block-id")&&e.push(o)}return e}catch{return[]}}function Xn(t){try{return ht(t).length>0}catch{return!1}}function Mu(t,e,n,s){try{const o=ht(t);if(o.length<2)return null;const r=zu(o,e,n,s);if(r){const a=Xr(o,r,s);a.sort((l,c)=>{const u=l.getBoundingClientRect(),p=c.getBoundingClientRect();return s==="vertical"?u.top-p.top:u.left-p.left});for(let l=0;l<a.length-1;l++){const c=a[l],u=a[l+1],p=c.getBoundingClientRect(),f=u.getBoundingClientRect();if(s==="vertical"){const h=p.bottom,m=f.top,x=m-h,b=n>=h&&n<=m,y=e>=Math.min(p.left,f.left)&&e<=Math.max(p.right,f.right);if(b&&y&&x>=Je.GAP_THRESHOLD)return{before:c,after:u}}else{const h=p.right,m=f.left,x=m-h,b=e>=h&&e<=m,y=n>=Math.min(p.top,f.top)&&n<=Math.max(p.bottom,f.bottom);if(b&&y&&x>=Je.GAP_THRESHOLD)return{before:c,after:u}}}}for(let a=0;a<o.length-1;a++){const l=o[a],c=o[a+1],u=l.getBoundingClientRect(),p=c.getBoundingClientRect();if(s==="vertical"){const f=u.bottom,h=p.top,m=h-f,x=n>=f&&n<=h,b=e>=Math.min(u.left,p.left)&&e<=Math.max(u.right,p.right);if(x&&b&&m>=Je.GAP_THRESHOLD)return{before:l,after:c}}else{const f=u.right,h=p.left,m=h-f,x=e>=f&&e<=h,b=n>=Math.min(u.top,p.top)&&n<=Math.max(u.bottom,p.bottom);if(x&&b&&m>=Je.GAP_THRESHOLD)return{before:l,after:c}}}return null}catch{return null}}function Ou(t,e,n,s){try{const o=t.getBoundingClientRect(),r=Je.PARENT_EDGE_PROXIMITY;if(s==="vertical"){if(n<=o.top+r)return"start";if(n>=o.bottom-r)return"end"}else{if(e<=o.left+r)return"start";if(e>=o.right-r)return"end"}return null}catch{return null}}function $u(t,e,n,s,o){const r=t.getBoundingClientRect();if(o==="vertical"){const l=(n-r.top)/r.height,c=Go(r.height),u=c/r.height;return s?c>0&&l<u?{position:"before",confidence:1-l/u}:c>0&&l>1-u?{position:"after",confidence:(l-(1-u))/u}:{position:"inside",confidence:1-Math.abs(l-.5)*2}:l<.5?{position:"before",confidence:1-l*2}:{position:"after",confidence:(l-.5)*2}}else{const l=(e-r.left)/r.width,c=Go(r.width),u=c/r.width;return s?c>0&&l<u?{position:"before",confidence:1-l/u}:c>0&&l>1-u?{position:"after",confidence:(l-(1-u))/u}:{position:"inside",confidence:1-Math.abs(l-.5)*2}:l<.5?{position:"before",confidence:1-l*2}:{position:"after",confidence:(l-.5)*2}}}function Fu(t,e,n,s,o){var A,v,j,I;const r=t.getAttribute("data-block-id"),a=t.getAttribute("data-block-type")||"Box";if(!r)return null;let l=t.parentElement;for(;l&&!l.hasAttribute("data-block-id");)l=l.parentElement;const c=r==="canvas"?r:l==null?void 0:l.getAttribute("data-block-id"),u=l?Bt(l):"vertical",p=Bt(t),f=Du(a),h=!f&&Qe(a,s),m=((A=o.defaultView)==null?void 0:A.scrollY)||0,x=((v=o.defaultView)==null?void 0:v.scrollX)||0;if(r==="canvas"&&Xn(t)){const N=ht(t),E=N[N.length-1];if(E){const _=E.getBoundingClientRect(),B=t.getBoundingClientRect(),P=window.getComputedStyle(t),R=parseFloat(P.paddingLeft)||0,M=parseFloat(P.paddingRight)||0,H=B.width-R-M,G=B.left+x+R;return{position:"after",placeholderOrientation:"horizontal",rect:{top:_.bottom+m,left:G,width:H,height:4},targetElement:E,targetBlockId:E.getAttribute("data-block-id"),targetParentId:"canvas",isEmpty:!1,confidence:1}}}if(h&&!f&&Xn(t)){const N=Mu(t,e,n,p);if(N){const E=N.before.getBoundingClientRect(),_=N.after.getBoundingClientRect(),B=t.getBoundingClientRect(),P=window.getComputedStyle(t),R=parseFloat(P.paddingLeft)||0,M=parseFloat(P.paddingRight)||0,H=ht(t),G=Xr(H,N.before,p);let fe=0;if(G.forEach(he=>{const se=he.getBoundingClientRect();se.height>fe&&(fe=se.height)}),p==="vertical"){const he=B.width-R-M,se=B.left+x+R;return{position:"after",placeholderOrientation:"horizontal",rect:{top:E.bottom+m,left:se,width:he,height:4},targetElement:N.before,targetBlockId:N.before.getAttribute("data-block-id"),targetParentId:r,isGapZone:!0,confidence:1}}else{const he=E.top+m,se=fe>0?fe:Math.max(E.height,_.height);return{position:"after",placeholderOrientation:"vertical",rect:{top:he,left:E.right+x,width:4,height:se},targetElement:N.before,targetBlockId:N.before.getAttribute("data-block-id"),targetParentId:r,isGapZone:!0,confidence:1}}}}if(l&&c){const N=Ou(l,e,n,u);if(N){const E=l.getBoundingClientRect(),_=window.getComputedStyle(l),B=parseFloat(_.paddingLeft)||0,P=parseFloat(_.paddingRight)||0,R=parseFloat(_.paddingTop)||0,M=parseFloat(_.paddingBottom)||0,H=((j=o.defaultView)==null?void 0:j.scrollY)||0,G=((I=o.defaultView)==null?void 0:I.scrollX)||0,fe=u==="vertical"?"horizontal":"vertical",he=ua(l);if(N==="start"){const se=ht(l)[0];if(se){const _e=se.getBoundingClientRect();if(u==="vertical"){const V=E.width-B-P,ve=E.left+G+B;return{position:"before",placeholderOrientation:fe,rect:{top:_e.top+H-2,left:ve,width:V,height:4},targetElement:se,targetBlockId:se.getAttribute("data-block-id"),targetParentId:c,confidence:.9}}else{const V=E.top+H+R,ve=he.maxHeight>0?he.maxHeight:E.height-R-M;return{position:"before",placeholderOrientation:fe,rect:{top:V,left:_e.left+G-2,width:4,height:ve},targetElement:se,targetBlockId:se.getAttribute("data-block-id"),targetParentId:c,confidence:.9}}}}else{const se=ht(l),_e=se[se.length-1];if(_e){const V=_e.getBoundingClientRect();if(u==="vertical"){const ve=E.width-B-P,Ue=E.left+G+B;return{position:"after",placeholderOrientation:fe,rect:{top:V.bottom+H-2,left:Ue,width:ve,height:4},targetElement:_e,targetBlockId:_e.getAttribute("data-block-id"),targetParentId:c,confidence:.9}}else{const ve=E.top+H+R,Ue=he.maxHeight>0?he.maxHeight:E.height-R-M;return{position:"after",placeholderOrientation:fe,rect:{top:ve,left:V.right+G-2,width:4,height:Ue},targetElement:_e,targetBlockId:_e.getAttribute("data-block-id"),targetParentId:c,confidence:.9}}}}}}let b=$u(t,e,n,h,u);if(f&&b.position==="inside"){const N=t.getBoundingClientRect();u==="vertical"?b={position:(n-N.top)/N.height<.5?"before":"after",confidence:b.confidence}:b={position:(e-N.left)/N.width<.5?"before":"after",confidence:b.confidence}}let y;b.position==="inside"?y=p==="vertical"?"horizontal":"vertical":y=u==="vertical"?"horizontal":"vertical";const k=Hu(t,l,b.position,y,o),C=b.position==="inside"?r:c;return{position:b.position,placeholderOrientation:y,rect:k,targetElement:t,targetBlockId:r,targetParentId:C??"",isEmpty:b.position==="inside"&&!Xn(t),confidence:b.confidence}}function zu(t,e,n,s){if(t.length===0)return null;const o=t.filter(l=>{const c=l.getBoundingClientRect();return s==="vertical"?n>=c.top&&n<=c.bottom:e>=c.left&&e<=c.right});if(o.length===0){const l=new Map;t.forEach(p=>{const f=p.getBoundingClientRect(),h=Math.round(s==="vertical"?f.top:f.left);l.has(h)||l.set(h,[]),l.get(h).push(p)});let c=null,u=1/0;l.forEach((p,f)=>{const h=Math.abs(s==="vertical"?n-f:e-f);h<u&&(u=h,c=p)}),c&&o.push(c)}if(o.length===0)return null;let r=o[0],a=1/0;return o.forEach(l=>{const c=l.getBoundingClientRect(),u=c.left+c.width/2,p=c.top+c.height/2,f=Math.sqrt(Math.pow(e-u,2)+Math.pow(n-p,2));f<a&&(a=f,r=l)}),r}function ua(t){const e=ht(t);if(e.length===0)return{maxWidth:0,maxHeight:0};let n=0,s=0;return e.forEach(o=>{const r=o.getBoundingClientRect();r.width>n&&(n=r.width),r.height>s&&(s=r.height)}),{maxWidth:n,maxHeight:s}}function Xr(t,e,n){const s=e.getBoundingClientRect(),o=5;return t.filter(r=>{const a=r.getBoundingClientRect();return n==="vertical"?Math.abs(a.top-s.top)<=o:Math.abs(a.left-s.left)<=o})}function Hu(t,e,n,s,o){var R,M;const r=t.getBoundingClientRect(),a=window.getComputedStyle(t),l=((R=o.defaultView)==null?void 0:R.scrollY)||0,c=((M=o.defaultView)==null?void 0:M.scrollX)||0,u=parseFloat(a.marginTop)||0,p=parseFloat(a.marginBottom)||0,f=parseFloat(a.marginLeft)||0,h=parseFloat(a.marginRight)||0,m=parseFloat(a.paddingTop)||0,x=parseFloat(a.paddingBottom)||0,b=parseFloat(a.paddingLeft)||0,y=parseFloat(a.paddingRight)||0,k=e==null?void 0:e.getBoundingClientRect(),C=e&&parseFloat(window.getComputedStyle(e).paddingLeft)||0,A=e&&parseFloat(window.getComputedStyle(e).paddingRight)||0,v=e&&parseFloat(window.getComputedStyle(e).paddingTop)||0,j=e&&parseFloat(window.getComputedStyle(e).paddingBottom)||0,I=e?ua(e):{maxHeight:0},N=e?Bt(e):"vertical",E=e?ht(e):[],_=Xr(E,t,N);let B=0,P=0;if(_.forEach(H=>{const G=H.getBoundingClientRect();G.height>B&&(B=G.height),G.width>P&&(P=G.width)}),n==="before")if(s==="horizontal"){const H=k?k.width-C-A:r.width,G=k?k.left+c+C:r.left+c;return{top:r.top+l-u-2,left:G,width:H,height:4}}else{const H=r.top+l,G=N==="horizontal"&&B>0?B:I.maxHeight>0?I.maxHeight:k?k.height-v-j:r.height;return{top:H,left:r.left+c-f-2,width:4,height:G}}else if(n==="after")if(s==="horizontal"){const H=k?k.width-C-A:r.width,G=k?k.left+c+C:r.left+c;return{top:r.bottom+l+p-2,left:G,width:H,height:4}}else{const H=r.top+l,G=N==="horizontal"&&B>0?B:I.maxHeight>0?I.maxHeight:k?k.height-v-j:r.height;return{top:H,left:r.right+c+h-2,width:4,height:G}}else return Xn(t)?Bt(t)==="vertical"?{top:r.bottom+l-x-2,left:r.left+c+b,width:r.width-b-y,height:4}:{top:r.top+l+m,left:r.right+c-y-2,width:4,height:r.height-m-x}:{top:r.top+l+m,left:r.left+c+b,width:r.width-b-y,height:Math.max(r.height-m-x,20)}}const Vu=100,bt=()=>{const[t]=Z(),[,e]=q(),{addBlocks:n}=Ee(),s=g.useCallback((r,a,l)=>{for(let h=0;h<r.length;h++){const{_id:m}=r[h];r[h]._id=ce.generateUUID();const x=d.filter(r,{_parent:m});for(let b=0;b<x.length;b++)x[b]._parent=r[h]._id}const c=d.first(r);let u,p;return a&&(u=d.find(t,{_id:a}),r[0]._parent=a,d.forEach(r,h=>{h!=null&&h._parent||(h._parent=a)}),p=a),!(u?Qe(u==null?void 0:u._type,c._type):!0)&&u&&(r[0]._parent=u._parent,p=u._parent),n(r,p??void 0,l),e([c._id]),c},[n,t,e]);return{addCoreBlock:g.useCallback((r,a,l)=>{if(d.has(r,"blocks")){const b=r.blocks;return s(b,a??void 0,l)}const c=ce.generateUUID(),u=K.getBlockDefaultProps(r.type),p={_type:r.type,_id:c,...u,...d.has(r,"_name")&&{_name:r._name},...d.has(r,"partialBlockId")&&{partialBlockId:r.partialBlockId}};let f,h;return a&&(f=d.find(t,{_id:a}),p._parent=a,h=a),!Qe(f==null?void 0:f._type,p._type)&&f&&(p._parent=f._parent,h=f._parent),n([p],h??void 0,l),setTimeout(()=>e([p._id]),Vu),p},[n,s,t,e]),addPredefinedBlock:s}};let st=null;const et=()=>{const[t]=S.useAtom(As),e=g.useMemo(()=>{var o;return(t==null?void 0:t.contentDocument)||((o=t==null?void 0:t.contentWindow)==null?void 0:o.document)},[t]),n=g.useCallback(o=>{if(e)if(st&&st.removeAttribute("data-highlighted"),typeof o!="string")o.setAttribute("data-highlighted","true"),st=o;else if(typeof o=="string"){const r=e.querySelector(`[data-block-id="${o}"]`);r&&(r.setAttribute("data-highlighted","true"),st=r)}else st=null},[e]),s=g.useCallback(()=>{st&&(st.removeAttribute("data-highlighted"),st=null)},[]);return{highlightBlock:n,clearHighlight:s,lastHighlighted:st}},_n=S.atom([]);_n.debugLabel="selectedStylingBlocksAtom";const Ae=()=>S.useAtom(_n),Wu=()=>{const[t,e]=S.useAtom(Es),[n,s]=S.useAtom(An),[o]=Z(),[r]=tn(),{addCoreBlock:a}=bt(),{moveBlocks:l}=Ee(),[,c]=q(),[,u]=Ae(),{clearHighlight:p}=et(),{clearParentHighlight:f}=Jr(),[h,m]=S.useAtom(Ur),x=Ke(),b=ia(),y=r==null?void 0:r.contentDocument;return g.useCallback(k=>{if(k.preventDefault(),k.stopPropagation(),Gr(!1),Uu(y),Uo(y),f(),s({isVisible:!1,isValid:!1,position:"inside",placeholderOrientation:"horizontal",isEmpty:!1,top:0,left:0,width:0,height:0}),setTimeout(()=>{f(),Uo(y),s({isVisible:!1,isValid:!1,position:"inside",placeholderOrientation:"horizontal",isEmpty:!1,top:0,left:0,width:0,height:0})},50),!t)return;if(!n.isValid||!n.targetBlockId){f();return}e(null);const C=n.targetBlockId,A=n.targetParentId;if(!C)return;const{parentId:v,index:j,replaceImageUrl:I}=Gu(o,C,A,n.position,t),N=t._id!==void 0;if(I&&pa(t)){x([C],{image:d.get(t,"blocks.0.image")}),setTimeout(()=>{m(h+1)},50);return}if(N)l([t._id],v===null?void 0:v,j),p(),u([]),c([t._id]);else{const E=t._type||t.type,_=t!=null&&t.blocks?d.isFunction(t==null?void 0:t.blocks)?K.syncBlocksWithDefaultProps(t==null?void 0:t.blocks()):t==null?void 0:t.blocks:null;if(E==="PartialBlock"){const B=t.partialBlockId||"",{canAdd:P,reason:R}=b(B);if(!P){le.toast.error(R||"Cannot add this partial block");return}a({blocks:[{_type:E,_id:"partial-block",partialBlockId:t.partialBlockId}]},v,j)}else a((_==null?void 0:_.length)>0?{blocks:[..._]}:{type:E},v,j)}setTimeout(()=>{m(h+1)},50)},[t,n,o,y,a,l,e,s,f,p,c,u,h,m,x,b])},pa=t=>{var r,a;const e=d.has(t,"blocks"),n=t==null?void 0:t.blocks,s=(n==null?void 0:n.length)===1&&((r=n==null?void 0:n[0])==null?void 0:r._type)==="Image",o=!((a=n==null?void 0:n[0])!=null&&a._id);return e&&s&&o};function Gu(t,e,n,s,o){var r,a;try{if(e===n&&((r=o==null?void 0:o.blocks)==null?void 0:r.length)===1&&d.get(o,"blocks.0._type")==="Image"&&((a=d.find(t,{_id:e}))==null?void 0:a._type)==="Image")return{parentId:"",index:-1,replaceImageUrl:!0};if(e==="canvas"||s==="inside"&&e==="canvas")return{parentId:null,index:d.filter(t,m=>!(m!=null&&m._parent)).length};if(s==="inside"){const h=d.filter(t,{_parent:e});return{parentId:e,index:h.length}}const l=!n||n==="canvas",c=l?void 0:n,u=d.filter(t,h=>l?!(h!=null&&h._parent):(h==null?void 0:h._parent)===c),p=u.findIndex(h=>h._id===e);if(p===-1)return{parentId:l?null:n,index:u.length};const f=s==="before"?p:p+1;return{parentId:l?null:n,index:f}}catch{return{parentId:null,index:d.filter(t,c=>!(c!=null&&c._parent)).length}}}function Uo(t){if(!t)return;t.querySelectorAll("[data-drop-target]").forEach(n=>n.removeAttribute("data-drop-target"))}function Uu(t){if(!t)return;t.querySelectorAll("[data-dragging]").forEach(n=>{n.removeAttribute("data-dragging")})}function fa(t,e,n){if(!t||!e)return!1;if(t===e)return!0;const s=n.find(r=>r._id===t);if(!s)return!1;let o=s;for(;o._parent;){if(o._parent===e)return!0;const r=n.find(a=>a._id===o._parent);if(!r)break;o=r}return!1}function ha(t,e,n){return!t||!e?!0:!fa(e,t,n)}function qu(t,e,n){if(!t)return!0;const s=n.find(r=>r._id===e);if(!s)return!0;const o=s._parent;return ha(t,o,n)}const Ku=["Heading","Text","Image","Paragraph","Icon","Input","Radio","Checkbox","Select","CustomHTML","TextArea","Divider","Repeater","Video"],ut={EDGE_ZONE:50,MAX_SCROLL_SPEED:10,MIN_SCROLL_SPEED:10},Yu=()=>{const[t]=S.useAtom(Es),[e]=tn(),[,n]=S.useAtom(An),{clearParentHighlight:s,highlightParent:o}=Jr(),[r]=Z(),a=e==null?void 0:e.contentDocument,l=g.useRef(null),c=g.useRef(0),u=g.useCallback(f=>{if(!(a!=null&&a.defaultView))return;const h=a.defaultView,m=h.innerHeight,x=h.scrollY,b=a.documentElement.scrollHeight;c.current=f;const y=f,k=m-f;let C=!1,A=null,v=0;if(y<ut.EDGE_ZONE&&x>0?(C=!0,A="up",v=y):k<ut.EDGE_ZONE&&x+m<b&&(C=!0,A="down",v=k),!C&&l.current!==null){cancelAnimationFrame(l.current),l.current=null;return}if(C&&A){const j=1-v/ut.EDGE_ZONE,I=ut.MIN_SCROLL_SPEED+(ut.MAX_SCROLL_SPEED-ut.MIN_SCROLL_SPEED)*j,N=()=>{if(!Gt||!h){l.current=null;return}const E=A==="up"?-I:I;h.scrollBy(0,E);const _=h.scrollY,B=_>0,P=_+m<b,R=c.current,M=m-c.current;A==="up"&&B&&R<ut.EDGE_ZONE||A==="down"&&P&&M<ut.EDGE_ZONE?l.current=requestAnimationFrame(N):l.current=null};l.current===null&&(l.current=requestAnimationFrame(N))}},[a]);g.useEffect(()=>()=>{l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)},[]),g.useEffect(()=>{!Gt&&l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)},[Gt]);const p=g.useCallback(d.throttle(f=>{if(!Gt||!t)return;s();const h=Ju(f),{element:m,targetBlockId:x,targetParentId:b}=h;if(!m||!x)return;const y=t._id;if(y&&(x===y||fa(x,y,r)))return;const k=t._type||t.type;if(!k)return;const C=f.clientX,A=f.clientY;if(u(A),!a)return;const v=Fu(m,C,A,k,a);if(!v)return;const j=m.getAttribute("data-block-type")||"Box";let I=!1;const N=Ku.includes(j);if(j==="Image"&&k==="Image"&&pa(t)){o(x),n({isVisible:!0,isValid:!0,position:v.position,placeholderOrientation:v.placeholderOrientation,isEmpty:!0,top:m.offsetTop,left:v.rect.left,width:m.clientWidth,height:m.clientHeight,targetBlockId:v.targetBlockId,targetParentId:v.targetBlockId});return}if(v.position==="inside"){if(N||y&&!ha(y,x,r))return;I=Qe(j,k)}else{let _=m.parentElement,B="Box";for(;_&&!_.hasAttribute("data-block-id");)_=_.parentElement;if(_&&(B=_.getAttribute("data-block-type")||"Box"),y&&!qu(y,x,r))return;I=Qe(B,k)}if(!I)return;o(v.targetParentId);const E=v.targetParentId||b||void 0;n({isVisible:!0,isValid:!0,position:v.position,placeholderOrientation:v.placeholderOrientation,isEmpty:v.isEmpty??!1,top:v.rect.top,left:v.rect.left,width:v.rect.width,height:v.rect.height,targetBlockId:v.targetBlockId,targetParentId:E}),Xu(a),v.targetElement.setAttribute("data-drop-target","true")},300),[a,t,n,s,o,r,u]);return g.useCallback(f=>{f.preventDefault(),f.stopPropagation(),p(f)},[p])};function Ju(t){let e=t.target;for(;e&&!e.hasAttribute("data-block-id");)e=e.parentElement;if(!e)return{element:null,targetBlockId:null,targetBlockType:null,targetParentId:null,targetParentType:null,orientation:"vertical"};const n=e.getAttribute("data-block-id"),s=e.getAttribute("data-block-type")||"Box";let o=e.parentElement;for(;o&&!o.hasAttribute("data-block-id");)o=o.parentElement;const r=(o==null?void 0:o.getAttribute("data-block-id"))||null,a=(o==null?void 0:o.getAttribute("data-block-type"))||"Box",l=Bt(e);return{element:e,targetBlockId:n,targetBlockType:s,targetParentId:r,targetParentType:a,orientation:l}}function Xu(t){if(!t)return;t.querySelectorAll("[data-drop-target]").forEach(n=>n.removeAttribute("data-drop-target"))}function Zu(t){var r;const e=document.createElement("div");e.className="absolute -top-[1000px] -left-[1000px] pl-3 pr-1 py-1 bg-white/60 border border-blue-400/30 rounded shadow-md flex items-center gap-1.5 font-sans pointer-events-none z-[9999] scale-90";const n=t.type||t._type||"Box",s=document.createElement("div");s.className="w-3 h-3 flex items-center justify-center text-blue-600";try{n==="Image"?s.innerHTML='<svg class="w-3 h-3" fill="currentColor" viewBox="0 0 0.72 0.72"><path d="M.57.12H.15a.09.09 0 0 0-.09.09v.3A.09.09 0 0 0 .15.6h.42A.09.09 0 0 0 .66.51v-.3A.09.09 0 0 0 .57.12M.15.54A.03.03 0 0 1 .12.51V.437L.219.338a.03.03 0 0 1 .042 0L.462.54ZM.6.51a.03.03 0 0 1-.03.03H.547L.433.425.459.399a.03.03 0 0 1 .042 0L.6.498Zm0-.097L.544.357a.09.09 0 0 0-.127 0L.391.383.305.297a.09.09 0 0 0-.127 0L.12.353V.21A.03.03 0 0 1 .15.18h.42A.03.03 0 0 1 .6.21Z"/></svg>':s.innerHTML=((r=document.querySelector(`[data-add-core-block-icon="${n}"]`))==null?void 0:r.outerHTML)||'<svg class="w-3 h-3" fill="currentColor" viewBox="0 0 20 20"><path d="M3 4a1 1 0 011-1h12a1 1 0 011 1v12a1 1 0 01-1 1H4a1 1 0 01-1-1V4z"/></svg>'}catch{s.textContent=""}const o=document.createElement("span");return o.className="text-[10px] font-medium text-blue-600 whitespace-nowrap",o.textContent=t.label||t.type||t._name||t._type||"Block",e.appendChild(s),e.appendChild(o),document.body.appendChild(e),e}function qo(t){t&&t.parentNode&&t.parentNode.removeChild(t)}const Qu=()=>{const[,t]=q(),[,e]=Ae(),{clearHighlight:n}=et(),[,s]=S.useAtom(Es),[,o]=S.useAtom(An),r=g.useRef(null);return g.useCallback((a,l,c=!0)=>{var p;r.current&&(qo(r.current),r.current=null);const u=c?d.pick(l,["type","blocks","partialBlockId"]):l;if(s(u),a.dataTransfer.setData("text/plain",JSON.stringify({block:u})),a.dataTransfer.effectAllowed="move",!c&&l._id){const f=(p=document.getElementById("canvas-iframe"))==null?void 0:p.contentDocument;if(f){const h=f.querySelector(`[data-block-id="${l._id}"]`);h&&setTimeout(()=>{if(h){const x=h.getBoundingClientRect().height;Bt(h==null?void 0:h.parentElement)==="vertical"&&x>200&&(h.style.height="max-content",h.style.maxHeight="max-content",h.style.minHeight="0",h.style.overflow="hidden",h.innerHTML="<div class='flex items-center justify-center w-full h-full outline-[1px] outline-dashed font-medium outline-gray-500 bg-gray-500/10 py-4 text-transparent'>-</div>",h.style.opacity="0.4"),h.style.opacity="0.4",h.setAttribute("data-dragging","true")}},0)}}if(l!=null&&l._type||l!=null&&l.type){const f=Zu(l);r.current=f,a.dataTransfer.setDragImage(f,0,0),setTimeout(()=>{r.current&&(qo(r.current),r.current=null)},50)}t([]),n(),e([]),oe.publish(Y.CLOSE_ADD_BLOCK),Gr(!0),o({isVisible:!0,isValid:!0,position:"inside",placeholderOrientation:"horizontal",isEmpty:!0,top:0,left:0,width:0,height:0,targetBlockId:"canvas",targetParentId:void 0})},[t,n,s,o])},nn=()=>{const t=Qu(),e=Yu(),n=Wu(),s=Ru();return{onDragStart:t,onDragOver:e,onDrop:n,onDragEnd:s,isDragging:Gt}},ep=()=>{const[t]=S.useAtom(An);return t},Ye=()=>{const{dragAndDrop:t}=$("flags",{dragAndDrop:!0});return t};let ma,ga;typeof document<"u"&&(ma=document);typeof window<"u"&&(ga=window);const xa=g.createContext({document:ma,window:ga}),tt=()=>g.useContext(xa),{Provider:tp,Consumer:p0}=xa,np=[{ControlIcon:w.PinTopIcon,dir:"VERTICAL",key:"UP"},{ControlIcon:w.PinBottomIcon,dir:"VERTICAL",key:"DOWN"},{ControlIcon:w.PinLeftIcon,dir:"HORIZONTAL",key:"LEFT"},{ControlIcon:w.PinRightIcon,dir:"HORIZONTAL",key:"RIGHT"}],sp=(t,e,n)=>{try{if(!t||!n)return"VERTICAL";const s=`[data-block-id='${t}']`,o=n==null?void 0:n.querySelector(s);if(o){const r=n==null?void 0:n.querySelector(`[data-block-id='${e}']`);return Bt(o,r).toUpperCase()}return"VERTICAL"}catch{return"VERTICAL"}},ba=(t,e,n)=>!!(t&&(n==="UP"||n==="LEFT")||e&&(n==="DOWN"||n==="RIGHT")),rp=(t,e)=>{const[n]=Z(),{document:s}=tt(),{moveBlocks:o}=Ee(),r=d.get(t,"_id"),a=d.get(t,"_parent"),l=d.filter(n,x=>a?d.get(x,"_parent")===a:!d.get(x,"_parent")),c=(l==null?void 0:l.length)<=1,u=d.findIndex(l,{_id:r}),p=u<=0,f=u+1===(l==null?void 0:l.length),h=sp(a,r,s),m=g.useCallback(x=>{ba(p,f,x)||c||(x==="UP"||x==="LEFT"?o([r],a||void 0,u-1):(x==="DOWN"||x==="RIGHT")&&o([r],a||void 0,u+2),e())},[p,f,c,u,r,a,e]);return rt.useHotkeys("shift+up, shift+down, shift+left, shift+right",({key:x})=>{var b;m((b=x==null?void 0:x.replace("Arrow",""))==null?void 0:b.toUpperCase())},{document:s},[m]),{isOnlyChild:c,isFirstBlock:p,isLastBlock:f,moveBlock:m,orientation:h}},op=({block:t,updateFloatingBar:e})=>{const{isOnlyChild:n,isFirstBlock:s,isLastBlock:o,moveBlock:r,orientation:a}=rp(t,e);return n?null:i.jsx(i.Fragment,{children:np.map(({ControlIcon:l,dir:c,key:u})=>a!==c||ba(s,o,u)?null:i.jsx(l,{onClick:()=>r(u),className:"rounded p-px hover:bg-white hover:text-blue-500"},u))})},Zr=()=>{const[t]=Z(),[,e]=q(),{addBlocks:n}=Ee();return g.useCallback((s,o=null)=>{const r=[];d.each(s,a=>{const l=t.find(h=>h._id===a);o?o==="root"&&(o=null):o=(l==null?void 0:l._parent)??null;const p=d.filter(t,h=>d.isString(o)?h._parent===o:!h._parent).indexOf(l)+1,f=ur(t,a,o);n(f,o??void 0,p),r.push(d.get(f,"0._id",""))}),e(r)},[t,e])},ip=S.atom(""),ya=()=>S.useAtom(ip),ka=S.atom("");ka.debugLabel="inlineEditingActiveAtom";const va=S.atom(0);va.debugLabel="inlineEditingItemIndexAtom";const Mt=()=>{const[t,e]=S.useAtom(ka),[n,s]=S.useAtom(va);return{editingBlockId:t,editingItemIndex:n,setEditingBlockId:e,setEditingItemIndex:s}},wa=S.atom("outline");wa.debugLabel="sidebarActivePanelAtom";const _s=()=>S.useAtom(wa),ap=({blockId:t,className:e})=>{const n=()=>{t&&oe.publish(Y.GOTO_BLOCK_SETTINGS,t)};return i.jsx(w.GearIcon,{className:e,onClick:n})},lp=S.atom(0),Ca=S.atom(0);function Qr(t){if(t.getAttribute("data-block-id")==="canvas")return null;if(t.getAttribute("data-block-id")||t.getAttribute("data-block-parent"))return t;const e=t.closest("[data-block-id]");return(e==null?void 0:e.getAttribute("data-block-id"))==="canvas"?null:e}const cp=["Heading","Paragraph","Text","Link","Span","Button"],dp=t=>{var e;return(t==null?void 0:t.getAttribute("data-block-type"))==="RichText"||((e=t==null?void 0:t.parentElement)==null?void 0:e.getAttribute("data-block-type"))==="RichText"},ja=t=>t?d.some(t.children,e=>{const n=e;return n.hasAttribute("data-block-id")||ja(n)}):!1,up=(t,e)=>{if(dp(t))return!0;const n=t==null?void 0:t.getAttribute("data-block-type");return n?cp.includes(n):!1},pp=()=>{const{editingBlockId:t,setEditingBlockId:e,setEditingItemIndex:n}=Mt();return g.useCallback(s=>{var l;if(s==null||s.preventDefault(),s==null||s.stopPropagation(),t)return;const o=Qr(s.target);if(!o||!up(o)||ja(o))return;const r=o.getAttribute("data-block-id");if(!r)return;const a=o.closest('[data-block-type="Repeater"]');a?(l=a==null?void 0:a.childNodes)==null||l.forEach((c,u)=>{c.contains(o)&&n(u)}):n(-1),e(r)},[t,e,n])},fp=()=>{const{editingBlockId:t}=Mt(),{clearHighlight:e}=et(),[,n]=Ae(),[s]=S.useAtom(Ca);return g.useCallback(o=>{if(t)return;o.stopPropagation();const r=Qr(o.target);if(!r){e(),n([]),oe.publish(Y.CANVAS_BLOCK_SELECTED,[]);return}if(s!==2){if(r!=null&&r.getAttribute("data-block-id")&&(r==null?void 0:r.getAttribute("data-block-id"))==="container"){oe.publish(Y.CLEAR_CANVAS_SELECTION);return}if(r!=null&&r.getAttribute("data-block-parent")){const a=r.getAttribute("data-style-prop"),l=r.getAttribute("data-style-id"),c=r.getAttribute("data-block-parent");oe.publish(Y.CANVAS_BLOCK_STYLE_SELECTED,{blockId:c,styleId:l,styleProp:a})}else if(r!=null&&r.getAttribute("data-block-id")){const a=r.getAttribute("data-block-id");oe.publish(Y.CANVAS_BLOCK_SELECTED,a==="canvas"?[]:[a])}e()}},[t,s,e,n])},hp=()=>{const{editingBlockId:t}=Mt(),{highlightBlock:e}=et();return xe.useThrottledCallback(n=>{if(t)return;const s=Qr(n.target);s&&e(s)},[t,e],100)},mp=()=>{const{clearHighlight:t}=et();return g.useCallback(()=>t(),[t])},gp=({children:t})=>{const e=pp(),n=fp(),s=hp(),o=mp();return i.jsx("div",{"data-block-id":"canvas",id:"canvas",onClick:n,onDoubleClick:e,onMouseMove:s,onMouseLeave:o,className:"relative h-full max-w-full p-px",children:t})},Sa=(t,e)=>t.querySelector(`[data-block-id="${e}"]`),xp=(t,e)=>t.querySelector(`[data-style-id="${e}"]`),bp=()=>{const t=J(),{document:e}=tt(),[n]=Ae(),[s,o]=g.useState([]),[,r]=g.useState([]),{onDragStart:a,onDragEnd:l,isDragging:c}=nn(),[u,p]=g.useState(null),f=Ye(),h=(m,x=0)=>{const{top:b}=m.getBoundingClientRect();return b+x>=0&&b-x<=window.innerHeight};return g.useEffect(()=>{var m;if(t!=null&&t._id&&t.type!=="Multiple"&&e){const x=Sa(e,t._id);x&&(h(x)||(m=e.defaultView)==null||m.scrollTo({top:x.offsetTop,behavior:"smooth"}),o([x]))}},[t==null?void 0:t._id,t==null?void 0:t.type,e]),g.useEffect(()=>{if(!d.isEmpty(n)&&e){const m=xp(e,d.first(n).id);r(m?[m]:[null])}else r([null])},[n,e]),i.jsx("div",{onDragEnd:()=>{p(null),l()},draggable:f&&!!t,onDragStart:m=>{p(s==null?void 0:s[0]),a(m,t,!1)},children:t&&i.jsx(yp,{block:t,isDragging:c&&!!u,selectedBlockElement:s[0]||(c?u:null)})})},yp=({block:t,isDragging:e,selectedBlockElement:n})=>{const s=Ns(),o=Zr(),[,r]=q(),[,a]=ya(),[,l]=Ae(),{hasPermission:c}=Ge(),{editingBlockId:u}=Mt(),{document:p}=tt(),f=Ye(),h=$("flags.gotoSettings",!1),m=$("flags.ai",!1),{floatingStyles:x,refs:b,update:y}=zo.useFloating({placement:"top-start",middleware:[zo.shift({boundary:p==null?void 0:p.body,limiter:Us.limitShift({offset:8,mainAxis:!0,crossAxis:!0})}),Us.flip({boundary:p==null?void 0:p.body,fallbackPlacements:["bottom-start","top-end","bottom-end","inside"]}),Us.size({boundary:p==null?void 0:p.body,apply({availableWidth:v,availableHeight:j,elements:I}){Object.assign(I.floating.style,{maxWidth:`${Math.max(200,v)}px`,maxHeight:`${Math.max(100,j)}px`})}})],elements:{reference:n}});xe.useResizeObserver(n,()=>y(),n!==null),xe.useResizeObserver(p==null?void 0:p.body,()=>y(),(p==null?void 0:p.body)!==null);const k=d.get(t,"_parent",null),C=d.isEmpty(d.get(t,"_name",""))?d.get(t,"_type",""):d.get(t,"_name","");g.useEffect(()=>{let v=null;return n?(v=setTimeout(()=>y(),500),()=>{v&&clearTimeout(v)}):(y(),()=>{v&&clearTimeout(v)})},[n,t==null?void 0:t._id]);const[,A]=_s();return!e&&(!n||!t||u)?null:i.jsx(i.Fragment,{children:i.jsx("div",{role:"button",tabIndex:0,ref:b.setFloating,style:x,onClick:v=>{v.stopPropagation(),v.preventDefault()},onMouseEnter:v=>{v.stopPropagation(),a(null)},onKeyDown:v=>v.stopPropagation(),className:`isolate z-[999] flex h-6 items-center justify-between bg-blue-500 py-2 text-xs text-white ${e?"opacity-0":""}`,children:i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center",children:[f&&i.jsx(w.DragHandleDots2Icon,{className:"flex-shrink-0 cursor-grab rounded p-0.5 hover:bg-white/20 active:cursor-grabbing"}),k&&i.jsx(w.ArrowUpIcon,{className:"flex-shrink-0 rounded p-0.5 hover:bg-white/20",onClick:()=>{l([]),r([k])}})]}),i.jsx("div",{className:`w-full ${f?"cursor-grab active:cursor-grabbing":""}`,children:i.jsx("div",{className:"mr-10 w-full items-center space-x-1 px-1 leading-tight",children:C})}),i.jsxs("div",{className:"flex items-center gap-1 pl-1 pr-1.5",children:[c(be.ADD_BLOCK)&&m&&i.jsx(Er,{className:"h-4 w-4 rounded hover:bg-white hover:text-blue-500",onClick:()=>{A("chai-chat-panel"),oe.publish(Y.OPEN_AI_PANEL)}}),h&&i.jsx(ap,{blockId:t==null?void 0:t._id,className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500"}),!f&&i.jsx(yu,{block:t,children:i.jsx(w.PlusIcon,{className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500"})}),Ir(d.get(t,"_type",""))&&c(be.ADD_BLOCK)?i.jsx(w.CopyIcon,{className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500",onClick:()=>o([t==null?void 0:t._id])}):null,Tr(d.get(t,"_type",""))&&c(be.DELETE_BLOCK)?i.jsx(w.TrashIcon,{className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500",onClick:()=>s([t==null?void 0:t._id])}):null,c(be.MOVE_BLOCK)&&i.jsx(op,{block:t,updateFloatingBar:y})]})]})})})},kp=`<!doctype html>
2
+ <html lang="en" dir="__HTML_DIR__" class="scroll-smooth h-full overflow-y-auto">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <script src="https://cdn.tailwindcss.com/3.4.17?plugins=forms@0.5.9,typography@0.5.15,aspect-ratio@0.4.2"><\/script>
7
+ <style>
8
+ html { height: 100%; overflow:auto; }
9
+ body { height: 100%; }
10
+ .air-highlight{ outline: 1px solid #42a1fc !important; outline-offset: -1px;}
11
+ .air-highlight-multi{ outline: 1px solid #29e503 !important; outline-offset: -1px;}
12
+ body{ -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none;
13
+ -moz-user-select: none;-ms-user-select: none; user-select: none; }
14
+ html{
15
+ -ms-overflow-style: none; /* IE and Edge */
16
+ scrollbar-width: none; /* Firefox */
17
+ }
18
+ /** IMPORTANT: Make fields content editable in SAFARI */
19
+ [contenteditable] {-webkit-user-select: text;user-select: text;}
20
+
21
+ html::-webkit-scrollbar { width: 0 !important }
22
+ .aspect-auto{aspect-ratio: auto;}
23
+ .aspect-square{aspect-ratio: 1/1;}
24
+ .aspect-video{aspect-ratio: 16/9;}
25
+ .dragging [data-dnd="leaf"] { pointer-events: none; } .dragging [data-dnd="leaf"] * { pointer-events: none; }
26
+ .dragging [data-dnd="ignore"], .dragging [data-dnd="ignore"] * { pointer-events: none; }
27
+ a{ pointer-events: none !important; }
28
+ [contenteditable="true"], [contenteditable="true"] * { cursor: text !important; }
29
+ [contenteditable="true"] {
30
+ outline: none;
31
+ box-shadow: 0 0 0px 4px rgba(36, 150, 255, 0.2);
32
+ -webkit-user-select: text;
33
+ -moz-user-select: text;
34
+ user-select: text;
35
+ }
36
+ .frame-root .frame-content { height: 100%; }
37
+ [data-drop="yes"] { outline: 2px dashed orange !important; outline-offset: -2px }
38
+ [data-dnd="yes"] { pointer-events: auto !important}
39
+ [data-dnd="no"],[data-block-type="GlobalBlock"],[data-block-type="PartialBlock"] > * { pointer-events: none !important; }
40
+ [data-block-type="GlobalBlock"],[data-block-type="PartialBlock"] { position: relative !important; }
41
+ .partial-overlay { pointer-events: auto !important; }
42
+ [data-dnd-dragged="yes"] { opacity: 0.6; pointer-events: none; }
43
+ [data-dnd-dragged="no"] { opacity: 1; pointer-events: auto !important; }
44
+ [force-show] { display: block !important; }
45
+ [data-cut-block="yes"] { pointer-events: none !important; display: none !important; }
46
+ </style>
47
+ <style id="highlighted-block">
48
+ [data-highlighted]{
49
+ outline: 1px solid #42a1fc !important; outline-offset: -1px;
50
+ }
51
+ </style>
52
+ <style>
53
+ .react-colorful {
54
+ height: 120px !important;
55
+ width: 180px !important;
56
+ }
57
+ .react-colorful > div {
58
+ margin-bottom: 4px;
59
+ }
60
+ .react-colorful__saturation {
61
+ border-radius: 4px !important;
62
+ }
63
+ .react-colorful__hue,
64
+ .react-colorful__alpha {
65
+ height: 12px !important;
66
+ border-radius: 4px !important;
67
+ }
68
+ .react-colorful__pointer {
69
+ width: 16px !important;
70
+ height: 16px !important;
71
+ border: 1.5px solid #fff !important;
72
+ cursor: pointer !important;
73
+ z-index: 10002 !important;
74
+ }
75
+ #active-inline-editing-element{outline: 2px solid #00c951;}
76
+ </style>
77
+ <style type="text/tailwindcss">
78
+ @layer utilities {
79
+ .rte {
80
+ h1 {
81
+ @apply text-2xl;
82
+ }
83
+ h2 {
84
+ @apply text-xl;
85
+ }
86
+ h3 {
87
+ @apply text-lg;
88
+ }
89
+ h4 {
90
+ @apply text-base;
91
+ }
92
+ h5 {
93
+ @apply text-sm;
94
+ }
95
+ h6 {
96
+ @apply text-xs;
97
+ }
98
+ p {
99
+ &:empty {
100
+ @apply h-4;
101
+ }
102
+ }
103
+ ul {
104
+ @apply list-disc pl-6 text-base;
105
+ }
106
+ ol {
107
+ @apply list-decimal pl-6 text-base;
108
+ }
109
+ li > p {
110
+ @apply m-0;
111
+ }
112
+ blockquote {
113
+ @apply pl-4 text-base;
114
+ p {
115
+ @apply pl-4 text-base;
116
+ }
117
+ }
118
+ }
119
+ }
120
+ </style>
121
+ </head>
122
+ <body class="font-body antialiased h-full">
123
+ <div class="frame-root h-full"></div>
124
+ </body>
125
+ </html>`;class vp extends g.Component{componentDidMount(){this.props.contentDidMount()}componentDidUpdate(){this.props.contentDidUpdate()}render(){return g.Children.only(this.props.children)}}class Na extends g.Component{constructor(n,s){super(n,s);kt(this,"setRef",n=>{this.nodeRef.current=n;const{forwardedRef:s}=this.props;typeof s=="function"?s(n):s&&(s.current=n)});kt(this,"handleLoad",()=>{clearInterval(this.loadCheck),this.state.iframeLoaded||this.setState({iframeLoaded:!0})});kt(this,"loadCheck",()=>setInterval(()=>{this.handleLoad()},500));this._isMounted=!1,this.nodeRef=g.createRef(),this.state={iframeLoaded:!1}}componentDidMount(){this._isMounted=!0,this.getDoc()&&this.nodeRef.current.contentWindow.addEventListener("DOMContentLoaded",this.handleLoad)}componentWillUnmount(){this._isMounted=!1,this.nodeRef.current.removeEventListener("DOMContentLoaded",this.handleLoad)}getDoc(){return this.nodeRef.current?this.nodeRef.current.contentDocument:null}getMountTarget(){const n=this.getDoc();return this.props.mountTarget?n.querySelector(this.props.mountTarget):n.body.children[0]}renderFrameContents(){if(!this._isMounted)return null;const n=this.getDoc();if(!n)return null;const s=this.props.contentDidMount,o=this.props.contentDidUpdate,r=n.defaultView||n.parentView,a=i.jsx(vp,{contentDidMount:s,contentDidUpdate:o,children:i.jsx(tp,{value:{document:n,window:r},children:i.jsx("div",{className:"frame-content",children:this.props.children})})}),l=this.getMountTarget();return[cr.createPortal(this.props.head,this.getDoc().head),cr.createPortal(a,l)]}render(){const n={...this.props,srcDoc:this.props.initialContent,children:void 0};return delete n.head,delete n.initialContent,delete n.mountTarget,delete n.contentDidMount,delete n.contentDidUpdate,delete n.forwardedRef,i.jsx("iframe",{...n,ref:this.setRef,onLoad:this.handleLoad,children:this.state.iframeLoaded&&this.renderFrameContents()})}}kt(Na,"defaultProps",{style:{},head:null,children:void 0,mountTarget:void 0,contentDidMount:()=>{},contentDidUpdate:()=>{},initialContent:'<!DOCTYPE html><html><head></head><body><div class="frame-root"></div></body></html>'});const wp=g.forwardRef((t,e)=>i.jsx(Na,{...t,forwardedRef:e})),Ea=S.atom([]),Is=()=>{const[t,e]=S.useAtom(Ea),n=S.useSetAtom(Aa),s=g.useCallback(o=>{e(o),n([])},[e,n]);return[t,s]},Aa=S.atom([]),_a=()=>{const[t]=Z(),[e,n]=S.useAtom(Aa),s=S.useSetAtom(Ea),{getPartialBlocks:o}=Vr(),r=$("flags.copyPaste",!0),a=g.useCallback(c=>c.some(u=>ur(t,u,null).some(f=>f._type==="PartialBlock"||f._type==="GlobalBlock")),[t]),l=g.useCallback(async(c,u=!1)=>{try{if(d.isEmpty(c))return;n(c),s([]);const p={_chai_copied_blocks:c.flatMap(f=>{const h=ur(t,f,null);if(!u)return h;let m=[];for(const x of h)if(x._type==="PartialBlock"||x._type==="GlobalBlock"){let b=o(x.partialBlockId);x._parent&&(b==null?void 0:b.length)>0&&(b=b.map(y=>(d.isEmpty(y._parent)&&d.set(y,"_parent",x._parent),y))),m=[...m,...b]}else m.push(x);return m})};if(!r)return;if(!navigator.clipboard){le.toast.error("Clipboard not available.");return}le.toast.promise(navigator.clipboard.writeText(JSON.stringify(p)),{success:"Blocks copied successfully",error:"Failed to copy blocks to clipboard"})}catch(p){le.toast.error("Failed to copy blocks to clipboard"),console.error("Failed to copy blocks to clipboard:",p)}},[n,s,t]);return[e,l,a]},Ys=()=>navigator.userAgent.toLowerCase().includes("firefox"),Cp=()=>{const[t]=Z();return(e,n)=>{var r;const s=((r=d.find(t,{_id:n}))==null?void 0:r._type)||null,o=d.first(e.map(a=>{var l;return(l=d.find(t,{_id:a}))==null?void 0:l._type}));return Qe(s,o)}},jp=()=>{const t=S.useAtomValue(Ne),{moveBlocks:e}=Ee();return g.useCallback((n,s)=>{const o=Array.isArray(s)?s[0]:s;if(s==="root"){const r=t==null?void 0:t.filter(a=>!a._parent);e(n,void 0,(r==null?void 0:r.length)||0)}else{const r=t==null?void 0:t.filter(a=>a._parent===o);e(n,o,(r==null?void 0:r.length)||0)}},[e,t])},eo=()=>{const[t,e]=Is(),n=jp(),{addPredefinedBlock:s}=bt(),o=Cp();return{canPaste:g.useCallback(async a=>{if(t.length>0)return o(t,a);if(Ys())return!1;try{const l=await navigator.clipboard.readText();if(l){const c=JSON.parse(l);return d.has(c,"_chai_copied_blocks")}}catch{return!1}return!1},[o,t]),pasteBlocks:g.useCallback(async a=>{const l=Array.isArray(a)?a[0]:a;if(!d.isEmpty(t)){n(t,a),e([]),Ys()||await navigator.clipboard.writeText("");return}if(Ys()){le.toast.error("Paste is not supported in Firefox");return}if(!(navigator!=null&&navigator.permissions)){le.toast.error("Cannot check clipboard permissions.");return}try{if((await navigator.permissions.query({name:"clipboard-read"})).state==="denied"){le.toast.error("Clipboard paste permission denied. Please allow clipboard access.");return}}catch{le.toast.error("Failed to check clipboard permissions. Please allow clipboard access.");return}le.toast.promise(async()=>{const c=await navigator.clipboard.readText();if(c){const u=JSON.parse(c);if(d.has(u,"_chai_copied_blocks"))s(u._chai_copied_blocks,l==="root"?null:l);else throw new Error("Nothing to paste")}else throw new Error("Nothing to paste")},{success:()=>"Blocks pasted successfully",error:()=>"Nothing to paste"})},[t,n,e,s])}},Ia=t=>{const[e,n]=q(),s=J(),o=Ns(),r=Zr(),{undo:a,redo:l}=En(),[,c]=Is(),[,u]=_a(),{canPaste:p,pasteBlocks:f}=eo(),h=t?{document:t}:{};rt.useHotkeys("ctrl+z,meta+z",m=>{m.preventDefault(),qe.hasUndo()&&a()},{...h,preventDefault:!0},[a]),rt.useHotkeys("ctrl+y,meta+y",m=>{m.preventDefault(),qe.hasRedo()&&l()},{...h,preventDefault:!0},[l]),rt.useHotkeys("ctrl+x,meta+x",m=>{const x=window.getSelection();x&&x.toString().length>0||(m.preventDefault(),d.isEmpty(e)||c(e))},{...h,enabled:!d.isEmpty(e)},[e,c]),rt.useHotkeys("ctrl+c,meta+c",m=>{const x=window.getSelection();x&&x.toString().length>0||(m.preventDefault(),u(e))},{...h,enabled:!d.isEmpty(e)},[e,u]),rt.useHotkeys("ctrl+v,meta+v",async()=>{await p(e[0])&&f(e)},{...h,enabled:!d.isEmpty(e),preventDefault:!0},[e,p,f]),rt.useHotkeys("esc",()=>n([]),h,[n]),rt.useHotkeys("ctrl+d,meta+d",()=>r(e),{...h,enabled:!d.isEmpty(e),preventDefault:!0},[e,r]),rt.useHotkeys("del, backspace",m=>{m.preventDefault(),Tr(d.get(s,"_type",""))&&o(e)},h,[e,o])},Sp=()=>{const{document:t}=tt();return Ia(t),null},Np=()=>{const{t}=z.useTranslation(),{hasPermission:e}=Ge(),n=e(be.ADD_BLOCK),s=Ye();return n?i.jsxs("div",{id:"add-block-bottom",className:"group relative w-full cursor-pointer py-2",children:[i.jsx("br",{}),!s&&i.jsx("div",{role:"button",onClick:()=>oe.publish(Y.OPEN_ADD_BLOCK),className:"block h-1 rounded bg-primary opacity-0 duration-200 group-hover:opacity-100",children:i.jsxs("div",{className:"absolute left-1/2 flex -translate-x-1/2 -translate-y-1/2 transform items-center gap-x-1 rounded-full bg-primary px-3 py-1 text-xs leading-tight text-white hover:bg-primary",children:[i.jsx(w.PlusIcon,{className:"size-2.5 stroke-[3]"})," ",t("Add block")]})}),i.jsx("br",{}),i.jsx("br",{}),i.jsx("br",{}),i.jsx("br",{})]}):null},Ta=({theme:t})=>{const e=g.useMemo(()=>Xe.getChaiThemeCssVariables({theme:t}),[t]);return i.jsx("style",{id:"chai-theme",dangerouslySetInnerHTML:{__html:e}})},Ba=He.atomWithStorage("darkMode",!1),In=()=>{const[t,e]=S.useAtom(Ba);return[t,e]},Ep=(t=Xe.defaultThemeOptions)=>{const e=Xe.defaultThemeValues;return t.fontFamily&&(e.fontFamily=Object.entries(t.fontFamily).reduce((n,[s,o])=>({...n,[s.replace("font-","")]:o}),e.fontFamily)),e.borderRadius=t.borderRadius,t.colors&&(e.colors=t.colors.reduce((n,s)=>(Object.entries(s.items).forEach(([o,r])=>{o in n&&(n[o]=r)}),n),e.colors)),e},Ra=S.atom({}),Ts=()=>{const t=Tn(),e=g.useMemo(()=>Ep(t),[t]),n=$("theme",{}),[s,o]=S.useAtom(Ra);return[g.useMemo(()=>({...e,...!d.isEmpty(n)&&n,...!d.isEmpty(s)&&s}),[e,n,s]),o]},Tn=()=>{const t=$("themeOptions",n=>n);return g.useMemo(()=>t(Xe.defaultThemeOptions),[t])},Ap=S.atom("block"),Pa=()=>S.useAtom(Ap),_p=S.atom("settings"),La=()=>S.useAtom(_p),Ip=()=>{const[t]=Ts(),e=Tn(),[n]=In(),{document:s,window:o}=tt();return g.useEffect(()=>{n?s==null||s.documentElement.classList.add("dark"):s==null||s.documentElement.classList.remove("dark")},[n,s]),g.useEffect(()=>{!o||!o.tailwind||(o.tailwind.config={darkMode:"class",theme:{extend:{container:{center:!0,padding:"1rem",screens:{"2xl":"1400px"}},...Xe.getChaiThemeOptions(e)}},plugins:[vd,kd,bd,yd,Xe.plugin(function({addBase:r,theme:a}){r({"h1,h2,h3,h4,h5,h6":{fontFamily:a("fontFamily.heading")},body:{fontFamily:a("fontFamily.body"),color:a("colors.foreground"),backgroundColor:a("colors.background")}})})]})},[t,e,o]),i.jsxs(i.Fragment,{children:[i.jsx(Ta,{theme:t}),i.jsx(Rp,{}),i.jsx(Bp,{}),i.jsx(Tp,{})]})},Tp=()=>{const[t]=Ae(),[e]=q(),n=g.useMemo(()=>`${d.map(t,({id:s})=>`[data-style-id="${s}"]`).join(",")}{
126
+ outline: 1px solid ${e.length>0?"#42a1fc":"#de8f09"} !important; outline-offset: -1px;
127
+ }`,[t,e]);return i.jsx("style",{id:"selected-styling-blocks",dangerouslySetInnerHTML:{__html:n}})},Bp=()=>{const[t]=q(),e=g.useMemo(()=>`${d.map(t,n=>`[data-block-id="${n}"]`).join(",")}{
128
+ outline: 1px solid #42a1fc !important; outline-offset: -1px;
129
+ }`,[t]);return i.jsx("style",{id:"selected-blocks",dangerouslySetInnerHTML:{__html:e}})},Rp=()=>{const[t]=Ts(),e=Nr.useRegisteredFonts(),n=g.useMemo(()=>{const{heading:r,body:a}={heading:d.get(t,"fontFamily.heading"),body:d.get(t,"fontFamily.body")};return e.filter(l=>l.family===r||l.family===a)},[t==null?void 0:t.fontFamily,e]),s=g.useMemo(()=>Xe.getThemeFontsUrls(d.filter(n,r=>d.has(r,"url"))),[n]),o=g.useMemo(()=>Xe.getThemeCustomFontFace(d.filter(n,r=>d.has(r,"src"))),[n]);return i.jsxs(i.Fragment,{children:[s.map((r,a)=>i.jsx("link",{rel:"stylesheet",href:r},`google-font-${a}`)),i.jsx("style",{id:"chai-custom-fonts",dangerouslySetInnerHTML:{__html:o}})]})},Pp=({children:t,onMount:e,onResize:n})=>{const[,s]=q(),[,o]=Ae(),r=g.useRef(null),a=xe.useDebouncedCallback(()=>{const{clientWidth:c}=r.current;n(c)},[r.current],100);xe.useResizeObserver(r.current,a,r.current!==null),g.useEffect(()=>{const{clientWidth:c}=r.current;e(c)},[]);const l=g.useCallback(()=>{s([]),o([])},[s,o]);return i.jsx("div",{id:"main-content",onClick:l,className:"h-full w-full border-l-4 border-r-4 pb-0",ref:r,children:t})},Lp=()=>{const[,t]=q(),{onDragStart:e,onDragEnd:n}=nn(),[s]=Z(),o=g.useRef(null),[r,a]=S.useAtom(lp),[l,c]=S.useAtom(Ca),u=g.useCallback(h=>{var k;if(h.button!==0)return;const m=Date.now(),x=m-r;if(x<400&&x>0){c(2);return}a(m);const y=(k=h.target.closest("[data-block-id]"))==null?void 0:k.getAttribute("data-block-id");y&&(t([y]),o.current=y)},[t,r,a,l,c]),p=g.useCallback(h=>{if(!o.current)return;const m=d.find(s,{_id:o.current});m&&e(h,m,!1)},[s,e]),f=g.useCallback(()=>{n(),o.current=null},[n]);return{onMouseDown:u,onDragStart:p,onDragEnd:f}},Dp=()=>{const[t]=Z();return g.useCallback((e,n)=>d.isEmpty(n)?{}:Object.entries(n).reduce((s,[o,r])=>{const a=[];let l=d.find(t,{_id:e});for(;l;)a.push(l),l=d.find(t,{_id:l._parent});const c=d.find(a,{_type:r.block});return c&&(s[o]=d.get(c,d.get(r,"prop"),null)),s},{}),[t])},Mp=S.atom("edit"),Da=()=>{const[t,e]=S.useAtom(Mp);return{mode:t,setMode:e}},Op=({children:t,block:e})=>{const n=g.useMemo(()=>K.getRegisteredChaiBlock(e._type),[e._type]),s=d.get(n,"dataProviderDependencies"),o=d.get(n,"dataProvider"),r=d.get(n,"dataProviderMode","mock"),a=$d(e,r,s,o);return t(a)},$p=()=>i.jsx("div",{className:"flex min-h-[100px] items-center justify-center bg-red-50 p-2 text-center text-red-500",children:"Something went wrong."});function me(...t){return Di.twMerge(Li.clsx(t))}const hr=({editor:t,trigger:e,content:n,from:s,menuRef:o})=>{const{document:r}=tt(),[a,l]=g.useState({left:void 0,right:void 0,top:void 0,bottom:void 0}),[c,u]=g.useState(!1),p=g.useRef(null);if(g.useEffect(()=>{var k,C;if(!c){l({left:void 0,right:void 0,top:void 0,bottom:void 0});return}const f=(k=p.current)==null?void 0:k.getBoundingClientRect();if(!f||!r)return;const h=(C=o.current)==null?void 0:C.getBoundingClientRect();if(!h)return;let m=f.left,x=f.bottom+4,b,y;(h==null?void 0:h.left)+(h==null?void 0:h.width)+50>=r.body.offsetWidth&&(m=void 0,b=r.body.offsetWidth-(f==null?void 0:f.right)),x+202>=r.body.clientHeight&&(x=void 0,y=r.body.clientHeight-f.bottom+h.height),l({left:m,top:x,right:b,bottom:y})},[c]),s==="canvas"){const f=()=>{u(!1),t&&(t==null||t.view.focus(),t==null||t.chain().focus().run())};return i.jsxs(i.Fragment,{children:[i.jsx("div",{ref:p,onClick:()=>u(h=>!h),className:"cursor-pointer",children:e}),c&&(a.left!==void 0||a.top!==void 0||a.right!==void 0||a.bottom!==void 0)&&cr.createPortal(i.jsx("div",{id:"chaibuilder-rte-dropdown-menu-content",onClick:f,className:"fixed inset-0 left-0 top-0 z-[10001] h-full w-screen",children:i.jsx("div",{onClick:h=>h.stopPropagation(),className:"absolute rounded-md border border-gray-500 bg-white p-1.5 text-xs shadow-2xl",style:Object.assign({},{left:a.left,top:a.top,right:a.right,bottom:a.bottom}),children:typeof n=="function"?n(f):n})}),r.body,"chaibuilder-rte-dropdown-menu")]})}return i.jsx(i.Fragment,{children:i.jsxs(gt,{open:c,onOpenChange:u,children:[i.jsx(xt,{className:"relative outline-none",asChild:!0,children:e}),i.jsx(Ze,{className:"z-50 rounded-md border bg-white p-1 text-xs shadow-xl",children:c&&(typeof n=="function"?n(()=>u(!1)):n)})]})})},Fp=(t,e,n)=>{const s=n==="settings",o=typeof e=="boolean"?e:e.some(r=>t.isActive(r));return{"rounded p-1":!0,"hover:bg-blue-900 hover:text-blue-100":!o&&!s,"hover:bg-blue-100 hover:text-blue-900":!o&&s,"bg-blue-500 text-white":o&&s,"bg-white text-blue-500":o&&!s}},Ko=({themeColors:t,onClose:e,color:n,onChange:s,onRemove:o})=>i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"flex w-[180px] flex-wrap gap-1 pb-2",children:(t==null?void 0:t.length)>0&&d.uniq(t).map(r=>{var a;return i.jsx("button",{className:me("h-4 w-4 cursor-pointer rounded-full border border-gray-900 shadow duration-200 hover:scale-105 hover:shadow-xl",{"border-2":r===n}),style:{backgroundColor:r},onClick:()=>{s(r),e()},title:(a=r||"#000000")==null?void 0:a.toUpperCase()},r)})}),i.jsx(od.HexAlphaColorPicker,{color:n,onChange:s,style:{width:"200px",height:"200px"}}),i.jsxs("div",{className:"mt-1 flex items-center justify-between gap-1",children:[i.jsx(T.Input,{type:"text",value:n||"#000000f2",onChange:r=>s(r.target.value,!0),className:"!h-5 !w-[105px] rounded-sm !p-0 text-center font-light uppercase text-gray-600 outline-none ring-0 focus:ring-0",placeholder:"#000000"}),i.jsxs("button",{className:"flex h-4 w-max cursor-pointer items-center gap-x-1 rounded-full bg-transparent px-1 text-red-600 shadow-none duration-200 hover:bg-red-100",onClick:()=>{o(),e()},title:"Remove",children:[i.jsx(w.Cross1Icon,{className:"h-3 w-3"})," Remove"]})]})]}),zp=({textColor:t,highlightColor:e,onChangeTextColor:n,onChangeHighlightColor:s,onRemoveTextColor:o,onRemoveHighlightColor:r,onClose:a})=>{const[l]=In(),[c]=S.useAtom(Tu),u=(c==null?void 0:c.colors)||{},p=Object.values(u).map(m=>d.get(m,l?"1":"0")),[f,h]=g.useState("TEXT");return i.jsxs("div",{id:"rte-widget-color-picker",className:"px-1",children:[i.jsxs("div",{className:"mb-2 flex items-center justify-between rounded-md border bg-muted",children:[i.jsx("div",{className:`w-full cursor-pointer rounded p-0.5 text-center ${f==="TEXT"?"bg-blue-500 text-white":"hover:bg-blue-100 hover:text-blue-500"}`,onClick:()=>h("TEXT"),children:"Text Color"}),i.jsx("div",{className:`w-full cursor-pointer rounded p-0.5 text-center ${f==="HIGHLIGHT"?"bg-blue-500 text-white":"hover:bg-blue-100 hover:text-blue-500"}`,onClick:()=>h("HIGHLIGHT"),children:"Highlight Color"})]}),f==="TEXT"?i.jsx(Ko,{themeColors:p,onClose:a,onChange:n,color:t,onRemove:o}):i.jsx(Ko,{themeColors:p,onClose:a,onChange:s,color:e,onRemove:r})]})},Hp=({editor:t,from:e,menuRef:n})=>{var C,A;const s=(C=t==null?void 0:t.getAttributes("textStyle"))==null?void 0:C.color,o=(A=t==null?void 0:t.getAttributes("highlight"))==null?void 0:A.color,[r,a]=g.useState(s||"#000000F2"),[l,c]=g.useState(o||"#00000057"),[u,p]=xe.useDebouncedState(r,150),[f,h]=xe.useDebouncedState(l,150),m=(v,j)=>{j?(a(v),p(v)):(t==null||t.chain().setColor(v).run(),a(v))},x=(v,j)=>{j?(c(v),h(v)):(t==null||t.chain().setHighlight({color:v}).run(),c(v))},b=()=>{t==null||t.chain().unsetColor().run(),a("#000000F2")},y=()=>{t==null||t.chain().unsetHighlight().run()};g.useEffect(()=>{o&&c(o)},[o]),g.useEffect(()=>{f!=null&&f.includes("#")&&(f==null?void 0:f.length)>=3&&(t==null||t.chain().setHighlight({color:f}).run())},[f]),g.useEffect(()=>{u!=null&&u.includes("#")&&(u==null?void 0:u.length)>=3&&(t==null||t.chain().setColor(u).run())},[u]);const k=!!s;return i.jsx(hr,{editor:t,from:e,menuRef:n,trigger:i.jsxs("div",{className:me("relative flex items-center",Fp(t,k,e)),title:"Text Color",children:[i.jsx("div",{className:"h-4 w-4 rounded-full",style:{backgroundColor:s||(e==="canvas"?"#FFFFFF":"#000000")}}),i.jsx(w.CaretDownIcon,{className:"h-3 w-3 opacity-50"})]}),content:v=>i.jsx(zp,{textColor:r,highlightColor:l,onChangeTextColor:m,onChangeHighlightColor:x,onRemoveTextColor:b,onRemoveHighlightColor:y,onClose:v})})},Le=(t,e,n)=>{const s=n==="settings",o=typeof e=="boolean"?e:e.some(r=>t.isActive(r));return{"rounded p-1":!0,"hover:bg-blue-900 hover:text-blue-100":!o&&!s,"hover:bg-blue-100 hover:text-blue-900":!o&&s,"bg-blue-500 text-white":o&&s,"bg-white text-blue-500":o&&!s}},Ma=({editor:t,from:e="settings",onExpand:n})=>{const s=g.useRef(null);if(!t)return null;const o=()=>{const a=window.prompt("URL");a&&t.chain().focus().extendMarkRange("link").setLink({href:a}).run()},r=()=>{t.chain().focus().unsetLink().run()};return i.jsxs("div",{ref:s,id:"chai-rich-text-menu-bar",className:me("mb-1 flex flex-wrap gap-0.5 rounded-t-md border-b border-border bg-gray-50 p-1",{"mb-0 rounded-md border-none bg-blue-500 text-white":e==="canvas"}),children:[i.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleBold().run(),className:me("",Le(t,["bold"],e)),title:"Bold",children:i.jsx(w.FontBoldIcon,{className:"h-4 w-4"})}),i.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleItalic().run(),className:me("",Le(t,["italic"],e)),title:"Italic",children:i.jsx(w.FontItalicIcon,{className:"h-4 w-4"})}),i.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleUnderline().run(),className:me("",Le(t,["underline"],e)),title:"Underline",children:i.jsx(w.UnderlineIcon,{className:"h-4 w-4"})}),i.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleStrike().run(),className:me("",Le(t,["strike"],e)),title:"Strike",children:i.jsx(w.StrikethroughIcon,{className:"h-4 w-4"})}),i.jsx("div",{className:"mx-1 h-5 w-px self-center bg-border"}),i.jsx(Hp,{editor:t,from:e,menuRef:s}),i.jsx("div",{className:"mx-1 h-5 w-px self-center bg-border"}),i.jsx(hr,{editor:t,menuRef:s,from:e,trigger:i.jsxs("button",{type:"button",className:me("flex items-center",Le(t,["bulletList","orderedList"],e)),title:"Bullet List",children:[i.jsx(w.ListBulletIcon,{className:"h-4 w-4"}),i.jsx(w.CaretDownIcon,{className:"h-3 w-3 opacity-50"})]}),content:a=>i.jsxs(i.Fragment,{children:[i.jsxs("div",{onClick:()=>{t.chain().focus().toggleBulletList().run(),a()},className:me("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,["bulletList"],e)),children:[i.jsx(w.ListBulletIcon,{className:"h-4 w-4"})," Unordered List"]}),i.jsxs("div",{onClick:()=>{t.chain().focus().toggleOrderedList().run(),a()},className:me("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,["orderedList"],e)),children:[i.jsx(w.ValueIcon,{className:"h-4 w-4"}),"Ordered List"]})]})}),i.jsx(hr,{editor:t,menuRef:s,from:e,trigger:i.jsxs("button",{type:"button",className:me("flex items-center",Le(t,t.isActive({textAlign:"center"})||t.isActive({textAlign:"right"}),e)),title:"Text Alignment",children:[t.isActive({textAlign:"center"})?i.jsx(w.TextAlignCenterIcon,{className:"h-4 w-4"}):t.isActive({textAlign:"right"})?i.jsx(w.TextAlignRightIcon,{className:"h-4 w-4"}):i.jsx(w.TextAlignLeftIcon,{className:"h-4 w-4"}),i.jsx(w.CaretDownIcon,{className:"h-3 w-3 opacity-50"})]}),content:a=>i.jsxs(i.Fragment,{children:[i.jsxs("div",{onClick:()=>{t.chain().focus().setTextAlign("left").run(),a()},className:me("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,t.isActive({textAlign:"left"}),e)),children:[i.jsx(w.TextAlignLeftIcon,{className:"h-4 w-4"})," Align Left"]}),i.jsxs("div",{onClick:()=>{t.chain().focus().setTextAlign("center").run(),a()},className:me("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,t.isActive({textAlign:"center"}),e)),children:[i.jsx(w.TextAlignCenterIcon,{className:"h-4 w-4"})," Align Center"]}),i.jsxs("div",{onClick:()=>{t.chain().focus().setTextAlign("right").run(),a()},className:me("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,t.isActive({textAlign:"right"}),e)),children:[i.jsx(w.TextAlignRightIcon,{className:"h-4 w-4"})," Align Right"]})]})}),t.isActive("link")?i.jsx("button",{type:"button",onClick:r,className:me("",Le(t,["link"],e)),title:"Remove Link",disabled:!t.isActive("link"),children:i.jsx(w.LinkBreak2Icon,{className:"h-3.5 w-3.5"})}):i.jsx("button",{type:"button",onClick:o,className:me("",Le(t,["link"],e)),title:"Add Link",children:i.jsx(w.Link2Icon,{className:"h-3.5 w-3.5"})}),n&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"mx-1 h-5 w-px self-center bg-border"}),i.jsx("button",{type:"button",onClick:n,className:me("",Le(t,!1,e)),title:"Open in full screen mode",children:i.jsx(w.EnterFullScreenIcon,{className:"h-3.5 w-3.5"})})]})]})};function je(t){this.content=t}je.prototype={constructor:je,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return e==-1?void 0:this.content[e+1]},update:function(t,e,n){var s=n&&n!=t?this.remove(n):this,o=s.find(t),r=s.content.slice();return o==-1?r.push(n||t,e):(r[o+1]=e,n&&(r[o]=n)),new je(r)},remove:function(t){var e=this.find(t);if(e==-1)return this;var n=this.content.slice();return n.splice(e,2),new je(n)},addToStart:function(t,e){return new je([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var n=this.remove(t).content.slice();return n.push(t,e),new je(n)},addBefore:function(t,e,n){var s=this.remove(e),o=s.content.slice(),r=s.find(t);return o.splice(r==-1?o.length:r,0,e,n),new je(o)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+1])},prepend:function(t){return t=je.from(t),t.size?new je(t.content.concat(this.subtract(t).content)):this},append:function(t){return t=je.from(t),t.size?new je(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=je.from(t);for(var n=0;n<t.content.length;n+=2)e=e.remove(t.content[n]);return e},toObject:function(){var t={};return this.forEach(function(e,n){t[e]=n}),t},get size(){return this.content.length>>1}};je.from=function(t){if(t instanceof je)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new je(e)};function Oa(t,e,n){for(let s=0;;s++){if(s==t.childCount||s==e.childCount)return t.childCount==e.childCount?null:n;let o=t.child(s),r=e.child(s);if(o==r){n+=o.nodeSize;continue}if(!o.sameMarkup(r))return n;if(o.isText&&o.text!=r.text){for(let a=0;o.text[a]==r.text[a];a++)n++;return n}if(o.content.size||r.content.size){let a=Oa(o.content,r.content,n+1);if(a!=null)return a}n+=o.nodeSize}}function $a(t,e,n,s){for(let o=t.childCount,r=e.childCount;;){if(o==0||r==0)return o==r?null:{a:n,b:s};let a=t.child(--o),l=e.child(--r),c=a.nodeSize;if(a==l){n-=c,s-=c;continue}if(!a.sameMarkup(l))return{a:n,b:s};if(a.isText&&a.text!=l.text){let u=0,p=Math.min(a.text.length,l.text.length);for(;u<p&&a.text[a.text.length-u-1]==l.text[l.text.length-u-1];)u++,n--,s--;return{a:n,b:s}}if(a.content.size||l.content.size){let u=$a(a.content,l.content,n-1,s-1);if(u)return u}n-=c,s-=c}}class D{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let s=0;s<e.length;s++)this.size+=e[s].nodeSize}nodesBetween(e,n,s,o=0,r){for(let a=0,l=0;l<n;a++){let c=this.content[a],u=l+c.nodeSize;if(u>e&&s(c,o+l,r||null,a)!==!1&&c.content.size){let p=l+1;c.nodesBetween(Math.max(0,e-p),Math.min(c.content.size,n-p),s,o+p)}l=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,s,o){let r="",a=!0;return this.nodesBetween(e,n,(l,c)=>{let u=l.isText?l.text.slice(Math.max(e,c)-c,n-c):l.isLeaf?o?typeof o=="function"?o(l):o:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&u||l.isTextblock)&&s&&(a?a=!1:r+=s),r+=u},0),r}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,s=e.firstChild,o=this.content.slice(),r=0;for(n.isText&&n.sameMarkup(s)&&(o[o.length-1]=n.withText(n.text+s.text),r=1);r<e.content.length;r++)o.push(e.content[r]);return new D(o,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let s=[],o=0;if(n>e)for(let r=0,a=0;a<n;r++){let l=this.content[r],c=a+l.nodeSize;c>e&&((a<e||c>n)&&(l.isText?l=l.cut(Math.max(0,e-a),Math.min(l.text.length,n-a)):l=l.cut(Math.max(0,e-a-1),Math.min(l.content.size,n-a-1))),s.push(l),o+=l.nodeSize),a=c}return new D(s,o)}cutByIndex(e,n){return e==n?D.empty:e==0&&n==this.content.length?this:new D(this.content.slice(e,n))}replaceChild(e,n){let s=this.content[e];if(s==n)return this;let o=this.content.slice(),r=this.size+n.nodeSize-s.nodeSize;return o[e]=n,new D(o,r)}addToStart(e){return new D([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new D(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,s=0;n<this.content.length;n++){let o=this.content[n];e(o,s,n),s+=o.nodeSize}}findDiffStart(e,n=0){return Oa(this,e,n)}findDiffEnd(e,n=this.size,s=e.size){return $a(this,e,n,s)}findIndex(e){if(e==0)return Wn(0,e);if(e==this.size)return Wn(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,s=0;;n++){let o=this.child(n),r=s+o.nodeSize;if(r>=e)return r==e?Wn(n+1,r):Wn(n,s);s=r}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return D.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new D(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return D.empty;let n,s=0;for(let o=0;o<e.length;o++){let r=e[o];s+=r.nodeSize,o&&r.isText&&e[o-1].sameMarkup(r)?(n||(n=e.slice(0,o)),n[n.length-1]=r.withText(n[n.length-1].text+r.text)):n&&n.push(r)}return new D(n||e,s)}static from(e){if(!e)return D.empty;if(e instanceof D)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new D([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}D.empty=new D([],0);const Js={index:0,offset:0};function Wn(t,e){return Js.index=t,Js.offset=e,Js}function as(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let s=0;s<t.length;s++)if(!as(t[s],e[s]))return!1}else{for(let s in t)if(!(s in e)||!as(t[s],e[s]))return!1;for(let s in e)if(!(s in t))return!1}return!0}class Q{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,s=!1;for(let o=0;o<e.length;o++){let r=e[o];if(this.eq(r))return e;if(this.type.excludes(r.type))n||(n=e.slice(0,o));else{if(r.type.excludes(this.type))return e;!s&&r.type.rank>this.type.rank&&(n||(n=e.slice(0,o)),n.push(this),s=!0),n&&n.push(r)}}return n||(n=e.slice()),s||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&as(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let s=e.marks[n.type];if(!s)throw new RangeError(`There is no mark type ${n.type} in this schema`);let o=s.create(n.attrs);return s.checkAttrs(o.attrs),o}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let s=0;s<e.length;s++)if(!e[s].eq(n[s]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return Q.none;if(e instanceof Q)return[e];let n=e.slice();return n.sort((s,o)=>s.type.rank-o.type.rank),n}}Q.none=[];class ls extends Error{}class W{constructor(e,n,s){this.content=e,this.openStart=n,this.openEnd=s}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let s=za(this.content,e+this.openStart,n);return s&&new W(s,this.openStart,this.openEnd)}removeBetween(e,n){return new W(Fa(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return W.empty;let s=n.openStart||0,o=n.openEnd||0;if(typeof s!="number"||typeof o!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new W(D.fromJSON(e,n.content),s,o)}static maxOpen(e,n=!0){let s=0,o=0;for(let r=e.firstChild;r&&!r.isLeaf&&(n||!r.type.spec.isolating);r=r.firstChild)s++;for(let r=e.lastChild;r&&!r.isLeaf&&(n||!r.type.spec.isolating);r=r.lastChild)o++;return new W(e,s,o)}}W.empty=new W(D.empty,0,0);function Fa(t,e,n){let{index:s,offset:o}=t.findIndex(e),r=t.maybeChild(s),{index:a,offset:l}=t.findIndex(n);if(o==e||r.isText){if(l!=n&&!t.child(a).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(s!=a)throw new RangeError("Removing non-flat range");return t.replaceChild(s,r.copy(Fa(r.content,e-o-1,n-o-1)))}function za(t,e,n,s){let{index:o,offset:r}=t.findIndex(e),a=t.maybeChild(o);if(r==e||a.isText)return s&&!s.canReplace(o,o,n)?null:t.cut(0,e).append(n).append(t.cut(e));let l=za(a.content,e-r-1,n,a);return l&&t.replaceChild(o,a.copy(l))}function Vp(t,e,n){if(n.openStart>t.depth)throw new ls("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new ls("Inconsistent open depths");return Ha(t,e,n,0)}function Ha(t,e,n,s){let o=t.index(s),r=t.node(s);if(o==e.index(s)&&s<t.depth-n.openStart){let a=Ha(t,e,n,s+1);return r.copy(r.content.replaceChild(o,a))}else if(n.content.size)if(!n.openStart&&!n.openEnd&&t.depth==s&&e.depth==s){let a=t.parent,l=a.content;return _t(a,l.cut(0,t.parentOffset).append(n.content).append(l.cut(e.parentOffset)))}else{let{start:a,end:l}=Wp(n,t);return _t(r,Wa(t,a,l,e,s))}else return _t(r,cs(t,e,s))}function Va(t,e){if(!e.type.compatibleContent(t.type))throw new ls("Cannot join "+e.type.name+" onto "+t.type.name)}function mr(t,e,n){let s=t.node(n);return Va(s,e.node(n)),s}function At(t,e){let n=e.length-1;n>=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function hn(t,e,n,s){let o=(e||t).node(n),r=0,a=e?e.index(n):o.childCount;t&&(r=t.index(n),t.depth>n?r++:t.textOffset&&(At(t.nodeAfter,s),r++));for(let l=r;l<a;l++)At(o.child(l),s);e&&e.depth==n&&e.textOffset&&At(e.nodeBefore,s)}function _t(t,e){return t.type.checkContent(e),t.copy(e)}function Wa(t,e,n,s,o){let r=t.depth>o&&mr(t,e,o+1),a=s.depth>o&&mr(n,s,o+1),l=[];return hn(null,t,o,l),r&&a&&e.index(o)==n.index(o)?(Va(r,a),At(_t(r,Wa(t,e,n,s,o+1)),l)):(r&&At(_t(r,cs(t,e,o+1)),l),hn(e,n,o,l),a&&At(_t(a,cs(n,s,o+1)),l)),hn(s,null,o,l),new D(l)}function cs(t,e,n){let s=[];if(hn(null,t,n,s),t.depth>n){let o=mr(t,e,n+1);At(_t(o,cs(t,e,n+1)),s)}return hn(e,null,n,s),new D(s)}function Wp(t,e){let n=e.depth-t.openStart,o=e.node(n).copy(t.content);for(let r=n-1;r>=0;r--)o=e.node(r).copy(D.from(o));return{start:o.resolveNoCache(t.openStart+n),end:o.resolveNoCache(o.content.size-t.openEnd-n)}}class kn{constructor(e,n,s){this.pos=e,this.path=n,this.parentOffset=s,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let s=this.pos-this.path[this.path.length-1],o=e.child(n);return s?e.child(n).cut(s):o}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let s=this.path[n*3],o=n==0?0:this.path[n*3-1]+1;for(let r=0;r<e;r++)o+=s.child(r).nodeSize;return o}marks(){let e=this.parent,n=this.index();if(e.content.size==0)return Q.none;if(this.textOffset)return e.child(n).marks;let s=e.maybeChild(n-1),o=e.maybeChild(n);if(!s){let l=s;s=o,o=l}let r=s.marks;for(var a=0;a<r.length;a++)r[a].type.spec.inclusive===!1&&(!o||!r[a].isInSet(o.marks))&&(r=r[a--].removeFromSet(r));return r}marksAcross(e){let n=this.parent.maybeChild(this.index());if(!n||!n.isInline)return null;let s=n.marks,o=e.parent.maybeChild(e.index());for(var r=0;r<s.length;r++)s[r].type.spec.inclusive===!1&&(!o||!s[r].isInSet(o.marks))&&(s=s[r--].removeFromSet(s));return s}sharedDepth(e){for(let n=this.depth;n>0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos<this.pos)return e.blockRange(this);for(let s=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);s>=0;s--)if(e.pos<=this.end(s)&&(!n||n(this.node(s))))return new ds(this,e,s);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let n=1;n<=this.depth;n++)e+=(e?"/":"")+this.node(n).type.name+"_"+this.index(n-1);return e+":"+this.parentOffset}static resolve(e,n){if(!(n>=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let s=[],o=0,r=n;for(let a=e;;){let{index:l,offset:c}=a.content.findIndex(r),u=r-c;if(s.push(a,l,o+c),!u||(a=a.child(l),a.isText))break;r=u-1,o+=c+1}return new kn(n,s,r)}static resolveCached(e,n){let s=Yo.get(e);if(s)for(let r=0;r<s.elts.length;r++){let a=s.elts[r];if(a.pos==n)return a}else Yo.set(e,s=new Gp);let o=s.elts[s.i]=kn.resolve(e,n);return s.i=(s.i+1)%Up,o}}class Gp{constructor(){this.elts=[],this.i=0}}const Up=12,Yo=new WeakMap;class ds{constructor(e,n,s){this.$from=e,this.$to=n,this.depth=s}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const qp=Object.create(null);let It=class gr{constructor(e,n,s,o=Q.none){this.type=e,this.attrs=n,this.marks=o,this.content=s||D.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,n,s,o=0){this.content.nodesBetween(e,n,s,o,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,n,s,o){return this.content.textBetween(e,n,s,o)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,n,s){return this.type==e&&as(this.attrs,n||e.defaultAttrs||qp)&&Q.sameSet(this.marks,s||Q.none)}copy(e=null){return e==this.content?this:new gr(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new gr(this.type,this.attrs,this.content,e)}cut(e,n=this.content.size){return e==0&&n==this.content.size?this:this.copy(this.content.cut(e,n))}slice(e,n=this.content.size,s=!1){if(e==n)return W.empty;let o=this.resolve(e),r=this.resolve(n),a=s?0:o.sharedDepth(n),l=o.start(a),u=o.node(a).content.cut(o.pos-l,r.pos-l);return new W(u,o.depth-a,r.depth-a)}replace(e,n,s){return Vp(this.resolve(e),this.resolve(n),s)}nodeAt(e){for(let n=this;;){let{index:s,offset:o}=n.content.findIndex(e);if(n=n.maybeChild(s),!n)return null;if(o==e||n.isText)return n;e-=o+1}}childAfter(e){let{index:n,offset:s}=this.content.findIndex(e);return{node:this.content.maybeChild(n),index:n,offset:s}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:n,offset:s}=this.content.findIndex(e);if(s<e)return{node:this.content.child(n),index:n,offset:s};let o=this.content.child(n-1);return{node:o,index:n-1,offset:s-o.nodeSize}}resolve(e){return kn.resolveCached(this,e)}resolveNoCache(e){return kn.resolve(this,e)}rangeHasMark(e,n,s){let o=!1;return n>e&&this.nodesBetween(e,n,r=>(s.isInSet(r.marks)&&(o=!0),!o)),o}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Ga(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,s=D.empty,o=0,r=s.childCount){let a=this.contentMatchAt(e).matchFragment(s,o,r),l=a&&a.matchFragment(this.content,n);if(!l||!l.validEnd)return!1;for(let c=o;c<r;c++)if(!this.type.allowsMarks(s.child(c).marks))return!1;return!0}canReplaceWith(e,n,s,o){if(o&&!this.type.allowsMarks(o))return!1;let r=this.contentMatchAt(e).matchType(s),a=r&&r.matchFragment(this.content,n);return a?a.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=Q.none;for(let n=0;n<this.marks.length;n++){let s=this.marks[n];s.type.checkAttrs(s.attrs),e=s.addToSet(e)}if(!Q.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(n=>n.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let s;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");s=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,s)}let o=D.fromJSON(e,n.content),r=e.nodeType(n.type).create(n.attrs,o,s);return r.type.checkAttrs(r.attrs),r}};It.prototype.text=void 0;class us extends It{constructor(e,n,s,o){if(super(e,n,null,o),!s)throw new RangeError("Empty text nodes are not allowed");this.text=s}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Ga(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new us(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new us(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function Ga(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class Rt{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let s=new Kp(e,n);if(s.next==null)return Rt.empty;let o=Ua(s);s.next&&s.err("Unexpected trailing text");let r=tf(ef(o));return nf(r,s),r}matchType(e){for(let n=0;n<this.next.length;n++)if(this.next[n].type==e)return this.next[n].next;return null}matchFragment(e,n=0,s=e.childCount){let o=this;for(let r=n;o&&r<s;r++)o=o.matchType(e.child(r).type);return o}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:n}=this.next[e];if(!(n.isText||n.hasRequiredAttrs()))return n}return null}compatible(e){for(let n=0;n<this.next.length;n++)for(let s=0;s<e.next.length;s++)if(this.next[n].type==e.next[s].type)return!0;return!1}fillBefore(e,n=!1,s=0){let o=[this];function r(a,l){let c=a.matchFragment(e,s);if(c&&(!n||c.validEnd))return D.from(l.map(u=>u.createAndFill()));for(let u=0;u<a.next.length;u++){let{type:p,next:f}=a.next[u];if(!(p.isText||p.hasRequiredAttrs())&&o.indexOf(f)==-1){o.push(f);let h=r(f,l.concat(p));if(h)return h}}return null}return r(this,[])}findWrapping(e){for(let s=0;s<this.wrapCache.length;s+=2)if(this.wrapCache[s]==e)return this.wrapCache[s+1];let n=this.computeWrapping(e);return this.wrapCache.push(e,n),n}computeWrapping(e){let n=Object.create(null),s=[{match:this,type:null,via:null}];for(;s.length;){let o=s.shift(),r=o.match;if(r.matchType(e)){let a=[];for(let l=o;l.type;l=l.via)a.push(l.type);return a.reverse()}for(let a=0;a<r.next.length;a++){let{type:l,next:c}=r.next[a];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in n)&&(!o.type||c.validEnd)&&(s.push({match:l.contentMatch,type:l,via:o}),n[l.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(s){e.push(s);for(let o=0;o<s.next.length;o++)e.indexOf(s.next[o].next)==-1&&n(s.next[o].next)}return n(this),e.map((s,o)=>{let r=o+(s.validEnd?"*":" ")+" ";for(let a=0;a<s.next.length;a++)r+=(a?", ":"")+s.next[a].type.name+"->"+e.indexOf(s.next[a].next);return r}).join(`
130
+ `)}}Rt.empty=new Rt(!0);class Kp{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function Ua(t){let e=[];do e.push(Yp(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Yp(t){let e=[];do e.push(Jp(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Jp(t){let e=Qp(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=Xp(t,e);else break;return e}function Jo(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function Xp(t,e){let n=Jo(t),s=n;return t.eat(",")&&(t.next!="}"?s=Jo(t):s=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:s,expr:e}}function Zp(t,e){let n=t.nodeTypes,s=n[e];if(s)return[s];let o=[];for(let r in n){let a=n[r];a.isInGroup(e)&&o.push(a)}return o.length==0&&t.err("No node type or group '"+e+"' found"),o}function Qp(t){if(t.eat("(")){let e=Ua(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=Zp(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function ef(t){let e=[[]];return o(r(t,0),n()),e;function n(){return e.push([])-1}function s(a,l,c){let u={term:c,to:l};return e[a].push(u),u}function o(a,l){a.forEach(c=>c.to=l)}function r(a,l){if(a.type=="choice")return a.exprs.reduce((c,u)=>c.concat(r(u,l)),[]);if(a.type=="seq")for(let c=0;;c++){let u=r(a.exprs[c],l);if(c==a.exprs.length-1)return u;o(u,l=n())}else if(a.type=="star"){let c=n();return s(l,c),o(r(a.expr,c),c),[s(c)]}else if(a.type=="plus"){let c=n();return o(r(a.expr,l),c),o(r(a.expr,c),c),[s(c)]}else{if(a.type=="opt")return[s(l)].concat(r(a.expr,l));if(a.type=="range"){let c=l;for(let u=0;u<a.min;u++){let p=n();o(r(a.expr,c),p),c=p}if(a.max==-1)o(r(a.expr,c),c);else for(let u=a.min;u<a.max;u++){let p=n();s(c,p),o(r(a.expr,c),p),c=p}return[s(c)]}else{if(a.type=="name")return[s(l,void 0,a.value)];throw new Error("Unknown expr type")}}}}function qa(t,e){return e-t}function Xo(t,e){let n=[];return s(e),n.sort(qa);function s(o){let r=t[o];if(r.length==1&&!r[0].term)return s(r[0].to);n.push(o);for(let a=0;a<r.length;a++){let{term:l,to:c}=r[a];!l&&n.indexOf(c)==-1&&s(c)}}}function tf(t){let e=Object.create(null);return n(Xo(t,0));function n(s){let o=[];s.forEach(a=>{t[a].forEach(({term:l,to:c})=>{if(!l)return;let u;for(let p=0;p<o.length;p++)o[p][0]==l&&(u=o[p][1]);Xo(t,c).forEach(p=>{u||o.push([l,u=[]]),u.indexOf(p)==-1&&u.push(p)})})});let r=e[s.join(",")]=new Rt(s.indexOf(t.length-1)>-1);for(let a=0;a<o.length;a++){let l=o[a][1].sort(qa);r.next.push({type:o[a][0],next:e[l.join(",")]||n(l)})}return r}}function nf(t,e){for(let n=0,s=[t];n<s.length;n++){let o=s[n],r=!o.validEnd,a=[];for(let l=0;l<o.next.length;l++){let{type:c,next:u}=o.next[l];a.push(c.name),r&&!(c.isText||c.hasRequiredAttrs())&&(r=!1),s.indexOf(u)==-1&&s.push(u)}r&&e.err("Only non-generatable nodes ("+a.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function Ka(t){let e=Object.create(null);for(let n in t){let s=t[n];if(!s.hasDefault)return null;e[n]=s.default}return e}function Ya(t,e){let n=Object.create(null);for(let s in t){let o=e&&e[s];if(o===void 0){let r=t[s];if(r.hasDefault)o=r.default;else throw new RangeError("No value supplied for attribute "+s)}n[s]=o}return n}function Ja(t,e,n,s){for(let o in e)if(!(o in t))throw new RangeError(`Unsupported attribute ${o} for ${n} of type ${o}`);for(let o in t){let r=t[o];r.validate&&r.validate(e[o])}}function Xa(t,e){let n=Object.create(null);if(e)for(let s in e)n[s]=new rf(t,s,e[s]);return n}class ps{constructor(e,n,s){this.name=e,this.schema=n,this.spec=s,this.markSet=null,this.groups=s.group?s.group.split(" "):[],this.attrs=Xa(e,s.attrs),this.defaultAttrs=Ka(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(s.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==Rt.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Ya(this.attrs,e)}create(e=null,n,s){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new It(this,this.computeAttrs(e),D.from(n),Q.setFrom(s))}createChecked(e=null,n,s){return n=D.from(n),this.checkContent(n),new It(this,this.computeAttrs(e),n,Q.setFrom(s))}createAndFill(e=null,n,s){if(e=this.computeAttrs(e),n=D.from(n),n.size){let a=this.contentMatch.fillBefore(n);if(!a)return null;n=a.append(n)}let o=this.contentMatch.matchFragment(n),r=o&&o.fillBefore(D.empty,!0);return r?new It(this,e,n.append(r),Q.setFrom(s)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let s=0;s<e.childCount;s++)if(!this.allowsMarks(e.child(s).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){Ja(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;n<e.length;n++)if(!this.allowsMarkType(e[n].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let n;for(let s=0;s<e.length;s++)this.allowsMarkType(e[s].type)?n&&n.push(e[s]):n||(n=e.slice(0,s));return n?n.length?n:Q.none:e}static compile(e,n){let s=Object.create(null);e.forEach((r,a)=>s[r]=new ps(r,n,a));let o=n.spec.topNode||"doc";if(!s[o])throw new RangeError("Schema is missing its top node type ('"+o+"')");if(!s.text)throw new RangeError("Every schema needs a 'text' type");for(let r in s.text.attrs)throw new RangeError("The text node type should not have attributes");return s}}function sf(t,e,n){let s=n.split("|");return o=>{let r=o===null?"null":typeof o;if(s.indexOf(r)<0)throw new RangeError(`Expected value of type ${s} for attribute ${e} on type ${t}, got ${r}`)}}class rf{constructor(e,n,s){this.hasDefault=Object.prototype.hasOwnProperty.call(s,"default"),this.default=s.default,this.validate=typeof s.validate=="string"?sf(e,n,s.validate):s.validate}get isRequired(){return!this.hasDefault}}class to{constructor(e,n,s,o){this.name=e,this.rank=n,this.schema=s,this.spec=o,this.attrs=Xa(e,o.attrs),this.excluded=null;let r=Ka(this.attrs);this.instance=r?new Q(this,r):null}create(e=null){return!e&&this.instance?this.instance:new Q(this,Ya(this.attrs,e))}static compile(e,n){let s=Object.create(null),o=0;return e.forEach((r,a)=>s[r]=new to(r,o++,n,a)),s}removeFromSet(e){for(var n=0;n<e.length;n++)e[n].type==this&&(e=e.slice(0,n).concat(e.slice(n+1)),n--);return e}isInSet(e){for(let n=0;n<e.length;n++)if(e[n].type==this)return e[n]}checkAttrs(e){Ja(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class of{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let o in e)n[o]=e[o];n.nodes=je.from(e.nodes),n.marks=je.from(e.marks||{}),this.nodes=ps.compile(this.spec.nodes,this),this.marks=to.compile(this.spec.marks,this);let s=Object.create(null);for(let o in this.nodes){if(o in this.marks)throw new RangeError(o+" can not be both a node and a mark");let r=this.nodes[o],a=r.spec.content||"",l=r.spec.marks;if(r.contentMatch=s[a]||(s[a]=Rt.parse(a,this.nodes)),r.inlineContent=r.contentMatch.inlineContent,r.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!r.isInline||!r.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=r}r.markSet=l=="_"?null:l?Zo(this,l.split(" ")):l==""||!r.inlineContent?[]:null}for(let o in this.marks){let r=this.marks[o],a=r.spec.excludes;r.excluded=a==null?[r]:a==""?[]:Zo(this,a.split(" "))}this.nodeFromJSON=o=>It.fromJSON(this,o),this.markFromJSON=o=>Q.fromJSON(this,o),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,s,o){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof ps){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,s,o)}text(e,n){let s=this.nodes.text;return new us(s,s.defaultAttrs,e,Q.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}}function Zo(t,e){let n=[];for(let s=0;s<e.length;s++){let o=e[s],r=t.marks[o],a=r;if(r)n.push(r);else for(let l in t.marks){let c=t.marks[l];(o=="_"||c.spec.group&&c.spec.group.split(" ").indexOf(o)>-1)&&n.push(a=c)}if(!a)throw new SyntaxError("Unknown mark type: '"+e[s]+"'")}return n}function af(t){return t.tag!=null}function lf(t){return t.style!=null}class Ut{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let s=this.matchedStyles=[];n.forEach(o=>{if(af(o))this.tags.push(o);else if(lf(o)){let r=/[^=]*/.exec(o.style)[0];s.indexOf(r)<0&&s.push(r),this.styles.push(o)}}),this.normalizeLists=!this.tags.some(o=>{if(!/^(ul|ol)\b/.test(o.tag)||!o.node)return!1;let r=e.nodes[o.node];return r.contentMatch.matchType(r)})}parse(e,n={}){let s=new ei(this,n,!1);return s.addAll(e,Q.none,n.from,n.to),s.finish()}parseSlice(e,n={}){let s=new ei(this,n,!0);return s.addAll(e,Q.none,n.from,n.to),W.maxOpen(s.finish())}matchTag(e,n,s){for(let o=s?this.tags.indexOf(s)+1:0;o<this.tags.length;o++){let r=this.tags[o];if(uf(e,r.tag)&&(r.namespace===void 0||e.namespaceURI==r.namespace)&&(!r.context||n.matchesContext(r.context))){if(r.getAttrs){let a=r.getAttrs(e);if(a===!1)continue;r.attrs=a||void 0}return r}}}matchStyle(e,n,s,o){for(let r=o?this.styles.indexOf(o)+1:0;r<this.styles.length;r++){let a=this.styles[r],l=a.style;if(!(l.indexOf(e)!=0||a.context&&!s.matchesContext(a.context)||l.length>e.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=n))){if(a.getAttrs){let c=a.getAttrs(n);if(c===!1)continue;a.attrs=c||void 0}return a}}}static schemaRules(e){let n=[];function s(o){let r=o.priority==null?50:o.priority,a=0;for(;a<n.length;a++){let l=n[a];if((l.priority==null?50:l.priority)<r)break}n.splice(a,0,o)}for(let o in e.marks){let r=e.marks[o].spec.parseDOM;r&&r.forEach(a=>{s(a=ti(a)),a.mark||a.ignore||a.clearMark||(a.mark=o)})}for(let o in e.nodes){let r=e.nodes[o].spec.parseDOM;r&&r.forEach(a=>{s(a=ti(a)),a.node||a.ignore||a.mark||(a.node=o)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Ut(e,Ut.schemaRules(e)))}}const Za={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},cf={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Qa={ol:!0,ul:!0},vn=1,xr=2,mn=4;function Qo(t,e,n){return e!=null?(e?vn:0)|(e==="full"?xr:0):t&&t.whitespace=="pre"?vn|xr:n&~mn}class Gn{constructor(e,n,s,o,r,a){this.type=e,this.attrs=n,this.marks=s,this.solid=o,this.options=a,this.content=[],this.activeMarks=Q.none,this.match=r||(a&mn?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(D.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let s=this.type.contentMatch,o;return(o=s.findWrapping(e.type))?(this.match=s,o):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&vn)){let s=this.content[this.content.length-1],o;if(s&&s.isText&&(o=/[ \t\r\n\u000c]+$/.exec(s.text))){let r=s;s.text.length==o[0].length?this.content.pop():this.content[this.content.length-1]=r.withText(r.text.slice(0,r.text.length-o[0].length))}}let n=D.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(D.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Za.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class ei{constructor(e,n,s){this.parser=e,this.options=n,this.isOpen=s,this.open=0,this.localPreserveWS=!1;let o=n.topNode,r,a=Qo(null,n.preserveWhitespace,0)|(s?mn:0);o?r=new Gn(o.type,o.attrs,Q.none,!0,n.topMatch||o.type.contentMatch,a):s?r=new Gn(null,null,Q.none,!0,null,a):r=new Gn(e.schema.topNodeType,null,Q.none,!0,null,a),this.nodes=[r],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let s=e.nodeValue,o=this.top,r=o.options&xr?"full":this.localPreserveWS||(o.options&vn)>0,{schema:a}=this.parser;if(r==="full"||o.inlineContext(e)||/[^ \t\r\n\u000c]/.test(s)){if(r)if(r==="full")s=s.replace(/\r\n?/g,`
131
+ `);else if(a.linebreakReplacement&&/[\r\n]/.test(s)&&this.top.findWrapping(a.linebreakReplacement.create())){let l=s.split(/\r?\n|\r/);for(let c=0;c<l.length;c++)c&&this.insertNode(a.linebreakReplacement.create(),n,!0),l[c]&&this.insertNode(a.text(l[c]),n,!/\S/.test(l[c]));s=""}else s=s.replace(/\r?\n|\r/g," ");else if(s=s.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(s)&&this.open==this.nodes.length-1){let l=o.content[o.content.length-1],c=e.previousSibling;(!l||c&&c.nodeName=="BR"||l.isText&&/[ \t\r\n\u000c]$/.test(l.text))&&(s=s.slice(1))}s&&this.insertNode(a.text(s),n,!/\S/.test(s)),this.findInText(e)}else this.findInside(e)}addElement(e,n,s){let o=this.localPreserveWS,r=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let a=e.nodeName.toLowerCase(),l;Qa.hasOwnProperty(a)&&this.parser.normalizeLists&&df(e);let c=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,s));e:if(c?c.ignore:cf.hasOwnProperty(a))this.findInside(e),this.ignoreFallback(e,n);else if(!c||c.skip||c.closeParent){c&&c.closeParent?this.open=Math.max(0,this.open-1):c&&c.skip.nodeType&&(e=c.skip);let u,p=this.needsBlock;if(Za.hasOwnProperty(a))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),u=!0,r.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,n);break e}let f=c&&c.skip?n:this.readStyles(e,n);f&&this.addAll(e,f),u&&this.sync(r),this.needsBlock=p}else{let u=this.readStyles(e,n);u&&this.addElementByRule(e,c,u,c.consuming===!1?l:void 0)}this.localPreserveWS=o}leafFallback(e,n){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
132
+ `),n)}ignoreFallback(e,n){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),n,!0)}readStyles(e,n){let s=e.style;if(s&&s.length)for(let o=0;o<this.parser.matchedStyles.length;o++){let r=this.parser.matchedStyles[o],a=s.getPropertyValue(r);if(a)for(let l=void 0;;){let c=this.parser.matchStyle(r,a,this,l);if(!c)break;if(c.ignore)return null;if(c.clearMark?n=n.filter(u=>!c.clearMark(u)):n=n.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return n}addElementByRule(e,n,s,o){let r,a;if(n.node)if(a=this.parser.schema.nodes[n.node],a.isLeaf)this.insertNode(a.create(n.attrs),s,e.nodeName=="BR")||this.leafFallback(e,s);else{let c=this.enter(a,n.attrs||null,s,n.preserveWhitespace);c&&(r=!0,s=c)}else{let c=this.parser.schema.marks[n.mark];s=s.concat(c.create(n.attrs))}let l=this.top;if(a&&a.isLeaf)this.findInside(e);else if(o)this.addElement(e,s,o);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,s,!1));else{let c=e;typeof n.contentElement=="string"?c=e.querySelector(n.contentElement):typeof n.contentElement=="function"?c=n.contentElement(e):n.contentElement&&(c=n.contentElement),this.findAround(e,c,!0),this.addAll(c,s),this.findAround(e,c,!1)}r&&this.sync(l)&&this.open--}addAll(e,n,s,o){let r=s||0;for(let a=s?e.childNodes[s]:e.firstChild,l=o==null?null:e.childNodes[o];a!=l;a=a.nextSibling,++r)this.findAtPoint(e,r),this.addDOM(a,n);this.findAtPoint(e,r)}findPlace(e,n,s){let o,r;for(let a=this.open,l=0;a>=0;a--){let c=this.nodes[a],u=c.findWrapping(e);if(u&&(!o||o.length>u.length+l)&&(o=u,r=c,!u.length))break;if(c.solid){if(s)break;l+=2}}if(!o)return null;this.sync(r);for(let a=0;a<o.length;a++)n=this.enterInner(o[a],null,n,!1);return n}insertNode(e,n,s){if(e.isInline&&this.needsBlock&&!this.top.type){let r=this.textblockFromContext();r&&(n=this.enterInner(r,null,n))}let o=this.findPlace(e,n,s);if(o){this.closeExtra();let r=this.top;r.match&&(r.match=r.match.matchType(e.type));let a=Q.none;for(let l of o.concat(e.marks))(r.type?r.type.allowsMarkType(l.type):ni(l.type,e.type))&&(a=l.addToSet(a));return r.content.push(e.mark(a)),!0}return!1}enter(e,n,s,o){let r=this.findPlace(e.create(n),s,!1);return r&&(r=this.enterInner(e,n,s,!0,o)),r}enterInner(e,n,s,o=!1,r){this.closeExtra();let a=this.top;a.match=a.match&&a.match.matchType(e);let l=Qo(e,r,a.options);a.options&mn&&a.content.length==0&&(l|=mn);let c=Q.none;return s=s.filter(u=>(a.type?a.type.allowsMarkType(u.type):ni(u.type,e))?(c=u.addToSet(c),!1):!0),this.nodes.push(new Gn(e,n,c,o,null,l)),this.open++,s}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let n=this.open;n>=0;n--){if(this.nodes[n]==e)return this.open=n,!0;this.localPreserveWS&&(this.nodes[n].options|=vn)}return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let s=this.nodes[n].content;for(let o=s.length-1;o>=0;o--)e+=s[o].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let s=0;s<this.find.length;s++)this.find[s].node==e&&this.find[s].offset==n&&(this.find[s].pos=this.currentPos)}findInside(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&e.nodeType==1&&e.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(e,n,s){if(e!=n&&this.find)for(let o=0;o<this.find.length;o++)this.find[o].pos==null&&e.nodeType==1&&e.contains(this.find[o].node)&&n.compareDocumentPosition(this.find[o].node)&(s?2:4)&&(this.find[o].pos=this.currentPos)}findInText(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&(this.find[n].pos=this.currentPos-(e.nodeValue.length-this.find[n].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),s=this.options.context,o=!this.isOpen&&(!s||s.parent.type==this.nodes[0].type),r=-(s?s.depth+1:0)+(o?0:1),a=(l,c)=>{for(;l>=0;l--){let u=n[l];if(u==""){if(l==n.length-1||l==0)continue;for(;c>=r;c--)if(a(l-1,c))return!0;return!1}else{let p=c>0||c==0&&o?this.nodes[c].type:s&&c>=r?s.node(c-r).type:null;if(!p||p.name!=u&&!p.isInGroup(u))return!1;c--}}return!0};return a(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let s=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(s&&s.isTextblock&&s.defaultAttrs)return s}for(let n in this.parser.schema.nodes){let s=this.parser.schema.nodes[n];if(s.isTextblock&&s.defaultAttrs)return s}}}function df(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let s=e.nodeType==1?e.nodeName.toLowerCase():null;s&&Qa.hasOwnProperty(s)&&n?(n.appendChild(e),e=n):s=="li"?n=e:s&&(n=null)}}function uf(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function ti(t){let e={};for(let n in t)e[n]=t[n];return e}function ni(t,e){let n=e.schema.nodes;for(let s in n){let o=n[s];if(!o.allowsMarkType(t))continue;let r=[],a=l=>{r.push(l);for(let c=0;c<l.edgeCount;c++){let{type:u,next:p}=l.edge(c);if(u==e||r.indexOf(p)<0&&a(p))return!0}};if(a(o.contentMatch))return!0}}const el=65535,tl=Math.pow(2,16);function pf(t,e){return t+e*tl}function si(t){return t&el}function ff(t){return(t-(t&el))/tl}const nl=1,sl=2,Zn=4,rl=8;class ri{constructor(e,n,s){this.pos=e,this.delInfo=n,this.recover=s}get deleted(){return(this.delInfo&rl)>0}get deletedBefore(){return(this.delInfo&(nl|Zn))>0}get deletedAfter(){return(this.delInfo&(sl|Zn))>0}get deletedAcross(){return(this.delInfo&Zn)>0}}class Fe{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&Fe.empty)return Fe.empty}recover(e){let n=0,s=si(e);if(!this.inverted)for(let o=0;o<s;o++)n+=this.ranges[o*3+2]-this.ranges[o*3+1];return this.ranges[s*3]+n+ff(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,s){let o=0,r=this.inverted?2:1,a=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let c=this.ranges[l]-(this.inverted?o:0);if(c>e)break;let u=this.ranges[l+r],p=this.ranges[l+a],f=c+u;if(e<=f){let h=u?e==c?-1:e==f?1:n:n,m=c+o+(h<0?0:p);if(s)return m;let x=e==(n<0?c:f)?null:pf(l/3,e-c),b=e==c?sl:e==f?nl:Zn;return(n<0?e!=c:e!=f)&&(b|=rl),new ri(m,b,x)}o+=p-u}return s?e+o:new ri(e+o,0,null)}touches(e,n){let s=0,o=si(n),r=this.inverted?2:1,a=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let c=this.ranges[l]-(this.inverted?s:0);if(c>e)break;let u=this.ranges[l+r],p=c+u;if(e<=p&&l==o*3)return!0;s+=this.ranges[l+a]-u}return!1}forEach(e){let n=this.inverted?2:1,s=this.inverted?1:2;for(let o=0,r=0;o<this.ranges.length;o+=3){let a=this.ranges[o],l=a-(this.inverted?r:0),c=a+(this.inverted?0:r),u=this.ranges[o+n],p=this.ranges[o+s];e(l,l+u,c,c+p),r+=p-u}}invert(){return new Fe(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Fe.empty:new Fe(e<0?[0,-e,0]:[0,0,e])}}Fe.empty=new Fe([]);const Xs=Object.create(null);class Be{getMap(){return Fe.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let s=Xs[n.stepType];if(!s)throw new RangeError(`No step type ${n.stepType} defined`);return s.fromJSON(e,n)}static jsonID(e,n){if(e in Xs)throw new RangeError("Duplicate use of step JSON ID "+e);return Xs[e]=n,n.prototype.jsonID=e,n}}class we{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new we(e,null)}static fail(e){return new we(null,e)}static fromReplace(e,n,s,o){try{return we.ok(e.replace(n,s,o))}catch(r){if(r instanceof ls)return we.fail(r.message);throw r}}}function no(t,e,n){let s=[];for(let o=0;o<t.childCount;o++){let r=t.child(o);r.content.size&&(r=r.copy(no(r.content,e,r))),r.isInline&&(r=e(r,n,o)),s.push(r)}return D.fromArray(s)}class vt extends Be{constructor(e,n,s){super(),this.from=e,this.to=n,this.mark=s}apply(e){let n=e.slice(this.from,this.to),s=e.resolve(this.from),o=s.node(s.sharedDepth(this.to)),r=new W(no(n.content,(a,l)=>!a.isAtom||!l.type.allowsMarkType(this.mark.type)?a:a.mark(this.mark.addToSet(a.marks)),o),n.openStart,n.openEnd);return we.fromReplace(e,this.from,this.to,r)}invert(){return new wt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),s=e.mapResult(this.to,-1);return n.deleted&&s.deleted||n.pos>=s.pos?null:new vt(n.pos,s.pos,this.mark)}merge(e){return e instanceof vt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new vt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new vt(n.from,n.to,e.markFromJSON(n.mark))}}Be.jsonID("addMark",vt);class wt extends Be{constructor(e,n,s){super(),this.from=e,this.to=n,this.mark=s}apply(e){let n=e.slice(this.from,this.to),s=new W(no(n.content,o=>o.mark(this.mark.removeFromSet(o.marks)),e),n.openStart,n.openEnd);return we.fromReplace(e,this.from,this.to,s)}invert(){return new vt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),s=e.mapResult(this.to,-1);return n.deleted&&s.deleted||n.pos>=s.pos?null:new wt(n.pos,s.pos,this.mark)}merge(e){return e instanceof wt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new wt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new wt(n.from,n.to,e.markFromJSON(n.mark))}}Be.jsonID("removeMark",wt);class Ct extends Be{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return we.fail("No node at mark step's position");let s=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return we.fromReplace(e,this.pos,this.pos+1,new W(D.from(s),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let s=this.mark.addToSet(n.marks);if(s.length==n.marks.length){for(let o=0;o<n.marks.length;o++)if(!n.marks[o].isInSet(s))return new Ct(this.pos,n.marks[o]);return new Ct(this.pos,this.mark)}}return new wn(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Ct(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Ct(n.pos,e.markFromJSON(n.mark))}}Be.jsonID("addNodeMark",Ct);class wn extends Be{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return we.fail("No node at mark step's position");let s=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return we.fromReplace(e,this.pos,this.pos+1,new W(D.from(s),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Ct(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new wn(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new wn(n.pos,e.markFromJSON(n.mark))}}Be.jsonID("removeNodeMark",wn);class Oe extends Be{constructor(e,n,s,o=!1){super(),this.from=e,this.to=n,this.slice=s,this.structure=o}apply(e){return this.structure&&br(e,this.from,this.to)?we.fail("Structure replace would overwrite content"):we.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Fe([this.from,this.to-this.from,this.slice.size])}invert(e){return new Oe(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let n=e.mapResult(this.from,1),s=e.mapResult(this.to,-1);return n.deletedAcross&&s.deletedAcross?null:new Oe(n.pos,Math.max(n.pos,s.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Oe)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let n=this.slice.size+e.slice.size==0?W.empty:new W(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Oe(this.from,this.to+(e.to-e.from),n,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let n=this.slice.size+e.slice.size==0?W.empty:new W(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Oe(e.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Oe(n.from,n.to,W.fromJSON(e,n.slice),!!n.structure)}}Be.jsonID("replace",Oe);class De extends Be{constructor(e,n,s,o,r,a,l=!1){super(),this.from=e,this.to=n,this.gapFrom=s,this.gapTo=o,this.slice=r,this.insert=a,this.structure=l}apply(e){if(this.structure&&(br(e,this.from,this.gapFrom)||br(e,this.gapTo,this.to)))return we.fail("Structure gap-replace would overwrite content");let n=e.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return we.fail("Gap is not a flat range");let s=this.slice.insertAt(this.insert,n.content);return s?we.fromReplace(e,this.from,this.to,s):we.fail("Content does not fit in gap")}getMap(){return new Fe([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let n=this.gapTo-this.gapFrom;return new De(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let n=e.mapResult(this.from,1),s=e.mapResult(this.to,-1),o=this.from==this.gapFrom?n.pos:e.map(this.gapFrom,-1),r=this.to==this.gapTo?s.pos:e.map(this.gapTo,1);return n.deletedAcross&&s.deletedAcross||o<n.pos||r>s.pos?null:new De(n.pos,s.pos,o,r,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new De(n.from,n.to,n.gapFrom,n.gapTo,W.fromJSON(e,n.slice),n.insert,!!n.structure)}}Be.jsonID("replaceAround",De);function br(t,e,n){let s=t.resolve(e),o=n-e,r=s.depth;for(;o>0&&r>0&&s.indexAfter(r)==s.node(r).childCount;)r--,o--;if(o>0){let a=s.node(r).maybeChild(s.indexAfter(r));for(;o>0;){if(!a||a.isLeaf)return!0;a=a.firstChild,o--}}return!1}function hf(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function sn(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let s=t.depth,o=0,r=0;;--s){let a=t.$from.node(s),l=t.$from.index(s)+o,c=t.$to.indexAfter(s)-r;if(s<t.depth&&a.canReplace(l,c,n))return s;if(s==0||a.type.spec.isolating||!hf(a,l,c))break;l&&(o=1),c<a.childCount&&(r=1)}return null}function ol(t,e,n=null,s=t){let o=mf(t,e),r=o&&gf(s,e);return r?o.map(oi).concat({type:e,attrs:n}).concat(r.map(oi)):null}function oi(t){return{type:t,attrs:null}}function mf(t,e){let{parent:n,startIndex:s,endIndex:o}=t,r=n.contentMatchAt(s).findWrapping(e);if(!r)return null;let a=r.length?r[0]:e;return n.canReplaceWith(s,o,a)?r:null}function gf(t,e){let{parent:n,startIndex:s,endIndex:o}=t,r=n.child(s),a=e.contentMatch.findWrapping(r.type);if(!a)return null;let c=(a.length?a[a.length-1]:e).contentMatch;for(let u=s;c&&u<o;u++)c=c.matchType(n.child(u).type);return!c||!c.validEnd?null:a}function lt(t,e,n=1,s){let o=t.resolve(e),r=o.depth-n,a=s&&s[s.length-1]||o.parent;if(r<0||o.parent.type.spec.isolating||!o.parent.canReplace(o.index(),o.parent.childCount)||!a.type.validContent(o.parent.content.cutByIndex(o.index(),o.parent.childCount)))return!1;for(let u=o.depth-1,p=n-2;u>r;u--,p--){let f=o.node(u),h=o.index(u);if(f.type.spec.isolating)return!1;let m=f.content.cutByIndex(h,f.childCount),x=s&&s[p+1];x&&(m=m.replaceChild(0,x.type.create(x.attrs)));let b=s&&s[p]||f;if(!f.canReplace(h+1,f.childCount)||!b.type.validContent(m))return!1}let l=o.indexAfter(r),c=s&&s[0];return o.node(r).canReplaceWith(l,l,c?c.type:o.node(r+1).type)}function Ot(t,e){let n=t.resolve(e),s=n.index();return il(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(s,s+1)}function xf(t,e){e.content.size||t.type.compatibleContent(e.type);let n=t.contentMatchAt(t.childCount),{linebreakReplacement:s}=t.type.schema;for(let o=0;o<e.childCount;o++){let r=e.child(o),a=r.type==s?t.type.schema.nodes.text:r.type;if(n=n.matchType(a),!n||!t.type.allowsMarks(r.marks))return!1}return n.validEnd}function il(t,e){return!!(t&&e&&!t.isLeaf&&xf(t,e))}function Bs(t,e,n=-1){let s=t.resolve(e);for(let o=s.depth;;o--){let r,a,l=s.index(o);if(o==s.depth?(r=s.nodeBefore,a=s.nodeAfter):n>0?(r=s.node(o+1),l++,a=s.node(o).maybeChild(l)):(r=s.node(o).maybeChild(l-1),a=s.node(o+1)),r&&!r.isTextblock&&il(r,a)&&s.node(o).canReplace(l,l+1))return e;if(o==0)break;e=n<0?s.before(o):s.after(o)}}function so(t,e,n=e,s=W.empty){if(e==n&&!s.size)return null;let o=t.resolve(e),r=t.resolve(n);return bf(o,r,s)?new Oe(e,n,s):new yf(o,r,s).fit()}function bf(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}class yf{constructor(e,n,s){this.$from=e,this.$to=n,this.unplaced=s,this.frontier=[],this.placed=D.empty;for(let o=0;o<=e.depth;o++){let r=e.node(o);this.frontier.push({type:r.type,match:r.contentMatchAt(e.indexAfter(o))})}for(let o=e.depth;o>0;o--)this.placed=D.from(e.node(o).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,s=this.$from,o=this.close(e<0?this.$to:s.doc.resolve(e));if(!o)return null;let r=this.placed,a=s.depth,l=o.depth;for(;a&&l&&r.childCount==1;)r=r.firstChild.content,a--,l--;let c=new W(r,a,l);return e>-1?new De(s.pos,e,this.$to.pos,this.$to.end(),c,n):c.size||s.pos!=this.$to.pos?new Oe(s.pos,o.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,s=0,o=this.unplaced.openEnd;s<e;s++){let r=n.firstChild;if(n.childCount>1&&(o=0),r.type.spec.isolating&&o<=s){e=s;break}n=r.content}for(let n=1;n<=2;n++)for(let s=n==1?e:this.unplaced.openStart;s>=0;s--){let o,r=null;s?(r=Zs(this.unplaced.content,s-1).firstChild,o=r.content):o=this.unplaced.content;let a=o.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:u}=this.frontier[l],p,f=null;if(n==1&&(a?u.matchType(a.type)||(f=u.fillBefore(D.from(a),!1)):r&&c.compatibleContent(r.type)))return{sliceDepth:s,frontierDepth:l,parent:r,inject:f};if(n==2&&a&&(p=u.findWrapping(a.type)))return{sliceDepth:s,frontierDepth:l,parent:r,wrap:p};if(r&&u.matchType(r.type))break}}}openMore(){let{content:e,openStart:n,openEnd:s}=this.unplaced,o=Zs(e,n);return!o.childCount||o.firstChild.isLeaf?!1:(this.unplaced=new W(e,n+1,Math.max(s,o.size+n>=e.size-s?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:s}=this.unplaced,o=Zs(e,n);if(o.childCount<=1&&n>0){let r=e.size-n<=n+o.size;this.unplaced=new W(un(e,n-1,1),n-1,r?n-1:s)}else this.unplaced=new W(un(e,n,1),n,s)}placeNodes({sliceDepth:e,frontierDepth:n,parent:s,inject:o,wrap:r}){for(;this.depth>n;)this.closeFrontierNode();if(r)for(let b=0;b<r.length;b++)this.openFrontierNode(r[b]);let a=this.unplaced,l=s?s.content:a.content,c=a.openStart-e,u=0,p=[],{match:f,type:h}=this.frontier[n];if(o){for(let b=0;b<o.childCount;b++)p.push(o.child(b));f=f.matchFragment(o)}let m=l.size+e-(a.content.size-a.openEnd);for(;u<l.childCount;){let b=l.child(u),y=f.matchType(b.type);if(!y)break;u++,(u>1||c==0||b.content.size)&&(f=y,p.push(al(b.mark(h.allowedMarks(b.marks)),u==1?c:0,u==l.childCount?m:-1)))}let x=u==l.childCount;x||(m=-1),this.placed=pn(this.placed,n,D.from(p)),this.frontier[n].match=f,x&&m<0&&s&&s.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let b=0,y=l;b<m;b++){let k=y.lastChild;this.frontier.push({type:k.type,match:k.contentMatchAt(k.childCount)}),y=k.content}this.unplaced=x?e==0?W.empty:new W(un(a.content,e-1,1),e-1,m<0?a.openEnd:e-1):new W(un(a.content,e,u),a.openStart,a.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],n;if(!e.type.isTextblock||!Qs(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(n=this.findCloseLevel(this.$to))&&n.depth==this.depth)return-1;let{depth:s}=this.$to,o=this.$to.after(s);for(;s>1&&o==this.$to.end(--s);)++o;return o}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:s,type:o}=this.frontier[n],r=n<e.depth&&e.end(n+1)==e.pos+(e.depth-(n+1)),a=Qs(e,n,o,s,r);if(a){for(let l=n-1;l>=0;l--){let{match:c,type:u}=this.frontier[l],p=Qs(e,l,u,c,!0);if(!p||p.childCount)continue e}return{depth:n,fit:a,move:r?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=pn(this.placed,n.depth,n.fit)),e=n.move;for(let s=n.depth+1;s<=e.depth;s++){let o=e.node(s),r=o.type.contentMatch.fillBefore(o.content,!0,e.index(s));this.openFrontierNode(o.type,o.attrs,r)}return e}openFrontierNode(e,n=null,s){let o=this.frontier[this.depth];o.match=o.match.matchType(e),this.placed=pn(this.placed,this.depth,D.from(e.create(n,s))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(D.empty,!0);n.childCount&&(this.placed=pn(this.placed,this.frontier.length,n))}}function un(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(un(t.firstChild.content,e-1,n)))}function pn(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(pn(t.lastChild.content,e-1,n)))}function Zs(t,e){for(let n=0;n<e;n++)t=t.firstChild.content;return t}function al(t,e,n){if(e<=0)return t;let s=t.content;return e>1&&(s=s.replaceChild(0,al(s.firstChild,e-1,s.childCount==1?n-1:0))),e>0&&(s=t.type.contentMatch.fillBefore(s).append(s),n<=0&&(s=s.append(t.type.contentMatch.matchFragment(s).fillBefore(D.empty,!0)))),t.copy(s)}function Qs(t,e,n,s,o){let r=t.node(e),a=o?t.indexAfter(e):t.index(e);if(a==r.childCount&&!n.compatibleContent(r.type))return null;let l=s.fillBefore(r.content,!0,a);return l&&!kf(n,r.content,a)?l:null}function kf(t,e,n){for(let s=n;s<e.childCount;s++)if(!t.allowsMarks(e.child(s).marks))return!0;return!1}class gn extends Be{constructor(e,n,s){super(),this.pos=e,this.attr=n,this.value=s}apply(e){let n=e.nodeAt(this.pos);if(!n)return we.fail("No node at attribute step's position");let s=Object.create(null);for(let r in n.attrs)s[r]=n.attrs[r];s[this.attr]=this.value;let o=n.type.create(s,null,n.marks);return we.fromReplace(e,this.pos,this.pos+1,new W(D.from(o),0,n.isLeaf?0:1))}getMap(){return Fe.empty}invert(e){return new gn(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new gn(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new gn(n.pos,n.attr,n.value)}}Be.jsonID("attr",gn);class fs extends Be{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let o in e.attrs)n[o]=e.attrs[o];n[this.attr]=this.value;let s=e.type.create(n,e.content,e.marks);return we.ok(s)}getMap(){return Fe.empty}invert(e){return new fs(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new fs(n.attr,n.value)}}Be.jsonID("docAttr",fs);let Cn=class extends Error{};Cn=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};Cn.prototype=Object.create(Error.prototype);Cn.prototype.constructor=Cn;Cn.prototype.name="TransformError";const er=Object.create(null);class X{constructor(e,n,s){this.$anchor=e,this.$head=n,this.ranges=s||[new vf(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n<e.length;n++)if(e[n].$from.pos!=e[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,n=W.empty){let s=n.content.lastChild,o=null;for(let l=0;l<n.openEnd;l++)o=s,s=s.lastChild;let r=e.steps.length,a=this.ranges;for(let l=0;l<a.length;l++){let{$from:c,$to:u}=a[l],p=e.mapping.slice(r);e.replaceRange(p.map(c.pos),p.map(u.pos),l?W.empty:n),l==0&&li(e,r,(s?s.isInline:o&&o.isTextblock)?-1:1)}}replaceWith(e,n){let s=e.steps.length,o=this.ranges;for(let r=0;r<o.length;r++){let{$from:a,$to:l}=o[r],c=e.mapping.slice(s),u=c.map(a.pos),p=c.map(l.pos);r?e.deleteRange(u,p):(e.replaceRangeWith(u,p,n),li(e,s,n.isInline?-1:1))}}static findFrom(e,n,s=!1){let o=e.parent.inlineContent?new ie(e):Wt(e.node(0),e.parent,e.pos,e.index(),n,s);if(o)return o;for(let r=e.depth-1;r>=0;r--){let a=n<0?Wt(e.node(0),e.node(r),e.before(r+1),e.index(r),n,s):Wt(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,n,s);if(a)return a}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new Ve(e.node(0))}static atStart(e){return Wt(e,e,0,0,1)||new Ve(e)}static atEnd(e){return Wt(e,e,e.content.size,e.childCount,-1)||new Ve(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let s=er[n.type];if(!s)throw new RangeError(`No selection type ${n.type} defined`);return s.fromJSON(e,n)}static jsonID(e,n){if(e in er)throw new RangeError("Duplicate use of selection JSON ID "+e);return er[e]=n,n.prototype.jsonID=e,n}getBookmark(){return ie.between(this.$anchor,this.$head).getBookmark()}}X.prototype.visible=!0;class vf{constructor(e,n){this.$from=e,this.$to=n}}let ii=!1;function ai(t){!ii&&!t.parent.inlineContent&&(ii=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class ie extends X{constructor(e,n=e){ai(e),ai(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let s=e.resolve(n.map(this.head));if(!s.parent.inlineContent)return X.near(s);let o=e.resolve(n.map(this.anchor));return new ie(o.parent.inlineContent?o:s,s)}replace(e,n=W.empty){if(super.replace(e,n),n==W.empty){let s=this.$from.marksAcross(this.$to);s&&e.ensureMarks(s)}}eq(e){return e instanceof ie&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Rs(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new ie(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,s=n){let o=e.resolve(n);return new this(o,s==n?o:e.resolve(s))}static between(e,n,s){let o=e.pos-n.pos;if((!s||o)&&(s=o>=0?1:-1),!n.parent.inlineContent){let r=X.findFrom(n,s,!0)||X.findFrom(n,-s,!0);if(r)n=r.$head;else return X.near(n,s)}return e.parent.inlineContent||(o==0?e=n:(e=(X.findFrom(e,-s,!0)||X.findFrom(e,s,!0)).$anchor,e.pos<n.pos!=o<0&&(e=n))),new ie(e,n)}}X.jsonID("text",ie);class Rs{constructor(e,n){this.anchor=e,this.head=n}map(e){return new Rs(e.map(this.anchor),e.map(this.head))}resolve(e){return ie.between(e.resolve(this.anchor),e.resolve(this.head))}}class ee extends X{constructor(e){let n=e.nodeAfter,s=e.node(0).resolve(e.pos+n.nodeSize);super(e,s),this.node=n}map(e,n){let{deleted:s,pos:o}=n.mapResult(this.anchor),r=e.resolve(o);return s?X.near(r):new ee(r)}content(){return new W(D.from(this.node),0,0)}eq(e){return e instanceof ee&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new ro(this.anchor)}static fromJSON(e,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new ee(e.resolve(n.anchor))}static create(e,n){return new ee(e.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}ee.prototype.visible=!1;X.jsonID("node",ee);class ro{constructor(e){this.anchor=e}map(e){let{deleted:n,pos:s}=e.mapResult(this.anchor);return n?new Rs(s,s):new ro(s)}resolve(e){let n=e.resolve(this.anchor),s=n.nodeAfter;return s&&ee.isSelectable(s)?new ee(n):X.near(n)}}class Ve extends X{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,n=W.empty){if(n==W.empty){e.delete(0,e.doc.content.size);let s=X.atStart(e.doc);s.eq(e.selection)||e.setSelection(s)}else super.replace(e,n)}toJSON(){return{type:"all"}}static fromJSON(e){return new Ve(e)}map(e){return new Ve(e)}eq(e){return e instanceof Ve}getBookmark(){return wf}}X.jsonID("all",Ve);const wf={map(){return this},resolve(t){return new Ve(t)}};function Wt(t,e,n,s,o,r=!1){if(e.inlineContent)return ie.create(t,n);for(let a=s-(o>0?0:1);o>0?a<e.childCount:a>=0;a+=o){let l=e.child(a);if(l.isAtom){if(!r&&ee.isSelectable(l))return ee.create(t,n-(o<0?l.nodeSize:0))}else{let c=Wt(t,l,n+o,o<0?l.childCount:0,o,r);if(c)return c}n+=l.nodeSize*o}return null}function li(t,e,n){let s=t.steps.length-1;if(s<e)return;let o=t.steps[s];if(!(o instanceof Oe||o instanceof De))return;let r=t.mapping.maps[s],a;r.forEach((l,c,u,p)=>{a==null&&(a=p)}),t.setSelection(X.near(t.doc.resolve(a),n))}function ci(t,e){return!e||!t?t:t.bind(e)}class Un{constructor(e,n,s){this.name=e,this.init=ci(n.init,s),this.apply=ci(n.apply,s)}}new Un("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Un("selection",{init(t,e){return t.selection||X.atStart(e.doc)},apply(t){return t.selection}}),new Un("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,s){return s.selection.$cursor?t.storedMarks:null}}),new Un("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}});function ll(t,e,n){for(let s in t){let o=t[s];o instanceof Function?o=o.bind(e):s=="handleDOMEvents"&&(o=ll(o,e,{})),n[s]=o}return n}class $t{constructor(e){this.spec=e,this.props={},e.props&&ll(e.props,this,this.props),this.key=e.key?e.key.key:cl("plugin")}getState(e){return e[this.key]}}const tr=Object.create(null);function cl(t){return t in tr?t+"$"+ ++tr[t]:(tr[t]=0,t+"$")}class Ft{constructor(e="key"){this.key=cl(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const oo=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function dl(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}const ul=(t,e,n)=>{let s=dl(t,n);if(!s)return!1;let o=io(s);if(!o){let a=s.blockRange(),l=a&&sn(a);return l==null?!1:(e&&e(t.tr.lift(a,l).scrollIntoView()),!0)}let r=o.nodeBefore;if(kl(t,o,e,-1))return!0;if(s.parent.content.size==0&&(Xt(r,"end")||ee.isSelectable(r)))for(let a=s.depth;;a--){let l=so(t.doc,s.before(a),s.after(a),W.empty);if(l&&l.slice.size<l.to-l.from){if(e){let c=t.tr.step(l);c.setSelection(Xt(r,"end")?X.findFrom(c.doc.resolve(c.mapping.map(o.pos,-1)),-1):ee.create(c.doc,o.pos-r.nodeSize)),e(c.scrollIntoView())}return!0}if(a==1||s.node(a-1).childCount>1)break}return r.isAtom&&o.depth==s.depth-1?(e&&e(t.tr.delete(o.pos-r.nodeSize,o.pos).scrollIntoView()),!0):!1},Cf=(t,e,n)=>{let s=dl(t,n);if(!s)return!1;let o=io(s);return o?pl(t,o,e):!1},jf=(t,e,n)=>{let s=hl(t,n);if(!s)return!1;let o=ao(s);return o?pl(t,o,e):!1};function pl(t,e,n){let s=e.nodeBefore,o=s,r=e.pos-1;for(;!o.isTextblock;r--){if(o.type.spec.isolating)return!1;let p=o.lastChild;if(!p)return!1;o=p}let a=e.nodeAfter,l=a,c=e.pos+1;for(;!l.isTextblock;c++){if(l.type.spec.isolating)return!1;let p=l.firstChild;if(!p)return!1;l=p}let u=so(t.doc,r,c,W.empty);if(!u||u.from!=r||u instanceof Oe&&u.slice.size>=c-r)return!1;if(n){let p=t.tr.step(u);p.setSelection(ie.create(p.doc,r)),n(p.scrollIntoView())}return!0}function Xt(t,e,n=!1){for(let s=t;s;s=e=="start"?s.firstChild:s.lastChild){if(s.isTextblock)return!0;if(n&&s.childCount!=1)return!1}return!1}const fl=(t,e,n)=>{let{$head:s,empty:o}=t.selection,r=s;if(!o)return!1;if(s.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):s.parentOffset>0)return!1;r=io(s)}let a=r&&r.nodeBefore;return!a||!ee.isSelectable(a)?!1:(e&&e(t.tr.setSelection(ee.create(t.doc,r.pos-a.nodeSize)).scrollIntoView()),!0)};function io(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function hl(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset<n.parent.content.size)?null:n}const ml=(t,e,n)=>{let s=hl(t,n);if(!s)return!1;let o=ao(s);if(!o)return!1;let r=o.nodeAfter;if(kl(t,o,e,1))return!0;if(s.parent.content.size==0&&(Xt(r,"start")||ee.isSelectable(r))){let a=so(t.doc,s.before(),s.after(),W.empty);if(a&&a.slice.size<a.to-a.from){if(e){let l=t.tr.step(a);l.setSelection(Xt(r,"start")?X.findFrom(l.doc.resolve(l.mapping.map(o.pos)),1):ee.create(l.doc,l.mapping.map(o.pos))),e(l.scrollIntoView())}return!0}}return r.isAtom&&o.depth==s.depth-1?(e&&e(t.tr.delete(o.pos,o.pos+r.nodeSize).scrollIntoView()),!0):!1},gl=(t,e,n)=>{let{$head:s,empty:o}=t.selection,r=s;if(!o)return!1;if(s.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):s.parentOffset<s.parent.content.size)return!1;r=ao(s)}let a=r&&r.nodeAfter;return!a||!ee.isSelectable(a)?!1:(e&&e(t.tr.setSelection(ee.create(t.doc,r.pos)).scrollIntoView()),!0)};function ao(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){let n=t.node(e);if(t.index(e)+1<n.childCount)return t.doc.resolve(t.after(e+1));if(n.type.spec.isolating)break}return null}const Sf=(t,e)=>{let n=t.selection,s=n instanceof ee,o;if(s){if(n.node.isTextblock||!Ot(t.doc,n.from))return!1;o=n.from}else if(o=Bs(t.doc,n.from,-1),o==null)return!1;if(e){let r=t.tr.join(o);s&&r.setSelection(ee.create(r.doc,o-t.doc.resolve(o).nodeBefore.nodeSize)),e(r.scrollIntoView())}return!0},Nf=(t,e)=>{let n=t.selection,s;if(n instanceof ee){if(n.node.isTextblock||!Ot(t.doc,n.to))return!1;s=n.to}else if(s=Bs(t.doc,n.to,1),s==null)return!1;return e&&e(t.tr.join(s).scrollIntoView()),!0},Ef=(t,e)=>{let{$from:n,$to:s}=t.selection,o=n.blockRange(s),r=o&&sn(o);return r==null?!1:(e&&e(t.tr.lift(o,r).scrollIntoView()),!0)},xl=(t,e)=>{let{$head:n,$anchor:s}=t.selection;return!n.parent.type.spec.code||!n.sameParent(s)?!1:(e&&e(t.tr.insertText(`
133
+ `).scrollIntoView()),!0)};function lo(t){for(let e=0;e<t.edgeCount;e++){let{type:n}=t.edge(e);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}const Af=(t,e)=>{let{$head:n,$anchor:s}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(s))return!1;let o=n.node(-1),r=n.indexAfter(-1),a=lo(o.contentMatchAt(r));if(!a||!o.canReplaceWith(r,r,a))return!1;if(e){let l=n.after(),c=t.tr.replaceWith(l,l,a.createAndFill());c.setSelection(X.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},bl=(t,e)=>{let n=t.selection,{$from:s,$to:o}=n;if(n instanceof Ve||s.parent.inlineContent||o.parent.inlineContent)return!1;let r=lo(o.parent.contentMatchAt(o.indexAfter()));if(!r||!r.isTextblock)return!1;if(e){let a=(!s.parentOffset&&o.index()<o.parent.childCount?s:o).pos,l=t.tr.insert(a,r.createAndFill());l.setSelection(ie.create(l.doc,a+1)),e(l.scrollIntoView())}return!0},yl=(t,e)=>{let{$cursor:n}=t.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(lt(t.doc,r))return e&&e(t.tr.split(r).scrollIntoView()),!0}let s=n.blockRange(),o=s&&sn(s);return o==null?!1:(e&&e(t.tr.lift(s,o).scrollIntoView()),!0)};function _f(t){return(e,n)=>{let{$from:s,$to:o}=e.selection;if(e.selection instanceof ee&&e.selection.node.isBlock)return!s.parentOffset||!lt(e.doc,s.pos)?!1:(n&&n(e.tr.split(s.pos).scrollIntoView()),!0);if(!s.depth)return!1;let r=[],a,l,c=!1,u=!1;for(let m=s.depth;;m--)if(s.node(m).isBlock){c=s.end(m)==s.pos+(s.depth-m),u=s.start(m)==s.pos-(s.depth-m),l=lo(s.node(m-1).contentMatchAt(s.indexAfter(m-1))),r.unshift(c&&l?{type:l}:null),a=m;break}else{if(m==1)return!1;r.unshift(null)}let p=e.tr;(e.selection instanceof ie||e.selection instanceof Ve)&&p.deleteSelection();let f=p.mapping.map(s.pos),h=lt(p.doc,f,r.length,r);if(h||(r[0]=l?{type:l}:null,h=lt(p.doc,f,r.length,r)),!h)return!1;if(p.split(f,r.length,r),!c&&u&&s.node(a).type!=l){let m=p.mapping.map(s.before(a)),x=p.doc.resolve(m);l&&s.node(a-1).canReplaceWith(x.index(),x.index()+1,l)&&p.setNodeMarkup(p.mapping.map(s.before(a)),l)}return n&&n(p.scrollIntoView()),!0}}const If=_f(),Tf=(t,e)=>{let{$from:n,to:s}=t.selection,o,r=n.sharedDepth(s);return r==0?!1:(o=n.before(r),e&&e(t.tr.setSelection(ee.create(t.doc,o))),!0)};function Bf(t,e,n){let s=e.nodeBefore,o=e.nodeAfter,r=e.index();return!s||!o||!s.type.compatibleContent(o.type)?!1:!s.content.size&&e.parent.canReplace(r-1,r)?(n&&n(t.tr.delete(e.pos-s.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(r,r+1)||!(o.isTextblock||Ot(t.doc,e.pos))?!1:(n&&n(t.tr.join(e.pos).scrollIntoView()),!0)}function kl(t,e,n,s){let o=e.nodeBefore,r=e.nodeAfter,a,l,c=o.type.spec.isolating||r.type.spec.isolating;if(!c&&Bf(t,e,n))return!0;let u=!c&&e.parent.canReplace(e.index(),e.index()+1);if(u&&(a=(l=o.contentMatchAt(o.childCount)).findWrapping(r.type))&&l.matchType(a[0]||r.type).validEnd){if(n){let m=e.pos+r.nodeSize,x=D.empty;for(let k=a.length-1;k>=0;k--)x=D.from(a[k].create(null,x));x=D.from(o.copy(x));let b=t.tr.step(new De(e.pos-1,m,e.pos,m,new W(x,1,0),a.length,!0)),y=b.doc.resolve(m+2*a.length);y.nodeAfter&&y.nodeAfter.type==o.type&&Ot(b.doc,y.pos)&&b.join(y.pos),n(b.scrollIntoView())}return!0}let p=r.type.spec.isolating||s>0&&c?null:X.findFrom(e,1),f=p&&p.$from.blockRange(p.$to),h=f&&sn(f);if(h!=null&&h>=e.depth)return n&&n(t.tr.lift(f,h).scrollIntoView()),!0;if(u&&Xt(r,"start",!0)&&Xt(o,"end")){let m=o,x=[];for(;x.push(m),!m.isTextblock;)m=m.lastChild;let b=r,y=1;for(;!b.isTextblock;b=b.firstChild)y++;if(m.canReplace(m.childCount,m.childCount,b.content)){if(n){let k=D.empty;for(let A=x.length-1;A>=0;A--)k=D.from(x[A].copy(k));let C=t.tr.step(new De(e.pos-x.length,e.pos+r.nodeSize,e.pos+y,e.pos+r.nodeSize-y,new W(k,x.length,0),0,!0));n(C.scrollIntoView())}return!0}}return!1}function vl(t){return function(e,n){let s=e.selection,o=t<0?s.$from:s.$to,r=o.depth;for(;o.node(r).isInline;){if(!r)return!1;r--}return o.node(r).isTextblock?(n&&n(e.tr.setSelection(ie.create(e.doc,t<0?o.start(r):o.end(r)))),!0):!1}}const Rf=vl(-1),Pf=vl(1);function Lf(t,e=null){return function(n,s){let{$from:o,$to:r}=n.selection,a=o.blockRange(r),l=a&&ol(a,t,e);return l?(s&&s(n.tr.wrap(a,l).scrollIntoView()),!0):!1}}function di(t,e=null){return function(n,s){let o=!1;for(let r=0;r<n.selection.ranges.length&&!o;r++){let{$from:{pos:a},$to:{pos:l}}=n.selection.ranges[r];n.doc.nodesBetween(a,l,(c,u)=>{if(o)return!1;if(!(!c.isTextblock||c.hasMarkup(t,e)))if(c.type==t)o=!0;else{let p=n.doc.resolve(u),f=p.index();o=p.parent.canReplaceWith(f,f+1,t)}})}if(!o)return!1;if(s){let r=n.tr;for(let a=0;a<n.selection.ranges.length;a++){let{$from:{pos:l},$to:{pos:c}}=n.selection.ranges[a];r.setBlockType(l,c,t,e)}s(r.scrollIntoView())}return!0}}function co(...t){return function(e,n,s){for(let o=0;o<t.length;o++)if(t[o](e,n,s))return!0;return!1}}co(oo,ul,fl);co(oo,ml,gl);co(xl,bl,yl,If);typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function Df(t,e=null){return function(n,s){let{$from:o,$to:r}=n.selection,a=o.blockRange(r);if(!a)return!1;let l=s?n.tr:null;return Mf(l,a,t,e)?(s&&s(l.scrollIntoView()),!0):!1}}function Mf(t,e,n,s=null){let o=!1,r=e,a=e.$from.doc;if(e.depth>=2&&e.$from.node(e.depth-1).type.compatibleContent(n)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let c=a.resolve(e.start-2);r=new ds(c,c,e.depth),e.endIndex<e.parent.childCount&&(e=new ds(e.$from,a.resolve(e.$to.end(e.depth)),e.depth)),o=!0}let l=ol(r,n,s,e);return l?(t&&Of(t,e,l,o,n),!0):!1}function Of(t,e,n,s,o){let r=D.empty;for(let p=n.length-1;p>=0;p--)r=D.from(n[p].type.create(n[p].attrs,r));t.step(new De(e.start-(s?2:0),e.end,e.start,e.end,new W(r,0,0),n.length,!0));let a=0;for(let p=0;p<n.length;p++)n[p].type==o&&(a=p+1);let l=n.length-a,c=e.start+n.length-(s?2:0),u=e.parent;for(let p=e.startIndex,f=e.endIndex,h=!0;p<f;p++,h=!1)!h&&lt(t.doc,c,l)&&(t.split(c,l),c+=2*l),c+=u.child(p).nodeSize;return t}function $f(t){return function(e,n){let{$from:s,$to:o}=e.selection,r=s.blockRange(o,a=>a.childCount>0&&a.firstChild.type==t);return r?n?s.node(r.depth-1).type==t?Ff(e,n,t,r):zf(e,n,r):!0:!1}}function Ff(t,e,n,s){let o=t.tr,r=s.end,a=s.$to.end(s.depth);r<a&&(o.step(new De(r-1,a,r,a,new W(D.from(n.create(null,s.parent.copy())),1,0),1,!0)),s=new ds(o.doc.resolve(s.$from.pos),o.doc.resolve(a),s.depth));const l=sn(s);if(l==null)return!1;o.lift(s,l);let c=o.doc.resolve(o.mapping.map(r,-1)-1);return Ot(o.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&o.join(c.pos),e(o.scrollIntoView()),!0}function zf(t,e,n){let s=t.tr,o=n.parent;for(let m=n.end,x=n.endIndex-1,b=n.startIndex;x>b;x--)m-=o.child(x).nodeSize,s.delete(m-1,m+1);let r=s.doc.resolve(n.start),a=r.nodeAfter;if(s.mapping.map(n.end)!=n.start+r.nodeAfter.nodeSize)return!1;let l=n.startIndex==0,c=n.endIndex==o.childCount,u=r.node(-1),p=r.index(-1);if(!u.canReplace(p+(l?0:1),p+1,a.content.append(c?D.empty:D.from(o))))return!1;let f=r.pos,h=f+a.nodeSize;return s.step(new De(f-(l?1:0),h+(c?1:0),f+1,h-1,new W((l?D.empty:D.from(o.copy(D.empty))).append(c?D.empty:D.from(o.copy(D.empty))),l?0:1,c?0:1),l?0:1)),e(s.scrollIntoView()),!0}function Hf(t){return function(e,n){let{$from:s,$to:o}=e.selection,r=s.blockRange(o,u=>u.childCount>0&&u.firstChild.type==t);if(!r)return!1;let a=r.startIndex;if(a==0)return!1;let l=r.parent,c=l.child(a-1);if(c.type!=t)return!1;if(n){let u=c.lastChild&&c.lastChild.type==l.type,p=D.from(u?t.create():null),f=new W(D.from(t.create(null,D.from(l.type.create(null,p)))),u?3:1,0),h=r.start,m=r.end;n(e.tr.step(new De(h-(u?3:1),m,h,m,f,1,!0)).scrollIntoView())}return!0}}function wl(t){const{state:e,transaction:n}=t;let{selection:s}=n,{doc:o}=n,{storedMarks:r}=n;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return r},get selection(){return s},get doc(){return o},get tr(){return s=n.selection,o=n.doc,r=n.storedMarks,n}}}class Vf{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:n,state:s}=this,{view:o}=n,{tr:r}=s,a=this.buildProps(r);return Object.fromEntries(Object.entries(e).map(([l,c])=>[l,(...p)=>{const f=c(...p)(a);return!r.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(r),f}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,n=!0){const{rawCommands:s,editor:o,state:r}=this,{view:a}=o,l=[],c=!!e,u=e||r.tr,p=()=>(!c&&n&&!u.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(u),l.every(h=>h===!0)),f={...Object.fromEntries(Object.entries(s).map(([h,m])=>[h,(...b)=>{const y=this.buildProps(u,n),k=m(...b)(y);return l.push(k),f}])),run:p};return f}createCan(e){const{rawCommands:n,state:s}=this,o=!1,r=e||s.tr,a=this.buildProps(r,o);return{...Object.fromEntries(Object.entries(n).map(([c,u])=>[c,(...p)=>u(...p)({...a,dispatch:void 0})])),chain:()=>this.createChain(r,o)}}buildProps(e,n=!0){const{rawCommands:s,editor:o,state:r}=this,{view:a}=o,l={tr:e,editor:o,view:a,state:wl({state:r,transaction:e}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(e,n),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(s).map(([c,u])=>[c,(...p)=>u(...p)(l)]))}};return l}}function jt(t,e,n){return t.config[e]===void 0&&t.parent?jt(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?jt(t.parent,e,n):null}):t.config[e]}function Wf(t){const e=t.filter(o=>o.type==="extension"),n=t.filter(o=>o.type==="node"),s=t.filter(o=>o.type==="mark");return{baseExtensions:e,nodeExtensions:n,markExtensions:s}}function Ie(t,e){if(typeof t=="string"){if(!e.nodes[t])throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);return e.nodes[t]}return t}function Gf(t){return typeof t=="function"}function fn(t,e=void 0,...n){return Gf(t)?e?t.bind(e)(...n):t(...n):t}function Uf(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function qf(t){return Object.prototype.toString.call(t).slice(8,-1)}function qn(t){return qf(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function Cl(t,e){const n={...t};return qn(t)&&qn(e)&&Object.keys(e).forEach(s=>{qn(e[s])&&qn(t[s])?n[s]=Cl(t[s],e[s]):n[s]=e[s]}),n}class We{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=fn(jt(this,"addOptions",{name:this.name}))),this.storage=fn(jt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new We(e)}configure(e={}){const n=this.extend({...this.config,addOptions:()=>Cl(this.options,e)});return n.name=this.name,n.parent=this.parent,n}extend(e={}){const n=new We({...this.config,...e});return n.parent=this,this.child=n,n.name=e.name?e.name:n.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=fn(jt(n,"addOptions",{name:n.name})),n.storage=fn(jt(n,"addStorage",{name:n.name,options:n.options})),n}}function Kf(t,e,n){const{from:s,to:o}=e,{blockSeparator:r=`
134
+
135
+ `,textSerializers:a={}}=n||{};let l="";return t.nodesBetween(s,o,(c,u,p,f)=>{var h;c.isBlock&&u>s&&(l+=r);const m=a==null?void 0:a[c.type.name];if(m)return p&&(l+=m({node:c,pos:u,parent:p,index:f,range:e})),!1;c.isText&&(l+=(h=c==null?void 0:c.text)===null||h===void 0?void 0:h.slice(Math.max(s,u)-u,o-u))}),l}function Yf(t){return Object.fromEntries(Object.entries(t.nodes).filter(([,e])=>e.spec.toText).map(([e,n])=>[e,n.spec.toText]))}We.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new $t({key:new Ft("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:t}=this,{state:e,schema:n}=t,{doc:s,selection:o}=e,{ranges:r}=o,a=Math.min(...r.map(p=>p.$from.pos)),l=Math.max(...r.map(p=>p.$to.pos)),c=Yf(n);return Kf(s,{from:a,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:c})}}})]}});const Jf=()=>({editor:t,view:e})=>(requestAnimationFrame(()=>{var n;t.isDestroyed||(e.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),Xf=(t=!1)=>({commands:e})=>e.setContent("",t),Zf=()=>({state:t,tr:e,dispatch:n})=>{const{selection:s}=e,{ranges:o}=s;return n&&o.forEach(({$from:r,$to:a})=>{t.doc.nodesBetween(r.pos,a.pos,(l,c)=>{if(l.type.isText)return;const{doc:u,mapping:p}=e,f=u.resolve(p.map(c)),h=u.resolve(p.map(c+l.nodeSize)),m=f.blockRange(h);if(!m)return;const x=sn(m);if(l.type.isTextblock){const{defaultType:b}=f.parent.contentMatchAt(f.index());e.setNodeMarkup(m.start,b)}(x||x===0)&&e.lift(m,x)})}),!0},Qf=t=>e=>t(e),eh=()=>({state:t,dispatch:e})=>bl(t,e),th=(t,e)=>({editor:n,tr:s})=>{const{state:o}=n,r=o.doc.slice(t.from,t.to);s.deleteRange(t.from,t.to);const a=s.mapping.map(e);return s.insert(a,r.content),s.setSelection(new ie(s.doc.resolve(Math.max(a-1,0)))),!0},nh=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,s=n.$anchor.node();if(s.content.size>0)return!1;const o=t.selection.$anchor;for(let r=o.depth;r>0;r-=1)if(o.node(r).type===s.type){if(e){const l=o.before(r),c=o.after(r);t.delete(l,c).scrollIntoView()}return!0}return!1},sh=t=>({tr:e,state:n,dispatch:s})=>{const o=Ie(t,n.schema),r=e.selection.$anchor;for(let a=r.depth;a>0;a-=1)if(r.node(a).type===o){if(s){const c=r.before(a),u=r.after(a);e.delete(c,u).scrollIntoView()}return!0}return!1},rh=t=>({tr:e,dispatch:n})=>{const{from:s,to:o}=t;return n&&e.delete(s,o),!0},oh=()=>({state:t,dispatch:e})=>oo(t,e),ih=()=>({commands:t})=>t.keyboardShortcut("Enter"),ah=()=>({state:t,dispatch:e})=>Af(t,e);function hs(t,e,n={strict:!0}){const s=Object.keys(e);return s.length?s.every(o=>n.strict?e[o]===t[o]:Uf(e[o])?e[o].test(t[o]):e[o]===t[o]):!0}function jl(t,e,n={}){return t.find(s=>s.type===e&&hs(Object.fromEntries(Object.keys(n).map(o=>[o,s.attrs[o]])),n))}function ui(t,e,n={}){return!!jl(t,e,n)}function Sl(t,e,n){var s;if(!t||!e)return;let o=t.parent.childAfter(t.parentOffset);if((!o.node||!o.node.marks.some(p=>p.type===e))&&(o=t.parent.childBefore(t.parentOffset)),!o.node||!o.node.marks.some(p=>p.type===e)||(n=n||((s=o.node.marks[0])===null||s===void 0?void 0:s.attrs),!jl([...o.node.marks],e,n)))return;let a=o.index,l=t.start()+o.offset,c=a+1,u=l+o.node.nodeSize;for(;a>0&&ui([...t.parent.child(a-1).marks],e,n);)a-=1,l-=t.parent.child(a).nodeSize;for(;c<t.parent.childCount&&ui([...t.parent.child(c).marks],e,n);)u+=t.parent.child(c).nodeSize,c+=1;return{from:l,to:u}}function yt(t,e){if(typeof t=="string"){if(!e.marks[t])throw Error(`There is no mark type named '${t}'. Maybe you forgot to add the extension?`);return e.marks[t]}return t}const lh=(t,e={})=>({tr:n,state:s,dispatch:o})=>{const r=yt(t,s.schema),{doc:a,selection:l}=n,{$from:c,from:u,to:p}=l;if(o){const f=Sl(c,r,e);if(f&&f.from<=u&&f.to>=p){const h=ie.create(a,f.from,f.to);n.setSelection(h)}}return!0},ch=t=>e=>{const n=typeof t=="function"?t(e):t;for(let s=0;s<n.length;s+=1)if(n[s](e))return!0;return!1};function Nl(t){return t instanceof ie}function St(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function dh(t,e=null){if(!e)return null;const n=X.atStart(t),s=X.atEnd(t);if(e==="start"||e===!0)return n;if(e==="end")return s;const o=n.from,r=s.to;return e==="all"?ie.create(t,St(0,o,r),St(t.content.size,o,r)):ie.create(t,St(e,o,r),St(e,o,r))}function uh(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function uo(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const ph=(t=null,e={})=>({editor:n,view:s,tr:o,dispatch:r})=>{e={scrollIntoView:!0,...e};const a=()=>{(uo()||uh())&&s.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(s.focus(),e!=null&&e.scrollIntoView&&n.commands.scrollIntoView())})};if(s.hasFocus()&&t===null||t===!1)return!0;if(r&&t===null&&!Nl(n.state.selection))return a(),!0;const l=dh(o.doc,t)||n.state.selection,c=n.state.selection.eq(l);return r&&(c||o.setSelection(l),c&&o.storedMarks&&o.setStoredMarks(o.storedMarks),a()),!0},fh=(t,e)=>n=>t.every((s,o)=>e(s,{...n,index:o})),hh=(t,e)=>({tr:n,commands:s})=>s.insertContentAt({from:n.selection.from,to:n.selection.to},t,e),El=t=>{const e=t.childNodes;for(let n=e.length-1;n>=0;n-=1){const s=e[n];s.nodeType===3&&s.nodeValue&&/^(\n\s\s|\n)$/.test(s.nodeValue)?t.removeChild(s):s.nodeType===1&&El(s)}return t};function Kn(t){const e=`<body>${t}</body>`,n=new window.DOMParser().parseFromString(e,"text/html").body;return El(n)}function jn(t,e,n){if(t instanceof It||t instanceof D)return t;n={slice:!0,parseOptions:{},...n};const s=typeof t=="object"&&t!==null,o=typeof t=="string";if(s)try{if(Array.isArray(t)&&t.length>0)return D.fromArray(t.map(l=>e.nodeFromJSON(l)));const a=e.nodeFromJSON(t);return n.errorOnInvalidContent&&a.check(),a}catch(r){if(n.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:r});return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",r),jn("",e,n)}if(o){if(n.errorOnInvalidContent){let a=!1,l="";const c=new of({topNode:e.spec.topNode,marks:e.spec.marks,nodes:e.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:u=>(a=!0,l=typeof u=="string"?u:u.outerHTML,null)}]}})});if(n.slice?Ut.fromSchema(c).parseSlice(Kn(t),n.parseOptions):Ut.fromSchema(c).parse(Kn(t),n.parseOptions),n.errorOnInvalidContent&&a)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const r=Ut.fromSchema(e);return n.slice?r.parseSlice(Kn(t),n.parseOptions).content:r.parse(Kn(t),n.parseOptions)}return jn("",e,n)}function mh(t,e,n){const s=t.steps.length-1;if(s<e)return;const o=t.steps[s];if(!(o instanceof Oe||o instanceof De))return;const r=t.mapping.maps[s];let a=0;r.forEach((l,c,u,p)=>{a===0&&(a=p)}),t.setSelection(X.near(t.doc.resolve(a),n))}const gh=t=>!("type"in t),xh=(t,e,n)=>({tr:s,dispatch:o,editor:r})=>{var a;if(o){n={parseOptions:r.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let l;const c=y=>{r.emit("contentError",{editor:r,error:y,disableCollaboration:()=>{r.storage.collaboration&&(r.storage.collaboration.isDisabled=!0)}})},u={preserveWhitespace:"full",...n.parseOptions};if(!n.errorOnInvalidContent&&!r.options.enableContentCheck&&r.options.emitContentError)try{jn(e,r.schema,{parseOptions:u,errorOnInvalidContent:!0})}catch(y){c(y)}try{l=jn(e,r.schema,{parseOptions:u,errorOnInvalidContent:(a=n.errorOnInvalidContent)!==null&&a!==void 0?a:r.options.enableContentCheck})}catch(y){return c(y),!1}let{from:p,to:f}=typeof t=="number"?{from:t,to:t}:{from:t.from,to:t.to},h=!0,m=!0;if((gh(l)?l:[l]).forEach(y=>{y.check(),h=h?y.isText&&y.marks.length===0:!1,m=m?y.isBlock:!1}),p===f&&m){const{parent:y}=s.doc.resolve(p);y.isTextblock&&!y.type.spec.code&&!y.childCount&&(p-=1,f+=1)}let b;if(h){if(Array.isArray(e))b=e.map(y=>y.text||"").join("");else if(e instanceof D){let y="";e.forEach(k=>{k.text&&(y+=k.text)}),b=y}else typeof e=="object"&&e&&e.text?b=e.text:b=e;s.insertText(b,p,f)}else b=l,s.replaceWith(p,f,b);n.updateSelection&&mh(s,s.steps.length-1,-1),n.applyInputRules&&s.setMeta("applyInputRules",{from:p,text:b}),n.applyPasteRules&&s.setMeta("applyPasteRules",{from:p,text:b})}return!0},bh=()=>({state:t,dispatch:e})=>Sf(t,e),yh=()=>({state:t,dispatch:e})=>Nf(t,e),kh=()=>({state:t,dispatch:e})=>ul(t,e),vh=()=>({state:t,dispatch:e})=>ml(t,e),wh=()=>({state:t,dispatch:e,tr:n})=>{try{const s=Bs(t.doc,t.selection.$from.pos,-1);return s==null?!1:(n.join(s,2),e&&e(n),!0)}catch{return!1}},Ch=()=>({state:t,dispatch:e,tr:n})=>{try{const s=Bs(t.doc,t.selection.$from.pos,1);return s==null?!1:(n.join(s,2),e&&e(n),!0)}catch{return!1}},jh=()=>({state:t,dispatch:e})=>Cf(t,e),Sh=()=>({state:t,dispatch:e})=>jf(t,e);function Al(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Nh(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let s,o,r,a;for(let l=0;l<e.length-1;l+=1){const c=e[l];if(/^(cmd|meta|m)$/i.test(c))a=!0;else if(/^a(lt)?$/i.test(c))s=!0;else if(/^(c|ctrl|control)$/i.test(c))o=!0;else if(/^s(hift)?$/i.test(c))r=!0;else if(/^mod$/i.test(c))uo()||Al()?a=!0:o=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return s&&(n=`Alt-${n}`),o&&(n=`Ctrl-${n}`),a&&(n=`Meta-${n}`),r&&(n=`Shift-${n}`),n}const Eh=t=>({editor:e,view:n,tr:s,dispatch:o})=>{const r=Nh(t).split(/-(?!$)/),a=r.find(u=>!["Alt","Ctrl","Meta","Shift"].includes(u)),l=new KeyboardEvent("keydown",{key:a==="Space"?" ":a,altKey:r.includes("Alt"),ctrlKey:r.includes("Ctrl"),metaKey:r.includes("Meta"),shiftKey:r.includes("Shift"),bubbles:!0,cancelable:!0}),c=e.captureTransaction(()=>{n.someProp("handleKeyDown",u=>u(n,l))});return c==null||c.steps.forEach(u=>{const p=u.map(s.mapping);p&&o&&s.maybeStep(p)}),!0};function po(t,e,n={}){const{from:s,to:o,empty:r}=t.selection,a=e?Ie(e,t.schema):null,l=[];t.doc.nodesBetween(s,o,(f,h)=>{if(f.isText)return;const m=Math.max(s,h),x=Math.min(o,h+f.nodeSize);l.push({node:f,from:m,to:x})});const c=o-s,u=l.filter(f=>a?a.name===f.node.type.name:!0).filter(f=>hs(f.node.attrs,n,{strict:!1}));return r?!!u.length:u.reduce((f,h)=>f+h.to-h.from,0)>=c}const Ah=(t,e={})=>({state:n,dispatch:s})=>{const o=Ie(t,n.schema);return po(n,o,e)?Ef(n,s):!1},_h=()=>({state:t,dispatch:e})=>yl(t,e),Ih=t=>({state:e,dispatch:n})=>{const s=Ie(t,e.schema);return $f(s)(e,n)},Th=()=>({state:t,dispatch:e})=>xl(t,e);function _l(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function pi(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((s,o)=>(n.includes(o)||(s[o]=t[o]),s),{})}const Bh=(t,e)=>({tr:n,state:s,dispatch:o})=>{let r=null,a=null;const l=_l(typeof t=="string"?t:t.name,s.schema);return l?(l==="node"&&(r=Ie(t,s.schema)),l==="mark"&&(a=yt(t,s.schema)),o&&n.selection.ranges.forEach(c=>{s.doc.nodesBetween(c.$from.pos,c.$to.pos,(u,p)=>{r&&r===u.type&&n.setNodeMarkup(p,void 0,pi(u.attrs,e)),a&&u.marks.length&&u.marks.forEach(f=>{a===f.type&&n.addMark(p,p+u.nodeSize,a.create(pi(f.attrs,e)))})})}),!0):!1},Rh=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),Ph=()=>({tr:t,dispatch:e})=>{if(e){const n=new Ve(t.doc);t.setSelection(n)}return!0},Lh=()=>({state:t,dispatch:e})=>fl(t,e),Dh=()=>({state:t,dispatch:e})=>gl(t,e),Mh=()=>({state:t,dispatch:e})=>Tf(t,e),Oh=()=>({state:t,dispatch:e})=>Pf(t,e),$h=()=>({state:t,dispatch:e})=>Rf(t,e);function Fh(t,e,n={},s={}){return jn(t,e,{slice:!1,parseOptions:n,errorOnInvalidContent:s.errorOnInvalidContent})}const zh=(t,e=!1,n={},s={})=>({editor:o,tr:r,dispatch:a,commands:l})=>{var c,u;const{doc:p}=r;if(n.preserveWhitespace!=="full"){const f=Fh(t,o.schema,n,{errorOnInvalidContent:(c=s.errorOnInvalidContent)!==null&&c!==void 0?c:o.options.enableContentCheck});return a&&r.replaceWith(0,p.content.size,f).setMeta("preventUpdate",!e),!0}return a&&r.setMeta("preventUpdate",!e),l.insertContentAt({from:0,to:p.content.size},t,{parseOptions:n,errorOnInvalidContent:(u=s.errorOnInvalidContent)!==null&&u!==void 0?u:o.options.enableContentCheck})};function Hh(t,e){const n=yt(e,t.schema),{from:s,to:o,empty:r}=t.selection,a=[];r?(t.storedMarks&&a.push(...t.storedMarks),a.push(...t.selection.$head.marks())):t.doc.nodesBetween(s,o,c=>{a.push(...c.marks)});const l=a.find(c=>c.type.name===n.name);return l?{...l.attrs}:{}}function Vh(t){for(let e=0;e<t.edgeCount;e+=1){const{type:n}=t.edge(e);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function Wh(t,e){for(let n=t.depth;n>0;n-=1){const s=t.node(n);if(e(s))return{pos:n>0?t.before(n):0,start:t.start(n),depth:n,node:s}}}function fo(t){return e=>Wh(e.$from,t)}function Qn(t,e,n){return Object.fromEntries(Object.entries(n).filter(([s])=>{const o=t.find(r=>r.type===e&&r.name===s);return o?o.attribute.keepOnSplit:!1}))}function Gh(t,e,n={}){const{empty:s,ranges:o}=t.selection,r=e?yt(e,t.schema):null;if(s)return!!(t.storedMarks||t.selection.$from.marks()).filter(f=>r?r.name===f.type.name:!0).find(f=>hs(f.attrs,n,{strict:!1}));let a=0;const l=[];if(o.forEach(({$from:f,$to:h})=>{const m=f.pos,x=h.pos;t.doc.nodesBetween(m,x,(b,y)=>{if(!b.isText&&!b.marks.length)return;const k=Math.max(m,y),C=Math.min(x,y+b.nodeSize),A=C-k;a+=A,l.push(...b.marks.map(v=>({mark:v,from:k,to:C})))})}),a===0)return!1;const c=l.filter(f=>r?r.name===f.mark.type.name:!0).filter(f=>hs(f.mark.attrs,n,{strict:!1})).reduce((f,h)=>f+h.to-h.from,0),u=l.filter(f=>r?f.mark.type!==r&&f.mark.type.excludes(r):!0).reduce((f,h)=>f+h.to-h.from,0);return(c>0?c+u:c)>=a}function fi(t,e){const{nodeExtensions:n}=Wf(e),s=n.find(a=>a.name===t);if(!s)return!1;const o={name:s.name,options:s.options,storage:s.storage},r=fn(jt(s,"group",o));return typeof r!="string"?!1:r.split(" ").includes("list")}function Il(t,{checkChildren:e=!0,ignoreWhitespace:n=!1}={}){var s;if(n){if(t.type.name==="hardBreak")return!0;if(t.isText)return/^\s*$/m.test((s=t.text)!==null&&s!==void 0?s:"")}if(t.isText)return!t.text;if(t.isAtom||t.isLeaf)return!1;if(t.content.childCount===0)return!0;if(e){let o=!0;return t.content.forEach(r=>{o!==!1&&(Il(r,{ignoreWhitespace:n,checkChildren:e})||(o=!1))}),o}return!1}function Uh(t,e,n){var s;const{selection:o}=e;let r=null;if(Nl(o)&&(r=o.$cursor),r){const l=(s=t.storedMarks)!==null&&s!==void 0?s:r.marks();return!!n.isInSet(l)||!l.some(c=>c.type.excludes(n))}const{ranges:a}=o;return a.some(({$from:l,$to:c})=>{let u=l.depth===0?t.doc.inlineContent&&t.doc.type.allowsMarkType(n):!1;return t.doc.nodesBetween(l.pos,c.pos,(p,f,h)=>{if(u)return!1;if(p.isInline){const m=!h||h.type.allowsMarkType(n),x=!!n.isInSet(p.marks)||!p.marks.some(b=>b.type.excludes(n));u=m&&x}return!u}),u})}const qh=(t,e={})=>({tr:n,state:s,dispatch:o})=>{const{selection:r}=n,{empty:a,ranges:l}=r,c=yt(t,s.schema);if(o)if(a){const u=Hh(s,c);n.addStoredMark(c.create({...u,...e}))}else l.forEach(u=>{const p=u.$from.pos,f=u.$to.pos;s.doc.nodesBetween(p,f,(h,m)=>{const x=Math.max(m,p),b=Math.min(m+h.nodeSize,f);h.marks.find(k=>k.type===c)?h.marks.forEach(k=>{c===k.type&&n.addMark(x,b,c.create({...k.attrs,...e}))}):n.addMark(x,b,c.create(e))})});return Uh(s,n,c)},Kh=(t,e)=>({tr:n})=>(n.setMeta(t,e),!0),Yh=(t,e={})=>({state:n,dispatch:s,chain:o})=>{const r=Ie(t,n.schema);let a;return n.selection.$anchor.sameParent(n.selection.$head)&&(a=n.selection.$anchor.parent.attrs),r.isTextblock?o().command(({commands:l})=>di(r,{...a,...e})(n)?!0:l.clearNodes()).command(({state:l})=>di(r,{...a,...e})(l,s)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Jh=t=>({tr:e,dispatch:n})=>{if(n){const{doc:s}=e,o=St(t,0,s.content.size),r=ee.create(s,o);e.setSelection(r)}return!0},Xh=t=>({tr:e,dispatch:n})=>{if(n){const{doc:s}=e,{from:o,to:r}=typeof t=="number"?{from:t,to:t}:t,a=ie.atStart(s).from,l=ie.atEnd(s).to,c=St(o,a,l),u=St(r,a,l),p=ie.create(s,c,u);e.setSelection(p)}return!0},Zh=t=>({state:e,dispatch:n})=>{const s=Ie(t,e.schema);return Hf(s)(e,n)};function hi(t,e){const n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();if(n){const s=n.filter(o=>e==null?void 0:e.includes(o.type.name));t.tr.ensureMarks(s)}}const Qh=({keepMarks:t=!0}={})=>({tr:e,state:n,dispatch:s,editor:o})=>{const{selection:r,doc:a}=e,{$from:l,$to:c}=r,u=o.extensionManager.attributes,p=Qn(u,l.node().type.name,l.node().attrs);if(r instanceof ee&&r.node.isBlock)return!l.parentOffset||!lt(a,l.pos)?!1:(s&&(t&&hi(n,o.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const f=c.parentOffset===c.parent.content.size,h=l.depth===0?void 0:Vh(l.node(-1).contentMatchAt(l.indexAfter(-1)));let m=f&&h?[{type:h,attrs:p}]:void 0,x=lt(e.doc,e.mapping.map(l.pos),1,m);if(!m&&!x&&lt(e.doc,e.mapping.map(l.pos),1,h?[{type:h}]:void 0)&&(x=!0,m=h?[{type:h,attrs:p}]:void 0),s){if(x&&(r instanceof ie&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,m),h&&!f&&!l.parentOffset&&l.parent.type!==h)){const b=e.mapping.map(l.before()),y=e.doc.resolve(b);l.node(-1).canReplaceWith(y.index(),y.index()+1,h)&&e.setNodeMarkup(e.mapping.map(l.before()),h)}t&&hi(n,o.extensionManager.splittableMarks),e.scrollIntoView()}return x},em=(t,e={})=>({tr:n,state:s,dispatch:o,editor:r})=>{var a;const l=Ie(t,s.schema),{$from:c,$to:u}=s.selection,p=s.selection.node;if(p&&p.isBlock||c.depth<2||!c.sameParent(u))return!1;const f=c.node(-1);if(f.type!==l)return!1;const h=r.extensionManager.attributes;if(c.parent.content.size===0&&c.node(-1).childCount===c.indexAfter(-1)){if(c.depth===2||c.node(-3).type!==l||c.index(-2)!==c.node(-2).childCount-1)return!1;if(o){let k=D.empty;const C=c.index(-1)?1:c.index(-2)?2:3;for(let E=c.depth-C;E>=c.depth-3;E-=1)k=D.from(c.node(E).copy(k));const A=c.indexAfter(-1)<c.node(-2).childCount?1:c.indexAfter(-2)<c.node(-3).childCount?2:3,v={...Qn(h,c.node().type.name,c.node().attrs),...e},j=((a=l.contentMatch.defaultType)===null||a===void 0?void 0:a.createAndFill(v))||void 0;k=k.append(D.from(l.createAndFill(null,j)||void 0));const I=c.before(c.depth-(C-1));n.replace(I,c.after(-A),new W(k,4-C,0));let N=-1;n.doc.nodesBetween(I,n.doc.content.size,(E,_)=>{if(N>-1)return!1;E.isTextblock&&E.content.size===0&&(N=_+1)}),N>-1&&n.setSelection(ie.near(n.doc.resolve(N))),n.scrollIntoView()}return!0}const m=u.pos===c.end()?f.contentMatchAt(0).defaultType:null,x={...Qn(h,f.type.name,f.attrs),...e},b={...Qn(h,c.node().type.name,c.node().attrs),...e};n.delete(c.pos,u.pos);const y=m?[{type:l,attrs:x},{type:m,attrs:b}]:[{type:l,attrs:x}];if(!lt(n.doc,c.pos,2))return!1;if(o){const{selection:k,storedMarks:C}=s,{splittableMarks:A}=r.extensionManager,v=C||k.$to.parentOffset&&k.$from.marks();if(n.split(c.pos,2,y).scrollIntoView(),!v||!o)return!0;const j=v.filter(I=>A.includes(I.type.name));n.ensureMarks(j)}return!0},nr=(t,e)=>{const n=fo(a=>a.type===e)(t.selection);if(!n)return!0;const s=t.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(s===void 0)return!0;const o=t.doc.nodeAt(s);return n.node.type===(o==null?void 0:o.type)&&Ot(t.doc,n.pos)&&t.join(n.pos),!0},sr=(t,e)=>{const n=fo(a=>a.type===e)(t.selection);if(!n)return!0;const s=t.doc.resolve(n.start).after(n.depth);if(s===void 0)return!0;const o=t.doc.nodeAt(s);return n.node.type===(o==null?void 0:o.type)&&Ot(t.doc,s)&&t.join(s),!0},tm=(t,e,n,s={})=>({editor:o,tr:r,state:a,dispatch:l,chain:c,commands:u,can:p})=>{const{extensions:f,splittableMarks:h}=o.extensionManager,m=Ie(t,a.schema),x=Ie(e,a.schema),{selection:b,storedMarks:y}=a,{$from:k,$to:C}=b,A=k.blockRange(C),v=y||b.$to.parentOffset&&b.$from.marks();if(!A)return!1;const j=fo(I=>fi(I.type.name,f))(b);if(A.depth>=1&&j&&A.depth-j.depth<=1){if(j.node.type===m)return u.liftListItem(x);if(fi(j.node.type.name,f)&&m.validContent(j.node.content)&&l)return c().command(()=>(r.setNodeMarkup(j.pos,m),!0)).command(()=>nr(r,m)).command(()=>sr(r,m)).run()}return!n||!v||!l?c().command(()=>p().wrapInList(m,s)?!0:u.clearNodes()).wrapInList(m,s).command(()=>nr(r,m)).command(()=>sr(r,m)).run():c().command(()=>{const I=p().wrapInList(m,s),N=v.filter(E=>h.includes(E.type.name));return r.ensureMarks(N),I?!0:u.clearNodes()}).wrapInList(m,s).command(()=>nr(r,m)).command(()=>sr(r,m)).run()},nm=(t,e={},n={})=>({state:s,commands:o})=>{const{extendEmptyMarkRange:r=!1}=n,a=yt(t,s.schema);return Gh(s,a,e)?o.unsetMark(a,{extendEmptyMarkRange:r}):o.setMark(a,e)},sm=(t,e,n={})=>({state:s,commands:o})=>{const r=Ie(t,s.schema),a=Ie(e,s.schema),l=po(s,r,n);let c;return s.selection.$anchor.sameParent(s.selection.$head)&&(c=s.selection.$anchor.parent.attrs),l?o.setNode(a,c):o.setNode(r,{...c,...n})},rm=(t,e={})=>({state:n,commands:s})=>{const o=Ie(t,n.schema);return po(n,o,e)?s.lift(o):s.wrapIn(o,e)},om=()=>({state:t,dispatch:e})=>{const n=t.plugins;for(let s=0;s<n.length;s+=1){const o=n[s];let r;if(o.spec.isInputRules&&(r=o.getState(t))){if(e){const a=t.tr,l=r.transform;for(let c=l.steps.length-1;c>=0;c-=1)a.step(l.steps[c].invert(l.docs[c]));if(r.text){const c=a.doc.resolve(r.from).marks();a.replaceWith(r.from,r.to,t.schema.text(r.text,c))}else a.delete(r.from,r.to)}return!0}}return!1},im=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,{empty:s,ranges:o}=n;return s||e&&o.forEach(r=>{t.removeMark(r.$from.pos,r.$to.pos)}),!0},am=(t,e={})=>({tr:n,state:s,dispatch:o})=>{var r;const{extendEmptyMarkRange:a=!1}=e,{selection:l}=n,c=yt(t,s.schema),{$from:u,empty:p,ranges:f}=l;if(!o)return!0;if(p&&a){let{from:h,to:m}=l;const x=(r=u.marks().find(y=>y.type===c))===null||r===void 0?void 0:r.attrs,b=Sl(u,c,x);b&&(h=b.from,m=b.to),n.removeMark(h,m,c)}else f.forEach(h=>{n.removeMark(h.$from.pos,h.$to.pos,c)});return n.removeStoredMark(c),!0},lm=(t,e={})=>({tr:n,state:s,dispatch:o})=>{let r=null,a=null;const l=_l(typeof t=="string"?t:t.name,s.schema);return l?(l==="node"&&(r=Ie(t,s.schema)),l==="mark"&&(a=yt(t,s.schema)),o&&n.selection.ranges.forEach(c=>{const u=c.$from.pos,p=c.$to.pos;let f,h,m,x;n.selection.empty?s.doc.nodesBetween(u,p,(b,y)=>{r&&r===b.type&&(m=Math.max(y,u),x=Math.min(y+b.nodeSize,p),f=y,h=b)}):s.doc.nodesBetween(u,p,(b,y)=>{y<u&&r&&r===b.type&&(m=Math.max(y,u),x=Math.min(y+b.nodeSize,p),f=y,h=b),y>=u&&y<=p&&(r&&r===b.type&&n.setNodeMarkup(y,void 0,{...b.attrs,...e}),a&&b.marks.length&&b.marks.forEach(k=>{if(a===k.type){const C=Math.max(y,u),A=Math.min(y+b.nodeSize,p);n.addMark(C,A,a.create({...k.attrs,...e}))}}))}),h&&(f!==void 0&&n.setNodeMarkup(f,void 0,{...h.attrs,...e}),a&&h.marks.length&&h.marks.forEach(b=>{a===b.type&&n.addMark(m,x,a.create({...b.attrs,...e}))}))}),!0):!1},cm=(t,e={})=>({state:n,dispatch:s})=>{const o=Ie(t,n.schema);return Lf(o,e)(n,s)},dm=(t,e={})=>({state:n,dispatch:s})=>{const o=Ie(t,n.schema);return Df(o,e)(n,s)};var um=Object.freeze({__proto__:null,blur:Jf,clearContent:Xf,clearNodes:Zf,command:Qf,createParagraphNear:eh,cut:th,deleteCurrentNode:nh,deleteNode:sh,deleteRange:rh,deleteSelection:oh,enter:ih,exitCode:ah,extendMarkRange:lh,first:ch,focus:ph,forEach:fh,insertContent:hh,insertContentAt:xh,joinBackward:kh,joinDown:yh,joinForward:vh,joinItemBackward:wh,joinItemForward:Ch,joinTextblockBackward:jh,joinTextblockForward:Sh,joinUp:bh,keyboardShortcut:Eh,lift:Ah,liftEmptyBlock:_h,liftListItem:Ih,newlineInCode:Th,resetAttributes:Bh,scrollIntoView:Rh,selectAll:Ph,selectNodeBackward:Lh,selectNodeForward:Dh,selectParentNode:Mh,selectTextblockEnd:Oh,selectTextblockStart:$h,setContent:zh,setMark:qh,setMeta:Kh,setNode:Yh,setNodeSelection:Jh,setTextSelection:Xh,sinkListItem:Zh,splitBlock:Qh,splitListItem:em,toggleList:tm,toggleMark:nm,toggleNode:sm,toggleWrap:rm,undoInputRule:om,unsetAllMarks:im,unsetMark:am,updateAttributes:lm,wrapIn:cm,wrapInList:dm});We.create({name:"commands",addCommands(){return{...um}}});We.create({name:"drop",addProseMirrorPlugins(){return[new $t({key:new Ft("tiptapDrop"),props:{handleDrop:(t,e,n,s)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:n,moved:s})}}})]}});We.create({name:"editable",addProseMirrorPlugins(){return[new $t({key:new Ft("editable"),props:{editable:()=>this.editor.options.editable}})]}});const pm=new Ft("focusEvents");We.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:t}=this;return[new $t({key:pm,props:{handleDOMEvents:{focus:(e,n)=>{t.isFocused=!0;const s=t.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return e.dispatch(s),!1},blur:(e,n)=>{t.isFocused=!1;const s=t.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return e.dispatch(s),!1}}}})]}});We.create({name:"keymap",addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({commands:a})=>[()=>a.undoInputRule(),()=>a.command(({tr:l})=>{const{selection:c,doc:u}=l,{empty:p,$anchor:f}=c,{pos:h,parent:m}=f,x=f.parent.isTextblock&&h>0?l.doc.resolve(h-1):f,b=x.parent.type.spec.isolating,y=f.pos-f.parentOffset,k=b&&x.parent.childCount===1?y===f.pos:X.atStart(u).from===h;return!p||!m.type.isTextblock||m.textContent.length||!k||k&&f.parent.type.name==="paragraph"?!1:a.clearNodes()}),()=>a.deleteSelection(),()=>a.joinBackward(),()=>a.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:a})=>[()=>a.deleteSelection(),()=>a.deleteCurrentNode(),()=>a.joinForward(),()=>a.selectNodeForward()]),s={Enter:()=>this.editor.commands.first(({commands:a})=>[()=>a.newlineInCode(),()=>a.createParagraphNear(),()=>a.liftEmptyBlock(),()=>a.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:t,"Mod-Backspace":t,"Shift-Backspace":t,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},o={...s},r={...s,"Ctrl-h":t,"Alt-Backspace":t,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return uo()||Al()?r:o},addProseMirrorPlugins(){return[new $t({key:new Ft("clearDocument"),appendTransaction:(t,e,n)=>{if(t.some(b=>b.getMeta("composition")))return;const s=t.some(b=>b.docChanged)&&!e.doc.eq(n.doc),o=t.some(b=>b.getMeta("preventClearDocument"));if(!s||o)return;const{empty:r,from:a,to:l}=e.selection,c=X.atStart(e.doc).from,u=X.atEnd(e.doc).to;if(r||!(a===c&&l===u)||!Il(n.doc))return;const h=n.tr,m=wl({state:n,transaction:h}),{commands:x}=new Vf({editor:this.editor,state:m});if(x.clearNodes(),!!h.steps.length)return h}})]}});We.create({name:"paste",addProseMirrorPlugins(){return[new $t({key:new Ft("tiptapPaste"),props:{handlePaste:(t,e,n)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:n})}}})]}});We.create({name:"tabindex",addProseMirrorPlugins(){return[new $t({key:new Ft("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});const fm=We.create({name:"color",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{color:{default:null,parseHTML:t=>{var e;return(e=t.style.color)===null||e===void 0?void 0:e.replace(/['"]+/g,"")},renderHTML:t=>t.color?{style:`color: ${t.color}`}:{}}}}]},addCommands(){return{setColor:t=>({chain:e})=>e().setMark("textStyle",{color:t}).run(),unsetColor:()=>({chain:t})=>t().setMark("textStyle",{color:null}).removeEmptyTextStyle().run()}}}),Tl=({blockId:t,value:e="",onUpdate:n=()=>{},onBlur:s=()=>{},placeholder:o="",from:r="settings",style:a={}})=>ss.useEditor({extensions:[rd,Zc,fm.configure({types:["textStyle"]}),Qc.configure({multicolor:!0}),ed.configure({openOnClick:!1,HTMLAttributes:{class:"underline"}}),nd.configure({types:["heading","paragraph"],alignments:["left","center","right"],defaultAlignment:"left"}),sd,td.configure({placeholder:o||"Enter text here",emptyEditorClass:"cursor-text before:content-[attr(data-placeholder)] before:absolute before:opacity-50 before:pointer-events-none"})],content:e||"",onUpdate:n,onBlur:s,editorProps:{attributes:{...a?{style:a}:{},class:r!=="canvas"?"text-sm p-1 px-2 rte":"rte"}}},[t]);function hm(t){let e=t;for(;e;){if(e.style&&e.style.textAlign)return e.style.textAlign;const n=window.getComputedStyle(e).textAlign;if(n&&n!=="start"&&n!=="initial"&&n!=="inherit")return n;e=e.parentElement}return null}const mm=g.memo(({blockContent:t,editingElement:e,onClose:n,onChange:s,onEscape:o})=>{const{document:r}=tt(),a=Tl({value:t,blockId:"active-inline-editing-element",placeholder:"Enter text here",onUpdate:({editor:u})=>s((u==null?void 0:u.getHTML())||""),onBlur:({editor:u,event:p})=>{if(!r)return;const f=p==null?void 0:p.relatedTarget,h=r.querySelector(".ProseMirror"),m=r.querySelector(".tippy-box"),x=r.querySelector("#chai-rich-text-menu-bar"),b=h==null?void 0:h.contains(f),y=m==null?void 0:m.contains(f),k=x==null?void 0:x.contains(f),C=window.document.getElementById("rte-widget-color-picker");if(!b&&!y&&!k&&!C){const A=(u==null?void 0:u.getHTML())||"";n(A)}},from:"canvas"});g.useEffect(()=>{var p,f;const u=hm(e);u&&((p=a==null?void 0:a.commands)==null||p.setTextAlign(u)),(f=a==null?void 0:a.commands)==null||f.focus(),a==null||a.emit("focus",{editor:a,event:new FocusEvent("focus"),transaction:[]})},[e,a]);const l=g.useMemo(()=>{var f;const u="max-w-none shadow-none outline outline-[2px] [&_*]:shadow-none";if(!e)return u;const p=((f=e==null?void 0:e.className)==null?void 0:f.replace("sr-only",""))||"";return`${u} ${p}`},[e]),c=u=>{u.key==="Escape"&&o(u)};return a&&i.jsxs("div",{onKeyDown:c,onClick:u=>u.stopPropagation(),className:"relative",children:[i.jsx(ss.BubbleMenu,{editor:a,shouldShow:()=>a&&(a==null?void 0:a.isFocused),tippyOptions:{duration:100,arrow:!0,hideOnClick:!1},className:"w-max",children:i.jsx(Ma,{editor:a,from:"canvas"})}),i.jsx(ss.EditorContent,{id:"active-inline-editing-element",onKeyDown:c,value:t,editor:a,className:l})]})}),gm=g.memo(({editingElement:t,blockContent:e,onClose:n,editorRef:s,onChange:o,onEscape:r})=>{const{document:a,window:l}=tt();g.useEffect(()=>{if(!(!a||!l))if(s.current){s.current.innerHTML=e,s.current.focus();const h=a.createRange(),m=l.getSelection();h.selectNodeContents(s.current),h.collapse(!1),m==null||m.removeAllRanges(),m==null||m.addRange(h),s.current.focus()}else n()},[e,a,s,n,l]);const c=g.useMemo(()=>{var m;const h=((m=t==null?void 0:t.tagName)==null?void 0:m.toLowerCase())||"div";return h==="button"?"div":h},[t]),u=g.useCallback(h=>{(h.key==="Enter"||h.key==="Escape")&&r(h)},[r]),p=g.useCallback(()=>{n()},[n]),f=g.useMemo(()=>{var h;return{id:"active-inline-editing-element",contentEditable:!0,className:`${((h=t==null?void 0:t.className)==null?void 0:h.replace("sr-only",""))||""} outline outline-[2px] outline-green-500 shadow-none empty:before:content-[attr(data-placeholder)] empty:before:text-gray-400 empty:before:absolute empty:before:pointer-events-none empty:before:select-none empty:before:inset-0 empty:before:z-0 relative min-h-[1em]`,style:d.cloneDeep(t==null?void 0:t.style)||{},onInput:m=>{const x=m.target;x&&(x.innerText.trim()===""?(x.setAttribute("data-placeholder","Enter text here"),x.children.length>0&&x.children[0].remove()):m.target.removeAttribute("data-placeholder"),o(m.target.innerText))},onClick:m=>{m.stopPropagation(),m.preventDefault()}}},[t==null?void 0:t.className,t==null?void 0:t.style,o]);return i.jsx(i.Fragment,{children:g.createElement(c,{ref:s,onBlur:p,onKeyDown:u,...f})})}),xm=g.memo(({block:t,children:e})=>{const n="content",{document:s}=tt(),{editingBlockId:o,editingItemIndex:r,setEditingBlockId:a,setEditingItemIndex:l}=Mt(),[c,u]=g.useState(null),p=g.useRef(null),{clearHighlight:f}=et(),h=Ke(),{selectedLang:m}=Te(),[,x]=q(),b=g.useRef(null),y=o,{blockContent:k,blockType:C}=g.useMemo(()=>{var P;const N=t._type;let E=t[n];const _=K.getRegisteredChaiBlock(t._type);return m&&((P=_==null?void 0:_.i18nProps)==null?void 0:P.includes(n))&&d.has(t,`${n}-${m}`)&&(E=d.get(t,`${n}-${m}`)),{blockContent:E,blockType:N}},[t,m]),A=g.useCallback(N=>{var _;const E=N||((_=p.current)==null?void 0:_.innerText);h([y],{[n]:E}),u(null),a(""),l(-1),x([]),y&&setTimeout(()=>x([y]),100)},[h,y,a,l,x]),v=xe.useDebouncedCallback(N=>{h([y],{[n]:N})},[y,t,h,m],1e3),j=g.useCallback(N=>{N.preventDefault(),y&&(b.current=y),A(),setTimeout(()=>{const E=b.current;b.current=null,E&&x([E])},100)},[y,A,x]);g.useEffect(()=>{var B;if(!y||!s)return;const N=`[data-block-id="${y}"]`,E=r>=0?`[data-block-index="${r}"]`:"",_=s.querySelector(`${N}${E}`);_&&((B=_==null?void 0:_.classList)==null||B.add("sr-only"),g.startTransition(()=>u(_)))},[y,C,s,r]);const I=g.useMemo(()=>c?(f(),["RichText","Paragraph"].includes(C)?i.jsx(mm,{blockContent:k,editingElement:c,onChange:v,onClose:A,onEscape:j}):i.jsx(gm,{editorRef:p,blockContent:k,editingElement:c,onClose:A,onChange:v,onEscape:j})):null,[c,f,C,k,A,v,j]);return i.jsxs(i.Fragment,{children:[I,e]})},(t,e)=>t.block._id===e.block._id&&t.block.content===e.block.content),Bl=g.createContext({index:-1,key:""}),mi=g.createContext(0),bm=["Box","Repeater","GlobalBlock","PartialBlock","Heading","Text","RichText","Span","Image","Button","Paragraph","Link","Video","Audio","Icon","List","ListItem","CustomScript","CustomHTML"],ym=({asyncProps:t,blockAtom:e,children:n})=>{const{editingBlockId:s,editingItemIndex:o}=Mt(),[r]=S.useAtom(e),a=g.useMemo(()=>K.getRegisteredChaiBlock(r._type),[r._type]),{selectedLang:l,fallbackLang:c}=Te(),u=Dp(),p=Dt(),[f]=S.useAtom(Yr),h=d.get(a,"component",null),{index:m,key:x}=g.useContext(Bl),{mode:b}=Da(),y=S.useAtomValue(Qt),k=Ye(),C=b==="edit",A=Lp(),v=g.useMemo(()=>f?ne.applyBindingToBlockProps(ne.applyLanguage(r,l,a),p,{index:m,key:x}):ne.applyLanguage(r,l,a),[r,l,a,p,f,m,x]),j=g.useMemo(()=>ne.getBlockTagAttributes(r,!0,y),[r,ne.getBlockTagAttributes,y]),I=g.useMemo(()=>u(r._id,ne.getBlockRuntimeProps(r._type)),[r._id,r._type,u,ne.getBlockRuntimeProps]),N=g.useMemo(()=>{const M={"data-block-id":r._id,"data-block-type":r._type,"data-block-index":m};return C&&k?{...M,draggable:!s,onMouseDown:A.onMouseDown,onDragStart:A.onDragStart,onDragEnd:A.onDragEnd}:M},[r._id,r._type,m,C,k,A,s]),E=g.useMemo(()=>({blockProps:N,inBuilder:b==="edit",lang:l||c,pageData:p,...v,...j,...I,...t}),[b,N,l,c,v,j,I,t]),_=g.useMemo(()=>!bm.includes(r._type),[r._type]),B=g.useMemo(()=>{const M=d.get(r,"_show",!0);return d.isString(M)?f?ne.resolveBinding(M,p)!=="false":!0:M},[r,f,p]);if(d.isNull(h)||!B)return null;let P=i.jsx(g.Suspense,{children:g.createElement(h,{...E,children:n({_id:r._id,_type:r._type,...d.isArray(v.repeaterItems)?{repeaterItems:ne.applyLimit(v.repeaterItems,r),$repeaterItemsKey:v.$repeaterItemsKey}:{},...r.partialBlockId?{partialBlockId:r.partialBlockId}:"",...r.globalBlock?{partialBlockId:r.globalBlock}:""})})});const R=s===r._id&&(o===m||m<0)?i.jsx(xm,{block:r,children:P}):P;return _?i.jsx(Nt.ErrorBoundary,{fallbackRender:$p,children:R}):R},km=({children:t,partialBlockId:e})=>{const n=$("gotoPage",d.noop),{saveState:s}=en(),{selectedLang:o,fallbackLang:r}=Te(),a=g.useCallback(l=>{if(l.stopPropagation(),s!=="SAVED"){le.toast.error("You have unsaved changes. Please save the page first.");return}n({pageId:e,lang:o||r})},[s,n,e,o,r]);return i.jsxs(i.Fragment,{children:[t,i.jsx("div",{className:"partial-overlay group absolute inset-0 z-50",children:i.jsx("div",{onDoubleClick:a,className:"flex h-full w-full items-center justify-center bg-black/10 opacity-0 transition-opacity duration-300 ease-in-out group-hover:opacity-100 group-hover:backdrop-opacity-85",children:i.jsx("p",{className:"rounded-md bg-white px-2 py-1 text-xs",children:"Partial block. Double click to edit."})})})]})},vm=()=>i.jsx("div",{className:"flex items-center justify-center rounded-md border border-destructive bg-destructive/10 p-4 text-center text-sm text-destructive",children:i.jsxs("p",{children:["Maximum partial nesting depth (",is," levels) exceeded"]})}),wm=({partialBlockId:t})=>{const{getPartialBlocks:e}=Vr(),n=g.useContext(mi),s=g.useMemo(()=>e(t),[e,t]),o=g.useMemo(()=>He.splitAtom(S.atom(s)),[s]);return n>=is?i.jsx(vm,{}):d.isEmpty(s)?null:i.jsx(mi.Provider,{value:n+1,children:i.jsx(km,{partialBlockId:t,children:i.jsx(ms,{splitAtoms:o,blocks:s,type:"PartialBlock"})})})},ms=({blocks:t,parent:e=null,splitAtoms:n=void 0,type:s=""})=>{const o=xu(n);let r=g.useMemo(()=>d.filter(t,l=>d.has(l,"_id")&&(d.isEmpty(e)?!l._parent:l._parent===e)),[t,e]);const a=g.useCallback(l=>d.filter(t,c=>c._parent===l).length>0,[t]);return(s==="Heading"||s==="Paragraph"||s==="Link")&&(r=ne.adjustSpacingInContentBlocks(r)),d.map(r,l=>{const c=o(l._id);return c?i.jsx(Op,{block:l,children:u=>i.jsx(ym,{blockAtom:c,asyncProps:u,children:({_id:p,_type:f,partialBlockId:h,repeaterItems:m,$repeaterItemsKey:x})=>f==="Repeater"?d.isArray(m)&&m.map((b,y)=>i.jsx(Bl.Provider,{value:{index:y,key:x},children:i.jsx(ms,{splitAtoms:n,blocks:t,parent:l._id,type:f})},`${p}-${y}`)):f==="GlobalBlock"||f==="PartialBlock"?i.jsx(S.Provider,{store:$e,children:i.jsx(wm,{partialBlockId:h})}):a(p)?i.jsx(ms,{splitAtoms:n,blocks:t,parent:l._id,type:f}):null})},l._id):null})},Cm=()=>{const[t]=Z();return i.jsx(ms,{splitAtoms:Nn,blocks:t})},jm=()=>{const[t]=Z(),[e]=S.useAtom(Ur),n=d.isEmpty(t)?null:i.jsx(Cm,{},e);return i.jsx(i.Fragment,{children:n})},Sm=He.atomWithStorage("canvasZoom",100),Rl=()=>S.useAtom(Sm),Nm=()=>S.useAtom(Xi),Pl=He.atomWithStorage("canvasWidth",800),Em=He.atomWithStorage("canvasDisplayWidth",800),Ll=S.atom(t=>{const e=t(Pl);return ce.getBreakpointValue(e).toLowerCase()}),gs=()=>{const[t,e]=S.useAtom(Pl),n=S.useAtomValue(Ll),[s,o]=Nm();return g.useEffect(()=>{s!=="xs"&&o(n)},[n,s,o]),[t,n,e]},ho=()=>{const[t,e]=S.useAtom(Em);return[t,e]},Am=t=>{const[e]=ho(),[,n]=Rl(),s=$("htmlDir","ltr"),[o,r]=g.useState({}),a=g.useCallback(()=>{const{width:l,height:c}=t;if(l<e){const u=parseFloat((l/e).toFixed(2).toString());let p={};const f=c*u,h=l*u;c&&(p={height:100+(c-f)/f*100+"%",width:100+(l-h)/h*100+"%"}),r({position:"relative",top:0,transform:`scale(${u})`,transformOrigin:s==="rtl"?"top right":"top left",...p,maxWidth:"none"}),n(u*100)}else r({}),n(100)},[e,t,s,n]);return g.useEffect(()=>{a()},[e,t,n,a]),o};function qt(t,e){g.useEffect(()=>{const n=oe.subscribe(t,e);return()=>n()},[t,e])}const _m=()=>{const[,t]=q(),[e,n]=Ae(),{document:s}=tt(),{clearHighlight:o}=et(),[r]=q(),[a]=S.useAtom(qr);return g.useEffect(()=>{setTimeout(()=>{if(!d.isEmpty(e))return;const l=Sa(s,d.first(r));if(l){const c=l.getAttribute("data-style-prop");if(c){const u=l.getAttribute("data-style-id"),p=l.getAttribute("data-block-parent");n([{id:u,prop:c,blockId:p}])}}},100)},[s,r,n,e]),g.useEffect(()=>()=>o(),[o]),qt(Y.CANVAS_BLOCK_SELECTED,l=>{l&&(!d.isEmpty(l)&&!d.includes(r,d.first(l))&&(a==null||a.closeAll()),t(l))}),qt(Y.CANVAS_BLOCK_STYLE_SELECTED,l=>{if(!l)return;const{blockId:c,styleId:u,styleProp:p}=l;c&&(d.includes(r,c)||a==null||a.closeAll(),n([{id:u,prop:p,blockId:c}]),t([c]))}),qt(Y.CLEAR_CANVAS_SELECTION,()=>{o(),t([]),n([])}),null},Im=()=>{const[t]=ho(),[,e]=ya(),n=g.useRef(null),s=g.useRef(null),[o,r]=g.useState({width:0,height:0}),a=Am(o),[,l]=tn(),c=$("loading",!1),u=$("htmlDir","ltr"),{onDragOver:p,onDrop:f,onDragEnd:h}=nn(),m=ep(),x=g.useCallback(y=>{r(k=>({...k,width:y}))},[r]);g.useEffect(()=>{if(!s.current)return;const{clientWidth:y,clientHeight:k}=s.current;r({width:y,height:k})},[s,t]);const b=g.useMemo(()=>{let y=kp;return y=y.replace("__HTML_DIR__",u),y},[u]);return i.jsx(Pp,{onMount:x,onResize:x,children:i.jsx("div",{onMouseLeave:()=>setTimeout(()=>e(""),300),className:"relative mx-auto h-full w-full overflow-hidden",onDragOver:p,onDrop:f,onDragEnd:h,ref:s,children:i.jsxs(wp,{contentDidMount:()=>l(n.current),ref:n,id:"canvas-iframe",style:{...a,...d.isEmpty(a)?{width:`${t}px`}:{}},className:"relative mx-auto box-content h-full w-full max-w-full shadow-lg transition-all duration-300 ease-linear",initialContent:b,children:[i.jsx(Sp,{}),i.jsx(bp,{}),i.jsx(Ip,{}),i.jsxs(Vc.Provider,{children:[i.jsxs(gp,{children:[c?i.jsx("div",{className:"h-full p-4",children:i.jsx(Jt,{className:"h-full"})}):i.jsx(jm,{}),i.jsx(Np,{})]}),i.jsx(_m,{})]}),m.isVisible&&i.jsx("div",{id:"placeholder",className:`pointer-events-none absolute z-[99999] max-w-full transition-all duration-150 ${m.isEmpty?"bg-purple-500/10 outline-dashed outline-2 -outline-offset-2 outline-purple-500":"rounded-full bg-green-500"}`,style:{top:m.top,left:m.left,width:m.width,height:m.height}})]})})})},xn=()=>{const{t}=z.useTranslation();return i.jsx("div",{className:"h-full w-full rounded-md bg-red-200 p-4 text-red-500",children:i.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center",children:[i.jsx("p",{className:"font-semibold",children:t("Oops! Something went wrong.")}),i.jsx("p",{children:t("Please try again.")})]})})},Tm=S.atom(null),mo=()=>S.useAtom(Tm),Bm=g.lazy(()=>Promise.resolve().then(()=>require("./code-editor-gwFRjQ2_.cjs"))),Dl=()=>{const[t]=mo(),e=$("onError",d.noop);return i.jsx("div",{className:"flex h-full max-h-full w-full flex-1 flex-col",children:i.jsxs("div",{className:"relative flex h-full max-h-full flex-col overflow-hidden bg-gray-100/40",children:[i.jsx(g.Suspense,{fallback:i.jsx(Jt,{className:"h-full"}),children:i.jsx(Nt.ErrorBoundary,{fallback:i.jsx(xn,{}),onError:e,children:i.jsx(Im,{})})}),t?i.jsx(g.Suspense,{fallback:i.jsx(Jt,{className:"h-full"}),children:i.jsx(Bm,{})}):null]})})},Pt={ab:"Abkhazian",aa:"Afar",af:"Afrikaans",ak:"Akan",sq:"Albanian",am:"Amharic",ar:"Arabic",an:"Aragonese",hy:"Armenian",as:"Assamese",av:"Avaric",ae:"Avestan",ay:"Aymara",az:"Azerbaijani",bm:"Bambara",ba:"Bashkir",eu:"Basque",be:"Belarusian",bn:"Bengali",bh:"Bihari",bi:"Bislama",bs:"Bosnian",br:"Breton",bg:"Bulgarian",my:"Burmese",ca:"Catalan",ch:"Chamorro",ce:"Chechen",ny:"Chichewa",zh:"Chinese","zh-Hans":"Chinese (Simplified)","zh-Hant":"Chinese (Traditional)",cv:"Chuvash",kw:"Cornish",co:"Corsican",cr:"Cree",hr:"Croatian",cs:"Czech",da:"Danish",dv:"Maldivian",nl:"Dutch",dz:"Dzongkha",en:"English",eo:"Esperanto",et:"Estonian",ee:"Ewe",fo:"Faroese",fj:"Fijian",fi:"Finnish",fr:"French",ff:"Fula, Pular",gl:"Galician",gd:"Gaelic (Scottish)",gv:"Manx",ka:"Georgian",de:"German",el:"Greek",kl:"Kalaallisut",gn:"Guarani",gu:"Gujarati",ht:"Haitian Creole",ha:"Hausa",he:"Hebrew",hz:"Herero",hi:"Hindi",ho:"Hiri Motu",hu:"Hungarian",is:"Icelandic",io:"Ido",ig:"Igbo",id:"Indonesian",ia:"Interlingua",ie:"Interlingue",iu:"Inuktitut",ik:"Inupiak",ga:"Irish",it:"Italian",ja:"Japanese",jv:"Javanese",kn:"Kannada",kr:"Kanuri",ks:"Kashmiri",kk:"Kazakh",km:"Khmer",ki:"Kikuyu",rw:"Kinyarwanda",rn:"Kirundi",ky:"Kyrgyz",kv:"Komi",kg:"Kongo",ko:"Korean",ku:"Kurdish",kj:"Kwanyama",lo:"Lao",la:"Latin",lv:"Latvian",li:"Limburgish",ln:"Lingala",lt:"Lithuanian",lu:"Luga-Katanga",lg:"Luganda, Ganda",lb:"Luxembourgish",mk:"Macedonian",mg:"Malagasy",ms:"Malay",ml:"Malayalam",mt:"Maltese",mi:"Maori",mr:"Marathi",mh:"Marshallese",mo:"Moldavian",mn:"Mongolian",na:"Nauru",nv:"Navajo",ng:"Ndonga",nd:"Northern Ndebele",ne:"Nepali",no:"Norwegian",nb:"Norwegian bokmål",nn:"Norwegian nynorsk",ii:"Sichuan Yi",oc:"Occitan",oj:"Ojibwe",cu:"Old Church Slavonic",or:"Oriya",om:"Oromo",os:"Ossetian",pi:"Pāli",ps:"Pashto, Pushto",fa:"Persian (Farsi)",pl:"Polish",pt:"Portuguese",pa:"Punjabi (Eastern)",qu:"Quechua",rm:"Romansh",ro:"Romanian",ru:"Russian",se:"Sami",sm:"Samoan",sg:"Sango",sa:"Sanskrit",sr:"Serbian",sh:"Serbo-Croatian",st:"Sesotho",tn:"Setswana",sn:"Shona",sd:"Sindhi",si:"Sinhalese",ss:"Swati",sk:"Slovak",sl:"Slovenian",so:"Somali",nr:"Southern Ndebele",es:"Spanish",su:"Sundanese",sw:"Swahili (Kiswahili)",sv:"Swedish",tl:"Tagalog",ty:"Tahitian",tg:"Tajik",ta:"Tamil",tt:"Tatar",te:"Telugu",th:"Thai",bo:"Tibetan",ti:"Tigrinya",to:"Tonga",ts:"Tsonga",tr:"Turkish",tk:"Turkmen",tw:"Twi",ug:"Uyghur",uk:"Ukrainian",ur:"Urdu",uz:"Uzbek",ve:"Venda",vi:"Vietnamese",vo:"Volapük",wa:"Wallon",cy:"Welsh",wo:"Wolof",fy:"Western Frisian",xh:"Xhosa",yi:"Yiddish",yo:"Yoruba",za:"Zhuang, Chuang",zu:"Zulu"},Rm=({id:t,placeholder:e})=>{const{t:n}=z.useTranslation(),[,s]=mo(),{selectedLang:o}=Te(),r=J(),a=t.replace("root.",""),l=K.getRegisteredChaiBlock(r==null?void 0:r._type),u=d.includes(d.get(l,"i18nProps",[]),a)&&o?`${a}-${o}`:a,p=d.get(r,u,""),f=g.useMemo(()=>d.get(Pt,o,o),[o]),h=()=>{const m=r==null?void 0:r._id;s({blockId:m,blockProp:u,placeholder:e,initialCode:p})};return i.jsxs("div",{className:"mt-2 flex flex-col gap-y-1",children:[i.jsxs("label",{htmlFor:t,children:["HTML Code",f&&i.jsxs("small",{className:"text-[9px] text-zinc-400",children:[" ",f]})]}),i.jsx("button",{onClick:h,className:"w-[90%] max-w-full cursor-default truncate text-pretty rounded border border-border bg-background p-2 text-left text-[10px]",children:p.trim().length>0?p.substring(0,46):e||"Eg: <script>console.log('Hello, world!');<\/script>"}),i.jsx(T.Button,{onClick:h,size:"sm",variant:"outline",className:"w-fit",children:n("Open code editor")})]})},Pm=({id:t,value:e,onChange:n,onBlur:s})=>{const o=$("collections",[]),r=J(),a=d.get(r,"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1").replace(U.COLLECTION_PREFIX,""),l=d.find(o,{id:a}),c=t==="root.filter"?"filters":"sorts",u=d.get(l,c,[]);return i.jsx("div",{children:i.jsxs("select",{value:e,onChange:p=>n(p.target.value),onBlur:p=>s(t,p.target.value),children:[i.jsx("option",{value:"",children:"Select"}),u.map(p=>i.jsx("option",{value:p.id,children:p.name},p.id))]})})},Lm=g.lazy(()=>Promise.resolve().then(()=>require("./IconPicker-C0WWlb8t.cjs")).then(t=>({default:t.IconPicker}))),Dm=t=>{try{let e=t.replace(/<svg([^>]*)\sheight="[^"]*"([^>]*)>/gi,"<svg$1$2>").replace(/<svg([^>]*)\swidth="[^"]*"([^>]*)>/gi,"<svg$1$2>");return e=e.replace(/>\s+</g,"><"),e=e.replace(/\n/g,"").replace(/\s{2,}/g," "),e=e.replace(/\s+=/g,"=").replace(/=\s+/g,"="),e=e.replace(/<!--[\s\S]*?-->/g,""),e.trim()}catch{return t}},Mm=({value:t,onChange:e,id:n})=>{const{t:s}=z.useTranslation(),[o,r]=g.useState(t||"");g.useEffect(()=>{r(t||"")},[t]);const a=l=>{r(l);const c=Dm(l);e(c)};return i.jsxs("div",{className:"mt-1 flex flex-col gap-2",id:"icon-picker-field",children:[i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsx("div",{className:"flex h-12 w-12 items-center justify-center overflow-hidden rounded-lg border bg-gray-50",children:o?i.jsx("div",{className:"h-6 w-6",dangerouslySetInnerHTML:{__html:o}}):i.jsx("span",{className:"text-xs text-gray-400",children:"SVG"})}),i.jsx("textarea",{id:n,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",value:o,onChange:l=>a(l.target.value),placeholder:s("SVG_code"),rows:2,className:"no-scrollbar w-full rounded-md border border-border bg-background px-3 py-1.5 text-xs shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(g.Suspense,{fallback:i.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading..."}),children:i.jsx(Lm,{onSelectIcon:a})}),i.jsx("p",{className:"text-xs text-muted-foreground",children:s("Paste SVG_code")})]})]})},Bn=pe.Root,Ml=pe.Trigger,Om=pe.Portal,Ol=O.forwardRef(({className:t,...e},n)=>i.jsx(pe.Overlay,{ref:n,className:T.cn("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...e}));Ol.displayName=pe.Overlay.displayName;const rn=O.forwardRef(({className:t,children:e,...n},s)=>i.jsxs(Om,{children:[i.jsx(Ol,{}),i.jsxs(pe.Content,{ref:s,className:T.cn("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",t),...n,children:[e,i.jsxs(pe.Close,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[i.jsx(w.Cross1Icon,{className:"h-4 w-4"}),i.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));rn.displayName=pe.Content.displayName;const Rn=({className:t,...e})=>i.jsx("div",{className:T.cn("flex flex-col space-y-1.5 text-center sm:text-left",t),...e});Rn.displayName="DialogHeader";const $l=({className:t,...e})=>i.jsx("div",{className:T.cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...e});$l.displayName="DialogFooter";const on=O.forwardRef(({className:t,...e},n)=>i.jsx(pe.Title,{ref:n,className:T.cn("text-lg font-semibold leading-none tracking-tight",t),...e}));on.displayName=pe.Title.displayName;const Fl=O.forwardRef(({className:t,...e},n)=>i.jsx(pe.Description,{ref:n,className:T.cn("text-sm text-muted-foreground",t),...e}));Fl.displayName=pe.Description.displayName;const es=({assetId:t,children:e,onSelect:n,mode:s="image"})=>{const[o,r]=g.useState(!1),a=T.useMediaManagerComponent(),l=(...c)=>{n.call(void 0,...c),r(!1)};return i.jsxs(Bn,{open:o,onOpenChange:c=>r(c),children:[i.jsx(Ml,{asChild:!0,children:e}),i.jsxs(rn,{className:"flex max-h-[90vh] max-w-7xl border-border md:w-fit",children:[i.jsx(on,{className:"sr-only",children:"Media Manager"}),i.jsx("div",{className:"h-full w-full",children:a?i.jsx(a,{close:()=>r(!1),onSelect:l,mode:s,assetId:t}):null})]})]})};es.displayName="MediaManagerModal";function $m(t,e,n){if(!t)return t;const{baseClasses:s,classes:o}=ne.getSplitChaiClasses(t),r=c=>c.split(" ").filter(u=>u&&!(e&&u==="w-full")&&!(n&&u==="h-full")).join(" "),a=r(s),l=r(o);return`${U.STYLES_KEY}${a},${l}`}const Yn="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTAwIiBoZWlnaHQ9IjQwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZjNmNGY2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCwgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNiIgZmlsbD0iI2Q1ZDdkYSIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPkltYWdlIFBsYWNlaG9sZGVyPC90ZXh0Pjwvc3ZnPg==",Fm=t=>{var o;if(!t||d.startsWith(t,"data"))return"";const e=((o=t.split("/").pop())==null?void 0:o.split("?")[0])||"";return[".jpg",".jpeg",".png",".gif",".webp",".svg",".bmp",".ico",".avif"].some(r=>e.toLowerCase().endsWith(r))?e:""},zm=({value:t,onChange:e,id:n,onBlur:s,uiSchema:o})=>{const{t:r}=z.useTranslation(),{selectedLang:a}=Te(),l=J(),c=Ke(),u=Dt(),p=(o==null?void 0:o["ui:allowEmpty"])===!0,f=n.split(".").pop()||"",h=a?`_${f}Id-${a}`:`_${f}Id`,m=d.isEmpty(a)&&(l==null?void 0:l._type)==="Image"&&d.has(l,"assetId"),x=d.get(l,h,m?l==null?void 0:l.assetId:""),b=g.useMemo(()=>{if(!t||!l||!/\{\{.*?\}\}/.test(t))return t;const j={...l,[f]:t},I=ne.applyBindingToBlockProps(j,u,{index:-1,key:""});return d.get(I,f,t)},[t,l,u,f]),y=!!x||b!==Yn&&b!=="",k=v=>{const j=d.isArray(v)?d.first(v):v;if(j){e(j==null?void 0:j.url);const I=j==null?void 0:j.width,N=j==null?void 0:j.height,E=h.includes("mobile");if(l!=null&&l._id){const _={...I&&{[E?"mobileWidth":"width"]:I},...N&&{[E?"mobileHeight":"height"]:N},...j.description&&{alt:j.description}};if(d.set(_,h,j.id),(I||N)&&(l!=null&&l._type)&&(l!=null&&l.styles)){const B=K.getBlockDefaultProps(l._type),P=d.get(B,"styles","");l.styles===P&&(_.styles=$m(l.styles,I,N))}if(d.isEmpty(_))return;c([l._id],_)}}},C=g.useCallback(()=>{if(e(p?"":Yn),l!=null&&l._id){const j={},I=h.includes("mobile");d.set(j,h,""),d.set(j,I?"mobileWidth":"width",""),d.set(j,I?"mobileHeight":"height",""),c([l._id],j)}},[l,e,c,h,p]),A=Fm(b);return i.jsxs("div",{className:"mt-1.5 flex items-start gap-x-3",children:[b?i.jsxs("div",{className:"group relative",children:[i.jsx("img",{src:b,className:"h-[72px] w-[72px] overflow-hidden rounded-md border border-border object-cover transition duration-200 "+(x&&x!==""?"cursor-pointer group-hover:blur-sm":""),alt:""}),y&&i.jsx("button",{type:"button",onClick:C,className:"absolute -right-2 -top-2 z-20 rounded-full bg-destructive p-1 text-destructive-foreground hover:bg-destructive/90",children:i.jsx(w.Cross1Icon,{className:"h-3 w-3"})}),x&&x!==""&&i.jsx(es,{onSelect:k,assetId:x,children:i.jsx("button",{type:"button",className:"absolute inset-0 z-10 flex cursor-pointer items-center justify-center bg-black/10 opacity-0 transition duration-200 group-hover:bg-black/30 group-hover:opacity-100",children:i.jsx(w.Pencil2Icon,{className:"h-4 w-4 text-white"})})})]}):i.jsx(es,{onSelect:k,mode:"image",assetId:x,children:i.jsx("div",{className:"h-[72px] w-[72px] cursor-pointer rounded-md border border-border bg-[radial-gradient(#AAA,transparent_1px)] duration-300 [background-size:10px_10px]"})}),i.jsxs("div",{className:"flex w-3/5 flex-col",children:[i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"max-w-[250px] truncate pr-2 text-xs text-gray-400",children:A}),i.jsx(es,{onSelect:k,assetId:"",children:i.jsx("small",{className:"mb-1 h-6 w-full cursor-pointer rounded-md bg-secondary px-1 py-1 text-center text-xs text-secondary-foreground hover:bg-secondary/80",children:!d.isEmpty(b)&&b!==Yn?r("Replace image"):r("Choose image")})}),i.jsx("div",{className:"text-center text-xs text-gray-400",children:"OR"})]}),i.jsx("input",{id:n,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",type:"url",className:"h-6 text-xs",placeholder:r("Enter image URL"),value:t===Yn?"":t,onBlur:({target:{value:v}})=>s(n,v),onChange:v=>e(v.target.value)})]})]})},Hm=Sr.cva("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Ps({className:t,variant:e,...n}){return i.jsx("div",{className:T.cn(Hm({variant:e}),t),...n})}const xs=Yt.Provider,de=Yt.Root,ue=Yt.Trigger,ae=O.forwardRef(({className:t,sideOffset:e=4,...n},s)=>i.jsx(Yt.Portal,{children:i.jsx(Yt.Content,{ref:s,sideOffset:e,className:T.cn("z-50 origin-[--radix-tooltip-content-transform-origin] overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...n})}));ae.displayName=Yt.Content.displayName;const go=O.forwardRef(({className:t,...e},n)=>i.jsx(Me.Command,{ref:n,className:T.cn("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",t),...e}));go.displayName=Me.Command.displayName;const xo=O.forwardRef(({className:t,...e},n)=>i.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[i.jsx(w.MagnifyingGlassIcon,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),i.jsx(Me.Command.Input,{ref:n,className:T.cn("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",t),...e})]}));xo.displayName=Me.Command.Input.displayName;const bo=O.forwardRef(({className:t,...e},n)=>i.jsx(Me.Command.List,{ref:n,className:T.cn("max-h-[300px] overflow-y-auto overflow-x-hidden",t),...e}));bo.displayName=Me.Command.List.displayName;const yo=O.forwardRef((t,e)=>i.jsx(Me.Command.Empty,{ref:e,className:"py-6 text-center text-sm",...t}));yo.displayName=Me.Command.Empty.displayName;const ko=O.forwardRef(({className:t,...e},n)=>i.jsx(Me.Command.Group,{ref:n,className:T.cn("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",t),...e}));ko.displayName=Me.Command.Group.displayName;const Vm=O.forwardRef(({className:t,...e},n)=>i.jsx(Me.Command.Separator,{ref:n,className:T.cn("-mx-1 h-px bg-border",t),...e}));Vm.displayName=Me.Command.Separator.displayName;const bs=O.forwardRef(({className:t,...e},n)=>i.jsx(Me.Command.Item,{ref:n,className:T.cn("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",t),...e}));bs.displayName=Me.Command.Item.displayName;const Ls=yn.Root,Ds=yn.Trigger,Pn=O.forwardRef(({className:t,align:e="center",sideOffset:n=4,...s},o)=>i.jsx(yn.Portal,{children:i.jsx(yn.Content,{ref:o,align:e,sideOffset:n,className:T.cn("z-50 w-72 origin-[--radix-popover-content-transform-origin] rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...s})}));Pn.displayName=yn.Content.displayName;const Wm=({data:t,onSelect:e,dataType:n})=>{const[s,o]=g.useState([]),[r,a]=g.useState(t),l=f=>Array.isArray(f)?"array":typeof f=="object"&&f!==null?"object":"value",c=g.useCallback(f=>{const h=m=>n==="value"?m==="value"||m==="object":n==="array"?m==="array":m===n;f.type==="object"?(o(m=>[...m,f.key]),a(f.value)):h(f.type)&&e([...s,f.key].join("."),n)},[s,e,n]),u=g.useCallback(()=>{if(s.length>0){const f=s.slice(0,-1);o(f),a(f.reduce((h,m)=>h[m],t))}},[s,t]),p=g.useMemo(()=>r?Object.entries(r).map(([f,h])=>({key:f,value:h,type:l(h)})).filter(f=>!d.startsWith(f.key,U.REPEATER_PREFIX)&&f.key.includes("/")?!1:n==="value"?f.type==="value"||f.type==="object":n==="array"?f.type==="array"||f.type==="object":n==="object"?f.type==="object":!0):[],[r,n]);return i.jsxs(go,{className:"fields-command",children:[i.jsx(xo,{className:"border-none",placeholder:"Search..."}),i.jsxs(bo,{children:[i.jsx(yo,{children:ft.t("No option found.")}),i.jsxs(ko,{children:[s.length>0&&i.jsxs(bs,{onSelect:u,className:"flex items-center text-sm",children:[i.jsx(w.ChevronLeftIcon,{className:"mr-2 h-4 w-4"}),ft.t("Back")]}),p.map(f=>i.jsxs(bs,{value:f.key,disabled:!1,onSelect:()=>c(f),className:"flex items-center justify-between",children:[i.jsxs("span",{className:"flex items-center gap-x-2",children:[d.startsWith(f.key,U.REPEATER_PREFIX)?i.jsx(w.LoopIcon,{}):d.startsWith(f.key,U.COLLECTION_PREFIX)?i.jsx(w.IdCardIcon,{}):null,d.startsWith(f.key,U.REPEATER_PREFIX)?ft.t("Repeater Data"):d.startsWith(f.key,U.COLLECTION_PREFIX)?f.key.replace(U.COLLECTION_PREFIX,""):f.key]}),i.jsxs("div",{className:"flex items-center gap-2",children:[n==="object"&&f.type==="object"&&i.jsx(T.Button,{size:"sm",variant:"ghost",className:"h-6 px-2 hover:bg-primary hover:text-primary-foreground",onClick:h=>{h.stopPropagation(),e([...s,f.key].join("."),n)},children:ft.t("Select")}),f.type==="object"&&i.jsx("div",{className:"cursor-pointer rounded p-1 hover:bg-muted",children:i.jsx(w.ChevronRightIcon,{className:"h-4 w-4 opacity-50"})})]})]},f.key))]})]})]})};function vo({data:t,onSelect:e,dataType:n="value"}){const[s,o]=g.useState(!1),r=$("collections",[]),a=g.useMemo(()=>n==="array"?{...r.map(c=>c.id).reduce((c,u)=>({...c,[U.COLLECTION_PREFIX+u]:[]}),{}),...t}:t,[t,r,n]);return i.jsxs(Ls,{open:s,onOpenChange:o,children:[i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:i.jsx(Ds,{asChild:!0,children:i.jsx(T.Button,{size:"sm",variant:"ghost",className:"h-5 rounded-sm px-1 py-0 text-[9px] text-muted-foreground",role:"combobox","aria-expanded":s,children:i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24px",height:"24px",viewBox:"0 0 24 24",fill:"none",children:i.jsx("path",{d:"M9.5 5H9C7.89543 5 7 5.89543 7 7V9C7 10 6.4 12 4 12C5 12 7 12.6 7 15V17.0002C7 18.1048 7.89543 19 9 19H9.5M14.5 5H15C16.1046 5 17 5.89543 17 7V9C17 10 17.6 12 20 12C19 12 17 12.6 17 15V17.0002C17 18.1048 16.1046 19 15 19H14.5",stroke:"#000000",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2"})})})})}),i.jsx(ae,{children:ft.t("Add field")})]}),i.jsx(Pn,{className:"z-[1000]! relative mr-3 w-[300px] p-0",children:i.jsx(Wm,{data:a,onSelect:(l,c)=>{e(l,c),o(!1)},dataType:n})})]})}const zl=({schema:t,onChange:e,id:n,formData:s})=>{const o=Dt(),r=$("flags.dataBinding",!0),a=Dd(),l=J(),c=g.useMemo(()=>{if(a.length===1)return"";const f=a.find(x=>x._type==="Repeater"),m=d.get(f,"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1");return`${U.REPEATER_PREFIX}${d.startsWith(m,U.COLLECTION_PREFIX)?`${m}/${f==null?void 0:f._id}`:m}`},[a]),u=g.useMemo(()=>d.first(d.get(o,c.replace(U.REPEATER_PREFIX,""),[])),[c,o]),p=g.useCallback((f,h)=>{if(f=d.isEmpty(c)?f:f.replace(`${c}`,"$index"),h==="array"||h==="object"){e(`{{${f}}}`,{},n);return}const m=k=>/[.,!?;:]/.test(k),x=(k,C,A)=>{let v="",j="";const I=C>0?k[C-1]:"",N=C<k.length?k[C]:"";return C>0&&(I==="."||!m(I)&&I!==" ")&&(v=" "),C<k.length&&!m(N)&&N!==" "&&(j=" "),{text:v+A+j,prefixLength:v.length,suffixLength:j.length}},b=document.getElementById(n);if(!b)return;const y=document.getElementById(`chai-rte-${n}`)||document.getElementById(`chai-rte-modal-${n}`);if(y&&(y.querySelector(".ProseMirror")||y.__chaiRTE)){const k=y.__chaiRTE;if(k){const C=`{{${f}}}`;k.commands.focus();const{from:A,to:v}=k.state.selection;if(A!==v)k.chain().deleteSelection().insertContent(C).run();else{const{state:I}=k,N=I.selection.from,E=I.doc.textBetween(Math.max(0,N-1),N),_=I.doc.textBetween(N,Math.min(N+1,I.doc.content.size));let B="";N>0&&E!==" "&&!m(E)&&(B=" ");let P="";_&&_!==" "&&!m(_)&&(P=" "),k.chain().insertContent(B+C+P).run()}setTimeout(()=>e(k.getHTML(),{},n),100);return}}else{const k=b,C=k.selectionStart||0,A=k.value||"",v=k.selectionEnd||C;if(v>C){const _=`{{${f}}}`,{text:B}=x(A,C,_),P=A.slice(0,C)+B+A.slice(v);e(P,{},n);return}const I=`{{${f}}}`,{text:N}=x(A,C,I),E=A.slice(0,C)+N+A.slice(C);e(E,{},n)}},[n,e,s,l==null?void 0:l._id,c]);return r?i.jsx(vo,{data:{...u&&{[c]:u},...o},onSelect:p,dataType:t.binding==="array"?"array":"value"}):null},Gm=t=>{const{id:e,classNames:n,label:s,children:o,errors:r,help:a,hidden:l,required:c,schema:u,formData:p,onChange:f}=t,{selectedLang:h,fallbackLang:m,languages:x}=Te(),b=g.useMemo(()=>d.isEmpty(x)?"":d.isEmpty(h)?m:h,[x,h,m]),y=g.useMemo(()=>d.get(Pt,b,b),[b]),k=Dt(),C=J(),A=K.useRegisteredChaiBlocks(),v=g.useMemo(()=>d.get(A,[C==null?void 0:C._type,"i18nProps"],[]),[A,C==null?void 0:C._type]),[j,I]=g.useState(null);if(l)return null;if(u.type==="boolean")return i.jsx("div",{className:n,children:o});const E=v==null?void 0:v.includes(e.replace("root.",""));if(u.type==="array"){const P=j===e;return i.jsxs("div",{className:`${n} relative`,children:[u.title&&i.jsx("div",{className:"flex items-center justify-between gap-1",children:i.jsxs("label",{htmlFor:e,onClick:()=>I(P?null:e),className:"flex cursor-pointer items-center gap-x-1 py-1 leading-tight duration-200 hover:bg-slate-100",children:[P?i.jsx(w.ChevronDownIcon,{className:"h-3 w-3"}):i.jsx(w.ChevronRightIcon,{className:"h-3 w-3"}),i.jsx(w.ListBulletIcon,{className:"h-3 w-3"}),i.jsx("span",{className:"leading-tight",children:s})," ",i.jsx(Ps,{className:"m-0 bg-gray-200 px-2 leading-tight text-gray-500 hover:bg-gray-200 hover:text-gray-500",children:i.jsx("span",{className:"text-[9px] font-medium text-slate-600",children:p==null?void 0:p.length})}),u.description&&i.jsx(xs,{children:i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:i.jsx(w.InfoCircledIcon,{className:"h-3 w-3 text-muted-foreground/70",onClick:R=>R.stopPropagation(),onMouseDown:R=>R.stopPropagation()})}),i.jsx(ae,{className:"max-w-xs",children:u.description})]})})]})}),(p==null?void 0:p.length)===0?i.jsx("div",{className:"h-0 overflow-hidden",children:o}):i.jsxs("div",{className:`${P?"pt-0.5":"h-0 overflow-hidden"}`,children:[o,r,a]})]})}const _=e.replace("root.",""),B=v.includes(_)&&!d.isEmpty(h)&&d.isEmpty(p);return i.jsxs("div",{className:n,children:[u.title&&i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("label",{htmlFor:e,className:u.type==="object"?"pb-2":"",children:[s," ",E&&i.jsxs("small",{className:"text-[9px] text-zinc-400",children:[" ",y]}),c&&u.type!=="object"?" *":null]}),u.description&&i.jsx(xs,{children:i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:i.jsx(w.InfoCircledIcon,{className:"h-3 w-3 text-muted-foreground/70"})}),i.jsx(ae,{className:"max-w-xs",children:u.description})]})})]}),!u.enum&&!u.oneOf&&k&&i.jsxs("span",{className:"flex items-center space-x-1",children:[B?i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:i.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",className:"lucide lucide-triangle-alert-icon lucide-triangle-alert h-3 w-3 text-orange-400",children:[i.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}),i.jsx("path",{d:"M12 9v4"}),i.jsx("path",{d:"M12 17h.01"})]})}),i.jsxs(ae,{className:"max-w-xs",children:["No translation provided. ",i.jsx("br",{}),"Using default language value."]})]}):null,i.jsx(zl,{schema:u,onChange:P=>{f(P,p,e)},id:e,formData:p})]})]}),o,r,a]})},Um=({href:t,onChange:e})=>{const{t:n}=z.useTranslation(),s=$("searchPageTypeItems",(v,j)=>[]),[o,r]=g.useState(!1),[a,l]=g.useState(!1),[c,u]=g.useState(""),[p,f]=g.useState([]),[h,m]=g.useState(-1),x=g.useRef(null);g.useEffect(()=>{if(u(""),f([]),m(-1),l(!1),!t||o||!d.startsWith(t,"pageType:"))return;const v=d.split(t,":");(async()=>{const j=await s("",[d.get(v,2,"page")]);j&&Array.isArray(j)&&u(d.get(j,[0,"name"],""))})()},[t]);const b=xe.useDebouncedCallback(async v=>{if(d.isEmpty(v))f([]);else{const j=await s("",v);f(j)}r(!1),m(-1)},[],300),y=v=>{const j=["pageType",v.pageType||"page",v.primaryPage??v.id];e(j.join(":")),u(v.name),l(!1),f([]),m(-1)},k=v=>{switch(v.key){case"ArrowDown":v.preventDefault(),m(j=>j<p.length-1?j+1:j);break;case"ArrowUp":v.preventDefault(),m(j=>j>0?j-1:j);break;case"Enter":if(v.preventDefault(),p.length===0)return;h>=0&&y(p[h]);break;case"Escape":v.preventDefault(),C();break}};g.useEffect(()=>{if(h>=0&&x.current){const v=x.current.children[h];v==null||v.scrollIntoView({block:"nearest"})}},[h]);const C=()=>{u(""),f([]),m(-1),l(!1),e("")},A=v=>{u(v),l(!d.isEmpty(v)),r(!0),b(v)};return i.jsxs("div",{children:[i.jsxs("div",{className:"group relative flex items-center",children:[i.jsx("input",{type:"text",value:c,onChange:v=>A(v.target.value),onKeyDown:k,placeholder:n("Search pages"),className:"w-full rounded-md border border-gray-300 p-2 pr-16"}),i.jsx("div",{className:"absolute bottom-2 right-2 top-3 flex items-center gap-1.5",children:c&&i.jsx("button",{onClick:C,className:"text-gray-400 hover:text-gray-600",title:n("Clear search"),children:i.jsx(w.Cross1Icon,{className:"h-4 w-4"})})})]}),(o||!d.isEmpty(p)||a&&d.isEmpty(p))&&i.jsx("div",{className:"absolute z-40 mt-2 max-h-40 w-full max-w-[250px] overflow-y-auto rounded-md border border-border bg-background shadow-lg",children:o?i.jsxs("div",{className:"space-y-1 p-2",children:[i.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),i.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):a&&d.isEmpty(p)?i.jsxs("div",{className:"flex items-center justify-center p-4 text-sm text-gray-500",children:[n("No results found for"),' "',c,'"']}):i.jsx("ul",{ref:x,children:d.map(p==null?void 0:p.slice(0,20),(v,j)=>i.jsxs("li",{onClick:()=>y(v),className:`cursor-pointer p-2 text-xs ${t!=null&&t.includes(v.id)?"bg-blue-200":j===h?"bg-gray-100":"hover:bg-gray-100"}`,children:[v.name," ",v.slug&&i.jsxs("small",{className:"font-light text-gray-500",children:["( ",v.slug," )"]}),v.lang&&i.jsx("small",{className:"ml-1 rounded bg-gray-200 px-1 py-0.5 text-[10px] font-medium text-gray-600",children:v.lang})]},v.id))})})]})},qm=({schema:t,formData:e,onChange:n,name:s})=>{const{t:o}=z.useTranslation(),{type:r="pageType",href:a="",target:l="self"}=e??{},c=$("pageTypes",[]),{selectedLang:u,fallbackLang:p,languages:f}=Te(),h=g.useMemo(()=>d.isEmpty(f)?"":d.isEmpty(u)?p:u,[f,u,p]),m=g.useMemo(()=>d.get(Pt,h,h),[h]),x=r==="pageType"&&d.isEmpty(c)?"url":r;return i.jsxs("div",{children:[i.jsxs("span",{className:"flex items-center justify-between gap-x-2 text-xs font-medium",children:[i.jsxs("span",{children:[(t==null?void 0:t.title)??"Link",i.jsx("span",{className:"pl-1 text-[9px] text-zinc-400",children:m})]}),i.jsx(zl,{schema:t,onChange:b=>{n({...e,href:b,...x==="pageType"?{type:"url"}:{}})},id:`root.${s}.href`,formData:e})]}),i.jsxs("div",{className:"flex flex-col gap-y-1.5",children:[i.jsx("select",{name:"type",value:r,onChange:b=>n({...e,type:b.target.value}),children:d.map([...d.isEmpty(c)?[]:[{const:"pageType",title:o("Goto Page")}],{const:"url",title:o("Open URL")},{const:"email",title:o("Compose Email")},{const:"telephone",title:o("Call Phone")},{const:"scroll",title:o("Scroll to element")}],b=>i.jsx("option",{value:b.const,children:b.title},b.const))}),x==="pageType"&&!d.isEmpty(c)?i.jsx(Um,{href:a,onChange:b=>n({...e,href:b})}):null,i.jsx("input",{id:`root.${s}.href`,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",name:"href",type:"text",className:x==="pageType"?"!hidden":"",value:a,onChange:b=>n({...e,href:b.target.value}),placeholder:o(r==="url"?"Enter URL":r==="scroll"?"#ElementID":"Enter details")}),x==="url"&&i.jsxs("div",{className:"flex items-center gap-x-2 text-muted-foreground",children:[i.jsx("input",{id:`root.${s}.target`,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",type:"checkbox",checked:l==="_blank",className:"!w-fit cursor-pointer rounded-md border border-border",onChange:()=>n({...e,target:l==="_blank"?"_self":"_blank"})}),i.jsx("span",{className:"pt-1 text-xs",children:o("Open in new tab")})]})]})]})},Km=({value:t,onChange:e})=>{var r;if(!t)return i.jsxs("div",{className:"mt-1 flex items-center gap-2 rounded-md border border-gray-200 bg-gray-50 px-2 py-1.5 text-xs text-gray-500 text-gray-600",children:[i.jsx(w.FileIcon,{className:"h-4 w-4"})," Choose a collection"]});const n=`{{${U.COLLECTION_PREFIX}`,s=t==null?void 0:t.startsWith(n);let o=t;return s&&(o=(r=t==null?void 0:t.replace(n,""))==null?void 0:r.replace("}}","")),i.jsx("div",{className:"mt-1 flex flex-col gap-1",children:i.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-blue-200 bg-blue-50 px-2 py-1 text-xs text-blue-600",children:[i.jsxs("span",{className:"flex max-w-[200px] items-center gap-2",children:[" ",s?i.jsx(w.IdCardIcon,{className:"h-3 min-h-3 w-3 min-w-3"}):null,i.jsxs(de,{delayDuration:500,children:[i.jsx(ue,{asChild:!0,children:i.jsx("span",{className:"cursor-default truncate",children:o})}),i.jsx(ae,{side:"left",hidden:o.length<50,children:o})]})]}),i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:i.jsx(T.Button,{variant:"ghost",size:"icon",className:"h-5 w-5 rounded-full bg-gray-200 text-gray-900 hover:bg-gray-300",onClick:()=>e(""),children:i.jsx(w.Cross1Icon,{className:"h-4 w-4"})})}),i.jsx(ae,{side:"left",children:"Remove binding"})]})]})})},Hl=S.atom(t=>{var a;const e=t(Ne),n=t(vs),s=n.length===1?n[0]:null;if(!s)return null;const o=d.find(e,{_id:s});if(!o)return null;let r=o._parent;for(;r;){const l=d.find(e,{_id:r});if(!l)return null;if((a=K.getRegisteredChaiBlock(l._type))!=null&&a.wrapper)return l;r=l._parent}return null});Hl.debugLabel="wrapperBlockAtom";const wo=()=>S.useAtomValue(Hl),Ym=()=>{const t=J(),e=wo(),{addCoreBlock:n}=bt();if(!t&&!e)return null;const s=(t==null?void 0:t._type)==="Row"?t:e;return i.jsx("div",{className:"pt-1",children:i.jsxs("button",{type:"button",className:"duratiom-300 flex items-center gap-x-1 rounded border border-gray-400 bg-gray-100 px-4 py-1 text-[11px] font-medium leading-tight hover:bg-slate-200",onClick:()=>n({type:"Column",styles:"#styles:,"},s==null?void 0:s._id),children:[i.jsx(w.PlusIcon,{className:"h-4 w-4"})," Add Column"]})})},Jm=g.lazy(()=>Promise.resolve().then(()=>require("./rte-widget-modal-CsTqFJc_.cjs"))),Xm=({blockId:t,id:e,placeholder:n,value:s,onChange:o,onBlur:r})=>{const a=g.useRef(null),[l,c]=g.useState(!1),u=Tl({blockId:t,value:s,placeholder:n,onBlur:({editor:h})=>{const m=h==null?void 0:h.getHTML();r(e,m)},onUpdate:({editor:h})=>{const m=h==null?void 0:h.getHTML();o(m)}});g.useEffect(()=>{a.current&&u&&(a.current.__chaiRTE=u)},[t,u]);const p=()=>{c(!1)},f=i.jsxs("div",{id:`chai-rte-${e}`,ref:a,className:"mt-1 rounded-md border border-input",children:[i.jsx(Ma,{editor:u,onExpand:()=>c(!0)}),i.jsx(ss.EditorContent,{editor:u,id:e,placeholder:n,className:`overflow-auto ${l?"max-h-[500px] min-h-[400px]":"max-h-[200px] min-h-[100px]"}`},e)]});return i.jsxs(i.Fragment,{children:[l&&i.jsx(g.Suspense,{fallback:i.jsx("div",{children:"Loading..."}),children:i.jsx(Jm,{isOpen:l,onClose:p,editor:u,rteElement:f})}),l?i.jsx("div",{children:"Open in modal"}):i.jsx("div",{className:"relative",children:f})]})},Zm=t=>{const{editingBlockId:e}=Mt(),[n,s]=g.useState(null),o=J(),r=o==null?void 0:o._id;return g.useEffect(()=>{s(r)},[r]),n&&n!==e?i.jsx(Xm,{...t,blockId:n},n):null},Qm=({formData:t,onChange:e})=>{const[n]=Z(),s=J(),o=wo(),{addCoreBlock:r}=bt(),[,a]=q(),l=(s==null?void 0:s._type)==="Slider"?s:o,c=d.find(n,{_parent:l==null?void 0:l._id,_type:"Slides"}),u=d.filter(n,{_parent:c==null?void 0:c._id,_type:"Slide"}),p=(t==null?void 0:t.currentSlide)||d.get(u,"0._id");if(g.useEffect(()=>{(s==null?void 0:s._type)==="Slide"&&(t==null?void 0:t.currentSlide)!==(s==null?void 0:s._id)&&e({...t,currentSlide:s==null?void 0:s._id})},[s]),g.useEffect(()=>{u!=null&&u.length&&!d.find(u,{_id:t==null?void 0:t.currentSlide})&&e({...t,currentSlide:d.get(u,"0._id")})},[t,u]),!s&&!o||!c)return null;const f=()=>{const x=d.findIndex(u,{_id:p});if(x>-1){const b=(x+1)%u.length,y=d.get(u,[b,"_id"]);if(!y)return;e({...t,currentSlide:y}),a([y])}},h=()=>{const x=d.findIndex(u,{_id:p});if(x>-1){const b=(x-1+u.length)%u.length,y=d.get(u,[b,"_id"]);if(!y)return;e({...t,currentSlide:y}),a([y])}},m=()=>{const x=r({styles:"#styles:,h-full w-full min-w-full",type:"Slide"},c==null?void 0:c._id),b=x==null?void 0:x._id;b&&(e({...t,currentSlide:b}),a([b]))};return i.jsxs("div",{className:"space-y-1.5 px-2",children:[i.jsxs("div",{className:"flex items-center gap-x-2 pb-2 text-[12px]",children:[i.jsx("button",{onClick:h,className:"rounded bg-gray-200 p-1.5 hover:opacity-80",children:i.jsx(w.ChevronLeftIcon,{className:"h-3 w-3"})}),i.jsx("div",{className:"whitespace-nowrap text-center text-[10px] text-slate-500",children:p?i.jsxs("span",{className:"",children:[i.jsxs("b",{className:"text-[12px]",children:[" ",d.findIndex(u,{_id:p})+1]}),"/",u.length]}):"-"}),i.jsx("button",{onClick:f,className:"rounded bg-gray-200 p-1.5 hover:opacity-80",children:i.jsx(w.ChevronRightIcon,{className:"h-3 w-3"})}),i.jsxs("button",{onClick:m,className:"flex w-full items-center justify-center gap-x-1 rounded bg-gray-200 p-1.5 text-xs font-medium leading-tight hover:opacity-80",children:[i.jsx(w.PlusCircledIcon,{className:"h-3 w-3"}),"Add Slide"]})]}),i.jsxs("div",{className:"flex items-center gap-x-2 leading-tight",children:[i.jsx("input",{type:"checkbox",checked:!!(t!=null&&t.showSlideButton),onChange:()=>e({...t,showSlideButton:!(t!=null&&t.showSlideButton)}),className:"cursor-pointer"}),i.jsx("label",{htmlFor:"autoplay",className:"mt-0.5 text-[12px]",children:"Show Slide Buttons"})]}),i.jsxs("div",{className:"flex items-center gap-x-2 leading-tight",children:[i.jsx("input",{type:"checkbox",checked:!!(t!=null&&t.showSlideNavbar),onChange:()=>e({...t,showSlideNavbar:!(t!=null&&t.showSlideNavbar)}),className:"cursor-pointer"}),i.jsx("label",{htmlFor:"autoplay",className:"mt-0.5 text-[12px]",children:"Show Slide Navbar"})]}),i.jsx("div",{children:i.jsxs("div",{className:"flex flex-col",children:[i.jsxs("div",{className:"flex items-center gap-x-2 leading-tight",children:[i.jsx("input",{type:"checkbox",checked:!!(t!=null&&t.autoplay),onChange:()=>e({...t,autoplay:!(t!=null&&t.autoplay)}),className:"cursor-pointer"}),i.jsx("label",{htmlFor:"autoplay",className:"mt-0.5 text-[12px]",children:"Autoplay slides"})]}),(t==null?void 0:t.autoplay)&&i.jsxs("div",{className:"pt-0.5 leading-tight",children:[i.jsxs("label",{htmlFor:"interval",className:"whitespace-nowrap text-[9px]",children:["Autoplay Interval ",i.jsx("span",{className:"font-light opacity-80",children:"(in seconds)"})]}),i.jsx("input",{type:"number",id:"interval",name:"interval",placeholder:"0",value:t==null?void 0:t.autoplayInterval,className:"text-xs",pattern:"[0-9]*",onChange:x=>{let b=x.target.value;b.length&&(b=b.replace("-","")),e({...t,autoplayInterval:b})}})]})]})})]})},eg=({formData:t,onChange:e})=>{const n=d.get(t,"srcsets",[])||[],s=(a,l)=>{const c=a.target.name,u=a.target.value;e({srcsets:d.map(n,(p,f)=>f===l?{...p,[c]:u}:p)})},o=()=>{e({srcsets:[...n,{}]})},r=a=>{e({srcsets:d.reject(n,(l,c)=>parseInt(c)===a)})};return i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between pb-2",children:[i.jsx("label",{children:"Responsive Video (optional)"}),i.jsx("button",{type:"button",onClick:o,className:"flex items-center gap-x-1 rounded-md border border-blue-500 bg-blue-100 px-2 py-px text-xs text-blue-600 hover:opacity-80",children:i.jsx(w.PlusIcon,{className:"h-3 w-3"})})]}),i.jsx("div",{className:"space-y-2",children:n.length===0?i.jsx("div",{className:"rounded border border-dashed border-gray-200 p-2 text-xs italic text-gray-500",children:"Add additional sources to create responsive videos"}):d.map(n,(a,l)=>i.jsxs("div",{className:"group relative space-y-1.5 rounded border border-gray-200 px-2 pb-1.5",children:[i.jsx("button",{type:"button",onClick:()=>r(l),className:"absolute -right-px -top-0 -translate-y-1/2 rounded-full bg-red-100 p-1 opacity-0 hover:bg-red-200 group-hover:opacity-100",children:i.jsx(w.Cross1Icon,{className:"h-2.5 w-2.5 text-red-500"})}),i.jsxs("div",{className:"flex items-center gap-x-2 rounded border",children:[i.jsx("label",{className:"flex !h-6 h-full w-1/4 items-center justify-center bg-gray-200 px-2 !text-[10px] !font-medium",children:"Width"}),i.jsx("input",{name:"width",placeholder:"Enter width (in px)",type:"number",value:d.get(a,"width"),onChange:c=>s(c,l),className:"!placeholder:text-gray-100 !mt-0 !rounded-none !border-0 !p-0 !text-xs"})]}),i.jsxs("div",{className:"flex items-center gap-x-2 rounded border",children:[i.jsx("label",{className:"flex !h-6 h-full w-1/4 items-center justify-center bg-gray-200 px-2 !text-[10px] !font-medium",children:"URL"}),i.jsx("input",{name:"url",placeholder:"Enter url",className:"!mt-0 !rounded-none !border-0 !p-0 !text-xs !shadow-none",value:d.get(a,"url",""),onChange:c=>s(c,l)})]})]},l))})]})},tg=t=>i.jsx("button",{...t,className:"duration absolute right-2 top-2 cursor-pointer text-blue-400 hover:text-blue-500",children:i.jsxs("div",{className:"flex items-center gap-x-0.5 text-[11px] leading-tight",children:[i.jsx(w.PlusIcon,{className:"h-3 w-3"})," ",i.jsx("span",{children:"Add"})]})}),gi=g.memo(({blockId:t,schema:e,uiSchema:n,formData:s,onChange:o})=>{const{selectedLang:r}=Te(),a=T.useChaiBlockSettingComponents("widget"),l=T.useChaiBlockSettingComponents("field"),c=T.useChaiBlockSettingComponents("template"),u=xe.useThrottledCallback(async({formData:p},f)=>{d.get(p,f)===void 0&&d.set(p,f,""),o({formData:p},f)},[o,r],400);return i.jsx(Gc,{widgets:{richtext:Zm,icon:Mm,image:zm,code:Rm,colCount:Ym,collectionSelect:Pm,repeaterBinding:Km,...a},fields:{link:qm,slider:Qm,sources:eg,...l},templates:{FieldTemplate:Gm,ButtonTemplates:{AddButton:tg},...c},idSeparator:".",autoComplete:"off",omitExtraData:!1,liveOmit:!1,liveValidate:!1,validator:Uc,uiSchema:n,schema:e,formData:s,onChange:({formData:p},f)=>{if(!f||t!==(p==null?void 0:p._id))return;const h=d.take(f.split("."),2).join(".").replace("root.","");u({formData:p},h)}},r)}),Ln=O.forwardRef(({className:t,thumbClassName:e,...n},s)=>i.jsx(dr.Root,{className:T.cn("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",t),...n,ref:s,children:i.jsx(dr.Thumb,{className:T.cn("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform",e,"data-[state=checked]:translate-x-3 data-[state=unchecked]:translate-x-0")})}));Ln.displayName=dr.Root.displayName;const ng=new ne.k({tags:["{{","}}"],autoEscape:!0,autoTrim:!1,useWith:!0,parse:{interpolate:"",exec:"~",raw:"~"}}),sg=[/\b(?:window|document|globalThis|process|Function|eval|import|fetch|XMLHttpRequest|WebSocket|localStorage|sessionStorage)\b/,/(^|[^=!<>])=([^=]|$)/,/\b(?:while|for|try|catch|class|new)\b/],Vl=t=>d.isArray(t)?"array":t===null?"null":d.isObject(t)?"JSON":typeof t,rr=(t,e)=>{const n=e?d.get(t,e):t;return!d.isObject(n)||n===null||d.isArray(n)?[]:Object.entries(n).filter(([s])=>!s.startsWith("#")).map(([s,o])=>({path:e?`${e}.${s}`:s,type:Vl(o)}))},Jn=t=>{const e=t.trim();if(!e)return null;if(sg.some(s=>s.test(e)))return"Unsafe expression detected";try{return ng.compile(`{{${e}}}`),null}catch{return"Invalid expression syntax"}},rg=({currentExpression:t,externalData:e,onSave:n})=>{const s=g.useRef(null),o=g.useRef(null),[r,a]=g.useState(t),[l,c]=g.useState(null),[u,p]=g.useState(0),[f,h]=g.useState(null);g.useEffect(()=>{a(t),c(Jn(t)),h(null),p(0)},[t]);const m=g.useMemo(()=>Object.entries(e??{}).filter(([y])=>!y.startsWith("#")).map(([y,k])=>({key:y,type:Vl(k)})),[e]),x=(y,k)=>{const A=y.slice(0,k).match(/[A-Za-z_$][\w$.]*\.?$/);if(!A){h(null);return}const v=A[0];let j;if(v.endsWith(".")){const I=v.slice(0,-1);j=rr(e,I)}else{const I=v.lastIndexOf(".");if(I===-1)j=rr(e,"").filter(N=>N.path.toLowerCase().startsWith(v.toLowerCase()));else{const N=v.slice(0,I),E=v.slice(I+1).toLowerCase();j=rr(e,N).filter(_=>_.path.slice(_.path.lastIndexOf(".")+1).toLowerCase().startsWith(E))}}if(j=j.slice(0,8),!j.length){h(null),p(0);return}h({start:k-v.length,end:k,options:j}),p(0)},b=y=>{if(!f)return;const k=r.slice(0,f.start)+y+r.slice(f.end);a(k),c(Jn(k)),h(null),p(0),requestAnimationFrame(()=>{var A,v;const C=f.start+y.length;(A=s.current)==null||A.focus(),(v=s.current)==null||v.setSelectionRange(C,C)})};return g.useEffect(()=>{if(!f||!o.current)return;const y=o.current.children[u];y==null||y.scrollIntoView({block:"nearest"})},[u,f]),i.jsxs("div",{className:"grid gap-2",children:[i.jsxs("div",{children:[i.jsx("p",{className:"mb-1 text-[10px] font-medium text-muted-foreground",children:"Data"}),i.jsx("div",{className:"flex flex-wrap gap-1",children:m.map(y=>i.jsxs("span",{className:"inline-flex items-center rounded bg-muted px-1.5 py-0.5 text-[10px]",children:[i.jsx("span",{className:"font-medium",children:y.key}),i.jsxs("span",{className:"ml-0.5 text-muted-foreground",children:[": ",y.type]})]},y.key))})]}),i.jsxs("div",{className:"relative",children:[i.jsx(T.Input,{ref:s,id:"expression",value:r,className:`h-8 text-xs ${l?"border-red-500":""}`,onChange:y=>{const k=y.target.value,C=y.target.selectionStart??k.length;a(k),c(Jn(k)),x(k,C)},onKeyDown:y=>{if(f&&f.options.length){if(y.key==="ArrowDown"){y.preventDefault(),p(k=>k>=f.options.length-1?0:k+1);return}if(y.key==="ArrowUp"){y.preventDefault(),p(k=>k<=0?f.options.length-1:k-1);return}if(y.key==="Enter"||y.key==="Tab"){y.preventDefault();const k=f.options[u];k&&b(k.path);return}if(y.key==="Escape"){y.preventDefault(),h(null),p(0);return}}if(y.key==="Enter"){y.preventDefault();const k=Jn(r);c(k),k||n(r.trim())}},placeholder:"name === 'x'",autoComplete:"off"}),f&&i.jsx("div",{ref:o,className:"absolute z-20 mt-1 max-h-36 w-full overflow-auto rounded border bg-background p-1 shadow",children:f.options.map((y,k)=>i.jsxs("button",{type:"button",className:`block w-full rounded px-2 py-1 text-left text-[10px] hover:bg-muted ${k===u?"bg-muted":""}`,onMouseDown:C=>{C.preventDefault(),b(y.path)},children:[i.jsx("span",{className:"font-medium",children:y.path.slice(y.path.lastIndexOf(".")+1)}),i.jsxs("span",{className:"ml-1 text-muted-foreground",children:[": ",y.type]})]},y.path))})]}),l&&i.jsx("p",{className:"text-[10px] text-red-500",children:l})]})},og=()=>{const{t}=z.useTranslation(),e=J(),n=Dt(),s=Ke(),[o,r]=g.useState(!1),a=h=>{if(e){if(!h||h.trim()===""){d.isString(e._show)&&s([e._id],{_show:!0});return}s([e._id],{_show:`{{${h.trim()}}}`})}},l=h=>{r(h)},c=()=>{if(!e)return;const h=d.has(e,"_show")?e._show:!0;s([e._id],{_show:!h})},u=()=>{e&&(s([e._id],{_show:!0}),r(!1))};if(!e)return null;const p=d.isString(e._show),f=p?e._show.startsWith("{{")&&e._show.endsWith("}}")?e._show.slice(2,-2).trim():e._show:"";return i.jsxs("div",{className:"my-2 flex items-center justify-between",children:[i.jsx("p",{className:"text-xs text-gray-500",children:t("Visibility")}),i.jsxs("div",{className:"group relative",children:[i.jsxs(Ls,{open:o,onOpenChange:l,children:[i.jsx(Ds,{asChild:!0,children:i.jsx("div",{className:`absolute -left-2 -top-1.5 z-10 h-3.5 w-3.5 cursor-pointer rounded-full border border-white bg-blue-500 transition-all hover:scale-125 ${p?"opacity-100":"opacity-0 group-hover:opacity-100"}`})}),i.jsx(Pn,{side:"left",className:"w-64 p-3",children:i.jsxs("div",{className:"grid gap-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"space-y-1",children:[i.jsx("h4",{className:"text-xs font-medium leading-none",children:t("Conditional Visibility")}),i.jsx("p",{className:"text-[10px] text-muted-foreground",children:t("Enter a JavaScript expression")})]}),p&&i.jsx(T.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-red-500",onClick:u,children:i.jsx(w.TrashIcon,{className:"h-3.5 w-3.5"})})]}),i.jsx("div",{className:"relative",children:i.jsx(rg,{currentExpression:f,externalData:n,onSave:h=>{a(h),r(!1)}})})]})})]}),i.jsx(Ln,{checked:p?!0:d.has(e,"_show")?e._show:!0,onCheckedChange:c,disabled:p})]})]})},xi=(t,e,n)=>{const s=d.cloneDeep(t);return d.forEach(d.keys(t),o=>{d.includes(d.get(n,"i18nProps",[]),o)&&!d.isEmpty(e)&&(s[o]=d.get(t,`${o}-${e}`))}),s};function yr(){const{selectedLang:t}=Te(),e=J(),n=Or(),s=Ke(),o=K.getRegisteredChaiBlock(e==null?void 0:e._type),r=xi(e,t,o),[a,l]=g.useState(r),[c,u]=g.useState(!1),p=wo(),f=K.getRegisteredChaiBlock(p==null?void 0:p._type),h=xi(p,t,f),m=({formData:j},I,N)=>{I&&(a==null?void 0:a._id)===e._id&&s([e._id],{[I]:d.get(j,I)},N)},x=g.useCallback(d.debounce(({formData:j},I,N)=>{m({formData:j},I,N),l(j)},1500),[e==null?void 0:e._id,t]),b=({formData:j},I)=>{I&&(n([e._id],{[I]:d.get(j,I)}),x({formData:j},I,{[I]:d.get(a,I)}))},y=({formData:j},I)=>{I&&(n([p._id],{[I]:d.get(j,I)}),x({formData:j},I,{[I]:d.get(a,I)}))},{schema:k,uiSchema:C}=g.useMemo(()=>{const j=e==null?void 0:e._type;if(!j)return{schema:{},uiSchema:{}};try{const{schema:I,uiSchema:N}=K.getBlockFormSchemas(j);if(j==="Repeater"){const E=d.get(e,"repeaterItems","");d.startsWith(E,`{{${U.COLLECTION_PREFIX}`)?(d.set(N,"filter",{"ui:widget":"collectionSelect"}),d.set(N,"sort",{"ui:widget":"collectionSelect"})):(d.set(N,"filter",{"ui:widget":"hidden"}),d.set(N,"sort",{"ui:widget":"hidden"}))}return{schema:I,uiSchema:N}}catch{return{schema:{},uiSchema:{}}}},[e]),{wrapperSchema:A,wrapperUiSchema:v}=g.useMemo(()=>{if(!p||!(p!=null&&p._type))return{wrapperSchema:{},wrapperUiSchema:{}};const j=p==null?void 0:p._type,{schema:I={},uiSchema:N={}}=K.getBlockFormSchemas(j);return{wrapperSchema:I,wrapperUiSchema:N}},[p]);return i.jsxs("div",{className:"no-scrollbar overflow-x-hidden px-px",children:[i.jsx(og,{}),!d.isEmpty(p)&&i.jsxs("div",{className:"mb-4 rounded border bg-zinc-100 px-1",children:[i.jsxs("div",{onClick:()=>u(j=>!j),className:"flex cursor-pointer items-center gap-x-1 py-2 text-xs font-medium leading-tight hover:bg-slate-100",children:[c?i.jsx(w.ChevronDownIcon,{className:"h-4 w-4 text-slate-400"}):i.jsx(w.ChevronRightIcon,{className:"h-4 w-4 text-slate-400"}),d.startCase(p._type)," settings"," ",p._name&&i.jsxs("span",{className:"text-[11px] font-light text-slate-400",children:["(",p._name,")"]})]}),i.jsx("div",{className:c?"h-auto":"invisible h-0",children:i.jsx(gi,{blockId:p==null?void 0:p._id,onChange:y,formData:h,schema:A,uiSchema:v})})]}),d.isEmpty(k)?null:i.jsx(gi,{blockId:e==null?void 0:e._id,onChange:b,formData:r,schema:k,uiSchema:C})]})}const ig=Tt.Root,Wl=O.forwardRef(({className:t,...e},n)=>i.jsx(Tt.Item,{ref:n,className:T.cn("border-b",t),...e}));Wl.displayName="AccordionItem";const Gl=O.forwardRef(({className:t,children:e,...n},s)=>i.jsx(Tt.Header,{className:"flex",children:i.jsxs(Tt.Trigger,{ref:s,className:T.cn("flex flex-1 items-center justify-between py-4 text-left text-sm font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",t),...n,children:[e,i.jsx(w.ChevronDownIcon,{className:"h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200"})]})}));Gl.displayName=Tt.Trigger.displayName;const Ul=O.forwardRef(({className:t,children:e,...n},s)=>i.jsx(Tt.Content,{ref:s,className:"overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...n,children:i.jsx("div",{className:T.cn("pb-4 pt-0",t),children:e})}));Ul.displayName=Tt.Content.displayName;const ag=S.atom(null,(t,e,{blockIds:n,fullClasses:s})=>{const o=d.first(t(_n)),r=d.filter(t(Nn),a=>n.includes(t(a)._id));return d.map(r,a=>{const l=t(a),c=s;let{classes:u,baseClasses:p}=ne.getSplitChaiClasses(d.get(l,o.prop,`${U.STYLES_KEY},`));return d.each(c,f=>{const h=f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),m=new RegExp(`(^|\\s)${h}(?=\\s|$)`,"g");u=u.replace(m," ").replace(/\s+/g," ").trim();const x=d.first(f.split(":"));d.includes(["2xl","xl","lg","md","sm"],x)&&c.push(f.split(":").pop().trim())}),d.each(c,f=>{const h=f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),m=new RegExp(`(^|\\s)${h}(?=\\s|$)`,"g");p=p.replace(m," ").replace(/\s+/g," ").trim()}),{ids:[l._id],props:{[o.prop]:`${U.STYLES_KEY}${p},${u}`}}})}),lg=t=>{const e=Object.keys(t).filter(s=>typeof t[s]=="string"&&t[s].startsWith(U.STYLES_KEY)),n={};return e.forEach(s=>{n[s]=`${U.STYLES_KEY},`}),{ids:[t._id],props:n}},cg=()=>{const{updateBlocks:t,updateBlocksRuntime:e}=Ee();return g.useCallback((n,s=!1)=>{const{ids:o,props:r}=lg(n);s?t(o,r):e(o,r)},[t,e])},Co=()=>{const{updateBlocks:t,updateBlocksRuntime:e}=Ee(),n=S.useSetAtom(ag);return g.useCallback((s,o,r=!1)=>{const a=n({blockIds:s,fullClasses:o});r?t(s,a[0].props):e(s,a[0].props)},[n])},ql=()=>{const t=J(),e=Ke(),n=g.useCallback(a=>K.getBlockDefaultProps(a)||{},[]),s=g.useCallback(a=>Object.keys(a).filter(l=>typeof a[l]=="string"&&a[l].startsWith("#styles:")),[]),o=g.useCallback(a=>{if(!t)return;const c=n(t._type)[a]??"#styles:,";e([t._id],{[a]:c})},[t,n,e]);return{resetAll:g.useCallback(()=>{if(!t)return;const a=s(t);if(a.length===0)return;const l=n(t._type),c=d.pick(l,a);e([t._id],c)},[t,s,n,e]),reset:o}},dg=()=>{var m;const t=J(),[e,n]=Ae(),s=Co(),[o]=q(),{t:r}=z.useTranslation(),{reset:a}=ql();if(!t)return null;const l=Object.keys(t).filter(x=>typeof t[x]=="string"&&t[x].startsWith("#styles:")),c=!d.isEmpty(l)&&l.length>1,u=d.get(t,(m=e[0])==null?void 0:m.prop,""),{classes:p=""}=ne.getSplitChaiClasses(u)||{},f=p?p.split(" ").filter(x=>!d.isEmpty(x)):[],h=x=>d.find(e,b=>b.prop===x);return i.jsx(i.Fragment,{children:c&&i.jsxs("div",{className:"flex flex-wrap gap-1",children:[i.jsxs("label",{htmlFor:"block-styling-props",className:"py-1 text-xs",children:[r("Style element"),":"]}),i.jsx("div",{className:"flex flex-wrap gap-2",children:d.map(l,x=>i.jsxs(Ps,{className:"flex cursor-pointer items-center gap-1 pr-1",variant:h(x)?"default":"secondary",onClick:()=>{n([{id:`${x}-${t._id}`,blockId:t._id,prop:x}])},children:[d.startCase(x),i.jsxs(gt,{children:[i.jsx(xt,{asChild:!0,children:i.jsx("button",{type:"button",className:"ml-1 rounded-sm p-0.5 hover:bg-blue-300 hover:text-blue-600",onClick:b=>b.stopPropagation(),children:i.jsx(w.DotsVerticalIcon,{className:"h-3 w-3"})})}),i.jsxs(Ze,{side:"bottom",className:"border-border text-xs",children:[i.jsx(ge,{className:"text-xs",onClick:()=>{a(x)},children:r("Reset style")}),i.jsx(ge,{className:"text-xs",onClick:()=>{s(o,f,!0)},children:r("Clear styles")})]})]})]},x))}),i.jsx("div",{className:"my-2 h-[1px] w-full bg-border"})]})})},Kl=g.createContext({setDragData:()=>{}}),bi=(t,e)=>{t=t.toLowerCase();let n=t.trim().replace(/ |\+/g,"");if((n==="auto"||n==="none")&&e.includes(n))return{value:"",unit:n};const s=e.length?new RegExp(e.join("|"),"g"):/XXXXXX/g;n=n.replace(s,"");const o=t.match(s),r=o&&o.length>1,a=!d.isEmpty(n)&&Number.isNaN(Number(n));return r||a?{error:"Invalid value"}:o&&(o[0]==="auto"||o[0]==="none")?{value:o[0],unit:""}:{value:n,unit:o?o[0]:""}},ug=t=>{const e=t.startsWith("-")?"-":"",n=t.split("-").pop();if(["auto","none"].includes(n))return{value:"",unit:n};if(n==="px")return{value:"1",unit:"px"};if(n==="screen")return{value:"100",unit:t.indexOf("w-")!==-1?"vw":"vh"};if(n==="full")return{value:"100",unit:"%"};if(d.includes(t,"skew-"))return{value:`${e}${n}`,unit:"deg"};if(d.includes(t,"rotate-"))return{value:`${e}${n}`,unit:"deg"};if(d.includes(t,"opacity-"))return{value:`${n/100}`,unit:"-"};if(d.includes(t,"duration-")||d.includes(t,"delay-"))return{value:`${n}`,unit:"ms"};if(d.includes(t,"translate-")&&!n.includes("/"))return{value:`${e}${`${n/4}`}`,unit:"rem"};if(d.includes(t,"scale-"))return{value:`${e}${`${n/100}`}`,unit:"-"};if(d.startsWith(t,"border")){const s=t.match(/border-?(x|y|t|r|b|l)?\d+/g);if(s)return{value:s[0].split("-").pop(),unit:"px"};if(t.match(/border-?(x|y|t|r|b|l)?/g))return{value:"1",unit:"px"}}if(d.startsWith(t,"max-w-")){if(t==="max-w-screen-sm")return{value:"640",unit:"px"};if(t==="max-w-screen-md")return{value:"768",unit:"px"};if(t==="max-w-screen-lg")return{value:"1024",unit:"px"};if(t==="max-w-screen-xl")return{value:"1280",unit:"px"};if(t==="max-w-screen-2xl")return{value:"1536",unit:"px"};if(n==="xs")return{value:"320",unit:"px"};if(n==="sm")return{value:"384",unit:"px"};if(n==="md")return{value:"448",unit:"px"};if(n==="lg")return{value:"512",unit:"px"};if(n==="xl")return{value:"576",unit:"px"};if(n==="2xl")return{value:"672",unit:"px"};if(n==="3xl")return{value:"768",unit:"px"};if(n==="4xl")return{value:"896",unit:"px"};if(n==="5xl")return{value:"1024",unit:"px"};if(n==="6xl")return{value:"1152",unit:"px"};if(n==="7xl")return{value:"1280",unit:"px"};if(n==="prose")return{value:"65",unit:"ch"}}if(d.startsWith(t,"text-")){if(n==="xs")return{value:"12",unit:"px"};if(n==="sm")return{value:"14",unit:"px"};if(n==="base")return{value:"16",unit:"px"};if(n==="lg")return{value:"18",unit:"px"};if(n==="xl")return{value:"20",unit:"px"};if(n==="2xl")return{value:"24",unit:"px"};if(n==="3xl")return{value:"30",unit:"px"};if(n==="4xl")return{value:"36",unit:"px"};if(n==="5xl")return{value:"48",unit:"px"};if(n==="6xl")return{value:"60",unit:"px"};if(n==="7xl")return{value:"72",unit:"px"};if(n==="8xl")return{value:"96",unit:"px"};if(n==="9xl")return{value:"128",unit:"px"}}if(d.startsWith(t,"leading-")){if(n==="none")return{value:"1",unit:"-"};if(n==="tight")return{value:"1.25",unit:"-"};if(n==="snug")return{value:"1.375",unit:"-"};if(n==="normal")return{value:"1.5",unit:"-"};if(n==="relaxed")return{value:"1.625",unit:"-"};if(n==="loose")return{value:"2",unit:"-"}}if(d.startsWith(t,"tracking-")){if(n==="tighter")return{value:"-0.05",unit:"em"};if(n==="tight")return{value:"-0.025",unit:"em"};if(n==="normal")return{value:"0",unit:"em"};if(n==="wide")return{value:"0.025",unit:"em"};if(n==="wider")return{value:"0.05",unit:"em"};if(n==="widest")return{value:"0.1",unit:"em"}}if(["max","min","fit"].includes(n))return{value:t,unit:"class"};if(n.includes("/")){const[s,o]=d.map(n.split("/"),r=>parseInt(r,10));return{value:e+(s/o*100).toFixed(2).replace(".00",""),unit:"%"}}return d.isNumber(parseFloat(n))?{value:`${e+parseFloat(n)*4}`,unit:"px"}:{value:n,unit:"class"}},Yl=t=>{if(d.isEmpty(t))return{value:"",unit:""};const e=t.match(/\[.*\]/g);if(e===null)return pg(t);const n=d.get(e,"0","").replace(/\[|\]/g,""),s=t.startsWith("-")?"-":"",o=d.first(n.match(/\d+.\d+|\d+/g));return{value:`${s}${o}`,unit:n.replace(o,"")}},pg=t=>d.isEmpty(t)?{value:"",unit:""}:ug(t),fg=({unit:t,currentValue:e,onDrag:n,onDragEnd:s,onDragStart:o,negative:r,cssProperty:a})=>{const{setDragData:l}=g.useContext(Kl);return i.jsx("button",{type:"button",onMouseDown:c=>{const u={onDrag:n,onDragEnd:s,dragging:!0,dragStartY:c.pageY,dragStartValue:`${e}`,dragUnit:t,negative:r,cssProperty:a};o(u),l(u)},color:void 0,className:"relative z-50 ml-1 hidden h-6 cursor-row-resize rounded bg-background/70 px-2 group-hover:inline",children:i.jsx(w.RowSpacingIcon,{})})},hg=({onSelect:t,current:e,units:n})=>i.jsx("div",{"data-theme":"light",className:"-m-[7px] -mx-[13px] flex w-9 flex-col",children:n.map(s=>i.jsx(T.Button,{className:"h-max rounded-none px-1 py-1 text-right text-[11px] hover:bg-blue-400",color:e===s?"primary":void 0,size:"sm",onClick:o=>{o.stopPropagation(),t(s)},children:s},s))}),yi=50,mg=t=>{const[e,n]=g.useState(!1),[s,o]=g.useState(""),{currentClass:r,onChange:a,classPrefix:l,cssProperty:c,units:u,negative:p}=t,[f,h]=g.useState(c!=null&&c.toLowerCase().includes("width")?"%":u[0]),[m,x]=g.useState(!1),[b,y]=g.useState(""),[k,C]=g.useState(!1),[A,v]=g.useState(!1);g.useEffect(()=>{const{value:_,unit:B}=Yl(r);if(B===""){o(_),h(c!=null&&c.toLowerCase().includes("width")?"%":d.first(u));return}h(B),o(B==="class"||d.isEmpty(_)?"":_)},[r,c,u]);const j=xe.useThrottledCallback(_=>a(_),[a],yi),I=xe.useThrottledCallback(_=>a(_,!1),[a],yi),N=g.useCallback((_=!1)=>{const B=bi(`${s}`,u);if(d.get(B,"error",!1)){x(!0);return}const P=d.get(B,"unit")!==""?d.get(B,"unit"):f;if(P==="auto"||P==="none"){j(`${l}${P}`);return}if(d.get(B,"value")==="")return;const M=`${d.get(B,"value","").startsWith("-")?"-":""}${l}[${d.get(B,"value","").replace("-","")}${P==="-"?"":P}]`;_?I(M):j(M)},[j,I,s,f,l,u]),E=g.useCallback(_=>{const B=bi(`${s}`,u);if(d.get(B,"error",!1)){x(!0);return}if(_==="auto"||_==="none"){j(`${l}${_}`);return}if(d.get(B,"value")==="")return;const P=d.get(B,"unit")!==""?d.get(B,"unit"):_,M=`${d.get(B,"value","").startsWith("-")?"-":""}${l}[${d.get(B,"value","").replace("-","")}${P==="-"?"":P}]`;j(M)},[j,s,l,u]);return i.jsx("div",{className:"flex w-full flex-col",children:i.jsx("div",{className:"flex items-center justify-start",children:f==="class"?i.jsxs(i.Fragment,{children:[i.jsx("input",{className:"h-6 w-24 rounded border border-foreground/20 bg-background px-2 py-0.5 text-sm focus-visible:outline-0",readOnly:!0,value:r}),i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:i.jsx("button",{type:"button",className:"invisible ml-3 mt-1 text-blue-600 group-hover:visible",children:i.jsx(w.InfoCircledIcon,{})})}),i.jsx(ae,{children:"Current value is using a Tailwind preset class."})]})]}):i.jsxs("div",{className:`group relative flex items-center ${k?"z-auto":""}`,children:[i.jsxs("div",{className:"flex items-center rounded-md border border-border",children:[["none","auto"].indexOf(f)!==-1?null:i.jsx("input",{readOnly:f==="class",onKeyPress:_=>{_.key==="Enter"&&N()},onKeyDown:_=>{if(_.keyCode!==38&&_.keyCode!==40)return;_.preventDefault(),v(!0);const B=d.parseInt(_.target.value);let P=d.isNaN(B)?0:B;_.keyCode===38&&(P+=1),_.keyCode===40&&(P-=1);const R=`${P}`,H=`${R.startsWith("-")?"-":""}${l}[${R.replace("-","")}${f==="-"?"":f}]`;I(H)},onKeyUp:_=>{A&&(_.preventDefault(),v(!1))},onBlur:()=>N(),onChange:_=>{x(!1),o(_.target.value)},onClick:_=>{var B;(B=_==null?void 0:_.target)==null||B.select(),n(!1)},value:k?b:s,className:"h-6 w-14 rounded rounded-r-none border border-transparent bg-background pl-2 text-sm focus-visible:outline-0".concat(" ",m?"border-red-500 text-red-500":"border-foreground/20")}),i.jsxs(de,{open:e,delayDuration:100,children:[i.jsx(ue,{asChild:!0,children:i.jsxs("button",{type:"button",onClick:()=>n(!e),className:"flex h-6 cursor-pointer items-center gap-x-1 rounded rounded-l-none bg-background p-px px-1 text-[11px] uppercase",children:[i.jsx("span",{className:`inline-block ${u.length===1?"px-2 font-semibold":""}`,children:f}),u.length>1?i.jsx(w.TriangleDownIcon,{}):null]})}),i.jsx(ae,{className:"bg-background",children:i.jsx(hg,{units:u,current:f,onSelect:_=>{n(!1),h(_),E(_)}})})]})]}),["none","auto"].indexOf(f)!==-1||k?null:i.jsx(fg,{onDragStart:()=>C(!0),onDragEnd:_=>{if(y(()=>""),C(!1),d.isEmpty(_))return;const B=`${_}`,R=`${B.startsWith("-")?"-":""}${l}[${B.replace("-","")}${f==="-"?"":f}]`;j(R)},onDrag:_=>{if(d.isEmpty(_))return;y(_);const B=`${_}`,R=`${B.startsWith("-")?"-":""}${l}[${B.replace("-","")}${f==="-"?"":f}]`;I(R)},currentValue:s,unit:f,negative:p,cssProperty:c})]})})})},Dn=g.createContext({canReset:!1,canChange:!0}),gg=({children:t,canReset:e=!1,canChange:n=!0})=>i.jsx(Dn.Provider,{value:{canReset:e,canChange:n},children:t}),or=[0,1,2,3,4,5,6,7,8,9,10,11,12,14,16,20,24,28,32,36,40,44,48,52,56,60,64,72,80,96],L={columns:[...d.range(1,13),"auto","3xs","2xs","xs","sm","md","lg","xl",...d.map(d.range(2,8),t=>`${t}xl`)],breakAfter:["auto","avoid","all","avoid-page","page","left","right","column"],breakInside:["auto","avoid","avoid-page","avoid-column"],display:["block","flex","grid","inline-block","inline","hidden"],objectFit:["contain","cover","fill","none","scale-down"],objectPosition:["bottom","center","left","left-bottom","left-top","right","right-bottom","right-top","top"],overflow:["auto","hidden","clip","visible","scroll"],overscroll:["auto","contain","none"],trbl:[0,"px","0.5",1,1.5,2,2.5,3,3.5,...d.range(4,13),14,16,20,24,28,32,36,40,44,48,52,56,60,64,72,80,96,"auto","1/2","1/3","2/3","1/4","2/4","3/4","full"],flexBasis:[...or,"auto","px","0.5","1.5","2.5","3.5","1/2","1/3","2/3","1/4","2/4","3/4","1/5","2/5","3/5","4/5","1/6","2/6","3/6","4/6","5/6","1/12","2/12","3/12","4/12","5/12","6/12","7/12","8/12","9/12","10/12","11/12","full"],padding:[...or,"px","0.5","1.5","2.5","3.5"],margin:["auto",...or,"px","0.5","1.5","2.5","3.5"],scale:[0,50,75,90,95,100,105,110,125,150],origin:["center","top","top-right","right","bottom-right","bottom","bottom-left","left","top-left"],blendEffect:["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],borderWidth:[0,2,4,8],borderRadius:["global","none","sm","md","lg","xl","2xl","3xl","full"],indent:[0,"px","0.5",1,1.5,2,2.5,3,3.5,...d.range(4,13),14,16,20,24,28,32,36,40,44,48,52,56,60,64,72,80,96],maxHeight:[0,"px","0.5",1,1.5,2,2.5,3,3.5,...d.range(4,13),14,16,20,24,28,32,36,40,44,48,52,56,60,64,72,80,96,"full","screen","min","max","fit"],space:[0,"px","0.5",1,1.5,2,2.5,3,3.5,...d.range(4,13),14,16,20,24,28,32,36,40,44,48,52,56,60,64,72,80,96,"px","reverse"],width:["0","px","0.5","1","1.5","2","2.5","3","3.5","4","5","6","7","8","9","10","11","12","14","16","20","24","28","32","36","40","44","48","52","56","60","64","72","80","96","auto","1/2","1/3","2/3","1/4","2/4","3/4","1/5","2/5","3/5","4/5","1/6","2/6","3/6","4/6","5/6","1/12","2/12","3/12","4/12","5/12","6/12","7/12","8/12","9/12","10/12","11/12"],maxWidth:["0","none","xs","sm","md","lg","xl","2xl","3xl","4xl","5xl","6xl","7xl","full","min","max","fit","prose","screen-sm","screen-md","screen-lg","screen-xl","screen-2xl"],height:["0","px","0.5","1","1.5","2","2.5","3","3.5","4","5","6","7","8","9","10","11","12","14","16","20","24","28","32","36","40","44","48","52","56","60","64","72","80","96","auto","1/2","1/3","2/3","1/4","2/4","3/4","1/5","2/5","3/5","4/5","1/6","2/6","3/6","4/6","5/6","full","screen","min","max","fit"]},Kt={textColor:{classes:[],regExp:"text-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},aspectRatio:{classes:["aspect-auto","aspect-square","aspect-video"],regExp:"aspect-(auto|square|video)"},container:{classes:["container"],regExp:"container"},columns:{classes:d.map(L.columns,t=>`columns-${t}`),regExp:"columns-(auto|[0-9]xl|[0-9]xs|xs|sm|md|lg|xl|\\d+)"},breakAfter:{classes:d.map(L.breakAfter,t=>`break-after-${t}`),regExp:"break-after-\\S+"},breakBefore:{classes:d.map(L.breakAfter,t=>`break-before-${t}`),regExp:"break-before-\\S+"},breakInside:{classes:d.map(L.breakInside,t=>`break-inside-${t}`),regExp:"break-inside-\\S+"},boxDecoration:{classes:["box-decoration-clone","box-decoration-slice"],regExp:"box-decoration-\\S+"},boxSizing:{classes:["box-border","box-content"],regExp:"box-(border|content)"},flexDirection:{classes:["flex-row","flex-row-reverse","flex-col","flex-col-reverse"],regExp:"flex-(row|row-reverse|col|col-reverse)"},flexWrap:{classes:["flex-wrap","flex-wrap-reverse","flex-nowrap"],regExp:"flex-(wrap|wrap-reverse|nowrap)"},flexGrowShrink:{classes:["flex-1","flex-auto","flex-initial","flex-none"],regExp:"flex-1|flex-auto|flex-initial|flex-none"},gridColumns:{classes:d.map([...d.range(0,13),"none"],t=>`grid-cols-${t}`),regExp:"grid-cols-(\\d+|none)"},gridFlow:{classes:["grid-flow-row","grid-flow-col","grid-flow-row-dense","grid-flow-col-dense"],regExp:"grid-flow-(row|col|row-dense|col-dense)"},outlineStyle:{classes:d.map(["none","dashed","dotted","double","hidden"],t=>`outline-${t}`),regExp:"outline-(none|dashed|dotted|double|hidden)"},borderStyle:{classes:d.map(["solid","dashed","dotted","double","hidden","none"],t=>`border-${t}`),regExp:"border-(solid|dashed|dotted|double|hidden|none)"},overflow:{classes:d.map(L.overflow,t=>`overflow-${t}`),regExp:`overflow-(${L.overflow.join("|")})`},overflowX:{classes:d.map(L.overflow,t=>`overflow-x-${t}`),regExp:`overflow-x-(${L.overflow.join("|")})`},overflowY:{classes:d.map(L.overflow,t=>`overflow-y-${t}`),regExp:`overflow-y-(${L.overflow.join("|")})`},gridRows:{classes:d.map([1,2,3,4,5,6,"none"],t=>`grid-rows-${t}`),regExp:"grid-rows-(\\d|none)"},display:{classes:d.map(L.display,t=>t.toString()),regExp:`(${L.display.join("|")})`},float:{classes:["float-right","float-left","float-none"],regExp:"float-\\S+"},clear:{classes:["clear-right","clear-left","clear-none","clear-both"],regExp:"clear-\\S+"},isolation:{classes:["isolate","isolation-auto"],regExp:"isolate|isolation-auto"},objectFit:{classes:d.map(L.objectFit,t=>`object-${t}`),regExp:"object-(contain|cover|fill|none|scale-down)"},objectPosition:{classes:d.map(L.objectPosition,t=>`object-${t}`),regExp:`object-(${L.objectPosition.join("|")})`},overscroll:{classes:d.map(L.overscroll,t=>`overscroll-${t}`),regExp:`overscroll-(${L.overscroll.join("|")})`},overscrollX:{classes:d.map(L.overscroll,t=>`overscroll-x-${t}`),regExp:`overscroll-x-(${L.overscroll.join("|")})`},overscrollY:{classes:d.map(L.overscroll,t=>`overscroll-y-${t}`),regExp:`overscroll-y-(${L.overscroll.join("|")})`},inset:{classes:d.map(L.trbl,t=>`inset-${t}`),regExp:"-?inset-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},insetX:{classes:d.map(L.trbl,t=>`inset-x-${t}`),regExp:"-?inset-x-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},insetY:{classes:d.map(L.trbl,t=>`inset-y-${t}`),regExp:"-?inset-y-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},top:{classes:d.map(L.trbl,t=>`top-${t}`),regExp:"-?top-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},topX:{classes:d.map(L.trbl,t=>`top-x-${t}`),regExp:"-?top-x-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},topY:{classes:d.map(L.trbl,t=>`top-y-${t}`),regExp:"-?top-y-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},right:{classes:d.map(L.trbl,t=>`right-${t}`),regExp:"-?right-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},rightX:{classes:d.map(L.trbl,t=>`right-x-${t}`),regExp:"-?right-x-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},rightY:{classes:d.map(L.trbl,t=>`right-y-${t}`),regExp:"-?right-y-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},bottom:{classes:d.map(L.trbl,t=>`bottom-${t}`),regExp:"-?bottom-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},bottomX:{classes:d.map(L.trbl,t=>`bottom-x-${t}`),regExp:"-?bottom-x-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},bottomY:{classes:d.map(L.trbl,t=>`bottom-y-${t}`),regExp:"-?bottom-y-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},left:{classes:d.map(L.trbl,t=>`left-${t}`),regExp:"-?left-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},leftX:{classes:d.map(L.trbl,t=>`left-x-${t}`),regExp:"-?left-x-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},leftY:{classes:d.map(L.trbl,t=>`left-y-${t}`),regExp:"-?left-y-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},visibility:{classes:["visible","invisible"],regExp:"invisible|visible"},zIndex:{classes:d.map(["0",10,20,30,40,50,"auto"],t=>`z-${t}`),regExp:"-?z-(\\d+|auto|\\[.*\\])"},flexBasis:{classes:d.map(L.flexBasis,t=>`basis-${t}`),regExp:"basis-(\\d+|\\S+)"},flexGrow:{classes:["grow","grow-0"],regExp:"grow(-0)?"},flexShrink:{classes:["shrink","shrink-0"],regExp:"shrink(-0)?"},gridColSpan:{classes:["col-auto",...d.map(d.range(1,13),t=>`col-span-${t}`),"col-span-full"],regExp:"col-(auto|span-(\\d+|full))"},gridColStart:{classes:[...d.map(d.range(1,14),t=>`col-start-${t}`),"col-start-auto"],regExp:"col-start-(\\d+|auto)"},gridColEnd:{classes:[...d.map(d.range(1,14),t=>`col-end-${t}`),"col-end-auto"],regExp:"col-end-(\\d+|auto)"},gridRowSpan:{classes:["row-auto",...d.map(d.range(1,7),t=>`row-span-${t}`),"row-span-full"],regExp:"row-(auto|span-(\\d+|full))"},gridRowStart:{classes:[...d.map(d.range(1,8),t=>`row-start-${t}`),"row-start-auto"],regExp:"row-start-(\\d+|auto)"},gridRowEnd:{classes:[...d.map(d.range(1,8),t=>`row-end-${t}`),"row-end-auto"],regExp:"row-end-(\\d+|auto)"},gridAutoColumns:{classes:["auto-cols-auto","auto-cols-min","auto-cols-max","auto-cols-fr"],regExp:"auto-cols-(auto|min|max|fr)"},gridAutoRows:{classes:["auto-rows-auto","auto-rows-min","auto-rows-max","auto-rows-fr"],regExp:"auto-rows-(auto|min|max|fr)"},gap:{classes:d.map(L.indent,t=>`gap-${t}`),regExp:"gap-(px|\\d.\\d|\\d|\\[.*\\])"},gapX:{classes:d.map(L.indent,t=>`gap-x-${t}`),regExp:"gap-x-(px|\\d.\\d|\\d|\\[.*\\])"},gapY:{classes:d.map(L.indent,t=>`gap-y-${t}`),regExp:"gap-y-(px|\\d.\\d|\\d|\\[.*\\])"},justifyContent:{classes:["justify-start","justify-end","justify-center","justify-between","justify-around","justify-evenly"],regExp:"justify-(start|end|center|between|around|evenly)"},justifyItems:{classes:["justify-items-start","justify-items-end","justify-items-center","justify-items-stretch"],regExp:"justify-items-(start|end|center|stretch)"},justifySelf:{classes:["justify-self-auto","justify-self-start","justify-self-end","justify-self-center","justify-self-stretch"],regExp:"justify-self-(auto|start|end|center|stretch)"},placeContent:{classes:["place-content-center","place-content-start","place-content-end","place-content-between","place-content-around","place-content-evenly","place-content-stretch"],regExp:"place-content-(center|start|end|between|around|evenly|stretch)"},placeItems:{classes:["place-items-start","place-items-end","place-items-center","place-items-stretch"],regExp:"place-items-(start|end|center|stretch)"},placeSelf:{classes:["place-self-auto","place-self-start","place-self-end","place-self-center","place-self-stretch"],regExp:"place-self-(auto|start|end|center|stretch)"},alignContent:{classes:["content-center","content-start","content-end","content-between","content-around","content-evenly"],regExp:"content-(center|start|end|between|around|evenly)"},alignItems:{classes:["items-start","items-end","items-center","items-baseline","items-stretch"],regExp:"items-(start|end|center|baseline|stretch)"},alignSelf:{classes:["self-auto","self-start","self-end","self-center","self-stretch","self-baseline"],regExp:"self-(auto|start|end|center|stretch|baseline)"},backgroundClip:{classes:["bg-clip-border","bg-clip-padding","bg-clip-content","bg-clip-text"],regExp:"bg-clip-(border|padding|content|text)"},dropShadow:{classes:d.map(["sm","md","lg","xl","2xl","none"],t=>`drop-shadow-${t}`),regExp:"drop-shadow-(sm|md|lg|xl|2xl|none)"},backdropBlur:{classes:d.map(["none","sm","md","lg","xl","2xl","3xl"],t=>`backdrop-blur-${t}`),regExp:"backdrop-blur-(none|sm|md|lg|xl|2xl|3xl)"},backdropBrightness:{classes:d.map([0,50,75,90,95,100,105,110,125,150,200],t=>`backdrop-brightness-${t}`),regExp:"backdrop-brightness-(\\d+)"},backdropContrast:{classes:d.map([0,50,75,100,125,150,200],t=>`backdrop-contrast-${t}`),regExp:"backdrop-contrast-(\\d+)"},backdropGrayScale:{classes:["backdrop-grayscale-0","backdrop-grayscale"],regExp:"backdrop-grayscale(-0)?"},backdropHueRotate:{classes:d.map([0,15,30,60,90,180],t=>`backdrop-hue-rotate-${t}`),regExp:"-?backdrop-hue-rotate-(\\d+)"},backdropInvert:{classes:["backdrop-invert-0","backdrop-invert"],regExp:"backdrop-invert(-0)?"},backdropOpacity:{classes:d.map([0,5,10,20,25,30,40,50,60,70,75,80,90,95,100],t=>`backdrop-opacity-${t}`),regExp:"backdrop-opacity-(\\d+)"},backdropSaturate:{classes:d.map([0,50,100,150,200],t=>`backdrop-saturate-${t}`),regExp:"backdrop-saturate-(\\d+)"},backdropSepia:{classes:["backdrop-sepia-0, backdrop-sepia"],regExp:"backdrop-sepia(-0)?"},backgroundOrigin:{classes:["bg-origin-border","bg-origin-padding","bg-origin-content"],regExp:"bg-origin-(border|padding|content)"},transformOrigin:{classes:d.map(L.origin,t=>`origin-${t}`),regExp:"origin-(\\d+|\\S+)"},padding:{classes:d.map(L.padding,t=>`p-${t}`),regExp:"p-(\\d+|\\S+|\\[.*\\])"},paddingX:{classes:d.map(L.padding,t=>`px-${t}`),regExp:"px-(\\d+|\\S+|\\[.*\\])"},paddingY:{classes:d.map(L.padding,t=>`py-${t}`),regExp:"py-(\\d+|\\S+|\\[.*\\])"},paddingTop:{classes:d.map(L.padding,t=>`pt-${t}`),regExp:"pt-(\\d+|\\S+|\\[.*\\])"},paddingRight:{classes:d.map(L.padding,t=>`pr-${t}`),regExp:"pr-(\\d+|\\S+|\\[.*\\])"},paddingBottom:{classes:d.map(L.padding,t=>`pb-${t}`),regExp:"pb-(\\d+|\\S+|\\[.*\\])"},paddingLeft:{classes:d.map(L.padding,t=>`pl-${t}`),regExp:"pl-(\\d+|\\S+|\\[.*\\])"},textDecorationStyle:{classes:["decoration-solid","decoration-double","decoration-dotted","decoration-dashed","decoration-wavy"],regExp:"decoration-(solid|double|dotted|dashed|wavy)"},textDecorationThickness:{classes:d.map(["auto","from-font","0",1,2,4,8],t=>`decoration-${t}`),regExp:"decoration-(auto|from-font|\\d+|\\S+)"},fromColor:{classes:[],regExp:"from-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},margin:{classes:d.map(L.margin,t=>`m-${t}`),regExp:"-?m-(\\d+|\\S+|\\[.*\\])"},marginX:{classes:d.map(L.margin,t=>`mx-${t}`),regExp:"-?mx-(\\d+|\\S+|\\[.*\\])"},marginY:{classes:d.map(L.margin,t=>`my-${t}`),regExp:"-?my-(\\d+|\\S+|\\[.*\\])"},marginTop:{classes:d.map(L.margin,t=>`mt-${t}`),regExp:"-?mt-(\\d+|\\S+|\\[.*\\])"},marginRight:{classes:d.map(L.margin,t=>`mr-${t}`),regExp:"-?mr-(\\d+|\\S+|\\[.*\\])"},marginBottom:{classes:d.map(L.margin,t=>`mb-${t}`),regExp:"-?mb-(\\d+|\\S+|\\[.*\\])"},marginLeft:{classes:d.map(L.margin,t=>`ml-${t}`),regExp:"-?ml-(\\d+|\\S+|\\[.*\\])"},spaceX:{classes:d.map(L.space,t=>`space-x-${t}`),regExp:"-?space-x-(\\d+|\\S+|\\[.*\\])"},spaceY:{classes:d.map(L.space,t=>`space-y-${t}`),regExp:"-?space-y-(\\d+|\\S+|\\[.*\\])"},boxShadow:{classes:d.map(["sm","md","lg","xl","2xl","inner","none"],t=>`shadow-${t}`),regExp:"shadow-(sm|md|lg|xl|2xl|inner|none)"},minWidth:{classes:["min-w-0","min-w-full","min-w-min","min-w-max","min-w-fit"],regExp:"min-w-(\\d+|\\S+|\\[.*\\])"},maxWidth:{classes:d.map(L.maxWidth,t=>`max-w-${t}`),regExp:"max-w-(\\d+|\\S+|\\[.*\\])"},width:{classes:d.map([...L.width,"full","screen","min","max","fit"],t=>`w-${t}`),regExp:"w-(\\d+.\\d+|\\d+|px|auto|full|screen|min|max|fit|\\[.*\\])$"},minHeight:{classes:["min-h-0","min-h-full","min-h-screen","min-h-min","min-h-max","min-h-fit"],regExp:"min-h-(\\d+|\\S+|\\[.*\\])"},maxHeight:{classes:d.map(L.maxHeight,t=>`max-h-${t}`),regExp:"max-h-(\\d+|\\S+|\\[.*\\])"},height:{classes:d.map(L.height,t=>`h-${t}`),regExp:"h-(\\d+.\\d+|\\d+|px|auto|full|screen|min|max|fit|\\[.*\\])"},fontFamily:{classes:["font-heading","font-body","font-sans","font-serif","font-mono"],regExp:"font-(heading|body|sans|serif|mono)"},textAlign:{classes:["text-left","text-center","text-right","text-justify"],regExp:"text-(left|center|right|justify)"},textOverflow:{classes:["truncate","text-ellipsis","text-clip"],regExp:"truncate|text-ellipsis|text-clip"},verticalAlign:{classes:["align-baseline","align-top","align-middle","align-bottom","align-text-top","align-text-bottom","align-sub","align-super"],regExp:"align-(baseline|top|middle|bottom|text-top|text-bottom|sub|super)"},fontSize:{classes:["text-xs","text-sm","text-base","text-lg","text-xl","text-2xl","text-3xl","text-4xl","text-5xl","text-6xl","text-7xl","text-8xl","text-9xl"],regExp:"text-(\\d+|\\S+|\\[.*\\])"},fontSmoothing:{classes:["antialiased","subpixel-antialiased"],regExp:"antialiased|subpixel-antialiased"},fontStyle:{classes:["italic","not-italic"],regExp:"not-italic|italic"},fontWeight:{classes:["font-thin","font-extralight","font-light","font-normal","font-medium","font-semibold","font-bold","font-extrabold","font-black"],regExp:"font-(thin|extralight|light|normal|medium|semibold|bold|extrabold|black)"},fontVariantNum:{classes:["normal-nums","ordinal","diagonal-fractions","stacked-fractions","tabular-nums","oldstyle-nums","proportional-nums","lining-nums","slashed-zero"],regExp:"normal-nums|ordinal|diagonal-fractions|stacked-fractions|tabular-nums|oldstyle-nums|proportional-nums|lining-nums|slashed-zero"},letterSpacing:{classes:["tracking-tighter","tracking-tight","tracking-normal","tracking-wide","tracking-wider","tracking-widest"],regExp:"-?tracking-(tighter|tight|normal|wide|wider|widest|\\[.*\\])"},lineHeight:{classes:["leading-none","leading-tight","leading-snug","leading-normal","leading-relaxed","leading-loose","leading-3","leading-4","leading-5","leading-6","leading-7","leading-8","leading-9","leading-10"],regExp:"leading-(none|tight|snug|normal|relaxed|loose|\\[.*\\]|\\d+)"},listStyleType:{classes:["list-none","list-disc","list-decimal"],regExp:"list-(none|disc|decimal)"},listStylePosition:{classes:["list-inside","list-outside"],regExp:"list-(inside|outside)"},textUnderlineOffset:{classes:["underline-offset-auto","underline-offset-0","underline-offset-1","underline-offset-2","underline-offset-4","underline-offset-8"],regExp:"underline-offset-(auto|\\d+|\\S+)"},textDecoration:{classes:["underline","overline","line-through","no-underline"],regExp:"underline|overline|line-through|no-underline"},textDecorationColor:{classes:[],regExp:"decoration-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},textTransform:{classes:["uppercase","lowercase","capitalize","normal-case"],regExp:"uppercase|lowercase|capitalize|normal-case"},textIndent:{classes:d.map(L.indent,t=>`indent-${t}`),regExp:"-?indent-(\\d+|\\S+)"},whitespace:{classes:["whitespace-normal","whitespace-nowrap","whitespace-pre","whitespace-pre-line","whitespace-pre-wrap"],regExp:"whitespace-(normal|nowrap|pre|pre-line|pre-wrap)"},wordBreak:{classes:["break-normal","break-words","break-all"],regExp:"break-(normal|words|all)"},content:{classes:["content-none"],regExp:"content-none"},backgroundAttachment:{classes:d.map(["fixed","local","scroll"],t=>`bg-${t}`),regExp:"bg-(fixed|local|scroll)"},backgroundColor:{classes:[],regExp:"bg-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},backgroundPosition:{classes:["bg-bottom","bg-center","bg-left","bg-left-bottom","bg-left-top","bg-right","bg-right-bottom","bg-right-top","bg-top"],regExp:"bg-(bottom|center|left|left-bottom|left-top|right|right-bottom|right-top|top)"},backgroundRepeat:{classes:["bg-repeat","bg-repeat-x","bg-repeat-y","bg-no-repeat","bg-repeat-round","bg-repeat-space"],regExp:"bg-(repeat|repeat-x|repeat-y|no-repeat|repeat-round|repeat-space)"},backgroundSize:{classes:["bg-auto","bg-cover","bg-contain"],regExp:"bg-(auto|cover|contain)"},backgroundGradient:{classes:["bg-gradient-none","bg-gradient-to-t","bg-gradient-to-tr","bg-gradient-to-r","bg-gradient-to-br","bg-gradient-to-b","bg-gradient-to-bl","bg-gradient-to-l","bg-gradient-to-tl"],regExp:"bg-gradient-(none|to-(t|tr|r|br|b|bl|l|tl))"},viaColor:{classes:[],regExp:"via-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},toColor:{classes:[],regExp:"to-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},position:{classes:["static","fixed","absolute","relative","sticky"],regExp:"(static|fixed|absolute|relative|sticky)"},borderRadiusTopLeft:{classes:["rounded-tl",...d.map(L.borderRadius,t=>`rounded-tl-${t}`)],regExp:"rounded-tl-?(\\d+|\\S+)?"},borderRadiusTopRight:{classes:["rounded-tr",...d.map(L.borderRadius,t=>`rounded-tr-${t}`)],regExp:"rounded-tr-?(\\d+|\\S+)?"},borderRadiusBottomRight:{classes:["rounded-br",...d.map(L.borderRadius,t=>`rounded-br-${t}`)],regExp:"rounded-br-?(\\d+|\\S+)?"},borderRadiusBottomLeft:{classes:["rounded-bl",...d.map(L.borderRadius,t=>`rounded-bl-${t}`)],regExp:"rounded-bl-?(\\d+|\\S+)?"},borderRadiusTop:{classes:["rounded-t",...d.map(L.borderRadius,t=>`rounded-t-${t}`)],regExp:"rounded-t-?(\\d+|\\S+)?"},borderRadiusRight:{classes:["rounded-r",...d.map(L.borderRadius,t=>`rounded-r-${t}`)],regExp:"rounded-r-?(\\d+|\\S+)?"},borderRadiusBottom:{classes:["rounded-b",...d.map(L.borderRadius,t=>`rounded-b-${t}`)],regExp:"rounded-b-?(\\d+|\\S+)?"},borderRadiusLeft:{classes:["rounded-l",...d.map(L.borderRadius,t=>`rounded-l-${t}`)],regExp:`(rounded-l-(${L.borderRadius.join("|")})|rounded-l$)`},borderRadius:{classes:["rounded",...d.map(L.borderRadius,t=>`rounded-${t}`)],regExp:`(rounded-(${L.borderRadius.join("|")}$)|rounded)`},borderX:{classes:["border-x",...d.map(L.borderWidth,t=>`border-x-${t}`)],regExp:"border-x-?(\\d+|\\S+|\\[.*\\])?"},borderY:{classes:["border-y",...d.map(L.borderWidth,t=>`border-y-${t}`)],regExp:"border-y-?(\\d+|\\S+|\\[.*\\])?"},borderTop:{classes:["border-t",...d.map(L.borderWidth,t=>`border-t-${t}`)],regExp:"border-t-?(\\d+|\\S+|\\[.*\\])?"},borderRight:{classes:["border-r",...d.map(L.borderWidth,t=>`border-r-${t}`)],regExp:"border-r-?(\\d+|\\S+|\\[.*\\])?"},borderBottom:{classes:["border-b",...d.map(L.borderWidth,t=>`border-b-${t}`)],regExp:"border-b-?(\\d+|\\S+|\\[.*\\])?"},borderLeft:{classes:["border-l",...d.map(L.borderWidth,t=>`border-l-${t}`)],regExp:"border-l-?(\\d+|\\S+|\\[.*\\])?"},borderColor:{classes:[],regExp:"^border-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\w+-\\d+|\\[#[0-9a-fA-F]+\\])$"},border:{classes:["border",...d.map(L.borderWidth,t=>`border-${t}`)],regExp:"^border(-\\d+|\\[\\d+px\\])?$"},order:{classes:d.map([...d.range(0,13),"first","last","none"],t=>`order-${t}`),regExp:"-?order-(\\d+|first|last|none)"},divideXWidth:{classes:d.map(["0",2,4,8],t=>`divide-x-${t}`),regExp:"divide-x-(\\d+|\\[.*\\])"},divideYWidth:{classes:d.map(["0",2,4,8],t=>`divide-y-${t}`),regExp:"divide-y-(\\d+|\\[.*\\])"},divideColor:{classes:[],regExp:"divide-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},divideStyle:{classes:d.map(["solid","dashed","dotted","double","none"],t=>`divide-${t}`),regExp:"divide-(solid|dashed|dotted|double|none)"},outlineWidth:{classes:d.map([0,1,2,4,8],t=>`outline-${t}`),regExp:"outline-(\\d+)"},outlineOffset:{classes:d.map([0,1,2,4,8],t=>`outline-offset-${t}`),regExp:"outline-offset-(\\d+)"},outlineColor:{classes:[],regExp:"outline-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},ringWidth:{classes:d.map([0,1,2,4,8,"inset"],t=>`ring-${t}`),regExp:"ring-(\\d+|inset)"},ringOffsetWidth:{classes:d.map([0,1,2,4,8],t=>`ring-offset-${t}`),regExp:"ring-offset-(\\d+)"},ringOffsetColor:{classes:[],regExp:"ring-offset-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},ringColor:{classes:[],regExp:"ring-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},boxShadowColor:{classes:[],regExp:"shadow-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},opacity:{classes:d.map([0,5,10,20,25,30,40,50,60,70,75,80,90,95,100],t=>`opacity-${t}`),regExp:"opacity-(\\d+|\\[.*\\])"},mixBlendMode:{classes:d.map(L.blendEffect,t=>`mix-blend-${t}`),regExp:"mix-blend-(\\d+|\\S+)"},bgBlendMode:{classes:d.map(L.blendEffect,t=>`bg-blend-${t}`),regExp:"bg-blend-(\\d+|\\S+)"},blur:{classes:d.map(["none","sm","md","lg","xl","2xl","3xl"],t=>`blur-${t}`),regExp:"blur-(none|sm|md|lg|xl|2xl|3xl)"},brightness:{classes:d.map([0,50,75,90,95,100,105,110,125,150,200],t=>`brightness-${t}`),regExp:"brightness-(\\d+)"},contrast:{classes:d.map([0,50,75,100,125,150,200],t=>`contrast-${t}`),regExp:"contrast-(\\d+)"},grayScale:{classes:["grayscale-0","grayscale"],regExp:"grayscale(-0)?"},hueRotate:{classes:d.map([0,15,30,60,90,180],t=>`hue-rotate-${t}`),regExp:"-?hue-rotate-(\\d+)"},invert:{classes:["invert-0","invert"],regExp:"invert(-0)?"},saturate:{classes:d.map([0,50,100,150,200],t=>`saturate-${t}`),regExp:"saturate-(\\d+)"},sepia:{classes:["sepia-0","sepia"],regExp:"sepia(-0)?"},transition:{classes:["transition-none","transition-all","transition-colors","transition-opacity","transition-shadow","transition-transform"],regExp:"transition-(none|all|colors|opacity|shadow|transform)"},duration:{classes:d.map([75,100,150,200,300,500,700,1e3],t=>`duration-${t}`),regExp:"duration-(\\d+|\\[.*\\])"},transitionEase:{classes:["ease-linear","ease-in","ease-out","ease-in-out"],regExp:"eas(e-linear|e-in|e-out|e-in-out)"},transitionDelay:{classes:d.map([75,100,150,200,300,500,700,1e3],t=>`delay-${t}`),regExp:"delay-(\\d+|\\[.*\\])"},animation:{classes:["animate-none","animate-spin","animate-ping"],regExp:"animate-(none|spin|ping)"},scaleX:{classes:d.map(L.scale,t=>`scale-x-${t}`),regExp:"-?scale-x-(\\d+|\\S+|\\[.*\\])"},scaleY:{classes:d.map(L.scale,t=>`scale-y-${t}`),regExp:"-?scale-y-(\\d+|\\S+|\\[.*\\])"},scale:{classes:d.map(L.scale,t=>`scale-${t}`),regExp:"-?scale-(\\d+|\\S+|\\[.*\\])"},rotate:{classes:d.map([0,1,2,3,6,12,45,90,180],t=>`rotate-${t}`),regExp:"-?rotate-(\\d+|\\S+|\\[.*\\])"},translateX:{classes:d.map([0,"px","0.5",1],t=>`translate-x-${t}`),regExp:"-?translate-x-(\\d+|\\S+|\\[.*\\])"},translateY:{classes:d.map([0,"px","0.5",1],t=>`translate-y-${t}`),regExp:"-?translate-y-(\\d+|\\S+|\\[.*\\])"},skewX:{classes:d.map([0,1,2,3,6,12],t=>`skew-x-${t}`),regExp:"-?skew-x-(\\d+|\\S+|\\[.*\\])"},skewY:{classes:d.map([0,1,2,3,6,12],t=>`skew-y-${t}`),regExp:"-?skew-y-(\\d+|\\S+|\\[.*\\])"},accentColor:{classes:[],regExp:"accent-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},appearance:{classes:["appearance-none"],regExp:"appearance-none"},cursor:{classes:["cursor-auto","cursor-default","cursor-pointer","cursor-wait","cursor-text","cursor-move","cursor-help","cursor-not-allowed"],regExp:"cursor-(auto|default|pointer|wait|text|move|help|not-allowed)"},caretColor:{classes:[],regExp:"caret-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},pointerEvents:{classes:["pointer-events-none","pointer-events-auto"],regExp:"pointer-events-(none|auto)"},userSelect:{classes:["select-none","select-text","select-all","select-auto"],regExp:"select-(none|text|all|auto)"},fill:{classes:[],regExp:"caret-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},stroke:{classes:[],regExp:"caret-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},strokeWidth:{classes:["stroke-0","stroke-1","stroke-2"],regExp:"stroke-(\\d+|\\[.*\\])"}},xg={backgroundColor:"bg",textColor:"text",borderColor:"border",boxShadowColor:"shadow",outlineColor:"outline",divideColor:"divide",fromColor:"from",viaColor:"via",toColor:"to",ringColor:"ring",ringOffsetColor:"ring-offset"},bg=["current","inherit","transparent","black","white"],yg=["slate","gray","zinc","neutral","stone","red","orange","amber","yellow","lime","green","emerald","teal","cyan","sky","blue","indigo","violet","purple","fuchsia","pink","rose"],kg=["50","100","200","300","400","500","600","700","800","900"],kr=d.map(d.values(xg),t=>t),vg=d.flattenDeep([...d.map(bg,t=>d.flatten(d.map(kr,e=>`${e}-${t}`))),...d.map(yg,t=>d.flattenDeep(d.map(kr,e=>d.flattenDeep(d.map(kg,n=>`${e}-${t}-${n}`)))))]),wg=d.map(d.flattenDeep(d.values(Kt).map(t=>t.classes).concat(vg)),t=>({name:t})),Cg=()=>{const t=Tn(),e=g.useMemo(()=>{let n=[];if(t.colors){const s=d.flattenDeep(d.map(t.colors,({items:o})=>d.keys(o)));n=d.flattenDeep(d.map(s,o=>d.flatten(d.map(kr,r=>`${r}-${o}`))))}return t.fontFamily&&(n=[...n,...d.map(d.keys(t.fontFamily),s=>`${s}`)]),d.map(n,s=>({name:s}))},[t]);return g.useMemo(()=>new Mi([...wg,...e],{isCaseSensitive:!1,threshold:.2,minMatchCharLength:2,keys:["name"]}),[e])},Ms=()=>{const t=Tn(),e=g.useMemo(()=>{if(t.colors){const o=d.flattenDeep(d.map(t.colors,({items:r})=>d.keys(r)));d.each(Kt,(r,a)=>{d.set(Kt,`${a}.regExp`,r.regExp.replace("__THEME_COLORS_REGEXP__",o.join("|")))})}return Kt},[t]),n=g.useCallback((o,r)=>{const a=d.get(e,`${o}.regExp`,"");return r.match(new RegExp(a))},[e]),s=g.useCallback((o,r=[])=>d.get(e,`${o}.classes`,r),[e]);return{match:n,getClasses:s}},Jl=({label:t,property:e,onChange:n})=>{const{getClasses:s}=Ms(),o=s(e),r=Mn(e),a=g.useMemo(()=>d.get(r,"cls",""),[r]),{canChange:l}=g.useContext(Dn),c=/\[.*\]/g.test(a);return i.jsx("div",{className:t?"w-full rounded":"grow",children:c?i.jsxs("div",{className:"flex items-center",children:[i.jsx(T.Input,{className:"w-[70%] rounded py-1",readOnly:!0,value:a}),i.jsxs(de,{delayDuration:100,children:[i.jsx(ue,{asChild:!0,children:i.jsx("button",{type:"button",className:"invisible ml-3 mt-1 text-blue-600 group-hover:visible",children:i.jsx(w.InfoCircledIcon,{})})}),i.jsx(ae,{children:"Current value is using a Tailwind arbitrary value."})]})]}):i.jsx(vr,{rounded:t,onChange:u=>n(u,e),selected:a,options:o,disabled:!l})})};function vr({selected:t,onChange:e,rounded:n=!1,options:s,disabled:o=!1}){const r=t.replace(/.*:/g,"").trim(),{undo:a,redo:l}=En();return i.jsxs("select",{disabled:!s.length||o,className:`${n?"rounded-md border border-border":"border-0"} disable:bg-gray-500 h-full w-full truncate rounded bg-background px-2 py-1 text-xs outline-none disabled:cursor-not-allowed`,onChange:c=>e(c.target.value),onKeyDown:c=>{c.ctrlKey&&(c.key==="z"&&a(),c.key==="y"&&l())},value:r,children:[i.jsx("option",{className:"bg-transparent",value:""}),s.map((c,u)=>i.jsx("option",{className:"bg-transparent",value:c,children:c},`option-${u}`))]})}const jg={backgroundColor:"bg",textColor:"text",borderColor:"border",boxShadowColor:"shadow",outlineColor:"outline",divideColor:"divide",fromColor:"from",viaColor:"via",toColor:"to",ringColor:"ring",ringOffsetColor:"ring-offset"},Sg=({property:t,onChange:e})=>{const n=Mn(t),s=g.useMemo(()=>d.get(n,"cls",""),[n]),{canChange:o}=g.useContext(Dn),[r,a]=g.useState([]),[l,c]=g.useState({color:"",shade:""}),u=s.split("-"),p=d.get(u,"1",""),f=d.get(u,"2",""),h=g.useCallback(b=>{["current","inherit","transparent","black","white"].includes(b)?(a([]),c({color:b})):(a(["50","100","200","300","400","500","600","700","800","900"]),c(y=>({...y,color:b,shade:y.shade?y.shade:"500"})))},[a,c]);g.useEffect(()=>{if(["current","inherit","transparent","black","white"].includes(p))return a([]);a(["50","100","200","300","400","500","600","700","800","900"])},[p]);const m=g.useCallback(b=>{c({color:p,shade:b})},[p]);g.useEffect(()=>{c({color:"",shade:""})},[n]);const{match:x}=Ms();return g.useEffect(()=>{const y=`${d.get(jg,t,"")}-${l.color}${l.shade?`-${l.shade}`:""}`;x(t,y)&&e(y,t)},[x,l,e,t]),i.jsxs("div",{className:"flex flex-row divide-x divide-solid divide-border rounded-lg border border-transparent text-xs",children:[i.jsx("div",{className:"grow text-center",children:i.jsx(vr,{disabled:!o,rounded:!0,selected:p,onChange:h,options:["current","transparent","primary","secondary","black","white","slate","gray","zinc","neutral","stone","red","orange","amber","yellow","lime","green","emerald","teal","cyan","sky","blue","indigo","violet","purple","fuchsia","pink","rose"]})}),i.jsx("button",{type:"button",className:"grow text-center",children:i.jsx(vr,{rounded:!0,selected:f,disabled:!p||!o,onChange:m,options:r})})]})},Xl={"not-italic":()=>i.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:i.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9 3H11V5H9V11H11V13H5V11H7V5H5V3H9Z",fill:"white"})}),visible:w.EyeOpenIcon,invisible:w.EyeClosedIcon,hidden:w.EyeClosedIcon,gap:w.BorderAllIcon,gapX:w.WidthIcon,gapY:w.HeightIcon,spaceX:w.WidthIcon,spaceY:w.HeightIcon,overscroll:w.BorderAllIcon,overscrollX:w.WidthIcon,overscrollY:w.HeightIcon,overflow:w.BorderAllIcon,overflowX:w.WidthIcon,overflowY:w.HeightIcon,top:w.ArrowUpIcon,right:w.ArrowRightIcon,bottom:w.ArrowDownIcon,left:w.ArrowLeftIcon,inset:w.BorderAllIcon,insetX:w.WidthIcon,insetY:w.HeightIcon,border:w.BorderAllIcon,borderX:w.WidthIcon,borderY:w.HeightIcon,borderTop:w.ArrowUpIcon,borderRight:w.ArrowRightIcon,borderBottom:w.ArrowDownIcon,borderLeft:w.ArrowLeftIcon,borderRadius:w.BorderAllIcon,borderRadiusX:w.WidthIcon,borderRadiusY:w.HeightIcon,borderRadiusTop:w.ArrowUpIcon,borderRadiusRight:w.ArrowRightIcon,borderRadiusBottom:w.ArrowDownIcon,borderRadiusLeft:w.ArrowLeftIcon,borderRadiusTopLeft:w.ArrowTopLeftIcon,borderRadiusTopRight:w.ArrowTopRightIcon,borderRadiusBottomRight:w.ArrowBottomRightIcon,borderRadiusBottomLeft:w.ArrowBottomLeftIcon,divideXWidth:w.WidthIcon,divideYWidth:w.HeightIcon,scale:w.BorderAllIcon,scaleX:w.WidthIcon,scaleY:w.HeightIcon,skewX:w.WidthIcon,skewY:w.HeightIcon,translateX:w.WidthIcon,translateY:w.HeightIcon,padding:w.BorderAllIcon,paddingX:w.WidthIcon,paddingY:w.HeightIcon,paddingTop:w.ArrowUpIcon,paddingRight:w.ArrowRightIcon,paddingBottom:w.ArrowDownIcon,paddingLeft:w.ArrowLeftIcon,margin:w.BorderAllIcon,marginX:w.WidthIcon,marginY:w.HeightIcon,marginTop:w.ArrowUpIcon,marginRight:w.ArrowRightIcon,marginBottom:w.ArrowDownIcon,marginLeft:w.ArrowLeftIcon,textLeft:w.AlignLeftIcon,textCenter:w.AlignCenterHorizontallyIcon,textRight:w.AlignRightIcon,textJustify:w.StretchHorizontallyIcon,italic:w.FontItalicIcon,underline:w.UnderlineIcon,overline:w.OverlineIcon,uppercase:w.LetterCaseUppercaseIcon,block:()=>i.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M2 2H14V14H2V2ZM1 1H15V15H1V1Z",fill:"currentColor"}),i.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7 4H4V12H7V4ZM9 4H12V12H9V4Z",fill:"currentColor"})]}),"float-right":()=>i.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{d:"M8 4H16V12H8V4Z",fill:"currentColor"}),i.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M0 4H6V6H0V4ZM0 7H6V9H0V7ZM4 10H0V12H4V10Z",fill:"currentColor"})]}),"float-left":()=>i.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{d:"M0 4H8V12H0V4Z",fill:"currentColor"}),i.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M10 4H16V6H10V4ZM10 7H16V9H10V7ZM14 10H10V12H14V10Z",fill:"currentColor"})]}),"float-none":w.Cross2Icon,fixed:()=>i.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M15 2H14V4H13V5H14V6H15V2ZM10 5V4H9V2H1V8H2V5H10ZM7 4V3H5V4H7ZM4 4V3H2V4H4ZM1 13H7V14H1V13Z",fill:"currentColor"}),i.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2H10V3H11V6H12V3H13V2H11ZM2 9H1V12H2V11H7V10H2V9ZM15 7H8V14H15V7Z",fill:"currentColor"})]}),absolute:()=>i.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M14 2H15V6H14V2ZM9 3V2H1V8H2V3H9ZM7 13H1V14H7V13Z",fill:"currentColor"}),i.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2H10V3H11V6H12V3H13V2H11ZM2 9H1V12H2V11H7V10H2V9ZM15 7H8V14H15V7Z",fill:"currentColor"})]}),relative:()=>i.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:i.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2H9V3H11V6H12V3H14V2H11ZM2 8H1V13H2V11H7V10H2V8ZM15 7H8V14H15V7Z",fill:"currentColor"})}),sticky:()=>i.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("path",{d:"M12.9998 7C13.6558 7 14.2937 6.78498 14.8158 6.38787C15.338 5.99076 15.7156 5.43345 15.8908 4.80128C16.066 4.16912 16.0292 3.49694 15.7859 2.8877C15.5427 2.27846 15.1065 1.76573 14.5441 1.42804C13.9817 1.09034 13.3241 0.946293 12.672 1.01795C12.02 1.08961 11.4094 1.37303 10.9337 1.8248C10.4581 2.27658 10.1436 2.8718 10.0385 3.51932C9.93341 4.16685 10.0434 4.83097 10.3518 5.41L6.88176 8.88C6.80034 8.96122 6.73572 9.05769 6.69158 9.16388C6.64744 9.27008 6.62465 9.38393 6.62451 9.49894C6.62437 9.61395 6.64689 9.72785 6.69077 9.83416C6.73465 9.94046 6.79904 10.0371 6.88026 10.1185C6.96149 10.1999 7.05795 10.2645 7.16415 10.3087C7.27035 10.3528 7.3842 10.3756 7.4992 10.3758C7.61421 10.3759 7.72812 10.3534 7.83442 10.3095C7.94072 10.2656 8.03734 10.2012 8.11876 10.12L11.5888 6.648C12.0088 6.873 12.4888 7 12.9988 7H12.9998Z",fill:"currentColor"}),i.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M9.535 2H1V14H15V7.465C14.69 7.645 14.355 7.783 14 7.875V13H2V5H9.126C8.86504 3.98486 9.01223 2.90789 9.536 2H9.535ZM7 3V4H5V3H7ZM4 3V4H2V3H4Z",fill:"currentColor"})]}),static:w.Cross1Icon},Ng=({property:t,onChange:e})=>{const{getClasses:n}=Ms(),s=n(t),{canChange:o}=g.useContext(Dn),r=Mn(t),a=g.useMemo(()=>d.get(r,"cls",""),[r]);return i.jsx("div",{className:"flex grow flex-wrap gap-1",children:d.map(s,l=>i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:i.jsx("button",{type:"button",disabled:!o,onClick:()=>e(l,t),className:`cursor-pointer rounded border border-border p-1 disabled:cursor-not-allowed ${a===l?"bg-primary text-white":"disabled:bg-gray-600 disabled:text-gray-400"}`,children:g.createElement(d.get(Xl,l,w.BoxIcon))})}),i.jsx(ae,{children:d.startCase(d.toLower(l))})]}))})},Eg=({property:t,onChange:e})=>{const{canReset:n,canChange:s}=g.useContext(Dn),o=Mn(t),r=g.useMemo(()=>d.get(o,"cls",""),[o]),{getClasses:a}=Ms(),l=a(t,[""]),c=l.indexOf(r)>-1?l.indexOf(r):0,u=/\[.*\]/g.test(r);return i.jsx("div",{className:"flex flex-row divide-x divide-solid divide-border rounded border border-border text-xs",children:u?i.jsx("div",{className:"px-2 py-[5px]",children:r}):i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",className:"hover:bg-bg-gray-700 box-border w-2/12 rounded-bl rounded-tl bg-background px-1 text-center disabled:cursor-not-allowed disabled:bg-gray-600",disabled:!s&&(!n||c-1<0),onClick:()=>e(d.nth(l,c-1),t),children:i.jsx("span",{className:"flex items-center justify-center",children:i.jsx(w.MinusIcon,{className:!s&&(!n||c-1<0)?"text-gray-500":"text-black/60 dark:text-white/60"})})}),i.jsx("div",{className:"w-8/12 text-center",children:i.jsx(Jl,{label:!1,property:t,onChange:e})}),i.jsx("button",{type:"button",className:"hover:bg-bg-gray-700 w-2/12 rounded-br rounded-tr bg-background px-1 text-center disabled:cursor-not-allowed disabled:bg-gray-600",disabled:!s&&(!n||c+1>=l.length),onClick:()=>e(d.nth(l,c+1),t),children:i.jsx("span",{className:"flex items-center justify-center",children:i.jsx(w.PlusIcon,{className:!s&&(!n||c+1>=l.length)?"text-gray-500":"text-black/60 dark:text-white/60"})})})]})})};function Ag(t){if(d.isEmpty(t.trim()))return"";const e=t.match(/sm:|md:|lg:|xl:|2xl:/g);return d.get(e,0,"xs").replace(":","")}function _g(t){const e=d.map(qd,s=>`${s}:`).join("|"),n=new RegExp(e,"g");return d.get(n.exec(t.trim()),0,"").replace(":","")}function Ig(t){return t.trim().split(":").pop()||""}const ir={};function Tg(t){if(d.isEmpty(t))return"";if(ir[t])return ir[t];let e="";for(const n in Kt){const s=d.get(Kt,`${n}.regExp`,"");if(new RegExp(s,"g").test(t)){e=n,ir[t]=e;break}}return e}function jo(t){return d.isEmpty(t)?null:{dark:d.startsWith(t,"dark:"),mq:Ag(t),mod:_g(t),cls:Ig(t),fullCls:t,property:Tg(t)}}function Bg(t){let e="";return t.dark&&(e+="dark:"),t.mq.toLowerCase()!=="xs"&&(e+=`${t.mq}:`),t.mod&&(e+=`${t.mod}:`),e+=t.cls,e}function Rg(t){t=t.replace(/\s+/g," ");const e=t.split(" ").map(jo).filter(s=>s!==null),n=["xs","sm","md","lg","xl","2xl"];return e.sort((s,o)=>n.indexOf(s.mq)-n.indexOf(o.mq)).map(s=>s.fullCls).join(" ")}function Pg(t){if(t=t.replace(/\s+/g," "),!t)return"";const e=["xs","sm","md","lg","xl","2xl"],n=t.split(" ").map(jo).filter(o=>o!==null);let s=t;if(n.length===1)return n[0].fullCls;for(const o of n){const r=o.property,a=e.indexOf(o.mq);for(let l=a+1;l<e.length;l++){const c=e[l],u=n.find(p=>p.property===r&&p.mq===c);if(u&&u.cls===o.cls)s=s.replace(u.fullCls,"");else if(u&&u.cls!==o.cls)break}}return s.replace(/\s+/g," ").trim()}const Lg=S.atom(null,(t,e,{blockIds:n,newClasses:s})=>{const o=d.filter(t(Nn),a=>n.includes(t(a)._id)),r=d.first(t(_n));return d.map(o,a=>{const l=t(a),c=d.get(l,r.prop,`${U.STYLES_KEY},`),{classes:u}=ne.getSplitChaiClasses(c);return{ids:[l._id],props:{[r.prop]:`${U.STYLES_KEY},${Rg(Pg(Di.twMerge(u,s)))}`}}})}),Zl=()=>{const t=S.useSetAtom(Lg),{updateBlocks:e,updateBlocksRuntime:n}=Ee();return g.useCallback((s,o,r=!1)=>{const a=t({blockIds:s,newClasses:o});if(!r){n(s,a[0].props);return}e(s,a[0].props)},[t,e,n])},Dg=t=>{const e=["xs","sm","md","lg","xl","2xl"],n=e.indexOf(t);return n===-1?["xs"]:e.slice(0,n+1)},Mg=S.atom(t=>{const e=d.first(t(_n)),n=t(ws);if(!e||e.blockId!==d.get(n,"_id",null))return[];const s=d.get(n,e.prop,`${U.STYLES_KEY},`),{classes:o}=ne.getSplitChaiClasses(s);return d.filter(d.map(o.trim().split(" "),jo),r=>!d.isNull(r))}),ki={xs:0,sm:1,md:2,lg:3,xl:4,"2xl":5},Og=S.atom(t=>{const e=t(Ll),n=t(Mr),s=t(Ba),o=Dg(e);let r=d.filter(t(Mg),{mod:n});return d.startsWith(n,"_")||(r=d.filter(r,a=>o.includes(a.mq))),r=r.sort((a,l)=>ki[a.mq]-ki[l.mq]),s||(r=d.filter(r,{dark:!1})),r}),Os=()=>S.useAtomValue(Og),$g=()=>S.useAtom(Mr),Mn=t=>{const e=Os();return d.findLast(e,{property:t})},Fg=(t,e)=>{const n={xs:0,sm:1,md:2,lg:3,xl:4,"2xl":5};return n[d.get(t,"mq","xs")]<=n[e]},zg={width:"w-",height:"h-",minWidth:"min-w-",minHeight:"min-h-",maxWidth:"max-w-",maxHeight:"max-h-",zIndex:"z-",gap:"gap-",gapX:"gap-x-",gapY:"gap-y-",margin:"m-",marginX:"mx-",marginY:"my-",marginTop:"mt-",marginBottom:"mb-",marginLeft:"ml-",marginRight:"mr-",padding:"p-",paddingX:"px-",paddingY:"py-",paddingTop:"pt-",paddingBottom:"pb-",paddingLeft:"pl-",paddingRight:"pr-",spaceX:"space-x-",spaceY:"space-y-",border:"border-",borderTop:"border-t-",borderBottom:"border-b-",borderLeft:"border-l-",borderRight:"border-r-",borderX:"border-x-",borderY:"border-y-",borderRadius:"rounded-",borderRadiusTop:"rounded-t-",borderRadiusRight:"rounded-r-",borderRadiusBottom:"rounded-b-",borderRadiusLeft:"rounded-l-",borderRadiusTopLeft:"rounded-tl-",borderRadiusTopRight:"rounded-tr-",borderRadiusBottomRight:"rounded-br-",borderRadiusBottomLeft:"rounded-bl-",fontSize:"text-",lineHeight:"leading-",letterSpacing:"tracking-",textIndent:"indent-",rotate:"rotate-",duration:"duration-",transitionDelay:"delay-",scale:"scale-",scaleX:"scale-x-",scaleY:"scale-y-",translateX:"translate-x-",translateY:"translate-y-",skewX:"skew-x-",skewY:"skew-y-",top:"top-",bottom:"bottom-",left:"left-",right:"right-",inset:"inset-",insetX:"inset-x-",insetY:"inset-y-",opacity:"opacity-",flexBasis:"basis-"},vi={xs:"",sm:"640px",md:"768px",lg:"1024px",xl:"1280px","2xl":"1536px"},Hg=t=>`${t.toUpperCase()} ${vi[t]?`(${vi[t]} & up)`:""}`,ys=t=>{const{t:e}=z.useTranslation(),{type:n="icons",label:s,property:o,onEmitChange:r=()=>{},units:a,negative:l=!1}=t,[c]=In(),[u]=$g(),[,p]=gs(),f=Mn(o),h=Zl(),m=Co(),[x]=q(),b=g.useMemo(()=>d.get(f,"fullCls",""),[f]),y=g.useCallback((I,N=!0)=>{const E={dark:c,mq:p,mod:u,cls:I};(c||u!=="")&&(E.mq="xs");const _=Bg(E);h(x,[_],N)},[x,c,p,u,o,h]),k=g.useCallback(()=>{m(x,[b],!0)},[x,b,m]),C=g.useMemo(()=>Fg(f,p),[f,p]);g.useEffect(()=>{r(C,f)},[C,r,f]);const[,,A]=gs(),v=g.useCallback(I=>{A({xs:400,sm:640,md:800,lg:1024,xl:1420,"2xl":1920}[I])},[A]),j=d.get(f,"dark",null)===c&&d.get(f,"mod",null)===u&&d.get(f,"mq",null)===p;return i.jsx(gg,{canChange:C,canReset:f&&j,children:i.jsxs("div",{className:"group flex flex-row items-center py-2 first:pt-0 last:pb-0",children:[i.jsx("div",{className:"relative w-[70px] truncate text-xs text-foreground",children:i.jsx("span",{className:`text-[11px] ${f&&!j?"text-foreground":""}`,children:e(s)})}),i.jsxs("div",{className:"flex flex-row items-center",children:[i.jsxs("div",{className:"w-[150px]",children:[n==="arbitrary"?i.jsx(mg,{currentClass:d.get(f,"cls",""),classPrefix:d.get(zg,o,""),units:a||[],onChange:y,negative:l,cssProperty:o}):null,n==="icons"&&i.jsx(Ng,{property:o,onChange:y}),n==="range"&&i.jsx(Eg,{property:o,onChange:y}),n==="color"&&i.jsx(Sg,{property:o,onChange:y}),n==="dropdown"&&i.jsx(Jl,{label:s,property:o,onChange:y})]}),i.jsx("div",{className:`w-[30px] cursor-pointer ${b?"visible":"invisible"}`,children:j?i.jsx("button",{type:"button",onClick:()=>k(),title:"Reset",className:"flex px-1.5 text-xs",children:i.jsx(w.CrossCircledIcon,{className:"h-5 w-5 text-blue-500 hover:opacity-80"})}):C&&f?i.jsxs(de,{delayDuration:100,children:[i.jsx(ue,{asChild:!0,children:i.jsx("button",{type:"button",className:"invisible ml-3 mt-1 rounded-full bg-primary text-white group-hover:visible",children:i.jsx(w.InfoCircledIcon,{})})}),i.jsx(ae,{children:i.jsx("div",{className:"text-right",children:i.jsxs("div",{children:["Current style is set at  ",i.jsxs("span",{className:"font-bold",children:[Hg(d.get(f,"mq")),c&&!f.dark?"(Light mode)":""]}),i.jsx("br",{}),i.jsxs("button",{type:"button",onClick:()=>v(d.get(f,"mq")),className:"block w-full cursor-default text-right font-semibold text-blue-500",children:["Switch to ",d.get(f,"mq").toUpperCase()]})]})})})]}):null})]})]})})},Vg=["px","%","em","rem","ch","vh","vw"],wr=({label:t,options:e,borderB:n=!1,borderT:s=!1,type:o="arbitrary",units:r=Vg,negative:a=!1})=>{const{t:l}=z.useTranslation(),[c,u]=g.useState(e[0].key),p=Os(),f=g.useCallback(h=>d.map(p,"property").includes(h),[p]);return i.jsxs("div",{className:`mb-2 border-border py-2 first:pt-0 last:pb-0 ${n?"border-b":""} ${s?"border-t":""}`,children:[i.jsxs("div",{className:"flex flex-row text-xs",children:[t&&i.jsx("span",{className:"relative w-[70px] flex-none text-xs text-foreground",children:l(t)}),i.jsx("div",{className:"mb-3 flex grow flex-row flex-wrap gap-x-px",children:e.map(({label:h,key:m},x)=>i.jsx("div",{className:"first:rounded-l last:rounded-r",children:i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:i.jsxs("button",{type:"button",onClick:()=>u(m),className:`relative cursor-pointer rounded-full p-1 text-[8px] ${m===c?"bg-[#3E57F0] text-white":"text-gray-600 dark:text-gray-300"}`,children:[g.createElement("div",{className:f(m)?"-bottom-1.5 absolute bg-[#3E57F0] h-[2px] left-0 w-full":""}),g.createElement(d.get(Xl,m,w.BoxIcon),{className:"text-inherit w-3 h-3"})]})}),i.jsx(ae,{children:d.startCase(d.toLower(h))})]})},`option-${x}`))})]}),i.jsx("div",{className:"mt-0 flex items-center",children:i.jsx(ys,{type:o,units:[...r],label:"",property:c,negative:a})})]})},wi=({heading:t,items:e})=>{const{t:n}=z.useTranslation(),s=Os(),o=g.useMemo(()=>{const r=c=>d.flatten(c.map(u=>u.styleType==="multiple"?d.map(u.options,"key"):u.property)),a=d.flatten(e.map(c=>c.styleType==="accordion"?r(c.items):c.styleType==="multiple"?d.map(c.options,"key"):c.property)),l=d.map(s,"property");return d.intersection(a,l).length>0},[s,e]);return i.jsxs("details",{children:[i.jsx("summary",{className:"my-px cursor-default rounded-md bg-gray-50 p-px px-2 text-[11px] text-foreground dark:bg-gray-800",children:i.jsxs("div",{className:"inline",children:[d.startCase(n(t.toLowerCase())),o?i.jsx("span",{className:`ml-1 mr-2 inline-block h-[8px] w-[8px] rounded-full ${o?"bg-primary":"bg-gray-300"}`}):null]})}),i.jsx("div",{className:"p-2",children:e.map(r=>r.styleType==="multiple"?i.jsx(wr,{...r},r.label):i.jsx(ys,{...r},r.label))})]})},Wg=g.createContext({}),ar=({section:t,showAccordian:e})=>{const{t:n}=z.useTranslation(),s=Os(),o=g.useCallback((a=[])=>{const l={};for(let u=0;u<s.length;u++)l[s[u].property]=s[u].cls;let c=!0;for(const u in a)if(!d.has(l,u)||l[u]!==a[u]){c=!1;break}return c},[s]),r=g.useMemo(()=>({}),[]);return i.jsx(Wg.Provider,{value:r,children:e?i.jsxs(Wl,{value:t.heading,className:"border-none",children:[i.jsx(Gl,{className:"border-slate-150 border-t py-2 text-xs",children:i.jsx("div",{className:"flex items-center py-2",children:i.jsx("div",{className:"flex items-center gap-x-2 text-xs font-medium",children:d.startCase(n(t.heading))})})}),i.jsx(Ul,{className:"py-2",children:t.items.map(a=>d.has(a,"component")?g.createElement(a.component,{key:a.label}):d.has(a,"styleType")?a.styleType==="multiple"?i.jsx(wr,{...a},a.label+"multiple-choices"):a.styleType==="accordion"&&o(a==null?void 0:a.conditions)?i.jsx(wi,{...a},a.label+"nested-options"):null:i.jsx(ys,{...a},a.label+"block-style"))})]}):i.jsx("div",{className:"py-2",children:t.items.map((a,l)=>d.has(a,"component")?g.createElement(a.component,{key:a.label}):d.has(a,"styleType")?a.styleType==="multiple"?i.jsx(wr,{...a},a.label+"multiple-choices"+l):a.styleType==="accordion"&&o(a==null?void 0:a.conditions)?i.jsx(wi,{...a},a.label+"nested-options"+l):null:i.jsx(ys,{...a},a.label+"block-style"+l))})})},Ql=ks.Root,ec=ks.Trigger,So=O.forwardRef(({className:t,align:e="center",sideOffset:n=4,...s},o)=>i.jsx(ks.Content,{ref:o,align:e,sideOffset:n,className:T.cn("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-64 origin-[--radix-hover-card-content-transform-origin] rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none",t),...s}));So.displayName=ks.Content.displayName;const Gg=He.atomWithStorage("selectedBreakpoints",["XS","MD","XL"]),Ug=()=>{const[t,e]=S.useAtom(Gg);return[t,e]},Ci=({className:t=""})=>i.jsxs("svg",{className:ce.cn("h-4 w-4",t),fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{x:"5",y:"2",width:"14",height:"20",rx:"2",ry:"2"}),i.jsx("line",{x1:"12",y1:"18",x2:"12.01",y2:"18"})]}),qg=({className:t=""})=>i.jsxs("svg",{className:ce.cn("h-4 w-4",t),fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{x:"2",y:"4",width:"20",height:"12",rx:"2",ry:"2"}),i.jsx("line",{x1:"6",y1:"20",x2:"18",y2:"20"}),i.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"20"})]}),Kg=({className:t=""})=>i.jsxs("svg",{className:ce.cn("h-4 w-4",t),fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),i.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),i.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]}),ji=({landscape:t=!1,className:e=""})=>i.jsxs("svg",{className:ce.cn("h-4 w-4",t?"rotate-90":"",e),fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{x:"4",y:"2",width:"16",height:"20",rx:"2",ry:"2"}),i.jsx("line",{x1:"12",y1:"18",x2:"12.01",y2:"18"})]}),Cr=[{title:"Mobile (Base)",content:"Styles set here are applied to all screen unless edited at higher breakpoint",breakpoint:"xs",icon:i.jsx(Ci,{className:"h-4 w-4"}),width:400},{title:"Mobile landscape (SM)",content:"Styles set here are applied at 640px and up unless edited at higher breakpoint",breakpoint:"sm",icon:i.jsx(Ci,{className:"h-4 w-4 rotate-90"}),width:640},{title:"Tablet (MD)",content:"Styles set here are applied at 768px and up",breakpoint:"md",icon:i.jsx(ji,{}),width:800},{title:"Tablet Landscape (LG)",content:"Styles set here are applied at 1024px and up unless edited at higher breakpoint",breakpoint:"lg",icon:i.jsx(ji,{landscape:!0}),width:1024},{title:"Desktop (XL)",content:"Styles set here are applied at 1280px and up unless edited at higher breakpoint",breakpoint:"xl",icon:i.jsx(qg,{className:"h-4 w-4"}),width:1420},{title:"Large Desktop (2XL)",content:"Styles set here are applied at 1536px and up",breakpoint:"2xl",icon:i.jsx(Kg,{className:"h-4 w-4"}),width:1920}],Si=({canvas:t=!1,openDelay:e=400,tooltip:n=!0,title:s,content:o,currentBreakpoint:r,breakpoint:a,width:l,icon:c,onClick:u,buttonClass:p="",activeButtonClass:f=""})=>{const{t:h}=z.useTranslation();return n?i.jsxs(Ql,{openDelay:e,children:[i.jsx(ec,{asChild:!0,children:i.jsx(T.Button,{onClick:()=>u(l),size:"sm",className:ce.cn("h-7 w-7 rounded-md p-1",a===r?f:p),variant:"ghost",children:c})}),i.jsx(So,{className:"w-fit max-w-52 border-border",children:i.jsx("div",{className:"flex justify-between space-x-4",children:i.jsxs("div",{className:"space-y-1",children:[i.jsx("h4",{className:"text-sm font-semibold",children:h(s)}),t&&i.jsx("p",{className:"text-xs",children:h(o)})]})})})]}):i.jsx(T.Button,{onClick:()=>u(l),size:"sm",className:"h-7 w-7 rounded-md p-1",variant:a===r?"outline":"ghost",children:c})},tc=({openDelay:t=400,canvas:e=!1,tooltip:n=!0,buttonClass:s="",activeButtonClass:o=""})=>{const[r,,a]=gs(),[l,c]=ho(),[u,p]=Ug(),f=u,h=p,{t:m}=z.useTranslation(),x=$("breakpoints",Cr),b=C=>{f.includes(C)?f.length>2&&h(f.filter(A=>A!==C)):h(A=>[...A,C])},y=C=>{e||a(C),c(C)},k=ce.getBreakpointValue(e?l:r).toLowerCase();return x.length<4?i.jsx("div",{className:"flex items-center rounded-md",children:d.map(x,C=>g.createElement(Si,{canvas:e,...C,onClick:y,key:C.breakpoint,currentBreakpoint:k,activeButtonClass:"bg-gray-700"}))}):i.jsxs("div",{className:"flex w-full items-center justify-between rounded-md",children:[i.jsx("div",{className:"flex items-center",children:d.map(x.filter(C=>d.includes(f,d.toUpper(C.breakpoint))),C=>g.createElement(Si,{canvas:e,openDelay:t,tooltip:n,...C,onClick:y,key:C.breakpoint,currentBreakpoint:k,buttonClass:s,activeButtonClass:o}))}),i.jsxs(gt,{children:[i.jsx(xt,{asChild:!0,children:i.jsx("span",{className:"cursor-pointer rounded-md p-1 hover:bg-background",children:i.jsx(w.ChevronDownIcon,{className:"scale-90 transform"})})}),i.jsxs(Ze,{className:"w-56 border-border text-xs",children:[i.jsx(Ar,{children:m("Screen sizes")}),i.jsx(_r,{}),d.map(x,C=>i.jsx(zi,{disabled:C.breakpoint==="xs",onCheckedChange:()=>b(d.toUpper(C.breakpoint)),checked:d.includes(f,d.toUpper(C.breakpoint)),onSelect:A=>A.preventDefault(),children:m(C.title)},C.breakpoint))]})]})]})};function Yg(){const[,t]=gs(),{t:e}=z.useTranslation(),n=g.useMemo(()=>{const s=Cr.find(o=>o.breakpoint===t);return(s==null?void 0:s.content)??""},[t,Cr]);return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-start bg-muted px-2 py-1 shadow-sm",children:[i.jsxs("p",{className:"text-xs text-muted-foreground",children:[e("Screen")," "]}),i.jsx(tc,{openDelay:1e3,tooltip:!1})]}),i.jsx("div",{className:"mb-2 flex items-center justify-between rounded-md rounded-t-none border border-border p-1",children:i.jsx("p",{className:"flex flex-1 items-center space-x-2 text-[10px] text-foreground",children:i.jsxs("span",{className:"text-xs text-foreground",children:[i.jsx("span",{className:"rounded-md bg-muted px-1 py-px text-xs font-bold uppercase text-muted-foreground",children:t==="xs"?"Base":t}),"  ",e(n)]})})})]})}const nc=({className:t=""})=>i.jsx(w.TokensIcon,{className:t});function sc({from:t="default",classFromProps:e,onAddNew:n,onRemove:s,showDesignTokenSuggestions:o=!0}){var an;const r=g.useRef(null),[a,l]=g.useState(""),[c,u]=g.useState(!1),[p,f]=g.useState(-1),h=g.useRef(!1),m=Cg(),{t:x}=z.useTranslation(),[b]=Ae(),y=J(),k=Zl(),C=Co(),[A]=q(),[v,j]=g.useState(""),I=S.useAtomValue(Qt),N=(an=d.first(b))==null?void 0:an.prop,{classes:E}=ne.getSplitChaiClasses(d.get(y,N,"")),B=(t==="default"?E:e??"").split(" ").filter(F=>!d.isEmpty(F)),P=g.useMemo(()=>[...B].sort((F,te)=>{const Ce=F.startsWith(U.DESIGN_TOKEN_PREFIX),nt=te.startsWith(U.DESIGN_TOKEN_PREFIX);return Ce&&!nt?-1:!Ce&&nt?1:0}),[B]),R=$("flags.copyPaste",!0),M=F=>{const te=F.startsWith(U.DESIGN_TOKEN_PREFIX),Ce=i.jsx("div",{className:"group relative flex max-w-[260px] items-center",children:i.jsxs("button",{onDoubleClick:()=>{j(H(F)),t==="default"?C(A,[F],!0):(d.isFunction(s)&&s(F),j(F)),setTimeout(()=>{r.current&&r.current.focus()},10)},className:"flex h-max cursor-default items-center gap-x-1 truncate break-words rounded bg-gray-200 py-px pl-0.5 pr-1 text-[11px] text-gray-600 dark:bg-gray-800 dark:text-gray-300",children:[i.jsxs("div",{className:"z-10 flex h-full w-max items-center justify-center",children:[i.jsx(w.Cross2Icon,{onClick:()=>{t==="default"?C(A,[F],!0):d.isFunction(s)&&s(F)},className:"hidden h-max w-3.5 cursor-pointer rounded bg-gray-100 p-0.5 text-red-500 hover:bg-gray-50 group-hover:block"}),i.jsxs("svg",{className:"h-3.5 w-3.5 group-hover:hidden",fill:"rgba(55, 65, 81, 0.4)",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",xmlSpace:"preserve",children:[i.jsx("g",{id:"SVGRepo_bgCarrier",strokeWidth:"0"}),i.jsx("g",{id:"SVGRepo_tracerCarrier",strokeLinecap:"round",strokeLinejoin:"round"}),i.jsx("g",{id:"SVGRepo_iconCarrier",children:i.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M12 6.036c-2.667 0-4.333 1.325-5 3.976 1-1.325 2.167-1.822 3.5-1.491.761.189 1.305.738 1.906 1.345C13.387 10.855 14.522 12 17 12c2.667 0 4.333-1.325 5-3.976-1 1.325-2.166 1.822-3.5 1.491-.761-.189-1.305-.738-1.907-1.345-.98-.99-2.114-2.134-4.593-2.134zM7 12c-2.667 0-4.333 1.325-5 3.976 1-1.326 2.167-1.822 3.5-1.491.761.189 1.305.738 1.907 1.345.98.989 2.115 2.134 4.594 2.134 2.667 0 4.333-1.325 5-3.976-1 1.325-2.167 1.822-3.5 1.491-.761-.189-1.305-.738-1.906-1.345C10.613 13.145 9.478 12 7 12z"})})]})]}),i.jsx("div",{children:H(F)})]})},F);return te&&I[F]?i.jsxs(de,{delayDuration:200,children:[i.jsx(ue,{asChild:!0,children:Ce}),i.jsx(ae,{side:"bottom",className:"max-w-[300px]",children:i.jsx("p",{className:"font-light",children:I[F].value})})]},F):Ce},H=F=>{if(F.startsWith(U.DESIGN_TOKEN_PREFIX)){const te=I[F];return te?te.name:F}return F},G=F=>{const te=Object.entries(I).find(([,Ce])=>Ce.name===F);return te?`${te[0]}`:F},fe=()=>{const F=v.trim().replace(/ +(?= )/g,"").split(" ").map(G);t==="designToken"?d.isFunction(n)&&n(F):k(A,F,!0),j("")},[he,se]=g.useState([]),_e=$("flags.designTokens",!0),V=({value:F})=>{const te=F.trim().toLowerCase(),Ce=te.match(/.+:/g);let nt=[],Ws=[];if(_e&&o&&(te===""?Ws=Object.entries(I).map(([dt,ln])=>({name:ln.name,id:`${dt}`,isDesignToken:!0})):Ws=Object.entries(I).filter(([,dt])=>dt.name.toLowerCase().includes(te)).map(([dt,ln])=>({name:ln.name,id:`${dt}`,isDesignToken:!0}))),Ce&&Ce.length>0){const[dt]=Ce,ln=te.replace(dt,"");nt=m.search(ln).map(Gs=>({...Gs,item:{...Gs.item,name:dt+Gs.item.name}}))}else nt=m.search(te);const Fc=[...Ws,...d.map(nt,"item")];return se(Fc)},ve=()=>{se([])},Ue=F=>F.name,zt=F=>i.jsxs("div",{className:"flex items-center gap-2 rounded-md p-1",children:[F.isDesignToken&&i.jsx(nc,{className:"h-4 w-4 text-gray-600"}),i.jsx("span",{children:F.name})]}),Ht=g.useMemo(()=>({ref:r,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,placeholder:`${x(o?"Enter classes separated by space or design tokens":"Enter classes separated by space")}`,value:v,onFocus:F=>{setTimeout(()=>{F.target&&F.target.select()},0)},onKeyDown:F=>{if(F.key==="Enter"&&v.trim()!==""){if(h.current){h.current=!1;return}F.preventDefault(),fe()}if(F.key==="Tab"&&he.length>0){F.preventDefault();const te=new KeyboardEvent("keydown",{key:"ArrowDown",code:"ArrowDown",keyCode:40,bubbles:!0});F.target.dispatchEvent(te)}},onChange:(F,{newValue:te})=>j(te),className:`w-full rounded-md text-xs px-2 hover:outline-0 bg-background border-border ${t==="default"?"py-1":"py-1.5"}`}),[v,x,r,he.length]),ct=F=>{const te=a.trim().replace(/ +(?= )/g,"").split(" ").map(G);C(A,[F],!0),k(A,te,!0),l(""),f(-1)},Fo=()=>{if(navigator.clipboard===void 0){le.toast.error(x("Clipboard not supported"));return}navigator.clipboard.writeText(B.join(" ")),le.toast.success(x("Classes copied to clipboard")),u(!0),setTimeout(()=>u(!1),2e3)};return i.jsxs("div",{className:`flex w-full flex-col gap-y-1.5 pb-4 ${t==="designToken"?"border-none":"border-b border-border"}`,children:[i.jsx("div",{className:"flex items-center justify-between gap-x-2",children:i.jsx("div",{className:"flex w-full items-center justify-between gap-x-2 text-muted-foreground",children:i.jsxs("span",{className:"flex items-center gap-x-1",children:[i.jsx("span",{children:x("Classes")}),R&&i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:c?i.jsx(w.CheckIcon,{className:"rounded-full border border-green-500 bg-green-500/10 text-green-500"}):i.jsx(w.CopyIcon,{onClick:Fo,className:"cursor-pointer"})}),i.jsx(ae,{children:i.jsx("p",{children:x("Copy classes to clipboard")})})]})]})})}),i.jsxs("div",{className:"relative flex items-center gap-x-3",children:[i.jsx("div",{className:"relative flex w-full items-center gap-x-3",children:i.jsx(cd,{suggestions:he,onSuggestionsFetchRequested:V,onSuggestionsClearRequested:ve,getSuggestionValue:Ue,renderSuggestion:zt,inputProps:Ht,onSuggestionSelected:(F,{suggestionValue:te})=>{h.current=!0;const nt=[G(te)];t==="designToken"?d.isFunction(n)&&n(nt):k(A,nt,!0),j("")},containerProps:{className:"relative h-8 w-full gap-y-1 py-1 border-border text-xs"},theme:{suggestion:"bg-transparent",suggestionHighlighted:"!bg-gray-300 dark:!bg-gray-800 cursor-pointer",suggestionsContainerOpen:"absolute bg-background no-scrollbar z-50 max-h-[230px] overflow-y-auto w-full border border-border rounded-md"}})}),i.jsx(T.Button,{variant:"outline",className:`border-border ${t==="default"?"h-6":"mt-1 h-7"}`,onClick:fe,disabled:v.trim()==="",size:"sm",children:i.jsx(w.PlusIcon,{})})]}),i.jsx("div",{className:"flex w-full flex-wrap gap-2 overflow-x-hidden",children:P.map((F,te)=>p===te?i.jsx("input",{ref:r,value:a,onChange:Ce=>l(Ce.target.value),onBlur:()=>{ct(F)},onKeyDown:Ce=>{Ce.key==="Enter"&&ct(F)},onFocus:Ce=>{setTimeout(()=>{Ce.target.select()},0)},className:"group relative flex max-w-[260px] cursor-default items-center gap-x-1 truncate break-words rounded border border-border bg-gray-200 p-px px-1.5 pr-2 text-[11px] text-gray-600 hover:border-gray-300 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-300"},F):M(F))})]})}const Se=["px","%","em","rem","ch","vh","vw"],Jg={heading:"flex.heading",items:[{type:"arbitrary",label:"flex.basis",units:Se,property:"flexBasis"},{type:"range",label:"flex.order",property:"order"},{type:"dropdown",label:"flex.flex",property:"flexGrowShrink"},{type:"dropdown",label:"flex.grow",property:"flexGrow"},{type:"dropdown",label:"flex.shrink",property:"flexShrink"}]},Xg={heading:"grid.heading",items:[{type:"range",label:"grid.col_span",property:"gridColSpan"},{type:"range",label:"grid.col_start",property:"gridColStart"},{type:"range",label:"grid.col_end",property:"gridColEnd"},{type:"range",label:"grid.row_span",property:"gridRowSpan"},{type:"range",label:"grid.row_start",property:"gridRowStart"},{type:"range",label:"grid.row_end",property:"gridRowEnd"},{type:"range",label:"grid.order",property:"order"}]},Zg=[{heading:"Styles",items:[{component:sc},{component:Yg},{type:"arbitrary",label:"layout.width",units:Se.concat("auto"),property:"width"},{type:"arbitrary",label:"layout.height",units:Se.concat("auto"),property:"height"},{styleType:"multiple",label:"layout.margin",negative:!0,units:[...Se,"auto"],options:[{key:"margin",label:"layout.margin_all"},{key:"marginX",label:"layout.margin_lr"},{key:"marginY",label:"layout.margin_tb"},{key:"marginTop",label:"layout.margin_top"},{key:"marginRight",label:"layout.margin_right"},{key:"marginBottom",label:"layout.margin_bottom"},{key:"marginLeft",label:"layout.margin_left"}]},{styleType:"multiple",label:"layout.padding",options:[{key:"padding",label:"layout.padding_all"},{key:"paddingX",label:"layout.padding_lr"},{key:"paddingY",label:"layout.padding_tb"},{key:"paddingTop",label:"layout.padding_top"},{key:"paddingRight",label:"layout.padding_right"},{key:"paddingBottom",label:"layout.padding_bottom"},{key:"paddingLeft",label:"layout.padding_left"}]},{styleType:"accordion",heading:"typography.heading",items:[{type:"dropdown",property:"textAlign",label:"typography.align"},{type:"dropdown",property:"fontFamily",label:"typography.font"},{type:"arbitrary",property:"fontSize",label:"typography.size",units:Se},{type:"arbitrary",property:"lineHeight",label:"typography.height",units:Se.concat("-")},{type:"range",property:"fontWeight",label:"typography.weight"},{type:"color",property:"textColor",label:"typography.color"}]},{styleType:"accordion",heading:"background.heading",items:[{type:"color",label:"background.bgcolor",property:"backgroundColor"},{type:"dropdown",label:"background.attachment",property:"backgroundAttachment"},{type:"dropdown",label:"background.clipping",property:"backgroundClip"},{type:"dropdown",label:"background.origin",property:"backgroundOrigin"},{type:"dropdown",label:"background.position",property:"backgroundPosition"},{type:"dropdown",label:"background.repeat",property:"backgroundRepeat"},{type:"dropdown",label:"background.size",property:"backgroundSize"}]}]}];Se.concat("auto"),Se.concat("auto"),[...Se],Se.concat("auto"),Se.concat("auto"),Se.concat("auto"),Se.concat("auto"),Se.concat("-");const Qg={px:1,"%":1,em:100,rem:100,ch:1,vw:1,vh:1,"-":1,deg:1,ms:.1};function jr(){const{flexChild:t,gridChild:e}=Pd(),[n]=Ae(),[s,o]=g.useState(""),[r,a]=g.useState({onDrag:u=>u,onDragEnd:u=>u,dragStartY:0,dragging:!1,dragStartValue:0,dragUnit:"",negative:!1,cssProperty:""}),l=xe.useThrottledCallback(u=>{const p=!d.get(r,"negative",!1),f=d.get(r,"cssProperty","");let h=parseFloat(r.dragStartValue);h=isNaN(h)?0:h;let m=Qg[r.dragUnit];(d.startsWith(f,"scale")||f==="opacity")&&(m=10);let b=(r.dragStartY-u.pageY)/m+h;p&&b<0&&(b=0),f==="opacity"&&b>1&&(b=1),r.onDrag(`${b}`),o(`${b}`)},[r],50),c=g.useCallback(()=>{setTimeout(()=>r.onDragEnd(`${s}`),100),a({onDrag:u=>u,onDragEnd:u=>u,dragStartY:0,dragging:!1,dragStartValue:0,dragUnit:"",negative:!1,cssProperty:""})},[r,s,a]);return d.isEmpty(n)?null:i.jsxs(Kl.Provider,{value:{setDragData:a},children:[r.dragging?i.jsx("div",{onMouseMove:l,onMouseUp:()=>c(),className:"absolute inset-0 z-30 cursor-row-resize bg-gray-300/10"}):null,i.jsxs("div",{className:"flex flex-col",children:[i.jsx(dg,{}),i.jsxs(ig,{defaultValue:["Styles"],type:"multiple",className:"w-full",children:[t&&i.jsx(ar,{section:Jg,showAccordian:t||e}),e&&i.jsx(ar,{section:Xg,showAccordian:t||e}),Zg.map(u=>i.jsx(ar,{section:u,showAccordian:t||e},u.heading))]})]})]})}const Sn=O.forwardRef(({className:t,children:e,...n},s)=>i.jsxs(Et.Root,{ref:s,className:T.cn("relative overflow-hidden",t),...n,children:[i.jsx(Et.Viewport,{className:"h-full w-full rounded-[inherit]",children:e}),i.jsx(rc,{}),i.jsx(Et.Corner,{})]}));Sn.displayName=Et.Root.displayName;const rc=O.forwardRef(({className:t,orientation:e="vertical",...n},s)=>i.jsx(Et.ScrollAreaScrollbar,{ref:s,orientation:e,className:T.cn("flex touch-none select-none transition-colors",e==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",e==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",t),...n,children:i.jsx(Et.ScrollAreaThumb,{className:"relative flex-1 rounded-full bg-border"})}));rc.displayName=Et.ScrollAreaScrollbar.displayName;const $s=Lt.Root,On=O.forwardRef(({className:t,...e},n)=>i.jsx(Lt.List,{ref:n,className:T.cn("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",t),...e}));On.displayName=Lt.List.displayName;const ze=O.forwardRef(({className:t,...e},n)=>i.jsx(Lt.Trigger,{ref:n,className:T.cn("inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",t),...e}));ze.displayName=Lt.Trigger.displayName;const at=O.forwardRef(({className:t,...e},n)=>i.jsx(Lt.Content,{ref:n,className:T.cn("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",t),...e}));at.displayName=Lt.Content.displayName;const ex=({block:t,disabled:e,parentId:n,position:s})=>{const{type:o,icon:r,label:a,disabledReason:l}=t,c=e||t.disabled,{addCoreBlock:u,addPredefinedBlock:p}=bt(),f=()=>{if(d.has(t,"blocks")){const y=d.isFunction(t.blocks)?t.blocks():t.blocks;p(K.syncBlocksWithDefaultProps(y),n||null,s)}else u(t,n||null,s);oe.publish(Y.CLOSE_ADD_BLOCK)},h=Ye(),{t:m}=z.useTranslation(),{onDragStart:x,onDragEnd:b}=nn();return i.jsx(i.Fragment,{children:i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:i.jsxs("button",{disabled:c,onClick:f,type:"button",onDragStart:y=>!c&&x(y,{...t,label:a,icon:r}),onDragEnd:b,draggable:h&&!c,className:`${d.kebabCase(`chai-block-${o}`)} ${h&&!c?"cursor-grab active:cursor-grabbing":"cursor-pointer"} space-y-2 rounded-lg border border-border p-3 text-center hover:bg-slate-300/50 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:text-gray-400 dark:border-gray-700 dark:text-white dark:hover:bg-slate-800/50 dark:disabled:bg-gray-900 dark:disabled:text-foreground ${c?"opacity-50":""}`,children:[g.createElement(r||w.BoxIcon,{className:"w-4 h-4 mx-auto","data-add-core-block-icon":o}),i.jsx("p",{className:"truncate text-xs",children:d.capitalize(m(a||o))})]})}),i.jsx(ae,{children:i.jsx("p",{children:c&&l?l:m(a||o)})})]})})},oc=({parentId:t,position:e,gridCols:n="grid-cols-2",disableBlockGroupsSidebar:s=!1})=>{const o=K.useRegisteredChaiBlocks(),r=d.groupBy(o,"category"),a=d.uniq(d.map(r.core,"group"));return i.jsx(hc,{gridCols:n,parentId:t,position:e,groups:a,blocks:r.core,disableBlockGroupsSidebar:s})},No=O.forwardRef(({className:t,...e},n)=>i.jsx("div",{ref:n,className:T.cn("rounded-xl border bg-card text-card-foreground shadow",t),...e}));No.displayName="Card";const Eo=O.forwardRef(({className:t,...e},n)=>i.jsx("div",{ref:n,className:T.cn("flex flex-col space-y-1.5 p-6",t),...e}));Eo.displayName="CardHeader";const ic=O.forwardRef(({className:t,...e},n)=>i.jsx("div",{ref:n,className:T.cn("font-semibold leading-none tracking-tight",t),...e}));ic.displayName="CardTitle";const ac=O.forwardRef(({className:t,...e},n)=>i.jsx("div",{ref:n,className:T.cn("text-sm text-muted-foreground",t),...e}));ac.displayName="CardDescription";const Ao=O.forwardRef(({className:t,...e},n)=>i.jsx("div",{ref:n,className:T.cn("p-6 pt-0",t),...e}));Ao.displayName="CardContent";const _o=O.forwardRef(({className:t,...e},n)=>i.jsx("div",{ref:n,className:T.cn("flex items-center p-6 pt-0",t),...e}));_o.displayName="CardFooter";const tx=Sr.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),mt=O.forwardRef(({className:t,...e},n)=>i.jsx($i.Root,{ref:n,className:T.cn(tx(),t),...e}));mt.displayName=$i.Root.displayName;const $n=O.forwardRef(({className:t,...e},n)=>i.jsx("textarea",{className:T.cn("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:n,...e}));$n.displayName="Textarea";const lc=({parentId:t,position:e,fromSidebar:n})=>{const{t:s}=z.useTranslation(),[o,r]=g.useState(""),{addPredefinedBlock:a}=bt(),[l,c]=g.useState(!1),u=async()=>{c(!0);const p=await T.getPreImportHTML(o),f=ne.getBlocksFromHTML(p);a([...f],t,e),r(""),c(!1),oe.publish(Y.CLOSE_ADD_BLOCK)};return i.jsxs(No,{className:`border-border/0 p-0 shadow-none ${n?"w-full":"max-w-full"}`,children:[i.jsx(Eo,{className:n?"p-0":"p-3",children:i.jsx(ac,{className:n?"text-xs":"",children:s("Use HTML snippets from Tailwind CSS component libraries")})}),i.jsx(Ao,{className:`space-y-2 py-0 ${n?"p-0":"px-3"}`,children:i.jsxs("div",{className:"space-y-1",children:[i.jsx(mt,{htmlFor:"current",className:"text-sm",children:s("Tailwind HTML snippet")}),i.jsx($n,{onChange:p=>r(p.target.value),rows:12,value:o,placeholder:s("Enter your code snippet here"),className:"resize-none overflow-x-auto whitespace-pre bg-background font-mono text-xs font-normal"})]})}),i.jsx(_o,{className:"flex flex-col justify-end p-3",children:i.jsx(T.Button,{disabled:o.trim()===""||l,onClick:()=>u(),size:"sm",className:"w-fit",children:l?i.jsxs(i.Fragment,{children:[i.jsx(w.CircleIcon,{className:"mr-2 h-4 w-4 animate-spin"})," ",s("Importing...")]}):s("Import HTML")})})]})},Fs=ye.Root,Io=ye.Value,Fn=O.forwardRef(({className:t,children:e,...n},s)=>i.jsxs(ye.Trigger,{ref:s,className:T.cn("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[placeholder]:text-muted-foreground [&>span]:line-clamp-1",t),...n,children:[e,i.jsx(ye.Icon,{asChild:!0,children:i.jsx(w.ChevronDownIcon,{className:"h-4 w-4 opacity-50"})})]}));Fn.displayName=ye.Trigger.displayName;const cc=O.forwardRef(({className:t,...e},n)=>i.jsx(ye.ScrollUpButton,{ref:n,className:T.cn("flex cursor-default items-center justify-center py-1",t),...e,children:i.jsx(w.ChevronUpIcon,{className:"h-4 w-4"})}));cc.displayName=ye.ScrollUpButton.displayName;const dc=O.forwardRef(({className:t,...e},n)=>i.jsx(ye.ScrollDownButton,{ref:n,className:T.cn("flex cursor-default items-center justify-center py-1",t),...e,children:i.jsx(w.ChevronDownIcon,{className:"h-4 w-4"})}));dc.displayName=ye.ScrollDownButton.displayName;const zn=O.forwardRef(({className:t,children:e,position:n="popper",...s},o)=>i.jsx(ye.Portal,{children:i.jsxs(ye.Content,{ref:o,className:T.cn("relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] origin-[--radix-select-content-transform-origin] overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:n,...s,children:[i.jsx(cc,{}),i.jsx(ye.Viewport,{className:T.cn("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:e}),i.jsx(dc,{})]})}));zn.displayName=ye.Content.displayName;const nx=O.forwardRef(({className:t,...e},n)=>i.jsx(ye.Label,{ref:n,className:T.cn("px-2 py-1.5 text-sm font-semibold",t),...e}));nx.displayName=ye.Label.displayName;const Hn=O.forwardRef(({className:t,children:e,...n},s)=>i.jsxs(ye.Item,{ref:s,className:T.cn("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...n,children:[i.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(ye.ItemIndicator,{children:i.jsx(w.CheckIcon,{className:"h-4 w-4"})})}),i.jsx(ye.ItemText,{children:e})]}));Hn.displayName=ye.Item.displayName;const sx=O.forwardRef(({className:t,...e},n)=>i.jsx(ye.Separator,{ref:n,className:T.cn("-mx-1 my-1 h-px bg-muted",t),...e}));sx.displayName=ye.Separator.displayName;const rx=({defaultValue:t="",onValueChange:e,options:n,placeholder:s="Select",className:o="",height:r=""})=>{const[a,l]=g.useState(t),c=u=>{const p=u.target.value;l(p),e(p)};return i.jsx("div",{className:ce.cn("relative inline-block w-full",o),children:i.jsxs("select",{className:ce.cn("mt-1 flex w-full rounded-md border border-border bg-background px-3 py-1 text-sm text-foreground shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",r),value:a,onChange:c,children:[i.jsx("option",{value:"",disabled:!0,children:s}),n.map(u=>i.jsx("option",{value:u.value,children:u.label},u.value))]})})};function ox({uiLibraries:t,library:e,setLibrary:n}){const{t:s}=z.useTranslation();return e?i.jsxs("div",{className:"h-12",children:[i.jsx("p",{className:"text-xs font-bold text-gray-500",children:s("Choose library")}),i.jsx(rx,{className:"mb-1",options:t.map(o=>({value:o.id,label:o.name})),defaultValue:e,onValueChange:o=>n(o)})]}):null}const ix=S.atom({}),ax=t=>{const[e,n]=S.useAtom(ix),s=g.useMemo(()=>(t==null?void 0:t.getBlocksList)||(()=>[]),[t]),o=d.get(e,`${t==null?void 0:t.id}.blocks`,null),r=d.get(e,`${t==null?void 0:t.id}.loading`,"idle"),a=d.get(e,`${t==null?void 0:t.id}.error`,!1),l=g.useRef("idle");g.useEffect(()=>{(async()=>{if(t&&!(r==="complete"||l.current==="loading")){l.current="loading",n(u=>({...u,[t==null?void 0:t.id]:{loading:"loading",blocks:[],error:!1}}));try{const u=await s(t);l.current="idle",n(p=>({...p,[t==null?void 0:t.id]:{loading:"complete",blocks:u||[],error:!1}}))}catch{l.current="idle",n(u=>({...u,[t==null?void 0:t.id]:{loading:"complete",blocks:[],error:!0}}))}}})()},[t,o,r,l,n,s]);const c=g.useCallback(u=>{n(p=>({...p,[u]:{loading:"idle",blocks:[],error:!1}}))},[n]);return{data:o||[],isLoading:r==="loading",isError:a,resetLibrary:c}},lx=()=>S.useAtom(Kr),uc=({block:t,html:e,blocks:n,children:s,onDragStart:o,onDragEnd:r,draggable:a,className:l="",type:c="Box"})=>{const{onDragStart:u,onDragEnd:p}=nn(),f=Ye(),[,h]=q(),{clearHighlight:m}=et(),x=a!==void 0?a:f,b=async k=>{try{if(o){o(k);return}let C=null;if(c==="Image"){if(!(t!=null&&t.image))return;C={type:"Image",blocks:[{_type:"Image",styles:"#styles:,w-full h-full object-cover",image:t==null?void 0:t.image,alt:(t==null?void 0:t.alt)||"",_name:(t==null?void 0:t.name)||"Image"}]}}else if(e){const A=typeof e=="function"?await e():e,v=ne.getBlocksFromHTML(A);if(d.isEmpty(v))return;C={type:"Box",blocks:v,name:d.get(v,"0._type","Block")}}else if(n){const A=typeof n=="function"?await n():n;if(d.isEmpty(A))return;C={type:"Box",blocks:A,name:d.get(A,"0._type","Block")}}else if(t){const A=typeof t=="function"?await t():t;C=typeof A=="object"?d.omit(A,["component","icon"]):A}if(!C)return;u(k,C,!0),setTimeout(()=>{h([]),m()},200)}catch(C){console.error("Error in ChaiDraggableBlock drag start:",C)}},y=k=>{r?r(k):p()};return i.jsx("div",{draggable:x,onDragStart:b,onDragEnd:y,className:`${x?"cursor-grab active:cursor-grabbing":""} ${l}`.trim(),children:s})};function pc({value:t,setValue:e}){const{t:n}=z.useTranslation();return i.jsx("div",{className:"flex py-2",children:i.jsxs("div",{className:"relative flex w-full max-w-md items-center rounded border px-2",children:[i.jsxs("div",{className:"flex w-full items-center gap-x-2",children:[i.jsx(w.MagnifyingGlassIcon,{className:"h-5 w-5 flex-shrink-0 stroke-[1px] text-muted-foreground"}),i.jsx(T.Input,{placeholder:n("Search blocks..."),value:t,onChange:s=>e(s.target.value),className:"w-full flex-1 border-none p-0 leading-tight outline-none"})]}),t&&i.jsx("button",{onClick:()=>e(""),className:"absolute right-2.5 top-2.5 text-muted-foreground hover:text-foreground",children:i.jsx(w.Cross1Icon,{className:"h-3.5 w-3.5"})})]})})}const Ni=({block:t,library:e,parentId:n=void 0,position:s=-1})=>{const[o,r]=g.useState(!1),a=g.useMemo(()=>(e==null?void 0:e.getBlock)||(()=>[]),[e]),{addCoreBlock:l,addPredefinedBlock:c}=bt(),u=d.get(t,"name",d.get(t,"label")),p=d.get(t,"description",""),{onDragStart:f,onDragEnd:h}=nn(),m=Ye(),x=g.useCallback(async y=>{if(y.stopPropagation(),d.has(t,"component")){l(t,n,s),oe.publish(Y.CLOSE_ADD_BLOCK);return}r(!0);let k=await a({library:e,block:t});typeof k=="string"&&(k=ne.getBlocksFromHTML(k)),d.isEmpty(k)||c(K.syncBlocksWithDefaultProps(k),n,s),oe.publish(Y.CLOSE_ADD_BLOCK),setTimeout(()=>r(!1),1e3)},[l,c,t,a,e,n,s]),b=async y=>{if(!m)return;let k=await a({library:e,block:t});typeof k=="string"&&(k=ne.getBlocksFromHTML(k)),f(y,{type:"Box",blocks:k,name:u},!0)};return i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:i.jsx(uc,{draggable:m,onDragStart:b,onDragEnd:h,children:i.jsxs("div",{onClick:o?()=>{}:x,className:Li("relative mt-2 overflow-hidden rounded-md border border-border duration-200 hover:border-blue-500 hover:shadow-xl",m?"":"cursor-pointer"),children:[o&&i.jsxs("div",{className:"absolute flex h-full w-full items-center justify-center bg-black/70",children:[i.jsx(w.ReloadIcon,{className:"h-4 w-4 animate-spin text-white"}),i.jsx("span",{className:"pl-2 text-sm text-white",children:"Adding..."})]}),t.preview?i.jsx("img",{src:t.preview,className:"min-h-[45px] w-full rounded-md",alt:u}):i.jsxs("div",{className:"flex h-fit w-full flex-col items-center justify-center gap-1 rounded-md border border-border p-6 py-10 text-center",children:[i.jsx("p",{className:"font-medium text-gray-800",children:u}),p&&i.jsx("p",{className:"text-sm text-gray-600",children:p})]})]})})}),i.jsx(ae,{children:i.jsx("div",{className:"max-w-xs",children:i.jsx("p",{className:"font-medium",children:u})})})]})},cx=({parentId:t,position:e,fromSidebar:n})=>{const[s,o]=lx(),r=T.useChaiLibraries(),a=r.find(R=>R.id===s)||d.first(r),{data:l,isLoading:c,isError:u,resetLibrary:p}=ax(a),[f,h]=g.useState(""),[m,x]=g.useState([]),b=g.useRef(null);g.useEffect(()=>{l&&Array.isArray(l)&&l.length>0&&(b.current=new Mi(l,{keys:["name","label","description","group"],threshold:.4,ignoreLocation:!0}))},[l]),g.useEffect(()=>{if(!f.trim()||!b.current){x([]);return}const R=b.current.search(f).map(M=>M.item);x(R)},[f]);const y=f.trim()&&!d.isEmpty(m)?m:l||[],k=d.groupBy(y,"group"),[C,A]=g.useState(null);g.useEffect(()=>{if(d.isEmpty(d.keys(k))){A(null);return}if(!C||!k[C]){A(d.first(d.keys(k))||null);return}},[k,C]);const v=d.get(k,C||"",[]),j=g.useRef(null),{t:I}=z.useTranslation(),N=g.useRef(null);g.useEffect(()=>{var M;const R=(M=N.current)==null?void 0:M.querySelector("[data-radix-scroll-area-viewport]");R&&R.scrollTo({top:0,behavior:"smooth"})},[a,C]);const E=R=>{j.current&&(clearTimeout(j.current),j.current=null),j.current=setTimeout(()=>{j.current&&A(R)},400)},_=()=>{a!=null&&a.id&&p(a.id)};if(c)return i.jsxs("div",{className:"mt-4 grid h-full w-full grid-cols-12 gap-2",children:[i.jsx(Jt,{className:"col-span-3 h-full"}),i.jsx(Jt,{className:"col-span-9 h-full"})]});const B=d.filter(v,(R,M)=>M%2===0),P=d.filter(v,(R,M)=>M%2===1);return i.jsx(i.Fragment,{children:i.jsxs("div",{className:"flex h-full max-h-full flex-col",children:[i.jsx(pc,{value:f,setValue:h}),i.jsx("div",{className:"relative flex h-full max-h-full flex-1 overflow-hidden bg-background",children:i.jsxs("div",{className:`flex h-full flex-1 pt-2 ${n?"flex-col":""}`,children:[i.jsxs("div",{className:`flex max-h-full min-w-60 flex-col gap-1 ${n?"pb-2":"w-60 max-w-60 px-1 pr-2"}`,children:[i.jsx(ox,{library:a==null?void 0:a.id,setLibrary:o,uiLibraries:r}),i.jsxs("div",{className:"mt-2 flex h-full max-h-full w-full flex-1 flex-col",children:[i.jsx("span",{className:"text-xs font-bold text-gray-500",children:I("Groups")}),!n&&i.jsx("hr",{className:"mt-1 border-border"}),i.jsx("div",{className:`no-scrollbar mt-2 h-full max-h-full flex-1 overflow-y-auto ${n?"":"pb-20"}`,children:d.isEmpty(k)?i.jsx("div",{className:"mt-4 flex flex-col items-center justify-center gap-3 p-4 text-center",children:f?i.jsx("p",{className:"text-sm",children:I("No matching blocks found")}):u?i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-sm",children:I("Failed to load the UI library. Try again")}),i.jsxs(T.Button,{onClick:_,variant:"outline",size:"sm",className:"gap-2",children:[i.jsx(w.ReloadIcon,{className:"h-4 w-4"}),I("Retry")]})]}):i.jsx("p",{className:"text-sm",children:I("This library is empty")})}):n?i.jsxs(Fs,{value:C??"",onValueChange:A,children:[i.jsx(Fn,{className:"w-full",children:i.jsx(Io,{placeholder:I("Select a group")})}),i.jsx(zn,{children:d.map(k,(R,M)=>i.jsx(Hn,{value:M,children:d.capitalize(I(M.toLowerCase()))},M))})]}):d.map(k,(R,M)=>i.jsxs("div",{onMouseEnter:()=>E(M),onMouseLeave:()=>j.current&&clearTimeout(j.current),role:"button",onClick:()=>A(M),className:T.cn("flex w-full cursor-pointer items-center justify-between rounded-md p-2 text-sm text-foreground transition-all ease-in-out hover:bg-gray-200 dark:hover:bg-gray-800",M===C?"bg-primary text-primary-foreground hover:bg-primary/80":""),children:[i.jsx("span",{children:d.capitalize(I(M.toLowerCase()))}),i.jsx(w.CaretRightIcon,{className:"ml-2 h-5 w-5"})]},M))})]})]}),i.jsx("div",{className:`flex h-full max-h-full w-full flex-col border-border ${n?"":"border-l"}`,children:i.jsxs(Sn,{ref:N,onMouseEnter:()=>j.current&&clearTimeout(j.current),className:"z-10 flex h-full max-h-full w-full flex-col gap-2 transition-all ease-linear",children:[d.isEmpty(v)&&!d.isEmpty(k)?i.jsx("div",{className:"flex h-full flex-col items-center justify-center p-6 text-center",children:i.jsx("p",{className:"text-sm",children:I("No blocks found in this group")})}):i.jsxs("div",{className:`grid w-full gap-2 ${n?"grid-cols-1 pb-20":"grid-cols-2 px-2"}`,children:[i.jsx("div",{className:"flex flex-col gap-1",children:B.map((R,M)=>i.jsx(Ni,{parentId:t,position:e,block:R,library:a},`block-${M}`))}),i.jsx("div",{className:"flex flex-col gap-1",children:P.map((R,M)=>i.jsx(Ni,{parentId:t,position:e,block:R,library:a},`block-second-${M}`))})]}),i.jsx("br",{}),i.jsx("br",{}),i.jsx("br",{})]})})]})})]})})},fc=({parentId:t,position:e,fromSidebar:n})=>i.jsx(cx,{parentId:t,position:e,fromSidebar:n}),dx=S.atom({blocks:[],groups:[],isLoading:!0,error:null}),ux=S.atom(!1),Ei=t=>{if(!t)return"";let e=t.replace(/[-_]/g," ");return e=e.replace(/([a-z])([A-Z])/g,"$1 $2"),e.split(" ").map(n=>n.charAt(0).toUpperCase()+n.slice(1).toLowerCase()).join(" ")},px=({parentId:t,position:e,gridCols:n="grid-cols-2",disableBlockGroupsSidebar:s=!1})=>{const{data:o,isLoading:r,refetch:a,error:l}=oa(),[c,u]=S.useAtom(dx),[p,f]=S.useAtom(ux),h=ia();g.useEffect(()=>{if(!p||Object.keys(c.blocks).length===0)if(l)u({blocks:[],groups:[],isLoading:!1,error:l}),f(!0);else if(!r&&Object.keys(o||{}).length>0){const b=Object.entries(o).map(([k,C])=>{const A=C,v=A.type||"partial",j=Ei(v);return{type:"PartialBlock",label:Ei(A.name||k),description:A.description||"",icon:w.FrameIcon,group:j,category:"partial",partialBlockId:k,_name:A.name}}),y=d.uniq(d.map(b,"group"));u({blocks:b,groups:y,isLoading:!1,error:null}),f(!0)}else r?u(b=>({...b,isLoading:!0,error:null})):!r&&Object.keys(o||{}).length===0&&(u({blocks:[],groups:[],isLoading:!1,error:"No partial blocks available"}),f(!0))},[r,o,p,f,u,c.blocks,l]);const m=()=>{u(b=>({...b,isLoading:!0,error:null})),f(!1),a()},x=g.useMemo(()=>c.blocks.map(b=>{const{canAdd:y,reason:k}=h(b.partialBlockId);return{...b,disabled:!y,disabledReason:k}}),[c.blocks,h]);return c.isLoading?i.jsx("div",{className:"flex items-center justify-center p-8 text-center text-muted-foreground",children:"Loading partial blocks..."}):c.error||c.blocks.length===0?i.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 p-8 text-center text-muted-foreground",children:[i.jsx("p",{children:c.error||"No partial blocks available"}),i.jsx("button",{onClick:m,className:"rounded-md bg-primary px-3 py-1 text-sm text-primary-foreground hover:bg-primary/90",children:"Refresh"})]}):i.jsx(hc,{gridCols:n,parentId:t,position:e,groups:c.groups,blocks:x,disableBlockGroupsSidebar:s})},Ai=["basic","typography","media","layout","form","advanced","other"],hc=({groups:t,blocks:e,parentId:n,position:s,gridCols:o="grid-cols-4",disableBlockGroupsSidebar:r})=>{var P;const{t:a}=z.useTranslation(),[l]=Z(),[c,u]=g.useState(""),p=g.useRef(null),[f]=S.useAtom(mc),h=(P=d.find(l,R=>R._id===n))==null?void 0:P._type,[m,x]=g.useState("all"),[b,y]=g.useState(null),k=g.useRef(null),C=$("flags.dragAndDrop",!0);g.useEffect(()=>{const R=setTimeout(()=>{var M;(M=p.current)==null||M.focus()},0);return()=>clearTimeout(R)},[f]),g.useEffect(()=>{c&&(x("all"),y(null))},[c]),g.useEffect(()=>(k.current=d.debounce(R=>{x(R)},500),()=>{k.current&&k.current.cancel()}),[]);const A=g.useCallback(R=>{y(R),k.current&&k.current(R)},[]),v=g.useCallback(()=>{y(null),k.current&&k.current.cancel()},[]),j=g.useCallback(R=>{k.current&&k.current.cancel(),x(R),y(null)},[]),I=g.useMemo(()=>c?d.values(e).filter(R=>{var M,H;return(((M=R.label)==null?void 0:M.toLowerCase())+" "+((H=R.type)==null?void 0:H.toLowerCase())).includes(c.toLowerCase())}):e,[e,c]),N=g.useMemo(()=>c?t.filter(R=>d.reject(d.filter(d.values(I),{group:R}),{hidden:!0}).length>0):t.filter(R=>d.reject(d.filter(d.values(e),{group:R}),{hidden:!0}).length>0),[e,I,t,c]),E=g.useMemo(()=>d.sortBy(N,R=>Ai.indexOf(R)===-1?99:Ai.indexOf(R)),[N]),_=g.useMemo(()=>m==="all"?I:d.filter(d.values(I),{group:m}),[I,m]),B=g.useMemo(()=>m==="all"?E:[m],[E,m]);return i.jsxs("div",{className:"mx-auto flex h-full w-full flex-col",children:[i.jsx(pc,{value:c,setValue:u}),i.jsxs("div",{className:"sticky top-10 flex h-[calc(100%-48px)] overflow-hidden pt-2",children:[!r&&E.length>0&&i.jsx("div",{className:"w-1/4 min-w-[120px] border-r border-border",children:i.jsx(Sn,{className:"h-full",children:i.jsxs("div",{className:"space-y-1",children:[i.jsx("button",{onClick:()=>j("all"),onMouseEnter:()=>A("all"),onMouseLeave:v,className:`w-full rounded-md px-2 py-1.5 text-left text-sm font-medium ${m==="all"||b==="all"?"bg-primary text-primary-foreground":"hover:bg-primary/50 hover:text-primary-foreground"}`,children:a("All")},"sidebar-all"),E.map(R=>i.jsx("button",{onClick:()=>j(R),onMouseEnter:()=>A(R),onMouseLeave:v,className:`w-full rounded-md px-2 py-1.5 text-left text-sm ${m===R||b===R?"bg-primary text-primary-foreground":"hover:bg-primary/50 hover:text-primary-foreground"}`,children:d.capitalize(a(R.toLowerCase()))},`sidebar-${R}`))]})})}),i.jsx("div",{className:`h-full flex-1 overflow-hidden ${!r&&E.length>0?"w-3/4":"w-full"}`,children:i.jsx(Sn,{id:"add-blocks-scroll-area",className:"no-scrollbar h-full",children:N.length===0&&c?i.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center text-muted-foreground",children:i.jsxs("p",{children:[a("No blocks found matching"),' "',c,'"']})}):i.jsx("div",{className:`${r?"p-0":"p-4"} space-y-6`,children:B.map((R,M)=>i.jsxs("div",{className:"space-y-3",children:[i.jsx("h3",{className:"px-1 text-sm font-medium",children:d.capitalize(a(R.toLowerCase()))}),i.jsx("div",{className:"grid gap-2 "+o,children:d.reject(m==="all"?d.filter(d.values(_),{group:R}):d.values(_),{hidden:!0}).map((H,G)=>i.jsx(ex,{parentId:n,position:s,block:H,disabled:!C&&(!Qe(h,H.type)||!Nd(h,H.type))},H.type+"-"+M+"-"+G))})]},R))})})})]})]})},mc=He.atomWithStorage("__add_block_tab","library"),To=({className:t,showHeading:e=!0,parentId:n=void 0,position:s=-1,fromSidebar:o=!1})=>{const{t:r}=z.useTranslation(),[a,l]=S.useAtom(mc),[,c]=S.useAtom(ca),u=$("flags.importHtml",!0),{data:p}=oa(),f=Object.keys(p||{}).length>0,{hasPermission:h}=Ge();g.useEffect(()=>{a==="partials"&&!f&&l("library")},[a,f,l]);const m=g.useCallback(()=>{oe.publish(Y.CLOSE_ADD_BLOCK)},[]),x=T.useChaiAddBlockTabs(),b=u&&h(be.IMPORT_HTML),k=T.useChaiLibraries().length>0;return g.useEffect(()=>{a==="library"&&!k&&l("core")},[a,k,l]),i.jsxs("div",{className:ce.cn("flex h-full w-full flex-col overflow-hidden",t),children:[e?i.jsxs("div",{className:"mb-2 flex flex-col justify-between rounded-md bg-background/30 p-1",children:[i.jsx("h1",{className:"flex flex-col items-baseline px-1 text-xl font-semibold xl:flex-col",children:r("Add block")}),i.jsx("span",{className:"p-0 text-xs font-light leading-3 opacity-80 xl:pl-1",children:r(a==="html"?"Enter or paste TailwindCSS HTML snippet":"Click to add block to page")})]}):null,i.jsxs($s,{onValueChange:C=>{c(""),l(C)},value:a,className:"flex h-full max-h-full flex-col overflow-hidden",children:[i.jsxs(On,{className:`flex items-center ${o?"h-max w-max justify-start p-1":"w-full"}`,children:[k&&i.jsx(ze,{value:"library",className:o?"h-5 px-2 text-xs":"",children:r("Library")}),i.jsx(ze,{value:"core",className:o?"h-5 px-2 text-xs":"",children:r("Blocks")}),f&&i.jsx(ze,{value:"partials",className:o?"h-5 px-2 text-xs":"",children:r("Partials")}),b?i.jsx(ze,{value:"html",className:o?"h-5 px-2 text-xs":"",children:r("Import")}):null,d.map(x,C=>i.jsx(ze,{value:C.id,className:o?"h-5 px-2 text-xs":"",children:g.createElement(C.tab)},`tab-add-block-${C.id}`))]}),i.jsx(at,{value:"core",className:"h-full max-h-full flex-1 pb-20",children:i.jsx("div",{className:"h-full max-h-full overflow-hidden",children:i.jsx("div",{className:"h-full w-full",children:i.jsx(oc,{gridCols:o?"grid-cols-2":"grid-cols-4",parentId:n,position:s,disableBlockGroupsSidebar:o})})})}),k&&i.jsx(at,{value:"library",className:"h-full max-h-full flex-1 pb-20",children:i.jsx(fc,{fromSidebar:o,parentId:n,position:s})}),f&&i.jsx(at,{value:"partials",className:"h-full max-h-full flex-1 pb-20",children:i.jsx("div",{className:"h-full max-h-full overflow-hidden",children:i.jsx("div",{className:"h-full w-full",children:i.jsx(px,{gridCols:o?"grid-cols-2":"grid-cols-4",parentId:n,position:s,disableBlockGroupsSidebar:o})})})}),b?i.jsx(at,{value:"html",className:"h-full max-h-full flex-1 pb-20 ",children:i.jsx(lc,{parentId:n,position:s,fromSidebar:o})}):null,d.map(x,C=>i.jsx(at,{value:C.id,children:g.createElement(C.tabContent,{close:m,parentId:n,position:s})},`panel-add-block-${C.id}`))]})]})},fx={display:"flex",alignItems:"center",zIndex:1},hx=g.memo(function({top:e,left:n,indent:s}){const o={position:"absolute",pointerEvents:"none",top:e-1+"px",left:"0px",right:0,paddingLeft:n+s+"px"};return i.jsxs("div",{style:{...fx,...o},children:[i.jsx("div",{className:"h-1 w-1 rounded-full bg-green-500"}),i.jsx("div",{className:"h-[1px] flex-1 rounded-[1px] border-t border-green-500"})]})}),mx=[{key:"ArrowDown",command:"selectNext"},{key:"ArrowUp",command:"selectPrev"},{key:"ArrowLeft",command:"selectParent",when:"isLeaf || isClosed"},{key:"ArrowLeft",command:"close",when:"isOpen"},{key:"ArrowRight",command:"open",when:"isClosed"},{key:"ArrowRight",command:"selectNext",when:"isOpen"},{key:"Home",command:"selectFirst"},{key:"End",command:"selectLast"}];function gx(t){t.firstNode&&t.select(t.firstNode.id)}function xx(t){t.lastNode&&t.select(t.lastNode.id)}function bx(t){const e=t.selectedNodes[0].next||t.firstNode;t.select(e.id)}function yx(t){const e=t.selectedNodes[0].prev||t.lastNode;t.select(e.id)}const kx=(t,e)=>{const n=t.selectedNodes[0],s=(n==null?void 0:n.parent)||null;s&&e&&t.select(s.id)},vx=(t,e)=>{const n=t.selectedNodes[0];n.isInternal&&e&&n.open()},wx=(t,e)=>{const n=t.selectedNodes[0];n.isInternal&&e&&n.close()},Bo=Pe.Root,gc=Pe.Trigger,Cx=Pe.Portal,xc=O.forwardRef(({className:t,...e},n)=>i.jsx(Pe.Overlay,{className:T.cn("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/80",t),...e,ref:n}));xc.displayName=Pe.Overlay.displayName;const zs=O.forwardRef(({className:t,...e},n)=>i.jsxs(Cx,{children:[i.jsx(xc,{}),i.jsx(Pe.Content,{ref:n,className:T.cn("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 sm:rounded-lg",t),...e})]}));zs.displayName=Pe.Content.displayName;const Hs=({className:t,...e})=>i.jsx("div",{className:T.cn("flex flex-col space-y-2 text-center sm:text-left",t),...e});Hs.displayName="AlertDialogHeader";const Ro=({className:t,...e})=>i.jsx("div",{className:T.cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...e});Ro.displayName="AlertDialogFooter";const Vs=O.forwardRef(({className:t,...e},n)=>i.jsx(Pe.Title,{ref:n,className:T.cn("text-lg font-semibold",t),...e}));Vs.displayName=Pe.Title.displayName;const Po=O.forwardRef(({className:t,...e},n)=>i.jsx(Pe.Description,{ref:n,className:T.cn("text-sm text-muted-foreground",t),...e}));Po.displayName=Pe.Description.displayName;const Lo=O.forwardRef(({className:t,...e},n)=>i.jsx(Pe.Action,{ref:n,className:T.cn(T.buttonVariants(),t),...e}));Lo.displayName=Pe.Action.displayName;const Do=O.forwardRef(({className:t,...e},n)=>i.jsx(Pe.Cancel,{ref:n,className:T.cn(T.buttonVariants({variant:"outline"}),"mt-2 sm:mt-0",t),...e}));Do.displayName=Pe.Cancel.displayName;const bc=({children:t})=>{const{t:e}=z.useTranslation(),{setNewBlocks:n}=Ee(),[,s]=q(),[,o]=Ae(),r=g.useCallback(()=>{n([]),s([]),o([])},[n]);return i.jsx("div",{className:"flex items-center",children:i.jsxs(Bo,{children:[i.jsx(gc,{asChild:!0,children:t||i.jsx(T.Button,{size:"sm",variant:"ghost",className:"flex items-center",children:i.jsx(w.EraserIcon,{})})}),i.jsxs(zs,{className:"border-border",children:[i.jsxs(Hs,{children:[i.jsx(Vs,{className:"text-foreground",children:e("Clear whole canvas?")}),i.jsx(Po,{children:e("Are you sure you want to clear the page?")})]}),i.jsxs(Ro,{children:[i.jsx(Do,{className:"text-foreground",children:e("Cancel")}),i.jsx(Lo,{onClick:r,children:e("Yes")})]})]})]})})},jx=()=>{const t=J(),{t:e}=z.useTranslation(),[,n]=S.useAtom(ta),s=T.useSaveToLibraryComponent(),o=()=>{t&&n({isOpen:!0,blockId:t._id})};return s?i.jsxs(ge,{className:"flex items-center gap-x-4 text-xs",onClick:o,children:[i.jsx(w.CheckIcon,{className:"h-4 w-4"})," ",t!=null&&t._libBlockId?e("Update library block"):e("Save to library")]}):null},Sx=()=>{const{t}=z.useTranslation(),e=J(),n=Ke(),s=()=>{e&&n([e._id],{_libBlockId:null})};return i.jsxs(ge,{onClick:s,className:"flex items-center gap-x-4 text-xs",children:[i.jsx(w.LinkBreak2Icon,{className:"h-4 w-4"})," ",t("Unlink from library")]})},_i=()=>{const{t}=z.useTranslation(),[e]=q();return $("flags.exportCode",!1)?i.jsxs(ge,{className:"flex items-center gap-x-4 text-xs",onClick:()=>oe.publish(Y.OPEN_EXPORT_CODE,e),children:[i.jsx(w.DownloadIcon,{})," ",t("Export")]}):null},Ii=({isFromBody:t=!1})=>{const[e]=Z(),[n]=q(),{pasteBlocks:s}=eo(),[,o,r]=_a(),{t:a}=z.useTranslation(),l=J(),c=$("flags.copyPaste",!0),u=g.useCallback(()=>{var h;const f=(t?(h=e==null?void 0:e.filter(m=>!(m!=null&&m._parent)))==null?void 0:h.map(m=>m==null?void 0:m._id):n).map(m=>{const x=e.find(b=>b._id===m);return{id:m,data:x}});r(f.map(m=>m.id))?le.toast.warning("Partial blocks detected. Clone partial blocks?",{cancel:{label:a("No"),onClick:()=>{o(f.map(m=>m.id)),le.toast.dismiss()}},action:{label:a("Yes"),onClick:()=>{o(f.map(m=>m.id),!0),le.toast.dismiss()}},position:"top-center"}):o(f.map(m=>m.id))},[n,e,o,r]);return i.jsxs(i.Fragment,{children:[c&&i.jsxs(ge,{disabled:!Ir(l==null?void 0:l._type),onClick:u,className:"flex items-center gap-x-4 text-xs",children:[i.jsx(w.CopyIcon,{})," ",a("Copy")]}),c&&i.jsxs(ge,{className:"flex items-center gap-x-4 text-xs",onClick:()=>{s(n)},children:[i.jsx(w.CardStackIcon,{})," ",a("Paste")]})]})},Nx=()=>{const[t]=q(),[,e]=Is(),{t:n}=z.useTranslation(),s=$("flags.copyPaste",!0);return i.jsx(i.Fragment,{children:s&&i.jsxs(ge,{className:"flex items-center gap-x-4 text-xs",onClick:()=>e(t),children:[i.jsx(w.ScissorsIcon,{})," ",n("Cut")]})})},Ex=()=>{const[t]=q(),e=Ns(),n=J(),{t:s}=z.useTranslation();return i.jsxs(ge,{disabled:!Tr(n==null?void 0:n._type),className:"flex items-center gap-x-4 text-xs",onClick:()=>e(t),children:[i.jsx(w.TrashIcon,{})," ",s("Remove")]})},Ax=({node:t})=>{const{t:e}=z.useTranslation();return i.jsxs(ge,{onClick:n=>{n.stopPropagation(),t.edit(),t.deselect()},className:"flex items-center gap-x-4 text-xs",children:[i.jsx(w.Pencil2Icon,{className:"h-4 w-4"})," ",e("Rename")]})},_x=({node:t})=>{const{t:e}=z.useTranslation(),[n]=q(),s=Zr(),o=J(),{hasPermission:r}=Ge(),{librarySite:a}=$("flags",{librarySite:!1}),l=Ye(),c=g.useCallback(()=>{s(n)},[n,s]),u=g.useMemo(()=>d.has(o,"_libBlockId")&&!d.isEmpty(o._libBlockId),[o==null?void 0:o._libBlockId]);return t==="BODY"?i.jsx(Ze,{side:"bottom",className:"border-border text-xs",children:r(be.ADD_BLOCK)&&i.jsxs(i.Fragment,{children:[i.jsxs(ge,{disabled:!1,className:"flex items-center gap-x-4 text-xs",onClick:()=>oe.publish(Y.OPEN_ADD_BLOCK,o),children:[i.jsx(w.PlusIcon,{className:"h-3.5 w-3.5"})," ",e("Add block")]}),r(be.ADD_BLOCK)&&i.jsx(Ii,{isFromBody:!0}),i.jsx(_i,{}),i.jsx(ge,{disabled:!1,onClick:p=>p.preventDefault(),className:"flex items-center gap-x-4 text-xs",children:i.jsx(bc,{children:i.jsxs("div",{className:"flex items-center gap-x-4 text-xs",children:[i.jsx(w.EraserIcon,{})," ",e("Clear canvas")]})})})]})}):i.jsxs(Ze,{side:"bottom",className:"border-border text-xs",children:[r(be.ADD_BLOCK)&&i.jsxs(i.Fragment,{children:[!l&&i.jsxs(ge,{disabled:!rs(o==null?void 0:o._type),className:"flex items-center gap-x-4 text-xs",onClick:()=>oe.publish(Y.OPEN_ADD_BLOCK,o),children:[i.jsx(w.PlusIcon,{className:"h-3.5 w-3.5"})," ",e("Add block")]}),i.jsxs(ge,{disabled:!Ir(o==null?void 0:o._type),className:"flex items-center gap-x-4 text-xs",onClick:c,children:[i.jsx(w.CardStackPlusIcon,{})," ",e("Duplicate")]})]}),i.jsx(Ax,{node:t}),r(be.MOVE_BLOCK)&&i.jsx(Nx,{}),r(be.ADD_BLOCK)&&i.jsx(Ii,{}),u&&a&&i.jsx(Sx,{}),r(be.CREATE_LIBRARY_BLOCK)&&a&&i.jsx(jx,{}),i.jsx(_i,{}),r(be.DELETE_BLOCK)&&i.jsx(Ex,{})]})},yc=({children:t,id:e,node:n})=>{const[,s]=q();return i.jsx(i.Fragment,{children:i.jsxs(gt,{onOpenChange:o=>{o&&s([e])},children:[i.jsx(xt,{children:t}),i.jsx(_x,{node:n})]})})},Ti="h-3 w-3 flex-shrink-0",kc=t=>{const e=K.useRegisteredChaiBlocks(),n=d.get(e,[t.type,"icon"]);return n?g.createElement(n,{className:Ti}):i.jsx(w.BoxIcon,{className:Ti})},Ix=()=>{const[t]=S.useAtom(Zt),[e]=S.useAtom(Rr),[n]=S.useAtom(Pr),[s]=S.useAtom(Lr),[o]=S.useAtom(Gi),[r]=S.useAtom(Ui),[a]=S.useAtom(qi);return{errors:t,isValid:e,hasErrors:n,hasWarnings:s,errorCount:o,warningCount:r,errorsByBlock:a,getBlockErrors:l=>a[l]||[],getErrorsBySeverity:l=>t.filter(c=>c.severity===l),getErrorMessages:()=>t.map(l=>l.message),getErrorMessagesBySeverity:l=>t.filter(c=>c.severity===l).map(c=>c.message),getAllErrorMessages:()=>({errors:t.filter(l=>l.severity==="error").map(l=>l.message),warnings:t.filter(l=>l.severity==="warning").map(l=>l.message)})}},Tx=({node:t})=>{var e,n;return i.jsx("input",{autoFocus:!0,className:me("ml-2 !h-4 w-full rounded-sm border border-border bg-background px-1 text-[11px] leading-tight outline-none",t.isSelected?"text-black dark:text-white":""),type:"text",defaultValue:((e=t.data)==null?void 0:e._name)||((n=t.data)==null?void 0:n._type),onFocus:s=>s.currentTarget.select(),onBlur:s=>t.submit(s.currentTarget.value),onKeyDown:s=>{s.key==="Enter"&&t.submit(s.currentTarget.value)}})},Bx=S.atom(null),lr=t=>{var e;return t!=null&&t._name?t._name:(t==null?void 0:t._type)==="Box"&&(t!=null&&t.tag)&&(t==null?void 0:t.tag)!=="div"?d.startCase(t.tag):((e=t==null?void 0:t._type)==null?void 0:e.split("/").pop())||""},Rx=(t,e)=>t.length>e?t.substring(0,e)+"...":t,Px=g.memo(({node:t,style:e,dragHandle:n})=>{var se,_e;const{t:s}=z.useTranslation(),o=Ke(),[r]=S.useAtom(As);let a=null;const l=t.children&&t.children.length>0,{highlightBlock:c,clearHighlight:u}=et(),p=Ye(),{id:f,data:h,isSelected:m,willReceiveDrop:x,isDragging:b,isEditing:y,handleClick:k}=t,C=Ix(),A=g.useMemo(()=>C.getBlockErrors(f),[C,f]),v=d.get(h,"_show",!0),j=V=>{V.stopPropagation(),v&&t.toggle()},I=V=>{V.isInternal&&(a=V.isOpen,V.isOpen&&V.close())},N=V=>{V.isInternal&&a!==null&&(a?V.open():V.close(),a=null)},[E,_]=S.useAtom(Bx),B=()=>{var V,ve;P(),(V=t.parent)!=null&&V.isSelected||_((ve=t==null?void 0:t.parent)==null?void 0:ve.id)},P=()=>{_(null)},R=V=>{P(),V.stopPropagation(),!t.isOpen&&v&&t.toggle(),k(V)};g.useEffect(()=>{const V=setTimeout(()=>{x&&!t.isOpen&&!b&&v&&t.toggle()},500);return()=>clearTimeout(V)},[x,t,b,v]);const M=(V,ve)=>{var an;const Ue=r.contentDocument||((an=r.contentWindow)==null?void 0:an.document),zt=Ue==null?void 0:Ue.querySelector(`[data-block-id=${V}]`);zt&&zt.setAttribute("data-drop",ve);const Ht=zt.getBoundingClientRect(),ct=r.getBoundingClientRect();!(Ht.top>=ct.top&&Ht.left>=ct.left&&Ht.bottom<=ct.bottom&&Ht.right<=ct.right)&&Ue&&(Ue.documentElement.scrollTop=zt.offsetTop-ct.top)},H=V=>{P();const ve=d.get(t,"parent.id");ve!=="__REACT_ARBORIST_INTERNAL_ROOT__"?oe.publish(Y.OPEN_ADD_BLOCK,{_id:ve,position:V}):oe.publish(Y.OPEN_ADD_BLOCK,{position:V})},{librarySite:G}=$("flags",{librarySite:!1}),fe=g.useMemo(()=>G&&d.has(h,"_libBlockId")&&!d.isEmpty(h._libBlockId),[h,G]),he=g.useMemo(()=>(h==null?void 0:h._type)==="PartialBlock"||(h==null?void 0:h._type)==="GlobalBlock",[h]);return f===U.ROOT_TEMP_KEY?i.jsxs("div",{className:"group relative mt-2 w-full cursor-pointer",children:[i.jsx("br",{}),i.jsx("div",{role:"button",onClick:()=>H(-1),className:"h-1 rounded bg-primary opacity-0 duration-200 group-hover:opacity-100",children:i.jsxs("div",{className:"absolute left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 transform items-center gap-x-1 rounded-full bg-primary px-3 py-1 text-[9px] leading-tight text-white hover:bg-primary",children:[i.jsx(w.PlusIcon,{className:"w-2.4 h-2.5 stroke-[5] text-white"})," ",s("Add block")]})}),i.jsx("br",{})]}):i.jsx("div",{className:me("relative flex h-full w-full items-center",m?"bg-primary/20":"hover:bg-gray-100"),children:i.jsxs("div",{className:"w-full",onMouseEnter:()=>c(f),onMouseLeave:()=>u(),onClick:R,style:e,"data-node-id":f,ref:n,onDragStart:()=>I(t),onDragEnd:()=>N(t),onDragOver:V=>{V.preventDefault(),M(f,"yes")},onDragLeave:V=>{V.preventDefault(),M(f,"no")},onDrop:V=>{V.preventDefault(),M(f,"no")},children:[t.level>0&&i.jsx("div",{className:"pointer-events-none absolute left-0 top-0 h-full",children:Array.from({length:t.level}).map((V,ve)=>i.jsx("div",{className:"absolute top-0 h-full border-l border-black/5 transition-colors group-hover/parent:border-black/30",style:{left:`${ve*14+10}px`}},ve))}),!p&&(t==null?void 0:t.rowIndex)!==null&&(t==null?void 0:t.rowIndex)!==void 0&&(t==null?void 0:t.rowIndex)>0&&(((se=t.parent)==null?void 0:se.isOpen)&&rs(d.get(t,"parent.data._type"))||((_e=t==null?void 0:t.parent)==null?void 0:_e.id)==="__REACT_ARBORIST_INTERNAL_ROOT__")&&i.jsx("div",{className:"group relative ml-5 h-full w-full cursor-pointer",children:i.jsx("div",{onClick:V=>{V.stopPropagation(),H(t.childIndex)},onMouseEnter:B,onMouseLeave:P,className:"absolute -top-0.5 h-0.5 w-[90%] rounded bg-primary/80 opacity-0 delay-200 duration-200 group-hover:opacity-100",children:i.jsx("div",{className:"absolute left-1/2 top-1/2 flex h-4 w-4 -translate-x-1/2 -translate-y-1/2 transform items-center justify-center rounded-full bg-primary/80 p-1 outline outline-2 outline-white hover:bg-primary/80",children:i.jsx(w.PlusIcon,{className:"h-2 w-2 stroke-[2] text-white"})})})}),i.jsx("div",{className:"absolute left-0 right-0 top-0 -z-10 h-full",children:i.jsx("div",{className:me("h-full transition-colors",x&&Qe(h._type,"Icon")?"bg-green-200":"",(t==null?void 0:t.id)===E?"bg-gray-100 dark:bg-gray-900":"")})}),i.jsxs("div",{className:me("group relative flex w-full cursor-pointer items-center justify-between space-x-px p-1 py-0 outline-none",b&&"opacity-20",v?"":"line-through opacity-50",fe&&m&&"text-primary"),children:[i.jsxs("div",{className:"flex items-center",children:[i.jsx("div",{className:`flex h-4 w-4 rotate-0 transform cursor-pointer items-center justify-center transition-transform duration-100 ${t.isOpen?"rotate-90":""}`,children:l&&i.jsx("button",{onClick:j,type:"button",children:i.jsx(w.ChevronRightIcon,{className:"h-3 w-3"})})}),i.jsxs("div",{className:me("leading-1 flex w-full items-center",fe&&"text-orange-600/90",fe&&m&&"text-orange-800",he&&"text-purple-600/90",he&&m&&"text-purple-800"),children:[A.length>0?i.jsx("div",{className:"text-red-500",children:i.jsx(w.ExclamationTriangleIcon,{className:"h-3 w-3"})}):i.jsx(kc,{type:h==null?void 0:h._type}),y?i.jsx(Tx,{node:t}):i.jsx("div",{className:"ml-1.5 flex items-center gap-x-1 truncate text-[13px]",onDoubleClick:V=>{V.stopPropagation(),t.edit(),t.deselect()},children:i.jsx("span",{title:lr(h).length>17?lr(h):"",children:Rx(lr(h),17)})})]})]}),i.jsxs("div",{className:"invisible flex items-center space-x-1.5 pr-px group-hover:visible",children:[rs(h==null?void 0:h._type)&&v?i.jsxs(de,{children:[i.jsx(ue,{onClick:()=>oe.publish(Y.OPEN_ADD_BLOCK,{_id:f}),className:"cursor-pointer rounded bg-transparent p-px hover:bg-primary/10",asChild:!0,children:i.jsx(w.PlusIcon,{className:"h-4 w-4"})}),i.jsx(ae,{className:"isolate z-[9999]",side:"bottom",children:s("Add block inside")})]}):null,i.jsxs(de,{children:[i.jsx(ue,{onClick:V=>{V.stopPropagation(),o([f],{_show:!v}),t.isOpen&&t.toggle()},className:"cursor-pointer rounded bg-transparent p-0.5 hover:bg-primary/10",asChild:!0,children:v?i.jsx(w.EyeClosedIcon,{className:"h-4 w-4"}):i.jsx(w.EyeOpenIcon,{className:"h-4 w-4"})}),i.jsx(ae,{className:"isolate z-[9999] text-xs",side:"bottom",children:s(v?"Hide the block from page":"Show the block on page")})]}),i.jsx(yc,{node:t,id:f,children:i.jsx("div",{className:"cursor-pointer rounded bg-transparent p-px hover:bg-primary/10",children:i.jsx(w.DotsVerticalIcon,{className:"h-3 w-3"})})})]})]})]})})}),vc=(t,e)=>{const n=d.filter(t,{_parent:e});if(n.length===0)return[];const s=[...n];return n.forEach(o=>{s.push(...vc(t,o==null?void 0:o._id))}),s},Lx=()=>{const[t,e]=S.useAtom(ta),{t:n}=z.useTranslation(),[s]=Z(),o=()=>e({isOpen:!1,blockId:null}),r=T.useSaveToLibraryComponent(),a=g.useMemo(()=>{if(!t.blockId)return[];const l=d.find(s,{_id:t.blockId});return l==null||delete l._parent,[l,...vc(s,l==null?void 0:l._id)]},[t.blockId,s]);return i.jsx(Bn,{open:t.isOpen,onOpenChange:l=>!l&&o(),children:i.jsxs(rn,{className:"p-4 sm:max-w-[450px]",children:[i.jsx(Rn,{className:"pb-2",children:i.jsx(on,{children:n("Save to Library")})}),r&&!d.isEmpty(t.blockId)&&i.jsx(r,{blockId:t.blockId,blocks:a,close:o})]})})},be={ADD_BLOCK:"add_block",DELETE_BLOCK:"delete_block",EDIT_BLOCK:"edit_block",MOVE_BLOCK:"move_block",EDIT_THEME:"edit_theme",SAVE_PAGE:"save_page",EDIT_STYLES:"edit_styles",IMPORT_HTML:"import_html",CREATE_LIBRARY_BLOCK:"create_library_block",CREATE_LIBRARY_GROUP:"create_library_group",EDIT_LIBRARY_BLOCK:"edit_library_block",DELETE_LIBRARY_BLOCK:"delete_library_block"};Object.values(be);const Dx=({parentContext:t,setParentContext:e})=>{const{t:n}=z.useTranslation(),{canPaste:s,pasteBlocks:o}=eo(),r=$("flags.copyPaste",!0);return g.useEffect(()=>{s("root")||e(null)},[s("root")]),!t||!s("root")||!r?null:i.jsx("div",{className:"absolute inset-0",children:i.jsxs(gt,{open:!0,onOpenChange:()=>e(null),children:[i.jsx(xt,{className:"hidden"}),i.jsx(Ze,{className:"absolute w-28 p-1 text-xs",style:{top:t.y,left:t.x},children:i.jsxs(ge,{className:"flex items-center gap-x-4 text-xs",onClick:()=>{o("root"),e(null)},children:[i.jsx(w.CardStackIcon,{})," ",n("Paste")]})})]})})},Mx=()=>{const[t]=Z();return(e,n)=>{if(!n)return!!d.first(e.map(a=>{var l;return(l=d.find(t,{_id:a}))==null?void 0:l._type}));const s=d.find(t,{_id:n});if(!s)return!1;const o=d.first(e.map(r=>{var a;return(a=d.find(t,{_id:r}))==null?void 0:a._type}));return o?Qe(s._type,o):!1}},wc=()=>{const[t]=S.useAtom(Vi),[e,n]=q(),[s]=Is(),o=Ke(),[,r]=Ae(),{moveBlocks:a}=Ee(),l=Mx(),c=g.useRef(null),[,u]=S.useAtom(qr),{t:p}=z.useTranslation(),[f,h]=g.useState(null),m=()=>{n([]),r([])},x=g.useMemo(()=>{const N=(_,B)=>_.filter(P=>!B.includes(P._id)).map(P=>({...P,children:P.children?N(P.children,B):[]}));return[...N(t,s),{_type:U.ROOT_TEMP_KEY,_id:U.ROOT_TEMP_KEY,children:[]}]},[t,s]),b=({id:N,name:E,node:_})=>{o([N],{_name:E},_.data._name)},y=({dragIds:N,parentId:E,index:_})=>{l(N,E)&&a(N,E??void 0,_)},k=N=>{if(N.length===0)return;const E=N[0]?N[0].id:"";r([]),n([E])},C=N=>{var B;N.preventDefault(),f&&h(null);const E=N.target,_=E.getAttribute("data-node-id")||((B=E.closest("[data-node-id]"))==null?void 0:B.getAttribute("data-node-id"));_?(r([]),n([_])):(r([]),n([]),h({x:N.clientX,y:N.clientY}))},A=xe.useDebouncedCallback(({parentNode:N,dragNodes:E})=>{var _;return(N==null?void 0:N.data._type)===U.ROOT_TEMP_KEY||!Qe(N==null?void 0:N.data._type,(_=E[0])==null?void 0:_.data._type)},[],300),v=(N,E)=>{if(!N)return!0;const _={isLeaf:!E.isInternal,isClosed:!E.isOpen,isOpen:E.isOpen};try{let B=N;return Object.keys(_).forEach(P=>{const R=new RegExp(`\\b${P}\\b`,"g");B=B.replace(R,String(_[P]))}),new Function(`return ${B}`)()}catch{return console.warn("Invalid condition expression:",N),!1}},j=N=>{if(!c.current)return;const E=c.current,_=E.selectedNodes[0];if(!_)return;n([_.id]),r([]);const B=!_.isInternal,P=!_.isOpen,R=_.isOpen,M=mx.find(H=>H.key===N.key&&(!H.when||v(H.when,_)));if(M)switch(N.preventDefault(),M.command){case"selectNext":bx(E);break;case"selectPrev":yx(E);break;case"selectParent":kx(E,B||P);break;case"close":wx(E,R);break;case"open":vx(E,P);break;case"selectFirst":gx(E);break;case"selectLast":xx(E);break}};g.useEffect(()=>{const N=()=>{c.current&&u(c.current)};N();const E=new MutationObserver(N);return E.observe(document.body,{childList:!0,subtree:!0}),()=>E.disconnect()},[u]);const{hasPermission:I}=Ge();return d.isEmpty(t)?i.jsx("div",{children:i.jsx("div",{className:"mt-10 flex h-full w-full items-center justify-center p-8",children:i.jsxs("div",{className:"flex flex-col items-center space-y-6 text-center",children:[i.jsx("div",{className:"rounded-full bg-muted p-6",children:i.jsx(w.StackIcon,{className:"h-12 w-12 text-muted-foreground"})}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("h3",{className:"text-lg font-semibold text-foreground",children:p("This page is empty")}),i.jsx("p",{className:"max-w-sm text-sm text-muted-foreground",children:p("Get started by adding your first block to begin building your page")})]}),I(be.ADD_BLOCK)&&i.jsxs(T.Button,{onClick:()=>oe.publish(Y.OPEN_ADD_BLOCK),className:"bg-primary shadow-sm hover:bg-primary/90",size:"sm",children:[i.jsx(w.PlusIcon,{className:"h-4 w-4"}),p("Add Block")]})]})})}):i.jsxs(i.Fragment,{children:[i.jsx("div",{className:ce.cn("chai-outline group/parent parent-group flex h-full select-none flex-col space-y-1"),onClick:()=>m(),children:i.jsxs("div",{id:"outline-view ",className:"no-scrollbar h-full overflow-y-auto text-sm",onKeyDown:N=>{c.current&&!c.current.isEditing&&j(N)},children:[i.jsxs("div",{className:"mb-2 flex items-center justify-end gap-x-1 pb-2 text-sm text-muted-foreground",children:[i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:i.jsx(T.Button,{className:"h-fit p-1",onClick:()=>{var N;return(N=c==null?void 0:c.current)==null?void 0:N.openAll()},variant:"ghost",size:"sm",children:i.jsx(w.DoubleArrowDownIcon,{className:"h-2 w-2"})})}),i.jsx(ae,{className:"isolate z-[9999]",children:p("Expand all")})]}),i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:i.jsx(T.Button,{className:"h-fit p-1",onClick:()=>{var N;return(N=c==null?void 0:c.current)==null?void 0:N.closeAll()},variant:"ghost",size:"sm",children:i.jsx(w.DoubleArrowUpIcon,{className:"h-2 w-2"})})}),i.jsx(ae,{className:"isolate z-[9999]",children:p("Collapse all")})]})]}),i.jsx("div",{className:"group relative z-30 ml-5 w-full cursor-pointer",children:i.jsx("div",{onClick:()=>oe.publish(Y.OPEN_ADD_BLOCK,{position:0}),className:"h-1 w-[90%] rounded bg-primary opacity-0 duration-200 group-hover:opacity-100",children:i.jsx("div",{className:"absolute left-[45%] top-1/2 flex h-4 w-4 -translate-x-1/2 -translate-y-1/2 transform items-center justify-center rounded-full bg-primary p-1 outline outline-2 outline-white hover:bg-primary",children:i.jsx(w.PlusIcon,{className:"h-3 w-3 stroke-[3] text-white"})})})}),i.jsx("div",{children:i.jsx("div",{role:"treeitem","aria-level":0,"aria-selected":!0,"aria-expanded":!1,onClick:()=>n([]),className:"flex min-h-[25px] items-center",children:i.jsxs("div",{className:ce.cn("group flex h-[25px] w-full cursor-pointer items-center justify-between space-x-px px-2 py-0 outline-none",e.length===0?"bg-primary/20":""),children:[i.jsxs("div",{className:"leading-1 flex items-center",children:[i.jsx(w.CardStackIcon,{className:"h-3 w-3 flex-shrink-0 rotate-180"}),i.jsx("div",{className:"ml-1.5 flex items-center gap-x-1 truncate text-[13px]",children:"Body"})]}),i.jsx(yc,{node:"BODY",id:"BODY",children:i.jsx("div",{className:"hidden cursor-pointer rounded bg-transparent p-px hover:bg-primary/10 group-hover:block",children:i.jsx(w.DotsVerticalIcon,{className:"h-3 w-3"})})})]})})}),i.jsx(hd.Tree,{ref:c,height:window.innerHeight-160,className:"no-scrollbar !h-full max-w-full !overflow-y-auto !overflow-x-hidden",rowClassName:"flex items-center h-full",selection:e[0]||"",onRename:b,openByDefault:!1,onMove:y,data:[...x],renderCursor:hx,onSelect:k,childrenAccessor:N=>N.children,width:"100%",rowHeight:25,renderDragPreview:()=>null,indent:14,onContextMenu:C,disableDrop:A,idAccessor:"_id",children:Px})]})}),i.jsx(Lx,{}),i.jsx(Dx,{parentContext:f,setParentContext:h})]})},bn=O.forwardRef(({className:t,orientation:e="horizontal",decorative:n=!0,...s},o)=>i.jsx(Fi.Root,{ref:o,decorative:n,orientation:e,className:T.cn("shrink-0 bg-border",e==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...s}));bn.displayName=Fi.Root.displayName;const Cc=O.forwardRef(({className:t,...e},n)=>i.jsxs(cn.Root,{ref:n,className:T.cn("relative flex w-full touch-none select-none items-center",t),...e,children:[i.jsx(cn.Track,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-neutral-300",children:i.jsx(cn.Range,{className:"absolute h-full bg-neutral-900"})}),i.jsx(cn.Thumb,{className:"block h-4 w-4 rounded-full border border-neutral-900 bg-neutral-900 shadow transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-900 disabled:pointer-events-none disabled:opacity-50"})]}));Cc.displayName=cn.Root.displayName;const Ox=({value:t,onChange:e,disabled:n})=>{const[s,o]=g.useState(t),r=xe.useThrottledCallback(e,[t],200,!0);return i.jsx(Cc,{min:0,step:1,max:50,disabled:n,value:[Number(s.replace("px",""))],onValueChange:a=>{o(a[0].toString()+"px"),r(a[0].toString())},className:"flex-1 cursor-pointer"})},$x=({value:t,onChange:e})=>{const n=d.debounce(s=>e(s),200);return i.jsx("div",{className:"relative flex h-6 w-6 cursor-pointer rounded-lg border border-border",style:{backgroundColor:t},children:i.jsx("input",{type:"color",value:t.startsWith("#")?t:"#000000",onChange:s=>{const o=s.target.value;/^#[0-9A-F]{6}$/i.test(o)&&n(o)},className:"absolute inset-0 h-full w-full cursor-pointer rounded-lg border-0 opacity-0"})})},Fx=({label:t,value:e,onChange:n})=>{const s=Nr.useRegisteredFonts(),{t:o}=z.useTranslation();return g.useEffect(()=>{s.some(r=>r.family===e)||n(s[0].family)},[e,n]),i.jsxs("div",{className:"space-y-0.5",children:[i.jsx(mt,{className:"mb-1 block text-xs text-gray-600",children:o(d.startCase(t))}),i.jsxs(Fs,{value:e,onValueChange:n,children:[i.jsx(Fn,{className:"h-8 w-full text-xs text-black",children:i.jsx(Io,{placeholder:o("Select font")})}),i.jsx(zn,{children:s.map(r=>i.jsx(Hn,{value:r.family,children:r.family},r.family))})]})]})},zx=()=>{const t=$("onSaveWebsiteData",async c=>{}),[e]=Ts(),n=g.useRef(!1),s=g.useCallback(async c=>{if(!n.current){n.current=!0;try{await t(c)}finally{n.current=!1}}},[t]),o=g.useCallback(async c=>{await s({type:"THEME",data:c??e})},[s,e]),r=g.useCallback(async c=>{const u=c??$e.get(Qt);await s({type:"DESIGN_TOKENS",data:u})},[s]),a=xe.useDebouncedCallback(o,[o],1e3),l=xe.useDebouncedCallback(r,[r],1e3);return{saveWebsiteData:s,saveTheme:o,saveDesignTokens:r,debouncedSaveTheme:a,debouncedSaveDesignTokens:l}},Hx={fontFamily:{heading:"Poppins",body:"Poppins"},borderRadius:"6px",colors:{background:["#ffffff","#0a0a0a"],foreground:["#0a0a0a","#fafafa"],primary:["#171717","#e5e5e5"],"primary-foreground":["#fafafa","#171717"],secondary:["#f5f5f5","#262626"],"secondary-foreground":["#171717","#fafafa"],muted:["#f5f5f5","#262626"],"muted-foreground":["#737373","#a1a1a1"],accent:["#f5f5f5","#404040"],"accent-foreground":["#171717","#fafafa"],destructive:["#e7000b","#ff6467"],"destructive-foreground":["#ffffff","#fafafa"],border:["#e5e5e5","#282828"],input:["#e5e5e5","#343434"],ring:["#a1a1a1","#737373"],card:["#ffffff","#171717"],"card-foreground":["#0a0a0a","#fafafa"],popover:["#ffffff","#262626"],"popover-foreground":["#0a0a0a","#fafafa"]}},Vx={fontFamily:{heading:"Poppins",body:"Poppins"},borderRadius:"4px",colors:{background:["#ffffff","#000000"],foreground:["#0f1419","#e7e9ea"],primary:["#1e9df1","#1c9cf0"],"primary-foreground":["#ffffff","#ffffff"],secondary:["#0f1419","#f0f3f4"],"secondary-foreground":["#ffffff","#0f1419"],muted:["#e5e5e6","#181818"],"muted-foreground":["#0f1419","#72767a"],accent:["#e3ecf6","#061622"],"accent-foreground":["#1e9df1","#1c9cf0"],destructive:["#f4212e","#f4212e"],"destructive-foreground":["#ffffff","#ffffff"],border:["#e1eaef","#242628"],input:["#f7f9fa","#22303c"],ring:["#1da1f2","#1da1f2"],card:["#f7f8f8","#17181c"],"card-foreground":["#0f1419","#d9d9d9"],popover:["#ffffff","#000000"],"popover-foreground":["#0f1419","#e7e9ea"]}},Wx={fontFamily:{heading:"Geist",body:"Geist"},borderRadius:"4px",colors:{background:["#fdf6e3","#002b36"],foreground:["#073642","#93a1a1"],primary:["#d33682","#d33682"],"primary-foreground":["#ffffff","#ffffff"],secondary:["#2aa198","#2aa198"],"secondary-foreground":["#ffffff","#ffffff"],muted:["#93a1a1","#586e75"],"muted-foreground":["#073642","#93a1a1"],accent:["#cb4b16","#cb4b16"],"accent-foreground":["#ffffff","#ffffff"],destructive:["#dc322f","#dc322f"],"destructive-foreground":["#ffffff","#ffffff"],border:["#839496","#586e75"],input:["#839496","#586e75"],ring:["#d33682","#d33682"],card:["#eee8d5","#073642"],"card-foreground":["#073642","#93a1a1"],popover:["#eee8d5","#073642"],"popover-foreground":["#073642","#93a1a1"]}},Gx={fontFamily:{heading:"Poppins",body:"Poppins"},borderRadius:"6px",colors:{background:["#faf9f5","#262624"],foreground:["#3d3929","#c3c0b6"],primary:["#c96442","#d97757"],"primary-foreground":["#ffffff","#ffffff"],secondary:["#e9e6dc","#faf9f5"],"secondary-foreground":["#535146","#30302e"],muted:["#ede9de","#1b1b19"],"muted-foreground":["#83827d","#b7b5a9"],accent:["#e9e6dc","#1a1915"],"accent-foreground":["#28261b","#f5f4ee"],destructive:["#141413","#ef4444"],"destructive-foreground":["#ffffff","#ffffff"],border:["#dad9d4","#3e3e38"],input:["#b4b2a7","#52514a"],ring:["#c96442","#d97757"],card:["#faf9f5","#262624"],"card-foreground":["#141413","#faf9f5"],popover:["#ffffff","#30302e"],"popover-foreground":["#28261b","#e5e5e2"]}},Ux={fontFamily:{heading:"Inter",body:"Inter"},borderRadius:"6px",colors:{background:["#fff9f5","#2a2024"],foreground:["#3d3436","#f2e9e4"],primary:["#ff7e5f","#ff7e5f"],"primary-foreground":["#ffffff","#ffffff"],secondary:["#ffedea","#463a41"],"secondary-foreground":["#b35340","#f2e9e4"],muted:["#fff0eb","#392f35"],"muted-foreground":["#78716c","#d7c6bc"],accent:["#feb47b","#feb47b"],"accent-foreground":["#3d3436","#2a2024"],destructive:["#e63946","#e63946"],"destructive-foreground":["#ffffff","#ffffff"],border:["#ffe0d6","#463a41"],input:["#ffe0d6","#463a41"],ring:["#ff7e5f","#ff7e5f"],card:["#ffffff","#392f35"],"card-foreground":["#3d3436","#f2e9e4"],popover:["#ffffff","#392f35"],"popover-foreground":["#3d3436","#f2e9e4"]}},qx=g.lazy(()=>Promise.resolve().then(()=>require("./css-import-modal-nAB5FSwn.cjs")).then(t=>({default:t.CssImportModal}))),jc="chai-builder-previous-theme",Kx=[{shadcn_default:Hx},{twitter_theme:Vx},{solarized_theme:Wx},{claude_theme:Gx},{supabase_theme:Ux}],Yx=t=>{if(!(typeof window>"u"))try{localStorage.setItem(jc,JSON.stringify(t))}catch(e){console.warn("Failed to save previous theme to localStorage:",e)}},Jx=()=>{if(!(typeof window>"u"))try{localStorage.removeItem(jc)}catch(t){console.warn("Failed to clear previous theme from localStorage:",t)}},Sc=O.memo(({className:t=""})=>{const[e,n]=In(),[s,o]=O.useState(""),[r,a]=O.useState(!1),l=$("themePresets",{}),{hasPermission:c}=Ge(),{debouncedSaveTheme:u}=zx(),p=$("flags.importTheme",!0),f=$("flags.darkMode",!1),h=Nr.useRegisteredFonts();(!l||l.length===0)&&Kx.map(E=>{l.push(E)});const[m,x]=Ts(),b=Tn(),{t:y}=z.useTranslation(),k=O.useCallback(E=>{const _={...m};Yx(_),x(E),u(),le.toast.success("Theme updated",{action:{label:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(w.ResetIcon,{className:"h-4 w-4"})," Undo"]}),onClick:()=>{x(_),Jx(),le.toast.dismiss()}},closeButton:!0,duration:15e3})},[m,x,u]),C=()=>{const E=l.find(_=>Object.keys(_)[0]===s);if(E){const _=Object.values(E)[0];_&&typeof _=="object"&&"fontFamily"in _&&"borderRadius"in _&&"colors"in _?(k(_),o("")):console.error("Invalid preset structure:",_)}else console.error("Preset not found:",s)},A=E=>{k(E),o("")},v=xe.useDebouncedCallback((E,_)=>{x(()=>({...m,fontFamily:{...m.fontFamily,[E.replace(/font-/g,"")]:_}})),u()},[m,u],200),j=O.useCallback(E=>{x(()=>({...m,borderRadius:`${E}px`})),u()},[m,x,u]),I=xe.useDebouncedCallback((E,_)=>{x(()=>{const B=d.get(m,`colors.${E}`);return e?d.set(B,1,_):d.set(B,0,_),{...m,colors:{...m.colors,[E]:B}}}),u()},[m,u],200),N=E=>i.jsx("div",{className:"grid grid-cols-1",children:Object.entries(E.items).map(([_])=>{const B=d.get(m,`colors.${_}.${e?1:0}`);return B?i.jsxs("div",{id:`theme-${_}`,className:"mt-1 flex items-center gap-x-2",children:[i.jsx($x,{value:B,onChange:P=>I(_,P)}),i.jsx(mt,{className:"text-xs font-normal leading-tight",children:_.split(/(?=[A-Z])/).join(" ").replace(/-/g," ").split(" ").map(P=>P.charAt(0).toUpperCase()+P.slice(1)).join(" ")+(!_.toLowerCase().includes("foreground")&&!_.toLowerCase().includes("border")&&!_.toLowerCase().includes("input")&&!_.toLowerCase().includes("ring")&&!_.toLowerCase().includes("background")?" Background":"")})]},_):null})});return c("edit_theme")?i.jsx("div",{className:"relative w-full",children:i.jsxs("div",{className:ce.cn("no-scrollbar h-full w-full overflow-y-auto",t),children:[l.length>0&&i.jsxs("div",{className:"mx-0 my-2 flex flex-col gap-1 py-2",children:[i.jsxs("div",{className:"flex w-full items-center justify-between",children:[i.jsx(mt,{className:"text-sm",children:y("Presets")}),i.jsx("div",{className:"flex gap-2",children:p&&i.jsxs(T.Button,{className:"px-1",variant:"link",size:"sm",onClick:()=>a(!0),children:[i.jsx(w.UploadIcon,{className:"h-4 w-4"}),y("Import theme")]})})]}),i.jsxs("div",{className:"flex items-center gap-2 px-0",children:[i.jsx("div",{className:"w-[70%]",children:i.jsxs(Fs,{value:s,onValueChange:o,children:[i.jsx(Fn,{className:"h-9 w-full text-sm",children:i.jsx(Io,{placeholder:y("Select preset")})}),i.jsx(zn,{children:Array.isArray(l)&&l.map(E=>{const _=Object.keys(E)[0],B=_.replaceAll("_"," ");return i.jsx(Hn,{value:_,children:d.capitalize(B)},_)})})]})}),i.jsx("div",{className:"w-[25%]",children:i.jsx(T.Button,{className:"w-full text-sm",disabled:!s,onClick:C,children:y("Apply")})})]})]}),i.jsx(bn,{}),i.jsxs("div",{className:ce.cn("my-2 space-y-3",t),children:[h.length>0?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(w.TextIcon,{className:"h-3 w-3 text-gray-600"}),i.jsx("span",{className:"text-xs font-medium text-gray-700",children:y("Typography")})]}),(b==null?void 0:b.fontFamily)&&i.jsx("div",{className:"space-y-2",children:Object.entries(b.fontFamily).map(([E,_])=>i.jsx(Fx,{label:E,value:m.fontFamily[E.replace(/font-/g,"")]||_[Object.keys(_)[0]],onChange:B=>v(E,B)},E))}),i.jsx(bn,{})]}):"",(b==null?void 0:b.borderRadius)&&i.jsxs("div",{className:"space-y-0.5",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(w.CornerTopRightIcon,{className:"h-3 w-3 text-gray-600"}),i.jsx("span",{className:"text-xs font-medium text-gray-700",children:y("Border Radius")})]}),i.jsx(Ps,{variant:"secondary",className:"text-xs",children:m.borderRadius})]}),i.jsx("div",{className:"flex items-center gap-4 py-2",children:i.jsx(Ox,{value:m.borderRadius,onChange:j})})]}),i.jsx(bn,{}),(b==null?void 0:b.colors)&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(w.MixerHorizontalIcon,{className:"h-3 w-3 text-gray-600"}),i.jsx("span",{className:"text-xs font-medium text-gray-700",children:y("Colors")})]}),f&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(w.SunIcon,{className:"h-4 w-4"}),i.jsx(Ln,{checked:e,onCheckedChange:E=>n(E),"aria-label":y("Toggle dark mode"),className:"mx-1"}),i.jsx(w.MoonIcon,{className:"h-4 w-4"})]})]}),i.jsx("div",{className:"space-y-2",children:b.colors.map(E=>i.jsx("div",{children:N(E)},E.group))})]}),i.jsx(g.Suspense,{fallback:i.jsx("div",{children:y("Loading...")}),children:r&&p&&i.jsx(qx,{open:r,onOpenChange:a,onImport:A})})]}),i.jsx("br",{}),i.jsx("br",{}),i.jsx("br",{}),i.jsx("br",{})]})}):i.jsx("div",{className:"relative w-full",children:i.jsx("div",{className:ce.cn("no-scrollbar h-full w-full overflow-y-auto text-center",t),children:i.jsx("div",{className:"mt-10 h-full items-center justify-center gap-2 text-muted-foreground",children:i.jsx("p",{className:"text-sm",children:y("You don't have permission to edit the theme. Please contact your administrator to get access.")})})})})}),Xx="Core",Zx="Import",Qx="Breakpoints",eb="Clear",tb="Cancel",nb="Yes",sb="Preview",rb="Settings",ob="Style",ib="Enter SVG code here",ab="Remove",lb="Choose",cb="Cut",db="Copy",ub="Paste",pb="Delete",fb="classes",hb="Theme",mb="Outline",gb="Copied",xb="Stop",bb="Edit",yb="Tag",kb="Value",vb="URL",wb="Images",Cb="Library",jb="Blocks",Sb="Basic",Nb="Media",Eb="Advanced",Ab="Form",_b="Groups",Ib="Accordions",Tb="Buttons",Bb="Layouts",Rb="FAQ",Pb="Hero",Lb="Features",Db="Footer",Mb="Navbar",Ob="Icons",$b="Testimonials",Fb="Blog",zb="Saved",Hb="Unsaved",Vb="Randomize",Wb="Classes",Gb="All",Ub="Undo",qb="Redo",Kb="Duplicate",Yb="Close",Jb="Selected",Xb="Select",Zb="Attributes",Qb="apply",ey="presets",ty="Orientation",ny="Color",sy="Upload",ry="Apply",oy="Back",iy="Insert",ay="Rename",ly="Partials",cy="Happy",dy="Sad",uy="Retry",py="Canvas is empty",fy="Presets",hy="No",my="Saving",gy={heading_font:"Heading Font",body_font:"Body Font",rounded_corner:"Rounded Corners",primary:"Primary",secondary:"Secondary",background:"Background",text_color:"Text Color",background_dark_mode:"Background (Dark Mode)",text_color_dark_mode:"Text Color (Dark Mode)"},xy={box:"box",tag:"Tag",div:"div",level:"Level",header:"header",footer:"footer",section:"section",article:"article",aside:"aside",main:"main",nav:"navigation",figure:"figure",details:"details",summary:"summary",dialog:"dialog",strike:"strike",caption:"caption",legend:"legend",figcaption:"figure caption",mark:"mark",background_image:"Background Image",label:"Label",default:"default",icon_size:"Icon Size",icon_position:"Icon Position",start:"Start",end:"End",button:"Button",custom_html:"Custom HTML",html_code:"HTML Code",default_snippet:"The HTML snippet goes here...",placeholder:"Enter custom HTML code here",custom_script:"Custom Script",dark_mode:"Dark Mode",divider:"Divider",empty_box:"Empty Box",heading:"Heading",image:"Image",alt:"Alt",width:"Width",height:"Height",video:"Video",span:"Span",content:"Content",icon:"Icon",richtext:"Rich Text",list:"List",list_type:"List Type",listitem:"List Item",link:"Link",list_item:"List Item",none:"None",disc:"Disc",number:"Number",paragraph:"Paragraph",lightbox_link:"Lightbox Link",href:"Link",type:"Type",iframe:"iframe",inline:"inline",ajax:"ajax",autoplay:"Video autoplay",max_width:"Max Width",backdrop_color:"Background Color",gallery_name:"Gallery Name",slot:"Slot",empty_slot:"Empty Slot",text:"Text",video_url:"Video URL",controls:"Show Controls",loop:"Loop",muted:"Muted",checkbox:"Checkbox",required:"Required",checked:"Checked",submit_button:"Submit Button",form:"Form",submit_url:"Submit URL",error_message:"Error Message",success_message:"Success Message",input:"Input",value:"Value",show_label:"Show Label",field_name:"Field Name",radio:"Radio",multiple:"Multiple",options:"Options",select:"Select",multiple_choice:"Multiple Choice",textarea:"Textarea",rows:"Rows"},by="Add",yy="Save",ky="Screen",vy={"Add block":"Add Block","Add Block":"Add Block","Add blocks":"Add blocks","Add inside":"Add inside","Add before":"Add before","Add after":"Add after","Add block inside":"Add block inside","Add field":"Add field","Enter or paste TailwindCSS HTML snippet":"Enter or paste TailwindCSS HTML snippet","Click to add block to page":"Click to add block to page",Core:Xx,"Custom Blocks":"Custom Blocks","UI Library":"UI Library",Import:Zx,"Use HTML snippets from Tailwind CSS component libraries":"Use HTML snippets from Tailwind CSS component libraries","Tailwind HTML snippet":"Tailwind HTML snippet","Enter your code snippet here":"Enter your code snippet here","Import HTML":"Import HTML","Imported HTML Note":"NOTE: Imported html will be added to the currently selected block. If no block is selected, the html will be added to the page.","Dark Mode":"Dark Mode","This page has no blocks. Add a block by clicking the + button":"This page has no blocks. Add a block by clicking the + button","This page is empty":"This page is empty","Please select a block to edit settings or styles":"Please select a block to edit settings or styles","Please select a block to Ask AI":"Please select a block to ask AI","Please select a styling block":"Please select a styling block","Drop your block here":"Drop your block here","Use setting":"Use setting","Mobile (XS)":"Mobile (XS)","Styles set here are applied to all screen unless edited at higher breakpoint":"Styles set here are applied to all screen unless edited at higher breakpoint","Mobile landscape (SM)":"Mobile landscape (SM)","Styles set here are applied at 640px and up unless edited at higher breakpoint":"Styles set here are applied at 640px and up unless edited at higher breakpoint","Tablet (MD)":"Tablet (MD)","Styles set here are applied at 768px and up":"Styles set here are applied at 768px and up","Tablet Landscape (LG)":"Tablet Landscape (LG)","Styles set here are applied at 1024px and up unless edited at higher breakpoint":"Styles set here are applied at 1024px and up unless edited at higher breakpoint","Desktop (XL)":"Desktop (XL)","Styles set here are applied at 1280px and up unless edited at higher breakpoint":"Styles set here are applied at 1280px and up unless edited at higher breakpoint","Large Desktop (2XL)":"Large Desktop (2XL)","Styles set here are applied at 1536px and up":"Styles set here are applied at 1536px and up",Breakpoints:Qx,Clear:eb,"Clear whole canvas?":"Clear whole canvas?","Are you sure you want to clear the whole canvas?":"Are you sure you want to clear the whole canvas?",Cancel:tb,Yes:nb,Preview:sb,Settings:rb,Styling:ob,SVG_code:ib,"Paste SVG_code":"Choose icon or paste SVG code","Enter Key":"Enter Key","Data Provider":"Data Provider","Remove Provider Confirmation":"Are you sure you want to remove <span class='text-blue-500'>{name}</span> provider?","Your data provider will be removed from this page and all added data binding will be not visible on blocks.":"Your data provider will be removed from this page and all added data binding will be not visible on blocks.",Remove:ab,"You have no data providers registered. Please add a data provider to your project.":"You have no data providers registered. Please add a data provider to your project.","Learn more":"Learn more","Add data providers:":"Add data providers:","Select a provider":"Select a provider",Choose:lb,"Page data providers:":"Page data providers:","View Data":"View Data","Mark as Global":"Mark as Global","Note: Global blocks are single instances. Editing global blocks will be reflected on all pages using these blocks.":"Note: Global blocks are single instances. Editing global blocks will be reflected on all pages using these blocks.","Global blocks are indicated with":"Global blocks are indicated with","Global blocks are available under 'Global' category":"Global blocks are available under 'Global' category","Enter global block name":"Enter global block name","Eg: Header, Footer":"Eg: Header, Footer","{length} blocks selected.":"{length} blocks selected.",Cut:cb,Copy:db,Paste:ub,Delete:pb,"Clear Selection":"Clear Selection","This is dev mode. Visit":"This is dev mode. Visit","to see page preview":"to see page preview",classes:fb,Theme:hb,Outline:mb,"Not supported":"Not supported","Please use Chrome, Firefox or Safari":"Please use Chrome, Firefox or Safari","Download Complete":"Download complete",Copied:gb,"Enter Classes":"Add classes or design tokens (space-separated)","Ask AI":"Ask AI","Edit with AI":"Edit with AI","Generating... Please wait...":"Generating... Please wait...","Saving... Please wait...":"Saving... Please wait...","Deleting... Please wait...":"Deleting... Please wait...",Stop:xb,"E.g.: This page is about an AI assistant app called Chai Studio. It allows users to create beautiful webpages and edit content with AI":"E.g.: This page is about an AI assistant app called Chai Studio. It allows users to create beautiful webpages and edit content with AI.","Ask AI to edit styles":"Ask AI to edit styles","Ask AI to edit content":"Ask AI to edit content","AI Context":"AI Context","Select Block for AI":"Select a block to edit with AI","Select Block to Edit":"Please select a block to edit",Edit:bb,"Describe this page. E.g.: This page is about...":"Describe this page. E.g.: This page is about...",Tag:yb,Value:kb,"Background Image":"Background Image","Enter image URL":"Enter image URL","Enter URL":"Enter URL",URL:vb,"Replace image":"Replace image","Choose image":"Choose image",Images:wb,Library:Cb,Blocks:jb,Basic:Sb,Media:Nb,Advanced:Eb,Form:Ab,"Choose Icon or SVG":"Choose an icon or enter SVG",Groups:_b,"UI Libraries":"UI Libraries",Accordions:Ib,Buttons:Tb,Layouts:Bb,"Choose Library":"Choose library","No Library Found":"No library found.",FAQ:Rb,Hero:Pb,Features:Lb,Footer:Db,Navbar:Mb,Icons:Ob,Testimonials:$b,Blog:Fb,"Remove context":"Remove context","Yes, Delete":"Yes, Delete","AI Context Updated":"AI Context Updated","You can now ask AI to edit your content.":"You can now ask AI to edit your content.",Saved:zb,Unsaved:Hb,"Saving...":"Saving...","Improve writing":"Improve writing","Replace placeholder content":"Replace placeholder content","Discard current placeholder content and replace with meaningful relevant content.":"Discard current placeholder content and replace with meaningful relevant content.","Fix grammar":"Fix grammar","Fix grammar in all text elements. Ensuring the text is grammatically correct and free of errors.":"Fix grammar in all text elements. Ensuring the text is grammatically correct and free of errors.","Make longer":"Make longer","Make all text elements longer.":"Make all text elements longer.","Make shorter":"Make shorter","Make all text elements shorter.":"Make all text elements shorter.","Add emojis":"Add emojis","Add emojis to text elements if relevant.":"Add emojis to text elements if relevant.",Randomize:Vb,"Randomize all text elements.":"Randomize all text elements.","Edit Block":"Edit Block","AI Assistant":"AI Assistant","Generate with AI":"Generate with AI","Theme Config":{"Heading Font":"Heading Font","Body Font":"Body Font","Rounded Corner":"Rounded Corners",Primary:"Primary",Secondary:"Secondary",Background:"Background","Text Color":"Text Color","Background Dark Mode":"Background (Dark Mode)","Text Color Dark Mode":"Text Color (Dark Mode)","Reset styles":"Reset styles"},"Copy classes to clipboard":"Copy classes to clipboard","Classes copied to clipboard":"Classes copied to clipboard",Classes:Wb,All:Gb,"Enter classes separated by space":"Add classes (space-separated)","Enter classes separated by space or design tokens":"Add classes or design tokens (space-separated)","Show hidden blocks":"Show hidden blocks","Expand all":"Expand all","Collapse all":"Collapse all","Choose library":"Choose library","Close Preview":"Close Preview",Error:"Error","Failed to copy template":"Failed to copy template","Total tokens used":"Total tokens used","Updated AI Context":"Updated AI Context","You can now Ask AI to edit your content":"You can now Ask AI to edit your content","Tell about this page eg this page is about":"Tell about this page eg this page is about..","Delete Context":"Delete Context","Keyboard shortcuts":"Keyboard shortcuts",Undo:Ub,Redo:qb,Duplicate:Kb,"Deselect blocks":"Deselect blocks","Delete block":"Delete block","Save page":"Save page","Scripts will be only executed in preview and live mode.":"Scripts will be only executed in preview and live mode.","HTML Code Editor |":"HTML Code Editor |",Close:Yb,"Coming soon":"Coming soon",Selected:Jb,Select:Xb,"Choose Builder Layout":"Choose Builder Layout","Single side panel":"Single side panel","Suitable for smaller screens. Bigger canvas size.":"Suitable for smaller screens. Bigger canvas size.","Dual side panel":"Dual side panel","Suitable for larger screens. Smaller canvas size.":"Suitable for larger screens. Smaller canvas size.","Dual side panel advanced":"Dual side panel advanced","Suitable for heavy styling & block editing. Setting are always visible.":"Suitable for heavy styling & block editing. Setting are always visible.","Block Settings":"Block Settings","Visibility settings":"Visibility settings","Show on canvas":"Show on canvas",Attributes:Zb,"Apply Presets":"Apply Presets",apply:Qb,presets:ey,"Global presets":"Global presets",Orientation:ty,Color:ny,"Please select an image":"Please select an image","click to upload":"click to upload","SVG, PNG, JPG or GIF (Max. 2mb)":"SVG, PNG, JPG or GIF (Max. 2mb)","Uploading...":"Uploading...",Upload:sy,"Something went wrong":"Something went wrong","Fetching...":"Fetching...","No images found":"No images found","It looks like you haven't uploaded any images yet. Start by clicking the upload button above.":"It looks like you haven't uploaded any images yet. Start by clicking the upload button above.","Open Code Editor":"Open Code Editor","Clear search":"Clear search","No results found for":"No results found for","Search {{pageTypeName}}":"Search {{pageTypeName}}","Goto Page":"Goto Page","Open URL":"Open URL","Compose Email":"Compose Email","Call Phone":"Call Phone","Scroll to element":"Scroll to element","#ElementID":"#ElementID","Enter details":"Enter details","Open in new tab":"Open in new tab",Apply:ry,Back:oy,Insert:iy,Rename:ay,"Unlink from library":"Unlink from library","Save to Library":"Save to Library","No blocks found in this group":"No blocks found in this group","No blocks found matching":"No blocks found matching","No matching blocks found":"No matching blocks found","Search blocks...":"Search blocks...",Partials:ly,Happy:cy,Sad:dy,"Importing...":"Importing...","Failed to load the UI library. Try again":"Failed to load the UI library. Try again",Retry:uy,"Oops! Something went wrong.":"Oops! Something went wrong.","Please try again.":"Please try again.","No option found.":"No option found.","Clipboard not supported":"Clipboard not supported","Are you sure you want to clear the page?":"Are you sure you want to clear the page?",canvas_empty:py,Presets:fy,"Reset style":"Reset style","Reset styles":"Reset styles","Clear styles":"Clear styles","Open code editor":"Open code editor","Style element":"Style element","Repeater Data":"Repeater Data","Toggle Data Binding":"Toggle Data Binding",No:hy,Saving:my,"Screen sizes":"Screen sizes","Theme Settings":"Theme Settings","Import CSS Theme":"Import CSS Theme","Import theme":"Import theme","Import Theme":"Import Theme","CSS Variables":"CSS Variables","You don't have permission to edit settings or styles":"You don't have permission to edit settings or styles","Please contact your administrator to get access":"Please contact your administrator to get access","flex.heading":"Flex Child","flex.basis":"Basis","flex.order":"Order","flex.flex":"Flex","flex.grow":"Grow","flex.shrink":"Shrink","grid.heading":"Grid Child","grid.col_span":"Col Span","grid.col_start":"Col Start","grid.col_end":"Col End","grid.row_span":"Row Span","grid.row_start":"Row Start","grid.row_end":"Row End","grid.order":"Order","layout.heading":"Layout","layout.width":"Width","layout.height":"Height","layout.margin":"Margin","layout.margin_all":"All","layout.margin_lr":"Left-Right","layout.margin_tb":"Top-Bottom","layout.margin_top":"Top","layout.margin_right":"Right","layout.margin_bottom":"Bottom","layout.margin_left":"Left","layout.padding":"Padding","layout.padding_all":"All","layout.padding_lr":"Left-Right","layout.padding_tb":"Top-Bottom","layout.padding_top":"Top","layout.padding_right":"Right","layout.padding_bottom":"Bottom","layout.padding_left":"Left","layout.space_bt":"Space Bt.","layout.space_lr":"Left-Right","layout.space_tb":"Top-Bottom","size.heading":"Size","size.min_width_height":"Min width & height","size.min_width":"Min Width","size.min_height":"Min Height","size.max_width_height":"Max width & height","size.max_width":"Max Width","size.max_height":"Max Height","size.object_options_aspect_ratio":"Object options & aspect ratio","size.aspect":"Aspect","size.fit":"Fit","size.position":"Position","display.heading":"Display","display.display":"Display","display.flex_options":"Flex options","display.flex_direction":"Direction","display.flex_wrap":"Wrap","display.justify_content":"Justify","display.align_content":"Content","display.align_items":"Items","display.gap":"Gap","display.gap_all":"All","display.gap_lr":"Left-Right","display.gap_tb":"Top-Bottom","display.grid_options":"Grid options","display.grid_columns":"Columns","display.grid_rows":"Rows","display.grid_auto_flow":"Auto Flow","display.grid_auto_cols":"Auto Cols","display.grid_auto_rows":"Auto Rows","display.visibility_opacity":"Visibility & Opacity","display.visibility":"Visibility","display.opacity":"Opacity","position.heading":"Position","position.position":"Position","position.options":"Position options","position.direction":"Direction","position.top":"Top","position.right":"Right","position.bottom":"Bottom","position.left":"Left","position.inset":"Inset","position.all":"All","position.lr":"Left Right","position.tb":"Top Bottom","position.z_index":"Z-Index","position.float_clear":"Float & Clear","position.float":"Float","position.clear":"Clear","position.overflow_overscroll":"Overflow & Overscroll","position.overflow":"Overflow","position.overscroll":"Overscroll","typography.heading":"Typography","typography.font":"Font","typography.size":"Size","typography.height":"Height","typography.weight":"Weight","typography.color":"Color","typography.alignments":"Alignments","typography.align":"Align","typography.valign":"V. Align","typography.spacing_decoration_more":"Spacing, decoration & more","typography.spacing":"Spacing","typography.decoration":"Decoration","typography.thickness":"Thickness","typography.transform":"Transform","typography.whitespace_breaks":"White space & breaks","typography.whitespace":"Whitespace","typography.wordbreak":"Wordbreak","background.heading":"Background","background.bgcolor":"Bg. Color","background.position_size_more":"Position, Size & more","background.attachment":"Attachment","background.clipping":"Clipping","background.origin":"Origin","background.position":"Position","background.repeat":"Repeat","background.size":"Size","background.gradient":"Gradient","background.gradient_colors":"Gradient colors","background.from_color":"From","background.via_color":"Via","background.to_color":"To","border.heading":"Border & Outline","border.width":"Width","border.all":"All","border.lr":"Left Right","border.tb":"Top bottom","border.top":"Top","border.right":"Right","border.bottom":"Bottom","border.left":"Left","border.corners":"Corners","border.top_left":"Top Left","border.top_right":"Top right","border.bottom_right":"Bottom right","border.bottom_left":"Bottom left","border.color":"Color","border.style":"Style","border.divide_options":"Divide options","border.divide_color":"Color","border.divide_style":"Style","border.outline_styling":"Outline styling","border.outline_width":"Width","border.outline_offset":"Offset","border.outline_style":"Style","border.ring_options":"Ring options","border.ring_width":"Width","border.ring_color":"Color","border.ring_offset_width":"Offset","border.ring_offset_color":"Off. color","effect.heading":"Effect & Animation","effect.shadow":"Shadow","effect.color":"Color","effect.cursor":"Cursor","effect.blend_cursor":"Blend & Cursor","effect.mix_blend":"Mix Blend","effect.bg_blend":"Bg. Blend","effect.transform":"Transform","effect.origin":"Origin","effect.scale":"Scale","effect.all":"All","effect.lr":"Left-Right","effect.tb":"Top-Bottom","effect.skew":"Skew","effect.translate":"Translate","effect.rotate":"Rotate","effect.animation":"Animation","effect.transition":"Transition","effect.easing":"Easing","effect.duration":"Duration","effect.delay":"Delay","classes.heading":"Classes",theme_config:gy,web_blocks:xy,"Export Code":"Export Code","Exporting {{count}} blocks":"Exporting {{count}} blocks","Exporting all blocks":"Exporting all blocks","Export code copied!":"Export code copied!","Failed to copy export code":"Failed to copy export code","Export code downloaded successfully!":"Export code downloaded successfully!","Failed to generate export HTML":"Failed to generate export HTML","Enter value":"Enter value","Attribute keys cannot start with @":"Attribute keys cannot start with @","Enter key":"Enter key",Add:by,Save:yy,Screen:ky};ft.use(z.initReactI18next).init({resources:{en:{translation:vy}},lng:"en",fallbackLng:"en",interpolation:{escapeValue:!1}});function wy(t,e,n){n.push(d.find(t,{_id:e}));const s=d.filter(t,{_parent:e});for(const o of s)n.push(...Nc(o._id,t));return n}const Nc=(t,e)=>{let n=[];return n=d.flattenDeep([...n,...wy(e,t,n)]),n},Cy=(t,e,n)=>d.compact(t.map(s=>{const o=["_id","_type","_parent"],r=d.pick(s,o),a=K.getRegisteredChaiBlock(s._type),l={},c=d.get(a,"aiProps",[]);for(const u in s)if(!o.includes(u)&&c.includes(u)){const p=d.get(s,`${u}-${e}`,""),f=d.get(s,u,"");l[u]=d.isString(p)&&p.trim()||f,n&&(l[u]=f)}return d.isEmpty(l)?!1:(d.has(r,"_parent")&&d.isEmpty(r._parent)&&delete r._parent,{...r,...l})})),jy=(t,e,n)=>!e||n!=="content"?t:`${t}. Generate content in ${d.get(Pt,e,e)} language.`,Sy=S.atom(!1),Ec=()=>{const[t,e]=S.useAtom(Sy),[n,s]=g.useState(null),o=$("askAiCallBack",d.noop),r=Qi(),a=Md(),[l]=Z(),{selectedLang:c,fallbackLang:u}=Te(),p=c.length?c:u,f=(h,m)=>{const x=d.cloneDeep(m.find(b=>b._id===h));for(const b in x){const y=x[b];if(typeof y=="string"&&d.startsWith(y,U.STYLES_KEY)){const{baseClasses:k,classes:C}=ne.getSplitChaiClasses(y);x[b]=d.compact(d.flattenDeep([k,C])).join(" ")}else b!=="_id"&&delete x[b]}return x};return{askAi:g.useCallback(async(h,m,x,b)=>{if(o){e(!0),s(null);try{const y=c===u?"":c,k=x.toLowerCase().includes("translate the content"),C=h==="content"?Cy(d.cloneDeep(Nc(m,l)),c,k):[f(m,l)],A=await o(h,jy(x,p,h),C,y);if(A===void 0)return;const{blocks:v,error:j}=A;if(j){s(j);return}if(h==="styles"){const I=v.map(N=>{for(const E in N)E!=="_id"&&(N[E]=`${U.STYLES_KEY},${N[E]}`);return N});a(I)}else r(v);b&&b(A)}catch(y){s(y)}finally{e(!1),b&&b()}}},[o,e,c,u,l,p,a,r]),loading:t,error:n}};function Ny({onClick:t}){const{loading:e}=Ec(),{t:n}=z.useTranslation(),{selectedLang:s,fallbackLang:o}=Te(),a=[...[{name:n("Improve writing"),icon:w.Pencil2Icon,prompt:n("Improving writing in all text elements. Replacing placeholder content with meaningful relevant content.")},{name:n("Replace placeholder content"),icon:w.LoopIcon,prompt:n("Discard current placeholder content and replace with meaningful relevant content.")},{name:n("Fix grammar"),icon:w.CheckIcon,prompt:n("Fix grammar in all text elements. Ensuring the text is grammatically correct and free of errors.")},{name:n("Make longer"),icon:w.ArrowUpIcon,prompt:n("Make all text elements longer.")},{name:n("Make shorter"),icon:w.ArrowDownIcon,prompt:n("Make all text elements shorter.")},{name:n("Add emojis"),icon:w.FaceIcon,prompt:n("Add emojis to text elements if relevant.")},{name:n("Randomize"),icon:w.ShuffleIcon,prompt:n("Randomize all text elements.")}]];return s&&s!==o&&a.splice(0,0,{name:n("Translate to {{lang}}",{lang:d.get(Pt,s,s)}),icon:w.ChatBubbleIcon,prompt:n("Translate the content to {{lang}}. Maintain same tone, style and length.",{lang:d.get(Pt,s,s)})}),i.jsx("div",{className:e?"pointer-events-none opacity-50":"",children:i.jsx("ul",{className:"space-y-1",children:a.map(({name:l,icon:c,subMenus:u,prompt:p})=>u?i.jsxs(Ls,{children:[i.jsx(Ds,{asChild:!0,children:i.jsxs("li",{className:"flex cursor-pointer items-center space-x-2 rounded p-1 pl-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-800",children:[i.jsx(c,{className:"h-4 w-4"}),i.jsx("span",{children:l})]},l)}),i.jsx(Pn,{side:"right",children:i.jsx("ul",{children:i.jsx("li",{children:n("Happy")})})})]}):i.jsxs("li",{onClick:()=>t(p),className:"flex cursor-pointer items-center space-x-2 rounded p-1 text-xs hover:bg-primary/10 hover:text-primary dark:hover:bg-gray-800",children:[i.jsx(c,{className:"h-3.5 w-3.5"}),i.jsx("span",{children:n(l)})]},l))})})}const Ac=({blockId:t})=>{const{t:e}=z.useTranslation(),{askAi:n,loading:s,error:o}=Ec(),[r,a]=g.useState(""),l=g.useRef(null),c=g.useRef(null),u=J();g.useEffect(()=>{var f;(f=l.current)==null||f.focus()},[]);const p=()=>{o||a("")};return i.jsx("div",{className:"",children:t?i.jsxs("div",{className:"",children:[i.jsx("label",{className:"text-xs font-medium text-gray-500",children:e("Selected block")}),u&&i.jsxs("div",{className:"flex items-center gap-x-1 rounded border border-primary/20 bg-primary/10 p-1.5 text-xs text-primary",children:[i.jsx(kc,{type:u._type})," ",i.jsx("p",{className:"truncate whitespace-nowrap leading-none",children:u._name||u._type})]}),i.jsx("br",{}),i.jsx("label",{className:"text-xs font-medium text-gray-500",children:e("Quick actions")}),i.jsx("div",{className:"rounded border p-2 text-sm",children:i.jsx(Ny,{onClick:f=>{c.current&&clearTimeout(c.current),n("content",t,f,p)}})}),i.jsx("br",{}),i.jsx("label",{className:"text-xs font-medium text-gray-500",children:e("Ask AI")}),i.jsxs("div",{className:"rounded border p-2 text-xs focus-within:border-gray-300",children:[i.jsx($n,{ref:l,value:r,onChange:f=>a(f.target.value),placeholder:e("Ask AI to edit content"),className:"w-full resize-none border-none p-0 text-xs shadow-none outline-none",rows:3,onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),c.current&&clearTimeout(c.current),n("content",t,r,p))}}),i.jsxs("div",{className:"flex items-center justify-end",children:[s&&i.jsx(T.Button,{variant:"destructive",onClick:()=>stop(),className:"hidden h-4 w-4",size:"icon",children:i.jsx(w.StopIcon,{className:"h-4 w-4"})}),i.jsx(T.Button,{onClick:()=>{c.current&&clearTimeout(c.current),n("content",t,r,p)},variant:"default",className:"h-7 w-7",disabled:s||r.trim().length<1,size:"icon",children:s?i.jsx(w.ReloadIcon,{className:"h-4 w-4 animate-spin"}):i.jsx(w.ArrowTopRightIcon,{className:"h-4 w-4"})})]})]}),i.jsx("div",{className:"max-w-full pt-2",children:o&&i.jsx("p",{className:"break-words rounded border border-red-500 bg-red-100 p-1 text-xs text-red-500",children:o.message})})]}):i.jsx("div",{className:"p-4 text-center",children:i.jsxs("div",{className:"space-y-4 rounded-xl p-4 text-muted-foreground",children:[i.jsx(Er,{className:"mx-auto h-7 w-7 text-muted-foreground"}),i.jsx("h1",{children:e("Please select a block to Ask AI")})]})})})},_c=()=>{const[t]=q();return i.jsx("div",{className:"no-scrollbar mt-2 flex-1 overflow-y-auto",children:i.jsx(Ac,{blockId:d.first(t)})})};function Ey(){const[t,e]=In();return i.jsxs("div",{className:"flex items-center",children:[t?i.jsx(w.MoonIcon,{className:"size-4 shrink-0"}):i.jsx(w.SunIcon,{className:"size-4 shrink-0"}),i.jsx(Ln,{id:"dark-mode-switch",checked:t,onCheckedChange:()=>{e(!t)},className:`${t?"bg-violet-600":"bg-violet-300"} relative ml-2 inline-flex h-[20px] w-[32px] shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75`,children:i.jsx("span",{"aria-hidden":"true",className:`${t?"translate-x-5":"translate-x-0"} pointer-events-none -mt-px inline-block h-[18px] w-[20px] transform rounded-full bg-white shadow-lg ring-0 transition duration-200 ease-in-out`})})]})}const Ay=()=>{const{hasUndo:t,hasRedo:e,undo:n,redo:s}=En();return i.jsxs("div",{className:"flex items-center",children:[i.jsx(T.Button,{disabled:!t(),size:"sm",onClick:n,className:"rounded-full",variant:"ghost",children:i.jsx(w.ResetIcon,{})}),i.jsx(T.Button,{disabled:!e(),onClick:s,size:"sm",className:"rounded-full",variant:"ghost",children:i.jsx(w.ResetIcon,{className:"rotate-180 scale-y-[-1] transform"})})]})},Ic=pe.Root,_y=pe.Portal,Tc=O.forwardRef(({className:t,...e},n)=>i.jsx(pe.Overlay,{className:T.cn("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...e,ref:n}));Tc.displayName=pe.Overlay.displayName;const Iy=Sr.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),Mo=O.forwardRef(({side:t="right",className:e,children:n,...s},o)=>i.jsxs(_y,{children:[i.jsx(Tc,{}),i.jsxs(pe.Content,{ref:o,className:T.cn(Iy({side:t}),e),...s,children:[i.jsxs(pe.Close,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[i.jsx(w.Cross1Icon,{className:"h-4 w-4"}),i.jsx("span",{className:"sr-only",children:"Close"})]}),n]})]}));Mo.displayName=pe.Content.displayName;const Oo=({className:t,...e})=>i.jsx("div",{className:T.cn("flex flex-col space-y-2 text-center sm:text-left",t),...e});Oo.displayName="SheetHeader";const $o=O.forwardRef(({className:t,...e},n)=>i.jsx(pe.Title,{ref:n,className:T.cn("text-lg font-semibold text-foreground",t),...e}));$o.displayName=pe.Title.displayName;const Bc=O.forwardRef(({className:t,...e},n)=>i.jsx(pe.Description,{ref:n,className:T.cn("text-sm text-muted-foreground",t),...e}));Bc.displayName=pe.Description.displayName;const Rc=()=>{const{t}=z.useTranslation(),[e,n]=g.useState(null),[s,o]=g.useState(-1),[r,a]=g.useState(!1),l=Ye(),[,c]=_s();return qt(Y.OPEN_ADD_BLOCK,u=>{l?c("add-block"):(n(u?u._id:null),o((u==null?void 0:u.position)??-1),a(!0))}),qt(Y.CLOSE_ADD_BLOCK,()=>{n(null),o(-1),a(!1)}),i.jsx(Bo,{open:r,onOpenChange:()=>r?a(!1):"",children:i.jsxs(zs,{className:"max-w-5xl overflow-hidden border-border",children:[i.jsxs(Hs,{className:"flex flex-row items-center justify-between",children:[i.jsx(Vs,{className:"text-foreground",children:t("Add blocks")}),i.jsx("button",{onClick:()=>a(!1),className:"text-gray-500 hover:text-gray-600 dark:text-gray-400 dark:hover:text-gray-300",children:i.jsx(w.Cross2Icon,{className:"h-6 w-6"})})]}),i.jsx("div",{className:"no-scrollbar h-[500px] max-h-full overflow-hidden",children:i.jsx(To,{parentId:e??"",position:s,showHeading:!1})})]})})},Ty=g.memo(function({preloadedAttributes:e=[],onAttributesChange:n}){const[s,o]=g.useState([]),[r,a]=g.useState(""),[l,c]=g.useState(""),[u,p]=g.useState(null),[f,h]=g.useState(""),m=g.useRef(null),x=g.useRef(null),b=Dt(),{t:y}=z.useTranslation();g.useEffect(()=>{o(e)},[e]);const k=()=>{if(r.startsWith("@")){h(y("Attribute keys cannot start with @"));return}if(r){const N=[...s,{key:r,value:l}];n==null||n(N),o(s),a(""),c(""),h("")}},C=N=>{const E=s.filter((_,B)=>B!==N);n==null||n(E),o(E)},A=N=>{p(N),a(s[N].key),c(s[N].value)},v=()=>{if(r.startsWith("@")){h(y("Attribute keys cannot start with @"));return}if(u!==null&&r){const N=[...s];N[u]={key:r,value:l},n==null||n(N),o(N),p(null),a(""),c(""),h("")}},j=N=>{N.key==="Enter"&&!N.shiftKey&&(N.preventDefault(),u!==null?v():k())},I=g.useCallback(N=>{const E=P=>/[.,!?;:]/.test(P),_=(P,R,M)=>{let H="",G="";const fe=R>0?P[R-1]:"",he=R<P.length?P[R]:"";return R>0&&(fe==="."||!E(fe)&&fe!==" ")&&(H=" "),R<P.length&&!E(he)&&he!==" "&&(G=" "),{text:H+M+G,prefixLength:H.length,suffixLength:G.length}},B=x.current;if(B){const P=B.selectionStart||0,R=B.value||"",M=B.selectionEnd||P;if(M>P){const se=`{{${N}}}`,{text:_e}=_(R,P,se),V=R.slice(0,P)+_e+R.slice(M);c(V);return}const G=`{{${N}}}`,{text:fe}=_(R,P,G),he=R.slice(0,P)+fe+R.slice(P);c(he)}},[]);return i.jsxs("div",{className:"flex max-h-full flex-1 flex-col",children:[i.jsxs("form",{onSubmit:N=>{N.preventDefault(),u!==null?v():k()},className:"space-y-3",children:[i.jsxs("div",{className:"flex flex-col gap-y-1",children:[i.jsxs("div",{className:"w-full",children:[i.jsx(mt,{htmlFor:"attrKey",className:"text-[11px] font-normal leading-tight text-slate-600",children:y("Key")}),i.jsx(T.Input,{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",id:"attrKey",ref:m,value:r,onChange:N=>a(N.target.value),placeholder:y("Enter key"),className:"py-0 text-xs font-normal leading-tight placeholder:text-slate-400"})]}),i.jsxs("div",{className:"w-full",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(mt,{htmlFor:"attrValue",className:"text-[11px] font-normal text-slate-600",children:y("Value")}),!d.isEmpty(b)&&i.jsx(vo,{data:b,onSelect:I})]}),i.jsx($n,{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",id:"attrValue",ref:x,value:l,onChange:N=>c(N.target.value),onKeyDown:j,placeholder:y("Enter value"),className:"text-xs font-normal leading-tight placeholder:text-slate-400"})]})]}),i.jsx("div",{className:"flex justify-end",children:i.jsx(T.Button,{type:"submit",disabled:!r.length,variant:"default",size:"sm",className:"h-8 w-24 text-xs",children:y(u!==null?"Save":"Add")})}),f&&i.jsx("p",{className:"text-xs text-red-500",children:f})]}),i.jsx("div",{className:"space-y-1 py-4",children:s.map((N,E)=>i.jsxs("div",{className:"flex items-center justify-between rounded border p-2 text-sm",children:[i.jsxs("div",{className:"flex flex-col text-xs leading-tight",children:[i.jsx("span",{className:"truncate text-[12px] font-light text-muted-foreground",children:N.key}),i.jsx("span",{className:"max-w-[200px] text-wrap font-normal",children:N.value.toString()})]}),i.jsxs("div",{className:"flex-shrink-0 text-slate-400",children:[i.jsx(T.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>A(E),children:i.jsx(w.Pencil2Icon,{className:"h-3 w-3"})}),i.jsx(T.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>C(E),children:i.jsx(w.Cross1Icon,{className:"h-3 w-3"})})]})]},E))})]})}),Pc=O.memo(()=>{const t=J(),[e,n]=g.useState([]),[s]=Ae(),o=Ke(),r=`${d.get(s,"0.prop")}_attrs`;O.useEffect(()=>{const l=d.map(d.get(t,r),(c,u)=>({key:u,value:c}));d.isEmpty(l)?n([]):n(l)},[d.get(t,r)]);const a=O.useCallback((l=[])=>{if(!t)return;const c={};d.forEach(l,u=>{d.isEmpty(u.key)||d.set(c,u.key,u.value)}),o([d.get(t,"_id")],{[r]:c})},[t,o,r]);return i.jsx("div",{className:"flex-col gap-y-2",children:i.jsx("div",{className:"flex flex-col",children:i.jsx("div",{children:i.jsx(Ty,{preloadedAttributes:e,onAttributesChange:a})})})})}),Vt=()=>null,Bi=()=>{const{resetAll:t}=ql(),e=J(),[n]=Ae(),s=cg(),{t:o}=z.useTranslation();return!e||d.isEmpty(n)?null:i.jsxs(gt,{children:[i.jsx(xt,{asChild:!0,children:i.jsx("div",{className:"inline-flex rounded-sm p-0.5 hover:bg-gray-300",onClick:r=>r.stopPropagation(),children:i.jsx(w.DotsVerticalIcon,{className:"h-3 w-3"})})}),i.jsxs(Ze,{side:"bottom",className:"border-border text-xs",children:[i.jsxs(ge,{className:"flex items-center gap-1 text-xs",onClick:()=>{t()},children:[i.jsx(w.ResetIcon,{className:"h-3 w-3"}),o("Reset styles")]}),i.jsxs(ge,{className:"text-xs",onClick:()=>{e&&s(e,!0)},children:[i.jsx(w.Cross2Icon,{className:"h-3 w-3"}),o("Clear styles")]})]})]})};function Ri(){const{t}=z.useTranslation(),[e,n]=g.useState(!0),[s]=Ae();return d.isEmpty(s)?null:i.jsxs(i.Fragment,{children:[i.jsxs("div",{onClick:()=>n(!e),className:"flex cursor-pointer items-center justify-between border-t border-border py-3 text-xs font-medium hover:underline",children:[i.jsx("span",{children:t("Attributes")}),i.jsx("span",{children:i.jsx(w.ChevronDownIcon,{className:"h-4 w-4 text-gray-500 "+(e?"rotate-180":"")})})]}),e&&i.jsx(Pc,{})]})}const By=({partialBlockId:t})=>{const e=$("gotoPage",d.noop),{saveState:n}=en(),{selectedLang:s,fallbackLang:o}=Te(),r=g.useCallback(a=>{if(a.stopPropagation(),n!=="SAVED"){le.toast.error("You have unsaved changes. Please save the page first.");return}e({pageId:t,lang:s||o})},[n,e,t,s,o]);return i.jsx(i.Fragment,{children:i.jsx("div",{className:"hidden",children:i.jsx("div",{onDoubleClick:r,className:"h-full w-full items-center justify-center",children:i.jsx("p",{className:"rounded-md bg-white px-2 py-1 text-xs",children:"Partial block. Double click to edit."})})})})},Ry=()=>{const t=J(),{t:e}=z.useTranslation(),n=$("onError",d.noop),{hasPermission:s}=Ge();let o=!s(be.EDIT_BLOCK);const r=!s(be.EDIT_STYLES),[a,l]=La();if(t&&t._type==="PartialBlock")return i.jsx(By,{partialBlockId:t.partialBlockId});if(!t)return i.jsx("div",{className:"p-4 text-center",children:i.jsxs("div",{className:"space-y-4 rounded-xl p-4 text-muted-foreground",children:[i.jsx(w.MixerHorizontalIcon,{className:"mx-auto text-3xl"}),i.jsx("h1",{children:e("Please select a block to edit settings or styles")})]})});if(o&&r)return i.jsx("div",{className:"p-4 text-center",children:i.jsxs("div",{className:"space-y-4 rounded-xl p-4 text-muted-foreground",children:[i.jsx(w.MixerHorizontalIcon,{className:"mx-auto text-3xl"}),i.jsx("h1",{children:e("You don't have permission to edit settings or styles")}),i.jsx("p",{children:e("Please contact your administrator to get access")})]})});if(r)return i.jsx(Nt.ErrorBoundary,{fallback:i.jsx(xn,{}),onError:n,children:i.jsxs("div",{className:"no-scrollbar h-full max-h-min w-full overflow-y-auto",children:[i.jsx(yr,{},t==null?void 0:t._id),i.jsx("br",{}),i.jsx("br",{})]})});if(o)return i.jsx(Nt.ErrorBoundary,{fallback:i.jsx(xn,{}),onError:n,children:i.jsxs("div",{className:"no-scrollbar h-full max-h-min w-full overflow-y-auto overflow-x-hidden",children:[i.jsx("div",{className:"flex w-full items-center justify-end",children:i.jsx(Bi,{})}),i.jsx(jr,{}),i.jsx(Ri,{}),i.jsx("br",{}),i.jsx("br",{}),i.jsx("br",{})]})});const u=p=>{(p==="settings"||p==="styles")&&l(p)};return i.jsx(Nt.ErrorBoundary,{fallback:i.jsx(xn,{}),onError:n,children:i.jsxs($s,{value:a,onValueChange:u,className:"flex flex-1 flex-col",children:[i.jsx("div",{className:"flex items-center justify-between",children:i.jsxs(On,{className:"grid h-auto w-full grid-cols-2 p-1 py-1",children:[i.jsx(ze,{value:"settings",className:"text-xs",children:e("Settings")}),i.jsx(ze,{value:"styles",className:"text-xs",children:i.jsxs("div",{className:"flex w-full items-center justify-between",children:[i.jsx("span",{className:"w-[90%] text-center",children:e("Styling")}),i.jsx("span",{className:"w-[10%]",children:i.jsx(Bi,{})})]})})]})}),i.jsxs(at,{value:"settings",className:"no-scrollbar h-full max-h-min overflow-y-auto",children:[i.jsx(yr,{},t==null?void 0:t._id),i.jsx("br",{}),i.jsx("br",{})]}),i.jsxs(at,{value:"styles",className:"no-scrollbar h-full max-h-min max-w-full overflow-y-auto overflow-x-hidden",children:[i.jsx(jr,{}),i.jsx(Ri,{}),i.jsx("br",{}),i.jsx("br",{}),i.jsx("br",{})]})]})})},pt=280,Py=({isActive:t,show:e})=>i.jsx(T.Button,{variant:t?"default":"ghost",size:"icon",onClick:e,children:i.jsx(Oi.ListTree,{className:"h-5 w-5"})}),Ly=({isActive:t,show:e})=>Ye()&&i.jsx(T.Button,{variant:t?"default":"ghost",size:"icon",onClick:e,children:i.jsx(Oi.PlusIcon,{className:"h-5 w-5"})}),Dy=({isActive:t,show:e})=>$("flags.ai",!1)?i.jsx(T.Button,{variant:t?"default":"ghost",size:"icon",onClick:e,children:i.jsx(Er,{})}):null;T.registerChaiSidebarPanel("add-block",{button:Ly,label:"Add Blocks",position:"top",isInternal:!0,width:pt,panel:()=>i.jsx(To,{showHeading:!1,fromSidebar:!0,parentId:void 0,position:-1})});T.registerChaiSidebarPanel("chai-chat-panel",{button:Dy,label:"Ask AI",position:"top",isInternal:!0,width:pt,panel:()=>i.jsx("div",{className:"",children:i.jsx(_c,{})})});T.registerChaiSidebarPanel("outline",{button:Py,label:"Outline",position:"top",isInternal:!0,width:pt,panel:()=>i.jsx("div",{className:"-mt-8",children:i.jsx(wc,{})})});const My=()=>{const t=T.useTopBarComponent(),[e,n]=_s(),s=g.useRef("outline"),[o,r]=g.useState(pt),[a,l]=Pa(),[,c]=La(),u=T.useChaiSidebarPanels("top"),p=T.useChaiSidebarPanels("bottom"),f=d.reverse([...p??[]]),h=g.useCallback(E=>{E.preventDefault()},[]),m=g.useMemo(()=>[u].flat(),[u]),x=g.useCallback(E=>{console.log("handleMenuItemClick",E,e),n(e===E?null:E)},[e,n]),{t:b}=z.useTranslation(),y=g.useMemo(()=>[...u,...p],[u,p]),k=$("htmlDir","ltr"),C=d.find(y,{id:e})??d.first(y),A=d.get(C,"width",pt);g.useEffect(()=>{if(e!==null){const E=d.find(y,{id:e});E&&d.get(E,"view","standard")==="standard"&&(s.current=e,r(d.get(E,"width",pt)))}},[e,y]);const v=g.useMemo(()=>{if(e===null)return 0;const E=d.find(y,{id:e});return d.get(E,"view","standard")==="standard"?A:o},[e,A,o,y]),j=g.useCallback(()=>{n(s.current)},[n,e]),I=g.useCallback(()=>{n("outline")},[n]);g.useEffect(()=>{e!==null&&!d.find(y,{id:e})&&n("outline")},[e,y]);const N=g.useCallback(E=>{x(E)},[x]);return i.jsx("div",{dir:k,className:"h-screen max-h-full w-screen overflow-x-hidden bg-background text-foreground",children:i.jsxs(xs,{children:[i.jsxs("div",{onContextMenu:h,className:"flex h-full max-h-full flex-col",children:[i.jsx("div",{className:"flex h-[50px] w-screen items-center border-b border-gray-200 bg-gray-50 text-gray-900",children:i.jsx(g.Suspense,{children:i.jsx(t,{})})}),i.jsxs("main",{className:"relative flex h-[calc(100vh-56px)] max-w-full flex-1 flex-row",children:[i.jsxs("div",{id:"sidebar",className:"flex w-12 flex-col items-center justify-between border-r border-gray-200 bg-gray-50 py-2 text-gray-900",children:[i.jsx("div",{className:"flex flex-col gap-y-1",children:m.map((E,_)=>i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:g.createElement(d.get(E,"button",Vt),{position:"top",panelId:E.id,isActive:e===E.id,show:()=>N(E.id)})}),i.jsx(ae,{side:"right",children:i.jsx("p",{children:b(E.label)})})]},"button-top-"+_))}),i.jsx("div",{className:"flex flex-col space-y-1"}),i.jsx("div",{className:"flex flex-col",children:f==null?void 0:f.map((E,_)=>i.jsxs(de,{children:[i.jsx(ue,{asChild:!0,children:g.createElement(d.get(E,"button",Vt),{position:"bottom",panelId:E.id,isActive:e===E.id,show:()=>N(E.id)})}),i.jsx(ae,{side:"right",children:i.jsx("p",{children:b(E.label)})})]},"button-bottom-"+_))})]}),i.jsx(Vn.motion.div,{id:"left-panel",className:"h-full max-h-full border-r border-gray-200 bg-white text-gray-900",initial:{width:v},animate:{width:v},transition:{duration:.3,ease:"easeInOut"},children:e!==null&&d.get(C,"view","standard")==="standard"&&i.jsxs("div",{className:"no-scrollbar flex h-full flex-col overflow-hidden px-3 py-2",children:[d.get(C,"label","")!==""?i.jsx("div",{className:`absolute top-2 flex h-10 items-center space-x-1 py-2 text-base font-bold ${d.get(C,"isInternal",!1)?"":"w-64"}`,children:i.jsx("span",{children:b(d.get(C,"label",""))})}):null,i.jsx("div",{className:"no-scrollbar h-full max-h-full overflow-y-auto "+(d.get(C,"label","")!==""?"pt-10":""),children:i.jsx(g.Suspense,{fallback:i.jsx("div",{children:"Loading..."}),children:g.createElement(d.get(C,"panel",Vt),{})})})]})}),i.jsx("div",{id:"canvas-container",className:"flex h-full max-h-full flex-1 flex-col bg-slate-800/20",children:i.jsx(g.Suspense,{children:i.jsx(Dl,{})})}),i.jsx(Vn.motion.div,{id:"right-panel",className:"h-full max-h-full border-l border-gray-200 bg-white text-gray-900",initial:{width:e==="ai"?0:pt},animate:{width:e==="ai"?0:pt},transition:{duration:.3,ease:"easeInOut"},children:i.jsx("div",{className:"no-scrollbar overflow h-full max-h-full overflow-hidden",children:i.jsxs("div",{className:"flex h-full max-h-full flex-col overflow-hidden p-3",children:[i.jsx("h2",{className:"-mt-1 flex items-center space-x-1 text-base font-bold",children:i.jsx("div",{className:"flex grow items-center gap-2",children:i.jsx("div",{className:"flex w-full items-center justify-between gap-2",children:a==="ai"?i.jsx(i.Fragment,{children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(w.LightningBoltIcon,{className:"rtl:ml-2"})," ",b("AI Assistant")]})}):a==="design-tokens"?i.jsxs("div",{className:"mb-1 flex w-full items-center justify-between gap-2",children:[i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(nc,{className:"h-4 w-4 text-gray-600"}),b("Design Tokens")]}),i.jsx(T.Button,{onClick:()=>{c("styles"),l("block")},variant:"ghost",size:"icon",className:"text-xs",children:i.jsx(w.Cross1Icon,{className:"h-4 w-4 rtl:ml-2"})})]}):a==="theme"?i.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(w.MixerHorizontalIcon,{className:"h-4 w-4 text-gray-600"}),b("Theme Settings")]}),i.jsx(T.Button,{onClick:()=>l("block"),variant:"ghost",size:"icon",className:"text-xs",children:i.jsx(w.Cross1Icon,{className:"h-4 w-4 rtl:ml-2"})})]}):null})})}),i.jsx("div",{className:"flex h-full max-h-full w-full",children:i.jsx(g.Suspense,{fallback:i.jsx("div",{children:"Loading..."}),children:a==="ai"?i.jsx(_c,{}):a==="theme"?i.jsx(Sc,{}):i.jsx(Ry,{})})})]})})})]})]}),i.jsx(Rc,{}),e!==null&&d.get(C,"view")==="drawer"&&i.jsx(Ic,{open:!0,onOpenChange:()=>j(),children:i.jsxs(Mo,{side:"left",className:"flex flex-col gap-0 p-0 sm:max-w-full",style:{width:`${A}px`},children:[i.jsx(Oo,{className:"border-b border-border px-2 py-2.5",children:i.jsxs($o,{className:"flex items-center gap-2",children:[i.jsx("span",{className:"inline-block",children:d.get(C,"icon",null)}),i.jsx("span",{children:b(d.get(C,"label",""))})]})}),i.jsx("div",{className:"h-full max-h-full overflow-y-auto p-4",children:i.jsx(g.Suspense,{fallback:i.jsx("div",{children:"Loading..."}),children:g.createElement(d.get(C,"panel",Vt),{close:I})})})]})})," ",e!==null&&d.get(C,"view")==="modal"&&i.jsx(Bn,{open:!0,onOpenChange:()=>j(),children:i.jsxs(rn,{className:"gap-0 p-0",style:{maxWidth:`${A}px`},children:[i.jsx(Rn,{className:"border-b border-border px-2 py-3.5",children:i.jsxs(on,{className:"flex items-center gap-2",children:[i.jsx("span",{className:"inline-block",children:d.get(C,"icon",null)}),i.jsx("span",{children:b(d.get(C,"label",""))})]})}),i.jsx("div",{className:"max-h-[70vh] overflow-y-auto p-4",children:i.jsx(g.Suspense,{fallback:i.jsx("div",{children:"Loading..."}),children:g.createElement(d.get(C,"panel",Vt),{close:I})})})]})}),e!==null&&d.get(C,"view")==="overlay"&&i.jsx(Vn.motion.div,{className:"absolute bottom-0 left-12 right-0 top-0 z-50",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.3},children:i.jsx("div",{className:"h-full w-full",children:i.jsxs(Vn.motion.div,{className:"flex h-full w-full flex-col bg-background",initial:{y:-20,opacity:0},animate:{y:0,opacity:1},exit:{y:20,opacity:0},transition:{duration:.3,delay:.1},children:[i.jsxs("div",{className:"flex h-[50px] items-center justify-between border-b border-border p-4",children:[i.jsxs("div",{className:"-ml-2 flex items-center gap-2 text-lg font-bold",children:[i.jsx("span",{className:"rtl:ml-2 rtl:inline-block",children:d.get(C,"icon",null)}),i.jsx("span",{children:b(d.get(C,"label",""))})]}),i.jsx(T.Button,{onClick:()=>j(),variant:"ghost",size:"icon",className:"",children:i.jsx(w.Cross1Icon,{className:"h-5 w-5"})})]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:i.jsx(g.Suspense,{fallback:i.jsx("div",{children:"Loading..."}),children:g.createElement(d.get(C,"panel",Vt),{close:I})})})]})})})]})})},Oy=S.atom(!1),$y=()=>{const[t,e]=S.useAtom(Oy);return[t,e]},Fy=()=>{const[t,e]=$y(),{t:n}=z.useTranslation(),s=$("previewComponent",null);return t?i.jsxs("div",{className:ce.cn("fixed inset-0 z-[999] bg-background",t?"block":"hidden"),children:[i.jsxs(T.Button,{size:"sm",className:"absolute right-0 top-0 m-4 space-x-2",onClick:()=>e(!1),children:[i.jsx(w.EyeClosedIcon,{}),i.jsx("span",{children:n("Close Preview")})]}),i.jsx("div",{children:s?i.jsx(g.Suspense,{fallback:i.jsx(Jt,{className:"h-96 w-full"}),children:g.createElement(s)}):null})]}):null},zy=t=>{},Hy=["data-block-index","draggable","data-drop","data-style-id","data-block-parent","data-style-prop","data-highlighted"],Vy=["Box","Button","Checkbox","Divider","EmptyBox","Form","FormButton","Heading","Image","Input","Label","LineBreak","Link","List","ListItem","Paragraph","Radio","RichText","Select","Span","Text","TextArea","Video"],Lc=t=>t.type==="element"&&["script","style","link"].includes(t.tagName||"")||t.type==="comment"?null:t.type==="text"?t:t.type==="element"&&t.attributes&&t.attributes.find(e=>e.key==="id"&&e.value==="add-block-bottom")?null:(t.type==="element"&&t.attributes&&(t.attributes=t.attributes.filter(e=>!Hy.includes(e.key))),t.children&&(t.children=t.children.map(Lc).filter(e=>e!==null)),t),ts=(t,e,n={})=>{var r,a,l,c,u,p;if(t.type!=="element"||!t.attributes)return t;if(t.tagName==="span"&&t.attributes.find(h=>h.key==="role"&&h.value==="link")){t.tagName="a",t.attributes=t.attributes.filter(x=>x.key!=="role");const h=(r=t.attributes.find(x=>x.key==="data-block-id"))==null?void 0:r.value,m=e==null?void 0:e.find(x=>(x==null?void 0:x._id)===h);if(m!=null&&m.link&&((l=(a=m==null?void 0:m.link)==null?void 0:a.href)==null?void 0:l.length)>0){const x=(c=m==null?void 0:m.link)==null?void 0:c.href,b=(u=m==null?void 0:m.link)==null?void 0:u.target;t.attributes.push({key:"href",value:x}),typeof b=="string"&&b.length>0&&t.attributes.push({key:"target",value:b})}}const s=t.attributes.find(f=>f.key==="data-block-type"),o=t.attributes.find(f=>f.key==="data-block-id");if(s){const f=s.value;if(Vy.includes(f)||(p=n==null?void 0:n.additionalCoreBlocks)!=null&&p.includes(f))t.attributes=t.attributes.filter(h=>h.key!=="data-block-type"),t.children&&(t.children=t.children.map(h=>ts(h,e,n)));else{const h=`chai-${d.kebabCase(f)}`;t.tagName=h,t.attributes=[],t.attributes.push({key:"chai-type",value:f});const m=K.getRegisteredChaiBlock(f),x=e.find(b=>b._id===(o==null?void 0:o.value));if(x&&t.attributes.push(...Object.entries(x).filter(([b])=>!["_id","_type","_parent","_index","_name"].includes(b)).map(([b,y])=>({key:b,value:typeof y=="string"?y:JSON.stringify(y)}))),m&&(m!=null&&m.description)&&t.attributes.push({key:"about-this-component",value:m.description}),m){if(m.canMove){const b=typeof m.canMove=="function"?m.canMove():m.canMove;t.attributes.push({key:"can-move",value:String(b)})}if(m.canDelete){const b=typeof m.canDelete=="function"?m.canDelete():m.canDelete;t.attributes.push({key:"can-delete",value:String(b)})}}f==="Icon"&&(t.attributes=t.attributes.filter(b=>b.key!=="icon")),m&&m.canAcceptBlock?t.children&&(t.children=t.children.map(b=>ts(b,e,n))):t.children=[]}}else t.children&&(t.children=t.children.map(f=>ts(f,e,n)));return o&&t.attributes.push({key:"bid",value:o.value}),t.attributes=t.attributes.filter(f=>f.key!=="data-block-type"&&f.key!=="data-block-id"),t},Dc=()=>{const[t]=tn();return g.useCallback(e=>{var u,p;if(!t)return"";const n=e!=null&&e.blockId?`[data-block-id="${e.blockId}"]`:"#canvas",s=(p=(u=t.contentDocument)==null?void 0:u.querySelector(n))==null?void 0:p[n==="#canvas"?"innerHTML":"outerHTML"];if(!s)return"";const r=Vo.parse(s).map(Lc).filter(f=>f!==null),a=Td(),l=r.map(f=>ts(f,a,e));let c=Vo.stringify(l);return c=c.replace(/#styles:,/g,"#styles:"),c.replace(/\s+/g," ").trim()},[t])};function Pi(t){const e={class:"className",for:"htmlFor",tabindex:"tabIndex",readonly:"readOnly",maxlength:"maxLength",minlength:"minLength",autocomplete:"autoComplete",autofocus:"autoFocus",autoplay:"autoPlay",formaction:"formAction",formenctype:"formEncType",formmethod:"formMethod",formnovalidate:"formNoValidate",formtarget:"formTarget",novalidate:"noValidate",crossorigin:"crossOrigin",datetime:"dateTime",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",allowfullscreen:"allowFullScreen"};if(e[t.toLowerCase()])return e[t.toLowerCase()];const n={"accent-height":"accentHeight","alignment-baseline":"alignmentBaseline","arabic-form":"arabicForm","baseline-shift":"baselineShift","cap-height":"capHeight","clip-path":"clipPath","clip-rule":"clipRule","color-interpolation":"colorInterpolation","color-interpolation-filters":"colorInterpolationFilters","color-profile":"colorProfile","color-rendering":"colorRendering","dominant-baseline":"dominantBaseline","enable-background":"enableBackground","fill-opacity":"fillOpacity","fill-rule":"fillRule","flood-color":"floodColor","flood-opacity":"floodOpacity","font-family":"fontFamily","font-size":"fontSize","font-size-adjust":"fontSizeAdjust","font-stretch":"fontStretch","font-style":"fontStyle","font-variant":"fontVariant","font-weight":"fontWeight","glyph-name":"glyphName","glyph-orientation-horizontal":"glyphOrientationHorizontal","glyph-orientation-vertical":"glyphOrientationVertical","horiz-adv-x":"horizAdvX","horiz-origin-x":"horizOriginX","image-rendering":"imageRendering","letter-spacing":"letterSpacing","lighting-color":"lightingColor","marker-end":"markerEnd","marker-mid":"markerMid","marker-start":"markerStart","overline-position":"overlinePosition","overline-thickness":"overlineThickness","paint-order":"paintOrder","panose-1":"panose1","pointer-events":"pointerEvents","rendering-intent":"renderingIntent","shape-rendering":"shapeRendering","stop-color":"stopColor","stop-opacity":"stopOpacity","strikethrough-position":"strikethroughPosition","strikethrough-thickness":"strikethroughThickness","stroke-dasharray":"strokeDasharray","stroke-dashoffset":"strokeDashoffset","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","stroke-miterlimit":"strokeMiterlimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-anchor":"textAnchor","text-decoration":"textDecoration","text-rendering":"textRendering","underline-position":"underlinePosition","underline-thickness":"underlineThickness","unicode-bidi":"unicodeBidi","unicode-range":"unicodeRange","units-per-em":"unitsPerEm","v-alphabetic":"vAlphabetic","v-hanging":"vHanging","v-ideographic":"vIdeographic","v-mathematical":"vMathematical","vector-effect":"vectorEffect","vert-adv-y":"vertAdvY","vert-origin-x":"vertOriginX","vert-origin-y":"vertOriginY","word-spacing":"wordSpacing","writing-mode":"writingMode","x-height":"xHeight"};return n[t]?n[t]:t}function ns(t,e=0){var u;if(Array.isArray(t)){if(t.length===0)return"";if(t.length===1)return ns(t[0],e);const p=" ".repeat(e);let f=`${p}<>
136
+ `;for(const h of t)f+=ns(h,e+1);return f+=`${p}</>
137
+ `,f}const n=" ".repeat(e);if(t.nodeType===Node.TEXT_NODE){const p=(u=t.textContent)==null?void 0:u.trim();return p?`${n}${p}
138
+ `:""}if(t.nodeType!==Node.ELEMENT_NODE)return"";const s=t.tagName.toLowerCase();if(["img","br","hr","input","meta","link","area","base","col","embed","source","track","wbr"].includes(s)){const p=[];for(const h of t.attributes)if(h.name.startsWith("on")&&h.name!=="on"){const m=h.name.toLowerCase().replace(/on(\w)/,(x,b)=>"on"+b.toUpperCase());p.push(`${m}={${h.value}}`)}else if(h.name==="style"&&h.value){const m=h.value.split(";").reduce((x,b)=>{const[y,k]=b.split(":").map(C=>C.trim());if(y&&k){const C=y.replace(/-([a-z])/g,A=>A[1].toUpperCase());x[C]=k.replace(/['"]/g,"")}return x},{});p.push(`style={${JSON.stringify(m)}}`)}else{const m=Pi(h.name);p.push(`${m}="${h.value}"`)}const f=p.length>0?` ${p.join(" ")}`:"";return`${n}<${s}${f} />
139
+ `}let r=`${n}<${s}`;const a=[];for(const p of t.attributes)if(p.name.startsWith("on")&&p.name!=="on"){const f=p.name.toLowerCase().replace(/on(\w)/,(h,m)=>"on"+m.toUpperCase());a.push(`${f}={${p.value}}`)}else if(p.name==="style"&&p.value){const f=p.value.split(";").reduce((h,m)=>{const[x,b]=m.split(":").map(y=>y.trim());if(x&&b){const y=x.replace(/-([a-z])/g,k=>k[1].toUpperCase());h[y]=b.replace(/['"]/g,"")}return h},{});a.push(`style={${JSON.stringify(f)}}`)}else{const f=Pi(p.name);a.push(`${f}="${p.value}"`)}a.length>0&&(r+=" "+a.join(" "));const l=Array.from(t.childNodes);if(!l.some(p=>{var f;return p.nodeType===Node.TEXT_NODE?(f=p.textContent)==null?void 0:f.trim():!0}))r+=` />
140
+ `;else{r+=`>
141
+ `;for(const p of l)r+=ns(p,e+1);r+=`${n}</${s}>
142
+ `}return r}function Wy(t){if(!t)return"";let e="",n=0;const s=" ";return t=t.replace(/>\s+</g,"><").trim(),t.split(/(<\/?[^>]+>)/g).filter(r=>r.trim()).forEach(r=>{r.match(/^<\/\w/)?(n=Math.max(0,n-1),e+=s.repeat(n)+r+`
143
+ `):r.match(/\/>$/)?e+=s.repeat(n)+r+`
144
+ `:r.match(/^<\w[^>]*[^\/]>$/)?(e+=s.repeat(n)+r+`
145
+ `,n++):r.trim()&&(e+=s.repeat(n)+r.trim()+`
146
+ `)}),e.trim()}const Gy=g.lazy(()=>Promise.resolve().then(()=>require("./code-display-i7jb2kmw.cjs")));async function Uy(t){try{const e=document.createElement("div");e.innerHTML=t;const n=Array.from(e.children);return{jsx:ns(n.length===1?n[0]:n),html:e.innerHTML}}catch{return{html:t,jsx:t}}}const qy=async({selectedBlock:t,html:e,isTypeScript:n=!1})=>{let s=(t==null?void 0:t._name)||(t==null?void 0:t._type)||"Component";s=d.camelCase(s).replace(/^./,u=>u.toUpperCase());const o=" ";let{jsx:r,html:a}=await Uy(e);return r=r==null?void 0:r.split(`
147
+ `).join(`
148
+ ${o}${o}`),r=`${n?`import React from 'react';
149
+
150
+ `:""}export const ${s}${n?": React.FC":""} = () => {
151
+ ${o}return (
152
+ ${o}${o}${r==null?void 0:r.trimEnd()}
153
+ ${o})
154
+ }`,{jsx:r,html:Wy(a),componentName:s}},Ky=({tab:t})=>{var k;const{t:e}=z.useTranslation(),[n,s]=g.useState({html:"",jsx:""}),o=J(),r=Dc(),[a,l]=g.useState(""),[c,u]=g.useState(!1),p=()=>{switch(t){case"js":return`${a}.jsx`;case"ts":return`${a}.tsx`;case"html":return`${a}.html`;case"tailwind":return"tailwind.config.js"}},f=()=>{switch(t){case"js":case"ts":return"javascript";case"html":return"HTML";case"tailwind":return"JSON"}},h=g.useCallback(async()=>{const C=o??{_name:"Body",_type:"Body"};try{u(!1);let A=r(o?{blockId:o._id,additionalCoreBlocks:["Icon"]}:{additionalCoreBlocks:["Icon"]});A=A.replace(/\s*bid=["'][^"']*["']/g,"");const v=t==="ts",{jsx:j,html:I,componentName:N}=await qy({selectedBlock:C,html:A,isTypeScript:v});s({html:I||"",jsx:j}),l(N),u(!0)}catch{const A="<div>Export failed. Close the modal and try again.</div>";s({html:A,jsx:A}),le.toast.error(e("Failed to generate export HTML"))}},[e,t,o,r]);g.useEffect(()=>{h()},[h,t]);const m=g.useCallback(async C=>{try{navigator.clipboard.writeText(C),le.toast.success(e("Export code copied!"))}catch{le.toast.error(e("Failed to copy export code"))}},[e]),x=C=>{const A=new Blob([C],{type:"text/jsx"}),v=URL.createObjectURL(A),j=document.createElement("a");j.href=v,j.download=p()??"",document.body.appendChild(j),j.click(),URL.revokeObjectURL(v),document.body.removeChild(j),le.toast.success(e("Export code downloaded successfully!"))},b=i.jsxs("span",{children:["Download ",i.jsx("span",{className:"font-mono text-xs font-light text-gray-300",children:p()})]}),y=g.useMemo(()=>{const C={extend:wd.shadcnTheme()},A=JSON.stringify(C,null,2);return`{
155
+ // Your tailwind config ...
156
+
157
+ "theme": ${A==null?void 0:A.split(`
158
+ `).join(`
159
+ `)},
160
+ }`},[]);return((k=n==null?void 0:n.jsx)==null?void 0:k.length)>0&&c?i.jsx(Gy,{onCopy:m,code:t==="tailwind"?y:t==="html"?n.html:n.jsx,language:f()||"",downloadText:b,onDownload:x},t):i.jsx("div",{className:"flex h-[620px] w-full items-center justify-center p-4",children:"Generating code..."})},Mc=()=>{const{t}=z.useTranslation(),[e,n]=g.useState(!1),{setMode:s}=Da(),[o,r]=g.useState("js"),a=g.useCallback(async()=>{r("js"),s("view"),n(!0)},[r,s,n]);qt(Y.OPEN_EXPORT_CODE,a);const l=async()=>{s("edit"),await new Promise(c=>setTimeout(c,300)),n(!1)};return i.jsx(Bn,{open:e,onOpenChange:l,children:i.jsxs(rn,{className:"max-w-5xl overflow-hidden border-border",children:[i.jsxs(Rn,{className:"flex flex-row items-center justify-between",children:[i.jsx(on,{className:"text-foreground",children:t("Export Code")}),i.jsx($s,{defaultValue:"js",onValueChange:r,children:i.jsxs(On,{children:[i.jsx(ze,{value:"js",children:"Javascript"}),i.jsx(ze,{value:"ts",children:"Typescript"}),i.jsx(ze,{value:"html",children:"HTML"}),i.jsx(ze,{value:"tailwind",children:"Tailwind config"})]})}),i.jsx("div",{})]}),i.jsx("div",{className:"flex min-h-[400px] flex-col gap-4",children:e&&i.jsx(g.Suspense,{fallback:i.jsx("div",{className:"flex h-[400px] items-center justify-center text-muted-foreground",children:"Loading code editor..."}),children:i.jsx(Nt.ErrorBoundary,{fallback:i.jsx("div",{children:"Something went wrong"}),children:i.jsx(Ky,{tab:o})})})})]})})},Yy=()=>{const t=$("smallScreenComponent",null);return i.jsx("section",{className:"fixed inset-0 z-[99999] flex h-screen w-screen items-center justify-center bg-white xl:hidden",children:t?g.createElement(t):i.jsx("div",{className:"flex h-full w-full items-center justify-center bg-[linear-gradient(to_right,#f3f4f6_1px,transparent_1px),linear-gradient(to_bottom,#f3f4f6_1px,transparent_1px)] bg-[size:10px_10px] py-12 sm:py-16 lg:py-20",children:i.jsx("div",{className:"mx-auto max-w-7xl px-4 sm:px-6 lg:px-8",children:i.jsxs("div",{className:"mx-auto max-w-md space-y-6 text-center",children:[i.jsxs("div",{className:"space-y-4",children:[i.jsx("h2",{className:"text-5xl font-bold tracking-tight text-gray-900",children:"Screen too small"}),i.jsxs("p",{className:"mx-auto max-w-sm text-sm leading-7 text-gray-600",children:["Please view this page on greater than ",i.jsx("strong",{className:"font-medium",children:"1280px"})," screen width for the best experience."]})]}),i.jsx("div",{className:"pt-4",children:i.jsxs("div",{className:"inline-flex items-center rounded-full bg-gray-100 px-4 py-2 text-sm text-gray-700",children:[i.jsx("svg",{className:"mr-2 h-5 w-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Minimum width: 1280px"]})})]})})})})},Jy=()=>{const{clear:t}=En(),[,e]=q(),{clearHighlight:n}=et(),[,s]=Ae(),[,o]=S.useAtom(da),{reset:r}=Vr(),{setSaveState:a}=en(),[,l]=ea(),[,c]=S.useAtom(Cs);return()=>{l({}),e([]),s([]),n(),t(),o(!1),r(),a("SAVED"),c(0)}},Xy=(t,e)=>{const n=[];let s=d.find(t,{_id:e}),o=d.get(s,"_parent","");for(;d.isString(o)&&!d.isEmpty(o);)n.push(s==null?void 0:s._parent),s=d.find(t,{_id:o}),o=s==null?void 0:s._parent;return d.flatten(n)},Zy=S.atom([]),Qy=()=>{const[t]=q(),e=S.useAtomValue(Ne),[,n]=S.useAtom(Zy);g.useEffect(()=>{let s=[];const o=d.first(t);d.isString(o)&&(s=[o,...Xy(e,o)]),n(s)},[t,e,n])},e0=t=>{const[,e]=Z(),n=Jy(),[s]=S.useAtom(Ss);S.useAtom(Kr),Ia(),Qy(),ou(),su(),hu();const{postMessage:o}=aa(),[,r]=S.useAtom(na),a=Hr();return g.useEffect(()=>{$e.set(Fr,d.omit(t,["blocks","translations","pageExternalData","globalStyles"]))},[t]),g.useEffect(()=>{$e.set(zr,t.pageExternalData||{})},[t.pageExternalData]),g.useEffect(()=>{$e.set(Qt,t.designTokens||{})},[t.designTokens]),g.useEffect(()=>{r(!1),setTimeout(()=>{const l=K.syncBlocksWithDefaultProps(t.blocks||[]);e(l),l&&l.length>0&&o({type:"blocks-updated",blocks:l}),n(),r(!0),a(l)},400)},[t.blocks]),g.useEffect(()=>{ft.changeLanguage(t.locale||"en")},[t.locale]),g.useEffect(()=>{zy(t.debugLogs??!1)},[t.debugLogs]),g.useEffect(()=>{t.translations&&d.each(t.translations,(l,c)=>{ft.addResourceBundle(c,"translation",l,!0,!0)})},[t.translations]),g.useEffect(()=>(s!=="SAVED"?window.onbeforeunload=()=>"":window.onbeforeunload=null,()=>{window.onbeforeunload=null}),[s]),null},t0=t=>{const e=g.useMemo(()=>t.layout||My,[t.layout]),n=$("builderTheme",Xe.defaultThemeValues),s=$("flags.exportCode",!1);return i.jsxs(i.Fragment,{children:[t.children,i.jsx(Ta,{theme:n}),i.jsx(e,{}),s&&i.jsx(Mc,{})]})},n0=t=>{const e=t.onError||d.noop;return i.jsx("div",{className:"h-screen w-screen",children:i.jsxs(Nt.ErrorBoundary,{fallback:i.jsx(xn,{}),onError:e,children:[i.jsx(Yy,{}),i.jsx(t0,{...t}),i.jsx(e0,{...t}),i.jsx(Fy,{}),i.jsx(le.Toaster,{richColors:!0})]})})},s0=({baseUrl:t="https://chaibuilder-sdk.vercel.app"}={})=>({name:"Chai Library",description:"",getBlocksList:async e=>{try{const n=await fetch(`${t}/library-blocks/blocks-list.json`);return n.ok?(await n.json()).map(o=>{var r;return{...o,preview:(r=o.preview)!=null&&r.startsWith("http")?o.preview:`${t}${o.preview}`}}):(console.error("Failed to fetch blocks list:",n.status,n.statusText),[])}catch(n){return console.error("Error fetching blocks list:",n),[]}},getBlock:async({block:e})=>{try{const n=await fetch(`${t}/${e.id}.html?raw`);return n.ok?await n.text():(console.error(`Failed to fetch block "${e.id}" from "${t}/${e.id}.html?raw": ${n.status} ${n.statusText}`),`<!-- Error loading block "${e.id}": ${n.status} ${n.statusText} -->`)}catch(n){return console.error(`Error fetching block "${e.id}" from "${t}/${e.id}.html?raw":`,n),`<!-- Error loading block "${e.id}" -->`}}}),r0=(t,e)=>t.map(n=>{const s=K.getRegisteredChaiBlock(n._type);if(!s)return n;const o=s.i18nProps;if(!o)return n;const r=d.filter(e,{_type:n._type}),a=d.pick(n,o);return d.each(a,(l,c)=>{const u=d.find(r,p=>{var m;const f=typeof p[c]=="string"?(m=p[c])==null?void 0:m.trim().toLowerCase():JSON.stringify(p[c]),h=typeof l=="string"?l.trim().toLowerCase():JSON.stringify(l);return f===h});if(u){const p=d.filter(Object.keys(u),h=>d.startsWith(h,`${c}-`)),f=d.pick(u,p);n={...n,...f}}}),n}),o0=()=>{const[t]=Z();return g.useCallback(e=>{const n=ne.getBlocksFromHTML(e),s=ne.mergeBlocksWithExisting(n,t);return r0(s,t)},[t])},Oc=(t,e)=>{const n=t.filter(o=>o._parent===e),s=n.flatMap(o=>Oc(t,o._id));return[...n,...s]},i0=(t,e)=>{const n=e.find(o=>o._id===t);if(!n)return[];const s=Oc(e,t);return[n,...s]},a0=()=>{const t=J(),[e]=Z();return g.useCallback((n="")=>{const s=t!=null&&t._id?i0(t._id,e):e;return s?d.compact(s.map(o=>{const r=K.getRegisteredChaiBlock(o._type);if(!r)return null;const a=(r==null?void 0:r.i18nProps)??[];if(a.length===0)return null;const l=n==="ALL"?Object.keys(o).filter(u=>a.find(p=>u.startsWith(p))):a.map(u=>n?`${u}-${n}`:u),c=d.pick(o,["_id"]);return d.each(l,u=>{c[u]=d.get(o,u,d.get(o,u.replace(`-${n}`,"")))}),c})):[]},[t==null?void 0:t._id,e])},$c=(t,e)=>{const n=t.filter(r=>r._parent===e),s=n.map(r=>r._id),o=n.flatMap(r=>$c(t,r._id));return[...s,...o]},l0=(t,e,n)=>{const s=d.find(t,{_id:e});if(!s)return t;const o=t.findIndex(f=>f._id===e),r=$c(t,e),a=new Set([e,...r]),l=t.filter(f=>!a.has(f._id)),c=new Set(n.map(f=>f._id)),u=n.map(f=>!f._parent||!c.has(f._parent)?{...f,_parent:s._parent}:f);return[...l.slice(0,o),...u,...l.slice(o)]},c0=()=>{const[,t]=q(),{setNewBlocks:e}=Ee(),{hasPermission:n}=Ge();return g.useCallback((s,o)=>{if(!n(be.EDIT_BLOCK))return;const r=$e.get(Ne),a=s?l0(r,s,o):o;e(a),o.length>0&&setTimeout(()=>t([o[0]._id]),200)},[t,e,n])};if(typeof window>"u")throw new Error("@chaibuilder/sdk is only supported in the browser. Avoid using it in the server side.");exports.AIUserPrompt=Ac;exports.AddBlocksDialog=Rc;exports.AddBlocksPanel=To;exports.AlertDialog=Bo;exports.AlertDialogAction=Lo;exports.AlertDialogCancel=Do;exports.AlertDialogContent=zs;exports.AlertDialogDescription=Po;exports.AlertDialogFooter=Ro;exports.AlertDialogHeader=Hs;exports.AlertDialogTitle=Vs;exports.AlertDialogTrigger=gc;exports.Badge=Ps;exports.BlockAttributesEditor=Pc;exports.BlockSettings=yr;exports.BlockStyling=jr;exports.Breakpoints=tc;exports.CanvasArea=Dl;exports.Card=No;exports.CardContent=Ao;exports.CardFooter=_o;exports.CardHeader=Eo;exports.CardTitle=ic;exports.ChaiBuilderEditor=n0;exports.ChaiDraggableBlock=uc;exports.ClearCanvas=bc;exports.Command=go;exports.CommandEmpty=yo;exports.CommandGroup=ko;exports.CommandInput=xo;exports.CommandItem=bs;exports.CommandList=bo;exports.DarkMode=Ey;exports.DefaultChaiBlocks=oc;exports.Dialog=Bn;exports.DialogContent=rn;exports.DialogDescription=Fl;exports.DialogFooter=$l;exports.DialogHeader=Rn;exports.DialogTitle=on;exports.DialogTrigger=Ml;exports.DropdownMenu=gt;exports.DropdownMenuContent=Ze;exports.DropdownMenuItem=ge;exports.DropdownMenuLabel=Ar;exports.DropdownMenuSeparator=_r;exports.DropdownMenuTrigger=xt;exports.ExportCodeModal=Mc;exports.HoverCard=Ql;exports.HoverCardContent=So;exports.HoverCardTrigger=ec;exports.ImportHTML=lc;exports.LANGUAGES=Pt;exports.Label=mt;exports.ListTree=wc;exports.NestedPathSelector=vo;exports.PERMISSIONS=be;exports.Popover=Ls;exports.PopoverContent=Pn;exports.PopoverTrigger=Ds;exports.ScrollArea=Sn;exports.Select=Fs;exports.SelectContent=zn;exports.SelectItem=Hn;exports.SelectTrigger=Fn;exports.Separator=bn;exports.Sheet=Ic;exports.SheetContent=Mo;exports.SheetDescription=Bc;exports.SheetHeader=Oo;exports.SheetTitle=$o;exports.Switch=Ln;exports.Tabs=$s;exports.TabsContent=at;exports.TabsList=On;exports.TabsTrigger=ze;exports.Textarea=$n;exports.ThemeConfigPanel=Sc;exports.Tooltip=de;exports.TooltipContent=ae;exports.TooltipProvider=xs;exports.TooltipTrigger=ue;exports.UILibrariesPanel=fc;exports.UndoRedo=Ay;exports.chaiDesignTokensAtom=Qt;exports.chaiThemeValuesAtom=Ra;exports.dataBindingActiveAtom=Yr;exports.defaultChaiLibrary=s0;exports.getClassValueAndUnit=Yl;exports.useAddBlock=bt;exports.useBlocksHtmlForAi=Dc;exports.useBlocksStore=Z;exports.useBuilderProp=$;exports.useCanvasZoom=Rl;exports.useCodeEditor=mo;exports.useHtmlToBlocks=o0;exports.useI18nBlocks=a0;exports.useLanguages=Te;exports.usePageExternalData=Dt;exports.usePermissions=Ge;exports.useRemoveBlocks=Ns;exports.useReplaceBlock=c0;exports.useRightPanel=Pa;exports.useSavePage=en;exports.useSelectedBlock=J;exports.useSelectedBlockIds=q;exports.useSidebarActivePanel=_s;exports.useStreamMultipleBlocksProps=Qi;exports.useUpdateBlocksProps=Ke;exports.useUpdateBlocksPropsRealtime=Or;