@synclineapi/mdx-editor 2.0.0 → 2.0.1

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.
@@ -683,7 +683,7 @@ class oi {
683
683
  const d = i.length;
684
684
  return i.push(this.codeRenderer.renderBlock(r, o, c)), `%%CODEBLOCK_${d}%%`;
685
685
  }), t = t.replace(/`([^`]+)`/g, (a, r) => `<code class="smdx-inline-code">${this.escapeHtml(r)}</code>`);
686
- const n = (a) => a.toLowerCase().replace(/[^\w]+/g, "-").replace(/^-|-$/g, "");
686
+ const n = (a) => a.replace(/<[^>]+>/g, "").toLowerCase().replace(/[^\w]+/g, "-").replace(/^-|-$/g, "");
687
687
  t = t.replace(/^######\s+(.+)$/gm, (a, r) => `<h6 id="${n(r)}">${r}</h6>`), t = t.replace(/^#####\s+(.+)$/gm, (a, r) => `<h5 id="${n(r)}">${r}</h5>`), t = t.replace(/^####\s+(.+)$/gm, (a, r) => `<h4 id="${n(r)}">${r}</h4>`), t = t.replace(/^###\s+(.+)$/gm, (a, r) => `<h3 id="${n(r)}">${r}</h3>`), t = t.replace(/^##\s+(.+)$/gm, (a, r) => `<h2 id="${n(r)}">${r}</h2>`), t = t.replace(/^#\s+(.+)$/gm, (a, r) => `<h1 id="${n(r)}">${r}</h1>`), t = t.replace(/^---$/gm, "<hr/>"), t = t.replace(/\*\*\*(.+?)\*\*\*/g, "<strong><em>$1</em></strong>"), t = t.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>"), t = t.replace(/\*(.+?)\*/g, "<em>$1</em>"), t = t.replace(/~~(.+?)~~/g, "<del>$1</del>"), t = t.replace(/((?:^>[ \t]*.+\n?)+)/gm, (a) => "<blockquote>" + a.trimEnd().split(`
688
688
  `).map((o) => o.replace(/^>[ \t]*/, "")).join("<br>") + "</blockquote>"), t = t.replace(/^- \[x\]\s+(.+)$/gm, '<div class="smdx-task"><span class="smdx-task-checkbox smdx-task-checked" role="checkbox" aria-checked="true" tabindex="0"></span><span>$1</span></div>'), t = t.replace(/^- \[ \]\s+(.+)$/gm, '<div class="smdx-task"><span class="smdx-task-checkbox" role="checkbox" aria-checked="false" tabindex="0"></span><span>$1</span></div>'), t = this.listRenderer.render(t), t = t.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '<img src="$2" alt="$1" class="smdx-image"/>'), t = t.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (a, r, o) => `<a href="${/^(https?|mailto|ftp|tel):\/\//i.test(o) || o.startsWith("#") || o.startsWith("/") || o.startsWith("./") || o.startsWith("../") ? o : `https://${o}`}" target="_blank" rel="noopener noreferrer">${r}</a>`), t = this.tableRenderer.render(t), t = t.replace(/ {2,}$/gm, "<br/>"), t = t.replace(/^(?!\s*<[a-zA-Z/!]|\s*%%)(.*\S.*)$/gm, "<p>$1</p>"), t = t.replace(/<p>\s*<\/p>/g, "");
689
689
  for (let a = 0; a < i.length; a++)
