@clepit/core 0.5.0-beta.341 → 0.5.0-beta.350

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.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{a as e,i as t,n,r as a,t as o}from"./highlight-C4NcTcIm.mjs";var i={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)"},r={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"},s=(e,t,n)=>{const a=[];for(const o of Object.keys(r)){const n=e[o],i=t[o];if(void 0===n&&void 0===i)continue;const s=r[o];void 0!==n&&void 0!==i?a.push(` ${s}: light-dark(${n}, ${i});`):a.push(` ${s}: ${n??i};`)}return 0===a.length?"":`${n} {\n${a.join("\n")}\n}`},l=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=/* @__PURE__ */new Map}static{this.themeSubscribers=/* @__PURE__ */new Set}static registerEditor(t,n,a){const o=document.getElementById(t);o&&(o.setAttribute("data-clepit-theme",n),o.setAttribute("data-clepit-instance",t)),e.themeRegistry.set(t,n),e.syncBodyThemeAttribute();const i=document.getElementById(`clepit-overrides-${t}`);if(i&&i.remove(),a){const n=s(a.light??{},a.dark??{},`[data-clepit-instance='${t}']`);n&&e.injectStyles(`clepit-overrides-${t}`,n)}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)}},c=e=>{let t;const n=/* @__PURE__ */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 p,d,u,m=(u?c(u):c)((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))((p=(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}))}}),d={name:"clepit-store",version:0},(e,t,n)=>{const a=d.version??0,o=d.storage??("undefined"==typeof localStorage?void 0:localStorage),i=d.merge??((e,t)=>Object.assign({},t,e)),r=p(e,t,n);if(o){try{const e=o.getItem(d.name);if(e){const t=JSON.parse(e),n=t.version===a?t.state:d.migrate?d.migrate(t.state,t.version??0):void 0;void 0!==n&&Object.assign(r,i(n,r))}}catch{}n.subscribe(e=>{try{o.setItem(d.name,JSON.stringify({state:d.partialize?d.partialize(e):e,version:a}))}catch{}})}return r}))));function h(){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 g(){return"mac"===h()?"⌘":"Ctrl"}function b(e){return"mac"===h()?e.join(""):e.join(" + ")}var f=e=>b([g(),e]),y=e=>b([g(),{down:"↓",left:"←",right:"→",up:"↑"}[e]]),v=()=>b([g(),"B"]),x=()=>b([g(),"⌫"]),k=()=>b([g(),"⌦"]),w=()=>b([g(),"I"]),C=()=>b([g(),"K"]),E=e=>b([g(),"⇧",e]),S=e=>b([g(),"⇧",{down:"↓",left:"←",right:"→",up:"↑"}[e]]),N=()=>b([g(),"U"]),A=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=v()}static apply(e){l.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),Wi.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))}}}Wi.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}},L=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=f("`")}static apply(e,t,n){l.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 a=document.createElement("code");a.classList.add("clepit-inline-code"),t&&l.applyClassNames(a,t),n&&Object.entries(n).forEach(([e,t])=>{if(void 0!==t){const n=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);a.style.setProperty(n,String(t))}}),e.surroundContents(a),Wi.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))}}}Wi.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&&l.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))}}))})}},B=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=w()}static apply(e){l.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),Wi.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))}}}Wi.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}},$="clepit-link-styles",M=`\n/* Link styles - simple and clean */\n.${l.classNames.block.link} {\n color: var(--clepit-primary);\n cursor: pointer;\n}\n\n.${l.classNames.block.link}:hover {\n color: var(--clepit-primary-hover);\n}\n`,I="clepit-dialogs-styles",T="\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 q(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 D(e,t){return`${e}-${t}`}function _(e){return!e||!e.trim()||"<br>"===e}function j(e){if(!e||_(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 z(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 O=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||(l.injectStyles(I,T),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=q("dialog","clepit-dialog-overlay"),this.applyStyles(this.overlay,this.options.styles?.overlay),this.applyClassNames(this.overlay,this.options.classNames?.overlay),this.dialog=q("div","clepit-dialog"),this.applyStyles(this.dialog,this.options.styles?.container),this.applyClassNames(this.dialog,this.options.classNames?.container);const e=q("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=q("div","clepit-dialog-group");this.applyStyles(a,this.options.styles?.group),this.applyClassNames(a,this.options.classNames?.group);const o=q("label","clepit-dialog-label");o.textContent=e,this.applyStyles(o,this.options.styles?.label),this.applyClassNames(o,this.options.classNames?.label);const i=q("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=q("div","clepit-dialog-buttons");this.applyStyles(e,this.options.styles?.buttons),this.applyClassNames(e,this.options.classNames?.buttons);const t=q("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=q("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}},H=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=C()}static apply(t,n,a){l.injectStyles($,M);const o=t.toString().trim(),i=e.findLinkElement(t.commonAncestorContainer);let r=o,s="";i&&(r=i.textContent||o,s=i.href||"");const c=t.cloneRange();new O({classNames:n,onCancel:()=>{const e=window.getSelection();e&&(e.removeAllRanges(),e.addRange(c))},onConfirm:(t,n)=>{try{const a=window.getSelection();if(a){if(a.removeAllRanges(),a.addRange(c),!n.trim())return void e.remove(c);if(t!==o){c.deleteContents();const e=document.createTextNode(t);c.insertNode(e),c.selectNode(e)}const i=l.createStyledElement("a",l.classNames.block.link);i.href=n,i.target="_blank",i.rel="noopener noreferrer";try{c.surroundContents(i)}catch{const e=c.extractContents();i.appendChild(e),c.insertNode(i)}const r=document.createRange();r.selectNodeContents(i),a.removeAllRanges(),a.addRange(r);const s=i.closest('[contenteditable="true"]');if(s){const e=new Event("input",{bubbles:!0});s.dispatchEvent(e)}}}catch(a){console.error("Failed to apply link:",a)}},styles:a,text:r||"Link text",url:s}).show(),Wi.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))}}}Wi.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}},P="clepit-marker-styles",R="\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",F=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=E("M")}static apply(t,n,a){l.injectStyles(P,R);const o=document.createElement("span");o.classList.add("clepit-marker-wrapper");const i=document.createElement("span");i.classList.add("clepit-marker-stroke");const r=t.extractContents();o.appendChild(document.createTextNode(" ")),o.appendChild(r),o.appendChild(document.createTextNode(" ")),o.insertBefore(i,o.firstChild),t.insertNode(o),t.selectNodeContents(o),e.applyUserStyles(o,i,n,a);const s=o.closest('[contenteditable="true"]');s&&s.dispatchEvent(new Event("input",{bubbles:!0})),Wi.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}))}}Wi.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(l.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(l.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,a,o){a&&l.applyClassNames(t,a),o&&Object.entries(o).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 i=t.style.getPropertyValue("--marker-background")||t.getAttribute("data-marker-background");if(i){const t=e.createStrokeSVG(i);return void(n.style.background=t)}if(o?.background){const t=o.background;if(t){const a=e.createStrokeSVG(String(t));return void(n.style.background=a)}}const r=t.closest(`.${l.classNames.editor.content}, .${l.classNames.renderer.content}`);if(r){const t=window.getComputedStyle(r).getPropertyValue("--clepit-marker-background");if(t&&"initial"!==t&&"inherit"!==t){const a=e.createStrokeSVG(t.trim());return void(n.style.background=a)}}const s=t.closest(`.${l.classNames.block.content}`);if(!s)return;const c=s.style.background||s.style.backgroundColor||s.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(s).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"}},V="clepit-inline-status-styles",U='\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',W=["info","success","warning","error","plain"],K=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||(l.injectStyles(I,T),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=q("dialog","clepit-dialog-overlay"),this.applyStyles(this.overlay,this.options.styles?.overlay),this.dialog=q("div","clepit-dialog"),this.applyStyles(this.dialog,this.options.styles?.container);const e=q("h3","clepit-dialog-title");e.textContent="Inline status",this.applyStyles(e,this.options.styles?.title),this.dialog.appendChild(e);const t=q("label","clepit-dialog-label");t.textContent="Label",this.applyStyles(t,this.options.styles?.label),this.dialog.appendChild(t),this.textInput=q("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=q("label","clepit-dialog-label");n.textContent="Variant",this.applyStyles(n,this.options.styles?.label),this.dialog.appendChild(n);const a=q("div","clepit-status-dialog-variants");for(const c of W){const e=q("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=q("div","clepit-dialog-buttons");this.applyStyles(o,this.options.styles?.buttons);const i=q("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=q("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))}},G="clepit-status",J=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,a){l.injectStyles(V,U);const o=t.toString().trim(),i=e.findStatusElement(t.commonAncestorContainer),r=i?i.textContent??o:o,s=i?e.readVariant(i):"info",c=t.cloneRange();new K({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!==o){c.deleteContents();const e=document.createTextNode(t);c.insertNode(e),c.selectNode(e)}const i=document.createElement("span");i.className=(e=>`${G} ${G}--${e}`)(n),i.dataset.statusVariant=n;try{c.surroundContents(i)}catch{const e=c.extractContents();i.appendChild(e),c.insertNode(i)}const r=document.createRange();r.selectNodeContents(i),a.removeAllRanges(),a.addRange(r);const s=i.closest('[contenteditable="true"]');s&&s.dispatchEvent(new Event("input",{bubbles:!0}))}catch(a){console.error("Failed to apply inline status:",a)}},styles:a,text:r||"status",variant:s}).show(),Wi.updateStateFromRange(t)}static remove(t){e.unwrap(t),Wi.updateStateFromRange(t)}static isActive(t){return!!e.findStatusElement(t.commonAncestorContainer)||t.cloneContents().querySelectorAll(`.${G}`).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(`.${G}`);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(G))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(`${G}--${n}`))return n;return"info"}},X=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=E("X")}static apply(e){l.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),Wi.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))}}}Wi.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}},Z="clepit-tooltip-styles",Y=`\n/* Tooltip styles - border bottom instead of text-decoration to avoid underline tool conflict */\n.${l.classNames.block.tooltip} {\n border-bottom: 1px dotted var(--clepit-text-subtle);\n cursor: help;\n}\n\n.${l.classNames.block.tooltip}:hover {\n border-bottom: 1px dotted var(--clepit-text-muted);\n}\n`,Q=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||(l.injectStyles(I,T),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=q("dialog","clepit-dialog-overlay"),this.applyStyles(this.overlay,this.options.styles?.overlay),this.applyClassNames(this.overlay,this.options.classNames?.overlay),this.dialog=q("div","clepit-dialog"),this.applyStyles(this.dialog,this.options.styles?.container),this.applyClassNames(this.dialog,this.options.classNames?.container);const e=q("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=q("div","clepit-dialog-group");this.applyStyles(a,this.options.styles?.group),this.applyClassNames(a,this.options.classNames?.group);const o=q("label","clepit-dialog-label");o.textContent=e,this.applyStyles(o,this.options.styles?.label),this.applyClassNames(o,this.options.classNames?.label);const i=q("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=q("div","clepit-dialog-buttons");this.applyStyles(e,this.options.styles?.buttons),this.applyClassNames(e,this.options.classNames?.buttons);const t=q("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=q("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 ee(e,t,n="below",a,o){let i=null,r=null;const s=()=>{if(i)return;l.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"),i=document.createElement("div"),i.className=`clepit-inline-tooltip ${a?.container||""}`,l.applyStyling(i,{styles:o?.container});const s=document.createElement("div");s.className=`clepit-inline-tooltip-content ${a?.content||""}`,s.textContent=t,l.applyStyling(s,{styles:o?.content});const p=document.createElement("div");p.className=`clepit-inline-tooltip-arrow clepit-inline-tooltip-arrow--${n} ${a?.arrow||""}`,l.applyStyling(p,{styles:o?.arrow}),s.appendChild(p),i.appendChild(s),document.body.appendChild(i);const d=e.getBoundingClientRect(),u=s.offsetWidth,m=s.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} ${a?.arrow||""}`,i.style.left=`${g}px`,i.style.top=`${Math.max(8,Math.min(h,window.innerHeight-m-8))}px`,requestAnimationFrame(()=>{i&&(i.style.opacity="1",s.style.transform="translateY(0)")}),r||(r=new MutationObserver(()=>{document.body.contains(e)&&e.isConnected||(c(),r&&(r.disconnect(),r=null))}),r.observe(document.body,{childList:!0,subtree:!0}))},c=()=>{i&&(i.style.opacity="0",setTimeout(()=>{i&&i.parentElement&&i.parentElement.removeChild(i),i=null,r&&(r.disconnect(),r=null)},120))};return e.addEventListener("mouseenter",s),e.addEventListener("mouseleave",c),()=>{e.removeEventListener("mouseenter",s),e.removeEventListener("mouseleave",c),c()}}var te=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=E("T")}static apply(t,n,a){l.injectStyles(Z,Y);const o=t.toString(),i=t.cloneRange();let r="",s=o;const c=e.findTooltipSpan(t.commonAncestorContainer);c&&(r=c.getAttribute("data-tooltip")||"",s=c.textContent||""),new Q({classNames:n.classNames,onCancel:()=>{const e=window.getSelection();e&&(e.removeAllRanges(),e.addRange(i))},onConfirm:(t,o)=>{const r=window.getSelection();if(!r)return;if(r.removeAllRanges(),r.addRange(i),!o.trim())return e.remove(i),void(t!==s&&(i.deleteContents(),i.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),i.selectNode(t)}}if(t!==s){i.deleteContents();const e=document.createTextNode(t);i.insertNode(e),i.selectNode(e)}const p=l.createStyledElement("span",l.classNames.block.tooltip);p.setAttribute("data-tooltip",o),a.classNames&&l.applyClassNames(p,a.classNames),a.styles&&Object.entries(a.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{i.surroundContents(p)}catch{const e=i.extractContents();p.appendChild(e),i.insertNode(p)}t!==s&&p.textContent!==t&&(p.textContent=t),ee(p,o,"above",n.classNames,n.styles);const d=p.closest('[contenteditable="true"]');d&&d.dispatchEvent(new Event("input",{bubbles:!0}))},styles:n.styles,text:s,tooltip:r}).show(),Wi.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)}Wi.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findTooltipSpan(n)||t.cloneContents().querySelectorAll(`span.${l.classNames.block.tooltip}`).length>0}static initializeElements(e,t){e.querySelectorAll(`span.${l.classNames.block.tooltip}`).forEach(e=>{if(e instanceof HTMLElement&&(t.classNames&&l.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&&(ee(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(l.classNames.block.tooltip))return e}return t.parentNode?e.findTooltipSpan(t.parentNode):null}},ne=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=N()}static apply(e){l.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),Wi.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))}}}Wi.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}},ae=["bold","inline-code","italic","link","marker","status","strikethrough","tooltip","underline"],oe=["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"],ie=["improve","shorten","lengthen","simplify","fix_grammar"],re=()=>[A,B,ne,X,L,F,J,H,te],se="inline-toolbar",le=class e{static{this.eventListenersMap=/* @__PURE__ */new WeakMap}static{this.hideTimeoutMap=/* @__PURE__ */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=m.getState().getInstance(t);if(!n)return console.error("InlineToolbar::create: Instance not found for containerId:",t);const a=document.getElementById(t);if(!a)return console.error("InlineToolbar::create: Container not found for containerId:",t);e.eventListenersMap.has(a)||e.eventListenersMap.set(a,[]),l.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 o=q("div","clepit-toolbar");o.id=`${t}-${se}`,o.classList.add("clepit-toolbar--hidden","clepit-toolbar--layout"),l.applyStyling(o,{classNames:n.config.classNames?.inlineToolbar?.container,styles:n.config.styles?.inlineToolbar?.container}),a.appendChild(o)}static repaint(t,n){const a=m.getState().getInstance(t);if(!a)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 o=((n.commonAncestorContainer.nodeType===Node.ELEMENT_NODE?n.commonAncestorContainer:n.commonAncestorContainer.parentElement)?.closest(`.${l.classNames.block.container}`))?.getAttribute("data-tool");e.getFilteredTools(o).forEach(a=>e.addButton(t,a,n)),a.config.onInlineRewrite&&e.addRewriteButton(t,n);const i=n.getBoundingClientRect(),r=document.getElementById(a.config.containerId)?.getBoundingClientRect();if(!r)return;const s=((e=!1)=>({height:40,width:24*(re().length+(e?1:0))+16}))(Boolean(a.config.onInlineRewrite)),c=i.left-r.left+i.width/2-s.width/2;let p=i.top-r.top-s.height-8;p<0&&(p=i.bottom-r.top+8),e.show(a.config.containerId,c,p)}static addRewriteButton(t,n){const a=m.getState().getInstance(t),o=a?.config.onInlineRewrite;if(!a||!o)return;const i=e.getElementFromContainerId(t),r=document.getElementById(t);if(!i||!r)return;const s=q("button","clepit-toolbar-button",{type:"button"});s.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>',s.setAttribute("data-tool","rewrite"),l.applyStyling(s,{classNames:a.config.classNames?.inlineToolbar?.button,styles:a.config.styles?.inlineToolbar?.button});const c=q("div","clepit-toolbar-rewrite-menu");c.style.display="none",c.setAttribute("data-rewrite-menu","true");for(const l of ie){const t=q("button","clepit-toolbar-rewrite-item",{type:"button"});t.textContent=a.config.inlineRewriteLabels?.[l]??l,t.setAttribute("data-rewrite-action",l),e.addEventListener(r,t,"mousedown",e=>e.preventDefault()),e.addEventListener(r,t,"click",()=>{c.style.display="none";const e=window.getSelection(),t=e&&e.rangeCount>0?e.getRangeAt(0):null,a=t&&!t.collapsed?t:n,i=a.toString();i.trim()&&(s.classList.add("busy"),o(i,l).then(e=>{e&&(a.deleteContents(),a.insertNode(document.createTextNode(e)),r.dispatchEvent(new Event("input",{bubbles:!0})))}).catch(()=>{}).finally(()=>s.classList.remove("busy")))}),c.appendChild(t)}e.addEventListener(r,s,"mousedown",e=>e.preventDefault()),e.addEventListener(r,s,"click",()=>{c.style.display="none"===c.style.display?"flex":"none"}),i.appendChild(s),e.createTooltip(i,s,"rewrite"),i.appendChild(c)}static addButton(t,n,a){const o=m.getState().getInstance(t);if(!o)return console.error("InlineToolbar::addButton: Instance not found for containerId:",t);const i=e.getElementFromContainerId(t);if(!i)return console.error("InlineToolbar::addButton: Toolbar not found for containerId:",t);const r=q("button","clepit-toolbar-button",{type:"button"});r.innerHTML=n.icon,l.applyStyling(r,{classNames:o.config.classNames?.inlineToolbar?.button,styles:o.config.styles?.inlineToolbar?.button}),n.isActive(a)&&r.classList.add("active"),r.setAttribute("data-tool",n.label.toLowerCase());const s=document.getElementById(t);s&&(e.addEventListener(s,r,"mousedown",e=>e.preventDefault()),e.addEventListener(s,r,"click",()=>{try{const e=window.getSelection(),t=e&&e.rangeCount>0?e.getRangeAt(0):null,i=t&&!t.collapsed?t:a;if(i&&n.isActive(i))n.remove(i),r.classList.remove("active");else if(i){switch(n.label){case"italic":B.apply(i);break;case"bold":A.apply(i);break;case"underline":ne.apply(i);break;case"strikethrough":X.apply(i);break;case"inlineCode":L.apply(i,o.config.classNames?.blocks?.["inline-code"],o.config.styles?.blocks?.["inline-code"]);break;case"marker":F.apply(i,o.config.classNames?.blocks?.marker,o.config.styles?.blocks?.marker);break;case"status":J.apply(i,o.config.classNames?.dialogs,o.config.styles?.dialogs);break;case"link":H.apply(i,o.config.classNames?.dialogs,o.config.styles?.dialogs);break;case"tooltip":te.apply(i,{classNames:o.config.classNames?.tooltips,styles:o.config.styles?.tooltips},{classNames:o.config.classNames?.blocks?.tooltip,styles:o.config.styles?.blocks?.tooltip})}r.classList.add("active")}}catch(e){console.warn("Error applying inline tool:",e)}})),i.appendChild(r),e.createTooltip(i,r,n.label)}static createTooltip(t,n,a){const o=q("div","clepit-toolbar-tooltip clepit-toolbar-tooltip--hidden"),i=q("div","clepit-toolbar-tooltip-content");i.textContent=a;const r=q("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}-${se}`):(console.error("InlineToolbar::getElementFromContainerId: Container not found for containerId:",e),null)}static getFilteredTools(e){return"header"===e?re().filter(e=>"bold"!==e.label):re()}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}-${se}`);if(!o)return console.warn("InlineToolbar::destroy: Toolbar not found for containerId:",t);o.remove()}};function ce(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 pe(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 de(e){const t=e.toLowerCase();return t.includes("youtube.com")||t.includes("youtu.be")}function ue(e){return e.toLowerCase().includes("vimeo.com")}function me(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=de(t),a=ue(t);return{isImage:ce(t),isUrl:!0,isVideo:pe(t)||n||a,isVimeo:a,isYouTube:n,url:t}}var he=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 a=n.closest(`.${l.classNames.editor.content}`);if(!a)return null;const o=a.getAttribute("data-container-id");if(!o)return null;const i=m.getState().getInstance(o);return i?{instance:i,target:n}:null}static handleClick(e){const t=e.currentTarget,n=e.target,a=n.closest(`.${l.classNames.block.link}`);if(a){const e=document.createRange();e.selectNodeContents(a);const n=m.getState().getInstance(t.id);return void(n&&H.apply(e,n.config.classNames?.dialogs,n.config.styles?.dialogs))}const o=n.closest(`.${l.classNames.block.tooltip}`);if(o){const e=document.createRange();e.selectNodeContents(o);const n=m.getState().getInstance(t.id);return void(n&&te.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{le.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{le.repaint(a.instance.config.containerId,n)}catch{}else try{le.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 a=me(n);if(!a.isUrl)return;const o=document.activeElement;if(!o)return;const i=o.closest(`.${l.classNames.block.container}`);if(!i)return;const r=i.closest(`.${l.classNames.editor.container}`);if(!r)return;const s=i.getAttribute("data-id"),c=Wi.getBlockIndex(r.id,s);if(-1===c)return;const p=Wi.getTool(i.getAttribute("data-tool"));if(!p)return;const d=p.input.isEmpty(i);if(a.isImage){const e={data:{alignment:"center",alt:"Image",caption:"",url:a.url},type:"image"};d?Wi.replaceBlock(r.id,c,e):Wi.insertBlock(e,r.id,c+1)}else if(a.isVideo){let e=a.url;a.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}(a.url)||a.url:a.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}(a.url)||a.url);const t={data:{alignment:"center",alt:"Video",caption:"",url:e},type:"video"};d?Wi.replaceBlock(r.id,c,t):Wi.insertBlock(t,r.id,c+1)}}},ge="\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",be=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(`.${l.classNames.block.alert}`)||e,n=t.getAttribute("data-variant")||"info";return{html:j(t.innerHTML),variant:n}}static render(t,n,a){l.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 o={html:"",variant:"info"},i=n?{...o,...n}:o,r=l.createStyledElement("div","clepit-alert",{classNames:a?.classNames?.[i.variant],styles:a?.styles?.[i.variant]});return r.setAttribute("data-variant",i.variant),r.setAttribute("contenteditable","true"),r.setAttribute("data-placeholder",e.placeholder),i.html?r.innerHTML=i.html:r.innerHTML="",e.addEventListener(t,r,"keydown",Wi.handleKeydown),e.addEventListener(t,r,"input",Wi.handleInput),r}static changeVariant(t,n,a){const o=m.getState().getInstance(a);if(!o)return;if(t.getAttribute("data-variant")===n)return;const i=t.innerHTML||"",r={html:i.trim()&&"<br>"!==i.trim()?i:"",variant:n},s={classNames:o.config.classNames?.blocks?.alert,margins:o.config.margins,styles:o.config.styles?.blocks?.alert},c=Wi.getBlockIndex(a,t.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id")),p=e.render(a,r,s);t.replaceWith(p),m.getState().updateBlockData(a,c,r)}static isEmpty(e){return _(e.querySelector(`.${l.classNames.block.alert}`)?.innerHTML)}static isEmptyData(e){return _(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]=[])}},fe=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))}},ye={create:e=>new fe(document.createElement(e)),createNS:(e,t)=>new fe(document.createElementNS(e,t))},ve=/* @__PURE__ */new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),xe=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),ke=e=>e.replace(/&/g,"&amp;").replace(/"/g,"&quot;"),we=class{constructor(e,t){this.tag=e,this.sanitize=t,this.attributes=/* @__PURE__ */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(xe(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(xe(e))}toString(){const e=[...this.classes.length>0?[`class="${ke(this.classes.join(" "))}"`]:[],...[...this.attributes].map(([e,t])=>`${e}="${ke(t)}"`)],t=[this.tag,...e].join(" ");return ve.has(this.tag)?`<${t}>`:`<${t}>${this.children.join("")}</${this.tag}>`}},Ce=e=>({create:t=>new we(t,e),createNS:(t,n)=>new we(n,e)}),Ee=e=>String(e),Se=e=>{if(!(e instanceof fe))throw new TypeError("toDomElement needs an element built by the dom backing");return e.node};function Ne(){l.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=q("div","clepit-invalid-data"),t=q("div","clepit-invalid-data-text");return t.textContent="Invalid data",e.appendChild(t),e}var Ae=class e{static render(t,n,a,o){if(l.injectStyles("clepit-alert-output-styles",ge),!e.validate(t))return Ne();if(be.isEmptyData(t))return document.createElement("div");const i=t.html,r=t.variant,s=l.createStyledElement("div",`clepit-output-alert clepit-output-alert--${r}`,{classNames:o?.[r],styles:a?.[r]});return i&&(s.innerHTML=i),s}static draw(t,n=ye){if(!e.validate(t)||be.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}},Le={icon:"!",get input(){return be},label:"Alert",get output(){return Ae},shortcut:E("A"),testId:"block-type-alert",type:"alert"},Be=`\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.${l.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.${l.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.${l.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.${l.classNames.block.audioDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Audio drop area delete button */\n.clepit-audio-drop-area .${l.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 .${l.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`,$e="\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",Me=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(`.${l.classNames.block.audio.captionEditable}`),a=e.querySelector(`.${l.classNames.block.audio.wrapper}`);let o="center";return a&&(o=a.classList.contains("align-left")?"left":a.classList.contains("align-right")?"right":"center"),{alignment:o,alt:t&&t.getAttribute("alt")||"",caption:j(n?.innerHTML),url:t&&t.getAttribute("src")||""}}static render(t,n,a,o){l.injectStyles("clepit-audio-input-styles",Be);const i=a||{alt:"",caption:"",url:""},r=l.createStyledElement("div",l.classNames.block.audio.container,{classNames:o?.classNames?.container,styles:o?.styles?.container});return i.url?e.renderAudio(r,i,t,n,o):e.renderDropArea(r,t,n,o),r}static renderAudio(t,n,a,o,i){if(!document.getElementById(o))return;t.innerHTML="";const r=l.createStyledElement("div",l.classNames.block.audio.wrapper,{classNames:i?.classNames?.container,styles:i?.styles?.container});switch(r.setAttribute("tabindex","-1"),n?.alignment||"center"){case"left":r.classList.add("align-left");break;case"center":r.classList.add("align-center");break;case"right":r.classList.add("align-right")}const s=l.createStyledElement("audio","clepit-audio",{classNames:i?.classNames?.container,styles:i?.styles?.container});s.src=n.url,s.controls=!0,s.preload="metadata",n.alt&&s.setAttribute("alt",n.alt);const c=l.createStyledElement("div","clepit-audio-caption-container",{classNames:i?.classNames?.container,styles:i?.styles?.container});c.classList.add("clepit-audio-caption-container");const p=l.createStyledElement("div","clepit-audio-caption-editable",{classNames:i?.classNames?.caption,styles:i?.styles?.caption});p.setAttribute("contenteditable","true"),p.setAttribute("data-placeholder",e.placeholder),p.innerHTML=n.caption||"",e.addEventListener(o,p,"keydown",Wi.handleKeydown),e.addEventListener(o,p,"input",Wi.handleInput),e.addEventListener(o,r,"click",()=>e.handleFileSelect(t,a,o,i)),r.appendChild(s),c.appendChild(p),t.appendChild(r),t.appendChild(c),p.focus()}static renderDropArea(t,n,a,o){t.innerHTML="";const i=l.createStyledElement("div",l.classNames.block.audio.dropArea,{classNames:o?.classNames?.dropArea?.container,styles:o?.styles?.dropArea?.container});i.setAttribute("tabindex","0"),i.classList.add("clepit-drop-area");const r=l.createStyledElement("div","clepit-audio-drop-icon",{classNames:o?.classNames?.dropArea?.icon,styles:o?.styles?.dropArea?.icon});r.textContent="♪";const s=l.createStyledElement("div","clepit-audio-drop-text",{classNames:o?.classNames?.dropArea?.text,styles:o?.styles?.dropArea?.text});s.innerHTML='<strong>Drop an audio file here</strong><br>or <span class="clepit-audio-click-text">click to select</span>';const c=l.createStyledElement("div","clepit-audio-drop-subtext",{classNames:o?.classNames?.dropArea?.subtext,styles:o?.styles?.dropArea?.subtext});c.textContent="Supports MP3, WAV, OGG, and other audio formats";const p=l.createStyledElement("button",`${l.classNames.block.audioDeleteBtn}`,{classNames:o?.classNames?.dropArea?.deleteButton,styles:o?.styles?.dropArea?.deleteButton});p.type="button",p.textContent="✕",i.appendChild(r),i.appendChild(s),i.appendChild(c),i.appendChild(p);const d=a?m.getState().getInstance(a):null,u=d?.config.classNames?.tooltips,h=d?.config.styles?.tooltips;ee(p,"Delete block","below",u,h),e.addEventListener(a,p,"click",e=>{e.preventDefault(),e.stopPropagation();const t=p.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id");t&&Wi.removeBlock(a,Wi.getBlockIndex(a,t))}),e.addEventListener(a,i,"click",()=>e.handleFileSelect(t,n,a,o)),e.addEventListener(a,i,"dragleave",()=>{i.classList.remove("clepit-audio-drop-area--dragover")}),e.addEventListener(a,i,"dragover",e=>{e.preventDefault(),e.stopPropagation(),i.classList.add("clepit-audio-drop-area--dragover")}),e.addEventListener(a,i,"drop",r=>{r.preventDefault(),r.stopPropagation(),i.classList.remove("clepit-audio-drop-area--dragover"),e.handleFileDrop(r,t,n,a,o)}),e.addEventListener(a,i,"focus",e=>{e.preventDefault(),e.stopPropagation()}),e.addEventListener(a,i,"mousedown",e=>{e.preventDefault(),e.stopPropagation()}),t.appendChild(i)}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,a,o,i){e.showLoading(n);try{let r=await a(t);if(r){e.renderAudio(n,{alignment:"center",alt:t.name,caption:"",url:r},a,o,i);const s=n.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id");s&&m.getState().updateBlockData(o,Wi.getBlockIndex(o,s),Wi.getBlockData(s).data)}else e.showError(n,"Failed to upload audio. Please try again.")}catch(r){console.error("Audio upload error:",r),e.showError(n,"Failed to upload audio. Please try again.")}}static showLoading(e){e.innerHTML="";const t=l.createStyledElement("div","clepit-audio-loading",void 0);t.textContent="Uploading audio...",e.appendChild(t)}static showError(e,t){e.innerHTML="";const n=l.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=Wi.getEditorId(e);if(!a)return;const o=e.getAttribute("data-id");o&&m.getState().partialUpdateBlockData(a,Wi.getBlockIndex(a,o),{alignment:t})}static isEmpty(e){const t=e.querySelector(`.${l.classNames.block.audio.wrapper} audio`),n=e.querySelector(`.${l.classNames.block.audio.captionEditable}`);let a=!1,o=!1;return t&&t.getAttribute("src")?.trim()||(a=!0),n?_(n.innerHTML)&&(o=!0):o=!0,a&&o}static isEmptyData(e){return!e.url?.trim()&&_(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]=[])}},Ie=class e{static render(t,n,a,o){if(l.injectStyles("clepit-audio-output-styles",$e),!e.validate(t))return Ne();if(Me.isEmptyData(t))return document.createElement("div");const i=t.url,r=t.caption,s=t.alignment||"center",c=l.createStyledElement("div","clepit-output-audio-container",{classNames:o?.container,styles:a?.container}),p=l.createStyledElement("div","clepit-output-audio-wrapper");switch(s){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=q("audio","clepit-output-audio");if(d.src=i,d.controls=!0,d.preload="metadata",t.alt&&d.setAttribute("alt",t.alt),p.appendChild(d),c.appendChild(p),r){const e=l.createStyledElement("figcaption","clepit-output-audio-caption",{classNames:o?.caption,styles:a?.caption}),n=t.caption;e.innerHTML=n&&n!==r?n:r,c.appendChild(e)}if(a&&(a.container&&Object.assign(c.style,a.container),a.caption)){const e=c.querySelector(".clepit-output-audio-caption");e&&Object.assign(e.style,a.caption)}if(o&&(o.container&&c.classList.add(o.container),o.caption)){const e=c.querySelector(".clepit-output-audio-caption");e&&e.classList.add(o.caption)}return c}static draw(t,n=ye){if(!e.validate(t)||Me.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}},Te={icon:"♪",get input(){return Me},label:"Audio",get output(){return Ie},shortcut:E("O"),testId:"block-type-audio",type:"audio"},qe=`\n/* Checklist input block styles */\n.${l.classNames.block.checklist.container} {\n margin: 0;\n padding: 0 20px;\n}\n\n.${l.classNames.block.checklist.item} {\n --text: var(--clepit-text);\n --check: var(--clepit-primary);\n --disabled: var(--clepit-text-muted);\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.${l.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.${l.classNames.block.checklist.text}::before,\n.${l.classNames.block.checklist.text}::after {\n content: "";\n position: absolute;\n}\n\n.${l.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.${l.classNames.block.checklist.text}::after {\n height: 4px;\n width: 4px;\n top: 8px;\n left: -25px;\n border-radius: 50%;\n}\n\n.${l.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.${l.classNames.block.checklist.checkbox}::before,\n.${l.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.${l.classNames.block.checklist.checkbox}::before {\n width: 0px;\n right: 60%;\n transform-origin: right bottom;\n}\n\n.${l.classNames.block.checklist.checkbox}::after {\n width: 0px;\n left: 40%;\n transform-origin: left bottom;\n}\n\n.${l.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.${l.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.${l.classNames.block.checklist.checkbox}:checked + .${l.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.${l.classNames.block.checklist.checkbox}:checked + .${l.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.${l.classNames.block.checklist.checkbox}:checked + .${l.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.${l.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.${l.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.${l.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(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--check), 14px -8px 0 0px var(--check), 14px 8px 0 0px var(--check), 0 15px 0 0px var(--check), -14px 8px 0 0px var(--check), -14px -8px 0 0px var(--check);\n }\n}\n\n@keyframes clepit-firework-11 {\n 0% {\n opacity: 1;\n box-shadow: 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--check), 14px -8px 0 0px var(--check), 14px 8px 0 0px var(--check), 0 15px 0 0px var(--check), -14px 8px 0 0px var(--check), -14px -8px 0 0px var(--check);\n }\n}\n`,De='\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-primary);\n --disabled: var(--clepit-text-muted);\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(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--check), 14px -8px 0 0px var(--check), 14px 8px 0 0px var(--check), 0 15px 0 0px var(--check), -14px 8px 0 0px var(--check), -14px -8px 0 0px var(--check);\n }\n}\n\n@keyframes clepit-firework-11 {\n 0% {\n opacity: 1;\n box-shadow: 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--check), 14px -8px 0 0px var(--check), 14px 8px 0 0px var(--check), 0 15px 0 0px var(--check), -14px 8px 0 0px var(--check), -14px -8px 0 0px var(--check);\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(`.${l.classNames.block.checklist.item}`).forEach(e=>{const n=e.querySelector('input[type="checkbox"]'),a=e.querySelector(`.${l.classNames.block.checklist.text}`);n&&a&&t.push({checked:n.checked,text:j(a.innerHTML)})}),{items:t}}static render(t,n,a){l.injectStyles("clepit-checklist-input-styles",qe);const o={items:[]},i=n?{...o,...n}:o,r=l.createStyledElement("div",l.classNames.block.checklist.container,{classNames:a?.classNames?.container,styles:a?.styles?.container});return i.items.length>0?i.items.forEach(n=>e.createAndAppendChecklistItem(n,r,t,a)):e.createAndAppendChecklistItem({checked:!1,text:""},r,t,a),r}static createAndAppendChecklistItem(t,n,a,o){const i=l.createStyledElement("div",l.classNames.block.checklist.item,{classNames:o?.classNames?.item,styles:o?.styles?.item}),r=l.createStyledElement("input",l.classNames.block.checklist.checkbox,{classNames:o?.classNames?.checkbox,styles:o?.styles?.checkbox});r.type="checkbox",r.checked=t.checked;const s=l.createStyledElement("div",l.classNames.block.checklist.text,{classNames:o?.classNames?.text,styles:o?.styles?.text});s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder",e.placeholder),s.innerHTML=t.text?.trim()||"",e.addEventListener(a,r,"change",()=>Wi.saveBlockData(r)),e.addEventListener(a,s,"keydown",t=>{const r=t,c=n.closest(`.${l.classNames.block.container}`);if(!c)return;const p=Wi.getBlockIndex(a,c.getAttribute("data-id")),d=r.metaKey||r.ctrlKey;if(r.shiftKey)switch(r.key){case"ArrowUp":t.preventDefault(),t.stopPropagation(),p>0&&Wi.moveBlock(a,p,p-1);break;case"ArrowDown":t.preventDefault(),t.stopPropagation();const e=Wi.getBlocks(a);e&&p<e.length-1&&Wi.moveBlock(a,p,p+1)}else if(d)switch(r.key){case"Delete":case"Backspace":t.preventDefault(),t.stopPropagation(),Wi.removeBlock(a,p)}else if("Enter"===r.key)if(t.preventDefault(),t.stopPropagation(),_(s.innerHTML)){e.cleanupEmptyItems(n);const t=n.closest(`.${l.classNames.block.container}`);if(!t)return;const o=Wi.getBlockIndex(a,t.getAttribute("data-id"));Wi.insertBlock({data:{html:""},type:"paragraph"},a,o+1)}else e.createAndAppendChecklistItem({checked:!1,text:""},n,a,o);else if("Backspace"===r.key){if(_(s.innerHTML)){t.preventDefault(),t.stopPropagation();const e=Array.from(n.querySelectorAll(`.${l.classNames.block.checklist.item}`)),o=e.indexOf(i);if(1===e.length){const e=n.closest(`.${l.classNames.block.container}`);if(!e)return;const t=Wi.getBlockIndex(a,e.getAttribute("data-id"));if(-1===t)return;Wi.removeBlock(a,t)}else i.remove(),o>0?e[o-1].querySelector(".clepit-checklist-text")?.focus():e[o+1].querySelector(".clepit-checklist-text")?.focus()}}else{Wi.ensureActiveBlock(a);const e=Wi.getBlocks(a);switch(r.key){case"ArrowUp":t.preventDefault(),t.stopPropagation();const a=Array.from(n.querySelectorAll(`.${l.classNames.block.checklist.item}`)),o=a.indexOf(i);if(0===o){if(p>0){const t=e[p-1];t&&Wi.focusBlock(t)}}else{const e=a[o-1].querySelector(`.${l.classNames.block.checklist.text}`);e&&e.focus()}return;case"ArrowDown":t.preventDefault(),t.stopPropagation();const r=Array.from(n.querySelectorAll(`.${l.classNames.block.checklist.item}`)),s=r.indexOf(i);if(s===r.length-1){if(p<e.length-1){const t=e[p+1];t&&Wi.focusBlock(t)}}else{const e=r[s+1].querySelector(`.${l.classNames.block.checklist.text}`);e&&e.focus()}return}}}),e.addEventListener(a,s,"input",Wi.handleInput),i.appendChild(r),i.appendChild(s),n.appendChild(i),s.focus()}static cleanupEmptyItems(e){const t=Array.from(e.querySelectorAll(`.${l.classNames.block.checklist.item}`)),n=t.filter(e=>_(e.querySelector(`.${l.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(`.${l.classNames.block.checklist.item}`);return!t||Array.from(t).every(e=>_(e.querySelector(`.${l.classNames.block.checklist.text}`)?.innerHTML))}static isEmptyData(e){return 0===e.items.length||e.items.every(e=>_(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]=[])}},je=class e{static render(t,n,a,o){if(l.injectStyles("clepit-checklist-output-styles",De),!e.validate(t))return Ne();if(_e.isEmptyData(t))return document.createElement("div");const i=t.items,r=l.createStyledElement("div","clepit-output-checklist",{classNames:o?.container,styles:a?.container});return i.forEach((e,t)=>{const n=l.createStyledElement("div","clepit-output-checklist-item",{classNames:o?.item,styles:a?.item}),i=l.createStyledElement("input","clepit-output-checklist-checkbox",{classNames:o?.checkbox,styles:a?.checkbox});i.type="checkbox",i.checked=e.checked,i.setAttribute("readonly","true");const s=l.createStyledElement("div","clepit-output-checklist-text",{classNames:o?.text,styles:a?.text});e.text&&e.text.trim()&&(s.innerHTML=e.text),i.checked&&n.classList.add("checked"),n.appendChild(i),n.appendChild(s),r.appendChild(n)}),r}static draw(t,n=ye){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)}},ze={icon:"☑",get input(){return _e},label:"Checklist",get output(){return je},shortcut:E("K"),testId:"block-type-checklist",type:"checklist"},Oe=`\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.${l.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.${l.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.${l.classNames.block.code.editor} .clepit-code-highlight,\n.${l.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.${l.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.${l.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.${l.classNames.block.code.editor} .clepit-code-input::placeholder {\n color: var(--clepit-text-muted);\n}\n\n.${l.classNames.block.code.editor} .clepit-code-input::selection {\n background: var(--clepit-code-selection-bg);\n color: transparent;\n}\n\n/* Code header */\n.${l.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.${l.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`,He="clepit-code-output-styles",Pe="\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",Re={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 Fe(e){return Re[e]||"Unknown"}var Ve=Object.fromEntries(Object.keys(n).map(e=>[e,{name:Fe(e)}])),Ue={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 We(e){return Ue[e]||"Unknown"}var Ke=Object.fromEntries(Object.keys(Ue).map(e=>[e,{name:We(e),theme:null}])),Ge=`\n/* Custom Switch Container */\n.${l.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.${l.classNames.switch.container} .tgl {\n display: none;\n}\n\n.${l.classNames.switch.container} .tgl,\n.${l.classNames.switch.container} .tgl:after,\n.${l.classNames.switch.container} .tgl:before,\n.${l.classNames.switch.container} .tgl *,\n.${l.classNames.switch.container} .tgl *:after,\n.${l.classNames.switch.container} .tgl *:before,\n.${l.classNames.switch.container} .tgl + .tgl-btn {\n box-sizing: border-box;\n}\n\n.${l.classNames.switch.container} .tgl::selection,\n.${l.classNames.switch.container} .tgl:after::selection,\n.${l.classNames.switch.container} .tgl:before::selection,\n.${l.classNames.switch.container} .tgl *::selection,\n.${l.classNames.switch.container} .tgl *:after::selection,\n.${l.classNames.switch.container} .tgl *:before::selection,\n.${l.classNames.switch.container} .tgl + .tgl-btn::selection {\n background: none;\n}\n\n.${l.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.${l.classNames.switch.container} .tgl + .tgl-btn:after,\n.${l.classNames.switch.container} .tgl + .tgl-btn:before {\n position: relative;\n display: block;\n content: "";\n width: 44%;\n height: 100%;\n}\n\n.${l.classNames.switch.container} .tgl + .tgl-btn:after {\n left: 0;\n}\n\n.${l.classNames.switch.container} .tgl + .tgl-btn:before {\n display: inline;\n position: absolute;\n top: 3px;\n}\n\n.${l.classNames.switch.container} .tgl:checked + .tgl-btn:after {\n left: 56.5%;\n}\n\n.${l.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.${l.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.${l.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.${l.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.${l.classNames.switch.container} .tgl-ios + .tgl-btn:active:after {\n padding-right: 0.4em;\n}\n\n.${l.classNames.switch.container} .tgl-ios:checked + .tgl-btn {\n background: var(--switch-blue);\n}\n\n.${l.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.${l.classNames.switch.container} .tgl-ios:checked + .tgl-btn:active:after {\n margin-left: -0.4em;\n}\n\n.${l.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`,Je=class{static create(e={}){const{checked:t=!1,onToggle:n,classNames:a,styles:o,label:i,id:r=`switch-${Math.random().toString(36).substring(2,11)}`}=e;l.injectStyles("clepit-custom-switch-styles",Ge);const s=l.createStyledElement("div",l.classNames.switch.container,{classNames:a?.container,styles:o?.container}),c=l.createStyledElement("input","tgl tgl-ios",{classNames:a?.input,styles:o?.input});c.type="checkbox",c.id=r,c.checked=t;const p=l.createStyledElement("label","tgl-btn",{classNames:a?.label,styles:o?.label});if(p.setAttribute("for",r),n&&c.addEventListener("change",e=>{const t=e.target;n(t.checked)}),s.appendChild(c),s.appendChild(p),i){const e=l.createStyledElement("span","clepit-switch-label-text",{classNames:a?.labelText,styles:o?.labelText});e.textContent=i,s.appendChild(e)}return s}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)}},Xe=class e{static{this.placeholder="Enter code..."}static{this.supportedLanguages=Ve}static{this.supportedThemes=Ke}static{this.defaultLanguage="typescript"}static{this.defaultTheme="auto"}static{this.inputMap=/* @__PURE__ */new WeakMap}static{this.dataMap=/* @__PURE__ */new WeakMap}static save(t){const n=t.querySelector(`.${l.classNames.block.code.container}`),a=n.querySelector(`.${l.classNames.block.code.headerWrapper}`),o=n?.getAttribute("data-language")||e.defaultLanguage,i=n?.getAttribute("data-theme")||e.defaultTheme,r=!!a&&Je.getState(a),s=e.inputMap.get(n);if(s){const t=s.value,a=e.dataMap.get(n),l={code:t.trim()||"",language:o,showCopy:r,theme:i};return a?.variants?.length&&(l.variants=a.variants),a?.syncKey&&(l.syncKey=a.syncKey),e.dataMap.set(n,l),l}return{...e.dataMap.get(n)||{code:"",language:e.defaultLanguage,theme:e.defaultTheme},showCopy:r}}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,a,o){l.injectStyles("clepit-code-input-styles",Oe);const i={code:"",language:o?.language||e.defaultLanguage,showCopy:!0,theme:o?.theme||e.defaultTheme},r=n?{...i,...n}:i,s=l.createStyledElement("div",l.classNames.block.code.container,{classNames:a?.classNames?.container,styles:a?.styles?.container});s.setAttribute("data-language",r.language||e.defaultLanguage),s.setAttribute("data-theme",r.theme||e.defaultTheme);const c=l.createStyledElement("div",l.classNames.block.code.headerWrapper,{classNames:a?.classNames?.header?.wrapper,styles:a?.styles?.header?.wrapper}),p=l.createStyledElement("div",l.classNames.block.code.header,{classNames:a?.classNames?.header?.text,styles:a?.styles?.header?.text}),d=Ve[r.language]?.name||Fe(e.defaultLanguage),u=Ke[r.theme]?.name||We(e.defaultTheme);p.textContent=e.getHeaderText(d,u);const h=l.createStyledElement("div",l.classNames.block.code.editor,{classNames:a?.classNames?.container,styles:a?.styles?.container});h.setAttribute("data-placeholder",e.placeholder);const g=t?m.getState().getInstance(t):null,b=g?.config.classNames?.switch,f=g?.config.styles?.switch,y=Je.create({checked:r.showCopy||!1,classNames:b,label:"Allow copy",onToggle:t=>{const n=e.dataMap.get(s)||{code:"",language:e.defaultLanguage,theme:e.defaultTheme};e.dataMap.set(s,{...n,showCopy:t}),Wi.saveBlockData(s)},styles:f});return c.appendChild(p),c.appendChild(y),s.appendChild(c),s.appendChild(h),e.mountEditor(s,h,r),s}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",`${Fe(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}),Wi.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 i=t.getAttribute("data-language")||e.defaultLanguage;n.replaceChildren(...o(a.endsWith("\n")?`${a} `:a,i).map(e=>{const t=document.createElement("span");return e.classes&&(t.className=e.classes),t.textContent=e.text,t}))}static updateLanguage(t,n){const a=t.querySelector(`.${l.classNames.block.code.container}`);if(!a)return;const o=t.querySelector(`.${l.classNames.block.code.editor}`);if(!o)return;a.setAttribute("data-language",n);const i=a.querySelector(`.${l.classNames.block.code.header}`),r=a.getAttribute("data-theme")||e.defaultTheme,s=We(r),c=Fe(n);i&&(i.textContent=e.getHeaderText(c,s));const p=e.inputMap.get(a);p&&e.mountEditor(a,o,{code:p.value,language:n,theme:r}),Wi.saveBlockData(a)}static updateTheme(t,n){const a=t.querySelector(`.${l.classNames.block.code.container}`);if(!a)return;const o=t.querySelector(`.${l.classNames.block.code.editor}`);if(!o)return;a.setAttribute("data-theme",n);const i=a.querySelector(`.${l.classNames.block.code.header}`),r=a.getAttribute("data-language")||e.defaultLanguage,s=Fe(r),c=We(n);i&&(i.textContent=e.getHeaderText(s,c));const p=e.inputMap.get(a);p&&e.mountEditor(a,o,{code:p.value,language:r,theme:n}),Wi.saveBlockData(a)}static handleKeydown(e,t,n){const a=e.closest(`.${l.classNames.block.container}`);if(!a)return;const o=Wi.getEditorId(a);if(!o)return;const i=Wi.getBlockIndex(o,a.getAttribute("data-id")),r=n.metaKey||n.ctrlKey;return"Enter"!==n.key||n.shiftKey?"Backspace"===n.key&&r||"Delete"===n.key&&r?(n.preventDefault(),void Wi.removeBlock(o,i)):"Backspace"!==n.key||""!==t.value.trim()?"ArrowUp"===n.key?(n.preventDefault(),void(n.shiftKey?Wi.moveBlock(o,i,i-1):Wi.focusBlock(a.previousElementSibling))):void("ArrowDown"===n.key&&(n.preventDefault(),n.shiftKey?Wi.moveBlock(o,i,i+1):Wi.focusBlock(a.nextElementSibling))):void Wi.removeBlock(o,i):(n.preventDefault(),void Wi.insertBlock({data:{html:""},type:"paragraph"},o,i+1))}static getHeaderText(e,t){return`${e} | ${t}`}static isEmpty(t){const n=t.querySelector(`.${l.classNames.block.code.container}`);if(!n)return!0;const a=e.inputMap.get(n);return!a||Boolean(a.value?.trim())}static isEmptyData(e){return _(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(`.${l.classNames.block.code.container}`).forEach(t=>{e.inputMap.delete(t),e.dataMap.delete(t)})}},Ze=".clepit-output-code-container",Ye=(e,n)=>[`${e} { background: ${n.background}; color: ${n.text}; }`,...t.map(t=>`${e} .clepit-code-${t} { color: ${n[t]};${(e=>"comment"===e?" font-style: italic;":"")(t)} }`)].join("\n"),Qe=()=>[Ye(Ze,e()),...Object.entries(a).map(([e,t])=>Ye(`${Ze}[data-theme='${e}']`,t))].join("\n"),et="clepit:code-variant-sync",tt=e=>`clepit.code-variant.${e}`,nt=(e,t)=>e.label?e.label:e.language?Re[e.language]??e.language:`Tab ${t+1}`,at=(e,t)=>{if(!t)return 0;const n=e.findIndex((e,n)=>nt(e,n)===t);return-1===n?0:n},ot=e=>{if(!e||"undefined"==typeof localStorage)return null;try{return localStorage.getItem(tt(e))}catch{return null}},it="http://www.w3.org/2000/svg",rt=e=>e.variants?.length?e.variants:[{code:e.code,language:e.language}],st=class e{static{this.eventListenersMap=/* @__PURE__ */new WeakMap}static draw(t,n=ye,a){if(!e.validate(t)||Xe.isEmptyData(t))return null;const i=rt(t),r=i.length>1,s=Math.min(Math.max(a?.activeVariant??0,0),i.length-1),l=n.create("div");l.addClass("clepit-output-code-container"),l.setAttribute("data-theme",t.theme??Xe.defaultTheme),t.syncKey&&l.setAttribute("data-sync-key",t.syncKey);const c=n.create("div");if(c.addClass("clepit-output-code-header"),r){const e=n.create("div");e.addClass("clepit-output-code-tabs"),e.setAttribute("role","tablist"),e.setAttribute("data-testid","code-variant-tabs"),i.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===s?"true":"false"),o.setAttribute("tabindex",a===s?"0":"-1"),o.setAttribute("data-testid",`code-variant-tab-${a}`),o.setText(nt(t,a)),e.append(o)}),c.append(e)}else{const e=n.create("span");e.setText(Re[t.language??"typescript"]??"TypeScript"),c.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(it,"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(it,"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)),c.append(e)}l.append(c);const p=n.create("div");return p.addClass("clepit-output-code-editor"),r&&p.setAttribute("role","tabpanel"),i.forEach((e,a)=>{const i=n.create("pre");i.addClass("clepit-output-code-pane"),i.setAttribute("data-variant-index",String(a)),a!==s&&i.setAttribute("hidden","");const r=n.create("code");for(const s of o(e.code??t.code,e.language??t.language??"plaintext")){const e=n.create("span");s.classes&&e.addClass(...s.classes.split(" ")),e.setText(s.text),r.append(e)}i.append(r),p.append(i)}),l.append(p),l}static render(t,n,a,o,i){if(l.injectStyles(He,Pe),l.injectStyles(`${He}-theme`,Qe()),!e.validate(t))return Ne();if(Xe.isEmptyData(t))return document.createElement("div");const r=rt(t),s=r.length>1?at(r,ot(t.syncKey)):0,c=Se(e.draw(t,ye,{activeVariant:s}));o?.container&&c.classList.add(o.container),a?.container&&Object.assign(c.style,a.container);const p=c.querySelector(".clepit-output-code-header");return p&&o?.header?.text&&p.classList.add(o.header.text),p&&a?.header?.text&&Object.assign(p.style,a.header.text),e.attach(c,t,s,i),c}static activate(t,n){if(!e.validate(n)||Xe.isEmptyData(n))return()=>{};const a=rt(n),o=a.length>1?at(a,ot(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?at(o,ot(i)):0;return e.attach(t,r,s,void 0,!0)}static attach(t,n,a,o,i=!1){const r=rt(n),s=o?document.getElementById(o):null,l=[...t.querySelectorAll(".clepit-output-code-tab")],c=[...t.querySelectorAll(".clepit-output-code-pane")];let p=a;const d=[];let u;const h=(t,n,a)=>{if(t.addEventListener(n,a),d.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(p=e,l.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=nt(r[e],e);((e,t)=>{if(e&&"undefined"!=typeof localStorage)try{localStorage.setItem(tt(e),t)}catch{return}})(n.syncKey,a),window.dispatchEvent(new CustomEvent(et,{detail:{label:a,syncKey:n.syncKey}}))};if(l.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),l[o]?.focus())})}),l.length>1&&n.syncKey){const t=e=>{const t=e.detail;if(!t||t.syncKey!==n.syncKey)return;const a=r.findIndex((e,n)=>nt(e,n)===t.label);-1!==a&&a!==p&&g(a,!1)};if(window.addEventListener(et,t),d.push({event:et,handler:t,target:window}),s){const n=e.eventListenersMap.get(s)??[];n.push({element:window,event:et,handler:t}),e.eventListenersMap.set(s,n)}}const b=()=>{for(const{event:e,handler:t,target:n}of d)n.removeEventListener(e,t);u?.()};i&&g(a,!1);const f=t.querySelector(".clepit-output-code-copy-btn");if(!f)return b;h(f,"click",()=>{e.copyCodeToClipboard(r[p]?.code??n.code),e.animateCopyButton(f)});const y=o?m.getState().getInstance(o):null;return u=ee(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))}},lt={icon:"𝕔",get input(){return Xe},label:"Code",get output(){return st},shortcut:E("C"),testId:"block-type-code",type:"code"},ct="\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",pt=`${ct}\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`,dt=ct,ut=/* @__PURE__ */new WeakMap;var mt=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=ut.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 _i.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:j(n?.innerHTML),open:a}}static render(t,n,a){l.injectStyles("collapsible-input",pt);const o={children:[],html:"",open:!0},i=n?{...o,...n}:o,r=l.createStyledElement("details","clepit-collapsible clepit-collapsible--input",{classNames:a?.classNames?.section,styles:a?.styles?.section});r.open=i.open??!0,ut.set(r,[...i.children??[]]);const s=document.createElement("summary"),c=document.createElement("span");c.className="clepit-collapsible__title",c.setAttribute("contenteditable","true"),c.setAttribute("data-placeholder",e.placeholder),i.html&&(c.innerHTML=j(i.html)),s.appendChild(c),r.appendChild(s);const p=document.createElement("div");return p.className="clepit-collapsible__children",(i.children??[]).forEach(n=>{p.appendChild(e.renderChild(t,n))}),r.appendChild(p),e.addEventListener(t,c,"keydown",Wi.handleKeydown),e.addEventListener(t,c,"input",Wi.handleInput),r}static renderChild(e,t){const n=document.createElement("div");n.className="clepit-collapsible__child";const a=Wi.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 _(n?.innerHTML)&&!a}static isEmptyData(e){return _(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]=[])}},ht="\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",gt=ht,bt=ht,ft=class e{static render(t,n,a,o){if(l.injectStyles("collection-output",bt),!e.validate(t))return Ne();const i=l.createStyledElement("div","clepit-collection clepit-output-collection",{classNames:o?.wrapper,styles:a?.wrapper});i.setAttribute("data-collection-id",t.collectionId);const r=document.createElement("span");r.className="clepit-collection__icon",r.textContent="▦",i.appendChild(r);const s=document.createElement("span");return s.className="clepit-collection__label",s.textContent="Collection",i.appendChild(s),i}static draw(t,n=ye){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}},yt="\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",vt=`${yt}\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`,xt=yt,kt=class e{static render(t,n,a,o){if(l.injectStyles("columns-output",xt),!e.validate(t))return Ne();const i=l.createStyledElement("div","clepit-columns clepit-output-columns",{classNames:o?.container,styles:a?.container});for(const r of t.columns){const t=l.createStyledElement("div","clepit-columns__column",{classNames:o?.column,styles:a?.column});for(const a of r)t.appendChild(e.renderChild(a,n));i.appendChild(t)}return i}static renderChild(e,t){const n=_i.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=ye,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=Ho(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))}},wt="\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",Ct=`${wt}\n.clepit-date--input {\n cursor: pointer;\n border: none;\n font: inherit;\n}\n`,Et=wt,St=/^(\d{4})-(\d{2})-(\d{2})$/;function Nt(e){const t=St.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 At=class e{static render(t,n,a,o){l.injectStyles("date-output",Et);const i=e.validate(t)?Nt(t.date):null;if(!i)return Ne();const r=l.createStyledElement("time","clepit-date clepit-output-date",{classNames:o?.pill,styles:a?.pill});return r.dateTime=t.date,r.textContent=new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeZone:"UTC"}).format(i),r}static draw(t,n=ye){const a=e.validate(t)?Nt(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}},Lt='\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',Bt=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,a){l.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 o={variant:"line"},i=n?{...o,...n}:o,r=l.createStyledElement("div","clepit-delimiter-container",{classNames:a?.classNames?.[i.variant],styles:a?.styles?.[i.variant]});if(r.setAttribute("contenteditable","true"),r.setAttribute("tabindex","0"),"stars"===i.variant){const e=l.createStyledElement("div","clepit-delimiter",{classNames:a?.classNames?.[i.variant],styles:a?.styles?.[i.variant]});e.setAttribute("data-variant",i.variant),e.textContent="***",r.appendChild(e)}else{const e=l.createStyledElement("hr","clepit-delimiter",{classNames:a?.classNames?.[i.variant],styles:a?.styles?.[i.variant]});e.setAttribute("data-variant",i.variant),r.appendChild(e)}return e.addEventListener(t,r,"keydown",e=>{const n=e,a=r.closest(`.${l.classNames.block.container}`);if(!a)return;const o=Wi.getBlockIndex(t,a.getAttribute("data-id")),i=n.metaKey||n.ctrlKey;if(n.shiftKey)switch(n.key){case"ArrowUp":e.preventDefault(),e.stopPropagation(),o>0&&Wi.moveBlock(t,o,o-1);break;case"ArrowDown":e.preventDefault(),e.stopPropagation();const n=Wi.getBlocks(t);n&&o<n.length-1&&Wi.moveBlock(t,o,o+1)}else if(i)switch(n.key){case"Delete":case"Backspace":e.preventDefault(),e.stopPropagation(),Wi.removeBlock(t,o)}else if("Enter"===n.key)n.preventDefault(),n.stopPropagation(),Wi.insertBlock({data:{html:""},type:"paragraph"},t,o+1);else if("Backspace"===n.key)n.preventDefault(),n.stopPropagation(),Wi.removeBlock(t,o);else{Wi.ensureActiveBlock(t);const a=Wi.getBlocks(t);switch(n.key){case"ArrowUp":if(e.preventDefault(),e.stopPropagation(),o>0){const e=a[o-1];e&&Wi.focusBlock(e)}return;case"ArrowDown":if(e.preventDefault(),e.stopPropagation(),o<a.length-1){const e=a[o+1];e&&Wi.focusBlock(e)}return}}}),r.focus(),r}static changeVariant(t,n,a){const o=m.getState().getInstance(a);if(!o)return;if(t.getAttribute("data-variant")===n)return;const i={variant:n},r={classNames:o.config.classNames?.blocks?.delimiter,styles:o.config.styles?.blocks?.delimiter},s=Wi.getBlockIndex(a,t.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id")),c=e.render(a,i,r);t.replaceWith(c),m.getState().updateBlockData(a,s,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]=[])}},$t=class e{static render(t,n,a,o){if(l.injectStyles("clepit-delimiter-output-styles",Lt),!e.validate(t))return Ne();if(Bt.isEmptyData(t))return document.createElement("div");const i=t.variant,r=l.createStyledElement("div","clepit-output-delimiter",{classNames:o?.[i],styles:a?.[i]});if("stars"===i)r.innerHTML="***",r.setAttribute("data-variant","stars");else{const e=document.createElement("hr");e.setAttribute("data-variant","line"),e.className="clepit-delimiter",r.appendChild(e)}return r}static draw(t,n=ye){if(!e.validate(t)||Bt.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}},Mt="\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",It=Mt,Tt=Mt,qt=class e{static render(t,n,a,o){if(l.injectStyles("doc-card-output",Tt),!e.validate(t))return Ne();const i=l.createStyledElement("a","clepit-doc-card clepit-output-doc-card",{classNames:o?.card,styles:a?.card});i.setAttribute("data-page-id",t.pageId),n?.docHref&&(i.href=n.docHref(t.pageId));const r=document.createElement("span");r.className="clepit-doc-card__icon",r.textContent=t.icon??"📄",i.appendChild(r);const s=document.createElement("span"),c=document.createElement("span");if(c.className="clepit-doc-card__title",c.textContent=t.title||"Untitled",s.appendChild(c),t.description){const e=document.createElement("span");e.className="clepit-doc-card__description",e.textContent=t.description,s.appendChild(e)}return i.appendChild(s),i}static draw(t,n=ye,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}},Dt="\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",_t=Dt,jt=Dt,zt=["http:","https:"],Ot=["youtube.com","www.youtube.com","m.youtube.com","youtu.be"],Ht=["file","design","board","proto","slides","deck"],Pt=(e,t="link")=>({embedUrl:null,provider:t,url:e});function Rt(e,t){return e===t||e.endsWith(`.${t}`)}function Ft(e,t){const n=function(e){try{const t=new URL(e);return zt.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(Ot.includes(a)){const e=function(e){if(Rt(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}:Pt(o,"youtube")}if(Rt(a,"figma.com")){const[,e,t]=n.pathname.split("/");return e&&t&&Ht.includes(e)?{aspect:4/3,embedUrl:`https://embed.figma.com/${"file"===e?"design":e}/${encodeURIComponent(t)}?embed-host=clepit`,provider:"figma",url:o}:Pt(o,"figma")}if(Rt(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}:Pt(o,"miro")}if(Rt(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}:Pt(o,"airtable")}if(Rt(a,"diagrams.net")||Rt(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(Rt(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}:Pt(o,"googleMaps")}return Pt(o)}var Vt="allow-scripts allow-same-origin allow-presentation allow-forms",Ut=class e{static render(t,n,a,o){if(l.injectStyles("embed-output",jt),!e.validate(t))return Ne();const i=Ft(t.url,{mapsEmbedKey:n?.mapsEmbedKey});return"invalid"===i.provider?Ne():i.embedUrl?e.frame(i.embedUrl,i.aspect,a,o):e.card(t,i.url,a,o)}static draw(t,n=ye,a){if(!e.validate(t))return null;const o=Ft(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",Vt),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,a){const o=l.createStyledElement("div","clepit-embed clepit-output-embed",{classNames:a?.wrapper,styles:n?.wrapper}),i=document.createElement("iframe");return i.className="clepit-embed__frame",i.src=e,i.setAttribute("sandbox",Vt),i.setAttribute("referrerpolicy","no-referrer"),i.setAttribute("loading","lazy"),i.setAttribute("allowfullscreen","true"),i.style.aspectRatio=String(t??16/9),o.appendChild(i),o}static card(e,t,n,a){const o=l.createStyledElement("a","clepit-embed-card clepit-output-embed",{classNames:a?.card,styles:n?.card});o.href=t,o.rel="noopener noreferrer nofollow",o.target="_blank";const i=document.createElement("span"),r=document.createElement("span");if(r.className="clepit-embed-card__title",r.textContent=e.title||t,i.appendChild(r),e.description){const t=document.createElement("span");t.className="clepit-embed-card__description",t.textContent=e.description,i.appendChild(t)}return o.appendChild(i),o}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.url&&e.url.length>0}},Wt="\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",Kt=`${Wt}\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`,Gt=Wt;function Jt(e){return null==e?"":e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}var Xt=class e{static render(t,n,a,o){if(l.injectStyles("file-output",Gt),!e.validate(t))return Ne();const i=l.createStyledElement("a","clepit-file clepit-output-file",{classNames:o?.row,styles:a?.row});i.href=t.url,i.setAttribute("download",t.name),i.setAttribute("rel","noopener noreferrer");const r=document.createElement("span");r.className="clepit-file__name",r.textContent=t.name,i.appendChild(r);const s=Jt(t.size);if(s){const e=document.createElement("span");e.className="clepit-file__size",e.textContent=s,i.appendChild(e)}return i}static draw(t,n=ye){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=Jt(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)))}},Zt='\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',Yt="At a glance",Qt=class e{static render(t,n,a,o){if(l.injectStyles("clepit-glance-output-styles",Zt),!e.validate(t))return Ne();if(0===t.rows.length)return document.createElement("div");const i=l.createStyledElement("div","clepit-glance",{classNames:o?.wrapper,styles:a?.wrapper});i.setAttribute("data-variant",t.variant??"plain"),i.setAttribute("data-testid","glance");const r=q("p","clepit-glance-caption");r.textContent=t.caption?.trim()?t.caption:Yt,i.appendChild(r);const s=q("dl","clepit-glance-rows");for(const e of t.rows){const t=q("dt","clepit-glance-label");t.textContent=e.label,s.appendChild(t);const n=q("dd","clepit-glance-value");n.innerHTML=j(e.html),s.appendChild(n)}return i.appendChild(s),i}static draw(t,n=ye){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:Yt),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))}},en="\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\nh1.clepit-output-header {\n font-size: 2.5rem;\n line-height: 1.2;\n}\n\nh2.clepit-output-header {\n font-size: 2rem;\n line-height: 1.3;\n}\n\nh3.clepit-output-header {\n font-size: 1.75rem;\n line-height: 1.4;\n}\n\nh4.clepit-output-header {\n font-size: 1.5rem;\n line-height: 1.4;\n}\n\nh5.clepit-output-header {\n font-size: 1.25rem;\n line-height: 1.4;\n}\n\nh6.clepit-output-header {\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 h1.clepit-output-header {\n font-size: 2rem;\n }\n\n h2.clepit-output-header {\n font-size: 1.75rem;\n }\n\n h3.clepit-output-header {\n font-size: 1.5rem;\n }\n}\n",tn=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(`.${l.classNames.block.header}`),n=t?.getAttribute("data-level")||"h1";return{html:j(t?.innerHTML),level:n}}static render(t,n,a){l.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 o={html:"",level:"h1"},i=n?{...o,...n}:o,r=i.level??"h1",s=l.createStyledElement(r,l.classNames.block.header,{classNames:a?.classNames?.[r],styles:a?.styles?.[r]});return s.setAttribute("data-level",r),s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder",e.placeholder),i.html?s.innerHTML=i.html:s.innerHTML="",e.addEventListener(t,s,"keydown",Wi.handleKeydown),e.addEventListener(t,s,"input",Wi.handleInput),s}static changeLevel(t,n,a){const o=m.getState().getInstance(a);if(!o)return;if(t.getAttribute("data-level")===n)return;const i={html:t.innerHTML,level:n},r={classNames:o.config.classNames?.blocks?.header,margins:o.config.margins,styles:o.config.styles?.blocks?.header},s=Wi.getBlockIndex(a,t.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id")),c=e.render(a,i,r);t.replaceWith(c),m.getState().updateBlockData(a,s,i)}static isEmpty(e){return _(e.querySelector(`.${l.classNames.block.header}`)?.innerHTML)}static isEmptyData(e){return _(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]=[])}},nn=class e{static render(t,n,a,o){if(l.injectStyles("clepit-header-output-styles",en),!e.validate(t))return Ne();if(tn.isEmptyData(t))return document.createElement("div");const i=t.html,r=t.level||"h1",s=l.createStyledElement(r,"clepit-output-header",{classNames:o?.[r],styles:a?.[r]});return i&&(s.innerHTML=i),s}static draw(t,n=ye){if(!e.validate(t)||tn.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}},an=`\n/* Image block styles */\n.${l.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.${l.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.${l.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.${l.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.${l.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.${l.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.${l.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.${l.classNames.block.imageDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Image drop area delete button */\n.clepit-image-drop-area .${l.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 .${l.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`,on="\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",rn=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(`.${l.classNames.block.image.captionEditable}`),a=e.querySelector(".clepit-image-wrapper");let o="center";return a&&(o=a.classList.contains("clepit-image-wrapper--left")?"left":a.classList.contains("clepit-image-wrapper--right")?"right":"center"),{alignment:o,alt:t?.getAttribute("alt")||"",caption:j(n?.innerHTML),url:t?.getAttribute("src")||""}}static render(t,n,a,o){l.injectStyles("clepit-image-input-styles",an);const i={alt:"",caption:"",url:""},r=a?{...i,...a}:i,s=l.createStyledElement("div",l.classNames.block.image.container,{classNames:o?.classNames?.container,styles:o?.styles?.container});return r.url?e.renderImage(s,r,t,n,o):e.renderDropArea(s,t,n,o),s}static renderImage(t,n,a,o,i){t.innerHTML="";const r=l.createStyledElement("div",l.classNames.block.image.wrapper,{classNames:i?.classNames?.container,styles:i?.styles?.container});switch(r.setAttribute("tabindex","-1"),n?.alignment||"center"){case"left":r.classList.add("clepit-image-wrapper--left");break;case"center":r.classList.add("clepit-image-wrapper--center");break;case"right":r.classList.add("clepit-image-wrapper--right")}const s=l.createStyledElement("img","clepit-image",{classNames:i?.classNames?.container,styles:i?.styles?.container});s.alt=n?.alt||"",s.src=n?.url||"",s.classList.add("clepit-image");const c=l.createStyledElement("div","clepit-image-caption-container",{classNames:i?.classNames?.caption,styles:i?.styles?.caption});c.classList.add("clepit-image-caption-container");const p=l.createStyledElement("div",l.classNames.block.image.captionEditable,{classNames:i?.classNames?.caption,styles:i?.styles?.caption});p.setAttribute("contenteditable","true"),p.setAttribute("data-placeholder",e.placeholder),p.innerHTML=n?.caption||"",e.addEventListener(o,p,"keydown",Wi.handleKeydown),e.addEventListener(o,p,"input",Wi.handleInput),e.addEventListener(o,r,"click",()=>e.handleFileSelect(t,a,o,i)),r.appendChild(s),c.appendChild(p),t.appendChild(r),t.appendChild(c),p.focus()}static renderDropArea(t,n,a,o){t.innerHTML="";const i=l.createStyledElement("div",l.classNames.block.image.dropArea,{classNames:o?.classNames?.dropArea?.container,styles:o?.styles?.dropArea?.container});i.setAttribute("tabindex","0"),i.classList.add("clepit-drop-area");const r=l.createStyledElement("div","clepit-image-drop-icon",{classNames:o?.classNames?.dropArea?.icon,styles:o?.styles?.dropArea?.icon});r.textContent="📷";const s=l.createStyledElement("div","clepit-image-drop-text",{classNames:o?.classNames?.dropArea?.text,styles:o?.styles?.dropArea?.text});s.innerHTML='<strong>Drop an image here</strong><br>or <span class="clepit-image-click-text">click to select</span>';const c=l.createStyledElement("div","clepit-image-drop-subtext",{classNames:o?.classNames?.dropArea?.subtext,styles:o?.styles?.dropArea?.subtext});c.textContent="Supports JPEG, PNG, GIF, WebP, SVG, and other image formats";const p=l.createStyledElement("button",`${l.classNames.block.imageDeleteBtn}`,{classNames:o?.classNames?.dropArea?.deleteButton,styles:o?.styles?.dropArea?.deleteButton});p.type="button",p.textContent="✕",i.appendChild(r),i.appendChild(s),i.appendChild(c),i.appendChild(p);const d=m.getState().getInstance(a),u=d?.config.classNames?.tooltips,h=d?.config.styles?.tooltips;ee(p,"Delete block","below",u,h),e.addEventListener(a,p,"click",e=>{e.preventDefault(),e.stopPropagation();const t=p.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id");t&&Wi.removeBlock(a,Wi.getBlockIndex(a,t))}),e.addEventListener(a,i,"click",()=>e.handleFileSelect(t,n,a,o)),e.addEventListener(a,i,"dragleave",()=>{i.classList.remove("clepit-image-drop-area--dragover")}),e.addEventListener(a,i,"dragover",e=>{e.preventDefault(),e.stopPropagation(),i.classList.add("clepit-image-drop-area--dragover")}),e.addEventListener(a,i,"drop",r=>{r.preventDefault(),r.stopPropagation(),i.classList.remove("clepit-image-drop-area--dragover"),e.handleFileDrop(r,t,n,a,o)}),e.addEventListener(a,i,"focus",e=>{e.preventDefault(),e.stopPropagation()}),e.addEventListener(a,i,"mousedown",e=>{e.preventDefault(),e.stopPropagation()}),t.appendChild(i)}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,a,o,i){e.showLoading(n);try{let r=await a(t);if(r){e.renderImage(n,{alignment:"center",alt:t.name,caption:"",url:r},a,o,i);const s=n.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id");s&&m.getState().updateBlockData(o,Wi.getBlockIndex(o,s),Wi.getBlockData(s).data)}else e.showError(n,"Failed to upload image. Please try again.")}catch(r){console.error("Image upload error:",r),e.showError(n,"Failed to upload image. Please try again.")}}static showLoading(e){e.innerHTML="";const t=l.createStyledElement("div","clepit-image-loading",void 0);t.textContent="Uploading image...",e.appendChild(t)}static showError(e,t){e.innerHTML="";const n=l.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=Wi.getEditorId(e);if(!a)return;const o=e.getAttribute("data-id");o&&m.getState().partialUpdateBlockData(a,Wi.getBlockIndex(a,o),{alignment:t})}static isEmpty(e){const t=e.querySelector(`.${l.classNames.block.image.wrapper} img`),n=e.querySelector(`.${l.classNames.block.image.captionEditable}`);let a=!1,o=!1;return t&&t.getAttribute("src")?.trim()||(a=!0),n?_(n.innerHTML)&&(o=!0):o=!0,a&&o}static isEmptyData(e){return!e.url?.trim()&&_(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]=[])}},sn=class e{static render(t,n,a,o){if(l.injectStyles("clepit-image-output-styles",on),!e.validate(t))return Ne();if(rn.isEmptyData(t))return document.createElement("div");const i=t.url,r=t.caption,s=t.alt||r||"",c=l.createStyledElement("div","clepit-output-image-container",{classNames:o?.container,styles:a?.container}),p=l.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=q("img","clepit-output-image");if(d.src=i,d.alt=s,p.appendChild(d),c.appendChild(p),r){const e=l.createStyledElement("figcaption","clepit-output-image-caption",{classNames:o?.caption,styles:a?.caption}),n=t.caption;e.innerHTML=n&&n!==r?n:r,c.appendChild(e)}return c}static draw(t,n=ye){if(!e.validate(t)||rn.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}},ln="\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",cn=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(j(e.innerHTML))),{items:a,type:n}}static render(t,n,a){l.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 o={items:[],type:e.defaultType},i=n?{...o,...n}:o,r="ordered"===i.type?"ol":"ul",s=l.createStyledElement(r,l.classNames.block.list.container,{classNames:a?.classNames?.[i.type]?.container,styles:a?.styles?.[i.type]?.container});s.setAttribute("data-type",i.type);const c=a?.classNames?.[i.type]?.item,p=a?.styles?.[i.type]?.item;return i.items.length>0?i.items.forEach(n=>e.createAndAppendListItem(n,s,t,c,p)):e.createAndAppendListItem("",s,t,c,p),s}static createAndAppendListItem(t,n,a,o,i){const r=l.createStyledElement("li",l.classNames.block.list.item,{classNames:o,styles:i});r.innerHTML=t,r.setAttribute("contenteditable","true"),r.setAttribute("data-placeholder",e.placeholder),e.addEventListener(a,r,"keydown",t=>{const s=t,c=n.closest(`.${l.classNames.block.container}`);if(!c)return;const p=Wi.getBlockIndex(a,c.getAttribute("data-id")),d=s.metaKey||s.ctrlKey;if(s.shiftKey)switch(s.key){case"ArrowUp":t.preventDefault(),t.stopPropagation(),p>0&&Wi.moveBlock(a,p,p-1);break;case"ArrowDown":t.preventDefault(),t.stopPropagation();const e=Wi.getBlocks(a);e&&p<e.length-1&&Wi.moveBlock(a,p,p+1)}else if(d)switch(s.key){case"Delete":case"Backspace":t.preventDefault(),t.stopPropagation(),Wi.removeBlock(a,p)}else if("Enter"===s.key)if(t.preventDefault(),t.stopPropagation(),_(r.innerHTML)){e.cleanupEmptyItems(n);const t=n.closest(`.${l.classNames.block.container}`);if(!t)return;const o=Wi.getBlockIndex(a,t.getAttribute("data-id"));Wi.insertBlock({data:{html:""},type:"paragraph"},a,o+1)}else e.createAndAppendListItem("",n,a,o,i);else if("Backspace"===s.key){if(_(r.innerHTML)){t.preventDefault(),t.stopPropagation();const e=Array.from(n.querySelectorAll("li")),o=e.indexOf(r);if(1===e.length){const e=n.closest(`.${l.classNames.block.container}`);if(!e)return;const t=Wi.getBlockIndex(a,e.getAttribute("data-id"));if(-1===t)return;Wi.removeBlock(a,t)}else r.remove(),o>0?e[o-1].focus():e[o+1].focus()}}else{Wi.ensureActiveBlock(a);const e=Wi.getBlocks(a);switch(s.key){case"ArrowUp":t.preventDefault(),t.stopPropagation();const a=Array.from(n.querySelectorAll(`.${l.classNames.block.list.item}`)),o=a.indexOf(r);if(0===o){if(p>0){const t=e[p-1];t&&Wi.focusBlock(t)}}else{const e=a[o-1];e&&e.focus()}return;case"ArrowDown":t.preventDefault(),t.stopPropagation();const i=Array.from(n.querySelectorAll(`.${l.classNames.block.list.item}`)),s=i.indexOf(r);if(s===i.length-1){if(p<e.length-1){const t=e[p+1];t&&Wi.focusBlock(t)}}else{const e=i[s+1];e&&e.focus()}return}}}),e.addEventListener(a,r,"input",Wi.handleInput),n.appendChild(r),r.focus()}static changeType(t,n,a){const o=m.getState().getInstance(a);if(!o)return;if(t.getAttribute("data-type")===n)return;const i={items:[...t.querySelectorAll("li")||[]].map(e=>e.innerHTML),type:n},r={classNames:o.config.classNames?.blocks?.list,styles:o.config.styles?.blocks?.list},s=Wi.getBlockIndex(a,t.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id")),c=e.render(a,i,r);t.replaceWith(c),m.getState().updateBlockData(a,s,i)}static cleanupEmptyItems(e){const t=Array.from(e.querySelectorAll("li")),n=t.filter(e=>_(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(`.${l.classNames.block.list.item}`);return!t||Array.from(t).every(e=>_(e.innerHTML))}static isEmptyData(e){return 0===e.items.length||e.items.every(e=>_(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]=[])}},pn=class e{static render(t,n,a,o){if(l.injectStyles("clepit-list-output-styles",ln),!e.validate(t))return Ne();if(cn.isEmptyData(t))return document.createElement("div");const i=t.items,r="ordered"===t.type?"ordered":"unordered",s=l.createStyledElement("ordered"===r?"ol":"ul","clepit-output-list",{classNames:o?.[r]?.container,styles:a?.[r]?.container});return i.forEach((e,t)=>{const n=e,i=l.createStyledElement("li","clepit-output-list-item",{classNames:o?.[r]?.item,styles:a?.[r]?.item});n&&n.trim()&&(i.innerHTML=n),s.appendChild(i)}),s}static draw(t,n=ye){if(!e.validate(t)||cn.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}},dn="\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",un=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),mn=(e,t)=>{const n={children:[],cyclic:!1,nullable:!1,required:!1,type:"unknown"};if(!un(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=mn(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=>mn(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=mn(e.items,t);return n.type=`${a.ref??a.type}[]`,n.children.push(...a.children),n}return"object"===n.type&&((e,t,n)=>{if(!un(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=mn(i,n);e.name=o,e.required=a.includes(o),t.children.push(e)}})(e,n,t),n},hn=(e,t)=>mn(e,{schemas:t,stack:/* @__PURE__ */new Set}),gn=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),bn=e=>{if(!gn(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"}},fn=e=>{if(!gn(e)||!gn(e.properties))return;const t={};for(const[n,a]of Object.entries(e.properties))t[n]=bn(a);return t},yn=e=>e.security[0],vn=(e,t)=>{return`${t}${n=e.path,n.replace(/\{([^}]+)\}/g,":$1")}`;var n},xn={bash:{build:(e,t)=>{const n=[`curl -X ${e.method} "${vn(e,t)}"`],a=yn(e);var o;a&&n.push(` -H "Authorization: Bearer $${o=a,o.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toUpperCase()}"`);const i=fn(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=fn(e.request),a=e.method.toLowerCase(),o=[` Uri.parse('${vn(e,t)}'),`],i=[],r=yn(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=fn(e.request),a=e.method.toLowerCase(),o=[` "${vn(e,t)}",`],i=yn(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=fn(e.request),a=[],o=yn(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('${vn(e,t)}', {`,...i,"});","","const data = await response.json();"].join("\n")},label:"TypeScript"}},kn=["bash","typescript","dart","python"],wn=["get","post","put","patch","delete"],Cn=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),En=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,""),Sn=(e,t,n)=>!!e&&(!!e.tags?.some(e=>t.includes(e))||(e.paths?.includes(n)??!1)),Nn=e=>(Array.isArray(e.parameters)?e.parameters:[]).filter(Cn).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}})),An=e=>Cn(e.responses)?Object.entries(e.responses).map(([e,t])=>{const n=Cn(t)?t:{},a=Cn(n.content)?n.content:void 0,o=a&&Cn(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}}):[],Ln=e=>{if(!Cn(e.requestBody))return;const t=Cn(e.requestBody.content)?e.requestBody.content:void 0;return(t&&Cn(t["application/json"])?t["application/json"]:void 0)?.schema},Bn=e=>{if(!Array.isArray(e.security))return[];const t=e.security.find(Cn);return t?Object.keys(t):[]},$n=e=>{if(!Array.isArray(e.servers))return;const t=e.servers.find(Cn);return"string"==typeof t?.url?t.url:void 0},Mn=(e,t)=>e[0]??t.split("/").filter(Boolean)[0]??"default",In=(e,t)=>{const n=Cn(e)?e:{},a=Cn(n.info)?n.info:{},o=Cn(n.components)?n.components:{},i={groups:[],schemas:Cn(o.schemas)?o.schemas:{},servers:(Array.isArray(n.servers)?n.servers:[]).filter(Cn).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=Cn(n.paths)?n.paths:{},s=/* @__PURE__ */new Map;for(const[l,c]of Object.entries(r))if(Cn(c))for(const e of wn){const n=c[e];if(!Cn(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(Sn(t.exclude,a,l))continue;if(t.include&&!i&&!Sn(t.include,a,l))continue;const r={..."string"==typeof n.description?{description:n.description}:{},id:En(`${e}-${l}`),internal:o,method:e.toUpperCase(),params:Nn(n),path:l,...void 0===Ln(n)?{}:{request:Ln(n)},responses:An(n),security:Bn(n),...void 0===$n(n)?{}:{server:$n(n)},summary:"string"==typeof n.summary?n.summary:l,tags:a},p=Mn(a,l),d=s.get(p);d?d.operations.push(r):s.set(p,{id:En(p),operations:[r],title:p})}return i.groups=[...s.values()],i},Tn=(e,t,n,a)=>{const o=e.create(t);return n&&o.addClass(...n.split(" ")),void 0!==a&&o.setText(a),o},qn=(e,t)=>{const n=Tn(e,"div","clepit-openapi-table-scroll");return n.append(t),n},Dn=(e,t,n,a)=>{const o=Tn(e,"p","clepit-openapi-section-title",t);return o.setAttribute("data-testid",`openapi-section-${n}-${a}`),o},_n=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},jn=(e,t=0)=>t>6?_n(e):e.type.endsWith("[]")?0===e.children.length?[]:[Object.fromEntries(e.children.map(e=>[e.required?e.name:`${e.name}?`,jn(e,t+1)]))]:e.children.length>0?Object.fromEntries(e.children.map(e=>[e.required?e.name:`${e.name}?`,jn(e,t+1)])):_n(e),zn=e=>{const t=Number.parseInt(e,10);return t>=200&&t<300?"success":t>=400&&t<500?"client":t>=500?"server":"other"},On=(e,t,n,a)=>{const o=Tn(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=Tn(e,"div","clepit-openapi-operation-head"),s=Tn(e,"span","clepit-openapi-method",t.method);s.setAttribute("data-method",t.method),s.setAttribute("data-testid",`openapi-method-${t.id}`);const l=Tn(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=Tn(e,"span","clepit-openapi-host",i);n.setAttribute("data-testid",`openapi-host-${t.id}`),r.append(n)}o.append(r);const c=Tn(e,"div","clepit-openapi-operation-body"),p=Tn(e,"h3","clepit-openapi-summary",t.summary);p.setAttribute("id",t.id),c.append(p),t.description&&c.append(Tn(e,"p","clepit-openapi-description",t.description));const d=Tn(e,"div","clepit-openapi-security");d.setAttribute("data-testid",`openapi-security-${t.id}`),d.append(Tn(e,"span","clepit-openapi-section-title","Auth")),d.appendText(" "),d.append(Tn(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=Tn(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(Tn(e,"th","clepit-openapi-th",i));a.append(o);for(const i of t.params){const t=e.create("tr"),o=Tn(e,"td","clepit-openapi-name",i.name);i.required&&o.append(Tn(e,"span","clepit-openapi-required"," required")),t.append(o),t.append(Tn(e,"td","clepit-openapi-cell",i.in)),t.append(Tn(e,"td","clepit-openapi-type",_n(hn(i.schema,n.schemas)))),t.append(Tn(e,"td","clepit-openapi-cell",i.description??"")),a.append(t)}return a})(e,t,n);if(u&&(c.append(Dn(e,"Parameters","parameters",t.id)),c.append(qn(e,u))),void 0!==t.request){const a=hn(t.request,n.schemas);if(a.children.length>0){c.append(Dn(e,"Body","body",t.id));const n=Tn(e,"div","clepit-openapi-body");n.setAttribute("data-testid",`openapi-body-${t.id}`);const o=st.draw({code:JSON.stringify(jn(a),null,2),language:"json",showCopy:!0},e);o&&n.append(o),c.append(n)}}t.responses.length>0&&(c.append(Dn(e,"Responses","responses",t.id)),c.append(((e,t,n)=>{const a=Tn(e,"div","clepit-openapi-responses");a.setAttribute("data-testid",`openapi-responses-${t.id}`);const o=Tn(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=Tn(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=Tn(e,"p","clepit-openapi-response-description");if(r){const t=Tn(e,"span","clepit-openapi-status",a.status);t.setAttribute("data-kind",zn(a.status)),c.append(t),c.appendText(` ${a.description}`)}else c.setText(a.description);if(l.append(c),void 0!==a.schema){const t=hn(a.schema,n.schemas);if(t.children.length>0){const n=st.draw({code:JSON.stringify(jn(t),null,2),language:"json",showCopy:!0},e);n&&l.append(n)}}i.push(l);const p=Tn(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",zn(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=xn[n];return a?[{code:a.build(e,t),label:a.label,language:n}]:[]}))(t,i,a.snippetLanguages??kn);if(m.length>0){c.append(Dn(e,"Try it","try-it",t.id));const n=st.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},Hn=class e{static draw(t,n=ye){if(!e.validate(t))return null;const a=In(t.spec,t),o=Tn(n,"div","clepit-openapi");if(a.servers.length>0){const e=Tn(n,"table","clepit-openapi-table clepit-openapi-servers");e.setAttribute("data-testid","openapi-servers");const t=n.create("tr");t.append(Tn(n,"th","clepit-openapi-th","Host")),t.append(Tn(n,"th","clepit-openapi-th","Serves")),e.append(t);for(const o of a.servers){const t=n.create("tr");t.append(Tn(n,"td","clepit-openapi-name",o.url)),t.append(Tn(n,"td","clepit-openapi-cell",o.description??"")),e.append(t)}o.append(qn(n,e))}for(const e of a.groups){const i=Tn(n,"section","clepit-openapi-group");i.setAttribute("data-testid",`openapi-group-${e.id}`);const r=Tn(n,"h2","clepit-openapi-group-title",e.title);r.setAttribute("id",e.id),i.append(r);for(const o of e.operations)i.append(On(n,o,a,t));o.append(i)}return o}static render(t,n,a,o){if(l.injectStyles("clepit-openapi-output-styles",dn),!e.validate(t))return Ne();const i=Se(e.draw(t,ye));o?.container&&i.classList.add(o.container),a?.container&&Object.assign(i.style,a.container),e.attach(i);for(const e of[...i.querySelectorAll(".clepit-output-code-container")])st.activateFromMarkup(e);return i}static activate(t){const n=[e.attach(t)];for(const e of[...t.querySelectorAll(".clepit-output-code-container")])n.push(st.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))}},Pn="\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",Rn=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:j(e.querySelector(`.${l.classNames.block.paragraph}`)?.innerHTML)}}static render(t,n,a){l.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 o=l.createStyledElement("div",l.classNames.block.paragraph,{classNames:a?.classNames,styles:a?.styles});return o.setAttribute("contenteditable","true"),o.setAttribute("data-placeholder",e.placeholder),o.innerHTML=n?.html||"",e.addEventListener(t,o,"keydown",Wi.handleKeydown),e.addEventListener(t,o,"input",Wi.handleInput),o}static isEmpty(e){return _(e.querySelector(`.${l.classNames.block.paragraph}`)?.innerHTML)}static isEmptyData(e){return _(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]=[])}},Fn=class e{static render(t,n,a,o){if(l.injectStyles("clepit-paragraph-output-styles",Pn),!e.validate(t))return Ne();const i=l.createStyledElement("p","clepit-output-paragraph",{classNames:o,styles:a});if(Rn.isEmptyData(t))return i.appendChild(document.createElement("br")),i;const r=t.html;return r&&(i.innerHTML=r),i}static draw(t,n=ye){if(!e.validate(t))return null;const a=n.create("p");return a.addClass("clepit-output-paragraph"),Rn.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}},Vn=`\n/* Quote block styles */\n.${l.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.${l.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.${l.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.${l.classNames.block.quote.author}:focus {\n outline: none;\n}\n\n.${l.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.${l.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.${l.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.${l.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.${l.classNames.block.quote.text} a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Quote inline code styling */\n.${l.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`,Un="\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",Wn=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(`.${l.classNames.block.quote.text}`),n=e.querySelector(`.${l.classNames.block.quote.author}`);return{author:j(n?.innerHTML),html:j(t?.innerHTML)}}static render(t,n,a){l.injectStyles("clepit-quote-input-styles",Vn);const o=n||{author:"",html:""},i=l.createStyledElement("div",l.classNames.block.quote.container,{classNames:a?.classNames?.container,styles:a?.styles?.container}),r=l.createStyledElement("div",l.classNames.block.quote.text,{classNames:a?.classNames?.text,styles:a?.styles?.text}),s=l.createStyledElement("div",l.classNames.block.quote.author,{classNames:a?.classNames?.author,styles:a?.styles?.author});if(r.innerHTML=o.html||"",r.setAttribute("contenteditable","true"),r.setAttribute("data-placeholder",e.placeholder),s.innerHTML=o.author||"",s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder",e.authorPlaceholder),e.addEventListener(t,r,"keydown",e.handleKeydown),e.addEventListener(t,r,"input",Wi.handleInput),e.addEventListener(t,s,"keydown",e.handleKeydown),e.addEventListener(t,s,"input",Wi.handleInput),i.appendChild(r),o.author){const e=l.createStyledElement("div",l.classNames.block.quote.divider,{classNames:a?.classNames?.divider,styles:a?.styles?.divider});i.appendChild(e)}return i.appendChild(s),i}static handleKeydown(e){const t=e,n=e.currentTarget,a=n.closest(`.${l.classNames.block.container}`),o=Wi.getEditorId(a);if(!o)return;const i=Wi.getBlockIndex(o,a.getAttribute("data-id")),r=a.querySelector(`.${l.classNames.block.quote.text}`),s=a.querySelector(`.${l.classNames.block.quote.author}`),c=t.metaKey||t.ctrlKey;if(t.shiftKey)switch(t.key){case"ArrowUp":e.preventDefault(),e.stopPropagation(),i>0&&Wi.moveBlock(o,i,i-1);break;case"ArrowDown":e.preventDefault(),e.stopPropagation();const t=Wi.getBlocks(o);t&&i<t.length-1&&Wi.moveBlock(o,i,i+1)}else if(c)switch(t.key){case"Delete":case"Backspace":e.preventDefault(),e.stopPropagation(),Wi.removeBlock(o,i)}else if("Enter"===t.key)t.preventDefault(),t.stopPropagation(),Wi.insertBlock({data:{html:""},type:"paragraph"},o,i+1);else if("Backspace"===t.key){if(!_(n.innerHTML))return;t.preventDefault(),t.stopPropagation(),n===r?Wi.removeBlock(o,i):n===s&&(_(r.innerHTML)?Wi.removeBlock(o,i):r.focus())}else if("ArrowUp"===t.key)if(t.preventDefault(),t.stopPropagation(),n===r){const e=a.previousElementSibling;e&&Wi.focusBlock(e)}else r.focus();else if("ArrowDown"===t.key)if(t.preventDefault(),t.stopPropagation(),n===s){const e=a.nextElementSibling;e&&Wi.focusBlock(e)}else s.focus()}static handleKeydownInAuthorInput(e){const t=e,n=e.currentTarget,a=n.closest(`.${l.classNames.block.container}`),o=Wi.getEditorId(a);if(o)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=a.querySelector(`.${l.classNames.block.quote.text}`);e&&e.focus()}}else{t.preventDefault(),t.stopPropagation();const e=Wi.getBlockIndex(o,a.getAttribute("data-id"));Wi.insertBlock({data:{html:""},type:"paragraph"},o,e+1)}}static isEmpty(e){const t=e.querySelector(`.${l.classNames.block.quote.text}`),n=e.querySelector(`.${l.classNames.block.quote.author}`);let a=!1,o=!1;return t?_(t.innerHTML)&&(a=!0):a=!0,n?_(n.innerHTML)&&(o=!0):o=!0,a&&o}static isEmptyData(e){return _(e.html)&&_(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]=[])}},Kn=class e{static render(t,n,a,o){if(l.injectStyles("clepit-quote-output-styles",Un),!e.validate(t))return Ne();if(Wn.isEmptyData(t))return document.createElement("div");const i=t.html,r=t.author||"",s=l.createStyledElement("div","clepit-output-quote-container",{classNames:o?.container,styles:a?.container}),c=l.createStyledElement("div","clepit-output-quote-text",{classNames:o?.text,styles:a?.text}),p=q("div","clepit-output-quote-content");if(i&&i.trim()&&(p.innerHTML=i),c.appendChild(p),s.appendChild(c),r){const e=l.createStyledElement("div","clepit-output-quote-divider",{classNames:o?.divider,styles:a?.divider});s.appendChild(e);const t=l.createStyledElement("div","clepit-output-quote-author",{classNames:o?.author,styles:a?.author});t.textContent=`— ${r}`,s.appendChild(t)}return s.querySelectorAll(`span.${l.classNames.block.tooltip}[data-tooltip]`).forEach(e=>{const t=e;t.hasAttribute("data-tooltip-initialized")||(ee(t,String(t.getAttribute("data-tooltip")||""),"above",n?.tooltipClassNames,void 0),t.setAttribute("data-tooltip-initialized","true"))}),s}static draw(t,n=ye){if(!e.validate(t)||Wn.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}},Gn="\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",Jn=Gn,Xn=Gn,Zn="http://www.w3.org/2000/svg";function Yn(e){return e&&/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(e.trim())?e.trim():"#000000"}function Qn(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 ea=class e{static render(t,n,a,o){if(l.injectStyles("sketch-output",Xn),!e.validate(t))return Ne();const i=l.createStyledElement("div","clepit-sketch clepit-output-sketch",{classNames:o?.wrapper,styles:a?.wrapper}),r=document.createElementNS(Zn,"svg");r.setAttribute("class","clepit-sketch__canvas"),r.setAttribute("viewBox","0 0 1000 240"),r.setAttribute("preserveAspectRatio","none"),r.setAttribute("role","img");for(const s of t.strokes??[]){const t=Qn(s.points??[]);if(!t)continue;const n=document.createElementNS(Zn,"path");n.setAttribute("d",t),n.setAttribute("fill","none"),n.setAttribute("stroke",Yn(s.color)),n.setAttribute("stroke-width",String(e.safeWidth(s))),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),r.appendChild(n)}return i.appendChild(r),i}static draw(t,n=ye){if(!e.validate(t))return null;const a=n.create("div");a.addClass("clepit-sketch","clepit-output-sketch");const o=n.createNS(Zn,"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=Qn(i.points??[]);if(!t)continue;const a=n.createNS(Zn,"path");a.setAttribute("d",t),a.setAttribute("fill","none"),a.setAttribute("stroke",Yn(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)}},ta=`\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.${l.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.${l.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) .${l.classNames.block.table.cell} {\n background: var(--clepit-bg);\n}\n\n.clepit-table-tbody tr:nth-child(even) .${l.classNames.block.table.cell} {\n background: var(--clepit-surface);\n}\n\n.${l.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.${l.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.${l.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.${l.classNames.block.table.headerCell}[data-placeholder]:empty::before,\n.${l.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.${l.classNames.block.table.headerCell}:hover .clepit-col-handle,\n.clepit-table-row:hover .clepit-row-delete,\n.${l.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`,na="\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",aa=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 a=n.querySelector("thead tr"),o=a?Array.from(a.querySelectorAll(`.${l.classNames.block.table.headerCell}`)):[],i=[],r=[];for(const e of o){const t=e.cloneNode(!0);t.querySelectorAll(".clepit-col-handle, .clepit-col-delete").forEach(e=>e.remove()),r.push(j(t.innerHTML))}i.push(r);const s=n.querySelectorAll("tbody tr");for(const e of Array.from(s)){const t=Array.from(e.querySelectorAll(`.${l.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(j(t.innerHTML))}i.push(n)}const c=(t.querySelector(".clepit-table-download-switch")?.querySelector('input[type="checkbox"]'))?.checked||!1;return{caption:j(t.querySelector(`.${l.classNames.block.table.caption}`)?.innerHTML||""),data:i,showDownload:c}}static render(t,n,a){l.injectStyles("clepit-table-input-styles",ta);const o=n?{...e.defaultData,...n}:e.defaultData,i=l.createStyledElement("div","clepit-table-container",{classNames:a?.classNames?.container,styles:a?.styles?.container}),r=l.createStyledElement("table","clepit-table",{classNames:a?.classNames?.table,styles:a?.styles?.table}),s=l.createStyledElement("thead","clepit-table-thead",{classNames:a?.classNames?.table,styles:a?.styles?.table}),c=e.createRow(t,o.data[0],!0);s.appendChild(c),r.appendChild(s);const p=l.createStyledElement("tbody","clepit-table-tbody",{classNames:a?.classNames?.table,styles:a?.styles?.table});for(let l=1;l<o.data.length;l++){const n=e.createRow(t,o.data[l]);p.appendChild(n)}r.appendChild(p);const d=l.createStyledElement("div","clepit-table-scroll-container");d.appendChild(r),i.appendChild(d);const u=l.createStyledElement("button","clepit-table-btn clepit-row-menu-btn",{classNames:a?.classNames?.rowMenuButton,styles:a?.styles?.rowMenuButton});u.style.position="absolute",u.style.display="none",u.style.zIndex="1000",u.textContent="⋮",i.appendChild(u);const h=l.createStyledElement("button","clepit-table-btn clepit-col-menu-btn",{classNames:a?.classNames?.columnMenuButton,styles:a?.styles?.columnMenuButton});h.style.position="absolute",h.style.display="none",h.style.zIndex="1000",h.textContent="⋯",i.appendChild(h);let g=null,b=-1,f=null;e.addEventListener(t,i,"mouseleave",()=>(u.style.display="none",h.style.display="none",void(f&&(f.remove(),f=null))));const v=e=>{g=e;const t=e.getBoundingClientRect(),n=i.getBoundingClientRect(),a=t.top-n.top+t.height/2-12;u.style.left="4px",u.style.top=`${Math.max(4,a)}px`,u.style.display="flex"},w=e=>{if(b=Array.from(c.querySelectorAll(`.${l.classNames.block.table.headerCell}`)).indexOf(e),b<0)return;const t=e.getBoundingClientRect(),n=i.getBoundingClientRect(),a=t.left-n.left+t.width/2-12,o=t.top-n.top-20;h.style.left=`${a}px`,h.style.top=`${Math.max(4,o)}px`,h.style.display="flex"};e.addEventListener(t,p,"mouseover",e=>{const t=e.target.closest("tr");t&&v(t)}),e.addEventListener(t,s,"mouseover",e=>{const t=e.target.closest(`.${l.classNames.block.table.headerCell}`);t&&w(t)}),e.addEventListener(t,p,"mouseover",e=>{const t=e.target.closest(`.${l.classNames.block.table.cell}`);if(!t)return;const n=t.closest("tr");if(!n)return;const a=Array.from(n.querySelectorAll(`.${l.classNames.block.table.cell}`)).indexOf(t);if(a>=0){const e=c.querySelectorAll(`.${l.classNames.block.table.headerCell}`)[a];e&&w(e)}v(n)});const C=()=>{g&&"none"!==u.style.display&&v(g);const e=c.querySelectorAll(`.${l.classNames.block.table.headerCell}`)[b];e&&"none"!==h.style.display&&w(e)};e.addEventListener(t,window,"scroll",C,{passive:!0}),e.addEventListener(t,d,"scroll",C,{passive:!0}),e.addEventListener(t,u,"click",n=>{if(n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation?.(),!g)return;const o=Array.from(p.querySelectorAll("tr")),r=o.indexOf(g),s=u.getBoundingClientRect(),d=i.getBoundingClientRect();e.createMenu(t,i,u,h,[{label:"Move up",onClick:()=>{r>0&&(p.insertBefore(g,o[r-1]),Wi.saveBlockData(g))},shortcut:y("up")},{label:"Move down",onClick:()=>{r>=0&&r<o.length-1&&(p.insertBefore(o[r+1],g),Wi.saveBlockData(g))},shortcut:y("down")},{label:"Insert above",onClick:()=>{const n=c.querySelectorAll(`.${l.classNames.block.table.headerCell}`).length||3,a=e.createRow(t,Array.from({length:n},()=>""));p.insertBefore(a,g),Wi.saveBlockData(g)},shortcut:S("up")},{label:"Insert below",onClick:()=>{const n=c.querySelectorAll(`.${l.classNames.block.table.headerCell}`).length||3,a=e.createRow(t,Array.from({length:n},()=>""));g.nextSibling?p.insertBefore(a,g.nextSibling):p.appendChild(a),Wi.saveBlockData(g)},shortcut:S("down")},{label:"Delete",onClick:()=>{o.length>1&&(g.remove(),Wi.saveBlockData(g))},shortcut:x()}],s.left-d.left,s.bottom-d.top+4,a,f)}),e.addEventListener(t,h,"click",n=>{if(n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation?.(),b<0)return;const o=Array.from(c.querySelectorAll(`.${l.classNames.block.table.headerCell}`)),r=h.getBoundingClientRect(),s=i.getBoundingClientRect();e.createMenu(t,i,u,h,[{label:"Move left",onClick:()=>{if(b<=0)return;const e=b,t=o[e-1],n=o[e];t&&n&&c.insertBefore(n,t),p.querySelectorAll("tr").forEach(t=>{const n=Array.from(t.querySelectorAll(`.${l.classNames.block.table.cell}`)),a=n[e-1],o=n[e];a&&o&&t.insertBefore(o,a)}),b=e-1,Wi.saveBlockData(c)},shortcut:y("left")},{label:"Move right",onClick:()=>{const e=b;if(e<0||e>=o.length-1)return;const t=o[e],n=o[e+1];t&&n&&c.insertBefore(n,t),p.querySelectorAll("tr").forEach(t=>{const n=Array.from(t.querySelectorAll(`.${l.classNames.block.table.cell}`)),a=n[e],o=n[e+1];a&&o&&t.insertBefore(o,a)}),b=e+1,Wi.saveBlockData(c)},shortcut:y("right")},{label:"Insert left",onClick:()=>{const n=b,a=e.createHeaderCell(t,"");c.insertBefore(a,o[n]),p.querySelectorAll("tr").forEach(a=>{const o=e.createCell(t,""),i=a.querySelectorAll(`.${l.classNames.block.table.cell}`);i[n]?a.insertBefore(o,i[n]):a.appendChild(o)}),Wi.saveBlockData(c)},shortcut:S("left")},{label:"Insert right",onClick:()=>{const n=b+1,a=o[b]?.nextSibling||null,i=e.createHeaderCell(t,"");c.insertBefore(i,a),p.querySelectorAll("tr").forEach(a=>{const o=e.createCell(t,""),i=a.querySelectorAll(`.${l.classNames.block.table.cell}`);i[n]?a.insertBefore(o,i[n]):a.appendChild(o)}),Wi.saveBlockData(c)},shortcut:S("right")},{label:"Delete",onClick:()=>{const e=c.querySelectorAll(`.${l.classNames.block.table.headerCell}`);if(b<0||e.length<=1)return;const t=e[b];t?.parentElement?.removeChild(t),p.querySelectorAll("tr").forEach(e=>{const t=e.querySelectorAll(`.${l.classNames.block.table.cell}`);t[b]&&t[b].parentElement?.removeChild(t[b])}),Wi.saveBlockData(c)},shortcut:k()}],r.left-s.left,r.bottom-s.top+4,a,f)});Array.from(p.querySelectorAll("tr")).forEach(n=>(n=>{e.addEventListener(t,n,"mouseenter",()=>v(n))})(n)),Array.from(c.querySelectorAll(`.${l.classNames.block.table.headerCell}`)).forEach(n=>{return a=n,void e.addEventListener(t,a,"mouseenter",()=>w(a));var a});const E=l.createStyledElement("div","clepit-table-caption-download-container",{classNames:a?.classNames?.container,styles:a?.styles?.container});E.style.display="flex",E.style.alignItems="center",E.style.gap="8px",E.style.marginTop="8px";const N=l.createStyledElement("div",`${l.classNames.block.table.caption}`,{classNames:a?.classNames?.caption,styles:a?.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=j(o.caption),e.addEventListener(t,N,"input",Wi.handleInput),e.addEventListener(t,N,"keydown",e.handleKeydown),e.addEventListener(t,N,"click",e.handleClick),E.appendChild(N);const A=l.createStyledElement("div",`${l.classNames.block.table.downloadSwitch}`);A.style.flexShrink="0";const L=Je.create({checked:o.showDownload||!1,label:"Allow download",onToggle:e=>{const n=i.closest(`.${l.classNames.block.container}`);if(n){const a=n.getAttribute("data-id");a&&m.getState().partialUpdateBlockData(t,Wi.getBlockIndex(t,a),{showDownload:e})}}});A.appendChild(L),E.appendChild(A),i.appendChild(E);return e.addEventListener(t,i,"focusin",()=>{const e=document.activeElement;if(e&&i.contains(e))if(e.classList.contains(l.classNames.block.table.cell)){const t=e.closest("tr");t&&(g=t,v(t))}else e.classList.contains(l.classNames.block.table.headerCell)&&w(e)}),i}static createRow(t,n,a){const o=m.getState().getInstance(t),i=o?.config.classNames?.blocks?.table?.row,r=o?.config.styles?.blocks?.table?.row,s=l.createStyledElement("tr",a?`${l.classNames.block.table.headerRow}`:`${l.classNames.block.table.row}`,{classNames:i,styles:r});for(let l=0;l<n.length;l++)s.appendChild(a?e.createHeaderCell(t,n[l]):e.createCell(t,n[l]));return s.querySelector(`.${l.classNames.block.table.cell}`)?.focus(),s}static createCell(t,n){const a=m.getState().getInstance(t),o=a?.config.classNames?.blocks?.table?.cell,i=a?.config.styles?.blocks?.table?.cell,r=l.createStyledElement("td",`${l.classNames.block.table.cell}`,{classNames:o,styles:i});return r.contentEditable="true",r.setAttribute("tabindex","0"),r.setAttribute("data-placeholder",e.cellPlaceholder),r.innerHTML=j(n),e.addEventListener(t,r,"input",Wi.handleInput),e.addEventListener(t,r,"keydown",e.handleKeydown),e.addEventListener(t,r,"click",e.handleClick),r}static createHeaderCell(t,n){const a=m.getState().getInstance(t),o=a?.config.classNames?.blocks?.table?.header,i=a?.config.styles?.blocks?.table?.header,r=l.createStyledElement("th",`${l.classNames.block.table.headerCell}`,{classNames:o,styles:i});return r.contentEditable="true",r.setAttribute("tabindex","0"),r.setAttribute("data-placeholder",e.headerPlaceholder),r.innerHTML=j(n),e.addEventListener(t,r,"input",Wi.handleInput),e.addEventListener(t,r,"keydown",e.handleKeydown),e.addEventListener(t,r,"click",e.handleClick),r}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=Wi.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=Wi.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,a,o,i,r,s,c,p){p&&(p.remove(),p=null);const d=l.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=`${r}px`,d.style.top=`${s}px`,d.style.minWidth="180px",i.forEach(n=>{const a="delete"===n.label.toLowerCase(),o=l.createStyledElement("div","clepit-menu-item"+(a?" clepit-menu-item--danger":""),{classNames:c?.classNames?.menuItem,styles:c?.styles?.menuItem});o.style.fontSize="14px";const i=l.createStyledElement("span","clepit-menu-icon"),r=n.label.toLowerCase();r.includes("move up")?i.textContent="↑":r.includes("move down")?i.textContent="↓":r.includes("move left")?i.textContent="←":r.includes("move right")?i.textContent="→":r.includes("insert")?i.textContent="+":r.includes("delete")?i.textContent="×":i.textContent="•";const s=l.createStyledElement("span","clepit-menu-text");if(s.textContent=n.label,o.appendChild(i),o.appendChild(s),n.shortcut){const e=l.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,o.appendChild(e)}e.addEventListener(t,o,"click",e=>{e.stopPropagation(),e.stopImmediatePropagation?.(),n.onClick(),p&&(p.remove(),p=null)}),d.appendChild(o)}),n.appendChild(d),p=d;const u=e=>{d.contains(e.target)||e.target===a||e.target===o||(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(`.${l.classNames.block.container}`);t&&Wi.setActiveBlock(t)}static handleKeydown(e){const t=e,n=e.currentTarget,a=Wi.getEditorId(n);if(!a)return;const o=n.closest(`.${l.classNames.block.container}`);if(!o)return;const i=Wi.getBlockIndex(a,o.getAttribute("data-id")),r=t.metaKey||t.ctrlKey;if(t.shiftKey)switch(t.key){case"ArrowUp":e.preventDefault(),e.stopPropagation(),i>0&&Wi.moveBlock(a,i,i-1);break;case"ArrowDown":e.preventDefault(),e.stopPropagation();const t=Wi.getBlocks(a);t&&i<t.length-1&&Wi.moveBlock(a,i,i+1)}else if(r){const o=n.closest("table"),r=o.querySelector("tbody"),s=o.querySelector("thead tr");switch(t.key){case"ArrowUp":if(n.classList.contains(l.classNames.block.table.cell)){e.preventDefault(),e.stopPropagation();const t=n.closest("tr"),a=Array.from(r.querySelectorAll("tr")),o=a.indexOf(t);if(o>0){const e=Array.from(t.querySelectorAll(`.${l.classNames.block.table.cell}`)).indexOf(n);r.insertBefore(t,a[o-1]),Wi.saveBlockData(t);const i=t.querySelectorAll(`.${l.classNames.block.table.cell}`)[e];i&&i.focus()}}break;case"ArrowDown":if(n.classList.contains(l.classNames.block.table.cell)){e.preventDefault(),e.stopPropagation();const t=n.closest("tr"),a=Array.from(r.querySelectorAll("tr")),o=a.indexOf(t);if(o>=0&&o<a.length-1){const e=Array.from(t.querySelectorAll(`.${l.classNames.block.table.cell}`)).indexOf(n);r.insertBefore(a[o+1],t),Wi.saveBlockData(t);const i=t.querySelectorAll(`.${l.classNames.block.table.cell}`)[e];i&&i.focus()}}break;case"ArrowLeft":let t=-1;const c=Array.from(s.querySelectorAll(`.${l.classNames.block.table.headerCell}`));if(n.classList.contains(l.classNames.block.table.headerCell))t=c.indexOf(n);else if(n.classList.contains(l.classNames.block.table.cell)){const e=n.closest("tr");t=Array.from(e.querySelectorAll(`.${l.classNames.block.table.cell}`)).indexOf(n)}if(t>0){e.preventDefault(),e.stopPropagation();const a=t,i=c[a-1],r=c[a];if(i&&r&&s.insertBefore(r,i),o.querySelectorAll("tbody tr").forEach(e=>{const t=Array.from(e.querySelectorAll(`.${l.classNames.block.table.cell}`)),n=t[a-1],o=t[a];n&&o&&e.insertBefore(o,n)}),n.classList.contains(l.classNames.block.table.cell)){const e=n.closest("tr").querySelectorAll(`.${l.classNames.block.table.cell}`)[a-1];e&&e.focus()}else{r&&r.focus()}Wi.saveBlockData(s)}break;case"ArrowRight":let p=-1;const d=Array.from(s.querySelectorAll(`.${l.classNames.block.table.headerCell}`));if(n.classList.contains(l.classNames.block.table.headerCell))p=d.indexOf(n);else if(n.classList.contains(l.classNames.block.table.cell)){const e=n.closest("tr");p=Array.from(e.querySelectorAll(`.${l.classNames.block.table.cell}`)).indexOf(n)}if(p<d.length-1){e.preventDefault(),e.stopPropagation();const t=p,a=d[t],i=d[t+1];if(a&&i&&s.insertBefore(i,a),o.querySelectorAll("tbody tr").forEach(e=>{const n=Array.from(e.querySelectorAll(`.${l.classNames.block.table.cell}`)),a=n[t],o=n[t+1];a&&o&&e.insertBefore(o,a)}),n.classList.contains(l.classNames.block.table.cell)){const e=n.closest("tr").querySelectorAll(`.${l.classNames.block.table.cell}`)[t+1];e&&e.focus()}else{i&&i.focus()}Wi.saveBlockData(s)}break;case"Backspace":if(n.classList.contains(l.classNames.block.table.cell)){e.preventDefault(),e.stopPropagation();const t=n.closest("tr");Array.from(r.querySelectorAll("tr")).length>1&&(t.remove(),Wi.saveBlockData(t))}else e.preventDefault(),e.stopPropagation(),Wi.removeBlock(a,i);break;case"Delete":let u=-1;const m=Array.from(s.querySelectorAll(`.${l.classNames.block.table.headerCell}`));if(n.classList.contains(l.classNames.block.table.headerCell))u=m.indexOf(n);else if(n.classList.contains(l.classNames.block.table.cell)){const e=n.closest("tr");u=Array.from(e.querySelectorAll(`.${l.classNames.block.table.cell}`)).indexOf(n)}if(u>=0&&m.length>1){e.preventDefault(),e.stopPropagation();const t=m[u];t?.parentElement?.removeChild(t),o.querySelectorAll("tbody tr").forEach(e=>{const t=e.querySelectorAll(`.${l.classNames.block.table.cell}`);t[u]&&t[u].parentElement?.removeChild(t[u])}),Wi.saveBlockData(s)}else e.preventDefault(),e.stopPropagation(),Wi.removeBlock(a,i)}}else if("Enter"===t.key)e.preventDefault(),e.stopPropagation(),Wi.insertBlock({data:{html:""},type:"paragraph"},a,i+1);else if("Backspace"===t.key){const t=n.closest(`.${l.classNames.block.container}`);if(!t)return;Array.from(t.querySelectorAll(`.${l.classNames.block.table.cell},.${l.classNames.block.table.headerCell}`)).every(e=>_(e.innerHTML))&&(e.preventDefault(),e.stopPropagation(),Wi.removeBlock(a,i))}else{Wi.ensureActiveBlock(a);const o=Wi.getBlocks(a);switch(t.key){case"ArrowUp":if(e.preventDefault(),e.stopPropagation(),n.classList.contains(l.classNames.block.table.caption)){const e=n.closest(`.${l.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 a=n.closest("tr"),r=Array.from(a?.cells||[]).indexOf(n);if("TBODY"===a?.parentElement?.tagName&&a===a.parentElement.firstElementChild){const e=t.querySelector("thead")?.querySelector("tr");if(e&&e.cells[r])return void e.cells[r].focus()}if(a?.previousElementSibling){const e=a.previousElementSibling.cells[r];e&&e.focus()}else if(i>0){const e=o[i-1];e&&Wi.focusBlock(e)}return;case"ArrowDown":if(e.preventDefault(),e.stopPropagation(),n.classList.contains(l.classNames.block.table.caption)){if(i<o.length-1){const e=o[i+1];e&&Wi.focusBlock(e)}return}const s=n.closest("table");if(!s)return;const c=n.closest("tr"),p=Array.from(c?.cells||[]).indexOf(n);if("THEAD"===c?.parentElement?.tagName){const e=s.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=s.closest(`.${l.classNames.block.container}`)?.querySelector(`.${l.classNames.block.table.caption}`);if(e)return void e.focus()}if(i<o.length-1){const e=o[i+1];e&&Wi.focusBlock(e)}}return;case"ArrowLeft":if(!z(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(!z(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(`.${l.classNames.block.table.caption}`),n=e.querySelectorAll(`.${l.classNames.block.table.cell},.${l.classNames.block.table.headerCell}`);let a=!1,o=!1;return t?_(t.innerHTML)&&(a=!0):a=!0,n?Array.from(n).every(e=>_(e.innerHTML))&&(o=!0):o=!0,a&&o}static isEmptyData(e){return _(e.caption)&&e.data.every(e=>e.every(e=>_(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]=[])}},oa="http://www.w3.org/2000/svg",ia=["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"],ra=class e{static{this.eventListenersMap=/* @__PURE__ */new WeakMap}static render(t,n,a,o,i){if(l.injectStyles("clepit-table-output-styles",na),!e.validate(t))return Ne();if(aa.isEmptyData(t))return document.createElement("div");const r=e.draw(t,ye);if(!r)return document.createElement("div");const s=Se(r);o?.container&&s.classList.add(o.container),a?.container&&Object.assign(s.style,a.container);const c=s.querySelector(".clepit-output-table-caption");c&&o?.caption&&c.classList.add(o.caption),c&&a?.caption&&Object.assign(c.style,a.caption);const p=s.querySelector(".clepit-output-table-footer-container");return p&&o?.footerContainer&&p.classList.add(o.footerContainer),p&&a?.footerContainer&&Object.assign(p.style,a.footerContainer),e.attach(s,t,a,o,i),s}static activate(t,n){return!e.validate(n)||aa.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 l=i?document.getElementById(i):null;if(l){const t=e.eventListenersMap.get(l)??[];t.push({element:r,event:"click",handler:s}),e.eventListenersMap.set(l,t)}const c=i?m.getState().getInstance(i):null,p=ee(r,"Download CSV","above",c?.config.classNames?.tooltips,c?.config.styles?.tooltips);return()=>{r.removeEventListener("click",s),p()}}static draw(t,n=ye){if(!e.validate(t)||aa.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(oa,"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 ia){const a=e.createNS(oa,"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))}},sa="\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",la=sa,ca=sa,pa={h1:0,h2:1,h3:2,h4:3,h5:4,h6:5},da=class{static render(e,t,n,a){l.injectStyles("toc-output",ca);const o=(t?.documentBlocks??[]).filter(e=>"header"===e.type),i=l.createStyledElement("nav","clepit-toc clepit-output-toc",{classNames:a?.list,styles:n?.list});if(0===o.length){const e=document.createElement("div");return e.className="clepit-toc__empty",e.textContent="Table of contents — headings appear here",i.appendChild(e),i}return o.forEach((e,t)=>{const o=e.data,r=l.createStyledElement("a","clepit-toc__entry",{classNames:a?.entry,styles:n?.entry});r.setAttribute("data-toc-index",t.toString());const s=pa[o.level??"h1"];r.style.paddingLeft=16*s+"px",e.id&&(r.href=`#${e.id}`),r.innerHTML=j(o.html),i.appendChild(r)}),i}static draw(e,t=ye,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*pa[a.level??"h1"]}px;`),e.id&&i.setAttribute("href",`#${e.id}`),i.setHtml(a.html),o.append(i)}),o}},ua="\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",ma=ua,ha=ua,ga=.55,ba=.52,fa=(e,t,n)=>e.draw.map(e=>({...e,x:e.x+t,y:e.y+n}));function ya(e,t=18){switch(e.kind){case"atom":return va(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=ya(r,t);n.push(...fa(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=ya(e.base,t),a=xa(t),o=[...n.draw];let i=n.width,r=n.height,s=n.depth;if(null!==e.sup){const s=ya(e.sup,a),l=Math.max(.62*n.height,.4*t);o.push(...fa(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=ya(e.sub,a),l=Math.max(.5*n.depth,.22*t);o.push(...fa(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=ya(e.numerator,t),a=ya(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:[...fa(n,(s-n.width)/2,l),{kind:"rule",thickness:i,width:s,x:0,y:-o},...fa(a,(s-a.width)/2,c)],height:-l+n.height,width:s}}(e,t);case"radical":return function(e,t){const n=ya(e.radicand,t),a=.6*t,o=null===e.index?null:ya(e.index,xa(xa(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},...fa(n,i+.12*t,0)];null!==o&&s.push(...fa(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=va(e.symbol,"upright",n),o=xa(t),i=null===e.upper?null:ya(e.upper,o),r=null===e.lower?null:ya(e.lower,o),s=Math.max(a.width,i?.width??0,r?.width??0),l=[...fa(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(...fa(i,(s-i.width)/2,-e)),c=e+i.height}if(null!==r){const e=a.depth+r.height+.16*t;l.push(...fa(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=ya(e.base,t),a=va(e.over,"upright",xa(t)),o="_"===e.over;return{depth:o?n.depth+.2*t:n.depth,draw:[...n.draw,...fa(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=ya(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}:va(e.open,"upright",o),r=""===e.close?{depth:0,draw:[],height:0,width:0}:va(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:[...fa(i,0,s(i)),...fa(n,i.width,0),...fa(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=>ya(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(...fa(n,e+(a-n.width)/2,u)),e+=a+s}u+=(r[v]??0)+l}const[m,h]=ka[e.style],g=Math.max(t,.62*p),b=""===m?{depth:0,draw:[],height:0,width:0}:va(m,"upright",g),f=""===h?{depth:0,draw:[],height:0,width:0}:va(h,"upright",g),y=e=>(e.height-e.depth)/2;return{depth:p/2,draw:[...fa(b,0,y(b)),...d.map(e=>({...e,x:e.x+b.width})),...fa(f,b.width+c,y(f))],height:p/2,width:b.width+c+f.width}}(e,t)}}function va(e,t,n){const a="italic"===t?ga:ba;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 xa(e){return Math.max(9,.7*e)}var ka={bracket:["[","]"],"double-pipe":["‖","‖"],paren:["(",")"],pipe:["|","|"],plain:["",""]};var wa={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:"ζ"},Ca={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:"→"},Ea={bigcap:"⋂",bigcup:"⋃",int:"∫",lim:"lim",oint:"∮",prod:"∏",sum:"∑"},Sa=["arccos","arcsin","arctan","cos","cosh","cot","csc","deg","det","dim","exp","gcd","ln","log","max","min","sec","sin","sinh","tan","tanh"],Na={bar:"‾",ddot:"¨",dot:"˙",hat:"^",tilde:"~",vec:"→"},Aa={",":3,";":5,":":4,"!":-3,qquad:36,quad:18},La={".":"","(":"(",")":")","[":"[","]":"]","\\{":"{","\\}":"}","\\|":"‖","|":"|"},Ba=["catcode","csname","def","href","include","input","newcommand","renewcommand","url","write"],$a={bmatrix:"bracket",matrix:"plain",pmatrix:"paren",Vmatrix:"double-pipe",vmatrix:"pipe"},Ma=/[A-Za-z0-9+\-=<>()[\]|,./!:;]/,Ia=/[A-Za-z]/,Ta=/[0-9]/,qa={mathbf:"bold",mathit:"italic",mathrm:"upright",text:"text"},Da=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,!Ia.test(this.peek()))return this.take();let e="";for(;Ia.test(this.peek());)e+=this.take();return e}},_a=class extends Error{};function ja(e){const t=new Da(e);try{const e=za(t,null);if(Ha(t))throw new _a("a \\right appears without a matching \\left");if(!t.done)throw new _a(`"${t.peek()}" is unexpected here`);return{ok:!0,root:e}}catch(n){if(n instanceof _a)return{ok:!1,reason:n.message};throw n}}function za(e,t){const n=[];for(;(e.skipSpace(),!e.done)&&("}"!==t||"}"!==e.peek())&&("]"!==t||"]"!==e.peek())&&("cell"!==t||"&"!==e.peek()&&!Oa(e)&&!Pa(e))&&!Ha(e);){const t=Ra(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 Oa(e){return"\\"===e.peek()&&"\\"===e.peek(1)}function Ha(e){return!!e.source.startsWith("\\right",e.at)&&!Ia.test(e.peek(6))}function Pa(e){return"\\"===e.peek()&&e.source.startsWith("\\end",e.at)}function Ra(e){const t=Fa(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=Fa(e);if(null===o)throw new _a(`"${t}" has nothing after it`);if("^"===t){if(null!==a)throw new _a("a term carries two superscripts");a=o}else{if(null!==n)throw new _a("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 Fa(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=za(e,"}");if("}"!==e.peek())throw new _a("a { group is never closed");return e.take(),t}if("\\"===t)return function(e){const t=e.readCommand();if(Ba.includes(t))throw new _a(`"\\${t}" is refused for safety, not merely unsupported`);if("\\"===t)throw new _a("a row break appears outside a matrix");if("begin"===t)return function(e){const t=Ua(e),n=$a[t];if(void 0===n)throw new _a(`the "${t}" environment is not supported yet`);const a=[];let o=[];for(let i=0;i<4096;i+=1)if(o.push(za(e,"cell")),e.skipSpace(),"&"!==e.peek()){if(!Oa(e)){if(Pa(e)){e.at+=4;const i=Ua(e);if(i!==t)throw new _a(`\\begin{${t}} is closed by \\end{${i}}`);return a.push(o),{kind:"matrix",rows:a,style:n}}throw new _a(`\\begin{${t}} is never closed`)}e.at+=2,a.push(o),o=[]}else e.take();throw new _a(`\\begin{${t}} is never closed`)}(e);if("end"===t)throw new _a("an \\end appears without a matching \\begin");if("frac"===t||"dfrac"===t||"tfrac"===t){const t=Va(e);return{denominator:Va(e),kind:"fraction",numerator:t}}if("sqrt"===t)return function(e){e.skipSpace();let t=null;if("["===e.peek()){if(e.take(),t=za(e,"]"),"]"!==e.peek())throw new _a("a \\sqrt index is never closed");e.take()}return{index:t,kind:"radical",radicand:Va(e)}}(e);if("left"===t)return function(e){const t=Wa(e,"left"),n=za(e,null);if(!Ha(e))throw new _a("a \\left has no matching \\right");return e.at+=6,{body:n,close:Wa(e,"right"),kind:"delimited",open:t}}(e);if("right"===t)throw new _a("a \\right appears without a matching \\left");const n=qa[t];if(void 0!==n)return{kind:"atom",style:n,text:Ua(e)};const a=Na[t];if(void 0!==a)return{base:Va(e),kind:"accent",over:a};if("overline"===t)return{base:Va(e),kind:"accent",over:"‾"};if("underline"===t)return{base:Va(e),kind:"accent",over:"_"};const o=Ea[t];if(void 0!==o)return{kind:"bigop",lower:null,symbol:o,upper:null};const i=wa[t];if(void 0!==i)return{kind:"atom",style:"italic",text:i};const r=Ca[t];if(void 0!==r)return{kind:"atom",style:"upright",text:r};if(Sa.includes(t))return{kind:"atom",style:"upright",text:t};const s=Aa[t];if(void 0!==s)return{kind:"space",width:s};const l=La[`\\${t}`];if(void 0!==l)return{kind:"atom",style:"upright",text:l};throw new _a(`"\\${t}" is not supported yet`)}(e);if(Ma.test(t))return e.take(),{kind:"atom",style:Ta.test(t)?"upright":"italic",text:t};throw new _a(`"${t}" is not a character this engine understands`)}function Va(e){if(e.skipSpace(),"{"!==e.peek()){const t=Fa(e);if(null===t)throw new _a("a command is missing its argument");return t}e.take();const t=za(e,"}");if("}"!==e.peek())throw new _a("a { group is never closed");return e.take(),t}function Ua(e){if(e.skipSpace(),"{"!==e.peek())throw new _a("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 _a("a text command’s { group is never closed")}function Wa(e,t){e.skipSpace();const n=e.peek();if("\\"===n){const t=e.readCommand(),n=La[`\\${t}`];if(void 0===n)throw new _a(`"\\${t}" is not a delimiter this engine understands`);return n}const a=La[n];if(void 0===a)throw new _a(`\\${t} is missing a delimiter`);return e.take(),a}var Ka={bold:{style:"normal",weight:"700"},italic:{style:"italic",weight:"400"},text:{style:"normal",weight:"400"},upright:{style:"normal",weight:"400"}};function Ga(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 Ja(e,t=ye){const n=e.width+16,a=e.height+e.depth+16,o=e.height+8,i=Ga("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=Ka[r.style],n=Ga("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(Xa(r,o,t)):i.append(Ga("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 Xa(e,t,n){const a=e.x+8,o=t+e.y-e.height,i=t+e.y,r=.32*e.size;return Ga("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 Za=72,Ya=40,Qa=28,eo=16;function to(e){return"flowchart"===e.kind?function(e){const t="LR"===e.direction||"RL"===e.direction,n=function(e){const t=/* @__PURE__ */new Map;for(const a of e.nodes)t.set(a.id,0);const n=function(e){const t=/* @__PURE__ */new Map;for(const o of e.edges)t.set(o.from,[...t.get(o.from)??[],o]);const n=/* @__PURE__ */new Map,a=/* @__PURE__ */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=/* @__PURE__ */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=/* @__PURE__ */new Map;for(const b of e.nodes)o.set(b.id,no(b.label,Za));const i=/* @__PURE__ */new Map,r=[...a.keys()].sort((e,t)=>e-t),s=e=>t?e.length*Ya+(e.length-1)*Qa:e.reduce((e,t)=>e+(o.get(t)??Za),0)+(e.length-1)*Qa,l=Math.max(...r.map(e=>s(a.get(e)??[])),0);for(const b of r){const n=a.get(b)??[],r=eo+b*((t?Za:Ya)+64);let c=eo+(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)??Za;i.set(a,{height:Ya,id:a,label:n.label,shape:n.shape,width:s,x:t?r:c,y:t?c:r}),c+=(t?Ya:s)+Qa}}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)+eo,kind:"flowchart",nodes:c,width:g+eo}}(e):function(e){const t=[];let n=eo;for(const m of e.participants){const e=no(m.label,96);t.push({actor:m.actor,centerX:n+e/2,headHeight:36,headWidth:e,id:m.id,label:m.label}),n+=e+Qa}const a=e=>t.find(t=>t.id===e)?.centerX??null,o=[],i=[],r=[],s=/* @__PURE__ */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=no(m.text,96),n=Math.min(...e),o=Math.max(...e),r="left"===m.placement?n-t-Qa:"right"===m.placement?o+Qa:(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-Qa+eo,d+eo);return{activations:r,height:p+eo,kind:"sequence",lifelineBottom:p,lifelines:t,messages:o,notes:i,width:u}}(e)}function no(e,t){return Math.max(t,Math.round(7.2*e.length)+32)}var ao=["BT","LR","RL","TB","TD"],oo=["subgraph","end","click","style","classDef","class","linkStyle","direction"],io=["loop","alt","else","opt","par","and","critical","option","break","rect","box","autonumber","end"],ro=[{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:"->"}],lo=[{close:"]]",open:"[[",shape:"subroutine"},{close:"])",open:"([",shape:"stadium"},{close:"))",open:"((",shape:"circle"},{close:"]",open:"[",shape:"rect"},{close:"}",open:"{",shape:"rhombus"},{close:")",open:"(",shape:"round"}],co=e=>({ok:!1,reason:e});function po(e){return e.split(/[\s(]/,1)[0]??""}function uo(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 co("the block is empty");const[n,...a]=t,o=po(n??"");return"sequenceDiagram"===o?function(e){const t=/* @__PURE__ */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=po(o);if(io.includes(e))return co(`"${e}" is not supported yet`);if("participant"===e||"actor"===e){const n=yo(o,e);if(null===n)return co(`"${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(!fo(t))return co(`"${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=vo(o);if(null===e)return co(`"${o}" is not a note this engine understands`);for(const t of e.targets)a(t);n.push(e);continue}const i=xo(o);if(null===i)return co(`"${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(po(e).length).trim();if(0===n.length)return co('the flowchart header is missing a direction, e.g. "flowchart TD"');const a=ao.find(e=>e===n);if(void 0===a)return co(`"${n}" is not a supported direction — use TD, TB, BT, LR or RL`);const o=/* @__PURE__ */new Map,i=[];for(const r of t){const e=po(r);if(oo.includes(e))return co(`"${e}" is not supported yet`);if(r.includes("&"))return co('"&" fan-out is not supported yet');const t=mo(r,o,i);if(null!==t)return co(t)}return{model:{direction:a,edges:i,kind:"flowchart",nodes:[...o.values()]},ok:!0}}(n??"",a):co(`"${o}" diagrams are not supported yet — only flowchart and sequenceDiagram are`)}function mo(e,t,n){const a=function(e){const t=[],n=[];let a=e.trim();for(let o=0;o<64;o+=1){const e=ho(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=bo(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 ho(e){const t=function(e){const t=/--\s+([^->|][^-]*?)\s+(-->|---|-\.->|-\.-|==>|===)/.exec(e);if(null===t||void 0===t.index)return null;const n=ro.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 ro){const t=e.indexOf(a.token);if(-1===t)continue;if(null!==n&&t>=n.at)continue;const o=go(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 go(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 bo(e){const t=e.trim();if(0===t.length)return null;for(const n of lo){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(fo(a))return{id:a,label:o.trim(),shape:n.shape}}return fo(t)?{id:t,label:t,shape:"rect"}:null}function fo(e){return/^[A-Za-z_][\w-]*$/.test(e)}function yo(e,t){const n=e.slice(t.length).trim(),a=/ as /.exec(n),o=(null===a?n:n.slice(0,a.index)).trim();if(!fo(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 vo(e){const t=e.slice(po(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(fo)?{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 fo(s)?{kind:"note",placement:(r[1]??"").toLowerCase(),targets:[s],text:o}:null}function xo(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(fo(t)&&fo(s))return{activate:"+"===r,deactivate:"-"===r,end:o.end,from:t,kind:"message",line:o.line,text:a,to:s}}return null}var ko={dotted:"5 4",solid:"",thick:""},wo={dotted:1.5,solid:1.5,thick:3};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 Eo(e,t,n,a,o){const i=Co("text",{class:a,"dominant-baseline":"middle","text-anchor":"middle",x:t,y:n},o);return i.setText(e),i}function So(e,t=ye){const n=Co("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=Co("defs",{},e),n=Co("marker",{id:"clepit-mermaid-arrow",markerHeight:7,markerUnits:"strokeWidth",markerWidth:7,orient:"auto-start-reverse",refX:7,refY:3.5},e);return n.append(Co("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)Ao(e,a,n);for(const a of t.nodes)No(e,a,n)}(n,e,t):function(e,t,n){for(const a of t.lifelines){e.append(Co("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(Co("rect",o,n)),e.append(Eo(a.label,a.centerX,16+a.headHeight/2,"clepit-typeset__label",n))}for(const a of t.activations)e.append(Co("rect",{class:"clepit-typeset__activation",height:a.height,width:a.width,x:a.x,y:a.y},n));for(const a of t.messages)Lo(e,a,n);for(const a of t.notes)e.append(Co("rect",{class:"clepit-typeset__note",height:a.height,width:a.width,x:a.x,y:a.y},n)),e.append(Eo(a.text,a.x+a.width/2,a.y+a.height/2,"clepit-typeset__label",n))}(n,e,t),n}function No(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 Co("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 Co("polygon",{...s,points:e},t)}if("stadium"===a)return Co("rect",{...s,height:n,rx:n/2,ry:n/2,width:o,x:i,y:r},t);if("round"===a)return Co("rect",{...s,height:n,rx:10,ry:10,width:o,x:i,y:r},t);if("subroutine"===a){const e=Co("g",{},t);return e.append(Co("rect",{...s,height:n,rx:8,ry:8,width:o,x:i,y:r},t)),e.append(Co("line",{...s,x1:i+6,x2:i+6,y1:r,y2:r+n},t)),e.append(Co("line",{...s,x1:i+o-6,x2:i+o-6,y1:r,y2:r+n},t)),e}return Co("rect",{...s,height:n,rx:8,ry:8,width:o,x:i,y:r},t)}(t,n)),e.append(Eo(t.label,t.x+t.width/2,t.y+t.height/2,"clepit-typeset__label",n))}function Ao(e,t,n){const[a,o]=t.points;if(void 0===a||void 0===o)return;const i=t.points.length>2?Co("polyline",{class:"clepit-typeset__edge",fill:"none",points:t.points.map(e=>`${e.x},${e.y}`).join(" "),"stroke-dasharray":ko[t.line],"stroke-width":wo[t.line]},n):Co("line",{class:"clepit-typeset__edge","stroke-dasharray":ko[t.line],"stroke-width":wo[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=Eo(t.label,t.labelX,t.labelY,"clepit-typeset__edge-label",n);a.setAttribute("paint-order","stroke"),e.append(a)}}function Lo(e,t,n){const a={class:"clepit-typeset__message","stroke-dasharray":ko[t.line],"stroke-width":wo[t.line]};if(t.selfCall){const o=`M ${t.fromX} ${t.y} h 28 v 18 h -28`,i=Co("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(Eo(t.text,t.fromX+52,t.y+9,"clepit-typeset__edge-label",n))}const o=Co("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(Co("line",{...a,x1:o-5,x2:o+5,y1:t.y-5,y2:t.y+5},n)),e.append(Co("line",{...a,x1:o-5,x2:o+5,y1:t.y+5,y2:t.y-5},n))}e.append(Eo(t.text,(t.fromX+t.toX)/2,t.y-8,"clepit-typeset__edge-label",n))}var Bo=class e{static render(t,n,a,o,i){if(l.injectStyles("typeset-output",ha),!e.validate(n))return Ne();const r=l.createStyledElement("div",`clepit-typeset clepit-output-typeset clepit-typeset--${t.toLowerCase()}`,{classNames:i?.wrapper,styles:o?.wrapper});if(r.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"),r.appendChild(e)}if("Mermaid"===t){const a=uo(n.source);return a.ok?(r.setAttribute("data-rendered","diagram"),r.appendChild(Se(So(to(a.model)))),r):e.appendFallback(r,n.source,a.reason,t)}if(0===n.source.trim().length)return e.appendFallback(r,n.source,null,t);const s=ja(n.source);return s.ok?(r.setAttribute("data-rendered","formula"),r.appendChild(Se(Ja(ya(s.root)))),r):e.appendFallback(r,n.source,s.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=ye){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=uo(n.source);return r.ok?(o.setAttribute("data-rendered","diagram"),i(),o.append(So(to(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=ja(n.source);return r.ok?(o.setAttribute("data-rendered","formula"),i(),o.append(Ja(ya(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)}},$o=class{static render(e,t,n,a){return Bo.render("LaTeX",e,t,n,a)}static draw(e,t=ye){return Bo.draw("LaTeX",e,t)}},Mo=class{static render(e,t,n,a){return Bo.render("Mermaid",e,t,n,a)}static draw(e,t=ye){return Bo.draw("Mermaid",e,t)}},Io="\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",To=Io,qo=Io,Do=class{static render(e,t,n,a){l.injectStyles("updates-output",qo);const o=l.createStyledElement("div","clepit-updates clepit-output-updates",{classNames:a?.wrapper,styles:n?.wrapper});e?.pageId&&o.setAttribute("data-page-id",e.pageId);const i=document.createElement("span");i.className="clepit-updates__icon",i.textContent="🕘",o.appendChild(i);const r=document.createElement("span");return r.className="clepit-updates__label",r.textContent="Updates",o.appendChild(r),o}static draw(e,t=ye){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}},_o=`\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.${l.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.${l.classNames.block.videoDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Video drop area delete button */\n.clepit-video-drop-area .${l.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 .${l.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`,jo="\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",zo=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"),a=e.querySelector(`.${l.classNames.block.video.captionEditable}`),o=e.querySelector(`.${l.classNames.block.video.wrapper}`);let i="center";o&&(i=o.classList.contains("clepit-video-wrapper--left")?"left":o.classList.contains("clepit-video-wrapper--right")?"right":"center");let r="",s="";return t?(r=t.getAttribute("src")||"",s=t.getAttribute("alt")||""):n&&(r=n.getAttribute("src")||"",s="Embedded video"),{alignment:i,alt:s,caption:j(a?.innerHTML),url:r}}static render(t,n,a,o){l.injectStyles("clepit-video-input-styles",_o);const i=a||{alt:"",caption:"",url:""},r=l.createStyledElement("div",l.classNames.block.video.container,{classNames:o?.classNames?.container,styles:o?.styles?.container});return i.url?e.renderVideo(r,i,t,n,o):e.renderDropArea(r,t,n,o),r}static renderVideo(t,n,a,o,i){t.innerHTML="";const r=l.createStyledElement("div",l.classNames.block.video.wrapper,{classNames:i?.classNames?.container,styles:i?.styles?.container});switch(r.setAttribute("tabindex","-1"),n?.alignment||"center"){case"left":r.classList.add("clepit-video-wrapper--left");break;case"center":r.classList.add("clepit-video-wrapper--center");break;case"right":r.classList.add("clepit-video-wrapper--right")}const s=de(n?.url||""),c=ue(n?.url||"");if(s||c){const e=l.createStyledElement("iframe",l.classNames.block.video.iframe,{classNames:i?.classNames?.container,styles:i?.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",r.appendChild(e)}else{const e=l.createStyledElement("video",l.classNames.block.video.video,{classNames:i?.classNames?.container,styles:i?.styles?.container});e.setAttribute("alt",n?.alt||""),e.src=n?.url||"",e.controls=!0,r.appendChild(e)}const p=l.createStyledElement("div","clepit-video-caption-container",{classNames:i?.classNames?.caption,styles:i?.styles?.caption});p.classList.add("clepit-video-caption-container");const d=l.createStyledElement("div",l.classNames.block.video.captionEditable,{classNames:i?.classNames?.caption,styles:i?.styles?.caption});d.setAttribute("contenteditable","true"),d.setAttribute("data-placeholder",e.placeholder),d.innerHTML=n?.caption||"",e.addEventListener(o,d,"input",Wi.handleInput),e.addEventListener(o,d,"keydown",Wi.handleKeydown),e.addEventListener(o,r,"click",()=>e.handleFileSelect(t,a,o,i)),p.appendChild(d),t.appendChild(r),t.appendChild(p),d.focus()}static renderDropArea(t,n,a,o){t.innerHTML="";const i=l.createStyledElement("div",l.classNames.block.video.dropArea,{classNames:o?.classNames?.dropArea?.container,styles:o?.styles?.dropArea?.container});i.setAttribute("tabindex","0"),i.classList.add("clepit-drop-area");const r=l.createStyledElement("div","clepit-video-drop-icon",{classNames:o?.classNames?.dropArea?.icon,styles:o?.styles?.dropArea?.icon});r.textContent="🎥";const s=l.createStyledElement("div","clepit-video-drop-text",{classNames:o?.classNames?.dropArea?.text,styles:o?.styles?.dropArea?.text});s.innerHTML='<strong>Drop a video here</strong><br>or <span class="clepit-video-click-text">click to select</span>';const c=l.createStyledElement("button",`${l.classNames.block.videoDeleteBtn}`,{classNames:o?.classNames?.dropArea?.deleteButton,styles:o?.styles?.dropArea?.deleteButton});c.type="button",c.textContent="✕",i.appendChild(r),i.appendChild(s),i.appendChild(c),e.addEventListener(a,c,"click",e=>{e.preventDefault(),e.stopPropagation();const t=c.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id");t&&Wi.removeBlock(a,Wi.getBlockIndex(a,t))}),e.addEventListener(a,i,"click",()=>e.handleFileSelect(t,n,a,o)),e.addEventListener(a,i,"dragleave",()=>{i.classList.remove("clepit-video-drop-area--dragover")}),e.addEventListener(a,i,"dragover",e=>{e.preventDefault(),e.stopPropagation(),i.classList.add("clepit-video-drop-area--dragover")}),e.addEventListener(a,i,"drop",r=>{r.preventDefault(),r.stopPropagation(),i.classList.remove("clepit-video-drop-area--dragover"),e.handleFileDrop(r,t,n,a,o)}),e.addEventListener(a,i,"focus",e=>{e.preventDefault(),e.stopPropagation()}),e.addEventListener(a,i,"mousedown",e=>{e.preventDefault(),e.stopPropagation()});const p=a?m.getState().getInstance(a):null,d=p?.config.classNames?.tooltips,u=p?.config.styles?.tooltips;ee(c,"Delete block","below",d,u),t.appendChild(i)}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,a,o,i){e.showLoading(n);try{let r=await a(t);if(r){e.renderVideo(n,{alignment:"center",alt:t.name,caption:"",url:r},a,o,i);const s=n.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id");s&&m.getState().updateBlockData(o,Wi.getBlockIndex(o,s),Wi.getBlockData(s).data)}else e.showError(n,"Failed to upload video. Please try again.")}catch(r){console.error("Video upload error:",r),e.showError(n,"Failed to upload video. Please try again.")}}static showLoading(e){e.innerHTML="";const t=l.createStyledElement("div","clepit-video-loading",void 0);t.textContent="Uploading video...",e.appendChild(t)}static showError(e,t){e.innerHTML="";const n=l.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=Wi.getEditorId(e);if(!a)return;const o=e.getAttribute("data-id");o&&m.getState().partialUpdateBlockData(a,Wi.getBlockIndex(a,o),{alignment:t})}static isEmpty(e){const t=e.querySelector(`.${l.classNames.block.video.wrapper} video`),n=e.querySelector(`.${l.classNames.block.video.wrapper} iframe`),a=e.querySelector(`.${l.classNames.block.video.captionEditable}`);let o=!1,i=!1,r=!1;return t&&t.getAttribute("src")?.trim()||(o=!0),n&&n.getAttribute("src")?.trim()||(i=!0),a?_(a.innerHTML)&&(r=!0):r=!0,o&&i&&r}static isEmptyData(e){return!e.url?.trim()&&_(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]=[])}},Oo=class e{static render(t,n,a,o){if(l.injectStyles("clepit-video-output-styles",jo),!e.validate(t))return Ne();if(zo.isEmptyData(t))return document.createElement("div");const i=t.url,r=t.caption,s=t.alignment||"center",c=l.createStyledElement("div","clepit-output-video-container",{classNames:o?.container,styles:a?.container}),p=l.createStyledElement("div","clepit-output-video-wrapper");switch(s){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=de(i),u=ue(i);if(d||u){const e=q("iframe","clepit-output-video-iframe");e.src=i,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=q("video","clepit-output-video");e.src=i,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(r){const e=l.createStyledElement("figcaption","clepit-output-video-caption",{classNames:o?.caption,styles:a?.caption}),n=t.caption;e.innerHTML=n&&n!==r?n:r,c.appendChild(e)}if(a&&(a.container&&Object.assign(c.style,a.container),a.caption)){const e=c.querySelector(".clepit-output-video-caption");e&&Object.assign(e.style,a.caption)}if(o&&(o.container&&c.classList.add(o.container),o.caption)){const e=c.querySelector(".clepit-output-video-caption");e&&e.classList.add(o.caption)}return c}static draw(t,n=ye){if(!e.validate(t)||zo.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}},Ho=(e,t,n)=>{const a=Po(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},Po=(e,t,n)=>{switch(e.type){case"alert":return Ae.draw(e.data,t);case"audio":return Ie.draw(e.data,t);case"checklist":return je.draw(e.data,t);case"code":return st.draw(e.data,t,n);case"collapsible":return Fo.draw(e.data,t,n);case"collection":return ft.draw(e.data,t);case"columns":return kt.draw(e.data,t,n);case"date":return At.draw(e.data,t);case"delimiter":return $t.draw(e.data,t);case"doc_card":return qt.draw(e.data,t,n);case"embed":return Ut.draw(e.data,t,n);case"file":return Xt.draw(e.data,t);case"glance":return Qt.draw(e.data,t);case"header":return nn.draw(e.data,t);case"image":return sn.draw(e.data,t);case"latex":return $o.draw(e.data,t);case"list":return pn.draw(e.data,t);case"mermaid":return Mo.draw(e.data,t);case"openapi":return Hn.draw(e.data,t);case"paragraph":return Fn.draw(e.data,t);case"quote":return Kn.draw(e.data,t);case"sketch":return ea.draw(e.data,t);case"table":return ra.draw(e.data,t);case"toc":return da.draw(e.data,t,n);case"updates":return Do.draw(e.data,t);case"video":return Oo.draw(e.data,t);default:return Ro(e)}},Ro=e=>(console.warn("drawBlock: no drawer for block",e),null),Fo=class e{static render(t,n,a,o){if(l.injectStyles("collapsible-output",dt),!e.validate(t))return Ne();const i=l.createStyledElement("details","clepit-collapsible clepit-output-collapsible",{classNames:o?.section,styles:a?.section});i.open=t.open??!1;const r=document.createElement("summary"),s=document.createElement("span");s.innerHTML=j(t.html),r.appendChild(s),i.appendChild(r);const c=document.createElement("div");c.className="clepit-collapsible__children";for(const l of t.children??[])c.appendChild(e.renderChild(l,n));return i.appendChild(c),i}static renderChild(e,t){const n=_i.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=ye,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=Ho(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))}},Vo={icon:"▸",get input(){return mt},label:"Collapsible section",get output(){return Fo},shortcut:E("E"),testId:"block-type-collapsible",type:"collapsible"},Uo=/* @__PURE__ */new WeakMap,Wo=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=Uo.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){l.injectStyles("collection-input",gt);const a=t??{collectionId:""},o=ft.render(a,void 0,n?.styles,n?.classNames);return o.classList.add("clepit-collection--input"),o.setAttribute("contenteditable","false"),Uo.set(o,a),o}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]=[])}},Ko={icon:"▦",get input(){return Wo},label:"Collection",get output(){return ft},shortcut:E("G"),testId:"block-type-collection",type:"collection"},Go=/* @__PURE__ */new WeakMap;var Jo=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=Go.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 _i.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,a){l.injectStyles("columns-input",vt);const o=n&&Array.isArray(n.columns)&&n.columns.length>=2?n:{columns:[[],[]]},i=l.createStyledElement("div","clepit-columns clepit-columns--input",{classNames:a?.classNames?.container,styles:a?.styles?.container});return Go.set(i,o.columns.map(e=>[...e])),o.columns.forEach(n=>{const o=l.createStyledElement("div","clepit-columns__column",{classNames:a?.classNames?.column,styles:a?.styles?.column});n.forEach(n=>{o.appendChild(e.renderChild(t,n))}),i.appendChild(o)}),i}static renderChild(e,t){const n=document.createElement("div");n.className="clepit-columns__child";const a=Wi.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]=[])}},Xo={icon:"▥",get input(){return Jo},label:"Columns",get output(){return kt},shortcut:E("L"),testId:"block-type-columns",type:"columns"},Zo=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,a){l.injectStyles("date-input",Ct);const o=l.createStyledElement("input","clepit-date clepit-date--input",{classNames:a?.classNames?.pill,styles:a?.styles?.pill});return o.type="date",n?.date&&Nt(n.date)&&(o.value=n.date),e.addEventListener(t,o,"keydown",e=>{e.stopPropagation()}),o}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]=[])}},Yo={icon:"▤",get input(){return Zo},label:"Date",get output(){return At},shortcut:E("D"),testId:"block-type-date",type:"date"},Qo={icon:"—",get input(){return Bt},label:"Delimiter",get output(){return $t},shortcut:E("D"),testId:"block-type-delimiter",type:"delimiter"},ei=/* @__PURE__ */new WeakMap,ti=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=ei.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){l.injectStyles("doc-card-input",It);const a=t??{pageId:"",title:""},o=qt.render(a,void 0,n?.styles,n?.classNames);return o.classList.add("clepit-doc-card--input"),o.setAttribute("contenteditable","false"),ei.set(o,a),o}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]=[])}},ni={icon:"🗎",get input(){return ti},label:"Doc card",get output(){return qt},shortcut:E("K"),testId:"block-type-doc-card",type:"doc_card"},ai=/* @__PURE__ */new WeakMap,oi=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?ai.get(t):void 0)??{url:""}}static render(e,t,n){l.injectStyles("embed-input",_t);const a=t??{url:""},o=Ut.render(a,void 0,n?.styles,n?.classNames);return o.classList.add("clepit-embed--input"),o.setAttribute("contenteditable","false"),ai.set(o,a),o}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]=[])}},ii={icon:"🔗",get input(){return oi},label:"Embed",get output(){return Ut},shortcut:E("M"),testId:"block-type-embed",type:"embed"},ri=/* @__PURE__ */new WeakMap,si=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=ri.get(t);if(e)return e}return{name:"",url:""}}static render(t,n,a,o){l.injectStyles("file-input",Kt);const i=document.createElement("div");return i.className="clepit-file-host",i.setAttribute("contenteditable","false"),a?.url&&a.name&&ri.set(i,a),e.renderState(i,t,n,o),i}static renderState(t,n,a,o){t.innerHTML="";const i=ri.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=Xt.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);ri.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]=[])}},li={icon:"📎",get input(){return si},label:"File",get output(){return Xt},shortcut:E("F"),testId:"block-type-file",type:"file"},ci={html:"",label:""},pi=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:j(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){l.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 a=t?.rows?.length?t:{rows:[ci]},o=Qt.render(a,void 0,n?.styles,n?.classNames);o.classList.add("clepit-glance--input");for(const i of o.querySelectorAll(".clepit-glance-label"))i.setAttribute("contenteditable","true"),i.setAttribute("data-placeholder","Label");for(const i of o.querySelectorAll(".clepit-glance-value"))i.setAttribute("contenteditable","true"),i.setAttribute("data-placeholder","Value");return o}static changeVariant(t,n,a){const o=m.getState().getInstance(a);if(!o)return;if((t.getAttribute("data-variant")??"plain")===n)return;const i=Wi.getBlockIndex(a,t.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id")),r={...e.save(t),variant:n},s={classNames:o.config.classNames?.blocks?.glance,margins:o.config.margins,styles:o.config.styles?.blocks?.glance},c=e.render(a,r,s);t.replaceWith(c),m.getState().updateBlockData(a,i,r)}static isEmpty(t){return e.isEmptyData(e.save(t))}static isEmptyData(e){return!e?.rows?.length||e.rows.every(e=>""===e.label.trim()&&""===j(e.html).trim())}static destroy(e){}},di={icon:"≡",get input(){return pi},label:"At a glance",get output(){return Qt},shortcut:E("N"),testId:"block-type-glance",type:"glance"},ui={icon:"H",get input(){return tn},label:"Header",get output(){return nn},shortcut:E("H"),testId:"block-type-header",type:"header"},mi={icon:"𝑖",get input(){return rn},label:"Image",get output(){return sn},shortcut:E("I"),testId:"block-type-image",type:"image"},hi={icon:"•",get input(){return cn},label:"List",get output(){return pn},shortcut:E("L"),testId:"block-type-list",type:"list"},gi="clepit-openapi__source",bi=(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??{}}},fi=class e{static{this.placeholder="Paste an OpenAPI document, or a URL to one…"}static{this.dataMap=/* @__PURE__ */new WeakMap}static render(t,n,a){l.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 o=q("div","clepit-openapi-input"),i=q("div",gi);i.setAttribute("contenteditable","true"),i.setAttribute("data-placeholder",e.placeholder),i.setAttribute("data-testid","openapi-source"),i.textContent=n?.url??(n?.spec?JSON.stringify(n.spec,null,2):"");const r=q("div","clepit-openapi-input__preview");return r.setAttribute("data-testid","openapi-preview"),n&&r.appendChild(Hn.render(n)),i.addEventListener("input",()=>{const t=bi(i.textContent??"",e.dataMap.get(o));e.dataMap.set(o,t),r.replaceChildren(Hn.render(t))}),n&&e.dataMap.set(o,n),o.appendChild(i),o.appendChild(r),o}static save(t){const n=(e=>e.classList.contains(gi)?e:e.querySelector(`.${gi}`))(t),a=t.classList.contains("clepit-openapi-input")?t:t.querySelector(".clepit-openapi-input"),o=a?e.dataMap.get(a):void 0;return bi(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){}},yi={icon:"⇄",get input(){return fi},label:"API reference",get output(){return Hn},shortcut:E("A"),testId:"block-type-openapi",type:"openapi"},vi={icon:"¶",get input(){return Rn},label:"Paragraph",get output(){return Fn},shortcut:E("P"),testId:"block-type-paragraph",type:"paragraph"},xi={icon:"“",get input(){return Wn},label:"Quote",get output(){return Kn},shortcut:E("Q"),testId:"block-type-quote",type:"quote"},ki=/* @__PURE__ */new WeakMap,wi=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?ki.get(t):void 0)??{strokes:[]}}static render(t,n,a){l.injectStyles("sketch-input",Jn);const o=n??{strokes:[]},i=ea.render(o,void 0,a?.styles,a?.classNames);return i.classList.add("clepit-sketch--input"),i.setAttribute("contenteditable","false"),ki.set(i,o),e.attachDrawing(t,i),i}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=ki.get(n)??{strokes:[]},t=o&&o.length>=4?{strokes:[...e.strokes,{points:o}]}:e,i=ea.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=ki.get(n)??{strokes:[]};ki.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]=[])}},Ci={icon:"✏️",get input(){return wi},label:"Sketch",get output(){return ea},shortcut:E("W"),testId:"block-type-sketch",type:"sketch"},Ei={icon:"⊞",get input(){return aa},label:"Table",get output(){return ra},shortcut:E("T"),testId:"block-type-table",type:"table"},Si=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){return{}}static render(e,t,n){l.injectStyles("toc-input",la);const a=m.getState().getData(e)?.blocks??[],o=da.render({},{documentBlocks:a},n?.styles,n?.classNames);return o.classList.add("clepit-toc--input"),o.setAttribute("contenteditable","false"),o}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]=[])}},Ni={icon:"≡",get input(){return Si},label:"Table of contents",get output(){return da},shortcut:E("T"),testId:"block-type-toc",type:"toc"},Ai={latex:"LaTeX",mermaid:"Mermaid"};function Li(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 Bi(e,t,n){l.injectStyles("typeset-input",ma);const a=t??{source:""},o=l.createStyledElement("div",`clepit-typeset clepit-output-typeset clepit-typeset--input clepit-typeset--${e}`,{classNames:n?.classNames?.wrapper,styles:n?.styles?.wrapper});o.setAttribute("data-language",e),o.setAttribute("data-rendered","source");const i=q("span","clepit-typeset__kind");i.textContent=Ai[e],o.appendChild(i);const r=q("span","clepit-typeset__title");r.setAttribute("data-testid","typeset-title"),r.setAttribute("contenteditable","true"),r.setAttribute("data-placeholder","mermaid"===e?"What does this diagram show?":"What does this formula show?"),r.textContent=a.title??"",o.appendChild(r);const s=q("pre","clepit-typeset__source");return s.setAttribute("contenteditable","true"),s.textContent=a.source,o.appendChild(s),o}var $i=class{static{this.placeholder=""}static save(e){return Li(e)}static render(e,t,n){return Bi("latex",t,n)}static isEmpty(e){return""===Li(e).source.trim()}static isEmptyData(e){return!e.source.trim()}static destroy(e){}},Mi=class{static{this.placeholder=""}static save(e){return Li(e)}static render(e,t,n){return Bi("mermaid",t,n)}static isEmpty(e){return""===Li(e).source.trim()}static isEmptyData(e){return!e.source.trim()}static destroy(e){}},Ii={icon:"∑",get input(){return $i},label:"LaTeX",get output(){return $o},shortcut:E("X"),testId:"block-type-latex",type:"latex"},Ti={icon:"◈",get input(){return Mi},label:"Mermaid",get output(){return Mo},shortcut:E("Y"),testId:"block-type-mermaid",type:"mermaid"},qi=/* @__PURE__ */new WeakMap,Di=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=qi.get(t);if(e)return e;const n=t.getAttribute("data-page-id");if(n)return{pageId:n}}return{}}static render(e,t,n){l.injectStyles("updates-input",To);const a=t??{},o=Do.render(a,void 0,n?.styles,n?.classNames);return o.classList.add("clepit-updates--input"),o.setAttribute("contenteditable","false"),qi.set(o,a),o}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]=[])}},_i=[Le,Te,ze,lt,Vo,Ko,{icon:"🕘",get input(){return Di},label:"Updates",get output(){return Do},shortcut:E("U"),testId:"block-type-updates",type:"updates"},Xo,Yo,Qo,ni,ii,li,di,ui,mi,hi,yi,vi,xi,Ci,Ii,Ti,Ei,Ni,{icon:"▶",get input(){return zo},label:"Video",get output(){return Oo},shortcut:E("V"),testId:"block-type-video",type:"video"}],ji="clepit-block-type-selector",zi="clepit-code-language-submenu",Oi="clepit-code-theme-submenu",Hi="clepit-convert-submenu",Pi="clepit-block-operations-menu";function Ri(e){return oe.includes(e)}function Fi(e,t,n){return e?.[t]??n}var Vi,Ui=class e{static{this.defaultClassName="clepit-block-toolbar"}static{this.menuAnchor="--clepit-block-toolbar"}static{this.submenuAnchorSeq=0}static{this.eventListenersMap=/* @__PURE__ */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 a=m.getState().getInstance(t);if(!a)return console.error("BlockToolbar::create: Instance not found for containerId:",t);const o=document.getElementById(t);if(!o)return console.error("BlockToolbar::create: Container not found for containerId:",t);e.eventListenersMap.has(o)||e.eventListenersMap.set(o,[]);const i=void 0!==a.config.audioUploader,r=void 0!==a.config.imageUploader,s=void 0!==a.config.videoUploader,c=a.config.classNames?.blockToolbar,p=a.config.classNames?.blockTypeMenu,d=a.config.classNames?.convertSubmenu,u=a.config.classNames?.operationsMenu,h=a.config.styles?.blockToolbar,g=a.config.styles?.blockTypeMenu,b=a.config.styles?.convertSubmenu,f=a.config.styles?.operationsMenu;e.remove(n),l.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=q("div",e.defaultClassName);y.id=`${t}-block-toolbar`,y.innerHTML="",l.applyStyling(y,{classNames:c?.container,styles:h?.container});const v=q("button","clepit-block-toolbar-add",{"data-testid":"toolbar-add-button",type:"button"});v.innerHTML="+",l.applyStyling(v,{classNames:c?.button,styles:h?.button}),e.addEventListener(o,v,"click",()=>e.showBlockTypeMenu({audioIsEnabled:i,block:n,classNames:p,containerId:t,imageIsEnabled:r,menuLabels:a.config.blockToolbarLabels,styles:g,toolLabels:a.config.blockToolLabels,videoIsEnabled:s}));const x=q("button","clepit-block-toolbar-ops",{"data-testid":"toolbar-operations-button",type:"button"});x.innerHTML="⋯",l.applyStyling(x,{classNames:c?.button,styles:h?.button}),e.addEventListener(o,x,"click",()=>e.showOperationsMenu({audioIsEnabled:i,block:n,classNames:u,containerId:t,convertSubmenuClassNames:d,convertSubmenuStyles:b,imageIsEnabled:r,operationLabels:a.config.blockToolbarLabels,styles:f,toolLabels:a.config.blockToolLabels,videoIsEnabled:s})),y.appendChild(v),y.appendChild(x),e.addEventListener(o,y,"click",e=>e.stopPropagation()),n.appendChild(y)}static showBlockTypeMenu({containerId:t,block:n,imageIsEnabled:a,videoIsEnabled:o,audioIsEnabled:i,classNames:r,styles:s,menuLabels:c,toolLabels:p}){e.closeAllMenus();const d=document.querySelector(`.${ji}`);if(d)return d.classList.remove(`${ji}--visible`),d.classList.add(`${ji}--hidden`),void setTimeout(()=>d.remove(),200);const u=q("div",ji);l.applyStyling(u,{classNames:r?.container,styles:s?.container});const m=q("input","",{placeholder:Fi(c,"searchBlocks","Search blocks..."),type:"text"});m.setAttribute("data-testid","block-type-search"),l.applyStyling(m,{classNames:r?.input,styles:s?.input}),u.appendChild(m);const h=document.querySelector(`#${t}`),g=q("div",`${ji}-items`),b=c=>{g.innerHTML="",c.forEach(c=>{if("image"===c.type&&!a)return;if("video"===c.type&&!o)return;if("audio"===c.type&&!i)return;const d=q("div","clepit-menu-item clepit-block-type-item");d.setAttribute("data-testid",`block-type-${c.type}`),l.applyStyling(d,{classNames:r?.item?.container,styles:s?.item?.container});const m=q("span","clepit-menu-icon "+("image"===c.type?"clepit-menu-icon--italic":""));m.textContent=c.icon,l.applyStyling(m,{classNames:r?.item?.icon,styles:s?.item?.icon}),d.appendChild(m);const b=q("span","clepit-menu-label");if(b.textContent=(Ri(c.type)?p?.[c.type]:void 0)??c.label,l.applyStyling(b,{classNames:r?.item?.text,styles:s?.item?.text}),d.appendChild(b),c.shortcut){const e=q("span","clepit-menu-shortcut");e.textContent=c.shortcut,l.applyStyling(e,{classNames:r?.item?.shortcut,styles:s?.item?.shortcut}),d.appendChild(e)}e.addEventListener(h,d,"click",e=>{if(e.stopPropagation(),n){const e=Wi.getBlockIndex(t,n.getAttribute("data-id")||"");Wi.insertBlock({data:{html:""},type:c.type},t,e+1)}u.hidePopover()}),g.appendChild(d)})};if(b(_i),e.addEventListener(h,m,"click",e=>e.stopPropagation()),e.addEventListener(h,m,"focus",e=>e.stopPropagation()),e.addEventListener(h,m,"input",()=>{const e=m.value.toLowerCase(),t=_i.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e));if(b(t),0===t.length&&""!==e.trim()){const e=q("div","clepit-not-found-message",{style:"padding: 8px 12px; color: #666; font-style: italic; text-align: center;"});e.textContent=Fi(c,"noBlockTypesFound","No block types found"),g.appendChild(e)}}),e.addEventListener(h,m,"keydown",e=>{"Escape"===e.key&&u.hidePopover()}),u.appendChild(g),u.classList.add(ji),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(`${ji}--visible`),m.focus(),e.addDocumentEventListener("click",e=>{const t=e.target;u.contains(t)||n?.contains(t)||u.remove()})):u.showPopover()}static showOperationsMenu({containerId:t,block:n,classNames:a,styles:o,convertSubmenuClassNames:i,convertSubmenuStyles:r,imageIsEnabled:s,videoIsEnabled:c,audioIsEnabled:p,operationLabels:d,toolLabels:u}){e.closeAllMenus();const m=q("div",Pi);o?.container&&l.applyStyling(m,{classNames:a?.container,styles:o.container}),a?.container&&m.classList.add(a.container);const h=q("input","",{placeholder:Fi(d,"searchOperations","Search operations..."),type:"text"});h.setAttribute("data-testid","operations-search"),l.applyStyling(h,{classNames:a?.input,styles:o?.input}),m.appendChild(h);const g=document.querySelector(`#${t}`),b=q("div",`${Pi}-items`),f=n.getAttribute("data-tool");if(!f)return;const y=(e,t)=>Fi(d,e,t),v=[{hasSubmenu:!0,icon:"↻",label:y("convert","Convert To"),testId:"operation-convert",value:"convert"},{icon:"↑",label:y("moveUp","Move Up"),shortcut:"⌘⇧↑",testId:"operation-moveUp",value:"moveUp"},{icon:"↓",label:y("moveDown","Move Down"),shortcut:"⌘⇧↓",testId:"operation-moveDown",value:"moveDown"},{icon:"×",label:y("delete","Delete"),shortcut:"⌘⇧⌫",testId:"operation-delete",value:"delete"}],x=[{icon:"←",label:y("alignLeft","Align Left"),testId:"image-align-left",value:"imageAlignLeft"},{icon:"↔",label:y("alignCenter","Align Center"),testId:"image-align-center",value:"imageAlignCenter"},{icon:"→",label:y("alignRight","Align Right"),testId:"image-align-right",value:"imageAlignRight"}],k=[{icon:"←",label:y("alignLeft","Align Left"),testId:"video-align-left",value:"videoAlignLeft"},{icon:"↔",label:y("alignCenter","Align Center"),testId:"video-align-center",value:"videoAlignCenter"},{icon:"→",label:y("alignRight","Align Right"),testId:"video-align-right",value:"videoAlignRight"}],w=[{icon:"←",label:y("alignLeft","Align Left"),testId:"audio-align-left",value:"audioAlignLeft"},{icon:"↔",label:y("alignCenter","Align Center"),testId:"audio-align-center",value:"audioAlignCenter"},{icon:"→",label:y("alignRight","Align Right"),testId:"audio-align-right",value:"audioAlignRight"}],C=[{hasSubmenu:!0,icon:"⌘",label:y("codeLanguage","Language"),testId:"code-language",value:"codeLanguage"},{hasSubmenu:!0,icon:"◆",label:y("codeTheme","Theme"),testId:"code-theme",value:"codeTheme"}];v.forEach(h=>{const f=q("div","clepit-menu-item clepit-block-operation-item");f.setAttribute("data-testid",`operation-${h.value}`),l.applyStyling(f,{classNames:a?.item?.container,styles:o?.item?.container}),f.setAttribute("data-testid",h.testId);const y=q("span","clepit-menu-icon");y.textContent=h.icon,l.applyStyling(y,{classNames:a?.item?.icon,styles:o?.item?.icon}),f.appendChild(y);const v=q("span","clepit-menu-label");if(v.textContent=h.label,l.applyStyling(v,{classNames:a?.item?.text,styles:o?.item?.text}),f.appendChild(v),h.shortcut){const e=q("span","clepit-menu-shortcut");e.textContent=h.shortcut,l.applyStyling(e,{classNames:a?.item?.shortcut,styles:o?.item?.shortcut}),f.appendChild(e)}if(h.hasSubmenu){const e=q("span","clepit-menu-arrow");e.textContent="›",f.appendChild(e)}"delete"===h.value&&(f.classList.add("clepit-block-toolbar--delete-enabled"),1===g.querySelectorAll(".clepit-block").length&&(f.classList.add("clepit-block-toolbar--delete-disabled"),f.title="Cannot delete the last block")),e.addEventListener(g,f,"click",a=>{a.stopPropagation(),h.hasSubmenu?(document.querySelector(`.${zi}`)?.remove(),document.querySelector(`.${Oi}`)?.remove(),e.showConvertSubmenu({audioIsEnabled:p,block:n,classNames:i,containerId:t,imageIsEnabled:s,menuLabels:d,parentItem:f,parentMenu:m,styles:r,toolLabels:u,videoIsEnabled:c})):(e.handleOperationSelect(h.value,n,t),m.remove())}),b.appendChild(f)});const E=()=>{const e=q("div","clepit-menu-divider");l.applyStyling(e,{classNames:a?.divider,styles:o?.divider}),b.appendChild(e)};if("image"===f&&(E(),x.forEach(i=>{const r=q("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(r,{classNames:a?.item?.container,styles:o?.item?.container}),r.setAttribute("data-testid",i.testId);const s=q("span","clepit-menu-icon");s.textContent=i.icon,l.applyStyling(s,{classNames:a?.item?.icon,styles:o?.item?.icon}),r.appendChild(s);const c=q("span","clepit-menu-label");if(c.textContent=i.label,l.applyStyling(c,{classNames:a?.item?.text,styles:o?.item?.text}),r.appendChild(c),i.value.startsWith("imageAlign")){const e=n.querySelector(".clepit-image-wrapper");if(e){const t=e.style.textAlign;("left"===t?"left":"right"===t?"right":"center")===i.value.replace("imageAlign","").toLowerCase()&&r.classList.add("active")}}e.addEventListener(g,r,"click",a=>{a.stopPropagation(),e.handleOperationSelect(i.value,n,t),m.remove()}),b.appendChild(r)})),"video"===f&&(E(),k.forEach(i=>{const r=q("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(r,{classNames:a?.item?.container,styles:o?.item?.container}),r.setAttribute("data-testid",i.testId);const s=q("span","clepit-menu-icon");s.textContent=i.icon,l.applyStyling(s,{classNames:a?.item?.icon,styles:o?.item?.icon}),r.appendChild(s);const c=q("span","clepit-menu-label");if(c.textContent=i.label,l.applyStyling(c,{classNames:a?.item?.text,styles:o?.item?.text}),r.appendChild(c),i.value.startsWith("videoAlign")){const e=n.querySelector(".clepit-video-wrapper");if(e){const t=e.style.textAlign;("left"===t?"left":"right"===t?"right":"center")===i.value.replace("videoAlign","").toLowerCase()&&r.classList.add("active")}}e.addEventListener(g,r,"click",a=>{a.stopPropagation(),e.handleOperationSelect(i.value,n,t),m.remove()}),b.appendChild(r)})),"audio"===f&&(E(),w.forEach(i=>{const r=q("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(r,{classNames:a?.item?.container,styles:o?.item?.container}),r.setAttribute("data-testid",i.testId);const s=q("span","clepit-menu-icon");s.textContent=i.icon,l.applyStyling(s,{classNames:a?.item?.icon,styles:o?.item?.icon}),r.appendChild(s);const c=q("span","clepit-menu-label");if(c.textContent=i.label,l.applyStyling(c,{classNames:a?.item?.text,styles:o?.item?.text}),r.appendChild(c),i.value.startsWith("audioAlign")){const e=n.querySelector(".clepit-audio-wrapper");if(e){const t=e.style.textAlign;("left"===t?"left":"right"===t?"right":"center")===i.value.replace("audioAlign","").toLowerCase()&&r.classList.add("active")}}e.addEventListener(g,r,"click",a=>{a.stopPropagation(),e.handleOperationSelect(i.value,n,t),m.remove()}),b.appendChild(r)})),"code"===f&&(E(),C.forEach(s=>{const c=q("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(c,{classNames:a?.item?.container,styles:o?.item?.container}),c.setAttribute("data-testid",s.testId);const p=q("span","clepit-menu-icon");p.textContent=s.icon,l.applyStyling(p,{classNames:a?.item?.icon,styles:o?.item?.icon}),c.appendChild(p);const u=q("span","clepit-menu-label");if(u.textContent=s.label,l.applyStyling(u,{classNames:a?.item?.text,styles:o?.item?.text}),c.appendChild(u),s.hasSubmenu){const e=q("span","clepit-menu-arrow");e.textContent="›",c.appendChild(e)}e.addEventListener(g,c,"click",a=>{a.stopPropagation(),s.hasSubmenu?"codeLanguage"===s.value?e.showCodeLanguageSubmenu({block:n,classNames:i,containerId:t,menuLabels:d,parentItem:c,parentMenu:m,styles:r}):"codeTheme"===s.value&&e.showCodeThemeSubmenu({block:n,classNames:i,containerId:t,menuLabels:d,parentItem:c,parentMenu:m,styles:r}):(e.handleOperationSelect(s.value,n,t),m.remove())}),b.appendChild(c)})),"header"===f){E();const i=e.getCurrentHeadingLevel(n);[{icon:"H1",label:y("headingH1","Heading 1"),value:"heading-h1"},{icon:"H2",label:y("headingH2","Heading 2"),value:"heading-h2"},{icon:"H3",label:y("headingH3","Heading 3"),value:"heading-h3"},{icon:"H4",label:y("headingH4","Heading 4"),value:"heading-h4"},{icon:"H5",label:y("headingH5","Heading 5"),value:"heading-h5"},{icon:"H6",label:y("headingH6","Heading 6"),value:"heading-h6"}].forEach(r=>{const s=q("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(s,{classNames:a?.item?.container,styles:o?.item?.container});const c=q("span","clepit-menu-icon");c.textContent=r.icon,l.applyStyling(c,{classNames:a?.item?.icon,styles:o?.item?.icon}),s.appendChild(c);const p=q("span","clepit-menu-label");p.textContent=r.label,l.applyStyling(p,{classNames:a?.item?.text,styles:o?.item?.text}),s.appendChild(p),r.value===`heading-${i}`&&s.classList.add("active"),e.addEventListener(g,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(r.value,n,t),m.remove()}),b.appendChild(s)})}if("list"===f){E();const i=n.querySelector(".clepit-list")?.getAttribute("data-type")||"unordered";[{icon:"•",label:y("listUnordered","Unordered"),value:"unordered"},{icon:"1.",label:y("listOrdered","Ordered"),value:"ordered"}].forEach(r=>{const s=q("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(s,{classNames:a?.item?.container,styles:o?.item?.container});const c=q("span","clepit-menu-icon");c.textContent=r.icon,l.applyStyling(c,{classNames:a?.item?.icon,styles:o?.item?.icon}),s.appendChild(c);const p=q("span","clepit-menu-label");p.textContent=r.label,l.applyStyling(p,{classNames:a?.item?.text,styles:o?.item?.text}),s.appendChild(p),r.value===i&&s.classList.add("active"),e.addEventListener(g,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`listType${r.value}`,n,t),m.remove()}),b.appendChild(s)})}if("alert"===f){E();const i=n.querySelector(".clepit-alert")?.getAttribute("data-variant")||"info";[{icon:"i",label:y("variantInfo","Info"),value:"info"},{icon:"!",label:y("variantWarning","Warning"),value:"warning"},{icon:"×",label:y("variantError","Error"),value:"error"},{icon:"✓",label:y("variantSuccess","Success"),value:"success"},{icon:"—",label:y("variantPlain","Plain"),value:"plain"}].forEach(r=>{const s=q("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(s,{classNames:a?.item?.container,styles:o?.item?.container});const c=q("span","clepit-menu-icon");c.textContent=r.icon,c.style.color=e.getAlertIconColor(r.value),l.applyStyling(c,{classNames:a?.item?.icon,styles:o?.item?.icon}),s.appendChild(c);const p=q("span","clepit-menu-label");p.textContent=r.label,l.applyStyling(p,{classNames:a?.item?.text,styles:o?.item?.text}),s.appendChild(p),r.value===i&&s.classList.add("active"),e.addEventListener(g,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`alertVariant${r.value}`,n,t),m.remove()}),b.appendChild(s)})}if("glance"===f){E();const i=n.querySelector(".clepit-glance")?.getAttribute("data-variant")||"plain";[{icon:"—",label:y("variantPlain","Plain"),value:"plain"},{icon:"i",label:y("variantInfo","Info"),value:"info"},{icon:"!",label:y("variantWarning","Warning"),value:"warning"},{icon:"×",label:y("variantError","Error"),value:"error"},{icon:"✓",label:y("variantSuccess","Success"),value:"success"}].forEach(r=>{const s=q("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(s,{classNames:a?.item?.container,styles:o?.item?.container});const c=q("span","clepit-menu-icon");c.textContent=r.icon,c.style.color=e.getAlertIconColor(r.value),l.applyStyling(c,{classNames:a?.item?.icon,styles:o?.item?.icon}),s.appendChild(c);const p=q("span","clepit-menu-label");p.textContent=r.label,l.applyStyling(p,{classNames:a?.item?.text,styles:o?.item?.text}),s.appendChild(p),r.value===i&&s.classList.add("active"),e.addEventListener(g,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`glanceVariant${r.value}`,n,t),m.remove()}),b.appendChild(s)})}if("delimiter"===f){E();const i=n.querySelector(".clepit-delimiter")?.getAttribute("data-variant")||"line";[{icon:"—",label:y("delimiterLine","Line"),value:"line"},{icon:"***",label:y("delimiterStars","Stars"),value:"stars"}].forEach(r=>{const s=q("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(s,{classNames:a?.item?.container,styles:o?.item?.container});const c=q("span","clepit-menu-icon");c.textContent=r.icon,l.applyStyling(c,{classNames:a?.item?.icon,styles:o?.item?.icon}),s.appendChild(c);const p=q("span","clepit-menu-label");p.textContent=r.label,l.applyStyling(p,{classNames:a?.item?.text,styles:o?.item?.text}),s.appendChild(p),r.value===i&&s.classList.add("active"),e.addEventListener(g,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`delimiterVariant${r.value}`,n,t),m.remove()}),b.appendChild(s)})}const S=b.querySelectorAll(".clepit-block-operation-item"),N=b.querySelectorAll(".clepit-menu-divider");if(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;S.forEach(n=>{(n.querySelector(".clepit-menu-label")?.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=q("div","clepit-not-found-message",{style:"padding: 8px 12px; color: #666; font-style: italic; text-align: center;"});e.textContent=y("noOperationsFound","No operations found"),b.appendChild(e)}}else n&&n.remove();N.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(g,h,"keydown",e=>{"Escape"===e.key&&m.remove()}),m.appendChild(b),m.classList.add(Pi),m.setAttribute("popover","auto"),h.setAttribute("autofocus",""),n){const t=n.querySelector(`.${e.defaultClassName}`);t&&t.style.setProperty("anchor-name",e.menuAnchor)}document.body.appendChild(m),m.addEventListener("toggle",e=>{"closed"===e.newState&&m.remove()}),"function"!=typeof m.showPopover?(m.classList.add(`${Pi}--visible`),h.focus(),e.addDocumentEventListener("click",e=>{const t=e.target;m.contains(t)||n?.contains(t)||t.closest?.(".clepit-block-toolbar-ops")||m.remove()})):m.showPopover()}static showConvertSubmenu({containerId:t,block:n,parentItem:a,parentMenu:o,classNames:i,styles:r,imageIsEnabled:s,videoIsEnabled:c,audioIsEnabled:p,menuLabels:d,toolLabels:u}){const m=document.querySelector(`.${Hi}`);m&&m.remove();const h=n.getAttribute("data-tool");if(!h)return;const g=q("div",Hi);g.classList.add(Hi),g.classList.add(`${Hi}--hidden`),r?.container&&l.applyStyles(g,r.container),i?.container&&g.classList.add(i.container);const b=q("input","",{placeholder:Fi(d,"searchConvertOptions","Search convert options..."),type:"text"});b.setAttribute("data-testid","convert-search"),l.applyStyling(b,{classNames:i?.input,styles:r?.input}),g.appendChild(b),setTimeout(()=>b.focus(),10);const f=document.querySelector(`#${t}`),y=q("div",`${Hi}-items`),v=e=>(Ri(e.type)?u?.[e.type]:void 0)??e.label;_i.filter(e=>e.type!==h&&(!("image"===e.type&&!s||"video"===e.type&&!c||"audio"===e.type&&!p)||void 0)).sort((e,t)=>v(e).localeCompare(v(t))).forEach(a=>{const s=q("div","clepit-menu-item clepit-convert-option-item");s.setAttribute("data-testid",a.testId),l.applyStyling(s,{classNames:i?.item?.container,styles:r?.item?.container});const c=q("span","clepit-menu-icon");c.textContent=a.icon,l.applyStyling(c,{classNames:i?.item?.icon,styles:r?.item?.icon}),s.appendChild(c);const p=q("span","clepit-menu-label");if(p.textContent=v(a),l.applyStyling(p,{classNames:i?.item?.text,styles:r?.item?.text}),s.appendChild(p),a.shortcut){const e=q("span","clepit-menu-shortcut");e.textContent=a.shortcut,l.applyStyling(e,{classNames:i?.item?.shortcut,styles:r?.item?.shortcut}),s.appendChild(e)}e.addEventListener(f,s,"click",e=>{e.stopPropagation();const i=n?.getAttribute("data-tool");if(!i)return;let r;if(n){const e=n.querySelector(".clepit-block-content");"paragraph"===i?r=e.querySelector(".clepit-paragraph")?.innerText||"":"quote"===i?r=e.querySelector(".clepit-quote-text")?.innerText||"":"list"===i?r=Array.from(e.querySelectorAll(".clepit-list-item")).map(e=>e.innerText.trim()).filter(Boolean).join("\n"):"alert"===i?r=e.querySelector(".clepit-alert")?.innerText||"":"header"===i&&(r=e.querySelector(".clepit-header")?.innerText||"")}const s=n?.getAttribute("data-id");s&&Wi.convertBlock(s,a.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),o.remove()}),y.appendChild(s)});const x=y.querySelectorAll(".clepit-convert-option-item");e.addEventListener(f,b,"click",e=>e.stopPropagation()),e.addEventListener(f,b,"focus",e=>e.stopPropagation()),e.addEventListener(f,b,"input",e=>{(e=>{let t=0;x.forEach(n=>{(n.querySelector(".clepit-menu-label")?.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=y.querySelector(".clepit-not-found-message");if(0===t&&""!==e.trim()){if(!n){const e=q("div","clepit-not-found-message",{style:"padding: 8px 12px; color: #666; font-style: italic; text-align: center;"});e.textContent=Fi(d,"noConvertOptionsFound","No convert options found"),y.appendChild(e)}}else n&&n.remove()})(e.target.value)}),e.addEventListener(f,b,"keydown",t=>{"Escape"===t.key&&e.closeMenu(Hi)}),g.appendChild(y);const k="--clepit-convert-parent-"+e.submenuAnchorSeq++;a.style.setProperty("anchor-name",k),g.style.setProperty("position-anchor",k),g.classList.remove(`${Hi}--hidden`),g.setAttribute("popover","auto"),document.body.appendChild(g),g.addEventListener("toggle",e=>{"closed"===e.newState&&g.remove()}),"function"!=typeof g.showPopover?(o.appendChild(g),g.classList.add(`${Hi}--visible`),e.addDocumentEventListener("click",e=>{const t=e.target;g.contains(t)||a.contains(t)||o.contains(t)||g.remove()})):g.showPopover()}static handleOperationSelect(e,t,n){if(!t)return;const a=document.querySelector(`#${n}`);if(e.startsWith("convertTo")){const a=e.replace("convertTo",""),o=t.getAttribute("data-id");return void(o&&Wi.convertBlock(o,a,n))}if(e.startsWith("heading-")){const n=e.replace("heading-","");if(-1===Wi.getBlockIndex(a.id,t.getAttribute("data-id")))return;const o=t.querySelector('[contenteditable="true"]');return void(o&&tn.changeLevel(o,n,a.id))}if(e.startsWith("listType")){const n=e.replace("listType","");if(-1===Wi.getBlockIndex(a.id,t.getAttribute("data-id")))return;const o=t.querySelector(".clepit-list");return void(o&&cn.changeType(o,n,a.id))}if(e.startsWith("alertVariant")){const n=e.replace("alertVariant","");if(-1===Wi.getBlockIndex(a.id,t.getAttribute("data-id")))return;const o=t.querySelector(".clepit-alert");return void(o&&be.changeVariant(o,n,a.id))}if(e.startsWith("glanceVariant")){const n=e.replace("glanceVariant","");if(-1===Wi.getBlockIndex(a.id,t.getAttribute("data-id")))return;const o=t.querySelector(".clepit-glance");return void(o&&pi.changeVariant(o,n,a.id))}if(e.startsWith("delimiterVariant")){const n=e.replace("delimiterVariant","");if(-1===Wi.getBlockIndex(a.id,t.getAttribute("data-id")))return;const o=t.querySelector(".clepit-delimiter");if(!o)return;return Bt.changeVariant(o,n,a.id)}if(e.startsWith("tableAction")){const n=e.replace("tableAction",""),a=t.querySelector(`.${l.classNames.block.content}`);if(!a)return;return aa.handleAction(n,a)}if(e.startsWith("imageAlign"))return rn.setAlignment(t,e.replace("imageAlign","").toLowerCase());if(e.startsWith("videoAlign"))return zo.setAlignment(t,e.replace("videoAlign","").toLowerCase());if(e.startsWith("audioAlign"))return Me.setAlignment(t,e.replace("audioAlign","").toLowerCase());if(e.startsWith("codeLanguage")){const n=e.replace("codeLanguage","");if(-1===Wi.getBlockIndex(a.id,t.getAttribute("data-id")))return;return Xe.updateLanguage(t,n)}if(e.startsWith("codeTheme")){const n=e.replace("codeTheme","");if(-1===Wi.getBlockIndex(a.id,t.getAttribute("data-id")))return;return Xe.updateTheme(t,n)}const o=Wi.getBlockIndex(a.id,t.getAttribute("data-id"));if(-1!==o)switch(e){case"delete":Wi.removeBlock(a.id,o);break;case"moveUp":o>0&&Wi.moveBlock(a.id,o,o-1);break;case"moveDown":o<Wi.getBlocks(a.id).length-1&&Wi.moveBlock(a.id,o,o+1);break;default:console.warn(`Unknown block operation: ${e}`)}}static showCodeLanguageSubmenu({parentItem:t,parentMenu:n,block:a,containerId:o,classNames:i,menuLabels:r,styles:s}){const c=document.querySelector(`.${zi}`);c&&c.remove();const p=document.querySelector(`.${Oi}`);p&&p.remove();const d=document.getElementById(o);if(!d)return;const u=a?.querySelector(`.${l.classNames.block.code.container}`)?.getAttribute("data-language")||"javascript",m=l.createStyledElement("div",zi,{classNames:i?.container,styles:s?.container});m.classList.add(Hi,"clepit-block-toolbar--submenu-positioned");const h=q("input","",{placeholder:Fi(r,"searchLanguages","Search languages..."),type:"text"});h.setAttribute("data-testid","language-search"),m.appendChild(h);const g=Xe.supportedLanguages;Object.entries(g).forEach(([t,r])=>{const c=l.createStyledElement("div","clepit-menu-item clepit-code-language-item",{classNames:i?.item?.container,styles:s?.item?.container});c.setAttribute("data-testid",`code-language-${t}`);const p=l.createStyledElement("span","",{classNames:i?.item?.text,styles:s?.item?.text});p.textContent=r.name,c.appendChild(p),t===u&&c.classList.add("active"),e.addEventListener(d,c,"click",i=>{i.stopPropagation(),e.handleOperationSelect(`codeLanguage${t}`,a,o),n.remove()}),m.appendChild(c)});const b=m.querySelectorAll(".clepit-code-language-item");e.addEventListener(d,h,"click",e=>e.stopPropagation()),e.addEventListener(d,h,"input",e=>{const t=e.target.value.toLowerCase();b.forEach(e=>{const n=e.querySelector("span")?.textContent?.toLowerCase()||"";e.classList.toggle("clepit-block-toolbar--item-hidden",!n.includes(t))})}),n.appendChild(m);const f=t.getBoundingClientRect(),y=n.getBoundingClientRect();m.style.top=f.top-y.top+"px",m.style.left=f.right-y.left+4+"px",setTimeout(()=>{m.classList.remove(`${zi}--hidden`),m.classList.add(`${zi}--visible`)},10),setTimeout(()=>{const t=e=>{const a=e.target,o=m.contains(a),i=n.contains(a);o||i||(m.classList.remove(`${zi}--visible`),m.classList.add(`${zi}--hidden`),setTimeout(()=>m.remove(),200),document.removeEventListener("click",t))};e.addDocumentEventListener("click",t)},0)}static showCodeThemeSubmenu({parentItem:t,parentMenu:n,block:a,containerId:o,classNames:i,menuLabels:r,styles:s}){const c=document.querySelector(`.${Oi}`);c&&c.remove();const p=document.querySelector(`.${zi}`);p&&p.remove();const d=document.getElementById(o);if(!d)return;const u=a?.querySelector(`.${l.classNames.block.code.container}`)?.getAttribute("data-theme")||"default",m=l.createStyledElement("div",Oi,{classNames:i?.container,styles:s?.container});m.classList.add(Hi,"clepit-block-toolbar--submenu-positioned");const h=q("input","",{placeholder:Fi(r,"searchThemes","Search themes..."),type:"text"});h.setAttribute("data-testid","theme-search"),m.appendChild(h);const g=Xe.supportedThemes;Object.entries(g).forEach(([t,r])=>{const c=l.createStyledElement("div","clepit-menu-item clepit-code-theme-item",{classNames:i?.item?.container,styles:s?.item?.container});c.setAttribute("data-testid",`code-theme-${t}`);const p=l.createStyledElement("span","",{classNames:i?.item?.text,styles:s?.item?.text});p.textContent=r.name,c.appendChild(p),t===u&&c.classList.add("active"),e.addEventListener(d,c,"click",i=>{i.stopPropagation(),e.handleOperationSelect(`codeTheme${t}`,a,o),n.remove()}),m.appendChild(c)});const b=m.querySelectorAll(".clepit-code-theme-item");e.addEventListener(d,h,"click",e=>e.stopPropagation()),e.addEventListener(d,h,"input",e=>{const t=e.target.value.toLowerCase();b.forEach(e=>{const n=e.querySelector("span")?.textContent?.toLowerCase()||"";e.classList.toggle("clepit-block-toolbar--item-hidden",!n.includes(t))})}),n.appendChild(m);const f=t.getBoundingClientRect(),y=n.getBoundingClientRect();m.style.top=f.top-y.top+"px",m.style.left=f.right-y.left+4+"px",setTimeout(()=>{m.classList.remove(`${Oi}--hidden`),m.classList.add(`${Oi}--visible`)},10),setTimeout(()=>{const t=e=>{const a=e.target,o=m.contains(a),i=n.contains(a);o||i||(m.classList.remove(`${Oi}--visible`),m.classList.add(`${Oi}--hidden`),setTimeout(()=>m.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(`.${ji}, .${Pi}, .${Hi}`)||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(ji),e.closeMenu(Pi),e.closeMenu(Hi)}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())}},Wi=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 a=m.getState().getInstance(n);if(!a)return console.error("BlockManager::createBlockElement: Instance not found for containerId:",n),null;const o=q("div",l.classNames.block.container);o.setAttribute("data-container-id",n),o.setAttribute("data-id",t.id??crypto.randomUUID()),o.setAttribute("data-tool",t.type),o.setAttribute("data-indent","0");const i={classNames:a.config.classNames?.blocks?.[t.type],styles:a.config.styles?.blocks?.[t.type]};let r,s;if(i.margins&&(r=i.margins.top,s=i.margins.bottom),void 0===r&&i.styles){const e=i.styles;if(e.marginTop){const t=e.marginTop;"string"==typeof t&&t.endsWith("px")?r=parseInt(t.replace("px",""),10):"number"==typeof t&&(r=t)}}if(void 0===s&&i.styles){const e=i.styles;if(e.marginBottom){const t=e.marginBottom;"string"==typeof t&&t.endsWith("px")?s=parseInt(t.replace("px",""),10):"number"==typeof t&&(s=t)}}void 0===r&&void 0!==a.config.margins?.top&&(r=a.config.margins.top),void 0===s&&void 0!==a.config.margins?.bottom&&(s=a.config.margins.bottom),void 0!==r&&(o.style.marginTop=`${r}px`),void 0!==s&&(o.style.marginBottom=`${s}px`),Ui.create({block:o,containerId:n});const c=q("div",l.classNames.block.content),p=e.renderTool(t.type,t.data,n);return p?(c.appendChild(p),e.addEventListener(n,o,"click",t=>e.focusBlock(t.currentTarget)),o.appendChild(c),o):(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 m.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(),m.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=m.getState().getData(t);if(!i)return;const r=m.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 l=o.map(t=>e.getBlockData(t.getAttribute("data-id"))),c={...i,blocks:l};m.getState().setData(t,c),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(`.${l.classNames.block.container}`);return Array.from(n)}static getActiveBlocks(e){const t=document.getElementById(e);if(!t)return[];const n=t.querySelectorAll(`.${l.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 _i.find(t=>t.type===e)||null}static getBlockData(t){const n=e.getBlock(t);if(!n)return{data:{html:""},type:"paragraph"};const a=n.getAttribute("data-tool"),o=a?e.getTool(a):null;if(!o)return{data:{html:""},id:t,type:"paragraph"};const i=n.querySelector(`.${l.classNames.block.content}`);return i?{data:o.input.save(i),id:t,tunes:e.getBlockTunes(n),type:a}:{data:{html:""},id:t,tunes:e.getBlockTunes(n),type:a}}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=m.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 be.render(n,t,o);case"audio":return a.config.audioUploader?Me.render(a.config.audioUploader,n,t,o):(console.error("BlockManager::renderTool: Audio uploader not found for containerId:",n),null);case"code":return Xe.render(n,t,o);case"collapsible":return mt.render(n,t,o);case"columns":return Jo.render(n,t,o);case"date":return Zo.render(n,t,o);case"delimiter":return Bt.render(n,t,o);case"collection":return Wo.render(n,t,o);case"doc_card":return ti.render(n,t,o);case"embed":return oi.render(n,t,o);case"openapi":return fi.render(n,t,o);case"sketch":return wi.render(n,t,o);case"latex":return $i.render(n,t,o);case"mermaid":return Mi.render(n,t,o);case"file":return a.config.fileUploader?si.render(a.config.fileUploader,n,t,o):(console.error("BlockManager::renderTool: File uploader not found for containerId:",n),null);case"header":return tn.render(n,t,o);case"image":return a.config.imageUploader?rn.render(a.config.imageUploader,n,t,o):(console.error("BlockManager::renderTool: Image uploader not found for containerId:",n),null);case"list":return cn.render(n,t,o);case"checklist":return _e.render(n,t,o);case"paragraph":return Rn.render(n,t,o);case"quote":return Wn.render(n,t,o);case"table":return aa.render(n,t,o);case"toc":return Si.render(n,t,o);case"video":return a.config.videoUploader?zo.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 a of e.getActiveBlocks(n))a.classList.remove(l.classNames.block.active);t.classList.add(l.classNames.block.active),Ui.show(n,t)}static getActiveBlock(e){const t=document.getElementById(e);return t?t.querySelector(`.${l.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 l=i.data;if("list"===n){const e=i.data,t=e.html||e.text||"";l={items:t?[t]:[""],type:"unordered"}}else if("header"===n){const e=i.data;l={html:e.html||e.text||"",level:"h1"}}const c={data:l,id:t,type:r.type},p=e.createBlockElement(c,a);if(!p)return console.error("BlockManager::convertBlock: New block element not found for newType:",n);o.replaceWith(p);const d=e.getBlockData(p.getAttribute("data-id"));m.getState().updateBlock(a,s,d),e.focusBlock(p)}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=he.getInstanceAndTargetFromRange(t);if(!n)return;const a=n.target.closest(`.${l.classNames.block.container}`);if(!a)return;const o=e.getBlockIndex(n.instance.config.containerId,a.getAttribute("data-id"));m.getState().updateBlock(n.instance.config.containerId,o,e.getBlockData(a.getAttribute("data-id")))}static renderBlock(t,n,a){const o=e.getBlocks(n),i=m.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=m.getState().getInstance(n);r&&te.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)),m.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();m.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(`.${l.classNames.editor.container}`);return t?t.id:null}static handleKeydown(t){const n=t,a=t.currentTarget,o=a.closest(`.${l.classNames.block.container}`),i=e.getEditorId(o);if(!i)return;const r=e.getBlockIndex(i,o.getAttribute("data-id")),s=n.metaKey||n.ctrlKey;if(n.shiftKey)switch(n.key){case"ArrowUp":t.preventDefault(),t.stopPropagation(),r>0&&e.moveBlock(i,r,r-1);break;case"ArrowDown":t.preventDefault(),t.stopPropagation();const n=e.getBlocks(i);n&&r<n.length-1&&e.moveBlock(i,r,r+1)}else if(s)switch(n.key){case"Delete":case"Backspace":t.preventDefault(),t.stopPropagation(),e.removeBlock(i,r)}else if("Enter"===n.key)n.preventDefault(),n.stopPropagation(),e.insertBlock({data:{html:""},type:"paragraph"},i,r+1);else if("Backspace"===n.key){if(!_(a.innerHTML))return;n.preventDefault(),n.stopPropagation(),e.removeBlock(i,r)}else{e.ensureActiveBlock(i);const a=e.getBlocks(i);switch(n.key){case"ArrowUp":if(t.preventDefault(),t.stopPropagation(),r>0){const t=a[r-1];t&&e.focusBlock(t)}return;case"ArrowDown":if(t.preventDefault(),t.stopPropagation(),r<a.length-1){const t=a[r+1];t&&e.focusBlock(t)}return}}}static handleInput(t){e.saveBlockData(t.currentTarget)}static ensureActiveBlock(t){const n=e.getBlocks(t);let a=e.getActiveBlock(t);if(!a){const t=document.activeElement;if(!t)return;const o=t.closest(`.${l.classNames.block.container}`);if(o)a=o,e.setActiveBlock(a);else{if(0===n.length)return;a=n[0],e.setActiveBlock(a)}}}static saveBlockData(t){const n=t.closest(`.${l.classNames.block.container}`),a=e.getEditorId(n);if(!a)return;const o=n.getAttribute("data-id");m.getState().updateBlockData(a,e.getBlockIndex(a,o),e.getBlockData(o).data)}static updateBlockData(t,n,a){const o=e.getBlock(t);if(o){const t=o.querySelector(`.${l.classNames.block.content}`);t&&(t.innerHTML="");const i=e.renderTool(o.getAttribute("data-tool"),n,a);i&&t.appendChild(i)}m.getState().updateBlockData(a,e.getBlockIndex(a,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]=[]),_i.forEach(e=>e.input.destroy(t));for(const a of e.getBlocks(t))a.remove()}},Ki=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=m.getState().getInstance(t);if(!n)return console.error("ActionBar::create: Instance not found for containerId:",t);l.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 a=document.getElementById(t);if(!a)return;const o=n.config.styles?.controls?.group,i=n.config.classNames?.controls?.group,r=n.config.styles?.controls?.button,s=n.config.classNames?.controls?.button,c=n.config.styles?.tooltips,p=n.config.classNames?.tooltips,d=q("div",l.classNames.actionBar.container);e.createButtonGroup(a,d,{buttonClassNames:s,buttonStyles:r,currentView:n.currentView,groupClassNames:i,groupStyles:o,tooltipClassNames:p,tooltipStyles:c}),a.insertBefore(d,a.firstChild)}static createButtonGroup(t,n,a){const o=q("div",l.classNames.actionBar.group);l.applyStyling(o,{classNames:a.groupClassNames,styles:a.groupStyles});const i=q("button",l.classNames.actionBar.button,{"data-testid":"action-bar-edit-button","data-view":"edit",id:D(t.id,l.idSuffixes.actionBar.editButton),type:"button"});i.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>',l.applyStyling(i,{classNames:a.buttonClassNames,styles:a.buttonStyles});const r=q("button",l.classNames.actionBar.button,{"data-testid":"action-bar-preview-button","data-view":"preview",id:D(t.id,l.idSuffixes.actionBar.previewButton),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="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>',l.applyStyling(r,{classNames:a.buttonClassNames,styles:a.buttonStyles});const s=q("button",l.classNames.actionBar.button,{"data-testid":"action-bar-json-button","data-view":"json",id:D(t.id,l.idSuffixes.actionBar.jsonButton),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="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>',l.applyStyling(s,{classNames:a.buttonClassNames,styles:a.buttonStyles}),"edit"===a.currentView?i.classList.add("active"):"preview"===a.currentView?r.classList.add("active"):"json"===a.currentView&&s.classList.add("active"),e.addEventListener(t.id,i,"click",e.handleViewChange),e.addEventListener(t.id,r,"click",e.handleViewChange),e.addEventListener(t.id,s,"click",e.handleViewChange),o.appendChild(i),o.appendChild(r),o.appendChild(s),n.appendChild(o),ee(i,"Edit Mode","above",a.tooltipClassNames,a.tooltipStyles),ee(r,"Preview Mode","above",a.tooltipClassNames,a.tooltipStyles),ee(s,"JSON Output","above",a.tooltipClassNames,a.tooltipStyles);const c=q("div",l.classNames.actionBar.action);l.applyStyling(c,{classNames:a.groupClassNames,styles:a.groupStyles});const p=q("button",l.classNames.actionBar.actionButton,{"data-testid":"view-copy-button",id:D(t.id,l.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>',l.applyStyling(p,{classNames:a.buttonClassNames,styles:a.buttonStyles});const d=q("button",l.classNames.actionBar.actionButton,{"data-testid":"view-download-button",id:D(t.id,l.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>',l.applyStyling(d,{classNames:a.buttonClassNames,styles:a.buttonStyles});const u=q("button",l.classNames.actionBar.actionButton,{"data-testid":"view-clear-button",id:D(t.id,l.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>',l.applyStyling(u,{classNames:a.buttonClassNames,styles:a.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),ee(p,"Copy JSON to Clipboard","above",a.tooltipClassNames,a.tooltipStyles),ee(d,"Download JSON File","above",a.tooltipClassNames,a.tooltipStyles),ee(u,"Clear Editor","above",a.tooltipClassNames,a.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(`.${l.classNames.actionBar.group}`);if(!n)return console.error("ActionBar::getCurrentView: View toggle group not found for container:",t.id),null;const a=n.querySelector(".active");return a?a.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 a=n.querySelector(`.${l.classNames.actionBar.container}`);a&&a.querySelectorAll(`#${D(e,l.idSuffixes.actionBar.editButton)}, #${D(e,l.idSuffixes.actionBar.previewButton)}, #${D(e,l.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=Wi.getEditorId(n);if(!a)return;const o=n.getAttribute("data-view");o&&(m.getState().setCurrentView(a,o),e.updateButtonStates(a,o))}static handleCopyJson(e){const t=e.currentTarget,n=Wi.getEditorId(t);if(!n)return;const a=m.getState().getInstance(n);a&&(navigator.clipboard.writeText(JSON.stringify(a.data,null,2)),t.classList.add(l.classNames.actionBar.copyFeedback),setTimeout(()=>t.classList.remove(l.classNames.actionBar.copyFeedback),200))}static handleClearEditor(e){const t=e.currentTarget,n=Wi.getEditorId(t);n&&Wi.resetBlocks(n)}static handleDownloadJson(e){const t=e.currentTarget,n=Wi.getEditorId(t);if(!n)return;const a=Wi.getBlocks(n).map(e=>Wi.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(`.${l.classNames.actionBar.container}`);n&&n.remove()}},Gi=`\n/* Editor Container */\n.${l.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.${l.classNames.editor.container}:focus {\n outline: none;\n}\n\n.${l.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.${l.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.${l.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.${l.classNames.editor.jsonOutput}:focus {\n outline: none;\n}\n\n/* Editable (allowed) -> green text */\n.${l.classNames.editor.jsonOutput}.clepit-json-editable {\n color: var(--clepit-success);\n}\n\n/* Invalid JSON -> red text */\n.${l.classNames.editor.jsonOutput}.clepit-json-error {\n color: var(--clepit-error);\n background-color: transparent;\n}\n\n.${l.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 .${l.classNames.editor.container} {\n padding: 8px;\n }\n\n .${l.classNames.editor.content} {\n padding: 12px;\n }\n}\n`,Ji=class{static render(e){const t=m.getState().getInstance(e);t&&(le.create(e),l.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'),Wi.renderBlocks(t.data.blocks,e))}},Xi=class e{static render(t){const n=m.getState().getInstance(t);if(!n)return;const a=document.getElementById(n.contentId);if(a)if(a.innerHTML="",n.data&&n.data.blocks&&n.data.blocks.length>0){const t=l.createStyledElement("pre",l.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(l.classNames.editor.jsonEditable),setTimeout(()=>t.focus(),0),e.addEventListeners(t)),a.appendChild(t)}else{const e=l.createStyledElement("div",l.classNames.editor.jsonEmpty);e.textContent="No content to display",a.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||"",a=Wi.getEditorId(t);if(a)try{const e=JSON.parse(n);if("object"==typeof e&&null!==e){e.blocks&&Array.isArray(e.blocks)||(e.blocks=[]);const t=m.getState().getInstance(a);if(t){const n=document.querySelector(`#${t.contentId} .${l.classNames.editor.jsonOutput}`);n&&(n.classList.remove(l.classNames.editor.jsonError),t.config.allowJsonViewEditing&&n.classList.add("clepit-json-editable"));const o=t.currentView;m.getState().setData(a,e),"json"===o&&m.getState().setCurrentView(a,"json"),console.log("Store updated successfully")}}}catch{const e=m.getState().getInstance(a);if(e){const t=document.querySelector(`#${e.contentId} .${l.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||"",a=Wi.getEditorId(t);if(!a)return;const o=m.getState().getInstance(a);if(o)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{le.hide(a),Ui.hide(a)}catch{}const t=o.currentView;m.getState().setData(a,e),"json"===t&&m.getState().setCurrentView(a,"json");const n=document.querySelector(`#${o.contentId} .${l.classNames.editor.jsonOutput}`);n&&(n.classList.remove("clepit-json-error"),o.config.allowJsonViewEditing?n.classList.add("clepit-json-editable"):n.classList.remove("clepit-json-editable")),o.config.onChange&&o.config.onChange(e)}}catch{const e=document.querySelector(`#${o.contentId} .${l.classNames.editor.jsonOutput}`);e&&(e.classList.add("clepit-json-error"),e.classList.remove("clepit-json-editable"))}}static destroy(t){const n=m.getState().getInstance(t);if(!n)return;const a=document.querySelector(`#${n.contentId} .${l.classNames.editor.jsonOutput}`);a&&e.removeEventListeners(a)}},Zi=/* @__PURE__ */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"]),Yi=(e,t)=>Zi.has(`${e}.${t}`),Qi=/* @__PURE__ */new Set(["checklist.items","list.items","table.data"]),er=(e,t)=>Qi.has(`${e}.${t}`),tr=(e,t,n,a)=>{if(!Array.isArray(t))return t;let o=!1;const i=e=>{const t=((e,t,n)=>{const a=ar(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},nr=(e,t,n,a)=>{let o=!1;const i={};for(const[r,s]of Object.entries(t)){if(er(e,r)){const t=tr(e,s,n,a);i[r]=t,t!==s&&(o=!0);continue}if(!Yi(e,r)){i[r]=s;continue}const t=ar(s,n,a);null!==t?(i[r]=t.value,t.value!==s&&(o=!0)):i[r]=s}return o?i:t},ar=(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]}},or="clepit-theme-styles",ir=".clepit-editor, .clepit-renderer-content, body[data-clepit-theme]",rr=`@layer clepit.reset, clepit.tokens, clepit.blocks, clepit.overrides;\n\n${Vi=i,Object.keys(r).map(e=>`@property ${r[e]} {\n syntax: '<color>';\n inherits: true;\n initial-value: ${Vi[e]};\n}`).join("\n\n")}\n\n@layer clepit.tokens {\n${s(i,{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)"},ir)}\n\n${ir} {\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`,sr=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 l.injectStyles(or,rr),l.injectStyles(V,U),n.classList.add(l.classNames.renderer.content),l.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=nr(e.type,e.data,t.locale,t.defaultLocale??t.locale);return n===e.data?e:{...e,data:n}}static renderBlock(e,t,n){const a=q("div",l.classNames.block.output);a.setAttribute("data-block-type",e.type),a.setAttribute("data-block-index",t.toString()),e.tunes&&Object.entries(e.tunes).forEach(([e,t])=>{a.setAttribute(`data-tune-${e}`,String(t))});const o=n.styles?.[e.type],i=n.classNames?.[e.type];let r,s,c,p=n.configs?.[e.type];if("paragraph"===e.type&&n.editorClassNames?.tooltips&&(p={...p,tooltipClassNames:n.editorClassNames.tooltips}),p?.margins&&(r=p.margins.top,s=p.margins.bottom),void 0===r&&void 0!==n.margins?.top&&(r=n.margins.top),void 0===s&&void 0!==n.margins?.bottom&&(s=n.margins.bottom),void 0!==r){const e=parseFloat(a.style.marginTop||"0")||0;a.style.marginTop=`${e+r}px`}if(void 0!==s){const e=parseFloat(a.style.marginBottom||"0")||0;a.style.marginBottom=`${e+s}px`}switch(e.type){case"alert":c=Ae.render(e.data,p,o,i);break;case"audio":c=Ie.render(e.data,p,o,i);break;case"code":c=st.render(e.data,p,o,i);break;case"collapsible":c=Fo.render(e.data,p,o,i);break;case"columns":c=kt.render(e.data,p,o,i);break;case"date":c=At.render(e.data,p,o,i);break;case"delimiter":c=$t.render(e.data,p,o,i);break;case"collection":c=ft.render(e.data,p,o,i);break;case"updates":c=Do.render(e.data,p,o,i);break;case"glance":c=Qt.render(e.data,p,o,i);break;case"embed":c=Ut.render(e.data,p,o,i);break;case"sketch":c=ea.render(e.data,p,o,i);break;case"latex":c=$o.render(e.data,p,o,i);break;case"mermaid":c=Mo.render(e.data,p,o,i);break;case"openapi":c=Hn.render(e.data,p,o,i);break;case"doc_card":c=qt.render(e.data,p,o,i);break;case"file":c=Xt.render(e.data,p,o,i);break;case"header":c=nn.render(e.data,p,o,i);break;case"image":c=sn.render(e.data,p,o,i);break;case"list":c=pn.render(e.data,p,o,i);break;case"checklist":c=je.render(e.data,p,o,i);break;case"paragraph":c=Fn.render(e.data,p,o,i);break;case"quote":c=Kn.render(e.data,p,o,i);break;case"table":c=ra.render(e.data,p,o,i);break;case"toc":c=da.render(e.data,{...p,documentBlocks:n.data?.blocks??[]},o,i);break;case"video":c=Oo.render(e.data,p,o,i);break;default:c=null}return c?(a.appendChild(c),te.initializeElements(a,{classNames:n.classNames?.tooltip,styles:n.styles?.tooltip}),a):null}},lr=class{static render(e){const t=m.getState().getInstance(e);t&&sr.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})}},cr=class e{static create(t){return e.destroy(t.containerId),e.initialize(t),Ki.create(t.containerId),e.render(t.containerId),he.addListeners(t.containerId),m.getState().setIsReady(t.containerId,!0),m.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)=>Wi.convertBlock(e,n,t.containerId),count:()=>Wi.getBlocks(t.containerId).length,get:e=>Wi.getBlock(e)?Wi.getBlockData(e):null,getAll:()=>Wi.getBlocks(t.containerId).map(e=>Wi.getBlockData(e.getAttribute("data-id"))),insert:(e,n,a,o)=>Wi.insertBlock({data:n,id:o??Math.random().toString(36).substring(2,11),type:e},t.containerId,a),move:(e,n)=>Wi.moveBlock(t.containerId,e,n),remove:e=>Wi.removeBlock(t.containerId,e),update:(e,n)=>Wi.updateBlockData(e,n,t.containerId)},blur:()=>{const e=document.activeElement;e&&document.getElementById(t.containerId)?.contains(e)&&e.blur()},data:{clear:()=>{m.getState().clearData(t.containerId),Wi.destroy(t.containerId)},clearContent:()=>Wi.destroy(t.containerId),clearStorage:()=>m.getState().clearData(t.containerId),extract:()=>Wi.extractData(t.containerId),set:e=>Wi.setBlocks(e.blocks,t.containerId)},destroy:()=>e.destroy(t.containerId),focus:()=>{const e=Wi.getBlocks(t.containerId)[0];e&&Wi.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:()=>Ui.hide(t.containerId),hideToolbar:()=>le.hide(t.containerId),showBlockMenu:e=>Ui.show(t.containerId,e),showToolbar:(e,n)=>le.show(t.containerId,e,n)},view:{getCurrentView:e=>m.getState().getCurrentView(e),switchView:(e,t)=>m.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}`;l.injectStyles(or,rr),l.injectStyles("clepit-editor-container-styles",Gi),l.injectStyles($,M),l.injectStyles(Z,Y),l.injectStyles(P,R);const a={allowJsonViewEditing:!1,initialView:"edit",maxHeight:0,minHeight:300,placeholder:"Start writing...",...t};n.className=l.classNames.editor.container,n.setAttribute("contenteditable","false"),l.registerEditor(t.containerId,a.theme??"auto",a.themeOverrides),a.minHeight&&n.style.setProperty("--clepit-min-height",`${a.minHeight}px`),a.maxHeight&&n.style.setProperty("--clepit-max-height",`${a.maxHeight}px`),l.applyStyles(n,a.styles?.container),l.applyClassNames(n,a.classNames?.container),a.margins&&(void 0!==a.margins.top&&n.style.setProperty("--block-margin-top",`${a.margins.top}px`),void 0!==a.margins.bottom&&n.style.setProperty("--block-margin-bottom",`${a.margins.bottom}px`));const o=`${a.containerId}-${l.idSuffixes.editorContent}`,i=q("div",l.classNames.editor.content);i.id=o,i.setAttribute("data-testid","editor-content-container"),i.setAttribute("data-container-id",t.containerId),l.applyStyles(i,a.styles?.editorContent),l.applyClassNames(i,a.classNames?.editorContent),n.appendChild(i),m.getState().addInstance(t.containerId,{config:a,contentId:o,currentView:a.initialView||"edit",data:e.localizeData(a.initialData,a),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(Zi).filter(t=>t.startsWith(`${e}.`)).map(t=>t.slice(e.length+1)).sort())(e.type)){const i=ar(n[r],a,o);i?.isFallback&&t.onLocaleFallback?.({blockId:e.id??"",field:r,requested:a,showing:i.locale})}const i=nr(e.type,n,a,o);return i===n?e:{...e,data:i}})}}static render(e){const t=m.getState().getInstance(e);if(!t)return;const n=document.getElementById(t.contentId);n&&(Xi.destroy(e),n.innerHTML=""),"edit"===t.currentView?Ji.render(e):"preview"===t.currentView?lr.render(e):"json"===t.currentView&&Xi.render(e),t.config.onReady&&t.config.onReady()}static destroy(e){he.removeListeners(e),Ki.destroy(e),Ui.destroy(e),le.destroy(e),Wi.destroy(e),l.unregisterEditor(e);const t=document.getElementById(e);t&&(t.innerHTML="")}},pr=e=>e.replace(/["\\]/g,"\\$&"),dr=e=>e.flatMap(e=>"collapsible"===e.type?[e,...dr(e.data.children??[])]:"columns"===e.type?[e,...dr(e.data.columns?.flat()??[])]:[e]),ur=(e,t)=>{const n=[];for(const a of dr(t)){if(!a.id)continue;if("code"!==a.type&&"openapi"!==a.type&&"table"!==a.type)continue;const t=e.querySelector(`[data-clepit-block-id="${pr(a.id)}"]`);if(!t||t.hasAttribute("data-clepit-activated"))continue;t.setAttribute("data-clepit-activated","");const o="code"===a.type?st.activate(t,a.data):"openapi"===a.type?Hn.activate(t):ra.activate(t,a.data);n.push(()=>{o(),t.removeAttribute("data-clepit-activated")})}return()=>{for(const e of n)e()}},mr=/* @__PURE__ */new Set(["strong","b","em","i","u","s","del","mark","code","a","span"]),hr=/* @__PURE__ */new Set(["href","target","data-tooltip","data-status","data-status-variant","data-user-id","data-page-id","class"]),gr=/* @__PURE__ */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,fr=e=>{const t=/* @__PURE__ */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},yr=e=>{const t=e.trim().toLowerCase().replace(/[\x00-\x20]/g,"");return!t.startsWith("javascript:")&&!t.startsWith("data:")&&!t.startsWith("vbscript:")},vr=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:fr(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(!mr.has(a.tag))continue;const e=n.lastIndexOf(a.tag);if(-1===e)continue;t.push(`</${a.tag}>`),n.splice(e,1);continue}if(!mr.has(a.tag))continue;const e=[];for(const[t,n]of a.attributes)hr.has(t)&&("href"!==t||yr(n))&&e.push(`${t}="${ke(n)}"`);"a"===a.tag&&e.push('target="_blank"','rel="noopener noreferrer"'),t.push(`<${[a.tag,...e].join(" ")}>`),a.selfClosing||gr.has(a.tag)||n.push(a.tag)}for(const a of[...n].reverse())t.push(`</${a}>`);return t.join("")},xr=()=>[rr,ge,$e,De,Pe,Qe(),dt,bt,xt,Et,Lt,Tt,jt,Gt,Zt,en,on,ln,dn,Pn,Un,Xn,na,ca,ha,qo,jo].join("\n"),kr=(e,t)=>{const n=Ce(vr),a={...t,documentBlocks:t?.documentBlocks??e};return e.map(e=>Ho(e,n,a)).filter(e=>null!==e).map(e=>Ee(e)).join("\n")},wr=(e,t)=>{const n=xe(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="${ke(e.description)}">`:"",e.canonicalUrl?`<link rel="canonical" href="${ke(e.canonicalUrl)}">`:"",`<meta property="og:title" content="${ke(e.title)}">`,e.description?`<meta property="og:description" content="${ke(e.description)}">`:"",`<style>${xr()}</style>`].filter(Boolean);return["<!doctype html>",`<html lang="${ke(e.locale??"en")}">`,`<head>${a.join("")}</head>`,"<body>",'<main class="clepit-public-page">',`<h1 class="clepit-public-page__title">${n}</h1>`,kr(e.blocks,{...t,anchorTargets:!0}),"</main>","</body>","</html>"].join("\n")};export{oe as BLOCK_TOOLS,cr as Editor,ae as INLINE_TOOLS,sr as Renderer,l as StyleManager,ur as activateBlocks,ye as domBacking,Ho as drawBlock,xr as pageStylesheet,In as parseOpenApi,kr as renderBlocks,wr as renderPage,Ee as renderToString,vr as sanitizeHtmlWithoutDom,Ce as stringBacking,Se as toDomElement,s as tokensToLightDarkBlock};
1
+ import{a as e,i as t,n,r as a,t as o}from"./highlight-C4NcTcIm.mjs";var i={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)"},r={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"},s=(e,t,n)=>{const a=[];for(const o of Object.keys(r)){const n=e[o],i=t[o];if(void 0===n&&void 0===i)continue;const s=r[o];void 0!==n&&void 0!==i?a.push(` ${s}: light-dark(${n}, ${i});`):a.push(` ${s}: ${n??i};`)}return 0===a.length?"":`${n} {\n${a.join("\n")}\n}`},l=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=/* @__PURE__ */new Map}static{this.themeSubscribers=/* @__PURE__ */new Set}static registerEditor(t,n,a){const o=document.getElementById(t);o&&(o.setAttribute("data-clepit-theme",n),o.setAttribute("data-clepit-instance",t)),e.themeRegistry.set(t,n),e.syncBodyThemeAttribute();const i=document.getElementById(`clepit-overrides-${t}`);if(i&&i.remove(),a){const n=s(a.light??{},a.dark??{},`[data-clepit-instance='${t}']`);n&&e.injectStyles(`clepit-overrides-${t}`,n)}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)}},c=e=>{let t;const n=/* @__PURE__ */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 d,p,u,m=(u?c(u):c)((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))((d=(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}))}}),p={name:"clepit-store",version:0},(e,t,n)=>{const a=p.version??0,o=p.storage??("undefined"==typeof localStorage?void 0:localStorage),i=p.merge??((e,t)=>Object.assign({},t,e)),r=d(e,t,n);if(o){try{const e=o.getItem(p.name);if(e){const t=JSON.parse(e),n=t.version===a?t.state:p.migrate?p.migrate(t.state,t.version??0):void 0;void 0!==n&&Object.assign(r,i(n,r))}}catch{}n.subscribe(e=>{try{o.setItem(p.name,JSON.stringify({state:p.partialize?p.partialize(e):e,version:a}))}catch{}})}return r}))));function h(){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 g(){return"mac"===h()?"⌘":"Ctrl"}function b(e){return"mac"===h()?e.join(""):e.join(" + ")}var f=e=>b([g(),e]),y=e=>b([g(),{down:"↓",left:"←",right:"→",up:"↑"}[e]]),v=()=>b([g(),"B"]),x=()=>b([g(),"⌫"]),k=()=>b([g(),"⌦"]),w=()=>b([g(),"I"]),C=()=>b([g(),"K"]),S=e=>b([g(),"⇧",e]),E=e=>b([g(),"⇧",{down:"↓",left:"←",right:"→",up:"↑"}[e]]),A=()=>b([g(),"U"]),N=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=v()}static apply(e){l.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),Qr.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))}}}Qr.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}},L=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=f("`")}static apply(e,t,n){l.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 a=document.createElement("code");a.classList.add("clepit-inline-code"),t&&l.applyClassNames(a,t),n&&Object.entries(n).forEach(([e,t])=>{if(void 0!==t){const n=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);a.style.setProperty(n,String(t))}}),e.surroundContents(a),Qr.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))}}}Qr.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&&l.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))}}))})}},B=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=w()}static apply(e){l.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),Qr.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))}}}Qr.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}},$="clepit-link-styles",I=`\n/* Link styles - simple and clean */\n.${l.classNames.block.link} {\n color: var(--clepit-primary);\n cursor: pointer;\n}\n\n.${l.classNames.block.link}:hover {\n color: var(--clepit-primary-hover);\n}\n`,T="clepit-dialogs-styles",M="\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 _(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 q(e,t){return`${e}-${t}`}function D(e){return!e||!e.trim()||"<br>"===e}function j(e){if(!e||D(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","title","contenteditable","data-tooltip","data-status","data-status-variant","data-user-id","data-page-id","data-issue-tool","data-issue-key","data-issue-title","data-issue-state","data-issue-category","data-issue-assignee","data-issue-avatar","data-issue-updated","data-issue-url","data-issue-pull","data-issue-reason","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 z(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 O=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||(l.injectStyles(T,M),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=_("dialog","clepit-dialog-overlay"),this.applyStyles(this.overlay,this.options.styles?.overlay),this.applyClassNames(this.overlay,this.options.classNames?.overlay),this.dialog=_("div","clepit-dialog"),this.applyStyles(this.dialog,this.options.styles?.container),this.applyClassNames(this.dialog,this.options.classNames?.container);const e=_("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=_("div","clepit-dialog-group");this.applyStyles(a,this.options.styles?.group),this.applyClassNames(a,this.options.classNames?.group);const o=_("label","clepit-dialog-label");o.textContent=e,this.applyStyles(o,this.options.styles?.label),this.applyClassNames(o,this.options.classNames?.label);const i=_("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=_("div","clepit-dialog-buttons");this.applyStyles(e,this.options.styles?.buttons),this.applyClassNames(e,this.options.classNames?.buttons);const t=_("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=_("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}},H=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=C()}static apply(t,n,a){l.injectStyles($,I);const o=t.toString().trim(),i=e.findLinkElement(t.commonAncestorContainer);let r=o,s="";i&&(r=i.textContent||o,s=i.href||"");const c=t.cloneRange();new O({classNames:n,onCancel:()=>{const e=window.getSelection();e&&(e.removeAllRanges(),e.addRange(c))},onConfirm:(t,n)=>{try{const a=window.getSelection();if(a){if(a.removeAllRanges(),a.addRange(c),!n.trim())return void e.remove(c);if(t!==o){c.deleteContents();const e=document.createTextNode(t);c.insertNode(e),c.selectNode(e)}const i=l.createStyledElement("a",l.classNames.block.link);i.href=n,i.target="_blank",i.rel="noopener noreferrer";try{c.surroundContents(i)}catch{const e=c.extractContents();i.appendChild(e),c.insertNode(i)}const r=document.createRange();r.selectNodeContents(i),a.removeAllRanges(),a.addRange(r);const s=i.closest('[contenteditable="true"]');if(s){const e=new Event("input",{bubbles:!0});s.dispatchEvent(e)}}}catch(a){console.error("Failed to apply link:",a)}},styles:a,text:r||"Link text",url:s}).show(),Qr.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))}}}Qr.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}},P="clepit-marker-styles",R="\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",F=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=S("M")}static apply(t,n,a){l.injectStyles(P,R);const o=document.createElement("span");o.classList.add("clepit-marker-wrapper");const i=document.createElement("span");i.classList.add("clepit-marker-stroke");const r=t.extractContents();o.appendChild(document.createTextNode(" ")),o.appendChild(r),o.appendChild(document.createTextNode(" ")),o.insertBefore(i,o.firstChild),t.insertNode(o),t.selectNodeContents(o),e.applyUserStyles(o,i,n,a);const s=o.closest('[contenteditable="true"]');s&&s.dispatchEvent(new Event("input",{bubbles:!0})),Qr.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}))}}Qr.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(l.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(l.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,a,o){a&&l.applyClassNames(t,a),o&&Object.entries(o).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 i=t.style.getPropertyValue("--marker-background")||t.getAttribute("data-marker-background");if(i){const t=e.createStrokeSVG(i);return void(n.style.background=t)}if(o?.background){const t=o.background;if(t){const a=e.createStrokeSVG(String(t));return void(n.style.background=a)}}const r=t.closest(`.${l.classNames.editor.content}, .${l.classNames.renderer.content}`);if(r){const t=window.getComputedStyle(r).getPropertyValue("--clepit-marker-background");if(t&&"initial"!==t&&"inherit"!==t){const a=e.createStrokeSVG(t.trim());return void(n.style.background=a)}}const s=t.closest(`.${l.classNames.block.content}`);if(!s)return;const c=s.style.background||s.style.backgroundColor||s.style.getPropertyValue("background-color");if(c&&"initial"!==c&&"inherit"!==c){const t=e.createStrokeSVG(c);return void(n.style.background=t)}const d=window.getComputedStyle(s).backgroundColor;if(d&&"rgba(0, 0, 0, 0)"!==d&&"transparent"!==d){const t=e.createStrokeSVG(d);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"}},U="clepit-inline-status-styles",V='\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',W=["info","success","warning","error","plain"],K=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||(l.injectStyles(T,M),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=_("dialog","clepit-dialog-overlay"),this.applyStyles(this.overlay,this.options.styles?.overlay),this.dialog=_("div","clepit-dialog"),this.applyStyles(this.dialog,this.options.styles?.container);const e=_("h3","clepit-dialog-title");e.textContent="Inline status",this.applyStyles(e,this.options.styles?.title),this.dialog.appendChild(e);const t=_("label","clepit-dialog-label");t.textContent="Label",this.applyStyles(t,this.options.styles?.label),this.dialog.appendChild(t),this.textInput=_("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=_("label","clepit-dialog-label");n.textContent="Variant",this.applyStyles(n,this.options.styles?.label),this.dialog.appendChild(n);const a=_("div","clepit-status-dialog-variants");for(const c of W){const e=_("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=_("div","clepit-dialog-buttons");this.applyStyles(o,this.options.styles?.buttons);const i=_("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=_("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))}},G="clepit-status",J=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,a){l.injectStyles(U,V);const o=t.toString().trim(),i=e.findStatusElement(t.commonAncestorContainer),r=i?i.textContent??o:o,s=i?e.readVariant(i):"info",c=t.cloneRange();new K({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!==o){c.deleteContents();const e=document.createTextNode(t);c.insertNode(e),c.selectNode(e)}const i=document.createElement("span");i.className=(e=>`${G} ${G}--${e}`)(n),i.dataset.statusVariant=n;try{c.surroundContents(i)}catch{const e=c.extractContents();i.appendChild(e),c.insertNode(i)}const r=document.createRange();r.selectNodeContents(i),a.removeAllRanges(),a.addRange(r);const s=i.closest('[contenteditable="true"]');s&&s.dispatchEvent(new Event("input",{bubbles:!0}))}catch(a){console.error("Failed to apply inline status:",a)}},styles:a,text:r||"status",variant:s}).show(),Qr.updateStateFromRange(t)}static remove(t){e.unwrap(t),Qr.updateStateFromRange(t)}static isActive(t){return!!e.findStatusElement(t.commonAncestorContainer)||t.cloneContents().querySelectorAll(`.${G}`).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(`.${G}`);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(G))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(`${G}--${n}`))return n;return"info"}},X=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=S("X")}static apply(e){l.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),Qr.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))}}}Qr.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}},Z="clepit-tooltip-styles",Y=`\n/* Tooltip styles - border bottom instead of text-decoration to avoid underline tool conflict */\n.${l.classNames.block.tooltip} {\n border-bottom: 1px dotted var(--clepit-text-subtle);\n cursor: help;\n}\n\n.${l.classNames.block.tooltip}:hover {\n border-bottom: 1px dotted var(--clepit-text-muted);\n}\n`,Q=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||(l.injectStyles(T,M),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=_("dialog","clepit-dialog-overlay"),this.applyStyles(this.overlay,this.options.styles?.overlay),this.applyClassNames(this.overlay,this.options.classNames?.overlay),this.dialog=_("div","clepit-dialog"),this.applyStyles(this.dialog,this.options.styles?.container),this.applyClassNames(this.dialog,this.options.classNames?.container);const e=_("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=_("div","clepit-dialog-group");this.applyStyles(a,this.options.styles?.group),this.applyClassNames(a,this.options.classNames?.group);const o=_("label","clepit-dialog-label");o.textContent=e,this.applyStyles(o,this.options.styles?.label),this.applyClassNames(o,this.options.classNames?.label);const i=_("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=_("div","clepit-dialog-buttons");this.applyStyles(e,this.options.styles?.buttons),this.applyClassNames(e,this.options.classNames?.buttons);const t=_("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=_("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 ee(e,t,n="below",a,o){let i=null,r=null;const s=()=>{if(i)return;l.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"),i=document.createElement("div"),i.className=`clepit-inline-tooltip ${a?.container||""}`,l.applyStyling(i,{styles:o?.container});const s=document.createElement("div");s.className=`clepit-inline-tooltip-content ${a?.content||""}`,s.textContent=t,l.applyStyling(s,{styles:o?.content});const d=document.createElement("div");d.className=`clepit-inline-tooltip-arrow clepit-inline-tooltip-arrow--${n} ${a?.arrow||""}`,l.applyStyling(d,{styles:o?.arrow}),s.appendChild(d),i.appendChild(s),document.body.appendChild(i);const p=e.getBoundingClientRect(),u=s.offsetWidth,m=s.offsetHeight;let h,g=p.left+p.width/2-u/2;g=Math.max(8,Math.min(g,window.innerWidth-u-8));let b=n;"below"===n?(h=p.bottom+6+2,h+m>window.innerHeight-8&&(h=p.top-m-6-2,b="above")):(h=p.top-m-6-2,h<8&&(h=p.bottom+6+2,b="below")),d.className=`clepit-inline-tooltip-arrow clepit-inline-tooltip-arrow--${b} ${a?.arrow||""}`,i.style.left=`${g}px`,i.style.top=`${Math.max(8,Math.min(h,window.innerHeight-m-8))}px`,requestAnimationFrame(()=>{i&&(i.style.opacity="1",s.style.transform="translateY(0)")}),r||(r=new MutationObserver(()=>{document.body.contains(e)&&e.isConnected||(c(),r&&(r.disconnect(),r=null))}),r.observe(document.body,{childList:!0,subtree:!0}))},c=()=>{i&&(i.style.opacity="0",setTimeout(()=>{i&&i.parentElement&&i.parentElement.removeChild(i),i=null,r&&(r.disconnect(),r=null)},120))};return e.addEventListener("mouseenter",s),e.addEventListener("mouseleave",c),()=>{e.removeEventListener("mouseenter",s),e.removeEventListener("mouseleave",c),c()}}var te=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=S("T")}static apply(t,n,a){l.injectStyles(Z,Y);const o=t.toString(),i=t.cloneRange();let r="",s=o;const c=e.findTooltipSpan(t.commonAncestorContainer);c&&(r=c.getAttribute("data-tooltip")||"",s=c.textContent||""),new Q({classNames:n.classNames,onCancel:()=>{const e=window.getSelection();e&&(e.removeAllRanges(),e.addRange(i))},onConfirm:(t,o)=>{const r=window.getSelection();if(!r)return;if(r.removeAllRanges(),r.addRange(i),!o.trim())return e.remove(i),void(t!==s&&(i.deleteContents(),i.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),i.selectNode(t)}}if(t!==s){i.deleteContents();const e=document.createTextNode(t);i.insertNode(e),i.selectNode(e)}const d=l.createStyledElement("span",l.classNames.block.tooltip);d.setAttribute("data-tooltip",o),a.classNames&&l.applyClassNames(d,a.classNames),a.styles&&Object.entries(a.styles).forEach(([e,t])=>{if(void 0!==t){const n=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);d.style.setProperty(n,String(t))}});try{i.surroundContents(d)}catch{const e=i.extractContents();d.appendChild(e),i.insertNode(d)}t!==s&&d.textContent!==t&&(d.textContent=t),ee(d,o,"above",n.classNames,n.styles);const p=d.closest('[contenteditable="true"]');p&&p.dispatchEvent(new Event("input",{bubbles:!0}))},styles:n.styles,text:s,tooltip:r}).show(),Qr.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)}Qr.updateStateFromRange(t)}static isActive(t){const n=t.commonAncestorContainer;return!!e.findTooltipSpan(n)||t.cloneContents().querySelectorAll(`span.${l.classNames.block.tooltip}`).length>0}static initializeElements(e,t){e.querySelectorAll(`span.${l.classNames.block.tooltip}`).forEach(e=>{if(e instanceof HTMLElement&&(t.classNames&&l.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&&(ee(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(l.classNames.block.tooltip))return e}return t.parentNode?e.findTooltipSpan(t.parentNode):null}},ne=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=A()}static apply(e){l.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),Qr.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))}}}Qr.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}},ae=["bold","inline-code","italic","link","marker","status","strikethrough","tooltip","underline"],oe=["alert","audio","checklist","code","collapsible","collection","columns","date","delimiter","doc_card","embed","file","glance","header","image","issues","latex","list","mermaid","openapi","paragraph","quote","sketch","table","toc","updates","video"],ie=["asana","github_issues","jira","linear"],re=["categoryCancelled","categoryDone","categoryStarted","categoryTodo","columnAssignee","columnIssue","columnStatus","columnTitle","connectAction","connectTool","linkedIssuesEmpty","noAccess","openInTool","providerUnreachable","showAsCard","unassigned","updatedRelative"],se=["connectGoogle","connectGoogleAction","noAccess","providerUnreachable","tryAgain","switchedOff","offerShowLive","viewOnGithub","truncated"],le=["improve","shorten","lengthen","simplify","fix_grammar"],ce=()=>[N,B,ne,X,L,F,J,H,te],de="inline-toolbar",pe=class e{static{this.eventListenersMap=/* @__PURE__ */new WeakMap}static{this.hideTimeoutMap=/* @__PURE__ */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=m.getState().getInstance(t);if(!n)return console.error("InlineToolbar::create: Instance not found for containerId:",t);const a=document.getElementById(t);if(!a)return console.error("InlineToolbar::create: Container not found for containerId:",t);e.eventListenersMap.has(a)||e.eventListenersMap.set(a,[]),l.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 o=_("div","clepit-toolbar");o.id=`${t}-${de}`,o.classList.add("clepit-toolbar--hidden","clepit-toolbar--layout"),l.applyStyling(o,{classNames:n.config.classNames?.inlineToolbar?.container,styles:n.config.styles?.inlineToolbar?.container}),a.appendChild(o)}static repaint(t,n){const a=m.getState().getInstance(t);if(!a)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 o=((n.commonAncestorContainer.nodeType===Node.ELEMENT_NODE?n.commonAncestorContainer:n.commonAncestorContainer.parentElement)?.closest(`.${l.classNames.block.container}`))?.getAttribute("data-tool");e.getFilteredTools(o).forEach(a=>e.addButton(t,a,n)),a.config.onInlineRewrite&&e.addRewriteButton(t,n);const i=n.getBoundingClientRect(),r=document.getElementById(a.config.containerId)?.getBoundingClientRect();if(!r)return;const s=((e=!1)=>({height:40,width:24*(ce().length+(e?1:0))+16}))(Boolean(a.config.onInlineRewrite)),c=i.left-r.left+i.width/2-s.width/2;let d=i.top-r.top-s.height-8;d<0&&(d=i.bottom-r.top+8),e.show(a.config.containerId,c,d)}static addRewriteButton(t,n){const a=m.getState().getInstance(t),o=a?.config.onInlineRewrite;if(!a||!o)return;const i=e.getElementFromContainerId(t),r=document.getElementById(t);if(!i||!r)return;const s=_("button","clepit-toolbar-button",{type:"button"});s.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>',s.setAttribute("data-tool","rewrite"),l.applyStyling(s,{classNames:a.config.classNames?.inlineToolbar?.button,styles:a.config.styles?.inlineToolbar?.button});const c=_("div","clepit-toolbar-rewrite-menu");c.style.display="none",c.setAttribute("data-rewrite-menu","true");for(const l of le){const t=_("button","clepit-toolbar-rewrite-item",{type:"button"});t.textContent=a.config.inlineRewriteLabels?.[l]??l,t.setAttribute("data-rewrite-action",l),e.addEventListener(r,t,"mousedown",e=>e.preventDefault()),e.addEventListener(r,t,"click",()=>{c.style.display="none";const e=window.getSelection(),t=e&&e.rangeCount>0?e.getRangeAt(0):null,a=t&&!t.collapsed?t:n,i=a.toString();i.trim()&&(s.classList.add("busy"),o(i,l).then(e=>{e&&(a.deleteContents(),a.insertNode(document.createTextNode(e)),r.dispatchEvent(new Event("input",{bubbles:!0})))}).catch(()=>{}).finally(()=>s.classList.remove("busy")))}),c.appendChild(t)}e.addEventListener(r,s,"mousedown",e=>e.preventDefault()),e.addEventListener(r,s,"click",()=>{c.style.display="none"===c.style.display?"flex":"none"}),i.appendChild(s),e.createTooltip(i,s,"rewrite"),i.appendChild(c)}static addButton(t,n,a){const o=m.getState().getInstance(t);if(!o)return console.error("InlineToolbar::addButton: Instance not found for containerId:",t);const i=e.getElementFromContainerId(t);if(!i)return console.error("InlineToolbar::addButton: Toolbar not found for containerId:",t);const r=_("button","clepit-toolbar-button",{type:"button"});r.innerHTML=n.icon,l.applyStyling(r,{classNames:o.config.classNames?.inlineToolbar?.button,styles:o.config.styles?.inlineToolbar?.button}),n.isActive(a)&&r.classList.add("active"),r.setAttribute("data-tool",n.label.toLowerCase());const s=document.getElementById(t);s&&(e.addEventListener(s,r,"mousedown",e=>e.preventDefault()),e.addEventListener(s,r,"click",()=>{try{const e=window.getSelection(),t=e&&e.rangeCount>0?e.getRangeAt(0):null,i=t&&!t.collapsed?t:a;if(i&&n.isActive(i))n.remove(i),r.classList.remove("active");else if(i){switch(n.label){case"italic":B.apply(i);break;case"bold":N.apply(i);break;case"underline":ne.apply(i);break;case"strikethrough":X.apply(i);break;case"inlineCode":L.apply(i,o.config.classNames?.blocks?.["inline-code"],o.config.styles?.blocks?.["inline-code"]);break;case"marker":F.apply(i,o.config.classNames?.blocks?.marker,o.config.styles?.blocks?.marker);break;case"status":J.apply(i,o.config.classNames?.dialogs,o.config.styles?.dialogs);break;case"link":H.apply(i,o.config.classNames?.dialogs,o.config.styles?.dialogs);break;case"tooltip":te.apply(i,{classNames:o.config.classNames?.tooltips,styles:o.config.styles?.tooltips},{classNames:o.config.classNames?.blocks?.tooltip,styles:o.config.styles?.blocks?.tooltip})}r.classList.add("active")}}catch(e){console.warn("Error applying inline tool:",e)}})),i.appendChild(r),e.createTooltip(i,r,n.label)}static createTooltip(t,n,a){const o=_("div","clepit-toolbar-tooltip clepit-toolbar-tooltip--hidden"),i=_("div","clepit-toolbar-tooltip-content");i.textContent=a;const r=_("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}-${de}`):(console.error("InlineToolbar::getElementFromContainerId: Container not found for containerId:",e),null)}static getFilteredTools(e){return"header"===e?ce().filter(e=>"bold"!==e.label):ce()}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}-${de}`);if(!o)return console.warn("InlineToolbar::destroy: Toolbar not found for containerId:",t);o.remove()}},ue=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))}},me={create:e=>new ue(document.createElement(e)),createNS:(e,t)=>new ue(document.createElementNS(e,t))},he=/* @__PURE__ */new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),ge=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),be=e=>e.replace(/&/g,"&amp;").replace(/"/g,"&quot;"),fe=class{constructor(e,t){this.tag=e,this.sanitize=t,this.attributes=/* @__PURE__ */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(ge(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(ge(e))}toString(){const e=[...this.classes.length>0?[`class="${be(this.classes.join(" "))}"`]:[],...[...this.attributes].map(([e,t])=>`${e}="${be(t)}"`)],t=[this.tag,...e].join(" ");return he.has(this.tag)?`<${t}>`:`<${t}>${this.children.join("")}</${this.tag}>`}},ye=e=>({create:t=>new fe(t,e),createNS:(t,n)=>new fe(n,e)}),ve=e=>String(e),xe=e=>{if(!(e instanceof ue))throw new TypeError("toDomElement needs an element built by the dom backing");return e.node};function ke(){l.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=_("div","clepit-invalid-data"),t=_("div","clepit-invalid-data-text");return t.textContent="Invalid data",e.appendChild(t),e}var we={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 Ce(e){return we[e]||"Unknown"}var Se=Object.fromEntries(Object.keys(n).map(e=>[e,{name:Ce(e)}])),Ee=`\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.${l.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.${l.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.${l.classNames.block.code.editor} .clepit-code-highlight,\n.${l.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.${l.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.${l.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.${l.classNames.block.code.editor} .clepit-code-input::placeholder {\n color: var(--clepit-text-muted);\n}\n\n.${l.classNames.block.code.editor} .clepit-code-input::selection {\n background: var(--clepit-code-selection-bg);\n color: transparent;\n}\n\n/* Code header */\n.${l.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.${l.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`,Ae="clepit-code-output-styles",Ne="\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",Le={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 Be(e){return Le[e]||"Unknown"}var $e=Object.fromEntries(Object.keys(Le).map(e=>[e,{name:Be(e),theme:null}])),Ie=`\n/* Custom Switch Container */\n.${l.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.${l.classNames.switch.container} .tgl {\n display: none;\n}\n\n.${l.classNames.switch.container} .tgl,\n.${l.classNames.switch.container} .tgl:after,\n.${l.classNames.switch.container} .tgl:before,\n.${l.classNames.switch.container} .tgl *,\n.${l.classNames.switch.container} .tgl *:after,\n.${l.classNames.switch.container} .tgl *:before,\n.${l.classNames.switch.container} .tgl + .tgl-btn {\n box-sizing: border-box;\n}\n\n.${l.classNames.switch.container} .tgl::selection,\n.${l.classNames.switch.container} .tgl:after::selection,\n.${l.classNames.switch.container} .tgl:before::selection,\n.${l.classNames.switch.container} .tgl *::selection,\n.${l.classNames.switch.container} .tgl *:after::selection,\n.${l.classNames.switch.container} .tgl *:before::selection,\n.${l.classNames.switch.container} .tgl + .tgl-btn::selection {\n background: none;\n}\n\n.${l.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.${l.classNames.switch.container} .tgl + .tgl-btn:after,\n.${l.classNames.switch.container} .tgl + .tgl-btn:before {\n position: relative;\n display: block;\n content: "";\n width: 44%;\n height: 100%;\n}\n\n.${l.classNames.switch.container} .tgl + .tgl-btn:after {\n left: 0;\n}\n\n.${l.classNames.switch.container} .tgl + .tgl-btn:before {\n display: inline;\n position: absolute;\n top: 3px;\n}\n\n.${l.classNames.switch.container} .tgl:checked + .tgl-btn:after {\n left: 56.5%;\n}\n\n.${l.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.${l.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.${l.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.${l.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.${l.classNames.switch.container} .tgl-ios + .tgl-btn:active:after {\n padding-right: 0.4em;\n}\n\n.${l.classNames.switch.container} .tgl-ios:checked + .tgl-btn {\n background: var(--switch-blue);\n}\n\n.${l.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.${l.classNames.switch.container} .tgl-ios:checked + .tgl-btn:active:after {\n margin-left: -0.4em;\n}\n\n.${l.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`,Te=class{static create(e={}){const{checked:t=!1,onToggle:n,classNames:a,styles:o,label:i,id:r=`switch-${Math.random().toString(36).substring(2,11)}`}=e;l.injectStyles("clepit-custom-switch-styles",Ie);const s=l.createStyledElement("div",l.classNames.switch.container,{classNames:a?.container,styles:o?.container}),c=l.createStyledElement("input","tgl tgl-ios",{classNames:a?.input,styles:o?.input});c.type="checkbox",c.id=r,c.checked=t;const d=l.createStyledElement("label","tgl-btn",{classNames:a?.label,styles:o?.label});if(d.setAttribute("for",r),n&&c.addEventListener("change",e=>{const t=e.target;n(t.checked)}),s.appendChild(c),s.appendChild(d),i){const e=l.createStyledElement("span","clepit-switch-label-text",{classNames:a?.labelText,styles:o?.labelText});e.textContent=i,s.appendChild(e)}return s}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)}},Me=class e{static{this.placeholder="Enter code..."}static{this.supportedLanguages=Se}static{this.supportedThemes=$e}static{this.defaultLanguage="typescript"}static{this.defaultTheme="auto"}static{this.inputMap=/* @__PURE__ */new WeakMap}static{this.dataMap=/* @__PURE__ */new WeakMap}static save(t){const n=t.querySelector(`.${l.classNames.block.code.container}`),a=n.querySelector(`.${l.classNames.block.code.headerWrapper}`),o=n?.getAttribute("data-language")||e.defaultLanguage,i=n?.getAttribute("data-theme")||e.defaultTheme,r=!!a&&Te.getState(a),s=e.inputMap.get(n);if(s){const t=s.value,a=e.dataMap.get(n),l={code:t.trim()||"",language:o,showCopy:r,theme:i};return a?.variants?.length&&(l.variants=a.variants),a?.syncKey&&(l.syncKey=a.syncKey),e.dataMap.set(n,l),l}return{...e.dataMap.get(n)||{code:"",language:e.defaultLanguage,theme:e.defaultTheme},showCopy:r}}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,a,o){l.injectStyles("clepit-code-input-styles",Ee);const i={code:"",language:o?.language||e.defaultLanguage,showCopy:!0,theme:o?.theme||e.defaultTheme},r=n?{...i,...n}:i,s=l.createStyledElement("div",l.classNames.block.code.container,{classNames:a?.classNames?.container,styles:a?.styles?.container});s.setAttribute("data-language",r.language||e.defaultLanguage),s.setAttribute("data-theme",r.theme||e.defaultTheme);const c=l.createStyledElement("div",l.classNames.block.code.headerWrapper,{classNames:a?.classNames?.header?.wrapper,styles:a?.styles?.header?.wrapper}),d=l.createStyledElement("div",l.classNames.block.code.header,{classNames:a?.classNames?.header?.text,styles:a?.styles?.header?.text}),p=Se[r.language]?.name||Ce(e.defaultLanguage),u=$e[r.theme]?.name||Be(e.defaultTheme);d.textContent=e.getHeaderText(p,u);const h=l.createStyledElement("div",l.classNames.block.code.editor,{classNames:a?.classNames?.container,styles:a?.styles?.container});h.setAttribute("data-placeholder",e.placeholder);const g=t?m.getState().getInstance(t):null,b=g?.config.classNames?.switch,f=g?.config.styles?.switch,y=Te.create({checked:r.showCopy||!1,classNames:b,label:"Allow copy",onToggle:t=>{const n=e.dataMap.get(s)||{code:"",language:e.defaultLanguage,theme:e.defaultTheme};e.dataMap.set(s,{...n,showCopy:t}),Qr.saveBlockData(s)},styles:f});return c.appendChild(d),c.appendChild(y),s.appendChild(c),s.appendChild(h),e.mountEditor(s,h,r),s}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",`${Ce(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}),Qr.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 i=t.getAttribute("data-language")||e.defaultLanguage;n.replaceChildren(...o(a.endsWith("\n")?`${a} `:a,i).map(e=>{const t=document.createElement("span");return e.classes&&(t.className=e.classes),t.textContent=e.text,t}))}static updateLanguage(t,n){const a=t.querySelector(`.${l.classNames.block.code.container}`);if(!a)return;const o=t.querySelector(`.${l.classNames.block.code.editor}`);if(!o)return;a.setAttribute("data-language",n);const i=a.querySelector(`.${l.classNames.block.code.header}`),r=a.getAttribute("data-theme")||e.defaultTheme,s=Be(r),c=Ce(n);i&&(i.textContent=e.getHeaderText(c,s));const d=e.inputMap.get(a);d&&e.mountEditor(a,o,{code:d.value,language:n,theme:r}),Qr.saveBlockData(a)}static updateTheme(t,n){const a=t.querySelector(`.${l.classNames.block.code.container}`);if(!a)return;const o=t.querySelector(`.${l.classNames.block.code.editor}`);if(!o)return;a.setAttribute("data-theme",n);const i=a.querySelector(`.${l.classNames.block.code.header}`),r=a.getAttribute("data-language")||e.defaultLanguage,s=Ce(r),c=Be(n);i&&(i.textContent=e.getHeaderText(s,c));const d=e.inputMap.get(a);d&&e.mountEditor(a,o,{code:d.value,language:r,theme:n}),Qr.saveBlockData(a)}static handleKeydown(e,t,n){const a=e.closest(`.${l.classNames.block.container}`);if(!a)return;const o=Qr.getEditorId(a);if(!o)return;const i=Qr.getBlockIndex(o,a.getAttribute("data-id")),r=n.metaKey||n.ctrlKey;return"Enter"!==n.key||n.shiftKey?"Backspace"===n.key&&r||"Delete"===n.key&&r?(n.preventDefault(),void Qr.removeBlock(o,i)):"Backspace"!==n.key||""!==t.value.trim()?"ArrowUp"===n.key?(n.preventDefault(),void(n.shiftKey?Qr.moveBlock(o,i,i-1):Qr.focusBlock(a.previousElementSibling))):void("ArrowDown"===n.key&&(n.preventDefault(),n.shiftKey?Qr.moveBlock(o,i,i+1):Qr.focusBlock(a.nextElementSibling))):void Qr.removeBlock(o,i):(n.preventDefault(),void Qr.insertBlock({data:{html:""},type:"paragraph"},o,i+1))}static getHeaderText(e,t){return`${e} | ${t}`}static isEmpty(t){const n=t.querySelector(`.${l.classNames.block.code.container}`);if(!n)return!0;const a=e.inputMap.get(n);return!a||Boolean(a.value?.trim())}static isEmptyData(e){return D(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(`.${l.classNames.block.code.container}`).forEach(t=>{e.inputMap.delete(t),e.dataMap.delete(t)})}},_e=".clepit-output-code-container",qe=(e,n)=>[`${e} { background: ${n.background}; color: ${n.text}; }`,...t.map(t=>`${e} .clepit-code-${t} { color: ${n[t]};${(e=>"comment"===e?" font-style: italic;":"")(t)} }`)].join("\n"),De=()=>[qe(_e,e()),...Object.entries(a).map(([e,t])=>qe(`${_e}[data-theme='${e}']`,t))].join("\n"),je="clepit:code-variant-sync",ze=e=>`clepit.code-variant.${e}`,Oe=(e,t)=>e.label?e.label:e.language?we[e.language]??e.language:`Tab ${t+1}`,He=(e,t)=>{if(!t)return 0;const n=e.findIndex((e,n)=>Oe(e,n)===t);return-1===n?0:n},Pe=e=>{if(!e||"undefined"==typeof localStorage)return null;try{return localStorage.getItem(ze(e))}catch{return null}},Re="http://www.w3.org/2000/svg",Fe=e=>e.variants?.length?e.variants:[{code:e.code,language:e.language}],Ue=class e{static{this.eventListenersMap=/* @__PURE__ */new WeakMap}static draw(t,n=me,a){if(!e.validate(t)||Me.isEmptyData(t))return null;const i=Fe(t),r=i.length>1,s=Math.min(Math.max(a?.activeVariant??0,0),i.length-1),l=n.create("div");l.addClass("clepit-output-code-container"),l.setAttribute("data-theme",t.theme??Me.defaultTheme),t.syncKey&&l.setAttribute("data-sync-key",t.syncKey);const c=n.create("div");if(c.addClass("clepit-output-code-header"),r){const e=n.create("div");e.addClass("clepit-output-code-tabs"),e.setAttribute("role","tablist"),e.setAttribute("data-testid","code-variant-tabs"),i.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===s?"true":"false"),o.setAttribute("tabindex",a===s?"0":"-1"),o.setAttribute("data-testid",`code-variant-tab-${a}`),o.setText(Oe(t,a)),e.append(o)}),c.append(e)}else{const e=n.create("span");e.setText(we[t.language??"typescript"]??"TypeScript"),c.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(Re,"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(Re,"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)),c.append(e)}l.append(c);const d=n.create("div");return d.addClass("clepit-output-code-editor"),r&&d.setAttribute("role","tabpanel"),i.forEach((e,a)=>{const i=n.create("pre");i.addClass("clepit-output-code-pane"),i.setAttribute("data-variant-index",String(a)),a!==s&&i.setAttribute("hidden","");const r=n.create("code");for(const s of o(e.code??t.code,e.language??t.language??"plaintext")){const e=n.create("span");s.classes&&e.addClass(...s.classes.split(" ")),e.setText(s.text),r.append(e)}i.append(r),d.append(i)}),l.append(d),l}static render(t,n,a,o,i){if(l.injectStyles(Ae,Ne),l.injectStyles(`${Ae}-theme`,De()),!e.validate(t))return ke();if(Me.isEmptyData(t))return document.createElement("div");const r=Fe(t),s=r.length>1?He(r,Pe(t.syncKey)):0,c=xe(e.draw(t,me,{activeVariant:s}));o?.container&&c.classList.add(o.container),a?.container&&Object.assign(c.style,a.container);const d=c.querySelector(".clepit-output-code-header");return d&&o?.header?.text&&d.classList.add(o.header.text),d&&a?.header?.text&&Object.assign(d.style,a.header.text),e.attach(c,t,s,i),c}static activate(t,n){if(!e.validate(n)||Me.isEmptyData(n))return()=>{};const a=Fe(n),o=a.length>1?He(a,Pe(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?He(o,Pe(i)):0;return e.attach(t,r,s,void 0,!0)}static attach(t,n,a,o,i=!1){const r=Fe(n),s=o?document.getElementById(o):null,l=[...t.querySelectorAll(".clepit-output-code-tab")],c=[...t.querySelectorAll(".clepit-output-code-pane")];let d=a;const p=[];let u;const h=(t,n,a)=>{if(t.addEventListener(n,a),p.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,l.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=Oe(r[e],e);((e,t)=>{if(e&&"undefined"!=typeof localStorage)try{localStorage.setItem(ze(e),t)}catch{return}})(n.syncKey,a),window.dispatchEvent(new CustomEvent(je,{detail:{label:a,syncKey:n.syncKey}}))};if(l.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),l[o]?.focus())})}),l.length>1&&n.syncKey){const t=e=>{const t=e.detail;if(!t||t.syncKey!==n.syncKey)return;const a=r.findIndex((e,n)=>Oe(e,n)===t.label);-1!==a&&a!==d&&g(a,!1)};if(window.addEventListener(je,t),p.push({event:je,handler:t,target:window}),s){const n=e.eventListenersMap.get(s)??[];n.push({element:window,event:je,handler:t}),e.eventListenersMap.set(s,n)}}const b=()=>{for(const{event:e,handler:t,target:n}of p)n.removeEventListener(e,t);u?.()};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?m.getState().getInstance(o):null;return u=ee(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))}},Ve="\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.clepit-embed-card--with-reason {\n display: flex;\n flex-direction: column;\n gap: 6px;\n padding: 12px;\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n}\n.clepit-embed-card--with-reason > .clepit-embed-card {\n padding: 0;\n border: 0;\n}\n.clepit-embed-card__reason {\n display: flex;\n flex-wrap: wrap;\n gap: 6px 14px;\n align-items: center;\n font-size: 0.9em;\n opacity: 0.85;\n}\n.clepit-embed-card__action {\n padding: 0;\n font: inherit;\n color: inherit;\n text-decoration: underline;\n background: none;\n border: 0;\n cursor: pointer;\n}\n.clepit-embed--gist-frame .clepit-embed__frame {\n height: 552px;\n}\n.clepit-embed-gist {\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n.clepit-embed-gist__file {\n display: flex;\n gap: 10px;\n align-items: baseline;\n font-size: 0.9em;\n}\n.clepit-embed-gist__file b {\n font-weight: 600;\n}\n.clepit-embed-gist__file a {\n margin-left: auto;\n color: inherit;\n opacity: 0.7;\n}\n.clepit-embed-offer {\n position: absolute;\n z-index: 20;\n display: inline-flex;\n gap: 6px;\n align-items: center;\n padding: 4px 4px 4px 10px;\n font-size: 12px;\n background: var(--clepit-surface, #fff);\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 999px;\n box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);\n}\n.clepit-embed-offer button {\n padding: 3px 9px;\n font: inherit;\n font-weight: 600;\n color: #fff;\n background: var(--clepit-primary, #5b5bff);\n border: 0;\n border-radius: 999px;\n cursor: pointer;\n}\n",We=Ve,Ke=Ve,Ge="inline-issue",Je='\n.clepit-issue {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n max-width: 100%;\n padding: 1px 8px 1px 6px;\n vertical-align: baseline;\n font-size: 0.92em;\n line-height: 1.5;\n color: inherit;\n text-decoration: none;\n white-space: nowrap;\n background: rgba(127, 127, 127, 0.1);\n border: 1px solid rgba(127, 127, 127, 0.25);\n border-radius: 999px;\n cursor: pointer;\n}\n.clepit-issue:hover {\n background: rgba(127, 127, 127, 0.16);\n}\n.clepit-issue__key {\n font-weight: 600;\n font-variant-numeric: tabular-nums;\n}\n.clepit-issue__title {\n overflow: hidden;\n text-overflow: ellipsis;\n max-width: 28ch;\n}\n.clepit-issue__state {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n padding: 0 7px;\n font-size: 12px;\n line-height: 18px;\n border-radius: 999px;\n background: rgba(127, 127, 127, 0.16);\n}\n.clepit-issue__state::before {\n content: \'\';\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: currentColor;\n}\n.clepit-issue__state[data-issue-category="todo"] {\n color: var(--clepit-text-muted, #6b7280);\n}\n.clepit-issue__state[data-issue-category="started"] {\n color: var(--clepit-primary, #5b5bff);\n background: var(--clepit-primary-bg, rgba(91, 91, 255, 0.16));\n}\n.clepit-issue__state[data-issue-category="done"] {\n color: var(--clepit-success, #15803d);\n background: var(--clepit-success-bg, rgba(21, 128, 61, 0.16));\n}\n.clepit-issue__state[data-issue-category="cancelled"] {\n color: var(--clepit-text-muted, #6b7280);\n text-decoration: line-through;\n}\n.clepit-issue__assignee {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 18px;\n height: 18px;\n font-size: 10px;\n font-weight: 600;\n letter-spacing: 0.02em;\n color: #fff;\n background: var(--clepit-primary, #5b5bff);\n border-radius: 50%;\n}\n.clepit-issue__reason {\n color: var(--clepit-text-muted, #6b7280);\n}\n.clepit-issue--reason {\n border-style: dashed;\n}\n[data-issue-chip-status="off"] .clepit-issue__state,\n[data-issue-chip-assignee="off"] .clepit-issue__assignee {\n display: none;\n}\n.clepit-issue-menu {\n position: absolute;\n z-index: 20;\n display: flex;\n flex-direction: column;\n gap: 2px;\n min-width: 180px;\n padding: 4px;\n font-size: 13px;\n background: var(--clepit-surface, #fff);\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);\n}\n.clepit-issue-menu a,\n.clepit-issue-menu button {\n display: block;\n width: 100%;\n padding: 6px 10px;\n font: inherit;\n color: inherit;\n text-align: left;\n text-decoration: none;\n background: none;\n border: 0;\n border-radius: 6px;\n cursor: pointer;\n}\n.clepit-issue-menu a:hover,\n.clepit-issue-menu button:hover {\n background: rgba(127, 127, 127, 0.1);\n}\n.clepit-issue-menu__reason {\n padding: 6px 10px 2px;\n font-size: 12px;\n color: var(--clepit-text-muted, #6b7280);\n}\n.clepit-issue-card {\n display: flex;\n flex-direction: column;\n gap: 6px;\n padding: 12px;\n color: inherit;\n text-decoration: none;\n border: 1px solid rgba(127, 127, 127, 0.35);\n border-radius: 8px;\n}\n.clepit-issue-card:hover {\n background: rgba(127, 127, 127, 0.08);\n}\n.clepit-issue-card__head {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: 8px;\n}\n.clepit-issue-card__key {\n font-weight: 600;\n font-variant-numeric: tabular-nums;\n}\n.clepit-issue-card__title {\n font-weight: 600;\n}\n.clepit-issue-card__meta {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: 6px 12px;\n font-size: 0.9em;\n opacity: 0.85;\n}\n.clepit-issue-card__assignee {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n}\n.clepit-issue-card__reason {\n display: flex;\n flex-wrap: wrap;\n gap: 6px 14px;\n align-items: center;\n font-size: 0.9em;\n opacity: 0.85;\n}\n.clepit-issue-card__action {\n padding: 0;\n font: inherit;\n color: inherit;\n text-decoration: underline;\n background: none;\n border: 0;\n cursor: pointer;\n}\n.clepit-issues {\n width: 100%;\n border-collapse: collapse;\n font-size: 0.95em;\n}\n.clepit-issues th,\n.clepit-issues td {\n padding: 6px 10px;\n text-align: left;\n border-bottom: 1px solid rgba(127, 127, 127, 0.25);\n}\n.clepit-issues th {\n font-size: 12px;\n font-weight: 600;\n letter-spacing: 0.02em;\n text-transform: uppercase;\n opacity: 0.7;\n}\n.clepit-issues a {\n color: inherit;\n font-weight: 600;\n text-decoration: none;\n}\n.clepit-issues a:hover {\n text-decoration: underline;\n}\n.clepit-issues__empty {\n opacity: 0.55;\n}\n',Xe={categoryCancelled:"Cancelled",categoryDone:"Done",categoryStarted:"In progress",categoryTodo:"To do",columnAssignee:"Assignee",columnIssue:"Issue",columnStatus:"Status",columnTitle:"Title",connectAction:"Connect",connectTool:"Connect {tool} to see this issue",linkedIssuesEmpty:"No issues linked on this page yet",noAccess:"You do not have access to this issue in {tool}",openInTool:"Open in {tool}",providerUnreachable:"{tool} did not answer",showAsCard:"Show as card",unassigned:"Unassigned",updatedRelative:"updated {when}"},Ze={asana:"Asana",github_issues:"GitHub",jira:"Jira",linear:"Linear"},Ye={cancelled:"categoryCancelled",done:"categoryDone",started:"categoryStarted",todo:"categoryTodo"};function Qe(e,t,n={}){let a=e?.[t]??Xe[t];for(const[o,i]of Object.entries(n))a=a.replace(`{${o}}`,i);return a}var et=e=>Ze[e]??e,tt="clepit-issue",nt=["todo","started","done","cancelled"],at=["connect_tool","no_access","provider_unreachable"],ot={connect_tool:"connectTool",no_access:"noAccess",provider_unreachable:"providerUnreachable"},it=e=>e.trim().split(/\s+/).slice(0,2).map(e=>e.charAt(0).toUpperCase()).join(""),rt=(e,t)=>e.reason?Qe(t,ot[e.reason],{tool:et(e.tool)}):null,st=(e,t)=>e.stateName||Qe(t,Ye[e.category]),lt=(e,t,n="")=>({category:"todo",key:n,stateName:"",title:"",tool:t,updatedAt:"",url:e}),ct=class e{static build(t,n,a=me){const o=a.create("a");o.addClass(tt),t.reason&&o.addClass(`${tt}--reason`),o.setAttribute("href",t.url),o.setAttribute("target","_blank"),o.setAttribute("rel","noopener noreferrer"),o.setAttribute("contenteditable","false");for(const[s,l]of Object.entries(e.attributes(t)))o.setAttribute(s,l);const i=a.create("span");i.addClass(`${tt}__key`),i.setText(t.key||(t.title?"":et(t.tool))),!t.key&&t.title||o.append(i);const r=rt(t,n);if(r){const e=a.create("span");return e.addClass(`${tt}__reason`),e.setText(r),o.append(e),o}if(t.title){const e=a.create("span");e.addClass(`${tt}__title`),e.setText(t.title),o.append(e)}if(t.stateName||t.updatedAt){const e=a.create("span");e.addClass(`${tt}__state`),e.setAttribute("data-issue-category",t.category),e.setText(st(t,n)),o.append(e)}if(t.assigneeName){const e=a.create("span");e.addClass(`${tt}__assignee`),e.setAttribute("title",t.assigneeName),e.setText(it(t.assigneeName)),o.append(e)}return o}static markup(t,n,a){return ve(e.build(t,n,ye(a)))}static create(t,n){return l.injectStyles(Ge,Je),xe(e.build(t,n))}static refresh(t,n,a){const o=e.create(n,a);for(const e of Array.from(t.attributes))e.name.startsWith("data-issue-")&&t.removeAttribute(e.name);for(const e of Array.from(o.attributes))t.setAttribute(e.name,e.value);t.replaceChildren(...Array.from(o.childNodes))}static read(e){const t=t=>e.getAttribute(`data-issue-${t}`)??"",n=t("category"),a=t("reason");return{assigneeAvatarUrl:t("avatar")||void 0,assigneeName:t("assignee")||void 0,category:nt.includes(n)?n:"todo",key:t("key"),pull:"true"===t("pull")||void 0,reason:at.includes(a)?a:void 0,stateName:t("state"),title:t("title"),tool:t("tool"),updatedAt:t("updated"),url:t("url")||e.getAttribute("href")||""}}static collect(e){return Array.from(e.querySelectorAll(`a.${tt}`))}static refreshAll(t,n,a){for(const o of e.collect(t)){const t=o.getAttribute("data-issue-url")||o.getAttribute("href")||"",i=n[t];i&&e.refresh(o,{...i,url:t},a)}}static applyParts(e,t){e.setAttribute("data-issue-chip-status",!1===t?.status?"off":"on"),e.setAttribute("data-issue-chip-assignee",!1===t?.assignee?"off":"on")}static insertAtCaret(t,n){const a=window.getSelection();if(!a||0===a.rangeCount)return null;const o=a.getRangeAt(0);o.deleteContents();const i=e.create(t,n);o.insertNode(i);const r=document.createTextNode(" ");i.after(r);const s=document.createRange();return s.setStartAfter(r),s.collapse(!0),a.removeAllRanges(),a.addRange(s),i}static attributes(e){const t={"data-issue-category":e.category,"data-issue-key":e.key,"data-issue-state":e.stateName,"data-issue-title":e.title,"data-issue-tool":e.tool,"data-issue-updated":e.updatedAt,"data-issue-url":e.url};return e.assigneeName&&(t["data-issue-assignee"]=e.assigneeName),e.assigneeAvatarUrl&&(t["data-issue-avatar"]=e.assigneeAvatarUrl),e.pull&&(t["data-issue-pull"]="true"),e.reason&&(t["data-issue-reason"]=e.reason),t}},dt=/<a\b[^>]*\bclepit-issue(?=["'\s])[^>]*>[\s\S]*?<\/a>/g,pt=(e,t)=>(new RegExp(`\\b${t}="([^"]*)"`).exec(e)?.[1]??"").replace(/&quot;/g,'"').replace(/&amp;/g,"&"),ut=e=>{const t=t=>pt(e,`data-issue-${t}`),n=t("category"),a=t("reason");return{assigneeAvatarUrl:t("avatar")||void 0,assigneeName:t("assignee")||void 0,category:nt.includes(n)?n:"todo",key:t("key"),pull:"true"===t("pull")||void 0,reason:at.includes(a)?a:void 0,stateName:t("state"),title:t("title"),tool:t("tool"),updatedAt:t("updated"),url:t("url")||pt(e,"href")}},mt=e=>Array.from(e.matchAll(dt),e=>ut(e[0])),ht=(e,t,n,a,o)=>t||n?e.replace(dt,e=>{const i=ut(e),r={...t?.[i.url]?{...t[i.url],url:i.url}:i};return!1===n?.status&&(r.stateName="",r.updatedAt=""),!1===n?.assignee&&(r.assigneeName=void 0),ct.markup(r,a,o)}):e,gt=class e{static render(t,n){return l.injectStyles(Ge,Je),xe(e.draw(t,me,n,!0))}static draw(t,n,a,o){const i=rt(t,a);if(i)return e.drawReason(t,i,n,a,o);const r=n.create("a");r.addClass("clepit-issue-card","clepit-output-embed"),r.setAttribute("data-testid","issue-card"),r.setAttribute("href",t.url),r.setAttribute("rel","noopener noreferrer nofollow"),r.setAttribute("target","_blank");const s=n.create("span");if(s.addClass("clepit-issue-card__head"),t.key){const e=n.create("span");e.addClass("clepit-issue-card__key"),e.setText(t.key),s.append(e)}const l=n.create("span");l.addClass("clepit-issue-card__title"),l.setText(t.title||t.url),s.append(l);const c=n.create("span");c.addClass("clepit-issue__state"),c.setAttribute("data-issue-category",t.category),c.setText(st(t,a)),s.append(c),r.append(s);const d=n.create("span");d.addClass("clepit-issue-card__meta");const p=n.create("span");if(p.addClass("clepit-issue-card__assignee"),t.assigneeName){const e=n.create("span");e.addClass("clepit-issue__assignee"),e.setAttribute("title",t.assigneeName),e.setText(it(t.assigneeName)),p.append(e),p.appendText(t.assigneeName)}else p.setText(Qe(a,"unassigned"));if(d.append(p),t.updatedAt){const e=n.create("span");e.addClass("clepit-issue-card__updated"),e.setText(Qe(a,"updatedRelative",{when:(u=t.updatedAt,u.length>=10?u.slice(0,10):u)})),d.append(e)}var u;return r.append(d),r}static drawReason(e,t,n,a,o){const i=n.create("div");i.addClass("clepit-issue-card","clepit-issue-card--reason","clepit-output-embed"),i.setAttribute("data-testid","issue-card");const r=n.create("a");r.addClass("clepit-issue-card__head"),r.setAttribute("href",e.url),r.setAttribute("rel","noopener noreferrer nofollow"),r.setAttribute("target","_blank");const s=n.create("span");if(s.addClass("clepit-issue-card__key"),s.setText(e.key||et(e.tool)),r.append(s),e.title){const t=n.create("span");t.addClass("clepit-issue-card__title"),t.setText(e.title),r.append(t)}i.append(r);const l=n.create("span");l.addClass("clepit-issue-card__reason"),l.setAttribute("data-testid","issue-reason");const c=n.create("span");if(c.setText(t),l.append(c),o&&"connect_tool"===e.reason){const t=n.create("button");t.addClass("clepit-issue-card__action"),t.setAttribute("type","button"),t.setAttribute("data-issue-action","connect"),t.setAttribute("data-issue-tool",e.tool),t.setAttribute("data-testid","issue-reason-action-connect"),t.setText(Qe(a,"connectAction")),l.append(t)}return i.append(l),i}},bt=["http:","https:"],ft=["youtube.com","www.youtube.com","m.youtube.com","youtu.be"],yt=["file","design","board","proto","slides","deck"],vt=["document","spreadsheets","presentation"],xt=/^[0-9a-f]{32}$/,kt=/^[A-Za-z0-9]+$/,wt={figma:"figma",githubGist:"github_gist",googleDrive:"google_drive",loom:"loom",miro:"miro"};function Ct(e,t){const n=wt[e];return void 0!==n&&(t??[]).includes(n)}var St=(e,t="link")=>({embedUrl:null,provider:t,url:e});function Et(e,t){return e===t||e.endsWith(`.${t}`)}function At(e,t){const n=e.hostname.toLowerCase(),a=e.toString();if(ft.includes(n)){const t=function(e){if(Et(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}(e);return t?{aspect:16/9,embedUrl:`https://www.youtube.com/embed/${encodeURIComponent(t)}`,provider:"youtube",url:a}:St(a,"youtube")}if(Et(n,"figma.com")){const[,t,n]=e.pathname.split("/");return t&&n&&yt.includes(t)?{aspect:4/3,embedUrl:`https://embed.figma.com/${"file"===t?"design":t}/${encodeURIComponent(n)}?embed-host=clepit`,provider:"figma",url:a}:St(a,"figma")}if(Et(n,"miro.com")){const t=e.pathname.match(/^\/app\/board\/([^/]+)/);return t?{aspect:16/9,embedUrl:`https://miro.com/app/live-embed/${encodeURIComponent(t[1])}`,provider:"miro",url:a}:St(a,"miro")}if(Et(n,"loom.com")){const[,t,n]=e.pathname.split("/");return("share"===t||"embed"===t)&&n&&kt.test(n)?{aspect:16/9,embedUrl:`https://www.loom.com/embed/${encodeURIComponent(n)}?hide_share=true`,provider:"loom",url:a}:St(a,"loom")}if("drive.google.com"===n){const t=e.pathname.match(/^\/file\/d\/([^/]+)/),n="/open"===e.pathname?e.searchParams.get("id"):null,o=t?.[1]??n;return o?{aspect:4/3,embedUrl:`https://drive.google.com/file/d/${encodeURIComponent(o)}/preview`,provider:"googleDrive",url:a}:St(a,"googleDrive")}if("docs.google.com"===n){const[,t,n,o]=e.pathname.split("/");return t&&vt.includes(t)&&"d"===n&&o?{aspect:4/3,embedUrl:`https://docs.google.com/${t}/d/${encodeURIComponent(o)}/preview`,provider:"googleDrive",url:a}:St(a,"googleDrive")}if("gist.github.com"===n){const[,t,n]=e.pathname.split("/");return t&&n&&xt.test(n)?{embedUrl:null,gist:{id:n,owner:t},provider:"githubGist",url:a}:St(a,"githubGist")}if(Et(n,"airtable.com")){const t=e.pathname.match(/^\/embed\/([^/]+)/),n=e.pathname.match(/^\/(shr[^/]+)/),o=t?.[1]??n?.[1];return o?{aspect:4/3,embedUrl:`https://airtable.com/embed/${encodeURIComponent(o)}`,provider:"airtable",url:a}:St(a,"airtable")}if(Et(n,"diagrams.net")||Et(n,"drawio.com"))return{aspect:4/3,embedUrl:`https://viewer.diagrams.net/?edit=_blank&layers=1&nav=1#U${encodeURIComponent(a)}`,provider:"drawio",url:a};if(Et(n,"google.com")&&e.pathname.startsWith("/maps")){const n=t?.mapsEmbedKey,o=e.searchParams.get("q");return n&&o?{aspect:4/3,embedUrl:`https://www.google.com/maps/embed/v1/place?key=${encodeURIComponent(n)}&q=${encodeURIComponent(o)}`,provider:"googleMaps",url:a}:St(a,"googleMaps")}return St(a)}function Nt(e,t){const n=function(e){try{const t=new URL(e);return bt.includes(t.protocol)?t:null}catch{return null}}(e);if(!n)return{embedUrl:null,provider:"invalid",url:e};const a=At(n,t);return Ct(a.provider,t?.disabledProviders)?{embedUrl:null,provider:a.provider,switchedOff:!0,url:a.url}:a}var Lt="allow-scripts allow-same-origin allow-presentation allow-forms",Bt={connectGoogle:"Connect your Google account to show this file",connectGoogleAction:"Connect",noAccess:"You do not have access to this file in Google Drive",offerShowLive:"{tool} · Show live",providerUnreachable:"{tool} did not answer, so the content is not shown",switchedOff:"Live view for {tool} is switched off for this workspace",truncated:"truncated",tryAgain:"Try again",viewOnGithub:"View on GitHub"},$t={figma:"Figma",githubGist:"GitHub",googleDrive:"Google Drive",loom:"Loom",miro:"Miro"};function It(e,t,n={}){let a=e?.[t]??Bt[t];for(const[o,i]of Object.entries(n))a=a.replace(`{${o}}`,i);return a}var Tt=new Set(Object.keys(we)),Mt={"c#":"csharp","c++":"cpp","html+erb":"html","objective-c":"objectivec",shell:"bash"};function _t(e){if(!e)return;const t=e.toLowerCase(),n=Mt[t];return n||(Tt.has(t)?t:void 0)}var qt={connect_google:"connectGoogle",no_access:"noAccess",provider_unreachable:"providerUnreachable",switched_off:"switchedOff"},Dt={connectGoogle:"connectGoogleAction",retry:"tryAgain"};function jt(e,t){const n=$t[t.provider]??"The tool";if(t.switchedOff)return{reason:"switched_off",tool:n};switch(e.reason){case"connect_google":return{action:"connectGoogle",reason:"connect_google",tool:n};case"no_access":return{reason:"no_access",tool:n};case"provider_unreachable":return{action:"retry",reason:"provider_unreachable",tool:n};case"switched_off":return{reason:"switched_off",tool:n};default:return null}}var zt=(e,t)=>"card"===e.display||!0===t.switchedOff||void 0!==e.reason,Ot=class e{static render(t,n,a,o){if(l.injectStyles("embed-output",Ke),!e.validate(t))return ke();if(t.issue)return gt.render({...t.issue,...n?.issues?.[t.url],url:t.url},n?.issueLabels);const i=Nt(t.url,{disabledProviders:n?.disabledEmbedProviders,mapsEmbedKey:n?.mapsEmbedKey});if("invalid"===i.provider)return ke();if(!zt(t,i)){if(i.gist)return e.gistFrame(i.gist,a,o);if(i.embedUrl)return e.frame(i.embedUrl,i.aspect,a,o)}const r=e.card(t,i.url,a,o),s=jt(t,i);if(!s)return r;const c=l.createStyledElement("div","clepit-embed-card--with-reason clepit-output-embed",{classNames:o?.wrapper,styles:a?.wrapper});r.classList.remove("clepit-output-embed"),c.appendChild(r);const d=document.createElement("span");d.className="clepit-embed-card__reason",d.setAttribute("data-testid","embed-reason");const p=document.createElement("span");if(p.textContent=It(n?.embedLabels,qt[s.reason],{tool:s.tool}),d.appendChild(p),s.action){const e=document.createElement("button");e.type="button",e.className="clepit-embed-card__action",e.setAttribute("data-embed-action",s.action),e.setAttribute("data-testid",`embed-reason-action-${s.action}`),e.textContent=It(n?.embedLabels,Dt[s.action]),d.appendChild(e)}return c.appendChild(d),c}static draw(t,n=me,a){if(!e.validate(t))return null;if(t.issue)return gt.draw({...t.issue,...a?.issues?.[t.url],url:t.url},n,a?.issueLabels,!1);const o=Nt(t.url,{disabledProviders:a?.disabledEmbedProviders,mapsEmbedKey:a?.mapsEmbedKey});if("invalid"===o.provider)return null;if(!zt(t,o)){if(o.gist&&t.gist&&t.gist.files.length>0)return e.drawGist(t,n,a);if(o.embedUrl)return e.drawFrame(o.embedUrl,o.aspect,n)}const i=jt(t,o);if(!i)return e.drawCard(t,o.url,n,!0);const r=n.create("div");r.addClass("clepit-embed-card--with-reason","clepit-output-embed"),r.append(e.drawCard(t,o.url,n,!1));const s=n.create("span");s.addClass("clepit-embed-card__reason"),s.setAttribute("data-testid","embed-reason");const l=n.create("span");return l.setText(It(a?.embedLabels,qt[i.reason],{tool:i.tool})),s.append(l),r.append(s),r}static drawGist(e,t,n){const a=e.gist,o=t.create("div");o.addClass("clepit-embed-gist","clepit-output-embed");for(const i of a.files){const e=t.create("div");e.addClass("clepit-embed-gist__file");const r=t.create("b");if(r.setText(i.name),e.append(r),i.truncated){const a=t.create("span");a.setText(It(n?.embedLabels,"truncated")),e.append(a)}const s=t.create("a");s.setAttribute("href",a.htmlUrl),s.setAttribute("rel","noopener noreferrer nofollow"),s.setAttribute("target","_blank"),s.setText(It(n?.embedLabels,"viewOnGithub")),e.append(s),o.append(e);const l=Ue.draw({code:i.content,language:_t(i.language),showCopy:!1},t,n);l&&o.append(l)}return o}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",Lt),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,a){const o=n.create("a");o.addClass("clepit-embed-card"),a&&o.addClass("clepit-output-embed"),o.setAttribute("href",t),o.setAttribute("rel","noopener noreferrer nofollow"),o.setAttribute("target","_blank");const i=n.create("span"),r=n.create("span");if(r.addClass("clepit-embed-card__title"),r.setText(e.title||t),i.append(r),e.description){const t=n.create("span");t.addClass("clepit-embed-card__description"),t.setText(e.description),i.append(t)}return o.append(i),o}static gistFrame(e,t,n){const a=l.createStyledElement("div","clepit-embed clepit-embed--gist-frame clepit-output-embed",{classNames:n?.wrapper,styles:t?.wrapper}),o=document.createElement("iframe");var i,r;return o.className="clepit-embed__frame",o.setAttribute("srcdoc",(i=e.owner,r=e.id,`<!doctype html><html><head><meta charset="utf-8"><base target="_blank"><style>body{margin:0;padding:8px;font:13px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif}.gist .gist-file{margin-bottom:0}</style></head><body><script src="https://gist.github.com/${encodeURIComponent(i)}/${encodeURIComponent(r)}.js"><\/script></body></html>`)),o.setAttribute("sandbox","allow-scripts allow-popups allow-popups-to-escape-sandbox"),o.setAttribute("referrerpolicy","no-referrer"),o.setAttribute("loading","lazy"),o.style.height="552px",a.appendChild(o),a}static frame(e,t,n,a){const o=l.createStyledElement("div","clepit-embed clepit-output-embed",{classNames:a?.wrapper,styles:n?.wrapper}),i=document.createElement("iframe");return i.className="clepit-embed__frame",i.src=e,i.setAttribute("sandbox",Lt),i.setAttribute("referrerpolicy","no-referrer"),i.setAttribute("loading","lazy"),i.setAttribute("allowfullscreen","true"),i.style.aspectRatio=String(t??16/9),o.appendChild(i),o}static card(e,t,n,a){const o=l.createStyledElement("a","clepit-embed-card clepit-output-embed",{classNames:a?.card,styles:n?.card});o.href=t,o.rel="noopener noreferrer nofollow",o.target="_blank";const i=document.createElement("span"),r=document.createElement("span");if(r.className="clepit-embed-card__title",r.textContent=e.title||t,i.appendChild(r),e.description){const t=document.createElement("span");t.className="clepit-embed-card__description",t.textContent=e.description,i.appendChild(t)}return o.appendChild(i),o}static validate(e){return void 0!==e&&"object"==typeof e&&null!==e&&"string"==typeof e.url&&e.url.length>0}};async function Ht(e,t,n,a){const o=m.getState().getInstance(e)?.config,i=function(e,t){return{data:"card"===t?{display:"card",url:e}:{url:e},type:"embed"}}(a,"card"===(o?.pasteEmbeds??"live")?"card":"live");n?Qr.replaceBlock(e,t,i):Qr.insertBlock(i,e,t+1);const r=Qr.getBlocks(e)[n?t:t+1]?.getAttribute("data-id")??null;return r&&o?.resolveLink&&await Pt(e,r,o.resolveLink),r}async function Pt(e,t,n){if(!n)return;const a=Qr.getBlockData(t).data;try{const o=await n(a.url),{reason:i,...r}=a;Qr.updateBlockData(t,{...r,...o,url:a.url},e)}catch{Qr.updateBlockData(t,{...a,reason:"provider_unreachable"},e)}}var Rt={},Ft={dismiss(e){for(const{element:t,event:n,handler:a}of Rt[e]??[])t.removeEventListener(n,a);Rt[e]=[],document.querySelector(`[data-embed-offer-for="${e}"]`)?.remove()},show(e,t,n,a){Ft.dismiss(e);const o=window.getSelection(),i=o?.rangeCount?o.getRangeAt(0):null;if(!i)return;i.deleteContents();const r=document.createTextNode(n);i.insertNode(r),i.setStartAfter(r),i.collapse(!0),o?.removeAllRanges(),o?.addRange(i);const s=document.getElementById(e);if(!s)return;const l=m.getState().getInstance(e)?.config,c=$t[a.provider]??a.provider,d=document.createElement("div");d.className="clepit-embed-offer",d.setAttribute("data-testid","embed-offer"),d.setAttribute("data-embed-offer-for",e);const p=document.createElement("span");p.textContent=It(l?.embedLabels,"offerShowLive",{tool:c}).replace(" · Show live",""),d.appendChild(p);const u=document.createElement("button");u.type="button",u.setAttribute("data-testid","embed-offer-accept"),u.textContent=It(l?.embedLabels,"offerShowLive",{tool:c}).split(" · ").pop()??"Show live",d.appendChild(u);const h=i.getBoundingClientRect(),g=s.getBoundingClientRect();d.style.left=`${Math.max(0,h.left-g.left)}px`,d.style.top=h.bottom-g.top+6+"px",s.appendChild(d);const b=()=>{const a=t.getAttribute("data-id"),o=Qr.getBlockIndex(e,a);Ft.dismiss(e),-1!==o&&Ht(e,o,!0,n)},f=t=>{const n=t.key;if("Enter"===n)return t.preventDefault(),void b();"Shift"!==n&&"Meta"!==n&&"Control"!==n&&"Alt"!==n&&Ft.dismiss(e)},y=t=>{d.contains(t.target)||Ft.dismiss(e)};u.addEventListener("click",b),document.addEventListener("keydown",f),document.addEventListener("mousedown",y),Rt[e]=[{element:u,event:"click",handler:b},{element:document,event:"keydown",handler:f},{element:document,event:"mousedown",handler:y}]}},Ut={},Vt={dismiss(e){for(const{element:t,event:n,handler:a}of Ut[e]??[])t.removeEventListener(n,a);Ut[e]=[],document.querySelector(`[data-issue-menu-for="${e}"]`)?.remove()},show(e,t){Vt.dismiss(e),l.injectStyles(Ge,Je);const n=document.getElementById(e);if(!n)return;const a=m.getState().getInstance(e)?.config,o=ct.read(t),i=et(o.tool),r=document.createElement("div");r.className="clepit-issue-menu",r.setAttribute("data-testid","issue-menu"),r.setAttribute("data-issue-menu-for",e);const s=rt(o,a?.issueLabels);if(s){const t=document.createElement("div");if(t.className="clepit-issue-menu__reason",t.setAttribute("data-testid","issue-reason"),t.textContent=s,r.appendChild(t),"connect_tool"===o.reason){const t=document.createElement("button");t.type="button",t.setAttribute("data-testid","issue-connect"),t.textContent=Qe(a?.issueLabels,"connectAction"),t.addEventListener("click",()=>{Vt.dismiss(e),a?.onIssueAction?.("connect",o.tool)}),r.appendChild(t)}}const c=document.createElement("a");c.href=o.url,c.target="_blank",c.rel="noopener noreferrer",c.setAttribute("data-testid","issue-open"),c.textContent=Qe(a?.issueLabels,"openInTool",{tool:i}),c.addEventListener("click",()=>Vt.dismiss(e)),r.appendChild(c);const d=document.createElement("button");d.type="button",d.setAttribute("data-testid","issue-show-card"),d.textContent=Qe(a?.issueLabels,"showAsCard"),d.addEventListener("click",()=>{Vt.dismiss(e),Vt.showAsCard(e,t)}),r.appendChild(d);const p=t.getBoundingClientRect(),u=n.getBoundingClientRect();r.style.left=`${Math.max(0,p.left-u.left)}px`,r.style.top=p.bottom-u.top+6+"px",n.appendChild(r);const h=t=>{"Escape"===t.key&&Vt.dismiss(e)},g=n=>{r.contains(n.target)||t.contains(n.target)||Vt.dismiss(e)};document.addEventListener("keydown",h),document.addEventListener("mousedown",g),Ut[e]=[{element:document,event:"keydown",handler:h},{element:document,event:"mousedown",handler:g}]},showAsCard(e,t){const n=ct.read(t),a=t.closest(`.${l.classNames.block.container}`),o=a?.getAttribute("data-id");if(!a||!o)return;const i=Qr.getBlockIndex(e,o);if(-1===i)return;const r=t.closest('[contenteditable="true"]');t.remove();const s={data:{issue:n,url:n.url},type:"embed"};Qr.getTool(a.getAttribute("data-tool"))?.input.isEmpty(a)?Qr.replaceBlock(e,i,s):(r&&Qr.saveBlockData(r),Qr.insertBlock(s,e,i+1))}},Wt=/^[A-Z][A-Z0-9_]*-\d+$/,Kt=/^\d+$/,Gt=(e,t)=>e.endsWith(".atlassian.net")||t.some(t=>(e=>{try{return new URL(e).host.toLowerCase()}catch{return null}})(t)===e),Jt=(e,t,n)=>n?{key:t,site:n,tool:e}:{key:t,tool:e};function Xt(e,t=[]){let n;try{n=new URL(e)}catch{return null}if("https:"!==n.protocol&&"http:"!==n.protocol)return null;const a=n.host.toLowerCase(),o=n.pathname.split("/").filter(Boolean);if("linear.app"===a){const[,e,t]=o;return"issue"===e&&t&&Wt.test(t)?Jt("linear",t):null}if("github.com"===a||"www.github.com"===a){const[e,t,n,a]=o;return e&&t&&("issues"===n||"pull"===n)&&a&&Kt.test(a)?Jt("github_issues",`${e}/${t}#${a}`):null}if("app.asana.com"===a){const[e,...t]=o;return"0"===e&&t.length>=2&&Kt.test(t[0])&&Kt.test(t[1])||("1"===e&&"project"===t[1]&&"task"===t[3]&&t[4]&&Kt.test(t[4])||"1"===e&&"task"===t[1]&&t[2]&&Kt.test(t[2]))?Jt("asana",""):null}if(Gt(a,t)){const e=`https://${a}`;if("browse"===o[0]&&o[1]&&Wt.test(o[1]))return Jt("jira",o[1],e);const t=n.searchParams.get("selectedIssue");return t&&Wt.test(t)?Jt("jira",t,e):null}return null}var Zt=/* @__PURE__ */new WeakMap,Yt=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?Zt.get(t):void 0)??{url:""}}static render(t,n,a){l.injectStyles("embed-input",We);const o=n??{url:""},i=m.getState().getInstance(t)?.config,r=Ot.render(o,{disabledEmbedProviders:i?.disabledEmbedProviders,embedLabels:i?.embedLabels},a?.styles,a?.classNames);return r.classList.add("clepit-embed--input"),r.setAttribute("contenteditable","false"),Zt.set(r,o),e.listenForActions(t,r),r}static isEmpty(t){return""===e.save(t).url}static isEmptyData(e){return!e.url}static handleOperation(t,n,a){const o=n.getAttribute("data-id"),i=e.save(n);switch(t){case"embedShowLive":{const{display:e,...t}=i;return Qr.updateBlockData(o,t,a)}case"embedShowCard":return Qr.updateBlockData(o,{...i,display:"card"},a);case"embedShowLink":{const e=Qr.getBlockIndex(a,o);if(-1===e)return;const t=document.createElement("a");return t.href=i.url,t.textContent=i.url,Qr.replaceBlock(a,e,{data:{html:t.outerHTML},type:"paragraph"})}case"embedCopyLink":return void navigator.clipboard?.writeText(i.url);case"embedShowChip":{const e=Qr.getBlockIndex(a,o);if(-1===e)return;const t=m.getState().getInstance(a)?.config,n=Xt(i.url,t?.jiraSites),r=i.issue??lt(i.url,n?.tool??"",n?.key??""),s=ct.create({...r,url:i.url},t?.issueLabels);return Qr.replaceBlock(a,e,{data:{html:`${s.outerHTML} `},type:"paragraph"})}default:return}}static refreshIssue(t,n,a){const o=e.save(t);if(!o.issue)return;const i=t.querySelector(`.${l.classNames.block.content}`);if(!i)return;const r=m.getState().getInstance(n),s={classNames:r?.config.classNames?.blocks?.embed,styles:r?.config.styles?.blocks?.embed};i.replaceChildren(e.render(n,{...o,issue:{...a,url:o.url}},s))}static destroy(t){const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}static listenForActions(t,n){const a=e=>{const a=e.target?.closest("[data-issue-action]");if(a)return e.preventDefault(),e.stopPropagation(),void m.getState().getInstance(t)?.config.onIssueAction?.("connect",a.getAttribute("data-issue-tool")??"");const o=e.target?.closest("[data-embed-action]");if(!o)return;e.preventDefault(),e.stopPropagation();const i=o.getAttribute("data-embed-action"),r=n.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id");if(!r)return;const s=m.getState().getInstance(t)?.config;"retry"===i?Pt(t,r,s?.resolveLink):s?.onEmbedAction?.(i,r)};n.addEventListener("click",a),e.eventListenersMap[t]??=[],e.eventListenersMap[t].push({element:n,event:"click",handler:a})}};async function Qt(e,t){const n=m.getState().getInstance(e)?.config;if(!n?.resolveIssues||0===t.length)return{};try{const e=await n.resolveIssues([...t]),a={};for(const n of t)e[n]&&(a[n]={...e[n],url:n});return a}catch{const e={};for(const a of t){const t=Xt(a,n.jiraSites);e[a]={...lt(a,t?.tool??"",t?.key??""),reason:"provider_unreachable"}}return e}}async function en(e,t,n,a,o,i){const r=m.getState().getInstance(e)?.config,s=lt(o,i.tool,i.key);if(a&&"on"===r?.issueCards){const t={data:{issue:s,url:o},type:"embed"};Qr.replaceBlock(e,n,t);const a=Qr.getBlocks(e)[n]?.getAttribute("data-id");return void(a&&await async function(e,t,n){const a=(await Qt(e,[n]))[n];if(!a)return;const o=Qr.getBlock(t);if(!o)return;const i=Yt.save(o);Qr.updateBlockData(t,{...i,issue:{...a,url:i.url}},e)}(e,a,o))}const l=ct.insertAtCaret(s,r?.issueLabels);if(!l)return;const c=l.closest('[contenteditable="true"]');c&&Qr.saveBlockData(c),await async function(e,t,n){const a=(await Qt(e,[n]))[n];if(!a||!t.isConnected)return;const o=m.getState().getInstance(e)?.config;ct.refresh(t,a,o?.issueLabels);const i=t.closest('[contenteditable="true"]');i&&Qr.saveBlockData(i)}(e,l,o)}function tn(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 nn(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 an(e){const t=e.toLowerCase();return t.includes("youtube.com")||t.includes("youtu.be")}function on(e){return e.toLowerCase().includes("vimeo.com")}function rn(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=an(t),a=on(t);return{isImage:tn(t),isUrl:!0,isVideo:nn(t)||n||a,isVimeo:a,isYouTube:n,url:t}}var sn=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 a=n.closest(`.${l.classNames.editor.content}`);if(!a)return null;const o=a.getAttribute("data-container-id");if(!o)return null;const i=m.getState().getInstance(o);return i?{instance:i,target:n}:null}static handleClick(e){const t=e.currentTarget,n=e.target,a=n.closest(`a.${tt}`);if(a){if("edit"!==m.getState().getInstance(t.id)?.currentView)return;return e.preventDefault(),void Vt.show(t.id,a)}const o=n.closest(`.${l.classNames.block.link}`);if(o){const e=document.createRange();e.selectNodeContents(o);const n=m.getState().getInstance(t.id);return void(n&&H.apply(e,n.config.classNames?.dialogs,n.config.styles?.dialogs))}const i=n.closest(`.${l.classNames.block.tooltip}`);if(i){const e=document.createRange();e.selectNodeContents(i);const n=m.getState().getInstance(t.id);return void(n&&te.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{pe.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{pe.repaint(a.instance.config.containerId,n)}catch{}else try{pe.hide(a.instance.config.containerId)}catch{}}static handlePaste(e){const t=e.clipboardData?.getData("text/plain").trim()??"";if(!t)return;const n=rn(t);if(!n.isUrl)return;const a=document.activeElement;if(!a)return;const o=a.closest(`.${l.classNames.block.container}`);if(!o)return;const i=o.closest(`.${l.classNames.editor.container}`);if(!i)return;const r=m.getState().getInstance(i.id)?.config,s=n.isImage||n.isVideo?null:(c=t,d=r?.jiraSites,Xt(c,d));var c,d;const p=n.isImage||n.isVideo||s?null:function(e,t){const n=Nt(e,{disabledProviders:t});return"invalid"===n.provider||"link"===n.provider?null:n}(t,r?.disabledEmbedProviders);if(!(n.isImage||n.isVideo||p||s))return;const u=o.getAttribute("data-id"),h=Qr.getBlockIndex(i.id,u);if(-1===h)return;const g=Qr.getTool(o.getAttribute("data-tool"));if(!g)return;const b=g.input.isEmpty(o);if(e.preventDefault(),s)en(i.id,0,h,b,t,s);else if(p)"offer"===(r?.pasteEmbeds??"live")?Ft.show(i.id,o,t,p):Ht(i.id,h,b,t);else if(n.isImage){const e={data:{alignment:"center",alt:"Image",caption:"",url:n.url},type:"image"};b?Qr.replaceBlock(i.id,h,e):Qr.insertBlock(e,i.id,h+1)}else if(n.isVideo){let e=n.url;n.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}(n.url)||n.url:n.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}(n.url)||n.url);const t={data:{alignment:"center",alt:"Video",caption:"",url:e},type:"video"};b?Qr.replaceBlock(i.id,h,t):Qr.insertBlock(t,i.id,h+1)}}},ln="\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",cn=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(`.${l.classNames.block.alert}`)||e,n=t.getAttribute("data-variant")||"info";return{html:j(t.innerHTML),variant:n}}static render(t,n,a){l.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 o={html:"",variant:"info"},i=n?{...o,...n}:o,r=l.createStyledElement("div","clepit-alert",{classNames:a?.classNames?.[i.variant],styles:a?.styles?.[i.variant]});return r.setAttribute("data-variant",i.variant),r.setAttribute("contenteditable","true"),r.setAttribute("data-placeholder",e.placeholder),i.html?r.innerHTML=i.html:r.innerHTML="",e.addEventListener(t,r,"keydown",Qr.handleKeydown),e.addEventListener(t,r,"input",Qr.handleInput),r}static changeVariant(t,n,a){const o=m.getState().getInstance(a);if(!o)return;if(t.getAttribute("data-variant")===n)return;const i=t.innerHTML||"",r={html:i.trim()&&"<br>"!==i.trim()?i:"",variant:n},s={classNames:o.config.classNames?.blocks?.alert,margins:o.config.margins,styles:o.config.styles?.blocks?.alert},c=Qr.getBlockIndex(a,t.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id")),d=e.render(a,r,s);t.replaceWith(d),m.getState().updateBlockData(a,c,r)}static isEmpty(e){return D(e.querySelector(`.${l.classNames.block.alert}`)?.innerHTML)}static isEmptyData(e){return D(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]=[])}},dn=class e{static render(t,n,a,o){if(l.injectStyles("clepit-alert-output-styles",ln),!e.validate(t))return ke();if(cn.isEmptyData(t))return document.createElement("div");const i=t.html,r=t.variant,s=l.createStyledElement("div",`clepit-output-alert clepit-output-alert--${r}`,{classNames:o?.[r],styles:a?.[r]});return i&&(s.innerHTML=i),s}static draw(t,n=me){if(!e.validate(t)||cn.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}},pn={icon:"!",get input(){return cn},label:"Alert",get output(){return dn},shortcut:S("A"),testId:"block-type-alert",type:"alert"},un=`\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.${l.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.${l.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.${l.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.${l.classNames.block.audioDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Audio drop area delete button */\n.clepit-audio-drop-area .${l.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 .${l.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`,mn="\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",hn=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(`.${l.classNames.block.audio.captionEditable}`),a=e.querySelector(`.${l.classNames.block.audio.wrapper}`);let o="center";return a&&(o=a.classList.contains("align-left")?"left":a.classList.contains("align-right")?"right":"center"),{alignment:o,alt:t&&t.getAttribute("alt")||"",caption:j(n?.innerHTML),url:t&&t.getAttribute("src")||""}}static render(t,n,a,o){l.injectStyles("clepit-audio-input-styles",un);const i=a||{alt:"",caption:"",url:""},r=l.createStyledElement("div",l.classNames.block.audio.container,{classNames:o?.classNames?.container,styles:o?.styles?.container});return i.url?e.renderAudio(r,i,t,n,o):e.renderDropArea(r,t,n,o),r}static renderAudio(t,n,a,o,i){if(!document.getElementById(o))return;t.innerHTML="";const r=l.createStyledElement("div",l.classNames.block.audio.wrapper,{classNames:i?.classNames?.container,styles:i?.styles?.container});switch(r.setAttribute("tabindex","-1"),n?.alignment||"center"){case"left":r.classList.add("align-left");break;case"center":r.classList.add("align-center");break;case"right":r.classList.add("align-right")}const s=l.createStyledElement("audio","clepit-audio",{classNames:i?.classNames?.container,styles:i?.styles?.container});s.src=n.url,s.controls=!0,s.preload="metadata",n.alt&&s.setAttribute("alt",n.alt);const c=l.createStyledElement("div","clepit-audio-caption-container",{classNames:i?.classNames?.container,styles:i?.styles?.container});c.classList.add("clepit-audio-caption-container");const d=l.createStyledElement("div","clepit-audio-caption-editable",{classNames:i?.classNames?.caption,styles:i?.styles?.caption});d.setAttribute("contenteditable","true"),d.setAttribute("data-placeholder",e.placeholder),d.innerHTML=n.caption||"",e.addEventListener(o,d,"keydown",Qr.handleKeydown),e.addEventListener(o,d,"input",Qr.handleInput),e.addEventListener(o,r,"click",()=>e.handleFileSelect(t,a,o,i)),r.appendChild(s),c.appendChild(d),t.appendChild(r),t.appendChild(c),d.focus()}static renderDropArea(t,n,a,o){t.innerHTML="";const i=l.createStyledElement("div",l.classNames.block.audio.dropArea,{classNames:o?.classNames?.dropArea?.container,styles:o?.styles?.dropArea?.container});i.setAttribute("tabindex","0"),i.classList.add("clepit-drop-area");const r=l.createStyledElement("div","clepit-audio-drop-icon",{classNames:o?.classNames?.dropArea?.icon,styles:o?.styles?.dropArea?.icon});r.textContent="♪";const s=l.createStyledElement("div","clepit-audio-drop-text",{classNames:o?.classNames?.dropArea?.text,styles:o?.styles?.dropArea?.text});s.innerHTML='<strong>Drop an audio file here</strong><br>or <span class="clepit-audio-click-text">click to select</span>';const c=l.createStyledElement("div","clepit-audio-drop-subtext",{classNames:o?.classNames?.dropArea?.subtext,styles:o?.styles?.dropArea?.subtext});c.textContent="Supports MP3, WAV, OGG, and other audio formats";const d=l.createStyledElement("button",`${l.classNames.block.audioDeleteBtn}`,{classNames:o?.classNames?.dropArea?.deleteButton,styles:o?.styles?.dropArea?.deleteButton});d.type="button",d.textContent="✕",i.appendChild(r),i.appendChild(s),i.appendChild(c),i.appendChild(d);const p=a?m.getState().getInstance(a):null,u=p?.config.classNames?.tooltips,h=p?.config.styles?.tooltips;ee(d,"Delete block","below",u,h),e.addEventListener(a,d,"click",e=>{e.preventDefault(),e.stopPropagation();const t=d.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id");t&&Qr.removeBlock(a,Qr.getBlockIndex(a,t))}),e.addEventListener(a,i,"click",()=>e.handleFileSelect(t,n,a,o)),e.addEventListener(a,i,"dragleave",()=>{i.classList.remove("clepit-audio-drop-area--dragover")}),e.addEventListener(a,i,"dragover",e=>{e.preventDefault(),e.stopPropagation(),i.classList.add("clepit-audio-drop-area--dragover")}),e.addEventListener(a,i,"drop",r=>{r.preventDefault(),r.stopPropagation(),i.classList.remove("clepit-audio-drop-area--dragover"),e.handleFileDrop(r,t,n,a,o)}),e.addEventListener(a,i,"focus",e=>{e.preventDefault(),e.stopPropagation()}),e.addEventListener(a,i,"mousedown",e=>{e.preventDefault(),e.stopPropagation()}),t.appendChild(i)}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,a,o,i){e.showLoading(n);try{let r=await a(t);if(r){e.renderAudio(n,{alignment:"center",alt:t.name,caption:"",url:r},a,o,i);const s=n.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id");s&&m.getState().updateBlockData(o,Qr.getBlockIndex(o,s),Qr.getBlockData(s).data)}else e.showError(n,"Failed to upload audio. Please try again.")}catch(r){console.error("Audio upload error:",r),e.showError(n,"Failed to upload audio. Please try again.")}}static showLoading(e){e.innerHTML="";const t=l.createStyledElement("div","clepit-audio-loading",void 0);t.textContent="Uploading audio...",e.appendChild(t)}static showError(e,t){e.innerHTML="";const n=l.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=Qr.getEditorId(e);if(!a)return;const o=e.getAttribute("data-id");o&&m.getState().partialUpdateBlockData(a,Qr.getBlockIndex(a,o),{alignment:t})}static isEmpty(e){const t=e.querySelector(`.${l.classNames.block.audio.wrapper} audio`),n=e.querySelector(`.${l.classNames.block.audio.captionEditable}`);let a=!1,o=!1;return t&&t.getAttribute("src")?.trim()||(a=!0),n?D(n.innerHTML)&&(o=!0):o=!0,a&&o}static isEmptyData(e){return!e.url?.trim()&&D(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]=[])}},gn=class e{static render(t,n,a,o){if(l.injectStyles("clepit-audio-output-styles",mn),!e.validate(t))return ke();if(hn.isEmptyData(t))return document.createElement("div");const i=t.url,r=t.caption,s=t.alignment||"center",c=l.createStyledElement("div","clepit-output-audio-container",{classNames:o?.container,styles:a?.container}),d=l.createStyledElement("div","clepit-output-audio-wrapper");switch(s){case"left":d.classList.add("clepit-output-audio-wrapper--left");break;case"center":d.classList.add("clepit-output-audio-wrapper--center");break;case"right":d.classList.add("clepit-output-audio-wrapper--right")}const p=_("audio","clepit-output-audio");if(p.src=i,p.controls=!0,p.preload="metadata",t.alt&&p.setAttribute("alt",t.alt),d.appendChild(p),c.appendChild(d),r){const e=l.createStyledElement("figcaption","clepit-output-audio-caption",{classNames:o?.caption,styles:a?.caption}),n=t.caption;e.innerHTML=n&&n!==r?n:r,c.appendChild(e)}if(a&&(a.container&&Object.assign(c.style,a.container),a.caption)){const e=c.querySelector(".clepit-output-audio-caption");e&&Object.assign(e.style,a.caption)}if(o&&(o.container&&c.classList.add(o.container),o.caption)){const e=c.querySelector(".clepit-output-audio-caption");e&&e.classList.add(o.caption)}return c}static draw(t,n=me){if(!e.validate(t)||hn.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}},bn={icon:"♪",get input(){return hn},label:"Audio",get output(){return gn},shortcut:S("O"),testId:"block-type-audio",type:"audio"},fn=`\n/* Checklist input block styles */\n.${l.classNames.block.checklist.container} {\n margin: 0;\n padding: 0 20px;\n}\n\n.${l.classNames.block.checklist.item} {\n --text: var(--clepit-text);\n --check: var(--clepit-primary);\n --disabled: var(--clepit-text-muted);\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.${l.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.${l.classNames.block.checklist.text}::before,\n.${l.classNames.block.checklist.text}::after {\n content: "";\n position: absolute;\n}\n\n.${l.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.${l.classNames.block.checklist.text}::after {\n height: 4px;\n width: 4px;\n top: 8px;\n left: -25px;\n border-radius: 50%;\n}\n\n.${l.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.${l.classNames.block.checklist.checkbox}::before,\n.${l.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.${l.classNames.block.checklist.checkbox}::before {\n width: 0px;\n right: 60%;\n transform-origin: right bottom;\n}\n\n.${l.classNames.block.checklist.checkbox}::after {\n width: 0px;\n left: 40%;\n transform-origin: left bottom;\n}\n\n.${l.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.${l.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.${l.classNames.block.checklist.checkbox}:checked + .${l.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.${l.classNames.block.checklist.checkbox}:checked + .${l.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.${l.classNames.block.checklist.checkbox}:checked + .${l.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.${l.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.${l.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.${l.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(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--check), 14px -8px 0 0px var(--check), 14px 8px 0 0px var(--check), 0 15px 0 0px var(--check), -14px 8px 0 0px var(--check), -14px -8px 0 0px var(--check);\n }\n}\n\n@keyframes clepit-firework-11 {\n 0% {\n opacity: 1;\n box-shadow: 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--check), 14px -8px 0 0px var(--check), 14px 8px 0 0px var(--check), 0 15px 0 0px var(--check), -14px 8px 0 0px var(--check), -14px -8px 0 0px var(--check);\n }\n}\n`,yn='\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-primary);\n --disabled: var(--clepit-text-muted);\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(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--check), 14px -8px 0 0px var(--check), 14px 8px 0 0px var(--check), 0 15px 0 0px var(--check), -14px 8px 0 0px var(--check), -14px -8px 0 0px var(--check);\n }\n}\n\n@keyframes clepit-firework-11 {\n 0% {\n opacity: 1;\n box-shadow: 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check), 0 0 0 -2px var(--check);\n }\n 30% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n box-shadow: 0 -15px 0 0px var(--check), 14px -8px 0 0px var(--check), 14px 8px 0 0px var(--check), 0 15px 0 0px var(--check), -14px 8px 0 0px var(--check), -14px -8px 0 0px var(--check);\n }\n}\n',vn=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(`.${l.classNames.block.checklist.item}`).forEach(e=>{const n=e.querySelector('input[type="checkbox"]'),a=e.querySelector(`.${l.classNames.block.checklist.text}`);n&&a&&t.push({checked:n.checked,text:j(a.innerHTML)})}),{items:t}}static render(t,n,a){l.injectStyles("clepit-checklist-input-styles",fn);const o={items:[]},i=n?{...o,...n}:o,r=l.createStyledElement("div",l.classNames.block.checklist.container,{classNames:a?.classNames?.container,styles:a?.styles?.container});return i.items.length>0?i.items.forEach(n=>e.createAndAppendChecklistItem(n,r,t,a)):e.createAndAppendChecklistItem({checked:!1,text:""},r,t,a),r}static createAndAppendChecklistItem(t,n,a,o){const i=l.createStyledElement("div",l.classNames.block.checklist.item,{classNames:o?.classNames?.item,styles:o?.styles?.item}),r=l.createStyledElement("input",l.classNames.block.checklist.checkbox,{classNames:o?.classNames?.checkbox,styles:o?.styles?.checkbox});r.type="checkbox",r.checked=t.checked;const s=l.createStyledElement("div",l.classNames.block.checklist.text,{classNames:o?.classNames?.text,styles:o?.styles?.text});s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder",e.placeholder),s.innerHTML=t.text?.trim()||"",e.addEventListener(a,r,"change",()=>Qr.saveBlockData(r)),e.addEventListener(a,s,"keydown",t=>{const r=t,c=n.closest(`.${l.classNames.block.container}`);if(!c)return;const d=Qr.getBlockIndex(a,c.getAttribute("data-id")),p=r.metaKey||r.ctrlKey;if(r.shiftKey)switch(r.key){case"ArrowUp":t.preventDefault(),t.stopPropagation(),d>0&&Qr.moveBlock(a,d,d-1);break;case"ArrowDown":t.preventDefault(),t.stopPropagation();const e=Qr.getBlocks(a);e&&d<e.length-1&&Qr.moveBlock(a,d,d+1)}else if(p)switch(r.key){case"Delete":case"Backspace":t.preventDefault(),t.stopPropagation(),Qr.removeBlock(a,d)}else if("Enter"===r.key)if(t.preventDefault(),t.stopPropagation(),D(s.innerHTML)){e.cleanupEmptyItems(n);const t=n.closest(`.${l.classNames.block.container}`);if(!t)return;const o=Qr.getBlockIndex(a,t.getAttribute("data-id"));Qr.insertBlock({data:{html:""},type:"paragraph"},a,o+1)}else e.createAndAppendChecklistItem({checked:!1,text:""},n,a,o);else if("Backspace"===r.key){if(D(s.innerHTML)){t.preventDefault(),t.stopPropagation();const e=Array.from(n.querySelectorAll(`.${l.classNames.block.checklist.item}`)),o=e.indexOf(i);if(1===e.length){const e=n.closest(`.${l.classNames.block.container}`);if(!e)return;const t=Qr.getBlockIndex(a,e.getAttribute("data-id"));if(-1===t)return;Qr.removeBlock(a,t)}else i.remove(),o>0?e[o-1].querySelector(".clepit-checklist-text")?.focus():e[o+1].querySelector(".clepit-checklist-text")?.focus()}}else{Qr.ensureActiveBlock(a);const e=Qr.getBlocks(a);switch(r.key){case"ArrowUp":t.preventDefault(),t.stopPropagation();const a=Array.from(n.querySelectorAll(`.${l.classNames.block.checklist.item}`)),o=a.indexOf(i);if(0===o){if(d>0){const t=e[d-1];t&&Qr.focusBlock(t)}}else{const e=a[o-1].querySelector(`.${l.classNames.block.checklist.text}`);e&&e.focus()}return;case"ArrowDown":t.preventDefault(),t.stopPropagation();const r=Array.from(n.querySelectorAll(`.${l.classNames.block.checklist.item}`)),s=r.indexOf(i);if(s===r.length-1){if(d<e.length-1){const t=e[d+1];t&&Qr.focusBlock(t)}}else{const e=r[s+1].querySelector(`.${l.classNames.block.checklist.text}`);e&&e.focus()}return}}}),e.addEventListener(a,s,"input",Qr.handleInput),i.appendChild(r),i.appendChild(s),n.appendChild(i),s.focus()}static cleanupEmptyItems(e){const t=Array.from(e.querySelectorAll(`.${l.classNames.block.checklist.item}`)),n=t.filter(e=>D(e.querySelector(`.${l.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(`.${l.classNames.block.checklist.item}`);return!t||Array.from(t).every(e=>D(e.querySelector(`.${l.classNames.block.checklist.text}`)?.innerHTML))}static isEmptyData(e){return 0===e.items.length||e.items.every(e=>D(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]=[])}},xn=class e{static render(t,n,a,o){if(l.injectStyles("clepit-checklist-output-styles",yn),!e.validate(t))return ke();if(vn.isEmptyData(t))return document.createElement("div");const i=t.items,r=l.createStyledElement("div","clepit-output-checklist",{classNames:o?.container,styles:a?.container});return i.forEach((e,t)=>{const n=l.createStyledElement("div","clepit-output-checklist-item",{classNames:o?.item,styles:a?.item}),i=l.createStyledElement("input","clepit-output-checklist-checkbox",{classNames:o?.checkbox,styles:a?.checkbox});i.type="checkbox",i.checked=e.checked,i.setAttribute("readonly","true");const s=l.createStyledElement("div","clepit-output-checklist-text",{classNames:o?.text,styles:a?.text});e.text&&e.text.trim()&&(s.innerHTML=e.text),i.checked&&n.classList.add("checked"),n.appendChild(i),n.appendChild(s),r.appendChild(n)}),r}static draw(t,n=me){if(!e.validate(t)||vn.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)}},kn={icon:"☑",get input(){return vn},label:"Checklist",get output(){return xn},shortcut:S("K"),testId:"block-type-checklist",type:"checklist"},wn={icon:"𝕔",get input(){return Me},label:"Code",get output(){return Ue},shortcut:S("C"),testId:"block-type-code",type:"code"},Cn="\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",Sn=`${Cn}\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`,En=Cn,An=/* @__PURE__ */new WeakMap;var Nn=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=An.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 Fr.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:j(n?.innerHTML),open:a}}static render(t,n,a){l.injectStyles("collapsible-input",Sn);const o={children:[],html:"",open:!0},i=n?{...o,...n}:o,r=l.createStyledElement("details","clepit-collapsible clepit-collapsible--input",{classNames:a?.classNames?.section,styles:a?.styles?.section});r.open=i.open??!0,An.set(r,[...i.children??[]]);const s=document.createElement("summary"),c=document.createElement("span");c.className="clepit-collapsible__title",c.setAttribute("contenteditable","true"),c.setAttribute("data-placeholder",e.placeholder),i.html&&(c.innerHTML=j(i.html)),s.appendChild(c),r.appendChild(s);const d=document.createElement("div");return d.className="clepit-collapsible__children",(i.children??[]).forEach(n=>{d.appendChild(e.renderChild(t,n))}),r.appendChild(d),e.addEventListener(t,c,"keydown",Qr.handleKeydown),e.addEventListener(t,c,"input",Qr.handleInput),r}static renderChild(e,t){const n=document.createElement("div");n.className="clepit-collapsible__child";const a=Qr.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 D(n?.innerHTML)&&!a}static isEmptyData(e){return D(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]=[])}},Ln="\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",Bn=Ln,$n=Ln,In=class e{static render(t,n,a,o){if(l.injectStyles("collection-output",$n),!e.validate(t))return ke();const i=l.createStyledElement("div","clepit-collection clepit-output-collection",{classNames:o?.wrapper,styles:a?.wrapper});i.setAttribute("data-collection-id",t.collectionId);const r=document.createElement("span");r.className="clepit-collection__icon",r.textContent="▦",i.appendChild(r);const s=document.createElement("span");return s.className="clepit-collection__label",s.textContent="Collection",i.appendChild(s),i}static draw(t,n=me){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}},Tn="\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",Mn=`${Tn}\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`,_n=Tn,qn=class e{static render(t,n,a,o){if(l.injectStyles("columns-output",_n),!e.validate(t))return ke();const i=l.createStyledElement("div","clepit-columns clepit-output-columns",{classNames:o?.container,styles:a?.container});for(const r of t.columns){const t=l.createStyledElement("div","clepit-columns__column",{classNames:o?.column,styles:a?.column});for(const a of r)t.appendChild(e.renderChild(a,n));i.appendChild(t)}return i}static renderChild(e,t){const n=Fr.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=me,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=Wi(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))}},Dn="\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",jn=`${Dn}\n.clepit-date--input {\n cursor: pointer;\n border: none;\n font: inherit;\n}\n`,zn=Dn,On=/^(\d{4})-(\d{2})-(\d{2})$/;function Hn(e){const t=On.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 Pn=class e{static render(t,n,a,o){l.injectStyles("date-output",zn);const i=e.validate(t)?Hn(t.date):null;if(!i)return ke();const r=l.createStyledElement("time","clepit-date clepit-output-date",{classNames:o?.pill,styles:a?.pill});return r.dateTime=t.date,r.textContent=new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeZone:"UTC"}).format(i),r}static draw(t,n=me){const a=e.validate(t)?Hn(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}},Rn='\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',Fn=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,a){l.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 o={variant:"line"},i=n?{...o,...n}:o,r=l.createStyledElement("div","clepit-delimiter-container",{classNames:a?.classNames?.[i.variant],styles:a?.styles?.[i.variant]});if(r.setAttribute("contenteditable","true"),r.setAttribute("tabindex","0"),"stars"===i.variant){const e=l.createStyledElement("div","clepit-delimiter",{classNames:a?.classNames?.[i.variant],styles:a?.styles?.[i.variant]});e.setAttribute("data-variant",i.variant),e.textContent="***",r.appendChild(e)}else{const e=l.createStyledElement("hr","clepit-delimiter",{classNames:a?.classNames?.[i.variant],styles:a?.styles?.[i.variant]});e.setAttribute("data-variant",i.variant),r.appendChild(e)}return e.addEventListener(t,r,"keydown",e=>{const n=e,a=r.closest(`.${l.classNames.block.container}`);if(!a)return;const o=Qr.getBlockIndex(t,a.getAttribute("data-id")),i=n.metaKey||n.ctrlKey;if(n.shiftKey)switch(n.key){case"ArrowUp":e.preventDefault(),e.stopPropagation(),o>0&&Qr.moveBlock(t,o,o-1);break;case"ArrowDown":e.preventDefault(),e.stopPropagation();const n=Qr.getBlocks(t);n&&o<n.length-1&&Qr.moveBlock(t,o,o+1)}else if(i)switch(n.key){case"Delete":case"Backspace":e.preventDefault(),e.stopPropagation(),Qr.removeBlock(t,o)}else if("Enter"===n.key)n.preventDefault(),n.stopPropagation(),Qr.insertBlock({data:{html:""},type:"paragraph"},t,o+1);else if("Backspace"===n.key)n.preventDefault(),n.stopPropagation(),Qr.removeBlock(t,o);else{Qr.ensureActiveBlock(t);const a=Qr.getBlocks(t);switch(n.key){case"ArrowUp":if(e.preventDefault(),e.stopPropagation(),o>0){const e=a[o-1];e&&Qr.focusBlock(e)}return;case"ArrowDown":if(e.preventDefault(),e.stopPropagation(),o<a.length-1){const e=a[o+1];e&&Qr.focusBlock(e)}return}}}),r.focus(),r}static changeVariant(t,n,a){const o=m.getState().getInstance(a);if(!o)return;if(t.getAttribute("data-variant")===n)return;const i={variant:n},r={classNames:o.config.classNames?.blocks?.delimiter,styles:o.config.styles?.blocks?.delimiter},s=Qr.getBlockIndex(a,t.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id")),c=e.render(a,i,r);t.replaceWith(c),m.getState().updateBlockData(a,s,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]=[])}},Un=class e{static render(t,n,a,o){if(l.injectStyles("clepit-delimiter-output-styles",Rn),!e.validate(t))return ke();if(Fn.isEmptyData(t))return document.createElement("div");const i=t.variant,r=l.createStyledElement("div","clepit-output-delimiter",{classNames:o?.[i],styles:a?.[i]});if("stars"===i)r.innerHTML="***",r.setAttribute("data-variant","stars");else{const e=document.createElement("hr");e.setAttribute("data-variant","line"),e.className="clepit-delimiter",r.appendChild(e)}return r}static draw(t,n=me){if(!e.validate(t)||Fn.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}},Vn="\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",Wn=Vn,Kn=Vn,Gn=class e{static render(t,n,a,o){if(l.injectStyles("doc-card-output",Kn),!e.validate(t))return ke();const i=l.createStyledElement("a","clepit-doc-card clepit-output-doc-card",{classNames:o?.card,styles:a?.card});i.setAttribute("data-page-id",t.pageId),n?.docHref&&(i.href=n.docHref(t.pageId));const r=document.createElement("span");r.className="clepit-doc-card__icon",r.textContent=t.icon??"📄",i.appendChild(r);const s=document.createElement("span"),c=document.createElement("span");if(c.className="clepit-doc-card__title",c.textContent=t.title||"Untitled",s.appendChild(c),t.description){const e=document.createElement("span");e.className="clepit-doc-card__description",e.textContent=t.description,s.appendChild(e)}return i.appendChild(s),i}static draw(t,n=me,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}},Jn="\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",Xn=`${Jn}\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`,Zn=Jn;function Yn(e){return null==e?"":e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}var Qn=class e{static render(t,n,a,o){if(l.injectStyles("file-output",Zn),!e.validate(t))return ke();const i=l.createStyledElement("a","clepit-file clepit-output-file",{classNames:o?.row,styles:a?.row});i.href=t.url,i.setAttribute("download",t.name),i.setAttribute("rel","noopener noreferrer");const r=document.createElement("span");r.className="clepit-file__name",r.textContent=t.name,i.appendChild(r);const s=Yn(t.size);if(s){const e=document.createElement("span");e.className="clepit-file__size",e.textContent=s,i.appendChild(e)}return i}static draw(t,n=me){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=Yn(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)))}},ea='\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',ta="At a glance",na=class e{static render(t,n,a,o){if(l.injectStyles("clepit-glance-output-styles",ea),!e.validate(t))return ke();if(0===t.rows.length)return document.createElement("div");const i=l.createStyledElement("div","clepit-glance",{classNames:o?.wrapper,styles:a?.wrapper});i.setAttribute("data-variant",t.variant??"plain"),i.setAttribute("data-testid","glance");const r=_("p","clepit-glance-caption");r.textContent=t.caption?.trim()?t.caption:ta,i.appendChild(r);const s=_("dl","clepit-glance-rows");for(const e of t.rows){const t=_("dt","clepit-glance-label");t.textContent=e.label,s.appendChild(t);const n=_("dd","clepit-glance-value");n.innerHTML=j(e.html),s.appendChild(n)}return i.appendChild(s),i}static draw(t,n=me){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:ta),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))}},aa="\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\nh1.clepit-output-header {\n font-size: 2.5rem;\n line-height: 1.2;\n}\n\nh2.clepit-output-header {\n font-size: 2rem;\n line-height: 1.3;\n}\n\nh3.clepit-output-header {\n font-size: 1.75rem;\n line-height: 1.4;\n}\n\nh4.clepit-output-header {\n font-size: 1.5rem;\n line-height: 1.4;\n}\n\nh5.clepit-output-header {\n font-size: 1.25rem;\n line-height: 1.4;\n}\n\nh6.clepit-output-header {\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 h1.clepit-output-header {\n font-size: 2rem;\n }\n\n h2.clepit-output-header {\n font-size: 1.75rem;\n }\n\n h3.clepit-output-header {\n font-size: 1.5rem;\n }\n}\n",oa=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(`.${l.classNames.block.header}`),n=t?.getAttribute("data-level")||"h1";return{html:j(t?.innerHTML),level:n}}static render(t,n,a){l.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 o={html:"",level:"h1"},i=n?{...o,...n}:o,r=i.level??"h1",s=l.createStyledElement(r,l.classNames.block.header,{classNames:a?.classNames?.[r],styles:a?.styles?.[r]});return s.setAttribute("data-level",r),s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder",e.placeholder),i.html?s.innerHTML=i.html:s.innerHTML="",e.addEventListener(t,s,"keydown",Qr.handleKeydown),e.addEventListener(t,s,"input",Qr.handleInput),s}static changeLevel(t,n,a){const o=m.getState().getInstance(a);if(!o)return;if(t.getAttribute("data-level")===n)return;const i={html:t.innerHTML,level:n},r={classNames:o.config.classNames?.blocks?.header,margins:o.config.margins,styles:o.config.styles?.blocks?.header},s=Qr.getBlockIndex(a,t.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id")),c=e.render(a,i,r);t.replaceWith(c),m.getState().updateBlockData(a,s,i)}static isEmpty(e){return D(e.querySelector(`.${l.classNames.block.header}`)?.innerHTML)}static isEmptyData(e){return D(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]=[])}},ia=class e{static render(t,n,a,o){if(l.injectStyles("clepit-header-output-styles",aa),!e.validate(t))return ke();if(oa.isEmptyData(t))return document.createElement("div");const i=t.html,r=t.level||"h1",s=l.createStyledElement(r,"clepit-output-header",{classNames:o?.[r],styles:a?.[r]});return i&&(s.innerHTML=i),s}static draw(t,n=me){if(!e.validate(t)||oa.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}},ra=`\n/* Image block styles */\n.${l.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.${l.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.${l.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.${l.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.${l.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.${l.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.${l.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.${l.classNames.block.imageDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Image drop area delete button */\n.clepit-image-drop-area .${l.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 .${l.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`,sa="\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",la=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(`.${l.classNames.block.image.captionEditable}`),a=e.querySelector(".clepit-image-wrapper");let o="center";return a&&(o=a.classList.contains("clepit-image-wrapper--left")?"left":a.classList.contains("clepit-image-wrapper--right")?"right":"center"),{alignment:o,alt:t?.getAttribute("alt")||"",caption:j(n?.innerHTML),url:t?.getAttribute("src")||""}}static render(t,n,a,o){l.injectStyles("clepit-image-input-styles",ra);const i={alt:"",caption:"",url:""},r=a?{...i,...a}:i,s=l.createStyledElement("div",l.classNames.block.image.container,{classNames:o?.classNames?.container,styles:o?.styles?.container});return r.url?e.renderImage(s,r,t,n,o):e.renderDropArea(s,t,n,o),s}static renderImage(t,n,a,o,i){t.innerHTML="";const r=l.createStyledElement("div",l.classNames.block.image.wrapper,{classNames:i?.classNames?.container,styles:i?.styles?.container});switch(r.setAttribute("tabindex","-1"),n?.alignment||"center"){case"left":r.classList.add("clepit-image-wrapper--left");break;case"center":r.classList.add("clepit-image-wrapper--center");break;case"right":r.classList.add("clepit-image-wrapper--right")}const s=l.createStyledElement("img","clepit-image",{classNames:i?.classNames?.container,styles:i?.styles?.container});s.alt=n?.alt||"",s.src=n?.url||"",s.classList.add("clepit-image");const c=l.createStyledElement("div","clepit-image-caption-container",{classNames:i?.classNames?.caption,styles:i?.styles?.caption});c.classList.add("clepit-image-caption-container");const d=l.createStyledElement("div",l.classNames.block.image.captionEditable,{classNames:i?.classNames?.caption,styles:i?.styles?.caption});d.setAttribute("contenteditable","true"),d.setAttribute("data-placeholder",e.placeholder),d.innerHTML=n?.caption||"",e.addEventListener(o,d,"keydown",Qr.handleKeydown),e.addEventListener(o,d,"input",Qr.handleInput),e.addEventListener(o,r,"click",()=>e.handleFileSelect(t,a,o,i)),r.appendChild(s),c.appendChild(d),t.appendChild(r),t.appendChild(c),d.focus()}static renderDropArea(t,n,a,o){t.innerHTML="";const i=l.createStyledElement("div",l.classNames.block.image.dropArea,{classNames:o?.classNames?.dropArea?.container,styles:o?.styles?.dropArea?.container});i.setAttribute("tabindex","0"),i.classList.add("clepit-drop-area");const r=l.createStyledElement("div","clepit-image-drop-icon",{classNames:o?.classNames?.dropArea?.icon,styles:o?.styles?.dropArea?.icon});r.textContent="📷";const s=l.createStyledElement("div","clepit-image-drop-text",{classNames:o?.classNames?.dropArea?.text,styles:o?.styles?.dropArea?.text});s.innerHTML='<strong>Drop an image here</strong><br>or <span class="clepit-image-click-text">click to select</span>';const c=l.createStyledElement("div","clepit-image-drop-subtext",{classNames:o?.classNames?.dropArea?.subtext,styles:o?.styles?.dropArea?.subtext});c.textContent="Supports JPEG, PNG, GIF, WebP, SVG, and other image formats";const d=l.createStyledElement("button",`${l.classNames.block.imageDeleteBtn}`,{classNames:o?.classNames?.dropArea?.deleteButton,styles:o?.styles?.dropArea?.deleteButton});d.type="button",d.textContent="✕",i.appendChild(r),i.appendChild(s),i.appendChild(c),i.appendChild(d);const p=m.getState().getInstance(a),u=p?.config.classNames?.tooltips,h=p?.config.styles?.tooltips;ee(d,"Delete block","below",u,h),e.addEventListener(a,d,"click",e=>{e.preventDefault(),e.stopPropagation();const t=d.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id");t&&Qr.removeBlock(a,Qr.getBlockIndex(a,t))}),e.addEventListener(a,i,"click",()=>e.handleFileSelect(t,n,a,o)),e.addEventListener(a,i,"dragleave",()=>{i.classList.remove("clepit-image-drop-area--dragover")}),e.addEventListener(a,i,"dragover",e=>{e.preventDefault(),e.stopPropagation(),i.classList.add("clepit-image-drop-area--dragover")}),e.addEventListener(a,i,"drop",r=>{r.preventDefault(),r.stopPropagation(),i.classList.remove("clepit-image-drop-area--dragover"),e.handleFileDrop(r,t,n,a,o)}),e.addEventListener(a,i,"focus",e=>{e.preventDefault(),e.stopPropagation()}),e.addEventListener(a,i,"mousedown",e=>{e.preventDefault(),e.stopPropagation()}),t.appendChild(i)}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,a,o,i){e.showLoading(n);try{let r=await a(t);if(r){e.renderImage(n,{alignment:"center",alt:t.name,caption:"",url:r},a,o,i);const s=n.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id");s&&m.getState().updateBlockData(o,Qr.getBlockIndex(o,s),Qr.getBlockData(s).data)}else e.showError(n,"Failed to upload image. Please try again.")}catch(r){console.error("Image upload error:",r),e.showError(n,"Failed to upload image. Please try again.")}}static showLoading(e){e.innerHTML="";const t=l.createStyledElement("div","clepit-image-loading",void 0);t.textContent="Uploading image...",e.appendChild(t)}static showError(e,t){e.innerHTML="";const n=l.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=Qr.getEditorId(e);if(!a)return;const o=e.getAttribute("data-id");o&&m.getState().partialUpdateBlockData(a,Qr.getBlockIndex(a,o),{alignment:t})}static isEmpty(e){const t=e.querySelector(`.${l.classNames.block.image.wrapper} img`),n=e.querySelector(`.${l.classNames.block.image.captionEditable}`);let a=!1,o=!1;return t&&t.getAttribute("src")?.trim()||(a=!0),n?D(n.innerHTML)&&(o=!0):o=!0,a&&o}static isEmptyData(e){return!e.url?.trim()&&D(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]=[])}},ca=class e{static render(t,n,a,o){if(l.injectStyles("clepit-image-output-styles",sa),!e.validate(t))return ke();if(la.isEmptyData(t))return document.createElement("div");const i=t.url,r=t.caption,s=t.alt||r||"",c=l.createStyledElement("div","clepit-output-image-container",{classNames:o?.container,styles:a?.container}),d=l.createStyledElement("div","clepit-output-image-wrapper");if(t.alignment)switch(t.alignment){case"left":d.classList.add("clepit-output-image-wrapper--left");break;case"center":d.classList.add("clepit-output-image-wrapper--center");break;case"right":d.classList.add("clepit-output-image-wrapper--right")}const p=_("img","clepit-output-image");if(p.src=i,p.alt=s,d.appendChild(p),c.appendChild(d),r){const e=l.createStyledElement("figcaption","clepit-output-image-caption",{classNames:o?.caption,styles:a?.caption}),n=t.caption;e.innerHTML=n&&n!==r?n:r,c.appendChild(e)}return c}static draw(t,n=me){if(!e.validate(t)||la.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}},da=Je,pa=Je,ua=(e,t)=>{if("string"!=typeof e){if(Array.isArray(e))for(const n of e)ua(n,t);else if(e&&"object"==typeof e){const n=e;if("embed"===n.type&&n.data&&"object"==typeof n.data){const e=n.data;e.issue&&"object"==typeof e.issue&&t.push({...e.issue,url:e.issue.url||e.url||""})}for(const e of Object.values(n))ua(e,t)}}else e.includes("clepit-issue")&&t.push(...mt(e))},ma=class e{static collect(e,t){const n=[];ua(e??[],n);const a=/* @__PURE__ */new Set,o=[];for(const i of n)i.url&&!a.has(i.url)&&(a.add(i.url),o.push(t?.[i.url]?{...t[i.url],url:i.url}:i));return o}static render(t,n,a,o){l.injectStyles("issues-output",pa);const i=e.collect(n?.documentBlocks,n?.issues);if(0===i.length){const e=l.createStyledElement("div","clepit-issues__empty clepit-output-issues",{classNames:o,styles:a});return e.setAttribute("data-testid","issues-empty"),e.textContent=Qe(n?.issueLabels,"linkedIssuesEmpty"),e}const r=xe(e.table(i,me,n?.issueLabels));return l.applyStyling(r,{classNames:o,styles:a}),r}static draw(t,n=me,a){if(null==t||"object"!=typeof t)return null;const o=e.collect(a?.documentBlocks,a?.issues);return 0===o.length?null:e.table(o,n,a?.issueLabels)}static table(e,t,n){const a=t.create("table");a.addClass("clepit-issues","clepit-output-issues"),a.setAttribute("data-testid","issues-table");const o=t.create("thead"),i=t.create("tr");for(const s of["columnIssue","columnTitle","columnStatus","columnAssignee"]){const e=t.create("th");e.setText(Qe(n,s)),i.append(e)}o.append(i),a.append(o);const r=t.create("tbody");for(const s of e){const e=t.create("tr");e.setAttribute("data-testid","issues-row"),e.setAttribute("data-issue-url",s.url);const a=t.create("td"),o=t.create("a");o.setAttribute("href",s.url),o.setAttribute("rel","noopener noreferrer nofollow"),o.setAttribute("target","_blank"),o.setText(s.key||s.title||s.url),a.append(o),e.append(a);const i=t.create("td");i.setText(s.key?s.title:""),e.append(i);const l=t.create("td");if(!s.reason){const e=t.create("span");e.addClass("clepit-issue__state"),e.setAttribute("data-issue-category",s.category),e.setText(st(s,n)),l.append(e)}e.append(l);const c=t.create("td");c.setText(s.reason?"":s.assigneeName||Qe(n,"unassigned")),e.append(c),r.append(e)}return a.append(r),a}},ha="\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",ga=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(j(e.innerHTML))),{items:a,type:n}}static render(t,n,a){l.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 o={items:[],type:e.defaultType},i=n?{...o,...n}:o,r="ordered"===i.type?"ol":"ul",s=l.createStyledElement(r,l.classNames.block.list.container,{classNames:a?.classNames?.[i.type]?.container,styles:a?.styles?.[i.type]?.container});s.setAttribute("data-type",i.type);const c=a?.classNames?.[i.type]?.item,d=a?.styles?.[i.type]?.item;return i.items.length>0?i.items.forEach(n=>e.createAndAppendListItem(n,s,t,c,d)):e.createAndAppendListItem("",s,t,c,d),s}static createAndAppendListItem(t,n,a,o,i){const r=l.createStyledElement("li",l.classNames.block.list.item,{classNames:o,styles:i});r.innerHTML=t,r.setAttribute("contenteditable","true"),r.setAttribute("data-placeholder",e.placeholder),e.addEventListener(a,r,"keydown",t=>{const s=t,c=n.closest(`.${l.classNames.block.container}`);if(!c)return;const d=Qr.getBlockIndex(a,c.getAttribute("data-id")),p=s.metaKey||s.ctrlKey;if(s.shiftKey)switch(s.key){case"ArrowUp":t.preventDefault(),t.stopPropagation(),d>0&&Qr.moveBlock(a,d,d-1);break;case"ArrowDown":t.preventDefault(),t.stopPropagation();const e=Qr.getBlocks(a);e&&d<e.length-1&&Qr.moveBlock(a,d,d+1)}else if(p)switch(s.key){case"Delete":case"Backspace":t.preventDefault(),t.stopPropagation(),Qr.removeBlock(a,d)}else if("Enter"===s.key)if(t.preventDefault(),t.stopPropagation(),D(r.innerHTML)){e.cleanupEmptyItems(n);const t=n.closest(`.${l.classNames.block.container}`);if(!t)return;const o=Qr.getBlockIndex(a,t.getAttribute("data-id"));Qr.insertBlock({data:{html:""},type:"paragraph"},a,o+1)}else e.createAndAppendListItem("",n,a,o,i);else if("Backspace"===s.key){if(D(r.innerHTML)){t.preventDefault(),t.stopPropagation();const e=Array.from(n.querySelectorAll("li")),o=e.indexOf(r);if(1===e.length){const e=n.closest(`.${l.classNames.block.container}`);if(!e)return;const t=Qr.getBlockIndex(a,e.getAttribute("data-id"));if(-1===t)return;Qr.removeBlock(a,t)}else r.remove(),o>0?e[o-1].focus():e[o+1].focus()}}else{Qr.ensureActiveBlock(a);const e=Qr.getBlocks(a);switch(s.key){case"ArrowUp":t.preventDefault(),t.stopPropagation();const a=Array.from(n.querySelectorAll(`.${l.classNames.block.list.item}`)),o=a.indexOf(r);if(0===o){if(d>0){const t=e[d-1];t&&Qr.focusBlock(t)}}else{const e=a[o-1];e&&e.focus()}return;case"ArrowDown":t.preventDefault(),t.stopPropagation();const i=Array.from(n.querySelectorAll(`.${l.classNames.block.list.item}`)),s=i.indexOf(r);if(s===i.length-1){if(d<e.length-1){const t=e[d+1];t&&Qr.focusBlock(t)}}else{const e=i[s+1];e&&e.focus()}return}}}),e.addEventListener(a,r,"input",Qr.handleInput),n.appendChild(r),r.focus()}static changeType(t,n,a){const o=m.getState().getInstance(a);if(!o)return;if(t.getAttribute("data-type")===n)return;const i={items:[...t.querySelectorAll("li")||[]].map(e=>e.innerHTML),type:n},r={classNames:o.config.classNames?.blocks?.list,styles:o.config.styles?.blocks?.list},s=Qr.getBlockIndex(a,t.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id")),c=e.render(a,i,r);t.replaceWith(c),m.getState().updateBlockData(a,s,i)}static cleanupEmptyItems(e){const t=Array.from(e.querySelectorAll("li")),n=t.filter(e=>D(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(`.${l.classNames.block.list.item}`);return!t||Array.from(t).every(e=>D(e.innerHTML))}static isEmptyData(e){return 0===e.items.length||e.items.every(e=>D(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]=[])}},ba=class e{static render(t,n,a,o){if(l.injectStyles("clepit-list-output-styles",ha),!e.validate(t))return ke();if(ga.isEmptyData(t))return document.createElement("div");const i=t.items,r="ordered"===t.type?"ordered":"unordered",s=l.createStyledElement("ordered"===r?"ol":"ul","clepit-output-list",{classNames:o?.[r]?.container,styles:a?.[r]?.container});return i.forEach((e,t)=>{const n=e,i=l.createStyledElement("li","clepit-output-list-item",{classNames:o?.[r]?.item,styles:a?.[r]?.item});n&&n.trim()&&(i.innerHTML=n),s.appendChild(i)}),s}static draw(t,n=me){if(!e.validate(t)||ga.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}},fa="\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",ya=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),va=(e,t)=>{const n={children:[],cyclic:!1,nullable:!1,required:!1,type:"unknown"};if(!ya(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=va(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=>va(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=va(e.items,t);return n.type=`${a.ref??a.type}[]`,n.children.push(...a.children),n}return"object"===n.type&&((e,t,n)=>{if(!ya(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=va(i,n);e.name=o,e.required=a.includes(o),t.children.push(e)}})(e,n,t),n},xa=(e,t)=>va(e,{schemas:t,stack:/* @__PURE__ */new Set}),ka=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),wa=e=>{if(!ka(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"}},Ca=e=>{if(!ka(e)||!ka(e.properties))return;const t={};for(const[n,a]of Object.entries(e.properties))t[n]=wa(a);return t},Sa=e=>e.security[0],Ea=(e,t)=>{return`${t}${n=e.path,n.replace(/\{([^}]+)\}/g,":$1")}`;var n},Aa={bash:{build:(e,t)=>{const n=[`curl -X ${e.method} "${Ea(e,t)}"`],a=Sa(e);var o;a&&n.push(` -H "Authorization: Bearer $${o=a,o.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toUpperCase()}"`);const i=Ca(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=Ca(e.request),a=e.method.toLowerCase(),o=[` Uri.parse('${Ea(e,t)}'),`],i=[],r=Sa(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=Ca(e.request),a=e.method.toLowerCase(),o=[` "${Ea(e,t)}",`],i=Sa(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=Ca(e.request),a=[],o=Sa(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('${Ea(e,t)}', {`,...i,"});","","const data = await response.json();"].join("\n")},label:"TypeScript"}},Na=["bash","typescript","dart","python"],La=["get","post","put","patch","delete"],Ba=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),$a=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,""),Ia=(e,t,n)=>!!e&&(!!e.tags?.some(e=>t.includes(e))||(e.paths?.includes(n)??!1)),Ta=e=>(Array.isArray(e.parameters)?e.parameters:[]).filter(Ba).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}})),Ma=e=>Ba(e.responses)?Object.entries(e.responses).map(([e,t])=>{const n=Ba(t)?t:{},a=Ba(n.content)?n.content:void 0,o=a&&Ba(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}}):[],_a=e=>{if(!Ba(e.requestBody))return;const t=Ba(e.requestBody.content)?e.requestBody.content:void 0;return(t&&Ba(t["application/json"])?t["application/json"]:void 0)?.schema},qa=e=>{if(!Array.isArray(e.security))return[];const t=e.security.find(Ba);return t?Object.keys(t):[]},Da=e=>{if(!Array.isArray(e.servers))return;const t=e.servers.find(Ba);return"string"==typeof t?.url?t.url:void 0},ja=(e,t)=>e[0]??t.split("/").filter(Boolean)[0]??"default",za=(e,t)=>{const n=Ba(e)?e:{},a=Ba(n.info)?n.info:{},o=Ba(n.components)?n.components:{},i={groups:[],schemas:Ba(o.schemas)?o.schemas:{},servers:(Array.isArray(n.servers)?n.servers:[]).filter(Ba).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=Ba(n.paths)?n.paths:{},s=/* @__PURE__ */new Map;for(const[l,c]of Object.entries(r))if(Ba(c))for(const e of La){const n=c[e];if(!Ba(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(Ia(t.exclude,a,l))continue;if(t.include&&!i&&!Ia(t.include,a,l))continue;const r={..."string"==typeof n.description?{description:n.description}:{},id:$a(`${e}-${l}`),internal:o,method:e.toUpperCase(),params:Ta(n),path:l,...void 0===_a(n)?{}:{request:_a(n)},responses:Ma(n),security:qa(n),...void 0===Da(n)?{}:{server:Da(n)},summary:"string"==typeof n.summary?n.summary:l,tags:a},d=ja(a,l),p=s.get(d);p?p.operations.push(r):s.set(d,{id:$a(d),operations:[r],title:d})}return i.groups=[...s.values()],i},Oa=(e,t,n,a)=>{const o=e.create(t);return n&&o.addClass(...n.split(" ")),void 0!==a&&o.setText(a),o},Ha=(e,t)=>{const n=Oa(e,"div","clepit-openapi-table-scroll");return n.append(t),n},Pa=(e,t,n,a)=>{const o=Oa(e,"p","clepit-openapi-section-title",t);return o.setAttribute("data-testid",`openapi-section-${n}-${a}`),o},Ra=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},Fa=(e,t=0)=>t>6?Ra(e):e.type.endsWith("[]")?0===e.children.length?[]:[Object.fromEntries(e.children.map(e=>[e.required?e.name:`${e.name}?`,Fa(e,t+1)]))]:e.children.length>0?Object.fromEntries(e.children.map(e=>[e.required?e.name:`${e.name}?`,Fa(e,t+1)])):Ra(e),Ua=e=>{const t=Number.parseInt(e,10);return t>=200&&t<300?"success":t>=400&&t<500?"client":t>=500?"server":"other"},Va=(e,t,n,a)=>{const o=Oa(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=Oa(e,"div","clepit-openapi-operation-head"),s=Oa(e,"span","clepit-openapi-method",t.method);s.setAttribute("data-method",t.method),s.setAttribute("data-testid",`openapi-method-${t.id}`);const l=Oa(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=Oa(e,"span","clepit-openapi-host",i);n.setAttribute("data-testid",`openapi-host-${t.id}`),r.append(n)}o.append(r);const c=Oa(e,"div","clepit-openapi-operation-body"),d=Oa(e,"h3","clepit-openapi-summary",t.summary);d.setAttribute("id",t.id),c.append(d),t.description&&c.append(Oa(e,"p","clepit-openapi-description",t.description));const p=Oa(e,"div","clepit-openapi-security");p.setAttribute("data-testid",`openapi-security-${t.id}`),p.append(Oa(e,"span","clepit-openapi-section-title","Auth")),p.appendText(" "),p.append(Oa(e,"span","clepit-openapi-badge",t.security.length>0?t.security.join(", "):"public")),c.append(p);const u=((e,t,n)=>{if(0===t.params.length)return null;const a=Oa(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(Oa(e,"th","clepit-openapi-th",i));a.append(o);for(const i of t.params){const t=e.create("tr"),o=Oa(e,"td","clepit-openapi-name",i.name);i.required&&o.append(Oa(e,"span","clepit-openapi-required"," required")),t.append(o),t.append(Oa(e,"td","clepit-openapi-cell",i.in)),t.append(Oa(e,"td","clepit-openapi-type",Ra(xa(i.schema,n.schemas)))),t.append(Oa(e,"td","clepit-openapi-cell",i.description??"")),a.append(t)}return a})(e,t,n);if(u&&(c.append(Pa(e,"Parameters","parameters",t.id)),c.append(Ha(e,u))),void 0!==t.request){const a=xa(t.request,n.schemas);if(a.children.length>0){c.append(Pa(e,"Body","body",t.id));const n=Oa(e,"div","clepit-openapi-body");n.setAttribute("data-testid",`openapi-body-${t.id}`);const o=Ue.draw({code:JSON.stringify(Fa(a),null,2),language:"json",showCopy:!0},e);o&&n.append(o),c.append(n)}}t.responses.length>0&&(c.append(Pa(e,"Responses","responses",t.id)),c.append(((e,t,n)=>{const a=Oa(e,"div","clepit-openapi-responses");a.setAttribute("data-testid",`openapi-responses-${t.id}`);const o=Oa(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=Oa(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=Oa(e,"p","clepit-openapi-response-description");if(r){const t=Oa(e,"span","clepit-openapi-status",a.status);t.setAttribute("data-kind",Ua(a.status)),c.append(t),c.appendText(` ${a.description}`)}else c.setText(a.description);if(l.append(c),void 0!==a.schema){const t=xa(a.schema,n.schemas);if(t.children.length>0){const n=Ue.draw({code:JSON.stringify(Fa(t),null,2),language:"json",showCopy:!0},e);n&&l.append(n)}}i.push(l);const d=Oa(e,"button","clepit-openapi-response-tab",a.status);d.setAttribute("type","button"),d.setAttribute("role","tab"),d.setAttribute("aria-controls",`${t.id}-response-${a.status}`),d.setAttribute("aria-selected",0===s?"true":"false"),d.setAttribute("tabindex",0===s?"0":"-1"),d.setAttribute("data-kind",Ua(a.status)),d.setAttribute("data-testid",`openapi-response-tab-${t.id}-${a.status}`),o.append(d)}),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=Aa[n];return a?[{code:a.build(e,t),label:a.label,language:n}]:[]}))(t,i,a.snippetLanguages??Na);if(m.length>0){c.append(Pa(e,"Try it","try-it",t.id));const n=Ue.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},Wa=class e{static draw(t,n=me){if(!e.validate(t))return null;const a=za(t.spec,t),o=Oa(n,"div","clepit-openapi");if(a.servers.length>0){const e=Oa(n,"table","clepit-openapi-table clepit-openapi-servers");e.setAttribute("data-testid","openapi-servers");const t=n.create("tr");t.append(Oa(n,"th","clepit-openapi-th","Host")),t.append(Oa(n,"th","clepit-openapi-th","Serves")),e.append(t);for(const o of a.servers){const t=n.create("tr");t.append(Oa(n,"td","clepit-openapi-name",o.url)),t.append(Oa(n,"td","clepit-openapi-cell",o.description??"")),e.append(t)}o.append(Ha(n,e))}for(const e of a.groups){const i=Oa(n,"section","clepit-openapi-group");i.setAttribute("data-testid",`openapi-group-${e.id}`);const r=Oa(n,"h2","clepit-openapi-group-title",e.title);r.setAttribute("id",e.id),i.append(r);for(const o of e.operations)i.append(Va(n,o,a,t));o.append(i)}return o}static render(t,n,a,o){if(l.injectStyles("clepit-openapi-output-styles",fa),!e.validate(t))return ke();const i=xe(e.draw(t,me));o?.container&&i.classList.add(o.container),a?.container&&Object.assign(i.style,a.container),e.attach(i);for(const e of[...i.querySelectorAll(".clepit-output-code-container")])Ue.activateFromMarkup(e);return i}static activate(t){const n=[e.attach(t)];for(const e of[...t.querySelectorAll(".clepit-output-code-container")])n.push(Ue.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))}},Ka="\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",Ga=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:j(e.querySelector(`.${l.classNames.block.paragraph}`)?.innerHTML)}}static render(t,n,a){l.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 o=l.createStyledElement("div",l.classNames.block.paragraph,{classNames:a?.classNames,styles:a?.styles});return o.setAttribute("contenteditable","true"),o.setAttribute("data-placeholder",e.placeholder),o.innerHTML=n?.html||"",e.addEventListener(t,o,"keydown",Qr.handleKeydown),e.addEventListener(t,o,"input",Qr.handleInput),o}static isEmpty(e){return D(e.querySelector(`.${l.classNames.block.paragraph}`)?.innerHTML)}static isEmptyData(e){return D(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]=[])}},Ja=class e{static render(t,n,a,o){if(l.injectStyles("clepit-paragraph-output-styles",Ka),!e.validate(t))return ke();const i=l.createStyledElement("p","clepit-output-paragraph",{classNames:o,styles:a});if(Ga.isEmptyData(t))return i.appendChild(document.createElement("br")),i;const r=t.html;return r&&(i.innerHTML=r),i}static draw(t,n=me){if(!e.validate(t))return null;const a=n.create("p");return a.addClass("clepit-output-paragraph"),Ga.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}},Xa=`\n/* Quote block styles */\n.${l.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.${l.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.${l.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.${l.classNames.block.quote.author}:focus {\n outline: none;\n}\n\n.${l.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.${l.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.${l.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.${l.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.${l.classNames.block.quote.text} a:hover {\n color: var(--clepit-primary-hover);\n text-decoration: none;\n}\n\n/* Quote inline code styling */\n.${l.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`,Za="\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",Ya=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(`.${l.classNames.block.quote.text}`),n=e.querySelector(`.${l.classNames.block.quote.author}`);return{author:j(n?.innerHTML),html:j(t?.innerHTML)}}static render(t,n,a){l.injectStyles("clepit-quote-input-styles",Xa);const o=n||{author:"",html:""},i=l.createStyledElement("div",l.classNames.block.quote.container,{classNames:a?.classNames?.container,styles:a?.styles?.container}),r=l.createStyledElement("div",l.classNames.block.quote.text,{classNames:a?.classNames?.text,styles:a?.styles?.text}),s=l.createStyledElement("div",l.classNames.block.quote.author,{classNames:a?.classNames?.author,styles:a?.styles?.author});if(r.innerHTML=o.html||"",r.setAttribute("contenteditable","true"),r.setAttribute("data-placeholder",e.placeholder),s.innerHTML=o.author||"",s.setAttribute("contenteditable","true"),s.setAttribute("data-placeholder",e.authorPlaceholder),e.addEventListener(t,r,"keydown",e.handleKeydown),e.addEventListener(t,r,"input",Qr.handleInput),e.addEventListener(t,s,"keydown",e.handleKeydown),e.addEventListener(t,s,"input",Qr.handleInput),i.appendChild(r),o.author){const e=l.createStyledElement("div",l.classNames.block.quote.divider,{classNames:a?.classNames?.divider,styles:a?.styles?.divider});i.appendChild(e)}return i.appendChild(s),i}static handleKeydown(e){const t=e,n=e.currentTarget,a=n.closest(`.${l.classNames.block.container}`),o=Qr.getEditorId(a);if(!o)return;const i=Qr.getBlockIndex(o,a.getAttribute("data-id")),r=a.querySelector(`.${l.classNames.block.quote.text}`),s=a.querySelector(`.${l.classNames.block.quote.author}`),c=t.metaKey||t.ctrlKey;if(t.shiftKey)switch(t.key){case"ArrowUp":e.preventDefault(),e.stopPropagation(),i>0&&Qr.moveBlock(o,i,i-1);break;case"ArrowDown":e.preventDefault(),e.stopPropagation();const t=Qr.getBlocks(o);t&&i<t.length-1&&Qr.moveBlock(o,i,i+1)}else if(c)switch(t.key){case"Delete":case"Backspace":e.preventDefault(),e.stopPropagation(),Qr.removeBlock(o,i)}else if("Enter"===t.key)t.preventDefault(),t.stopPropagation(),Qr.insertBlock({data:{html:""},type:"paragraph"},o,i+1);else if("Backspace"===t.key){if(!D(n.innerHTML))return;t.preventDefault(),t.stopPropagation(),n===r?Qr.removeBlock(o,i):n===s&&(D(r.innerHTML)?Qr.removeBlock(o,i):r.focus())}else if("ArrowUp"===t.key)if(t.preventDefault(),t.stopPropagation(),n===r){const e=a.previousElementSibling;e&&Qr.focusBlock(e)}else r.focus();else if("ArrowDown"===t.key)if(t.preventDefault(),t.stopPropagation(),n===s){const e=a.nextElementSibling;e&&Qr.focusBlock(e)}else s.focus()}static handleKeydownInAuthorInput(e){const t=e,n=e.currentTarget,a=n.closest(`.${l.classNames.block.container}`),o=Qr.getEditorId(a);if(o)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=a.querySelector(`.${l.classNames.block.quote.text}`);e&&e.focus()}}else{t.preventDefault(),t.stopPropagation();const e=Qr.getBlockIndex(o,a.getAttribute("data-id"));Qr.insertBlock({data:{html:""},type:"paragraph"},o,e+1)}}static isEmpty(e){const t=e.querySelector(`.${l.classNames.block.quote.text}`),n=e.querySelector(`.${l.classNames.block.quote.author}`);let a=!1,o=!1;return t?D(t.innerHTML)&&(a=!0):a=!0,n?D(n.innerHTML)&&(o=!0):o=!0,a&&o}static isEmptyData(e){return D(e.html)&&D(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]=[])}},Qa=class e{static render(t,n,a,o){if(l.injectStyles("clepit-quote-output-styles",Za),!e.validate(t))return ke();if(Ya.isEmptyData(t))return document.createElement("div");const i=t.html,r=t.author||"",s=l.createStyledElement("div","clepit-output-quote-container",{classNames:o?.container,styles:a?.container}),c=l.createStyledElement("div","clepit-output-quote-text",{classNames:o?.text,styles:a?.text}),d=_("div","clepit-output-quote-content");if(i&&i.trim()&&(d.innerHTML=i),c.appendChild(d),s.appendChild(c),r){const e=l.createStyledElement("div","clepit-output-quote-divider",{classNames:o?.divider,styles:a?.divider});s.appendChild(e);const t=l.createStyledElement("div","clepit-output-quote-author",{classNames:o?.author,styles:a?.author});t.textContent=`— ${r}`,s.appendChild(t)}return s.querySelectorAll(`span.${l.classNames.block.tooltip}[data-tooltip]`).forEach(e=>{const t=e;t.hasAttribute("data-tooltip-initialized")||(ee(t,String(t.getAttribute("data-tooltip")||""),"above",n?.tooltipClassNames,void 0),t.setAttribute("data-tooltip-initialized","true"))}),s}static draw(t,n=me){if(!e.validate(t)||Ya.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}},eo="\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",to=eo,no=eo,ao="http://www.w3.org/2000/svg";function oo(e){return e&&/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(e.trim())?e.trim():"#000000"}function io(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 ro=class e{static render(t,n,a,o){if(l.injectStyles("sketch-output",no),!e.validate(t))return ke();const i=l.createStyledElement("div","clepit-sketch clepit-output-sketch",{classNames:o?.wrapper,styles:a?.wrapper}),r=document.createElementNS(ao,"svg");r.setAttribute("class","clepit-sketch__canvas"),r.setAttribute("viewBox","0 0 1000 240"),r.setAttribute("preserveAspectRatio","none"),r.setAttribute("role","img");for(const s of t.strokes??[]){const t=io(s.points??[]);if(!t)continue;const n=document.createElementNS(ao,"path");n.setAttribute("d",t),n.setAttribute("fill","none"),n.setAttribute("stroke",oo(s.color)),n.setAttribute("stroke-width",String(e.safeWidth(s))),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),r.appendChild(n)}return i.appendChild(r),i}static draw(t,n=me){if(!e.validate(t))return null;const a=n.create("div");a.addClass("clepit-sketch","clepit-output-sketch");const o=n.createNS(ao,"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=io(i.points??[]);if(!t)continue;const a=n.createNS(ao,"path");a.setAttribute("d",t),a.setAttribute("fill","none"),a.setAttribute("stroke",oo(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)}},so=`\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.${l.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.${l.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) .${l.classNames.block.table.cell} {\n background: var(--clepit-bg);\n}\n\n.clepit-table-tbody tr:nth-child(even) .${l.classNames.block.table.cell} {\n background: var(--clepit-surface);\n}\n\n.${l.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.${l.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.${l.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.${l.classNames.block.table.headerCell}[data-placeholder]:empty::before,\n.${l.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.${l.classNames.block.table.headerCell}:hover .clepit-col-handle,\n.clepit-table-row:hover .clepit-row-delete,\n.${l.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`,lo="\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",co=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 a=n.querySelector("thead tr"),o=a?Array.from(a.querySelectorAll(`.${l.classNames.block.table.headerCell}`)):[],i=[],r=[];for(const e of o){const t=e.cloneNode(!0);t.querySelectorAll(".clepit-col-handle, .clepit-col-delete").forEach(e=>e.remove()),r.push(j(t.innerHTML))}i.push(r);const s=n.querySelectorAll("tbody tr");for(const e of Array.from(s)){const t=Array.from(e.querySelectorAll(`.${l.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(j(t.innerHTML))}i.push(n)}const c=(t.querySelector(".clepit-table-download-switch")?.querySelector('input[type="checkbox"]'))?.checked||!1;return{caption:j(t.querySelector(`.${l.classNames.block.table.caption}`)?.innerHTML||""),data:i,showDownload:c}}static render(t,n,a){l.injectStyles("clepit-table-input-styles",so);const o=n?{...e.defaultData,...n}:e.defaultData,i=l.createStyledElement("div","clepit-table-container",{classNames:a?.classNames?.container,styles:a?.styles?.container}),r=l.createStyledElement("table","clepit-table",{classNames:a?.classNames?.table,styles:a?.styles?.table}),s=l.createStyledElement("thead","clepit-table-thead",{classNames:a?.classNames?.table,styles:a?.styles?.table}),c=e.createRow(t,o.data[0],!0);s.appendChild(c),r.appendChild(s);const d=l.createStyledElement("tbody","clepit-table-tbody",{classNames:a?.classNames?.table,styles:a?.styles?.table});for(let l=1;l<o.data.length;l++){const n=e.createRow(t,o.data[l]);d.appendChild(n)}r.appendChild(d);const p=l.createStyledElement("div","clepit-table-scroll-container");p.appendChild(r),i.appendChild(p);const u=l.createStyledElement("button","clepit-table-btn clepit-row-menu-btn",{classNames:a?.classNames?.rowMenuButton,styles:a?.styles?.rowMenuButton});u.style.position="absolute",u.style.display="none",u.style.zIndex="1000",u.textContent="⋮",i.appendChild(u);const h=l.createStyledElement("button","clepit-table-btn clepit-col-menu-btn",{classNames:a?.classNames?.columnMenuButton,styles:a?.styles?.columnMenuButton});h.style.position="absolute",h.style.display="none",h.style.zIndex="1000",h.textContent="⋯",i.appendChild(h);let g=null,b=-1,f=null;e.addEventListener(t,i,"mouseleave",()=>(u.style.display="none",h.style.display="none",void(f&&(f.remove(),f=null))));const v=e=>{g=e;const t=e.getBoundingClientRect(),n=i.getBoundingClientRect(),a=t.top-n.top+t.height/2-12;u.style.left="4px",u.style.top=`${Math.max(4,a)}px`,u.style.display="flex"},w=e=>{if(b=Array.from(c.querySelectorAll(`.${l.classNames.block.table.headerCell}`)).indexOf(e),b<0)return;const t=e.getBoundingClientRect(),n=i.getBoundingClientRect(),a=t.left-n.left+t.width/2-12,o=t.top-n.top-20;h.style.left=`${a}px`,h.style.top=`${Math.max(4,o)}px`,h.style.display="flex"};e.addEventListener(t,d,"mouseover",e=>{const t=e.target.closest("tr");t&&v(t)}),e.addEventListener(t,s,"mouseover",e=>{const t=e.target.closest(`.${l.classNames.block.table.headerCell}`);t&&w(t)}),e.addEventListener(t,d,"mouseover",e=>{const t=e.target.closest(`.${l.classNames.block.table.cell}`);if(!t)return;const n=t.closest("tr");if(!n)return;const a=Array.from(n.querySelectorAll(`.${l.classNames.block.table.cell}`)).indexOf(t);if(a>=0){const e=c.querySelectorAll(`.${l.classNames.block.table.headerCell}`)[a];e&&w(e)}v(n)});const C=()=>{g&&"none"!==u.style.display&&v(g);const e=c.querySelectorAll(`.${l.classNames.block.table.headerCell}`)[b];e&&"none"!==h.style.display&&w(e)};e.addEventListener(t,window,"scroll",C,{passive:!0}),e.addEventListener(t,p,"scroll",C,{passive:!0}),e.addEventListener(t,u,"click",n=>{if(n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation?.(),!g)return;const o=Array.from(d.querySelectorAll("tr")),r=o.indexOf(g),s=u.getBoundingClientRect(),p=i.getBoundingClientRect();e.createMenu(t,i,u,h,[{label:"Move up",onClick:()=>{r>0&&(d.insertBefore(g,o[r-1]),Qr.saveBlockData(g))},shortcut:y("up")},{label:"Move down",onClick:()=>{r>=0&&r<o.length-1&&(d.insertBefore(o[r+1],g),Qr.saveBlockData(g))},shortcut:y("down")},{label:"Insert above",onClick:()=>{const n=c.querySelectorAll(`.${l.classNames.block.table.headerCell}`).length||3,a=e.createRow(t,Array.from({length:n},()=>""));d.insertBefore(a,g),Qr.saveBlockData(g)},shortcut:E("up")},{label:"Insert below",onClick:()=>{const n=c.querySelectorAll(`.${l.classNames.block.table.headerCell}`).length||3,a=e.createRow(t,Array.from({length:n},()=>""));g.nextSibling?d.insertBefore(a,g.nextSibling):d.appendChild(a),Qr.saveBlockData(g)},shortcut:E("down")},{label:"Delete",onClick:()=>{o.length>1&&(g.remove(),Qr.saveBlockData(g))},shortcut:x()}],s.left-p.left,s.bottom-p.top+4,a,f)}),e.addEventListener(t,h,"click",n=>{if(n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation?.(),b<0)return;const o=Array.from(c.querySelectorAll(`.${l.classNames.block.table.headerCell}`)),r=h.getBoundingClientRect(),s=i.getBoundingClientRect();e.createMenu(t,i,u,h,[{label:"Move left",onClick:()=>{if(b<=0)return;const e=b,t=o[e-1],n=o[e];t&&n&&c.insertBefore(n,t),d.querySelectorAll("tr").forEach(t=>{const n=Array.from(t.querySelectorAll(`.${l.classNames.block.table.cell}`)),a=n[e-1],o=n[e];a&&o&&t.insertBefore(o,a)}),b=e-1,Qr.saveBlockData(c)},shortcut:y("left")},{label:"Move right",onClick:()=>{const e=b;if(e<0||e>=o.length-1)return;const t=o[e],n=o[e+1];t&&n&&c.insertBefore(n,t),d.querySelectorAll("tr").forEach(t=>{const n=Array.from(t.querySelectorAll(`.${l.classNames.block.table.cell}`)),a=n[e],o=n[e+1];a&&o&&t.insertBefore(o,a)}),b=e+1,Qr.saveBlockData(c)},shortcut:y("right")},{label:"Insert left",onClick:()=>{const n=b,a=e.createHeaderCell(t,"");c.insertBefore(a,o[n]),d.querySelectorAll("tr").forEach(a=>{const o=e.createCell(t,""),i=a.querySelectorAll(`.${l.classNames.block.table.cell}`);i[n]?a.insertBefore(o,i[n]):a.appendChild(o)}),Qr.saveBlockData(c)},shortcut:E("left")},{label:"Insert right",onClick:()=>{const n=b+1,a=o[b]?.nextSibling||null,i=e.createHeaderCell(t,"");c.insertBefore(i,a),d.querySelectorAll("tr").forEach(a=>{const o=e.createCell(t,""),i=a.querySelectorAll(`.${l.classNames.block.table.cell}`);i[n]?a.insertBefore(o,i[n]):a.appendChild(o)}),Qr.saveBlockData(c)},shortcut:E("right")},{label:"Delete",onClick:()=>{const e=c.querySelectorAll(`.${l.classNames.block.table.headerCell}`);if(b<0||e.length<=1)return;const t=e[b];t?.parentElement?.removeChild(t),d.querySelectorAll("tr").forEach(e=>{const t=e.querySelectorAll(`.${l.classNames.block.table.cell}`);t[b]&&t[b].parentElement?.removeChild(t[b])}),Qr.saveBlockData(c)},shortcut:k()}],r.left-s.left,r.bottom-s.top+4,a,f)});Array.from(d.querySelectorAll("tr")).forEach(n=>(n=>{e.addEventListener(t,n,"mouseenter",()=>v(n))})(n)),Array.from(c.querySelectorAll(`.${l.classNames.block.table.headerCell}`)).forEach(n=>{return a=n,void e.addEventListener(t,a,"mouseenter",()=>w(a));var a});const S=l.createStyledElement("div","clepit-table-caption-download-container",{classNames:a?.classNames?.container,styles:a?.styles?.container});S.style.display="flex",S.style.alignItems="center",S.style.gap="8px",S.style.marginTop="8px";const A=l.createStyledElement("div",`${l.classNames.block.table.caption}`,{classNames:a?.classNames?.caption,styles:a?.styles?.caption});A.contentEditable="true",A.setAttribute("tabindex","0"),A.setAttribute("data-placeholder",e.captionPlaceholder),A.style.flex="1",A.style.minWidth="0",A.innerHTML=j(o.caption),e.addEventListener(t,A,"input",Qr.handleInput),e.addEventListener(t,A,"keydown",e.handleKeydown),e.addEventListener(t,A,"click",e.handleClick),S.appendChild(A);const N=l.createStyledElement("div",`${l.classNames.block.table.downloadSwitch}`);N.style.flexShrink="0";const L=Te.create({checked:o.showDownload||!1,label:"Allow download",onToggle:e=>{const n=i.closest(`.${l.classNames.block.container}`);if(n){const a=n.getAttribute("data-id");a&&m.getState().partialUpdateBlockData(t,Qr.getBlockIndex(t,a),{showDownload:e})}}});N.appendChild(L),S.appendChild(N),i.appendChild(S);return e.addEventListener(t,i,"focusin",()=>{const e=document.activeElement;if(e&&i.contains(e))if(e.classList.contains(l.classNames.block.table.cell)){const t=e.closest("tr");t&&(g=t,v(t))}else e.classList.contains(l.classNames.block.table.headerCell)&&w(e)}),i}static createRow(t,n,a){const o=m.getState().getInstance(t),i=o?.config.classNames?.blocks?.table?.row,r=o?.config.styles?.blocks?.table?.row,s=l.createStyledElement("tr",a?`${l.classNames.block.table.headerRow}`:`${l.classNames.block.table.row}`,{classNames:i,styles:r});for(let l=0;l<n.length;l++)s.appendChild(a?e.createHeaderCell(t,n[l]):e.createCell(t,n[l]));return s.querySelector(`.${l.classNames.block.table.cell}`)?.focus(),s}static createCell(t,n){const a=m.getState().getInstance(t),o=a?.config.classNames?.blocks?.table?.cell,i=a?.config.styles?.blocks?.table?.cell,r=l.createStyledElement("td",`${l.classNames.block.table.cell}`,{classNames:o,styles:i});return r.contentEditable="true",r.setAttribute("tabindex","0"),r.setAttribute("data-placeholder",e.cellPlaceholder),r.innerHTML=j(n),e.addEventListener(t,r,"input",Qr.handleInput),e.addEventListener(t,r,"keydown",e.handleKeydown),e.addEventListener(t,r,"click",e.handleClick),r}static createHeaderCell(t,n){const a=m.getState().getInstance(t),o=a?.config.classNames?.blocks?.table?.header,i=a?.config.styles?.blocks?.table?.header,r=l.createStyledElement("th",`${l.classNames.block.table.headerCell}`,{classNames:o,styles:i});return r.contentEditable="true",r.setAttribute("tabindex","0"),r.setAttribute("data-placeholder",e.headerPlaceholder),r.innerHTML=j(n),e.addEventListener(t,r,"input",Qr.handleInput),e.addEventListener(t,r,"keydown",e.handleKeydown),e.addEventListener(t,r,"click",e.handleClick),r}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=Qr.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=Qr.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,a,o,i,r,s,c,d){d&&(d.remove(),d=null);const p=l.createStyledElement("div","clepit-block-operations-menu clepit-table-menu",{classNames:c?.classNames?.menu,styles:c?.styles?.menu});p.classList.add("clepit-block-operations-menu--visible"),p.style.position="absolute",p.style.zIndex="20",p.style.left=`${r}px`,p.style.top=`${s}px`,p.style.minWidth="180px",i.forEach(n=>{const a="delete"===n.label.toLowerCase(),o=l.createStyledElement("div","clepit-menu-item"+(a?" clepit-menu-item--danger":""),{classNames:c?.classNames?.menuItem,styles:c?.styles?.menuItem});o.style.fontSize="14px";const i=l.createStyledElement("span","clepit-menu-icon"),r=n.label.toLowerCase();r.includes("move up")?i.textContent="↑":r.includes("move down")?i.textContent="↓":r.includes("move left")?i.textContent="←":r.includes("move right")?i.textContent="→":r.includes("insert")?i.textContent="+":r.includes("delete")?i.textContent="×":i.textContent="•";const s=l.createStyledElement("span","clepit-menu-text");if(s.textContent=n.label,o.appendChild(i),o.appendChild(s),n.shortcut){const e=l.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,o.appendChild(e)}e.addEventListener(t,o,"click",e=>{e.stopPropagation(),e.stopImmediatePropagation?.(),n.onClick(),d&&(d.remove(),d=null)}),p.appendChild(o)}),n.appendChild(p),d=p;const u=e=>{p.contains(e.target)||e.target===a||e.target===o||(p.remove(),d=null,document.removeEventListener("click",u))};return setTimeout(()=>document.addEventListener("click",u),0),p}static handleClick(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget.closest(`.${l.classNames.block.container}`);t&&Qr.setActiveBlock(t)}static handleKeydown(e){const t=e,n=e.currentTarget,a=Qr.getEditorId(n);if(!a)return;const o=n.closest(`.${l.classNames.block.container}`);if(!o)return;const i=Qr.getBlockIndex(a,o.getAttribute("data-id")),r=t.metaKey||t.ctrlKey;if(t.shiftKey)switch(t.key){case"ArrowUp":e.preventDefault(),e.stopPropagation(),i>0&&Qr.moveBlock(a,i,i-1);break;case"ArrowDown":e.preventDefault(),e.stopPropagation();const t=Qr.getBlocks(a);t&&i<t.length-1&&Qr.moveBlock(a,i,i+1)}else if(r){const o=n.closest("table"),r=o.querySelector("tbody"),s=o.querySelector("thead tr");switch(t.key){case"ArrowUp":if(n.classList.contains(l.classNames.block.table.cell)){e.preventDefault(),e.stopPropagation();const t=n.closest("tr"),a=Array.from(r.querySelectorAll("tr")),o=a.indexOf(t);if(o>0){const e=Array.from(t.querySelectorAll(`.${l.classNames.block.table.cell}`)).indexOf(n);r.insertBefore(t,a[o-1]),Qr.saveBlockData(t);const i=t.querySelectorAll(`.${l.classNames.block.table.cell}`)[e];i&&i.focus()}}break;case"ArrowDown":if(n.classList.contains(l.classNames.block.table.cell)){e.preventDefault(),e.stopPropagation();const t=n.closest("tr"),a=Array.from(r.querySelectorAll("tr")),o=a.indexOf(t);if(o>=0&&o<a.length-1){const e=Array.from(t.querySelectorAll(`.${l.classNames.block.table.cell}`)).indexOf(n);r.insertBefore(a[o+1],t),Qr.saveBlockData(t);const i=t.querySelectorAll(`.${l.classNames.block.table.cell}`)[e];i&&i.focus()}}break;case"ArrowLeft":let t=-1;const c=Array.from(s.querySelectorAll(`.${l.classNames.block.table.headerCell}`));if(n.classList.contains(l.classNames.block.table.headerCell))t=c.indexOf(n);else if(n.classList.contains(l.classNames.block.table.cell)){const e=n.closest("tr");t=Array.from(e.querySelectorAll(`.${l.classNames.block.table.cell}`)).indexOf(n)}if(t>0){e.preventDefault(),e.stopPropagation();const a=t,i=c[a-1],r=c[a];if(i&&r&&s.insertBefore(r,i),o.querySelectorAll("tbody tr").forEach(e=>{const t=Array.from(e.querySelectorAll(`.${l.classNames.block.table.cell}`)),n=t[a-1],o=t[a];n&&o&&e.insertBefore(o,n)}),n.classList.contains(l.classNames.block.table.cell)){const e=n.closest("tr").querySelectorAll(`.${l.classNames.block.table.cell}`)[a-1];e&&e.focus()}else{r&&r.focus()}Qr.saveBlockData(s)}break;case"ArrowRight":let d=-1;const p=Array.from(s.querySelectorAll(`.${l.classNames.block.table.headerCell}`));if(n.classList.contains(l.classNames.block.table.headerCell))d=p.indexOf(n);else if(n.classList.contains(l.classNames.block.table.cell)){const e=n.closest("tr");d=Array.from(e.querySelectorAll(`.${l.classNames.block.table.cell}`)).indexOf(n)}if(d<p.length-1){e.preventDefault(),e.stopPropagation();const t=d,a=p[t],i=p[t+1];if(a&&i&&s.insertBefore(i,a),o.querySelectorAll("tbody tr").forEach(e=>{const n=Array.from(e.querySelectorAll(`.${l.classNames.block.table.cell}`)),a=n[t],o=n[t+1];a&&o&&e.insertBefore(o,a)}),n.classList.contains(l.classNames.block.table.cell)){const e=n.closest("tr").querySelectorAll(`.${l.classNames.block.table.cell}`)[t+1];e&&e.focus()}else{i&&i.focus()}Qr.saveBlockData(s)}break;case"Backspace":if(n.classList.contains(l.classNames.block.table.cell)){e.preventDefault(),e.stopPropagation();const t=n.closest("tr");Array.from(r.querySelectorAll("tr")).length>1&&(t.remove(),Qr.saveBlockData(t))}else e.preventDefault(),e.stopPropagation(),Qr.removeBlock(a,i);break;case"Delete":let u=-1;const m=Array.from(s.querySelectorAll(`.${l.classNames.block.table.headerCell}`));if(n.classList.contains(l.classNames.block.table.headerCell))u=m.indexOf(n);else if(n.classList.contains(l.classNames.block.table.cell)){const e=n.closest("tr");u=Array.from(e.querySelectorAll(`.${l.classNames.block.table.cell}`)).indexOf(n)}if(u>=0&&m.length>1){e.preventDefault(),e.stopPropagation();const t=m[u];t?.parentElement?.removeChild(t),o.querySelectorAll("tbody tr").forEach(e=>{const t=e.querySelectorAll(`.${l.classNames.block.table.cell}`);t[u]&&t[u].parentElement?.removeChild(t[u])}),Qr.saveBlockData(s)}else e.preventDefault(),e.stopPropagation(),Qr.removeBlock(a,i)}}else if("Enter"===t.key)e.preventDefault(),e.stopPropagation(),Qr.insertBlock({data:{html:""},type:"paragraph"},a,i+1);else if("Backspace"===t.key){const t=n.closest(`.${l.classNames.block.container}`);if(!t)return;Array.from(t.querySelectorAll(`.${l.classNames.block.table.cell},.${l.classNames.block.table.headerCell}`)).every(e=>D(e.innerHTML))&&(e.preventDefault(),e.stopPropagation(),Qr.removeBlock(a,i))}else{Qr.ensureActiveBlock(a);const o=Qr.getBlocks(a);switch(t.key){case"ArrowUp":if(e.preventDefault(),e.stopPropagation(),n.classList.contains(l.classNames.block.table.caption)){const e=n.closest(`.${l.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 a=n.closest("tr"),r=Array.from(a?.cells||[]).indexOf(n);if("TBODY"===a?.parentElement?.tagName&&a===a.parentElement.firstElementChild){const e=t.querySelector("thead")?.querySelector("tr");if(e&&e.cells[r])return void e.cells[r].focus()}if(a?.previousElementSibling){const e=a.previousElementSibling.cells[r];e&&e.focus()}else if(i>0){const e=o[i-1];e&&Qr.focusBlock(e)}return;case"ArrowDown":if(e.preventDefault(),e.stopPropagation(),n.classList.contains(l.classNames.block.table.caption)){if(i<o.length-1){const e=o[i+1];e&&Qr.focusBlock(e)}return}const s=n.closest("table");if(!s)return;const c=n.closest("tr"),d=Array.from(c?.cells||[]).indexOf(n);if("THEAD"===c?.parentElement?.tagName){const e=s.querySelector("tbody")?.firstElementChild;if(e&&e.cells[d])return void e.cells[d].focus()}if(c?.nextElementSibling){const e=c.nextElementSibling.cells[d];e&&e.focus()}else{if("TBODY"===c?.parentElement?.tagName&&c===c.parentElement.lastElementChild){const e=s.closest(`.${l.classNames.block.container}`)?.querySelector(`.${l.classNames.block.table.caption}`);if(e)return void e.focus()}if(i<o.length-1){const e=o[i+1];e&&Qr.focusBlock(e)}}return;case"ArrowLeft":if(!z(n,"left"))return;e.preventDefault(),e.stopPropagation();const p=n.closest("table");if(!p)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=p.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(!z(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(`.${l.classNames.block.table.caption}`),n=e.querySelectorAll(`.${l.classNames.block.table.cell},.${l.classNames.block.table.headerCell}`);let a=!1,o=!1;return t?D(t.innerHTML)&&(a=!0):a=!0,n?Array.from(n).every(e=>D(e.innerHTML))&&(o=!0):o=!0,a&&o}static isEmptyData(e){return D(e.caption)&&e.data.every(e=>e.every(e=>D(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]=[])}},po="http://www.w3.org/2000/svg",uo=["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"],mo=class e{static{this.eventListenersMap=/* @__PURE__ */new WeakMap}static render(t,n,a,o,i){if(l.injectStyles("clepit-table-output-styles",lo),!e.validate(t))return ke();if(co.isEmptyData(t))return document.createElement("div");const r=e.draw(t,me);if(!r)return document.createElement("div");const s=xe(r);o?.container&&s.classList.add(o.container),a?.container&&Object.assign(s.style,a.container);const c=s.querySelector(".clepit-output-table-caption");c&&o?.caption&&c.classList.add(o.caption),c&&a?.caption&&Object.assign(c.style,a.caption);const d=s.querySelector(".clepit-output-table-footer-container");return d&&o?.footerContainer&&d.classList.add(o.footerContainer),d&&a?.footerContainer&&Object.assign(d.style,a.footerContainer),e.attach(s,t,a,o,i),s}static activate(t,n){return!e.validate(n)||co.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 l=i?document.getElementById(i):null;if(l){const t=e.eventListenersMap.get(l)??[];t.push({element:r,event:"click",handler:s}),e.eventListenersMap.set(l,t)}const c=i?m.getState().getInstance(i):null,d=ee(r,"Download CSV","above",c?.config.classNames?.tooltips,c?.config.styles?.tooltips);return()=>{r.removeEventListener("click",s),d()}}static draw(t,n=me){if(!e.validate(t)||co.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(po,"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 uo){const a=e.createNS(po,"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))}},ho="\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",go=ho,bo=ho,fo={h1:0,h2:1,h3:2,h4:3,h5:4,h6:5},yo=class{static render(e,t,n,a){l.injectStyles("toc-output",bo);const o=(t?.documentBlocks??[]).filter(e=>"header"===e.type),i=l.createStyledElement("nav","clepit-toc clepit-output-toc",{classNames:a?.list,styles:n?.list});if(0===o.length){const e=document.createElement("div");return e.className="clepit-toc__empty",e.textContent="Table of contents — headings appear here",i.appendChild(e),i}return o.forEach((e,t)=>{const o=e.data,r=l.createStyledElement("a","clepit-toc__entry",{classNames:a?.entry,styles:n?.entry});r.setAttribute("data-toc-index",t.toString());const s=fo[o.level??"h1"];r.style.paddingLeft=16*s+"px",e.id&&(r.href=`#${e.id}`),r.innerHTML=j(o.html),i.appendChild(r)}),i}static draw(e,t=me,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*fo[a.level??"h1"]}px;`),e.id&&i.setAttribute("href",`#${e.id}`),i.setHtml(a.html),o.append(i)}),o}},vo="\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",xo=vo,ko=vo,wo=.55,Co=.52,So=(e,t,n)=>e.draw.map(e=>({...e,x:e.x+t,y:e.y+n}));function Eo(e,t=18){switch(e.kind){case"atom":return Ao(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=Eo(r,t);n.push(...So(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=Eo(e.base,t),a=No(t),o=[...n.draw];let i=n.width,r=n.height,s=n.depth;if(null!==e.sup){const s=Eo(e.sup,a),l=Math.max(.62*n.height,.4*t);o.push(...So(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=Eo(e.sub,a),l=Math.max(.5*n.depth,.22*t);o.push(...So(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=Eo(e.numerator,t),a=Eo(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:[...So(n,(s-n.width)/2,l),{kind:"rule",thickness:i,width:s,x:0,y:-o},...So(a,(s-a.width)/2,c)],height:-l+n.height,width:s}}(e,t);case"radical":return function(e,t){const n=Eo(e.radicand,t),a=.6*t,o=null===e.index?null:Eo(e.index,No(No(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},...So(n,i+.12*t,0)];null!==o&&s.push(...So(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=Ao(e.symbol,"upright",n),o=No(t),i=null===e.upper?null:Eo(e.upper,o),r=null===e.lower?null:Eo(e.lower,o),s=Math.max(a.width,i?.width??0,r?.width??0),l=[...So(a,(s-a.width)/2,0)];let c=a.height,d=a.depth;if(null!==i){const e=a.height+i.depth+.16*t;l.push(...So(i,(s-i.width)/2,-e)),c=e+i.height}if(null!==r){const e=a.depth+r.height+.16*t;l.push(...So(r,(s-r.width)/2,e)),d=e+r.depth}return{depth:d,draw:l,height:c,width:s}}(e,t);case"accent":return function(e,t){const n=Eo(e.base,t),a=Ao(e.over,"upright",No(t)),o="_"===e.over;return{depth:o?n.depth+.2*t:n.depth,draw:[...n.draw,...So(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=Eo(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}:Ao(e.open,"upright",o),r=""===e.close?{depth:0,draw:[],height:0,width:0}:Ao(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:[...So(i,0,s(i)),...So(n,i.width,0),...So(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=>Eo(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),d=i.reduce((e,t,n)=>e+t+(r[n]??0),0)+l*Math.max(n.length-1,0),p=[];let u=-d/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;p.push(...So(n,e+(a-n.width)/2,u)),e+=a+s}u+=(r[v]??0)+l}const[m,h]=Lo[e.style],g=Math.max(t,.62*d),b=""===m?{depth:0,draw:[],height:0,width:0}:Ao(m,"upright",g),f=""===h?{depth:0,draw:[],height:0,width:0}:Ao(h,"upright",g),y=e=>(e.height-e.depth)/2;return{depth:d/2,draw:[...So(b,0,y(b)),...p.map(e=>({...e,x:e.x+b.width})),...So(f,b.width+c,y(f))],height:d/2,width:b.width+c+f.width}}(e,t)}}function Ao(e,t,n){const a="italic"===t?wo:Co;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 No(e){return Math.max(9,.7*e)}var Lo={bracket:["[","]"],"double-pipe":["‖","‖"],paren:["(",")"],pipe:["|","|"],plain:["",""]};var Bo={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:"ζ"},$o={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:"→"},Io={bigcap:"⋂",bigcup:"⋃",int:"∫",lim:"lim",oint:"∮",prod:"∏",sum:"∑"},To=["arccos","arcsin","arctan","cos","cosh","cot","csc","deg","det","dim","exp","gcd","ln","log","max","min","sec","sin","sinh","tan","tanh"],Mo={bar:"‾",ddot:"¨",dot:"˙",hat:"^",tilde:"~",vec:"→"},_o={",":3,";":5,":":4,"!":-3,qquad:36,quad:18},qo={".":"","(":"(",")":")","[":"[","]":"]","\\{":"{","\\}":"}","\\|":"‖","|":"|"},Do=["catcode","csname","def","href","include","input","newcommand","renewcommand","url","write"],jo={bmatrix:"bracket",matrix:"plain",pmatrix:"paren",Vmatrix:"double-pipe",vmatrix:"pipe"},zo=/[A-Za-z0-9+\-=<>()[\]|,./!:;]/,Oo=/[A-Za-z]/,Ho=/[0-9]/,Po={mathbf:"bold",mathit:"italic",mathrm:"upright",text:"text"},Ro=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,!Oo.test(this.peek()))return this.take();let e="";for(;Oo.test(this.peek());)e+=this.take();return e}},Fo=class extends Error{};function Uo(e){const t=new Ro(e);try{const e=Vo(t,null);if(Ko(t))throw new Fo("a \\right appears without a matching \\left");if(!t.done)throw new Fo(`"${t.peek()}" is unexpected here`);return{ok:!0,root:e}}catch(n){if(n instanceof Fo)return{ok:!1,reason:n.message};throw n}}function Vo(e,t){const n=[];for(;(e.skipSpace(),!e.done)&&("}"!==t||"}"!==e.peek())&&("]"!==t||"]"!==e.peek())&&("cell"!==t||"&"!==e.peek()&&!Wo(e)&&!Go(e))&&!Ko(e);){const t=Jo(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 Wo(e){return"\\"===e.peek()&&"\\"===e.peek(1)}function Ko(e){return!!e.source.startsWith("\\right",e.at)&&!Oo.test(e.peek(6))}function Go(e){return"\\"===e.peek()&&e.source.startsWith("\\end",e.at)}function Jo(e){const t=Xo(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=Xo(e);if(null===o)throw new Fo(`"${t}" has nothing after it`);if("^"===t){if(null!==a)throw new Fo("a term carries two superscripts");a=o}else{if(null!==n)throw new Fo("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 Xo(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=Vo(e,"}");if("}"!==e.peek())throw new Fo("a { group is never closed");return e.take(),t}if("\\"===t)return function(e){const t=e.readCommand();if(Do.includes(t))throw new Fo(`"\\${t}" is refused for safety, not merely unsupported`);if("\\"===t)throw new Fo("a row break appears outside a matrix");if("begin"===t)return function(e){const t=Yo(e),n=jo[t];if(void 0===n)throw new Fo(`the "${t}" environment is not supported yet`);const a=[];let o=[];for(let i=0;i<4096;i+=1)if(o.push(Vo(e,"cell")),e.skipSpace(),"&"!==e.peek()){if(!Wo(e)){if(Go(e)){e.at+=4;const i=Yo(e);if(i!==t)throw new Fo(`\\begin{${t}} is closed by \\end{${i}}`);return a.push(o),{kind:"matrix",rows:a,style:n}}throw new Fo(`\\begin{${t}} is never closed`)}e.at+=2,a.push(o),o=[]}else e.take();throw new Fo(`\\begin{${t}} is never closed`)}(e);if("end"===t)throw new Fo("an \\end appears without a matching \\begin");if("frac"===t||"dfrac"===t||"tfrac"===t){const t=Zo(e);return{denominator:Zo(e),kind:"fraction",numerator:t}}if("sqrt"===t)return function(e){e.skipSpace();let t=null;if("["===e.peek()){if(e.take(),t=Vo(e,"]"),"]"!==e.peek())throw new Fo("a \\sqrt index is never closed");e.take()}return{index:t,kind:"radical",radicand:Zo(e)}}(e);if("left"===t)return function(e){const t=Qo(e,"left"),n=Vo(e,null);if(!Ko(e))throw new Fo("a \\left has no matching \\right");return e.at+=6,{body:n,close:Qo(e,"right"),kind:"delimited",open:t}}(e);if("right"===t)throw new Fo("a \\right appears without a matching \\left");const n=Po[t];if(void 0!==n)return{kind:"atom",style:n,text:Yo(e)};const a=Mo[t];if(void 0!==a)return{base:Zo(e),kind:"accent",over:a};if("overline"===t)return{base:Zo(e),kind:"accent",over:"‾"};if("underline"===t)return{base:Zo(e),kind:"accent",over:"_"};const o=Io[t];if(void 0!==o)return{kind:"bigop",lower:null,symbol:o,upper:null};const i=Bo[t];if(void 0!==i)return{kind:"atom",style:"italic",text:i};const r=$o[t];if(void 0!==r)return{kind:"atom",style:"upright",text:r};if(To.includes(t))return{kind:"atom",style:"upright",text:t};const s=_o[t];if(void 0!==s)return{kind:"space",width:s};const l=qo[`\\${t}`];if(void 0!==l)return{kind:"atom",style:"upright",text:l};throw new Fo(`"\\${t}" is not supported yet`)}(e);if(zo.test(t))return e.take(),{kind:"atom",style:Ho.test(t)?"upright":"italic",text:t};throw new Fo(`"${t}" is not a character this engine understands`)}function Zo(e){if(e.skipSpace(),"{"!==e.peek()){const t=Xo(e);if(null===t)throw new Fo("a command is missing its argument");return t}e.take();const t=Vo(e,"}");if("}"!==e.peek())throw new Fo("a { group is never closed");return e.take(),t}function Yo(e){if(e.skipSpace(),"{"!==e.peek())throw new Fo("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 Fo("a text command’s { group is never closed")}function Qo(e,t){e.skipSpace();const n=e.peek();if("\\"===n){const t=e.readCommand(),n=qo[`\\${t}`];if(void 0===n)throw new Fo(`"\\${t}" is not a delimiter this engine understands`);return n}const a=qo[n];if(void 0===a)throw new Fo(`\\${t} is missing a delimiter`);return e.take(),a}var ei={bold:{style:"normal",weight:"700"},italic:{style:"italic",weight:"400"},text:{style:"normal",weight:"400"},upright:{style:"normal",weight:"400"}};function ti(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 ni(e,t=me){const n=e.width+16,a=e.height+e.depth+16,o=e.height+8,i=ti("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=ei[r.style],n=ti("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(ai(r,o,t)):i.append(ti("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 ai(e,t,n){const a=e.x+8,o=t+e.y-e.height,i=t+e.y,r=.32*e.size;return ti("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 oi=72,ii=40,ri=28,si=16;function li(e){return"flowchart"===e.kind?function(e){const t="LR"===e.direction||"RL"===e.direction,n=function(e){const t=/* @__PURE__ */new Map;for(const a of e.nodes)t.set(a.id,0);const n=function(e){const t=/* @__PURE__ */new Map;for(const o of e.edges)t.set(o.from,[...t.get(o.from)??[],o]);const n=/* @__PURE__ */new Map,a=/* @__PURE__ */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=/* @__PURE__ */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=/* @__PURE__ */new Map;for(const b of e.nodes)o.set(b.id,ci(b.label,oi));const i=/* @__PURE__ */new Map,r=[...a.keys()].sort((e,t)=>e-t),s=e=>t?e.length*ii+(e.length-1)*ri:e.reduce((e,t)=>e+(o.get(t)??oi),0)+(e.length-1)*ri,l=Math.max(...r.map(e=>s(a.get(e)??[])),0);for(const b of r){const n=a.get(b)??[],r=si+b*((t?oi:ii)+64);let c=si+(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)??oi;i.set(a,{height:ii,id:a,label:n.label,shape:n.shape,width:s,x:t?r:c,y:t?c:r}),c+=(t?ii:s)+ri}}const c=e.nodes.map(e=>i.get(e.id)).filter(e=>void 0!==e),d=Math.max(...c.map(e=>e.x+e.width),0),p=Math.max(...c.map(e=>e.y+e.height),0),u=(t?p:d)+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?d:Math.max(d,h?u:0);return{edges:m,height:(t?Math.max(p,h?u:0):p)+si,kind:"flowchart",nodes:c,width:g+si}}(e):function(e){const t=[];let n=si;for(const m of e.participants){const e=ci(m.label,96);t.push({actor:m.actor,centerX:n+e/2,headHeight:36,headWidth:e,id:m.id,label:m.label}),n+=e+ri}const a=e=>t.find(t=>t.id===e)?.centerX??null,o=[],i=[],r=[],s=/* @__PURE__ */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=ci(m.text,96),n=Math.min(...e),o=Math.max(...e),r="left"===m.placement?n-t-ri:"right"===m.placement?o+ri:(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 d=l;for(const m of[...s.keys()])c(m,d);const p=Math.max(...i.map(e=>e.x+e.width),0),u=Math.max(n-ri+si,p+si);return{activations:r,height:d+si,kind:"sequence",lifelineBottom:d,lifelines:t,messages:o,notes:i,width:u}}(e)}function ci(e,t){return Math.max(t,Math.round(7.2*e.length)+32)}var di=["BT","LR","RL","TB","TD"],pi=["subgraph","end","click","style","classDef","class","linkStyle","direction"],ui=["loop","alt","else","opt","par","and","critical","option","break","rect","box","autonumber","end"],mi=[{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:"-.-"}],hi=[{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:"->"}],gi=[{close:"]]",open:"[[",shape:"subroutine"},{close:"])",open:"([",shape:"stadium"},{close:"))",open:"((",shape:"circle"},{close:"]",open:"[",shape:"rect"},{close:"}",open:"{",shape:"rhombus"},{close:")",open:"(",shape:"round"}],bi=e=>({ok:!1,reason:e});function fi(e){return e.split(/[\s(]/,1)[0]??""}function yi(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 bi("the block is empty");const[n,...a]=t,o=fi(n??"");return"sequenceDiagram"===o?function(e){const t=/* @__PURE__ */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=fi(o);if(ui.includes(e))return bi(`"${e}" is not supported yet`);if("participant"===e||"actor"===e){const n=Si(o,e);if(null===n)return bi(`"${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(!Ci(t))return bi(`"${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=Ei(o);if(null===e)return bi(`"${o}" is not a note this engine understands`);for(const t of e.targets)a(t);n.push(e);continue}const i=Ai(o);if(null===i)return bi(`"${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(fi(e).length).trim();if(0===n.length)return bi('the flowchart header is missing a direction, e.g. "flowchart TD"');const a=di.find(e=>e===n);if(void 0===a)return bi(`"${n}" is not a supported direction — use TD, TB, BT, LR or RL`);const o=/* @__PURE__ */new Map,i=[];for(const r of t){const e=fi(r);if(pi.includes(e))return bi(`"${e}" is not supported yet`);if(r.includes("&"))return bi('"&" fan-out is not supported yet');const t=vi(r,o,i);if(null!==t)return bi(t)}return{model:{direction:a,edges:i,kind:"flowchart",nodes:[...o.values()]},ok:!0}}(n??"",a):bi(`"${o}" diagrams are not supported yet — only flowchart and sequenceDiagram are`)}function vi(e,t,n){const a=function(e){const t=[],n=[];let a=e.trim();for(let o=0;o<64;o+=1){const e=xi(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=wi(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 xi(e){const t=function(e){const t=/--\s+([^->|][^-]*?)\s+(-->|---|-\.->|-\.-|==>|===)/.exec(e);if(null===t||void 0===t.index)return null;const n=mi.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 mi){const t=e.indexOf(a.token);if(-1===t)continue;if(null!==n&&t>=n.at)continue;const o=ki(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 ki(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 wi(e){const t=e.trim();if(0===t.length)return null;for(const n of gi){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(Ci(a))return{id:a,label:o.trim(),shape:n.shape}}return Ci(t)?{id:t,label:t,shape:"rect"}:null}function Ci(e){return/^[A-Za-z_][\w-]*$/.test(e)}function Si(e,t){const n=e.slice(t.length).trim(),a=/ as /.exec(n),o=(null===a?n:n.slice(0,a.index)).trim();if(!Ci(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 Ei(e){const t=e.slice(fi(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(Ci)?{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 Ci(s)?{kind:"note",placement:(r[1]??"").toLowerCase(),targets:[s],text:o}:null}function Ai(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 hi){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(Ci(t)&&Ci(s))return{activate:"+"===r,deactivate:"-"===r,end:o.end,from:t,kind:"message",line:o.line,text:a,to:s}}return null}var Ni={dotted:"5 4",solid:"",thick:""},Li={dotted:1.5,solid:1.5,thick:3};function Bi(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 $i(e,t,n,a,o){const i=Bi("text",{class:a,"dominant-baseline":"middle","text-anchor":"middle",x:t,y:n},o);return i.setText(e),i}function Ii(e,t=me){const n=Bi("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=Bi("defs",{},e),n=Bi("marker",{id:"clepit-mermaid-arrow",markerHeight:7,markerUnits:"strokeWidth",markerWidth:7,orient:"auto-start-reverse",refX:7,refY:3.5},e);return n.append(Bi("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)Mi(e,a,n);for(const a of t.nodes)Ti(e,a,n)}(n,e,t):function(e,t,n){for(const a of t.lifelines){e.append(Bi("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(Bi("rect",o,n)),e.append($i(a.label,a.centerX,16+a.headHeight/2,"clepit-typeset__label",n))}for(const a of t.activations)e.append(Bi("rect",{class:"clepit-typeset__activation",height:a.height,width:a.width,x:a.x,y:a.y},n));for(const a of t.messages)_i(e,a,n);for(const a of t.notes)e.append(Bi("rect",{class:"clepit-typeset__note",height:a.height,width:a.width,x:a.x,y:a.y},n)),e.append($i(a.text,a.x+a.width/2,a.y+a.height/2,"clepit-typeset__label",n))}(n,e,t),n}function Ti(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 Bi("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 Bi("polygon",{...s,points:e},t)}if("stadium"===a)return Bi("rect",{...s,height:n,rx:n/2,ry:n/2,width:o,x:i,y:r},t);if("round"===a)return Bi("rect",{...s,height:n,rx:10,ry:10,width:o,x:i,y:r},t);if("subroutine"===a){const e=Bi("g",{},t);return e.append(Bi("rect",{...s,height:n,rx:8,ry:8,width:o,x:i,y:r},t)),e.append(Bi("line",{...s,x1:i+6,x2:i+6,y1:r,y2:r+n},t)),e.append(Bi("line",{...s,x1:i+o-6,x2:i+o-6,y1:r,y2:r+n},t)),e}return Bi("rect",{...s,height:n,rx:8,ry:8,width:o,x:i,y:r},t)}(t,n)),e.append($i(t.label,t.x+t.width/2,t.y+t.height/2,"clepit-typeset__label",n))}function Mi(e,t,n){const[a,o]=t.points;if(void 0===a||void 0===o)return;const i=t.points.length>2?Bi("polyline",{class:"clepit-typeset__edge",fill:"none",points:t.points.map(e=>`${e.x},${e.y}`).join(" "),"stroke-dasharray":Ni[t.line],"stroke-width":Li[t.line]},n):Bi("line",{class:"clepit-typeset__edge","stroke-dasharray":Ni[t.line],"stroke-width":Li[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=$i(t.label,t.labelX,t.labelY,"clepit-typeset__edge-label",n);a.setAttribute("paint-order","stroke"),e.append(a)}}function _i(e,t,n){const a={class:"clepit-typeset__message","stroke-dasharray":Ni[t.line],"stroke-width":Li[t.line]};if(t.selfCall){const o=`M ${t.fromX} ${t.y} h 28 v 18 h -28`,i=Bi("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($i(t.text,t.fromX+52,t.y+9,"clepit-typeset__edge-label",n))}const o=Bi("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(Bi("line",{...a,x1:o-5,x2:o+5,y1:t.y-5,y2:t.y+5},n)),e.append(Bi("line",{...a,x1:o-5,x2:o+5,y1:t.y+5,y2:t.y-5},n))}e.append($i(t.text,(t.fromX+t.toX)/2,t.y-8,"clepit-typeset__edge-label",n))}var qi=class e{static render(t,n,a,o,i){if(l.injectStyles("typeset-output",ko),!e.validate(n))return ke();const r=l.createStyledElement("div",`clepit-typeset clepit-output-typeset clepit-typeset--${t.toLowerCase()}`,{classNames:i?.wrapper,styles:o?.wrapper});if(r.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"),r.appendChild(e)}if("Mermaid"===t){const a=yi(n.source);return a.ok?(r.setAttribute("data-rendered","diagram"),r.appendChild(xe(Ii(li(a.model)))),r):e.appendFallback(r,n.source,a.reason,t)}if(0===n.source.trim().length)return e.appendFallback(r,n.source,null,t);const s=Uo(n.source);return s.ok?(r.setAttribute("data-rendered","formula"),r.appendChild(xe(ni(Eo(s.root)))),r):e.appendFallback(r,n.source,s.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=me){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=yi(n.source);return r.ok?(o.setAttribute("data-rendered","diagram"),i(),o.append(Ii(li(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=Uo(n.source);return r.ok?(o.setAttribute("data-rendered","formula"),i(),o.append(ni(Eo(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)}},Di=class{static render(e,t,n,a){return qi.render("LaTeX",e,t,n,a)}static draw(e,t=me){return qi.draw("LaTeX",e,t)}},ji=class{static render(e,t,n,a){return qi.render("Mermaid",e,t,n,a)}static draw(e,t=me){return qi.draw("Mermaid",e,t)}},zi="\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",Oi=zi,Hi=zi,Pi=class{static render(e,t,n,a){l.injectStyles("updates-output",Hi);const o=l.createStyledElement("div","clepit-updates clepit-output-updates",{classNames:a?.wrapper,styles:n?.wrapper});e?.pageId&&o.setAttribute("data-page-id",e.pageId);const i=document.createElement("span");i.className="clepit-updates__icon",i.textContent="🕘",o.appendChild(i);const r=document.createElement("span");return r.className="clepit-updates__label",r.textContent="Updates",o.appendChild(r),o}static draw(e,t=me){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}},Ri=`\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.${l.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.${l.classNames.block.videoDeleteBtn}:hover {\n color: var(--clepit-error);\n}\n\n/* Video drop area delete button */\n.clepit-video-drop-area .${l.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 .${l.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`,Fi="\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",Ui=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"),a=e.querySelector(`.${l.classNames.block.video.captionEditable}`),o=e.querySelector(`.${l.classNames.block.video.wrapper}`);let i="center";o&&(i=o.classList.contains("clepit-video-wrapper--left")?"left":o.classList.contains("clepit-video-wrapper--right")?"right":"center");let r="",s="";return t?(r=t.getAttribute("src")||"",s=t.getAttribute("alt")||""):n&&(r=n.getAttribute("src")||"",s="Embedded video"),{alignment:i,alt:s,caption:j(a?.innerHTML),url:r}}static render(t,n,a,o){l.injectStyles("clepit-video-input-styles",Ri);const i=a||{alt:"",caption:"",url:""},r=l.createStyledElement("div",l.classNames.block.video.container,{classNames:o?.classNames?.container,styles:o?.styles?.container});return i.url?e.renderVideo(r,i,t,n,o):e.renderDropArea(r,t,n,o),r}static renderVideo(t,n,a,o,i){t.innerHTML="";const r=l.createStyledElement("div",l.classNames.block.video.wrapper,{classNames:i?.classNames?.container,styles:i?.styles?.container});switch(r.setAttribute("tabindex","-1"),n?.alignment||"center"){case"left":r.classList.add("clepit-video-wrapper--left");break;case"center":r.classList.add("clepit-video-wrapper--center");break;case"right":r.classList.add("clepit-video-wrapper--right")}const s=an(n?.url||""),c=on(n?.url||"");if(s||c){const e=l.createStyledElement("iframe",l.classNames.block.video.iframe,{classNames:i?.classNames?.container,styles:i?.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",r.appendChild(e)}else{const e=l.createStyledElement("video",l.classNames.block.video.video,{classNames:i?.classNames?.container,styles:i?.styles?.container});e.setAttribute("alt",n?.alt||""),e.src=n?.url||"",e.controls=!0,r.appendChild(e)}const d=l.createStyledElement("div","clepit-video-caption-container",{classNames:i?.classNames?.caption,styles:i?.styles?.caption});d.classList.add("clepit-video-caption-container");const p=l.createStyledElement("div",l.classNames.block.video.captionEditable,{classNames:i?.classNames?.caption,styles:i?.styles?.caption});p.setAttribute("contenteditable","true"),p.setAttribute("data-placeholder",e.placeholder),p.innerHTML=n?.caption||"",e.addEventListener(o,p,"input",Qr.handleInput),e.addEventListener(o,p,"keydown",Qr.handleKeydown),e.addEventListener(o,r,"click",()=>e.handleFileSelect(t,a,o,i)),d.appendChild(p),t.appendChild(r),t.appendChild(d),p.focus()}static renderDropArea(t,n,a,o){t.innerHTML="";const i=l.createStyledElement("div",l.classNames.block.video.dropArea,{classNames:o?.classNames?.dropArea?.container,styles:o?.styles?.dropArea?.container});i.setAttribute("tabindex","0"),i.classList.add("clepit-drop-area");const r=l.createStyledElement("div","clepit-video-drop-icon",{classNames:o?.classNames?.dropArea?.icon,styles:o?.styles?.dropArea?.icon});r.textContent="🎥";const s=l.createStyledElement("div","clepit-video-drop-text",{classNames:o?.classNames?.dropArea?.text,styles:o?.styles?.dropArea?.text});s.innerHTML='<strong>Drop a video here</strong><br>or <span class="clepit-video-click-text">click to select</span>';const c=l.createStyledElement("button",`${l.classNames.block.videoDeleteBtn}`,{classNames:o?.classNames?.dropArea?.deleteButton,styles:o?.styles?.dropArea?.deleteButton});c.type="button",c.textContent="✕",i.appendChild(r),i.appendChild(s),i.appendChild(c),e.addEventListener(a,c,"click",e=>{e.preventDefault(),e.stopPropagation();const t=c.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id");t&&Qr.removeBlock(a,Qr.getBlockIndex(a,t))}),e.addEventListener(a,i,"click",()=>e.handleFileSelect(t,n,a,o)),e.addEventListener(a,i,"dragleave",()=>{i.classList.remove("clepit-video-drop-area--dragover")}),e.addEventListener(a,i,"dragover",e=>{e.preventDefault(),e.stopPropagation(),i.classList.add("clepit-video-drop-area--dragover")}),e.addEventListener(a,i,"drop",r=>{r.preventDefault(),r.stopPropagation(),i.classList.remove("clepit-video-drop-area--dragover"),e.handleFileDrop(r,t,n,a,o)}),e.addEventListener(a,i,"focus",e=>{e.preventDefault(),e.stopPropagation()}),e.addEventListener(a,i,"mousedown",e=>{e.preventDefault(),e.stopPropagation()});const d=a?m.getState().getInstance(a):null,p=d?.config.classNames?.tooltips,u=d?.config.styles?.tooltips;ee(c,"Delete block","below",p,u),t.appendChild(i)}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,a,o,i){e.showLoading(n);try{let r=await a(t);if(r){e.renderVideo(n,{alignment:"center",alt:t.name,caption:"",url:r},a,o,i);const s=n.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id");s&&m.getState().updateBlockData(o,Qr.getBlockIndex(o,s),Qr.getBlockData(s).data)}else e.showError(n,"Failed to upload video. Please try again.")}catch(r){console.error("Video upload error:",r),e.showError(n,"Failed to upload video. Please try again.")}}static showLoading(e){e.innerHTML="";const t=l.createStyledElement("div","clepit-video-loading",void 0);t.textContent="Uploading video...",e.appendChild(t)}static showError(e,t){e.innerHTML="";const n=l.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=Qr.getEditorId(e);if(!a)return;const o=e.getAttribute("data-id");o&&m.getState().partialUpdateBlockData(a,Qr.getBlockIndex(a,o),{alignment:t})}static isEmpty(e){const t=e.querySelector(`.${l.classNames.block.video.wrapper} video`),n=e.querySelector(`.${l.classNames.block.video.wrapper} iframe`),a=e.querySelector(`.${l.classNames.block.video.captionEditable}`);let o=!1,i=!1,r=!1;return t&&t.getAttribute("src")?.trim()||(o=!0),n&&n.getAttribute("src")?.trim()||(i=!0),a?D(a.innerHTML)&&(r=!0):r=!0,o&&i&&r}static isEmptyData(e){return!e.url?.trim()&&D(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]=[])}},Vi=class e{static render(t,n,a,o){if(l.injectStyles("clepit-video-output-styles",Fi),!e.validate(t))return ke();if(Ui.isEmptyData(t))return document.createElement("div");const i=t.url,r=t.caption,s=t.alignment||"center",c=l.createStyledElement("div","clepit-output-video-container",{classNames:o?.container,styles:a?.container}),d=l.createStyledElement("div","clepit-output-video-wrapper");switch(s){case"left":d.classList.add("clepit-output-video-wrapper--left");break;case"center":d.classList.add("clepit-output-video-wrapper--center");break;case"right":d.classList.add("clepit-output-video-wrapper--right")}const p=an(i),u=on(i);if(p||u){const e=_("iframe","clepit-output-video-iframe");e.src=i,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",d.appendChild(e),c.appendChild(d)}else{const e=_("video","clepit-output-video");e.src=i,e.controls=!0,e.preload="metadata",e.style.maxWidth="100%",e.style.height="auto",e.style.display="block",d.appendChild(e),c.appendChild(d)}if(r){const e=l.createStyledElement("figcaption","clepit-output-video-caption",{classNames:o?.caption,styles:a?.caption}),n=t.caption;e.innerHTML=n&&n!==r?n:r,c.appendChild(e)}if(a&&(a.container&&Object.assign(c.style,a.container),a.caption)){const e=c.querySelector(".clepit-output-video-caption");e&&Object.assign(e.style,a.caption)}if(o&&(o.container&&c.classList.add(o.container),o.caption)){const e=c.querySelector(".clepit-output-video-caption");e&&e.classList.add(o.caption)}return c}static draw(t,n=me){if(!e.validate(t)||Ui.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}},Wi=(e,t,n)=>{const a=Ki(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},Ki=(e,t,n)=>{switch(e.type){case"alert":return dn.draw(e.data,t);case"audio":return gn.draw(e.data,t);case"checklist":return xn.draw(e.data,t);case"code":return Ue.draw(e.data,t,n);case"collapsible":return Ji.draw(e.data,t,n);case"collection":return In.draw(e.data,t);case"columns":return qn.draw(e.data,t,n);case"date":return Pn.draw(e.data,t);case"delimiter":return Un.draw(e.data,t);case"doc_card":return Gn.draw(e.data,t,n);case"embed":return Ot.draw(e.data,t,n);case"file":return Qn.draw(e.data,t);case"glance":return na.draw(e.data,t);case"header":return ia.draw(e.data,t);case"image":return ca.draw(e.data,t);case"issues":return ma.draw(e.data,t,n);case"latex":return Di.draw(e.data,t);case"list":return ba.draw(e.data,t);case"mermaid":return ji.draw(e.data,t);case"openapi":return Wa.draw(e.data,t);case"paragraph":return Ja.draw(e.data,t);case"quote":return Qa.draw(e.data,t);case"sketch":return ro.draw(e.data,t);case"table":return mo.draw(e.data,t);case"toc":return yo.draw(e.data,t,n);case"updates":return Pi.draw(e.data,t);case"video":return Vi.draw(e.data,t);default:return Gi(e)}},Gi=e=>(console.warn("drawBlock: no drawer for block",e),null),Ji=class e{static render(t,n,a,o){if(l.injectStyles("collapsible-output",En),!e.validate(t))return ke();const i=l.createStyledElement("details","clepit-collapsible clepit-output-collapsible",{classNames:o?.section,styles:a?.section});i.open=t.open??!1;const r=document.createElement("summary"),s=document.createElement("span");s.innerHTML=j(t.html),r.appendChild(s),i.appendChild(r);const c=document.createElement("div");c.className="clepit-collapsible__children";for(const l of t.children??[])c.appendChild(e.renderChild(l,n));return i.appendChild(c),i}static renderChild(e,t){const n=Fr.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=me,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=Wi(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))}},Xi={icon:"▸",get input(){return Nn},label:"Collapsible section",get output(){return Ji},shortcut:S("E"),testId:"block-type-collapsible",type:"collapsible"},Zi=/* @__PURE__ */new WeakMap,Yi=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=Zi.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){l.injectStyles("collection-input",Bn);const a=t??{collectionId:""},o=In.render(a,void 0,n?.styles,n?.classNames);return o.classList.add("clepit-collection--input"),o.setAttribute("contenteditable","false"),Zi.set(o,a),o}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]=[])}},Qi={icon:"▦",get input(){return Yi},label:"Collection",get output(){return In},shortcut:S("G"),testId:"block-type-collection",type:"collection"},er=/* @__PURE__ */new WeakMap;var tr=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=er.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 Fr.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,a){l.injectStyles("columns-input",Mn);const o=n&&Array.isArray(n.columns)&&n.columns.length>=2?n:{columns:[[],[]]},i=l.createStyledElement("div","clepit-columns clepit-columns--input",{classNames:a?.classNames?.container,styles:a?.styles?.container});return er.set(i,o.columns.map(e=>[...e])),o.columns.forEach(n=>{const o=l.createStyledElement("div","clepit-columns__column",{classNames:a?.classNames?.column,styles:a?.styles?.column});n.forEach(n=>{o.appendChild(e.renderChild(t,n))}),i.appendChild(o)}),i}static renderChild(e,t){const n=document.createElement("div");n.className="clepit-columns__child";const a=Qr.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]=[])}},nr={icon:"▥",get input(){return tr},label:"Columns",get output(){return qn},shortcut:S("L"),testId:"block-type-columns",type:"columns"},ar=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,a){l.injectStyles("date-input",jn);const o=l.createStyledElement("input","clepit-date clepit-date--input",{classNames:a?.classNames?.pill,styles:a?.styles?.pill});return o.type="date",n?.date&&Hn(n.date)&&(o.value=n.date),e.addEventListener(t,o,"keydown",e=>{e.stopPropagation()}),o}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]=[])}},or={icon:"▤",get input(){return ar},label:"Date",get output(){return Pn},shortcut:S("D"),testId:"block-type-date",type:"date"},ir={icon:"—",get input(){return Fn},label:"Delimiter",get output(){return Un},shortcut:S("D"),testId:"block-type-delimiter",type:"delimiter"},rr=/* @__PURE__ */new WeakMap,sr=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=rr.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){l.injectStyles("doc-card-input",Wn);const a=t??{pageId:"",title:""},o=Gn.render(a,void 0,n?.styles,n?.classNames);return o.classList.add("clepit-doc-card--input"),o.setAttribute("contenteditable","false"),rr.set(o,a),o}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]=[])}},lr={icon:"🗎",get input(){return sr},label:"Doc card",get output(){return Gn},shortcut:S("K"),testId:"block-type-doc-card",type:"doc_card"},cr={icon:"🔗",get input(){return Yt},label:"Embed",get output(){return Ot},shortcut:S("M"),testId:"block-type-embed",type:"embed"},dr=/* @__PURE__ */new WeakMap,pr=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=dr.get(t);if(e)return e}return{name:"",url:""}}static render(t,n,a,o){l.injectStyles("file-input",Xn);const i=document.createElement("div");return i.className="clepit-file-host",i.setAttribute("contenteditable","false"),a?.url&&a.name&&dr.set(i,a),e.renderState(i,t,n,o),i}static renderState(t,n,a,o){t.innerHTML="";const i=dr.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=Qn.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);dr.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]=[])}},ur={icon:"📎",get input(){return pr},label:"File",get output(){return Qn},shortcut:S("F"),testId:"block-type-file",type:"file"},mr={html:"",label:""},hr=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:j(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){l.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 a=t?.rows?.length?t:{rows:[mr]},o=na.render(a,void 0,n?.styles,n?.classNames);o.classList.add("clepit-glance--input");for(const i of o.querySelectorAll(".clepit-glance-label"))i.setAttribute("contenteditable","true"),i.setAttribute("data-placeholder","Label");for(const i of o.querySelectorAll(".clepit-glance-value"))i.setAttribute("contenteditable","true"),i.setAttribute("data-placeholder","Value");return o}static changeVariant(t,n,a){const o=m.getState().getInstance(a);if(!o)return;if((t.getAttribute("data-variant")??"plain")===n)return;const i=Qr.getBlockIndex(a,t.closest(`.${l.classNames.block.container}`)?.getAttribute("data-id")),r={...e.save(t),variant:n},s={classNames:o.config.classNames?.blocks?.glance,margins:o.config.margins,styles:o.config.styles?.blocks?.glance},c=e.render(a,r,s);t.replaceWith(c),m.getState().updateBlockData(a,i,r)}static isEmpty(t){return e.isEmptyData(e.save(t))}static isEmptyData(e){return!e?.rows?.length||e.rows.every(e=>""===e.label.trim()&&""===j(e.html).trim())}static destroy(e){}},gr={icon:"≡",get input(){return hr},label:"At a glance",get output(){return na},shortcut:S("N"),testId:"block-type-glance",type:"glance"},br={icon:"H",get input(){return oa},label:"Header",get output(){return ia},shortcut:S("H"),testId:"block-type-header",type:"header"},fr={icon:"𝑖",get input(){return la},label:"Image",get output(){return ca},shortcut:S("I"),testId:"block-type-image",type:"image"},yr={},vr=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){return{}}static render(e,t,n){l.injectStyles("issues-input",da);const a=m.getState().getInstance(e)?.config,o=m.getState().getData(e)?.blocks??[],i=ma.render({},{documentBlocks:o,issueLabels:a?.issueLabels,issues:yr[e]},n?.styles,n?.classNames);return i.classList.add("clepit-issues--input"),i.setAttribute("contenteditable","false"),i}static refresh(t,n){yr[t]={...yr[t],...n};const a=document.getElementById(t);if(a)for(const o of Array.from(a.querySelectorAll(`.${l.classNames.block.container}[data-tool="issues"]`))){const n=o.querySelector(`.${l.classNames.block.content}`);if(!n)continue;const a=m.getState().getInstance(t),i={classNames:a?.config.classNames?.blocks?.issues,styles:a?.config.styles?.blocks?.issues};n.replaceChildren(e.render(t,{},i))}}static isEmpty(e){return!1}static isEmptyData(e){return!1}static destroy(t){delete yr[t];const n=e.eventListenersMap[t];n&&(n.forEach(({element:e,event:t,handler:n})=>e.removeEventListener(t,n)),e.eventListenersMap[t]=[])}},xr={icon:"☑",get input(){return vr},label:"Linked issues",get output(){return ma},shortcut:S("J"),testId:"block-type-issues",type:"issues"},kr={icon:"•",get input(){return ga},label:"List",get output(){return ba},shortcut:S("L"),testId:"block-type-list",type:"list"},wr="clepit-openapi__source",Cr=(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??{}}},Sr=class e{static{this.placeholder="Paste an OpenAPI document, or a URL to one…"}static{this.dataMap=/* @__PURE__ */new WeakMap}static render(t,n,a){l.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 o=_("div","clepit-openapi-input"),i=_("div",wr);i.setAttribute("contenteditable","true"),i.setAttribute("data-placeholder",e.placeholder),i.setAttribute("data-testid","openapi-source"),i.textContent=n?.url??(n?.spec?JSON.stringify(n.spec,null,2):"");const r=_("div","clepit-openapi-input__preview");return r.setAttribute("data-testid","openapi-preview"),n&&r.appendChild(Wa.render(n)),i.addEventListener("input",()=>{const t=Cr(i.textContent??"",e.dataMap.get(o));e.dataMap.set(o,t),r.replaceChildren(Wa.render(t))}),n&&e.dataMap.set(o,n),o.appendChild(i),o.appendChild(r),o}static save(t){const n=(e=>e.classList.contains(wr)?e:e.querySelector(`.${wr}`))(t),a=t.classList.contains("clepit-openapi-input")?t:t.querySelector(".clepit-openapi-input"),o=a?e.dataMap.get(a):void 0;return Cr(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){}},Er={icon:"⇄",get input(){return Sr},label:"API reference",get output(){return Wa},shortcut:S("A"),testId:"block-type-openapi",type:"openapi"},Ar={icon:"¶",get input(){return Ga},label:"Paragraph",get output(){return Ja},shortcut:S("P"),testId:"block-type-paragraph",type:"paragraph"},Nr={icon:"“",get input(){return Ya},label:"Quote",get output(){return Qa},shortcut:S("Q"),testId:"block-type-quote",type:"quote"},Lr=/* @__PURE__ */new WeakMap,Br=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?Lr.get(t):void 0)??{strokes:[]}}static render(t,n,a){l.injectStyles("sketch-input",to);const o=n??{strokes:[]},i=ro.render(o,void 0,a?.styles,a?.classNames);return i.classList.add("clepit-sketch--input"),i.setAttribute("contenteditable","false"),Lr.set(i,o),e.attachDrawing(t,i),i}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=Lr.get(n)??{strokes:[]},t=o&&o.length>=4?{strokes:[...e.strokes,{points:o}]}:e,i=ro.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=Lr.get(n)??{strokes:[]};Lr.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]=[])}},$r={icon:"✏️",get input(){return Br},label:"Sketch",get output(){return ro},shortcut:S("W"),testId:"block-type-sketch",type:"sketch"},Ir={icon:"⊞",get input(){return co},label:"Table",get output(){return mo},shortcut:S("T"),testId:"block-type-table",type:"table"},Tr=class e{static{this.placeholder=""}static{this.eventListenersMap={}}static save(e){return{}}static render(e,t,n){l.injectStyles("toc-input",go);const a=m.getState().getData(e)?.blocks??[],o=yo.render({},{documentBlocks:a},n?.styles,n?.classNames);return o.classList.add("clepit-toc--input"),o.setAttribute("contenteditable","false"),o}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]=[])}},Mr={icon:"≡",get input(){return Tr},label:"Table of contents",get output(){return yo},shortcut:S("T"),testId:"block-type-toc",type:"toc"},_r={latex:"LaTeX",mermaid:"Mermaid"};function qr(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 Dr(e,t,n){l.injectStyles("typeset-input",xo);const a=t??{source:""},o=l.createStyledElement("div",`clepit-typeset clepit-output-typeset clepit-typeset--input clepit-typeset--${e}`,{classNames:n?.classNames?.wrapper,styles:n?.styles?.wrapper});o.setAttribute("data-language",e),o.setAttribute("data-rendered","source");const i=_("span","clepit-typeset__kind");i.textContent=_r[e],o.appendChild(i);const r=_("span","clepit-typeset__title");r.setAttribute("data-testid","typeset-title"),r.setAttribute("contenteditable","true"),r.setAttribute("data-placeholder","mermaid"===e?"What does this diagram show?":"What does this formula show?"),r.textContent=a.title??"",o.appendChild(r);const s=_("pre","clepit-typeset__source");return s.setAttribute("contenteditable","true"),s.textContent=a.source,o.appendChild(s),o}var jr=class{static{this.placeholder=""}static save(e){return qr(e)}static render(e,t,n){return Dr("latex",t,n)}static isEmpty(e){return""===qr(e).source.trim()}static isEmptyData(e){return!e.source.trim()}static destroy(e){}},zr=class{static{this.placeholder=""}static save(e){return qr(e)}static render(e,t,n){return Dr("mermaid",t,n)}static isEmpty(e){return""===qr(e).source.trim()}static isEmptyData(e){return!e.source.trim()}static destroy(e){}},Or={icon:"∑",get input(){return jr},label:"LaTeX",get output(){return Di},shortcut:S("X"),testId:"block-type-latex",type:"latex"},Hr={icon:"◈",get input(){return zr},label:"Mermaid",get output(){return ji},shortcut:S("Y"),testId:"block-type-mermaid",type:"mermaid"},Pr=/* @__PURE__ */new WeakMap,Rr=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=Pr.get(t);if(e)return e;const n=t.getAttribute("data-page-id");if(n)return{pageId:n}}return{}}static render(e,t,n){l.injectStyles("updates-input",Oi);const a=t??{},o=Pi.render(a,void 0,n?.styles,n?.classNames);return o.classList.add("clepit-updates--input"),o.setAttribute("contenteditable","false"),Pr.set(o,a),o}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]=[])}},Fr=[pn,bn,kn,wn,Xi,Qi,{icon:"🕘",get input(){return Rr},label:"Updates",get output(){return Pi},shortcut:S("U"),testId:"block-type-updates",type:"updates"},nr,or,ir,lr,cr,ur,gr,br,fr,xr,kr,Er,Ar,Nr,$r,Or,Hr,Ir,Mr,{icon:"▶",get input(){return Ui},label:"Video",get output(){return Vi},shortcut:S("V"),testId:"block-type-video",type:"video"}],Ur="clepit-block-type-selector",Vr="clepit-code-language-submenu",Wr="clepit-code-theme-submenu",Kr="clepit-convert-submenu",Gr="clepit-block-operations-menu";function Jr(e){return oe.includes(e)}function Xr(e,t,n){return e?.[t]??n}var Zr,Yr=class e{static{this.defaultClassName="clepit-block-toolbar"}static{this.menuAnchor="--clepit-block-toolbar"}static{this.submenuAnchorSeq=0}static{this.eventListenersMap=/* @__PURE__ */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 a=m.getState().getInstance(t);if(!a)return console.error("BlockToolbar::create: Instance not found for containerId:",t);const o=document.getElementById(t);if(!o)return console.error("BlockToolbar::create: Container not found for containerId:",t);e.eventListenersMap.has(o)||e.eventListenersMap.set(o,[]);const i=void 0!==a.config.audioUploader,r=void 0!==a.config.imageUploader,s=void 0!==a.config.videoUploader,c=a.config.classNames?.blockToolbar,d=a.config.classNames?.blockTypeMenu,p=a.config.classNames?.convertSubmenu,u=a.config.classNames?.operationsMenu,h=a.config.styles?.blockToolbar,g=a.config.styles?.blockTypeMenu,b=a.config.styles?.convertSubmenu,f=a.config.styles?.operationsMenu;e.remove(n),l.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=_("div",e.defaultClassName);y.id=`${t}-block-toolbar`,y.innerHTML="",l.applyStyling(y,{classNames:c?.container,styles:h?.container});const v=_("button","clepit-block-toolbar-add",{"data-testid":"toolbar-add-button",type:"button"});v.innerHTML="+",l.applyStyling(v,{classNames:c?.button,styles:h?.button}),e.addEventListener(o,v,"click",()=>e.showBlockTypeMenu({audioIsEnabled:i,block:n,classNames:d,containerId:t,imageIsEnabled:r,menuLabels:a.config.blockToolbarLabels,styles:g,toolLabels:a.config.blockToolLabels,videoIsEnabled:s}));const x=_("button","clepit-block-toolbar-ops",{"data-testid":"toolbar-operations-button",type:"button"});x.innerHTML="⋯",l.applyStyling(x,{classNames:c?.button,styles:h?.button}),e.addEventListener(o,x,"click",()=>e.showOperationsMenu({audioIsEnabled:i,block:n,classNames:u,containerId:t,convertSubmenuClassNames:p,convertSubmenuStyles:b,imageIsEnabled:r,operationLabels:a.config.blockToolbarLabels,styles:f,toolLabels:a.config.blockToolLabels,videoIsEnabled:s})),y.appendChild(v),y.appendChild(x),e.addEventListener(o,y,"click",e=>e.stopPropagation()),n.appendChild(y)}static showBlockTypeMenu({containerId:t,block:n,imageIsEnabled:a,videoIsEnabled:o,audioIsEnabled:i,classNames:r,styles:s,menuLabels:c,toolLabels:d}){e.closeAllMenus();const p=document.querySelector(`.${Ur}`);if(p)return p.classList.remove(`${Ur}--visible`),p.classList.add(`${Ur}--hidden`),void setTimeout(()=>p.remove(),200);const u=_("div",Ur);l.applyStyling(u,{classNames:r?.container,styles:s?.container});const m=_("input","",{placeholder:Xr(c,"searchBlocks","Search blocks..."),type:"text"});m.setAttribute("data-testid","block-type-search"),l.applyStyling(m,{classNames:r?.input,styles:s?.input}),u.appendChild(m);const h=document.querySelector(`#${t}`),g=_("div",`${Ur}-items`),b=c=>{g.innerHTML="",c.forEach(c=>{if("image"===c.type&&!a)return;if("video"===c.type&&!o)return;if("audio"===c.type&&!i)return;const p=_("div","clepit-menu-item clepit-block-type-item");p.setAttribute("data-testid",`block-type-${c.type}`),l.applyStyling(p,{classNames:r?.item?.container,styles:s?.item?.container});const m=_("span","clepit-menu-icon "+("image"===c.type?"clepit-menu-icon--italic":""));m.textContent=c.icon,l.applyStyling(m,{classNames:r?.item?.icon,styles:s?.item?.icon}),p.appendChild(m);const b=_("span","clepit-menu-label");if(b.textContent=(Jr(c.type)?d?.[c.type]:void 0)??c.label,l.applyStyling(b,{classNames:r?.item?.text,styles:s?.item?.text}),p.appendChild(b),c.shortcut){const e=_("span","clepit-menu-shortcut");e.textContent=c.shortcut,l.applyStyling(e,{classNames:r?.item?.shortcut,styles:s?.item?.shortcut}),p.appendChild(e)}e.addEventListener(h,p,"click",e=>{if(e.stopPropagation(),n){const e=Qr.getBlockIndex(t,n.getAttribute("data-id")||"");Qr.insertBlock({data:{html:""},type:c.type},t,e+1)}u.hidePopover()}),g.appendChild(p)})};if(b(Fr),e.addEventListener(h,m,"click",e=>e.stopPropagation()),e.addEventListener(h,m,"focus",e=>e.stopPropagation()),e.addEventListener(h,m,"input",()=>{const e=m.value.toLowerCase(),t=Fr.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e));if(b(t),0===t.length&&""!==e.trim()){const e=_("div","clepit-not-found-message",{style:"padding: 8px 12px; color: #666; font-style: italic; text-align: center;"});e.textContent=Xr(c,"noBlockTypesFound","No block types found"),g.appendChild(e)}}),e.addEventListener(h,m,"keydown",e=>{"Escape"===e.key&&u.hidePopover()}),u.appendChild(g),u.classList.add(Ur),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(`${Ur}--visible`),m.focus(),e.addDocumentEventListener("click",e=>{const t=e.target;u.contains(t)||n?.contains(t)||u.remove()})):u.showPopover()}static showOperationsMenu({containerId:t,block:n,classNames:a,styles:o,convertSubmenuClassNames:i,convertSubmenuStyles:r,imageIsEnabled:s,videoIsEnabled:c,audioIsEnabled:d,operationLabels:p,toolLabels:u}){e.closeAllMenus();const m=_("div",Gr);o?.container&&l.applyStyling(m,{classNames:a?.container,styles:o.container}),a?.container&&m.classList.add(a.container);const h=_("input","",{placeholder:Xr(p,"searchOperations","Search operations..."),type:"text"});h.setAttribute("data-testid","operations-search"),l.applyStyling(h,{classNames:a?.input,styles:o?.input}),m.appendChild(h);const g=document.querySelector(`#${t}`),b=_("div",`${Gr}-items`),f=n.getAttribute("data-tool");if(!f)return;const y=(e,t)=>Xr(p,e,t),v=[{hasSubmenu:!0,icon:"↻",label:y("convert","Convert To"),testId:"operation-convert",value:"convert"},{icon:"↑",label:y("moveUp","Move Up"),shortcut:"⌘⇧↑",testId:"operation-moveUp",value:"moveUp"},{icon:"↓",label:y("moveDown","Move Down"),shortcut:"⌘⇧↓",testId:"operation-moveDown",value:"moveDown"},{icon:"×",label:y("delete","Delete"),shortcut:"⌘⇧⌫",testId:"operation-delete",value:"delete"}],x=[{icon:"←",label:y("alignLeft","Align Left"),testId:"image-align-left",value:"imageAlignLeft"},{icon:"↔",label:y("alignCenter","Align Center"),testId:"image-align-center",value:"imageAlignCenter"},{icon:"→",label:y("alignRight","Align Right"),testId:"image-align-right",value:"imageAlignRight"}],k=[{icon:"←",label:y("alignLeft","Align Left"),testId:"video-align-left",value:"videoAlignLeft"},{icon:"↔",label:y("alignCenter","Align Center"),testId:"video-align-center",value:"videoAlignCenter"},{icon:"→",label:y("alignRight","Align Right"),testId:"video-align-right",value:"videoAlignRight"}],w=[{icon:"←",label:y("alignLeft","Align Left"),testId:"audio-align-left",value:"audioAlignLeft"},{icon:"↔",label:y("alignCenter","Align Center"),testId:"audio-align-center",value:"audioAlignCenter"},{icon:"→",label:y("alignRight","Align Right"),testId:"audio-align-right",value:"audioAlignRight"}],C=[{hasSubmenu:!0,icon:"⌘",label:y("codeLanguage","Language"),testId:"code-language",value:"codeLanguage"},{hasSubmenu:!0,icon:"◆",label:y("codeTheme","Theme"),testId:"code-theme",value:"codeTheme"}],S="embed"===f&&Yt.save(n).issue?[{icon:"▭",label:y("embedShowChip","Show as chip"),testId:"embed-show-chip",value:"embedShowChip"},{icon:"↗",label:y("embedShowLink","Show as link"),testId:"embed-show-link",value:"embedShowLink"},{icon:"⧉",label:y("embedCopyLink","Copy link"),testId:"embed-copy-link",value:"embedCopyLink"}]:[{icon:"▣",label:y("embedShowLive","Show live"),testId:"embed-show-live",value:"embedShowLive"},{icon:"▭",label:y("embedShowCard","Show as card"),testId:"embed-show-card",value:"embedShowCard"},{icon:"↗",label:y("embedShowLink","Show as link"),testId:"embed-show-link",value:"embedShowLink"},{icon:"⧉",label:y("embedCopyLink","Copy link"),testId:"embed-copy-link",value:"embedCopyLink"}];v.forEach(h=>{const f=_("div","clepit-menu-item clepit-block-operation-item");f.setAttribute("data-testid",`operation-${h.value}`),l.applyStyling(f,{classNames:a?.item?.container,styles:o?.item?.container}),f.setAttribute("data-testid",h.testId);const y=_("span","clepit-menu-icon");y.textContent=h.icon,l.applyStyling(y,{classNames:a?.item?.icon,styles:o?.item?.icon}),f.appendChild(y);const v=_("span","clepit-menu-label");if(v.textContent=h.label,l.applyStyling(v,{classNames:a?.item?.text,styles:o?.item?.text}),f.appendChild(v),h.shortcut){const e=_("span","clepit-menu-shortcut");e.textContent=h.shortcut,l.applyStyling(e,{classNames:a?.item?.shortcut,styles:o?.item?.shortcut}),f.appendChild(e)}if(h.hasSubmenu){const e=_("span","clepit-menu-arrow");e.textContent="›",f.appendChild(e)}"delete"===h.value&&(f.classList.add("clepit-block-toolbar--delete-enabled"),1===g.querySelectorAll(".clepit-block").length&&(f.classList.add("clepit-block-toolbar--delete-disabled"),f.title="Cannot delete the last block")),e.addEventListener(g,f,"click",a=>{a.stopPropagation(),h.hasSubmenu?(document.querySelector(`.${Vr}`)?.remove(),document.querySelector(`.${Wr}`)?.remove(),e.showConvertSubmenu({audioIsEnabled:d,block:n,classNames:i,containerId:t,imageIsEnabled:s,menuLabels:p,parentItem:f,parentMenu:m,styles:r,toolLabels:u,videoIsEnabled:c})):(e.handleOperationSelect(h.value,n,t),m.remove())}),b.appendChild(f)});const E=()=>{const e=_("div","clepit-menu-divider");l.applyStyling(e,{classNames:a?.divider,styles:o?.divider}),b.appendChild(e)};if("image"===f&&(E(),x.forEach(i=>{const r=_("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(r,{classNames:a?.item?.container,styles:o?.item?.container}),r.setAttribute("data-testid",i.testId);const s=_("span","clepit-menu-icon");s.textContent=i.icon,l.applyStyling(s,{classNames:a?.item?.icon,styles:o?.item?.icon}),r.appendChild(s);const c=_("span","clepit-menu-label");if(c.textContent=i.label,l.applyStyling(c,{classNames:a?.item?.text,styles:o?.item?.text}),r.appendChild(c),i.value.startsWith("imageAlign")){const e=n.querySelector(".clepit-image-wrapper");if(e){const t=e.style.textAlign;("left"===t?"left":"right"===t?"right":"center")===i.value.replace("imageAlign","").toLowerCase()&&r.classList.add("active")}}e.addEventListener(g,r,"click",a=>{a.stopPropagation(),e.handleOperationSelect(i.value,n,t),m.remove()}),b.appendChild(r)})),"video"===f&&(E(),k.forEach(i=>{const r=_("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(r,{classNames:a?.item?.container,styles:o?.item?.container}),r.setAttribute("data-testid",i.testId);const s=_("span","clepit-menu-icon");s.textContent=i.icon,l.applyStyling(s,{classNames:a?.item?.icon,styles:o?.item?.icon}),r.appendChild(s);const c=_("span","clepit-menu-label");if(c.textContent=i.label,l.applyStyling(c,{classNames:a?.item?.text,styles:o?.item?.text}),r.appendChild(c),i.value.startsWith("videoAlign")){const e=n.querySelector(".clepit-video-wrapper");if(e){const t=e.style.textAlign;("left"===t?"left":"right"===t?"right":"center")===i.value.replace("videoAlign","").toLowerCase()&&r.classList.add("active")}}e.addEventListener(g,r,"click",a=>{a.stopPropagation(),e.handleOperationSelect(i.value,n,t),m.remove()}),b.appendChild(r)})),"audio"===f&&(E(),w.forEach(i=>{const r=_("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(r,{classNames:a?.item?.container,styles:o?.item?.container}),r.setAttribute("data-testid",i.testId);const s=_("span","clepit-menu-icon");s.textContent=i.icon,l.applyStyling(s,{classNames:a?.item?.icon,styles:o?.item?.icon}),r.appendChild(s);const c=_("span","clepit-menu-label");if(c.textContent=i.label,l.applyStyling(c,{classNames:a?.item?.text,styles:o?.item?.text}),r.appendChild(c),i.value.startsWith("audioAlign")){const e=n.querySelector(".clepit-audio-wrapper");if(e){const t=e.style.textAlign;("left"===t?"left":"right"===t?"right":"center")===i.value.replace("audioAlign","").toLowerCase()&&r.classList.add("active")}}e.addEventListener(g,r,"click",a=>{a.stopPropagation(),e.handleOperationSelect(i.value,n,t),m.remove()}),b.appendChild(r)})),"code"===f&&(E(),C.forEach(s=>{const c=_("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(c,{classNames:a?.item?.container,styles:o?.item?.container}),c.setAttribute("data-testid",s.testId);const d=_("span","clepit-menu-icon");d.textContent=s.icon,l.applyStyling(d,{classNames:a?.item?.icon,styles:o?.item?.icon}),c.appendChild(d);const u=_("span","clepit-menu-label");if(u.textContent=s.label,l.applyStyling(u,{classNames:a?.item?.text,styles:o?.item?.text}),c.appendChild(u),s.hasSubmenu){const e=_("span","clepit-menu-arrow");e.textContent="›",c.appendChild(e)}e.addEventListener(g,c,"click",a=>{a.stopPropagation(),s.hasSubmenu?"codeLanguage"===s.value?e.showCodeLanguageSubmenu({block:n,classNames:i,containerId:t,menuLabels:p,parentItem:c,parentMenu:m,styles:r}):"codeTheme"===s.value&&e.showCodeThemeSubmenu({block:n,classNames:i,containerId:t,menuLabels:p,parentItem:c,parentMenu:m,styles:r}):(e.handleOperationSelect(s.value,n,t),m.remove())}),b.appendChild(c)})),"embed"===f&&(E(),S.forEach(i=>{const r=_("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(r,{classNames:a?.item?.container,styles:o?.item?.container}),r.setAttribute("data-testid",i.testId);const s=_("span","clepit-menu-icon");s.textContent=i.icon,l.applyStyling(s,{classNames:a?.item?.icon,styles:o?.item?.icon}),r.appendChild(s);const c=_("span","clepit-menu-label");c.textContent=i.label,l.applyStyling(c,{classNames:a?.item?.text,styles:o?.item?.text}),r.appendChild(c),e.addEventListener(g,r,"click",a=>{a.stopPropagation(),e.handleOperationSelect(i.value,n,t),m.remove()}),b.appendChild(r)})),"header"===f){E();const i=e.getCurrentHeadingLevel(n);[{icon:"H1",label:y("headingH1","Heading 1"),value:"heading-h1"},{icon:"H2",label:y("headingH2","Heading 2"),value:"heading-h2"},{icon:"H3",label:y("headingH3","Heading 3"),value:"heading-h3"},{icon:"H4",label:y("headingH4","Heading 4"),value:"heading-h4"},{icon:"H5",label:y("headingH5","Heading 5"),value:"heading-h5"},{icon:"H6",label:y("headingH6","Heading 6"),value:"heading-h6"}].forEach(r=>{const s=_("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(s,{classNames:a?.item?.container,styles:o?.item?.container});const c=_("span","clepit-menu-icon");c.textContent=r.icon,l.applyStyling(c,{classNames:a?.item?.icon,styles:o?.item?.icon}),s.appendChild(c);const d=_("span","clepit-menu-label");d.textContent=r.label,l.applyStyling(d,{classNames:a?.item?.text,styles:o?.item?.text}),s.appendChild(d),r.value===`heading-${i}`&&s.classList.add("active"),e.addEventListener(g,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(r.value,n,t),m.remove()}),b.appendChild(s)})}if("list"===f){E();const i=n.querySelector(".clepit-list")?.getAttribute("data-type")||"unordered";[{icon:"•",label:y("listUnordered","Unordered"),value:"unordered"},{icon:"1.",label:y("listOrdered","Ordered"),value:"ordered"}].forEach(r=>{const s=_("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(s,{classNames:a?.item?.container,styles:o?.item?.container});const c=_("span","clepit-menu-icon");c.textContent=r.icon,l.applyStyling(c,{classNames:a?.item?.icon,styles:o?.item?.icon}),s.appendChild(c);const d=_("span","clepit-menu-label");d.textContent=r.label,l.applyStyling(d,{classNames:a?.item?.text,styles:o?.item?.text}),s.appendChild(d),r.value===i&&s.classList.add("active"),e.addEventListener(g,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`listType${r.value}`,n,t),m.remove()}),b.appendChild(s)})}if("alert"===f){E();const i=n.querySelector(".clepit-alert")?.getAttribute("data-variant")||"info";[{icon:"i",label:y("variantInfo","Info"),value:"info"},{icon:"!",label:y("variantWarning","Warning"),value:"warning"},{icon:"×",label:y("variantError","Error"),value:"error"},{icon:"✓",label:y("variantSuccess","Success"),value:"success"},{icon:"—",label:y("variantPlain","Plain"),value:"plain"}].forEach(r=>{const s=_("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(s,{classNames:a?.item?.container,styles:o?.item?.container});const c=_("span","clepit-menu-icon");c.textContent=r.icon,c.style.color=e.getAlertIconColor(r.value),l.applyStyling(c,{classNames:a?.item?.icon,styles:o?.item?.icon}),s.appendChild(c);const d=_("span","clepit-menu-label");d.textContent=r.label,l.applyStyling(d,{classNames:a?.item?.text,styles:o?.item?.text}),s.appendChild(d),r.value===i&&s.classList.add("active"),e.addEventListener(g,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`alertVariant${r.value}`,n,t),m.remove()}),b.appendChild(s)})}if("glance"===f){E();const i=n.querySelector(".clepit-glance")?.getAttribute("data-variant")||"plain";[{icon:"—",label:y("variantPlain","Plain"),value:"plain"},{icon:"i",label:y("variantInfo","Info"),value:"info"},{icon:"!",label:y("variantWarning","Warning"),value:"warning"},{icon:"×",label:y("variantError","Error"),value:"error"},{icon:"✓",label:y("variantSuccess","Success"),value:"success"}].forEach(r=>{const s=_("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(s,{classNames:a?.item?.container,styles:o?.item?.container});const c=_("span","clepit-menu-icon");c.textContent=r.icon,c.style.color=e.getAlertIconColor(r.value),l.applyStyling(c,{classNames:a?.item?.icon,styles:o?.item?.icon}),s.appendChild(c);const d=_("span","clepit-menu-label");d.textContent=r.label,l.applyStyling(d,{classNames:a?.item?.text,styles:o?.item?.text}),s.appendChild(d),r.value===i&&s.classList.add("active"),e.addEventListener(g,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`glanceVariant${r.value}`,n,t),m.remove()}),b.appendChild(s)})}if("delimiter"===f){E();const i=n.querySelector(".clepit-delimiter")?.getAttribute("data-variant")||"line";[{icon:"—",label:y("delimiterLine","Line"),value:"line"},{icon:"***",label:y("delimiterStars","Stars"),value:"stars"}].forEach(r=>{const s=_("div","clepit-menu-item clepit-block-operation-item");l.applyStyling(s,{classNames:a?.item?.container,styles:o?.item?.container});const c=_("span","clepit-menu-icon");c.textContent=r.icon,l.applyStyling(c,{classNames:a?.item?.icon,styles:o?.item?.icon}),s.appendChild(c);const d=_("span","clepit-menu-label");d.textContent=r.label,l.applyStyling(d,{classNames:a?.item?.text,styles:o?.item?.text}),s.appendChild(d),r.value===i&&s.classList.add("active"),e.addEventListener(g,s,"click",a=>{a.stopPropagation(),e.handleOperationSelect(`delimiterVariant${r.value}`,n,t),m.remove()}),b.appendChild(s)})}const A=b.querySelectorAll(".clepit-block-operation-item"),N=b.querySelectorAll(".clepit-menu-divider");if(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;A.forEach(n=>{(n.querySelector(".clepit-menu-label")?.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=_("div","clepit-not-found-message",{style:"padding: 8px 12px; color: #666; font-style: italic; text-align: center;"});e.textContent=y("noOperationsFound","No operations found"),b.appendChild(e)}}else n&&n.remove();N.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(g,h,"keydown",e=>{"Escape"===e.key&&m.remove()}),m.appendChild(b),m.classList.add(Gr),m.setAttribute("popover","auto"),h.setAttribute("autofocus",""),n){const t=n.querySelector(`.${e.defaultClassName}`);t&&t.style.setProperty("anchor-name",e.menuAnchor)}document.body.appendChild(m),m.addEventListener("toggle",e=>{"closed"===e.newState&&m.remove()}),"function"!=typeof m.showPopover?(m.classList.add(`${Gr}--visible`),h.focus(),e.addDocumentEventListener("click",e=>{const t=e.target;m.contains(t)||n?.contains(t)||t.closest?.(".clepit-block-toolbar-ops")||m.remove()})):m.showPopover()}static showConvertSubmenu({containerId:t,block:n,parentItem:a,parentMenu:o,classNames:i,styles:r,imageIsEnabled:s,videoIsEnabled:c,audioIsEnabled:d,menuLabels:p,toolLabels:u}){const m=document.querySelector(`.${Kr}`);m&&m.remove();const h=n.getAttribute("data-tool");if(!h)return;const g=_("div",Kr);g.classList.add(Kr),g.classList.add(`${Kr}--hidden`),r?.container&&l.applyStyles(g,r.container),i?.container&&g.classList.add(i.container);const b=_("input","",{placeholder:Xr(p,"searchConvertOptions","Search convert options..."),type:"text"});b.setAttribute("data-testid","convert-search"),l.applyStyling(b,{classNames:i?.input,styles:r?.input}),g.appendChild(b),setTimeout(()=>b.focus(),10);const f=document.querySelector(`#${t}`),y=_("div",`${Kr}-items`),v=e=>(Jr(e.type)?u?.[e.type]:void 0)??e.label;Fr.filter(e=>e.type!==h&&(!("image"===e.type&&!s||"video"===e.type&&!c||"audio"===e.type&&!d)||void 0)).sort((e,t)=>v(e).localeCompare(v(t))).forEach(a=>{const s=_("div","clepit-menu-item clepit-convert-option-item");s.setAttribute("data-testid",a.testId),l.applyStyling(s,{classNames:i?.item?.container,styles:r?.item?.container});const c=_("span","clepit-menu-icon");c.textContent=a.icon,l.applyStyling(c,{classNames:i?.item?.icon,styles:r?.item?.icon}),s.appendChild(c);const d=_("span","clepit-menu-label");if(d.textContent=v(a),l.applyStyling(d,{classNames:i?.item?.text,styles:r?.item?.text}),s.appendChild(d),a.shortcut){const e=_("span","clepit-menu-shortcut");e.textContent=a.shortcut,l.applyStyling(e,{classNames:i?.item?.shortcut,styles:r?.item?.shortcut}),s.appendChild(e)}e.addEventListener(f,s,"click",e=>{e.stopPropagation();const i=n?.getAttribute("data-tool");if(!i)return;let r;if(n){const e=n.querySelector(".clepit-block-content");"paragraph"===i?r=e.querySelector(".clepit-paragraph")?.innerText||"":"quote"===i?r=e.querySelector(".clepit-quote-text")?.innerText||"":"list"===i?r=Array.from(e.querySelectorAll(".clepit-list-item")).map(e=>e.innerText.trim()).filter(Boolean).join("\n"):"alert"===i?r=e.querySelector(".clepit-alert")?.innerText||"":"header"===i&&(r=e.querySelector(".clepit-header")?.innerText||"")}const s=n?.getAttribute("data-id");s&&Qr.convertBlock(s,a.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),o.remove()}),y.appendChild(s)});const x=y.querySelectorAll(".clepit-convert-option-item");e.addEventListener(f,b,"click",e=>e.stopPropagation()),e.addEventListener(f,b,"focus",e=>e.stopPropagation()),e.addEventListener(f,b,"input",e=>{(e=>{let t=0;x.forEach(n=>{(n.querySelector(".clepit-menu-label")?.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=y.querySelector(".clepit-not-found-message");if(0===t&&""!==e.trim()){if(!n){const e=_("div","clepit-not-found-message",{style:"padding: 8px 12px; color: #666; font-style: italic; text-align: center;"});e.textContent=Xr(p,"noConvertOptionsFound","No convert options found"),y.appendChild(e)}}else n&&n.remove()})(e.target.value)}),e.addEventListener(f,b,"keydown",t=>{"Escape"===t.key&&e.closeMenu(Kr)}),g.appendChild(y);const k="--clepit-convert-parent-"+e.submenuAnchorSeq++;a.style.setProperty("anchor-name",k),g.style.setProperty("position-anchor",k),g.classList.remove(`${Kr}--hidden`),g.setAttribute("popover","auto"),document.body.appendChild(g),g.addEventListener("toggle",e=>{"closed"===e.newState&&g.remove()}),"function"!=typeof g.showPopover?(o.appendChild(g),g.classList.add(`${Kr}--visible`),e.addDocumentEventListener("click",e=>{const t=e.target;g.contains(t)||a.contains(t)||o.contains(t)||g.remove()})):g.showPopover()}static handleOperationSelect(e,t,n){if(!t)return;const a=document.querySelector(`#${n}`);if(e.startsWith("convertTo")){const a=e.replace("convertTo",""),o=t.getAttribute("data-id");return void(o&&Qr.convertBlock(o,a,n))}if(e.startsWith("heading-")){const n=e.replace("heading-","");if(-1===Qr.getBlockIndex(a.id,t.getAttribute("data-id")))return;const o=t.querySelector('[contenteditable="true"]');return void(o&&oa.changeLevel(o,n,a.id))}if(e.startsWith("listType")){const n=e.replace("listType","");if(-1===Qr.getBlockIndex(a.id,t.getAttribute("data-id")))return;const o=t.querySelector(".clepit-list");return void(o&&ga.changeType(o,n,a.id))}if(e.startsWith("alertVariant")){const n=e.replace("alertVariant","");if(-1===Qr.getBlockIndex(a.id,t.getAttribute("data-id")))return;const o=t.querySelector(".clepit-alert");return void(o&&cn.changeVariant(o,n,a.id))}if(e.startsWith("glanceVariant")){const n=e.replace("glanceVariant","");if(-1===Qr.getBlockIndex(a.id,t.getAttribute("data-id")))return;const o=t.querySelector(".clepit-glance");return void(o&&hr.changeVariant(o,n,a.id))}if(e.startsWith("delimiterVariant")){const n=e.replace("delimiterVariant","");if(-1===Qr.getBlockIndex(a.id,t.getAttribute("data-id")))return;const o=t.querySelector(".clepit-delimiter");if(!o)return;return Fn.changeVariant(o,n,a.id)}if(e.startsWith("tableAction")){const n=e.replace("tableAction",""),a=t.querySelector(`.${l.classNames.block.content}`);if(!a)return;return co.handleAction(n,a)}if(e.startsWith("embed"))return Yt.handleOperation(e,t,a.id);if(e.startsWith("imageAlign"))return la.setAlignment(t,e.replace("imageAlign","").toLowerCase());if(e.startsWith("videoAlign"))return Ui.setAlignment(t,e.replace("videoAlign","").toLowerCase());if(e.startsWith("audioAlign"))return hn.setAlignment(t,e.replace("audioAlign","").toLowerCase());if(e.startsWith("codeLanguage")){const n=e.replace("codeLanguage","");if(-1===Qr.getBlockIndex(a.id,t.getAttribute("data-id")))return;return Me.updateLanguage(t,n)}if(e.startsWith("codeTheme")){const n=e.replace("codeTheme","");if(-1===Qr.getBlockIndex(a.id,t.getAttribute("data-id")))return;return Me.updateTheme(t,n)}const o=Qr.getBlockIndex(a.id,t.getAttribute("data-id"));if(-1!==o)switch(e){case"delete":Qr.removeBlock(a.id,o);break;case"moveUp":o>0&&Qr.moveBlock(a.id,o,o-1);break;case"moveDown":o<Qr.getBlocks(a.id).length-1&&Qr.moveBlock(a.id,o,o+1);break;default:console.warn(`Unknown block operation: ${e}`)}}static showCodeLanguageSubmenu({parentItem:t,parentMenu:n,block:a,containerId:o,classNames:i,menuLabels:r,styles:s}){const c=document.querySelector(`.${Vr}`);c&&c.remove();const d=document.querySelector(`.${Wr}`);d&&d.remove();const p=document.getElementById(o);if(!p)return;const u=a?.querySelector(`.${l.classNames.block.code.container}`)?.getAttribute("data-language")||"javascript",m=l.createStyledElement("div",Vr,{classNames:i?.container,styles:s?.container});m.classList.add(Kr,"clepit-block-toolbar--submenu-positioned");const h=_("input","",{placeholder:Xr(r,"searchLanguages","Search languages..."),type:"text"});h.setAttribute("data-testid","language-search"),m.appendChild(h);const g=Me.supportedLanguages;Object.entries(g).forEach(([t,r])=>{const c=l.createStyledElement("div","clepit-menu-item clepit-code-language-item",{classNames:i?.item?.container,styles:s?.item?.container});c.setAttribute("data-testid",`code-language-${t}`);const d=l.createStyledElement("span","",{classNames:i?.item?.text,styles:s?.item?.text});d.textContent=r.name,c.appendChild(d),t===u&&c.classList.add("active"),e.addEventListener(p,c,"click",i=>{i.stopPropagation(),e.handleOperationSelect(`codeLanguage${t}`,a,o),n.remove()}),m.appendChild(c)});const b=m.querySelectorAll(".clepit-code-language-item");e.addEventListener(p,h,"click",e=>e.stopPropagation()),e.addEventListener(p,h,"input",e=>{const t=e.target.value.toLowerCase();b.forEach(e=>{const n=e.querySelector("span")?.textContent?.toLowerCase()||"";e.classList.toggle("clepit-block-toolbar--item-hidden",!n.includes(t))})}),n.appendChild(m);const f=t.getBoundingClientRect(),y=n.getBoundingClientRect();m.style.top=f.top-y.top+"px",m.style.left=f.right-y.left+4+"px",setTimeout(()=>{m.classList.remove(`${Vr}--hidden`),m.classList.add(`${Vr}--visible`)},10),setTimeout(()=>{const t=e=>{const a=e.target,o=m.contains(a),i=n.contains(a);o||i||(m.classList.remove(`${Vr}--visible`),m.classList.add(`${Vr}--hidden`),setTimeout(()=>m.remove(),200),document.removeEventListener("click",t))};e.addDocumentEventListener("click",t)},0)}static showCodeThemeSubmenu({parentItem:t,parentMenu:n,block:a,containerId:o,classNames:i,menuLabels:r,styles:s}){const c=document.querySelector(`.${Wr}`);c&&c.remove();const d=document.querySelector(`.${Vr}`);d&&d.remove();const p=document.getElementById(o);if(!p)return;const u=a?.querySelector(`.${l.classNames.block.code.container}`)?.getAttribute("data-theme")||"default",m=l.createStyledElement("div",Wr,{classNames:i?.container,styles:s?.container});m.classList.add(Kr,"clepit-block-toolbar--submenu-positioned");const h=_("input","",{placeholder:Xr(r,"searchThemes","Search themes..."),type:"text"});h.setAttribute("data-testid","theme-search"),m.appendChild(h);const g=Me.supportedThemes;Object.entries(g).forEach(([t,r])=>{const c=l.createStyledElement("div","clepit-menu-item clepit-code-theme-item",{classNames:i?.item?.container,styles:s?.item?.container});c.setAttribute("data-testid",`code-theme-${t}`);const d=l.createStyledElement("span","",{classNames:i?.item?.text,styles:s?.item?.text});d.textContent=r.name,c.appendChild(d),t===u&&c.classList.add("active"),e.addEventListener(p,c,"click",i=>{i.stopPropagation(),e.handleOperationSelect(`codeTheme${t}`,a,o),n.remove()}),m.appendChild(c)});const b=m.querySelectorAll(".clepit-code-theme-item");e.addEventListener(p,h,"click",e=>e.stopPropagation()),e.addEventListener(p,h,"input",e=>{const t=e.target.value.toLowerCase();b.forEach(e=>{const n=e.querySelector("span")?.textContent?.toLowerCase()||"";e.classList.toggle("clepit-block-toolbar--item-hidden",!n.includes(t))})}),n.appendChild(m);const f=t.getBoundingClientRect(),y=n.getBoundingClientRect();m.style.top=f.top-y.top+"px",m.style.left=f.right-y.left+4+"px",setTimeout(()=>{m.classList.remove(`${Wr}--hidden`),m.classList.add(`${Wr}--visible`)},10),setTimeout(()=>{const t=e=>{const a=e.target,o=m.contains(a),i=n.contains(a);o||i||(m.classList.remove(`${Wr}--visible`),m.classList.add(`${Wr}--hidden`),setTimeout(()=>m.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(`.${Ur}, .${Gr}, .${Kr}`)||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(Ur),e.closeMenu(Gr),e.closeMenu(Kr)}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())}},Qr=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 a=m.getState().getInstance(n);if(!a)return console.error("BlockManager::createBlockElement: Instance not found for containerId:",n),null;const o=_("div",l.classNames.block.container);o.setAttribute("data-container-id",n),o.setAttribute("data-id",t.id??crypto.randomUUID()),o.setAttribute("data-tool",t.type),o.setAttribute("data-indent","0");const i={classNames:a.config.classNames?.blocks?.[t.type],styles:a.config.styles?.blocks?.[t.type]};let r,s;if(i.margins&&(r=i.margins.top,s=i.margins.bottom),void 0===r&&i.styles){const e=i.styles;if(e.marginTop){const t=e.marginTop;"string"==typeof t&&t.endsWith("px")?r=parseInt(t.replace("px",""),10):"number"==typeof t&&(r=t)}}if(void 0===s&&i.styles){const e=i.styles;if(e.marginBottom){const t=e.marginBottom;"string"==typeof t&&t.endsWith("px")?s=parseInt(t.replace("px",""),10):"number"==typeof t&&(s=t)}}void 0===r&&void 0!==a.config.margins?.top&&(r=a.config.margins.top),void 0===s&&void 0!==a.config.margins?.bottom&&(s=a.config.margins.bottom),void 0!==r&&(o.style.marginTop=`${r}px`),void 0!==s&&(o.style.marginBottom=`${s}px`),Yr.create({block:o,containerId:n});const c=_("div",l.classNames.block.content),d=e.renderTool(t.type,t.data,n);return d?(c.appendChild(d),e.addEventListener(n,o,"click",t=>e.focusBlock(t.currentTarget)),o.appendChild(c),o):(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 m.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(),m.getState().removeBlock(t,n)}static replaceBlock(t,n,a){e.insertBlock(a,t,n+1),e.removeBlock(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=m.getState().getData(t);if(!i)return;const r=m.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 l=o.map(t=>e.getBlockData(t.getAttribute("data-id"))),c={...i,blocks:l};m.getState().setData(t,c),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(`.${l.classNames.block.container}`);return Array.from(n)}static getActiveBlocks(e){const t=document.getElementById(e);if(!t)return[];const n=t.querySelectorAll(`.${l.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 Fr.find(t=>t.type===e)||null}static getBlockData(t){const n=e.getBlock(t);if(!n)return{data:{html:""},type:"paragraph"};const a=n.getAttribute("data-tool"),o=a?e.getTool(a):null;if(!o)return{data:{html:""},id:t,type:"paragraph"};const i=n.querySelector(`.${l.classNames.block.content}`);return i?{data:o.input.save(i),id:t,tunes:e.getBlockTunes(n),type:a}:{data:{html:""},id:t,tunes:e.getBlockTunes(n),type:a}}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=m.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 cn.render(n,t,o);case"audio":return a.config.audioUploader?hn.render(a.config.audioUploader,n,t,o):(console.error("BlockManager::renderTool: Audio uploader not found for containerId:",n),null);case"code":return Me.render(n,t,o);case"collapsible":return Nn.render(n,t,o);case"columns":return tr.render(n,t,o);case"date":return ar.render(n,t,o);case"delimiter":return Fn.render(n,t,o);case"collection":return Yi.render(n,t,o);case"doc_card":return sr.render(n,t,o);case"embed":return Yt.render(n,t,o);case"openapi":return Sr.render(n,t,o);case"sketch":return Br.render(n,t,o);case"latex":return jr.render(n,t,o);case"mermaid":return zr.render(n,t,o);case"file":return a.config.fileUploader?pr.render(a.config.fileUploader,n,t,o):(console.error("BlockManager::renderTool: File uploader not found for containerId:",n),null);case"header":return oa.render(n,t,o);case"image":return a.config.imageUploader?la.render(a.config.imageUploader,n,t,o):(console.error("BlockManager::renderTool: Image uploader not found for containerId:",n),null);case"list":return ga.render(n,t,o);case"checklist":return vn.render(n,t,o);case"paragraph":return Ga.render(n,t,o);case"quote":return Ya.render(n,t,o);case"table":return co.render(n,t,o);case"toc":return Tr.render(n,t,o);case"issues":return vr.render(n,t,o);case"video":return a.config.videoUploader?Ui.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 a of e.getActiveBlocks(n))a.classList.remove(l.classNames.block.active);t.classList.add(l.classNames.block.active),Yr.show(n,t)}static getActiveBlock(e){const t=document.getElementById(e);return t?t.querySelector(`.${l.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 l=i.data;if("list"===n){const e=i.data,t=e.html||e.text||"";l={items:t?[t]:[""],type:"unordered"}}else if("header"===n){const e=i.data;l={html:e.html||e.text||"",level:"h1"}}const c={data:l,id:t,type:r.type},d=e.createBlockElement(c,a);if(!d)return console.error("BlockManager::convertBlock: New block element not found for newType:",n);o.replaceWith(d);const p=e.getBlockData(d.getAttribute("data-id"));m.getState().updateBlock(a,s,p),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=sn.getInstanceAndTargetFromRange(t);if(!n)return;const a=n.target.closest(`.${l.classNames.block.container}`);if(!a)return;const o=e.getBlockIndex(n.instance.config.containerId,a.getAttribute("data-id"));m.getState().updateBlock(n.instance.config.containerId,o,e.getBlockData(a.getAttribute("data-id")))}static renderBlock(t,n,a){const o=e.getBlocks(n),i=m.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=m.getState().getInstance(n);r&&te.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)),m.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();m.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(`.${l.classNames.editor.container}`);return t?t.id:null}static handleKeydown(t){const n=t,a=t.currentTarget,o=a.closest(`.${l.classNames.block.container}`),i=e.getEditorId(o);if(!i)return;const r=e.getBlockIndex(i,o.getAttribute("data-id")),s=n.metaKey||n.ctrlKey;if(n.shiftKey)switch(n.key){case"ArrowUp":t.preventDefault(),t.stopPropagation(),r>0&&e.moveBlock(i,r,r-1);break;case"ArrowDown":t.preventDefault(),t.stopPropagation();const n=e.getBlocks(i);n&&r<n.length-1&&e.moveBlock(i,r,r+1)}else if(s)switch(n.key){case"Delete":case"Backspace":t.preventDefault(),t.stopPropagation(),e.removeBlock(i,r)}else if("Enter"===n.key)n.preventDefault(),n.stopPropagation(),e.insertBlock({data:{html:""},type:"paragraph"},i,r+1);else if("Backspace"===n.key){if(!D(a.innerHTML))return;n.preventDefault(),n.stopPropagation(),e.removeBlock(i,r)}else{e.ensureActiveBlock(i);const a=e.getBlocks(i);switch(n.key){case"ArrowUp":if(t.preventDefault(),t.stopPropagation(),r>0){const t=a[r-1];t&&e.focusBlock(t)}return;case"ArrowDown":if(t.preventDefault(),t.stopPropagation(),r<a.length-1){const t=a[r+1];t&&e.focusBlock(t)}return}}}static handleInput(t){e.saveBlockData(t.currentTarget)}static ensureActiveBlock(t){const n=e.getBlocks(t);let a=e.getActiveBlock(t);if(!a){const t=document.activeElement;if(!t)return;const o=t.closest(`.${l.classNames.block.container}`);if(o)a=o,e.setActiveBlock(a);else{if(0===n.length)return;a=n[0],e.setActiveBlock(a)}}}static saveBlockData(t){const n=t.closest(`.${l.classNames.block.container}`),a=e.getEditorId(n);if(!a)return;const o=n.getAttribute("data-id");m.getState().updateBlockData(a,e.getBlockIndex(a,o),e.getBlockData(o).data)}static updateBlockData(t,n,a){const o=e.getBlock(t);if(o){const t=o.querySelector(`.${l.classNames.block.content}`);t&&(t.innerHTML="");const i=e.renderTool(o.getAttribute("data-tool"),n,a);i&&t.appendChild(i)}m.getState().updateBlockData(a,e.getBlockIndex(a,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]=[]),Fr.forEach(e=>e.input.destroy(t));for(const a of e.getBlocks(t))a.remove()}},es=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=m.getState().getInstance(t);if(!n)return console.error("ActionBar::create: Instance not found for containerId:",t);l.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 a=document.getElementById(t);if(!a)return;const o=n.config.styles?.controls?.group,i=n.config.classNames?.controls?.group,r=n.config.styles?.controls?.button,s=n.config.classNames?.controls?.button,c=n.config.styles?.tooltips,d=n.config.classNames?.tooltips,p=_("div",l.classNames.actionBar.container);e.createButtonGroup(a,p,{buttonClassNames:s,buttonStyles:r,currentView:n.currentView,groupClassNames:i,groupStyles:o,tooltipClassNames:d,tooltipStyles:c}),a.insertBefore(p,a.firstChild)}static createButtonGroup(t,n,a){const o=_("div",l.classNames.actionBar.group);l.applyStyling(o,{classNames:a.groupClassNames,styles:a.groupStyles});const i=_("button",l.classNames.actionBar.button,{"data-testid":"action-bar-edit-button","data-view":"edit",id:q(t.id,l.idSuffixes.actionBar.editButton),type:"button"});i.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>',l.applyStyling(i,{classNames:a.buttonClassNames,styles:a.buttonStyles});const r=_("button",l.classNames.actionBar.button,{"data-testid":"action-bar-preview-button","data-view":"preview",id:q(t.id,l.idSuffixes.actionBar.previewButton),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="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>',l.applyStyling(r,{classNames:a.buttonClassNames,styles:a.buttonStyles});const s=_("button",l.classNames.actionBar.button,{"data-testid":"action-bar-json-button","data-view":"json",id:q(t.id,l.idSuffixes.actionBar.jsonButton),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="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>',l.applyStyling(s,{classNames:a.buttonClassNames,styles:a.buttonStyles}),"edit"===a.currentView?i.classList.add("active"):"preview"===a.currentView?r.classList.add("active"):"json"===a.currentView&&s.classList.add("active"),e.addEventListener(t.id,i,"click",e.handleViewChange),e.addEventListener(t.id,r,"click",e.handleViewChange),e.addEventListener(t.id,s,"click",e.handleViewChange),o.appendChild(i),o.appendChild(r),o.appendChild(s),n.appendChild(o),ee(i,"Edit Mode","above",a.tooltipClassNames,a.tooltipStyles),ee(r,"Preview Mode","above",a.tooltipClassNames,a.tooltipStyles),ee(s,"JSON Output","above",a.tooltipClassNames,a.tooltipStyles);const c=_("div",l.classNames.actionBar.action);l.applyStyling(c,{classNames:a.groupClassNames,styles:a.groupStyles});const d=_("button",l.classNames.actionBar.actionButton,{"data-testid":"view-copy-button",id:q(t.id,l.idSuffixes.actionBar.copyButton),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"><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>',l.applyStyling(d,{classNames:a.buttonClassNames,styles:a.buttonStyles});const p=_("button",l.classNames.actionBar.actionButton,{"data-testid":"view-download-button",id:q(t.id,l.idSuffixes.actionBar.downloadButton),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"><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>',l.applyStyling(p,{classNames:a.buttonClassNames,styles:a.buttonStyles});const u=_("button",l.classNames.actionBar.actionButton,{"data-testid":"view-clear-button",id:q(t.id,l.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>',l.applyStyling(u,{classNames:a.buttonClassNames,styles:a.buttonStyles}),e.addEventListener(t.id,d,"click",e.handleCopyJson),e.addEventListener(t.id,p,"click",e.handleDownloadJson),e.addEventListener(t.id,u,"click",e.handleClearEditor),c.appendChild(d),c.appendChild(p),c.appendChild(u),n.appendChild(c),ee(d,"Copy JSON to Clipboard","above",a.tooltipClassNames,a.tooltipStyles),ee(p,"Download JSON File","above",a.tooltipClassNames,a.tooltipStyles),ee(u,"Clear Editor","above",a.tooltipClassNames,a.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(`.${l.classNames.actionBar.group}`);if(!n)return console.error("ActionBar::getCurrentView: View toggle group not found for container:",t.id),null;const a=n.querySelector(".active");return a?a.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 a=n.querySelector(`.${l.classNames.actionBar.container}`);a&&a.querySelectorAll(`#${q(e,l.idSuffixes.actionBar.editButton)}, #${q(e,l.idSuffixes.actionBar.previewButton)}, #${q(e,l.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=Qr.getEditorId(n);if(!a)return;const o=n.getAttribute("data-view");o&&(m.getState().setCurrentView(a,o),e.updateButtonStates(a,o))}static handleCopyJson(e){const t=e.currentTarget,n=Qr.getEditorId(t);if(!n)return;const a=m.getState().getInstance(n);a&&(navigator.clipboard.writeText(JSON.stringify(a.data,null,2)),t.classList.add(l.classNames.actionBar.copyFeedback),setTimeout(()=>t.classList.remove(l.classNames.actionBar.copyFeedback),200))}static handleClearEditor(e){const t=e.currentTarget,n=Qr.getEditorId(t);n&&Qr.resetBlocks(n)}static handleDownloadJson(e){const t=e.currentTarget,n=Qr.getEditorId(t);if(!n)return;const a=Qr.getBlocks(n).map(e=>Qr.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(`.${l.classNames.actionBar.container}`);n&&n.remove()}},ts=`\n/* Editor Container */\n.${l.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.${l.classNames.editor.container}:focus {\n outline: none;\n}\n\n.${l.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.${l.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.${l.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.${l.classNames.editor.jsonOutput}:focus {\n outline: none;\n}\n\n/* Editable (allowed) -> green text */\n.${l.classNames.editor.jsonOutput}.clepit-json-editable {\n color: var(--clepit-success);\n}\n\n/* Invalid JSON -> red text */\n.${l.classNames.editor.jsonOutput}.clepit-json-error {\n color: var(--clepit-error);\n background-color: transparent;\n}\n\n.${l.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 .${l.classNames.editor.container} {\n padding: 8px;\n }\n\n .${l.classNames.editor.content} {\n padding: 12px;\n }\n}\n`,ns=class e{static{this.timers={}}static{this.focusHandlers={}}static start(t){if(e.stop(t),!(m.getState().getInstance(t)?.config)?.resolveIssues)return;e.run(t),e.timers[t]=setInterval(()=>{e.run(t)},3e5);const n=()=>{e.run(t)};window.addEventListener("focus",n),e.focusHandlers[t]=n}static stop(t){const n=e.timers[t];n&&clearInterval(n),delete e.timers[t];const a=e.focusHandlers[t];a&&window.removeEventListener("focus",a),delete e.focusHandlers[t]}static urls(e){const t=document.getElementById(e);if(!t)return[];const n=/* @__PURE__ */new Set;for(const a of ct.collect(t))n.add(ct.read(a).url);for(const a of Qr.getBlocks(e)){if("embed"!==a.getAttribute("data-tool"))continue;const e=Yt.save(a);e.issue&&n.add(e.url)}return n.delete(""),[...n]}static async run(t){const n=e.urls(t);if(0===n.length)return;const a=await Qt(t,n),o=document.getElementById(t),i=m.getState().getInstance(t)?.config;if(o&&i&&0!==Object.keys(a).length){ct.refreshAll(o,a,i.issueLabels);for(const e of Qr.getBlocks(t)){if("embed"!==e.getAttribute("data-tool"))continue;const n=Yt.save(e),o=n.issue?a[n.url]:void 0;o&&Yt.refreshIssue(e,t,o)}vr.refresh(t,a)}}},as=class{static render(e){const t=m.getState().getInstance(e);t&&(pe.create(e),l.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'),Qr.renderBlocks(t.data.blocks,e))}},os=class e{static render(t){const n=m.getState().getInstance(t);if(!n)return;const a=document.getElementById(n.contentId);if(a)if(a.innerHTML="",n.data&&n.data.blocks&&n.data.blocks.length>0){const t=l.createStyledElement("pre",l.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(l.classNames.editor.jsonEditable),setTimeout(()=>t.focus(),0),e.addEventListeners(t)),a.appendChild(t)}else{const e=l.createStyledElement("div",l.classNames.editor.jsonEmpty);e.textContent="No content to display",a.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||"",a=Qr.getEditorId(t);if(a)try{const e=JSON.parse(n);if("object"==typeof e&&null!==e){e.blocks&&Array.isArray(e.blocks)||(e.blocks=[]);const t=m.getState().getInstance(a);if(t){const n=document.querySelector(`#${t.contentId} .${l.classNames.editor.jsonOutput}`);n&&(n.classList.remove(l.classNames.editor.jsonError),t.config.allowJsonViewEditing&&n.classList.add("clepit-json-editable"));const o=t.currentView;m.getState().setData(a,e),"json"===o&&m.getState().setCurrentView(a,"json"),console.log("Store updated successfully")}}}catch{const e=m.getState().getInstance(a);if(e){const t=document.querySelector(`#${e.contentId} .${l.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||"",a=Qr.getEditorId(t);if(!a)return;const o=m.getState().getInstance(a);if(o)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{pe.hide(a),Yr.hide(a)}catch{}const t=o.currentView;m.getState().setData(a,e),"json"===t&&m.getState().setCurrentView(a,"json");const n=document.querySelector(`#${o.contentId} .${l.classNames.editor.jsonOutput}`);n&&(n.classList.remove("clepit-json-error"),o.config.allowJsonViewEditing?n.classList.add("clepit-json-editable"):n.classList.remove("clepit-json-editable")),o.config.onChange&&o.config.onChange(e)}}catch{const e=document.querySelector(`#${o.contentId} .${l.classNames.editor.jsonOutput}`);e&&(e.classList.add("clepit-json-error"),e.classList.remove("clepit-json-editable"))}}static destroy(t){const n=m.getState().getInstance(t);if(!n)return;const a=document.querySelector(`#${n.contentId} .${l.classNames.editor.jsonOutput}`);a&&e.removeEventListeners(a)}},is=/* @__PURE__ */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"]),rs=(e,t)=>is.has(`${e}.${t}`),ss=/* @__PURE__ */new Set(["checklist.items","list.items","table.data"]),ls=(e,t)=>ss.has(`${e}.${t}`),cs=(e,t,n,a)=>{if(!Array.isArray(t))return t;let o=!1;const i=e=>{const t=((e,t,n)=>{const a=ps(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},ds=(e,t,n,a)=>{let o=!1;const i={};for(const[r,s]of Object.entries(t)){if(ls(e,r)){const t=cs(e,s,n,a);i[r]=t,t!==s&&(o=!0);continue}if(!rs(e,r)){i[r]=s;continue}const t=ps(s,n,a);null!==t?(i[r]=t.value,t.value!==s&&(o=!0)):i[r]=s}return o?i:t},ps=(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]}},us="clepit-theme-styles",ms=".clepit-editor, .clepit-renderer-content, body[data-clepit-theme]",hs=`@layer clepit.reset, clepit.tokens, clepit.blocks, clepit.overrides;\n\n${Zr=i,Object.keys(r).map(e=>`@property ${r[e]} {\n syntax: '<color>';\n inherits: true;\n initial-value: ${Zr[e]};\n}`).join("\n\n")}\n\n@layer clepit.tokens {\n${s(i,{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)"},ms)}\n\n${ms} {\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`,gs=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 l.injectStyles(us,hs),l.injectStyles(U,V),l.injectStyles(Ge,Je),n.classList.add(l.classNames.renderer.content),l.registerEditor(t.containerId,t.theme??"auto",t.themeOverrides),n.innerHTML="",ct.applyParts(n,t.issueChip),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)}),t.issues&&ct.refreshAll(n,t.issues,t.issueLabels),n):n}static localize(e,t){if(!t.locale)return e;const n=ds(e.type,e.data,t.locale,t.defaultLocale??t.locale);return n===e.data?e:{...e,data:n}}static renderBlock(e,t,n){const a=_("div",l.classNames.block.output);a.setAttribute("data-block-type",e.type),a.setAttribute("data-block-index",t.toString()),e.tunes&&Object.entries(e.tunes).forEach(([e,t])=>{a.setAttribute(`data-tune-${e}`,String(t))});const o=n.styles?.[e.type],i=n.classNames?.[e.type];let r,s,c,d=n.configs?.[e.type];if("paragraph"===e.type&&n.editorClassNames?.tooltips&&(d={...d,tooltipClassNames:n.editorClassNames.tooltips}),d?.margins&&(r=d.margins.top,s=d.margins.bottom),void 0===r&&void 0!==n.margins?.top&&(r=n.margins.top),void 0===s&&void 0!==n.margins?.bottom&&(s=n.margins.bottom),void 0!==r){const e=parseFloat(a.style.marginTop||"0")||0;a.style.marginTop=`${e+r}px`}if(void 0!==s){const e=parseFloat(a.style.marginBottom||"0")||0;a.style.marginBottom=`${e+s}px`}switch(e.type){case"alert":c=dn.render(e.data,d,o,i);break;case"audio":c=gn.render(e.data,d,o,i);break;case"code":c=Ue.render(e.data,d,o,i);break;case"collapsible":c=Ji.render(e.data,d,o,i);break;case"columns":c=qn.render(e.data,d,o,i);break;case"date":c=Pn.render(e.data,d,o,i);break;case"delimiter":c=Un.render(e.data,d,o,i);break;case"collection":c=In.render(e.data,d,o,i);break;case"updates":c=Pi.render(e.data,d,o,i);break;case"glance":c=na.render(e.data,d,o,i);break;case"embed":c=Ot.render(e.data,{...d,issueLabels:n.issueLabels,issues:n.issues},o,i);break;case"sketch":c=ro.render(e.data,d,o,i);break;case"latex":c=Di.render(e.data,d,o,i);break;case"mermaid":c=ji.render(e.data,d,o,i);break;case"openapi":c=Wa.render(e.data,d,o,i);break;case"doc_card":c=Gn.render(e.data,d,o,i);break;case"file":c=Qn.render(e.data,d,o,i);break;case"header":c=ia.render(e.data,d,o,i);break;case"image":c=ca.render(e.data,d,o,i);break;case"list":c=ba.render(e.data,d,o,i);break;case"checklist":c=xn.render(e.data,d,o,i);break;case"paragraph":c=Ja.render(e.data,d,o,i);break;case"quote":c=Qa.render(e.data,d,o,i);break;case"table":c=mo.render(e.data,d,o,i);break;case"toc":c=yo.render(e.data,{...d,documentBlocks:n.data?.blocks??[]},o,i);break;case"issues":c=ma.render(e.data,{...d,documentBlocks:n.data?.blocks??[],issueLabels:n.issueLabels,issues:n.issues},o,i);break;case"video":c=Vi.render(e.data,d,o,i);break;default:c=null}return c?(a.appendChild(c),te.initializeElements(a,{classNames:n.classNames?.tooltip,styles:n.styles?.tooltip}),a):null}},bs=class{static render(e){const t=m.getState().getInstance(e);t&&gs.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})}},fs=class e{static create(t){return e.destroy(t.containerId),e.initialize(t),es.create(t.containerId),e.render(t.containerId),sn.addListeners(t.containerId),ns.start(t.containerId),m.getState().setIsReady(t.containerId,!0),m.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)=>Qr.convertBlock(e,n,t.containerId),count:()=>Qr.getBlocks(t.containerId).length,get:e=>Qr.getBlock(e)?Qr.getBlockData(e):null,getAll:()=>Qr.getBlocks(t.containerId).map(e=>Qr.getBlockData(e.getAttribute("data-id"))),insert:(e,n,a,o)=>Qr.insertBlock({data:n,id:o??Math.random().toString(36).substring(2,11),type:e},t.containerId,a),move:(e,n)=>Qr.moveBlock(t.containerId,e,n),remove:e=>Qr.removeBlock(t.containerId,e),update:(e,n)=>Qr.updateBlockData(e,n,t.containerId)},blur:()=>{const e=document.activeElement;e&&document.getElementById(t.containerId)?.contains(e)&&e.blur()},data:{clear:()=>{m.getState().clearData(t.containerId),Qr.destroy(t.containerId)},clearContent:()=>Qr.destroy(t.containerId),clearStorage:()=>m.getState().clearData(t.containerId),extract:()=>Qr.extractData(t.containerId),set:e=>Qr.setBlocks(e.blocks,t.containerId)},destroy:()=>e.destroy(t.containerId),focus:()=>{const e=Qr.getBlocks(t.containerId)[0];e&&Qr.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:()=>Yr.hide(t.containerId),hideToolbar:()=>pe.hide(t.containerId),showBlockMenu:e=>Yr.show(t.containerId,e),showToolbar:(e,n)=>pe.show(t.containerId,e,n)},view:{getCurrentView:e=>m.getState().getCurrentView(e),switchView:(e,t)=>m.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}`;l.injectStyles(us,hs),l.injectStyles("clepit-editor-container-styles",ts),l.injectStyles($,I),l.injectStyles(Z,Y),l.injectStyles(P,R),l.injectStyles(Ge,Je);const a={allowJsonViewEditing:!1,initialView:"edit",maxHeight:0,minHeight:300,placeholder:"Start writing...",...t};n.className=l.classNames.editor.container,n.setAttribute("contenteditable","false"),ct.applyParts(n,a.issueChip),l.registerEditor(t.containerId,a.theme??"auto",a.themeOverrides),a.minHeight&&n.style.setProperty("--clepit-min-height",`${a.minHeight}px`),a.maxHeight&&n.style.setProperty("--clepit-max-height",`${a.maxHeight}px`),l.applyStyles(n,a.styles?.container),l.applyClassNames(n,a.classNames?.container),a.margins&&(void 0!==a.margins.top&&n.style.setProperty("--block-margin-top",`${a.margins.top}px`),void 0!==a.margins.bottom&&n.style.setProperty("--block-margin-bottom",`${a.margins.bottom}px`));const o=`${a.containerId}-${l.idSuffixes.editorContent}`,i=_("div",l.classNames.editor.content);i.id=o,i.setAttribute("data-testid","editor-content-container"),i.setAttribute("data-container-id",t.containerId),l.applyStyles(i,a.styles?.editorContent),l.applyClassNames(i,a.classNames?.editorContent),n.appendChild(i),m.getState().addInstance(t.containerId,{config:a,contentId:o,currentView:a.initialView||"edit",data:e.localizeData(a.initialData,a),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(is).filter(t=>t.startsWith(`${e}.`)).map(t=>t.slice(e.length+1)).sort())(e.type)){const i=ps(n[r],a,o);i?.isFallback&&t.onLocaleFallback?.({blockId:e.id??"",field:r,requested:a,showing:i.locale})}const i=ds(e.type,n,a,o);return i===n?e:{...e,data:i}})}}static render(e){const t=m.getState().getInstance(e);if(!t)return;const n=document.getElementById(t.contentId);n&&(os.destroy(e),n.innerHTML=""),"edit"===t.currentView?as.render(e):"preview"===t.currentView?bs.render(e):"json"===t.currentView&&os.render(e),t.config.onReady&&t.config.onReady()}static destroy(e){ns.stop(e),Vt.dismiss(e),sn.removeListeners(e),es.destroy(e),Yr.destroy(e),pe.destroy(e),Qr.destroy(e),l.unregisterEditor(e);const t=document.getElementById(e);t&&(t.innerHTML="")}},ys=e=>e.replace(/["\\]/g,"\\$&"),vs=e=>e.flatMap(e=>"collapsible"===e.type?[e,...vs(e.data.children??[])]:"columns"===e.type?[e,...vs(e.data.columns?.flat()??[])]:[e]),xs=(e,t)=>{const n=[];for(const a of vs(t)){if(!a.id)continue;if("code"!==a.type&&"openapi"!==a.type&&"table"!==a.type)continue;const t=e.querySelector(`[data-clepit-block-id="${ys(a.id)}"]`);if(!t||t.hasAttribute("data-clepit-activated"))continue;t.setAttribute("data-clepit-activated","");const o="code"===a.type?Ue.activate(t,a.data):"openapi"===a.type?Wa.activate(t):mo.activate(t,a.data);n.push(()=>{o(),t.removeAttribute("data-clepit-activated")})}return()=>{for(const e of n)e()}},ks=/* @__PURE__ */new Set(["strong","b","em","i","u","s","del","mark","code","a","span"]),ws=/* @__PURE__ */new Set(["href","target","title","contenteditable","data-tooltip","data-status","data-status-variant","data-user-id","data-page-id","data-issue-tool","data-issue-key","data-issue-title","data-issue-state","data-issue-category","data-issue-assignee","data-issue-avatar","data-issue-updated","data-issue-url","data-issue-pull","data-issue-reason","class"]),Cs=/* @__PURE__ */new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),Ss=/([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g,Es=e=>{const t=/* @__PURE__ */new Map;Ss.lastIndex=0;let n=Ss.exec(e);for(;null!==n;)t.set(n[1].toLowerCase(),n[2]??n[3]??n[4]??""),n=Ss.exec(e);return t},As=e=>{const t=e.trim().toLowerCase().replace(/[\x00-\x20]/g,"");return!t.startsWith("javascript:")&&!t.startsWith("data:")&&!t.startsWith("vbscript:")},Ns=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:Es(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(!ks.has(a.tag))continue;const e=n.lastIndexOf(a.tag);if(-1===e)continue;t.push(`</${a.tag}>`),n.splice(e,1);continue}if(!ks.has(a.tag))continue;const e=[];for(const[t,n]of a.attributes)ws.has(t)&&("href"!==t||As(n))&&e.push(`${t}="${be(n)}"`);"a"===a.tag&&e.push('target="_blank"','rel="noopener noreferrer"'),t.push(`<${[a.tag,...e].join(" ")}>`),a.selfClosing||Cs.has(a.tag)||n.push(a.tag)}for(const a of[...n].reverse())t.push(`</${a}>`);return t.join("")},Ls=()=>[hs,ln,mn,yn,Ne,De(),En,$n,_n,zn,Rn,Kn,Ke,Zn,ea,aa,sa,Je,ha,fa,Ka,Za,no,lo,bo,ko,Hi,Fi].join("\n"),Bs=(e,t)=>{const n=ye(Ns),a={...t,documentBlocks:t?.documentBlocks??e},o=e.map(e=>Wi(e,n,a)).filter(e=>null!==e).map(e=>ve(e)).join("\n");return ht(o,t?.issues,t?.issueChip,t?.issueLabels,Ns)},$s=(e,t)=>{const n=ge(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="${be(e.description)}">`:"",e.canonicalUrl?`<link rel="canonical" href="${be(e.canonicalUrl)}">`:"",`<meta property="og:title" content="${be(e.title)}">`,e.description?`<meta property="og:description" content="${be(e.description)}">`:"",`<style>${Ls()}</style>`].filter(Boolean);return["<!doctype html>",`<html lang="${be(e.locale??"en")}">`,`<head>${a.join("")}</head>`,"<body>",'<main class="clepit-public-page">',`<h1 class="clepit-public-page__title">${n}</h1>`,Bs(e.blocks,{...t,anchorTargets:!0}),"</main>","</body>","</html>"].join("\n")};export{oe as BLOCK_TOOLS,Bt as EMBED_ENGLISH,se as EMBED_LABELS,$t as EMBED_TOOL_NAMES,wt as EMBED_WIRE_KEYS,fs as Editor,ae as INLINE_TOOLS,Xe as ISSUE_ENGLISH,re as ISSUE_LABELS,ie as ISSUE_TOOLS,Ze as ISSUE_TOOL_NAMES,ct as IssueChip,gs as Renderer,l as StyleManager,xs as activateBlocks,mt as chipsInHtml,Xt as classifyIssueUrl,me as domBacking,Wi as drawBlock,It as embedLabel,Ct as isEmbedProviderDisabled,Qe as issueLabel,et as issueToolName,Ls as pageStylesheet,za as parseOpenApi,ut as readChipMarkup,ht as refreshChipsInHtml,Bs as renderBlocks,$s as renderPage,ve as renderToString,Nt as resolveEmbed,Ns as sanitizeHtmlWithoutDom,ye as stringBacking,xe as toDomElement,s as tokensToLightDarkBlock};
2
2
  //# sourceMappingURL=index.mjs.map