@chaibuilder/sdk 4.0.0-beta.23 → 4.0.0-beta.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{2SSKDMRQ-SUA5eA2S.js → 2SSKDMRQ-Bk_4y8lw.js} +2 -2
- package/dist/{2SSKDMRQ-DVWVGtU8.cjs → 2SSKDMRQ-vWeQ_IyI.cjs} +1 -1
- package/dist/{AP7HFJJL-CUN5zddU.cjs → AP7HFJJL-CMPLeI6t.cjs} +1 -1
- package/dist/{AP7HFJJL-Co5bLh3I.js → AP7HFJJL-D_mI2XSw.js} +1 -1
- package/dist/{IconPicker-Bmz6vXB8.cjs → IconPicker-DB_PpKvH.cjs} +1 -1
- package/dist/{IconPicker-BZvFj3cg.js → IconPicker-jc6_JzXf.js} +1 -1
- package/dist/{WDYDFRGG-DjCIT9L-.js → WDYDFRGG-B4H3RPcp.js} +2 -2
- package/dist/{WDYDFRGG-BpSteEEf.cjs → WDYDFRGG-D7vzbPjk.cjs} +1 -1
- package/dist/{active-in-another-tab-DfRJcvAz.js → active-in-another-tab-CDhFxBU7.js} +2 -2
- package/dist/{active-in-another-tab-C8-vpt8f.cjs → active-in-another-tab-CMPHyyHE.cjs} +1 -1
- package/dist/{add-new-language-page-jZ7Pg0Fv.js → add-new-language-page-BliZ46WW.js} +3 -3
- package/dist/{add-new-language-page-B2BEmfil.cjs → add-new-language-page-IbMzbf4v.cjs} +1 -1
- package/dist/{add-new-page-DbEBB3w7.cjs → add-new-page-BJJqSKp0.cjs} +1 -1
- package/dist/{add-new-page-YZF_XF8X.js → add-new-page-DUCKfyWo.js} +2 -2
- package/dist/{ai-panel-content-Bf_ojKwt.cjs → ai-panel-content-DWOqjq3Z.cjs} +1 -1
- package/dist/{ai-panel-content-C8ecaQnv.js → ai-panel-content-GeQIaXy8.js} +3 -3
- package/dist/{ai-panel-default-lang-DokOmE_Q.cjs → ai-panel-default-lang-DGNDrfam.cjs} +2 -2
- package/dist/{ai-panel-default-lang-BC8Gq_jl.js → ai-panel-default-lang-VQsV6KB3.js} +3 -3
- package/dist/{ai-panel-other-lang-Ccx1t8pp.cjs → ai-panel-other-lang-DvXF0Nn5.cjs} +1 -1
- package/dist/{ai-panel-other-lang-BJ30SL7z.js → ai-panel-other-lang-SuC8jyfr.js} +3 -3
- package/dist/{ai-prompt-input-SfeB6a2j.js → ai-prompt-input-CB6iQAmE.js} +1 -1
- package/dist/{ai-prompt-input-ED14e6NE.cjs → ai-prompt-input-a8s-JrZb.cjs} +1 -1
- package/dist/{ai-translation-prompt-BRRzei71.js → ai-translation-prompt-CoNVDclG.js} +1 -1
- package/dist/{ai-translation-prompt-spS-OC6L.cjs → ai-translation-prompt-Qn1Sz4BI.cjs} +1 -1
- package/dist/change-password-modal-BtdsU0mm.cjs +1 -0
- package/dist/change-password-modal-CMEo8lEm.js +137 -0
- package/dist/{code-editor-CYiIxUKp.js → code-editor-CTMQr0aU.js} +1 -1
- package/dist/{code-editor-CIqswl5j.cjs → code-editor-CjatfjZe.cjs} +1 -1
- package/dist/{continue-editing-in-this-client-B3CnmiZ2.cjs → continue-editing-in-this-client-7swLl0kq.cjs} +1 -1
- package/dist/{continue-editing-in-this-client-vICoETHN.js → continue-editing-in-this-client-CNVJZvXQ.js} +2 -2
- package/dist/core.cjs +1 -1
- package/dist/core.d.ts +1 -0
- package/dist/core.js +1 -1
- package/dist/{css-import-modal-DautOct0.js → css-import-modal-B3XY8Hzw.js} +1 -1
- package/dist/{css-import-modal-CHFZPXXQ.cjs → css-import-modal-D2RqE-V0.cjs} +1 -1
- package/dist/{delete-design-token-BmWHk_Ap.js → delete-design-token-DEyYFVHU.js} +1 -1
- package/dist/{delete-design-token-D-wGR5qS.cjs → delete-design-token-Dd3b86G7.cjs} +1 -1
- package/dist/{delete-page-Dlv8srng.js → delete-page-BSn5mRvk.js} +2 -2
- package/dist/{delete-page-D5mzl-ET.cjs → delete-page-BfsmsTek.cjs} +1 -1
- package/dist/{design-token-usage-DIszlgJK.cjs → design-token-usage-BY8meqAt.cjs} +1 -1
- package/dist/{design-token-usage-hl29qR_q.js → design-token-usage-f20BdlHE.js} +1 -1
- package/dist/{digital-asset-manager-v2LfDXwR.cjs → digital-asset-manager-Pi0YiB35.cjs} +1 -1
- package/dist/{digital-asset-manager-o_bNl9qj.js → digital-asset-manager-iXt27NlP.js} +3 -3
- package/dist/{duplicate-page-BjqgghN0.js → duplicate-page-BuVub6uY.js} +3 -3
- package/dist/{duplicate-page-CEuF8dll.cjs → duplicate-page-g5hiQkrZ.cjs} +1 -1
- package/dist/{dynamic-page-selector-BWC7kHJ1.js → dynamic-page-selector-NZ-rKLo3.js} +2 -2
- package/dist/{dynamic-page-selector-D4EWs4Qd.cjs → dynamic-page-selector-z6UGEjk1.cjs} +1 -1
- package/dist/{get-chai-builder-theme-DDVRJQ6Z.js → get-chai-builder-theme-CHXhAcdV.js} +1 -1
- package/dist/{get-chai-builder-theme-BApShjRz.cjs → get-chai-builder-theme-CMypjJk8.cjs} +1 -1
- package/dist/{image-editor-B1-bjvPd.js → image-editor--WT9183_.js} +1 -1
- package/dist/{image-editor-2h5axNuk.cjs → image-editor-C6cZZNbB.cjs} +1 -1
- package/dist/index-BGGNVIKx.cjs +5 -0
- package/dist/{index-DWGTiEak.cjs → index-CfsIhbT2.cjs} +11 -11
- package/dist/{index-BvluH-oT.js → index-ckjNCVor.js} +990 -978
- package/dist/{index-BN6yEl-H.js → index-iRqgNs2O.js} +897 -891
- package/dist/{json-diff-viewer-WX0GIjq-.js → json-diff-viewer-DAQ-qSHk.js} +2 -2
- package/dist/{json-diff-viewer-BjCIlzd7.cjs → json-diff-viewer-DheqS084.cjs} +1 -1
- package/dist/{lang-panel-C4x7bcyb.js → lang-panel-DRDPvY1i.js} +3 -3
- package/dist/{lang-panel--yfjRDE2.cjs → lang-panel-oLc-QyU4.cjs} +1 -1
- package/dist/{manage-design-tokens-DhdwhzQu.cjs → manage-design-tokens-Hu25ejcC.cjs} +1 -1
- package/dist/{manage-design-tokens-CRwsErkx.js → manage-design-tokens-rEzXQJRW.js} +2 -2
- package/dist/{mark-as-template-DpZSFrLK.js → mark-as-template-BNbn5zQG.js} +2 -2
- package/dist/{mark-as-template-BH0W9p2G.cjs → mark-as-template-DEThYoS6.cjs} +1 -1
- package/dist/{nested-path-selector-content-BDQmZzlf.js → nested-path-selector-content-BERhs6_L.js} +1 -1
- package/dist/{nested-path-selector-content-CHYz7cdB.cjs → nested-path-selector-content-Dz3-bNqT.cjs} +1 -1
- package/dist/{no-language-page-content-D0lcCseQ.js → no-language-page-content-CPVIz5rC.js} +2 -2
- package/dist/{no-language-page-content-D7btm8zX.cjs → no-language-page-content-CrUkIrUJ.cjs} +1 -1
- package/dist/{no-language-page-dialog-sYOmLnpY.cjs → no-language-page-dialog-964r8feg.cjs} +1 -1
- package/dist/{no-language-page-dialog-BdW7oXvt.js → no-language-page-dialog-DPDJ6gkQ.js} +2 -2
- package/dist/{page-creator-O_QpbMlB.js → page-creator-CDcfL4al.js} +3 -3
- package/dist/{page-creator-B-jBAGZl.cjs → page-creator-kvymje2i.cjs} +1 -1
- package/dist/{page-lock-CmQKpw1U.js → page-lock-BpUGSiCT.js} +2 -2
- package/dist/{page-lock-BrVqfmVm.cjs → page-lock-gOE-Tt7g.cjs} +1 -1
- package/dist/{page-locked-dialog-BjeJOXuN.js → page-locked-dialog-UQeYxWz1.js} +2 -2
- package/dist/{page-locked-dialog-ChHVSk7X.cjs → page-locked-dialog-aJFtoEzq.cjs} +1 -1
- package/dist/{page-manager-new-B90zLpRY.cjs → page-manager-new-DBomYOFT.cjs} +1 -1
- package/dist/{page-manager-new-wcsdorbd.js → page-manager-new-Dg02OZtc.js} +22 -22
- package/dist/{page-manager-search-and-filter-DY_NsetM.js → page-manager-search-and-filter-CCTh5gkC.js} +2 -2
- package/dist/{page-manager-search-and-filter-Bb_Zfpsj.cjs → page-manager-search-and-filter-pWHXOgMJ.cjs} +1 -1
- package/dist/{page-revisions-content-CVpi-467.cjs → page-revisions-content-BDY8RXJW.cjs} +1 -1
- package/dist/{page-revisions-content-5h39VYXj.js → page-revisions-content-C6YjUAx9.js} +7 -7
- package/dist/pages.cjs +1 -1
- package/dist/pages.d.ts +1 -0
- package/dist/pages.js +12 -12
- package/dist/plugin-DH3BDqys.js +251 -0
- package/dist/{plugin-BGlQf0iy.cjs → plugin-DO5QAuc1.cjs} +13 -13
- package/dist/{publish-pages-content-rrfvXks4.js → publish-pages-content-8MQN9iLc.js} +17 -17
- package/dist/{publish-pages-content-BG1GIuIz.cjs → publish-pages-content-DjUd9oWi.cjs} +1 -1
- package/dist/render.cjs +1 -1
- package/dist/render.d.ts +4 -1
- package/dist/render.js +2 -2
- package/dist/{rte-widget-modal-29WtCMJs.js → rte-widget-modal-Bj7lxFEs.js} +1 -1
- package/dist/{rte-widget-modal-JRoPPuju.cjs → rte-widget-modal-O31cHitM.cjs} +1 -1
- package/dist/{save-to-lib-Bm7R2K7j.js → save-to-lib-BMlowHNl.js} +2 -2
- package/dist/{save-to-lib-YvzDV5ee.cjs → save-to-lib-vxpiXsok.cjs} +1 -1
- package/dist/sdk.css +1 -1
- package/dist/{selected-block-display-bdClAekS.cjs → selected-block-display-BjhZTfSL.cjs} +1 -1
- package/dist/{selected-block-display-BAulh0Nz.js → selected-block-display-BxHTDLna.js} +2 -2
- package/dist/{seo-panel-CT0D3I44.js → seo-panel-197ULlty.js} +2 -2
- package/dist/{seo-panel-D9wnaLG-.cjs → seo-panel-MrGhioya.cjs} +1 -1
- package/dist/{shared-json-ld-ON6LaybZ.cjs → shared-json-ld-6ovlKZ7L.cjs} +1 -1
- package/dist/{shared-json-ld-CuhqVL8H.js → shared-json-ld-B2kfIim8.js} +24 -24
- package/dist/{slug-input-DNeh6LBv.js → slug-input-CSqTWSv8.js} +1 -1
- package/dist/{slug-input-CxmcQbTR.cjs → slug-input-CV-Dvosn.cjs} +1 -1
- package/dist/supabase-actions.cjs +1 -1
- package/dist/supabase-actions.d.ts +34 -0
- package/dist/supabase-actions.js +231 -192
- package/dist/{take-over-request-CrILj_3q.cjs → take-over-request-BFZbLBOK.cjs} +1 -1
- package/dist/{take-over-request-BmeR6t3b.js → take-over-request-Ds_-1dOv.js} +2 -2
- package/dist/{theme-panel-footer-D4oCAY2G.js → theme-panel-footer-C1f2KMBq.js} +2 -2
- package/dist/{theme-panel-footer-BMx5lGB4.cjs → theme-panel-footer-dHh8VGgj.cjs} +1 -1
- package/dist/{translation-warning-modal-BNG9m-FC.js → translation-warning-modal-DPdVK3CD.js} +1 -1
- package/dist/{translation-warning-modal-ChL7oDO1.cjs → translation-warning-modal-HD8Mlj1e.cjs} +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/{unmark-as-template-BYiyJloZ.cjs → unmark-as-template-D8wEsu9z.cjs} +1 -1
- package/dist/{unmark-as-template-CEEMIY1A.js → unmark-as-template-DLVNotM_.js} +2 -2
- package/dist/{unpublish-page-B0aY1JnO.cjs → unpublish-page-Cl2R_dfN.cjs} +1 -1
- package/dist/{unpublish-page-Bm20P3TB.js → unpublish-page-ik9a66Rz.js} +2 -2
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/web-blocks.cjs +1 -1
- package/dist/web-blocks.js +23 -22
- package/dist/{web-preview-iQgiotU6.cjs → web-preview-CE39XTw0.cjs} +1 -1
- package/dist/{web-preview-BtEn4Vc-.js → web-preview-ztlGD_Xm.js} +1 -1
- package/package.json +1 -1
- package/dist/index-BJVYKKJq.cjs +0 -5
- package/dist/plugin-C-ht41UZ.js +0 -245
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Mc=Object.defineProperty;var Dc=(t,e,n)=>e in t?Mc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var wt=(t,e,n)=>Dc(t,typeof e!="symbol"?e+"":e,n);const a=require("react/jsx-runtime"),_=require("./register-chai-top-bar-DWTuRU53.cjs"),d=require("lodash-es"),Oc=require("@radix-ui/react-dropdown-menu"),v=require("@radix-ui/react-icons"),g=require("react"),X=require("./core-BWQrViOY.cjs"),j=require("jotai"),q=require("./STRINGS-FNnfjF5H.cjs"),Ho=require("@rjsf/utils"),ve=require("./common-functions-B3a4xKt_.cjs"),Se=require("jotai/utils"),ke=require("@react-hookz/web"),Ze=require("./plugin-BGlQf0iy.cjs"),$c=require("tree-model"),Fc=require("undo-manager"),F=require("react-i18next"),zc=require("@radix-ui/react-dialog"),be=require("./apply-binding-nqrhHgIz.cjs"),vr=require("class-variance-authority"),Hc=require("@radix-ui/react-tooltip"),De=require("cmdk"),Vc=require("@radix-ui/react-popover"),gt=require("i18next"),Wc=require("@tiptap/extension-text-style"),Gc=require("@tiptap/extension-highlight"),Uc=require("@tiptap/extension-link"),qc=require("@tiptap/extension-placeholder"),Kc=require("@tiptap/extension-text-align"),Yc=require("@tiptap/extension-underline"),ns=require("@tiptap/react"),Xc=require("@tiptap/starter-kit"),Pa=require("clsx"),La=require("tailwind-merge"),Jc=require("react-colorful"),rr=require("react-dom"),Zc=require("@rjsf/core"),Qc=require("@rjsf/validator-ajv8"),ed=require("@radix-ui/react-accordion"),Ma=require("fuse.js"),td=require("@radix-ui/react-hover-card"),nd=require("@radix-ui/react-label"),sd=require("react-autosuggest"),pe=require("sonner"),rd=require("@radix-ui/react-scroll-area"),od=require("@radix-ui/react-tabs"),ad=require("@radix-ui/react-select"),id=require("@radix-ui/react-alert-dialog"),ld=require("react-arborist"),cd=require("@radix-ui/react-separator"),dd=require("@radix-ui/react-switch"),ud=require("@radix-ui/react-slider"),Da=require("./fonts-B-Xt29pe.cjs");require("nanoid");const Vo=require("himalaya");require("@mhsdesign/jit-browser-tailwindcss");const pd=require("@tailwindcss/aspect-ratio"),fd=require("@tailwindcss/container-queries"),hd=require("@tailwindcss/forms"),md=require("@tailwindcss/typography"),Xe=require("react-hotkeys-hook"),gd=require("./get-chai-builder-tailwind-config-DNp8Vhme.cjs"),At=require("react-error-boundary"),Vn=require("framer-motion"),Hs=require("@floating-ui/dom"),Wo=require("@floating-ui/react-dom"),xd=require("react-wrap-balancer");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 ge=Re(Oc),D=Re(g),ie=Re(zc),Jt=Re(Hc),vn=Re(Vc),Pt=Re(ed),bs=Re(td),Oa=Re(nd),It=Re(rd),$t=Re(od),me=Re(ad),Pe=Re(id),$a=Re(cd),or=Re(dd),un=Re(ud);function Lt({className:t,...e}){return a.jsx("div",{className:_.cn("animate-pulse rounded-md bg-primary/10",t),...e})}const kr=({className:t="h-full w-full",onClick:e=d.noop})=>a.jsx("svg",{className:t,viewBox:"0 0 256 256",fill:"currentColor",onClick:e,children:a.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"})}),et=ge.Root,tt=ge.Trigger,bd=D.forwardRef(({className:t,inset:e,children:n,...s},r)=>a.jsxs(ge.SubTrigger,{ref:r,className:_.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,a.jsx(v.ChevronRightIcon,{className:"ml-auto h-4 w-4"})]}));bd.displayName=ge.SubTrigger.displayName;const yd=D.forwardRef(({className:t,...e},n)=>a.jsx(ge.SubContent,{ref:n,className:_.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}));yd.displayName=ge.SubContent.displayName;const Ge=D.forwardRef(({className:t,sideOffset:e=4,...n},s)=>a.jsx(ge.Portal,{children:a.jsx(ge.Content,{ref:s,sideOffset:e,className:_.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})}));Ge.displayName=ge.Content.displayName;const le=D.forwardRef(({className:t,inset:e,...n},s)=>a.jsx(ge.Item,{ref:s,className:_.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}));le.displayName=ge.Item.displayName;const Fa=D.forwardRef(({className:t,children:e,checked:n,...s},r)=>a.jsxs(ge.CheckboxItem,{ref:r,className:_.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:[a.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:a.jsx(ge.ItemIndicator,{children:a.jsx(v.CheckIcon,{className:"h-4 w-4"})})}),e]}));Fa.displayName=ge.CheckboxItem.displayName;const vd=D.forwardRef(({className:t,children:e,...n},s)=>a.jsxs(ge.RadioItem,{ref:s,className:_.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:[a.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:a.jsx(ge.ItemIndicator,{children:a.jsx(v.CircleIcon,{className:"h-2 w-2 fill-current"})})}),e]}));vd.displayName=ge.RadioItem.displayName;const za=D.forwardRef(({className:t,inset:e,...n},s)=>a.jsx(ge.Label,{ref:s,className:_.cn("px-2 py-1.5 text-sm font-semibold",e&&"pl-8",t),...n}));za.displayName=ge.Label.displayName;const wr=D.forwardRef(({className:t,...e},n)=>a.jsx(ge.Separator,{ref:n,className:_.cn("-mx-1 my-1 h-px bg-muted",t),...e}));wr.displayName=ge.Separator.displayName;const K={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=X.getRegisteredChaiBlock(t);return n&&n.canAcceptBlock?n.canAcceptBlock(e):!1},ss=t=>{const e=X.getRegisteredChaiBlock(t);return e?d.has(e,"canAcceptBlock"):!1},kd=(t,e)=>{const n=X.getRegisteredChaiBlock(e);return n&&n.canBeNested?n.canBeNested(t):!0},Cr=t=>{const e=X.getRegisteredChaiBlock(t);return e&&e.canDuplicate?e.canDuplicate():!0},jr=t=>{const e=X.getRegisteredChaiBlock(t);return e&&e.canDelete?e.canDelete():!0};class wd{constructor(){wt(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(r=>r(n))}}const oe=new wd;function Ha(t,e,n){const s=d.filter(t,o=>o._parent===e),r=[];for(let o=0;o<s.length;o++)if(d.filter(t,{_parent:s[o]._id}).length>0){const i=ve.generateUUID();r.push({...s[o],oldId:s[o]._id,_id:i,_parent:n}),r.push(d.flatten(Ha(t,s[o]._id,i)))}else r.push({...s[o],oldId:s[o]._id,_id:ve.generateUUID(),_parent:n});return d.flatten(r)}function Sr(t){const e={};t.forEach(s=>{e[s._id]={...s,children:[]}});const n=[];return t.forEach(s=>{if(s._parent){const r=e[s._parent];r&&r.children.push(e[s._id])}else n.push(e[s._id])}),n}const ar=(t,e,n=null)=>{let s=d.find(t,{_id:e});s={...s,oldId:s._id,_id:ve.generateUUID()},n!==(s==null?void 0:s._parent)&&(s={...s,_parent:n});const r=[s];return d.filter(t,{_parent:e}).length>0&&r.push(d.flatten(Ha(t,e,s._id))),d.flatten(r)},je=j.atom([]);je.debugLabel="presentBlocksAtom";const Va=j.atom(t=>{const e=t(je);return Sr([...e])});Va.debugLabel="treeDSBlocks";const En=Se.splitAtom(je);En.debugLabel="pageBlocksAtomsAtom";const Cd=j.atom("");Cd.debugLabel="builderActivePageAtom";const jd=j.atom(-1);jd.debugLabel="destinationDropIndexAtom";const Wa=j.atom([]);Wa.debugLabel="buildingBlocksAtom";const Sd=j.atom(t=>{const e=t(Wa);return d.filter(e,n=>d.has(n,"blockId"))});Sd.debugLabel="globalBlocksAtom";const Qt=j.atom([]);Qt.debugLabel="structureErrorsAtom";const Nr=j.atom(!0);Nr.debugLabel="structureValidationValidAtom";const Er=j.atom(!1);Er.debugLabel="hasStructureErrorsAtom";const Ar=j.atom(!1);Ar.debugLabel="hasStructureWarningsAtom";const Ga=j.atom(t=>t(Qt).filter(n=>n.severity==="error").length);Ga.debugLabel="structureErrorCountAtom";const Ua=j.atom(t=>t(Qt).filter(n=>n.severity==="warning").length);Ua.debugLabel="structureWarningCountAtom";const qa=j.atom(t=>{const e=t(Qt),n={};return e.forEach(s=>{s.blockId&&(n[s.blockId]||(n[s.blockId]=[]),n[s.blockId].push(s))}),n});qa.debugLabel="structureErrorsByBlockAtom";const Ve=j.getDefaultStore(),Nd=()=>Ve.get(je),$=(t,e)=>{const n=j.useAtomValue(Rr);return g.useMemo(()=>d.get(n,t,e),[n,t,e])},Ka=j.atom("");Ka.debugLabel="selectedLanguageAtom";const Te=()=>{const t=$("languages",[]),e=$("fallbackLang","en"),[n,s]=j.useAtom(Ka),r=o=>{s(e===o?"":o)};return{languages:t==null?void 0:t.filter(o=>o!==e),fallbackLang:e,selectedLang:n,setSelectedLang:r}},ys=j.atom([]);ys.debugLabel="selectedBlockIdsAtom";const Ir=j.atom(t=>{const e=t(je),n=t(ys);return d.map(d.filter(e,({_id:s})=>d.includes(n,s)),s=>({...s}))});Ir.debugLabel="selectedBlocksAtom";const vs=j.atom(t=>{const e=t(Ir);if(e.length!==0&&e.length===1)return e[0]});vs.debugLabel="selectedBlockAtom";const J=()=>j.useAtomValue(vs),Ed=t=>d.get(t,"_parent",null),Ad=j.atom(t=>{const e=t(Ir),n=d.map(e,Ed);return d.filter(t(je),s=>d.includes(n,s._id))});Ad.debugLabel="selectedBlocksParentsAtom";const Ya=j.atom(()=>!1);Ya.debugLabel="selectedBlockFlexChildAtom";const Xa=j.atom(()=>!1);Xa.debugLabel="selectedBlockGridChildAtom";const Tr=j.atom("");Tr.debugLabel="styleStateAtom";const Ja=Se.atomWithStorage("styleBreakpoint","xs");Ja.debugLabel="styleBreakpointAtom";const Id=()=>({flexChild:j.useAtomValue(Ya),gridChild:j.useAtomValue(Xa)}),Td=j.atom(t=>{const e=t(vs),n=t(je);let s=e;const r=[e];do{const o=n.find(({_id:i})=>i===(s==null?void 0:s._parent));s=o,o&&r.push(o)}while(s!=null&&s._parent);return r}),_d=()=>d.compact(j.useAtomValue(Td)),U=()=>{const[t,e]=j.useAtom(ys),n=g.useCallback(s=>{e(r=>d.includes(r,s)?d.without(r,s):[...r,s])},[e]);return[t,e,n]},Za=(t,e,n)=>{const s=X.getRegisteredChaiBlock(d.get(n,"_type",""));if(!s)return t;const r={...t};return d.forEach(d.keys(t),o=>{if(d.includes(d.get(s,"i18nProps",[]),o)&&!d.isEmpty(e)){const i=`${o}-${e}`;d.set(r,i,t[o]),d.unset(r,o)}}),r},nt=()=>{const{updateBlocks:t}=Ne(),{selectedLang:e}=Te(),n=J();return g.useCallback((s,r,o)=>{const i=Za(r,e,n);t(s,i,o)},[e,n,t])},Bd=()=>{const{updateMultipleBlocksProps:t}=Ne();return g.useCallback(e=>{t(e)},[t])},Rd=()=>{const{updateBlocksRuntime:t}=Ne();return g.useCallback(async(e,n,s=30)=>{const r=d.keys(d.omit(n,["_id"]));for(const o of r){const i=n[o];if(d.isString(i)){const l=d.chunk(i.split(""),12);let c="";t([e],{[o]:""});for(let u=0;u<l.length;u++)c+=l[u].join(""),t([e],{[o]:c}),await new Promise(p=>setTimeout(p,s))}}},[t])},Qa=()=>{const{updateMultipleBlocksProps:t}=Ne(),e=Rd();return g.useCallback(async n=>{for(const s of n)await e(s._id,s);t(n)},[e,t])},_r=()=>{const{updateBlocksRuntime:t}=Ne(),{selectedLang:e}=Te(),n=J();return g.useCallback((s,r)=>{const o=Za(r,e,n);t(s,o)},[e,n,t])},Br=j.atom({});Br.debugLabel="blockRepeaterDataAtom";const ei=()=>j.useAtom(Br),Pd=(t,e,n,s)=>{const[r,o]=g.useState({status:"idle",props:{},error:void 0}),i=_r(),l=$("getBlockAsyncProps",async h=>({})),c=j.useSetAtom(Br),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,`{{${q.COLLECTION_PREFIX}`),f=(t==null?void 0:t._type)!=="Repeater"&&e==="live";return g.useEffect(()=>{if(e==="mock"){if(d.isFunction(s)){o(x=>({...x,status:"loading",props:{}}));const h=s({block:t});if(!Ho.isObject(h))throw new Error("mockDataProvider should return an object");o(x=>({...x,status:"loaded",props:h}))}return}e==="live"&&(!p&&!f||(o(h=>({...h,status:"loading",props:{}})),l({block:t}).then((h={})=>{p?(c(x=>({...x,[t._id]:{status:"loaded",props:d.get(h,"items",[]),repeaterItems:t.repeaterItems}})),o(x=>({...x,status:"loaded",props:{totalItems:d.get(h,"totalItems")}})),i([t._id],{totalItems:d.get(h,"totalItems")})):o(x=>({...x,status:"loaded",props:Ho.isObject(h)?h:{}}))}).catch(h=>{p?(c(x=>({...x,[t._id]:{status:"error",error:h,props:[]}})),o(x=>({...x,status:"error",error:h,props:{}}))):o(x=>({...x,status:"error",error:h,props:{}}))})))},[t==null?void 0:t._id,u,p,f,s,e]),{$loading:d.get(r,"status")==="loading",...t?d.get(r,"props",{}):{}}},Rr=j.atom(null);Rr.debugLabel="chaiBuilderPropsAtom";const Ld=j.atom({});Ld.debugLabel="chaiExternalDataAtom";const Md=j.atom({});Md.debugLabel="chaiRjsfFieldsAtom";const Dd=j.atom({});Dd.debugLabel="chaiRjsfWidgetsAtom";const Od=j.atom({});Od.debugLabel="chaiRjsfTemplatesAtom";const Pr=j.atom({});Pr.debugLabel="chaiPageExternalDataAtom";const en=j.atom({});en.debugLabel="chaiDesignTokensAtom";const tn=()=>{const[t]=ei(),e=g.useMemo(()=>{const s={};return Object.entries(t).forEach(([r,o])=>{o.status==="loaded"&&o.repeaterItems&&(s[o.repeaterItems.replace("}}",`/${r}`).replace("{{","")]=o.props)}),s},[t]);return{...j.useAtomValue(Pr),...e}},ks=j.atom(0),ti=j.atom({isOpen:!1,blockId:null}),$d=[{name:"no-nested-div-in-p",description:"Prevents div elements from being nested inside paragraph elements",validate:(t,e)=>{const n=[],s=(r,o=!1)=>{r.forEach(i=>{const l=i._type==="Paragraph";i._type==="Box"&&o&&n.push({id:`div-in-paragraph-${i._id}`,message:"Box (div) cannot be nested inside Paragraph elements",severity:"error",blockId:i._id}),i.children&&i.children.length>0&&s(i.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=(o,i=!1,l=[])=>{o.forEach(c=>{const u=[...l,c._id],p=c._type==="Link",f=c._type==="Button"&&c.link&&c.link.href&&c.link.href.trim()!=="",m=p||f;if(m&&i){const h=p?"Link":"Button with href";n.push({id:`nested-interactive-tree-${c._id}`,message:`${h} 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,m,u)})},r=o=>{o.filter(l=>l._type==="Link"||l._type==="Button"&&l.link&&l.link.href&&l.link.href.trim()!=="").forEach(l=>{if(l._parent){const c=o.find(m=>m._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 m=l._type==="Link"?"Link":"Button with href",h=u?"Link":"Button with href";n.push({id:`nested-interactive-parent-${l._id}`,message:`${m} cannot be nested inside ${h}`,severity:"error",blockId:l._id})}let f=c;for(;f&&f._parent;){const m=o.find(h=>h._id===f._parent);if(m){const h=m._type==="Link",x=m._type==="Button"&&m.link&&m.link.href&&m.link.href.trim()!=="";if(h||x){const b=l._type==="Link"?"Link":"Button with href",y=h?"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=m}}})};return s(e),r(t),n}},{name:"listitem-in-list",description:"Ensures ListItems are only inside List containers",validate:(t,e)=>{const n=[],s=(r,o=null)=>{r.forEach(i=>{i._type==="ListItem"&&o!=="List"&&n.push({id:`listitem-outside-list-${i._id}`,message:"List Item must be inside a List container",severity:"error",blockId:i._id}),i.children&&i.children.length>0&&s(i.children,i._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=(r,o=[])=>{r.forEach(i=>{const l=[...o,i._type];if(i._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-${i._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:i._id})}i._type==="TableRow"&&!l.slice(0,-1).includes("Table")&&n.push({id:`table-row-outside-table-${i._id}`,message:"Table Row must be inside a Table (Table Head or Table Body)",severity:"error",blockId:i._id}),(i._type==="TableHead"||i._type==="TableBody")&&!l.slice(0,-1).includes("Table")&&n.push({id:`table-section-outside-table-${i._id}`,message:"Table Head/Body must be inside a Table",severity:"error",blockId:i._id}),i.children&&i.children.length>0&&s(i.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=(r,o=!1)=>{r.forEach(i=>{const l=i._type==="Button";l&&o&&n.push({id:`nested-button-${i._id}`,message:"Button cannot be nested inside another button",severity:"error",blockId:i._id}),i.children&&i.children.length>0&&s(i.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=(r,o=[])=>{r.forEach(i=>{const l=i._type==="Paragraph";if(l&&o.length>0&&n.push({id:`nested-paragraph-${i._id}`,message:"Paragraph cannot be nested inside another paragraph",severity:"error",blockId:i._id}),i.children&&i.children.length>0){const c=l?[...o,i._id]:o;s(i.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=[],r=(o,i=[])=>{o.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:[...i,l._id]})}l.children&&l.children.length>0&&r(l.children,[...i,l._id])})};r(e);for(let o=1;o<s.length;o++){const i=s[o],l=s[o-1];i.level>l.level+1&&n.push({id:`heading-level-skip-${i.blockId}`,message:`Heading level skipped: h${l.level} followed by h${i.level}. Consider using h${l.level+1}`,severity:"warning",blockId:i.blockId})}return n}}],Fd=[{name:"image-alt-text",description:"Warns if images are missing alt text",validate:(t,e)=>{const n=[],s=r=>{r.forEach(o=>{o._type==="Image"&&!o.alt&&n.push({id:`image-missing-alt-${o._id}`,message:"Image should have alt text for accessibility",severity:"warning",blockId:o._id}),o.children&&o.children.length>0&&s(o.children)})};return s(e),n}},{name:"button-accessibility",description:"Ensures buttons have accessible labels",validate:(t,e)=>{const n=[],s=r=>{r.forEach(o=>{o._type==="Button"&&(o.content||o.children&&o.children.length>0||n.push({id:`button-no-label-${o._id}`,message:"Button should have accessible content (text or icon)",severity:"warning",blockId:o._id})),o.children&&o.children.length>0&&s(o.children)})};return s(e),n}}];class zd{constructor(){wt(this,"rules",[...$d])}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(...Fd)}getRuleNames(){return this.rules.map(e=>e.name)}}const Vs=new zd,Lr=(t={})=>{const e=$("flags.validateStructure",!0),n=j.useSetAtom(Qt),s=j.useSetAtom(Nr),r=j.useSetAtom(Er),o=j.useSetAtom(Ar),i=g.useCallback(c=>{const u=c;if(!e||!u||u.length===0)return;const p=Sr(u),f=[];let m=Vs.getRules();t.enableAccessibilityRules&&(Vs.enableAccessibilityRules(),m=Vs.getRules()),t.customRules&&t.customRules.length>0&&m.push(...t.customRules),m.forEach(y=>{try{const k=y.validate(u,p);f.push(...k)}catch(k){console.error(`Error running structure rule "${y.name}":`,k)}});const h=f.filter(y=>y.severity==="error").length>0,x=f.filter(y=>y.severity==="warning").length>0,b=!h;n(f),s(b),r(h),o(x)},[e,t,n,s,r,o]);return ke.useDebouncedCallback(i,[e,t,n,s,r,o],1e3)},Hd=["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"],ir={bodyFont:"Inter",headingFont:"Inter",roundedCorners:5,primaryColor:"#570df8",secondaryColor:"#f002b8",bodyBgDarkColor:"#031022",bodyBgLightColor:"#fcfcfc",bodyTextDarkColor:"#ffffff",bodyTextLightColor:"#000000"},Vd=j.atom(ir);j.atom(null);const Wd=()=>{const[t,e]=j.useAtom(Vd);return[d.isObject(t)?{...ir,...t}:ir,e]},Gd=j.atom(null),Ud=()=>({currentPage:j.useAtomValue(Gd)}),qd=d.memoize(t=>{const e=X.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))}),Kd=()=>{const[t]=Wd(),{currentPage:e}=Ud(),[n]=te();return g.useCallback(()=>{const s=d.map(n,r=>d.omit(r,qd(r._type)));return{currentPage:e,blocks:s}},[t,e,n])},ni=j.atom(!1),si=()=>j.useAtom(ni),qe=()=>{const t=$("permissions",null);return{hasPermission:g.useCallback(n=>t?t.includes(n):!0,[t])}},Yd=(t=Ze.defaultThemeOptions)=>{const e=Ze.defaultThemeValues;return t.fontFamily&&(e.fontFamily=Object.entries(t.fontFamily).reduce((n,[s,r])=>({...n,[s.replace("font-","")]:r}),e.fontFamily)),e.borderRadius=t.borderRadius,t.colors&&(e.colors=t.colors.reduce((n,s)=>(Object.entries(s.items).forEach(([r,o])=>{r in n&&(n[r]=o)}),n),e.colors)),e},Xd=j.atom({}),An=()=>{const t=In(),e=g.useMemo(()=>Yd(t),[t]),n=$("theme",{}),[s,r]=j.useAtom(Xd);return[g.useMemo(()=>({...e,...!d.isEmpty(n)&&n,...!d.isEmpty(s)&&s}),[e,n,s]),r]},In=()=>{const t=$("themeOptions",n=>n);return g.useMemo(()=>t(Ze.defaultThemeOptions),[t])},Jd=j.atom("block"),Mr=()=>j.useAtom(Jd),Zd=j.atom("settings"),ri=()=>j.useAtom(Zd),ws=j.atom("SAVED");ws.debugLabel="builderSaveStateAtom";const Qd=(t,e)=>e?t.some(n=>{if(!(n!=null&&n._type)||n._type==="PartialBlock")return!1;try{const s=X.getRegisteredChaiBlock(n._type);return s?(d.has(s,"i18nProps")?s.i18nProps??[]:[]).some(o=>{const i=`${o}-${e}`;return!n[i]||d.isEmpty(n[i])}):!1}catch(s){return console.warn(`Failed to get block definition for type: ${n._type}`,s),!1}}):!1,nn=()=>{const[t,e]=j.useAtom(ws),n=$("onSave",async k=>{}),s=$("onSaveStateChange",d.noop),r=Kd(),[o]=An(),{hasPermission:i}=qe(),{selectedLang:l,fallbackLang:c}=Te(),[u]=si(),p=j.useAtomValue(en),f=Lr(),[,m]=j.useAtom(ks),h=()=>{const k=r();return!l||l===c?!1:Qd(k.blocks||[],l)},x=g.useCallback(k=>!k&&(!i("save_page")||!u)||!k&&t==="SAVED",[i,u,t]);return{savePage:ke.useThrottledCallback(async(k=!1,w=!1)=>{if(x(w))return;const E=r();return E!=null&&E.blocks&&f(E.blocks),e("SAVING"),s("SAVING"),m(0),await n({autoSave:k,blocks:E.blocks,theme:o,needTranslations:h(),designTokens:p}),setTimeout(()=>{e("SAVED"),s("SAVED")},100),!0},[x,r,e,p,o,m,n,s,u,f],3e3),savePageAsync:async(k=!1)=>{if(x(k))return;e("SAVING"),s("SAVING");const w=r();return m(0),await n({autoSave:!0,blocks:w.blocks,theme:o,needTranslations:h(),designTokens:p}),setTimeout(()=>{e("SAVED"),s("SAVED")},100),!0},saveState:t,setSaveState:e,needTranslations:h}},eu=()=>{const{savePage:t,saveState:e}=nn(),n=$("autoSave",!0),s=$("autoSaveActionsCount",10),[r]=j.useAtom(ks);g.useEffect(()=>{n&&(e==="SAVED"||e==="SAVING"||r>=s&&t(!0))},[n,t,e,r,s])},Dr=()=>{const[,t]=j.useAtom(ks),{setSaveState:e}=nn();return g.useCallback(()=>{t(n=>n+1),e(n=>n!=="UNSAVED"?"UNSAVED":n)},[t,e])};function tu(t,e,n,s){const r=[...e];let o=[...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 m={_id:ve.generateUUID(),_parent:n,_type:"Text",content:u.content};Object.keys(u).forEach(h=>{h.startsWith("content-")&&(m[h]=u[h])}),r.unshift(m),o=o.map(h=>{if(h._id===n){const x={...h,content:""};return Object.keys(x).forEach(b=>{b.startsWith("content-")&&(x[b]="")}),x}return h})}}let i=o.filter(u=>!u._parent);n&&(i=o.filter(u=>u._parent===n));const l=s!==void 0&&!isNaN(s)&&s>-1?Math.min(s,i.length):i.length;let c=o.length;for(let u=0,p=0;u<o.length;u++)if(n!==void 0?o[u]._parent===n:!o[u]._parent){if(p===l){c=u;break}p++}return!n&&s!==void 0&&s>=i.length&&(c=o.length),[...o.slice(0,c),...r,...o.slice(c)]}function nu(t){return Sr(t)}function su(t){let e=[];return t.walk(n=>(delete n.model.children,e.push(n.model),!0)),e}function Go(t,e){return t.first(n=>n.model._id===e)||null}function ru(t,e,n,s){var u,p;const r=Go(t,e),o=Go(t,n);if(!r||!o)return!1;o.children||(o.model.children=[]);let i=(u=o==null?void 0:o.children)==null?void 0:u.findIndex(f=>f.model._id===e);r.drop(),i=Math.max(i,0);const c=(((p=r==null?void 0:r.model)==null?void 0:p._parent)||"root")===n&&i<=s?s-1:s;try{o.addChildAtIndex(r,c)}catch(f){return console.error("Error adding child to parent:",f),!1}return!0}function ou(t,e){if(!e||!e._parent)return t;const n=e._parent,s=t.find(o=>o._id===n);if(!s)return t;const r=t.filter(o=>o._parent===n);if(r.length===2){const o=r.find(i=>i._id!==e._id);if(o&&o._type==="Text"&&"content"in s)return t.map(l=>{if(l._id===n){const c={...l,content:o.content};return Object.keys(o).forEach(u=>{u.startsWith("content-")&&(c[u]=o[u])}),c}return l}).filter(l=>l._id!==o._id)}return t}function au(t,e,n){if(!n||n==="root")return t;const s=t.find(r=>r._id===n);if(!s)return t;if(s.content!==void 0&&s.content!==""&&!t.some(o=>o._parent===n&&o._id!==e._id)){const i={_id:ve.generateUUID(),_parent:n,_type:"Text",content:s.content};Object.keys(s).forEach(u=>{u.startsWith("content-")&&(i[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),i,...l.slice(c)]:[i,...l]}return t}function iu(t,e,n,s){if(!e)return t;const r=t.find(u=>u._id===e);if(!r)return t;let o=ou(t,r);const i=n||"root",c=new $c().parse({_id:"root",children:nu(o)});if(ru(c,e,i,s)){let u=su(c);const p=u.find(f=>f._id===e);return p&&(p._parent=i==="root"?null:i),u.shift(),n&&(u=au(u,r,n)),u}return o}const pn=new BroadcastChannel("chaibuilder"),oi=()=>{const t=$("pageId","chaibuilder_page");return{postMessage:ke.useDebouncedCallback(n=>pn.postMessage({...n,pageId:t}),[t],200)}},lu=()=>{const[,t]=te(),e=$("pageId","chaibuilder_page"),{updateBlocksProps:n}=ai();g.useEffect(()=>(pn.onmessageerror=s=>{console.log("error",s)},pn.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)},()=>{pn.onmessage=null,pn.onmessageerror=null}),[t,e])},Or=(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(m=>m._id!==l);if(f&&f._type==="Text"){const m=n.find(h=>h._id===u);m&&"content"in m&&(n=n.map(h=>{if(h._id===u){const x={...h,content:f.content};return Object.keys(f).forEach(b=>{b.startsWith("content-")&&(x[b]=f[b])}),x}return h}),s.push(f._id))}}});const r=[...e,...s],o=[],i=d.filter(n,l=>d.includes(r,l._id)||d.includes(r,l._parent)?(o.push(l._id),!1):!0);return d.isEmpty(o)?i:Or(i,o)},Cs=()=>{const[t]=te(),[e,n]=U(),{setNewBlocks:s}=Ne(),{hasPermission:r}=qe();return g.useCallback(o=>{var l;if(!r(se.DELETE_BLOCK))return;const i=((l=d.find(t,{_id:o[0]}))==null?void 0:l._parent)||null;s(Or(t,o)),setTimeout(()=>n(i?[i]:[]),200)},[t,n,e,r])},cu=j.atom(null,(t,e,{id:n,props:s})=>{const r=t(En),o=d.find(r,i=>t(i)._id===n);return o?e(o,{...t(o),...s}):null}),du=()=>j.useSetAtom(cu),uu=t=>Se.useAtomCallback(g.useCallback((e,n,s)=>{const r=e(t);if(!r||!r.length)return console.warn("No blocks available in splitAtoms"),null;const o=d.find(r,i=>e(i)._id===(d.isString(s)?s:e(s)._id));return o||(console.warn(`Block with id ${s} not found`),null)},[t]),{store:Ve}),ai=()=>{const[,t]=te(),{postMessage:e}=oi(),n=du(),s=Lr(),r=Dr();return{setNewBlocks:o=>{t(o),e({type:"blocks-updated",blocks:o})},addBlocks:(o,i,l)=>{t(c=>{const u=tu(c,o,i,l);return e({type:"blocks-updated",blocks:u}),s(u),r(),u})},removeBlocks:o=>{t(i=>{const l=Or(i,o);return e({type:"blocks-updated",blocks:l}),s(l),r(),l})},moveBlocks:(o,i,l)=>{t(c=>{let u=[...c];for(let p=0;p<o.length;p++)u=iu(u,o[p],i,l);return d.each(o,p=>{const f=d.find(u,m=>m._id===p);f&&n({id:p,props:{_parent:f._parent||null}})}),e({type:"blocks-updated",blocks:u}),s(u),r(),u})},updateBlocksProps:o=>{o.forEach(i=>{const l=d.omit(i,"_id");n({id:i._id,props:l})}),e({type:"blocks-props-updated",blocks:o}),r()}}},Ke=new Fc;Ke.setLimit(50);const pu=j.atom({canUndo:!1,canRedo:!1}),Tn=()=>{const[,t]=j.useAtom(ws),[e,n]=j.useAtom(pu),s=$("onSaveStateChange",d.noop),r=g.useCallback(()=>{const u={canUndo:Ke.hasUndo(),canRedo:Ke.hasRedo()};n(u),t("UNSAVED"),s("UNSAVED")},[n,t,s]);g.useEffect(()=>(Ke.setCallback(r),()=>{Ke.setCallback(d.noop)}),[r]);const o=g.useCallback(u=>{Ke.add(u),r()},[r]),i=g.useCallback(()=>{Ke.undo(),r()},[r]),l=g.useCallback(()=>{Ke.redo(),r()},[r]),c=g.useCallback(()=>{Ke.clear(),n({canUndo:!1,canRedo:!1})},[n]);return g.useMemo(()=>({add:o,undo:i,redo:l,hasUndo:()=>e.canUndo,hasRedo:()=>e.canRedo,clear:c}),[o,i,l,e.canUndo,e.canRedo,c])},te=()=>j.useAtom(je),Ne=()=>{const{add:t}=Tn(),{setNewBlocks:e,addBlocks:n,removeBlocks:s,moveBlocks:r,updateBlocksProps:o}=ai();return{moveBlocks:(h,x,b)=>{const y=Ve.get(je),k=d.map(h,E=>{const I=y.find(S=>S._id===E)._parent||null,N=y.filter(S=>I?S._parent===I:!S._parent).map(S=>S._id).indexOf(E);return{_id:E,oldParent:I,oldPosition:N}}),w=k.find(({_id:E})=>E===h[0]);w&&w.oldParent===x&&w.oldPosition===b||(r(h,x??null,b),t({undo:()=>d.each(k,({_id:E,oldParent:A,oldPosition:I})=>{r([E],A??null,I)}),redo:()=>r(h,x??null,b)}))},addBlocks:(h,x,b)=>{n(h,x,b),t({undo:()=>s(d.map(h,"_id")),redo:()=>n(h,x,b)})},removeBlocks:h=>{var w;const x=Ve.get(je),b=(w=d.first(h))==null?void 0:w._parent,k=x.filter(E=>b?E._parent===b:!E._parent).indexOf(d.first(h));s(d.map(h,"_id")),t({undo:()=>n(h,b??void 0,k),redo:()=>s(d.map(h,"_id"))})},updateBlocks:(h,x,b)=>{const y=Ve.get(je);let k=[];if(b)k=d.map(h,w=>({_id:w,...b}));else{const w=d.keys(x);k=d.map(h,E=>{const A=y.find(T=>T._id===E),I={_id:E};return d.each(w,T=>I[T]=A[T]),I})}o(d.map(h,w=>({_id:w,...x}))),t({undo:()=>o(k),redo:()=>o(d.map(h,w=>({_id:w,...x})))})},updateBlocksRuntime:(h,x)=>{o(d.map(h,b=>({_id:b,...x})))},setNewBlocks:h=>{const x=Ve.get(je);e(h),t({undo:()=>e(x),redo:()=>e(h)})},updateMultipleBlocksProps:h=>{const x=Ve.get(je);let b=[];b=d.map(h,y=>{const k=d.keys(y),w=x.find(A=>A._id===y._id),E={};return d.each(k,A=>E[A]=w==null?void 0:w[A]),E}),o(h),t({undo:()=>o(b),redo:()=>o(h)})}}},fu=({block:t,children:e})=>{const{t:n}=F.useTranslation(),[s]=te(),{hasPermission:r}=qe(),o=d.get(t,"_id"),i=d.get(t,"_parent"),l=d.filter(s,f=>i?d.get(f,"_parent")===i:!d.get(f,"_parent")),c=ss(d.get(t,"_type","")),u=d.findIndex(l,{_id:o}),p=f=>{if(f==="CHILD")oe.publish(K.OPEN_ADD_BLOCK,t);else{const m={_id:i||"",position:l==null?void 0:l.length};f==="BEFORE"?m.position=Math.max(u,0):f==="AFTER"&&(m.position=u+1),oe.publish(K.OPEN_ADD_BLOCK,m)}};return r(se.ADD_BLOCK)?a.jsxs(et,{children:[a.jsx(tt,{children:e}),a.jsxs(Ge,{className:"border border-blue-500 bg-primary text-white shadow-2xl",children:[c&&a.jsx(le,{className:"cursor-pointer text-xs",onClick:()=>p("CHILD"),children:n("Add inside")}),a.jsx(le,{className:"cursor-pointer text-xs",onClick:()=>p("BEFORE"),children:n("Add before")}),a.jsx(le,{className:"cursor-pointer text-xs",onClick:()=>p("AFTER"),children:n("Add after")})]})]}):null},js=j.atom(null),_n=j.atom({isVisible:!1,isValid:!1,position:"inside",placeholderOrientation:"horizontal",isEmpty:!1,top:0,left:0,width:0,height:0});let qt=!1;const $r=t=>{qt=t},Fr=j.atom(0),hu=j.atom(!1);hu.debugLabel="readOnlyModeAtom";const mu=j.atom("online");mu.debugLabel="networkModeAtom";j.atom("");const gu=j.atom(!1);gu.debugLabel="editLayerNameAtom";const xu=j.atom("");xu.debugLabel="activeLanguageAtom";const bu=j.atom("");bu.debugLabel="primaryLanguageAtom";const Ss=j.atom(null);Ss.debugLabel="canvasIframeAtom";const yu=j.atom("outline");yu.debugLabel="activePanelAtom";const ii=j.atom("");ii.debugLabel="showPredefinedBlockCategoryAtom";const vu=j.atom(!1);vu.debugLabel="draggingFlagAtom";const zr=j.atom(null);zr.debugLabel="treeRefAtom";const ku=j.atom({});ku.debugLabel="canvasSettingsAtom";const li=j.atom(!1);li.debugLabel="aiAssistantActiveAtom";const wu=j.atom(!1);wu.debugLabel="codeEditorOpenAtom";const Cu=Se.atomWithStorage("codeEditorHeight",500);Cu.debugLabel="codeEditorHeightAtom";const ju=j.atom([]);ju.debugLabel="xShowBlocksAtom";const Hr=Se.atomWithStorage("_selectedLibrary",null);Hr.debugLabel="selectedLibraryAtom";const Vr=j.atom(!0);Vr.debugLabel="dataBindingActiveAtom";const sn=()=>j.useAtom(Ss);let re=null,lt=null;function Su(t,e){const n=t.getAttribute("data-block-name"),s=t.getAttribute("data-block-type"),r=n||s||"Container",o=e.createElement("div");return o.className="chai-drag-parent-label",o.textContent=r,o.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",o}function Ws(){lt&<.parentNode&&(lt.parentNode.removeChild(lt),lt=null)}const Wr=()=>{const[t]=sn(),e=g.useMemo(()=>{var r;return(t==null?void 0:t.contentDocument)||((r=t==null?void 0:t.contentWindow)==null?void 0:r.document)},[t]),n=g.useCallback(r=>{if(!e)return;let o=null;if(!r){re&&(re.style.outline="",re.style.outlineOffset="",re.style.backgroundColor="",re.style.position="",re=null),Ws();return}typeof r!="string"?o=r:o=e.querySelector(`[data-block-id="${r}"]`),!(o===re&<&<.parentNode)&&(re&&re!==o&&(re.style.outline="",re.style.outlineOffset="",re.style.backgroundColor="",re.style.position=""),Ws(),o?(o.style.outline="2px dashed rgba(34, 197, 94, 1)",o.style.outlineOffset="2px",o.style.backgroundColor="rgba(34, 197, 94, 0.05)",window.getComputedStyle(o).position==="static"&&(o.style.position="relative"),lt=Su(o,e),o.appendChild(lt),re=o):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),Ws()},[]);return{highlightParent:n,clearParentHighlight:s,lastDragHighlighted:re}},Nu=()=>{const[,t]=j.useAtom(js),[,e]=j.useAtom(_n),[n]=sn(),{clearParentHighlight:s}=Wr(),[r,o]=j.useAtom(Fr),i=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}),Eu(i),s(),i&&i.querySelectorAll("[data-dragging]").forEach(c=>{c.removeAttribute("data-dragging")}),$r(!1),o(r+1)},[t,e,i,s,r,o])};function Eu(t){if(!t)return;t.querySelectorAll("[data-drop-target]").forEach(n=>n.removeAttribute("data-drop-target"))}function Mt(t,e=null){const n=window.getComputedStyle(t),s=e?window.getComputedStyle(e):null,r=n.display,o=s?s.display:null;if(r==="flex"||r==="inline-flex"){const i=n.flexDirection;return i==="column"||i==="column-reverse"?"vertical":"horizontal"}else if(r==="grid"){const i=n.gridAutoFlow,l=n.gridTemplateColumns;return i.includes("column")||l&&l!=="none"&&l!==""&&!l.includes("calc")&&l.split(" ").length<=1?"vertical":"horizontal"}else if(o==="inline-block"||o==="inline")return"horizontal";return"vertical"}const Au=["Heading","Text","Image","Paragraph","Icon","Input","Radio","Checkbox","Select","CustomHTML","TextArea","Divider","Repeater","Video"];function Iu(t){try{return Au.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 Uo(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 xt(t){try{const e=[],n=t.children;for(let s=0;s<n.length;s++){const r=n[s];r.hasAttribute("data-block-id")&&e.push(r)}return e}catch{return[]}}function Xn(t){try{return xt(t).length>0}catch{return!1}}function Tu(t,e,n,s){try{const r=xt(t);if(r.length<2)return null;const o=Pu(r,e,n,s);if(o){const i=Gr(r,o,s);i.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<i.length-1;l++){const c=i[l],u=i[l+1],p=c.getBoundingClientRect(),f=u.getBoundingClientRect();if(s==="vertical"){const m=p.bottom,h=f.top,x=h-m,b=n>=m&&n<=h,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 m=p.right,h=f.left,x=h-m,b=e>=m&&e<=h,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 i=0;i<r.length-1;i++){const l=r[i],c=r[i+1],u=l.getBoundingClientRect(),p=c.getBoundingClientRect();if(s==="vertical"){const f=u.bottom,m=p.top,h=m-f,x=n>=f&&n<=m,b=e>=Math.min(u.left,p.left)&&e<=Math.max(u.right,p.right);if(x&&b&&h>=Je.GAP_THRESHOLD)return{before:l,after:c}}else{const f=u.right,m=p.left,h=m-f,x=e>=f&&e<=m,b=n>=Math.min(u.top,p.top)&&n<=Math.max(u.bottom,p.bottom);if(x&&b&&h>=Je.GAP_THRESHOLD)return{before:l,after:c}}}return null}catch{return null}}function _u(t,e,n,s){try{const r=t.getBoundingClientRect(),o=Je.PARENT_EDGE_PROXIMITY;if(s==="vertical"){if(n<=r.top+o)return"start";if(n>=r.bottom-o)return"end"}else{if(e<=r.left+o)return"start";if(e>=r.right-o)return"end"}return null}catch{return null}}function Bu(t,e,n,s,r){const o=t.getBoundingClientRect();if(r==="vertical"){const l=(n-o.top)/o.height,c=Uo(o.height),u=c/o.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-o.left)/o.width,c=Uo(o.width),u=c/o.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 Ru(t,e,n,s,r){var E,A,I,T;const o=t.getAttribute("data-block-id"),i=t.getAttribute("data-block-type")||"Box";if(!o)return null;let l=t.parentElement;for(;l&&!l.hasAttribute("data-block-id");)l=l.parentElement;const c=o==="canvas"?o:l==null?void 0:l.getAttribute("data-block-id"),u=l?Mt(l):"vertical",p=Mt(t),f=Iu(i),m=!f&&Qe(i,s),h=((E=r.defaultView)==null?void 0:E.scrollY)||0,x=((A=r.defaultView)==null?void 0:A.scrollX)||0;if(o==="canvas"&&Xn(t)){const N=xt(t),S=N[N.length-1];if(S){const C=S.getBoundingClientRect(),B=t.getBoundingClientRect(),P=window.getComputedStyle(t),R=parseFloat(P.paddingLeft)||0,O=parseFloat(P.paddingRight)||0,z=B.width-R-O,G=B.left+x+R;return{position:"after",placeholderOrientation:"horizontal",rect:{top:C.bottom+h,left:G,width:z,height:4},targetElement:S,targetBlockId:S.getAttribute("data-block-id"),targetParentId:"canvas",isEmpty:!1,confidence:1}}}if(m&&!f&&Xn(t)){const N=Tu(t,e,n,p);if(N){const S=N.before.getBoundingClientRect(),C=N.after.getBoundingClientRect(),B=t.getBoundingClientRect(),P=window.getComputedStyle(t),R=parseFloat(P.paddingLeft)||0,O=parseFloat(P.paddingRight)||0,z=xt(t),G=Gr(z,N.before,p);let de=0;if(G.forEach(ue=>{const ne=ue.getBoundingClientRect();ne.height>de&&(de=ne.height)}),p==="vertical"){const ue=B.width-R-O,ne=B.left+x+R;return{position:"after",placeholderOrientation:"horizontal",rect:{top:S.bottom+h,left:ne,width:ue,height:4},targetElement:N.before,targetBlockId:N.before.getAttribute("data-block-id"),targetParentId:o,isGapZone:!0,confidence:1}}else{const ue=S.top+h,ne=de>0?de:Math.max(S.height,C.height);return{position:"after",placeholderOrientation:"vertical",rect:{top:ue,left:S.right+x,width:4,height:ne},targetElement:N.before,targetBlockId:N.before.getAttribute("data-block-id"),targetParentId:o,isGapZone:!0,confidence:1}}}}if(l&&c){const N=_u(l,e,n,u);if(N){const S=l.getBoundingClientRect(),C=window.getComputedStyle(l),B=parseFloat(C.paddingLeft)||0,P=parseFloat(C.paddingRight)||0,R=parseFloat(C.paddingTop)||0,O=parseFloat(C.paddingBottom)||0,z=((I=r.defaultView)==null?void 0:I.scrollY)||0,G=((T=r.defaultView)==null?void 0:T.scrollX)||0,de=u==="vertical"?"horizontal":"vertical",ue=ci(l);if(N==="start"){const ne=xt(l)[0];if(ne){const Ae=ne.getBoundingClientRect();if(u==="vertical"){const Oe=S.width-B-P,W=S.left+G+B;return{position:"before",placeholderOrientation:de,rect:{top:Ae.top+z-2,left:W,width:Oe,height:4},targetElement:ne,targetBlockId:ne.getAttribute("data-block-id"),targetParentId:c,confidence:.9}}else{const Oe=S.top+z+R,W=ue.maxHeight>0?ue.maxHeight:S.height-R-O;return{position:"before",placeholderOrientation:de,rect:{top:Oe,left:Ae.left+G-2,width:4,height:W},targetElement:ne,targetBlockId:ne.getAttribute("data-block-id"),targetParentId:c,confidence:.9}}}}else{const ne=xt(l),Ae=ne[ne.length-1];if(Ae){const Oe=Ae.getBoundingClientRect();if(u==="vertical"){const W=S.width-B-P,$e=S.left+G+B;return{position:"after",placeholderOrientation:de,rect:{top:Oe.bottom+z-2,left:$e,width:W,height:4},targetElement:Ae,targetBlockId:Ae.getAttribute("data-block-id"),targetParentId:c,confidence:.9}}else{const W=S.top+z+R,$e=ue.maxHeight>0?ue.maxHeight:S.height-R-O;return{position:"after",placeholderOrientation:de,rect:{top:W,left:Oe.right+G-2,width:4,height:$e},targetElement:Ae,targetBlockId:Ae.getAttribute("data-block-id"),targetParentId:c,confidence:.9}}}}}}let b=Bu(t,e,n,m,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=Lu(t,l,b.position,y,r),w=b.position==="inside"?o:c;return{position:b.position,placeholderOrientation:y,rect:k,targetElement:t,targetBlockId:o,targetParentId:w??"",isEmpty:b.position==="inside"&&!Xn(t),confidence:b.confidence}}function Pu(t,e,n,s){if(t.length===0)return null;const r=t.filter(l=>{const c=l.getBoundingClientRect();return s==="vertical"?n>=c.top&&n<=c.bottom:e>=c.left&&e<=c.right});if(r.length===0){const l=new Map;t.forEach(p=>{const f=p.getBoundingClientRect(),m=Math.round(s==="vertical"?f.top:f.left);l.has(m)||l.set(m,[]),l.get(m).push(p)});let c=null,u=1/0;l.forEach((p,f)=>{const m=Math.abs(s==="vertical"?n-f:e-f);m<u&&(u=m,c=p)}),c&&r.push(c)}if(r.length===0)return null;let o=r[0],i=1/0;return r.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<i&&(i=f,o=l)}),o}function ci(t){const e=xt(t);if(e.length===0)return{maxWidth:0,maxHeight:0};let n=0,s=0;return e.forEach(r=>{const o=r.getBoundingClientRect();o.width>n&&(n=o.width),o.height>s&&(s=o.height)}),{maxWidth:n,maxHeight:s}}function Gr(t,e,n){const s=e.getBoundingClientRect(),r=5;return t.filter(o=>{const i=o.getBoundingClientRect();return n==="vertical"?Math.abs(i.top-s.top)<=r:Math.abs(i.left-s.left)<=r})}function Lu(t,e,n,s,r){var R,O;const o=t.getBoundingClientRect(),i=window.getComputedStyle(t),l=((R=r.defaultView)==null?void 0:R.scrollY)||0,c=((O=r.defaultView)==null?void 0:O.scrollX)||0,u=parseFloat(i.marginTop)||0,p=parseFloat(i.marginBottom)||0,f=parseFloat(i.marginLeft)||0,m=parseFloat(i.marginRight)||0,h=parseFloat(i.paddingTop)||0,x=parseFloat(i.paddingBottom)||0,b=parseFloat(i.paddingLeft)||0,y=parseFloat(i.paddingRight)||0,k=e==null?void 0:e.getBoundingClientRect(),w=e&&parseFloat(window.getComputedStyle(e).paddingLeft)||0,E=e&&parseFloat(window.getComputedStyle(e).paddingRight)||0,A=e&&parseFloat(window.getComputedStyle(e).paddingTop)||0,I=e&&parseFloat(window.getComputedStyle(e).paddingBottom)||0,T=e?ci(e):{maxHeight:0},N=e?Mt(e):"vertical",S=e?xt(e):[],C=Gr(S,t,N);let B=0,P=0;if(C.forEach(z=>{const G=z.getBoundingClientRect();G.height>B&&(B=G.height),G.width>P&&(P=G.width)}),n==="before")if(s==="horizontal"){const z=k?k.width-w-E:o.width,G=k?k.left+c+w:o.left+c;return{top:o.top+l-u-2,left:G,width:z,height:4}}else{const z=o.top+l,G=N==="horizontal"&&B>0?B:T.maxHeight>0?T.maxHeight:k?k.height-A-I:o.height;return{top:z,left:o.left+c-f-2,width:4,height:G}}else if(n==="after")if(s==="horizontal"){const z=k?k.width-w-E:o.width,G=k?k.left+c+w:o.left+c;return{top:o.bottom+l+p-2,left:G,width:z,height:4}}else{const z=o.top+l,G=N==="horizontal"&&B>0?B:T.maxHeight>0?T.maxHeight:k?k.height-A-I:o.height;return{top:z,left:o.right+c+m-2,width:4,height:G}}else return Xn(t)?Mt(t)==="vertical"?{top:o.bottom+l-x-2,left:o.left+c+b,width:o.width-b-y,height:4}:{top:o.top+l+h,left:o.right+c-y-2,width:4,height:o.height-h-x}:{top:o.top+l+h,left:o.left+c+b,width:o.width-b-y,height:Math.max(o.height-h-x,20)}}const Mu=100,bt=()=>{const[t]=te(),[,e]=U(),{addBlocks:n}=Ne(),s=g.useCallback((o,i,l)=>{for(let m=0;m<o.length;m++){const{_id:h}=o[m];o[m]._id=ve.generateUUID();const x=d.filter(o,{_parent:h});for(let b=0;b<x.length;b++)x[b]._parent=o[m]._id}const c=d.first(o);let u,p;return i&&(u=d.find(t,{_id:i}),o[0]._parent=i,d.forEach(o,m=>{m!=null&&m._parent||(m._parent=i)}),p=i),!(u?Qe(u==null?void 0:u._type,c._type):!0)&&u&&(o[0]._parent=u._parent,p=u._parent),n(o,p??void 0,l),e([c._id]),c},[n,t,e]);return{addCoreBlock:g.useCallback((o,i,l)=>{if(d.has(o,"blocks")){const b=o.blocks;return s(b,i??void 0,l)}const c=ve.generateUUID(),u=X.getDefaultBlockProps(o.type),p={_type:o.type,_id:c,...u,...d.has(o,"_name")&&{_name:o._name},...d.has(o,"partialBlockId")&&{partialBlockId:o.partialBlockId}};let f,m;return i&&(f=d.find(t,{_id:i}),p._parent=i,m=i),!Qe(f==null?void 0:f._type,p._type)&&f&&(p._parent=f._parent,m=f._parent),n([p],m??void 0,l),setTimeout(()=>e([p._id]),Mu),p},[n,s,t,e]),addPredefinedBlock:s}};let at=null;const st=()=>{const[t]=j.useAtom(Ss),e=g.useMemo(()=>{var r;return(t==null?void 0:t.contentDocument)||((r=t==null?void 0:t.contentWindow)==null?void 0:r.document)},[t]),n=g.useCallback(r=>{if(e)if(at&&at.removeAttribute("data-highlighted"),typeof r!="string")r.setAttribute("data-highlighted","true"),at=r;else if(typeof r=="string"){const o=e.querySelector(`[data-block-id="${r}"]`);o&&(o.setAttribute("data-highlighted","true"),at=o)}else at=null},[e]),s=g.useCallback(()=>{at&&(at.removeAttribute("data-highlighted"),at=null)},[]);return{highlightBlock:n,clearHighlight:s,lastHighlighted:at}},Bn=j.atom([]);Bn.debugLabel="selectedStylingBlocksAtom";const Ee=()=>j.useAtom(Bn),Du=()=>{const[t,e]=j.useAtom(js),[n,s]=j.useAtom(_n),[r]=te(),[o]=sn(),{addCoreBlock:i}=bt(),{moveBlocks:l}=Ne(),[,c]=U(),[,u]=Ee(),{clearHighlight:p}=st(),{clearParentHighlight:f}=Wr(),[m,h]=j.useAtom(Fr),x=nt(),b=o==null?void 0:o.contentDocument;return g.useCallback(y=>{if(y.preventDefault(),y.stopPropagation(),$r(!1),$u(b),qo(b),f(),s({isVisible:!1,isValid:!1,position:"inside",placeholderOrientation:"horizontal",isEmpty:!1,top:0,left:0,width:0,height:0}),setTimeout(()=>{f(),qo(b),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 k=n.targetBlockId,w=n.targetParentId;if(!k)return;const{parentId:E,index:A,replaceImageUrl:I}=Ou(r,k,w,n.position,t),T=t._id!==void 0;if(I&&di(t)){x([k],{image:d.get(t,"blocks.0.image")}),setTimeout(()=>{h(m+1)},50);return}if(T)l([t._id],E===null?void 0:E,A),p(),u([]),c([t._id]);else{const N=t._type||t.type,S=t!=null&&t.blocks?d.isFunction(t==null?void 0:t.blocks)?X.syncBlocksWithDefaultProps(t==null?void 0:t.blocks()):t==null?void 0:t.blocks:null;i(N==="PartialBlock"?{blocks:[{_type:N,_id:"partial-block",partialBlockId:t.partialBlockId}]}:(S==null?void 0:S.length)>0?{blocks:[...S]}:{type:N},E,A)}setTimeout(()=>{h(m+1)},50)},[t,n,r,b,i,l,e,s,f,p,c,u,m,h,x])},di=t=>{var o,i;const e=d.has(t,"blocks"),n=t==null?void 0:t.blocks,s=(n==null?void 0:n.length)===1&&((o=n==null?void 0:n[0])==null?void 0:o._type)==="Image",r=!((i=n==null?void 0:n[0])!=null&&i._id);return e&&s&&r};function Ou(t,e,n,s,r){var o,i;try{if(e===n&&((o=r==null?void 0:r.blocks)==null?void 0:o.length)===1&&d.get(r,"blocks.0._type")==="Image"&&((i=d.find(t,{_id:e}))==null?void 0:i._type)==="Image")return{parentId:"",index:-1,replaceImageUrl:!0};if(e==="canvas"||s==="inside"&&e==="canvas")return{parentId:null,index:d.filter(t,h=>!(h!=null&&h._parent)).length};if(s==="inside"){const m=d.filter(t,{_parent:e});return{parentId:e,index:m.length}}const l=!n||n==="canvas",c=l?void 0:n,u=d.filter(t,m=>l?!(m!=null&&m._parent):(m==null?void 0:m._parent)===c),p=u.findIndex(m=>m._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 qo(t){if(!t)return;t.querySelectorAll("[data-drop-target]").forEach(n=>n.removeAttribute("data-drop-target"))}function $u(t){if(!t)return;t.querySelectorAll("[data-dragging]").forEach(n=>{n.removeAttribute("data-dragging")})}function ui(t,e,n){if(!t||!e)return!1;if(t===e)return!0;const s=n.find(o=>o._id===t);if(!s)return!1;let r=s;for(;r._parent;){if(r._parent===e)return!0;const o=n.find(i=>i._id===r._parent);if(!o)break;r=o}return!1}function pi(t,e,n){return!t||!e?!0:!ui(e,t,n)}function Fu(t,e,n){if(!t)return!0;const s=n.find(o=>o._id===e);if(!s)return!0;const r=s._parent;return pi(t,r,n)}const zu=["Heading","Text","Image","Paragraph","Icon","Input","Radio","Checkbox","Select","CustomHTML","TextArea","Divider","Repeater","Video"],ht={EDGE_ZONE:50,MAX_SCROLL_SPEED:10,MIN_SCROLL_SPEED:10},Hu=()=>{const[t]=j.useAtom(js),[e]=sn(),[,n]=j.useAtom(_n),{clearParentHighlight:s,highlightParent:r}=Wr(),[o]=te(),i=e==null?void 0:e.contentDocument,l=g.useRef(null),c=g.useRef(0),u=g.useCallback(f=>{if(!(i!=null&&i.defaultView))return;const m=i.defaultView,h=m.innerHeight,x=m.scrollY,b=i.documentElement.scrollHeight;c.current=f;const y=f,k=h-f;let w=!1,E=null,A=0;if(y<ht.EDGE_ZONE&&x>0?(w=!0,E="up",A=y):k<ht.EDGE_ZONE&&x+h<b&&(w=!0,E="down",A=k),!w&&l.current!==null){cancelAnimationFrame(l.current),l.current=null;return}if(w&&E){const I=1-A/ht.EDGE_ZONE,T=ht.MIN_SCROLL_SPEED+(ht.MAX_SCROLL_SPEED-ht.MIN_SCROLL_SPEED)*I,N=()=>{if(!qt||!m){l.current=null;return}const S=E==="up"?-T:T;m.scrollBy(0,S);const C=m.scrollY,B=C>0,P=C+h<b,R=c.current,O=h-c.current;E==="up"&&B&&R<ht.EDGE_ZONE||E==="down"&&P&&O<ht.EDGE_ZONE?l.current=requestAnimationFrame(N):l.current=null};l.current===null&&(l.current=requestAnimationFrame(N))}},[i]);g.useEffect(()=>()=>{l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)},[]),g.useEffect(()=>{!qt&&l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)},[qt]);const p=g.useCallback(d.throttle(f=>{if(!qt||!t)return;s();const m=Vu(f),{element:h,targetBlockId:x,targetParentId:b}=m;if(!h||!x)return;const y=t._id;if(y&&(x===y||ui(x,y,o)))return;const k=t._type||t.type;if(!k)return;const w=f.clientX,E=f.clientY;if(u(E),!i)return;const A=Ru(h,w,E,k,i);if(!A)return;const I=h.getAttribute("data-block-type")||"Box";let T=!1;const N=zu.includes(I);if(I==="Image"&&k==="Image"&&di(t)){r(x),n({isVisible:!0,isValid:!0,position:A.position,placeholderOrientation:A.placeholderOrientation,isEmpty:!0,top:h.offsetTop,left:A.rect.left,width:h.clientWidth,height:h.clientHeight,targetBlockId:A.targetBlockId,targetParentId:A.targetBlockId});return}if(A.position==="inside"){if(N||y&&!pi(y,x,o))return;T=Qe(I,k)}else{let C=h.parentElement,B="Box";for(;C&&!C.hasAttribute("data-block-id");)C=C.parentElement;if(C&&(B=C.getAttribute("data-block-type")||"Box"),y&&!Fu(y,x,o))return;T=Qe(B,k)}if(!T)return;r(A.targetParentId);const S=A.targetParentId||b||void 0;n({isVisible:!0,isValid:!0,position:A.position,placeholderOrientation:A.placeholderOrientation,isEmpty:A.isEmpty??!1,top:A.rect.top,left:A.rect.left,width:A.rect.width,height:A.rect.height,targetBlockId:A.targetBlockId,targetParentId:S}),Wu(i),A.targetElement.setAttribute("data-drop-target","true")},300),[i,t,n,s,r,o,u]);return g.useCallback(f=>{f.preventDefault(),f.stopPropagation(),p(f)},[p])};function Vu(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 r=e.parentElement;for(;r&&!r.hasAttribute("data-block-id");)r=r.parentElement;const o=(r==null?void 0:r.getAttribute("data-block-id"))||null,i=(r==null?void 0:r.getAttribute("data-block-type"))||"Box",l=Mt(e);return{element:e,targetBlockId:n,targetBlockType:s,targetParentId:o,targetParentType:i,orientation:l}}function Wu(t){if(!t)return;t.querySelectorAll("[data-drop-target]").forEach(n=>n.removeAttribute("data-drop-target"))}function Gu(t){var o;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=((o=document.querySelector(`[data-add-core-block-icon="${n}"]`))==null?void 0:o.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 r=document.createElement("span");return r.className="text-[10px] font-medium text-blue-600 whitespace-nowrap",r.textContent=t.label||t.type||t._name||t._type||"Block",e.appendChild(s),e.appendChild(r),document.body.appendChild(e),e}function Ko(t){t&&t.parentNode&&t.parentNode.removeChild(t)}const Uu=()=>{const[,t]=U(),[,e]=Ee(),{clearHighlight:n}=st(),[,s]=j.useAtom(js),[,r]=j.useAtom(_n),o=g.useRef(null);return g.useCallback((i,l,c=!0)=>{var p;o.current&&(Ko(o.current),o.current=null);const u=c?d.pick(l,["type","blocks","partialBlockId"]):l;if(s(u),i.dataTransfer.setData("text/plain",JSON.stringify({block:u})),i.dataTransfer.effectAllowed="move",!c&&l._id){const f=(p=document.getElementById("canvas-iframe"))==null?void 0:p.contentDocument;if(f){const m=f.querySelector(`[data-block-id="${l._id}"]`);m&&setTimeout(()=>{if(m){const x=m.getBoundingClientRect().height;Mt(m==null?void 0:m.parentElement)==="vertical"&&x>200&&(m.style.height="max-content",m.style.maxHeight="max-content",m.style.minHeight="0",m.style.overflow="hidden",m.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>",m.style.opacity="0.4"),m.style.opacity="0.4",m.setAttribute("data-dragging","true")}},0)}}if(l!=null&&l._type||l!=null&&l.type){const f=Gu(l);o.current=f,i.dataTransfer.setDragImage(f,0,0),setTimeout(()=>{o.current&&(Ko(o.current),o.current=null)},50)}t([]),n(),e([]),oe.publish(K.CLOSE_ADD_BLOCK),$r(!0),r({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,r])},rn=()=>{const t=Uu(),e=Hu(),n=Du(),s=Nu();return{onDragStart:t,onDragOver:e,onDrop:n,onDragEnd:s,isDragging:qt}},qu=()=>{const[t]=j.useAtom(_n);return t},Ye=()=>{const{dragAndDrop:t}=$("flags",{dragAndDrop:!0});return t};let fi,hi;typeof document<"u"&&(fi=document);typeof window<"u"&&(hi=window);const mi=g.createContext({document:fi,window:hi}),rt=()=>g.useContext(mi),{Provider:Ku,Consumer:Ky}=mi,Yu=[{ControlIcon:v.PinTopIcon,dir:"VERTICAL",key:"UP"},{ControlIcon:v.PinBottomIcon,dir:"VERTICAL",key:"DOWN"},{ControlIcon:v.PinLeftIcon,dir:"HORIZONTAL",key:"LEFT"},{ControlIcon:v.PinRightIcon,dir:"HORIZONTAL",key:"RIGHT"}],Xu=(t,e,n)=>{try{if(!t||!n)return"VERTICAL";const s=`[data-block-id='${t}']`,r=n==null?void 0:n.querySelector(s);if(r){const o=n==null?void 0:n.querySelector(`[data-block-id='${e}']`);return Mt(r,o).toUpperCase()}return"VERTICAL"}catch{return"VERTICAL"}},gi=(t,e,n)=>!!(t&&(n==="UP"||n==="LEFT")||e&&(n==="DOWN"||n==="RIGHT")),Ju=(t,e)=>{const[n]=te(),{document:s}=rt(),{moveBlocks:r}=Ne(),o=d.get(t,"_id"),i=d.get(t,"_parent"),l=d.filter(n,x=>i?d.get(x,"_parent")===i:!d.get(x,"_parent")),c=(l==null?void 0:l.length)<=1,u=d.findIndex(l,{_id:o}),p=u<=0,f=u+1===(l==null?void 0:l.length),m=Xu(i,o,s),h=g.useCallback(x=>{gi(p,f,x)||c||(x==="UP"||x==="LEFT"?r([o],i||void 0,u-1):(x==="DOWN"||x==="RIGHT")&&r([o],i||void 0,u+2),e())},[p,f,c,u,o,i,e]);return Xe.useHotkeys("shift+up, shift+down, shift+left, shift+right",({key:x})=>{var b;h((b=x==null?void 0:x.replace("Arrow",""))==null?void 0:b.toUpperCase())},{document:s},[h]),{isOnlyChild:c,isFirstBlock:p,isLastBlock:f,moveBlock:h,orientation:m}},Zu=({block:t,updateFloatingBar:e})=>{const{isOnlyChild:n,isFirstBlock:s,isLastBlock:r,moveBlock:o,orientation:i}=Ju(t,e);return n?null:a.jsx(a.Fragment,{children:Yu.map(({ControlIcon:l,dir:c,key:u})=>i!==c||gi(s,r,u)?null:a.jsx(l,{onClick:()=>o(u),className:"rounded p-px hover:bg-white hover:text-blue-500"},u))})},Ur=()=>{const[t]=te(),[,e]=U(),{addBlocks:n}=Ne();return g.useCallback((s,r=null)=>{const o=[];d.each(s,i=>{const l=t.find(m=>m._id===i);r?r==="root"&&(r=null):r=(l==null?void 0:l._parent)??null;const p=d.filter(t,m=>d.isString(r)?m._parent===r:!m._parent).indexOf(l)+1,f=ar(t,i,r);n(f,r??void 0,p),o.push(d.get(f,"0._id",""))}),e(o)},[t,e])},Qu=j.atom(""),xi=()=>j.useAtom(Qu),bi=j.atom("");bi.debugLabel="inlineEditingActiveAtom";const yi=j.atom(0);yi.debugLabel="inlineEditingItemIndexAtom";const Ft=()=>{const[t,e]=j.useAtom(bi),[n,s]=j.useAtom(yi);return{editingBlockId:t,editingItemIndex:n,setEditingBlockId:e,setEditingItemIndex:s}},vi=j.atom("outline");vi.debugLabel="sidebarActivePanelAtom";const Ns=()=>j.useAtom(vi),ep=({blockId:t,className:e})=>{const n=()=>{t&&oe.publish(K.GOTO_BLOCK_SETTINGS,t)};return a.jsx(v.GearIcon,{className:e,onClick:n})},tp=j.atom(0),ki=j.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 np=["Heading","Paragraph","Text","Link","Span","Button"],sp=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"},wi=t=>t?d.some(t.children,e=>{const n=e;return n.hasAttribute("data-block-id")||wi(n)}):!1,rp=(t,e)=>{if(sp(t))return!0;const n=t==null?void 0:t.getAttribute("data-block-type");return n?np.includes(n):!1},op=()=>{const{editingBlockId:t,setEditingBlockId:e,setEditingItemIndex:n}=Ft();return g.useCallback(s=>{var l;if(s==null||s.preventDefault(),s==null||s.stopPropagation(),t)return;const r=qr(s.target);if(!r||!rp(r)||wi(r))return;const o=r.getAttribute("data-block-id");if(!o)return;const i=r.closest('[data-block-type="Repeater"]');i?(l=i==null?void 0:i.childNodes)==null||l.forEach((c,u)=>{c.contains(r)&&n(u)}):n(-1),e(o)},[t,e,n])},ap=()=>{const{editingBlockId:t}=Ft(),{clearHighlight:e}=st(),[,n]=Ee(),[s]=j.useAtom(ki);return g.useCallback(r=>{if(t)return;r.stopPropagation();const o=qr(r.target);if(!o){e(),n([]),oe.publish(K.CANVAS_BLOCK_SELECTED,[]);return}if(s!==2){if(o!=null&&o.getAttribute("data-block-id")&&(o==null?void 0:o.getAttribute("data-block-id"))==="container"){oe.publish(K.CLEAR_CANVAS_SELECTION);return}if(o!=null&&o.getAttribute("data-block-parent")){const i=o.getAttribute("data-style-prop"),l=o.getAttribute("data-style-id"),c=o.getAttribute("data-block-parent");oe.publish(K.CANVAS_BLOCK_STYLE_SELECTED,{blockId:c,styleId:l,styleProp:i})}else if(o!=null&&o.getAttribute("data-block-id")){const i=o.getAttribute("data-block-id");oe.publish(K.CANVAS_BLOCK_SELECTED,i==="canvas"?[]:[i])}e()}},[t,s,e,n])},ip=()=>{const{editingBlockId:t}=Ft(),{highlightBlock:e}=st();return ke.useThrottledCallback(n=>{if(t)return;const s=qr(n.target);s&&e(s)},[t,e],100)},lp=()=>{const{clearHighlight:t}=st();return g.useCallback(()=>t(),[t])},cp=({children:t})=>{const e=op(),n=ap(),s=ip(),r=lp();return a.jsx("div",{"data-block-id":"canvas",id:"canvas",onClick:n,onDoubleClick:e,onMouseMove:s,onMouseLeave:r,className:"relative h-full max-w-full p-px",children:t})},Ci=(t,e)=>t.querySelector(`[data-block-id="${e}"]`),dp=(t,e)=>t.querySelector(`[data-style-id="${e}"]`),up=()=>{const t=J(),{document:e}=rt(),[n]=Ee(),[s,r]=g.useState([]),[,o]=g.useState([]),{onDragStart:i,onDragEnd:l,isDragging:c}=rn(),[u,p]=g.useState(null),f=Ye(),m=(h,x=0)=>{const{top:b}=h.getBoundingClientRect();return b+x>=0&&b-x<=window.innerHeight};return g.useEffect(()=>{var h;if(t!=null&&t._id&&t.type!=="Multiple"&&e){const x=Ci(e,t._id);x&&(m(x)||(h=e.defaultView)==null||h.scrollTo({top:x.offsetTop,behavior:"smooth"}),r([x]))}},[t==null?void 0:t._id,t==null?void 0:t.type,e]),g.useEffect(()=>{if(!d.isEmpty(n)&&e){const h=dp(e,d.first(n).id);o(h?[h]:[null])}else o([null])},[n,e]),a.jsx("div",{onDragEnd:()=>{p(null),l()},draggable:f&&!!t,onDragStart:h=>{p(s==null?void 0:s[0]),i(h,t,!1)},children:t&&a.jsx(pp,{block:t,isDragging:c&&!!u,selectedBlockElement:s[0]||(c?u:null)})})},pp=({block:t,isDragging:e,selectedBlockElement:n})=>{const s=Cs(),r=Ur(),[,o]=U(),[,i]=xi(),[,l]=Ee(),{hasPermission:c}=qe(),{editingBlockId:u}=Ft(),{document:p}=rt(),f=Ye(),m=$("flags.gotoSettings",!1),h=$("flags.ai",!1),{floatingStyles:x,refs:b,update:y}=Wo.useFloating({placement:"top-start",middleware:[Wo.shift({boundary:p==null?void 0:p.body,limiter:Hs.limitShift({offset:8,mainAxis:!0,crossAxis:!0})}),Hs.flip({boundary:p==null?void 0:p.body,fallbackPlacements:["bottom-start","top-end","bottom-end","inside"]}),Hs.size({boundary:p==null?void 0:p.body,apply({availableWidth:A,availableHeight:I,elements:T}){Object.assign(T.floating.style,{maxWidth:`${Math.max(200,A)}px`,maxHeight:`${Math.max(100,I)}px`})}})],elements:{reference:n}});ke.useResizeObserver(n,()=>y(),n!==null),ke.useResizeObserver(p==null?void 0:p.body,()=>y(),(p==null?void 0:p.body)!==null);const k=d.get(t,"_parent",null),w=d.isEmpty(d.get(t,"_name",""))?d.get(t,"_type",""):d.get(t,"_name","");g.useEffect(()=>{let A=null;return n?(A=setTimeout(()=>y(),500),()=>{A&&clearTimeout(A)}):(y(),()=>{A&&clearTimeout(A)})},[n,t==null?void 0:t._id]);const[,E]=Ns();return!e&&(!n||!t||u)?null:a.jsx(a.Fragment,{children:a.jsx("div",{role:"button",tabIndex:0,ref:b.setFloating,style:x,onClick:A=>{A.stopPropagation(),A.preventDefault()},onMouseEnter:A=>{A.stopPropagation(),i(null)},onKeyDown:A=>A.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:a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center",children:[f&&a.jsx(v.DragHandleDots2Icon,{className:"flex-shrink-0 cursor-grab rounded p-0.5 hover:bg-white/20 active:cursor-grabbing"}),k&&a.jsx(v.ArrowUpIcon,{className:"flex-shrink-0 rounded p-0.5 hover:bg-white/20",onClick:()=>{l([]),o([k])}})]}),a.jsx("div",{className:`w-full ${f?"cursor-grab active:cursor-grabbing":""}`,children:a.jsx("div",{className:"mr-10 w-full items-center space-x-1 px-1 leading-tight",children:w})}),a.jsxs("div",{className:"flex items-center gap-1 pl-1 pr-1.5",children:[c(se.ADD_BLOCK)&&h&&a.jsx(kr,{className:"h-4 w-4 rounded hover:bg-white hover:text-blue-500",onClick:()=>{E("chai-chat-panel"),oe.publish(K.OPEN_AI_PANEL)}}),m&&a.jsx(ep,{blockId:t==null?void 0:t._id,className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500"}),!f&&a.jsx(fu,{block:t,children:a.jsx(v.PlusIcon,{className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500"})}),Cr(d.get(t,"_type",""))&&c(se.ADD_BLOCK)?a.jsx(v.CopyIcon,{className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500",onClick:()=>r([t==null?void 0:t._id])}):null,jr(d.get(t,"_type",""))&&c(se.DELETE_BLOCK)?a.jsx(v.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(se.MOVE_BLOCK)&&a.jsx(Zu,{block:t,updateFloatingBar:y})]})]})})})},fp=`<!doctype html>
|
|
1
|
+
"use strict";var Mc=Object.defineProperty;var Dc=(t,e,n)=>e in t?Mc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var wt=(t,e,n)=>Dc(t,typeof e!="symbol"?e+"":e,n);const a=require("react/jsx-runtime"),B=require("./register-chai-top-bar-DWTuRU53.cjs"),d=require("lodash-es"),Oc=require("@radix-ui/react-dropdown-menu"),k=require("@radix-ui/react-icons"),g=require("react"),X=require("./core-BWQrViOY.cjs"),j=require("jotai"),q=require("./STRINGS-FNnfjF5H.cjs"),Ho=require("@rjsf/utils"),ve=require("./common-functions-B3a4xKt_.cjs"),Se=require("jotai/utils"),ke=require("@react-hookz/web"),Ze=require("./plugin-DO5QAuc1.cjs"),$c=require("tree-model"),Fc=require("undo-manager"),F=require("react-i18next"),zc=require("@radix-ui/react-dialog"),be=require("./apply-binding-nqrhHgIz.cjs"),vr=require("class-variance-authority"),Hc=require("@radix-ui/react-tooltip"),De=require("cmdk"),Vc=require("@radix-ui/react-popover"),gt=require("i18next"),Wc=require("@tiptap/extension-text-style"),Gc=require("@tiptap/extension-highlight"),Uc=require("@tiptap/extension-link"),qc=require("@tiptap/extension-placeholder"),Kc=require("@tiptap/extension-text-align"),Yc=require("@tiptap/extension-underline"),ns=require("@tiptap/react"),Xc=require("@tiptap/starter-kit"),Pa=require("clsx"),La=require("tailwind-merge"),Jc=require("react-colorful"),rr=require("react-dom"),Zc=require("@rjsf/core"),Qc=require("@rjsf/validator-ajv8"),ed=require("@radix-ui/react-accordion"),Ma=require("fuse.js"),td=require("@radix-ui/react-hover-card"),nd=require("@radix-ui/react-label"),sd=require("react-autosuggest"),pe=require("sonner"),rd=require("@radix-ui/react-scroll-area"),od=require("@radix-ui/react-tabs"),ad=require("@radix-ui/react-select"),id=require("@radix-ui/react-alert-dialog"),ld=require("react-arborist"),cd=require("@radix-ui/react-separator"),dd=require("@radix-ui/react-switch"),ud=require("@radix-ui/react-slider"),Da=require("./fonts-B-Xt29pe.cjs");require("nanoid");const Vo=require("himalaya");require("@mhsdesign/jit-browser-tailwindcss");const pd=require("@tailwindcss/aspect-ratio"),fd=require("@tailwindcss/container-queries"),hd=require("@tailwindcss/forms"),md=require("@tailwindcss/typography"),Xe=require("react-hotkeys-hook"),gd=require("./get-chai-builder-tailwind-config-DNp8Vhme.cjs"),At=require("react-error-boundary"),Vn=require("framer-motion"),Hs=require("@floating-ui/dom"),Wo=require("@floating-ui/react-dom"),xd=require("react-wrap-balancer");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 ge=Re(Oc),D=Re(g),ie=Re(zc),Jt=Re(Hc),vn=Re(Vc),Pt=Re(ed),bs=Re(td),Oa=Re(nd),It=Re(rd),$t=Re(od),me=Re(ad),Pe=Re(id),$a=Re(cd),or=Re(dd),un=Re(ud);function Lt({className:t,...e}){return a.jsx("div",{className:B.cn("animate-pulse rounded-md bg-primary/10",t),...e})}const kr=({className:t="h-full w-full",onClick:e=d.noop})=>a.jsx("svg",{className:t,viewBox:"0 0 256 256",fill:"currentColor",onClick:e,children:a.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"})}),et=ge.Root,tt=ge.Trigger,bd=D.forwardRef(({className:t,inset:e,children:n,...s},r)=>a.jsxs(ge.SubTrigger,{ref:r,className:B.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,a.jsx(k.ChevronRightIcon,{className:"ml-auto h-4 w-4"})]}));bd.displayName=ge.SubTrigger.displayName;const yd=D.forwardRef(({className:t,...e},n)=>a.jsx(ge.SubContent,{ref:n,className:B.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}));yd.displayName=ge.SubContent.displayName;const Ge=D.forwardRef(({className:t,sideOffset:e=4,...n},s)=>a.jsx(ge.Portal,{children:a.jsx(ge.Content,{ref:s,sideOffset:e,className:B.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})}));Ge.displayName=ge.Content.displayName;const le=D.forwardRef(({className:t,inset:e,...n},s)=>a.jsx(ge.Item,{ref:s,className:B.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}));le.displayName=ge.Item.displayName;const Fa=D.forwardRef(({className:t,children:e,checked:n,...s},r)=>a.jsxs(ge.CheckboxItem,{ref:r,className:B.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:[a.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:a.jsx(ge.ItemIndicator,{children:a.jsx(k.CheckIcon,{className:"h-4 w-4"})})}),e]}));Fa.displayName=ge.CheckboxItem.displayName;const vd=D.forwardRef(({className:t,children:e,...n},s)=>a.jsxs(ge.RadioItem,{ref:s,className:B.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:[a.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:a.jsx(ge.ItemIndicator,{children:a.jsx(k.CircleIcon,{className:"h-2 w-2 fill-current"})})}),e]}));vd.displayName=ge.RadioItem.displayName;const za=D.forwardRef(({className:t,inset:e,...n},s)=>a.jsx(ge.Label,{ref:s,className:B.cn("px-2 py-1.5 text-sm font-semibold",e&&"pl-8",t),...n}));za.displayName=ge.Label.displayName;const wr=D.forwardRef(({className:t,...e},n)=>a.jsx(ge.Separator,{ref:n,className:B.cn("-mx-1 my-1 h-px bg-muted",t),...e}));wr.displayName=ge.Separator.displayName;const K={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=X.getRegisteredChaiBlock(t);return n&&n.canAcceptBlock?n.canAcceptBlock(e):!1},ss=t=>{const e=X.getRegisteredChaiBlock(t);return e?d.has(e,"canAcceptBlock"):!1},kd=(t,e)=>{const n=X.getRegisteredChaiBlock(e);return n&&n.canBeNested?n.canBeNested(t):!0},Cr=t=>{const e=X.getRegisteredChaiBlock(t);return e&&e.canDuplicate?e.canDuplicate():!0},jr=t=>{const e=X.getRegisteredChaiBlock(t);return e&&e.canDelete?e.canDelete():!0};class wd{constructor(){wt(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(r=>r(n))}}const oe=new wd;function Ha(t,e,n){const s=d.filter(t,o=>o._parent===e),r=[];for(let o=0;o<s.length;o++)if(d.filter(t,{_parent:s[o]._id}).length>0){const i=ve.generateUUID();r.push({...s[o],oldId:s[o]._id,_id:i,_parent:n}),r.push(d.flatten(Ha(t,s[o]._id,i)))}else r.push({...s[o],oldId:s[o]._id,_id:ve.generateUUID(),_parent:n});return d.flatten(r)}function Sr(t){const e={};t.forEach(s=>{e[s._id]={...s,children:[]}});const n=[];return t.forEach(s=>{if(s._parent){const r=e[s._parent];r&&r.children.push(e[s._id])}else n.push(e[s._id])}),n}const ar=(t,e,n=null)=>{let s=d.find(t,{_id:e});s={...s,oldId:s._id,_id:ve.generateUUID()},n!==(s==null?void 0:s._parent)&&(s={...s,_parent:n});const r=[s];return d.filter(t,{_parent:e}).length>0&&r.push(d.flatten(Ha(t,e,s._id))),d.flatten(r)},je=j.atom([]);je.debugLabel="presentBlocksAtom";const Va=j.atom(t=>{const e=t(je);return Sr([...e])});Va.debugLabel="treeDSBlocks";const En=Se.splitAtom(je);En.debugLabel="pageBlocksAtomsAtom";const Cd=j.atom("");Cd.debugLabel="builderActivePageAtom";const jd=j.atom(-1);jd.debugLabel="destinationDropIndexAtom";const Wa=j.atom([]);Wa.debugLabel="buildingBlocksAtom";const Sd=j.atom(t=>{const e=t(Wa);return d.filter(e,n=>d.has(n,"blockId"))});Sd.debugLabel="globalBlocksAtom";const Qt=j.atom([]);Qt.debugLabel="structureErrorsAtom";const Nr=j.atom(!0);Nr.debugLabel="structureValidationValidAtom";const Er=j.atom(!1);Er.debugLabel="hasStructureErrorsAtom";const Ar=j.atom(!1);Ar.debugLabel="hasStructureWarningsAtom";const Ga=j.atom(t=>t(Qt).filter(n=>n.severity==="error").length);Ga.debugLabel="structureErrorCountAtom";const Ua=j.atom(t=>t(Qt).filter(n=>n.severity==="warning").length);Ua.debugLabel="structureWarningCountAtom";const qa=j.atom(t=>{const e=t(Qt),n={};return e.forEach(s=>{s.blockId&&(n[s.blockId]||(n[s.blockId]=[]),n[s.blockId].push(s))}),n});qa.debugLabel="structureErrorsByBlockAtom";const Ve=j.getDefaultStore(),Nd=()=>Ve.get(je),$=(t,e)=>{const n=j.useAtomValue(Rr);return g.useMemo(()=>d.get(n,t,e),[n,t,e])},Ka=j.atom("");Ka.debugLabel="selectedLanguageAtom";const Te=()=>{const t=$("languages",[]),e=$("fallbackLang","en"),[n,s]=j.useAtom(Ka),r=o=>{s(e===o?"":o)};return{languages:t==null?void 0:t.filter(o=>o!==e),fallbackLang:e,selectedLang:n,setSelectedLang:r}},ys=j.atom([]);ys.debugLabel="selectedBlockIdsAtom";const Ir=j.atom(t=>{const e=t(je),n=t(ys);return d.map(d.filter(e,({_id:s})=>d.includes(n,s)),s=>({...s}))});Ir.debugLabel="selectedBlocksAtom";const vs=j.atom(t=>{const e=t(Ir);if(e.length!==0&&e.length===1)return e[0]});vs.debugLabel="selectedBlockAtom";const J=()=>j.useAtomValue(vs),Ed=t=>d.get(t,"_parent",null),Ad=j.atom(t=>{const e=t(Ir),n=d.map(e,Ed);return d.filter(t(je),s=>d.includes(n,s._id))});Ad.debugLabel="selectedBlocksParentsAtom";const Ya=j.atom(()=>!1);Ya.debugLabel="selectedBlockFlexChildAtom";const Xa=j.atom(()=>!1);Xa.debugLabel="selectedBlockGridChildAtom";const Tr=j.atom("");Tr.debugLabel="styleStateAtom";const Ja=Se.atomWithStorage("styleBreakpoint","xs");Ja.debugLabel="styleBreakpointAtom";const Id=()=>({flexChild:j.useAtomValue(Ya),gridChild:j.useAtomValue(Xa)}),Td=j.atom(t=>{const e=t(vs),n=t(je);let s=e;const r=[e];do{const o=n.find(({_id:i})=>i===(s==null?void 0:s._parent));s=o,o&&r.push(o)}while(s!=null&&s._parent);return r}),_d=()=>d.compact(j.useAtomValue(Td)),U=()=>{const[t,e]=j.useAtom(ys),n=g.useCallback(s=>{e(r=>d.includes(r,s)?d.without(r,s):[...r,s])},[e]);return[t,e,n]},Za=(t,e,n)=>{const s=X.getRegisteredChaiBlock(d.get(n,"_type",""));if(!s)return t;const r={...t};return d.forEach(d.keys(t),o=>{if(d.includes(d.get(s,"i18nProps",[]),o)&&!d.isEmpty(e)){const i=`${o}-${e}`;d.set(r,i,t[o]),d.unset(r,o)}}),r},nt=()=>{const{updateBlocks:t}=Ne(),{selectedLang:e}=Te(),n=J();return g.useCallback((s,r,o)=>{const i=Za(r,e,n);t(s,i,o)},[e,n,t])},Bd=()=>{const{updateMultipleBlocksProps:t}=Ne();return g.useCallback(e=>{t(e)},[t])},Rd=()=>{const{updateBlocksRuntime:t}=Ne();return g.useCallback(async(e,n,s=30)=>{const r=d.keys(d.omit(n,["_id"]));for(const o of r){const i=n[o];if(d.isString(i)){const l=d.chunk(i.split(""),12);let c="";t([e],{[o]:""});for(let u=0;u<l.length;u++)c+=l[u].join(""),t([e],{[o]:c}),await new Promise(p=>setTimeout(p,s))}}},[t])},Qa=()=>{const{updateMultipleBlocksProps:t}=Ne(),e=Rd();return g.useCallback(async n=>{for(const s of n)await e(s._id,s);t(n)},[e,t])},_r=()=>{const{updateBlocksRuntime:t}=Ne(),{selectedLang:e}=Te(),n=J();return g.useCallback((s,r)=>{const o=Za(r,e,n);t(s,o)},[e,n,t])},Br=j.atom({});Br.debugLabel="blockRepeaterDataAtom";const ei=()=>j.useAtom(Br),Pd=(t,e,n,s)=>{const[r,o]=g.useState({status:"idle",props:{},error:void 0}),i=_r(),l=$("getBlockAsyncProps",async h=>({})),c=j.useSetAtom(Br),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,`{{${q.COLLECTION_PREFIX}`),f=(t==null?void 0:t._type)!=="Repeater"&&e==="live";return g.useEffect(()=>{if(e==="mock"){if(d.isFunction(s)){o(x=>({...x,status:"loading",props:{}}));const h=s({block:t});if(!Ho.isObject(h))throw new Error("mockDataProvider should return an object");o(x=>({...x,status:"loaded",props:h}))}return}e==="live"&&(!p&&!f||(o(h=>({...h,status:"loading",props:{}})),l({block:t}).then((h={})=>{p?(c(x=>({...x,[t._id]:{status:"loaded",props:d.get(h,"items",[]),repeaterItems:t.repeaterItems}})),o(x=>({...x,status:"loaded",props:{totalItems:d.get(h,"totalItems")}})),i([t._id],{totalItems:d.get(h,"totalItems")})):o(x=>({...x,status:"loaded",props:Ho.isObject(h)?h:{}}))}).catch(h=>{p?(c(x=>({...x,[t._id]:{status:"error",error:h,props:[]}})),o(x=>({...x,status:"error",error:h,props:{}}))):o(x=>({...x,status:"error",error:h,props:{}}))})))},[t==null?void 0:t._id,u,p,f,s,e]),{$loading:d.get(r,"status")==="loading",...t?d.get(r,"props",{}):{}}},Rr=j.atom(null);Rr.debugLabel="chaiBuilderPropsAtom";const Ld=j.atom({});Ld.debugLabel="chaiExternalDataAtom";const Md=j.atom({});Md.debugLabel="chaiRjsfFieldsAtom";const Dd=j.atom({});Dd.debugLabel="chaiRjsfWidgetsAtom";const Od=j.atom({});Od.debugLabel="chaiRjsfTemplatesAtom";const Pr=j.atom({});Pr.debugLabel="chaiPageExternalDataAtom";const en=j.atom({});en.debugLabel="chaiDesignTokensAtom";const tn=()=>{const[t]=ei(),e=g.useMemo(()=>{const s={};return Object.entries(t).forEach(([r,o])=>{o.status==="loaded"&&o.repeaterItems&&(s[o.repeaterItems.replace("}}",`/${r}`).replace("{{","")]=o.props)}),s},[t]);return{...j.useAtomValue(Pr),...e}},ks=j.atom(0),ti=j.atom({isOpen:!1,blockId:null}),$d=[{name:"no-nested-div-in-p",description:"Prevents div elements from being nested inside paragraph elements",validate:(t,e)=>{const n=[],s=(r,o=!1)=>{r.forEach(i=>{const l=i._type==="Paragraph";i._type==="Box"&&o&&n.push({id:`div-in-paragraph-${i._id}`,message:"Box (div) cannot be nested inside Paragraph elements",severity:"error",blockId:i._id}),i.children&&i.children.length>0&&s(i.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=(o,i=!1,l=[])=>{o.forEach(c=>{const u=[...l,c._id],p=c._type==="Link",f=c._type==="Button"&&c.link&&c.link.href&&c.link.href.trim()!=="",m=p||f;if(m&&i){const h=p?"Link":"Button with href";n.push({id:`nested-interactive-tree-${c._id}`,message:`${h} 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,m,u)})},r=o=>{o.filter(l=>l._type==="Link"||l._type==="Button"&&l.link&&l.link.href&&l.link.href.trim()!=="").forEach(l=>{if(l._parent){const c=o.find(m=>m._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 m=l._type==="Link"?"Link":"Button with href",h=u?"Link":"Button with href";n.push({id:`nested-interactive-parent-${l._id}`,message:`${m} cannot be nested inside ${h}`,severity:"error",blockId:l._id})}let f=c;for(;f&&f._parent;){const m=o.find(h=>h._id===f._parent);if(m){const h=m._type==="Link",x=m._type==="Button"&&m.link&&m.link.href&&m.link.href.trim()!=="";if(h||x){const b=l._type==="Link"?"Link":"Button with href",y=h?"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=m}}})};return s(e),r(t),n}},{name:"listitem-in-list",description:"Ensures ListItems are only inside List containers",validate:(t,e)=>{const n=[],s=(r,o=null)=>{r.forEach(i=>{i._type==="ListItem"&&o!=="List"&&n.push({id:`listitem-outside-list-${i._id}`,message:"List Item must be inside a List container",severity:"error",blockId:i._id}),i.children&&i.children.length>0&&s(i.children,i._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=(r,o=[])=>{r.forEach(i=>{const l=[...o,i._type];if(i._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-${i._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:i._id})}i._type==="TableRow"&&!l.slice(0,-1).includes("Table")&&n.push({id:`table-row-outside-table-${i._id}`,message:"Table Row must be inside a Table (Table Head or Table Body)",severity:"error",blockId:i._id}),(i._type==="TableHead"||i._type==="TableBody")&&!l.slice(0,-1).includes("Table")&&n.push({id:`table-section-outside-table-${i._id}`,message:"Table Head/Body must be inside a Table",severity:"error",blockId:i._id}),i.children&&i.children.length>0&&s(i.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=(r,o=!1)=>{r.forEach(i=>{const l=i._type==="Button";l&&o&&n.push({id:`nested-button-${i._id}`,message:"Button cannot be nested inside another button",severity:"error",blockId:i._id}),i.children&&i.children.length>0&&s(i.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=(r,o=[])=>{r.forEach(i=>{const l=i._type==="Paragraph";if(l&&o.length>0&&n.push({id:`nested-paragraph-${i._id}`,message:"Paragraph cannot be nested inside another paragraph",severity:"error",blockId:i._id}),i.children&&i.children.length>0){const c=l?[...o,i._id]:o;s(i.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=[],r=(o,i=[])=>{o.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:[...i,l._id]})}l.children&&l.children.length>0&&r(l.children,[...i,l._id])})};r(e);for(let o=1;o<s.length;o++){const i=s[o],l=s[o-1];i.level>l.level+1&&n.push({id:`heading-level-skip-${i.blockId}`,message:`Heading level skipped: h${l.level} followed by h${i.level}. Consider using h${l.level+1}`,severity:"warning",blockId:i.blockId})}return n}}],Fd=[{name:"image-alt-text",description:"Warns if images are missing alt text",validate:(t,e)=>{const n=[],s=r=>{r.forEach(o=>{o._type==="Image"&&!o.alt&&n.push({id:`image-missing-alt-${o._id}`,message:"Image should have alt text for accessibility",severity:"warning",blockId:o._id}),o.children&&o.children.length>0&&s(o.children)})};return s(e),n}},{name:"button-accessibility",description:"Ensures buttons have accessible labels",validate:(t,e)=>{const n=[],s=r=>{r.forEach(o=>{o._type==="Button"&&(o.content||o.children&&o.children.length>0||n.push({id:`button-no-label-${o._id}`,message:"Button should have accessible content (text or icon)",severity:"warning",blockId:o._id})),o.children&&o.children.length>0&&s(o.children)})};return s(e),n}}];class zd{constructor(){wt(this,"rules",[...$d])}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(...Fd)}getRuleNames(){return this.rules.map(e=>e.name)}}const Vs=new zd,Lr=(t={})=>{const e=$("flags.validateStructure",!0),n=j.useSetAtom(Qt),s=j.useSetAtom(Nr),r=j.useSetAtom(Er),o=j.useSetAtom(Ar),i=g.useCallback(c=>{const u=c;if(!e||!u||u.length===0)return;const p=Sr(u),f=[];let m=Vs.getRules();t.enableAccessibilityRules&&(Vs.enableAccessibilityRules(),m=Vs.getRules()),t.customRules&&t.customRules.length>0&&m.push(...t.customRules),m.forEach(y=>{try{const v=y.validate(u,p);f.push(...v)}catch(v){console.error(`Error running structure rule "${y.name}":`,v)}});const h=f.filter(y=>y.severity==="error").length>0,x=f.filter(y=>y.severity==="warning").length>0,b=!h;n(f),s(b),r(h),o(x)},[e,t,n,s,r,o]);return ke.useDebouncedCallback(i,[e,t,n,s,r,o],1e3)},Hd=["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"],ir={bodyFont:"Inter",headingFont:"Inter",roundedCorners:5,primaryColor:"#570df8",secondaryColor:"#f002b8",bodyBgDarkColor:"#031022",bodyBgLightColor:"#fcfcfc",bodyTextDarkColor:"#ffffff",bodyTextLightColor:"#000000"},Vd=j.atom(ir);j.atom(null);const Wd=()=>{const[t,e]=j.useAtom(Vd);return[d.isObject(t)?{...ir,...t}:ir,e]},Gd=j.atom(null),Ud=()=>({currentPage:j.useAtomValue(Gd)}),qd=d.memoize(t=>{const e=X.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))}),Kd=()=>{const[t]=Wd(),{currentPage:e}=Ud(),[n]=te();return g.useCallback(()=>{const s=d.map(n,r=>d.omit(r,qd(r._type)));return{currentPage:e,blocks:s}},[t,e,n])},ni=j.atom(!1),si=()=>j.useAtom(ni),qe=()=>{const t=$("permissions",null);return{hasPermission:g.useCallback(n=>t?t.includes(n):!0,[t])}},Yd=(t=Ze.defaultThemeOptions)=>{const e=Ze.defaultThemeValues;return t.fontFamily&&(e.fontFamily=Object.entries(t.fontFamily).reduce((n,[s,r])=>({...n,[s.replace("font-","")]:r}),e.fontFamily)),e.borderRadius=t.borderRadius,t.colors&&(e.colors=t.colors.reduce((n,s)=>(Object.entries(s.items).forEach(([r,o])=>{r in n&&(n[r]=o)}),n),e.colors)),e},Xd=j.atom({}),An=()=>{const t=In(),e=g.useMemo(()=>Yd(t),[t]),n=$("theme",{}),[s,r]=j.useAtom(Xd);return[g.useMemo(()=>({...e,...!d.isEmpty(n)&&n,...!d.isEmpty(s)&&s}),[e,n,s]),r]},In=()=>{const t=$("themeOptions",n=>n);return g.useMemo(()=>t(Ze.defaultThemeOptions),[t])},Jd=j.atom("block"),Mr=()=>j.useAtom(Jd),Zd=j.atom("settings"),ri=()=>j.useAtom(Zd),ws=j.atom("SAVED");ws.debugLabel="builderSaveStateAtom";const Qd=(t,e)=>e?t.some(n=>{if(!(n!=null&&n._type)||n._type==="PartialBlock")return!1;try{const s=X.getRegisteredChaiBlock(n._type);return s?(d.has(s,"i18nProps")?s.i18nProps??[]:[]).some(o=>{const i=`${o}-${e}`;return!n[i]||d.isEmpty(n[i])}):!1}catch(s){return console.warn(`Failed to get block definition for type: ${n._type}`,s),!1}}):!1,nn=()=>{const[t,e]=j.useAtom(ws),n=$("onSave",async v=>{}),s=$("onSaveStateChange",d.noop),r=Kd(),[o]=An(),{hasPermission:i}=qe(),{selectedLang:l,fallbackLang:c}=Te(),[u]=si(),p=j.useAtomValue(en),f=Lr(),[,m]=j.useAtom(ks),h=()=>{const v=r();return!l||l===c?!1:Qd(v.blocks||[],l)},x=g.useCallback(v=>!v&&(!i("save_page")||!u)||!v&&t==="SAVED",[i,u,t]);return{savePage:ke.useThrottledCallback(async(v=!1,w=!1)=>{if(x(w))return;const N=r();return N!=null&&N.blocks&&f(N.blocks),e("SAVING"),s("SAVING"),m(0),await n({autoSave:v,blocks:N.blocks,theme:o,needTranslations:h(),designTokens:p}),setTimeout(()=>{e("SAVED"),s("SAVED")},100),!0},[x,r,e,p,o,m,n,s,u,f],3e3),savePageAsync:async(v=!1)=>{if(x(v))return;e("SAVING"),s("SAVING");const w=r();return m(0),await n({autoSave:!0,blocks:w.blocks,theme:o,needTranslations:h(),designTokens:p}),setTimeout(()=>{e("SAVED"),s("SAVED")},100),!0},saveState:t,setSaveState:e,needTranslations:h}},eu=()=>{const{savePage:t,saveState:e}=nn(),n=$("autoSave",!0),s=$("autoSaveActionsCount",10),[r]=j.useAtom(ks);g.useEffect(()=>{n&&(e==="SAVED"||e==="SAVING"||r>=s&&t(!0))},[n,t,e,r,s])},Dr=()=>{const[,t]=j.useAtom(ks),{setSaveState:e}=nn();return g.useCallback(()=>{t(n=>n+1),e(n=>n!=="UNSAVED"?"UNSAVED":n)},[t,e])};function tu(t,e,n,s){const r=[...e];let o=[...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 m={_id:ve.generateUUID(),_parent:n,_type:"Text",content:u.content};Object.keys(u).forEach(h=>{h.startsWith("content-")&&(m[h]=u[h])}),r.unshift(m),o=o.map(h=>{if(h._id===n){const x={...h,content:""};return Object.keys(x).forEach(b=>{b.startsWith("content-")&&(x[b]="")}),x}return h})}}let i=o.filter(u=>!u._parent);n&&(i=o.filter(u=>u._parent===n));const l=s!==void 0&&!isNaN(s)&&s>-1?Math.min(s,i.length):i.length;let c=o.length;for(let u=0,p=0;u<o.length;u++)if(n!==void 0?o[u]._parent===n:!o[u]._parent){if(p===l){c=u;break}p++}return!n&&s!==void 0&&s>=i.length&&(c=o.length),[...o.slice(0,c),...r,...o.slice(c)]}function nu(t){return Sr(t)}function su(t){let e=[];return t.walk(n=>(delete n.model.children,e.push(n.model),!0)),e}function Go(t,e){return t.first(n=>n.model._id===e)||null}function ru(t,e,n,s){var u,p;const r=Go(t,e),o=Go(t,n);if(!r||!o)return!1;o.children||(o.model.children=[]);let i=(u=o==null?void 0:o.children)==null?void 0:u.findIndex(f=>f.model._id===e);r.drop(),i=Math.max(i,0);const c=(((p=r==null?void 0:r.model)==null?void 0:p._parent)||"root")===n&&i<=s?s-1:s;try{o.addChildAtIndex(r,c)}catch(f){return console.error("Error adding child to parent:",f),!1}return!0}function ou(t,e){if(!e||!e._parent)return t;const n=e._parent,s=t.find(o=>o._id===n);if(!s)return t;const r=t.filter(o=>o._parent===n);if(r.length===2){const o=r.find(i=>i._id!==e._id);if(o&&o._type==="Text"&&"content"in s)return t.map(l=>{if(l._id===n){const c={...l,content:o.content};return Object.keys(o).forEach(u=>{u.startsWith("content-")&&(c[u]=o[u])}),c}return l}).filter(l=>l._id!==o._id)}return t}function au(t,e,n){if(!n||n==="root")return t;const s=t.find(r=>r._id===n);if(!s)return t;if(s.content!==void 0&&s.content!==""&&!t.some(o=>o._parent===n&&o._id!==e._id)){const i={_id:ve.generateUUID(),_parent:n,_type:"Text",content:s.content};Object.keys(s).forEach(u=>{u.startsWith("content-")&&(i[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),i,...l.slice(c)]:[i,...l]}return t}function iu(t,e,n,s){if(!e)return t;const r=t.find(u=>u._id===e);if(!r)return t;let o=ou(t,r);const i=n||"root",c=new $c().parse({_id:"root",children:nu(o)});if(ru(c,e,i,s)){let u=su(c);const p=u.find(f=>f._id===e);return p&&(p._parent=i==="root"?null:i),u.shift(),n&&(u=au(u,r,n)),u}return o}const pn=new BroadcastChannel("chaibuilder"),oi=()=>{const t=$("pageId","chaibuilder_page");return{postMessage:ke.useDebouncedCallback(n=>pn.postMessage({...n,pageId:t}),[t],200)}},lu=()=>{const[,t]=te(),e=$("pageId","chaibuilder_page"),{updateBlocksProps:n}=ai();g.useEffect(()=>(pn.onmessageerror=s=>{console.log("error",s)},pn.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)},()=>{pn.onmessage=null,pn.onmessageerror=null}),[t,e])},Or=(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(m=>m._id!==l);if(f&&f._type==="Text"){const m=n.find(h=>h._id===u);m&&"content"in m&&(n=n.map(h=>{if(h._id===u){const x={...h,content:f.content};return Object.keys(f).forEach(b=>{b.startsWith("content-")&&(x[b]=f[b])}),x}return h}),s.push(f._id))}}});const r=[...e,...s],o=[],i=d.filter(n,l=>d.includes(r,l._id)||d.includes(r,l._parent)?(o.push(l._id),!1):!0);return d.isEmpty(o)?i:Or(i,o)},Cs=()=>{const[t]=te(),[e,n]=U(),{setNewBlocks:s}=Ne(),{hasPermission:r}=qe();return g.useCallback(o=>{var l;if(!r(se.DELETE_BLOCK))return;const i=((l=d.find(t,{_id:o[0]}))==null?void 0:l._parent)||null;s(Or(t,o)),setTimeout(()=>n(i?[i]:[]),200)},[t,n,e,r])},cu=j.atom(null,(t,e,{id:n,props:s})=>{const r=t(En),o=d.find(r,i=>t(i)._id===n);return o?e(o,{...t(o),...s}):null}),du=()=>j.useSetAtom(cu),uu=t=>Se.useAtomCallback(g.useCallback((e,n,s)=>{const r=e(t);if(!r||!r.length)return console.warn("No blocks available in splitAtoms"),null;const o=d.find(r,i=>e(i)._id===(d.isString(s)?s:e(s)._id));return o||(console.warn(`Block with id ${s} not found`),null)},[t]),{store:Ve}),ai=()=>{const[,t]=te(),{postMessage:e}=oi(),n=du(),s=Lr(),r=Dr();return{setNewBlocks:o=>{t(o),e({type:"blocks-updated",blocks:o})},addBlocks:(o,i,l)=>{t(c=>{const u=tu(c,o,i,l);return e({type:"blocks-updated",blocks:u}),s(u),r(),u})},removeBlocks:o=>{t(i=>{const l=Or(i,o);return e({type:"blocks-updated",blocks:l}),s(l),r(),l})},moveBlocks:(o,i,l)=>{t(c=>{let u=[...c];for(let p=0;p<o.length;p++)u=iu(u,o[p],i,l);return d.each(o,p=>{const f=d.find(u,m=>m._id===p);f&&n({id:p,props:{_parent:f._parent||null}})}),e({type:"blocks-updated",blocks:u}),s(u),r(),u})},updateBlocksProps:o=>{o.forEach(i=>{const l=d.omit(i,"_id");n({id:i._id,props:l})}),e({type:"blocks-props-updated",blocks:o}),r()}}},Ke=new Fc;Ke.setLimit(50);const pu=j.atom({canUndo:!1,canRedo:!1}),Tn=()=>{const[,t]=j.useAtom(ws),[e,n]=j.useAtom(pu),s=$("onSaveStateChange",d.noop),r=g.useCallback(()=>{const u={canUndo:Ke.hasUndo(),canRedo:Ke.hasRedo()};n(u),t("UNSAVED"),s("UNSAVED")},[n,t,s]);g.useEffect(()=>(Ke.setCallback(r),()=>{Ke.setCallback(d.noop)}),[r]);const o=g.useCallback(u=>{Ke.add(u),r()},[r]),i=g.useCallback(()=>{Ke.undo(),r()},[r]),l=g.useCallback(()=>{Ke.redo(),r()},[r]),c=g.useCallback(()=>{Ke.clear(),n({canUndo:!1,canRedo:!1})},[n]);return g.useMemo(()=>({add:o,undo:i,redo:l,hasUndo:()=>e.canUndo,hasRedo:()=>e.canRedo,clear:c}),[o,i,l,e.canUndo,e.canRedo,c])},te=()=>j.useAtom(je),Ne=()=>{const{add:t}=Tn(),{setNewBlocks:e,addBlocks:n,removeBlocks:s,moveBlocks:r,updateBlocksProps:o}=ai();return{moveBlocks:(h,x,b)=>{const y=Ve.get(je),v=d.map(h,N=>{const I=y.find(A=>A._id===N)._parent||null,S=y.filter(A=>I?A._parent===I:!A._parent).map(A=>A._id).indexOf(N);return{_id:N,oldParent:I,oldPosition:S}}),w=v.find(({_id:N})=>N===h[0]);w&&w.oldParent===x&&w.oldPosition===b||(r(h,x??null,b),t({undo:()=>d.each(v,({_id:N,oldParent:E,oldPosition:I})=>{r([N],E??null,I)}),redo:()=>r(h,x??null,b)}))},addBlocks:(h,x,b)=>{n(h,x,b),t({undo:()=>s(d.map(h,"_id")),redo:()=>n(h,x,b)})},removeBlocks:h=>{var w;const x=Ve.get(je),b=(w=d.first(h))==null?void 0:w._parent,v=x.filter(N=>b?N._parent===b:!N._parent).indexOf(d.first(h));s(d.map(h,"_id")),t({undo:()=>n(h,b??void 0,v),redo:()=>s(d.map(h,"_id"))})},updateBlocks:(h,x,b)=>{const y=Ve.get(je);let v=[];if(b)v=d.map(h,w=>({_id:w,...b}));else{const w=d.keys(x);v=d.map(h,N=>{const E=y.find(_=>_._id===N),I={_id:N};return d.each(w,_=>I[_]=E[_]),I})}o(d.map(h,w=>({_id:w,...x}))),t({undo:()=>o(v),redo:()=>o(d.map(h,w=>({_id:w,...x})))})},updateBlocksRuntime:(h,x)=>{o(d.map(h,b=>({_id:b,...x})))},setNewBlocks:h=>{const x=Ve.get(je);e(h),t({undo:()=>e(x),redo:()=>e(h)})},updateMultipleBlocksProps:h=>{const x=Ve.get(je);let b=[];b=d.map(h,y=>{const v=d.keys(y),w=x.find(E=>E._id===y._id),N={};return d.each(v,E=>N[E]=w==null?void 0:w[E]),N}),o(h),t({undo:()=>o(b),redo:()=>o(h)})}}},fu=({block:t,children:e})=>{const{t:n}=F.useTranslation(),[s]=te(),{hasPermission:r}=qe(),o=d.get(t,"_id"),i=d.get(t,"_parent"),l=d.filter(s,f=>i?d.get(f,"_parent")===i:!d.get(f,"_parent")),c=ss(d.get(t,"_type","")),u=d.findIndex(l,{_id:o}),p=f=>{if(f==="CHILD")oe.publish(K.OPEN_ADD_BLOCK,t);else{const m={_id:i||"",position:l==null?void 0:l.length};f==="BEFORE"?m.position=Math.max(u,0):f==="AFTER"&&(m.position=u+1),oe.publish(K.OPEN_ADD_BLOCK,m)}};return r(se.ADD_BLOCK)?a.jsxs(et,{children:[a.jsx(tt,{children:e}),a.jsxs(Ge,{className:"border border-blue-500 bg-primary text-white shadow-2xl",children:[c&&a.jsx(le,{className:"cursor-pointer text-xs",onClick:()=>p("CHILD"),children:n("Add inside")}),a.jsx(le,{className:"cursor-pointer text-xs",onClick:()=>p("BEFORE"),children:n("Add before")}),a.jsx(le,{className:"cursor-pointer text-xs",onClick:()=>p("AFTER"),children:n("Add after")})]})]}):null},js=j.atom(null),_n=j.atom({isVisible:!1,isValid:!1,position:"inside",placeholderOrientation:"horizontal",isEmpty:!1,top:0,left:0,width:0,height:0});let qt=!1;const $r=t=>{qt=t},Fr=j.atom(0),hu=j.atom(!1);hu.debugLabel="readOnlyModeAtom";const mu=j.atom("online");mu.debugLabel="networkModeAtom";j.atom("");const gu=j.atom(!1);gu.debugLabel="editLayerNameAtom";const xu=j.atom("");xu.debugLabel="activeLanguageAtom";const bu=j.atom("");bu.debugLabel="primaryLanguageAtom";const Ss=j.atom(null);Ss.debugLabel="canvasIframeAtom";const yu=j.atom("outline");yu.debugLabel="activePanelAtom";const ii=j.atom("");ii.debugLabel="showPredefinedBlockCategoryAtom";const vu=j.atom(!1);vu.debugLabel="draggingFlagAtom";const zr=j.atom(null);zr.debugLabel="treeRefAtom";const ku=j.atom({});ku.debugLabel="canvasSettingsAtom";const li=j.atom(!1);li.debugLabel="aiAssistantActiveAtom";const wu=j.atom(!1);wu.debugLabel="codeEditorOpenAtom";const Cu=Se.atomWithStorage("codeEditorHeight",500);Cu.debugLabel="codeEditorHeightAtom";const ju=j.atom([]);ju.debugLabel="xShowBlocksAtom";const Hr=Se.atomWithStorage("_selectedLibrary",null);Hr.debugLabel="selectedLibraryAtom";const Vr=j.atom(!0);Vr.debugLabel="dataBindingActiveAtom";const sn=()=>j.useAtom(Ss);let re=null,lt=null;function Su(t,e){const n=t.getAttribute("data-block-name"),s=t.getAttribute("data-block-type"),r=n||s||"Container",o=e.createElement("div");return o.className="chai-drag-parent-label",o.textContent=r,o.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",o}function Ws(){lt&<.parentNode&&(lt.parentNode.removeChild(lt),lt=null)}const Wr=()=>{const[t]=sn(),e=g.useMemo(()=>{var r;return(t==null?void 0:t.contentDocument)||((r=t==null?void 0:t.contentWindow)==null?void 0:r.document)},[t]),n=g.useCallback(r=>{if(!e)return;let o=null;if(!r){re&&(re.style.outline="",re.style.outlineOffset="",re.style.backgroundColor="",re.style.position="",re=null),Ws();return}typeof r!="string"?o=r:o=e.querySelector(`[data-block-id="${r}"]`),!(o===re&<&<.parentNode)&&(re&&re!==o&&(re.style.outline="",re.style.outlineOffset="",re.style.backgroundColor="",re.style.position=""),Ws(),o?(o.style.outline="2px dashed rgba(34, 197, 94, 1)",o.style.outlineOffset="2px",o.style.backgroundColor="rgba(34, 197, 94, 0.05)",window.getComputedStyle(o).position==="static"&&(o.style.position="relative"),lt=Su(o,e),o.appendChild(lt),re=o):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),Ws()},[]);return{highlightParent:n,clearParentHighlight:s,lastDragHighlighted:re}},Nu=()=>{const[,t]=j.useAtom(js),[,e]=j.useAtom(_n),[n]=sn(),{clearParentHighlight:s}=Wr(),[r,o]=j.useAtom(Fr),i=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}),Eu(i),s(),i&&i.querySelectorAll("[data-dragging]").forEach(c=>{c.removeAttribute("data-dragging")}),$r(!1),o(r+1)},[t,e,i,s,r,o])};function Eu(t){if(!t)return;t.querySelectorAll("[data-drop-target]").forEach(n=>n.removeAttribute("data-drop-target"))}function Mt(t,e=null){const n=window.getComputedStyle(t),s=e?window.getComputedStyle(e):null,r=n.display,o=s?s.display:null;if(r==="flex"||r==="inline-flex"){const i=n.flexDirection;return i==="column"||i==="column-reverse"?"vertical":"horizontal"}else if(r==="grid"){const i=n.gridAutoFlow,l=n.gridTemplateColumns;return i.includes("column")||l&&l!=="none"&&l!==""&&!l.includes("calc")&&l.split(" ").length<=1?"vertical":"horizontal"}else if(o==="inline-block"||o==="inline")return"horizontal";return"vertical"}const Au=["Heading","Text","Image","Paragraph","Icon","Input","Radio","Checkbox","Select","CustomHTML","TextArea","Divider","Repeater","Video"];function Iu(t){try{return Au.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 Uo(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 xt(t){try{const e=[],n=t.children;for(let s=0;s<n.length;s++){const r=n[s];r.hasAttribute("data-block-id")&&e.push(r)}return e}catch{return[]}}function Xn(t){try{return xt(t).length>0}catch{return!1}}function Tu(t,e,n,s){try{const r=xt(t);if(r.length<2)return null;const o=Pu(r,e,n,s);if(o){const i=Gr(r,o,s);i.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<i.length-1;l++){const c=i[l],u=i[l+1],p=c.getBoundingClientRect(),f=u.getBoundingClientRect();if(s==="vertical"){const m=p.bottom,h=f.top,x=h-m,b=n>=m&&n<=h,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 m=p.right,h=f.left,x=h-m,b=e>=m&&e<=h,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 i=0;i<r.length-1;i++){const l=r[i],c=r[i+1],u=l.getBoundingClientRect(),p=c.getBoundingClientRect();if(s==="vertical"){const f=u.bottom,m=p.top,h=m-f,x=n>=f&&n<=m,b=e>=Math.min(u.left,p.left)&&e<=Math.max(u.right,p.right);if(x&&b&&h>=Je.GAP_THRESHOLD)return{before:l,after:c}}else{const f=u.right,m=p.left,h=m-f,x=e>=f&&e<=m,b=n>=Math.min(u.top,p.top)&&n<=Math.max(u.bottom,p.bottom);if(x&&b&&h>=Je.GAP_THRESHOLD)return{before:l,after:c}}}return null}catch{return null}}function _u(t,e,n,s){try{const r=t.getBoundingClientRect(),o=Je.PARENT_EDGE_PROXIMITY;if(s==="vertical"){if(n<=r.top+o)return"start";if(n>=r.bottom-o)return"end"}else{if(e<=r.left+o)return"start";if(e>=r.right-o)return"end"}return null}catch{return null}}function Bu(t,e,n,s,r){const o=t.getBoundingClientRect();if(r==="vertical"){const l=(n-o.top)/o.height,c=Uo(o.height),u=c/o.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-o.left)/o.width,c=Uo(o.width),u=c/o.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 Ru(t,e,n,s,r){var N,E,I,_;const o=t.getAttribute("data-block-id"),i=t.getAttribute("data-block-type")||"Box";if(!o)return null;let l=t.parentElement;for(;l&&!l.hasAttribute("data-block-id");)l=l.parentElement;const c=o==="canvas"?o:l==null?void 0:l.getAttribute("data-block-id"),u=l?Mt(l):"vertical",p=Mt(t),f=Iu(i),m=!f&&Qe(i,s),h=((N=r.defaultView)==null?void 0:N.scrollY)||0,x=((E=r.defaultView)==null?void 0:E.scrollX)||0;if(o==="canvas"&&Xn(t)){const S=xt(t),A=S[S.length-1];if(A){const C=A.getBoundingClientRect(),T=t.getBoundingClientRect(),P=window.getComputedStyle(t),R=parseFloat(P.paddingLeft)||0,O=parseFloat(P.paddingRight)||0,z=T.width-R-O,G=T.left+x+R;return{position:"after",placeholderOrientation:"horizontal",rect:{top:C.bottom+h,left:G,width:z,height:4},targetElement:A,targetBlockId:A.getAttribute("data-block-id"),targetParentId:"canvas",isEmpty:!1,confidence:1}}}if(m&&!f&&Xn(t)){const S=Tu(t,e,n,p);if(S){const A=S.before.getBoundingClientRect(),C=S.after.getBoundingClientRect(),T=t.getBoundingClientRect(),P=window.getComputedStyle(t),R=parseFloat(P.paddingLeft)||0,O=parseFloat(P.paddingRight)||0,z=xt(t),G=Gr(z,S.before,p);let de=0;if(G.forEach(ue=>{const ne=ue.getBoundingClientRect();ne.height>de&&(de=ne.height)}),p==="vertical"){const ue=T.width-R-O,ne=T.left+x+R;return{position:"after",placeholderOrientation:"horizontal",rect:{top:A.bottom+h,left:ne,width:ue,height:4},targetElement:S.before,targetBlockId:S.before.getAttribute("data-block-id"),targetParentId:o,isGapZone:!0,confidence:1}}else{const ue=A.top+h,ne=de>0?de:Math.max(A.height,C.height);return{position:"after",placeholderOrientation:"vertical",rect:{top:ue,left:A.right+x,width:4,height:ne},targetElement:S.before,targetBlockId:S.before.getAttribute("data-block-id"),targetParentId:o,isGapZone:!0,confidence:1}}}}if(l&&c){const S=_u(l,e,n,u);if(S){const A=l.getBoundingClientRect(),C=window.getComputedStyle(l),T=parseFloat(C.paddingLeft)||0,P=parseFloat(C.paddingRight)||0,R=parseFloat(C.paddingTop)||0,O=parseFloat(C.paddingBottom)||0,z=((I=r.defaultView)==null?void 0:I.scrollY)||0,G=((_=r.defaultView)==null?void 0:_.scrollX)||0,de=u==="vertical"?"horizontal":"vertical",ue=ci(l);if(S==="start"){const ne=xt(l)[0];if(ne){const Ae=ne.getBoundingClientRect();if(u==="vertical"){const Oe=A.width-T-P,W=A.left+G+T;return{position:"before",placeholderOrientation:de,rect:{top:Ae.top+z-2,left:W,width:Oe,height:4},targetElement:ne,targetBlockId:ne.getAttribute("data-block-id"),targetParentId:c,confidence:.9}}else{const Oe=A.top+z+R,W=ue.maxHeight>0?ue.maxHeight:A.height-R-O;return{position:"before",placeholderOrientation:de,rect:{top:Oe,left:Ae.left+G-2,width:4,height:W},targetElement:ne,targetBlockId:ne.getAttribute("data-block-id"),targetParentId:c,confidence:.9}}}}else{const ne=xt(l),Ae=ne[ne.length-1];if(Ae){const Oe=Ae.getBoundingClientRect();if(u==="vertical"){const W=A.width-T-P,$e=A.left+G+T;return{position:"after",placeholderOrientation:de,rect:{top:Oe.bottom+z-2,left:$e,width:W,height:4},targetElement:Ae,targetBlockId:Ae.getAttribute("data-block-id"),targetParentId:c,confidence:.9}}else{const W=A.top+z+R,$e=ue.maxHeight>0?ue.maxHeight:A.height-R-O;return{position:"after",placeholderOrientation:de,rect:{top:W,left:Oe.right+G-2,width:4,height:$e},targetElement:Ae,targetBlockId:Ae.getAttribute("data-block-id"),targetParentId:c,confidence:.9}}}}}}let b=Bu(t,e,n,m,u);if(f&&b.position==="inside"){const S=t.getBoundingClientRect();u==="vertical"?b={position:(n-S.top)/S.height<.5?"before":"after",confidence:b.confidence}:b={position:(e-S.left)/S.width<.5?"before":"after",confidence:b.confidence}}let y;b.position==="inside"?y=p==="vertical"?"horizontal":"vertical":y=u==="vertical"?"horizontal":"vertical";const v=Lu(t,l,b.position,y,r),w=b.position==="inside"?o:c;return{position:b.position,placeholderOrientation:y,rect:v,targetElement:t,targetBlockId:o,targetParentId:w??"",isEmpty:b.position==="inside"&&!Xn(t),confidence:b.confidence}}function Pu(t,e,n,s){if(t.length===0)return null;const r=t.filter(l=>{const c=l.getBoundingClientRect();return s==="vertical"?n>=c.top&&n<=c.bottom:e>=c.left&&e<=c.right});if(r.length===0){const l=new Map;t.forEach(p=>{const f=p.getBoundingClientRect(),m=Math.round(s==="vertical"?f.top:f.left);l.has(m)||l.set(m,[]),l.get(m).push(p)});let c=null,u=1/0;l.forEach((p,f)=>{const m=Math.abs(s==="vertical"?n-f:e-f);m<u&&(u=m,c=p)}),c&&r.push(c)}if(r.length===0)return null;let o=r[0],i=1/0;return r.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<i&&(i=f,o=l)}),o}function ci(t){const e=xt(t);if(e.length===0)return{maxWidth:0,maxHeight:0};let n=0,s=0;return e.forEach(r=>{const o=r.getBoundingClientRect();o.width>n&&(n=o.width),o.height>s&&(s=o.height)}),{maxWidth:n,maxHeight:s}}function Gr(t,e,n){const s=e.getBoundingClientRect(),r=5;return t.filter(o=>{const i=o.getBoundingClientRect();return n==="vertical"?Math.abs(i.top-s.top)<=r:Math.abs(i.left-s.left)<=r})}function Lu(t,e,n,s,r){var R,O;const o=t.getBoundingClientRect(),i=window.getComputedStyle(t),l=((R=r.defaultView)==null?void 0:R.scrollY)||0,c=((O=r.defaultView)==null?void 0:O.scrollX)||0,u=parseFloat(i.marginTop)||0,p=parseFloat(i.marginBottom)||0,f=parseFloat(i.marginLeft)||0,m=parseFloat(i.marginRight)||0,h=parseFloat(i.paddingTop)||0,x=parseFloat(i.paddingBottom)||0,b=parseFloat(i.paddingLeft)||0,y=parseFloat(i.paddingRight)||0,v=e==null?void 0:e.getBoundingClientRect(),w=e&&parseFloat(window.getComputedStyle(e).paddingLeft)||0,N=e&&parseFloat(window.getComputedStyle(e).paddingRight)||0,E=e&&parseFloat(window.getComputedStyle(e).paddingTop)||0,I=e&&parseFloat(window.getComputedStyle(e).paddingBottom)||0,_=e?ci(e):{maxHeight:0},S=e?Mt(e):"vertical",A=e?xt(e):[],C=Gr(A,t,S);let T=0,P=0;if(C.forEach(z=>{const G=z.getBoundingClientRect();G.height>T&&(T=G.height),G.width>P&&(P=G.width)}),n==="before")if(s==="horizontal"){const z=v?v.width-w-N:o.width,G=v?v.left+c+w:o.left+c;return{top:o.top+l-u-2,left:G,width:z,height:4}}else{const z=o.top+l,G=S==="horizontal"&&T>0?T:_.maxHeight>0?_.maxHeight:v?v.height-E-I:o.height;return{top:z,left:o.left+c-f-2,width:4,height:G}}else if(n==="after")if(s==="horizontal"){const z=v?v.width-w-N:o.width,G=v?v.left+c+w:o.left+c;return{top:o.bottom+l+p-2,left:G,width:z,height:4}}else{const z=o.top+l,G=S==="horizontal"&&T>0?T:_.maxHeight>0?_.maxHeight:v?v.height-E-I:o.height;return{top:z,left:o.right+c+m-2,width:4,height:G}}else return Xn(t)?Mt(t)==="vertical"?{top:o.bottom+l-x-2,left:o.left+c+b,width:o.width-b-y,height:4}:{top:o.top+l+h,left:o.right+c-y-2,width:4,height:o.height-h-x}:{top:o.top+l+h,left:o.left+c+b,width:o.width-b-y,height:Math.max(o.height-h-x,20)}}const Mu=100,bt=()=>{const[t]=te(),[,e]=U(),{addBlocks:n}=Ne(),s=g.useCallback((o,i,l)=>{for(let m=0;m<o.length;m++){const{_id:h}=o[m];o[m]._id=ve.generateUUID();const x=d.filter(o,{_parent:h});for(let b=0;b<x.length;b++)x[b]._parent=o[m]._id}const c=d.first(o);let u,p;return i&&(u=d.find(t,{_id:i}),o[0]._parent=i,d.forEach(o,m=>{m!=null&&m._parent||(m._parent=i)}),p=i),!(u?Qe(u==null?void 0:u._type,c._type):!0)&&u&&(o[0]._parent=u._parent,p=u._parent),n(o,p??void 0,l),e([c._id]),c},[n,t,e]);return{addCoreBlock:g.useCallback((o,i,l)=>{if(d.has(o,"blocks")){const b=o.blocks;return s(b,i??void 0,l)}const c=ve.generateUUID(),u=X.getDefaultBlockProps(o.type),p={_type:o.type,_id:c,...u,...d.has(o,"_name")&&{_name:o._name},...d.has(o,"partialBlockId")&&{partialBlockId:o.partialBlockId}};let f,m;return i&&(f=d.find(t,{_id:i}),p._parent=i,m=i),!Qe(f==null?void 0:f._type,p._type)&&f&&(p._parent=f._parent,m=f._parent),n([p],m??void 0,l),setTimeout(()=>e([p._id]),Mu),p},[n,s,t,e]),addPredefinedBlock:s}};let at=null;const st=()=>{const[t]=j.useAtom(Ss),e=g.useMemo(()=>{var r;return(t==null?void 0:t.contentDocument)||((r=t==null?void 0:t.contentWindow)==null?void 0:r.document)},[t]),n=g.useCallback(r=>{if(e)if(at&&at.removeAttribute("data-highlighted"),typeof r!="string")r.setAttribute("data-highlighted","true"),at=r;else if(typeof r=="string"){const o=e.querySelector(`[data-block-id="${r}"]`);o&&(o.setAttribute("data-highlighted","true"),at=o)}else at=null},[e]),s=g.useCallback(()=>{at&&(at.removeAttribute("data-highlighted"),at=null)},[]);return{highlightBlock:n,clearHighlight:s,lastHighlighted:at}},Bn=j.atom([]);Bn.debugLabel="selectedStylingBlocksAtom";const Ee=()=>j.useAtom(Bn),Du=()=>{const[t,e]=j.useAtom(js),[n,s]=j.useAtom(_n),[r]=te(),[o]=sn(),{addCoreBlock:i}=bt(),{moveBlocks:l}=Ne(),[,c]=U(),[,u]=Ee(),{clearHighlight:p}=st(),{clearParentHighlight:f}=Wr(),[m,h]=j.useAtom(Fr),x=nt(),b=o==null?void 0:o.contentDocument;return g.useCallback(y=>{if(y.preventDefault(),y.stopPropagation(),$r(!1),$u(b),qo(b),f(),s({isVisible:!1,isValid:!1,position:"inside",placeholderOrientation:"horizontal",isEmpty:!1,top:0,left:0,width:0,height:0}),setTimeout(()=>{f(),qo(b),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 v=n.targetBlockId,w=n.targetParentId;if(!v)return;const{parentId:N,index:E,replaceImageUrl:I}=Ou(r,v,w,n.position,t),_=t._id!==void 0;if(I&&di(t)){x([v],{image:d.get(t,"blocks.0.image")}),setTimeout(()=>{h(m+1)},50);return}if(_)l([t._id],N===null?void 0:N,E),p(),u([]),c([t._id]);else{const S=t._type||t.type,A=t!=null&&t.blocks?d.isFunction(t==null?void 0:t.blocks)?X.syncBlocksWithDefaultProps(t==null?void 0:t.blocks()):t==null?void 0:t.blocks:null;i(S==="PartialBlock"?{blocks:[{_type:S,_id:"partial-block",partialBlockId:t.partialBlockId}]}:(A==null?void 0:A.length)>0?{blocks:[...A]}:{type:S},N,E)}setTimeout(()=>{h(m+1)},50)},[t,n,r,b,i,l,e,s,f,p,c,u,m,h,x])},di=t=>{var o,i;const e=d.has(t,"blocks"),n=t==null?void 0:t.blocks,s=(n==null?void 0:n.length)===1&&((o=n==null?void 0:n[0])==null?void 0:o._type)==="Image",r=!((i=n==null?void 0:n[0])!=null&&i._id);return e&&s&&r};function Ou(t,e,n,s,r){var o,i;try{if(e===n&&((o=r==null?void 0:r.blocks)==null?void 0:o.length)===1&&d.get(r,"blocks.0._type")==="Image"&&((i=d.find(t,{_id:e}))==null?void 0:i._type)==="Image")return{parentId:"",index:-1,replaceImageUrl:!0};if(e==="canvas"||s==="inside"&&e==="canvas")return{parentId:null,index:d.filter(t,h=>!(h!=null&&h._parent)).length};if(s==="inside"){const m=d.filter(t,{_parent:e});return{parentId:e,index:m.length}}const l=!n||n==="canvas",c=l?void 0:n,u=d.filter(t,m=>l?!(m!=null&&m._parent):(m==null?void 0:m._parent)===c),p=u.findIndex(m=>m._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 qo(t){if(!t)return;t.querySelectorAll("[data-drop-target]").forEach(n=>n.removeAttribute("data-drop-target"))}function $u(t){if(!t)return;t.querySelectorAll("[data-dragging]").forEach(n=>{n.removeAttribute("data-dragging")})}function ui(t,e,n){if(!t||!e)return!1;if(t===e)return!0;const s=n.find(o=>o._id===t);if(!s)return!1;let r=s;for(;r._parent;){if(r._parent===e)return!0;const o=n.find(i=>i._id===r._parent);if(!o)break;r=o}return!1}function pi(t,e,n){return!t||!e?!0:!ui(e,t,n)}function Fu(t,e,n){if(!t)return!0;const s=n.find(o=>o._id===e);if(!s)return!0;const r=s._parent;return pi(t,r,n)}const zu=["Heading","Text","Image","Paragraph","Icon","Input","Radio","Checkbox","Select","CustomHTML","TextArea","Divider","Repeater","Video"],ht={EDGE_ZONE:50,MAX_SCROLL_SPEED:10,MIN_SCROLL_SPEED:10},Hu=()=>{const[t]=j.useAtom(js),[e]=sn(),[,n]=j.useAtom(_n),{clearParentHighlight:s,highlightParent:r}=Wr(),[o]=te(),i=e==null?void 0:e.contentDocument,l=g.useRef(null),c=g.useRef(0),u=g.useCallback(f=>{if(!(i!=null&&i.defaultView))return;const m=i.defaultView,h=m.innerHeight,x=m.scrollY,b=i.documentElement.scrollHeight;c.current=f;const y=f,v=h-f;let w=!1,N=null,E=0;if(y<ht.EDGE_ZONE&&x>0?(w=!0,N="up",E=y):v<ht.EDGE_ZONE&&x+h<b&&(w=!0,N="down",E=v),!w&&l.current!==null){cancelAnimationFrame(l.current),l.current=null;return}if(w&&N){const I=1-E/ht.EDGE_ZONE,_=ht.MIN_SCROLL_SPEED+(ht.MAX_SCROLL_SPEED-ht.MIN_SCROLL_SPEED)*I,S=()=>{if(!qt||!m){l.current=null;return}const A=N==="up"?-_:_;m.scrollBy(0,A);const C=m.scrollY,T=C>0,P=C+h<b,R=c.current,O=h-c.current;N==="up"&&T&&R<ht.EDGE_ZONE||N==="down"&&P&&O<ht.EDGE_ZONE?l.current=requestAnimationFrame(S):l.current=null};l.current===null&&(l.current=requestAnimationFrame(S))}},[i]);g.useEffect(()=>()=>{l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)},[]),g.useEffect(()=>{!qt&&l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)},[qt]);const p=g.useCallback(d.throttle(f=>{if(!qt||!t)return;s();const m=Vu(f),{element:h,targetBlockId:x,targetParentId:b}=m;if(!h||!x)return;const y=t._id;if(y&&(x===y||ui(x,y,o)))return;const v=t._type||t.type;if(!v)return;const w=f.clientX,N=f.clientY;if(u(N),!i)return;const E=Ru(h,w,N,v,i);if(!E)return;const I=h.getAttribute("data-block-type")||"Box";let _=!1;const S=zu.includes(I);if(I==="Image"&&v==="Image"&&di(t)){r(x),n({isVisible:!0,isValid:!0,position:E.position,placeholderOrientation:E.placeholderOrientation,isEmpty:!0,top:h.offsetTop,left:E.rect.left,width:h.clientWidth,height:h.clientHeight,targetBlockId:E.targetBlockId,targetParentId:E.targetBlockId});return}if(E.position==="inside"){if(S||y&&!pi(y,x,o))return;_=Qe(I,v)}else{let C=h.parentElement,T="Box";for(;C&&!C.hasAttribute("data-block-id");)C=C.parentElement;if(C&&(T=C.getAttribute("data-block-type")||"Box"),y&&!Fu(y,x,o))return;_=Qe(T,v)}if(!_)return;r(E.targetParentId);const A=E.targetParentId||b||void 0;n({isVisible:!0,isValid:!0,position:E.position,placeholderOrientation:E.placeholderOrientation,isEmpty:E.isEmpty??!1,top:E.rect.top,left:E.rect.left,width:E.rect.width,height:E.rect.height,targetBlockId:E.targetBlockId,targetParentId:A}),Wu(i),E.targetElement.setAttribute("data-drop-target","true")},300),[i,t,n,s,r,o,u]);return g.useCallback(f=>{f.preventDefault(),f.stopPropagation(),p(f)},[p])};function Vu(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 r=e.parentElement;for(;r&&!r.hasAttribute("data-block-id");)r=r.parentElement;const o=(r==null?void 0:r.getAttribute("data-block-id"))||null,i=(r==null?void 0:r.getAttribute("data-block-type"))||"Box",l=Mt(e);return{element:e,targetBlockId:n,targetBlockType:s,targetParentId:o,targetParentType:i,orientation:l}}function Wu(t){if(!t)return;t.querySelectorAll("[data-drop-target]").forEach(n=>n.removeAttribute("data-drop-target"))}function Gu(t){var o;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=((o=document.querySelector(`[data-add-core-block-icon="${n}"]`))==null?void 0:o.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 r=document.createElement("span");return r.className="text-[10px] font-medium text-blue-600 whitespace-nowrap",r.textContent=t.label||t.type||t._name||t._type||"Block",e.appendChild(s),e.appendChild(r),document.body.appendChild(e),e}function Ko(t){t&&t.parentNode&&t.parentNode.removeChild(t)}const Uu=()=>{const[,t]=U(),[,e]=Ee(),{clearHighlight:n}=st(),[,s]=j.useAtom(js),[,r]=j.useAtom(_n),o=g.useRef(null);return g.useCallback((i,l,c=!0)=>{var p;o.current&&(Ko(o.current),o.current=null);const u=c?d.pick(l,["type","blocks","partialBlockId"]):l;if(s(u),i.dataTransfer.setData("text/plain",JSON.stringify({block:u})),i.dataTransfer.effectAllowed="move",!c&&l._id){const f=(p=document.getElementById("canvas-iframe"))==null?void 0:p.contentDocument;if(f){const m=f.querySelector(`[data-block-id="${l._id}"]`);m&&setTimeout(()=>{if(m){const x=m.getBoundingClientRect().height;Mt(m==null?void 0:m.parentElement)==="vertical"&&x>200&&(m.style.height="max-content",m.style.maxHeight="max-content",m.style.minHeight="0",m.style.overflow="hidden",m.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>",m.style.opacity="0.4"),m.style.opacity="0.4",m.setAttribute("data-dragging","true")}},0)}}if(l!=null&&l._type||l!=null&&l.type){const f=Gu(l);o.current=f,i.dataTransfer.setDragImage(f,0,0),setTimeout(()=>{o.current&&(Ko(o.current),o.current=null)},50)}t([]),n(),e([]),oe.publish(K.CLOSE_ADD_BLOCK),$r(!0),r({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,r])},rn=()=>{const t=Uu(),e=Hu(),n=Du(),s=Nu();return{onDragStart:t,onDragOver:e,onDrop:n,onDragEnd:s,isDragging:qt}},qu=()=>{const[t]=j.useAtom(_n);return t},Ye=()=>{const{dragAndDrop:t}=$("flags",{dragAndDrop:!0});return t};let fi,hi;typeof document<"u"&&(fi=document);typeof window<"u"&&(hi=window);const mi=g.createContext({document:fi,window:hi}),rt=()=>g.useContext(mi),{Provider:Ku,Consumer:Ky}=mi,Yu=[{ControlIcon:k.PinTopIcon,dir:"VERTICAL",key:"UP"},{ControlIcon:k.PinBottomIcon,dir:"VERTICAL",key:"DOWN"},{ControlIcon:k.PinLeftIcon,dir:"HORIZONTAL",key:"LEFT"},{ControlIcon:k.PinRightIcon,dir:"HORIZONTAL",key:"RIGHT"}],Xu=(t,e,n)=>{try{if(!t||!n)return"VERTICAL";const s=`[data-block-id='${t}']`,r=n==null?void 0:n.querySelector(s);if(r){const o=n==null?void 0:n.querySelector(`[data-block-id='${e}']`);return Mt(r,o).toUpperCase()}return"VERTICAL"}catch{return"VERTICAL"}},gi=(t,e,n)=>!!(t&&(n==="UP"||n==="LEFT")||e&&(n==="DOWN"||n==="RIGHT")),Ju=(t,e)=>{const[n]=te(),{document:s}=rt(),{moveBlocks:r}=Ne(),o=d.get(t,"_id"),i=d.get(t,"_parent"),l=d.filter(n,x=>i?d.get(x,"_parent")===i:!d.get(x,"_parent")),c=(l==null?void 0:l.length)<=1,u=d.findIndex(l,{_id:o}),p=u<=0,f=u+1===(l==null?void 0:l.length),m=Xu(i,o,s),h=g.useCallback(x=>{gi(p,f,x)||c||(x==="UP"||x==="LEFT"?r([o],i||void 0,u-1):(x==="DOWN"||x==="RIGHT")&&r([o],i||void 0,u+2),e())},[p,f,c,u,o,i,e]);return Xe.useHotkeys("shift+up, shift+down, shift+left, shift+right",({key:x})=>{var b;h((b=x==null?void 0:x.replace("Arrow",""))==null?void 0:b.toUpperCase())},{document:s},[h]),{isOnlyChild:c,isFirstBlock:p,isLastBlock:f,moveBlock:h,orientation:m}},Zu=({block:t,updateFloatingBar:e})=>{const{isOnlyChild:n,isFirstBlock:s,isLastBlock:r,moveBlock:o,orientation:i}=Ju(t,e);return n?null:a.jsx(a.Fragment,{children:Yu.map(({ControlIcon:l,dir:c,key:u})=>i!==c||gi(s,r,u)?null:a.jsx(l,{onClick:()=>o(u),className:"rounded p-px hover:bg-white hover:text-blue-500"},u))})},Ur=()=>{const[t]=te(),[,e]=U(),{addBlocks:n}=Ne();return g.useCallback((s,r=null)=>{const o=[];d.each(s,i=>{const l=t.find(m=>m._id===i);r?r==="root"&&(r=null):r=(l==null?void 0:l._parent)??null;const p=d.filter(t,m=>d.isString(r)?m._parent===r:!m._parent).indexOf(l)+1,f=ar(t,i,r);n(f,r??void 0,p),o.push(d.get(f,"0._id",""))}),e(o)},[t,e])},Qu=j.atom(""),xi=()=>j.useAtom(Qu),bi=j.atom("");bi.debugLabel="inlineEditingActiveAtom";const yi=j.atom(0);yi.debugLabel="inlineEditingItemIndexAtom";const Ft=()=>{const[t,e]=j.useAtom(bi),[n,s]=j.useAtom(yi);return{editingBlockId:t,editingItemIndex:n,setEditingBlockId:e,setEditingItemIndex:s}},vi=j.atom("outline");vi.debugLabel="sidebarActivePanelAtom";const Ns=()=>j.useAtom(vi),ep=({blockId:t,className:e})=>{const n=()=>{t&&oe.publish(K.GOTO_BLOCK_SETTINGS,t)};return a.jsx(k.GearIcon,{className:e,onClick:n})},tp=j.atom(0),ki=j.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 np=["Heading","Paragraph","Text","Link","Span","Button"],sp=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"},wi=t=>t?d.some(t.children,e=>{const n=e;return n.hasAttribute("data-block-id")||wi(n)}):!1,rp=(t,e)=>{if(sp(t))return!0;const n=t==null?void 0:t.getAttribute("data-block-type");return n?np.includes(n):!1},op=()=>{const{editingBlockId:t,setEditingBlockId:e,setEditingItemIndex:n}=Ft();return g.useCallback(s=>{var l;if(s==null||s.preventDefault(),s==null||s.stopPropagation(),t)return;const r=qr(s.target);if(!r||!rp(r)||wi(r))return;const o=r.getAttribute("data-block-id");if(!o)return;const i=r.closest('[data-block-type="Repeater"]');i?(l=i==null?void 0:i.childNodes)==null||l.forEach((c,u)=>{c.contains(r)&&n(u)}):n(-1),e(o)},[t,e,n])},ap=()=>{const{editingBlockId:t}=Ft(),{clearHighlight:e}=st(),[,n]=Ee(),[s]=j.useAtom(ki);return g.useCallback(r=>{if(t)return;r.stopPropagation();const o=qr(r.target);if(!o){e(),n([]),oe.publish(K.CANVAS_BLOCK_SELECTED,[]);return}if(s!==2){if(o!=null&&o.getAttribute("data-block-id")&&(o==null?void 0:o.getAttribute("data-block-id"))==="container"){oe.publish(K.CLEAR_CANVAS_SELECTION);return}if(o!=null&&o.getAttribute("data-block-parent")){const i=o.getAttribute("data-style-prop"),l=o.getAttribute("data-style-id"),c=o.getAttribute("data-block-parent");oe.publish(K.CANVAS_BLOCK_STYLE_SELECTED,{blockId:c,styleId:l,styleProp:i})}else if(o!=null&&o.getAttribute("data-block-id")){const i=o.getAttribute("data-block-id");oe.publish(K.CANVAS_BLOCK_SELECTED,i==="canvas"?[]:[i])}e()}},[t,s,e,n])},ip=()=>{const{editingBlockId:t}=Ft(),{highlightBlock:e}=st();return ke.useThrottledCallback(n=>{if(t)return;const s=qr(n.target);s&&e(s)},[t,e],100)},lp=()=>{const{clearHighlight:t}=st();return g.useCallback(()=>t(),[t])},cp=({children:t})=>{const e=op(),n=ap(),s=ip(),r=lp();return a.jsx("div",{"data-block-id":"canvas",id:"canvas",onClick:n,onDoubleClick:e,onMouseMove:s,onMouseLeave:r,className:"relative h-full max-w-full p-px",children:t})},Ci=(t,e)=>t.querySelector(`[data-block-id="${e}"]`),dp=(t,e)=>t.querySelector(`[data-style-id="${e}"]`),up=()=>{const t=J(),{document:e}=rt(),[n]=Ee(),[s,r]=g.useState([]),[,o]=g.useState([]),{onDragStart:i,onDragEnd:l,isDragging:c}=rn(),[u,p]=g.useState(null),f=Ye(),m=(h,x=0)=>{const{top:b}=h.getBoundingClientRect();return b+x>=0&&b-x<=window.innerHeight};return g.useEffect(()=>{var h;if(t!=null&&t._id&&t.type!=="Multiple"&&e){const x=Ci(e,t._id);x&&(m(x)||(h=e.defaultView)==null||h.scrollTo({top:x.offsetTop,behavior:"smooth"}),r([x]))}},[t==null?void 0:t._id,t==null?void 0:t.type,e]),g.useEffect(()=>{if(!d.isEmpty(n)&&e){const h=dp(e,d.first(n).id);o(h?[h]:[null])}else o([null])},[n,e]),a.jsx("div",{onDragEnd:()=>{p(null),l()},draggable:f&&!!t,onDragStart:h=>{p(s==null?void 0:s[0]),i(h,t,!1)},children:t&&a.jsx(pp,{block:t,isDragging:c&&!!u,selectedBlockElement:s[0]||(c?u:null)})})},pp=({block:t,isDragging:e,selectedBlockElement:n})=>{const s=Cs(),r=Ur(),[,o]=U(),[,i]=xi(),[,l]=Ee(),{hasPermission:c}=qe(),{editingBlockId:u}=Ft(),{document:p}=rt(),f=Ye(),m=$("flags.gotoSettings",!1),h=$("flags.ai",!1),{floatingStyles:x,refs:b,update:y}=Wo.useFloating({placement:"top-start",middleware:[Wo.shift({boundary:p==null?void 0:p.body,limiter:Hs.limitShift({offset:8,mainAxis:!0,crossAxis:!0})}),Hs.flip({boundary:p==null?void 0:p.body,fallbackPlacements:["bottom-start","top-end","bottom-end","inside"]}),Hs.size({boundary:p==null?void 0:p.body,apply({availableWidth:E,availableHeight:I,elements:_}){Object.assign(_.floating.style,{maxWidth:`${Math.max(200,E)}px`,maxHeight:`${Math.max(100,I)}px`})}})],elements:{reference:n}});ke.useResizeObserver(n,()=>y(),n!==null),ke.useResizeObserver(p==null?void 0:p.body,()=>y(),(p==null?void 0:p.body)!==null);const v=d.get(t,"_parent",null),w=d.isEmpty(d.get(t,"_name",""))?d.get(t,"_type",""):d.get(t,"_name","");g.useEffect(()=>{let E=null;return n?(E=setTimeout(()=>y(),500),()=>{E&&clearTimeout(E)}):(y(),()=>{E&&clearTimeout(E)})},[n,t==null?void 0:t._id]);const[,N]=Ns();return!e&&(!n||!t||u)?null:a.jsx(a.Fragment,{children:a.jsx("div",{role:"button",tabIndex:0,ref:b.setFloating,style:x,onClick:E=>{E.stopPropagation(),E.preventDefault()},onMouseEnter:E=>{E.stopPropagation(),i(null)},onKeyDown:E=>E.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:a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center",children:[f&&a.jsx(k.DragHandleDots2Icon,{className:"flex-shrink-0 cursor-grab rounded p-0.5 hover:bg-white/20 active:cursor-grabbing"}),v&&a.jsx(k.ArrowUpIcon,{className:"flex-shrink-0 rounded p-0.5 hover:bg-white/20",onClick:()=>{l([]),o([v])}})]}),a.jsx("div",{className:`w-full ${f?"cursor-grab active:cursor-grabbing":""}`,children:a.jsx("div",{className:"mr-10 w-full items-center space-x-1 px-1 leading-tight",children:w})}),a.jsxs("div",{className:"flex items-center gap-1 pl-1 pr-1.5",children:[c(se.ADD_BLOCK)&&h&&a.jsx(kr,{className:"h-4 w-4 rounded hover:bg-white hover:text-blue-500",onClick:()=>{N("chai-chat-panel"),oe.publish(K.OPEN_AI_PANEL)}}),m&&a.jsx(ep,{blockId:t==null?void 0:t._id,className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500"}),!f&&a.jsx(fu,{block:t,children:a.jsx(k.PlusIcon,{className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500"})}),Cr(d.get(t,"_type",""))&&c(se.ADD_BLOCK)?a.jsx(k.CopyIcon,{className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500",onClick:()=>r([t==null?void 0:t._id])}):null,jr(d.get(t,"_type",""))&&c(se.DELETE_BLOCK)?a.jsx(k.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(se.MOVE_BLOCK)&&a.jsx(Zu,{block:t,updateFloatingBar:y})]})]})})})},fp=`<!doctype html>
|
|
2
2
|
<html lang="en" dir="__HTML_DIR__" class="scroll-smooth h-full overflow-y-auto">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8">
|
|
@@ -122,21 +122,21 @@
|
|
|
122
122
|
<body class="font-body antialiased h-full">
|
|
123
123
|
<div class="frame-root h-full"></div>
|
|
124
124
|
</body>
|
|
125
|
-
</html>`;class hp extends g.Component{componentDidMount(){this.props.contentDidMount()}componentDidUpdate(){this.props.contentDidUpdate()}render(){return g.Children.only(this.props.children)}}class ji extends g.Component{constructor(n,s){super(n,s);wt(this,"setRef",n=>{this.nodeRef.current=n;const{forwardedRef:s}=this.props;typeof s=="function"?s(n):s&&(s.current=n)});wt(this,"handleLoad",()=>{clearInterval(this.loadCheck),this.state.iframeLoaded||this.setState({iframeLoaded:!0})});wt(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,r=this.props.contentDidUpdate,o=n.defaultView||n.parentView,i=a.jsx(hp,{contentDidMount:s,contentDidUpdate:r,children:a.jsx(Ku,{value:{document:n,window:o},children:a.jsx("div",{className:"frame-content",children:this.props.children})})}),l=this.getMountTarget();return[rr.createPortal(this.props.head,this.getDoc().head),rr.createPortal(i,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,a.jsx("iframe",{...n,ref:this.setRef,onLoad:this.handleLoad,children:this.state.iframeLoaded&&this.renderFrameContents()})}}wt(ji,"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 mp=g.forwardRef((t,e)=>a.jsx(ji,{...t,forwardedRef:e})),Si=j.atom([]),Es=()=>{const[t,e]=j.useAtom(Si),n=j.useSetAtom(Ai),s=g.useCallback(r=>{e(r),n([])},[e,n]);return[t,s]},Ni=j.atom({}),gp=j.atom({}),As=()=>{const[t,e]=j.useAtom(Ni),n=g.useCallback(r=>d.get(t,r,[]),[t]),s=g.useCallback(()=>e({}),[e]);return{getPartailBlocks:n,reset:s}},xp=()=>{const[t]=te(),[e,n]=j.useAtom(Ni),[s,r]=j.useAtom(gp),o=$("getPartialBlockBlocks",async l=>[]),i=g.useMemo(()=>t.filter(l=>l._type==="PartialBlock"||l._type==="GlobalBlock").map(l=>d.get(l,"partialBlockId",d.get(l,"globalBlock",""))),[t]);g.useEffect(()=>{d.forEach(i,l=>{d.has(e,l)||d.get(s,`${l}.loading`,!1)||(r(c=>({...c,[l]:{loading:!0,error:null}})),o(l).then(c=>{n(u=>({...u,[l]:c})),r(u=>({...u,[l]:{loading:!1,error:null}}))}).catch(c=>{r(u=>({...u,[l]:{loading:!1,error:c.message}}))}))})},[o,e,s,n,r,i])},bp=j.atom({}),Ei=()=>{const[t,e]=g.useState(!1),[n,s]=g.useState(null),[r,o]=j.useAtom(bp),i=$("getPartialBlocks",async()=>[]),l=g.useCallback(async()=>{e(!0),s(null);try{const c=await i();o(c),e(!1)}catch(c){s(c instanceof Error?c.message:"Failed to fetch partial blocks"),e(!1)}},[i,o]);return g.useEffect(()=>{l()},[]),{data:r,isLoading:t,refetch:l,error:n}},Ai=j.atom([]),Ii=()=>{const[t]=te(),[e,n]=j.useAtom(Ai),s=j.useSetAtom(Si),{getPartailBlocks:r}=As(),o=$("flags.copyPaste",!0),i=g.useCallback(c=>c.some(u=>ar(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 m=ar(t,f,null);if(!u)return m;let h=[];for(const x of m)if(x._type==="PartialBlock"||x._type==="GlobalBlock"){let b=r(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))),h=[...h,...b]}else h.push(x);return h})};if(!o)return;if(!navigator.clipboard){pe.toast.error("Clipboard not available.");return}pe.toast.promise(navigator.clipboard.writeText(JSON.stringify(p)),{success:"Blocks copied successfully",error:"Failed to copy blocks to clipboard"})}catch(p){pe.toast.error("Failed to copy blocks to clipboard"),console.error("Failed to copy blocks to clipboard:",p)}},[n,s,t]);return[e,l,i]},Gs=()=>navigator.userAgent.toLowerCase().includes("firefox"),yp=()=>{const[t]=te();return(e,n)=>{var o;const s=((o=d.find(t,{_id:n}))==null?void 0:o._type)||null,r=d.first(e.map(i=>{var l;return(l=d.find(t,{_id:i}))==null?void 0:l._type}));return Qe(s,r)}},vp=()=>{const t=j.useAtomValue(je),{moveBlocks:e}=Ne();return g.useCallback((n,s)=>{const r=Array.isArray(s)?s[0]:s;if(s==="root"){const o=t==null?void 0:t.filter(i=>!i._parent);e(n,void 0,(o==null?void 0:o.length)||0)}else{const o=t==null?void 0:t.filter(i=>i._parent===r);e(n,r,(o==null?void 0:o.length)||0)}},[e,t])},Kr=()=>{const[t,e]=Es(),n=vp(),{addPredefinedBlock:s}=bt(),r=yp();return{canPaste:g.useCallback(async i=>{if(t.length>0)return r(t,i);if(Gs())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},[r,t]),pasteBlocks:g.useCallback(async i=>{const l=Array.isArray(i)?i[0]:i;if(!d.isEmpty(t)){n(t,i),e([]),Gs()||await navigator.clipboard.writeText("");return}if(Gs()){pe.toast.error("Paste is not supported in Firefox");return}if(!(navigator!=null&&navigator.permissions)){pe.toast.error("Cannot check clipboard permissions.");return}try{if((await navigator.permissions.query({name:"clipboard-read"})).state==="denied"){pe.toast.error("Clipboard paste permission denied. Please allow clipboard access.");return}}catch{pe.toast.error("Failed to check clipboard permissions. Please allow clipboard access.");return}pe.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])}},Ti=t=>{const[e,n]=U(),s=J(),r=Cs(),o=Ur(),{undo:i,redo:l}=Tn(),[,c]=Es(),[,u]=Ii(),{canPaste:p,pasteBlocks:f}=Kr(),m=t?{document:t}:{};Xe.useHotkeys("ctrl+z,meta+z",h=>{h.preventDefault(),Ke.hasUndo()&&i()},{...m,preventDefault:!0},[i]),Xe.useHotkeys("ctrl+y,meta+y",h=>{h.preventDefault(),Ke.hasRedo()&&l()},{...m,preventDefault:!0},[l]),Xe.useHotkeys("ctrl+x,meta+x",h=>{h.preventDefault(),d.isEmpty(e)||c(e)},{...m,enabled:!d.isEmpty(e)
|
|
125
|
+
</html>`;class hp extends g.Component{componentDidMount(){this.props.contentDidMount()}componentDidUpdate(){this.props.contentDidUpdate()}render(){return g.Children.only(this.props.children)}}class ji extends g.Component{constructor(n,s){super(n,s);wt(this,"setRef",n=>{this.nodeRef.current=n;const{forwardedRef:s}=this.props;typeof s=="function"?s(n):s&&(s.current=n)});wt(this,"handleLoad",()=>{clearInterval(this.loadCheck),this.state.iframeLoaded||this.setState({iframeLoaded:!0})});wt(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,r=this.props.contentDidUpdate,o=n.defaultView||n.parentView,i=a.jsx(hp,{contentDidMount:s,contentDidUpdate:r,children:a.jsx(Ku,{value:{document:n,window:o},children:a.jsx("div",{className:"frame-content",children:this.props.children})})}),l=this.getMountTarget();return[rr.createPortal(this.props.head,this.getDoc().head),rr.createPortal(i,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,a.jsx("iframe",{...n,ref:this.setRef,onLoad:this.handleLoad,children:this.state.iframeLoaded&&this.renderFrameContents()})}}wt(ji,"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 mp=g.forwardRef((t,e)=>a.jsx(ji,{...t,forwardedRef:e})),Si=j.atom([]),Es=()=>{const[t,e]=j.useAtom(Si),n=j.useSetAtom(Ai),s=g.useCallback(r=>{e(r),n([])},[e,n]);return[t,s]},Ni=j.atom({}),gp=j.atom({}),As=()=>{const[t,e]=j.useAtom(Ni),n=g.useCallback(r=>d.get(t,r,[]),[t]),s=g.useCallback(()=>e({}),[e]);return{getPartailBlocks:n,reset:s}},xp=()=>{const[t]=te(),[e,n]=j.useAtom(Ni),[s,r]=j.useAtom(gp),o=$("getPartialBlockBlocks",async l=>[]),i=g.useMemo(()=>t.filter(l=>l._type==="PartialBlock"||l._type==="GlobalBlock").map(l=>d.get(l,"partialBlockId",d.get(l,"globalBlock",""))),[t]);g.useEffect(()=>{d.forEach(i,l=>{d.has(e,l)||d.get(s,`${l}.loading`,!1)||(r(c=>({...c,[l]:{loading:!0,error:null}})),o(l).then(c=>{n(u=>({...u,[l]:c})),r(u=>({...u,[l]:{loading:!1,error:null}}))}).catch(c=>{r(u=>({...u,[l]:{loading:!1,error:c.message}}))}))})},[o,e,s,n,r,i])},bp=j.atom({}),Ei=()=>{const[t,e]=g.useState(!1),[n,s]=g.useState(null),[r,o]=j.useAtom(bp),i=$("getPartialBlocks",async()=>[]),l=g.useCallback(async()=>{e(!0),s(null);try{const c=await i();o(c),e(!1)}catch(c){s(c instanceof Error?c.message:"Failed to fetch partial blocks"),e(!1)}},[i,o]);return g.useEffect(()=>{l()},[]),{data:r,isLoading:t,refetch:l,error:n}},Ai=j.atom([]),Ii=()=>{const[t]=te(),[e,n]=j.useAtom(Ai),s=j.useSetAtom(Si),{getPartailBlocks:r}=As(),o=$("flags.copyPaste",!0),i=g.useCallback(c=>c.some(u=>ar(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 m=ar(t,f,null);if(!u)return m;let h=[];for(const x of m)if(x._type==="PartialBlock"||x._type==="GlobalBlock"){let b=r(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))),h=[...h,...b]}else h.push(x);return h})};if(!o)return;if(!navigator.clipboard){pe.toast.error("Clipboard not available.");return}pe.toast.promise(navigator.clipboard.writeText(JSON.stringify(p)),{success:"Blocks copied successfully",error:"Failed to copy blocks to clipboard"})}catch(p){pe.toast.error("Failed to copy blocks to clipboard"),console.error("Failed to copy blocks to clipboard:",p)}},[n,s,t]);return[e,l,i]},Gs=()=>navigator.userAgent.toLowerCase().includes("firefox"),yp=()=>{const[t]=te();return(e,n)=>{var o;const s=((o=d.find(t,{_id:n}))==null?void 0:o._type)||null,r=d.first(e.map(i=>{var l;return(l=d.find(t,{_id:i}))==null?void 0:l._type}));return Qe(s,r)}},vp=()=>{const t=j.useAtomValue(je),{moveBlocks:e}=Ne();return g.useCallback((n,s)=>{const r=Array.isArray(s)?s[0]:s;if(s==="root"){const o=t==null?void 0:t.filter(i=>!i._parent);e(n,void 0,(o==null?void 0:o.length)||0)}else{const o=t==null?void 0:t.filter(i=>i._parent===r);e(n,r,(o==null?void 0:o.length)||0)}},[e,t])},Kr=()=>{const[t,e]=Es(),n=vp(),{addPredefinedBlock:s}=bt(),r=yp();return{canPaste:g.useCallback(async i=>{if(t.length>0)return r(t,i);if(Gs())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},[r,t]),pasteBlocks:g.useCallback(async i=>{const l=Array.isArray(i)?i[0]:i;if(!d.isEmpty(t)){n(t,i),e([]),Gs()||await navigator.clipboard.writeText("");return}if(Gs()){pe.toast.error("Paste is not supported in Firefox");return}if(!(navigator!=null&&navigator.permissions)){pe.toast.error("Cannot check clipboard permissions.");return}try{if((await navigator.permissions.query({name:"clipboard-read"})).state==="denied"){pe.toast.error("Clipboard paste permission denied. Please allow clipboard access.");return}}catch{pe.toast.error("Failed to check clipboard permissions. Please allow clipboard access.");return}pe.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])}},Ti=t=>{const[e,n]=U(),s=J(),r=Cs(),o=Ur(),{undo:i,redo:l}=Tn(),[,c]=Es(),[,u]=Ii(),{canPaste:p,pasteBlocks:f}=Kr(),m=t?{document:t}:{};Xe.useHotkeys("ctrl+z,meta+z",h=>{h.preventDefault(),Ke.hasUndo()&&i()},{...m,preventDefault:!0},[i]),Xe.useHotkeys("ctrl+y,meta+y",h=>{h.preventDefault(),Ke.hasRedo()&&l()},{...m,preventDefault:!0},[l]),Xe.useHotkeys("ctrl+x,meta+x",h=>{const x=window.getSelection();x&&x.toString().length>0||(h.preventDefault(),d.isEmpty(e)||c(e))},{...m,enabled:!d.isEmpty(e)},[e,c]),Xe.useHotkeys("ctrl+c,meta+c",h=>{const x=window.getSelection();x&&x.toString().length>0||(h.preventDefault(),u(e))},{...m,enabled:!d.isEmpty(e)},[e,u]),Xe.useHotkeys("ctrl+v,meta+v",async()=>{await p(e[0])&&f(e)},{...m,enabled:!d.isEmpty(e),preventDefault:!0},[e,p,f]),Xe.useHotkeys("esc",()=>n([]),m,[n]),Xe.useHotkeys("ctrl+d,meta+d",()=>o(e),{...m,enabled:!d.isEmpty(e),preventDefault:!0},[e,o]),Xe.useHotkeys("del, backspace",h=>{h.preventDefault(),jr(d.get(s,"_type",""))&&r(e)},m,[e,r])},kp=()=>{const{document:t}=rt();return Ti(t),null},wp=()=>{const{t}=F.useTranslation(),{hasPermission:e}=qe(),n=e(se.ADD_BLOCK),s=Ye();return n?a.jsxs("div",{id:"add-block-bottom",className:"group relative w-full cursor-pointer py-2",children:[a.jsx("br",{}),!s&&a.jsx("div",{role:"button",onClick:()=>oe.publish(K.OPEN_ADD_BLOCK),className:"block h-1 rounded bg-primary opacity-0 duration-200 group-hover:opacity-100",children:a.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:[a.jsx(k.PlusIcon,{className:"size-2.5 stroke-[3]"})," ",t("Add block")]})}),a.jsx("br",{}),a.jsx("br",{}),a.jsx("br",{}),a.jsx("br",{})]}):null},_i=({theme:t})=>{const e=g.useMemo(()=>Ze.getChaiThemeCssVariables({theme:t,fontVariables:!0}),[t]);return a.jsx("style",{id:"chai-theme",dangerouslySetInnerHTML:{__html:e}})},Bi=Se.atomWithStorage("darkMode",!1),Rn=()=>{const[t,e]=j.useAtom(Bi);return[t,e]},Cp=()=>{const[t]=An(),e=In(),[n]=Rn(),{document:s,window:r}=rt();return g.useEffect(()=>{n?s==null||s.documentElement.classList.add("dark"):s==null||s.documentElement.classList.remove("dark")},[n,s]),g.useEffect(()=>{!r||!r.tailwind||(r.tailwind.config={darkMode:"class",theme:{extend:{container:{center:!0,padding:"1rem",screens:{"2xl":"1400px"}},...Ze.getChaiThemeOptions(e)}},plugins:[md,hd,pd,fd,Ze.plugin(function({addBase:o,theme:i}){o({"h1,h2,h3,h4,h5,h6":{fontFamily:i("fontFamily.heading")},body:{fontFamily:i("fontFamily.body"),color:i("colors.foreground"),backgroundColor:i("colors.background")}})})]})},[t,e,r]),a.jsxs(a.Fragment,{children:[a.jsx(_i,{theme:t}),a.jsx(Np,{}),a.jsx(Sp,{}),a.jsx(jp,{})]})},jp=()=>{const[t]=Ee(),[e]=U(),n=g.useMemo(()=>`${d.map(t,({id:s})=>`[data-style-id="${s}"]`).join(",")}{
|
|
126
126
|
outline: 1px solid ${e.length>0?"#42a1fc":"#de8f09"} !important; outline-offset: -1px;
|
|
127
127
|
}`,[t,e]);return a.jsx("style",{id:"selected-styling-blocks",dangerouslySetInnerHTML:{__html:n}})},Sp=()=>{const[t]=U(),e=g.useMemo(()=>`${d.map(t,n=>`[data-block-id="${n}"]`).join(",")}{
|
|
128
128
|
outline: 1px solid #42a1fc !important; outline-offset: -1px;
|
|
129
|
-
}`,[t]);return a.jsx("style",{id:"selected-blocks",dangerouslySetInnerHTML:{__html:e}})},Np=()=>{const[t]=An(),e=Da.useRegisteredFonts(),n=g.useMemo(()=>{const{heading:o,body:i}={heading:d.get(t,"fontFamily.heading"),body:d.get(t,"fontFamily.body")};return e.filter(l=>l.family===o||l.family===i)},[t==null?void 0:t.fontFamily,e]),s=g.useMemo(()=>Ze.getThemeFontsUrls(d.filter(n,o=>d.has(o,"url"))),[n]),r=g.useMemo(()=>Ze.getThemeCustomFontFace(d.filter(n,o=>d.has(o,"src"))),[n]);return a.jsxs(a.Fragment,{children:[s.map((o,i)=>a.jsx("link",{rel:"stylesheet",href:o},`google-font-${i}`)),a.jsx("style",{id:"chai-custom-fonts",dangerouslySetInnerHTML:{__html:r}})]})},Ep=({children:t,onMount:e,onResize:n})=>{const[,s]=U(),[,r]=Ee(),o=g.useRef(null),i=ke.useDebouncedCallback(()=>{const{clientWidth:c}=o.current;n(c)},[o.current],100);ke.useResizeObserver(o.current,i,o.current!==null),g.useEffect(()=>{const{clientWidth:c}=o.current;e(c)},[]);const l=g.useCallback(()=>{s([]),r([])},[s,r]);return a.jsx("div",{id:"main-content",onClick:l,className:"h-full w-full border-l-4 border-r-4 pb-0",ref:o,children:t})},Ap=()=>{const[,t]=U(),{onDragStart:e,onDragEnd:n}=rn(),[s]=te(),r=g.useRef(null),[o,i]=j.useAtom(tp),[l,c]=j.useAtom(ki),u=g.useCallback(m=>{var k;if(m.button!==0)return;const h=Date.now(),x=h-o;if(x<400&&x>0){c(2);return}i(h);const y=(k=m.target.closest("[data-block-id]"))==null?void 0:k.getAttribute("data-block-id");y&&(t([y]),r.current=y)},[t,o,i,l,c]),p=g.useCallback(m=>{if(!r.current)return;const h=d.find(s,{_id:r.current});h&&e(m,h,!1)},[s,e]),f=g.useCallback(()=>{n(),r.current=null},[n]);return{onMouseDown:u,onDragStart:p,onDragEnd:f}},Ip=()=>{const[t]=te();return g.useCallback((e,n)=>d.isEmpty(n)?{}:Object.entries(n).reduce((s,[r,o])=>{const i=[];let l=d.find(t,{_id:e});for(;l;)i.push(l),l=d.find(t,{_id:l._parent});const c=d.find(i,{_type:o.block});return c&&(s[r]=d.get(c,d.get(o,"prop"),null)),s},{}),[t])},Tp=j.atom("edit"),Ri=()=>{const[t,e]=j.useAtom(Tp);return{mode:t,setMode:e}},_p=({children:t,block:e})=>{const n=g.useMemo(()=>X.getRegisteredChaiBlock(e._type),[e._type]),s=d.get(n,"dataProviderDependencies"),r=d.get(n,"dataProvider"),o=d.get(n,"dataProviderMode","mock"),i=Pd(e,o,s,r);return t(i)},Bp=()=>a.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 xe(...t){return La.twMerge(Pa.clsx(t))}Se.atomWithStorage("chai-builder-blocks",[]);const Rp=Se.atomWithStorage("chai-builder-theme",Ze.defaultThemeValues);Se.atomWithStorage("chai-builder-design-tokens",{});Se.atomWithStorage("chai-builder-ai-context","");const lr=({editor:t,trigger:e,content:n,from:s,menuRef:r})=>{const{document:o}=rt(),[i,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,w;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||!o)return;const m=(w=r.current)==null?void 0:w.getBoundingClientRect();if(!m)return;let h=f.left,x=f.bottom+4,b,y;(m==null?void 0:m.left)+(m==null?void 0:m.width)+50>=o.body.offsetWidth&&(h=void 0,b=o.body.offsetWidth-(f==null?void 0:f.right)),x+202>=o.body.clientHeight&&(x=void 0,y=o.body.clientHeight-f.bottom+m.height),l({left:h,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 a.jsxs(a.Fragment,{children:[a.jsx("div",{ref:p,onClick:()=>u(m=>!m),className:"cursor-pointer",children:e}),c&&(i.left!==void 0||i.top!==void 0||i.right!==void 0||i.bottom!==void 0)&&rr.createPortal(a.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:a.jsx("div",{onClick:m=>m.stopPropagation(),className:"absolute rounded-md border border-gray-500 bg-white p-1.5 text-xs shadow-2xl",style:Object.assign({},{left:i.left,top:i.top,right:i.right,bottom:i.bottom}),children:typeof n=="function"?n(f):n})}),o.body,"chaibuilder-rte-dropdown-menu")]})}return a.jsx(a.Fragment,{children:a.jsxs(et,{open:c,onOpenChange:u,children:[a.jsx(tt,{className:"relative outline-none",asChild:!0,children:e}),a.jsx(Ge,{className:"z-50 rounded-md border bg-white p-1 text-xs shadow-xl",children:c&&(typeof n=="function"?n(()=>u(!1)):n)})]})})},Pp=(t,e,n)=>{const s=n==="settings",r=typeof e=="boolean"?e:e.some(o=>t.isActive(o));return{"rounded p-1":!0,"hover:bg-blue-900 hover:text-blue-100":!r&&!s,"hover:bg-blue-100 hover:text-blue-900":!r&&s,"bg-blue-500 text-white":r&&s,"bg-white text-blue-500":r&&!s}},Yo=({themeColors:t,onClose:e,color:n,onChange:s,onRemove:r})=>a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex w-[180px] flex-wrap gap-1 pb-2",children:(t==null?void 0:t.length)>0&&d.uniq(t).map(o=>{var i;return a.jsx("button",{className:xe("h-4 w-4 cursor-pointer rounded-full border border-gray-900 shadow duration-200 hover:scale-105 hover:shadow-xl",{"border-2":o===n}),style:{backgroundColor:o},onClick:()=>{s(o),e()},title:(i=o||"#000000")==null?void 0:i.toUpperCase()},o)})}),a.jsx(Jc.HexAlphaColorPicker,{color:n,onChange:s,style:{width:"200px",height:"200px"}}),a.jsxs("div",{className:"mt-1 flex items-center justify-between gap-1",children:[a.jsx(_.Input,{type:"text",value:n||"#000000f2",onChange:o=>s(o.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"}),a.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:()=>{r(),e()},title:"Remove",children:[a.jsx(v.Cross1Icon,{className:"h-3 w-3"})," Remove"]})]})]}),Lp=({textColor:t,highlightColor:e,onChangeTextColor:n,onChangeHighlightColor:s,onRemoveTextColor:r,onRemoveHighlightColor:o,onClose:i})=>{const[l]=Rn(),[c]=j.useAtom(Rp),u=(c==null?void 0:c.colors)||{},p=Object.values(u).map(h=>d.get(h,l?"1":"0")),[f,m]=g.useState("TEXT");return a.jsxs("div",{id:"rte-widget-color-picker",className:"px-1",children:[a.jsxs("div",{className:"mb-2 flex items-center justify-between rounded-md border bg-muted",children:[a.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:()=>m("TEXT"),children:"Text Color"}),a.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:()=>m("HIGHLIGHT"),children:"Highlight Color"})]}),f==="TEXT"?a.jsx(Yo,{themeColors:p,onClose:i,onChange:n,color:t,onRemove:r}):a.jsx(Yo,{themeColors:p,onClose:i,onChange:s,color:e,onRemove:o})]})},Mp=({editor:t,from:e,menuRef:n})=>{var w,E;const s=(w=t==null?void 0:t.getAttributes("textStyle"))==null?void 0:w.color,r=(E=t==null?void 0:t.getAttributes("highlight"))==null?void 0:E.color,[o,i]=g.useState(s||"#000000F2"),[l,c]=g.useState(r||"#00000057"),[u,p]=ke.useDebouncedState(o,150),[f,m]=ke.useDebouncedState(l,150),h=(A,I)=>{I?(i(A),p(A)):(t==null||t.chain().setColor(A).run(),i(A))},x=(A,I)=>{I?(c(A),m(A)):(t==null||t.chain().setHighlight({color:A}).run(),c(A))},b=()=>{t==null||t.chain().unsetColor().run(),i("#000000F2")},y=()=>{t==null||t.chain().unsetHighlight().run()};g.useEffect(()=>{r&&c(r)},[r]),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 a.jsx(lr,{editor:t,from:e,menuRef:n,trigger:a.jsxs("div",{className:xe("relative flex items-center",Pp(t,k,e)),title:"Text Color",children:[a.jsx("div",{className:"h-4 w-4 rounded-full",style:{backgroundColor:s||(e==="canvas"?"#FFFFFF":"#000000")}}),a.jsx(v.CaretDownIcon,{className:"h-3 w-3 opacity-50"})]}),content:A=>a.jsx(Lp,{textColor:o,highlightColor:l,onChangeTextColor:h,onChangeHighlightColor:x,onRemoveTextColor:b,onRemoveHighlightColor:y,onClose:A})})},Le=(t,e,n)=>{const s=n==="settings",r=typeof e=="boolean"?e:e.some(o=>t.isActive(o));return{"rounded p-1":!0,"hover:bg-blue-900 hover:text-blue-100":!r&&!s,"hover:bg-blue-100 hover:text-blue-900":!r&&s,"bg-blue-500 text-white":r&&s,"bg-white text-blue-500":r&&!s}},Pi=({editor:t,from:e="settings",onExpand:n})=>{const s=g.useRef(null);if(!t)return null;const r=()=>{const i=window.prompt("URL");i&&t.chain().focus().extendMarkRange("link").setLink({href:i}).run()},o=()=>{t.chain().focus().unsetLink().run()};return a.jsxs("div",{ref:s,id:"chai-rich-text-menu-bar",className:xe("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:[a.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleBold().run(),className:xe("",Le(t,["bold"],e)),title:"Bold",children:a.jsx(v.FontBoldIcon,{className:"h-4 w-4"})}),a.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleItalic().run(),className:xe("",Le(t,["italic"],e)),title:"Italic",children:a.jsx(v.FontItalicIcon,{className:"h-4 w-4"})}),a.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleUnderline().run(),className:xe("",Le(t,["underline"],e)),title:"Underline",children:a.jsx(v.UnderlineIcon,{className:"h-4 w-4"})}),a.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleStrike().run(),className:xe("",Le(t,["strike"],e)),title:"Strike",children:a.jsx(v.StrikethroughIcon,{className:"h-4 w-4"})}),a.jsx("div",{className:"mx-1 h-5 w-px self-center bg-border"}),a.jsx(Mp,{editor:t,from:e,menuRef:s}),a.jsx("div",{className:"mx-1 h-5 w-px self-center bg-border"}),a.jsx(lr,{editor:t,menuRef:s,from:e,trigger:a.jsxs("button",{type:"button",className:xe("flex items-center",Le(t,["bulletList","orderedList"],e)),title:"Bullet List",children:[a.jsx(v.ListBulletIcon,{className:"h-4 w-4"}),a.jsx(v.CaretDownIcon,{className:"h-3 w-3 opacity-50"})]}),content:i=>a.jsxs(a.Fragment,{children:[a.jsxs("div",{onClick:()=>{t.chain().focus().toggleBulletList().run(),i()},className:xe("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,["bulletList"],e)),children:[a.jsx(v.ListBulletIcon,{className:"h-4 w-4"})," Unordered List"]}),a.jsxs("div",{onClick:()=>{t.chain().focus().toggleOrderedList().run(),i()},className:xe("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,["orderedList"],e)),children:[a.jsx(v.ValueIcon,{className:"h-4 w-4"}),"Ordered List"]})]})}),a.jsx(lr,{editor:t,menuRef:s,from:e,trigger:a.jsxs("button",{type:"button",className:xe("flex items-center",Le(t,t.isActive({textAlign:"center"})||t.isActive({textAlign:"right"}),e)),title:"Text Alignment",children:[t.isActive({textAlign:"center"})?a.jsx(v.TextAlignCenterIcon,{className:"h-4 w-4"}):t.isActive({textAlign:"right"})?a.jsx(v.TextAlignRightIcon,{className:"h-4 w-4"}):a.jsx(v.TextAlignLeftIcon,{className:"h-4 w-4"}),a.jsx(v.CaretDownIcon,{className:"h-3 w-3 opacity-50"})]}),content:i=>a.jsxs(a.Fragment,{children:[a.jsxs("div",{onClick:()=>{t.chain().focus().setTextAlign("left").run(),i()},className:xe("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,t.isActive({textAlign:"left"}),e)),children:[a.jsx(v.TextAlignLeftIcon,{className:"h-4 w-4"})," Align Left"]}),a.jsxs("div",{onClick:()=>{t.chain().focus().setTextAlign("center").run(),i()},className:xe("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,t.isActive({textAlign:"center"}),e)),children:[a.jsx(v.TextAlignCenterIcon,{className:"h-4 w-4"})," Align Center"]}),a.jsxs("div",{onClick:()=>{t.chain().focus().setTextAlign("right").run(),i()},className:xe("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,t.isActive({textAlign:"right"}),e)),children:[a.jsx(v.TextAlignRightIcon,{className:"h-4 w-4"})," Align Right"]})]})}),t.isActive("link")?a.jsx("button",{type:"button",onClick:o,className:xe("",Le(t,["link"],e)),title:"Remove Link",disabled:!t.isActive("link"),children:a.jsx(v.LinkBreak2Icon,{className:"h-3.5 w-3.5"})}):a.jsx("button",{type:"button",onClick:r,className:xe("",Le(t,["link"],e)),title:"Add Link",children:a.jsx(v.Link2Icon,{className:"h-3.5 w-3.5"})}),n&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"mx-1 h-5 w-px self-center bg-border"}),a.jsx("button",{type:"button",onClick:n,className:xe("",Le(t,!1,e)),title:"Open in full screen mode",children:a.jsx(v.EnterFullScreenIcon,{className:"h-3.5 w-3.5"})})]})]})};function we(t){this.content=t}we.prototype={constructor:we,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,r=s.find(t),o=s.content.slice();return r==-1?o.push(n||t,e):(o[r+1]=e,n&&(o[r]=n)),new we(o)},remove:function(t){var e=this.find(t);if(e==-1)return this;var n=this.content.slice();return n.splice(e,2),new we(n)},addToStart:function(t,e){return new we([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var n=this.remove(t).content.slice();return n.push(t,e),new we(n)},addBefore:function(t,e,n){var s=this.remove(e),r=s.content.slice(),o=s.find(t);return r.splice(o==-1?r.length:o,0,e,n),new we(r)},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=we.from(t),t.size?new we(t.content.concat(this.subtract(t).content)):this},append:function(t){return t=we.from(t),t.size?new we(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=we.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}};we.from=function(t){if(t instanceof we)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new we(e)};function Li(t,e,n){for(let s=0;;s++){if(s==t.childCount||s==e.childCount)return t.childCount==e.childCount?null:n;let r=t.child(s),o=e.child(s);if(r==o){n+=r.nodeSize;continue}if(!r.sameMarkup(o))return n;if(r.isText&&r.text!=o.text){for(let i=0;r.text[i]==o.text[i];i++)n++;return n}if(r.content.size||o.content.size){let i=Li(r.content,o.content,n+1);if(i!=null)return i}n+=r.nodeSize}}function Mi(t,e,n,s){for(let r=t.childCount,o=e.childCount;;){if(r==0||o==0)return r==o?null:{a:n,b:s};let i=t.child(--r),l=e.child(--o),c=i.nodeSize;if(i==l){n-=c,s-=c;continue}if(!i.sameMarkup(l))return{a:n,b:s};if(i.isText&&i.text!=l.text){let u=0,p=Math.min(i.text.length,l.text.length);for(;u<p&&i.text[i.text.length-u-1]==l.text[l.text.length-u-1];)u++,n--,s--;return{a:n,b:s}}if(i.content.size||l.content.size){let u=Mi(i.content,l.content,n-1,s-1);if(u)return u}n-=c,s-=c}}class M{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,r=0,o){for(let i=0,l=0;l<n;i++){let c=this.content[i],u=l+c.nodeSize;if(u>e&&s(c,r+l,o||null,i)!==!1&&c.content.size){let p=l+1;c.nodesBetween(Math.max(0,e-p),Math.min(c.content.size,n-p),s,r+p)}l=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,s,r){let o="",i=!0;return this.nodesBetween(e,n,(l,c)=>{let u=l.isText?l.text.slice(Math.max(e,c)-c,n-c):l.isLeaf?r?typeof r=="function"?r(l):r:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&u||l.isTextblock)&&s&&(i?i=!1:o+=s),o+=u},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,s=e.firstChild,r=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(s)&&(r[r.length-1]=n.withText(n.text+s.text),o=1);o<e.content.length;o++)r.push(e.content[o]);return new M(r,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let s=[],r=0;if(n>e)for(let o=0,i=0;i<n;o++){let l=this.content[o],c=i+l.nodeSize;c>e&&((i<e||c>n)&&(l.isText?l=l.cut(Math.max(0,e-i),Math.min(l.text.length,n-i)):l=l.cut(Math.max(0,e-i-1),Math.min(l.content.size,n-i-1))),s.push(l),r+=l.nodeSize),i=c}return new M(s,r)}cutByIndex(e,n){return e==n?M.empty:e==0&&n==this.content.length?this:new M(this.content.slice(e,n))}replaceChild(e,n){let s=this.content[e];if(s==n)return this;let r=this.content.slice(),o=this.size+n.nodeSize-s.nodeSize;return r[e]=n,new M(r,o)}addToStart(e){return new M([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new M(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 r=this.content[n];e(r,s,n),s+=r.nodeSize}}findDiffStart(e,n=0){return Li(this,e,n)}findDiffEnd(e,n=this.size,s=e.size){return Mi(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 r=this.child(n),o=s+r.nodeSize;if(o>=e)return o==e?Wn(n+1,o):Wn(n,s);s=o}}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 M.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new M(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return M.empty;let n,s=0;for(let r=0;r<e.length;r++){let o=e[r];s+=o.nodeSize,r&&o.isText&&e[r-1].sameMarkup(o)?(n||(n=e.slice(0,r)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new M(n||e,s)}static from(e){if(!e)return M.empty;if(e instanceof M)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new M([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}M.empty=new M([],0);const Us={index:0,offset:0};function Wn(t,e){return Us.index=t,Us.offset=e,Us}function rs(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(!rs(t[s],e[s]))return!1}else{for(let s in t)if(!(s in e)||!rs(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 r=0;r<e.length;r++){let o=e[r];if(this.eq(o))return e;if(this.type.excludes(o.type))n||(n=e.slice(0,r));else{if(o.type.excludes(this.type))return e;!s&&o.type.rank>this.type.rank&&(n||(n=e.slice(0,r)),n.push(this),s=!0),n&&n.push(o)}}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&&rs(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 r=s.create(n.attrs);return s.checkAttrs(r.attrs),r}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,r)=>s.type.rank-r.type.rank),n}}Q.none=[];class as extends Error{}class V{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=Oi(this.content,e+this.openStart,n);return s&&new V(s,this.openStart,this.openEnd)}removeBetween(e,n){return new V(Di(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 V.empty;let s=n.openStart||0,r=n.openEnd||0;if(typeof s!="number"||typeof r!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new V(M.fromJSON(e,n.content),s,r)}static maxOpen(e,n=!0){let s=0,r=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)s++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)r++;return new V(e,s,r)}}V.empty=new V(M.empty,0,0);function Di(t,e,n){let{index:s,offset:r}=t.findIndex(e),o=t.maybeChild(s),{index:i,offset:l}=t.findIndex(n);if(r==e||o.isText){if(l!=n&&!t.child(i).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(s!=i)throw new RangeError("Removing non-flat range");return t.replaceChild(s,o.copy(Di(o.content,e-r-1,n-r-1)))}function Oi(t,e,n,s){let{index:r,offset:o}=t.findIndex(e),i=t.maybeChild(r);if(o==e||i.isText)return s&&!s.canReplace(r,r,n)?null:t.cut(0,e).append(n).append(t.cut(e));let l=Oi(i.content,e-o-1,n,i);return l&&t.replaceChild(r,i.copy(l))}function Dp(t,e,n){if(n.openStart>t.depth)throw new as("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new as("Inconsistent open depths");return $i(t,e,n,0)}function $i(t,e,n,s){let r=t.index(s),o=t.node(s);if(r==e.index(s)&&s<t.depth-n.openStart){let i=$i(t,e,n,s+1);return o.copy(o.content.replaceChild(r,i))}else if(n.content.size)if(!n.openStart&&!n.openEnd&&t.depth==s&&e.depth==s){let i=t.parent,l=i.content;return _t(i,l.cut(0,t.parentOffset).append(n.content).append(l.cut(e.parentOffset)))}else{let{start:i,end:l}=Op(n,t);return _t(o,zi(t,i,l,e,s))}else return _t(o,is(t,e,s))}function Fi(t,e){if(!e.type.compatibleContent(t.type))throw new as("Cannot join "+e.type.name+" onto "+t.type.name)}function cr(t,e,n){let s=t.node(n);return Fi(s,e.node(n)),s}function Tt(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 gn(t,e,n,s){let r=(e||t).node(n),o=0,i=e?e.index(n):r.childCount;t&&(o=t.index(n),t.depth>n?o++:t.textOffset&&(Tt(t.nodeAfter,s),o++));for(let l=o;l<i;l++)Tt(r.child(l),s);e&&e.depth==n&&e.textOffset&&Tt(e.nodeBefore,s)}function _t(t,e){return t.type.checkContent(e),t.copy(e)}function zi(t,e,n,s,r){let o=t.depth>r&&cr(t,e,r+1),i=s.depth>r&&cr(n,s,r+1),l=[];return gn(null,t,r,l),o&&i&&e.index(r)==n.index(r)?(Fi(o,i),Tt(_t(o,zi(t,e,n,s,r+1)),l)):(o&&Tt(_t(o,is(t,e,r+1)),l),gn(e,n,r,l),i&&Tt(_t(i,is(n,s,r+1)),l)),gn(s,null,r,l),new M(l)}function is(t,e,n){let s=[];if(gn(null,t,n,s),t.depth>n){let r=cr(t,e,n+1);Tt(_t(r,is(t,e,n+1)),s)}return gn(e,null,n,s),new M(s)}function Op(t,e){let n=e.depth-t.openStart,r=e.node(n).copy(t.content);for(let o=n-1;o>=0;o--)r=e.node(o).copy(M.from(r));return{start:r.resolveNoCache(t.openStart+n),end:r.resolveNoCache(r.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],r=e.child(n);return s?e.child(n).cut(s):r}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],r=n==0?0:this.path[n*3-1]+1;for(let o=0;o<e;o++)r+=s.child(o).nodeSize;return r}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),r=e.maybeChild(n);if(!s){let l=s;s=r,r=l}let o=s.marks;for(var i=0;i<o.length;i++)o[i].type.spec.inclusive===!1&&(!r||!o[i].isInSet(r.marks))&&(o=o[i--].removeFromSet(o));return o}marksAcross(e){let n=this.parent.maybeChild(this.index());if(!n||!n.isInline)return null;let s=n.marks,r=e.parent.maybeChild(e.index());for(var o=0;o<s.length;o++)s[o].type.spec.inclusive===!1&&(!r||!s[o].isInSet(r.marks))&&(s=s[o--].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 ls(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=[],r=0,o=n;for(let i=e;;){let{index:l,offset:c}=i.content.findIndex(o),u=o-c;if(s.push(i,l,r+c),!u||(i=i.child(l),i.isText))break;o=u-1,r+=c+1}return new kn(n,s,o)}static resolveCached(e,n){let s=Xo.get(e);if(s)for(let o=0;o<s.elts.length;o++){let i=s.elts[o];if(i.pos==n)return i}else Xo.set(e,s=new $p);let r=s.elts[s.i]=kn.resolve(e,n);return s.i=(s.i+1)%Fp,r}}class $p{constructor(){this.elts=[],this.i=0}}const Fp=12,Xo=new WeakMap;class ls{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 zp=Object.create(null);let Bt=class dr{constructor(e,n,s,r=Q.none){this.type=e,this.attrs=n,this.marks=r,this.content=s||M.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,r=0){this.content.nodesBetween(e,n,s,r,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,r){return this.content.textBetween(e,n,s,r)}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&&rs(this.attrs,n||e.defaultAttrs||zp)&&Q.sameSet(this.marks,s||Q.none)}copy(e=null){return e==this.content?this:new dr(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new dr(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 V.empty;let r=this.resolve(e),o=this.resolve(n),i=s?0:r.sharedDepth(n),l=r.start(i),u=r.node(i).content.cut(r.pos-l,o.pos-l);return new V(u,r.depth-i,o.depth-i)}replace(e,n,s){return Dp(this.resolve(e),this.resolve(n),s)}nodeAt(e){for(let n=this;;){let{index:s,offset:r}=n.content.findIndex(e);if(n=n.maybeChild(s),!n)return null;if(r==e||n.isText)return n;e-=r+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 r=this.content.child(n-1);return{node:r,index:n-1,offset:s-r.nodeSize}}resolve(e){return kn.resolveCached(this,e)}resolveNoCache(e){return kn.resolve(this,e)}rangeHasMark(e,n,s){let r=!1;return n>e&&this.nodesBetween(e,n,o=>(s.isInSet(o.marks)&&(r=!0),!r)),r}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()+")"),Hi(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=M.empty,r=0,o=s.childCount){let i=this.contentMatchAt(e).matchFragment(s,r,o),l=i&&i.matchFragment(this.content,n);if(!l||!l.validEnd)return!1;for(let c=r;c<o;c++)if(!this.type.allowsMarks(s.child(c).marks))return!1;return!0}canReplaceWith(e,n,s,r){if(r&&!this.type.allowsMarks(r))return!1;let o=this.contentMatchAt(e).matchType(s),i=o&&o.matchFragment(this.content,n);return i?i.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 r=M.fromJSON(e,n.content),o=e.nodeType(n.type).create(n.attrs,r,s);return o.type.checkAttrs(o.attrs),o}};Bt.prototype.text=void 0;class cs extends Bt{constructor(e,n,s,r){if(super(e,n,null,r),!s)throw new RangeError("Empty text nodes are not allowed");this.text=s}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Hi(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 cs(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new cs(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 Hi(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class Dt{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let s=new Hp(e,n);if(s.next==null)return Dt.empty;let r=Vi(s);s.next&&s.err("Unexpected trailing text");let o=Yp(Kp(r));return Xp(o,s),o}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 r=this;for(let o=n;r&&o<s;o++)r=r.matchType(e.child(o).type);return r}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 r=[this];function o(i,l){let c=i.matchFragment(e,s);if(c&&(!n||c.validEnd))return M.from(l.map(u=>u.createAndFill()));for(let u=0;u<i.next.length;u++){let{type:p,next:f}=i.next[u];if(!(p.isText||p.hasRequiredAttrs())&&r.indexOf(f)==-1){r.push(f);let m=o(f,l.concat(p));if(m)return m}}return null}return o(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 r=s.shift(),o=r.match;if(o.matchType(e)){let i=[];for(let l=r;l.type;l=l.via)i.push(l.type);return i.reverse()}for(let i=0;i<o.next.length;i++){let{type:l,next:c}=o.next[i];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in n)&&(!r.type||c.validEnd)&&(s.push({match:l.contentMatch,type:l,via:r}),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 r=0;r<s.next.length;r++)e.indexOf(s.next[r].next)==-1&&n(s.next[r].next)}return n(this),e.map((s,r)=>{let o=r+(s.validEnd?"*":" ")+" ";for(let i=0;i<s.next.length;i++)o+=(i?", ":"")+s.next[i].type.name+"->"+e.indexOf(s.next[i].next);return o}).join(`
|
|
129
|
+
}`,[t]);return a.jsx("style",{id:"selected-blocks",dangerouslySetInnerHTML:{__html:e}})},Np=()=>{const[t]=An(),e=Da.useRegisteredFonts(),n=g.useMemo(()=>{const{heading:o,body:i}={heading:d.get(t,"fontFamily.heading"),body:d.get(t,"fontFamily.body")};return e.filter(l=>l.family===o||l.family===i)},[t==null?void 0:t.fontFamily,e]),s=g.useMemo(()=>Ze.getThemeFontsUrls(d.filter(n,o=>d.has(o,"url"))),[n]),r=g.useMemo(()=>Ze.getThemeCustomFontFace(d.filter(n,o=>d.has(o,"src"))),[n]);return a.jsxs(a.Fragment,{children:[s.map((o,i)=>a.jsx("link",{rel:"stylesheet",href:o},`google-font-${i}`)),a.jsx("style",{id:"chai-custom-fonts",dangerouslySetInnerHTML:{__html:r}})]})},Ep=({children:t,onMount:e,onResize:n})=>{const[,s]=U(),[,r]=Ee(),o=g.useRef(null),i=ke.useDebouncedCallback(()=>{const{clientWidth:c}=o.current;n(c)},[o.current],100);ke.useResizeObserver(o.current,i,o.current!==null),g.useEffect(()=>{const{clientWidth:c}=o.current;e(c)},[]);const l=g.useCallback(()=>{s([]),r([])},[s,r]);return a.jsx("div",{id:"main-content",onClick:l,className:"h-full w-full border-l-4 border-r-4 pb-0",ref:o,children:t})},Ap=()=>{const[,t]=U(),{onDragStart:e,onDragEnd:n}=rn(),[s]=te(),r=g.useRef(null),[o,i]=j.useAtom(tp),[l,c]=j.useAtom(ki),u=g.useCallback(m=>{var v;if(m.button!==0)return;const h=Date.now(),x=h-o;if(x<400&&x>0){c(2);return}i(h);const y=(v=m.target.closest("[data-block-id]"))==null?void 0:v.getAttribute("data-block-id");y&&(t([y]),r.current=y)},[t,o,i,l,c]),p=g.useCallback(m=>{if(!r.current)return;const h=d.find(s,{_id:r.current});h&&e(m,h,!1)},[s,e]),f=g.useCallback(()=>{n(),r.current=null},[n]);return{onMouseDown:u,onDragStart:p,onDragEnd:f}},Ip=()=>{const[t]=te();return g.useCallback((e,n)=>d.isEmpty(n)?{}:Object.entries(n).reduce((s,[r,o])=>{const i=[];let l=d.find(t,{_id:e});for(;l;)i.push(l),l=d.find(t,{_id:l._parent});const c=d.find(i,{_type:o.block});return c&&(s[r]=d.get(c,d.get(o,"prop"),null)),s},{}),[t])},Tp=j.atom("edit"),Ri=()=>{const[t,e]=j.useAtom(Tp);return{mode:t,setMode:e}},_p=({children:t,block:e})=>{const n=g.useMemo(()=>X.getRegisteredChaiBlock(e._type),[e._type]),s=d.get(n,"dataProviderDependencies"),r=d.get(n,"dataProvider"),o=d.get(n,"dataProviderMode","mock"),i=Pd(e,o,s,r);return t(i)},Bp=()=>a.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 xe(...t){return La.twMerge(Pa.clsx(t))}Se.atomWithStorage("chai-builder-blocks",[]);const Rp=Se.atomWithStorage("chai-builder-theme",Ze.defaultThemeValues);Se.atomWithStorage("chai-builder-design-tokens",{});Se.atomWithStorage("chai-builder-ai-context","");const lr=({editor:t,trigger:e,content:n,from:s,menuRef:r})=>{const{document:o}=rt(),[i,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 v,w;if(!c){l({left:void 0,right:void 0,top:void 0,bottom:void 0});return}const f=(v=p.current)==null?void 0:v.getBoundingClientRect();if(!f||!o)return;const m=(w=r.current)==null?void 0:w.getBoundingClientRect();if(!m)return;let h=f.left,x=f.bottom+4,b,y;(m==null?void 0:m.left)+(m==null?void 0:m.width)+50>=o.body.offsetWidth&&(h=void 0,b=o.body.offsetWidth-(f==null?void 0:f.right)),x+202>=o.body.clientHeight&&(x=void 0,y=o.body.clientHeight-f.bottom+m.height),l({left:h,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 a.jsxs(a.Fragment,{children:[a.jsx("div",{ref:p,onClick:()=>u(m=>!m),className:"cursor-pointer",children:e}),c&&(i.left!==void 0||i.top!==void 0||i.right!==void 0||i.bottom!==void 0)&&rr.createPortal(a.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:a.jsx("div",{onClick:m=>m.stopPropagation(),className:"absolute rounded-md border border-gray-500 bg-white p-1.5 text-xs shadow-2xl",style:Object.assign({},{left:i.left,top:i.top,right:i.right,bottom:i.bottom}),children:typeof n=="function"?n(f):n})}),o.body,"chaibuilder-rte-dropdown-menu")]})}return a.jsx(a.Fragment,{children:a.jsxs(et,{open:c,onOpenChange:u,children:[a.jsx(tt,{className:"relative outline-none",asChild:!0,children:e}),a.jsx(Ge,{className:"z-50 rounded-md border bg-white p-1 text-xs shadow-xl",children:c&&(typeof n=="function"?n(()=>u(!1)):n)})]})})},Pp=(t,e,n)=>{const s=n==="settings",r=typeof e=="boolean"?e:e.some(o=>t.isActive(o));return{"rounded p-1":!0,"hover:bg-blue-900 hover:text-blue-100":!r&&!s,"hover:bg-blue-100 hover:text-blue-900":!r&&s,"bg-blue-500 text-white":r&&s,"bg-white text-blue-500":r&&!s}},Yo=({themeColors:t,onClose:e,color:n,onChange:s,onRemove:r})=>a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex w-[180px] flex-wrap gap-1 pb-2",children:(t==null?void 0:t.length)>0&&d.uniq(t).map(o=>{var i;return a.jsx("button",{className:xe("h-4 w-4 cursor-pointer rounded-full border border-gray-900 shadow duration-200 hover:scale-105 hover:shadow-xl",{"border-2":o===n}),style:{backgroundColor:o},onClick:()=>{s(o),e()},title:(i=o||"#000000")==null?void 0:i.toUpperCase()},o)})}),a.jsx(Jc.HexAlphaColorPicker,{color:n,onChange:s,style:{width:"200px",height:"200px"}}),a.jsxs("div",{className:"mt-1 flex items-center justify-between gap-1",children:[a.jsx(B.Input,{type:"text",value:n||"#000000f2",onChange:o=>s(o.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"}),a.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:()=>{r(),e()},title:"Remove",children:[a.jsx(k.Cross1Icon,{className:"h-3 w-3"})," Remove"]})]})]}),Lp=({textColor:t,highlightColor:e,onChangeTextColor:n,onChangeHighlightColor:s,onRemoveTextColor:r,onRemoveHighlightColor:o,onClose:i})=>{const[l]=Rn(),[c]=j.useAtom(Rp),u=(c==null?void 0:c.colors)||{},p=Object.values(u).map(h=>d.get(h,l?"1":"0")),[f,m]=g.useState("TEXT");return a.jsxs("div",{id:"rte-widget-color-picker",className:"px-1",children:[a.jsxs("div",{className:"mb-2 flex items-center justify-between rounded-md border bg-muted",children:[a.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:()=>m("TEXT"),children:"Text Color"}),a.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:()=>m("HIGHLIGHT"),children:"Highlight Color"})]}),f==="TEXT"?a.jsx(Yo,{themeColors:p,onClose:i,onChange:n,color:t,onRemove:r}):a.jsx(Yo,{themeColors:p,onClose:i,onChange:s,color:e,onRemove:o})]})},Mp=({editor:t,from:e,menuRef:n})=>{var w,N;const s=(w=t==null?void 0:t.getAttributes("textStyle"))==null?void 0:w.color,r=(N=t==null?void 0:t.getAttributes("highlight"))==null?void 0:N.color,[o,i]=g.useState(s||"#000000F2"),[l,c]=g.useState(r||"#00000057"),[u,p]=ke.useDebouncedState(o,150),[f,m]=ke.useDebouncedState(l,150),h=(E,I)=>{I?(i(E),p(E)):(t==null||t.chain().setColor(E).run(),i(E))},x=(E,I)=>{I?(c(E),m(E)):(t==null||t.chain().setHighlight({color:E}).run(),c(E))},b=()=>{t==null||t.chain().unsetColor().run(),i("#000000F2")},y=()=>{t==null||t.chain().unsetHighlight().run()};g.useEffect(()=>{r&&c(r)},[r]),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 v=!!s;return a.jsx(lr,{editor:t,from:e,menuRef:n,trigger:a.jsxs("div",{className:xe("relative flex items-center",Pp(t,v,e)),title:"Text Color",children:[a.jsx("div",{className:"h-4 w-4 rounded-full",style:{backgroundColor:s||(e==="canvas"?"#FFFFFF":"#000000")}}),a.jsx(k.CaretDownIcon,{className:"h-3 w-3 opacity-50"})]}),content:E=>a.jsx(Lp,{textColor:o,highlightColor:l,onChangeTextColor:h,onChangeHighlightColor:x,onRemoveTextColor:b,onRemoveHighlightColor:y,onClose:E})})},Le=(t,e,n)=>{const s=n==="settings",r=typeof e=="boolean"?e:e.some(o=>t.isActive(o));return{"rounded p-1":!0,"hover:bg-blue-900 hover:text-blue-100":!r&&!s,"hover:bg-blue-100 hover:text-blue-900":!r&&s,"bg-blue-500 text-white":r&&s,"bg-white text-blue-500":r&&!s}},Pi=({editor:t,from:e="settings",onExpand:n})=>{const s=g.useRef(null);if(!t)return null;const r=()=>{const i=window.prompt("URL");i&&t.chain().focus().extendMarkRange("link").setLink({href:i}).run()},o=()=>{t.chain().focus().unsetLink().run()};return a.jsxs("div",{ref:s,id:"chai-rich-text-menu-bar",className:xe("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:[a.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleBold().run(),className:xe("",Le(t,["bold"],e)),title:"Bold",children:a.jsx(k.FontBoldIcon,{className:"h-4 w-4"})}),a.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleItalic().run(),className:xe("",Le(t,["italic"],e)),title:"Italic",children:a.jsx(k.FontItalicIcon,{className:"h-4 w-4"})}),a.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleUnderline().run(),className:xe("",Le(t,["underline"],e)),title:"Underline",children:a.jsx(k.UnderlineIcon,{className:"h-4 w-4"})}),a.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleStrike().run(),className:xe("",Le(t,["strike"],e)),title:"Strike",children:a.jsx(k.StrikethroughIcon,{className:"h-4 w-4"})}),a.jsx("div",{className:"mx-1 h-5 w-px self-center bg-border"}),a.jsx(Mp,{editor:t,from:e,menuRef:s}),a.jsx("div",{className:"mx-1 h-5 w-px self-center bg-border"}),a.jsx(lr,{editor:t,menuRef:s,from:e,trigger:a.jsxs("button",{type:"button",className:xe("flex items-center",Le(t,["bulletList","orderedList"],e)),title:"Bullet List",children:[a.jsx(k.ListBulletIcon,{className:"h-4 w-4"}),a.jsx(k.CaretDownIcon,{className:"h-3 w-3 opacity-50"})]}),content:i=>a.jsxs(a.Fragment,{children:[a.jsxs("div",{onClick:()=>{t.chain().focus().toggleBulletList().run(),i()},className:xe("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,["bulletList"],e)),children:[a.jsx(k.ListBulletIcon,{className:"h-4 w-4"})," Unordered List"]}),a.jsxs("div",{onClick:()=>{t.chain().focus().toggleOrderedList().run(),i()},className:xe("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,["orderedList"],e)),children:[a.jsx(k.ValueIcon,{className:"h-4 w-4"}),"Ordered List"]})]})}),a.jsx(lr,{editor:t,menuRef:s,from:e,trigger:a.jsxs("button",{type:"button",className:xe("flex items-center",Le(t,t.isActive({textAlign:"center"})||t.isActive({textAlign:"right"}),e)),title:"Text Alignment",children:[t.isActive({textAlign:"center"})?a.jsx(k.TextAlignCenterIcon,{className:"h-4 w-4"}):t.isActive({textAlign:"right"})?a.jsx(k.TextAlignRightIcon,{className:"h-4 w-4"}):a.jsx(k.TextAlignLeftIcon,{className:"h-4 w-4"}),a.jsx(k.CaretDownIcon,{className:"h-3 w-3 opacity-50"})]}),content:i=>a.jsxs(a.Fragment,{children:[a.jsxs("div",{onClick:()=>{t.chain().focus().setTextAlign("left").run(),i()},className:xe("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,t.isActive({textAlign:"left"}),e)),children:[a.jsx(k.TextAlignLeftIcon,{className:"h-4 w-4"})," Align Left"]}),a.jsxs("div",{onClick:()=>{t.chain().focus().setTextAlign("center").run(),i()},className:xe("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,t.isActive({textAlign:"center"}),e)),children:[a.jsx(k.TextAlignCenterIcon,{className:"h-4 w-4"})," Align Center"]}),a.jsxs("div",{onClick:()=>{t.chain().focus().setTextAlign("right").run(),i()},className:xe("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",Le(t,t.isActive({textAlign:"right"}),e)),children:[a.jsx(k.TextAlignRightIcon,{className:"h-4 w-4"})," Align Right"]})]})}),t.isActive("link")?a.jsx("button",{type:"button",onClick:o,className:xe("",Le(t,["link"],e)),title:"Remove Link",disabled:!t.isActive("link"),children:a.jsx(k.LinkBreak2Icon,{className:"h-3.5 w-3.5"})}):a.jsx("button",{type:"button",onClick:r,className:xe("",Le(t,["link"],e)),title:"Add Link",children:a.jsx(k.Link2Icon,{className:"h-3.5 w-3.5"})}),n&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"mx-1 h-5 w-px self-center bg-border"}),a.jsx("button",{type:"button",onClick:n,className:xe("",Le(t,!1,e)),title:"Open in full screen mode",children:a.jsx(k.EnterFullScreenIcon,{className:"h-3.5 w-3.5"})})]})]})};function we(t){this.content=t}we.prototype={constructor:we,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,r=s.find(t),o=s.content.slice();return r==-1?o.push(n||t,e):(o[r+1]=e,n&&(o[r]=n)),new we(o)},remove:function(t){var e=this.find(t);if(e==-1)return this;var n=this.content.slice();return n.splice(e,2),new we(n)},addToStart:function(t,e){return new we([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var n=this.remove(t).content.slice();return n.push(t,e),new we(n)},addBefore:function(t,e,n){var s=this.remove(e),r=s.content.slice(),o=s.find(t);return r.splice(o==-1?r.length:o,0,e,n),new we(r)},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=we.from(t),t.size?new we(t.content.concat(this.subtract(t).content)):this},append:function(t){return t=we.from(t),t.size?new we(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=we.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}};we.from=function(t){if(t instanceof we)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new we(e)};function Li(t,e,n){for(let s=0;;s++){if(s==t.childCount||s==e.childCount)return t.childCount==e.childCount?null:n;let r=t.child(s),o=e.child(s);if(r==o){n+=r.nodeSize;continue}if(!r.sameMarkup(o))return n;if(r.isText&&r.text!=o.text){for(let i=0;r.text[i]==o.text[i];i++)n++;return n}if(r.content.size||o.content.size){let i=Li(r.content,o.content,n+1);if(i!=null)return i}n+=r.nodeSize}}function Mi(t,e,n,s){for(let r=t.childCount,o=e.childCount;;){if(r==0||o==0)return r==o?null:{a:n,b:s};let i=t.child(--r),l=e.child(--o),c=i.nodeSize;if(i==l){n-=c,s-=c;continue}if(!i.sameMarkup(l))return{a:n,b:s};if(i.isText&&i.text!=l.text){let u=0,p=Math.min(i.text.length,l.text.length);for(;u<p&&i.text[i.text.length-u-1]==l.text[l.text.length-u-1];)u++,n--,s--;return{a:n,b:s}}if(i.content.size||l.content.size){let u=Mi(i.content,l.content,n-1,s-1);if(u)return u}n-=c,s-=c}}class M{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,r=0,o){for(let i=0,l=0;l<n;i++){let c=this.content[i],u=l+c.nodeSize;if(u>e&&s(c,r+l,o||null,i)!==!1&&c.content.size){let p=l+1;c.nodesBetween(Math.max(0,e-p),Math.min(c.content.size,n-p),s,r+p)}l=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,s,r){let o="",i=!0;return this.nodesBetween(e,n,(l,c)=>{let u=l.isText?l.text.slice(Math.max(e,c)-c,n-c):l.isLeaf?r?typeof r=="function"?r(l):r:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&u||l.isTextblock)&&s&&(i?i=!1:o+=s),o+=u},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,s=e.firstChild,r=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(s)&&(r[r.length-1]=n.withText(n.text+s.text),o=1);o<e.content.length;o++)r.push(e.content[o]);return new M(r,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let s=[],r=0;if(n>e)for(let o=0,i=0;i<n;o++){let l=this.content[o],c=i+l.nodeSize;c>e&&((i<e||c>n)&&(l.isText?l=l.cut(Math.max(0,e-i),Math.min(l.text.length,n-i)):l=l.cut(Math.max(0,e-i-1),Math.min(l.content.size,n-i-1))),s.push(l),r+=l.nodeSize),i=c}return new M(s,r)}cutByIndex(e,n){return e==n?M.empty:e==0&&n==this.content.length?this:new M(this.content.slice(e,n))}replaceChild(e,n){let s=this.content[e];if(s==n)return this;let r=this.content.slice(),o=this.size+n.nodeSize-s.nodeSize;return r[e]=n,new M(r,o)}addToStart(e){return new M([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new M(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 r=this.content[n];e(r,s,n),s+=r.nodeSize}}findDiffStart(e,n=0){return Li(this,e,n)}findDiffEnd(e,n=this.size,s=e.size){return Mi(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 r=this.child(n),o=s+r.nodeSize;if(o>=e)return o==e?Wn(n+1,o):Wn(n,s);s=o}}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 M.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new M(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return M.empty;let n,s=0;for(let r=0;r<e.length;r++){let o=e[r];s+=o.nodeSize,r&&o.isText&&e[r-1].sameMarkup(o)?(n||(n=e.slice(0,r)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new M(n||e,s)}static from(e){if(!e)return M.empty;if(e instanceof M)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new M([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}M.empty=new M([],0);const Us={index:0,offset:0};function Wn(t,e){return Us.index=t,Us.offset=e,Us}function rs(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(!rs(t[s],e[s]))return!1}else{for(let s in t)if(!(s in e)||!rs(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 r=0;r<e.length;r++){let o=e[r];if(this.eq(o))return e;if(this.type.excludes(o.type))n||(n=e.slice(0,r));else{if(o.type.excludes(this.type))return e;!s&&o.type.rank>this.type.rank&&(n||(n=e.slice(0,r)),n.push(this),s=!0),n&&n.push(o)}}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&&rs(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 r=s.create(n.attrs);return s.checkAttrs(r.attrs),r}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,r)=>s.type.rank-r.type.rank),n}}Q.none=[];class as extends Error{}class V{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=Oi(this.content,e+this.openStart,n);return s&&new V(s,this.openStart,this.openEnd)}removeBetween(e,n){return new V(Di(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 V.empty;let s=n.openStart||0,r=n.openEnd||0;if(typeof s!="number"||typeof r!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new V(M.fromJSON(e,n.content),s,r)}static maxOpen(e,n=!0){let s=0,r=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)s++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)r++;return new V(e,s,r)}}V.empty=new V(M.empty,0,0);function Di(t,e,n){let{index:s,offset:r}=t.findIndex(e),o=t.maybeChild(s),{index:i,offset:l}=t.findIndex(n);if(r==e||o.isText){if(l!=n&&!t.child(i).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(s!=i)throw new RangeError("Removing non-flat range");return t.replaceChild(s,o.copy(Di(o.content,e-r-1,n-r-1)))}function Oi(t,e,n,s){let{index:r,offset:o}=t.findIndex(e),i=t.maybeChild(r);if(o==e||i.isText)return s&&!s.canReplace(r,r,n)?null:t.cut(0,e).append(n).append(t.cut(e));let l=Oi(i.content,e-o-1,n,i);return l&&t.replaceChild(r,i.copy(l))}function Dp(t,e,n){if(n.openStart>t.depth)throw new as("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new as("Inconsistent open depths");return $i(t,e,n,0)}function $i(t,e,n,s){let r=t.index(s),o=t.node(s);if(r==e.index(s)&&s<t.depth-n.openStart){let i=$i(t,e,n,s+1);return o.copy(o.content.replaceChild(r,i))}else if(n.content.size)if(!n.openStart&&!n.openEnd&&t.depth==s&&e.depth==s){let i=t.parent,l=i.content;return _t(i,l.cut(0,t.parentOffset).append(n.content).append(l.cut(e.parentOffset)))}else{let{start:i,end:l}=Op(n,t);return _t(o,zi(t,i,l,e,s))}else return _t(o,is(t,e,s))}function Fi(t,e){if(!e.type.compatibleContent(t.type))throw new as("Cannot join "+e.type.name+" onto "+t.type.name)}function cr(t,e,n){let s=t.node(n);return Fi(s,e.node(n)),s}function Tt(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 gn(t,e,n,s){let r=(e||t).node(n),o=0,i=e?e.index(n):r.childCount;t&&(o=t.index(n),t.depth>n?o++:t.textOffset&&(Tt(t.nodeAfter,s),o++));for(let l=o;l<i;l++)Tt(r.child(l),s);e&&e.depth==n&&e.textOffset&&Tt(e.nodeBefore,s)}function _t(t,e){return t.type.checkContent(e),t.copy(e)}function zi(t,e,n,s,r){let o=t.depth>r&&cr(t,e,r+1),i=s.depth>r&&cr(n,s,r+1),l=[];return gn(null,t,r,l),o&&i&&e.index(r)==n.index(r)?(Fi(o,i),Tt(_t(o,zi(t,e,n,s,r+1)),l)):(o&&Tt(_t(o,is(t,e,r+1)),l),gn(e,n,r,l),i&&Tt(_t(i,is(n,s,r+1)),l)),gn(s,null,r,l),new M(l)}function is(t,e,n){let s=[];if(gn(null,t,n,s),t.depth>n){let r=cr(t,e,n+1);Tt(_t(r,is(t,e,n+1)),s)}return gn(e,null,n,s),new M(s)}function Op(t,e){let n=e.depth-t.openStart,r=e.node(n).copy(t.content);for(let o=n-1;o>=0;o--)r=e.node(o).copy(M.from(r));return{start:r.resolveNoCache(t.openStart+n),end:r.resolveNoCache(r.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],r=e.child(n);return s?e.child(n).cut(s):r}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],r=n==0?0:this.path[n*3-1]+1;for(let o=0;o<e;o++)r+=s.child(o).nodeSize;return r}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),r=e.maybeChild(n);if(!s){let l=s;s=r,r=l}let o=s.marks;for(var i=0;i<o.length;i++)o[i].type.spec.inclusive===!1&&(!r||!o[i].isInSet(r.marks))&&(o=o[i--].removeFromSet(o));return o}marksAcross(e){let n=this.parent.maybeChild(this.index());if(!n||!n.isInline)return null;let s=n.marks,r=e.parent.maybeChild(e.index());for(var o=0;o<s.length;o++)s[o].type.spec.inclusive===!1&&(!r||!s[o].isInSet(r.marks))&&(s=s[o--].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 ls(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=[],r=0,o=n;for(let i=e;;){let{index:l,offset:c}=i.content.findIndex(o),u=o-c;if(s.push(i,l,r+c),!u||(i=i.child(l),i.isText))break;o=u-1,r+=c+1}return new kn(n,s,o)}static resolveCached(e,n){let s=Xo.get(e);if(s)for(let o=0;o<s.elts.length;o++){let i=s.elts[o];if(i.pos==n)return i}else Xo.set(e,s=new $p);let r=s.elts[s.i]=kn.resolve(e,n);return s.i=(s.i+1)%Fp,r}}class $p{constructor(){this.elts=[],this.i=0}}const Fp=12,Xo=new WeakMap;class ls{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 zp=Object.create(null);let Bt=class dr{constructor(e,n,s,r=Q.none){this.type=e,this.attrs=n,this.marks=r,this.content=s||M.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,r=0){this.content.nodesBetween(e,n,s,r,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,r){return this.content.textBetween(e,n,s,r)}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&&rs(this.attrs,n||e.defaultAttrs||zp)&&Q.sameSet(this.marks,s||Q.none)}copy(e=null){return e==this.content?this:new dr(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new dr(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 V.empty;let r=this.resolve(e),o=this.resolve(n),i=s?0:r.sharedDepth(n),l=r.start(i),u=r.node(i).content.cut(r.pos-l,o.pos-l);return new V(u,r.depth-i,o.depth-i)}replace(e,n,s){return Dp(this.resolve(e),this.resolve(n),s)}nodeAt(e){for(let n=this;;){let{index:s,offset:r}=n.content.findIndex(e);if(n=n.maybeChild(s),!n)return null;if(r==e||n.isText)return n;e-=r+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 r=this.content.child(n-1);return{node:r,index:n-1,offset:s-r.nodeSize}}resolve(e){return kn.resolveCached(this,e)}resolveNoCache(e){return kn.resolve(this,e)}rangeHasMark(e,n,s){let r=!1;return n>e&&this.nodesBetween(e,n,o=>(s.isInSet(o.marks)&&(r=!0),!r)),r}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()+")"),Hi(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=M.empty,r=0,o=s.childCount){let i=this.contentMatchAt(e).matchFragment(s,r,o),l=i&&i.matchFragment(this.content,n);if(!l||!l.validEnd)return!1;for(let c=r;c<o;c++)if(!this.type.allowsMarks(s.child(c).marks))return!1;return!0}canReplaceWith(e,n,s,r){if(r&&!this.type.allowsMarks(r))return!1;let o=this.contentMatchAt(e).matchType(s),i=o&&o.matchFragment(this.content,n);return i?i.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 r=M.fromJSON(e,n.content),o=e.nodeType(n.type).create(n.attrs,r,s);return o.type.checkAttrs(o.attrs),o}};Bt.prototype.text=void 0;class cs extends Bt{constructor(e,n,s,r){if(super(e,n,null,r),!s)throw new RangeError("Empty text nodes are not allowed");this.text=s}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Hi(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 cs(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new cs(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 Hi(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class Dt{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let s=new Hp(e,n);if(s.next==null)return Dt.empty;let r=Vi(s);s.next&&s.err("Unexpected trailing text");let o=Yp(Kp(r));return Xp(o,s),o}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 r=this;for(let o=n;r&&o<s;o++)r=r.matchType(e.child(o).type);return r}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 r=[this];function o(i,l){let c=i.matchFragment(e,s);if(c&&(!n||c.validEnd))return M.from(l.map(u=>u.createAndFill()));for(let u=0;u<i.next.length;u++){let{type:p,next:f}=i.next[u];if(!(p.isText||p.hasRequiredAttrs())&&r.indexOf(f)==-1){r.push(f);let m=o(f,l.concat(p));if(m)return m}}return null}return o(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 r=s.shift(),o=r.match;if(o.matchType(e)){let i=[];for(let l=r;l.type;l=l.via)i.push(l.type);return i.reverse()}for(let i=0;i<o.next.length;i++){let{type:l,next:c}=o.next[i];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in n)&&(!r.type||c.validEnd)&&(s.push({match:l.contentMatch,type:l,via:r}),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 r=0;r<s.next.length;r++)e.indexOf(s.next[r].next)==-1&&n(s.next[r].next)}return n(this),e.map((s,r)=>{let o=r+(s.validEnd?"*":" ")+" ";for(let i=0;i<s.next.length;i++)o+=(i?", ":"")+s.next[i].type.name+"->"+e.indexOf(s.next[i].next);return o}).join(`
|
|
130
130
|
`)}}Dt.empty=new Dt(!0);class Hp{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 Vi(t){let e=[];do e.push(Vp(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Vp(t){let e=[];do e.push(Wp(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Wp(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=Gp(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 Gp(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 Up(t,e){let n=t.nodeTypes,s=n[e];if(s)return[s];let r=[];for(let o in n){let i=n[o];i.isInGroup(e)&&r.push(i)}return r.length==0&&t.err("No node type or group '"+e+"' found"),r}function qp(t){if(t.eat("(")){let e=Vi(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=Up(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 Kp(t){let e=[[]];return r(o(t,0),n()),e;function n(){return e.push([])-1}function s(i,l,c){let u={term:c,to:l};return e[i].push(u),u}function r(i,l){i.forEach(c=>c.to=l)}function o(i,l){if(i.type=="choice")return i.exprs.reduce((c,u)=>c.concat(o(u,l)),[]);if(i.type=="seq")for(let c=0;;c++){let u=o(i.exprs[c],l);if(c==i.exprs.length-1)return u;r(u,l=n())}else if(i.type=="star"){let c=n();return s(l,c),r(o(i.expr,c),c),[s(c)]}else if(i.type=="plus"){let c=n();return r(o(i.expr,l),c),r(o(i.expr,c),c),[s(c)]}else{if(i.type=="opt")return[s(l)].concat(o(i.expr,l));if(i.type=="range"){let c=l;for(let u=0;u<i.min;u++){let p=n();r(o(i.expr,c),p),c=p}if(i.max==-1)r(o(i.expr,c),c);else for(let u=i.min;u<i.max;u++){let p=n();s(c,p),r(o(i.expr,c),p),c=p}return[s(c)]}else{if(i.type=="name")return[s(l,void 0,i.value)];throw new Error("Unknown expr type")}}}}function Wi(t,e){return e-t}function Zo(t,e){let n=[];return s(e),n.sort(Wi);function s(r){let o=t[r];if(o.length==1&&!o[0].term)return s(o[0].to);n.push(r);for(let i=0;i<o.length;i++){let{term:l,to:c}=o[i];!l&&n.indexOf(c)==-1&&s(c)}}}function Yp(t){let e=Object.create(null);return n(Zo(t,0));function n(s){let r=[];s.forEach(i=>{t[i].forEach(({term:l,to:c})=>{if(!l)return;let u;for(let p=0;p<r.length;p++)r[p][0]==l&&(u=r[p][1]);Zo(t,c).forEach(p=>{u||r.push([l,u=[]]),u.indexOf(p)==-1&&u.push(p)})})});let o=e[s.join(",")]=new Dt(s.indexOf(t.length-1)>-1);for(let i=0;i<r.length;i++){let l=r[i][1].sort(Wi);o.next.push({type:r[i][0],next:e[l.join(",")]||n(l)})}return o}}function Xp(t,e){for(let n=0,s=[t];n<s.length;n++){let r=s[n],o=!r.validEnd,i=[];for(let l=0;l<r.next.length;l++){let{type:c,next:u}=r.next[l];i.push(c.name),o&&!(c.isText||c.hasRequiredAttrs())&&(o=!1),s.indexOf(u)==-1&&s.push(u)}o&&e.err("Only non-generatable nodes ("+i.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function Gi(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 Ui(t,e){let n=Object.create(null);for(let s in t){let r=e&&e[s];if(r===void 0){let o=t[s];if(o.hasDefault)r=o.default;else throw new RangeError("No value supplied for attribute "+s)}n[s]=r}return n}function qi(t,e,n,s){for(let r in e)if(!(r in t))throw new RangeError(`Unsupported attribute ${r} for ${n} of type ${r}`);for(let r in t){let o=t[r];o.validate&&o.validate(e[r])}}function Ki(t,e){let n=Object.create(null);if(e)for(let s in e)n[s]=new Zp(t,s,e[s]);return n}class ds{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=Ki(e,s.attrs),this.defaultAttrs=Gi(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==Dt.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:Ui(this.attrs,e)}create(e=null,n,s){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Bt(this,this.computeAttrs(e),M.from(n),Q.setFrom(s))}createChecked(e=null,n,s){return n=M.from(n),this.checkContent(n),new Bt(this,this.computeAttrs(e),n,Q.setFrom(s))}createAndFill(e=null,n,s){if(e=this.computeAttrs(e),n=M.from(n),n.size){let i=this.contentMatch.fillBefore(n);if(!i)return null;n=i.append(n)}let r=this.contentMatch.matchFragment(n),o=r&&r.fillBefore(M.empty,!0);return o?new Bt(this,e,n.append(o),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){qi(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((o,i)=>s[o]=new ds(o,n,i));let r=n.spec.topNode||"doc";if(!s[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!s.text)throw new RangeError("Every schema needs a 'text' type");for(let o in s.text.attrs)throw new RangeError("The text node type should not have attributes");return s}}function Jp(t,e,n){let s=n.split("|");return r=>{let o=r===null?"null":typeof r;if(s.indexOf(o)<0)throw new RangeError(`Expected value of type ${s} for attribute ${e} on type ${t}, got ${o}`)}}class Zp{constructor(e,n,s){this.hasDefault=Object.prototype.hasOwnProperty.call(s,"default"),this.default=s.default,this.validate=typeof s.validate=="string"?Jp(e,n,s.validate):s.validate}get isRequired(){return!this.hasDefault}}class Yr{constructor(e,n,s,r){this.name=e,this.rank=n,this.schema=s,this.spec=r,this.attrs=Ki(e,r.attrs),this.excluded=null;let o=Gi(this.attrs);this.instance=o?new Q(this,o):null}create(e=null){return!e&&this.instance?this.instance:new Q(this,Ui(this.attrs,e))}static compile(e,n){let s=Object.create(null),r=0;return e.forEach((o,i)=>s[o]=new Yr(o,r++,n,i)),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){qi(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class Qp{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let r in e)n[r]=e[r];n.nodes=we.from(e.nodes),n.marks=we.from(e.marks||{}),this.nodes=ds.compile(this.spec.nodes,this),this.marks=Yr.compile(this.spec.marks,this);let s=Object.create(null);for(let r in this.nodes){if(r in this.marks)throw new RangeError(r+" can not be both a node and a mark");let o=this.nodes[r],i=o.spec.content||"",l=o.spec.marks;if(o.contentMatch=s[i]||(s[i]=Dt.parse(i,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=l=="_"?null:l?Qo(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let r in this.marks){let o=this.marks[r],i=o.spec.excludes;o.excluded=i==null?[o]:i==""?[]:Qo(this,i.split(" "))}this.nodeFromJSON=r=>Bt.fromJSON(this,r),this.markFromJSON=r=>Q.fromJSON(this,r),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,s,r){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof ds){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,r)}text(e,n){let s=this.nodes.text;return new cs(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 Qo(t,e){let n=[];for(let s=0;s<e.length;s++){let r=e[s],o=t.marks[r],i=o;if(o)n.push(o);else for(let l in t.marks){let c=t.marks[l];(r=="_"||c.spec.group&&c.spec.group.split(" ").indexOf(r)>-1)&&n.push(i=c)}if(!i)throw new SyntaxError("Unknown mark type: '"+e[s]+"'")}return n}function ef(t){return t.tag!=null}function tf(t){return t.style!=null}class Kt{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let s=this.matchedStyles=[];n.forEach(r=>{if(ef(r))this.tags.push(r);else if(tf(r)){let o=/[^=]*/.exec(r.style)[0];s.indexOf(o)<0&&s.push(o),this.styles.push(r)}}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let o=e.nodes[r.node];return o.contentMatch.matchType(o)})}parse(e,n={}){let s=new ta(this,n,!1);return s.addAll(e,Q.none,n.from,n.to),s.finish()}parseSlice(e,n={}){let s=new ta(this,n,!0);return s.addAll(e,Q.none,n.from,n.to),V.maxOpen(s.finish())}matchTag(e,n,s){for(let r=s?this.tags.indexOf(s)+1:0;r<this.tags.length;r++){let o=this.tags[r];if(rf(e,o.tag)&&(o.namespace===void 0||e.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let i=o.getAttrs(e);if(i===!1)continue;o.attrs=i||void 0}return o}}}matchStyle(e,n,s,r){for(let o=r?this.styles.indexOf(r)+1:0;o<this.styles.length;o++){let i=this.styles[o],l=i.style;if(!(l.indexOf(e)!=0||i.context&&!s.matchesContext(i.context)||l.length>e.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=n))){if(i.getAttrs){let c=i.getAttrs(n);if(c===!1)continue;i.attrs=c||void 0}return i}}}static schemaRules(e){let n=[];function s(r){let o=r.priority==null?50:r.priority,i=0;for(;i<n.length;i++){let l=n[i];if((l.priority==null?50:l.priority)<o)break}n.splice(i,0,r)}for(let r in e.marks){let o=e.marks[r].spec.parseDOM;o&&o.forEach(i=>{s(i=na(i)),i.mark||i.ignore||i.clearMark||(i.mark=r)})}for(let r in e.nodes){let o=e.nodes[r].spec.parseDOM;o&&o.forEach(i=>{s(i=na(i)),i.node||i.ignore||i.mark||(i.node=r)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Kt(e,Kt.schemaRules(e)))}}const Yi={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},nf={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Xi={ol:!0,ul:!0},wn=1,ur=2,xn=4;function ea(t,e,n){return e!=null?(e?wn:0)|(e==="full"?ur:0):t&&t.whitespace=="pre"?wn|ur:n&~xn}class Gn{constructor(e,n,s,r,o,i){this.type=e,this.attrs=n,this.marks=s,this.solid=r,this.options=i,this.content=[],this.activeMarks=Q.none,this.match=o||(i&xn?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(M.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let s=this.type.contentMatch,r;return(r=s.findWrapping(e.type))?(this.match=s,r):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&wn)){let s=this.content[this.content.length-1],r;if(s&&s.isText&&(r=/[ \t\r\n\u000c]+$/.exec(s.text))){let o=s;s.text.length==r[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-r[0].length))}}let n=M.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(M.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&&!Yi.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class ta{constructor(e,n,s){this.parser=e,this.options=n,this.isOpen=s,this.open=0,this.localPreserveWS=!1;let r=n.topNode,o,i=ea(null,n.preserveWhitespace,0)|(s?xn:0);r?o=new Gn(r.type,r.attrs,Q.none,!0,n.topMatch||r.type.contentMatch,i):s?o=new Gn(null,null,Q.none,!0,null,i):o=new Gn(e.schema.topNodeType,null,Q.none,!0,null,i),this.nodes=[o],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,r=this.top,o=r.options&ur?"full":this.localPreserveWS||(r.options&wn)>0,{schema:i}=this.parser;if(o==="full"||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(s)){if(o)if(o==="full")s=s.replace(/\r\n?/g,`
|
|
131
131
|
`);else if(i.linebreakReplacement&&/[\r\n]/.test(s)&&this.top.findWrapping(i.linebreakReplacement.create())){let l=s.split(/\r?\n|\r/);for(let c=0;c<l.length;c++)c&&this.insertNode(i.linebreakReplacement.create(),n,!0),l[c]&&this.insertNode(i.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=r.content[r.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(i.text(s),n,!/\S/.test(s)),this.findInText(e)}else this.findInside(e)}addElement(e,n,s){let r=this.localPreserveWS,o=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let i=e.nodeName.toLowerCase(),l;Xi.hasOwnProperty(i)&&this.parser.normalizeLists&&sf(e);let c=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,s));e:if(c?c.ignore:nf.hasOwnProperty(i))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(Yi.hasOwnProperty(i))o.content.length&&o.content[0].isInline&&this.open&&(this.open--,o=this.top),u=!0,o.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(o),this.needsBlock=p}else{let u=this.readStyles(e,n);u&&this.addElementByRule(e,c,u,c.consuming===!1?l:void 0)}this.localPreserveWS=r}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 r=0;r<this.parser.matchedStyles.length;r++){let o=this.parser.matchedStyles[r],i=s.getPropertyValue(o);if(i)for(let l=void 0;;){let c=this.parser.matchStyle(o,i,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,r){let o,i;if(n.node)if(i=this.parser.schema.nodes[n.node],i.isLeaf)this.insertNode(i.create(n.attrs),s,e.nodeName=="BR")||this.leafFallback(e,s);else{let c=this.enter(i,n.attrs||null,s,n.preserveWhitespace);c&&(o=!0,s=c)}else{let c=this.parser.schema.marks[n.mark];s=s.concat(c.create(n.attrs))}let l=this.top;if(i&&i.isLeaf)this.findInside(e);else if(r)this.addElement(e,s,r);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)}o&&this.sync(l)&&this.open--}addAll(e,n,s,r){let o=s||0;for(let i=s?e.childNodes[s]:e.firstChild,l=r==null?null:e.childNodes[r];i!=l;i=i.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(i,n);this.findAtPoint(e,o)}findPlace(e,n,s){let r,o;for(let i=this.open,l=0;i>=0;i--){let c=this.nodes[i],u=c.findWrapping(e);if(u&&(!r||r.length>u.length+l)&&(r=u,o=c,!u.length))break;if(c.solid){if(s)break;l+=2}}if(!r)return null;this.sync(o);for(let i=0;i<r.length;i++)n=this.enterInner(r[i],null,n,!1);return n}insertNode(e,n,s){if(e.isInline&&this.needsBlock&&!this.top.type){let o=this.textblockFromContext();o&&(n=this.enterInner(o,null,n))}let r=this.findPlace(e,n,s);if(r){this.closeExtra();let o=this.top;o.match&&(o.match=o.match.matchType(e.type));let i=Q.none;for(let l of r.concat(e.marks))(o.type?o.type.allowsMarkType(l.type):sa(l.type,e.type))&&(i=l.addToSet(i));return o.content.push(e.mark(i)),!0}return!1}enter(e,n,s,r){let o=this.findPlace(e.create(n),s,!1);return o&&(o=this.enterInner(e,n,s,!0,r)),o}enterInner(e,n,s,r=!1,o){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let l=ea(e,o,i.options);i.options&xn&&i.content.length==0&&(l|=xn);let c=Q.none;return s=s.filter(u=>(i.type?i.type.allowsMarkType(u.type):sa(u.type,e))?(c=u.addToSet(c),!1):!0),this.nodes.push(new Gn(e,n,c,r,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|=wn)}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 r=s.length-1;r>=0;r--)e+=s[r].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 r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&n.compareDocumentPosition(this.find[r].node)&(s?2:4)&&(this.find[r].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,r=!this.isOpen&&(!s||s.parent.type==this.nodes[0].type),o=-(s?s.depth+1:0)+(r?0:1),i=(l,c)=>{for(;l>=0;l--){let u=n[l];if(u==""){if(l==n.length-1||l==0)continue;for(;c>=o;c--)if(i(l-1,c))return!0;return!1}else{let p=c>0||c==0&&r?this.nodes[c].type:s&&c>=o?s.node(c-o).type:null;if(!p||p.name!=u&&!p.isInGroup(u))return!1;c--}}return!0};return i(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 sf(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let s=e.nodeType==1?e.nodeName.toLowerCase():null;s&&Xi.hasOwnProperty(s)&&n?(n.appendChild(e),e=n):s=="li"?n=e:s&&(n=null)}}function rf(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function na(t){let e={};for(let n in t)e[n]=t[n];return e}function sa(t,e){let n=e.schema.nodes;for(let s in n){let r=n[s];if(!r.allowsMarkType(t))continue;let o=[],i=l=>{o.push(l);for(let c=0;c<l.edgeCount;c++){let{type:u,next:p}=l.edge(c);if(u==e||o.indexOf(p)<0&&i(p))return!0}};if(i(r.contentMatch))return!0}}const Ji=65535,Zi=Math.pow(2,16);function of(t,e){return t+e*Zi}function ra(t){return t&Ji}function af(t){return(t-(t&Ji))/Zi}const Qi=1,el=2,Jn=4,tl=8;class oa{constructor(e,n,s){this.pos=e,this.delInfo=n,this.recover=s}get deleted(){return(this.delInfo&tl)>0}get deletedBefore(){return(this.delInfo&(Qi|Jn))>0}get deletedAfter(){return(this.delInfo&(el|Jn))>0}get deletedAcross(){return(this.delInfo&Jn)>0}}class ze{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&ze.empty)return ze.empty}recover(e){let n=0,s=ra(e);if(!this.inverted)for(let r=0;r<s;r++)n+=this.ranges[r*3+2]-this.ranges[r*3+1];return this.ranges[s*3]+n+af(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 r=0,o=this.inverted?2:1,i=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let c=this.ranges[l]-(this.inverted?r:0);if(c>e)break;let u=this.ranges[l+o],p=this.ranges[l+i],f=c+u;if(e<=f){let m=u?e==c?-1:e==f?1:n:n,h=c+r+(m<0?0:p);if(s)return h;let x=e==(n<0?c:f)?null:of(l/3,e-c),b=e==c?el:e==f?Qi:Jn;return(n<0?e!=c:e!=f)&&(b|=tl),new oa(h,b,x)}r+=p-u}return s?e+r:new oa(e+r,0,null)}touches(e,n){let s=0,r=ra(n),o=this.inverted?2:1,i=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+o],p=c+u;if(e<=p&&l==r*3)return!0;s+=this.ranges[l+i]-u}return!1}forEach(e){let n=this.inverted?2:1,s=this.inverted?1:2;for(let r=0,o=0;r<this.ranges.length;r+=3){let i=this.ranges[r],l=i-(this.inverted?o:0),c=i+(this.inverted?0:o),u=this.ranges[r+n],p=this.ranges[r+s];e(l,l+u,c,c+p),o+=p-u}}invert(){return new ze(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?ze.empty:new ze(e<0?[0,-e,0]:[0,0,e])}}ze.empty=new ze([]);const qs=Object.create(null);class _e{getMap(){return ze.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let s=qs[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 qs)throw new RangeError("Duplicate use of step JSON ID "+e);return qs[e]=n,n.prototype.jsonID=e,n}}class ye{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new ye(e,null)}static fail(e){return new ye(null,e)}static fromReplace(e,n,s,r){try{return ye.ok(e.replace(n,s,r))}catch(o){if(o instanceof as)return ye.fail(o.message);throw o}}}function Xr(t,e,n){let s=[];for(let r=0;r<t.childCount;r++){let o=t.child(r);o.content.size&&(o=o.copy(Xr(o.content,e,o))),o.isInline&&(o=e(o,n,r)),s.push(o)}return M.fromArray(s)}class Ct extends _e{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),r=s.node(s.sharedDepth(this.to)),o=new V(Xr(n.content,(i,l)=>!i.isAtom||!l.type.allowsMarkType(this.mark.type)?i:i.mark(this.mark.addToSet(i.marks)),r),n.openStart,n.openEnd);return ye.fromReplace(e,this.from,this.to,o)}invert(){return new jt(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 Ct(n.pos,s.pos,this.mark)}merge(e){return e instanceof Ct&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ct(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 Ct(n.from,n.to,e.markFromJSON(n.mark))}}_e.jsonID("addMark",Ct);class jt extends _e{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 V(Xr(n.content,r=>r.mark(this.mark.removeFromSet(r.marks)),e),n.openStart,n.openEnd);return ye.fromReplace(e,this.from,this.to,s)}invert(){return new Ct(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 jt(n.pos,s.pos,this.mark)}merge(e){return e instanceof jt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new jt(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 jt(n.from,n.to,e.markFromJSON(n.mark))}}_e.jsonID("removeMark",jt);class St extends _e{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return ye.fail("No node at mark step's position");let s=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return ye.fromReplace(e,this.pos,this.pos+1,new V(M.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 r=0;r<n.marks.length;r++)if(!n.marks[r].isInSet(s))return new St(this.pos,n.marks[r]);return new St(this.pos,this.mark)}}return new Cn(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new St(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 St(n.pos,e.markFromJSON(n.mark))}}_e.jsonID("addNodeMark",St);class Cn extends _e{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return ye.fail("No node at mark step's position");let s=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return ye.fromReplace(e,this.pos,this.pos+1,new V(M.from(s),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new St(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Cn(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 Cn(n.pos,e.markFromJSON(n.mark))}}_e.jsonID("removeNodeMark",Cn);class Fe extends _e{constructor(e,n,s,r=!1){super(),this.from=e,this.to=n,this.slice=s,this.structure=r}apply(e){return this.structure&&pr(e,this.from,this.to)?ye.fail("Structure replace would overwrite content"):ye.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new ze([this.from,this.to-this.from,this.slice.size])}invert(e){return new Fe(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 Fe(n.pos,Math.max(n.pos,s.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Fe)||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?V.empty:new V(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Fe(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?V.empty:new V(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Fe(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 Fe(n.from,n.to,V.fromJSON(e,n.slice),!!n.structure)}}_e.jsonID("replace",Fe);class Me extends _e{constructor(e,n,s,r,o,i,l=!1){super(),this.from=e,this.to=n,this.gapFrom=s,this.gapTo=r,this.slice=o,this.insert=i,this.structure=l}apply(e){if(this.structure&&(pr(e,this.from,this.gapFrom)||pr(e,this.gapTo,this.to)))return ye.fail("Structure gap-replace would overwrite content");let n=e.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return ye.fail("Gap is not a flat range");let s=this.slice.insertAt(this.insert,n.content);return s?ye.fromReplace(e,this.from,this.to,s):ye.fail("Content does not fit in gap")}getMap(){return new ze([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 Me(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),r=this.from==this.gapFrom?n.pos:e.map(this.gapFrom,-1),o=this.to==this.gapTo?s.pos:e.map(this.gapTo,1);return n.deletedAcross&&s.deletedAcross||r<n.pos||o>s.pos?null:new Me(n.pos,s.pos,r,o,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 Me(n.from,n.to,n.gapFrom,n.gapTo,V.fromJSON(e,n.slice),n.insert,!!n.structure)}}_e.jsonID("replaceAround",Me);function pr(t,e,n){let s=t.resolve(e),r=n-e,o=s.depth;for(;r>0&&o>0&&s.indexAfter(o)==s.node(o).childCount;)o--,r--;if(r>0){let i=s.node(o).maybeChild(s.indexAfter(o));for(;r>0;){if(!i||i.isLeaf)return!0;i=i.firstChild,r--}}return!1}function lf(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function on(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let s=t.depth,r=0,o=0;;--s){let i=t.$from.node(s),l=t.$from.index(s)+r,c=t.$to.indexAfter(s)-o;if(s<t.depth&&i.canReplace(l,c,n))return s;if(s==0||i.type.spec.isolating||!lf(i,l,c))break;l&&(r=1),c<i.childCount&&(o=1)}return null}function nl(t,e,n=null,s=t){let r=cf(t,e),o=r&&df(s,e);return o?r.map(aa).concat({type:e,attrs:n}).concat(o.map(aa)):null}function aa(t){return{type:t,attrs:null}}function cf(t,e){let{parent:n,startIndex:s,endIndex:r}=t,o=n.contentMatchAt(s).findWrapping(e);if(!o)return null;let i=o.length?o[0]:e;return n.canReplaceWith(s,r,i)?o:null}function df(t,e){let{parent:n,startIndex:s,endIndex:r}=t,o=n.child(s),i=e.contentMatch.findWrapping(o.type);if(!i)return null;let c=(i.length?i[i.length-1]:e).contentMatch;for(let u=s;c&&u<r;u++)c=c.matchType(n.child(u).type);return!c||!c.validEnd?null:i}function dt(t,e,n=1,s){let r=t.resolve(e),o=r.depth-n,i=s&&s[s.length-1]||r.parent;if(o<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!i.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let u=r.depth-1,p=n-2;u>o;u--,p--){let f=r.node(u),m=r.index(u);if(f.type.spec.isolating)return!1;let h=f.content.cutByIndex(m,f.childCount),x=s&&s[p+1];x&&(h=h.replaceChild(0,x.type.create(x.attrs)));let b=s&&s[p]||f;if(!f.canReplace(m+1,f.childCount)||!b.type.validContent(h))return!1}let l=r.indexAfter(o),c=s&&s[0];return r.node(o).canReplaceWith(l,l,c?c.type:r.node(o+1).type)}function zt(t,e){let n=t.resolve(e),s=n.index();return sl(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(s,s+1)}function uf(t,e){e.content.size||t.type.compatibleContent(e.type);let n=t.contentMatchAt(t.childCount),{linebreakReplacement:s}=t.type.schema;for(let r=0;r<e.childCount;r++){let o=e.child(r),i=o.type==s?t.type.schema.nodes.text:o.type;if(n=n.matchType(i),!n||!t.type.allowsMarks(o.marks))return!1}return n.validEnd}function sl(t,e){return!!(t&&e&&!t.isLeaf&&uf(t,e))}function Is(t,e,n=-1){let s=t.resolve(e);for(let r=s.depth;;r--){let o,i,l=s.index(r);if(r==s.depth?(o=s.nodeBefore,i=s.nodeAfter):n>0?(o=s.node(r+1),l++,i=s.node(r).maybeChild(l)):(o=s.node(r).maybeChild(l-1),i=s.node(r+1)),o&&!o.isTextblock&&sl(o,i)&&s.node(r).canReplace(l,l+1))return e;if(r==0)break;e=n<0?s.before(r):s.after(r)}}function Jr(t,e,n=e,s=V.empty){if(e==n&&!s.size)return null;let r=t.resolve(e),o=t.resolve(n);return pf(r,o,s)?new Fe(e,n,s):new ff(r,o,s).fit()}function pf(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}class ff{constructor(e,n,s){this.$from=e,this.$to=n,this.unplaced=s,this.frontier=[],this.placed=M.empty;for(let r=0;r<=e.depth;r++){let o=e.node(r);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(r))})}for(let r=e.depth;r>0;r--)this.placed=M.from(e.node(r).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,r=this.close(e<0?this.$to:s.doc.resolve(e));if(!r)return null;let o=this.placed,i=s.depth,l=r.depth;for(;i&&l&&o.childCount==1;)o=o.firstChild.content,i--,l--;let c=new V(o,i,l);return e>-1?new Me(s.pos,e,this.$to.pos,this.$to.end(),c,n):c.size||s.pos!=this.$to.pos?new Fe(s.pos,r.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,s=0,r=this.unplaced.openEnd;s<e;s++){let o=n.firstChild;if(n.childCount>1&&(r=0),o.type.spec.isolating&&r<=s){e=s;break}n=o.content}for(let n=1;n<=2;n++)for(let s=n==1?e:this.unplaced.openStart;s>=0;s--){let r,o=null;s?(o=Ks(this.unplaced.content,s-1).firstChild,r=o.content):r=this.unplaced.content;let i=r.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:u}=this.frontier[l],p,f=null;if(n==1&&(i?u.matchType(i.type)||(f=u.fillBefore(M.from(i),!1)):o&&c.compatibleContent(o.type)))return{sliceDepth:s,frontierDepth:l,parent:o,inject:f};if(n==2&&i&&(p=u.findWrapping(i.type)))return{sliceDepth:s,frontierDepth:l,parent:o,wrap:p};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:s}=this.unplaced,r=Ks(e,n);return!r.childCount||r.firstChild.isLeaf?!1:(this.unplaced=new V(e,n+1,Math.max(s,r.size+n>=e.size-s?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:s}=this.unplaced,r=Ks(e,n);if(r.childCount<=1&&n>0){let o=e.size-n<=n+r.size;this.unplaced=new V(fn(e,n-1,1),n-1,o?n-1:s)}else this.unplaced=new V(fn(e,n,1),n,s)}placeNodes({sliceDepth:e,frontierDepth:n,parent:s,inject:r,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let b=0;b<o.length;b++)this.openFrontierNode(o[b]);let i=this.unplaced,l=s?s.content:i.content,c=i.openStart-e,u=0,p=[],{match:f,type:m}=this.frontier[n];if(r){for(let b=0;b<r.childCount;b++)p.push(r.child(b));f=f.matchFragment(r)}let h=l.size+e-(i.content.size-i.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(rl(b.mark(m.allowedMarks(b.marks)),u==1?c:0,u==l.childCount?h:-1)))}let x=u==l.childCount;x||(h=-1),this.placed=hn(this.placed,n,M.from(p)),this.frontier[n].match=f,x&&h<0&&s&&s.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let b=0,y=l;b<h;b++){let k=y.lastChild;this.frontier.push({type:k.type,match:k.contentMatchAt(k.childCount)}),y=k.content}this.unplaced=x?e==0?V.empty:new V(fn(i.content,e-1,1),e-1,h<0?i.openEnd:e-1):new V(fn(i.content,e,u),i.openStart,i.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],n;if(!e.type.isTextblock||!Ys(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,r=this.$to.after(s);for(;s>1&&r==this.$to.end(--s);)++r;return r}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:s,type:r}=this.frontier[n],o=n<e.depth&&e.end(n+1)==e.pos+(e.depth-(n+1)),i=Ys(e,n,r,s,o);if(i){for(let l=n-1;l>=0;l--){let{match:c,type:u}=this.frontier[l],p=Ys(e,l,u,c,!0);if(!p||p.childCount)continue e}return{depth:n,fit:i,move:o?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=hn(this.placed,n.depth,n.fit)),e=n.move;for(let s=n.depth+1;s<=e.depth;s++){let r=e.node(s),o=r.type.contentMatch.fillBefore(r.content,!0,e.index(s));this.openFrontierNode(r.type,r.attrs,o)}return e}openFrontierNode(e,n=null,s){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=hn(this.placed,this.depth,M.from(e.create(n,s))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(M.empty,!0);n.childCount&&(this.placed=hn(this.placed,this.frontier.length,n))}}function fn(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(fn(t.firstChild.content,e-1,n)))}function hn(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(hn(t.lastChild.content,e-1,n)))}function Ks(t,e){for(let n=0;n<e;n++)t=t.firstChild.content;return t}function rl(t,e,n){if(e<=0)return t;let s=t.content;return e>1&&(s=s.replaceChild(0,rl(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(M.empty,!0)))),t.copy(s)}function Ys(t,e,n,s,r){let o=t.node(e),i=r?t.indexAfter(e):t.index(e);if(i==o.childCount&&!n.compatibleContent(o.type))return null;let l=s.fillBefore(o.content,!0,i);return l&&!hf(n,o.content,i)?l:null}function hf(t,e,n){for(let s=n;s<e.childCount;s++)if(!t.allowsMarks(e.child(s).marks))return!0;return!1}class bn extends _e{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 ye.fail("No node at attribute step's position");let s=Object.create(null);for(let o in n.attrs)s[o]=n.attrs[o];s[this.attr]=this.value;let r=n.type.create(s,null,n.marks);return ye.fromReplace(e,this.pos,this.pos+1,new V(M.from(r),0,n.isLeaf?0:1))}getMap(){return ze.empty}invert(e){return new bn(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 bn(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 bn(n.pos,n.attr,n.value)}}_e.jsonID("attr",bn);class us extends _e{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let r in e.attrs)n[r]=e.attrs[r];n[this.attr]=this.value;let s=e.type.create(n,e.content,e.marks);return ye.ok(s)}getMap(){return ze.empty}invert(e){return new us(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 us(n.attr,n.value)}}_e.jsonID("docAttr",us);let jn=class extends Error{};jn=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};jn.prototype=Object.create(Error.prototype);jn.prototype.constructor=jn;jn.prototype.name="TransformError";const Xs=Object.create(null);class Y{constructor(e,n,s){this.$anchor=e,this.$head=n,this.ranges=s||[new mf(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=V.empty){let s=n.content.lastChild,r=null;for(let l=0;l<n.openEnd;l++)r=s,s=s.lastChild;let o=e.steps.length,i=this.ranges;for(let l=0;l<i.length;l++){let{$from:c,$to:u}=i[l],p=e.mapping.slice(o);e.replaceRange(p.map(c.pos),p.map(u.pos),l?V.empty:n),l==0&&ca(e,o,(s?s.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,n){let s=e.steps.length,r=this.ranges;for(let o=0;o<r.length;o++){let{$from:i,$to:l}=r[o],c=e.mapping.slice(s),u=c.map(i.pos),p=c.map(l.pos);o?e.deleteRange(u,p):(e.replaceRangeWith(u,p,n),ca(e,s,n.isInline?-1:1))}}static findFrom(e,n,s=!1){let r=e.parent.inlineContent?new ae(e):Ut(e.node(0),e.parent,e.pos,e.index(),n,s);if(r)return r;for(let o=e.depth-1;o>=0;o--){let i=n<0?Ut(e.node(0),e.node(o),e.before(o+1),e.index(o),n,s):Ut(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,s);if(i)return i}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new We(e.node(0))}static atStart(e){return Ut(e,e,0,0,1)||new We(e)}static atEnd(e){return Ut(e,e,e.content.size,e.childCount,-1)||new We(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let s=Xs[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 Xs)throw new RangeError("Duplicate use of selection JSON ID "+e);return Xs[e]=n,n.prototype.jsonID=e,n}getBookmark(){return ae.between(this.$anchor,this.$head).getBookmark()}}Y.prototype.visible=!0;class mf{constructor(e,n){this.$from=e,this.$to=n}}let ia=!1;function la(t){!ia&&!t.parent.inlineContent&&(ia=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class ae extends Y{constructor(e,n=e){la(e),la(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 Y.near(s);let r=e.resolve(n.map(this.anchor));return new ae(r.parent.inlineContent?r:s,s)}replace(e,n=V.empty){if(super.replace(e,n),n==V.empty){let s=this.$from.marksAcross(this.$to);s&&e.ensureMarks(s)}}eq(e){return e instanceof ae&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Ts(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 ae(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,s=n){let r=e.resolve(n);return new this(r,s==n?r:e.resolve(s))}static between(e,n,s){let r=e.pos-n.pos;if((!s||r)&&(s=r>=0?1:-1),!n.parent.inlineContent){let o=Y.findFrom(n,s,!0)||Y.findFrom(n,-s,!0);if(o)n=o.$head;else return Y.near(n,s)}return e.parent.inlineContent||(r==0?e=n:(e=(Y.findFrom(e,-s,!0)||Y.findFrom(e,s,!0)).$anchor,e.pos<n.pos!=r<0&&(e=n))),new ae(e,n)}}Y.jsonID("text",ae);class Ts{constructor(e,n){this.anchor=e,this.head=n}map(e){return new Ts(e.map(this.anchor),e.map(this.head))}resolve(e){return ae.between(e.resolve(this.anchor),e.resolve(this.head))}}class ee extends Y{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:r}=n.mapResult(this.anchor),o=e.resolve(r);return s?Y.near(o):new ee(o)}content(){return new V(M.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 Zr(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;Y.jsonID("node",ee);class Zr{constructor(e){this.anchor=e}map(e){let{deleted:n,pos:s}=e.mapResult(this.anchor);return n?new Ts(s,s):new Zr(s)}resolve(e){let n=e.resolve(this.anchor),s=n.nodeAfter;return s&&ee.isSelectable(s)?new ee(n):Y.near(n)}}class We extends Y{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,n=V.empty){if(n==V.empty){e.delete(0,e.doc.content.size);let s=Y.atStart(e.doc);s.eq(e.selection)||e.setSelection(s)}else super.replace(e,n)}toJSON(){return{type:"all"}}static fromJSON(e){return new We(e)}map(e){return new We(e)}eq(e){return e instanceof We}getBookmark(){return gf}}Y.jsonID("all",We);const gf={map(){return this},resolve(t){return new We(t)}};function Ut(t,e,n,s,r,o=!1){if(e.inlineContent)return ae.create(t,n);for(let i=s-(r>0?0:1);r>0?i<e.childCount:i>=0;i+=r){let l=e.child(i);if(l.isAtom){if(!o&&ee.isSelectable(l))return ee.create(t,n-(r<0?l.nodeSize:0))}else{let c=Ut(t,l,n+r,r<0?l.childCount:0,r,o);if(c)return c}n+=l.nodeSize*r}return null}function ca(t,e,n){let s=t.steps.length-1;if(s<e)return;let r=t.steps[s];if(!(r instanceof Fe||r instanceof Me))return;let o=t.mapping.maps[s],i;o.forEach((l,c,u,p)=>{i==null&&(i=p)}),t.setSelection(Y.near(t.doc.resolve(i),n))}function da(t,e){return!e||!t?t:t.bind(e)}class Un{constructor(e,n,s){this.name=e,this.init=da(n.init,s),this.apply=da(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||Y.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 ol(t,e,n){for(let s in t){let r=t[s];r instanceof Function?r=r.bind(e):s=="handleDOMEvents"&&(r=ol(r,e,{})),n[s]=r}return n}class Ht{constructor(e){this.spec=e,this.props={},e.props&&ol(e.props,this,this.props),this.key=e.key?e.key.key:al("plugin")}getState(e){return e[this.key]}}const Js=Object.create(null);function al(t){return t in Js?t+"$"+ ++Js[t]:(Js[t]=0,t+"$")}class Vt{constructor(e="key"){this.key=al(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Qr=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function il(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}const ll=(t,e,n)=>{let s=il(t,n);if(!s)return!1;let r=eo(s);if(!r){let i=s.blockRange(),l=i&&on(i);return l==null?!1:(e&&e(t.tr.lift(i,l).scrollIntoView()),!0)}let o=r.nodeBefore;if(xl(t,r,e,-1))return!0;if(s.parent.content.size==0&&(Zt(o,"end")||ee.isSelectable(o)))for(let i=s.depth;;i--){let l=Jr(t.doc,s.before(i),s.after(i),V.empty);if(l&&l.slice.size<l.to-l.from){if(e){let c=t.tr.step(l);c.setSelection(Zt(o,"end")?Y.findFrom(c.doc.resolve(c.mapping.map(r.pos,-1)),-1):ee.create(c.doc,r.pos-o.nodeSize)),e(c.scrollIntoView())}return!0}if(i==1||s.node(i-1).childCount>1)break}return o.isAtom&&r.depth==s.depth-1?(e&&e(t.tr.delete(r.pos-o.nodeSize,r.pos).scrollIntoView()),!0):!1},xf=(t,e,n)=>{let s=il(t,n);if(!s)return!1;let r=eo(s);return r?cl(t,r,e):!1},bf=(t,e,n)=>{let s=ul(t,n);if(!s)return!1;let r=to(s);return r?cl(t,r,e):!1};function cl(t,e,n){let s=e.nodeBefore,r=s,o=e.pos-1;for(;!r.isTextblock;o--){if(r.type.spec.isolating)return!1;let p=r.lastChild;if(!p)return!1;r=p}let i=e.nodeAfter,l=i,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=Jr(t.doc,o,c,V.empty);if(!u||u.from!=o||u instanceof Fe&&u.slice.size>=c-o)return!1;if(n){let p=t.tr.step(u);p.setSelection(ae.create(p.doc,o)),n(p.scrollIntoView())}return!0}function Zt(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 dl=(t,e,n)=>{let{$head:s,empty:r}=t.selection,o=s;if(!r)return!1;if(s.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):s.parentOffset>0)return!1;o=eo(s)}let i=o&&o.nodeBefore;return!i||!ee.isSelectable(i)?!1:(e&&e(t.tr.setSelection(ee.create(t.doc,o.pos-i.nodeSize)).scrollIntoView()),!0)};function eo(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 ul(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset<n.parent.content.size)?null:n}const pl=(t,e,n)=>{let s=ul(t,n);if(!s)return!1;let r=to(s);if(!r)return!1;let o=r.nodeAfter;if(xl(t,r,e,1))return!0;if(s.parent.content.size==0&&(Zt(o,"start")||ee.isSelectable(o))){let i=Jr(t.doc,s.before(),s.after(),V.empty);if(i&&i.slice.size<i.to-i.from){if(e){let l=t.tr.step(i);l.setSelection(Zt(o,"start")?Y.findFrom(l.doc.resolve(l.mapping.map(r.pos)),1):ee.create(l.doc,l.mapping.map(r.pos))),e(l.scrollIntoView())}return!0}}return o.isAtom&&r.depth==s.depth-1?(e&&e(t.tr.delete(r.pos,r.pos+o.nodeSize).scrollIntoView()),!0):!1},fl=(t,e,n)=>{let{$head:s,empty:r}=t.selection,o=s;if(!r)return!1;if(s.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):s.parentOffset<s.parent.content.size)return!1;o=to(s)}let i=o&&o.nodeAfter;return!i||!ee.isSelectable(i)?!1:(e&&e(t.tr.setSelection(ee.create(t.doc,o.pos)).scrollIntoView()),!0)};function to(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 yf=(t,e)=>{let n=t.selection,s=n instanceof ee,r;if(s){if(n.node.isTextblock||!zt(t.doc,n.from))return!1;r=n.from}else if(r=Is(t.doc,n.from,-1),r==null)return!1;if(e){let o=t.tr.join(r);s&&o.setSelection(ee.create(o.doc,r-t.doc.resolve(r).nodeBefore.nodeSize)),e(o.scrollIntoView())}return!0},vf=(t,e)=>{let n=t.selection,s;if(n instanceof ee){if(n.node.isTextblock||!zt(t.doc,n.to))return!1;s=n.to}else if(s=Is(t.doc,n.to,1),s==null)return!1;return e&&e(t.tr.join(s).scrollIntoView()),!0},kf=(t,e)=>{let{$from:n,$to:s}=t.selection,r=n.blockRange(s),o=r&&on(r);return o==null?!1:(e&&e(t.tr.lift(r,o).scrollIntoView()),!0)},hl=(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 no(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 wf=(t,e)=>{let{$head:n,$anchor:s}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(s))return!1;let r=n.node(-1),o=n.indexAfter(-1),i=no(r.contentMatchAt(o));if(!i||!r.canReplaceWith(o,o,i))return!1;if(e){let l=n.after(),c=t.tr.replaceWith(l,l,i.createAndFill());c.setSelection(Y.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},ml=(t,e)=>{let n=t.selection,{$from:s,$to:r}=n;if(n instanceof We||s.parent.inlineContent||r.parent.inlineContent)return!1;let o=no(r.parent.contentMatchAt(r.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let i=(!s.parentOffset&&r.index()<r.parent.childCount?s:r).pos,l=t.tr.insert(i,o.createAndFill());l.setSelection(ae.create(l.doc,i+1)),e(l.scrollIntoView())}return!0},gl=(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 o=n.before();if(dt(t.doc,o))return e&&e(t.tr.split(o).scrollIntoView()),!0}let s=n.blockRange(),r=s&&on(s);return r==null?!1:(e&&e(t.tr.lift(s,r).scrollIntoView()),!0)};function Cf(t){return(e,n)=>{let{$from:s,$to:r}=e.selection;if(e.selection instanceof ee&&e.selection.node.isBlock)return!s.parentOffset||!dt(e.doc,s.pos)?!1:(n&&n(e.tr.split(s.pos).scrollIntoView()),!0);if(!s.depth)return!1;let o=[],i,l,c=!1,u=!1;for(let h=s.depth;;h--)if(s.node(h).isBlock){c=s.end(h)==s.pos+(s.depth-h),u=s.start(h)==s.pos-(s.depth-h),l=no(s.node(h-1).contentMatchAt(s.indexAfter(h-1))),o.unshift(c&&l?{type:l}:null),i=h;break}else{if(h==1)return!1;o.unshift(null)}let p=e.tr;(e.selection instanceof ae||e.selection instanceof We)&&p.deleteSelection();let f=p.mapping.map(s.pos),m=dt(p.doc,f,o.length,o);if(m||(o[0]=l?{type:l}:null,m=dt(p.doc,f,o.length,o)),!m)return!1;if(p.split(f,o.length,o),!c&&u&&s.node(i).type!=l){let h=p.mapping.map(s.before(i)),x=p.doc.resolve(h);l&&s.node(i-1).canReplaceWith(x.index(),x.index()+1,l)&&p.setNodeMarkup(p.mapping.map(s.before(i)),l)}return n&&n(p.scrollIntoView()),!0}}const jf=Cf(),Sf=(t,e)=>{let{$from:n,to:s}=t.selection,r,o=n.sharedDepth(s);return o==0?!1:(r=n.before(o),e&&e(t.tr.setSelection(ee.create(t.doc,r))),!0)};function Nf(t,e,n){let s=e.nodeBefore,r=e.nodeAfter,o=e.index();return!s||!r||!s.type.compatibleContent(r.type)?!1:!s.content.size&&e.parent.canReplace(o-1,o)?(n&&n(t.tr.delete(e.pos-s.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(r.isTextblock||zt(t.doc,e.pos))?!1:(n&&n(t.tr.join(e.pos).scrollIntoView()),!0)}function xl(t,e,n,s){let r=e.nodeBefore,o=e.nodeAfter,i,l,c=r.type.spec.isolating||o.type.spec.isolating;if(!c&&Nf(t,e,n))return!0;let u=!c&&e.parent.canReplace(e.index(),e.index()+1);if(u&&(i=(l=r.contentMatchAt(r.childCount)).findWrapping(o.type))&&l.matchType(i[0]||o.type).validEnd){if(n){let h=e.pos+o.nodeSize,x=M.empty;for(let k=i.length-1;k>=0;k--)x=M.from(i[k].create(null,x));x=M.from(r.copy(x));let b=t.tr.step(new Me(e.pos-1,h,e.pos,h,new V(x,1,0),i.length,!0)),y=b.doc.resolve(h+2*i.length);y.nodeAfter&&y.nodeAfter.type==r.type&&zt(b.doc,y.pos)&&b.join(y.pos),n(b.scrollIntoView())}return!0}let p=o.type.spec.isolating||s>0&&c?null:Y.findFrom(e,1),f=p&&p.$from.blockRange(p.$to),m=f&&on(f);if(m!=null&&m>=e.depth)return n&&n(t.tr.lift(f,m).scrollIntoView()),!0;if(u&&Zt(o,"start",!0)&&Zt(r,"end")){let h=r,x=[];for(;x.push(h),!h.isTextblock;)h=h.lastChild;let b=o,y=1;for(;!b.isTextblock;b=b.firstChild)y++;if(h.canReplace(h.childCount,h.childCount,b.content)){if(n){let k=M.empty;for(let E=x.length-1;E>=0;E--)k=M.from(x[E].copy(k));let w=t.tr.step(new Me(e.pos-x.length,e.pos+o.nodeSize,e.pos+y,e.pos+o.nodeSize-y,new V(k,x.length,0),0,!0));n(w.scrollIntoView())}return!0}}return!1}function bl(t){return function(e,n){let s=e.selection,r=t<0?s.$from:s.$to,o=r.depth;for(;r.node(o).isInline;){if(!o)return!1;o--}return r.node(o).isTextblock?(n&&n(e.tr.setSelection(ae.create(e.doc,t<0?r.start(o):r.end(o)))),!0):!1}}const Ef=bl(-1),Af=bl(1);function If(t,e=null){return function(n,s){let{$from:r,$to:o}=n.selection,i=r.blockRange(o),l=i&&nl(i,t,e);return l?(s&&s(n.tr.wrap(i,l).scrollIntoView()),!0):!1}}function ua(t,e=null){return function(n,s){let r=!1;for(let o=0;o<n.selection.ranges.length&&!r;o++){let{$from:{pos:i},$to:{pos:l}}=n.selection.ranges[o];n.doc.nodesBetween(i,l,(c,u)=>{if(r)return!1;if(!(!c.isTextblock||c.hasMarkup(t,e)))if(c.type==t)r=!0;else{let p=n.doc.resolve(u),f=p.index();r=p.parent.canReplaceWith(f,f+1,t)}})}if(!r)return!1;if(s){let o=n.tr;for(let i=0;i<n.selection.ranges.length;i++){let{$from:{pos:l},$to:{pos:c}}=n.selection.ranges[i];o.setBlockType(l,c,t,e)}s(o.scrollIntoView())}return!0}}function so(...t){return function(e,n,s){for(let r=0;r<t.length;r++)if(t[r](e,n,s))return!0;return!1}}so(Qr,ll,dl);so(Qr,pl,fl);so(hl,ml,gl,jf);typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function Tf(t,e=null){return function(n,s){let{$from:r,$to:o}=n.selection,i=r.blockRange(o);if(!i)return!1;let l=s?n.tr:null;return _f(l,i,t,e)?(s&&s(l.scrollIntoView()),!0):!1}}function _f(t,e,n,s=null){let r=!1,o=e,i=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=i.resolve(e.start-2);o=new ls(c,c,e.depth),e.endIndex<e.parent.childCount&&(e=new ls(e.$from,i.resolve(e.$to.end(e.depth)),e.depth)),r=!0}let l=nl(o,n,s,e);return l?(t&&Bf(t,e,l,r,n),!0):!1}function Bf(t,e,n,s,r){let o=M.empty;for(let p=n.length-1;p>=0;p--)o=M.from(n[p].type.create(n[p].attrs,o));t.step(new Me(e.start-(s?2:0),e.end,e.start,e.end,new V(o,0,0),n.length,!0));let i=0;for(let p=0;p<n.length;p++)n[p].type==r&&(i=p+1);let l=n.length-i,c=e.start+n.length-(s?2:0),u=e.parent;for(let p=e.startIndex,f=e.endIndex,m=!0;p<f;p++,m=!1)!m&&dt(t.doc,c,l)&&(t.split(c,l),c+=2*l),c+=u.child(p).nodeSize;return t}function Rf(t){return function(e,n){let{$from:s,$to:r}=e.selection,o=s.blockRange(r,i=>i.childCount>0&&i.firstChild.type==t);return o?n?s.node(o.depth-1).type==t?Pf(e,n,t,o):Lf(e,n,o):!0:!1}}function Pf(t,e,n,s){let r=t.tr,o=s.end,i=s.$to.end(s.depth);o<i&&(r.step(new Me(o-1,i,o,i,new V(M.from(n.create(null,s.parent.copy())),1,0),1,!0)),s=new ls(r.doc.resolve(s.$from.pos),r.doc.resolve(i),s.depth));const l=on(s);if(l==null)return!1;r.lift(s,l);let c=r.doc.resolve(r.mapping.map(o,-1)-1);return zt(r.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&r.join(c.pos),e(r.scrollIntoView()),!0}function Lf(t,e,n){let s=t.tr,r=n.parent;for(let h=n.end,x=n.endIndex-1,b=n.startIndex;x>b;x--)h-=r.child(x).nodeSize,s.delete(h-1,h+1);let o=s.doc.resolve(n.start),i=o.nodeAfter;if(s.mapping.map(n.end)!=n.start+o.nodeAfter.nodeSize)return!1;let l=n.startIndex==0,c=n.endIndex==r.childCount,u=o.node(-1),p=o.index(-1);if(!u.canReplace(p+(l?0:1),p+1,i.content.append(c?M.empty:M.from(r))))return!1;let f=o.pos,m=f+i.nodeSize;return s.step(new Me(f-(l?1:0),m+(c?1:0),f+1,m-1,new V((l?M.empty:M.from(r.copy(M.empty))).append(c?M.empty:M.from(r.copy(M.empty))),l?0:1,c?0:1),l?0:1)),e(s.scrollIntoView()),!0}function Mf(t){return function(e,n){let{$from:s,$to:r}=e.selection,o=s.blockRange(r,u=>u.childCount>0&&u.firstChild.type==t);if(!o)return!1;let i=o.startIndex;if(i==0)return!1;let l=o.parent,c=l.child(i-1);if(c.type!=t)return!1;if(n){let u=c.lastChild&&c.lastChild.type==l.type,p=M.from(u?t.create():null),f=new V(M.from(t.create(null,M.from(l.type.create(null,p)))),u?3:1,0),m=o.start,h=o.end;n(e.tr.step(new Me(m-(u?3:1),h,m,h,f,1,!0)).scrollIntoView())}return!0}}function yl(t){const{state:e,transaction:n}=t;let{selection:s}=n,{doc:r}=n,{storedMarks:o}=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 o},get selection(){return s},get doc(){return r},get tr(){return s=n.selection,r=n.doc,o=n.storedMarks,n}}}class Df{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:r}=n,{tr:o}=s,i=this.buildProps(o);return Object.fromEntries(Object.entries(e).map(([l,c])=>[l,(...p)=>{const f=c(...p)(i);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&r.dispatch(o),f}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,n=!0){const{rawCommands:s,editor:r,state:o}=this,{view:i}=r,l=[],c=!!e,u=e||o.tr,p=()=>(!c&&n&&!u.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(u),l.every(m=>m===!0)),f={...Object.fromEntries(Object.entries(s).map(([m,h])=>[m,(...b)=>{const y=this.buildProps(u,n),k=h(...b)(y);return l.push(k),f}])),run:p};return f}createCan(e){const{rawCommands:n,state:s}=this,r=!1,o=e||s.tr,i=this.buildProps(o,r);return{...Object.fromEntries(Object.entries(n).map(([c,u])=>[c,(...p)=>u(...p)({...i,dispatch:void 0})])),chain:()=>this.createChain(o,r)}}buildProps(e,n=!0){const{rawCommands:s,editor:r,state:o}=this,{view:i}=r,l={tr:e,editor:r,view:i,state:yl({state:o,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 Nt(t,e,n){return t.config[e]===void 0&&t.parent?Nt(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?Nt(t.parent,e,n):null}):t.config[e]}function Of(t){const e=t.filter(r=>r.type==="extension"),n=t.filter(r=>r.type==="node"),s=t.filter(r=>r.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 $f(t){return typeof t=="function"}function mn(t,e=void 0,...n){return $f(t)?e?t.bind(e)(...n):t(...n):t}function Ff(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function zf(t){return Object.prototype.toString.call(t).slice(8,-1)}function qn(t){return zf(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function vl(t,e){const n={...t};return qn(t)&&qn(e)&&Object.keys(e).forEach(s=>{qn(e[s])&&qn(t[s])?n[s]=vl(t[s],e[s]):n[s]=e[s]}),n}class Ue{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=mn(Nt(this,"addOptions",{name:this.name}))),this.storage=mn(Nt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new Ue(e)}configure(e={}){const n=this.extend({...this.config,addOptions:()=>vl(this.options,e)});return n.name=this.name,n.parent=this.parent,n}extend(e={}){const n=new Ue({...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=mn(Nt(n,"addOptions",{name:n.name})),n.storage=mn(Nt(n,"addStorage",{name:n.name,options:n.options})),n}}function Hf(t,e,n){const{from:s,to:r}=e,{blockSeparator:o=`
|
|
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 r=0;r<this.parser.matchedStyles.length;r++){let o=this.parser.matchedStyles[r],i=s.getPropertyValue(o);if(i)for(let l=void 0;;){let c=this.parser.matchStyle(o,i,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,r){let o,i;if(n.node)if(i=this.parser.schema.nodes[n.node],i.isLeaf)this.insertNode(i.create(n.attrs),s,e.nodeName=="BR")||this.leafFallback(e,s);else{let c=this.enter(i,n.attrs||null,s,n.preserveWhitespace);c&&(o=!0,s=c)}else{let c=this.parser.schema.marks[n.mark];s=s.concat(c.create(n.attrs))}let l=this.top;if(i&&i.isLeaf)this.findInside(e);else if(r)this.addElement(e,s,r);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)}o&&this.sync(l)&&this.open--}addAll(e,n,s,r){let o=s||0;for(let i=s?e.childNodes[s]:e.firstChild,l=r==null?null:e.childNodes[r];i!=l;i=i.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(i,n);this.findAtPoint(e,o)}findPlace(e,n,s){let r,o;for(let i=this.open,l=0;i>=0;i--){let c=this.nodes[i],u=c.findWrapping(e);if(u&&(!r||r.length>u.length+l)&&(r=u,o=c,!u.length))break;if(c.solid){if(s)break;l+=2}}if(!r)return null;this.sync(o);for(let i=0;i<r.length;i++)n=this.enterInner(r[i],null,n,!1);return n}insertNode(e,n,s){if(e.isInline&&this.needsBlock&&!this.top.type){let o=this.textblockFromContext();o&&(n=this.enterInner(o,null,n))}let r=this.findPlace(e,n,s);if(r){this.closeExtra();let o=this.top;o.match&&(o.match=o.match.matchType(e.type));let i=Q.none;for(let l of r.concat(e.marks))(o.type?o.type.allowsMarkType(l.type):sa(l.type,e.type))&&(i=l.addToSet(i));return o.content.push(e.mark(i)),!0}return!1}enter(e,n,s,r){let o=this.findPlace(e.create(n),s,!1);return o&&(o=this.enterInner(e,n,s,!0,r)),o}enterInner(e,n,s,r=!1,o){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let l=ea(e,o,i.options);i.options&xn&&i.content.length==0&&(l|=xn);let c=Q.none;return s=s.filter(u=>(i.type?i.type.allowsMarkType(u.type):sa(u.type,e))?(c=u.addToSet(c),!1):!0),this.nodes.push(new Gn(e,n,c,r,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|=wn)}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 r=s.length-1;r>=0;r--)e+=s[r].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 r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&n.compareDocumentPosition(this.find[r].node)&(s?2:4)&&(this.find[r].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,r=!this.isOpen&&(!s||s.parent.type==this.nodes[0].type),o=-(s?s.depth+1:0)+(r?0:1),i=(l,c)=>{for(;l>=0;l--){let u=n[l];if(u==""){if(l==n.length-1||l==0)continue;for(;c>=o;c--)if(i(l-1,c))return!0;return!1}else{let p=c>0||c==0&&r?this.nodes[c].type:s&&c>=o?s.node(c-o).type:null;if(!p||p.name!=u&&!p.isInGroup(u))return!1;c--}}return!0};return i(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 sf(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let s=e.nodeType==1?e.nodeName.toLowerCase():null;s&&Xi.hasOwnProperty(s)&&n?(n.appendChild(e),e=n):s=="li"?n=e:s&&(n=null)}}function rf(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function na(t){let e={};for(let n in t)e[n]=t[n];return e}function sa(t,e){let n=e.schema.nodes;for(let s in n){let r=n[s];if(!r.allowsMarkType(t))continue;let o=[],i=l=>{o.push(l);for(let c=0;c<l.edgeCount;c++){let{type:u,next:p}=l.edge(c);if(u==e||o.indexOf(p)<0&&i(p))return!0}};if(i(r.contentMatch))return!0}}const Ji=65535,Zi=Math.pow(2,16);function of(t,e){return t+e*Zi}function ra(t){return t&Ji}function af(t){return(t-(t&Ji))/Zi}const Qi=1,el=2,Jn=4,tl=8;class oa{constructor(e,n,s){this.pos=e,this.delInfo=n,this.recover=s}get deleted(){return(this.delInfo&tl)>0}get deletedBefore(){return(this.delInfo&(Qi|Jn))>0}get deletedAfter(){return(this.delInfo&(el|Jn))>0}get deletedAcross(){return(this.delInfo&Jn)>0}}class ze{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&ze.empty)return ze.empty}recover(e){let n=0,s=ra(e);if(!this.inverted)for(let r=0;r<s;r++)n+=this.ranges[r*3+2]-this.ranges[r*3+1];return this.ranges[s*3]+n+af(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 r=0,o=this.inverted?2:1,i=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let c=this.ranges[l]-(this.inverted?r:0);if(c>e)break;let u=this.ranges[l+o],p=this.ranges[l+i],f=c+u;if(e<=f){let m=u?e==c?-1:e==f?1:n:n,h=c+r+(m<0?0:p);if(s)return h;let x=e==(n<0?c:f)?null:of(l/3,e-c),b=e==c?el:e==f?Qi:Jn;return(n<0?e!=c:e!=f)&&(b|=tl),new oa(h,b,x)}r+=p-u}return s?e+r:new oa(e+r,0,null)}touches(e,n){let s=0,r=ra(n),o=this.inverted?2:1,i=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+o],p=c+u;if(e<=p&&l==r*3)return!0;s+=this.ranges[l+i]-u}return!1}forEach(e){let n=this.inverted?2:1,s=this.inverted?1:2;for(let r=0,o=0;r<this.ranges.length;r+=3){let i=this.ranges[r],l=i-(this.inverted?o:0),c=i+(this.inverted?0:o),u=this.ranges[r+n],p=this.ranges[r+s];e(l,l+u,c,c+p),o+=p-u}}invert(){return new ze(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?ze.empty:new ze(e<0?[0,-e,0]:[0,0,e])}}ze.empty=new ze([]);const qs=Object.create(null);class _e{getMap(){return ze.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let s=qs[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 qs)throw new RangeError("Duplicate use of step JSON ID "+e);return qs[e]=n,n.prototype.jsonID=e,n}}class ye{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new ye(e,null)}static fail(e){return new ye(null,e)}static fromReplace(e,n,s,r){try{return ye.ok(e.replace(n,s,r))}catch(o){if(o instanceof as)return ye.fail(o.message);throw o}}}function Xr(t,e,n){let s=[];for(let r=0;r<t.childCount;r++){let o=t.child(r);o.content.size&&(o=o.copy(Xr(o.content,e,o))),o.isInline&&(o=e(o,n,r)),s.push(o)}return M.fromArray(s)}class Ct extends _e{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),r=s.node(s.sharedDepth(this.to)),o=new V(Xr(n.content,(i,l)=>!i.isAtom||!l.type.allowsMarkType(this.mark.type)?i:i.mark(this.mark.addToSet(i.marks)),r),n.openStart,n.openEnd);return ye.fromReplace(e,this.from,this.to,o)}invert(){return new jt(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 Ct(n.pos,s.pos,this.mark)}merge(e){return e instanceof Ct&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ct(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 Ct(n.from,n.to,e.markFromJSON(n.mark))}}_e.jsonID("addMark",Ct);class jt extends _e{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 V(Xr(n.content,r=>r.mark(this.mark.removeFromSet(r.marks)),e),n.openStart,n.openEnd);return ye.fromReplace(e,this.from,this.to,s)}invert(){return new Ct(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 jt(n.pos,s.pos,this.mark)}merge(e){return e instanceof jt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new jt(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 jt(n.from,n.to,e.markFromJSON(n.mark))}}_e.jsonID("removeMark",jt);class St extends _e{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return ye.fail("No node at mark step's position");let s=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return ye.fromReplace(e,this.pos,this.pos+1,new V(M.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 r=0;r<n.marks.length;r++)if(!n.marks[r].isInSet(s))return new St(this.pos,n.marks[r]);return new St(this.pos,this.mark)}}return new Cn(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new St(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 St(n.pos,e.markFromJSON(n.mark))}}_e.jsonID("addNodeMark",St);class Cn extends _e{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return ye.fail("No node at mark step's position");let s=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return ye.fromReplace(e,this.pos,this.pos+1,new V(M.from(s),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new St(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Cn(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 Cn(n.pos,e.markFromJSON(n.mark))}}_e.jsonID("removeNodeMark",Cn);class Fe extends _e{constructor(e,n,s,r=!1){super(),this.from=e,this.to=n,this.slice=s,this.structure=r}apply(e){return this.structure&&pr(e,this.from,this.to)?ye.fail("Structure replace would overwrite content"):ye.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new ze([this.from,this.to-this.from,this.slice.size])}invert(e){return new Fe(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 Fe(n.pos,Math.max(n.pos,s.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Fe)||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?V.empty:new V(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Fe(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?V.empty:new V(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Fe(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 Fe(n.from,n.to,V.fromJSON(e,n.slice),!!n.structure)}}_e.jsonID("replace",Fe);class Me extends _e{constructor(e,n,s,r,o,i,l=!1){super(),this.from=e,this.to=n,this.gapFrom=s,this.gapTo=r,this.slice=o,this.insert=i,this.structure=l}apply(e){if(this.structure&&(pr(e,this.from,this.gapFrom)||pr(e,this.gapTo,this.to)))return ye.fail("Structure gap-replace would overwrite content");let n=e.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return ye.fail("Gap is not a flat range");let s=this.slice.insertAt(this.insert,n.content);return s?ye.fromReplace(e,this.from,this.to,s):ye.fail("Content does not fit in gap")}getMap(){return new ze([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 Me(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),r=this.from==this.gapFrom?n.pos:e.map(this.gapFrom,-1),o=this.to==this.gapTo?s.pos:e.map(this.gapTo,1);return n.deletedAcross&&s.deletedAcross||r<n.pos||o>s.pos?null:new Me(n.pos,s.pos,r,o,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 Me(n.from,n.to,n.gapFrom,n.gapTo,V.fromJSON(e,n.slice),n.insert,!!n.structure)}}_e.jsonID("replaceAround",Me);function pr(t,e,n){let s=t.resolve(e),r=n-e,o=s.depth;for(;r>0&&o>0&&s.indexAfter(o)==s.node(o).childCount;)o--,r--;if(r>0){let i=s.node(o).maybeChild(s.indexAfter(o));for(;r>0;){if(!i||i.isLeaf)return!0;i=i.firstChild,r--}}return!1}function lf(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function on(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let s=t.depth,r=0,o=0;;--s){let i=t.$from.node(s),l=t.$from.index(s)+r,c=t.$to.indexAfter(s)-o;if(s<t.depth&&i.canReplace(l,c,n))return s;if(s==0||i.type.spec.isolating||!lf(i,l,c))break;l&&(r=1),c<i.childCount&&(o=1)}return null}function nl(t,e,n=null,s=t){let r=cf(t,e),o=r&&df(s,e);return o?r.map(aa).concat({type:e,attrs:n}).concat(o.map(aa)):null}function aa(t){return{type:t,attrs:null}}function cf(t,e){let{parent:n,startIndex:s,endIndex:r}=t,o=n.contentMatchAt(s).findWrapping(e);if(!o)return null;let i=o.length?o[0]:e;return n.canReplaceWith(s,r,i)?o:null}function df(t,e){let{parent:n,startIndex:s,endIndex:r}=t,o=n.child(s),i=e.contentMatch.findWrapping(o.type);if(!i)return null;let c=(i.length?i[i.length-1]:e).contentMatch;for(let u=s;c&&u<r;u++)c=c.matchType(n.child(u).type);return!c||!c.validEnd?null:i}function dt(t,e,n=1,s){let r=t.resolve(e),o=r.depth-n,i=s&&s[s.length-1]||r.parent;if(o<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!i.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let u=r.depth-1,p=n-2;u>o;u--,p--){let f=r.node(u),m=r.index(u);if(f.type.spec.isolating)return!1;let h=f.content.cutByIndex(m,f.childCount),x=s&&s[p+1];x&&(h=h.replaceChild(0,x.type.create(x.attrs)));let b=s&&s[p]||f;if(!f.canReplace(m+1,f.childCount)||!b.type.validContent(h))return!1}let l=r.indexAfter(o),c=s&&s[0];return r.node(o).canReplaceWith(l,l,c?c.type:r.node(o+1).type)}function zt(t,e){let n=t.resolve(e),s=n.index();return sl(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(s,s+1)}function uf(t,e){e.content.size||t.type.compatibleContent(e.type);let n=t.contentMatchAt(t.childCount),{linebreakReplacement:s}=t.type.schema;for(let r=0;r<e.childCount;r++){let o=e.child(r),i=o.type==s?t.type.schema.nodes.text:o.type;if(n=n.matchType(i),!n||!t.type.allowsMarks(o.marks))return!1}return n.validEnd}function sl(t,e){return!!(t&&e&&!t.isLeaf&&uf(t,e))}function Is(t,e,n=-1){let s=t.resolve(e);for(let r=s.depth;;r--){let o,i,l=s.index(r);if(r==s.depth?(o=s.nodeBefore,i=s.nodeAfter):n>0?(o=s.node(r+1),l++,i=s.node(r).maybeChild(l)):(o=s.node(r).maybeChild(l-1),i=s.node(r+1)),o&&!o.isTextblock&&sl(o,i)&&s.node(r).canReplace(l,l+1))return e;if(r==0)break;e=n<0?s.before(r):s.after(r)}}function Jr(t,e,n=e,s=V.empty){if(e==n&&!s.size)return null;let r=t.resolve(e),o=t.resolve(n);return pf(r,o,s)?new Fe(e,n,s):new ff(r,o,s).fit()}function pf(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}class ff{constructor(e,n,s){this.$from=e,this.$to=n,this.unplaced=s,this.frontier=[],this.placed=M.empty;for(let r=0;r<=e.depth;r++){let o=e.node(r);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(r))})}for(let r=e.depth;r>0;r--)this.placed=M.from(e.node(r).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,r=this.close(e<0?this.$to:s.doc.resolve(e));if(!r)return null;let o=this.placed,i=s.depth,l=r.depth;for(;i&&l&&o.childCount==1;)o=o.firstChild.content,i--,l--;let c=new V(o,i,l);return e>-1?new Me(s.pos,e,this.$to.pos,this.$to.end(),c,n):c.size||s.pos!=this.$to.pos?new Fe(s.pos,r.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,s=0,r=this.unplaced.openEnd;s<e;s++){let o=n.firstChild;if(n.childCount>1&&(r=0),o.type.spec.isolating&&r<=s){e=s;break}n=o.content}for(let n=1;n<=2;n++)for(let s=n==1?e:this.unplaced.openStart;s>=0;s--){let r,o=null;s?(o=Ks(this.unplaced.content,s-1).firstChild,r=o.content):r=this.unplaced.content;let i=r.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:u}=this.frontier[l],p,f=null;if(n==1&&(i?u.matchType(i.type)||(f=u.fillBefore(M.from(i),!1)):o&&c.compatibleContent(o.type)))return{sliceDepth:s,frontierDepth:l,parent:o,inject:f};if(n==2&&i&&(p=u.findWrapping(i.type)))return{sliceDepth:s,frontierDepth:l,parent:o,wrap:p};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:s}=this.unplaced,r=Ks(e,n);return!r.childCount||r.firstChild.isLeaf?!1:(this.unplaced=new V(e,n+1,Math.max(s,r.size+n>=e.size-s?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:s}=this.unplaced,r=Ks(e,n);if(r.childCount<=1&&n>0){let o=e.size-n<=n+r.size;this.unplaced=new V(fn(e,n-1,1),n-1,o?n-1:s)}else this.unplaced=new V(fn(e,n,1),n,s)}placeNodes({sliceDepth:e,frontierDepth:n,parent:s,inject:r,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let b=0;b<o.length;b++)this.openFrontierNode(o[b]);let i=this.unplaced,l=s?s.content:i.content,c=i.openStart-e,u=0,p=[],{match:f,type:m}=this.frontier[n];if(r){for(let b=0;b<r.childCount;b++)p.push(r.child(b));f=f.matchFragment(r)}let h=l.size+e-(i.content.size-i.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(rl(b.mark(m.allowedMarks(b.marks)),u==1?c:0,u==l.childCount?h:-1)))}let x=u==l.childCount;x||(h=-1),this.placed=hn(this.placed,n,M.from(p)),this.frontier[n].match=f,x&&h<0&&s&&s.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let b=0,y=l;b<h;b++){let v=y.lastChild;this.frontier.push({type:v.type,match:v.contentMatchAt(v.childCount)}),y=v.content}this.unplaced=x?e==0?V.empty:new V(fn(i.content,e-1,1),e-1,h<0?i.openEnd:e-1):new V(fn(i.content,e,u),i.openStart,i.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],n;if(!e.type.isTextblock||!Ys(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,r=this.$to.after(s);for(;s>1&&r==this.$to.end(--s);)++r;return r}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:s,type:r}=this.frontier[n],o=n<e.depth&&e.end(n+1)==e.pos+(e.depth-(n+1)),i=Ys(e,n,r,s,o);if(i){for(let l=n-1;l>=0;l--){let{match:c,type:u}=this.frontier[l],p=Ys(e,l,u,c,!0);if(!p||p.childCount)continue e}return{depth:n,fit:i,move:o?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=hn(this.placed,n.depth,n.fit)),e=n.move;for(let s=n.depth+1;s<=e.depth;s++){let r=e.node(s),o=r.type.contentMatch.fillBefore(r.content,!0,e.index(s));this.openFrontierNode(r.type,r.attrs,o)}return e}openFrontierNode(e,n=null,s){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=hn(this.placed,this.depth,M.from(e.create(n,s))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(M.empty,!0);n.childCount&&(this.placed=hn(this.placed,this.frontier.length,n))}}function fn(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(fn(t.firstChild.content,e-1,n)))}function hn(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(hn(t.lastChild.content,e-1,n)))}function Ks(t,e){for(let n=0;n<e;n++)t=t.firstChild.content;return t}function rl(t,e,n){if(e<=0)return t;let s=t.content;return e>1&&(s=s.replaceChild(0,rl(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(M.empty,!0)))),t.copy(s)}function Ys(t,e,n,s,r){let o=t.node(e),i=r?t.indexAfter(e):t.index(e);if(i==o.childCount&&!n.compatibleContent(o.type))return null;let l=s.fillBefore(o.content,!0,i);return l&&!hf(n,o.content,i)?l:null}function hf(t,e,n){for(let s=n;s<e.childCount;s++)if(!t.allowsMarks(e.child(s).marks))return!0;return!1}class bn extends _e{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 ye.fail("No node at attribute step's position");let s=Object.create(null);for(let o in n.attrs)s[o]=n.attrs[o];s[this.attr]=this.value;let r=n.type.create(s,null,n.marks);return ye.fromReplace(e,this.pos,this.pos+1,new V(M.from(r),0,n.isLeaf?0:1))}getMap(){return ze.empty}invert(e){return new bn(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 bn(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 bn(n.pos,n.attr,n.value)}}_e.jsonID("attr",bn);class us extends _e{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let r in e.attrs)n[r]=e.attrs[r];n[this.attr]=this.value;let s=e.type.create(n,e.content,e.marks);return ye.ok(s)}getMap(){return ze.empty}invert(e){return new us(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 us(n.attr,n.value)}}_e.jsonID("docAttr",us);let jn=class extends Error{};jn=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};jn.prototype=Object.create(Error.prototype);jn.prototype.constructor=jn;jn.prototype.name="TransformError";const Xs=Object.create(null);class Y{constructor(e,n,s){this.$anchor=e,this.$head=n,this.ranges=s||[new mf(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=V.empty){let s=n.content.lastChild,r=null;for(let l=0;l<n.openEnd;l++)r=s,s=s.lastChild;let o=e.steps.length,i=this.ranges;for(let l=0;l<i.length;l++){let{$from:c,$to:u}=i[l],p=e.mapping.slice(o);e.replaceRange(p.map(c.pos),p.map(u.pos),l?V.empty:n),l==0&&ca(e,o,(s?s.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,n){let s=e.steps.length,r=this.ranges;for(let o=0;o<r.length;o++){let{$from:i,$to:l}=r[o],c=e.mapping.slice(s),u=c.map(i.pos),p=c.map(l.pos);o?e.deleteRange(u,p):(e.replaceRangeWith(u,p,n),ca(e,s,n.isInline?-1:1))}}static findFrom(e,n,s=!1){let r=e.parent.inlineContent?new ae(e):Ut(e.node(0),e.parent,e.pos,e.index(),n,s);if(r)return r;for(let o=e.depth-1;o>=0;o--){let i=n<0?Ut(e.node(0),e.node(o),e.before(o+1),e.index(o),n,s):Ut(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,s);if(i)return i}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new We(e.node(0))}static atStart(e){return Ut(e,e,0,0,1)||new We(e)}static atEnd(e){return Ut(e,e,e.content.size,e.childCount,-1)||new We(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let s=Xs[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 Xs)throw new RangeError("Duplicate use of selection JSON ID "+e);return Xs[e]=n,n.prototype.jsonID=e,n}getBookmark(){return ae.between(this.$anchor,this.$head).getBookmark()}}Y.prototype.visible=!0;class mf{constructor(e,n){this.$from=e,this.$to=n}}let ia=!1;function la(t){!ia&&!t.parent.inlineContent&&(ia=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class ae extends Y{constructor(e,n=e){la(e),la(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 Y.near(s);let r=e.resolve(n.map(this.anchor));return new ae(r.parent.inlineContent?r:s,s)}replace(e,n=V.empty){if(super.replace(e,n),n==V.empty){let s=this.$from.marksAcross(this.$to);s&&e.ensureMarks(s)}}eq(e){return e instanceof ae&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Ts(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 ae(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,s=n){let r=e.resolve(n);return new this(r,s==n?r:e.resolve(s))}static between(e,n,s){let r=e.pos-n.pos;if((!s||r)&&(s=r>=0?1:-1),!n.parent.inlineContent){let o=Y.findFrom(n,s,!0)||Y.findFrom(n,-s,!0);if(o)n=o.$head;else return Y.near(n,s)}return e.parent.inlineContent||(r==0?e=n:(e=(Y.findFrom(e,-s,!0)||Y.findFrom(e,s,!0)).$anchor,e.pos<n.pos!=r<0&&(e=n))),new ae(e,n)}}Y.jsonID("text",ae);class Ts{constructor(e,n){this.anchor=e,this.head=n}map(e){return new Ts(e.map(this.anchor),e.map(this.head))}resolve(e){return ae.between(e.resolve(this.anchor),e.resolve(this.head))}}class ee extends Y{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:r}=n.mapResult(this.anchor),o=e.resolve(r);return s?Y.near(o):new ee(o)}content(){return new V(M.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 Zr(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;Y.jsonID("node",ee);class Zr{constructor(e){this.anchor=e}map(e){let{deleted:n,pos:s}=e.mapResult(this.anchor);return n?new Ts(s,s):new Zr(s)}resolve(e){let n=e.resolve(this.anchor),s=n.nodeAfter;return s&&ee.isSelectable(s)?new ee(n):Y.near(n)}}class We extends Y{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,n=V.empty){if(n==V.empty){e.delete(0,e.doc.content.size);let s=Y.atStart(e.doc);s.eq(e.selection)||e.setSelection(s)}else super.replace(e,n)}toJSON(){return{type:"all"}}static fromJSON(e){return new We(e)}map(e){return new We(e)}eq(e){return e instanceof We}getBookmark(){return gf}}Y.jsonID("all",We);const gf={map(){return this},resolve(t){return new We(t)}};function Ut(t,e,n,s,r,o=!1){if(e.inlineContent)return ae.create(t,n);for(let i=s-(r>0?0:1);r>0?i<e.childCount:i>=0;i+=r){let l=e.child(i);if(l.isAtom){if(!o&&ee.isSelectable(l))return ee.create(t,n-(r<0?l.nodeSize:0))}else{let c=Ut(t,l,n+r,r<0?l.childCount:0,r,o);if(c)return c}n+=l.nodeSize*r}return null}function ca(t,e,n){let s=t.steps.length-1;if(s<e)return;let r=t.steps[s];if(!(r instanceof Fe||r instanceof Me))return;let o=t.mapping.maps[s],i;o.forEach((l,c,u,p)=>{i==null&&(i=p)}),t.setSelection(Y.near(t.doc.resolve(i),n))}function da(t,e){return!e||!t?t:t.bind(e)}class Un{constructor(e,n,s){this.name=e,this.init=da(n.init,s),this.apply=da(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||Y.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 ol(t,e,n){for(let s in t){let r=t[s];r instanceof Function?r=r.bind(e):s=="handleDOMEvents"&&(r=ol(r,e,{})),n[s]=r}return n}class Ht{constructor(e){this.spec=e,this.props={},e.props&&ol(e.props,this,this.props),this.key=e.key?e.key.key:al("plugin")}getState(e){return e[this.key]}}const Js=Object.create(null);function al(t){return t in Js?t+"$"+ ++Js[t]:(Js[t]=0,t+"$")}class Vt{constructor(e="key"){this.key=al(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Qr=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function il(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}const ll=(t,e,n)=>{let s=il(t,n);if(!s)return!1;let r=eo(s);if(!r){let i=s.blockRange(),l=i&&on(i);return l==null?!1:(e&&e(t.tr.lift(i,l).scrollIntoView()),!0)}let o=r.nodeBefore;if(xl(t,r,e,-1))return!0;if(s.parent.content.size==0&&(Zt(o,"end")||ee.isSelectable(o)))for(let i=s.depth;;i--){let l=Jr(t.doc,s.before(i),s.after(i),V.empty);if(l&&l.slice.size<l.to-l.from){if(e){let c=t.tr.step(l);c.setSelection(Zt(o,"end")?Y.findFrom(c.doc.resolve(c.mapping.map(r.pos,-1)),-1):ee.create(c.doc,r.pos-o.nodeSize)),e(c.scrollIntoView())}return!0}if(i==1||s.node(i-1).childCount>1)break}return o.isAtom&&r.depth==s.depth-1?(e&&e(t.tr.delete(r.pos-o.nodeSize,r.pos).scrollIntoView()),!0):!1},xf=(t,e,n)=>{let s=il(t,n);if(!s)return!1;let r=eo(s);return r?cl(t,r,e):!1},bf=(t,e,n)=>{let s=ul(t,n);if(!s)return!1;let r=to(s);return r?cl(t,r,e):!1};function cl(t,e,n){let s=e.nodeBefore,r=s,o=e.pos-1;for(;!r.isTextblock;o--){if(r.type.spec.isolating)return!1;let p=r.lastChild;if(!p)return!1;r=p}let i=e.nodeAfter,l=i,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=Jr(t.doc,o,c,V.empty);if(!u||u.from!=o||u instanceof Fe&&u.slice.size>=c-o)return!1;if(n){let p=t.tr.step(u);p.setSelection(ae.create(p.doc,o)),n(p.scrollIntoView())}return!0}function Zt(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 dl=(t,e,n)=>{let{$head:s,empty:r}=t.selection,o=s;if(!r)return!1;if(s.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):s.parentOffset>0)return!1;o=eo(s)}let i=o&&o.nodeBefore;return!i||!ee.isSelectable(i)?!1:(e&&e(t.tr.setSelection(ee.create(t.doc,o.pos-i.nodeSize)).scrollIntoView()),!0)};function eo(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 ul(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset<n.parent.content.size)?null:n}const pl=(t,e,n)=>{let s=ul(t,n);if(!s)return!1;let r=to(s);if(!r)return!1;let o=r.nodeAfter;if(xl(t,r,e,1))return!0;if(s.parent.content.size==0&&(Zt(o,"start")||ee.isSelectable(o))){let i=Jr(t.doc,s.before(),s.after(),V.empty);if(i&&i.slice.size<i.to-i.from){if(e){let l=t.tr.step(i);l.setSelection(Zt(o,"start")?Y.findFrom(l.doc.resolve(l.mapping.map(r.pos)),1):ee.create(l.doc,l.mapping.map(r.pos))),e(l.scrollIntoView())}return!0}}return o.isAtom&&r.depth==s.depth-1?(e&&e(t.tr.delete(r.pos,r.pos+o.nodeSize).scrollIntoView()),!0):!1},fl=(t,e,n)=>{let{$head:s,empty:r}=t.selection,o=s;if(!r)return!1;if(s.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):s.parentOffset<s.parent.content.size)return!1;o=to(s)}let i=o&&o.nodeAfter;return!i||!ee.isSelectable(i)?!1:(e&&e(t.tr.setSelection(ee.create(t.doc,o.pos)).scrollIntoView()),!0)};function to(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 yf=(t,e)=>{let n=t.selection,s=n instanceof ee,r;if(s){if(n.node.isTextblock||!zt(t.doc,n.from))return!1;r=n.from}else if(r=Is(t.doc,n.from,-1),r==null)return!1;if(e){let o=t.tr.join(r);s&&o.setSelection(ee.create(o.doc,r-t.doc.resolve(r).nodeBefore.nodeSize)),e(o.scrollIntoView())}return!0},vf=(t,e)=>{let n=t.selection,s;if(n instanceof ee){if(n.node.isTextblock||!zt(t.doc,n.to))return!1;s=n.to}else if(s=Is(t.doc,n.to,1),s==null)return!1;return e&&e(t.tr.join(s).scrollIntoView()),!0},kf=(t,e)=>{let{$from:n,$to:s}=t.selection,r=n.blockRange(s),o=r&&on(r);return o==null?!1:(e&&e(t.tr.lift(r,o).scrollIntoView()),!0)},hl=(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 no(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 wf=(t,e)=>{let{$head:n,$anchor:s}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(s))return!1;let r=n.node(-1),o=n.indexAfter(-1),i=no(r.contentMatchAt(o));if(!i||!r.canReplaceWith(o,o,i))return!1;if(e){let l=n.after(),c=t.tr.replaceWith(l,l,i.createAndFill());c.setSelection(Y.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},ml=(t,e)=>{let n=t.selection,{$from:s,$to:r}=n;if(n instanceof We||s.parent.inlineContent||r.parent.inlineContent)return!1;let o=no(r.parent.contentMatchAt(r.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let i=(!s.parentOffset&&r.index()<r.parent.childCount?s:r).pos,l=t.tr.insert(i,o.createAndFill());l.setSelection(ae.create(l.doc,i+1)),e(l.scrollIntoView())}return!0},gl=(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 o=n.before();if(dt(t.doc,o))return e&&e(t.tr.split(o).scrollIntoView()),!0}let s=n.blockRange(),r=s&&on(s);return r==null?!1:(e&&e(t.tr.lift(s,r).scrollIntoView()),!0)};function Cf(t){return(e,n)=>{let{$from:s,$to:r}=e.selection;if(e.selection instanceof ee&&e.selection.node.isBlock)return!s.parentOffset||!dt(e.doc,s.pos)?!1:(n&&n(e.tr.split(s.pos).scrollIntoView()),!0);if(!s.depth)return!1;let o=[],i,l,c=!1,u=!1;for(let h=s.depth;;h--)if(s.node(h).isBlock){c=s.end(h)==s.pos+(s.depth-h),u=s.start(h)==s.pos-(s.depth-h),l=no(s.node(h-1).contentMatchAt(s.indexAfter(h-1))),o.unshift(c&&l?{type:l}:null),i=h;break}else{if(h==1)return!1;o.unshift(null)}let p=e.tr;(e.selection instanceof ae||e.selection instanceof We)&&p.deleteSelection();let f=p.mapping.map(s.pos),m=dt(p.doc,f,o.length,o);if(m||(o[0]=l?{type:l}:null,m=dt(p.doc,f,o.length,o)),!m)return!1;if(p.split(f,o.length,o),!c&&u&&s.node(i).type!=l){let h=p.mapping.map(s.before(i)),x=p.doc.resolve(h);l&&s.node(i-1).canReplaceWith(x.index(),x.index()+1,l)&&p.setNodeMarkup(p.mapping.map(s.before(i)),l)}return n&&n(p.scrollIntoView()),!0}}const jf=Cf(),Sf=(t,e)=>{let{$from:n,to:s}=t.selection,r,o=n.sharedDepth(s);return o==0?!1:(r=n.before(o),e&&e(t.tr.setSelection(ee.create(t.doc,r))),!0)};function Nf(t,e,n){let s=e.nodeBefore,r=e.nodeAfter,o=e.index();return!s||!r||!s.type.compatibleContent(r.type)?!1:!s.content.size&&e.parent.canReplace(o-1,o)?(n&&n(t.tr.delete(e.pos-s.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(r.isTextblock||zt(t.doc,e.pos))?!1:(n&&n(t.tr.join(e.pos).scrollIntoView()),!0)}function xl(t,e,n,s){let r=e.nodeBefore,o=e.nodeAfter,i,l,c=r.type.spec.isolating||o.type.spec.isolating;if(!c&&Nf(t,e,n))return!0;let u=!c&&e.parent.canReplace(e.index(),e.index()+1);if(u&&(i=(l=r.contentMatchAt(r.childCount)).findWrapping(o.type))&&l.matchType(i[0]||o.type).validEnd){if(n){let h=e.pos+o.nodeSize,x=M.empty;for(let v=i.length-1;v>=0;v--)x=M.from(i[v].create(null,x));x=M.from(r.copy(x));let b=t.tr.step(new Me(e.pos-1,h,e.pos,h,new V(x,1,0),i.length,!0)),y=b.doc.resolve(h+2*i.length);y.nodeAfter&&y.nodeAfter.type==r.type&&zt(b.doc,y.pos)&&b.join(y.pos),n(b.scrollIntoView())}return!0}let p=o.type.spec.isolating||s>0&&c?null:Y.findFrom(e,1),f=p&&p.$from.blockRange(p.$to),m=f&&on(f);if(m!=null&&m>=e.depth)return n&&n(t.tr.lift(f,m).scrollIntoView()),!0;if(u&&Zt(o,"start",!0)&&Zt(r,"end")){let h=r,x=[];for(;x.push(h),!h.isTextblock;)h=h.lastChild;let b=o,y=1;for(;!b.isTextblock;b=b.firstChild)y++;if(h.canReplace(h.childCount,h.childCount,b.content)){if(n){let v=M.empty;for(let N=x.length-1;N>=0;N--)v=M.from(x[N].copy(v));let w=t.tr.step(new Me(e.pos-x.length,e.pos+o.nodeSize,e.pos+y,e.pos+o.nodeSize-y,new V(v,x.length,0),0,!0));n(w.scrollIntoView())}return!0}}return!1}function bl(t){return function(e,n){let s=e.selection,r=t<0?s.$from:s.$to,o=r.depth;for(;r.node(o).isInline;){if(!o)return!1;o--}return r.node(o).isTextblock?(n&&n(e.tr.setSelection(ae.create(e.doc,t<0?r.start(o):r.end(o)))),!0):!1}}const Ef=bl(-1),Af=bl(1);function If(t,e=null){return function(n,s){let{$from:r,$to:o}=n.selection,i=r.blockRange(o),l=i&&nl(i,t,e);return l?(s&&s(n.tr.wrap(i,l).scrollIntoView()),!0):!1}}function ua(t,e=null){return function(n,s){let r=!1;for(let o=0;o<n.selection.ranges.length&&!r;o++){let{$from:{pos:i},$to:{pos:l}}=n.selection.ranges[o];n.doc.nodesBetween(i,l,(c,u)=>{if(r)return!1;if(!(!c.isTextblock||c.hasMarkup(t,e)))if(c.type==t)r=!0;else{let p=n.doc.resolve(u),f=p.index();r=p.parent.canReplaceWith(f,f+1,t)}})}if(!r)return!1;if(s){let o=n.tr;for(let i=0;i<n.selection.ranges.length;i++){let{$from:{pos:l},$to:{pos:c}}=n.selection.ranges[i];o.setBlockType(l,c,t,e)}s(o.scrollIntoView())}return!0}}function so(...t){return function(e,n,s){for(let r=0;r<t.length;r++)if(t[r](e,n,s))return!0;return!1}}so(Qr,ll,dl);so(Qr,pl,fl);so(hl,ml,gl,jf);typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function Tf(t,e=null){return function(n,s){let{$from:r,$to:o}=n.selection,i=r.blockRange(o);if(!i)return!1;let l=s?n.tr:null;return _f(l,i,t,e)?(s&&s(l.scrollIntoView()),!0):!1}}function _f(t,e,n,s=null){let r=!1,o=e,i=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=i.resolve(e.start-2);o=new ls(c,c,e.depth),e.endIndex<e.parent.childCount&&(e=new ls(e.$from,i.resolve(e.$to.end(e.depth)),e.depth)),r=!0}let l=nl(o,n,s,e);return l?(t&&Bf(t,e,l,r,n),!0):!1}function Bf(t,e,n,s,r){let o=M.empty;for(let p=n.length-1;p>=0;p--)o=M.from(n[p].type.create(n[p].attrs,o));t.step(new Me(e.start-(s?2:0),e.end,e.start,e.end,new V(o,0,0),n.length,!0));let i=0;for(let p=0;p<n.length;p++)n[p].type==r&&(i=p+1);let l=n.length-i,c=e.start+n.length-(s?2:0),u=e.parent;for(let p=e.startIndex,f=e.endIndex,m=!0;p<f;p++,m=!1)!m&&dt(t.doc,c,l)&&(t.split(c,l),c+=2*l),c+=u.child(p).nodeSize;return t}function Rf(t){return function(e,n){let{$from:s,$to:r}=e.selection,o=s.blockRange(r,i=>i.childCount>0&&i.firstChild.type==t);return o?n?s.node(o.depth-1).type==t?Pf(e,n,t,o):Lf(e,n,o):!0:!1}}function Pf(t,e,n,s){let r=t.tr,o=s.end,i=s.$to.end(s.depth);o<i&&(r.step(new Me(o-1,i,o,i,new V(M.from(n.create(null,s.parent.copy())),1,0),1,!0)),s=new ls(r.doc.resolve(s.$from.pos),r.doc.resolve(i),s.depth));const l=on(s);if(l==null)return!1;r.lift(s,l);let c=r.doc.resolve(r.mapping.map(o,-1)-1);return zt(r.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&r.join(c.pos),e(r.scrollIntoView()),!0}function Lf(t,e,n){let s=t.tr,r=n.parent;for(let h=n.end,x=n.endIndex-1,b=n.startIndex;x>b;x--)h-=r.child(x).nodeSize,s.delete(h-1,h+1);let o=s.doc.resolve(n.start),i=o.nodeAfter;if(s.mapping.map(n.end)!=n.start+o.nodeAfter.nodeSize)return!1;let l=n.startIndex==0,c=n.endIndex==r.childCount,u=o.node(-1),p=o.index(-1);if(!u.canReplace(p+(l?0:1),p+1,i.content.append(c?M.empty:M.from(r))))return!1;let f=o.pos,m=f+i.nodeSize;return s.step(new Me(f-(l?1:0),m+(c?1:0),f+1,m-1,new V((l?M.empty:M.from(r.copy(M.empty))).append(c?M.empty:M.from(r.copy(M.empty))),l?0:1,c?0:1),l?0:1)),e(s.scrollIntoView()),!0}function Mf(t){return function(e,n){let{$from:s,$to:r}=e.selection,o=s.blockRange(r,u=>u.childCount>0&&u.firstChild.type==t);if(!o)return!1;let i=o.startIndex;if(i==0)return!1;let l=o.parent,c=l.child(i-1);if(c.type!=t)return!1;if(n){let u=c.lastChild&&c.lastChild.type==l.type,p=M.from(u?t.create():null),f=new V(M.from(t.create(null,M.from(l.type.create(null,p)))),u?3:1,0),m=o.start,h=o.end;n(e.tr.step(new Me(m-(u?3:1),h,m,h,f,1,!0)).scrollIntoView())}return!0}}function yl(t){const{state:e,transaction:n}=t;let{selection:s}=n,{doc:r}=n,{storedMarks:o}=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 o},get selection(){return s},get doc(){return r},get tr(){return s=n.selection,r=n.doc,o=n.storedMarks,n}}}class Df{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:r}=n,{tr:o}=s,i=this.buildProps(o);return Object.fromEntries(Object.entries(e).map(([l,c])=>[l,(...p)=>{const f=c(...p)(i);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&r.dispatch(o),f}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,n=!0){const{rawCommands:s,editor:r,state:o}=this,{view:i}=r,l=[],c=!!e,u=e||o.tr,p=()=>(!c&&n&&!u.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(u),l.every(m=>m===!0)),f={...Object.fromEntries(Object.entries(s).map(([m,h])=>[m,(...b)=>{const y=this.buildProps(u,n),v=h(...b)(y);return l.push(v),f}])),run:p};return f}createCan(e){const{rawCommands:n,state:s}=this,r=!1,o=e||s.tr,i=this.buildProps(o,r);return{...Object.fromEntries(Object.entries(n).map(([c,u])=>[c,(...p)=>u(...p)({...i,dispatch:void 0})])),chain:()=>this.createChain(o,r)}}buildProps(e,n=!0){const{rawCommands:s,editor:r,state:o}=this,{view:i}=r,l={tr:e,editor:r,view:i,state:yl({state:o,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 Nt(t,e,n){return t.config[e]===void 0&&t.parent?Nt(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?Nt(t.parent,e,n):null}):t.config[e]}function Of(t){const e=t.filter(r=>r.type==="extension"),n=t.filter(r=>r.type==="node"),s=t.filter(r=>r.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 $f(t){return typeof t=="function"}function mn(t,e=void 0,...n){return $f(t)?e?t.bind(e)(...n):t(...n):t}function Ff(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function zf(t){return Object.prototype.toString.call(t).slice(8,-1)}function qn(t){return zf(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function vl(t,e){const n={...t};return qn(t)&&qn(e)&&Object.keys(e).forEach(s=>{qn(e[s])&&qn(t[s])?n[s]=vl(t[s],e[s]):n[s]=e[s]}),n}class Ue{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=mn(Nt(this,"addOptions",{name:this.name}))),this.storage=mn(Nt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new Ue(e)}configure(e={}){const n=this.extend({...this.config,addOptions:()=>vl(this.options,e)});return n.name=this.name,n.parent=this.parent,n}extend(e={}){const n=new Ue({...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=mn(Nt(n,"addOptions",{name:n.name})),n.storage=mn(Nt(n,"addStorage",{name:n.name,options:n.options})),n}}function Hf(t,e,n){const{from:s,to:r}=e,{blockSeparator:o=`
|
|
134
134
|
|
|
135
|
-
`,textSerializers:i={}}=n||{};let l="";return t.nodesBetween(s,r,(c,u,p,f)=>{var m;c.isBlock&&u>s&&(l+=o);const h=i==null?void 0:i[c.type.name];if(h)return p&&(l+=h({node:c,pos:u,parent:p,index:f,range:e})),!1;c.isText&&(l+=(m=c==null?void 0:c.text)===null||m===void 0?void 0:m.slice(Math.max(s,u)-u,r-u))}),l}function Vf(t){return Object.fromEntries(Object.entries(t.nodes).filter(([,e])=>e.spec.toText).map(([e,n])=>[e,n.spec.toText]))}Ue.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new Ht({key:new Vt("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:t}=this,{state:e,schema:n}=t,{doc:s,selection:r}=e,{ranges:o}=r,i=Math.min(...o.map(p=>p.$from.pos)),l=Math.max(...o.map(p=>p.$to.pos)),c=Vf(n);return Hf(s,{from:i,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:c})}}})]}});const Wf=()=>({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),Gf=(t=!1)=>({commands:e})=>e.setContent("",t),Uf=()=>({state:t,tr:e,dispatch:n})=>{const{selection:s}=e,{ranges:r}=s;return n&&r.forEach(({$from:o,$to:i})=>{t.doc.nodesBetween(o.pos,i.pos,(l,c)=>{if(l.type.isText)return;const{doc:u,mapping:p}=e,f=u.resolve(p.map(c)),m=u.resolve(p.map(c+l.nodeSize)),h=f.blockRange(m);if(!h)return;const x=on(h);if(l.type.isTextblock){const{defaultType:b}=f.parent.contentMatchAt(f.index());e.setNodeMarkup(h.start,b)}(x||x===0)&&e.lift(h,x)})}),!0},qf=t=>e=>t(e),Kf=()=>({state:t,dispatch:e})=>ml(t,e),Yf=(t,e)=>({editor:n,tr:s})=>{const{state:r}=n,o=r.doc.slice(t.from,t.to);s.deleteRange(t.from,t.to);const i=s.mapping.map(e);return s.insert(i,o.content),s.setSelection(new ae(s.doc.resolve(Math.max(i-1,0)))),!0},Xf=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,s=n.$anchor.node();if(s.content.size>0)return!1;const r=t.selection.$anchor;for(let o=r.depth;o>0;o-=1)if(r.node(o).type===s.type){if(e){const l=r.before(o),c=r.after(o);t.delete(l,c).scrollIntoView()}return!0}return!1},Jf=t=>({tr:e,state:n,dispatch:s})=>{const r=Ie(t,n.schema),o=e.selection.$anchor;for(let i=o.depth;i>0;i-=1)if(o.node(i).type===r){if(s){const c=o.before(i),u=o.after(i);e.delete(c,u).scrollIntoView()}return!0}return!1},Zf=t=>({tr:e,dispatch:n})=>{const{from:s,to:r}=t;return n&&e.delete(s,r),!0},Qf=()=>({state:t,dispatch:e})=>Qr(t,e),eh=()=>({commands:t})=>t.keyboardShortcut("Enter"),th=()=>({state:t,dispatch:e})=>wf(t,e);function ps(t,e,n={strict:!0}){const s=Object.keys(e);return s.length?s.every(r=>n.strict?e[r]===t[r]:Ff(e[r])?e[r].test(t[r]):e[r]===t[r]):!0}function kl(t,e,n={}){return t.find(s=>s.type===e&&ps(Object.fromEntries(Object.keys(n).map(r=>[r,s.attrs[r]])),n))}function pa(t,e,n={}){return!!kl(t,e,n)}function wl(t,e,n){var s;if(!t||!e)return;let r=t.parent.childAfter(t.parentOffset);if((!r.node||!r.node.marks.some(p=>p.type===e))&&(r=t.parent.childBefore(t.parentOffset)),!r.node||!r.node.marks.some(p=>p.type===e)||(n=n||((s=r.node.marks[0])===null||s===void 0?void 0:s.attrs),!kl([...r.node.marks],e,n)))return;let i=r.index,l=t.start()+r.offset,c=i+1,u=l+r.node.nodeSize;for(;i>0&&pa([...t.parent.child(i-1).marks],e,n);)i-=1,l-=t.parent.child(i).nodeSize;for(;c<t.parent.childCount&&pa([...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 nh=(t,e={})=>({tr:n,state:s,dispatch:r})=>{const o=yt(t,s.schema),{doc:i,selection:l}=n,{$from:c,from:u,to:p}=l;if(r){const f=wl(c,o,e);if(f&&f.from<=u&&f.to>=p){const m=ae.create(i,f.from,f.to);n.setSelection(m)}}return!0},sh=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 Cl(t){return t instanceof ae}function Et(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function rh(t,e=null){if(!e)return null;const n=Y.atStart(t),s=Y.atEnd(t);if(e==="start"||e===!0)return n;if(e==="end")return s;const r=n.from,o=s.to;return e==="all"?ae.create(t,Et(0,r,o),Et(t.content.size,r,o)):ae.create(t,Et(e,r,o),Et(e,r,o))}function oh(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function ro(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const ah=(t=null,e={})=>({editor:n,view:s,tr:r,dispatch:o})=>{e={scrollIntoView:!0,...e};const i=()=>{(ro()||oh())&&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(o&&t===null&&!Cl(n.state.selection))return i(),!0;const l=rh(r.doc,t)||n.state.selection,c=n.state.selection.eq(l);return o&&(c||r.setSelection(l),c&&r.storedMarks&&r.setStoredMarks(r.storedMarks),i()),!0},ih=(t,e)=>n=>t.every((s,r)=>e(s,{...n,index:r})),lh=(t,e)=>({tr:n,commands:s})=>s.insertContentAt({from:n.selection.from,to:n.selection.to},t,e),jl=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&&jl(s)}return t};function Kn(t){const e=`<body>${t}</body>`,n=new window.DOMParser().parseFromString(e,"text/html").body;return jl(n)}function Sn(t,e,n){if(t instanceof Bt||t instanceof M)return t;n={slice:!0,parseOptions:{},...n};const s=typeof t=="object"&&t!==null,r=typeof t=="string";if(s)try{if(Array.isArray(t)&&t.length>0)return M.fromArray(t.map(l=>e.nodeFromJSON(l)));const i=e.nodeFromJSON(t);return n.errorOnInvalidContent&&i.check(),i}catch(o){if(n.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:o});return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",o),Sn("",e,n)}if(r){if(n.errorOnInvalidContent){let i=!1,l="";const c=new Qp({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=>(i=!0,l=typeof u=="string"?u:u.outerHTML,null)}]}})});if(n.slice?Kt.fromSchema(c).parseSlice(Kn(t),n.parseOptions):Kt.fromSchema(c).parse(Kn(t),n.parseOptions),n.errorOnInvalidContent&&i)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const o=Kt.fromSchema(e);return n.slice?o.parseSlice(Kn(t),n.parseOptions).content:o.parse(Kn(t),n.parseOptions)}return Sn("",e,n)}function ch(t,e,n){const s=t.steps.length-1;if(s<e)return;const r=t.steps[s];if(!(r instanceof Fe||r instanceof Me))return;const o=t.mapping.maps[s];let i=0;o.forEach((l,c,u,p)=>{i===0&&(i=p)}),t.setSelection(Y.near(t.doc.resolve(i),n))}const dh=t=>!("type"in t),uh=(t,e,n)=>({tr:s,dispatch:r,editor:o})=>{var i;if(r){n={parseOptions:o.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let l;const c=y=>{o.emit("contentError",{editor:o,error:y,disableCollaboration:()=>{o.storage.collaboration&&(o.storage.collaboration.isDisabled=!0)}})},u={preserveWhitespace:"full",...n.parseOptions};if(!n.errorOnInvalidContent&&!o.options.enableContentCheck&&o.options.emitContentError)try{Sn(e,o.schema,{parseOptions:u,errorOnInvalidContent:!0})}catch(y){c(y)}try{l=Sn(e,o.schema,{parseOptions:u,errorOnInvalidContent:(i=n.errorOnInvalidContent)!==null&&i!==void 0?i:o.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},m=!0,h=!0;if((dh(l)?l:[l]).forEach(y=>{y.check(),m=m?y.isText&&y.marks.length===0:!1,h=h?y.isBlock:!1}),p===f&&h){const{parent:y}=s.doc.resolve(p);y.isTextblock&&!y.type.spec.code&&!y.childCount&&(p-=1,f+=1)}let b;if(m){if(Array.isArray(e))b=e.map(y=>y.text||"").join("");else if(e instanceof M){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&&ch(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},ph=()=>({state:t,dispatch:e})=>yf(t,e),fh=()=>({state:t,dispatch:e})=>vf(t,e),hh=()=>({state:t,dispatch:e})=>ll(t,e),mh=()=>({state:t,dispatch:e})=>pl(t,e),gh=()=>({state:t,dispatch:e,tr:n})=>{try{const s=Is(t.doc,t.selection.$from.pos,-1);return s==null?!1:(n.join(s,2),e&&e(n),!0)}catch{return!1}},xh=()=>({state:t,dispatch:e,tr:n})=>{try{const s=Is(t.doc,t.selection.$from.pos,1);return s==null?!1:(n.join(s,2),e&&e(n),!0)}catch{return!1}},bh=()=>({state:t,dispatch:e})=>xf(t,e),yh=()=>({state:t,dispatch:e})=>bf(t,e);function Sl(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function vh(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let s,r,o,i;for(let l=0;l<e.length-1;l+=1){const c=e[l];if(/^(cmd|meta|m)$/i.test(c))i=!0;else if(/^a(lt)?$/i.test(c))s=!0;else if(/^(c|ctrl|control)$/i.test(c))r=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))ro()||Sl()?i=!0:r=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return s&&(n=`Alt-${n}`),r&&(n=`Ctrl-${n}`),i&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const kh=t=>({editor:e,view:n,tr:s,dispatch:r})=>{const o=vh(t).split(/-(?!$)/),i=o.find(u=>!["Alt","Ctrl","Meta","Shift"].includes(u)),l=new KeyboardEvent("keydown",{key:i==="Space"?" ":i,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.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&&r&&s.maybeStep(p)}),!0};function oo(t,e,n={}){const{from:s,to:r,empty:o}=t.selection,i=e?Ie(e,t.schema):null,l=[];t.doc.nodesBetween(s,r,(f,m)=>{if(f.isText)return;const h=Math.max(s,m),x=Math.min(r,m+f.nodeSize);l.push({node:f,from:h,to:x})});const c=r-s,u=l.filter(f=>i?i.name===f.node.type.name:!0).filter(f=>ps(f.node.attrs,n,{strict:!1}));return o?!!u.length:u.reduce((f,m)=>f+m.to-m.from,0)>=c}const wh=(t,e={})=>({state:n,dispatch:s})=>{const r=Ie(t,n.schema);return oo(n,r,e)?kf(n,s):!1},Ch=()=>({state:t,dispatch:e})=>gl(t,e),jh=t=>({state:e,dispatch:n})=>{const s=Ie(t,e.schema);return Rf(s)(e,n)},Sh=()=>({state:t,dispatch:e})=>hl(t,e);function Nl(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function fa(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((s,r)=>(n.includes(r)||(s[r]=t[r]),s),{})}const Nh=(t,e)=>({tr:n,state:s,dispatch:r})=>{let o=null,i=null;const l=Nl(typeof t=="string"?t:t.name,s.schema);return l?(l==="node"&&(o=Ie(t,s.schema)),l==="mark"&&(i=yt(t,s.schema)),r&&n.selection.ranges.forEach(c=>{s.doc.nodesBetween(c.$from.pos,c.$to.pos,(u,p)=>{o&&o===u.type&&n.setNodeMarkup(p,void 0,fa(u.attrs,e)),i&&u.marks.length&&u.marks.forEach(f=>{i===f.type&&n.addMark(p,p+u.nodeSize,i.create(fa(f.attrs,e)))})})}),!0):!1},Eh=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),Ah=()=>({tr:t,dispatch:e})=>{if(e){const n=new We(t.doc);t.setSelection(n)}return!0},Ih=()=>({state:t,dispatch:e})=>dl(t,e),Th=()=>({state:t,dispatch:e})=>fl(t,e),_h=()=>({state:t,dispatch:e})=>Sf(t,e),Bh=()=>({state:t,dispatch:e})=>Af(t,e),Rh=()=>({state:t,dispatch:e})=>Ef(t,e);function Ph(t,e,n={},s={}){return Sn(t,e,{slice:!1,parseOptions:n,errorOnInvalidContent:s.errorOnInvalidContent})}const Lh=(t,e=!1,n={},s={})=>({editor:r,tr:o,dispatch:i,commands:l})=>{var c,u;const{doc:p}=o;if(n.preserveWhitespace!=="full"){const f=Ph(t,r.schema,n,{errorOnInvalidContent:(c=s.errorOnInvalidContent)!==null&&c!==void 0?c:r.options.enableContentCheck});return i&&o.replaceWith(0,p.content.size,f).setMeta("preventUpdate",!e),!0}return i&&o.setMeta("preventUpdate",!e),l.insertContentAt({from:0,to:p.content.size},t,{parseOptions:n,errorOnInvalidContent:(u=s.errorOnInvalidContent)!==null&&u!==void 0?u:r.options.enableContentCheck})};function Mh(t,e){const n=yt(e,t.schema),{from:s,to:r,empty:o}=t.selection,i=[];o?(t.storedMarks&&i.push(...t.storedMarks),i.push(...t.selection.$head.marks())):t.doc.nodesBetween(s,r,c=>{i.push(...c.marks)});const l=i.find(c=>c.type.name===n.name);return l?{...l.attrs}:{}}function Dh(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 Oh(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 ao(t){return e=>Oh(e.$from,t)}function Zn(t,e,n){return Object.fromEntries(Object.entries(n).filter(([s])=>{const r=t.find(o=>o.type===e&&o.name===s);return r?r.attribute.keepOnSplit:!1}))}function $h(t,e,n={}){const{empty:s,ranges:r}=t.selection,o=e?yt(e,t.schema):null;if(s)return!!(t.storedMarks||t.selection.$from.marks()).filter(f=>o?o.name===f.type.name:!0).find(f=>ps(f.attrs,n,{strict:!1}));let i=0;const l=[];if(r.forEach(({$from:f,$to:m})=>{const h=f.pos,x=m.pos;t.doc.nodesBetween(h,x,(b,y)=>{if(!b.isText&&!b.marks.length)return;const k=Math.max(h,y),w=Math.min(x,y+b.nodeSize),E=w-k;i+=E,l.push(...b.marks.map(A=>({mark:A,from:k,to:w})))})}),i===0)return!1;const c=l.filter(f=>o?o.name===f.mark.type.name:!0).filter(f=>ps(f.mark.attrs,n,{strict:!1})).reduce((f,m)=>f+m.to-m.from,0),u=l.filter(f=>o?f.mark.type!==o&&f.mark.type.excludes(o):!0).reduce((f,m)=>f+m.to-m.from,0);return(c>0?c+u:c)>=i}function ha(t,e){const{nodeExtensions:n}=Of(e),s=n.find(i=>i.name===t);if(!s)return!1;const r={name:s.name,options:s.options,storage:s.storage},o=mn(Nt(s,"group",r));return typeof o!="string"?!1:o.split(" ").includes("list")}function El(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 r=!0;return t.content.forEach(o=>{r!==!1&&(El(o,{ignoreWhitespace:n,checkChildren:e})||(r=!1))}),r}return!1}function Fh(t,e,n){var s;const{selection:r}=e;let o=null;if(Cl(r)&&(o=r.$cursor),o){const l=(s=t.storedMarks)!==null&&s!==void 0?s:o.marks();return!!n.isInSet(l)||!l.some(c=>c.type.excludes(n))}const{ranges:i}=r;return i.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,m)=>{if(u)return!1;if(p.isInline){const h=!m||m.type.allowsMarkType(n),x=!!n.isInSet(p.marks)||!p.marks.some(b=>b.type.excludes(n));u=h&&x}return!u}),u})}const zh=(t,e={})=>({tr:n,state:s,dispatch:r})=>{const{selection:o}=n,{empty:i,ranges:l}=o,c=yt(t,s.schema);if(r)if(i){const u=Mh(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,(m,h)=>{const x=Math.max(h,p),b=Math.min(h+m.nodeSize,f);m.marks.find(k=>k.type===c)?m.marks.forEach(k=>{c===k.type&&n.addMark(x,b,c.create({...k.attrs,...e}))}):n.addMark(x,b,c.create(e))})});return Fh(s,n,c)},Hh=(t,e)=>({tr:n})=>(n.setMeta(t,e),!0),Vh=(t,e={})=>({state:n,dispatch:s,chain:r})=>{const o=Ie(t,n.schema);let i;return n.selection.$anchor.sameParent(n.selection.$head)&&(i=n.selection.$anchor.parent.attrs),o.isTextblock?r().command(({commands:l})=>ua(o,{...i,...e})(n)?!0:l.clearNodes()).command(({state:l})=>ua(o,{...i,...e})(l,s)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Wh=t=>({tr:e,dispatch:n})=>{if(n){const{doc:s}=e,r=Et(t,0,s.content.size),o=ee.create(s,r);e.setSelection(o)}return!0},Gh=t=>({tr:e,dispatch:n})=>{if(n){const{doc:s}=e,{from:r,to:o}=typeof t=="number"?{from:t,to:t}:t,i=ae.atStart(s).from,l=ae.atEnd(s).to,c=Et(r,i,l),u=Et(o,i,l),p=ae.create(s,c,u);e.setSelection(p)}return!0},Uh=t=>({state:e,dispatch:n})=>{const s=Ie(t,e.schema);return Mf(s)(e,n)};function ma(t,e){const n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();if(n){const s=n.filter(r=>e==null?void 0:e.includes(r.type.name));t.tr.ensureMarks(s)}}const qh=({keepMarks:t=!0}={})=>({tr:e,state:n,dispatch:s,editor:r})=>{const{selection:o,doc:i}=e,{$from:l,$to:c}=o,u=r.extensionManager.attributes,p=Zn(u,l.node().type.name,l.node().attrs);if(o instanceof ee&&o.node.isBlock)return!l.parentOffset||!dt(i,l.pos)?!1:(s&&(t&&ma(n,r.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const f=c.parentOffset===c.parent.content.size,m=l.depth===0?void 0:Dh(l.node(-1).contentMatchAt(l.indexAfter(-1)));let h=f&&m?[{type:m,attrs:p}]:void 0,x=dt(e.doc,e.mapping.map(l.pos),1,h);if(!h&&!x&&dt(e.doc,e.mapping.map(l.pos),1,m?[{type:m}]:void 0)&&(x=!0,h=m?[{type:m,attrs:p}]:void 0),s){if(x&&(o instanceof ae&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,h),m&&!f&&!l.parentOffset&&l.parent.type!==m)){const b=e.mapping.map(l.before()),y=e.doc.resolve(b);l.node(-1).canReplaceWith(y.index(),y.index()+1,m)&&e.setNodeMarkup(e.mapping.map(l.before()),m)}t&&ma(n,r.extensionManager.splittableMarks),e.scrollIntoView()}return x},Kh=(t,e={})=>({tr:n,state:s,dispatch:r,editor:o})=>{var i;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 m=o.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(r){let k=M.empty;const w=c.index(-1)?1:c.index(-2)?2:3;for(let S=c.depth-w;S>=c.depth-3;S-=1)k=M.from(c.node(S).copy(k));const E=c.indexAfter(-1)<c.node(-2).childCount?1:c.indexAfter(-2)<c.node(-3).childCount?2:3,A={...Zn(m,c.node().type.name,c.node().attrs),...e},I=((i=l.contentMatch.defaultType)===null||i===void 0?void 0:i.createAndFill(A))||void 0;k=k.append(M.from(l.createAndFill(null,I)||void 0));const T=c.before(c.depth-(w-1));n.replace(T,c.after(-E),new V(k,4-w,0));let N=-1;n.doc.nodesBetween(T,n.doc.content.size,(S,C)=>{if(N>-1)return!1;S.isTextblock&&S.content.size===0&&(N=C+1)}),N>-1&&n.setSelection(ae.near(n.doc.resolve(N))),n.scrollIntoView()}return!0}const h=u.pos===c.end()?f.contentMatchAt(0).defaultType:null,x={...Zn(m,f.type.name,f.attrs),...e},b={...Zn(m,c.node().type.name,c.node().attrs),...e};n.delete(c.pos,u.pos);const y=h?[{type:l,attrs:x},{type:h,attrs:b}]:[{type:l,attrs:x}];if(!dt(n.doc,c.pos,2))return!1;if(r){const{selection:k,storedMarks:w}=s,{splittableMarks:E}=o.extensionManager,A=w||k.$to.parentOffset&&k.$from.marks();if(n.split(c.pos,2,y).scrollIntoView(),!A||!r)return!0;const I=A.filter(T=>E.includes(T.type.name));n.ensureMarks(I)}return!0},Zs=(t,e)=>{const n=ao(i=>i.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 r=t.doc.nodeAt(s);return n.node.type===(r==null?void 0:r.type)&&zt(t.doc,n.pos)&&t.join(n.pos),!0},Qs=(t,e)=>{const n=ao(i=>i.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 r=t.doc.nodeAt(s);return n.node.type===(r==null?void 0:r.type)&&zt(t.doc,s)&&t.join(s),!0},Yh=(t,e,n,s={})=>({editor:r,tr:o,state:i,dispatch:l,chain:c,commands:u,can:p})=>{const{extensions:f,splittableMarks:m}=r.extensionManager,h=Ie(t,i.schema),x=Ie(e,i.schema),{selection:b,storedMarks:y}=i,{$from:k,$to:w}=b,E=k.blockRange(w),A=y||b.$to.parentOffset&&b.$from.marks();if(!E)return!1;const I=ao(T=>ha(T.type.name,f))(b);if(E.depth>=1&&I&&E.depth-I.depth<=1){if(I.node.type===h)return u.liftListItem(x);if(ha(I.node.type.name,f)&&h.validContent(I.node.content)&&l)return c().command(()=>(o.setNodeMarkup(I.pos,h),!0)).command(()=>Zs(o,h)).command(()=>Qs(o,h)).run()}return!n||!A||!l?c().command(()=>p().wrapInList(h,s)?!0:u.clearNodes()).wrapInList(h,s).command(()=>Zs(o,h)).command(()=>Qs(o,h)).run():c().command(()=>{const T=p().wrapInList(h,s),N=A.filter(S=>m.includes(S.type.name));return o.ensureMarks(N),T?!0:u.clearNodes()}).wrapInList(h,s).command(()=>Zs(o,h)).command(()=>Qs(o,h)).run()},Xh=(t,e={},n={})=>({state:s,commands:r})=>{const{extendEmptyMarkRange:o=!1}=n,i=yt(t,s.schema);return $h(s,i,e)?r.unsetMark(i,{extendEmptyMarkRange:o}):r.setMark(i,e)},Jh=(t,e,n={})=>({state:s,commands:r})=>{const o=Ie(t,s.schema),i=Ie(e,s.schema),l=oo(s,o,n);let c;return s.selection.$anchor.sameParent(s.selection.$head)&&(c=s.selection.$anchor.parent.attrs),l?r.setNode(i,c):r.setNode(o,{...c,...n})},Zh=(t,e={})=>({state:n,commands:s})=>{const r=Ie(t,n.schema);return oo(n,r,e)?s.lift(r):s.wrapIn(r,e)},Qh=()=>({state:t,dispatch:e})=>{const n=t.plugins;for(let s=0;s<n.length;s+=1){const r=n[s];let o;if(r.spec.isInputRules&&(o=r.getState(t))){if(e){const i=t.tr,l=o.transform;for(let c=l.steps.length-1;c>=0;c-=1)i.step(l.steps[c].invert(l.docs[c]));if(o.text){const c=i.doc.resolve(o.from).marks();i.replaceWith(o.from,o.to,t.schema.text(o.text,c))}else i.delete(o.from,o.to)}return!0}}return!1},em=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,{empty:s,ranges:r}=n;return s||e&&r.forEach(o=>{t.removeMark(o.$from.pos,o.$to.pos)}),!0},tm=(t,e={})=>({tr:n,state:s,dispatch:r})=>{var o;const{extendEmptyMarkRange:i=!1}=e,{selection:l}=n,c=yt(t,s.schema),{$from:u,empty:p,ranges:f}=l;if(!r)return!0;if(p&&i){let{from:m,to:h}=l;const x=(o=u.marks().find(y=>y.type===c))===null||o===void 0?void 0:o.attrs,b=wl(u,c,x);b&&(m=b.from,h=b.to),n.removeMark(m,h,c)}else f.forEach(m=>{n.removeMark(m.$from.pos,m.$to.pos,c)});return n.removeStoredMark(c),!0},nm=(t,e={})=>({tr:n,state:s,dispatch:r})=>{let o=null,i=null;const l=Nl(typeof t=="string"?t:t.name,s.schema);return l?(l==="node"&&(o=Ie(t,s.schema)),l==="mark"&&(i=yt(t,s.schema)),r&&n.selection.ranges.forEach(c=>{const u=c.$from.pos,p=c.$to.pos;let f,m,h,x;n.selection.empty?s.doc.nodesBetween(u,p,(b,y)=>{o&&o===b.type&&(h=Math.max(y,u),x=Math.min(y+b.nodeSize,p),f=y,m=b)}):s.doc.nodesBetween(u,p,(b,y)=>{y<u&&o&&o===b.type&&(h=Math.max(y,u),x=Math.min(y+b.nodeSize,p),f=y,m=b),y>=u&&y<=p&&(o&&o===b.type&&n.setNodeMarkup(y,void 0,{...b.attrs,...e}),i&&b.marks.length&&b.marks.forEach(k=>{if(i===k.type){const w=Math.max(y,u),E=Math.min(y+b.nodeSize,p);n.addMark(w,E,i.create({...k.attrs,...e}))}}))}),m&&(f!==void 0&&n.setNodeMarkup(f,void 0,{...m.attrs,...e}),i&&m.marks.length&&m.marks.forEach(b=>{i===b.type&&n.addMark(h,x,i.create({...b.attrs,...e}))}))}),!0):!1},sm=(t,e={})=>({state:n,dispatch:s})=>{const r=Ie(t,n.schema);return If(r,e)(n,s)},rm=(t,e={})=>({state:n,dispatch:s})=>{const r=Ie(t,n.schema);return Tf(r,e)(n,s)};var om=Object.freeze({__proto__:null,blur:Wf,clearContent:Gf,clearNodes:Uf,command:qf,createParagraphNear:Kf,cut:Yf,deleteCurrentNode:Xf,deleteNode:Jf,deleteRange:Zf,deleteSelection:Qf,enter:eh,exitCode:th,extendMarkRange:nh,first:sh,focus:ah,forEach:ih,insertContent:lh,insertContentAt:uh,joinBackward:hh,joinDown:fh,joinForward:mh,joinItemBackward:gh,joinItemForward:xh,joinTextblockBackward:bh,joinTextblockForward:yh,joinUp:ph,keyboardShortcut:kh,lift:wh,liftEmptyBlock:Ch,liftListItem:jh,newlineInCode:Sh,resetAttributes:Nh,scrollIntoView:Eh,selectAll:Ah,selectNodeBackward:Ih,selectNodeForward:Th,selectParentNode:_h,selectTextblockEnd:Bh,selectTextblockStart:Rh,setContent:Lh,setMark:zh,setMeta:Hh,setNode:Vh,setNodeSelection:Wh,setTextSelection:Gh,sinkListItem:Uh,splitBlock:qh,splitListItem:Kh,toggleList:Yh,toggleMark:Xh,toggleNode:Jh,toggleWrap:Zh,undoInputRule:Qh,unsetAllMarks:em,unsetMark:tm,updateAttributes:nm,wrapIn:sm,wrapInList:rm});Ue.create({name:"commands",addCommands(){return{...om}}});Ue.create({name:"drop",addProseMirrorPlugins(){return[new Ht({key:new Vt("tiptapDrop"),props:{handleDrop:(t,e,n,s)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:n,moved:s})}}})]}});Ue.create({name:"editable",addProseMirrorPlugins(){return[new Ht({key:new Vt("editable"),props:{editable:()=>this.editor.options.editable}})]}});const am=new Vt("focusEvents");Ue.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:t}=this;return[new Ht({key:am,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}}}})]}});Ue.create({name:"keymap",addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({commands:i})=>[()=>i.undoInputRule(),()=>i.command(({tr:l})=>{const{selection:c,doc:u}=l,{empty:p,$anchor:f}=c,{pos:m,parent:h}=f,x=f.parent.isTextblock&&m>0?l.doc.resolve(m-1):f,b=x.parent.type.spec.isolating,y=f.pos-f.parentOffset,k=b&&x.parent.childCount===1?y===f.pos:Y.atStart(u).from===m;return!p||!h.type.isTextblock||h.textContent.length||!k||k&&f.parent.type.name==="paragraph"?!1:i.clearNodes()}),()=>i.deleteSelection(),()=>i.joinBackward(),()=>i.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:i})=>[()=>i.deleteSelection(),()=>i.deleteCurrentNode(),()=>i.joinForward(),()=>i.selectNodeForward()]),s={Enter:()=>this.editor.commands.first(({commands:i})=>[()=>i.newlineInCode(),()=>i.createParagraphNear(),()=>i.liftEmptyBlock(),()=>i.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()},r={...s},o={...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 ro()||Sl()?o:r},addProseMirrorPlugins(){return[new Ht({key:new Vt("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),r=t.some(b=>b.getMeta("preventClearDocument"));if(!s||r)return;const{empty:o,from:i,to:l}=e.selection,c=Y.atStart(e.doc).from,u=Y.atEnd(e.doc).to;if(o||!(i===c&&l===u)||!El(n.doc))return;const m=n.tr,h=yl({state:n,transaction:m}),{commands:x}=new Df({editor:this.editor,state:h});if(x.clearNodes(),!!m.steps.length)return m}})]}});Ue.create({name:"paste",addProseMirrorPlugins(){return[new Ht({key:new Vt("tiptapPaste"),props:{handlePaste:(t,e,n)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:n})}}})]}});Ue.create({name:"tabindex",addProseMirrorPlugins(){return[new Ht({key:new Vt("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});const im=Ue.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()}}}),Al=({blockId:t,value:e="",onUpdate:n=()=>{},onBlur:s=()=>{},placeholder:r="",from:o="settings",style:i={}})=>ns.useEditor({extensions:[Xc,Wc,im.configure({types:["textStyle"]}),Gc.configure({multicolor:!0}),Uc.configure({openOnClick:!1,HTMLAttributes:{class:"underline"}}),Kc.configure({types:["heading","paragraph"],alignments:["left","center","right"],defaultAlignment:"left"}),Yc,qc.configure({placeholder:r||"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:{...i?{style:i}:{},class:o!=="canvas"?"text-sm p-1 px-2 rte":"rte"}}},[t]);function lm(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 cm=g.memo(({blockContent:t,editingElement:e,onClose:n,onChange:s,onEscape:r})=>{const{document:o}=rt(),i=Al({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(!o)return;const f=p==null?void 0:p.relatedTarget,m=o.querySelector(".ProseMirror"),h=o.querySelector(".tippy-box"),x=o.querySelector("#chai-rich-text-menu-bar"),b=m==null?void 0:m.contains(f),y=h==null?void 0:h.contains(f),k=x==null?void 0:x.contains(f),w=window.document.getElementById("rte-widget-color-picker");if(!b&&!y&&!k&&!w){const E=(u==null?void 0:u.getHTML())||"";n(E)}},from:"canvas"});g.useEffect(()=>{var p,f;const u=lm(e);u&&((p=i==null?void 0:i.commands)==null||p.setTextAlign(u)),(f=i==null?void 0:i.commands)==null||f.focus(),i==null||i.emit("focus",{editor:i,event:new FocusEvent("focus"),transaction:[]})},[e,i]);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"&&r(u)};return i&&a.jsxs("div",{onKeyDown:c,onClick:u=>u.stopPropagation(),className:"relative",children:[a.jsx(ns.BubbleMenu,{editor:i,shouldShow:()=>i&&(i==null?void 0:i.isFocused),tippyOptions:{duration:100,arrow:!0,hideOnClick:!1},className:"w-max",children:a.jsx(Pi,{editor:i,from:"canvas"})}),a.jsx(ns.EditorContent,{id:"active-inline-editing-element",onKeyDown:c,value:t,editor:i,className:l})]})}),dm=g.memo(({editingElement:t,blockContent:e,onClose:n,editorRef:s,onChange:r,onEscape:o})=>{const{document:i,window:l}=rt();g.useEffect(()=>{if(!(!i||!l))if(s.current){s.current.innerHTML=e,s.current.focus();const m=i.createRange(),h=l.getSelection();m.selectNodeContents(s.current),m.collapse(!1),h==null||h.removeAllRanges(),h==null||h.addRange(m),s.current.focus()}else n()},[e,i,s,n,l]);const c=g.useMemo(()=>{var h;const m=((h=t==null?void 0:t.tagName)==null?void 0:h.toLowerCase())||"div";return m==="button"?"div":m},[t]),u=g.useCallback(m=>{(m.key==="Enter"||m.key==="Escape")&&o(m)},[o]),p=g.useCallback(()=>{n()},[n]),f=g.useMemo(()=>{var m;return{id:"active-inline-editing-element",contentEditable:!0,className:`${((m=t==null?void 0:t.className)==null?void 0:m.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:h=>{const x=h.target;x&&(x.innerText.trim()===""?(x.setAttribute("data-placeholder","Enter text here"),x.children.length>0&&x.children[0].remove()):h.target.removeAttribute("data-placeholder"),r(h.target.innerText))},onClick:h=>{h.stopPropagation(),h.preventDefault()}}},[t==null?void 0:t.className,t==null?void 0:t.style,r]);return a.jsx(a.Fragment,{children:g.createElement(c,{ref:s,onBlur:p,onKeyDown:u,...f})})}),um=g.memo(({block:t,children:e})=>{const n="content",{document:s}=rt(),{editingBlockId:r,editingItemIndex:o,setEditingBlockId:i,setEditingItemIndex:l}=Ft(),[c,u]=g.useState(null),p=g.useRef(null),{clearHighlight:f}=st(),m=nt(),{selectedLang:h}=Te(),[,x]=U(),b=g.useRef(null),y=r,{blockContent:k,blockType:w}=g.useMemo(()=>{var P;const N=t._type;let S=t[n];const C=X.getRegisteredChaiBlock(t._type);return h&&((P=C==null?void 0:C.i18nProps)==null?void 0:P.includes(n))&&d.has(t,`${n}-${h}`)&&(S=d.get(t,`${n}-${h}`)),{blockContent:S,blockType:N}},[t,h]),E=g.useCallback(N=>{var C;const S=N||((C=p.current)==null?void 0:C.innerText);m([y],{[n]:S}),u(null),i(""),l(-1),x([]),y&&setTimeout(()=>x([y]),100)},[m,y,i,l,x]),A=ke.useDebouncedCallback(N=>{m([y],{[n]:N})},[y,t,m,h],1e3),I=g.useCallback(N=>{N.preventDefault(),y&&(b.current=y),E(),setTimeout(()=>{const S=b.current;b.current=null,S&&x([S])},100)},[y,E,x]);g.useEffect(()=>{var B;if(!y||!s)return;const N=`[data-block-id="${y}"]`,S=o>=0?`[data-block-index="${o}"]`:"",C=s.querySelector(`${N}${S}`);C&&((B=C==null?void 0:C.classList)==null||B.add("sr-only"),g.startTransition(()=>u(C)))},[y,w,s,o]);const T=g.useMemo(()=>c?(f(),["RichText","Paragraph"].includes(w)?a.jsx(cm,{blockContent:k,editingElement:c,onChange:A,onClose:E,onEscape:I}):a.jsx(dm,{editorRef:p,blockContent:k,editingElement:c,onClose:E,onChange:A,onEscape:I})):null,[c,f,w,k,E,A,I]);return a.jsxs(a.Fragment,{children:[T,e]})},(t,e)=>t.block._id===e.block._id&&t.block.content===e.block.content),Il=g.createContext({index:-1,key:""}),pm=["Box","Repeater","GlobalBlock","PartialBlock","Heading","Text","RichText","Span","Image","Button","Paragraph","Link","Video","Audio","Icon","List","ListItem","CustomScript","CustomHTML"],fm=({asyncProps:t,blockAtom:e,children:n})=>{const{editingBlockId:s,editingItemIndex:r}=Ft(),[o]=j.useAtom(e),i=g.useMemo(()=>X.getRegisteredChaiBlock(o._type),[o._type]),{selectedLang:l,fallbackLang:c}=Te(),u=Ip(),p=tn(),[f]=j.useAtom(Vr),m=d.get(i,"component",null),{index:h,key:x}=g.useContext(Il),{mode:b}=Ri(),y=j.useAtomValue(en),k=Ye(),w=b==="edit",E=Ap(),A=g.useMemo(()=>f?be.applyBindingToBlockProps(be.applyLanguage(o,l,i),p,{index:h,key:x}):be.applyLanguage(o,l,i),[o,l,i,p,f,h,x]),I=g.useMemo(()=>be.getBlockTagAttributes(o,!0,y),[o,be.getBlockTagAttributes,y]),T=g.useMemo(()=>u(o._id,be.getBlockRuntimeProps(o._type)),[o._id,o._type,u,be.getBlockRuntimeProps]),N=g.useMemo(()=>{const O={"data-block-id":o._id,"data-block-type":o._type,"data-block-index":h};return w&&k?{...O,draggable:!s,onMouseDown:E.onMouseDown,onDragStart:E.onDragStart,onDragEnd:E.onDragEnd}:O},[o._id,o._type,h,w,k,E,s]),S=g.useMemo(()=>({blockProps:N,inBuilder:b==="edit",lang:l||c,pageData:p,...A,...I,...T,...t}),[b,N,l,c,A,I,T,t]),C=g.useMemo(()=>!pm.includes(o._type),[o._type]),B=g.useMemo(()=>d.get(o,"_show",!0),[o]);if(d.isNull(m)||!B)return null;let P=a.jsx(g.Suspense,{children:g.createElement(m,{...S,children:n({_id:o._id,_type:o._type,...d.isArray(A.repeaterItems)?{repeaterItems:be.applyLimit(A.repeaterItems,o),$repeaterItemsKey:A.$repeaterItemsKey}:{},...o.partialBlockId?{partialBlockId:o.partialBlockId}:"",...o.globalBlock?{partialBlockId:o.globalBlock}:""})})});const R=s===o._id&&(r===h||h<0)?a.jsx(um,{block:o,children:P}):P;return C?a.jsx(At.ErrorBoundary,{fallbackRender:Bp,children:R}):R},hm=({children:t,partialBlockId:e})=>{const n=$("gotoPage",d.noop),{saveState:s}=nn(),{selectedLang:r,fallbackLang:o}=Te(),i=g.useCallback(l=>{if(l.stopPropagation(),s!=="SAVED"){pe.toast.error("You have unsaved changes. Please save the page first.");return}n({pageId:e,lang:r||o})},[s,n,e,r,o]);return a.jsxs(a.Fragment,{children:[t,a.jsx("div",{className:"partial-overlay group absolute inset-0 z-50",children:a.jsx("div",{onDoubleClick:i,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:a.jsx("p",{className:"rounded-md bg-white px-2 py-1 text-xs",children:"Partial block. Double click to edit."})})})]})},mm=({partialBlockId:t})=>{const{getPartailBlocks:e}=As(),n=g.useMemo(()=>e(t),[e,t]),s=g.useMemo(()=>Se.splitAtom(j.atom(n)),[n]);return d.isEmpty(n)?null:a.jsx(hm,{partialBlockId:t,children:a.jsx(fs,{splitAtoms:s,blocks:n,type:"PartialBlock"})})},fs=({blocks:t,parent:e=null,splitAtoms:n=void 0,type:s=""})=>{const r=uu(n);let o=g.useMemo(()=>d.filter(t,l=>d.has(l,"_id")&&(d.isEmpty(e)?!l._parent:l._parent===e)),[t,e]);const i=g.useCallback(l=>d.filter(t,c=>c._parent===l).length>0,[t]);return(s==="Heading"||s==="Paragraph"||s==="Link")&&(o=be.adjustSpacingInContentBlocks(o)),d.map(o,l=>{const c=r(l._id);return c?a.jsx(_p,{block:l,children:u=>a.jsx(fm,{blockAtom:c,asyncProps:u,children:({_id:p,_type:f,partialBlockId:m,repeaterItems:h,$repeaterItemsKey:x})=>f==="Repeater"?d.isArray(h)&&h.map((b,y)=>a.jsx(Il.Provider,{value:{index:y,key:x},children:a.jsx(fs,{splitAtoms:n,blocks:t,parent:l._id,type:f})},`${p}-${y}`)):f==="GlobalBlock"||f==="PartialBlock"?a.jsx(j.Provider,{store:Ve,children:a.jsx(mm,{partialBlockId:m})}):i(p)?a.jsx(fs,{splitAtoms:n,blocks:t,parent:l._id,type:f}):null})},l._id):null})},gm=()=>{const[t]=te();return a.jsx(fs,{splitAtoms:En,blocks:t})},xm=()=>{const[t]=te(),[e]=j.useAtom(Fr),n=d.isEmpty(t)?null:a.jsx(gm,{},e);return a.jsx(a.Fragment,{children:n})},bm=Se.atomWithStorage("canvasZoom",100),Tl=()=>j.useAtom(bm),ym=()=>j.useAtom(Ja),_l=Se.atomWithStorage("canvasWidth",800),vm=Se.atomWithStorage("canvasDisplayWidth",800),Bl=j.atom(t=>{const e=t(_l);return ve.getBreakpointValue(e).toLowerCase()}),hs=()=>{const[t,e]=j.useAtom(_l),n=j.useAtomValue(Bl),[s,r]=ym();return g.useEffect(()=>{s!=="xs"&&r(n)},[n,s,r]),[t,n,e]},io=()=>{const[t,e]=j.useAtom(vm);return[t,e]},km=t=>{const[e]=io(),[,n]=Tl(),s=$("htmlDir","ltr"),[r,o]=g.useState({}),i=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,m=l*u;c&&(p={height:100+(c-f)/f*100+"%",width:100+(l-m)/m*100+"%"}),o({position:"relative",top:0,transform:`scale(${u})`,transformOrigin:s==="rtl"?"top right":"top left",...p,maxWidth:"none"}),n(u*100)}else o({}),n(100)},[e,t,s,n]);return g.useEffect(()=>{i()},[e,t,n,i]),r};function Yt(t,e){g.useEffect(()=>{const n=oe.subscribe(t,e);return()=>n()},[t,e])}const wm=()=>{const[,t]=U(),[e,n]=Ee(),{document:s}=rt(),{clearHighlight:r}=st(),[o]=U(),[i]=j.useAtom(zr);return g.useEffect(()=>{setTimeout(()=>{if(!d.isEmpty(e))return;const l=Ci(s,d.first(o));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,o,n,e]),g.useEffect(()=>()=>r(),[r]),Yt(K.CANVAS_BLOCK_SELECTED,l=>{l&&(!d.isEmpty(l)&&!d.includes(o,d.first(l))&&(i==null||i.closeAll()),t(l))}),Yt(K.CANVAS_BLOCK_STYLE_SELECTED,l=>{if(!l)return;const{blockId:c,styleId:u,styleProp:p}=l;c&&(d.includes(o,c)||i==null||i.closeAll(),n([{id:u,prop:p,blockId:c}]),t([c]))}),Yt(K.CLEAR_CANVAS_SELECTION,()=>{r(),t([]),n([])}),null},Cm=()=>{const[t]=io(),[,e]=xi(),n=g.useRef(null),s=g.useRef(null),[r,o]=g.useState({width:0,height:0}),i=km(r),[,l]=sn(),c=$("loading",!1),u=$("htmlDir","ltr"),{onDragOver:p,onDrop:f,onDragEnd:m}=rn(),h=qu(),x=g.useCallback(y=>{o(k=>({...k,width:y}))},[o]);g.useEffect(()=>{if(!s.current)return;const{clientWidth:y,clientHeight:k}=s.current;o({width:y,height:k})},[s,t]);const b=g.useMemo(()=>{let y=fp;return y=y.replace("__HTML_DIR__",u),y},[u]);return a.jsx(Ep,{onMount:x,onResize:x,children:a.jsx("div",{onMouseLeave:()=>setTimeout(()=>e(""),300),className:"relative mx-auto h-full w-full overflow-hidden",onDragOver:p,onDrop:f,onDragEnd:m,ref:s,children:a.jsxs(mp,{contentDidMount:()=>l(n.current),ref:n,id:"canvas-iframe",style:{...i,...d.isEmpty(i)?{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:[a.jsx(kp,{}),a.jsx(up,{}),a.jsx(Cp,{}),a.jsxs(xd.Provider,{children:[a.jsxs(cp,{children:[c?a.jsx("div",{className:"h-full p-4",children:a.jsx(Lt,{className:"h-full"})}):a.jsx(xm,{}),a.jsx(wp,{})]}),a.jsx(wm,{})]}),h.isVisible&&a.jsx("div",{id:"placeholder",className:`pointer-events-none absolute z-[99999] max-w-full transition-all duration-150 ${h.isEmpty?"bg-purple-500/10 outline-dashed outline-2 -outline-offset-2 outline-purple-500":"rounded-full bg-green-500"}`,style:{top:h.top,left:h.left,width:h.width,height:h.height}})]})})})},yn=()=>{const{t}=F.useTranslation();return a.jsx("div",{className:"h-full w-full rounded-md bg-red-200 p-4 text-red-500",children:a.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center",children:[a.jsx("p",{className:"font-semibold",children:t("Oops! Something went wrong.")}),a.jsx("p",{children:t("Please try again.")})]})})},jm=j.atom(null),lo=()=>j.useAtom(jm),Sm=g.lazy(()=>Promise.resolve().then(()=>require("./code-editor-CIqswl5j.cjs"))),Rl=()=>{const[t]=lo(),e=$("onError",d.noop);return a.jsx("div",{className:"flex h-full max-h-full w-full flex-1 flex-col",children:a.jsxs("div",{className:"relative flex h-full max-h-full flex-col overflow-hidden bg-gray-100/40",children:[a.jsx(g.Suspense,{fallback:a.jsx(Lt,{className:"h-full"}),children:a.jsx(At.ErrorBoundary,{fallback:a.jsx(yn,{}),onError:e,children:a.jsx(Cm,{})})}),t?a.jsx(g.Suspense,{fallback:a.jsx(Lt,{className:"h-full"}),children:a.jsx(Sm,{})}):null]})})},Ot={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"},Nm=({id:t,placeholder:e})=>{const{t:n}=F.useTranslation(),[,s]=lo(),{selectedLang:r}=Te(),o=J(),i=t.replace("root.",""),l=X.getRegisteredChaiBlock(o==null?void 0:o._type),u=d.includes(d.get(l,"i18nProps",[]),i)&&r?`${i}-${r}`:i,p=d.get(o,u,""),f=g.useMemo(()=>d.get(Ot,r,r),[r]),m=()=>{const h=o==null?void 0:o._id;s({blockId:h,blockProp:u,placeholder:e,initialCode:p})};return a.jsxs("div",{className:"mt-2 flex flex-col gap-y-1",children:[a.jsxs("label",{htmlFor:t,children:["HTML Code",f&&a.jsxs("small",{className:"text-[9px] text-zinc-400",children:[" ",f]})]}),a.jsx("button",{onClick:m,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>"}),a.jsx(_.Button,{onClick:m,size:"sm",variant:"outline",className:"w-fit",children:n("Open code editor")})]})},Em=({id:t,value:e,onChange:n,onBlur:s})=>{const r=$("collections",[]),o=J(),i=d.get(o,"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1").replace(q.COLLECTION_PREFIX,""),l=d.find(r,{id:i}),c=t==="root.filter"?"filters":"sorts",u=d.get(l,c,[]);return a.jsx("div",{children:a.jsxs("select",{value:e,onChange:p=>n(p.target.value),onBlur:p=>s(t,p.target.value),children:[a.jsx("option",{value:"",children:"Select"}),u.map(p=>a.jsx("option",{value:p.id,children:p.name},p.id))]})})},Am=g.lazy(()=>Promise.resolve().then(()=>require("./IconPicker-Bmz6vXB8.cjs")).then(t=>({default:t.IconPicker}))),Im=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}},Tm=({value:t,onChange:e,id:n})=>{const{t:s}=F.useTranslation(),[r,o]=g.useState(t||"");g.useEffect(()=>{o(t||"")},[t]);const i=l=>{o(l);const c=Im(l);e(c)};return a.jsxs("div",{className:"mt-1 flex flex-col gap-2",id:"icon-picker-field",children:[a.jsxs("div",{className:"flex items-center gap-x-2",children:[a.jsx("div",{className:"flex h-12 w-12 items-center justify-center overflow-hidden rounded-lg border bg-gray-50",children:r?a.jsx("div",{className:"h-6 w-6",dangerouslySetInnerHTML:{__html:r}}):a.jsx("span",{className:"text-xs text-gray-400",children:"SVG"})}),a.jsx("textarea",{id:n,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",value:r,onChange:l=>i(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"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(g.Suspense,{fallback:a.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading..."}),children:a.jsx(Am,{onSelectIcon:i})}),a.jsx("p",{className:"text-xs text-muted-foreground",children:s("Paste SVG_code")})]})]})},Pn=ie.Root,Pl=ie.Trigger,_m=ie.Portal,Ll=D.forwardRef(({className:t,...e},n)=>a.jsx(ie.Overlay,{ref:n,className:_.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}));Ll.displayName=ie.Overlay.displayName;const an=D.forwardRef(({className:t,children:e,...n},s)=>a.jsxs(_m,{children:[a.jsx(Ll,{}),a.jsxs(ie.Content,{ref:s,className:_.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,a.jsxs(ie.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:[a.jsx(v.Cross1Icon,{className:"h-4 w-4"}),a.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));an.displayName=ie.Content.displayName;const Ln=({className:t,...e})=>a.jsx("div",{className:_.cn("flex flex-col space-y-1.5 text-center sm:text-left",t),...e});Ln.displayName="DialogHeader";const Ml=({className:t,...e})=>a.jsx("div",{className:_.cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...e});Ml.displayName="DialogFooter";const ln=D.forwardRef(({className:t,...e},n)=>a.jsx(ie.Title,{ref:n,className:_.cn("text-lg font-semibold leading-none tracking-tight",t),...e}));ln.displayName=ie.Title.displayName;const Dl=D.forwardRef(({className:t,...e},n)=>a.jsx(ie.Description,{ref:n,className:_.cn("text-sm text-muted-foreground",t),...e}));Dl.displayName=ie.Description.displayName;const Qn=({assetId:t,children:e,onSelect:n,mode:s="image"})=>{const[r,o]=g.useState(!1),i=_.useMediaManagerComponent(),l=(...c)=>{n.call(void 0,...c),o(!1)};return a.jsxs(Pn,{open:r,onOpenChange:c=>o(c),children:[a.jsx(Pl,{asChild:!0,children:e}),a.jsxs(an,{className:"flex max-h-[90vh] max-w-7xl border-border md:w-fit",children:[a.jsx(ln,{className:"sr-only",children:"Media Manager"}),a.jsx("div",{className:"h-full w-full",children:i?a.jsx(i,{close:()=>o(!1),onSelect:l,mode:s,assetId:t}):null})]})]})};Qn.displayName="MediaManagerModal";const Yn="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTAwIiBoZWlnaHQ9IjQwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZjNmNGY2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCwgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNiIgZmlsbD0iI2Q1ZDdkYSIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPkltYWdlIFBsYWNlaG9sZGVyPC90ZXh0Pjwvc3ZnPg==",Bm=t=>{var r;if(!t||d.startsWith(t,"data"))return"";const e=((r=t.split("/").pop())==null?void 0:r.split("?")[0])||"";return[".jpg",".jpeg",".png",".gif",".webp",".svg",".bmp",".ico",".avif"].some(o=>e.toLowerCase().endsWith(o))?e:""},Rm=({value:t,onChange:e,id:n,onBlur:s,uiSchema:r})=>{const{t:o}=F.useTranslation(),{selectedLang:i}=Te(),l=J(),c=nt(),u=tn(),p=(r==null?void 0:r["ui:allowEmpty"])===!0,f=n.split(".").pop()||"",m=i?`_${f}Id-${i}`:`_${f}Id`,h=d.isEmpty(i)&&(l==null?void 0:l._type)==="Image"&&d.has(l,"assetId"),x=d.get(l,m,h?l==null?void 0:l.assetId:""),b=g.useMemo(()=>{if(!t||!l||!/\{\{.*?\}\}/.test(t))return t;const I={...l,[f]:t},T=be.applyBindingToBlockProps(I,u,{index:-1,key:""});return d.get(T,f,t)},[t,l,u,f]),y=!!x||b!==Yn&&b!=="",k=A=>{const I=d.isArray(A)?d.first(A):A;if(I){e(I==null?void 0:I.url);const T=I==null?void 0:I.width,N=I==null?void 0:I.height,S=m.includes("mobile");if(l!=null&&l._id){const C={...T&&{[S?"mobileWidth":"width"]:T},...N&&{[S?"mobileHeight":"height"]:N},...I.description&&{alt:I.description}};if(d.set(C,m,I.id),d.isEmpty(C))return;c([l._id],C)}}},w=g.useCallback(()=>{if(e(p?"":Yn),l!=null&&l._id){const I={},T=m.includes("mobile");d.set(I,m,""),d.set(I,T?"mobileWidth":"width",""),d.set(I,T?"mobileHeight":"height",""),c([l._id],I)}},[l,e,c,m,p]),E=Bm(b);return a.jsxs("div",{className:"mt-1.5 flex items-start gap-x-3",children:[b?a.jsxs("div",{className:"group relative",children:[a.jsx("img",{src:b,className:"h-14 w-14 overflow-hidden rounded-md border border-border object-cover transition duration-200 "+(x&&x!==""?"cursor-pointer group-hover:blur-sm":""),alt:""}),y&&a.jsx("button",{type:"button",onClick:w,className:"absolute -right-2 -top-2 z-20 rounded-full bg-destructive p-1 text-destructive-foreground hover:bg-destructive/90",children:a.jsx(v.Cross1Icon,{className:"h-3 w-3"})}),x&&x!==""&&a.jsx(Qn,{onSelect:k,assetId:x,children:a.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:a.jsx(v.Pencil2Icon,{className:"h-4 w-4 text-white"})})})]}):a.jsx(Qn,{onSelect:k,mode:"image",assetId:x,children:a.jsx("div",{className:"h-14 w-14 cursor-pointer rounded-md border border-border bg-[radial-gradient(#AAA,transparent_1px)] duration-300 [background-size:10px_10px]"})}),a.jsxs("div",{className:"flex w-3/5 flex-col",children:[a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"max-w-[250px] truncate pr-2 text-xs text-gray-400",children:E}),a.jsx(Qn,{onSelect:k,assetId:"",children:a.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?o("Replace image"):o("Choose image")})}),a.jsx("div",{className:"text-center text-xs text-gray-400",children:"OR"})]}),a.jsx("input",{id:n,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",type:"url",className:"h-6 text-xs",placeholder:o("Enter image URL"),value:t===Yn?"":t,onBlur:({target:{value:A}})=>s(n,A),onChange:A=>e(A.target.value)})]})]})},Pm=vr.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 _s({className:t,variant:e,...n}){return a.jsx("div",{className:_.cn(Pm({variant:e}),t),...n})}const ms=Jt.Provider,fe=Jt.Root,he=Jt.Trigger,ce=D.forwardRef(({className:t,sideOffset:e=4,...n},s)=>a.jsx(Jt.Portal,{children:a.jsx(Jt.Content,{ref:s,sideOffset:e,className:_.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})}));ce.displayName=Jt.Content.displayName;const co=D.forwardRef(({className:t,...e},n)=>a.jsx(De.Command,{ref:n,className:_.cn("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",t),...e}));co.displayName=De.Command.displayName;const uo=D.forwardRef(({className:t,...e},n)=>a.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[a.jsx(v.MagnifyingGlassIcon,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),a.jsx(De.Command.Input,{ref:n,className:_.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})]}));uo.displayName=De.Command.Input.displayName;const po=D.forwardRef(({className:t,...e},n)=>a.jsx(De.Command.List,{ref:n,className:_.cn("max-h-[300px] overflow-y-auto overflow-x-hidden",t),...e}));po.displayName=De.Command.List.displayName;const fo=D.forwardRef((t,e)=>a.jsx(De.Command.Empty,{ref:e,className:"py-6 text-center text-sm",...t}));fo.displayName=De.Command.Empty.displayName;const ho=D.forwardRef(({className:t,...e},n)=>a.jsx(De.Command.Group,{ref:n,className:_.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}));ho.displayName=De.Command.Group.displayName;const Lm=D.forwardRef(({className:t,...e},n)=>a.jsx(De.Command.Separator,{ref:n,className:_.cn("-mx-1 h-px bg-border",t),...e}));Lm.displayName=De.Command.Separator.displayName;const gs=D.forwardRef(({className:t,...e},n)=>a.jsx(De.Command.Item,{ref:n,className:_.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}));gs.displayName=De.Command.Item.displayName;const mo=vn.Root,go=vn.Trigger,Bs=D.forwardRef(({className:t,align:e="center",sideOffset:n=4,...s},r)=>a.jsx(vn.Portal,{children:a.jsx(vn.Content,{ref:r,align:e,sideOffset:n,className:_.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})}));Bs.displayName=vn.Content.displayName;const Mm=({data:t,onSelect:e,dataType:n})=>{const[s,r]=g.useState([]),[o,i]=g.useState(t),l=f=>Array.isArray(f)?"array":typeof f=="object"&&f!==null?"object":"value",c=g.useCallback(f=>{const m=h=>n==="value"?h==="value"||h==="object":n==="array"?h==="array":h===n;f.type==="object"?(r(h=>[...h,f.key]),i(f.value)):m(f.type)&&e([...s,f.key].join("."),n)},[s,e,n]),u=g.useCallback(()=>{if(s.length>0){const f=s.slice(0,-1);r(f),i(f.reduce((m,h)=>m[h],t))}},[s,t]),p=g.useMemo(()=>o?Object.entries(o).map(([f,m])=>({key:f,value:m,type:l(m)})).filter(f=>!d.startsWith(f.key,q.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):[],[o,n]);return a.jsxs(co,{className:"fields-command",children:[a.jsx(uo,{className:"border-none",placeholder:"Search..."}),a.jsxs(po,{children:[a.jsx(fo,{children:gt.t("No option found.")}),a.jsxs(ho,{children:[s.length>0&&a.jsxs(gs,{onSelect:u,className:"flex items-center text-sm",children:[a.jsx(v.ChevronLeftIcon,{className:"mr-2 h-4 w-4"}),gt.t("Back")]}),p.map(f=>a.jsxs(gs,{value:f.key,disabled:!1,onSelect:()=>c(f),className:"flex items-center justify-between",children:[a.jsxs("span",{className:"flex items-center gap-x-2",children:[d.startsWith(f.key,q.REPEATER_PREFIX)?a.jsx(v.LoopIcon,{}):d.startsWith(f.key,q.COLLECTION_PREFIX)?a.jsx(v.IdCardIcon,{}):null,d.startsWith(f.key,q.REPEATER_PREFIX)?gt.t("Repeater Data"):d.startsWith(f.key,q.COLLECTION_PREFIX)?f.key.replace(q.COLLECTION_PREFIX,""):f.key]}),a.jsxs("div",{className:"flex items-center gap-2",children:[n==="object"&&f.type==="object"&&a.jsx(_.Button,{size:"sm",variant:"ghost",className:"h-6 px-2 hover:bg-primary hover:text-primary-foreground",onClick:m=>{m.stopPropagation(),e([...s,f.key].join("."),n)},children:gt.t("Select")}),f.type==="object"&&a.jsx("div",{className:"cursor-pointer rounded p-1 hover:bg-muted",children:a.jsx(v.ChevronRightIcon,{className:"h-4 w-4 opacity-50"})})]})]},f.key))]})]})]})};function xo({data:t,onSelect:e,dataType:n="value"}){const[s,r]=g.useState(!1),o=$("collections",[]),i=g.useMemo(()=>n==="array"?{...o.map(c=>c.id).reduce((c,u)=>({...c,[q.COLLECTION_PREFIX+u]:[]}),{}),...t}:t,[t,o,n]);return a.jsxs(mo,{open:s,onOpenChange:r,children:[a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(go,{asChild:!0,children:a.jsx(_.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:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24px",height:"24px",viewBox:"0 0 24 24",fill:"none",children:a.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"})})})})}),a.jsx(ce,{children:gt.t("Add field")})]}),a.jsx(Bs,{className:"z-[1000]! relative mr-3 w-[300px] p-0",children:a.jsx(Mm,{data:i,onSelect:(l,c)=>{e(l,c),r(!1)},dataType:n})})]})}const Ol=({schema:t,onChange:e,id:n,formData:s})=>{const r=tn(),o=$("flags.dataBinding",!0),i=_d(),l=J(),c=g.useMemo(()=>{if(i.length===1)return"";const f=i.find(x=>x._type==="Repeater"),h=d.get(f,"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1");return`${q.REPEATER_PREFIX}${d.startsWith(h,q.COLLECTION_PREFIX)?`${h}/${f==null?void 0:f._id}`:h}`},[i]),u=g.useMemo(()=>d.first(d.get(r,c.replace(q.REPEATER_PREFIX,""),[])),[c,r]),p=g.useCallback((f,m)=>{if(f=d.isEmpty(c)?f:f.replace(`${c}`,"$index"),m==="array"||m==="object"){e(`{{${f}}}`,{},n);return}const h=k=>/[.,!?;:]/.test(k),x=(k,w,E)=>{let A="",I="";const T=w>0?k[w-1]:"",N=w<k.length?k[w]:"";return w>0&&(T==="."||!h(T)&&T!==" ")&&(A=" "),w<k.length&&!h(N)&&N!==" "&&(I=" "),{text:A+E+I,prefixLength:A.length,suffixLength:I.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 w=`{{${f}}}`;k.commands.focus();const{from:E,to:A}=k.state.selection;if(E!==A)k.chain().deleteSelection().insertContent(w).run();else{const{state:T}=k,N=T.selection.from,S=T.doc.textBetween(Math.max(0,N-1),N),C=T.doc.textBetween(N,Math.min(N+1,T.doc.content.size));let B="";N>0&&S!==" "&&!h(S)&&(B=" ");let P="";C&&C!==" "&&!h(C)&&(P=" "),k.chain().insertContent(B+w+P).run()}setTimeout(()=>e(k.getHTML(),{},n),100);return}}else{const k=b,w=k.selectionStart||0,E=k.value||"",A=k.selectionEnd||w;if(A>w){const C=`{{${f}}}`,{text:B}=x(E,w,C),P=E.slice(0,w)+B+E.slice(A);e(P,{},n);return}const T=`{{${f}}}`,{text:N}=x(E,w,T),S=E.slice(0,w)+N+E.slice(w);e(S,{},n)}},[n,e,s,l==null?void 0:l._id,c]);return o?a.jsx(xo,{data:{...u&&{[c]:u},...r},onSelect:p,dataType:t.binding==="array"?"array":"value"}):null},Dm=t=>{const{id:e,classNames:n,label:s,children:r,errors:o,help:i,hidden:l,required:c,schema:u,formData:p,onChange:f}=t,{selectedLang:m,fallbackLang:h,languages:x}=Te(),b=g.useMemo(()=>d.isEmpty(x)?"":d.isEmpty(m)?h:m,[x,m,h]),y=g.useMemo(()=>d.get(Ot,b,b),[b]),k=tn(),w=J(),E=X.useRegisteredChaiBlocks(),A=g.useMemo(()=>d.get(E,[w==null?void 0:w._type,"i18nProps"],[]),[E,w==null?void 0:w._type]),[I,T]=g.useState(null);if(l)return null;if(u.type==="boolean")return a.jsx("div",{className:n,children:r});const S=A==null?void 0:A.includes(e.replace("root.",""));if(u.type==="array"){const P=I===e;return a.jsxs("div",{className:`${n} relative`,children:[u.title&&a.jsx("div",{className:"flex items-center justify-between gap-1",children:a.jsxs("label",{htmlFor:e,onClick:()=>T(P?null:e),className:"flex cursor-pointer items-center gap-x-1 py-1 leading-tight duration-200 hover:bg-slate-100",children:[P?a.jsx(v.ChevronDownIcon,{className:"h-3 w-3"}):a.jsx(v.ChevronRightIcon,{className:"h-3 w-3"}),a.jsx(v.ListBulletIcon,{className:"h-3 w-3"}),a.jsx("span",{className:"leading-tight",children:s})," ",a.jsx(_s,{className:"m-0 bg-gray-200 px-2 leading-tight text-gray-500 hover:bg-gray-200 hover:text-gray-500",children:a.jsx("span",{className:"text-[9px] font-medium text-slate-600",children:p==null?void 0:p.length})}),u.description&&a.jsx(ms,{children:a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(v.InfoCircledIcon,{className:"h-3 w-3 text-muted-foreground/70",onClick:R=>R.stopPropagation(),onMouseDown:R=>R.stopPropagation()})}),a.jsx(ce,{className:"max-w-xs",children:u.description})]})})]})}),(p==null?void 0:p.length)===0?a.jsx("div",{className:"h-0 overflow-hidden",children:r}):a.jsxs("div",{className:`${P?"pt-0.5":"h-0 overflow-hidden"}`,children:[r,o,i]})]})}const C=e.replace("root.",""),B=A.includes(C)&&!d.isEmpty(m)&&d.isEmpty(p);return a.jsxs("div",{className:n,children:[u.title&&a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("label",{htmlFor:e,className:u.type==="object"?"pb-2":"",children:[s," ",S&&a.jsxs("small",{className:"text-[9px] text-zinc-400",children:[" ",y]}),c&&u.type!=="object"?" *":null]}),u.description&&a.jsx(ms,{children:a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(v.InfoCircledIcon,{className:"h-3 w-3 text-muted-foreground/70"})}),a.jsx(ce,{className:"max-w-xs",children:u.description})]})})]}),!u.enum&&!u.oneOf&&k&&a.jsxs("span",{className:"flex items-center space-x-1",children:[B?a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.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:[a.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"}),a.jsx("path",{d:"M12 9v4"}),a.jsx("path",{d:"M12 17h.01"})]})}),a.jsxs(ce,{className:"max-w-xs",children:["No translation provided. ",a.jsx("br",{}),"Using default language value."]})]}):null,a.jsx(Ol,{schema:u,onChange:P=>{f(P,p,e)},id:e,formData:p})]})]}),r,o,i]})},Om=({href:t,pageTypes:e,onChange:n})=>{var S;const{t:s}=F.useTranslation(),r=$("searchPageTypeItems",(C,B)=>[]),[o,i]=g.useState(!1),[l,c]=g.useState(!1),[u,p]=g.useState("page"),[f,m]=g.useState(""),[h,x]=g.useState([]),[b,y]=g.useState(-1),k=g.useRef(null),w=(S=e==null?void 0:e.find(C=>C.key===u))==null?void 0:S.name;g.useEffect(()=>{if(m(""),x([]),y(-1),c(!1),!t||o||!d.startsWith(t,"pageType:"))return;const C=d.split(t,":"),B=d.get(C,1,"page")||"page";p(B),(async()=>{const P=await r(B,[d.get(C,2,"page")]);P&&Array.isArray(P)&&m(d.get(P,[0,"name"],""))})()},[t]);const E=ke.useDebouncedCallback(async C=>{if(d.isEmpty(C))x([]);else{const B=await r(u,C);x(B)}i(!1),y(-1)},[u],300),A=C=>{const B=["pageType",u,C.primaryPage??C.id];B[1]&&(n(B.join(":")),m(C.name),c(!1),x([]),y(-1))},I=C=>{switch(C.key){case"ArrowDown":C.preventDefault(),y(B=>B<h.length-1?B+1:B);break;case"ArrowUp":C.preventDefault(),y(B=>B>0?B-1:B);break;case"Enter":if(C.preventDefault(),h.length===0)return;b>=0&&A(h[b]);break;case"Escape":C.preventDefault(),T();break}};g.useEffect(()=>{if(b>=0&&k.current){const C=k.current.children[b];C==null||C.scrollIntoView({block:"nearest"})}},[b]);const T=()=>{m(""),x([]),y(-1),c(!1),n("")},N=C=>{m(C),c(!d.isEmpty(C)),i(!0),E(C)};return a.jsxs("div",{children:[a.jsx("select",{name:"pageType",value:u,onChange:C=>p(C.target.value),children:d.map(e,C=>a.jsx("option",{value:C.key,children:C.name},C.key))}),u&&a.jsxs("div",{className:"group relative mt-2 flex items-center",children:[a.jsx("input",{type:"text",value:f,onChange:C=>N(C.target.value),onKeyDown:I,placeholder:s(`Search ${w??""}`),className:"w-full rounded-md border border-gray-300 p-2 pr-16"}),a.jsx("div",{className:"absolute bottom-2 right-2 top-3 flex items-center gap-1.5",children:f&&a.jsx("button",{onClick:T,className:"text-gray-400 hover:text-gray-600",title:s("Clear search"),children:a.jsx(v.Cross1Icon,{className:"h-4 w-4"})})})]}),(o||!d.isEmpty(h)||l&&d.isEmpty(h))&&a.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?a.jsxs("div",{className:"space-y-1 p-2",children:[a.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),a.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):l&&d.isEmpty(h)?a.jsxs("div",{className:"flex items-center justify-center p-4 text-sm text-gray-500",children:[s("No results found for"),' "',f,'"']}):a.jsx("ul",{ref:k,children:d.map(h==null?void 0:h.slice(0,20),(C,B)=>a.jsxs("li",{onClick:()=>A(C),className:`cursor-pointer p-2 text-xs ${t!=null&&t.includes(C.id)?"bg-blue-200":B===b?"bg-gray-100":"hover:bg-gray-100"}`,children:[C.name," ",C.slug&&a.jsxs("small",{className:"font-light text-gray-500",children:["( ",C.slug," )"]}),C.lang&&a.jsx("small",{className:"ml-1 rounded bg-gray-200 px-1 py-0.5 text-[10px] font-medium text-gray-600",children:C.lang})]},C.id))})})]})},$m=({schema:t,formData:e,onChange:n,name:s})=>{const{t:r}=F.useTranslation(),{type:o="pageType",href:i="",target:l="self"}=e??{},c=$("pageTypes",[]),{selectedLang:u,fallbackLang:p,languages:f}=Te(),m=g.useMemo(()=>d.isEmpty(f)?"":d.isEmpty(u)?p:u,[f,u,p]),h=g.useMemo(()=>d.get(Ot,m,m),[m]),x=o==="pageType"&&d.isEmpty(c)?"url":o;return a.jsxs("div",{children:[a.jsxs("span",{className:"flex items-center justify-between gap-x-2 text-xs font-medium",children:[a.jsxs("span",{children:[(t==null?void 0:t.title)??"Link",a.jsx("span",{className:"pl-1 text-[9px] text-zinc-400",children:h})]}),a.jsx(Ol,{schema:t,onChange:b=>{n({...e,href:b,...x==="pageType"?{type:"url"}:{}})},id:`root.${s}.href`,formData:e})]}),a.jsxs("div",{className:"flex flex-col gap-y-1.5",children:[a.jsx("select",{name:"type",value:o,onChange:b=>n({...e,type:b.target.value}),children:d.map([...d.isEmpty(c)?[]:[{const:"pageType",title:r("Goto Page")}],{const:"url",title:r("Open URL")},{const:"email",title:r("Compose Email")},{const:"telephone",title:r("Call Phone")},{const:"scroll",title:r("Scroll to element")}],b=>a.jsx("option",{value:b.const,children:b.title},b.const))}),x==="pageType"&&!d.isEmpty(c)?a.jsx(Om,{href:i,pageTypes:c,onChange:b=>n({...e,href:b})}):null,a.jsx("input",{id:`root.${s}.href`,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",name:"href",type:"text",className:x==="pageType"?"!hidden":"",value:i,onChange:b=>n({...e,href:b.target.value}),placeholder:r(o==="url"?"Enter URL":o==="scroll"?"#ElementID":"Enter details")}),x==="url"&&a.jsxs("div",{className:"flex items-center gap-x-2 text-muted-foreground",children:[a.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"})}),a.jsx("span",{className:"pt-1 text-xs",children:r("Open in new tab")})]})]})]})},Fm=({value:t,onChange:e})=>{var o;if(!t)return a.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:[a.jsx(v.FileIcon,{className:"h-4 w-4"})," Choose a collection"]});const n=`{{${q.COLLECTION_PREFIX}`,s=t==null?void 0:t.startsWith(n);let r=t;return s&&(r=(o=t==null?void 0:t.replace(n,""))==null?void 0:o.replace("}}","")),a.jsx("div",{className:"mt-1 flex flex-col gap-1",children:a.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:[a.jsxs("span",{className:"flex max-w-[200px] items-center gap-2",children:[" ",s?a.jsx(v.IdCardIcon,{className:"h-3 min-h-3 w-3 min-w-3"}):null,a.jsxs(fe,{delayDuration:500,children:[a.jsx(he,{asChild:!0,children:a.jsx("span",{className:"cursor-default truncate",children:r})}),a.jsx(ce,{side:"left",hidden:r.length<50,children:r})]})]}),a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(_.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:a.jsx(v.Cross1Icon,{className:"h-4 w-4"})})}),a.jsx(ce,{side:"left",children:"Remove binding"})]})]})})},$l=j.atom(t=>{var i;const e=t(je),n=t(ys),s=n.length===1?n[0]:null;if(!s)return null;const r=d.find(e,{_id:s});if(!r)return null;let o=r._parent;for(;o;){const l=d.find(e,{_id:o});if(!l)return null;if((i=X.getRegisteredChaiBlock(l._type))!=null&&i.wrapper)return l;o=l._parent}return null});$l.debugLabel="wrapperBlockAtom";const bo=()=>j.useAtomValue($l),zm=()=>{const t=J(),e=bo(),{addCoreBlock:n}=bt();if(!t&&!e)return null;const s=(t==null?void 0:t._type)==="Row"?t:e;return a.jsx("div",{className:"pt-1",children:a.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:[a.jsx(v.PlusIcon,{className:"h-4 w-4"})," Add Column"]})})},Hm=g.lazy(()=>Promise.resolve().then(()=>require("./rte-widget-modal-JRoPPuju.cjs"))),Vm=({blockId:t,id:e,placeholder:n,value:s,onChange:r,onBlur:o})=>{const i=g.useRef(null),[l,c]=g.useState(!1),u=Al({blockId:t,value:s,placeholder:n,onBlur:({editor:m})=>{const h=m==null?void 0:m.getHTML();o(e,h)},onUpdate:({editor:m})=>{const h=m==null?void 0:m.getHTML();r(h)}});g.useEffect(()=>{i.current&&u&&(i.current.__chaiRTE=u)},[t,u]);const p=()=>{c(!1)},f=a.jsxs("div",{id:`chai-rte-${e}`,ref:i,className:"mt-1 rounded-md border border-input",children:[a.jsx(Pi,{editor:u,onExpand:()=>c(!0)}),a.jsx(ns.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 a.jsxs(a.Fragment,{children:[l&&a.jsx(g.Suspense,{fallback:a.jsx("div",{children:"Loading..."}),children:a.jsx(Hm,{isOpen:l,onClose:p,editor:u,rteElement:f})}),l?a.jsx("div",{children:"Open in modal"}):a.jsx("div",{className:"relative",children:f})]})},Wm=t=>{const{editingBlockId:e}=Ft(),[n,s]=g.useState(null),r=J(),o=r==null?void 0:r._id;return g.useEffect(()=>{s(o)},[o]),n&&n!==e?a.jsx(Vm,{...t,blockId:n},n):null},Gm=({formData:t,onChange:e})=>{const[n]=te(),s=J(),r=bo(),{addCoreBlock:o}=bt(),[,i]=U(),l=(s==null?void 0:s._type)==="Slider"?s:r,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&&!r||!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}),i([y])}},m=()=>{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}),i([y])}},h=()=>{const x=o({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}),i([b]))};return a.jsxs("div",{className:"space-y-1.5 px-2",children:[a.jsxs("div",{className:"flex items-center gap-x-2 pb-2 text-[12px]",children:[a.jsx("button",{onClick:m,className:"rounded bg-gray-200 p-1.5 hover:opacity-80",children:a.jsx(v.ChevronLeftIcon,{className:"h-3 w-3"})}),a.jsx("div",{className:"whitespace-nowrap text-center text-[10px] text-slate-500",children:p?a.jsxs("span",{className:"",children:[a.jsxs("b",{className:"text-[12px]",children:[" ",d.findIndex(u,{_id:p})+1]}),"/",u.length]}):"-"}),a.jsx("button",{onClick:f,className:"rounded bg-gray-200 p-1.5 hover:opacity-80",children:a.jsx(v.ChevronRightIcon,{className:"h-3 w-3"})}),a.jsxs("button",{onClick:h,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:[a.jsx(v.PlusCircledIcon,{className:"h-3 w-3"}),"Add Slide"]})]}),a.jsxs("div",{className:"flex items-center gap-x-2 leading-tight",children:[a.jsx("input",{type:"checkbox",checked:!!(t!=null&&t.showSlideButton),onChange:()=>e({...t,showSlideButton:!(t!=null&&t.showSlideButton)}),className:"cursor-pointer"}),a.jsx("label",{htmlFor:"autoplay",className:"mt-0.5 text-[12px]",children:"Show Slide Buttons"})]}),a.jsxs("div",{className:"flex items-center gap-x-2 leading-tight",children:[a.jsx("input",{type:"checkbox",checked:!!(t!=null&&t.showSlideNavbar),onChange:()=>e({...t,showSlideNavbar:!(t!=null&&t.showSlideNavbar)}),className:"cursor-pointer"}),a.jsx("label",{htmlFor:"autoplay",className:"mt-0.5 text-[12px]",children:"Show Slide Navbar"})]}),a.jsx("div",{children:a.jsxs("div",{className:"flex flex-col",children:[a.jsxs("div",{className:"flex items-center gap-x-2 leading-tight",children:[a.jsx("input",{type:"checkbox",checked:!!(t!=null&&t.autoplay),onChange:()=>e({...t,autoplay:!(t!=null&&t.autoplay)}),className:"cursor-pointer"}),a.jsx("label",{htmlFor:"autoplay",className:"mt-0.5 text-[12px]",children:"Autoplay slides"})]}),(t==null?void 0:t.autoplay)&&a.jsxs("div",{className:"pt-0.5 leading-tight",children:[a.jsxs("label",{htmlFor:"interval",className:"whitespace-nowrap text-[9px]",children:["Autoplay Interval ",a.jsx("span",{className:"font-light opacity-80",children:"(in seconds)"})]}),a.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})}})]})]})})]})},Um=({formData:t,onChange:e})=>{const n=d.get(t,"srcsets",[])||[],s=(i,l)=>{const c=i.target.name,u=i.target.value;e({srcsets:d.map(n,(p,f)=>f===l?{...p,[c]:u}:p)})},r=()=>{e({srcsets:[...n,{}]})},o=i=>{e({srcsets:d.reject(n,(l,c)=>parseInt(c)===i)})};return a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between pb-2",children:[a.jsx("label",{children:"Responsive Video (optional)"}),a.jsx("button",{type:"button",onClick:r,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:a.jsx(v.PlusIcon,{className:"h-3 w-3"})})]}),a.jsx("div",{className:"space-y-2",children:n.length===0?a.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,(i,l)=>a.jsxs("div",{className:"group relative space-y-1.5 rounded border border-gray-200 px-2 pb-1.5",children:[a.jsx("button",{type:"button",onClick:()=>o(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:a.jsx(v.Cross1Icon,{className:"h-2.5 w-2.5 text-red-500"})}),a.jsxs("div",{className:"flex items-center gap-x-2 rounded border",children:[a.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"}),a.jsx("input",{name:"width",placeholder:"Enter width (in px)",type:"number",value:d.get(i,"width"),onChange:c=>s(c,l),className:"!placeholder:text-gray-100 !mt-0 !rounded-none !border-0 !p-0 !text-xs"})]}),a.jsxs("div",{className:"flex items-center gap-x-2 rounded border",children:[a.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"}),a.jsx("input",{name:"url",placeholder:"Enter url",className:"!mt-0 !rounded-none !border-0 !p-0 !text-xs !shadow-none",value:d.get(i,"url",""),onChange:c=>s(c,l)})]})]},l))})]})},qm=t=>a.jsx("button",{...t,className:"duration absolute right-2 top-2 cursor-pointer text-blue-400 hover:text-blue-500",children:a.jsxs("div",{className:"flex items-center gap-x-0.5 text-[11px] leading-tight",children:[a.jsx(v.PlusIcon,{className:"h-3 w-3"})," ",a.jsx("span",{children:"Add"})]})}),ga=g.memo(({blockId:t,schema:e,uiSchema:n,formData:s,onChange:r})=>{const{selectedLang:o}=Te(),i=_.useBlockSettingComponents("widget"),l=_.useBlockSettingComponents("field"),c=_.useBlockSettingComponents("template"),u=ke.useThrottledCallback(async({formData:p},f)=>{d.get(p,f)===void 0&&d.set(p,f,""),r({formData:p},f)},[r,o],400);return a.jsx(Zc,{widgets:{richtext:Wm,icon:Tm,image:Rm,code:Nm,colCount:zm,collectionSelect:Em,repeaterBinding:Fm,...i},fields:{link:$m,slider:Gm,sources:Um,...l},templates:{FieldTemplate:Dm,ButtonTemplates:{AddButton:qm},...c},idSeparator:".",autoComplete:"off",omitExtraData:!1,liveOmit:!1,liveValidate:!1,validator:Qc,uiSchema:n,schema:e,formData:s,onChange:({formData:p},f)=>{if(!f||t!==(p==null?void 0:p._id))return;const m=d.take(f.split("."),2).join(".").replace("root.","");u({formData:p},m)}},o)}),xa=(t,e,n)=>{const s=d.cloneDeep(t);return d.forEach(d.keys(t),r=>{d.includes(d.get(n,"i18nProps",[]),r)&&!d.isEmpty(e)&&(s[r]=d.get(t,`${r}-${e}`))}),s};function fr(){const{selectedLang:t}=Te(),e=J(),n=_r(),s=nt(),r=X.getRegisteredChaiBlock(e==null?void 0:e._type),o=xa(e,t,r),[i,l]=g.useState(o),[c,u]=g.useState(!1),p=bo(),f=X.getRegisteredChaiBlock(p==null?void 0:p._type),m=xa(p,t,f),h=({formData:I},T,N)=>{T&&(i==null?void 0:i._id)===e._id&&s([e._id],{[T]:d.get(I,T)},N)},x=g.useCallback(d.debounce(({formData:I},T,N)=>{h({formData:I},T,N),l(I)},1500),[e==null?void 0:e._id,t]),b=({formData:I},T)=>{T&&(n([e._id],{[T]:d.get(I,T)}),x({formData:I},T,{[T]:d.get(i,T)}))},y=({formData:I},T)=>{T&&(n([p._id],{[T]:d.get(I,T)}),x({formData:I},T,{[T]:d.get(i,T)}))},{schema:k,uiSchema:w}=g.useMemo(()=>{const I=e==null?void 0:e._type;if(!I)return{schema:{},uiSchema:{}};try{const{schema:T,uiSchema:N}=X.getBlockFormSchemas(I);if(I==="Repeater"){const S=d.get(e,"repeaterItems","");d.startsWith(S,`{{${q.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:T,uiSchema:N}}catch{return{schema:{},uiSchema:{}}}},[e]),{wrapperSchema:E,wrapperUiSchema:A}=g.useMemo(()=>{if(!p||!(p!=null&&p._type))return{wrapperSchema:{},wrapperUiSchema:{}};const I=p==null?void 0:p._type,{schema:T={},uiSchema:N={}}=X.getBlockFormSchemas(I);return{wrapperSchema:T,wrapperUiSchema:N}},[p]);return a.jsxs("div",{className:"no-scrollbar overflow-x-hidden px-px",children:[!d.isEmpty(p)&&a.jsxs("div",{className:"mb-4 rounded border bg-zinc-100 px-1",children:[a.jsxs("div",{onClick:()=>u(I=>!I),className:"flex cursor-pointer items-center gap-x-1 py-2 text-xs font-medium leading-tight hover:bg-slate-100",children:[c?a.jsx(v.ChevronDownIcon,{className:"h-4 w-4 text-slate-400"}):a.jsx(v.ChevronRightIcon,{className:"h-4 w-4 text-slate-400"}),d.startCase(p._type)," settings"," ",p._name&&a.jsxs("span",{className:"text-[11px] font-light text-slate-400",children:["(",p._name,")"]})]}),a.jsx("div",{className:c?"h-auto":"invisible h-0",children:a.jsx(ga,{blockId:p==null?void 0:p._id,onChange:y,formData:m,schema:E,uiSchema:A})})]}),d.isEmpty(k)?null:a.jsx(ga,{blockId:e==null?void 0:e._id,onChange:b,formData:o,schema:k,uiSchema:w})]})}const Fl=Pt.Root,yo=D.forwardRef(({className:t,...e},n)=>a.jsx(Pt.Item,{ref:n,className:_.cn("border-b",t),...e}));yo.displayName="AccordionItem";const vo=D.forwardRef(({className:t,children:e,...n},s)=>a.jsx(Pt.Header,{className:"flex",children:a.jsxs(Pt.Trigger,{ref:s,className:_.cn("flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline text-left [&[data-state=open]>svg]:rotate-180",t),...n,children:[e,a.jsx(v.ChevronDownIcon,{className:"h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200"})]})}));vo.displayName=Pt.Trigger.displayName;const ko=D.forwardRef(({className:t,children:e,...n},s)=>a.jsx(Pt.Content,{ref:s,className:"overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...n,children:a.jsx("div",{className:_.cn("pb-4 pt-0",t),children:e})}));ko.displayName=Pt.Content.displayName;const Km=j.atom(null,(t,e,{blockIds:n,fullClasses:s})=>{const r=d.first(t(Bn)),o=d.filter(t(En),i=>n.includes(t(i)._id));return d.map(o,i=>{const l=t(i),c=s;let{classes:u,baseClasses:p}=be.getSplitChaiClasses(d.get(l,r.prop,`${q.STYLES_KEY},`));return d.each(c,f=>{const m=f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),h=new RegExp(`(^|\\s)${m}(?=\\s|$)`,"g");u=u.replace(h," ").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 m=f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),h=new RegExp(`(^|\\s)${m}(?=\\s|$)`,"g");p=p.replace(h," ").replace(/\s+/g," ").trim()}),{ids:[l._id],props:{[r.prop]:`${q.STYLES_KEY}${p},${u}`}}})}),Ym=t=>{const e=Object.keys(t).filter(s=>typeof t[s]=="string"&&t[s].startsWith(q.STYLES_KEY)),n={};return e.forEach(s=>{n[s]=`${q.STYLES_KEY},`}),{ids:[t._id],props:n}},Xm=()=>{const{updateBlocks:t,updateBlocksRuntime:e}=Ne();return g.useCallback((n,s=!1)=>{const{ids:r,props:o}=Ym(n);s?t(r,o):e(r,o)},[t,e])},wo=()=>{const{updateBlocks:t,updateBlocksRuntime:e}=Ne(),n=j.useSetAtom(Km);return g.useCallback((s,r,o=!1)=>{const i=n({blockIds:s,fullClasses:r});o?t(s,i[0].props):e(s,i[0].props)},[n])},zl=()=>{const t=J(),e=nt(),n=g.useCallback(i=>X.getDefaultBlockProps(i)||{},[]),s=g.useCallback(i=>Object.keys(i).filter(l=>typeof i[l]=="string"&&i[l].startsWith("#styles:")),[]),r=g.useCallback(i=>{if(!t)return;const c=n(t._type)[i]??"#styles:,";e([t._id],{[i]:c})},[t,n,e]);return{resetAll:g.useCallback(()=>{if(!t)return;const i=s(t);if(i.length===0)return;const l=n(t._type),c=d.pick(l,i);e([t._id],c)},[t,s,n,e]),reset:r}},Jm=()=>{var h;const t=J(),[e,n]=Ee(),s=wo(),[r]=U(),{t:o}=F.useTranslation(),{reset:i}=zl();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,(h=e[0])==null?void 0:h.prop,""),{classes:p=""}=be.getSplitChaiClasses(u)||{},f=p?p.split(" ").filter(x=>!d.isEmpty(x)):[],m=x=>d.find(e,b=>b.prop===x);return a.jsx(a.Fragment,{children:c&&a.jsxs("div",{className:"flex flex-wrap gap-1",children:[a.jsxs("label",{htmlFor:"block-styling-props",className:"py-1 text-xs",children:[o("Style element"),":"]}),a.jsx("div",{className:"flex flex-wrap gap-2",children:d.map(l,x=>a.jsxs(_s,{className:"flex cursor-pointer items-center gap-1 pr-1",variant:m(x)?"default":"secondary",onClick:()=>{n([{id:`${x}-${t._id}`,blockId:t._id,prop:x}])},children:[d.startCase(x),a.jsxs(et,{children:[a.jsx(tt,{asChild:!0,children:a.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:a.jsx(v.DotsVerticalIcon,{className:"h-3 w-3"})})}),a.jsxs(Ge,{side:"bottom",className:"border-border text-xs",children:[a.jsx(le,{className:"text-xs",onClick:()=>{i(x)},children:o("Reset style")}),a.jsx(le,{className:"text-xs",onClick:()=>{s(r,f,!0)},children:o("Clear styles")})]})]})]},x))}),a.jsx("div",{className:"my-2 h-[1px] w-full bg-border"})]})})},Hl=g.createContext({setDragData:()=>{}}),ba=(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 r=t.match(s),o=r&&r.length>1,i=!d.isEmpty(n)&&Number.isNaN(Number(n));return o||i?{error:"Invalid value"}:r&&(r[0]==="auto"||r[0]==="none")?{value:r[0],unit:""}:{value:n,unit:r?r[0]:""}},Zm=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,r]=d.map(n.split("/"),o=>parseInt(o,10));return{value:e+(s/r*100).toFixed(2).replace(".00",""),unit:"%"}}return d.isNumber(parseFloat(n))?{value:`${e+parseFloat(n)*4}`,unit:"px"}:{value:n,unit:"class"}},Vl=t=>{if(d.isEmpty(t))return{value:"",unit:""};const e=t.match(/\[.*\]/g);if(e===null)return Qm(t);const n=d.get(e,"0","").replace(/\[|\]/g,""),s=t.startsWith("-")?"-":"",r=d.first(n.match(/\d+.\d+|\d+/g));return{value:`${s}${r}`,unit:n.replace(r,"")}},Qm=t=>d.isEmpty(t)?{value:"",unit:""}:Zm(t),eg=({unit:t,currentValue:e,onDrag:n,onDragEnd:s,onDragStart:r,negative:o,cssProperty:i})=>{const{setDragData:l}=g.useContext(Hl);return a.jsx("button",{type:"button",onMouseDown:c=>{const u={onDrag:n,onDragEnd:s,dragging:!0,dragStartY:c.pageY,dragStartValue:`${e}`,dragUnit:t,negative:o,cssProperty:i};r(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:a.jsx(v.RowSpacingIcon,{})})},tg=({onSelect:t,current:e,units:n})=>a.jsx("div",{"data-theme":"light",className:"-m-[7px] -mx-[13px] flex w-9 flex-col",children:n.map(s=>a.jsx(_.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:r=>{r.stopPropagation(),t(s)},children:s},s))}),ya=50,ng=t=>{const[e,n]=g.useState(!1),[s,r]=g.useState(""),{currentClass:o,onChange:i,classPrefix:l,cssProperty:c,units:u,negative:p}=t,[f,m]=g.useState(c!=null&&c.toLowerCase().includes("width")?"%":u[0]),[h,x]=g.useState(!1),[b,y]=g.useState(""),[k,w]=g.useState(!1),[E,A]=g.useState(!1);g.useEffect(()=>{const{value:C,unit:B}=Vl(o);if(B===""){r(C),m(c!=null&&c.toLowerCase().includes("width")?"%":d.first(u));return}m(B),r(B==="class"||d.isEmpty(C)?"":C)},[o,c,u]);const I=ke.useThrottledCallback(C=>i(C),[i],ya),T=ke.useThrottledCallback(C=>i(C,!1),[i],ya),N=g.useCallback((C=!1)=>{const B=ba(`${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"){I(`${l}${P}`);return}if(d.get(B,"value")==="")return;const O=`${d.get(B,"value","").startsWith("-")?"-":""}${l}[${d.get(B,"value","").replace("-","")}${P==="-"?"":P}]`;C?T(O):I(O)},[I,T,s,f,l,u]),S=g.useCallback(C=>{const B=ba(`${s}`,u);if(d.get(B,"error",!1)){x(!0);return}if(C==="auto"||C==="none"){I(`${l}${C}`);return}if(d.get(B,"value")==="")return;const P=d.get(B,"unit")!==""?d.get(B,"unit"):C,O=`${d.get(B,"value","").startsWith("-")?"-":""}${l}[${d.get(B,"value","").replace("-","")}${P==="-"?"":P}]`;I(O)},[I,s,l,u]);return a.jsx("div",{className:"flex w-full flex-col",children:a.jsx("div",{className:"flex items-center justify-start",children:f==="class"?a.jsxs(a.Fragment,{children:[a.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:o}),a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx("button",{type:"button",className:"invisible ml-3 mt-1 text-blue-600 group-hover:visible",children:a.jsx(v.InfoCircledIcon,{})})}),a.jsx(ce,{children:"Current value is using a Tailwind preset class."})]})]}):a.jsxs("div",{className:`group relative flex items-center ${k?"z-auto":""}`,children:[a.jsxs("div",{className:"flex items-center rounded-md border border-border",children:[["none","auto"].indexOf(f)!==-1?null:a.jsx("input",{readOnly:f==="class",onKeyPress:C=>{C.key==="Enter"&&N()},onKeyDown:C=>{if(C.keyCode!==38&&C.keyCode!==40)return;C.preventDefault(),A(!0);const B=d.parseInt(C.target.value);let P=d.isNaN(B)?0:B;C.keyCode===38&&(P+=1),C.keyCode===40&&(P-=1);const R=`${P}`,z=`${R.startsWith("-")?"-":""}${l}[${R.replace("-","")}${f==="-"?"":f}]`;T(z)},onKeyUp:C=>{E&&(C.preventDefault(),A(!1))},onBlur:()=>N(),onChange:C=>{x(!1),r(C.target.value)},onClick:C=>{var B;(B=C==null?void 0:C.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(" ",h?"border-red-500 text-red-500":"border-foreground/20")}),a.jsxs(fe,{open:e,delayDuration:100,children:[a.jsx(he,{asChild:!0,children:a.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:[a.jsx("span",{className:`inline-block ${u.length===1?"px-2 font-semibold":""}`,children:f}),u.length>1?a.jsx(v.TriangleDownIcon,{}):null]})}),a.jsx(ce,{className:"bg-background",children:a.jsx(tg,{units:u,current:f,onSelect:C=>{n(!1),m(C),S(C)}})})]})]}),["none","auto"].indexOf(f)!==-1||k?null:a.jsx(eg,{onDragStart:()=>w(!0),onDragEnd:C=>{if(y(()=>""),w(!1),d.isEmpty(C))return;const B=`${C}`,R=`${B.startsWith("-")?"-":""}${l}[${B.replace("-","")}${f==="-"?"":f}]`;I(R)},onDrag:C=>{if(d.isEmpty(C))return;y(C);const B=`${C}`,R=`${B.startsWith("-")?"-":""}${l}[${B.replace("-","")}${f==="-"?"":f}]`;T(R)},currentValue:s,unit:f,negative:p,cssProperty:c})]})})})},Mn=g.createContext({canReset:!1,canChange:!0}),sg=({children:t,canReset:e=!1,canChange:n=!0})=>a.jsx(Mn.Provider,{value:{canReset:e,canChange:n},children:t}),er=[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:[...er,"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:[...er,"px","0.5","1.5","2.5","3.5"],margin:["auto",...er,"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"]},Xt={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+|\\[.*\\])"}},rg={backgroundColor:"bg",textColor:"text",borderColor:"border",boxShadowColor:"shadow",outlineColor:"outline",divideColor:"divide",fromColor:"from",viaColor:"via",toColor:"to",ringColor:"ring",ringOffsetColor:"ring-offset"},og=["current","inherit","transparent","black","white"],ag=["slate","gray","zinc","neutral","stone","red","orange","amber","yellow","lime","green","emerald","teal","cyan","sky","blue","indigo","violet","purple","fuchsia","pink","rose"],ig=["50","100","200","300","400","500","600","700","800","900"],hr=d.map(d.values(rg),t=>t),lg=d.flattenDeep([...d.map(og,t=>d.flatten(d.map(hr,e=>`${e}-${t}`))),...d.map(ag,t=>d.flattenDeep(d.map(hr,e=>d.flattenDeep(d.map(ig,n=>`${e}-${t}-${n}`)))))]),cg=d.map(d.flattenDeep(d.values(Xt).map(t=>t.classes).concat(lg)),t=>({name:t})),dg=()=>{const t=In(),e=g.useMemo(()=>{let n=[];if(t.colors){const s=d.flattenDeep(d.map(t.colors,({items:r})=>d.keys(r)));n=d.flattenDeep(d.map(s,r=>d.flatten(d.map(hr,o=>`${o}-${r}`))))}return t.fontFamily&&(n=[...n,...d.map(d.keys(t.fontFamily),s=>`${s}`)]),d.map(n,s=>({name:s}))},[t]);return g.useMemo(()=>new Ma([...cg,...e],{isCaseSensitive:!1,threshold:.2,minMatchCharLength:2,keys:["name"]}),[e])},Rs=()=>{const t=In(),e=g.useMemo(()=>{if(t.colors){const r=d.flattenDeep(d.map(t.colors,({items:o})=>d.keys(o)));d.each(Xt,(o,i)=>{d.set(Xt,`${i}.regExp`,o.regExp.replace("__THEME_COLORS_REGEXP__",r.join("|")))})}return Xt},[t]),n=g.useCallback((r,o)=>{const i=d.get(e,`${r}.regExp`,"");return o.match(new RegExp(i))},[e]),s=g.useCallback((r,o=[])=>d.get(e,`${r}.classes`,o),[e]);return{match:n,getClasses:s}},Wl=({label:t,property:e,onChange:n})=>{const{getClasses:s}=Rs(),r=s(e),o=Dn(e),i=g.useMemo(()=>d.get(o,"cls",""),[o]),{canChange:l}=g.useContext(Mn),c=/\[.*\]/g.test(i);return a.jsx("div",{className:t?"w-full rounded":"grow",children:c?a.jsxs("div",{className:"flex items-center",children:[a.jsx(_.Input,{className:"w-[70%] rounded py-1",readOnly:!0,value:i}),a.jsxs(fe,{delayDuration:100,children:[a.jsx(he,{asChild:!0,children:a.jsx("button",{type:"button",className:"invisible ml-3 mt-1 text-blue-600 group-hover:visible",children:a.jsx(v.InfoCircledIcon,{})})}),a.jsx(ce,{children:"Current value is using a Tailwind arbitrary value."})]})]}):a.jsx(mr,{rounded:t,onChange:u=>n(u,e),selected:i,options:r,disabled:!l})})};function mr({selected:t,onChange:e,rounded:n=!1,options:s,disabled:r=!1}){const o=t.replace(/.*:/g,"").trim(),{undo:i,redo:l}=Tn();return a.jsxs("select",{disabled:!s.length||r,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"&&i(),c.key==="y"&&l())},value:o,children:[a.jsx("option",{className:"bg-transparent",value:""}),s.map((c,u)=>a.jsx("option",{className:"bg-transparent",value:c,children:c},`option-${u}`))]})}const ug={backgroundColor:"bg",textColor:"text",borderColor:"border",boxShadowColor:"shadow",outlineColor:"outline",divideColor:"divide",fromColor:"from",viaColor:"via",toColor:"to",ringColor:"ring",ringOffsetColor:"ring-offset"},pg=({property:t,onChange:e})=>{const n=Dn(t),s=g.useMemo(()=>d.get(n,"cls",""),[n]),{canChange:r}=g.useContext(Mn),[o,i]=g.useState([]),[l,c]=g.useState({color:"",shade:""}),u=s.split("-"),p=d.get(u,"1",""),f=d.get(u,"2",""),m=g.useCallback(b=>{["current","inherit","transparent","black","white"].includes(b)?(i([]),c({color:b})):(i(["50","100","200","300","400","500","600","700","800","900"]),c(y=>({...y,color:b,shade:y.shade?y.shade:"500"})))},[i,c]);g.useEffect(()=>{if(["current","inherit","transparent","black","white"].includes(p))return i([]);i(["50","100","200","300","400","500","600","700","800","900"])},[p]);const h=g.useCallback(b=>{c({color:p,shade:b})},[p]);g.useEffect(()=>{c({color:"",shade:""})},[n]);const{match:x}=Rs();return g.useEffect(()=>{const y=`${d.get(ug,t,"")}-${l.color}${l.shade?`-${l.shade}`:""}`;x(t,y)&&e(y,t)},[x,l,e,t]),a.jsxs("div",{className:"flex flex-row divide-x divide-solid divide-border rounded-lg border border-transparent text-xs",children:[a.jsx("div",{className:"grow text-center",children:a.jsx(mr,{disabled:!r,rounded:!0,selected:p,onChange:m,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"]})}),a.jsx("button",{type:"button",className:"grow text-center",children:a.jsx(mr,{rounded:!0,selected:f,disabled:!p||!r,onChange:h,options:o})})]})},Gl={"not-italic":()=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9 3H11V5H9V11H11V13H5V11H7V5H5V3H9Z",fill:"white"})}),visible:v.EyeOpenIcon,invisible:v.EyeClosedIcon,hidden:v.EyeClosedIcon,gap:v.BorderAllIcon,gapX:v.WidthIcon,gapY:v.HeightIcon,spaceX:v.WidthIcon,spaceY:v.HeightIcon,overscroll:v.BorderAllIcon,overscrollX:v.WidthIcon,overscrollY:v.HeightIcon,overflow:v.BorderAllIcon,overflowX:v.WidthIcon,overflowY:v.HeightIcon,top:v.ArrowUpIcon,right:v.ArrowRightIcon,bottom:v.ArrowDownIcon,left:v.ArrowLeftIcon,inset:v.BorderAllIcon,insetX:v.WidthIcon,insetY:v.HeightIcon,border:v.BorderAllIcon,borderX:v.WidthIcon,borderY:v.HeightIcon,borderTop:v.ArrowUpIcon,borderRight:v.ArrowRightIcon,borderBottom:v.ArrowDownIcon,borderLeft:v.ArrowLeftIcon,borderRadius:v.BorderAllIcon,borderRadiusX:v.WidthIcon,borderRadiusY:v.HeightIcon,borderRadiusTop:v.ArrowUpIcon,borderRadiusRight:v.ArrowRightIcon,borderRadiusBottom:v.ArrowDownIcon,borderRadiusLeft:v.ArrowLeftIcon,borderRadiusTopLeft:v.ArrowTopLeftIcon,borderRadiusTopRight:v.ArrowTopRightIcon,borderRadiusBottomRight:v.ArrowBottomRightIcon,borderRadiusBottomLeft:v.ArrowBottomLeftIcon,divideXWidth:v.WidthIcon,divideYWidth:v.HeightIcon,scale:v.BorderAllIcon,scaleX:v.WidthIcon,scaleY:v.HeightIcon,skewX:v.WidthIcon,skewY:v.HeightIcon,translateX:v.WidthIcon,translateY:v.HeightIcon,padding:v.BorderAllIcon,paddingX:v.WidthIcon,paddingY:v.HeightIcon,paddingTop:v.ArrowUpIcon,paddingRight:v.ArrowRightIcon,paddingBottom:v.ArrowDownIcon,paddingLeft:v.ArrowLeftIcon,margin:v.BorderAllIcon,marginX:v.WidthIcon,marginY:v.HeightIcon,marginTop:v.ArrowUpIcon,marginRight:v.ArrowRightIcon,marginBottom:v.ArrowDownIcon,marginLeft:v.ArrowLeftIcon,textLeft:v.AlignLeftIcon,textCenter:v.AlignCenterHorizontallyIcon,textRight:v.AlignRightIcon,textJustify:v.StretchHorizontallyIcon,italic:v.FontItalicIcon,underline:v.UnderlineIcon,overline:v.OverlineIcon,uppercase:v.LetterCaseUppercaseIcon,block:()=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M2 2H14V14H2V2ZM1 1H15V15H1V1Z",fill:"currentColor"}),a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7 4H4V12H7V4ZM9 4H12V12H9V4Z",fill:"currentColor"})]}),"float-right":()=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("path",{d:"M8 4H16V12H8V4Z",fill:"currentColor"}),a.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M0 4H6V6H0V4ZM0 7H6V9H0V7ZM4 10H0V12H4V10Z",fill:"currentColor"})]}),"float-left":()=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("path",{d:"M0 4H8V12H0V4Z",fill:"currentColor"}),a.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M10 4H16V6H10V4ZM10 7H16V9H10V7ZM14 10H10V12H14V10Z",fill:"currentColor"})]}),"float-none":v.Cross2Icon,fixed:()=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M15 2H14V4H13V5H14V6H15V2ZM10 5V4H9V2H1V8H2V5H10ZM7 4V3H5V4H7ZM4 4V3H2V4H4ZM1 13H7V14H1V13Z",fill:"currentColor"}),a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2H10V3H11V6H12V3H13V2H11ZM2 9H1V12H2V11H7V10H2V9ZM15 7H8V14H15V7Z",fill:"currentColor"})]}),absolute:()=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M14 2H15V6H14V2ZM9 3V2H1V8H2V3H9ZM7 13H1V14H7V13Z",fill:"currentColor"}),a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2H10V3H11V6H12V3H13V2H11ZM2 9H1V12H2V11H7V10H2V9ZM15 7H8V14H15V7Z",fill:"currentColor"})]}),relative:()=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2H9V3H11V6H12V3H14V2H11ZM2 8H1V13H2V11H7V10H2V8ZM15 7H8V14H15V7Z",fill:"currentColor"})}),sticky:()=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.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"}),a.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:v.Cross1Icon},fg=({property:t,onChange:e})=>{const{getClasses:n}=Rs(),s=n(t),{canChange:r}=g.useContext(Mn),o=Dn(t),i=g.useMemo(()=>d.get(o,"cls",""),[o]);return a.jsx("div",{className:"flex grow flex-wrap gap-1",children:d.map(s,l=>a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx("button",{type:"button",disabled:!r,onClick:()=>e(l,t),className:`cursor-pointer rounded border border-border p-1 disabled:cursor-not-allowed ${i===l?"bg-primary text-white":"disabled:bg-gray-600 disabled:text-gray-400"}`,children:g.createElement(d.get(Gl,l,v.BoxIcon))})}),a.jsx(ce,{children:d.startCase(d.toLower(l))})]}))})},hg=({property:t,onChange:e})=>{const{canReset:n,canChange:s}=g.useContext(Mn),r=Dn(t),o=g.useMemo(()=>d.get(r,"cls",""),[r]),{getClasses:i}=Rs(),l=i(t,[""]),c=l.indexOf(o)>-1?l.indexOf(o):0,u=/\[.*\]/g.test(o);return a.jsx("div",{className:"flex flex-row divide-x divide-solid divide-border rounded border border-border text-xs",children:u?a.jsx("div",{className:"px-2 py-[5px]",children:o}):a.jsxs(a.Fragment,{children:[a.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:a.jsx("span",{className:"flex items-center justify-center",children:a.jsx(v.MinusIcon,{className:!s&&(!n||c-1<0)?"text-gray-500":"text-black/60 dark:text-white/60"})})}),a.jsx("div",{className:"w-8/12 text-center",children:a.jsx(Wl,{label:!1,property:t,onChange:e})}),a.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:a.jsx("span",{className:"flex items-center justify-center",children:a.jsx(v.PlusIcon,{className:!s&&(!n||c+1>=l.length)?"text-gray-500":"text-black/60 dark:text-white/60"})})})]})})};function mg(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 gg(t){const e=d.map(Hd,s=>`${s}:`).join("|"),n=new RegExp(e,"g");return d.get(n.exec(t.trim()),0,"").replace(":","")}function xg(t){return t.trim().split(":").pop()||""}const tr={};function bg(t){if(d.isEmpty(t))return"";if(tr[t])return tr[t];let e="";for(const n in Xt){const s=d.get(Xt,`${n}.regExp`,"");if(new RegExp(s,"g").test(t)){e=n,tr[t]=e;break}}return e}function Co(t){return d.isEmpty(t)?null:{dark:d.startsWith(t,"dark:"),mq:mg(t),mod:gg(t),cls:xg(t),fullCls:t,property:bg(t)}}function yg(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 Ul(t){t=t.replace(/\s+/g," ");const e=t.split(" ").map(Co).filter(s=>s!==null),n=["xs","sm","md","lg","xl","2xl"];return e.sort((s,r)=>n.indexOf(s.mq)-n.indexOf(r.mq)).map(s=>s.fullCls).join(" ")}function ql(t){if(t=t.replace(/\s+/g," "),!t)return"";const e=["xs","sm","md","lg","xl","2xl"],n=t.split(" ").map(Co).filter(r=>r!==null);let s=t;if(n.length===1)return n[0].fullCls;for(const r of n){const o=r.property,i=e.indexOf(r.mq);for(let l=i+1;l<e.length;l++){const c=e[l],u=n.find(p=>p.property===o&&p.mq===c);if(u&&u.cls===r.cls)s=s.replace(u.fullCls,"");else if(u&&u.cls!==r.cls)break}}return s.replace(/\s+/g," ").trim()}const vg=j.atom(null,(t,e,{blockIds:n,newClasses:s})=>{const r=d.filter(t(En),i=>n.includes(t(i)._id)),o=d.first(t(Bn));return d.map(r,i=>{const l=t(i),c=d.get(l,o.prop,`${q.STYLES_KEY},`),{classes:u}=be.getSplitChaiClasses(c);return{ids:[l._id],props:{[o.prop]:`${q.STYLES_KEY},${Ul(ql(La.twMerge(u,s)))}`}}})}),Kl=()=>{const t=j.useSetAtom(vg),{updateBlocks:e,updateBlocksRuntime:n}=Ne();return g.useCallback((s,r,o=!1)=>{const i=t({blockIds:s,newClasses:r});if(!o){n(s,i[0].props);return}e(s,i[0].props)},[t,e,n])},kg=t=>{const e=["xs","sm","md","lg","xl","2xl"],n=e.indexOf(t);return n===-1?["xs"]:e.slice(0,n+1)},wg=j.atom(t=>{const e=d.first(t(Bn)),n=t(vs);if(!e||e.blockId!==d.get(n,"_id",null))return[];const s=d.get(n,e.prop,`${q.STYLES_KEY},`),{classes:r}=be.getSplitChaiClasses(s);return d.filter(d.map(r.trim().split(" "),Co),o=>!d.isNull(o))}),va={xs:0,sm:1,md:2,lg:3,xl:4,"2xl":5},Cg=j.atom(t=>{const e=t(Bl),n=t(Tr),s=t(Bi),r=kg(e);let o=d.filter(t(wg),{mod:n});return d.startsWith(n,"_")||(o=d.filter(o,i=>r.includes(i.mq))),o=o.sort((i,l)=>va[i.mq]-va[l.mq]),s||(o=d.filter(o,{dark:!1})),o}),Ps=()=>j.useAtomValue(Cg),jg=()=>j.useAtom(Tr),Dn=t=>{const e=Ps();return d.findLast(e,{property:t})},Sg=(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]},Ng={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-"},ka={xs:"",sm:"640px",md:"768px",lg:"1024px",xl:"1280px","2xl":"1536px"},Eg=t=>`${t.toUpperCase()} ${ka[t]?`(${ka[t]} & up)`:""}`,xs=t=>{const{t:e}=F.useTranslation(),{type:n="icons",label:s,property:r,onEmitChange:o=()=>{},units:i,negative:l=!1}=t,[c]=Rn(),[u]=jg(),[,p]=hs(),f=Dn(r),m=Kl(),h=wo(),[x]=U(),b=g.useMemo(()=>d.get(f,"fullCls",""),[f]),y=g.useCallback((T,N=!0)=>{const S={dark:c,mq:p,mod:u,cls:T};(c||u!=="")&&(S.mq="xs");const C=yg(S);m(x,[C],N)},[x,c,p,u,r,m]),k=g.useCallback(()=>{h(x,[b],!0)},[x,b,h]),w=g.useMemo(()=>Sg(f,p),[f,p]);g.useEffect(()=>{o(w,f)},[w,o,f]);const[,,E]=hs(),A=g.useCallback(T=>{E({xs:400,sm:640,md:800,lg:1024,xl:1420,"2xl":1920}[T])},[E]),I=d.get(f,"dark",null)===c&&d.get(f,"mod",null)===u&&d.get(f,"mq",null)===p;return a.jsx(sg,{canChange:w,canReset:f&&I,children:a.jsxs("div",{className:"group flex flex-row items-center py-2 first:pt-0 last:pb-0",children:[a.jsx("div",{className:"relative w-[70px] truncate text-xs text-foreground",children:a.jsx("span",{className:`text-[11px] ${f&&!I?"text-foreground":""}`,children:e(s)})}),a.jsxs("div",{className:"flex flex-row items-center",children:[a.jsxs("div",{className:"w-[150px]",children:[n==="arbitrary"?a.jsx(ng,{currentClass:d.get(f,"cls",""),classPrefix:d.get(Ng,r,""),units:i||[],onChange:y,negative:l,cssProperty:r}):null,n==="icons"&&a.jsx(fg,{property:r,onChange:y}),n==="range"&&a.jsx(hg,{property:r,onChange:y}),n==="color"&&a.jsx(pg,{property:r,onChange:y}),n==="dropdown"&&a.jsx(Wl,{label:s,property:r,onChange:y})]}),a.jsx("div",{className:`w-[30px] cursor-pointer ${b?"visible":"invisible"}`,children:I?a.jsx("button",{type:"button",onClick:()=>k(),title:"Reset",className:"flex px-1.5 text-xs",children:a.jsx(v.CrossCircledIcon,{className:"h-5 w-5 text-blue-500 hover:opacity-80"})}):w&&f?a.jsxs(fe,{delayDuration:100,children:[a.jsx(he,{asChild:!0,children:a.jsx("button",{type:"button",className:"invisible ml-3 mt-1 rounded-full bg-primary text-white group-hover:visible",children:a.jsx(v.InfoCircledIcon,{})})}),a.jsx(ce,{children:a.jsx("div",{className:"text-right",children:a.jsxs("div",{children:["Current style is set at ",a.jsxs("span",{className:"font-bold",children:[Eg(d.get(f,"mq")),c&&!f.dark?"(Light mode)":""]}),a.jsx("br",{}),a.jsxs("button",{type:"button",onClick:()=>A(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})]})]})})},Ag=["px","%","em","rem","ch","vh","vw"],gr=({label:t,options:e,borderB:n=!1,borderT:s=!1,type:r="arbitrary",units:o=Ag,negative:i=!1})=>{const{t:l}=F.useTranslation(),[c,u]=g.useState(e[0].key),p=Ps(),f=g.useCallback(m=>d.map(p,"property").includes(m),[p]);return a.jsxs("div",{className:`mb-2 border-border py-2 first:pt-0 last:pb-0 ${n?"border-b":""} ${s?"border-t":""}`,children:[a.jsxs("div",{className:"flex flex-row text-xs",children:[t&&a.jsx("span",{className:"relative w-[70px] flex-none text-xs text-foreground",children:l(t)}),a.jsx("div",{className:"mb-3 flex grow flex-row flex-wrap gap-x-px",children:e.map(({label:m,key:h},x)=>a.jsx("div",{className:"first:rounded-l last:rounded-r",children:a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsxs("button",{type:"button",onClick:()=>u(h),className:`relative cursor-pointer rounded-full p-1 text-[8px] ${h===c?"bg-[#3E57F0] text-white":"text-gray-600 dark:text-gray-300"}`,children:[g.createElement("div",{className:f(h)?"-bottom-1.5 absolute bg-[#3E57F0] h-[2px] left-0 w-full":""}),g.createElement(d.get(Gl,h,v.BoxIcon),{className:"text-inherit w-3 h-3"})]})}),a.jsx(ce,{children:d.startCase(d.toLower(m))})]})},`option-${x}`))})]}),a.jsx("div",{className:"mt-0 flex items-center",children:a.jsx(xs,{type:r,units:[...o],label:"",property:c,negative:i})})]})},wa=({heading:t,items:e})=>{const{t:n}=F.useTranslation(),s=Ps(),r=g.useMemo(()=>{const o=c=>d.flatten(c.map(u=>u.styleType==="multiple"?d.map(u.options,"key"):u.property)),i=d.flatten(e.map(c=>c.styleType==="accordion"?o(c.items):c.styleType==="multiple"?d.map(c.options,"key"):c.property)),l=d.map(s,"property");return d.intersection(i,l).length>0},[s,e]);return a.jsxs("details",{children:[a.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:a.jsxs("div",{className:"inline",children:[d.startCase(n(t.toLowerCase())),r?a.jsx("span",{className:`ml-1 mr-2 inline-block h-[8px] w-[8px] rounded-full ${r?"bg-primary":"bg-gray-300"}`}):null]})}),a.jsx("div",{className:"p-2",children:e.map(o=>o.styleType==="multiple"?a.jsx(gr,{...o},o.label):a.jsx(xs,{...o},o.label))})]})},Ig=g.createContext({}),nr=({section:t,showAccordian:e})=>{const{t:n}=F.useTranslation(),s=Ps(),r=g.useCallback((i=[])=>{const l={};for(let u=0;u<s.length;u++)l[s[u].property]=s[u].cls;let c=!0;for(const u in i)if(!d.has(l,u)||l[u]!==i[u]){c=!1;break}return c},[s]),o=g.useMemo(()=>({}),[]);return a.jsx(Ig.Provider,{value:o,children:e?a.jsxs(yo,{value:t.heading,className:"border-none",children:[a.jsx(vo,{className:"border-slate-150 border-t py-2 text-xs",children:a.jsx("div",{className:"flex items-center py-2",children:a.jsx("div",{className:"flex items-center gap-x-2 text-xs font-medium",children:d.startCase(n(t.heading))})})}),a.jsx(ko,{className:"py-2",children:t.items.map(i=>d.has(i,"component")?g.createElement(i.component,{key:i.label}):d.has(i,"styleType")?i.styleType==="multiple"?a.jsx(gr,{...i},i.label+"multiple-choices"):i.styleType==="accordion"&&r(i==null?void 0:i.conditions)?a.jsx(wa,{...i},i.label+"nested-options"):null:a.jsx(xs,{...i},i.label+"block-style"))})]}):a.jsx("div",{className:"py-2",children:t.items.map((i,l)=>d.has(i,"component")?g.createElement(i.component,{key:i.label}):d.has(i,"styleType")?i.styleType==="multiple"?a.jsx(gr,{...i},i.label+"multiple-choices"+l):i.styleType==="accordion"&&r(i==null?void 0:i.conditions)?a.jsx(wa,{...i},i.label+"nested-options"+l):null:a.jsx(xs,{...i},i.label+"block-style"+l))})})},Yl=bs.Root,Xl=bs.Trigger,jo=D.forwardRef(({className:t,align:e="center",sideOffset:n=4,...s},r)=>a.jsx(bs.Content,{ref:r,align:e,sideOffset:n,className:_.cn("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 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}));jo.displayName=bs.Content.displayName;const Tg=Se.atomWithStorage("selectedBreakpoints",["XS","MD","XL"]),_g=()=>{const[t,e]=j.useAtom(Tg);return[t,e]},Ca=({landscape:t=!1,className:e=""})=>a.jsx("svg",{className:ve.cn("h-3 w-3",t?"rotate-90":"",e),stroke:"currentColor",fill:"currentColor",strokeWidth:"0",viewBox:"0 0 448 512",xmlns:"http://www.w3.org/2000/svg",children:a.jsx("path",{d:"M400 0H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V48c0-26.5-21.5-48-48-48zM224 480c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm176-108c0 6.6-5.4 12-12 12H60c-6.6 0-12-5.4-12-12V60c0-6.6 5.4-12 12-12h328c6.6 0 12 5.4 12 12v312z"})}),xr=[{title:"Mobile (Base)",content:"Styles set here are applied to all screen unless edited at higher breakpoint",breakpoint:"xs",icon:a.jsx(v.MobileIcon,{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:a.jsx(v.MobileIcon,{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:a.jsx(Ca,{}),width:800},{title:"Tablet Landscape (LG)",content:"Styles set here are applied at 1024px and up unless edited at higher breakpoint",breakpoint:"lg",icon:a.jsx(Ca,{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:a.jsx(v.LaptopIcon,{className:"h-4 w-4"}),width:1420},{title:"Large Desktop (2XL)",content:"Styles set here are applied at 1536px and up",breakpoint:"2xl",icon:a.jsx(v.DesktopIcon,{className:"h-4 w-4"}),width:1920}],ja=({canvas:t=!1,openDelay:e=400,tooltip:n=!0,title:s,content:r,currentBreakpoint:o,breakpoint:i,width:l,icon:c,onClick:u,buttonClass:p="",activeButtonClass:f=""})=>{const{t:m}=F.useTranslation();return n?a.jsxs(Yl,{openDelay:e,children:[a.jsx(Xl,{asChild:!0,children:a.jsx(_.Button,{onClick:()=>u(l),size:"sm",className:ve.cn("h-7 w-7 rounded-md p-1",i===o?f:p),variant:i===o?"outline":"ghost",children:c})}),a.jsx(jo,{className:"w-fit max-w-52 border-border",children:a.jsx("div",{className:"flex justify-between space-x-4",children:a.jsxs("div",{className:"space-y-1",children:[a.jsx("h4",{className:"text-sm font-semibold",children:m(s)}),t&&a.jsx("p",{className:"text-xs",children:m(r)})]})})})]}):a.jsx(_.Button,{onClick:()=>u(l),size:"sm",className:"h-7 w-7 rounded-md p-1",variant:i===o?"outline":"ghost",children:c})},So=({openDelay:t=400,canvas:e=!1,tooltip:n=!0,buttonClass:s="",activeButtonClass:r=""})=>{const[o,,i]=hs(),[l,c]=io(),[u,p]=_g(),f=u,m=p,{t:h}=F.useTranslation(),x=$("breakpoints",xr),b=w=>{f.includes(w)?f.length>2&&m(f.filter(E=>E!==w)):m(E=>[...E,w])},y=w=>{e||i(w),c(w)},k=ve.getBreakpointValue(e?l:o).toLowerCase();return x.length<4?a.jsx("div",{className:"flex items-center rounded-md",children:d.map(x,w=>g.createElement(ja,{canvas:e,...w,onClick:y,key:w.breakpoint,currentBreakpoint:k}))}):a.jsxs("div",{className:"flex w-full items-center justify-between rounded-md",children:[a.jsx("div",{className:"flex items-center",children:d.map(x.filter(w=>d.includes(f,d.toUpper(w.breakpoint))),w=>g.createElement(ja,{canvas:e,openDelay:t,tooltip:n,...w,onClick:y,key:w.breakpoint,currentBreakpoint:k,buttonClass:s,activeButtonClass:r}))}),a.jsxs(et,{children:[a.jsx(tt,{asChild:!0,children:a.jsx("span",{className:"cursor-pointer rounded-md p-1 hover:bg-background",children:a.jsx(v.ChevronDownIcon,{className:"scale-90 transform"})})}),a.jsxs(Ge,{className:"w-56 border-border text-xs",children:[a.jsx(za,{children:h("Screen sizes")}),a.jsx(wr,{}),d.map(x,w=>a.jsx(Fa,{disabled:w.breakpoint==="xs",onCheckedChange:()=>b(d.toUpper(w.breakpoint)),checked:d.includes(f,d.toUpper(w.breakpoint)),onSelect:E=>E.preventDefault(),children:h(w.title)},w.breakpoint))]})]})]})};function Bg(){const[,t]=hs(),{t:e}=F.useTranslation(),n=g.useMemo(()=>{const s=xr.find(r=>r.breakpoint===t);return(s==null?void 0:s.content)??""},[t,xr]);return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-start bg-muted px-2 py-1 shadow-sm",children:[a.jsxs("p",{className:"text-xs text-muted-foreground",children:[e("Screen")," "]}),a.jsx(So,{openDelay:1e3,tooltip:!1})]}),a.jsx("div",{className:"mb-2 flex items-center justify-between rounded-md rounded-t-none border border-border p-1",children:a.jsx("p",{className:"flex flex-1 items-center space-x-2 text-[10px] text-foreground",children:a.jsxs("span",{className:"text-xs text-foreground",children:[a.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 Rg=vr.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),ut=D.forwardRef(({className:t,...e},n)=>a.jsx(Oa.Root,{ref:n,className:_.cn(Rg(),t),...e}));ut.displayName=Oa.Root.displayName;const br=({className:t=""})=>a.jsx(v.TokensIcon,{className:t});function No({from:t="default",classFromProps:e,onAddNew:n,onRemove:s}){var pt;const r=g.useRef(null),[o,i]=g.useState(""),[l,c]=g.useState(!1),[u,p]=g.useState(-1),f=g.useRef(!1),[,m]=Mr(),h=dg(),{t:x}=F.useTranslation(),[b]=Ee(),y=J(),k=Kl(),w=wo(),[E]=U(),[A,I]=g.useState(""),T=j.useAtomValue(en),N=(pt=d.first(b))==null?void 0:pt.prop,{classes:S}=be.getSplitChaiClasses(d.get(y,N,"")),B=(t==="default"?S:e??"").split(" ").filter(H=>!d.isEmpty(H)),P=g.useMemo(()=>[...B].sort((H,Z)=>{const Be=H.startsWith(q.DESIGN_TOKEN_PREFIX),ot=Z.startsWith(q.DESIGN_TOKEN_PREFIX);return Be&&!ot?-1:!Be&&ot?1:0}),[B]),R=$("flags.copyPaste",!0),O=H=>{if(H.startsWith(q.DESIGN_TOKEN_PREFIX)){const Z=T[H];return Z?Z.name:H}return H},z=H=>{const Z=Object.entries(T).find(([,Be])=>Be.name===H);return Z?`${Z[0]}`:H},G=()=>{const H=A.trim().replace(/ +(?= )/g,"").split(" ").map(z);t==="designToken"?d.isFunction(n)&&n(H):k(E,H,!0),I("")},[de,ue]=g.useState([]),ne=$("flags.designTokens",!0),Ae=({value:H})=>{const Z=H.trim().toLowerCase(),Be=Z.match(/.+:/g);let ot=[],Fs=[];if(ne&&(Z===""?Fs=Object.entries(T).map(([ft,dn])=>({name:dn.name,id:`${ft}`,isDesignToken:!0})):Fs=Object.entries(T).filter(([,ft])=>ft.name.toLowerCase().includes(Z)).map(([ft,dn])=>({name:dn.name,id:`${ft}`,isDesignToken:!0}))),Be&&Be.length>0){const[ft]=Be,dn=Z.replace(ft,"");ot=h.search(dn).map(zs=>({...zs,item:{...zs.item,name:ft+zs.item.name}}))}else ot=h.search(Z);const Lc=[...Fs,...d.map(ot,"item")];return ue(Lc)},Oe=()=>{ue([])},W=H=>H.name,$e=H=>a.jsxs("div",{className:"flex items-center gap-2 rounded-md p-1",children:[H.isDesignToken&&a.jsx(br,{className:"h-4 w-4 text-gray-600"}),a.jsx("span",{children:H.name})]}),vt=g.useMemo(()=>({ref:r,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,placeholder:x("Enter classes separated by space"),value:A,onFocus:H=>{setTimeout(()=>{H.target&&H.target.select()},0)},onKeyDown:H=>{if(H.key==="Enter"&&A.trim()!==""){if(f.current){f.current=!1;return}H.preventDefault(),G()}if(H.key==="Tab"&&de.length>0){H.preventDefault();const Z=new KeyboardEvent("keydown",{key:"ArrowDown",code:"ArrowDown",keyCode:40,bubbles:!0});H.target.dispatchEvent(Z)}},onChange:(H,{newValue:Z})=>I(Z),className:`w-full rounded-md text-xs px-2 hover:outline-0 bg-background border-border ${t==="default"?"py-1":"py-1.5"}`}),[A,x,r,de.length]),kt=H=>{const Z=o.trim().replace(/ +(?= )/g,"").split(" ").map(z);w(E,[H],!0),k(E,Z,!0),i(""),p(-1)},Wt=()=>{if(navigator.clipboard===void 0){pe.toast.error(x("Clipboard not supported"));return}navigator.clipboard.writeText(B.join(" ")),pe.toast.success(x("Classes copied to clipboard")),c(!0),setTimeout(()=>c(!1),2e3)};return a.jsxs("div",{className:`flex w-full flex-col gap-y-1.5 pb-4 ${t==="designToken"?"border-none":"border-b border-border"}`,children:[a.jsx("div",{className:"flex items-center justify-between gap-x-2",children:a.jsxs("div",{className:"flex w-full items-center justify-between gap-x-2 text-muted-foreground",children:[a.jsxs("span",{className:"flex items-center gap-x-1",children:[a.jsx("span",{children:t==="designToken"?a.jsx(ut,{className:"text-sm font-medium leading-tight text-gray-900 peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:x("Token Classes")}):x(ne?"Styles":"Classes")}),R&&a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:l?a.jsx(v.CheckIcon,{className:"rounded-full border border-green-500 bg-green-500/10 text-green-500"}):a.jsx(v.CopyIcon,{onClick:Wt,className:"cursor-pointer"})}),a.jsx(ce,{children:a.jsx("p",{children:x("Copy classes to clipboard")})})]})]}),ne&&t==="default"&&a.jsx(_.Button,{variant:"link",className:"underline",onClick:()=>m("design-tokens"),children:x("Design Tokens")})]})}),a.jsxs("div",{className:"relative flex items-center gap-x-3",children:[a.jsx("div",{className:"relative flex w-full items-center gap-x-3",children:a.jsx(sd,{suggestions:de,onSuggestionsFetchRequested:Ae,onSuggestionsClearRequested:Oe,getSuggestionValue:W,renderSuggestion:$e,inputProps:vt,onSuggestionSelected:(H,{suggestionValue:Z})=>{f.current=!0;const ot=[z(Z)];t==="designToken"?d.isFunction(n)&&n(ot):k(E,ot,!0),I("")},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"}})}),a.jsx(_.Button,{variant:"outline",className:`border-border ${t==="default"?"h-6":"mt-1 h-7"}`,onClick:G,disabled:A.trim()==="",size:"sm",children:a.jsx(v.PlusIcon,{})})]}),a.jsx("div",{className:"flex w-full flex-wrap gap-2 overflow-x-hidden",children:P.map((H,Z)=>u===Z?a.jsx("input",{ref:r,value:o,onChange:Be=>i(Be.target.value),onBlur:()=>{kt(H)},onKeyDown:Be=>{Be.key==="Enter"&&kt(H)},onFocus:Be=>{setTimeout(()=>{Be.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"},H):a.jsx("div",{className:"group relative flex max-w-[260px] items-center",children:a.jsxs("button",{onDoubleClick:()=>{I(O(H)),t==="default"?w(E,[H],!0):(d.isFunction(s)&&s(H),I(H)),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:[a.jsxs("div",{className:"z-10 flex h-full w-max items-center justify-center",children:[a.jsx(v.Cross2Icon,{onClick:()=>{t==="default"?w(E,[H],!0):d.isFunction(s)&&s(H)},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"}),H.startsWith(q.DESIGN_TOKEN_PREFIX)?a.jsx(br,{className:"text-[rgba(55, 65, 81, 0.4)] h-3.5 w-3.5 group-hover:hidden"}):a.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:[a.jsx("g",{id:"SVGRepo_bgCarrier",strokeWidth:"0"}),a.jsx("g",{id:"SVGRepo_tracerCarrier",strokeLinecap:"round",strokeLinejoin:"round"}),a.jsx("g",{id:"SVGRepo_iconCarrier",children:a.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"})})]})]}),a.jsx("div",{children:O(H)})]})},H))})]})}const Ce=["px","%","em","rem","ch","vh","vw"],Pg={heading:"flex.heading",items:[{type:"arbitrary",label:"flex.basis",units:Ce,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"}]},Lg={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"}]},Mg=[{heading:"Styles",items:[{component:No},{component:Bg},{type:"arbitrary",label:"layout.width",units:Ce.concat("auto"),property:"width"},{type:"arbitrary",label:"layout.height",units:Ce.concat("auto"),property:"height"},{styleType:"multiple",label:"layout.margin",negative:!0,units:[...Ce,"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:Ce},{type:"arbitrary",property:"lineHeight",label:"typography.height",units:Ce.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"}]}]}];Ce.concat("auto"),Ce.concat("auto"),[...Ce],Ce.concat("auto"),Ce.concat("auto"),Ce.concat("auto"),Ce.concat("auto"),Ce.concat("-");const Dg={px:1,"%":1,em:100,rem:100,ch:1,vw:1,vh:1,"-":1,deg:1,ms:.1};function yr(){const{flexChild:t,gridChild:e}=Id(),[n]=Ee(),[s,r]=g.useState(""),[o,i]=g.useState({onDrag:u=>u,onDragEnd:u=>u,dragStartY:0,dragging:!1,dragStartValue:0,dragUnit:"",negative:!1,cssProperty:""}),l=ke.useThrottledCallback(u=>{const p=!d.get(o,"negative",!1),f=d.get(o,"cssProperty","");let m=parseFloat(o.dragStartValue);m=isNaN(m)?0:m;let h=Dg[o.dragUnit];(d.startsWith(f,"scale")||f==="opacity")&&(h=10);let b=(o.dragStartY-u.pageY)/h+m;p&&b<0&&(b=0),f==="opacity"&&b>1&&(b=1),o.onDrag(`${b}`),r(`${b}`)},[o],50),c=g.useCallback(()=>{setTimeout(()=>o.onDragEnd(`${s}`),100),i({onDrag:u=>u,onDragEnd:u=>u,dragStartY:0,dragging:!1,dragStartValue:0,dragUnit:"",negative:!1,cssProperty:""})},[o,s,i]);return d.isEmpty(n)?null:a.jsxs(Hl.Provider,{value:{setDragData:i},children:[o.dragging?a.jsx("div",{onMouseMove:l,onMouseUp:()=>c(),className:"absolute inset-0 z-30 cursor-row-resize bg-gray-300/10"}):null,a.jsxs("div",{className:"flex flex-col",children:[a.jsx(Jm,{}),a.jsxs(Fl,{defaultValue:["Styles"],type:"multiple",className:"w-full",children:[t&&a.jsx(nr,{section:Pg,showAccordian:t||e}),e&&a.jsx(nr,{section:Lg,showAccordian:t||e}),Mg.map(u=>a.jsx(nr,{section:u,showAccordian:t||e},u.heading))]})]})]})}const Nn=D.forwardRef(({className:t,children:e,...n},s)=>a.jsxs(It.Root,{ref:s,className:_.cn("relative overflow-hidden",t),...n,children:[a.jsx(It.Viewport,{className:"h-full w-full rounded-[inherit]",children:e}),a.jsx(Jl,{}),a.jsx(It.Corner,{})]}));Nn.displayName=It.Root.displayName;const Jl=D.forwardRef(({className:t,orientation:e="vertical",...n},s)=>a.jsx(It.ScrollAreaScrollbar,{ref:s,orientation:e,className:_.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:a.jsx(It.ScrollAreaThumb,{className:"relative flex-1 rounded-full bg-border"})}));Jl.displayName=It.ScrollAreaScrollbar.displayName;const Ls=$t.Root,On=D.forwardRef(({className:t,...e},n)=>a.jsx($t.List,{ref:n,className:_.cn("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",t),...e}));On.displayName=$t.List.displayName;const He=D.forwardRef(({className:t,...e},n)=>a.jsx($t.Trigger,{ref:n,className:_.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}));He.displayName=$t.Trigger.displayName;const ct=D.forwardRef(({className:t,...e},n)=>a.jsx($t.Content,{ref:n,className:_.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}));ct.displayName=$t.Content.displayName;const Og=({block:t,disabled:e,parentId:n,position:s})=>{const{type:r,icon:o,label:i}=t,{addCoreBlock:l,addPredefinedBlock:c}=bt(),u=()=>{if(d.has(t,"blocks")){const x=d.isFunction(t.blocks)?t.blocks():t.blocks;c(X.syncBlocksWithDefaultProps(x),n||null,s)}else l(t,n||null,s);oe.publish(K.CLOSE_ADD_BLOCK)},p=Ye(),{t:f}=F.useTranslation(),{onDragStart:m,onDragEnd:h}=rn();return a.jsx(a.Fragment,{children:a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsxs("button",{disabled:e,onClick:u,type:"button",onDragStart:x=>m(x,{...t,label:i,icon:o}),onDragEnd:h,draggable:p,className:`${d.kebabCase(`chai-block-${r}`)} ${p?"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 ${e?"opacity-50":""}`,children:[g.createElement(o||v.BoxIcon,{className:"w-4 h-4 mx-auto","data-add-core-block-icon":r}),a.jsx("p",{className:"truncate text-xs",children:d.capitalize(f(i||r))})]})}),a.jsx(ce,{children:a.jsx("p",{children:f(i||r)})})]})})},Zl=({parentId:t,position:e,gridCols:n="grid-cols-2",disableBlockGroupsSidebar:s=!1})=>{const r=X.useRegisteredChaiBlocks(),o=d.groupBy(r,"category"),i=d.uniq(d.map(o.core,"group"));return a.jsx(cc,{gridCols:n,parentId:t,position:e,groups:i,blocks:o.core,disableBlockGroupsSidebar:s})},Eo=D.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:_.cn("rounded-xl border bg-card text-card-foreground shadow",t),...e}));Eo.displayName="Card";const Ao=D.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:_.cn("flex flex-col space-y-1.5 p-6",t),...e}));Ao.displayName="CardHeader";const Ql=D.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:_.cn("font-semibold leading-none tracking-tight",t),...e}));Ql.displayName="CardTitle";const ec=D.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:_.cn("text-sm text-muted-foreground",t),...e}));ec.displayName="CardDescription";const Io=D.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:_.cn("p-6 pt-0",t),...e}));Io.displayName="CardContent";const To=D.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:_.cn("flex items-center p-6 pt-0",t),...e}));To.displayName="CardFooter";const $n=D.forwardRef(({className:t,...e},n)=>a.jsx("textarea",{className:_.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 tc=({parentId:t,position:e,fromSidebar:n})=>{const{t:s}=F.useTranslation(),[r,o]=g.useState(""),{addPredefinedBlock:i}=bt(),[l,c]=g.useState(!1),u=async()=>{c(!0);const p=await _.getPreImportHTML(r),f=be.getBlocksFromHTML(p);i([...f],t,e),o(""),c(!1),oe.publish(K.CLOSE_ADD_BLOCK)};return a.jsxs(Eo,{className:`border-border/0 p-0 shadow-none ${n?"w-full":"max-w-full"}`,children:[a.jsx(Ao,{className:n?"p-0":"p-3",children:a.jsx(ec,{className:n?"text-xs":"",children:s("Use HTML snippets from Tailwind CSS component libraries")})}),a.jsx(Io,{className:`space-y-2 py-0 ${n?"p-0":"px-3"}`,children:a.jsxs("div",{className:"space-y-1",children:[a.jsx(ut,{htmlFor:"current",className:"text-sm",children:s("Tailwind HTML snippet")}),a.jsx($n,{onChange:p=>o(p.target.value),rows:12,value:r,placeholder:s("Enter your code snippet here"),className:"resize-none overflow-x-auto whitespace-pre bg-background font-mono text-xs font-normal"})]})}),a.jsx(To,{className:"flex flex-col justify-end p-3",children:a.jsx(_.Button,{disabled:r.trim()===""||l,onClick:()=>u(),size:"sm",className:"w-fit",children:l?a.jsxs(a.Fragment,{children:[a.jsx(v.CircleIcon,{className:"mr-2 h-4 w-4 animate-spin"})," ",s("Importing...")]}):s("Import HTML")})})]})},Ms=me.Root,_o=me.Value,Fn=D.forwardRef(({className:t,children:e,...n},s)=>a.jsxs(me.Trigger,{ref:s,className:_.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,a.jsx(me.Icon,{asChild:!0,children:a.jsx(v.ChevronDownIcon,{className:"h-4 w-4 opacity-50"})})]}));Fn.displayName=me.Trigger.displayName;const nc=D.forwardRef(({className:t,...e},n)=>a.jsx(me.ScrollUpButton,{ref:n,className:_.cn("flex cursor-default items-center justify-center py-1",t),...e,children:a.jsx(v.ChevronUpIcon,{className:"h-4 w-4"})}));nc.displayName=me.ScrollUpButton.displayName;const sc=D.forwardRef(({className:t,...e},n)=>a.jsx(me.ScrollDownButton,{ref:n,className:_.cn("flex cursor-default items-center justify-center py-1",t),...e,children:a.jsx(v.ChevronDownIcon,{className:"h-4 w-4"})}));sc.displayName=me.ScrollDownButton.displayName;const zn=D.forwardRef(({className:t,children:e,position:n="popper",...s},r)=>a.jsx(me.Portal,{children:a.jsxs(me.Content,{ref:r,className:_.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:[a.jsx(nc,{}),a.jsx(me.Viewport,{className:_.cn("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:e}),a.jsx(sc,{})]})}));zn.displayName=me.Content.displayName;const $g=D.forwardRef(({className:t,...e},n)=>a.jsx(me.Label,{ref:n,className:_.cn("px-2 py-1.5 text-sm font-semibold",t),...e}));$g.displayName=me.Label.displayName;const Hn=D.forwardRef(({className:t,children:e,...n},s)=>a.jsxs(me.Item,{ref:s,className:_.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:[a.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:a.jsx(me.ItemIndicator,{children:a.jsx(v.CheckIcon,{className:"h-4 w-4"})})}),a.jsx(me.ItemText,{children:e})]}));Hn.displayName=me.Item.displayName;const Fg=D.forwardRef(({className:t,...e},n)=>a.jsx(me.Separator,{ref:n,className:_.cn("-mx-1 my-1 h-px bg-muted",t),...e}));Fg.displayName=me.Separator.displayName;const zg=({defaultValue:t="",onValueChange:e,options:n,placeholder:s="Select",className:r="",height:o=""})=>{const[i,l]=g.useState(t),c=u=>{const p=u.target.value;l(p),e(p)};return a.jsx("div",{className:ve.cn("relative inline-block w-full",r),children:a.jsxs("select",{className:ve.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",o),value:i,onChange:c,children:[a.jsx("option",{value:"",disabled:!0,children:s}),n.map(u=>a.jsx("option",{value:u.value,children:u.label},u.value))]})})};function Hg({uiLibraries:t,library:e,setLibrary:n}){const{t:s}=F.useTranslation();return e?a.jsxs("div",{className:"h-12",children:[a.jsx("p",{className:"text-xs font-bold text-gray-500",children:s("Choose library")}),a.jsx(zg,{className:"mb-1",options:t.map(r=>({value:r.id,label:r.name})),defaultValue:e,onValueChange:r=>n(r)})]}):null}const rc=j.atom({}),oc=t=>{const[e,n]=j.useAtom(rc),s=g.useMemo(()=>(t==null?void 0:t.getBlocksList)||(()=>[]),[t]),r=d.get(e,`${t==null?void 0:t.id}.blocks`,null),o=d.get(e,`${t==null?void 0:t.id}.loading`,"idle"),i=d.get(e,`${t==null?void 0:t.id}.error`,!1),l=g.useRef("idle");g.useEffect(()=>{(async()=>{if(t&&!(o==="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,r,o,l,n,s]);const c=g.useCallback(u=>{n(p=>({...p,[u]:{loading:"idle",blocks:[],error:!1}}))},[n]);return{data:r||[],isLoading:o==="loading",isError:i,resetLibrary:c}},Vg=()=>j.useAtom(Hr),ac=({block:t,html:e,blocks:n,children:s,onDragStart:r,onDragEnd:o,draggable:i,className:l="",type:c="Box"})=>{const{onDragStart:u,onDragEnd:p}=rn(),f=Ye(),[,m]=U(),{clearHighlight:h}=st(),x=i!==void 0?i:f,b=async k=>{try{if(r){r(k);return}let w=null;if(c==="Image"){if(!(t!=null&&t.image))return;w={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 E=typeof e=="function"?await e():e,A=be.getBlocksFromHTML(E);if(d.isEmpty(A))return;w={type:"Box",blocks:A,name:d.get(A,"0._type","Block")}}else if(n){const E=typeof n=="function"?await n():n;if(d.isEmpty(E))return;w={type:"Box",blocks:E,name:d.get(E,"0._type","Block")}}else if(t){const E=typeof t=="function"?await t():t;w=typeof E=="object"?d.omit(E,["component","icon"]):E}if(!w)return;u(k,w,!0),setTimeout(()=>{m([]),h()},200)}catch(w){console.error("Error in ChaiDraggableBlock drag start:",w)}},y=k=>{o?o(k):p()};return a.jsx("div",{draggable:x,onDragStart:b,onDragEnd:y,className:`${x?"cursor-grab active:cursor-grabbing":""} ${l}`.trim(),children:s})};function ic({value:t,setValue:e}){const{t:n}=F.useTranslation();return a.jsx("div",{className:"flex py-2",children:a.jsxs("div",{className:"relative flex w-full max-w-md items-center rounded border px-2",children:[a.jsxs("div",{className:"flex w-full items-center gap-x-2",children:[a.jsx(v.MagnifyingGlassIcon,{className:"h-5 w-5 flex-shrink-0 stroke-[1px] text-muted-foreground"}),a.jsx(_.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&&a.jsx("button",{onClick:()=>e(""),className:"absolute right-2.5 top-2.5 text-muted-foreground hover:text-foreground",children:a.jsx(v.Cross1Icon,{className:"h-3.5 w-3.5"})})]})})}const Sa=({block:t,library:e,parentId:n=void 0,position:s=-1})=>{const[r,o]=g.useState(!1),i=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:m}=rn(),h=Ye(),x=g.useCallback(async y=>{if(y.stopPropagation(),d.has(t,"component")){l(t,n,s),oe.publish(K.CLOSE_ADD_BLOCK);return}o(!0);let k=await i({library:e,block:t});typeof k=="string"&&(k=be.getBlocksFromHTML(k)),d.isEmpty(k)||c(X.syncBlocksWithDefaultProps(k),n,s),oe.publish(K.CLOSE_ADD_BLOCK),setTimeout(()=>o(!1),1e3)},[l,c,t,i,e,n,s]),b=async y=>{if(!h)return;let k=await i({library:e,block:t});typeof k=="string"&&(k=be.getBlocksFromHTML(k)),f(y,{type:"Box",blocks:k,name:u},!0)};return a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(ac,{draggable:h,onDragStart:b,onDragEnd:m,children:a.jsxs("div",{onClick:r?()=>{}:x,className:Pa("relative mt-2 overflow-hidden rounded-md border border-border duration-200 hover:border-blue-500 hover:shadow-xl",h?"":"cursor-pointer"),children:[r&&a.jsxs("div",{className:"absolute flex h-full w-full items-center justify-center bg-black/70",children:[a.jsx(v.ReloadIcon,{className:"h-4 w-4 animate-spin text-white"}),a.jsx("span",{className:"pl-2 text-sm text-white",children:"Adding..."})]}),t.preview?a.jsx("img",{src:t.preview,className:"min-h-[45px] w-full rounded-md",alt:u}):a.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:[a.jsx("p",{className:"font-medium text-gray-800",children:u}),p&&a.jsx("p",{className:"text-sm text-gray-600",children:p})]})]})})}),a.jsx(ce,{children:a.jsx("div",{className:"max-w-xs",children:a.jsx("p",{className:"font-medium",children:u})})})]})},Wg=({parentId:t,position:e,fromSidebar:n})=>{const[s,r]=Vg(),o=_.useChaiLibraries(),i=o.find(R=>R.id===s)||d.first(o),{data:l,isLoading:c,isError:u,resetLibrary:p}=oc(i),[f,m]=g.useState(""),[h,x]=g.useState([]),b=g.useRef(null);g.useEffect(()=>{l&&Array.isArray(l)&&l.length>0&&(b.current=new Ma(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(O=>O.item);x(R)},[f]);const y=f.trim()&&!d.isEmpty(h)?h:l||[],k=d.groupBy(y,"group"),[w,E]=g.useState(null);g.useEffect(()=>{if(d.isEmpty(d.keys(k))){E(null);return}if(!w||!k[w]){E(d.first(d.keys(k))||null);return}},[k,w]);const A=d.get(k,w||"",[]),I=g.useRef(null),{t:T}=F.useTranslation(),N=g.useRef(null);g.useEffect(()=>{var O;const R=(O=N.current)==null?void 0:O.querySelector("[data-radix-scroll-area-viewport]");R&&R.scrollTo({top:0,behavior:"smooth"})},[i,w]);const S=R=>{I.current&&(clearTimeout(I.current),I.current=null),I.current=setTimeout(()=>{I.current&&E(R)},400)},C=()=>{i!=null&&i.id&&p(i.id)};if(c)return a.jsxs("div",{className:"mt-4 grid h-full w-full grid-cols-12 gap-2",children:[a.jsx(Lt,{className:"col-span-3 h-full"}),a.jsx(Lt,{className:"col-span-9 h-full"})]});const B=d.filter(A,(R,O)=>O%2===0),P=d.filter(A,(R,O)=>O%2===1);return a.jsx(a.Fragment,{children:a.jsxs("div",{className:"flex h-full max-h-full flex-col",children:[a.jsx(ic,{value:f,setValue:m}),a.jsx("div",{className:"relative flex h-full max-h-full flex-1 overflow-hidden bg-background",children:a.jsxs("div",{className:`flex h-full flex-1 pt-2 ${n?"flex-col":""}`,children:[a.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:[a.jsx(Hg,{library:i==null?void 0:i.id,setLibrary:r,uiLibraries:o}),a.jsxs("div",{className:"mt-2 flex h-full max-h-full w-full flex-1 flex-col",children:[a.jsx("span",{className:"text-xs font-bold text-gray-500",children:T("Groups")}),!n&&a.jsx("hr",{className:"mt-1 border-border"}),a.jsx("div",{className:`no-scrollbar mt-2 h-full max-h-full flex-1 overflow-y-auto ${n?"":"pb-20"}`,children:d.isEmpty(k)?a.jsx("div",{className:"mt-4 flex flex-col items-center justify-center gap-3 p-4 text-center",children:f?a.jsx("p",{className:"text-sm",children:T("No matching blocks found")}):u?a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-sm",children:T("Failed to load the UI library. Try again")}),a.jsxs(_.Button,{onClick:C,variant:"outline",size:"sm",className:"gap-2",children:[a.jsx(v.ReloadIcon,{className:"h-4 w-4"}),T("Retry")]})]}):a.jsx("p",{className:"text-sm",children:T("This library is empty")})}):n?a.jsxs(Ms,{value:w??"",onValueChange:E,children:[a.jsx(Fn,{className:"w-full",children:a.jsx(_o,{placeholder:T("Select a group")})}),a.jsx(zn,{children:d.map(k,(R,O)=>a.jsx(Hn,{value:O,children:d.capitalize(T(O.toLowerCase()))},O))})]}):d.map(k,(R,O)=>a.jsxs("div",{onMouseEnter:()=>S(O),onMouseLeave:()=>I.current&&clearTimeout(I.current),role:"button",onClick:()=>E(O),className:_.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",O===w?"bg-primary text-primary-foreground hover:bg-primary/80":""),children:[a.jsx("span",{children:d.capitalize(T(O.toLowerCase()))}),a.jsx(v.CaretRightIcon,{className:"ml-2 h-5 w-5"})]},O))})]})]}),a.jsx("div",{className:`flex h-full max-h-full w-full flex-col border-border ${n?"":"border-l"}`,children:a.jsxs(Nn,{ref:N,onMouseEnter:()=>I.current&&clearTimeout(I.current),className:"z-10 flex h-full max-h-full w-full flex-col gap-2 transition-all ease-linear",children:[d.isEmpty(A)&&!d.isEmpty(k)?a.jsx("div",{className:"flex h-full flex-col items-center justify-center p-6 text-center",children:a.jsx("p",{className:"text-sm",children:T("No blocks found in this group")})}):a.jsxs("div",{className:`grid w-full gap-2 ${n?"grid-cols-1 pb-20":"grid-cols-2 px-2"}`,children:[a.jsx("div",{className:"flex flex-col gap-1",children:B.map((R,O)=>a.jsx(Sa,{parentId:t,position:e,block:R,library:i},`block-${O}`))}),a.jsx("div",{className:"flex flex-col gap-1",children:P.map((R,O)=>a.jsx(Sa,{parentId:t,position:e,block:R,library:i},`block-second-${O}`))})]}),a.jsx("br",{}),a.jsx("br",{}),a.jsx("br",{})]})})]})})]})})},lc=({parentId:t,position:e,fromSidebar:n})=>a.jsx(Wg,{parentId:t,position:e,fromSidebar:n}),Gg=j.atom({blocks:[],groups:[],isLoading:!0,error:null}),Ug=j.atom(!1),Na=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(" ")},qg=({parentId:t,position:e,gridCols:n="grid-cols-2",disableBlockGroupsSidebar:s=!1})=>{const{data:r,isLoading:o,refetch:i,error:l}=Ei(),[c,u]=j.useAtom(Gg),[p,f]=j.useAtom(Ug);g.useEffect(()=>{if(!p||Object.keys(c.blocks).length===0)if(l)u({blocks:[],groups:[],isLoading:!1,error:l}),f(!0);else if(!o&&Object.keys(r||{}).length>0){const h=Object.entries(r).map(([b,y])=>{const k=y,w=k.type||"partial",E=Na(w);return{type:"PartialBlock",label:Na(k.name||b),description:k.description||"",icon:v.FrameIcon,group:E,category:"partial",partialBlockId:b,_name:k.name}}),x=d.uniq(d.map(h,"group"));u({blocks:h,groups:x,isLoading:!1,error:null}),f(!0)}else o?u(h=>({...h,isLoading:!0,error:null})):!o&&Object.keys(r||{}).length===0&&(u({blocks:[],groups:[],isLoading:!1,error:"No partial blocks available"}),f(!0))},[o,r,p,f,u,c.blocks,l]);const m=()=>{u(h=>({...h,isLoading:!0,error:null})),f(!1),i()};return c.isLoading?a.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?a.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 p-8 text-center text-muted-foreground",children:[a.jsx("p",{children:c.error||"No partial blocks available"}),a.jsx("button",{onClick:m,className:"rounded-md bg-primary px-3 py-1 text-sm text-primary-foreground hover:bg-primary/90",children:"Refresh"})]}):a.jsx(cc,{gridCols:n,parentId:t,position:e,groups:c.groups,blocks:c.blocks,disableBlockGroupsSidebar:s})},Ea=["basic","typography","media","layout","form","advanced","other"],cc=({groups:t,blocks:e,parentId:n,position:s,gridCols:r="grid-cols-4",disableBlockGroupsSidebar:o})=>{var P;const{t:i}=F.useTranslation(),[l]=te(),[c,u]=g.useState(""),p=g.useRef(null),[f]=j.useAtom(dc),m=(P=d.find(l,R=>R._id===n))==null?void 0:P._type,[h,x]=g.useState("all"),[b,y]=g.useState(null),k=g.useRef(null),w=$("flags.dragAndDrop",!0);g.useEffect(()=>{const R=setTimeout(()=>{var O;(O=p.current)==null||O.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 E=g.useCallback(R=>{y(R),k.current&&k.current(R)},[]),A=g.useCallback(()=>{y(null),k.current&&k.current.cancel()},[]),I=g.useCallback(R=>{k.current&&k.current.cancel(),x(R),y(null)},[]),T=g.useMemo(()=>c?d.values(e).filter(R=>{var O,z;return(((O=R.label)==null?void 0:O.toLowerCase())+" "+((z=R.type)==null?void 0:z.toLowerCase())).includes(c.toLowerCase())}):e,[e,c]),N=g.useMemo(()=>c?t.filter(R=>d.reject(d.filter(d.values(T),{group:R}),{hidden:!0}).length>0):t.filter(R=>d.reject(d.filter(d.values(e),{group:R}),{hidden:!0}).length>0),[e,T,t,c]),S=g.useMemo(()=>d.sortBy(N,R=>Ea.indexOf(R)===-1?99:Ea.indexOf(R)),[N]),C=g.useMemo(()=>h==="all"?T:d.filter(d.values(T),{group:h}),[T,h]),B=g.useMemo(()=>h==="all"?S:[h],[S,h]);return a.jsxs("div",{className:"mx-auto flex h-full w-full flex-col",children:[a.jsx(ic,{value:c,setValue:u}),a.jsxs("div",{className:"sticky top-10 flex h-[calc(100%-48px)] overflow-hidden pt-2",children:[!o&&S.length>0&&a.jsx("div",{className:"w-1/4 min-w-[120px] border-r border-border",children:a.jsx(Nn,{className:"h-full",children:a.jsxs("div",{className:"space-y-1",children:[a.jsx("button",{onClick:()=>I("all"),onMouseEnter:()=>E("all"),onMouseLeave:A,className:`w-full rounded-md px-2 py-1.5 text-left text-sm font-medium ${h==="all"||b==="all"?"bg-primary text-primary-foreground":"hover:bg-primary/50 hover:text-primary-foreground"}`,children:i("All")},"sidebar-all"),S.map(R=>a.jsx("button",{onClick:()=>I(R),onMouseEnter:()=>E(R),onMouseLeave:A,className:`w-full rounded-md px-2 py-1.5 text-left text-sm ${h===R||b===R?"bg-primary text-primary-foreground":"hover:bg-primary/50 hover:text-primary-foreground"}`,children:d.capitalize(i(R.toLowerCase()))},`sidebar-${R}`))]})})}),a.jsx("div",{className:`h-full flex-1 overflow-hidden ${!o&&S.length>0?"w-3/4":"w-full"}`,children:a.jsx(Nn,{id:"add-blocks-scroll-area",className:"no-scrollbar h-full",children:N.length===0&&c?a.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center text-muted-foreground",children:a.jsxs("p",{children:[i("No blocks found matching"),' "',c,'"']})}):a.jsx("div",{className:`${o?"p-0":"p-4"} space-y-6`,children:B.map((R,O)=>a.jsxs("div",{className:"space-y-3",children:[a.jsx("h3",{className:"px-1 text-sm font-medium",children:d.capitalize(i(R.toLowerCase()))}),a.jsx("div",{className:"grid gap-2 "+r,children:d.reject(h==="all"?d.filter(d.values(C),{group:R}):d.values(C),{hidden:!0}).map((z,G)=>a.jsx(Og,{parentId:n,position:s,block:z,disabled:!w&&(!Qe(m,z.type)||!kd(m,z.type))},z.type+"-"+O+"-"+G))})]},R))})})})]})]})},dc=Se.atomWithStorage("__add_block_tab","library"),Bo=({className:t,showHeading:e=!0,parentId:n=void 0,position:s=-1,fromSidebar:r=!1})=>{const{t:o}=F.useTranslation(),[i,l]=j.useAtom(dc),[,c]=j.useAtom(ii),u=$("flags.importHtml",!0),{data:p}=Ei(),f=Object.keys(p||{}).length>0,{hasPermission:m}=qe();g.useEffect(()=>{i==="partials"&&!f&&l("library")},[i,f,l]);const h=g.useCallback(()=>{oe.publish(K.CLOSE_ADD_BLOCK)},[]),x=_.useChaiAddBlockTabs(),b=u&&m(se.IMPORT_HTML),k=_.useChaiLibraries().length>0;return g.useEffect(()=>{i==="library"&&!k&&l("core")},[i,k,l]),a.jsxs("div",{className:ve.cn("flex h-full w-full flex-col overflow-hidden",t),children:[e?a.jsxs("div",{className:"mb-2 flex flex-col justify-between rounded-md bg-background/30 p-1",children:[a.jsx("h1",{className:"flex flex-col items-baseline px-1 text-xl font-semibold xl:flex-col",children:o("Add block")}),a.jsx("span",{className:"p-0 text-xs font-light leading-3 opacity-80 xl:pl-1",children:o(i==="html"?"Enter or paste TailwindCSS HTML snippet":"Click to add block to page")})]}):null,a.jsxs(Ls,{onValueChange:w=>{c(""),l(w)},value:i,className:"flex h-full max-h-full flex-col overflow-hidden",children:[a.jsxs(On,{className:`flex items-center ${r?"h-max w-max justify-start p-1":"w-full"}`,children:[k&&a.jsx(He,{value:"library",className:r?"h-5 px-2 text-xs":"",children:o("Library")}),a.jsx(He,{value:"core",className:r?"h-5 px-2 text-xs":"",children:o("Blocks")}),f&&a.jsx(He,{value:"partials",className:r?"h-5 px-2 text-xs":"",children:o("Partials")}),b?a.jsx(He,{value:"html",className:r?"h-5 px-2 text-xs":"",children:o("Import")}):null,d.map(x,w=>a.jsx(He,{value:w.id,className:r?"h-5 px-2 text-xs":"",children:g.createElement(w.tab)},`tab-add-block-${w.id}`))]}),a.jsx(ct,{value:"core",className:"h-full max-h-full flex-1 pb-20",children:a.jsx("div",{className:"h-full max-h-full overflow-hidden",children:a.jsx("div",{className:"h-full w-full",children:a.jsx(Zl,{gridCols:r?"grid-cols-2":"grid-cols-4",parentId:n,position:s,disableBlockGroupsSidebar:r})})})}),k&&a.jsx(ct,{value:"library",className:"h-full max-h-full flex-1 pb-20",children:a.jsx(lc,{fromSidebar:r,parentId:n,position:s})}),f&&a.jsx(ct,{value:"partials",className:"h-full max-h-full flex-1 pb-20",children:a.jsx("div",{className:"h-full max-h-full overflow-hidden",children:a.jsx("div",{className:"h-full w-full",children:a.jsx(qg,{gridCols:r?"grid-cols-2":"grid-cols-4",parentId:n,position:s,disableBlockGroupsSidebar:r})})})}),b?a.jsx(ct,{value:"html",className:"h-full max-h-full flex-1 pb-20 ",children:a.jsx(tc,{parentId:n,position:s,fromSidebar:r})}):null,d.map(x,w=>a.jsx(ct,{value:w.id,children:g.createElement(w.tabContent,{close:h,parentId:n,position:s})},`panel-add-block-${w.id}`))]})]})},Kg={display:"flex",alignItems:"center",zIndex:1},Yg=g.memo(function({top:e,left:n}){const s={position:"absolute",pointerEvents:"none",top:e+"px",left:n+"px",right:0};return a.jsx("div",{style:{...Kg,...s},children:a.jsx("div",{className:"h-0.5 flex-1 rounded-[1px] bg-green-500"})})}),Aa="h-3 w-3 flex-shrink-0",Ro=t=>{const e=X.useRegisteredChaiBlocks(),n=d.get(e,[t.type,"icon"]);return n?g.createElement(n,{className:Aa}):a.jsx(v.SquareIcon,{className:Aa})},Xg=g.memo(function({children:e,isDragging:n}){return n?a.jsx("div",{className:"pointer-events-none fixed left-0 top-0 z-[100] h-full w-full",children:e}):null}),Jg=g.memo(({id:t,isDragging:e,mouse:n})=>{const[s]=te(),r=g.useMemo(()=>s.find(i=>i._id===t),[s,t]),o=g.useMemo(()=>({transform:`translate(${(n==null?void 0:n.x)-10}px, ${(n==null?void 0:n.y)-10}px)`}),[n]);return n?a.jsx("div",{children:a.jsx(Xg,{isDragging:e,children:a.jsx("div",{className:"pointer-events-none absolute z-50 rounded border border-border bg-gray-100/80 font-semibold text-blue-600 shadow-md dark:border-gray-700 dark:bg-gray-800",style:o,children:a.jsxs("button",{type:"button",className:"flex !cursor-grab items-center p-0.5","aria-label":`Type: ${r==null?void 0:r._type}`,children:[a.jsx("div",{className:"-mt-0.5 h-3 w-3",children:a.jsx(Ro,{type:r==null?void 0:r._type})}),a.jsx("div",{className:"ml-2 truncate text-[11px]",children:(r==null?void 0:r._name)||(r==null?void 0:r._type)})]})})})}):a.jsx("div",{className:"hidden"})}),Zg=[{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 Qg(t){t.firstNode&&t.select(t.firstNode.id)}function ex(t){t.lastNode&&t.select(t.lastNode.id)}function tx(t){const e=t.selectedNodes[0].next||t.firstNode;t.select(e.id)}function nx(t){const e=t.selectedNodes[0].prev||t.lastNode;t.select(e.id)}const sx=(t,e)=>{const n=t.selectedNodes[0],s=(n==null?void 0:n.parent)||null;s&&e&&t.select(s.id)},rx=(t,e)=>{const n=t.selectedNodes[0];n.isInternal&&e&&n.open()},ox=(t,e)=>{const n=t.selectedNodes[0];n.isInternal&&e&&n.close()},Po=Pe.Root,uc=Pe.Trigger,ax=Pe.Portal,pc=D.forwardRef(({className:t,...e},n)=>a.jsx(Pe.Overlay,{className:_.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}));pc.displayName=Pe.Overlay.displayName;const Ds=D.forwardRef(({className:t,...e},n)=>a.jsxs(ax,{children:[a.jsx(pc,{}),a.jsx(Pe.Content,{ref:n,className:_.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),...e})]}));Ds.displayName=Pe.Content.displayName;const Os=({className:t,...e})=>a.jsx("div",{className:_.cn("flex flex-col space-y-2 text-center sm:text-left",t),...e});Os.displayName="AlertDialogHeader";const Lo=({className:t,...e})=>a.jsx("div",{className:_.cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...e});Lo.displayName="AlertDialogFooter";const $s=D.forwardRef(({className:t,...e},n)=>a.jsx(Pe.Title,{ref:n,className:_.cn("text-lg font-semibold",t),...e}));$s.displayName=Pe.Title.displayName;const Mo=D.forwardRef(({className:t,...e},n)=>a.jsx(Pe.Description,{ref:n,className:_.cn("text-sm text-muted-foreground",t),...e}));Mo.displayName=Pe.Description.displayName;const Do=D.forwardRef(({className:t,...e},n)=>a.jsx(Pe.Action,{ref:n,className:_.cn(_.buttonVariants(),t),...e}));Do.displayName=Pe.Action.displayName;const Oo=D.forwardRef(({className:t,...e},n)=>a.jsx(Pe.Cancel,{ref:n,className:_.cn(_.buttonVariants({variant:"outline"}),"mt-2 sm:mt-0",t),...e}));Oo.displayName=Pe.Cancel.displayName;const fc=({children:t})=>{const{t:e}=F.useTranslation(),{setNewBlocks:n}=Ne(),[,s]=U(),[,r]=Ee(),o=g.useCallback(()=>{n([]),s([]),r([])},[n]);return a.jsx("div",{className:"flex items-center",children:a.jsxs(Po,{children:[a.jsx(uc,{asChild:!0,children:t||a.jsxs(_.Button,{size:"sm",variant:"ghost",className:"flex items-center",children:[a.jsx(v.EraserIcon,{})," ",e("Clear")]})}),a.jsxs(Ds,{className:"border-border",children:[a.jsxs(Os,{children:[a.jsx($s,{className:"text-foreground",children:e("Clear whole canvas?")}),a.jsx(Mo,{children:e("Are you sure you want to clear the page?")})]}),a.jsxs(Lo,{children:[a.jsx(Oo,{className:"text-foreground",children:e("Cancel")}),a.jsx(Do,{onClick:o,children:e("Yes")})]})]})]})})},ix=()=>{const t=J(),{t:e}=F.useTranslation(),[,n]=j.useAtom(ti),s=_.useSaveToLibraryComponent(),r=()=>{t&&n({isOpen:!0,blockId:t._id})};return s?a.jsxs(le,{className:"flex items-center gap-x-4 text-xs",onClick:r,children:[a.jsx(v.CheckIcon,{className:"h-4 w-4"})," ",t!=null&&t._libBlockId?e("Update library block"):e("Save to library")]}):null},lx=()=>{const{t}=F.useTranslation(),e=J(),n=nt(),s=()=>{e&&n([e._id],{_libBlockId:null})};return a.jsxs(le,{onClick:s,className:"flex items-center gap-x-4 text-xs",children:[a.jsx(v.LinkBreak2Icon,{className:"h-4 w-4"})," ",t("Unlink from library")]})},Ia=()=>{const{t}=F.useTranslation(),[e]=U();return $("flags.exportCode",!1)?a.jsxs(le,{className:"flex items-center gap-x-4 text-xs",onClick:()=>oe.publish(K.OPEN_EXPORT_CODE,e),children:[a.jsx(v.DownloadIcon,{})," ",t("Export")]}):null},Ta=({isFromBody:t=!1})=>{const[e]=te(),[n]=U(),{pasteBlocks:s}=Kr(),[,r,o]=Ii(),{t:i}=F.useTranslation(),l=J(),c=$("flags.copyPaste",!0),u=g.useCallback(()=>{var m;const f=(t?(m=e==null?void 0:e.filter(h=>!(h!=null&&h._parent)))==null?void 0:m.map(h=>h==null?void 0:h._id):n).map(h=>{const x=e.find(b=>b._id===h);return{id:h,data:x}});o(f.map(h=>h.id))?pe.toast.warning("Partial blocks detected. Clone partial blocks?",{cancel:{label:i("No"),onClick:()=>{r(f.map(h=>h.id)),pe.toast.dismiss()}},action:{label:i("Yes"),onClick:()=>{r(f.map(h=>h.id),!0),pe.toast.dismiss()}},position:"top-center"}):r(f.map(h=>h.id))},[n,e,r,o]);return a.jsxs(a.Fragment,{children:[c&&a.jsxs(le,{disabled:!Cr(l==null?void 0:l._type),onClick:u,className:"flex items-center gap-x-4 text-xs",children:[a.jsx(v.CopyIcon,{})," ",i("Copy")]}),c&&a.jsxs(le,{className:"flex items-center gap-x-4 text-xs",onClick:()=>{s(n)},children:[a.jsx(v.CardStackIcon,{})," ",i("Paste")]})]})},cx=()=>{const[t]=U(),[,e]=Es(),{t:n}=F.useTranslation(),s=$("flags.copyPaste",!0);return a.jsx(a.Fragment,{children:s&&a.jsxs(le,{className:"flex items-center gap-x-4 text-xs",onClick:()=>e(t),children:[a.jsx(v.ScissorsIcon,{})," ",n("Cut")]})})},dx=()=>{const[t]=U(),e=Cs(),n=J(),{t:s}=F.useTranslation();return a.jsxs(le,{disabled:!jr(n==null?void 0:n._type),className:"flex items-center gap-x-4 text-xs",onClick:()=>e(t),children:[a.jsx(v.TrashIcon,{})," ",s("Remove")]})},ux=({node:t})=>{const{t:e}=F.useTranslation();return a.jsxs(le,{onClick:n=>{n.stopPropagation(),t.edit(),t.deselect()},className:"flex items-center gap-x-4 text-xs",children:[a.jsx(v.Pencil2Icon,{className:"h-4 w-4"})," ",e("Rename")]})},px=({node:t})=>{const{t:e}=F.useTranslation(),[n]=U(),s=Ur(),r=J(),{hasPermission:o}=qe(),{librarySite:i}=$("flags",{librarySite:!1}),l=Ye(),c=g.useCallback(()=>{s(n)},[n,s]),u=g.useMemo(()=>d.has(r,"_libBlockId")&&!d.isEmpty(r._libBlockId),[r==null?void 0:r._libBlockId]);return t==="BODY"?a.jsx(Ge,{side:"bottom",className:"border-border text-xs",children:o(se.ADD_BLOCK)&&a.jsxs(a.Fragment,{children:[a.jsxs(le,{disabled:!1,className:"flex items-center gap-x-4 text-xs",onClick:()=>oe.publish(K.OPEN_ADD_BLOCK,r),children:[a.jsx(v.PlusIcon,{className:"h-3.5 w-3.5"})," ",e("Add block")]}),o(se.ADD_BLOCK)&&a.jsx(Ta,{isFromBody:!0}),a.jsx(Ia,{}),a.jsx(le,{disabled:!1,onClick:p=>p.preventDefault(),className:"flex items-center gap-x-4 text-xs",children:a.jsx(fc,{children:a.jsxs("div",{className:"flex items-center gap-x-4 text-xs",children:[a.jsx(v.EraserIcon,{})," ",e("Clear canvas")]})})})]})}):a.jsxs(Ge,{side:"bottom",className:"border-border text-xs",children:[o(se.ADD_BLOCK)&&a.jsxs(a.Fragment,{children:[!l&&a.jsxs(le,{disabled:!ss(r==null?void 0:r._type),className:"flex items-center gap-x-4 text-xs",onClick:()=>oe.publish(K.OPEN_ADD_BLOCK,r),children:[a.jsx(v.PlusIcon,{className:"h-3.5 w-3.5"})," ",e("Add block")]}),a.jsxs(le,{disabled:!Cr(r==null?void 0:r._type),className:"flex items-center gap-x-4 text-xs",onClick:c,children:[a.jsx(v.CardStackPlusIcon,{})," ",e("Duplicate")]})]}),a.jsx(ux,{node:t}),o(se.MOVE_BLOCK)&&a.jsx(cx,{}),o(se.ADD_BLOCK)&&a.jsx(Ta,{}),u&&i&&a.jsx(lx,{}),o(se.CREATE_LIBRARY_BLOCK)&&i&&a.jsx(ix,{}),a.jsx(Ia,{}),o(se.DELETE_BLOCK)&&a.jsx(dx,{})]})},hc=({children:t,id:e,node:n})=>{const[,s]=U();return a.jsx(a.Fragment,{children:a.jsxs(et,{onOpenChange:r=>{r&&s([e])},children:[a.jsx(tt,{children:t}),a.jsx(px,{node:n})]})})},se={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(se);const mc=()=>{const[t]=j.useAtom(Qt),[e]=j.useAtom(Nr),[n]=j.useAtom(Er),[s]=j.useAtom(Ar),[r]=j.useAtom(Ga),[o]=j.useAtom(Ua),[i]=j.useAtom(qa);return{errors:t,isValid:e,hasErrors:n,hasWarnings:s,errorCount:r,warningCount:o,errorsByBlock:i,getBlockErrors:l=>i[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)})}},fx=({node:t})=>{var e,n;return a.jsx("input",{autoFocus:!0,className:xe("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)}})},hx=j.atom(null),sr=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())||""},mx=(t,e)=>t.length>e?t.substring(0,e)+"...":t,gx=g.memo(({node:t,style:e,dragHandle:n})=>{var Ae,Oe;const{t:s}=F.useTranslation(),r=nt(),[o]=j.useAtom(Ss),{hasPermission:i}=qe();let l=null;const c=t.children&&t.children.length>0,{highlightBlock:u,clearHighlight:p}=st(),f=Ye(),{id:m,data:h,isSelected:x,willReceiveDrop:b,isDragging:y,isEditing:k,handleClick:w}=t,E=mc(),A=g.useMemo(()=>E.getBlockErrors(m),[E,m]),I=d.get(h,"_show",!0),T=W=>{W.stopPropagation(),I&&t.toggle()},N=W=>{W.isInternal&&(l=W.isOpen,W.isOpen&&W.close())},S=W=>{W.isInternal&&l!==null&&(l?W.open():W.close(),l=null)},[C,B]=j.useAtom(hx),P=()=>{var W,$e;R(),(W=t.parent)!=null&&W.isSelected||B(($e=t==null?void 0:t.parent)==null?void 0:$e.id)},R=()=>{B(null)},O=W=>{R(),W.stopPropagation(),!t.isOpen&&I&&t.toggle(),w(W)};g.useEffect(()=>{const W=setTimeout(()=>{b&&!t.isOpen&&!y&&I&&t.toggle()},500);return()=>clearTimeout(W)},[b,t,y]);const z=(W,$e)=>{var Z;const vt=o.contentDocument||((Z=o.contentWindow)==null?void 0:Z.document),kt=vt==null?void 0:vt.querySelector(`[data-block-id=${W}]`);kt&&kt.setAttribute("data-drop",$e);const Wt=kt.getBoundingClientRect(),pt=o.getBoundingClientRect();!(Wt.top>=pt.top&&Wt.left>=pt.left&&Wt.bottom<=pt.bottom&&Wt.right<=pt.right)&&vt&&(vt.documentElement.scrollTop=kt.offsetTop-pt.top)},G=W=>{R();const $e=d.get(t,"parent.id");$e!=="__REACT_ARBORIST_INTERNAL_ROOT__"?oe.publish(K.OPEN_ADD_BLOCK,{_id:$e,position:W}):oe.publish(K.OPEN_ADD_BLOCK,{position:W})};if(m===q.ROOT_TEMP_KEY)return a.jsxs("div",{className:"group relative mt-2 w-full cursor-pointer",children:[a.jsx("br",{}),i(se.ADD_BLOCK)&&a.jsx("div",{role:"button",onClick:()=>G(-1),className:"h-1 rounded bg-primary opacity-0 duration-200 group-hover:opacity-100",children:a.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:[a.jsx(v.PlusIcon,{className:"w-2.4 h-2.5 stroke-[5] text-white"})," ",s("Add block")]})}),a.jsx("br",{})]});const{librarySite:de}=$("flags",{librarySite:!1}),ue=g.useMemo(()=>de&&d.has(h,"_libBlockId")&&!d.isEmpty(h._libBlockId)&&(i(se.CREATE_LIBRARY_BLOCK)||i(se.EDIT_LIBRARY_BLOCK)),[h,i,de]),ne=g.useMemo(()=>(h==null?void 0:h._type)==="PartialBlock"||(h==null?void 0:h._type)==="GlobalBlock",[h]);return a.jsx("div",{className:"w-full",children:a.jsxs("div",{onMouseEnter:()=>u(m),onMouseLeave:()=>p(),onClick:O,style:e,"data-node-id":m,ref:n,onDragStart:()=>N(t),onDragEnd:()=>S(t),onDragOver:W=>{W.preventDefault(),z(m,"yes")},onDragLeave:W=>{W.preventDefault(),z(m,"no")},onDrop:W=>{W.preventDefault(),z(m,"no")},children:[i(se.ADD_BLOCK)&&!f&&(t==null?void 0:t.rowIndex)!==null&&(t==null?void 0:t.rowIndex)!==void 0&&(t==null?void 0:t.rowIndex)>0&&(((Ae=t.parent)==null?void 0:Ae.isOpen)&&ss(d.get(t,"parent.data._type"))||((Oe=t==null?void 0:t.parent)==null?void 0:Oe.id)==="__REACT_ARBORIST_INTERNAL_ROOT__")&&a.jsx("div",{className:"group relative ml-5 h-full w-full cursor-pointer",children:a.jsx("div",{onClick:W=>{W.stopPropagation(),G(t.childIndex)},onMouseEnter:P,onMouseLeave:R,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:a.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:a.jsx(v.PlusIcon,{className:"h-2 w-2 stroke-[2] text-white"})})})}),a.jsxs("div",{className:xe("group flex w-full cursor-pointer items-center justify-between space-x-px !rounded p-1 py-0 outline-none",x?"bg-primary/20":"hover:bg-primary/10",b&&Qe(h._type,"Icon")?"bg-green-200":"",(t==null?void 0:t.id)===C?"bg-primary/10":"",y&&"opacity-20",I?"":"line-through opacity-50",ue&&x&&"bg-primary/20 text-primary"),children:[a.jsxs("div",{className:"flex items-center",children:[a.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:c&&a.jsx("button",{onClick:T,type:"button",children:a.jsx(v.ChevronRightIcon,{className:"h-3 w-3"})})}),a.jsxs("div",{className:xe("leading-1 flex items-center",ue&&"text-orange-600/90",ue&&x&&"text-orange-800",ne&&"text-purple-600/90",ne&&x&&"text-purple-800"),children:[A.length>0?a.jsx("div",{className:"text-red-500",children:a.jsx(v.ExclamationTriangleIcon,{className:"h-3 w-3"})}):a.jsx(Ro,{type:h==null?void 0:h._type}),k?a.jsx(fx,{node:t}):a.jsx("div",{className:"ml-1.5 flex items-center gap-x-1 truncate text-[13px]",onDoubleClick:W=>{W.stopPropagation(),t.edit(),t.deselect()},children:a.jsx("span",{title:sr(h).length>17?sr(h):"",children:mx(sr(h),17)})})]})]}),a.jsxs("div",{className:"invisible flex items-center space-x-1.5 pr-px group-hover:visible",children:[ss(h==null?void 0:h._type)&&I&&i(se.ADD_BLOCK)?a.jsxs(fe,{children:[a.jsx(he,{onClick:()=>oe.publish(K.OPEN_ADD_BLOCK,{_id:m}),className:"cursor-pointer rounded bg-transparent p-px hover:bg-primary/10",asChild:!0,children:a.jsx(v.PlusIcon,{className:"h-4 w-4"})}),a.jsx(ce,{className:"isolate z-[9999]",side:"bottom",children:s("Add block inside")})]}):null,a.jsxs(fe,{children:[a.jsx(he,{onClick:W=>{W.stopPropagation(),r([m],{_show:!I}),t.isOpen&&t.toggle()},className:"cursor-pointer rounded bg-transparent p-0.5 hover:bg-primary/10",asChild:!0,children:I?a.jsx(v.EyeClosedIcon,{className:"h-4 w-4"}):a.jsx(v.EyeOpenIcon,{className:"h-4 w-4"})}),a.jsx(ce,{className:"isolate z-[9999] text-xs",side:"bottom",children:s(I?"Hide the block from page":"Show the block on page")})]}),a.jsx(hc,{node:t,id:m,children:a.jsx("div",{className:"cursor-pointer rounded bg-transparent p-px hover:bg-primary/10",children:a.jsx(v.DotsVerticalIcon,{className:"h-3 w-3"})})})]})]})]})})}),gc=(t,e)=>{const n=d.filter(t,{_parent:e});if(n.length===0)return[];const s=[...n];return n.forEach(r=>{s.push(...gc(t,r==null?void 0:r._id))}),s},xx=()=>{const[t,e]=j.useAtom(ti),{t:n}=F.useTranslation(),[s]=te(),r=()=>e({isOpen:!1,blockId:null}),o=_.useSaveToLibraryComponent(),i=g.useMemo(()=>{if(!t.blockId)return[];const l=d.find(s,{_id:t.blockId});return l==null||delete l._parent,[l,...gc(s,l==null?void 0:l._id)]},[t.blockId,s]);return a.jsx(Pn,{open:t.isOpen,onOpenChange:l=>!l&&r(),children:a.jsxs(an,{className:"p-4 sm:max-w-[450px]",children:[a.jsx(Ln,{className:"pb-2",children:a.jsx(ln,{children:n("Save to Library")})}),o&&!d.isEmpty(t.blockId)&&a.jsx(o,{blockId:t.blockId,blocks:i,close:r})]})})},bx=({parentContext:t,setParentContext:e})=>{const{t:n}=F.useTranslation(),{canPaste:s,pasteBlocks:r}=Kr(),o=$("flags.copyPaste",!0);return g.useEffect(()=>{s("root")||e(null)},[s("root")]),!t||!s("root")||!o?null:a.jsx("div",{className:"absolute inset-0",children:a.jsxs(et,{open:!0,onOpenChange:()=>e(null),children:[a.jsx(tt,{className:"hidden"}),a.jsx(Ge,{className:"absolute w-28 p-1 text-xs",style:{top:t.y,left:t.x},children:a.jsxs(le,{className:"flex items-center gap-x-4 text-xs",onClick:()=>{r("root"),e(null)},children:[a.jsx(v.CardStackIcon,{})," ",n("Paste")]})})]})})},yx=()=>{const[t]=te();return(e,n)=>{const s=d.find(t,{_id:n});if(!s)return!1;const r=d.first(e.map(o=>{var i;return(i=d.find(t,{_id:o}))==null?void 0:i._type}));return r?Qe(s._type,r):!1}},xc=()=>{const[t]=j.useAtom(Va),[e,n]=U(),[s]=Es(),r=nt(),[,o]=Ee(),{moveBlocks:i}=Ne(),l=yx(),c=g.useRef(null),[,u]=j.useAtom(zr),{t:p}=F.useTranslation(),[f,m]=g.useState(null),h=()=>{n([]),o([])},x=g.useMemo(()=>{const N=(C,B)=>C.filter(P=>!B.includes(P._id)).map(P=>({...P,children:P.children?N(P.children,B):[]}));return[...N(t,s),{_type:q.ROOT_TEMP_KEY,_id:q.ROOT_TEMP_KEY,children:[]}]},[t,s]),b=({id:N,name:S,node:C})=>{r([N],{_name:S},C.data._name)},y=({dragIds:N,parentId:S,index:C})=>{l(N,S)&&i(N,S,C)},k=N=>{if(N.length===0)return;const S=N[0]?N[0].id:"";o([]),n([S])},w=N=>{var B;N.preventDefault(),f&&m(null);const S=N.target,C=S.getAttribute("data-node-id")||((B=S.closest("[data-node-id]"))==null?void 0:B.getAttribute("data-node-id"));C?(o([]),n([C])):(o([]),n([]),m({x:N.clientX,y:N.clientY}))},E=ke.useDebouncedCallback(({parentNode:N,dragNodes:S})=>{var C;return(N==null?void 0:N.data._type)===q.ROOT_TEMP_KEY||!Qe(N==null?void 0:N.data._type,(C=S[0])==null?void 0:C.data._type)},[],300),A=(N,S)=>{if(!N)return!0;const C={isLeaf:!S.isInternal,isClosed:!S.isOpen,isOpen:S.isOpen};try{let B=N;return Object.keys(C).forEach(P=>{const R=new RegExp(`\\b${P}\\b`,"g");B=B.replace(R,String(C[P]))}),new Function(`return ${B}`)()}catch{return console.warn("Invalid condition expression:",N),!1}},I=N=>{if(!c.current)return;const S=c.current,C=S.selectedNodes[0];if(!C)return;n([C.id]),o([]);const B=!C.isInternal,P=!C.isOpen,R=C.isOpen,O=Zg.find(z=>z.key===N.key&&(!z.when||A(z.when,C)));if(O)switch(N.preventDefault(),O.command){case"selectNext":tx(S);break;case"selectPrev":nx(S);break;case"selectParent":sx(S,B||P);break;case"close":ox(S,R);break;case"open":rx(S,P);break;case"selectFirst":Qg(S);break;case"selectLast":ex(S);break}};g.useEffect(()=>{const N=()=>{c.current&&u(c.current)};N();const S=new MutationObserver(N);return S.observe(document.body,{childList:!0,subtree:!0}),()=>S.disconnect()},[u]);const{hasPermission:T}=qe();return d.isEmpty(t)?a.jsx("div",{children:a.jsx("div",{className:"mt-10 flex h-full w-full items-center justify-center p-8",children:a.jsxs("div",{className:"flex flex-col items-center space-y-6 text-center",children:[a.jsx("div",{className:"rounded-full bg-muted p-6",children:a.jsx(v.StackIcon,{className:"h-12 w-12 text-muted-foreground"})}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("h3",{className:"text-lg font-semibold text-foreground",children:p("This page is empty")}),a.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")})]}),T(se.ADD_BLOCK)&&a.jsxs(_.Button,{onClick:()=>oe.publish(K.OPEN_ADD_BLOCK),className:"bg-primary shadow-sm hover:bg-primary/90",size:"sm",children:[a.jsx(v.PlusIcon,{className:"h-4 w-4"}),p("Add Block")]})]})})}):a.jsxs(a.Fragment,{children:[a.jsx("div",{className:ve.cn("flex h-full select-none flex-col space-y-1"),onClick:()=>h(),children:a.jsxs("div",{id:"outline-view ",className:"no-scrollbar h-full overflow-y-auto text-sm",onKeyDown:N=>{c.current&&!c.current.isEditing&&I(N)},children:[a.jsxs("div",{className:"mb-2 flex items-center justify-end gap-x-1 pb-2 text-sm text-muted-foreground",children:[a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(_.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:a.jsx(v.DoubleArrowDownIcon,{className:"h-2 w-2"})})}),a.jsx(ce,{className:"isolate z-[9999]",children:p("Expand all")})]}),a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(_.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:a.jsx(v.DoubleArrowUpIcon,{className:"h-2 w-2"})})}),a.jsx(ce,{className:"isolate z-[9999]",children:p("Collapse all")})]})]}),a.jsx("div",{className:"group relative z-30 ml-5 w-full cursor-pointer",children:a.jsx("div",{onClick:()=>oe.publish(K.OPEN_ADD_BLOCK,{position:0}),className:"h-1 w-[90%] rounded bg-primary opacity-0 duration-200 group-hover:opacity-100",children:a.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:a.jsx(v.PlusIcon,{className:"h-3 w-3 stroke-[3] text-white"})})})}),a.jsx("div",{children:a.jsx("div",{role:"treeitem","aria-level":0,"aria-selected":!0,"aria-expanded":!1,onClick:()=>n([]),className:"flex h-full items-center border-b border-transparent",children:a.jsxs("div",{className:ve.cn("group flex w-full cursor-pointer items-center justify-between space-x-px !rounded p-1 py-0 outline-none",e.length===0?"bg-primary/20":""),children:[a.jsxs("div",{className:"leading-1 flex items-center",children:[a.jsx(v.CardStackIcon,{className:"h-3 w-3 flex-shrink-0 rotate-180"}),a.jsx("div",{className:"ml-1.5 flex items-center gap-x-1 truncate text-[13px]",children:"Body"})]}),a.jsx(hc,{node:"BODY",id:"BODY",children:a.jsx("div",{className:"hidden cursor-pointer rounded bg-transparent p-px hover:bg-primary/10 group-hover:block",children:a.jsx(v.DotsVerticalIcon,{className:"h-3 w-3"})})})]})})}),a.jsx(ld.Tree,{ref:c,height:window.innerHeight-160,className:"no-scrollbar !h-full max-w-full space-y-1 !overflow-y-auto !overflow-x-hidden",rowClassName:"flex items-center h-full border-b border-transparent",selection:e[0]||"",onRename:b,openByDefault:!1,onMove:y,data:[...x],renderCursor:Yg,onSelect:k,childrenAccessor:N=>N.children,width:"100%",rowHeight:25,renderDragPreview:Jg,indent:10,onContextMenu:w,disableDrop:E,idAccessor:"_id",children:gx})]})}),a.jsx(xx,{}),a.jsx(bx,{parentContext:f,setParentContext:m})]})},Rt=D.forwardRef(({className:t,orientation:e="horizontal",decorative:n=!0,...s},r)=>a.jsx($a.Root,{ref:r,decorative:n,orientation:e,className:_.cn("shrink-0 bg-border",e==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...s}));Rt.displayName=$a.Root.displayName;const cn=D.forwardRef(({className:t,thumbClassName:e,...n},s)=>a.jsx(or.Root,{className:_.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:a.jsx(or.Thumb,{className:_.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")})}));cn.displayName=or.Root.displayName;const bc=D.forwardRef(({className:t,...e},n)=>a.jsxs(un.Root,{ref:n,className:_.cn("relative flex w-full touch-none select-none items-center",t),...e,children:[a.jsx(un.Track,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-neutral-300",children:a.jsx(un.Range,{className:"absolute h-full bg-neutral-900"})}),a.jsx(un.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"})]}));bc.displayName=un.Root.displayName;const vx=({value:t,onChange:e,disabled:n})=>{const[s,r]=g.useState(t),o=ke.useThrottledCallback(e,[t],200,!0);return a.jsx(bc,{min:0,step:1,max:50,disabled:n,value:[Number(s.replace("px",""))],onValueChange:i=>{r(i[0].toString()+"px"),o(i[0].toString())},className:"flex-1 cursor-pointer"})},kx=({value:t,onChange:e})=>{const n=d.debounce(s=>e(s),200);return a.jsx("div",{className:"relative flex h-6 w-6 cursor-pointer rounded-lg border border-border",style:{backgroundColor:t},children:a.jsx("input",{type:"color",value:t.startsWith("#")?t:"#000000",onChange:s=>{const r=s.target.value;/^#[0-9A-F]{6}$/i.test(r)&&n(r)},className:"absolute inset-0 h-full w-full cursor-pointer rounded-lg border-0 opacity-0"})})},wx=({label:t,value:e,onChange:n})=>{const s=Da.useRegisteredFonts(),{t:r}=F.useTranslation();return g.useEffect(()=>{s.some(o=>o.family===e)||n(s[0].family)},[e,n]),a.jsxs("div",{className:"space-y-0.5",children:[a.jsx(ut,{className:"mb-1 block text-xs text-gray-600",children:r(d.startCase(t))}),a.jsxs(Ms,{value:e,onValueChange:n,children:[a.jsx(Fn,{className:"h-8 w-full text-xs text-black",children:a.jsx(_o,{placeholder:r("Select font")})}),a.jsx(zn,{children:s.map(o=>a.jsx(Hn,{value:o.family,children:o.family},o.family))})]})]})},Cx={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"]}},jx={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"]}},Sx={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"]}},Nx={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"]}},Ex={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"]}},Ax=g.lazy(()=>Promise.resolve().then(()=>require("./css-import-modal-CHFZPXXQ.cjs")).then(t=>({default:t.CssImportModal}))),yc="chai-builder-previous-theme",Ix=[{shadcn_default:Cx},{twitter_theme:jx},{solarized_theme:Sx},{claude_theme:Nx},{supabase_theme:Ex}],Tx=t=>{if(!(typeof window>"u"))try{localStorage.setItem(yc,JSON.stringify(t))}catch(e){console.warn("Failed to save previous theme to localStorage:",e)}},_x=()=>{if(!(typeof window>"u"))try{localStorage.removeItem(yc)}catch(t){console.warn("Failed to clear previous theme from localStorage:",t)}},vc=D.memo(({className:t=""})=>{const[e,n]=Rn(),[s,r]=D.useState(""),[o,i]=D.useState(!1),l=$("themePresets",{}),c=$("themePanelComponent",null),{hasPermission:u}=qe(),p=$("flags.importTheme",!0),f=$("flags.darkMode",!0),m=Dr();(!l||l.length===0)&&Ix.map(S=>{l.push(S)});const[h,x]=An(),b=In(),{t:y}=F.useTranslation(),k=D.useCallback(S=>{const C={...h};Tx(C),x(S),m(),pe.toast.success("Theme updated",{action:{label:a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(v.ResetIcon,{className:"h-4 w-4"})," Undo"]}),onClick:()=>{x(C),_x(),pe.toast.dismiss()}},closeButton:!0,duration:15e3})},[h,x,m]),w=()=>{const S=l.find(C=>Object.keys(C)[0]===s);if(S){const C=Object.values(S)[0];C&&typeof C=="object"&&"fontFamily"in C&&"borderRadius"in C&&"colors"in C?(k(C),r(""),m()):console.error("Invalid preset structure:",C)}else console.error("Preset not found:",s)},E=S=>{k(S),r(""),m()},A=ke.useDebouncedCallback((S,C)=>{x(()=>({...h,fontFamily:{...h.fontFamily,[S.replace(/font-/g,"")]:C}})),m()},[h,m],200),I=D.useCallback(S=>{x(()=>({...h,borderRadius:`${S}px`})),m()},[h,m]),T=ke.useDebouncedCallback((S,C)=>{x(()=>{const B=d.get(h,`colors.${S}`);return e?d.set(B,1,C):d.set(B,0,C),m(),{...h,colors:{...h.colors,[S]:B}}})},[h,m],200),N=S=>a.jsx("div",{className:"grid grid-cols-1",children:Object.entries(S.items).map(([C])=>{const B=d.get(h,`colors.${C}.${e?1:0}`);return B?a.jsxs("div",{id:`theme-${C}`,className:"mt-1 flex items-center gap-x-2",children:[a.jsx(kx,{value:B,onChange:P=>T(C,P)}),a.jsx(ut,{className:"text-xs font-normal leading-tight",children:C.split(/(?=[A-Z])/).join(" ").replace(/-/g," ").split(" ").map(P=>P.charAt(0).toUpperCase()+P.slice(1)).join(" ")+(!C.toLowerCase().includes("foreground")&&!C.toLowerCase().includes("border")&&!C.toLowerCase().includes("input")&&!C.toLowerCase().includes("ring")&&!C.toLowerCase().includes("background")?" Background":"")})]},C):null})});return u("edit_theme")?a.jsxs("div",{className:"relative w-full",children:[a.jsxs("div",{className:ve.cn("no-scrollbar h-full w-full overflow-y-auto",t),children:[l.length>0&&a.jsxs("div",{className:"mx-0 my-2 flex flex-col gap-1 py-2",children:[a.jsxs("div",{className:"flex w-full items-center justify-between",children:[a.jsx(ut,{className:"text-sm",children:y("Presets")}),a.jsx("div",{className:"flex gap-2",children:p&&a.jsxs(_.Button,{className:"px-1",variant:"link",size:"sm",onClick:()=>i(!0),children:[a.jsx(v.UploadIcon,{className:"h-4 w-4"}),y("Import theme")]})})]}),a.jsxs("div",{className:"flex items-center gap-2 px-0",children:[a.jsx("div",{className:"w-[70%]",children:a.jsxs(Ms,{value:s,onValueChange:r,children:[a.jsx(Fn,{className:"h-9 w-full text-sm",children:a.jsx(_o,{placeholder:y("Select preset")})}),a.jsx(zn,{children:Array.isArray(l)&&l.map(S=>{const C=Object.keys(S)[0],B=C.replaceAll("_"," ");return a.jsx(Hn,{value:C,children:d.capitalize(B)},C)})})]})}),a.jsx("div",{className:"w-[25%]",children:a.jsx(_.Button,{className:"w-full text-sm",disabled:!s,onClick:w,children:y("Apply")})})]})]}),a.jsx(Rt,{}),a.jsxs("div",{className:ve.cn("my-2 space-y-3",t),children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(v.TextIcon,{className:"h-3 w-3 text-gray-600"}),a.jsx("span",{className:"text-xs font-medium text-gray-700",children:y("Typography")})]}),(b==null?void 0:b.fontFamily)&&a.jsx("div",{className:"space-y-2",children:Object.entries(b.fontFamily).map(([S,C])=>a.jsx(wx,{label:S,value:h.fontFamily[S.replace(/font-/g,"")]||C[Object.keys(C)[0]],onChange:B=>A(S,B)},S))}),a.jsx(Rt,{}),(b==null?void 0:b.borderRadius)&&a.jsxs("div",{className:"space-y-0.5",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(v.CornerTopRightIcon,{className:"h-3 w-3 text-gray-600"}),a.jsx("span",{className:"text-xs font-medium text-gray-700",children:y("Border Radius")})]}),a.jsx(_s,{variant:"secondary",className:"text-xs",children:h.borderRadius})]}),a.jsx("div",{className:"flex items-center gap-4 py-2",children:a.jsx(vx,{value:h.borderRadius,onChange:I})})]}),a.jsx(Rt,{}),(b==null?void 0:b.colors)&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(v.MixerHorizontalIcon,{className:"h-3 w-3 text-gray-600"}),a.jsx("span",{className:"text-xs font-medium text-gray-700",children:y("Colors")})]}),f&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(v.SunIcon,{className:"h-4 w-4"}),a.jsx(cn,{checked:e,onCheckedChange:S=>n(S),"aria-label":y("Toggle dark mode"),className:"mx-1"}),a.jsx(v.MoonIcon,{className:"h-4 w-4"})]})]}),a.jsx("div",{className:"space-y-2",children:b.colors.map(S=>N(S))})]}),a.jsx(g.Suspense,{fallback:a.jsx("div",{children:y("Loading...")}),children:o&&p&&a.jsx(Ax,{open:o,onOpenChange:i,onImport:E})})]}),a.jsx("br",{}),a.jsx("br",{}),a.jsx("br",{}),a.jsx("br",{})]}),c&&a.jsx("div",{className:"absolute bottom-4 w-full",children:D.createElement(c)})]}):a.jsx("div",{className:"relative w-full",children:a.jsx("div",{className:ve.cn("no-scrollbar h-full w-full overflow-y-auto text-center",t),children:a.jsx("div",{className:"mt-10 h-full items-center justify-center gap-2 text-muted-foreground",children:a.jsx("p",{className:"text-sm",children:y("You don't have permission to edit the theme. Please contact your administrator to get access.")})})})})}),Bx="Core",Rx="Import",Px="Breakpoints",Lx="Clear",Mx="Cancel",Dx="Yes",Ox="Preview",$x="Settings",Fx="Style",zx="Enter SVG code here",Hx="Remove",Vx="Choose",Wx="Cut",Gx="Copy",Ux="Paste",qx="Delete",Kx="classes",Yx="Theme",Xx="Outline",Jx="Copied",Zx="Stop",Qx="Edit",eb="Tag",tb="Value",nb="URL",sb="Images",rb="Library",ob="Blocks",ab="Basic",ib="Media",lb="Advanced",cb="Form",db="Groups",ub="Accordions",pb="Buttons",fb="Layouts",hb="FAQ",mb="Hero",gb="Features",xb="Footer",bb="Navbar",yb="Icons",vb="Testimonials",kb="Blog",wb="Saved",Cb="Unsaved",jb="Randomize",Sb="Classes",Nb="All",Eb="Undo",Ab="Redo",Ib="Duplicate",Tb="Close",_b="Selected",Bb="Select",Rb="Attributes",Pb="apply",Lb="presets",Mb="Orientation",Db="Color",Ob="Upload",$b="Apply",Fb="Back",zb="Insert",Hb="Rename",Vb="Partials",Wb="Happy",Gb="Sad",Ub="Retry",qb="Canvas is empty",Kb="Presets",Yb="No",Xb="Saving",Jb={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)"},Zb={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"},Qb="Add",ey="Save",ty="Screen",ny={"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:Bx,"Custom Blocks":"Custom Blocks","UI Library":"UI Library",Import:Rx,"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:Px,Clear:Lx,"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:Mx,Yes:Dx,Preview:Ox,Settings:$x,Styling:Fx,SVG_code:zx,"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:Hx,"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:Vx,"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:Wx,Copy:Gx,Paste:Ux,Delete:qx,"Clear Selection":"Clear Selection","This is dev mode. Visit":"This is dev mode. Visit","to see page preview":"to see page preview",classes:Kx,Theme:Yx,Outline:Xx,"Not supported":"Not supported","Please use Chrome, Firefox or Safari":"Please use Chrome, Firefox or Safari","Download Complete":"Download complete",Copied:Jx,"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:Zx,"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:Qx,"Describe this page. E.g.: This page is about...":"Describe this page. E.g.: This page is about...",Tag:eb,Value:tb,"Background Image":"Background Image","Enter image URL":"Enter image URL","Enter URL":"Enter URL",URL:nb,"Replace image":"Replace image","Choose image":"Choose image",Images:sb,Library:rb,Blocks:ob,Basic:ab,Media:ib,Advanced:lb,Form:cb,"Choose Icon or SVG":"Choose an icon or enter SVG",Groups:db,"UI Libraries":"UI Libraries",Accordions:ub,Buttons:pb,Layouts:fb,"Choose Library":"Choose library","No Library Found":"No library found.",FAQ:hb,Hero:mb,Features:gb,Footer:xb,Navbar:bb,Icons:yb,Testimonials:vb,Blog:kb,"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:wb,Unsaved:Cb,"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:jb,"Randomize all text elements.":"Randomize all text elements.","Edit Block":"Edit Block","AI Assistant":"AI Assistant","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:Sb,All:Nb,"Enter classes separated by space":"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:Eb,Redo:Ab,Duplicate:Ib,"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:Tb,"Coming soon":"Coming soon",Selected:_b,Select:Bb,"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:Rb,"Apply Presets":"Apply Presets",apply:Pb,presets:Lb,"Global presets":"Global presets",Orientation:Mb,Color:Db,"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:Ob,"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:$b,Back:Fb,Insert:zb,Rename:Hb,"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:Vb,Happy:Wb,Sad:Gb,"Importing...":"Importing...","Failed to load the UI library. Try again":"Failed to load the UI library. Try again",Retry:Ub,"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:qb,Presets:Kb,"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:Yb,Saving:Xb,"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:Jb,web_blocks:Zb,"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:Qb,Save:ey,Screen:ty};gt.use(F.initReactI18next).init({resources:{en:{translation:ny}},lng:"en",fallbackLng:"en",interpolation:{escapeValue:!1}});function sy(t,e,n){n.push(d.find(t,{_id:e}));const s=d.filter(t,{_parent:e});for(const r of s)n.push(...kc(r._id,t));return n}const kc=(t,e)=>{let n=[];return n=d.flattenDeep([...n,...sy(e,t,n)]),n},ry=(t,e,n)=>d.compact(t.map(s=>{const r=["_id","_type","_parent"],o=d.pick(s,r),i=X.getRegisteredChaiBlock(s._type),l={},c=d.get(i,"aiProps",[]);for(const u in s)if(!r.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(o,"_parent")&&d.isEmpty(o._parent)&&delete o._parent,{...o,...l})})),oy=(t,e,n)=>!e||n!=="content"?t:`${t}. Generate content in ${d.get(Ot,e,e)} language.`,ay=j.atom(!1),wc=()=>{const[t,e]=j.useAtom(ay),[n,s]=g.useState(null),r=$("askAiCallBack",d.noop),o=Qa(),i=Bd(),[l]=te(),{selectedLang:c,fallbackLang:u}=Te(),p=c.length?c:u,f=(m,h)=>{const x=d.cloneDeep(h.find(b=>b._id===m));for(const b in x){const y=x[b];if(typeof y=="string"&&d.startsWith(y,q.STYLES_KEY)){const{baseClasses:k,classes:w}=be.getSplitChaiClasses(y);x[b]=d.compact(d.flattenDeep([k,w])).join(" ")}else b!=="_id"&&delete x[b]}return x};return{askAi:g.useCallback(async(m,h,x,b)=>{if(r){e(!0),s(null);try{const y=c===u?"":c,k=x.toLowerCase().includes("translate the content"),w=m==="content"?ry(d.cloneDeep(kc(h,l)),c,k):[f(h,l)],E=await r(m,oy(x,p,m),w,y);if(E===void 0)return;const{blocks:A,error:I}=E;if(I){s(I);return}if(m==="styles"){const T=A.map(N=>{for(const S in N)S!=="_id"&&(N[S]=`${q.STYLES_KEY},${N[S]}`);return N});i(T)}else o(A);b&&b(E)}catch(y){s(y)}finally{e(!1),b&&b()}}},[r,e,c,u,l,p,i,o]),loading:t,error:n}};function iy({onClick:t}){const{loading:e}=wc(),{t:n}=F.useTranslation(),{selectedLang:s,fallbackLang:r}=Te(),i=[...[{name:n("Improve writing"),icon:v.Pencil2Icon,prompt:n("Improving writing in all text elements. Replacing placeholder content with meaningful relevant content.")},{name:n("Replace placeholder content"),icon:v.LoopIcon,prompt:n("Discard current placeholder content and replace with meaningful relevant content.")},{name:n("Fix grammar"),icon:v.CheckIcon,prompt:n("Fix grammar in all text elements. Ensuring the text is grammatically correct and free of errors.")},{name:n("Make longer"),icon:v.ArrowUpIcon,prompt:n("Make all text elements longer.")},{name:n("Make shorter"),icon:v.ArrowDownIcon,prompt:n("Make all text elements shorter.")},{name:n("Add emojis"),icon:v.FaceIcon,prompt:n("Add emojis to text elements if relevant.")},{name:n("Randomize"),icon:v.ShuffleIcon,prompt:n("Randomize all text elements.")}]];return s&&s!==r&&i.splice(0,0,{name:n("Translate to {{lang}}",{lang:d.get(Ot,s,s)}),icon:v.ChatBubbleIcon,prompt:n("Translate the content to {{lang}}. Maintain same tone, style and length.",{lang:d.get(Ot,s,s)})}),a.jsx("div",{className:e?"pointer-events-none opacity-50":"",children:a.jsx("ul",{className:"space-y-1",children:i.map(({name:l,icon:c,subMenus:u,prompt:p})=>u?a.jsxs(mo,{children:[a.jsx(go,{asChild:!0,children:a.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:[a.jsx(c,{className:"h-4 w-4"}),a.jsx("span",{children:l})]},l)}),a.jsx(Bs,{side:"right",children:a.jsx("ul",{children:a.jsx("li",{children:n("Happy")})})})]}):a.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:[a.jsx(c,{className:"h-3.5 w-3.5"}),a.jsx("span",{children:n(l)})]},l))})})}const Cc=({blockId:t})=>{const{t:e}=F.useTranslation(),{askAi:n,loading:s,error:r}=wc(),[o,i]=g.useState(""),l=g.useRef(null),c=g.useRef(null),u=J();g.useEffect(()=>{var f;(f=l.current)==null||f.focus()},[]);const p=()=>{r||i("")};return a.jsx("div",{className:"",children:t?a.jsxs("div",{className:"",children:[a.jsx("label",{className:"text-xs font-medium text-gray-500",children:e("Selected block")}),u&&a.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:[a.jsx(Ro,{type:u._type})," ",a.jsx("p",{className:"truncate whitespace-nowrap leading-none",children:u._name||u._type})]}),a.jsx("br",{}),a.jsx("label",{className:"text-xs font-medium text-gray-500",children:e("Quick actions")}),a.jsx("div",{className:"rounded border p-2 text-sm",children:a.jsx(iy,{onClick:f=>{c.current&&clearTimeout(c.current),n("content",t,f,p)}})}),a.jsx("br",{}),a.jsx("label",{className:"text-xs font-medium text-gray-500",children:e("Ask AI")}),a.jsxs("div",{className:"rounded border p-2 text-xs focus-within:border-gray-300",children:[a.jsx($n,{ref:l,value:o,onChange:f=>i(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,o,p))}}),a.jsxs("div",{className:"flex items-center justify-end",children:[s&&a.jsx(_.Button,{variant:"destructive",onClick:()=>stop(),className:"hidden h-4 w-4",size:"icon",children:a.jsx(v.StopIcon,{className:"h-4 w-4"})}),a.jsx(_.Button,{onClick:()=>{c.current&&clearTimeout(c.current),n("content",t,o,p)},variant:"default",className:"h-7 w-7",disabled:s||o.trim().length<1,size:"icon",children:s?a.jsx(v.ReloadIcon,{className:"h-4 w-4 animate-spin"}):a.jsx(v.ArrowTopRightIcon,{className:"h-4 w-4"})})]})]}),a.jsx("div",{className:"max-w-full pt-2",children:r&&a.jsx("p",{className:"break-words rounded border border-red-500 bg-red-100 p-1 text-xs text-red-500",children:r.message})})]}):a.jsx("div",{className:"p-4 text-center",children:a.jsxs("div",{className:"space-y-4 rounded-xl p-4 text-muted-foreground",children:[a.jsx(kr,{className:"mx-auto h-7 w-7 text-muted-foreground"}),a.jsx("h1",{children:e("Please select a block to Ask AI")})]})})})},jc=()=>{const[t]=U();return a.jsx("div",{className:"no-scrollbar mt-2 flex-1 overflow-y-auto",children:a.jsx(Cc,{blockId:d.first(t)})})};function Sc(){const[t,e]=Rn();return a.jsxs("div",{className:"flex items-center",children:[t?a.jsx(v.MoonIcon,{className:"size-4 shrink-0"}):a.jsx(v.SunIcon,{className:"size-4 shrink-0"}),a.jsx(cn,{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:a.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 Nc=()=>{const{hasUndo:t,hasRedo:e,undo:n,redo:s}=Tn();return a.jsxs("div",{className:"flex items-center",children:[a.jsx(_.Button,{disabled:!t(),size:"sm",onClick:n,className:"rounded-full",variant:"ghost",children:a.jsx(v.ResetIcon,{})}),a.jsx(_.Button,{disabled:!e(),onClick:s,size:"sm",className:"rounded-full",variant:"ghost",children:a.jsx(v.ResetIcon,{className:"rotate-180 scale-y-[-1] transform"})})]})},Ec=ie.Root,ly=ie.Trigger,cy=ie.Portal,Ac=D.forwardRef(({className:t,...e},n)=>a.jsx(ie.Overlay,{className:_.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}));Ac.displayName=ie.Overlay.displayName;const dy=vr.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"}}),$o=D.forwardRef(({side:t="right",className:e,children:n,...s},r)=>a.jsxs(cy,{children:[a.jsx(Ac,{}),a.jsxs(ie.Content,{ref:r,className:_.cn(dy({side:t}),e),...s,children:[a.jsxs(ie.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:[a.jsx(v.Cross1Icon,{className:"h-4 w-4"}),a.jsx("span",{className:"sr-only",children:"Close"})]}),n]})]}));$o.displayName=ie.Content.displayName;const Fo=({className:t,...e})=>a.jsx("div",{className:_.cn("flex flex-col space-y-2 text-center sm:text-left",t),...e});Fo.displayName="SheetHeader";const zo=D.forwardRef(({className:t,...e},n)=>a.jsx(ie.Title,{ref:n,className:_.cn("text-lg font-semibold text-foreground",t),...e}));zo.displayName=ie.Title.displayName;const Ic=D.forwardRef(({className:t,...e},n)=>a.jsx(ie.Description,{ref:n,className:_.cn("text-sm text-muted-foreground",t),...e}));Ic.displayName=ie.Description.displayName;const Tc=()=>{const{t}=F.useTranslation(),[e,n]=g.useState(null),[s,r]=g.useState(-1),[o,i]=g.useState(!1),l=Ye(),[,c]=Ns();return Yt(K.OPEN_ADD_BLOCK,u=>{l?c("add-block"):(n(u?u._id:null),r((u==null?void 0:u.position)??-1),i(!0))}),Yt(K.CLOSE_ADD_BLOCK,()=>{n(null),r(-1),i(!1)}),a.jsx(Po,{open:o,onOpenChange:()=>o?i(!1):"",children:a.jsxs(Ds,{className:"max-w-5xl overflow-hidden border-border",children:[a.jsxs(Os,{className:"flex flex-row items-center justify-between",children:[a.jsx($s,{className:"text-foreground",children:t("Add blocks")}),a.jsx("button",{onClick:()=>i(!1),className:"text-gray-500 hover:text-gray-600 dark:text-gray-400 dark:hover:text-gray-300",children:a.jsx(v.Cross2Icon,{className:"h-6 w-6"})})]}),a.jsx("div",{className:"no-scrollbar h-[500px] max-h-full overflow-hidden",children:a.jsx(Bo,{parentId:e??"",position:s,showHeading:!1})})]})})},uy=g.memo(function({preloadedAttributes:e=[],onAttributesChange:n}){const[s,r]=g.useState([]),[o,i]=g.useState(""),[l,c]=g.useState(""),[u,p]=g.useState(null),[f,m]=g.useState(""),h=g.useRef(null),x=g.useRef(null),b=tn(),{t:y}=F.useTranslation();g.useEffect(()=>{r(e)},[e]);const k=()=>{if(o.startsWith("@")){m(y("Attribute keys cannot start with @"));return}if(o){const N=[...s,{key:o,value:l}];n==null||n(N),r(s),i(""),c(""),m("")}},w=N=>{const S=s.filter((C,B)=>B!==N);n==null||n(S),r(S)},E=N=>{p(N),i(s[N].key),c(s[N].value)},A=()=>{if(o.startsWith("@")){m(y("Attribute keys cannot start with @"));return}if(u!==null&&o){const N=[...s];N[u]={key:o,value:l},n==null||n(N),r(N),p(null),i(""),c(""),m("")}},I=N=>{N.key==="Enter"&&!N.shiftKey&&(N.preventDefault(),u!==null?A():k())},T=g.useCallback(N=>{const S=P=>/[.,!?;:]/.test(P),C=(P,R,O)=>{let z="",G="";const de=R>0?P[R-1]:"",ue=R<P.length?P[R]:"";return R>0&&(de==="."||!S(de)&&de!==" ")&&(z=" "),R<P.length&&!S(ue)&&ue!==" "&&(G=" "),{text:z+O+G,prefixLength:z.length,suffixLength:G.length}},B=x.current;if(B){const P=B.selectionStart||0,R=B.value||"",O=B.selectionEnd||P;if(O>P){const ne=`{{${N}}}`,{text:Ae}=C(R,P,ne),Oe=R.slice(0,P)+Ae+R.slice(O);c(Oe);return}const G=`{{${N}}}`,{text:de}=C(R,P,G),ue=R.slice(0,P)+de+R.slice(P);c(ue)}},[]);return a.jsxs("div",{className:"flex max-h-full flex-1 flex-col",children:[a.jsxs("form",{onSubmit:N=>{N.preventDefault(),u!==null?A():k()},className:"space-y-3",children:[a.jsxs("div",{className:"flex flex-col gap-y-1",children:[a.jsxs("div",{className:"w-full",children:[a.jsx(ut,{htmlFor:"attrKey",className:"text-[11px] font-normal leading-tight text-slate-600",children:y("Key")}),a.jsx(_.Input,{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",id:"attrKey",ref:h,value:o,onChange:N=>i(N.target.value),placeholder:y("Enter key"),className:"py-0 text-xs font-normal leading-tight placeholder:text-slate-400"})]}),a.jsxs("div",{className:"w-full",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx(ut,{htmlFor:"attrValue",className:"text-[11px] font-normal text-slate-600",children:y("Value")}),!d.isEmpty(b)&&a.jsx(xo,{data:b,onSelect:T})]}),a.jsx($n,{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",id:"attrValue",ref:x,value:l,onChange:N=>c(N.target.value),onKeyDown:I,placeholder:y("Enter value"),className:"text-xs font-normal leading-tight placeholder:text-slate-400"})]})]}),a.jsx("div",{className:"flex justify-end",children:a.jsx(_.Button,{type:"submit",disabled:!o.length,variant:"default",size:"sm",className:"h-8 w-24 text-xs",children:y(u!==null?"Save":"Add")})}),f&&a.jsx("p",{className:"text-xs text-red-500",children:f})]}),a.jsx("div",{className:"space-y-1 py-4",children:s.map((N,S)=>a.jsxs("div",{className:"flex items-center justify-between rounded border p-2 text-sm",children:[a.jsxs("div",{className:"flex flex-col text-xs leading-tight",children:[a.jsx("span",{className:"truncate text-[12px] font-light text-muted-foreground",children:N.key}),a.jsx("span",{className:"max-w-[200px] text-wrap font-normal",children:N.value.toString()})]}),a.jsxs("div",{className:"flex-shrink-0 text-slate-400",children:[a.jsx(_.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>E(S),children:a.jsx(v.Pencil2Icon,{className:"h-3 w-3"})}),a.jsx(_.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>w(S),children:a.jsx(v.Cross1Icon,{className:"h-3 w-3"})})]})]},S))})]})}),_c=D.memo(()=>{const t=J(),[e,n]=g.useState([]),[s]=Ee(),r=nt(),o=`${d.get(s,"0.prop")}_attrs`;D.useEffect(()=>{const l=d.map(d.get(t,o),(c,u)=>({key:u,value:c}));d.isEmpty(l)?n([]):n(l)},[d.get(t,o)]);const i=D.useCallback((l=[])=>{if(!t)return;const c={};d.forEach(l,u=>{d.isEmpty(u.key)||d.set(c,u.key,u.value)}),r([d.get(t,"_id")],{[o]:c})},[t,r,o]);return a.jsx("div",{className:"flex-col gap-y-2",children:a.jsx("div",{className:"flex flex-col",children:a.jsx("div",{children:a.jsx(uy,{preloadedAttributes:e,onAttributesChange:i})})})})}),py=()=>{const[t]=Tl();return a.jsxs("div",{className:"flex w-12 cursor-not-allowed items-center justify-center gap-x-1 space-x-0 font-medium text-gray-400",children:[a.jsx(v.ZoomInIcon,{className:"h-3.5 w-3.5 flex-shrink-0"})," ",a.jsxs("div",{className:"text-xs leading-3",children:[d.round(t,0),"%"]})]})},fy=()=>{const{hasErrors:t,hasWarnings:e,errorCount:n,warningCount:s,errors:r}=mc(),[,o]=U(),{t:i}=F.useTranslation();if(!t&&!e)return null;const l=()=>t?"text-red-500":e?"text-orange-500":"text-gray-500",c=()=>t?a.jsx(v.ExclamationTriangleIcon,{className:"h-4 w-4"}):e?a.jsx(v.InfoCircledIcon,{className:"h-4 w-4"}):null,u=()=>t&&e?`${n} error${n>1?"s":""}, ${s} warning${s>1?"s":""}`:t?`${n} error${n>1?"s":""}`:e?`${s} warning${s>1?"s":""}`:"";return a.jsxs(et,{children:[a.jsx(tt,{asChild:!0,children:a.jsxs("div",{className:`ml-2 flex cursor-pointer items-center gap-2 ${l()}`,children:[c(),a.jsx("span",{className:"text-xs font-medium",children:u()})]})}),a.jsx(Ge,{side:"bottom",className:"max-w-xs p-2",align:"end",children:a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-semibold",children:i("Invalid structure")}),r.length===0?a.jsx("p",{className:"text-xs",children:i("No validation issues found.")}):a.jsxs("div",{className:"space-y-1",children:[r.slice(0,5).map(p=>a.jsxs("div",{onClick:()=>{p.blockId&&o([p.blockId])},className:`cursor-pointer rounded p-2 text-xs transition-opacity hover:opacity-80 ${p.severity==="error"?"border border-red-200 bg-red-50 text-red-700":"border border-orange-200 bg-orange-50 text-orange-700"}`,children:[a.jsx("div",{className:"font-medium",children:p.severity==="error"?"Error:":"Warning:"}),a.jsx("div",{children:p.message})]},p.id)),r.length>5&&a.jsxs("p",{className:"text-xs italic text-gray-500",children:["... and ",r.length-5," more issues"]})]})]})})]})},hy=()=>{const t=$("flags.darkMode",!0),e=$("flags.dataBinding",!0),[n,s]=j.useAtom(Vr),{t:r}=F.useTranslation(),o=t,i=e;return a.jsxs("div",{className:"flex h-10 items-center justify-between border-b border-border bg-background/70 px-2 shadow-xl",children:[a.jsx("div",{className:"flex h-full space-x-2",children:o?a.jsx(Sc,{}):null}),a.jsxs("div",{className:"flex h-full items-center space-x-2",children:[a.jsx(So,{canvas:!0,openDelay:400}),a.jsx(Rt,{orientation:"vertical"}),a.jsx(py,{}),a.jsx(Rt,{orientation:"vertical"}),a.jsx(Nc,{})]}),a.jsxs("div",{className:"flex h-full items-center",children:[i?a.jsxs(et,{children:[a.jsx(tt,{asChild:!0,children:a.jsx(_.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 rounded-md p-1",children:a.jsx(v.DotsHorizontalIcon,{className:"h-4 w-4"})})}),a.jsx(Ge,{className:"w-56 border-border text-xs",children:a.jsxs(le,{className:"flex items-center gap-2",onSelect:l=>l.preventDefault(),children:[a.jsx(v.LightningBoltIcon,{className:"h-4 w-4 text-gray-500"}),a.jsx("span",{className:"flex-1",children:r("Data Binding")}),a.jsx(cn,{checked:n,onCheckedChange:()=>s(!n)})]})})]}):null,a.jsx(fy,{}),a.jsx(fc,{})]})]})},Gt=()=>null,_a=()=>{const{resetAll:t}=zl(),e=J(),[n]=Ee(),s=Xm(),{t:r}=F.useTranslation();return!e||d.isEmpty(n)?null:a.jsxs(et,{children:[a.jsx(tt,{asChild:!0,children:a.jsx("div",{className:"inline-flex rounded-sm p-0.5 hover:bg-gray-300",onClick:o=>o.stopPropagation(),children:a.jsx(v.DotsVerticalIcon,{className:"h-3 w-3"})})}),a.jsxs(Ge,{side:"bottom",className:"border-border text-xs",children:[a.jsxs(le,{className:"flex items-center gap-1 text-xs",onClick:()=>{t()},children:[a.jsx(v.ResetIcon,{className:"h-3 w-3"}),r("Reset styles")]}),a.jsxs(le,{className:"text-xs",onClick:()=>{e&&s(e,!0)},children:[a.jsx(v.Cross2Icon,{className:"h-3 w-3"}),r("Clear styles")]})]})]})};function Ba(){const{t}=F.useTranslation(),[e,n]=g.useState(!0),[s]=Ee();return d.isEmpty(s)?null:a.jsxs(a.Fragment,{children:[a.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:[a.jsx("span",{children:t("Attributes")}),a.jsx("span",{children:a.jsx(v.ChevronDownIcon,{className:"h-4 w-4 text-gray-500 "+(e?"rotate-180":"")})})]}),e&&a.jsx(_c,{})]})}const my=({partialBlockId:t})=>{const e=$("gotoPage",d.noop),{saveState:n}=nn(),{selectedLang:s,fallbackLang:r}=Te(),o=g.useCallback(i=>{if(i.stopPropagation(),n!=="SAVED"){pe.toast.error("You have unsaved changes. Please save the page first.");return}e({pageId:t,lang:s||r})},[n,e,t,s,r]);return a.jsx(a.Fragment,{children:a.jsx("div",{className:"hidden",children:a.jsx("div",{onDoubleClick:o,className:"h-full w-full items-center justify-center",children:a.jsx("p",{className:"rounded-md bg-white px-2 py-1 text-xs",children:"Partial block. Double click to edit."})})})})},gy=()=>{const t=J(),{t:e}=F.useTranslation(),n=$("onError",d.noop),{hasPermission:s}=qe();let r=!s(se.EDIT_BLOCK);const o=!s(se.EDIT_STYLES),[i,l]=ri();if(t&&t._type==="PartialBlock")return a.jsx(my,{partialBlockId:t.partialBlockId});if(d.isNull(t))return a.jsx("div",{className:"p-4 text-center",children:a.jsxs("div",{className:"space-y-4 rounded-xl p-4 text-muted-foreground",children:[a.jsx(v.MixerHorizontalIcon,{className:"mx-auto text-3xl"}),a.jsx("h1",{children:e("Please select a block to edit settings or styles")})]})});if(r&&o)return a.jsx("div",{className:"p-4 text-center",children:a.jsxs("div",{className:"space-y-4 rounded-xl p-4 text-muted-foreground",children:[a.jsx(v.MixerHorizontalIcon,{className:"mx-auto text-3xl"}),a.jsx("h1",{children:e("You don't have permission to edit settings or styles")}),a.jsx("p",{children:e("Please contact your administrator to get access")})]})});if(o)return a.jsx(At.ErrorBoundary,{fallback:a.jsx(yn,{}),onError:n,children:a.jsxs("div",{className:"no-scrollbar h-full max-h-min w-full overflow-y-auto",children:[a.jsx(fr,{},t==null?void 0:t._id),a.jsx("br",{}),a.jsx("br",{})]})});if(r)return a.jsx(At.ErrorBoundary,{fallback:a.jsx(yn,{}),onError:n,children:a.jsxs("div",{className:"no-scrollbar h-full max-h-min w-full overflow-y-auto overflow-x-hidden",children:[a.jsx("div",{className:"flex w-full items-center justify-end",children:a.jsx(_a,{})}),a.jsx(yr,{}),a.jsx(Ba,{}),a.jsx("br",{}),a.jsx("br",{}),a.jsx("br",{})]})});const u=p=>{(p==="settings"||p==="styles")&&l(p)};return a.jsx(At.ErrorBoundary,{fallback:a.jsx(yn,{}),onError:n,children:a.jsxs(Ls,{value:i,onValueChange:u,className:"flex flex-1 flex-col",children:[a.jsx("div",{className:"flex items-center justify-between",children:a.jsxs(On,{className:"grid h-auto w-full grid-cols-2 p-1 py-1",children:[a.jsx(He,{value:"settings",className:"text-xs",children:e("Settings")}),a.jsx(He,{value:"styles",className:"text-xs",children:a.jsxs("div",{className:"flex w-full items-center justify-between",children:[a.jsx("span",{className:"w-[90%] text-center",children:e("Styling")}),a.jsx("span",{className:"w-[10%]",children:a.jsx(_a,{})})]})})]})}),a.jsxs(ct,{value:"settings",className:"no-scrollbar h-full max-h-min overflow-y-auto",children:[a.jsx(fr,{},t==null?void 0:t._id),a.jsx("br",{}),a.jsx("br",{})]}),a.jsxs(ct,{value:"styles",className:"no-scrollbar h-full max-h-min max-w-full overflow-y-auto overflow-x-hidden",children:[a.jsx(yr,{}),a.jsx(Ba,{}),a.jsx("br",{}),a.jsx("br",{}),a.jsx("br",{})]})]})})},xy=g.lazy(()=>Promise.resolve().then(()=>require("./manage-design-tokens-DhdwhzQu.cjs"))),mt=280,by=({isActive:t,show:e})=>a.jsx(_.Button,{variant:t?"default":"ghost",size:"icon",onClick:e,children:a.jsx(v.StackIcon,{className:"h-5 w-5"})}),yy=({isActive:t,show:e})=>Ye()&&a.jsx(_.Button,{variant:t?"default":"ghost",size:"icon",onClick:e,children:a.jsx(v.PlusCircledIcon,{className:"h-5 w-5"})}),vy=({isActive:t,show:e})=>$("flags.ai",!1)?a.jsx(_.Button,{variant:t?"default":"ghost",size:"icon",onClick:e,children:a.jsx(kr,{})}):null;_.registerChaiSidebarPanel("add-block",{button:yy,label:"Add Blocks",position:"top",isInternal:!0,width:mt,panel:()=>a.jsx(Bo,{showHeading:!1,fromSidebar:!0,parentId:void 0,position:-1})});_.registerChaiSidebarPanel("chai-chat-panel",{button:vy,label:"Ask AI",position:"top",isInternal:!0,width:mt,panel:()=>a.jsx("div",{className:"",children:a.jsx(jc,{})})});_.registerChaiSidebarPanel("outline",{button:by,label:"Outline",position:"top",isInternal:!0,width:mt,panel:()=>a.jsx("div",{className:"-mt-8",children:a.jsx(xc,{})})});const ky=()=>{const t=_.useTopBarComponent(),[e,n]=Ns(),s=g.useRef("outline"),[r,o]=g.useState(mt),[i,l]=Mr(),[,c]=ri(),u=_.useChaiSidebarPanels("top"),p=_.useChaiSidebarPanels("bottom"),f=d.reverse([...p??[]]),m=g.useCallback(S=>{S.preventDefault()},[]),h=g.useMemo(()=>[u].flat(),[u]),x=g.useCallback(S=>{console.log("handleMenuItemClick",S,e),n(e===S?null:S)},[e,n]),{t:b}=F.useTranslation(),y=g.useMemo(()=>[...u,...p],[u,p]),k=$("htmlDir","ltr"),w=d.find(y,{id:e})??d.first(y),E=d.get(w,"width",mt);g.useEffect(()=>{if(e!==null){const S=d.find(y,{id:e});S&&d.get(S,"view","standard")==="standard"&&(s.current=e,o(d.get(S,"width",mt)))}},[e,y]);const A=g.useMemo(()=>{if(e===null)return 0;const S=d.find(y,{id:e});return d.get(S,"view","standard")==="standard"?E:r},[e,E,r,y]),I=g.useCallback(()=>{n(s.current)},[n,e]),T=g.useCallback(()=>{n("outline")},[n]);g.useEffect(()=>{e!==null&&!d.find(y,{id:e})&&n("outline")},[e,y]);const N=g.useCallback(S=>{x(S)},[x]);return a.jsx("div",{dir:k,className:"h-screen max-h-full w-screen overflow-x-hidden bg-background text-foreground",children:a.jsxs(ms,{children:[a.jsxs("div",{onContextMenu:m,className:"flex h-full max-h-full flex-col bg-background text-foreground",children:[a.jsx("div",{className:"flex h-[50px] w-screen items-center border-b border-border",children:a.jsx(g.Suspense,{children:a.jsx(t,{})})}),a.jsxs("main",{className:"relative flex h-[calc(100vh-56px)] max-w-full flex-1 flex-row",children:[a.jsxs("div",{id:"sidebar",className:"flex w-12 flex-col items-center justify-between border-r border-border py-2",children:[a.jsx("div",{className:"flex flex-col gap-y-1",children:h.map((S,C)=>a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:g.createElement(d.get(S,"button",Gt),{position:"top",panelId:S.id,isActive:e===S.id,show:()=>N(S.id)})}),a.jsx(ce,{side:"right",children:a.jsx("p",{children:b(S.label)})})]},"button-top-"+C))}),a.jsx("div",{className:"flex flex-col space-y-1"}),a.jsx("div",{className:"flex flex-col",children:f==null?void 0:f.map((S,C)=>a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:g.createElement(d.get(S,"button",Gt),{position:"bottom",panelId:S.id,isActive:e===S.id,show:()=>N(S.id)})}),a.jsx(ce,{side:"right",children:a.jsx("p",{children:b(S.label)})})]},"button-bottom-"+C))})]}),a.jsx(Vn.motion.div,{id:"left-panel",className:"h-full max-h-full border-r border-border",initial:{width:A},animate:{width:A},transition:{duration:.3,ease:"easeInOut"},children:e!==null&&d.get(w,"view","standard")==="standard"&&a.jsxs("div",{className:"no-scrollbar flex h-full flex-col overflow-hidden px-3 py-2",children:[a.jsx("div",{className:`absolute top-2 flex h-10 items-center space-x-1 py-2 text-base font-bold ${d.get(w,"isInternal",!1)?"":"w-64"}`,children:a.jsx("span",{children:b(d.get(w,"label",""))})}),a.jsx("div",{className:"no-scrollbar h-full max-h-full overflow-y-auto pt-10",children:a.jsx(g.Suspense,{fallback:a.jsx("div",{children:"Loading..."}),children:g.createElement(d.get(w,"panel",Gt),{})})})]})}),a.jsxs("div",{id:"canvas-container",className:"flex h-full max-h-full flex-1 flex-col bg-slate-800/20",children:[a.jsx(hy,{}),a.jsx(g.Suspense,{children:a.jsx(Rl,{})})]}),a.jsx(Vn.motion.div,{id:"right-panel",className:"h-full max-h-full border-l border-border",initial:{width:e==="ai"?0:mt},animate:{width:e==="ai"?0:mt},transition:{duration:.3,ease:"easeInOut"},children:a.jsx("div",{className:"no-scrollbar overflow h-full max-h-full overflow-hidden",children:a.jsxs("div",{className:"flex h-full max-h-full flex-col overflow-hidden p-3",children:[a.jsx("h2",{className:"-mt-1 flex items-center space-x-1 text-base font-bold",children:a.jsx("div",{className:"flex grow items-center gap-2",children:a.jsx("div",{className:"flex w-full items-center justify-between gap-2",children:i==="ai"?a.jsx(a.Fragment,{children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(v.LightningBoltIcon,{className:"rtl:ml-2"})," ",b("AI Assistant")]})}):i==="design-tokens"?a.jsxs("div",{className:"mb-1 flex w-full items-center justify-between gap-2",children:[a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(br,{className:"h-4 w-4 text-gray-600"}),b("Design Tokens")]}),a.jsx(_.Button,{onClick:()=>{c("styles"),l("block")},variant:"ghost",size:"icon",className:"text-xs",children:a.jsx(v.Cross1Icon,{className:"h-4 w-4 rtl:ml-2"})})]}):i==="theme"?a.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(v.MixerHorizontalIcon,{className:"h-4 w-4 text-gray-600"}),b("Theme Settings")]}),a.jsx(_.Button,{onClick:()=>l("block"),variant:"ghost",size:"icon",className:"text-xs",children:a.jsx(v.Cross1Icon,{className:"h-4 w-4 rtl:ml-2"})})]}):null})})}),a.jsx("div",{className:"flex h-full max-h-full w-full",children:a.jsx(g.Suspense,{fallback:a.jsx("div",{children:"Loading..."}),children:i==="ai"?a.jsx(jc,{}):i==="design-tokens"?a.jsx(g.Suspense,{fallback:a.jsx("div",{className:"h-1/2 w-full animate-pulse"}),children:a.jsx(xy,{})}):i==="theme"?a.jsx(vc,{}):a.jsx(gy,{})})})]})})})]})]}),a.jsx(Tc,{}),e!==null&&d.get(w,"view")==="drawer"&&a.jsx(Ec,{open:!0,onOpenChange:()=>I(),children:a.jsxs($o,{side:"left",className:"flex flex-col gap-0 p-0 sm:max-w-full",style:{width:`${E}px`},children:[a.jsx(Fo,{className:"border-b border-border px-2 py-2.5",children:a.jsxs(zo,{className:"flex items-center gap-2",children:[a.jsx("span",{className:"inline-block",children:d.get(w,"icon",null)}),a.jsx("span",{children:b(d.get(w,"label",""))})]})}),a.jsx("div",{className:"h-full max-h-full overflow-y-auto p-4",children:a.jsx(g.Suspense,{fallback:a.jsx("div",{children:"Loading..."}),children:g.createElement(d.get(w,"panel",Gt),{close:T})})})]})})," ",e!==null&&d.get(w,"view")==="modal"&&a.jsx(Pn,{open:!0,onOpenChange:()=>I(),children:a.jsxs(an,{className:"gap-0 p-0",style:{maxWidth:`${E}px`},children:[a.jsx(Ln,{className:"border-b border-border px-2 py-3.5",children:a.jsxs(ln,{className:"flex items-center gap-2",children:[a.jsx("span",{className:"inline-block",children:d.get(w,"icon",null)}),a.jsx("span",{children:b(d.get(w,"label",""))})]})}),a.jsx("div",{className:"max-h-[70vh] overflow-y-auto p-4",children:a.jsx(g.Suspense,{fallback:a.jsx("div",{children:"Loading..."}),children:g.createElement(d.get(w,"panel",Gt),{close:T})})})]})}),e!==null&&d.get(w,"view")==="overlay"&&a.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:a.jsx("div",{className:"h-full w-full",children:a.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:[a.jsxs("div",{className:"flex h-[50px] items-center justify-between border-b border-border p-4",children:[a.jsxs("div",{className:"-ml-2 flex items-center gap-2 text-lg font-bold",children:[a.jsx("span",{className:"rtl:ml-2 rtl:inline-block",children:d.get(w,"icon",null)}),a.jsx("span",{children:b(d.get(w,"label",""))})]}),a.jsx(_.Button,{onClick:()=>I(),variant:"ghost",size:"icon",className:"",children:a.jsx(v.Cross1Icon,{className:"h-5 w-5"})})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:a.jsx(g.Suspense,{fallback:a.jsx("div",{children:"Loading..."}),children:g.createElement(d.get(w,"panel",Gt),{close:T})})})]})})})]})})},wy=j.atom(!1),Cy=()=>{const[t,e]=j.useAtom(wy);return[t,e]},jy=()=>{const[t,e]=Cy(),{t:n}=F.useTranslation(),s=$("previewComponent",null);return t?a.jsxs("div",{className:ve.cn("fixed inset-0 z-[999] bg-background",t?"block":"hidden"),children:[a.jsxs(_.Button,{size:"sm",className:"absolute right-0 top-0 m-4 space-x-2",onClick:()=>e(!1),children:[a.jsx(v.EyeClosedIcon,{}),a.jsx("span",{children:n("Close Preview")})]}),a.jsx("div",{children:s?a.jsx(g.Suspense,{fallback:a.jsx(Lt,{className:"h-96 w-full"}),children:g.createElement(s)}):null})]}):null},Sy=({featureKey:t,options:e})=>{const n=_.useToggleChaiFeatureFlag(t),s=_.useChaiFeatureFlag(t);return a.jsxs("div",{className:"flex items-center space-x-3 rounded-md p-2 transition-colors hover:bg-gray-50 dark:hover:bg-gray-800",children:[a.jsx(cn,{checked:s,onCheckedChange:n}),a.jsxs("div",{className:"flex-1",children:[a.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:e.key}),e.description&&a.jsx("p",{className:"mt-0.5 text-xs text-gray-500 dark:text-gray-400",children:e.description})]})]})},Ny=Se.atomWithStorage("show-feature-flag",null),Ey=({close:t,position:e,updatePosition:n})=>{const s=_.useChaiFeatureFlags(),[r,o]=g.useState(""),[i,l]=g.useState(!1),[c,u]=g.useState({x:0,y:0}),p=g.useMemo(()=>{if(!r.trim())return s;const x=r.toLowerCase();return Object.fromEntries(Object.entries(s).filter(([b,y])=>{var k;return(b==null?void 0:b.toLowerCase().includes(x))||((k=y==null?void 0:y.description)==null?void 0:k.toLowerCase().includes(x))}))},[s,r]),f=x=>{l(!0),u({x:x.clientX-e.x,y:x.clientY-e.y})},m=x=>{if(!i)return;const b=x.clientX-c.x,y=x.clientY-c.y,k=x.currentTarget,w=k.offsetWidth,E=k.offsetHeight,A=window.innerWidth-w,I=window.innerHeight-E,T=Math.max(0,Math.min(b,A)),N=Math.max(0,Math.min(y,I));n(T,N)},h=()=>{l(!1)};return g.useEffect(()=>{const x=()=>{i&&l(!1)};return window.addEventListener("mouseup",x),()=>window.removeEventListener("mouseup",x)},[i]),!e||e.x<0||e.y<0?null:a.jsxs("div",{onMouseDown:f,onMouseMove:m,onMouseUp:h,className:"fixed z-[9999999] select-none rounded-md border border-gray-300 bg-white p-3 shadow-2xl",style:{left:e.x,top:e.y,cursor:i?"grabbing":"grab",userSelect:"none"},children:[a.jsxs("div",{className:"relative sticky top-0 rounded-t-lg bg-white",children:[a.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsxs("h3",{className:"flex items-center gap-x-2 text-base font-semibold text-gray-900 dark:text-gray-100",children:[a.jsx(v.DragHandleDots2Icon,{})," Feature Flags"]}),a.jsxs("p",{className:"text-xs text-gray-400 dark:text-gray-400",children:["Toggle experimental features (",a.jsx("span",{className:"font-mono",children:"Ctrl+Shift+1"})," to toggle)"]})]}),a.jsx(_.Button,{variant:"ghost",size:"sm",onClick:t,className:"absolute -right-2 -top-2 p-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200",children:a.jsx(v.Cross1Icon,{className:"h-4 w-4"})})]}),a.jsxs("div",{className:"relative",children:[a.jsx(v.MagnifyingGlassIcon,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"}),a.jsx(_.Input,{type:"search",placeholder:"Search features...",className:"w-full pl-8",value:r,onChange:x=>o(x.target.value),autoFocus:!0})]})]}),a.jsx("div",{className:"max-h-96 overflow-y-auto py-2",children:Object.keys(p).length>0?a.jsx("div",{className:"space-y-1",children:Object.entries(p).map(([x,b])=>a.jsx(Sy,{featureKey:x,options:b},x))}):a.jsx("div",{className:"py-8 text-center",children:a.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:['No features found matching "',r,'"']})})})]})},Ay=()=>{const[t,e]=j.useAtom(Ny);return Xe.useHotkeys("ctrl+shift+1,meta+shift+1",()=>e(n=>n?{...n,show:!n.show}:{x:0,y:0,show:!0}),{enableOnFormTags:!0}),t!=null&&t.show?a.jsx(Ey,{position:t,close:()=>e(n=>n?{...n,show:!1}:null),updatePosition:(n,s)=>e(r=>r?{...r,x:n,y:s,show:r.show}:{x:n,y:s,show:!0})}):null},Iy=t=>{},Ty=["data-block-index","draggable","data-drop","data-style-id","data-block-parent","data-style-prop","data-highlighted"],_y=["Box","Button","Checkbox","Divider","EmptyBox","Form","FormButton","Heading","Image","Input","Label","LineBreak","Link","List","ListItem","Paragraph","Radio","RichText","Select","Span","Text","TextArea","Video"],Bc=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=>!Ty.includes(e.key))),t.children&&(t.children=t.children.map(Bc).filter(e=>e!==null)),t),es=(t,e,n={})=>{var o,i,l,c,u,p;if(t.type!=="element"||!t.attributes)return t;if(t.tagName==="span"&&t.attributes.find(m=>m.key==="role"&&m.value==="link")){t.tagName="a",t.attributes=t.attributes.filter(x=>x.key!=="role");const m=(o=t.attributes.find(x=>x.key==="data-block-id"))==null?void 0:o.value,h=e==null?void 0:e.find(x=>(x==null?void 0:x._id)===m);if(h!=null&&h.link&&((l=(i=h==null?void 0:h.link)==null?void 0:i.href)==null?void 0:l.length)>0){const x=(c=h==null?void 0:h.link)==null?void 0:c.href,b=(u=h==null?void 0:h.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"),r=t.attributes.find(f=>f.key==="data-block-id");if(s){const f=s.value;if(_y.includes(f)||(p=n==null?void 0:n.additionalCoreBlocks)!=null&&p.includes(f))t.attributes=t.attributes.filter(m=>m.key!=="data-block-type"),t.children&&(t.children=t.children.map(m=>es(m,e,n)));else{const m=`chai-${d.kebabCase(f)}`;t.tagName=m,t.attributes=[],t.attributes.push({key:"chai-type",value:f});const h=X.getRegisteredChaiBlock(f),x=e.find(b=>b._id===(r==null?void 0:r.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)}))),h&&(h!=null&&h.description)&&t.attributes.push({key:"about-this-component",value:h.description}),h){if(h.canMove){const b=typeof h.canMove=="function"?h.canMove():h.canMove;t.attributes.push({key:"can-move",value:String(b)})}if(h.canDelete){const b=typeof h.canDelete=="function"?h.canDelete():h.canDelete;t.attributes.push({key:"can-delete",value:String(b)})}}f==="Icon"&&(t.attributes=t.attributes.filter(b=>b.key!=="icon")),h&&h.canAcceptBlock?t.children&&(t.children=t.children.map(b=>es(b,e,n))):t.children=[]}}else t.children&&(t.children=t.children.map(f=>es(f,e,n)));return r&&t.attributes.push({key:"bid",value:r.value}),t.attributes=t.attributes.filter(f=>f.key!=="data-block-type"&&f.key!=="data-block-id"),t},Rc=()=>{const[t]=sn();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 o=Vo.parse(s).map(Bc).filter(f=>f!==null),i=Nd(),l=o.map(f=>es(f,i,e));let c=Vo.stringify(l);return c=c.replace(/#styles:,/g,"#styles:"),c.replace(/\s+/g," ").trim()},[t])};function Ra(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 ts(t,e=0){var u;if(Array.isArray(t)){if(t.length===0)return"";if(t.length===1)return ts(t[0],e);const p=" ".repeat(e);let f=`${p}<>
|
|
135
|
+
`,textSerializers:i={}}=n||{};let l="";return t.nodesBetween(s,r,(c,u,p,f)=>{var m;c.isBlock&&u>s&&(l+=o);const h=i==null?void 0:i[c.type.name];if(h)return p&&(l+=h({node:c,pos:u,parent:p,index:f,range:e})),!1;c.isText&&(l+=(m=c==null?void 0:c.text)===null||m===void 0?void 0:m.slice(Math.max(s,u)-u,r-u))}),l}function Vf(t){return Object.fromEntries(Object.entries(t.nodes).filter(([,e])=>e.spec.toText).map(([e,n])=>[e,n.spec.toText]))}Ue.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new Ht({key:new Vt("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:t}=this,{state:e,schema:n}=t,{doc:s,selection:r}=e,{ranges:o}=r,i=Math.min(...o.map(p=>p.$from.pos)),l=Math.max(...o.map(p=>p.$to.pos)),c=Vf(n);return Hf(s,{from:i,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:c})}}})]}});const Wf=()=>({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),Gf=(t=!1)=>({commands:e})=>e.setContent("",t),Uf=()=>({state:t,tr:e,dispatch:n})=>{const{selection:s}=e,{ranges:r}=s;return n&&r.forEach(({$from:o,$to:i})=>{t.doc.nodesBetween(o.pos,i.pos,(l,c)=>{if(l.type.isText)return;const{doc:u,mapping:p}=e,f=u.resolve(p.map(c)),m=u.resolve(p.map(c+l.nodeSize)),h=f.blockRange(m);if(!h)return;const x=on(h);if(l.type.isTextblock){const{defaultType:b}=f.parent.contentMatchAt(f.index());e.setNodeMarkup(h.start,b)}(x||x===0)&&e.lift(h,x)})}),!0},qf=t=>e=>t(e),Kf=()=>({state:t,dispatch:e})=>ml(t,e),Yf=(t,e)=>({editor:n,tr:s})=>{const{state:r}=n,o=r.doc.slice(t.from,t.to);s.deleteRange(t.from,t.to);const i=s.mapping.map(e);return s.insert(i,o.content),s.setSelection(new ae(s.doc.resolve(Math.max(i-1,0)))),!0},Xf=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,s=n.$anchor.node();if(s.content.size>0)return!1;const r=t.selection.$anchor;for(let o=r.depth;o>0;o-=1)if(r.node(o).type===s.type){if(e){const l=r.before(o),c=r.after(o);t.delete(l,c).scrollIntoView()}return!0}return!1},Jf=t=>({tr:e,state:n,dispatch:s})=>{const r=Ie(t,n.schema),o=e.selection.$anchor;for(let i=o.depth;i>0;i-=1)if(o.node(i).type===r){if(s){const c=o.before(i),u=o.after(i);e.delete(c,u).scrollIntoView()}return!0}return!1},Zf=t=>({tr:e,dispatch:n})=>{const{from:s,to:r}=t;return n&&e.delete(s,r),!0},Qf=()=>({state:t,dispatch:e})=>Qr(t,e),eh=()=>({commands:t})=>t.keyboardShortcut("Enter"),th=()=>({state:t,dispatch:e})=>wf(t,e);function ps(t,e,n={strict:!0}){const s=Object.keys(e);return s.length?s.every(r=>n.strict?e[r]===t[r]:Ff(e[r])?e[r].test(t[r]):e[r]===t[r]):!0}function kl(t,e,n={}){return t.find(s=>s.type===e&&ps(Object.fromEntries(Object.keys(n).map(r=>[r,s.attrs[r]])),n))}function pa(t,e,n={}){return!!kl(t,e,n)}function wl(t,e,n){var s;if(!t||!e)return;let r=t.parent.childAfter(t.parentOffset);if((!r.node||!r.node.marks.some(p=>p.type===e))&&(r=t.parent.childBefore(t.parentOffset)),!r.node||!r.node.marks.some(p=>p.type===e)||(n=n||((s=r.node.marks[0])===null||s===void 0?void 0:s.attrs),!kl([...r.node.marks],e,n)))return;let i=r.index,l=t.start()+r.offset,c=i+1,u=l+r.node.nodeSize;for(;i>0&&pa([...t.parent.child(i-1).marks],e,n);)i-=1,l-=t.parent.child(i).nodeSize;for(;c<t.parent.childCount&&pa([...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 nh=(t,e={})=>({tr:n,state:s,dispatch:r})=>{const o=yt(t,s.schema),{doc:i,selection:l}=n,{$from:c,from:u,to:p}=l;if(r){const f=wl(c,o,e);if(f&&f.from<=u&&f.to>=p){const m=ae.create(i,f.from,f.to);n.setSelection(m)}}return!0},sh=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 Cl(t){return t instanceof ae}function Et(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function rh(t,e=null){if(!e)return null;const n=Y.atStart(t),s=Y.atEnd(t);if(e==="start"||e===!0)return n;if(e==="end")return s;const r=n.from,o=s.to;return e==="all"?ae.create(t,Et(0,r,o),Et(t.content.size,r,o)):ae.create(t,Et(e,r,o),Et(e,r,o))}function oh(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function ro(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const ah=(t=null,e={})=>({editor:n,view:s,tr:r,dispatch:o})=>{e={scrollIntoView:!0,...e};const i=()=>{(ro()||oh())&&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(o&&t===null&&!Cl(n.state.selection))return i(),!0;const l=rh(r.doc,t)||n.state.selection,c=n.state.selection.eq(l);return o&&(c||r.setSelection(l),c&&r.storedMarks&&r.setStoredMarks(r.storedMarks),i()),!0},ih=(t,e)=>n=>t.every((s,r)=>e(s,{...n,index:r})),lh=(t,e)=>({tr:n,commands:s})=>s.insertContentAt({from:n.selection.from,to:n.selection.to},t,e),jl=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&&jl(s)}return t};function Kn(t){const e=`<body>${t}</body>`,n=new window.DOMParser().parseFromString(e,"text/html").body;return jl(n)}function Sn(t,e,n){if(t instanceof Bt||t instanceof M)return t;n={slice:!0,parseOptions:{},...n};const s=typeof t=="object"&&t!==null,r=typeof t=="string";if(s)try{if(Array.isArray(t)&&t.length>0)return M.fromArray(t.map(l=>e.nodeFromJSON(l)));const i=e.nodeFromJSON(t);return n.errorOnInvalidContent&&i.check(),i}catch(o){if(n.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:o});return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",o),Sn("",e,n)}if(r){if(n.errorOnInvalidContent){let i=!1,l="";const c=new Qp({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=>(i=!0,l=typeof u=="string"?u:u.outerHTML,null)}]}})});if(n.slice?Kt.fromSchema(c).parseSlice(Kn(t),n.parseOptions):Kt.fromSchema(c).parse(Kn(t),n.parseOptions),n.errorOnInvalidContent&&i)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const o=Kt.fromSchema(e);return n.slice?o.parseSlice(Kn(t),n.parseOptions).content:o.parse(Kn(t),n.parseOptions)}return Sn("",e,n)}function ch(t,e,n){const s=t.steps.length-1;if(s<e)return;const r=t.steps[s];if(!(r instanceof Fe||r instanceof Me))return;const o=t.mapping.maps[s];let i=0;o.forEach((l,c,u,p)=>{i===0&&(i=p)}),t.setSelection(Y.near(t.doc.resolve(i),n))}const dh=t=>!("type"in t),uh=(t,e,n)=>({tr:s,dispatch:r,editor:o})=>{var i;if(r){n={parseOptions:o.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let l;const c=y=>{o.emit("contentError",{editor:o,error:y,disableCollaboration:()=>{o.storage.collaboration&&(o.storage.collaboration.isDisabled=!0)}})},u={preserveWhitespace:"full",...n.parseOptions};if(!n.errorOnInvalidContent&&!o.options.enableContentCheck&&o.options.emitContentError)try{Sn(e,o.schema,{parseOptions:u,errorOnInvalidContent:!0})}catch(y){c(y)}try{l=Sn(e,o.schema,{parseOptions:u,errorOnInvalidContent:(i=n.errorOnInvalidContent)!==null&&i!==void 0?i:o.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},m=!0,h=!0;if((dh(l)?l:[l]).forEach(y=>{y.check(),m=m?y.isText&&y.marks.length===0:!1,h=h?y.isBlock:!1}),p===f&&h){const{parent:y}=s.doc.resolve(p);y.isTextblock&&!y.type.spec.code&&!y.childCount&&(p-=1,f+=1)}let b;if(m){if(Array.isArray(e))b=e.map(y=>y.text||"").join("");else if(e instanceof M){let y="";e.forEach(v=>{v.text&&(y+=v.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&&ch(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},ph=()=>({state:t,dispatch:e})=>yf(t,e),fh=()=>({state:t,dispatch:e})=>vf(t,e),hh=()=>({state:t,dispatch:e})=>ll(t,e),mh=()=>({state:t,dispatch:e})=>pl(t,e),gh=()=>({state:t,dispatch:e,tr:n})=>{try{const s=Is(t.doc,t.selection.$from.pos,-1);return s==null?!1:(n.join(s,2),e&&e(n),!0)}catch{return!1}},xh=()=>({state:t,dispatch:e,tr:n})=>{try{const s=Is(t.doc,t.selection.$from.pos,1);return s==null?!1:(n.join(s,2),e&&e(n),!0)}catch{return!1}},bh=()=>({state:t,dispatch:e})=>xf(t,e),yh=()=>({state:t,dispatch:e})=>bf(t,e);function Sl(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function vh(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let s,r,o,i;for(let l=0;l<e.length-1;l+=1){const c=e[l];if(/^(cmd|meta|m)$/i.test(c))i=!0;else if(/^a(lt)?$/i.test(c))s=!0;else if(/^(c|ctrl|control)$/i.test(c))r=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))ro()||Sl()?i=!0:r=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return s&&(n=`Alt-${n}`),r&&(n=`Ctrl-${n}`),i&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const kh=t=>({editor:e,view:n,tr:s,dispatch:r})=>{const o=vh(t).split(/-(?!$)/),i=o.find(u=>!["Alt","Ctrl","Meta","Shift"].includes(u)),l=new KeyboardEvent("keydown",{key:i==="Space"?" ":i,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.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&&r&&s.maybeStep(p)}),!0};function oo(t,e,n={}){const{from:s,to:r,empty:o}=t.selection,i=e?Ie(e,t.schema):null,l=[];t.doc.nodesBetween(s,r,(f,m)=>{if(f.isText)return;const h=Math.max(s,m),x=Math.min(r,m+f.nodeSize);l.push({node:f,from:h,to:x})});const c=r-s,u=l.filter(f=>i?i.name===f.node.type.name:!0).filter(f=>ps(f.node.attrs,n,{strict:!1}));return o?!!u.length:u.reduce((f,m)=>f+m.to-m.from,0)>=c}const wh=(t,e={})=>({state:n,dispatch:s})=>{const r=Ie(t,n.schema);return oo(n,r,e)?kf(n,s):!1},Ch=()=>({state:t,dispatch:e})=>gl(t,e),jh=t=>({state:e,dispatch:n})=>{const s=Ie(t,e.schema);return Rf(s)(e,n)},Sh=()=>({state:t,dispatch:e})=>hl(t,e);function Nl(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function fa(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((s,r)=>(n.includes(r)||(s[r]=t[r]),s),{})}const Nh=(t,e)=>({tr:n,state:s,dispatch:r})=>{let o=null,i=null;const l=Nl(typeof t=="string"?t:t.name,s.schema);return l?(l==="node"&&(o=Ie(t,s.schema)),l==="mark"&&(i=yt(t,s.schema)),r&&n.selection.ranges.forEach(c=>{s.doc.nodesBetween(c.$from.pos,c.$to.pos,(u,p)=>{o&&o===u.type&&n.setNodeMarkup(p,void 0,fa(u.attrs,e)),i&&u.marks.length&&u.marks.forEach(f=>{i===f.type&&n.addMark(p,p+u.nodeSize,i.create(fa(f.attrs,e)))})})}),!0):!1},Eh=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),Ah=()=>({tr:t,dispatch:e})=>{if(e){const n=new We(t.doc);t.setSelection(n)}return!0},Ih=()=>({state:t,dispatch:e})=>dl(t,e),Th=()=>({state:t,dispatch:e})=>fl(t,e),_h=()=>({state:t,dispatch:e})=>Sf(t,e),Bh=()=>({state:t,dispatch:e})=>Af(t,e),Rh=()=>({state:t,dispatch:e})=>Ef(t,e);function Ph(t,e,n={},s={}){return Sn(t,e,{slice:!1,parseOptions:n,errorOnInvalidContent:s.errorOnInvalidContent})}const Lh=(t,e=!1,n={},s={})=>({editor:r,tr:o,dispatch:i,commands:l})=>{var c,u;const{doc:p}=o;if(n.preserveWhitespace!=="full"){const f=Ph(t,r.schema,n,{errorOnInvalidContent:(c=s.errorOnInvalidContent)!==null&&c!==void 0?c:r.options.enableContentCheck});return i&&o.replaceWith(0,p.content.size,f).setMeta("preventUpdate",!e),!0}return i&&o.setMeta("preventUpdate",!e),l.insertContentAt({from:0,to:p.content.size},t,{parseOptions:n,errorOnInvalidContent:(u=s.errorOnInvalidContent)!==null&&u!==void 0?u:r.options.enableContentCheck})};function Mh(t,e){const n=yt(e,t.schema),{from:s,to:r,empty:o}=t.selection,i=[];o?(t.storedMarks&&i.push(...t.storedMarks),i.push(...t.selection.$head.marks())):t.doc.nodesBetween(s,r,c=>{i.push(...c.marks)});const l=i.find(c=>c.type.name===n.name);return l?{...l.attrs}:{}}function Dh(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 Oh(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 ao(t){return e=>Oh(e.$from,t)}function Zn(t,e,n){return Object.fromEntries(Object.entries(n).filter(([s])=>{const r=t.find(o=>o.type===e&&o.name===s);return r?r.attribute.keepOnSplit:!1}))}function $h(t,e,n={}){const{empty:s,ranges:r}=t.selection,o=e?yt(e,t.schema):null;if(s)return!!(t.storedMarks||t.selection.$from.marks()).filter(f=>o?o.name===f.type.name:!0).find(f=>ps(f.attrs,n,{strict:!1}));let i=0;const l=[];if(r.forEach(({$from:f,$to:m})=>{const h=f.pos,x=m.pos;t.doc.nodesBetween(h,x,(b,y)=>{if(!b.isText&&!b.marks.length)return;const v=Math.max(h,y),w=Math.min(x,y+b.nodeSize),N=w-v;i+=N,l.push(...b.marks.map(E=>({mark:E,from:v,to:w})))})}),i===0)return!1;const c=l.filter(f=>o?o.name===f.mark.type.name:!0).filter(f=>ps(f.mark.attrs,n,{strict:!1})).reduce((f,m)=>f+m.to-m.from,0),u=l.filter(f=>o?f.mark.type!==o&&f.mark.type.excludes(o):!0).reduce((f,m)=>f+m.to-m.from,0);return(c>0?c+u:c)>=i}function ha(t,e){const{nodeExtensions:n}=Of(e),s=n.find(i=>i.name===t);if(!s)return!1;const r={name:s.name,options:s.options,storage:s.storage},o=mn(Nt(s,"group",r));return typeof o!="string"?!1:o.split(" ").includes("list")}function El(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 r=!0;return t.content.forEach(o=>{r!==!1&&(El(o,{ignoreWhitespace:n,checkChildren:e})||(r=!1))}),r}return!1}function Fh(t,e,n){var s;const{selection:r}=e;let o=null;if(Cl(r)&&(o=r.$cursor),o){const l=(s=t.storedMarks)!==null&&s!==void 0?s:o.marks();return!!n.isInSet(l)||!l.some(c=>c.type.excludes(n))}const{ranges:i}=r;return i.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,m)=>{if(u)return!1;if(p.isInline){const h=!m||m.type.allowsMarkType(n),x=!!n.isInSet(p.marks)||!p.marks.some(b=>b.type.excludes(n));u=h&&x}return!u}),u})}const zh=(t,e={})=>({tr:n,state:s,dispatch:r})=>{const{selection:o}=n,{empty:i,ranges:l}=o,c=yt(t,s.schema);if(r)if(i){const u=Mh(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,(m,h)=>{const x=Math.max(h,p),b=Math.min(h+m.nodeSize,f);m.marks.find(v=>v.type===c)?m.marks.forEach(v=>{c===v.type&&n.addMark(x,b,c.create({...v.attrs,...e}))}):n.addMark(x,b,c.create(e))})});return Fh(s,n,c)},Hh=(t,e)=>({tr:n})=>(n.setMeta(t,e),!0),Vh=(t,e={})=>({state:n,dispatch:s,chain:r})=>{const o=Ie(t,n.schema);let i;return n.selection.$anchor.sameParent(n.selection.$head)&&(i=n.selection.$anchor.parent.attrs),o.isTextblock?r().command(({commands:l})=>ua(o,{...i,...e})(n)?!0:l.clearNodes()).command(({state:l})=>ua(o,{...i,...e})(l,s)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Wh=t=>({tr:e,dispatch:n})=>{if(n){const{doc:s}=e,r=Et(t,0,s.content.size),o=ee.create(s,r);e.setSelection(o)}return!0},Gh=t=>({tr:e,dispatch:n})=>{if(n){const{doc:s}=e,{from:r,to:o}=typeof t=="number"?{from:t,to:t}:t,i=ae.atStart(s).from,l=ae.atEnd(s).to,c=Et(r,i,l),u=Et(o,i,l),p=ae.create(s,c,u);e.setSelection(p)}return!0},Uh=t=>({state:e,dispatch:n})=>{const s=Ie(t,e.schema);return Mf(s)(e,n)};function ma(t,e){const n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();if(n){const s=n.filter(r=>e==null?void 0:e.includes(r.type.name));t.tr.ensureMarks(s)}}const qh=({keepMarks:t=!0}={})=>({tr:e,state:n,dispatch:s,editor:r})=>{const{selection:o,doc:i}=e,{$from:l,$to:c}=o,u=r.extensionManager.attributes,p=Zn(u,l.node().type.name,l.node().attrs);if(o instanceof ee&&o.node.isBlock)return!l.parentOffset||!dt(i,l.pos)?!1:(s&&(t&&ma(n,r.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const f=c.parentOffset===c.parent.content.size,m=l.depth===0?void 0:Dh(l.node(-1).contentMatchAt(l.indexAfter(-1)));let h=f&&m?[{type:m,attrs:p}]:void 0,x=dt(e.doc,e.mapping.map(l.pos),1,h);if(!h&&!x&&dt(e.doc,e.mapping.map(l.pos),1,m?[{type:m}]:void 0)&&(x=!0,h=m?[{type:m,attrs:p}]:void 0),s){if(x&&(o instanceof ae&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,h),m&&!f&&!l.parentOffset&&l.parent.type!==m)){const b=e.mapping.map(l.before()),y=e.doc.resolve(b);l.node(-1).canReplaceWith(y.index(),y.index()+1,m)&&e.setNodeMarkup(e.mapping.map(l.before()),m)}t&&ma(n,r.extensionManager.splittableMarks),e.scrollIntoView()}return x},Kh=(t,e={})=>({tr:n,state:s,dispatch:r,editor:o})=>{var i;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 m=o.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(r){let v=M.empty;const w=c.index(-1)?1:c.index(-2)?2:3;for(let A=c.depth-w;A>=c.depth-3;A-=1)v=M.from(c.node(A).copy(v));const N=c.indexAfter(-1)<c.node(-2).childCount?1:c.indexAfter(-2)<c.node(-3).childCount?2:3,E={...Zn(m,c.node().type.name,c.node().attrs),...e},I=((i=l.contentMatch.defaultType)===null||i===void 0?void 0:i.createAndFill(E))||void 0;v=v.append(M.from(l.createAndFill(null,I)||void 0));const _=c.before(c.depth-(w-1));n.replace(_,c.after(-N),new V(v,4-w,0));let S=-1;n.doc.nodesBetween(_,n.doc.content.size,(A,C)=>{if(S>-1)return!1;A.isTextblock&&A.content.size===0&&(S=C+1)}),S>-1&&n.setSelection(ae.near(n.doc.resolve(S))),n.scrollIntoView()}return!0}const h=u.pos===c.end()?f.contentMatchAt(0).defaultType:null,x={...Zn(m,f.type.name,f.attrs),...e},b={...Zn(m,c.node().type.name,c.node().attrs),...e};n.delete(c.pos,u.pos);const y=h?[{type:l,attrs:x},{type:h,attrs:b}]:[{type:l,attrs:x}];if(!dt(n.doc,c.pos,2))return!1;if(r){const{selection:v,storedMarks:w}=s,{splittableMarks:N}=o.extensionManager,E=w||v.$to.parentOffset&&v.$from.marks();if(n.split(c.pos,2,y).scrollIntoView(),!E||!r)return!0;const I=E.filter(_=>N.includes(_.type.name));n.ensureMarks(I)}return!0},Zs=(t,e)=>{const n=ao(i=>i.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 r=t.doc.nodeAt(s);return n.node.type===(r==null?void 0:r.type)&&zt(t.doc,n.pos)&&t.join(n.pos),!0},Qs=(t,e)=>{const n=ao(i=>i.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 r=t.doc.nodeAt(s);return n.node.type===(r==null?void 0:r.type)&&zt(t.doc,s)&&t.join(s),!0},Yh=(t,e,n,s={})=>({editor:r,tr:o,state:i,dispatch:l,chain:c,commands:u,can:p})=>{const{extensions:f,splittableMarks:m}=r.extensionManager,h=Ie(t,i.schema),x=Ie(e,i.schema),{selection:b,storedMarks:y}=i,{$from:v,$to:w}=b,N=v.blockRange(w),E=y||b.$to.parentOffset&&b.$from.marks();if(!N)return!1;const I=ao(_=>ha(_.type.name,f))(b);if(N.depth>=1&&I&&N.depth-I.depth<=1){if(I.node.type===h)return u.liftListItem(x);if(ha(I.node.type.name,f)&&h.validContent(I.node.content)&&l)return c().command(()=>(o.setNodeMarkup(I.pos,h),!0)).command(()=>Zs(o,h)).command(()=>Qs(o,h)).run()}return!n||!E||!l?c().command(()=>p().wrapInList(h,s)?!0:u.clearNodes()).wrapInList(h,s).command(()=>Zs(o,h)).command(()=>Qs(o,h)).run():c().command(()=>{const _=p().wrapInList(h,s),S=E.filter(A=>m.includes(A.type.name));return o.ensureMarks(S),_?!0:u.clearNodes()}).wrapInList(h,s).command(()=>Zs(o,h)).command(()=>Qs(o,h)).run()},Xh=(t,e={},n={})=>({state:s,commands:r})=>{const{extendEmptyMarkRange:o=!1}=n,i=yt(t,s.schema);return $h(s,i,e)?r.unsetMark(i,{extendEmptyMarkRange:o}):r.setMark(i,e)},Jh=(t,e,n={})=>({state:s,commands:r})=>{const o=Ie(t,s.schema),i=Ie(e,s.schema),l=oo(s,o,n);let c;return s.selection.$anchor.sameParent(s.selection.$head)&&(c=s.selection.$anchor.parent.attrs),l?r.setNode(i,c):r.setNode(o,{...c,...n})},Zh=(t,e={})=>({state:n,commands:s})=>{const r=Ie(t,n.schema);return oo(n,r,e)?s.lift(r):s.wrapIn(r,e)},Qh=()=>({state:t,dispatch:e})=>{const n=t.plugins;for(let s=0;s<n.length;s+=1){const r=n[s];let o;if(r.spec.isInputRules&&(o=r.getState(t))){if(e){const i=t.tr,l=o.transform;for(let c=l.steps.length-1;c>=0;c-=1)i.step(l.steps[c].invert(l.docs[c]));if(o.text){const c=i.doc.resolve(o.from).marks();i.replaceWith(o.from,o.to,t.schema.text(o.text,c))}else i.delete(o.from,o.to)}return!0}}return!1},em=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,{empty:s,ranges:r}=n;return s||e&&r.forEach(o=>{t.removeMark(o.$from.pos,o.$to.pos)}),!0},tm=(t,e={})=>({tr:n,state:s,dispatch:r})=>{var o;const{extendEmptyMarkRange:i=!1}=e,{selection:l}=n,c=yt(t,s.schema),{$from:u,empty:p,ranges:f}=l;if(!r)return!0;if(p&&i){let{from:m,to:h}=l;const x=(o=u.marks().find(y=>y.type===c))===null||o===void 0?void 0:o.attrs,b=wl(u,c,x);b&&(m=b.from,h=b.to),n.removeMark(m,h,c)}else f.forEach(m=>{n.removeMark(m.$from.pos,m.$to.pos,c)});return n.removeStoredMark(c),!0},nm=(t,e={})=>({tr:n,state:s,dispatch:r})=>{let o=null,i=null;const l=Nl(typeof t=="string"?t:t.name,s.schema);return l?(l==="node"&&(o=Ie(t,s.schema)),l==="mark"&&(i=yt(t,s.schema)),r&&n.selection.ranges.forEach(c=>{const u=c.$from.pos,p=c.$to.pos;let f,m,h,x;n.selection.empty?s.doc.nodesBetween(u,p,(b,y)=>{o&&o===b.type&&(h=Math.max(y,u),x=Math.min(y+b.nodeSize,p),f=y,m=b)}):s.doc.nodesBetween(u,p,(b,y)=>{y<u&&o&&o===b.type&&(h=Math.max(y,u),x=Math.min(y+b.nodeSize,p),f=y,m=b),y>=u&&y<=p&&(o&&o===b.type&&n.setNodeMarkup(y,void 0,{...b.attrs,...e}),i&&b.marks.length&&b.marks.forEach(v=>{if(i===v.type){const w=Math.max(y,u),N=Math.min(y+b.nodeSize,p);n.addMark(w,N,i.create({...v.attrs,...e}))}}))}),m&&(f!==void 0&&n.setNodeMarkup(f,void 0,{...m.attrs,...e}),i&&m.marks.length&&m.marks.forEach(b=>{i===b.type&&n.addMark(h,x,i.create({...b.attrs,...e}))}))}),!0):!1},sm=(t,e={})=>({state:n,dispatch:s})=>{const r=Ie(t,n.schema);return If(r,e)(n,s)},rm=(t,e={})=>({state:n,dispatch:s})=>{const r=Ie(t,n.schema);return Tf(r,e)(n,s)};var om=Object.freeze({__proto__:null,blur:Wf,clearContent:Gf,clearNodes:Uf,command:qf,createParagraphNear:Kf,cut:Yf,deleteCurrentNode:Xf,deleteNode:Jf,deleteRange:Zf,deleteSelection:Qf,enter:eh,exitCode:th,extendMarkRange:nh,first:sh,focus:ah,forEach:ih,insertContent:lh,insertContentAt:uh,joinBackward:hh,joinDown:fh,joinForward:mh,joinItemBackward:gh,joinItemForward:xh,joinTextblockBackward:bh,joinTextblockForward:yh,joinUp:ph,keyboardShortcut:kh,lift:wh,liftEmptyBlock:Ch,liftListItem:jh,newlineInCode:Sh,resetAttributes:Nh,scrollIntoView:Eh,selectAll:Ah,selectNodeBackward:Ih,selectNodeForward:Th,selectParentNode:_h,selectTextblockEnd:Bh,selectTextblockStart:Rh,setContent:Lh,setMark:zh,setMeta:Hh,setNode:Vh,setNodeSelection:Wh,setTextSelection:Gh,sinkListItem:Uh,splitBlock:qh,splitListItem:Kh,toggleList:Yh,toggleMark:Xh,toggleNode:Jh,toggleWrap:Zh,undoInputRule:Qh,unsetAllMarks:em,unsetMark:tm,updateAttributes:nm,wrapIn:sm,wrapInList:rm});Ue.create({name:"commands",addCommands(){return{...om}}});Ue.create({name:"drop",addProseMirrorPlugins(){return[new Ht({key:new Vt("tiptapDrop"),props:{handleDrop:(t,e,n,s)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:n,moved:s})}}})]}});Ue.create({name:"editable",addProseMirrorPlugins(){return[new Ht({key:new Vt("editable"),props:{editable:()=>this.editor.options.editable}})]}});const am=new Vt("focusEvents");Ue.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:t}=this;return[new Ht({key:am,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}}}})]}});Ue.create({name:"keymap",addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({commands:i})=>[()=>i.undoInputRule(),()=>i.command(({tr:l})=>{const{selection:c,doc:u}=l,{empty:p,$anchor:f}=c,{pos:m,parent:h}=f,x=f.parent.isTextblock&&m>0?l.doc.resolve(m-1):f,b=x.parent.type.spec.isolating,y=f.pos-f.parentOffset,v=b&&x.parent.childCount===1?y===f.pos:Y.atStart(u).from===m;return!p||!h.type.isTextblock||h.textContent.length||!v||v&&f.parent.type.name==="paragraph"?!1:i.clearNodes()}),()=>i.deleteSelection(),()=>i.joinBackward(),()=>i.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:i})=>[()=>i.deleteSelection(),()=>i.deleteCurrentNode(),()=>i.joinForward(),()=>i.selectNodeForward()]),s={Enter:()=>this.editor.commands.first(({commands:i})=>[()=>i.newlineInCode(),()=>i.createParagraphNear(),()=>i.liftEmptyBlock(),()=>i.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()},r={...s},o={...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 ro()||Sl()?o:r},addProseMirrorPlugins(){return[new Ht({key:new Vt("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),r=t.some(b=>b.getMeta("preventClearDocument"));if(!s||r)return;const{empty:o,from:i,to:l}=e.selection,c=Y.atStart(e.doc).from,u=Y.atEnd(e.doc).to;if(o||!(i===c&&l===u)||!El(n.doc))return;const m=n.tr,h=yl({state:n,transaction:m}),{commands:x}=new Df({editor:this.editor,state:h});if(x.clearNodes(),!!m.steps.length)return m}})]}});Ue.create({name:"paste",addProseMirrorPlugins(){return[new Ht({key:new Vt("tiptapPaste"),props:{handlePaste:(t,e,n)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:n})}}})]}});Ue.create({name:"tabindex",addProseMirrorPlugins(){return[new Ht({key:new Vt("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});const im=Ue.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()}}}),Al=({blockId:t,value:e="",onUpdate:n=()=>{},onBlur:s=()=>{},placeholder:r="",from:o="settings",style:i={}})=>ns.useEditor({extensions:[Xc,Wc,im.configure({types:["textStyle"]}),Gc.configure({multicolor:!0}),Uc.configure({openOnClick:!1,HTMLAttributes:{class:"underline"}}),Kc.configure({types:["heading","paragraph"],alignments:["left","center","right"],defaultAlignment:"left"}),Yc,qc.configure({placeholder:r||"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:{...i?{style:i}:{},class:o!=="canvas"?"text-sm p-1 px-2 rte":"rte"}}},[t]);function lm(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 cm=g.memo(({blockContent:t,editingElement:e,onClose:n,onChange:s,onEscape:r})=>{const{document:o}=rt(),i=Al({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(!o)return;const f=p==null?void 0:p.relatedTarget,m=o.querySelector(".ProseMirror"),h=o.querySelector(".tippy-box"),x=o.querySelector("#chai-rich-text-menu-bar"),b=m==null?void 0:m.contains(f),y=h==null?void 0:h.contains(f),v=x==null?void 0:x.contains(f),w=window.document.getElementById("rte-widget-color-picker");if(!b&&!y&&!v&&!w){const N=(u==null?void 0:u.getHTML())||"";n(N)}},from:"canvas"});g.useEffect(()=>{var p,f;const u=lm(e);u&&((p=i==null?void 0:i.commands)==null||p.setTextAlign(u)),(f=i==null?void 0:i.commands)==null||f.focus(),i==null||i.emit("focus",{editor:i,event:new FocusEvent("focus"),transaction:[]})},[e,i]);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"&&r(u)};return i&&a.jsxs("div",{onKeyDown:c,onClick:u=>u.stopPropagation(),className:"relative",children:[a.jsx(ns.BubbleMenu,{editor:i,shouldShow:()=>i&&(i==null?void 0:i.isFocused),tippyOptions:{duration:100,arrow:!0,hideOnClick:!1},className:"w-max",children:a.jsx(Pi,{editor:i,from:"canvas"})}),a.jsx(ns.EditorContent,{id:"active-inline-editing-element",onKeyDown:c,value:t,editor:i,className:l})]})}),dm=g.memo(({editingElement:t,blockContent:e,onClose:n,editorRef:s,onChange:r,onEscape:o})=>{const{document:i,window:l}=rt();g.useEffect(()=>{if(!(!i||!l))if(s.current){s.current.innerHTML=e,s.current.focus();const m=i.createRange(),h=l.getSelection();m.selectNodeContents(s.current),m.collapse(!1),h==null||h.removeAllRanges(),h==null||h.addRange(m),s.current.focus()}else n()},[e,i,s,n,l]);const c=g.useMemo(()=>{var h;const m=((h=t==null?void 0:t.tagName)==null?void 0:h.toLowerCase())||"div";return m==="button"?"div":m},[t]),u=g.useCallback(m=>{(m.key==="Enter"||m.key==="Escape")&&o(m)},[o]),p=g.useCallback(()=>{n()},[n]),f=g.useMemo(()=>{var m;return{id:"active-inline-editing-element",contentEditable:!0,className:`${((m=t==null?void 0:t.className)==null?void 0:m.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:h=>{const x=h.target;x&&(x.innerText.trim()===""?(x.setAttribute("data-placeholder","Enter text here"),x.children.length>0&&x.children[0].remove()):h.target.removeAttribute("data-placeholder"),r(h.target.innerText))},onClick:h=>{h.stopPropagation(),h.preventDefault()}}},[t==null?void 0:t.className,t==null?void 0:t.style,r]);return a.jsx(a.Fragment,{children:g.createElement(c,{ref:s,onBlur:p,onKeyDown:u,...f})})}),um=g.memo(({block:t,children:e})=>{const n="content",{document:s}=rt(),{editingBlockId:r,editingItemIndex:o,setEditingBlockId:i,setEditingItemIndex:l}=Ft(),[c,u]=g.useState(null),p=g.useRef(null),{clearHighlight:f}=st(),m=nt(),{selectedLang:h}=Te(),[,x]=U(),b=g.useRef(null),y=r,{blockContent:v,blockType:w}=g.useMemo(()=>{var P;const S=t._type;let A=t[n];const C=X.getRegisteredChaiBlock(t._type);return h&&((P=C==null?void 0:C.i18nProps)==null?void 0:P.includes(n))&&d.has(t,`${n}-${h}`)&&(A=d.get(t,`${n}-${h}`)),{blockContent:A,blockType:S}},[t,h]),N=g.useCallback(S=>{var C;const A=S||((C=p.current)==null?void 0:C.innerText);m([y],{[n]:A}),u(null),i(""),l(-1),x([]),y&&setTimeout(()=>x([y]),100)},[m,y,i,l,x]),E=ke.useDebouncedCallback(S=>{m([y],{[n]:S})},[y,t,m,h],1e3),I=g.useCallback(S=>{S.preventDefault(),y&&(b.current=y),N(),setTimeout(()=>{const A=b.current;b.current=null,A&&x([A])},100)},[y,N,x]);g.useEffect(()=>{var T;if(!y||!s)return;const S=`[data-block-id="${y}"]`,A=o>=0?`[data-block-index="${o}"]`:"",C=s.querySelector(`${S}${A}`);C&&((T=C==null?void 0:C.classList)==null||T.add("sr-only"),g.startTransition(()=>u(C)))},[y,w,s,o]);const _=g.useMemo(()=>c?(f(),["RichText","Paragraph"].includes(w)?a.jsx(cm,{blockContent:v,editingElement:c,onChange:E,onClose:N,onEscape:I}):a.jsx(dm,{editorRef:p,blockContent:v,editingElement:c,onClose:N,onChange:E,onEscape:I})):null,[c,f,w,v,N,E,I]);return a.jsxs(a.Fragment,{children:[_,e]})},(t,e)=>t.block._id===e.block._id&&t.block.content===e.block.content),Il=g.createContext({index:-1,key:""}),pm=["Box","Repeater","GlobalBlock","PartialBlock","Heading","Text","RichText","Span","Image","Button","Paragraph","Link","Video","Audio","Icon","List","ListItem","CustomScript","CustomHTML"],fm=({asyncProps:t,blockAtom:e,children:n})=>{const{editingBlockId:s,editingItemIndex:r}=Ft(),[o]=j.useAtom(e),i=g.useMemo(()=>X.getRegisteredChaiBlock(o._type),[o._type]),{selectedLang:l,fallbackLang:c}=Te(),u=Ip(),p=tn(),[f]=j.useAtom(Vr),m=d.get(i,"component",null),{index:h,key:x}=g.useContext(Il),{mode:b}=Ri(),y=j.useAtomValue(en),v=Ye(),w=b==="edit",N=Ap(),E=g.useMemo(()=>f?be.applyBindingToBlockProps(be.applyLanguage(o,l,i),p,{index:h,key:x}):be.applyLanguage(o,l,i),[o,l,i,p,f,h,x]),I=g.useMemo(()=>be.getBlockTagAttributes(o,!0,y),[o,be.getBlockTagAttributes,y]),_=g.useMemo(()=>u(o._id,be.getBlockRuntimeProps(o._type)),[o._id,o._type,u,be.getBlockRuntimeProps]),S=g.useMemo(()=>{const O={"data-block-id":o._id,"data-block-type":o._type,"data-block-index":h};return w&&v?{...O,draggable:!s,onMouseDown:N.onMouseDown,onDragStart:N.onDragStart,onDragEnd:N.onDragEnd}:O},[o._id,o._type,h,w,v,N,s]),A=g.useMemo(()=>({blockProps:S,inBuilder:b==="edit",lang:l||c,pageData:p,...E,...I,..._,...t}),[b,S,l,c,E,I,_,t]),C=g.useMemo(()=>!pm.includes(o._type),[o._type]),T=g.useMemo(()=>d.get(o,"_show",!0),[o]);if(d.isNull(m)||!T)return null;let P=a.jsx(g.Suspense,{children:g.createElement(m,{...A,children:n({_id:o._id,_type:o._type,...d.isArray(E.repeaterItems)?{repeaterItems:be.applyLimit(E.repeaterItems,o),$repeaterItemsKey:E.$repeaterItemsKey}:{},...o.partialBlockId?{partialBlockId:o.partialBlockId}:"",...o.globalBlock?{partialBlockId:o.globalBlock}:""})})});const R=s===o._id&&(r===h||h<0)?a.jsx(um,{block:o,children:P}):P;return C?a.jsx(At.ErrorBoundary,{fallbackRender:Bp,children:R}):R},hm=({children:t,partialBlockId:e})=>{const n=$("gotoPage",d.noop),{saveState:s}=nn(),{selectedLang:r,fallbackLang:o}=Te(),i=g.useCallback(l=>{if(l.stopPropagation(),s!=="SAVED"){pe.toast.error("You have unsaved changes. Please save the page first.");return}n({pageId:e,lang:r||o})},[s,n,e,r,o]);return a.jsxs(a.Fragment,{children:[t,a.jsx("div",{className:"partial-overlay group absolute inset-0 z-50",children:a.jsx("div",{onDoubleClick:i,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:a.jsx("p",{className:"rounded-md bg-white px-2 py-1 text-xs",children:"Partial block. Double click to edit."})})})]})},mm=({partialBlockId:t})=>{const{getPartailBlocks:e}=As(),n=g.useMemo(()=>e(t),[e,t]),s=g.useMemo(()=>Se.splitAtom(j.atom(n)),[n]);return d.isEmpty(n)?null:a.jsx(hm,{partialBlockId:t,children:a.jsx(fs,{splitAtoms:s,blocks:n,type:"PartialBlock"})})},fs=({blocks:t,parent:e=null,splitAtoms:n=void 0,type:s=""})=>{const r=uu(n);let o=g.useMemo(()=>d.filter(t,l=>d.has(l,"_id")&&(d.isEmpty(e)?!l._parent:l._parent===e)),[t,e]);const i=g.useCallback(l=>d.filter(t,c=>c._parent===l).length>0,[t]);return(s==="Heading"||s==="Paragraph"||s==="Link")&&(o=be.adjustSpacingInContentBlocks(o)),d.map(o,l=>{const c=r(l._id);return c?a.jsx(_p,{block:l,children:u=>a.jsx(fm,{blockAtom:c,asyncProps:u,children:({_id:p,_type:f,partialBlockId:m,repeaterItems:h,$repeaterItemsKey:x})=>f==="Repeater"?d.isArray(h)&&h.map((b,y)=>a.jsx(Il.Provider,{value:{index:y,key:x},children:a.jsx(fs,{splitAtoms:n,blocks:t,parent:l._id,type:f})},`${p}-${y}`)):f==="GlobalBlock"||f==="PartialBlock"?a.jsx(j.Provider,{store:Ve,children:a.jsx(mm,{partialBlockId:m})}):i(p)?a.jsx(fs,{splitAtoms:n,blocks:t,parent:l._id,type:f}):null})},l._id):null})},gm=()=>{const[t]=te();return a.jsx(fs,{splitAtoms:En,blocks:t})},xm=()=>{const[t]=te(),[e]=j.useAtom(Fr),n=d.isEmpty(t)?null:a.jsx(gm,{},e);return a.jsx(a.Fragment,{children:n})},bm=Se.atomWithStorage("canvasZoom",100),Tl=()=>j.useAtom(bm),ym=()=>j.useAtom(Ja),_l=Se.atomWithStorage("canvasWidth",800),vm=Se.atomWithStorage("canvasDisplayWidth",800),Bl=j.atom(t=>{const e=t(_l);return ve.getBreakpointValue(e).toLowerCase()}),hs=()=>{const[t,e]=j.useAtom(_l),n=j.useAtomValue(Bl),[s,r]=ym();return g.useEffect(()=>{s!=="xs"&&r(n)},[n,s,r]),[t,n,e]},io=()=>{const[t,e]=j.useAtom(vm);return[t,e]},km=t=>{const[e]=io(),[,n]=Tl(),s=$("htmlDir","ltr"),[r,o]=g.useState({}),i=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,m=l*u;c&&(p={height:100+(c-f)/f*100+"%",width:100+(l-m)/m*100+"%"}),o({position:"relative",top:0,transform:`scale(${u})`,transformOrigin:s==="rtl"?"top right":"top left",...p,maxWidth:"none"}),n(u*100)}else o({}),n(100)},[e,t,s,n]);return g.useEffect(()=>{i()},[e,t,n,i]),r};function Yt(t,e){g.useEffect(()=>{const n=oe.subscribe(t,e);return()=>n()},[t,e])}const wm=()=>{const[,t]=U(),[e,n]=Ee(),{document:s}=rt(),{clearHighlight:r}=st(),[o]=U(),[i]=j.useAtom(zr);return g.useEffect(()=>{setTimeout(()=>{if(!d.isEmpty(e))return;const l=Ci(s,d.first(o));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,o,n,e]),g.useEffect(()=>()=>r(),[r]),Yt(K.CANVAS_BLOCK_SELECTED,l=>{l&&(!d.isEmpty(l)&&!d.includes(o,d.first(l))&&(i==null||i.closeAll()),t(l))}),Yt(K.CANVAS_BLOCK_STYLE_SELECTED,l=>{if(!l)return;const{blockId:c,styleId:u,styleProp:p}=l;c&&(d.includes(o,c)||i==null||i.closeAll(),n([{id:u,prop:p,blockId:c}]),t([c]))}),Yt(K.CLEAR_CANVAS_SELECTION,()=>{r(),t([]),n([])}),null},Cm=()=>{const[t]=io(),[,e]=xi(),n=g.useRef(null),s=g.useRef(null),[r,o]=g.useState({width:0,height:0}),i=km(r),[,l]=sn(),c=$("loading",!1),u=$("htmlDir","ltr"),{onDragOver:p,onDrop:f,onDragEnd:m}=rn(),h=qu(),x=g.useCallback(y=>{o(v=>({...v,width:y}))},[o]);g.useEffect(()=>{if(!s.current)return;const{clientWidth:y,clientHeight:v}=s.current;o({width:y,height:v})},[s,t]);const b=g.useMemo(()=>{let y=fp;return y=y.replace("__HTML_DIR__",u),y},[u]);return a.jsx(Ep,{onMount:x,onResize:x,children:a.jsx("div",{onMouseLeave:()=>setTimeout(()=>e(""),300),className:"relative mx-auto h-full w-full overflow-hidden",onDragOver:p,onDrop:f,onDragEnd:m,ref:s,children:a.jsxs(mp,{contentDidMount:()=>l(n.current),ref:n,id:"canvas-iframe",style:{...i,...d.isEmpty(i)?{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:[a.jsx(kp,{}),a.jsx(up,{}),a.jsx(Cp,{}),a.jsxs(xd.Provider,{children:[a.jsxs(cp,{children:[c?a.jsx("div",{className:"h-full p-4",children:a.jsx(Lt,{className:"h-full"})}):a.jsx(xm,{}),a.jsx(wp,{})]}),a.jsx(wm,{})]}),h.isVisible&&a.jsx("div",{id:"placeholder",className:`pointer-events-none absolute z-[99999] max-w-full transition-all duration-150 ${h.isEmpty?"bg-purple-500/10 outline-dashed outline-2 -outline-offset-2 outline-purple-500":"rounded-full bg-green-500"}`,style:{top:h.top,left:h.left,width:h.width,height:h.height}})]})})})},yn=()=>{const{t}=F.useTranslation();return a.jsx("div",{className:"h-full w-full rounded-md bg-red-200 p-4 text-red-500",children:a.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center",children:[a.jsx("p",{className:"font-semibold",children:t("Oops! Something went wrong.")}),a.jsx("p",{children:t("Please try again.")})]})})},jm=j.atom(null),lo=()=>j.useAtom(jm),Sm=g.lazy(()=>Promise.resolve().then(()=>require("./code-editor-CjatfjZe.cjs"))),Rl=()=>{const[t]=lo(),e=$("onError",d.noop);return a.jsx("div",{className:"flex h-full max-h-full w-full flex-1 flex-col",children:a.jsxs("div",{className:"relative flex h-full max-h-full flex-col overflow-hidden bg-gray-100/40",children:[a.jsx(g.Suspense,{fallback:a.jsx(Lt,{className:"h-full"}),children:a.jsx(At.ErrorBoundary,{fallback:a.jsx(yn,{}),onError:e,children:a.jsx(Cm,{})})}),t?a.jsx(g.Suspense,{fallback:a.jsx(Lt,{className:"h-full"}),children:a.jsx(Sm,{})}):null]})})},Ot={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"},Nm=({id:t,placeholder:e})=>{const{t:n}=F.useTranslation(),[,s]=lo(),{selectedLang:r}=Te(),o=J(),i=t.replace("root.",""),l=X.getRegisteredChaiBlock(o==null?void 0:o._type),u=d.includes(d.get(l,"i18nProps",[]),i)&&r?`${i}-${r}`:i,p=d.get(o,u,""),f=g.useMemo(()=>d.get(Ot,r,r),[r]),m=()=>{const h=o==null?void 0:o._id;s({blockId:h,blockProp:u,placeholder:e,initialCode:p})};return a.jsxs("div",{className:"mt-2 flex flex-col gap-y-1",children:[a.jsxs("label",{htmlFor:t,children:["HTML Code",f&&a.jsxs("small",{className:"text-[9px] text-zinc-400",children:[" ",f]})]}),a.jsx("button",{onClick:m,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>"}),a.jsx(B.Button,{onClick:m,size:"sm",variant:"outline",className:"w-fit",children:n("Open code editor")})]})},Em=({id:t,value:e,onChange:n,onBlur:s})=>{const r=$("collections",[]),o=J(),i=d.get(o,"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1").replace(q.COLLECTION_PREFIX,""),l=d.find(r,{id:i}),c=t==="root.filter"?"filters":"sorts",u=d.get(l,c,[]);return a.jsx("div",{children:a.jsxs("select",{value:e,onChange:p=>n(p.target.value),onBlur:p=>s(t,p.target.value),children:[a.jsx("option",{value:"",children:"Select"}),u.map(p=>a.jsx("option",{value:p.id,children:p.name},p.id))]})})},Am=g.lazy(()=>Promise.resolve().then(()=>require("./IconPicker-DB_PpKvH.cjs")).then(t=>({default:t.IconPicker}))),Im=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}},Tm=({value:t,onChange:e,id:n})=>{const{t:s}=F.useTranslation(),[r,o]=g.useState(t||"");g.useEffect(()=>{o(t||"")},[t]);const i=l=>{o(l);const c=Im(l);e(c)};return a.jsxs("div",{className:"mt-1 flex flex-col gap-2",id:"icon-picker-field",children:[a.jsxs("div",{className:"flex items-center gap-x-2",children:[a.jsx("div",{className:"flex h-12 w-12 items-center justify-center overflow-hidden rounded-lg border bg-gray-50",children:r?a.jsx("div",{className:"h-6 w-6",dangerouslySetInnerHTML:{__html:r}}):a.jsx("span",{className:"text-xs text-gray-400",children:"SVG"})}),a.jsx("textarea",{id:n,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",value:r,onChange:l=>i(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"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(g.Suspense,{fallback:a.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading..."}),children:a.jsx(Am,{onSelectIcon:i})}),a.jsx("p",{className:"text-xs text-muted-foreground",children:s("Paste SVG_code")})]})]})},Pn=ie.Root,Pl=ie.Trigger,_m=ie.Portal,Ll=D.forwardRef(({className:t,...e},n)=>a.jsx(ie.Overlay,{ref:n,className:B.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}));Ll.displayName=ie.Overlay.displayName;const an=D.forwardRef(({className:t,children:e,...n},s)=>a.jsxs(_m,{children:[a.jsx(Ll,{}),a.jsxs(ie.Content,{ref:s,className:B.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,a.jsxs(ie.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:[a.jsx(k.Cross1Icon,{className:"h-4 w-4"}),a.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));an.displayName=ie.Content.displayName;const Ln=({className:t,...e})=>a.jsx("div",{className:B.cn("flex flex-col space-y-1.5 text-center sm:text-left",t),...e});Ln.displayName="DialogHeader";const Ml=({className:t,...e})=>a.jsx("div",{className:B.cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...e});Ml.displayName="DialogFooter";const ln=D.forwardRef(({className:t,...e},n)=>a.jsx(ie.Title,{ref:n,className:B.cn("text-lg font-semibold leading-none tracking-tight",t),...e}));ln.displayName=ie.Title.displayName;const Dl=D.forwardRef(({className:t,...e},n)=>a.jsx(ie.Description,{ref:n,className:B.cn("text-sm text-muted-foreground",t),...e}));Dl.displayName=ie.Description.displayName;const Qn=({assetId:t,children:e,onSelect:n,mode:s="image"})=>{const[r,o]=g.useState(!1),i=B.useMediaManagerComponent(),l=(...c)=>{n.call(void 0,...c),o(!1)};return a.jsxs(Pn,{open:r,onOpenChange:c=>o(c),children:[a.jsx(Pl,{asChild:!0,children:e}),a.jsxs(an,{className:"flex max-h-[90vh] max-w-7xl border-border md:w-fit",children:[a.jsx(ln,{className:"sr-only",children:"Media Manager"}),a.jsx("div",{className:"h-full w-full",children:i?a.jsx(i,{close:()=>o(!1),onSelect:l,mode:s,assetId:t}):null})]})]})};Qn.displayName="MediaManagerModal";const Yn="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTAwIiBoZWlnaHQ9IjQwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZjNmNGY2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCwgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNiIgZmlsbD0iI2Q1ZDdkYSIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPkltYWdlIFBsYWNlaG9sZGVyPC90ZXh0Pjwvc3ZnPg==",Bm=t=>{var r;if(!t||d.startsWith(t,"data"))return"";const e=((r=t.split("/").pop())==null?void 0:r.split("?")[0])||"";return[".jpg",".jpeg",".png",".gif",".webp",".svg",".bmp",".ico",".avif"].some(o=>e.toLowerCase().endsWith(o))?e:""},Rm=({value:t,onChange:e,id:n,onBlur:s,uiSchema:r})=>{const{t:o}=F.useTranslation(),{selectedLang:i}=Te(),l=J(),c=nt(),u=tn(),p=(r==null?void 0:r["ui:allowEmpty"])===!0,f=n.split(".").pop()||"",m=i?`_${f}Id-${i}`:`_${f}Id`,h=d.isEmpty(i)&&(l==null?void 0:l._type)==="Image"&&d.has(l,"assetId"),x=d.get(l,m,h?l==null?void 0:l.assetId:""),b=g.useMemo(()=>{if(!t||!l||!/\{\{.*?\}\}/.test(t))return t;const I={...l,[f]:t},_=be.applyBindingToBlockProps(I,u,{index:-1,key:""});return d.get(_,f,t)},[t,l,u,f]),y=!!x||b!==Yn&&b!=="",v=E=>{const I=d.isArray(E)?d.first(E):E;if(I){e(I==null?void 0:I.url);const _=I==null?void 0:I.width,S=I==null?void 0:I.height,A=m.includes("mobile");if(l!=null&&l._id){const C={..._&&{[A?"mobileWidth":"width"]:_},...S&&{[A?"mobileHeight":"height"]:S},...I.description&&{alt:I.description}};if(d.set(C,m,I.id),d.isEmpty(C))return;c([l._id],C)}}},w=g.useCallback(()=>{if(e(p?"":Yn),l!=null&&l._id){const I={},_=m.includes("mobile");d.set(I,m,""),d.set(I,_?"mobileWidth":"width",""),d.set(I,_?"mobileHeight":"height",""),c([l._id],I)}},[l,e,c,m,p]),N=Bm(b);return a.jsxs("div",{className:"mt-1.5 flex items-start gap-x-3",children:[b?a.jsxs("div",{className:"group relative",children:[a.jsx("img",{src:b,className:"h-14 w-14 overflow-hidden rounded-md border border-border object-cover transition duration-200 "+(x&&x!==""?"cursor-pointer group-hover:blur-sm":""),alt:""}),y&&a.jsx("button",{type:"button",onClick:w,className:"absolute -right-2 -top-2 z-20 rounded-full bg-destructive p-1 text-destructive-foreground hover:bg-destructive/90",children:a.jsx(k.Cross1Icon,{className:"h-3 w-3"})}),x&&x!==""&&a.jsx(Qn,{onSelect:v,assetId:x,children:a.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:a.jsx(k.Pencil2Icon,{className:"h-4 w-4 text-white"})})})]}):a.jsx(Qn,{onSelect:v,mode:"image",assetId:x,children:a.jsx("div",{className:"h-14 w-14 cursor-pointer rounded-md border border-border bg-[radial-gradient(#AAA,transparent_1px)] duration-300 [background-size:10px_10px]"})}),a.jsxs("div",{className:"flex w-3/5 flex-col",children:[a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"max-w-[250px] truncate pr-2 text-xs text-gray-400",children:N}),a.jsx(Qn,{onSelect:v,assetId:"",children:a.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?o("Replace image"):o("Choose image")})}),a.jsx("div",{className:"text-center text-xs text-gray-400",children:"OR"})]}),a.jsx("input",{id:n,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",type:"url",className:"h-6 text-xs",placeholder:o("Enter image URL"),value:t===Yn?"":t,onBlur:({target:{value:E}})=>s(n,E),onChange:E=>e(E.target.value)})]})]})},Pm=vr.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 _s({className:t,variant:e,...n}){return a.jsx("div",{className:B.cn(Pm({variant:e}),t),...n})}const ms=Jt.Provider,fe=Jt.Root,he=Jt.Trigger,ce=D.forwardRef(({className:t,sideOffset:e=4,...n},s)=>a.jsx(Jt.Portal,{children:a.jsx(Jt.Content,{ref:s,sideOffset:e,className:B.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})}));ce.displayName=Jt.Content.displayName;const co=D.forwardRef(({className:t,...e},n)=>a.jsx(De.Command,{ref:n,className:B.cn("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",t),...e}));co.displayName=De.Command.displayName;const uo=D.forwardRef(({className:t,...e},n)=>a.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[a.jsx(k.MagnifyingGlassIcon,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),a.jsx(De.Command.Input,{ref:n,className:B.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})]}));uo.displayName=De.Command.Input.displayName;const po=D.forwardRef(({className:t,...e},n)=>a.jsx(De.Command.List,{ref:n,className:B.cn("max-h-[300px] overflow-y-auto overflow-x-hidden",t),...e}));po.displayName=De.Command.List.displayName;const fo=D.forwardRef((t,e)=>a.jsx(De.Command.Empty,{ref:e,className:"py-6 text-center text-sm",...t}));fo.displayName=De.Command.Empty.displayName;const ho=D.forwardRef(({className:t,...e},n)=>a.jsx(De.Command.Group,{ref:n,className:B.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}));ho.displayName=De.Command.Group.displayName;const Lm=D.forwardRef(({className:t,...e},n)=>a.jsx(De.Command.Separator,{ref:n,className:B.cn("-mx-1 h-px bg-border",t),...e}));Lm.displayName=De.Command.Separator.displayName;const gs=D.forwardRef(({className:t,...e},n)=>a.jsx(De.Command.Item,{ref:n,className:B.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}));gs.displayName=De.Command.Item.displayName;const mo=vn.Root,go=vn.Trigger,Bs=D.forwardRef(({className:t,align:e="center",sideOffset:n=4,...s},r)=>a.jsx(vn.Portal,{children:a.jsx(vn.Content,{ref:r,align:e,sideOffset:n,className:B.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})}));Bs.displayName=vn.Content.displayName;const Mm=({data:t,onSelect:e,dataType:n})=>{const[s,r]=g.useState([]),[o,i]=g.useState(t),l=f=>Array.isArray(f)?"array":typeof f=="object"&&f!==null?"object":"value",c=g.useCallback(f=>{const m=h=>n==="value"?h==="value"||h==="object":n==="array"?h==="array":h===n;f.type==="object"?(r(h=>[...h,f.key]),i(f.value)):m(f.type)&&e([...s,f.key].join("."),n)},[s,e,n]),u=g.useCallback(()=>{if(s.length>0){const f=s.slice(0,-1);r(f),i(f.reduce((m,h)=>m[h],t))}},[s,t]),p=g.useMemo(()=>o?Object.entries(o).map(([f,m])=>({key:f,value:m,type:l(m)})).filter(f=>!d.startsWith(f.key,q.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):[],[o,n]);return a.jsxs(co,{className:"fields-command",children:[a.jsx(uo,{className:"border-none",placeholder:"Search..."}),a.jsxs(po,{children:[a.jsx(fo,{children:gt.t("No option found.")}),a.jsxs(ho,{children:[s.length>0&&a.jsxs(gs,{onSelect:u,className:"flex items-center text-sm",children:[a.jsx(k.ChevronLeftIcon,{className:"mr-2 h-4 w-4"}),gt.t("Back")]}),p.map(f=>a.jsxs(gs,{value:f.key,disabled:!1,onSelect:()=>c(f),className:"flex items-center justify-between",children:[a.jsxs("span",{className:"flex items-center gap-x-2",children:[d.startsWith(f.key,q.REPEATER_PREFIX)?a.jsx(k.LoopIcon,{}):d.startsWith(f.key,q.COLLECTION_PREFIX)?a.jsx(k.IdCardIcon,{}):null,d.startsWith(f.key,q.REPEATER_PREFIX)?gt.t("Repeater Data"):d.startsWith(f.key,q.COLLECTION_PREFIX)?f.key.replace(q.COLLECTION_PREFIX,""):f.key]}),a.jsxs("div",{className:"flex items-center gap-2",children:[n==="object"&&f.type==="object"&&a.jsx(B.Button,{size:"sm",variant:"ghost",className:"h-6 px-2 hover:bg-primary hover:text-primary-foreground",onClick:m=>{m.stopPropagation(),e([...s,f.key].join("."),n)},children:gt.t("Select")}),f.type==="object"&&a.jsx("div",{className:"cursor-pointer rounded p-1 hover:bg-muted",children:a.jsx(k.ChevronRightIcon,{className:"h-4 w-4 opacity-50"})})]})]},f.key))]})]})]})};function xo({data:t,onSelect:e,dataType:n="value"}){const[s,r]=g.useState(!1),o=$("collections",[]),i=g.useMemo(()=>n==="array"?{...o.map(c=>c.id).reduce((c,u)=>({...c,[q.COLLECTION_PREFIX+u]:[]}),{}),...t}:t,[t,o,n]);return a.jsxs(mo,{open:s,onOpenChange:r,children:[a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(go,{asChild:!0,children:a.jsx(B.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:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24px",height:"24px",viewBox:"0 0 24 24",fill:"none",children:a.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"})})})})}),a.jsx(ce,{children:gt.t("Add field")})]}),a.jsx(Bs,{className:"z-[1000]! relative mr-3 w-[300px] p-0",children:a.jsx(Mm,{data:i,onSelect:(l,c)=>{e(l,c),r(!1)},dataType:n})})]})}const Ol=({schema:t,onChange:e,id:n,formData:s})=>{const r=tn(),o=$("flags.dataBinding",!0),i=_d(),l=J(),c=g.useMemo(()=>{if(i.length===1)return"";const f=i.find(x=>x._type==="Repeater"),h=d.get(f,"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1");return`${q.REPEATER_PREFIX}${d.startsWith(h,q.COLLECTION_PREFIX)?`${h}/${f==null?void 0:f._id}`:h}`},[i]),u=g.useMemo(()=>d.first(d.get(r,c.replace(q.REPEATER_PREFIX,""),[])),[c,r]),p=g.useCallback((f,m)=>{if(f=d.isEmpty(c)?f:f.replace(`${c}`,"$index"),m==="array"||m==="object"){e(`{{${f}}}`,{},n);return}const h=v=>/[.,!?;:]/.test(v),x=(v,w,N)=>{let E="",I="";const _=w>0?v[w-1]:"",S=w<v.length?v[w]:"";return w>0&&(_==="."||!h(_)&&_!==" ")&&(E=" "),w<v.length&&!h(S)&&S!==" "&&(I=" "),{text:E+N+I,prefixLength:E.length,suffixLength:I.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 v=y.__chaiRTE;if(v){const w=`{{${f}}}`;v.commands.focus();const{from:N,to:E}=v.state.selection;if(N!==E)v.chain().deleteSelection().insertContent(w).run();else{const{state:_}=v,S=_.selection.from,A=_.doc.textBetween(Math.max(0,S-1),S),C=_.doc.textBetween(S,Math.min(S+1,_.doc.content.size));let T="";S>0&&A!==" "&&!h(A)&&(T=" ");let P="";C&&C!==" "&&!h(C)&&(P=" "),v.chain().insertContent(T+w+P).run()}setTimeout(()=>e(v.getHTML(),{},n),100);return}}else{const v=b,w=v.selectionStart||0,N=v.value||"",E=v.selectionEnd||w;if(E>w){const C=`{{${f}}}`,{text:T}=x(N,w,C),P=N.slice(0,w)+T+N.slice(E);e(P,{},n);return}const _=`{{${f}}}`,{text:S}=x(N,w,_),A=N.slice(0,w)+S+N.slice(w);e(A,{},n)}},[n,e,s,l==null?void 0:l._id,c]);return o?a.jsx(xo,{data:{...u&&{[c]:u},...r},onSelect:p,dataType:t.binding==="array"?"array":"value"}):null},Dm=t=>{const{id:e,classNames:n,label:s,children:r,errors:o,help:i,hidden:l,required:c,schema:u,formData:p,onChange:f}=t,{selectedLang:m,fallbackLang:h,languages:x}=Te(),b=g.useMemo(()=>d.isEmpty(x)?"":d.isEmpty(m)?h:m,[x,m,h]),y=g.useMemo(()=>d.get(Ot,b,b),[b]),v=tn(),w=J(),N=X.useRegisteredChaiBlocks(),E=g.useMemo(()=>d.get(N,[w==null?void 0:w._type,"i18nProps"],[]),[N,w==null?void 0:w._type]),[I,_]=g.useState(null);if(l)return null;if(u.type==="boolean")return a.jsx("div",{className:n,children:r});const A=E==null?void 0:E.includes(e.replace("root.",""));if(u.type==="array"){const P=I===e;return a.jsxs("div",{className:`${n} relative`,children:[u.title&&a.jsx("div",{className:"flex items-center justify-between gap-1",children:a.jsxs("label",{htmlFor:e,onClick:()=>_(P?null:e),className:"flex cursor-pointer items-center gap-x-1 py-1 leading-tight duration-200 hover:bg-slate-100",children:[P?a.jsx(k.ChevronDownIcon,{className:"h-3 w-3"}):a.jsx(k.ChevronRightIcon,{className:"h-3 w-3"}),a.jsx(k.ListBulletIcon,{className:"h-3 w-3"}),a.jsx("span",{className:"leading-tight",children:s})," ",a.jsx(_s,{className:"m-0 bg-gray-200 px-2 leading-tight text-gray-500 hover:bg-gray-200 hover:text-gray-500",children:a.jsx("span",{className:"text-[9px] font-medium text-slate-600",children:p==null?void 0:p.length})}),u.description&&a.jsx(ms,{children:a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(k.InfoCircledIcon,{className:"h-3 w-3 text-muted-foreground/70",onClick:R=>R.stopPropagation(),onMouseDown:R=>R.stopPropagation()})}),a.jsx(ce,{className:"max-w-xs",children:u.description})]})})]})}),(p==null?void 0:p.length)===0?a.jsx("div",{className:"h-0 overflow-hidden",children:r}):a.jsxs("div",{className:`${P?"pt-0.5":"h-0 overflow-hidden"}`,children:[r,o,i]})]})}const C=e.replace("root.",""),T=E.includes(C)&&!d.isEmpty(m)&&d.isEmpty(p);return a.jsxs("div",{className:n,children:[u.title&&a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("label",{htmlFor:e,className:u.type==="object"?"pb-2":"",children:[s," ",A&&a.jsxs("small",{className:"text-[9px] text-zinc-400",children:[" ",y]}),c&&u.type!=="object"?" *":null]}),u.description&&a.jsx(ms,{children:a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(k.InfoCircledIcon,{className:"h-3 w-3 text-muted-foreground/70"})}),a.jsx(ce,{className:"max-w-xs",children:u.description})]})})]}),!u.enum&&!u.oneOf&&v&&a.jsxs("span",{className:"flex items-center space-x-1",children:[T?a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.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:[a.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"}),a.jsx("path",{d:"M12 9v4"}),a.jsx("path",{d:"M12 17h.01"})]})}),a.jsxs(ce,{className:"max-w-xs",children:["No translation provided. ",a.jsx("br",{}),"Using default language value."]})]}):null,a.jsx(Ol,{schema:u,onChange:P=>{f(P,p,e)},id:e,formData:p})]})]}),r,o,i]})},Om=({href:t,pageTypes:e,onChange:n})=>{var A;const{t:s}=F.useTranslation(),r=$("searchPageTypeItems",(C,T)=>[]),[o,i]=g.useState(!1),[l,c]=g.useState(!1),[u,p]=g.useState("page"),[f,m]=g.useState(""),[h,x]=g.useState([]),[b,y]=g.useState(-1),v=g.useRef(null),w=(A=e==null?void 0:e.find(C=>C.key===u))==null?void 0:A.name;g.useEffect(()=>{if(m(""),x([]),y(-1),c(!1),!t||o||!d.startsWith(t,"pageType:"))return;const C=d.split(t,":"),T=d.get(C,1,"page")||"page";p(T),(async()=>{const P=await r(T,[d.get(C,2,"page")]);P&&Array.isArray(P)&&m(d.get(P,[0,"name"],""))})()},[t]);const N=ke.useDebouncedCallback(async C=>{if(d.isEmpty(C))x([]);else{const T=await r(u,C);x(T)}i(!1),y(-1)},[u],300),E=C=>{const T=["pageType",u,C.primaryPage??C.id];T[1]&&(n(T.join(":")),m(C.name),c(!1),x([]),y(-1))},I=C=>{switch(C.key){case"ArrowDown":C.preventDefault(),y(T=>T<h.length-1?T+1:T);break;case"ArrowUp":C.preventDefault(),y(T=>T>0?T-1:T);break;case"Enter":if(C.preventDefault(),h.length===0)return;b>=0&&E(h[b]);break;case"Escape":C.preventDefault(),_();break}};g.useEffect(()=>{if(b>=0&&v.current){const C=v.current.children[b];C==null||C.scrollIntoView({block:"nearest"})}},[b]);const _=()=>{m(""),x([]),y(-1),c(!1),n("")},S=C=>{m(C),c(!d.isEmpty(C)),i(!0),N(C)};return a.jsxs("div",{children:[a.jsx("select",{name:"pageType",value:u,onChange:C=>p(C.target.value),children:d.map(e,C=>a.jsx("option",{value:C.key,children:C.name},C.key))}),u&&a.jsxs("div",{className:"group relative mt-2 flex items-center",children:[a.jsx("input",{type:"text",value:f,onChange:C=>S(C.target.value),onKeyDown:I,placeholder:s(`Search ${w??""}`),className:"w-full rounded-md border border-gray-300 p-2 pr-16"}),a.jsx("div",{className:"absolute bottom-2 right-2 top-3 flex items-center gap-1.5",children:f&&a.jsx("button",{onClick:_,className:"text-gray-400 hover:text-gray-600",title:s("Clear search"),children:a.jsx(k.Cross1Icon,{className:"h-4 w-4"})})})]}),(o||!d.isEmpty(h)||l&&d.isEmpty(h))&&a.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?a.jsxs("div",{className:"space-y-1 p-2",children:[a.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),a.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):l&&d.isEmpty(h)?a.jsxs("div",{className:"flex items-center justify-center p-4 text-sm text-gray-500",children:[s("No results found for"),' "',f,'"']}):a.jsx("ul",{ref:v,children:d.map(h==null?void 0:h.slice(0,20),(C,T)=>a.jsxs("li",{onClick:()=>E(C),className:`cursor-pointer p-2 text-xs ${t!=null&&t.includes(C.id)?"bg-blue-200":T===b?"bg-gray-100":"hover:bg-gray-100"}`,children:[C.name," ",C.slug&&a.jsxs("small",{className:"font-light text-gray-500",children:["( ",C.slug," )"]}),C.lang&&a.jsx("small",{className:"ml-1 rounded bg-gray-200 px-1 py-0.5 text-[10px] font-medium text-gray-600",children:C.lang})]},C.id))})})]})},$m=({schema:t,formData:e,onChange:n,name:s})=>{const{t:r}=F.useTranslation(),{type:o="pageType",href:i="",target:l="self"}=e??{},c=$("pageTypes",[]),{selectedLang:u,fallbackLang:p,languages:f}=Te(),m=g.useMemo(()=>d.isEmpty(f)?"":d.isEmpty(u)?p:u,[f,u,p]),h=g.useMemo(()=>d.get(Ot,m,m),[m]),x=o==="pageType"&&d.isEmpty(c)?"url":o;return a.jsxs("div",{children:[a.jsxs("span",{className:"flex items-center justify-between gap-x-2 text-xs font-medium",children:[a.jsxs("span",{children:[(t==null?void 0:t.title)??"Link",a.jsx("span",{className:"pl-1 text-[9px] text-zinc-400",children:h})]}),a.jsx(Ol,{schema:t,onChange:b=>{n({...e,href:b,...x==="pageType"?{type:"url"}:{}})},id:`root.${s}.href`,formData:e})]}),a.jsxs("div",{className:"flex flex-col gap-y-1.5",children:[a.jsx("select",{name:"type",value:o,onChange:b=>n({...e,type:b.target.value}),children:d.map([...d.isEmpty(c)?[]:[{const:"pageType",title:r("Goto Page")}],{const:"url",title:r("Open URL")},{const:"email",title:r("Compose Email")},{const:"telephone",title:r("Call Phone")},{const:"scroll",title:r("Scroll to element")}],b=>a.jsx("option",{value:b.const,children:b.title},b.const))}),x==="pageType"&&!d.isEmpty(c)?a.jsx(Om,{href:i,pageTypes:c,onChange:b=>n({...e,href:b})}):null,a.jsx("input",{id:`root.${s}.href`,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",name:"href",type:"text",className:x==="pageType"?"!hidden":"",value:i,onChange:b=>n({...e,href:b.target.value}),placeholder:r(o==="url"?"Enter URL":o==="scroll"?"#ElementID":"Enter details")}),x==="url"&&a.jsxs("div",{className:"flex items-center gap-x-2 text-muted-foreground",children:[a.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"})}),a.jsx("span",{className:"pt-1 text-xs",children:r("Open in new tab")})]})]})]})},Fm=({value:t,onChange:e})=>{var o;if(!t)return a.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:[a.jsx(k.FileIcon,{className:"h-4 w-4"})," Choose a collection"]});const n=`{{${q.COLLECTION_PREFIX}`,s=t==null?void 0:t.startsWith(n);let r=t;return s&&(r=(o=t==null?void 0:t.replace(n,""))==null?void 0:o.replace("}}","")),a.jsx("div",{className:"mt-1 flex flex-col gap-1",children:a.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:[a.jsxs("span",{className:"flex max-w-[200px] items-center gap-2",children:[" ",s?a.jsx(k.IdCardIcon,{className:"h-3 min-h-3 w-3 min-w-3"}):null,a.jsxs(fe,{delayDuration:500,children:[a.jsx(he,{asChild:!0,children:a.jsx("span",{className:"cursor-default truncate",children:r})}),a.jsx(ce,{side:"left",hidden:r.length<50,children:r})]})]}),a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(B.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:a.jsx(k.Cross1Icon,{className:"h-4 w-4"})})}),a.jsx(ce,{side:"left",children:"Remove binding"})]})]})})},$l=j.atom(t=>{var i;const e=t(je),n=t(ys),s=n.length===1?n[0]:null;if(!s)return null;const r=d.find(e,{_id:s});if(!r)return null;let o=r._parent;for(;o;){const l=d.find(e,{_id:o});if(!l)return null;if((i=X.getRegisteredChaiBlock(l._type))!=null&&i.wrapper)return l;o=l._parent}return null});$l.debugLabel="wrapperBlockAtom";const bo=()=>j.useAtomValue($l),zm=()=>{const t=J(),e=bo(),{addCoreBlock:n}=bt();if(!t&&!e)return null;const s=(t==null?void 0:t._type)==="Row"?t:e;return a.jsx("div",{className:"pt-1",children:a.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:[a.jsx(k.PlusIcon,{className:"h-4 w-4"})," Add Column"]})})},Hm=g.lazy(()=>Promise.resolve().then(()=>require("./rte-widget-modal-O31cHitM.cjs"))),Vm=({blockId:t,id:e,placeholder:n,value:s,onChange:r,onBlur:o})=>{const i=g.useRef(null),[l,c]=g.useState(!1),u=Al({blockId:t,value:s,placeholder:n,onBlur:({editor:m})=>{const h=m==null?void 0:m.getHTML();o(e,h)},onUpdate:({editor:m})=>{const h=m==null?void 0:m.getHTML();r(h)}});g.useEffect(()=>{i.current&&u&&(i.current.__chaiRTE=u)},[t,u]);const p=()=>{c(!1)},f=a.jsxs("div",{id:`chai-rte-${e}`,ref:i,className:"mt-1 rounded-md border border-input",children:[a.jsx(Pi,{editor:u,onExpand:()=>c(!0)}),a.jsx(ns.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 a.jsxs(a.Fragment,{children:[l&&a.jsx(g.Suspense,{fallback:a.jsx("div",{children:"Loading..."}),children:a.jsx(Hm,{isOpen:l,onClose:p,editor:u,rteElement:f})}),l?a.jsx("div",{children:"Open in modal"}):a.jsx("div",{className:"relative",children:f})]})},Wm=t=>{const{editingBlockId:e}=Ft(),[n,s]=g.useState(null),r=J(),o=r==null?void 0:r._id;return g.useEffect(()=>{s(o)},[o]),n&&n!==e?a.jsx(Vm,{...t,blockId:n},n):null},Gm=({formData:t,onChange:e})=>{const[n]=te(),s=J(),r=bo(),{addCoreBlock:o}=bt(),[,i]=U(),l=(s==null?void 0:s._type)==="Slider"?s:r,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&&!r||!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}),i([y])}},m=()=>{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}),i([y])}},h=()=>{const x=o({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}),i([b]))};return a.jsxs("div",{className:"space-y-1.5 px-2",children:[a.jsxs("div",{className:"flex items-center gap-x-2 pb-2 text-[12px]",children:[a.jsx("button",{onClick:m,className:"rounded bg-gray-200 p-1.5 hover:opacity-80",children:a.jsx(k.ChevronLeftIcon,{className:"h-3 w-3"})}),a.jsx("div",{className:"whitespace-nowrap text-center text-[10px] text-slate-500",children:p?a.jsxs("span",{className:"",children:[a.jsxs("b",{className:"text-[12px]",children:[" ",d.findIndex(u,{_id:p})+1]}),"/",u.length]}):"-"}),a.jsx("button",{onClick:f,className:"rounded bg-gray-200 p-1.5 hover:opacity-80",children:a.jsx(k.ChevronRightIcon,{className:"h-3 w-3"})}),a.jsxs("button",{onClick:h,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:[a.jsx(k.PlusCircledIcon,{className:"h-3 w-3"}),"Add Slide"]})]}),a.jsxs("div",{className:"flex items-center gap-x-2 leading-tight",children:[a.jsx("input",{type:"checkbox",checked:!!(t!=null&&t.showSlideButton),onChange:()=>e({...t,showSlideButton:!(t!=null&&t.showSlideButton)}),className:"cursor-pointer"}),a.jsx("label",{htmlFor:"autoplay",className:"mt-0.5 text-[12px]",children:"Show Slide Buttons"})]}),a.jsxs("div",{className:"flex items-center gap-x-2 leading-tight",children:[a.jsx("input",{type:"checkbox",checked:!!(t!=null&&t.showSlideNavbar),onChange:()=>e({...t,showSlideNavbar:!(t!=null&&t.showSlideNavbar)}),className:"cursor-pointer"}),a.jsx("label",{htmlFor:"autoplay",className:"mt-0.5 text-[12px]",children:"Show Slide Navbar"})]}),a.jsx("div",{children:a.jsxs("div",{className:"flex flex-col",children:[a.jsxs("div",{className:"flex items-center gap-x-2 leading-tight",children:[a.jsx("input",{type:"checkbox",checked:!!(t!=null&&t.autoplay),onChange:()=>e({...t,autoplay:!(t!=null&&t.autoplay)}),className:"cursor-pointer"}),a.jsx("label",{htmlFor:"autoplay",className:"mt-0.5 text-[12px]",children:"Autoplay slides"})]}),(t==null?void 0:t.autoplay)&&a.jsxs("div",{className:"pt-0.5 leading-tight",children:[a.jsxs("label",{htmlFor:"interval",className:"whitespace-nowrap text-[9px]",children:["Autoplay Interval ",a.jsx("span",{className:"font-light opacity-80",children:"(in seconds)"})]}),a.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})}})]})]})})]})},Um=({formData:t,onChange:e})=>{const n=d.get(t,"srcsets",[])||[],s=(i,l)=>{const c=i.target.name,u=i.target.value;e({srcsets:d.map(n,(p,f)=>f===l?{...p,[c]:u}:p)})},r=()=>{e({srcsets:[...n,{}]})},o=i=>{e({srcsets:d.reject(n,(l,c)=>parseInt(c)===i)})};return a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between pb-2",children:[a.jsx("label",{children:"Responsive Video (optional)"}),a.jsx("button",{type:"button",onClick:r,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:a.jsx(k.PlusIcon,{className:"h-3 w-3"})})]}),a.jsx("div",{className:"space-y-2",children:n.length===0?a.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,(i,l)=>a.jsxs("div",{className:"group relative space-y-1.5 rounded border border-gray-200 px-2 pb-1.5",children:[a.jsx("button",{type:"button",onClick:()=>o(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:a.jsx(k.Cross1Icon,{className:"h-2.5 w-2.5 text-red-500"})}),a.jsxs("div",{className:"flex items-center gap-x-2 rounded border",children:[a.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"}),a.jsx("input",{name:"width",placeholder:"Enter width (in px)",type:"number",value:d.get(i,"width"),onChange:c=>s(c,l),className:"!placeholder:text-gray-100 !mt-0 !rounded-none !border-0 !p-0 !text-xs"})]}),a.jsxs("div",{className:"flex items-center gap-x-2 rounded border",children:[a.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"}),a.jsx("input",{name:"url",placeholder:"Enter url",className:"!mt-0 !rounded-none !border-0 !p-0 !text-xs !shadow-none",value:d.get(i,"url",""),onChange:c=>s(c,l)})]})]},l))})]})},qm=t=>a.jsx("button",{...t,className:"duration absolute right-2 top-2 cursor-pointer text-blue-400 hover:text-blue-500",children:a.jsxs("div",{className:"flex items-center gap-x-0.5 text-[11px] leading-tight",children:[a.jsx(k.PlusIcon,{className:"h-3 w-3"})," ",a.jsx("span",{children:"Add"})]})}),ga=g.memo(({blockId:t,schema:e,uiSchema:n,formData:s,onChange:r})=>{const{selectedLang:o}=Te(),i=B.useBlockSettingComponents("widget"),l=B.useBlockSettingComponents("field"),c=B.useBlockSettingComponents("template"),u=ke.useThrottledCallback(async({formData:p},f)=>{d.get(p,f)===void 0&&d.set(p,f,""),r({formData:p},f)},[r,o],400);return a.jsx(Zc,{widgets:{richtext:Wm,icon:Tm,image:Rm,code:Nm,colCount:zm,collectionSelect:Em,repeaterBinding:Fm,...i},fields:{link:$m,slider:Gm,sources:Um,...l},templates:{FieldTemplate:Dm,ButtonTemplates:{AddButton:qm},...c},idSeparator:".",autoComplete:"off",omitExtraData:!1,liveOmit:!1,liveValidate:!1,validator:Qc,uiSchema:n,schema:e,formData:s,onChange:({formData:p},f)=>{if(!f||t!==(p==null?void 0:p._id))return;const m=d.take(f.split("."),2).join(".").replace("root.","");u({formData:p},m)}},o)}),xa=(t,e,n)=>{const s=d.cloneDeep(t);return d.forEach(d.keys(t),r=>{d.includes(d.get(n,"i18nProps",[]),r)&&!d.isEmpty(e)&&(s[r]=d.get(t,`${r}-${e}`))}),s};function fr(){const{selectedLang:t}=Te(),e=J(),n=_r(),s=nt(),r=X.getRegisteredChaiBlock(e==null?void 0:e._type),o=xa(e,t,r),[i,l]=g.useState(o),[c,u]=g.useState(!1),p=bo(),f=X.getRegisteredChaiBlock(p==null?void 0:p._type),m=xa(p,t,f),h=({formData:I},_,S)=>{_&&(i==null?void 0:i._id)===e._id&&s([e._id],{[_]:d.get(I,_)},S)},x=g.useCallback(d.debounce(({formData:I},_,S)=>{h({formData:I},_,S),l(I)},1500),[e==null?void 0:e._id,t]),b=({formData:I},_)=>{_&&(n([e._id],{[_]:d.get(I,_)}),x({formData:I},_,{[_]:d.get(i,_)}))},y=({formData:I},_)=>{_&&(n([p._id],{[_]:d.get(I,_)}),x({formData:I},_,{[_]:d.get(i,_)}))},{schema:v,uiSchema:w}=g.useMemo(()=>{const I=e==null?void 0:e._type;if(!I)return{schema:{},uiSchema:{}};try{const{schema:_,uiSchema:S}=X.getBlockFormSchemas(I);if(I==="Repeater"){const A=d.get(e,"repeaterItems","");d.startsWith(A,`{{${q.COLLECTION_PREFIX}`)?(d.set(S,"filter",{"ui:widget":"collectionSelect"}),d.set(S,"sort",{"ui:widget":"collectionSelect"})):(d.set(S,"filter",{"ui:widget":"hidden"}),d.set(S,"sort",{"ui:widget":"hidden"}))}return{schema:_,uiSchema:S}}catch{return{schema:{},uiSchema:{}}}},[e]),{wrapperSchema:N,wrapperUiSchema:E}=g.useMemo(()=>{if(!p||!(p!=null&&p._type))return{wrapperSchema:{},wrapperUiSchema:{}};const I=p==null?void 0:p._type,{schema:_={},uiSchema:S={}}=X.getBlockFormSchemas(I);return{wrapperSchema:_,wrapperUiSchema:S}},[p]);return a.jsxs("div",{className:"no-scrollbar overflow-x-hidden px-px",children:[!d.isEmpty(p)&&a.jsxs("div",{className:"mb-4 rounded border bg-zinc-100 px-1",children:[a.jsxs("div",{onClick:()=>u(I=>!I),className:"flex cursor-pointer items-center gap-x-1 py-2 text-xs font-medium leading-tight hover:bg-slate-100",children:[c?a.jsx(k.ChevronDownIcon,{className:"h-4 w-4 text-slate-400"}):a.jsx(k.ChevronRightIcon,{className:"h-4 w-4 text-slate-400"}),d.startCase(p._type)," settings"," ",p._name&&a.jsxs("span",{className:"text-[11px] font-light text-slate-400",children:["(",p._name,")"]})]}),a.jsx("div",{className:c?"h-auto":"invisible h-0",children:a.jsx(ga,{blockId:p==null?void 0:p._id,onChange:y,formData:m,schema:N,uiSchema:E})})]}),d.isEmpty(v)?null:a.jsx(ga,{blockId:e==null?void 0:e._id,onChange:b,formData:o,schema:v,uiSchema:w})]})}const Fl=Pt.Root,yo=D.forwardRef(({className:t,...e},n)=>a.jsx(Pt.Item,{ref:n,className:B.cn("border-b",t),...e}));yo.displayName="AccordionItem";const vo=D.forwardRef(({className:t,children:e,...n},s)=>a.jsx(Pt.Header,{className:"flex",children:a.jsxs(Pt.Trigger,{ref:s,className:B.cn("flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline text-left [&[data-state=open]>svg]:rotate-180",t),...n,children:[e,a.jsx(k.ChevronDownIcon,{className:"h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200"})]})}));vo.displayName=Pt.Trigger.displayName;const ko=D.forwardRef(({className:t,children:e,...n},s)=>a.jsx(Pt.Content,{ref:s,className:"overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...n,children:a.jsx("div",{className:B.cn("pb-4 pt-0",t),children:e})}));ko.displayName=Pt.Content.displayName;const Km=j.atom(null,(t,e,{blockIds:n,fullClasses:s})=>{const r=d.first(t(Bn)),o=d.filter(t(En),i=>n.includes(t(i)._id));return d.map(o,i=>{const l=t(i),c=s;let{classes:u,baseClasses:p}=be.getSplitChaiClasses(d.get(l,r.prop,`${q.STYLES_KEY},`));return d.each(c,f=>{const m=f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),h=new RegExp(`(^|\\s)${m}(?=\\s|$)`,"g");u=u.replace(h," ").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 m=f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),h=new RegExp(`(^|\\s)${m}(?=\\s|$)`,"g");p=p.replace(h," ").replace(/\s+/g," ").trim()}),{ids:[l._id],props:{[r.prop]:`${q.STYLES_KEY}${p},${u}`}}})}),Ym=t=>{const e=Object.keys(t).filter(s=>typeof t[s]=="string"&&t[s].startsWith(q.STYLES_KEY)),n={};return e.forEach(s=>{n[s]=`${q.STYLES_KEY},`}),{ids:[t._id],props:n}},Xm=()=>{const{updateBlocks:t,updateBlocksRuntime:e}=Ne();return g.useCallback((n,s=!1)=>{const{ids:r,props:o}=Ym(n);s?t(r,o):e(r,o)},[t,e])},wo=()=>{const{updateBlocks:t,updateBlocksRuntime:e}=Ne(),n=j.useSetAtom(Km);return g.useCallback((s,r,o=!1)=>{const i=n({blockIds:s,fullClasses:r});o?t(s,i[0].props):e(s,i[0].props)},[n])},zl=()=>{const t=J(),e=nt(),n=g.useCallback(i=>X.getDefaultBlockProps(i)||{},[]),s=g.useCallback(i=>Object.keys(i).filter(l=>typeof i[l]=="string"&&i[l].startsWith("#styles:")),[]),r=g.useCallback(i=>{if(!t)return;const c=n(t._type)[i]??"#styles:,";e([t._id],{[i]:c})},[t,n,e]);return{resetAll:g.useCallback(()=>{if(!t)return;const i=s(t);if(i.length===0)return;const l=n(t._type),c=d.pick(l,i);e([t._id],c)},[t,s,n,e]),reset:r}},Jm=()=>{var h;const t=J(),[e,n]=Ee(),s=wo(),[r]=U(),{t:o}=F.useTranslation(),{reset:i}=zl();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,(h=e[0])==null?void 0:h.prop,""),{classes:p=""}=be.getSplitChaiClasses(u)||{},f=p?p.split(" ").filter(x=>!d.isEmpty(x)):[],m=x=>d.find(e,b=>b.prop===x);return a.jsx(a.Fragment,{children:c&&a.jsxs("div",{className:"flex flex-wrap gap-1",children:[a.jsxs("label",{htmlFor:"block-styling-props",className:"py-1 text-xs",children:[o("Style element"),":"]}),a.jsx("div",{className:"flex flex-wrap gap-2",children:d.map(l,x=>a.jsxs(_s,{className:"flex cursor-pointer items-center gap-1 pr-1",variant:m(x)?"default":"secondary",onClick:()=>{n([{id:`${x}-${t._id}`,blockId:t._id,prop:x}])},children:[d.startCase(x),a.jsxs(et,{children:[a.jsx(tt,{asChild:!0,children:a.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:a.jsx(k.DotsVerticalIcon,{className:"h-3 w-3"})})}),a.jsxs(Ge,{side:"bottom",className:"border-border text-xs",children:[a.jsx(le,{className:"text-xs",onClick:()=>{i(x)},children:o("Reset style")}),a.jsx(le,{className:"text-xs",onClick:()=>{s(r,f,!0)},children:o("Clear styles")})]})]})]},x))}),a.jsx("div",{className:"my-2 h-[1px] w-full bg-border"})]})})},Hl=g.createContext({setDragData:()=>{}}),ba=(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 r=t.match(s),o=r&&r.length>1,i=!d.isEmpty(n)&&Number.isNaN(Number(n));return o||i?{error:"Invalid value"}:r&&(r[0]==="auto"||r[0]==="none")?{value:r[0],unit:""}:{value:n,unit:r?r[0]:""}},Zm=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,r]=d.map(n.split("/"),o=>parseInt(o,10));return{value:e+(s/r*100).toFixed(2).replace(".00",""),unit:"%"}}return d.isNumber(parseFloat(n))?{value:`${e+parseFloat(n)*4}`,unit:"px"}:{value:n,unit:"class"}},Vl=t=>{if(d.isEmpty(t))return{value:"",unit:""};const e=t.match(/\[.*\]/g);if(e===null)return Qm(t);const n=d.get(e,"0","").replace(/\[|\]/g,""),s=t.startsWith("-")?"-":"",r=d.first(n.match(/\d+.\d+|\d+/g));return{value:`${s}${r}`,unit:n.replace(r,"")}},Qm=t=>d.isEmpty(t)?{value:"",unit:""}:Zm(t),eg=({unit:t,currentValue:e,onDrag:n,onDragEnd:s,onDragStart:r,negative:o,cssProperty:i})=>{const{setDragData:l}=g.useContext(Hl);return a.jsx("button",{type:"button",onMouseDown:c=>{const u={onDrag:n,onDragEnd:s,dragging:!0,dragStartY:c.pageY,dragStartValue:`${e}`,dragUnit:t,negative:o,cssProperty:i};r(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:a.jsx(k.RowSpacingIcon,{})})},tg=({onSelect:t,current:e,units:n})=>a.jsx("div",{"data-theme":"light",className:"-m-[7px] -mx-[13px] flex w-9 flex-col",children:n.map(s=>a.jsx(B.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:r=>{r.stopPropagation(),t(s)},children:s},s))}),ya=50,ng=t=>{const[e,n]=g.useState(!1),[s,r]=g.useState(""),{currentClass:o,onChange:i,classPrefix:l,cssProperty:c,units:u,negative:p}=t,[f,m]=g.useState(c!=null&&c.toLowerCase().includes("width")?"%":u[0]),[h,x]=g.useState(!1),[b,y]=g.useState(""),[v,w]=g.useState(!1),[N,E]=g.useState(!1);g.useEffect(()=>{const{value:C,unit:T}=Vl(o);if(T===""){r(C),m(c!=null&&c.toLowerCase().includes("width")?"%":d.first(u));return}m(T),r(T==="class"||d.isEmpty(C)?"":C)},[o,c,u]);const I=ke.useThrottledCallback(C=>i(C),[i],ya),_=ke.useThrottledCallback(C=>i(C,!1),[i],ya),S=g.useCallback((C=!1)=>{const T=ba(`${s}`,u);if(d.get(T,"error",!1)){x(!0);return}const P=d.get(T,"unit")!==""?d.get(T,"unit"):f;if(P==="auto"||P==="none"){I(`${l}${P}`);return}if(d.get(T,"value")==="")return;const O=`${d.get(T,"value","").startsWith("-")?"-":""}${l}[${d.get(T,"value","").replace("-","")}${P==="-"?"":P}]`;C?_(O):I(O)},[I,_,s,f,l,u]),A=g.useCallback(C=>{const T=ba(`${s}`,u);if(d.get(T,"error",!1)){x(!0);return}if(C==="auto"||C==="none"){I(`${l}${C}`);return}if(d.get(T,"value")==="")return;const P=d.get(T,"unit")!==""?d.get(T,"unit"):C,O=`${d.get(T,"value","").startsWith("-")?"-":""}${l}[${d.get(T,"value","").replace("-","")}${P==="-"?"":P}]`;I(O)},[I,s,l,u]);return a.jsx("div",{className:"flex w-full flex-col",children:a.jsx("div",{className:"flex items-center justify-start",children:f==="class"?a.jsxs(a.Fragment,{children:[a.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:o}),a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx("button",{type:"button",className:"invisible ml-3 mt-1 text-blue-600 group-hover:visible",children:a.jsx(k.InfoCircledIcon,{})})}),a.jsx(ce,{children:"Current value is using a Tailwind preset class."})]})]}):a.jsxs("div",{className:`group relative flex items-center ${v?"z-auto":""}`,children:[a.jsxs("div",{className:"flex items-center rounded-md border border-border",children:[["none","auto"].indexOf(f)!==-1?null:a.jsx("input",{readOnly:f==="class",onKeyPress:C=>{C.key==="Enter"&&S()},onKeyDown:C=>{if(C.keyCode!==38&&C.keyCode!==40)return;C.preventDefault(),E(!0);const T=d.parseInt(C.target.value);let P=d.isNaN(T)?0:T;C.keyCode===38&&(P+=1),C.keyCode===40&&(P-=1);const R=`${P}`,z=`${R.startsWith("-")?"-":""}${l}[${R.replace("-","")}${f==="-"?"":f}]`;_(z)},onKeyUp:C=>{N&&(C.preventDefault(),E(!1))},onBlur:()=>S(),onChange:C=>{x(!1),r(C.target.value)},onClick:C=>{var T;(T=C==null?void 0:C.target)==null||T.select(),n(!1)},value:v?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(" ",h?"border-red-500 text-red-500":"border-foreground/20")}),a.jsxs(fe,{open:e,delayDuration:100,children:[a.jsx(he,{asChild:!0,children:a.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:[a.jsx("span",{className:`inline-block ${u.length===1?"px-2 font-semibold":""}`,children:f}),u.length>1?a.jsx(k.TriangleDownIcon,{}):null]})}),a.jsx(ce,{className:"bg-background",children:a.jsx(tg,{units:u,current:f,onSelect:C=>{n(!1),m(C),A(C)}})})]})]}),["none","auto"].indexOf(f)!==-1||v?null:a.jsx(eg,{onDragStart:()=>w(!0),onDragEnd:C=>{if(y(()=>""),w(!1),d.isEmpty(C))return;const T=`${C}`,R=`${T.startsWith("-")?"-":""}${l}[${T.replace("-","")}${f==="-"?"":f}]`;I(R)},onDrag:C=>{if(d.isEmpty(C))return;y(C);const T=`${C}`,R=`${T.startsWith("-")?"-":""}${l}[${T.replace("-","")}${f==="-"?"":f}]`;_(R)},currentValue:s,unit:f,negative:p,cssProperty:c})]})})})},Mn=g.createContext({canReset:!1,canChange:!0}),sg=({children:t,canReset:e=!1,canChange:n=!0})=>a.jsx(Mn.Provider,{value:{canReset:e,canChange:n},children:t}),er=[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:[...er,"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:[...er,"px","0.5","1.5","2.5","3.5"],margin:["auto",...er,"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"]},Xt={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+|\\[.*\\])"}},rg={backgroundColor:"bg",textColor:"text",borderColor:"border",boxShadowColor:"shadow",outlineColor:"outline",divideColor:"divide",fromColor:"from",viaColor:"via",toColor:"to",ringColor:"ring",ringOffsetColor:"ring-offset"},og=["current","inherit","transparent","black","white"],ag=["slate","gray","zinc","neutral","stone","red","orange","amber","yellow","lime","green","emerald","teal","cyan","sky","blue","indigo","violet","purple","fuchsia","pink","rose"],ig=["50","100","200","300","400","500","600","700","800","900"],hr=d.map(d.values(rg),t=>t),lg=d.flattenDeep([...d.map(og,t=>d.flatten(d.map(hr,e=>`${e}-${t}`))),...d.map(ag,t=>d.flattenDeep(d.map(hr,e=>d.flattenDeep(d.map(ig,n=>`${e}-${t}-${n}`)))))]),cg=d.map(d.flattenDeep(d.values(Xt).map(t=>t.classes).concat(lg)),t=>({name:t})),dg=()=>{const t=In(),e=g.useMemo(()=>{let n=[];if(t.colors){const s=d.flattenDeep(d.map(t.colors,({items:r})=>d.keys(r)));n=d.flattenDeep(d.map(s,r=>d.flatten(d.map(hr,o=>`${o}-${r}`))))}return t.fontFamily&&(n=[...n,...d.map(d.keys(t.fontFamily),s=>`${s}`)]),d.map(n,s=>({name:s}))},[t]);return g.useMemo(()=>new Ma([...cg,...e],{isCaseSensitive:!1,threshold:.2,minMatchCharLength:2,keys:["name"]}),[e])},Rs=()=>{const t=In(),e=g.useMemo(()=>{if(t.colors){const r=d.flattenDeep(d.map(t.colors,({items:o})=>d.keys(o)));d.each(Xt,(o,i)=>{d.set(Xt,`${i}.regExp`,o.regExp.replace("__THEME_COLORS_REGEXP__",r.join("|")))})}return Xt},[t]),n=g.useCallback((r,o)=>{const i=d.get(e,`${r}.regExp`,"");return o.match(new RegExp(i))},[e]),s=g.useCallback((r,o=[])=>d.get(e,`${r}.classes`,o),[e]);return{match:n,getClasses:s}},Wl=({label:t,property:e,onChange:n})=>{const{getClasses:s}=Rs(),r=s(e),o=Dn(e),i=g.useMemo(()=>d.get(o,"cls",""),[o]),{canChange:l}=g.useContext(Mn),c=/\[.*\]/g.test(i);return a.jsx("div",{className:t?"w-full rounded":"grow",children:c?a.jsxs("div",{className:"flex items-center",children:[a.jsx(B.Input,{className:"w-[70%] rounded py-1",readOnly:!0,value:i}),a.jsxs(fe,{delayDuration:100,children:[a.jsx(he,{asChild:!0,children:a.jsx("button",{type:"button",className:"invisible ml-3 mt-1 text-blue-600 group-hover:visible",children:a.jsx(k.InfoCircledIcon,{})})}),a.jsx(ce,{children:"Current value is using a Tailwind arbitrary value."})]})]}):a.jsx(mr,{rounded:t,onChange:u=>n(u,e),selected:i,options:r,disabled:!l})})};function mr({selected:t,onChange:e,rounded:n=!1,options:s,disabled:r=!1}){const o=t.replace(/.*:/g,"").trim(),{undo:i,redo:l}=Tn();return a.jsxs("select",{disabled:!s.length||r,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"&&i(),c.key==="y"&&l())},value:o,children:[a.jsx("option",{className:"bg-transparent",value:""}),s.map((c,u)=>a.jsx("option",{className:"bg-transparent",value:c,children:c},`option-${u}`))]})}const ug={backgroundColor:"bg",textColor:"text",borderColor:"border",boxShadowColor:"shadow",outlineColor:"outline",divideColor:"divide",fromColor:"from",viaColor:"via",toColor:"to",ringColor:"ring",ringOffsetColor:"ring-offset"},pg=({property:t,onChange:e})=>{const n=Dn(t),s=g.useMemo(()=>d.get(n,"cls",""),[n]),{canChange:r}=g.useContext(Mn),[o,i]=g.useState([]),[l,c]=g.useState({color:"",shade:""}),u=s.split("-"),p=d.get(u,"1",""),f=d.get(u,"2",""),m=g.useCallback(b=>{["current","inherit","transparent","black","white"].includes(b)?(i([]),c({color:b})):(i(["50","100","200","300","400","500","600","700","800","900"]),c(y=>({...y,color:b,shade:y.shade?y.shade:"500"})))},[i,c]);g.useEffect(()=>{if(["current","inherit","transparent","black","white"].includes(p))return i([]);i(["50","100","200","300","400","500","600","700","800","900"])},[p]);const h=g.useCallback(b=>{c({color:p,shade:b})},[p]);g.useEffect(()=>{c({color:"",shade:""})},[n]);const{match:x}=Rs();return g.useEffect(()=>{const y=`${d.get(ug,t,"")}-${l.color}${l.shade?`-${l.shade}`:""}`;x(t,y)&&e(y,t)},[x,l,e,t]),a.jsxs("div",{className:"flex flex-row divide-x divide-solid divide-border rounded-lg border border-transparent text-xs",children:[a.jsx("div",{className:"grow text-center",children:a.jsx(mr,{disabled:!r,rounded:!0,selected:p,onChange:m,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"]})}),a.jsx("button",{type:"button",className:"grow text-center",children:a.jsx(mr,{rounded:!0,selected:f,disabled:!p||!r,onChange:h,options:o})})]})},Gl={"not-italic":()=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9 3H11V5H9V11H11V13H5V11H7V5H5V3H9Z",fill:"white"})}),visible:k.EyeOpenIcon,invisible:k.EyeClosedIcon,hidden:k.EyeClosedIcon,gap:k.BorderAllIcon,gapX:k.WidthIcon,gapY:k.HeightIcon,spaceX:k.WidthIcon,spaceY:k.HeightIcon,overscroll:k.BorderAllIcon,overscrollX:k.WidthIcon,overscrollY:k.HeightIcon,overflow:k.BorderAllIcon,overflowX:k.WidthIcon,overflowY:k.HeightIcon,top:k.ArrowUpIcon,right:k.ArrowRightIcon,bottom:k.ArrowDownIcon,left:k.ArrowLeftIcon,inset:k.BorderAllIcon,insetX:k.WidthIcon,insetY:k.HeightIcon,border:k.BorderAllIcon,borderX:k.WidthIcon,borderY:k.HeightIcon,borderTop:k.ArrowUpIcon,borderRight:k.ArrowRightIcon,borderBottom:k.ArrowDownIcon,borderLeft:k.ArrowLeftIcon,borderRadius:k.BorderAllIcon,borderRadiusX:k.WidthIcon,borderRadiusY:k.HeightIcon,borderRadiusTop:k.ArrowUpIcon,borderRadiusRight:k.ArrowRightIcon,borderRadiusBottom:k.ArrowDownIcon,borderRadiusLeft:k.ArrowLeftIcon,borderRadiusTopLeft:k.ArrowTopLeftIcon,borderRadiusTopRight:k.ArrowTopRightIcon,borderRadiusBottomRight:k.ArrowBottomRightIcon,borderRadiusBottomLeft:k.ArrowBottomLeftIcon,divideXWidth:k.WidthIcon,divideYWidth:k.HeightIcon,scale:k.BorderAllIcon,scaleX:k.WidthIcon,scaleY:k.HeightIcon,skewX:k.WidthIcon,skewY:k.HeightIcon,translateX:k.WidthIcon,translateY:k.HeightIcon,padding:k.BorderAllIcon,paddingX:k.WidthIcon,paddingY:k.HeightIcon,paddingTop:k.ArrowUpIcon,paddingRight:k.ArrowRightIcon,paddingBottom:k.ArrowDownIcon,paddingLeft:k.ArrowLeftIcon,margin:k.BorderAllIcon,marginX:k.WidthIcon,marginY:k.HeightIcon,marginTop:k.ArrowUpIcon,marginRight:k.ArrowRightIcon,marginBottom:k.ArrowDownIcon,marginLeft:k.ArrowLeftIcon,textLeft:k.AlignLeftIcon,textCenter:k.AlignCenterHorizontallyIcon,textRight:k.AlignRightIcon,textJustify:k.StretchHorizontallyIcon,italic:k.FontItalicIcon,underline:k.UnderlineIcon,overline:k.OverlineIcon,uppercase:k.LetterCaseUppercaseIcon,block:()=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M2 2H14V14H2V2ZM1 1H15V15H1V1Z",fill:"currentColor"}),a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7 4H4V12H7V4ZM9 4H12V12H9V4Z",fill:"currentColor"})]}),"float-right":()=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("path",{d:"M8 4H16V12H8V4Z",fill:"currentColor"}),a.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M0 4H6V6H0V4ZM0 7H6V9H0V7ZM4 10H0V12H4V10Z",fill:"currentColor"})]}),"float-left":()=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("path",{d:"M0 4H8V12H0V4Z",fill:"currentColor"}),a.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M10 4H16V6H10V4ZM10 7H16V9H10V7ZM14 10H10V12H14V10Z",fill:"currentColor"})]}),"float-none":k.Cross2Icon,fixed:()=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M15 2H14V4H13V5H14V6H15V2ZM10 5V4H9V2H1V8H2V5H10ZM7 4V3H5V4H7ZM4 4V3H2V4H4ZM1 13H7V14H1V13Z",fill:"currentColor"}),a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2H10V3H11V6H12V3H13V2H11ZM2 9H1V12H2V11H7V10H2V9ZM15 7H8V14H15V7Z",fill:"currentColor"})]}),absolute:()=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M14 2H15V6H14V2ZM9 3V2H1V8H2V3H9ZM7 13H1V14H7V13Z",fill:"currentColor"}),a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2H10V3H11V6H12V3H13V2H11ZM2 9H1V12H2V11H7V10H2V9ZM15 7H8V14H15V7Z",fill:"currentColor"})]}),relative:()=>a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:a.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2H9V3H11V6H12V3H14V2H11ZM2 8H1V13H2V11H7V10H2V8ZM15 7H8V14H15V7Z",fill:"currentColor"})}),sticky:()=>a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.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"}),a.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:k.Cross1Icon},fg=({property:t,onChange:e})=>{const{getClasses:n}=Rs(),s=n(t),{canChange:r}=g.useContext(Mn),o=Dn(t),i=g.useMemo(()=>d.get(o,"cls",""),[o]);return a.jsx("div",{className:"flex grow flex-wrap gap-1",children:d.map(s,l=>a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx("button",{type:"button",disabled:!r,onClick:()=>e(l,t),className:`cursor-pointer rounded border border-border p-1 disabled:cursor-not-allowed ${i===l?"bg-primary text-white":"disabled:bg-gray-600 disabled:text-gray-400"}`,children:g.createElement(d.get(Gl,l,k.BoxIcon))})}),a.jsx(ce,{children:d.startCase(d.toLower(l))})]}))})},hg=({property:t,onChange:e})=>{const{canReset:n,canChange:s}=g.useContext(Mn),r=Dn(t),o=g.useMemo(()=>d.get(r,"cls",""),[r]),{getClasses:i}=Rs(),l=i(t,[""]),c=l.indexOf(o)>-1?l.indexOf(o):0,u=/\[.*\]/g.test(o);return a.jsx("div",{className:"flex flex-row divide-x divide-solid divide-border rounded border border-border text-xs",children:u?a.jsx("div",{className:"px-2 py-[5px]",children:o}):a.jsxs(a.Fragment,{children:[a.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:a.jsx("span",{className:"flex items-center justify-center",children:a.jsx(k.MinusIcon,{className:!s&&(!n||c-1<0)?"text-gray-500":"text-black/60 dark:text-white/60"})})}),a.jsx("div",{className:"w-8/12 text-center",children:a.jsx(Wl,{label:!1,property:t,onChange:e})}),a.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:a.jsx("span",{className:"flex items-center justify-center",children:a.jsx(k.PlusIcon,{className:!s&&(!n||c+1>=l.length)?"text-gray-500":"text-black/60 dark:text-white/60"})})})]})})};function mg(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 gg(t){const e=d.map(Hd,s=>`${s}:`).join("|"),n=new RegExp(e,"g");return d.get(n.exec(t.trim()),0,"").replace(":","")}function xg(t){return t.trim().split(":").pop()||""}const tr={};function bg(t){if(d.isEmpty(t))return"";if(tr[t])return tr[t];let e="";for(const n in Xt){const s=d.get(Xt,`${n}.regExp`,"");if(new RegExp(s,"g").test(t)){e=n,tr[t]=e;break}}return e}function Co(t){return d.isEmpty(t)?null:{dark:d.startsWith(t,"dark:"),mq:mg(t),mod:gg(t),cls:xg(t),fullCls:t,property:bg(t)}}function yg(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 Ul(t){t=t.replace(/\s+/g," ");const e=t.split(" ").map(Co).filter(s=>s!==null),n=["xs","sm","md","lg","xl","2xl"];return e.sort((s,r)=>n.indexOf(s.mq)-n.indexOf(r.mq)).map(s=>s.fullCls).join(" ")}function ql(t){if(t=t.replace(/\s+/g," "),!t)return"";const e=["xs","sm","md","lg","xl","2xl"],n=t.split(" ").map(Co).filter(r=>r!==null);let s=t;if(n.length===1)return n[0].fullCls;for(const r of n){const o=r.property,i=e.indexOf(r.mq);for(let l=i+1;l<e.length;l++){const c=e[l],u=n.find(p=>p.property===o&&p.mq===c);if(u&&u.cls===r.cls)s=s.replace(u.fullCls,"");else if(u&&u.cls!==r.cls)break}}return s.replace(/\s+/g," ").trim()}const vg=j.atom(null,(t,e,{blockIds:n,newClasses:s})=>{const r=d.filter(t(En),i=>n.includes(t(i)._id)),o=d.first(t(Bn));return d.map(r,i=>{const l=t(i),c=d.get(l,o.prop,`${q.STYLES_KEY},`),{classes:u}=be.getSplitChaiClasses(c);return{ids:[l._id],props:{[o.prop]:`${q.STYLES_KEY},${Ul(ql(La.twMerge(u,s)))}`}}})}),Kl=()=>{const t=j.useSetAtom(vg),{updateBlocks:e,updateBlocksRuntime:n}=Ne();return g.useCallback((s,r,o=!1)=>{const i=t({blockIds:s,newClasses:r});if(!o){n(s,i[0].props);return}e(s,i[0].props)},[t,e,n])},kg=t=>{const e=["xs","sm","md","lg","xl","2xl"],n=e.indexOf(t);return n===-1?["xs"]:e.slice(0,n+1)},wg=j.atom(t=>{const e=d.first(t(Bn)),n=t(vs);if(!e||e.blockId!==d.get(n,"_id",null))return[];const s=d.get(n,e.prop,`${q.STYLES_KEY},`),{classes:r}=be.getSplitChaiClasses(s);return d.filter(d.map(r.trim().split(" "),Co),o=>!d.isNull(o))}),va={xs:0,sm:1,md:2,lg:3,xl:4,"2xl":5},Cg=j.atom(t=>{const e=t(Bl),n=t(Tr),s=t(Bi),r=kg(e);let o=d.filter(t(wg),{mod:n});return d.startsWith(n,"_")||(o=d.filter(o,i=>r.includes(i.mq))),o=o.sort((i,l)=>va[i.mq]-va[l.mq]),s||(o=d.filter(o,{dark:!1})),o}),Ps=()=>j.useAtomValue(Cg),jg=()=>j.useAtom(Tr),Dn=t=>{const e=Ps();return d.findLast(e,{property:t})},Sg=(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]},Ng={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-"},ka={xs:"",sm:"640px",md:"768px",lg:"1024px",xl:"1280px","2xl":"1536px"},Eg=t=>`${t.toUpperCase()} ${ka[t]?`(${ka[t]} & up)`:""}`,xs=t=>{const{t:e}=F.useTranslation(),{type:n="icons",label:s,property:r,onEmitChange:o=()=>{},units:i,negative:l=!1}=t,[c]=Rn(),[u]=jg(),[,p]=hs(),f=Dn(r),m=Kl(),h=wo(),[x]=U(),b=g.useMemo(()=>d.get(f,"fullCls",""),[f]),y=g.useCallback((_,S=!0)=>{const A={dark:c,mq:p,mod:u,cls:_};(c||u!=="")&&(A.mq="xs");const C=yg(A);m(x,[C],S)},[x,c,p,u,r,m]),v=g.useCallback(()=>{h(x,[b],!0)},[x,b,h]),w=g.useMemo(()=>Sg(f,p),[f,p]);g.useEffect(()=>{o(w,f)},[w,o,f]);const[,,N]=hs(),E=g.useCallback(_=>{N({xs:400,sm:640,md:800,lg:1024,xl:1420,"2xl":1920}[_])},[N]),I=d.get(f,"dark",null)===c&&d.get(f,"mod",null)===u&&d.get(f,"mq",null)===p;return a.jsx(sg,{canChange:w,canReset:f&&I,children:a.jsxs("div",{className:"group flex flex-row items-center py-2 first:pt-0 last:pb-0",children:[a.jsx("div",{className:"relative w-[70px] truncate text-xs text-foreground",children:a.jsx("span",{className:`text-[11px] ${f&&!I?"text-foreground":""}`,children:e(s)})}),a.jsxs("div",{className:"flex flex-row items-center",children:[a.jsxs("div",{className:"w-[150px]",children:[n==="arbitrary"?a.jsx(ng,{currentClass:d.get(f,"cls",""),classPrefix:d.get(Ng,r,""),units:i||[],onChange:y,negative:l,cssProperty:r}):null,n==="icons"&&a.jsx(fg,{property:r,onChange:y}),n==="range"&&a.jsx(hg,{property:r,onChange:y}),n==="color"&&a.jsx(pg,{property:r,onChange:y}),n==="dropdown"&&a.jsx(Wl,{label:s,property:r,onChange:y})]}),a.jsx("div",{className:`w-[30px] cursor-pointer ${b?"visible":"invisible"}`,children:I?a.jsx("button",{type:"button",onClick:()=>v(),title:"Reset",className:"flex px-1.5 text-xs",children:a.jsx(k.CrossCircledIcon,{className:"h-5 w-5 text-blue-500 hover:opacity-80"})}):w&&f?a.jsxs(fe,{delayDuration:100,children:[a.jsx(he,{asChild:!0,children:a.jsx("button",{type:"button",className:"invisible ml-3 mt-1 rounded-full bg-primary text-white group-hover:visible",children:a.jsx(k.InfoCircledIcon,{})})}),a.jsx(ce,{children:a.jsx("div",{className:"text-right",children:a.jsxs("div",{children:["Current style is set at ",a.jsxs("span",{className:"font-bold",children:[Eg(d.get(f,"mq")),c&&!f.dark?"(Light mode)":""]}),a.jsx("br",{}),a.jsxs("button",{type:"button",onClick:()=>E(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})]})]})})},Ag=["px","%","em","rem","ch","vh","vw"],gr=({label:t,options:e,borderB:n=!1,borderT:s=!1,type:r="arbitrary",units:o=Ag,negative:i=!1})=>{const{t:l}=F.useTranslation(),[c,u]=g.useState(e[0].key),p=Ps(),f=g.useCallback(m=>d.map(p,"property").includes(m),[p]);return a.jsxs("div",{className:`mb-2 border-border py-2 first:pt-0 last:pb-0 ${n?"border-b":""} ${s?"border-t":""}`,children:[a.jsxs("div",{className:"flex flex-row text-xs",children:[t&&a.jsx("span",{className:"relative w-[70px] flex-none text-xs text-foreground",children:l(t)}),a.jsx("div",{className:"mb-3 flex grow flex-row flex-wrap gap-x-px",children:e.map(({label:m,key:h},x)=>a.jsx("div",{className:"first:rounded-l last:rounded-r",children:a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsxs("button",{type:"button",onClick:()=>u(h),className:`relative cursor-pointer rounded-full p-1 text-[8px] ${h===c?"bg-[#3E57F0] text-white":"text-gray-600 dark:text-gray-300"}`,children:[g.createElement("div",{className:f(h)?"-bottom-1.5 absolute bg-[#3E57F0] h-[2px] left-0 w-full":""}),g.createElement(d.get(Gl,h,k.BoxIcon),{className:"text-inherit w-3 h-3"})]})}),a.jsx(ce,{children:d.startCase(d.toLower(m))})]})},`option-${x}`))})]}),a.jsx("div",{className:"mt-0 flex items-center",children:a.jsx(xs,{type:r,units:[...o],label:"",property:c,negative:i})})]})},wa=({heading:t,items:e})=>{const{t:n}=F.useTranslation(),s=Ps(),r=g.useMemo(()=>{const o=c=>d.flatten(c.map(u=>u.styleType==="multiple"?d.map(u.options,"key"):u.property)),i=d.flatten(e.map(c=>c.styleType==="accordion"?o(c.items):c.styleType==="multiple"?d.map(c.options,"key"):c.property)),l=d.map(s,"property");return d.intersection(i,l).length>0},[s,e]);return a.jsxs("details",{children:[a.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:a.jsxs("div",{className:"inline",children:[d.startCase(n(t.toLowerCase())),r?a.jsx("span",{className:`ml-1 mr-2 inline-block h-[8px] w-[8px] rounded-full ${r?"bg-primary":"bg-gray-300"}`}):null]})}),a.jsx("div",{className:"p-2",children:e.map(o=>o.styleType==="multiple"?a.jsx(gr,{...o},o.label):a.jsx(xs,{...o},o.label))})]})},Ig=g.createContext({}),nr=({section:t,showAccordian:e})=>{const{t:n}=F.useTranslation(),s=Ps(),r=g.useCallback((i=[])=>{const l={};for(let u=0;u<s.length;u++)l[s[u].property]=s[u].cls;let c=!0;for(const u in i)if(!d.has(l,u)||l[u]!==i[u]){c=!1;break}return c},[s]),o=g.useMemo(()=>({}),[]);return a.jsx(Ig.Provider,{value:o,children:e?a.jsxs(yo,{value:t.heading,className:"border-none",children:[a.jsx(vo,{className:"border-slate-150 border-t py-2 text-xs",children:a.jsx("div",{className:"flex items-center py-2",children:a.jsx("div",{className:"flex items-center gap-x-2 text-xs font-medium",children:d.startCase(n(t.heading))})})}),a.jsx(ko,{className:"py-2",children:t.items.map(i=>d.has(i,"component")?g.createElement(i.component,{key:i.label}):d.has(i,"styleType")?i.styleType==="multiple"?a.jsx(gr,{...i},i.label+"multiple-choices"):i.styleType==="accordion"&&r(i==null?void 0:i.conditions)?a.jsx(wa,{...i},i.label+"nested-options"):null:a.jsx(xs,{...i},i.label+"block-style"))})]}):a.jsx("div",{className:"py-2",children:t.items.map((i,l)=>d.has(i,"component")?g.createElement(i.component,{key:i.label}):d.has(i,"styleType")?i.styleType==="multiple"?a.jsx(gr,{...i},i.label+"multiple-choices"+l):i.styleType==="accordion"&&r(i==null?void 0:i.conditions)?a.jsx(wa,{...i},i.label+"nested-options"+l):null:a.jsx(xs,{...i},i.label+"block-style"+l))})})},Yl=bs.Root,Xl=bs.Trigger,jo=D.forwardRef(({className:t,align:e="center",sideOffset:n=4,...s},r)=>a.jsx(bs.Content,{ref:r,align:e,sideOffset:n,className:B.cn("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 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}));jo.displayName=bs.Content.displayName;const Tg=Se.atomWithStorage("selectedBreakpoints",["XS","MD","XL"]),_g=()=>{const[t,e]=j.useAtom(Tg);return[t,e]},Ca=({landscape:t=!1,className:e=""})=>a.jsx("svg",{className:ve.cn("h-3 w-3",t?"rotate-90":"",e),stroke:"currentColor",fill:"currentColor",strokeWidth:"0",viewBox:"0 0 448 512",xmlns:"http://www.w3.org/2000/svg",children:a.jsx("path",{d:"M400 0H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V48c0-26.5-21.5-48-48-48zM224 480c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm176-108c0 6.6-5.4 12-12 12H60c-6.6 0-12-5.4-12-12V60c0-6.6 5.4-12 12-12h328c6.6 0 12 5.4 12 12v312z"})}),xr=[{title:"Mobile (Base)",content:"Styles set here are applied to all screen unless edited at higher breakpoint",breakpoint:"xs",icon:a.jsx(k.MobileIcon,{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:a.jsx(k.MobileIcon,{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:a.jsx(Ca,{}),width:800},{title:"Tablet Landscape (LG)",content:"Styles set here are applied at 1024px and up unless edited at higher breakpoint",breakpoint:"lg",icon:a.jsx(Ca,{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:a.jsx(k.LaptopIcon,{className:"h-4 w-4"}),width:1420},{title:"Large Desktop (2XL)",content:"Styles set here are applied at 1536px and up",breakpoint:"2xl",icon:a.jsx(k.DesktopIcon,{className:"h-4 w-4"}),width:1920}],ja=({canvas:t=!1,openDelay:e=400,tooltip:n=!0,title:s,content:r,currentBreakpoint:o,breakpoint:i,width:l,icon:c,onClick:u,buttonClass:p="",activeButtonClass:f=""})=>{const{t:m}=F.useTranslation();return n?a.jsxs(Yl,{openDelay:e,children:[a.jsx(Xl,{asChild:!0,children:a.jsx(B.Button,{onClick:()=>u(l),size:"sm",className:ve.cn("h-7 w-7 rounded-md p-1",i===o?f:p),variant:i===o?"outline":"ghost",children:c})}),a.jsx(jo,{className:"w-fit max-w-52 border-border",children:a.jsx("div",{className:"flex justify-between space-x-4",children:a.jsxs("div",{className:"space-y-1",children:[a.jsx("h4",{className:"text-sm font-semibold",children:m(s)}),t&&a.jsx("p",{className:"text-xs",children:m(r)})]})})})]}):a.jsx(B.Button,{onClick:()=>u(l),size:"sm",className:"h-7 w-7 rounded-md p-1",variant:i===o?"outline":"ghost",children:c})},So=({openDelay:t=400,canvas:e=!1,tooltip:n=!0,buttonClass:s="",activeButtonClass:r=""})=>{const[o,,i]=hs(),[l,c]=io(),[u,p]=_g(),f=u,m=p,{t:h}=F.useTranslation(),x=$("breakpoints",xr),b=w=>{f.includes(w)?f.length>2&&m(f.filter(N=>N!==w)):m(N=>[...N,w])},y=w=>{e||i(w),c(w)},v=ve.getBreakpointValue(e?l:o).toLowerCase();return x.length<4?a.jsx("div",{className:"flex items-center rounded-md",children:d.map(x,w=>g.createElement(ja,{canvas:e,...w,onClick:y,key:w.breakpoint,currentBreakpoint:v}))}):a.jsxs("div",{className:"flex w-full items-center justify-between rounded-md",children:[a.jsx("div",{className:"flex items-center",children:d.map(x.filter(w=>d.includes(f,d.toUpper(w.breakpoint))),w=>g.createElement(ja,{canvas:e,openDelay:t,tooltip:n,...w,onClick:y,key:w.breakpoint,currentBreakpoint:v,buttonClass:s,activeButtonClass:r}))}),a.jsxs(et,{children:[a.jsx(tt,{asChild:!0,children:a.jsx("span",{className:"cursor-pointer rounded-md p-1 hover:bg-background",children:a.jsx(k.ChevronDownIcon,{className:"scale-90 transform"})})}),a.jsxs(Ge,{className:"w-56 border-border text-xs",children:[a.jsx(za,{children:h("Screen sizes")}),a.jsx(wr,{}),d.map(x,w=>a.jsx(Fa,{disabled:w.breakpoint==="xs",onCheckedChange:()=>b(d.toUpper(w.breakpoint)),checked:d.includes(f,d.toUpper(w.breakpoint)),onSelect:N=>N.preventDefault(),children:h(w.title)},w.breakpoint))]})]})]})};function Bg(){const[,t]=hs(),{t:e}=F.useTranslation(),n=g.useMemo(()=>{const s=xr.find(r=>r.breakpoint===t);return(s==null?void 0:s.content)??""},[t,xr]);return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-start bg-muted px-2 py-1 shadow-sm",children:[a.jsxs("p",{className:"text-xs text-muted-foreground",children:[e("Screen")," "]}),a.jsx(So,{openDelay:1e3,tooltip:!1})]}),a.jsx("div",{className:"mb-2 flex items-center justify-between rounded-md rounded-t-none border border-border p-1",children:a.jsx("p",{className:"flex flex-1 items-center space-x-2 text-[10px] text-foreground",children:a.jsxs("span",{className:"text-xs text-foreground",children:[a.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 Rg=vr.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),ut=D.forwardRef(({className:t,...e},n)=>a.jsx(Oa.Root,{ref:n,className:B.cn(Rg(),t),...e}));ut.displayName=Oa.Root.displayName;const br=({className:t=""})=>a.jsx(k.TokensIcon,{className:t});function No({from:t="default",classFromProps:e,onAddNew:n,onRemove:s}){var pt;const r=g.useRef(null),[o,i]=g.useState(""),[l,c]=g.useState(!1),[u,p]=g.useState(-1),f=g.useRef(!1),[,m]=Mr(),h=dg(),{t:x}=F.useTranslation(),[b]=Ee(),y=J(),v=Kl(),w=wo(),[N]=U(),[E,I]=g.useState(""),_=j.useAtomValue(en),S=(pt=d.first(b))==null?void 0:pt.prop,{classes:A}=be.getSplitChaiClasses(d.get(y,S,"")),T=(t==="default"?A:e??"").split(" ").filter(H=>!d.isEmpty(H)),P=g.useMemo(()=>[...T].sort((H,Z)=>{const Be=H.startsWith(q.DESIGN_TOKEN_PREFIX),ot=Z.startsWith(q.DESIGN_TOKEN_PREFIX);return Be&&!ot?-1:!Be&&ot?1:0}),[T]),R=$("flags.copyPaste",!0),O=H=>{if(H.startsWith(q.DESIGN_TOKEN_PREFIX)){const Z=_[H];return Z?Z.name:H}return H},z=H=>{const Z=Object.entries(_).find(([,Be])=>Be.name===H);return Z?`${Z[0]}`:H},G=()=>{const H=E.trim().replace(/ +(?= )/g,"").split(" ").map(z);t==="designToken"?d.isFunction(n)&&n(H):v(N,H,!0),I("")},[de,ue]=g.useState([]),ne=$("flags.designTokens",!0),Ae=({value:H})=>{const Z=H.trim().toLowerCase(),Be=Z.match(/.+:/g);let ot=[],Fs=[];if(ne&&(Z===""?Fs=Object.entries(_).map(([ft,dn])=>({name:dn.name,id:`${ft}`,isDesignToken:!0})):Fs=Object.entries(_).filter(([,ft])=>ft.name.toLowerCase().includes(Z)).map(([ft,dn])=>({name:dn.name,id:`${ft}`,isDesignToken:!0}))),Be&&Be.length>0){const[ft]=Be,dn=Z.replace(ft,"");ot=h.search(dn).map(zs=>({...zs,item:{...zs.item,name:ft+zs.item.name}}))}else ot=h.search(Z);const Lc=[...Fs,...d.map(ot,"item")];return ue(Lc)},Oe=()=>{ue([])},W=H=>H.name,$e=H=>a.jsxs("div",{className:"flex items-center gap-2 rounded-md p-1",children:[H.isDesignToken&&a.jsx(br,{className:"h-4 w-4 text-gray-600"}),a.jsx("span",{children:H.name})]}),vt=g.useMemo(()=>({ref:r,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,placeholder:x("Enter classes separated by space"),value:E,onFocus:H=>{setTimeout(()=>{H.target&&H.target.select()},0)},onKeyDown:H=>{if(H.key==="Enter"&&E.trim()!==""){if(f.current){f.current=!1;return}H.preventDefault(),G()}if(H.key==="Tab"&&de.length>0){H.preventDefault();const Z=new KeyboardEvent("keydown",{key:"ArrowDown",code:"ArrowDown",keyCode:40,bubbles:!0});H.target.dispatchEvent(Z)}},onChange:(H,{newValue:Z})=>I(Z),className:`w-full rounded-md text-xs px-2 hover:outline-0 bg-background border-border ${t==="default"?"py-1":"py-1.5"}`}),[E,x,r,de.length]),kt=H=>{const Z=o.trim().replace(/ +(?= )/g,"").split(" ").map(z);w(N,[H],!0),v(N,Z,!0),i(""),p(-1)},Wt=()=>{if(navigator.clipboard===void 0){pe.toast.error(x("Clipboard not supported"));return}navigator.clipboard.writeText(T.join(" ")),pe.toast.success(x("Classes copied to clipboard")),c(!0),setTimeout(()=>c(!1),2e3)};return a.jsxs("div",{className:`flex w-full flex-col gap-y-1.5 pb-4 ${t==="designToken"?"border-none":"border-b border-border"}`,children:[a.jsx("div",{className:"flex items-center justify-between gap-x-2",children:a.jsxs("div",{className:"flex w-full items-center justify-between gap-x-2 text-muted-foreground",children:[a.jsxs("span",{className:"flex items-center gap-x-1",children:[a.jsx("span",{children:t==="designToken"?a.jsx(ut,{className:"text-sm font-medium leading-tight text-gray-900 peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:x("Token Classes")}):x(ne?"Styles":"Classes")}),R&&a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:l?a.jsx(k.CheckIcon,{className:"rounded-full border border-green-500 bg-green-500/10 text-green-500"}):a.jsx(k.CopyIcon,{onClick:Wt,className:"cursor-pointer"})}),a.jsx(ce,{children:a.jsx("p",{children:x("Copy classes to clipboard")})})]})]}),ne&&t==="default"&&a.jsx(B.Button,{variant:"link",className:"underline",onClick:()=>m("design-tokens"),children:x("Design Tokens")})]})}),a.jsxs("div",{className:"relative flex items-center gap-x-3",children:[a.jsx("div",{className:"relative flex w-full items-center gap-x-3",children:a.jsx(sd,{suggestions:de,onSuggestionsFetchRequested:Ae,onSuggestionsClearRequested:Oe,getSuggestionValue:W,renderSuggestion:$e,inputProps:vt,onSuggestionSelected:(H,{suggestionValue:Z})=>{f.current=!0;const ot=[z(Z)];t==="designToken"?d.isFunction(n)&&n(ot):v(N,ot,!0),I("")},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"}})}),a.jsx(B.Button,{variant:"outline",className:`border-border ${t==="default"?"h-6":"mt-1 h-7"}`,onClick:G,disabled:E.trim()==="",size:"sm",children:a.jsx(k.PlusIcon,{})})]}),a.jsx("div",{className:"flex w-full flex-wrap gap-2 overflow-x-hidden",children:P.map((H,Z)=>u===Z?a.jsx("input",{ref:r,value:o,onChange:Be=>i(Be.target.value),onBlur:()=>{kt(H)},onKeyDown:Be=>{Be.key==="Enter"&&kt(H)},onFocus:Be=>{setTimeout(()=>{Be.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"},H):a.jsx("div",{className:"group relative flex max-w-[260px] items-center",children:a.jsxs("button",{onDoubleClick:()=>{I(O(H)),t==="default"?w(N,[H],!0):(d.isFunction(s)&&s(H),I(H)),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:[a.jsxs("div",{className:"z-10 flex h-full w-max items-center justify-center",children:[a.jsx(k.Cross2Icon,{onClick:()=>{t==="default"?w(N,[H],!0):d.isFunction(s)&&s(H)},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"}),H.startsWith(q.DESIGN_TOKEN_PREFIX)?a.jsx(br,{className:"text-[rgba(55, 65, 81, 0.4)] h-3.5 w-3.5 group-hover:hidden"}):a.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:[a.jsx("g",{id:"SVGRepo_bgCarrier",strokeWidth:"0"}),a.jsx("g",{id:"SVGRepo_tracerCarrier",strokeLinecap:"round",strokeLinejoin:"round"}),a.jsx("g",{id:"SVGRepo_iconCarrier",children:a.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"})})]})]}),a.jsx("div",{children:O(H)})]})},H))})]})}const Ce=["px","%","em","rem","ch","vh","vw"],Pg={heading:"flex.heading",items:[{type:"arbitrary",label:"flex.basis",units:Ce,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"}]},Lg={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"}]},Mg=[{heading:"Styles",items:[{component:No},{component:Bg},{type:"arbitrary",label:"layout.width",units:Ce.concat("auto"),property:"width"},{type:"arbitrary",label:"layout.height",units:Ce.concat("auto"),property:"height"},{styleType:"multiple",label:"layout.margin",negative:!0,units:[...Ce,"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:Ce},{type:"arbitrary",property:"lineHeight",label:"typography.height",units:Ce.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"}]}]}];Ce.concat("auto"),Ce.concat("auto"),[...Ce],Ce.concat("auto"),Ce.concat("auto"),Ce.concat("auto"),Ce.concat("auto"),Ce.concat("-");const Dg={px:1,"%":1,em:100,rem:100,ch:1,vw:1,vh:1,"-":1,deg:1,ms:.1};function yr(){const{flexChild:t,gridChild:e}=Id(),[n]=Ee(),[s,r]=g.useState(""),[o,i]=g.useState({onDrag:u=>u,onDragEnd:u=>u,dragStartY:0,dragging:!1,dragStartValue:0,dragUnit:"",negative:!1,cssProperty:""}),l=ke.useThrottledCallback(u=>{const p=!d.get(o,"negative",!1),f=d.get(o,"cssProperty","");let m=parseFloat(o.dragStartValue);m=isNaN(m)?0:m;let h=Dg[o.dragUnit];(d.startsWith(f,"scale")||f==="opacity")&&(h=10);let b=(o.dragStartY-u.pageY)/h+m;p&&b<0&&(b=0),f==="opacity"&&b>1&&(b=1),o.onDrag(`${b}`),r(`${b}`)},[o],50),c=g.useCallback(()=>{setTimeout(()=>o.onDragEnd(`${s}`),100),i({onDrag:u=>u,onDragEnd:u=>u,dragStartY:0,dragging:!1,dragStartValue:0,dragUnit:"",negative:!1,cssProperty:""})},[o,s,i]);return d.isEmpty(n)?null:a.jsxs(Hl.Provider,{value:{setDragData:i},children:[o.dragging?a.jsx("div",{onMouseMove:l,onMouseUp:()=>c(),className:"absolute inset-0 z-30 cursor-row-resize bg-gray-300/10"}):null,a.jsxs("div",{className:"flex flex-col",children:[a.jsx(Jm,{}),a.jsxs(Fl,{defaultValue:["Styles"],type:"multiple",className:"w-full",children:[t&&a.jsx(nr,{section:Pg,showAccordian:t||e}),e&&a.jsx(nr,{section:Lg,showAccordian:t||e}),Mg.map(u=>a.jsx(nr,{section:u,showAccordian:t||e},u.heading))]})]})]})}const Nn=D.forwardRef(({className:t,children:e,...n},s)=>a.jsxs(It.Root,{ref:s,className:B.cn("relative overflow-hidden",t),...n,children:[a.jsx(It.Viewport,{className:"h-full w-full rounded-[inherit]",children:e}),a.jsx(Jl,{}),a.jsx(It.Corner,{})]}));Nn.displayName=It.Root.displayName;const Jl=D.forwardRef(({className:t,orientation:e="vertical",...n},s)=>a.jsx(It.ScrollAreaScrollbar,{ref:s,orientation:e,className:B.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:a.jsx(It.ScrollAreaThumb,{className:"relative flex-1 rounded-full bg-border"})}));Jl.displayName=It.ScrollAreaScrollbar.displayName;const Ls=$t.Root,On=D.forwardRef(({className:t,...e},n)=>a.jsx($t.List,{ref:n,className:B.cn("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",t),...e}));On.displayName=$t.List.displayName;const He=D.forwardRef(({className:t,...e},n)=>a.jsx($t.Trigger,{ref:n,className:B.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}));He.displayName=$t.Trigger.displayName;const ct=D.forwardRef(({className:t,...e},n)=>a.jsx($t.Content,{ref:n,className:B.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}));ct.displayName=$t.Content.displayName;const Og=({block:t,disabled:e,parentId:n,position:s})=>{const{type:r,icon:o,label:i}=t,{addCoreBlock:l,addPredefinedBlock:c}=bt(),u=()=>{if(d.has(t,"blocks")){const x=d.isFunction(t.blocks)?t.blocks():t.blocks;c(X.syncBlocksWithDefaultProps(x),n||null,s)}else l(t,n||null,s);oe.publish(K.CLOSE_ADD_BLOCK)},p=Ye(),{t:f}=F.useTranslation(),{onDragStart:m,onDragEnd:h}=rn();return a.jsx(a.Fragment,{children:a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsxs("button",{disabled:e,onClick:u,type:"button",onDragStart:x=>m(x,{...t,label:i,icon:o}),onDragEnd:h,draggable:p,className:`${d.kebabCase(`chai-block-${r}`)} ${p?"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 ${e?"opacity-50":""}`,children:[g.createElement(o||k.BoxIcon,{className:"w-4 h-4 mx-auto","data-add-core-block-icon":r}),a.jsx("p",{className:"truncate text-xs",children:d.capitalize(f(i||r))})]})}),a.jsx(ce,{children:a.jsx("p",{children:f(i||r)})})]})})},Zl=({parentId:t,position:e,gridCols:n="grid-cols-2",disableBlockGroupsSidebar:s=!1})=>{const r=X.useRegisteredChaiBlocks(),o=d.groupBy(r,"category"),i=d.uniq(d.map(o.core,"group"));return a.jsx(cc,{gridCols:n,parentId:t,position:e,groups:i,blocks:o.core,disableBlockGroupsSidebar:s})},Eo=D.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:B.cn("rounded-xl border bg-card text-card-foreground shadow",t),...e}));Eo.displayName="Card";const Ao=D.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:B.cn("flex flex-col space-y-1.5 p-6",t),...e}));Ao.displayName="CardHeader";const Ql=D.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:B.cn("font-semibold leading-none tracking-tight",t),...e}));Ql.displayName="CardTitle";const ec=D.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:B.cn("text-sm text-muted-foreground",t),...e}));ec.displayName="CardDescription";const Io=D.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:B.cn("p-6 pt-0",t),...e}));Io.displayName="CardContent";const To=D.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:B.cn("flex items-center p-6 pt-0",t),...e}));To.displayName="CardFooter";const $n=D.forwardRef(({className:t,...e},n)=>a.jsx("textarea",{className:B.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 tc=({parentId:t,position:e,fromSidebar:n})=>{const{t:s}=F.useTranslation(),[r,o]=g.useState(""),{addPredefinedBlock:i}=bt(),[l,c]=g.useState(!1),u=async()=>{c(!0);const p=await B.getPreImportHTML(r),f=be.getBlocksFromHTML(p);i([...f],t,e),o(""),c(!1),oe.publish(K.CLOSE_ADD_BLOCK)};return a.jsxs(Eo,{className:`border-border/0 p-0 shadow-none ${n?"w-full":"max-w-full"}`,children:[a.jsx(Ao,{className:n?"p-0":"p-3",children:a.jsx(ec,{className:n?"text-xs":"",children:s("Use HTML snippets from Tailwind CSS component libraries")})}),a.jsx(Io,{className:`space-y-2 py-0 ${n?"p-0":"px-3"}`,children:a.jsxs("div",{className:"space-y-1",children:[a.jsx(ut,{htmlFor:"current",className:"text-sm",children:s("Tailwind HTML snippet")}),a.jsx($n,{onChange:p=>o(p.target.value),rows:12,value:r,placeholder:s("Enter your code snippet here"),className:"resize-none overflow-x-auto whitespace-pre bg-background font-mono text-xs font-normal"})]})}),a.jsx(To,{className:"flex flex-col justify-end p-3",children:a.jsx(B.Button,{disabled:r.trim()===""||l,onClick:()=>u(),size:"sm",className:"w-fit",children:l?a.jsxs(a.Fragment,{children:[a.jsx(k.CircleIcon,{className:"mr-2 h-4 w-4 animate-spin"})," ",s("Importing...")]}):s("Import HTML")})})]})},Ms=me.Root,_o=me.Value,Fn=D.forwardRef(({className:t,children:e,...n},s)=>a.jsxs(me.Trigger,{ref:s,className:B.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,a.jsx(me.Icon,{asChild:!0,children:a.jsx(k.ChevronDownIcon,{className:"h-4 w-4 opacity-50"})})]}));Fn.displayName=me.Trigger.displayName;const nc=D.forwardRef(({className:t,...e},n)=>a.jsx(me.ScrollUpButton,{ref:n,className:B.cn("flex cursor-default items-center justify-center py-1",t),...e,children:a.jsx(k.ChevronUpIcon,{className:"h-4 w-4"})}));nc.displayName=me.ScrollUpButton.displayName;const sc=D.forwardRef(({className:t,...e},n)=>a.jsx(me.ScrollDownButton,{ref:n,className:B.cn("flex cursor-default items-center justify-center py-1",t),...e,children:a.jsx(k.ChevronDownIcon,{className:"h-4 w-4"})}));sc.displayName=me.ScrollDownButton.displayName;const zn=D.forwardRef(({className:t,children:e,position:n="popper",...s},r)=>a.jsx(me.Portal,{children:a.jsxs(me.Content,{ref:r,className:B.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:[a.jsx(nc,{}),a.jsx(me.Viewport,{className:B.cn("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:e}),a.jsx(sc,{})]})}));zn.displayName=me.Content.displayName;const $g=D.forwardRef(({className:t,...e},n)=>a.jsx(me.Label,{ref:n,className:B.cn("px-2 py-1.5 text-sm font-semibold",t),...e}));$g.displayName=me.Label.displayName;const Hn=D.forwardRef(({className:t,children:e,...n},s)=>a.jsxs(me.Item,{ref:s,className:B.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:[a.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:a.jsx(me.ItemIndicator,{children:a.jsx(k.CheckIcon,{className:"h-4 w-4"})})}),a.jsx(me.ItemText,{children:e})]}));Hn.displayName=me.Item.displayName;const Fg=D.forwardRef(({className:t,...e},n)=>a.jsx(me.Separator,{ref:n,className:B.cn("-mx-1 my-1 h-px bg-muted",t),...e}));Fg.displayName=me.Separator.displayName;const zg=({defaultValue:t="",onValueChange:e,options:n,placeholder:s="Select",className:r="",height:o=""})=>{const[i,l]=g.useState(t),c=u=>{const p=u.target.value;l(p),e(p)};return a.jsx("div",{className:ve.cn("relative inline-block w-full",r),children:a.jsxs("select",{className:ve.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",o),value:i,onChange:c,children:[a.jsx("option",{value:"",disabled:!0,children:s}),n.map(u=>a.jsx("option",{value:u.value,children:u.label},u.value))]})})};function Hg({uiLibraries:t,library:e,setLibrary:n}){const{t:s}=F.useTranslation();return e?a.jsxs("div",{className:"h-12",children:[a.jsx("p",{className:"text-xs font-bold text-gray-500",children:s("Choose library")}),a.jsx(zg,{className:"mb-1",options:t.map(r=>({value:r.id,label:r.name})),defaultValue:e,onValueChange:r=>n(r)})]}):null}const rc=j.atom({}),oc=t=>{const[e,n]=j.useAtom(rc),s=g.useMemo(()=>(t==null?void 0:t.getBlocksList)||(()=>[]),[t]),r=d.get(e,`${t==null?void 0:t.id}.blocks`,null),o=d.get(e,`${t==null?void 0:t.id}.loading`,"idle"),i=d.get(e,`${t==null?void 0:t.id}.error`,!1),l=g.useRef("idle");g.useEffect(()=>{(async()=>{if(t&&!(o==="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,r,o,l,n,s]);const c=g.useCallback(u=>{n(p=>({...p,[u]:{loading:"idle",blocks:[],error:!1}}))},[n]);return{data:r||[],isLoading:o==="loading",isError:i,resetLibrary:c}},Vg=()=>j.useAtom(Hr),ac=({block:t,html:e,blocks:n,children:s,onDragStart:r,onDragEnd:o,draggable:i,className:l="",type:c="Box"})=>{const{onDragStart:u,onDragEnd:p}=rn(),f=Ye(),[,m]=U(),{clearHighlight:h}=st(),x=i!==void 0?i:f,b=async v=>{try{if(r){r(v);return}let w=null;if(c==="Image"){if(!(t!=null&&t.image))return;w={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 N=typeof e=="function"?await e():e,E=be.getBlocksFromHTML(N);if(d.isEmpty(E))return;w={type:"Box",blocks:E,name:d.get(E,"0._type","Block")}}else if(n){const N=typeof n=="function"?await n():n;if(d.isEmpty(N))return;w={type:"Box",blocks:N,name:d.get(N,"0._type","Block")}}else if(t){const N=typeof t=="function"?await t():t;w=typeof N=="object"?d.omit(N,["component","icon"]):N}if(!w)return;u(v,w,!0),setTimeout(()=>{m([]),h()},200)}catch(w){console.error("Error in ChaiDraggableBlock drag start:",w)}},y=v=>{o?o(v):p()};return a.jsx("div",{draggable:x,onDragStart:b,onDragEnd:y,className:`${x?"cursor-grab active:cursor-grabbing":""} ${l}`.trim(),children:s})};function ic({value:t,setValue:e}){const{t:n}=F.useTranslation();return a.jsx("div",{className:"flex py-2",children:a.jsxs("div",{className:"relative flex w-full max-w-md items-center rounded border px-2",children:[a.jsxs("div",{className:"flex w-full items-center gap-x-2",children:[a.jsx(k.MagnifyingGlassIcon,{className:"h-5 w-5 flex-shrink-0 stroke-[1px] text-muted-foreground"}),a.jsx(B.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&&a.jsx("button",{onClick:()=>e(""),className:"absolute right-2.5 top-2.5 text-muted-foreground hover:text-foreground",children:a.jsx(k.Cross1Icon,{className:"h-3.5 w-3.5"})})]})})}const Sa=({block:t,library:e,parentId:n=void 0,position:s=-1})=>{const[r,o]=g.useState(!1),i=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:m}=rn(),h=Ye(),x=g.useCallback(async y=>{if(y.stopPropagation(),d.has(t,"component")){l(t,n,s),oe.publish(K.CLOSE_ADD_BLOCK);return}o(!0);let v=await i({library:e,block:t});typeof v=="string"&&(v=be.getBlocksFromHTML(v)),d.isEmpty(v)||c(X.syncBlocksWithDefaultProps(v),n,s),oe.publish(K.CLOSE_ADD_BLOCK),setTimeout(()=>o(!1),1e3)},[l,c,t,i,e,n,s]),b=async y=>{if(!h)return;let v=await i({library:e,block:t});typeof v=="string"&&(v=be.getBlocksFromHTML(v)),f(y,{type:"Box",blocks:v,name:u},!0)};return a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(ac,{draggable:h,onDragStart:b,onDragEnd:m,children:a.jsxs("div",{onClick:r?()=>{}:x,className:Pa("relative mt-2 overflow-hidden rounded-md border border-border duration-200 hover:border-blue-500 hover:shadow-xl",h?"":"cursor-pointer"),children:[r&&a.jsxs("div",{className:"absolute flex h-full w-full items-center justify-center bg-black/70",children:[a.jsx(k.ReloadIcon,{className:"h-4 w-4 animate-spin text-white"}),a.jsx("span",{className:"pl-2 text-sm text-white",children:"Adding..."})]}),t.preview?a.jsx("img",{src:t.preview,className:"min-h-[45px] w-full rounded-md",alt:u}):a.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:[a.jsx("p",{className:"font-medium text-gray-800",children:u}),p&&a.jsx("p",{className:"text-sm text-gray-600",children:p})]})]})})}),a.jsx(ce,{children:a.jsx("div",{className:"max-w-xs",children:a.jsx("p",{className:"font-medium",children:u})})})]})},Wg=({parentId:t,position:e,fromSidebar:n})=>{const[s,r]=Vg(),o=B.useChaiLibraries(),i=o.find(R=>R.id===s)||d.first(o),{data:l,isLoading:c,isError:u,resetLibrary:p}=oc(i),[f,m]=g.useState(""),[h,x]=g.useState([]),b=g.useRef(null);g.useEffect(()=>{l&&Array.isArray(l)&&l.length>0&&(b.current=new Ma(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(O=>O.item);x(R)},[f]);const y=f.trim()&&!d.isEmpty(h)?h:l||[],v=d.groupBy(y,"group"),[w,N]=g.useState(null);g.useEffect(()=>{if(d.isEmpty(d.keys(v))){N(null);return}if(!w||!v[w]){N(d.first(d.keys(v))||null);return}},[v,w]);const E=d.get(v,w||"",[]),I=g.useRef(null),{t:_}=F.useTranslation(),S=g.useRef(null);g.useEffect(()=>{var O;const R=(O=S.current)==null?void 0:O.querySelector("[data-radix-scroll-area-viewport]");R&&R.scrollTo({top:0,behavior:"smooth"})},[i,w]);const A=R=>{I.current&&(clearTimeout(I.current),I.current=null),I.current=setTimeout(()=>{I.current&&N(R)},400)},C=()=>{i!=null&&i.id&&p(i.id)};if(c)return a.jsxs("div",{className:"mt-4 grid h-full w-full grid-cols-12 gap-2",children:[a.jsx(Lt,{className:"col-span-3 h-full"}),a.jsx(Lt,{className:"col-span-9 h-full"})]});const T=d.filter(E,(R,O)=>O%2===0),P=d.filter(E,(R,O)=>O%2===1);return a.jsx(a.Fragment,{children:a.jsxs("div",{className:"flex h-full max-h-full flex-col",children:[a.jsx(ic,{value:f,setValue:m}),a.jsx("div",{className:"relative flex h-full max-h-full flex-1 overflow-hidden bg-background",children:a.jsxs("div",{className:`flex h-full flex-1 pt-2 ${n?"flex-col":""}`,children:[a.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:[a.jsx(Hg,{library:i==null?void 0:i.id,setLibrary:r,uiLibraries:o}),a.jsxs("div",{className:"mt-2 flex h-full max-h-full w-full flex-1 flex-col",children:[a.jsx("span",{className:"text-xs font-bold text-gray-500",children:_("Groups")}),!n&&a.jsx("hr",{className:"mt-1 border-border"}),a.jsx("div",{className:`no-scrollbar mt-2 h-full max-h-full flex-1 overflow-y-auto ${n?"":"pb-20"}`,children:d.isEmpty(v)?a.jsx("div",{className:"mt-4 flex flex-col items-center justify-center gap-3 p-4 text-center",children:f?a.jsx("p",{className:"text-sm",children:_("No matching blocks found")}):u?a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-sm",children:_("Failed to load the UI library. Try again")}),a.jsxs(B.Button,{onClick:C,variant:"outline",size:"sm",className:"gap-2",children:[a.jsx(k.ReloadIcon,{className:"h-4 w-4"}),_("Retry")]})]}):a.jsx("p",{className:"text-sm",children:_("This library is empty")})}):n?a.jsxs(Ms,{value:w??"",onValueChange:N,children:[a.jsx(Fn,{className:"w-full",children:a.jsx(_o,{placeholder:_("Select a group")})}),a.jsx(zn,{children:d.map(v,(R,O)=>a.jsx(Hn,{value:O,children:d.capitalize(_(O.toLowerCase()))},O))})]}):d.map(v,(R,O)=>a.jsxs("div",{onMouseEnter:()=>A(O),onMouseLeave:()=>I.current&&clearTimeout(I.current),role:"button",onClick:()=>N(O),className:B.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",O===w?"bg-primary text-primary-foreground hover:bg-primary/80":""),children:[a.jsx("span",{children:d.capitalize(_(O.toLowerCase()))}),a.jsx(k.CaretRightIcon,{className:"ml-2 h-5 w-5"})]},O))})]})]}),a.jsx("div",{className:`flex h-full max-h-full w-full flex-col border-border ${n?"":"border-l"}`,children:a.jsxs(Nn,{ref:S,onMouseEnter:()=>I.current&&clearTimeout(I.current),className:"z-10 flex h-full max-h-full w-full flex-col gap-2 transition-all ease-linear",children:[d.isEmpty(E)&&!d.isEmpty(v)?a.jsx("div",{className:"flex h-full flex-col items-center justify-center p-6 text-center",children:a.jsx("p",{className:"text-sm",children:_("No blocks found in this group")})}):a.jsxs("div",{className:`grid w-full gap-2 ${n?"grid-cols-1 pb-20":"grid-cols-2 px-2"}`,children:[a.jsx("div",{className:"flex flex-col gap-1",children:T.map((R,O)=>a.jsx(Sa,{parentId:t,position:e,block:R,library:i},`block-${O}`))}),a.jsx("div",{className:"flex flex-col gap-1",children:P.map((R,O)=>a.jsx(Sa,{parentId:t,position:e,block:R,library:i},`block-second-${O}`))})]}),a.jsx("br",{}),a.jsx("br",{}),a.jsx("br",{})]})})]})})]})})},lc=({parentId:t,position:e,fromSidebar:n})=>a.jsx(Wg,{parentId:t,position:e,fromSidebar:n}),Gg=j.atom({blocks:[],groups:[],isLoading:!0,error:null}),Ug=j.atom(!1),Na=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(" ")},qg=({parentId:t,position:e,gridCols:n="grid-cols-2",disableBlockGroupsSidebar:s=!1})=>{const{data:r,isLoading:o,refetch:i,error:l}=Ei(),[c,u]=j.useAtom(Gg),[p,f]=j.useAtom(Ug);g.useEffect(()=>{if(!p||Object.keys(c.blocks).length===0)if(l)u({blocks:[],groups:[],isLoading:!1,error:l}),f(!0);else if(!o&&Object.keys(r||{}).length>0){const h=Object.entries(r).map(([b,y])=>{const v=y,w=v.type||"partial",N=Na(w);return{type:"PartialBlock",label:Na(v.name||b),description:v.description||"",icon:k.FrameIcon,group:N,category:"partial",partialBlockId:b,_name:v.name}}),x=d.uniq(d.map(h,"group"));u({blocks:h,groups:x,isLoading:!1,error:null}),f(!0)}else o?u(h=>({...h,isLoading:!0,error:null})):!o&&Object.keys(r||{}).length===0&&(u({blocks:[],groups:[],isLoading:!1,error:"No partial blocks available"}),f(!0))},[o,r,p,f,u,c.blocks,l]);const m=()=>{u(h=>({...h,isLoading:!0,error:null})),f(!1),i()};return c.isLoading?a.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?a.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 p-8 text-center text-muted-foreground",children:[a.jsx("p",{children:c.error||"No partial blocks available"}),a.jsx("button",{onClick:m,className:"rounded-md bg-primary px-3 py-1 text-sm text-primary-foreground hover:bg-primary/90",children:"Refresh"})]}):a.jsx(cc,{gridCols:n,parentId:t,position:e,groups:c.groups,blocks:c.blocks,disableBlockGroupsSidebar:s})},Ea=["basic","typography","media","layout","form","advanced","other"],cc=({groups:t,blocks:e,parentId:n,position:s,gridCols:r="grid-cols-4",disableBlockGroupsSidebar:o})=>{var P;const{t:i}=F.useTranslation(),[l]=te(),[c,u]=g.useState(""),p=g.useRef(null),[f]=j.useAtom(dc),m=(P=d.find(l,R=>R._id===n))==null?void 0:P._type,[h,x]=g.useState("all"),[b,y]=g.useState(null),v=g.useRef(null),w=$("flags.dragAndDrop",!0);g.useEffect(()=>{const R=setTimeout(()=>{var O;(O=p.current)==null||O.focus()},0);return()=>clearTimeout(R)},[f]),g.useEffect(()=>{c&&(x("all"),y(null))},[c]),g.useEffect(()=>(v.current=d.debounce(R=>{x(R)},500),()=>{v.current&&v.current.cancel()}),[]);const N=g.useCallback(R=>{y(R),v.current&&v.current(R)},[]),E=g.useCallback(()=>{y(null),v.current&&v.current.cancel()},[]),I=g.useCallback(R=>{v.current&&v.current.cancel(),x(R),y(null)},[]),_=g.useMemo(()=>c?d.values(e).filter(R=>{var O,z;return(((O=R.label)==null?void 0:O.toLowerCase())+" "+((z=R.type)==null?void 0:z.toLowerCase())).includes(c.toLowerCase())}):e,[e,c]),S=g.useMemo(()=>c?t.filter(R=>d.reject(d.filter(d.values(_),{group:R}),{hidden:!0}).length>0):t.filter(R=>d.reject(d.filter(d.values(e),{group:R}),{hidden:!0}).length>0),[e,_,t,c]),A=g.useMemo(()=>d.sortBy(S,R=>Ea.indexOf(R)===-1?99:Ea.indexOf(R)),[S]),C=g.useMemo(()=>h==="all"?_:d.filter(d.values(_),{group:h}),[_,h]),T=g.useMemo(()=>h==="all"?A:[h],[A,h]);return a.jsxs("div",{className:"mx-auto flex h-full w-full flex-col",children:[a.jsx(ic,{value:c,setValue:u}),a.jsxs("div",{className:"sticky top-10 flex h-[calc(100%-48px)] overflow-hidden pt-2",children:[!o&&A.length>0&&a.jsx("div",{className:"w-1/4 min-w-[120px] border-r border-border",children:a.jsx(Nn,{className:"h-full",children:a.jsxs("div",{className:"space-y-1",children:[a.jsx("button",{onClick:()=>I("all"),onMouseEnter:()=>N("all"),onMouseLeave:E,className:`w-full rounded-md px-2 py-1.5 text-left text-sm font-medium ${h==="all"||b==="all"?"bg-primary text-primary-foreground":"hover:bg-primary/50 hover:text-primary-foreground"}`,children:i("All")},"sidebar-all"),A.map(R=>a.jsx("button",{onClick:()=>I(R),onMouseEnter:()=>N(R),onMouseLeave:E,className:`w-full rounded-md px-2 py-1.5 text-left text-sm ${h===R||b===R?"bg-primary text-primary-foreground":"hover:bg-primary/50 hover:text-primary-foreground"}`,children:d.capitalize(i(R.toLowerCase()))},`sidebar-${R}`))]})})}),a.jsx("div",{className:`h-full flex-1 overflow-hidden ${!o&&A.length>0?"w-3/4":"w-full"}`,children:a.jsx(Nn,{id:"add-blocks-scroll-area",className:"no-scrollbar h-full",children:S.length===0&&c?a.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center text-muted-foreground",children:a.jsxs("p",{children:[i("No blocks found matching"),' "',c,'"']})}):a.jsx("div",{className:`${o?"p-0":"p-4"} space-y-6`,children:T.map((R,O)=>a.jsxs("div",{className:"space-y-3",children:[a.jsx("h3",{className:"px-1 text-sm font-medium",children:d.capitalize(i(R.toLowerCase()))}),a.jsx("div",{className:"grid gap-2 "+r,children:d.reject(h==="all"?d.filter(d.values(C),{group:R}):d.values(C),{hidden:!0}).map((z,G)=>a.jsx(Og,{parentId:n,position:s,block:z,disabled:!w&&(!Qe(m,z.type)||!kd(m,z.type))},z.type+"-"+O+"-"+G))})]},R))})})})]})]})},dc=Se.atomWithStorage("__add_block_tab","library"),Bo=({className:t,showHeading:e=!0,parentId:n=void 0,position:s=-1,fromSidebar:r=!1})=>{const{t:o}=F.useTranslation(),[i,l]=j.useAtom(dc),[,c]=j.useAtom(ii),u=$("flags.importHtml",!0),{data:p}=Ei(),f=Object.keys(p||{}).length>0,{hasPermission:m}=qe();g.useEffect(()=>{i==="partials"&&!f&&l("library")},[i,f,l]);const h=g.useCallback(()=>{oe.publish(K.CLOSE_ADD_BLOCK)},[]),x=B.useChaiAddBlockTabs(),b=u&&m(se.IMPORT_HTML),v=B.useChaiLibraries().length>0;return g.useEffect(()=>{i==="library"&&!v&&l("core")},[i,v,l]),a.jsxs("div",{className:ve.cn("flex h-full w-full flex-col overflow-hidden",t),children:[e?a.jsxs("div",{className:"mb-2 flex flex-col justify-between rounded-md bg-background/30 p-1",children:[a.jsx("h1",{className:"flex flex-col items-baseline px-1 text-xl font-semibold xl:flex-col",children:o("Add block")}),a.jsx("span",{className:"p-0 text-xs font-light leading-3 opacity-80 xl:pl-1",children:o(i==="html"?"Enter or paste TailwindCSS HTML snippet":"Click to add block to page")})]}):null,a.jsxs(Ls,{onValueChange:w=>{c(""),l(w)},value:i,className:"flex h-full max-h-full flex-col overflow-hidden",children:[a.jsxs(On,{className:`flex items-center ${r?"h-max w-max justify-start p-1":"w-full"}`,children:[v&&a.jsx(He,{value:"library",className:r?"h-5 px-2 text-xs":"",children:o("Library")}),a.jsx(He,{value:"core",className:r?"h-5 px-2 text-xs":"",children:o("Blocks")}),f&&a.jsx(He,{value:"partials",className:r?"h-5 px-2 text-xs":"",children:o("Partials")}),b?a.jsx(He,{value:"html",className:r?"h-5 px-2 text-xs":"",children:o("Import")}):null,d.map(x,w=>a.jsx(He,{value:w.id,className:r?"h-5 px-2 text-xs":"",children:g.createElement(w.tab)},`tab-add-block-${w.id}`))]}),a.jsx(ct,{value:"core",className:"h-full max-h-full flex-1 pb-20",children:a.jsx("div",{className:"h-full max-h-full overflow-hidden",children:a.jsx("div",{className:"h-full w-full",children:a.jsx(Zl,{gridCols:r?"grid-cols-2":"grid-cols-4",parentId:n,position:s,disableBlockGroupsSidebar:r})})})}),v&&a.jsx(ct,{value:"library",className:"h-full max-h-full flex-1 pb-20",children:a.jsx(lc,{fromSidebar:r,parentId:n,position:s})}),f&&a.jsx(ct,{value:"partials",className:"h-full max-h-full flex-1 pb-20",children:a.jsx("div",{className:"h-full max-h-full overflow-hidden",children:a.jsx("div",{className:"h-full w-full",children:a.jsx(qg,{gridCols:r?"grid-cols-2":"grid-cols-4",parentId:n,position:s,disableBlockGroupsSidebar:r})})})}),b?a.jsx(ct,{value:"html",className:"h-full max-h-full flex-1 pb-20 ",children:a.jsx(tc,{parentId:n,position:s,fromSidebar:r})}):null,d.map(x,w=>a.jsx(ct,{value:w.id,children:g.createElement(w.tabContent,{close:h,parentId:n,position:s})},`panel-add-block-${w.id}`))]})]})},Kg={display:"flex",alignItems:"center",zIndex:1},Yg=g.memo(function({top:e,left:n}){const s={position:"absolute",pointerEvents:"none",top:e+"px",left:n+"px",right:0};return a.jsx("div",{style:{...Kg,...s},children:a.jsx("div",{className:"h-0.5 flex-1 rounded-[1px] bg-green-500"})})}),Aa="h-3 w-3 flex-shrink-0",Ro=t=>{const e=X.useRegisteredChaiBlocks(),n=d.get(e,[t.type,"icon"]);return n?g.createElement(n,{className:Aa}):a.jsx(k.SquareIcon,{className:Aa})},Xg=g.memo(function({children:e,isDragging:n}){return n?a.jsx("div",{className:"pointer-events-none fixed left-0 top-0 z-[100] h-full w-full",children:e}):null}),Jg=g.memo(({id:t,isDragging:e,mouse:n})=>{const[s]=te(),r=g.useMemo(()=>s.find(i=>i._id===t),[s,t]),o=g.useMemo(()=>({transform:`translate(${(n==null?void 0:n.x)-10}px, ${(n==null?void 0:n.y)-10}px)`}),[n]);return n?a.jsx("div",{children:a.jsx(Xg,{isDragging:e,children:a.jsx("div",{className:"pointer-events-none absolute z-50 rounded border border-border bg-gray-100/80 font-semibold text-blue-600 shadow-md dark:border-gray-700 dark:bg-gray-800",style:o,children:a.jsxs("button",{type:"button",className:"flex !cursor-grab items-center p-0.5","aria-label":`Type: ${r==null?void 0:r._type}`,children:[a.jsx("div",{className:"-mt-0.5 h-3 w-3",children:a.jsx(Ro,{type:r==null?void 0:r._type})}),a.jsx("div",{className:"ml-2 truncate text-[11px]",children:(r==null?void 0:r._name)||(r==null?void 0:r._type)})]})})})}):a.jsx("div",{className:"hidden"})}),Zg=[{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 Qg(t){t.firstNode&&t.select(t.firstNode.id)}function ex(t){t.lastNode&&t.select(t.lastNode.id)}function tx(t){const e=t.selectedNodes[0].next||t.firstNode;t.select(e.id)}function nx(t){const e=t.selectedNodes[0].prev||t.lastNode;t.select(e.id)}const sx=(t,e)=>{const n=t.selectedNodes[0],s=(n==null?void 0:n.parent)||null;s&&e&&t.select(s.id)},rx=(t,e)=>{const n=t.selectedNodes[0];n.isInternal&&e&&n.open()},ox=(t,e)=>{const n=t.selectedNodes[0];n.isInternal&&e&&n.close()},Po=Pe.Root,uc=Pe.Trigger,ax=Pe.Portal,pc=D.forwardRef(({className:t,...e},n)=>a.jsx(Pe.Overlay,{className:B.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}));pc.displayName=Pe.Overlay.displayName;const Ds=D.forwardRef(({className:t,...e},n)=>a.jsxs(ax,{children:[a.jsx(pc,{}),a.jsx(Pe.Content,{ref:n,className:B.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),...e})]}));Ds.displayName=Pe.Content.displayName;const Os=({className:t,...e})=>a.jsx("div",{className:B.cn("flex flex-col space-y-2 text-center sm:text-left",t),...e});Os.displayName="AlertDialogHeader";const Lo=({className:t,...e})=>a.jsx("div",{className:B.cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...e});Lo.displayName="AlertDialogFooter";const $s=D.forwardRef(({className:t,...e},n)=>a.jsx(Pe.Title,{ref:n,className:B.cn("text-lg font-semibold",t),...e}));$s.displayName=Pe.Title.displayName;const Mo=D.forwardRef(({className:t,...e},n)=>a.jsx(Pe.Description,{ref:n,className:B.cn("text-sm text-muted-foreground",t),...e}));Mo.displayName=Pe.Description.displayName;const Do=D.forwardRef(({className:t,...e},n)=>a.jsx(Pe.Action,{ref:n,className:B.cn(B.buttonVariants(),t),...e}));Do.displayName=Pe.Action.displayName;const Oo=D.forwardRef(({className:t,...e},n)=>a.jsx(Pe.Cancel,{ref:n,className:B.cn(B.buttonVariants({variant:"outline"}),"mt-2 sm:mt-0",t),...e}));Oo.displayName=Pe.Cancel.displayName;const fc=({children:t})=>{const{t:e}=F.useTranslation(),{setNewBlocks:n}=Ne(),[,s]=U(),[,r]=Ee(),o=g.useCallback(()=>{n([]),s([]),r([])},[n]);return a.jsx("div",{className:"flex items-center",children:a.jsxs(Po,{children:[a.jsx(uc,{asChild:!0,children:t||a.jsxs(B.Button,{size:"sm",variant:"ghost",className:"flex items-center",children:[a.jsx(k.EraserIcon,{})," ",e("Clear")]})}),a.jsxs(Ds,{className:"border-border",children:[a.jsxs(Os,{children:[a.jsx($s,{className:"text-foreground",children:e("Clear whole canvas?")}),a.jsx(Mo,{children:e("Are you sure you want to clear the page?")})]}),a.jsxs(Lo,{children:[a.jsx(Oo,{className:"text-foreground",children:e("Cancel")}),a.jsx(Do,{onClick:o,children:e("Yes")})]})]})]})})},ix=()=>{const t=J(),{t:e}=F.useTranslation(),[,n]=j.useAtom(ti),s=B.useSaveToLibraryComponent(),r=()=>{t&&n({isOpen:!0,blockId:t._id})};return s?a.jsxs(le,{className:"flex items-center gap-x-4 text-xs",onClick:r,children:[a.jsx(k.CheckIcon,{className:"h-4 w-4"})," ",t!=null&&t._libBlockId?e("Update library block"):e("Save to library")]}):null},lx=()=>{const{t}=F.useTranslation(),e=J(),n=nt(),s=()=>{e&&n([e._id],{_libBlockId:null})};return a.jsxs(le,{onClick:s,className:"flex items-center gap-x-4 text-xs",children:[a.jsx(k.LinkBreak2Icon,{className:"h-4 w-4"})," ",t("Unlink from library")]})},Ia=()=>{const{t}=F.useTranslation(),[e]=U();return $("flags.exportCode",!1)?a.jsxs(le,{className:"flex items-center gap-x-4 text-xs",onClick:()=>oe.publish(K.OPEN_EXPORT_CODE,e),children:[a.jsx(k.DownloadIcon,{})," ",t("Export")]}):null},Ta=({isFromBody:t=!1})=>{const[e]=te(),[n]=U(),{pasteBlocks:s}=Kr(),[,r,o]=Ii(),{t:i}=F.useTranslation(),l=J(),c=$("flags.copyPaste",!0),u=g.useCallback(()=>{var m;const f=(t?(m=e==null?void 0:e.filter(h=>!(h!=null&&h._parent)))==null?void 0:m.map(h=>h==null?void 0:h._id):n).map(h=>{const x=e.find(b=>b._id===h);return{id:h,data:x}});o(f.map(h=>h.id))?pe.toast.warning("Partial blocks detected. Clone partial blocks?",{cancel:{label:i("No"),onClick:()=>{r(f.map(h=>h.id)),pe.toast.dismiss()}},action:{label:i("Yes"),onClick:()=>{r(f.map(h=>h.id),!0),pe.toast.dismiss()}},position:"top-center"}):r(f.map(h=>h.id))},[n,e,r,o]);return a.jsxs(a.Fragment,{children:[c&&a.jsxs(le,{disabled:!Cr(l==null?void 0:l._type),onClick:u,className:"flex items-center gap-x-4 text-xs",children:[a.jsx(k.CopyIcon,{})," ",i("Copy")]}),c&&a.jsxs(le,{className:"flex items-center gap-x-4 text-xs",onClick:()=>{s(n)},children:[a.jsx(k.CardStackIcon,{})," ",i("Paste")]})]})},cx=()=>{const[t]=U(),[,e]=Es(),{t:n}=F.useTranslation(),s=$("flags.copyPaste",!0);return a.jsx(a.Fragment,{children:s&&a.jsxs(le,{className:"flex items-center gap-x-4 text-xs",onClick:()=>e(t),children:[a.jsx(k.ScissorsIcon,{})," ",n("Cut")]})})},dx=()=>{const[t]=U(),e=Cs(),n=J(),{t:s}=F.useTranslation();return a.jsxs(le,{disabled:!jr(n==null?void 0:n._type),className:"flex items-center gap-x-4 text-xs",onClick:()=>e(t),children:[a.jsx(k.TrashIcon,{})," ",s("Remove")]})},ux=({node:t})=>{const{t:e}=F.useTranslation();return a.jsxs(le,{onClick:n=>{n.stopPropagation(),t.edit(),t.deselect()},className:"flex items-center gap-x-4 text-xs",children:[a.jsx(k.Pencil2Icon,{className:"h-4 w-4"})," ",e("Rename")]})},px=({node:t})=>{const{t:e}=F.useTranslation(),[n]=U(),s=Ur(),r=J(),{hasPermission:o}=qe(),{librarySite:i}=$("flags",{librarySite:!1}),l=Ye(),c=g.useCallback(()=>{s(n)},[n,s]),u=g.useMemo(()=>d.has(r,"_libBlockId")&&!d.isEmpty(r._libBlockId),[r==null?void 0:r._libBlockId]);return t==="BODY"?a.jsx(Ge,{side:"bottom",className:"border-border text-xs",children:o(se.ADD_BLOCK)&&a.jsxs(a.Fragment,{children:[a.jsxs(le,{disabled:!1,className:"flex items-center gap-x-4 text-xs",onClick:()=>oe.publish(K.OPEN_ADD_BLOCK,r),children:[a.jsx(k.PlusIcon,{className:"h-3.5 w-3.5"})," ",e("Add block")]}),o(se.ADD_BLOCK)&&a.jsx(Ta,{isFromBody:!0}),a.jsx(Ia,{}),a.jsx(le,{disabled:!1,onClick:p=>p.preventDefault(),className:"flex items-center gap-x-4 text-xs",children:a.jsx(fc,{children:a.jsxs("div",{className:"flex items-center gap-x-4 text-xs",children:[a.jsx(k.EraserIcon,{})," ",e("Clear canvas")]})})})]})}):a.jsxs(Ge,{side:"bottom",className:"border-border text-xs",children:[o(se.ADD_BLOCK)&&a.jsxs(a.Fragment,{children:[!l&&a.jsxs(le,{disabled:!ss(r==null?void 0:r._type),className:"flex items-center gap-x-4 text-xs",onClick:()=>oe.publish(K.OPEN_ADD_BLOCK,r),children:[a.jsx(k.PlusIcon,{className:"h-3.5 w-3.5"})," ",e("Add block")]}),a.jsxs(le,{disabled:!Cr(r==null?void 0:r._type),className:"flex items-center gap-x-4 text-xs",onClick:c,children:[a.jsx(k.CardStackPlusIcon,{})," ",e("Duplicate")]})]}),a.jsx(ux,{node:t}),o(se.MOVE_BLOCK)&&a.jsx(cx,{}),o(se.ADD_BLOCK)&&a.jsx(Ta,{}),u&&i&&a.jsx(lx,{}),o(se.CREATE_LIBRARY_BLOCK)&&i&&a.jsx(ix,{}),a.jsx(Ia,{}),o(se.DELETE_BLOCK)&&a.jsx(dx,{})]})},hc=({children:t,id:e,node:n})=>{const[,s]=U();return a.jsx(a.Fragment,{children:a.jsxs(et,{onOpenChange:r=>{r&&s([e])},children:[a.jsx(tt,{children:t}),a.jsx(px,{node:n})]})})},se={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(se);const mc=()=>{const[t]=j.useAtom(Qt),[e]=j.useAtom(Nr),[n]=j.useAtom(Er),[s]=j.useAtom(Ar),[r]=j.useAtom(Ga),[o]=j.useAtom(Ua),[i]=j.useAtom(qa);return{errors:t,isValid:e,hasErrors:n,hasWarnings:s,errorCount:r,warningCount:o,errorsByBlock:i,getBlockErrors:l=>i[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)})}},fx=({node:t})=>{var e,n;return a.jsx("input",{autoFocus:!0,className:xe("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)}})},hx=j.atom(null),sr=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())||""},mx=(t,e)=>t.length>e?t.substring(0,e)+"...":t,gx=g.memo(({node:t,style:e,dragHandle:n})=>{var Ae,Oe;const{t:s}=F.useTranslation(),r=nt(),[o]=j.useAtom(Ss),{hasPermission:i}=qe();let l=null;const c=t.children&&t.children.length>0,{highlightBlock:u,clearHighlight:p}=st(),f=Ye(),{id:m,data:h,isSelected:x,willReceiveDrop:b,isDragging:y,isEditing:v,handleClick:w}=t,N=mc(),E=g.useMemo(()=>N.getBlockErrors(m),[N,m]),I=d.get(h,"_show",!0),_=W=>{W.stopPropagation(),I&&t.toggle()},S=W=>{W.isInternal&&(l=W.isOpen,W.isOpen&&W.close())},A=W=>{W.isInternal&&l!==null&&(l?W.open():W.close(),l=null)},[C,T]=j.useAtom(hx),P=()=>{var W,$e;R(),(W=t.parent)!=null&&W.isSelected||T(($e=t==null?void 0:t.parent)==null?void 0:$e.id)},R=()=>{T(null)},O=W=>{R(),W.stopPropagation(),!t.isOpen&&I&&t.toggle(),w(W)};g.useEffect(()=>{const W=setTimeout(()=>{b&&!t.isOpen&&!y&&I&&t.toggle()},500);return()=>clearTimeout(W)},[b,t,y]);const z=(W,$e)=>{var Z;const vt=o.contentDocument||((Z=o.contentWindow)==null?void 0:Z.document),kt=vt==null?void 0:vt.querySelector(`[data-block-id=${W}]`);kt&&kt.setAttribute("data-drop",$e);const Wt=kt.getBoundingClientRect(),pt=o.getBoundingClientRect();!(Wt.top>=pt.top&&Wt.left>=pt.left&&Wt.bottom<=pt.bottom&&Wt.right<=pt.right)&&vt&&(vt.documentElement.scrollTop=kt.offsetTop-pt.top)},G=W=>{R();const $e=d.get(t,"parent.id");$e!=="__REACT_ARBORIST_INTERNAL_ROOT__"?oe.publish(K.OPEN_ADD_BLOCK,{_id:$e,position:W}):oe.publish(K.OPEN_ADD_BLOCK,{position:W})};if(m===q.ROOT_TEMP_KEY)return a.jsxs("div",{className:"group relative mt-2 w-full cursor-pointer",children:[a.jsx("br",{}),i(se.ADD_BLOCK)&&a.jsx("div",{role:"button",onClick:()=>G(-1),className:"h-1 rounded bg-primary opacity-0 duration-200 group-hover:opacity-100",children:a.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:[a.jsx(k.PlusIcon,{className:"w-2.4 h-2.5 stroke-[5] text-white"})," ",s("Add block")]})}),a.jsx("br",{})]});const{librarySite:de}=$("flags",{librarySite:!1}),ue=g.useMemo(()=>de&&d.has(h,"_libBlockId")&&!d.isEmpty(h._libBlockId)&&(i(se.CREATE_LIBRARY_BLOCK)||i(se.EDIT_LIBRARY_BLOCK)),[h,i,de]),ne=g.useMemo(()=>(h==null?void 0:h._type)==="PartialBlock"||(h==null?void 0:h._type)==="GlobalBlock",[h]);return a.jsx("div",{className:"w-full",children:a.jsxs("div",{onMouseEnter:()=>u(m),onMouseLeave:()=>p(),onClick:O,style:e,"data-node-id":m,ref:n,onDragStart:()=>S(t),onDragEnd:()=>A(t),onDragOver:W=>{W.preventDefault(),z(m,"yes")},onDragLeave:W=>{W.preventDefault(),z(m,"no")},onDrop:W=>{W.preventDefault(),z(m,"no")},children:[i(se.ADD_BLOCK)&&!f&&(t==null?void 0:t.rowIndex)!==null&&(t==null?void 0:t.rowIndex)!==void 0&&(t==null?void 0:t.rowIndex)>0&&(((Ae=t.parent)==null?void 0:Ae.isOpen)&&ss(d.get(t,"parent.data._type"))||((Oe=t==null?void 0:t.parent)==null?void 0:Oe.id)==="__REACT_ARBORIST_INTERNAL_ROOT__")&&a.jsx("div",{className:"group relative ml-5 h-full w-full cursor-pointer",children:a.jsx("div",{onClick:W=>{W.stopPropagation(),G(t.childIndex)},onMouseEnter:P,onMouseLeave:R,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:a.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:a.jsx(k.PlusIcon,{className:"h-2 w-2 stroke-[2] text-white"})})})}),a.jsxs("div",{className:xe("group flex w-full cursor-pointer items-center justify-between space-x-px !rounded p-1 py-0 outline-none",x?"bg-primary/20":"hover:bg-primary/10",b&&Qe(h._type,"Icon")?"bg-green-200":"",(t==null?void 0:t.id)===C?"bg-primary/10":"",y&&"opacity-20",I?"":"line-through opacity-50",ue&&x&&"bg-primary/20 text-primary"),children:[a.jsxs("div",{className:"flex items-center",children:[a.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:c&&a.jsx("button",{onClick:_,type:"button",children:a.jsx(k.ChevronRightIcon,{className:"h-3 w-3"})})}),a.jsxs("div",{className:xe("leading-1 flex items-center",ue&&"text-orange-600/90",ue&&x&&"text-orange-800",ne&&"text-purple-600/90",ne&&x&&"text-purple-800"),children:[E.length>0?a.jsx("div",{className:"text-red-500",children:a.jsx(k.ExclamationTriangleIcon,{className:"h-3 w-3"})}):a.jsx(Ro,{type:h==null?void 0:h._type}),v?a.jsx(fx,{node:t}):a.jsx("div",{className:"ml-1.5 flex items-center gap-x-1 truncate text-[13px]",onDoubleClick:W=>{W.stopPropagation(),t.edit(),t.deselect()},children:a.jsx("span",{title:sr(h).length>17?sr(h):"",children:mx(sr(h),17)})})]})]}),a.jsxs("div",{className:"invisible flex items-center space-x-1.5 pr-px group-hover:visible",children:[ss(h==null?void 0:h._type)&&I&&i(se.ADD_BLOCK)?a.jsxs(fe,{children:[a.jsx(he,{onClick:()=>oe.publish(K.OPEN_ADD_BLOCK,{_id:m}),className:"cursor-pointer rounded bg-transparent p-px hover:bg-primary/10",asChild:!0,children:a.jsx(k.PlusIcon,{className:"h-4 w-4"})}),a.jsx(ce,{className:"isolate z-[9999]",side:"bottom",children:s("Add block inside")})]}):null,a.jsxs(fe,{children:[a.jsx(he,{onClick:W=>{W.stopPropagation(),r([m],{_show:!I}),t.isOpen&&t.toggle()},className:"cursor-pointer rounded bg-transparent p-0.5 hover:bg-primary/10",asChild:!0,children:I?a.jsx(k.EyeClosedIcon,{className:"h-4 w-4"}):a.jsx(k.EyeOpenIcon,{className:"h-4 w-4"})}),a.jsx(ce,{className:"isolate z-[9999] text-xs",side:"bottom",children:s(I?"Hide the block from page":"Show the block on page")})]}),a.jsx(hc,{node:t,id:m,children:a.jsx("div",{className:"cursor-pointer rounded bg-transparent p-px hover:bg-primary/10",children:a.jsx(k.DotsVerticalIcon,{className:"h-3 w-3"})})})]})]})]})})}),gc=(t,e)=>{const n=d.filter(t,{_parent:e});if(n.length===0)return[];const s=[...n];return n.forEach(r=>{s.push(...gc(t,r==null?void 0:r._id))}),s},xx=()=>{const[t,e]=j.useAtom(ti),{t:n}=F.useTranslation(),[s]=te(),r=()=>e({isOpen:!1,blockId:null}),o=B.useSaveToLibraryComponent(),i=g.useMemo(()=>{if(!t.blockId)return[];const l=d.find(s,{_id:t.blockId});return l==null||delete l._parent,[l,...gc(s,l==null?void 0:l._id)]},[t.blockId,s]);return a.jsx(Pn,{open:t.isOpen,onOpenChange:l=>!l&&r(),children:a.jsxs(an,{className:"p-4 sm:max-w-[450px]",children:[a.jsx(Ln,{className:"pb-2",children:a.jsx(ln,{children:n("Save to Library")})}),o&&!d.isEmpty(t.blockId)&&a.jsx(o,{blockId:t.blockId,blocks:i,close:r})]})})},bx=({parentContext:t,setParentContext:e})=>{const{t:n}=F.useTranslation(),{canPaste:s,pasteBlocks:r}=Kr(),o=$("flags.copyPaste",!0);return g.useEffect(()=>{s("root")||e(null)},[s("root")]),!t||!s("root")||!o?null:a.jsx("div",{className:"absolute inset-0",children:a.jsxs(et,{open:!0,onOpenChange:()=>e(null),children:[a.jsx(tt,{className:"hidden"}),a.jsx(Ge,{className:"absolute w-28 p-1 text-xs",style:{top:t.y,left:t.x},children:a.jsxs(le,{className:"flex items-center gap-x-4 text-xs",onClick:()=>{r("root"),e(null)},children:[a.jsx(k.CardStackIcon,{})," ",n("Paste")]})})]})})},yx=()=>{const[t]=te();return(e,n)=>{const s=d.find(t,{_id:n});if(!s)return!1;const r=d.first(e.map(o=>{var i;return(i=d.find(t,{_id:o}))==null?void 0:i._type}));return r?Qe(s._type,r):!1}},xc=()=>{const[t]=j.useAtom(Va),[e,n]=U(),[s]=Es(),r=nt(),[,o]=Ee(),{moveBlocks:i}=Ne(),l=yx(),c=g.useRef(null),[,u]=j.useAtom(zr),{t:p}=F.useTranslation(),[f,m]=g.useState(null),h=()=>{n([]),o([])},x=g.useMemo(()=>{const S=(C,T)=>C.filter(P=>!T.includes(P._id)).map(P=>({...P,children:P.children?S(P.children,T):[]}));return[...S(t,s),{_type:q.ROOT_TEMP_KEY,_id:q.ROOT_TEMP_KEY,children:[]}]},[t,s]),b=({id:S,name:A,node:C})=>{r([S],{_name:A},C.data._name)},y=({dragIds:S,parentId:A,index:C})=>{l(S,A)&&i(S,A,C)},v=S=>{if(S.length===0)return;const A=S[0]?S[0].id:"";o([]),n([A])},w=S=>{var T;S.preventDefault(),f&&m(null);const A=S.target,C=A.getAttribute("data-node-id")||((T=A.closest("[data-node-id]"))==null?void 0:T.getAttribute("data-node-id"));C?(o([]),n([C])):(o([]),n([]),m({x:S.clientX,y:S.clientY}))},N=ke.useDebouncedCallback(({parentNode:S,dragNodes:A})=>{var C;return(S==null?void 0:S.data._type)===q.ROOT_TEMP_KEY||!Qe(S==null?void 0:S.data._type,(C=A[0])==null?void 0:C.data._type)},[],300),E=(S,A)=>{if(!S)return!0;const C={isLeaf:!A.isInternal,isClosed:!A.isOpen,isOpen:A.isOpen};try{let T=S;return Object.keys(C).forEach(P=>{const R=new RegExp(`\\b${P}\\b`,"g");T=T.replace(R,String(C[P]))}),new Function(`return ${T}`)()}catch{return console.warn("Invalid condition expression:",S),!1}},I=S=>{if(!c.current)return;const A=c.current,C=A.selectedNodes[0];if(!C)return;n([C.id]),o([]);const T=!C.isInternal,P=!C.isOpen,R=C.isOpen,O=Zg.find(z=>z.key===S.key&&(!z.when||E(z.when,C)));if(O)switch(S.preventDefault(),O.command){case"selectNext":tx(A);break;case"selectPrev":nx(A);break;case"selectParent":sx(A,T||P);break;case"close":ox(A,R);break;case"open":rx(A,P);break;case"selectFirst":Qg(A);break;case"selectLast":ex(A);break}};g.useEffect(()=>{const S=()=>{c.current&&u(c.current)};S();const A=new MutationObserver(S);return A.observe(document.body,{childList:!0,subtree:!0}),()=>A.disconnect()},[u]);const{hasPermission:_}=qe();return d.isEmpty(t)?a.jsx("div",{children:a.jsx("div",{className:"mt-10 flex h-full w-full items-center justify-center p-8",children:a.jsxs("div",{className:"flex flex-col items-center space-y-6 text-center",children:[a.jsx("div",{className:"rounded-full bg-muted p-6",children:a.jsx(k.StackIcon,{className:"h-12 w-12 text-muted-foreground"})}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("h3",{className:"text-lg font-semibold text-foreground",children:p("This page is empty")}),a.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")})]}),_(se.ADD_BLOCK)&&a.jsxs(B.Button,{onClick:()=>oe.publish(K.OPEN_ADD_BLOCK),className:"bg-primary shadow-sm hover:bg-primary/90",size:"sm",children:[a.jsx(k.PlusIcon,{className:"h-4 w-4"}),p("Add Block")]})]})})}):a.jsxs(a.Fragment,{children:[a.jsx("div",{className:ve.cn("flex h-full select-none flex-col space-y-1"),onClick:()=>h(),children:a.jsxs("div",{id:"outline-view ",className:"no-scrollbar h-full overflow-y-auto text-sm",onKeyDown:S=>{c.current&&!c.current.isEditing&&I(S)},children:[a.jsxs("div",{className:"mb-2 flex items-center justify-end gap-x-1 pb-2 text-sm text-muted-foreground",children:[a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(B.Button,{className:"h-fit p-1",onClick:()=>{var S;return(S=c==null?void 0:c.current)==null?void 0:S.openAll()},variant:"ghost",size:"sm",children:a.jsx(k.DoubleArrowDownIcon,{className:"h-2 w-2"})})}),a.jsx(ce,{className:"isolate z-[9999]",children:p("Expand all")})]}),a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:a.jsx(B.Button,{className:"h-fit p-1",onClick:()=>{var S;return(S=c==null?void 0:c.current)==null?void 0:S.closeAll()},variant:"ghost",size:"sm",children:a.jsx(k.DoubleArrowUpIcon,{className:"h-2 w-2"})})}),a.jsx(ce,{className:"isolate z-[9999]",children:p("Collapse all")})]})]}),a.jsx("div",{className:"group relative z-30 ml-5 w-full cursor-pointer",children:a.jsx("div",{onClick:()=>oe.publish(K.OPEN_ADD_BLOCK,{position:0}),className:"h-1 w-[90%] rounded bg-primary opacity-0 duration-200 group-hover:opacity-100",children:a.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:a.jsx(k.PlusIcon,{className:"h-3 w-3 stroke-[3] text-white"})})})}),a.jsx("div",{children:a.jsx("div",{role:"treeitem","aria-level":0,"aria-selected":!0,"aria-expanded":!1,onClick:()=>n([]),className:"flex h-full items-center border-b border-transparent",children:a.jsxs("div",{className:ve.cn("group flex w-full cursor-pointer items-center justify-between space-x-px !rounded p-1 py-0 outline-none",e.length===0?"bg-primary/20":""),children:[a.jsxs("div",{className:"leading-1 flex items-center",children:[a.jsx(k.CardStackIcon,{className:"h-3 w-3 flex-shrink-0 rotate-180"}),a.jsx("div",{className:"ml-1.5 flex items-center gap-x-1 truncate text-[13px]",children:"Body"})]}),a.jsx(hc,{node:"BODY",id:"BODY",children:a.jsx("div",{className:"hidden cursor-pointer rounded bg-transparent p-px hover:bg-primary/10 group-hover:block",children:a.jsx(k.DotsVerticalIcon,{className:"h-3 w-3"})})})]})})}),a.jsx(ld.Tree,{ref:c,height:window.innerHeight-160,className:"no-scrollbar !h-full max-w-full space-y-1 !overflow-y-auto !overflow-x-hidden",rowClassName:"flex items-center h-full border-b border-transparent",selection:e[0]||"",onRename:b,openByDefault:!1,onMove:y,data:[...x],renderCursor:Yg,onSelect:v,childrenAccessor:S=>S.children,width:"100%",rowHeight:25,renderDragPreview:Jg,indent:10,onContextMenu:w,disableDrop:N,idAccessor:"_id",children:gx})]})}),a.jsx(xx,{}),a.jsx(bx,{parentContext:f,setParentContext:m})]})},Rt=D.forwardRef(({className:t,orientation:e="horizontal",decorative:n=!0,...s},r)=>a.jsx($a.Root,{ref:r,decorative:n,orientation:e,className:B.cn("shrink-0 bg-border",e==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...s}));Rt.displayName=$a.Root.displayName;const cn=D.forwardRef(({className:t,thumbClassName:e,...n},s)=>a.jsx(or.Root,{className:B.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:a.jsx(or.Thumb,{className:B.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")})}));cn.displayName=or.Root.displayName;const bc=D.forwardRef(({className:t,...e},n)=>a.jsxs(un.Root,{ref:n,className:B.cn("relative flex w-full touch-none select-none items-center",t),...e,children:[a.jsx(un.Track,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-neutral-300",children:a.jsx(un.Range,{className:"absolute h-full bg-neutral-900"})}),a.jsx(un.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"})]}));bc.displayName=un.Root.displayName;const vx=({value:t,onChange:e,disabled:n})=>{const[s,r]=g.useState(t),o=ke.useThrottledCallback(e,[t],200,!0);return a.jsx(bc,{min:0,step:1,max:50,disabled:n,value:[Number(s.replace("px",""))],onValueChange:i=>{r(i[0].toString()+"px"),o(i[0].toString())},className:"flex-1 cursor-pointer"})},kx=({value:t,onChange:e})=>{const n=d.debounce(s=>e(s),200);return a.jsx("div",{className:"relative flex h-6 w-6 cursor-pointer rounded-lg border border-border",style:{backgroundColor:t},children:a.jsx("input",{type:"color",value:t.startsWith("#")?t:"#000000",onChange:s=>{const r=s.target.value;/^#[0-9A-F]{6}$/i.test(r)&&n(r)},className:"absolute inset-0 h-full w-full cursor-pointer rounded-lg border-0 opacity-0"})})},wx=({label:t,value:e,onChange:n})=>{const s=Da.useRegisteredFonts(),{t:r}=F.useTranslation();return g.useEffect(()=>{s.some(o=>o.family===e)||n(s[0].family)},[e,n]),a.jsxs("div",{className:"space-y-0.5",children:[a.jsx(ut,{className:"mb-1 block text-xs text-gray-600",children:r(d.startCase(t))}),a.jsxs(Ms,{value:e,onValueChange:n,children:[a.jsx(Fn,{className:"h-8 w-full text-xs text-black",children:a.jsx(_o,{placeholder:r("Select font")})}),a.jsx(zn,{children:s.map(o=>a.jsx(Hn,{value:o.family,children:o.family},o.family))})]})]})},Cx={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"]}},jx={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"]}},Sx={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"]}},Nx={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"]}},Ex={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"]}},Ax=g.lazy(()=>Promise.resolve().then(()=>require("./css-import-modal-D2RqE-V0.cjs")).then(t=>({default:t.CssImportModal}))),yc="chai-builder-previous-theme",Ix=[{shadcn_default:Cx},{twitter_theme:jx},{solarized_theme:Sx},{claude_theme:Nx},{supabase_theme:Ex}],Tx=t=>{if(!(typeof window>"u"))try{localStorage.setItem(yc,JSON.stringify(t))}catch(e){console.warn("Failed to save previous theme to localStorage:",e)}},_x=()=>{if(!(typeof window>"u"))try{localStorage.removeItem(yc)}catch(t){console.warn("Failed to clear previous theme from localStorage:",t)}},vc=D.memo(({className:t=""})=>{const[e,n]=Rn(),[s,r]=D.useState(""),[o,i]=D.useState(!1),l=$("themePresets",{}),c=$("themePanelComponent",null),{hasPermission:u}=qe(),p=$("flags.importTheme",!0),f=$("flags.darkMode",!0),m=$("flags.fontsInTheme",!1),h=Dr();(!l||l.length===0)&&Ix.map(C=>{l.push(C)});const[x,b]=An(),y=In(),{t:v}=F.useTranslation(),w=D.useCallback(C=>{const T={...x};Tx(T),b(C),h(),pe.toast.success("Theme updated",{action:{label:a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(k.ResetIcon,{className:"h-4 w-4"})," Undo"]}),onClick:()=>{b(T),_x(),pe.toast.dismiss()}},closeButton:!0,duration:15e3})},[x,b,h]),N=()=>{const C=l.find(T=>Object.keys(T)[0]===s);if(C){const T=Object.values(C)[0];T&&typeof T=="object"&&"fontFamily"in T&&"borderRadius"in T&&"colors"in T?(w(T),r(""),h()):console.error("Invalid preset structure:",T)}else console.error("Preset not found:",s)},E=C=>{w(C),r(""),h()},I=ke.useDebouncedCallback((C,T)=>{b(()=>({...x,fontFamily:{...x.fontFamily,[C.replace(/font-/g,"")]:T}})),h()},[x,h],200),_=D.useCallback(C=>{b(()=>({...x,borderRadius:`${C}px`})),h()},[x,h]),S=ke.useDebouncedCallback((C,T)=>{b(()=>{const P=d.get(x,`colors.${C}`);return e?d.set(P,1,T):d.set(P,0,T),h(),{...x,colors:{...x.colors,[C]:P}}})},[x,h],200),A=C=>a.jsx("div",{className:"grid grid-cols-1",children:Object.entries(C.items).map(([T])=>{const P=d.get(x,`colors.${T}.${e?1:0}`);return P?a.jsxs("div",{id:`theme-${T}`,className:"mt-1 flex items-center gap-x-2",children:[a.jsx(kx,{value:P,onChange:R=>S(T,R)}),a.jsx(ut,{className:"text-xs font-normal leading-tight",children:T.split(/(?=[A-Z])/).join(" ").replace(/-/g," ").split(" ").map(R=>R.charAt(0).toUpperCase()+R.slice(1)).join(" ")+(!T.toLowerCase().includes("foreground")&&!T.toLowerCase().includes("border")&&!T.toLowerCase().includes("input")&&!T.toLowerCase().includes("ring")&&!T.toLowerCase().includes("background")?" Background":"")})]},T):null})});return u("edit_theme")?a.jsxs("div",{className:"relative w-full",children:[a.jsxs("div",{className:ve.cn("no-scrollbar h-full w-full overflow-y-auto",t),children:[l.length>0&&a.jsxs("div",{className:"mx-0 my-2 flex flex-col gap-1 py-2",children:[a.jsxs("div",{className:"flex w-full items-center justify-between",children:[a.jsx(ut,{className:"text-sm",children:v("Presets")}),a.jsx("div",{className:"flex gap-2",children:p&&a.jsxs(B.Button,{className:"px-1",variant:"link",size:"sm",onClick:()=>i(!0),children:[a.jsx(k.UploadIcon,{className:"h-4 w-4"}),v("Import theme")]})})]}),a.jsxs("div",{className:"flex items-center gap-2 px-0",children:[a.jsx("div",{className:"w-[70%]",children:a.jsxs(Ms,{value:s,onValueChange:r,children:[a.jsx(Fn,{className:"h-9 w-full text-sm",children:a.jsx(_o,{placeholder:v("Select preset")})}),a.jsx(zn,{children:Array.isArray(l)&&l.map(C=>{const T=Object.keys(C)[0],P=T.replaceAll("_"," ");return a.jsx(Hn,{value:T,children:d.capitalize(P)},T)})})]})}),a.jsx("div",{className:"w-[25%]",children:a.jsx(B.Button,{className:"w-full text-sm",disabled:!s,onClick:N,children:v("Apply")})})]})]}),a.jsx(Rt,{}),a.jsxs("div",{className:ve.cn("my-2 space-y-3",t),children:[m&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(k.TextIcon,{className:"h-3 w-3 text-gray-600"}),a.jsx("span",{className:"text-xs font-medium text-gray-700",children:v("Typography")})]}),(y==null?void 0:y.fontFamily)&&a.jsx("div",{className:"space-y-2",children:Object.entries(y.fontFamily).map(([C,T])=>a.jsx(wx,{label:C,value:x.fontFamily[C.replace(/font-/g,"")]||T[Object.keys(T)[0]],onChange:P=>I(C,P)},C))}),a.jsx(Rt,{})]}),(y==null?void 0:y.borderRadius)&&a.jsxs("div",{className:"space-y-0.5",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(k.CornerTopRightIcon,{className:"h-3 w-3 text-gray-600"}),a.jsx("span",{className:"text-xs font-medium text-gray-700",children:v("Border Radius")})]}),a.jsx(_s,{variant:"secondary",className:"text-xs",children:x.borderRadius})]}),a.jsx("div",{className:"flex items-center gap-4 py-2",children:a.jsx(vx,{value:x.borderRadius,onChange:_})})]}),a.jsx(Rt,{}),(y==null?void 0:y.colors)&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(k.MixerHorizontalIcon,{className:"h-3 w-3 text-gray-600"}),a.jsx("span",{className:"text-xs font-medium text-gray-700",children:v("Colors")})]}),f&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(k.SunIcon,{className:"h-4 w-4"}),a.jsx(cn,{checked:e,onCheckedChange:C=>n(C),"aria-label":v("Toggle dark mode"),className:"mx-1"}),a.jsx(k.MoonIcon,{className:"h-4 w-4"})]})]}),a.jsx("div",{className:"space-y-2",children:y.colors.map(C=>A(C))})]}),a.jsx(g.Suspense,{fallback:a.jsx("div",{children:v("Loading...")}),children:o&&p&&a.jsx(Ax,{open:o,onOpenChange:i,onImport:E})})]}),a.jsx("br",{}),a.jsx("br",{}),a.jsx("br",{}),a.jsx("br",{})]}),c&&a.jsx("div",{className:"absolute bottom-4 w-full",children:D.createElement(c)})]}):a.jsx("div",{className:"relative w-full",children:a.jsx("div",{className:ve.cn("no-scrollbar h-full w-full overflow-y-auto text-center",t),children:a.jsx("div",{className:"mt-10 h-full items-center justify-center gap-2 text-muted-foreground",children:a.jsx("p",{className:"text-sm",children:v("You don't have permission to edit the theme. Please contact your administrator to get access.")})})})})}),Bx="Core",Rx="Import",Px="Breakpoints",Lx="Clear",Mx="Cancel",Dx="Yes",Ox="Preview",$x="Settings",Fx="Style",zx="Enter SVG code here",Hx="Remove",Vx="Choose",Wx="Cut",Gx="Copy",Ux="Paste",qx="Delete",Kx="classes",Yx="Theme",Xx="Outline",Jx="Copied",Zx="Stop",Qx="Edit",eb="Tag",tb="Value",nb="URL",sb="Images",rb="Library",ob="Blocks",ab="Basic",ib="Media",lb="Advanced",cb="Form",db="Groups",ub="Accordions",pb="Buttons",fb="Layouts",hb="FAQ",mb="Hero",gb="Features",xb="Footer",bb="Navbar",yb="Icons",vb="Testimonials",kb="Blog",wb="Saved",Cb="Unsaved",jb="Randomize",Sb="Classes",Nb="All",Eb="Undo",Ab="Redo",Ib="Duplicate",Tb="Close",_b="Selected",Bb="Select",Rb="Attributes",Pb="apply",Lb="presets",Mb="Orientation",Db="Color",Ob="Upload",$b="Apply",Fb="Back",zb="Insert",Hb="Rename",Vb="Partials",Wb="Happy",Gb="Sad",Ub="Retry",qb="Canvas is empty",Kb="Presets",Yb="No",Xb="Saving",Jb={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)"},Zb={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"},Qb="Add",ey="Save",ty="Screen",ny={"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:Bx,"Custom Blocks":"Custom Blocks","UI Library":"UI Library",Import:Rx,"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:Px,Clear:Lx,"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:Mx,Yes:Dx,Preview:Ox,Settings:$x,Styling:Fx,SVG_code:zx,"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:Hx,"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:Vx,"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:Wx,Copy:Gx,Paste:Ux,Delete:qx,"Clear Selection":"Clear Selection","This is dev mode. Visit":"This is dev mode. Visit","to see page preview":"to see page preview",classes:Kx,Theme:Yx,Outline:Xx,"Not supported":"Not supported","Please use Chrome, Firefox or Safari":"Please use Chrome, Firefox or Safari","Download Complete":"Download complete",Copied:Jx,"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:Zx,"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:Qx,"Describe this page. E.g.: This page is about...":"Describe this page. E.g.: This page is about...",Tag:eb,Value:tb,"Background Image":"Background Image","Enter image URL":"Enter image URL","Enter URL":"Enter URL",URL:nb,"Replace image":"Replace image","Choose image":"Choose image",Images:sb,Library:rb,Blocks:ob,Basic:ab,Media:ib,Advanced:lb,Form:cb,"Choose Icon or SVG":"Choose an icon or enter SVG",Groups:db,"UI Libraries":"UI Libraries",Accordions:ub,Buttons:pb,Layouts:fb,"Choose Library":"Choose library","No Library Found":"No library found.",FAQ:hb,Hero:mb,Features:gb,Footer:xb,Navbar:bb,Icons:yb,Testimonials:vb,Blog:kb,"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:wb,Unsaved:Cb,"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:jb,"Randomize all text elements.":"Randomize all text elements.","Edit Block":"Edit Block","AI Assistant":"AI Assistant","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:Sb,All:Nb,"Enter classes separated by space":"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:Eb,Redo:Ab,Duplicate:Ib,"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:Tb,"Coming soon":"Coming soon",Selected:_b,Select:Bb,"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:Rb,"Apply Presets":"Apply Presets",apply:Pb,presets:Lb,"Global presets":"Global presets",Orientation:Mb,Color:Db,"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:Ob,"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:$b,Back:Fb,Insert:zb,Rename:Hb,"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:Vb,Happy:Wb,Sad:Gb,"Importing...":"Importing...","Failed to load the UI library. Try again":"Failed to load the UI library. Try again",Retry:Ub,"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:qb,Presets:Kb,"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:Yb,Saving:Xb,"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:Jb,web_blocks:Zb,"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:Qb,Save:ey,Screen:ty};gt.use(F.initReactI18next).init({resources:{en:{translation:ny}},lng:"en",fallbackLng:"en",interpolation:{escapeValue:!1}});function sy(t,e,n){n.push(d.find(t,{_id:e}));const s=d.filter(t,{_parent:e});for(const r of s)n.push(...kc(r._id,t));return n}const kc=(t,e)=>{let n=[];return n=d.flattenDeep([...n,...sy(e,t,n)]),n},ry=(t,e,n)=>d.compact(t.map(s=>{const r=["_id","_type","_parent"],o=d.pick(s,r),i=X.getRegisteredChaiBlock(s._type),l={},c=d.get(i,"aiProps",[]);for(const u in s)if(!r.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(o,"_parent")&&d.isEmpty(o._parent)&&delete o._parent,{...o,...l})})),oy=(t,e,n)=>!e||n!=="content"?t:`${t}. Generate content in ${d.get(Ot,e,e)} language.`,ay=j.atom(!1),wc=()=>{const[t,e]=j.useAtom(ay),[n,s]=g.useState(null),r=$("askAiCallBack",d.noop),o=Qa(),i=Bd(),[l]=te(),{selectedLang:c,fallbackLang:u}=Te(),p=c.length?c:u,f=(m,h)=>{const x=d.cloneDeep(h.find(b=>b._id===m));for(const b in x){const y=x[b];if(typeof y=="string"&&d.startsWith(y,q.STYLES_KEY)){const{baseClasses:v,classes:w}=be.getSplitChaiClasses(y);x[b]=d.compact(d.flattenDeep([v,w])).join(" ")}else b!=="_id"&&delete x[b]}return x};return{askAi:g.useCallback(async(m,h,x,b)=>{if(r){e(!0),s(null);try{const y=c===u?"":c,v=x.toLowerCase().includes("translate the content"),w=m==="content"?ry(d.cloneDeep(kc(h,l)),c,v):[f(h,l)],N=await r(m,oy(x,p,m),w,y);if(N===void 0)return;const{blocks:E,error:I}=N;if(I){s(I);return}if(m==="styles"){const _=E.map(S=>{for(const A in S)A!=="_id"&&(S[A]=`${q.STYLES_KEY},${S[A]}`);return S});i(_)}else o(E);b&&b(N)}catch(y){s(y)}finally{e(!1),b&&b()}}},[r,e,c,u,l,p,i,o]),loading:t,error:n}};function iy({onClick:t}){const{loading:e}=wc(),{t:n}=F.useTranslation(),{selectedLang:s,fallbackLang:r}=Te(),i=[...[{name:n("Improve writing"),icon:k.Pencil2Icon,prompt:n("Improving writing in all text elements. Replacing placeholder content with meaningful relevant content.")},{name:n("Replace placeholder content"),icon:k.LoopIcon,prompt:n("Discard current placeholder content and replace with meaningful relevant content.")},{name:n("Fix grammar"),icon:k.CheckIcon,prompt:n("Fix grammar in all text elements. Ensuring the text is grammatically correct and free of errors.")},{name:n("Make longer"),icon:k.ArrowUpIcon,prompt:n("Make all text elements longer.")},{name:n("Make shorter"),icon:k.ArrowDownIcon,prompt:n("Make all text elements shorter.")},{name:n("Add emojis"),icon:k.FaceIcon,prompt:n("Add emojis to text elements if relevant.")},{name:n("Randomize"),icon:k.ShuffleIcon,prompt:n("Randomize all text elements.")}]];return s&&s!==r&&i.splice(0,0,{name:n("Translate to {{lang}}",{lang:d.get(Ot,s,s)}),icon:k.ChatBubbleIcon,prompt:n("Translate the content to {{lang}}. Maintain same tone, style and length.",{lang:d.get(Ot,s,s)})}),a.jsx("div",{className:e?"pointer-events-none opacity-50":"",children:a.jsx("ul",{className:"space-y-1",children:i.map(({name:l,icon:c,subMenus:u,prompt:p})=>u?a.jsxs(mo,{children:[a.jsx(go,{asChild:!0,children:a.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:[a.jsx(c,{className:"h-4 w-4"}),a.jsx("span",{children:l})]},l)}),a.jsx(Bs,{side:"right",children:a.jsx("ul",{children:a.jsx("li",{children:n("Happy")})})})]}):a.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:[a.jsx(c,{className:"h-3.5 w-3.5"}),a.jsx("span",{children:n(l)})]},l))})})}const Cc=({blockId:t})=>{const{t:e}=F.useTranslation(),{askAi:n,loading:s,error:r}=wc(),[o,i]=g.useState(""),l=g.useRef(null),c=g.useRef(null),u=J();g.useEffect(()=>{var f;(f=l.current)==null||f.focus()},[]);const p=()=>{r||i("")};return a.jsx("div",{className:"",children:t?a.jsxs("div",{className:"",children:[a.jsx("label",{className:"text-xs font-medium text-gray-500",children:e("Selected block")}),u&&a.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:[a.jsx(Ro,{type:u._type})," ",a.jsx("p",{className:"truncate whitespace-nowrap leading-none",children:u._name||u._type})]}),a.jsx("br",{}),a.jsx("label",{className:"text-xs font-medium text-gray-500",children:e("Quick actions")}),a.jsx("div",{className:"rounded border p-2 text-sm",children:a.jsx(iy,{onClick:f=>{c.current&&clearTimeout(c.current),n("content",t,f,p)}})}),a.jsx("br",{}),a.jsx("label",{className:"text-xs font-medium text-gray-500",children:e("Ask AI")}),a.jsxs("div",{className:"rounded border p-2 text-xs focus-within:border-gray-300",children:[a.jsx($n,{ref:l,value:o,onChange:f=>i(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,o,p))}}),a.jsxs("div",{className:"flex items-center justify-end",children:[s&&a.jsx(B.Button,{variant:"destructive",onClick:()=>stop(),className:"hidden h-4 w-4",size:"icon",children:a.jsx(k.StopIcon,{className:"h-4 w-4"})}),a.jsx(B.Button,{onClick:()=>{c.current&&clearTimeout(c.current),n("content",t,o,p)},variant:"default",className:"h-7 w-7",disabled:s||o.trim().length<1,size:"icon",children:s?a.jsx(k.ReloadIcon,{className:"h-4 w-4 animate-spin"}):a.jsx(k.ArrowTopRightIcon,{className:"h-4 w-4"})})]})]}),a.jsx("div",{className:"max-w-full pt-2",children:r&&a.jsx("p",{className:"break-words rounded border border-red-500 bg-red-100 p-1 text-xs text-red-500",children:r.message})})]}):a.jsx("div",{className:"p-4 text-center",children:a.jsxs("div",{className:"space-y-4 rounded-xl p-4 text-muted-foreground",children:[a.jsx(kr,{className:"mx-auto h-7 w-7 text-muted-foreground"}),a.jsx("h1",{children:e("Please select a block to Ask AI")})]})})})},jc=()=>{const[t]=U();return a.jsx("div",{className:"no-scrollbar mt-2 flex-1 overflow-y-auto",children:a.jsx(Cc,{blockId:d.first(t)})})};function Sc(){const[t,e]=Rn();return a.jsxs("div",{className:"flex items-center",children:[t?a.jsx(k.MoonIcon,{className:"size-4 shrink-0"}):a.jsx(k.SunIcon,{className:"size-4 shrink-0"}),a.jsx(cn,{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:a.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 Nc=()=>{const{hasUndo:t,hasRedo:e,undo:n,redo:s}=Tn();return a.jsxs("div",{className:"flex items-center",children:[a.jsx(B.Button,{disabled:!t(),size:"sm",onClick:n,className:"rounded-full",variant:"ghost",children:a.jsx(k.ResetIcon,{})}),a.jsx(B.Button,{disabled:!e(),onClick:s,size:"sm",className:"rounded-full",variant:"ghost",children:a.jsx(k.ResetIcon,{className:"rotate-180 scale-y-[-1] transform"})})]})},Ec=ie.Root,ly=ie.Trigger,cy=ie.Portal,Ac=D.forwardRef(({className:t,...e},n)=>a.jsx(ie.Overlay,{className:B.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}));Ac.displayName=ie.Overlay.displayName;const dy=vr.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"}}),$o=D.forwardRef(({side:t="right",className:e,children:n,...s},r)=>a.jsxs(cy,{children:[a.jsx(Ac,{}),a.jsxs(ie.Content,{ref:r,className:B.cn(dy({side:t}),e),...s,children:[a.jsxs(ie.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:[a.jsx(k.Cross1Icon,{className:"h-4 w-4"}),a.jsx("span",{className:"sr-only",children:"Close"})]}),n]})]}));$o.displayName=ie.Content.displayName;const Fo=({className:t,...e})=>a.jsx("div",{className:B.cn("flex flex-col space-y-2 text-center sm:text-left",t),...e});Fo.displayName="SheetHeader";const zo=D.forwardRef(({className:t,...e},n)=>a.jsx(ie.Title,{ref:n,className:B.cn("text-lg font-semibold text-foreground",t),...e}));zo.displayName=ie.Title.displayName;const Ic=D.forwardRef(({className:t,...e},n)=>a.jsx(ie.Description,{ref:n,className:B.cn("text-sm text-muted-foreground",t),...e}));Ic.displayName=ie.Description.displayName;const Tc=()=>{const{t}=F.useTranslation(),[e,n]=g.useState(null),[s,r]=g.useState(-1),[o,i]=g.useState(!1),l=Ye(),[,c]=Ns();return Yt(K.OPEN_ADD_BLOCK,u=>{l?c("add-block"):(n(u?u._id:null),r((u==null?void 0:u.position)??-1),i(!0))}),Yt(K.CLOSE_ADD_BLOCK,()=>{n(null),r(-1),i(!1)}),a.jsx(Po,{open:o,onOpenChange:()=>o?i(!1):"",children:a.jsxs(Ds,{className:"max-w-5xl overflow-hidden border-border",children:[a.jsxs(Os,{className:"flex flex-row items-center justify-between",children:[a.jsx($s,{className:"text-foreground",children:t("Add blocks")}),a.jsx("button",{onClick:()=>i(!1),className:"text-gray-500 hover:text-gray-600 dark:text-gray-400 dark:hover:text-gray-300",children:a.jsx(k.Cross2Icon,{className:"h-6 w-6"})})]}),a.jsx("div",{className:"no-scrollbar h-[500px] max-h-full overflow-hidden",children:a.jsx(Bo,{parentId:e??"",position:s,showHeading:!1})})]})})},uy=g.memo(function({preloadedAttributes:e=[],onAttributesChange:n}){const[s,r]=g.useState([]),[o,i]=g.useState(""),[l,c]=g.useState(""),[u,p]=g.useState(null),[f,m]=g.useState(""),h=g.useRef(null),x=g.useRef(null),b=tn(),{t:y}=F.useTranslation();g.useEffect(()=>{r(e)},[e]);const v=()=>{if(o.startsWith("@")){m(y("Attribute keys cannot start with @"));return}if(o){const S=[...s,{key:o,value:l}];n==null||n(S),r(s),i(""),c(""),m("")}},w=S=>{const A=s.filter((C,T)=>T!==S);n==null||n(A),r(A)},N=S=>{p(S),i(s[S].key),c(s[S].value)},E=()=>{if(o.startsWith("@")){m(y("Attribute keys cannot start with @"));return}if(u!==null&&o){const S=[...s];S[u]={key:o,value:l},n==null||n(S),r(S),p(null),i(""),c(""),m("")}},I=S=>{S.key==="Enter"&&!S.shiftKey&&(S.preventDefault(),u!==null?E():v())},_=g.useCallback(S=>{const A=P=>/[.,!?;:]/.test(P),C=(P,R,O)=>{let z="",G="";const de=R>0?P[R-1]:"",ue=R<P.length?P[R]:"";return R>0&&(de==="."||!A(de)&&de!==" ")&&(z=" "),R<P.length&&!A(ue)&&ue!==" "&&(G=" "),{text:z+O+G,prefixLength:z.length,suffixLength:G.length}},T=x.current;if(T){const P=T.selectionStart||0,R=T.value||"",O=T.selectionEnd||P;if(O>P){const ne=`{{${S}}}`,{text:Ae}=C(R,P,ne),Oe=R.slice(0,P)+Ae+R.slice(O);c(Oe);return}const G=`{{${S}}}`,{text:de}=C(R,P,G),ue=R.slice(0,P)+de+R.slice(P);c(ue)}},[]);return a.jsxs("div",{className:"flex max-h-full flex-1 flex-col",children:[a.jsxs("form",{onSubmit:S=>{S.preventDefault(),u!==null?E():v()},className:"space-y-3",children:[a.jsxs("div",{className:"flex flex-col gap-y-1",children:[a.jsxs("div",{className:"w-full",children:[a.jsx(ut,{htmlFor:"attrKey",className:"text-[11px] font-normal leading-tight text-slate-600",children:y("Key")}),a.jsx(B.Input,{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",id:"attrKey",ref:h,value:o,onChange:S=>i(S.target.value),placeholder:y("Enter key"),className:"py-0 text-xs font-normal leading-tight placeholder:text-slate-400"})]}),a.jsxs("div",{className:"w-full",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx(ut,{htmlFor:"attrValue",className:"text-[11px] font-normal text-slate-600",children:y("Value")}),!d.isEmpty(b)&&a.jsx(xo,{data:b,onSelect:_})]}),a.jsx($n,{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",id:"attrValue",ref:x,value:l,onChange:S=>c(S.target.value),onKeyDown:I,placeholder:y("Enter value"),className:"text-xs font-normal leading-tight placeholder:text-slate-400"})]})]}),a.jsx("div",{className:"flex justify-end",children:a.jsx(B.Button,{type:"submit",disabled:!o.length,variant:"default",size:"sm",className:"h-8 w-24 text-xs",children:y(u!==null?"Save":"Add")})}),f&&a.jsx("p",{className:"text-xs text-red-500",children:f})]}),a.jsx("div",{className:"space-y-1 py-4",children:s.map((S,A)=>a.jsxs("div",{className:"flex items-center justify-between rounded border p-2 text-sm",children:[a.jsxs("div",{className:"flex flex-col text-xs leading-tight",children:[a.jsx("span",{className:"truncate text-[12px] font-light text-muted-foreground",children:S.key}),a.jsx("span",{className:"max-w-[200px] text-wrap font-normal",children:S.value.toString()})]}),a.jsxs("div",{className:"flex-shrink-0 text-slate-400",children:[a.jsx(B.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>N(A),children:a.jsx(k.Pencil2Icon,{className:"h-3 w-3"})}),a.jsx(B.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>w(A),children:a.jsx(k.Cross1Icon,{className:"h-3 w-3"})})]})]},A))})]})}),_c=D.memo(()=>{const t=J(),[e,n]=g.useState([]),[s]=Ee(),r=nt(),o=`${d.get(s,"0.prop")}_attrs`;D.useEffect(()=>{const l=d.map(d.get(t,o),(c,u)=>({key:u,value:c}));d.isEmpty(l)?n([]):n(l)},[d.get(t,o)]);const i=D.useCallback((l=[])=>{if(!t)return;const c={};d.forEach(l,u=>{d.isEmpty(u.key)||d.set(c,u.key,u.value)}),r([d.get(t,"_id")],{[o]:c})},[t,r,o]);return a.jsx("div",{className:"flex-col gap-y-2",children:a.jsx("div",{className:"flex flex-col",children:a.jsx("div",{children:a.jsx(uy,{preloadedAttributes:e,onAttributesChange:i})})})})}),py=()=>{const[t]=Tl();return a.jsxs("div",{className:"flex w-12 cursor-not-allowed items-center justify-center gap-x-1 space-x-0 font-medium text-gray-400",children:[a.jsx(k.ZoomInIcon,{className:"h-3.5 w-3.5 flex-shrink-0"})," ",a.jsxs("div",{className:"text-xs leading-3",children:[d.round(t,0),"%"]})]})},fy=()=>{const{hasErrors:t,hasWarnings:e,errorCount:n,warningCount:s,errors:r}=mc(),[,o]=U(),{t:i}=F.useTranslation();if(!t&&!e)return null;const l=()=>t?"text-red-500":e?"text-orange-500":"text-gray-500",c=()=>t?a.jsx(k.ExclamationTriangleIcon,{className:"h-4 w-4"}):e?a.jsx(k.InfoCircledIcon,{className:"h-4 w-4"}):null,u=()=>t&&e?`${n} error${n>1?"s":""}, ${s} warning${s>1?"s":""}`:t?`${n} error${n>1?"s":""}`:e?`${s} warning${s>1?"s":""}`:"";return a.jsxs(et,{children:[a.jsx(tt,{asChild:!0,children:a.jsxs("div",{className:`ml-2 flex cursor-pointer items-center gap-2 ${l()}`,children:[c(),a.jsx("span",{className:"text-xs font-medium",children:u()})]})}),a.jsx(Ge,{side:"bottom",className:"max-w-xs p-2",align:"end",children:a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-semibold",children:i("Invalid structure")}),r.length===0?a.jsx("p",{className:"text-xs",children:i("No validation issues found.")}):a.jsxs("div",{className:"space-y-1",children:[r.slice(0,5).map(p=>a.jsxs("div",{onClick:()=>{p.blockId&&o([p.blockId])},className:`cursor-pointer rounded p-2 text-xs transition-opacity hover:opacity-80 ${p.severity==="error"?"border border-red-200 bg-red-50 text-red-700":"border border-orange-200 bg-orange-50 text-orange-700"}`,children:[a.jsx("div",{className:"font-medium",children:p.severity==="error"?"Error:":"Warning:"}),a.jsx("div",{children:p.message})]},p.id)),r.length>5&&a.jsxs("p",{className:"text-xs italic text-gray-500",children:["... and ",r.length-5," more issues"]})]})]})})]})},hy=()=>{const t=$("flags.darkMode",!0),e=$("flags.dataBinding",!0),[n,s]=j.useAtom(Vr),{t:r}=F.useTranslation(),o=t,i=e;return a.jsxs("div",{className:"flex h-10 items-center justify-between border-b border-border bg-background/70 px-2 shadow-xl",children:[a.jsx("div",{className:"flex h-full space-x-2",children:o?a.jsx(Sc,{}):null}),a.jsxs("div",{className:"flex h-full items-center space-x-2",children:[a.jsx(So,{canvas:!0,openDelay:400}),a.jsx(Rt,{orientation:"vertical"}),a.jsx(py,{}),a.jsx(Rt,{orientation:"vertical"}),a.jsx(Nc,{})]}),a.jsxs("div",{className:"flex h-full items-center",children:[i?a.jsxs(et,{children:[a.jsx(tt,{asChild:!0,children:a.jsx(B.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 rounded-md p-1",children:a.jsx(k.DotsHorizontalIcon,{className:"h-4 w-4"})})}),a.jsx(Ge,{className:"w-56 border-border text-xs",children:a.jsxs(le,{className:"flex items-center gap-2",onSelect:l=>l.preventDefault(),children:[a.jsx(k.LightningBoltIcon,{className:"h-4 w-4 text-gray-500"}),a.jsx("span",{className:"flex-1",children:r("Data Binding")}),a.jsx(cn,{checked:n,onCheckedChange:()=>s(!n)})]})})]}):null,a.jsx(fy,{}),a.jsx(fc,{})]})]})},Gt=()=>null,_a=()=>{const{resetAll:t}=zl(),e=J(),[n]=Ee(),s=Xm(),{t:r}=F.useTranslation();return!e||d.isEmpty(n)?null:a.jsxs(et,{children:[a.jsx(tt,{asChild:!0,children:a.jsx("div",{className:"inline-flex rounded-sm p-0.5 hover:bg-gray-300",onClick:o=>o.stopPropagation(),children:a.jsx(k.DotsVerticalIcon,{className:"h-3 w-3"})})}),a.jsxs(Ge,{side:"bottom",className:"border-border text-xs",children:[a.jsxs(le,{className:"flex items-center gap-1 text-xs",onClick:()=>{t()},children:[a.jsx(k.ResetIcon,{className:"h-3 w-3"}),r("Reset styles")]}),a.jsxs(le,{className:"text-xs",onClick:()=>{e&&s(e,!0)},children:[a.jsx(k.Cross2Icon,{className:"h-3 w-3"}),r("Clear styles")]})]})]})};function Ba(){const{t}=F.useTranslation(),[e,n]=g.useState(!0),[s]=Ee();return d.isEmpty(s)?null:a.jsxs(a.Fragment,{children:[a.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:[a.jsx("span",{children:t("Attributes")}),a.jsx("span",{children:a.jsx(k.ChevronDownIcon,{className:"h-4 w-4 text-gray-500 "+(e?"rotate-180":"")})})]}),e&&a.jsx(_c,{})]})}const my=({partialBlockId:t})=>{const e=$("gotoPage",d.noop),{saveState:n}=nn(),{selectedLang:s,fallbackLang:r}=Te(),o=g.useCallback(i=>{if(i.stopPropagation(),n!=="SAVED"){pe.toast.error("You have unsaved changes. Please save the page first.");return}e({pageId:t,lang:s||r})},[n,e,t,s,r]);return a.jsx(a.Fragment,{children:a.jsx("div",{className:"hidden",children:a.jsx("div",{onDoubleClick:o,className:"h-full w-full items-center justify-center",children:a.jsx("p",{className:"rounded-md bg-white px-2 py-1 text-xs",children:"Partial block. Double click to edit."})})})})},gy=()=>{const t=J(),{t:e}=F.useTranslation(),n=$("onError",d.noop),{hasPermission:s}=qe();let r=!s(se.EDIT_BLOCK);const o=!s(se.EDIT_STYLES),[i,l]=ri();if(t&&t._type==="PartialBlock")return a.jsx(my,{partialBlockId:t.partialBlockId});if(d.isNull(t))return a.jsx("div",{className:"p-4 text-center",children:a.jsxs("div",{className:"space-y-4 rounded-xl p-4 text-muted-foreground",children:[a.jsx(k.MixerHorizontalIcon,{className:"mx-auto text-3xl"}),a.jsx("h1",{children:e("Please select a block to edit settings or styles")})]})});if(r&&o)return a.jsx("div",{className:"p-4 text-center",children:a.jsxs("div",{className:"space-y-4 rounded-xl p-4 text-muted-foreground",children:[a.jsx(k.MixerHorizontalIcon,{className:"mx-auto text-3xl"}),a.jsx("h1",{children:e("You don't have permission to edit settings or styles")}),a.jsx("p",{children:e("Please contact your administrator to get access")})]})});if(o)return a.jsx(At.ErrorBoundary,{fallback:a.jsx(yn,{}),onError:n,children:a.jsxs("div",{className:"no-scrollbar h-full max-h-min w-full overflow-y-auto",children:[a.jsx(fr,{},t==null?void 0:t._id),a.jsx("br",{}),a.jsx("br",{})]})});if(r)return a.jsx(At.ErrorBoundary,{fallback:a.jsx(yn,{}),onError:n,children:a.jsxs("div",{className:"no-scrollbar h-full max-h-min w-full overflow-y-auto overflow-x-hidden",children:[a.jsx("div",{className:"flex w-full items-center justify-end",children:a.jsx(_a,{})}),a.jsx(yr,{}),a.jsx(Ba,{}),a.jsx("br",{}),a.jsx("br",{}),a.jsx("br",{})]})});const u=p=>{(p==="settings"||p==="styles")&&l(p)};return a.jsx(At.ErrorBoundary,{fallback:a.jsx(yn,{}),onError:n,children:a.jsxs(Ls,{value:i,onValueChange:u,className:"flex flex-1 flex-col",children:[a.jsx("div",{className:"flex items-center justify-between",children:a.jsxs(On,{className:"grid h-auto w-full grid-cols-2 p-1 py-1",children:[a.jsx(He,{value:"settings",className:"text-xs",children:e("Settings")}),a.jsx(He,{value:"styles",className:"text-xs",children:a.jsxs("div",{className:"flex w-full items-center justify-between",children:[a.jsx("span",{className:"w-[90%] text-center",children:e("Styling")}),a.jsx("span",{className:"w-[10%]",children:a.jsx(_a,{})})]})})]})}),a.jsxs(ct,{value:"settings",className:"no-scrollbar h-full max-h-min overflow-y-auto",children:[a.jsx(fr,{},t==null?void 0:t._id),a.jsx("br",{}),a.jsx("br",{})]}),a.jsxs(ct,{value:"styles",className:"no-scrollbar h-full max-h-min max-w-full overflow-y-auto overflow-x-hidden",children:[a.jsx(yr,{}),a.jsx(Ba,{}),a.jsx("br",{}),a.jsx("br",{}),a.jsx("br",{})]})]})})},xy=g.lazy(()=>Promise.resolve().then(()=>require("./manage-design-tokens-Hu25ejcC.cjs"))),mt=280,by=({isActive:t,show:e})=>a.jsx(B.Button,{variant:t?"default":"ghost",size:"icon",onClick:e,children:a.jsx(k.StackIcon,{className:"h-5 w-5"})}),yy=({isActive:t,show:e})=>Ye()&&a.jsx(B.Button,{variant:t?"default":"ghost",size:"icon",onClick:e,children:a.jsx(k.PlusCircledIcon,{className:"h-5 w-5"})}),vy=({isActive:t,show:e})=>$("flags.ai",!1)?a.jsx(B.Button,{variant:t?"default":"ghost",size:"icon",onClick:e,children:a.jsx(kr,{})}):null;B.registerChaiSidebarPanel("add-block",{button:yy,label:"Add Blocks",position:"top",isInternal:!0,width:mt,panel:()=>a.jsx(Bo,{showHeading:!1,fromSidebar:!0,parentId:void 0,position:-1})});B.registerChaiSidebarPanel("chai-chat-panel",{button:vy,label:"Ask AI",position:"top",isInternal:!0,width:mt,panel:()=>a.jsx("div",{className:"",children:a.jsx(jc,{})})});B.registerChaiSidebarPanel("outline",{button:by,label:"Outline",position:"top",isInternal:!0,width:mt,panel:()=>a.jsx("div",{className:"-mt-8",children:a.jsx(xc,{})})});const ky=()=>{const t=B.useTopBarComponent(),[e,n]=Ns(),s=g.useRef("outline"),[r,o]=g.useState(mt),[i,l]=Mr(),[,c]=ri(),u=B.useChaiSidebarPanels("top"),p=B.useChaiSidebarPanels("bottom"),f=d.reverse([...p??[]]),m=g.useCallback(A=>{A.preventDefault()},[]),h=g.useMemo(()=>[u].flat(),[u]),x=g.useCallback(A=>{console.log("handleMenuItemClick",A,e),n(e===A?null:A)},[e,n]),{t:b}=F.useTranslation(),y=g.useMemo(()=>[...u,...p],[u,p]),v=$("htmlDir","ltr"),w=d.find(y,{id:e})??d.first(y),N=d.get(w,"width",mt);g.useEffect(()=>{if(e!==null){const A=d.find(y,{id:e});A&&d.get(A,"view","standard")==="standard"&&(s.current=e,o(d.get(A,"width",mt)))}},[e,y]);const E=g.useMemo(()=>{if(e===null)return 0;const A=d.find(y,{id:e});return d.get(A,"view","standard")==="standard"?N:r},[e,N,r,y]),I=g.useCallback(()=>{n(s.current)},[n,e]),_=g.useCallback(()=>{n("outline")},[n]);g.useEffect(()=>{e!==null&&!d.find(y,{id:e})&&n("outline")},[e,y]);const S=g.useCallback(A=>{x(A)},[x]);return a.jsx("div",{dir:v,className:"h-screen max-h-full w-screen overflow-x-hidden bg-background text-foreground",children:a.jsxs(ms,{children:[a.jsxs("div",{onContextMenu:m,className:"flex h-full max-h-full flex-col bg-background text-foreground",children:[a.jsx("div",{className:"flex h-[50px] w-screen items-center border-b border-border",children:a.jsx(g.Suspense,{children:a.jsx(t,{})})}),a.jsxs("main",{className:"relative flex h-[calc(100vh-56px)] max-w-full flex-1 flex-row",children:[a.jsxs("div",{id:"sidebar",className:"flex w-12 flex-col items-center justify-between border-r border-border py-2",children:[a.jsx("div",{className:"flex flex-col gap-y-1",children:h.map((A,C)=>a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:g.createElement(d.get(A,"button",Gt),{position:"top",panelId:A.id,isActive:e===A.id,show:()=>S(A.id)})}),a.jsx(ce,{side:"right",children:a.jsx("p",{children:b(A.label)})})]},"button-top-"+C))}),a.jsx("div",{className:"flex flex-col space-y-1"}),a.jsx("div",{className:"flex flex-col",children:f==null?void 0:f.map((A,C)=>a.jsxs(fe,{children:[a.jsx(he,{asChild:!0,children:g.createElement(d.get(A,"button",Gt),{position:"bottom",panelId:A.id,isActive:e===A.id,show:()=>S(A.id)})}),a.jsx(ce,{side:"right",children:a.jsx("p",{children:b(A.label)})})]},"button-bottom-"+C))})]}),a.jsx(Vn.motion.div,{id:"left-panel",className:"h-full max-h-full border-r border-border",initial:{width:E},animate:{width:E},transition:{duration:.3,ease:"easeInOut"},children:e!==null&&d.get(w,"view","standard")==="standard"&&a.jsxs("div",{className:"no-scrollbar flex h-full flex-col overflow-hidden px-3 py-2",children:[a.jsx("div",{className:`absolute top-2 flex h-10 items-center space-x-1 py-2 text-base font-bold ${d.get(w,"isInternal",!1)?"":"w-64"}`,children:a.jsx("span",{children:b(d.get(w,"label",""))})}),a.jsx("div",{className:"no-scrollbar h-full max-h-full overflow-y-auto pt-10",children:a.jsx(g.Suspense,{fallback:a.jsx("div",{children:"Loading..."}),children:g.createElement(d.get(w,"panel",Gt),{})})})]})}),a.jsxs("div",{id:"canvas-container",className:"flex h-full max-h-full flex-1 flex-col bg-slate-800/20",children:[a.jsx(hy,{}),a.jsx(g.Suspense,{children:a.jsx(Rl,{})})]}),a.jsx(Vn.motion.div,{id:"right-panel",className:"h-full max-h-full border-l border-border",initial:{width:e==="ai"?0:mt},animate:{width:e==="ai"?0:mt},transition:{duration:.3,ease:"easeInOut"},children:a.jsx("div",{className:"no-scrollbar overflow h-full max-h-full overflow-hidden",children:a.jsxs("div",{className:"flex h-full max-h-full flex-col overflow-hidden p-3",children:[a.jsx("h2",{className:"-mt-1 flex items-center space-x-1 text-base font-bold",children:a.jsx("div",{className:"flex grow items-center gap-2",children:a.jsx("div",{className:"flex w-full items-center justify-between gap-2",children:i==="ai"?a.jsx(a.Fragment,{children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(k.LightningBoltIcon,{className:"rtl:ml-2"})," ",b("AI Assistant")]})}):i==="design-tokens"?a.jsxs("div",{className:"mb-1 flex w-full items-center justify-between gap-2",children:[a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(br,{className:"h-4 w-4 text-gray-600"}),b("Design Tokens")]}),a.jsx(B.Button,{onClick:()=>{c("styles"),l("block")},variant:"ghost",size:"icon",className:"text-xs",children:a.jsx(k.Cross1Icon,{className:"h-4 w-4 rtl:ml-2"})})]}):i==="theme"?a.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(k.MixerHorizontalIcon,{className:"h-4 w-4 text-gray-600"}),b("Theme Settings")]}),a.jsx(B.Button,{onClick:()=>l("block"),variant:"ghost",size:"icon",className:"text-xs",children:a.jsx(k.Cross1Icon,{className:"h-4 w-4 rtl:ml-2"})})]}):null})})}),a.jsx("div",{className:"flex h-full max-h-full w-full",children:a.jsx(g.Suspense,{fallback:a.jsx("div",{children:"Loading..."}),children:i==="ai"?a.jsx(jc,{}):i==="design-tokens"?a.jsx(g.Suspense,{fallback:a.jsx("div",{className:"h-1/2 w-full animate-pulse"}),children:a.jsx(xy,{})}):i==="theme"?a.jsx(vc,{}):a.jsx(gy,{})})})]})})})]})]}),a.jsx(Tc,{}),e!==null&&d.get(w,"view")==="drawer"&&a.jsx(Ec,{open:!0,onOpenChange:()=>I(),children:a.jsxs($o,{side:"left",className:"flex flex-col gap-0 p-0 sm:max-w-full",style:{width:`${N}px`},children:[a.jsx(Fo,{className:"border-b border-border px-2 py-2.5",children:a.jsxs(zo,{className:"flex items-center gap-2",children:[a.jsx("span",{className:"inline-block",children:d.get(w,"icon",null)}),a.jsx("span",{children:b(d.get(w,"label",""))})]})}),a.jsx("div",{className:"h-full max-h-full overflow-y-auto p-4",children:a.jsx(g.Suspense,{fallback:a.jsx("div",{children:"Loading..."}),children:g.createElement(d.get(w,"panel",Gt),{close:_})})})]})})," ",e!==null&&d.get(w,"view")==="modal"&&a.jsx(Pn,{open:!0,onOpenChange:()=>I(),children:a.jsxs(an,{className:"gap-0 p-0",style:{maxWidth:`${N}px`},children:[a.jsx(Ln,{className:"border-b border-border px-2 py-3.5",children:a.jsxs(ln,{className:"flex items-center gap-2",children:[a.jsx("span",{className:"inline-block",children:d.get(w,"icon",null)}),a.jsx("span",{children:b(d.get(w,"label",""))})]})}),a.jsx("div",{className:"max-h-[70vh] overflow-y-auto p-4",children:a.jsx(g.Suspense,{fallback:a.jsx("div",{children:"Loading..."}),children:g.createElement(d.get(w,"panel",Gt),{close:_})})})]})}),e!==null&&d.get(w,"view")==="overlay"&&a.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:a.jsx("div",{className:"h-full w-full",children:a.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:[a.jsxs("div",{className:"flex h-[50px] items-center justify-between border-b border-border p-4",children:[a.jsxs("div",{className:"-ml-2 flex items-center gap-2 text-lg font-bold",children:[a.jsx("span",{className:"rtl:ml-2 rtl:inline-block",children:d.get(w,"icon",null)}),a.jsx("span",{children:b(d.get(w,"label",""))})]}),a.jsx(B.Button,{onClick:()=>I(),variant:"ghost",size:"icon",className:"",children:a.jsx(k.Cross1Icon,{className:"h-5 w-5"})})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:a.jsx(g.Suspense,{fallback:a.jsx("div",{children:"Loading..."}),children:g.createElement(d.get(w,"panel",Gt),{close:_})})})]})})})]})})},wy=j.atom(!1),Cy=()=>{const[t,e]=j.useAtom(wy);return[t,e]},jy=()=>{const[t,e]=Cy(),{t:n}=F.useTranslation(),s=$("previewComponent",null);return t?a.jsxs("div",{className:ve.cn("fixed inset-0 z-[999] bg-background",t?"block":"hidden"),children:[a.jsxs(B.Button,{size:"sm",className:"absolute right-0 top-0 m-4 space-x-2",onClick:()=>e(!1),children:[a.jsx(k.EyeClosedIcon,{}),a.jsx("span",{children:n("Close Preview")})]}),a.jsx("div",{children:s?a.jsx(g.Suspense,{fallback:a.jsx(Lt,{className:"h-96 w-full"}),children:g.createElement(s)}):null})]}):null},Sy=({featureKey:t,options:e})=>{const n=B.useToggleChaiFeatureFlag(t),s=B.useChaiFeatureFlag(t);return a.jsxs("div",{className:"flex items-center space-x-3 rounded-md p-2 transition-colors hover:bg-gray-50 dark:hover:bg-gray-800",children:[a.jsx(cn,{checked:s,onCheckedChange:n}),a.jsxs("div",{className:"flex-1",children:[a.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:e.key}),e.description&&a.jsx("p",{className:"mt-0.5 text-xs text-gray-500 dark:text-gray-400",children:e.description})]})]})},Ny=Se.atomWithStorage("show-feature-flag",null),Ey=({close:t,position:e,updatePosition:n})=>{const s=B.useChaiFeatureFlags(),[r,o]=g.useState(""),[i,l]=g.useState(!1),[c,u]=g.useState({x:0,y:0}),p=g.useMemo(()=>{if(!r.trim())return s;const x=r.toLowerCase();return Object.fromEntries(Object.entries(s).filter(([b,y])=>{var v;return(b==null?void 0:b.toLowerCase().includes(x))||((v=y==null?void 0:y.description)==null?void 0:v.toLowerCase().includes(x))}))},[s,r]),f=x=>{l(!0),u({x:x.clientX-e.x,y:x.clientY-e.y})},m=x=>{if(!i)return;const b=x.clientX-c.x,y=x.clientY-c.y,v=x.currentTarget,w=v.offsetWidth,N=v.offsetHeight,E=window.innerWidth-w,I=window.innerHeight-N,_=Math.max(0,Math.min(b,E)),S=Math.max(0,Math.min(y,I));n(_,S)},h=()=>{l(!1)};return g.useEffect(()=>{const x=()=>{i&&l(!1)};return window.addEventListener("mouseup",x),()=>window.removeEventListener("mouseup",x)},[i]),!e||e.x<0||e.y<0?null:a.jsxs("div",{onMouseDown:f,onMouseMove:m,onMouseUp:h,className:"fixed z-[9999999] select-none rounded-md border border-gray-300 bg-white p-3 shadow-2xl",style:{left:e.x,top:e.y,cursor:i?"grabbing":"grab",userSelect:"none"},children:[a.jsxs("div",{className:"relative sticky top-0 rounded-t-lg bg-white",children:[a.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsxs("h3",{className:"flex items-center gap-x-2 text-base font-semibold text-gray-900 dark:text-gray-100",children:[a.jsx(k.DragHandleDots2Icon,{})," Feature Flags"]}),a.jsxs("p",{className:"text-xs text-gray-400 dark:text-gray-400",children:["Toggle experimental features (",a.jsx("span",{className:"font-mono",children:"Ctrl+Shift+1"})," to toggle)"]})]}),a.jsx(B.Button,{variant:"ghost",size:"sm",onClick:t,className:"absolute -right-2 -top-2 p-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200",children:a.jsx(k.Cross1Icon,{className:"h-4 w-4"})})]}),a.jsxs("div",{className:"relative",children:[a.jsx(k.MagnifyingGlassIcon,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"}),a.jsx(B.Input,{type:"search",placeholder:"Search features...",className:"w-full pl-8",value:r,onChange:x=>o(x.target.value),autoFocus:!0})]})]}),a.jsx("div",{className:"max-h-96 overflow-y-auto py-2",children:Object.keys(p).length>0?a.jsx("div",{className:"space-y-1",children:Object.entries(p).map(([x,b])=>a.jsx(Sy,{featureKey:x,options:b},x))}):a.jsx("div",{className:"py-8 text-center",children:a.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:['No features found matching "',r,'"']})})})]})},Ay=()=>{const[t,e]=j.useAtom(Ny);return Xe.useHotkeys("ctrl+shift+1,meta+shift+1",()=>e(n=>n?{...n,show:!n.show}:{x:0,y:0,show:!0}),{enableOnFormTags:!0}),t!=null&&t.show?a.jsx(Ey,{position:t,close:()=>e(n=>n?{...n,show:!1}:null),updatePosition:(n,s)=>e(r=>r?{...r,x:n,y:s,show:r.show}:{x:n,y:s,show:!0})}):null},Iy=t=>{},Ty=["data-block-index","draggable","data-drop","data-style-id","data-block-parent","data-style-prop","data-highlighted"],_y=["Box","Button","Checkbox","Divider","EmptyBox","Form","FormButton","Heading","Image","Input","Label","LineBreak","Link","List","ListItem","Paragraph","Radio","RichText","Select","Span","Text","TextArea","Video"],Bc=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=>!Ty.includes(e.key))),t.children&&(t.children=t.children.map(Bc).filter(e=>e!==null)),t),es=(t,e,n={})=>{var o,i,l,c,u,p;if(t.type!=="element"||!t.attributes)return t;if(t.tagName==="span"&&t.attributes.find(m=>m.key==="role"&&m.value==="link")){t.tagName="a",t.attributes=t.attributes.filter(x=>x.key!=="role");const m=(o=t.attributes.find(x=>x.key==="data-block-id"))==null?void 0:o.value,h=e==null?void 0:e.find(x=>(x==null?void 0:x._id)===m);if(h!=null&&h.link&&((l=(i=h==null?void 0:h.link)==null?void 0:i.href)==null?void 0:l.length)>0){const x=(c=h==null?void 0:h.link)==null?void 0:c.href,b=(u=h==null?void 0:h.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"),r=t.attributes.find(f=>f.key==="data-block-id");if(s){const f=s.value;if(_y.includes(f)||(p=n==null?void 0:n.additionalCoreBlocks)!=null&&p.includes(f))t.attributes=t.attributes.filter(m=>m.key!=="data-block-type"),t.children&&(t.children=t.children.map(m=>es(m,e,n)));else{const m=`chai-${d.kebabCase(f)}`;t.tagName=m,t.attributes=[],t.attributes.push({key:"chai-type",value:f});const h=X.getRegisteredChaiBlock(f),x=e.find(b=>b._id===(r==null?void 0:r.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)}))),h&&(h!=null&&h.description)&&t.attributes.push({key:"about-this-component",value:h.description}),h){if(h.canMove){const b=typeof h.canMove=="function"?h.canMove():h.canMove;t.attributes.push({key:"can-move",value:String(b)})}if(h.canDelete){const b=typeof h.canDelete=="function"?h.canDelete():h.canDelete;t.attributes.push({key:"can-delete",value:String(b)})}}f==="Icon"&&(t.attributes=t.attributes.filter(b=>b.key!=="icon")),h&&h.canAcceptBlock?t.children&&(t.children=t.children.map(b=>es(b,e,n))):t.children=[]}}else t.children&&(t.children=t.children.map(f=>es(f,e,n)));return r&&t.attributes.push({key:"bid",value:r.value}),t.attributes=t.attributes.filter(f=>f.key!=="data-block-type"&&f.key!=="data-block-id"),t},Rc=()=>{const[t]=sn();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 o=Vo.parse(s).map(Bc).filter(f=>f!==null),i=Nd(),l=o.map(f=>es(f,i,e));let c=Vo.stringify(l);return c=c.replace(/#styles:,/g,"#styles:"),c.replace(/\s+/g," ").trim()},[t])};function Ra(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 ts(t,e=0){var u;if(Array.isArray(t)){if(t.length===0)return"";if(t.length===1)return ts(t[0],e);const p=" ".repeat(e);let f=`${p}<>
|
|
136
136
|
`;for(const m of t)f+=ts(m,e+1);return f+=`${p}</>
|
|
137
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 m of t.attributes)if(m.name.startsWith("on")&&m.name!=="on"){const h=m.name.toLowerCase().replace(/on(\w)/,(x,b)=>"on"+b.toUpperCase());p.push(`${h}={${m.value}}`)}else if(m.name==="style"&&m.value){const h=m.value.split(";").reduce((x,b)=>{const[y,
|
|
139
|
-
`}let o=`${n}<${s}`;const i=[];for(const p of t.attributes)if(p.name.startsWith("on")&&p.name!=="on"){const f=p.name.toLowerCase().replace(/on(\w)/,(m,h)=>"on"+h.toUpperCase());i.push(`${f}={${p.value}}`)}else if(p.name==="style"&&p.value){const f=p.value.split(";").reduce((m,h)=>{const[x,b]=h.split(":").map(y=>y.trim());if(x&&b){const y=x.replace(/-([a-z])/g,
|
|
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 m of t.attributes)if(m.name.startsWith("on")&&m.name!=="on"){const h=m.name.toLowerCase().replace(/on(\w)/,(x,b)=>"on"+b.toUpperCase());p.push(`${h}={${m.value}}`)}else if(m.name==="style"&&m.value){const h=m.value.split(";").reduce((x,b)=>{const[y,v]=b.split(":").map(w=>w.trim());if(y&&v){const w=y.replace(/-([a-z])/g,N=>N[1].toUpperCase());x[w]=v.replace(/['"]/g,"")}return x},{});p.push(`style={${JSON.stringify(h)}}`)}else{const h=Ra(m.name);p.push(`${h}="${m.value}"`)}const f=p.length>0?` ${p.join(" ")}`:"";return`${n}<${s}${f} />
|
|
139
|
+
`}let o=`${n}<${s}`;const i=[];for(const p of t.attributes)if(p.name.startsWith("on")&&p.name!=="on"){const f=p.name.toLowerCase().replace(/on(\w)/,(m,h)=>"on"+h.toUpperCase());i.push(`${f}={${p.value}}`)}else if(p.name==="style"&&p.value){const f=p.value.split(";").reduce((m,h)=>{const[x,b]=h.split(":").map(y=>y.trim());if(x&&b){const y=x.replace(/-([a-z])/g,v=>v[1].toUpperCase());m[y]=b.replace(/['"]/g,"")}return m},{});i.push(`style={${JSON.stringify(f)}}`)}else{const f=Ra(p.name);i.push(`${f}="${p.value}"`)}i.length>0&&(o+=" "+i.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}))o+=` />
|
|
140
140
|
`;else{o+=`>
|
|
141
141
|
`;for(const p of l)o+=ts(p,e+1);o+=`${n}</${s}>
|
|
142
142
|
`}return o}function By(t){if(!t)return"";let e="",n=0;const s=" ";return t=t.replace(/>\s+</g,"><").trim(),t.split(/(<\/?[^>]+>)/g).filter(o=>o.trim()).forEach(o=>{o.match(/^<\/\w/)?(n=Math.max(0,n-1),e+=s.repeat(n)+o+`
|
|
@@ -151,10 +151,10 @@ ${r}${r}`),o=`${n?`import React from 'react';
|
|
|
151
151
|
${r}return (
|
|
152
152
|
${r}${r}${o==null?void 0:o.trimEnd()}
|
|
153
153
|
${r})
|
|
154
|
-
}`,{jsx:o,html:By(i),componentName:s}},My=({tab:t})=>{var
|
|
154
|
+
}`,{jsx:o,html:By(i),componentName:s}},My=({tab:t})=>{var v;const{t:e}=F.useTranslation(),[n,s]=g.useState({html:"",jsx:""}),r=J(),o=Rc(),[i,l]=g.useState(""),[c,u]=g.useState(!1),p=()=>{switch(t){case"js":return`${i}.jsx`;case"ts":return`${i}.tsx`;case"html":return`${i}.html`;case"tailwind":return"tailwind.config.js"}},f=()=>{switch(t){case"js":case"ts":return"javascript";case"html":return"HTML";case"tailwind":return"JSON"}},m=g.useCallback(async()=>{if(r)try{u(!1);let w=o({blockId:r==null?void 0:r._id,additionalCoreBlocks:["Icon"]});w=w.replace(/\s*bid=["'][^"']*["']/g,"");const N=t==="ts",{jsx:E,html:I,componentName:_}=await Ly({selectedBlock:r,html:w,isTypeScript:N});s({html:I||"",jsx:E}),l(_),u(!0)}catch{const w="<div>Export failed. Close the modal and try again.</div>";s({html:w,jsx:w}),pe.toast.error(e("Failed to generate export HTML"))}},[e,t,r,o]);g.useEffect(()=>{m()},[m,t]);const h=g.useCallback(async w=>{try{navigator.clipboard.writeText(w),pe.toast.success(e("Export code copied!"))}catch{pe.toast.error(e("Failed to copy export code"))}},[e]),x=w=>{const N=new Blob([w],{type:"text/jsx"}),E=URL.createObjectURL(N),I=document.createElement("a");I.href=E,I.download=p()??"",document.body.appendChild(I),I.click(),URL.revokeObjectURL(E),document.body.removeChild(I),pe.toast.success(e("Export code downloaded successfully!"))},b=a.jsxs("span",{children:["Download ",a.jsx("span",{className:"font-mono text-xs font-light text-gray-300",children:p()})]}),y=g.useMemo(()=>{const w={extend:gd.shadcnTheme()},N=JSON.stringify(w,null,2);return`{
|
|
155
155
|
// Your tailwind config ...
|
|
156
156
|
|
|
157
|
-
"theme": ${
|
|
157
|
+
"theme": ${N==null?void 0:N.split(`
|
|
158
158
|
`).join(`
|
|
159
159
|
`)},
|
|
160
|
-
}`},[]);return((
|
|
160
|
+
}`},[]);return((v=n==null?void 0:n.jsx)==null?void 0:v.length)>0&&c?a.jsx(Ry,{onCopy:h,code:t==="tailwind"?y:t==="html"?n.html:n.jsx,language:f()||"",downloadText:b,onDownload:x},t):a.jsx("div",{className:"flex h-[620px] w-full items-center justify-center p-4",children:"Generating code..."})},Pc=()=>{const{t}=F.useTranslation(),[e,n]=g.useState(!1),{setMode:s}=Ri(),[r,o]=g.useState("js"),i=g.useCallback(async()=>{o("js"),s("view"),n(!0)},[o,s,n]);Yt(K.OPEN_EXPORT_CODE,i);const l=async()=>{s("edit"),await new Promise(c=>setTimeout(c,300)),n(!1)};return a.jsx(Pn,{open:e,onOpenChange:l,children:a.jsxs(an,{className:"max-w-5xl overflow-hidden border-border",children:[a.jsxs(Ln,{className:"flex flex-row items-center justify-between",children:[a.jsx(ln,{className:"text-foreground",children:t("Export Code")}),a.jsx(Ls,{defaultValue:"js",onValueChange:o,children:a.jsxs(On,{children:[a.jsx(He,{value:"js",children:"Javascript"}),a.jsx(He,{value:"ts",children:"Typescript"}),a.jsx(He,{value:"html",children:"HTML"}),a.jsx(He,{value:"tailwind",children:"Tailwind config"})]})}),a.jsx("div",{})]}),a.jsx("div",{className:"flex min-h-[400px] flex-col gap-4",children:e&&a.jsx(g.Suspense,{fallback:a.jsx("div",{className:"flex h-[400px] items-center justify-center text-muted-foreground",children:"Loading code editor..."}),children:a.jsx(At.ErrorBoundary,{fallback:a.jsx("div",{children:"Something went wrong"}),children:a.jsx(My,{tab:r})})})})]})})},Dy=()=>{const t=$("smallScreenComponent",null);return a.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):a.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:a.jsx("div",{className:"mx-auto max-w-7xl px-4 sm:px-6 lg:px-8",children:a.jsxs("div",{className:"mx-auto max-w-md space-y-6 text-center",children:[a.jsx("img",{src:"https://ucarecdn.com/fbfc3b05-cb73-4e99-92a2-3a367b7c36cd/",alt:"Chai Builder",className:"mx-auto h-20 w-20 rounded-full shadow-lg transition-transform duration-300 hover:scale-105"}),a.jsxs("div",{className:"space-y-4",children:[a.jsx("h2",{className:"text-5xl font-bold tracking-tight text-gray-900",children:"Screen too small"}),a.jsxs("p",{className:"mx-auto max-w-sm text-sm leading-7 text-gray-600",children:["Please view this page on greater than ",a.jsx("strong",{className:"font-medium",children:"1280px"})," screen width for the best experience."]})]}),a.jsx("div",{className:"pt-4",children:a.jsxs("div",{className:"inline-flex items-center rounded-full bg-gray-100 px-4 py-2 text-sm text-gray-700",children:[a.jsx("svg",{className:"mr-2 h-5 w-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.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"]})})]})})})})},Oy=()=>{const{clear:t}=Tn(),[,e]=U(),{clearHighlight:n}=st(),[,s]=Ee(),[,r]=j.useAtom(li),{reset:o}=As(),{setSaveState:i}=nn(),[,l]=ei(),[,c]=j.useAtom(ks);return()=>{l({}),e([]),s([]),n(),t(),r(!1),o(),i("SAVED"),c(0)}},$y=(t,e)=>{const n=[];let s=d.find(t,{_id:e}),r=d.get(s,"_parent","");for(;d.isString(r)&&!d.isEmpty(r);)n.push(s==null?void 0:s._parent),s=d.find(t,{_id:r}),r=s==null?void 0:s._parent;return d.flatten(n)},Fy=j.atom([]),zy=()=>{const[t]=U(),e=j.useAtomValue(je),[,n]=j.useAtom(Fy);g.useEffect(()=>{let s=[];const r=d.first(t);d.isString(r)&&(s=[r,...$y(e,r)]),n(s)},[t,e,n])},Hy=t=>{const[,e]=te(),n=Oy(),[s]=j.useAtom(ws);j.useAtom(Hr),Ti(),zy(),eu(),xp(),lu();const{postMessage:r}=oi(),[,o]=j.useAtom(ni),i=Lr();return g.useEffect(()=>{Ve.set(Rr,d.omit(t,["blocks","translations","pageExternalData","globalStyles"]))},[t]),g.useEffect(()=>{Ve.set(Pr,t.pageExternalData||{})},[t.pageExternalData]),g.useEffect(()=>{Ve.set(en,t.designTokens||{})},[t.designTokens]),g.useEffect(()=>{o(!1),setTimeout(()=>{const l=X.syncBlocksWithDefaultProps(t.blocks||[]);e(l),l&&l.length>0&&r({type:"blocks-updated",blocks:l}),n(),o(!0),i(l)},400)},[t.blocks]),g.useEffect(()=>{gt.changeLanguage(t.locale||"en")},[t.locale]),g.useEffect(()=>{Iy(t.debugLogs??!1)},[t.debugLogs]),g.useEffect(()=>{t.translations&&d.each(t.translations,(l,c)=>{gt.addResourceBundle(c,"translation",l,!0,!0)})},[t.translations]),g.useEffect(()=>(s!=="SAVED"?window.onbeforeunload=()=>"":window.onbeforeunload=null,()=>{window.onbeforeunload=null}),[s]),null},Vy=t=>{const e=g.useMemo(()=>t.layout||ky,[t.layout]),n=$("builderTheme",Ze.defaultThemeValues),s=$("flags.exportCode",!1);return a.jsxs(a.Fragment,{children:[t.children,a.jsx(_i,{theme:n}),a.jsx(e,{}),s&&a.jsx(Pc,{})]})},Wy=t=>{const e=t.onError||d.noop;return a.jsx("div",{className:"h-screen w-screen",children:a.jsxs(At.ErrorBoundary,{fallback:a.jsx(yn,{}),onError:e,children:[a.jsx(Dy,{}),a.jsx(Vy,{...t}),a.jsx(Hy,{...t}),a.jsx(jy,{}),a.jsx(pe.Toaster,{richColors:!0}),a.jsx(Ay,{})]})})},Gy=({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(r=>{var o;return{...r,preview:(o=r.preview)!=null&&o.startsWith("http")?r.preview:`${t}${r.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}" -->`}}});if(typeof window>"u")throw new Error("@chaibuilder/sdk is only supported in the browser. Avoid using it in the server side.");exports.AIUserPrompt=Cc;exports.Accordion=Fl;exports.AccordionContent=ko;exports.AccordionItem=yo;exports.AccordionTrigger=vo;exports.AddBlocksDialog=Tc;exports.AddBlocksPanel=Bo;exports.AlertDialog=Po;exports.AlertDialogAction=Do;exports.AlertDialogCancel=Oo;exports.AlertDialogContent=Ds;exports.AlertDialogDescription=Mo;exports.AlertDialogFooter=Lo;exports.AlertDialogHeader=Os;exports.AlertDialogTitle=$s;exports.AlertDialogTrigger=uc;exports.Badge=_s;exports.BlockAttributesEditor=_c;exports.BlockSettings=fr;exports.BlockStyling=yr;exports.Breakpoints=So;exports.CanvasArea=Rl;exports.Card=Eo;exports.CardContent=Io;exports.CardFooter=To;exports.CardHeader=Ao;exports.CardTitle=Ql;exports.ChaiBuilderEditor=Wy;exports.ChaiDraggableBlock=ac;exports.Command=co;exports.CommandEmpty=fo;exports.CommandGroup=ho;exports.CommandInput=uo;exports.CommandItem=gs;exports.CommandList=po;exports.DarkMode=Sc;exports.DefaultChaiBlocks=Zl;exports.Dialog=Pn;exports.DialogContent=an;exports.DialogDescription=Dl;exports.DialogFooter=Ml;exports.DialogHeader=Ln;exports.DialogTitle=ln;exports.DialogTrigger=Pl;exports.DropdownMenu=et;exports.DropdownMenuContent=Ge;exports.DropdownMenuItem=le;exports.DropdownMenuSeparator=wr;exports.DropdownMenuTrigger=tt;exports.ExportCodeModal=Pc;exports.HoverCard=Yl;exports.HoverCardContent=jo;exports.HoverCardTrigger=Xl;exports.ImportHTML=tc;exports.LANGUAGES=Ot;exports.Label=ut;exports.ListTree=xc;exports.ManualClasses=No;exports.NestedPathSelector=xo;exports.PERMISSIONS=se;exports.Popover=mo;exports.PopoverContent=Bs;exports.PopoverTrigger=go;exports.ScrollArea=Nn;exports.Select=Ms;exports.SelectContent=zn;exports.SelectItem=Hn;exports.SelectTrigger=Fn;exports.Separator=Rt;exports.Sheet=Ec;exports.SheetContent=$o;exports.SheetDescription=Ic;exports.SheetHeader=Fo;exports.SheetTitle=zo;exports.SheetTrigger=ly;exports.Skeleton=Lt;exports.Switch=cn;exports.Tabs=Ls;exports.TabsContent=ct;exports.TabsList=On;exports.TabsTrigger=He;exports.Textarea=$n;exports.ThemeConfigPanel=vc;exports.Tooltip=fe;exports.TooltipContent=ce;exports.TooltipProvider=ms;exports.TooltipTrigger=he;exports.UILibrariesPanel=lc;exports.UndoRedo=Nc;exports.builderStore=Ve;exports.chaiDesignTokensAtom=en;exports.defaultChaiLibrary=Gy;exports.getClassValueAndUnit=Vl;exports.libraryBlocksAtom=rc;exports.orderClassesByBreakpoint=Ul;exports.presentBlocksAtom=je;exports.removeDuplicateClasses=ql;exports.useAddBlock=bt;exports.useBlocksHtmlForAi=Rc;exports.useBlocksStore=te;exports.useBlocksStoreUndoableActions=Ne;exports.useBuilderProp=$;exports.useCodeEditor=lo;exports.useIncrementActionsCount=Dr;exports.useIsPageLoaded=si;exports.useLanguages=Te;exports.useLibraryBlocks=oc;exports.usePageExternalData=tn;exports.usePartialBlocksStore=As;exports.usePermissions=qe;exports.useRemoveBlocks=Cs;exports.useRightPanel=Mr;exports.useSavePage=nn;exports.useSelectedBlock=J;exports.useSelectedBlockIds=U;exports.useSidebarActivePanel=Ns;exports.useStreamMultipleBlocksProps=Qa;exports.useTheme=An;exports.useUpdateBlocksProps=nt;exports.useUpdateBlocksPropsRealtime=_r;
|