@clepit/core 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={bg:"#ffffff",blockHighlightBg:"rgba(0, 0, 0, 0.05)",border:"rgba(17, 24, 39, 0.12)",borderSubtle:"rgba(17, 24, 39, 0.06)",codeBg:"#f2f4f7",codeBorder:"rgba(17, 24, 39, 0.10)",codeComment:"#868f9c",codeFunction:"#6f42c1",codeGutter:"#868f9c",codeKeyword:"#cf222e",codeNumber:"#0550ae",codePunctuation:"#525866",codeSelectionBg:"rgba(91, 91, 255, 0.14)",codeString:"#0a7c3e",codeText:"#0a0a0a",codeType:"#953800",error:"#dc2626",errorBg:"rgba(220, 38, 38, 0.08)",info:"#2563eb",infoBg:"rgba(37, 99, 235, 0.08)",marker:"#ffe047",primary:"#5b5bff",primaryBg:"rgba(91, 91, 255, 0.08)",primaryHover:"#4747e6",selectionBg:"rgba(91, 91, 255, 0.14)",success:"#16a34a",successBg:"rgba(22, 163, 74, 0.08)",surface:"#f8f9fa",surface2:"#f1f3f5",text:"#0a0a0a",textMuted:"#525866",textSubtle:"#868f9c",warning:"#d97706",warningBg:"rgba(217, 119, 6, 0.08)"},t={bg:"--clepit-bg",blockHighlightBg:"--clepit-block-highlight-bg",border:"--clepit-border",borderSubtle:"--clepit-border-subtle",codeBg:"--clepit-code-bg",codeBorder:"--clepit-code-border",codeComment:"--clepit-code-comment",codeFunction:"--clepit-code-function",codeGutter:"--clepit-code-gutter",codeKeyword:"--clepit-code-keyword",codeNumber:"--clepit-code-number",codePunctuation:"--clepit-code-punctuation",codeSelectionBg:"--clepit-code-selection-bg",codeString:"--clepit-code-string",codeText:"--clepit-code-text",codeType:"--clepit-code-type",error:"--clepit-error",errorBg:"--clepit-error-bg",info:"--clepit-info",infoBg:"--clepit-info-bg",marker:"--clepit-marker",primary:"--clepit-primary",primaryBg:"--clepit-primary-bg",primaryHover:"--clepit-primary-hover",selectionBg:"--clepit-selection-bg",success:"--clepit-success",successBg:"--clepit-success-bg",surface:"--clepit-surface",surface2:"--clepit-surface-2",text:"--clepit-text",textMuted:"--clepit-text-muted",textSubtle:"--clepit-text-subtle",warning:"--clepit-warning",warningBg:"--clepit-warning-bg"},n=(e,n,a)=>{const o=[];for(const i of Object.keys(t)){const a=e[i],r=n[i];if(void 0===a&&void 0===r)continue;const s=t[i];void 0!==a&&void 0!==r?o.push(` ${s}: light-dark(${a}, ${r});`):o.push(` ${s}: ${a??r};`)}return 0===o.length?"":`${a} {\n${o.join("\n")}\n}`},a=class e{static{this.idSuffixes={actionBar:{clearButton:"action-bar-clear-button",copyButton:"action-bar-copy-button",downloadButton:"action-bar-download-button",editButton:"edit-button",jsonButton:"json-button",previewButton:"preview-button"},editorContent:"content"}}static{this.classNames={actionBar:{action:"clepit-view-actions",actionButton:"clepit-view-action-button",button:"clepit-action-bar-button",container:"clepit-action-bar",copyFeedback:"clepit-view-action-button--copy-feedback",group:"clepit-action-bar-group"},block:{active:"clepit-block--active",alert:"clepit-alert",audio:{captionEditable:"clepit-audio-caption-editable",container:"clepit-audio-container",dropArea:"clepit-audio-drop-area",wrapper:"clepit-audio-wrapper"},audioDeleteBtn:"clepit-audio-delete-btn",checklist:{checkbox:"clepit-checklist-checkbox",container:"clepit-checklist",item:"clepit-checklist-item",text:"clepit-checklist-text"},code:{container:"clepit-code-container",editor:"clepit-code-editor",header:"clepit-code-header",headerWrapper:"clepit-code-header-wrapper"},container:"clepit-block",content:"clepit-block-content",header:"clepit-header",image:{captionEditable:"clepit-image-caption-editable",container:"clepit-image-container",dropArea:"clepit-image-drop-area",wrapper:"clepit-image-wrapper"},imageDeleteBtn:"clepit-image-delete-btn",indent1:"clepit-block-indent-1",indent2:"clepit-block-indent-2",indent3:"clepit-block-indent-3",link:"clepit-link",list:{container:"clepit-list",item:"clepit-list-item"},output:"clepit-output-block",paragraph:"clepit-paragraph",quote:{author:"clepit-quote-author",container:"clepit-quote-container",divider:"clepit-quote-divider",text:"clepit-quote-text"},table:{caption:"clepit-table-caption",cell:"clepit-table-cell",downloadSwitch:"clepit-table-download-switch",headerCell:"clepit-table-header-cell",headerRow:"clepit-table-header-row",row:"clepit-table-row"},tooltip:"clepit-tooltip",video:{captionEditable:"clepit-video-caption-editable",container:"clepit-video-container",dropArea:"clepit-video-drop-area",iframe:"clepit-video-iframe",video:"clepit-video",wrapper:"clepit-video-wrapper"},videoDeleteBtn:"clepit-video-delete-btn"},editor:{container:"clepit-editor",content:"clepit-editor-content",jsonEditable:"clepit-json-editable",jsonEmpty:"clepit-json-empty",jsonError:"clepit-json-error",jsonOutput:"clepit-json-output"},renderer:{content:"clepit-renderer-content"},switch:{container:"clepit-custom-switch"}}}static applyStyles(e,t){t&&"object"==typeof t&&Object.entries(t).forEach(([t,n])=>{if(void 0!==n)if(t.startsWith("--"))e.style.setProperty(t,String(n));else{const a=t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);e.style.setProperty(a,String(n))}})}static applyClassNames(e,t){t&&("string"==typeof t?e.classList.add(t):Object.entries(t).forEach(([t,n])=>{n&&"string"==typeof n&&e.classList.add(n)}))}static applyStyling(t,n){const{styles:a,classNames:o}=n;if(a&&"object"==typeof a){const n=[],o={};Object.entries(a).forEach(([e,t])=>{void 0===t?n.push(e):o[e]=t}),Object.keys(o).length>0&&e.applyStyles(t,o),n.forEach(e=>t.style.removeProperty(e))}o&&e.applyClassNames(t,o)}static createStyledElement(t,n,a){const o=document.createElement(t);return o.className=n,a&&e.applyStyling(o,a),o}static injectStyles(e,t){if(document.getElementById(e))return!1;const n=document.createElement("style");return n.id=e,n.textContent=t,document.head.appendChild(n),!0}static{this.themeRegistry=new Map}static{this.themeSubscribers=new Set}static registerEditor(t,a,o){const i=document.getElementById(t);i&&(i.setAttribute("data-clepit-theme",a),i.setAttribute("data-clepit-instance",t)),e.themeRegistry.set(t,a),e.syncBodyThemeAttribute();const r=document.getElementById(`clepit-overrides-${t}`);if(r&&r.remove(),o){const a=n(o.light??{},o.dark??{},`[data-clepit-instance='${t}']`);a&&e.injectStyles(`clepit-overrides-${t}`,a)}e.ensureThemeListener()}static unregisterEditor(t){const n=document.getElementById(`clepit-overrides-${t}`);n&&n.remove();const a=document.getElementById(t);a&&(a.removeAttribute("data-clepit-theme"),a.removeAttribute("data-clepit-instance")),e.themeRegistry.delete(t),e.syncBodyThemeAttribute(),e.maybeDetachThemeListener()}static syncBodyThemeAttribute(){if("undefined"==typeof document||!document.body)return;const t=e.themeRegistry.values().next().value;t?document.body.setAttribute("data-clepit-theme",t):document.body.removeAttribute("data-clepit-theme")}static getResolvedTheme(){return"undefined"==typeof window||"function"!=typeof window.matchMedia?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}static subscribe(t){return e.themeSubscribers.add(t),e.ensureThemeListener(),()=>{e.themeSubscribers.delete(t),e.maybeDetachThemeListener()}}static unregisterAllEditorsForTest(){for(const t of Array.from(e.themeRegistry.keys()))e.unregisterEditor(t);e.themeSubscribers.clear(),e.maybeDetachThemeListener()}static ensureThemeListener(){"undefined"!=typeof window&&"function"==typeof window.matchMedia&&0!==e.themeSubscribers.size&&(e.themeMediaQuery||(e.themeMediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),e.themeMediaQueryListener=t=>{const n=t.matches?"dark":"light";for(const a of e.themeSubscribers)a(n)},e.themeMediaQuery.addEventListener("change",e.themeMediaQueryListener)))}static maybeDetachThemeListener(){e.themeSubscribers.size>0||e.themeMediaQuery&&e.themeMediaQueryListener&&(e.themeMediaQuery.removeEventListener("change",e.themeMediaQueryListener),e.themeMediaQuery=void 0,e.themeMediaQueryListener=void 0)}},o=e=>{let t;const n=new Set,a=(e,a)=>{const o="function"==typeof e?e(t):e;if(Object.is(o,t))return;const i=t;t=a?o:Object.assign({},t,o);for(const r of n)r(t,i)},o=()=>t,i={getInitialState:()=>r,getState:o,setState:a,subscribe:e=>(n.add(e),()=>{n.delete(e)})},r=t=e(a,o,i);return i};var i,r,s,l=(s?o(s):o)((e=>(t,n,a)=>{const o=a.subscribe;return a.subscribe=(e,t,n)=>{if(!t)return o(e);const i=n?.equalityFn??Object.is;let r=e(a.getState());return n?.fireImmediately&&t(r,r),o(n=>{const a=e(n);if(!i(r,a)){const e=r;t(r=a,e)}})},e(t,n,a)})((e=>(t,n,a)=>e(t,n,a))((i=(e,t)=>({addBlock:(n,a,o)=>{const i=t().instances[n];if(!i)return;const r=[...i.data.blocks];void 0===o||o<0||o>r.length?r.push(a):r.splice(o,0,a);const s={...i,data:{...i.data,blocks:r}};e(e=>({instances:{...e.instances,[n]:s}})),i.config.onChange&&i.config.onChange(s.data)},addInstance:(n,a)=>{const o=t().instances;o[n]?o[n].config=a.config:o[n]=a,e({instances:o})},clearData:n=>{const a=t().instances[n];if(!a)return;const o={...a,data:{...a.data,blocks:[]}};e(e=>({instances:{...e.instances,[n]:o}})),a.config.onChange&&a.config.onChange(o.data)},getContentElement:e=>{const n=t().instances[e];return n?document.querySelector(`#${n.contentId}`):null},getCurrentView:e=>t().instances[e]?.currentView||null,getData:e=>t().instances[e]?.data||null,getInstance:e=>t().instances[e]||null,getIsReady:e=>{const n=t().instances[e];return!!n&&n.isReady},instances:{},partialUpdateBlockData:(n,a,o)=>{const i=t().instances[n];if(!i)return;const r=i.data.blocks.map((e,t)=>t===a?{...e,data:{...e.data,...o}}:e),s={...i,data:{...i.data,blocks:r}};e(e=>({instances:{...e.instances,[n]:s}})),i.config.onChange&&i.config.onChange(s.data)},removeBlock:(n,a)=>{const o=t().instances[n];if(!o)return;const i=o.data.blocks.filter((e,t)=>t!==a),r={...o,data:{...o.data,blocks:i}};e(e=>({instances:{...e.instances,[n]:r}})),o.config.onChange&&o.config.onChange(r.data)},removeInstance:t=>{e(e=>{const n={...e.instances};return delete n[t],{instances:n}})},setCurrentView:(n,a)=>{const o=t().instances[n];if(!o)return;const i={...o,currentView:a};e(e=>({instances:{...e.instances,[n]:i}})),o.config.onChange&&o.config.onChange(i.data)},setData:(n,a)=>{const o=t().instances[n];if(!o)return;const i={...o,data:a};e(e=>({instances:{...e.instances,[n]:i}})),o.config.onChange&&o.config.onChange(a)},setIsReady:(n,a)=>{const o=t().instances[n];if(!o)return;const i={...o,isReady:a};e(e=>({instances:{...e.instances,[n]:i}})),o.config.onChange&&o.config.onChange(i.data)},updateBlock:(n,a,o)=>{const i=t().instances[n];if(!i)return;const r=i.data.blocks.map((e,t)=>t===a?{...e,...o}:e),s={...i,data:{...i.data,blocks:r}};e(e=>({instances:{...e.instances,[n]:s}})),i.config.onChange&&i.config.onChange(s.data)},updateBlockData:(n,a,o)=>{const i=t().instances[n];if(!i)return;const r=i.data.blocks.map((e,t)=>t===a?{...e,data:o}:e),s={...i,data:{...i.data,blocks:r}};e(e=>({instances:{...e.instances,[n]:s}})),i.config.onChange&&i.config.onChange(s.data)},updateData:(n,a)=>{const o=t().instances[n];if(!o)return;const i={...o,data:{...o.data,...a}};e(e=>({instances:{...e.instances,[n]:i}})),o.config.onChange&&o.config.onChange(i.data)},updateInstance:(n,a)=>{const o=t().instances;o[n]&&(o[n].data=a.data,e({instances:o}))}}),r={name:"clepit-store",version:0},(e,t,n)=>{const a=r.version??0,o=r.storage??("undefined"==typeof localStorage?void 0:localStorage),s=r.merge??((e,t)=>Object.assign({},t,e)),l=i(e,t,n);if(o){try{const e=o.getItem(r.name);if(e){const t=JSON.parse(e),n=t.version===a?t.state:r.migrate?r.migrate(t.state,t.version??0):void 0;void 0!==n&&Object.assign(l,s(n,l))}}catch{}n.subscribe(e=>{try{o.setItem(r.name,JSON.stringify({state:r.partialize?r.partialize(e):e,version:a}))}catch{}})}return l}))));function c(){if("undefined"==typeof navigator)return"unknown";const e=navigator.platform.toLowerCase(),t=navigator.userAgent.toLowerCase();return e.includes("mac")||t.includes("mac")?"mac":e.includes("win")||t.includes("win")?"windows":e.includes("linux")||t.includes("linux")?"linux":"unknown"}function p(){return"mac"===c()?"⌘":"Ctrl"}function d(e){return"mac"===c()?e.join(""):e.join(" + ")}var u=e=>d([p(),e]),m=e=>d([p(),{down:"↓",left:"←",right:"→",up:"↑"}[e]]),h=()=>d([p(),"B"]),g=()=>d([p(),"⌫"]),b=()=>d([p(),"⌦"]),f=()=>d([p(),"I"]),y=()=>d([p(),"K"]),v=e=>d([p(),"⇧",e]),x=e=>d([p(),"⇧",{down:"↓",left:"←",right:"→",up:"↑"}[e]]),k=()=>d([p(),"U"]),w=class e{static{this.label="bold"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 4h6a4 4 0 0 1 0 8H7z"/><path d="M7 12h7a4 4 0 0 1 0 8H7z"/></svg>'}static{this.shortcut=h()}static apply(e){a.injectStyles("clepit-bold-styles","\n/* Bold inline formatting styles */\n.clepit-toolbar-button strong,\n.clepit-toolbar-button em,\n.clepit-toolbar-button u,\n.clepit-toolbar-button code,\n.clepit-toolbar-button mark {\n font-size: inherit;\n font-weight: inherit;\n font-style: inherit;\n text-decoration: inherit;\n background: transparent;\n padding: 0;\n border-radius: 0;\n font-family: inherit;\n}\n");const t=document.createElement("strong");e.surroundContents(t),or.updateStateFromRange(e)}static remove(t){const n=e.findBoldElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}}else{const e=t.commonAncestorContainer;if(e.nodeType===Node.ELEMENT_NODE){const n=e.querySelectorAll("strong");for(const e of n)if(t.intersectsNode(e)){const t=e.parentElement;t&&(t.insertBefore(document.createTextNode(e.textContent||""),e),t.removeChild(e))}}}or.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findBoldElement(n)||t.cloneContents().querySelectorAll('b, strong, [style*="font-weight: bold"], [style*="font-weight:bold"]').length>0}static findBoldElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("B"===e.tagName||"STRONG"===e.tagName)return e;if("bold"===e.style.fontWeight||Number.parseInt(e.style.fontWeight)>=700)return e}return t.parentNode?e.findBoldElement(t.parentNode):null}},C=class e{static{this.label="inline code"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="7 8 3 12 7 16"/><polyline points="17 8 21 12 17 16"/></svg>'}static{this.shortcut=u("`")}static apply(e,t,n){a.injectStyles("clepit-inline-code-styles","\n/* Inline code styling when <code> is within editable text */\n.clepit-paragraph code,\n.clepit-header code,\n.clepit-list-item code,\n.clepit-quote-text code,\n.clepit-quote-caption code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Output inline code styling */\n.clepit-output-paragraph code,\n.clepit-output-header code,\n.clepit-output-list li code,\n.clepit-output-quote code,\n.clepit-output-quote cite code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Toolbar button code styling */\n.clepit-toolbar-button strong,\n.clepit-toolbar-button em,\n.clepit-toolbar-button u,\n.clepit-toolbar-button code,\n.clepit-toolbar-button mark {\n font-size: inherit;\n font-weight: inherit;\n font-style: inherit;\n text-decoration: inherit;\n background: transparent;\n padding: 0;\n border-radius: 0;\n font-family: inherit;\n}\n");const o=document.createElement("code");o.classList.add("clepit-inline-code"),t&&a.applyClassNames(o,t),n&&Object.entries(n).forEach(([e,t])=>{if(void 0!==t){const n=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);o.style.setProperty(n,String(t))}}),e.surroundContents(o),or.updateStateFromRange(e)}static remove(t){const n=e.findCodeElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}}else{const e=t.commonAncestorContainer;if(e.nodeType===Node.ELEMENT_NODE){const n=e.querySelectorAll("code");for(const e of n)if(t.intersectsNode(e)){const t=e.parentElement;t&&(t.insertBefore(document.createTextNode(e.textContent||""),e),t.removeChild(e))}}}or.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findCodeElement(n)||t.cloneContents().querySelectorAll('code, [style*="font-family: monospace"], [style*="font-family:monospace"]').length>0}static findCodeElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("CODE"===e.tagName)return e;const n=window.getComputedStyle(e);if(n.fontFamily.includes("monospace")||n.fontFamily.includes("Monaco")||n.fontFamily.includes("Menlo"))return e;if(e.style.fontFamily.includes("monospace")||e.style.fontFamily.includes("Monaco")||e.style.fontFamily.includes("Menlo"))return e}return t.parentNode?e.findCodeElement(t.parentNode):null}static updateExistingCodeElements(e,t){document.querySelectorAll("code").forEach(n=>{n instanceof HTMLElement&&(n.classList.contains("clepit-inline-code")||n.classList.add("clepit-inline-code"),e&&a.applyClassNames(n,e),t&&Object.entries(t).forEach(([e,t])=>{if(void 0!==t){const a=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);n.style.setProperty(a,String(t))}}))})}},E=class e{static{this.label="italic"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 4h8"/><path d="M7 20h8"/><path d="M13 4L9 20"/></svg>'}static{this.shortcut=f()}static apply(e){a.injectStyles("clepit-italic-styles","\n/* Italic inline formatting styles */\n.clepit-toolbar-button strong,\n.clepit-toolbar-button em,\n.clepit-toolbar-button u,\n.clepit-toolbar-button code,\n.clepit-toolbar-button mark {\n font-size: inherit;\n font-weight: inherit;\n font-style: inherit;\n text-decoration: inherit;\n background: transparent;\n padding: 0;\n border-radius: 0;\n font-family: inherit;\n}\n\n.clepit-menu-icon--italic {\n font-style: italic;\n}\n");const t=document.createElement("em");e.surroundContents(t),or.updateStateFromRange(e)}static remove(t){const n=e.findItalicElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}}else{const e=t.commonAncestorContainer;if(e.nodeType===Node.ELEMENT_NODE){const n=e.querySelectorAll("em, i");for(const e of n)if(t.intersectsNode(e)){const t=e.parentElement;t&&(t.insertBefore(document.createTextNode(e.textContent||""),e),t.removeChild(e))}}}or.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findItalicElement(n)||t.cloneContents().querySelectorAll('i, em, [style*="font-style: italic"], [style*="font-style:italic"]').length>0}static findItalicElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("I"===e.tagName||"EM"===e.tagName)return e;if("italic"===window.getComputedStyle(e).fontStyle)return e;if("italic"===e.style.fontStyle)return e}return t.parentNode?e.findItalicElement(t.parentNode):null}},S="clepit-link-styles",N=`\n/* Link styles - simple and clean */\n.${a.classNames.block.link} {\n color: var(--clepit-primary);\n cursor: pointer;\n}\n\n.${a.classNames.block.link}:hover {\n color: var(--clepit-primary-hover);\n}\n`,A="clepit-dialogs-styles",L="\n/* Dialog Overlay */\n/* A native <dialog>. showModal() puts it in the top layer and paints a real\n * ::backdrop, so the full-screen scrim, the z-index and the manual centring are\n * the browser's job now. The non-modal branch below keeps the old flex overlay\n * for a DOM without showModal, where the element is an ordinary block. */\n.clepit-dialog-overlay {\n border: none;\n padding: 0;\n background: transparent;\n max-width: none;\n max-height: none;\n}\n\n.clepit-dialog-overlay[open] {\n display: flex;\n align-items: center;\n justify-content: center;\n}\n\n.clepit-dialog-overlay::backdrop {\n background: rgba(0, 0, 0, 0.5);\n backdrop-filter: blur(2px);\n}\n\n/* Fallback: no showModal, so the element is not in the top layer and paints no\n * backdrop of its own. */\n.clepit-dialog-overlay:not([open]) {\n position: fixed;\n inset: 0;\n background: rgba(0, 0, 0, 0.5);\n align-items: center;\n justify-content: center;\n z-index: 10000;\n backdrop-filter: blur(2px);\n}\n\n/* Dialog Container */\n.clepit-dialog {\n background: var(--clepit-bg);\n border-radius: 8px;\n box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);\n padding: 24px;\n min-width: 400px;\n max-width: 500px;\n max-height: 80vh;\n overflow-y: auto;\n position: relative;\n transform: scale(0.95);\n opacity: 0;\n transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n.clepit-dialog--hidden {\n transform: scale(0.95);\n opacity: 0;\n}\n\n.clepit-dialog:not(.clepit-dialog--hidden) {\n transform: scale(1);\n opacity: 1;\n}\n\n/* Dialog Title */\n.clepit-dialog-title {\n margin: 0 0 20px 0;\n font-size: 18px;\n font-weight: 600;\n color: var(--clepit-text);\n text-align: center;\n}\n\n/* Dialog Group */\n.clepit-dialog-group {\n margin-bottom: 16px;\n}\n\n/* Dialog Label */\n.clepit-dialog-label {\n display: block;\n margin-bottom: 6px;\n font-size: 14px;\n font-weight: 500;\n color: var(--clepit-text);\n}\n\n/* Dialog Input */\n.clepit-dialog-input {\n width: 100%;\n padding: 10px 12px;\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n font-size: 14px;\n color: var(--clepit-text);\n background: var(--clepit-bg);\n transition: border-color 0.2s ease, box-shadow 0.2s ease;\n box-sizing: border-box;\n}\n\n.clepit-dialog-input:focus {\n outline: none;\n border-color: var(--clepit-primary);\n box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);\n}\n\n.clepit-dialog-input::placeholder {\n color: var(--clepit-text-subtle);\n}\n\n/* Dialog Buttons */\n.clepit-dialog-buttons {\n display: flex;\n gap: 12px;\n justify-content: flex-end;\n margin-top: 24px;\n}\n\n/* Dialog Button */\n.clepit-dialog-button {\n padding: 10px 20px;\n border: none;\n border-radius: 6px;\n font-size: 14px;\n font-weight: 500;\n cursor: pointer;\n transition: all 0.2s ease;\n min-width: 80px;\n}\n\n.clepit-dialog-button--cancel {\n background: var(--clepit-surface);\n color: var(--clepit-text);\n border: 1px solid var(--clepit-border);\n}\n\n.clepit-dialog-button--cancel:hover {\n background: var(--clepit-border);\n border-color: var(--clepit-text-subtle);\n}\n\n.clepit-dialog-button--save {\n background: var(--clepit-primary);\n color: white;\n}\n\n.clepit-dialog-button--save:hover {\n background: var(--clepit-primary);\n}\n\n.clepit-dialog-button--save:disabled {\n background: var(--clepit-text-subtle);\n cursor: not-allowed;\n}\n\n/* Responsive */\n@media (max-width: 640px) {\n .clepit-dialog {\n min-width: 320px;\n max-width: 90vw;\n margin: 20px;\n }\n\n .clepit-dialog-buttons {\n flex-direction: column;\n }\n\n .clepit-dialog-button {\n width: 100%;\n }\n}\n";function B(e,t,n){const a=document.createElement(e);if(t&&(a.className=t),n)for(const[o,i]of Object.entries(n))a.setAttribute(o,i);return a}function $(e,t){return`${e}-${t}`}function I(e){return!e||!e.trim()||"<br>"===e}function M(e){if(!e||I(e))return"";const t=document.createElement("div");t.innerHTML=e;const n=["strong","b","em","i","u","s","del","mark","code","a","span"],a=["href","target","data-tooltip","data-status","data-status-variant","data-user-id","data-page-id","class"];function o(e){if(e.nodeType===Node.TEXT_NODE)return e.cloneNode(!0);if(e.nodeType===Node.ELEMENT_NODE){const t=e,i=t.tagName.toLowerCase();if(!n.includes(i))return document.createTextNode(t.textContent||"");const r=document.createElement(i);for(const e of t.attributes)a.includes(e.name.toLowerCase())&&r.setAttribute(e.name,e.value);"a"===i&&(r.setAttribute("target","_blank"),r.setAttribute("rel","noopener noreferrer"));for(const e of Array.from(t.childNodes)){const t=o(e);t&&r.appendChild(t)}return r}return null}const i=document.createElement("div");for(const r of Array.from(t.childNodes)){const e=o(r);e&&i.appendChild(e)}return i.innerHTML}function T(e,t){const n=window.getSelection();if(!n||0===n.rangeCount)return!1;const a=n.getRangeAt(0);if(!a)return!1;if(!e.contains(a.commonAncestorContainer))return!1;if(0===(e.textContent||"").length)return!0;if("left"===t){const t=e.firstChild;return t&&t.nodeType===Node.TEXT_NODE?a.startContainer===t&&0===a.startOffset:a.startContainer===e&&0===a.startOffset}{const t=e.lastChild;return t&&t.nodeType===Node.TEXT_NODE?a.endContainer===t&&a.endOffset===t.textContent?.length:a.endContainer===e&&a.endOffset===e.childNodes.length}}var q=class e{static{this.isOpen=!1}constructor(e){this.overlay=null,this.dialog=null,this.textInput=null,this.urlInput=null,this.handleKeyDown=e=>{"Escape"===e.key&&(this.options.onCancel(),this.hide())},this.handleInputKeyDown=e=>{if("Enter"===e.key){const e=this.textInput?.value.trim()||"",t=this.urlInput?.value.trim()||"";e&&t&&(this.options.onConfirm(e,t),this.hide())}},this.options=e}show(){this.overlay||e.isOpen||(a.injectStyles(A,L),e.isOpen=!0,this.createDialog(),this.bindEvents(),this.focusFirstInput())}hide(){if(!this.overlay)return;const t=this.overlay;"function"==typeof t.close&&t.open&&t.close(),t.remove(),this.overlay=null,this.dialog=null,this.textInput=null,this.urlInput=null,e.isOpen=!1;const n=document.querySelector(".clepit-toolbar");n&&(n.style.display="flex")}createDialog(){this.overlay=B("dialog","clepit-dialog-overlay"),this.applyStyles(this.overlay,this.options.styles?.overlay),this.applyClassNames(this.overlay,this.options.classNames?.overlay),this.dialog=B("div","clepit-dialog"),this.applyStyles(this.dialog,this.options.styles?.container),this.applyClassNames(this.dialog,this.options.classNames?.container);const e=B("h3","clepit-dialog-title");e.textContent="Insert Link",this.applyStyles(e,this.options.styles?.title),this.applyClassNames(e,this.options.classNames?.title);const t=this.createInputGroup("Text",this.options.text,"text");this.textInput=t.querySelector("input");const n=this.createInputGroup("URL",this.options.url,"url");this.urlInput=n.querySelector("input");const a=this.createButtonGroup();this.dialog.appendChild(e),this.dialog.appendChild(t),this.dialog.appendChild(n),this.dialog.appendChild(a),this.overlay.appendChild(this.dialog),document.body.appendChild(this.overlay);const o=this.overlay;"function"==typeof o.showModal?o.showModal():o.style.display="flex",this.dialog?.classList.remove("clepit-dialog--hidden");const i=document.querySelector(".clepit-toolbar");i&&(i.style.display="none")}createInputGroup(e,t,n){const a=B("div","clepit-dialog-group");this.applyStyles(a,this.options.styles?.group),this.applyClassNames(a,this.options.classNames?.group);const o=B("label","clepit-dialog-label");o.textContent=e,this.applyStyles(o,this.options.styles?.label),this.applyClassNames(o,this.options.classNames?.label);const i=B("input","clepit-dialog-input");return i.type="url"===n?"url":"text",i.value=t,i.placeholder="url"===n?"https://example.com":"Link text",this.applyStyles(i,this.options.styles?.input),this.applyClassNames(i,this.options.classNames?.input),a.appendChild(o),a.appendChild(i),a}createButtonGroup(){const e=B("div","clepit-dialog-buttons");this.applyStyles(e,this.options.styles?.buttons),this.applyClassNames(e,this.options.classNames?.buttons);const t=B("button","clepit-dialog-button clepit-dialog-button--cancel");t.textContent="Cancel",t.type="button",this.applyStyles(t,this.options.styles?.cancelButton),this.applyClassNames(t,this.options.classNames?.cancelButton);const n=B("button","clepit-dialog-button clepit-dialog-button--save");return n.textContent="Apply",n.type="button",this.applyStyles(n,this.options.styles?.saveButton),this.applyClassNames(n,this.options.classNames?.saveButton),t.addEventListener("click",()=>{this.options.onCancel(),this.hide()}),n.addEventListener("click",()=>{this.options.onConfirm(this.textInput?.value.trim()||"",this.urlInput?.value.trim()||""),this.hide()}),e.appendChild(t),e.appendChild(n),e}bindEvents(){this.overlay&&(this.overlay.addEventListener("click",e=>{e.target===this.overlay&&(this.options.onCancel(),this.hide())}),document.addEventListener("keydown",this.handleKeyDown),this.textInput&&this.textInput.addEventListener("keydown",this.handleInputKeyDown),this.urlInput&&this.urlInput.addEventListener("keydown",this.handleInputKeyDown))}focusFirstInput(){setTimeout(()=>{this.urlInput&&(this.urlInput.focus(),this.urlInput.select())},100)}applyStyles(e,t){t&&Object.entries(t).forEach(([t,n])=>{void 0!==n&&e.style.setProperty(t,String(n))})}applyClassNames(e,t){t&&e.classList.add(t)}destroy(){document.removeEventListener("keydown",this.handleKeyDown),this.hide(),e.isOpen=!1}},D=class e{static{this.label="link"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13a5 5 0 0 0 7.07 0l1.76-1.76a5 5 0 0 0-7.07-7.07L10 5"/><path d="M14 11a5 5 0 0 0-7.07 0L5.17 12.76a5 5 0 0 0 7.07 7.07L14 19"/></svg>'}static{this.shortcut=y()}static apply(t,n,o){a.injectStyles(S,N);const i=t.toString().trim(),r=e.findLinkElement(t.commonAncestorContainer);let s=i,l="";r&&(s=r.textContent||i,l=r.href||"");const c=t.cloneRange();new q({classNames:n,onCancel:()=>{const e=window.getSelection();e&&(e.removeAllRanges(),e.addRange(c))},onConfirm:(t,n)=>{try{const o=window.getSelection();if(o){if(o.removeAllRanges(),o.addRange(c),!n.trim())return void e.remove(c);if(t!==i){c.deleteContents();const e=document.createTextNode(t);c.insertNode(e),c.selectNode(e)}const r=a.createStyledElement("a",a.classNames.block.link);r.href=n,r.target="_blank",r.rel="noopener noreferrer";try{c.surroundContents(r)}catch{const e=c.extractContents();r.appendChild(e),c.insertNode(r)}const s=document.createRange();s.selectNodeContents(r),o.removeAllRanges(),o.addRange(s);const l=r.closest('[contenteditable="true"]');if(l){const e=new Event("input",{bubbles:!0});l.dispatchEvent(e)}}}catch(o){console.error("Failed to apply link:",o)}},styles:o,text:s||"Link text",url:l}).show(),or.updateStateFromRange(t)}static remove(t){const n=e.findLinkElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}}else{const e=t.commonAncestorContainer;if(e.nodeType===Node.ELEMENT_NODE){const n=e.querySelectorAll("a");for(const e of n)if(t.intersectsNode(e)){const t=e.parentElement;t&&(t.insertBefore(document.createTextNode(e.textContent||""),e),t.removeChild(e))}}}or.updateStateFromRange(t)}static findLinkElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("A"===e.tagName)return e}return t.parentNode?e.findLinkElement(t.parentNode):null}static isActive(t){const n=t.commonAncestorContainer;return!!e.findLinkElement(n)||t.cloneContents().querySelectorAll("a").length>0}},_="clepit-marker-styles",j="\n/* Marker brush effect */\n.clepit-paragraph mark,\n.clepit-header mark,\n.clepit-list-item mark,\n.clepit-quote-text mark,\n.clepit-quote-caption mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0; /* create stacking context so ::before sits behind text, not page */\n white-space: pre-wrap; /* ensure leading/trailing spaces inside mark render */\n}\n.clepit-paragraph mark::before,\n.clepit-header mark::before,\n.clepit-list-item mark::before,\n.clepit-quote-text mark::before,\n.clepit-quote-caption mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n -webkit-mask-image: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z'/></svg>\");\n mask-image: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z'/></svg>\");\n -webkit-mask-size: 100% 100%;\n mask-size: 100% 100%;\n -webkit-mask-repeat: no-repeat;\n mask-repeat: no-repeat;\n background-color: var(--clepit-marker);\n z-index: -1; /* behind text but within mark's stacking context */\n}\n\n/* Output marker brush effect for <mark> */\n.clepit-output-paragraph mark,\n.clepit-output-header mark,\n.clepit-output-list li mark,\n.clepit-output-quote mark,\n.clepit-output-quote cite mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n.clepit-output-paragraph mark::before,\n.clepit-output-header mark::before,\n.clepit-output-list li mark::before,\n.clepit-output-quote mark::before,\n.clepit-output-quote cite mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n -webkit-mask-image: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z'/></svg>\");\n mask-image: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z'/></svg>\");\n -webkit-mask-size: 100% 100%;\n mask-size: 100% 100%;\n -webkit-mask-repeat: no-repeat;\n mask-repeat: no-repeat;\n background-color: var(--clepit-marker);\n z-index: -1;\n}\n\n/* Marker wrapper styling */\n.clepit-marker-wrapper {\n position: relative;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n color: inherit;\n}\n\n/* Marker stroke styling */\n.clepit-marker-stroke {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n z-index: -1;\n pointer-events: none;\n -webkit-mask-image: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z'/></svg>\");\n mask-image: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z'/></svg>\");\n -webkit-mask-size: 100% 100%;\n mask-size: 100% 100%;\n -webkit-mask-repeat: no-repeat;\n mask-repeat: no-repeat;\n background-color: var(--clepit-marker);\n}\n\n/* Toolbar button mark styling */\n.clepit-toolbar-button strong,\n.clepit-toolbar-button em,\n.clepit-toolbar-button u,\n.clepit-toolbar-button code,\n.clepit-toolbar-button mark {\n font-size: inherit;\n font-weight: inherit;\n font-style: inherit;\n text-decoration: inherit;\n background: transparent;\n padding: 0;\n border-radius: 0;\n font-family: inherit;\n}\n",z=class e{static{this.label="marker"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 21l6-2 9-9a2.828 2.828 0 0 0-4-4l-9 9-2 6z"/><path d="M14 7l3 3"/></svg>'}static{this.shortcut=v("M")}static apply(t,n,o){a.injectStyles(_,j);const i=document.createElement("span");i.classList.add("clepit-marker-wrapper");const r=document.createElement("span");r.classList.add("clepit-marker-stroke");const s=t.extractContents();i.appendChild(document.createTextNode(" ")),i.appendChild(s),i.appendChild(document.createTextNode(" ")),i.insertBefore(r,i.firstChild),t.insertNode(i),t.selectNodeContents(i),e.applyUserStyles(i,r,n,o);const l=i.closest('[contenteditable="true"]');l&&l.dispatchEvent(new Event("input",{bubbles:!0})),or.updateStateFromRange(t)}static remove(t){const n=e.findMarkerElement(t.commonAncestorContainer);if(n){const t=n.parentElement;if(t){const a=n.previousSibling,o=n.nextSibling,i=document.createDocumentFragment();Array.from(n.childNodes).forEach(e=>{e.nodeType===Node.ELEMENT_NODE&&e.classList?.contains("clepit-marker-stroke")||i.appendChild(e.cloneNode(!0))}),n.replaceWith(i),e.cleanupSpaces(t,a,o);const r=t.closest('[contenteditable="true"]');r&&r.dispatchEvent(new Event("input",{bubbles:!0}))}return}const a=t.cloneContents().querySelectorAll(".clepit-marker-wrapper");if(a.length>0){a.forEach(t=>{const n=t.parentElement;if(n){const a=t.previousSibling,o=t.nextSibling,i=document.createDocumentFragment();Array.from(t.childNodes).forEach(e=>{e.nodeType===Node.ELEMENT_NODE&&e.classList?.contains("clepit-marker-stroke")||i.appendChild(e.cloneNode(!0))}),t.replaceWith(i),e.cleanupSpaces(n,a,o)}});const n=t.commonAncestorContainer.closest('[contenteditable="true"]');return void(n&&n.dispatchEvent(new Event("input",{bubbles:!0})))}const o=e.findLegacyMarkElement(t.commonAncestorContainer);if(o){const e=o.parentElement;if(e){const t=o.textContent||"",n=document.createTextNode(t);e.insertBefore(n,o),e.removeChild(o);const a=e.closest('[contenteditable="true"]');a&&a.dispatchEvent(new Event("input",{bubbles:!0}))}}or.updateStateFromRange(t)}static cleanupSpaces(e,t,n){const a=Array.from(e.childNodes).filter(e=>e.nodeType===Node.TEXT_NODE);a.forEach((e,o)=>{let i=e.textContent||"";if(0===o&&t?.nodeType===Node.TEXT_NODE&&(t.textContent||"").endsWith(" ")&&i.startsWith(" ")&&(i=i.substring(1)),o===a.length-1&&n?.nodeType===Node.TEXT_NODE){const e=n.textContent||"";i.endsWith(" ")&&e.startsWith(" ")&&(i=i.substring(0,i.length-1))}e.textContent=i})}static isActive(t){if(t.collapsed)return!1;if(t.cloneContents().querySelectorAll(".clepit-marker-wrapper").length>0)return!0;if(e.findMarkerElement(t.commonAncestorContainer))return!0;const n=t.startContainer,a=t.endContainer;return!(n===t.commonAncestorContainer||!e.findMarkerElement(n))||(!(a===t.commonAncestorContainer||a===n||!e.findMarkerElement(a))||null!==e.findLegacyMarkElement(t.commonAncestorContainer))}static findMarkerElement(e){let t=e,n=0;for(;t&&n<10;){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if(e.classList?.contains("clepit-marker-wrapper"))return e;if(e.classList?.contains("clepit-block")||e.classList?.contains(a.classNames.editor.container))break}t=t.parentNode,n++}return null}static findLegacyMarkElement(e){let t=e,n=0;for(;t&&n<10;){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("MARK"===e.tagName)return e;if(e.classList?.contains("clepit-block")||e.classList?.contains(a.classNames.editor.container))break;if(0===n){const t=window.getComputedStyle(e);if("yellow"===t.backgroundColor||"rgb(255, 255, 0)"===t.backgroundColor)return e;if("yellow"===e.style.backgroundColor||"rgb(255, 255, 0)"===e.style.backgroundColor)return e}}t=t.parentNode,n++}return null}static applyUserStyles(t,n,o,i){o&&a.applyClassNames(t,o),i&&Object.entries(i).forEach(([e,n])=>{if(void 0!==n&&"background"!==e){const a=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);t.style.setProperty(a,String(n))}});const r=t.style.getPropertyValue("--marker-background")||t.getAttribute("data-marker-background");if(r){const t=e.createStrokeSVG(r);return void(n.style.background=t)}if(i?.background){const t=i.background;if(t){const a=e.createStrokeSVG(String(t));return void(n.style.background=a)}}const s=t.closest(`.${a.classNames.editor.content}, .${a.classNames.renderer.content}`);if(s){const t=window.getComputedStyle(s).getPropertyValue("--clepit-marker-background");if(t&&"initial"!==t&&"inherit"!==t){const a=e.createStrokeSVG(t.trim());return void(n.style.background=a)}}const l=t.closest(`.${a.classNames.block.content}`);if(!l)return;const c=l.style.background||l.style.backgroundColor||l.style.getPropertyValue("background-color");if(c&&"initial"!==c&&"inherit"!==c){const t=e.createStrokeSVG(c);return void(n.style.background=t)}const p=window.getComputedStyle(l).backgroundColor;if(p&&"rgba(0, 0, 0, 0)"!==p&&"transparent"!==p){const t=e.createStrokeSVG(p);n.style.background=t}}static createStrokeSVG(t){const n=e.colorToHex(t);return`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='${encodeURIComponent(n)}'/></svg>") no-repeat center / 100% 100%`}static colorToHex(e){if(e.startsWith("#"))return e;if(e.startsWith("rgb")){const t=e.match(/\d+/g);if(t&&t.length>=3)return`#${parseInt(t[0]).toString(16).padStart(2,"0")}${parseInt(t[1]).toString(16).padStart(2,"0")}${parseInt(t[2]).toString(16).padStart(2,"0")}`}return{blue:"#3742FA",cyan:"#7FDBDA",green:"#2ED573",lime:"#32FF7E",orange:"#FFA502",pink:"#FF6B9D",purple:"#A55EEA",red:"#FF4757",teal:"#006266",yellow:"#FFE047"}[e.toLowerCase()]||"#FFE047"}},O="clepit-inline-status-styles",H='\n/* Inline status — same visual language as the Alert block but inline. */\n.clepit-status {\n display: inline;\n padding: 2px 8px;\n border-radius: 4px;\n font-size: 0.9em;\n line-height: 1.5;\n vertical-align: baseline;\n}\n\n.clepit-status[data-status-variant="info"] {\n background: var(--clepit-primary-bg);\n color: var(--clepit-primary-hover);\n}\n\n.clepit-status[data-status-variant="success"] {\n background: var(--clepit-success-bg);\n color: var(--clepit-success);\n}\n\n.clepit-status[data-status-variant="warning"] {\n background: var(--clepit-warning-bg);\n color: var(--clepit-warning);\n}\n\n.clepit-status[data-status-variant="error"] {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n}\n\n.clepit-status[data-status-variant="plain"] {\n background: transparent;\n color: inherit;\n}\n\n/* Dialog variant picker — mirrors inline chip styling at rest, highlight on hover/selected. */\n.clepit-status-dialog-variants {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n margin-top: 4px;\n}\n\n.clepit-status-dialog-variant {\n appearance: none;\n -webkit-appearance: none;\n background: transparent;\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n padding: 6px 12px;\n cursor: pointer;\n font-family: inherit;\n font-size: 13px;\n color: var(--clepit-text);\n transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;\n}\n\n.clepit-status-dialog-variant:hover {\n border-color: transparent;\n}\n\n.clepit-status-dialog-variant--info:hover,\n.clepit-status-dialog-variant--info[data-selected="true"] {\n background: var(--clepit-primary-bg);\n color: var(--clepit-primary-hover);\n border-color: transparent;\n}\n\n.clepit-status-dialog-variant--success:hover,\n.clepit-status-dialog-variant--success[data-selected="true"] {\n background: var(--clepit-success-bg);\n color: var(--clepit-success);\n border-color: transparent;\n}\n\n.clepit-status-dialog-variant--warning:hover,\n.clepit-status-dialog-variant--warning[data-selected="true"] {\n background: var(--clepit-warning-bg);\n color: var(--clepit-warning);\n border-color: transparent;\n}\n\n.clepit-status-dialog-variant--error:hover,\n.clepit-status-dialog-variant--error[data-selected="true"] {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n border-color: transparent;\n}\n\n.clepit-status-dialog-variant--plain:hover,\n.clepit-status-dialog-variant--plain[data-selected="true"] {\n background: var(--clepit-surface);\n color: var(--clepit-text);\n border-color: transparent;\n}\n',P=["info","success","warning","error","plain"],R=class e{static{this.isOpen=!1}constructor(e){this.overlay=null,this.dialog=null,this.textInput=null,this.options=e,this.variant=e.variant}show(){this.overlay||e.isOpen||(a.injectStyles(A,L),e.isOpen=!0,this.createDialog(),this.bindEvents(),this.focusFirstInput())}hide(){if(!this.overlay)return;const t=this.overlay;"function"==typeof t.close&&t.open&&t.close(),t.remove(),this.overlay=null,this.dialog=null,this.textInput=null,e.isOpen=!1;const n=document.querySelector(".clepit-toolbar");n&&(n.style.display="flex")}createDialog(){this.overlay=B("dialog","clepit-dialog-overlay"),this.applyStyles(this.overlay,this.options.styles?.overlay),this.dialog=B("div","clepit-dialog"),this.applyStyles(this.dialog,this.options.styles?.container);const e=B("h3","clepit-dialog-title");e.textContent="Inline status",this.applyStyles(e,this.options.styles?.title),this.dialog.appendChild(e);const t=B("label","clepit-dialog-label");t.textContent="Label",this.applyStyles(t,this.options.styles?.label),this.dialog.appendChild(t),this.textInput=B("input","clepit-dialog-input"),this.textInput.type="text",this.textInput.value=this.options.text,this.textInput.placeholder="Status label",this.applyStyles(this.textInput,this.options.styles?.input),this.dialog.appendChild(this.textInput);const n=B("label","clepit-dialog-label");n.textContent="Variant",this.applyStyles(n,this.options.styles?.label),this.dialog.appendChild(n);const a=B("div","clepit-status-dialog-variants");for(const c of P){const e=B("button",`clepit-status-dialog-variant clepit-status-dialog-variant--${c}`);e.type="button",e.dataset.variant=c,e.textContent=c,e.dataset.selected=String(c===this.variant),e.addEventListener("click",()=>{this.variant=c;for(const e of Array.from(a.children))e.dataset.selected=String(e.dataset.variant===c)}),a.appendChild(e)}this.dialog.appendChild(a);const o=B("div","clepit-dialog-buttons");this.applyStyles(o,this.options.styles?.buttons);const i=B("button","clepit-dialog-button clepit-dialog-button--cancel");i.type="button",i.textContent="Cancel",i.addEventListener("click",()=>this.handleCancel()),this.applyStyles(i,this.options.styles?.cancelButton),o.appendChild(i);const r=B("button","clepit-dialog-button clepit-dialog-button--save");r.type="button",r.textContent="Apply",r.addEventListener("click",()=>this.handleConfirm()),this.applyStyles(r,this.options.styles?.saveButton),o.appendChild(r),this.dialog.appendChild(o),this.overlay.appendChild(this.dialog),document.body.appendChild(this.overlay);const s=this.overlay;"function"==typeof s.showModal?s.showModal():s.style.display="flex";const l=document.querySelector(".clepit-toolbar");l&&(l.style.display="none")}bindEvents(){if(!this.overlay||!this.dialog||!this.textInput)return;this.overlay.addEventListener("click",e=>{e.target===this.overlay&&this.handleCancel()});const e=e=>{"Escape"===e.key&&this.handleCancel(),"Enter"===e.key&&e.target===this.textInput&&(e.preventDefault(),this.handleConfirm())};document.addEventListener("keydown",e),this.dialog.dataset.keyHandlerRegistered="true",this.dialog.__keyHandler=e}focusFirstInput(){setTimeout(()=>this.textInput?.focus(),50)}handleConfirm(){this.textInput&&(this.options.onConfirm(this.textInput.value.trim(),this.variant),this.cleanupKeyHandler(),this.hide())}handleCancel(){this.options.onCancel(),this.cleanupKeyHandler(),this.hide()}cleanupKeyHandler(){if(!this.dialog)return;const e=this.dialog.__keyHandler;e&&document.removeEventListener("keydown",e)}applyStyles(e,t){if(t)for(const[n,a]of Object.entries(t))void 0!==a&&e.style.setProperty(n,String(a))}},F="clepit-status",V=class e{static{this.label="status"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="8" width="18" height="8" rx="4"/><circle cx="8" cy="12" r="1.25"/><circle cx="16" cy="12" r="1.25"/></svg>'}static apply(t,n,o){a.injectStyles(O,H);const i=t.toString().trim(),r=e.findStatusElement(t.commonAncestorContainer),s=r?r.textContent??i:i,l=r?e.readVariant(r):"info",c=t.cloneRange();new R({classNames:n,onCancel:()=>{const e=window.getSelection();e&&(e.removeAllRanges(),e.addRange(c))},onConfirm:(t,n)=>{try{const a=window.getSelection();if(!a)return;if(a.removeAllRanges(),a.addRange(c),!t.trim())return void e.remove(c);if(e.unwrap(c),t!==i){c.deleteContents();const e=document.createTextNode(t);c.insertNode(e),c.selectNode(e)}const o=document.createElement("span");o.className=(e=>`${F} ${F}--${e}`)(n),o.dataset.statusVariant=n;try{c.surroundContents(o)}catch{const e=c.extractContents();o.appendChild(e),c.insertNode(o)}const r=document.createRange();r.selectNodeContents(o),a.removeAllRanges(),a.addRange(r);const s=o.closest('[contenteditable="true"]');s&&s.dispatchEvent(new Event("input",{bubbles:!0}))}catch(a){console.error("Failed to apply inline status:",a)}},styles:o,text:s||"status",variant:l}).show(),or.updateStateFromRange(t)}static remove(t){e.unwrap(t),or.updateStateFromRange(t)}static isActive(t){return!!e.findStatusElement(t.commonAncestorContainer)||t.cloneContents().querySelectorAll(`.${F}`).length>0}static unwrap(t){const n=e.findStatusElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}return}const a=t.commonAncestorContainer;if(a.nodeType!==Node.ELEMENT_NODE)return;const o=a.querySelectorAll(`.${F}`);for(const e of Array.from(o)){if(!t.intersectsNode(e))continue;const n=e.parentElement;n&&(n.insertBefore(document.createTextNode(e.textContent||""),e),n.removeChild(e))}}static findStatusElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if(e.classList?.contains(F))return e}return t.parentNode?e.findStatusElement(t.parentNode):null}static readVariant(e){const t=e.dataset.statusVariant;if(t&&["info","success","warning","error"].includes(t))return t;for(const n of["info","success","warning","error"])if(e.classList.contains(`${F}--${n}`))return n;return"info"}},U=class e{static{this.label="strikethrough"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M16 4H9a3 3 0 0 0-2.83 4"/><path d="M14 12a4 4 0 0 1 0 8H6"/><line x1="4" x2="20" y1="12" y2="12"/></svg>'}static{this.shortcut=v("X")}static apply(e){a.injectStyles("clepit-strikethrough-styles",'\n/* Strikethrough inline formatting styles */\n.clepit-toolbar-button strong,\n.clepit-toolbar-button em,\n.clepit-toolbar-button u,\n.clepit-toolbar-button s,\n.clepit-toolbar-button del,\n.clepit-toolbar-button code,\n.clepit-toolbar-button mark {\n font-size: inherit;\n font-weight: inherit;\n font-style: inherit;\n text-decoration: inherit;\n background: transparent;\n padding: 0;\n border-radius: 0;\n font-family: inherit;\n}\n\n/* Keep strikethrough visual hint without changing size */\n.clepit-toolbar-button[data-tool="strikethrough"] {\n text-decoration: line-through;\n}\n');const t=document.createElement("s");e.surroundContents(t),or.updateStateFromRange(e)}static remove(t){const n=e.findStrikethroughElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}}else{const e=t.commonAncestorContainer;if(e.nodeType===Node.ELEMENT_NODE){const n=e.querySelectorAll('s, del, [style*="text-decoration: line-through"], [style*="text-decoration:line-through"]');for(const e of n)if(t.intersectsNode(e)){const t=e.parentElement;t&&(t.insertBefore(document.createTextNode(e.textContent||""),e),t.removeChild(e))}}}or.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findStrikethroughElement(n)||t.cloneContents().querySelectorAll('s, del, [style*="text-decoration: line-through"], [style*="text-decoration:line-through"]').length>0}static findStrikethroughElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("S"===e.tagName||"DEL"===e.tagName)return e;if(window.getComputedStyle(e).textDecoration.includes("line-through"))return e;if(e.style.textDecoration.includes("line-through"))return e}return t.parentNode?e.findStrikethroughElement(t.parentNode):null}},W="clepit-tooltip-styles",K=`\n/* Tooltip styles - border bottom instead of text-decoration to avoid underline tool conflict */\n.${a.classNames.block.tooltip} {\n border-bottom: 1px dotted var(--clepit-text-subtle);\n cursor: help;\n}\n\n.${a.classNames.block.tooltip}:hover {\n border-bottom: 1px dotted var(--clepit-text-muted);\n}\n`,G=class{constructor(e){this.overlay=null,this.dialog=null,this.inputText=null,this.inputTooltip=null,this.handleKeyDown=e=>{"Escape"===e.key&&(this.options.onCancel(),this.hide())},this.handleInputKeyDown=e=>{if("Enter"===e.key){const e=this.inputText?.value.trim()||"",t=this.inputTooltip?.value.trim()||"";this.options.onConfirm(e,t),this.hide()}},this.options=e}show(){this.overlay||(a.injectStyles(A,L),document.querySelectorAll(".clepit-dialog-overlay").forEach(e=>{e!==this.overlay&&e.remove()}),this.createDialog(),this.bindEvents(),this.focusFirstInput())}hide(){if(!this.overlay)return;const e=this.overlay;"function"==typeof e.close&&e.open&&e.close(),this.destroy()}createDialog(){this.overlay=B("dialog","clepit-dialog-overlay"),this.applyStyles(this.overlay,this.options.styles?.overlay),this.applyClassNames(this.overlay,this.options.classNames?.overlay),this.dialog=B("div","clepit-dialog"),this.applyStyles(this.dialog,this.options.styles?.container),this.applyClassNames(this.dialog,this.options.classNames?.container);const e=B("h3","clepit-dialog-title");e.textContent="Insert Tooltip",this.applyStyles(e,this.options.styles?.title),this.applyClassNames(e,this.options.classNames?.title);const t=this.createInputGroup("Text",this.options.text,"text");this.inputText=t.querySelector("input");const n=this.createInputGroup("Tooltip",this.options.tooltip,"text");this.inputTooltip=n.querySelector("input");const a=this.createButtonGroup();this.dialog.appendChild(e),this.dialog.appendChild(t),this.dialog.appendChild(n),this.dialog.appendChild(a),this.overlay.appendChild(this.dialog),document.body.appendChild(this.overlay);const o=this.overlay;"function"==typeof o.showModal?o.showModal():o.style.display="flex",this.dialog?.classList.remove("clepit-dialog--hidden");const i=document.querySelector(".clepit-toolbar");i&&(i.style.display="none"),this.options.onShow?.()}createInputGroup(e,t,n){const a=B("div","clepit-dialog-group");this.applyStyles(a,this.options.styles?.group),this.applyClassNames(a,this.options.classNames?.group);const o=B("label","clepit-dialog-label");o.textContent=e,this.applyStyles(o,this.options.styles?.label),this.applyClassNames(o,this.options.classNames?.label);const i=B("input","clepit-dialog-input");return i.type="url"===n?"url":"text",i.value=t,i.placeholder="Tooltip"===e?"Tooltip text":"Text",this.applyStyles(i,this.options.styles?.input),this.applyClassNames(i,this.options.classNames?.input),a.appendChild(o),a.appendChild(i),a}createButtonGroup(){const e=B("div","clepit-dialog-buttons");this.applyStyles(e,this.options.styles?.buttons),this.applyClassNames(e,this.options.classNames?.buttons);const t=B("button","clepit-dialog-button clepit-dialog-button--cancel");t.textContent="Cancel",t.type="button",this.applyStyles(t,this.options.styles?.cancelButton),this.applyClassNames(t,this.options.classNames?.cancelButton);const n=B("button","clepit-dialog-button clepit-dialog-button--save");return n.textContent="Apply",n.type="button",this.applyStyles(n,this.options.styles?.saveButton),this.applyClassNames(n,this.options.classNames?.saveButton),t.addEventListener("click",()=>{this.options.onCancel(),this.hide()}),n.addEventListener("click",()=>{this.options.onConfirm(this.inputText?.value.trim()||"",this.inputTooltip?.value.trim()||""),this.hide()}),e.appendChild(t),e.appendChild(n),e}bindEvents(){this.overlay&&(this.overlay.addEventListener("click",e=>{e.target===this.overlay&&(this.options.onCancel(),this.hide())}),document.addEventListener("keydown",this.handleKeyDown),this.inputText&&this.inputText.addEventListener("keydown",this.handleInputKeyDown),this.inputTooltip&&this.inputTooltip.addEventListener("keydown",this.handleInputKeyDown))}focusFirstInput(){setTimeout(()=>{this.inputTooltip&&(this.inputTooltip.focus(),this.inputTooltip.select())},100)}applyStyles(e,t){t&&Object.entries(t).forEach(([t,n])=>{if(void 0!==n){const a=t.replace(/([A-Z])/g,"-$1").toLowerCase();e.style.setProperty(a,String(n))}})}applyClassNames(e,t){t&&e.classList.add(t)}destroy(){if(document.removeEventListener("keydown",this.handleKeyDown),this.overlay){this.overlay.remove(),this.overlay=null,this.dialog=null,this.inputText=null,this.inputTooltip=null;const e=document.querySelector(".clepit-toolbar");e&&(e.style.display="flex"),this.options.onHide&&this.options.onHide()}}};function J(e,t,n="below",o,i){let r=null,s=null;const l=()=>{r&&(r.style.opacity="0",setTimeout(()=>{r&&r.parentElement&&r.parentElement.removeChild(r),r=null,s&&(s.disconnect(),s=null)},120))};e.addEventListener("mouseenter",()=>{if(r)return;a.injectStyles("clepit-inline-tooltip-styles","\n/* Inline Tooltip Container */\n.clepit-inline-tooltip {\n position: fixed;\n z-index: 9999;\n pointer-events: none;\n opacity: 0;\n transition: opacity 0.2s ease-in-out;\n}\n\n/* Tooltip Content */\n.clepit-inline-tooltip-content {\n background: var(--clepit-text);\n color: var(--clepit-bg);\n padding: 6px 10px;\n border-radius: 6px;\n font-size: 12px;\n font-weight: 500;\n white-space: nowrap;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);\n transform: translateY(8px);\n transition: transform 0.2s ease-in-out;\n position: relative;\n}\n\n/* Tooltip Arrow */\n.clepit-inline-tooltip-arrow {\n position: absolute;\n width: 0;\n height: 0;\n}\n\n/* Arrow pointing down (when tooltip is above target) */\n.clepit-inline-tooltip-arrow--above {\n top: 100%;\n left: 50%;\n transform: translateX(-50%);\n border-left: 6px solid transparent;\n border-right: 6px solid transparent;\n border-top: 6px solid var(--clepit-text);\n}\n\n/* Arrow pointing up (when tooltip is below target) */\n.clepit-inline-tooltip-arrow--below {\n bottom: 100%;\n left: 50%;\n transform: translateX(-50%);\n border-left: 6px solid transparent;\n border-right: 6px solid transparent;\n border-bottom: 6px solid var(--clepit-text);\n}\n"),r=document.createElement("div"),r.className=`clepit-inline-tooltip ${o?.container||""}`,a.applyStyling(r,{styles:i?.container});const c=document.createElement("div");c.className=`clepit-inline-tooltip-content ${o?.content||""}`,c.textContent=t,a.applyStyling(c,{styles:i?.content});const p=document.createElement("div");p.className=`clepit-inline-tooltip-arrow clepit-inline-tooltip-arrow--${n} ${o?.arrow||""}`,a.applyStyling(p,{styles:i?.arrow}),c.appendChild(p),r.appendChild(c),document.body.appendChild(r);const d=e.getBoundingClientRect(),u=c.offsetWidth,m=c.offsetHeight;let h,g=d.left+d.width/2-u/2;g=Math.max(8,Math.min(g,window.innerWidth-u-8));let b=n;"below"===n?(h=d.bottom+6+2,h+m>window.innerHeight-8&&(h=d.top-m-6-2,b="above")):(h=d.top-m-6-2,h<8&&(h=d.bottom+6+2,b="below")),p.className=`clepit-inline-tooltip-arrow clepit-inline-tooltip-arrow--${b} ${o?.arrow||""}`,r.style.left=`${g}px`,r.style.top=`${Math.max(8,Math.min(h,window.innerHeight-m-8))}px`,requestAnimationFrame(()=>{r&&(r.style.opacity="1",c.style.transform="translateY(0)")}),s||(s=new MutationObserver(()=>{document.body.contains(e)&&e.isConnected||(l(),s&&(s.disconnect(),s=null))}),s.observe(document.body,{childList:!0,subtree:!0}))}),e.addEventListener("mouseleave",l)}var X=class e{static{this.label="tooltip"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 7l-2.5 3H5a2 2 0 0 0-2 2v4a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-4a2 2 0 0 0-2-2h-4.5L12 7z"/><path d="M8 13h8"/><path d="M8 16h6"/></svg>'}static{this.shortcut=v("T")}static apply(t,n,o){a.injectStyles(W,K);const i=t.toString(),r=t.cloneRange();let s="",l=i;const c=e.findTooltipSpan(t.commonAncestorContainer);c&&(s=c.getAttribute("data-tooltip")||"",l=c.textContent||""),new G({classNames:n.classNames,onCancel:()=>{const e=window.getSelection();e&&(e.removeAllRanges(),e.addRange(r))},onConfirm:(t,i)=>{const s=window.getSelection();if(!s)return;if(s.removeAllRanges(),s.addRange(r),!i.trim())return e.remove(r),void(t!==l&&(r.deleteContents(),r.insertNode(document.createTextNode(t))));if(c){const e=c.parentElement;if(e){const t=document.createTextNode(c.textContent||"");e.insertBefore(t,c),e.removeChild(c),r.selectNode(t)}}if(t!==l){r.deleteContents();const e=document.createTextNode(t);r.insertNode(e),r.selectNode(e)}const p=a.createStyledElement("span",a.classNames.block.tooltip);p.setAttribute("data-tooltip",i),o.classNames&&a.applyClassNames(p,o.classNames),o.styles&&Object.entries(o.styles).forEach(([e,t])=>{if(void 0!==t){const n=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);p.style.setProperty(n,String(t))}});try{r.surroundContents(p)}catch{const e=r.extractContents();p.appendChild(e),r.insertNode(p)}t!==l&&p.textContent!==t&&(p.textContent=t),J(p,i,"above",n.classNames,n.styles);const d=p.closest('[contenteditable="true"]');d&&d.dispatchEvent(new Event("input",{bubbles:!0}))},styles:n.styles,text:l,tooltip:s}).show(),or.updateStateFromRange(t)}static remove(t){const n=t.commonAncestorContainer,a=e.findTooltipSpan(n);if(a){const e=a.parentElement;if(!e)return;e.insertBefore(document.createTextNode(a.textContent||""),a),e.removeChild(a),t.selectNode(e)}or.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findTooltipSpan(n)||t.cloneContents().querySelectorAll(`span.${a.classNames.block.tooltip}`).length>0}static initializeElements(e,t){e.querySelectorAll(`span.${a.classNames.block.tooltip}`).forEach(e=>{if(e instanceof HTMLElement&&(t.classNames&&a.applyClassNames(e,t.classNames),t.styles&&Object.entries(t.styles).forEach(([t,n])=>{if(void 0!==n){const a=t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);e.style.setProperty(a,String(n))}}),!e.hasAttribute("data-tooltip-initialized"))){const t=e.getAttribute("data-tooltip");t&&(J(e,t,"above"),e.setAttribute("data-tooltip-initialized","true"))}})}static findTooltipSpan(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if(e.classList.contains(a.classNames.block.tooltip))return e}return t.parentNode?e.findTooltipSpan(t.parentNode):null}},Z=class e{static{this.label="underline"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 4v7a6 6 0 0 0 12 0V4"/><path d="M4 20h16"/></svg>'}static{this.shortcut=k()}static apply(e){a.injectStyles("clepit-underline-styles",'\n/* Underline inline formatting styles */\n.clepit-toolbar-button strong,\n.clepit-toolbar-button em,\n.clepit-toolbar-button u,\n.clepit-toolbar-button code,\n.clepit-toolbar-button mark {\n font-size: inherit;\n font-weight: inherit;\n font-style: inherit;\n text-decoration: inherit;\n background: transparent;\n padding: 0;\n border-radius: 0;\n font-family: inherit;\n}\n\n/* Keep underline visual hint without changing size */\n.clepit-toolbar-button[data-tool="underline"] {\n text-decoration: underline;\n}\n');const t=document.createElement("u");e.surroundContents(t),or.updateStateFromRange(e)}static remove(t){const n=e.findUnderlineElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}}else{const e=t.commonAncestorContainer;if(e.nodeType===Node.ELEMENT_NODE){const n=e.querySelectorAll("u");for(const e of n)if(t.intersectsNode(e)){const t=e.parentElement;t&&(t.insertBefore(document.createTextNode(e.textContent||""),e),t.removeChild(e))}}}or.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findUnderlineElement(n)||t.cloneContents().querySelectorAll('u, [style*="text-decoration: underline"], [style*="text-decoration:underline"]').length>0}static findUnderlineElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("U"===e.tagName)return e;if(window.getComputedStyle(e).textDecoration.includes("underline"))return e;if(e.style.textDecoration.includes("underline"))return e}return t.parentNode?e.findUnderlineElement(t.parentNode):null}},Y=["alert","audio","checklist","code","collapsible","collection","columns","date","delimiter","doc_card","embed","file","glance","header","image","latex","list","mermaid","openapi","paragraph","quote","sketch","table","toc","updates","video"],Q=["improve","shorten","lengthen","simplify","fix_grammar"],ee=()=>[w,E,Z,U,C,z,V,D,X],te="inline-toolbar",ne=class e{static{this.eventListenersMap=new WeakMap}static{this.hideTimeoutMap=new Map}static{this.tooltipAnchorSeq=0}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap.get(t)||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap.set(t,i)}static create(t){const n=l.getState().getInstance(t);if(!n)return console.error("InlineToolbar::create: Instance not found for containerId:",t);const o=document.getElementById(t);if(!o)return console.error("InlineToolbar::create: Container not found for containerId:",t);e.eventListenersMap.has(o)||e.eventListenersMap.set(o,[]),a.injectStyles("clepit-inline-toolbar-styles","\n/* Inline Toolbar */\n.clepit-toolbar {\n position: absolute;\n z-index: 1002;\n background: var(--clepit-toolbar-bg, var(--clepit-bg));\n border: var(--clepit-toolbar-border, 1px solid var(--clepit-border));\n border-radius: 8px;\n padding: 8px;\n box-shadow: var(--clepit-toolbar-shadow, 0 2px 8px rgba(0, 0, 0, 0.1));\n backdrop-filter: blur(8px);\n display: none;\n transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);\n white-space: nowrap;\n will-change: transform;\n}\n\n.clepit-toolbar--layout {\n display: flex;\n flex-direction: row;\n gap: 0px;\n align-items: center;\n}\n\n.clepit-toolbar--hidden {\n display: none !important;\n}\n\n.clepit-toolbar--visible {\n display: flex !important;\n transform: translateY(0) scale(1) !important;\n}\n\n@keyframes toolbarFadeIn {\n from {\n opacity: 0;\n transform: translateY(-10px) scale(0.95);\n }\n to {\n opacity: 1;\n transform: translateY(0) scale(1);\n }\n}\n\n.clepit-toolbar-button {\n width: 24px;\n height: 24px;\n border: none;\n border-radius: 4px;\n background: transparent;\n color: var(--clepit-toolbar-color, var(--clepit-text));\n font-size: 12px;\n font-weight: bold;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);\n position: relative;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;\n line-height: 1;\n /* Ensure all content inside buttons inherits the same font size and styling */\n text-rendering: optimizeLegibility;\n will-change: transform, background-color, color;\n}\n\n/* Normalize SVG icon sizing in toolbar buttons */\n.clepit-toolbar-button svg {\n width: 14px;\n height: 14px;\n display: block;\n stroke: currentColor;\n}\n\n.clepit-toolbar-button:hover {\n background: var(--clepit-toolbar-hover-bg, var(--clepit-selection-bg));\n color: var(--clepit-toolbar-hover-color, var(--clepit-text));\n transform: scale(1.05);\n}\n\n.clepit-toolbar-button:active {\n transform: scale(0.95);\n transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n.clepit-toolbar-button.active {\n background: var(--clepit-toolbar-active-bg, var(--clepit-primary-bg));\n color: var(--clepit-toolbar-active-color, var(--clepit-primary));\n font-weight: bold;\n}\n\n/* Ensure consistent base font size for character-based icons */\n.clepit-toolbar-button { font-size: 12px; }\n\n/* Tooltip styles */\n/* Anchored to its own button and shown by :hover / :focus-visible, so no\n * JavaScript measures or centres it. :focus-visible is not decoration: the old\n * mouseenter-only version was invisible to a keyboard user.\n *\n * Guarded by @supports — anchor positioning is Baseline 2026 at ~91%. Without\n * it the tooltip simply never shows, which is what it already did before this\n * change for anyone not using a mouse. */\n.clepit-toolbar-tooltip {\n position: absolute;\n display: none;\n z-index: 9999;\n pointer-events: none;\n}\n\n@supports (anchor-name: --a) {\n .clepit-toolbar-tooltip {\n position: fixed;\n position-area: top;\n margin-block-end: 8px;\n justify-self: anchor-center;\n opacity: 0;\n transform: translateY(8px);\n transition:\n opacity 0.15s ease-in-out,\n transform 0.15s ease-in-out,\n display 0.15s allow-discrete;\n }\n\n .clepit-toolbar-button:hover + .clepit-toolbar-tooltip,\n .clepit-toolbar-button:focus-visible + .clepit-toolbar-tooltip,\n .clepit-toolbar-button:focus-visible + .clepit-toolbar-tooltip {\n display: block;\n opacity: 1;\n transform: translateY(0);\n }\n\n @starting-style {\n .clepit-toolbar-button:hover + .clepit-toolbar-tooltip,\n .clepit-toolbar-button:focus-visible + .clepit-toolbar-tooltip {\n opacity: 0;\n transform: translateY(8px);\n }\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .clepit-toolbar-tooltip {\n transition-duration: 0s;\n }\n}\n\n.clepit-toolbar-tooltip-content {\n white-space: nowrap;\n font-size: 12px;\n font-weight: 500;\n color: var(--clepit-bg);\n background-color: var(--clepit-text);\n padding: 6px 10px;\n border-radius: 6px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);\n transition: transform 0.2s ease-in-out;\n}\n\n.clepit-toolbar-tooltip-arrow {\n position: absolute;\n top: 100%;\n left: 50%;\n margin-left: -4px;\n width: 0;\n height: 0;\n border-left: 4px solid transparent;\n border-right: 4px solid transparent;\n border-top: 4px solid var(--clepit-text);\n}\n\n.clepit-toolbar-tooltip--hidden {\n display: none;\n transform: translateY(8px);\n}\n\n.clepit-toolbar-tooltip--visible {\n display: block;\n transform: translateY(0);\n}\n\n.clepit-toolbar-tooltip--fade-out {\n transform: translateY(5px);\n}\n\n/* Toolbar positioning and animation classes */\n.clepit-toolbar--positioned {\n position: absolute;\n}\n\n.clepit-toolbar--measurement {\n display: flex;\n visibility: hidden;\n opacity: 0;\n position: absolute;\n left: -9999px;\n top: -9999px;\n}\n\n.clepit-toolbar--show-animation {\n display: flex;\n visibility: visible;\n transform: translateY(-10px) scale(0.95);\n transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n.clepit-toolbar--show-animation.clepit-toolbar--visible {\n transform: translateY(0) scale(1);\n}\n\n.clepit-toolbar--position-animation {\n transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), top 0.3s cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n.clepit-toolbar--hide-animation {\n transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);\n transform: translateY(-5px) scale(0.98);\n}\n\n/* Rewrite menu — the sparkle-wand's action list, anchored under the toolbar */\n.clepit-toolbar-rewrite-menu {\n position: absolute;\n top: 100%;\n right: 0;\n margin-top: 4px;\n flex-direction: column;\n min-width: 160px;\n padding: 4px;\n border-radius: var(--clepit-radius-sm, 6px);\n background: var(--clepit-surface, #fff);\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);\n z-index: 2;\n}\n\n.clepit-toolbar-rewrite-item {\n appearance: none;\n border: 0;\n background: transparent;\n color: var(--clepit-text-primary, inherit);\n font: inherit;\n text-align: start;\n padding: 6px 10px;\n border-radius: var(--clepit-radius-xs, 4px);\n cursor: pointer;\n}\n\n.clepit-toolbar-rewrite-item:hover,\n.clepit-toolbar-rewrite-item:focus-visible {\n background: var(--clepit-surface-hover, rgba(0, 0, 0, 0.06));\n}\n\n/* The wand stays put while a rewrite is in flight, so the toolbar does not\n reflow under the pointer mid-request. */\n.clepit-toolbar-button.busy {\n opacity: 0.5;\n pointer-events: none;\n}\n\n/* Responsive */\n@media (max-width: 768px) {\n .clepit-toolbar {\n flex-wrap: wrap;\n max-width: 200px;\n }\n}\n");const i=B("div","clepit-toolbar");i.id=`${t}-${te}`,i.classList.add("clepit-toolbar--hidden","clepit-toolbar--layout"),a.applyStyling(i,{classNames:n.config.classNames?.inlineToolbar?.container,styles:n.config.styles?.inlineToolbar?.container}),o.appendChild(i)}static repaint(t,n){const o=l.getState().getInstance(t);if(!o)return console.error("InlineToolbar::repaint: Instance not found for containerId:",t);if(!e.getElementFromContainerId(t))return console.error("InlineToolbar::repaint: Toolbar not found for containerId:",t);e.clearButtons(t);const i=((n.commonAncestorContainer.nodeType===Node.ELEMENT_NODE?n.commonAncestorContainer:n.commonAncestorContainer.parentElement)?.closest(`.${a.classNames.block.container}`))?.getAttribute("data-tool");e.getFilteredTools(i).forEach(a=>e.addButton(t,a,n)),o.config.onInlineRewrite&&e.addRewriteButton(t,n);const r=n.getBoundingClientRect(),s=document.getElementById(o.config.containerId)?.getBoundingClientRect();if(!s)return;const c=((e=!1)=>({height:40,width:24*(ee().length+(e?1:0))+16}))(Boolean(o.config.onInlineRewrite)),p=r.left-s.left+r.width/2-c.width/2;let d=r.top-s.top-c.height-8;d<0&&(d=r.bottom-s.top+8),e.show(o.config.containerId,p,d)}static addRewriteButton(t,n){const o=l.getState().getInstance(t),i=o?.config.onInlineRewrite;if(!o||!i)return;const r=e.getElementFromContainerId(t),s=document.getElementById(t);if(!r||!s)return;const c=B("button","clepit-toolbar-button",{type:"button"});c.innerHTML='<svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor" aria-hidden="true"><path d="M12 2l1.6 4.4L18 8l-4.4 1.6L12 14l-1.6-4.4L6 8l4.4-1.6L12 2zm6 10l.9 2.5L21 15l-2.1.8L18 18l-.9-2.2L15 15l2.1-.5L18 12zM6 13l1.1 3L10 17l-2.9 1L6 21l-1.1-3L2 17l2.9-1L6 13z"/></svg>',c.setAttribute("data-tool","rewrite"),a.applyStyling(c,{classNames:o.config.classNames?.inlineToolbar?.button,styles:o.config.styles?.inlineToolbar?.button});const p=B("div","clepit-toolbar-rewrite-menu");p.style.display="none",p.setAttribute("data-rewrite-menu","true");for(const a of Q){const t=B("button","clepit-toolbar-rewrite-item",{type:"button"});t.textContent=o.config.inlineRewriteLabels?.[a]??a,t.setAttribute("data-rewrite-action",a),e.addEventListener(s,t,"mousedown",e=>e.preventDefault()),e.addEventListener(s,t,"click",()=>{p.style.display="none";const e=window.getSelection(),t=e&&e.rangeCount>0?e.getRangeAt(0):null,o=t&&!t.collapsed?t:n,r=o.toString();r.trim()&&(c.classList.add("busy"),i(r,a).then(e=>{e&&(o.deleteContents(),o.insertNode(document.createTextNode(e)),s.dispatchEvent(new Event("input",{bubbles:!0})))}).catch(()=>{}).finally(()=>c.classList.remove("busy")))}),p.appendChild(t)}e.addEventListener(s,c,"mousedown",e=>e.preventDefault()),e.addEventListener(s,c,"click",()=>{p.style.display="none"===p.style.display?"flex":"none"}),r.appendChild(c),e.createTooltip(r,c,"rewrite"),r.appendChild(p)}static addButton(t,n,o){const i=l.getState().getInstance(t);if(!i)return console.error("InlineToolbar::addButton: Instance not found for containerId:",t);const r=e.getElementFromContainerId(t);if(!r)return console.error("InlineToolbar::addButton: Toolbar not found for containerId:",t);const s=B("button","clepit-toolbar-button",{type:"button"});s.innerHTML=n.icon,a.applyStyling(s,{classNames:i.config.classNames?.inlineToolbar?.button,styles:i.config.styles?.inlineToolbar?.button}),n.isActive(o)&&s.classList.add("active"),s.setAttribute("data-tool",n.label.toLowerCase());const c=document.getElementById(t);c&&(e.addEventListener(c,s,"mousedown",e=>e.preventDefault()),e.addEventListener(c,s,"click",()=>{try{const e=window.getSelection(),t=e&&e.rangeCount>0?e.getRangeAt(0):null,a=t&&!t.collapsed?t:o;if(a&&n.isActive(a))n.remove(a),s.classList.remove("active");else if(a){switch(n.label){case"italic":E.apply(a);break;case"bold":w.apply(a);break;case"underline":Z.apply(a);break;case"strikethrough":U.apply(a);break;case"inlineCode":C.apply(a,i.config.classNames?.blocks?.["inline-code"],i.config.styles?.blocks?.["inline-code"]);break;case"marker":z.apply(a,i.config.classNames?.blocks?.marker,i.config.styles?.blocks?.marker);break;case"status":V.apply(a,i.config.classNames?.dialogs,i.config.styles?.dialogs);break;case"link":D.apply(a,i.config.classNames?.dialogs,i.config.styles?.dialogs);break;case"tooltip":X.apply(a,{classNames:i.config.classNames?.tooltips,styles:i.config.styles?.tooltips},{classNames:i.config.classNames?.blocks?.tooltip,styles:i.config.styles?.blocks?.tooltip})}s.classList.add("active")}}catch(e){console.warn("Error applying inline tool:",e)}})),r.appendChild(s),e.createTooltip(r,s,n.label)}static createTooltip(t,n,a){const o=B("div","clepit-toolbar-tooltip clepit-toolbar-tooltip--hidden"),i=B("div","clepit-toolbar-tooltip-content");i.textContent=a;const r=B("div","clepit-toolbar-tooltip-arrow");i.appendChild(r),o.appendChild(i),n.insertAdjacentElement("afterend",o);const s="--clepit-inline-tool-"+e.tooltipAnchorSeq++;n.style.setProperty("anchor-name",s),o.style.setProperty("position-anchor",s),o.classList.remove("clepit-toolbar-tooltip--hidden")}static clearButtons(t){const n=e.getElementFromContainerId(t);if(!n)return console.error("InlineToolbar::clearButtons: Toolbar not found for containerId:",t);n.querySelectorAll(".clepit-toolbar-button").forEach(e=>e.remove()),n.querySelectorAll(".clepit-toolbar-tooltip").forEach(e=>e.remove())}static show(t,n,a){const o=e.getElementFromContainerId(t);if(!o)return console.error("InlineToolbar::show: Toolbar not found for containerId:",t);if(e.cancelPendingHide(t),o.classList.remove("clepit-toolbar--hidden"),o.classList.add("clepit-toolbar--visible"),o.classList.contains("clepit-toolbar--visible")){const e=parseFloat(o.style.left)||0,t=parseFloat(o.style.top)||0;(Math.abs(e-n)>1||Math.abs(t-a)>1)&&o.classList.add("clepit-toolbar--position-animation")}else o.classList.add("clepit-toolbar--show-animation");o.style.left=`${n}px`,o.style.top=`${a}px`,requestAnimationFrame(()=>{o.classList.add("clepit-toolbar--visible")})}static hide(t){const n=e.getElementFromContainerId(t);if(n)if(e.cancelPendingHide(t),n.classList.contains("clepit-toolbar--visible")){n.classList.add("clepit-toolbar--hide-animation");const a=setTimeout(()=>{n.classList.remove("clepit-toolbar--visible","clepit-toolbar--hide-animation"),n.classList.add("clepit-toolbar--hidden"),e.hideTimeoutMap.delete(t)},200);e.hideTimeoutMap.set(t,a)}else n.classList.remove("clepit-toolbar--visible"),n.classList.add("clepit-toolbar--hidden")}static cancelPendingHide(t){const n=e.hideTimeoutMap.get(t);void 0!==n&&(clearTimeout(n),e.hideTimeoutMap.delete(t))}static getElementFromContainerId(e){const t=document.querySelector(`#${e}`);return t?t.querySelector(`#${t.id}-${te}`):(console.error("InlineToolbar::getElementFromContainerId: Container not found for containerId:",e),null)}static getFilteredTools(e){return"header"===e?ee().filter(e=>"bold"!==e.label):ee()}static destroy(t){e.cancelPendingHide(t);const n=document.querySelector(`#${t}`);if(!n)return console.warn("InlineToolbar::destroy: Container not found for containerId:",t);const a=e.eventListenersMap.get(n);a&&(a.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap.delete(n));const o=n.querySelector(`#${t}-${te}`);if(!o)return console.warn("InlineToolbar::destroy: Toolbar not found for containerId:",t);o.remove()}};function ae(e){const t=e.toLowerCase();return[".jpg",".jpeg",".png",".gif",".webp",".svg",".bmp",".tiff",".ico"].some(e=>t.includes(e))||t.includes("data:image/")||t.includes("blob:")}function oe(e){const t=e.toLowerCase();return[".mp4",".webm",".ogg",".mov",".avi",".mkv",".flv",".wmv",".m4v"].some(e=>t.includes(e))||t.includes("data:video/")||t.includes("blob:")}function ie(e){const t=e.toLowerCase();return t.includes("youtube.com")||t.includes("youtu.be")}function re(e){return e.toLowerCase().includes("vimeo.com")}function se(e){const t=e.trim();if(!function(e){try{return new URL(e),!0}catch{return!1}}(t))return{isImage:!1,isUrl:!1,isVideo:!1,isVimeo:!1,isYouTube:!1,url:t};const n=ie(t),a=re(t);return{isImage:ae(t),isUrl:!0,isVideo:oe(t)||n||a,isVimeo:a,isYouTube:n,url:t}}var le=class e{static addListeners(t){const n=document.getElementById(t);if(!n)return console.error("EventManager::addListeners: Container not found for containerId:",t);document.addEventListener("selectionchange",e.handleSelectionChange),document.addEventListener("paste",e.handlePaste),n.addEventListener("click",e.handleClick)}static removeListeners(t){const n=document.getElementById(t);if(!n)return console.error("EventManager::removeListeners: Container not found for containerId:",t);document.removeEventListener("selectionchange",e.handleSelectionChange),document.removeEventListener("paste",e.handlePaste),n.removeEventListener("click",e.handleClick)}static getInstanceAndTargetFromRange(e){const t=e.commonAncestorContainer,n=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement;if(!n)return null;const o=n.closest(`.${a.classNames.editor.content}`);if(!o)return null;const i=o.getAttribute("data-container-id");if(!i)return null;const r=l.getState().getInstance(i);return r?{instance:r,target:n}:null}static handleClick(e){const t=e.currentTarget,n=e.target,o=n.closest(`.${a.classNames.block.link}`);if(o){const e=document.createRange();e.selectNodeContents(o);const n=l.getState().getInstance(t.id);return void(n&&D.apply(e,n.config.classNames?.dialogs,n.config.styles?.dialogs))}const i=n.closest(`.${a.classNames.block.tooltip}`);if(i){const e=document.createRange();e.selectNodeContents(i);const n=l.getState().getInstance(t.id);return void(n&&X.apply(e,{classNames:n.config.classNames?.tooltips,styles:n.config.styles?.tooltips},{classNames:n.config.classNames?.blocks?.tooltip,styles:n.config.styles?.blocks?.tooltip}))}}static handleSelectionChange(){const t=window.getSelection();if(!t||0===t.rangeCount)return;const n=t.getRangeAt(0),a=e.getInstanceAndTargetFromRange(n);if(!a)return;if("edit"!==a.instance.currentView){try{ne.hide(a.instance.config.containerId)}catch{}return}if(null!==document.querySelector(".clepit-dialog-overlay"))return;const o=t?.toString().trim();if(o&&o.length>0||t&&t.rangeCount>0&&!t.getRangeAt(0).collapsed)try{ne.repaint(a.instance.config.containerId,n)}catch{}else try{ne.hide(a.instance.config.containerId)}catch{}}static handlePaste(e){e.preventDefault();const t=e.clipboardData;if(!t)return;const n=t.getData("text/plain");if(!n)return;const o=se(n);if(!o.isUrl)return;const i=document.activeElement;if(!i)return;const r=i.closest(`.${a.classNames.block.container}`);if(!r)return;const s=r.closest(`.${a.classNames.editor.container}`);if(!s)return;const l=r.getAttribute("data-id"),c=or.getBlockIndex(s.id,l);if(-1===c)return;const p=or.getTool(r.getAttribute("data-tool"));if(!p)return;const d=p.input.isEmpty(r);if(o.isImage){const e={data:{alignment:"center",alt:"Image",caption:"",url:o.url},type:"image"};d?or.replaceBlock(s.id,c,e):or.insertBlock(e,s.id,c+1)}else if(o.isVideo){let e=o.url;o.isYouTube?e=function(e){const t=function(e){for(const t of[/(?:youtube\.com\/watch\?v=|youtu\.be\/)([^&\n?#]+)/,/youtube\.com\/embed\/([^&\n?#]+)/]){const n=e.match(t);if(n)return n[1]}return null}(e);return t?`https://www.youtube.com/embed/${t}`:null}(o.url)||o.url:o.isVimeo&&(e=function(e){const t=function(e){for(const t of[/vimeo\.com\/(\d+)/,/player\.vimeo\.com\/video\/(\d+)/]){const n=e.match(t);if(n)return n[1]}return null}(e);return t?`https://player.vimeo.com/video/${t}`:null}(o.url)||o.url);const t={data:{alignment:"center",alt:"Video",caption:"",url:e},type:"video"};d?or.replaceBlock(s.id,c,t):or.insertBlock(t,s.id,c+1)}}},ce="\n/* Output alert styles */\n.clepit-output-alert {\n padding: 12px 16px;\n border-radius: 4px;\n font-size: 14px;\n line-height: 1.5;\n margin: 1rem 0;\n}\n\n.clepit-output-alert--info {\n background: var(--clepit-primary-bg);\n color: var(--clepit-primary-hover);\n}\n\n.clepit-output-alert--warning {\n background: var(--clepit-warning-bg);\n color: var(--clepit-warning);\n}\n\n.clepit-output-alert--error {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n}\n\n.clepit-output-alert--success {\n background: var(--clepit-success-bg);\n color: var(--clepit-success);\n}\n\n.clepit-output-alert--plain {\n background: transparent;\n color: inherit;\n}\n\n.clepit-output-alert-content {\n line-height: 1.5;\n}\n\n/* Output alert link styles */\n.clepit-output-alert a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-output-alert a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Output alert inline code styling */\n.clepit-output-alert code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Output alert marker brush effect */\n.clepit-output-alert mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n\n.clepit-output-alert mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1;\n}\n",pe=class e{static{this.placeholder="Alert message here..."}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.querySelector(`.${a.classNames.block.alert}`)||e,n=t.getAttribute("data-variant")||"info";return{html:M(t.innerHTML),variant:n}}static render(t,n,o){a.injectStyles("clepit-alert-input-styles","\n/* Alert block styles */\n.clepit-alert {\n padding: 12px 16px;\n border-radius: 4px;\n font-size: 14px;\n line-height: 1.5;\n margin: 0 20px;\n}\n\n.clepit-alert[data-variant=\"info\"] {\n background: var(--clepit-primary-bg);\n color: var(--clepit-primary-hover);\n}\n\n.clepit-alert[data-variant=\"warning\"] {\n background: var(--clepit-warning-bg);\n color: var(--clepit-warning);\n}\n\n.clepit-alert[data-variant=\"error\"] {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n}\n\n.clepit-alert[data-variant=\"success\"] {\n background: var(--clepit-success-bg);\n color: var(--clepit-success);\n}\n\n.clepit-alert[data-variant=\"plain\"] {\n background: transparent;\n color: inherit;\n}\n\n.clepit-alert-text {\n outline: none;\n margin: 0;\n padding: 0;\n}\n\n.clepit-alert[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: rgba(0, 0, 0, 0.6);\n font-style: italic;\n pointer-events: none;\n}\n\n/* Alert link styles */\n.clepit-alert-text a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-alert-text a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Alert inline code styling */\n.clepit-alert-text code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Alert marker brush effect */\n.clepit-alert-text mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0; /* create stacking context so ::before sits behind text, not page */\n white-space: pre-wrap; /* ensure leading/trailing spaces inside mark render */\n}\n\n.clepit-alert-text mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1; /* behind text but within mark's stacking context */\n}\n\n");const i={html:"",variant:"info"},r=n?{...i,...n}:i,s=a.createStyledElement("div","clepit-alert",{classNames:o?.classNames?.[r.variant],styles:o?.styles?.[r.variant]});return s.setAttribute("data-variant",r.variant),s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder",e.placeholder),r.html?s.innerHTML=r.html:s.innerHTML="",e.addEventListener(t,s,"keydown",or.handleKeydown),e.addEventListener(t,s,"input",or.handleInput),s}static changeVariant(t,n,o){const i=l.getState().getInstance(o);if(!i)return;if(t.getAttribute("data-variant")===n)return;const r=t.innerHTML||"",s={html:r.trim()&&"<br>"!==r.trim()?r:"",variant:n},c={classNames:i.config.classNames?.blocks?.alert,margins:i.config.margins,styles:i.config.styles?.blocks?.alert},p=or.getBlockIndex(o,t.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id")),d=e.render(o,s,c);t.replaceWith(d),l.getState().updateBlockData(o,p,s)}static isEmpty(e){return I(e.querySelector(`.${a.classNames.block.alert}`)?.innerHTML)}static isEmptyData(e){return I(e.html)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},de=class{constructor(e){this.node=e}get tag(){return this.node.tagName.toLowerCase()}setAttribute(e,t){this.node.setAttribute(e,t)}addClass(...e){this.node.classList.add(...e.filter(Boolean))}setText(e){this.node.textContent=e}setHtml(e){this.node.innerHTML=e}append(e){this.node.appendChild(e.node)}appendText(e){this.node.appendChild(document.createTextNode(e))}},ue={create:e=>new de(document.createElement(e)),createNS:(e,t)=>new de(document.createElementNS(e,t))},me=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),he=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),ge=e=>e.replace(/&/g,"&amp;").replace(/"/g,"&quot;"),be=class{constructor(e,t){this.tag=e,this.sanitize=t,this.attributes=new Map,this.classes=[],this.children=[]}setAttribute(e,t){this.attributes.set(e,t)}addClass(...e){for(const t of e.filter(Boolean))this.classes.includes(t)||this.classes.push(t)}setText(e){this.children.length=0,this.children.push(he(e))}setHtml(e){this.children.length=0,this.children.push(this.sanitize(e))}append(e){this.children.push(e.toString())}appendText(e){this.children.push(he(e))}toString(){const e=[...this.classes.length>0?[`class="${ge(this.classes.join(" "))}"`]:[],...[...this.attributes].map(([e,t])=>`${e}="${ge(t)}"`)],t=[this.tag,...e].join(" ");return me.has(this.tag)?`<${t}>`:`<${t}>${this.children.join("")}</${this.tag}>`}},fe=e=>({create:t=>new be(t,e),createNS:(t,n)=>new be(n,e)}),ye=e=>String(e),ve=e=>{if(!(e instanceof de))throw new TypeError("toDomElement needs an element built by the dom backing");return e.node};function xe(){a.injectStyles("clepit-invalid-data-styles","\n/* Invalid data component styles */\n.clepit-invalid-data {\n padding: 12px 16px;\n border-radius: 4px;\n font-size: 14px;\n line-height: 1.5;\n margin: 1rem 0;\n background: #ffebee;\n color: #c62828;\n}\n\n.clepit-invalid-data-text {\n font-weight: bold;\n margin: 0;\n padding: 0;\n}\n");const e=B("div","clepit-invalid-data"),t=B("div","clepit-invalid-data-text");return t.textContent="Invalid data",e.appendChild(t),e}var ke=class e{static render(t,n,o,i){if(a.injectStyles("clepit-alert-output-styles",ce),!e.validate(t))return xe();if(pe.isEmptyData(t))return document.createElement("div");const r=t.html,s=t.variant,l=a.createStyledElement("div",`clepit-output-alert clepit-output-alert--${s}`,{classNames:i?.[s],styles:o?.[s]});return r&&(l.innerHTML=r),l}static draw(t,n=ue){if(!e.validate(t)||pe.isEmptyData(t))return null;const a=n.create("div");return a.addClass("clepit-output-alert",`clepit-output-alert--${t.variant}`),t.html&&a.setHtml(t.html),a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"variant"in e&&"html"in e&&"string"==typeof e.html}},we={icon:"!",get input(){return pe},label:"Alert",get output(){return ke},shortcut:v("A"),testId:"block-type-alert",type:"alert"},Ce=`\n/* Audio block styles */\n.clepit-audio-container {\n margin: 0 16px;\n text-align: center;\n min-height: 120px;\n position: relative;\n display: block;\n width: 96%;\n box-sizing: border-box;\n}\n\n.${a.classNames.block.audio.wrapper} {\n display: flex;\n position: relative;\n cursor: pointer;\n transition: opacity 0.2s ease;\n outline: none;\n}\n\n.clepit-audio {\n width: 100%;\n}\n\n.align-left {\n justify-content: flex-start;\n}\n\n.align-center {\n justify-content: center;\n}\n\n.align-right {\n justify-content: flex-end;\n}\n\n.${a.classNames.block.audio.wrapper}:hover {\n opacity: 0.9;\n}\n\n.clepit-audio-caption-container {\n margin-top: 12px;\n text-align: center;\n}\n\n.clepit-audio-caption-label {\n font-size: 12px;\n color: var(--clepit-text-muted);\n margin-bottom: 4px;\n font-weight: 500;\n}\n\n.clepit-audio-caption-input {\n width: 100%;\n max-width: 400px;\n padding: 8px 12px;\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n font-size: 14px;\n background: var(--clepit-bg);\n outline: none;\n transition: border-color 0.2s ease;\n pointer-events: auto;\n user-select: text;\n}\n\n.clepit-audio-caption-input:focus {\n border-color: var(--clepit-primary);\n box-shadow: 0 0 0 2px var(--clepit-primary-bg);\n}\n\n/* Audio caption styling */\n.clepit-audio-caption-editable {\n border: 1px solid var(--clepit-border-subtle);\n border-radius: 4px;\n padding: 8px 12px;\n min-height: 40px;\n font-size: 14px;\n line-height: 1.4;\n outline: none;\n transition: border-color 0.2s ease;\n}\n\n/* Audio caption placeholder styles */\n.clepit-audio-caption-editable[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Audio Drop Area */\n.clepit-audio-drop-area {\n border: 2px dashed var(--clepit-border);\n border-radius: 8px;\n padding: 40px 20px;\n text-align: center;\n background: var(--clepit-surface);\n cursor: pointer;\n transition: all 0.2s ease;\n margin: 16px 0;\n user-select: none;\n pointer-events: auto;\n outline: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n position: relative;\n}\n\n.clepit-audio-drop-area:hover {\n border-color: var(--clepit-primary);\n background: var(--clepit-surface);\n}\n\n.clepit-audio-drop-area--dragover {\n border-color: var(--clepit-primary);\n background: var(--clepit-primary-bg);\n transform: scale(1.02);\n}\n\n.clepit-audio-drop-icon {\n font-size: 48px;\n margin-bottom: 16px;\n opacity: 0.6;\n}\n\n.clepit-audio-drop-text {\n font-size: 16px;\n color: var(--clepit-text-muted);\n line-height: 1.5;\n margin-bottom: 8px;\n}\n\n.clepit-audio-drop-subtext {\n font-size: 14px;\n color: var(--clepit-text-subtle);\n line-height: 1.4;\n}\n\n.clepit-audio-click-text {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n}\n\n/* Audio Loading State */\n.clepit-audio-loading {\n text-align: center;\n padding: 40px 20px;\n margin: 16px 0;\n}\n\n.clepit-audio-loading-spinner {\n width: 32px;\n height: 32px;\n border: 3px solid var(--clepit-surface);\n border-top: 3px solid var(--clepit-primary);\n border-radius: 50%;\n animation: spin 1s linear infinite;\n margin: 0 auto 16px;\n}\n\n@keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n}\n\n.clepit-audio-loading-text {\n font-size: 14px;\n color: var(--clepit-text-muted);\n}\n\n/* Audio Error State */\n.clepit-audio-error {\n text-align: center;\n padding: 20px;\n margin: 16px 0;\n border: 1px solid var(--clepit-error);\n border-radius: 8px;\n background: var(--clepit-error-bg);\n}\n\n.clepit-audio-error-icon {\n font-size: 24px;\n margin-bottom: 8px;\n}\n\n.clepit-audio-error-text {\n font-size: 14px;\n color: var(--clepit-error);\n margin-bottom: 12px;\n}\n\n.clepit-audio-error-retry {\n background: var(--clepit-error);\n color: white;\n border: none;\n padding: 8px 16px;\n border-radius: 4px;\n cursor: pointer;\n font-size: 14px;\n transition: background-color 0.2s ease;\n}\n\n.clepit-audio-error-retry:hover {\n background: var(--clepit-error);\n}\n\n/* Audio delete button */\n.${a.classNames.block.audioDeleteBtn} {\n position: absolute;\n top: 8px;\n right: 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 50%;\n width: 24px;\n height: 24px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: var(--clepit-bg);\n cursor: pointer;\n color: var(--clepit-text-muted);\n transition: color 0.2s ease;\n}\n\n.${a.classNames.block.audioDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Audio drop area delete button */\n.clepit-audio-drop-area .${a.classNames.block.audioDeleteBtn} {\n position: absolute;\n top: 8px;\n right: 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 50%;\n width: 24px;\n height: 24px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: var(--clepit-bg);\n cursor: pointer;\n color: var(--clepit-text-muted);\n transition: color 0.2s ease;\n}\n\n.clepit-audio-drop-area .${a.classNames.block.audioDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Drop area positioning */\n.clepit-drop-area {\n position: relative;\n}\n\n/* Hidden input */\n.clepit-hidden-input {\n display: none;\n}\n\n`,Ee="\n/* Output audio styles */\n.clepit-output-audio-container {\n width: 100%;\n margin: 1rem 0;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: flex-start;\n}\n\n.clepit-output-audio-wrapper {\n width: 100%;\n display: flex;\n}\n\n.clepit-output-audio {\n width: 100%;\n}\n\n\n.clepit-output-audio-caption {\n margin-top: 0.5rem;\n font-size: 0.875rem;\n color: var(--clepit-text-muted);\n font-style: italic;\n text-align: center;\n}\n\n/* Output audio alignment */\n.clepit-output-audio-wrapper--left {\n justify-content: flex-start;\n}\n\n.clepit-output-audio-wrapper--center {\n justify-content: center;\n}\n\n.clepit-output-audio-wrapper--right {\n justify-content: flex-end;\n}\n",Se=class e{static{this.placeholder="Add a caption..."}static{this.eventListenersMap={}}static{this.validTypes=["audio/mp3","audio/wav","audio/ogg","audio/mpeg","audio/mp4","audio/webm"]}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.querySelector("audio"),n=e.querySelector(`.${a.classNames.block.audio.captionEditable}`),o=e.querySelector(`.${a.classNames.block.audio.wrapper}`);let i="center";return o&&(i=o.classList.contains("align-left")?"left":o.classList.contains("align-right")?"right":"center"),{alignment:i,alt:t&&t.getAttribute("alt")||"",caption:M(n?.innerHTML),url:t&&t.getAttribute("src")||""}}static render(t,n,o,i){a.injectStyles("clepit-audio-input-styles",Ce);const r=o||{alt:"",caption:"",url:""},s=a.createStyledElement("div",a.classNames.block.audio.container,{classNames:i?.classNames?.container,styles:i?.styles?.container});return r.url?e.renderAudio(s,r,t,n,i):e.renderDropArea(s,t,n,i),s}static renderAudio(t,n,o,i,r){if(!document.getElementById(i))return;t.innerHTML="";const s=a.createStyledElement("div",a.classNames.block.audio.wrapper,{classNames:r?.classNames?.container,styles:r?.styles?.container});switch(s.setAttribute("tabindex","-1"),n?.alignment||"center"){case"left":s.classList.add("align-left");break;case"center":s.classList.add("align-center");break;case"right":s.classList.add("align-right")}const l=a.createStyledElement("audio","clepit-audio",{classNames:r?.classNames?.container,styles:r?.styles?.container});l.src=n.url,l.controls=!0,l.preload="metadata",n.alt&&l.setAttribute("alt",n.alt);const c=a.createStyledElement("div","clepit-audio-caption-container",{classNames:r?.classNames?.container,styles:r?.styles?.container});c.classList.add("clepit-audio-caption-container");const p=a.createStyledElement("div","clepit-audio-caption-editable",{classNames:r?.classNames?.caption,styles:r?.styles?.caption});p.setAttribute("contenteditable","true"),p.setAttribute("data-placeholder",e.placeholder),p.innerHTML=n.caption||"",e.addEventListener(i,p,"keydown",or.handleKeydown),e.addEventListener(i,p,"input",or.handleInput),e.addEventListener(i,s,"click",()=>e.handleFileSelect(t,o,i,r)),s.appendChild(l),c.appendChild(p),t.appendChild(s),t.appendChild(c),p.focus()}static renderDropArea(t,n,o,i){t.innerHTML="";const r=a.createStyledElement("div",a.classNames.block.audio.dropArea,{classNames:i?.classNames?.dropArea?.container,styles:i?.styles?.dropArea?.container});r.setAttribute("tabindex","0"),r.classList.add("clepit-drop-area");const s=a.createStyledElement("div","clepit-audio-drop-icon",{classNames:i?.classNames?.dropArea?.icon,styles:i?.styles?.dropArea?.icon});s.textContent="♪";const c=a.createStyledElement("div","clepit-audio-drop-text",{classNames:i?.classNames?.dropArea?.text,styles:i?.styles?.dropArea?.text});c.innerHTML='<strong>Drop an audio file here</strong><br>or <span class="clepit-audio-click-text">click to select</span>';const p=a.createStyledElement("div","clepit-audio-drop-subtext",{classNames:i?.classNames?.dropArea?.subtext,styles:i?.styles?.dropArea?.subtext});p.textContent="Supports MP3, WAV, OGG, and other audio formats";const d=a.createStyledElement("button",`${a.classNames.block.audioDeleteBtn}`,{classNames:i?.classNames?.dropArea?.deleteButton,styles:i?.styles?.dropArea?.deleteButton});d.type="button",d.textContent="✕",r.appendChild(s),r.appendChild(c),r.appendChild(p),r.appendChild(d);const u=o?l.getState().getInstance(o):null,m=u?.config.classNames?.tooltips,h=u?.config.styles?.tooltips;J(d,"Delete block","below",m,h),e.addEventListener(o,d,"click",e=>{e.preventDefault(),e.stopPropagation();const t=d.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id");t&&or.removeBlock(o,or.getBlockIndex(o,t))}),e.addEventListener(o,r,"click",()=>e.handleFileSelect(t,n,o,i)),e.addEventListener(o,r,"dragleave",()=>{r.classList.remove("clepit-audio-drop-area--dragover")}),e.addEventListener(o,r,"dragover",e=>{e.preventDefault(),e.stopPropagation(),r.classList.add("clepit-audio-drop-area--dragover")}),e.addEventListener(o,r,"drop",a=>{a.preventDefault(),a.stopPropagation(),r.classList.remove("clepit-audio-drop-area--dragover"),e.handleFileDrop(a,t,n,o,i)}),e.addEventListener(o,r,"focus",e=>{e.preventDefault(),e.stopPropagation()}),e.addEventListener(o,r,"mousedown",e=>{e.preventDefault(),e.stopPropagation()}),t.appendChild(r)}static handleFileSelect(t,n,a,o){const i=document.createElement("input");i.type="file",i.accept="audio/*",i.style.display="none",i.addEventListener("change",()=>{const r=i.files;if(r&&r.length>0){const i=r[0];e.isValidAudioFile(i)?e.processAudioFile(i,t,n,a,o):e.showError(t,"Please select a valid audio file (MP3, WAV, OGG)")}}),document.body.appendChild(i),i.click(),document.body.removeChild(i)}static handleFileDrop(t,n,a,o,i){const r=t.dataTransfer?.files;if(r&&r.length>0){const t=r[0];e.isValidAudioFile(t)?e.processAudioFile(t,n,a,o,i):e.showError(n,"Please select a valid audio file (MP3, WAV, OGG)")}}static isValidAudioFile(t){return e.validTypes.includes(t.type)||t.type.startsWith("audio/")}static async processAudioFile(t,n,o,i,r){e.showLoading(n);try{let s=await o(t);if(s){e.renderAudio(n,{alignment:"center",alt:t.name,caption:"",url:s},o,i,r);const c=n.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id");c&&l.getState().updateBlockData(i,or.getBlockIndex(i,c),or.getBlockData(c).data)}else e.showError(n,"Failed to upload audio. Please try again.")}catch(s){console.error("Audio upload error:",s),e.showError(n,"Failed to upload audio. Please try again.")}}static showLoading(e){e.innerHTML="";const t=a.createStyledElement("div","clepit-audio-loading",void 0);t.textContent="Uploading audio...",e.appendChild(t)}static showError(e,t){e.innerHTML="";const n=a.createStyledElement("div","clepit-audio-error",void 0);n.textContent=t,e.appendChild(n)}static setAlignment(e,t){const n=e.querySelector(".clepit-audio-wrapper");n&&(n.classList.remove("align-left","align-center","align-right"),n.classList.add(`align-${t}`));const a=or.getEditorId(e);if(!a)return;const o=e.getAttribute("data-id");o&&l.getState().partialUpdateBlockData(a,or.getBlockIndex(a,o),{alignment:t})}static isEmpty(e){const t=e.querySelector(`.${a.classNames.block.audio.wrapper} audio`),n=e.querySelector(`.${a.classNames.block.audio.captionEditable}`);let o=!1,i=!1;return t&&t.getAttribute("src")?.trim()||(o=!0),n?I(n.innerHTML)&&(i=!0):i=!0,o&&i}static isEmptyData(e){return!e.url?.trim()&&I(e.caption)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Ne=class e{static render(t,n,o,i){if(a.injectStyles("clepit-audio-output-styles",Ee),!e.validate(t))return xe();if(Se.isEmptyData(t))return document.createElement("div");const r=t.url,s=t.caption,l=t.alignment||"center",c=a.createStyledElement("div","clepit-output-audio-container",{classNames:i?.container,styles:o?.container}),p=a.createStyledElement("div","clepit-output-audio-wrapper");switch(l){case"left":p.classList.add("clepit-output-audio-wrapper--left");break;case"center":p.classList.add("clepit-output-audio-wrapper--center");break;case"right":p.classList.add("clepit-output-audio-wrapper--right")}const d=B("audio","clepit-output-audio");if(d.src=r,d.controls=!0,d.preload="metadata",t.alt&&d.setAttribute("alt",t.alt),p.appendChild(d),c.appendChild(p),s){const e=a.createStyledElement("figcaption","clepit-output-audio-caption",{classNames:i?.caption,styles:o?.caption}),n=t.caption;e.innerHTML=n&&n!==s?n:s,c.appendChild(e)}if(o&&(o.container&&Object.assign(c.style,o.container),o.caption)){const e=c.querySelector(".clepit-output-audio-caption");e&&Object.assign(e.style,o.caption)}if(i&&(i.container&&c.classList.add(i.container),i.caption)){const e=c.querySelector(".clepit-output-audio-caption");e&&e.classList.add(i.caption)}return c}static draw(t,n=ue){if(!e.validate(t)||Se.isEmptyData(t))return null;const a=n.create("div");a.addClass("clepit-output-audio-container");const o=n.create("div");o.addClass("clepit-output-audio-wrapper");const i=t.alignment??"center";i&&o.addClass(`clepit-output-audio-wrapper--${i}`);const r=n.create("audio");if(r.addClass("clepit-output-audio"),r.setAttribute("src",t.url),r.setAttribute("controls","controls"),o.append(r),a.append(o),t.caption){const e=n.create("figcaption");e.addClass("clepit-output-audio-caption"),e.setHtml(t.caption),a.append(e)}return a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.url}},Ae={icon:"♪",get input(){return Se},label:"Audio",get output(){return Ne},shortcut:v("O"),testId:"block-type-audio",type:"audio"},Le=`\n/* Checklist input block styles */\n.${a.classNames.block.checklist.container} {\n margin: 0;\n padding: 0 20px;\n}\n\n.${a.classNames.block.checklist.item} {\n --text: var(--clepit-text);\n --check: var(--clepit-marker);\n --disabled: var(--clepit-border);\n --border-radius: 10px;\n border-radius: var(--border-radius);\n position: relative;\n padding: 5px;\n display: grid;\n grid-template-columns: 30px auto;\n align-items: center;\n margin: 4px 0;\n}\n\n.${a.classNames.block.checklist.text} {\n color: var(--text);\n position: relative;\n cursor: pointer;\n display: grid;\n align-items: center;\n width: -webkit-fit-content;\n width: -moz-fit-content;\n width: fit-content;\n transition: color 0.3s ease;\n outline: none;\n min-height: 1.2em;\n line-height: 1.6;\n padding: 0;\n margin: 0;\n}\n\n.${a.classNames.block.checklist.text}::before,\n.${a.classNames.block.checklist.text}::after {\n content: "";\n position: absolute;\n}\n\n.${a.classNames.block.checklist.text}::before {\n height: 2px;\n width: 8px;\n left: -27px;\n background: var(--check);\n border-radius: 2px;\n transition: background 0.3s ease;\n}\n\n.${a.classNames.block.checklist.text}::after {\n height: 4px;\n width: 4px;\n top: 8px;\n left: -25px;\n border-radius: 50%;\n}\n\n.${a.classNames.block.checklist.checkbox} {\n -webkit-appearance: none;\n -moz-appearance: none;\n position: relative;\n height: 15px;\n width: 15px;\n outline: none;\n border: 0;\n margin: 0 15px 0 0;\n cursor: pointer;\n background: var(--background);\n display: grid;\n align-items: center;\n}\n\n.${a.classNames.block.checklist.checkbox}::before,\n.${a.classNames.block.checklist.checkbox}::after {\n content: "";\n position: absolute;\n height: 2px;\n top: auto;\n background: var(--check);\n border-radius: 2px;\n}\n\n.${a.classNames.block.checklist.checkbox}::before {\n width: 0px;\n right: 60%;\n transform-origin: right bottom;\n}\n\n.${a.classNames.block.checklist.checkbox}::after {\n width: 0px;\n left: 40%;\n transform-origin: left bottom;\n}\n\n.${a.classNames.block.checklist.checkbox}:checked::before {\n -webkit-animation: clepit-check-01-11 0.4s ease forwards;\n animation: clepit-check-01-11 0.4s ease forwards;\n}\n\n.${a.classNames.block.checklist.checkbox}:checked::after {\n -webkit-animation: clepit-check-02-11 0.4s ease forwards;\n animation: clepit-check-02-11 0.4s ease forwards;\n}\n\n.${a.classNames.block.checklist.checkbox}:checked + .${a.classNames.block.checklist.text} {\n color: var(--disabled);\n -webkit-animation: clepit-move-11 0.3s ease 0.1s forwards;\n animation: clepit-move-11 0.3s ease 0.1s forwards;\n}\n\n.${a.classNames.block.checklist.checkbox}:checked + .${a.classNames.block.checklist.text}::before {\n background: var(--disabled);\n -webkit-animation: clepit-slice-11 0.4s ease forwards;\n animation: clepit-slice-11 0.4s ease forwards;\n}\n\n.${a.classNames.block.checklist.checkbox}:checked + .${a.classNames.block.checklist.text}::after {\n -webkit-animation: clepit-firework-11 0.5s ease forwards 0.1s;\n animation: clepit-firework-11 0.5s ease forwards 0.1s;\n}\n\n.${a.classNames.block.checklist.text}[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Checklist input link styles */\n.${a.classNames.block.checklist.text} a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.${a.classNames.block.checklist.text} a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n@-webkit-keyframes clepit-move-11 {\n 50% {\n padding-left: 8px;\n padding-right: 0px;\n }\n 100% {\n padding-right: 4px;\n }\n}\n\n@keyframes clepit-move-11 {\n 50% {\n padding-left: 8px;\n padding-right: 0px;\n }\n 100% {\n padding-right: 4px;\n }\n}\n\n@-webkit-keyframes clepit-slice-11 {\n 60% {\n width: 100%;\n left: 4px;\n }\n 100% {\n width: 100%;\n left: -2px;\n padding-left: 0;\n }\n}\n\n@keyframes clepit-slice-11 {\n 60% {\n width: 100%;\n left: 4px;\n }\n 100% {\n width: 100%;\n left: -2px;\n padding-left: 0;\n }\n}\n\n@-webkit-keyframes clepit-check-01-11 {\n 0% {\n width: 4px;\n top: auto;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: auto;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(45deg);\n }\n 100% {\n width: 5px;\n top: 8px;\n transform: rotate(45deg);\n }\n}\n\n@keyframes clepit-check-01-11 {\n 0% {\n width: 4px;\n top: auto;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: auto;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(45deg);\n }\n 100% {\n width: 5px;\n top: 8px;\n transform: rotate(45deg);\n }\n}\n\n@-webkit-keyframes clepit-check-02-11 {\n 0% {\n width: 4px;\n top: 17px;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: 17px;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(-45deg);\n }\n 100% {\n width: 10px;\n top: 8px;\n transform: rotate(-45deg);\n }\n}\n\n@keyframes clepit-check-02-11 {\n 0% {\n width: 4px;\n top: 17px;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: 17px;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(-45deg);\n }\n 100% {\n width: 10px;\n top: 8px;\n transform: rotate(-45deg);\n }\n}\n\n@-webkit-keyframes clepit-firework-11 {\n 0% {\n opacity: 1;\n box-shadow: 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--clepit-marker), 14px -8px 0 0px var(--clepit-marker), 14px 8px 0 0px var(--clepit-marker), 0 15px 0 0px var(--clepit-marker), -14px 8px 0 0px var(--clepit-marker), -14px -8px 0 0px var(--clepit-marker);\n }\n}\n\n@keyframes clepit-firework-11 {\n 0% {\n opacity: 1;\n box-shadow: 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--clepit-marker), 14px -8px 0 0px var(--clepit-marker), 14px 8px 0 0px var(--clepit-marker), 0 15px 0 0px var(--clepit-marker), -14px 8px 0 0px var(--clepit-marker), -14px -8px 0 0px var(--clepit-marker);\n }\n}\n`,Be='\n/* Checklist output block styles */\n.clepit-output-checklist {\n margin: 0 0 1rem 0;\n padding-left: 0;\n}\n\n.clepit-output-checklist-item {\n --text: var(--clepit-text);\n --check: var(--clepit-marker);\n --disabled: var(--clepit-border);\n --border-radius: 10px;\n border-radius: var(--border-radius);\n position: relative;\n padding: 5px;\n display: grid;\n grid-template-columns: 30px auto;\n align-items: center;\n margin: 0.5rem 0;\n line-height: 1.6;\n}\n\n.clepit-output-checklist-text {\n color: var(--text);\n position: relative;\n cursor: pointer;\n display: grid;\n align-items: center;\n width: -webkit-fit-content;\n width: -moz-fit-content;\n width: fit-content;\n transition: color 0.3s ease;\n line-height: 1.6;\n}\n\n.clepit-output-checklist-text::before,\n.clepit-output-checklist-text::after {\n content: "";\n position: absolute;\n}\n\n.clepit-output-checklist-text::before {\n height: 2px;\n width: 8px;\n left: -27px;\n background: var(--check);\n border-radius: 2px;\n transition: background 0.3s ease;\n}\n\n.clepit-output-checklist-text::after {\n height: 4px;\n width: 4px;\n top: 8px;\n left: -25px;\n border-radius: 50%;\n}\n\n.clepit-output-checklist-checkbox {\n -webkit-appearance: none;\n -moz-appearance: none;\n position: relative;\n height: 15px;\n width: 15px;\n outline: none;\n border: 0;\n margin: 0 15px 0 0;\n cursor: pointer;\n background: var(--background);\n display: grid;\n align-items: center;\n pointer-events: none;\n}\n\n.clepit-output-checklist-checkbox::before,\n.clepit-output-checklist-checkbox::after {\n content: "";\n position: absolute;\n height: 2px;\n top: auto;\n background: var(--check);\n border-radius: 2px;\n}\n\n.clepit-output-checklist-checkbox::before {\n width: 0px;\n right: 60%;\n transform-origin: right bottom;\n}\n\n.clepit-output-checklist-checkbox::after {\n width: 0px;\n left: 40%;\n transform-origin: left bottom;\n}\n\n.clepit-output-checklist-checkbox:checked::before {\n -webkit-animation: clepit-check-01-11 0.4s ease forwards;\n animation: clepit-check-01-11 0.4s ease forwards;\n}\n\n.clepit-output-checklist-checkbox:checked::after {\n -webkit-animation: clepit-check-02-11 0.4s ease forwards;\n animation: clepit-check-02-11 0.4s ease forwards;\n}\n\n.clepit-output-checklist-checkbox:checked + .clepit-output-checklist-text {\n color: var(--disabled);\n -webkit-animation: clepit-move-11 0.3s ease 0.1s forwards;\n animation: clepit-move-11 0.3s ease 0.1s forwards;\n}\n\n.clepit-output-checklist-checkbox:checked + .clepit-output-checklist-text::before {\n background: var(--disabled);\n -webkit-animation: clepit-slice-11 0.4s ease forwards;\n animation: clepit-slice-11 0.4s ease forwards;\n}\n\n.clepit-output-checklist-checkbox:checked + .clepit-output-checklist-text::after {\n -webkit-animation: clepit-firework-11 0.5s ease forwards 0.1s;\n animation: clepit-firework-11 0.5s ease forwards 0.1s;\n}\n\n@-webkit-keyframes clepit-move-11 {\n 50% {\n padding-left: 8px;\n padding-right: 0px;\n }\n 100% {\n padding-right: 4px;\n }\n}\n\n@keyframes clepit-move-11 {\n 50% {\n padding-left: 8px;\n padding-right: 0px;\n }\n 100% {\n padding-right: 4px;\n }\n}\n\n@-webkit-keyframes clepit-slice-11 {\n 60% {\n width: 100%;\n left: 4px;\n }\n 100% {\n width: 100%;\n left: -2px;\n padding-left: 0;\n }\n}\n\n@keyframes clepit-slice-11 {\n 60% {\n width: 100%;\n left: 4px;\n }\n 100% {\n width: 100%;\n left: -2px;\n padding-left: 0;\n }\n}\n\n@-webkit-keyframes clepit-check-01-11 {\n 0% {\n width: 4px;\n top: auto;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: auto;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(45deg);\n }\n 100% {\n width: 5px;\n top: 8px;\n transform: rotate(45deg);\n }\n}\n\n@keyframes clepit-check-01-11 {\n 0% {\n width: 4px;\n top: auto;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: auto;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(45deg);\n }\n 100% {\n width: 5px;\n top: 8px;\n transform: rotate(45deg);\n }\n}\n\n@-webkit-keyframes clepit-check-02-11 {\n 0% {\n width: 4px;\n top: 17px;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: 17px;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(-45deg);\n }\n 100% {\n width: 10px;\n top: 8px;\n transform: rotate(-45deg);\n }\n}\n\n@keyframes clepit-check-02-11 {\n 0% {\n width: 4px;\n top: 17px;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: 17px;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(-45deg);\n }\n 100% {\n width: 10px;\n top: 8px;\n transform: rotate(-45deg);\n }\n}\n\n@-webkit-keyframes clepit-firework-11 {\n 0% {\n opacity: 1;\n box-shadow: 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--clepit-marker), 14px -8px 0 0px var(--clepit-marker), 14px 8px 0 0px var(--clepit-marker), 0 15px 0 0px var(--clepit-marker), -14px 8px 0 0px var(--clepit-marker), -14px -8px 0 0px var(--clepit-marker);\n }\n}\n\n@keyframes clepit-firework-11 {\n 0% {\n opacity: 1;\n box-shadow: 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--clepit-marker), 14px -8px 0 0px var(--clepit-marker), 14px 8px 0 0px var(--clepit-marker), 0 15px 0 0px var(--clepit-marker), -14px 8px 0 0px var(--clepit-marker), -14px -8px 0 0px var(--clepit-marker);\n }\n}\n',$e=class e{static{this.placeholder="Add checklist item..."}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=[];return e.querySelectorAll(`.${a.classNames.block.checklist.item}`).forEach(e=>{const n=e.querySelector('input[type="checkbox"]'),o=e.querySelector(`.${a.classNames.block.checklist.text}`);n&&o&&t.push({checked:n.checked,text:M(o.innerHTML)})}),{items:t}}static render(t,n,o){a.injectStyles("clepit-checklist-input-styles",Le);const i={items:[]},r=n?{...i,...n}:i,s=a.createStyledElement("div",a.classNames.block.checklist.container,{classNames:o?.classNames?.container,styles:o?.styles?.container});return r.items.length>0?r.items.forEach(n=>e.createAndAppendChecklistItem(n,s,t,o)):e.createAndAppendChecklistItem({checked:!1,text:""},s,t,o),s}static createAndAppendChecklistItem(t,n,o,i){const r=a.createStyledElement("div",a.classNames.block.checklist.item,{classNames:i?.classNames?.item,styles:i?.styles?.item}),s=a.createStyledElement("input",a.classNames.block.checklist.checkbox,{classNames:i?.classNames?.checkbox,styles:i?.styles?.checkbox});s.type="checkbox",s.checked=t.checked;const l=a.createStyledElement("div",a.classNames.block.checklist.text,{classNames:i?.classNames?.text,styles:i?.styles?.text});l.setAttribute("contenteditable","true"),l.setAttribute("data-placeholder",e.placeholder),l.innerHTML=t.text?.trim()||"",e.addEventListener(o,s,"change",()=>or.saveBlockData(s)),e.addEventListener(o,l,"keydown",t=>{const s=t,c=n.closest(`.${a.classNames.block.container}`);if(!c)return;const p=or.getBlockIndex(o,c.getAttribute("data-id")),d=s.metaKey||s.ctrlKey;if(s.shiftKey)switch(s.key){case"ArrowUp":t.preventDefault(),t.stopPropagation(),p>0&&or.moveBlock(o,p,p-1);break;case"ArrowDown":t.preventDefault(),t.stopPropagation();const e=or.getBlocks(o);e&&p<e.length-1&&or.moveBlock(o,p,p+1)}else if(d)switch(s.key){case"Delete":case"Backspace":t.preventDefault(),t.stopPropagation(),or.removeBlock(o,p)}else if("Enter"===s.key)if(t.preventDefault(),t.stopPropagation(),I(l.innerHTML)){e.cleanupEmptyItems(n);const t=n.closest(`.${a.classNames.block.container}`);if(!t)return;const i=or.getBlockIndex(o,t.getAttribute("data-id"));or.insertBlock({data:{html:""},type:"paragraph"},o,i+1)}else e.createAndAppendChecklistItem({checked:!1,text:""},n,o,i);else if("Backspace"===s.key){if(I(l.innerHTML)){t.preventDefault(),t.stopPropagation();const e=Array.from(n.querySelectorAll(`.${a.classNames.block.checklist.item}`)),i=e.indexOf(r);if(1===e.length){const e=n.closest(`.${a.classNames.block.container}`);if(!e)return;const t=or.getBlockIndex(o,e.getAttribute("data-id"));if(-1===t)return;or.removeBlock(o,t)}else r.remove(),i>0?e[i-1].querySelector(".clepit-checklist-text")?.focus():e[i+1].querySelector(".clepit-checklist-text")?.focus()}}else{or.ensureActiveBlock(o);const e=or.getBlocks(o);switch(s.key){case"ArrowUp":t.preventDefault(),t.stopPropagation();const o=Array.from(n.querySelectorAll(`.${a.classNames.block.checklist.item}`)),i=o.indexOf(r);if(0===i){if(p>0){const t=e[p-1];t&&or.focusBlock(t)}}else{const e=o[i-1].querySelector(`.${a.classNames.block.checklist.text}`);e&&e.focus()}return;case"ArrowDown":t.preventDefault(),t.stopPropagation();const s=Array.from(n.querySelectorAll(`.${a.classNames.block.checklist.item}`)),l=s.indexOf(r);if(l===s.length-1){if(p<e.length-1){const t=e[p+1];t&&or.focusBlock(t)}}else{const e=s[l+1].querySelector(`.${a.classNames.block.checklist.text}`);e&&e.focus()}return}}}),e.addEventListener(o,l,"input",or.handleInput),r.appendChild(s),r.appendChild(l),n.appendChild(r),l.focus()}static cleanupEmptyItems(e){const t=Array.from(e.querySelectorAll(`.${a.classNames.block.checklist.item}`)),n=t.filter(e=>I(e.querySelector(`.${a.classNames.block.checklist.text}`)?.innerHTML||""));if(t.length===n.length){if(t.length<2)return;for(let e=1;e<n.length;e++)n[e].remove()}else n.forEach(e=>e.remove())}static isEmpty(e){const t=e.querySelectorAll(`.${a.classNames.block.checklist.item}`);return!t||Array.from(t).every(e=>I(e.querySelector(`.${a.classNames.block.checklist.text}`)?.innerHTML))}static isEmptyData(e){return 0===e.items.length||e.items.every(e=>I(e.text))}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Ie=class e{static render(t,n,o,i){if(a.injectStyles("clepit-checklist-output-styles",Be),!e.validate(t))return xe();if($e.isEmptyData(t))return document.createElement("div");const r=t.items,s=a.createStyledElement("div","clepit-output-checklist",{classNames:i?.container,styles:o?.container});return r.forEach((e,t)=>{const n=a.createStyledElement("div","clepit-output-checklist-item",{classNames:i?.item,styles:o?.item}),r=a.createStyledElement("input","clepit-output-checklist-checkbox",{classNames:i?.checkbox,styles:o?.checkbox});r.type="checkbox",r.checked=e.checked,r.setAttribute("readonly","true");const l=a.createStyledElement("div","clepit-output-checklist-text",{classNames:i?.text,styles:o?.text});e.text&&e.text.trim()&&(l.innerHTML=e.text),r.checked&&n.classList.add("checked"),n.appendChild(r),n.appendChild(l),s.appendChild(n)}),s}static draw(t,n=ue){if(!e.validate(t)||$e.isEmptyData(t))return null;const a=n.create("div");a.addClass("clepit-output-checklist");for(const e of t.items){const t=n.create("div");t.addClass("clepit-output-checklist-item");const o=n.create("input");o.addClass("clepit-output-checklist-checkbox"),o.setAttribute("type","checkbox"),e.checked&&o.setAttribute("checked","checked"),o.setAttribute("readonly","true"),t.append(o);const i=n.create("div");i.addClass("clepit-output-checklist-text"),e.text?.trim()&&i.setHtml(e.text),t.append(i),a.append(t)}return a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&Array.isArray(e.items)}},Me={icon:"☑",get input(){return $e},label:"Checklist",get output(){return Ie},shortcut:v("K"),testId:"block-type-checklist",type:"checklist"},Te=`\n/* Code block styles */\n.clepit-code {\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0;\n}\n\n.clepit-code-pre {\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0;\n}\n\n.clepit-block[data-tool="code"] .clepit-block-content {\n background: transparent;\n border: none;\n padding: 0;\n margin-right: 8px;\n}\n\n/* Code placeholder styles */\n.clepit-code[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Code container */\n.${a.classNames.block.code.container} {\n border: 1px solid var(--clepit-code-border);\n background: var(--clepit-code-bg);\n border-radius: 6px;\n overflow: visible; /* allow header tooltips to escape */\n margin: 8px 0;\n}\n\n.${a.classNames.block.code.editor} {\n height: 200px;\n max-height: 60vh;\n min-height: 200px;\n overflow: hidden;\n position: relative;\n}\n\n/* The editing surface: a textarea laid over a highlighted pre. The two must\n * agree on every metric that affects where a glyph lands, or the caret drifts\n * away from the colour behind it. They inherit from one rule for that reason. */\n.${a.classNames.block.code.editor} .clepit-code-highlight,\n.${a.classNames.block.code.editor} .clepit-code-input {\n margin: 0;\n border: 0;\n padding: 12px 34px;\n font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Source Code Pro', monospace;\n font-size: 0.875rem;\n line-height: 1.5;\n letter-spacing: normal;\n tab-size: 2;\n white-space: pre;\n overflow: auto;\n box-sizing: border-box;\n}\n\n.${a.classNames.block.code.editor} .clepit-code-highlight {\n position: absolute;\n inset: 0;\n pointer-events: none;\n color: var(--clepit-code-text);\n}\n\n/* The text itself is transparent: the colour the reader sees belongs to the pre\n * behind it. The caret keeps a colour of its own so it stays visible. */\n.${a.classNames.block.code.editor} .clepit-code-input {\n position: relative;\n width: 100%;\n height: 100%;\n display: block;\n background: transparent;\n color: transparent;\n caret-color: var(--clepit-code-text);\n resize: none;\n outline: none;\n}\n\n.${a.classNames.block.code.editor} .clepit-code-input::placeholder {\n color: var(--clepit-text-muted);\n}\n\n.${a.classNames.block.code.editor} .clepit-code-input::selection {\n background: var(--clepit-code-selection-bg);\n color: transparent;\n}\n\n/* Code header */\n.${a.classNames.block.code.headerWrapper} {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 8px;\n width: 100%;\n padding: 8px 34px;\n position: relative; /* allow inner tooltip absolute positioning */\n overflow: visible; /* ensure tooltip not clipped */\n z-index: 2;\n border-bottom: 1px solid var(--clepit-border-color);\n}\n\n.${a.classNames.block.code.header} {\n font-size: 12px;\n font-weight: 500;\n}\n\n/* Code Language Submenu */\n.clepit-code-language-submenu {\n position: absolute;\n top: 0;\n left: 100%;\n z-index: 1002;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n padding: 8px;\n min-width: 160px;\n max-width: 200px;\n margin-left: 4px;\n max-height: 300px;\n overflow-y: auto;\n display: none;\n transition: transform 0.2s ease;\n}\n\n.clepit-code-language-submenu--visible {\n display: block !important;\n transform: translateX(0);\n}\n\n.clepit-code-language-submenu--hidden {\n display: none !important;\n}\n\n/* Code Theme Submenu */\n.clepit-code-theme-submenu {\n position: absolute;\n top: 0;\n left: 100%;\n z-index: 1002;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n padding: 8px;\n min-width: 140px;\n max-width: 180px;\n margin-left: 4px;\n max-height: 250px;\n overflow-y: auto;\n display: none;\n transition: transform 0.2s ease;\n}\n\n.clepit-code-theme-submenu--visible {\n display: block !important;\n transform: translateX(0);\n}\n\n.clepit-code-theme-submenu--hidden {\n display: none !important;\n}\n\n/* Code language submenu items */\n.clepit-code-language-item {\n padding: 8px 12px;\n cursor: pointer;\n border-radius: 4px;\n transition: background-color 0.2s;\n font-size: 14px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n\n.clepit-code-language-item:hover {\n background-color: var(--clepit-hover-bg, var(--clepit-surface));\n}\n\n/* Code theme submenu items */\n.clepit-code-theme-item {\n padding: 8px 12px;\n cursor: pointer;\n border-radius: 4px;\n transition: background-color 0.2s;\n font-size: 14px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n\n.clepit-code-theme-item:hover {\n background-color: var(--clepit-hover-bg, var(--clepit-surface));\n}\n\n\n`,qe="clepit-code-output-styles",De="\n/* Output Code Block */\n/* No margin of its own — every consumer already governs the gap around this\n * container (page rhythm via the block wrapper's margin-block, or a flex\n * container's gap inside the openapi block). A margin here just adds a second,\n * inconsistent gap on top of whichever one the consumer already applies. */\n.clepit-output-code-container {\n border: 1px solid var(--clepit-code-border);\n border-radius: 6px;\n overflow: hidden;\n background: var(--clepit-code-bg);\n margin: 0;\n}\n\n.clepit-output-code-header {\n background: var(--clepit-code-bg);\n padding: 8px 34px;\n border-bottom: 1px solid var(--clepit-code-border);\n font-size: 12px;\n color: var(--clepit-text-muted);\n font-weight: 500;\n display: flex;\n align-items: center;\n justify-content: space-between;\n}\n\n/* Output header — theme-agnostic; tokens handle light/dark automatically */\n.clepit-output-code-header {\n background: var(--clepit-code-bg);\n color: var(--clepit-text-muted);\n border-bottom-color: var(--clepit-code-border);\n --clepit-svg-stroke-color: var(--clepit-text-muted);\n --clepit-btn-hover-bg: var(--clepit-block-highlight-bg);\n}\n\n/* Output code variant tabs */\n.clepit-output-code-tabs {\n display: flex;\n align-items: stretch;\n gap: 4px;\n margin: -8px 0 -8px -18px;\n overflow-x: auto;\n scrollbar-width: none;\n}\n\n.clepit-output-code-tabs::-webkit-scrollbar {\n display: none;\n}\n\n.clepit-output-code-tab {\n appearance: none;\n -webkit-appearance: none;\n background: transparent;\n border: none;\n border-bottom: 2px solid transparent;\n color: var(--clepit-text-muted);\n cursor: pointer;\n font: inherit;\n padding: 8px 10px;\n transition: color 0.2s ease, border-color 0.2s ease;\n white-space: nowrap;\n}\n\n.clepit-output-code-tab:hover {\n color: var(--clepit-text);\n}\n\n.clepit-output-code-tab[aria-selected=\"true\"] {\n border-bottom-color: var(--clepit-primary);\n color: var(--clepit-primary);\n}\n\n.clepit-output-code-tab:focus-visible {\n outline: 2px solid var(--clepit-primary);\n outline-offset: -2px;\n}\n\n.clepit-output-code-editor {\n overflow: auto;\n max-height: 60vh;\n position: relative;\n border: none;\n border-radius: 0;\n}\n\n/* The output panes: one pre per variant, the inactive ones carrying a hidden attribute.\n * Colour comes from the generated theme stylesheet, keyed on the container's\n * data-theme, so a published page keeps its palette with nothing running. */\n.clepit-output-code-pane {\n margin: 0;\n padding: 12px 34px;\n max-height: 60vh;\n overflow: auto;\n font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Source Code Pro', monospace;\n font-size: 0.875rem;\n line-height: 1.5;\n tab-size: 2;\n white-space: pre;\n}\n\n/* Code Output */\n.clepit-output-code {\n margin: 1rem 0;\n background-color: var(--clepit-code-bg);\n border: 1px solid var(--clepit-code-border);\n border-radius: 6px;\n overflow: hidden;\n}\n\n.clepit-output-code code {\n display: block;\n padding: 1rem;\n font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Source Code Pro', monospace;\n font-size: 0.875rem;\n line-height: 1.5;\n color: var(--clepit-code-text);\n overflow-x: auto;\n white-space: pre;\n}\n\n/* Output code copy button */\n.clepit-output-code-copy-btn {\n margin-left: auto;\n width: 24px;\n height: 24px;\n border: none;\n outline: none;\n cursor: pointer;\n border-radius: 50%;\n background: transparent;\n transition: all 0.2s ease;\n padding: 4px;\n display: flex;\n align-items: center;\n justify-content: center;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n}\n\n.clepit-output-code-copy-btn {\n color: var(--clepit-text-muted);\n}\n\n.clepit-output-code-copy-btn:hover {\n background: var(--clepit-block-highlight-bg);\n color: var(--clepit-primary);\n}\n\n.clepit-output-code-copy-btn:hover .clepit-copy-icon {\n stroke: var(--clepit-primary);\n}\n\n.clepit-output-code-copy-btn:active {\n transform: scale(0.95);\n}\n\n.clepit-copy-icon,\n.clepit-check-icon {\n width: 20px;\n height: 20px;\n stroke: var(--clepit-svg-stroke-color);\n stroke-width: 2;\n fill: none;\n display: block;\n}\n\n/* Code output button animation styles */\n.clepit-output-code-copy-btn--animating {\n color: var(--clepit-success);\n transform: scale(1.1);\n}\n\n.clepit-output-code-copy-btn--normal {\n color: var(--clepit-svg-stroke-color);\n transform: scale(1);\n}\n",_e={dark:{background:"#1c2128",comment:"rgba(240, 246, 252, 0.42)",function:"#d2a8ff",gutter:"rgba(240, 246, 252, 0.42)",keyword:"#ff7b72",number:"#79c0ff",punctuation:"rgba(240, 246, 252, 0.62)",selection:"rgba(124, 124, 255, 0.24)",string:"#7ee787",text:"rgba(240, 246, 252, 0.92)",type:"#ffa657"},dracula:{background:"#282a36",comment:"#6272a4",function:"#50fa7b",gutter:"#6272a4",keyword:"#ff79c6",number:"#bd93f9",punctuation:"#f8f8f2",selection:"rgba(68, 71, 90, 0.8)",string:"#f1fa8c",text:"#f8f8f2",type:"#8be9fd"},github:{background:"#ffffff",comment:"#6e7781",function:"#8250df",gutter:"#8c959f",keyword:"#cf222e",number:"#0550ae",punctuation:"#24292f",selection:"rgba(84, 174, 255, 0.24)",string:"#0a3069",text:"#24292f",type:"#953800"},"github-dark":{background:"#0d1117",comment:"#8b949e",function:"#d2a8ff",gutter:"#6e7681",keyword:"#ff7b72",number:"#79c0ff",punctuation:"#c9d1d9",selection:"rgba(56, 139, 253, 0.24)",string:"#a5d6ff",text:"#c9d1d9",type:"#ffa657"},light:{background:"#fdfdfd",comment:"#868f9c",function:"#6f42c1",gutter:"#868f9c",keyword:"#cf222e",number:"#0550ae",punctuation:"#525866",selection:"rgba(91, 91, 255, 0.14)",string:"#0a7c3e",text:"#0a0a0a",type:"#953800"},monokai:{background:"#272822",comment:"#75715e",function:"#a6e22e",gutter:"#75715e",keyword:"#f92672",number:"#ae81ff",punctuation:"#f8f8f2",selection:"rgba(73, 72, 62, 0.9)",string:"#e6db74",text:"#f8f8f2",type:"#66d9ef"},solarized:{background:"#fdf6e3",comment:"#93a1a1",function:"#268bd2",gutter:"#93a1a1",keyword:"#859900",number:"#d33682",punctuation:"#657b83",selection:"rgba(238, 232, 213, 0.9)",string:"#2aa198",text:"#657b83",type:"#b58900"},"solarized-dark":{background:"#002b36",comment:"#586e75",function:"#268bd2",gutter:"#586e75",keyword:"#859900",number:"#d33682",punctuation:"#839496",selection:"rgba(7, 54, 66, 0.9)",string:"#2aa198",text:"#839496",type:"#b58900"},tomorrow:{background:"#fafafa",comment:"#8e908c",function:"#4271ae",gutter:"#8e908c",keyword:"#8959a8",number:"#f5871f",punctuation:"#4d4d4c",selection:"rgba(214, 214, 214, 0.9)",string:"#718c00",text:"#4d4d4c",type:"#c82829"}},je=["keyword","string","number","comment","function","type","punctuation","text"],ze=Object.fromEntries(je.map(e=>[e,`clepit-code-${e}`])),Oe=e=>e>="0"&&e<="9",He=e=>" "===e||"\t"===e||"\n"===e||"\r"===e||"\f"===e||"\v"===e,Pe=e=>e>="a"&&e<="z"||e>="A"&&e<="Z"||"_"===e||e.charCodeAt(0)>127,Re=e=>(e.lineComments?.length??0)>0||(e.blockComments?.length??0)>0||(e.strings?.length??0)>0||(e.keywords?.length??0)>0||(e.types?.length??0)>0||(e.constants?.length??0)>0||(e.builtins?.length??0)>0,Fe=(e,t)=>new Set((e??[]).map(e=>t?e.toLowerCase():e)),Ve=(e,t)=>{let n=t;for(;n<e.length&&(" "===e[n]||"\t"===e[n]);)n++;return e[n]??""},Ue=(e,t,n)=>{const a=n.close??n.open;let o=t+n.open.length;for(;o<e.length;)if(n.escape&&e[o]===n.escape)o+=2;else{if(!n.multiline&&"\n"===e[o])return o;if(e.startsWith(a,o))return o+a.length;o++}return e.length},We=(e,t)=>{let n=t;if("0"===e[n]&&/[xXbBoO]/.test(e[n+1]??"")){for(n+=2;n<e.length&&/[0-9a-fA-F_]/.test(e[n]);)n++;return n}for(;n<e.length&&/[0-9_]/.test(e[n]);)n++;if("."===e[n]&&Oe(e[n+1]??""))for(n++;n<e.length&&/[0-9_]/.test(e[n]);)n++;if(/[eE]/.test(e[n]??"")&&(Oe(e[n+1]??"")||/[+-]/.test(e[n+1]??"")&&Oe(e[n+2]??"")))for(n+=2;n<e.length&&Oe(e[n]);)n++;for(;n<e.length&&Pe(e[n])&&!Oe(e[n])&&/[a-zA-Z]/.test(e[n])&&n-t<32&&/[nlLfFdDuUmM]/.test(e[n]);)n++;return n},Ke=[{escape:"\\",open:'"'},{escape:"\\",open:"'"}],Ge={blockComments:[["/*","*/"]],lineComments:["//"]},Je=e=>({...Ge,functionCalls:!0,strings:Ke,...e}),Xe=e=>({functionCalls:!0,lineComments:["#"],strings:Ke,...e}),Ze=["as","async","await","break","case","catch","class","const","continue","debugger","default","delete","do","else","export","extends","finally","for","from","function","get","if","import","in","instanceof","let","new","of","return","set","static","super","switch","this","throw","try","typeof","var","void","while","with","yield"],Ye=[...Ze,"abstract","declare","enum","implements","infer","interface","is","keyof","namespace","override","private","protected","public","readonly","satisfies","type"],Qe=Je({constants:["false","null","true","undefined","NaN","Infinity"],identifierExtra:"$",keywords:Ze,strings:[...Ke,{escape:"\\",multiline:!0,open:"`"}],types:["Array","Boolean","Date","Error","Map","Number","Object","Promise","RegExp","Set","String","Symbol"]}),et={...Qe,keywords:Ye,types:[...Qe.types??[],"any","bigint","boolean","never","number","object","string","symbol","unknown","void"]},tt=Xe({constants:["False","None","True"],keywords:["and","as","assert","async","await","break","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","in","is","lambda","nonlocal","not","or","pass","raise","return","try","while","with","yield"],strings:[{escape:"\\",multiline:!0,open:'"""'},{escape:"\\",multiline:!0,open:"'''"},...Ke],types:["bool","bytes","dict","float","frozenset","int","list","set","str","tuple"]}),nt={blockComments:[["\x3c!--","--\x3e"]],strings:Ke,types:[]},at={assembly:{constants:[],keywords:["add","call","cmp","jmp","jne","je","lea","mov","pop","push","ret","sub","xor"],lineComments:[";","#"],strings:Ke,types:["byte","dword","qword","word"]},bash:Xe({builtins:["cd","echo","exit","export","printf","read","source"],constants:["false","true"],identifierExtra:"$",keywords:["case","do","done","elif","else","esac","fi","for","function","if","in","local","return","select","then","until","while"],strings:[{escape:"\\",multiline:!0,open:'"'},{multiline:!0,open:"'"}]}),clojure:{constants:["false","nil","true"],identifierExtra:"-*?!<>=/",keywords:["def","defmacro","defn","do","fn","if","let","loop","ns","quote","recur","require","var","when"],lineComments:[";"],strings:[{escape:"\\",multiline:!0,open:'"'}]},cobol:{caseInsensitive:!0,keywords:["accept","add","call","compute","display","division","else","end","goback","identification","if","move","perform","procedure","program-id","section","stop","to","until","working-storage"],lineComments:["*"],strings:Ke,types:["pic","picture"]},cpp:Je({constants:["false","nullptr","true"],keywords:["auto","break","case","catch","class","const","constexpr","continue","default","delete","do","else","enum","explicit","export","extern","for","friend","goto","if","inline","mutable","namespace","new","noexcept","operator","private","protected","public","return","sizeof","static","struct","switch","template","this","throw","try","typedef","typename","union","using","virtual","volatile","while"],types:["bool","char","double","float","int","long","short","signed","size_t","unsigned","void","wchar_t"]}),csharp:Je({constants:["false","null","true"],keywords:["abstract","as","async","await","base","break","case","catch","class","const","continue","default","delegate","do","else","enum","event","explicit","extern","finally","fixed","for","foreach","get","goto","if","implicit","in","interface","internal","is","lock","namespace","new","operator","out","override","params","private","protected","public","readonly","record","ref","return","sealed","set","sizeof","stackalloc","static","struct","switch","this","throw","try","typeof","unsafe","using","var","virtual","void","while","yield"],types:["bool","byte","char","decimal","double","float","int","long","object","sbyte","short","string","uint","ulong","ushort"]}),css:{blockComments:[["/*","*/"]],functionCalls:!0,keywords:["and","from","important","not","only","to"],strings:Ke,types:["@container","@import","@keyframes","@layer","@media","@property","@supports"]},dart:Je({constants:["false","null","true"],keywords:["abstract","as","assert","async","await","break","case","catch","class","const","continue","covariant","default","deferred","do","else","enum","export","extends","extension","external","factory","final","finally","for","get","if","implements","import","in","is","late","library","mixin","new","on","operator","part","required","rethrow","return","sealed","set","show","static","super","switch","sync","this","throw","try","typedef","var","while","with","yield"],types:["bool","double","dynamic","int","List","Map","num","Object","Set","String","void"]}),diff:{lineComments:["diff ","index ","--- ","+++ "],strings:[]},dockerfile:Xe({caseInsensitive:!0,keywords:["add","arg","cmd","copy","entrypoint","env","expose","from","healthcheck","label","run","shell","stopsignal","user","volume","workdir"]}),erlang:{constants:["false","true","undefined"],functionCalls:!0,keywords:["after","begin","case","catch","cond","end","fun","if","let","of","receive","try","when"],lineComments:["%"],strings:Ke},fortran:{caseInsensitive:!0,keywords:["allocate","call","contains","do","else","end","function","if","implicit","module","program","return","subroutine","then","use","while"],lineComments:["!"],strings:Ke,types:["character","complex","integer","logical","real"]},go:Je({builtins:["append","cap","copy","delete","len","make","new","panic","recover"],constants:["false","iota","nil","true"],keywords:["break","case","chan","const","continue","default","defer","else","fallthrough","for","func","go","goto","if","import","interface","map","package","range","return","select","struct","switch","type","var"],strings:[...Ke,{multiline:!0,open:"`"}],types:["bool","byte","complex128","complex64","error","float32","float64","int","int16","int32","int64","int8","rune","string","uint","uint16","uint32","uint64","uint8","uintptr"]}),graphql:Xe({keywords:["directive","enum","extend","fragment","implements","input","interface","mutation","on","query","scalar","schema","subscription","type","union"],types:["Boolean","Float","ID","Int","String"]}),groovy:Je({constants:["false","null","true"],keywords:["abstract","as","assert","break","case","catch","class","const","continue","def","default","do","else","enum","extends","final","finally","for","if","implements","import","in","instanceof","interface","new","package","private","protected","public","return","static","super","switch","this","throw","throws","trait","try","while"],types:["BigDecimal","Boolean","Integer","List","Map","String","boolean","double","int","long","void"]}),haskell:{blockComments:[["{-","-}"]],constants:["False","Nothing","True"],functionCalls:!0,keywords:["case","class","data","deriving","do","else","if","import","in","infixl","infixr","instance","let","module","newtype","of","then","type","where"],lineComments:["--"],strings:[{escape:"\\",open:'"'}],types:["Bool","Char","Double","Either","Int","Integer","IO","Maybe","String"]},html:nt,java:Je({constants:["false","null","true"],keywords:["abstract","assert","break","case","catch","class","const","continue","default","do","else","enum","extends","final","finally","for","goto","if","implements","import","instanceof","interface","native","new","package","private","protected","public","record","return","sealed","static","strictfp","super","switch","synchronized","this","throw","throws","transient","try","var","volatile","while","yield"],types:["Boolean","Double","Integer","List","Long","Map","Object","String","boolean","byte","char","double","float","int","long","short","void"]}),javascript:Qe,json:{constants:["false","null","true"],strings:[{escape:"\\",open:'"'}]},jsx:Qe,julia:Xe({blockComments:[["#=","=#"]],constants:["false","nothing","true"],keywords:["abstract","baremodule","begin","break","catch","const","continue","do","else","elseif","end","export","finally","for","function","global","if","import","let","local","macro","module","mutable","primitive","quote","return","struct","try","using","while"],types:["Array","Bool","Char","Dict","Float64","Int","Int64","String"]}),kotlin:Je({constants:["false","null","true"],keywords:["as","break","by","class","companion","const","constructor","continue","crossinline","data","do","else","enum","external","final","finally","for","fun","get","if","import","in","infix","init","inline","interface","internal","is","lateinit","object","open","operator","out","override","package","private","protected","public","reified","return","sealed","set","super","suspend","this","throw","try","typealias","val","var","vararg","when","while"],strings:[{escape:"\\",multiline:!0,open:'"""'},...Ke],types:["Any","Array","Boolean","Char","Double","Float","Int","List","Long","Map","Nothing","Set","String","Unit"]}),lua:{blockComments:[["--[[","]]"]],constants:["false","nil","true"],functionCalls:!0,keywords:["and","break","do","else","elseif","end","for","function","goto","if","in","local","not","or","repeat","return","then","until","while"],lineComments:["--"],strings:[{close:"]]",multiline:!0,open:"[["},...Ke]},markdown:{lineComments:[],strings:[{open:"`"}]},nginx:Xe({keywords:["access_log","error_log","events","http","include","index","listen","location","proxy_pass","return","root","server","server_name","ssl_certificate","upstream"]}),objectivec:Je({constants:["NO","YES","nil"],identifierExtra:"@",keywords:["@class","@end","@implementation","@interface","@property","@protocol","@selector","@synthesize","break","case","const","continue","default","do","else","enum","extern","for","if","return","sizeof","static","struct","switch","typedef","union","void","while"],types:["BOOL","CGFloat","NSArray","NSDictionary","NSInteger","NSObject","NSString","char","double","float","id","int","long","short"]}),pascal:{blockComments:[["{","}"],["(*","*)"]],caseInsensitive:!0,constants:["false","nil","true"],functionCalls:!0,keywords:["and","array","begin","case","const","div","do","downto","else","end","for","function","goto","if","implementation","interface","mod","not","of","or","procedure","program","record","repeat","then","to","type","unit","until","uses","var","while","with"],lineComments:["//"],strings:[{open:"'"}],types:["boolean","byte","char","integer","real","string"]},perl:Xe({constants:["undef"],identifierExtra:"$@%",keywords:["do","else","elsif","foreach","for","if","last","local","my","next","our","package","return","sub","unless","until","use","while"]}),php:Je({constants:["false","null","true"],identifierExtra:"$",keywords:["abstract","as","break","case","catch","class","clone","const","continue","declare","default","do","echo","else","elseif","enum","extends","final","finally","fn","for","foreach","function","global","if","implements","include","instanceof","interface","match","namespace","new","print","private","protected","public","readonly","require","return","static","switch","throw","trait","try","use","var","while","yield"],lineComments:["//","#"],types:["array","bool","callable","float","int","iterable","mixed","object","string","void"]}),plaintext:{},powershell:Xe({blockComments:[["<#","#>"]],caseInsensitive:!0,constants:["$false","$null","$true"],identifierExtra:"$-",keywords:["begin","break","catch","continue","do","else","elseif","end","finally","for","foreach","function","if","in","param","process","return","switch","throw","try","until","while"]}),protobuf:Je({constants:["false","true"],keywords:["enum","extend","import","map","message","oneof","option","optional","package","repeated","required","reserved","returns","rpc","service","syntax"],types:["bool","bytes","double","fixed32","fixed64","float","int32","int64","sint32","sint64","string","uint32","uint64"]}),python:tt,r:Xe({constants:["FALSE","Inf","NA","NULL","NaN","TRUE"],identifierExtra:".",keywords:["break","else","for","function","if","in","next","repeat","return","while"],types:["character","data.frame","factor","integer","list","logical","matrix","numeric","vector"]}),ruby:Xe({blockComments:[["=begin","=end"]],constants:["false","nil","true"],identifierExtra:"?!@$",keywords:["alias","and","begin","break","case","class","def","defined?","do","else","elsif","end","ensure","for","if","in","module","next","not","or","redo","rescue","retry","return","self","super","then","undef","unless","until","when","while","yield"],types:["Array","Float","Hash","Integer","String","Symbol"]}),rust:Je({constants:["false","None","Some","true"],keywords:["as","async","await","break","const","continue","crate","dyn","else","enum","extern","fn","for","if","impl","in","let","loop","match","mod","move","mut","pub","ref","return","self","static","struct","super","trait","type","unsafe","use","where","while"],types:["String","Vec","bool","char","f32","f64","i128","i16","i32","i64","i8","isize","str","u128","u16","u32","u64","u8","usize"]}),scala:Je({constants:["false","null","true"],keywords:["abstract","case","catch","class","def","do","else","extends","final","finally","for","given","if","implicit","import","lazy","match","new","object","override","package","private","protected","return","sealed","super","this","throw","trait","try","type","val","var","while","with","yield"],types:["Any","Boolean","Double","Float","Int","List","Long","Map","Option","Seq","String","Unit"]}),scheme:{constants:["#f","#t"],identifierExtra:"-*?!<>=/",keywords:["begin","cond","define","do","else","if","lambda","let","let*","letrec","quote","set!"],lineComments:[";"],strings:[{escape:"\\",open:'"'}]},shell:Xe({builtins:["cd","echo","exit","export","printf","read","source"],identifierExtra:"$",keywords:["case","do","done","elif","else","esac","fi","for","function","if","in","return","then","until","while"],strings:[{escape:"\\",multiline:!0,open:'"'},{multiline:!0,open:"'"}]}),sql:{blockComments:[["/*","*/"]],caseInsensitive:!0,constants:["false","true"],functionCalls:!0,keywords:["add","all","alter","and","as","asc","begin","between","by","case","cast","column","commit","create","cross","delete","desc","distinct","drop","else","end","exists","from","full","group","having","in","index","inner","insert","into","is","join","left","like","limit","not","null","offset","on","or","order","outer","primary","references","returning","right","rollback","select","set","table","then","union","unique","update","values","view","when","where","with"],lineComments:["--"],strings:[{open:"'"},{open:'"'}],types:["bigint","boolean","bytea","date","decimal","integer","jsonb","numeric","serial","text","timestamp","uuid","varchar"]},swift:Je({constants:["false","nil","true"],keywords:["actor","as","associatedtype","async","await","break","case","catch","class","continue","default","defer","deinit","do","else","enum","extension","fallthrough","fileprivate","final","for","func","guard","if","import","in","init","inout","internal","is","lazy","let","mutating","open","operator","private","protocol","public","repeat","return","self","static","struct","subscript","super","switch","throw","throws","try","typealias","var","where","while"],types:["Any","Array","Bool","Character","Dictionary","Double","Float","Int","Optional","Set","String","UInt","Void"]}),toml:Xe({constants:["false","true"],functionCalls:!1}),tsx:et,typescript:et,vb:{caseInsensitive:!0,constants:["False","Nothing","True"],functionCalls:!0,keywords:["as","byval","case","catch","class","dim","do","each","else","elseif","end","finally","for","function","if","imports","in","loop","module","namespace","new","next","private","public","return","select","set","sub","then","throw","try","while"],lineComments:["'"],strings:[{open:'"'}],types:["Boolean","Date","Double","Integer","Long","Object","String"]},verilog:Je({keywords:["always","assign","begin","case","else","end","endcase","endmodule","for","if","initial","input","module","output","parameter","posedge","negedge"],types:["integer","logic","reg","wire"]}),vhdl:{caseInsensitive:!0,constants:["false","true"],functionCalls:!0,keywords:["architecture","begin","case","component","else","elsif","end","entity","for","function","if","is","library","loop","of","port","process","signal","then","use","when","while"],lineComments:["--"],strings:[{open:'"'}],types:["bit","boolean","integer","natural","std_logic","std_logic_vector"]},xml:nt,yaml:Xe({constants:["false","no","null","true","yes"],functionCalls:!1})},ot=(e,t)=>((e,t)=>{if(0===e.length)return[];if(!Re(t))return[{classes:"",text:e}];const n=[],a=Fe(t.keywords,t.caseInsensitive),o=Fe(t.types,t.caseInsensitive),i=Fe(t.constants,t.caseInsensitive),r=Fe(t.builtins,t.caseInsensitive),s=e=>Pe(e)||Oe(e)||(t.identifierExtra?.includes(e)??!1);let l=0,c="";const p=()=>{0!==c.length&&(n.push({classes:"",text:c}),c="")},d=(e,t)=>{p(),n.push({classes:t,text:e})};for(;l<e.length;){const n=e.slice(l),p=e[l],u=(t.blockComments??[]).find(([e])=>n.startsWith(e));if(u){const[t,n]=u,a=e.indexOf(n,l+t.length),o=-1===a?e.length:a+n.length;d(e.slice(l,o),ze.comment),l=o;continue}if(void 0!==(t.lineComments??[]).find(e=>n.startsWith(e))){const t=e.indexOf("\n",l),n=-1===t?e.length:t;d(e.slice(l,n),ze.comment),l=n;continue}const m=(t.strings??[]).find(e=>n.startsWith(e.open));if(m){const t=Ue(e,l,m);d(e.slice(l,t),ze.string),l=t;continue}if(Oe(p)&&!(l>0&&s(e[l-1]))){const t=We(e,l);d(e.slice(l,t),ze.number),l=t;continue}if(Pe(p)||t.identifierExtra?.includes(p)){let n=l+1;for(;n<e.length&&s(e[n]);)n++;const p=e.slice(l,n),u=t.caseInsensitive?p.toLowerCase():p;a.has(u)?d(p,ze.keyword):o.has(u)?d(p,ze.type):i.has(u)?d(p,ze.number):r.has(u)||t.functionCalls&&"("===Ve(e,n)?d(p,ze.function):c+=p,l=n;continue}He(p)?(c+=p,l++):(d(p,ze.punctuation),l++)}return p(),n})(e,at[t]??{}),it={assembly:"Assembly",bash:"Bash",clojure:"Clojure",cobol:"COBOL",cpp:"C++",csharp:"C#",css:"CSS",dart:"Dart",diff:"Diff",dockerfile:"Dockerfile",erlang:"Erlang",fortran:"Fortran",go:"Go",graphql:"GraphQL",groovy:"Groovy",haskell:"Haskell",html:"HTML",java:"Java",javascript:"JavaScript",json:"JSON",jsx:"JSX",julia:"Julia",kotlin:"Kotlin",lua:"Lua",markdown:"Markdown",nginx:"Nginx",objectivec:"Objective-C",pascal:"Pascal",perl:"Perl",php:"PHP",plaintext:"Plain Text",powershell:"PowerShell",protobuf:"Protocol Buffers",python:"Python",r:"R",ruby:"Ruby",rust:"Rust",scala:"Scala",scheme:"Scheme",shell:"Shell",sql:"SQL",swift:"Swift",toml:"TOML",tsx:"TSX",typescript:"TypeScript",vb:"Visual Basic",verilog:"Verilog",vhdl:"VHDL",xml:"XML",yaml:"YAML"};function rt(e){return it[e]||"Unknown"}var st=Object.fromEntries(Object.keys(at).map(e=>[e,{name:rt(e)}])),lt={auto:"Auto",dark:"Dark",default:"Auto",dracula:"Dracula",github:"GitHub","github-dark":"GitHub Dark",light:"Light",monokai:"Monokai",solarized:"Solarized","solarized-dark":"Solarized Dark",tomorrow:"Tomorrow"};function ct(e){return lt[e]||"Unknown"}var pt=Object.fromEntries(Object.keys(lt).map(e=>[e,{name:ct(e),theme:null}])),dt=`\n/* Custom Switch Container */\n.${a.classNames.switch.container} {\n --switch-blue: #0D7EFF;\n --switch-red: #FF0D0D;\n --switch-text: var(--clepit-bg);\n --switch-white: var(--clepit-bg);\n display: flex;\n flex-direction: row;\n align-items: center;\n gap: 8px;\n}\n\n.${a.classNames.switch.container} .tgl {\n display: none;\n}\n\n.${a.classNames.switch.container} .tgl,\n.${a.classNames.switch.container} .tgl:after,\n.${a.classNames.switch.container} .tgl:before,\n.${a.classNames.switch.container} .tgl *,\n.${a.classNames.switch.container} .tgl *:after,\n.${a.classNames.switch.container} .tgl *:before,\n.${a.classNames.switch.container} .tgl + .tgl-btn {\n box-sizing: border-box;\n}\n\n.${a.classNames.switch.container} .tgl::selection,\n.${a.classNames.switch.container} .tgl:after::selection,\n.${a.classNames.switch.container} .tgl:before::selection,\n.${a.classNames.switch.container} .tgl *::selection,\n.${a.classNames.switch.container} .tgl *:after::selection,\n.${a.classNames.switch.container} .tgl *:before::selection,\n.${a.classNames.switch.container} .tgl + .tgl-btn::selection {\n background: none;\n}\n\n.${a.classNames.switch.container} .tgl + .tgl-btn {\n outline: 0;\n display: block;\n width: 57px;\n height: 27px;\n position: relative;\n cursor: pointer;\n user-select: none;\n font-size: 12px;\n font-weight: 400;\n color: var(--switch-white);\n}\n\n.${a.classNames.switch.container} .tgl + .tgl-btn:after,\n.${a.classNames.switch.container} .tgl + .tgl-btn:before {\n position: relative;\n display: block;\n content: "";\n width: 44%;\n height: 100%;\n}\n\n.${a.classNames.switch.container} .tgl + .tgl-btn:after {\n left: 0;\n}\n\n.${a.classNames.switch.container} .tgl + .tgl-btn:before {\n display: inline;\n position: absolute;\n top: 3px;\n}\n\n.${a.classNames.switch.container} .tgl:checked + .tgl-btn:after {\n left: 56.5%;\n}\n\n.${a.classNames.switch.container} .tgl-ios + .tgl-btn {\n background: var(--switch-red);\n border-radius: 20rem;\n padding: 2px;\n transition: all 0.4s ease;\n box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);\n}\n\n.${a.classNames.switch.container} .tgl-ios + .tgl-btn:after {\n border-radius: 2em;\n background: var(--switch-white);\n transition: left 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), padding 0.3s ease, margin 0.3s ease;\n box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.2);\n}\n\n.${a.classNames.switch.container} .tgl-ios + .tgl-btn:before {\n content: "No";\n left: 30px;\n color: var(--switch-text);\n transition: left 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);\n}\n\n.${a.classNames.switch.container} .tgl-ios + .tgl-btn:active {\n box-shadow: inset 0 0 0 30px rgba(0, 0, 0, 0.1);\n}\n\n.${a.classNames.switch.container} .tgl-ios + .tgl-btn:active:after {\n padding-right: 0.4em;\n}\n\n.${a.classNames.switch.container} .tgl-ios:checked + .tgl-btn {\n background: var(--switch-blue);\n}\n\n.${a.classNames.switch.container} .tgl-ios:checked + .tgl-btn:active {\n box-shadow: inset 0 0 0 30px rgba(0, 0, 0, 0.1);\n}\n\n.${a.classNames.switch.container} .tgl-ios:checked + .tgl-btn:active:after {\n margin-left: -0.4em;\n}\n\n.${a.classNames.switch.container} .tgl-ios:checked + .tgl-btn:before {\n content: "Yes";\n left: 6px;\n color: var(--switch-white);\n}\n\n.clepit-switch-label-text {\n font-size: 13px;\n display: flex;\n align-items: center;\n}\n`,ut=class{static create(e={}){const{checked:t=!1,onToggle:n,classNames:o,styles:i,label:r,id:s=`switch-${Math.random().toString(36).substring(2,11)}`}=e;a.injectStyles("clepit-custom-switch-styles",dt);const l=a.createStyledElement("div",a.classNames.switch.container,{classNames:o?.container,styles:i?.container}),c=a.createStyledElement("input","tgl tgl-ios",{classNames:o?.input,styles:i?.input});c.type="checkbox",c.id=s,c.checked=t;const p=a.createStyledElement("label","tgl-btn",{classNames:o?.label,styles:i?.label});if(p.setAttribute("for",s),n&&c.addEventListener("change",e=>{const t=e.target;n(t.checked)}),l.appendChild(c),l.appendChild(p),r){const e=a.createStyledElement("span","clepit-switch-label-text",{classNames:o?.labelText,styles:i?.labelText});e.textContent=r,l.appendChild(e)}return l}static getState(e){const t=e.querySelector('input[type="checkbox"]');return!!t&&t.checked}static setState(e,t){const n=e.querySelector('input[type="checkbox"]');n&&(n.checked=t)}},mt=class e{static{this.placeholder="Enter code..."}static{this.supportedLanguages=st}static{this.supportedThemes=pt}static{this.defaultLanguage="typescript"}static{this.defaultTheme="auto"}static{this.inputMap=new WeakMap}static{this.dataMap=new WeakMap}static save(t){const n=t.querySelector(`.${a.classNames.block.code.container}`),o=n.querySelector(`.${a.classNames.block.code.headerWrapper}`),i=n?.getAttribute("data-language")||e.defaultLanguage,r=n?.getAttribute("data-theme")||e.defaultTheme,s=!!o&&ut.getState(o),l=e.inputMap.get(n);if(l){const t=l.value,a=e.dataMap.get(n),o={code:t.trim()||"",language:i,showCopy:s,theme:r};return a?.variants?.length&&(o.variants=a.variants),a?.syncKey&&(o.syncKey=a.syncKey),e.dataMap.set(n,o),o}return{...e.dataMap.get(n)||{code:"",language:e.defaultLanguage,theme:e.defaultTheme},showCopy:s}}static addVariant(e){const t=e.variants?.length?e.variants:[{code:e.code,...e.language?{language:e.language}:{}}];return{...e,variants:[...t,{code:""}]}}static removeVariant(e,t){const n=(e.variants??[]).filter((e,n)=>n!==t),a=n[0],o={...e,code:a?.code??e.code,...a?.language?{language:a.language}:{}};if(n.length<=1){const{variants:e,...t}=o;return t}return{...o,variants:n}}static render(t,n,o,i){a.injectStyles("clepit-code-input-styles",Te);const r={code:"",language:i?.language||e.defaultLanguage,showCopy:!0,theme:i?.theme||e.defaultTheme},s=n?{...r,...n}:r,c=a.createStyledElement("div",a.classNames.block.code.container,{classNames:o?.classNames?.container,styles:o?.styles?.container});c.setAttribute("data-language",s.language||e.defaultLanguage),c.setAttribute("data-theme",s.theme||e.defaultTheme);const p=a.createStyledElement("div",a.classNames.block.code.headerWrapper,{classNames:o?.classNames?.header?.wrapper,styles:o?.styles?.header?.wrapper}),d=a.createStyledElement("div",a.classNames.block.code.header,{classNames:o?.classNames?.header?.text,styles:o?.styles?.header?.text}),u=st[s.language]?.name||rt(e.defaultLanguage),m=pt[s.theme]?.name||ct(e.defaultTheme);d.textContent=e.getHeaderText(u,m);const h=a.createStyledElement("div",a.classNames.block.code.editor,{classNames:o?.classNames?.container,styles:o?.styles?.container});h.setAttribute("data-placeholder",e.placeholder);const g=t?l.getState().getInstance(t):null,b=g?.config.classNames?.switch,f=g?.config.styles?.switch,y=ut.create({checked:s.showCopy||!1,classNames:b,label:"Allow copy",onToggle:t=>{const n=e.dataMap.get(c)||{code:"",language:e.defaultLanguage,theme:e.defaultTheme};e.dataMap.set(c,{...n,showCopy:t}),or.saveBlockData(c)},styles:f});return p.appendChild(d),p.appendChild(y),c.appendChild(p),c.appendChild(h),e.mountEditor(c,h,s),c}static mountEditor(t,n,a){const o=a.language??e.defaultLanguage,i=document.createElement("pre");i.className="clepit-code-highlight",i.setAttribute("aria-hidden","true");const r=document.createElement("code");i.appendChild(r);const s=document.createElement("textarea");s.className="clepit-code-input",s.value=a.code??"",s.spellcheck=!1,s.autocapitalize="off",s.setAttribute("autocorrect","off"),s.setAttribute("data-testid","code-input"),s.setAttribute("aria-label",`${rt(o)} code`),s.placeholder=e.placeholder,n.replaceChildren(i,s),e.inputMap.set(t,s),e.dataMap.set(t,a),e.paint(t,r,s.value),s.addEventListener("input",()=>{e.paint(t,r,s.value);const n=e.dataMap.get(t)??{code:"",language:t.getAttribute("data-language")||e.defaultLanguage,theme:t.getAttribute("data-theme")||e.defaultTheme};e.dataMap.set(t,{...n,code:s.value}),or.saveBlockData(t)}),s.addEventListener("scroll",()=>{i.scrollTop=s.scrollTop,i.scrollLeft=s.scrollLeft}),s.addEventListener("keydown",n=>e.handleKeydown(t,s,n))}static paint(t,n,a){const o=t.getAttribute("data-language")||e.defaultLanguage;n.replaceChildren(...ot(a.endsWith("\n")?`${a} `:a,o).map(e=>{const t=document.createElement("span");return e.classes&&(t.className=e.classes),t.textContent=e.text,t}))}static updateLanguage(t,n){const o=t.querySelector(`.${a.classNames.block.code.container}`);if(!o)return;const i=t.querySelector(`.${a.classNames.block.code.editor}`);if(!i)return;o.setAttribute("data-language",n);const r=o.querySelector(`.${a.classNames.block.code.header}`),s=o.getAttribute("data-theme")||e.defaultTheme,l=ct(s),c=rt(n);r&&(r.textContent=e.getHeaderText(c,l));const p=e.inputMap.get(o);p&&e.mountEditor(o,i,{code:p.value,language:n,theme:s}),or.saveBlockData(o)}static updateTheme(t,n){const o=t.querySelector(`.${a.classNames.block.code.container}`);if(!o)return;const i=t.querySelector(`.${a.classNames.block.code.editor}`);if(!i)return;o.setAttribute("data-theme",n);const r=o.querySelector(`.${a.classNames.block.code.header}`),s=o.getAttribute("data-language")||e.defaultLanguage,l=rt(s),c=ct(n);r&&(r.textContent=e.getHeaderText(l,c));const p=e.inputMap.get(o);p&&e.mountEditor(o,i,{code:p.value,language:s,theme:n}),or.saveBlockData(o)}static handleKeydown(e,t,n){const o=e.closest(`.${a.classNames.block.container}`);if(!o)return;const i=or.getEditorId(o);if(!i)return;const r=or.getBlockIndex(i,o.getAttribute("data-id")),s=n.metaKey||n.ctrlKey;return"Enter"!==n.key||n.shiftKey?"Backspace"===n.key&&s||"Delete"===n.key&&s?(n.preventDefault(),void or.removeBlock(i,r)):"Backspace"!==n.key||""!==t.value.trim()?"ArrowUp"===n.key?(n.preventDefault(),void(n.shiftKey?or.moveBlock(i,r,r-1):or.focusBlock(o.previousElementSibling))):void("ArrowDown"===n.key&&(n.preventDefault(),n.shiftKey?or.moveBlock(i,r,r+1):or.focusBlock(o.nextElementSibling))):void or.removeBlock(i,r):(n.preventDefault(),void or.insertBlock({data:{html:""},type:"paragraph"},i,r+1))}static getHeaderText(e,t){return`${e} | ${t}`}static isEmpty(t){const n=t.querySelector(`.${a.classNames.block.code.container}`);if(!n)return!0;const o=e.inputMap.get(n);return!o||Boolean(o.value?.trim())}static isEmptyData(e){return I(e.code)}static destroy(t){const n=document.getElementById(t);if(!n)return console.warn("CodeInput::destroy: Container not found for containerId:",t);n.querySelectorAll(`.${a.classNames.block.code.container}`).forEach(t=>{e.inputMap.delete(t),e.dataMap.delete(t)})}},ht=".clepit-output-code-container",gt=(e,t)=>[`${e} { background: ${t.background}; color: ${t.text}; }`,...je.map(n=>`${e} .clepit-code-${n} { color: ${t[n]};${(e=>"comment"===e?" font-style: italic;":"")(n)} }`)].join("\n"),bt=()=>[gt(ht,{background:"var(--clepit-code-bg)",comment:"var(--clepit-code-comment)",function:"var(--clepit-code-function)",gutter:"var(--clepit-code-gutter)",keyword:"var(--clepit-code-keyword)",number:"var(--clepit-code-number)",punctuation:"var(--clepit-code-punctuation)",selection:"var(--clepit-code-selection-bg)",string:"var(--clepit-code-string)",text:"var(--clepit-code-text)",type:"var(--clepit-code-type)"}),...Object.entries(_e).map(([e,t])=>gt(`${ht}[data-theme='${e}']`,t))].join("\n"),ft="clepit:code-variant-sync",yt=e=>`clepit.code-variant.${e}`,vt=(e,t)=>e.label?e.label:e.language?it[e.language]??e.language:`Tab ${t+1}`,xt="http://www.w3.org/2000/svg",kt=e=>e.variants?.length?e.variants:[{code:e.code,language:e.language}],wt=class e{static{this.eventListenersMap=new WeakMap}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap.get(t)||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap.set(t,i)}static draw(t,n=ue,a){if(!e.validate(t)||mt.isEmptyData(t))return null;const o=kt(t),i=o.length>1,r=Math.min(Math.max(a?.activeVariant??0,0),o.length-1),s=n.create("div");s.addClass("clepit-output-code-container"),s.setAttribute("data-theme",t.theme??mt.defaultTheme);const l=n.create("div");if(l.addClass("clepit-output-code-header"),i){const e=n.create("div");e.addClass("clepit-output-code-tabs"),e.setAttribute("role","tablist"),e.setAttribute("data-testid","code-variant-tabs"),o.forEach((t,a)=>{const o=n.create("button");o.addClass("clepit-output-code-tab"),o.setAttribute("type","button"),o.setAttribute("role","tab"),o.setAttribute("aria-selected",a===r?"true":"false"),o.setAttribute("tabindex",a===r?"0":"-1"),o.setAttribute("data-testid",`code-variant-tab-${a}`),o.setText(vt(t,a)),e.append(o)}),l.append(e)}else{const e=n.create("span");e.setText(it[t.language??"typescript"]??"TypeScript"),l.append(e)}if(t.showCopy){const e=n.create("button");e.addClass("clepit-output-code-copy-btn"),e.setAttribute("type","button"),e.setAttribute("aria-label","Copy code"),e.append((e=>{const t=e.createNS(xt,"svg");t.setAttribute("class","clepit-copy-icon"),t.setAttribute("width","16"),t.setAttribute("height","16"),t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("fill","none");const n=e.createNS(xt,"path");return n.setAttribute("d","M7.5 3H14.6C16.8402 3 17.9603 3 18.816 3.43597C19.5686 3.81947 20.1805 4.43139 20.564 5.18404C21 6.03969 21 7.15979 21 9.4V16.5M6.2 21H14.3C15.4201 21 15.9802 21 16.408 20.782C16.7843 20.5903 17.0903 20.2843 17.282 19.908C17.5 19.4802 17.5 18.9201 17.5 17.8V9.7C17.5 8.57989 17.5 8.01984 17.282 7.59202C17.0903 7.21569 16.7843 6.90973 16.408 6.71799C15.9802 6.5 15.4201 6.5 14.3 6.5H6.2C5.0799 6.5 4.51984 6.5 4.09202 6.71799C3.71569 6.90973 3.40973 7.21569 3.21799 7.59202C3 8.01984 3 8.57989 3 9.7V17.8C3 18.9201 3 19.4802 3.21799 19.908C3.40973 20.2843 3.71569 20.5903 4.09202 20.782C4.51984 21 5.0799 21 6.2 21Z"),n.setAttribute("stroke","var(--clepit-svg-stroke-color)"),n.setAttribute("stroke-width","2"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),t.append(n),t})(n)),l.append(e)}s.append(l);const c=n.create("div");return c.addClass("clepit-output-code-editor"),i&&c.setAttribute("role","tabpanel"),o.forEach((e,a)=>{const o=n.create("pre");o.addClass("clepit-output-code-pane"),o.setAttribute("data-variant-index",String(a)),a!==r&&o.setAttribute("hidden","");const i=n.create("code");for(const r of ot(e.code??t.code,e.language??t.language??"plaintext")){const e=n.create("span");r.classes&&e.addClass(...r.classes.split(" ")),e.setText(r.text),i.append(e)}o.append(i),c.append(o)}),s.append(c),s}static render(t,n,o,i,r){if(a.injectStyles(qe,De),a.injectStyles(`${qe}-theme`,bt()),!e.validate(t))return xe();if(mt.isEmptyData(t))return document.createElement("div");const s=kt(t),l=s.length>1?((e,t)=>{if(!t)return 0;const n=e.findIndex((e,n)=>vt(e,n)===t);return-1===n?0:n})(s,(e=>{if(!e||"undefined"==typeof localStorage)return null;try{return localStorage.getItem(yt(e))}catch{return null}})(t.syncKey)):0,c=ve(e.draw(t,ue,{activeVariant:l}));i?.container&&c.classList.add(i.container),o?.container&&Object.assign(c.style,o.container);const p=c.querySelector(".clepit-output-code-header");return p&&i?.header?.text&&p.classList.add(i.header.text),p&&o?.header?.text&&Object.assign(p.style,o.header.text),e.attach(c,t,l,r),c}static attach(t,n,a,o){const i=kt(n),r=o?document.getElementById(o):null,s=[...t.querySelectorAll(".clepit-output-code-tab")],c=[...t.querySelectorAll(".clepit-output-code-pane")];let p=a;const d=(t,n,a)=>{if(r)return e.eventListenersMap.has(r)||e.eventListenersMap.set(r,[]),void e.addEventListener(r,t,n,a);t.addEventListener(n,a)},u=(e,t)=>{if(e<0||e>=i.length)return;if(p=e,s.forEach((t,n)=>{t.setAttribute("aria-selected",n===e?"true":"false"),t.tabIndex=n===e?0:-1}),c.forEach((t,n)=>{t.hidden=n!==e}),!t||!n.syncKey)return;const a=vt(i[e],e);((e,t)=>{if(e&&"undefined"!=typeof localStorage)try{localStorage.setItem(yt(e),t)}catch{return}})(n.syncKey,a),window.dispatchEvent(new CustomEvent(ft,{detail:{label:a,syncKey:n.syncKey}}))};if(s.forEach((e,t)=>{d(e,"click",()=>u(t,!0)),d(e,"keydown",e=>{const n=e.key,a="ArrowRight"===n?1:"ArrowLeft"===n?-1:0,o="Home"===n?0:"End"===n?i.length-1:0===a?-1:(t+a+i.length)%i.length;-1!==o&&(e.preventDefault(),u(o,!0),s[o]?.focus())})}),s.length>1&&n.syncKey){const t=e=>{const t=e.detail;if(!t||t.syncKey!==n.syncKey)return;const a=i.findIndex((e,n)=>vt(e,n)===t.label);-1!==a&&a!==p&&u(a,!1)};if(window.addEventListener(ft,t),r){const n=e.eventListenersMap.get(r)??[];n.push({element:window,event:ft,handler:t}),e.eventListenersMap.set(r,n)}}const m=t.querySelector(".clepit-output-code-copy-btn");if(!m)return;d(m,"click",()=>{e.copyCodeToClipboard(i[p]?.code??n.code),e.animateCopyButton(m)});const h=o?l.getState().getInstance(o):null;J(m,"Copy code","above",h?.config.classNames?.tooltips,h?.config.styles?.tooltips)}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.code}static copyCodeToClipboard(e){navigator.clipboard&&window.isSecureContext?navigator.clipboard.writeText(e).catch(e=>{console.error("Failed to copy code to clipboard:",e)}):console.warn("Clipboard API not available in this context")}static animateCopyButton(e){const t=e.innerHTML;e.innerHTML='<svg class="clepit-check-icon" focusable="false" aria-hidden="true" viewBox="0 0 24 24" data-testid="CheckIcon"><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"></path></svg>',e.classList.remove("clepit-output-code-copy-btn--normal"),e.classList.add("clepit-output-code-copy-btn--animating"),setTimeout(()=>{e.innerHTML=t,e.classList.remove("clepit-output-code-copy-btn--animating"),e.classList.add("clepit-output-code-copy-btn--normal")},1e3)}static destroy(t){const n=document.getElementById(t);if(!n)return console.warn("CodeOutput::destroy: Container not found for containerId:",t);const a=e.eventListenersMap.get(n);a&&(a.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap.delete(n))}},Ct={icon:"𝕔",get input(){return mt},label:"Code",get output(){return wt},shortcut:v("C"),testId:"block-type-code",type:"code"},Et="\n.clepit-collapsible {\n display: block;\n}\n.clepit-collapsible > summary {\n display: flex;\n align-items: flex-start;\n gap: 6px;\n cursor: pointer;\n font-weight: 600;\n list-style: none;\n}\n.clepit-collapsible > summary::-webkit-details-marker {\n display: none;\n}\n.clepit-collapsible > summary::before {\n content: '';\n flex: 0 0 auto;\n width: 8px;\n height: 8px;\n margin-top: 7px;\n border-right: 2px solid currentColor;\n border-bottom: 2px solid currentColor;\n transform: rotate(-45deg);\n transition: transform 120ms ease;\n}\n.clepit-collapsible[open] > summary::before {\n transform: rotate(45deg);\n}\n.clepit-collapsible__children {\n padding-left: 22px;\n}\n.clepit-collapsible__children > * + * {\n margin-top: 8px;\n}\n",St=`${Et}\n.clepit-collapsible__title-input {\n border: none;\n outline: none;\n background: transparent;\n font: inherit;\n font-weight: 600;\n width: 100%;\n}\n.clepit-collapsible__add-child {\n border: none;\n background: transparent;\n cursor: pointer;\n font: inherit;\n opacity: 0.6;\n padding: 4px 0;\n}\n.clepit-collapsible__add-child:hover {\n opacity: 1;\n}\n.clepit-collapsible__child-row {\n display: flex;\n align-items: flex-start;\n gap: 4px;\n}\n.clepit-collapsible__child-row > :first-child {\n flex: 1 1 auto;\n}\n.clepit-collapsible__remove-child {\n border: none;\n background: transparent;\n cursor: pointer;\n opacity: 0.4;\n padding: 2px;\n}\n.clepit-collapsible__remove-child:hover {\n opacity: 1;\n}\n`,Nt=Et,At=new WeakMap;var Lt=class e{static{this.placeholder="Section title"}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.classList.contains("clepit-collapsible")?e:e.querySelector(".clepit-collapsible");if(!t)return{children:[],html:"",open:!1};const n=t.querySelector(".clepit-collapsible__title"),a=t.open??!1,o=At.get(t)??[],i=[];return t.querySelectorAll(".clepit-collapsible__child").forEach((e,t)=>{const n=o[t],a=e.getAttribute("data-child-type")??n?.type,r=a?function(e){return Xi.find(t=>t.type===e)}(a):void 0;if(r){const t=r.input.save(e);i.push({...n?.id?{id:n.id}:{},data:t,type:r.type})}else n&&i.push(n)}),{children:i,html:M(n?.innerHTML),open:a}}static render(t,n,o){a.injectStyles("collapsible-input",St);const i={children:[],html:"",open:!0},r=n?{...i,...n}:i,s=a.createStyledElement("details","clepit-collapsible clepit-collapsible--input",{classNames:o?.classNames?.section,styles:o?.styles?.section});s.open=r.open??!0,At.set(s,[...r.children??[]]);const l=document.createElement("summary"),c=document.createElement("span");c.className="clepit-collapsible__title",c.setAttribute("contenteditable","true"),c.setAttribute("data-placeholder",e.placeholder),r.html&&(c.innerHTML=M(r.html)),l.appendChild(c),s.appendChild(l);const p=document.createElement("div");return p.className="clepit-collapsible__children",(r.children??[]).forEach(n=>{p.appendChild(e.renderChild(t,n))}),s.appendChild(p),e.addEventListener(t,c,"keydown",or.handleKeydown),e.addEventListener(t,c,"input",or.handleInput),s}static renderChild(e,t){const n=document.createElement("div");n.className="clepit-collapsible__child";const a=or.renderTool(t.type,t.data,e);if(a)n.setAttribute("data-child-type",t.type),n.appendChild(a);else{const e=document.createElement("div");e.className="clepit-collapsible__unknown-child",e.textContent=`Unsupported block: ${t.type}`,n.appendChild(e)}return n}static isEmpty(e){const t=e.querySelector(".clepit-collapsible");if(!t)return!0;const n=t.querySelector(".clepit-collapsible__title"),a=t.querySelectorAll(".clepit-collapsible__child").length>0;return I(n?.innerHTML)&&!a}static isEmptyData(e){return I(e.html)&&0===(e.children??[]).length}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Bt="\n.clepit-collection {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 12px;\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n color: inherit;\n}\n.clepit-collection__icon {\n font-size: 18px;\n line-height: 1;\n}\n.clepit-collection__label {\n opacity: 0.7;\n}\n",$t=Bt,It=Bt,Mt=class e{static render(t,n,o,i){if(a.injectStyles("collection-output",It),!e.validate(t))return xe();const r=a.createStyledElement("div","clepit-collection clepit-output-collection",{classNames:i?.wrapper,styles:o?.wrapper});r.setAttribute("data-collection-id",t.collectionId);const s=document.createElement("span");s.className="clepit-collection__icon",s.textContent="▦",r.appendChild(s);const l=document.createElement("span");return l.className="clepit-collection__label",l.textContent="Collection",r.appendChild(l),r}static draw(t,n=ue){if(!e.validate(t))return null;const a=n.create("div");a.addClass("clepit-collection","clepit-output-collection"),a.setAttribute("data-collection-id",t.collectionId);const o=n.create("span");o.addClass("clepit-collection__icon"),o.setText("▦"),a.append(o);const i=n.create("span");return i.addClass("clepit-collection__label"),i.setText("Collection"),a.append(i),a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.collectionId&&e.collectionId.length>0}},Tt="\n.clepit-columns {\n display: flex;\n gap: 16px;\n align-items: flex-start;\n}\n.clepit-columns__column {\n flex: 1 1 0;\n min-width: 0;\n}\n.clepit-columns__column > * + * {\n margin-top: 8px;\n}\n@media (max-width: 640px) {\n .clepit-columns {\n flex-direction: column;\n }\n}\n",qt=`${Tt}\n.clepit-columns__add-child,\n.clepit-columns__add-column {\n border: none;\n background: transparent;\n cursor: pointer;\n font: inherit;\n opacity: 0.6;\n padding: 4px 0;\n}\n.clepit-columns__add-child:hover,\n.clepit-columns__add-column:hover {\n opacity: 1;\n}\n`,Dt=Tt,_t=class e{static render(t,n,o,i){if(a.injectStyles("columns-output",Dt),!e.validate(t))return xe();const r=a.createStyledElement("div","clepit-columns clepit-output-columns",{classNames:i?.container,styles:o?.container});for(const s of t.columns){const t=a.createStyledElement("div","clepit-columns__column",{classNames:i?.column,styles:o?.column});for(const a of s)t.appendChild(e.renderChild(a,n));r.appendChild(t)}return r}static renderChild(e,t){const n=Xi.find(t=>t.type===e.type);if(!n){const t=document.createElement("div");return t.className="clepit-columns__unknown-child",t.textContent=`Unsupported block: ${e.type}`,t}return n.output.render(e.data,t)}static draw(t,n=ue,a){if(!e.validate(t))return null;const o=n.create("div");o.addClass("clepit-columns","clepit-output-columns");for(const e of t.columns){const t=n.create("div");t.addClass("clepit-columns__column");for(const o of e){const e=ti(o,n,a);e&&t.append(e)}o.append(t)}return o}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&Array.isArray(e.columns)&&e.columns.length>=2&&e.columns.length<=4&&e.columns.every(e=>Array.isArray(e))}},jt="\n.clepit-date {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n padding: 2px 8px;\n border-radius: 6px;\n background: rgba(127, 127, 127, 0.12);\n font-variant-numeric: tabular-nums;\n}\n",zt=`${jt}\n.clepit-date--input {\n cursor: pointer;\n border: none;\n font: inherit;\n}\n`,Ot=jt,Ht=/^(\d{4})-(\d{2})-(\d{2})$/;function Pt(e){const t=Ht.exec(e.trim());if(!t)return null;const n=Number(t[1]),a=Number(t[2]),o=Number(t[3]),i=new Date(Date.UTC(n,a-1,o));return i.getUTCFullYear()!==n||i.getUTCMonth()!==a-1||i.getUTCDate()!==o?null:i}var Rt=class e{static render(t,n,o,i){a.injectStyles("date-output",Ot);const r=e.validate(t)?Pt(t.date):null;if(!r)return xe();const s=a.createStyledElement("time","clepit-date clepit-output-date",{classNames:i?.pill,styles:o?.pill});return s.dateTime=t.date,s.textContent=new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeZone:"UTC"}).format(r),s}static draw(t,n=ue){const a=e.validate(t)?Pt(t.date):null;if(!a)return null;const o=n.create("time");return o.addClass("clepit-date","clepit-output-date"),o.setAttribute("datetime",t.date),o.setText(new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeZone:"UTC"}).format(a)),o}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.date}},Ft='\n/* Output delimiter styles */\n.clepit-output-delimiter {\n margin: 2rem 0;\n text-align: center;\n}\n\n.clepit-output-delimiter[data-variant="stars"] {\n font-size: 1.5rem;\n font-weight: 300;\n letter-spacing: 8px;\n margin: 0; /* Remove margin for star variant */\n}\n\n.clepit-output-delimiter hr[data-variant="line"] {\n border: none;\n height: 2px;\n background: linear-gradient(to right, transparent, var(--clepit-border), transparent);\n margin: 20px 0;\n}\n\n.clepit-output-delimiter[data-variant="line"] {\n margin: 0; /* Remove container margin for line variant */\n}\n',Vt=class e{static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){return{variant:e.querySelector(".clepit-delimiter")?.getAttribute("data-variant")||"line"}}static render(t,n,o){a.injectStyles("clepit-delimiter-input-styles",'\n/* Delimiter block styles */\n.clepit-delimiter-container {\n margin: 0.5rem 0;\n text-align: center;\n}\n\n.clepit-delimiter {\n border: none;\n height: 2px;\n background: linear-gradient(to right, transparent, var(--clepit-border), transparent);\n margin: 20px 0;\n}\n\n.clepit-delimiter[data-variant="stars"] {\n height: auto;\n background: none;\n font-size: 24px;\n letter-spacing: 8px;\n margin: 0; /* Remove margin for star variant */\n}\n\n');const i={variant:"line"},r=n?{...i,...n}:i,s=a.createStyledElement("div","clepit-delimiter-container",{classNames:o?.classNames?.[r.variant],styles:o?.styles?.[r.variant]});if(s.setAttribute("contenteditable","true"),s.setAttribute("tabindex","0"),"stars"===r.variant){const e=a.createStyledElement("div","clepit-delimiter",{classNames:o?.classNames?.[r.variant],styles:o?.styles?.[r.variant]});e.setAttribute("data-variant",r.variant),e.textContent="***",s.appendChild(e)}else{const e=a.createStyledElement("hr","clepit-delimiter",{classNames:o?.classNames?.[r.variant],styles:o?.styles?.[r.variant]});e.setAttribute("data-variant",r.variant),s.appendChild(e)}return e.addEventListener(t,s,"keydown",e=>{const n=e,o=s.closest(`.${a.classNames.block.container}`);if(!o)return;const i=or.getBlockIndex(t,o.getAttribute("data-id")),r=n.metaKey||n.ctrlKey;if(n.shiftKey)switch(n.key){case"ArrowUp":e.preventDefault(),e.stopPropagation(),i>0&&or.moveBlock(t,i,i-1);break;case"ArrowDown":e.preventDefault(),e.stopPropagation();const n=or.getBlocks(t);n&&i<n.length-1&&or.moveBlock(t,i,i+1)}else if(r)switch(n.key){case"Delete":case"Backspace":e.preventDefault(),e.stopPropagation(),or.removeBlock(t,i)}else if("Enter"===n.key)n.preventDefault(),n.stopPropagation(),or.insertBlock({data:{html:""},type:"paragraph"},t,i+1);else if("Backspace"===n.key)n.preventDefault(),n.stopPropagation(),or.removeBlock(t,i);else{or.ensureActiveBlock(t);const a=or.getBlocks(t);switch(n.key){case"ArrowUp":if(e.preventDefault(),e.stopPropagation(),i>0){const e=a[i-1];e&&or.focusBlock(e)}return;case"ArrowDown":if(e.preventDefault(),e.stopPropagation(),i<a.length-1){const e=a[i+1];e&&or.focusBlock(e)}return}}}),s.focus(),s}static changeVariant(t,n,o){const i=l.getState().getInstance(o);if(!i)return;if(t.getAttribute("data-variant")===n)return;const r={variant:n},s={classNames:i.config.classNames?.blocks?.delimiter,styles:i.config.styles?.blocks?.delimiter},c=or.getBlockIndex(o,t.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id")),p=e.render(o,r,s);t.replaceWith(p),l.getState().updateBlockData(o,c,r)}static isEmpty(e){return!1}static isEmptyData(e){return!1}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Ut=class e{static render(t,n,o,i){if(a.injectStyles("clepit-delimiter-output-styles",Ft),!e.validate(t))return xe();if(Vt.isEmptyData(t))return document.createElement("div");const r=t.variant,s=a.createStyledElement("div","clepit-output-delimiter",{classNames:i?.[r],styles:o?.[r]});if("stars"===r)s.innerHTML="***",s.setAttribute("data-variant","stars");else{const e=document.createElement("hr");e.setAttribute("data-variant","line"),e.className="clepit-delimiter",s.appendChild(e)}return s}static draw(t,n=ue){if(!e.validate(t)||Vt.isEmptyData(t))return null;const a=n.create("div");if(a.addClass("clepit-output-delimiter"),"stars"===t.variant)return a.setHtml("***"),a.setAttribute("data-variant","stars"),a;const o=n.create("hr");return o.setAttribute("data-variant","line"),o.addClass("clepit-delimiter"),a.append(o),a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.variant}},Wt="\n.clepit-doc-card {\n display: flex;\n align-items: flex-start;\n gap: 10px;\n padding: 12px;\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n cursor: pointer;\n color: inherit;\n text-decoration: none;\n}\n.clepit-doc-card:hover {\n background: rgba(127, 127, 127, 0.08);\n}\n.clepit-doc-card__icon {\n font-size: 20px;\n line-height: 1;\n}\n.clepit-doc-card__title {\n font-weight: 600;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.clepit-doc-card__description {\n opacity: 0.7;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n overflow: hidden;\n}\n",Kt=Wt,Gt=Wt,Jt=class e{static render(t,n,o,i){if(a.injectStyles("doc-card-output",Gt),!e.validate(t))return xe();const r=a.createStyledElement("a","clepit-doc-card clepit-output-doc-card",{classNames:i?.card,styles:o?.card});r.setAttribute("data-page-id",t.pageId),n?.docHref&&(r.href=n.docHref(t.pageId));const s=document.createElement("span");s.className="clepit-doc-card__icon",s.textContent=t.icon??"📄",r.appendChild(s);const l=document.createElement("span"),c=document.createElement("span");if(c.className="clepit-doc-card__title",c.textContent=t.title||"Untitled",l.appendChild(c),t.description){const e=document.createElement("span");e.className="clepit-doc-card__description",e.textContent=t.description,l.appendChild(e)}return r.appendChild(l),r}static draw(t,n=ue,a){if(!e.validate(t))return null;const o=n.create("a");o.addClass("clepit-doc-card","clepit-output-doc-card"),o.setAttribute("data-page-id",t.pageId),a?.docHref&&o.setAttribute("href",a.docHref(t.pageId));const i=n.create("span");i.addClass("clepit-doc-card__icon"),i.setText(t.icon??"📄"),o.append(i);const r=n.create("span"),s=n.create("span");if(s.addClass("clepit-doc-card__title"),s.setText(t.title||"Untitled"),r.append(s),t.description){const e=n.create("span");e.addClass("clepit-doc-card__description"),e.setText(t.description),r.append(e)}return o.append(r),o}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.pageId&&e.pageId.length>0&&"string"==typeof e.title}},Xt="\n.clepit-embed {\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n overflow: hidden;\n}\n.clepit-embed__frame {\n display: block;\n width: 100%;\n border: 0;\n}\n.clepit-embed-card {\n display: flex;\n align-items: flex-start;\n gap: 10px;\n padding: 12px;\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n color: inherit;\n text-decoration: none;\n}\n.clepit-embed-card:hover {\n background: rgba(127, 127, 127, 0.08);\n}\n.clepit-embed-card__title {\n font-weight: 600;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.clepit-embed-card__description {\n opacity: 0.7;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n overflow: hidden;\n}\n",Zt=Xt,Yt=Xt,Qt=["http:","https:"],en=["youtube.com","www.youtube.com","m.youtube.com","youtu.be"],tn=["file","design","board","proto","slides","deck"],nn=(e,t="link")=>({embedUrl:null,provider:t,url:e});function an(e,t){return e===t||e.endsWith(`.${t}`)}function on(e,t){const n=function(e){try{const t=new URL(e);return Qt.includes(t.protocol)?t:null}catch{return null}}(e);if(!n)return{embedUrl:null,provider:"invalid",url:e};const a=n.hostname.toLowerCase(),o=n.toString();if(en.includes(a)){const e=function(e){if(an(e.hostname,"youtu.be"))return e.pathname.slice(1).split("/")[0]||null;if("/watch"===e.pathname)return e.searchParams.get("v");const t=e.pathname.match(/^\/(?:embed|shorts|live)\/([^/]+)/);return t?t[1]:null}(n);return e?{aspect:16/9,embedUrl:`https://www.youtube.com/embed/${encodeURIComponent(e)}`,provider:"youtube",url:o}:nn(o,"youtube")}if(an(a,"figma.com")){const[,e,t]=n.pathname.split("/");return e&&t&&tn.includes(e)?{aspect:4/3,embedUrl:`https://embed.figma.com/${"file"===e?"design":e}/${encodeURIComponent(t)}?embed-host=clepit`,provider:"figma",url:o}:nn(o,"figma")}if(an(a,"miro.com")){const e=n.pathname.match(/^\/app\/board\/([^/]+)/);return e?{aspect:16/9,embedUrl:`https://miro.com/app/live-embed/${encodeURIComponent(e[1])}`,provider:"miro",url:o}:nn(o,"miro")}if(an(a,"airtable.com")){const e=n.pathname.match(/^\/embed\/([^/]+)/),t=n.pathname.match(/^\/(shr[^/]+)/),a=e?.[1]??t?.[1];return a?{aspect:4/3,embedUrl:`https://airtable.com/embed/${encodeURIComponent(a)}`,provider:"airtable",url:o}:nn(o,"airtable")}if(an(a,"diagrams.net")||an(a,"drawio.com"))return{aspect:4/3,embedUrl:`https://viewer.diagrams.net/?edit=_blank&layers=1&nav=1#U${encodeURIComponent(o)}`,provider:"drawio",url:o};if(an(a,"google.com")&&n.pathname.startsWith("/maps")){const e=t?.mapsEmbedKey,a=n.searchParams.get("q");return e&&a?{aspect:4/3,embedUrl:`https://www.google.com/maps/embed/v1/place?key=${encodeURIComponent(e)}&q=${encodeURIComponent(a)}`,provider:"googleMaps",url:o}:nn(o,"googleMaps")}return nn(o)}var rn="allow-scripts allow-same-origin allow-presentation allow-forms",sn=class e{static render(t,n,o,i){if(a.injectStyles("embed-output",Yt),!e.validate(t))return xe();const r=on(t.url,{mapsEmbedKey:n?.mapsEmbedKey});return"invalid"===r.provider?xe():r.embedUrl?e.frame(r.embedUrl,r.aspect,o,i):e.card(t,r.url,o,i)}static draw(t,n=ue,a){if(!e.validate(t))return null;const o=on(t.url,{mapsEmbedKey:a?.mapsEmbedKey});return"invalid"===o.provider?null:o.embedUrl?e.drawFrame(o.embedUrl,o.aspect,n):e.drawCard(t,o.url,n)}static drawFrame(e,t,n){const a=n.create("div");a.addClass("clepit-embed","clepit-output-embed");const o=n.create("iframe");return o.addClass("clepit-embed__frame"),o.setAttribute("src",e),o.setAttribute("sandbox",rn),o.setAttribute("referrerpolicy","no-referrer"),o.setAttribute("loading","lazy"),o.setAttribute("allowfullscreen","true"),o.setAttribute("style",`aspect-ratio: ${t??16/9};`),a.append(o),a}static drawCard(e,t,n){const a=n.create("a");a.addClass("clepit-embed-card","clepit-output-embed"),a.setAttribute("href",t),a.setAttribute("rel","noopener noreferrer nofollow"),a.setAttribute("target","_blank");const o=n.create("span"),i=n.create("span");if(i.addClass("clepit-embed-card__title"),i.setText(e.title||t),o.append(i),e.description){const t=n.create("span");t.addClass("clepit-embed-card__description"),t.setText(e.description),o.append(t)}return a.append(o),a}static frame(e,t,n,o){const i=a.createStyledElement("div","clepit-embed clepit-output-embed",{classNames:o?.wrapper,styles:n?.wrapper}),r=document.createElement("iframe");return r.className="clepit-embed__frame",r.src=e,r.setAttribute("sandbox",rn),r.setAttribute("referrerpolicy","no-referrer"),r.setAttribute("loading","lazy"),r.setAttribute("allowfullscreen","true"),r.style.aspectRatio=String(t??16/9),i.appendChild(r),i}static card(e,t,n,o){const i=a.createStyledElement("a","clepit-embed-card clepit-output-embed",{classNames:o?.card,styles:n?.card});i.href=t,i.rel="noopener noreferrer nofollow",i.target="_blank";const r=document.createElement("span"),s=document.createElement("span");if(s.className="clepit-embed-card__title",s.textContent=e.title||t,r.appendChild(s),e.description){const t=document.createElement("span");t.className="clepit-embed-card__description",t.textContent=e.description,r.appendChild(t)}return i.appendChild(r),i}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.url&&e.url.length>0}},ln="\n.clepit-file {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 10px 12px;\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n color: inherit;\n text-decoration: none;\n}\n.clepit-file:hover {\n background: rgba(127, 127, 127, 0.08);\n}\n.clepit-file__name {\n font-weight: 500;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.clepit-file__size {\n opacity: 0.6;\n font-size: 12px;\n}\n",cn=`${ln}\n.clepit-file__upload {\n border: 1px dashed rgba(127, 127, 127, 0.5);\n background: transparent;\n cursor: pointer;\n font: inherit;\n padding: 10px 12px;\n border-radius: 8px;\n}\n`,pn=ln;function dn(e){return null==e?"":e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}var un=class e{static render(t,n,o,i){if(a.injectStyles("file-output",pn),!e.validate(t))return xe();const r=a.createStyledElement("a","clepit-file clepit-output-file",{classNames:i?.row,styles:o?.row});r.href=t.url,r.setAttribute("download",t.name),r.setAttribute("rel","noopener noreferrer");const s=document.createElement("span");s.className="clepit-file__name",s.textContent=t.name,r.appendChild(s);const l=dn(t.size);if(l){const e=document.createElement("span");e.className="clepit-file__size",e.textContent=l,r.appendChild(e)}return r}static draw(t,n=ue){if(!e.validate(t))return null;const a=n.create("a");a.addClass("clepit-file","clepit-output-file"),a.setAttribute("href",t.url),a.setAttribute("download",t.name),a.setAttribute("rel","noopener noreferrer");const o=n.create("span");o.addClass("clepit-file__name"),o.setText(t.name),a.append(o);const i=dn(t.size);if(i){const e=n.create("span");e.addClass("clepit-file__size"),e.setText(i),a.append(e)}return a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&("string"==typeof e.url&&0!==e.url.length&&("string"==typeof e.name&&0!==e.name.length&&/^https?:\/\//i.test(e.url)))}},mn='\n.clepit-glance {\n background: var(--clepit-surface);\n border: 1px solid var(--clepit-border);\n border-radius: 8px;\n padding: 12px 14px;\n}\n\n/* A variant tints the surface only. Text keeps the reading colours the rest of\n * the page uses, so a glance stays as legible as the prose around it. */\n.clepit-glance[data-variant="info"] {\n background: var(--clepit-primary-bg);\n}\n\n.clepit-glance[data-variant="success"] {\n background: var(--clepit-success-bg);\n}\n\n.clepit-glance[data-variant="warning"] {\n background: var(--clepit-warning-bg);\n}\n\n.clepit-glance[data-variant="error"] {\n background: var(--clepit-error-bg);\n}\n\n.clepit-glance-caption {\n color: var(--clepit-text-subtle);\n font-size: 11px;\n font-weight: 700;\n letter-spacing: 0.08em;\n margin: 0 0 8px;\n text-transform: uppercase;\n}\n\n/* Labels form a single vertical rail whatever their length, so the reader scans\n * one column for the question and one for the answer. */\n.clepit-glance-rows {\n column-gap: 16px;\n display: grid;\n grid-template-columns: max-content 1fr;\n margin: 0;\n row-gap: 4px;\n}\n\n.clepit-glance-label {\n color: var(--clepit-text-subtle);\n font-size: 14px;\n}\n\n.clepit-glance-value {\n color: var(--clepit-text);\n font-size: 14px;\n margin: 0;\n}\n\n.clepit-glance-value code {\n background: var(--clepit-code-bg);\n border-radius: 4px;\n font-family: \'SF Mono\', \'Monaco\', \'Roboto Mono\', monospace;\n font-size: 13px;\n padding: 1px 5px;\n}\n\n.clepit-glance-value a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-glance-value a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* A single-column stack below the narrowest tablet: a max-content label column\n * squeezes the value to a few characters once the viewport is phone width. */\n@media (max-width: 600px) {\n .clepit-glance-rows {\n grid-template-columns: 1fr;\n row-gap: 2px;\n }\n\n .clepit-glance-value {\n margin: 0 0 6px;\n }\n}\n',hn="At a glance",gn=class e{static render(t,n,o,i){if(a.injectStyles("clepit-glance-output-styles",mn),!e.validate(t))return xe();if(0===t.rows.length)return document.createElement("div");const r=a.createStyledElement("div","clepit-glance",{classNames:i?.wrapper,styles:o?.wrapper});r.setAttribute("data-variant",t.variant??"plain"),r.setAttribute("data-testid","glance");const s=B("p","clepit-glance-caption");s.textContent=t.caption?.trim()?t.caption:hn,r.appendChild(s);const l=B("dl","clepit-glance-rows");for(const e of t.rows){const t=B("dt","clepit-glance-label");t.textContent=e.label,l.appendChild(t);const n=B("dd","clepit-glance-value");n.innerHTML=M(e.html),l.appendChild(n)}return r.appendChild(l),r}static draw(t,n=ue){if(!e.validate(t)||0===t.rows.length)return null;const a=n.create("div");a.addClass("clepit-glance"),a.setAttribute("data-variant",t.variant??"plain"),a.setAttribute("data-testid","glance");const o=n.create("p");o.addClass("clepit-glance-caption"),o.setText(t.caption?.trim()?t.caption:hn),a.append(o);const i=n.create("dl");i.addClass("clepit-glance-rows");for(const e of t.rows){const t=n.create("dt");t.addClass("clepit-glance-label"),t.setText(e.label),i.append(t);const a=n.create("dd");a.addClass("clepit-glance-value"),a.setHtml(e.html),i.append(a)}return a.append(i),a}static validate(e){return null!=e&&"object"==typeof e&&(!!Array.isArray(e.rows)&&e.rows.every(e=>null!==e&&"object"==typeof e&&"string"==typeof e.label&&"string"==typeof e.html))}},bn='\n/* Output header styles */\n.clepit-output-header {\n margin: 0 0 1rem 0;\n font-weight: 600;\n color: var(--clepit-text);\n}\n\n.clepit-output-header[data-level="1"] {\n font-size: 2.5rem;\n line-height: 1.2;\n}\n\n.clepit-output-header[data-level="2"] {\n font-size: 2rem;\n line-height: 1.3;\n}\n\n.clepit-output-header[data-level="3"] {\n font-size: 1.75rem;\n line-height: 1.4;\n}\n\n.clepit-output-header[data-level="4"] {\n font-size: 1.5rem;\n line-height: 1.4;\n}\n\n.clepit-output-header[data-level="5"] {\n font-size: 1.25rem;\n line-height: 1.4;\n}\n\n.clepit-output-header[data-level="6"] {\n font-size: 1rem;\n line-height: 1.4;\n}\n\n/* Output header inline code styling */\n.clepit-output-header code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Output header marker brush effect */\n.clepit-output-header mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n\n.clepit-output-header mark::before {\n content: \'\';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 100 20\' preserveAspectRatio=\'none\'><path d=\'M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z\' fill=\'%23FFE047\'/></svg>") no-repeat center / 100% 100%;\n z-index: -1;\n}\n\n/* Output header link styles */\n.clepit-output-header a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-output-header a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Responsive Design */\n@media (max-width: 768px) {\n .clepit-output-header[data-level="1"] {\n font-size: 2rem;\n }\n\n .clepit-output-header[data-level="2"] {\n font-size: 1.75rem;\n }\n\n .clepit-output-header[data-level="3"] {\n font-size: 1.5rem;\n }\n}\n',fn=class e{static{this.placeholder="Enter heading..."}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.querySelector(`.${a.classNames.block.header}`),n=t?.getAttribute("data-level")||"h1";return{html:M(t?.innerHTML),level:n}}static render(t,n,o){a.injectStyles("clepit-header-input-styles",'\n/* Header block styles */\n.clepit-header {\n outline: none;\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0 20px;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content {\n font-weight: bold;\n margin: 16px 0 8px 0;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content h1 {\n font-size: 32px;\n margin: 0;\n color: inherit;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content h2 {\n font-size: 24px;\n margin: 0;\n color: inherit;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content h3 {\n font-size: 20px;\n margin: 0;\n color: inherit;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content h4 {\n font-size: 18px;\n margin: 0;\n color: inherit;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content h5 {\n font-size: 16px;\n margin: 0;\n color: inherit;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content h6 {\n font-size: 14px;\n margin: 0;\n color: inherit;\n}\n\n/* Header placeholder styles */\n.clepit-header[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Header link styles */\n.clepit-header a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-header a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Header inline code styling */\n.clepit-header code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Header marker brush effect */\n.clepit-header mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0; /* create stacking context so ::before sits behind text, not page */\n white-space: pre-wrap; /* ensure leading/trailing spaces inside mark render */\n}\n\n.clepit-header mark::before {\n content: \'\';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 100 20\' preserveAspectRatio=\'none\'><path d=\'M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z\' fill=\'%23FFE047\'/></svg>") no-repeat center / 100% 100%;\n z-index: -1; /* behind text but within mark\'s stacking context */\n}\n\n');const i={html:"",level:"h1"},r=n?{...i,...n}:i,s=r.level??"h1",l=a.createStyledElement(s,a.classNames.block.header,{classNames:o?.classNames?.[s],styles:o?.styles?.[s]});return l.setAttribute("data-level",s),l.setAttribute("contenteditable","true"),l.setAttribute("data-placeholder",e.placeholder),r.html?l.innerHTML=r.html:l.innerHTML="",e.addEventListener(t,l,"keydown",or.handleKeydown),e.addEventListener(t,l,"input",or.handleInput),l}static changeLevel(t,n,o){const i=l.getState().getInstance(o);if(!i)return;if(t.getAttribute("data-level")===n)return;const r={html:t.innerHTML,level:n},s={classNames:i.config.classNames?.blocks?.header,margins:i.config.margins,styles:i.config.styles?.blocks?.header},c=or.getBlockIndex(o,t.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id")),p=e.render(o,r,s);t.replaceWith(p),l.getState().updateBlockData(o,c,r)}static isEmpty(e){return I(e.querySelector(`.${a.classNames.block.header}`)?.innerHTML)}static isEmptyData(e){return I(e.html)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},yn=class e{static render(t,n,o,i){if(a.injectStyles("clepit-header-output-styles",bn),!e.validate(t))return xe();if(fn.isEmptyData(t))return document.createElement("div");const r=t.html,s=t.level||"h1",l=a.createStyledElement(s,"clepit-output-header",{classNames:i?.[s],styles:o?.[s]});return r&&(l.innerHTML=r),l}static draw(t,n=ue){if(!e.validate(t)||fn.isEmptyData(t))return null;const a=n.create(t.level||"h1");return a.addClass("clepit-output-header"),t.html&&a.setHtml(t.html),a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.html}},vn=`\n/* Image block styles */\n.${a.classNames.block.image.container} {\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0;\n}\n\n.clepit-image-caption {\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0;\n}\n\n.clepit-block[data-tool="image"] .clepit-block-content {\n text-align: center;\n}\n\n.clepit-block[data-tool="image"] .clepit-block-content img {\n max-width: 100%;\n height: auto;\n border-radius: 4px;\n}\n\n/* Image Block Enhanced Styles */\n.${a.classNames.block.image.container} {\n margin: 16px 0;\n text-align: center;\n min-height: 120px;\n position: relative;\n display: block;\n width: 100%;\n box-sizing: border-box;\n}\n\n.${a.classNames.block.image.wrapper} {\n display: flex;\n position: relative;\n cursor: pointer;\n transition: opacity 0.2s ease;\n outline: none;\n}\n\n.${a.classNames.block.image.wrapper}:hover {\n opacity: 0.9;\n}\n\n.clepit-image {\n max-width: 100%;\n height: auto;\n border-radius: 8px;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);\n display: block;\n}\n\n.clepit-image-caption-container {\n margin-top: 12px;\n text-align: center;\n}\n\n.clepit-image-caption-label {\n font-size: 12px;\n color: var(--clepit-text-muted);\n margin-bottom: 4px;\n font-weight: 500;\n}\n\n.clepit-image-caption-input {\n width: 100%;\n max-width: 400px;\n padding: 8px 12px;\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n font-size: 14px;\n background: var(--clepit-bg);\n outline: none;\n transition: border-color 0.2s ease;\n pointer-events: auto;\n user-select: text;\n}\n\n.clepit-image-caption-input:focus {\n border-color: var(--clepit-primary);\n box-shadow: 0 0 0 2px var(--clepit-primary-bg);\n}\n\n/* Image caption styling */\n.clepit-image-caption-editable {\n border: 1px solid var(--clepit-border-subtle);\n border-radius: 4px;\n padding: 8px 12px;\n min-height: 40px;\n font-size: 14px;\n line-height: 1.4;\n outline: none;\n transition: border-color 0.2s ease;\n}\n\n/* Image caption placeholder styles */\n.clepit-image-caption-editable[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Image Drop Area */\n.${a.classNames.block.image.dropArea} {\n border: 2px dashed var(--clepit-border);\n border-radius: 8px;\n padding: 40px 20px;\n text-align: center;\n background: var(--clepit-surface);\n cursor: pointer;\n transition: all 0.2s ease;\n margin: 16px 0;\n user-select: none;\n pointer-events: auto;\n outline: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n position: relative;\n min-height: 120px;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n}\n\n.${a.classNames.block.image.dropArea}:hover {\n border-color: var(--clepit-primary);\n background: var(--clepit-surface);\n}\n\n.clepit-image-drop-area--dragover {\n border-color: var(--clepit-primary);\n background: var(--clepit-primary-bg);\n transform: scale(1.02);\n}\n\n.clepit-image-drop-icon {\n font-size: 48px;\n margin-bottom: 16px;\n opacity: 0.6;\n}\n\n.clepit-image-drop-text {\n font-size: 16px;\n color: var(--clepit-text-muted);\n line-height: 1.5;\n margin-bottom: 8px;\n}\n\n.clepit-image-drop-subtext {\n font-size: 14px;\n color: var(--clepit-text-subtle);\n line-height: 1.4;\n}\n\n.clepit-image-click-text {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n}\n\n/* Image Loading State */\n.clepit-image-loading {\n text-align: center;\n padding: 40px 20px;\n margin: 16px 0;\n}\n\n.clepit-image-loading-spinner {\n width: 32px;\n height: 32px;\n border: 3px solid var(--clepit-surface);\n border-top: 3px solid var(--clepit-primary);\n border-radius: 50%;\n animation: spin 1s linear infinite;\n margin: 0 auto 16px;\n}\n\n@keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n}\n\n.clepit-image-loading-text {\n font-size: 14px;\n color: var(--clepit-text-muted);\n}\n\n/* Image Error State */\n.clepit-image-error {\n text-align: center;\n padding: 20px;\n margin: 16px 0;\n border: 1px solid var(--clepit-error);\n border-radius: 8px;\n background: var(--clepit-error-bg);\n}\n\n.clepit-image-error-icon {\n font-size: 24px;\n margin-bottom: 8px;\n}\n\n.clepit-image-error-text {\n font-size: 14px;\n color: var(--clepit-error);\n margin-bottom: 12px;\n}\n\n.clepit-image-error-retry {\n background: var(--clepit-error);\n color: white;\n border: none;\n padding: 8px 16px;\n border-radius: 4px;\n cursor: pointer;\n font-size: 14px;\n transition: background-color 0.2s ease;\n}\n\n.clepit-image-error-retry:hover {\n background: var(--clepit-error);\n}\n\n/* Image delete button */\n.${a.classNames.block.imageDeleteBtn} {\n position: absolute;\n top: 8px;\n right: 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 50%;\n width: 24px;\n height: 24px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: var(--clepit-bg);\n cursor: pointer;\n color: var(--clepit-text-muted);\n transition: color 0.2s ease;\n}\n\n.${a.classNames.block.imageDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Image drop area delete button */\n.clepit-image-drop-area .${a.classNames.block.imageDeleteBtn} {\n position: absolute;\n top: 8px;\n right: 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 50%;\n width: 24px;\n height: 24px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: var(--clepit-bg);\n cursor: pointer;\n color: var(--clepit-text-muted);\n transition: color 0.2s ease;\n}\n\n.clepit-image-drop-area .${a.classNames.block.imageDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Drop area positioning */\n.clepit-drop-area {\n position: relative;\n}\n\n/* Hidden input */\n.clepit-hidden-input {\n display: none;\n}\n\n`,xn="\n/* Output image styles */\n.clepit-output-image-container {\n margin: 1rem 0;\n text-align: center;\n}\n\n.clepit-output-image {\n max-width: 100%;\n height: auto;\n border-radius: 8px;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);\n}\n\n.clepit-output-image-caption {\n margin-top: 0.5rem;\n font-size: 0.875rem;\n color: var(--clepit-text-muted);\n font-style: italic;\n text-align: center;\n}\n\n/* Image wrapper positioning */\n.clepit-image-wrapper {\n position: relative;\n cursor: pointer;\n display: flex;\n margin-bottom: 10px;\n}\n.clepit-output-image-wrapper--left {\n justify-content: flex-start;\n}\n\n.clepit-output-image-wrapper--center {\n justify-content: center;\n}\n\n.clepit-output-image-wrapper--right {\n justify-content: flex-end;\n}\n",kn=class e{static{this.placeholder="Add a caption..."}static{this.validTypes=["image/jpeg","image/jpg","image/png","image/gif","image/webp","image/ico","image/x-icon","image/avif","image/heic"]}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.querySelector("img"),n=e.querySelector(`.${a.classNames.block.image.captionEditable}`),o=e.querySelector(".clepit-image-wrapper");let i="center";return o&&(i=o.classList.contains("clepit-image-wrapper--left")?"left":o.classList.contains("clepit-image-wrapper--right")?"right":"center"),{alignment:i,alt:t?.getAttribute("alt")||"",caption:M(n?.innerHTML),url:t?.getAttribute("src")||""}}static render(t,n,o,i){a.injectStyles("clepit-image-input-styles",vn);const r={alt:"",caption:"",url:""},s=o?{...r,...o}:r,l=a.createStyledElement("div",a.classNames.block.image.container,{classNames:i?.classNames?.container,styles:i?.styles?.container});return s.url?e.renderImage(l,s,t,n,i):e.renderDropArea(l,t,n,i),l}static renderImage(t,n,o,i,r){t.innerHTML="";const s=a.createStyledElement("div",a.classNames.block.image.wrapper,{classNames:r?.classNames?.container,styles:r?.styles?.container});switch(s.setAttribute("tabindex","-1"),n?.alignment||"center"){case"left":s.classList.add("clepit-image-wrapper--left");break;case"center":s.classList.add("clepit-image-wrapper--center");break;case"right":s.classList.add("clepit-image-wrapper--right")}const l=a.createStyledElement("img","clepit-image",{classNames:r?.classNames?.container,styles:r?.styles?.container});l.alt=n?.alt||"",l.src=n?.url||"",l.classList.add("clepit-image");const c=a.createStyledElement("div","clepit-image-caption-container",{classNames:r?.classNames?.caption,styles:r?.styles?.caption});c.classList.add("clepit-image-caption-container");const p=a.createStyledElement("div",a.classNames.block.image.captionEditable,{classNames:r?.classNames?.caption,styles:r?.styles?.caption});p.setAttribute("contenteditable","true"),p.setAttribute("data-placeholder",e.placeholder),p.innerHTML=n?.caption||"",e.addEventListener(i,p,"keydown",or.handleKeydown),e.addEventListener(i,p,"input",or.handleInput),e.addEventListener(i,s,"click",()=>e.handleFileSelect(t,o,i,r)),s.appendChild(l),c.appendChild(p),t.appendChild(s),t.appendChild(c),p.focus()}static renderDropArea(t,n,o,i){t.innerHTML="";const r=a.createStyledElement("div",a.classNames.block.image.dropArea,{classNames:i?.classNames?.dropArea?.container,styles:i?.styles?.dropArea?.container});r.setAttribute("tabindex","0"),r.classList.add("clepit-drop-area");const s=a.createStyledElement("div","clepit-image-drop-icon",{classNames:i?.classNames?.dropArea?.icon,styles:i?.styles?.dropArea?.icon});s.textContent="📷";const c=a.createStyledElement("div","clepit-image-drop-text",{classNames:i?.classNames?.dropArea?.text,styles:i?.styles?.dropArea?.text});c.innerHTML='<strong>Drop an image here</strong><br>or <span class="clepit-image-click-text">click to select</span>';const p=a.createStyledElement("div","clepit-image-drop-subtext",{classNames:i?.classNames?.dropArea?.subtext,styles:i?.styles?.dropArea?.subtext});p.textContent="Supports JPEG, PNG, GIF, WebP, SVG, and other image formats";const d=a.createStyledElement("button",`${a.classNames.block.imageDeleteBtn}`,{classNames:i?.classNames?.dropArea?.deleteButton,styles:i?.styles?.dropArea?.deleteButton});d.type="button",d.textContent="✕",r.appendChild(s),r.appendChild(c),r.appendChild(p),r.appendChild(d);const u=l.getState().getInstance(o),m=u?.config.classNames?.tooltips,h=u?.config.styles?.tooltips;J(d,"Delete block","below",m,h),e.addEventListener(o,d,"click",e=>{e.preventDefault(),e.stopPropagation();const t=d.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id");t&&or.removeBlock(o,or.getBlockIndex(o,t))}),e.addEventListener(o,r,"click",()=>e.handleFileSelect(t,n,o,i)),e.addEventListener(o,r,"dragleave",()=>{r.classList.remove("clepit-image-drop-area--dragover")}),e.addEventListener(o,r,"dragover",e=>{e.preventDefault(),e.stopPropagation(),r.classList.add("clepit-image-drop-area--dragover")}),e.addEventListener(o,r,"drop",a=>{a.preventDefault(),a.stopPropagation(),r.classList.remove("clepit-image-drop-area--dragover"),e.handleFileDrop(a,t,n,o,i)}),e.addEventListener(o,r,"focus",e=>{e.preventDefault(),e.stopPropagation()}),e.addEventListener(o,r,"mousedown",e=>{e.preventDefault(),e.stopPropagation()}),t.appendChild(r)}static handleFileDrop(t,n,a,o,i){const r=t.dataTransfer?.files;if(r&&r.length>0){const t=r[0];e.isValidImageFile(t)?e.processImageFile(t,n,a,o,i):e.showError(n,"Please select a valid image file (JPEG, PNG, GIF, WebP, SVG, BMP, TIFF, ICO, AVIF, HEIC, JXL, and more)")}}static handleFileSelect(t,n,a,o){const i=document.createElement("input");i.type="file",i.accept="image/*",i.classList.add("clepit-hidden-input"),i.addEventListener("change",()=>{const r=i.files;if(r&&r.length>0){const i=r[0];e.isValidImageFile(i)?e.processImageFile(i,t,n,a,o):e.showError(t,"Please select a valid image file (JPEG, PNG, GIF, WebP, SVG, BMP, TIFF, ICO, AVIF, HEIC, JXL, and more)")}}),document.body.appendChild(i),i.click(),document.body.removeChild(i)}static isValidImageFile(t){return e.validTypes.includes(t.type)||t.type.startsWith("image/")}static async processImageFile(t,n,o,i,r){e.showLoading(n);try{let s=await o(t);if(s){e.renderImage(n,{alignment:"center",alt:t.name,caption:"",url:s},o,i,r);const c=n.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id");c&&l.getState().updateBlockData(i,or.getBlockIndex(i,c),or.getBlockData(c).data)}else e.showError(n,"Failed to upload image. Please try again.")}catch(s){console.error("Image upload error:",s),e.showError(n,"Failed to upload image. Please try again.")}}static showLoading(e){e.innerHTML="";const t=a.createStyledElement("div","clepit-image-loading",void 0);t.textContent="Uploading image...",e.appendChild(t)}static showError(e,t){e.innerHTML="";const n=a.createStyledElement("div","clepit-image-error",void 0);n.textContent=t,e.appendChild(n)}static setAlignment(e,t){const n=e.querySelector(".clepit-image-wrapper");n&&(n.classList.remove("clepit-image-wrapper--left","clepit-image-wrapper--center","clepit-image-wrapper--right"),n.classList.add(`clepit-image-wrapper--${t}`));const a=or.getEditorId(e);if(!a)return;const o=e.getAttribute("data-id");o&&l.getState().partialUpdateBlockData(a,or.getBlockIndex(a,o),{alignment:t})}static isEmpty(e){const t=e.querySelector(`.${a.classNames.block.image.wrapper} img`),n=e.querySelector(`.${a.classNames.block.image.captionEditable}`);let o=!1,i=!1;return t&&t.getAttribute("src")?.trim()||(o=!0),n?I(n.innerHTML)&&(i=!0):i=!0,o&&i}static isEmptyData(e){return!e.url?.trim()&&I(e.caption)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},wn=class e{static render(t,n,o,i){if(a.injectStyles("clepit-image-output-styles",xn),!e.validate(t))return xe();if(kn.isEmptyData(t))return document.createElement("div");const r=t.url,s=t.caption,l=t.alt||s||"",c=a.createStyledElement("div","clepit-output-image-container",{classNames:i?.container,styles:o?.container}),p=a.createStyledElement("div","clepit-output-image-wrapper");if(t.alignment)switch(t.alignment){case"left":p.classList.add("clepit-output-image-wrapper--left");break;case"center":p.classList.add("clepit-output-image-wrapper--center");break;case"right":p.classList.add("clepit-output-image-wrapper--right")}const d=B("img","clepit-output-image");if(d.src=r,d.alt=l,p.appendChild(d),c.appendChild(p),s){const e=a.createStyledElement("figcaption","clepit-output-image-caption",{classNames:i?.caption,styles:o?.caption}),n=t.caption;e.innerHTML=n&&n!==s?n:s,c.appendChild(e)}return c}static draw(t,n=ue){if(!e.validate(t)||kn.isEmptyData(t))return null;const a=n.create("div");a.addClass("clepit-output-image-container");const o=n.create("div");o.addClass("clepit-output-image-wrapper");const i=t.alignment??"";i&&o.addClass(`clepit-output-image-wrapper--${i}`);const r=n.create("img");if(r.addClass("clepit-output-image"),r.setAttribute("src",t.url),r.setAttribute("alt",t.alt||t.caption||""),o.append(r),a.append(o),t.caption){const e=n.create("figcaption");e.addClass("clepit-output-image-caption"),e.setHtml(t.caption),a.append(e)}return a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.url}},Cn="\n/* Output list styles */\n.clepit-output-list {\n margin: 0 0 1rem 0;\n padding-left: 2rem;\n}\n\n.clepit-output-list-item {\n margin: 0.5rem 0;\n line-height: 1.6;\n}\n\n/* Output list link styles */\n.clepit-output-list a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-output-list a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Output list inline code styling */\n.clepit-output-list li code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Output list marker brush effect */\n.clepit-output-list li mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n\n.clepit-output-list li mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1;\n}\n\n/* Responsive Design */\n@media (max-width: 768px) {\n .clepit-output-list {\n padding-left: 1.5rem;\n }\n}\n",En=class e{static{this.placeholder="Enter list item..."}static{this.defaultType="unordered"}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(t){const n=t.getAttribute("data-type")||e.defaultType,a=[];return t.querySelectorAll("li").forEach(e=>a.push(M(e.innerHTML))),{items:a,type:n}}static render(t,n,o){a.injectStyles("clepit-list-input-styles","\n/* List block styles */\n.clepit-list {\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0 16px;\n}\n\n.clepit-list-item {\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0;\n}\n\n.clepit-block[data-tool=\"list\"] .clepit-block-content {\n padding-left: 40px;\n}\n\n.clepit-block[data-tool=\"list\"] .clepit-block-content ul,\n.clepit-block[data-tool=\"list\"] .clepit-block-content ol {\n margin: 0;\n padding-left: 20px;\n}\n\n.clepit-block[data-tool=\"list\"] .clepit-block-content li {\n margin: 4px 0;\n}\n\n/* List item placeholder styles */\n.clepit-list-item[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* List item link styles */\n.clepit-list-item a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-list-item a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* List item inline code styling */\n.clepit-list-item code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* List item marker brush effect */\n.clepit-list-item mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0; /* create stacking context so ::before sits behind text, not page */\n white-space: pre-wrap; /* ensure leading/trailing spaces inside mark render */\n}\n\n.clepit-list-item mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1; /* behind text but within mark's stacking context */\n}\n\n");const i={items:[],type:e.defaultType},r=n?{...i,...n}:i,s="ordered"===r.type?"ol":"ul",l=a.createStyledElement(s,a.classNames.block.list.container,{classNames:o?.classNames?.[r.type]?.container,styles:o?.styles?.[r.type]?.container});l.setAttribute("data-type",r.type);const c=o?.classNames?.[r.type]?.item,p=o?.styles?.[r.type]?.item;return r.items.length>0?r.items.forEach(n=>e.createAndAppendListItem(n,l,t,c,p)):e.createAndAppendListItem("",l,t,c,p),l}static createAndAppendListItem(t,n,o,i,r){const s=a.createStyledElement("li",a.classNames.block.list.item,{classNames:i,styles:r});s.innerHTML=t,s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder",e.placeholder),e.addEventListener(o,s,"keydown",t=>{const l=t,c=n.closest(`.${a.classNames.block.container}`);if(!c)return;const p=or.getBlockIndex(o,c.getAttribute("data-id")),d=l.metaKey||l.ctrlKey;if(l.shiftKey)switch(l.key){case"ArrowUp":t.preventDefault(),t.stopPropagation(),p>0&&or.moveBlock(o,p,p-1);break;case"ArrowDown":t.preventDefault(),t.stopPropagation();const e=or.getBlocks(o);e&&p<e.length-1&&or.moveBlock(o,p,p+1)}else if(d)switch(l.key){case"Delete":case"Backspace":t.preventDefault(),t.stopPropagation(),or.removeBlock(o,p)}else if("Enter"===l.key)if(t.preventDefault(),t.stopPropagation(),I(s.innerHTML)){e.cleanupEmptyItems(n);const t=n.closest(`.${a.classNames.block.container}`);if(!t)return;const i=or.getBlockIndex(o,t.getAttribute("data-id"));or.insertBlock({data:{html:""},type:"paragraph"},o,i+1)}else e.createAndAppendListItem("",n,o,i,r);else if("Backspace"===l.key){if(I(s.innerHTML)){t.preventDefault(),t.stopPropagation();const e=Array.from(n.querySelectorAll("li")),i=e.indexOf(s);if(1===e.length){const e=n.closest(`.${a.classNames.block.container}`);if(!e)return;const t=or.getBlockIndex(o,e.getAttribute("data-id"));if(-1===t)return;or.removeBlock(o,t)}else s.remove(),i>0?e[i-1].focus():e[i+1].focus()}}else{or.ensureActiveBlock(o);const e=or.getBlocks(o);switch(l.key){case"ArrowUp":t.preventDefault(),t.stopPropagation();const o=Array.from(n.querySelectorAll(`.${a.classNames.block.list.item}`)),i=o.indexOf(s);if(0===i){if(p>0){const t=e[p-1];t&&or.focusBlock(t)}}else{const e=o[i-1];e&&e.focus()}return;case"ArrowDown":t.preventDefault(),t.stopPropagation();const r=Array.from(n.querySelectorAll(`.${a.classNames.block.list.item}`)),l=r.indexOf(s);if(l===r.length-1){if(p<e.length-1){const t=e[p+1];t&&or.focusBlock(t)}}else{const e=r[l+1];e&&e.focus()}return}}}),e.addEventListener(o,s,"input",or.handleInput),n.appendChild(s),s.focus()}static changeType(t,n,o){const i=l.getState().getInstance(o);if(!i)return;if(t.getAttribute("data-type")===n)return;const r={items:[...t.querySelectorAll("li")||[]].map(e=>e.innerHTML),type:n},s={classNames:i.config.classNames?.blocks?.list,styles:i.config.styles?.blocks?.list},c=or.getBlockIndex(o,t.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id")),p=e.render(o,r,s);t.replaceWith(p),l.getState().updateBlockData(o,c,r)}static cleanupEmptyItems(e){const t=Array.from(e.querySelectorAll("li")),n=t.filter(e=>I(e.innerHTML));if(t.length===n.length){if(t.length<2)return;for(let e=1;e<n.length;e++)n[e].remove()}else n.forEach(e=>e.remove())}static isEmpty(e){const t=e.querySelectorAll(`.${a.classNames.block.list.item}`);return!t||Array.from(t).every(e=>I(e.innerHTML))}static isEmptyData(e){return 0===e.items.length||e.items.every(e=>I(e))}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Sn=class e{static render(t,n,o,i){if(a.injectStyles("clepit-list-output-styles",Cn),!e.validate(t))return xe();if(En.isEmptyData(t))return document.createElement("div");const r=t.items,s="ordered"===t.type?"ordered":"unordered",l=a.createStyledElement("ordered"===s?"ol":"ul","clepit-output-list",{classNames:i?.[s]?.container,styles:o?.[s]?.container});return r.forEach((e,t)=>{const n=e,r=a.createStyledElement("li","clepit-output-list-item",{classNames:i?.[s]?.item,styles:o?.[s]?.item});n&&n.trim()&&(r.innerHTML=n),l.appendChild(r)}),l}static draw(t,n=ue){if(!e.validate(t)||En.isEmptyData(t))return null;const a="ordered"===t.type,o=n.create(a?"ol":"ul");o.addClass("clepit-output-list");for(const e of t.items){const t=n.create("li");t.addClass("clepit-output-list-item"),e?.trim()&&t.setHtml(e),o.append(t)}return o}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&Array.isArray(e.items)&&"string"==typeof e.type}},Nn="\n.clepit-openapi {\n display: flex;\n flex-direction: column;\n gap: 40px;\n margin: 16px 0;\n}\n\n/* Groups and operations are separated by rhythm, never by rules — the same\n * house style the tables follow. */\n.clepit-openapi-group {\n display: flex;\n flex-direction: column;\n gap: 14px;\n}\n\n/* An eyebrow label rather than a heading, matching the uppercase group headings\n * in the docs sidebar so the reference echoes the nav — approved 2026-08-06\n * (direction 2B, \"Eyebrow\"). */\n.clepit-openapi-group-title {\n color: var(--clepit-text-subtle);\n font-size: 11px;\n font-weight: 700;\n letter-spacing: 0.08em;\n margin: 0;\n text-transform: uppercase;\n}\n\n.clepit-openapi-operation {\n border: 1px solid var(--clepit-border);\n border-radius: 8px;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n}\n\n/* The head is a tinted strip so an operation reads as one bounded unit in a\n * page of a dozen — approved 2026-08-06 (direction 1B, \"Panel\"). */\n.clepit-openapi-operation-head {\n align-items: center;\n background: color-mix(in oklab, var(--clepit-text) 4%, transparent);\n border-bottom: 1px solid var(--clepit-border);\n display: flex;\n flex-wrap: wrap;\n gap: 10px;\n padding: 10px 14px;\n}\n\n.clepit-openapi-operation-body {\n display: flex;\n flex-direction: column;\n gap: 10px;\n padding: 14px;\n}\n\n.clepit-openapi-method {\n border-radius: 4px;\n color: var(--clepit-bg);\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n font-size: 11px;\n font-weight: 700;\n letter-spacing: 0.04em;\n padding: 3px 8px;\n}\n\n.clepit-openapi-method[data-method=\"GET\"] { background: var(--clepit-success); }\n.clepit-openapi-method[data-method=\"POST\"],\n.clepit-openapi-method[data-method=\"PUT\"],\n.clepit-openapi-method[data-method=\"PATCH\"] { background: var(--clepit-primary); }\n.clepit-openapi-method[data-method=\"DELETE\"] { background: var(--clepit-error); }\n\n.clepit-openapi-path {\n color: var(--clepit-text);\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n font-size: 14px;\n}\n\n.clepit-openapi-host {\n color: var(--clepit-text-subtle);\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n font-size: 12px;\n margin-left: auto;\n}\n\n.clepit-openapi-summary {\n color: var(--clepit-text);\n font-size: 16px;\n font-weight: 600;\n margin: 0;\n}\n\n.clepit-openapi-description {\n color: var(--clepit-text-muted);\n margin: 0;\n}\n\n.clepit-openapi-section-title {\n color: var(--clepit-text-subtle);\n font-size: 11px;\n font-weight: 700;\n letter-spacing: 0.08em;\n margin: 4px 0 0;\n text-transform: uppercase;\n}\n\n/* A table has no scroll surface of its own — a cell the house style cannot\n * break (a long host URL) would otherwise force the table, and every ancestor\n * up to the page itself, wider than the viewport. */\n.clepit-openapi-table-scroll {\n max-width: 100%;\n overflow-x: auto;\n border: 1px solid var(--clepit-border);\n border-radius: 8px;\n box-shadow: 0 1px 2px rgba(0,0,0,0.04);\n}\n\n.clepit-openapi-table {\n border-collapse: collapse;\n font-size: 14px;\n width: 100%;\n}\n\n.clepit-openapi-table th {\n background: var(--clepit-surface);\n border-bottom: 1px solid var(--clepit-border);\n color: var(--clepit-text-subtle);\n font-weight: 600;\n padding: 6px 8px;\n text-align: left;\n}\n\n/* House style: no horizontal dividers between rows. Zebra striping is what\n * separates them instead. */\n.clepit-openapi-table td {\n color: var(--clepit-text);\n padding: 7px 8px;\n vertical-align: top;\n}\n\n.clepit-openapi-table tr:nth-child(even) td {\n background: var(--clepit-surface);\n}\n\n.clepit-openapi-name {\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n overflow-wrap: anywhere;\n}\n\n.clepit-openapi-type {\n color: var(--clepit-text-muted);\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n}\n\n.clepit-openapi-required {\n color: var(--clepit-error);\n font-size: 12px;\n}\n\n.clepit-openapi-badge {\n background: var(--clepit-primary-bg);\n border-radius: 4px;\n color: var(--clepit-primary);\n font-size: 12px;\n padding: 2px 8px;\n}\n\n.clepit-openapi-status {\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n font-weight: 600;\n}\n\n.clepit-openapi-status[data-kind=\"success\"] { color: var(--clepit-success); }\n.clepit-openapi-status[data-kind=\"client\"] { color: var(--clepit-warning); }\n.clepit-openapi-status[data-kind=\"server\"] { color: var(--clepit-error); }\n\n/* One response at a time behind a status tab strip — approved 2026-08-06\n * (direction 1B, \"Tabbed\"). */\n.clepit-openapi-responses {\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.clepit-openapi-response-tabs {\n border-bottom: 1px solid var(--clepit-border);\n display: flex;\n flex-wrap: wrap;\n gap: 16px;\n margin-bottom: 4px;\n}\n\n.clepit-openapi-response-tab {\n background: none;\n border: 0;\n border-bottom: 2px solid transparent;\n color: var(--clepit-text-muted);\n cursor: pointer;\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n font-size: 12px;\n margin-bottom: -1px;\n padding: 6px 0;\n}\n\n.clepit-openapi-response-tab[aria-selected=\"true\"] {\n border-bottom-color: var(--clepit-primary);\n color: var(--clepit-text);\n font-weight: 600;\n}\n\n.clepit-openapi-response-tab:focus-visible {\n outline: 2px solid var(--clepit-primary);\n outline-offset: 2px;\n}\n\n.clepit-openapi-response-description {\n color: var(--clepit-text-muted);\n margin: 0;\n}\n\n/* Tabs hide three quarters of the contract from a printed page, so print gets\n * every response expanded and the strip removed. */\n@media print {\n .clepit-openapi-response-tabs { display: none; }\n .clepit-openapi-response { display: block !important; }\n .clepit-openapi-response + .clepit-openapi-response { margin-top: 10px; }\n}\n\n.clepit-openapi-servers {\n color: var(--clepit-text-muted);\n font-size: 14px;\n margin: 0;\n}\n",An=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),Ln=(e,t)=>{const n={children:[],cyclic:!1,nullable:!1,required:!1,type:"unknown"};if(!An(e))return n;if("string"==typeof e.$ref){const o=(a=e.$ref).split("/").pop()??a;if(n.ref=o,t.stack.has(o))return n.cyclic=!0,n.type=o,n;const i=t.schemas[o];if(void 0===i)return n;t.stack.add(o);const r=Ln(i,t);return t.stack.delete(o),r.ref=o,r}var a;"string"==typeof e.description&&(n.description=e.description),"string"==typeof e.format&&(n.format=e.format),Array.isArray(e.enum)&&(n.enum=e.enum.map(e=>String(e)));const o=["allOf","anyOf","oneOf"].find(t=>Array.isArray(e[t]));if(o){const a=e[o].map(e=>Ln(e,t));if("allOf"===o){n.type="object";for(const e of a)n.children.push(...e.children);return n}const i=a.filter(e=>"null"!==e.type&&!("unknown"===e.type&&e.nullable));return(a.length!==i.length||a.some(e=>e.nullable))&&(n.nullable=!0),n.type=i.map(e=>e.ref??e.type).join(" | ")||"unknown",n.children.push(...i.flatMap(e=>e.children)),n}if(n.type=((e,t)=>{const n=e.type;if(Array.isArray(n)){const e=n.filter(e=>"string"==typeof e);return e.includes("null")&&(t.nullable=!0),e.find(e=>"null"!==e)??"unknown"}return"string"==typeof n?n:"unknown"})(e,n),"array"===n.type){const a=Ln(e.items,t);return n.type=`${a.ref??a.type}[]`,n.children.push(...a.children),n}return"object"===n.type&&((e,t,n)=>{if(!An(e.properties))return;const a=Array.isArray(e.required)?e.required.filter(e=>"string"==typeof e):[];for(const[o,i]of Object.entries(e.properties)){const e=Ln(i,n);e.name=o,e.required=a.includes(o),t.children.push(e)}})(e,n,t),n},Bn=(e,t)=>Ln(e,{schemas:t,stack:new Set}),$n=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),In=e=>{if(!$n(e))return"string";const t=Array.isArray(e.type)?e.type.find(e=>"null"!==e):e.type;if(Array.isArray(e.enum)&&e.enum.length>0)return e.enum[0];switch(t){case"array":return[];case"boolean":return!0;case"integer":case"number":return 0;case"object":return{};default:return"string"}},Mn=e=>{if(!$n(e)||!$n(e.properties))return;const t={};for(const[n,a]of Object.entries(e.properties))t[n]=In(a);return t},Tn=e=>e.security[0],qn=(e,t)=>{return`${t}${n=e.path,n.replace(/\{([^}]+)\}/g,":$1")}`;var n},Dn={bash:{build:(e,t)=>{const n=[`curl -X ${e.method} "${qn(e,t)}"`],a=Tn(e);var o;a&&n.push(` -H "Authorization: Bearer $${o=a,o.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toUpperCase()}"`);const i=Mn(e.request);return i&&(n.push(' -H "Content-Type: application/json"'),n.push(` -d '${JSON.stringify(i)}'`)),n.join(" \\\n")},label:"cURL"},dart:{build:(e,t)=>{const n=Mn(e.request),a=e.method.toLowerCase(),o=[` Uri.parse('${qn(e,t)}'),`],i=[],r=Tn(e);return r&&i.push(` 'Authorization': 'Bearer $${r}',`),n&&i.push(" 'Content-Type': 'application/json',"),i.length>0&&o.push(" headers: {",...i," },"),n&&o.push(` body: jsonEncode(${JSON.stringify(n)}),`),[`final response = await http.${a}(`,...o,");"].join("\n")},label:"Dart"},python:{build:(e,t)=>{const n=Mn(e.request),a=e.method.toLowerCase(),o=[` "${qn(e,t)}",`],i=Tn(e);var r;return i&&o.push(` headers={"Authorization": f"Bearer {${r=i,r.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toLowerCase()}}"},`),n&&o.push(` json=${JSON.stringify(n)},`),[`response = requests.${a}(`,...o,")"].join("\n")},label:"Python"},typescript:{build:(e,t)=>{const n=Mn(e.request),a=[],o=Tn(e);o&&a.push(` Authorization: \`Bearer \${${o}}\`,`),n&&a.push(" 'Content-Type': 'application/json',");const i=[` method: '${e.method}',`];return a.length>0&&i.push(" headers: {",...a," },"),n&&i.push(` body: JSON.stringify(${JSON.stringify(n,null,2).replace(/\n/g,"\n ")}),`),[`const response = await fetch('${qn(e,t)}', {`,...i,"});","","const data = await response.json();"].join("\n")},label:"TypeScript"}},_n=["bash","typescript","dart","python"],jn=["get","post","put","patch","delete"],zn=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),On=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,""),Hn=(e,t,n)=>!!e&&(!!e.tags?.some(e=>t.includes(e))||(e.paths?.includes(n)??!1)),Pn=e=>(Array.isArray(e.parameters)?e.parameters:[]).filter(zn).map(e=>({..."string"==typeof e.description?{description:e.description}:{},in:"path"===e.in||"header"===e.in?e.in:"query",name:String(e.name??""),required:!0===e.required,...void 0===e.schema?{}:{schema:e.schema}})),Rn=e=>zn(e.responses)?Object.entries(e.responses).map(([e,t])=>{const n=zn(t)?t:{},a=zn(n.content)?n.content:void 0,o=a&&zn(a["application/json"])?a["application/json"]:void 0;return{description:"string"==typeof n.description?n.description:"",...void 0===o?.schema?{}:{schema:o.schema},status:e}}):[],Fn=e=>{if(!zn(e.requestBody))return;const t=zn(e.requestBody.content)?e.requestBody.content:void 0;return(t&&zn(t["application/json"])?t["application/json"]:void 0)?.schema},Vn=e=>{if(!Array.isArray(e.security))return[];const t=e.security.find(zn);return t?Object.keys(t):[]},Un=e=>{if(!Array.isArray(e.servers))return;const t=e.servers.find(zn);return"string"==typeof t?.url?t.url:void 0},Wn=(e,t)=>e[0]??t.split("/").filter(Boolean)[0]??"default",Kn=(e,t)=>{const n=zn(e)?e:{},a=zn(n.info)?n.info:{},o=zn(n.components)?n.components:{},i={groups:[],schemas:zn(o.schemas)?o.schemas:{},servers:(Array.isArray(n.servers)?n.servers:[]).filter(zn).map(e=>({..."string"==typeof e.description?{description:e.description}:{},url:String(e.url??"")})),title:"string"==typeof a.title?a.title:"",version:"string"==typeof a.version?a.version:""},r=zn(n.paths)?n.paths:{},s=new Map;for(const[l,c]of Object.entries(r))if(zn(c))for(const e of jn){const n=c[e];if(!zn(n))continue;const a=(Array.isArray(n.tags)?n.tags:[]).filter(e=>"string"==typeof e),o=!0===n["x-internal"],i=t.include?.paths?.includes(l)??!1;if(o&&!i)continue;if(Hn(t.exclude,a,l))continue;if(t.include&&!i&&!Hn(t.include,a,l))continue;const r={..."string"==typeof n.description?{description:n.description}:{},id:On(`${e}-${l}`),internal:o,method:e.toUpperCase(),params:Pn(n),path:l,...void 0===Fn(n)?{}:{request:Fn(n)},responses:Rn(n),security:Vn(n),...void 0===Un(n)?{}:{server:Un(n)},summary:"string"==typeof n.summary?n.summary:l,tags:a},p=Wn(a,l),d=s.get(p);d?d.operations.push(r):s.set(p,{id:On(p),operations:[r],title:p})}return i.groups=[...s.values()],i},Gn=(e,t,n,a)=>{const o=e.create(t);return n&&o.addClass(...n.split(" ")),void 0!==a&&o.setText(a),o},Jn=(e,t)=>{const n=Gn(e,"div","clepit-openapi-table-scroll");return n.append(t),n},Xn=(e,t,n,a)=>{const o=Gn(e,"p","clepit-openapi-section-title",t);return o.setAttribute("data-testid",`openapi-section-${n}-${a}`),o},Zn=e=>{const t=e.ref&&"object"===e.type?e.ref:e.type,n=e.enum?e.enum.join(" | "):t;return e.nullable?`${n} | null`:n},Yn=(e,t=0)=>t>6?Zn(e):e.type.endsWith("[]")?0===e.children.length?[]:[Object.fromEntries(e.children.map(e=>[e.required?e.name:`${e.name}?`,Yn(e,t+1)]))]:e.children.length>0?Object.fromEntries(e.children.map(e=>[e.required?e.name:`${e.name}?`,Yn(e,t+1)])):Zn(e),Qn=e=>{const t=Number.parseInt(e,10);return t>=200&&t<300?"success":t>=400&&t<500?"client":t>=500?"server":"other"},ea=(e,t,n,a)=>{const o=Gn(e,"section","clepit-openapi-operation");o.setAttribute("data-testid",`openapi-operation-${t.id}`);const i=t.server??a.defaultServer??n.servers[0]?.url??"";o.setAttribute("data-server",i);const r=Gn(e,"div","clepit-openapi-operation-head"),s=Gn(e,"span","clepit-openapi-method",t.method);s.setAttribute("data-method",t.method),s.setAttribute("data-testid",`openapi-method-${t.id}`);const l=Gn(e,"span","clepit-openapi-path",t.path);if(l.setAttribute("data-testid",`openapi-path-${t.id}`),r.append(s),r.append(l),i){const n=Gn(e,"span","clepit-openapi-host",i);n.setAttribute("data-testid",`openapi-host-${t.id}`),r.append(n)}o.append(r);const c=Gn(e,"div","clepit-openapi-operation-body"),p=Gn(e,"h3","clepit-openapi-summary",t.summary);p.setAttribute("id",t.id),c.append(p),t.description&&c.append(Gn(e,"p","clepit-openapi-description",t.description));const d=Gn(e,"div","clepit-openapi-security");d.setAttribute("data-testid",`openapi-security-${t.id}`),d.append(Gn(e,"span","clepit-openapi-section-title","Auth")),d.appendText(" "),d.append(Gn(e,"span","clepit-openapi-badge",t.security.length>0?t.security.join(", "):"public")),c.append(d);const u=((e,t,n)=>{if(0===t.params.length)return null;const a=Gn(e,"table","clepit-openapi-table");a.setAttribute("data-testid",`openapi-params-${t.id}`);const o=e.create("tr");for(const i of["Name","In","Type","Description"])o.append(Gn(e,"th","clepit-openapi-th",i));a.append(o);for(const i of t.params){const t=e.create("tr"),o=Gn(e,"td","clepit-openapi-name",i.name);i.required&&o.append(Gn(e,"span","clepit-openapi-required"," required")),t.append(o),t.append(Gn(e,"td","clepit-openapi-cell",i.in)),t.append(Gn(e,"td","clepit-openapi-type",Zn(Bn(i.schema,n.schemas)))),t.append(Gn(e,"td","clepit-openapi-cell",i.description??"")),a.append(t)}return a})(e,t,n);if(u&&(c.append(Xn(e,"Parameters","parameters",t.id)),c.append(Jn(e,u))),void 0!==t.request){const a=Bn(t.request,n.schemas);if(a.children.length>0){c.append(Xn(e,"Body","body",t.id));const n=Gn(e,"div","clepit-openapi-body");n.setAttribute("data-testid",`openapi-body-${t.id}`);const o=wt.draw({code:JSON.stringify(Yn(a),null,2),language:"json",showCopy:!0},e);o&&n.append(o),c.append(n)}}t.responses.length>0&&(c.append(Xn(e,"Responses","responses",t.id)),c.append(((e,t,n)=>{const a=Gn(e,"div","clepit-openapi-responses");a.setAttribute("data-testid",`openapi-responses-${t.id}`);const o=Gn(e,"div","clepit-openapi-response-tabs");o.setAttribute("role","tablist"),o.setAttribute("data-testid",`openapi-response-tabs-${t.id}`);const i=[],r=1===t.responses.length;t.responses.forEach((a,s)=>{const l=Gn(e,"div","clepit-openapi-response");l.setAttribute("id",`${t.id}-response-${a.status}`),l.setAttribute("role","tabpanel"),l.setAttribute("data-status",a.status),l.setAttribute("data-testid",`openapi-response-${t.id}-${a.status}`),0!==s&&l.setAttribute("hidden","");const c=Gn(e,"p","clepit-openapi-response-description");if(r){const t=Gn(e,"span","clepit-openapi-status",a.status);t.setAttribute("data-kind",Qn(a.status)),c.append(t),c.appendText(` ${a.description}`)}else c.setText(a.description);if(l.append(c),void 0!==a.schema){const t=Bn(a.schema,n.schemas);if(t.children.length>0){const n=wt.draw({code:JSON.stringify(Yn(t),null,2),language:"json",showCopy:!0},e);n&&l.append(n)}}i.push(l);const p=Gn(e,"button","clepit-openapi-response-tab",a.status);p.setAttribute("type","button"),p.setAttribute("role","tab"),p.setAttribute("aria-controls",`${t.id}-response-${a.status}`),p.setAttribute("aria-selected",0===s?"true":"false"),p.setAttribute("tabindex",0===s?"0":"-1"),p.setAttribute("data-kind",Qn(a.status)),p.setAttribute("data-testid",`openapi-response-tab-${t.id}-${a.status}`),o.append(p)}),r||a.append(o);for(const s of i)a.append(s);return a})(e,t,n)));const m=((e,t,n)=>n.flatMap(n=>{const a=Dn[n];return a?[{code:a.build(e,t),label:a.label,language:n}]:[]}))(t,i,a.snippetLanguages??_n);if(m.length>0){c.append(Xn(e,"Try it","try-it",t.id));const n=wt.draw({code:m[0].code,language:m[0].language,showCopy:!0,syncKey:"api-reference",variants:m},e);n&&c.append(n)}return o.append(c),o},ta=class e{static draw(t,n=ue){if(!e.validate(t))return null;const a=Kn(t.spec,t),o=Gn(n,"div","clepit-openapi");if(a.servers.length>0){const e=Gn(n,"table","clepit-openapi-table clepit-openapi-servers");e.setAttribute("data-testid","openapi-servers");const t=n.create("tr");t.append(Gn(n,"th","clepit-openapi-th","Host")),t.append(Gn(n,"th","clepit-openapi-th","Serves")),e.append(t);for(const o of a.servers){const t=n.create("tr");t.append(Gn(n,"td","clepit-openapi-name",o.url)),t.append(Gn(n,"td","clepit-openapi-cell",o.description??"")),e.append(t)}o.append(Jn(n,e))}for(const e of a.groups){const i=Gn(n,"section","clepit-openapi-group");i.setAttribute("data-testid",`openapi-group-${e.id}`);const r=Gn(n,"h2","clepit-openapi-group-title",e.title);r.setAttribute("id",e.id),i.append(r);for(const o of e.operations)i.append(ea(n,o,a,t));o.append(i)}return o}static render(t,n,o,i){if(a.injectStyles("clepit-openapi-output-styles",Nn),!e.validate(t))return xe();const r=ve(e.draw(t,ue));return i?.container&&r.classList.add(i.container),o?.container&&Object.assign(r.style,o.container),e.attach(r),r}static attach(e){for(const t of[...e.querySelectorAll(".clepit-openapi-responses")]){const e=[...t.querySelectorAll(".clepit-openapi-response-tab")],n=[...t.querySelectorAll(".clepit-openapi-response")],a=t=>{e.forEach((e,n)=>{e.setAttribute("aria-selected",n===t?"true":"false"),e.tabIndex=n===t?0:-1}),n.forEach((e,n)=>{e.hidden=n!==t})};e.forEach((t,n)=>{t.addEventListener("click",()=>a(n)),t.addEventListener("keydown",t=>{const o=t.key,i="ArrowRight"===o?1:"ArrowLeft"===o?-1:0,r="Home"===o?0:"End"===o?e.length-1:0===i?-1:(n+i+e.length)%e.length;-1!==r&&(t.preventDefault(),a(r),e[r]?.focus())})})}}static validate(e){return null!=e&&"object"==typeof e&&("string"==typeof e.url&&e.url.length>0||"object"==typeof e.spec&&null!==e.spec&&!Array.isArray(e.spec))}},na="\n/* Output paragraph styles */\n.clepit-output-paragraph {\n margin: 0 0 1rem 0;\n line-height: 1.6;\n color: var(--clepit-text);\n}\n\n/* Output paragraph inline code styling */\n.clepit-output-paragraph code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Output paragraph marker brush effect */\n.clepit-output-paragraph mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n\n.clepit-output-paragraph mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1;\n}\n\n/* Output paragraph link styles */\n.clepit-output-paragraph a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-output-paragraph a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n",aa=class e{static{this.placeholder="Enter text..."}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){return{html:M(e.querySelector(`.${a.classNames.block.paragraph}`)?.innerHTML)}}static render(t,n,o){a.injectStyles("clepit-paragraph-input-styles","\n/* Paragraph block styles */\n.clepit-paragraph {\n outline: none;\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0 20px;\n}\n\n.clepit-block[data-tool=\"paragraph\"] .clepit-block-content {\n font-size: 16px;\n line-height: 1.6;\n}\n\n/* Paragraph placeholder styles */\n.clepit-paragraph[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Paragraph link styles */\n.clepit-paragraph a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-paragraph a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Paragraph inline code styling */\n.clepit-paragraph code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Paragraph marker brush effect */\n.clepit-paragraph mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0; /* create stacking context so ::before sits behind text, not page */\n white-space: pre-wrap; /* ensure leading/trailing spaces inside mark render */\n}\n\n.clepit-paragraph mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1; /* behind text but within mark's stacking context */\n}\n\n");const i=a.createStyledElement("div",a.classNames.block.paragraph,{classNames:o?.classNames,styles:o?.styles});return i.setAttribute("contenteditable","true"),i.setAttribute("data-placeholder",e.placeholder),i.innerHTML=n?.html||"",e.addEventListener(t,i,"keydown",or.handleKeydown),e.addEventListener(t,i,"input",or.handleInput),i}static isEmpty(e){return I(e.querySelector(`.${a.classNames.block.paragraph}`)?.innerHTML)}static isEmptyData(e){return I(e.html)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},oa=class e{static render(t,n,o,i){if(a.injectStyles("clepit-paragraph-output-styles",na),!e.validate(t))return xe();const r=a.createStyledElement("p","clepit-output-paragraph",{classNames:i,styles:o});if(aa.isEmptyData(t))return r.appendChild(document.createElement("br")),r;const s=t.html;return s&&(r.innerHTML=s),r}static draw(t,n=ue){if(!e.validate(t))return null;const a=n.create("p");return a.addClass("clepit-output-paragraph"),aa.isEmptyData(t)?(a.append(n.create("br")),a):(t.html&&a.setHtml(t.html),a)}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.html}},ia=`\n/* Quote block styles */\n.${a.classNames.block.quote.container} {\n background: linear-gradient(135deg, var(--clepit-surface) 0%, var(--clepit-surface-2) 100%);\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n padding: 16px 20px;\n margin: 16px 16px 16px 0;\n position: relative;\n}\n\n.${a.classNames.block.quote.text} {\n font-size: 1.2em;\n line-height: 1.6;\n font-family: cursive, serif;\n font-style: italic;\n margin-bottom: 15px;\n padding: 4px 6px;\n}\n\n.${a.classNames.block.quote.author} {\n color: var(--clepit-text-muted);\n font-size: 0.9em;\n font-style: normal;\n font-family: inherit;\n text-align: right;\n margin-top: 10px;\n padding: 8px 12px;\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n background: var(--clepit-bg);\n outline: none;\n transition: border-color 0.2s ease;\n}\n\n.${a.classNames.block.quote.author}:focus {\n outline: none;\n}\n\n.${a.classNames.block.quote.divider} {\n height: 1px;\n margin: 15px 0;\n background: linear-gradient(to right, transparent, var(--clepit-border-subtle), transparent);\n}\n\n/* Quote placeholder styles */\n.${a.classNames.block.quote.text}[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n.${a.classNames.block.quote.author}[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Quote link styles */\n.${a.classNames.block.quote.text} a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.${a.classNames.block.quote.text} a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Quote inline code styling */\n.${a.classNames.block.quote.text} code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n`,ra="\n/* Output quote styles */\n.clepit-output-quote-container {\n background: linear-gradient(135deg, var(--clepit-surface) 0%, var(--clepit-surface-2) 100%);\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n padding: 12px 14px;\n margin: 20px 0;\n position: relative;\n}\n\n.clepit-output-quote-author {\n color: var(--clepit-text-muted);\n font-size: 0.9em;\n font-style: normal;\n font-family: inherit;\n text-align: right;\n margin-top: 10px;\n}\n\n.clepit-output-quote-divider {\n height: 1px;\n margin: 15px 0;\n background: linear-gradient(to right, transparent, var(--clepit-border-subtle), transparent);\n}\n\n.clepit-output-quote-text {\n font-size: 1.2em;\n line-height: 1.6;\n font-family: cursive, serif;\n font-style: italic;\n margin-bottom: 15px;\n}\n\n.clepit-output-quote-content {\n /* Content styling handled by parent */\n}\n\n/* Output quote link styles */\n.clepit-output-quote a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-output-quote a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Output quote inline code styling */\n.clepit-output-quote code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n.clepit-output-quote cite code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Output quote marker brush effect */\n.clepit-output-quote mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n\n.clepit-output-quote mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1;\n}\n\n.clepit-output-quote cite mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n\n.clepit-output-quote cite mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1;\n}\n",sa=class e{static{this.placeholder="Enter quote..."}static{this.authorPlaceholder="Enter author..."}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.querySelector(`.${a.classNames.block.quote.text}`);return{author:M(e.querySelector(`.${a.classNames.block.quote.author}`)?.innerHTML),html:M(t?.innerHTML)}}static render(t,n,o){a.injectStyles("clepit-quote-input-styles",ia);const i=n||{author:"",html:""},r=a.createStyledElement("div",a.classNames.block.quote.container,{classNames:o?.classNames?.container,styles:o?.styles?.container}),s=a.createStyledElement("div",a.classNames.block.quote.text,{classNames:o?.classNames?.text,styles:o?.styles?.text}),l=a.createStyledElement("div",a.classNames.block.quote.author,{classNames:o?.classNames?.author,styles:o?.styles?.author});if(s.innerHTML=i.html||"",s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder",e.placeholder),l.innerHTML=i.author||"",l.setAttribute("contenteditable","true"),l.setAttribute("data-placeholder",e.authorPlaceholder),e.addEventListener(t,s,"keydown",e.handleKeydown),e.addEventListener(t,s,"input",or.handleInput),e.addEventListener(t,l,"keydown",e.handleKeydown),e.addEventListener(t,l,"input",or.handleInput),r.appendChild(s),i.author){const e=a.createStyledElement("div",a.classNames.block.quote.divider,{classNames:o?.classNames?.divider,styles:o?.styles?.divider});r.appendChild(e)}return r.appendChild(l),r}static handleKeydown(e){const t=e,n=e.currentTarget,o=n.closest(`.${a.classNames.block.container}`),i=or.getEditorId(o);if(!i)return;const r=or.getBlockIndex(i,o.getAttribute("data-id")),s=o.querySelector(`.${a.classNames.block.quote.text}`),l=o.querySelector(`.${a.classNames.block.quote.author}`),c=t.metaKey||t.ctrlKey;if(t.shiftKey)switch(t.key){case"ArrowUp":e.preventDefault(),e.stopPropagation(),r>0&&or.moveBlock(i,r,r-1);break;case"ArrowDown":e.preventDefault(),e.stopPropagation();const t=or.getBlocks(i);t&&r<t.length-1&&or.moveBlock(i,r,r+1)}else if(c)switch(t.key){case"Delete":case"Backspace":e.preventDefault(),e.stopPropagation(),or.removeBlock(i,r)}else if("Enter"===t.key)t.preventDefault(),t.stopPropagation(),or.insertBlock({data:{html:""},type:"paragraph"},i,r+1);else if("Backspace"===t.key){if(!I(n.innerHTML))return;t.preventDefault(),t.stopPropagation(),n===s?or.removeBlock(i,r):n===l&&(I(s.innerHTML)?or.removeBlock(i,r):s.focus())}else if("ArrowUp"===t.key)if(t.preventDefault(),t.stopPropagation(),n===s){const e=o.previousElementSibling;e&&or.focusBlock(e)}else s.focus();else if("ArrowDown"===t.key)if(t.preventDefault(),t.stopPropagation(),n===l){const e=o.nextElementSibling;e&&or.focusBlock(e)}else l.focus()}static handleKeydownInAuthorInput(e){const t=e,n=e.currentTarget,o=n.closest(`.${a.classNames.block.container}`),i=or.getEditorId(o);if(i)if("Enter"!==t.key||t.shiftKey){if("Backspace"===t.key){if(n.innerHTML?.trim()&&"<br>"!==n.innerHTML.trim())return;t.preventDefault(),t.stopPropagation();const e=o.querySelector(`.${a.classNames.block.quote.text}`);e&&e.focus()}}else{t.preventDefault(),t.stopPropagation();const e=or.getBlockIndex(i,o.getAttribute("data-id"));or.insertBlock({data:{html:""},type:"paragraph"},i,e+1)}}static isEmpty(e){const t=e.querySelector(`.${a.classNames.block.quote.text}`),n=e.querySelector(`.${a.classNames.block.quote.author}`);let o=!1,i=!1;return t?I(t.innerHTML)&&(o=!0):o=!0,n?I(n.innerHTML)&&(i=!0):i=!0,o&&i}static isEmptyData(e){return I(e.html)&&I(e.author)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},la=class e{static render(t,n,o,i){if(a.injectStyles("clepit-quote-output-styles",ra),!e.validate(t))return xe();if(sa.isEmptyData(t))return document.createElement("div");const r=t.html,s=t.author||"",l=a.createStyledElement("div","clepit-output-quote-container",{classNames:i?.container,styles:o?.container}),c=a.createStyledElement("div","clepit-output-quote-text",{classNames:i?.text,styles:o?.text}),p=B("div","clepit-output-quote-content");if(r&&r.trim()&&(p.innerHTML=r),c.appendChild(p),l.appendChild(c),s){const e=a.createStyledElement("div","clepit-output-quote-divider",{classNames:i?.divider,styles:o?.divider});l.appendChild(e);const t=a.createStyledElement("div","clepit-output-quote-author",{classNames:i?.author,styles:o?.author});t.textContent=`— ${s}`,l.appendChild(t)}return l.querySelectorAll(`span.${a.classNames.block.tooltip}[data-tooltip]`).forEach(e=>{const t=e;t.hasAttribute("data-tooltip-initialized")||(J(t,String(t.getAttribute("data-tooltip")||""),"above",n?.tooltipClassNames,void 0),t.setAttribute("data-tooltip-initialized","true"))}),l}static draw(t,n=ue){if(!e.validate(t)||sa.isEmptyData(t))return null;const a=n.create("div");a.addClass("clepit-output-quote-container");const o=n.create("div");o.addClass("clepit-output-quote-text");const i=n.create("div");if(i.addClass("clepit-output-quote-content"),t.html?.trim()&&i.setHtml(t.html),o.append(i),a.append(o),t.author){const e=n.create("div");e.addClass("clepit-output-quote-divider"),a.append(e);const o=n.create("div");o.addClass("clepit-output-quote-author"),o.setText(`— ${t.author}`),a.append(o)}return a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.html}},ca="\n.clepit-sketch {\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n overflow: hidden;\n}\n.clepit-sketch__canvas {\n display: block;\n width: 100%;\n height: 240px;\n touch-action: none;\n}\n.clepit-sketch--input .clepit-sketch__canvas {\n cursor: crosshair;\n}\n",pa=ca,da=ca,ua="http://www.w3.org/2000/svg";function ma(e){return e&&/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(e.trim())?e.trim():"#000000"}function ha(e){if(e.length<4)return"";const t=[`M ${e[0]} ${e[1]}`];for(let n=2;n+1<e.length;n+=2)t.push(`L ${e[n]} ${e[n+1]}`);return t.join(" ")}var ga=class e{static render(t,n,o,i){if(a.injectStyles("sketch-output",da),!e.validate(t))return xe();const r=a.createStyledElement("div","clepit-sketch clepit-output-sketch",{classNames:i?.wrapper,styles:o?.wrapper}),s=document.createElementNS(ua,"svg");s.setAttribute("class","clepit-sketch__canvas"),s.setAttribute("viewBox","0 0 1000 240"),s.setAttribute("preserveAspectRatio","none"),s.setAttribute("role","img");for(const a of t.strokes??[]){const t=ha(a.points??[]);if(!t)continue;const n=document.createElementNS(ua,"path");n.setAttribute("d",t),n.setAttribute("fill","none"),n.setAttribute("stroke",ma(a.color)),n.setAttribute("stroke-width",String(e.safeWidth(a))),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),s.appendChild(n)}return r.appendChild(s),r}static draw(t,n=ue){if(!e.validate(t))return null;const a=n.create("div");a.addClass("clepit-sketch","clepit-output-sketch");const o=n.createNS(ua,"svg");o.setAttribute("class","clepit-sketch__canvas"),o.setAttribute("viewBox","0 0 1000 240"),o.setAttribute("preserveAspectRatio","none"),o.setAttribute("role","img");for(const i of t.strokes??[]){const t=ha(i.points??[]);if(!t)continue;const a=n.createNS(ua,"path");a.setAttribute("d",t),a.setAttribute("fill","none"),a.setAttribute("stroke",ma(i.color)),a.setAttribute("stroke-width",String(e.safeWidth(i))),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),o.append(a)}return a.append(o),a}static safeWidth(e){const t=Number(e.width);return Number.isFinite(t)&&t>0&&t<=64?t:2}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&Array.isArray(e.strokes)}},ba=`\n/* Table block styles */\n.clepit-table-container {\n position: relative;\n display: block;\n max-width: 100%;\n overflow-x: auto;\n overflow-y: visible; /* allow buttons to be visible outside */\n margin: 16px 0;\n padding: 20px;\n}\n\n.clepit-table {\n width: 100%;\n border-collapse: separate;\n border-spacing: 0;\n background: var(--clepit-bg);\n border-radius: 8px;\n border: 1px solid var(--clepit-border);\n box-shadow: 0 1px 2px rgba(0,0,0,0.04);\n}\n\n.clepit-table-controls {\n display: flex;\n gap: 6px;\n margin: 6px 0;\n}\n\n.clepit-table-btn {\n border: 1px solid var(--clepit-border);\n background: var(--clepit-surface);\n border-radius: 4px;\n padding: 2px 6px;\n font-size: 12px;\n color: var(--clepit-text);\n cursor: pointer;\n}\n\n.clepit-table-btn:hover {\n background: var(--clepit-surface-2);\n}\n\n.clepit-table-corner {\n width: 28px;\n min-width: 28px;\n border-right: 1px solid var(--clepit-border);\n}\n\n.${a.classNames.block.table.headerCell} {\n background: var(--clepit-surface);\n border-bottom: 1px solid var(--clepit-border);\n border-right: 1px solid var(--clepit-border);\n padding: 10px 12px;\n font-weight: 600;\n min-width: 120px;\n vertical-align: top;\n text-align: left;\n position: relative;\n}\n\n.${a.classNames.block.table.cell} {\n border-right: 1px solid var(--clepit-border);\n border-bottom: 1px solid var(--clepit-border);\n padding: 10px 12px;\n min-width: 120px;\n vertical-align: top;\n text-align: left;\n}\n\n/* Zebra striping: odd white, even light grey */\n.clepit-table-tbody tr:nth-child(odd) .${a.classNames.block.table.cell} {\n background: var(--clepit-bg);\n}\n\n.clepit-table-tbody tr:nth-child(even) .${a.classNames.block.table.cell} {\n background: var(--clepit-surface);\n}\n\n.${a.classNames.block.table.caption} {\n margin: 8px 0 0 0; /* full width, no horizontal margins */\n width: 100%;\n padding: 10px 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n background: var(--clepit-surface);\n font-size: 13px;\n outline: none;\n flex: 1;\n min-width: 0;\n}\n\n.${a.classNames.block.table.caption}[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: rgba(0, 0, 0, 0.6);\n font-style: italic;\n}\n\n/* Table Download Switch Container */\n.clepit-table-download-switch {\n margin: 8px 0 0 0;\n padding: 6px 8px;\n background: var(--clepit-surface);\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n font-size: 13px;\n}\n\n.${a.classNames.block.table.headerCell}:focus,\n.clepit-table-cell:focus {\n outline: 2px solid var(--clepit-primary);\n outline-offset: -2px;\n}\n\n/* Table placeholder styles */\n.${a.classNames.block.table.headerCell}[data-placeholder]:empty::before,\n.${a.classNames.block.table.cell}[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Row handle cell */\n.clepit-table-row-handle {\n position: absolute;\n left: -22px;\n top: 50%;\n transform: translateY(-50%);\n width: 18px;\n height: 18px;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 2px;\n display: none;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n font-size: 10px;\n color: var(--clepit-text-muted);\n z-index: 1001;\n}\n\n.clepit-table-col-handle {\n position: absolute;\n top: -22px;\n left: 50%;\n transform: translateX(-50%);\n width: 18px;\n height: 18px;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 2px;\n display: none;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n font-size: 10px;\n color: var(--clepit-text-muted);\n z-index: 1001;\n}\n\n.clepit-table-row-delete {\n position: absolute;\n right: -22px;\n top: 50%;\n transform: translateY(-50%);\n width: 18px;\n height: 18px;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 2px;\n display: none;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n font-size: 10px;\n color: var(--clepit-text-muted);\n z-index: 1001;\n}\n\n.clepit-table-col-delete {\n right: -22px;\n top: calc(50% + 18px);\n transform: translateY(-50%);\n}\n\n/* Show handles on hover/active */\n.clepit-table-row:hover .clepit-row-handle,\n.${a.classNames.block.table.headerCell}:hover .clepit-col-handle,\n.clepit-table-row:hover .clepit-row-delete,\n.${a.classNames.block.table.headerCell}:hover .clepit-col-delete {\n display: flex;\n}\n\n/* Hover/active states like toolbar buttons */\n.clepit-row-handle:hover, .clepit-col-handle:hover,\n.clepit-row-delete:hover, .clepit-col-delete:hover {\n color: var(--clepit-primary);\n}\n\n/* Table menu buttons */\n.clepit-table-row-menu-btn,\n.clepit-table-col-menu-btn {\n position: absolute;\n background: var(--clepit-bg);\n color: var(--clepit-text);\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n padding: 4px 8px;\n font-size: 12px;\n cursor: pointer;\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 1002;\n}\n\n.clepit-table-row-menu-btn:hover,\n.clepit-table-col-menu-btn:hover {\n color: var(--clepit-primary);\n background: var(--clepit-bg);\n border-color: var(--clepit-border);\n}\n\n.clepit-table-row-menu-btn--visible,\n.clepit-table-col-menu-btn--visible {\n display: flex;\n}\n\n/* Table container */\n.clepit-table-container {\n overflow: visible;\n position: relative;\n}\n\n.clepit-table-scroll-container {\n overflow-x: auto;\n overflow-y: visible;\n max-width: 100%;\n}\n\n/* Table caption download container */\n.clepit-table-caption-download-container {\n display: flex;\n align-items: center;\n gap: 8px;\n margin-top: 8px;\n}\n\n.clepit-table-download-switch {\n flex-shrink: 0;\n}\n\n`,fa="\n/* Output table styles */\n.clepit-output-table-container {\n margin: 1rem 0;\n overflow-x: auto;\n}\n\n.clepit-output-table {\n width: 100%;\n border-collapse: collapse;\n border: 1px solid var(--clepit-border);\n border-radius: 8px;\n overflow: hidden;\n background: var(--clepit-bg);\n box-shadow: 0 1px 2px rgba(0,0,0,0.04);\n}\n\n/* House style: rows carry no horizontal dividers and no column rules. Rows are\n * told apart by zebra striping, which is what does that job instead — removing\n * the rules is not a licence to remove the banding too. */\n/* These four rules were assigned from JavaScript, one element at a time, which\n * is a browser call inside a render path. In a stylesheet they cost nothing to\n * a page that draws without a browser, and a caller's own inline style still\n * wins over them exactly as it did before. */\n.clepit-output-table-wrapper {\n overflow: hidden;\n width: 100%;\n border-radius: 4px;\n margin-bottom: 1rem;\n}\n\n.clepit-output-table-scroller {\n overflow-x: auto;\n}\n\n.clepit-output-table {\n table-layout: auto;\n margin-top: 0;\n margin-bottom: 0;\n border-radius: 0;\n}\n\n.clepit-output-table th,\n.clepit-output-table td {\n padding: 10px 12px;\n text-align: left;\n min-width: 120px;\n max-width: 400px;\n}\n\n.clepit-output-table th {\n background: var(--clepit-surface);\n border-bottom: 1px solid var(--clepit-border);\n color: var(--clepit-text);\n font-weight: 600;\n}\n\n.clepit-output-table tbody tr:nth-child(odd) {\n background: var(--clepit-bg);\n}\n\n.clepit-output-table tbody tr:nth-child(even) {\n background: var(--clepit-surface);\n}\n\n/* No hover state: a rendered table is display, not a control. A row that\n * changes colour under the pointer reads as clickable when it is not. */\n\n/* Table Output Caption */\n.clepit-output-table-caption {\n margin-top: 0.5rem;\n font-size: 0.875rem;\n color: var(--clepit-text-muted);\n font-style: italic;\n text-align: center;\n}\n\n/* Make footer cell neutral so caption styles are visible */\n.clepit-output-table tfoot td,\n.clepit-output-table tfoot .clepit-output-table-caption-cell {\n padding: 0;\n border: 0;\n background: transparent;\n}\n\n.clepit-output-table-download-btn {\n margin-left: auto;\n width: 24px;\n height: 24px;\n border: none;\n outline: none;\n cursor: pointer;\n border-radius: 50%;\n background: transparent;\n transition: all 0.2s ease;\n padding: 4px;\n display: flex;\n align-items: center;\n justify-content: center;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n}\n\n.clepit-output-table-download-btn:hover {\n background: var(--clepit-bg);\n}\n\n.clepit-output-table-download-btn:hover .clepit-download-icon {\n stroke: var(--clepit-primary);\n}\n\n.clepit-output-table-download-btn:active {\n transform: scale(0.95);\n}\n\n.clepit-download-icon {\n width: 20px;\n height: 20px;\n stroke: var(--clepit-text-muted);\n transition: stroke 0.2s ease;\n}\n\n.clepit-output-table-footer-container {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 8px 12px;\n background: var(--clepit-surface);\n border: 1px solid var(--clepit-border);\n border-top: none;\n border-radius: 0 0 8px 8px;\n}\n",ya=class e{static{this.defaultCols=3}static{this.defaultRows=3}static{this.headerPlaceholder="Enter header..."}static{this.cellPlaceholder="Enter text..."}static{this.captionPlaceholder="Add a caption..."}static{this.defaultData={caption:"",data:Array.from({length:e.defaultRows},()=>Array.from({length:e.defaultCols},()=>"")),showDownload:!1}}static{this.eventListenersMap={}}static addEventListener(t,n,a,o,i){n.addEventListener(a,o,i);const r=e.eventListenersMap[t]||[];r.push({element:n,event:a,handler:o,options:i}),e.eventListenersMap[t]=r}static save(t){const n=t.querySelector("table");if(!n)return e.defaultData;const o=n.querySelector("thead tr"),i=o?Array.from(o.querySelectorAll(`.${a.classNames.block.table.headerCell}`)):[],r=[],s=[];for(const e of i){const t=e.cloneNode(!0);t.querySelectorAll(".clepit-col-handle, .clepit-col-delete").forEach(e=>e.remove()),s.push(M(t.innerHTML))}r.push(s);const l=n.querySelectorAll("tbody tr");for(const e of Array.from(l)){const t=Array.from(e.querySelectorAll(`.${a.classNames.block.table.cell}`)),n=[];for(const e of t){const t=e.cloneNode(!0);t.querySelectorAll(".clepit-row-handle, .clepit-row-delete").forEach(e=>e.remove()),n.push(M(t.innerHTML))}r.push(n)}const c=(t.querySelector(".clepit-table-download-switch")?.querySelector('input[type="checkbox"]'))?.checked||!1;return{caption:M(t.querySelector(`.${a.classNames.block.table.caption}`)?.innerHTML||""),data:r,showDownload:c}}static render(t,n,o){a.injectStyles("clepit-table-input-styles",ba);const i=n?{...e.defaultData,...n}:e.defaultData,r=a.createStyledElement("div","clepit-table-container",{classNames:o?.classNames?.container,styles:o?.styles?.container}),s=a.createStyledElement("table","clepit-table",{classNames:o?.classNames?.table,styles:o?.styles?.table}),c=a.createStyledElement("thead","clepit-table-thead",{classNames:o?.classNames?.table,styles:o?.styles?.table}),p=e.createRow(t,i.data[0],!0);c.appendChild(p),s.appendChild(c);const d=a.createStyledElement("tbody","clepit-table-tbody",{classNames:o?.classNames?.table,styles:o?.styles?.table});for(let a=1;a<i.data.length;a++){const n=e.createRow(t,i.data[a]);d.appendChild(n)}s.appendChild(d);const u=a.createStyledElement("div","clepit-table-scroll-container");u.appendChild(s),r.appendChild(u);const h=a.createStyledElement("button","clepit-table-btn clepit-row-menu-btn",{classNames:o?.classNames?.rowMenuButton,styles:o?.styles?.rowMenuButton});h.style.position="absolute",h.style.display="none",h.style.zIndex="1000",h.textContent="⋮",r.appendChild(h);const f=a.createStyledElement("button","clepit-table-btn clepit-col-menu-btn",{classNames:o?.classNames?.columnMenuButton,styles:o?.styles?.columnMenuButton});f.style.position="absolute",f.style.display="none",f.style.zIndex="1000",f.textContent="⋯",r.appendChild(f);let y=null,v=-1,k=null;e.addEventListener(t,r,"mouseleave",()=>(h.style.display="none",f.style.display="none",void(k&&(k.remove(),k=null))));const w=e=>{y=e;const t=e.getBoundingClientRect(),n=r.getBoundingClientRect(),a=t.top-n.top+t.height/2-12;h.style.left="4px",h.style.top=`${Math.max(4,a)}px`,h.style.display="flex"},C=e=>{if(v=Array.from(p.querySelectorAll(`.${a.classNames.block.table.headerCell}`)).indexOf(e),v<0)return;const t=e.getBoundingClientRect(),n=r.getBoundingClientRect(),o=t.left-n.left+t.width/2-12,i=t.top-n.top-20;f.style.left=`${o}px`,f.style.top=`${Math.max(4,i)}px`,f.style.display="flex"};e.addEventListener(t,d,"mouseover",e=>{const t=e.target.closest("tr");t&&w(t)}),e.addEventListener(t,c,"mouseover",e=>{const t=e.target.closest(`.${a.classNames.block.table.headerCell}`);t&&C(t)}),e.addEventListener(t,d,"mouseover",e=>{const t=e.target.closest(`.${a.classNames.block.table.cell}`);if(!t)return;const n=t.closest("tr");if(!n)return;const o=Array.from(n.querySelectorAll(`.${a.classNames.block.table.cell}`)).indexOf(t);if(o>=0){const e=p.querySelectorAll(`.${a.classNames.block.table.headerCell}`)[o];e&&C(e)}w(n)});const E=()=>{y&&"none"!==h.style.display&&w(y);const e=p.querySelectorAll(`.${a.classNames.block.table.headerCell}`)[v];e&&"none"!==f.style.display&&C(e)};e.addEventListener(t,window,"scroll",E,{passive:!0}),e.addEventListener(t,u,"scroll",E,{passive:!0}),e.addEventListener(t,h,"click",n=>{if(n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation?.(),!y)return;const i=Array.from(d.querySelectorAll("tr")),s=i.indexOf(y),l=h.getBoundingClientRect(),c=r.getBoundingClientRect();e.createMenu(t,r,h,f,[{label:"Move up",onClick:()=>{s>0&&(d.insertBefore(y,i[s-1]),or.saveBlockData(y))},shortcut:m("up")},{label:"Move down",onClick:()=>{s>=0&&s<i.length-1&&(d.insertBefore(i[s+1],y),or.saveBlockData(y))},shortcut:m("down")},{label:"Insert above",onClick:()=>{const n=p.querySelectorAll(`.${a.classNames.block.table.headerCell}`).length||3,o=e.createRow(t,Array.from({length:n},()=>""));d.insertBefore(o,y),or.saveBlockData(y)},shortcut:x("up")},{label:"Insert below",onClick:()=>{const n=p.querySelectorAll(`.${a.classNames.block.table.headerCell}`).length||3,o=e.createRow(t,Array.from({length:n},()=>""));y.nextSibling?d.insertBefore(o,y.nextSibling):d.appendChild(o),or.saveBlockData(y)},shortcut:x("down")},{label:"Delete",onClick:()=>{i.length>1&&(y.remove(),or.saveBlockData(y))},shortcut:g()}],l.left-c.left,l.bottom-c.top+4,o,k)}),e.addEventListener(t,f,"click",n=>{if(n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation?.(),v<0)return;const i=Array.from(p.querySelectorAll(`.${a.classNames.block.table.headerCell}`)),s=f.getBoundingClientRect(),l=r.getBoundingClientRect();e.createMenu(t,r,h,f,[{label:"Move left",onClick:()=>{if(v<=0)return;const e=v,t=i[e-1],n=i[e];t&&n&&p.insertBefore(n,t),d.querySelectorAll("tr").forEach(t=>{const n=Array.from(t.querySelectorAll(`.${a.classNames.block.table.cell}`)),o=n[e-1],i=n[e];o&&i&&t.insertBefore(i,o)}),v=e-1,or.saveBlockData(p)},shortcut:m("left")},{label:"Move right",onClick:()=>{const e=v;if(e<0||e>=i.length-1)return;const t=i[e],n=i[e+1];t&&n&&p.insertBefore(n,t),d.querySelectorAll("tr").forEach(t=>{const n=Array.from(t.querySelectorAll(`.${a.classNames.block.table.cell}`)),o=n[e],i=n[e+1];o&&i&&t.insertBefore(i,o)}),v=e+1,or.saveBlockData(p)},shortcut:m("right")},{label:"Insert left",onClick:()=>{const n=v,o=e.createHeaderCell(t,"");p.insertBefore(o,i[n]),d.querySelectorAll("tr").forEach(o=>{const i=e.createCell(t,""),r=o.querySelectorAll(`.${a.classNames.block.table.cell}`);r[n]?o.insertBefore(i,r[n]):o.appendChild(i)}),or.saveBlockData(p)},shortcut:x("left")},{label:"Insert right",onClick:()=>{const n=v+1,o=i[v]?.nextSibling||null,r=e.createHeaderCell(t,"");p.insertBefore(r,o),d.querySelectorAll("tr").forEach(o=>{const i=e.createCell(t,""),r=o.querySelectorAll(`.${a.classNames.block.table.cell}`);r[n]?o.insertBefore(i,r[n]):o.appendChild(i)}),or.saveBlockData(p)},shortcut:x("right")},{label:"Delete",onClick:()=>{const e=p.querySelectorAll(`.${a.classNames.block.table.headerCell}`);if(v<0||e.length<=1)return;const t=e[v];t?.parentElement?.removeChild(t),d.querySelectorAll("tr").forEach(e=>{const t=e.querySelectorAll(`.${a.classNames.block.table.cell}`);t[v]&&t[v].parentElement?.removeChild(t[v])}),or.saveBlockData(p)},shortcut:b()}],s.left-l.left,s.bottom-l.top+4,o,k)});Array.from(d.querySelectorAll("tr")).forEach(n=>(n=>{e.addEventListener(t,n,"mouseenter",()=>w(n))})(n)),Array.from(p.querySelectorAll(`.${a.classNames.block.table.headerCell}`)).forEach(n=>{return a=n,void e.addEventListener(t,a,"mouseenter",()=>C(a));var a});const S=a.createStyledElement("div","clepit-table-caption-download-container",{classNames:o?.classNames?.container,styles:o?.styles?.container});S.style.display="flex",S.style.alignItems="center",S.style.gap="8px",S.style.marginTop="8px";const N=a.createStyledElement("div",`${a.classNames.block.table.caption}`,{classNames:o?.classNames?.caption,styles:o?.styles?.caption});N.contentEditable="true",N.setAttribute("tabindex","0"),N.setAttribute("data-placeholder",e.captionPlaceholder),N.style.flex="1",N.style.minWidth="0",N.innerHTML=M(i.caption),e.addEventListener(t,N,"input",or.handleInput),e.addEventListener(t,N,"keydown",e.handleKeydown),e.addEventListener(t,N,"click",e.handleClick),S.appendChild(N);const A=a.createStyledElement("div",`${a.classNames.block.table.downloadSwitch}`);A.style.flexShrink="0";const L=ut.create({checked:i.showDownload||!1,label:"Allow download",onToggle:e=>{const n=r.closest(`.${a.classNames.block.container}`);if(n){const a=n.getAttribute("data-id");a&&l.getState().partialUpdateBlockData(t,or.getBlockIndex(t,a),{showDownload:e})}}});A.appendChild(L),S.appendChild(A),r.appendChild(S);return e.addEventListener(t,r,"focusin",()=>{const e=document.activeElement;if(e&&r.contains(e))if(e.classList.contains(a.classNames.block.table.cell)){const t=e.closest("tr");t&&(y=t,w(t))}else e.classList.contains(a.classNames.block.table.headerCell)&&C(e)}),r}static createRow(t,n,o){const i=l.getState().getInstance(t),r=i?.config.classNames?.blocks?.table?.row,s=i?.config.styles?.blocks?.table?.row,c=a.createStyledElement("tr",o?`${a.classNames.block.table.headerRow}`:`${a.classNames.block.table.row}`,{classNames:r,styles:s});for(let a=0;a<n.length;a++)c.appendChild(o?e.createHeaderCell(t,n[a]):e.createCell(t,n[a]));return c.querySelector(`.${a.classNames.block.table.cell}`)?.focus(),c}static createCell(t,n){const o=l.getState().getInstance(t),i=o?.config.classNames?.blocks?.table?.cell,r=o?.config.styles?.blocks?.table?.cell,s=a.createStyledElement("td",`${a.classNames.block.table.cell}`,{classNames:i,styles:r});return s.contentEditable="true",s.setAttribute("tabindex","0"),s.setAttribute("data-placeholder",e.cellPlaceholder),s.innerHTML=M(n),e.addEventListener(t,s,"input",or.handleInput),e.addEventListener(t,s,"keydown",e.handleKeydown),e.addEventListener(t,s,"click",e.handleClick),s}static createHeaderCell(t,n){const o=l.getState().getInstance(t),i=o?.config.classNames?.blocks?.table?.header,r=o?.config.styles?.blocks?.table?.header,s=a.createStyledElement("th",`${a.classNames.block.table.headerCell}`,{classNames:i,styles:r});return s.contentEditable="true",s.setAttribute("tabindex","0"),s.setAttribute("data-placeholder",e.headerPlaceholder),s.innerHTML=M(n),e.addEventListener(t,s,"input",or.handleInput),e.addEventListener(t,s,"keydown",e.handleKeydown),e.addEventListener(t,s,"click",e.handleClick),s}static handleAction(t,n){const a=n.querySelector("table");if(a)switch(t){case"addRow":return e.addRow(a);case"removeRow":return e.removeRow(a);case"addColumn":return e.addColumn(a);case"removeColumn":return e.removeColumn(a)}}static addRow(t){const n=t.querySelector("tbody");if(!n)return;const a=or.getEditorId(t);if(!a)return;const o=t.querySelector("thead tr")?.querySelectorAll("th").length||e.defaultData.data[0].length,i=e.createRow(a,Array.from({length:o},()=>""));n.appendChild(i)}static removeRow(e){const t=e.querySelector("tbody");if(!t)return;const n=t.querySelectorAll("tr");n.length>1&&t.removeChild(n[n.length-1])}static addColumn(t){const n=or.getEditorId(t);if(!n)return;const a=t.querySelector("thead tr"),o=t.querySelector("tbody");if(!a||!o)return;const i=e.createHeaderCell(n,"");a.appendChild(i),o.querySelectorAll("tr").forEach(t=>{const a=e.createCell(n,"");t.appendChild(a)})}static removeColumn(e){const t=e.querySelector("thead tr"),n=e.querySelector("tbody");if(!t||!n)return;const a=t.querySelectorAll("th");a.length>1&&(t.removeChild(a[a.length-1]),n.querySelectorAll("tr").forEach(e=>{const t=e.querySelectorAll("td");t.length>1&&e.removeChild(t[t.length-1])}))}static createMenu(t,n,o,i,r,s,l,c,p){p&&(p.remove(),p=null);const d=a.createStyledElement("div","clepit-block-operations-menu clepit-table-menu",{classNames:c?.classNames?.menu,styles:c?.styles?.menu});d.classList.add("clepit-block-operations-menu--visible"),d.style.position="absolute",d.style.zIndex="20",d.style.left=`${s}px`,d.style.top=`${l}px`,d.style.minWidth="180px",r.forEach(n=>{const o="delete"===n.label.toLowerCase(),i=a.createStyledElement("div","clepit-menu-item"+(o?" clepit-menu-item--danger":""),{classNames:c?.classNames?.menuItem,styles:c?.styles?.menuItem});i.style.fontSize="14px";const r=a.createStyledElement("span","clepit-menu-icon"),s=n.label.toLowerCase();s.includes("move up")?r.textContent="↑":s.includes("move down")?r.textContent="↓":s.includes("move left")?r.textContent="←":s.includes("move right")?r.textContent="→":s.includes("insert")?r.textContent="+":s.includes("delete")?r.textContent="×":r.textContent="•";const l=a.createStyledElement("span","clepit-menu-text");if(l.textContent=n.label,i.appendChild(r),i.appendChild(l),n.shortcut){const e=a.createStyledElement("span","clepit-menu-shortcut");e.style.marginLeft="auto",e.style.fontSize="9px",e.style.color="#666",e.style.opacity="0.7",e.textContent=n.shortcut,i.appendChild(e)}e.addEventListener(t,i,"click",e=>{e.stopPropagation(),e.stopImmediatePropagation?.(),n.onClick(),p&&(p.remove(),p=null)}),d.appendChild(i)}),n.appendChild(d),p=d;const u=e=>{d.contains(e.target)||e.target===o||e.target===i||(d.remove(),p=null,document.removeEventListener("click",u))};return setTimeout(()=>document.addEventListener("click",u),0),d}static handleClick(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget.closest(`.${a.classNames.block.container}`);t&&or.setActiveBlock(t)}static handleKeydown(e){const t=e,n=e.currentTarget,o=or.getEditorId(n);if(!o)return;const i=n.closest(`.${a.classNames.block.container}`);if(!i)return;const r=or.getBlockIndex(o,i.getAttribute("data-id")),s=t.metaKey||t.ctrlKey;if(t.shiftKey)switch(t.key){case"ArrowUp":e.preventDefault(),e.stopPropagation(),r>0&&or.moveBlock(o,r,r-1);break;case"ArrowDown":e.preventDefault(),e.stopPropagation();const t=or.getBlocks(o);t&&r<t.length-1&&or.moveBlock(o,r,r+1)}else if(s){const i=n.closest("table"),s=i.querySelector("tbody"),l=i.querySelector("thead tr");switch(t.key){case"ArrowUp":if(n.classList.contains(a.classNames.block.table.cell)){e.preventDefault(),e.stopPropagation();const t=n.closest("tr"),o=Array.from(s.querySelectorAll("tr")),i=o.indexOf(t);if(i>0){const e=Array.from(t.querySelectorAll(`.${a.classNames.block.table.cell}`)).indexOf(n);s.insertBefore(t,o[i-1]),or.saveBlockData(t);const r=t.querySelectorAll(`.${a.classNames.block.table.cell}`)[e];r&&r.focus()}}break;case"ArrowDown":if(n.classList.contains(a.classNames.block.table.cell)){e.preventDefault(),e.stopPropagation();const t=n.closest("tr"),o=Array.from(s.querySelectorAll("tr")),i=o.indexOf(t);if(i>=0&&i<o.length-1){const e=Array.from(t.querySelectorAll(`.${a.classNames.block.table.cell}`)).indexOf(n);s.insertBefore(o[i+1],t),or.saveBlockData(t);const r=t.querySelectorAll(`.${a.classNames.block.table.cell}`)[e];r&&r.focus()}}break;case"ArrowLeft":let t=-1;const c=Array.from(l.querySelectorAll(`.${a.classNames.block.table.headerCell}`));if(n.classList.contains(a.classNames.block.table.headerCell))t=c.indexOf(n);else if(n.classList.contains(a.classNames.block.table.cell)){const e=n.closest("tr");t=Array.from(e.querySelectorAll(`.${a.classNames.block.table.cell}`)).indexOf(n)}if(t>0){e.preventDefault(),e.stopPropagation();const o=t,r=c[o-1],s=c[o];if(r&&s&&l.insertBefore(s,r),i.querySelectorAll("tbody tr").forEach(e=>{const t=Array.from(e.querySelectorAll(`.${a.classNames.block.table.cell}`)),n=t[o-1],i=t[o];n&&i&&e.insertBefore(i,n)}),n.classList.contains(a.classNames.block.table.cell)){const e=n.closest("tr").querySelectorAll(`.${a.classNames.block.table.cell}`)[o-1];e&&e.focus()}else{s&&s.focus()}or.saveBlockData(l)}break;case"ArrowRight":let p=-1;const d=Array.from(l.querySelectorAll(`.${a.classNames.block.table.headerCell}`));if(n.classList.contains(a.classNames.block.table.headerCell))p=d.indexOf(n);else if(n.classList.contains(a.classNames.block.table.cell)){const e=n.closest("tr");p=Array.from(e.querySelectorAll(`.${a.classNames.block.table.cell}`)).indexOf(n)}if(p<d.length-1){e.preventDefault(),e.stopPropagation();const t=p,o=d[t],r=d[t+1];if(o&&r&&l.insertBefore(r,o),i.querySelectorAll("tbody tr").forEach(e=>{const n=Array.from(e.querySelectorAll(`.${a.classNames.block.table.cell}`)),o=n[t],i=n[t+1];o&&i&&e.insertBefore(i,o)}),n.classList.contains(a.classNames.block.table.cell)){const e=n.closest("tr").querySelectorAll(`.${a.classNames.block.table.cell}`)[t+1];e&&e.focus()}else{r&&r.focus()}or.saveBlockData(l)}break;case"Backspace":if(n.classList.contains(a.classNames.block.table.cell)){e.preventDefault(),e.stopPropagation();const t=n.closest("tr");Array.from(s.querySelectorAll("tr")).length>1&&(t.remove(),or.saveBlockData(t))}else e.preventDefault(),e.stopPropagation(),or.removeBlock(o,r);break;case"Delete":let u=-1;const m=Array.from(l.querySelectorAll(`.${a.classNames.block.table.headerCell}`));if(n.classList.contains(a.classNames.block.table.headerCell))u=m.indexOf(n);else if(n.classList.contains(a.classNames.block.table.cell)){const e=n.closest("tr");u=Array.from(e.querySelectorAll(`.${a.classNames.block.table.cell}`)).indexOf(n)}if(u>=0&&m.length>1){e.preventDefault(),e.stopPropagation();const t=m[u];t?.parentElement?.removeChild(t),i.querySelectorAll("tbody tr").forEach(e=>{const t=e.querySelectorAll(`.${a.classNames.block.table.cell}`);t[u]&&t[u].parentElement?.removeChild(t[u])}),or.saveBlockData(l)}else e.preventDefault(),e.stopPropagation(),or.removeBlock(o,r)}}else if("Enter"===t.key)e.preventDefault(),e.stopPropagation(),or.insertBlock({data:{html:""},type:"paragraph"},o,r+1);else if("Backspace"===t.key){const t=n.closest(`.${a.classNames.block.container}`);if(!t)return;Array.from(t.querySelectorAll(`.${a.classNames.block.table.cell},.${a.classNames.block.table.headerCell}`)).every(e=>I(e.innerHTML))&&(e.preventDefault(),e.stopPropagation(),or.removeBlock(o,r))}else{or.ensureActiveBlock(o);const i=or.getBlocks(o);switch(t.key){case"ArrowUp":if(e.preventDefault(),e.stopPropagation(),n.classList.contains(a.classNames.block.table.caption)){const e=n.closest(`.${a.classNames.block.container}`)?.querySelector("table");if(e){const t=e.querySelector("tbody")?.lastElementChild;if(t&&t.cells.length>0){const e=t.cells[t.cells.length-1];return void(e&&e.focus())}}}const t=n.closest("table");if(!t)return;const o=n.closest("tr"),s=Array.from(o?.cells||[]).indexOf(n);if("TBODY"===o?.parentElement?.tagName&&o===o.parentElement.firstElementChild){const e=t.querySelector("thead")?.querySelector("tr");if(e&&e.cells[s])return void e.cells[s].focus()}if(o?.previousElementSibling){const e=o.previousElementSibling.cells[s];e&&e.focus()}else if(r>0){const e=i[r-1];e&&or.focusBlock(e)}return;case"ArrowDown":if(e.preventDefault(),e.stopPropagation(),n.classList.contains(a.classNames.block.table.caption)){if(r<i.length-1){const e=i[r+1];e&&or.focusBlock(e)}return}const l=n.closest("table");if(!l)return;const c=n.closest("tr"),p=Array.from(c?.cells||[]).indexOf(n);if("THEAD"===c?.parentElement?.tagName){const e=l.querySelector("tbody")?.firstElementChild;if(e&&e.cells[p])return void e.cells[p].focus()}if(c?.nextElementSibling){const e=c.nextElementSibling.cells[p];e&&e.focus()}else{if("TBODY"===c?.parentElement?.tagName&&c===c.parentElement.lastElementChild){const e=l.closest(`.${a.classNames.block.container}`)?.querySelector(`.${a.classNames.block.table.caption}`);if(e)return void e.focus()}if(r<i.length-1){const e=i[r+1];e&&or.focusBlock(e)}}return;case"ArrowLeft":if(!T(n,"left"))return;e.preventDefault(),e.stopPropagation();const d=n.closest("table");if(!d)return;const u=n.closest("tr"),m=Array.from(u?.cells||[]).indexOf(n);if(m>0){const e=u?.cells[m-1];e&&e.focus()}else{if("TBODY"===u?.parentElement?.tagName&&u===u.parentElement.firstElementChild){const e=d.querySelector("thead")?.querySelector("tr");if(e&&e.cells.length>0){const t=e.cells[e.cells.length-1];return void(t&&t.focus())}}if(u?.previousElementSibling){const e=u.previousElementSibling,t=e.cells[e.cells.length-1];t&&t.focus()}}return;case"ArrowRight":if(!T(n,"right"))return;e.preventDefault(),e.stopPropagation();const h=n.closest("table");if(!h)return;const g=n.closest("tr"),b=Array.from(g?.cells||[]).indexOf(n);if(b<(g?.cells.length||0)-1){const e=g?.cells[b+1];e&&e.focus()}else{if("THEAD"===g?.parentElement?.tagName){const e=h.querySelector("tbody")?.firstElementChild;if(e&&e.cells.length>0){const t=e.cells[0];return void(t&&t.focus())}}if(g?.nextElementSibling){const e=g.nextElementSibling.cells[0];e&&e.focus()}}return}}}static isEmpty(e){const t=e.querySelector(`.${a.classNames.block.table.caption}`),n=e.querySelectorAll(`.${a.classNames.block.table.cell},.${a.classNames.block.table.headerCell}`);let o=!1,i=!1;return t?I(t.innerHTML)&&(o=!0):o=!0,n?Array.from(n).every(e=>I(e.innerHTML))&&(i=!0):i=!0,o&&i}static isEmptyData(e){return I(e.caption)&&e.data.every(e=>e.every(e=>I(e)))}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},va="http://www.w3.org/2000/svg",xa=["M3 15C3 17.8284 3 19.2426 3.87868 20.1213C4.75736 21 6.17157 21 9 21H15C17.8284 21 19.2426 21 20.1213 20.1213C21 19.2426 21 17.8284 21 15","M12 3V16M12 16L16 11.625M12 16L8 11.625"],ka=class e{static{this.eventListenersMap=new WeakMap}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap.get(t)||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap.set(t,i)}static render(t,n,o,i,r){if(a.injectStyles("clepit-table-output-styles",fa),!e.validate(t))return xe();if(ya.isEmptyData(t))return document.createElement("div");const s=e.draw(t,ue);if(!s)return document.createElement("div");const l=ve(s);i?.container&&l.classList.add(i.container),o?.container&&Object.assign(l.style,o.container);const c=l.querySelector(".clepit-output-table-caption");c&&i?.caption&&c.classList.add(i.caption),c&&o?.caption&&Object.assign(c.style,o.caption);const p=l.querySelector(".clepit-output-table-footer-container");return p&&i?.footerContainer&&p.classList.add(i.footerContainer),p&&o?.footerContainer&&Object.assign(p.style,o.footerContainer),e.attach(l,t,o,i,r),l}static attach(t,n,a,o,i){const r=t.querySelector(".clepit-output-table-download-btn");if(!r)return;o?.downloadButton&&r.classList.add(o.downloadButton),a?.downloadButton&&Object.assign(r.style,a.downloadButton);const s=i?document.getElementById(i):null;s?(e.eventListenersMap.has(s)||e.eventListenersMap.set(s,[]),e.addEventListener(s,r,"click",()=>e.downloadTableAsCSV(n))):r.addEventListener("click",()=>e.downloadTableAsCSV(n));const c=i?l.getState().getInstance(i):null;J(r,"Download CSV","above",c?.config.classNames?.tooltips,c?.config.styles?.tooltips)}static draw(t,n=ue){if(!e.validate(t)||ya.isEmptyData(t))return null;const a=Array.isArray(t.data)&&t.data.length>0?t.data:[];if(0===a.length)return null;const o=n.create("div");o.addClass("clepit-output-table-wrapper");const i=n.create("div");i.addClass("clepit-output-table-scroller");const r=n.create("table");r.addClass("clepit-output-table");const s=n.create("thead"),l=n.create("tr");for(const e of a[0]??[]){const t=n.create("th");t.setText(e),l.append(t)}if(s.append(l),r.append(s),a.length>1){const e=n.create("tbody");for(const t of a.slice(1)){const a=n.create("tr");for(const e of t){const t=n.create("td");t.setText(e),a.append(t)}e.append(a)}r.append(e)}if(i.append(r),o.append(i),t.caption||t.showDownload){const a=n.create("div");if(a.addClass("clepit-output-table-footer-container"),t.caption){const e=n.create("figcaption");e.addClass("clepit-output-table-caption"),t.caption.trim()&&e.setHtml(t.caption),a.append(e)}if(t.showDownload){const t=n.create("button");t.addClass("clepit-output-table-download-btn"),t.setAttribute("type","button"),t.setAttribute("aria-label","Download CSV"),t.append(e.drawDownloadIcon(n)),a.append(t)}o.append(a)}return o}static drawDownloadIcon(e){const t=e.createNS(va,"svg");t.setAttribute("class","clepit-download-icon"),t.setAttribute("width","20"),t.setAttribute("height","20"),t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("fill","none");for(const n of xa){const a=e.createNS(va,"path");a.setAttribute("d",n),a.setAttribute("stroke","currentColor"),a.setAttribute("stroke-width","1.5"),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),t.append(a)}return t}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&Array.isArray(e.data)}static downloadTableAsCSV(e){const t=e.data||[];if(0===t.length)return;const n=t.map(e=>e.map(e=>{const t=e.replace(/"/g,'""');return t.includes(",")||t.includes('"')||t.includes("\n")?`"${t}"`:t}).join(",")).join("\n"),a=new Blob([n],{type:"text/csv;charset=utf-8;"}),o=document.createElement("a"),i=URL.createObjectURL(a);o.setAttribute("href",i),o.setAttribute("download","table-data.csv"),o.style.visibility="hidden",document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i)}static destroy(t){const n=document.getElementById(t);if(!n)return console.warn("TableOutput::destroy: Container not found for containerId:",t);const a=e.eventListenersMap.get(n);a&&(a.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap.delete(n))}},wa="\n.clepit-toc {\n display: block;\n}\n.clepit-toc__entry {\n display: block;\n padding: 2px 0;\n color: inherit;\n text-decoration: none;\n}\n.clepit-toc__entry:hover {\n text-decoration: underline;\n}\n.clepit-toc__empty {\n opacity: 0.55;\n}\n",Ca=wa,Ea=wa,Sa={h1:0,h2:1,h3:2,h4:3,h5:4,h6:5},Na=class{static render(e,t,n,o){a.injectStyles("toc-output",Ea);const i=(t?.documentBlocks??[]).filter(e=>"header"===e.type),r=a.createStyledElement("nav","clepit-toc clepit-output-toc",{classNames:o?.list,styles:n?.list});if(0===i.length){const e=document.createElement("div");return e.className="clepit-toc__empty",e.textContent="Table of contents — headings appear here",r.appendChild(e),r}return i.forEach((e,t)=>{const i=e.data,s=a.createStyledElement("a","clepit-toc__entry",{classNames:o?.entry,styles:n?.entry});s.setAttribute("data-toc-index",t.toString());const l=Sa[i.level??"h1"];s.style.paddingLeft=16*l+"px",e.id&&(s.href=`#${e.id}`),s.innerHTML=M(i.html),r.appendChild(s)}),r}static draw(e,t=ue,n){if(null==e||"object"!=typeof e)return null;const a=(n?.documentBlocks??[]).filter(e=>"header"===e.type);if(0===a.length)return null;const o=t.create("nav");return o.addClass("clepit-toc","clepit-output-toc"),a.forEach((e,n)=>{const a=e.data,i=t.create("a");i.addClass("clepit-toc__entry"),i.setAttribute("data-toc-index",n.toString()),i.setAttribute("style",`padding-left: ${16*Sa[a.level??"h1"]}px;`),e.id&&i.setAttribute("href",`#${e.id}`),i.setHtml(a.html),o.append(i)}),o}},Aa="\n.clepit-typeset {\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n padding: 12px;\n}\n.clepit-typeset__kind {\n display: block;\n opacity: 0.7;\n font-size: 0.85em;\n margin-bottom: 6px;\n}\n.clepit-typeset__kind:has(+ .clepit-typeset__title) {\n display: inline-block;\n font-size: 11px;\n font-weight: 700;\n letter-spacing: 0.06em;\n margin-bottom: 0;\n text-transform: uppercase;\n}\n.clepit-typeset__title {\n display: block;\n font-size: 1em;\n font-weight: 600;\n margin: 2px 0 8px;\n opacity: 1;\n}\n.clepit-typeset__title[data-placeholder]:empty::before {\n color: inherit;\n content: attr(data-placeholder);\n font-style: italic;\n font-weight: 400;\n opacity: 0.5;\n pointer-events: none;\n}\n.clepit-typeset__source {\n display: block;\n margin: 0;\n white-space: pre-wrap;\n word-break: break-word;\n font-family: ui-monospace, SFMono-Regular, Menlo, monospace;\n}\n.clepit-typeset--input .clepit-typeset__source {\n outline: none;\n}\n.clepit-typeset__diagram {\n display: block;\n max-width: 100%;\n height: auto;\n}\n.clepit-typeset__node {\n fill: rgba(127, 127, 127, 0.08);\n stroke: currentColor;\n stroke-width: 1.5;\n}\n.clepit-typeset__label {\n fill: currentColor;\n font-size: 13px;\n font-family: inherit;\n}\n.clepit-typeset__edge,\n.clepit-typeset__message,\n.clepit-typeset__lifeline {\n stroke: currentColor;\n fill: none;\n}\n.clepit-typeset__lifeline {\n stroke-dasharray: 4 4;\n opacity: 0.55;\n}\n.clepit-typeset__arrowhead {\n fill: currentColor;\n}\n.clepit-typeset__edge-label {\n fill: currentColor;\n font-size: 12px;\n font-family: inherit;\n}\n.clepit-typeset__activation {\n fill: rgba(127, 127, 127, 0.3);\n stroke: currentColor;\n stroke-width: 1;\n}\n.clepit-typeset__note {\n fill: rgba(240, 200, 100, 0.18);\n stroke: currentColor;\n stroke-width: 1;\n}\n.clepit-typeset__formula {\n display: block;\n max-width: 100%;\n height: auto;\n}\n.clepit-typeset__glyph {\n fill: currentColor;\n font-family: ui-serif, Georgia, 'Times New Roman', serif;\n}\n.clepit-typeset__glyph--text {\n font-family: inherit;\n}\n.clepit-typeset__rule,\n.clepit-typeset__radical {\n fill: currentColor;\n}\n.clepit-typeset__radical {\n stroke: currentColor;\n stroke-width: 1.2;\n fill: none;\n}\n.clepit-typeset__fallback-reason {\n display: block;\n opacity: 0.7;\n font-size: 0.85em;\n margin-bottom: 6px;\n}\n",La=Aa,Ba=Aa,$a=.55,Ia=.52,Ma=(e,t,n)=>e.draw.map(e=>({...e,x:e.x+t,y:e.y+n}));function Ta(e,t=18){switch(e.kind){case"atom":return qa(e.text,e.style,t);case"space":return{depth:0,draw:[],height:0,width:e.width/18*t};case"row":return function(e,t){const n=[];let a=0,o=0,i=0;for(const r of e){const e=Ta(r,t);n.push(...Ma(e,a,0)),a+=e.width,o=Math.max(o,e.height),i=Math.max(i,e.depth)}return{depth:i,draw:n,height:o,width:a}}(e.items,t);case"script":return function(e,t){const n=Ta(e.base,t),a=Da(t),o=[...n.draw];let i=n.width,r=n.height,s=n.depth;if(null!==e.sup){const s=Ta(e.sup,a),l=Math.max(.62*n.height,.4*t);o.push(...Ma(s,n.width,-l)),i=Math.max(i,n.width+s.width),r=Math.max(r,l+s.height)}if(null!==e.sub){const r=Ta(e.sub,a),l=Math.max(.5*n.depth,.22*t);o.push(...Ma(r,n.width,l)),i=Math.max(i,n.width+r.width),s=Math.max(s,l+r.depth)}return{depth:s,draw:o,height:r,width:i}}(e,t);case"fraction":return function(e,t){const n=Ta(e.numerator,t),a=Ta(e.denominator,t),o=.25*t,i=.045*t,r=.18*t,s=Math.max(n.width,a.width)+.3*t,l=-(o+r+n.depth),c=-o+r+a.height;return{depth:c+a.depth,draw:[...Ma(n,(s-n.width)/2,l),{kind:"rule",thickness:i,width:s,x:0,y:-o},...Ma(a,(s-a.width)/2,c)],height:-l+n.height,width:s}}(e,t);case"radical":return function(e,t){const n=Ta(e.radicand,t),a=.6*t,o=null===e.index?null:Ta(e.index,Da(Da(t))),i=a+.6*(o?.width??0),r=n.height+.18*t,s=[{height:r+n.depth,kind:"radical",size:t,width:n.width+.2*t,x:i,y:0},...Ma(n,i+.12*t,0)];null!==o&&s.push(...Ma(o,.1*t,.55*-r));return{depth:n.depth,draw:s,height:r,width:i+n.width+.3*t}}(e,t);case"bigop":return function(e,t){const n=1.4*t,a=qa(e.symbol,"upright",n),o=Da(t),i=null===e.upper?null:Ta(e.upper,o),r=null===e.lower?null:Ta(e.lower,o),s=Math.max(a.width,i?.width??0,r?.width??0),l=[...Ma(a,(s-a.width)/2,0)];let c=a.height,p=a.depth;if(null!==i){const e=a.height+i.depth+.16*t;l.push(...Ma(i,(s-i.width)/2,-e)),c=e+i.height}if(null!==r){const e=a.depth+r.height+.16*t;l.push(...Ma(r,(s-r.width)/2,e)),p=e+r.depth}return{depth:p,draw:l,height:c,width:s}}(e,t);case"accent":return function(e,t){const n=Ta(e.base,t),a=qa(e.over,"upright",Da(t)),o="_"===e.over;return{depth:o?n.depth+.2*t:n.depth,draw:[...n.draw,...Ma(a,(n.width-a.width)/2,o?n.depth+.18*t:-(n.height+.04*t))],height:o?n.height:n.height+.2*t,width:n.width}}(e,t);case"delimited":return function(e,t){const n=Ta(e.body,t),a=n.height+n.depth,o=Math.max(t,a*(1/.55)*.62),i=""===e.open?{depth:0,draw:[],height:0,width:0}:qa(e.open,"upright",o),r=""===e.close?{depth:0,draw:[],height:0,width:0}:qa(e.close,"upright",o),s=e=>(n.height-n.depth)/2-(e.height-e.depth)/2;return{depth:Math.max(n.depth,i.depth-s(i),r.depth-s(r)),draw:[...Ma(i,0,s(i)),...Ma(n,i.width,0),...Ma(r,i.width+n.width,s(r))],height:Math.max(n.height,i.height+s(i),r.height+s(r)),width:i.width+n.width+r.width}}(e,t);case"matrix":return function(e,t){const n=e.rows.map(e=>e.map(e=>Ta(e,t))),a=Math.max(...n.map(e=>e.length),0),o=[];for(let v=0;v<a;v+=1)o.push(Math.max(...n.map(e=>e[v]?.width??0),0));const i=n.map(e=>Math.max(...e.map(e=>e.height),0)),r=n.map(e=>Math.max(...e.map(e=>e.depth),0)),s=.6*t,l=.35*t,c=o.reduce((e,t)=>e+t,0)+s*Math.max(a-1,0),p=i.reduce((e,t,n)=>e+t+(r[n]??0),0)+l*Math.max(n.length-1,0),d=[];let u=-p/2;for(const[v,x]of n.entries()){u+=i[v]??0;let e=0;for(const[t,n]of x.entries()){const a=o[t]??0;d.push(...Ma(n,e+(a-n.width)/2,u)),e+=a+s}u+=(r[v]??0)+l}const[m,h]=_a[e.style],g=Math.max(t,.62*p),b=""===m?{depth:0,draw:[],height:0,width:0}:qa(m,"upright",g),f=""===h?{depth:0,draw:[],height:0,width:0}:qa(h,"upright",g),y=e=>(e.height-e.depth)/2;return{depth:p/2,draw:[...Ma(b,0,y(b)),...d.map(e=>({...e,x:e.x+b.width})),...Ma(f,b.width+c,y(f))],height:p/2,width:b.width+c+f.width}}(e,t)}}function qa(e,t,n){const a="italic"===t?$a:Ia;return{depth:.22*n,draw:[{kind:"glyph",size:n,style:t,text:e,x:0,y:0}],height:.72*n,width:e.length*a*n}}function Da(e){return Math.max(9,.7*e)}var _a={bracket:["[","]"],"double-pipe":["‖","‖"],paren:["(",")"],pipe:["|","|"],plain:["",""]};var ja={alpha:"α",beta:"β",chi:"χ",Delta:"Δ",delta:"δ",epsilon:"ϵ",eta:"η",Gamma:"Γ",gamma:"γ",iota:"ι",kappa:"κ",Lambda:"Λ",lambda:"λ",mu:"μ",nu:"ν",Omega:"Ω",omega:"ω",Phi:"Φ",Pi:"Π",Psi:"Ψ",phi:"ϕ",pi:"π",psi:"ψ",rho:"ρ",Sigma:"Σ",sigma:"σ",Theta:"Θ",tau:"τ",theta:"θ",Upsilon:"Υ",upsilon:"υ",varepsilon:"ε",varphi:"φ",vartheta:"ϑ",Xi:"Ξ",xi:"ξ",zeta:"ζ"},za={angle:"∠",approx:"≈",ast:"∗",cap:"∩",cdot:"⋅",cup:"∪",div:"÷",equiv:"≡",exists:"∃",forall:"∀",geq:"≥",in:"∈",infty:"∞",Leftarrow:"⇐",leftarrow:"←",leftrightarrow:"↔",leq:"≤",mp:"∓",nabla:"∇",neg:"¬",neq:"≠",notin:"∉",parallel:"∥",partial:"∂",perp:"⊥",pm:"±",propto:"∝",Rightarrow:"⇒",rightarrow:"→",sim:"∼",simeq:"≃",star:"⋆",subset:"⊂",subseteq:"⊆",supset:"⊃",supseteq:"⊇",times:"×",to:"→"},Oa={bigcap:"⋂",bigcup:"⋃",int:"∫",lim:"lim",oint:"∮",prod:"∏",sum:"∑"},Ha=["arccos","arcsin","arctan","cos","cosh","cot","csc","deg","det","dim","exp","gcd","ln","log","max","min","sec","sin","sinh","tan","tanh"],Pa={bar:"‾",ddot:"¨",dot:"˙",hat:"^",tilde:"~",vec:"→"},Ra={",":3,";":5,":":4,"!":-3,qquad:36,quad:18},Fa={".":"","(":"(",")":")","[":"[","]":"]","\\{":"{","\\}":"}","\\|":"‖","|":"|"},Va=["catcode","csname","def","href","include","input","newcommand","renewcommand","url","write"],Ua={bmatrix:"bracket",matrix:"plain",pmatrix:"paren",Vmatrix:"double-pipe",vmatrix:"pipe"},Wa=/[A-Za-z0-9+\-=<>()[\]|,./!:;]/,Ka=/[A-Za-z]/,Ga=/[0-9]/,Ja={mathbf:"bold",mathit:"italic",mathrm:"upright",text:"text"},Xa=class{constructor(e){this.source=e,this.at=0}get done(){return this.at>=this.source.length}peek(e=0){return this.source[this.at+e]??""}take(){const e=this.peek();return this.at+=1,e}skipSpace(){for(;!this.done&&/\s/.test(this.peek());)this.at+=1}readCommand(){if(this.at+=1,!Ka.test(this.peek()))return this.take();let e="";for(;Ka.test(this.peek());)e+=this.take();return e}},Za=class extends Error{};function Ya(e){const t=new Xa(e);try{const e=Qa(t,null);if(to(t))throw new Za("a \\right appears without a matching \\left");if(!t.done)throw new Za(`"${t.peek()}" is unexpected here`);return{ok:!0,root:e}}catch(n){if(n instanceof Za)return{ok:!1,reason:n.message};throw n}}function Qa(e,t){const n=[];for(;(e.skipSpace(),!e.done)&&("}"!==t||"}"!==e.peek())&&("]"!==t||"]"!==e.peek())&&("cell"!==t||"&"!==e.peek()&&!eo(e)&&!no(e))&&!to(e);){const t=ao(e);if(null===t)break;n.push(t)}return(e=>1===e.length&&void 0!==e[0]?e[0]:{items:e,kind:"row"})(n)}function eo(e){return"\\"===e.peek()&&"\\"===e.peek(1)}function to(e){return!!e.source.startsWith("\\right",e.at)&&!Ka.test(e.peek(6))}function no(e){return"\\"===e.peek()&&e.source.startsWith("\\end",e.at)}function ao(e){const t=oo(e);if(null===t)return null;let n=null,a=null;for(;;){e.skipSpace();const t=e.peek();if("^"!==t&&"_"!==t)break;e.take();const o=oo(e);if(null===o)throw new Za(`"${t}" has nothing after it`);if("^"===t){if(null!==a)throw new Za("a term carries two superscripts");a=o}else{if(null!==n)throw new Za("a term carries two subscripts");n=o}}return null===n&&null===a?t:"bigop"===t.kind?{...t,lower:n,upper:a}:{base:t,kind:"script",sub:n,sup:a}}function oo(e){if(e.skipSpace(),e.done)return null;const t=e.peek();if("}"===t||"&"===t||"^"===t||"_"===t)return null;if("{"===t){e.take();const t=Qa(e,"}");if("}"!==e.peek())throw new Za("a { group is never closed");return e.take(),t}if("\\"===t)return function(e){const t=e.readCommand();if(Va.includes(t))throw new Za(`"\\${t}" is refused for safety, not merely unsupported`);if("\\"===t)throw new Za("a row break appears outside a matrix");if("begin"===t)return function(e){const t=ro(e),n=Ua[t];if(void 0===n)throw new Za(`the "${t}" environment is not supported yet`);const a=[];let o=[];for(let i=0;i<4096;i+=1)if(o.push(Qa(e,"cell")),e.skipSpace(),"&"!==e.peek()){if(!eo(e)){if(no(e)){e.at+=4;const i=ro(e);if(i!==t)throw new Za(`\\begin{${t}} is closed by \\end{${i}}`);return a.push(o),{kind:"matrix",rows:a,style:n}}throw new Za(`\\begin{${t}} is never closed`)}e.at+=2,a.push(o),o=[]}else e.take();throw new Za(`\\begin{${t}} is never closed`)}(e);if("end"===t)throw new Za("an \\end appears without a matching \\begin");if("frac"===t||"dfrac"===t||"tfrac"===t){const t=io(e);return{denominator:io(e),kind:"fraction",numerator:t}}if("sqrt"===t)return function(e){e.skipSpace();let t=null;if("["===e.peek()){if(e.take(),t=Qa(e,"]"),"]"!==e.peek())throw new Za("a \\sqrt index is never closed");e.take()}return{index:t,kind:"radical",radicand:io(e)}}(e);if("left"===t)return function(e){const t=so(e,"left"),n=Qa(e,null);if(!to(e))throw new Za("a \\left has no matching \\right");return e.at+=6,{body:n,close:so(e,"right"),kind:"delimited",open:t}}(e);if("right"===t)throw new Za("a \\right appears without a matching \\left");const n=Ja[t];if(void 0!==n)return{kind:"atom",style:n,text:ro(e)};const a=Pa[t];if(void 0!==a)return{base:io(e),kind:"accent",over:a};if("overline"===t)return{base:io(e),kind:"accent",over:"‾"};if("underline"===t)return{base:io(e),kind:"accent",over:"_"};const o=Oa[t];if(void 0!==o)return{kind:"bigop",lower:null,symbol:o,upper:null};const i=ja[t];if(void 0!==i)return{kind:"atom",style:"italic",text:i};const r=za[t];if(void 0!==r)return{kind:"atom",style:"upright",text:r};if(Ha.includes(t))return{kind:"atom",style:"upright",text:t};const s=Ra[t];if(void 0!==s)return{kind:"space",width:s};const l=Fa[`\\${t}`];if(void 0!==l)return{kind:"atom",style:"upright",text:l};throw new Za(`"\\${t}" is not supported yet`)}(e);if(Wa.test(t))return e.take(),{kind:"atom",style:Ga.test(t)?"upright":"italic",text:t};throw new Za(`"${t}" is not a character this engine understands`)}function io(e){if(e.skipSpace(),"{"!==e.peek()){const t=oo(e);if(null===t)throw new Za("a command is missing its argument");return t}e.take();const t=Qa(e,"}");if("}"!==e.peek())throw new Za("a { group is never closed");return e.take(),t}function ro(e){if(e.skipSpace(),"{"!==e.peek())throw new Za("a text command is missing its { group");e.take();let t="",n=1;for(;!e.done;){const a=e.peek();if("{"===a&&(n+=1),"}"===a&&(n-=1,0===n))return e.take(),t;t+=e.take()}throw new Za("a text command’s { group is never closed")}function so(e,t){e.skipSpace();const n=e.peek();if("\\"===n){const t=e.readCommand(),n=Fa[`\\${t}`];if(void 0===n)throw new Za(`"\\${t}" is not a delimiter this engine understands`);return n}const a=Fa[n];if(void 0===a)throw new Za(`\\${t} is missing a delimiter`);return e.take(),a}var lo={bold:{style:"normal",weight:"700"},italic:{style:"italic",weight:"400"},text:{style:"normal",weight:"400"},upright:{style:"normal",weight:"400"}};function co(e,t,n){const a=n.createNS("http://www.w3.org/2000/svg",e);for(const[o,i]of Object.entries(t))a.setAttribute(o,String(i));return a}function po(e,t=ue){const n=e.width+16,a=e.height+e.depth+16,o=e.height+8,i=co("svg",{class:"clepit-typeset__formula",height:a,role:"img",viewBox:`0 0 ${n} ${a}`,width:n},t);for(const r of e.draw){if("glyph"===r.kind){const e=lo[r.style],n=co("text",{class:"clepit-typeset__glyph","dominant-baseline":"alphabetic","font-size":r.size,"font-style":e.style,"font-weight":e.weight,x:r.x+8,y:o+r.y},t);"text"===r.style&&n.setAttribute("class","clepit-typeset__glyph clepit-typeset__glyph--text"),n.setText(r.text),i.append(n);continue}"rule"!==r.kind?i.append(uo(r,o,t)):i.append(co("rect",{class:"clepit-typeset__rule",height:r.thickness,width:r.width,x:r.x+8,y:o+r.y-r.thickness/2},t))}return i}function uo(e,t,n){const a=e.x+8,o=t+e.y-e.height,i=t+e.y,r=.32*e.size;return co("path",{class:"clepit-typeset__radical",d:[`M ${a-1.6*r} ${i-.45*e.height}`,`L ${a-.9*r} ${i-.55*e.height}`,`L ${a-.2*r} ${i}`,`L ${a+.35*r} ${o}`,`L ${a+e.width} ${o}`].join(" "),fill:"none"},n)}var mo=72,ho=40,go=28,bo=16;function fo(e){return"flowchart"===e.kind?function(e){const t="LR"===e.direction||"RL"===e.direction,n=function(e){const t=new Map;for(const a of e.nodes)t.set(a.id,0);const n=function(e){const t=new Map;for(const o of e.edges)t.set(o.from,[...t.get(o.from)??[],o]);const n=new Map,a=new Set;for(const o of e.nodes){if(n.has(o.id))continue;n.set(o.id,"visiting");const e=[{id:o.id,index:0}];for(;e.length>0;){const o=e[e.length-1],i=t.get(o.id)??[];if(o.index>=i.length){n.set(o.id,"done"),e.pop();continue}const r=i[o.index];o.index+=1;const s=n.get(r.to);"visiting"===s?a.add(r):void 0===s&&(n.set(r.to,"visiting"),e.push({id:r.to,index:0}))}}return e.edges.filter(e=>!a.has(e))}(e);for(let a=0;a<e.nodes.length;a+=1){let e=!1;for(const a of n){if(a.from===a.to)continue;const n=(t.get(a.from)??0)+1;n>(t.get(a.to)??0)&&(t.set(a.to,n),e=!0)}if(!e)break}return t}(e),a=new Map;for(const b of e.nodes){const e=n.get(b.id)??0;a.set(e,[...a.get(e)??[],b.id])}const o=new Map;for(const b of e.nodes)o.set(b.id,yo(b.label,mo));const i=new Map,r=[...a.keys()].sort((e,t)=>e-t),s=e=>t?e.length*ho+(e.length-1)*go:e.reduce((e,t)=>e+(o.get(t)??mo),0)+(e.length-1)*go,l=Math.max(...r.map(e=>s(a.get(e)??[])),0);for(const b of r){const n=a.get(b)??[],r=bo+b*((t?mo:ho)+64);let c=bo+(l-s(n))/2;for(const a of n){const n=e.nodes.find(e=>e.id===a);if(void 0===n)continue;const s=o.get(a)??mo;i.set(a,{height:ho,id:a,label:n.label,shape:n.shape,width:s,x:t?r:c,y:t?c:r}),c+=(t?ho:s)+go}}const c=e.nodes.map(e=>i.get(e.id)).filter(e=>void 0!==e),p=Math.max(...c.map(e=>e.x+e.width),0),d=Math.max(...c.map(e=>e.y+e.height),0),u=(t?d:p)+24,m=e.edges.map(e=>function(e,t,n,a){const o=t.get(e.from),i=t.get(e.to);if(void 0===o||void 0===i)return null;if(n?i.x<o.x:i.y<o.y){const t=n?{x:o.x+o.width/2,y:o.y+o.height}:{x:o.x+o.width,y:o.y+o.height/2},r=n?{x:i.x+i.width/2,y:i.y+i.height}:{x:i.x+i.width,y:i.y+i.height/2},s=n?{x:t.x,y:a}:{x:a,y:t.y},l=n?{x:r.x,y:a}:{x:a,y:r.y};return{arrow:e.arrow,label:e.label,labelX:(s.x+l.x)/2,labelY:(s.y+l.y)/2,line:e.line,points:[t,s,l,r]}}const r=n?{x:o.x+o.width,y:o.y+o.height/2}:{x:o.x+o.width/2,y:o.y+o.height},s=n?{x:i.x,y:i.y+i.height/2}:{x:i.x+i.width/2,y:i.y};return{arrow:e.arrow,label:e.label,labelX:(r.x+s.x)/2,labelY:(r.y+s.y)/2,line:e.line,points:[r,s]}}(e,i,t,u)).filter(e=>null!==e),h=m.some(e=>e.points.length>2),g=t?p:Math.max(p,h?u:0);return{edges:m,height:(t?Math.max(d,h?u:0):d)+bo,kind:"flowchart",nodes:c,width:g+bo}}(e):function(e){const t=[];let n=bo;for(const m of e.participants){const e=yo(m.label,96);t.push({actor:m.actor,centerX:n+e/2,headHeight:36,headWidth:e,id:m.id,label:m.label}),n+=e+go}const a=e=>t.find(t=>t.id===e)?.centerX??null,o=[],i=[],r=[],s=new Map;let l=100;const c=(e,t)=>{const n=s.get(e),o=a(e);void 0!==n&&null!==o&&(r.push({height:Math.max(t-n,24),width:10,x:o-5,y:n}),s.delete(e))};for(const m of e.steps){if("activation"===m.kind){m.active?s.set(m.participant,l):c(m.participant,l);continue}if("note"===m.kind){const e=m.targets.map(a).filter(e=>null!==e);if(0===e.length)continue;const t=yo(m.text,96),n=Math.min(...e),o=Math.max(...e),r="left"===m.placement?n-t-go:"right"===m.placement?o+go:(n+o)/2-t/2;i.push({height:34,text:m.text,width:t,x:r,y:l}),l+=62;continue}const e=a(m.from),t=a(m.to);null!==e&&null!==t&&(m.activate&&s.set(m.to,l),o.push({end:m.end,fromX:e,line:m.line,selfCall:m.from===m.to,text:m.text,toX:t,y:l}),l+=48,m.deactivate&&c(m.to,l))}const p=l;for(const m of[...s.keys()])c(m,p);const d=Math.max(...i.map(e=>e.x+e.width),0),u=Math.max(n-go+bo,d+bo);return{activations:r,height:p+bo,kind:"sequence",lifelineBottom:p,lifelines:t,messages:o,notes:i,width:u}}(e)}function yo(e,t){return Math.max(t,Math.round(7.2*e.length)+32)}var vo=["BT","LR","RL","TB","TD"],xo=["subgraph","end","click","style","classDef","class","linkStyle","direction"],ko=["loop","alt","else","opt","par","and","critical","option","break","rect","box","autonumber","end"],wo=[{arrow:!0,line:"dotted",token:"-.->"},{arrow:!0,line:"thick",token:"==>"},{arrow:!0,line:"solid",token:"--\x3e"},{arrow:!1,line:"thick",token:"==="},{arrow:!1,line:"solid",token:"---"},{arrow:!1,line:"dotted",token:"-.-"}],Co=[{end:"arrow",line:"dotted",token:"--\x3e>"},{end:"arrow",line:"solid",token:"->>"},{end:"cross",line:"dotted",token:"--x"},{end:"cross",line:"solid",token:"-x"},{end:"none",line:"dotted",token:"--\x3e"},{end:"none",line:"solid",token:"->"}],Eo=[{close:"]]",open:"[[",shape:"subroutine"},{close:"])",open:"([",shape:"stadium"},{close:"))",open:"((",shape:"circle"},{close:"]",open:"[",shape:"rect"},{close:"}",open:"{",shape:"rhombus"},{close:")",open:"(",shape:"round"}],So=e=>({ok:!1,reason:e});function No(e){return e.split(/[\s(]/,1)[0]??""}function Ao(e){const t=function(e){return e.split("\n").map(e=>function(e){const t=e.indexOf("%%");return-1===t?e:e.slice(0,t)}(e).trim()).filter(e=>e.length>0)}(e);if(0===t.length)return So("the block is empty");const[n,...a]=t,o=No(n??"");return"sequenceDiagram"===o?function(e){const t=new Map,n=[],a=e=>(t.has(e)||t.set(e,{actor:!1,id:e,label:e}),e);for(const o of e){const e=No(o);if(ko.includes(e))return So(`"${e}" is not supported yet`);if("participant"===e||"actor"===e){const n=To(o,e);if(null===n)return So(`"${o}" is not a participant declaration this engine understands`);t.set(n.id,n);continue}if("activate"===e||"deactivate"===e){const t=o.slice(e.length).trim();if(!Mo(t))return So(`"${o}" does not name a participant to ${e}`);n.push({active:"activate"===e,kind:"activation",participant:a(t)});continue}if("Note"===e||"note"===e){const e=qo(o);if(null===e)return So(`"${o}" is not a note this engine understands`);for(const t of e.targets)a(t);n.push(e);continue}const i=Do(o);if(null===i)return So(`"${o}" is not a message this engine understands`);a(i.from),a(i.to),n.push(i)}return{model:{kind:"sequence",participants:[...t.values()],steps:n},ok:!0}}(a):"flowchart"===o||"graph"===o?function(e,t){const n=e.slice(No(e).length).trim();if(0===n.length)return So('the flowchart header is missing a direction, e.g. "flowchart TD"');const a=vo.find(e=>e===n);if(void 0===a)return So(`"${n}" is not a supported direction — use TD, TB, BT, LR or RL`);const o=new Map,i=[];for(const r of t){const e=No(r);if(xo.includes(e))return So(`"${e}" is not supported yet`);if(r.includes("&"))return So('"&" fan-out is not supported yet');const t=Lo(r,o,i);if(null!==t)return So(t)}return{model:{direction:a,edges:i,kind:"flowchart",nodes:[...o.values()]},ok:!0}}(n??"",a):So(`"${o}" diagrams are not supported yet — only flowchart and sequenceDiagram are`)}function Lo(e,t,n){const a=function(e){const t=[],n=[];let a=e.trim();for(let o=0;o<64;o+=1){const e=Bo(a);if(null===e)return t.push(a.trim()),t.every(e=>e.length>0)?{links:n,terms:t}:null;t.push(a.slice(0,e.at).trim()),n.push({arrow:e.arrow,label:e.label,line:e.line}),a=a.slice(e.at+e.length)}return null}(e);if(null===a)return`"${e}" is not a node or edge this engine understands`;const o=[];for(const i of a.terms){const e=Io(i);if(null===e)return`"${i}" is not a node declaration this engine understands`;t.has(e.id)||t.set(e.id,e),o.push(e)}for(const[i,r]of a.links.entries()){const t=o[i],a=o[i+1];if(void 0===t||void 0===a)return`"${e}" has a link with nothing on one side of it`;n.push({arrow:r.arrow,from:t.id,label:r.label,line:r.line,to:a.id})}return null}function Bo(e){const t=function(e){const t=/--\s+([^->|][^-]*?)\s+(-->|---|-\.->|-\.-|==>|===)/.exec(e);if(null===t||void 0===t.index)return null;const n=wo.find(e=>e.token===t[2]);return void 0===n?null:{arrow:n.arrow,at:t.index,label:(t[1]??"").trim(),length:t[0].length,line:n.line}}(e);if(null!==t)return t;let n=null;for(const a of wo){const t=e.indexOf(a.token);if(-1===t)continue;if(null!==n&&t>=n.at)continue;const o=$o(e,t+a.token.length);n={arrow:a.arrow,at:t,label:o.label,length:a.token.length+o.consumed,line:a.line}}return n}function $o(e,t){if("|"!==e[t])return{consumed:0,label:null};const n=e.indexOf("|",t+1);return-1===n?{consumed:0,label:null}:{consumed:n-t+1,label:e.slice(t+1,n).trim()}}function Io(e){const t=e.trim();if(0===t.length)return null;for(const n of Eo){const e=t.indexOf(n.open);if(e<=0||!t.endsWith(n.close))continue;const a=t.slice(0,e).trim(),o=t.slice(e+n.open.length,t.length-n.close.length);if(Mo(a))return{id:a,label:o.trim(),shape:n.shape}}return Mo(t)?{id:t,label:t,shape:"rect"}:null}function Mo(e){return/^[A-Za-z_][\w-]*$/.test(e)}function To(e,t){const n=e.slice(t.length).trim(),a=/ as /.exec(n),o=(null===a?n:n.slice(0,a.index)).trim();if(!Mo(o))return null;const i=null===a?o:n.slice(a.index+a[0].length).trim();return{actor:"actor"===t,id:o,label:0===i.length?o:i}}function qo(e){const t=e.slice(No(e).length).trim(),n=t.indexOf(":");if(-1===n)return null;const a=t.slice(0,n).trim(),o=t.slice(n+1).trim(),i=/^over\s+(.+)$/i.exec(a);if(null!==i){const e=(i[1]??"").split(",").map(e=>e.trim());return e.every(Mo)?{kind:"note",placement:"over",targets:e,text:o}:null}const r=/^(left|right)\s+of\s+(.+)$/i.exec(a);if(null===r)return null;const s=(r[2]??"").trim();return Mo(s)?{kind:"note",placement:(r[1]??"").toLowerCase(),targets:[s],text:o}:null}function Do(e){const t=e.indexOf(":");if(-1===t)return null;const n=e.slice(0,t),a=e.slice(t+1).trim();for(const o of Co){const e=n.indexOf(o.token);if(-1===e)continue;const t=n.slice(0,e).trim(),i=n.slice(e+o.token.length).trim(),r=i.startsWith("+")||i.startsWith("-")?i[0]:null,s=null===r?i:i.slice(1).trim();if(Mo(t)&&Mo(s))return{activate:"+"===r,deactivate:"-"===r,end:o.end,from:t,kind:"message",line:o.line,text:a,to:s}}return null}var _o={dotted:"5 4",solid:"",thick:""},jo={dotted:1.5,solid:1.5,thick:3};function zo(e,t,n){const a=n.createNS("http://www.w3.org/2000/svg",e);for(const[o,i]of Object.entries(t))a.setAttribute(o,String(i));return a}function Oo(e,t,n,a,o){const i=zo("text",{class:a,"dominant-baseline":"middle","text-anchor":"middle",x:t,y:n},o);return i.setText(e),i}function Ho(e,t=ue){const n=zo("svg",{class:"clepit-typeset__diagram",height:e.height,role:"img",viewBox:`0 0 ${e.width} ${e.height}`,width:e.width},t);return n.append(function(e){const t=zo("defs",{},e),n=zo("marker",{id:"clepit-mermaid-arrow",markerHeight:7,markerUnits:"strokeWidth",markerWidth:7,orient:"auto-start-reverse",refX:7,refY:3.5},e);return n.append(zo("path",{class:"clepit-typeset__arrowhead",d:"M 0 0 L 7 3.5 L 0 7 z"},e)),t.append(n),t}(t)),"flowchart"===e.kind?function(e,t,n){for(const a of t.edges)Ro(e,a,n);for(const a of t.nodes)Po(e,a,n)}(n,e,t):function(e,t,n){for(const a of t.lifelines){e.append(zo("line",{class:"clepit-typeset__lifeline",x1:a.centerX,x2:a.centerX,y1:a.headHeight+16,y2:t.lifelineBottom},n));const o={class:a.actor?"clepit-typeset__node clepit-typeset__actor":"clepit-typeset__node",height:a.headHeight,rx:a.actor?a.headHeight/2:4,ry:a.actor?a.headHeight/2:4,width:a.headWidth,x:a.centerX-a.headWidth/2,y:16};e.append(zo("rect",o,n)),e.append(Oo(a.label,a.centerX,16+a.headHeight/2,"clepit-typeset__label",n))}for(const a of t.activations)e.append(zo("rect",{class:"clepit-typeset__activation",height:a.height,width:a.width,x:a.x,y:a.y},n));for(const a of t.messages)Fo(e,a,n);for(const a of t.notes)e.append(zo("rect",{class:"clepit-typeset__note",height:a.height,width:a.width,x:a.x,y:a.y},n)),e.append(Oo(a.text,a.x+a.width/2,a.y+a.height/2,"clepit-typeset__label",n))}(n,e,t),n}function Po(e,t,n){e.append(function(e,t){const{height:n,shape:a,width:o,x:i,y:r}=e,s={class:"clepit-typeset__node"};if("circle"===a)return zo("ellipse",{...s,cx:i+o/2,cy:r+n/2,rx:o/2,ry:n/2},t);if("rhombus"===a){const e=`${i+o/2},${r} ${i+o},${r+n/2} ${i+o/2},${r+n} ${i},${r+n/2}`;return zo("polygon",{...s,points:e},t)}if("stadium"===a)return zo("rect",{...s,height:n,rx:n/2,ry:n/2,width:o,x:i,y:r},t);if("round"===a)return zo("rect",{...s,height:n,rx:10,ry:10,width:o,x:i,y:r},t);if("subroutine"===a){const e=zo("g",{},t);return e.append(zo("rect",{...s,height:n,rx:8,ry:8,width:o,x:i,y:r},t)),e.append(zo("line",{...s,x1:i+6,x2:i+6,y1:r,y2:r+n},t)),e.append(zo("line",{...s,x1:i+o-6,x2:i+o-6,y1:r,y2:r+n},t)),e}return zo("rect",{...s,height:n,rx:8,ry:8,width:o,x:i,y:r},t)}(t,n)),e.append(Oo(t.label,t.x+t.width/2,t.y+t.height/2,"clepit-typeset__label",n))}function Ro(e,t,n){const[a,o]=t.points;if(void 0===a||void 0===o)return;const i=t.points.length>2?zo("polyline",{class:"clepit-typeset__edge",fill:"none",points:t.points.map(e=>`${e.x},${e.y}`).join(" "),"stroke-dasharray":_o[t.line],"stroke-width":jo[t.line]},n):zo("line",{class:"clepit-typeset__edge","stroke-dasharray":_o[t.line],"stroke-width":jo[t.line],x1:a.x,x2:o.x,y1:a.y,y2:o.y},n);if(t.arrow&&i.setAttribute("marker-end","url(#clepit-mermaid-arrow)"),e.append(i),null!==t.label){const a=Oo(t.label,t.labelX,t.labelY,"clepit-typeset__edge-label",n);a.setAttribute("paint-order","stroke"),e.append(a)}}function Fo(e,t,n){const a={class:"clepit-typeset__message","stroke-dasharray":_o[t.line],"stroke-width":jo[t.line]};if(t.selfCall){const o=`M ${t.fromX} ${t.y} h 28 v 18 h -28`,i=zo("path",{...a,d:o,fill:"none"},n);return"arrow"===t.end&&i.setAttribute("marker-end","url(#clepit-mermaid-arrow)"),e.append(i),void e.append(Oo(t.text,t.fromX+52,t.y+9,"clepit-typeset__edge-label",n))}const o=zo("line",{...a,x1:t.fromX,x2:t.toX,y1:t.y,y2:t.y},n);if("arrow"===t.end&&o.setAttribute("marker-end","url(#clepit-mermaid-arrow)"),e.append(o),"cross"===t.end){const o=t.toX+(t.toX>t.fromX?-5:5);e.append(zo("line",{...a,x1:o-5,x2:o+5,y1:t.y-5,y2:t.y+5},n)),e.append(zo("line",{...a,x1:o-5,x2:o+5,y1:t.y+5,y2:t.y-5},n))}e.append(Oo(t.text,(t.fromX+t.toX)/2,t.y-8,"clepit-typeset__edge-label",n))}var Vo=class e{static render(t,n,o,i,r){if(a.injectStyles("typeset-output",Ba),!e.validate(n))return xe();const s=a.createStyledElement("div",`clepit-typeset clepit-output-typeset clepit-typeset--${t.toLowerCase()}`,{classNames:r?.wrapper,styles:i?.wrapper});if(s.setAttribute("data-language",t.toLowerCase()),n.title){const e=document.createElement("span");e.className="clepit-typeset__title",e.textContent=n.title,e.setAttribute("data-testid","typeset-title"),s.appendChild(e)}if("Mermaid"===t){const a=Ao(n.source);return a.ok?(s.setAttribute("data-rendered","diagram"),s.appendChild(ve(Ho(fo(a.model)))),s):e.appendFallback(s,n.source,a.reason,t)}if(0===n.source.trim().length)return e.appendFallback(s,n.source,null,t);const l=Ya(n.source);return l.ok?(s.setAttribute("data-rendered","formula"),s.appendChild(ve(po(Ta(l.root)))),s):e.appendFallback(s,n.source,l.reason,t)}static appendFallback(e,t,n,a){e.setAttribute("data-rendered","source");const o=document.createElement("span");if(o.className="clepit-typeset__kind",o.textContent=a,e.prepend(o),null!==n){const t=document.createElement("span");t.className="clepit-typeset__fallback-reason",t.textContent=n,e.appendChild(t)}const i=document.createElement("pre");return i.className="clepit-typeset__source",i.textContent=t,e.appendChild(i),e}static draw(t,n,a=ue){if(!e.validate(n))return null;const o=a.create("div");o.addClass("clepit-typeset","clepit-output-typeset",`clepit-typeset--${t.toLowerCase()}`),o.setAttribute("data-language",t.toLowerCase());const i=()=>{if(!n.title)return;const e=a.create("span");e.addClass("clepit-typeset__title"),e.setText(n.title),e.setAttribute("data-testid","typeset-title"),o.append(e)};if("Mermaid"===t){const r=Ao(n.source);return r.ok?(o.setAttribute("data-rendered","diagram"),i(),o.append(Ho(fo(r.model),a)),o):e.drawFallback(o,n,r.reason,t,a,i)}if(0===n.source.trim().length)return e.drawFallback(o,n,null,t,a,i);const r=Ya(n.source);return r.ok?(o.setAttribute("data-rendered","formula"),i(),o.append(po(Ta(r.root),a)),o):e.drawFallback(o,n,r.reason,t,a,i)}static drawFallback(e,t,n,a,o,i){e.setAttribute("data-rendered","source");const r=o.create("span");if(r.addClass("clepit-typeset__kind"),r.setText(a),e.append(r),i(),null!==n){const t=o.create("span");t.addClass("clepit-typeset__fallback-reason"),t.setText(n),e.append(t)}const s=o.create("pre");return s.addClass("clepit-typeset__source"),s.setText(t.source),e.append(s),e}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.source&&(void 0===e.title||"string"==typeof e.title)}},Uo=class{static render(e,t,n,a){return Vo.render("LaTeX",e,t,n,a)}static draw(e,t=ue){return Vo.draw("LaTeX",e,t)}},Wo=class{static render(e,t,n,a){return Vo.render("Mermaid",e,t,n,a)}static draw(e,t=ue){return Vo.draw("Mermaid",e,t)}},Ko="\n.clepit-updates {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 12px;\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n color: inherit;\n}\n.clepit-updates__icon {\n font-size: 18px;\n line-height: 1;\n}\n.clepit-updates__label {\n opacity: 0.7;\n}\n",Go=Ko,Jo=Ko,Xo=class{static render(e,t,n,o){a.injectStyles("updates-output",Jo);const i=a.createStyledElement("div","clepit-updates clepit-output-updates",{classNames:o?.wrapper,styles:n?.wrapper});e?.pageId&&i.setAttribute("data-page-id",e.pageId);const r=document.createElement("span");r.className="clepit-updates__icon",r.textContent="🕘",i.appendChild(r);const s=document.createElement("span");return s.className="clepit-updates__label",s.textContent="Updates",i.appendChild(s),i}static draw(e,t=ue){if(null==e||"object"!=typeof e)return null;const n=t.create("div");n.addClass("clepit-updates","clepit-output-updates"),e.pageId&&n.setAttribute("data-page-id",e.pageId);const a=t.create("span");a.addClass("clepit-updates__icon"),a.setText("🕘"),n.append(a);const o=t.create("span");return o.addClass("clepit-updates__label"),o.setText("Updates"),n.append(o),n}},Zo=`\n/* Video block styles */\n.clepit-video-container {\n margin: 16px 0;\n text-align: center;\n min-height: 120px;\n position: relative;\n display: block;\n width: 100%;\n box-sizing: border-box;\n}\n\n.clepit-video-wrapper {\n display: flex;\n position: relative;\n cursor: pointer;\n transition: opacity 0.2s ease;\n outline: none;\n}\n\n.clepit-video-wrapper:hover {\n opacity: 0.9;\n}\n\n.clepit-video {\n max-width: 100%;\n height: auto;\n border-radius: 8px;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);\n display: block;\n}\n\n.clepit-video-wrapper--left {\n justify-content: flex-start;\n}\n\n.clepit-video-wrapper--center {\n justify-content: center;\n}\n\n.clepit-video-wrapper--right {\n justify-content: flex-end;\n}\n\n.clepit-video-caption-container {\n margin-top: 12px;\n text-align: center;\n}\n\n.clepit-video-caption-label {\n font-size: 12px;\n color: var(--clepit-text-muted);\n margin-bottom: 4px;\n font-weight: 500;\n}\n\n.clepit-video-caption-input {\n width: 100%;\n max-width: 400px;\n padding: 8px 12px;\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n font-size: 14px;\n background: var(--clepit-bg);\n outline: none;\n transition: border-color 0.2s ease;\n pointer-events: auto;\n user-select: text;\n}\n\n.clepit-video-caption-input:focus {\n border-color: var(--clepit-primary);\n box-shadow: 0 0 0 2px var(--clepit-primary-bg);\n}\n\n/* Video caption styling */\n.clepit-video-caption-editable {\n border: 1px solid var(--clepit-border-subtle);\n border-radius: 4px;\n padding: 8px 12px;\n min-height: 40px;\n font-size: 14px;\n line-height: 1.4;\n outline: none;\n transition: border-color 0.2s ease;\n}\n\n/* Video caption placeholder styles */\n.clepit-video-caption-editable[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Video Drop Area */\n.clepit-video-drop-area {\n border: 2px dashed var(--clepit-border);\n border-radius: 8px;\n padding: 40px 20px;\n text-align: center;\n background: var(--clepit-surface);\n cursor: pointer;\n transition: all 0.2s ease;\n margin: 16px 0;\n user-select: none;\n pointer-events: auto;\n outline: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n position: relative;\n}\n\n.clepit-video-drop-area:hover {\n border-color: var(--clepit-primary);\n background: var(--clepit-surface);\n}\n\n.clepit-video-drop-area--dragover {\n border-color: var(--clepit-primary);\n background: var(--clepit-primary-bg);\n transform: scale(1.02);\n}\n\n.clepit-video-drop-icon {\n font-size: 48px;\n margin-bottom: 16px;\n opacity: 0.6;\n}\n\n.clepit-video-drop-text {\n font-size: 16px;\n color: var(--clepit-text-muted);\n line-height: 1.5;\n}\n\n.clepit-video-click-text {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n}\n\n/* Video Loading State */\n.clepit-video-loading {\n text-align: center;\n padding: 40px 20px;\n margin: 16px 0;\n}\n\n.clepit-video-loading-spinner {\n width: 32px;\n height: 32px;\n border: 3px solid var(--clepit-surface);\n border-top: 3px solid var(--clepit-primary);\n border-radius: 50%;\n animation: spin 1s linear infinite;\n margin: 0 auto 16px;\n}\n\n@keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n}\n\n.clepit-video-loading-text {\n font-size: 14px;\n color: var(--clepit-text-muted);\n}\n\n/* Video Error State */\n.clepit-video-error {\n text-align: center;\n padding: 20px;\n margin: 16px 0;\n border: 1px solid var(--clepit-error);\n border-radius: 8px;\n background: var(--clepit-error-bg);\n}\n\n.clepit-video-error-icon {\n font-size: 24px;\n margin-bottom: 8px;\n}\n\n.clepit-video-error-text {\n font-size: 14px;\n color: var(--clepit-error);\n margin-bottom: 12px;\n}\n\n.clepit-video-error-retry {\n background: var(--clepit-error);\n color: white;\n border: none;\n padding: 8px 16px;\n border-radius: 4px;\n cursor: pointer;\n font-size: 14px;\n transition: background-color 0.2s ease;\n}\n\n.clepit-video-error-retry:hover {\n background: var(--clepit-error);\n}\n\n/* Video caption placeholder */\n.clepit-video-caption-placeholder {\n color: var(--clepit-text-subtle);\n}\n\n/* Video delete button */\n.${a.classNames.block.videoDeleteBtn} {\n position: absolute;\n top: 8px;\n right: 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 50%;\n width: 24px;\n height: 24px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: var(--clepit-bg);\n cursor: pointer;\n color: var(--clepit-text-muted);\n transition: color 0.2s ease;\n}\n\n.${a.classNames.block.videoDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Video drop area delete button */\n.clepit-video-drop-area .${a.classNames.block.videoDeleteBtn} {\n position: absolute;\n top: 8px;\n right: 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 50%;\n width: 24px;\n height: 24px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: var(--clepit-bg);\n cursor: pointer;\n color: var(--clepit-text-muted);\n transition: color 0.2s ease;\n}\n\n.clepit-video-drop-area .${a.classNames.block.videoDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Drop area positioning */\n.clepit-drop-area {\n position: relative;\n}\n\n/* Hidden input */\n.clepit-hidden-input {\n display: none;\n}\n\n`,Yo="\n/* Output video styles */\n.clepit-output-video-container {\n margin: 1rem 0;\n text-align: center;\n}\n\n.clepit-output-video {\n max-width: 100%;\n height: auto;\n border-radius: 8px;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);\n}\n\n.clepit-output-video-caption {\n margin-top: 0.5rem;\n font-size: 0.875rem;\n color: var(--clepit-text-muted);\n font-style: italic;\n text-align: center;\n}\n\n/* Output video alignment */\n.clepit-output-video-wr--left {\n justify-content: flex-start;\n}\n\n.clepit-output-video-wr--center {\n justify-content: center;\n}\n\n.clepit-output-video-wr--right {\n justify-content: flex-end;\n}\n",Qo=class e{static{this.placeholder="Add a caption..."}static{this.eventListenersMap={}}static{this.validTypes=["video/mp4","video/webm","video/ogg","video/ogv"]}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.querySelector("video"),n=e.querySelector("iframe"),o=e.querySelector(`.${a.classNames.block.video.captionEditable}`),i=e.querySelector(`.${a.classNames.block.video.wrapper}`);let r="center";i&&(r=i.classList.contains("clepit-video-wrapper--left")?"left":i.classList.contains("clepit-video-wrapper--right")?"right":"center");let s="",l="";return t?(s=t.getAttribute("src")||"",l=t.getAttribute("alt")||""):n&&(s=n.getAttribute("src")||"",l="Embedded video"),{alignment:r,alt:l,caption:M(o?.innerHTML),url:s}}static render(t,n,o,i){a.injectStyles("clepit-video-input-styles",Zo);const r=o||{alt:"",caption:"",url:""},s=a.createStyledElement("div",a.classNames.block.video.container,{classNames:i?.classNames?.container,styles:i?.styles?.container});return r.url?e.renderVideo(s,r,t,n,i):e.renderDropArea(s,t,n,i),s}static renderVideo(t,n,o,i,r){t.innerHTML="";const s=a.createStyledElement("div",a.classNames.block.video.wrapper,{classNames:r?.classNames?.container,styles:r?.styles?.container});switch(s.setAttribute("tabindex","-1"),n?.alignment||"center"){case"left":s.classList.add("clepit-video-wrapper--left");break;case"center":s.classList.add("clepit-video-wrapper--center");break;case"right":s.classList.add("clepit-video-wrapper--right")}const l=ie(n?.url||""),c=re(n?.url||"");if(l||c){const e=a.createStyledElement("iframe",a.classNames.block.video.iframe,{classNames:r?.classNames?.container,styles:r?.styles?.container});e.src=n?.url||"",e.setAttribute("frameborder","0"),e.setAttribute("allowfullscreen","true"),e.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"),e.style.maxWidth="100%",e.style.width="560px",e.style.height="315px",e.style.display="block",e.style.borderRadius="8px",s.appendChild(e)}else{const e=a.createStyledElement("video",a.classNames.block.video.video,{classNames:r?.classNames?.container,styles:r?.styles?.container});e.setAttribute("alt",n?.alt||""),e.src=n?.url||"",e.controls=!0,s.appendChild(e)}const p=a.createStyledElement("div","clepit-video-caption-container",{classNames:r?.classNames?.caption,styles:r?.styles?.caption});p.classList.add("clepit-video-caption-container");const d=a.createStyledElement("div",a.classNames.block.video.captionEditable,{classNames:r?.classNames?.caption,styles:r?.styles?.caption});d.setAttribute("contenteditable","true"),d.setAttribute("data-placeholder",e.placeholder),d.innerHTML=n?.caption||"",e.addEventListener(i,d,"input",or.handleInput),e.addEventListener(i,d,"keydown",or.handleKeydown),e.addEventListener(i,s,"click",()=>e.handleFileSelect(t,o,i,r)),p.appendChild(d),t.appendChild(s),t.appendChild(p),d.focus()}static renderDropArea(t,n,o,i){t.innerHTML="";const r=a.createStyledElement("div",a.classNames.block.video.dropArea,{classNames:i?.classNames?.dropArea?.container,styles:i?.styles?.dropArea?.container});r.setAttribute("tabindex","0"),r.classList.add("clepit-drop-area");const s=a.createStyledElement("div","clepit-video-drop-icon",{classNames:i?.classNames?.dropArea?.icon,styles:i?.styles?.dropArea?.icon});s.textContent="🎥";const c=a.createStyledElement("div","clepit-video-drop-text",{classNames:i?.classNames?.dropArea?.text,styles:i?.styles?.dropArea?.text});c.innerHTML='<strong>Drop a video here</strong><br>or <span class="clepit-video-click-text">click to select</span>';const p=a.createStyledElement("button",`${a.classNames.block.videoDeleteBtn}`,{classNames:i?.classNames?.dropArea?.deleteButton,styles:i?.styles?.dropArea?.deleteButton});p.type="button",p.textContent="✕",r.appendChild(s),r.appendChild(c),r.appendChild(p),e.addEventListener(o,p,"click",e=>{e.preventDefault(),e.stopPropagation();const t=p.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id");t&&or.removeBlock(o,or.getBlockIndex(o,t))}),e.addEventListener(o,r,"click",()=>e.handleFileSelect(t,n,o,i)),e.addEventListener(o,r,"dragleave",()=>{r.classList.remove("clepit-video-drop-area--dragover")}),e.addEventListener(o,r,"dragover",e=>{e.preventDefault(),e.stopPropagation(),r.classList.add("clepit-video-drop-area--dragover")}),e.addEventListener(o,r,"drop",a=>{a.preventDefault(),a.stopPropagation(),r.classList.remove("clepit-video-drop-area--dragover"),e.handleFileDrop(a,t,n,o,i)}),e.addEventListener(o,r,"focus",e=>{e.preventDefault(),e.stopPropagation()}),e.addEventListener(o,r,"mousedown",e=>{e.preventDefault(),e.stopPropagation()});const d=o?l.getState().getInstance(o):null,u=d?.config.classNames?.tooltips,m=d?.config.styles?.tooltips;J(p,"Delete block","below",u,m),t.appendChild(r)}static handleFileDrop(t,n,a,o,i){const r=t.dataTransfer?.files;if(r&&r.length>0){const t=r[0];e.isValidVideoFile(t)?e.processVideoFile(t,n,a,o,i):e.showError(n,"Please select a valid video file (MP4, WebM, OGV)")}}static handleFileSelect(t,n,a,o){const i=document.createElement("input");i.type="file",i.accept="video/*",i.style.display="none",i.addEventListener("change",()=>{const r=i.files;if(r&&r.length>0){const i=r[0];e.isValidVideoFile(i)?e.processVideoFile(i,t,n,a,o):e.showError(t,"Please select a valid video file (MP4, WebM, OGV)")}}),document.body.appendChild(i),i.click(),document.body.removeChild(i)}static isValidVideoFile(t){return e.validTypes.includes(t.type)||t.type.startsWith("video/")}static async processVideoFile(t,n,o,i,r){e.showLoading(n);try{let s=await o(t);if(s){e.renderVideo(n,{alignment:"center",alt:t.name,caption:"",url:s},o,i,r);const c=n.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id");c&&l.getState().updateBlockData(i,or.getBlockIndex(i,c),or.getBlockData(c).data)}else e.showError(n,"Failed to upload video. Please try again.")}catch(s){console.error("Video upload error:",s),e.showError(n,"Failed to upload video. Please try again.")}}static showLoading(e){e.innerHTML="";const t=a.createStyledElement("div","clepit-video-loading",void 0);t.textContent="Uploading video...",e.appendChild(t)}static showError(e,t){e.innerHTML="";const n=a.createStyledElement("div","clepit-video-error",void 0);n.textContent=t,e.appendChild(n)}static setAlignment(e,t){const n=e.querySelector(".clepit-video-wrapper");n&&(n.classList.remove("clepit-video-wrapper--left","clepit-video-wrapper--center","clepit-video-wrapper--right"),n.classList.add(`clepit-video-wrapper--${t}`));const a=or.getEditorId(e);if(!a)return;const o=e.getAttribute("data-id");o&&l.getState().partialUpdateBlockData(a,or.getBlockIndex(a,o),{alignment:t})}static isEmpty(e){const t=e.querySelector(`.${a.classNames.block.video.wrapper} video`),n=e.querySelector(`.${a.classNames.block.video.wrapper} iframe`),o=e.querySelector(`.${a.classNames.block.video.captionEditable}`);let i=!1,r=!1,s=!1;return t&&t.getAttribute("src")?.trim()||(i=!0),n&&n.getAttribute("src")?.trim()||(r=!0),o?I(o.innerHTML)&&(s=!0):s=!0,i&&r&&s}static isEmptyData(e){return!e.url?.trim()&&I(e.caption)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},ei=class e{static render(t,n,o,i){if(a.injectStyles("clepit-video-output-styles",Yo),!e.validate(t))return xe();if(Qo.isEmptyData(t))return document.createElement("div");const r=t.url,s=t.caption,l=t.alignment||"center",c=a.createStyledElement("div","clepit-output-video-container",{classNames:i?.container,styles:o?.container}),p=a.createStyledElement("div","clepit-output-video-wrapper");switch(l){case"left":p.classList.add("clepit-output-video-wrapper--left");break;case"center":p.classList.add("clepit-output-video-wrapper--center");break;case"right":p.classList.add("clepit-output-video-wrapper--right")}const d=ie(r),u=re(r);if(d||u){const e=B("iframe","clepit-output-video-iframe");e.src=r,e.setAttribute("frameborder","0"),e.setAttribute("allowfullscreen","true"),e.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"),e.style.maxWidth="100%",e.style.width="560px",e.style.height="315px",e.style.display="block",e.style.borderRadius="8px",p.appendChild(e),c.appendChild(p)}else{const e=B("video","clepit-output-video");e.src=r,e.controls=!0,e.preload="metadata",e.style.maxWidth="100%",e.style.height="auto",e.style.display="block",p.appendChild(e),c.appendChild(p)}if(s){const e=a.createStyledElement("figcaption","clepit-output-video-caption",{classNames:i?.caption,styles:o?.caption}),n=t.caption;e.innerHTML=n&&n!==s?n:s,c.appendChild(e)}if(o&&(o.container&&Object.assign(c.style,o.container),o.caption)){const e=c.querySelector(".clepit-output-video-caption");e&&Object.assign(e.style,o.caption)}if(i&&(i.container&&c.classList.add(i.container),i.caption)){const e=c.querySelector(".clepit-output-video-caption");e&&e.classList.add(i.caption)}return c}static draw(t,n=ue){if(!e.validate(t)||Qo.isEmptyData(t))return null;const a=n.create("div");a.addClass("clepit-output-video-container");const o=n.create("div");o.addClass("clepit-output-video-wrapper");const i=t.alignment??"center";i&&o.addClass(`clepit-output-video-wrapper--${i}`);const r=n.create("video");if(r.addClass("clepit-output-video"),r.setAttribute("src",t.url),r.setAttribute("controls","controls"),o.append(r),a.append(o),t.caption){const e=n.create("figcaption");e.addClass("clepit-output-video-caption"),e.setHtml(t.caption),a.append(e)}return a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.url}},ti=(e,t,n)=>{switch(e.type){case"alert":return ke.draw(e.data,t);case"audio":return Ne.draw(e.data,t);case"checklist":return Ie.draw(e.data,t);case"code":return wt.draw(e.data,t,n);case"collapsible":return ai.draw(e.data,t,n);case"collection":return Mt.draw(e.data,t);case"columns":return _t.draw(e.data,t,n);case"date":return Rt.draw(e.data,t);case"delimiter":return Ut.draw(e.data,t);case"doc_card":return Jt.draw(e.data,t,n);case"embed":return sn.draw(e.data,t,n);case"file":return un.draw(e.data,t);case"glance":return gn.draw(e.data,t);case"header":return yn.draw(e.data,t);case"image":return wn.draw(e.data,t);case"latex":return Uo.draw(e.data,t);case"list":return Sn.draw(e.data,t);case"mermaid":return Wo.draw(e.data,t);case"openapi":return ta.draw(e.data,t);case"paragraph":return oa.draw(e.data,t);case"quote":return la.draw(e.data,t);case"sketch":return ga.draw(e.data,t);case"table":return ka.draw(e.data,t);case"toc":return Na.draw(e.data,t,n);case"updates":return Xo.draw(e.data,t);case"video":return ei.draw(e.data,t);default:return ni(e)}},ni=e=>(console.warn("drawBlock: no drawer for block",e),null),ai=class e{static render(t,n,o,i){if(a.injectStyles("collapsible-output",Nt),!e.validate(t))return xe();const r=a.createStyledElement("details","clepit-collapsible clepit-output-collapsible",{classNames:i?.section,styles:o?.section});r.open=t.open??!1;const s=document.createElement("summary"),l=document.createElement("span");l.innerHTML=M(t.html),s.appendChild(l),r.appendChild(s);const c=document.createElement("div");c.className="clepit-collapsible__children";for(const a of t.children??[])c.appendChild(e.renderChild(a,n));return r.appendChild(c),r}static renderChild(e,t){const n=Xi.find(t=>t.type===e.type);if(!n){const t=document.createElement("div");return t.className="clepit-collapsible__unknown-child",t.textContent=`Unsupported block: ${e.type}`,t}return n.output.render(e.data,t)}static draw(t,n=ue,a){if(!e.validate(t))return null;const o=n.create("details");o.addClass("clepit-collapsible","clepit-output-collapsible"),t.open&&o.setAttribute("open","");const i=n.create("summary"),r=n.create("span");r.setHtml(t.html),i.append(r),o.append(i);const s=n.create("div");s.addClass("clepit-collapsible__children");for(const e of t.children??[]){const t=ti(e,n,a);t&&s.append(t)}return o.append(s),o}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"html"in e&&"string"==typeof e.html&&(void 0===e.children||Array.isArray(e.children))}},oi={icon:"▸",get input(){return Lt},label:"Collapsible section",get output(){return ai},shortcut:v("E"),testId:"block-type-collapsible",type:"collapsible"},ii=new WeakMap,ri=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){const t=e.classList.contains("clepit-collection")?e:e.querySelector(".clepit-collection");if(t){const e=ii.get(t);if(e)return e;const n=t.getAttribute("data-collection-id");if(n)return{collectionId:n}}return{collectionId:""}}static render(e,t,n){a.injectStyles("collection-input",$t);const o=t??{collectionId:""},i=Mt.render(o,void 0,n?.styles,n?.classNames);return i.classList.add("clepit-collection--input"),i.setAttribute("contenteditable","false"),ii.set(i,o),i}static isEmpty(t){return""===e.save(t).collectionId}static isEmptyData(e){return!e.collectionId}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},si={icon:"▦",get input(){return ri},label:"Collection",get output(){return Mt},shortcut:v("G"),testId:"block-type-collection",type:"collection"},li=new WeakMap;var ci=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){const t=e.classList.contains("clepit-columns")?e:e.querySelector(".clepit-columns");if(!t)return{columns:[[],[]]};const n=li.get(t)??[],a=[];return t.querySelectorAll(":scope > .clepit-columns__column").forEach((e,t)=>{const o=n[t]??[],i=[];e.querySelectorAll(":scope > .clepit-columns__child").forEach((e,t)=>{const n=o[t],a=e.getAttribute("data-child-type")??n?.type,r=a?function(e){return Xi.find(t=>t.type===e)}(a):void 0;if(r){const t=r.input.save(e);i.push({...n?.id?{id:n.id}:{},data:t,type:r.type})}else n&&i.push(n)}),a.push(i)}),{columns:a.length>=2?a:[[],[]]}}static render(t,n,o){a.injectStyles("columns-input",qt);const i=n&&Array.isArray(n.columns)&&n.columns.length>=2?n:{columns:[[],[]]},r=a.createStyledElement("div","clepit-columns clepit-columns--input",{classNames:o?.classNames?.container,styles:o?.styles?.container});return li.set(r,i.columns.map(e=>[...e])),i.columns.forEach(n=>{const i=a.createStyledElement("div","clepit-columns__column",{classNames:o?.classNames?.column,styles:o?.styles?.column});n.forEach(n=>{i.appendChild(e.renderChild(t,n))}),r.appendChild(i)}),r}static renderChild(e,t){const n=document.createElement("div");n.className="clepit-columns__child";const a=or.renderTool(t.type,t.data,e);if(a)n.setAttribute("data-child-type",t.type),n.appendChild(a);else{const e=document.createElement("div");e.className="clepit-columns__unknown-child",e.textContent=`Unsupported block: ${t.type}`,n.appendChild(e)}return n}static isEmpty(e){const t=e.querySelector(".clepit-columns");return!t||0===t.querySelectorAll(".clepit-columns__child").length}static isEmptyData(e){return(e.columns??[]).every(e=>0===e.length)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},pi={icon:"▥",get input(){return ci},label:"Columns",get output(){return _t},shortcut:v("L"),testId:"block-type-columns",type:"columns"},di=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){return{date:(e.matches('input[type="date"]')?e:e.querySelector('input[type="date"]'))?.value??""}}static render(t,n,o){a.injectStyles("date-input",zt);const i=a.createStyledElement("input","clepit-date clepit-date--input",{classNames:o?.classNames?.pill,styles:o?.styles?.pill});return i.type="date",n?.date&&Pt(n.date)&&(i.value=n.date),e.addEventListener(t,i,"keydown",e=>{e.stopPropagation()}),i}static isEmpty(t){return""===e.save(t).date}static isEmptyData(e){return!e.date}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},ui={icon:"▤",get input(){return di},label:"Date",get output(){return Rt},shortcut:v("D"),testId:"block-type-date",type:"date"},mi={icon:"—",get input(){return Vt},label:"Delimiter",get output(){return Ut},shortcut:v("D"),testId:"block-type-delimiter",type:"delimiter"},hi=new WeakMap,gi=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){const t=e.classList.contains("clepit-doc-card")?e:e.querySelector(".clepit-doc-card");if(t){const e=hi.get(t);if(e)return e;const n=t.getAttribute("data-page-id");if(n)return{pageId:n,title:t.querySelector(".clepit-doc-card__title")?.textContent??""}}return{pageId:"",title:""}}static render(e,t,n){a.injectStyles("doc-card-input",Kt);const o=t??{pageId:"",title:""},i=Jt.render(o,void 0,n?.styles,n?.classNames);return i.classList.add("clepit-doc-card--input"),i.setAttribute("contenteditable","false"),hi.set(i,o),i}static isEmpty(t){return""===e.save(t).pageId}static isEmptyData(e){return!e.pageId}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},bi={icon:"🗎",get input(){return gi},label:"Doc card",get output(){return Jt},shortcut:v("K"),testId:"block-type-doc-card",type:"doc_card"},fi=new WeakMap,yi=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){const t=e.classList.contains("clepit-output-embed")?e:e.querySelector(".clepit-output-embed");return(t?fi.get(t):void 0)??{url:""}}static render(e,t,n){a.injectStyles("embed-input",Zt);const o=t??{url:""},i=sn.render(o,void 0,n?.styles,n?.classNames);return i.classList.add("clepit-embed--input"),i.setAttribute("contenteditable","false"),fi.set(i,o),i}static isEmpty(t){return""===e.save(t).url}static isEmptyData(e){return!e.url}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},vi={icon:"🔗",get input(){return yi},label:"Embed",get output(){return sn},shortcut:v("M"),testId:"block-type-embed",type:"embed"},xi=new WeakMap,ki=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.classList.contains("clepit-file-host")?e:e.querySelector(".clepit-file-host");if(t){const e=xi.get(t);if(e)return e}return{name:"",url:""}}static render(t,n,o,i){a.injectStyles("file-input",cn);const r=document.createElement("div");return r.className="clepit-file-host",r.setAttribute("contenteditable","false"),o?.url&&o.name&&xi.set(r,o),e.renderState(r,t,n,i),r}static renderState(t,n,a,o){t.innerHTML="";const i=xi.get(t);if(!i){const i=document.createElement("button");return i.type="button",i.className="clepit-file__upload",i.setAttribute("data-testid","file-upload-button"),i.textContent="Upload file",e.addEventListener(a,i,"click",()=>{e.pick(t,n,a,o)}),void t.appendChild(i)}const r=un.render(i,void 0,o?.styles,o?.classNames);r.removeAttribute("href"),t.appendChild(r)}static pick(t,n,a,o){const i=document.createElement("input");i.type="file",i.addEventListener("change",async()=>{const r=i.files?.[0];if(!r)return;const s=await n(r);xi.set(t,{contentType:r.type||void 0,name:r.name,size:r.size,url:s}),e.renderState(t,n,a,o)}),i.click()}static isEmpty(t){return""===e.save(t).url}static isEmptyData(e){return!e.url}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},wi={icon:"📎",get input(){return ki},label:"File",get output(){return un},shortcut:v("F"),testId:"block-type-file",type:"file"},Ci={html:"",label:""},Ei=class e{static{this.placeholder="At a glance"}static save(e){const t=e.classList.contains("clepit-glance")?e:e.querySelector(".clepit-glance");if(!t)return{rows:[]};const n=[...t.querySelectorAll(".clepit-glance-label")],a=[...t.querySelectorAll(".clepit-glance-value")],o=n.map((e,t)=>({html:M(a[t]?.innerHTML??""),label:e.textContent??""})),i=t.getAttribute("data-variant")??"plain",r=t.querySelector(".clepit-glance-caption")?.textContent??"";return r?{caption:r,rows:o,variant:i}:{rows:o,variant:i}}static render(e,t,n){a.injectStyles("clepit-glance-input-styles","\n.clepit-glance--input {\n cursor: text;\n}\n\n.clepit-glance--input .clepit-glance-label:empty::before,\n.clepit-glance--input .clepit-glance-value:empty::before {\n color: var(--clepit-text-subtle);\n content: attr(data-placeholder);\n font-style: italic;\n pointer-events: none;\n}\n");const o=t?.rows?.length?t:{rows:[Ci]},i=gn.render(o,void 0,n?.styles,n?.classNames);i.classList.add("clepit-glance--input");for(const a of i.querySelectorAll(".clepit-glance-label"))a.setAttribute("contenteditable","true"),a.setAttribute("data-placeholder","Label");for(const a of i.querySelectorAll(".clepit-glance-value"))a.setAttribute("contenteditable","true"),a.setAttribute("data-placeholder","Value");return i}static changeVariant(t,n,o){const i=l.getState().getInstance(o);if(!i)return;if((t.getAttribute("data-variant")??"plain")===n)return;const r=or.getBlockIndex(o,t.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id")),s={...e.save(t),variant:n},c={classNames:i.config.classNames?.blocks?.glance,margins:i.config.margins,styles:i.config.styles?.blocks?.glance},p=e.render(o,s,c);t.replaceWith(p),l.getState().updateBlockData(o,r,s)}static isEmpty(t){return e.isEmptyData(e.save(t))}static isEmptyData(e){return!e?.rows?.length||e.rows.every(e=>""===e.label.trim()&&""===M(e.html).trim())}static destroy(e){}},Si={icon:"≡",get input(){return Ei},label:"At a glance",get output(){return gn},shortcut:v("N"),testId:"block-type-glance",type:"glance"},Ni={icon:"H",get input(){return fn},label:"Header",get output(){return yn},shortcut:v("H"),testId:"block-type-header",type:"header"},Ai={icon:"𝑖",get input(){return kn},label:"Image",get output(){return wn},shortcut:v("I"),testId:"block-type-image",type:"image"},Li={icon:"•",get input(){return En},label:"List",get output(){return Sn},shortcut:v("L"),testId:"block-type-list",type:"list"},Bi="clepit-openapi__source",$i=(e,t)=>{const n=e.trim();if(""===n)return{};if(/^https?:\/\//i.test(n))return{url:n};try{return{spec:JSON.parse(n)}}catch{return t??{}}},Ii=class e{static{this.placeholder="Paste an OpenAPI document, or a URL to one…"}static{this.dataMap=new WeakMap}static render(t,n,o){a.injectStyles("clepit-openapi-input-styles","\n.clepit-openapi-input {\n display: flex;\n flex-direction: column;\n gap: 12px;\n}\n\n.clepit-openapi__source {\n background: var(--clepit-code-bg);\n border: 1px solid var(--clepit-code-border);\n border-radius: 6px;\n color: var(--clepit-code-text);\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n font-size: 13px;\n max-height: 240px;\n overflow: auto;\n padding: 12px;\n white-space: pre-wrap;\n}\n\n.clepit-openapi__source[data-placeholder]:empty::before {\n color: var(--clepit-text-subtle);\n content: attr(data-placeholder);\n font-style: italic;\n pointer-events: none;\n}\n");const i=B("div","clepit-openapi-input"),r=B("div",Bi);r.setAttribute("contenteditable","true"),r.setAttribute("data-placeholder",e.placeholder),r.setAttribute("data-testid","openapi-source"),r.textContent=n?.url??(n?.spec?JSON.stringify(n.spec,null,2):"");const s=B("div","clepit-openapi-input__preview");return s.setAttribute("data-testid","openapi-preview"),n&&s.appendChild(ta.render(n)),r.addEventListener("input",()=>{const t=$i(r.textContent??"",e.dataMap.get(i));e.dataMap.set(i,t),s.replaceChildren(ta.render(t))}),n&&e.dataMap.set(i,n),i.appendChild(r),i.appendChild(s),i}static save(t){const n=(e=>e.classList.contains(Bi)?e:e.querySelector(`.${Bi}`))(t),a=t.classList.contains("clepit-openapi-input")?t:t.querySelector(".clepit-openapi-input"),o=a?e.dataMap.get(a):void 0;return $i(n?.textContent??"",o)}static isEmpty(t){return e.isEmptyData(e.save(t))}static isEmptyData(e){return void 0===e.spec&&!e.url}static destroy(e){}},Mi={icon:"⇄",get input(){return Ii},label:"API reference",get output(){return ta},shortcut:v("A"),testId:"block-type-openapi",type:"openapi"},Ti={icon:"¶",get input(){return aa},label:"Paragraph",get output(){return oa},shortcut:v("P"),testId:"block-type-paragraph",type:"paragraph"},qi={icon:"“",get input(){return sa},label:"Quote",get output(){return la},shortcut:v("Q"),testId:"block-type-quote",type:"quote"},Di=new WeakMap,_i=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){const t=e.classList.contains("clepit-sketch")?e:e.querySelector(".clepit-sketch");return(t?Di.get(t):void 0)??{strokes:[]}}static render(t,n,o){a.injectStyles("sketch-input",pa);const i=n??{strokes:[]},r=ga.render(i,void 0,o?.styles,o?.classNames);return r.classList.add("clepit-sketch--input"),r.setAttribute("contenteditable","false"),Di.set(r,i),e.attachDrawing(t,r),r}static attachDrawing(t,n){const a=n.querySelector("svg");if(!a)return;let o=null;const i=e=>{const t=a.getBoundingClientRect(),n=0===t.width?0:(e.clientX-t.left)/t.width*1e3,o=0===t.height?0:(e.clientY-t.top)/t.height*240;return[Math.round(100*n)/100,Math.round(100*o)/100]},r=()=>{const e=Di.get(n)??{strokes:[]},t=o&&o.length>=4?{strokes:[...e.strokes,{points:o}]}:e,i=ga.render(t).querySelector("svg");i&&a.replaceChildren(...Array.from(i.childNodes))},s=[],l=(e,t)=>{a.addEventListener(e,t),s.push({element:a,event:e,handler:t})};l("pointerdown",e=>{o=i(e),e.target.setPointerCapture?.(e.pointerId)}),l("pointermove",e=>{o&&(o.push(...i(e)),r())});const c=()=>{if(o&&o.length>=4){const e=Di.get(n)??{strokes:[]};Di.set(n,{strokes:[...e.strokes,{points:o}]})}o=null,r()};l("pointerup",c),l("pointercancel",c),e.eventListenersMap[t]=[...e.eventListenersMap[t]??[],...s]}static isEmpty(t){return 0===e.save(t).strokes.length}static isEmptyData(e){return 0===(e.strokes??[]).length}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},ji={icon:"✏️",get input(){return _i},label:"Sketch",get output(){return ga},shortcut:v("W"),testId:"block-type-sketch",type:"sketch"},zi={icon:"⊞",get input(){return ya},label:"Table",get output(){return ka},shortcut:v("T"),testId:"block-type-table",type:"table"},Oi=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){return{}}static render(e,t,n){a.injectStyles("toc-input",Ca);const o=l.getState().getData(e)?.blocks??[],i=Na.render({},{documentBlocks:o},n?.styles,n?.classNames);return i.classList.add("clepit-toc--input"),i.setAttribute("contenteditable","false"),i}static isEmpty(e){return!1}static isEmptyData(e){return!1}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Hi={icon:"≡",get input(){return Oi},label:"Table of contents",get output(){return Na},shortcut:v("T"),testId:"block-type-toc",type:"toc"},Pi={latex:"LaTeX",mermaid:"Mermaid"};function Ri(e){const t=e.classList.contains("clepit-typeset")?e:e.querySelector(".clepit-typeset"),n=t?.querySelector(".clepit-typeset__source"),a=t?.querySelector(".clepit-typeset__title")?.textContent?.trim();return a?{source:n?.textContent??"",title:a}:{source:n?.textContent??""}}function Fi(e,t,n){a.injectStyles("typeset-input",La);const o=t??{source:""},i=a.createStyledElement("div",`clepit-typeset clepit-output-typeset clepit-typeset--input clepit-typeset--${e}`,{classNames:n?.classNames?.wrapper,styles:n?.styles?.wrapper});i.setAttribute("data-language",e),i.setAttribute("data-rendered","source");const r=B("span","clepit-typeset__kind");r.textContent=Pi[e],i.appendChild(r);const s=B("span","clepit-typeset__title");s.setAttribute("data-testid","typeset-title"),s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder","mermaid"===e?"What does this diagram show?":"What does this formula show?"),s.textContent=o.title??"",i.appendChild(s);const l=B("pre","clepit-typeset__source");return l.setAttribute("contenteditable","true"),l.textContent=o.source,i.appendChild(l),i}var Vi=class{static{this.placeholder=""}static save(e){return Ri(e)}static render(e,t,n){return Fi("latex",t,n)}static isEmpty(e){return""===Ri(e).source.trim()}static isEmptyData(e){return!e.source.trim()}static destroy(e){}},Ui=class{static{this.placeholder=""}static save(e){return Ri(e)}static render(e,t,n){return Fi("mermaid",t,n)}static isEmpty(e){return""===Ri(e).source.trim()}static isEmptyData(e){return!e.source.trim()}static destroy(e){}},Wi={icon:"∑",get input(){return Vi},label:"LaTeX",get output(){return Uo},shortcut:v("X"),testId:"block-type-latex",type:"latex"},Ki={icon:"◈",get input(){return Ui},label:"Mermaid",get output(){return Wo},shortcut:v("Y"),testId:"block-type-mermaid",type:"mermaid"},Gi=new WeakMap,Ji=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){const t=e.classList.contains("clepit-updates")?e:e.querySelector(".clepit-updates");if(t){const e=Gi.get(t);if(e)return e;const n=t.getAttribute("data-page-id");if(n)return{pageId:n}}return{}}static render(e,t,n){a.injectStyles("updates-input",Go);const o=t??{},i=Xo.render(o,void 0,n?.styles,n?.classNames);return i.classList.add("clepit-updates--input"),i.setAttribute("contenteditable","false"),Gi.set(i,o),i}static isEmpty(e){return!1}static isEmptyData(e){return!1}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Xi=[we,Ae,Me,Ct,oi,si,{icon:"🕘",get input(){return Ji},label:"Updates",get output(){return Xo},shortcut:v("U"),testId:"block-type-updates",type:"updates"},pi,ui,mi,bi,vi,wi,Si,Ni,Ai,Li,Mi,Ti,qi,ji,Wi,Ki,zi,Hi,{icon:"▶",get input(){return Qo},label:"Video",get output(){return ei},shortcut:v("V"),testId:"block-type-video",type:"video"}],Zi="clepit-block-type-selector",Yi="clepit-code-language-submenu",Qi="clepit-code-theme-submenu",er="clepit-convert-submenu",tr="clepit-block-operations-menu";var nr,ar=class e{static{this.defaultClassName="clepit-block-toolbar"}static{this.menuAnchor="--clepit-block-toolbar"}static{this.submenuAnchorSeq=0}static{this.eventListenersMap=new WeakMap}static{this.documentListeners=[]}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap.get(t)||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap.set(t,i)}static addDocumentEventListener(t,n){const a=e=>n(e);document.addEventListener(t,a),e.documentListeners.push({event:t,handler:a})}static create({containerId:t,block:n}){const o=l.getState().getInstance(t);if(!o)return console.error("BlockToolbar::create: Instance not found for containerId:",t);const i=document.getElementById(t);if(!i)return console.error("BlockToolbar::create: Container not found for containerId:",t);e.eventListenersMap.has(i)||e.eventListenersMap.set(i,[]);const r=void 0!==o.config.audioUploader,s=void 0!==o.config.imageUploader,c=void 0!==o.config.videoUploader,p=o.config.classNames?.blockToolbar,d=o.config.classNames?.blockTypeMenu,u=o.config.classNames?.convertSubmenu,m=o.config.classNames?.operationsMenu,h=o.config.styles?.blockToolbar,g=o.config.styles?.blockTypeMenu,b=o.config.styles?.convertSubmenu,f=o.config.styles?.operationsMenu;e.remove(n),a.injectStyles("clepit-block-toolbar-styles",'\n/* Block Toolbar */\n.clepit-block-toolbar {\n position: absolute;\n left: 4px;\n top: 4px;\n z-index: 1000;\n display: none;\n gap: 4px;\n flex-shrink: 0;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n overflow: hidden;\n padding: 4px;\n transition: transform 0.2s ease;\n}\n\n.clepit-block-toolbar--visible {\n display: flex !important;\n transform: translateY(0) !important;\n pointer-events: auto !important;\n}\n\n.clepit-block-toolbar--hidden {\n display: none !important;\n pointer-events: none !important;\n}\n\n.clepit-block--active .clepit-block-toolbar,\n.clepit-block:focus-within .clepit-block-toolbar,\n.clepit-block-toolbar[style*="display: flex"] {\n display: flex;\n pointer-events: auto;\n}\n\n.clepit-block-toolbar-add,\n.clepit-block-toolbar-ops {\n width: 24px;\n height: 24px;\n border: none;\n border-radius: 4px;\n background: transparent;\n color: var(--clepit-text-muted);\n font-size: 14px;\n font-weight: bold;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s ease;\n}\n\n.clepit-block-toolbar-add:hover,\n.clepit-block-toolbar-ops:hover {\n background: var(--clepit-toolbar-button-hover-bg, var(--clepit-selection-bg));\n color: var(--clepit-toolbar-button-hover-color, var(--clepit-primary));\n transform: scale(1.05);\n}\n\n.clepit-block-toolbar-add:active,\n.clepit-block-toolbar-ops:active {\n transform: scale(0.95);\n}\n\n/* Block toolbar positioning and display classes */\n.clepit-block-toolbar--positioned {\n position: absolute;\n}\n\n.clepit-block-toolbar--menu-positioned {\n position: absolute;\n z-index: 1001;\n}\n\n.clepit-block-toolbar--submenu-positioned {\n position: absolute;\n z-index: 998;\n}\n\n.clepit-block-toolbar--item-hidden {\n display: none;\n}\n\n.clepit-block-toolbar--item-visible {\n display: flex;\n}\n\n.clepit-block-toolbar--separator-hidden {\n display: none;\n}\n\n.clepit-block-toolbar--separator-visible {\n display: block;\n}\n\n.clepit-block-toolbar--delete-disabled {\n opacity: 0.5;\n cursor: not-allowed;\n pointer-events: none;\n}\n\n.clepit-block-toolbar--delete-enabled {\n color: var(--clepit-error);\n}\n\n/* The toolbar stays absolutely positioned at every width. It used to go\n * position: static below 768px, which made it a flex item of .clepit-block —\n * and because it is appended after the content it landed to the RIGHT of the\n * text rather than above it, taking a further 60px off an already narrow\n * column. Absolute keeps it inside the gutter the block opens for it. */\n');const y=B("div",e.defaultClassName);y.id=`${t}-block-toolbar`,y.innerHTML="",a.applyStyling(y,{classNames:p?.container,styles:h?.container});const v=B("button","clepit-block-toolbar-add",{"data-testid":"toolbar-add-button",type:"button"});v.innerHTML="+",a.applyStyling(v,{classNames:p?.button,styles:h?.button}),e.addEventListener(i,v,"click",()=>e.showBlockTypeMenu({audioIsEnabled:r,block:n,classNames:d,containerId:t,imageIsEnabled:s,styles:g,toolLabels:o.config.blockToolLabels,videoIsEnabled:c}));const x=B("button","clepit-block-toolbar-ops",{"data-testid":"toolbar-operations-button",type:"button"});x.innerHTML="⋯",a.applyStyling(x,{classNames:p?.button,styles:h?.button}),e.addEventListener(i,x,"click",()=>e.showOperationsMenu({audioIsEnabled:r,block:n,classNames:m,containerId:t,convertSubmenuClassNames:u,convertSubmenuStyles:b,imageIsEnabled:s,operationLabels:o.config.blockToolbarLabels,styles:f,videoIsEnabled:c})),y.appendChild(v),y.appendChild(x),e.addEventListener(i,y,"click",e=>e.stopPropagation()),n.appendChild(y)}static showBlockTypeMenu({containerId:t,block:n,imageIsEnabled:o,videoIsEnabled:i,audioIsEnabled:r,classNames:s,styles:l,toolLabels:c}){e.closeAllMenus();const p=document.querySelector(`.${Zi}`);if(p)return p.classList.remove(`${Zi}--visible`),p.classList.add(`${Zi}--hidden`),void setTimeout(()=>p.remove(),200);const d=B("div",Zi);a.applyStyling(d,{classNames:s?.container,styles:l?.container});const u=B("input","",{placeholder:"Search blocks...",type:"text"});u.setAttribute("data-testid","block-type-search"),a.applyStyling(u,{classNames:s?.input,styles:l?.input}),d.appendChild(u);const m=document.querySelector(`#${t}`),h=B("div",`${Zi}-items`),g=p=>{h.innerHTML="",p.forEach(p=>{if("image"===p.type&&!o)return;if("video"===p.type&&!i)return;if("audio"===p.type&&!r)return;const u=B("div","clepit-menu-item clepit-block-type-item");u.setAttribute("data-testid",`block-type-${p.type}`),a.applyStyling(u,{classNames:s?.item?.container,styles:l?.item?.container});const g=B("span","clepit-menu-icon "+("image"===p.type?"clepit-menu-icon--italic":""));g.textContent=p.icon,a.applyStyling(g,{classNames:s?.item?.icon,styles:l?.item?.icon}),u.appendChild(g);const b=B("span","");var f;if(b.textContent=(f=p.type,(Y.includes(f)?c?.[p.type]:void 0)??p.label),a.applyStyling(b,{classNames:s?.item?.text,styles:l?.item?.text}),u.appendChild(b),p.shortcut){const e=B("span","clepit-menu-shortcut");e.textContent=p.shortcut,a.applyStyling(e,{classNames:s?.item?.shortcut,styles:l?.item?.shortcut}),u.appendChild(e)}e.addEventListener(m,u,"click",e=>{if(e.stopPropagation(),n){const e=or.getBlockIndex(t,n.getAttribute("data-id")||"");or.insertBlock({data:{html:""},type:p.type},t,e+1)}d.hidePopover()}),h.appendChild(u)})};if(g(Xi),e.addEventListener(m,u,"click",e=>e.stopPropagation()),e.addEventListener(m,u,"focus",e=>e.stopPropagation()),e.addEventListener(m,u,"input",()=>{const e=u.value.toLowerCase(),t=Xi.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e));if(g(t),0===t.length&&""!==e.trim()){const e=B("div","clepit-not-found-message",{style:"padding: 8px 12px; color: #666; font-style: italic; text-align: center;"});e.textContent="No block types found",h.appendChild(e)}}),e.addEventListener(m,u,"keydown",e=>{"Escape"===e.key&&d.hidePopover()}),d.appendChild(h),d.classList.add(Zi),d.setAttribute("popover","auto"),u.setAttribute("autofocus",""),n){const t=n.querySelector(`.${e.defaultClassName}`);t&&t.style.setProperty("anchor-name",e.menuAnchor)}document.body.appendChild(d),d.addEventListener("toggle",e=>{"closed"===e.newState&&d.remove()}),"function"!=typeof d.showPopover?(d.classList.add(`${Zi}--visible`),u.focus(),e.addDocumentEventListener("click",e=>{const t=e.target;d.contains(t)||n?.contains(t)||d.remove()})):d.showPopover()}static showOperationsMenu({containerId:t,block:n,classNames:o,styles:i,convertSubmenuClassNames:r,convertSubmenuStyles:s,imageIsEnabled:l,videoIsEnabled:c,audioIsEnabled:p,operationLabels:d}){e.closeAllMenus();const u=B("div",tr);i?.container&&a.applyStyling(u,{classNames:o?.container,styles:i.container}),o?.container&&u.classList.add(o.container);const m=B("input","",{placeholder:"Search operations...",type:"text"});m.setAttribute("data-testid","operations-search"),a.applyStyling(m,{classNames:o?.input,styles:i?.input}),u.appendChild(m);const h=document.querySelector(`#${t}`),g=B("div",`${tr}-items`),b=n.getAttribute("data-tool");if(!b)return;const f=(e,t)=>d?.[e]??t,y=[{icon:"←",label:"Align Left",testId:"image-align-left",value:"imageAlignLeft"},{icon:"↔",label:"Align Center",testId:"image-align-center",value:"imageAlignCenter"},{icon:"→",label:"Align Right",testId:"image-align-right",value:"imageAlignRight"}],v=[{icon:"←",label:"Align Left",testId:"video-align-left",value:"videoAlignLeft"},{icon:"↔",label:"Align Center",testId:"video-align-center",value:"videoAlignCenter"},{icon:"→",label:"Align Right",testId:"video-align-right",value:"videoAlignRight"}],x=[{icon:"←",label:"Align Left",testId:"audio-align-left",value:"audioAlignLeft"},{icon:"↔",label:"Align Center",testId:"audio-align-center",value:"audioAlignCenter"},{icon:"→",label:"Align Right",testId:"audio-align-right",value:"audioAlignRight"}],k=[{hasSubmenu:!0,icon:"⌘",label:"Language",testId:"code-language",value:"codeLanguage"},{hasSubmenu:!0,icon:"◆",label:"Theme",testId:"code-theme",value:"codeTheme"}];[{hasSubmenu:!0,icon:"↻",label:f("convert","Convert To"),testId:"operation-convert",value:"convert"},{icon:"↑",label:f("moveUp","Move Up"),shortcut:"⌘⇧↑",testId:"operation-moveUp",value:"moveUp"},{icon:"↓",label:f("moveDown","Move Down"),shortcut:"⌘⇧↓",testId:"operation-moveDown",value:"moveDown"},{icon:"×",label:f("delete","Delete"),shortcut:"⌘⇧⌫",testId:"operation-delete",value:"delete"}].forEach(d=>{const m=B("div","clepit-menu-item clepit-block-operation-item");m.setAttribute("data-testid",`operation-${d.value}`),a.applyStyling(m,{classNames:o?.item?.container,styles:i?.item?.container}),m.setAttribute("data-testid",d.testId);const b=B("span","clepit-menu-icon");b.textContent=d.icon,a.applyStyling(b,{classNames:o?.item?.icon,styles:i?.item?.icon}),m.appendChild(b);const f=B("span","");if(f.textContent=d.label,a.applyStyling(f,{classNames:o?.item?.text,styles:i?.item?.text}),m.appendChild(f),d.shortcut){const e=B("span","clepit-menu-shortcut");e.textContent=d.shortcut,a.applyStyling(e,{classNames:o?.item?.shortcut,styles:i?.item?.shortcut}),m.appendChild(e)}if(d.hasSubmenu){const e=B("span","clepit-menu-arrow");e.textContent="›",m.appendChild(e)}"delete"===d.value&&(m.classList.add("clepit-block-toolbar--delete-enabled"),1===h.querySelectorAll(".clepit-block").length&&(m.classList.add("clepit-block-toolbar--delete-disabled"),m.title="Cannot delete the last block")),e.addEventListener(h,m,"click",a=>{a.stopPropagation(),d.hasSubmenu?(document.querySelector(`.${Yi}`)?.remove(),document.querySelector(`.${Qi}`)?.remove(),e.showConvertSubmenu({audioIsEnabled:p,block:n,classNames:r,containerId:t,imageIsEnabled:l,parentItem:m,parentMenu:u,styles:s,videoIsEnabled:c})):(e.handleOperationSelect(d.value,n,t),u.remove())}),g.appendChild(m)});const w=()=>{const e=B("div","clepit-menu-divider");a.applyStyling(e,{classNames:o?.divider,styles:i?.divider}),g.appendChild(e)};if("image"===b&&(w(),y.forEach(r=>{const s=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(s,{classNames:o?.item?.container,styles:i?.item?.container}),s.setAttribute("data-testid",r.testId);const l=B("span","clepit-menu-icon");l.textContent=r.icon,a.applyStyling(l,{classNames:o?.item?.icon,styles:i?.item?.icon}),s.appendChild(l);const c=B("span","");if(c.textContent=r.label,a.applyStyling(c,{classNames:o?.item?.text,styles:i?.item?.text}),s.appendChild(c),r.value.startsWith("imageAlign")){const e=n.querySelector(".clepit-image-wrapper");if(e){const t=e.style.textAlign;("left"===t?"left":"right"===t?"right":"center")===r.value.replace("imageAlign","").toLowerCase()&&s.classList.add("active")}}e.addEventListener(h,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(r.value,n,t),u.remove()}),g.appendChild(s)})),"video"===b&&(w(),v.forEach(r=>{const s=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(s,{classNames:o?.item?.container,styles:i?.item?.container}),s.setAttribute("data-testid",r.testId);const l=B("span","clepit-menu-icon");l.textContent=r.icon,a.applyStyling(l,{classNames:o?.item?.icon,styles:i?.item?.icon}),s.appendChild(l);const c=B("span","");if(c.textContent=r.label,a.applyStyling(c,{classNames:o?.item?.text,styles:i?.item?.text}),s.appendChild(c),r.value.startsWith("videoAlign")){const e=n.querySelector(".clepit-video-wrapper");if(e){const t=e.style.textAlign;("left"===t?"left":"right"===t?"right":"center")===r.value.replace("videoAlign","").toLowerCase()&&s.classList.add("active")}}e.addEventListener(h,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(r.value,n,t),u.remove()}),g.appendChild(s)})),"audio"===b&&(w(),x.forEach(r=>{const s=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(s,{classNames:o?.item?.container,styles:i?.item?.container}),s.setAttribute("data-testid",r.testId);const l=B("span","clepit-menu-icon");l.textContent=r.icon,a.applyStyling(l,{classNames:o?.item?.icon,styles:i?.item?.icon}),s.appendChild(l);const c=B("span","");if(c.textContent=r.label,a.applyStyling(c,{classNames:o?.item?.text,styles:i?.item?.text}),s.appendChild(c),r.value.startsWith("audioAlign")){const e=n.querySelector(".clepit-audio-wrapper");if(e){const t=e.style.textAlign;("left"===t?"left":"right"===t?"right":"center")===r.value.replace("audioAlign","").toLowerCase()&&s.classList.add("active")}}e.addEventListener(h,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(r.value,n,t),u.remove()}),g.appendChild(s)})),"code"===b&&(w(),k.forEach(l=>{const c=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(c,{classNames:o?.item?.container,styles:i?.item?.container}),c.setAttribute("data-testid",l.testId);const p=B("span","clepit-menu-icon");p.textContent=l.icon,a.applyStyling(p,{classNames:o?.item?.icon,styles:i?.item?.icon}),c.appendChild(p);const d=B("span","");if(d.textContent=l.label,a.applyStyling(d,{classNames:o?.item?.text,styles:i?.item?.text}),c.appendChild(d),l.hasSubmenu){const e=B("span","clepit-menu-arrow");e.textContent="›",c.appendChild(e)}e.addEventListener(h,c,"click",a=>{a.stopPropagation(),l.hasSubmenu?"codeLanguage"===l.value?e.showCodeLanguageSubmenu({block:n,classNames:r,containerId:t,parentItem:c,parentMenu:u,styles:s}):"codeTheme"===l.value&&e.showCodeThemeSubmenu({block:n,classNames:r,containerId:t,parentItem:c,parentMenu:u,styles:s}):(e.handleOperationSelect(l.value,n,t),u.remove())}),g.appendChild(c)})),"header"===b){w();const r=e.getCurrentHeadingLevel(n);[{icon:"H1",label:"Heading 1",value:"heading-h1"},{icon:"H2",label:"Heading 2",value:"heading-h2"},{icon:"H3",label:"Heading 3",value:"heading-h3"},{icon:"H4",label:"Heading 4",value:"heading-h4"},{icon:"H5",label:"Heading 5",value:"heading-h5"},{icon:"H6",label:"Heading 6",value:"heading-h6"}].forEach(s=>{const l=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(l,{classNames:o?.item?.container,styles:i?.item?.container});const c=B("span","clepit-menu-icon");c.textContent=s.icon,a.applyStyling(c,{classNames:o?.item?.icon,styles:i?.item?.icon}),l.appendChild(c);const p=B("span","");p.textContent=s.label,a.applyStyling(p,{classNames:o?.item?.text,styles:i?.item?.text}),l.appendChild(p),s.value===`heading-${r}`&&l.classList.add("active"),e.addEventListener(h,l,"click",a=>{a.stopPropagation(),e.handleOperationSelect(s.value,n,t),u.remove()}),g.appendChild(l)})}if("list"===b){w();const r=n.querySelector(".clepit-list")?.getAttribute("data-type")||"unordered";[{icon:"•",label:"Unordered",value:"unordered"},{icon:"1.",label:"Ordered",value:"ordered"}].forEach(s=>{const l=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(l,{classNames:o?.item?.container,styles:i?.item?.container});const c=B("span","clepit-menu-icon");c.textContent=s.icon,a.applyStyling(c,{classNames:o?.item?.icon,styles:i?.item?.icon}),l.appendChild(c);const p=B("span","");p.textContent=s.label,a.applyStyling(p,{classNames:o?.item?.text,styles:i?.item?.text}),l.appendChild(p),s.value===r&&l.classList.add("active"),e.addEventListener(h,l,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`listType${s.value}`,n,t),u.remove()}),g.appendChild(l)})}if("alert"===b){w();const r=n.querySelector(".clepit-alert")?.getAttribute("data-variant")||"info";[{icon:"i",label:"Info",value:"info"},{icon:"!",label:"Warning",value:"warning"},{icon:"×",label:"Error",value:"error"},{icon:"✓",label:"Success",value:"success"},{icon:"—",label:"Plain",value:"plain"}].forEach(s=>{const l=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(l,{classNames:o?.item?.container,styles:i?.item?.container});const c=B("span","clepit-menu-icon");c.textContent=s.icon,c.style.color=e.getAlertIconColor(s.value),a.applyStyling(c,{classNames:o?.item?.icon,styles:i?.item?.icon}),l.appendChild(c);const p=B("span","");p.textContent=s.label,a.applyStyling(p,{classNames:o?.item?.text,styles:i?.item?.text}),l.appendChild(p),s.value===r&&l.classList.add("active"),e.addEventListener(h,l,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`alertVariant${s.value}`,n,t),u.remove()}),g.appendChild(l)})}if("glance"===b){w();const r=n.querySelector(".clepit-glance")?.getAttribute("data-variant")||"plain";[{icon:"—",label:"Plain",value:"plain"},{icon:"i",label:"Info",value:"info"},{icon:"!",label:"Warning",value:"warning"},{icon:"×",label:"Error",value:"error"},{icon:"✓",label:"Success",value:"success"}].forEach(s=>{const l=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(l,{classNames:o?.item?.container,styles:i?.item?.container});const c=B("span","clepit-menu-icon");c.textContent=s.icon,c.style.color=e.getAlertIconColor(s.value),a.applyStyling(c,{classNames:o?.item?.icon,styles:i?.item?.icon}),l.appendChild(c);const p=B("span","");p.textContent=s.label,a.applyStyling(p,{classNames:o?.item?.text,styles:i?.item?.text}),l.appendChild(p),s.value===r&&l.classList.add("active"),e.addEventListener(h,l,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`glanceVariant${s.value}`,n,t),u.remove()}),g.appendChild(l)})}if("delimiter"===b){w();const r=n.querySelector(".clepit-delimiter")?.getAttribute("data-variant")||"line";[{icon:"—",label:"Line",value:"line"},{icon:"***",label:"Stars",value:"stars"}].forEach(s=>{const l=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(l,{classNames:o?.item?.container,styles:i?.item?.container});const c=B("span","clepit-menu-icon");c.textContent=s.icon,a.applyStyling(c,{classNames:o?.item?.icon,styles:i?.item?.icon}),l.appendChild(c);const p=B("span","");p.textContent=s.label,a.applyStyling(p,{classNames:o?.item?.text,styles:i?.item?.text}),l.appendChild(p),s.value===r&&l.classList.add("active"),e.addEventListener(h,l,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`delimiterVariant${s.value}`,n,t),u.remove()}),g.appendChild(l)})}const C=g.querySelectorAll(".clepit-block-operation-item"),E=g.querySelectorAll(".clepit-menu-divider");if(e.addEventListener(h,m,"click",e=>e.stopPropagation()),e.addEventListener(h,m,"focus",e=>e.stopPropagation()),e.addEventListener(h,m,"input",e=>{(e=>{let t=0;C.forEach(n=>{(n.querySelector("span:last-child")?.textContent?.toLowerCase()||"").includes(e.toLowerCase())?(n.classList.remove("clepit-block-toolbar--item-hidden"),n.classList.add("clepit-block-toolbar--item-visible"),t++):(n.classList.remove("clepit-block-toolbar--item-visible"),n.classList.add("clepit-block-toolbar--item-hidden"))});const n=g.querySelector(".clepit-not-found-message");if(0===t&&""!==e.trim()){if(!n){const e=B("div","clepit-not-found-message",{style:"padding: 8px 12px; color: #666; font-style: italic; text-align: center;"});e.textContent="No operations found",g.appendChild(e)}}else n&&n.remove();E.forEach(t=>{""!==e.trim()?(t.classList.remove("clepit-block-toolbar--separator-visible"),t.classList.add("clepit-block-toolbar--separator-hidden")):(t.classList.remove("clepit-block-toolbar--separator-hidden"),t.classList.add("clepit-block-toolbar--separator-visible"))})})(e.target.value)}),e.addEventListener(h,m,"keydown",e=>{"Escape"===e.key&&u.remove()}),u.appendChild(g),u.classList.add(tr),u.setAttribute("popover","auto"),m.setAttribute("autofocus",""),n){const t=n.querySelector(`.${e.defaultClassName}`);t&&t.style.setProperty("anchor-name",e.menuAnchor)}document.body.appendChild(u),u.addEventListener("toggle",e=>{"closed"===e.newState&&u.remove()}),"function"!=typeof u.showPopover?(u.classList.add(`${tr}--visible`),m.focus(),e.addDocumentEventListener("click",e=>{const t=e.target;u.contains(t)||n?.contains(t)||t.closest?.(".clepit-block-toolbar-ops")||u.remove()})):u.showPopover()}static showConvertSubmenu({containerId:t,block:n,parentItem:o,parentMenu:i,classNames:r,styles:s,imageIsEnabled:l,videoIsEnabled:c,audioIsEnabled:p}){const d=document.querySelector(`.${er}`);d&&d.remove();const u=n.getAttribute("data-tool");if(!u)return;const m=B("div",er);m.classList.add(er),m.classList.add(`${er}--hidden`),s?.container&&a.applyStyles(m,s.container),r?.container&&m.classList.add(r.container);const h=B("input","",{placeholder:"Search convert options...",type:"text"});h.setAttribute("data-testid","convert-search"),a.applyStyling(h,{classNames:r?.input,styles:s?.input}),m.appendChild(h),setTimeout(()=>h.focus(),10);const g=document.querySelector(`#${t}`),b=B("div",`${er}-items`);Xi.filter(e=>e.type!==u&&(!("image"===e.type&&!l||"video"===e.type&&!c||"audio"===e.type&&!p)||void 0)).sort((e,t)=>e.label.localeCompare(t.label)).forEach(o=>{const l=B("div","clepit-menu-item clepit-convert-option-item");l.setAttribute("data-testid",o.testId),a.applyStyling(l,{classNames:r?.item?.container,styles:s?.item?.container});const c=B("span","clepit-menu-icon");c.textContent=o.icon,a.applyStyling(c,{classNames:r?.item?.icon,styles:s?.item?.icon}),l.appendChild(c);const p=B("span","");if(p.textContent=o.label,a.applyStyling(p,{classNames:r?.item?.text,styles:s?.item?.text}),l.appendChild(p),o.shortcut){const e=B("span","clepit-menu-shortcut");e.textContent=o.shortcut,a.applyStyling(e,{classNames:r?.item?.shortcut,styles:s?.item?.shortcut}),l.appendChild(e)}e.addEventListener(g,l,"click",e=>{e.stopPropagation();const a=n?.getAttribute("data-tool");if(!a)return;let r;if(n){const e=n.querySelector(".clepit-block-content");"paragraph"===a?r=e.querySelector(".clepit-paragraph")?.innerText||"":"quote"===a?r=e.querySelector(".clepit-quote-text")?.innerText||"":"list"===a?r=Array.from(e.querySelectorAll(".clepit-list-item")).map(e=>e.innerText.trim()).filter(Boolean).join("\n"):"alert"===a?r=e.querySelector(".clepit-alert")?.innerText||"":"header"===a&&(r=e.querySelector(".clepit-header")?.innerText||"")}const s=n?.getAttribute("data-id");s&&or.convertBlock(s,o.type,t),setTimeout(()=>{if(!n)return;const e=n.getAttribute("data-tool");if(r&&r.trim()){const t=n.querySelector(".clepit-block-content");if("paragraph"===e){const e=t.querySelector(".clepit-paragraph");e&&(e.innerText=r)}else if("quote"===e){const e=t.querySelector(".clepit-quote-text");e&&(e.innerText=r)}else if("list"===e){const e=t.querySelector(".clepit-list");e&&(e.innerHTML="",r.split("\n").forEach(t=>{const n=document.createElement("li");n.className="clepit-list-item",n.setAttribute("contenteditable","true"),n.innerText=t,e.appendChild(n)}))}else if("alert"===e){const e=t.querySelector(".clepit-alert");e&&(e.innerText=r)}else if("header"===e){const e=t.querySelector(".clepit-header");e&&(e.innerText=r)}}},0),i.remove()}),b.appendChild(l)});const f=b.querySelectorAll(".clepit-convert-option-item");e.addEventListener(g,h,"click",e=>e.stopPropagation()),e.addEventListener(g,h,"focus",e=>e.stopPropagation()),e.addEventListener(g,h,"input",e=>{(e=>{let t=0;f.forEach(n=>{(n.querySelector("span:last-child")?.textContent?.toLowerCase()||"").includes(e.toLowerCase())?(n.classList.remove("clepit-block-toolbar--item-hidden"),n.classList.add("clepit-block-toolbar--item-visible"),t++):(n.classList.remove("clepit-block-toolbar--item-visible"),n.classList.add("clepit-block-toolbar--item-hidden"))});const n=b.querySelector(".clepit-not-found-message");if(0===t&&""!==e.trim()){if(!n){const e=B("div","clepit-not-found-message",{style:"padding: 8px 12px; color: #666; font-style: italic; text-align: center;"});e.textContent="No convert options found",b.appendChild(e)}}else n&&n.remove()})(e.target.value)}),e.addEventListener(g,h,"keydown",t=>{"Escape"===t.key&&e.closeMenu(er)}),m.appendChild(b);const y="--clepit-convert-parent-"+e.submenuAnchorSeq++;o.style.setProperty("anchor-name",y),m.style.setProperty("position-anchor",y),m.classList.remove(`${er}--hidden`),m.setAttribute("popover","auto"),document.body.appendChild(m),m.addEventListener("toggle",e=>{"closed"===e.newState&&m.remove()}),"function"!=typeof m.showPopover?(i.appendChild(m),m.classList.add(`${er}--visible`),e.addDocumentEventListener("click",e=>{const t=e.target;m.contains(t)||o.contains(t)||i.contains(t)||m.remove()})):m.showPopover()}static handleOperationSelect(e,t,n){if(!t)return;const o=document.querySelector(`#${n}`);if(e.startsWith("convertTo")){const a=e.replace("convertTo",""),o=t.getAttribute("data-id");return void(o&&or.convertBlock(o,a,n))}if(e.startsWith("heading-")){const n=e.replace("heading-","");if(-1===or.getBlockIndex(o.id,t.getAttribute("data-id")))return;const a=t.querySelector('[contenteditable="true"]');return void(a&&fn.changeLevel(a,n,o.id))}if(e.startsWith("listType")){const n=e.replace("listType","");if(-1===or.getBlockIndex(o.id,t.getAttribute("data-id")))return;const a=t.querySelector(".clepit-list");return void(a&&En.changeType(a,n,o.id))}if(e.startsWith("alertVariant")){const n=e.replace("alertVariant","");if(-1===or.getBlockIndex(o.id,t.getAttribute("data-id")))return;const a=t.querySelector(".clepit-alert");return void(a&&pe.changeVariant(a,n,o.id))}if(e.startsWith("glanceVariant")){const n=e.replace("glanceVariant","");if(-1===or.getBlockIndex(o.id,t.getAttribute("data-id")))return;const a=t.querySelector(".clepit-glance");return void(a&&Ei.changeVariant(a,n,o.id))}if(e.startsWith("delimiterVariant")){const n=e.replace("delimiterVariant","");if(-1===or.getBlockIndex(o.id,t.getAttribute("data-id")))return;const a=t.querySelector(".clepit-delimiter");if(!a)return;return Vt.changeVariant(a,n,o.id)}if(e.startsWith("tableAction")){const n=e.replace("tableAction",""),o=t.querySelector(`.${a.classNames.block.content}`);if(!o)return;return ya.handleAction(n,o)}if(e.startsWith("imageAlign"))return kn.setAlignment(t,e.replace("imageAlign","").toLowerCase());if(e.startsWith("videoAlign"))return Qo.setAlignment(t,e.replace("videoAlign","").toLowerCase());if(e.startsWith("audioAlign"))return Se.setAlignment(t,e.replace("audioAlign","").toLowerCase());if(e.startsWith("codeLanguage")){const n=e.replace("codeLanguage","");if(-1===or.getBlockIndex(o.id,t.getAttribute("data-id")))return;return mt.updateLanguage(t,n)}if(e.startsWith("codeTheme")){const n=e.replace("codeTheme","");if(-1===or.getBlockIndex(o.id,t.getAttribute("data-id")))return;return mt.updateTheme(t,n)}const i=or.getBlockIndex(o.id,t.getAttribute("data-id"));if(-1!==i)switch(e){case"delete":or.removeBlock(o.id,i);break;case"moveUp":i>0&&or.moveBlock(o.id,i,i-1);break;case"moveDown":i<or.getBlocks(o.id).length-1&&or.moveBlock(o.id,i,i+1);break;default:console.warn(`Unknown block operation: ${e}`)}}static showCodeLanguageSubmenu({parentItem:t,parentMenu:n,block:o,containerId:i,classNames:r,styles:s}){const l=document.querySelector(`.${Yi}`);l&&l.remove();const c=document.querySelector(`.${Qi}`);c&&c.remove();const p=document.getElementById(i);if(!p)return;const d=o?.querySelector(`.${a.classNames.block.code.container}`)?.getAttribute("data-language")||"javascript",u=a.createStyledElement("div",Yi,{classNames:r?.container,styles:s?.container});u.classList.add(er,"clepit-block-toolbar--submenu-positioned");const m=B("input","",{placeholder:"Search languages...",type:"text"});m.setAttribute("data-testid","language-search"),u.appendChild(m);const h=mt.supportedLanguages;Object.entries(h).forEach(([t,l])=>{const c=a.createStyledElement("div","clepit-menu-item clepit-code-language-item",{classNames:r?.item?.container,styles:s?.item?.container});c.setAttribute("data-testid",`code-language-${t}`);const m=a.createStyledElement("span","",{classNames:r?.item?.text,styles:s?.item?.text});m.textContent=l.name,c.appendChild(m),t===d&&c.classList.add("active"),e.addEventListener(p,c,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`codeLanguage${t}`,o,i),n.remove()}),u.appendChild(c)});const g=u.querySelectorAll(".clepit-code-language-item");e.addEventListener(p,m,"click",e=>e.stopPropagation()),e.addEventListener(p,m,"input",e=>{const t=e.target.value.toLowerCase();g.forEach(e=>{const n=e.querySelector("span")?.textContent?.toLowerCase()||"";e.classList.toggle("clepit-block-toolbar--item-hidden",!n.includes(t))})}),n.appendChild(u);const b=t.getBoundingClientRect(),f=n.getBoundingClientRect();u.style.top=b.top-f.top+"px",u.style.left=b.right-f.left+4+"px",setTimeout(()=>{u.classList.remove(`${Yi}--hidden`),u.classList.add(`${Yi}--visible`)},10),setTimeout(()=>{const t=e=>{const a=e.target,o=u.contains(a),i=n.contains(a);o||i||(u.classList.remove(`${Yi}--visible`),u.classList.add(`${Yi}--hidden`),setTimeout(()=>u.remove(),200),document.removeEventListener("click",t))};e.addDocumentEventListener("click",t)},0)}static showCodeThemeSubmenu({parentItem:t,parentMenu:n,block:o,containerId:i,classNames:r,styles:s}){const l=document.querySelector(`.${Qi}`);l&&l.remove();const c=document.querySelector(`.${Yi}`);c&&c.remove();const p=document.getElementById(i);if(!p)return;const d=o?.querySelector(`.${a.classNames.block.code.container}`)?.getAttribute("data-theme")||"default",u=a.createStyledElement("div",Qi,{classNames:r?.container,styles:s?.container});u.classList.add(er,"clepit-block-toolbar--submenu-positioned");const m=B("input","",{placeholder:"Search themes...",type:"text"});m.setAttribute("data-testid","theme-search"),u.appendChild(m);const h=mt.supportedThemes;Object.entries(h).forEach(([t,l])=>{const c=a.createStyledElement("div","clepit-menu-item clepit-code-theme-item",{classNames:r?.item?.container,styles:s?.item?.container});c.setAttribute("data-testid",`code-theme-${t}`);const m=a.createStyledElement("span","",{classNames:r?.item?.text,styles:s?.item?.text});m.textContent=l.name,c.appendChild(m),t===d&&c.classList.add("active"),e.addEventListener(p,c,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`codeTheme${t}`,o,i),n.remove()}),u.appendChild(c)});const g=u.querySelectorAll(".clepit-code-theme-item");e.addEventListener(p,m,"click",e=>e.stopPropagation()),e.addEventListener(p,m,"input",e=>{const t=e.target.value.toLowerCase();g.forEach(e=>{const n=e.querySelector("span")?.textContent?.toLowerCase()||"";e.classList.toggle("clepit-block-toolbar--item-hidden",!n.includes(t))})}),n.appendChild(u);const b=t.getBoundingClientRect(),f=n.getBoundingClientRect();u.style.top=b.top-f.top+"px",u.style.left=b.right-f.left+4+"px",setTimeout(()=>{u.classList.remove(`${Qi}--hidden`),u.classList.add(`${Qi}--visible`)},10),setTimeout(()=>{const t=e=>{const a=e.target,o=u.contains(a),i=n.contains(a);o||i||(u.classList.remove(`${Qi}--visible`),u.classList.add(`${Qi}--hidden`),setTimeout(()=>u.remove(),200),document.removeEventListener("click",t))};e.addDocumentEventListener("click",t)},0)}static show(t,n){e.closeAllMenus(),e.hideAllToolbars(t);const a=n.querySelector(`.${e.defaultClassName}`);a&&(a.classList.add("clepit-block-toolbar--visible"),a.classList.remove("clepit-block-toolbar--hidden"))}static hide(t){document.querySelector(`.${Zi}, .${tr}, .${er}`)||e.hideAllToolbars(t)}static hideAllToolbars(t){const n=document.getElementById(t);n&&n.querySelectorAll(`.${e.defaultClassName}`).forEach(e=>{e.classList.remove("clepit-block-toolbar--visible"),e.classList.add("clepit-block-toolbar--hidden")})}static getCurrentHeadingLevel(e){if(!e)return"h1";const t=e.querySelector(".clepit-header");if(!t)return"h1";const n=t.getAttribute("data-level");if(n)return n;const a=t.tagName.toLowerCase();return a||"h1"}static closeMenu(e){const t=document.querySelector(`.${e}`);t&&(t.matches(":popover-open")&&"function"==typeof t.hidePopover?t.hidePopover():t.remove())}static closeAllMenus(){e.closeMenu(Zi),e.closeMenu(tr),e.closeMenu(er)}static getAlertIconColor(e){switch(e){case"info":return"#2196f3";case"warning":return"#ff9800";case"error":return"#f44336";case"success":return"#4caf50";default:return"#666"}}static remove(t){t.querySelectorAll(`.${e.defaultClassName}`).forEach(e=>e.remove())}static destroy(t){const n=document.getElementById(t);if(!n)return console.warn("BlockToolbar::destroy: Container not found for containerId:",t);const a=e.eventListenersMap.get(n);a&&(a.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap.delete(n)),e.documentListeners.forEach(({event:e,handler:t})=>{document.removeEventListener(e,t)}),e.documentListeners=[],n.querySelectorAll(`.${e.defaultClassName}`).forEach(e=>e.remove())}},or=class e{static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static createBlockElement(t,n){const o=l.getState().getInstance(n);if(!o)return console.error("BlockManager::createBlockElement: Instance not found for containerId:",n),null;const i=B("div",a.classNames.block.container);i.setAttribute("data-container-id",n),i.setAttribute("data-id",crypto.randomUUID()),i.setAttribute("data-tool",t.type),i.setAttribute("data-indent","0");const r={classNames:o.config.classNames?.blocks?.[t.type],styles:o.config.styles?.blocks?.[t.type]};let s,c;if(r.margins&&(s=r.margins.top,c=r.margins.bottom),void 0===s&&r.styles){const e=r.styles;if(e.marginTop){const t=e.marginTop;"string"==typeof t&&t.endsWith("px")?s=parseInt(t.replace("px",""),10):"number"==typeof t&&(s=t)}}if(void 0===c&&r.styles){const e=r.styles;if(e.marginBottom){const t=e.marginBottom;"string"==typeof t&&t.endsWith("px")?c=parseInt(t.replace("px",""),10):"number"==typeof t&&(c=t)}}void 0===s&&void 0!==o.config.margins?.top&&(s=o.config.margins.top),void 0===c&&void 0!==o.config.margins?.bottom&&(c=o.config.margins.bottom),void 0!==s&&(i.style.marginTop=`${s}px`),void 0!==c&&(i.style.marginBottom=`${c}px`),ar.create({block:i,containerId:n});const p=B("div",a.classNames.block.content),d=e.renderTool(t.type,t.data,n);return d?(p.appendChild(d),e.addEventListener(n,i,"click",t=>e.focusBlock(t.currentTarget)),i.appendChild(p),i):(console.error("BlockManager::createBlockElement: Rendered element not found for type:",t.type),null)}static insertBlock(t,n,a){const o=e.createBlockElement(t,n);if(!o)return null;e.renderBlock(o,n,a);const i=e.getBlockData(o.getAttribute("data-id"));return l.getState().addBlock(n,i,e.getBlockIndex(n,o.getAttribute("data-id"))),o}static removeBlock(t,n){const a=e.getBlocks(t);if(n<0||n>=a.length||1===a.length)return null;if(n>0){const t=e.getBlock(a[n-1].getAttribute("data-id"));t&&e.focusBlock(t)}else if(0===n&&a.length>1){const t=e.getBlock(a[n+1].getAttribute("data-id"));t&&e.focusBlock(t)}a[n].remove(),l.getState().removeBlock(t,n)}static replaceBlock(t,n,a){e.removeBlock(t,n),e.insertBlock(a,t,n)}static moveBlock(t,n,a){const o=e.getBlocks(t);if(n<0||n>=o.length||a<0||a>=o.length)return;const i=l.getState().getData(t);if(!i)return;const r=l.getState().getContentElement(t);if(!r)return;const s=o[n];o.splice(n,1),o.splice(a,0,s),0===a?r.insertBefore(s,r.firstChild):a>=o.length-1?r.appendChild(s):r.insertBefore(s,o[a+1]);const c=o.map(t=>e.getBlockData(t.getAttribute("data-id"))),p={...i,blocks:c};l.getState().setData(t,p),e.focusBlock(s)}static getBlock(e){return document.querySelector(`[data-id="${e}"]`)}static getBlocks(e){const t=document.getElementById(e);if(!t)return[];const n=t.querySelectorAll(`.${a.classNames.block.container}`);return Array.from(n)}static getActiveBlocks(e){const t=document.getElementById(e);if(!t)return[];const n=t.querySelectorAll(`.${a.classNames.block.active}`);return Array.from(n)}static getBlockIndex(t,n){return e.getBlocks(t).findIndex(e=>e.getAttribute("data-id")===n)}static getTool(e){return Xi.find(t=>t.type===e)||null}static getBlockData(t){const n=e.getBlock(t);if(!n)return{data:{html:""},type:"paragraph"};const o=n.getAttribute("data-tool"),i=o?e.getTool(o):null;if(!i)return{data:{html:""},type:"paragraph"};const r=n.querySelector(`.${a.classNames.block.content}`);return r?{data:i.input.save(r),tunes:e.getBlockTunes(n),type:o}:{data:{html:""},tunes:e.getBlockTunes(n),type:o}}static extractData(t){return{blocks:e.getBlocks(t).map(t=>e.getBlockData(t.getAttribute("data-id"))),time:Date.now(),version:"1.0.0"}}static renderTool(e,t,n){const a=l.getState().getInstance(n);if(!a)return null;const o={classNames:a.config.classNames?.blocks?.[e],styles:a.config.styles?.blocks?.[e]};switch(e){case"alert":return pe.render(n,t,o);case"audio":return a.config.audioUploader?Se.render(a.config.audioUploader,n,t,o):(console.error("BlockManager::renderTool: Audio uploader not found for containerId:",n),null);case"code":return mt.render(n,t,o);case"collapsible":return Lt.render(n,t,o);case"columns":return ci.render(n,t,o);case"date":return di.render(n,t,o);case"delimiter":return Vt.render(n,t,o);case"collection":return ri.render(n,t,o);case"doc_card":return gi.render(n,t,o);case"embed":return yi.render(n,t,o);case"openapi":return Ii.render(n,t,o);case"sketch":return _i.render(n,t,o);case"latex":return Vi.render(n,t,o);case"mermaid":return Ui.render(n,t,o);case"file":return a.config.fileUploader?ki.render(a.config.fileUploader,n,t,o):(console.error("BlockManager::renderTool: File uploader not found for containerId:",n),null);case"header":return fn.render(n,t,o);case"image":return a.config.imageUploader?kn.render(a.config.imageUploader,n,t,o):(console.error("BlockManager::renderTool: Image uploader not found for containerId:",n),null);case"list":return En.render(n,t,o);case"checklist":return $e.render(n,t,o);case"paragraph":return aa.render(n,t,o);case"quote":return sa.render(n,t,o);case"table":return ya.render(n,t,o);case"toc":return Oi.render(n,t,o);case"video":return a.config.videoUploader?Qo.render(a.config.videoUploader,n,t,o):(console.error("BlockManager::renderTool: Video uploader not found for containerId:",n),null);default:return null}}static focusBlock(t){const n=t.querySelector('[contenteditable="true"]');n&&n.focus({preventScroll:!0}),e.setActiveBlock(t)}static setActiveBlock(t){const n=t.getAttribute("data-container-id");for(const o of e.getActiveBlocks(n))o.classList.remove(a.classNames.block.active);t.classList.add(a.classNames.block.active),ar.show(n,t)}static getActiveBlock(e){const t=document.getElementById(e);return t?t.querySelector(`.${a.classNames.block.active}`):null}static convertBlock(t,n,a){const o=e.getBlock(t);if(!o)return console.error("BlockManager::convertBlock: Block not found for blockId:",t);const i=e.getBlockData(t),r=e.getTool(n);if(!r)return console.error("BlockManager::convertBlock: New tool not found for newType:",n);const s=e.getBlockIndex(a,t);let c=i.data;if("list"===n){const e=i.data,t=e.html||e.text||"";c={items:t?[t]:[""],type:"unordered"}}else if("header"===n){const e=i.data;c={html:e.html||e.text||"",level:"h1"}}const p={data:c,id:t,type:r.type},d=e.createBlockElement(p,a);if(!d)return console.error("BlockManager::convertBlock: New block element not found for newType:",n);o.replaceWith(d);const u=e.getBlockData(d.getAttribute("data-id"));l.getState().updateBlock(a,s,u),e.focusBlock(d)}static getBlockTunes(e){const t={},n=e.querySelectorAll("[data-tune]");for(const a of n){const e=a.getAttribute("data-tune");e&&(t[e]=a.getAttribute("data-value")||!0)}return Object.keys(t).length>0?t:void 0}static updateStateFromRange(t){const n=le.getInstanceAndTargetFromRange(t);if(!n)return;const o=n.target.closest(`.${a.classNames.block.container}`);if(!o)return;const i=e.getBlockIndex(n.instance.config.containerId,o.getAttribute("data-id"));l.getState().updateBlock(n.instance.config.containerId,i,e.getBlockData(o.getAttribute("data-id")))}static renderBlock(t,n,a){const o=e.getBlocks(n),i=l.getState().getContentElement(n);if(!i)return console.error("BlockManager::renderBlock: Container not found for containerId:",n);if(void 0!==a&&a>=0)if(a<o.length){const e=o[a];i.insertBefore(t,e),o.splice(a,0,t)}else i.appendChild(t),o.push(t);else i.appendChild(t),o.push(t);e.focusBlock(t);const r=l.getState().getInstance(n);r&&X.initializeElements(t,{classNames:r.config.classNames?.blocks?.tooltip,styles:r.config.styles?.blocks?.tooltip})}static setBlocks(t,n){e.removeAllBlocks(n),t.forEach((t,a)=>e.insertBlock(t,n,a)),l.getState().updateData(n,{blocks:t})}static renderBlocks(t,n){for(const o of e.getBlocks(n))o.remove();const a=(t,a)=>{const o=e.createBlockElement(t,n);o&&e.renderBlock(o,n,a)};if(0===t.length)return a({data:{html:""},type:"paragraph"},0);t.forEach(a)}static removeAllBlocks(t){for(const n of e.getBlocks(t))n.remove();l.getState().setData(t,{blocks:[],time:Date.now(),version:"1.0.0"})}static resetBlocks(t){e.removeAllBlocks(t),e.insertBlock({data:{html:""},type:"paragraph"},t,0)}static getEditorId(e){const t=e.closest(`.${a.classNames.editor.container}`);return t?t.id:null}static handleKeydown(t){const n=t,o=t.currentTarget,i=o.closest(`.${a.classNames.block.container}`),r=e.getEditorId(i);if(!r)return;const s=e.getBlockIndex(r,i.getAttribute("data-id")),l=n.metaKey||n.ctrlKey;if(n.shiftKey)switch(n.key){case"ArrowUp":t.preventDefault(),t.stopPropagation(),s>0&&e.moveBlock(r,s,s-1);break;case"ArrowDown":t.preventDefault(),t.stopPropagation();const n=e.getBlocks(r);n&&s<n.length-1&&e.moveBlock(r,s,s+1)}else if(l)switch(n.key){case"Delete":case"Backspace":t.preventDefault(),t.stopPropagation(),e.removeBlock(r,s)}else if("Enter"===n.key)n.preventDefault(),n.stopPropagation(),e.insertBlock({data:{html:""},type:"paragraph"},r,s+1);else if("Backspace"===n.key){if(!I(o.innerHTML))return;n.preventDefault(),n.stopPropagation(),e.removeBlock(r,s)}else{e.ensureActiveBlock(r);const a=e.getBlocks(r);switch(n.key){case"ArrowUp":if(t.preventDefault(),t.stopPropagation(),s>0){const t=a[s-1];t&&e.focusBlock(t)}return;case"ArrowDown":if(t.preventDefault(),t.stopPropagation(),s<a.length-1){const t=a[s+1];t&&e.focusBlock(t)}return}}}static handleInput(t){e.saveBlockData(t.currentTarget)}static ensureActiveBlock(t){const n=e.getBlocks(t);let o=e.getActiveBlock(t);if(!o){const t=document.activeElement;if(!t)return;const i=t.closest(`.${a.classNames.block.container}`);if(i)o=i,e.setActiveBlock(o);else{if(0===n.length)return;o=n[0],e.setActiveBlock(o)}}}static saveBlockData(t){const n=t.closest(`.${a.classNames.block.container}`),o=e.getEditorId(n);if(!o)return;const i=n.getAttribute("data-id");l.getState().updateBlockData(o,e.getBlockIndex(o,i),e.getBlockData(i).data)}static updateBlockData(t,n,o){const i=e.getBlock(t);if(i){const t=i.querySelector(`.${a.classNames.block.content}`);t&&(t.innerHTML="");const r=e.renderTool(i.getAttribute("data-tool"),n,o);r&&t.appendChild(r)}l.getState().updateBlockData(o,e.getBlockIndex(o,t),n)}static destroy(t){if(!document.getElementById(t))return;const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[]),Xi.forEach(e=>e.input.destroy(t));for(const a of e.getBlocks(t))a.remove()}},ir=class e{static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static create(t){const n=l.getState().getInstance(t);if(!n)return console.error("ActionBar::create: Instance not found for containerId:",t);a.injectStyles("clepit-action-bar-styles","\n/* View Toggle */\n.clepit-action-bar {\n position: relative;\n z-index: 1000;\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: -14px; /* Position buttons so exactly half is inside and half outside */\n pointer-events: none;\n padding: 0 100px;\n}\n\n.clepit-action-bar-group {\n display: flex;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n overflow: hidden;\n padding: 4px;\n gap: 4px;\n}\n\n.clepit-action-bar-button {\n width: 24px;\n height: 24px;\n border: none;\n border-radius: 4px;\n background: transparent;\n color: var(--clepit-text-muted);\n font-size: 14px;\n font-weight: bold;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s ease;\n pointer-events: auto;\n}\n\n.clepit-action-bar-button:first-child {\n border-radius: 4px;\n}\n\n.clepit-action-bar-button:last-child {\n border-radius: 4px;\n}\n\n.clepit-action-bar-button:not(:first-child):not(:last-child) {\n border-radius: 4px;\n}\n\n.clepit-action-bar-button:hover {\n background: var(--clepit-toolbar-button-hover-bg, var(--clepit-selection-bg));\n color: var(--clepit-toolbar-button-hover-color, var(--clepit-primary));\n transform: scale(1.05);\n}\n\n.clepit-action-bar-button:active {\n transform: scale(0.95);\n}\n\n.clepit-action-bar-button.active {\n background-color: var(--clepit-primary-bg);\n color: var(--clepit-primary);\n font-weight: bold;\n}\n\n/* Action Buttons */\n.clepit-view-actions {\n display: flex;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n overflow: hidden;\n padding: 4px;\n gap: 4px;\n}\n\n.clepit-view-action-button {\n width: 24px;\n height: 24px;\n border: none;\n border-radius: 4px;\n background: transparent;\n color: var(--clepit-text-muted);\n font-size: 14px;\n font-weight: bold;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s ease;\n pointer-events: auto;\n}\n\n.clepit-view-action-button:first-child {\n border-radius: 4px;\n}\n\n.clepit-view-action-button:last-child {\n border-radius: 4px;\n}\n\n.clepit-view-action-button:not(:first-child):not(:last-child) {\n border-radius: 4px;\n}\n\n.clepit-view-action-button:hover {\n background: var(--clepit-toolbar-button-hover-bg, var(--clepit-selection-bg));\n color: var(--clepit-toolbar-button-hover-color, var(--clepit-primary));\n transform: scale(1.05);\n}\n\n.clepit-view-action-button:active {\n transform: scale(0.95);\n}\n\n/* Copy button feedback animation */\n.clepit-view-action-button--copy-feedback {\n transform: scale(0.95) !important;\n background-color: var(--clepit-success) !important;\n color: var(--clepit-bg) !important;\n}\n");const o=document.getElementById(t);if(!o)return;const i=n.config.styles?.controls?.group,r=n.config.classNames?.controls?.group,s=n.config.styles?.controls?.button,c=n.config.classNames?.controls?.button,p=n.config.styles?.tooltips,d=n.config.classNames?.tooltips,u=B("div",a.classNames.actionBar.container);e.createButtonGroup(o,u,{buttonClassNames:c,buttonStyles:s,currentView:n.currentView,groupClassNames:r,groupStyles:i,tooltipClassNames:d,tooltipStyles:p}),o.insertBefore(u,o.firstChild)}static createButtonGroup(t,n,o){const i=B("div",a.classNames.actionBar.group);a.applyStyling(i,{classNames:o.groupClassNames,styles:o.groupStyles});const r=B("button",a.classNames.actionBar.button,{"data-testid":"action-bar-edit-button","data-view":"edit",id:$(t.id,a.idSuffixes.actionBar.editButton),type:"button"});r.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/></svg>',a.applyStyling(r,{classNames:o.buttonClassNames,styles:o.buttonStyles});const s=B("button",a.classNames.actionBar.button,{"data-testid":"action-bar-preview-button","data-view":"preview",id:$(t.id,a.idSuffixes.actionBar.previewButton),type:"button"});s.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>',a.applyStyling(s,{classNames:o.buttonClassNames,styles:o.buttonStyles});const l=B("button",a.classNames.actionBar.button,{"data-testid":"action-bar-json-button","data-view":"json",id:$(t.id,a.idSuffixes.actionBar.jsonButton),type:"button"});l.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14,2 14,8 20,8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10,9 9,9 8,9"/></svg>',a.applyStyling(l,{classNames:o.buttonClassNames,styles:o.buttonStyles}),"edit"===o.currentView?r.classList.add("active"):"preview"===o.currentView?s.classList.add("active"):"json"===o.currentView&&l.classList.add("active"),e.addEventListener(t.id,r,"click",e.handleViewChange),e.addEventListener(t.id,s,"click",e.handleViewChange),e.addEventListener(t.id,l,"click",e.handleViewChange),i.appendChild(r),i.appendChild(s),i.appendChild(l),n.appendChild(i),J(r,"Edit Mode","above",o.tooltipClassNames,o.tooltipStyles),J(s,"Preview Mode","above",o.tooltipClassNames,o.tooltipStyles),J(l,"JSON Output","above",o.tooltipClassNames,o.tooltipStyles);const c=B("div",a.classNames.actionBar.action);a.applyStyling(c,{classNames:o.groupClassNames,styles:o.groupStyles});const p=B("button",a.classNames.actionBar.actionButton,{"data-testid":"view-copy-button",id:$(t.id,a.idSuffixes.actionBar.copyButton),type:"button"});p.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>',a.applyStyling(p,{classNames:o.buttonClassNames,styles:o.buttonStyles});const d=B("button",a.classNames.actionBar.actionButton,{"data-testid":"view-download-button",id:$(t.id,a.idSuffixes.actionBar.downloadButton),type:"button"});d.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7,10 12,15 17,10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>',a.applyStyling(d,{classNames:o.buttonClassNames,styles:o.buttonStyles});const u=B("button",a.classNames.actionBar.actionButton,{"data-testid":"view-clear-button",id:$(t.id,a.idSuffixes.actionBar.clearButton),type:"button"});u.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>',a.applyStyling(u,{classNames:o.buttonClassNames,styles:o.buttonStyles}),e.addEventListener(t.id,p,"click",e.handleCopyJson),e.addEventListener(t.id,d,"click",e.handleDownloadJson),e.addEventListener(t.id,u,"click",e.handleClearEditor),c.appendChild(p),c.appendChild(d),c.appendChild(u),n.appendChild(c),J(p,"Copy JSON to Clipboard","above",o.tooltipClassNames,o.tooltipStyles),J(d,"Download JSON File","above",o.tooltipClassNames,o.tooltipStyles),J(u,"Clear Editor","above",o.tooltipClassNames,o.tooltipStyles)}static getCurrentView(e){const t=document.getElementById(e);if(!t)return console.error("ActionBar::getCurrentView: Container not found for containerId:",e),null;const n=t.querySelector(`.${a.classNames.actionBar.group}`);if(!n)return console.error("ActionBar::getCurrentView: View toggle group not found for container:",t.id),null;const o=n.querySelector(".active");return o?o.getAttribute("data-view"):(console.error("ActionBar::getCurrentView: Active button not found for container:",t.id),null)}static updateButtonStates(e,t){const n=document.getElementById(e);if(!n)return;const o=n.querySelector(`.${a.classNames.actionBar.container}`);o&&o.querySelectorAll(`#${$(e,a.idSuffixes.actionBar.editButton)}, #${$(e,a.idSuffixes.actionBar.previewButton)}, #${$(e,a.idSuffixes.actionBar.jsonButton)}`).forEach(e=>{e.getAttribute("data-view")===t?e.classList.add("active"):e.classList.remove("active")})}static handleViewChange(t){const n=t.currentTarget,a=or.getEditorId(n);if(!a)return;const o=n.getAttribute("data-view");o&&(l.getState().setCurrentView(a,o),e.updateButtonStates(a,o))}static handleCopyJson(e){const t=e.currentTarget,n=or.getEditorId(t);if(!n)return;const o=l.getState().getInstance(n);o&&(navigator.clipboard.writeText(JSON.stringify(o.data,null,2)),t.classList.add(a.classNames.actionBar.copyFeedback),setTimeout(()=>t.classList.remove(a.classNames.actionBar.copyFeedback),200))}static handleClearEditor(e){const t=e.currentTarget,n=or.getEditorId(t);n&&or.resetBlocks(n)}static handleDownloadJson(e){const t=e.currentTarget,n=or.getEditorId(t);if(!n)return;const a=or.getBlocks(n).map(e=>or.getBlockData(e.getAttribute("data-id"))),o=new Blob([JSON.stringify(a,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${n}--content.json`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(i)}static destroy(e){const t=document.getElementById(e);if(!t)return;const n=t.querySelector(`.${a.classNames.actionBar.container}`);n&&n.remove()}},rr=new Set(["alert.html","audio.alt","audio.caption","checklist.items","header.html","image.alt","image.caption","list.items","paragraph.html","quote.html","table.caption","table.data","video.alt","video.caption"]),sr=(e,t)=>rr.has(`${e}.${t}`),lr=new Set(["checklist.items","list.items","table.data"]),cr=(e,t)=>lr.has(`${e}.${t}`),pr=(e,t,n,a)=>{if(!Array.isArray(t))return t;let o=!1;const i=e=>{const t=((e,t,n)=>{const a=ur(e,t,n);return null===a?e:a.value})(e,n,a);return t!==e&&(o=!0),t},r=t.map(t=>{if("table"===e)return Array.isArray(t)?t.map(i):t;if("checklist"===e){if("object"!=typeof t||null===t)return t;const e=t,n=i(e.text);return n===e.text?t:{...e,text:n}}return i(t)});return o?r:t},dr=(e,t,n,a)=>{let o=!1;const i={};for(const[r,s]of Object.entries(t)){if(cr(e,r)){const t=pr(e,s,n,a);i[r]=t,t!==s&&(o=!0);continue}if(!sr(e,r)){i[r]=s;continue}const t=ur(s,n,a);null!==t?(i[r]=t.value,t.value!==s&&(o=!0)):i[r]=s}return o?i:t},ur=(e,t,n)=>{if(void 0===e)return null;if(!(e=>"object"==typeof e&&null!==e&&!Array.isArray(e))(e))return{isFallback:t!==n,locale:n,value:e};const a=e[t];if(void 0!==a)return{isFallback:!1,locale:t,value:a};const o=e[n];if(void 0!==o)return{isFallback:!0,locale:n,value:o};const i=Object.keys(e).sort()[0];return void 0===i?null:{isFallback:!0,locale:i,value:e[i]}},mr=`\n/* Editor Container */\n.${a.classNames.editor.container} {\n position: relative;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n line-height: 1.6;\n color: var(--clepit-text);\n padding: 20px; /* Normal padding - no extra left padding needed */\n outline: none;\n box-sizing: border-box;\n width: 100%;\n}\n\n.${a.classNames.editor.container}:focus {\n outline: none;\n}\n\n.${a.classNames.editor.container}[data-readonly="true"] {\n background: var(--clepit-surface);\n color: var(--clepit-text-muted);\n cursor: not-allowed;\n}\n\n/* Editor Content Container */\n.${a.classNames.editor.content} {\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n overflow-y: auto;\n padding: 16px 24px; /* Increased horizontal padding for better preview content spacing */\n background: var(--clepit-bg);\n height: 100%;\n max-height: var(--clepit-max-height, 410px);\n min-height: var(--clepit-min-height, 200px);\n}\n\n/* JSON Output */\n.${a.classNames.editor.jsonOutput} {\n margin: 0;\n padding: 16px;\n font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;\n font-size: 13px;\n line-height: 1.4;\n color: var(--clepit-text); /* default readonly is black */\n overflow-x: auto;\n white-space: pre-wrap;\n word-wrap: break-word;\n outline: none;\n min-height: 100%;\n}\n\n.${a.classNames.editor.jsonOutput}:focus {\n outline: none;\n}\n\n/* Editable (allowed) -> green text */\n.${a.classNames.editor.jsonOutput}.clepit-json-editable {\n color: var(--clepit-success);\n}\n\n/* Invalid JSON -> red text */\n.${a.classNames.editor.jsonOutput}.clepit-json-error {\n color: var(--clepit-error);\n background-color: transparent;\n}\n\n.${a.classNames.editor.jsonEmpty} {\n padding: 16px;\n text-align: center;\n color: var(--clepit-text-muted);\n font-style: italic;\n}\n\n/* Responsive */\n@media (max-width: 768px) {\n /* Container and content each carried their own inset, so a phone spent 80px\n * of a ~400px editor on nested padding before a single character. */\n .${a.classNames.editor.container} {\n padding: 8px;\n }\n\n .${a.classNames.editor.content} {\n padding: 12px;\n }\n}\n`,hr=class{static render(e){const t=l.getState().getInstance(e);t&&(ne.create(e),a.injectStyles("clepit-block-manager-styles",'\n/* Blocks */\n.clepit-block {\n position: relative;\n margin: var(--block-margin-top, 8px) 0 var(--block-margin-bottom, 16px) 0;\n padding: 8px 0;\n padding-left: 54px;\n border-radius: 4px;\n transition: background-color 0.2s ease;\n display: flex;\n align-items: flex-start;\n gap: 6px;\n}\n\n.clepit-block:hover {\n background-color: var(--clepit-block-highlight-bg);\n}\n\n.clepit-block--active {\n background-color: var(--clepit-block-highlight-bg);\n}\n\n.clepit-block-content {\n outline: none;\n min-height: 1.2em;\n flex: 1;\n min-width: 0; /* Allow content to shrink */\n}\n\n/* Remove focus outline from editable elements */\n.clepit-block-content [contenteditable="true"] {\n outline: none;\n}\n\n/* Placeholder styles for all text elements */\n.clepit-block-content:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Menu animation classes */\n.clepit-block-type-selector--visible {\n display: block;\n transform: translateY(0);\n}\n\n.clepit-block-type-selector--hidden {\n display: none;\n}\n\n/* Block Operations Menu */\n.clepit-block-operations-menu {\n position: absolute;\n top: 100%;\n left: 0;\n z-index: 1001;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n padding: 8px;\n min-width: 200px;\n margin-top: 4px;\n display: none;\n transition: transform 0.2s ease;\n}\n\n.clepit-block-operations-menu--visible {\n display: block;\n transform: translateY(0);\n}\n\n.clepit-block-operations-menu--hidden {\n display: none;\n}\n\n/* Block Type Selector */\n.clepit-block-type-selector {\n position: absolute;\n top: 100%;\n left: 0;\n z-index: 1001;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n padding: 8px;\n min-width: 150px;\n margin-top: 4px;\n display: none;\n transition: transform 0.2s ease;\n}\n\n.clepit-block-type-selector--visible {\n display: block;\n transform: translateY(0);\n}\n\n.clepit-block-type-selector--hidden {\n display: none;\n}\n\n/* Default menu item styles - package doesn\'t care about theme */\n.clepit-menu-item {\n padding: 8px 12px;\n cursor: pointer;\n border-radius: 4px;\n transition: background-color 0.2s;\n display: flex;\n align-items: center;\n gap: 8px;\n}\n\n.clepit-menu-item .clepit-menu-icon {\n width: 16px;\n height: 16px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n font-size: 14px;\n}\n\n.clepit-menu-item:hover {\n background-color: var(--clepit-selection-bg);\n}\n\n.clepit-menu-item.active {\n background-color: var(--clepit-primary-bg);\n color: var(--clepit-primary);\n font-weight: bold;\n}\n\n.clepit-menu-item--danger {\n color: var(--clepit-error);\n}\n\n/* Block type menu items - match font size with operations menu */\n.clepit-block-type-item {\n font-size: 14px;\n}\n\n/* Default menu divider styles */\n.clepit-menu-divider {\n height: 1px;\n background: linear-gradient(to right, transparent, var(--clepit-border), transparent);\n margin: 8px 0;\n}\n\n/* Default menu arrow styles */\n.clepit-menu-arrow {\n margin-left: auto;\n font-size: 12px;\n color: var(--clepit-text-muted);\n}\n\n/* Input styles for block type selector */\n.clepit-block-type-selector input {\n width: 100%;\n padding: 8px 12px;\n border: 1px solid var(--clepit-input-border, var(--clepit-border));\n border-radius: 4px;\n font-size: 14px;\n margin-bottom: 8px;\n outline: none;\n transition: border-color 0.2s;\n background-color: var(--input-bg, var(--clepit-bg));\n color: var(--input-color, var(--clepit-text));\n}\n\n.clepit-block-type-selector input:focus {\n border-color: var(--clepit-primary);\n box-shadow: 0 0 0 2px var(--clepit-primary-bg);\n}\n\n.clepit-block-type-selector input::placeholder {\n color: var(--placeholder-color, var(--clepit-text-subtle));\n}\n\n.clepit-block-type-selector-items {\n max-height: 200px;\n overflow-y: auto;\n}\n\n.clepit-menu-icon {\n font-size: 14px;\n min-width: 20px;\n text-align: center;\n font-weight: bold;\n}\n\n.clepit-menu-shortcut {\n margin-left: auto;\n font-size: 9px;\n color: var(--clepit-text-muted);\n opacity: 0.7;\n}\n\n.clepit-menu-positioned {\n position: absolute;\n z-index: 1001;\n top: var(--menu-top, 0);\n left: var(--menu-left, 0);\n}\n\n/* The block menus are popovers in the top layer. Anchor positioning puts them\n * under the block toolbar without JavaScript measuring anything.\n *\n * Guarded: anchor positioning is Baseline 2026 (Chrome 125+, Firefox 132+,\n * Safari 18.2+), roughly 91% of traffic. Browsers without it get the popover\'s\n * default centred placement rather than a second JS positioning path — the menu\n * stays usable, just not adjacent to its button. */\n.clepit-block-type-selector:popover-open,\n.clepit-block-operations-menu:popover-open {\n margin: 0;\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n background: var(--clepit-bg);\n padding: 8px;\n overflow: visible;\n}\n\n@supports (anchor-name: --a) {\n .clepit-block-type-selector:popover-open,\n .clepit-block-operations-menu:popover-open {\n position-anchor: --clepit-block-toolbar;\n position-area: bottom span-inline-end;\n margin-block-start: 5px;\n }\n}\n\n@supports (position-try-fallbacks: flip-block) {\n .clepit-block-type-selector:popover-open,\n .clepit-block-operations-menu:popover-open {\n position-try-fallbacks: flip-block;\n }\n}\n\n/* Convert Submenu */\n@supports (anchor-name: --a) {\n .clepit-convert-submenu:popover-open {\n position: fixed;\n position-area: inline-end span-block-end;\n margin: 0 0 0 4px;\n inset: auto;\n }\n\n .clepit-convert-submenu:popover-open {\n position-try-fallbacks: flip-inline;\n }\n}\n\n.clepit-convert-submenu {\n position: absolute;\n top: var(--submenu-top, 0);\n left: var(--submenu-left, 100%);\n z-index: var(--submenu-z-index, 1002);\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n padding: 8px;\n min-width: 140px;\n margin-left: 4px;\n display: none;\n transition: transform 0.2s ease;\n}\n\n.clepit-convert-submenu--visible {\n display: block;\n opacity: 1;\n transform: translateX(0);\n}\n\n.clepit-convert-submenu--hidden {\n display: none;\n opacity: 0;\n transform: translateX(-10px);\n}\n\n/* Input styles for convert submenu */\n.clepit-convert-submenu input {\n width: 100%;\n padding: 6px 8px;\n border: 1px solid var(--clepit-input-border, var(--clepit-border));\n border-radius: 4px;\n font-size: 12px;\n outline: none;\n background-color: var(--input-bg, var(--clepit-bg));\n color: var(--input-color, var(--clepit-text));\n}\n\n.clepit-convert-submenu input:focus {\n border-color: var(--clepit-input-focus-border, var(--clepit-primary));\n box-shadow: 0 0 0 2px var(--clepit-input-focus-shadow, var(--clepit-primary-bg));\n}\n\n.clepit-convert-submenu input::placeholder {\n color: var(--clepit-input-placeholder, var(--clepit-text-subtle));\n}\n\n.clepit-convert-submenu-items {\n max-height: 200px;\n overflow-y: auto;\n}\n\n.clepit-block-operation-item {\n padding: 8px 12px;\n cursor: pointer;\n border-radius: 4px;\n transition: background-color 0.2s;\n font-size: 14px;\n}\n\n.clepit-block-operation-item:hover {\n background-color: var(--clepit-hover-bg, var(--clepit-selection-bg));\n}\n\n/* Input styles for operations menu */\n.clepit-block-operations-menu input {\n width: 100%;\n padding: 8px 12px;\n border: 1px solid var(--clepit-input-border, var(--clepit-border));\n border-radius: 4px;\n font-size: 14px;\n margin-bottom: 8px;\n outline: none;\n transition: border-color 0.2s;\n background-color: var(--input-bg, var(--clepit-bg));\n color: var(--input-color, var(--clepit-text));\n}\n\n.clepit-block-operations-menu input:focus {\n border-color: var(--clepit-primary);\n box-shadow: 0 0 0 2px var(--clepit-primary-bg);\n}\n\n.clepit-block-operations-menu input::placeholder {\n color: var(--placeholder-color, var(--clepit-text-subtle));\n}\n\n.clepit-block-operations-menu-items {\n max-height: 200px;\n overflow-y: auto;\n}\n\n.clepit-block-operation-item[data-operation="delete"] {\n color: var(--clepit-error);\n}\n\n/* Convert submenu items */\n.clepit-convert-option-item {\n padding: 8px 12px;\n cursor: pointer;\n border-radius: 4px;\n transition: background-color 0.2s;\n font-size: 14px;\n}\n\n.clepit-convert-option-item:hover {\n background-color: var(--clepit-hover-bg, var(--clepit-selection-bg));\n}\n\n/* Indentation */\n.clepit-block[data-indent="1"] .clepit-block-content {\n margin-left: 20px;\n}\n\n.clepit-block[data-indent="2"] .clepit-block-content {\n margin-left: 40px;\n}\n\n.clepit-block[data-indent="3"] .clepit-block-content {\n margin-left: 60px;\n}\n\n/* Responsive */\n@media (max-width: 768px) {\n /* The 54px gutter exists to hold the block toolbar, which is only ever\n * displayed on the active block. On a phone that reserved a seventh of the\n * editor\'s width on every idle block at once, pushing the text into a narrow\n * column with empty space either side. Give the width back and let the\n * gutter open only under the block whose toolbar is actually showing. */\n /* No transition on padding-left. The block element is re-created as you\n * interact with it, so an animated gutter restarts from 0 every time and\n * never reaches its end value — the toolbar would sit on top of the text. */\n .clepit-block {\n padding-left: 0;\n }\n\n .clepit-block--active,\n .clepit-block:focus-within,\n .clepit-block:has(.clepit-block-toolbar--visible) {\n padding-left: 54px;\n }\n}\n'),or.renderBlocks(t.data.blocks,e))}},gr=class e{static render(t){const n=l.getState().getInstance(t);if(!n)return;const o=document.getElementById(n.contentId);if(o)if(o.innerHTML="",n.data&&n.data.blocks&&n.data.blocks.length>0){const t=a.createStyledElement("pre",a.classNames.editor.jsonOutput);t.textContent=JSON.stringify(n.data,null,2),t.setAttribute("data-testid","json-editable-textarea"),n.config.allowJsonViewEditing&&(t.setAttribute("contenteditable","true"),t.classList.add(a.classNames.editor.jsonEditable),setTimeout(()=>t.focus(),0),e.addEventListeners(t)),o.appendChild(t)}else{const e=a.createStyledElement("div",a.classNames.editor.jsonEmpty);e.textContent="No content to display",o.appendChild(e)}}static addEventListeners(t){t.addEventListener("input",e.handleJsonInput),t.addEventListener("blur",e.validateAndUpdateJson),t.addEventListener("keydown",e.validateAndUpdateJson)}static removeEventListeners(t){t.removeEventListener("input",e.handleJsonInput),t.removeEventListener("blur",e.validateAndUpdateJson),t.removeEventListener("keydown",e.validateAndUpdateJson)}static handleJsonInput(e){const t=e.target,n=t.textContent||"",o=or.getEditorId(t);if(o)try{const e=JSON.parse(n);if("object"==typeof e&&null!==e){e.blocks&&Array.isArray(e.blocks)||(e.blocks=[]);const t=l.getState().getInstance(o);if(t){const n=document.querySelector(`#${t.contentId} .${a.classNames.editor.jsonOutput}`);n&&(n.classList.remove(a.classNames.editor.jsonError),t.config.allowJsonViewEditing&&n.classList.add("clepit-json-editable"));const i=t.currentView;l.getState().setData(o,e),"json"===i&&l.getState().setCurrentView(o,"json"),console.log("Store updated successfully")}}}catch{const e=l.getState().getInstance(o);if(e){const t=document.querySelector(`#${e.contentId} .${a.classNames.editor.jsonOutput}`);t&&(t.classList.add("clepit-json-error"),t.classList.remove("clepit-json-editable"))}}}static validateAndUpdateJson(e){const t=e.target,n=t.textContent||"",o=or.getEditorId(t);if(!o)return;const i=l.getState().getInstance(o);if(i)try{const e=JSON.parse(n);if("object"!=typeof e||null===e)throw new Error("Invalid JSON structure");{e.blocks&&Array.isArray(e.blocks)||(e.blocks=[]);try{ne.hide(o),ar.hide(o)}catch{}const t=i.currentView;l.getState().setData(o,e),"json"===t&&l.getState().setCurrentView(o,"json");const n=document.querySelector(`#${i.contentId} .${a.classNames.editor.jsonOutput}`);n&&(n.classList.remove("clepit-json-error"),i.config.allowJsonViewEditing?n.classList.add("clepit-json-editable"):n.classList.remove("clepit-json-editable")),i.config.onChange&&i.config.onChange(e)}}catch{const e=document.querySelector(`#${i.contentId} .${a.classNames.editor.jsonOutput}`);e&&(e.classList.add("clepit-json-error"),e.classList.remove("clepit-json-editable"))}}static destroy(t){const n=l.getState().getInstance(t);if(!n)return;const o=document.querySelector(`#${n.contentId} .${a.classNames.editor.jsonOutput}`);o&&e.removeEventListeners(o)}},br="clepit-theme-styles",fr=".clepit-editor, .clepit-renderer-content, body[data-clepit-theme]",yr=`@layer clepit.reset, clepit.tokens, clepit.blocks, clepit.overrides;\n\n${nr=e,Object.keys(t).map(e=>`@property ${t[e]} {\n syntax: '<color>';\n inherits: true;\n initial-value: ${nr[e]};\n}`).join("\n\n")}\n\n@layer clepit.tokens {\n${n(e,{bg:"#161b22",blockHighlightBg:"rgba(0, 0, 0, 0.25)",border:"rgba(240, 246, 252, 0.1)",borderSubtle:"rgba(240, 246, 252, 0.06)",codeBg:"#1e242c",codeBorder:"rgba(240, 246, 252, 0.10)",codeComment:"rgba(240, 246, 252, 0.42)",codeFunction:"#d2a8ff",codeGutter:"rgba(240, 246, 252, 0.42)",codeKeyword:"#ff7b72",codeNumber:"#79c0ff",codePunctuation:"rgba(240, 246, 252, 0.62)",codeSelectionBg:"rgba(124, 124, 255, 0.18)",codeString:"#7ee787",codeText:"rgba(240, 246, 252, 0.92)",codeType:"#ffa657",error:"#f87171",errorBg:"rgba(248, 113, 113, 0.12)",info:"#60a5fa",infoBg:"rgba(96, 165, 250, 0.12)",marker:"rgba(255, 224, 71, 0.28)",primary:"#7c7cff",primaryBg:"rgba(124, 124, 255, 0.14)",primaryHover:"#9494ff",selectionBg:"rgba(124, 124, 255, 0.18)",success:"#4ade80",successBg:"rgba(74, 222, 128, 0.12)",surface:"#1c222a",surface2:"#222a33",text:"rgba(240, 246, 252, 0.92)",textMuted:"rgba(240, 246, 252, 0.62)",textSubtle:"rgba(240, 246, 252, 0.42)",warning:"#fbbf24",warningBg:"rgba(251, 191, 36, 0.12)"},fr)}\n\n${fr} {\n color-scheme: light;\n}\n\n.clepit-editor[data-clepit-theme='auto'], .clepit-renderer-content[data-clepit-theme='auto'], body[data-clepit-theme='auto'] {\n color-scheme: light dark;\n}\n\n.clepit-editor[data-clepit-theme='dark'], .clepit-renderer-content[data-clepit-theme='dark'], body[data-clepit-theme='dark'] {\n color-scheme: dark;\n}\n\n.clepit-editor[data-clepit-theme='light'], .clepit-renderer-content[data-clepit-theme='light'], body[data-clepit-theme='light'] {\n color-scheme: light;\n}\n}\n`,vr=class e{static render(t){const n=document.getElementById(t.containerId);if(!n)throw new Error(`Container element with ID '${t.containerId}' not found`);return a.injectStyles(br,yr),a.injectStyles(O,H),n.classList.add(a.classNames.renderer.content),a.registerEditor(t.containerId,t.theme??"auto",t.themeOverrides),n.innerHTML="",t.data?.blocks&&Array.isArray(t.data.blocks)?(t.data.blocks.forEach((a,o)=>{const i=e.renderBlock(e.localize(a,t),o,t);i&&n.appendChild(i)}),n):n}static localize(e,t){if(!t.locale)return e;const n=dr(e.type,e.data,t.locale,t.defaultLocale??t.locale);return n===e.data?e:{...e,data:n}}static renderBlock(e,t,n){const o=B("div",a.classNames.block.output);o.setAttribute("data-block-type",e.type),o.setAttribute("data-block-index",t.toString()),e.tunes&&Object.entries(e.tunes).forEach(([e,t])=>{o.setAttribute(`data-tune-${e}`,String(t))});const i=n.styles?.[e.type],r=n.classNames?.[e.type];let s,l,c,p=n.configs?.[e.type];if("paragraph"===e.type&&n.editorClassNames?.tooltips&&(p={...p,tooltipClassNames:n.editorClassNames.tooltips}),p?.margins&&(s=p.margins.top,l=p.margins.bottom),void 0===s&&void 0!==n.margins?.top&&(s=n.margins.top),void 0===l&&void 0!==n.margins?.bottom&&(l=n.margins.bottom),void 0!==s){const e=parseFloat(o.style.marginTop||"0")||0;o.style.marginTop=`${e+s}px`}if(void 0!==l){const e=parseFloat(o.style.marginBottom||"0")||0;o.style.marginBottom=`${e+l}px`}switch(e.type){case"alert":c=ke.render(e.data,p,i,r);break;case"audio":c=Ne.render(e.data,p,i,r);break;case"code":c=wt.render(e.data,p,i,r);break;case"collapsible":c=ai.render(e.data,p,i,r);break;case"columns":c=_t.render(e.data,p,i,r);break;case"date":c=Rt.render(e.data,p,i,r);break;case"delimiter":c=Ut.render(e.data,p,i,r);break;case"collection":c=Mt.render(e.data,p,i,r);break;case"updates":c=Xo.render(e.data,p,i,r);break;case"glance":c=gn.render(e.data,p,i,r);break;case"embed":c=sn.render(e.data,p,i,r);break;case"sketch":c=ga.render(e.data,p,i,r);break;case"latex":c=Uo.render(e.data,p,i,r);break;case"mermaid":c=Wo.render(e.data,p,i,r);break;case"openapi":c=ta.render(e.data,p,i,r);break;case"doc_card":c=Jt.render(e.data,p,i,r);break;case"file":c=un.render(e.data,p,i,r);break;case"header":c=yn.render(e.data,p,i,r);break;case"image":c=wn.render(e.data,p,i,r);break;case"list":c=Sn.render(e.data,p,i,r);break;case"checklist":c=Ie.render(e.data,p,i,r);break;case"paragraph":c=oa.render(e.data,p,i,r);break;case"quote":c=la.render(e.data,p,i,r);break;case"table":c=ka.render(e.data,p,i,r);break;case"toc":c=Na.render(e.data,{...p,documentBlocks:n.data?.blocks??[]},i,r);break;case"video":c=ei.render(e.data,p,i,r);break;default:c=null}return c?(o.appendChild(c),X.initializeElements(o,{classNames:n.classNames?.tooltip,styles:n.styles?.tooltip}),o):null}},xr=class{static render(e){const t=l.getState().getInstance(e);t&&vr.render({classNames:t.config.classNames?.blocks,containerId:t.contentId,data:t.data,editorClassNames:t.config.classNames,margins:t.config.margins,styles:t.config.styles?.blocks})}},kr=new Set(["strong","b","em","i","u","s","del","mark","code","a","span"]),wr=new Set(["href","target","data-tooltip","data-status","data-status-variant","data-user-id","data-page-id","class"]),Cr=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),Er=/([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g,Sr=e=>{const t=new Map;Er.lastIndex=0;let n=Er.exec(e);for(;null!==n;)t.set(n[1].toLowerCase(),n[2]??n[3]??n[4]??""),n=Er.exec(e);return t},Nr=e=>{const t=e.trim().toLowerCase().replace(/[\x00-\x20]/g,"");return!t.startsWith("javascript:")&&!t.startsWith("data:")&&!t.startsWith("vbscript:")},Ar=e=>{if(!e)return"";const t=[],n=[];for(const a of(e=>{const t=[],n=/<\/?([a-zA-Z][a-zA-Z0-9-]*)((?:[^>"']|"[^"]*"|'[^']*')*)>/g;let a=0,o=n.exec(e);for(;null!==o;){o.index>a&&t.push({type:"text",value:e.slice(a,o.index)});const i=o[1].toLowerCase();o[0].startsWith("</")?t.push({tag:i,type:"close"}):t.push({attributes:Sr(o[2]??""),selfClosing:(o[2]??"").trimEnd().endsWith("/"),tag:i,type:"open"}),a=o.index+o[0].length,o=n.exec(e)}return a<e.length&&t.push({type:"text",value:e.slice(a)}),t})(e)){if("text"===a.type){t.push(a.value);continue}if("close"===a.type){if(!kr.has(a.tag))continue;const e=n.lastIndexOf(a.tag);if(-1===e)continue;t.push(`</${a.tag}>`),n.splice(e,1);continue}if(!kr.has(a.tag))continue;const e=[];for(const[t,n]of a.attributes)wr.has(t)&&("href"!==t||Nr(n))&&e.push(`${t}="${ge(n)}"`);"a"===a.tag&&e.push('target="_blank"','rel="noopener noreferrer"'),t.push(`<${[a.tag,...e].join(" ")}>`),a.selfClosing||Cr.has(a.tag)||n.push(a.tag)}for(const a of[...n].reverse())t.push(`</${a}>`);return t.join("")},Lr=()=>[yr,ce,Ee,Be,De,bt(),Nt,It,Dt,Ot,Ft,Gt,Yt,pn,mn,bn,xn,Cn,Nn,na,ra,da,fa,Ea,Ba,Jo,Yo].join("\n"),Br=(e,t)=>{const n=fe(Ar),a={...t,documentBlocks:t?.documentBlocks??e};return e.map(e=>ti(e,n,a)).filter(e=>null!==e).map(e=>ye(e)).join("\n")};exports.Editor=class e{static create(t){return e.destroy(t.containerId),e.initialize(t),ir.create(t.containerId),e.render(t.containerId),le.addListeners(t.containerId),l.getState().setIsReady(t.containerId,!0),l.subscribe(e=>e.instances,(n,a)=>{const o=n[t.containerId];if(!o)return;const i=a[t.containerId];i&&o.currentView!==i.currentView&&e.render(t.containerId)}),{blocks:{convert:(e,n)=>or.convertBlock(e,n,t.containerId),count:()=>or.getBlocks(t.containerId).length,get:e=>or.getBlock(e)?or.getBlockData(e):null,getAll:()=>or.getBlocks(t.containerId).map(e=>or.getBlockData(e.getAttribute("data-id"))),insert:(e,n,a)=>or.insertBlock({data:n,id:Math.random().toString(36).substring(2,11),type:e},t.containerId,a),move:(e,n)=>or.moveBlock(t.containerId,e,n),remove:e=>or.removeBlock(t.containerId,e),update:(e,n)=>or.updateBlockData(e,n,t.containerId)},blur:()=>{const e=document.activeElement;e&&document.getElementById(t.containerId)?.contains(e)&&e.blur()},data:{clear:()=>{l.getState().clearData(t.containerId),or.destroy(t.containerId)},clearContent:()=>or.destroy(t.containerId),clearStorage:()=>l.getState().clearData(t.containerId),extract:()=>or.extractData(t.containerId),set:e=>or.setBlocks(e.blocks,t.containerId)},destroy:()=>e.destroy(t.containerId),focus:()=>{const e=or.getBlocks(t.containerId)[0];e&&or.focusBlock(e)},selection:{clear:()=>window.getSelection()?.removeAllRanges(),get:()=>window.getSelection(),set:e=>{const t=window.getSelection();t&&(t.removeAllRanges(),t.addRange(e.getRangeAt(0)))}},ui:{hideBlockMenu:()=>ar.hide(t.containerId),hideToolbar:()=>ne.hide(t.containerId),showBlockMenu:e=>ar.show(t.containerId,e),showToolbar:(e,n)=>ne.show(t.containerId,e,n)},view:{getCurrentView:e=>l.getState().getCurrentView(e),switchView:(e,t)=>l.getState().setCurrentView(e,t)}}}static initialize(t){console.info("Editor::initialize: Creating editor instance for containerId:",t.containerId);const n=document.getElementById(t.containerId);if(!n)throw`Unable to find container with ID ${t.containerId}`;a.injectStyles(br,yr),a.injectStyles("clepit-editor-container-styles",mr),a.injectStyles(S,N),a.injectStyles(W,K),a.injectStyles(_,j);const o={allowJsonViewEditing:!1,initialView:"edit",maxHeight:0,minHeight:300,placeholder:"Start writing...",...t};n.className=a.classNames.editor.container,n.setAttribute("contenteditable","false"),a.registerEditor(t.containerId,o.theme??"auto",o.themeOverrides),o.minHeight&&n.style.setProperty("--clepit-min-height",`${o.minHeight}px`),o.maxHeight&&n.style.setProperty("--clepit-max-height",`${o.maxHeight}px`),a.applyStyles(n,o.styles?.container),a.applyClassNames(n,o.classNames?.container),o.margins&&(void 0!==o.margins.top&&n.style.setProperty("--block-margin-top",`${o.margins.top}px`),void 0!==o.margins.bottom&&n.style.setProperty("--block-margin-bottom",`${o.margins.bottom}px`));const i=`${o.containerId}-${a.idSuffixes.editorContent}`,r=B("div",a.classNames.editor.content);r.id=i,r.setAttribute("data-testid","editor-content-container"),r.setAttribute("data-container-id",t.containerId),a.applyStyles(r,o.styles?.editorContent),a.applyClassNames(r,o.classNames?.editorContent),n.appendChild(r),l.getState().addInstance(t.containerId,{config:o,contentId:i,currentView:o.initialView||"edit",data:e.localizeData(o.initialData,o),isReady:!1})}static localizeData(e,t){const n=e||{blocks:[],time:Date.now(),version:"1.0.0"},a=t.locale;if(!a)return n;const o=t.defaultLocale??a;return{...n,blocks:n.blocks.map(e=>{const n=e.data;for(const r of(e=>Array.from(rr).filter(t=>t.startsWith(`${e}.`)).map(t=>t.slice(e.length+1)).sort())(e.type)){const i=ur(n[r],a,o);i?.isFallback&&t.onLocaleFallback?.({blockId:e.id??"",field:r,requested:a,showing:i.locale})}const i=dr(e.type,n,a,o);return i===n?e:{...e,data:i}})}}static render(e){const t=l.getState().getInstance(e);if(!t)return;const n=document.getElementById(t.contentId);n&&(gr.destroy(e),n.innerHTML=""),"edit"===t.currentView?hr.render(e):"preview"===t.currentView?xr.render(e):"json"===t.currentView&&gr.render(e),t.config.onReady&&t.config.onReady()}static destroy(e){console.info("Editor::destroy: Destroying editor instance for containerId:",e);const t=document.getElementById(e);if(!t)return console.error("Editor::destroy: Container not found for containerId:",e);le.removeListeners(e),ir.destroy(e),ar.destroy(e),ne.destroy(e),or.destroy(e),a.unregisterEditor(e),t.innerHTML=""}},exports.Renderer=vr,exports.StyleManager=a,exports.domBacking=ue,exports.drawBlock=ti,exports.pageStylesheet=Lr,exports.parseOpenApi=Kn,exports.renderBlocks=Br,exports.renderPage=(e,t)=>{const n=he(e.title),a=['<meta charset="utf-8">','<meta name="viewport" content="width=device-width, initial-scale=1">',`<title>${n}</title>`,e.description?`<meta name="description" content="${ge(e.description)}">`:"",e.canonicalUrl?`<link rel="canonical" href="${ge(e.canonicalUrl)}">`:"",`<meta property="og:title" content="${ge(e.title)}">`,e.description?`<meta property="og:description" content="${ge(e.description)}">`:"",`<style>${Lr()}</style>`].filter(Boolean);return["<!doctype html>",`<html lang="${ge(e.locale??"en")}">`,`<head>${a.join("")}</head>`,"<body>",'<main class="clepit-public-page">',`<h1 class="clepit-public-page__title">${n}</h1>`,Br(e.blocks,t),"</main>","</body>","</html>"].join("\n")},exports.renderToString=ye,exports.sanitizeHtmlWithoutDom=Ar,exports.stringBacking=fe,exports.toDomElement=ve;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={bg:"#ffffff",blockHighlightBg:"rgba(0, 0, 0, 0.05)",border:"rgba(17, 24, 39, 0.12)",borderSubtle:"rgba(17, 24, 39, 0.06)",codeBg:"#f2f4f7",codeBorder:"rgba(17, 24, 39, 0.10)",codeComment:"#868f9c",codeFunction:"#6f42c1",codeGutter:"#868f9c",codeKeyword:"#cf222e",codeNumber:"#0550ae",codePunctuation:"#525866",codeSelectionBg:"rgba(91, 91, 255, 0.14)",codeString:"#0a7c3e",codeText:"#0a0a0a",codeType:"#953800",error:"#dc2626",errorBg:"rgba(220, 38, 38, 0.08)",info:"#2563eb",infoBg:"rgba(37, 99, 235, 0.08)",marker:"#ffe047",primary:"#5b5bff",primaryBg:"rgba(91, 91, 255, 0.08)",primaryHover:"#4747e6",selectionBg:"rgba(91, 91, 255, 0.14)",success:"#16a34a",successBg:"rgba(22, 163, 74, 0.08)",surface:"#f8f9fa",surface2:"#f1f3f5",text:"#0a0a0a",textMuted:"#525866",textSubtle:"#868f9c",warning:"#d97706",warningBg:"rgba(217, 119, 6, 0.08)"},t={bg:"--clepit-bg",blockHighlightBg:"--clepit-block-highlight-bg",border:"--clepit-border",borderSubtle:"--clepit-border-subtle",codeBg:"--clepit-code-bg",codeBorder:"--clepit-code-border",codeComment:"--clepit-code-comment",codeFunction:"--clepit-code-function",codeGutter:"--clepit-code-gutter",codeKeyword:"--clepit-code-keyword",codeNumber:"--clepit-code-number",codePunctuation:"--clepit-code-punctuation",codeSelectionBg:"--clepit-code-selection-bg",codeString:"--clepit-code-string",codeText:"--clepit-code-text",codeType:"--clepit-code-type",error:"--clepit-error",errorBg:"--clepit-error-bg",info:"--clepit-info",infoBg:"--clepit-info-bg",marker:"--clepit-marker",primary:"--clepit-primary",primaryBg:"--clepit-primary-bg",primaryHover:"--clepit-primary-hover",selectionBg:"--clepit-selection-bg",success:"--clepit-success",successBg:"--clepit-success-bg",surface:"--clepit-surface",surface2:"--clepit-surface-2",text:"--clepit-text",textMuted:"--clepit-text-muted",textSubtle:"--clepit-text-subtle",warning:"--clepit-warning",warningBg:"--clepit-warning-bg"},n=(e,n,a)=>{const o=[];for(const i of Object.keys(t)){const a=e[i],r=n[i];if(void 0===a&&void 0===r)continue;const s=t[i];void 0!==a&&void 0!==r?o.push(` ${s}: light-dark(${a}, ${r});`):o.push(` ${s}: ${a??r};`)}return 0===o.length?"":`${a} {\n${o.join("\n")}\n}`},a=class e{static{this.idSuffixes={actionBar:{clearButton:"action-bar-clear-button",copyButton:"action-bar-copy-button",downloadButton:"action-bar-download-button",editButton:"edit-button",jsonButton:"json-button",previewButton:"preview-button"},editorContent:"content"}}static{this.classNames={actionBar:{action:"clepit-view-actions",actionButton:"clepit-view-action-button",button:"clepit-action-bar-button",container:"clepit-action-bar",copyFeedback:"clepit-view-action-button--copy-feedback",group:"clepit-action-bar-group"},block:{active:"clepit-block--active",alert:"clepit-alert",audio:{captionEditable:"clepit-audio-caption-editable",container:"clepit-audio-container",dropArea:"clepit-audio-drop-area",wrapper:"clepit-audio-wrapper"},audioDeleteBtn:"clepit-audio-delete-btn",checklist:{checkbox:"clepit-checklist-checkbox",container:"clepit-checklist",item:"clepit-checklist-item",text:"clepit-checklist-text"},code:{container:"clepit-code-container",editor:"clepit-code-editor",header:"clepit-code-header",headerWrapper:"clepit-code-header-wrapper"},container:"clepit-block",content:"clepit-block-content",header:"clepit-header",image:{captionEditable:"clepit-image-caption-editable",container:"clepit-image-container",dropArea:"clepit-image-drop-area",wrapper:"clepit-image-wrapper"},imageDeleteBtn:"clepit-image-delete-btn",indent1:"clepit-block-indent-1",indent2:"clepit-block-indent-2",indent3:"clepit-block-indent-3",link:"clepit-link",list:{container:"clepit-list",item:"clepit-list-item"},output:"clepit-output-block",paragraph:"clepit-paragraph",quote:{author:"clepit-quote-author",container:"clepit-quote-container",divider:"clepit-quote-divider",text:"clepit-quote-text"},table:{caption:"clepit-table-caption",cell:"clepit-table-cell",downloadSwitch:"clepit-table-download-switch",headerCell:"clepit-table-header-cell",headerRow:"clepit-table-header-row",row:"clepit-table-row"},tooltip:"clepit-tooltip",video:{captionEditable:"clepit-video-caption-editable",container:"clepit-video-container",dropArea:"clepit-video-drop-area",iframe:"clepit-video-iframe",video:"clepit-video",wrapper:"clepit-video-wrapper"},videoDeleteBtn:"clepit-video-delete-btn"},editor:{container:"clepit-editor",content:"clepit-editor-content",jsonEditable:"clepit-json-editable",jsonEmpty:"clepit-json-empty",jsonError:"clepit-json-error",jsonOutput:"clepit-json-output"},renderer:{content:"clepit-renderer-content"},switch:{container:"clepit-custom-switch"}}}static applyStyles(e,t){t&&"object"==typeof t&&Object.entries(t).forEach(([t,n])=>{if(void 0!==n)if(t.startsWith("--"))e.style.setProperty(t,String(n));else{const a=t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);e.style.setProperty(a,String(n))}})}static applyClassNames(e,t){t&&("string"==typeof t?e.classList.add(t):Object.entries(t).forEach(([t,n])=>{n&&"string"==typeof n&&e.classList.add(n)}))}static applyStyling(t,n){const{styles:a,classNames:o}=n;if(a&&"object"==typeof a){const n=[],o={};Object.entries(a).forEach(([e,t])=>{void 0===t?n.push(e):o[e]=t}),Object.keys(o).length>0&&e.applyStyles(t,o),n.forEach(e=>t.style.removeProperty(e))}o&&e.applyClassNames(t,o)}static createStyledElement(t,n,a){const o=document.createElement(t);return o.className=n,a&&e.applyStyling(o,a),o}static injectStyles(e,t){if(document.getElementById(e))return!1;const n=document.createElement("style");return n.id=e,n.textContent=t,document.head.appendChild(n),!0}static{this.themeRegistry=new Map}static{this.themeSubscribers=new Set}static registerEditor(t,a,o){const i=document.getElementById(t);i&&(i.setAttribute("data-clepit-theme",a),i.setAttribute("data-clepit-instance",t)),e.themeRegistry.set(t,a),e.syncBodyThemeAttribute();const r=document.getElementById(`clepit-overrides-${t}`);if(r&&r.remove(),o){const a=n(o.light??{},o.dark??{},`[data-clepit-instance='${t}']`);a&&e.injectStyles(`clepit-overrides-${t}`,a)}e.ensureThemeListener()}static unregisterEditor(t){const n=document.getElementById(`clepit-overrides-${t}`);n&&n.remove();const a=document.getElementById(t);a&&(a.removeAttribute("data-clepit-theme"),a.removeAttribute("data-clepit-instance")),e.themeRegistry.delete(t),e.syncBodyThemeAttribute(),e.maybeDetachThemeListener()}static syncBodyThemeAttribute(){if("undefined"==typeof document||!document.body)return;const t=e.themeRegistry.values().next().value;t?document.body.setAttribute("data-clepit-theme",t):document.body.removeAttribute("data-clepit-theme")}static getResolvedTheme(){return"undefined"==typeof window||"function"!=typeof window.matchMedia?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}static subscribe(t){return e.themeSubscribers.add(t),e.ensureThemeListener(),()=>{e.themeSubscribers.delete(t),e.maybeDetachThemeListener()}}static unregisterAllEditorsForTest(){for(const t of Array.from(e.themeRegistry.keys()))e.unregisterEditor(t);e.themeSubscribers.clear(),e.maybeDetachThemeListener()}static ensureThemeListener(){"undefined"!=typeof window&&"function"==typeof window.matchMedia&&0!==e.themeSubscribers.size&&(e.themeMediaQuery||(e.themeMediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),e.themeMediaQueryListener=t=>{const n=t.matches?"dark":"light";for(const a of e.themeSubscribers)a(n)},e.themeMediaQuery.addEventListener("change",e.themeMediaQueryListener)))}static maybeDetachThemeListener(){e.themeSubscribers.size>0||e.themeMediaQuery&&e.themeMediaQueryListener&&(e.themeMediaQuery.removeEventListener("change",e.themeMediaQueryListener),e.themeMediaQuery=void 0,e.themeMediaQueryListener=void 0)}},o=e=>{let t;const n=new Set,a=(e,a)=>{const o="function"==typeof e?e(t):e;if(Object.is(o,t))return;const i=t;t=a?o:Object.assign({},t,o);for(const r of n)r(t,i)},o=()=>t,i={getInitialState:()=>r,getState:o,setState:a,subscribe:e=>(n.add(e),()=>{n.delete(e)})},r=t=e(a,o,i);return i};var i,r,s,l=(s?o(s):o)((e=>(t,n,a)=>{const o=a.subscribe;return a.subscribe=(e,t,n)=>{if(!t)return o(e);const i=n?.equalityFn??Object.is;let r=e(a.getState());return n?.fireImmediately&&t(r,r),o(n=>{const a=e(n);if(!i(r,a)){const e=r;t(r=a,e)}})},e(t,n,a)})((e=>(t,n,a)=>e(t,n,a))((i=(e,t)=>({addBlock:(n,a,o)=>{const i=t().instances[n];if(!i)return;const r=[...i.data.blocks];void 0===o||o<0||o>r.length?r.push(a):r.splice(o,0,a);const s={...i,data:{...i.data,blocks:r}};e(e=>({instances:{...e.instances,[n]:s}})),i.config.onChange&&i.config.onChange(s.data)},addInstance:(n,a)=>{const o=t().instances;o[n]?o[n].config=a.config:o[n]=a,e({instances:o})},clearData:n=>{const a=t().instances[n];if(!a)return;const o={...a,data:{...a.data,blocks:[]}};e(e=>({instances:{...e.instances,[n]:o}})),a.config.onChange&&a.config.onChange(o.data)},getContentElement:e=>{const n=t().instances[e];return n?document.querySelector(`#${n.contentId}`):null},getCurrentView:e=>t().instances[e]?.currentView||null,getData:e=>t().instances[e]?.data||null,getInstance:e=>t().instances[e]||null,getIsReady:e=>{const n=t().instances[e];return!!n&&n.isReady},instances:{},partialUpdateBlockData:(n,a,o)=>{const i=t().instances[n];if(!i)return;const r=i.data.blocks.map((e,t)=>t===a?{...e,data:{...e.data,...o}}:e),s={...i,data:{...i.data,blocks:r}};e(e=>({instances:{...e.instances,[n]:s}})),i.config.onChange&&i.config.onChange(s.data)},removeBlock:(n,a)=>{const o=t().instances[n];if(!o)return;const i=o.data.blocks.filter((e,t)=>t!==a),r={...o,data:{...o.data,blocks:i}};e(e=>({instances:{...e.instances,[n]:r}})),o.config.onChange&&o.config.onChange(r.data)},removeInstance:t=>{e(e=>{const n={...e.instances};return delete n[t],{instances:n}})},setCurrentView:(n,a)=>{const o=t().instances[n];if(!o)return;const i={...o,currentView:a};e(e=>({instances:{...e.instances,[n]:i}})),o.config.onChange&&o.config.onChange(i.data)},setData:(n,a)=>{const o=t().instances[n];if(!o)return;const i={...o,data:a};e(e=>({instances:{...e.instances,[n]:i}})),o.config.onChange&&o.config.onChange(a)},setIsReady:(n,a)=>{const o=t().instances[n];if(!o)return;const i={...o,isReady:a};e(e=>({instances:{...e.instances,[n]:i}})),o.config.onChange&&o.config.onChange(i.data)},updateBlock:(n,a,o)=>{const i=t().instances[n];if(!i)return;const r=i.data.blocks.map((e,t)=>t===a?{...e,...o}:e),s={...i,data:{...i.data,blocks:r}};e(e=>({instances:{...e.instances,[n]:s}})),i.config.onChange&&i.config.onChange(s.data)},updateBlockData:(n,a,o)=>{const i=t().instances[n];if(!i)return;const r=i.data.blocks.map((e,t)=>t===a?{...e,data:o}:e),s={...i,data:{...i.data,blocks:r}};e(e=>({instances:{...e.instances,[n]:s}})),i.config.onChange&&i.config.onChange(s.data)},updateData:(n,a)=>{const o=t().instances[n];if(!o)return;const i={...o,data:{...o.data,...a}};e(e=>({instances:{...e.instances,[n]:i}})),o.config.onChange&&o.config.onChange(i.data)},updateInstance:(n,a)=>{const o=t().instances;o[n]&&(o[n].data=a.data,e({instances:o}))}}),r={name:"clepit-store",version:0},(e,t,n)=>{const a=r.version??0,o=r.storage??("undefined"==typeof localStorage?void 0:localStorage),s=r.merge??((e,t)=>Object.assign({},t,e)),l=i(e,t,n);if(o){try{const e=o.getItem(r.name);if(e){const t=JSON.parse(e),n=t.version===a?t.state:r.migrate?r.migrate(t.state,t.version??0):void 0;void 0!==n&&Object.assign(l,s(n,l))}}catch{}n.subscribe(e=>{try{o.setItem(r.name,JSON.stringify({state:r.partialize?r.partialize(e):e,version:a}))}catch{}})}return l}))));function c(){if("undefined"==typeof navigator)return"unknown";const e=navigator.platform.toLowerCase(),t=navigator.userAgent.toLowerCase();return e.includes("mac")||t.includes("mac")?"mac":e.includes("win")||t.includes("win")?"windows":e.includes("linux")||t.includes("linux")?"linux":"unknown"}function p(){return"mac"===c()?"⌘":"Ctrl"}function d(e){return"mac"===c()?e.join(""):e.join(" + ")}var u=e=>d([p(),e]),m=e=>d([p(),{down:"↓",left:"←",right:"→",up:"↑"}[e]]),h=()=>d([p(),"B"]),g=()=>d([p(),"⌫"]),b=()=>d([p(),"⌦"]),f=()=>d([p(),"I"]),y=()=>d([p(),"K"]),v=e=>d([p(),"⇧",e]),x=e=>d([p(),"⇧",{down:"↓",left:"←",right:"→",up:"↑"}[e]]),k=()=>d([p(),"U"]),w=class e{static{this.label="bold"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 4h6a4 4 0 0 1 0 8H7z"/><path d="M7 12h7a4 4 0 0 1 0 8H7z"/></svg>'}static{this.shortcut=h()}static apply(e){a.injectStyles("clepit-bold-styles","\n/* Bold inline formatting styles */\n.clepit-toolbar-button strong,\n.clepit-toolbar-button em,\n.clepit-toolbar-button u,\n.clepit-toolbar-button code,\n.clepit-toolbar-button mark {\n font-size: inherit;\n font-weight: inherit;\n font-style: inherit;\n text-decoration: inherit;\n background: transparent;\n padding: 0;\n border-radius: 0;\n font-family: inherit;\n}\n");const t=document.createElement("strong");e.surroundContents(t),sr.updateStateFromRange(e)}static remove(t){const n=e.findBoldElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}}else{const e=t.commonAncestorContainer;if(e.nodeType===Node.ELEMENT_NODE){const n=e.querySelectorAll("strong");for(const e of n)if(t.intersectsNode(e)){const t=e.parentElement;t&&(t.insertBefore(document.createTextNode(e.textContent||""),e),t.removeChild(e))}}}sr.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findBoldElement(n)||t.cloneContents().querySelectorAll('b, strong, [style*="font-weight: bold"], [style*="font-weight:bold"]').length>0}static findBoldElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("B"===e.tagName||"STRONG"===e.tagName)return e;if("bold"===e.style.fontWeight||Number.parseInt(e.style.fontWeight)>=700)return e}return t.parentNode?e.findBoldElement(t.parentNode):null}},C=class e{static{this.label="inline code"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="7 8 3 12 7 16"/><polyline points="17 8 21 12 17 16"/></svg>'}static{this.shortcut=u("`")}static apply(e,t,n){a.injectStyles("clepit-inline-code-styles","\n/* Inline code styling when <code> is within editable text */\n.clepit-paragraph code,\n.clepit-header code,\n.clepit-list-item code,\n.clepit-quote-text code,\n.clepit-quote-caption code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Output inline code styling */\n.clepit-output-paragraph code,\n.clepit-output-header code,\n.clepit-output-list li code,\n.clepit-output-quote code,\n.clepit-output-quote cite code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Toolbar button code styling */\n.clepit-toolbar-button strong,\n.clepit-toolbar-button em,\n.clepit-toolbar-button u,\n.clepit-toolbar-button code,\n.clepit-toolbar-button mark {\n font-size: inherit;\n font-weight: inherit;\n font-style: inherit;\n text-decoration: inherit;\n background: transparent;\n padding: 0;\n border-radius: 0;\n font-family: inherit;\n}\n");const o=document.createElement("code");o.classList.add("clepit-inline-code"),t&&a.applyClassNames(o,t),n&&Object.entries(n).forEach(([e,t])=>{if(void 0!==t){const n=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);o.style.setProperty(n,String(t))}}),e.surroundContents(o),sr.updateStateFromRange(e)}static remove(t){const n=e.findCodeElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}}else{const e=t.commonAncestorContainer;if(e.nodeType===Node.ELEMENT_NODE){const n=e.querySelectorAll("code");for(const e of n)if(t.intersectsNode(e)){const t=e.parentElement;t&&(t.insertBefore(document.createTextNode(e.textContent||""),e),t.removeChild(e))}}}sr.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findCodeElement(n)||t.cloneContents().querySelectorAll('code, [style*="font-family: monospace"], [style*="font-family:monospace"]').length>0}static findCodeElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("CODE"===e.tagName)return e;const n=window.getComputedStyle(e);if(n.fontFamily.includes("monospace")||n.fontFamily.includes("Monaco")||n.fontFamily.includes("Menlo"))return e;if(e.style.fontFamily.includes("monospace")||e.style.fontFamily.includes("Monaco")||e.style.fontFamily.includes("Menlo"))return e}return t.parentNode?e.findCodeElement(t.parentNode):null}static updateExistingCodeElements(e,t){document.querySelectorAll("code").forEach(n=>{n instanceof HTMLElement&&(n.classList.contains("clepit-inline-code")||n.classList.add("clepit-inline-code"),e&&a.applyClassNames(n,e),t&&Object.entries(t).forEach(([e,t])=>{if(void 0!==t){const a=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);n.style.setProperty(a,String(t))}}))})}},E=class e{static{this.label="italic"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 4h8"/><path d="M7 20h8"/><path d="M13 4L9 20"/></svg>'}static{this.shortcut=f()}static apply(e){a.injectStyles("clepit-italic-styles","\n/* Italic inline formatting styles */\n.clepit-toolbar-button strong,\n.clepit-toolbar-button em,\n.clepit-toolbar-button u,\n.clepit-toolbar-button code,\n.clepit-toolbar-button mark {\n font-size: inherit;\n font-weight: inherit;\n font-style: inherit;\n text-decoration: inherit;\n background: transparent;\n padding: 0;\n border-radius: 0;\n font-family: inherit;\n}\n\n.clepit-menu-icon--italic {\n font-style: italic;\n}\n");const t=document.createElement("em");e.surroundContents(t),sr.updateStateFromRange(e)}static remove(t){const n=e.findItalicElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}}else{const e=t.commonAncestorContainer;if(e.nodeType===Node.ELEMENT_NODE){const n=e.querySelectorAll("em, i");for(const e of n)if(t.intersectsNode(e)){const t=e.parentElement;t&&(t.insertBefore(document.createTextNode(e.textContent||""),e),t.removeChild(e))}}}sr.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findItalicElement(n)||t.cloneContents().querySelectorAll('i, em, [style*="font-style: italic"], [style*="font-style:italic"]').length>0}static findItalicElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("I"===e.tagName||"EM"===e.tagName)return e;if("italic"===window.getComputedStyle(e).fontStyle)return e;if("italic"===e.style.fontStyle)return e}return t.parentNode?e.findItalicElement(t.parentNode):null}},S="clepit-link-styles",N=`\n/* Link styles - simple and clean */\n.${a.classNames.block.link} {\n color: var(--clepit-primary);\n cursor: pointer;\n}\n\n.${a.classNames.block.link}:hover {\n color: var(--clepit-primary-hover);\n}\n`,A="clepit-dialogs-styles",L="\n/* Dialog Overlay */\n/* A native <dialog>. showModal() puts it in the top layer and paints a real\n * ::backdrop, so the full-screen scrim, the z-index and the manual centring are\n * the browser's job now. The non-modal branch below keeps the old flex overlay\n * for a DOM without showModal, where the element is an ordinary block. */\n.clepit-dialog-overlay {\n border: none;\n padding: 0;\n background: transparent;\n max-width: none;\n max-height: none;\n}\n\n.clepit-dialog-overlay[open] {\n display: flex;\n align-items: center;\n justify-content: center;\n}\n\n.clepit-dialog-overlay::backdrop {\n background: rgba(0, 0, 0, 0.5);\n backdrop-filter: blur(2px);\n}\n\n/* Fallback: no showModal, so the element is not in the top layer and paints no\n * backdrop of its own. */\n.clepit-dialog-overlay:not([open]) {\n position: fixed;\n inset: 0;\n background: rgba(0, 0, 0, 0.5);\n align-items: center;\n justify-content: center;\n z-index: 10000;\n backdrop-filter: blur(2px);\n}\n\n/* Dialog Container */\n.clepit-dialog {\n background: var(--clepit-bg);\n border-radius: 8px;\n box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);\n padding: 24px;\n min-width: 400px;\n max-width: 500px;\n max-height: 80vh;\n overflow-y: auto;\n position: relative;\n transform: scale(0.95);\n opacity: 0;\n transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n.clepit-dialog--hidden {\n transform: scale(0.95);\n opacity: 0;\n}\n\n.clepit-dialog:not(.clepit-dialog--hidden) {\n transform: scale(1);\n opacity: 1;\n}\n\n/* Dialog Title */\n.clepit-dialog-title {\n margin: 0 0 20px 0;\n font-size: 18px;\n font-weight: 600;\n color: var(--clepit-text);\n text-align: center;\n}\n\n/* Dialog Group */\n.clepit-dialog-group {\n margin-bottom: 16px;\n}\n\n/* Dialog Label */\n.clepit-dialog-label {\n display: block;\n margin-bottom: 6px;\n font-size: 14px;\n font-weight: 500;\n color: var(--clepit-text);\n}\n\n/* Dialog Input */\n.clepit-dialog-input {\n width: 100%;\n padding: 10px 12px;\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n font-size: 14px;\n color: var(--clepit-text);\n background: var(--clepit-bg);\n transition: border-color 0.2s ease, box-shadow 0.2s ease;\n box-sizing: border-box;\n}\n\n.clepit-dialog-input:focus {\n outline: none;\n border-color: var(--clepit-primary);\n box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);\n}\n\n.clepit-dialog-input::placeholder {\n color: var(--clepit-text-subtle);\n}\n\n/* Dialog Buttons */\n.clepit-dialog-buttons {\n display: flex;\n gap: 12px;\n justify-content: flex-end;\n margin-top: 24px;\n}\n\n/* Dialog Button */\n.clepit-dialog-button {\n padding: 10px 20px;\n border: none;\n border-radius: 6px;\n font-size: 14px;\n font-weight: 500;\n cursor: pointer;\n transition: all 0.2s ease;\n min-width: 80px;\n}\n\n.clepit-dialog-button--cancel {\n background: var(--clepit-surface);\n color: var(--clepit-text);\n border: 1px solid var(--clepit-border);\n}\n\n.clepit-dialog-button--cancel:hover {\n background: var(--clepit-border);\n border-color: var(--clepit-text-subtle);\n}\n\n.clepit-dialog-button--save {\n background: var(--clepit-primary);\n color: white;\n}\n\n.clepit-dialog-button--save:hover {\n background: var(--clepit-primary);\n}\n\n.clepit-dialog-button--save:disabled {\n background: var(--clepit-text-subtle);\n cursor: not-allowed;\n}\n\n/* Responsive */\n@media (max-width: 640px) {\n .clepit-dialog {\n min-width: 320px;\n max-width: 90vw;\n margin: 20px;\n }\n\n .clepit-dialog-buttons {\n flex-direction: column;\n }\n\n .clepit-dialog-button {\n width: 100%;\n }\n}\n";function B(e,t,n){const a=document.createElement(e);if(t&&(a.className=t),n)for(const[o,i]of Object.entries(n))a.setAttribute(o,i);return a}function $(e,t){return`${e}-${t}`}function M(e){return!e||!e.trim()||"<br>"===e}function I(e){if(!e||M(e))return"";const t=document.createElement("div");t.innerHTML=e;const n=["strong","b","em","i","u","s","del","mark","code","a","span"],a=["href","target","data-tooltip","data-status","data-status-variant","data-user-id","data-page-id","class"];function o(e){if(e.nodeType===Node.TEXT_NODE)return e.cloneNode(!0);if(e.nodeType===Node.ELEMENT_NODE){const t=e,i=t.tagName.toLowerCase();if(!n.includes(i))return document.createTextNode(t.textContent||"");const r=document.createElement(i);for(const e of t.attributes)a.includes(e.name.toLowerCase())&&r.setAttribute(e.name,e.value);"a"===i&&(r.setAttribute("target","_blank"),r.setAttribute("rel","noopener noreferrer"));for(const e of Array.from(t.childNodes)){const t=o(e);t&&r.appendChild(t)}return r}return null}const i=document.createElement("div");for(const r of Array.from(t.childNodes)){const e=o(r);e&&i.appendChild(e)}return i.innerHTML}function T(e,t){const n=window.getSelection();if(!n||0===n.rangeCount)return!1;const a=n.getRangeAt(0);if(!a)return!1;if(!e.contains(a.commonAncestorContainer))return!1;if(0===(e.textContent||"").length)return!0;if("left"===t){const t=e.firstChild;return t&&t.nodeType===Node.TEXT_NODE?a.startContainer===t&&0===a.startOffset:a.startContainer===e&&0===a.startOffset}{const t=e.lastChild;return t&&t.nodeType===Node.TEXT_NODE?a.endContainer===t&&a.endOffset===t.textContent?.length:a.endContainer===e&&a.endOffset===e.childNodes.length}}var q=class e{static{this.isOpen=!1}constructor(e){this.overlay=null,this.dialog=null,this.textInput=null,this.urlInput=null,this.handleKeyDown=e=>{"Escape"===e.key&&(this.options.onCancel(),this.hide())},this.handleInputKeyDown=e=>{if("Enter"===e.key){const e=this.textInput?.value.trim()||"",t=this.urlInput?.value.trim()||"";e&&t&&(this.options.onConfirm(e,t),this.hide())}},this.options=e}show(){this.overlay||e.isOpen||(a.injectStyles(A,L),e.isOpen=!0,this.createDialog(),this.bindEvents(),this.focusFirstInput())}hide(){if(!this.overlay)return;const t=this.overlay;"function"==typeof t.close&&t.open&&t.close(),t.remove(),this.overlay=null,this.dialog=null,this.textInput=null,this.urlInput=null,e.isOpen=!1;const n=document.querySelector(".clepit-toolbar");n&&(n.style.display="flex")}createDialog(){this.overlay=B("dialog","clepit-dialog-overlay"),this.applyStyles(this.overlay,this.options.styles?.overlay),this.applyClassNames(this.overlay,this.options.classNames?.overlay),this.dialog=B("div","clepit-dialog"),this.applyStyles(this.dialog,this.options.styles?.container),this.applyClassNames(this.dialog,this.options.classNames?.container);const e=B("h3","clepit-dialog-title");e.textContent="Insert Link",this.applyStyles(e,this.options.styles?.title),this.applyClassNames(e,this.options.classNames?.title);const t=this.createInputGroup("Text",this.options.text,"text");this.textInput=t.querySelector("input");const n=this.createInputGroup("URL",this.options.url,"url");this.urlInput=n.querySelector("input");const a=this.createButtonGroup();this.dialog.appendChild(e),this.dialog.appendChild(t),this.dialog.appendChild(n),this.dialog.appendChild(a),this.overlay.appendChild(this.dialog),document.body.appendChild(this.overlay);const o=this.overlay;"function"==typeof o.showModal?o.showModal():o.style.display="flex",this.dialog?.classList.remove("clepit-dialog--hidden");const i=document.querySelector(".clepit-toolbar");i&&(i.style.display="none")}createInputGroup(e,t,n){const a=B("div","clepit-dialog-group");this.applyStyles(a,this.options.styles?.group),this.applyClassNames(a,this.options.classNames?.group);const o=B("label","clepit-dialog-label");o.textContent=e,this.applyStyles(o,this.options.styles?.label),this.applyClassNames(o,this.options.classNames?.label);const i=B("input","clepit-dialog-input");return i.type="url"===n?"url":"text",i.value=t,i.placeholder="url"===n?"https://example.com":"Link text",this.applyStyles(i,this.options.styles?.input),this.applyClassNames(i,this.options.classNames?.input),a.appendChild(o),a.appendChild(i),a}createButtonGroup(){const e=B("div","clepit-dialog-buttons");this.applyStyles(e,this.options.styles?.buttons),this.applyClassNames(e,this.options.classNames?.buttons);const t=B("button","clepit-dialog-button clepit-dialog-button--cancel");t.textContent="Cancel",t.type="button",this.applyStyles(t,this.options.styles?.cancelButton),this.applyClassNames(t,this.options.classNames?.cancelButton);const n=B("button","clepit-dialog-button clepit-dialog-button--save");return n.textContent="Apply",n.type="button",this.applyStyles(n,this.options.styles?.saveButton),this.applyClassNames(n,this.options.classNames?.saveButton),t.addEventListener("click",()=>{this.options.onCancel(),this.hide()}),n.addEventListener("click",()=>{this.options.onConfirm(this.textInput?.value.trim()||"",this.urlInput?.value.trim()||""),this.hide()}),e.appendChild(t),e.appendChild(n),e}bindEvents(){this.overlay&&(this.overlay.addEventListener("click",e=>{e.target===this.overlay&&(this.options.onCancel(),this.hide())}),document.addEventListener("keydown",this.handleKeyDown),this.textInput&&this.textInput.addEventListener("keydown",this.handleInputKeyDown),this.urlInput&&this.urlInput.addEventListener("keydown",this.handleInputKeyDown))}focusFirstInput(){setTimeout(()=>{this.urlInput&&(this.urlInput.focus(),this.urlInput.select())},100)}applyStyles(e,t){t&&Object.entries(t).forEach(([t,n])=>{void 0!==n&&e.style.setProperty(t,String(n))})}applyClassNames(e,t){t&&e.classList.add(t)}destroy(){document.removeEventListener("keydown",this.handleKeyDown),this.hide(),e.isOpen=!1}},D=class e{static{this.label="link"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13a5 5 0 0 0 7.07 0l1.76-1.76a5 5 0 0 0-7.07-7.07L10 5"/><path d="M14 11a5 5 0 0 0-7.07 0L5.17 12.76a5 5 0 0 0 7.07 7.07L14 19"/></svg>'}static{this.shortcut=y()}static apply(t,n,o){a.injectStyles(S,N);const i=t.toString().trim(),r=e.findLinkElement(t.commonAncestorContainer);let s=i,l="";r&&(s=r.textContent||i,l=r.href||"");const c=t.cloneRange();new q({classNames:n,onCancel:()=>{const e=window.getSelection();e&&(e.removeAllRanges(),e.addRange(c))},onConfirm:(t,n)=>{try{const o=window.getSelection();if(o){if(o.removeAllRanges(),o.addRange(c),!n.trim())return void e.remove(c);if(t!==i){c.deleteContents();const e=document.createTextNode(t);c.insertNode(e),c.selectNode(e)}const r=a.createStyledElement("a",a.classNames.block.link);r.href=n,r.target="_blank",r.rel="noopener noreferrer";try{c.surroundContents(r)}catch{const e=c.extractContents();r.appendChild(e),c.insertNode(r)}const s=document.createRange();s.selectNodeContents(r),o.removeAllRanges(),o.addRange(s);const l=r.closest('[contenteditable="true"]');if(l){const e=new Event("input",{bubbles:!0});l.dispatchEvent(e)}}}catch(o){console.error("Failed to apply link:",o)}},styles:o,text:s||"Link text",url:l}).show(),sr.updateStateFromRange(t)}static remove(t){const n=e.findLinkElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}}else{const e=t.commonAncestorContainer;if(e.nodeType===Node.ELEMENT_NODE){const n=e.querySelectorAll("a");for(const e of n)if(t.intersectsNode(e)){const t=e.parentElement;t&&(t.insertBefore(document.createTextNode(e.textContent||""),e),t.removeChild(e))}}}sr.updateStateFromRange(t)}static findLinkElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("A"===e.tagName)return e}return t.parentNode?e.findLinkElement(t.parentNode):null}static isActive(t){const n=t.commonAncestorContainer;return!!e.findLinkElement(n)||t.cloneContents().querySelectorAll("a").length>0}},_="clepit-marker-styles",j="\n/* Marker brush effect */\n.clepit-paragraph mark,\n.clepit-header mark,\n.clepit-list-item mark,\n.clepit-quote-text mark,\n.clepit-quote-caption mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0; /* create stacking context so ::before sits behind text, not page */\n white-space: pre-wrap; /* ensure leading/trailing spaces inside mark render */\n}\n.clepit-paragraph mark::before,\n.clepit-header mark::before,\n.clepit-list-item mark::before,\n.clepit-quote-text mark::before,\n.clepit-quote-caption mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n -webkit-mask-image: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z'/></svg>\");\n mask-image: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z'/></svg>\");\n -webkit-mask-size: 100% 100%;\n mask-size: 100% 100%;\n -webkit-mask-repeat: no-repeat;\n mask-repeat: no-repeat;\n background-color: var(--clepit-marker);\n z-index: -1; /* behind text but within mark's stacking context */\n}\n\n/* Output marker brush effect for <mark> */\n.clepit-output-paragraph mark,\n.clepit-output-header mark,\n.clepit-output-list li mark,\n.clepit-output-quote mark,\n.clepit-output-quote cite mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n.clepit-output-paragraph mark::before,\n.clepit-output-header mark::before,\n.clepit-output-list li mark::before,\n.clepit-output-quote mark::before,\n.clepit-output-quote cite mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n -webkit-mask-image: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z'/></svg>\");\n mask-image: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z'/></svg>\");\n -webkit-mask-size: 100% 100%;\n mask-size: 100% 100%;\n -webkit-mask-repeat: no-repeat;\n mask-repeat: no-repeat;\n background-color: var(--clepit-marker);\n z-index: -1;\n}\n\n/* Marker wrapper styling */\n.clepit-marker-wrapper {\n position: relative;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n color: inherit;\n}\n\n/* Marker stroke styling */\n.clepit-marker-stroke {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n z-index: -1;\n pointer-events: none;\n -webkit-mask-image: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z'/></svg>\");\n mask-image: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z'/></svg>\");\n -webkit-mask-size: 100% 100%;\n mask-size: 100% 100%;\n -webkit-mask-repeat: no-repeat;\n mask-repeat: no-repeat;\n background-color: var(--clepit-marker);\n}\n\n/* Toolbar button mark styling */\n.clepit-toolbar-button strong,\n.clepit-toolbar-button em,\n.clepit-toolbar-button u,\n.clepit-toolbar-button code,\n.clepit-toolbar-button mark {\n font-size: inherit;\n font-weight: inherit;\n font-style: inherit;\n text-decoration: inherit;\n background: transparent;\n padding: 0;\n border-radius: 0;\n font-family: inherit;\n}\n",z=class e{static{this.label="marker"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 21l6-2 9-9a2.828 2.828 0 0 0-4-4l-9 9-2 6z"/><path d="M14 7l3 3"/></svg>'}static{this.shortcut=v("M")}static apply(t,n,o){a.injectStyles(_,j);const i=document.createElement("span");i.classList.add("clepit-marker-wrapper");const r=document.createElement("span");r.classList.add("clepit-marker-stroke");const s=t.extractContents();i.appendChild(document.createTextNode(" ")),i.appendChild(s),i.appendChild(document.createTextNode(" ")),i.insertBefore(r,i.firstChild),t.insertNode(i),t.selectNodeContents(i),e.applyUserStyles(i,r,n,o);const l=i.closest('[contenteditable="true"]');l&&l.dispatchEvent(new Event("input",{bubbles:!0})),sr.updateStateFromRange(t)}static remove(t){const n=e.findMarkerElement(t.commonAncestorContainer);if(n){const t=n.parentElement;if(t){const a=n.previousSibling,o=n.nextSibling,i=document.createDocumentFragment();Array.from(n.childNodes).forEach(e=>{e.nodeType===Node.ELEMENT_NODE&&e.classList?.contains("clepit-marker-stroke")||i.appendChild(e.cloneNode(!0))}),n.replaceWith(i),e.cleanupSpaces(t,a,o);const r=t.closest('[contenteditable="true"]');r&&r.dispatchEvent(new Event("input",{bubbles:!0}))}return}const a=t.cloneContents().querySelectorAll(".clepit-marker-wrapper");if(a.length>0){a.forEach(t=>{const n=t.parentElement;if(n){const a=t.previousSibling,o=t.nextSibling,i=document.createDocumentFragment();Array.from(t.childNodes).forEach(e=>{e.nodeType===Node.ELEMENT_NODE&&e.classList?.contains("clepit-marker-stroke")||i.appendChild(e.cloneNode(!0))}),t.replaceWith(i),e.cleanupSpaces(n,a,o)}});const n=t.commonAncestorContainer.closest('[contenteditable="true"]');return void(n&&n.dispatchEvent(new Event("input",{bubbles:!0})))}const o=e.findLegacyMarkElement(t.commonAncestorContainer);if(o){const e=o.parentElement;if(e){const t=o.textContent||"",n=document.createTextNode(t);e.insertBefore(n,o),e.removeChild(o);const a=e.closest('[contenteditable="true"]');a&&a.dispatchEvent(new Event("input",{bubbles:!0}))}}sr.updateStateFromRange(t)}static cleanupSpaces(e,t,n){const a=Array.from(e.childNodes).filter(e=>e.nodeType===Node.TEXT_NODE);a.forEach((e,o)=>{let i=e.textContent||"";if(0===o&&t?.nodeType===Node.TEXT_NODE&&(t.textContent||"").endsWith(" ")&&i.startsWith(" ")&&(i=i.substring(1)),o===a.length-1&&n?.nodeType===Node.TEXT_NODE){const e=n.textContent||"";i.endsWith(" ")&&e.startsWith(" ")&&(i=i.substring(0,i.length-1))}e.textContent=i})}static isActive(t){if(t.collapsed)return!1;if(t.cloneContents().querySelectorAll(".clepit-marker-wrapper").length>0)return!0;if(e.findMarkerElement(t.commonAncestorContainer))return!0;const n=t.startContainer,a=t.endContainer;return!(n===t.commonAncestorContainer||!e.findMarkerElement(n))||(!(a===t.commonAncestorContainer||a===n||!e.findMarkerElement(a))||null!==e.findLegacyMarkElement(t.commonAncestorContainer))}static findMarkerElement(e){let t=e,n=0;for(;t&&n<10;){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if(e.classList?.contains("clepit-marker-wrapper"))return e;if(e.classList?.contains("clepit-block")||e.classList?.contains(a.classNames.editor.container))break}t=t.parentNode,n++}return null}static findLegacyMarkElement(e){let t=e,n=0;for(;t&&n<10;){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("MARK"===e.tagName)return e;if(e.classList?.contains("clepit-block")||e.classList?.contains(a.classNames.editor.container))break;if(0===n){const t=window.getComputedStyle(e);if("yellow"===t.backgroundColor||"rgb(255, 255, 0)"===t.backgroundColor)return e;if("yellow"===e.style.backgroundColor||"rgb(255, 255, 0)"===e.style.backgroundColor)return e}}t=t.parentNode,n++}return null}static applyUserStyles(t,n,o,i){o&&a.applyClassNames(t,o),i&&Object.entries(i).forEach(([e,n])=>{if(void 0!==n&&"background"!==e){const a=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);t.style.setProperty(a,String(n))}});const r=t.style.getPropertyValue("--marker-background")||t.getAttribute("data-marker-background");if(r){const t=e.createStrokeSVG(r);return void(n.style.background=t)}if(i?.background){const t=i.background;if(t){const a=e.createStrokeSVG(String(t));return void(n.style.background=a)}}const s=t.closest(`.${a.classNames.editor.content}, .${a.classNames.renderer.content}`);if(s){const t=window.getComputedStyle(s).getPropertyValue("--clepit-marker-background");if(t&&"initial"!==t&&"inherit"!==t){const a=e.createStrokeSVG(t.trim());return void(n.style.background=a)}}const l=t.closest(`.${a.classNames.block.content}`);if(!l)return;const c=l.style.background||l.style.backgroundColor||l.style.getPropertyValue("background-color");if(c&&"initial"!==c&&"inherit"!==c){const t=e.createStrokeSVG(c);return void(n.style.background=t)}const p=window.getComputedStyle(l).backgroundColor;if(p&&"rgba(0, 0, 0, 0)"!==p&&"transparent"!==p){const t=e.createStrokeSVG(p);n.style.background=t}}static createStrokeSVG(t){const n=e.colorToHex(t);return`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='${encodeURIComponent(n)}'/></svg>") no-repeat center / 100% 100%`}static colorToHex(e){if(e.startsWith("#"))return e;if(e.startsWith("rgb")){const t=e.match(/\d+/g);if(t&&t.length>=3)return`#${parseInt(t[0]).toString(16).padStart(2,"0")}${parseInt(t[1]).toString(16).padStart(2,"0")}${parseInt(t[2]).toString(16).padStart(2,"0")}`}return{blue:"#3742FA",cyan:"#7FDBDA",green:"#2ED573",lime:"#32FF7E",orange:"#FFA502",pink:"#FF6B9D",purple:"#A55EEA",red:"#FF4757",teal:"#006266",yellow:"#FFE047"}[e.toLowerCase()]||"#FFE047"}},O="clepit-inline-status-styles",H='\n/* Inline status — same visual language as the Alert block but inline. */\n.clepit-status {\n display: inline;\n padding: 2px 8px;\n border-radius: 4px;\n font-size: 0.9em;\n line-height: 1.5;\n vertical-align: baseline;\n}\n\n.clepit-status[data-status-variant="info"] {\n background: var(--clepit-primary-bg);\n color: var(--clepit-primary-hover);\n}\n\n.clepit-status[data-status-variant="success"] {\n background: var(--clepit-success-bg);\n color: var(--clepit-success);\n}\n\n.clepit-status[data-status-variant="warning"] {\n background: var(--clepit-warning-bg);\n color: var(--clepit-warning);\n}\n\n.clepit-status[data-status-variant="error"] {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n}\n\n.clepit-status[data-status-variant="plain"] {\n background: transparent;\n color: inherit;\n}\n\n/* Dialog variant picker — mirrors inline chip styling at rest, highlight on hover/selected. */\n.clepit-status-dialog-variants {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n margin-top: 4px;\n}\n\n.clepit-status-dialog-variant {\n appearance: none;\n -webkit-appearance: none;\n background: transparent;\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n padding: 6px 12px;\n cursor: pointer;\n font-family: inherit;\n font-size: 13px;\n color: var(--clepit-text);\n transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;\n}\n\n.clepit-status-dialog-variant:hover {\n border-color: transparent;\n}\n\n.clepit-status-dialog-variant--info:hover,\n.clepit-status-dialog-variant--info[data-selected="true"] {\n background: var(--clepit-primary-bg);\n color: var(--clepit-primary-hover);\n border-color: transparent;\n}\n\n.clepit-status-dialog-variant--success:hover,\n.clepit-status-dialog-variant--success[data-selected="true"] {\n background: var(--clepit-success-bg);\n color: var(--clepit-success);\n border-color: transparent;\n}\n\n.clepit-status-dialog-variant--warning:hover,\n.clepit-status-dialog-variant--warning[data-selected="true"] {\n background: var(--clepit-warning-bg);\n color: var(--clepit-warning);\n border-color: transparent;\n}\n\n.clepit-status-dialog-variant--error:hover,\n.clepit-status-dialog-variant--error[data-selected="true"] {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n border-color: transparent;\n}\n\n.clepit-status-dialog-variant--plain:hover,\n.clepit-status-dialog-variant--plain[data-selected="true"] {\n background: var(--clepit-surface);\n color: var(--clepit-text);\n border-color: transparent;\n}\n',P=["info","success","warning","error","plain"],F=class e{static{this.isOpen=!1}constructor(e){this.overlay=null,this.dialog=null,this.textInput=null,this.options=e,this.variant=e.variant}show(){this.overlay||e.isOpen||(a.injectStyles(A,L),e.isOpen=!0,this.createDialog(),this.bindEvents(),this.focusFirstInput())}hide(){if(!this.overlay)return;const t=this.overlay;"function"==typeof t.close&&t.open&&t.close(),t.remove(),this.overlay=null,this.dialog=null,this.textInput=null,e.isOpen=!1;const n=document.querySelector(".clepit-toolbar");n&&(n.style.display="flex")}createDialog(){this.overlay=B("dialog","clepit-dialog-overlay"),this.applyStyles(this.overlay,this.options.styles?.overlay),this.dialog=B("div","clepit-dialog"),this.applyStyles(this.dialog,this.options.styles?.container);const e=B("h3","clepit-dialog-title");e.textContent="Inline status",this.applyStyles(e,this.options.styles?.title),this.dialog.appendChild(e);const t=B("label","clepit-dialog-label");t.textContent="Label",this.applyStyles(t,this.options.styles?.label),this.dialog.appendChild(t),this.textInput=B("input","clepit-dialog-input"),this.textInput.type="text",this.textInput.value=this.options.text,this.textInput.placeholder="Status label",this.applyStyles(this.textInput,this.options.styles?.input),this.dialog.appendChild(this.textInput);const n=B("label","clepit-dialog-label");n.textContent="Variant",this.applyStyles(n,this.options.styles?.label),this.dialog.appendChild(n);const a=B("div","clepit-status-dialog-variants");for(const c of P){const e=B("button",`clepit-status-dialog-variant clepit-status-dialog-variant--${c}`);e.type="button",e.dataset.variant=c,e.textContent=c,e.dataset.selected=String(c===this.variant),e.addEventListener("click",()=>{this.variant=c;for(const e of Array.from(a.children))e.dataset.selected=String(e.dataset.variant===c)}),a.appendChild(e)}this.dialog.appendChild(a);const o=B("div","clepit-dialog-buttons");this.applyStyles(o,this.options.styles?.buttons);const i=B("button","clepit-dialog-button clepit-dialog-button--cancel");i.type="button",i.textContent="Cancel",i.addEventListener("click",()=>this.handleCancel()),this.applyStyles(i,this.options.styles?.cancelButton),o.appendChild(i);const r=B("button","clepit-dialog-button clepit-dialog-button--save");r.type="button",r.textContent="Apply",r.addEventListener("click",()=>this.handleConfirm()),this.applyStyles(r,this.options.styles?.saveButton),o.appendChild(r),this.dialog.appendChild(o),this.overlay.appendChild(this.dialog),document.body.appendChild(this.overlay);const s=this.overlay;"function"==typeof s.showModal?s.showModal():s.style.display="flex";const l=document.querySelector(".clepit-toolbar");l&&(l.style.display="none")}bindEvents(){if(!this.overlay||!this.dialog||!this.textInput)return;this.overlay.addEventListener("click",e=>{e.target===this.overlay&&this.handleCancel()});const e=e=>{"Escape"===e.key&&this.handleCancel(),"Enter"===e.key&&e.target===this.textInput&&(e.preventDefault(),this.handleConfirm())};document.addEventListener("keydown",e),this.dialog.dataset.keyHandlerRegistered="true",this.dialog.__keyHandler=e}focusFirstInput(){setTimeout(()=>this.textInput?.focus(),50)}handleConfirm(){this.textInput&&(this.options.onConfirm(this.textInput.value.trim(),this.variant),this.cleanupKeyHandler(),this.hide())}handleCancel(){this.options.onCancel(),this.cleanupKeyHandler(),this.hide()}cleanupKeyHandler(){if(!this.dialog)return;const e=this.dialog.__keyHandler;e&&document.removeEventListener("keydown",e)}applyStyles(e,t){if(t)for(const[n,a]of Object.entries(t))void 0!==a&&e.style.setProperty(n,String(a))}},R="clepit-status",V=class e{static{this.label="status"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="8" width="18" height="8" rx="4"/><circle cx="8" cy="12" r="1.25"/><circle cx="16" cy="12" r="1.25"/></svg>'}static apply(t,n,o){a.injectStyles(O,H);const i=t.toString().trim(),r=e.findStatusElement(t.commonAncestorContainer),s=r?r.textContent??i:i,l=r?e.readVariant(r):"info",c=t.cloneRange();new F({classNames:n,onCancel:()=>{const e=window.getSelection();e&&(e.removeAllRanges(),e.addRange(c))},onConfirm:(t,n)=>{try{const a=window.getSelection();if(!a)return;if(a.removeAllRanges(),a.addRange(c),!t.trim())return void e.remove(c);if(e.unwrap(c),t!==i){c.deleteContents();const e=document.createTextNode(t);c.insertNode(e),c.selectNode(e)}const o=document.createElement("span");o.className=(e=>`${R} ${R}--${e}`)(n),o.dataset.statusVariant=n;try{c.surroundContents(o)}catch{const e=c.extractContents();o.appendChild(e),c.insertNode(o)}const r=document.createRange();r.selectNodeContents(o),a.removeAllRanges(),a.addRange(r);const s=o.closest('[contenteditable="true"]');s&&s.dispatchEvent(new Event("input",{bubbles:!0}))}catch(a){console.error("Failed to apply inline status:",a)}},styles:o,text:s||"status",variant:l}).show(),sr.updateStateFromRange(t)}static remove(t){e.unwrap(t),sr.updateStateFromRange(t)}static isActive(t){return!!e.findStatusElement(t.commonAncestorContainer)||t.cloneContents().querySelectorAll(`.${R}`).length>0}static unwrap(t){const n=e.findStatusElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}return}const a=t.commonAncestorContainer;if(a.nodeType!==Node.ELEMENT_NODE)return;const o=a.querySelectorAll(`.${R}`);for(const e of Array.from(o)){if(!t.intersectsNode(e))continue;const n=e.parentElement;n&&(n.insertBefore(document.createTextNode(e.textContent||""),e),n.removeChild(e))}}static findStatusElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if(e.classList?.contains(R))return e}return t.parentNode?e.findStatusElement(t.parentNode):null}static readVariant(e){const t=e.dataset.statusVariant;if(t&&["info","success","warning","error"].includes(t))return t;for(const n of["info","success","warning","error"])if(e.classList.contains(`${R}--${n}`))return n;return"info"}},U=class e{static{this.label="strikethrough"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M16 4H9a3 3 0 0 0-2.83 4"/><path d="M14 12a4 4 0 0 1 0 8H6"/><line x1="4" x2="20" y1="12" y2="12"/></svg>'}static{this.shortcut=v("X")}static apply(e){a.injectStyles("clepit-strikethrough-styles",'\n/* Strikethrough inline formatting styles */\n.clepit-toolbar-button strong,\n.clepit-toolbar-button em,\n.clepit-toolbar-button u,\n.clepit-toolbar-button s,\n.clepit-toolbar-button del,\n.clepit-toolbar-button code,\n.clepit-toolbar-button mark {\n font-size: inherit;\n font-weight: inherit;\n font-style: inherit;\n text-decoration: inherit;\n background: transparent;\n padding: 0;\n border-radius: 0;\n font-family: inherit;\n}\n\n/* Keep strikethrough visual hint without changing size */\n.clepit-toolbar-button[data-tool="strikethrough"] {\n text-decoration: line-through;\n}\n');const t=document.createElement("s");e.surroundContents(t),sr.updateStateFromRange(e)}static remove(t){const n=e.findStrikethroughElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}}else{const e=t.commonAncestorContainer;if(e.nodeType===Node.ELEMENT_NODE){const n=e.querySelectorAll('s, del, [style*="text-decoration: line-through"], [style*="text-decoration:line-through"]');for(const e of n)if(t.intersectsNode(e)){const t=e.parentElement;t&&(t.insertBefore(document.createTextNode(e.textContent||""),e),t.removeChild(e))}}}sr.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findStrikethroughElement(n)||t.cloneContents().querySelectorAll('s, del, [style*="text-decoration: line-through"], [style*="text-decoration:line-through"]').length>0}static findStrikethroughElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("S"===e.tagName||"DEL"===e.tagName)return e;if(window.getComputedStyle(e).textDecoration.includes("line-through"))return e;if(e.style.textDecoration.includes("line-through"))return e}return t.parentNode?e.findStrikethroughElement(t.parentNode):null}},W="clepit-tooltip-styles",K=`\n/* Tooltip styles - border bottom instead of text-decoration to avoid underline tool conflict */\n.${a.classNames.block.tooltip} {\n border-bottom: 1px dotted var(--clepit-text-subtle);\n cursor: help;\n}\n\n.${a.classNames.block.tooltip}:hover {\n border-bottom: 1px dotted var(--clepit-text-muted);\n}\n`,G=class{constructor(e){this.overlay=null,this.dialog=null,this.inputText=null,this.inputTooltip=null,this.handleKeyDown=e=>{"Escape"===e.key&&(this.options.onCancel(),this.hide())},this.handleInputKeyDown=e=>{if("Enter"===e.key){const e=this.inputText?.value.trim()||"",t=this.inputTooltip?.value.trim()||"";this.options.onConfirm(e,t),this.hide()}},this.options=e}show(){this.overlay||(a.injectStyles(A,L),document.querySelectorAll(".clepit-dialog-overlay").forEach(e=>{e!==this.overlay&&e.remove()}),this.createDialog(),this.bindEvents(),this.focusFirstInput())}hide(){if(!this.overlay)return;const e=this.overlay;"function"==typeof e.close&&e.open&&e.close(),this.destroy()}createDialog(){this.overlay=B("dialog","clepit-dialog-overlay"),this.applyStyles(this.overlay,this.options.styles?.overlay),this.applyClassNames(this.overlay,this.options.classNames?.overlay),this.dialog=B("div","clepit-dialog"),this.applyStyles(this.dialog,this.options.styles?.container),this.applyClassNames(this.dialog,this.options.classNames?.container);const e=B("h3","clepit-dialog-title");e.textContent="Insert Tooltip",this.applyStyles(e,this.options.styles?.title),this.applyClassNames(e,this.options.classNames?.title);const t=this.createInputGroup("Text",this.options.text,"text");this.inputText=t.querySelector("input");const n=this.createInputGroup("Tooltip",this.options.tooltip,"text");this.inputTooltip=n.querySelector("input");const a=this.createButtonGroup();this.dialog.appendChild(e),this.dialog.appendChild(t),this.dialog.appendChild(n),this.dialog.appendChild(a),this.overlay.appendChild(this.dialog),document.body.appendChild(this.overlay);const o=this.overlay;"function"==typeof o.showModal?o.showModal():o.style.display="flex",this.dialog?.classList.remove("clepit-dialog--hidden");const i=document.querySelector(".clepit-toolbar");i&&(i.style.display="none"),this.options.onShow?.()}createInputGroup(e,t,n){const a=B("div","clepit-dialog-group");this.applyStyles(a,this.options.styles?.group),this.applyClassNames(a,this.options.classNames?.group);const o=B("label","clepit-dialog-label");o.textContent=e,this.applyStyles(o,this.options.styles?.label),this.applyClassNames(o,this.options.classNames?.label);const i=B("input","clepit-dialog-input");return i.type="url"===n?"url":"text",i.value=t,i.placeholder="Tooltip"===e?"Tooltip text":"Text",this.applyStyles(i,this.options.styles?.input),this.applyClassNames(i,this.options.classNames?.input),a.appendChild(o),a.appendChild(i),a}createButtonGroup(){const e=B("div","clepit-dialog-buttons");this.applyStyles(e,this.options.styles?.buttons),this.applyClassNames(e,this.options.classNames?.buttons);const t=B("button","clepit-dialog-button clepit-dialog-button--cancel");t.textContent="Cancel",t.type="button",this.applyStyles(t,this.options.styles?.cancelButton),this.applyClassNames(t,this.options.classNames?.cancelButton);const n=B("button","clepit-dialog-button clepit-dialog-button--save");return n.textContent="Apply",n.type="button",this.applyStyles(n,this.options.styles?.saveButton),this.applyClassNames(n,this.options.classNames?.saveButton),t.addEventListener("click",()=>{this.options.onCancel(),this.hide()}),n.addEventListener("click",()=>{this.options.onConfirm(this.inputText?.value.trim()||"",this.inputTooltip?.value.trim()||""),this.hide()}),e.appendChild(t),e.appendChild(n),e}bindEvents(){this.overlay&&(this.overlay.addEventListener("click",e=>{e.target===this.overlay&&(this.options.onCancel(),this.hide())}),document.addEventListener("keydown",this.handleKeyDown),this.inputText&&this.inputText.addEventListener("keydown",this.handleInputKeyDown),this.inputTooltip&&this.inputTooltip.addEventListener("keydown",this.handleInputKeyDown))}focusFirstInput(){setTimeout(()=>{this.inputTooltip&&(this.inputTooltip.focus(),this.inputTooltip.select())},100)}applyStyles(e,t){t&&Object.entries(t).forEach(([t,n])=>{if(void 0!==n){const a=t.replace(/([A-Z])/g,"-$1").toLowerCase();e.style.setProperty(a,String(n))}})}applyClassNames(e,t){t&&e.classList.add(t)}destroy(){if(document.removeEventListener("keydown",this.handleKeyDown),this.overlay){this.overlay.remove(),this.overlay=null,this.dialog=null,this.inputText=null,this.inputTooltip=null;const e=document.querySelector(".clepit-toolbar");e&&(e.style.display="flex"),this.options.onHide&&this.options.onHide()}}};function J(e,t,n="below",o,i){let r=null,s=null;const l=()=>{if(r)return;a.injectStyles("clepit-inline-tooltip-styles","\n/* Inline Tooltip Container */\n.clepit-inline-tooltip {\n position: fixed;\n z-index: 9999;\n pointer-events: none;\n opacity: 0;\n transition: opacity 0.2s ease-in-out;\n}\n\n/* Tooltip Content */\n.clepit-inline-tooltip-content {\n background: var(--clepit-text);\n color: var(--clepit-bg);\n padding: 6px 10px;\n border-radius: 6px;\n font-size: 12px;\n font-weight: 500;\n white-space: nowrap;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);\n transform: translateY(8px);\n transition: transform 0.2s ease-in-out;\n position: relative;\n}\n\n/* Tooltip Arrow */\n.clepit-inline-tooltip-arrow {\n position: absolute;\n width: 0;\n height: 0;\n}\n\n/* Arrow pointing down (when tooltip is above target) */\n.clepit-inline-tooltip-arrow--above {\n top: 100%;\n left: 50%;\n transform: translateX(-50%);\n border-left: 6px solid transparent;\n border-right: 6px solid transparent;\n border-top: 6px solid var(--clepit-text);\n}\n\n/* Arrow pointing up (when tooltip is below target) */\n.clepit-inline-tooltip-arrow--below {\n bottom: 100%;\n left: 50%;\n transform: translateX(-50%);\n border-left: 6px solid transparent;\n border-right: 6px solid transparent;\n border-bottom: 6px solid var(--clepit-text);\n}\n"),r=document.createElement("div"),r.className=`clepit-inline-tooltip ${o?.container||""}`,a.applyStyling(r,{styles:i?.container});const l=document.createElement("div");l.className=`clepit-inline-tooltip-content ${o?.content||""}`,l.textContent=t,a.applyStyling(l,{styles:i?.content});const p=document.createElement("div");p.className=`clepit-inline-tooltip-arrow clepit-inline-tooltip-arrow--${n} ${o?.arrow||""}`,a.applyStyling(p,{styles:i?.arrow}),l.appendChild(p),r.appendChild(l),document.body.appendChild(r);const d=e.getBoundingClientRect(),u=l.offsetWidth,m=l.offsetHeight;let h,g=d.left+d.width/2-u/2;g=Math.max(8,Math.min(g,window.innerWidth-u-8));let b=n;"below"===n?(h=d.bottom+6+2,h+m>window.innerHeight-8&&(h=d.top-m-6-2,b="above")):(h=d.top-m-6-2,h<8&&(h=d.bottom+6+2,b="below")),p.className=`clepit-inline-tooltip-arrow clepit-inline-tooltip-arrow--${b} ${o?.arrow||""}`,r.style.left=`${g}px`,r.style.top=`${Math.max(8,Math.min(h,window.innerHeight-m-8))}px`,requestAnimationFrame(()=>{r&&(r.style.opacity="1",l.style.transform="translateY(0)")}),s||(s=new MutationObserver(()=>{document.body.contains(e)&&e.isConnected||(c(),s&&(s.disconnect(),s=null))}),s.observe(document.body,{childList:!0,subtree:!0}))},c=()=>{r&&(r.style.opacity="0",setTimeout(()=>{r&&r.parentElement&&r.parentElement.removeChild(r),r=null,s&&(s.disconnect(),s=null)},120))};return e.addEventListener("mouseenter",l),e.addEventListener("mouseleave",c),()=>{e.removeEventListener("mouseenter",l),e.removeEventListener("mouseleave",c),c()}}var X=class e{static{this.label="tooltip"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 7l-2.5 3H5a2 2 0 0 0-2 2v4a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-4a2 2 0 0 0-2-2h-4.5L12 7z"/><path d="M8 13h8"/><path d="M8 16h6"/></svg>'}static{this.shortcut=v("T")}static apply(t,n,o){a.injectStyles(W,K);const i=t.toString(),r=t.cloneRange();let s="",l=i;const c=e.findTooltipSpan(t.commonAncestorContainer);c&&(s=c.getAttribute("data-tooltip")||"",l=c.textContent||""),new G({classNames:n.classNames,onCancel:()=>{const e=window.getSelection();e&&(e.removeAllRanges(),e.addRange(r))},onConfirm:(t,i)=>{const s=window.getSelection();if(!s)return;if(s.removeAllRanges(),s.addRange(r),!i.trim())return e.remove(r),void(t!==l&&(r.deleteContents(),r.insertNode(document.createTextNode(t))));if(c){const e=c.parentElement;if(e){const t=document.createTextNode(c.textContent||"");e.insertBefore(t,c),e.removeChild(c),r.selectNode(t)}}if(t!==l){r.deleteContents();const e=document.createTextNode(t);r.insertNode(e),r.selectNode(e)}const p=a.createStyledElement("span",a.classNames.block.tooltip);p.setAttribute("data-tooltip",i),o.classNames&&a.applyClassNames(p,o.classNames),o.styles&&Object.entries(o.styles).forEach(([e,t])=>{if(void 0!==t){const n=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);p.style.setProperty(n,String(t))}});try{r.surroundContents(p)}catch{const e=r.extractContents();p.appendChild(e),r.insertNode(p)}t!==l&&p.textContent!==t&&(p.textContent=t),J(p,i,"above",n.classNames,n.styles);const d=p.closest('[contenteditable="true"]');d&&d.dispatchEvent(new Event("input",{bubbles:!0}))},styles:n.styles,text:l,tooltip:s}).show(),sr.updateStateFromRange(t)}static remove(t){const n=t.commonAncestorContainer,a=e.findTooltipSpan(n);if(a){const e=a.parentElement;if(!e)return;e.insertBefore(document.createTextNode(a.textContent||""),a),e.removeChild(a),t.selectNode(e)}sr.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findTooltipSpan(n)||t.cloneContents().querySelectorAll(`span.${a.classNames.block.tooltip}`).length>0}static initializeElements(e,t){e.querySelectorAll(`span.${a.classNames.block.tooltip}`).forEach(e=>{if(e instanceof HTMLElement&&(t.classNames&&a.applyClassNames(e,t.classNames),t.styles&&Object.entries(t.styles).forEach(([t,n])=>{if(void 0!==n){const a=t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);e.style.setProperty(a,String(n))}}),!e.hasAttribute("data-tooltip-initialized"))){const t=e.getAttribute("data-tooltip");t&&(J(e,t,"above"),e.setAttribute("data-tooltip-initialized","true"))}})}static findTooltipSpan(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if(e.classList.contains(a.classNames.block.tooltip))return e}return t.parentNode?e.findTooltipSpan(t.parentNode):null}},Z=class e{static{this.label="underline"}static{this.icon='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 4v7a6 6 0 0 0 12 0V4"/><path d="M4 20h16"/></svg>'}static{this.shortcut=k()}static apply(e){a.injectStyles("clepit-underline-styles",'\n/* Underline inline formatting styles */\n.clepit-toolbar-button strong,\n.clepit-toolbar-button em,\n.clepit-toolbar-button u,\n.clepit-toolbar-button code,\n.clepit-toolbar-button mark {\n font-size: inherit;\n font-weight: inherit;\n font-style: inherit;\n text-decoration: inherit;\n background: transparent;\n padding: 0;\n border-radius: 0;\n font-family: inherit;\n}\n\n/* Keep underline visual hint without changing size */\n.clepit-toolbar-button[data-tool="underline"] {\n text-decoration: underline;\n}\n');const t=document.createElement("u");e.surroundContents(t),sr.updateStateFromRange(e)}static remove(t){const n=e.findUnderlineElement(t.commonAncestorContainer);if(n){const e=n.parentElement;if(e){const a=document.createTextNode(n.textContent||"");e.insertBefore(a,n),e.removeChild(n),t.selectNode(a)}}else{const e=t.commonAncestorContainer;if(e.nodeType===Node.ELEMENT_NODE){const n=e.querySelectorAll("u");for(const e of n)if(t.intersectsNode(e)){const t=e.parentElement;t&&(t.insertBefore(document.createTextNode(e.textContent||""),e),t.removeChild(e))}}}sr.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findUnderlineElement(n)||t.cloneContents().querySelectorAll('u, [style*="text-decoration: underline"], [style*="text-decoration:underline"]').length>0}static findUnderlineElement(t){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if("U"===e.tagName)return e;if(window.getComputedStyle(e).textDecoration.includes("underline"))return e;if(e.style.textDecoration.includes("underline"))return e}return t.parentNode?e.findUnderlineElement(t.parentNode):null}},Y=["alert","audio","checklist","code","collapsible","collection","columns","date","delimiter","doc_card","embed","file","glance","header","image","latex","list","mermaid","openapi","paragraph","quote","sketch","table","toc","updates","video"],Q=["improve","shorten","lengthen","simplify","fix_grammar"],ee=()=>[w,E,Z,U,C,z,V,D,X],te="inline-toolbar",ne=class e{static{this.eventListenersMap=new WeakMap}static{this.hideTimeoutMap=new Map}static{this.tooltipAnchorSeq=0}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap.get(t)||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap.set(t,i)}static create(t){const n=l.getState().getInstance(t);if(!n)return console.error("InlineToolbar::create: Instance not found for containerId:",t);const o=document.getElementById(t);if(!o)return console.error("InlineToolbar::create: Container not found for containerId:",t);e.eventListenersMap.has(o)||e.eventListenersMap.set(o,[]),a.injectStyles("clepit-inline-toolbar-styles","\n/* Inline Toolbar */\n.clepit-toolbar {\n position: absolute;\n z-index: 1002;\n background: var(--clepit-toolbar-bg, var(--clepit-bg));\n border: var(--clepit-toolbar-border, 1px solid var(--clepit-border));\n border-radius: 8px;\n padding: 8px;\n box-shadow: var(--clepit-toolbar-shadow, 0 2px 8px rgba(0, 0, 0, 0.1));\n backdrop-filter: blur(8px);\n display: none;\n transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);\n white-space: nowrap;\n will-change: transform;\n}\n\n.clepit-toolbar--layout {\n display: flex;\n flex-direction: row;\n gap: 0px;\n align-items: center;\n}\n\n.clepit-toolbar--hidden {\n display: none !important;\n}\n\n.clepit-toolbar--visible {\n display: flex !important;\n transform: translateY(0) scale(1) !important;\n}\n\n@keyframes toolbarFadeIn {\n from {\n opacity: 0;\n transform: translateY(-10px) scale(0.95);\n }\n to {\n opacity: 1;\n transform: translateY(0) scale(1);\n }\n}\n\n.clepit-toolbar-button {\n width: 24px;\n height: 24px;\n border: none;\n border-radius: 4px;\n background: transparent;\n color: var(--clepit-toolbar-color, var(--clepit-text));\n font-size: 12px;\n font-weight: bold;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);\n position: relative;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;\n line-height: 1;\n /* Ensure all content inside buttons inherits the same font size and styling */\n text-rendering: optimizeLegibility;\n will-change: transform, background-color, color;\n}\n\n/* Normalize SVG icon sizing in toolbar buttons */\n.clepit-toolbar-button svg {\n width: 14px;\n height: 14px;\n display: block;\n stroke: currentColor;\n}\n\n.clepit-toolbar-button:hover {\n background: var(--clepit-toolbar-hover-bg, var(--clepit-selection-bg));\n color: var(--clepit-toolbar-hover-color, var(--clepit-text));\n transform: scale(1.05);\n}\n\n.clepit-toolbar-button:active {\n transform: scale(0.95);\n transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n.clepit-toolbar-button.active {\n background: var(--clepit-toolbar-active-bg, var(--clepit-primary-bg));\n color: var(--clepit-toolbar-active-color, var(--clepit-primary));\n font-weight: bold;\n}\n\n/* Ensure consistent base font size for character-based icons */\n.clepit-toolbar-button { font-size: 12px; }\n\n/* Tooltip styles */\n/* Anchored to its own button and shown by :hover / :focus-visible, so no\n * JavaScript measures or centres it. :focus-visible is not decoration: the old\n * mouseenter-only version was invisible to a keyboard user.\n *\n * Guarded by @supports — anchor positioning is Baseline 2026 at ~91%. Without\n * it the tooltip simply never shows, which is what it already did before this\n * change for anyone not using a mouse. */\n.clepit-toolbar-tooltip {\n position: absolute;\n display: none;\n z-index: 9999;\n pointer-events: none;\n}\n\n@supports (anchor-name: --a) {\n .clepit-toolbar-tooltip {\n position: fixed;\n position-area: top;\n margin-block-end: 8px;\n justify-self: anchor-center;\n opacity: 0;\n transform: translateY(8px);\n transition:\n opacity 0.15s ease-in-out,\n transform 0.15s ease-in-out,\n display 0.15s allow-discrete;\n }\n\n .clepit-toolbar-button:hover + .clepit-toolbar-tooltip,\n .clepit-toolbar-button:focus-visible + .clepit-toolbar-tooltip,\n .clepit-toolbar-button:focus-visible + .clepit-toolbar-tooltip {\n display: block;\n opacity: 1;\n transform: translateY(0);\n }\n\n @starting-style {\n .clepit-toolbar-button:hover + .clepit-toolbar-tooltip,\n .clepit-toolbar-button:focus-visible + .clepit-toolbar-tooltip {\n opacity: 0;\n transform: translateY(8px);\n }\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .clepit-toolbar-tooltip {\n transition-duration: 0s;\n }\n}\n\n.clepit-toolbar-tooltip-content {\n white-space: nowrap;\n font-size: 12px;\n font-weight: 500;\n color: var(--clepit-bg);\n background-color: var(--clepit-text);\n padding: 6px 10px;\n border-radius: 6px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);\n transition: transform 0.2s ease-in-out;\n}\n\n.clepit-toolbar-tooltip-arrow {\n position: absolute;\n top: 100%;\n left: 50%;\n margin-left: -4px;\n width: 0;\n height: 0;\n border-left: 4px solid transparent;\n border-right: 4px solid transparent;\n border-top: 4px solid var(--clepit-text);\n}\n\n.clepit-toolbar-tooltip--hidden {\n display: none;\n transform: translateY(8px);\n}\n\n.clepit-toolbar-tooltip--visible {\n display: block;\n transform: translateY(0);\n}\n\n.clepit-toolbar-tooltip--fade-out {\n transform: translateY(5px);\n}\n\n/* Toolbar positioning and animation classes */\n.clepit-toolbar--positioned {\n position: absolute;\n}\n\n.clepit-toolbar--measurement {\n display: flex;\n visibility: hidden;\n opacity: 0;\n position: absolute;\n left: -9999px;\n top: -9999px;\n}\n\n.clepit-toolbar--show-animation {\n display: flex;\n visibility: visible;\n transform: translateY(-10px) scale(0.95);\n transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n.clepit-toolbar--show-animation.clepit-toolbar--visible {\n transform: translateY(0) scale(1);\n}\n\n.clepit-toolbar--position-animation {\n transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), top 0.3s cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n.clepit-toolbar--hide-animation {\n transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);\n transform: translateY(-5px) scale(0.98);\n}\n\n/* Rewrite menu — the sparkle-wand's action list, anchored under the toolbar */\n.clepit-toolbar-rewrite-menu {\n position: absolute;\n top: 100%;\n right: 0;\n margin-top: 4px;\n flex-direction: column;\n min-width: 160px;\n padding: 4px;\n border-radius: var(--clepit-radius-sm, 6px);\n background: var(--clepit-surface, #fff);\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);\n z-index: 2;\n}\n\n.clepit-toolbar-rewrite-item {\n appearance: none;\n border: 0;\n background: transparent;\n color: var(--clepit-text-primary, inherit);\n font: inherit;\n text-align: start;\n padding: 6px 10px;\n border-radius: var(--clepit-radius-xs, 4px);\n cursor: pointer;\n}\n\n.clepit-toolbar-rewrite-item:hover,\n.clepit-toolbar-rewrite-item:focus-visible {\n background: var(--clepit-surface-hover, rgba(0, 0, 0, 0.06));\n}\n\n/* The wand stays put while a rewrite is in flight, so the toolbar does not\n reflow under the pointer mid-request. */\n.clepit-toolbar-button.busy {\n opacity: 0.5;\n pointer-events: none;\n}\n\n/* Responsive */\n@media (max-width: 768px) {\n .clepit-toolbar {\n flex-wrap: wrap;\n max-width: 200px;\n }\n}\n");const i=B("div","clepit-toolbar");i.id=`${t}-${te}`,i.classList.add("clepit-toolbar--hidden","clepit-toolbar--layout"),a.applyStyling(i,{classNames:n.config.classNames?.inlineToolbar?.container,styles:n.config.styles?.inlineToolbar?.container}),o.appendChild(i)}static repaint(t,n){const o=l.getState().getInstance(t);if(!o)return console.error("InlineToolbar::repaint: Instance not found for containerId:",t);if(!e.getElementFromContainerId(t))return console.error("InlineToolbar::repaint: Toolbar not found for containerId:",t);e.clearButtons(t);const i=((n.commonAncestorContainer.nodeType===Node.ELEMENT_NODE?n.commonAncestorContainer:n.commonAncestorContainer.parentElement)?.closest(`.${a.classNames.block.container}`))?.getAttribute("data-tool");e.getFilteredTools(i).forEach(a=>e.addButton(t,a,n)),o.config.onInlineRewrite&&e.addRewriteButton(t,n);const r=n.getBoundingClientRect(),s=document.getElementById(o.config.containerId)?.getBoundingClientRect();if(!s)return;const c=((e=!1)=>({height:40,width:24*(ee().length+(e?1:0))+16}))(Boolean(o.config.onInlineRewrite)),p=r.left-s.left+r.width/2-c.width/2;let d=r.top-s.top-c.height-8;d<0&&(d=r.bottom-s.top+8),e.show(o.config.containerId,p,d)}static addRewriteButton(t,n){const o=l.getState().getInstance(t),i=o?.config.onInlineRewrite;if(!o||!i)return;const r=e.getElementFromContainerId(t),s=document.getElementById(t);if(!r||!s)return;const c=B("button","clepit-toolbar-button",{type:"button"});c.innerHTML='<svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor" aria-hidden="true"><path d="M12 2l1.6 4.4L18 8l-4.4 1.6L12 14l-1.6-4.4L6 8l4.4-1.6L12 2zm6 10l.9 2.5L21 15l-2.1.8L18 18l-.9-2.2L15 15l2.1-.5L18 12zM6 13l1.1 3L10 17l-2.9 1L6 21l-1.1-3L2 17l2.9-1L6 13z"/></svg>',c.setAttribute("data-tool","rewrite"),a.applyStyling(c,{classNames:o.config.classNames?.inlineToolbar?.button,styles:o.config.styles?.inlineToolbar?.button});const p=B("div","clepit-toolbar-rewrite-menu");p.style.display="none",p.setAttribute("data-rewrite-menu","true");for(const a of Q){const t=B("button","clepit-toolbar-rewrite-item",{type:"button"});t.textContent=o.config.inlineRewriteLabels?.[a]??a,t.setAttribute("data-rewrite-action",a),e.addEventListener(s,t,"mousedown",e=>e.preventDefault()),e.addEventListener(s,t,"click",()=>{p.style.display="none";const e=window.getSelection(),t=e&&e.rangeCount>0?e.getRangeAt(0):null,o=t&&!t.collapsed?t:n,r=o.toString();r.trim()&&(c.classList.add("busy"),i(r,a).then(e=>{e&&(o.deleteContents(),o.insertNode(document.createTextNode(e)),s.dispatchEvent(new Event("input",{bubbles:!0})))}).catch(()=>{}).finally(()=>c.classList.remove("busy")))}),p.appendChild(t)}e.addEventListener(s,c,"mousedown",e=>e.preventDefault()),e.addEventListener(s,c,"click",()=>{p.style.display="none"===p.style.display?"flex":"none"}),r.appendChild(c),e.createTooltip(r,c,"rewrite"),r.appendChild(p)}static addButton(t,n,o){const i=l.getState().getInstance(t);if(!i)return console.error("InlineToolbar::addButton: Instance not found for containerId:",t);const r=e.getElementFromContainerId(t);if(!r)return console.error("InlineToolbar::addButton: Toolbar not found for containerId:",t);const s=B("button","clepit-toolbar-button",{type:"button"});s.innerHTML=n.icon,a.applyStyling(s,{classNames:i.config.classNames?.inlineToolbar?.button,styles:i.config.styles?.inlineToolbar?.button}),n.isActive(o)&&s.classList.add("active"),s.setAttribute("data-tool",n.label.toLowerCase());const c=document.getElementById(t);c&&(e.addEventListener(c,s,"mousedown",e=>e.preventDefault()),e.addEventListener(c,s,"click",()=>{try{const e=window.getSelection(),t=e&&e.rangeCount>0?e.getRangeAt(0):null,a=t&&!t.collapsed?t:o;if(a&&n.isActive(a))n.remove(a),s.classList.remove("active");else if(a){switch(n.label){case"italic":E.apply(a);break;case"bold":w.apply(a);break;case"underline":Z.apply(a);break;case"strikethrough":U.apply(a);break;case"inlineCode":C.apply(a,i.config.classNames?.blocks?.["inline-code"],i.config.styles?.blocks?.["inline-code"]);break;case"marker":z.apply(a,i.config.classNames?.blocks?.marker,i.config.styles?.blocks?.marker);break;case"status":V.apply(a,i.config.classNames?.dialogs,i.config.styles?.dialogs);break;case"link":D.apply(a,i.config.classNames?.dialogs,i.config.styles?.dialogs);break;case"tooltip":X.apply(a,{classNames:i.config.classNames?.tooltips,styles:i.config.styles?.tooltips},{classNames:i.config.classNames?.blocks?.tooltip,styles:i.config.styles?.blocks?.tooltip})}s.classList.add("active")}}catch(e){console.warn("Error applying inline tool:",e)}})),r.appendChild(s),e.createTooltip(r,s,n.label)}static createTooltip(t,n,a){const o=B("div","clepit-toolbar-tooltip clepit-toolbar-tooltip--hidden"),i=B("div","clepit-toolbar-tooltip-content");i.textContent=a;const r=B("div","clepit-toolbar-tooltip-arrow");i.appendChild(r),o.appendChild(i),n.insertAdjacentElement("afterend",o);const s="--clepit-inline-tool-"+e.tooltipAnchorSeq++;n.style.setProperty("anchor-name",s),o.style.setProperty("position-anchor",s),o.classList.remove("clepit-toolbar-tooltip--hidden")}static clearButtons(t){const n=e.getElementFromContainerId(t);if(!n)return console.error("InlineToolbar::clearButtons: Toolbar not found for containerId:",t);n.querySelectorAll(".clepit-toolbar-button").forEach(e=>e.remove()),n.querySelectorAll(".clepit-toolbar-tooltip").forEach(e=>e.remove())}static show(t,n,a){const o=e.getElementFromContainerId(t);if(!o)return console.error("InlineToolbar::show: Toolbar not found for containerId:",t);if(e.cancelPendingHide(t),o.classList.remove("clepit-toolbar--hidden"),o.classList.add("clepit-toolbar--visible"),o.classList.contains("clepit-toolbar--visible")){const e=parseFloat(o.style.left)||0,t=parseFloat(o.style.top)||0;(Math.abs(e-n)>1||Math.abs(t-a)>1)&&o.classList.add("clepit-toolbar--position-animation")}else o.classList.add("clepit-toolbar--show-animation");o.style.left=`${n}px`,o.style.top=`${a}px`,requestAnimationFrame(()=>{o.classList.add("clepit-toolbar--visible")})}static hide(t){const n=e.getElementFromContainerId(t);if(n)if(e.cancelPendingHide(t),n.classList.contains("clepit-toolbar--visible")){n.classList.add("clepit-toolbar--hide-animation");const a=setTimeout(()=>{n.classList.remove("clepit-toolbar--visible","clepit-toolbar--hide-animation"),n.classList.add("clepit-toolbar--hidden"),e.hideTimeoutMap.delete(t)},200);e.hideTimeoutMap.set(t,a)}else n.classList.remove("clepit-toolbar--visible"),n.classList.add("clepit-toolbar--hidden")}static cancelPendingHide(t){const n=e.hideTimeoutMap.get(t);void 0!==n&&(clearTimeout(n),e.hideTimeoutMap.delete(t))}static getElementFromContainerId(e){const t=document.querySelector(`#${e}`);return t?t.querySelector(`#${t.id}-${te}`):(console.error("InlineToolbar::getElementFromContainerId: Container not found for containerId:",e),null)}static getFilteredTools(e){return"header"===e?ee().filter(e=>"bold"!==e.label):ee()}static destroy(t){e.cancelPendingHide(t);const n=document.querySelector(`#${t}`);if(!n)return;const a=e.eventListenersMap.get(n);a&&(a.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap.delete(n));const o=n.querySelector(`#${t}-${te}`);if(!o)return console.warn("InlineToolbar::destroy: Toolbar not found for containerId:",t);o.remove()}};function ae(e){const t=e.toLowerCase();return[".jpg",".jpeg",".png",".gif",".webp",".svg",".bmp",".tiff",".ico"].some(e=>t.includes(e))||t.includes("data:image/")||t.includes("blob:")}function oe(e){const t=e.toLowerCase();return[".mp4",".webm",".ogg",".mov",".avi",".mkv",".flv",".wmv",".m4v"].some(e=>t.includes(e))||t.includes("data:video/")||t.includes("blob:")}function ie(e){const t=e.toLowerCase();return t.includes("youtube.com")||t.includes("youtu.be")}function re(e){return e.toLowerCase().includes("vimeo.com")}function se(e){const t=e.trim();if(!function(e){try{return new URL(e),!0}catch{return!1}}(t))return{isImage:!1,isUrl:!1,isVideo:!1,isVimeo:!1,isYouTube:!1,url:t};const n=ie(t),a=re(t);return{isImage:ae(t),isUrl:!0,isVideo:oe(t)||n||a,isVimeo:a,isYouTube:n,url:t}}var le=class e{static addListeners(t){const n=document.getElementById(t);if(!n)return console.error("EventManager::addListeners: Container not found for containerId:",t);document.addEventListener("selectionchange",e.handleSelectionChange),document.addEventListener("paste",e.handlePaste),n.addEventListener("click",e.handleClick)}static removeListeners(t){const n=document.getElementById(t);n&&(document.removeEventListener("selectionchange",e.handleSelectionChange),document.removeEventListener("paste",e.handlePaste),n.removeEventListener("click",e.handleClick))}static getInstanceAndTargetFromRange(e){const t=e.commonAncestorContainer,n=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement;if(!n)return null;const o=n.closest(`.${a.classNames.editor.content}`);if(!o)return null;const i=o.getAttribute("data-container-id");if(!i)return null;const r=l.getState().getInstance(i);return r?{instance:r,target:n}:null}static handleClick(e){const t=e.currentTarget,n=e.target,o=n.closest(`.${a.classNames.block.link}`);if(o){const e=document.createRange();e.selectNodeContents(o);const n=l.getState().getInstance(t.id);return void(n&&D.apply(e,n.config.classNames?.dialogs,n.config.styles?.dialogs))}const i=n.closest(`.${a.classNames.block.tooltip}`);if(i){const e=document.createRange();e.selectNodeContents(i);const n=l.getState().getInstance(t.id);return void(n&&X.apply(e,{classNames:n.config.classNames?.tooltips,styles:n.config.styles?.tooltips},{classNames:n.config.classNames?.blocks?.tooltip,styles:n.config.styles?.blocks?.tooltip}))}}static handleSelectionChange(){const t=window.getSelection();if(!t||0===t.rangeCount)return;const n=t.getRangeAt(0),a=e.getInstanceAndTargetFromRange(n);if(!a)return;if("edit"!==a.instance.currentView){try{ne.hide(a.instance.config.containerId)}catch{}return}if(null!==document.querySelector(".clepit-dialog-overlay"))return;const o=t?.toString().trim();if(o&&o.length>0||t&&t.rangeCount>0&&!t.getRangeAt(0).collapsed)try{ne.repaint(a.instance.config.containerId,n)}catch{}else try{ne.hide(a.instance.config.containerId)}catch{}}static handlePaste(e){e.preventDefault();const t=e.clipboardData;if(!t)return;const n=t.getData("text/plain");if(!n)return;const o=se(n);if(!o.isUrl)return;const i=document.activeElement;if(!i)return;const r=i.closest(`.${a.classNames.block.container}`);if(!r)return;const s=r.closest(`.${a.classNames.editor.container}`);if(!s)return;const l=r.getAttribute("data-id"),c=sr.getBlockIndex(s.id,l);if(-1===c)return;const p=sr.getTool(r.getAttribute("data-tool"));if(!p)return;const d=p.input.isEmpty(r);if(o.isImage){const e={data:{alignment:"center",alt:"Image",caption:"",url:o.url},type:"image"};d?sr.replaceBlock(s.id,c,e):sr.insertBlock(e,s.id,c+1)}else if(o.isVideo){let e=o.url;o.isYouTube?e=function(e){const t=function(e){for(const t of[/(?:youtube\.com\/watch\?v=|youtu\.be\/)([^&\n?#]+)/,/youtube\.com\/embed\/([^&\n?#]+)/]){const n=e.match(t);if(n)return n[1]}return null}(e);return t?`https://www.youtube.com/embed/${t}`:null}(o.url)||o.url:o.isVimeo&&(e=function(e){const t=function(e){for(const t of[/vimeo\.com\/(\d+)/,/player\.vimeo\.com\/video\/(\d+)/]){const n=e.match(t);if(n)return n[1]}return null}(e);return t?`https://player.vimeo.com/video/${t}`:null}(o.url)||o.url);const t={data:{alignment:"center",alt:"Video",caption:"",url:e},type:"video"};d?sr.replaceBlock(s.id,c,t):sr.insertBlock(t,s.id,c+1)}}},ce="\n/* Output alert styles */\n.clepit-output-alert {\n padding: 12px 16px;\n border-radius: 4px;\n font-size: 14px;\n line-height: 1.5;\n margin: 1rem 0;\n}\n\n.clepit-output-alert--info {\n background: var(--clepit-primary-bg);\n color: var(--clepit-primary-hover);\n}\n\n.clepit-output-alert--warning {\n background: var(--clepit-warning-bg);\n color: var(--clepit-warning);\n}\n\n.clepit-output-alert--error {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n}\n\n.clepit-output-alert--success {\n background: var(--clepit-success-bg);\n color: var(--clepit-success);\n}\n\n.clepit-output-alert--plain {\n background: transparent;\n color: inherit;\n}\n\n.clepit-output-alert-content {\n line-height: 1.5;\n}\n\n/* Output alert link styles */\n.clepit-output-alert a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-output-alert a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Output alert inline code styling */\n.clepit-output-alert code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Output alert marker brush effect */\n.clepit-output-alert mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n\n.clepit-output-alert mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1;\n}\n",pe=class e{static{this.placeholder="Alert message here..."}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.querySelector(`.${a.classNames.block.alert}`)||e,n=t.getAttribute("data-variant")||"info";return{html:I(t.innerHTML),variant:n}}static render(t,n,o){a.injectStyles("clepit-alert-input-styles","\n/* Alert block styles */\n.clepit-alert {\n padding: 12px 16px;\n border-radius: 4px;\n font-size: 14px;\n line-height: 1.5;\n margin: 0 20px;\n}\n\n.clepit-alert[data-variant=\"info\"] {\n background: var(--clepit-primary-bg);\n color: var(--clepit-primary-hover);\n}\n\n.clepit-alert[data-variant=\"warning\"] {\n background: var(--clepit-warning-bg);\n color: var(--clepit-warning);\n}\n\n.clepit-alert[data-variant=\"error\"] {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n}\n\n.clepit-alert[data-variant=\"success\"] {\n background: var(--clepit-success-bg);\n color: var(--clepit-success);\n}\n\n.clepit-alert[data-variant=\"plain\"] {\n background: transparent;\n color: inherit;\n}\n\n.clepit-alert-text {\n outline: none;\n margin: 0;\n padding: 0;\n}\n\n.clepit-alert[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: rgba(0, 0, 0, 0.6);\n font-style: italic;\n pointer-events: none;\n}\n\n/* Alert link styles */\n.clepit-alert-text a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-alert-text a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Alert inline code styling */\n.clepit-alert-text code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Alert marker brush effect */\n.clepit-alert-text mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0; /* create stacking context so ::before sits behind text, not page */\n white-space: pre-wrap; /* ensure leading/trailing spaces inside mark render */\n}\n\n.clepit-alert-text mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1; /* behind text but within mark's stacking context */\n}\n\n");const i={html:"",variant:"info"},r=n?{...i,...n}:i,s=a.createStyledElement("div","clepit-alert",{classNames:o?.classNames?.[r.variant],styles:o?.styles?.[r.variant]});return s.setAttribute("data-variant",r.variant),s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder",e.placeholder),r.html?s.innerHTML=r.html:s.innerHTML="",e.addEventListener(t,s,"keydown",sr.handleKeydown),e.addEventListener(t,s,"input",sr.handleInput),s}static changeVariant(t,n,o){const i=l.getState().getInstance(o);if(!i)return;if(t.getAttribute("data-variant")===n)return;const r=t.innerHTML||"",s={html:r.trim()&&"<br>"!==r.trim()?r:"",variant:n},c={classNames:i.config.classNames?.blocks?.alert,margins:i.config.margins,styles:i.config.styles?.blocks?.alert},p=sr.getBlockIndex(o,t.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id")),d=e.render(o,s,c);t.replaceWith(d),l.getState().updateBlockData(o,p,s)}static isEmpty(e){return M(e.querySelector(`.${a.classNames.block.alert}`)?.innerHTML)}static isEmptyData(e){return M(e.html)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},de=class{constructor(e){this.node=e}get tag(){return this.node.tagName.toLowerCase()}setAttribute(e,t){this.node.setAttribute(e,t)}addClass(...e){this.node.classList.add(...e.filter(Boolean))}setText(e){this.node.textContent=e}setHtml(e){this.node.innerHTML=e}append(e){this.node.appendChild(e.node)}appendText(e){this.node.appendChild(document.createTextNode(e))}},ue={create:e=>new de(document.createElement(e)),createNS:(e,t)=>new de(document.createElementNS(e,t))},me=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),he=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),ge=e=>e.replace(/&/g,"&amp;").replace(/"/g,"&quot;"),be=class{constructor(e,t){this.tag=e,this.sanitize=t,this.attributes=new Map,this.classes=[],this.children=[]}setAttribute(e,t){this.attributes.set(e,t)}addClass(...e){for(const t of e.filter(Boolean))this.classes.includes(t)||this.classes.push(t)}setText(e){this.children.length=0,this.children.push(he(e))}setHtml(e){this.children.length=0,this.children.push(this.sanitize(e))}append(e){this.children.push(e.toString())}appendText(e){this.children.push(he(e))}toString(){const e=[...this.classes.length>0?[`class="${ge(this.classes.join(" "))}"`]:[],...[...this.attributes].map(([e,t])=>`${e}="${ge(t)}"`)],t=[this.tag,...e].join(" ");return me.has(this.tag)?`<${t}>`:`<${t}>${this.children.join("")}</${this.tag}>`}},fe=e=>({create:t=>new be(t,e),createNS:(t,n)=>new be(n,e)}),ye=e=>String(e),ve=e=>{if(!(e instanceof de))throw new TypeError("toDomElement needs an element built by the dom backing");return e.node};function xe(){a.injectStyles("clepit-invalid-data-styles","\n/* Invalid data component styles */\n.clepit-invalid-data {\n padding: 12px 16px;\n border-radius: 4px;\n font-size: 14px;\n line-height: 1.5;\n margin: 1rem 0;\n background: #ffebee;\n color: #c62828;\n}\n\n.clepit-invalid-data-text {\n font-weight: bold;\n margin: 0;\n padding: 0;\n}\n");const e=B("div","clepit-invalid-data"),t=B("div","clepit-invalid-data-text");return t.textContent="Invalid data",e.appendChild(t),e}var ke=class e{static render(t,n,o,i){if(a.injectStyles("clepit-alert-output-styles",ce),!e.validate(t))return xe();if(pe.isEmptyData(t))return document.createElement("div");const r=t.html,s=t.variant,l=a.createStyledElement("div",`clepit-output-alert clepit-output-alert--${s}`,{classNames:i?.[s],styles:o?.[s]});return r&&(l.innerHTML=r),l}static draw(t,n=ue){if(!e.validate(t)||pe.isEmptyData(t))return null;const a=n.create("div");return a.addClass("clepit-output-alert",`clepit-output-alert--${t.variant}`),t.html&&a.setHtml(t.html),a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"variant"in e&&"html"in e&&"string"==typeof e.html}},we={icon:"!",get input(){return pe},label:"Alert",get output(){return ke},shortcut:v("A"),testId:"block-type-alert",type:"alert"},Ce=`\n/* Audio block styles */\n.clepit-audio-container {\n margin: 0 16px;\n text-align: center;\n min-height: 120px;\n position: relative;\n display: block;\n width: 96%;\n box-sizing: border-box;\n}\n\n.${a.classNames.block.audio.wrapper} {\n display: flex;\n position: relative;\n cursor: pointer;\n transition: opacity 0.2s ease;\n outline: none;\n}\n\n.clepit-audio {\n width: 100%;\n}\n\n.align-left {\n justify-content: flex-start;\n}\n\n.align-center {\n justify-content: center;\n}\n\n.align-right {\n justify-content: flex-end;\n}\n\n.${a.classNames.block.audio.wrapper}:hover {\n opacity: 0.9;\n}\n\n.clepit-audio-caption-container {\n margin-top: 12px;\n text-align: center;\n}\n\n.clepit-audio-caption-label {\n font-size: 12px;\n color: var(--clepit-text-muted);\n margin-bottom: 4px;\n font-weight: 500;\n}\n\n.clepit-audio-caption-input {\n width: 100%;\n max-width: 400px;\n padding: 8px 12px;\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n font-size: 14px;\n background: var(--clepit-bg);\n outline: none;\n transition: border-color 0.2s ease;\n pointer-events: auto;\n user-select: text;\n}\n\n.clepit-audio-caption-input:focus {\n border-color: var(--clepit-primary);\n box-shadow: 0 0 0 2px var(--clepit-primary-bg);\n}\n\n/* Audio caption styling */\n.clepit-audio-caption-editable {\n border: 1px solid var(--clepit-border-subtle);\n border-radius: 4px;\n padding: 8px 12px;\n min-height: 40px;\n font-size: 14px;\n line-height: 1.4;\n outline: none;\n transition: border-color 0.2s ease;\n}\n\n/* Audio caption placeholder styles */\n.clepit-audio-caption-editable[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Audio Drop Area */\n.clepit-audio-drop-area {\n border: 2px dashed var(--clepit-border);\n border-radius: 8px;\n padding: 40px 20px;\n text-align: center;\n background: var(--clepit-surface);\n cursor: pointer;\n transition: all 0.2s ease;\n margin: 16px 0;\n user-select: none;\n pointer-events: auto;\n outline: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n position: relative;\n}\n\n.clepit-audio-drop-area:hover {\n border-color: var(--clepit-primary);\n background: var(--clepit-surface);\n}\n\n.clepit-audio-drop-area--dragover {\n border-color: var(--clepit-primary);\n background: var(--clepit-primary-bg);\n transform: scale(1.02);\n}\n\n.clepit-audio-drop-icon {\n font-size: 48px;\n margin-bottom: 16px;\n opacity: 0.6;\n}\n\n.clepit-audio-drop-text {\n font-size: 16px;\n color: var(--clepit-text-muted);\n line-height: 1.5;\n margin-bottom: 8px;\n}\n\n.clepit-audio-drop-subtext {\n font-size: 14px;\n color: var(--clepit-text-subtle);\n line-height: 1.4;\n}\n\n.clepit-audio-click-text {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n}\n\n/* Audio Loading State */\n.clepit-audio-loading {\n text-align: center;\n padding: 40px 20px;\n margin: 16px 0;\n}\n\n.clepit-audio-loading-spinner {\n width: 32px;\n height: 32px;\n border: 3px solid var(--clepit-surface);\n border-top: 3px solid var(--clepit-primary);\n border-radius: 50%;\n animation: spin 1s linear infinite;\n margin: 0 auto 16px;\n}\n\n@keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n}\n\n.clepit-audio-loading-text {\n font-size: 14px;\n color: var(--clepit-text-muted);\n}\n\n/* Audio Error State */\n.clepit-audio-error {\n text-align: center;\n padding: 20px;\n margin: 16px 0;\n border: 1px solid var(--clepit-error);\n border-radius: 8px;\n background: var(--clepit-error-bg);\n}\n\n.clepit-audio-error-icon {\n font-size: 24px;\n margin-bottom: 8px;\n}\n\n.clepit-audio-error-text {\n font-size: 14px;\n color: var(--clepit-error);\n margin-bottom: 12px;\n}\n\n.clepit-audio-error-retry {\n background: var(--clepit-error);\n color: white;\n border: none;\n padding: 8px 16px;\n border-radius: 4px;\n cursor: pointer;\n font-size: 14px;\n transition: background-color 0.2s ease;\n}\n\n.clepit-audio-error-retry:hover {\n background: var(--clepit-error);\n}\n\n/* Audio delete button */\n.${a.classNames.block.audioDeleteBtn} {\n position: absolute;\n top: 8px;\n right: 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 50%;\n width: 24px;\n height: 24px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: var(--clepit-bg);\n cursor: pointer;\n color: var(--clepit-text-muted);\n transition: color 0.2s ease;\n}\n\n.${a.classNames.block.audioDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Audio drop area delete button */\n.clepit-audio-drop-area .${a.classNames.block.audioDeleteBtn} {\n position: absolute;\n top: 8px;\n right: 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 50%;\n width: 24px;\n height: 24px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: var(--clepit-bg);\n cursor: pointer;\n color: var(--clepit-text-muted);\n transition: color 0.2s ease;\n}\n\n.clepit-audio-drop-area .${a.classNames.block.audioDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Drop area positioning */\n.clepit-drop-area {\n position: relative;\n}\n\n/* Hidden input */\n.clepit-hidden-input {\n display: none;\n}\n\n`,Ee="\n/* Output audio styles */\n.clepit-output-audio-container {\n width: 100%;\n margin: 1rem 0;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: flex-start;\n}\n\n.clepit-output-audio-wrapper {\n width: 100%;\n display: flex;\n}\n\n.clepit-output-audio {\n width: 100%;\n}\n\n\n.clepit-output-audio-caption {\n margin-top: 0.5rem;\n font-size: 0.875rem;\n color: var(--clepit-text-muted);\n font-style: italic;\n text-align: center;\n}\n\n/* Output audio alignment */\n.clepit-output-audio-wrapper--left {\n justify-content: flex-start;\n}\n\n.clepit-output-audio-wrapper--center {\n justify-content: center;\n}\n\n.clepit-output-audio-wrapper--right {\n justify-content: flex-end;\n}\n",Se=class e{static{this.placeholder="Add a caption..."}static{this.eventListenersMap={}}static{this.validTypes=["audio/mp3","audio/wav","audio/ogg","audio/mpeg","audio/mp4","audio/webm"]}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.querySelector("audio"),n=e.querySelector(`.${a.classNames.block.audio.captionEditable}`),o=e.querySelector(`.${a.classNames.block.audio.wrapper}`);let i="center";return o&&(i=o.classList.contains("align-left")?"left":o.classList.contains("align-right")?"right":"center"),{alignment:i,alt:t&&t.getAttribute("alt")||"",caption:I(n?.innerHTML),url:t&&t.getAttribute("src")||""}}static render(t,n,o,i){a.injectStyles("clepit-audio-input-styles",Ce);const r=o||{alt:"",caption:"",url:""},s=a.createStyledElement("div",a.classNames.block.audio.container,{classNames:i?.classNames?.container,styles:i?.styles?.container});return r.url?e.renderAudio(s,r,t,n,i):e.renderDropArea(s,t,n,i),s}static renderAudio(t,n,o,i,r){if(!document.getElementById(i))return;t.innerHTML="";const s=a.createStyledElement("div",a.classNames.block.audio.wrapper,{classNames:r?.classNames?.container,styles:r?.styles?.container});switch(s.setAttribute("tabindex","-1"),n?.alignment||"center"){case"left":s.classList.add("align-left");break;case"center":s.classList.add("align-center");break;case"right":s.classList.add("align-right")}const l=a.createStyledElement("audio","clepit-audio",{classNames:r?.classNames?.container,styles:r?.styles?.container});l.src=n.url,l.controls=!0,l.preload="metadata",n.alt&&l.setAttribute("alt",n.alt);const c=a.createStyledElement("div","clepit-audio-caption-container",{classNames:r?.classNames?.container,styles:r?.styles?.container});c.classList.add("clepit-audio-caption-container");const p=a.createStyledElement("div","clepit-audio-caption-editable",{classNames:r?.classNames?.caption,styles:r?.styles?.caption});p.setAttribute("contenteditable","true"),p.setAttribute("data-placeholder",e.placeholder),p.innerHTML=n.caption||"",e.addEventListener(i,p,"keydown",sr.handleKeydown),e.addEventListener(i,p,"input",sr.handleInput),e.addEventListener(i,s,"click",()=>e.handleFileSelect(t,o,i,r)),s.appendChild(l),c.appendChild(p),t.appendChild(s),t.appendChild(c),p.focus()}static renderDropArea(t,n,o,i){t.innerHTML="";const r=a.createStyledElement("div",a.classNames.block.audio.dropArea,{classNames:i?.classNames?.dropArea?.container,styles:i?.styles?.dropArea?.container});r.setAttribute("tabindex","0"),r.classList.add("clepit-drop-area");const s=a.createStyledElement("div","clepit-audio-drop-icon",{classNames:i?.classNames?.dropArea?.icon,styles:i?.styles?.dropArea?.icon});s.textContent="♪";const c=a.createStyledElement("div","clepit-audio-drop-text",{classNames:i?.classNames?.dropArea?.text,styles:i?.styles?.dropArea?.text});c.innerHTML='<strong>Drop an audio file here</strong><br>or <span class="clepit-audio-click-text">click to select</span>';const p=a.createStyledElement("div","clepit-audio-drop-subtext",{classNames:i?.classNames?.dropArea?.subtext,styles:i?.styles?.dropArea?.subtext});p.textContent="Supports MP3, WAV, OGG, and other audio formats";const d=a.createStyledElement("button",`${a.classNames.block.audioDeleteBtn}`,{classNames:i?.classNames?.dropArea?.deleteButton,styles:i?.styles?.dropArea?.deleteButton});d.type="button",d.textContent="✕",r.appendChild(s),r.appendChild(c),r.appendChild(p),r.appendChild(d);const u=o?l.getState().getInstance(o):null,m=u?.config.classNames?.tooltips,h=u?.config.styles?.tooltips;J(d,"Delete block","below",m,h),e.addEventListener(o,d,"click",e=>{e.preventDefault(),e.stopPropagation();const t=d.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id");t&&sr.removeBlock(o,sr.getBlockIndex(o,t))}),e.addEventListener(o,r,"click",()=>e.handleFileSelect(t,n,o,i)),e.addEventListener(o,r,"dragleave",()=>{r.classList.remove("clepit-audio-drop-area--dragover")}),e.addEventListener(o,r,"dragover",e=>{e.preventDefault(),e.stopPropagation(),r.classList.add("clepit-audio-drop-area--dragover")}),e.addEventListener(o,r,"drop",a=>{a.preventDefault(),a.stopPropagation(),r.classList.remove("clepit-audio-drop-area--dragover"),e.handleFileDrop(a,t,n,o,i)}),e.addEventListener(o,r,"focus",e=>{e.preventDefault(),e.stopPropagation()}),e.addEventListener(o,r,"mousedown",e=>{e.preventDefault(),e.stopPropagation()}),t.appendChild(r)}static handleFileSelect(t,n,a,o){const i=document.createElement("input");i.type="file",i.accept="audio/*",i.style.display="none",i.addEventListener("change",()=>{const r=i.files;if(r&&r.length>0){const i=r[0];e.isValidAudioFile(i)?e.processAudioFile(i,t,n,a,o):e.showError(t,"Please select a valid audio file (MP3, WAV, OGG)")}}),document.body.appendChild(i),i.click(),document.body.removeChild(i)}static handleFileDrop(t,n,a,o,i){const r=t.dataTransfer?.files;if(r&&r.length>0){const t=r[0];e.isValidAudioFile(t)?e.processAudioFile(t,n,a,o,i):e.showError(n,"Please select a valid audio file (MP3, WAV, OGG)")}}static isValidAudioFile(t){return e.validTypes.includes(t.type)||t.type.startsWith("audio/")}static async processAudioFile(t,n,o,i,r){e.showLoading(n);try{let s=await o(t);if(s){e.renderAudio(n,{alignment:"center",alt:t.name,caption:"",url:s},o,i,r);const c=n.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id");c&&l.getState().updateBlockData(i,sr.getBlockIndex(i,c),sr.getBlockData(c).data)}else e.showError(n,"Failed to upload audio. Please try again.")}catch(s){console.error("Audio upload error:",s),e.showError(n,"Failed to upload audio. Please try again.")}}static showLoading(e){e.innerHTML="";const t=a.createStyledElement("div","clepit-audio-loading",void 0);t.textContent="Uploading audio...",e.appendChild(t)}static showError(e,t){e.innerHTML="";const n=a.createStyledElement("div","clepit-audio-error",void 0);n.textContent=t,e.appendChild(n)}static setAlignment(e,t){const n=e.querySelector(".clepit-audio-wrapper");n&&(n.classList.remove("align-left","align-center","align-right"),n.classList.add(`align-${t}`));const a=sr.getEditorId(e);if(!a)return;const o=e.getAttribute("data-id");o&&l.getState().partialUpdateBlockData(a,sr.getBlockIndex(a,o),{alignment:t})}static isEmpty(e){const t=e.querySelector(`.${a.classNames.block.audio.wrapper} audio`),n=e.querySelector(`.${a.classNames.block.audio.captionEditable}`);let o=!1,i=!1;return t&&t.getAttribute("src")?.trim()||(o=!0),n?M(n.innerHTML)&&(i=!0):i=!0,o&&i}static isEmptyData(e){return!e.url?.trim()&&M(e.caption)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Ne=class e{static render(t,n,o,i){if(a.injectStyles("clepit-audio-output-styles",Ee),!e.validate(t))return xe();if(Se.isEmptyData(t))return document.createElement("div");const r=t.url,s=t.caption,l=t.alignment||"center",c=a.createStyledElement("div","clepit-output-audio-container",{classNames:i?.container,styles:o?.container}),p=a.createStyledElement("div","clepit-output-audio-wrapper");switch(l){case"left":p.classList.add("clepit-output-audio-wrapper--left");break;case"center":p.classList.add("clepit-output-audio-wrapper--center");break;case"right":p.classList.add("clepit-output-audio-wrapper--right")}const d=B("audio","clepit-output-audio");if(d.src=r,d.controls=!0,d.preload="metadata",t.alt&&d.setAttribute("alt",t.alt),p.appendChild(d),c.appendChild(p),s){const e=a.createStyledElement("figcaption","clepit-output-audio-caption",{classNames:i?.caption,styles:o?.caption}),n=t.caption;e.innerHTML=n&&n!==s?n:s,c.appendChild(e)}if(o&&(o.container&&Object.assign(c.style,o.container),o.caption)){const e=c.querySelector(".clepit-output-audio-caption");e&&Object.assign(e.style,o.caption)}if(i&&(i.container&&c.classList.add(i.container),i.caption)){const e=c.querySelector(".clepit-output-audio-caption");e&&e.classList.add(i.caption)}return c}static draw(t,n=ue){if(!e.validate(t)||Se.isEmptyData(t))return null;const a=n.create("div");a.addClass("clepit-output-audio-container");const o=n.create("div");o.addClass("clepit-output-audio-wrapper");const i=t.alignment??"center";i&&o.addClass(`clepit-output-audio-wrapper--${i}`);const r=n.create("audio");if(r.addClass("clepit-output-audio"),r.setAttribute("src",t.url),r.setAttribute("controls","controls"),o.append(r),a.append(o),t.caption){const e=n.create("figcaption");e.addClass("clepit-output-audio-caption"),e.setHtml(t.caption),a.append(e)}return a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.url}},Ae={icon:"♪",get input(){return Se},label:"Audio",get output(){return Ne},shortcut:v("O"),testId:"block-type-audio",type:"audio"},Le=`\n/* Checklist input block styles */\n.${a.classNames.block.checklist.container} {\n margin: 0;\n padding: 0 20px;\n}\n\n.${a.classNames.block.checklist.item} {\n --text: var(--clepit-text);\n --check: var(--clepit-marker);\n --disabled: var(--clepit-border);\n --border-radius: 10px;\n border-radius: var(--border-radius);\n position: relative;\n padding: 5px;\n display: grid;\n grid-template-columns: 30px auto;\n align-items: center;\n margin: 4px 0;\n}\n\n.${a.classNames.block.checklist.text} {\n color: var(--text);\n position: relative;\n cursor: pointer;\n display: grid;\n align-items: center;\n width: -webkit-fit-content;\n width: -moz-fit-content;\n width: fit-content;\n transition: color 0.3s ease;\n outline: none;\n min-height: 1.2em;\n line-height: 1.6;\n padding: 0;\n margin: 0;\n}\n\n.${a.classNames.block.checklist.text}::before,\n.${a.classNames.block.checklist.text}::after {\n content: "";\n position: absolute;\n}\n\n.${a.classNames.block.checklist.text}::before {\n height: 2px;\n width: 8px;\n left: -27px;\n background: var(--check);\n border-radius: 2px;\n transition: background 0.3s ease;\n}\n\n.${a.classNames.block.checklist.text}::after {\n height: 4px;\n width: 4px;\n top: 8px;\n left: -25px;\n border-radius: 50%;\n}\n\n.${a.classNames.block.checklist.checkbox} {\n -webkit-appearance: none;\n -moz-appearance: none;\n position: relative;\n height: 15px;\n width: 15px;\n outline: none;\n border: 0;\n margin: 0 15px 0 0;\n cursor: pointer;\n background: var(--background);\n display: grid;\n align-items: center;\n}\n\n.${a.classNames.block.checklist.checkbox}::before,\n.${a.classNames.block.checklist.checkbox}::after {\n content: "";\n position: absolute;\n height: 2px;\n top: auto;\n background: var(--check);\n border-radius: 2px;\n}\n\n.${a.classNames.block.checklist.checkbox}::before {\n width: 0px;\n right: 60%;\n transform-origin: right bottom;\n}\n\n.${a.classNames.block.checklist.checkbox}::after {\n width: 0px;\n left: 40%;\n transform-origin: left bottom;\n}\n\n.${a.classNames.block.checklist.checkbox}:checked::before {\n -webkit-animation: clepit-check-01-11 0.4s ease forwards;\n animation: clepit-check-01-11 0.4s ease forwards;\n}\n\n.${a.classNames.block.checklist.checkbox}:checked::after {\n -webkit-animation: clepit-check-02-11 0.4s ease forwards;\n animation: clepit-check-02-11 0.4s ease forwards;\n}\n\n.${a.classNames.block.checklist.checkbox}:checked + .${a.classNames.block.checklist.text} {\n color: var(--disabled);\n -webkit-animation: clepit-move-11 0.3s ease 0.1s forwards;\n animation: clepit-move-11 0.3s ease 0.1s forwards;\n}\n\n.${a.classNames.block.checklist.checkbox}:checked + .${a.classNames.block.checklist.text}::before {\n background: var(--disabled);\n -webkit-animation: clepit-slice-11 0.4s ease forwards;\n animation: clepit-slice-11 0.4s ease forwards;\n}\n\n.${a.classNames.block.checklist.checkbox}:checked + .${a.classNames.block.checklist.text}::after {\n -webkit-animation: clepit-firework-11 0.5s ease forwards 0.1s;\n animation: clepit-firework-11 0.5s ease forwards 0.1s;\n}\n\n.${a.classNames.block.checklist.text}[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Checklist input link styles */\n.${a.classNames.block.checklist.text} a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.${a.classNames.block.checklist.text} a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n@-webkit-keyframes clepit-move-11 {\n 50% {\n padding-left: 8px;\n padding-right: 0px;\n }\n 100% {\n padding-right: 4px;\n }\n}\n\n@keyframes clepit-move-11 {\n 50% {\n padding-left: 8px;\n padding-right: 0px;\n }\n 100% {\n padding-right: 4px;\n }\n}\n\n@-webkit-keyframes clepit-slice-11 {\n 60% {\n width: 100%;\n left: 4px;\n }\n 100% {\n width: 100%;\n left: -2px;\n padding-left: 0;\n }\n}\n\n@keyframes clepit-slice-11 {\n 60% {\n width: 100%;\n left: 4px;\n }\n 100% {\n width: 100%;\n left: -2px;\n padding-left: 0;\n }\n}\n\n@-webkit-keyframes clepit-check-01-11 {\n 0% {\n width: 4px;\n top: auto;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: auto;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(45deg);\n }\n 100% {\n width: 5px;\n top: 8px;\n transform: rotate(45deg);\n }\n}\n\n@keyframes clepit-check-01-11 {\n 0% {\n width: 4px;\n top: auto;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: auto;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(45deg);\n }\n 100% {\n width: 5px;\n top: 8px;\n transform: rotate(45deg);\n }\n}\n\n@-webkit-keyframes clepit-check-02-11 {\n 0% {\n width: 4px;\n top: 17px;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: 17px;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(-45deg);\n }\n 100% {\n width: 10px;\n top: 8px;\n transform: rotate(-45deg);\n }\n}\n\n@keyframes clepit-check-02-11 {\n 0% {\n width: 4px;\n top: 17px;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: 17px;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(-45deg);\n }\n 100% {\n width: 10px;\n top: 8px;\n transform: rotate(-45deg);\n }\n}\n\n@-webkit-keyframes clepit-firework-11 {\n 0% {\n opacity: 1;\n box-shadow: 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--clepit-marker), 14px -8px 0 0px var(--clepit-marker), 14px 8px 0 0px var(--clepit-marker), 0 15px 0 0px var(--clepit-marker), -14px 8px 0 0px var(--clepit-marker), -14px -8px 0 0px var(--clepit-marker);\n }\n}\n\n@keyframes clepit-firework-11 {\n 0% {\n opacity: 1;\n box-shadow: 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--clepit-marker), 14px -8px 0 0px var(--clepit-marker), 14px 8px 0 0px var(--clepit-marker), 0 15px 0 0px var(--clepit-marker), -14px 8px 0 0px var(--clepit-marker), -14px -8px 0 0px var(--clepit-marker);\n }\n}\n`,Be='\n/* Checklist output block styles */\n.clepit-output-checklist {\n margin: 0 0 1rem 0;\n padding-left: 0;\n}\n\n.clepit-output-checklist-item {\n --text: var(--clepit-text);\n --check: var(--clepit-marker);\n --disabled: var(--clepit-border);\n --border-radius: 10px;\n border-radius: var(--border-radius);\n position: relative;\n padding: 5px;\n display: grid;\n grid-template-columns: 30px auto;\n align-items: center;\n margin: 0.5rem 0;\n line-height: 1.6;\n}\n\n.clepit-output-checklist-text {\n color: var(--text);\n position: relative;\n cursor: pointer;\n display: grid;\n align-items: center;\n width: -webkit-fit-content;\n width: -moz-fit-content;\n width: fit-content;\n transition: color 0.3s ease;\n line-height: 1.6;\n}\n\n.clepit-output-checklist-text::before,\n.clepit-output-checklist-text::after {\n content: "";\n position: absolute;\n}\n\n.clepit-output-checklist-text::before {\n height: 2px;\n width: 8px;\n left: -27px;\n background: var(--check);\n border-radius: 2px;\n transition: background 0.3s ease;\n}\n\n.clepit-output-checklist-text::after {\n height: 4px;\n width: 4px;\n top: 8px;\n left: -25px;\n border-radius: 50%;\n}\n\n.clepit-output-checklist-checkbox {\n -webkit-appearance: none;\n -moz-appearance: none;\n position: relative;\n height: 15px;\n width: 15px;\n outline: none;\n border: 0;\n margin: 0 15px 0 0;\n cursor: pointer;\n background: var(--background);\n display: grid;\n align-items: center;\n pointer-events: none;\n}\n\n.clepit-output-checklist-checkbox::before,\n.clepit-output-checklist-checkbox::after {\n content: "";\n position: absolute;\n height: 2px;\n top: auto;\n background: var(--check);\n border-radius: 2px;\n}\n\n.clepit-output-checklist-checkbox::before {\n width: 0px;\n right: 60%;\n transform-origin: right bottom;\n}\n\n.clepit-output-checklist-checkbox::after {\n width: 0px;\n left: 40%;\n transform-origin: left bottom;\n}\n\n.clepit-output-checklist-checkbox:checked::before {\n -webkit-animation: clepit-check-01-11 0.4s ease forwards;\n animation: clepit-check-01-11 0.4s ease forwards;\n}\n\n.clepit-output-checklist-checkbox:checked::after {\n -webkit-animation: clepit-check-02-11 0.4s ease forwards;\n animation: clepit-check-02-11 0.4s ease forwards;\n}\n\n.clepit-output-checklist-checkbox:checked + .clepit-output-checklist-text {\n color: var(--disabled);\n -webkit-animation: clepit-move-11 0.3s ease 0.1s forwards;\n animation: clepit-move-11 0.3s ease 0.1s forwards;\n}\n\n.clepit-output-checklist-checkbox:checked + .clepit-output-checklist-text::before {\n background: var(--disabled);\n -webkit-animation: clepit-slice-11 0.4s ease forwards;\n animation: clepit-slice-11 0.4s ease forwards;\n}\n\n.clepit-output-checklist-checkbox:checked + .clepit-output-checklist-text::after {\n -webkit-animation: clepit-firework-11 0.5s ease forwards 0.1s;\n animation: clepit-firework-11 0.5s ease forwards 0.1s;\n}\n\n@-webkit-keyframes clepit-move-11 {\n 50% {\n padding-left: 8px;\n padding-right: 0px;\n }\n 100% {\n padding-right: 4px;\n }\n}\n\n@keyframes clepit-move-11 {\n 50% {\n padding-left: 8px;\n padding-right: 0px;\n }\n 100% {\n padding-right: 4px;\n }\n}\n\n@-webkit-keyframes clepit-slice-11 {\n 60% {\n width: 100%;\n left: 4px;\n }\n 100% {\n width: 100%;\n left: -2px;\n padding-left: 0;\n }\n}\n\n@keyframes clepit-slice-11 {\n 60% {\n width: 100%;\n left: 4px;\n }\n 100% {\n width: 100%;\n left: -2px;\n padding-left: 0;\n }\n}\n\n@-webkit-keyframes clepit-check-01-11 {\n 0% {\n width: 4px;\n top: auto;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: auto;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(45deg);\n }\n 100% {\n width: 5px;\n top: 8px;\n transform: rotate(45deg);\n }\n}\n\n@keyframes clepit-check-01-11 {\n 0% {\n width: 4px;\n top: auto;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: auto;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(45deg);\n }\n 100% {\n width: 5px;\n top: 8px;\n transform: rotate(45deg);\n }\n}\n\n@-webkit-keyframes clepit-check-02-11 {\n 0% {\n width: 4px;\n top: 17px;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: 17px;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(-45deg);\n }\n 100% {\n width: 10px;\n top: 8px;\n transform: rotate(-45deg);\n }\n}\n\n@keyframes clepit-check-02-11 {\n 0% {\n width: 4px;\n top: 17px;\n transform: rotate(0);\n }\n 50% {\n width: 0px;\n top: 17px;\n transform: rotate(0);\n }\n 51% {\n width: 0px;\n top: 8px;\n transform: rotate(-45deg);\n }\n 100% {\n width: 10px;\n top: 8px;\n transform: rotate(-45deg);\n }\n}\n\n@-webkit-keyframes clepit-firework-11 {\n 0% {\n opacity: 1;\n box-shadow: 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--clepit-marker), 14px -8px 0 0px var(--clepit-marker), 14px 8px 0 0px var(--clepit-marker), 0 15px 0 0px var(--clepit-marker), -14px 8px 0 0px var(--clepit-marker), -14px -8px 0 0px var(--clepit-marker);\n }\n}\n\n@keyframes clepit-firework-11 {\n 0% {\n opacity: 1;\n box-shadow: 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker), 0 0 0 -2px var(--clepit-marker);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--clepit-marker), 14px -8px 0 0px var(--clepit-marker), 14px 8px 0 0px var(--clepit-marker), 0 15px 0 0px var(--clepit-marker), -14px 8px 0 0px var(--clepit-marker), -14px -8px 0 0px var(--clepit-marker);\n }\n}\n',$e=class e{static{this.placeholder="Add checklist item..."}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=[];return e.querySelectorAll(`.${a.classNames.block.checklist.item}`).forEach(e=>{const n=e.querySelector('input[type="checkbox"]'),o=e.querySelector(`.${a.classNames.block.checklist.text}`);n&&o&&t.push({checked:n.checked,text:I(o.innerHTML)})}),{items:t}}static render(t,n,o){a.injectStyles("clepit-checklist-input-styles",Le);const i={items:[]},r=n?{...i,...n}:i,s=a.createStyledElement("div",a.classNames.block.checklist.container,{classNames:o?.classNames?.container,styles:o?.styles?.container});return r.items.length>0?r.items.forEach(n=>e.createAndAppendChecklistItem(n,s,t,o)):e.createAndAppendChecklistItem({checked:!1,text:""},s,t,o),s}static createAndAppendChecklistItem(t,n,o,i){const r=a.createStyledElement("div",a.classNames.block.checklist.item,{classNames:i?.classNames?.item,styles:i?.styles?.item}),s=a.createStyledElement("input",a.classNames.block.checklist.checkbox,{classNames:i?.classNames?.checkbox,styles:i?.styles?.checkbox});s.type="checkbox",s.checked=t.checked;const l=a.createStyledElement("div",a.classNames.block.checklist.text,{classNames:i?.classNames?.text,styles:i?.styles?.text});l.setAttribute("contenteditable","true"),l.setAttribute("data-placeholder",e.placeholder),l.innerHTML=t.text?.trim()||"",e.addEventListener(o,s,"change",()=>sr.saveBlockData(s)),e.addEventListener(o,l,"keydown",t=>{const s=t,c=n.closest(`.${a.classNames.block.container}`);if(!c)return;const p=sr.getBlockIndex(o,c.getAttribute("data-id")),d=s.metaKey||s.ctrlKey;if(s.shiftKey)switch(s.key){case"ArrowUp":t.preventDefault(),t.stopPropagation(),p>0&&sr.moveBlock(o,p,p-1);break;case"ArrowDown":t.preventDefault(),t.stopPropagation();const e=sr.getBlocks(o);e&&p<e.length-1&&sr.moveBlock(o,p,p+1)}else if(d)switch(s.key){case"Delete":case"Backspace":t.preventDefault(),t.stopPropagation(),sr.removeBlock(o,p)}else if("Enter"===s.key)if(t.preventDefault(),t.stopPropagation(),M(l.innerHTML)){e.cleanupEmptyItems(n);const t=n.closest(`.${a.classNames.block.container}`);if(!t)return;const i=sr.getBlockIndex(o,t.getAttribute("data-id"));sr.insertBlock({data:{html:""},type:"paragraph"},o,i+1)}else e.createAndAppendChecklistItem({checked:!1,text:""},n,o,i);else if("Backspace"===s.key){if(M(l.innerHTML)){t.preventDefault(),t.stopPropagation();const e=Array.from(n.querySelectorAll(`.${a.classNames.block.checklist.item}`)),i=e.indexOf(r);if(1===e.length){const e=n.closest(`.${a.classNames.block.container}`);if(!e)return;const t=sr.getBlockIndex(o,e.getAttribute("data-id"));if(-1===t)return;sr.removeBlock(o,t)}else r.remove(),i>0?e[i-1].querySelector(".clepit-checklist-text")?.focus():e[i+1].querySelector(".clepit-checklist-text")?.focus()}}else{sr.ensureActiveBlock(o);const e=sr.getBlocks(o);switch(s.key){case"ArrowUp":t.preventDefault(),t.stopPropagation();const o=Array.from(n.querySelectorAll(`.${a.classNames.block.checklist.item}`)),i=o.indexOf(r);if(0===i){if(p>0){const t=e[p-1];t&&sr.focusBlock(t)}}else{const e=o[i-1].querySelector(`.${a.classNames.block.checklist.text}`);e&&e.focus()}return;case"ArrowDown":t.preventDefault(),t.stopPropagation();const s=Array.from(n.querySelectorAll(`.${a.classNames.block.checklist.item}`)),l=s.indexOf(r);if(l===s.length-1){if(p<e.length-1){const t=e[p+1];t&&sr.focusBlock(t)}}else{const e=s[l+1].querySelector(`.${a.classNames.block.checklist.text}`);e&&e.focus()}return}}}),e.addEventListener(o,l,"input",sr.handleInput),r.appendChild(s),r.appendChild(l),n.appendChild(r),l.focus()}static cleanupEmptyItems(e){const t=Array.from(e.querySelectorAll(`.${a.classNames.block.checklist.item}`)),n=t.filter(e=>M(e.querySelector(`.${a.classNames.block.checklist.text}`)?.innerHTML||""));if(t.length===n.length){if(t.length<2)return;for(let e=1;e<n.length;e++)n[e].remove()}else n.forEach(e=>e.remove())}static isEmpty(e){const t=e.querySelectorAll(`.${a.classNames.block.checklist.item}`);return!t||Array.from(t).every(e=>M(e.querySelector(`.${a.classNames.block.checklist.text}`)?.innerHTML))}static isEmptyData(e){return 0===e.items.length||e.items.every(e=>M(e.text))}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Me=class e{static render(t,n,o,i){if(a.injectStyles("clepit-checklist-output-styles",Be),!e.validate(t))return xe();if($e.isEmptyData(t))return document.createElement("div");const r=t.items,s=a.createStyledElement("div","clepit-output-checklist",{classNames:i?.container,styles:o?.container});return r.forEach((e,t)=>{const n=a.createStyledElement("div","clepit-output-checklist-item",{classNames:i?.item,styles:o?.item}),r=a.createStyledElement("input","clepit-output-checklist-checkbox",{classNames:i?.checkbox,styles:o?.checkbox});r.type="checkbox",r.checked=e.checked,r.setAttribute("readonly","true");const l=a.createStyledElement("div","clepit-output-checklist-text",{classNames:i?.text,styles:o?.text});e.text&&e.text.trim()&&(l.innerHTML=e.text),r.checked&&n.classList.add("checked"),n.appendChild(r),n.appendChild(l),s.appendChild(n)}),s}static draw(t,n=ue){if(!e.validate(t)||$e.isEmptyData(t))return null;const a=n.create("div");a.addClass("clepit-output-checklist");for(const e of t.items){const t=n.create("div");t.addClass("clepit-output-checklist-item");const o=n.create("input");o.addClass("clepit-output-checklist-checkbox"),o.setAttribute("type","checkbox"),e.checked&&o.setAttribute("checked","checked"),o.setAttribute("readonly","true"),t.append(o);const i=n.create("div");i.addClass("clepit-output-checklist-text"),e.text?.trim()&&i.setHtml(e.text),t.append(i),a.append(t)}return a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&Array.isArray(e.items)}},Ie={icon:"☑",get input(){return $e},label:"Checklist",get output(){return Me},shortcut:v("K"),testId:"block-type-checklist",type:"checklist"},Te=`\n/* Code block styles */\n.clepit-code {\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0;\n}\n\n.clepit-code-pre {\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0;\n}\n\n.clepit-block[data-tool="code"] .clepit-block-content {\n background: transparent;\n border: none;\n padding: 0;\n margin-right: 8px;\n}\n\n/* Code placeholder styles */\n.clepit-code[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Code container */\n.${a.classNames.block.code.container} {\n border: 1px solid var(--clepit-code-border);\n background: var(--clepit-code-bg);\n border-radius: 6px;\n overflow: visible; /* allow header tooltips to escape */\n margin: 8px 0;\n}\n\n.${a.classNames.block.code.editor} {\n height: 200px;\n max-height: 60vh;\n min-height: 200px;\n overflow: hidden;\n position: relative;\n}\n\n/* The editing surface: a textarea laid over a highlighted pre. The two must\n * agree on every metric that affects where a glyph lands, or the caret drifts\n * away from the colour behind it. They inherit from one rule for that reason. */\n.${a.classNames.block.code.editor} .clepit-code-highlight,\n.${a.classNames.block.code.editor} .clepit-code-input {\n margin: 0;\n border: 0;\n padding: 12px 34px;\n font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Source Code Pro', monospace;\n font-size: 0.875rem;\n line-height: 1.5;\n letter-spacing: normal;\n tab-size: 2;\n white-space: pre;\n overflow: auto;\n box-sizing: border-box;\n}\n\n.${a.classNames.block.code.editor} .clepit-code-highlight {\n position: absolute;\n inset: 0;\n pointer-events: none;\n color: var(--clepit-code-text);\n}\n\n/* The text itself is transparent: the colour the reader sees belongs to the pre\n * behind it. The caret keeps a colour of its own so it stays visible. */\n.${a.classNames.block.code.editor} .clepit-code-input {\n position: relative;\n width: 100%;\n height: 100%;\n display: block;\n background: transparent;\n color: transparent;\n caret-color: var(--clepit-code-text);\n resize: none;\n outline: none;\n}\n\n.${a.classNames.block.code.editor} .clepit-code-input::placeholder {\n color: var(--clepit-text-muted);\n}\n\n.${a.classNames.block.code.editor} .clepit-code-input::selection {\n background: var(--clepit-code-selection-bg);\n color: transparent;\n}\n\n/* Code header */\n.${a.classNames.block.code.headerWrapper} {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 8px;\n width: 100%;\n padding: 8px 34px;\n position: relative; /* allow inner tooltip absolute positioning */\n overflow: visible; /* ensure tooltip not clipped */\n z-index: 2;\n border-bottom: 1px solid var(--clepit-border-color);\n}\n\n.${a.classNames.block.code.header} {\n font-size: 12px;\n font-weight: 500;\n}\n\n/* Code Language Submenu */\n.clepit-code-language-submenu {\n position: absolute;\n top: 0;\n left: 100%;\n z-index: 1002;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n padding: 8px;\n min-width: 160px;\n max-width: 200px;\n margin-left: 4px;\n max-height: 300px;\n overflow-y: auto;\n display: none;\n transition: transform 0.2s ease;\n}\n\n.clepit-code-language-submenu--visible {\n display: block !important;\n transform: translateX(0);\n}\n\n.clepit-code-language-submenu--hidden {\n display: none !important;\n}\n\n/* Code Theme Submenu */\n.clepit-code-theme-submenu {\n position: absolute;\n top: 0;\n left: 100%;\n z-index: 1002;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n padding: 8px;\n min-width: 140px;\n max-width: 180px;\n margin-left: 4px;\n max-height: 250px;\n overflow-y: auto;\n display: none;\n transition: transform 0.2s ease;\n}\n\n.clepit-code-theme-submenu--visible {\n display: block !important;\n transform: translateX(0);\n}\n\n.clepit-code-theme-submenu--hidden {\n display: none !important;\n}\n\n/* Code language submenu items */\n.clepit-code-language-item {\n padding: 8px 12px;\n cursor: pointer;\n border-radius: 4px;\n transition: background-color 0.2s;\n font-size: 14px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n\n.clepit-code-language-item:hover {\n background-color: var(--clepit-hover-bg, var(--clepit-surface));\n}\n\n/* Code theme submenu items */\n.clepit-code-theme-item {\n padding: 8px 12px;\n cursor: pointer;\n border-radius: 4px;\n transition: background-color 0.2s;\n font-size: 14px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n\n.clepit-code-theme-item:hover {\n background-color: var(--clepit-hover-bg, var(--clepit-surface));\n}\n\n\n`,qe="clepit-code-output-styles",De="\n/* Output Code Block */\n/* No margin of its own — every consumer already governs the gap around this\n * container (page rhythm via the block wrapper's margin-block, or a flex\n * container's gap inside the openapi block). A margin here just adds a second,\n * inconsistent gap on top of whichever one the consumer already applies. */\n.clepit-output-code-container {\n border: 1px solid var(--clepit-code-border);\n border-radius: 6px;\n overflow: hidden;\n background: var(--clepit-code-bg);\n margin: 0;\n}\n\n.clepit-output-code-header {\n background: var(--clepit-code-bg);\n padding: 8px 34px;\n border-bottom: 1px solid var(--clepit-code-border);\n font-size: 12px;\n color: var(--clepit-text-muted);\n font-weight: 500;\n display: flex;\n align-items: center;\n justify-content: space-between;\n}\n\n/* Output header — theme-agnostic; tokens handle light/dark automatically */\n.clepit-output-code-header {\n background: var(--clepit-code-bg);\n color: var(--clepit-text-muted);\n border-bottom-color: var(--clepit-code-border);\n --clepit-svg-stroke-color: var(--clepit-text-muted);\n --clepit-btn-hover-bg: var(--clepit-block-highlight-bg);\n}\n\n/* Output code variant tabs */\n.clepit-output-code-tabs {\n display: flex;\n align-items: stretch;\n gap: 4px;\n margin: -8px 0 -8px -18px;\n overflow-x: auto;\n scrollbar-width: none;\n}\n\n.clepit-output-code-tabs::-webkit-scrollbar {\n display: none;\n}\n\n.clepit-output-code-tab {\n appearance: none;\n -webkit-appearance: none;\n background: transparent;\n border: none;\n border-bottom: 2px solid transparent;\n color: var(--clepit-text-muted);\n cursor: pointer;\n font: inherit;\n padding: 8px 10px;\n transition: color 0.2s ease, border-color 0.2s ease;\n white-space: nowrap;\n}\n\n.clepit-output-code-tab:hover {\n color: var(--clepit-text);\n}\n\n.clepit-output-code-tab[aria-selected=\"true\"] {\n border-bottom-color: var(--clepit-primary);\n color: var(--clepit-primary);\n}\n\n.clepit-output-code-tab:focus-visible {\n outline: 2px solid var(--clepit-primary);\n outline-offset: -2px;\n}\n\n.clepit-output-code-editor {\n overflow: auto;\n max-height: 60vh;\n position: relative;\n border: none;\n border-radius: 0;\n}\n\n/* The output panes: one pre per variant, the inactive ones carrying a hidden attribute.\n * Colour comes from the generated theme stylesheet, keyed on the container's\n * data-theme, so a published page keeps its palette with nothing running. */\n.clepit-output-code-pane {\n margin: 0;\n padding: 12px 34px;\n max-height: 60vh;\n overflow: auto;\n font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Source Code Pro', monospace;\n font-size: 0.875rem;\n line-height: 1.5;\n tab-size: 2;\n white-space: pre;\n}\n\n/* Code Output */\n.clepit-output-code {\n margin: 1rem 0;\n background-color: var(--clepit-code-bg);\n border: 1px solid var(--clepit-code-border);\n border-radius: 6px;\n overflow: hidden;\n}\n\n.clepit-output-code code {\n display: block;\n padding: 1rem;\n font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Source Code Pro', monospace;\n font-size: 0.875rem;\n line-height: 1.5;\n color: var(--clepit-code-text);\n overflow-x: auto;\n white-space: pre;\n}\n\n/* Output code copy button */\n.clepit-output-code-copy-btn {\n margin-left: auto;\n width: 24px;\n height: 24px;\n border: none;\n outline: none;\n cursor: pointer;\n border-radius: 50%;\n background: transparent;\n transition: all 0.2s ease;\n padding: 4px;\n display: flex;\n align-items: center;\n justify-content: center;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n}\n\n.clepit-output-code-copy-btn {\n color: var(--clepit-text-muted);\n}\n\n.clepit-output-code-copy-btn:hover {\n background: var(--clepit-block-highlight-bg);\n color: var(--clepit-primary);\n}\n\n.clepit-output-code-copy-btn:hover .clepit-copy-icon {\n stroke: var(--clepit-primary);\n}\n\n.clepit-output-code-copy-btn:active {\n transform: scale(0.95);\n}\n\n.clepit-copy-icon,\n.clepit-check-icon {\n width: 20px;\n height: 20px;\n stroke: var(--clepit-svg-stroke-color);\n stroke-width: 2;\n fill: none;\n display: block;\n}\n\n/* Code output button animation styles */\n.clepit-output-code-copy-btn--animating {\n color: var(--clepit-success);\n transform: scale(1.1);\n}\n\n.clepit-output-code-copy-btn--normal {\n color: var(--clepit-svg-stroke-color);\n transform: scale(1);\n}\n",_e={dark:{background:"#1c2128",comment:"rgba(240, 246, 252, 0.42)",function:"#d2a8ff",gutter:"rgba(240, 246, 252, 0.42)",keyword:"#ff7b72",number:"#79c0ff",punctuation:"rgba(240, 246, 252, 0.62)",selection:"rgba(124, 124, 255, 0.24)",string:"#7ee787",text:"rgba(240, 246, 252, 0.92)",type:"#ffa657"},dracula:{background:"#282a36",comment:"#6272a4",function:"#50fa7b",gutter:"#6272a4",keyword:"#ff79c6",number:"#bd93f9",punctuation:"#f8f8f2",selection:"rgba(68, 71, 90, 0.8)",string:"#f1fa8c",text:"#f8f8f2",type:"#8be9fd"},github:{background:"#ffffff",comment:"#6e7781",function:"#8250df",gutter:"#8c959f",keyword:"#cf222e",number:"#0550ae",punctuation:"#24292f",selection:"rgba(84, 174, 255, 0.24)",string:"#0a3069",text:"#24292f",type:"#953800"},"github-dark":{background:"#0d1117",comment:"#8b949e",function:"#d2a8ff",gutter:"#6e7681",keyword:"#ff7b72",number:"#79c0ff",punctuation:"#c9d1d9",selection:"rgba(56, 139, 253, 0.24)",string:"#a5d6ff",text:"#c9d1d9",type:"#ffa657"},light:{background:"#fdfdfd",comment:"#868f9c",function:"#6f42c1",gutter:"#868f9c",keyword:"#cf222e",number:"#0550ae",punctuation:"#525866",selection:"rgba(91, 91, 255, 0.14)",string:"#0a7c3e",text:"#0a0a0a",type:"#953800"},monokai:{background:"#272822",comment:"#75715e",function:"#a6e22e",gutter:"#75715e",keyword:"#f92672",number:"#ae81ff",punctuation:"#f8f8f2",selection:"rgba(73, 72, 62, 0.9)",string:"#e6db74",text:"#f8f8f2",type:"#66d9ef"},solarized:{background:"#fdf6e3",comment:"#93a1a1",function:"#268bd2",gutter:"#93a1a1",keyword:"#859900",number:"#d33682",punctuation:"#657b83",selection:"rgba(238, 232, 213, 0.9)",string:"#2aa198",text:"#657b83",type:"#b58900"},"solarized-dark":{background:"#002b36",comment:"#586e75",function:"#268bd2",gutter:"#586e75",keyword:"#859900",number:"#d33682",punctuation:"#839496",selection:"rgba(7, 54, 66, 0.9)",string:"#2aa198",text:"#839496",type:"#b58900"},tomorrow:{background:"#fafafa",comment:"#8e908c",function:"#4271ae",gutter:"#8e908c",keyword:"#8959a8",number:"#f5871f",punctuation:"#4d4d4c",selection:"rgba(214, 214, 214, 0.9)",string:"#718c00",text:"#4d4d4c",type:"#c82829"}},je=["keyword","string","number","comment","function","type","punctuation","text"],ze=Object.fromEntries(je.map(e=>[e,`clepit-code-${e}`])),Oe=e=>e>="0"&&e<="9",He=e=>" "===e||"\t"===e||"\n"===e||"\r"===e||"\f"===e||"\v"===e,Pe=e=>e>="a"&&e<="z"||e>="A"&&e<="Z"||"_"===e||e.charCodeAt(0)>127,Fe=e=>(e.lineComments?.length??0)>0||(e.blockComments?.length??0)>0||(e.strings?.length??0)>0||(e.keywords?.length??0)>0||(e.types?.length??0)>0||(e.constants?.length??0)>0||(e.builtins?.length??0)>0,Re=(e,t)=>new Set((e??[]).map(e=>t?e.toLowerCase():e)),Ve=(e,t)=>{let n=t;for(;n<e.length&&(" "===e[n]||"\t"===e[n]);)n++;return e[n]??""},Ue=(e,t,n)=>{const a=n.close??n.open;let o=t+n.open.length;for(;o<e.length;)if(n.escape&&e[o]===n.escape)o+=2;else{if(!n.multiline&&"\n"===e[o])return o;if(e.startsWith(a,o))return o+a.length;o++}return e.length},We=(e,t)=>{let n=t;if("0"===e[n]&&/[xXbBoO]/.test(e[n+1]??"")){for(n+=2;n<e.length&&/[0-9a-fA-F_]/.test(e[n]);)n++;return n}for(;n<e.length&&/[0-9_]/.test(e[n]);)n++;if("."===e[n]&&Oe(e[n+1]??""))for(n++;n<e.length&&/[0-9_]/.test(e[n]);)n++;if(/[eE]/.test(e[n]??"")&&(Oe(e[n+1]??"")||/[+-]/.test(e[n+1]??"")&&Oe(e[n+2]??"")))for(n+=2;n<e.length&&Oe(e[n]);)n++;for(;n<e.length&&Pe(e[n])&&!Oe(e[n])&&/[a-zA-Z]/.test(e[n])&&n-t<32&&/[nlLfFdDuUmM]/.test(e[n]);)n++;return n},Ke=[{escape:"\\",open:'"'},{escape:"\\",open:"'"}],Ge={blockComments:[["/*","*/"]],lineComments:["//"]},Je=e=>({...Ge,functionCalls:!0,strings:Ke,...e}),Xe=e=>({functionCalls:!0,lineComments:["#"],strings:Ke,...e}),Ze=["as","async","await","break","case","catch","class","const","continue","debugger","default","delete","do","else","export","extends","finally","for","from","function","get","if","import","in","instanceof","let","new","of","return","set","static","super","switch","this","throw","try","typeof","var","void","while","with","yield"],Ye=[...Ze,"abstract","declare","enum","implements","infer","interface","is","keyof","namespace","override","private","protected","public","readonly","satisfies","type"],Qe=Je({constants:["false","null","true","undefined","NaN","Infinity"],identifierExtra:"$",keywords:Ze,strings:[...Ke,{escape:"\\",multiline:!0,open:"`"}],types:["Array","Boolean","Date","Error","Map","Number","Object","Promise","RegExp","Set","String","Symbol"]}),et={...Qe,keywords:Ye,types:[...Qe.types??[],"any","bigint","boolean","never","number","object","string","symbol","unknown","void"]},tt=Xe({constants:["False","None","True"],keywords:["and","as","assert","async","await","break","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","in","is","lambda","nonlocal","not","or","pass","raise","return","try","while","with","yield"],strings:[{escape:"\\",multiline:!0,open:'"""'},{escape:"\\",multiline:!0,open:"'''"},...Ke],types:["bool","bytes","dict","float","frozenset","int","list","set","str","tuple"]}),nt={blockComments:[["\x3c!--","--\x3e"]],strings:Ke,types:[]},at={assembly:{constants:[],keywords:["add","call","cmp","jmp","jne","je","lea","mov","pop","push","ret","sub","xor"],lineComments:[";","#"],strings:Ke,types:["byte","dword","qword","word"]},bash:Xe({builtins:["cd","echo","exit","export","printf","read","source"],constants:["false","true"],identifierExtra:"$",keywords:["case","do","done","elif","else","esac","fi","for","function","if","in","local","return","select","then","until","while"],strings:[{escape:"\\",multiline:!0,open:'"'},{multiline:!0,open:"'"}]}),clojure:{constants:["false","nil","true"],identifierExtra:"-*?!<>=/",keywords:["def","defmacro","defn","do","fn","if","let","loop","ns","quote","recur","require","var","when"],lineComments:[";"],strings:[{escape:"\\",multiline:!0,open:'"'}]},cobol:{caseInsensitive:!0,keywords:["accept","add","call","compute","display","division","else","end","goback","identification","if","move","perform","procedure","program-id","section","stop","to","until","working-storage"],lineComments:["*"],strings:Ke,types:["pic","picture"]},cpp:Je({constants:["false","nullptr","true"],keywords:["auto","break","case","catch","class","const","constexpr","continue","default","delete","do","else","enum","explicit","export","extern","for","friend","goto","if","inline","mutable","namespace","new","noexcept","operator","private","protected","public","return","sizeof","static","struct","switch","template","this","throw","try","typedef","typename","union","using","virtual","volatile","while"],types:["bool","char","double","float","int","long","short","signed","size_t","unsigned","void","wchar_t"]}),csharp:Je({constants:["false","null","true"],keywords:["abstract","as","async","await","base","break","case","catch","class","const","continue","default","delegate","do","else","enum","event","explicit","extern","finally","fixed","for","foreach","get","goto","if","implicit","in","interface","internal","is","lock","namespace","new","operator","out","override","params","private","protected","public","readonly","record","ref","return","sealed","set","sizeof","stackalloc","static","struct","switch","this","throw","try","typeof","unsafe","using","var","virtual","void","while","yield"],types:["bool","byte","char","decimal","double","float","int","long","object","sbyte","short","string","uint","ulong","ushort"]}),css:{blockComments:[["/*","*/"]],functionCalls:!0,keywords:["and","from","important","not","only","to"],strings:Ke,types:["@container","@import","@keyframes","@layer","@media","@property","@supports"]},dart:Je({constants:["false","null","true"],keywords:["abstract","as","assert","async","await","break","case","catch","class","const","continue","covariant","default","deferred","do","else","enum","export","extends","extension","external","factory","final","finally","for","get","if","implements","import","in","is","late","library","mixin","new","on","operator","part","required","rethrow","return","sealed","set","show","static","super","switch","sync","this","throw","try","typedef","var","while","with","yield"],types:["bool","double","dynamic","int","List","Map","num","Object","Set","String","void"]}),diff:{lineComments:["diff ","index ","--- ","+++ "],strings:[]},dockerfile:Xe({caseInsensitive:!0,keywords:["add","arg","cmd","copy","entrypoint","env","expose","from","healthcheck","label","run","shell","stopsignal","user","volume","workdir"]}),erlang:{constants:["false","true","undefined"],functionCalls:!0,keywords:["after","begin","case","catch","cond","end","fun","if","let","of","receive","try","when"],lineComments:["%"],strings:Ke},fortran:{caseInsensitive:!0,keywords:["allocate","call","contains","do","else","end","function","if","implicit","module","program","return","subroutine","then","use","while"],lineComments:["!"],strings:Ke,types:["character","complex","integer","logical","real"]},go:Je({builtins:["append","cap","copy","delete","len","make","new","panic","recover"],constants:["false","iota","nil","true"],keywords:["break","case","chan","const","continue","default","defer","else","fallthrough","for","func","go","goto","if","import","interface","map","package","range","return","select","struct","switch","type","var"],strings:[...Ke,{multiline:!0,open:"`"}],types:["bool","byte","complex128","complex64","error","float32","float64","int","int16","int32","int64","int8","rune","string","uint","uint16","uint32","uint64","uint8","uintptr"]}),graphql:Xe({keywords:["directive","enum","extend","fragment","implements","input","interface","mutation","on","query","scalar","schema","subscription","type","union"],types:["Boolean","Float","ID","Int","String"]}),groovy:Je({constants:["false","null","true"],keywords:["abstract","as","assert","break","case","catch","class","const","continue","def","default","do","else","enum","extends","final","finally","for","if","implements","import","in","instanceof","interface","new","package","private","protected","public","return","static","super","switch","this","throw","throws","trait","try","while"],types:["BigDecimal","Boolean","Integer","List","Map","String","boolean","double","int","long","void"]}),haskell:{blockComments:[["{-","-}"]],constants:["False","Nothing","True"],functionCalls:!0,keywords:["case","class","data","deriving","do","else","if","import","in","infixl","infixr","instance","let","module","newtype","of","then","type","where"],lineComments:["--"],strings:[{escape:"\\",open:'"'}],types:["Bool","Char","Double","Either","Int","Integer","IO","Maybe","String"]},html:nt,java:Je({constants:["false","null","true"],keywords:["abstract","assert","break","case","catch","class","const","continue","default","do","else","enum","extends","final","finally","for","goto","if","implements","import","instanceof","interface","native","new","package","private","protected","public","record","return","sealed","static","strictfp","super","switch","synchronized","this","throw","throws","transient","try","var","volatile","while","yield"],types:["Boolean","Double","Integer","List","Long","Map","Object","String","boolean","byte","char","double","float","int","long","short","void"]}),javascript:Qe,json:{constants:["false","null","true"],strings:[{escape:"\\",open:'"'}]},jsx:Qe,julia:Xe({blockComments:[["#=","=#"]],constants:["false","nothing","true"],keywords:["abstract","baremodule","begin","break","catch","const","continue","do","else","elseif","end","export","finally","for","function","global","if","import","let","local","macro","module","mutable","primitive","quote","return","struct","try","using","while"],types:["Array","Bool","Char","Dict","Float64","Int","Int64","String"]}),kotlin:Je({constants:["false","null","true"],keywords:["as","break","by","class","companion","const","constructor","continue","crossinline","data","do","else","enum","external","final","finally","for","fun","get","if","import","in","infix","init","inline","interface","internal","is","lateinit","object","open","operator","out","override","package","private","protected","public","reified","return","sealed","set","super","suspend","this","throw","try","typealias","val","var","vararg","when","while"],strings:[{escape:"\\",multiline:!0,open:'"""'},...Ke],types:["Any","Array","Boolean","Char","Double","Float","Int","List","Long","Map","Nothing","Set","String","Unit"]}),lua:{blockComments:[["--[[","]]"]],constants:["false","nil","true"],functionCalls:!0,keywords:["and","break","do","else","elseif","end","for","function","goto","if","in","local","not","or","repeat","return","then","until","while"],lineComments:["--"],strings:[{close:"]]",multiline:!0,open:"[["},...Ke]},markdown:{lineComments:[],strings:[{open:"`"}]},nginx:Xe({keywords:["access_log","error_log","events","http","include","index","listen","location","proxy_pass","return","root","server","server_name","ssl_certificate","upstream"]}),objectivec:Je({constants:["NO","YES","nil"],identifierExtra:"@",keywords:["@class","@end","@implementation","@interface","@property","@protocol","@selector","@synthesize","break","case","const","continue","default","do","else","enum","extern","for","if","return","sizeof","static","struct","switch","typedef","union","void","while"],types:["BOOL","CGFloat","NSArray","NSDictionary","NSInteger","NSObject","NSString","char","double","float","id","int","long","short"]}),pascal:{blockComments:[["{","}"],["(*","*)"]],caseInsensitive:!0,constants:["false","nil","true"],functionCalls:!0,keywords:["and","array","begin","case","const","div","do","downto","else","end","for","function","goto","if","implementation","interface","mod","not","of","or","procedure","program","record","repeat","then","to","type","unit","until","uses","var","while","with"],lineComments:["//"],strings:[{open:"'"}],types:["boolean","byte","char","integer","real","string"]},perl:Xe({constants:["undef"],identifierExtra:"$@%",keywords:["do","else","elsif","foreach","for","if","last","local","my","next","our","package","return","sub","unless","until","use","while"]}),php:Je({constants:["false","null","true"],identifierExtra:"$",keywords:["abstract","as","break","case","catch","class","clone","const","continue","declare","default","do","echo","else","elseif","enum","extends","final","finally","fn","for","foreach","function","global","if","implements","include","instanceof","interface","match","namespace","new","print","private","protected","public","readonly","require","return","static","switch","throw","trait","try","use","var","while","yield"],lineComments:["//","#"],types:["array","bool","callable","float","int","iterable","mixed","object","string","void"]}),plaintext:{},powershell:Xe({blockComments:[["<#","#>"]],caseInsensitive:!0,constants:["$false","$null","$true"],identifierExtra:"$-",keywords:["begin","break","catch","continue","do","else","elseif","end","finally","for","foreach","function","if","in","param","process","return","switch","throw","try","until","while"]}),protobuf:Je({constants:["false","true"],keywords:["enum","extend","import","map","message","oneof","option","optional","package","repeated","required","reserved","returns","rpc","service","syntax"],types:["bool","bytes","double","fixed32","fixed64","float","int32","int64","sint32","sint64","string","uint32","uint64"]}),python:tt,r:Xe({constants:["FALSE","Inf","NA","NULL","NaN","TRUE"],identifierExtra:".",keywords:["break","else","for","function","if","in","next","repeat","return","while"],types:["character","data.frame","factor","integer","list","logical","matrix","numeric","vector"]}),ruby:Xe({blockComments:[["=begin","=end"]],constants:["false","nil","true"],identifierExtra:"?!@$",keywords:["alias","and","begin","break","case","class","def","defined?","do","else","elsif","end","ensure","for","if","in","module","next","not","or","redo","rescue","retry","return","self","super","then","undef","unless","until","when","while","yield"],types:["Array","Float","Hash","Integer","String","Symbol"]}),rust:Je({constants:["false","None","Some","true"],keywords:["as","async","await","break","const","continue","crate","dyn","else","enum","extern","fn","for","if","impl","in","let","loop","match","mod","move","mut","pub","ref","return","self","static","struct","super","trait","type","unsafe","use","where","while"],types:["String","Vec","bool","char","f32","f64","i128","i16","i32","i64","i8","isize","str","u128","u16","u32","u64","u8","usize"]}),scala:Je({constants:["false","null","true"],keywords:["abstract","case","catch","class","def","do","else","extends","final","finally","for","given","if","implicit","import","lazy","match","new","object","override","package","private","protected","return","sealed","super","this","throw","trait","try","type","val","var","while","with","yield"],types:["Any","Boolean","Double","Float","Int","List","Long","Map","Option","Seq","String","Unit"]}),scheme:{constants:["#f","#t"],identifierExtra:"-*?!<>=/",keywords:["begin","cond","define","do","else","if","lambda","let","let*","letrec","quote","set!"],lineComments:[";"],strings:[{escape:"\\",open:'"'}]},shell:Xe({builtins:["cd","echo","exit","export","printf","read","source"],identifierExtra:"$",keywords:["case","do","done","elif","else","esac","fi","for","function","if","in","return","then","until","while"],strings:[{escape:"\\",multiline:!0,open:'"'},{multiline:!0,open:"'"}]}),sql:{blockComments:[["/*","*/"]],caseInsensitive:!0,constants:["false","true"],functionCalls:!0,keywords:["add","all","alter","and","as","asc","begin","between","by","case","cast","column","commit","create","cross","delete","desc","distinct","drop","else","end","exists","from","full","group","having","in","index","inner","insert","into","is","join","left","like","limit","not","null","offset","on","or","order","outer","primary","references","returning","right","rollback","select","set","table","then","union","unique","update","values","view","when","where","with"],lineComments:["--"],strings:[{open:"'"},{open:'"'}],types:["bigint","boolean","bytea","date","decimal","integer","jsonb","numeric","serial","text","timestamp","uuid","varchar"]},swift:Je({constants:["false","nil","true"],keywords:["actor","as","associatedtype","async","await","break","case","catch","class","continue","default","defer","deinit","do","else","enum","extension","fallthrough","fileprivate","final","for","func","guard","if","import","in","init","inout","internal","is","lazy","let","mutating","open","operator","private","protocol","public","repeat","return","self","static","struct","subscript","super","switch","throw","throws","try","typealias","var","where","while"],types:["Any","Array","Bool","Character","Dictionary","Double","Float","Int","Optional","Set","String","UInt","Void"]}),toml:Xe({constants:["false","true"],functionCalls:!1}),tsx:et,typescript:et,vb:{caseInsensitive:!0,constants:["False","Nothing","True"],functionCalls:!0,keywords:["as","byval","case","catch","class","dim","do","each","else","elseif","end","finally","for","function","if","imports","in","loop","module","namespace","new","next","private","public","return","select","set","sub","then","throw","try","while"],lineComments:["'"],strings:[{open:'"'}],types:["Boolean","Date","Double","Integer","Long","Object","String"]},verilog:Je({keywords:["always","assign","begin","case","else","end","endcase","endmodule","for","if","initial","input","module","output","parameter","posedge","negedge"],types:["integer","logic","reg","wire"]}),vhdl:{caseInsensitive:!0,constants:["false","true"],functionCalls:!0,keywords:["architecture","begin","case","component","else","elsif","end","entity","for","function","if","is","library","loop","of","port","process","signal","then","use","when","while"],lineComments:["--"],strings:[{open:'"'}],types:["bit","boolean","integer","natural","std_logic","std_logic_vector"]},xml:nt,yaml:Xe({constants:["false","no","null","true","yes"],functionCalls:!1})},ot=(e,t)=>((e,t)=>{if(0===e.length)return[];if(!Fe(t))return[{classes:"",text:e}];const n=[],a=Re(t.keywords,t.caseInsensitive),o=Re(t.types,t.caseInsensitive),i=Re(t.constants,t.caseInsensitive),r=Re(t.builtins,t.caseInsensitive),s=e=>Pe(e)||Oe(e)||(t.identifierExtra?.includes(e)??!1);let l=0,c="";const p=()=>{0!==c.length&&(n.push({classes:"",text:c}),c="")},d=(e,t)=>{p(),n.push({classes:t,text:e})};for(;l<e.length;){const n=e.slice(l),p=e[l],u=(t.blockComments??[]).find(([e])=>n.startsWith(e));if(u){const[t,n]=u,a=e.indexOf(n,l+t.length),o=-1===a?e.length:a+n.length;d(e.slice(l,o),ze.comment),l=o;continue}if(void 0!==(t.lineComments??[]).find(e=>n.startsWith(e))){const t=e.indexOf("\n",l),n=-1===t?e.length:t;d(e.slice(l,n),ze.comment),l=n;continue}const m=(t.strings??[]).find(e=>n.startsWith(e.open));if(m){const t=Ue(e,l,m);d(e.slice(l,t),ze.string),l=t;continue}if(Oe(p)&&!(l>0&&s(e[l-1]))){const t=We(e,l);d(e.slice(l,t),ze.number),l=t;continue}if(Pe(p)||t.identifierExtra?.includes(p)){let n=l+1;for(;n<e.length&&s(e[n]);)n++;const p=e.slice(l,n),u=t.caseInsensitive?p.toLowerCase():p;a.has(u)?d(p,ze.keyword):o.has(u)?d(p,ze.type):i.has(u)?d(p,ze.number):r.has(u)||t.functionCalls&&"("===Ve(e,n)?d(p,ze.function):c+=p,l=n;continue}He(p)?(c+=p,l++):(d(p,ze.punctuation),l++)}return p(),n})(e,at[t]??{}),it={assembly:"Assembly",bash:"Bash",clojure:"Clojure",cobol:"COBOL",cpp:"C++",csharp:"C#",css:"CSS",dart:"Dart",diff:"Diff",dockerfile:"Dockerfile",erlang:"Erlang",fortran:"Fortran",go:"Go",graphql:"GraphQL",groovy:"Groovy",haskell:"Haskell",html:"HTML",java:"Java",javascript:"JavaScript",json:"JSON",jsx:"JSX",julia:"Julia",kotlin:"Kotlin",lua:"Lua",markdown:"Markdown",nginx:"Nginx",objectivec:"Objective-C",pascal:"Pascal",perl:"Perl",php:"PHP",plaintext:"Plain Text",powershell:"PowerShell",protobuf:"Protocol Buffers",python:"Python",r:"R",ruby:"Ruby",rust:"Rust",scala:"Scala",scheme:"Scheme",shell:"Shell",sql:"SQL",swift:"Swift",toml:"TOML",tsx:"TSX",typescript:"TypeScript",vb:"Visual Basic",verilog:"Verilog",vhdl:"VHDL",xml:"XML",yaml:"YAML"};function rt(e){return it[e]||"Unknown"}var st=Object.fromEntries(Object.keys(at).map(e=>[e,{name:rt(e)}])),lt={auto:"Auto",dark:"Dark",default:"Auto",dracula:"Dracula",github:"GitHub","github-dark":"GitHub Dark",light:"Light",monokai:"Monokai",solarized:"Solarized","solarized-dark":"Solarized Dark",tomorrow:"Tomorrow"};function ct(e){return lt[e]||"Unknown"}var pt=Object.fromEntries(Object.keys(lt).map(e=>[e,{name:ct(e),theme:null}])),dt=`\n/* Custom Switch Container */\n.${a.classNames.switch.container} {\n --switch-blue: #0D7EFF;\n --switch-red: #FF0D0D;\n --switch-text: var(--clepit-bg);\n --switch-white: var(--clepit-bg);\n display: flex;\n flex-direction: row;\n align-items: center;\n gap: 8px;\n}\n\n.${a.classNames.switch.container} .tgl {\n display: none;\n}\n\n.${a.classNames.switch.container} .tgl,\n.${a.classNames.switch.container} .tgl:after,\n.${a.classNames.switch.container} .tgl:before,\n.${a.classNames.switch.container} .tgl *,\n.${a.classNames.switch.container} .tgl *:after,\n.${a.classNames.switch.container} .tgl *:before,\n.${a.classNames.switch.container} .tgl + .tgl-btn {\n box-sizing: border-box;\n}\n\n.${a.classNames.switch.container} .tgl::selection,\n.${a.classNames.switch.container} .tgl:after::selection,\n.${a.classNames.switch.container} .tgl:before::selection,\n.${a.classNames.switch.container} .tgl *::selection,\n.${a.classNames.switch.container} .tgl *:after::selection,\n.${a.classNames.switch.container} .tgl *:before::selection,\n.${a.classNames.switch.container} .tgl + .tgl-btn::selection {\n background: none;\n}\n\n.${a.classNames.switch.container} .tgl + .tgl-btn {\n outline: 0;\n display: block;\n width: 57px;\n height: 27px;\n position: relative;\n cursor: pointer;\n user-select: none;\n font-size: 12px;\n font-weight: 400;\n color: var(--switch-white);\n}\n\n.${a.classNames.switch.container} .tgl + .tgl-btn:after,\n.${a.classNames.switch.container} .tgl + .tgl-btn:before {\n position: relative;\n display: block;\n content: "";\n width: 44%;\n height: 100%;\n}\n\n.${a.classNames.switch.container} .tgl + .tgl-btn:after {\n left: 0;\n}\n\n.${a.classNames.switch.container} .tgl + .tgl-btn:before {\n display: inline;\n position: absolute;\n top: 3px;\n}\n\n.${a.classNames.switch.container} .tgl:checked + .tgl-btn:after {\n left: 56.5%;\n}\n\n.${a.classNames.switch.container} .tgl-ios + .tgl-btn {\n background: var(--switch-red);\n border-radius: 20rem;\n padding: 2px;\n transition: all 0.4s ease;\n box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);\n}\n\n.${a.classNames.switch.container} .tgl-ios + .tgl-btn:after {\n border-radius: 2em;\n background: var(--switch-white);\n transition: left 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), padding 0.3s ease, margin 0.3s ease;\n box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.2);\n}\n\n.${a.classNames.switch.container} .tgl-ios + .tgl-btn:before {\n content: "No";\n left: 30px;\n color: var(--switch-text);\n transition: left 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);\n}\n\n.${a.classNames.switch.container} .tgl-ios + .tgl-btn:active {\n box-shadow: inset 0 0 0 30px rgba(0, 0, 0, 0.1);\n}\n\n.${a.classNames.switch.container} .tgl-ios + .tgl-btn:active:after {\n padding-right: 0.4em;\n}\n\n.${a.classNames.switch.container} .tgl-ios:checked + .tgl-btn {\n background: var(--switch-blue);\n}\n\n.${a.classNames.switch.container} .tgl-ios:checked + .tgl-btn:active {\n box-shadow: inset 0 0 0 30px rgba(0, 0, 0, 0.1);\n}\n\n.${a.classNames.switch.container} .tgl-ios:checked + .tgl-btn:active:after {\n margin-left: -0.4em;\n}\n\n.${a.classNames.switch.container} .tgl-ios:checked + .tgl-btn:before {\n content: "Yes";\n left: 6px;\n color: var(--switch-white);\n}\n\n.clepit-switch-label-text {\n font-size: 13px;\n display: flex;\n align-items: center;\n}\n`,ut=class{static create(e={}){const{checked:t=!1,onToggle:n,classNames:o,styles:i,label:r,id:s=`switch-${Math.random().toString(36).substring(2,11)}`}=e;a.injectStyles("clepit-custom-switch-styles",dt);const l=a.createStyledElement("div",a.classNames.switch.container,{classNames:o?.container,styles:i?.container}),c=a.createStyledElement("input","tgl tgl-ios",{classNames:o?.input,styles:i?.input});c.type="checkbox",c.id=s,c.checked=t;const p=a.createStyledElement("label","tgl-btn",{classNames:o?.label,styles:i?.label});if(p.setAttribute("for",s),n&&c.addEventListener("change",e=>{const t=e.target;n(t.checked)}),l.appendChild(c),l.appendChild(p),r){const e=a.createStyledElement("span","clepit-switch-label-text",{classNames:o?.labelText,styles:i?.labelText});e.textContent=r,l.appendChild(e)}return l}static getState(e){const t=e.querySelector('input[type="checkbox"]');return!!t&&t.checked}static setState(e,t){const n=e.querySelector('input[type="checkbox"]');n&&(n.checked=t)}},mt=class e{static{this.placeholder="Enter code..."}static{this.supportedLanguages=st}static{this.supportedThemes=pt}static{this.defaultLanguage="typescript"}static{this.defaultTheme="auto"}static{this.inputMap=new WeakMap}static{this.dataMap=new WeakMap}static save(t){const n=t.querySelector(`.${a.classNames.block.code.container}`),o=n.querySelector(`.${a.classNames.block.code.headerWrapper}`),i=n?.getAttribute("data-language")||e.defaultLanguage,r=n?.getAttribute("data-theme")||e.defaultTheme,s=!!o&&ut.getState(o),l=e.inputMap.get(n);if(l){const t=l.value,a=e.dataMap.get(n),o={code:t.trim()||"",language:i,showCopy:s,theme:r};return a?.variants?.length&&(o.variants=a.variants),a?.syncKey&&(o.syncKey=a.syncKey),e.dataMap.set(n,o),o}return{...e.dataMap.get(n)||{code:"",language:e.defaultLanguage,theme:e.defaultTheme},showCopy:s}}static addVariant(e){const t=e.variants?.length?e.variants:[{code:e.code,...e.language?{language:e.language}:{}}];return{...e,variants:[...t,{code:""}]}}static removeVariant(e,t){const n=(e.variants??[]).filter((e,n)=>n!==t),a=n[0],o={...e,code:a?.code??e.code,...a?.language?{language:a.language}:{}};if(n.length<=1){const{variants:e,...t}=o;return t}return{...o,variants:n}}static render(t,n,o,i){a.injectStyles("clepit-code-input-styles",Te);const r={code:"",language:i?.language||e.defaultLanguage,showCopy:!0,theme:i?.theme||e.defaultTheme},s=n?{...r,...n}:r,c=a.createStyledElement("div",a.classNames.block.code.container,{classNames:o?.classNames?.container,styles:o?.styles?.container});c.setAttribute("data-language",s.language||e.defaultLanguage),c.setAttribute("data-theme",s.theme||e.defaultTheme);const p=a.createStyledElement("div",a.classNames.block.code.headerWrapper,{classNames:o?.classNames?.header?.wrapper,styles:o?.styles?.header?.wrapper}),d=a.createStyledElement("div",a.classNames.block.code.header,{classNames:o?.classNames?.header?.text,styles:o?.styles?.header?.text}),u=st[s.language]?.name||rt(e.defaultLanguage),m=pt[s.theme]?.name||ct(e.defaultTheme);d.textContent=e.getHeaderText(u,m);const h=a.createStyledElement("div",a.classNames.block.code.editor,{classNames:o?.classNames?.container,styles:o?.styles?.container});h.setAttribute("data-placeholder",e.placeholder);const g=t?l.getState().getInstance(t):null,b=g?.config.classNames?.switch,f=g?.config.styles?.switch,y=ut.create({checked:s.showCopy||!1,classNames:b,label:"Allow copy",onToggle:t=>{const n=e.dataMap.get(c)||{code:"",language:e.defaultLanguage,theme:e.defaultTheme};e.dataMap.set(c,{...n,showCopy:t}),sr.saveBlockData(c)},styles:f});return p.appendChild(d),p.appendChild(y),c.appendChild(p),c.appendChild(h),e.mountEditor(c,h,s),c}static mountEditor(t,n,a){const o=a.language??e.defaultLanguage,i=document.createElement("pre");i.className="clepit-code-highlight",i.setAttribute("aria-hidden","true");const r=document.createElement("code");i.appendChild(r);const s=document.createElement("textarea");s.className="clepit-code-input",s.value=a.code??"",s.spellcheck=!1,s.autocapitalize="off",s.setAttribute("autocorrect","off"),s.setAttribute("data-testid","code-input"),s.setAttribute("aria-label",`${rt(o)} code`),s.placeholder=e.placeholder,n.replaceChildren(i,s),e.inputMap.set(t,s),e.dataMap.set(t,a),e.paint(t,r,s.value),s.addEventListener("input",()=>{e.paint(t,r,s.value);const n=e.dataMap.get(t)??{code:"",language:t.getAttribute("data-language")||e.defaultLanguage,theme:t.getAttribute("data-theme")||e.defaultTheme};e.dataMap.set(t,{...n,code:s.value}),sr.saveBlockData(t)}),s.addEventListener("scroll",()=>{i.scrollTop=s.scrollTop,i.scrollLeft=s.scrollLeft}),s.addEventListener("keydown",n=>e.handleKeydown(t,s,n))}static paint(t,n,a){const o=t.getAttribute("data-language")||e.defaultLanguage;n.replaceChildren(...ot(a.endsWith("\n")?`${a} `:a,o).map(e=>{const t=document.createElement("span");return e.classes&&(t.className=e.classes),t.textContent=e.text,t}))}static updateLanguage(t,n){const o=t.querySelector(`.${a.classNames.block.code.container}`);if(!o)return;const i=t.querySelector(`.${a.classNames.block.code.editor}`);if(!i)return;o.setAttribute("data-language",n);const r=o.querySelector(`.${a.classNames.block.code.header}`),s=o.getAttribute("data-theme")||e.defaultTheme,l=ct(s),c=rt(n);r&&(r.textContent=e.getHeaderText(c,l));const p=e.inputMap.get(o);p&&e.mountEditor(o,i,{code:p.value,language:n,theme:s}),sr.saveBlockData(o)}static updateTheme(t,n){const o=t.querySelector(`.${a.classNames.block.code.container}`);if(!o)return;const i=t.querySelector(`.${a.classNames.block.code.editor}`);if(!i)return;o.setAttribute("data-theme",n);const r=o.querySelector(`.${a.classNames.block.code.header}`),s=o.getAttribute("data-language")||e.defaultLanguage,l=rt(s),c=ct(n);r&&(r.textContent=e.getHeaderText(l,c));const p=e.inputMap.get(o);p&&e.mountEditor(o,i,{code:p.value,language:s,theme:n}),sr.saveBlockData(o)}static handleKeydown(e,t,n){const o=e.closest(`.${a.classNames.block.container}`);if(!o)return;const i=sr.getEditorId(o);if(!i)return;const r=sr.getBlockIndex(i,o.getAttribute("data-id")),s=n.metaKey||n.ctrlKey;return"Enter"!==n.key||n.shiftKey?"Backspace"===n.key&&s||"Delete"===n.key&&s?(n.preventDefault(),void sr.removeBlock(i,r)):"Backspace"!==n.key||""!==t.value.trim()?"ArrowUp"===n.key?(n.preventDefault(),void(n.shiftKey?sr.moveBlock(i,r,r-1):sr.focusBlock(o.previousElementSibling))):void("ArrowDown"===n.key&&(n.preventDefault(),n.shiftKey?sr.moveBlock(i,r,r+1):sr.focusBlock(o.nextElementSibling))):void sr.removeBlock(i,r):(n.preventDefault(),void sr.insertBlock({data:{html:""},type:"paragraph"},i,r+1))}static getHeaderText(e,t){return`${e} | ${t}`}static isEmpty(t){const n=t.querySelector(`.${a.classNames.block.code.container}`);if(!n)return!0;const o=e.inputMap.get(n);return!o||Boolean(o.value?.trim())}static isEmptyData(e){return M(e.code)}static destroy(t){const n=document.getElementById(t);if(!n)return console.warn("CodeInput::destroy: Container not found for containerId:",t);n.querySelectorAll(`.${a.classNames.block.code.container}`).forEach(t=>{e.inputMap.delete(t),e.dataMap.delete(t)})}},ht=".clepit-output-code-container",gt=(e,t)=>[`${e} { background: ${t.background}; color: ${t.text}; }`,...je.map(n=>`${e} .clepit-code-${n} { color: ${t[n]};${(e=>"comment"===e?" font-style: italic;":"")(n)} }`)].join("\n"),bt=()=>[gt(ht,{background:"var(--clepit-code-bg)",comment:"var(--clepit-code-comment)",function:"var(--clepit-code-function)",gutter:"var(--clepit-code-gutter)",keyword:"var(--clepit-code-keyword)",number:"var(--clepit-code-number)",punctuation:"var(--clepit-code-punctuation)",selection:"var(--clepit-code-selection-bg)",string:"var(--clepit-code-string)",text:"var(--clepit-code-text)",type:"var(--clepit-code-type)"}),...Object.entries(_e).map(([e,t])=>gt(`${ht}[data-theme='${e}']`,t))].join("\n"),ft="clepit:code-variant-sync",yt=e=>`clepit.code-variant.${e}`,vt=(e,t)=>e.label?e.label:e.language?it[e.language]??e.language:`Tab ${t+1}`,xt=(e,t)=>{if(!t)return 0;const n=e.findIndex((e,n)=>vt(e,n)===t);return-1===n?0:n},kt=e=>{if(!e||"undefined"==typeof localStorage)return null;try{return localStorage.getItem(yt(e))}catch{return null}},wt="http://www.w3.org/2000/svg",Ct=e=>e.variants?.length?e.variants:[{code:e.code,language:e.language}],Et=class e{static{this.eventListenersMap=new WeakMap}static draw(t,n=ue,a){if(!e.validate(t)||mt.isEmptyData(t))return null;const o=Ct(t),i=o.length>1,r=Math.min(Math.max(a?.activeVariant??0,0),o.length-1),s=n.create("div");s.addClass("clepit-output-code-container"),s.setAttribute("data-theme",t.theme??mt.defaultTheme),t.syncKey&&s.setAttribute("data-sync-key",t.syncKey);const l=n.create("div");if(l.addClass("clepit-output-code-header"),i){const e=n.create("div");e.addClass("clepit-output-code-tabs"),e.setAttribute("role","tablist"),e.setAttribute("data-testid","code-variant-tabs"),o.forEach((t,a)=>{const o=n.create("button");o.addClass("clepit-output-code-tab"),o.setAttribute("type","button"),o.setAttribute("role","tab"),o.setAttribute("aria-selected",a===r?"true":"false"),o.setAttribute("tabindex",a===r?"0":"-1"),o.setAttribute("data-testid",`code-variant-tab-${a}`),o.setText(vt(t,a)),e.append(o)}),l.append(e)}else{const e=n.create("span");e.setText(it[t.language??"typescript"]??"TypeScript"),l.append(e)}if(t.showCopy){const e=n.create("button");e.addClass("clepit-output-code-copy-btn"),e.setAttribute("type","button"),e.setAttribute("aria-label","Copy code"),e.append((e=>{const t=e.createNS(wt,"svg");t.setAttribute("class","clepit-copy-icon"),t.setAttribute("width","16"),t.setAttribute("height","16"),t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("fill","none");const n=e.createNS(wt,"path");return n.setAttribute("d","M7.5 3H14.6C16.8402 3 17.9603 3 18.816 3.43597C19.5686 3.81947 20.1805 4.43139 20.564 5.18404C21 6.03969 21 7.15979 21 9.4V16.5M6.2 21H14.3C15.4201 21 15.9802 21 16.408 20.782C16.7843 20.5903 17.0903 20.2843 17.282 19.908C17.5 19.4802 17.5 18.9201 17.5 17.8V9.7C17.5 8.57989 17.5 8.01984 17.282 7.59202C17.0903 7.21569 16.7843 6.90973 16.408 6.71799C15.9802 6.5 15.4201 6.5 14.3 6.5H6.2C5.0799 6.5 4.51984 6.5 4.09202 6.71799C3.71569 6.90973 3.40973 7.21569 3.21799 7.59202C3 8.01984 3 8.57989 3 9.7V17.8C3 18.9201 3 19.4802 3.21799 19.908C3.40973 20.2843 3.71569 20.5903 4.09202 20.782C4.51984 21 5.0799 21 6.2 21Z"),n.setAttribute("stroke","var(--clepit-svg-stroke-color)"),n.setAttribute("stroke-width","2"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),t.append(n),t})(n)),l.append(e)}s.append(l);const c=n.create("div");return c.addClass("clepit-output-code-editor"),i&&c.setAttribute("role","tabpanel"),o.forEach((e,a)=>{const o=n.create("pre");o.addClass("clepit-output-code-pane"),o.setAttribute("data-variant-index",String(a)),a!==r&&o.setAttribute("hidden","");const i=n.create("code");for(const r of ot(e.code??t.code,e.language??t.language??"plaintext")){const e=n.create("span");r.classes&&e.addClass(...r.classes.split(" ")),e.setText(r.text),i.append(e)}o.append(i),c.append(o)}),s.append(c),s}static render(t,n,o,i,r){if(a.injectStyles(qe,De),a.injectStyles(`${qe}-theme`,bt()),!e.validate(t))return xe();if(mt.isEmptyData(t))return document.createElement("div");const s=Ct(t),l=s.length>1?xt(s,kt(t.syncKey)):0,c=ve(e.draw(t,ue,{activeVariant:l}));i?.container&&c.classList.add(i.container),o?.container&&Object.assign(c.style,o.container);const p=c.querySelector(".clepit-output-code-header");return p&&i?.header?.text&&p.classList.add(i.header.text),p&&o?.header?.text&&Object.assign(p.style,o.header.text),e.attach(c,t,l,r),c}static activate(t,n){if(!e.validate(n)||mt.isEmptyData(n))return()=>{};const a=Ct(n),o=a.length>1?xt(a,kt(n.syncKey)):0;return e.attach(t,n,o,void 0,!0)}static activateFromMarkup(t){const n=[...t.querySelectorAll(".clepit-output-code-pane")];if(0===n.length)return()=>{};const a=[...t.querySelectorAll(".clepit-output-code-tab")],o=n.map((e,t)=>({code:e.textContent??"",label:a[t]?.textContent||void 0})),i=t.getAttribute("data-sync-key")??void 0,r={code:o[0]?.code??"",showCopy:null!==t.querySelector(".clepit-output-code-copy-btn"),syncKey:i,variants:o},s=o.length>1?xt(o,kt(i)):0;return e.attach(t,r,s,void 0,!0)}static attach(t,n,a,o,i=!1){const r=Ct(n),s=o?document.getElementById(o):null,c=[...t.querySelectorAll(".clepit-output-code-tab")],p=[...t.querySelectorAll(".clepit-output-code-pane")];let d=a;const u=[];let m;const h=(t,n,a)=>{if(t.addEventListener(n,a),u.push({event:n,handler:a,target:t}),s){const o=e.eventListenersMap.get(s)??[];o.push({element:t,event:n,handler:a}),e.eventListenersMap.set(s,o)}},g=(e,t)=>{if(e<0||e>=r.length)return;if(d=e,c.forEach((t,n)=>{t.setAttribute("aria-selected",n===e?"true":"false"),t.tabIndex=n===e?0:-1}),p.forEach((t,n)=>{t.hidden=n!==e}),!t||!n.syncKey)return;const a=vt(r[e],e);((e,t)=>{if(e&&"undefined"!=typeof localStorage)try{localStorage.setItem(yt(e),t)}catch{return}})(n.syncKey,a),window.dispatchEvent(new CustomEvent(ft,{detail:{label:a,syncKey:n.syncKey}}))};if(c.forEach((e,t)=>{h(e,"click",()=>g(t,!0)),h(e,"keydown",e=>{const n=e.key,a="ArrowRight"===n?1:"ArrowLeft"===n?-1:0,o="Home"===n?0:"End"===n?r.length-1:0===a?-1:(t+a+r.length)%r.length;-1!==o&&(e.preventDefault(),g(o,!0),c[o]?.focus())})}),c.length>1&&n.syncKey){const t=e=>{const t=e.detail;if(!t||t.syncKey!==n.syncKey)return;const a=r.findIndex((e,n)=>vt(e,n)===t.label);-1!==a&&a!==d&&g(a,!1)};if(window.addEventListener(ft,t),u.push({event:ft,handler:t,target:window}),s){const n=e.eventListenersMap.get(s)??[];n.push({element:window,event:ft,handler:t}),e.eventListenersMap.set(s,n)}}const b=()=>{for(const{event:e,handler:t,target:n}of u)n.removeEventListener(e,t);m?.()};i&&g(a,!1);const f=t.querySelector(".clepit-output-code-copy-btn");if(!f)return b;h(f,"click",()=>{e.copyCodeToClipboard(r[d]?.code??n.code),e.animateCopyButton(f)});const y=o?l.getState().getInstance(o):null;return m=J(f,"Copy code","above",y?.config.classNames?.tooltips,y?.config.styles?.tooltips),b}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.code}static copyCodeToClipboard(e){navigator.clipboard&&window.isSecureContext?navigator.clipboard.writeText(e).catch(e=>{console.error("Failed to copy code to clipboard:",e)}):console.warn("Clipboard API not available in this context")}static animateCopyButton(e){const t=e.innerHTML;e.innerHTML='<svg class="clepit-check-icon" focusable="false" aria-hidden="true" viewBox="0 0 24 24" data-testid="CheckIcon"><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"></path></svg>',e.classList.remove("clepit-output-code-copy-btn--normal"),e.classList.add("clepit-output-code-copy-btn--animating"),setTimeout(()=>{e.innerHTML=t,e.classList.remove("clepit-output-code-copy-btn--animating"),e.classList.add("clepit-output-code-copy-btn--normal")},1e3)}static destroy(t){const n=document.getElementById(t);if(!n)return console.warn("CodeOutput::destroy: Container not found for containerId:",t);const a=e.eventListenersMap.get(n);a&&(a.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap.delete(n))}},St={icon:"𝕔",get input(){return mt},label:"Code",get output(){return Et},shortcut:v("C"),testId:"block-type-code",type:"code"},Nt="\n.clepit-collapsible {\n display: block;\n}\n.clepit-collapsible > summary {\n display: flex;\n align-items: flex-start;\n gap: 6px;\n cursor: pointer;\n font-weight: 600;\n list-style: none;\n}\n.clepit-collapsible > summary::-webkit-details-marker {\n display: none;\n}\n.clepit-collapsible > summary::before {\n content: '';\n flex: 0 0 auto;\n width: 8px;\n height: 8px;\n margin-top: 7px;\n border-right: 2px solid currentColor;\n border-bottom: 2px solid currentColor;\n transform: rotate(-45deg);\n transition: transform 120ms ease;\n}\n.clepit-collapsible[open] > summary::before {\n transform: rotate(45deg);\n}\n.clepit-collapsible__children {\n padding-left: 22px;\n}\n.clepit-collapsible__children > * + * {\n margin-top: 8px;\n}\n",At=`${Nt}\n.clepit-collapsible__title-input {\n border: none;\n outline: none;\n background: transparent;\n font: inherit;\n font-weight: 600;\n width: 100%;\n}\n.clepit-collapsible__add-child {\n border: none;\n background: transparent;\n cursor: pointer;\n font: inherit;\n opacity: 0.6;\n padding: 4px 0;\n}\n.clepit-collapsible__add-child:hover {\n opacity: 1;\n}\n.clepit-collapsible__child-row {\n display: flex;\n align-items: flex-start;\n gap: 4px;\n}\n.clepit-collapsible__child-row > :first-child {\n flex: 1 1 auto;\n}\n.clepit-collapsible__remove-child {\n border: none;\n background: transparent;\n cursor: pointer;\n opacity: 0.4;\n padding: 2px;\n}\n.clepit-collapsible__remove-child:hover {\n opacity: 1;\n}\n`,Lt=Nt,Bt=new WeakMap;var $t=class e{static{this.placeholder="Section title"}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.classList.contains("clepit-collapsible")?e:e.querySelector(".clepit-collapsible");if(!t)return{children:[],html:"",open:!1};const n=t.querySelector(".clepit-collapsible__title"),a=t.open??!1,o=Bt.get(t)??[],i=[];return t.querySelectorAll(".clepit-collapsible__child").forEach((e,t)=>{const n=o[t],a=e.getAttribute("data-child-type")??n?.type,r=a?function(e){return Qi.find(t=>t.type===e)}(a):void 0;if(r){const t=r.input.save(e);i.push({...n?.id?{id:n.id}:{},data:t,type:r.type})}else n&&i.push(n)}),{children:i,html:I(n?.innerHTML),open:a}}static render(t,n,o){a.injectStyles("collapsible-input",At);const i={children:[],html:"",open:!0},r=n?{...i,...n}:i,s=a.createStyledElement("details","clepit-collapsible clepit-collapsible--input",{classNames:o?.classNames?.section,styles:o?.styles?.section});s.open=r.open??!0,Bt.set(s,[...r.children??[]]);const l=document.createElement("summary"),c=document.createElement("span");c.className="clepit-collapsible__title",c.setAttribute("contenteditable","true"),c.setAttribute("data-placeholder",e.placeholder),r.html&&(c.innerHTML=I(r.html)),l.appendChild(c),s.appendChild(l);const p=document.createElement("div");return p.className="clepit-collapsible__children",(r.children??[]).forEach(n=>{p.appendChild(e.renderChild(t,n))}),s.appendChild(p),e.addEventListener(t,c,"keydown",sr.handleKeydown),e.addEventListener(t,c,"input",sr.handleInput),s}static renderChild(e,t){const n=document.createElement("div");n.className="clepit-collapsible__child";const a=sr.renderTool(t.type,t.data,e);if(a)n.setAttribute("data-child-type",t.type),n.appendChild(a);else{const e=document.createElement("div");e.className="clepit-collapsible__unknown-child",e.textContent=`Unsupported block: ${t.type}`,n.appendChild(e)}return n}static isEmpty(e){const t=e.querySelector(".clepit-collapsible");if(!t)return!0;const n=t.querySelector(".clepit-collapsible__title"),a=t.querySelectorAll(".clepit-collapsible__child").length>0;return M(n?.innerHTML)&&!a}static isEmptyData(e){return M(e.html)&&0===(e.children??[]).length}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Mt="\n.clepit-collection {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 12px;\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n color: inherit;\n}\n.clepit-collection__icon {\n font-size: 18px;\n line-height: 1;\n}\n.clepit-collection__label {\n opacity: 0.7;\n}\n",It=Mt,Tt=Mt,qt=class e{static render(t,n,o,i){if(a.injectStyles("collection-output",Tt),!e.validate(t))return xe();const r=a.createStyledElement("div","clepit-collection clepit-output-collection",{classNames:i?.wrapper,styles:o?.wrapper});r.setAttribute("data-collection-id",t.collectionId);const s=document.createElement("span");s.className="clepit-collection__icon",s.textContent="▦",r.appendChild(s);const l=document.createElement("span");return l.className="clepit-collection__label",l.textContent="Collection",r.appendChild(l),r}static draw(t,n=ue){if(!e.validate(t))return null;const a=n.create("div");a.addClass("clepit-collection","clepit-output-collection"),a.setAttribute("data-collection-id",t.collectionId);const o=n.create("span");o.addClass("clepit-collection__icon"),o.setText("▦"),a.append(o);const i=n.create("span");return i.addClass("clepit-collection__label"),i.setText("Collection"),a.append(i),a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.collectionId&&e.collectionId.length>0}},Dt="\n.clepit-columns {\n display: flex;\n gap: 16px;\n align-items: flex-start;\n}\n.clepit-columns__column {\n flex: 1 1 0;\n min-width: 0;\n}\n.clepit-columns__column > * + * {\n margin-top: 8px;\n}\n@media (max-width: 640px) {\n .clepit-columns {\n flex-direction: column;\n }\n}\n",_t=`${Dt}\n.clepit-columns__add-child,\n.clepit-columns__add-column {\n border: none;\n background: transparent;\n cursor: pointer;\n font: inherit;\n opacity: 0.6;\n padding: 4px 0;\n}\n.clepit-columns__add-child:hover,\n.clepit-columns__add-column:hover {\n opacity: 1;\n}\n`,jt=Dt,zt=class e{static render(t,n,o,i){if(a.injectStyles("columns-output",jt),!e.validate(t))return xe();const r=a.createStyledElement("div","clepit-columns clepit-output-columns",{classNames:i?.container,styles:o?.container});for(const s of t.columns){const t=a.createStyledElement("div","clepit-columns__column",{classNames:i?.column,styles:o?.column});for(const a of s)t.appendChild(e.renderChild(a,n));r.appendChild(t)}return r}static renderChild(e,t){const n=Qi.find(t=>t.type===e.type);if(!n){const t=document.createElement("div");return t.className="clepit-columns__unknown-child",t.textContent=`Unsupported block: ${e.type}`,t}return n.output.render(e.data,t)}static draw(t,n=ue,a){if(!e.validate(t))return null;const o=n.create("div");o.addClass("clepit-columns","clepit-output-columns");for(const e of t.columns){const t=n.create("div");t.addClass("clepit-columns__column");for(const o of e){const e=ai(o,n,a);e&&t.append(e)}o.append(t)}return o}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&Array.isArray(e.columns)&&e.columns.length>=2&&e.columns.length<=4&&e.columns.every(e=>Array.isArray(e))}},Ot="\n.clepit-date {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n padding: 2px 8px;\n border-radius: 6px;\n background: rgba(127, 127, 127, 0.12);\n font-variant-numeric: tabular-nums;\n}\n",Ht=`${Ot}\n.clepit-date--input {\n cursor: pointer;\n border: none;\n font: inherit;\n}\n`,Pt=Ot,Ft=/^(\d{4})-(\d{2})-(\d{2})$/;function Rt(e){const t=Ft.exec(e.trim());if(!t)return null;const n=Number(t[1]),a=Number(t[2]),o=Number(t[3]),i=new Date(Date.UTC(n,a-1,o));return i.getUTCFullYear()!==n||i.getUTCMonth()!==a-1||i.getUTCDate()!==o?null:i}var Vt=class e{static render(t,n,o,i){a.injectStyles("date-output",Pt);const r=e.validate(t)?Rt(t.date):null;if(!r)return xe();const s=a.createStyledElement("time","clepit-date clepit-output-date",{classNames:i?.pill,styles:o?.pill});return s.dateTime=t.date,s.textContent=new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeZone:"UTC"}).format(r),s}static draw(t,n=ue){const a=e.validate(t)?Rt(t.date):null;if(!a)return null;const o=n.create("time");return o.addClass("clepit-date","clepit-output-date"),o.setAttribute("datetime",t.date),o.setText(new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeZone:"UTC"}).format(a)),o}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.date}},Ut='\n/* Output delimiter styles */\n.clepit-output-delimiter {\n margin: 2rem 0;\n text-align: center;\n}\n\n.clepit-output-delimiter[data-variant="stars"] {\n font-size: 1.5rem;\n font-weight: 300;\n letter-spacing: 8px;\n margin: 0; /* Remove margin for star variant */\n}\n\n.clepit-output-delimiter hr[data-variant="line"] {\n border: none;\n height: 2px;\n background: linear-gradient(to right, transparent, var(--clepit-border), transparent);\n margin: 20px 0;\n}\n\n.clepit-output-delimiter[data-variant="line"] {\n margin: 0; /* Remove container margin for line variant */\n}\n',Wt=class e{static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){return{variant:e.querySelector(".clepit-delimiter")?.getAttribute("data-variant")||"line"}}static render(t,n,o){a.injectStyles("clepit-delimiter-input-styles",'\n/* Delimiter block styles */\n.clepit-delimiter-container {\n margin: 0.5rem 0;\n text-align: center;\n}\n\n.clepit-delimiter {\n border: none;\n height: 2px;\n background: linear-gradient(to right, transparent, var(--clepit-border), transparent);\n margin: 20px 0;\n}\n\n.clepit-delimiter[data-variant="stars"] {\n height: auto;\n background: none;\n font-size: 24px;\n letter-spacing: 8px;\n margin: 0; /* Remove margin for star variant */\n}\n\n');const i={variant:"line"},r=n?{...i,...n}:i,s=a.createStyledElement("div","clepit-delimiter-container",{classNames:o?.classNames?.[r.variant],styles:o?.styles?.[r.variant]});if(s.setAttribute("contenteditable","true"),s.setAttribute("tabindex","0"),"stars"===r.variant){const e=a.createStyledElement("div","clepit-delimiter",{classNames:o?.classNames?.[r.variant],styles:o?.styles?.[r.variant]});e.setAttribute("data-variant",r.variant),e.textContent="***",s.appendChild(e)}else{const e=a.createStyledElement("hr","clepit-delimiter",{classNames:o?.classNames?.[r.variant],styles:o?.styles?.[r.variant]});e.setAttribute("data-variant",r.variant),s.appendChild(e)}return e.addEventListener(t,s,"keydown",e=>{const n=e,o=s.closest(`.${a.classNames.block.container}`);if(!o)return;const i=sr.getBlockIndex(t,o.getAttribute("data-id")),r=n.metaKey||n.ctrlKey;if(n.shiftKey)switch(n.key){case"ArrowUp":e.preventDefault(),e.stopPropagation(),i>0&&sr.moveBlock(t,i,i-1);break;case"ArrowDown":e.preventDefault(),e.stopPropagation();const n=sr.getBlocks(t);n&&i<n.length-1&&sr.moveBlock(t,i,i+1)}else if(r)switch(n.key){case"Delete":case"Backspace":e.preventDefault(),e.stopPropagation(),sr.removeBlock(t,i)}else if("Enter"===n.key)n.preventDefault(),n.stopPropagation(),sr.insertBlock({data:{html:""},type:"paragraph"},t,i+1);else if("Backspace"===n.key)n.preventDefault(),n.stopPropagation(),sr.removeBlock(t,i);else{sr.ensureActiveBlock(t);const a=sr.getBlocks(t);switch(n.key){case"ArrowUp":if(e.preventDefault(),e.stopPropagation(),i>0){const e=a[i-1];e&&sr.focusBlock(e)}return;case"ArrowDown":if(e.preventDefault(),e.stopPropagation(),i<a.length-1){const e=a[i+1];e&&sr.focusBlock(e)}return}}}),s.focus(),s}static changeVariant(t,n,o){const i=l.getState().getInstance(o);if(!i)return;if(t.getAttribute("data-variant")===n)return;const r={variant:n},s={classNames:i.config.classNames?.blocks?.delimiter,styles:i.config.styles?.blocks?.delimiter},c=sr.getBlockIndex(o,t.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id")),p=e.render(o,r,s);t.replaceWith(p),l.getState().updateBlockData(o,c,r)}static isEmpty(e){return!1}static isEmptyData(e){return!1}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Kt=class e{static render(t,n,o,i){if(a.injectStyles("clepit-delimiter-output-styles",Ut),!e.validate(t))return xe();if(Wt.isEmptyData(t))return document.createElement("div");const r=t.variant,s=a.createStyledElement("div","clepit-output-delimiter",{classNames:i?.[r],styles:o?.[r]});if("stars"===r)s.innerHTML="***",s.setAttribute("data-variant","stars");else{const e=document.createElement("hr");e.setAttribute("data-variant","line"),e.className="clepit-delimiter",s.appendChild(e)}return s}static draw(t,n=ue){if(!e.validate(t)||Wt.isEmptyData(t))return null;const a=n.create("div");if(a.addClass("clepit-output-delimiter"),"stars"===t.variant)return a.setHtml("***"),a.setAttribute("data-variant","stars"),a;const o=n.create("hr");return o.setAttribute("data-variant","line"),o.addClass("clepit-delimiter"),a.append(o),a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.variant}},Gt="\n.clepit-doc-card {\n display: flex;\n align-items: flex-start;\n gap: 10px;\n padding: 12px;\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n cursor: pointer;\n color: inherit;\n text-decoration: none;\n}\n.clepit-doc-card:hover {\n background: rgba(127, 127, 127, 0.08);\n}\n.clepit-doc-card__icon {\n font-size: 20px;\n line-height: 1;\n}\n.clepit-doc-card__title {\n font-weight: 600;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.clepit-doc-card__description {\n opacity: 0.7;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n overflow: hidden;\n}\n",Jt=Gt,Xt=Gt,Zt=class e{static render(t,n,o,i){if(a.injectStyles("doc-card-output",Xt),!e.validate(t))return xe();const r=a.createStyledElement("a","clepit-doc-card clepit-output-doc-card",{classNames:i?.card,styles:o?.card});r.setAttribute("data-page-id",t.pageId),n?.docHref&&(r.href=n.docHref(t.pageId));const s=document.createElement("span");s.className="clepit-doc-card__icon",s.textContent=t.icon??"📄",r.appendChild(s);const l=document.createElement("span"),c=document.createElement("span");if(c.className="clepit-doc-card__title",c.textContent=t.title||"Untitled",l.appendChild(c),t.description){const e=document.createElement("span");e.className="clepit-doc-card__description",e.textContent=t.description,l.appendChild(e)}return r.appendChild(l),r}static draw(t,n=ue,a){if(!e.validate(t))return null;const o=n.create("a");o.addClass("clepit-doc-card","clepit-output-doc-card"),o.setAttribute("data-page-id",t.pageId),a?.docHref&&o.setAttribute("href",a.docHref(t.pageId));const i=n.create("span");i.addClass("clepit-doc-card__icon"),i.setText(t.icon??"📄"),o.append(i);const r=n.create("span"),s=n.create("span");if(s.addClass("clepit-doc-card__title"),s.setText(t.title||"Untitled"),r.append(s),t.description){const e=n.create("span");e.addClass("clepit-doc-card__description"),e.setText(t.description),r.append(e)}return o.append(r),o}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.pageId&&e.pageId.length>0&&"string"==typeof e.title}},Yt="\n.clepit-embed {\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n overflow: hidden;\n}\n.clepit-embed__frame {\n display: block;\n width: 100%;\n border: 0;\n}\n.clepit-embed-card {\n display: flex;\n align-items: flex-start;\n gap: 10px;\n padding: 12px;\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n color: inherit;\n text-decoration: none;\n}\n.clepit-embed-card:hover {\n background: rgba(127, 127, 127, 0.08);\n}\n.clepit-embed-card__title {\n font-weight: 600;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.clepit-embed-card__description {\n opacity: 0.7;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n overflow: hidden;\n}\n",Qt=Yt,en=Yt,tn=["http:","https:"],nn=["youtube.com","www.youtube.com","m.youtube.com","youtu.be"],an=["file","design","board","proto","slides","deck"],on=(e,t="link")=>({embedUrl:null,provider:t,url:e});function rn(e,t){return e===t||e.endsWith(`.${t}`)}function sn(e,t){const n=function(e){try{const t=new URL(e);return tn.includes(t.protocol)?t:null}catch{return null}}(e);if(!n)return{embedUrl:null,provider:"invalid",url:e};const a=n.hostname.toLowerCase(),o=n.toString();if(nn.includes(a)){const e=function(e){if(rn(e.hostname,"youtu.be"))return e.pathname.slice(1).split("/")[0]||null;if("/watch"===e.pathname)return e.searchParams.get("v");const t=e.pathname.match(/^\/(?:embed|shorts|live)\/([^/]+)/);return t?t[1]:null}(n);return e?{aspect:16/9,embedUrl:`https://www.youtube.com/embed/${encodeURIComponent(e)}`,provider:"youtube",url:o}:on(o,"youtube")}if(rn(a,"figma.com")){const[,e,t]=n.pathname.split("/");return e&&t&&an.includes(e)?{aspect:4/3,embedUrl:`https://embed.figma.com/${"file"===e?"design":e}/${encodeURIComponent(t)}?embed-host=clepit`,provider:"figma",url:o}:on(o,"figma")}if(rn(a,"miro.com")){const e=n.pathname.match(/^\/app\/board\/([^/]+)/);return e?{aspect:16/9,embedUrl:`https://miro.com/app/live-embed/${encodeURIComponent(e[1])}`,provider:"miro",url:o}:on(o,"miro")}if(rn(a,"airtable.com")){const e=n.pathname.match(/^\/embed\/([^/]+)/),t=n.pathname.match(/^\/(shr[^/]+)/),a=e?.[1]??t?.[1];return a?{aspect:4/3,embedUrl:`https://airtable.com/embed/${encodeURIComponent(a)}`,provider:"airtable",url:o}:on(o,"airtable")}if(rn(a,"diagrams.net")||rn(a,"drawio.com"))return{aspect:4/3,embedUrl:`https://viewer.diagrams.net/?edit=_blank&layers=1&nav=1#U${encodeURIComponent(o)}`,provider:"drawio",url:o};if(rn(a,"google.com")&&n.pathname.startsWith("/maps")){const e=t?.mapsEmbedKey,a=n.searchParams.get("q");return e&&a?{aspect:4/3,embedUrl:`https://www.google.com/maps/embed/v1/place?key=${encodeURIComponent(e)}&q=${encodeURIComponent(a)}`,provider:"googleMaps",url:o}:on(o,"googleMaps")}return on(o)}var ln="allow-scripts allow-same-origin allow-presentation allow-forms",cn=class e{static render(t,n,o,i){if(a.injectStyles("embed-output",en),!e.validate(t))return xe();const r=sn(t.url,{mapsEmbedKey:n?.mapsEmbedKey});return"invalid"===r.provider?xe():r.embedUrl?e.frame(r.embedUrl,r.aspect,o,i):e.card(t,r.url,o,i)}static draw(t,n=ue,a){if(!e.validate(t))return null;const o=sn(t.url,{mapsEmbedKey:a?.mapsEmbedKey});return"invalid"===o.provider?null:o.embedUrl?e.drawFrame(o.embedUrl,o.aspect,n):e.drawCard(t,o.url,n)}static drawFrame(e,t,n){const a=n.create("div");a.addClass("clepit-embed","clepit-output-embed");const o=n.create("iframe");return o.addClass("clepit-embed__frame"),o.setAttribute("src",e),o.setAttribute("sandbox",ln),o.setAttribute("referrerpolicy","no-referrer"),o.setAttribute("loading","lazy"),o.setAttribute("allowfullscreen","true"),o.setAttribute("style",`aspect-ratio: ${t??16/9};`),a.append(o),a}static drawCard(e,t,n){const a=n.create("a");a.addClass("clepit-embed-card","clepit-output-embed"),a.setAttribute("href",t),a.setAttribute("rel","noopener noreferrer nofollow"),a.setAttribute("target","_blank");const o=n.create("span"),i=n.create("span");if(i.addClass("clepit-embed-card__title"),i.setText(e.title||t),o.append(i),e.description){const t=n.create("span");t.addClass("clepit-embed-card__description"),t.setText(e.description),o.append(t)}return a.append(o),a}static frame(e,t,n,o){const i=a.createStyledElement("div","clepit-embed clepit-output-embed",{classNames:o?.wrapper,styles:n?.wrapper}),r=document.createElement("iframe");return r.className="clepit-embed__frame",r.src=e,r.setAttribute("sandbox",ln),r.setAttribute("referrerpolicy","no-referrer"),r.setAttribute("loading","lazy"),r.setAttribute("allowfullscreen","true"),r.style.aspectRatio=String(t??16/9),i.appendChild(r),i}static card(e,t,n,o){const i=a.createStyledElement("a","clepit-embed-card clepit-output-embed",{classNames:o?.card,styles:n?.card});i.href=t,i.rel="noopener noreferrer nofollow",i.target="_blank";const r=document.createElement("span"),s=document.createElement("span");if(s.className="clepit-embed-card__title",s.textContent=e.title||t,r.appendChild(s),e.description){const t=document.createElement("span");t.className="clepit-embed-card__description",t.textContent=e.description,r.appendChild(t)}return i.appendChild(r),i}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.url&&e.url.length>0}},pn="\n.clepit-file {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 10px 12px;\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n color: inherit;\n text-decoration: none;\n}\n.clepit-file:hover {\n background: rgba(127, 127, 127, 0.08);\n}\n.clepit-file__name {\n font-weight: 500;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.clepit-file__size {\n opacity: 0.6;\n font-size: 12px;\n}\n",dn=`${pn}\n.clepit-file__upload {\n border: 1px dashed rgba(127, 127, 127, 0.5);\n background: transparent;\n cursor: pointer;\n font: inherit;\n padding: 10px 12px;\n border-radius: 8px;\n}\n`,un=pn;function mn(e){return null==e?"":e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}var hn=class e{static render(t,n,o,i){if(a.injectStyles("file-output",un),!e.validate(t))return xe();const r=a.createStyledElement("a","clepit-file clepit-output-file",{classNames:i?.row,styles:o?.row});r.href=t.url,r.setAttribute("download",t.name),r.setAttribute("rel","noopener noreferrer");const s=document.createElement("span");s.className="clepit-file__name",s.textContent=t.name,r.appendChild(s);const l=mn(t.size);if(l){const e=document.createElement("span");e.className="clepit-file__size",e.textContent=l,r.appendChild(e)}return r}static draw(t,n=ue){if(!e.validate(t))return null;const a=n.create("a");a.addClass("clepit-file","clepit-output-file"),a.setAttribute("href",t.url),a.setAttribute("download",t.name),a.setAttribute("rel","noopener noreferrer");const o=n.create("span");o.addClass("clepit-file__name"),o.setText(t.name),a.append(o);const i=mn(t.size);if(i){const e=n.create("span");e.addClass("clepit-file__size"),e.setText(i),a.append(e)}return a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&("string"==typeof e.url&&0!==e.url.length&&("string"==typeof e.name&&0!==e.name.length&&/^https?:\/\//i.test(e.url)))}},gn='\n.clepit-glance {\n background: var(--clepit-surface);\n border: 1px solid var(--clepit-border);\n border-radius: 8px;\n padding: 12px 14px;\n}\n\n/* A variant tints the surface only. Text keeps the reading colours the rest of\n * the page uses, so a glance stays as legible as the prose around it. */\n.clepit-glance[data-variant="info"] {\n background: var(--clepit-primary-bg);\n}\n\n.clepit-glance[data-variant="success"] {\n background: var(--clepit-success-bg);\n}\n\n.clepit-glance[data-variant="warning"] {\n background: var(--clepit-warning-bg);\n}\n\n.clepit-glance[data-variant="error"] {\n background: var(--clepit-error-bg);\n}\n\n.clepit-glance-caption {\n color: var(--clepit-text-subtle);\n font-size: 11px;\n font-weight: 700;\n letter-spacing: 0.08em;\n margin: 0 0 8px;\n text-transform: uppercase;\n}\n\n/* Labels form a single vertical rail whatever their length, so the reader scans\n * one column for the question and one for the answer. */\n.clepit-glance-rows {\n column-gap: 16px;\n display: grid;\n grid-template-columns: max-content 1fr;\n margin: 0;\n row-gap: 4px;\n}\n\n.clepit-glance-label {\n color: var(--clepit-text-subtle);\n font-size: 14px;\n}\n\n.clepit-glance-value {\n color: var(--clepit-text);\n font-size: 14px;\n margin: 0;\n}\n\n.clepit-glance-value code {\n background: var(--clepit-code-bg);\n border-radius: 4px;\n font-family: \'SF Mono\', \'Monaco\', \'Roboto Mono\', monospace;\n font-size: 13px;\n padding: 1px 5px;\n}\n\n.clepit-glance-value a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-glance-value a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* A single-column stack below the narrowest tablet: a max-content label column\n * squeezes the value to a few characters once the viewport is phone width. */\n@media (max-width: 600px) {\n .clepit-glance-rows {\n grid-template-columns: 1fr;\n row-gap: 2px;\n }\n\n .clepit-glance-value {\n margin: 0 0 6px;\n }\n}\n',bn="At a glance",fn=class e{static render(t,n,o,i){if(a.injectStyles("clepit-glance-output-styles",gn),!e.validate(t))return xe();if(0===t.rows.length)return document.createElement("div");const r=a.createStyledElement("div","clepit-glance",{classNames:i?.wrapper,styles:o?.wrapper});r.setAttribute("data-variant",t.variant??"plain"),r.setAttribute("data-testid","glance");const s=B("p","clepit-glance-caption");s.textContent=t.caption?.trim()?t.caption:bn,r.appendChild(s);const l=B("dl","clepit-glance-rows");for(const e of t.rows){const t=B("dt","clepit-glance-label");t.textContent=e.label,l.appendChild(t);const n=B("dd","clepit-glance-value");n.innerHTML=I(e.html),l.appendChild(n)}return r.appendChild(l),r}static draw(t,n=ue){if(!e.validate(t)||0===t.rows.length)return null;const a=n.create("div");a.addClass("clepit-glance"),a.setAttribute("data-variant",t.variant??"plain"),a.setAttribute("data-testid","glance");const o=n.create("p");o.addClass("clepit-glance-caption"),o.setText(t.caption?.trim()?t.caption:bn),a.append(o);const i=n.create("dl");i.addClass("clepit-glance-rows");for(const e of t.rows){const t=n.create("dt");t.addClass("clepit-glance-label"),t.setText(e.label),i.append(t);const a=n.create("dd");a.addClass("clepit-glance-value"),a.setHtml(e.html),i.append(a)}return a.append(i),a}static validate(e){return null!=e&&"object"==typeof e&&(!!Array.isArray(e.rows)&&e.rows.every(e=>null!==e&&"object"==typeof e&&"string"==typeof e.label&&"string"==typeof e.html))}},yn='\n/* Output header styles */\n.clepit-output-header {\n margin: 0 0 1rem 0;\n font-weight: 600;\n color: var(--clepit-text);\n}\n\n.clepit-output-header[data-level="1"] {\n font-size: 2.5rem;\n line-height: 1.2;\n}\n\n.clepit-output-header[data-level="2"] {\n font-size: 2rem;\n line-height: 1.3;\n}\n\n.clepit-output-header[data-level="3"] {\n font-size: 1.75rem;\n line-height: 1.4;\n}\n\n.clepit-output-header[data-level="4"] {\n font-size: 1.5rem;\n line-height: 1.4;\n}\n\n.clepit-output-header[data-level="5"] {\n font-size: 1.25rem;\n line-height: 1.4;\n}\n\n.clepit-output-header[data-level="6"] {\n font-size: 1rem;\n line-height: 1.4;\n}\n\n/* Output header inline code styling */\n.clepit-output-header code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Output header marker brush effect */\n.clepit-output-header mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n\n.clepit-output-header mark::before {\n content: \'\';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 100 20\' preserveAspectRatio=\'none\'><path d=\'M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z\' fill=\'%23FFE047\'/></svg>") no-repeat center / 100% 100%;\n z-index: -1;\n}\n\n/* Output header link styles */\n.clepit-output-header a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-output-header a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Responsive Design */\n@media (max-width: 768px) {\n .clepit-output-header[data-level="1"] {\n font-size: 2rem;\n }\n\n .clepit-output-header[data-level="2"] {\n font-size: 1.75rem;\n }\n\n .clepit-output-header[data-level="3"] {\n font-size: 1.5rem;\n }\n}\n',vn=class e{static{this.placeholder="Enter heading..."}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.querySelector(`.${a.classNames.block.header}`),n=t?.getAttribute("data-level")||"h1";return{html:I(t?.innerHTML),level:n}}static render(t,n,o){a.injectStyles("clepit-header-input-styles",'\n/* Header block styles */\n.clepit-header {\n outline: none;\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0 20px;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content {\n font-weight: bold;\n margin: 16px 0 8px 0;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content h1 {\n font-size: 32px;\n margin: 0;\n color: inherit;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content h2 {\n font-size: 24px;\n margin: 0;\n color: inherit;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content h3 {\n font-size: 20px;\n margin: 0;\n color: inherit;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content h4 {\n font-size: 18px;\n margin: 0;\n color: inherit;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content h5 {\n font-size: 16px;\n margin: 0;\n color: inherit;\n}\n\n.clepit-block[data-tool="header"] .clepit-block-content h6 {\n font-size: 14px;\n margin: 0;\n color: inherit;\n}\n\n/* Header placeholder styles */\n.clepit-header[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Header link styles */\n.clepit-header a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-header a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Header inline code styling */\n.clepit-header code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Header marker brush effect */\n.clepit-header mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0; /* create stacking context so ::before sits behind text, not page */\n white-space: pre-wrap; /* ensure leading/trailing spaces inside mark render */\n}\n\n.clepit-header mark::before {\n content: \'\';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 100 20\' preserveAspectRatio=\'none\'><path d=\'M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z\' fill=\'%23FFE047\'/></svg>") no-repeat center / 100% 100%;\n z-index: -1; /* behind text but within mark\'s stacking context */\n}\n\n');const i={html:"",level:"h1"},r=n?{...i,...n}:i,s=r.level??"h1",l=a.createStyledElement(s,a.classNames.block.header,{classNames:o?.classNames?.[s],styles:o?.styles?.[s]});return l.setAttribute("data-level",s),l.setAttribute("contenteditable","true"),l.setAttribute("data-placeholder",e.placeholder),r.html?l.innerHTML=r.html:l.innerHTML="",e.addEventListener(t,l,"keydown",sr.handleKeydown),e.addEventListener(t,l,"input",sr.handleInput),l}static changeLevel(t,n,o){const i=l.getState().getInstance(o);if(!i)return;if(t.getAttribute("data-level")===n)return;const r={html:t.innerHTML,level:n},s={classNames:i.config.classNames?.blocks?.header,margins:i.config.margins,styles:i.config.styles?.blocks?.header},c=sr.getBlockIndex(o,t.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id")),p=e.render(o,r,s);t.replaceWith(p),l.getState().updateBlockData(o,c,r)}static isEmpty(e){return M(e.querySelector(`.${a.classNames.block.header}`)?.innerHTML)}static isEmptyData(e){return M(e.html)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},xn=class e{static render(t,n,o,i){if(a.injectStyles("clepit-header-output-styles",yn),!e.validate(t))return xe();if(vn.isEmptyData(t))return document.createElement("div");const r=t.html,s=t.level||"h1",l=a.createStyledElement(s,"clepit-output-header",{classNames:i?.[s],styles:o?.[s]});return r&&(l.innerHTML=r),l}static draw(t,n=ue){if(!e.validate(t)||vn.isEmptyData(t))return null;const a=n.create(t.level||"h1");return a.addClass("clepit-output-header"),t.html&&a.setHtml(t.html),a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.html}},kn=`\n/* Image block styles */\n.${a.classNames.block.image.container} {\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0;\n}\n\n.clepit-image-caption {\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0;\n}\n\n.clepit-block[data-tool="image"] .clepit-block-content {\n text-align: center;\n}\n\n.clepit-block[data-tool="image"] .clepit-block-content img {\n max-width: 100%;\n height: auto;\n border-radius: 4px;\n}\n\n/* Image Block Enhanced Styles */\n.${a.classNames.block.image.container} {\n margin: 16px 0;\n text-align: center;\n min-height: 120px;\n position: relative;\n display: block;\n width: 100%;\n box-sizing: border-box;\n}\n\n.${a.classNames.block.image.wrapper} {\n display: flex;\n position: relative;\n cursor: pointer;\n transition: opacity 0.2s ease;\n outline: none;\n}\n\n.${a.classNames.block.image.wrapper}:hover {\n opacity: 0.9;\n}\n\n.clepit-image {\n max-width: 100%;\n height: auto;\n border-radius: 8px;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);\n display: block;\n}\n\n.clepit-image-caption-container {\n margin-top: 12px;\n text-align: center;\n}\n\n.clepit-image-caption-label {\n font-size: 12px;\n color: var(--clepit-text-muted);\n margin-bottom: 4px;\n font-weight: 500;\n}\n\n.clepit-image-caption-input {\n width: 100%;\n max-width: 400px;\n padding: 8px 12px;\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n font-size: 14px;\n background: var(--clepit-bg);\n outline: none;\n transition: border-color 0.2s ease;\n pointer-events: auto;\n user-select: text;\n}\n\n.clepit-image-caption-input:focus {\n border-color: var(--clepit-primary);\n box-shadow: 0 0 0 2px var(--clepit-primary-bg);\n}\n\n/* Image caption styling */\n.clepit-image-caption-editable {\n border: 1px solid var(--clepit-border-subtle);\n border-radius: 4px;\n padding: 8px 12px;\n min-height: 40px;\n font-size: 14px;\n line-height: 1.4;\n outline: none;\n transition: border-color 0.2s ease;\n}\n\n/* Image caption placeholder styles */\n.clepit-image-caption-editable[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Image Drop Area */\n.${a.classNames.block.image.dropArea} {\n border: 2px dashed var(--clepit-border);\n border-radius: 8px;\n padding: 40px 20px;\n text-align: center;\n background: var(--clepit-surface);\n cursor: pointer;\n transition: all 0.2s ease;\n margin: 16px 0;\n user-select: none;\n pointer-events: auto;\n outline: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n position: relative;\n min-height: 120px;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n}\n\n.${a.classNames.block.image.dropArea}:hover {\n border-color: var(--clepit-primary);\n background: var(--clepit-surface);\n}\n\n.clepit-image-drop-area--dragover {\n border-color: var(--clepit-primary);\n background: var(--clepit-primary-bg);\n transform: scale(1.02);\n}\n\n.clepit-image-drop-icon {\n font-size: 48px;\n margin-bottom: 16px;\n opacity: 0.6;\n}\n\n.clepit-image-drop-text {\n font-size: 16px;\n color: var(--clepit-text-muted);\n line-height: 1.5;\n margin-bottom: 8px;\n}\n\n.clepit-image-drop-subtext {\n font-size: 14px;\n color: var(--clepit-text-subtle);\n line-height: 1.4;\n}\n\n.clepit-image-click-text {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n}\n\n/* Image Loading State */\n.clepit-image-loading {\n text-align: center;\n padding: 40px 20px;\n margin: 16px 0;\n}\n\n.clepit-image-loading-spinner {\n width: 32px;\n height: 32px;\n border: 3px solid var(--clepit-surface);\n border-top: 3px solid var(--clepit-primary);\n border-radius: 50%;\n animation: spin 1s linear infinite;\n margin: 0 auto 16px;\n}\n\n@keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n}\n\n.clepit-image-loading-text {\n font-size: 14px;\n color: var(--clepit-text-muted);\n}\n\n/* Image Error State */\n.clepit-image-error {\n text-align: center;\n padding: 20px;\n margin: 16px 0;\n border: 1px solid var(--clepit-error);\n border-radius: 8px;\n background: var(--clepit-error-bg);\n}\n\n.clepit-image-error-icon {\n font-size: 24px;\n margin-bottom: 8px;\n}\n\n.clepit-image-error-text {\n font-size: 14px;\n color: var(--clepit-error);\n margin-bottom: 12px;\n}\n\n.clepit-image-error-retry {\n background: var(--clepit-error);\n color: white;\n border: none;\n padding: 8px 16px;\n border-radius: 4px;\n cursor: pointer;\n font-size: 14px;\n transition: background-color 0.2s ease;\n}\n\n.clepit-image-error-retry:hover {\n background: var(--clepit-error);\n}\n\n/* Image delete button */\n.${a.classNames.block.imageDeleteBtn} {\n position: absolute;\n top: 8px;\n right: 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 50%;\n width: 24px;\n height: 24px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: var(--clepit-bg);\n cursor: pointer;\n color: var(--clepit-text-muted);\n transition: color 0.2s ease;\n}\n\n.${a.classNames.block.imageDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Image drop area delete button */\n.clepit-image-drop-area .${a.classNames.block.imageDeleteBtn} {\n position: absolute;\n top: 8px;\n right: 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 50%;\n width: 24px;\n height: 24px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: var(--clepit-bg);\n cursor: pointer;\n color: var(--clepit-text-muted);\n transition: color 0.2s ease;\n}\n\n.clepit-image-drop-area .${a.classNames.block.imageDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Drop area positioning */\n.clepit-drop-area {\n position: relative;\n}\n\n/* Hidden input */\n.clepit-hidden-input {\n display: none;\n}\n\n`,wn="\n/* Output image styles */\n.clepit-output-image-container {\n margin: 1rem 0;\n text-align: center;\n}\n\n.clepit-output-image {\n max-width: 100%;\n height: auto;\n border-radius: 8px;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);\n}\n\n.clepit-output-image-caption {\n margin-top: 0.5rem;\n font-size: 0.875rem;\n color: var(--clepit-text-muted);\n font-style: italic;\n text-align: center;\n}\n\n/* Image wrapper positioning */\n.clepit-image-wrapper {\n position: relative;\n cursor: pointer;\n display: flex;\n margin-bottom: 10px;\n}\n.clepit-output-image-wrapper--left {\n justify-content: flex-start;\n}\n\n.clepit-output-image-wrapper--center {\n justify-content: center;\n}\n\n.clepit-output-image-wrapper--right {\n justify-content: flex-end;\n}\n",Cn=class e{static{this.placeholder="Add a caption..."}static{this.validTypes=["image/jpeg","image/jpg","image/png","image/gif","image/webp","image/ico","image/x-icon","image/avif","image/heic"]}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.querySelector("img"),n=e.querySelector(`.${a.classNames.block.image.captionEditable}`),o=e.querySelector(".clepit-image-wrapper");let i="center";return o&&(i=o.classList.contains("clepit-image-wrapper--left")?"left":o.classList.contains("clepit-image-wrapper--right")?"right":"center"),{alignment:i,alt:t?.getAttribute("alt")||"",caption:I(n?.innerHTML),url:t?.getAttribute("src")||""}}static render(t,n,o,i){a.injectStyles("clepit-image-input-styles",kn);const r={alt:"",caption:"",url:""},s=o?{...r,...o}:r,l=a.createStyledElement("div",a.classNames.block.image.container,{classNames:i?.classNames?.container,styles:i?.styles?.container});return s.url?e.renderImage(l,s,t,n,i):e.renderDropArea(l,t,n,i),l}static renderImage(t,n,o,i,r){t.innerHTML="";const s=a.createStyledElement("div",a.classNames.block.image.wrapper,{classNames:r?.classNames?.container,styles:r?.styles?.container});switch(s.setAttribute("tabindex","-1"),n?.alignment||"center"){case"left":s.classList.add("clepit-image-wrapper--left");break;case"center":s.classList.add("clepit-image-wrapper--center");break;case"right":s.classList.add("clepit-image-wrapper--right")}const l=a.createStyledElement("img","clepit-image",{classNames:r?.classNames?.container,styles:r?.styles?.container});l.alt=n?.alt||"",l.src=n?.url||"",l.classList.add("clepit-image");const c=a.createStyledElement("div","clepit-image-caption-container",{classNames:r?.classNames?.caption,styles:r?.styles?.caption});c.classList.add("clepit-image-caption-container");const p=a.createStyledElement("div",a.classNames.block.image.captionEditable,{classNames:r?.classNames?.caption,styles:r?.styles?.caption});p.setAttribute("contenteditable","true"),p.setAttribute("data-placeholder",e.placeholder),p.innerHTML=n?.caption||"",e.addEventListener(i,p,"keydown",sr.handleKeydown),e.addEventListener(i,p,"input",sr.handleInput),e.addEventListener(i,s,"click",()=>e.handleFileSelect(t,o,i,r)),s.appendChild(l),c.appendChild(p),t.appendChild(s),t.appendChild(c),p.focus()}static renderDropArea(t,n,o,i){t.innerHTML="";const r=a.createStyledElement("div",a.classNames.block.image.dropArea,{classNames:i?.classNames?.dropArea?.container,styles:i?.styles?.dropArea?.container});r.setAttribute("tabindex","0"),r.classList.add("clepit-drop-area");const s=a.createStyledElement("div","clepit-image-drop-icon",{classNames:i?.classNames?.dropArea?.icon,styles:i?.styles?.dropArea?.icon});s.textContent="📷";const c=a.createStyledElement("div","clepit-image-drop-text",{classNames:i?.classNames?.dropArea?.text,styles:i?.styles?.dropArea?.text});c.innerHTML='<strong>Drop an image here</strong><br>or <span class="clepit-image-click-text">click to select</span>';const p=a.createStyledElement("div","clepit-image-drop-subtext",{classNames:i?.classNames?.dropArea?.subtext,styles:i?.styles?.dropArea?.subtext});p.textContent="Supports JPEG, PNG, GIF, WebP, SVG, and other image formats";const d=a.createStyledElement("button",`${a.classNames.block.imageDeleteBtn}`,{classNames:i?.classNames?.dropArea?.deleteButton,styles:i?.styles?.dropArea?.deleteButton});d.type="button",d.textContent="✕",r.appendChild(s),r.appendChild(c),r.appendChild(p),r.appendChild(d);const u=l.getState().getInstance(o),m=u?.config.classNames?.tooltips,h=u?.config.styles?.tooltips;J(d,"Delete block","below",m,h),e.addEventListener(o,d,"click",e=>{e.preventDefault(),e.stopPropagation();const t=d.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id");t&&sr.removeBlock(o,sr.getBlockIndex(o,t))}),e.addEventListener(o,r,"click",()=>e.handleFileSelect(t,n,o,i)),e.addEventListener(o,r,"dragleave",()=>{r.classList.remove("clepit-image-drop-area--dragover")}),e.addEventListener(o,r,"dragover",e=>{e.preventDefault(),e.stopPropagation(),r.classList.add("clepit-image-drop-area--dragover")}),e.addEventListener(o,r,"drop",a=>{a.preventDefault(),a.stopPropagation(),r.classList.remove("clepit-image-drop-area--dragover"),e.handleFileDrop(a,t,n,o,i)}),e.addEventListener(o,r,"focus",e=>{e.preventDefault(),e.stopPropagation()}),e.addEventListener(o,r,"mousedown",e=>{e.preventDefault(),e.stopPropagation()}),t.appendChild(r)}static handleFileDrop(t,n,a,o,i){const r=t.dataTransfer?.files;if(r&&r.length>0){const t=r[0];e.isValidImageFile(t)?e.processImageFile(t,n,a,o,i):e.showError(n,"Please select a valid image file (JPEG, PNG, GIF, WebP, SVG, BMP, TIFF, ICO, AVIF, HEIC, JXL, and more)")}}static handleFileSelect(t,n,a,o){const i=document.createElement("input");i.type="file",i.accept="image/*",i.classList.add("clepit-hidden-input"),i.addEventListener("change",()=>{const r=i.files;if(r&&r.length>0){const i=r[0];e.isValidImageFile(i)?e.processImageFile(i,t,n,a,o):e.showError(t,"Please select a valid image file (JPEG, PNG, GIF, WebP, SVG, BMP, TIFF, ICO, AVIF, HEIC, JXL, and more)")}}),document.body.appendChild(i),i.click(),document.body.removeChild(i)}static isValidImageFile(t){return e.validTypes.includes(t.type)||t.type.startsWith("image/")}static async processImageFile(t,n,o,i,r){e.showLoading(n);try{let s=await o(t);if(s){e.renderImage(n,{alignment:"center",alt:t.name,caption:"",url:s},o,i,r);const c=n.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id");c&&l.getState().updateBlockData(i,sr.getBlockIndex(i,c),sr.getBlockData(c).data)}else e.showError(n,"Failed to upload image. Please try again.")}catch(s){console.error("Image upload error:",s),e.showError(n,"Failed to upload image. Please try again.")}}static showLoading(e){e.innerHTML="";const t=a.createStyledElement("div","clepit-image-loading",void 0);t.textContent="Uploading image...",e.appendChild(t)}static showError(e,t){e.innerHTML="";const n=a.createStyledElement("div","clepit-image-error",void 0);n.textContent=t,e.appendChild(n)}static setAlignment(e,t){const n=e.querySelector(".clepit-image-wrapper");n&&(n.classList.remove("clepit-image-wrapper--left","clepit-image-wrapper--center","clepit-image-wrapper--right"),n.classList.add(`clepit-image-wrapper--${t}`));const a=sr.getEditorId(e);if(!a)return;const o=e.getAttribute("data-id");o&&l.getState().partialUpdateBlockData(a,sr.getBlockIndex(a,o),{alignment:t})}static isEmpty(e){const t=e.querySelector(`.${a.classNames.block.image.wrapper} img`),n=e.querySelector(`.${a.classNames.block.image.captionEditable}`);let o=!1,i=!1;return t&&t.getAttribute("src")?.trim()||(o=!0),n?M(n.innerHTML)&&(i=!0):i=!0,o&&i}static isEmptyData(e){return!e.url?.trim()&&M(e.caption)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},En=class e{static render(t,n,o,i){if(a.injectStyles("clepit-image-output-styles",wn),!e.validate(t))return xe();if(Cn.isEmptyData(t))return document.createElement("div");const r=t.url,s=t.caption,l=t.alt||s||"",c=a.createStyledElement("div","clepit-output-image-container",{classNames:i?.container,styles:o?.container}),p=a.createStyledElement("div","clepit-output-image-wrapper");if(t.alignment)switch(t.alignment){case"left":p.classList.add("clepit-output-image-wrapper--left");break;case"center":p.classList.add("clepit-output-image-wrapper--center");break;case"right":p.classList.add("clepit-output-image-wrapper--right")}const d=B("img","clepit-output-image");if(d.src=r,d.alt=l,p.appendChild(d),c.appendChild(p),s){const e=a.createStyledElement("figcaption","clepit-output-image-caption",{classNames:i?.caption,styles:o?.caption}),n=t.caption;e.innerHTML=n&&n!==s?n:s,c.appendChild(e)}return c}static draw(t,n=ue){if(!e.validate(t)||Cn.isEmptyData(t))return null;const a=n.create("div");a.addClass("clepit-output-image-container");const o=n.create("div");o.addClass("clepit-output-image-wrapper");const i=t.alignment??"";i&&o.addClass(`clepit-output-image-wrapper--${i}`);const r=n.create("img");if(r.addClass("clepit-output-image"),r.setAttribute("src",t.url),r.setAttribute("alt",t.alt||t.caption||""),o.append(r),a.append(o),t.caption){const e=n.create("figcaption");e.addClass("clepit-output-image-caption"),e.setHtml(t.caption),a.append(e)}return a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.url}},Sn="\n/* Output list styles */\n.clepit-output-list {\n margin: 0 0 1rem 0;\n padding-left: 2rem;\n}\n\n.clepit-output-list-item {\n margin: 0.5rem 0;\n line-height: 1.6;\n}\n\n/* Output list link styles */\n.clepit-output-list a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-output-list a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Output list inline code styling */\n.clepit-output-list li code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Output list marker brush effect */\n.clepit-output-list li mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n\n.clepit-output-list li mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1;\n}\n\n/* Responsive Design */\n@media (max-width: 768px) {\n .clepit-output-list {\n padding-left: 1.5rem;\n }\n}\n",Nn=class e{static{this.placeholder="Enter list item..."}static{this.defaultType="unordered"}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(t){const n=t.getAttribute("data-type")||e.defaultType,a=[];return t.querySelectorAll("li").forEach(e=>a.push(I(e.innerHTML))),{items:a,type:n}}static render(t,n,o){a.injectStyles("clepit-list-input-styles","\n/* List block styles */\n.clepit-list {\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0 16px;\n}\n\n.clepit-list-item {\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0;\n}\n\n.clepit-block[data-tool=\"list\"] .clepit-block-content {\n padding-left: 40px;\n}\n\n.clepit-block[data-tool=\"list\"] .clepit-block-content ul,\n.clepit-block[data-tool=\"list\"] .clepit-block-content ol {\n margin: 0;\n padding-left: 20px;\n}\n\n.clepit-block[data-tool=\"list\"] .clepit-block-content li {\n margin: 4px 0;\n}\n\n/* List item placeholder styles */\n.clepit-list-item[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* List item link styles */\n.clepit-list-item a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-list-item a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* List item inline code styling */\n.clepit-list-item code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* List item marker brush effect */\n.clepit-list-item mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0; /* create stacking context so ::before sits behind text, not page */\n white-space: pre-wrap; /* ensure leading/trailing spaces inside mark render */\n}\n\n.clepit-list-item mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1; /* behind text but within mark's stacking context */\n}\n\n");const i={items:[],type:e.defaultType},r=n?{...i,...n}:i,s="ordered"===r.type?"ol":"ul",l=a.createStyledElement(s,a.classNames.block.list.container,{classNames:o?.classNames?.[r.type]?.container,styles:o?.styles?.[r.type]?.container});l.setAttribute("data-type",r.type);const c=o?.classNames?.[r.type]?.item,p=o?.styles?.[r.type]?.item;return r.items.length>0?r.items.forEach(n=>e.createAndAppendListItem(n,l,t,c,p)):e.createAndAppendListItem("",l,t,c,p),l}static createAndAppendListItem(t,n,o,i,r){const s=a.createStyledElement("li",a.classNames.block.list.item,{classNames:i,styles:r});s.innerHTML=t,s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder",e.placeholder),e.addEventListener(o,s,"keydown",t=>{const l=t,c=n.closest(`.${a.classNames.block.container}`);if(!c)return;const p=sr.getBlockIndex(o,c.getAttribute("data-id")),d=l.metaKey||l.ctrlKey;if(l.shiftKey)switch(l.key){case"ArrowUp":t.preventDefault(),t.stopPropagation(),p>0&&sr.moveBlock(o,p,p-1);break;case"ArrowDown":t.preventDefault(),t.stopPropagation();const e=sr.getBlocks(o);e&&p<e.length-1&&sr.moveBlock(o,p,p+1)}else if(d)switch(l.key){case"Delete":case"Backspace":t.preventDefault(),t.stopPropagation(),sr.removeBlock(o,p)}else if("Enter"===l.key)if(t.preventDefault(),t.stopPropagation(),M(s.innerHTML)){e.cleanupEmptyItems(n);const t=n.closest(`.${a.classNames.block.container}`);if(!t)return;const i=sr.getBlockIndex(o,t.getAttribute("data-id"));sr.insertBlock({data:{html:""},type:"paragraph"},o,i+1)}else e.createAndAppendListItem("",n,o,i,r);else if("Backspace"===l.key){if(M(s.innerHTML)){t.preventDefault(),t.stopPropagation();const e=Array.from(n.querySelectorAll("li")),i=e.indexOf(s);if(1===e.length){const e=n.closest(`.${a.classNames.block.container}`);if(!e)return;const t=sr.getBlockIndex(o,e.getAttribute("data-id"));if(-1===t)return;sr.removeBlock(o,t)}else s.remove(),i>0?e[i-1].focus():e[i+1].focus()}}else{sr.ensureActiveBlock(o);const e=sr.getBlocks(o);switch(l.key){case"ArrowUp":t.preventDefault(),t.stopPropagation();const o=Array.from(n.querySelectorAll(`.${a.classNames.block.list.item}`)),i=o.indexOf(s);if(0===i){if(p>0){const t=e[p-1];t&&sr.focusBlock(t)}}else{const e=o[i-1];e&&e.focus()}return;case"ArrowDown":t.preventDefault(),t.stopPropagation();const r=Array.from(n.querySelectorAll(`.${a.classNames.block.list.item}`)),l=r.indexOf(s);if(l===r.length-1){if(p<e.length-1){const t=e[p+1];t&&sr.focusBlock(t)}}else{const e=r[l+1];e&&e.focus()}return}}}),e.addEventListener(o,s,"input",sr.handleInput),n.appendChild(s),s.focus()}static changeType(t,n,o){const i=l.getState().getInstance(o);if(!i)return;if(t.getAttribute("data-type")===n)return;const r={items:[...t.querySelectorAll("li")||[]].map(e=>e.innerHTML),type:n},s={classNames:i.config.classNames?.blocks?.list,styles:i.config.styles?.blocks?.list},c=sr.getBlockIndex(o,t.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id")),p=e.render(o,r,s);t.replaceWith(p),l.getState().updateBlockData(o,c,r)}static cleanupEmptyItems(e){const t=Array.from(e.querySelectorAll("li")),n=t.filter(e=>M(e.innerHTML));if(t.length===n.length){if(t.length<2)return;for(let e=1;e<n.length;e++)n[e].remove()}else n.forEach(e=>e.remove())}static isEmpty(e){const t=e.querySelectorAll(`.${a.classNames.block.list.item}`);return!t||Array.from(t).every(e=>M(e.innerHTML))}static isEmptyData(e){return 0===e.items.length||e.items.every(e=>M(e))}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},An=class e{static render(t,n,o,i){if(a.injectStyles("clepit-list-output-styles",Sn),!e.validate(t))return xe();if(Nn.isEmptyData(t))return document.createElement("div");const r=t.items,s="ordered"===t.type?"ordered":"unordered",l=a.createStyledElement("ordered"===s?"ol":"ul","clepit-output-list",{classNames:i?.[s]?.container,styles:o?.[s]?.container});return r.forEach((e,t)=>{const n=e,r=a.createStyledElement("li","clepit-output-list-item",{classNames:i?.[s]?.item,styles:o?.[s]?.item});n&&n.trim()&&(r.innerHTML=n),l.appendChild(r)}),l}static draw(t,n=ue){if(!e.validate(t)||Nn.isEmptyData(t))return null;const a="ordered"===t.type,o=n.create(a?"ol":"ul");o.addClass("clepit-output-list");for(const e of t.items){const t=n.create("li");t.addClass("clepit-output-list-item"),e?.trim()&&t.setHtml(e),o.append(t)}return o}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&Array.isArray(e.items)&&"string"==typeof e.type}},Ln="\n.clepit-openapi {\n display: flex;\n flex-direction: column;\n gap: 40px;\n margin: 16px 0;\n}\n\n/* Groups and operations are separated by rhythm, never by rules — the same\n * house style the tables follow. */\n.clepit-openapi-group {\n display: flex;\n flex-direction: column;\n gap: 14px;\n}\n\n/* An eyebrow label rather than a heading, matching the uppercase group headings\n * in the docs sidebar so the reference echoes the nav — approved 2026-08-06\n * (direction 2B, \"Eyebrow\"). */\n.clepit-openapi-group-title {\n color: var(--clepit-text-subtle);\n font-size: 11px;\n font-weight: 700;\n letter-spacing: 0.08em;\n margin: 0;\n text-transform: uppercase;\n}\n\n.clepit-openapi-operation {\n border: 1px solid var(--clepit-border);\n border-radius: 8px;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n}\n\n/* The head is a tinted strip so an operation reads as one bounded unit in a\n * page of a dozen — approved 2026-08-06 (direction 1B, \"Panel\"). */\n.clepit-openapi-operation-head {\n align-items: center;\n background: color-mix(in oklab, var(--clepit-text) 4%, transparent);\n border-bottom: 1px solid var(--clepit-border);\n display: flex;\n flex-wrap: wrap;\n gap: 10px;\n padding: 10px 14px;\n}\n\n.clepit-openapi-operation-body {\n display: flex;\n flex-direction: column;\n gap: 10px;\n padding: 14px;\n}\n\n.clepit-openapi-method {\n border-radius: 4px;\n color: var(--clepit-bg);\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n font-size: 11px;\n font-weight: 700;\n letter-spacing: 0.04em;\n padding: 3px 8px;\n}\n\n.clepit-openapi-method[data-method=\"GET\"] { background: var(--clepit-success); }\n.clepit-openapi-method[data-method=\"POST\"],\n.clepit-openapi-method[data-method=\"PUT\"],\n.clepit-openapi-method[data-method=\"PATCH\"] { background: var(--clepit-primary); }\n.clepit-openapi-method[data-method=\"DELETE\"] { background: var(--clepit-error); }\n\n.clepit-openapi-path {\n color: var(--clepit-text);\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n font-size: 14px;\n}\n\n.clepit-openapi-host {\n color: var(--clepit-text-subtle);\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n font-size: 12px;\n margin-left: auto;\n}\n\n.clepit-openapi-summary {\n color: var(--clepit-text);\n font-size: 16px;\n font-weight: 600;\n margin: 0;\n}\n\n.clepit-openapi-description {\n color: var(--clepit-text-muted);\n margin: 0;\n}\n\n.clepit-openapi-section-title {\n color: var(--clepit-text-subtle);\n font-size: 11px;\n font-weight: 700;\n letter-spacing: 0.08em;\n margin: 4px 0 0;\n text-transform: uppercase;\n}\n\n/* A table has no scroll surface of its own — a cell the house style cannot\n * break (a long host URL) would otherwise force the table, and every ancestor\n * up to the page itself, wider than the viewport. */\n.clepit-openapi-table-scroll {\n max-width: 100%;\n overflow-x: auto;\n border: 1px solid var(--clepit-border);\n border-radius: 8px;\n box-shadow: 0 1px 2px rgba(0,0,0,0.04);\n}\n\n.clepit-openapi-table {\n border-collapse: collapse;\n font-size: 14px;\n width: 100%;\n}\n\n.clepit-openapi-table th {\n background: var(--clepit-surface);\n border-bottom: 1px solid var(--clepit-border);\n color: var(--clepit-text-subtle);\n font-weight: 600;\n padding: 6px 8px;\n text-align: left;\n}\n\n/* House style: no horizontal dividers between rows. Zebra striping is what\n * separates them instead. */\n.clepit-openapi-table td {\n color: var(--clepit-text);\n padding: 7px 8px;\n vertical-align: top;\n}\n\n.clepit-openapi-table tr:nth-child(even) td {\n background: var(--clepit-surface);\n}\n\n.clepit-openapi-name {\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n overflow-wrap: anywhere;\n}\n\n.clepit-openapi-type {\n color: var(--clepit-text-muted);\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n}\n\n.clepit-openapi-required {\n color: var(--clepit-error);\n font-size: 12px;\n}\n\n.clepit-openapi-badge {\n background: var(--clepit-primary-bg);\n border-radius: 4px;\n color: var(--clepit-primary);\n font-size: 12px;\n padding: 2px 8px;\n}\n\n.clepit-openapi-status {\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n font-weight: 600;\n}\n\n.clepit-openapi-status[data-kind=\"success\"] { color: var(--clepit-success); }\n.clepit-openapi-status[data-kind=\"client\"] { color: var(--clepit-warning); }\n.clepit-openapi-status[data-kind=\"server\"] { color: var(--clepit-error); }\n\n/* One response at a time behind a status tab strip — approved 2026-08-06\n * (direction 1B, \"Tabbed\"). */\n.clepit-openapi-responses {\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.clepit-openapi-response-tabs {\n border-bottom: 1px solid var(--clepit-border);\n display: flex;\n flex-wrap: wrap;\n gap: 16px;\n margin-bottom: 4px;\n}\n\n.clepit-openapi-response-tab {\n background: none;\n border: 0;\n border-bottom: 2px solid transparent;\n color: var(--clepit-text-muted);\n cursor: pointer;\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n font-size: 12px;\n margin-bottom: -1px;\n padding: 6px 0;\n}\n\n.clepit-openapi-response-tab[aria-selected=\"true\"] {\n border-bottom-color: var(--clepit-primary);\n color: var(--clepit-text);\n font-weight: 600;\n}\n\n.clepit-openapi-response-tab:focus-visible {\n outline: 2px solid var(--clepit-primary);\n outline-offset: 2px;\n}\n\n.clepit-openapi-response-description {\n color: var(--clepit-text-muted);\n margin: 0;\n}\n\n/* Tabs hide three quarters of the contract from a printed page, so print gets\n * every response expanded and the strip removed. */\n@media print {\n .clepit-openapi-response-tabs { display: none; }\n .clepit-openapi-response { display: block !important; }\n .clepit-openapi-response + .clepit-openapi-response { margin-top: 10px; }\n}\n\n.clepit-openapi-servers {\n color: var(--clepit-text-muted);\n font-size: 14px;\n margin: 0;\n}\n",Bn=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),$n=(e,t)=>{const n={children:[],cyclic:!1,nullable:!1,required:!1,type:"unknown"};if(!Bn(e))return n;if("string"==typeof e.$ref){const o=(a=e.$ref).split("/").pop()??a;if(n.ref=o,t.stack.has(o))return n.cyclic=!0,n.type=o,n;const i=t.schemas[o];if(void 0===i)return n;t.stack.add(o);const r=$n(i,t);return t.stack.delete(o),r.ref=o,r}var a;"string"==typeof e.description&&(n.description=e.description),"string"==typeof e.format&&(n.format=e.format),Array.isArray(e.enum)&&(n.enum=e.enum.map(e=>String(e)));const o=["allOf","anyOf","oneOf"].find(t=>Array.isArray(e[t]));if(o){const a=e[o].map(e=>$n(e,t));if("allOf"===o){n.type="object";for(const e of a)n.children.push(...e.children);return n}const i=a.filter(e=>"null"!==e.type&&!("unknown"===e.type&&e.nullable));return(a.length!==i.length||a.some(e=>e.nullable))&&(n.nullable=!0),n.type=i.map(e=>e.ref??e.type).join(" | ")||"unknown",n.children.push(...i.flatMap(e=>e.children)),n}if(n.type=((e,t)=>{const n=e.type;if(Array.isArray(n)){const e=n.filter(e=>"string"==typeof e);return e.includes("null")&&(t.nullable=!0),e.find(e=>"null"!==e)??"unknown"}return"string"==typeof n?n:"unknown"})(e,n),"array"===n.type){const a=$n(e.items,t);return n.type=`${a.ref??a.type}[]`,n.children.push(...a.children),n}return"object"===n.type&&((e,t,n)=>{if(!Bn(e.properties))return;const a=Array.isArray(e.required)?e.required.filter(e=>"string"==typeof e):[];for(const[o,i]of Object.entries(e.properties)){const e=$n(i,n);e.name=o,e.required=a.includes(o),t.children.push(e)}})(e,n,t),n},Mn=(e,t)=>$n(e,{schemas:t,stack:new Set}),In=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),Tn=e=>{if(!In(e))return"string";const t=Array.isArray(e.type)?e.type.find(e=>"null"!==e):e.type;if(Array.isArray(e.enum)&&e.enum.length>0)return e.enum[0];switch(t){case"array":return[];case"boolean":return!0;case"integer":case"number":return 0;case"object":return{};default:return"string"}},qn=e=>{if(!In(e)||!In(e.properties))return;const t={};for(const[n,a]of Object.entries(e.properties))t[n]=Tn(a);return t},Dn=e=>e.security[0],_n=(e,t)=>{return`${t}${n=e.path,n.replace(/\{([^}]+)\}/g,":$1")}`;var n},jn={bash:{build:(e,t)=>{const n=[`curl -X ${e.method} "${_n(e,t)}"`],a=Dn(e);var o;a&&n.push(` -H "Authorization: Bearer $${o=a,o.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toUpperCase()}"`);const i=qn(e.request);return i&&(n.push(' -H "Content-Type: application/json"'),n.push(` -d '${JSON.stringify(i)}'`)),n.join(" \\\n")},label:"cURL"},dart:{build:(e,t)=>{const n=qn(e.request),a=e.method.toLowerCase(),o=[` Uri.parse('${_n(e,t)}'),`],i=[],r=Dn(e);return r&&i.push(` 'Authorization': 'Bearer $${r}',`),n&&i.push(" 'Content-Type': 'application/json',"),i.length>0&&o.push(" headers: {",...i," },"),n&&o.push(` body: jsonEncode(${JSON.stringify(n)}),`),[`final response = await http.${a}(`,...o,");"].join("\n")},label:"Dart"},python:{build:(e,t)=>{const n=qn(e.request),a=e.method.toLowerCase(),o=[` "${_n(e,t)}",`],i=Dn(e);var r;return i&&o.push(` headers={"Authorization": f"Bearer {${r=i,r.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toLowerCase()}}"},`),n&&o.push(` json=${JSON.stringify(n)},`),[`response = requests.${a}(`,...o,")"].join("\n")},label:"Python"},typescript:{build:(e,t)=>{const n=qn(e.request),a=[],o=Dn(e);o&&a.push(` Authorization: \`Bearer \${${o}}\`,`),n&&a.push(" 'Content-Type': 'application/json',");const i=[` method: '${e.method}',`];return a.length>0&&i.push(" headers: {",...a," },"),n&&i.push(` body: JSON.stringify(${JSON.stringify(n,null,2).replace(/\n/g,"\n ")}),`),[`const response = await fetch('${_n(e,t)}', {`,...i,"});","","const data = await response.json();"].join("\n")},label:"TypeScript"}},zn=["bash","typescript","dart","python"],On=["get","post","put","patch","delete"],Hn=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),Pn=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,""),Fn=(e,t,n)=>!!e&&(!!e.tags?.some(e=>t.includes(e))||(e.paths?.includes(n)??!1)),Rn=e=>(Array.isArray(e.parameters)?e.parameters:[]).filter(Hn).map(e=>({..."string"==typeof e.description?{description:e.description}:{},in:"path"===e.in||"header"===e.in?e.in:"query",name:String(e.name??""),required:!0===e.required,...void 0===e.schema?{}:{schema:e.schema}})),Vn=e=>Hn(e.responses)?Object.entries(e.responses).map(([e,t])=>{const n=Hn(t)?t:{},a=Hn(n.content)?n.content:void 0,o=a&&Hn(a["application/json"])?a["application/json"]:void 0;return{description:"string"==typeof n.description?n.description:"",...void 0===o?.schema?{}:{schema:o.schema},status:e}}):[],Un=e=>{if(!Hn(e.requestBody))return;const t=Hn(e.requestBody.content)?e.requestBody.content:void 0;return(t&&Hn(t["application/json"])?t["application/json"]:void 0)?.schema},Wn=e=>{if(!Array.isArray(e.security))return[];const t=e.security.find(Hn);return t?Object.keys(t):[]},Kn=e=>{if(!Array.isArray(e.servers))return;const t=e.servers.find(Hn);return"string"==typeof t?.url?t.url:void 0},Gn=(e,t)=>e[0]??t.split("/").filter(Boolean)[0]??"default",Jn=(e,t)=>{const n=Hn(e)?e:{},a=Hn(n.info)?n.info:{},o=Hn(n.components)?n.components:{},i={groups:[],schemas:Hn(o.schemas)?o.schemas:{},servers:(Array.isArray(n.servers)?n.servers:[]).filter(Hn).map(e=>({..."string"==typeof e.description?{description:e.description}:{},url:String(e.url??"")})),title:"string"==typeof a.title?a.title:"",version:"string"==typeof a.version?a.version:""},r=Hn(n.paths)?n.paths:{},s=new Map;for(const[l,c]of Object.entries(r))if(Hn(c))for(const e of On){const n=c[e];if(!Hn(n))continue;const a=(Array.isArray(n.tags)?n.tags:[]).filter(e=>"string"==typeof e),o=!0===n["x-internal"],i=t.include?.paths?.includes(l)??!1;if(o&&!i)continue;if(Fn(t.exclude,a,l))continue;if(t.include&&!i&&!Fn(t.include,a,l))continue;const r={..."string"==typeof n.description?{description:n.description}:{},id:Pn(`${e}-${l}`),internal:o,method:e.toUpperCase(),params:Rn(n),path:l,...void 0===Un(n)?{}:{request:Un(n)},responses:Vn(n),security:Wn(n),...void 0===Kn(n)?{}:{server:Kn(n)},summary:"string"==typeof n.summary?n.summary:l,tags:a},p=Gn(a,l),d=s.get(p);d?d.operations.push(r):s.set(p,{id:Pn(p),operations:[r],title:p})}return i.groups=[...s.values()],i},Xn=(e,t,n,a)=>{const o=e.create(t);return n&&o.addClass(...n.split(" ")),void 0!==a&&o.setText(a),o},Zn=(e,t)=>{const n=Xn(e,"div","clepit-openapi-table-scroll");return n.append(t),n},Yn=(e,t,n,a)=>{const o=Xn(e,"p","clepit-openapi-section-title",t);return o.setAttribute("data-testid",`openapi-section-${n}-${a}`),o},Qn=e=>{const t=e.ref&&"object"===e.type?e.ref:e.type,n=e.enum?e.enum.join(" | "):t;return e.nullable?`${n} | null`:n},ea=(e,t=0)=>t>6?Qn(e):e.type.endsWith("[]")?0===e.children.length?[]:[Object.fromEntries(e.children.map(e=>[e.required?e.name:`${e.name}?`,ea(e,t+1)]))]:e.children.length>0?Object.fromEntries(e.children.map(e=>[e.required?e.name:`${e.name}?`,ea(e,t+1)])):Qn(e),ta=e=>{const t=Number.parseInt(e,10);return t>=200&&t<300?"success":t>=400&&t<500?"client":t>=500?"server":"other"},na=(e,t,n,a)=>{const o=Xn(e,"section","clepit-openapi-operation");o.setAttribute("data-testid",`openapi-operation-${t.id}`);const i=t.server??a.defaultServer??n.servers[0]?.url??"";o.setAttribute("data-server",i);const r=Xn(e,"div","clepit-openapi-operation-head"),s=Xn(e,"span","clepit-openapi-method",t.method);s.setAttribute("data-method",t.method),s.setAttribute("data-testid",`openapi-method-${t.id}`);const l=Xn(e,"span","clepit-openapi-path",t.path);if(l.setAttribute("data-testid",`openapi-path-${t.id}`),r.append(s),r.append(l),i){const n=Xn(e,"span","clepit-openapi-host",i);n.setAttribute("data-testid",`openapi-host-${t.id}`),r.append(n)}o.append(r);const c=Xn(e,"div","clepit-openapi-operation-body"),p=Xn(e,"h3","clepit-openapi-summary",t.summary);p.setAttribute("id",t.id),c.append(p),t.description&&c.append(Xn(e,"p","clepit-openapi-description",t.description));const d=Xn(e,"div","clepit-openapi-security");d.setAttribute("data-testid",`openapi-security-${t.id}`),d.append(Xn(e,"span","clepit-openapi-section-title","Auth")),d.appendText(" "),d.append(Xn(e,"span","clepit-openapi-badge",t.security.length>0?t.security.join(", "):"public")),c.append(d);const u=((e,t,n)=>{if(0===t.params.length)return null;const a=Xn(e,"table","clepit-openapi-table");a.setAttribute("data-testid",`openapi-params-${t.id}`);const o=e.create("tr");for(const i of["Name","In","Type","Description"])o.append(Xn(e,"th","clepit-openapi-th",i));a.append(o);for(const i of t.params){const t=e.create("tr"),o=Xn(e,"td","clepit-openapi-name",i.name);i.required&&o.append(Xn(e,"span","clepit-openapi-required"," required")),t.append(o),t.append(Xn(e,"td","clepit-openapi-cell",i.in)),t.append(Xn(e,"td","clepit-openapi-type",Qn(Mn(i.schema,n.schemas)))),t.append(Xn(e,"td","clepit-openapi-cell",i.description??"")),a.append(t)}return a})(e,t,n);if(u&&(c.append(Yn(e,"Parameters","parameters",t.id)),c.append(Zn(e,u))),void 0!==t.request){const a=Mn(t.request,n.schemas);if(a.children.length>0){c.append(Yn(e,"Body","body",t.id));const n=Xn(e,"div","clepit-openapi-body");n.setAttribute("data-testid",`openapi-body-${t.id}`);const o=Et.draw({code:JSON.stringify(ea(a),null,2),language:"json",showCopy:!0},e);o&&n.append(o),c.append(n)}}t.responses.length>0&&(c.append(Yn(e,"Responses","responses",t.id)),c.append(((e,t,n)=>{const a=Xn(e,"div","clepit-openapi-responses");a.setAttribute("data-testid",`openapi-responses-${t.id}`);const o=Xn(e,"div","clepit-openapi-response-tabs");o.setAttribute("role","tablist"),o.setAttribute("data-testid",`openapi-response-tabs-${t.id}`);const i=[],r=1===t.responses.length;t.responses.forEach((a,s)=>{const l=Xn(e,"div","clepit-openapi-response");l.setAttribute("id",`${t.id}-response-${a.status}`),l.setAttribute("role","tabpanel"),l.setAttribute("data-status",a.status),l.setAttribute("data-testid",`openapi-response-${t.id}-${a.status}`),0!==s&&l.setAttribute("hidden","");const c=Xn(e,"p","clepit-openapi-response-description");if(r){const t=Xn(e,"span","clepit-openapi-status",a.status);t.setAttribute("data-kind",ta(a.status)),c.append(t),c.appendText(` ${a.description}`)}else c.setText(a.description);if(l.append(c),void 0!==a.schema){const t=Mn(a.schema,n.schemas);if(t.children.length>0){const n=Et.draw({code:JSON.stringify(ea(t),null,2),language:"json",showCopy:!0},e);n&&l.append(n)}}i.push(l);const p=Xn(e,"button","clepit-openapi-response-tab",a.status);p.setAttribute("type","button"),p.setAttribute("role","tab"),p.setAttribute("aria-controls",`${t.id}-response-${a.status}`),p.setAttribute("aria-selected",0===s?"true":"false"),p.setAttribute("tabindex",0===s?"0":"-1"),p.setAttribute("data-kind",ta(a.status)),p.setAttribute("data-testid",`openapi-response-tab-${t.id}-${a.status}`),o.append(p)}),r||a.append(o);for(const s of i)a.append(s);return a})(e,t,n)));const m=((e,t,n)=>n.flatMap(n=>{const a=jn[n];return a?[{code:a.build(e,t),label:a.label,language:n}]:[]}))(t,i,a.snippetLanguages??zn);if(m.length>0){c.append(Yn(e,"Try it","try-it",t.id));const n=Et.draw({code:m[0].code,language:m[0].language,showCopy:!0,syncKey:"api-reference",variants:m},e);n&&c.append(n)}return o.append(c),o},aa=class e{static draw(t,n=ue){if(!e.validate(t))return null;const a=Jn(t.spec,t),o=Xn(n,"div","clepit-openapi");if(a.servers.length>0){const e=Xn(n,"table","clepit-openapi-table clepit-openapi-servers");e.setAttribute("data-testid","openapi-servers");const t=n.create("tr");t.append(Xn(n,"th","clepit-openapi-th","Host")),t.append(Xn(n,"th","clepit-openapi-th","Serves")),e.append(t);for(const o of a.servers){const t=n.create("tr");t.append(Xn(n,"td","clepit-openapi-name",o.url)),t.append(Xn(n,"td","clepit-openapi-cell",o.description??"")),e.append(t)}o.append(Zn(n,e))}for(const e of a.groups){const i=Xn(n,"section","clepit-openapi-group");i.setAttribute("data-testid",`openapi-group-${e.id}`);const r=Xn(n,"h2","clepit-openapi-group-title",e.title);r.setAttribute("id",e.id),i.append(r);for(const o of e.operations)i.append(na(n,o,a,t));o.append(i)}return o}static render(t,n,o,i){if(a.injectStyles("clepit-openapi-output-styles",Ln),!e.validate(t))return xe();const r=ve(e.draw(t,ue));i?.container&&r.classList.add(i.container),o?.container&&Object.assign(r.style,o.container),e.attach(r);for(const e of[...r.querySelectorAll(".clepit-output-code-container")])Et.activateFromMarkup(e);return r}static activate(t){const n=[e.attach(t)];for(const e of[...t.querySelectorAll(".clepit-output-code-container")])n.push(Et.activateFromMarkup(e));return()=>{for(const e of n)e()}}static attach(e){const t=[],n=(e,n,a)=>{e.addEventListener(n,a),t.push({event:n,handler:a,target:e})};for(const a of[...e.querySelectorAll(".clepit-openapi-responses")]){const e=[...a.querySelectorAll(".clepit-openapi-response-tab")],t=[...a.querySelectorAll(".clepit-openapi-response")],o=n=>{e.forEach((e,t)=>{e.setAttribute("aria-selected",t===n?"true":"false"),e.tabIndex=t===n?0:-1}),t.forEach((e,t)=>{e.hidden=t!==n})};e.forEach((t,a)=>{n(t,"click",()=>o(a)),n(t,"keydown",t=>{const n=t.key,i="ArrowRight"===n?1:"ArrowLeft"===n?-1:0,r="Home"===n?0:"End"===n?e.length-1:0===i?-1:(a+i+e.length)%e.length;-1!==r&&(t.preventDefault(),o(r),e[r]?.focus())})})}return()=>{for(const{event:e,handler:n,target:a}of t)a.removeEventListener(e,n)}}static validate(e){return null!=e&&"object"==typeof e&&("string"==typeof e.url&&e.url.length>0||"object"==typeof e.spec&&null!==e.spec&&!Array.isArray(e.spec))}},oa="\n/* Output paragraph styles */\n.clepit-output-paragraph {\n margin: 0 0 1rem 0;\n line-height: 1.6;\n color: var(--clepit-text);\n}\n\n/* Output paragraph inline code styling */\n.clepit-output-paragraph code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Output paragraph marker brush effect */\n.clepit-output-paragraph mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n\n.clepit-output-paragraph mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1;\n}\n\n/* Output paragraph link styles */\n.clepit-output-paragraph a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-output-paragraph a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n",ia=class e{static{this.placeholder="Enter text..."}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){return{html:I(e.querySelector(`.${a.classNames.block.paragraph}`)?.innerHTML)}}static render(t,n,o){a.injectStyles("clepit-paragraph-input-styles","\n/* Paragraph block styles */\n.clepit-paragraph {\n outline: none;\n margin: 0;\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 0;\n margin-inline-end: 0;\n padding: 0 20px;\n}\n\n.clepit-block[data-tool=\"paragraph\"] .clepit-block-content {\n font-size: 16px;\n line-height: 1.6;\n}\n\n/* Paragraph placeholder styles */\n.clepit-paragraph[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Paragraph link styles */\n.clepit-paragraph a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-paragraph a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Paragraph inline code styling */\n.clepit-paragraph code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Paragraph marker brush effect */\n.clepit-paragraph mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0; /* create stacking context so ::before sits behind text, not page */\n white-space: pre-wrap; /* ensure leading/trailing spaces inside mark render */\n}\n\n.clepit-paragraph mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1; /* behind text but within mark's stacking context */\n}\n\n");const i=a.createStyledElement("div",a.classNames.block.paragraph,{classNames:o?.classNames,styles:o?.styles});return i.setAttribute("contenteditable","true"),i.setAttribute("data-placeholder",e.placeholder),i.innerHTML=n?.html||"",e.addEventListener(t,i,"keydown",sr.handleKeydown),e.addEventListener(t,i,"input",sr.handleInput),i}static isEmpty(e){return M(e.querySelector(`.${a.classNames.block.paragraph}`)?.innerHTML)}static isEmptyData(e){return M(e.html)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},ra=class e{static render(t,n,o,i){if(a.injectStyles("clepit-paragraph-output-styles",oa),!e.validate(t))return xe();const r=a.createStyledElement("p","clepit-output-paragraph",{classNames:i,styles:o});if(ia.isEmptyData(t))return r.appendChild(document.createElement("br")),r;const s=t.html;return s&&(r.innerHTML=s),r}static draw(t,n=ue){if(!e.validate(t))return null;const a=n.create("p");return a.addClass("clepit-output-paragraph"),ia.isEmptyData(t)?(a.append(n.create("br")),a):(t.html&&a.setHtml(t.html),a)}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.html}},sa=`\n/* Quote block styles */\n.${a.classNames.block.quote.container} {\n background: linear-gradient(135deg, var(--clepit-surface) 0%, var(--clepit-surface-2) 100%);\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n padding: 16px 20px;\n margin: 16px 16px 16px 0;\n position: relative;\n}\n\n.${a.classNames.block.quote.text} {\n font-size: 1.2em;\n line-height: 1.6;\n font-family: cursive, serif;\n font-style: italic;\n margin-bottom: 15px;\n padding: 4px 6px;\n}\n\n.${a.classNames.block.quote.author} {\n color: var(--clepit-text-muted);\n font-size: 0.9em;\n font-style: normal;\n font-family: inherit;\n text-align: right;\n margin-top: 10px;\n padding: 8px 12px;\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n background: var(--clepit-bg);\n outline: none;\n transition: border-color 0.2s ease;\n}\n\n.${a.classNames.block.quote.author}:focus {\n outline: none;\n}\n\n.${a.classNames.block.quote.divider} {\n height: 1px;\n margin: 15px 0;\n background: linear-gradient(to right, transparent, var(--clepit-border-subtle), transparent);\n}\n\n/* Quote placeholder styles */\n.${a.classNames.block.quote.text}[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n.${a.classNames.block.quote.author}[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Quote link styles */\n.${a.classNames.block.quote.text} a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.${a.classNames.block.quote.text} a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Quote inline code styling */\n.${a.classNames.block.quote.text} code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n`,la="\n/* Output quote styles */\n.clepit-output-quote-container {\n background: linear-gradient(135deg, var(--clepit-surface) 0%, var(--clepit-surface-2) 100%);\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n padding: 12px 14px;\n margin: 20px 0;\n position: relative;\n}\n\n.clepit-output-quote-author {\n color: var(--clepit-text-muted);\n font-size: 0.9em;\n font-style: normal;\n font-family: inherit;\n text-align: right;\n margin-top: 10px;\n}\n\n.clepit-output-quote-divider {\n height: 1px;\n margin: 15px 0;\n background: linear-gradient(to right, transparent, var(--clepit-border-subtle), transparent);\n}\n\n.clepit-output-quote-text {\n font-size: 1.2em;\n line-height: 1.6;\n font-family: cursive, serif;\n font-style: italic;\n margin-bottom: 15px;\n}\n\n.clepit-output-quote-content {\n /* Content styling handled by parent */\n}\n\n/* Output quote link styles */\n.clepit-output-quote a {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n transition: color 0.2s ease;\n}\n\n.clepit-output-quote a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Output quote inline code styling */\n.clepit-output-quote code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n.clepit-output-quote cite code {\n background: var(--clepit-error-bg);\n color: var(--clepit-error);\n padding: 0 4px;\n border-radius: 4px;\n}\n\n/* Output quote marker brush effect */\n.clepit-output-quote mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n\n.clepit-output-quote mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1;\n}\n\n.clepit-output-quote cite mark {\n background: none;\n position: relative;\n color: inherit;\n display: inline-block;\n z-index: 0;\n white-space: pre-wrap;\n}\n\n.clepit-output-quote cite mark::before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: 0.15em;\n height: 1.25em;\n transform: rotate(-0.4deg);\n background: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' preserveAspectRatio='none'><path d='M0,8 C5,2 15,1 25,3 35,5 45,2 55,4 65,6 75,5 85,7 95,9 100,8 100,8 100,14 95,18 85,17 75,16 65,19 55,17 45,15 35,18 25,16 15,14 5,15 0,12 Z' fill='%23FFE047'/></svg>\") no-repeat center / 100% 100%;\n z-index: -1;\n}\n",ca=class e{static{this.placeholder="Enter quote..."}static{this.authorPlaceholder="Enter author..."}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.querySelector(`.${a.classNames.block.quote.text}`);return{author:I(e.querySelector(`.${a.classNames.block.quote.author}`)?.innerHTML),html:I(t?.innerHTML)}}static render(t,n,o){a.injectStyles("clepit-quote-input-styles",sa);const i=n||{author:"",html:""},r=a.createStyledElement("div",a.classNames.block.quote.container,{classNames:o?.classNames?.container,styles:o?.styles?.container}),s=a.createStyledElement("div",a.classNames.block.quote.text,{classNames:o?.classNames?.text,styles:o?.styles?.text}),l=a.createStyledElement("div",a.classNames.block.quote.author,{classNames:o?.classNames?.author,styles:o?.styles?.author});if(s.innerHTML=i.html||"",s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder",e.placeholder),l.innerHTML=i.author||"",l.setAttribute("contenteditable","true"),l.setAttribute("data-placeholder",e.authorPlaceholder),e.addEventListener(t,s,"keydown",e.handleKeydown),e.addEventListener(t,s,"input",sr.handleInput),e.addEventListener(t,l,"keydown",e.handleKeydown),e.addEventListener(t,l,"input",sr.handleInput),r.appendChild(s),i.author){const e=a.createStyledElement("div",a.classNames.block.quote.divider,{classNames:o?.classNames?.divider,styles:o?.styles?.divider});r.appendChild(e)}return r.appendChild(l),r}static handleKeydown(e){const t=e,n=e.currentTarget,o=n.closest(`.${a.classNames.block.container}`),i=sr.getEditorId(o);if(!i)return;const r=sr.getBlockIndex(i,o.getAttribute("data-id")),s=o.querySelector(`.${a.classNames.block.quote.text}`),l=o.querySelector(`.${a.classNames.block.quote.author}`),c=t.metaKey||t.ctrlKey;if(t.shiftKey)switch(t.key){case"ArrowUp":e.preventDefault(),e.stopPropagation(),r>0&&sr.moveBlock(i,r,r-1);break;case"ArrowDown":e.preventDefault(),e.stopPropagation();const t=sr.getBlocks(i);t&&r<t.length-1&&sr.moveBlock(i,r,r+1)}else if(c)switch(t.key){case"Delete":case"Backspace":e.preventDefault(),e.stopPropagation(),sr.removeBlock(i,r)}else if("Enter"===t.key)t.preventDefault(),t.stopPropagation(),sr.insertBlock({data:{html:""},type:"paragraph"},i,r+1);else if("Backspace"===t.key){if(!M(n.innerHTML))return;t.preventDefault(),t.stopPropagation(),n===s?sr.removeBlock(i,r):n===l&&(M(s.innerHTML)?sr.removeBlock(i,r):s.focus())}else if("ArrowUp"===t.key)if(t.preventDefault(),t.stopPropagation(),n===s){const e=o.previousElementSibling;e&&sr.focusBlock(e)}else s.focus();else if("ArrowDown"===t.key)if(t.preventDefault(),t.stopPropagation(),n===l){const e=o.nextElementSibling;e&&sr.focusBlock(e)}else l.focus()}static handleKeydownInAuthorInput(e){const t=e,n=e.currentTarget,o=n.closest(`.${a.classNames.block.container}`),i=sr.getEditorId(o);if(i)if("Enter"!==t.key||t.shiftKey){if("Backspace"===t.key){if(n.innerHTML?.trim()&&"<br>"!==n.innerHTML.trim())return;t.preventDefault(),t.stopPropagation();const e=o.querySelector(`.${a.classNames.block.quote.text}`);e&&e.focus()}}else{t.preventDefault(),t.stopPropagation();const e=sr.getBlockIndex(i,o.getAttribute("data-id"));sr.insertBlock({data:{html:""},type:"paragraph"},i,e+1)}}static isEmpty(e){const t=e.querySelector(`.${a.classNames.block.quote.text}`),n=e.querySelector(`.${a.classNames.block.quote.author}`);let o=!1,i=!1;return t?M(t.innerHTML)&&(o=!0):o=!0,n?M(n.innerHTML)&&(i=!0):i=!0,o&&i}static isEmptyData(e){return M(e.html)&&M(e.author)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},pa=class e{static render(t,n,o,i){if(a.injectStyles("clepit-quote-output-styles",la),!e.validate(t))return xe();if(ca.isEmptyData(t))return document.createElement("div");const r=t.html,s=t.author||"",l=a.createStyledElement("div","clepit-output-quote-container",{classNames:i?.container,styles:o?.container}),c=a.createStyledElement("div","clepit-output-quote-text",{classNames:i?.text,styles:o?.text}),p=B("div","clepit-output-quote-content");if(r&&r.trim()&&(p.innerHTML=r),c.appendChild(p),l.appendChild(c),s){const e=a.createStyledElement("div","clepit-output-quote-divider",{classNames:i?.divider,styles:o?.divider});l.appendChild(e);const t=a.createStyledElement("div","clepit-output-quote-author",{classNames:i?.author,styles:o?.author});t.textContent=`— ${s}`,l.appendChild(t)}return l.querySelectorAll(`span.${a.classNames.block.tooltip}[data-tooltip]`).forEach(e=>{const t=e;t.hasAttribute("data-tooltip-initialized")||(J(t,String(t.getAttribute("data-tooltip")||""),"above",n?.tooltipClassNames,void 0),t.setAttribute("data-tooltip-initialized","true"))}),l}static draw(t,n=ue){if(!e.validate(t)||ca.isEmptyData(t))return null;const a=n.create("div");a.addClass("clepit-output-quote-container");const o=n.create("div");o.addClass("clepit-output-quote-text");const i=n.create("div");if(i.addClass("clepit-output-quote-content"),t.html?.trim()&&i.setHtml(t.html),o.append(i),a.append(o),t.author){const e=n.create("div");e.addClass("clepit-output-quote-divider"),a.append(e);const o=n.create("div");o.addClass("clepit-output-quote-author"),o.setText(`— ${t.author}`),a.append(o)}return a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.html}},da="\n.clepit-sketch {\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n overflow: hidden;\n}\n.clepit-sketch__canvas {\n display: block;\n width: 100%;\n height: 240px;\n touch-action: none;\n}\n.clepit-sketch--input .clepit-sketch__canvas {\n cursor: crosshair;\n}\n",ua=da,ma=da,ha="http://www.w3.org/2000/svg";function ga(e){return e&&/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(e.trim())?e.trim():"#000000"}function ba(e){if(e.length<4)return"";const t=[`M ${e[0]} ${e[1]}`];for(let n=2;n+1<e.length;n+=2)t.push(`L ${e[n]} ${e[n+1]}`);return t.join(" ")}var fa=class e{static render(t,n,o,i){if(a.injectStyles("sketch-output",ma),!e.validate(t))return xe();const r=a.createStyledElement("div","clepit-sketch clepit-output-sketch",{classNames:i?.wrapper,styles:o?.wrapper}),s=document.createElementNS(ha,"svg");s.setAttribute("class","clepit-sketch__canvas"),s.setAttribute("viewBox","0 0 1000 240"),s.setAttribute("preserveAspectRatio","none"),s.setAttribute("role","img");for(const a of t.strokes??[]){const t=ba(a.points??[]);if(!t)continue;const n=document.createElementNS(ha,"path");n.setAttribute("d",t),n.setAttribute("fill","none"),n.setAttribute("stroke",ga(a.color)),n.setAttribute("stroke-width",String(e.safeWidth(a))),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),s.appendChild(n)}return r.appendChild(s),r}static draw(t,n=ue){if(!e.validate(t))return null;const a=n.create("div");a.addClass("clepit-sketch","clepit-output-sketch");const o=n.createNS(ha,"svg");o.setAttribute("class","clepit-sketch__canvas"),o.setAttribute("viewBox","0 0 1000 240"),o.setAttribute("preserveAspectRatio","none"),o.setAttribute("role","img");for(const i of t.strokes??[]){const t=ba(i.points??[]);if(!t)continue;const a=n.createNS(ha,"path");a.setAttribute("d",t),a.setAttribute("fill","none"),a.setAttribute("stroke",ga(i.color)),a.setAttribute("stroke-width",String(e.safeWidth(i))),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),o.append(a)}return a.append(o),a}static safeWidth(e){const t=Number(e.width);return Number.isFinite(t)&&t>0&&t<=64?t:2}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&Array.isArray(e.strokes)}},ya=`\n/* Table block styles */\n.clepit-table-container {\n position: relative;\n display: block;\n max-width: 100%;\n overflow-x: auto;\n overflow-y: visible; /* allow buttons to be visible outside */\n margin: 16px 0;\n padding: 20px;\n}\n\n.clepit-table {\n width: 100%;\n border-collapse: separate;\n border-spacing: 0;\n background: var(--clepit-bg);\n border-radius: 8px;\n border: 1px solid var(--clepit-border);\n box-shadow: 0 1px 2px rgba(0,0,0,0.04);\n}\n\n.clepit-table-controls {\n display: flex;\n gap: 6px;\n margin: 6px 0;\n}\n\n.clepit-table-btn {\n border: 1px solid var(--clepit-border);\n background: var(--clepit-surface);\n border-radius: 4px;\n padding: 2px 6px;\n font-size: 12px;\n color: var(--clepit-text);\n cursor: pointer;\n}\n\n.clepit-table-btn:hover {\n background: var(--clepit-surface-2);\n}\n\n.clepit-table-corner {\n width: 28px;\n min-width: 28px;\n border-right: 1px solid var(--clepit-border);\n}\n\n.${a.classNames.block.table.headerCell} {\n background: var(--clepit-surface);\n border-bottom: 1px solid var(--clepit-border);\n border-right: 1px solid var(--clepit-border);\n padding: 10px 12px;\n font-weight: 600;\n min-width: 120px;\n vertical-align: top;\n text-align: left;\n position: relative;\n}\n\n.${a.classNames.block.table.cell} {\n border-right: 1px solid var(--clepit-border);\n border-bottom: 1px solid var(--clepit-border);\n padding: 10px 12px;\n min-width: 120px;\n vertical-align: top;\n text-align: left;\n}\n\n/* Zebra striping: odd white, even light grey */\n.clepit-table-tbody tr:nth-child(odd) .${a.classNames.block.table.cell} {\n background: var(--clepit-bg);\n}\n\n.clepit-table-tbody tr:nth-child(even) .${a.classNames.block.table.cell} {\n background: var(--clepit-surface);\n}\n\n.${a.classNames.block.table.caption} {\n margin: 8px 0 0 0; /* full width, no horizontal margins */\n width: 100%;\n padding: 10px 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n background: var(--clepit-surface);\n font-size: 13px;\n outline: none;\n flex: 1;\n min-width: 0;\n}\n\n.${a.classNames.block.table.caption}[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: rgba(0, 0, 0, 0.6);\n font-style: italic;\n}\n\n/* Table Download Switch Container */\n.clepit-table-download-switch {\n margin: 8px 0 0 0;\n padding: 6px 8px;\n background: var(--clepit-surface);\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n font-size: 13px;\n}\n\n.${a.classNames.block.table.headerCell}:focus,\n.clepit-table-cell:focus {\n outline: 2px solid var(--clepit-primary);\n outline-offset: -2px;\n}\n\n/* Table placeholder styles */\n.${a.classNames.block.table.headerCell}[data-placeholder]:empty::before,\n.${a.classNames.block.table.cell}[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Row handle cell */\n.clepit-table-row-handle {\n position: absolute;\n left: -22px;\n top: 50%;\n transform: translateY(-50%);\n width: 18px;\n height: 18px;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 2px;\n display: none;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n font-size: 10px;\n color: var(--clepit-text-muted);\n z-index: 1001;\n}\n\n.clepit-table-col-handle {\n position: absolute;\n top: -22px;\n left: 50%;\n transform: translateX(-50%);\n width: 18px;\n height: 18px;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 2px;\n display: none;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n font-size: 10px;\n color: var(--clepit-text-muted);\n z-index: 1001;\n}\n\n.clepit-table-row-delete {\n position: absolute;\n right: -22px;\n top: 50%;\n transform: translateY(-50%);\n width: 18px;\n height: 18px;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 2px;\n display: none;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n font-size: 10px;\n color: var(--clepit-text-muted);\n z-index: 1001;\n}\n\n.clepit-table-col-delete {\n right: -22px;\n top: calc(50% + 18px);\n transform: translateY(-50%);\n}\n\n/* Show handles on hover/active */\n.clepit-table-row:hover .clepit-row-handle,\n.${a.classNames.block.table.headerCell}:hover .clepit-col-handle,\n.clepit-table-row:hover .clepit-row-delete,\n.${a.classNames.block.table.headerCell}:hover .clepit-col-delete {\n display: flex;\n}\n\n/* Hover/active states like toolbar buttons */\n.clepit-row-handle:hover, .clepit-col-handle:hover,\n.clepit-row-delete:hover, .clepit-col-delete:hover {\n color: var(--clepit-primary);\n}\n\n/* Table menu buttons */\n.clepit-table-row-menu-btn,\n.clepit-table-col-menu-btn {\n position: absolute;\n background: var(--clepit-bg);\n color: var(--clepit-text);\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n padding: 4px 8px;\n font-size: 12px;\n cursor: pointer;\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 1002;\n}\n\n.clepit-table-row-menu-btn:hover,\n.clepit-table-col-menu-btn:hover {\n color: var(--clepit-primary);\n background: var(--clepit-bg);\n border-color: var(--clepit-border);\n}\n\n.clepit-table-row-menu-btn--visible,\n.clepit-table-col-menu-btn--visible {\n display: flex;\n}\n\n/* Table container */\n.clepit-table-container {\n overflow: visible;\n position: relative;\n}\n\n.clepit-table-scroll-container {\n overflow-x: auto;\n overflow-y: visible;\n max-width: 100%;\n}\n\n/* Table caption download container */\n.clepit-table-caption-download-container {\n display: flex;\n align-items: center;\n gap: 8px;\n margin-top: 8px;\n}\n\n.clepit-table-download-switch {\n flex-shrink: 0;\n}\n\n`,va="\n/* Output table styles */\n.clepit-output-table-container {\n margin: 1rem 0;\n overflow-x: auto;\n}\n\n.clepit-output-table {\n width: 100%;\n border-collapse: collapse;\n border: 1px solid var(--clepit-border);\n border-radius: 8px;\n overflow: hidden;\n background: var(--clepit-bg);\n box-shadow: 0 1px 2px rgba(0,0,0,0.04);\n}\n\n/* House style: rows carry no horizontal dividers and no column rules. Rows are\n * told apart by zebra striping, which is what does that job instead — removing\n * the rules is not a licence to remove the banding too. */\n/* These four rules were assigned from JavaScript, one element at a time, which\n * is a browser call inside a render path. In a stylesheet they cost nothing to\n * a page that draws without a browser, and a caller's own inline style still\n * wins over them exactly as it did before. */\n.clepit-output-table-wrapper {\n overflow: hidden;\n width: 100%;\n border-radius: 4px;\n margin-bottom: 1rem;\n}\n\n.clepit-output-table-scroller {\n overflow-x: auto;\n}\n\n.clepit-output-table {\n table-layout: auto;\n margin-top: 0;\n margin-bottom: 0;\n border-radius: 0;\n}\n\n.clepit-output-table th,\n.clepit-output-table td {\n padding: 10px 12px;\n text-align: left;\n min-width: 120px;\n max-width: 400px;\n}\n\n.clepit-output-table th {\n background: var(--clepit-surface);\n border-bottom: 1px solid var(--clepit-border);\n color: var(--clepit-text);\n font-weight: 600;\n}\n\n.clepit-output-table tbody tr:nth-child(odd) {\n background: var(--clepit-bg);\n}\n\n.clepit-output-table tbody tr:nth-child(even) {\n background: var(--clepit-surface);\n}\n\n/* No hover state: a rendered table is display, not a control. A row that\n * changes colour under the pointer reads as clickable when it is not. */\n\n/* Table Output Caption */\n.clepit-output-table-caption {\n margin-top: 0.5rem;\n font-size: 0.875rem;\n color: var(--clepit-text-muted);\n font-style: italic;\n text-align: center;\n}\n\n/* Make footer cell neutral so caption styles are visible */\n.clepit-output-table tfoot td,\n.clepit-output-table tfoot .clepit-output-table-caption-cell {\n padding: 0;\n border: 0;\n background: transparent;\n}\n\n.clepit-output-table-download-btn {\n margin-left: auto;\n width: 24px;\n height: 24px;\n border: none;\n outline: none;\n cursor: pointer;\n border-radius: 50%;\n background: transparent;\n transition: all 0.2s ease;\n padding: 4px;\n display: flex;\n align-items: center;\n justify-content: center;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n}\n\n.clepit-output-table-download-btn:hover {\n background: var(--clepit-bg);\n}\n\n.clepit-output-table-download-btn:hover .clepit-download-icon {\n stroke: var(--clepit-primary);\n}\n\n.clepit-output-table-download-btn:active {\n transform: scale(0.95);\n}\n\n.clepit-download-icon {\n width: 20px;\n height: 20px;\n stroke: var(--clepit-text-muted);\n transition: stroke 0.2s ease;\n}\n\n.clepit-output-table-footer-container {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 8px 12px;\n background: var(--clepit-surface);\n border: 1px solid var(--clepit-border);\n border-top: none;\n border-radius: 0 0 8px 8px;\n}\n",xa=class e{static{this.defaultCols=3}static{this.defaultRows=3}static{this.headerPlaceholder="Enter header..."}static{this.cellPlaceholder="Enter text..."}static{this.captionPlaceholder="Add a caption..."}static{this.defaultData={caption:"",data:Array.from({length:e.defaultRows},()=>Array.from({length:e.defaultCols},()=>"")),showDownload:!1}}static{this.eventListenersMap={}}static addEventListener(t,n,a,o,i){n.addEventListener(a,o,i);const r=e.eventListenersMap[t]||[];r.push({element:n,event:a,handler:o,options:i}),e.eventListenersMap[t]=r}static save(t){const n=t.querySelector("table");if(!n)return e.defaultData;const o=n.querySelector("thead tr"),i=o?Array.from(o.querySelectorAll(`.${a.classNames.block.table.headerCell}`)):[],r=[],s=[];for(const e of i){const t=e.cloneNode(!0);t.querySelectorAll(".clepit-col-handle, .clepit-col-delete").forEach(e=>e.remove()),s.push(I(t.innerHTML))}r.push(s);const l=n.querySelectorAll("tbody tr");for(const e of Array.from(l)){const t=Array.from(e.querySelectorAll(`.${a.classNames.block.table.cell}`)),n=[];for(const e of t){const t=e.cloneNode(!0);t.querySelectorAll(".clepit-row-handle, .clepit-row-delete").forEach(e=>e.remove()),n.push(I(t.innerHTML))}r.push(n)}const c=(t.querySelector(".clepit-table-download-switch")?.querySelector('input[type="checkbox"]'))?.checked||!1;return{caption:I(t.querySelector(`.${a.classNames.block.table.caption}`)?.innerHTML||""),data:r,showDownload:c}}static render(t,n,o){a.injectStyles("clepit-table-input-styles",ya);const i=n?{...e.defaultData,...n}:e.defaultData,r=a.createStyledElement("div","clepit-table-container",{classNames:o?.classNames?.container,styles:o?.styles?.container}),s=a.createStyledElement("table","clepit-table",{classNames:o?.classNames?.table,styles:o?.styles?.table}),c=a.createStyledElement("thead","clepit-table-thead",{classNames:o?.classNames?.table,styles:o?.styles?.table}),p=e.createRow(t,i.data[0],!0);c.appendChild(p),s.appendChild(c);const d=a.createStyledElement("tbody","clepit-table-tbody",{classNames:o?.classNames?.table,styles:o?.styles?.table});for(let a=1;a<i.data.length;a++){const n=e.createRow(t,i.data[a]);d.appendChild(n)}s.appendChild(d);const u=a.createStyledElement("div","clepit-table-scroll-container");u.appendChild(s),r.appendChild(u);const h=a.createStyledElement("button","clepit-table-btn clepit-row-menu-btn",{classNames:o?.classNames?.rowMenuButton,styles:o?.styles?.rowMenuButton});h.style.position="absolute",h.style.display="none",h.style.zIndex="1000",h.textContent="⋮",r.appendChild(h);const f=a.createStyledElement("button","clepit-table-btn clepit-col-menu-btn",{classNames:o?.classNames?.columnMenuButton,styles:o?.styles?.columnMenuButton});f.style.position="absolute",f.style.display="none",f.style.zIndex="1000",f.textContent="⋯",r.appendChild(f);let y=null,v=-1,k=null;e.addEventListener(t,r,"mouseleave",()=>(h.style.display="none",f.style.display="none",void(k&&(k.remove(),k=null))));const w=e=>{y=e;const t=e.getBoundingClientRect(),n=r.getBoundingClientRect(),a=t.top-n.top+t.height/2-12;h.style.left="4px",h.style.top=`${Math.max(4,a)}px`,h.style.display="flex"},C=e=>{if(v=Array.from(p.querySelectorAll(`.${a.classNames.block.table.headerCell}`)).indexOf(e),v<0)return;const t=e.getBoundingClientRect(),n=r.getBoundingClientRect(),o=t.left-n.left+t.width/2-12,i=t.top-n.top-20;f.style.left=`${o}px`,f.style.top=`${Math.max(4,i)}px`,f.style.display="flex"};e.addEventListener(t,d,"mouseover",e=>{const t=e.target.closest("tr");t&&w(t)}),e.addEventListener(t,c,"mouseover",e=>{const t=e.target.closest(`.${a.classNames.block.table.headerCell}`);t&&C(t)}),e.addEventListener(t,d,"mouseover",e=>{const t=e.target.closest(`.${a.classNames.block.table.cell}`);if(!t)return;const n=t.closest("tr");if(!n)return;const o=Array.from(n.querySelectorAll(`.${a.classNames.block.table.cell}`)).indexOf(t);if(o>=0){const e=p.querySelectorAll(`.${a.classNames.block.table.headerCell}`)[o];e&&C(e)}w(n)});const E=()=>{y&&"none"!==h.style.display&&w(y);const e=p.querySelectorAll(`.${a.classNames.block.table.headerCell}`)[v];e&&"none"!==f.style.display&&C(e)};e.addEventListener(t,window,"scroll",E,{passive:!0}),e.addEventListener(t,u,"scroll",E,{passive:!0}),e.addEventListener(t,h,"click",n=>{if(n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation?.(),!y)return;const i=Array.from(d.querySelectorAll("tr")),s=i.indexOf(y),l=h.getBoundingClientRect(),c=r.getBoundingClientRect();e.createMenu(t,r,h,f,[{label:"Move up",onClick:()=>{s>0&&(d.insertBefore(y,i[s-1]),sr.saveBlockData(y))},shortcut:m("up")},{label:"Move down",onClick:()=>{s>=0&&s<i.length-1&&(d.insertBefore(i[s+1],y),sr.saveBlockData(y))},shortcut:m("down")},{label:"Insert above",onClick:()=>{const n=p.querySelectorAll(`.${a.classNames.block.table.headerCell}`).length||3,o=e.createRow(t,Array.from({length:n},()=>""));d.insertBefore(o,y),sr.saveBlockData(y)},shortcut:x("up")},{label:"Insert below",onClick:()=>{const n=p.querySelectorAll(`.${a.classNames.block.table.headerCell}`).length||3,o=e.createRow(t,Array.from({length:n},()=>""));y.nextSibling?d.insertBefore(o,y.nextSibling):d.appendChild(o),sr.saveBlockData(y)},shortcut:x("down")},{label:"Delete",onClick:()=>{i.length>1&&(y.remove(),sr.saveBlockData(y))},shortcut:g()}],l.left-c.left,l.bottom-c.top+4,o,k)}),e.addEventListener(t,f,"click",n=>{if(n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation?.(),v<0)return;const i=Array.from(p.querySelectorAll(`.${a.classNames.block.table.headerCell}`)),s=f.getBoundingClientRect(),l=r.getBoundingClientRect();e.createMenu(t,r,h,f,[{label:"Move left",onClick:()=>{if(v<=0)return;const e=v,t=i[e-1],n=i[e];t&&n&&p.insertBefore(n,t),d.querySelectorAll("tr").forEach(t=>{const n=Array.from(t.querySelectorAll(`.${a.classNames.block.table.cell}`)),o=n[e-1],i=n[e];o&&i&&t.insertBefore(i,o)}),v=e-1,sr.saveBlockData(p)},shortcut:m("left")},{label:"Move right",onClick:()=>{const e=v;if(e<0||e>=i.length-1)return;const t=i[e],n=i[e+1];t&&n&&p.insertBefore(n,t),d.querySelectorAll("tr").forEach(t=>{const n=Array.from(t.querySelectorAll(`.${a.classNames.block.table.cell}`)),o=n[e],i=n[e+1];o&&i&&t.insertBefore(i,o)}),v=e+1,sr.saveBlockData(p)},shortcut:m("right")},{label:"Insert left",onClick:()=>{const n=v,o=e.createHeaderCell(t,"");p.insertBefore(o,i[n]),d.querySelectorAll("tr").forEach(o=>{const i=e.createCell(t,""),r=o.querySelectorAll(`.${a.classNames.block.table.cell}`);r[n]?o.insertBefore(i,r[n]):o.appendChild(i)}),sr.saveBlockData(p)},shortcut:x("left")},{label:"Insert right",onClick:()=>{const n=v+1,o=i[v]?.nextSibling||null,r=e.createHeaderCell(t,"");p.insertBefore(r,o),d.querySelectorAll("tr").forEach(o=>{const i=e.createCell(t,""),r=o.querySelectorAll(`.${a.classNames.block.table.cell}`);r[n]?o.insertBefore(i,r[n]):o.appendChild(i)}),sr.saveBlockData(p)},shortcut:x("right")},{label:"Delete",onClick:()=>{const e=p.querySelectorAll(`.${a.classNames.block.table.headerCell}`);if(v<0||e.length<=1)return;const t=e[v];t?.parentElement?.removeChild(t),d.querySelectorAll("tr").forEach(e=>{const t=e.querySelectorAll(`.${a.classNames.block.table.cell}`);t[v]&&t[v].parentElement?.removeChild(t[v])}),sr.saveBlockData(p)},shortcut:b()}],s.left-l.left,s.bottom-l.top+4,o,k)});Array.from(d.querySelectorAll("tr")).forEach(n=>(n=>{e.addEventListener(t,n,"mouseenter",()=>w(n))})(n)),Array.from(p.querySelectorAll(`.${a.classNames.block.table.headerCell}`)).forEach(n=>{return a=n,void e.addEventListener(t,a,"mouseenter",()=>C(a));var a});const S=a.createStyledElement("div","clepit-table-caption-download-container",{classNames:o?.classNames?.container,styles:o?.styles?.container});S.style.display="flex",S.style.alignItems="center",S.style.gap="8px",S.style.marginTop="8px";const N=a.createStyledElement("div",`${a.classNames.block.table.caption}`,{classNames:o?.classNames?.caption,styles:o?.styles?.caption});N.contentEditable="true",N.setAttribute("tabindex","0"),N.setAttribute("data-placeholder",e.captionPlaceholder),N.style.flex="1",N.style.minWidth="0",N.innerHTML=I(i.caption),e.addEventListener(t,N,"input",sr.handleInput),e.addEventListener(t,N,"keydown",e.handleKeydown),e.addEventListener(t,N,"click",e.handleClick),S.appendChild(N);const A=a.createStyledElement("div",`${a.classNames.block.table.downloadSwitch}`);A.style.flexShrink="0";const L=ut.create({checked:i.showDownload||!1,label:"Allow download",onToggle:e=>{const n=r.closest(`.${a.classNames.block.container}`);if(n){const a=n.getAttribute("data-id");a&&l.getState().partialUpdateBlockData(t,sr.getBlockIndex(t,a),{showDownload:e})}}});A.appendChild(L),S.appendChild(A),r.appendChild(S);return e.addEventListener(t,r,"focusin",()=>{const e=document.activeElement;if(e&&r.contains(e))if(e.classList.contains(a.classNames.block.table.cell)){const t=e.closest("tr");t&&(y=t,w(t))}else e.classList.contains(a.classNames.block.table.headerCell)&&C(e)}),r}static createRow(t,n,o){const i=l.getState().getInstance(t),r=i?.config.classNames?.blocks?.table?.row,s=i?.config.styles?.blocks?.table?.row,c=a.createStyledElement("tr",o?`${a.classNames.block.table.headerRow}`:`${a.classNames.block.table.row}`,{classNames:r,styles:s});for(let a=0;a<n.length;a++)c.appendChild(o?e.createHeaderCell(t,n[a]):e.createCell(t,n[a]));return c.querySelector(`.${a.classNames.block.table.cell}`)?.focus(),c}static createCell(t,n){const o=l.getState().getInstance(t),i=o?.config.classNames?.blocks?.table?.cell,r=o?.config.styles?.blocks?.table?.cell,s=a.createStyledElement("td",`${a.classNames.block.table.cell}`,{classNames:i,styles:r});return s.contentEditable="true",s.setAttribute("tabindex","0"),s.setAttribute("data-placeholder",e.cellPlaceholder),s.innerHTML=I(n),e.addEventListener(t,s,"input",sr.handleInput),e.addEventListener(t,s,"keydown",e.handleKeydown),e.addEventListener(t,s,"click",e.handleClick),s}static createHeaderCell(t,n){const o=l.getState().getInstance(t),i=o?.config.classNames?.blocks?.table?.header,r=o?.config.styles?.blocks?.table?.header,s=a.createStyledElement("th",`${a.classNames.block.table.headerCell}`,{classNames:i,styles:r});return s.contentEditable="true",s.setAttribute("tabindex","0"),s.setAttribute("data-placeholder",e.headerPlaceholder),s.innerHTML=I(n),e.addEventListener(t,s,"input",sr.handleInput),e.addEventListener(t,s,"keydown",e.handleKeydown),e.addEventListener(t,s,"click",e.handleClick),s}static handleAction(t,n){const a=n.querySelector("table");if(a)switch(t){case"addRow":return e.addRow(a);case"removeRow":return e.removeRow(a);case"addColumn":return e.addColumn(a);case"removeColumn":return e.removeColumn(a)}}static addRow(t){const n=t.querySelector("tbody");if(!n)return;const a=sr.getEditorId(t);if(!a)return;const o=t.querySelector("thead tr")?.querySelectorAll("th").length||e.defaultData.data[0].length,i=e.createRow(a,Array.from({length:o},()=>""));n.appendChild(i)}static removeRow(e){const t=e.querySelector("tbody");if(!t)return;const n=t.querySelectorAll("tr");n.length>1&&t.removeChild(n[n.length-1])}static addColumn(t){const n=sr.getEditorId(t);if(!n)return;const a=t.querySelector("thead tr"),o=t.querySelector("tbody");if(!a||!o)return;const i=e.createHeaderCell(n,"");a.appendChild(i),o.querySelectorAll("tr").forEach(t=>{const a=e.createCell(n,"");t.appendChild(a)})}static removeColumn(e){const t=e.querySelector("thead tr"),n=e.querySelector("tbody");if(!t||!n)return;const a=t.querySelectorAll("th");a.length>1&&(t.removeChild(a[a.length-1]),n.querySelectorAll("tr").forEach(e=>{const t=e.querySelectorAll("td");t.length>1&&e.removeChild(t[t.length-1])}))}static createMenu(t,n,o,i,r,s,l,c,p){p&&(p.remove(),p=null);const d=a.createStyledElement("div","clepit-block-operations-menu clepit-table-menu",{classNames:c?.classNames?.menu,styles:c?.styles?.menu});d.classList.add("clepit-block-operations-menu--visible"),d.style.position="absolute",d.style.zIndex="20",d.style.left=`${s}px`,d.style.top=`${l}px`,d.style.minWidth="180px",r.forEach(n=>{const o="delete"===n.label.toLowerCase(),i=a.createStyledElement("div","clepit-menu-item"+(o?" clepit-menu-item--danger":""),{classNames:c?.classNames?.menuItem,styles:c?.styles?.menuItem});i.style.fontSize="14px";const r=a.createStyledElement("span","clepit-menu-icon"),s=n.label.toLowerCase();s.includes("move up")?r.textContent="↑":s.includes("move down")?r.textContent="↓":s.includes("move left")?r.textContent="←":s.includes("move right")?r.textContent="→":s.includes("insert")?r.textContent="+":s.includes("delete")?r.textContent="×":r.textContent="•";const l=a.createStyledElement("span","clepit-menu-text");if(l.textContent=n.label,i.appendChild(r),i.appendChild(l),n.shortcut){const e=a.createStyledElement("span","clepit-menu-shortcut");e.style.marginLeft="auto",e.style.fontSize="9px",e.style.color="#666",e.style.opacity="0.7",e.textContent=n.shortcut,i.appendChild(e)}e.addEventListener(t,i,"click",e=>{e.stopPropagation(),e.stopImmediatePropagation?.(),n.onClick(),p&&(p.remove(),p=null)}),d.appendChild(i)}),n.appendChild(d),p=d;const u=e=>{d.contains(e.target)||e.target===o||e.target===i||(d.remove(),p=null,document.removeEventListener("click",u))};return setTimeout(()=>document.addEventListener("click",u),0),d}static handleClick(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget.closest(`.${a.classNames.block.container}`);t&&sr.setActiveBlock(t)}static handleKeydown(e){const t=e,n=e.currentTarget,o=sr.getEditorId(n);if(!o)return;const i=n.closest(`.${a.classNames.block.container}`);if(!i)return;const r=sr.getBlockIndex(o,i.getAttribute("data-id")),s=t.metaKey||t.ctrlKey;if(t.shiftKey)switch(t.key){case"ArrowUp":e.preventDefault(),e.stopPropagation(),r>0&&sr.moveBlock(o,r,r-1);break;case"ArrowDown":e.preventDefault(),e.stopPropagation();const t=sr.getBlocks(o);t&&r<t.length-1&&sr.moveBlock(o,r,r+1)}else if(s){const i=n.closest("table"),s=i.querySelector("tbody"),l=i.querySelector("thead tr");switch(t.key){case"ArrowUp":if(n.classList.contains(a.classNames.block.table.cell)){e.preventDefault(),e.stopPropagation();const t=n.closest("tr"),o=Array.from(s.querySelectorAll("tr")),i=o.indexOf(t);if(i>0){const e=Array.from(t.querySelectorAll(`.${a.classNames.block.table.cell}`)).indexOf(n);s.insertBefore(t,o[i-1]),sr.saveBlockData(t);const r=t.querySelectorAll(`.${a.classNames.block.table.cell}`)[e];r&&r.focus()}}break;case"ArrowDown":if(n.classList.contains(a.classNames.block.table.cell)){e.preventDefault(),e.stopPropagation();const t=n.closest("tr"),o=Array.from(s.querySelectorAll("tr")),i=o.indexOf(t);if(i>=0&&i<o.length-1){const e=Array.from(t.querySelectorAll(`.${a.classNames.block.table.cell}`)).indexOf(n);s.insertBefore(o[i+1],t),sr.saveBlockData(t);const r=t.querySelectorAll(`.${a.classNames.block.table.cell}`)[e];r&&r.focus()}}break;case"ArrowLeft":let t=-1;const c=Array.from(l.querySelectorAll(`.${a.classNames.block.table.headerCell}`));if(n.classList.contains(a.classNames.block.table.headerCell))t=c.indexOf(n);else if(n.classList.contains(a.classNames.block.table.cell)){const e=n.closest("tr");t=Array.from(e.querySelectorAll(`.${a.classNames.block.table.cell}`)).indexOf(n)}if(t>0){e.preventDefault(),e.stopPropagation();const o=t,r=c[o-1],s=c[o];if(r&&s&&l.insertBefore(s,r),i.querySelectorAll("tbody tr").forEach(e=>{const t=Array.from(e.querySelectorAll(`.${a.classNames.block.table.cell}`)),n=t[o-1],i=t[o];n&&i&&e.insertBefore(i,n)}),n.classList.contains(a.classNames.block.table.cell)){const e=n.closest("tr").querySelectorAll(`.${a.classNames.block.table.cell}`)[o-1];e&&e.focus()}else{s&&s.focus()}sr.saveBlockData(l)}break;case"ArrowRight":let p=-1;const d=Array.from(l.querySelectorAll(`.${a.classNames.block.table.headerCell}`));if(n.classList.contains(a.classNames.block.table.headerCell))p=d.indexOf(n);else if(n.classList.contains(a.classNames.block.table.cell)){const e=n.closest("tr");p=Array.from(e.querySelectorAll(`.${a.classNames.block.table.cell}`)).indexOf(n)}if(p<d.length-1){e.preventDefault(),e.stopPropagation();const t=p,o=d[t],r=d[t+1];if(o&&r&&l.insertBefore(r,o),i.querySelectorAll("tbody tr").forEach(e=>{const n=Array.from(e.querySelectorAll(`.${a.classNames.block.table.cell}`)),o=n[t],i=n[t+1];o&&i&&e.insertBefore(i,o)}),n.classList.contains(a.classNames.block.table.cell)){const e=n.closest("tr").querySelectorAll(`.${a.classNames.block.table.cell}`)[t+1];e&&e.focus()}else{r&&r.focus()}sr.saveBlockData(l)}break;case"Backspace":if(n.classList.contains(a.classNames.block.table.cell)){e.preventDefault(),e.stopPropagation();const t=n.closest("tr");Array.from(s.querySelectorAll("tr")).length>1&&(t.remove(),sr.saveBlockData(t))}else e.preventDefault(),e.stopPropagation(),sr.removeBlock(o,r);break;case"Delete":let u=-1;const m=Array.from(l.querySelectorAll(`.${a.classNames.block.table.headerCell}`));if(n.classList.contains(a.classNames.block.table.headerCell))u=m.indexOf(n);else if(n.classList.contains(a.classNames.block.table.cell)){const e=n.closest("tr");u=Array.from(e.querySelectorAll(`.${a.classNames.block.table.cell}`)).indexOf(n)}if(u>=0&&m.length>1){e.preventDefault(),e.stopPropagation();const t=m[u];t?.parentElement?.removeChild(t),i.querySelectorAll("tbody tr").forEach(e=>{const t=e.querySelectorAll(`.${a.classNames.block.table.cell}`);t[u]&&t[u].parentElement?.removeChild(t[u])}),sr.saveBlockData(l)}else e.preventDefault(),e.stopPropagation(),sr.removeBlock(o,r)}}else if("Enter"===t.key)e.preventDefault(),e.stopPropagation(),sr.insertBlock({data:{html:""},type:"paragraph"},o,r+1);else if("Backspace"===t.key){const t=n.closest(`.${a.classNames.block.container}`);if(!t)return;Array.from(t.querySelectorAll(`.${a.classNames.block.table.cell},.${a.classNames.block.table.headerCell}`)).every(e=>M(e.innerHTML))&&(e.preventDefault(),e.stopPropagation(),sr.removeBlock(o,r))}else{sr.ensureActiveBlock(o);const i=sr.getBlocks(o);switch(t.key){case"ArrowUp":if(e.preventDefault(),e.stopPropagation(),n.classList.contains(a.classNames.block.table.caption)){const e=n.closest(`.${a.classNames.block.container}`)?.querySelector("table");if(e){const t=e.querySelector("tbody")?.lastElementChild;if(t&&t.cells.length>0){const e=t.cells[t.cells.length-1];return void(e&&e.focus())}}}const t=n.closest("table");if(!t)return;const o=n.closest("tr"),s=Array.from(o?.cells||[]).indexOf(n);if("TBODY"===o?.parentElement?.tagName&&o===o.parentElement.firstElementChild){const e=t.querySelector("thead")?.querySelector("tr");if(e&&e.cells[s])return void e.cells[s].focus()}if(o?.previousElementSibling){const e=o.previousElementSibling.cells[s];e&&e.focus()}else if(r>0){const e=i[r-1];e&&sr.focusBlock(e)}return;case"ArrowDown":if(e.preventDefault(),e.stopPropagation(),n.classList.contains(a.classNames.block.table.caption)){if(r<i.length-1){const e=i[r+1];e&&sr.focusBlock(e)}return}const l=n.closest("table");if(!l)return;const c=n.closest("tr"),p=Array.from(c?.cells||[]).indexOf(n);if("THEAD"===c?.parentElement?.tagName){const e=l.querySelector("tbody")?.firstElementChild;if(e&&e.cells[p])return void e.cells[p].focus()}if(c?.nextElementSibling){const e=c.nextElementSibling.cells[p];e&&e.focus()}else{if("TBODY"===c?.parentElement?.tagName&&c===c.parentElement.lastElementChild){const e=l.closest(`.${a.classNames.block.container}`)?.querySelector(`.${a.classNames.block.table.caption}`);if(e)return void e.focus()}if(r<i.length-1){const e=i[r+1];e&&sr.focusBlock(e)}}return;case"ArrowLeft":if(!T(n,"left"))return;e.preventDefault(),e.stopPropagation();const d=n.closest("table");if(!d)return;const u=n.closest("tr"),m=Array.from(u?.cells||[]).indexOf(n);if(m>0){const e=u?.cells[m-1];e&&e.focus()}else{if("TBODY"===u?.parentElement?.tagName&&u===u.parentElement.firstElementChild){const e=d.querySelector("thead")?.querySelector("tr");if(e&&e.cells.length>0){const t=e.cells[e.cells.length-1];return void(t&&t.focus())}}if(u?.previousElementSibling){const e=u.previousElementSibling,t=e.cells[e.cells.length-1];t&&t.focus()}}return;case"ArrowRight":if(!T(n,"right"))return;e.preventDefault(),e.stopPropagation();const h=n.closest("table");if(!h)return;const g=n.closest("tr"),b=Array.from(g?.cells||[]).indexOf(n);if(b<(g?.cells.length||0)-1){const e=g?.cells[b+1];e&&e.focus()}else{if("THEAD"===g?.parentElement?.tagName){const e=h.querySelector("tbody")?.firstElementChild;if(e&&e.cells.length>0){const t=e.cells[0];return void(t&&t.focus())}}if(g?.nextElementSibling){const e=g.nextElementSibling.cells[0];e&&e.focus()}}return}}}static isEmpty(e){const t=e.querySelector(`.${a.classNames.block.table.caption}`),n=e.querySelectorAll(`.${a.classNames.block.table.cell},.${a.classNames.block.table.headerCell}`);let o=!1,i=!1;return t?M(t.innerHTML)&&(o=!0):o=!0,n?Array.from(n).every(e=>M(e.innerHTML))&&(i=!0):i=!0,o&&i}static isEmptyData(e){return M(e.caption)&&e.data.every(e=>e.every(e=>M(e)))}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},ka="http://www.w3.org/2000/svg",wa=["M3 15C3 17.8284 3 19.2426 3.87868 20.1213C4.75736 21 6.17157 21 9 21H15C17.8284 21 19.2426 21 20.1213 20.1213C21 19.2426 21 17.8284 21 15","M12 3V16M12 16L16 11.625M12 16L8 11.625"],Ca=class e{static{this.eventListenersMap=new WeakMap}static render(t,n,o,i,r){if(a.injectStyles("clepit-table-output-styles",va),!e.validate(t))return xe();if(xa.isEmptyData(t))return document.createElement("div");const s=e.draw(t,ue);if(!s)return document.createElement("div");const l=ve(s);i?.container&&l.classList.add(i.container),o?.container&&Object.assign(l.style,o.container);const c=l.querySelector(".clepit-output-table-caption");c&&i?.caption&&c.classList.add(i.caption),c&&o?.caption&&Object.assign(c.style,o.caption);const p=l.querySelector(".clepit-output-table-footer-container");return p&&i?.footerContainer&&p.classList.add(i.footerContainer),p&&o?.footerContainer&&Object.assign(p.style,o.footerContainer),e.attach(l,t,o,i,r),l}static activate(t,n){return!e.validate(n)||xa.isEmptyData(n)?()=>{}:e.attach(t,n)}static attach(t,n,a,o,i){const r=t.querySelector(".clepit-output-table-download-btn");if(!r)return()=>{};o?.downloadButton&&r.classList.add(o.downloadButton),a?.downloadButton&&Object.assign(r.style,a.downloadButton);const s=()=>e.downloadTableAsCSV(n);r.addEventListener("click",s);const c=i?document.getElementById(i):null;if(c){const t=e.eventListenersMap.get(c)??[];t.push({element:r,event:"click",handler:s}),e.eventListenersMap.set(c,t)}const p=i?l.getState().getInstance(i):null,d=J(r,"Download CSV","above",p?.config.classNames?.tooltips,p?.config.styles?.tooltips);return()=>{r.removeEventListener("click",s),d()}}static draw(t,n=ue){if(!e.validate(t)||xa.isEmptyData(t))return null;const a=Array.isArray(t.data)&&t.data.length>0?t.data:[];if(0===a.length)return null;const o=n.create("div");o.addClass("clepit-output-table-wrapper");const i=n.create("div");i.addClass("clepit-output-table-scroller");const r=n.create("table");r.addClass("clepit-output-table");const s=n.create("thead"),l=n.create("tr");for(const e of a[0]??[]){const t=n.create("th");t.setText(e),l.append(t)}if(s.append(l),r.append(s),a.length>1){const e=n.create("tbody");for(const t of a.slice(1)){const a=n.create("tr");for(const e of t){const t=n.create("td");t.setText(e),a.append(t)}e.append(a)}r.append(e)}if(i.append(r),o.append(i),t.caption||t.showDownload){const a=n.create("div");if(a.addClass("clepit-output-table-footer-container"),t.caption){const e=n.create("figcaption");e.addClass("clepit-output-table-caption"),t.caption.trim()&&e.setHtml(t.caption),a.append(e)}if(t.showDownload){const t=n.create("button");t.addClass("clepit-output-table-download-btn"),t.setAttribute("type","button"),t.setAttribute("aria-label","Download CSV"),t.append(e.drawDownloadIcon(n)),a.append(t)}o.append(a)}return o}static drawDownloadIcon(e){const t=e.createNS(ka,"svg");t.setAttribute("class","clepit-download-icon"),t.setAttribute("width","20"),t.setAttribute("height","20"),t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("fill","none");for(const n of wa){const a=e.createNS(ka,"path");a.setAttribute("d",n),a.setAttribute("stroke","currentColor"),a.setAttribute("stroke-width","1.5"),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),t.append(a)}return t}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&Array.isArray(e.data)}static downloadTableAsCSV(e){const t=e.data||[];if(0===t.length)return;const n=t.map(e=>e.map(e=>{const t=e.replace(/"/g,'""');return t.includes(",")||t.includes('"')||t.includes("\n")?`"${t}"`:t}).join(",")).join("\n"),a=new Blob([n],{type:"text/csv;charset=utf-8;"}),o=document.createElement("a"),i=URL.createObjectURL(a);o.setAttribute("href",i),o.setAttribute("download","table-data.csv"),o.style.visibility="hidden",document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i)}static destroy(t){const n=document.getElementById(t);if(!n)return console.warn("TableOutput::destroy: Container not found for containerId:",t);const a=e.eventListenersMap.get(n);a&&(a.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap.delete(n))}},Ea="\n.clepit-toc {\n display: block;\n}\n.clepit-toc__entry {\n display: block;\n padding: 2px 0;\n color: inherit;\n text-decoration: none;\n}\n.clepit-toc__entry:hover {\n text-decoration: underline;\n}\n.clepit-toc__empty {\n opacity: 0.55;\n}\n",Sa=Ea,Na=Ea,Aa={h1:0,h2:1,h3:2,h4:3,h5:4,h6:5},La=class{static render(e,t,n,o){a.injectStyles("toc-output",Na);const i=(t?.documentBlocks??[]).filter(e=>"header"===e.type),r=a.createStyledElement("nav","clepit-toc clepit-output-toc",{classNames:o?.list,styles:n?.list});if(0===i.length){const e=document.createElement("div");return e.className="clepit-toc__empty",e.textContent="Table of contents — headings appear here",r.appendChild(e),r}return i.forEach((e,t)=>{const i=e.data,s=a.createStyledElement("a","clepit-toc__entry",{classNames:o?.entry,styles:n?.entry});s.setAttribute("data-toc-index",t.toString());const l=Aa[i.level??"h1"];s.style.paddingLeft=16*l+"px",e.id&&(s.href=`#${e.id}`),s.innerHTML=I(i.html),r.appendChild(s)}),r}static draw(e,t=ue,n){if(null==e||"object"!=typeof e)return null;const a=(n?.documentBlocks??[]).filter(e=>"header"===e.type);if(0===a.length)return null;const o=t.create("nav");return o.addClass("clepit-toc","clepit-output-toc"),a.forEach((e,n)=>{const a=e.data,i=t.create("a");i.addClass("clepit-toc__entry"),i.setAttribute("data-toc-index",n.toString()),i.setAttribute("style",`padding-left: ${16*Aa[a.level??"h1"]}px;`),e.id&&i.setAttribute("href",`#${e.id}`),i.setHtml(a.html),o.append(i)}),o}},Ba="\n.clepit-typeset {\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n padding: 12px;\n}\n.clepit-typeset__kind {\n display: block;\n opacity: 0.7;\n font-size: 0.85em;\n margin-bottom: 6px;\n}\n.clepit-typeset__kind:has(+ .clepit-typeset__title) {\n display: inline-block;\n font-size: 11px;\n font-weight: 700;\n letter-spacing: 0.06em;\n margin-bottom: 0;\n text-transform: uppercase;\n}\n.clepit-typeset__title {\n display: block;\n font-size: 1em;\n font-weight: 600;\n margin: 2px 0 8px;\n opacity: 1;\n}\n.clepit-typeset__title[data-placeholder]:empty::before {\n color: inherit;\n content: attr(data-placeholder);\n font-style: italic;\n font-weight: 400;\n opacity: 0.5;\n pointer-events: none;\n}\n.clepit-typeset__source {\n display: block;\n margin: 0;\n white-space: pre-wrap;\n word-break: break-word;\n font-family: ui-monospace, SFMono-Regular, Menlo, monospace;\n}\n.clepit-typeset--input .clepit-typeset__source {\n outline: none;\n}\n.clepit-typeset__diagram {\n display: block;\n max-width: 100%;\n height: auto;\n}\n.clepit-typeset__node {\n fill: rgba(127, 127, 127, 0.08);\n stroke: currentColor;\n stroke-width: 1.5;\n}\n.clepit-typeset__label {\n fill: currentColor;\n font-size: 13px;\n font-family: inherit;\n}\n.clepit-typeset__edge,\n.clepit-typeset__message,\n.clepit-typeset__lifeline {\n stroke: currentColor;\n fill: none;\n}\n.clepit-typeset__lifeline {\n stroke-dasharray: 4 4;\n opacity: 0.55;\n}\n.clepit-typeset__arrowhead {\n fill: currentColor;\n}\n.clepit-typeset__edge-label {\n fill: currentColor;\n font-size: 12px;\n font-family: inherit;\n}\n.clepit-typeset__activation {\n fill: rgba(127, 127, 127, 0.3);\n stroke: currentColor;\n stroke-width: 1;\n}\n.clepit-typeset__note {\n fill: rgba(240, 200, 100, 0.18);\n stroke: currentColor;\n stroke-width: 1;\n}\n.clepit-typeset__formula {\n display: block;\n max-width: 100%;\n height: auto;\n}\n.clepit-typeset__glyph {\n fill: currentColor;\n font-family: ui-serif, Georgia, 'Times New Roman', serif;\n}\n.clepit-typeset__glyph--text {\n font-family: inherit;\n}\n.clepit-typeset__rule,\n.clepit-typeset__radical {\n fill: currentColor;\n}\n.clepit-typeset__radical {\n stroke: currentColor;\n stroke-width: 1.2;\n fill: none;\n}\n.clepit-typeset__fallback-reason {\n display: block;\n opacity: 0.7;\n font-size: 0.85em;\n margin-bottom: 6px;\n}\n",$a=Ba,Ma=Ba,Ia=.55,Ta=.52,qa=(e,t,n)=>e.draw.map(e=>({...e,x:e.x+t,y:e.y+n}));function Da(e,t=18){switch(e.kind){case"atom":return _a(e.text,e.style,t);case"space":return{depth:0,draw:[],height:0,width:e.width/18*t};case"row":return function(e,t){const n=[];let a=0,o=0,i=0;for(const r of e){const e=Da(r,t);n.push(...qa(e,a,0)),a+=e.width,o=Math.max(o,e.height),i=Math.max(i,e.depth)}return{depth:i,draw:n,height:o,width:a}}(e.items,t);case"script":return function(e,t){const n=Da(e.base,t),a=ja(t),o=[...n.draw];let i=n.width,r=n.height,s=n.depth;if(null!==e.sup){const s=Da(e.sup,a),l=Math.max(.62*n.height,.4*t);o.push(...qa(s,n.width,-l)),i=Math.max(i,n.width+s.width),r=Math.max(r,l+s.height)}if(null!==e.sub){const r=Da(e.sub,a),l=Math.max(.5*n.depth,.22*t);o.push(...qa(r,n.width,l)),i=Math.max(i,n.width+r.width),s=Math.max(s,l+r.depth)}return{depth:s,draw:o,height:r,width:i}}(e,t);case"fraction":return function(e,t){const n=Da(e.numerator,t),a=Da(e.denominator,t),o=.25*t,i=.045*t,r=.18*t,s=Math.max(n.width,a.width)+.3*t,l=-(o+r+n.depth),c=-o+r+a.height;return{depth:c+a.depth,draw:[...qa(n,(s-n.width)/2,l),{kind:"rule",thickness:i,width:s,x:0,y:-o},...qa(a,(s-a.width)/2,c)],height:-l+n.height,width:s}}(e,t);case"radical":return function(e,t){const n=Da(e.radicand,t),a=.6*t,o=null===e.index?null:Da(e.index,ja(ja(t))),i=a+.6*(o?.width??0),r=n.height+.18*t,s=[{height:r+n.depth,kind:"radical",size:t,width:n.width+.2*t,x:i,y:0},...qa(n,i+.12*t,0)];null!==o&&s.push(...qa(o,.1*t,.55*-r));return{depth:n.depth,draw:s,height:r,width:i+n.width+.3*t}}(e,t);case"bigop":return function(e,t){const n=1.4*t,a=_a(e.symbol,"upright",n),o=ja(t),i=null===e.upper?null:Da(e.upper,o),r=null===e.lower?null:Da(e.lower,o),s=Math.max(a.width,i?.width??0,r?.width??0),l=[...qa(a,(s-a.width)/2,0)];let c=a.height,p=a.depth;if(null!==i){const e=a.height+i.depth+.16*t;l.push(...qa(i,(s-i.width)/2,-e)),c=e+i.height}if(null!==r){const e=a.depth+r.height+.16*t;l.push(...qa(r,(s-r.width)/2,e)),p=e+r.depth}return{depth:p,draw:l,height:c,width:s}}(e,t);case"accent":return function(e,t){const n=Da(e.base,t),a=_a(e.over,"upright",ja(t)),o="_"===e.over;return{depth:o?n.depth+.2*t:n.depth,draw:[...n.draw,...qa(a,(n.width-a.width)/2,o?n.depth+.18*t:-(n.height+.04*t))],height:o?n.height:n.height+.2*t,width:n.width}}(e,t);case"delimited":return function(e,t){const n=Da(e.body,t),a=n.height+n.depth,o=Math.max(t,a*(1/.55)*.62),i=""===e.open?{depth:0,draw:[],height:0,width:0}:_a(e.open,"upright",o),r=""===e.close?{depth:0,draw:[],height:0,width:0}:_a(e.close,"upright",o),s=e=>(n.height-n.depth)/2-(e.height-e.depth)/2;return{depth:Math.max(n.depth,i.depth-s(i),r.depth-s(r)),draw:[...qa(i,0,s(i)),...qa(n,i.width,0),...qa(r,i.width+n.width,s(r))],height:Math.max(n.height,i.height+s(i),r.height+s(r)),width:i.width+n.width+r.width}}(e,t);case"matrix":return function(e,t){const n=e.rows.map(e=>e.map(e=>Da(e,t))),a=Math.max(...n.map(e=>e.length),0),o=[];for(let v=0;v<a;v+=1)o.push(Math.max(...n.map(e=>e[v]?.width??0),0));const i=n.map(e=>Math.max(...e.map(e=>e.height),0)),r=n.map(e=>Math.max(...e.map(e=>e.depth),0)),s=.6*t,l=.35*t,c=o.reduce((e,t)=>e+t,0)+s*Math.max(a-1,0),p=i.reduce((e,t,n)=>e+t+(r[n]??0),0)+l*Math.max(n.length-1,0),d=[];let u=-p/2;for(const[v,x]of n.entries()){u+=i[v]??0;let e=0;for(const[t,n]of x.entries()){const a=o[t]??0;d.push(...qa(n,e+(a-n.width)/2,u)),e+=a+s}u+=(r[v]??0)+l}const[m,h]=za[e.style],g=Math.max(t,.62*p),b=""===m?{depth:0,draw:[],height:0,width:0}:_a(m,"upright",g),f=""===h?{depth:0,draw:[],height:0,width:0}:_a(h,"upright",g),y=e=>(e.height-e.depth)/2;return{depth:p/2,draw:[...qa(b,0,y(b)),...d.map(e=>({...e,x:e.x+b.width})),...qa(f,b.width+c,y(f))],height:p/2,width:b.width+c+f.width}}(e,t)}}function _a(e,t,n){const a="italic"===t?Ia:Ta;return{depth:.22*n,draw:[{kind:"glyph",size:n,style:t,text:e,x:0,y:0}],height:.72*n,width:e.length*a*n}}function ja(e){return Math.max(9,.7*e)}var za={bracket:["[","]"],"double-pipe":["‖","‖"],paren:["(",")"],pipe:["|","|"],plain:["",""]};var Oa={alpha:"α",beta:"β",chi:"χ",Delta:"Δ",delta:"δ",epsilon:"ϵ",eta:"η",Gamma:"Γ",gamma:"γ",iota:"ι",kappa:"κ",Lambda:"Λ",lambda:"λ",mu:"μ",nu:"ν",Omega:"Ω",omega:"ω",Phi:"Φ",Pi:"Π",Psi:"Ψ",phi:"ϕ",pi:"π",psi:"ψ",rho:"ρ",Sigma:"Σ",sigma:"σ",Theta:"Θ",tau:"τ",theta:"θ",Upsilon:"Υ",upsilon:"υ",varepsilon:"ε",varphi:"φ",vartheta:"ϑ",Xi:"Ξ",xi:"ξ",zeta:"ζ"},Ha={angle:"∠",approx:"≈",ast:"∗",cap:"∩",cdot:"⋅",cup:"∪",div:"÷",equiv:"≡",exists:"∃",forall:"∀",geq:"≥",in:"∈",infty:"∞",Leftarrow:"⇐",leftarrow:"←",leftrightarrow:"↔",leq:"≤",mp:"∓",nabla:"∇",neg:"¬",neq:"≠",notin:"∉",parallel:"∥",partial:"∂",perp:"⊥",pm:"±",propto:"∝",Rightarrow:"⇒",rightarrow:"→",sim:"∼",simeq:"≃",star:"⋆",subset:"⊂",subseteq:"⊆",supset:"⊃",supseteq:"⊇",times:"×",to:"→"},Pa={bigcap:"⋂",bigcup:"⋃",int:"∫",lim:"lim",oint:"∮",prod:"∏",sum:"∑"},Fa=["arccos","arcsin","arctan","cos","cosh","cot","csc","deg","det","dim","exp","gcd","ln","log","max","min","sec","sin","sinh","tan","tanh"],Ra={bar:"‾",ddot:"¨",dot:"˙",hat:"^",tilde:"~",vec:"→"},Va={",":3,";":5,":":4,"!":-3,qquad:36,quad:18},Ua={".":"","(":"(",")":")","[":"[","]":"]","\\{":"{","\\}":"}","\\|":"‖","|":"|"},Wa=["catcode","csname","def","href","include","input","newcommand","renewcommand","url","write"],Ka={bmatrix:"bracket",matrix:"plain",pmatrix:"paren",Vmatrix:"double-pipe",vmatrix:"pipe"},Ga=/[A-Za-z0-9+\-=<>()[\]|,./!:;]/,Ja=/[A-Za-z]/,Xa=/[0-9]/,Za={mathbf:"bold",mathit:"italic",mathrm:"upright",text:"text"},Ya=class{constructor(e){this.source=e,this.at=0}get done(){return this.at>=this.source.length}peek(e=0){return this.source[this.at+e]??""}take(){const e=this.peek();return this.at+=1,e}skipSpace(){for(;!this.done&&/\s/.test(this.peek());)this.at+=1}readCommand(){if(this.at+=1,!Ja.test(this.peek()))return this.take();let e="";for(;Ja.test(this.peek());)e+=this.take();return e}},Qa=class extends Error{};function eo(e){const t=new Ya(e);try{const e=to(t,null);if(ao(t))throw new Qa("a \\right appears without a matching \\left");if(!t.done)throw new Qa(`"${t.peek()}" is unexpected here`);return{ok:!0,root:e}}catch(n){if(n instanceof Qa)return{ok:!1,reason:n.message};throw n}}function to(e,t){const n=[];for(;(e.skipSpace(),!e.done)&&("}"!==t||"}"!==e.peek())&&("]"!==t||"]"!==e.peek())&&("cell"!==t||"&"!==e.peek()&&!no(e)&&!oo(e))&&!ao(e);){const t=io(e);if(null===t)break;n.push(t)}return(e=>1===e.length&&void 0!==e[0]?e[0]:{items:e,kind:"row"})(n)}function no(e){return"\\"===e.peek()&&"\\"===e.peek(1)}function ao(e){return!!e.source.startsWith("\\right",e.at)&&!Ja.test(e.peek(6))}function oo(e){return"\\"===e.peek()&&e.source.startsWith("\\end",e.at)}function io(e){const t=ro(e);if(null===t)return null;let n=null,a=null;for(;;){e.skipSpace();const t=e.peek();if("^"!==t&&"_"!==t)break;e.take();const o=ro(e);if(null===o)throw new Qa(`"${t}" has nothing after it`);if("^"===t){if(null!==a)throw new Qa("a term carries two superscripts");a=o}else{if(null!==n)throw new Qa("a term carries two subscripts");n=o}}return null===n&&null===a?t:"bigop"===t.kind?{...t,lower:n,upper:a}:{base:t,kind:"script",sub:n,sup:a}}function ro(e){if(e.skipSpace(),e.done)return null;const t=e.peek();if("}"===t||"&"===t||"^"===t||"_"===t)return null;if("{"===t){e.take();const t=to(e,"}");if("}"!==e.peek())throw new Qa("a { group is never closed");return e.take(),t}if("\\"===t)return function(e){const t=e.readCommand();if(Wa.includes(t))throw new Qa(`"\\${t}" is refused for safety, not merely unsupported`);if("\\"===t)throw new Qa("a row break appears outside a matrix");if("begin"===t)return function(e){const t=lo(e),n=Ka[t];if(void 0===n)throw new Qa(`the "${t}" environment is not supported yet`);const a=[];let o=[];for(let i=0;i<4096;i+=1)if(o.push(to(e,"cell")),e.skipSpace(),"&"!==e.peek()){if(!no(e)){if(oo(e)){e.at+=4;const i=lo(e);if(i!==t)throw new Qa(`\\begin{${t}} is closed by \\end{${i}}`);return a.push(o),{kind:"matrix",rows:a,style:n}}throw new Qa(`\\begin{${t}} is never closed`)}e.at+=2,a.push(o),o=[]}else e.take();throw new Qa(`\\begin{${t}} is never closed`)}(e);if("end"===t)throw new Qa("an \\end appears without a matching \\begin");if("frac"===t||"dfrac"===t||"tfrac"===t){const t=so(e);return{denominator:so(e),kind:"fraction",numerator:t}}if("sqrt"===t)return function(e){e.skipSpace();let t=null;if("["===e.peek()){if(e.take(),t=to(e,"]"),"]"!==e.peek())throw new Qa("a \\sqrt index is never closed");e.take()}return{index:t,kind:"radical",radicand:so(e)}}(e);if("left"===t)return function(e){const t=co(e,"left"),n=to(e,null);if(!ao(e))throw new Qa("a \\left has no matching \\right");return e.at+=6,{body:n,close:co(e,"right"),kind:"delimited",open:t}}(e);if("right"===t)throw new Qa("a \\right appears without a matching \\left");const n=Za[t];if(void 0!==n)return{kind:"atom",style:n,text:lo(e)};const a=Ra[t];if(void 0!==a)return{base:so(e),kind:"accent",over:a};if("overline"===t)return{base:so(e),kind:"accent",over:"‾"};if("underline"===t)return{base:so(e),kind:"accent",over:"_"};const o=Pa[t];if(void 0!==o)return{kind:"bigop",lower:null,symbol:o,upper:null};const i=Oa[t];if(void 0!==i)return{kind:"atom",style:"italic",text:i};const r=Ha[t];if(void 0!==r)return{kind:"atom",style:"upright",text:r};if(Fa.includes(t))return{kind:"atom",style:"upright",text:t};const s=Va[t];if(void 0!==s)return{kind:"space",width:s};const l=Ua[`\\${t}`];if(void 0!==l)return{kind:"atom",style:"upright",text:l};throw new Qa(`"\\${t}" is not supported yet`)}(e);if(Ga.test(t))return e.take(),{kind:"atom",style:Xa.test(t)?"upright":"italic",text:t};throw new Qa(`"${t}" is not a character this engine understands`)}function so(e){if(e.skipSpace(),"{"!==e.peek()){const t=ro(e);if(null===t)throw new Qa("a command is missing its argument");return t}e.take();const t=to(e,"}");if("}"!==e.peek())throw new Qa("a { group is never closed");return e.take(),t}function lo(e){if(e.skipSpace(),"{"!==e.peek())throw new Qa("a text command is missing its { group");e.take();let t="",n=1;for(;!e.done;){const a=e.peek();if("{"===a&&(n+=1),"}"===a&&(n-=1,0===n))return e.take(),t;t+=e.take()}throw new Qa("a text command’s { group is never closed")}function co(e,t){e.skipSpace();const n=e.peek();if("\\"===n){const t=e.readCommand(),n=Ua[`\\${t}`];if(void 0===n)throw new Qa(`"\\${t}" is not a delimiter this engine understands`);return n}const a=Ua[n];if(void 0===a)throw new Qa(`\\${t} is missing a delimiter`);return e.take(),a}var po={bold:{style:"normal",weight:"700"},italic:{style:"italic",weight:"400"},text:{style:"normal",weight:"400"},upright:{style:"normal",weight:"400"}};function uo(e,t,n){const a=n.createNS("http://www.w3.org/2000/svg",e);for(const[o,i]of Object.entries(t))a.setAttribute(o,String(i));return a}function mo(e,t=ue){const n=e.width+16,a=e.height+e.depth+16,o=e.height+8,i=uo("svg",{class:"clepit-typeset__formula",height:a,role:"img",viewBox:`0 0 ${n} ${a}`,width:n},t);for(const r of e.draw){if("glyph"===r.kind){const e=po[r.style],n=uo("text",{class:"clepit-typeset__glyph","dominant-baseline":"alphabetic","font-size":r.size,"font-style":e.style,"font-weight":e.weight,x:r.x+8,y:o+r.y},t);"text"===r.style&&n.setAttribute("class","clepit-typeset__glyph clepit-typeset__glyph--text"),n.setText(r.text),i.append(n);continue}"rule"!==r.kind?i.append(ho(r,o,t)):i.append(uo("rect",{class:"clepit-typeset__rule",height:r.thickness,width:r.width,x:r.x+8,y:o+r.y-r.thickness/2},t))}return i}function ho(e,t,n){const a=e.x+8,o=t+e.y-e.height,i=t+e.y,r=.32*e.size;return uo("path",{class:"clepit-typeset__radical",d:[`M ${a-1.6*r} ${i-.45*e.height}`,`L ${a-.9*r} ${i-.55*e.height}`,`L ${a-.2*r} ${i}`,`L ${a+.35*r} ${o}`,`L ${a+e.width} ${o}`].join(" "),fill:"none"},n)}var go=72,bo=40,fo=28,yo=16;function vo(e){return"flowchart"===e.kind?function(e){const t="LR"===e.direction||"RL"===e.direction,n=function(e){const t=new Map;for(const a of e.nodes)t.set(a.id,0);const n=function(e){const t=new Map;for(const o of e.edges)t.set(o.from,[...t.get(o.from)??[],o]);const n=new Map,a=new Set;for(const o of e.nodes){if(n.has(o.id))continue;n.set(o.id,"visiting");const e=[{id:o.id,index:0}];for(;e.length>0;){const o=e[e.length-1],i=t.get(o.id)??[];if(o.index>=i.length){n.set(o.id,"done"),e.pop();continue}const r=i[o.index];o.index+=1;const s=n.get(r.to);"visiting"===s?a.add(r):void 0===s&&(n.set(r.to,"visiting"),e.push({id:r.to,index:0}))}}return e.edges.filter(e=>!a.has(e))}(e);for(let a=0;a<e.nodes.length;a+=1){let e=!1;for(const a of n){if(a.from===a.to)continue;const n=(t.get(a.from)??0)+1;n>(t.get(a.to)??0)&&(t.set(a.to,n),e=!0)}if(!e)break}return t}(e),a=new Map;for(const b of e.nodes){const e=n.get(b.id)??0;a.set(e,[...a.get(e)??[],b.id])}const o=new Map;for(const b of e.nodes)o.set(b.id,xo(b.label,go));const i=new Map,r=[...a.keys()].sort((e,t)=>e-t),s=e=>t?e.length*bo+(e.length-1)*fo:e.reduce((e,t)=>e+(o.get(t)??go),0)+(e.length-1)*fo,l=Math.max(...r.map(e=>s(a.get(e)??[])),0);for(const b of r){const n=a.get(b)??[],r=yo+b*((t?go:bo)+64);let c=yo+(l-s(n))/2;for(const a of n){const n=e.nodes.find(e=>e.id===a);if(void 0===n)continue;const s=o.get(a)??go;i.set(a,{height:bo,id:a,label:n.label,shape:n.shape,width:s,x:t?r:c,y:t?c:r}),c+=(t?bo:s)+fo}}const c=e.nodes.map(e=>i.get(e.id)).filter(e=>void 0!==e),p=Math.max(...c.map(e=>e.x+e.width),0),d=Math.max(...c.map(e=>e.y+e.height),0),u=(t?d:p)+24,m=e.edges.map(e=>function(e,t,n,a){const o=t.get(e.from),i=t.get(e.to);if(void 0===o||void 0===i)return null;if(n?i.x<o.x:i.y<o.y){const t=n?{x:o.x+o.width/2,y:o.y+o.height}:{x:o.x+o.width,y:o.y+o.height/2},r=n?{x:i.x+i.width/2,y:i.y+i.height}:{x:i.x+i.width,y:i.y+i.height/2},s=n?{x:t.x,y:a}:{x:a,y:t.y},l=n?{x:r.x,y:a}:{x:a,y:r.y};return{arrow:e.arrow,label:e.label,labelX:(s.x+l.x)/2,labelY:(s.y+l.y)/2,line:e.line,points:[t,s,l,r]}}const r=n?{x:o.x+o.width,y:o.y+o.height/2}:{x:o.x+o.width/2,y:o.y+o.height},s=n?{x:i.x,y:i.y+i.height/2}:{x:i.x+i.width/2,y:i.y};return{arrow:e.arrow,label:e.label,labelX:(r.x+s.x)/2,labelY:(r.y+s.y)/2,line:e.line,points:[r,s]}}(e,i,t,u)).filter(e=>null!==e),h=m.some(e=>e.points.length>2),g=t?p:Math.max(p,h?u:0);return{edges:m,height:(t?Math.max(d,h?u:0):d)+yo,kind:"flowchart",nodes:c,width:g+yo}}(e):function(e){const t=[];let n=yo;for(const m of e.participants){const e=xo(m.label,96);t.push({actor:m.actor,centerX:n+e/2,headHeight:36,headWidth:e,id:m.id,label:m.label}),n+=e+fo}const a=e=>t.find(t=>t.id===e)?.centerX??null,o=[],i=[],r=[],s=new Map;let l=100;const c=(e,t)=>{const n=s.get(e),o=a(e);void 0!==n&&null!==o&&(r.push({height:Math.max(t-n,24),width:10,x:o-5,y:n}),s.delete(e))};for(const m of e.steps){if("activation"===m.kind){m.active?s.set(m.participant,l):c(m.participant,l);continue}if("note"===m.kind){const e=m.targets.map(a).filter(e=>null!==e);if(0===e.length)continue;const t=xo(m.text,96),n=Math.min(...e),o=Math.max(...e),r="left"===m.placement?n-t-fo:"right"===m.placement?o+fo:(n+o)/2-t/2;i.push({height:34,text:m.text,width:t,x:r,y:l}),l+=62;continue}const e=a(m.from),t=a(m.to);null!==e&&null!==t&&(m.activate&&s.set(m.to,l),o.push({end:m.end,fromX:e,line:m.line,selfCall:m.from===m.to,text:m.text,toX:t,y:l}),l+=48,m.deactivate&&c(m.to,l))}const p=l;for(const m of[...s.keys()])c(m,p);const d=Math.max(...i.map(e=>e.x+e.width),0),u=Math.max(n-fo+yo,d+yo);return{activations:r,height:p+yo,kind:"sequence",lifelineBottom:p,lifelines:t,messages:o,notes:i,width:u}}(e)}function xo(e,t){return Math.max(t,Math.round(7.2*e.length)+32)}var ko=["BT","LR","RL","TB","TD"],wo=["subgraph","end","click","style","classDef","class","linkStyle","direction"],Co=["loop","alt","else","opt","par","and","critical","option","break","rect","box","autonumber","end"],Eo=[{arrow:!0,line:"dotted",token:"-.->"},{arrow:!0,line:"thick",token:"==>"},{arrow:!0,line:"solid",token:"--\x3e"},{arrow:!1,line:"thick",token:"==="},{arrow:!1,line:"solid",token:"---"},{arrow:!1,line:"dotted",token:"-.-"}],So=[{end:"arrow",line:"dotted",token:"--\x3e>"},{end:"arrow",line:"solid",token:"->>"},{end:"cross",line:"dotted",token:"--x"},{end:"cross",line:"solid",token:"-x"},{end:"none",line:"dotted",token:"--\x3e"},{end:"none",line:"solid",token:"->"}],No=[{close:"]]",open:"[[",shape:"subroutine"},{close:"])",open:"([",shape:"stadium"},{close:"))",open:"((",shape:"circle"},{close:"]",open:"[",shape:"rect"},{close:"}",open:"{",shape:"rhombus"},{close:")",open:"(",shape:"round"}],Ao=e=>({ok:!1,reason:e});function Lo(e){return e.split(/[\s(]/,1)[0]??""}function Bo(e){const t=function(e){return e.split("\n").map(e=>function(e){const t=e.indexOf("%%");return-1===t?e:e.slice(0,t)}(e).trim()).filter(e=>e.length>0)}(e);if(0===t.length)return Ao("the block is empty");const[n,...a]=t,o=Lo(n??"");return"sequenceDiagram"===o?function(e){const t=new Map,n=[],a=e=>(t.has(e)||t.set(e,{actor:!1,id:e,label:e}),e);for(const o of e){const e=Lo(o);if(Co.includes(e))return Ao(`"${e}" is not supported yet`);if("participant"===e||"actor"===e){const n=Do(o,e);if(null===n)return Ao(`"${o}" is not a participant declaration this engine understands`);t.set(n.id,n);continue}if("activate"===e||"deactivate"===e){const t=o.slice(e.length).trim();if(!qo(t))return Ao(`"${o}" does not name a participant to ${e}`);n.push({active:"activate"===e,kind:"activation",participant:a(t)});continue}if("Note"===e||"note"===e){const e=_o(o);if(null===e)return Ao(`"${o}" is not a note this engine understands`);for(const t of e.targets)a(t);n.push(e);continue}const i=jo(o);if(null===i)return Ao(`"${o}" is not a message this engine understands`);a(i.from),a(i.to),n.push(i)}return{model:{kind:"sequence",participants:[...t.values()],steps:n},ok:!0}}(a):"flowchart"===o||"graph"===o?function(e,t){const n=e.slice(Lo(e).length).trim();if(0===n.length)return Ao('the flowchart header is missing a direction, e.g. "flowchart TD"');const a=ko.find(e=>e===n);if(void 0===a)return Ao(`"${n}" is not a supported direction — use TD, TB, BT, LR or RL`);const o=new Map,i=[];for(const r of t){const e=Lo(r);if(wo.includes(e))return Ao(`"${e}" is not supported yet`);if(r.includes("&"))return Ao('"&" fan-out is not supported yet');const t=$o(r,o,i);if(null!==t)return Ao(t)}return{model:{direction:a,edges:i,kind:"flowchart",nodes:[...o.values()]},ok:!0}}(n??"",a):Ao(`"${o}" diagrams are not supported yet — only flowchart and sequenceDiagram are`)}function $o(e,t,n){const a=function(e){const t=[],n=[];let a=e.trim();for(let o=0;o<64;o+=1){const e=Mo(a);if(null===e)return t.push(a.trim()),t.every(e=>e.length>0)?{links:n,terms:t}:null;t.push(a.slice(0,e.at).trim()),n.push({arrow:e.arrow,label:e.label,line:e.line}),a=a.slice(e.at+e.length)}return null}(e);if(null===a)return`"${e}" is not a node or edge this engine understands`;const o=[];for(const i of a.terms){const e=To(i);if(null===e)return`"${i}" is not a node declaration this engine understands`;t.has(e.id)||t.set(e.id,e),o.push(e)}for(const[i,r]of a.links.entries()){const t=o[i],a=o[i+1];if(void 0===t||void 0===a)return`"${e}" has a link with nothing on one side of it`;n.push({arrow:r.arrow,from:t.id,label:r.label,line:r.line,to:a.id})}return null}function Mo(e){const t=function(e){const t=/--\s+([^->|][^-]*?)\s+(-->|---|-\.->|-\.-|==>|===)/.exec(e);if(null===t||void 0===t.index)return null;const n=Eo.find(e=>e.token===t[2]);return void 0===n?null:{arrow:n.arrow,at:t.index,label:(t[1]??"").trim(),length:t[0].length,line:n.line}}(e);if(null!==t)return t;let n=null;for(const a of Eo){const t=e.indexOf(a.token);if(-1===t)continue;if(null!==n&&t>=n.at)continue;const o=Io(e,t+a.token.length);n={arrow:a.arrow,at:t,label:o.label,length:a.token.length+o.consumed,line:a.line}}return n}function Io(e,t){if("|"!==e[t])return{consumed:0,label:null};const n=e.indexOf("|",t+1);return-1===n?{consumed:0,label:null}:{consumed:n-t+1,label:e.slice(t+1,n).trim()}}function To(e){const t=e.trim();if(0===t.length)return null;for(const n of No){const e=t.indexOf(n.open);if(e<=0||!t.endsWith(n.close))continue;const a=t.slice(0,e).trim(),o=t.slice(e+n.open.length,t.length-n.close.length);if(qo(a))return{id:a,label:o.trim(),shape:n.shape}}return qo(t)?{id:t,label:t,shape:"rect"}:null}function qo(e){return/^[A-Za-z_][\w-]*$/.test(e)}function Do(e,t){const n=e.slice(t.length).trim(),a=/ as /.exec(n),o=(null===a?n:n.slice(0,a.index)).trim();if(!qo(o))return null;const i=null===a?o:n.slice(a.index+a[0].length).trim();return{actor:"actor"===t,id:o,label:0===i.length?o:i}}function _o(e){const t=e.slice(Lo(e).length).trim(),n=t.indexOf(":");if(-1===n)return null;const a=t.slice(0,n).trim(),o=t.slice(n+1).trim(),i=/^over\s+(.+)$/i.exec(a);if(null!==i){const e=(i[1]??"").split(",").map(e=>e.trim());return e.every(qo)?{kind:"note",placement:"over",targets:e,text:o}:null}const r=/^(left|right)\s+of\s+(.+)$/i.exec(a);if(null===r)return null;const s=(r[2]??"").trim();return qo(s)?{kind:"note",placement:(r[1]??"").toLowerCase(),targets:[s],text:o}:null}function jo(e){const t=e.indexOf(":");if(-1===t)return null;const n=e.slice(0,t),a=e.slice(t+1).trim();for(const o of So){const e=n.indexOf(o.token);if(-1===e)continue;const t=n.slice(0,e).trim(),i=n.slice(e+o.token.length).trim(),r=i.startsWith("+")||i.startsWith("-")?i[0]:null,s=null===r?i:i.slice(1).trim();if(qo(t)&&qo(s))return{activate:"+"===r,deactivate:"-"===r,end:o.end,from:t,kind:"message",line:o.line,text:a,to:s}}return null}var zo={dotted:"5 4",solid:"",thick:""},Oo={dotted:1.5,solid:1.5,thick:3};function Ho(e,t,n){const a=n.createNS("http://www.w3.org/2000/svg",e);for(const[o,i]of Object.entries(t))a.setAttribute(o,String(i));return a}function Po(e,t,n,a,o){const i=Ho("text",{class:a,"dominant-baseline":"middle","text-anchor":"middle",x:t,y:n},o);return i.setText(e),i}function Fo(e,t=ue){const n=Ho("svg",{class:"clepit-typeset__diagram",height:e.height,role:"img",viewBox:`0 0 ${e.width} ${e.height}`,width:e.width},t);return n.append(function(e){const t=Ho("defs",{},e),n=Ho("marker",{id:"clepit-mermaid-arrow",markerHeight:7,markerUnits:"strokeWidth",markerWidth:7,orient:"auto-start-reverse",refX:7,refY:3.5},e);return n.append(Ho("path",{class:"clepit-typeset__arrowhead",d:"M 0 0 L 7 3.5 L 0 7 z"},e)),t.append(n),t}(t)),"flowchart"===e.kind?function(e,t,n){for(const a of t.edges)Vo(e,a,n);for(const a of t.nodes)Ro(e,a,n)}(n,e,t):function(e,t,n){for(const a of t.lifelines){e.append(Ho("line",{class:"clepit-typeset__lifeline",x1:a.centerX,x2:a.centerX,y1:a.headHeight+16,y2:t.lifelineBottom},n));const o={class:a.actor?"clepit-typeset__node clepit-typeset__actor":"clepit-typeset__node",height:a.headHeight,rx:a.actor?a.headHeight/2:4,ry:a.actor?a.headHeight/2:4,width:a.headWidth,x:a.centerX-a.headWidth/2,y:16};e.append(Ho("rect",o,n)),e.append(Po(a.label,a.centerX,16+a.headHeight/2,"clepit-typeset__label",n))}for(const a of t.activations)e.append(Ho("rect",{class:"clepit-typeset__activation",height:a.height,width:a.width,x:a.x,y:a.y},n));for(const a of t.messages)Uo(e,a,n);for(const a of t.notes)e.append(Ho("rect",{class:"clepit-typeset__note",height:a.height,width:a.width,x:a.x,y:a.y},n)),e.append(Po(a.text,a.x+a.width/2,a.y+a.height/2,"clepit-typeset__label",n))}(n,e,t),n}function Ro(e,t,n){e.append(function(e,t){const{height:n,shape:a,width:o,x:i,y:r}=e,s={class:"clepit-typeset__node"};if("circle"===a)return Ho("ellipse",{...s,cx:i+o/2,cy:r+n/2,rx:o/2,ry:n/2},t);if("rhombus"===a){const e=`${i+o/2},${r} ${i+o},${r+n/2} ${i+o/2},${r+n} ${i},${r+n/2}`;return Ho("polygon",{...s,points:e},t)}if("stadium"===a)return Ho("rect",{...s,height:n,rx:n/2,ry:n/2,width:o,x:i,y:r},t);if("round"===a)return Ho("rect",{...s,height:n,rx:10,ry:10,width:o,x:i,y:r},t);if("subroutine"===a){const e=Ho("g",{},t);return e.append(Ho("rect",{...s,height:n,rx:8,ry:8,width:o,x:i,y:r},t)),e.append(Ho("line",{...s,x1:i+6,x2:i+6,y1:r,y2:r+n},t)),e.append(Ho("line",{...s,x1:i+o-6,x2:i+o-6,y1:r,y2:r+n},t)),e}return Ho("rect",{...s,height:n,rx:8,ry:8,width:o,x:i,y:r},t)}(t,n)),e.append(Po(t.label,t.x+t.width/2,t.y+t.height/2,"clepit-typeset__label",n))}function Vo(e,t,n){const[a,o]=t.points;if(void 0===a||void 0===o)return;const i=t.points.length>2?Ho("polyline",{class:"clepit-typeset__edge",fill:"none",points:t.points.map(e=>`${e.x},${e.y}`).join(" "),"stroke-dasharray":zo[t.line],"stroke-width":Oo[t.line]},n):Ho("line",{class:"clepit-typeset__edge","stroke-dasharray":zo[t.line],"stroke-width":Oo[t.line],x1:a.x,x2:o.x,y1:a.y,y2:o.y},n);if(t.arrow&&i.setAttribute("marker-end","url(#clepit-mermaid-arrow)"),e.append(i),null!==t.label){const a=Po(t.label,t.labelX,t.labelY,"clepit-typeset__edge-label",n);a.setAttribute("paint-order","stroke"),e.append(a)}}function Uo(e,t,n){const a={class:"clepit-typeset__message","stroke-dasharray":zo[t.line],"stroke-width":Oo[t.line]};if(t.selfCall){const o=`M ${t.fromX} ${t.y} h 28 v 18 h -28`,i=Ho("path",{...a,d:o,fill:"none"},n);return"arrow"===t.end&&i.setAttribute("marker-end","url(#clepit-mermaid-arrow)"),e.append(i),void e.append(Po(t.text,t.fromX+52,t.y+9,"clepit-typeset__edge-label",n))}const o=Ho("line",{...a,x1:t.fromX,x2:t.toX,y1:t.y,y2:t.y},n);if("arrow"===t.end&&o.setAttribute("marker-end","url(#clepit-mermaid-arrow)"),e.append(o),"cross"===t.end){const o=t.toX+(t.toX>t.fromX?-5:5);e.append(Ho("line",{...a,x1:o-5,x2:o+5,y1:t.y-5,y2:t.y+5},n)),e.append(Ho("line",{...a,x1:o-5,x2:o+5,y1:t.y+5,y2:t.y-5},n))}e.append(Po(t.text,(t.fromX+t.toX)/2,t.y-8,"clepit-typeset__edge-label",n))}var Wo=class e{static render(t,n,o,i,r){if(a.injectStyles("typeset-output",Ma),!e.validate(n))return xe();const s=a.createStyledElement("div",`clepit-typeset clepit-output-typeset clepit-typeset--${t.toLowerCase()}`,{classNames:r?.wrapper,styles:i?.wrapper});if(s.setAttribute("data-language",t.toLowerCase()),n.title){const e=document.createElement("span");e.className="clepit-typeset__title",e.textContent=n.title,e.setAttribute("data-testid","typeset-title"),s.appendChild(e)}if("Mermaid"===t){const a=Bo(n.source);return a.ok?(s.setAttribute("data-rendered","diagram"),s.appendChild(ve(Fo(vo(a.model)))),s):e.appendFallback(s,n.source,a.reason,t)}if(0===n.source.trim().length)return e.appendFallback(s,n.source,null,t);const l=eo(n.source);return l.ok?(s.setAttribute("data-rendered","formula"),s.appendChild(ve(mo(Da(l.root)))),s):e.appendFallback(s,n.source,l.reason,t)}static appendFallback(e,t,n,a){e.setAttribute("data-rendered","source");const o=document.createElement("span");if(o.className="clepit-typeset__kind",o.textContent=a,e.prepend(o),null!==n){const t=document.createElement("span");t.className="clepit-typeset__fallback-reason",t.textContent=n,e.appendChild(t)}const i=document.createElement("pre");return i.className="clepit-typeset__source",i.textContent=t,e.appendChild(i),e}static draw(t,n,a=ue){if(!e.validate(n))return null;const o=a.create("div");o.addClass("clepit-typeset","clepit-output-typeset",`clepit-typeset--${t.toLowerCase()}`),o.setAttribute("data-language",t.toLowerCase());const i=()=>{if(!n.title)return;const e=a.create("span");e.addClass("clepit-typeset__title"),e.setText(n.title),e.setAttribute("data-testid","typeset-title"),o.append(e)};if("Mermaid"===t){const r=Bo(n.source);return r.ok?(o.setAttribute("data-rendered","diagram"),i(),o.append(Fo(vo(r.model),a)),o):e.drawFallback(o,n,r.reason,t,a,i)}if(0===n.source.trim().length)return e.drawFallback(o,n,null,t,a,i);const r=eo(n.source);return r.ok?(o.setAttribute("data-rendered","formula"),i(),o.append(mo(Da(r.root),a)),o):e.drawFallback(o,n,r.reason,t,a,i)}static drawFallback(e,t,n,a,o,i){e.setAttribute("data-rendered","source");const r=o.create("span");if(r.addClass("clepit-typeset__kind"),r.setText(a),e.append(r),i(),null!==n){const t=o.create("span");t.addClass("clepit-typeset__fallback-reason"),t.setText(n),e.append(t)}const s=o.create("pre");return s.addClass("clepit-typeset__source"),s.setText(t.source),e.append(s),e}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.source&&(void 0===e.title||"string"==typeof e.title)}},Ko=class{static render(e,t,n,a){return Wo.render("LaTeX",e,t,n,a)}static draw(e,t=ue){return Wo.draw("LaTeX",e,t)}},Go=class{static render(e,t,n,a){return Wo.render("Mermaid",e,t,n,a)}static draw(e,t=ue){return Wo.draw("Mermaid",e,t)}},Jo="\n.clepit-updates {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 12px;\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n color: inherit;\n}\n.clepit-updates__icon {\n font-size: 18px;\n line-height: 1;\n}\n.clepit-updates__label {\n opacity: 0.7;\n}\n",Xo=Jo,Zo=Jo,Yo=class{static render(e,t,n,o){a.injectStyles("updates-output",Zo);const i=a.createStyledElement("div","clepit-updates clepit-output-updates",{classNames:o?.wrapper,styles:n?.wrapper});e?.pageId&&i.setAttribute("data-page-id",e.pageId);const r=document.createElement("span");r.className="clepit-updates__icon",r.textContent="🕘",i.appendChild(r);const s=document.createElement("span");return s.className="clepit-updates__label",s.textContent="Updates",i.appendChild(s),i}static draw(e,t=ue){if(null==e||"object"!=typeof e)return null;const n=t.create("div");n.addClass("clepit-updates","clepit-output-updates"),e.pageId&&n.setAttribute("data-page-id",e.pageId);const a=t.create("span");a.addClass("clepit-updates__icon"),a.setText("🕘"),n.append(a);const o=t.create("span");return o.addClass("clepit-updates__label"),o.setText("Updates"),n.append(o),n}},Qo=`\n/* Video block styles */\n.clepit-video-container {\n margin: 16px 0;\n text-align: center;\n min-height: 120px;\n position: relative;\n display: block;\n width: 100%;\n box-sizing: border-box;\n}\n\n.clepit-video-wrapper {\n display: flex;\n position: relative;\n cursor: pointer;\n transition: opacity 0.2s ease;\n outline: none;\n}\n\n.clepit-video-wrapper:hover {\n opacity: 0.9;\n}\n\n.clepit-video {\n max-width: 100%;\n height: auto;\n border-radius: 8px;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);\n display: block;\n}\n\n.clepit-video-wrapper--left {\n justify-content: flex-start;\n}\n\n.clepit-video-wrapper--center {\n justify-content: center;\n}\n\n.clepit-video-wrapper--right {\n justify-content: flex-end;\n}\n\n.clepit-video-caption-container {\n margin-top: 12px;\n text-align: center;\n}\n\n.clepit-video-caption-label {\n font-size: 12px;\n color: var(--clepit-text-muted);\n margin-bottom: 4px;\n font-weight: 500;\n}\n\n.clepit-video-caption-input {\n width: 100%;\n max-width: 400px;\n padding: 8px 12px;\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n font-size: 14px;\n background: var(--clepit-bg);\n outline: none;\n transition: border-color 0.2s ease;\n pointer-events: auto;\n user-select: text;\n}\n\n.clepit-video-caption-input:focus {\n border-color: var(--clepit-primary);\n box-shadow: 0 0 0 2px var(--clepit-primary-bg);\n}\n\n/* Video caption styling */\n.clepit-video-caption-editable {\n border: 1px solid var(--clepit-border-subtle);\n border-radius: 4px;\n padding: 8px 12px;\n min-height: 40px;\n font-size: 14px;\n line-height: 1.4;\n outline: none;\n transition: border-color 0.2s ease;\n}\n\n/* Video caption placeholder styles */\n.clepit-video-caption-editable[data-placeholder]:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Video Drop Area */\n.clepit-video-drop-area {\n border: 2px dashed var(--clepit-border);\n border-radius: 8px;\n padding: 40px 20px;\n text-align: center;\n background: var(--clepit-surface);\n cursor: pointer;\n transition: all 0.2s ease;\n margin: 16px 0;\n user-select: none;\n pointer-events: auto;\n outline: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n position: relative;\n}\n\n.clepit-video-drop-area:hover {\n border-color: var(--clepit-primary);\n background: var(--clepit-surface);\n}\n\n.clepit-video-drop-area--dragover {\n border-color: var(--clepit-primary);\n background: var(--clepit-primary-bg);\n transform: scale(1.02);\n}\n\n.clepit-video-drop-icon {\n font-size: 48px;\n margin-bottom: 16px;\n opacity: 0.6;\n}\n\n.clepit-video-drop-text {\n font-size: 16px;\n color: var(--clepit-text-muted);\n line-height: 1.5;\n}\n\n.clepit-video-click-text {\n color: var(--clepit-primary);\n text-decoration: none;\n cursor: pointer;\n}\n\n/* Video Loading State */\n.clepit-video-loading {\n text-align: center;\n padding: 40px 20px;\n margin: 16px 0;\n}\n\n.clepit-video-loading-spinner {\n width: 32px;\n height: 32px;\n border: 3px solid var(--clepit-surface);\n border-top: 3px solid var(--clepit-primary);\n border-radius: 50%;\n animation: spin 1s linear infinite;\n margin: 0 auto 16px;\n}\n\n@keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n}\n\n.clepit-video-loading-text {\n font-size: 14px;\n color: var(--clepit-text-muted);\n}\n\n/* Video Error State */\n.clepit-video-error {\n text-align: center;\n padding: 20px;\n margin: 16px 0;\n border: 1px solid var(--clepit-error);\n border-radius: 8px;\n background: var(--clepit-error-bg);\n}\n\n.clepit-video-error-icon {\n font-size: 24px;\n margin-bottom: 8px;\n}\n\n.clepit-video-error-text {\n font-size: 14px;\n color: var(--clepit-error);\n margin-bottom: 12px;\n}\n\n.clepit-video-error-retry {\n background: var(--clepit-error);\n color: white;\n border: none;\n padding: 8px 16px;\n border-radius: 4px;\n cursor: pointer;\n font-size: 14px;\n transition: background-color 0.2s ease;\n}\n\n.clepit-video-error-retry:hover {\n background: var(--clepit-error);\n}\n\n/* Video caption placeholder */\n.clepit-video-caption-placeholder {\n color: var(--clepit-text-subtle);\n}\n\n/* Video delete button */\n.${a.classNames.block.videoDeleteBtn} {\n position: absolute;\n top: 8px;\n right: 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 50%;\n width: 24px;\n height: 24px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: var(--clepit-bg);\n cursor: pointer;\n color: var(--clepit-text-muted);\n transition: color 0.2s ease;\n}\n\n.${a.classNames.block.videoDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Video drop area delete button */\n.clepit-video-drop-area .${a.classNames.block.videoDeleteBtn} {\n position: absolute;\n top: 8px;\n right: 8px;\n border: 1px solid var(--clepit-border);\n border-radius: 50%;\n width: 24px;\n height: 24px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: var(--clepit-bg);\n cursor: pointer;\n color: var(--clepit-text-muted);\n transition: color 0.2s ease;\n}\n\n.clepit-video-drop-area .${a.classNames.block.videoDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Drop area positioning */\n.clepit-drop-area {\n position: relative;\n}\n\n/* Hidden input */\n.clepit-hidden-input {\n display: none;\n}\n\n`,ei="\n/* Output video styles */\n.clepit-output-video-container {\n margin: 1rem 0;\n text-align: center;\n}\n\n.clepit-output-video {\n max-width: 100%;\n height: auto;\n border-radius: 8px;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);\n}\n\n.clepit-output-video-caption {\n margin-top: 0.5rem;\n font-size: 0.875rem;\n color: var(--clepit-text-muted);\n font-style: italic;\n text-align: center;\n}\n\n/* Output video alignment */\n.clepit-output-video-wr--left {\n justify-content: flex-start;\n}\n\n.clepit-output-video-wr--center {\n justify-content: center;\n}\n\n.clepit-output-video-wr--right {\n justify-content: flex-end;\n}\n",ti=class e{static{this.placeholder="Add a caption..."}static{this.eventListenersMap={}}static{this.validTypes=["video/mp4","video/webm","video/ogg","video/ogv"]}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.querySelector("video"),n=e.querySelector("iframe"),o=e.querySelector(`.${a.classNames.block.video.captionEditable}`),i=e.querySelector(`.${a.classNames.block.video.wrapper}`);let r="center";i&&(r=i.classList.contains("clepit-video-wrapper--left")?"left":i.classList.contains("clepit-video-wrapper--right")?"right":"center");let s="",l="";return t?(s=t.getAttribute("src")||"",l=t.getAttribute("alt")||""):n&&(s=n.getAttribute("src")||"",l="Embedded video"),{alignment:r,alt:l,caption:I(o?.innerHTML),url:s}}static render(t,n,o,i){a.injectStyles("clepit-video-input-styles",Qo);const r=o||{alt:"",caption:"",url:""},s=a.createStyledElement("div",a.classNames.block.video.container,{classNames:i?.classNames?.container,styles:i?.styles?.container});return r.url?e.renderVideo(s,r,t,n,i):e.renderDropArea(s,t,n,i),s}static renderVideo(t,n,o,i,r){t.innerHTML="";const s=a.createStyledElement("div",a.classNames.block.video.wrapper,{classNames:r?.classNames?.container,styles:r?.styles?.container});switch(s.setAttribute("tabindex","-1"),n?.alignment||"center"){case"left":s.classList.add("clepit-video-wrapper--left");break;case"center":s.classList.add("clepit-video-wrapper--center");break;case"right":s.classList.add("clepit-video-wrapper--right")}const l=ie(n?.url||""),c=re(n?.url||"");if(l||c){const e=a.createStyledElement("iframe",a.classNames.block.video.iframe,{classNames:r?.classNames?.container,styles:r?.styles?.container});e.src=n?.url||"",e.setAttribute("frameborder","0"),e.setAttribute("allowfullscreen","true"),e.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"),e.style.maxWidth="100%",e.style.width="560px",e.style.height="315px",e.style.display="block",e.style.borderRadius="8px",s.appendChild(e)}else{const e=a.createStyledElement("video",a.classNames.block.video.video,{classNames:r?.classNames?.container,styles:r?.styles?.container});e.setAttribute("alt",n?.alt||""),e.src=n?.url||"",e.controls=!0,s.appendChild(e)}const p=a.createStyledElement("div","clepit-video-caption-container",{classNames:r?.classNames?.caption,styles:r?.styles?.caption});p.classList.add("clepit-video-caption-container");const d=a.createStyledElement("div",a.classNames.block.video.captionEditable,{classNames:r?.classNames?.caption,styles:r?.styles?.caption});d.setAttribute("contenteditable","true"),d.setAttribute("data-placeholder",e.placeholder),d.innerHTML=n?.caption||"",e.addEventListener(i,d,"input",sr.handleInput),e.addEventListener(i,d,"keydown",sr.handleKeydown),e.addEventListener(i,s,"click",()=>e.handleFileSelect(t,o,i,r)),p.appendChild(d),t.appendChild(s),t.appendChild(p),d.focus()}static renderDropArea(t,n,o,i){t.innerHTML="";const r=a.createStyledElement("div",a.classNames.block.video.dropArea,{classNames:i?.classNames?.dropArea?.container,styles:i?.styles?.dropArea?.container});r.setAttribute("tabindex","0"),r.classList.add("clepit-drop-area");const s=a.createStyledElement("div","clepit-video-drop-icon",{classNames:i?.classNames?.dropArea?.icon,styles:i?.styles?.dropArea?.icon});s.textContent="🎥";const c=a.createStyledElement("div","clepit-video-drop-text",{classNames:i?.classNames?.dropArea?.text,styles:i?.styles?.dropArea?.text});c.innerHTML='<strong>Drop a video here</strong><br>or <span class="clepit-video-click-text">click to select</span>';const p=a.createStyledElement("button",`${a.classNames.block.videoDeleteBtn}`,{classNames:i?.classNames?.dropArea?.deleteButton,styles:i?.styles?.dropArea?.deleteButton});p.type="button",p.textContent="✕",r.appendChild(s),r.appendChild(c),r.appendChild(p),e.addEventListener(o,p,"click",e=>{e.preventDefault(),e.stopPropagation();const t=p.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id");t&&sr.removeBlock(o,sr.getBlockIndex(o,t))}),e.addEventListener(o,r,"click",()=>e.handleFileSelect(t,n,o,i)),e.addEventListener(o,r,"dragleave",()=>{r.classList.remove("clepit-video-drop-area--dragover")}),e.addEventListener(o,r,"dragover",e=>{e.preventDefault(),e.stopPropagation(),r.classList.add("clepit-video-drop-area--dragover")}),e.addEventListener(o,r,"drop",a=>{a.preventDefault(),a.stopPropagation(),r.classList.remove("clepit-video-drop-area--dragover"),e.handleFileDrop(a,t,n,o,i)}),e.addEventListener(o,r,"focus",e=>{e.preventDefault(),e.stopPropagation()}),e.addEventListener(o,r,"mousedown",e=>{e.preventDefault(),e.stopPropagation()});const d=o?l.getState().getInstance(o):null,u=d?.config.classNames?.tooltips,m=d?.config.styles?.tooltips;J(p,"Delete block","below",u,m),t.appendChild(r)}static handleFileDrop(t,n,a,o,i){const r=t.dataTransfer?.files;if(r&&r.length>0){const t=r[0];e.isValidVideoFile(t)?e.processVideoFile(t,n,a,o,i):e.showError(n,"Please select a valid video file (MP4, WebM, OGV)")}}static handleFileSelect(t,n,a,o){const i=document.createElement("input");i.type="file",i.accept="video/*",i.style.display="none",i.addEventListener("change",()=>{const r=i.files;if(r&&r.length>0){const i=r[0];e.isValidVideoFile(i)?e.processVideoFile(i,t,n,a,o):e.showError(t,"Please select a valid video file (MP4, WebM, OGV)")}}),document.body.appendChild(i),i.click(),document.body.removeChild(i)}static isValidVideoFile(t){return e.validTypes.includes(t.type)||t.type.startsWith("video/")}static async processVideoFile(t,n,o,i,r){e.showLoading(n);try{let s=await o(t);if(s){e.renderVideo(n,{alignment:"center",alt:t.name,caption:"",url:s},o,i,r);const c=n.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id");c&&l.getState().updateBlockData(i,sr.getBlockIndex(i,c),sr.getBlockData(c).data)}else e.showError(n,"Failed to upload video. Please try again.")}catch(s){console.error("Video upload error:",s),e.showError(n,"Failed to upload video. Please try again.")}}static showLoading(e){e.innerHTML="";const t=a.createStyledElement("div","clepit-video-loading",void 0);t.textContent="Uploading video...",e.appendChild(t)}static showError(e,t){e.innerHTML="";const n=a.createStyledElement("div","clepit-video-error",void 0);n.textContent=t,e.appendChild(n)}static setAlignment(e,t){const n=e.querySelector(".clepit-video-wrapper");n&&(n.classList.remove("clepit-video-wrapper--left","clepit-video-wrapper--center","clepit-video-wrapper--right"),n.classList.add(`clepit-video-wrapper--${t}`));const a=sr.getEditorId(e);if(!a)return;const o=e.getAttribute("data-id");o&&l.getState().partialUpdateBlockData(a,sr.getBlockIndex(a,o),{alignment:t})}static isEmpty(e){const t=e.querySelector(`.${a.classNames.block.video.wrapper} video`),n=e.querySelector(`.${a.classNames.block.video.wrapper} iframe`),o=e.querySelector(`.${a.classNames.block.video.captionEditable}`);let i=!1,r=!1,s=!1;return t&&t.getAttribute("src")?.trim()||(i=!0),n&&n.getAttribute("src")?.trim()||(r=!0),o?M(o.innerHTML)&&(s=!0):s=!0,i&&r&&s}static isEmptyData(e){return!e.url?.trim()&&M(e.caption)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},ni=class e{static render(t,n,o,i){if(a.injectStyles("clepit-video-output-styles",ei),!e.validate(t))return xe();if(ti.isEmptyData(t))return document.createElement("div");const r=t.url,s=t.caption,l=t.alignment||"center",c=a.createStyledElement("div","clepit-output-video-container",{classNames:i?.container,styles:o?.container}),p=a.createStyledElement("div","clepit-output-video-wrapper");switch(l){case"left":p.classList.add("clepit-output-video-wrapper--left");break;case"center":p.classList.add("clepit-output-video-wrapper--center");break;case"right":p.classList.add("clepit-output-video-wrapper--right")}const d=ie(r),u=re(r);if(d||u){const e=B("iframe","clepit-output-video-iframe");e.src=r,e.setAttribute("frameborder","0"),e.setAttribute("allowfullscreen","true"),e.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"),e.style.maxWidth="100%",e.style.width="560px",e.style.height="315px",e.style.display="block",e.style.borderRadius="8px",p.appendChild(e),c.appendChild(p)}else{const e=B("video","clepit-output-video");e.src=r,e.controls=!0,e.preload="metadata",e.style.maxWidth="100%",e.style.height="auto",e.style.display="block",p.appendChild(e),c.appendChild(p)}if(s){const e=a.createStyledElement("figcaption","clepit-output-video-caption",{classNames:i?.caption,styles:o?.caption}),n=t.caption;e.innerHTML=n&&n!==s?n:s,c.appendChild(e)}if(o&&(o.container&&Object.assign(c.style,o.container),o.caption)){const e=c.querySelector(".clepit-output-video-caption");e&&Object.assign(e.style,o.caption)}if(i&&(i.container&&c.classList.add(i.container),i.caption)){const e=c.querySelector(".clepit-output-video-caption");e&&e.classList.add(i.caption)}return c}static draw(t,n=ue){if(!e.validate(t)||ti.isEmptyData(t))return null;const a=n.create("div");a.addClass("clepit-output-video-container");const o=n.create("div");o.addClass("clepit-output-video-wrapper");const i=t.alignment??"center";i&&o.addClass(`clepit-output-video-wrapper--${i}`);const r=n.create("video");if(r.addClass("clepit-output-video"),r.setAttribute("src",t.url),r.setAttribute("controls","controls"),o.append(r),a.append(o),t.caption){const e=n.create("figcaption");e.addClass("clepit-output-video-caption"),e.setHtml(t.caption),a.append(e)}return a}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.url}},ai=(e,t,n)=>{const a=oi(e,t,n);return a&&(a.setAttribute("data-block-type",e.type),e.id&&(a.setAttribute("data-clepit-block-id",e.id),n?.anchorTargets&&a.setAttribute("id",e.id))),a},oi=(e,t,n)=>{switch(e.type){case"alert":return ke.draw(e.data,t);case"audio":return Ne.draw(e.data,t);case"checklist":return Me.draw(e.data,t);case"code":return Et.draw(e.data,t,n);case"collapsible":return ri.draw(e.data,t,n);case"collection":return qt.draw(e.data,t);case"columns":return zt.draw(e.data,t,n);case"date":return Vt.draw(e.data,t);case"delimiter":return Kt.draw(e.data,t);case"doc_card":return Zt.draw(e.data,t,n);case"embed":return cn.draw(e.data,t,n);case"file":return hn.draw(e.data,t);case"glance":return fn.draw(e.data,t);case"header":return xn.draw(e.data,t);case"image":return En.draw(e.data,t);case"latex":return Ko.draw(e.data,t);case"list":return An.draw(e.data,t);case"mermaid":return Go.draw(e.data,t);case"openapi":return aa.draw(e.data,t);case"paragraph":return ra.draw(e.data,t);case"quote":return pa.draw(e.data,t);case"sketch":return fa.draw(e.data,t);case"table":return Ca.draw(e.data,t);case"toc":return La.draw(e.data,t,n);case"updates":return Yo.draw(e.data,t);case"video":return ni.draw(e.data,t);default:return ii(e)}},ii=e=>(console.warn("drawBlock: no drawer for block",e),null),ri=class e{static render(t,n,o,i){if(a.injectStyles("collapsible-output",Lt),!e.validate(t))return xe();const r=a.createStyledElement("details","clepit-collapsible clepit-output-collapsible",{classNames:i?.section,styles:o?.section});r.open=t.open??!1;const s=document.createElement("summary"),l=document.createElement("span");l.innerHTML=I(t.html),s.appendChild(l),r.appendChild(s);const c=document.createElement("div");c.className="clepit-collapsible__children";for(const a of t.children??[])c.appendChild(e.renderChild(a,n));return r.appendChild(c),r}static renderChild(e,t){const n=Qi.find(t=>t.type===e.type);if(!n){const t=document.createElement("div");return t.className="clepit-collapsible__unknown-child",t.textContent=`Unsupported block: ${e.type}`,t}return n.output.render(e.data,t)}static draw(t,n=ue,a){if(!e.validate(t))return null;const o=n.create("details");o.addClass("clepit-collapsible","clepit-output-collapsible"),t.open&&o.setAttribute("open","");const i=n.create("summary"),r=n.create("span");r.setHtml(t.html),i.append(r),o.append(i);const s=n.create("div");s.addClass("clepit-collapsible__children");for(const e of t.children??[]){const t=ai(e,n,a);t&&s.append(t)}return o.append(s),o}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"html"in e&&"string"==typeof e.html&&(void 0===e.children||Array.isArray(e.children))}},si={icon:"▸",get input(){return $t},label:"Collapsible section",get output(){return ri},shortcut:v("E"),testId:"block-type-collapsible",type:"collapsible"},li=new WeakMap,ci=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){const t=e.classList.contains("clepit-collection")?e:e.querySelector(".clepit-collection");if(t){const e=li.get(t);if(e)return e;const n=t.getAttribute("data-collection-id");if(n)return{collectionId:n}}return{collectionId:""}}static render(e,t,n){a.injectStyles("collection-input",It);const o=t??{collectionId:""},i=qt.render(o,void 0,n?.styles,n?.classNames);return i.classList.add("clepit-collection--input"),i.setAttribute("contenteditable","false"),li.set(i,o),i}static isEmpty(t){return""===e.save(t).collectionId}static isEmptyData(e){return!e.collectionId}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},pi={icon:"▦",get input(){return ci},label:"Collection",get output(){return qt},shortcut:v("G"),testId:"block-type-collection",type:"collection"},di=new WeakMap;var ui=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){const t=e.classList.contains("clepit-columns")?e:e.querySelector(".clepit-columns");if(!t)return{columns:[[],[]]};const n=di.get(t)??[],a=[];return t.querySelectorAll(":scope > .clepit-columns__column").forEach((e,t)=>{const o=n[t]??[],i=[];e.querySelectorAll(":scope > .clepit-columns__child").forEach((e,t)=>{const n=o[t],a=e.getAttribute("data-child-type")??n?.type,r=a?function(e){return Qi.find(t=>t.type===e)}(a):void 0;if(r){const t=r.input.save(e);i.push({...n?.id?{id:n.id}:{},data:t,type:r.type})}else n&&i.push(n)}),a.push(i)}),{columns:a.length>=2?a:[[],[]]}}static render(t,n,o){a.injectStyles("columns-input",_t);const i=n&&Array.isArray(n.columns)&&n.columns.length>=2?n:{columns:[[],[]]},r=a.createStyledElement("div","clepit-columns clepit-columns--input",{classNames:o?.classNames?.container,styles:o?.styles?.container});return di.set(r,i.columns.map(e=>[...e])),i.columns.forEach(n=>{const i=a.createStyledElement("div","clepit-columns__column",{classNames:o?.classNames?.column,styles:o?.styles?.column});n.forEach(n=>{i.appendChild(e.renderChild(t,n))}),r.appendChild(i)}),r}static renderChild(e,t){const n=document.createElement("div");n.className="clepit-columns__child";const a=sr.renderTool(t.type,t.data,e);if(a)n.setAttribute("data-child-type",t.type),n.appendChild(a);else{const e=document.createElement("div");e.className="clepit-columns__unknown-child",e.textContent=`Unsupported block: ${t.type}`,n.appendChild(e)}return n}static isEmpty(e){const t=e.querySelector(".clepit-columns");return!t||0===t.querySelectorAll(".clepit-columns__child").length}static isEmptyData(e){return(e.columns??[]).every(e=>0===e.length)}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},mi={icon:"▥",get input(){return ui},label:"Columns",get output(){return zt},shortcut:v("L"),testId:"block-type-columns",type:"columns"},hi=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){return{date:(e.matches('input[type="date"]')?e:e.querySelector('input[type="date"]'))?.value??""}}static render(t,n,o){a.injectStyles("date-input",Ht);const i=a.createStyledElement("input","clepit-date clepit-date--input",{classNames:o?.classNames?.pill,styles:o?.styles?.pill});return i.type="date",n?.date&&Rt(n.date)&&(i.value=n.date),e.addEventListener(t,i,"keydown",e=>{e.stopPropagation()}),i}static isEmpty(t){return""===e.save(t).date}static isEmptyData(e){return!e.date}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},gi={icon:"▤",get input(){return hi},label:"Date",get output(){return Vt},shortcut:v("D"),testId:"block-type-date",type:"date"},bi={icon:"—",get input(){return Wt},label:"Delimiter",get output(){return Kt},shortcut:v("D"),testId:"block-type-delimiter",type:"delimiter"},fi=new WeakMap,yi=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){const t=e.classList.contains("clepit-doc-card")?e:e.querySelector(".clepit-doc-card");if(t){const e=fi.get(t);if(e)return e;const n=t.getAttribute("data-page-id");if(n)return{pageId:n,title:t.querySelector(".clepit-doc-card__title")?.textContent??""}}return{pageId:"",title:""}}static render(e,t,n){a.injectStyles("doc-card-input",Jt);const o=t??{pageId:"",title:""},i=Zt.render(o,void 0,n?.styles,n?.classNames);return i.classList.add("clepit-doc-card--input"),i.setAttribute("contenteditable","false"),fi.set(i,o),i}static isEmpty(t){return""===e.save(t).pageId}static isEmptyData(e){return!e.pageId}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},vi={icon:"🗎",get input(){return yi},label:"Doc card",get output(){return Zt},shortcut:v("K"),testId:"block-type-doc-card",type:"doc_card"},xi=new WeakMap,ki=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){const t=e.classList.contains("clepit-output-embed")?e:e.querySelector(".clepit-output-embed");return(t?xi.get(t):void 0)??{url:""}}static render(e,t,n){a.injectStyles("embed-input",Qt);const o=t??{url:""},i=cn.render(o,void 0,n?.styles,n?.classNames);return i.classList.add("clepit-embed--input"),i.setAttribute("contenteditable","false"),xi.set(i,o),i}static isEmpty(t){return""===e.save(t).url}static isEmptyData(e){return!e.url}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},wi={icon:"🔗",get input(){return ki},label:"Embed",get output(){return cn},shortcut:v("M"),testId:"block-type-embed",type:"embed"},Ci=new WeakMap,Ei=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static save(e){const t=e.classList.contains("clepit-file-host")?e:e.querySelector(".clepit-file-host");if(t){const e=Ci.get(t);if(e)return e}return{name:"",url:""}}static render(t,n,o,i){a.injectStyles("file-input",dn);const r=document.createElement("div");return r.className="clepit-file-host",r.setAttribute("contenteditable","false"),o?.url&&o.name&&Ci.set(r,o),e.renderState(r,t,n,i),r}static renderState(t,n,a,o){t.innerHTML="";const i=Ci.get(t);if(!i){const i=document.createElement("button");return i.type="button",i.className="clepit-file__upload",i.setAttribute("data-testid","file-upload-button"),i.textContent="Upload file",e.addEventListener(a,i,"click",()=>{e.pick(t,n,a,o)}),void t.appendChild(i)}const r=hn.render(i,void 0,o?.styles,o?.classNames);r.removeAttribute("href"),t.appendChild(r)}static pick(t,n,a,o){const i=document.createElement("input");i.type="file",i.addEventListener("change",async()=>{const r=i.files?.[0];if(!r)return;const s=await n(r);Ci.set(t,{contentType:r.type||void 0,name:r.name,size:r.size,url:s}),e.renderState(t,n,a,o)}),i.click()}static isEmpty(t){return""===e.save(t).url}static isEmptyData(e){return!e.url}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Si={icon:"📎",get input(){return Ei},label:"File",get output(){return hn},shortcut:v("F"),testId:"block-type-file",type:"file"},Ni={html:"",label:""},Ai=class e{static{this.placeholder="At a glance"}static save(e){const t=e.classList.contains("clepit-glance")?e:e.querySelector(".clepit-glance");if(!t)return{rows:[]};const n=[...t.querySelectorAll(".clepit-glance-label")],a=[...t.querySelectorAll(".clepit-glance-value")],o=n.map((e,t)=>({html:I(a[t]?.innerHTML??""),label:e.textContent??""})),i=t.getAttribute("data-variant")??"plain",r=t.querySelector(".clepit-glance-caption")?.textContent??"";return r?{caption:r,rows:o,variant:i}:{rows:o,variant:i}}static render(e,t,n){a.injectStyles("clepit-glance-input-styles","\n.clepit-glance--input {\n cursor: text;\n}\n\n.clepit-glance--input .clepit-glance-label:empty::before,\n.clepit-glance--input .clepit-glance-value:empty::before {\n color: var(--clepit-text-subtle);\n content: attr(data-placeholder);\n font-style: italic;\n pointer-events: none;\n}\n");const o=t?.rows?.length?t:{rows:[Ni]},i=fn.render(o,void 0,n?.styles,n?.classNames);i.classList.add("clepit-glance--input");for(const a of i.querySelectorAll(".clepit-glance-label"))a.setAttribute("contenteditable","true"),a.setAttribute("data-placeholder","Label");for(const a of i.querySelectorAll(".clepit-glance-value"))a.setAttribute("contenteditable","true"),a.setAttribute("data-placeholder","Value");return i}static changeVariant(t,n,o){const i=l.getState().getInstance(o);if(!i)return;if((t.getAttribute("data-variant")??"plain")===n)return;const r=sr.getBlockIndex(o,t.closest(`.${a.classNames.block.container}`)?.getAttribute("data-id")),s={...e.save(t),variant:n},c={classNames:i.config.classNames?.blocks?.glance,margins:i.config.margins,styles:i.config.styles?.blocks?.glance},p=e.render(o,s,c);t.replaceWith(p),l.getState().updateBlockData(o,r,s)}static isEmpty(t){return e.isEmptyData(e.save(t))}static isEmptyData(e){return!e?.rows?.length||e.rows.every(e=>""===e.label.trim()&&""===I(e.html).trim())}static destroy(e){}},Li={icon:"≡",get input(){return Ai},label:"At a glance",get output(){return fn},shortcut:v("N"),testId:"block-type-glance",type:"glance"},Bi={icon:"H",get input(){return vn},label:"Header",get output(){return xn},shortcut:v("H"),testId:"block-type-header",type:"header"},$i={icon:"𝑖",get input(){return Cn},label:"Image",get output(){return En},shortcut:v("I"),testId:"block-type-image",type:"image"},Mi={icon:"•",get input(){return Nn},label:"List",get output(){return An},shortcut:v("L"),testId:"block-type-list",type:"list"},Ii="clepit-openapi__source",Ti=(e,t)=>{const n=e.trim();if(""===n)return{};if(/^https?:\/\//i.test(n))return{url:n};try{return{spec:JSON.parse(n)}}catch{return t??{}}},qi=class e{static{this.placeholder="Paste an OpenAPI document, or a URL to one…"}static{this.dataMap=new WeakMap}static render(t,n,o){a.injectStyles("clepit-openapi-input-styles","\n.clepit-openapi-input {\n display: flex;\n flex-direction: column;\n gap: 12px;\n}\n\n.clepit-openapi__source {\n background: var(--clepit-code-bg);\n border: 1px solid var(--clepit-code-border);\n border-radius: 6px;\n color: var(--clepit-code-text);\n font-family: 'SF Mono', 'Monaco', 'Roboto Mono', monospace;\n font-size: 13px;\n max-height: 240px;\n overflow: auto;\n padding: 12px;\n white-space: pre-wrap;\n}\n\n.clepit-openapi__source[data-placeholder]:empty::before {\n color: var(--clepit-text-subtle);\n content: attr(data-placeholder);\n font-style: italic;\n pointer-events: none;\n}\n");const i=B("div","clepit-openapi-input"),r=B("div",Ii);r.setAttribute("contenteditable","true"),r.setAttribute("data-placeholder",e.placeholder),r.setAttribute("data-testid","openapi-source"),r.textContent=n?.url??(n?.spec?JSON.stringify(n.spec,null,2):"");const s=B("div","clepit-openapi-input__preview");return s.setAttribute("data-testid","openapi-preview"),n&&s.appendChild(aa.render(n)),r.addEventListener("input",()=>{const t=Ti(r.textContent??"",e.dataMap.get(i));e.dataMap.set(i,t),s.replaceChildren(aa.render(t))}),n&&e.dataMap.set(i,n),i.appendChild(r),i.appendChild(s),i}static save(t){const n=(e=>e.classList.contains(Ii)?e:e.querySelector(`.${Ii}`))(t),a=t.classList.contains("clepit-openapi-input")?t:t.querySelector(".clepit-openapi-input"),o=a?e.dataMap.get(a):void 0;return Ti(n?.textContent??"",o)}static isEmpty(t){return e.isEmptyData(e.save(t))}static isEmptyData(e){return void 0===e.spec&&!e.url}static destroy(e){}},Di={icon:"⇄",get input(){return qi},label:"API reference",get output(){return aa},shortcut:v("A"),testId:"block-type-openapi",type:"openapi"},_i={icon:"¶",get input(){return ia},label:"Paragraph",get output(){return ra},shortcut:v("P"),testId:"block-type-paragraph",type:"paragraph"},ji={icon:"“",get input(){return ca},label:"Quote",get output(){return pa},shortcut:v("Q"),testId:"block-type-quote",type:"quote"},zi=new WeakMap,Oi=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){const t=e.classList.contains("clepit-sketch")?e:e.querySelector(".clepit-sketch");return(t?zi.get(t):void 0)??{strokes:[]}}static render(t,n,o){a.injectStyles("sketch-input",ua);const i=n??{strokes:[]},r=fa.render(i,void 0,o?.styles,o?.classNames);return r.classList.add("clepit-sketch--input"),r.setAttribute("contenteditable","false"),zi.set(r,i),e.attachDrawing(t,r),r}static attachDrawing(t,n){const a=n.querySelector("svg");if(!a)return;let o=null;const i=e=>{const t=a.getBoundingClientRect(),n=0===t.width?0:(e.clientX-t.left)/t.width*1e3,o=0===t.height?0:(e.clientY-t.top)/t.height*240;return[Math.round(100*n)/100,Math.round(100*o)/100]},r=()=>{const e=zi.get(n)??{strokes:[]},t=o&&o.length>=4?{strokes:[...e.strokes,{points:o}]}:e,i=fa.render(t).querySelector("svg");i&&a.replaceChildren(...Array.from(i.childNodes))},s=[],l=(e,t)=>{a.addEventListener(e,t),s.push({element:a,event:e,handler:t})};l("pointerdown",e=>{o=i(e),e.target.setPointerCapture?.(e.pointerId)}),l("pointermove",e=>{o&&(o.push(...i(e)),r())});const c=()=>{if(o&&o.length>=4){const e=zi.get(n)??{strokes:[]};zi.set(n,{strokes:[...e.strokes,{points:o}]})}o=null,r()};l("pointerup",c),l("pointercancel",c),e.eventListenersMap[t]=[...e.eventListenersMap[t]??[],...s]}static isEmpty(t){return 0===e.save(t).strokes.length}static isEmptyData(e){return 0===(e.strokes??[]).length}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Hi={icon:"✏️",get input(){return Oi},label:"Sketch",get output(){return fa},shortcut:v("W"),testId:"block-type-sketch",type:"sketch"},Pi={icon:"⊞",get input(){return xa},label:"Table",get output(){return Ca},shortcut:v("T"),testId:"block-type-table",type:"table"},Fi=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){return{}}static render(e,t,n){a.injectStyles("toc-input",Sa);const o=l.getState().getData(e)?.blocks??[],i=La.render({},{documentBlocks:o},n?.styles,n?.classNames);return i.classList.add("clepit-toc--input"),i.setAttribute("contenteditable","false"),i}static isEmpty(e){return!1}static isEmptyData(e){return!1}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Ri={icon:"≡",get input(){return Fi},label:"Table of contents",get output(){return La},shortcut:v("T"),testId:"block-type-toc",type:"toc"},Vi={latex:"LaTeX",mermaid:"Mermaid"};function Ui(e){const t=e.classList.contains("clepit-typeset")?e:e.querySelector(".clepit-typeset"),n=t?.querySelector(".clepit-typeset__source"),a=t?.querySelector(".clepit-typeset__title")?.textContent?.trim();return a?{source:n?.textContent??"",title:a}:{source:n?.textContent??""}}function Wi(e,t,n){a.injectStyles("typeset-input",$a);const o=t??{source:""},i=a.createStyledElement("div",`clepit-typeset clepit-output-typeset clepit-typeset--input clepit-typeset--${e}`,{classNames:n?.classNames?.wrapper,styles:n?.styles?.wrapper});i.setAttribute("data-language",e),i.setAttribute("data-rendered","source");const r=B("span","clepit-typeset__kind");r.textContent=Vi[e],i.appendChild(r);const s=B("span","clepit-typeset__title");s.setAttribute("data-testid","typeset-title"),s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder","mermaid"===e?"What does this diagram show?":"What does this formula show?"),s.textContent=o.title??"",i.appendChild(s);const l=B("pre","clepit-typeset__source");return l.setAttribute("contenteditable","true"),l.textContent=o.source,i.appendChild(l),i}var Ki=class{static{this.placeholder=""}static save(e){return Ui(e)}static render(e,t,n){return Wi("latex",t,n)}static isEmpty(e){return""===Ui(e).source.trim()}static isEmptyData(e){return!e.source.trim()}static destroy(e){}},Gi=class{static{this.placeholder=""}static save(e){return Ui(e)}static render(e,t,n){return Wi("mermaid",t,n)}static isEmpty(e){return""===Ui(e).source.trim()}static isEmptyData(e){return!e.source.trim()}static destroy(e){}},Ji={icon:"∑",get input(){return Ki},label:"LaTeX",get output(){return Ko},shortcut:v("X"),testId:"block-type-latex",type:"latex"},Xi={icon:"◈",get input(){return Gi},label:"Mermaid",get output(){return Go},shortcut:v("Y"),testId:"block-type-mermaid",type:"mermaid"},Zi=new WeakMap,Yi=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){const t=e.classList.contains("clepit-updates")?e:e.querySelector(".clepit-updates");if(t){const e=Zi.get(t);if(e)return e;const n=t.getAttribute("data-page-id");if(n)return{pageId:n}}return{}}static render(e,t,n){a.injectStyles("updates-input",Xo);const o=t??{},i=Yo.render(o,void 0,n?.styles,n?.classNames);return i.classList.add("clepit-updates--input"),i.setAttribute("contenteditable","false"),Zi.set(i,o),i}static isEmpty(e){return!1}static isEmptyData(e){return!1}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},Qi=[we,Ae,Ie,St,si,pi,{icon:"🕘",get input(){return Yi},label:"Updates",get output(){return Yo},shortcut:v("U"),testId:"block-type-updates",type:"updates"},mi,gi,bi,vi,wi,Si,Li,Bi,$i,Mi,Di,_i,ji,Hi,Ji,Xi,Pi,Ri,{icon:"▶",get input(){return ti},label:"Video",get output(){return ni},shortcut:v("V"),testId:"block-type-video",type:"video"}],er="clepit-block-type-selector",tr="clepit-code-language-submenu",nr="clepit-code-theme-submenu",ar="clepit-convert-submenu",or="clepit-block-operations-menu";var ir,rr=class e{static{this.defaultClassName="clepit-block-toolbar"}static{this.menuAnchor="--clepit-block-toolbar"}static{this.submenuAnchorSeq=0}static{this.eventListenersMap=new WeakMap}static{this.documentListeners=[]}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap.get(t)||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap.set(t,i)}static addDocumentEventListener(t,n){const a=e=>n(e);document.addEventListener(t,a),e.documentListeners.push({event:t,handler:a})}static create({containerId:t,block:n}){const o=l.getState().getInstance(t);if(!o)return console.error("BlockToolbar::create: Instance not found for containerId:",t);const i=document.getElementById(t);if(!i)return console.error("BlockToolbar::create: Container not found for containerId:",t);e.eventListenersMap.has(i)||e.eventListenersMap.set(i,[]);const r=void 0!==o.config.audioUploader,s=void 0!==o.config.imageUploader,c=void 0!==o.config.videoUploader,p=o.config.classNames?.blockToolbar,d=o.config.classNames?.blockTypeMenu,u=o.config.classNames?.convertSubmenu,m=o.config.classNames?.operationsMenu,h=o.config.styles?.blockToolbar,g=o.config.styles?.blockTypeMenu,b=o.config.styles?.convertSubmenu,f=o.config.styles?.operationsMenu;e.remove(n),a.injectStyles("clepit-block-toolbar-styles",'\n/* Block Toolbar */\n.clepit-block-toolbar {\n position: absolute;\n left: 4px;\n top: 4px;\n z-index: 1000;\n display: none;\n gap: 4px;\n flex-shrink: 0;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n overflow: hidden;\n padding: 4px;\n transition: transform 0.2s ease;\n}\n\n.clepit-block-toolbar--visible {\n display: flex !important;\n transform: translateY(0) !important;\n pointer-events: auto !important;\n}\n\n.clepit-block-toolbar--hidden {\n display: none !important;\n pointer-events: none !important;\n}\n\n.clepit-block--active .clepit-block-toolbar,\n.clepit-block:focus-within .clepit-block-toolbar,\n.clepit-block-toolbar[style*="display: flex"] {\n display: flex;\n pointer-events: auto;\n}\n\n.clepit-block-toolbar-add,\n.clepit-block-toolbar-ops {\n width: 24px;\n height: 24px;\n border: none;\n border-radius: 4px;\n background: transparent;\n color: var(--clepit-text-muted);\n font-size: 14px;\n font-weight: bold;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s ease;\n}\n\n.clepit-block-toolbar-add:hover,\n.clepit-block-toolbar-ops:hover {\n background: var(--clepit-toolbar-button-hover-bg, var(--clepit-selection-bg));\n color: var(--clepit-toolbar-button-hover-color, var(--clepit-primary));\n transform: scale(1.05);\n}\n\n.clepit-block-toolbar-add:active,\n.clepit-block-toolbar-ops:active {\n transform: scale(0.95);\n}\n\n/* Block toolbar positioning and display classes */\n.clepit-block-toolbar--positioned {\n position: absolute;\n}\n\n.clepit-block-toolbar--menu-positioned {\n position: absolute;\n z-index: 1001;\n}\n\n.clepit-block-toolbar--submenu-positioned {\n position: absolute;\n z-index: 998;\n}\n\n.clepit-block-toolbar--item-hidden {\n display: none;\n}\n\n.clepit-block-toolbar--item-visible {\n display: flex;\n}\n\n.clepit-block-toolbar--separator-hidden {\n display: none;\n}\n\n.clepit-block-toolbar--separator-visible {\n display: block;\n}\n\n.clepit-block-toolbar--delete-disabled {\n opacity: 0.5;\n cursor: not-allowed;\n pointer-events: none;\n}\n\n.clepit-block-toolbar--delete-enabled {\n color: var(--clepit-error);\n}\n\n/* The toolbar stays absolutely positioned at every width. It used to go\n * position: static below 768px, which made it a flex item of .clepit-block —\n * and because it is appended after the content it landed to the RIGHT of the\n * text rather than above it, taking a further 60px off an already narrow\n * column. Absolute keeps it inside the gutter the block opens for it. */\n');const y=B("div",e.defaultClassName);y.id=`${t}-block-toolbar`,y.innerHTML="",a.applyStyling(y,{classNames:p?.container,styles:h?.container});const v=B("button","clepit-block-toolbar-add",{"data-testid":"toolbar-add-button",type:"button"});v.innerHTML="+",a.applyStyling(v,{classNames:p?.button,styles:h?.button}),e.addEventListener(i,v,"click",()=>e.showBlockTypeMenu({audioIsEnabled:r,block:n,classNames:d,containerId:t,imageIsEnabled:s,styles:g,toolLabels:o.config.blockToolLabels,videoIsEnabled:c}));const x=B("button","clepit-block-toolbar-ops",{"data-testid":"toolbar-operations-button",type:"button"});x.innerHTML="⋯",a.applyStyling(x,{classNames:p?.button,styles:h?.button}),e.addEventListener(i,x,"click",()=>e.showOperationsMenu({audioIsEnabled:r,block:n,classNames:m,containerId:t,convertSubmenuClassNames:u,convertSubmenuStyles:b,imageIsEnabled:s,operationLabels:o.config.blockToolbarLabels,styles:f,videoIsEnabled:c})),y.appendChild(v),y.appendChild(x),e.addEventListener(i,y,"click",e=>e.stopPropagation()),n.appendChild(y)}static showBlockTypeMenu({containerId:t,block:n,imageIsEnabled:o,videoIsEnabled:i,audioIsEnabled:r,classNames:s,styles:l,toolLabels:c}){e.closeAllMenus();const p=document.querySelector(`.${er}`);if(p)return p.classList.remove(`${er}--visible`),p.classList.add(`${er}--hidden`),void setTimeout(()=>p.remove(),200);const d=B("div",er);a.applyStyling(d,{classNames:s?.container,styles:l?.container});const u=B("input","",{placeholder:"Search blocks...",type:"text"});u.setAttribute("data-testid","block-type-search"),a.applyStyling(u,{classNames:s?.input,styles:l?.input}),d.appendChild(u);const m=document.querySelector(`#${t}`),h=B("div",`${er}-items`),g=p=>{h.innerHTML="",p.forEach(p=>{if("image"===p.type&&!o)return;if("video"===p.type&&!i)return;if("audio"===p.type&&!r)return;const u=B("div","clepit-menu-item clepit-block-type-item");u.setAttribute("data-testid",`block-type-${p.type}`),a.applyStyling(u,{classNames:s?.item?.container,styles:l?.item?.container});const g=B("span","clepit-menu-icon "+("image"===p.type?"clepit-menu-icon--italic":""));g.textContent=p.icon,a.applyStyling(g,{classNames:s?.item?.icon,styles:l?.item?.icon}),u.appendChild(g);const b=B("span","");var f;if(b.textContent=(f=p.type,(Y.includes(f)?c?.[p.type]:void 0)??p.label),a.applyStyling(b,{classNames:s?.item?.text,styles:l?.item?.text}),u.appendChild(b),p.shortcut){const e=B("span","clepit-menu-shortcut");e.textContent=p.shortcut,a.applyStyling(e,{classNames:s?.item?.shortcut,styles:l?.item?.shortcut}),u.appendChild(e)}e.addEventListener(m,u,"click",e=>{if(e.stopPropagation(),n){const e=sr.getBlockIndex(t,n.getAttribute("data-id")||"");sr.insertBlock({data:{html:""},type:p.type},t,e+1)}d.hidePopover()}),h.appendChild(u)})};if(g(Qi),e.addEventListener(m,u,"click",e=>e.stopPropagation()),e.addEventListener(m,u,"focus",e=>e.stopPropagation()),e.addEventListener(m,u,"input",()=>{const e=u.value.toLowerCase(),t=Qi.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e));if(g(t),0===t.length&&""!==e.trim()){const e=B("div","clepit-not-found-message",{style:"padding: 8px 12px; color: #666; font-style: italic; text-align: center;"});e.textContent="No block types found",h.appendChild(e)}}),e.addEventListener(m,u,"keydown",e=>{"Escape"===e.key&&d.hidePopover()}),d.appendChild(h),d.classList.add(er),d.setAttribute("popover","auto"),u.setAttribute("autofocus",""),n){const t=n.querySelector(`.${e.defaultClassName}`);t&&t.style.setProperty("anchor-name",e.menuAnchor)}document.body.appendChild(d),d.addEventListener("toggle",e=>{"closed"===e.newState&&d.remove()}),"function"!=typeof d.showPopover?(d.classList.add(`${er}--visible`),u.focus(),e.addDocumentEventListener("click",e=>{const t=e.target;d.contains(t)||n?.contains(t)||d.remove()})):d.showPopover()}static showOperationsMenu({containerId:t,block:n,classNames:o,styles:i,convertSubmenuClassNames:r,convertSubmenuStyles:s,imageIsEnabled:l,videoIsEnabled:c,audioIsEnabled:p,operationLabels:d}){e.closeAllMenus();const u=B("div",or);i?.container&&a.applyStyling(u,{classNames:o?.container,styles:i.container}),o?.container&&u.classList.add(o.container);const m=B("input","",{placeholder:"Search operations...",type:"text"});m.setAttribute("data-testid","operations-search"),a.applyStyling(m,{classNames:o?.input,styles:i?.input}),u.appendChild(m);const h=document.querySelector(`#${t}`),g=B("div",`${or}-items`),b=n.getAttribute("data-tool");if(!b)return;const f=(e,t)=>d?.[e]??t,y=[{icon:"←",label:"Align Left",testId:"image-align-left",value:"imageAlignLeft"},{icon:"↔",label:"Align Center",testId:"image-align-center",value:"imageAlignCenter"},{icon:"→",label:"Align Right",testId:"image-align-right",value:"imageAlignRight"}],v=[{icon:"←",label:"Align Left",testId:"video-align-left",value:"videoAlignLeft"},{icon:"↔",label:"Align Center",testId:"video-align-center",value:"videoAlignCenter"},{icon:"→",label:"Align Right",testId:"video-align-right",value:"videoAlignRight"}],x=[{icon:"←",label:"Align Left",testId:"audio-align-left",value:"audioAlignLeft"},{icon:"↔",label:"Align Center",testId:"audio-align-center",value:"audioAlignCenter"},{icon:"→",label:"Align Right",testId:"audio-align-right",value:"audioAlignRight"}],k=[{hasSubmenu:!0,icon:"⌘",label:"Language",testId:"code-language",value:"codeLanguage"},{hasSubmenu:!0,icon:"◆",label:"Theme",testId:"code-theme",value:"codeTheme"}];[{hasSubmenu:!0,icon:"↻",label:f("convert","Convert To"),testId:"operation-convert",value:"convert"},{icon:"↑",label:f("moveUp","Move Up"),shortcut:"⌘⇧↑",testId:"operation-moveUp",value:"moveUp"},{icon:"↓",label:f("moveDown","Move Down"),shortcut:"⌘⇧↓",testId:"operation-moveDown",value:"moveDown"},{icon:"×",label:f("delete","Delete"),shortcut:"⌘⇧⌫",testId:"operation-delete",value:"delete"}].forEach(d=>{const m=B("div","clepit-menu-item clepit-block-operation-item");m.setAttribute("data-testid",`operation-${d.value}`),a.applyStyling(m,{classNames:o?.item?.container,styles:i?.item?.container}),m.setAttribute("data-testid",d.testId);const b=B("span","clepit-menu-icon");b.textContent=d.icon,a.applyStyling(b,{classNames:o?.item?.icon,styles:i?.item?.icon}),m.appendChild(b);const f=B("span","");if(f.textContent=d.label,a.applyStyling(f,{classNames:o?.item?.text,styles:i?.item?.text}),m.appendChild(f),d.shortcut){const e=B("span","clepit-menu-shortcut");e.textContent=d.shortcut,a.applyStyling(e,{classNames:o?.item?.shortcut,styles:i?.item?.shortcut}),m.appendChild(e)}if(d.hasSubmenu){const e=B("span","clepit-menu-arrow");e.textContent="›",m.appendChild(e)}"delete"===d.value&&(m.classList.add("clepit-block-toolbar--delete-enabled"),1===h.querySelectorAll(".clepit-block").length&&(m.classList.add("clepit-block-toolbar--delete-disabled"),m.title="Cannot delete the last block")),e.addEventListener(h,m,"click",a=>{a.stopPropagation(),d.hasSubmenu?(document.querySelector(`.${tr}`)?.remove(),document.querySelector(`.${nr}`)?.remove(),e.showConvertSubmenu({audioIsEnabled:p,block:n,classNames:r,containerId:t,imageIsEnabled:l,parentItem:m,parentMenu:u,styles:s,videoIsEnabled:c})):(e.handleOperationSelect(d.value,n,t),u.remove())}),g.appendChild(m)});const w=()=>{const e=B("div","clepit-menu-divider");a.applyStyling(e,{classNames:o?.divider,styles:i?.divider}),g.appendChild(e)};if("image"===b&&(w(),y.forEach(r=>{const s=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(s,{classNames:o?.item?.container,styles:i?.item?.container}),s.setAttribute("data-testid",r.testId);const l=B("span","clepit-menu-icon");l.textContent=r.icon,a.applyStyling(l,{classNames:o?.item?.icon,styles:i?.item?.icon}),s.appendChild(l);const c=B("span","");if(c.textContent=r.label,a.applyStyling(c,{classNames:o?.item?.text,styles:i?.item?.text}),s.appendChild(c),r.value.startsWith("imageAlign")){const e=n.querySelector(".clepit-image-wrapper");if(e){const t=e.style.textAlign;("left"===t?"left":"right"===t?"right":"center")===r.value.replace("imageAlign","").toLowerCase()&&s.classList.add("active")}}e.addEventListener(h,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(r.value,n,t),u.remove()}),g.appendChild(s)})),"video"===b&&(w(),v.forEach(r=>{const s=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(s,{classNames:o?.item?.container,styles:i?.item?.container}),s.setAttribute("data-testid",r.testId);const l=B("span","clepit-menu-icon");l.textContent=r.icon,a.applyStyling(l,{classNames:o?.item?.icon,styles:i?.item?.icon}),s.appendChild(l);const c=B("span","");if(c.textContent=r.label,a.applyStyling(c,{classNames:o?.item?.text,styles:i?.item?.text}),s.appendChild(c),r.value.startsWith("videoAlign")){const e=n.querySelector(".clepit-video-wrapper");if(e){const t=e.style.textAlign;("left"===t?"left":"right"===t?"right":"center")===r.value.replace("videoAlign","").toLowerCase()&&s.classList.add("active")}}e.addEventListener(h,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(r.value,n,t),u.remove()}),g.appendChild(s)})),"audio"===b&&(w(),x.forEach(r=>{const s=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(s,{classNames:o?.item?.container,styles:i?.item?.container}),s.setAttribute("data-testid",r.testId);const l=B("span","clepit-menu-icon");l.textContent=r.icon,a.applyStyling(l,{classNames:o?.item?.icon,styles:i?.item?.icon}),s.appendChild(l);const c=B("span","");if(c.textContent=r.label,a.applyStyling(c,{classNames:o?.item?.text,styles:i?.item?.text}),s.appendChild(c),r.value.startsWith("audioAlign")){const e=n.querySelector(".clepit-audio-wrapper");if(e){const t=e.style.textAlign;("left"===t?"left":"right"===t?"right":"center")===r.value.replace("audioAlign","").toLowerCase()&&s.classList.add("active")}}e.addEventListener(h,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(r.value,n,t),u.remove()}),g.appendChild(s)})),"code"===b&&(w(),k.forEach(l=>{const c=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(c,{classNames:o?.item?.container,styles:i?.item?.container}),c.setAttribute("data-testid",l.testId);const p=B("span","clepit-menu-icon");p.textContent=l.icon,a.applyStyling(p,{classNames:o?.item?.icon,styles:i?.item?.icon}),c.appendChild(p);const d=B("span","");if(d.textContent=l.label,a.applyStyling(d,{classNames:o?.item?.text,styles:i?.item?.text}),c.appendChild(d),l.hasSubmenu){const e=B("span","clepit-menu-arrow");e.textContent="›",c.appendChild(e)}e.addEventListener(h,c,"click",a=>{a.stopPropagation(),l.hasSubmenu?"codeLanguage"===l.value?e.showCodeLanguageSubmenu({block:n,classNames:r,containerId:t,parentItem:c,parentMenu:u,styles:s}):"codeTheme"===l.value&&e.showCodeThemeSubmenu({block:n,classNames:r,containerId:t,parentItem:c,parentMenu:u,styles:s}):(e.handleOperationSelect(l.value,n,t),u.remove())}),g.appendChild(c)})),"header"===b){w();const r=e.getCurrentHeadingLevel(n);[{icon:"H1",label:"Heading 1",value:"heading-h1"},{icon:"H2",label:"Heading 2",value:"heading-h2"},{icon:"H3",label:"Heading 3",value:"heading-h3"},{icon:"H4",label:"Heading 4",value:"heading-h4"},{icon:"H5",label:"Heading 5",value:"heading-h5"},{icon:"H6",label:"Heading 6",value:"heading-h6"}].forEach(s=>{const l=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(l,{classNames:o?.item?.container,styles:i?.item?.container});const c=B("span","clepit-menu-icon");c.textContent=s.icon,a.applyStyling(c,{classNames:o?.item?.icon,styles:i?.item?.icon}),l.appendChild(c);const p=B("span","");p.textContent=s.label,a.applyStyling(p,{classNames:o?.item?.text,styles:i?.item?.text}),l.appendChild(p),s.value===`heading-${r}`&&l.classList.add("active"),e.addEventListener(h,l,"click",a=>{a.stopPropagation(),e.handleOperationSelect(s.value,n,t),u.remove()}),g.appendChild(l)})}if("list"===b){w();const r=n.querySelector(".clepit-list")?.getAttribute("data-type")||"unordered";[{icon:"•",label:"Unordered",value:"unordered"},{icon:"1.",label:"Ordered",value:"ordered"}].forEach(s=>{const l=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(l,{classNames:o?.item?.container,styles:i?.item?.container});const c=B("span","clepit-menu-icon");c.textContent=s.icon,a.applyStyling(c,{classNames:o?.item?.icon,styles:i?.item?.icon}),l.appendChild(c);const p=B("span","");p.textContent=s.label,a.applyStyling(p,{classNames:o?.item?.text,styles:i?.item?.text}),l.appendChild(p),s.value===r&&l.classList.add("active"),e.addEventListener(h,l,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`listType${s.value}`,n,t),u.remove()}),g.appendChild(l)})}if("alert"===b){w();const r=n.querySelector(".clepit-alert")?.getAttribute("data-variant")||"info";[{icon:"i",label:"Info",value:"info"},{icon:"!",label:"Warning",value:"warning"},{icon:"×",label:"Error",value:"error"},{icon:"✓",label:"Success",value:"success"},{icon:"—",label:"Plain",value:"plain"}].forEach(s=>{const l=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(l,{classNames:o?.item?.container,styles:i?.item?.container});const c=B("span","clepit-menu-icon");c.textContent=s.icon,c.style.color=e.getAlertIconColor(s.value),a.applyStyling(c,{classNames:o?.item?.icon,styles:i?.item?.icon}),l.appendChild(c);const p=B("span","");p.textContent=s.label,a.applyStyling(p,{classNames:o?.item?.text,styles:i?.item?.text}),l.appendChild(p),s.value===r&&l.classList.add("active"),e.addEventListener(h,l,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`alertVariant${s.value}`,n,t),u.remove()}),g.appendChild(l)})}if("glance"===b){w();const r=n.querySelector(".clepit-glance")?.getAttribute("data-variant")||"plain";[{icon:"—",label:"Plain",value:"plain"},{icon:"i",label:"Info",value:"info"},{icon:"!",label:"Warning",value:"warning"},{icon:"×",label:"Error",value:"error"},{icon:"✓",label:"Success",value:"success"}].forEach(s=>{const l=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(l,{classNames:o?.item?.container,styles:i?.item?.container});const c=B("span","clepit-menu-icon");c.textContent=s.icon,c.style.color=e.getAlertIconColor(s.value),a.applyStyling(c,{classNames:o?.item?.icon,styles:i?.item?.icon}),l.appendChild(c);const p=B("span","");p.textContent=s.label,a.applyStyling(p,{classNames:o?.item?.text,styles:i?.item?.text}),l.appendChild(p),s.value===r&&l.classList.add("active"),e.addEventListener(h,l,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`glanceVariant${s.value}`,n,t),u.remove()}),g.appendChild(l)})}if("delimiter"===b){w();const r=n.querySelector(".clepit-delimiter")?.getAttribute("data-variant")||"line";[{icon:"—",label:"Line",value:"line"},{icon:"***",label:"Stars",value:"stars"}].forEach(s=>{const l=B("div","clepit-menu-item clepit-block-operation-item");a.applyStyling(l,{classNames:o?.item?.container,styles:i?.item?.container});const c=B("span","clepit-menu-icon");c.textContent=s.icon,a.applyStyling(c,{classNames:o?.item?.icon,styles:i?.item?.icon}),l.appendChild(c);const p=B("span","");p.textContent=s.label,a.applyStyling(p,{classNames:o?.item?.text,styles:i?.item?.text}),l.appendChild(p),s.value===r&&l.classList.add("active"),e.addEventListener(h,l,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`delimiterVariant${s.value}`,n,t),u.remove()}),g.appendChild(l)})}const C=g.querySelectorAll(".clepit-block-operation-item"),E=g.querySelectorAll(".clepit-menu-divider");if(e.addEventListener(h,m,"click",e=>e.stopPropagation()),e.addEventListener(h,m,"focus",e=>e.stopPropagation()),e.addEventListener(h,m,"input",e=>{(e=>{let t=0;C.forEach(n=>{(n.querySelector("span:last-child")?.textContent?.toLowerCase()||"").includes(e.toLowerCase())?(n.classList.remove("clepit-block-toolbar--item-hidden"),n.classList.add("clepit-block-toolbar--item-visible"),t++):(n.classList.remove("clepit-block-toolbar--item-visible"),n.classList.add("clepit-block-toolbar--item-hidden"))});const n=g.querySelector(".clepit-not-found-message");if(0===t&&""!==e.trim()){if(!n){const e=B("div","clepit-not-found-message",{style:"padding: 8px 12px; color: #666; font-style: italic; text-align: center;"});e.textContent="No operations found",g.appendChild(e)}}else n&&n.remove();E.forEach(t=>{""!==e.trim()?(t.classList.remove("clepit-block-toolbar--separator-visible"),t.classList.add("clepit-block-toolbar--separator-hidden")):(t.classList.remove("clepit-block-toolbar--separator-hidden"),t.classList.add("clepit-block-toolbar--separator-visible"))})})(e.target.value)}),e.addEventListener(h,m,"keydown",e=>{"Escape"===e.key&&u.remove()}),u.appendChild(g),u.classList.add(or),u.setAttribute("popover","auto"),m.setAttribute("autofocus",""),n){const t=n.querySelector(`.${e.defaultClassName}`);t&&t.style.setProperty("anchor-name",e.menuAnchor)}document.body.appendChild(u),u.addEventListener("toggle",e=>{"closed"===e.newState&&u.remove()}),"function"!=typeof u.showPopover?(u.classList.add(`${or}--visible`),m.focus(),e.addDocumentEventListener("click",e=>{const t=e.target;u.contains(t)||n?.contains(t)||t.closest?.(".clepit-block-toolbar-ops")||u.remove()})):u.showPopover()}static showConvertSubmenu({containerId:t,block:n,parentItem:o,parentMenu:i,classNames:r,styles:s,imageIsEnabled:l,videoIsEnabled:c,audioIsEnabled:p}){const d=document.querySelector(`.${ar}`);d&&d.remove();const u=n.getAttribute("data-tool");if(!u)return;const m=B("div",ar);m.classList.add(ar),m.classList.add(`${ar}--hidden`),s?.container&&a.applyStyles(m,s.container),r?.container&&m.classList.add(r.container);const h=B("input","",{placeholder:"Search convert options...",type:"text"});h.setAttribute("data-testid","convert-search"),a.applyStyling(h,{classNames:r?.input,styles:s?.input}),m.appendChild(h),setTimeout(()=>h.focus(),10);const g=document.querySelector(`#${t}`),b=B("div",`${ar}-items`);Qi.filter(e=>e.type!==u&&(!("image"===e.type&&!l||"video"===e.type&&!c||"audio"===e.type&&!p)||void 0)).sort((e,t)=>e.label.localeCompare(t.label)).forEach(o=>{const l=B("div","clepit-menu-item clepit-convert-option-item");l.setAttribute("data-testid",o.testId),a.applyStyling(l,{classNames:r?.item?.container,styles:s?.item?.container});const c=B("span","clepit-menu-icon");c.textContent=o.icon,a.applyStyling(c,{classNames:r?.item?.icon,styles:s?.item?.icon}),l.appendChild(c);const p=B("span","");if(p.textContent=o.label,a.applyStyling(p,{classNames:r?.item?.text,styles:s?.item?.text}),l.appendChild(p),o.shortcut){const e=B("span","clepit-menu-shortcut");e.textContent=o.shortcut,a.applyStyling(e,{classNames:r?.item?.shortcut,styles:s?.item?.shortcut}),l.appendChild(e)}e.addEventListener(g,l,"click",e=>{e.stopPropagation();const a=n?.getAttribute("data-tool");if(!a)return;let r;if(n){const e=n.querySelector(".clepit-block-content");"paragraph"===a?r=e.querySelector(".clepit-paragraph")?.innerText||"":"quote"===a?r=e.querySelector(".clepit-quote-text")?.innerText||"":"list"===a?r=Array.from(e.querySelectorAll(".clepit-list-item")).map(e=>e.innerText.trim()).filter(Boolean).join("\n"):"alert"===a?r=e.querySelector(".clepit-alert")?.innerText||"":"header"===a&&(r=e.querySelector(".clepit-header")?.innerText||"")}const s=n?.getAttribute("data-id");s&&sr.convertBlock(s,o.type,t),setTimeout(()=>{if(!n)return;const e=n.getAttribute("data-tool");if(r&&r.trim()){const t=n.querySelector(".clepit-block-content");if("paragraph"===e){const e=t.querySelector(".clepit-paragraph");e&&(e.innerText=r)}else if("quote"===e){const e=t.querySelector(".clepit-quote-text");e&&(e.innerText=r)}else if("list"===e){const e=t.querySelector(".clepit-list");e&&(e.innerHTML="",r.split("\n").forEach(t=>{const n=document.createElement("li");n.className="clepit-list-item",n.setAttribute("contenteditable","true"),n.innerText=t,e.appendChild(n)}))}else if("alert"===e){const e=t.querySelector(".clepit-alert");e&&(e.innerText=r)}else if("header"===e){const e=t.querySelector(".clepit-header");e&&(e.innerText=r)}}},0),i.remove()}),b.appendChild(l)});const f=b.querySelectorAll(".clepit-convert-option-item");e.addEventListener(g,h,"click",e=>e.stopPropagation()),e.addEventListener(g,h,"focus",e=>e.stopPropagation()),e.addEventListener(g,h,"input",e=>{(e=>{let t=0;f.forEach(n=>{(n.querySelector("span:last-child")?.textContent?.toLowerCase()||"").includes(e.toLowerCase())?(n.classList.remove("clepit-block-toolbar--item-hidden"),n.classList.add("clepit-block-toolbar--item-visible"),t++):(n.classList.remove("clepit-block-toolbar--item-visible"),n.classList.add("clepit-block-toolbar--item-hidden"))});const n=b.querySelector(".clepit-not-found-message");if(0===t&&""!==e.trim()){if(!n){const e=B("div","clepit-not-found-message",{style:"padding: 8px 12px; color: #666; font-style: italic; text-align: center;"});e.textContent="No convert options found",b.appendChild(e)}}else n&&n.remove()})(e.target.value)}),e.addEventListener(g,h,"keydown",t=>{"Escape"===t.key&&e.closeMenu(ar)}),m.appendChild(b);const y="--clepit-convert-parent-"+e.submenuAnchorSeq++;o.style.setProperty("anchor-name",y),m.style.setProperty("position-anchor",y),m.classList.remove(`${ar}--hidden`),m.setAttribute("popover","auto"),document.body.appendChild(m),m.addEventListener("toggle",e=>{"closed"===e.newState&&m.remove()}),"function"!=typeof m.showPopover?(i.appendChild(m),m.classList.add(`${ar}--visible`),e.addDocumentEventListener("click",e=>{const t=e.target;m.contains(t)||o.contains(t)||i.contains(t)||m.remove()})):m.showPopover()}static handleOperationSelect(e,t,n){if(!t)return;const o=document.querySelector(`#${n}`);if(e.startsWith("convertTo")){const a=e.replace("convertTo",""),o=t.getAttribute("data-id");return void(o&&sr.convertBlock(o,a,n))}if(e.startsWith("heading-")){const n=e.replace("heading-","");if(-1===sr.getBlockIndex(o.id,t.getAttribute("data-id")))return;const a=t.querySelector('[contenteditable="true"]');return void(a&&vn.changeLevel(a,n,o.id))}if(e.startsWith("listType")){const n=e.replace("listType","");if(-1===sr.getBlockIndex(o.id,t.getAttribute("data-id")))return;const a=t.querySelector(".clepit-list");return void(a&&Nn.changeType(a,n,o.id))}if(e.startsWith("alertVariant")){const n=e.replace("alertVariant","");if(-1===sr.getBlockIndex(o.id,t.getAttribute("data-id")))return;const a=t.querySelector(".clepit-alert");return void(a&&pe.changeVariant(a,n,o.id))}if(e.startsWith("glanceVariant")){const n=e.replace("glanceVariant","");if(-1===sr.getBlockIndex(o.id,t.getAttribute("data-id")))return;const a=t.querySelector(".clepit-glance");return void(a&&Ai.changeVariant(a,n,o.id))}if(e.startsWith("delimiterVariant")){const n=e.replace("delimiterVariant","");if(-1===sr.getBlockIndex(o.id,t.getAttribute("data-id")))return;const a=t.querySelector(".clepit-delimiter");if(!a)return;return Wt.changeVariant(a,n,o.id)}if(e.startsWith("tableAction")){const n=e.replace("tableAction",""),o=t.querySelector(`.${a.classNames.block.content}`);if(!o)return;return xa.handleAction(n,o)}if(e.startsWith("imageAlign"))return Cn.setAlignment(t,e.replace("imageAlign","").toLowerCase());if(e.startsWith("videoAlign"))return ti.setAlignment(t,e.replace("videoAlign","").toLowerCase());if(e.startsWith("audioAlign"))return Se.setAlignment(t,e.replace("audioAlign","").toLowerCase());if(e.startsWith("codeLanguage")){const n=e.replace("codeLanguage","");if(-1===sr.getBlockIndex(o.id,t.getAttribute("data-id")))return;return mt.updateLanguage(t,n)}if(e.startsWith("codeTheme")){const n=e.replace("codeTheme","");if(-1===sr.getBlockIndex(o.id,t.getAttribute("data-id")))return;return mt.updateTheme(t,n)}const i=sr.getBlockIndex(o.id,t.getAttribute("data-id"));if(-1!==i)switch(e){case"delete":sr.removeBlock(o.id,i);break;case"moveUp":i>0&&sr.moveBlock(o.id,i,i-1);break;case"moveDown":i<sr.getBlocks(o.id).length-1&&sr.moveBlock(o.id,i,i+1);break;default:console.warn(`Unknown block operation: ${e}`)}}static showCodeLanguageSubmenu({parentItem:t,parentMenu:n,block:o,containerId:i,classNames:r,styles:s}){const l=document.querySelector(`.${tr}`);l&&l.remove();const c=document.querySelector(`.${nr}`);c&&c.remove();const p=document.getElementById(i);if(!p)return;const d=o?.querySelector(`.${a.classNames.block.code.container}`)?.getAttribute("data-language")||"javascript",u=a.createStyledElement("div",tr,{classNames:r?.container,styles:s?.container});u.classList.add(ar,"clepit-block-toolbar--submenu-positioned");const m=B("input","",{placeholder:"Search languages...",type:"text"});m.setAttribute("data-testid","language-search"),u.appendChild(m);const h=mt.supportedLanguages;Object.entries(h).forEach(([t,l])=>{const c=a.createStyledElement("div","clepit-menu-item clepit-code-language-item",{classNames:r?.item?.container,styles:s?.item?.container});c.setAttribute("data-testid",`code-language-${t}`);const m=a.createStyledElement("span","",{classNames:r?.item?.text,styles:s?.item?.text});m.textContent=l.name,c.appendChild(m),t===d&&c.classList.add("active"),e.addEventListener(p,c,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`codeLanguage${t}`,o,i),n.remove()}),u.appendChild(c)});const g=u.querySelectorAll(".clepit-code-language-item");e.addEventListener(p,m,"click",e=>e.stopPropagation()),e.addEventListener(p,m,"input",e=>{const t=e.target.value.toLowerCase();g.forEach(e=>{const n=e.querySelector("span")?.textContent?.toLowerCase()||"";e.classList.toggle("clepit-block-toolbar--item-hidden",!n.includes(t))})}),n.appendChild(u);const b=t.getBoundingClientRect(),f=n.getBoundingClientRect();u.style.top=b.top-f.top+"px",u.style.left=b.right-f.left+4+"px",setTimeout(()=>{u.classList.remove(`${tr}--hidden`),u.classList.add(`${tr}--visible`)},10),setTimeout(()=>{const t=e=>{const a=e.target,o=u.contains(a),i=n.contains(a);o||i||(u.classList.remove(`${tr}--visible`),u.classList.add(`${tr}--hidden`),setTimeout(()=>u.remove(),200),document.removeEventListener("click",t))};e.addDocumentEventListener("click",t)},0)}static showCodeThemeSubmenu({parentItem:t,parentMenu:n,block:o,containerId:i,classNames:r,styles:s}){const l=document.querySelector(`.${nr}`);l&&l.remove();const c=document.querySelector(`.${tr}`);c&&c.remove();const p=document.getElementById(i);if(!p)return;const d=o?.querySelector(`.${a.classNames.block.code.container}`)?.getAttribute("data-theme")||"default",u=a.createStyledElement("div",nr,{classNames:r?.container,styles:s?.container});u.classList.add(ar,"clepit-block-toolbar--submenu-positioned");const m=B("input","",{placeholder:"Search themes...",type:"text"});m.setAttribute("data-testid","theme-search"),u.appendChild(m);const h=mt.supportedThemes;Object.entries(h).forEach(([t,l])=>{const c=a.createStyledElement("div","clepit-menu-item clepit-code-theme-item",{classNames:r?.item?.container,styles:s?.item?.container});c.setAttribute("data-testid",`code-theme-${t}`);const m=a.createStyledElement("span","",{classNames:r?.item?.text,styles:s?.item?.text});m.textContent=l.name,c.appendChild(m),t===d&&c.classList.add("active"),e.addEventListener(p,c,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`codeTheme${t}`,o,i),n.remove()}),u.appendChild(c)});const g=u.querySelectorAll(".clepit-code-theme-item");e.addEventListener(p,m,"click",e=>e.stopPropagation()),e.addEventListener(p,m,"input",e=>{const t=e.target.value.toLowerCase();g.forEach(e=>{const n=e.querySelector("span")?.textContent?.toLowerCase()||"";e.classList.toggle("clepit-block-toolbar--item-hidden",!n.includes(t))})}),n.appendChild(u);const b=t.getBoundingClientRect(),f=n.getBoundingClientRect();u.style.top=b.top-f.top+"px",u.style.left=b.right-f.left+4+"px",setTimeout(()=>{u.classList.remove(`${nr}--hidden`),u.classList.add(`${nr}--visible`)},10),setTimeout(()=>{const t=e=>{const a=e.target,o=u.contains(a),i=n.contains(a);o||i||(u.classList.remove(`${nr}--visible`),u.classList.add(`${nr}--hidden`),setTimeout(()=>u.remove(),200),document.removeEventListener("click",t))};e.addDocumentEventListener("click",t)},0)}static show(t,n){e.closeAllMenus(),e.hideAllToolbars(t);const a=n.querySelector(`.${e.defaultClassName}`);a&&(a.classList.add("clepit-block-toolbar--visible"),a.classList.remove("clepit-block-toolbar--hidden"))}static hide(t){document.querySelector(`.${er}, .${or}, .${ar}`)||e.hideAllToolbars(t)}static hideAllToolbars(t){const n=document.getElementById(t);n&&n.querySelectorAll(`.${e.defaultClassName}`).forEach(e=>{e.classList.remove("clepit-block-toolbar--visible"),e.classList.add("clepit-block-toolbar--hidden")})}static getCurrentHeadingLevel(e){if(!e)return"h1";const t=e.querySelector(".clepit-header");if(!t)return"h1";const n=t.getAttribute("data-level");if(n)return n;const a=t.tagName.toLowerCase();return a||"h1"}static closeMenu(e){const t=document.querySelector(`.${e}`);t&&(t.matches(":popover-open")&&"function"==typeof t.hidePopover?t.hidePopover():t.remove())}static closeAllMenus(){e.closeMenu(er),e.closeMenu(or),e.closeMenu(ar)}static getAlertIconColor(e){switch(e){case"info":return"#2196f3";case"warning":return"#ff9800";case"error":return"#f44336";case"success":return"#4caf50";default:return"#666"}}static remove(t){t.querySelectorAll(`.${e.defaultClassName}`).forEach(e=>e.remove())}static destroy(t){const n=document.getElementById(t);if(!n)return;const a=e.eventListenersMap.get(n);a&&(a.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap.delete(n)),e.documentListeners.forEach(({event:e,handler:t})=>{document.removeEventListener(e,t)}),e.documentListeners=[],n.querySelectorAll(`.${e.defaultClassName}`).forEach(e=>e.remove())}},sr=class e{static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static createBlockElement(t,n){const o=l.getState().getInstance(n);if(!o)return console.error("BlockManager::createBlockElement: Instance not found for containerId:",n),null;const i=B("div",a.classNames.block.container);i.setAttribute("data-container-id",n),i.setAttribute("data-id",crypto.randomUUID()),i.setAttribute("data-tool",t.type),i.setAttribute("data-indent","0");const r={classNames:o.config.classNames?.blocks?.[t.type],styles:o.config.styles?.blocks?.[t.type]};let s,c;if(r.margins&&(s=r.margins.top,c=r.margins.bottom),void 0===s&&r.styles){const e=r.styles;if(e.marginTop){const t=e.marginTop;"string"==typeof t&&t.endsWith("px")?s=parseInt(t.replace("px",""),10):"number"==typeof t&&(s=t)}}if(void 0===c&&r.styles){const e=r.styles;if(e.marginBottom){const t=e.marginBottom;"string"==typeof t&&t.endsWith("px")?c=parseInt(t.replace("px",""),10):"number"==typeof t&&(c=t)}}void 0===s&&void 0!==o.config.margins?.top&&(s=o.config.margins.top),void 0===c&&void 0!==o.config.margins?.bottom&&(c=o.config.margins.bottom),void 0!==s&&(i.style.marginTop=`${s}px`),void 0!==c&&(i.style.marginBottom=`${c}px`),rr.create({block:i,containerId:n});const p=B("div",a.classNames.block.content),d=e.renderTool(t.type,t.data,n);return d?(p.appendChild(d),e.addEventListener(n,i,"click",t=>e.focusBlock(t.currentTarget)),i.appendChild(p),i):(console.error("BlockManager::createBlockElement: Rendered element not found for type:",t.type),null)}static insertBlock(t,n,a){const o=e.createBlockElement(t,n);if(!o)return null;e.renderBlock(o,n,a);const i=e.getBlockData(o.getAttribute("data-id"));return l.getState().addBlock(n,i,e.getBlockIndex(n,o.getAttribute("data-id"))),o}static removeBlock(t,n){const a=e.getBlocks(t);if(n<0||n>=a.length||1===a.length)return null;if(n>0){const t=e.getBlock(a[n-1].getAttribute("data-id"));t&&e.focusBlock(t)}else if(0===n&&a.length>1){const t=e.getBlock(a[n+1].getAttribute("data-id"));t&&e.focusBlock(t)}a[n].remove(),l.getState().removeBlock(t,n)}static replaceBlock(t,n,a){e.removeBlock(t,n),e.insertBlock(a,t,n)}static moveBlock(t,n,a){const o=e.getBlocks(t);if(n<0||n>=o.length||a<0||a>=o.length)return;const i=l.getState().getData(t);if(!i)return;const r=l.getState().getContentElement(t);if(!r)return;const s=o[n];o.splice(n,1),o.splice(a,0,s),0===a?r.insertBefore(s,r.firstChild):a>=o.length-1?r.appendChild(s):r.insertBefore(s,o[a+1]);const c=o.map(t=>e.getBlockData(t.getAttribute("data-id"))),p={...i,blocks:c};l.getState().setData(t,p),e.focusBlock(s)}static getBlock(e){return document.querySelector(`[data-id="${e}"]`)}static getBlocks(e){const t=document.getElementById(e);if(!t)return[];const n=t.querySelectorAll(`.${a.classNames.block.container}`);return Array.from(n)}static getActiveBlocks(e){const t=document.getElementById(e);if(!t)return[];const n=t.querySelectorAll(`.${a.classNames.block.active}`);return Array.from(n)}static getBlockIndex(t,n){return e.getBlocks(t).findIndex(e=>e.getAttribute("data-id")===n)}static getTool(e){return Qi.find(t=>t.type===e)||null}static getBlockData(t){const n=e.getBlock(t);if(!n)return{data:{html:""},type:"paragraph"};const o=n.getAttribute("data-tool"),i=o?e.getTool(o):null;if(!i)return{data:{html:""},type:"paragraph"};const r=n.querySelector(`.${a.classNames.block.content}`);return r?{data:i.input.save(r),tunes:e.getBlockTunes(n),type:o}:{data:{html:""},tunes:e.getBlockTunes(n),type:o}}static extractData(t){return{blocks:e.getBlocks(t).map(t=>e.getBlockData(t.getAttribute("data-id"))),time:Date.now(),version:"1.0.0"}}static renderTool(e,t,n){const a=l.getState().getInstance(n);if(!a)return null;const o={classNames:a.config.classNames?.blocks?.[e],styles:a.config.styles?.blocks?.[e]};switch(e){case"alert":return pe.render(n,t,o);case"audio":return a.config.audioUploader?Se.render(a.config.audioUploader,n,t,o):(console.error("BlockManager::renderTool: Audio uploader not found for containerId:",n),null);case"code":return mt.render(n,t,o);case"collapsible":return $t.render(n,t,o);case"columns":return ui.render(n,t,o);case"date":return hi.render(n,t,o);case"delimiter":return Wt.render(n,t,o);case"collection":return ci.render(n,t,o);case"doc_card":return yi.render(n,t,o);case"embed":return ki.render(n,t,o);case"openapi":return qi.render(n,t,o);case"sketch":return Oi.render(n,t,o);case"latex":return Ki.render(n,t,o);case"mermaid":return Gi.render(n,t,o);case"file":return a.config.fileUploader?Ei.render(a.config.fileUploader,n,t,o):(console.error("BlockManager::renderTool: File uploader not found for containerId:",n),null);case"header":return vn.render(n,t,o);case"image":return a.config.imageUploader?Cn.render(a.config.imageUploader,n,t,o):(console.error("BlockManager::renderTool: Image uploader not found for containerId:",n),null);case"list":return Nn.render(n,t,o);case"checklist":return $e.render(n,t,o);case"paragraph":return ia.render(n,t,o);case"quote":return ca.render(n,t,o);case"table":return xa.render(n,t,o);case"toc":return Fi.render(n,t,o);case"video":return a.config.videoUploader?ti.render(a.config.videoUploader,n,t,o):(console.error("BlockManager::renderTool: Video uploader not found for containerId:",n),null);default:return null}}static focusBlock(t){const n=t.querySelector('[contenteditable="true"]');n&&n.focus({preventScroll:!0}),e.setActiveBlock(t)}static setActiveBlock(t){const n=t.getAttribute("data-container-id");for(const o of e.getActiveBlocks(n))o.classList.remove(a.classNames.block.active);t.classList.add(a.classNames.block.active),rr.show(n,t)}static getActiveBlock(e){const t=document.getElementById(e);return t?t.querySelector(`.${a.classNames.block.active}`):null}static convertBlock(t,n,a){const o=e.getBlock(t);if(!o)return console.error("BlockManager::convertBlock: Block not found for blockId:",t);const i=e.getBlockData(t),r=e.getTool(n);if(!r)return console.error("BlockManager::convertBlock: New tool not found for newType:",n);const s=e.getBlockIndex(a,t);let c=i.data;if("list"===n){const e=i.data,t=e.html||e.text||"";c={items:t?[t]:[""],type:"unordered"}}else if("header"===n){const e=i.data;c={html:e.html||e.text||"",level:"h1"}}const p={data:c,id:t,type:r.type},d=e.createBlockElement(p,a);if(!d)return console.error("BlockManager::convertBlock: New block element not found for newType:",n);o.replaceWith(d);const u=e.getBlockData(d.getAttribute("data-id"));l.getState().updateBlock(a,s,u),e.focusBlock(d)}static getBlockTunes(e){const t={},n=e.querySelectorAll("[data-tune]");for(const a of n){const e=a.getAttribute("data-tune");e&&(t[e]=a.getAttribute("data-value")||!0)}return Object.keys(t).length>0?t:void 0}static updateStateFromRange(t){const n=le.getInstanceAndTargetFromRange(t);if(!n)return;const o=n.target.closest(`.${a.classNames.block.container}`);if(!o)return;const i=e.getBlockIndex(n.instance.config.containerId,o.getAttribute("data-id"));l.getState().updateBlock(n.instance.config.containerId,i,e.getBlockData(o.getAttribute("data-id")))}static renderBlock(t,n,a){const o=e.getBlocks(n),i=l.getState().getContentElement(n);if(!i)return console.error("BlockManager::renderBlock: Container not found for containerId:",n);if(void 0!==a&&a>=0)if(a<o.length){const e=o[a];i.insertBefore(t,e),o.splice(a,0,t)}else i.appendChild(t),o.push(t);else i.appendChild(t),o.push(t);e.focusBlock(t);const r=l.getState().getInstance(n);r&&X.initializeElements(t,{classNames:r.config.classNames?.blocks?.tooltip,styles:r.config.styles?.blocks?.tooltip})}static setBlocks(t,n){e.removeAllBlocks(n),t.forEach((t,a)=>e.insertBlock(t,n,a)),l.getState().updateData(n,{blocks:t})}static renderBlocks(t,n){for(const o of e.getBlocks(n))o.remove();const a=(t,a)=>{const o=e.createBlockElement(t,n);o&&e.renderBlock(o,n,a)};if(0===t.length)return a({data:{html:""},type:"paragraph"},0);t.forEach(a)}static removeAllBlocks(t){for(const n of e.getBlocks(t))n.remove();l.getState().setData(t,{blocks:[],time:Date.now(),version:"1.0.0"})}static resetBlocks(t){e.removeAllBlocks(t),e.insertBlock({data:{html:""},type:"paragraph"},t,0)}static getEditorId(e){const t=e.closest(`.${a.classNames.editor.container}`);return t?t.id:null}static handleKeydown(t){const n=t,o=t.currentTarget,i=o.closest(`.${a.classNames.block.container}`),r=e.getEditorId(i);if(!r)return;const s=e.getBlockIndex(r,i.getAttribute("data-id")),l=n.metaKey||n.ctrlKey;if(n.shiftKey)switch(n.key){case"ArrowUp":t.preventDefault(),t.stopPropagation(),s>0&&e.moveBlock(r,s,s-1);break;case"ArrowDown":t.preventDefault(),t.stopPropagation();const n=e.getBlocks(r);n&&s<n.length-1&&e.moveBlock(r,s,s+1)}else if(l)switch(n.key){case"Delete":case"Backspace":t.preventDefault(),t.stopPropagation(),e.removeBlock(r,s)}else if("Enter"===n.key)n.preventDefault(),n.stopPropagation(),e.insertBlock({data:{html:""},type:"paragraph"},r,s+1);else if("Backspace"===n.key){if(!M(o.innerHTML))return;n.preventDefault(),n.stopPropagation(),e.removeBlock(r,s)}else{e.ensureActiveBlock(r);const a=e.getBlocks(r);switch(n.key){case"ArrowUp":if(t.preventDefault(),t.stopPropagation(),s>0){const t=a[s-1];t&&e.focusBlock(t)}return;case"ArrowDown":if(t.preventDefault(),t.stopPropagation(),s<a.length-1){const t=a[s+1];t&&e.focusBlock(t)}return}}}static handleInput(t){e.saveBlockData(t.currentTarget)}static ensureActiveBlock(t){const n=e.getBlocks(t);let o=e.getActiveBlock(t);if(!o){const t=document.activeElement;if(!t)return;const i=t.closest(`.${a.classNames.block.container}`);if(i)o=i,e.setActiveBlock(o);else{if(0===n.length)return;o=n[0],e.setActiveBlock(o)}}}static saveBlockData(t){const n=t.closest(`.${a.classNames.block.container}`),o=e.getEditorId(n);if(!o)return;const i=n.getAttribute("data-id");l.getState().updateBlockData(o,e.getBlockIndex(o,i),e.getBlockData(i).data)}static updateBlockData(t,n,o){const i=e.getBlock(t);if(i){const t=i.querySelector(`.${a.classNames.block.content}`);t&&(t.innerHTML="");const r=e.renderTool(i.getAttribute("data-tool"),n,o);r&&t.appendChild(r)}l.getState().updateBlockData(o,e.getBlockIndex(o,t),n)}static destroy(t){if(!document.getElementById(t))return;const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[]),Qi.forEach(e=>e.input.destroy(t));for(const a of e.getBlocks(t))a.remove()}},lr=class e{static{this.eventListenersMap={}}static addEventListener(t,n,a,o){n.addEventListener(a,o);const i=e.eventListenersMap[t]||[];i.push({element:n,event:a,handler:o}),e.eventListenersMap[t]=i}static create(t){const n=l.getState().getInstance(t);if(!n)return console.error("ActionBar::create: Instance not found for containerId:",t);a.injectStyles("clepit-action-bar-styles","\n/* View Toggle */\n.clepit-action-bar {\n position: relative;\n z-index: 1000;\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: -14px; /* Position buttons so exactly half is inside and half outside */\n pointer-events: none;\n padding: 0 100px;\n}\n\n.clepit-action-bar-group {\n display: flex;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n overflow: hidden;\n padding: 4px;\n gap: 4px;\n}\n\n.clepit-action-bar-button {\n width: 24px;\n height: 24px;\n border: none;\n border-radius: 4px;\n background: transparent;\n color: var(--clepit-text-muted);\n font-size: 14px;\n font-weight: bold;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s ease;\n pointer-events: auto;\n}\n\n.clepit-action-bar-button:first-child {\n border-radius: 4px;\n}\n\n.clepit-action-bar-button:last-child {\n border-radius: 4px;\n}\n\n.clepit-action-bar-button:not(:first-child):not(:last-child) {\n border-radius: 4px;\n}\n\n.clepit-action-bar-button:hover {\n background: var(--clepit-toolbar-button-hover-bg, var(--clepit-selection-bg));\n color: var(--clepit-toolbar-button-hover-color, var(--clepit-primary));\n transform: scale(1.05);\n}\n\n.clepit-action-bar-button:active {\n transform: scale(0.95);\n}\n\n.clepit-action-bar-button.active {\n background-color: var(--clepit-primary-bg);\n color: var(--clepit-primary);\n font-weight: bold;\n}\n\n/* Action Buttons */\n.clepit-view-actions {\n display: flex;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n overflow: hidden;\n padding: 4px;\n gap: 4px;\n}\n\n.clepit-view-action-button {\n width: 24px;\n height: 24px;\n border: none;\n border-radius: 4px;\n background: transparent;\n color: var(--clepit-text-muted);\n font-size: 14px;\n font-weight: bold;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s ease;\n pointer-events: auto;\n}\n\n.clepit-view-action-button:first-child {\n border-radius: 4px;\n}\n\n.clepit-view-action-button:last-child {\n border-radius: 4px;\n}\n\n.clepit-view-action-button:not(:first-child):not(:last-child) {\n border-radius: 4px;\n}\n\n.clepit-view-action-button:hover {\n background: var(--clepit-toolbar-button-hover-bg, var(--clepit-selection-bg));\n color: var(--clepit-toolbar-button-hover-color, var(--clepit-primary));\n transform: scale(1.05);\n}\n\n.clepit-view-action-button:active {\n transform: scale(0.95);\n}\n\n/* Copy button feedback animation */\n.clepit-view-action-button--copy-feedback {\n transform: scale(0.95) !important;\n background-color: var(--clepit-success) !important;\n color: var(--clepit-bg) !important;\n}\n");const o=document.getElementById(t);if(!o)return;const i=n.config.styles?.controls?.group,r=n.config.classNames?.controls?.group,s=n.config.styles?.controls?.button,c=n.config.classNames?.controls?.button,p=n.config.styles?.tooltips,d=n.config.classNames?.tooltips,u=B("div",a.classNames.actionBar.container);e.createButtonGroup(o,u,{buttonClassNames:c,buttonStyles:s,currentView:n.currentView,groupClassNames:r,groupStyles:i,tooltipClassNames:d,tooltipStyles:p}),o.insertBefore(u,o.firstChild)}static createButtonGroup(t,n,o){const i=B("div",a.classNames.actionBar.group);a.applyStyling(i,{classNames:o.groupClassNames,styles:o.groupStyles});const r=B("button",a.classNames.actionBar.button,{"data-testid":"action-bar-edit-button","data-view":"edit",id:$(t.id,a.idSuffixes.actionBar.editButton),type:"button"});r.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/></svg>',a.applyStyling(r,{classNames:o.buttonClassNames,styles:o.buttonStyles});const s=B("button",a.classNames.actionBar.button,{"data-testid":"action-bar-preview-button","data-view":"preview",id:$(t.id,a.idSuffixes.actionBar.previewButton),type:"button"});s.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>',a.applyStyling(s,{classNames:o.buttonClassNames,styles:o.buttonStyles});const l=B("button",a.classNames.actionBar.button,{"data-testid":"action-bar-json-button","data-view":"json",id:$(t.id,a.idSuffixes.actionBar.jsonButton),type:"button"});l.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14,2 14,8 20,8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10,9 9,9 8,9"/></svg>',a.applyStyling(l,{classNames:o.buttonClassNames,styles:o.buttonStyles}),"edit"===o.currentView?r.classList.add("active"):"preview"===o.currentView?s.classList.add("active"):"json"===o.currentView&&l.classList.add("active"),e.addEventListener(t.id,r,"click",e.handleViewChange),e.addEventListener(t.id,s,"click",e.handleViewChange),e.addEventListener(t.id,l,"click",e.handleViewChange),i.appendChild(r),i.appendChild(s),i.appendChild(l),n.appendChild(i),J(r,"Edit Mode","above",o.tooltipClassNames,o.tooltipStyles),J(s,"Preview Mode","above",o.tooltipClassNames,o.tooltipStyles),J(l,"JSON Output","above",o.tooltipClassNames,o.tooltipStyles);const c=B("div",a.classNames.actionBar.action);a.applyStyling(c,{classNames:o.groupClassNames,styles:o.groupStyles});const p=B("button",a.classNames.actionBar.actionButton,{"data-testid":"view-copy-button",id:$(t.id,a.idSuffixes.actionBar.copyButton),type:"button"});p.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>',a.applyStyling(p,{classNames:o.buttonClassNames,styles:o.buttonStyles});const d=B("button",a.classNames.actionBar.actionButton,{"data-testid":"view-download-button",id:$(t.id,a.idSuffixes.actionBar.downloadButton),type:"button"});d.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7,10 12,15 17,10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>',a.applyStyling(d,{classNames:o.buttonClassNames,styles:o.buttonStyles});const u=B("button",a.classNames.actionBar.actionButton,{"data-testid":"view-clear-button",id:$(t.id,a.idSuffixes.actionBar.clearButton),type:"button"});u.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>',a.applyStyling(u,{classNames:o.buttonClassNames,styles:o.buttonStyles}),e.addEventListener(t.id,p,"click",e.handleCopyJson),e.addEventListener(t.id,d,"click",e.handleDownloadJson),e.addEventListener(t.id,u,"click",e.handleClearEditor),c.appendChild(p),c.appendChild(d),c.appendChild(u),n.appendChild(c),J(p,"Copy JSON to Clipboard","above",o.tooltipClassNames,o.tooltipStyles),J(d,"Download JSON File","above",o.tooltipClassNames,o.tooltipStyles),J(u,"Clear Editor","above",o.tooltipClassNames,o.tooltipStyles)}static getCurrentView(e){const t=document.getElementById(e);if(!t)return console.error("ActionBar::getCurrentView: Container not found for containerId:",e),null;const n=t.querySelector(`.${a.classNames.actionBar.group}`);if(!n)return console.error("ActionBar::getCurrentView: View toggle group not found for container:",t.id),null;const o=n.querySelector(".active");return o?o.getAttribute("data-view"):(console.error("ActionBar::getCurrentView: Active button not found for container:",t.id),null)}static updateButtonStates(e,t){const n=document.getElementById(e);if(!n)return;const o=n.querySelector(`.${a.classNames.actionBar.container}`);o&&o.querySelectorAll(`#${$(e,a.idSuffixes.actionBar.editButton)}, #${$(e,a.idSuffixes.actionBar.previewButton)}, #${$(e,a.idSuffixes.actionBar.jsonButton)}`).forEach(e=>{e.getAttribute("data-view")===t?e.classList.add("active"):e.classList.remove("active")})}static handleViewChange(t){const n=t.currentTarget,a=sr.getEditorId(n);if(!a)return;const o=n.getAttribute("data-view");o&&(l.getState().setCurrentView(a,o),e.updateButtonStates(a,o))}static handleCopyJson(e){const t=e.currentTarget,n=sr.getEditorId(t);if(!n)return;const o=l.getState().getInstance(n);o&&(navigator.clipboard.writeText(JSON.stringify(o.data,null,2)),t.classList.add(a.classNames.actionBar.copyFeedback),setTimeout(()=>t.classList.remove(a.classNames.actionBar.copyFeedback),200))}static handleClearEditor(e){const t=e.currentTarget,n=sr.getEditorId(t);n&&sr.resetBlocks(n)}static handleDownloadJson(e){const t=e.currentTarget,n=sr.getEditorId(t);if(!n)return;const a=sr.getBlocks(n).map(e=>sr.getBlockData(e.getAttribute("data-id"))),o=new Blob([JSON.stringify(a,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${n}--content.json`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(i)}static destroy(e){const t=document.getElementById(e);if(!t)return;const n=t.querySelector(`.${a.classNames.actionBar.container}`);n&&n.remove()}},cr=new Set(["alert.html","audio.alt","audio.caption","checklist.items","header.html","image.alt","image.caption","list.items","paragraph.html","quote.html","table.caption","table.data","video.alt","video.caption"]),pr=(e,t)=>cr.has(`${e}.${t}`),dr=new Set(["checklist.items","list.items","table.data"]),ur=(e,t)=>dr.has(`${e}.${t}`),mr=(e,t,n,a)=>{if(!Array.isArray(t))return t;let o=!1;const i=e=>{const t=((e,t,n)=>{const a=gr(e,t,n);return null===a?e:a.value})(e,n,a);return t!==e&&(o=!0),t},r=t.map(t=>{if("table"===e)return Array.isArray(t)?t.map(i):t;if("checklist"===e){if("object"!=typeof t||null===t)return t;const e=t,n=i(e.text);return n===e.text?t:{...e,text:n}}return i(t)});return o?r:t},hr=(e,t,n,a)=>{let o=!1;const i={};for(const[r,s]of Object.entries(t)){if(ur(e,r)){const t=mr(e,s,n,a);i[r]=t,t!==s&&(o=!0);continue}if(!pr(e,r)){i[r]=s;continue}const t=gr(s,n,a);null!==t?(i[r]=t.value,t.value!==s&&(o=!0)):i[r]=s}return o?i:t},gr=(e,t,n)=>{if(void 0===e)return null;if(!(e=>"object"==typeof e&&null!==e&&!Array.isArray(e))(e))return{isFallback:t!==n,locale:n,value:e};const a=e[t];if(void 0!==a)return{isFallback:!1,locale:t,value:a};const o=e[n];if(void 0!==o)return{isFallback:!0,locale:n,value:o};const i=Object.keys(e).sort()[0];return void 0===i?null:{isFallback:!0,locale:i,value:e[i]}},br=`\n/* Editor Container */\n.${a.classNames.editor.container} {\n position: relative;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n line-height: 1.6;\n color: var(--clepit-text);\n padding: 20px; /* Normal padding - no extra left padding needed */\n outline: none;\n box-sizing: border-box;\n width: 100%;\n}\n\n.${a.classNames.editor.container}:focus {\n outline: none;\n}\n\n.${a.classNames.editor.container}[data-readonly="true"] {\n background: var(--clepit-surface);\n color: var(--clepit-text-muted);\n cursor: not-allowed;\n}\n\n/* Editor Content Container */\n.${a.classNames.editor.content} {\n border: 1px solid var(--clepit-border);\n border-radius: 4px;\n overflow-y: auto;\n padding: 16px 24px; /* Increased horizontal padding for better preview content spacing */\n background: var(--clepit-bg);\n height: 100%;\n max-height: var(--clepit-max-height, 410px);\n min-height: var(--clepit-min-height, 200px);\n}\n\n/* JSON Output */\n.${a.classNames.editor.jsonOutput} {\n margin: 0;\n padding: 16px;\n font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;\n font-size: 13px;\n line-height: 1.4;\n color: var(--clepit-text); /* default readonly is black */\n overflow-x: auto;\n white-space: pre-wrap;\n word-wrap: break-word;\n outline: none;\n min-height: 100%;\n}\n\n.${a.classNames.editor.jsonOutput}:focus {\n outline: none;\n}\n\n/* Editable (allowed) -> green text */\n.${a.classNames.editor.jsonOutput}.clepit-json-editable {\n color: var(--clepit-success);\n}\n\n/* Invalid JSON -> red text */\n.${a.classNames.editor.jsonOutput}.clepit-json-error {\n color: var(--clepit-error);\n background-color: transparent;\n}\n\n.${a.classNames.editor.jsonEmpty} {\n padding: 16px;\n text-align: center;\n color: var(--clepit-text-muted);\n font-style: italic;\n}\n\n/* Responsive */\n@media (max-width: 768px) {\n /* Container and content each carried their own inset, so a phone spent 80px\n * of a ~400px editor on nested padding before a single character. */\n .${a.classNames.editor.container} {\n padding: 8px;\n }\n\n .${a.classNames.editor.content} {\n padding: 12px;\n }\n}\n`,fr=class{static render(e){const t=l.getState().getInstance(e);t&&(ne.create(e),a.injectStyles("clepit-block-manager-styles",'\n/* Blocks */\n.clepit-block {\n position: relative;\n margin: var(--block-margin-top, 8px) 0 var(--block-margin-bottom, 16px) 0;\n padding: 8px 0;\n padding-left: 54px;\n border-radius: 4px;\n transition: background-color 0.2s ease;\n display: flex;\n align-items: flex-start;\n gap: 6px;\n}\n\n.clepit-block:hover {\n background-color: var(--clepit-block-highlight-bg);\n}\n\n.clepit-block--active {\n background-color: var(--clepit-block-highlight-bg);\n}\n\n.clepit-block-content {\n outline: none;\n min-height: 1.2em;\n flex: 1;\n min-width: 0; /* Allow content to shrink */\n}\n\n/* Remove focus outline from editable elements */\n.clepit-block-content [contenteditable="true"] {\n outline: none;\n}\n\n/* Placeholder styles for all text elements */\n.clepit-block-content:empty::before {\n content: attr(data-placeholder);\n color: var(--clepit-text-subtle);\n pointer-events: none;\n font-style: italic;\n}\n\n/* Menu animation classes */\n.clepit-block-type-selector--visible {\n display: block;\n transform: translateY(0);\n}\n\n.clepit-block-type-selector--hidden {\n display: none;\n}\n\n/* Block Operations Menu */\n.clepit-block-operations-menu {\n position: absolute;\n top: 100%;\n left: 0;\n z-index: 1001;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n padding: 8px;\n min-width: 200px;\n margin-top: 4px;\n display: none;\n transition: transform 0.2s ease;\n}\n\n.clepit-block-operations-menu--visible {\n display: block;\n transform: translateY(0);\n}\n\n.clepit-block-operations-menu--hidden {\n display: none;\n}\n\n/* Block Type Selector */\n.clepit-block-type-selector {\n position: absolute;\n top: 100%;\n left: 0;\n z-index: 1001;\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n padding: 8px;\n min-width: 150px;\n margin-top: 4px;\n display: none;\n transition: transform 0.2s ease;\n}\n\n.clepit-block-type-selector--visible {\n display: block;\n transform: translateY(0);\n}\n\n.clepit-block-type-selector--hidden {\n display: none;\n}\n\n/* Default menu item styles - package doesn\'t care about theme */\n.clepit-menu-item {\n padding: 8px 12px;\n cursor: pointer;\n border-radius: 4px;\n transition: background-color 0.2s;\n display: flex;\n align-items: center;\n gap: 8px;\n}\n\n.clepit-menu-item .clepit-menu-icon {\n width: 16px;\n height: 16px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n font-size: 14px;\n}\n\n.clepit-menu-item:hover {\n background-color: var(--clepit-selection-bg);\n}\n\n.clepit-menu-item.active {\n background-color: var(--clepit-primary-bg);\n color: var(--clepit-primary);\n font-weight: bold;\n}\n\n.clepit-menu-item--danger {\n color: var(--clepit-error);\n}\n\n/* Block type menu items - match font size with operations menu */\n.clepit-block-type-item {\n font-size: 14px;\n}\n\n/* Default menu divider styles */\n.clepit-menu-divider {\n height: 1px;\n background: linear-gradient(to right, transparent, var(--clepit-border), transparent);\n margin: 8px 0;\n}\n\n/* Default menu arrow styles */\n.clepit-menu-arrow {\n margin-left: auto;\n font-size: 12px;\n color: var(--clepit-text-muted);\n}\n\n/* Input styles for block type selector */\n.clepit-block-type-selector input {\n width: 100%;\n padding: 8px 12px;\n border: 1px solid var(--clepit-input-border, var(--clepit-border));\n border-radius: 4px;\n font-size: 14px;\n margin-bottom: 8px;\n outline: none;\n transition: border-color 0.2s;\n background-color: var(--input-bg, var(--clepit-bg));\n color: var(--input-color, var(--clepit-text));\n}\n\n.clepit-block-type-selector input:focus {\n border-color: var(--clepit-primary);\n box-shadow: 0 0 0 2px var(--clepit-primary-bg);\n}\n\n.clepit-block-type-selector input::placeholder {\n color: var(--placeholder-color, var(--clepit-text-subtle));\n}\n\n.clepit-block-type-selector-items {\n max-height: 200px;\n overflow-y: auto;\n}\n\n.clepit-menu-icon {\n font-size: 14px;\n min-width: 20px;\n text-align: center;\n font-weight: bold;\n}\n\n.clepit-menu-shortcut {\n margin-left: auto;\n font-size: 9px;\n color: var(--clepit-text-muted);\n opacity: 0.7;\n}\n\n.clepit-menu-positioned {\n position: absolute;\n z-index: 1001;\n top: var(--menu-top, 0);\n left: var(--menu-left, 0);\n}\n\n/* The block menus are popovers in the top layer. Anchor positioning puts them\n * under the block toolbar without JavaScript measuring anything.\n *\n * Guarded: anchor positioning is Baseline 2026 (Chrome 125+, Firefox 132+,\n * Safari 18.2+), roughly 91% of traffic. Browsers without it get the popover\'s\n * default centred placement rather than a second JS positioning path — the menu\n * stays usable, just not adjacent to its button. */\n.clepit-block-type-selector:popover-open,\n.clepit-block-operations-menu:popover-open {\n /* The base menu rules above still say display:none from the pre-popover\n * mechanism, and an author rule outranks the UA\'s popover reveal. Without\n * an explicit display here every menu opens into the top layer invisible. */\n display: block;\n margin: 0;\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n background: var(--clepit-bg);\n padding: 8px;\n overflow: visible;\n}\n\n.clepit-convert-submenu:popover-open {\n display: block;\n}\n\n@supports (anchor-name: --a) {\n .clepit-block-type-selector:popover-open,\n .clepit-block-operations-menu:popover-open {\n position-anchor: --clepit-block-toolbar;\n position-area: bottom span-inline-end;\n margin-block-start: 5px;\n }\n}\n\n@supports (position-try-fallbacks: flip-block) {\n .clepit-block-type-selector:popover-open,\n .clepit-block-operations-menu:popover-open {\n position-try-fallbacks: flip-block;\n }\n}\n\n/* Convert Submenu */\n@supports (anchor-name: --a) {\n .clepit-convert-submenu:popover-open {\n position: fixed;\n position-area: inline-end span-block-end;\n margin: 0 0 0 4px;\n inset: auto;\n }\n\n .clepit-convert-submenu:popover-open {\n position-try-fallbacks: flip-inline;\n }\n}\n\n.clepit-convert-submenu {\n position: absolute;\n top: var(--submenu-top, 0);\n left: var(--submenu-left, 100%);\n z-index: var(--submenu-z-index, 1002);\n background: var(--clepit-bg);\n border: 1px solid var(--clepit-border);\n border-radius: 6px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n padding: 8px;\n min-width: 140px;\n margin-left: 4px;\n display: none;\n transition: transform 0.2s ease;\n}\n\n.clepit-convert-submenu--visible {\n display: block;\n opacity: 1;\n transform: translateX(0);\n}\n\n.clepit-convert-submenu--hidden {\n display: none;\n opacity: 0;\n transform: translateX(-10px);\n}\n\n/* Input styles for convert submenu */\n.clepit-convert-submenu input {\n width: 100%;\n padding: 6px 8px;\n border: 1px solid var(--clepit-input-border, var(--clepit-border));\n border-radius: 4px;\n font-size: 12px;\n outline: none;\n background-color: var(--input-bg, var(--clepit-bg));\n color: var(--input-color, var(--clepit-text));\n}\n\n.clepit-convert-submenu input:focus {\n border-color: var(--clepit-input-focus-border, var(--clepit-primary));\n box-shadow: 0 0 0 2px var(--clepit-input-focus-shadow, var(--clepit-primary-bg));\n}\n\n.clepit-convert-submenu input::placeholder {\n color: var(--clepit-input-placeholder, var(--clepit-text-subtle));\n}\n\n.clepit-convert-submenu-items {\n max-height: 200px;\n overflow-y: auto;\n}\n\n.clepit-block-operation-item {\n padding: 8px 12px;\n cursor: pointer;\n border-radius: 4px;\n transition: background-color 0.2s;\n font-size: 14px;\n}\n\n.clepit-block-operation-item:hover {\n background-color: var(--clepit-hover-bg, var(--clepit-selection-bg));\n}\n\n/* Input styles for operations menu */\n.clepit-block-operations-menu input {\n width: 100%;\n padding: 8px 12px;\n border: 1px solid var(--clepit-input-border, var(--clepit-border));\n border-radius: 4px;\n font-size: 14px;\n margin-bottom: 8px;\n outline: none;\n transition: border-color 0.2s;\n background-color: var(--input-bg, var(--clepit-bg));\n color: var(--input-color, var(--clepit-text));\n}\n\n.clepit-block-operations-menu input:focus {\n border-color: var(--clepit-primary);\n box-shadow: 0 0 0 2px var(--clepit-primary-bg);\n}\n\n.clepit-block-operations-menu input::placeholder {\n color: var(--placeholder-color, var(--clepit-text-subtle));\n}\n\n.clepit-block-operations-menu-items {\n max-height: 200px;\n overflow-y: auto;\n}\n\n.clepit-block-operation-item[data-operation="delete"] {\n color: var(--clepit-error);\n}\n\n/* Convert submenu items */\n.clepit-convert-option-item {\n padding: 8px 12px;\n cursor: pointer;\n border-radius: 4px;\n transition: background-color 0.2s;\n font-size: 14px;\n}\n\n.clepit-convert-option-item:hover {\n background-color: var(--clepit-hover-bg, var(--clepit-selection-bg));\n}\n\n/* Indentation */\n.clepit-block[data-indent="1"] .clepit-block-content {\n margin-left: 20px;\n}\n\n.clepit-block[data-indent="2"] .clepit-block-content {\n margin-left: 40px;\n}\n\n.clepit-block[data-indent="3"] .clepit-block-content {\n margin-left: 60px;\n}\n\n/* Responsive */\n@media (max-width: 768px) {\n /* The 54px gutter exists to hold the block toolbar, which is only ever\n * displayed on the active block. On a phone that reserved a seventh of the\n * editor\'s width on every idle block at once, pushing the text into a narrow\n * column with empty space either side. Give the width back and let the\n * gutter open only under the block whose toolbar is actually showing. */\n /* No transition on padding-left. The block element is re-created as you\n * interact with it, so an animated gutter restarts from 0 every time and\n * never reaches its end value — the toolbar would sit on top of the text. */\n .clepit-block {\n padding-left: 0;\n }\n\n .clepit-block--active,\n .clepit-block:focus-within,\n .clepit-block:has(.clepit-block-toolbar--visible) {\n padding-left: 54px;\n }\n}\n'),sr.renderBlocks(t.data.blocks,e))}},yr=class e{static render(t){const n=l.getState().getInstance(t);if(!n)return;const o=document.getElementById(n.contentId);if(o)if(o.innerHTML="",n.data&&n.data.blocks&&n.data.blocks.length>0){const t=a.createStyledElement("pre",a.classNames.editor.jsonOutput);t.textContent=JSON.stringify(n.data,null,2),t.setAttribute("data-testid","json-editable-textarea"),n.config.allowJsonViewEditing&&(t.setAttribute("contenteditable","true"),t.classList.add(a.classNames.editor.jsonEditable),setTimeout(()=>t.focus(),0),e.addEventListeners(t)),o.appendChild(t)}else{const e=a.createStyledElement("div",a.classNames.editor.jsonEmpty);e.textContent="No content to display",o.appendChild(e)}}static addEventListeners(t){t.addEventListener("input",e.handleJsonInput),t.addEventListener("blur",e.validateAndUpdateJson),t.addEventListener("keydown",e.validateAndUpdateJson)}static removeEventListeners(t){t.removeEventListener("input",e.handleJsonInput),t.removeEventListener("blur",e.validateAndUpdateJson),t.removeEventListener("keydown",e.validateAndUpdateJson)}static handleJsonInput(e){const t=e.target,n=t.textContent||"",o=sr.getEditorId(t);if(o)try{const e=JSON.parse(n);if("object"==typeof e&&null!==e){e.blocks&&Array.isArray(e.blocks)||(e.blocks=[]);const t=l.getState().getInstance(o);if(t){const n=document.querySelector(`#${t.contentId} .${a.classNames.editor.jsonOutput}`);n&&(n.classList.remove(a.classNames.editor.jsonError),t.config.allowJsonViewEditing&&n.classList.add("clepit-json-editable"));const i=t.currentView;l.getState().setData(o,e),"json"===i&&l.getState().setCurrentView(o,"json"),console.log("Store updated successfully")}}}catch{const e=l.getState().getInstance(o);if(e){const t=document.querySelector(`#${e.contentId} .${a.classNames.editor.jsonOutput}`);t&&(t.classList.add("clepit-json-error"),t.classList.remove("clepit-json-editable"))}}}static validateAndUpdateJson(e){const t=e.target,n=t.textContent||"",o=sr.getEditorId(t);if(!o)return;const i=l.getState().getInstance(o);if(i)try{const e=JSON.parse(n);if("object"!=typeof e||null===e)throw new Error("Invalid JSON structure");{e.blocks&&Array.isArray(e.blocks)||(e.blocks=[]);try{ne.hide(o),rr.hide(o)}catch{}const t=i.currentView;l.getState().setData(o,e),"json"===t&&l.getState().setCurrentView(o,"json");const n=document.querySelector(`#${i.contentId} .${a.classNames.editor.jsonOutput}`);n&&(n.classList.remove("clepit-json-error"),i.config.allowJsonViewEditing?n.classList.add("clepit-json-editable"):n.classList.remove("clepit-json-editable")),i.config.onChange&&i.config.onChange(e)}}catch{const e=document.querySelector(`#${i.contentId} .${a.classNames.editor.jsonOutput}`);e&&(e.classList.add("clepit-json-error"),e.classList.remove("clepit-json-editable"))}}static destroy(t){const n=l.getState().getInstance(t);if(!n)return;const o=document.querySelector(`#${n.contentId} .${a.classNames.editor.jsonOutput}`);o&&e.removeEventListeners(o)}},vr="clepit-theme-styles",xr=".clepit-editor, .clepit-renderer-content, body[data-clepit-theme]",kr=`@layer clepit.reset, clepit.tokens, clepit.blocks, clepit.overrides;\n\n${ir=e,Object.keys(t).map(e=>`@property ${t[e]} {\n syntax: '<color>';\n inherits: true;\n initial-value: ${ir[e]};\n}`).join("\n\n")}\n\n@layer clepit.tokens {\n${n(e,{bg:"#161b22",blockHighlightBg:"rgba(0, 0, 0, 0.25)",border:"rgba(240, 246, 252, 0.1)",borderSubtle:"rgba(240, 246, 252, 0.06)",codeBg:"#1e242c",codeBorder:"rgba(240, 246, 252, 0.10)",codeComment:"rgba(240, 246, 252, 0.42)",codeFunction:"#d2a8ff",codeGutter:"rgba(240, 246, 252, 0.42)",codeKeyword:"#ff7b72",codeNumber:"#79c0ff",codePunctuation:"rgba(240, 246, 252, 0.62)",codeSelectionBg:"rgba(124, 124, 255, 0.18)",codeString:"#7ee787",codeText:"rgba(240, 246, 252, 0.92)",codeType:"#ffa657",error:"#f87171",errorBg:"rgba(248, 113, 113, 0.12)",info:"#60a5fa",infoBg:"rgba(96, 165, 250, 0.12)",marker:"rgba(255, 224, 71, 0.28)",primary:"#7c7cff",primaryBg:"rgba(124, 124, 255, 0.14)",primaryHover:"#9494ff",selectionBg:"rgba(124, 124, 255, 0.18)",success:"#4ade80",successBg:"rgba(74, 222, 128, 0.12)",surface:"#1c222a",surface2:"#222a33",text:"rgba(240, 246, 252, 0.92)",textMuted:"rgba(240, 246, 252, 0.62)",textSubtle:"rgba(240, 246, 252, 0.42)",warning:"#fbbf24",warningBg:"rgba(251, 191, 36, 0.12)"},xr)}\n\n${xr} {\n color-scheme: light;\n}\n\n.clepit-editor[data-clepit-theme='auto'], .clepit-renderer-content[data-clepit-theme='auto'], body[data-clepit-theme='auto'] {\n color-scheme: light dark;\n}\n\n.clepit-editor[data-clepit-theme='dark'], .clepit-renderer-content[data-clepit-theme='dark'], body[data-clepit-theme='dark'] {\n color-scheme: dark;\n}\n\n.clepit-editor[data-clepit-theme='light'], .clepit-renderer-content[data-clepit-theme='light'], body[data-clepit-theme='light'] {\n color-scheme: light;\n}\n}\n\n@layer clepit.blocks {\n[data-clepit-block-id]:target {\n background: var(--clepit-block-highlight-bg);\n border-radius: 6px;\n scroll-margin-top: 24px;\n}\n}\n`,wr=class e{static render(t){const n=document.getElementById(t.containerId);if(!n)throw new Error(`Container element with ID '${t.containerId}' not found`);return a.injectStyles(vr,kr),a.injectStyles(O,H),n.classList.add(a.classNames.renderer.content),a.registerEditor(t.containerId,t.theme??"auto",t.themeOverrides),n.innerHTML="",t.data?.blocks&&Array.isArray(t.data.blocks)?(t.data.blocks.forEach((a,o)=>{const i=e.renderBlock(e.localize(a,t),o,t);i&&n.appendChild(i)}),n):n}static localize(e,t){if(!t.locale)return e;const n=hr(e.type,e.data,t.locale,t.defaultLocale??t.locale);return n===e.data?e:{...e,data:n}}static renderBlock(e,t,n){const o=B("div",a.classNames.block.output);o.setAttribute("data-block-type",e.type),o.setAttribute("data-block-index",t.toString()),e.tunes&&Object.entries(e.tunes).forEach(([e,t])=>{o.setAttribute(`data-tune-${e}`,String(t))});const i=n.styles?.[e.type],r=n.classNames?.[e.type];let s,l,c,p=n.configs?.[e.type];if("paragraph"===e.type&&n.editorClassNames?.tooltips&&(p={...p,tooltipClassNames:n.editorClassNames.tooltips}),p?.margins&&(s=p.margins.top,l=p.margins.bottom),void 0===s&&void 0!==n.margins?.top&&(s=n.margins.top),void 0===l&&void 0!==n.margins?.bottom&&(l=n.margins.bottom),void 0!==s){const e=parseFloat(o.style.marginTop||"0")||0;o.style.marginTop=`${e+s}px`}if(void 0!==l){const e=parseFloat(o.style.marginBottom||"0")||0;o.style.marginBottom=`${e+l}px`}switch(e.type){case"alert":c=ke.render(e.data,p,i,r);break;case"audio":c=Ne.render(e.data,p,i,r);break;case"code":c=Et.render(e.data,p,i,r);break;case"collapsible":c=ri.render(e.data,p,i,r);break;case"columns":c=zt.render(e.data,p,i,r);break;case"date":c=Vt.render(e.data,p,i,r);break;case"delimiter":c=Kt.render(e.data,p,i,r);break;case"collection":c=qt.render(e.data,p,i,r);break;case"updates":c=Yo.render(e.data,p,i,r);break;case"glance":c=fn.render(e.data,p,i,r);break;case"embed":c=cn.render(e.data,p,i,r);break;case"sketch":c=fa.render(e.data,p,i,r);break;case"latex":c=Ko.render(e.data,p,i,r);break;case"mermaid":c=Go.render(e.data,p,i,r);break;case"openapi":c=aa.render(e.data,p,i,r);break;case"doc_card":c=Zt.render(e.data,p,i,r);break;case"file":c=hn.render(e.data,p,i,r);break;case"header":c=xn.render(e.data,p,i,r);break;case"image":c=En.render(e.data,p,i,r);break;case"list":c=An.render(e.data,p,i,r);break;case"checklist":c=Me.render(e.data,p,i,r);break;case"paragraph":c=ra.render(e.data,p,i,r);break;case"quote":c=pa.render(e.data,p,i,r);break;case"table":c=Ca.render(e.data,p,i,r);break;case"toc":c=La.render(e.data,{...p,documentBlocks:n.data?.blocks??[]},i,r);break;case"video":c=ni.render(e.data,p,i,r);break;default:c=null}return c?(o.appendChild(c),X.initializeElements(o,{classNames:n.classNames?.tooltip,styles:n.styles?.tooltip}),o):null}},Cr=class{static render(e){const t=l.getState().getInstance(e);t&&wr.render({classNames:t.config.classNames?.blocks,containerId:t.contentId,data:t.data,editorClassNames:t.config.classNames,margins:t.config.margins,styles:t.config.styles?.blocks})}},Er=e=>e.replace(/["\\]/g,"\\$&"),Sr=e=>e.flatMap(e=>"collapsible"===e.type?[e,...Sr(e.data.children??[])]:"columns"===e.type?[e,...Sr(e.data.columns?.flat()??[])]:[e]),Nr=new Set(["strong","b","em","i","u","s","del","mark","code","a","span"]),Ar=new Set(["href","target","data-tooltip","data-status","data-status-variant","data-user-id","data-page-id","class"]),Lr=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),Br=/([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g,$r=e=>{const t=new Map;Br.lastIndex=0;let n=Br.exec(e);for(;null!==n;)t.set(n[1].toLowerCase(),n[2]??n[3]??n[4]??""),n=Br.exec(e);return t},Mr=e=>{const t=e.trim().toLowerCase().replace(/[\x00-\x20]/g,"");return!t.startsWith("javascript:")&&!t.startsWith("data:")&&!t.startsWith("vbscript:")},Ir=e=>{if(!e)return"";const t=[],n=[];for(const a of(e=>{const t=[],n=/<\/?([a-zA-Z][a-zA-Z0-9-]*)((?:[^>"']|"[^"]*"|'[^']*')*)>/g;let a=0,o=n.exec(e);for(;null!==o;){o.index>a&&t.push({type:"text",value:e.slice(a,o.index)});const i=o[1].toLowerCase();o[0].startsWith("</")?t.push({tag:i,type:"close"}):t.push({attributes:$r(o[2]??""),selfClosing:(o[2]??"").trimEnd().endsWith("/"),tag:i,type:"open"}),a=o.index+o[0].length,o=n.exec(e)}return a<e.length&&t.push({type:"text",value:e.slice(a)}),t})(e)){if("text"===a.type){t.push(a.value);continue}if("close"===a.type){if(!Nr.has(a.tag))continue;const e=n.lastIndexOf(a.tag);if(-1===e)continue;t.push(`</${a.tag}>`),n.splice(e,1);continue}if(!Nr.has(a.tag))continue;const e=[];for(const[t,n]of a.attributes)Ar.has(t)&&("href"!==t||Mr(n))&&e.push(`${t}="${ge(n)}"`);"a"===a.tag&&e.push('target="_blank"','rel="noopener noreferrer"'),t.push(`<${[a.tag,...e].join(" ")}>`),a.selfClosing||Lr.has(a.tag)||n.push(a.tag)}for(const a of[...n].reverse())t.push(`</${a}>`);return t.join("")},Tr=()=>[kr,ce,Ee,Be,De,bt(),Lt,Tt,jt,Pt,Ut,Xt,en,un,gn,yn,wn,Sn,Ln,oa,la,ma,va,Na,Ma,Zo,ei].join("\n"),qr=(e,t)=>{const n=fe(Ir),a={...t,documentBlocks:t?.documentBlocks??e};return e.map(e=>ai(e,n,a)).filter(e=>null!==e).map(e=>ye(e)).join("\n")};exports.Editor=class e{static create(t){return e.destroy(t.containerId),e.initialize(t),lr.create(t.containerId),e.render(t.containerId),le.addListeners(t.containerId),l.getState().setIsReady(t.containerId,!0),l.subscribe(e=>e.instances,(n,a)=>{const o=n[t.containerId];if(!o)return;const i=a[t.containerId];i&&o.currentView!==i.currentView&&e.render(t.containerId)}),{blocks:{convert:(e,n)=>sr.convertBlock(e,n,t.containerId),count:()=>sr.getBlocks(t.containerId).length,get:e=>sr.getBlock(e)?sr.getBlockData(e):null,getAll:()=>sr.getBlocks(t.containerId).map(e=>sr.getBlockData(e.getAttribute("data-id"))),insert:(e,n,a)=>sr.insertBlock({data:n,id:Math.random().toString(36).substring(2,11),type:e},t.containerId,a),move:(e,n)=>sr.moveBlock(t.containerId,e,n),remove:e=>sr.removeBlock(t.containerId,e),update:(e,n)=>sr.updateBlockData(e,n,t.containerId)},blur:()=>{const e=document.activeElement;e&&document.getElementById(t.containerId)?.contains(e)&&e.blur()},data:{clear:()=>{l.getState().clearData(t.containerId),sr.destroy(t.containerId)},clearContent:()=>sr.destroy(t.containerId),clearStorage:()=>l.getState().clearData(t.containerId),extract:()=>sr.extractData(t.containerId),set:e=>sr.setBlocks(e.blocks,t.containerId)},destroy:()=>e.destroy(t.containerId),focus:()=>{const e=sr.getBlocks(t.containerId)[0];e&&sr.focusBlock(e)},selection:{clear:()=>window.getSelection()?.removeAllRanges(),get:()=>window.getSelection(),set:e=>{const t=window.getSelection();t&&(t.removeAllRanges(),t.addRange(e.getRangeAt(0)))}},ui:{hideBlockMenu:()=>rr.hide(t.containerId),hideToolbar:()=>ne.hide(t.containerId),showBlockMenu:e=>rr.show(t.containerId,e),showToolbar:(e,n)=>ne.show(t.containerId,e,n)},view:{getCurrentView:e=>l.getState().getCurrentView(e),switchView:(e,t)=>l.getState().setCurrentView(e,t)}}}static initialize(t){console.info("Editor::initialize: Creating editor instance for containerId:",t.containerId);const n=document.getElementById(t.containerId);if(!n)throw`Unable to find container with ID ${t.containerId}`;a.injectStyles(vr,kr),a.injectStyles("clepit-editor-container-styles",br),a.injectStyles(S,N),a.injectStyles(W,K),a.injectStyles(_,j);const o={allowJsonViewEditing:!1,initialView:"edit",maxHeight:0,minHeight:300,placeholder:"Start writing...",...t};n.className=a.classNames.editor.container,n.setAttribute("contenteditable","false"),a.registerEditor(t.containerId,o.theme??"auto",o.themeOverrides),o.minHeight&&n.style.setProperty("--clepit-min-height",`${o.minHeight}px`),o.maxHeight&&n.style.setProperty("--clepit-max-height",`${o.maxHeight}px`),a.applyStyles(n,o.styles?.container),a.applyClassNames(n,o.classNames?.container),o.margins&&(void 0!==o.margins.top&&n.style.setProperty("--block-margin-top",`${o.margins.top}px`),void 0!==o.margins.bottom&&n.style.setProperty("--block-margin-bottom",`${o.margins.bottom}px`));const i=`${o.containerId}-${a.idSuffixes.editorContent}`,r=B("div",a.classNames.editor.content);r.id=i,r.setAttribute("data-testid","editor-content-container"),r.setAttribute("data-container-id",t.containerId),a.applyStyles(r,o.styles?.editorContent),a.applyClassNames(r,o.classNames?.editorContent),n.appendChild(r),l.getState().addInstance(t.containerId,{config:o,contentId:i,currentView:o.initialView||"edit",data:e.localizeData(o.initialData,o),isReady:!1})}static localizeData(e,t){const n=e||{blocks:[],time:Date.now(),version:"1.0.0"},a=t.locale;if(!a)return n;const o=t.defaultLocale??a;return{...n,blocks:n.blocks.map(e=>{const n=e.data;for(const r of(e=>Array.from(cr).filter(t=>t.startsWith(`${e}.`)).map(t=>t.slice(e.length+1)).sort())(e.type)){const i=gr(n[r],a,o);i?.isFallback&&t.onLocaleFallback?.({blockId:e.id??"",field:r,requested:a,showing:i.locale})}const i=hr(e.type,n,a,o);return i===n?e:{...e,data:i}})}}static render(e){const t=l.getState().getInstance(e);if(!t)return;const n=document.getElementById(t.contentId);n&&(yr.destroy(e),n.innerHTML=""),"edit"===t.currentView?fr.render(e):"preview"===t.currentView?Cr.render(e):"json"===t.currentView&&yr.render(e),t.config.onReady&&t.config.onReady()}static destroy(e){le.removeListeners(e),lr.destroy(e),rr.destroy(e),ne.destroy(e),sr.destroy(e),a.unregisterEditor(e);const t=document.getElementById(e);t&&(t.innerHTML="")}},exports.Renderer=wr,exports.StyleManager=a,exports.activateBlocks=(e,t)=>{const n=[];for(const a of Sr(t)){if(!a.id)continue;if("code"!==a.type&&"openapi"!==a.type&&"table"!==a.type)continue;const t=e.querySelector(`[data-clepit-block-id="${Er(a.id)}"]`);if(!t||t.hasAttribute("data-clepit-activated"))continue;t.setAttribute("data-clepit-activated","");const o="code"===a.type?Et.activate(t,a.data):"openapi"===a.type?aa.activate(t):Ca.activate(t,a.data);n.push(()=>{o(),t.removeAttribute("data-clepit-activated")})}return()=>{for(const e of n)e()}},exports.domBacking=ue,exports.drawBlock=ai,exports.pageStylesheet=Tr,exports.parseOpenApi=Jn,exports.renderBlocks=qr,exports.renderPage=(e,t)=>{const n=he(e.title),a=['<meta charset="utf-8">','<meta name="viewport" content="width=device-width, initial-scale=1">',`<title>${n}</title>`,e.description?`<meta name="description" content="${ge(e.description)}">`:"",e.canonicalUrl?`<link rel="canonical" href="${ge(e.canonicalUrl)}">`:"",`<meta property="og:title" content="${ge(e.title)}">`,e.description?`<meta property="og:description" content="${ge(e.description)}">`:"",`<style>${Tr()}</style>`].filter(Boolean);return["<!doctype html>",`<html lang="${ge(e.locale??"en")}">`,`<head>${a.join("")}</head>`,"<body>",'<main class="clepit-public-page">',`<h1 class="clepit-public-page__title">${n}</h1>`,qr(e.blocks,{...t,anchorTargets:!0}),"</main>","</body>","</html>"].join("\n")},exports.renderToString=ye,exports.sanitizeHtmlWithoutDom=Ir,exports.stringBacking=fe,exports.toDomElement=ve,exports.tokensToLightDarkBlock=n;
2
2
  //# sourceMappingURL=index.js.map