@@ -12000,7 +12000,7 @@ class Da {
12000
12000
  if (a) continue;
12001
12001
  const o = r.match(/^(#{1,6})\s+(.+)/);
12002
12002
  if (o) {
12003
- const c = o[1].length, d = o[2].replace(/[*_`~\[\]]/g, "").trim(), l = d.toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-");
12003
+ const c = o[1].length, d = o[2].replace(/[*_`~\[\]]/g, "").trim(), l = d.toLowerCase().replace(/[^\w]+/g, "-").replace(/^-|-$/g, "");
12004
12004
  n.push({ level: c, text: d, slug: l });
12005
12005
  }
12006
12006
  }
@@ -1,7 +1,7 @@
1
1
  (function(v,ne){typeof exports=="object"&&typeof module<"u"?ne(exports,require("highlight.js")):typeof define=="function"&&define.amd?define(["exports","highlight.js"],ne):(v=typeof globalThis<"u"?globalThis:v||self,ne(v.SynclineMDXEditor={},v.hljs))})(this,function(v,ne){"use strict";class xt{constructor(){this.listeners=new Map}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t)}off(e,t){var i;(i=this.listeners.get(e))==null||i.delete(t)}emit(e,t){var i;(i=this.listeners.get(e))==null||i.forEach(n=>{try{n(t)}catch(a){console.error(`[SynclineMDX] Error in event handler for "${e}":`,a)}})}removeAllListeners(e){e?this.listeners.delete(e):this.listeners.clear()}}function ae(s){const e=s.map(r=>r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),t=new RegExp(`<(\\/?)(${e.join("|")})(?=[\\s>/])`,"g"),i=/([a-zA-Z_][\w-]*)(?=\s*=)|([a-zA-Z_][\w-]*)(?=[\s\t/>]|$)|("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/g;let n=!1;const a=(r,o,c)=>{i.lastIndex=0;for(const d of r.matchAll(i))d[1]!==void 0?c.push({cls:"fn",start:o+d.index,end:o+d.index+d[1].length}):d[2]!==void 0?c.push({cls:"fn",start:o+d.index,end:o+d.index+d[2].length}):d[3]!==void 0&&c.push({cls:"str",start:o+d.index,end:o+d.index+d[3].length})};return r=>{const o=[];if(n){const c=r.indexOf(">"),d=c===-1?r.length:c;return a(r.slice(0,d),0,o),c!==-1&&(n=!1),o}t.lastIndex=0;for(const c of r.matchAll(t))if(c[1]){const d=c.index+2;o.push({cls:"cls",start:d,end:d+c[2].length})}else{const d=c.index+1;o.push({cls:"cls",start:d,end:d+c[2].length});const l=d+c[2].length,h=r.indexOf(">",l),p=h===-1?r.length:h;if(a(r.slice(l,p),l,o),h===-1){n=!0;break}}return o}}function Ki(s,e){const t=[],i=s.match(/^(#{1,6}) /);if(i)return t.push({cls:"kw",start:0,end:i[1].length}),t;const n=s.match(/^(`{3,}|~{3,})([\w-]*)/);if(n)return t.push({cls:"kw",start:0,end:n[1].length}),n[2]&&t.push({cls:"typ",start:n[1].length,end:n[1].length+n[2].length}),t;if(/^(\s*)(---+|\*\*\*+|___+)\s*$/.test(s))return t.push({cls:"kw",start:0,end:s.length}),t;const a=s.match(/^(\s*>+\s?)/);a&&t.push({cls:"kw",start:0,end:a[1].length});const r=s.match(/^(\s*)([-*+]) (\[[ x]\] )?/);if(r){const l=r[1].length;if(t.push({cls:"op",start:l,end:l+1}),r[3]){const h=l+2;t.push({cls:"kw",start:h,end:h+r[3].trimEnd().length})}}const o=s.match(/^(\s*)(\d+\.) /);if(o){const l=o[1].length;t.push({cls:"op",start:l,end:l+o[2].length})}const c=s.match(/^(import|export)(\s)/);if(c&&t.push({cls:"kw",start:0,end:c[1].length}),/^\s*\|/.test(s)){for(const l of s.matchAll(/\|/g))t.push({cls:"op",start:l.index,end:l.index+1});return t}const d=new Set;for(const l of s.matchAll(/`([^`]+)`/g)){for(let h=l.index;h<l.index+l[0].length;h++)d.add(h);t.push({cls:"str",start:l.index,end:l.index+l[0].length})}for(const l of s.matchAll(new RegExp("(\\*\\*|__)(?!\\s)(.+?)(?<!\\s)\\1","g")))if(!d.has(l.index)){for(let h=l.index;h<l.index+l[0].length;h++)d.add(h);t.push({cls:"num",start:l.index,end:l.index+l[0].length})}for(const l of s.matchAll(new RegExp("(?<!\\*)\\*(?!\\*)(?!\\s)(.+?)(?<!\\s)\\*(?!\\*)|(?<!_)_(?!_)(?!\\s)(.+?)(?<!\\s)_(?!_)","g")))if(!d.has(l.index)){for(let h=l.index;h<l.index+l[0].length;h++)d.add(h);t.push({cls:"fn",start:l.index,end:l.index+l[0].length})}for(const l of s.matchAll(/~~(.+?)~~/g))if(!d.has(l.index)){for(let h=l.index;h<l.index+l[0].length;h++)d.add(h);t.push({cls:"cmt",start:l.index,end:l.index+l[0].length})}for(const l of s.matchAll(/!\[([^\]]*)\]\(([^)]*)\)/g)){if(d.has(l.index))continue;const h=l.index+2+l[1].length+1;t.push({cls:"fn",start:l.index,end:h}),t.push({cls:"str",start:h,end:l.index+l[0].length});for(let p=l.index;p<l.index+l[0].length;p++)d.add(p)}for(const l of s.matchAll(/\[([^\]]+)\]\(([^)]*)\)/g)){if(d.has(l.index))continue;const h=l.index+1+l[1].length+1;t.push({cls:"fn",start:l.index,end:h}),t.push({cls:"str",start:h,end:l.index+l[0].length});for(let p=l.index;p<l.index+l[0].length;p++)d.add(p)}return t}function kt(s,e){return(t,i)=>{const n=[];for(const a of s){const r=a(t,i);r.length&&n.push(...r)}for(const a of e){const r=a(t,i);r.length&&n.push(...r)}return n}}class Je{constructor(e,t){this.editorApi=e,this.plugins=new Map,this.toolbarItems=new Map,this.shortcuts=[],this.renderers=[],this.parsers=[],this.styleElements=[],this.completionsByPlugin=new Map,this.tokenProvidersByPlugin=new Map,this.events=t}async register(e){if(this.plugins.has(e.name)){console.warn(`[SynclineMDX] Plugin "${e.name}" is already registered.`);return}if(e.dependencies){for(const n of e.dependencies)if(!this.plugins.has(n))throw new Error(`[SynclineMDX] Plugin "${e.name}" requires "${n}" which is not registered.`)}if(this.plugins.set(e.name,e),e.toolbarItems)for(const n of e.toolbarItems)this.toolbarItems.set(n.id,n);e.shortcuts&&this.shortcuts.push(...e.shortcuts),e.patterns&&(this.renderers.push(...e.patterns),this.renderers.sort((n,a)=>(a.priority??0)-(n.priority??0))),e.components&&(this.renderers.push(...e.components),this.renderers.sort((n,a)=>(a.priority??0)-(n.priority??0))),e.parsers&&(this.parsers.push(...e.parsers),this.parsers.sort((n,a)=>(a.priority??0)-(n.priority??0)));const t=e.completions?[...e.completions]:[];this.completionsByPlugin.set(e.name,t);const i=e.provideTokens?[e.provideTokens]:[];if(e.patterns)for(const n of e.patterns)n.provideTokens&&i.push(n.provideTokens);if(e.components)for(const n of e.components)n.tag&&(i.push(ae([n.tag])),t.push({label:n.label??n.tag,kind:"cls",detail:n.description??`<${n.tag}> component`})),n.completions&&t.push(...n.completions);this.tokenProvidersByPlugin.set(e.name,i),e.styles&&this.injectStyles(e.styles),e.init&&await e.init(this.createContext(e.name)),this.events.emit("plugin-registered",e.name)}unregister(e){const t=this.plugins.get(e);if(t){if(t.destroy&&t.destroy(this.createContext(e)),t.toolbarItems)for(const i of t.toolbarItems)this.toolbarItems.delete(i.id);if(t.shortcuts&&(this.shortcuts=this.shortcuts.filter(i=>!t.shortcuts.some(n=>n.key===i.key))),t.patterns){const i=new Set(t.patterns.map(n=>n.name));this.renderers=this.renderers.filter(n=>!i.has(n.name))}if(t.components){const i=new Set(t.components.map(n=>n.name));this.renderers=this.renderers.filter(n=>!i.has(n.name))}if(t.parsers){const i=new Set(t.parsers.map(n=>n.name));this.parsers=this.parsers.filter(n=>!i.has(n.name))}this.completionsByPlugin.delete(e),this.tokenProvidersByPlugin.delete(e),this.plugins.delete(e),this.events.emit("plugin-removed",e)}}getToolbarItem(e){return this.toolbarItems.get(e)}getAllToolbarItems(){return this.toolbarItems}getShortcuts(){return this.shortcuts}getRenderers(){return this.renderers}getParsers(){return this.parsers}getCompletions(){const e=[];for(const t of this.completionsByPlugin.values())e.push(...t);return e}getTokenProviders(){const e=[];for(const t of this.tokenProvidersByPlugin.values())e.push(...t);return e}hasPlugin(e){return this.plugins.has(e)}getPlugin(e){return this.plugins.get(e)}createContext(e){return{editor:this.editorApi,registerToolbarItem:t=>this.toolbarItems.set(t.id,t),registerShortcut:t=>this.shortcuts.push(t),registerRenderer:t=>{this.renderers.push(t),this.renderers.sort((i,n)=>(n.priority??0)-(i.priority??0))},registerParser:t=>{this.parsers.push(t),this.parsers.sort((i,n)=>(n.priority??0)-(i.priority??0))},registerCompletion:t=>{const i=this.completionsByPlugin.get(e)??[];i.push(t),this.completionsByPlugin.set(e,i)},registerTokenProvider:t=>{const i=this.tokenProvidersByPlugin.get(e)??[];i.push(t),this.tokenProvidersByPlugin.set(e,i)},injectStyles:t=>this.injectStyles(t),emit:(t,i)=>this.events.emit(t,i),on:(t,i)=>this.events.on(t,i),off:(t,i)=>this.events.off(t,i)}}injectStyles(e){const t=document.createElement("style");t.setAttribute("data-syncline-mdx","plugin"),t.textContent=e,document.head.appendChild(t),this.styleElements.push(t)}destroy(){for(const[e]of this.plugins)this.unregister(e);for(const e of this.styleElements)e.remove();this.styleElements=[]}}function Yi(){var e;if(typeof navigator>"u")return!1;const s=navigator;return(e=s.userAgentData)!=null&&e.platform?/mac/i.test(s.userAgentData.platform):navigator.platform?/mac/i.test(navigator.platform):/Macintosh|MacIntel|MacPPC|Mac OS X/.test(navigator.userAgent)}function Ze(s){return Yi()?s.replace(/ctrl\+/gi,"⌘").replace(/shift\+/gi,"⇧").replace(/alt\+/gi,"⌥"):s.replace(/⌘/g,"Ctrl+").replace(/⇧/g,"Shift+").replace(/⌥/g,"Alt+")}class Qe{constructor(e,t,i,n){this.config=e,this.pluginManager=t,this.editorApi=i,this.events=n,this.activeDropdown=null,this.documentClickHandler=a=>{this.activeDropdown&&!this.activeDropdown.contains(a.target)&&this.closeDropdowns()}}render(e){this.el=document.createElement("div"),this.el.className="smdx-toolbar";for(const t of this.config){const i=document.createElement("div");i.className="smdx-toolbar-row",this.renderRow(t,i),this.el.appendChild(i)}return e.appendChild(this.el),document.addEventListener("click",this.documentClickHandler),this.el}renderRow(e,t){for(const i of e)typeof i=="string"?i==="|"?this.renderDivider(t):this.renderItem(i,t):"type"in i&&i.type==="divider"?this.renderDivider(t):"type"in i&&i.type==="group"&&this.renderGroup(i,t)}renderDivider(e){const t=document.createElement("span");t.className="smdx-toolbar-divider",e.appendChild(t)}renderItem(e,t){const i=this.pluginManager.getToolbarItem(e);if(i)if(i.children&&i.children.length>0)this.renderDropdownItem(i,t);else{const n=this.createButton(i);t.appendChild(n)}}renderGroup(e,t){if(e.display==="dropdown")this.renderDropdownGroup(e,t);else{const i=document.createElement("div");i.className="smdx-toolbar-group";for(const n of e.items)typeof n=="string"?this.renderItem(n,i):this.renderGroup(n,i);t.appendChild(i)}}renderDropdownGroup(e,t){const i=document.createElement("div");i.className="smdx-toolbar-dropdown";const n=document.createElement("button");n.className="smdx-toolbar-btn smdx-toolbar-dropdown-trigger",n.type="button",n.innerHTML=`${e.icon||""}<span class="smdx-toolbar-btn-label">${e.label||""}</span><svg class="smdx-dropdown-arrow" width="10" height="6" viewBox="0 0 10 6"><path d="M1 1l4 4 4-4" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>`,n.title=e.label||"",n.setAttribute("aria-label",e.label||"Dropdown"),n.setAttribute("aria-haspopup","true"),n.setAttribute("aria-expanded","false");const a=document.createElement("div");a.className="smdx-toolbar-dropdown-menu",a.setAttribute("role","menu"),a.style.display="none";for(const r of e.items)if(typeof r=="string"){const o=this.pluginManager.getToolbarItem(r);if(!o)continue;if(o.children&&o.children.length>0)this.renderSubmenu(o,a);else{const c=this.createMenuButton(o);a.appendChild(c)}}else{const o=document.createElement("div");if(o.className="smdx-toolbar-dropdown-section",r.label){const c=document.createElement("div");c.className="smdx-toolbar-dropdown-section-label",c.textContent=r.label,o.appendChild(c)}for(const c of r.items)if(typeof c=="string"){const d=this.pluginManager.getToolbarItem(c);if(d)if(d.children&&d.children.length>0)this.renderSubmenu(d,o);else{const l=this.createMenuButton(d);o.appendChild(l)}}a.appendChild(o)}n.addEventListener("click",r=>{r.stopPropagation(),this.toggleDropdown(a,i)}),i.appendChild(n),i.appendChild(a),t.appendChild(i)}renderDropdownItem(e,t){const i=document.createElement("div");i.className="smdx-toolbar-dropdown";const n=document.createElement("button");n.className="smdx-toolbar-btn smdx-toolbar-dropdown-trigger",n.type="button",n.innerHTML=`${e.icon||""}<span class="smdx-toolbar-btn-label">${e.label}</span><svg class="smdx-dropdown-arrow" width="10" height="6" viewBox="0 0 10 6"><path d="M1 1l4 4 4-4" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>`;const a=e.tooltip||e.label,r=e.shortcutLabel?Ze(e.shortcutLabel):void 0;n.title=r?`${a} (${r})`:a,n.setAttribute("aria-label",r?`${a} (${r})`:a),n.setAttribute("aria-haspopup","true"),n.setAttribute("aria-expanded","false");const o=document.createElement("div");o.className="smdx-toolbar-dropdown-menu",o.setAttribute("role","menu"),o.style.display="none";for(const c of e.children)if(c.children&&c.children.length>0)this.renderSubmenu(c,o);else{const d=this.createMenuButton(c);o.appendChild(d)}n.addEventListener("click",c=>{c.stopPropagation(),this.toggleDropdown(o,i)}),i.appendChild(n),i.appendChild(o),t.appendChild(i)}positionMenu(e,t){const i=t.getBoundingClientRect(),n=4;let a=i.bottom+n,r=i.left;e.style.top=a+"px",e.style.left=r+"px",e.style.visibility="hidden",e.style.display="",requestAnimationFrame(()=>{const o=e.getBoundingClientRect();o.right>window.innerWidth-4&&(r=i.right-o.width,e.style.left=Math.max(4,r)+"px"),o.bottom>window.innerHeight-4&&(a=i.top-o.height-n,e.style.top=Math.max(4,a)+"px"),e.style.visibility=""})}renderSubmenu(e,t){const i=document.createElement("div");i.className="smdx-toolbar-submenu";const n=document.createElement("button");n.className="smdx-toolbar-menu-btn smdx-toolbar-submenu-trigger",n.type="button",n.innerHTML=`${e.icon||""}<span>${e.label}</span><svg class="smdx-submenu-arrow" width="6" height="10" viewBox="0 0 6 10"><path d="M1 1l4 4-4 4" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>`;const a=document.createElement("div");a.className="smdx-toolbar-dropdown-menu smdx-toolbar-submenu-menu",a.style.display="none";for(const l of e.children)if(l.children&&l.children.length>0)this.renderSubmenu(l,a);else{const h=this.createMenuButton(l);a.appendChild(h)}const r=()=>{const l=i.getBoundingClientRect();a.style.left=`${l.right}px`,a.style.top=`${l.top}px`,requestAnimationFrame(()=>{const h=a.getBoundingClientRect();h.right>window.innerWidth&&(a.style.left=`${l.left-h.width}px`),h.bottom>window.innerHeight&&(a.style.top=`${window.innerHeight-h.height-8}px`)})};let o=null;const c=()=>{o&&(clearTimeout(o),o=null),a.style.display="",r()},d=()=>{o&&clearTimeout(o),o=setTimeout(()=>{a.style.display="none",o=null},120)};n.addEventListener("mouseenter",c),a.addEventListener("mouseenter",c),i.addEventListener("mouseleave",d),a.addEventListener("mouseleave",d),i.appendChild(n),i.appendChild(a),t.appendChild(i)}createButton(e){const t=document.createElement("button");t.className=`smdx-toolbar-btn${e.className?" "+e.className:""}`,t.type="button",t.tabIndex=0;const i=e.tooltip||e.label,n=e.shortcutLabel?Ze(e.shortcutLabel):void 0;return t.title=n?`${i} (${n})`:i,t.setAttribute("aria-label",n?`${i} (${n})`:i),t.dataset.toolbarId=e.id,e.icon?t.innerHTML=e.icon:t.textContent=e.label,n&&t.setAttribute("data-shortcut",n),t.addEventListener("click",a=>{a.preventDefault(),this.executeAction(e)}),e.render&&e.render(t,this.getActionContext()),t}createMenuButton(e){const t=document.createElement("button");return t.className=`smdx-toolbar-menu-btn${e.className?" "+e.className:""}`,t.type="button",t.setAttribute("role","menuitem"),t.dataset.toolbarId=e.id,t.innerHTML=`${e.icon||""}<span>${e.label}</span>${e.shortcutLabel?`<span class="smdx-shortcut-label">${Ze(e.shortcutLabel)}</span>`:""}`,t.addEventListener("click",i=>{i.preventDefault(),this.closeDropdowns(),this.executeAction(e)}),t}executeAction(e){var i;const t=this.getActionContext();(i=e.isDisabled)!=null&&i.call(e,t)||(e.action(t),this.events.emit("toolbar-action",e.id))}getActionContext(){return{editor:this.editorApi,selection:this.editorApi.getSelection()}}toggleDropdown(e,t){var i,n;if(e.style.display==="none"){this.closeDropdowns();const a=t.querySelector(".smdx-toolbar-dropdown-trigger");a?this.positionMenu(e,a):e.style.display="",this.activeDropdown=t,(i=t.querySelector(".smdx-toolbar-dropdown-trigger"))==null||i.setAttribute("aria-expanded","true")}else e.style.display="none",e.style.visibility="",(n=t.querySelector(".smdx-toolbar-dropdown-trigger"))==null||n.setAttribute("aria-expanded","false"),this.activeDropdown=null}closeDropdowns(){var e,t;(e=this.el)==null||e.querySelectorAll(".smdx-toolbar-dropdown-menu").forEach(i=>{i.style.display="none",i.style.visibility=""}),(t=this.el)==null||t.querySelectorAll('[aria-expanded="true"]').forEach(i=>{i.setAttribute("aria-expanded","false")}),this.activeDropdown=null}updateActiveStates(){var t;const e=this.getActionContext();(t=this.el)==null||t.querySelectorAll("[data-toolbar-id]").forEach(i=>{const n=i.dataset.toolbarId,a=this.pluginManager.getToolbarItem(n);a!=null&&a.isActive&&i.classList.toggle("smdx-active",a.isActive(e)),a!=null&&a.isDisabled&&(i.disabled=a.isDisabled(e))})}destroy(){var e;document.removeEventListener("click",this.documentClickHandler),(e=this.el)==null||e.remove()}}const Xi=new Set(["script","style","object","embed","base","form","input","link","meta","noscript","applet","frame","frameset"]),Ji=["https://www.youtube.com/embed/","https://youtube.com/embed/","https://codepen.io/","https://codesandbox.io/embed/"];function Zi(s){return Ji.some(e=>s.startsWith(e))}const wt=/^on/i,Qi=/^\s*javascript\s*:/i;function en(s){if(typeof document>"u")return s;const t=new DOMParser().parseFromString(`<!DOCTYPE html><body>${s}</body>`,"text/html"),i=document.createTreeWalker(t.body,NodeFilter.SHOW_ELEMENT),n=[];let a=i.currentNode;for(;a;){if(a.nodeType===Node.ELEMENT_NODE){const r=a,o=r.tagName.toLowerCase();if(Xi.has(o))n.push(r);else if(o==="iframe"){const c=r.getAttribute("src")||"";if(!Zi(c))n.push(r);else{const d=[];for(const l of Array.from(r.attributes))wt.test(l.name)&&d.push(l.name);for(const l of d)r.removeAttribute(l)}}else{const c=[];for(const d of Array.from(r.attributes))(wt.test(d.name)||(d.name==="href"||d.name==="src"||d.name==="action")&&Qi.test(d.value))&&c.push(d.name);for(const d of c)r.removeAttribute(d)}}a=i.nextNode()}for(const r of n)r.remove();return t.body.innerHTML}const tn={js:"JavaScript",javascript:"JavaScript",ts:"TypeScript",typescript:"TypeScript",py:"Python",python:"Python",java:"Java",rb:"Ruby",ruby:"Ruby",go:"Go",rust:"Rust",rs:"Rust",cpp:"C++",c:"C",cs:"C#",csharp:"C#",php:"PHP",swift:"Swift",kt:"Kotlin",kotlin:"Kotlin",scala:"Scala",sh:"Shell",bash:"Bash",zsh:"Zsh",sql:"SQL",html:"HTML",css:"CSS",scss:"SCSS",less:"LESS",json:"JSON",yaml:"YAML",yml:"YAML",xml:"XML",md:"Markdown",markdown:"Markdown",graphql:"GraphQL",dart:"Dart",r:"R",lua:"Lua",perl:"Perl",text:"Text",txt:"Text"};class _t{escapeHtml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}renderBlock(e,t,i){let n;const a=i.trimEnd();try{e&&ne.getLanguage(e)?n=ne.highlight(a,{language:e}).value:n=ne.highlightAuto(a).value}catch{n=this.escapeHtml(a)}const r=e?tn[e.toLowerCase()]||e.charAt(0).toUpperCase()+e.slice(1):"",o=r?`<span class="smdx-code-lang">${r}</span>`:"",c=t?`<span class="smdx-code-filename"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>${this.escapeHtml(t)}</span>`:"",d='<button class="smdx-copy-btn" data-copy-btn="true" title="Copy code" aria-label="Copy code"><svg class="smdx-copy-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg><svg class="smdx-check-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg></button>',l=!!(r||t),h=l?`<div class="smdx-code-header">${o}${c}${d}</div>`:"";return`<div class="smdx-code-block${l?" smdx-has-header":""}">${h}<pre><code class="hljs language-${e||"text"}">${n}</code></pre>${l?"":d}</div>`}}class vt{parseTableRow(e){return e.split("|").slice(1,-1).map(t=>t.trim())}render(e){const t=/(?:^[ \t]*(\|.+\|)\n[ \t]*(\|[-| :]+\|)\n((?:[ \t]*\|.+\|\n?)*))/gm;return e.replace(t,(i,n,a,r)=>{const o=this.parseTableRow(n),c=r.trim().split(`
2
2
  `).filter(Boolean).map(l=>this.parseTableRow(l));let d='<div class="smdx-table-wrapper"><table class="smdx-table"><thead><tr>';for(const l of o)d+=`<th>${l}</th>`;d+="</tr></thead><tbody>";for(const l of c){d+="<tr>";for(const h of l)d+=`<td>${h}</td>`;d+="</tr>"}return d+="</tbody></table></div>",d})}}class Ct{isListItem(e){return/^\s*[-*]\s+/.test(e)||/^\s*\d+\.\s+/.test(e)}buildNestedList(e){var c,d,l;if(e.length===0)return"";const t=((c=e[0].match(/^(\s*)/))==null?void 0:c[1].length)??0,i=/^\s*\d+\.\s+/.test(e[0]),n=i?"ol":"ul",a=i?"smdx-ol-item":"smdx-ul-item";let r=`<${n}>`,o=0;for(;o<e.length;){const h=e[o],p=((d=h.match(/^(\s*)/))==null?void 0:d[1].length)??0;if(p<t)break;if(p>t){o++;continue}const u=i?h.replace(/^\s*\d+\.\s+/,""):h.replace(/^\s*[-*]\s+/,"");o++;const m=[];for(;o<e.length&&((((l=e[o].match(/^(\s*)/))==null?void 0:l[1].length)??0)>t&&this.isListItem(e[o]));)m.push(e[o]),o++;const g=m.length>0?this.buildNestedList(m):"";r+=`<li class="${a}">${u}${g}</li>`}return r+=`</${n}>`,r}render(e){var a,r;const t=e.split(`
3
3
  `),i=[];let n=0;for(;n<t.length;)if(this.isListItem(t[n])){const o=[],c=((a=t[n].match(/^(\s*)/))==null?void 0:a[1].length)??0;for(;n<t.length;)if(this.isListItem(t[n]))o.push(t[n]),n++;else if(t[n].trim()===""){let d=n+1;for(;d<t.length&&t[d].trim()==="";)d++;if(d<t.length&&this.isListItem(t[d])&&(((r=t[d].match(/^(\s*)/))==null?void 0:r[1].length)??0)>c){n=d;continue}break}else break;i.push(this.buildNestedList(o))}else i.push(t[n]),n++;return i.join(`
4
- `)}}class Tt{constructor(){this.codeRenderer=new _t,this.tableRenderer=new vt,this.listRenderer=new Ct}escapeHtml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}render(e){let t=e;const i=[];t=t.replace(/```(\w*)(?:[\t ]+([\w.\/ \-]+?))?\n([\s\S]*?)```/g,(a,r,o,c)=>{const d=i.length;return i.push(this.codeRenderer.renderBlock(r,o,c)),`%%CODEBLOCK_${d}%%`}),t=t.replace(/`([^`]+)`/g,(a,r)=>`<code class="smdx-inline-code">${this.escapeHtml(r)}</code>`);const n=a=>a.toLowerCase().replace(/[^\w]+/g,"-").replace(/^-|-$/g,"");t=t.replace(/^######\s+(.+)$/gm,(a,r)=>`<h6 id="${n(r)}">${r}</h6>`),t=t.replace(/^#####\s+(.+)$/gm,(a,r)=>`<h5 id="${n(r)}">${r}</h5>`),t=t.replace(/^####\s+(.+)$/gm,(a,r)=>`<h4 id="${n(r)}">${r}</h4>`),t=t.replace(/^###\s+(.+)$/gm,(a,r)=>`<h3 id="${n(r)}">${r}</h3>`),t=t.replace(/^##\s+(.+)$/gm,(a,r)=>`<h2 id="${n(r)}">${r}</h2>`),t=t.replace(/^#\s+(.+)$/gm,(a,r)=>`<h1 id="${n(r)}">${r}</h1>`),t=t.replace(/^---$/gm,"<hr/>"),t=t.replace(/\*\*\*(.+?)\*\*\*/g,"<strong><em>$1</em></strong>"),t=t.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*(.+?)\*/g,"<em>$1</em>"),t=t.replace(/~~(.+?)~~/g,"<del>$1</del>"),t=t.replace(/((?:^>[ \t]*.+\n?)+)/gm,a=>"<blockquote>"+a.trimEnd().split(`
4
+ `)}}class Tt{constructor(){this.codeRenderer=new _t,this.tableRenderer=new vt,this.listRenderer=new Ct}escapeHtml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}render(e){let t=e;const i=[];t=t.replace(/```(\w*)(?:[\t ]+([\w.\/ \-]+?))?\n([\s\S]*?)```/g,(a,r,o,c)=>{const d=i.length;return i.push(this.codeRenderer.renderBlock(r,o,c)),`%%CODEBLOCK_${d}%%`}),t=t.replace(/`([^`]+)`/g,(a,r)=>`<code class="smdx-inline-code">${this.escapeHtml(r)}</code>`);const n=a=>a.replace(/<[^>]+>/g,"").toLowerCase().replace(/[^\w]+/g,"-").replace(/^-|-$/g,"");t=t.replace(/^######\s+(.+)$/gm,(a,r)=>`<h6 id="${n(r)}">${r}</h6>`),t=t.replace(/^#####\s+(.+)$/gm,(a,r)=>`<h5 id="${n(r)}">${r}</h5>`),t=t.replace(/^####\s+(.+)$/gm,(a,r)=>`<h4 id="${n(r)}">${r}</h4>`),t=t.replace(/^###\s+(.+)$/gm,(a,r)=>`<h3 id="${n(r)}">${r}</h3>`),t=t.replace(/^##\s+(.+)$/gm,(a,r)=>`<h2 id="${n(r)}">${r}</h2>`),t=t.replace(/^#\s+(.+)$/gm,(a,r)=>`<h1 id="${n(r)}">${r}</h1>`),t=t.replace(/^---$/gm,"<hr/>"),t=t.replace(/\*\*\*(.+?)\*\*\*/g,"<strong><em>$1</em></strong>"),t=t.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*(.+?)\*/g,"<em>$1</em>"),t=t.replace(/~~(.+?)~~/g,"<del>$1</del>"),t=t.replace(/((?:^>[ \t]*.+\n?)+)/gm,a=>"<blockquote>"+a.trimEnd().split(`
5
5
  `).map(o=>o.replace(/^>[ \t]*/,"")).join("<br>")+"</blockquote>"),t=t.replace(/^- \[x\]\s+(.+)$/gm,'<div class="smdx-task"><span class="smdx-task-checkbox smdx-task-checked" role="checkbox" aria-checked="true" tabindex="0"></span><span>$1</span></div>'),t=t.replace(/^- \[ \]\s+(.+)$/gm,'<div class="smdx-task"><span class="smdx-task-checkbox" role="checkbox" aria-checked="false" tabindex="0"></span><span>$1</span></div>'),t=this.listRenderer.render(t),t=t.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,'<img src="$2" alt="$1" class="smdx-image"/>'),t=t.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(a,r,o)=>`<a href="${/^(https?|mailto|ftp|tel):\/\//i.test(o)||o.startsWith("#")||o.startsWith("/")||o.startsWith("./")||o.startsWith("../")?o:`https://${o}`}" target="_blank" rel="noopener noreferrer">${r}</a>`),t=this.tableRenderer.render(t),t=t.replace(/ {2,}$/gm,"<br/>"),t=t.replace(/^(?!\s*<[a-zA-Z/!]|\s*%%)(.*\S.*)$/gm,"<p>$1</p>"),t=t.replace(/<p>\s*<\/p>/g,"");for(let a=0;a<i.length;a++)t=t.replace(`%%CODEBLOCK_${a}%%`,i[a]);return t}}class Et{validate(e){const t=[];let i=e.replace(/```[\s\S]*?```/g,"");i=i.replace(/`[^`]+`/g,"");const n=[],a=i.split(`
6
6
  `);for(let r=0;r<a.length;r++){const o=a[r];let c;const d=/<\/?([A-Z][A-Za-z0-9]*)(?:\s[^>]*)?\/?>|<([A-Z][A-Za-z0-9]*)(?:\s[^>]*)?>/g;for(;(c=d.exec(o))!==null;){const l=c[0];if(l.endsWith("/>"))continue;const h=c[1]||c[2];if(!h)continue;const p=c.index+1;if(l.startsWith("</")){let m=!1;for(let g=n.length-1;g>=0;g--)if(n[g].tag===h){n.splice(g,1),m=!0;break}m||t.push(`Unexpected closing tag '</${h}>' at line ${r+1}:${p} — no matching opening tag found.`)}else n.push({tag:h,line:r+1,col:p})}}for(const r of n)t.push(`Expected a closing tag for '<${r.tag}>' (${r.line}:${r.col}) before the end of the document.`);return t}}class we{constructor(){this.renderers=[],this.parsers=[],this.markdownRenderer=new Tt,this.mdxValidator=new Et}setRenderers(e){this.renderers=e}setParsers(e){this.parsers=e}async render(e){let t=e;const i=this.mdxValidator.validate(e),n=[];t=t.replace(/`([^`\n]+)`/g,(a,r)=>{const o=n.length;return n.push(r),`%%INLINECODE_${o}%%`});for(const a of this.parsers)t=t.replace(a.pattern,(...r)=>a.transform(r));for(const a of this.renderers)t=t.replace(a.pattern,(r,...o)=>{const c={};return o.length>0&&(c.content=o[0]||""),a.render(r,c)});for(let a=0;a<n.length;a++){const r=`\`${n[a]}\``;t=t.replace(`%%INLINECODE_${a}%%`,()=>r)}if(t=this.markdownRenderer.render(t),i.length>0){const a=o=>o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");t=i.map(o=>`<div class="smdx-parse-error"><span class="smdx-parse-error-icon">&#9888;</span> ${a(o)}</div>`).join("")+t}return en(t)}}const Ye=class Ye{constructor(e,t,i){this.isDragging=!1,this.startX=0,this.startLeftWidth=0,this.onResizeCallback=null,this.resizeRafId=null,this.onMouseDown=n=>{this.startDrag(n.clientX),n.preventDefault()},this.onMouseMove=n=>{this.isDragging&&this.moveDrag(n.clientX)},this.onMouseUp=()=>{this.endDrag()},this.onTouchStart=n=>{n.touches.length===1&&(this.startDrag(n.touches[0].clientX),n.preventDefault())},this.onTouchMove=n=>{!this.isDragging||n.touches.length!==1||(this.moveDrag(n.touches[0].clientX),n.preventDefault())},this.onTouchEnd=()=>{this.endDrag()},this.onKeyDown=n=>{if(n.key!=="ArrowLeft"&&n.key!=="ArrowRight")return;n.preventDefault();const a=this.container.getBoundingClientRect().width;if(a<=0)return;const r=this.left.getBoundingClientRect().width,o=a*Ye.KEYBOARD_STEP_PERCENT,c=n.key==="ArrowRight"?o:-o;let d=(r+c)/a*100;d=Math.max(20,Math.min(80,d)),this.left.style.flex=`0 0 ${d}%`,this.right.style.flex="1 1 0",this.notifyResize()},this.container=e,this.left=t,this.right=i,this.splitter=document.createElement("div"),this.splitter.className="smdx-splitter",this.splitter.setAttribute("role","separator"),this.splitter.setAttribute("aria-label","Resize editor and preview"),this.splitter.setAttribute("tabindex","0"),t.after(this.splitter),this.splitter.addEventListener("mousedown",this.onMouseDown),document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onMouseUp),this.splitter.addEventListener("touchstart",this.onTouchStart,{passive:!1}),document.addEventListener("touchmove",this.onTouchMove,{passive:!1}),document.addEventListener("touchend",this.onTouchEnd),this.splitter.addEventListener("keydown",this.onKeyDown)}onResize(e){this.onResizeCallback=e}startDrag(e){this.isDragging=!0,this.startX=e,this.startLeftWidth=this.left.getBoundingClientRect().width,document.body.style.cursor="col-resize",document.body.style.userSelect="none",this.right.style.pointerEvents="none"}moveDrag(e){const t=e-this.startX,i=this.container.getBoundingClientRect().width;if(i<=0)return;let n=(this.startLeftWidth+t)/i*100;n=Math.max(20,Math.min(80,n)),this.left.style.flex=`0 0 ${n}%`,this.right.style.flex="1 1 0",this.notifyResize()}endDrag(){this.isDragging&&(this.isDragging=!1,document.body.style.cursor="",document.body.style.userSelect="",this.right.style.pointerEvents="",this.notifyResize())}notifyResize(){var e;this.resizeRafId===null&&(typeof requestAnimationFrame<"u"?this.resizeRafId=requestAnimationFrame(()=>{var t;this.resizeRafId=null,(t=this.onResizeCallback)==null||t.call(this)}):(e=this.onResizeCallback)==null||e.call(this))}destroy(){document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp),document.removeEventListener("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onTouchEnd),this.splitter.removeEventListener("mousedown",this.onMouseDown),this.splitter.removeEventListener("touchstart",this.onTouchStart),this.splitter.removeEventListener("keydown",this.onKeyDown),this.resizeRafId!==null&&typeof cancelAnimationFrame<"u"&&cancelAnimationFrame(this.resizeRafId),this.splitter.remove()}};Ye.KEYBOARD_STEP_PERCENT=.02;let _e=Ye;var nn=Object.defineProperty,an=(s,e,t)=>e in s?nn(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,_=(s,e,t)=>an(s,typeof e!="symbol"?e+"":e,t);const sn=new Set(["function","const","let","var","return","if","else","for","while","class","import","export","default","async","await","new","this","typeof","instanceof","try","catch","finally","throw","extends","as","from","of","in","void","switch","case","break","continue","do","delete","yield","super","null","true","false","undefined","require","constructor","static"]),rn=new Set(["number","string","boolean","object","Promise","Array","Map","Set","HTMLElement","KeyboardEvent","Float64Array","EventListener","Document","Window","Node","Element","Event","MouseEvent","CustomEvent"]),on=[{label:"console.log",kind:"fn",detail:"void",language:"javascript"},{label:"console.error",kind:"fn",detail:"void",language:"javascript"},{label:"console.warn",kind:"fn",detail:"void",language:"javascript"},{label:"console.table",kind:"fn",detail:"void",language:"javascript"},{label:"document.getElementById",kind:"fn",detail:"HTMLElement | null",language:"javascript"},{label:"document.querySelector",kind:"fn",detail:"Element | null",language:"javascript"},{label:"document.querySelectorAll",kind:"fn",detail:"NodeList",language:"javascript"},{label:"document.createElement",kind:"fn",detail:"HTMLElement",language:"javascript"},{label:"addEventListener",kind:"fn",detail:"(ev, cb) => void",language:"javascript"},{label:"removeEventListener",kind:"fn",detail:"(ev, cb) => void",language:"javascript"},{label:"setTimeout",kind:"fn",detail:"(cb, ms) => id",language:"javascript"},{label:"clearTimeout",kind:"fn",detail:"(id) => void",language:"javascript"},{label:"setInterval",kind:"fn",detail:"(cb, ms) => id",language:"javascript"},{label:"clearInterval",kind:"fn",detail:"(id) => void",language:"javascript"},{label:"requestAnimationFrame",kind:"fn",detail:"(cb) => number",language:"javascript"},{label:"JSON.stringify",kind:"fn",detail:"string",language:"javascript"},{label:"JSON.parse",kind:"fn",detail:"any",language:"javascript"},{label:"Math.max",kind:"fn",detail:"number",language:"javascript"},{label:"Math.min",kind:"fn",detail:"number",language:"javascript"},{label:"Math.floor",kind:"fn",detail:"number",language:"javascript"},{label:"Math.ceil",kind:"fn",detail:"number",language:"javascript"},{label:"Math.round",kind:"fn",detail:"number",language:"javascript"},{label:"Math.abs",kind:"fn",detail:"number",language:"javascript"},{label:"Math.sqrt",kind:"fn",detail:"number",language:"javascript"},{label:"Math.random",kind:"fn",detail:"number",language:"javascript"},{label:"Object.keys",kind:"fn",detail:"string[]",language:"javascript"},{label:"Object.values",kind:"fn",detail:"any[]",language:"javascript"},{label:"Object.entries",kind:"fn",detail:"[string, any][]",language:"javascript"},{label:"Object.assign",kind:"fn",detail:"T & U",language:"javascript"},{label:"Object.freeze",kind:"fn",detail:"Readonly<T>",language:"javascript"},{label:"Array.from",kind:"fn",detail:"T[]",language:"javascript"},{label:"Array.isArray",kind:"fn",detail:"boolean",language:"javascript"},{label:"Promise.all",kind:"fn",detail:"Promise<T[]>",language:"javascript"},{label:"Promise.resolve",kind:"fn",detail:"Promise<T>",language:"javascript"},{label:"Promise.reject",kind:"fn",detail:"Promise<never>",language:"javascript"},{label:"fetch",kind:"fn",detail:"Promise<Response>",language:"javascript"},{label:"parseInt",kind:"fn",detail:"number",language:"javascript"},{label:"parseFloat",kind:"fn",detail:"number",language:"javascript"},{label:"arrowfn",kind:"snip",detail:"arrow function",body:`const $1 = ($2) => {
7
7
  $3
@@ -1125,7 +1125,7 @@ $$`},{label:"copy",kind:"snip",detail:"<CopyText> clickable copy block",body:"<C
1125
1125
  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 18l6-6-6-6"/></svg>
1126
1126
  </button>
1127
1127
  `,e.querySelector(".smdx-toc-close-btn").addEventListener("click",()=>{this.tocCollapsed=!0,this.buildTocPanel()});const t=document.createElement("div");t.className="smdx-toc-body";const i=document.createElement("div");i.className="smdx-toc-footer",i.textContent="0 headings",this.tocContainer.appendChild(e),this.tocContainer.appendChild(t),this.tocContainer.appendChild(i)}refreshToc(){if(this.tocCollapsed)return;const e=this.tocContainer.querySelector(".smdx-toc-body"),t=this.tocContainer.querySelector(".smdx-toc-footer");if(!e||!t)return;const i=this.textarea.value,n=[];let a=!1;for(const r of i.split(`
1128
- `)){if(r.trim().startsWith("```")){a=!a;continue}if(a)continue;const o=r.match(/^(#{1,6})\s+(.+)/);if(o){const c=o[1].length,d=o[2].replace(/[*_`~\[\]]/g,"").trim(),l=d.toLowerCase().replace(/[^\w\s-]/g,"").replace(/\s+/g,"-");n.push({level:c,text:d,slug:l})}}if(n.length===0)e.innerHTML='<div class="smdx-toc-empty">No headings found.</div>';else{const r=document.createElement("nav");r.className="smdx-toc-nav";const o=this.previewContent;n.forEach(c=>{const d=document.createElement("button");d.type="button",d.className=`smdx-toc-item smdx-toc-h${c.level}`,d.style.paddingLeft=`${(c.level-1)*12+8}px`,d.textContent=c.text,d.title=c.text,d.addEventListener("click",()=>{const l=o.querySelector(`#${CSS.escape(c.slug)}`);l&&l.scrollIntoView({behavior:"smooth",block:"start"})}),r.appendChild(d)}),e.innerHTML="",e.appendChild(r)}t.textContent=`${n.length} heading${n.length!==1?"s":""}`}toggleToc(){this.tocCollapsed=!this.tocCollapsed,this.buildTocPanel(),this.tocCollapsed||this.refreshToc()}getValue(){return this.codeEditor.getValue()}setValue(e){this.codeEditor.setValue(e),this.textarea.value=e,this.scheduleRender(),this.events.emit("change",e)}insertText(e){this.codeEditor.insertText(e),this.codeEditor.focus()}wrapSelection(e,t){const{start:i,end:n,text:a}=this.getSelection(),r=this.codeEditor.getValue(),o=a||"text",c=e+o+t,d=r.substring(0,i)+c+r.substring(n);this.codeEditor.setValue(d);const l=i+e.length,h=l+o.length;this.setSelection(l,h),this.codeEditor.focus()}replaceSelection(e){const{start:t,end:i}=this.getSelection(),n=this.codeEditor.getValue(),a=n.substring(0,t)+e+n.substring(i);this.codeEditor.setValue(a);const r=this.offsetToPos(t+e.length);this.codeEditor.setCursor(r),this.codeEditor.focus()}getSelection(){const e=this.codeEditor.getValue(),t=this.codeEditor.getSelection(),i=this.codeEditor.getCursor();if(!t){const c=this.posToOffset(i.row,i.col);return{start:c,end:c,text:"",beforeText:e.substring(0,c),afterText:e.substring(c)}}const n=this.posToOffset(t.ar,t.ac),a=this.posToOffset(t.fr,t.fc),r=Math.min(n,a),o=Math.max(n,a);return{start:r,end:o,text:e.substring(r,o),beforeText:e.substring(0,r),afterText:e.substring(o)}}setSelection(e,t){const i=this.offsetToPos(e),n=this.offsetToPos(t),a={ar:i.row,ac:i.col,fr:n.row,fc:n.col};this.codeEditor.setSelection(a),this.codeEditor.focus()}insertBlock(e){const{start:t,end:i}=this.getSelection(),n=this.codeEditor.getValue(),a=n.substring(0,t),r=n.substring(i),o=a.length>0&&!a.endsWith(`
1128
+ `)){if(r.trim().startsWith("```")){a=!a;continue}if(a)continue;const o=r.match(/^(#{1,6})\s+(.+)/);if(o){const c=o[1].length,d=o[2].replace(/[*_`~\[\]]/g,"").trim(),l=d.toLowerCase().replace(/[^\w]+/g,"-").replace(/^-|-$/g,"");n.push({level:c,text:d,slug:l})}}if(n.length===0)e.innerHTML='<div class="smdx-toc-empty">No headings found.</div>';else{const r=document.createElement("nav");r.className="smdx-toc-nav";const o=this.previewContent;n.forEach(c=>{const d=document.createElement("button");d.type="button",d.className=`smdx-toc-item smdx-toc-h${c.level}`,d.style.paddingLeft=`${(c.level-1)*12+8}px`,d.textContent=c.text,d.title=c.text,d.addEventListener("click",()=>{const l=o.querySelector(`#${CSS.escape(c.slug)}`);l&&l.scrollIntoView({behavior:"smooth",block:"start"})}),r.appendChild(d)}),e.innerHTML="",e.appendChild(r)}t.textContent=`${n.length} heading${n.length!==1?"s":""}`}toggleToc(){this.tocCollapsed=!this.tocCollapsed,this.buildTocPanel(),this.tocCollapsed||this.refreshToc()}getValue(){return this.codeEditor.getValue()}setValue(e){this.codeEditor.setValue(e),this.textarea.value=e,this.scheduleRender(),this.events.emit("change",e)}insertText(e){this.codeEditor.insertText(e),this.codeEditor.focus()}wrapSelection(e,t){const{start:i,end:n,text:a}=this.getSelection(),r=this.codeEditor.getValue(),o=a||"text",c=e+o+t,d=r.substring(0,i)+c+r.substring(n);this.codeEditor.setValue(d);const l=i+e.length,h=l+o.length;this.setSelection(l,h),this.codeEditor.focus()}replaceSelection(e){const{start:t,end:i}=this.getSelection(),n=this.codeEditor.getValue(),a=n.substring(0,t)+e+n.substring(i);this.codeEditor.setValue(a);const r=this.offsetToPos(t+e.length);this.codeEditor.setCursor(r),this.codeEditor.focus()}getSelection(){const e=this.codeEditor.getValue(),t=this.codeEditor.getSelection(),i=this.codeEditor.getCursor();if(!t){const c=this.posToOffset(i.row,i.col);return{start:c,end:c,text:"",beforeText:e.substring(0,c),afterText:e.substring(c)}}const n=this.posToOffset(t.ar,t.ac),a=this.posToOffset(t.fr,t.fc),r=Math.min(n,a),o=Math.max(n,a);return{start:r,end:o,text:e.substring(r,o),beforeText:e.substring(0,r),afterText:e.substring(o)}}setSelection(e,t){const i=this.offsetToPos(e),n=this.offsetToPos(t),a={ar:i.row,ac:i.col,fr:n.row,fc:n.col};this.codeEditor.setSelection(a),this.codeEditor.focus()}insertBlock(e){const{start:t,end:i}=this.getSelection(),n=this.codeEditor.getValue(),a=n.substring(0,t),r=n.substring(i),o=a.length>0&&!a.endsWith(`
1129
1129
  `),c=r.length>0&&!r.startsWith(`
1130
1130
  `),d=(o?`
1131
1131
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.0.0",
6
+ "version": "2.0.1",
7
7
  "description": "Framework-agnostic, plugin-based MDX/Markdown editor with toolbar customization and live preview",
8
8
  "type": "module",
9
9
  "main": "dist/syncline-mdx-editor.umd.cjs",