@mrakomor/core 0.0.12 → 0.0.13

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.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';(function(){if(!(typeof document>"u")){var t="mrakomor/core/style/core.css",e=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(o){return o.getAttribute("data-mrakomor-css-path")===t});if(!e){var n=document.createElement("style");n.setAttribute("data-mrakomor-css",""),n.setAttribute("data-mrakomor-css-path",t),n.textContent=`.namespace-unknown-unknowncomponent{background-color:#f0f0f0;padding:12px 0;margin-bottom:8px}.mrakomor-editor:focus-visible{outline:none}.mrakomor-editor{display:flex;flex-direction:column;height:100%;min-height:0}.mrakomor-editor-surface{position:relative;flex:1 1 auto;min-height:0}.mrakomor-tools-container{position:absolute;inset:0;pointer-events:none;z-index:4}.mrakomor-content{position:relative;height:100%;min-height:0;overflow-y:auto}.mrakomor-content:focus-visible{outline:none}
2
- `,document.head.appendChild(n);}}})();var zt=class{next(...t){}error(...t){}complete(...t){}},be=class{#e=new Set;pipe(...t){return t.reduce((e,n)=>n(e),this)}next(...t){Array.from(this.#e).forEach(e=>{typeof e=="function"?e(...t):e.next(...t);});}error(...t){Array.from(this.#e).forEach(e=>{e?.error?.(...t),this.unsubscribe(e);});}complete(...t){Array.from(this.#e).forEach(e=>{e?.complete?.(...t),this.unsubscribe(e);});}subscribe(t){return this.#e.add(t),{unsubscribe:()=>{this.unsubscribe(t);}}}unsubscribe(t){this.#e.delete(t);}};var Be=Symbol("@esmj/signals:type"),Se=Symbol("@esmj/signals:name");var L=null,lt=false,ut=[];function H(t){let e=L;L=null;let n=t();return L=e,n}function po(){lt=false;let t=Vt();for(let n of t)n.get();let e=ut;ut=[];for(let n of e)n();}function Gt(){lt||(lt=true,queueMicrotask(po));}function ft(t){ut.push(t),Gt();}var qt=Symbol("@esmj/signals:internal observable"),K=Symbol("@esmj/signals:original function"),go=class extends be{#e=new Set;#n=null;constructor(t){super(),this.#n=t,this.pipe(e=>{let n=e.subscribe.bind(e),o=e.unsubscribe.bind(e);return e.subscribe=r=>{n(r),this.#e.add(r);},e.unsubscribe=r=>{o(r),this.#e.delete(r);},e});}watch(t){if(typeof t.next!="function"&&(t.next=()=>H(()=>{this.#e.add(t),this.#n();}),t.next[K]=void 0),t instanceof Jt&&t.next[K]===void 0){let e=t.next.bind(t);t.next=()=>H(()=>{this.#e.add(t),e(),this.#n();}),t.next[K]=e;}return this.subscribe(t)}getPending(){let t=[];for(let e of this.#e){if(!e.get[K]){let n=e.get,o=n.bind(e);e.get=()=>H(()=>(this.#e.delete(e),o())),e.get[K]=n;}t.push(e);}return t}unwatch(t){return t.next=t.next[K]?t.next[K]:t.next,t.get=t.get[K]?t.get[K]:t.get,this.#e.delete(t),this.unsubscribe(t)}},Me=null;function Yt(t){Me=new go(t);}Yt(()=>{Gt();});function Vt(){return Me.getPending()}function Wt(t){return Me.watch(t)}function Xt(t){return Me.unwatch(t)}var F=Symbol("@esmj/signals:no error"),Jt=class Qt extends zt{#e=true;#n=false;#r=null;#t=this.#f();#o=null;#i=null;#c=0;#a=new Map;#s=F;constructor(e,n){super(),this.#o=e,this.#i=n,this.debug=n?.debug,this[Be]="computed",this[Se]=n?.debug??null,this.get=this.get.bind(this);}#u(){for(let{unsubscribe:e}of this.#t.dependencies.values())e();this.#t.dependencies.clear();}#f(){return {dependencies:new Map,sourceRevisions:new Map,observer:this}}getRevision(){return this.#c}getDebugInfo(){return {name:this[Se],dirty:this.#e,revision:this.#c,sourceDependencies:[...this.#a.keys()]}}#l(){for(let[e,n]of this.#a)if(e instanceof Qt&&H(()=>e.get()),e.getRevision()!==n)return true;return false}next(){this.#e=true,this.#r[qt].next();}get(){if(this.#n)throw new Error("Cycle detected in computed signal");if(this.#r||(this.#r=S(this.#m(),this.#i)),(this.#e||this.#s!==F)&&(this.#a.size===0||this.#l()?this.#m():this.#e=false),L&&L.sourceRevisions.set(this,this.#c),this.#s!==F)throw this.#s;return this.#r.get()}peek(){if(this.#r||(this.#r=S(this.#m(),this.#i)),(this.#e||this.#s!==F)&&(this.#a.size===0||this.#l()?this.#m():this.#e=false),this.#s!==F)throw this.#s;return this.#r.peek()}#m(){this.#n=true,this.#e=false,this.#s=F,this.#u(),this.#t.sourceRevisions.clear();let e=L;L=this.#t;let n;try{n=this.#o();}catch(o){this.#s=o;}return L=e,this.#a=this.#t.sourceRevisions,this.#t.sourceRevisions=new Map,this.#n=false,n instanceof Promise&&(n=n.then(o=>{this.#s=F,this.#r.set(o);}).catch(o=>{this.#s=o;})),this.#s===F&&this.#r&&this.#r.set(n),this.#c++,n}destroy(){this.#u(),this.#a.clear(),this.#e=true,this.#s=F;}};function M(t,e){return new Jt(t,e)}function P(t,e){let n,{debug:o,...r}={},s=M(()=>{n?.(),n=t();},{equals:()=>false,...r});s.get(),Wt(s);let i=()=>{n?.(),s.destroy(),Xt(s);};return i[Symbol.dispose]=i,i[Be]="effect",i[Se]=o??null,i.__RX_COMPUTED__=s,i}function S(t,e={}){let n=e?.equals??Object.is,o=0,r=new be;function s(){return L&&(L.dependencies.set(r,r.subscribe(L.observer)),L.sourceRevisions.set(l,o)),t}function i(){return t}function a(u){if(!n(t,u)){t=u,o++,r.next();}return t}function c(){return o}let l={get:s,set:a,peek:i,getRevision:c,[qt]:r,[Be]:"signal",[Se]:e?.debug??null};return l}function we(){return Date.now().toString(32).substring(5)+Math.random().toString(32).substring(2)}var cn=Symbol("node-component"),Le=Symbol("node-internal"),ho=Symbol("keep-literal"),Pe=Symbol("raw-props");function dt(t){return typeof t=="function"?t:t!=null&&typeof t.get=="function"?()=>t.get():()=>t}function gt(t,e){let n=t.children!==void 0?t.children:e;return Array.isArray(n)?n[0]:n}var Eo=new Set(["template","script"]);function yo(t,e){let n=(t==null?"span":String(t)).trim(),o=n;Eo.has(n.toLowerCase())&&(console.warn(`[esmj-dom] tagName "${t}" cannot render children in normal flow and is not supported as a reconciliation wrapper; falling back to "span".`),o="span");let r=document.createElement(o);return o==="span"&&(r.style.display="contents"),r.setAttribute(e,we()),r}function ht(t,e,n){let o=yo(t,e);return n?.id&&o.setAttribute("id",n.id),o}function W(t){let e=null,n=()=>e,o=s=>(e=s??null,typeof t=="function"&&t(e),e),r={get:n,set:o,[Symbol.toPrimitive](){return e?String(e):""}};return Object.defineProperty(r,"current",{get(){return e},set(s){o(s);},enumerable:true,configurable:false}),new Proxy(r,{get(s,i,a){if(Reflect.has(s,i))return Reflect.get(s,i,a);if(!e)return;let c=e[i];return typeof c=="function"?c.bind(e):c},set(s,i,a,c){return Reflect.has(s,i)||!e?Reflect.set(s,i,a,c):(e[i]=a,true)},has(s,i){return Reflect.has(s,i)||!!e&&i in e}})}var ln=null;function $(){return ln}function Te(t){ln=t;}function se(t){return t?.[cn]||null}function Zt(t,e){t[cn]=e;}function Oe(t,e={disposers:[],id:we()}){return t?.[Le]?t[Le]:(t&&(t[Le]=e),e)}function xo(t){return t[Le]}function z(t,e){let n=xo(t);n||(n=Oe(t)),n.disposers.push(e);}function _e(t,e,n){t.has(e)||t.set(e,[]),t.get(e).push(n);}function V(t,e){let n=$();Te(t);try{return e()}finally{Te(n);}}var De=new Map,Ne=new Map,en=new Map;function un(t,e){let n=typeof e=="function"?e:r=>!!e?.includes(r),o=Object.create(null);for(let r of Object.keys(t)){let s=t[r];r==="children"||n(r)?o[r]=s:s?.[ho]?o[r]=s():s!=null&&typeof s.get=="function"?o[r]=s:typeof s=="function"?o[r]=M(s):o[r]=S(s);}return o}function ie(t,e){if(t===e)return true;if(t==null||e==null||typeof t!="object"||typeof e!="object")return false;let n=Object.keys(t),o=Object.keys(e);return n.length!==o.length?false:n.every(r=>{let s=Object.getOwnPropertyDescriptor(t,r),i=Object.getOwnPropertyDescriptor(e,r);if(!s||!i)return false;let a="value"in s?s.value:s.get?.call(t),c="value"in i?i.value:i.get?.call(e);return ie(a,c)})}function Et(t){return {id:Symbol("context-id"),defaultValue:t}}function yt(t,e){let n=$();n&&n.contexts.set(t.id,e);}function xt(t){let e=$();return e?.contexts?.has(t.id)?e.contexts.get(t.id):t.defaultValue}function $e(t){let e=$();if(!e){console.warn("onMount called outside of a component context");return}_e(De,e.id,t);}function je(t){let e=$();if(!e){console.warn("onUnmount called outside of a component context");return}_e(Ne,e.id,t);}function A(t){ft(()=>{setTimeout(t,0);});}function ae(t){let e=t.componentId,n=De.get(e);if(n){De.delete(e);for(let o of n){let r=o();typeof r=="function"&&_e(Ne,e,r);}}}function bo(t){let e=Ne.get(t);if(e){Ne.delete(t);for(let n of e)n();}}function So(t){let e=en.get(t);if(e){en.delete(t);for(let n of e)n();}}function Re(t){if(!t)return;let e=Oe(t);if(e?.disposers?.length){for(let o of e.disposers)try{o();}catch(r){console.error("[esmj-dom] cleanupTree: disposer threw, cleanup continues",r);}e.disposers=[];}let n=se(t);if(n&&(bo(n.componentId),So(n.componentId)),t.childNodes){let o=t.firstChild;for(;o;){let r=o.nextSibling;Re(o),o=r;}}}function X(t){return t!=null&&typeof t=="object"&&typeof t.$constructor=="function"}function tn(t){return typeof t=="function"&&typeof t.prototype?.render=="function"}function Co(t,e,n){let o=we(),r={componentId:o,$children:n,element:null,classInstance:null,$constructor(){let s=tn(t)?void 0:t[Pe],i={...un(e??{},s),children:n},a=$(),c={disposers:[],id:o,contexts:new Map(a?.contexts)};Te(c);let l;if(tn(t)){r.ClassConstructor=t;let f=new t(i);r.classInstance=f,typeof f.onMount=="function"&&_e(De,o,()=>{f.onMount?.();}),typeof f.onUnmount=="function"&&_e(Ne,o,()=>{f.onUnmount?.();}),l=f.render();}else l=t(i);Te(a);let u=ko(l);if(r.element=u,u instanceof DocumentFragment&&u.childNodes.length)for(let f of u.childNodes)Oe(f,c),Zt(f,r);else Oe(u,c),u instanceof Node&&Zt(u,r);return u}};return r}function bt(t,e){let n=e.$constructor();n instanceof Node&&t.appendChild(n),queueMicrotask(()=>{ae(e);});}function ko(t){return t instanceof Node?t:X(t)?t.$constructor():typeof t=="string"||typeof t=="number"?document.createTextNode(String(t)):document.createTextNode("")}var nn={className:"class",htmlFor:"for"},on=new Set(["value","defaultValue","checked","selected","indeterminate"]),_o=new Set(["srcdoc"]),No=new Set(["href","src","action","formaction","xlink:href"]),Ro=new Set(["securitypolicyviolation"]),Ao=new Set(["contenteditable","draggable","spellcheck"]);function ke(t){return t!=null&&typeof t=="object"&&typeof t.get=="function"&&!(t instanceof Node)}var fn=Symbol("Fragment");function E(t,e,n){if(t===fn){let r=document.createDocumentFragment();return pt(r,sn(n)),r}if(typeof t=="function")return Co(t,e||{},n);typeof t!="string"&&(n=e,e=t,t="div"),e=e||{};let o=document.createElement(t);return e.id&&o.setAttribute("id",e.id),Ue(o,e),pt(o,sn(n)),o}function mt(t,e){e instanceof DocumentFragment?t.replaceChildren(e):t.innerHTML=e??"";}function Io(t){return typeof t!="string"?false:t.replace(/[\p{White_Space}\p{Cc}]+/gu,"").toLowerCase().startsWith("javascript:")}function vo(t,e){if(typeof t!="string")return false;let n=t.toLowerCase();return _o.has(n)?true:No.has(n)&&e!==null&&e!==void 0&&Io(String(e))}function mn(t){return typeof t!="string"?t:nn[t]?nn[t]:t}function Bo(t,e){let n=mn(t),o=typeof n=="string"?n.toLowerCase():String(n).toLowerCase();return Ao.has(o)&&(e===true||e===false||e==="true"||e==="false")?String(e):e==null||e===false?null:e}function rn(t,e,n){let o=Bo(e,n);if(o===null){t.removeAttribute(e);return}if(vo(e,o)){t.removeAttribute(e),console.warn(`[esmj-dom] Blocked unsafe attribute "${String(e)}" on <${t.tagName.toLowerCase()}>`);return}t.setAttribute(e,o);}function Ue(t,e){let n=$();for(let[o,r]of Reflect.ownKeys(e).map(s=>[s,e[s]]))if(o!=="id"){if(o=mn(o),o==="$ref"){typeof r=="function"?r(t):typeof r=="object"&&r!==null&&(r.current=t);continue}if(o==="$dangerouslySetInnerHTML"){if(ke(r)){let s=P(()=>{V(n,()=>{mt(t,r.get());});});z(t,s);}else if(typeof r=="function"){let s=P(()=>{V(n,()=>{mt(t,r());});});z(t,s);}else mt(t,r);continue}if(o==="style"){if(ke(r)){let s=P(()=>{V(n,()=>{Object.assign(t.style,r.get());});});z(t,s);}else typeof r=="object"&&r!==null?Object.assign(t.style,r):t.setAttribute("style",r);continue}if(typeof o=="string"&&o.startsWith("on")&&typeof r=="function"){let s=o.slice(2).toLowerCase();if(Ro.has(s)){console.warn(`[esmj-dom] Blocked unsafe event binding "${o}" on <${t.tagName.toLowerCase()}>`);continue}t.addEventListener(s,r);continue}if(ke(r)||typeof r=="function"){let s=o,i=P(()=>{V(n,()=>{let a=typeof r=="function"?r():r.get();on.has(s)?t[s]=a??"":rn(t,s,a);});});z(t,i);continue}on.has(o)||typeof o=="symbol"?t[o]=r??"":rn(t,o,r);}}function sn(t){return t==null?[]:Array.isArray(t)?t.flat(Number.POSITIVE_INFINITY):[t]}function pt(t,e){for(let n of e)pn(t,n);}function pn(t,e){if(!(e==null||e===false||e===true)){if(e instanceof Node){t.appendChild(e);return}if(typeof e=="string"||typeof e=="number"){t.appendChild(document.createTextNode(String(e)));return}if(typeof e=="function"){an(t,e);return}if(X(e)){bt(t,e);return}if(ke(e)){an(t,()=>e.get());return}if(Array.isArray(e)){pt(t,e);return}t.appendChild(document.createTextNode(String(e)));}}function ce(t){let e=null,n=t;return X(t)&&(e=t,n=t.$constructor()),n instanceof DocumentFragment?{nodes:Array.from(n.childNodes),instance:e}:n instanceof Node?{nodes:[n],instance:e}:n==null||n===false||n===true?{nodes:[],instance:e}:{nodes:[document.createTextNode(String(n))],instance:e}}function Ke(t,e=true){for(let n of t)e&&Re(n),n.remove();}function an(t,e){let n=$(),o=document.createComment("");t.appendChild(o);let r=[],s=P(()=>{V(n,()=>{let i=e(),{nodes:a,instance:c}=ce(i);Ke(r),a.length&&o.after(...a),c&&queueMicrotask(()=>ae(c)),r=a;});});z(t,s);}var Fe=class{constructor(t){this.props=t;}};function dn(t,e,n,o){let{equals:r=ie,tagName:s="span",...i}=o??{},a=ht(s,"data-for",i);Ue(a,i);let c=$(),l=[],u=new Map,f=M(()=>t()),p=P(()=>{let h=f.get(),b=Array.isArray(h)?h:[],R=[],N=[],g=new Set;for(let x=0;x<b.length;x++){let _=b[x],v=e(_,x);if(g.has(v)){console.error(`For: duplicate key "${String(v)}" detected; ignoring later item at index ${x}`);continue}g.add(v),R.push(_),N.push(v);}let y=new Map(l.map(x=>[x.key,x])),k=[];for(let x=0;x<R.length;x++){let _=N[x],v=R[x],U=y.get(_);if(U)u.get(_).set(v),k.push(U),y.delete(_);else {let xe=S(v,{equals:r});u.set(_,xe);let ct={...xe,set(){}},Z={key:_,nodes:[]};V(c,()=>{let lo=n(ct,x),{nodes:uo,instance:Ht}=ce(lo);Z.nodes=uo,Ht&&queueMicrotask(()=>ae(Ht));}),k.push(Z);}}for(let[x,_]of y)Ke(_.nodes),u.delete(x);let C=null;for(let x=k.length-1;x>=0;x--){let _=k[x].nodes;for(let v=_.length-1;v>=0;v--){let U=_[v];(U.parentNode!==a||U.nextSibling!==C)&&a.insertBefore(U,C),C=U;}}l=k;});return z(a,p),a}function St(t,e,n,o){if(typeof t=="function")return dn(t,e,n,o);let{each:r,keyFn:s,equals:i,tagName:a,children:c,...l}=t??{};if(typeof s!="function")throw new Error('For: "keyFn" prop is required and must be a function');let u=dt(r),f=gt(t??{},e);return dn(u,s,f,{...l,equals:i,tagName:a})}St[Pe]=t=>t!=="each";function ee(t,e){if(typeof t=="string"&&(t=document.querySelector(t)),!t)throw new Error("mount: container not found");t instanceof DocumentFragment||(Re(t),t.innerHTML=""),X(e)?bt(t,e):e instanceof Node?t.appendChild(e):t.appendChild(document.createTextNode(String(e)));}function hn(t){if(typeof t=="string"&&(t=document.querySelector(t)),!t)throw new Error("unmount: container not found");Re(t),t.innerHTML="";}function Ae(t,e){let n=null;if(X(e)?(n=e.$constructor(),queueMicrotask(()=>ae(e))):e instanceof Node?n=e:n=document.createTextNode(String(e)),n instanceof HTMLElement){let o=M(()=>!!t()),r=P(()=>{n.style.display=o.get()?"":"none";});z(n,r);}return n}var T=class extends Fe{static get nodeName(){return "span"}static get style(){return "SPAN"}static match(e){return e.nodeName===this.nodeName.toUpperCase()||e.style===this.style}getState(){return {style:this.constructor.style}}render(){return E(this.constructor.nodeName,{},this.props.children)}};var le=class extends T{static get nodeName(){return "b"}static get style(){return "BOLD"}static get LABEL(){return E("b",{},"B")}static match(e){return e.nodeName==="strong"?true:super.match(e)}};var ue=class extends T{static get nodeName(){return "i"}static get style(){return "ITALIC"}static get LABEL(){return E("i",{},"I")}};var fe=class extends T{static get nodeName(){return "sub"}static get style(){return "SUBSCRIPT"}static get LABEL(){return E("sub",{},"Sub")}};var me=class extends T{static get nodeName(){return "sup"}static get style(){return "SUPERSCRIPT"}static get LABEL(){return E("sup",{},"Sup")}};var pe=class extends T{static get nodeName(){return "u"}static get style(){return "UNDERLINE"}static get LABEL(){return E("u",{},"U")}};var j=Symbol("result-key"),He=Symbol("stopped-event");function En(t,e){let n=!!e.name,o=e[j]||"result",r=o.includes("."),s={error:null,context:{},[j]:o,...e,[o]:n?void 0:te(e,o),name:t,[He]:false,defaultPrevented:false};return r&&(wo(s,o),s[o]=n?void 0:te(e,o)),s.stopPropagation=()=>{s[He]=true;},s.preventDefault=()=>{s.defaultPrevented=true;},s}function te(t,e){return e===""?t:e.split(".").reduce((o,r)=>o?.[r]??void 0,t)}function Ct(t,e,n){let o=e.split("."),r=o.pop(),s=te(t,o.join("."));return s[r]=n}function wo(t,e){let n=e.split(".");n.pop(),n.reduce((o,r)=>o[r]=o[r]??{},t);}var ze=class{constructor({logger:e,debug:n}={}){this._logger=e??console,this._debug=n??false,this._events=new Map,this.addListener=this.on,this.removeListener=this.off;}emit(e,n={}){let o=this.listeners(e),r=En(e,n),s=null,i=null;this._debug&&(typeof this._debug=="function"?this._debug(e,r):this._logger.debug(`Event name: ${e}, event: ${r}`));for(let a of o){if(s&&(s=s.then(c=>(Ct(r,r[j],c??te(r,r[j])),r[He]?te(r,r[j]):a(r)))),!s){if(r[He])return r;i=a(r);}i instanceof Promise&&!s?s=i:Ct(r,r[j],i??te(r,r[j]));}return s?s.then(a=>(Ct(r,r[j],a??te(r,r[j])),r)):r}emitParallel(e,n={}){let o=this.listeners(e),r=En(e,n);return Promise.all(o.map(async s=>await s(r))).then(s=>(r[r[j]]=s,r)).catch(s=>{throw r.error=s,s})}listeners(e){return this._events.has(e)?[...this._events.get(e)]:[]}removeAllListeners(e){return e?this.listeners(e).forEach(n=>this.off(e,n)):Array.from(this._events.keys()).forEach(n=>this.removeAllListeners(n))}_addListener(e,n,o){return this._events.has(e)||this._events.set(e,[]),this._events.get(e)[o](n),()=>{this.off(e,n);}}on(e,n){if(typeof n!="function")throw new TypeError("The listener must be a function");return this._addListener(e,n,"push")}prependListener(e,n){return this._addListener(e,n,"unshift")}_addListenerOnce(e,n,o){let r=this[o](e,s=>(r(),n(s)));}once(e,n){return this._addListenerOnce(e,n,"on")}prependOnceListener(e,n){return this._addListenerOnce(e,n,"prependListener")}off(e,n){if(this._events.has(e)){let o=this._events.get(e),r=o.indexOf(n);o.splice(r,1);}}};var m={INSERT_BLOCK_ELEMENT:"mrakomor:insert-block-component",REPLACE_BLOCK_ELEMENT:"mrakomor:replace-block-component",REMOVE_BLOCK_ELEMENT:"mrakomor:remove-block-component",MERGE_BLOCK_ELEMENT:"mrakomor:merge-block-component",INSERT_ENTITY_RANGE:"mrakomor:insert-entity-range",REMOVE_ENTITY_RANGE:"mrakomor:remove-entity-range",INSERT_INLINE_STYLE_RANGE:"mrakomor:insert-inline-style-range",KEYDOWN:"mrakomor:keydown",BEFORE_INPUT:"mrakomor:beforeinput",INPUT:"mrakomor:input",CLICK:"mrakomor:click",FOCUSIN:"mrakomor:focusin",FOCUSOUT:"mrakomor:focusout",SELECTION_CHANGE:"mrakomor:selection-change",CONTENT_CHANGE:"mrakomor:content-change",TRANSFORM_BLOCK_ELEMENT:"mrakomor:transform-block-element",MOVE_BLOCK_ELEMENT:"mrakomor:move-block-element"};function w(t){return e=>{if(!e.defaultPrevented)return t(e)}}function yn({mrakomor:t}={}){let e=t?.emitter??new ze;function n(o,r={}){return typeof t?.emit=="function"?t.emit(o,r):e.emit(o,{...r,mrakomor:t})}return {emitter:e,command:{insertBlockElement(o,r){n(m.INSERT_BLOCK_ELEMENT,{...o,options:r});},replaceBlockElement(o,r){n(m.REPLACE_BLOCK_ELEMENT,{...o,options:r});},removeBlockElement(o,r){n(m.REMOVE_BLOCK_ELEMENT,{...o,options:r});},mergeBlockElement(o,r){n(m.MERGE_BLOCK_ELEMENT,{...o,options:r});},insertEntityRange(o,r){n(m.INSERT_ENTITY_RANGE,{...o,options:r});},removeEntityRange(o,r){n(m.REMOVE_ENTITY_RANGE,{...o,options:r});},insertInlineStyleRange(o,r){n(m.INSERT_INLINE_STYLE_RANGE,{...o,options:r});},transformBlockElement(o,r){n(m.TRANSFORM_BLOCK_ELEMENT,{...o,options:r});},moveBlockElement(o,r){n(m.MOVE_BLOCK_ELEMENT,{...o,options:r});}}}}function xn(t){return t.map((e,n)=>({entry:e,index:n})).sort((e,n)=>{let o=e.entry.order??e.index,r=n.entry.order??n.index;return o!==r?o-r:e.index-n.index}).map(({entry:e})=>e)}var de=class extends be{mrakomor;#e=new Map;#n=null;#r=0;#t;constructor(e,n={}){super(),this.mrakomor=e,this.#t=n.sort??xn;}normalize(e,n){throw new Error("Register subclass must implement normalize")}#o(){this.#n=null,this.next(this.list());}#i(e,n=this.#r++){let o=this.normalize(e,n);return o?(this.#e.set(o.id,o),o):null}add(e){if(Array.isArray(e)){let o=[];for(let r of e){let s=this.#i(r,this.#r++);s&&o.push(s);}return o.length&&this.#o(),o}let n=this.#i(e);return n&&this.#o(),n}get(e){return this.#e.get(e)}has(e){return this.#e.has(e)}remove(e){let n=this.#e.delete(e);return n&&this.#o(),n}list(){return this.#n??=this.#t([...this.#e.values()]),this.#n}};var Lo={abortEarly:true};function At(t,e){if(e===void 0)return t;let n=t?.cause?.key?`${e}.${t.cause.key}`:`${e}`;return {message:`Error parsing key "${n}": ${t.message}`,cause:{key:n}}}function To(t,e,n){if(t.errors?.length)for(let o=0;o<t.errors.length;o++)e.push(At(t.errors[o],n));}function Cn(t,e,n,o){if(n!==false){let r=At(t.error,e);return {success:false,error:r,errors:[r]}}To(t,o,e);}function Ge(t){return t?.abortEarly!==void 0?t:Lo}function kt(t,e){B(t,"_parse",(n,o,r)=>{let s=n(o,r);return !s.success&&e(o)?{success:true,data:o}:s});}var Ie=t=>typeof t=="string"||t instanceof String,_t=t=>(typeof t=="number"||t instanceof Number)&&!Number.isNaN(t),Nt=t=>t===true||t===false,Oo=t=>t instanceof Date&&!Number.isNaN(t.getTime()),Do=t=>typeof t=="function",Po=t=>Array.isArray(t),Rt=t=>typeof t=="object"&&t!==null&&!Array.isArray(t);function kn(t,e){let n=O(Rt,{...e,type:"object"});n._getDescription=()=>`object({ ${Object.entries(t).map(([r,s])=>`${r}: ${s._getDescription()}`).join(", ")} })`,n._getDefinition=()=>t;let o=n;return o.derive=function(r,{when:s="always"}={}){return B(this,"_parse",(i,a,c)=>{let l=i(a,c);if(!l.success)return l;let u=r(l.data,{context:c?.context});if(!Rt(u)){let f={message:`derive() callback must return a plain object of overrides, got ${u===null?"null":typeof u}`};return {success:false,error:f,errors:[f]}}if(s==="missing"){let f={...l.data};for(let p in u)f[p]===void 0&&(f[p]=u[p]);return {success:true,data:f}}return {success:true,data:{...l.data,...u}}}),this},B(n,"_parse",(r,s,i)=>{let a=r(s,i),{abortEarly:c}=Ge(i);if(a.success===false)return a;let l={},u=[];for(let f in t){let p=t[f]._parse(a.data[f],i);if(p.success)l[f]=p.data;else {let h=Cn(p,f,c,u);if(h)return h}}return u.length>0?{success:false,error:u[0],errors:u}:{success:true,data:l}}),o}function It(t){return O(Ie,{...t,type:"string"})}function vt(t){return O(_t,{...t,type:"number"})}function Bt(t){return O(Nt,{...t,type:"boolean"})}function Mt(t){return O(Oo,{...t,type:"date"})}function _n(t){return O(Do,{...t,type:"function"})}function Nn(t,e){let n=i=>t.includes(i),o=i=>`Invalid ${r} value. Expected ${t.map(a=>`"${a}"`).join(" | ")}, received "${i}".`,r="enum",s=O(n,{message:o,...e,type:r});return s._getDescription=()=>`enum(${t.map(i=>`"${i}"`).join(" | ")})`,s._getDefinition=()=>t,s}function Rn(t,e){let n=O(Po,{...e,type:"array"});return n._getDescription=()=>`array(${t._getDescription()})`,n._getDefinition=()=>t,B(n,"_parse",(o,r,s)=>{let i=o(r,s),{abortEarly:a}=Ge(s);if(i.success===false)return i;let c=[],l=[],u=s;for(let f=0;f<i.data.length;f++){let p={...u,context:{...u?.context,index:f}},h=t._parse(i.data[f],p);if(h.success)c.push(h.data);else {let b=Cn(h,f,a,l);if(b)return b}}return l.length>0?{success:false,error:l[0],errors:l}:{success:true,data:c}}),n}function An(){return O(()=>true)}function ge(t,e){return B(e,"_parse",(n,o,r)=>(o=t(o),n(o,r))),e}function In(t,e){let n=r=>`Invalid union value. Expected the value to match one of the schemas:${t.map((s,i)=>` ${i+1}. ${s._getDescription()}`).join(",")} but received "${typeof r}" with value: ${Rt(r)?JSON.stringify(r):`"${r}"`}`,o=O(()=>false,{message:n,...e,type:"union"});return o._getDefinition=()=>t,B(o,"_parse",(r,s,i)=>{let a=i,c=[];for(let p=0;p<t.length;p++){let h=t[p]._parse(s,a);if(h.success)return h;c.push(h);}let{abortEarly:l}=Ge(a),u={message:typeof n=="function"?n(s):n};if(l!==false)return {success:false,error:u,errors:[u]};let f=[];for(let p=0;p<c.length;p++){let h=c[p].errors;if(h?.length)for(let b=0;b<h.length;b++)h[b].cause?.key&&f.push(At(h[b],`branch ${p}`));}return f.length===0&&f.push(u),{success:false,error:f[0],errors:f}}),o}function vn(t,e){let n=O(o=>o===t,{message:o=>e?.message?typeof e.message=="function"?e.message(o):e.message:`Expected literal value "${t}", received "${o}"`,name:e?.name,type:"literal"});return n._getDescription=()=>`literal("${t}")`,n._getDefinition=()=>t,n}function Bn(t){let e=O(()=>true,{type:"contextRef"});return e._getDescription=()=>`contextRef("${t}")`,B(e,"_parse",(n,o,r)=>({success:true,data:r?.context?.[t]})),e}function Mn(t,e){return {parse(n,o){let r=t.parse(o?.context??{},o);return e(r).parse(n,o)},safeParse(n,o){let r=t.safeParse(o?.context??{},o);return r.success?e(r.data).safeParse(n,o):r}}}var wn={boolean(t){let e=t?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return ge(n=>{let o;return Ie(n)&&(o=n.toLowerCase()),o==="true"||o==="yes"||o==="on"||o==="1"||n===1?true:o==="false"||o==="no"||o==="off"||o==="0"||n===0?false:n},Bt({...t,message:e}))},number(t){let e=t?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return ge(n=>{if(Nt(n))return Number(n);if(Ie(n)){let o=n.trim();if(o==="")return n;let r=Number(o);if(Number.isFinite(r))return r}return n},vt({...t,message:e}))},string(t){let e=t?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return ge(n=>Nt(n)||_t(n)&&Number.isFinite(n)?String(n):n,It({...t,message:e}))},date(t){let e=t?.message??(n=>`Cannot cast "${n}" to a valid date.`);return ge(n=>{let o;return Ie(n)&&(o=n.trim()),_t(n)&&Number.isFinite(n)||o?new Date(o??n):n},Mt({...t,message:e}))},json(t,e){let n=e?.message??(o=>`Cannot parse "${o}" as JSON.`);return B(t,"_parse",(o,r,s)=>{if(Ie(r))try{r=JSON.parse(r);}catch{let i={message:typeof n=="function"?n(r):n};return {success:false,error:i,errors:[i]}}return o(r,s)}),t}},Ln={},d={object:kn,string:It,number:vt,boolean:Bt,date:Mt,function:_n,enum:Nn,array:Rn,any:An,preprocess:ge,union:In,literal:vn,contextRef:Bn,withContext:Mn,coerce:Ln,cast:wn};function bn(t){return e=>`The value "${e}" must be type of ${t} but is type of "${typeof e}".`}function B(t,e,n){let o=t[e];t[e]=(...r)=>n(o,...r);}function O(t,{type:e="any",name:n,message:o}={}){o=o||bn(e);let r={name:n,message:o,type:e},s={_getName(){return n},_getType(){return e},_getDescription(){return this._getName()??this._getType()},_parse(i,a){let c=t(i);if(c===true)return {success:true,data:i};if(typeof c=="object"&&c?.success===true)return c;let l={message:typeof o=="function"?o(i):o};return {success:false,error:l,errors:[l]}},parse(i,a){let c=this._parse(i,a);if(!c.success)throw c=c,new Error(c.error.message,{cause:c.error.cause});return c.data},safeParse(i,a){return this._parse(i,a)},transform(i){return B(this,"_parse",(a,c,l)=>{let u=a(c,l);return u.success&&(u.data=i(u.data)),u}),this},optional(){return kt(this,i=>i===void 0),this},nullable(){return kt(this,i=>i===null),this},nullish(){return kt(this,i=>i==null),this},default(i){return B(this,"_parse",(a,c,l)=>(c===void 0&&(c=typeof i=="function"?i({context:l?.context}):i),a(c,l))),this},catch(i){return B(this,"_parse",(a,c,l)=>{let u=a(c,l);return u.success?u:{success:true,data:typeof i=="function"?i({input:c,error:u.error}):i}}),this},pipe(i){return B(this,"_parse",(a,c,l)=>{let u=a(c,l);return u.success?i._parse(u.data,l):u}),this},refine(i,{message:a,type:c,jsonSchema:l}={}){if(c&&(a=a||bn(c),e=c),l){let u=[...this._getJsonSchemaHints?.()??[],l];this._getJsonSchemaHints=()=>u;}return B(this,"_parse",(u,f,p)=>{let h=u(f,p),{abortEarly:b}=Ge(p);if(!h.success)return h;let R=i(h.data);if(R===true||typeof R=="object"&&R?.success===true)return h;let N={message:typeof a=="function"?a(f):a};return {success:false,error:N,errors:[N]}}),this},clone(){return {...this}}};return Sn.length>0?Sn.reduce((i,a)=>a(i,t,r)??i,s):s}var Sn=[];var $o=d.object({component:d.function(),id:d.string(),label:d.string(),keywords:d.array(d.string()),group:d.string(),order:d.number().default(({context:t})=>t?.index??0),settings:d.any().optional()});function jo(t,e){let n=`block:${t}`;return e?.style==="UNORDERED"?`${n}:ul`:e?.style==="ORDERED"?`${n}:ol`:n}function Tn(t,e=0){let n=typeof t=="function",o=n?t:t?.component,r=n?{}:t,s=o.NAMESPACE??"",i=s.split(".").pop()||s,a=r.label||o.LABEL||i||s,c=Array.isArray(o.KEYWORDS)?o.KEYWORDS:[],l=r.keywords?.length?r.keywords.map(String):c.length?c.map(String):[a,i].filter(Boolean).map(String),u=r.settings;return $o.parse({component:o,id:r.id||jo(s,u),label:String(a),keywords:l,group:String(r.group||o.GROUP||"blocks"),...typeof r.order=="number"?{order:r.order}:{},...u?{settings:u}:{}},{context:{index:e}})}var qe=class t extends de{#e=null;constructor(e){super(e),this.subscribe(()=>{this.#e=null;});}normalize(e,n){if(e==null)return null;try{return Tn(e,n)}catch{return null}}getByNamespace(e){return this.#n().get(e)}#n(){return this.#e??=t.buildNamespaceMap(this.list()),this.#e}static buildNamespaceMap(e){let n=new Map;for(let o of e){let r=o.component?.NAMESPACE;r&&!n.has(r)&&n.set(r,o.component);}return n}};var wt="molecule.paragraph.Paragraph";var On="molecule.external.ExternalComponent",Dn="namespace.unknown.UnknownComponent";var Pn="molecule.headline.";var Lt=Dt(),Tt=Dt(),$n=Dt(),Uo=Array.from({length:256},(t,e)=>(e<=15?"0":"")+e.toString(16));function Dt(){return Math.floor(Math.random()*16777215)}function Ko(){return Tt=(Tt+1)%16777215,Tt}function J(){let t=Math.floor(Date.now()/1e3);t=parseInt(t,10)%4294967295;let e=Ko(),n=String.fromCharCode(t>>24&255,t>>16&255,t>>8&255,t&255,Lt>>16&255,Lt>>8&255,Lt&255,$n>>8&255,$n&255,e>>16&255,e>>8&255,e&255),o="";for(let r=0;r<n.length;r++)o+=Uo[n.charCodeAt(r)];return o}var ve=Symbol("block-element"),Fo=Symbol("block-element-body"),he=Symbol("selectable-element");function Ye(t,e){let n=t;for(n?.nodeType===Node.TEXT_NODE&&(n=n.parentElement);n&&n[e]===void 0;)n=n.parentElement;return n??null}function G(t){return t?Ye(t.startContainer,ve):null}function jn(t){return Ye(t,ve)}function Kn(t){return t?Ye(t.startContainer,he):null}function Un(t){return Ye(t,he)}function Ho(t){return t?t[he]!==void 0?[t]:[...t.children].filter(e=>e[he]!==void 0):[]}function zo(t,e){return e?Ho(t).indexOf(e):-1}function Fn(t,e){let n=Kn(e);return !n||!t?.contains(n)?null:{element:n,index:zo(t,n)}}function Pt(){return window.getSelection()}function q(){let t=Pt();return t.rangeCount>0?t.getRangeAt(0).cloneRange():null}function $t(){let t=q();if(!t)return 0;t.collapse(true);let e=Kn(t),n=G(t),o=e??I(n);return Ee(o,t.startContainer,t.startOffset)}function Ee(t,e,n){if(!t)return 0;if(e===t){if(e.nodeType===Node.TEXT_NODE)return n;let i=0,a=t.childNodes,c=Math.min(n,a.length);for(let l=0;l<c;l++)i+=a[l].textContent.length;return i}if(e.nodeType===Node.ELEMENT_NODE&&!t.contains(e))return 0;let o=0,r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),s=r.nextNode();for(;s;){if(s===e)return o+n;o+=s.textContent.length,s=r.nextNode();}return o}function zn(t=q()){if(!t||t.collapsed)return null;let e=jn(t.startContainer),n=jn(t.endContainer);if(!e||!n)return null;let o=Un(t.startContainer)??I(e),r=Un(t.endContainer)??I(n);return {startBlock:e,endBlock:n,startOffset:Ee(o,t.startContainer,t.startOffset),endOffset:Ee(r,t.endContainer,t.endOffset)}}function Ot(t,e){let n=document.createRange();if(!t)return n;if(e<=0)return n.setStart(t,0),n.collapse(true),n;let o=0,r=[t];for(;r.length>0;){let s=r.pop();if(s.nodeType===Node.TEXT_NODE){let i=s.textContent.length;if(o+i>=e)return n.setEnd(s,e-o),n.setStart(s,e-o),n;o+=i;}else if(s.childNodes&&s.childNodes.length>0)for(let i=s.childNodes.length-1;i>=0;i--)r.push(s.childNodes[i]);}return n.setEnd(t,t.childNodes.length),n.setStart(t,t.childNodes.length),n}function Y(t,e){let n=Ot(t,e),o=Pt();o.removeAllRanges(),o.addRange(n);}function I(t){if(!t)return null;let e=Ve(t);return e?.firstElementChild??e?.firstChild}function D(t){if(!t?.[ve])return null;let e=I(t);return e?se(e)?.classInstance:null}function Ve(t){if(!t)return null;for(let e of t.children)if(e[Fo])return e;return null}function We(t,e,n,o=12){let r=t.getBoundingClientRect(),s=typeof e?.getBoundingClientRect=="function"?e.getBoundingClientRect():e??{left:0,top:0},i=n?.offsetHeight??40;return {x:s.left-r.left,y:s.top-r.top-i-o}}function Gn(t,e){let n=t.getBoundingClientRect(),o=e?.offsetWidth??420,r=e?.offsetHeight??320,s=16;return {x:Math.max(s,(n.width-o)/2),y:Math.max(s,(n.height-r)/2)}}var Xe=Et();var Je=class extends Fe{state;element;mrakomor;constructor(e){super(e);let{state:n,observeDOMChanges:o=true}=e??{};this.state=n,this.element=null,this.mrakomor=xt(Xe),this._stale=false,this._observer=null,this._offInputStale=null,this._onInputMarkStale=null,this._observeDOMChanges=o;}static get NAMESPACE(){return "namespace.AbstractComponent"}static getStateSchema(){return d.object({component:d.string().default(this.NAMESPACE),properties:d.object().default({}),settings:d.object().default({})}).default({})}static getPropsSchema(){return d.object({state:this.getStateSchema(),observeDOMChanges:d.boolean().default(true)}).default({})}parseFromHTML(e){return this.constructor.getStateSchema(e).parse()}getState(){if(this._stale){let e=this.element;return this.parseFromHTML(e)}return this.state.peek()}isStale(){return this._stale}#e(){this._stale=true;}onMount(){!this.element||!this._observeDOMChanges||(this._observer=new MutationObserver(()=>{this.#e();}),this._observer.observe(this.element,{subtree:true,characterData:true,characterDataOldValue:true,childList:true,attributes:true,attributeOldValue:true}),this._onInputMarkStale=e=>{let n=e.target;n instanceof Node&&this.element?.contains(n)&&this.#e();},this.mrakomor?.emitter&&(this._offInputStale=this.mrakomor.emitter.on(m.INPUT,this._onInputMarkStale)));}onUnmount(){this._observer&&(this._observer.disconnect(),this._observer=null),this._offInputStale?.(),this._offInputStale=null,this._onInputMarkStale=null,this._stale=false;}};function Q(t){return t===`
2
+ `,document.head.appendChild(n);}}})();var Ht=class{next(...t){}error(...t){}complete(...t){}},xe=class{#e=new Set;pipe(...t){return t.reduce((e,n)=>n(e),this)}next(...t){Array.from(this.#e).forEach(e=>{typeof e=="function"?e(...t):e.next(...t);});}error(...t){Array.from(this.#e).forEach(e=>{e?.error?.(...t),this.unsubscribe(e);});}complete(...t){Array.from(this.#e).forEach(e=>{e?.complete?.(...t),this.unsubscribe(e);});}subscribe(t){return this.#e.add(t),{unsubscribe:()=>{this.unsubscribe(t);}}}unsubscribe(t){this.#e.delete(t);}};var Be=Symbol("@esmj/signals:type"),be=Symbol("@esmj/signals:name");var T=null,st=false,it=[];function G(t){let e=T;T=null;let n=t();return T=e,n}function ho(){st=false;let t=Yt();for(let n of t)n.get();let e=it;it=[];for(let n of e)n();}function zt(){st||(st=true,queueMicrotask(ho));}function ct(t){it.push(t),zt();}var Gt=Symbol("@esmj/signals:internal observable"),H=Symbol("@esmj/signals:original function"),Eo=class extends xe{#e=new Set;#n=null;constructor(t){super(),this.#n=t,this.pipe(e=>{let n=e.subscribe.bind(e),o=e.unsubscribe.bind(e);return e.subscribe=r=>{n(r),this.#e.add(r);},e.unsubscribe=r=>{o(r),this.#e.delete(r);},e});}watch(t){if(typeof t.next!="function"&&(t.next=()=>G(()=>{this.#e.add(t),this.#n();}),t.next[H]=void 0),t instanceof Xt&&t.next[H]===void 0){let e=t.next.bind(t);t.next=()=>G(()=>{this.#e.add(t),e(),this.#n();}),t.next[H]=e;}return this.subscribe(t)}getPending(){let t=[];for(let e of this.#e){if(!e.get[H]){let n=e.get,o=n.bind(e);e.get=()=>G(()=>(this.#e.delete(e),o())),e.get[H]=n;}t.push(e);}return t}unwatch(t){return t.next=t.next[H]?t.next[H]:t.next,t.get=t.get[H]?t.get[H]:t.get,this.#e.delete(t),this.unsubscribe(t)}},ve=null;function qt(t){ve=new Eo(t);}qt(()=>{zt();});function Yt(){return ve.getPending()}function Vt(t){return ve.watch(t)}function Wt(t){return ve.unwatch(t)}var z=Symbol("@esmj/signals:no error"),Xt=class Jt extends Ht{#e=true;#n=false;#r=null;#t=this.#f();#o=null;#i=null;#a=0;#c=new Map;#s=z;constructor(e,n){super(),this.#o=e,this.#i=n,this.debug=n?.debug,this[Be]="computed",this[be]=n?.debug??null,this.get=this.get.bind(this);}#u(){for(let{unsubscribe:e}of this.#t.dependencies.values())e();this.#t.dependencies.clear();}#f(){return {dependencies:new Map,sourceRevisions:new Map,observer:this}}getRevision(){return this.#a}getDebugInfo(){return {name:this[be],dirty:this.#e,revision:this.#a,sourceDependencies:[...this.#c.keys()]}}#l(){for(let[e,n]of this.#c)if(e instanceof Jt&&G(()=>e.get()),e.getRevision()!==n)return true;return false}next(){this.#e=true,this.#r[Gt].next();}get(){if(this.#n)throw new Error("Cycle detected in computed signal");if(this.#r||(this.#r=S(this.#m(),this.#i)),(this.#e||this.#s!==z)&&(this.#c.size===0||this.#l()?this.#m():this.#e=false),T&&T.sourceRevisions.set(this,this.#a),this.#s!==z)throw this.#s;return this.#r.get()}peek(){if(this.#r||(this.#r=S(this.#m(),this.#i)),(this.#e||this.#s!==z)&&(this.#c.size===0||this.#l()?this.#m():this.#e=false),this.#s!==z)throw this.#s;return this.#r.peek()}#m(){this.#n=true,this.#e=false,this.#s=z,this.#u(),this.#t.sourceRevisions.clear();let e=T;T=this.#t;let n;try{n=this.#o();}catch(o){this.#s=o;}return T=e,this.#c=this.#t.sourceRevisions,this.#t.sourceRevisions=new Map,this.#n=false,n instanceof Promise&&(n=n.then(o=>{this.#s=z,this.#r.set(o);}).catch(o=>{this.#s=o;})),this.#s===z&&this.#r&&this.#r.set(n),this.#a++,n}destroy(){this.#u(),this.#c.clear(),this.#e=true,this.#s=z;}};function L(t,e){return new Xt(t,e)}function P(t,e){let n,{debug:o,...r}={},s=L(()=>{n?.(),n=t();},{equals:()=>false,...r});s.get(),Vt(s);let i=()=>{n?.(),s.destroy(),Wt(s);};return i[Symbol.dispose]=i,i[Be]="effect",i[be]=o??null,i.__RX_COMPUTED__=s,i}function S(t,e={}){let n=e?.equals??Object.is,o=0,r=new xe;function s(){return T&&(T.dependencies.set(r,r.subscribe(T.observer)),T.sourceRevisions.set(l,o)),t}function i(){return t}function c(u){if(!n(t,u)){t=u,o++,r.next();}return t}function a(){return o}let l={get:s,set:c,peek:i,getRevision:a,[Gt]:r,[Be]:"signal",[be]:e?.debug??null};return l}function Me(){return Date.now().toString(32).substring(5)+Math.random().toString(32).substring(2)}var cn=Symbol("node-component"),we=Symbol("node-internal"),yo=Symbol("keep-literal"),De=Symbol("raw-props");function ut(t){return typeof t=="function"?t:t!=null&&typeof t.get=="function"?()=>t.get():()=>t}function ft(t,e){let n=t.children!==void 0?t.children:e;return Array.isArray(n)?n[0]:n}var xo=new Set(["template","script"]);function bo(t,e){let n=(t==null?"span":String(t)).trim(),o=n;xo.has(n.toLowerCase())&&(console.warn(`[esmj-dom] tagName "${t}" cannot render children in normal flow and is not supported as a reconciliation wrapper; falling back to "span".`),o="span");let r=document.createElement(o);return o==="span"&&(r.style.display="contents"),r.setAttribute(e,Me()),r}function mt(t,e,n){let o=bo(t,e);return n?.id&&o.setAttribute("id",n.id),o}function W(t){let e=null,n=()=>e,o=s=>(e=s??null,typeof t=="function"&&t(e),e),r={get:n,set:o,[Symbol.toPrimitive](){return e?String(e):""}};return Object.defineProperty(r,"current",{get(){return e},set(s){o(s);},enumerable:true,configurable:false}),new Proxy(r,{get(s,i,c){if(Reflect.has(s,i))return Reflect.get(s,i,c);if(!e)return;let a=e[i];return typeof a=="function"?a.bind(e):a},set(s,i,c,a){return Reflect.has(s,i)||!e?Reflect.set(s,i,c,a):(e[i]=c,true)},has(s,i){return Reflect.has(s,i)||!!e&&i in e}})}var an=null;function j(){return an}function Le(t){an=t;}function se(t){return t?.[cn]||null}function Qt(t,e){t[cn]=e;}function Te(t,e={disposers:[],id:Me()}){return t?.[we]?t[we]:(t&&(t[we]=e),e)}function So(t){return t[we]}function q(t,e){let n=So(t);n||(n=Te(t)),n.disposers.push(e);}function Ce(t,e,n){t.has(e)||t.set(e,[]),t.get(e).push(n);}function V(t,e){let n=j();Le(t);try{return e()}finally{Le(n);}}var Oe=new Map,_e=new Map,Zt=new Map;function ln(t,e){let n=typeof e=="function"?e:r=>!!e?.includes(r),o=Object.create(null);for(let r of Object.keys(t)){let s=t[r];r==="children"||n(r)?o[r]=s:s?.[yo]?o[r]=s():s!=null&&typeof s.get=="function"?o[r]=s:typeof s=="function"?o[r]=L(s):o[r]=S(s);}return o}function ie(t,e){if(t===e)return true;if(t==null||e==null||typeof t!="object"||typeof e!="object")return false;let n=Object.keys(t),o=Object.keys(e);return n.length!==o.length?false:n.every(r=>{let s=Object.getOwnPropertyDescriptor(t,r),i=Object.getOwnPropertyDescriptor(e,r);if(!s||!i)return false;let c="value"in s?s.value:s.get?.call(t),a="value"in i?i.value:i.get?.call(e);return ie(c,a)})}function pt(t){return {id:Symbol("context-id"),defaultValue:t}}function dt(t,e){let n=j();n&&n.contexts.set(t.id,e);}function gt(t){let e=j();return e?.contexts?.has(t.id)?e.contexts.get(t.id):t.defaultValue}function Pe(t){let e=j();if(!e){console.warn("onMount called outside of a component context");return}Ce(Oe,e.id,t);}function $e(t){let e=j();if(!e){console.warn("onUnmount called outside of a component context");return}Ce(_e,e.id,t);}function R(t){ct(()=>{setTimeout(t,0);});}function ce(t){let e=t.componentId,n=Oe.get(e);if(n){Oe.delete(e);for(let o of n){let r=o();typeof r=="function"&&Ce(_e,e,r);}}}function ko(t){let e=_e.get(t);if(e){_e.delete(t);for(let n of e)n();}}function Co(t){let e=Zt.get(t);if(e){Zt.delete(t);for(let n of e)n();}}function Ne(t){if(!t)return;let e=Te(t);if(e?.disposers?.length){for(let o of e.disposers)try{o();}catch(r){console.error("[esmj-dom] cleanupTree: disposer threw, cleanup continues",r);}e.disposers=[];}let n=se(t);if(n&&(ko(n.componentId),Co(n.componentId)),t.childNodes){let o=t.firstChild;for(;o;){let r=o.nextSibling;Ne(o),o=r;}}}function X(t){return t!=null&&typeof t=="object"&&typeof t.$constructor=="function"}function en(t){return typeof t=="function"&&typeof t.prototype?.render=="function"}function _o(t,e,n){let o=Me(),r={componentId:o,$children:n,element:null,classInstance:null,$constructor(){let s=en(t)?void 0:t[De],i={...ln(e??{},s),children:n},c=j(),a={disposers:[],id:o,contexts:new Map(c?.contexts)};Le(a);let l;if(en(t)){r.ClassConstructor=t;let f=new t(i);r.classInstance=f,typeof f.onMount=="function"&&Ce(Oe,o,()=>{f.onMount?.();}),typeof f.onUnmount=="function"&&Ce(_e,o,()=>{f.onUnmount?.();}),l=f.render();}else l=t(i);Le(c);let u=No(l);if(r.element=u,u instanceof DocumentFragment&&u.childNodes.length)for(let f of u.childNodes)Te(f,a),Qt(f,r);else Te(u,a),u instanceof Node&&Qt(u,r);return u}};return r}function ht(t,e){let n=e.$constructor();n instanceof Node&&t.appendChild(n),queueMicrotask(()=>{ce(e);});}function No(t){return t instanceof Node?t:X(t)?t.$constructor():typeof t=="string"||typeof t=="number"?document.createTextNode(String(t)):document.createTextNode("")}var tn={className:"class",htmlFor:"for"},nn=new Set(["value","defaultValue","checked","selected","indeterminate"]),Ro=new Set(["srcdoc"]),Ao=new Set(["href","src","action","formaction","xlink:href"]),Io=new Set(["securitypolicyviolation"]),Bo=new Set(["contenteditable","draggable","spellcheck"]);function ke(t){return t!=null&&typeof t=="object"&&typeof t.get=="function"&&!(t instanceof Node)}var un=Symbol("Fragment");function h(t,e,n){if(t===un){let r=document.createDocumentFragment();return lt(r,rn(n)),r}if(typeof t=="function")return _o(t,e||{},n);typeof t!="string"&&(n=e,e=t,t="div"),e=e||{};let o=document.createElement(t);return e.id&&o.setAttribute("id",e.id),je(o,e),lt(o,rn(n)),o}function at(t,e){e instanceof DocumentFragment?t.replaceChildren(e):t.innerHTML=e??"";}function vo(t){return typeof t!="string"?false:t.replace(/[\p{White_Space}\p{Cc}]+/gu,"").toLowerCase().startsWith("javascript:")}function Mo(t,e){if(typeof t!="string")return false;let n=t.toLowerCase();return Ro.has(n)?true:Ao.has(n)&&e!==null&&e!==void 0&&vo(String(e))}function fn(t){return typeof t!="string"?t:tn[t]?tn[t]:t}function wo(t,e){let n=fn(t),o=typeof n=="string"?n.toLowerCase():String(n).toLowerCase();return Bo.has(o)&&(e===true||e===false||e==="true"||e==="false")?String(e):e==null||e===false?null:e}function on(t,e,n){let o=wo(e,n);if(o===null){t.removeAttribute(e);return}if(Mo(e,o)){t.removeAttribute(e),console.warn(`[esmj-dom] Blocked unsafe attribute "${String(e)}" on <${t.tagName.toLowerCase()}>`);return}t.setAttribute(e,o);}function je(t,e){let n=j();for(let[o,r]of Reflect.ownKeys(e).map(s=>[s,e[s]]))if(o!=="id"){if(o=fn(o),o==="$ref"){typeof r=="function"?r(t):typeof r=="object"&&r!==null&&(r.current=t);continue}if(o==="$dangerouslySetInnerHTML"){if(ke(r)){let s=P(()=>{V(n,()=>{at(t,r.get());});});q(t,s);}else if(typeof r=="function"){let s=P(()=>{V(n,()=>{at(t,r());});});q(t,s);}else at(t,r);continue}if(o==="style"){if(ke(r)){let s=P(()=>{V(n,()=>{Object.assign(t.style,r.get());});});q(t,s);}else typeof r=="object"&&r!==null?Object.assign(t.style,r):t.setAttribute("style",r);continue}if(typeof o=="string"&&o.startsWith("on")&&typeof r=="function"){let s=o.slice(2).toLowerCase();if(Io.has(s)){console.warn(`[esmj-dom] Blocked unsafe event binding "${o}" on <${t.tagName.toLowerCase()}>`);continue}t.addEventListener(s,r);continue}if(ke(r)||typeof r=="function"){let s=o,i=P(()=>{V(n,()=>{let c=typeof r=="function"?r():r.get();nn.has(s)?t[s]=c??"":on(t,s,c);});});q(t,i);continue}nn.has(o)||typeof o=="symbol"?t[o]=r??"":on(t,o,r);}}function rn(t){return t==null?[]:Array.isArray(t)?t.flat(Number.POSITIVE_INFINITY):[t]}function lt(t,e){for(let n of e)mn(t,n);}function mn(t,e){if(!(e==null||e===false||e===true)){if(e instanceof Node){t.appendChild(e);return}if(typeof e=="string"||typeof e=="number"){t.appendChild(document.createTextNode(String(e)));return}if(typeof e=="function"){sn(t,e);return}if(X(e)){ht(t,e);return}if(ke(e)){sn(t,()=>e.get());return}if(Array.isArray(e)){lt(t,e);return}t.appendChild(document.createTextNode(String(e)));}}function ae(t){let e=null,n=t;return X(t)&&(e=t,n=t.$constructor()),n instanceof DocumentFragment?{nodes:Array.from(n.childNodes),instance:e}:n instanceof Node?{nodes:[n],instance:e}:n==null||n===false||n===true?{nodes:[],instance:e}:{nodes:[document.createTextNode(String(n))],instance:e}}function Ue(t,e=true){for(let n of t)e&&Ne(n),n.remove();}function sn(t,e){let n=j(),o=document.createComment("");t.appendChild(o);let r=[],s=P(()=>{V(n,()=>{let i=e(),{nodes:c,instance:a}=ae(i);Ue(r),c.length&&o.after(...c),a&&queueMicrotask(()=>ce(a)),r=c;});});q(t,s);}var Ke=class{constructor(t){this.props=t;}};function pn(t,e,n,o){let{equals:r=ie,tagName:s="span",...i}=o??{},c=mt(s,"data-for",i);je(c,i);let a=j(),l=[],u=new Map,f=L(()=>t()),m=P(()=>{let d=f.get(),x=Array.isArray(d)?d:[],C=[],_=[],E=new Set;for(let y=0;y<x.length;y++){let k=x[y],w=e(k,y);if(E.has(w)){console.error(`For: duplicate key "${String(w)}" detected; ignoring later item at index ${y}`);continue}E.add(w),C.push(k),_.push(w);}let b=new Map(l.map(y=>[y.key,y])),A=[];for(let y=0;y<C.length;y++){let k=_[y],w=C[y],Q=b.get(k);if(Q)u.get(k).set(w),A.push(Q),b.delete(k);else {let Ut=S(w,{equals:r});u.set(k,Ut);let uo={...Ut,set(){}},Kt={key:k,nodes:[]};V(a,()=>{let fo=n(uo,y),{nodes:mo,instance:Ft}=ae(fo);Kt.nodes=mo,Ft&&queueMicrotask(()=>ce(Ft));}),A.push(Kt);}}for(let[y,k]of b)Ue(k.nodes),u.delete(y);let N=null;for(let y=A.length-1;y>=0;y--){let k=A[y].nodes;for(let w=k.length-1;w>=0;w--){let Q=k[w];(Q.parentNode!==c||Q.nextSibling!==N)&&c.insertBefore(Q,N),N=Q;}}l=A;});return q(c,m),c}function Et(t,e,n,o){if(typeof t=="function")return pn(t,e,n,o);let{each:r,keyFn:s,equals:i,tagName:c,children:a,...l}=t??{};if(typeof s!="function")throw new Error('For: "keyFn" prop is required and must be a function');let u=ut(r),f=ft(t??{},e);return pn(u,s,f,{...l,equals:i,tagName:c})}Et[De]=t=>t!=="each";function Z(t,e){if(typeof t=="string"&&(t=document.querySelector(t)),!t)throw new Error("mount: container not found");t instanceof DocumentFragment||(Ne(t),t.innerHTML=""),X(e)?ht(t,e):e instanceof Node?t.appendChild(e):t.appendChild(document.createTextNode(String(e)));}function gn(t){if(typeof t=="string"&&(t=document.querySelector(t)),!t)throw new Error("unmount: container not found");Ne(t),t.innerHTML="";}function Re(t,e){let n=null;if(X(e)?(n=e.$constructor(),queueMicrotask(()=>ce(e))):e instanceof Node?n=e:n=document.createTextNode(String(e)),n instanceof HTMLElement){let o=L(()=>!!t()),r=P(()=>{n.style.display=o.get()?"":"none";});q(n,r);}return n}var O=class extends Ke{static get nodeName(){return "span"}static get style(){return "SPAN"}static match(e){return e.nodeName===this.nodeName.toUpperCase()||e.style===this.style}getState(){return {style:this.constructor.style}}render(){return h(this.constructor.nodeName,{},this.props.children)}};var le=class extends O{static get nodeName(){return "b"}static get style(){return "BOLD"}static get LABEL(){return h("b",{},"B")}static match(e){return e.nodeName==="strong"?true:super.match(e)}};var ue=class extends O{static get nodeName(){return "i"}static get style(){return "ITALIC"}static get LABEL(){return h("i",{},"I")}};var fe=class extends O{static get nodeName(){return "sub"}static get style(){return "SUBSCRIPT"}static get LABEL(){return h("sub",{},"Sub")}};var me=class extends O{static get nodeName(){return "sup"}static get style(){return "SUPERSCRIPT"}static get LABEL(){return h("sup",{},"Sup")}};var pe=class extends O{static get nodeName(){return "u"}static get style(){return "UNDERLINE"}static get LABEL(){return h("u",{},"U")}};var U=Symbol("result-key"),Fe=Symbol("stopped-event");function hn(t,e){let n=!!e.name,o=e[U]||"result",r=o.includes("."),s={error:null,context:{},[U]:o,...e,[o]:n?void 0:ee(e,o),name:t,[Fe]:false,defaultPrevented:false};return r&&(To(s,o),s[o]=n?void 0:ee(e,o)),s.stopPropagation=()=>{s[Fe]=true;},s.preventDefault=()=>{s.defaultPrevented=true;},s}function ee(t,e){return e===""?t:e.split(".").reduce((o,r)=>o?.[r]??void 0,t)}function yt(t,e,n){let o=e.split("."),r=o.pop(),s=ee(t,o.join("."));return s[r]=n}function To(t,e){let n=e.split(".");n.pop(),n.reduce((o,r)=>o[r]=o[r]??{},t);}var He=class{constructor({logger:e,debug:n}={}){this._logger=e??console,this._debug=n??false,this._events=new Map,this.addListener=this.on,this.removeListener=this.off;}emit(e,n={}){let o=this.listeners(e),r=hn(e,n),s=null,i=null;this._debug&&(typeof this._debug=="function"?this._debug(e,r):this._logger.debug(`Event name: ${e}, event: ${r}`));for(let c of o){if(s&&(s=s.then(a=>(yt(r,r[U],a??ee(r,r[U])),r[Fe]?ee(r,r[U]):c(r)))),!s){if(r[Fe])return r;i=c(r);}i instanceof Promise&&!s?s=i:yt(r,r[U],i??ee(r,r[U]));}return s?s.then(c=>(yt(r,r[U],c??ee(r,r[U])),r)):r}emitParallel(e,n={}){let o=this.listeners(e),r=hn(e,n);return Promise.all(o.map(async s=>await s(r))).then(s=>(r[r[U]]=s,r)).catch(s=>{throw r.error=s,s})}listeners(e){return this._events.has(e)?[...this._events.get(e)]:[]}removeAllListeners(e){return e?this.listeners(e).forEach(n=>this.off(e,n)):Array.from(this._events.keys()).forEach(n=>this.removeAllListeners(n))}_addListener(e,n,o){return this._events.has(e)||this._events.set(e,[]),this._events.get(e)[o](n),()=>{this.off(e,n);}}on(e,n){if(typeof n!="function")throw new TypeError("The listener must be a function");return this._addListener(e,n,"push")}prependListener(e,n){return this._addListener(e,n,"unshift")}_addListenerOnce(e,n,o){let r=this[o](e,s=>(r(),n(s)));}once(e,n){return this._addListenerOnce(e,n,"on")}prependOnceListener(e,n){return this._addListenerOnce(e,n,"prependListener")}off(e,n){if(this._events.has(e)){let o=this._events.get(e),r=o.indexOf(n);o.splice(r,1);}}};var p={INSERT_BLOCK_ELEMENT:"mrakomor:insert-block-component",REPLACE_BLOCK_ELEMENT:"mrakomor:replace-block-component",REMOVE_BLOCK_ELEMENT:"mrakomor:remove-block-component",MERGE_BLOCK_ELEMENT:"mrakomor:merge-block-component",INSERT_ENTITY_RANGE:"mrakomor:insert-entity-range",REMOVE_ENTITY_RANGE:"mrakomor:remove-entity-range",INSERT_INLINE_STYLE_RANGE:"mrakomor:insert-inline-style-range",KEYDOWN:"mrakomor:keydown",BEFORE_INPUT:"mrakomor:beforeinput",INPUT:"mrakomor:input",CLICK:"mrakomor:click",FOCUSIN:"mrakomor:focusin",FOCUSOUT:"mrakomor:focusout",SELECTION_CHANGE:"mrakomor:selection-change",CONTENT_CHANGE:"mrakomor:content-change",TRANSFORM_BLOCK_ELEMENT:"mrakomor:transform-block-element",MOVE_BLOCK_ELEMENT:"mrakomor:move-block-element"};function B(t){return e=>{if(!e.defaultPrevented)return t(e)}}function En({mrakomor:t}={}){let e=t?.emitter??new He;function n(o,r={}){return typeof t?.emit=="function"?t.emit(o,r):e.emit(o,{...r,mrakomor:t})}return {emitter:e,command:{insertBlockElement(o,r){n(p.INSERT_BLOCK_ELEMENT,{...o,options:r});},replaceBlockElement(o,r){n(p.REPLACE_BLOCK_ELEMENT,{...o,options:r});},removeBlockElement(o,r){n(p.REMOVE_BLOCK_ELEMENT,{...o,options:r});},mergeBlockElement(o,r){n(p.MERGE_BLOCK_ELEMENT,{...o,options:r});},insertEntityRange(o,r){n(p.INSERT_ENTITY_RANGE,{...o,options:r});},removeEntityRange(o,r){n(p.REMOVE_ENTITY_RANGE,{...o,options:r});},insertInlineStyleRange(o,r){n(p.INSERT_INLINE_STYLE_RANGE,{...o,options:r});},transformBlockElement(o,r){n(p.TRANSFORM_BLOCK_ELEMENT,{...o,options:r});},moveBlockElement(o,r){n(p.MOVE_BLOCK_ELEMENT,{...o,options:r});}}}}function yn(t){return t.map((e,n)=>({entry:e,index:n})).sort((e,n)=>{let o=e.entry.order??e.index,r=n.entry.order??n.index;return o!==r?o-r:e.index-n.index}).map(({entry:e})=>e)}var de=class extends xe{mrakomor;#e=new Map;#n=null;#r=0;#t;constructor(e,n={}){super(),this.mrakomor=e,this.#t=n.sort??yn;}normalize(e,n){throw new Error("Register subclass must implement normalize")}#o(){this.#n=null,this.next(this.list());}#i(e,n=this.#r++){let o=this.normalize(e,n);return o?(this.#e.set(o.id,o),o):null}add(e){if(Array.isArray(e)){let o=[];for(let r of e){let s=this.#i(r,this.#r++);s&&o.push(s);}return o.length&&this.#o(),o}let n=this.#i(e);return n&&this.#o(),n}get(e){return this.#e.get(e)}has(e){return this.#e.has(e)}remove(e){let n=this.#e.delete(e);return n&&this.#o(),n}list(){return this.#n??=this.#t([...this.#e.values()]),this.#n}};var Oo={abortEarly:true};function Ct(t,e){if(e===void 0)return t;let n=t?.cause?.key?`${e}.${t.cause.key}`:`${e}`;return {message:`Error parsing key "${n}": ${t.message}`,cause:{key:n}}}function Do(t,e,n){if(t.errors?.length)for(let o=0;o<t.errors.length;o++)e.push(Ct(t.errors[o],n));}function Sn(t,e,n,o){if(n!==false){let r=Ct(t.error,e);return {success:false,error:r,errors:[r]}}Do(t,o,e);}function ze(t){return t?.abortEarly!==void 0?t:Oo}function xt(t,e){v(t,"_parse",(n,o,r)=>{let s=n(o,r);return !s.success&&e(o)?{success:true,data:o}:s});}var Ae=t=>typeof t=="string"||t instanceof String,bt=t=>(typeof t=="number"||t instanceof Number)&&!Number.isNaN(t),St=t=>t===true||t===false,Po=t=>t instanceof Date&&!Number.isNaN(t.getTime()),$o=t=>typeof t=="function",jo=t=>Array.isArray(t),kt=t=>typeof t=="object"&&t!==null&&!Array.isArray(t);function kn(t,e){let n=D(kt,{...e,type:"object"});n._getDescription=()=>`object({ ${Object.entries(t).map(([r,s])=>`${r}: ${s._getDescription()}`).join(", ")} })`,n._getDefinition=()=>t;let o=n;return o.derive=function(r,{when:s="always"}={}){return v(this,"_parse",(i,c,a)=>{let l=i(c,a);if(!l.success)return l;let u=r(l.data,{context:a?.context});if(!kt(u)){let f={message:`derive() callback must return a plain object of overrides, got ${u===null?"null":typeof u}`};return {success:false,error:f,errors:[f]}}if(s==="missing"){let f={...l.data};for(let m in u)f[m]===void 0&&(f[m]=u[m]);return {success:true,data:f}}return {success:true,data:{...l.data,...u}}}),this},v(n,"_parse",(r,s,i)=>{let c=r(s,i),{abortEarly:a}=ze(i);if(c.success===false)return c;let l={},u=[];for(let f in t){let m=t[f]._parse(c.data[f],i);if(m.success)l[f]=m.data;else {let d=Sn(m,f,a,u);if(d)return d}}return u.length>0?{success:false,error:u[0],errors:u}:{success:true,data:l}}),o}function _t(t){return D(Ae,{...t,type:"string"})}function Nt(t){return D(bt,{...t,type:"number"})}function Rt(t){return D(St,{...t,type:"boolean"})}function At(t){return D(Po,{...t,type:"date"})}function Cn(t){return D($o,{...t,type:"function"})}function _n(t,e){let n=i=>t.includes(i),o=i=>`Invalid ${r} value. Expected ${t.map(c=>`"${c}"`).join(" | ")}, received "${i}".`,r="enum",s=D(n,{message:o,...e,type:r});return s._getDescription=()=>`enum(${t.map(i=>`"${i}"`).join(" | ")})`,s._getDefinition=()=>t,s}function Nn(t,e){let n=D(jo,{...e,type:"array"});return n._getDescription=()=>`array(${t._getDescription()})`,n._getDefinition=()=>t,v(n,"_parse",(o,r,s)=>{let i=o(r,s),{abortEarly:c}=ze(s);if(i.success===false)return i;let a=[],l=[],u=s;for(let f=0;f<i.data.length;f++){let m={...u,context:{...u?.context,index:f}},d=t._parse(i.data[f],m);if(d.success)a.push(d.data);else {let x=Sn(d,f,c,l);if(x)return x}}return l.length>0?{success:false,error:l[0],errors:l}:{success:true,data:a}}),n}function Rn(){return D(()=>true)}function ge(t,e){return v(e,"_parse",(n,o,r)=>(o=t(o),n(o,r))),e}function An(t,e){let n=r=>`Invalid union value. Expected the value to match one of the schemas:${t.map((s,i)=>` ${i+1}. ${s._getDescription()}`).join(",")} but received "${typeof r}" with value: ${kt(r)?JSON.stringify(r):`"${r}"`}`,o=D(()=>false,{message:n,...e,type:"union"});return o._getDefinition=()=>t,v(o,"_parse",(r,s,i)=>{let c=i,a=[];for(let m=0;m<t.length;m++){let d=t[m]._parse(s,c);if(d.success)return d;a.push(d);}let{abortEarly:l}=ze(c),u={message:typeof n=="function"?n(s):n};if(l!==false)return {success:false,error:u,errors:[u]};let f=[];for(let m=0;m<a.length;m++){let d=a[m].errors;if(d?.length)for(let x=0;x<d.length;x++)d[x].cause?.key&&f.push(Ct(d[x],`branch ${m}`));}return f.length===0&&f.push(u),{success:false,error:f[0],errors:f}}),o}function In(t,e){let n=D(o=>o===t,{message:o=>e?.message?typeof e.message=="function"?e.message(o):e.message:`Expected literal value "${t}", received "${o}"`,name:e?.name,type:"literal"});return n._getDescription=()=>`literal("${t}")`,n._getDefinition=()=>t,n}function Bn(t){let e=D(()=>true,{type:"contextRef"});return e._getDescription=()=>`contextRef("${t}")`,v(e,"_parse",(n,o,r)=>({success:true,data:r?.context?.[t]})),e}function vn(t,e){return {parse(n,o){let r=t.parse(o?.context??{},o);return e(r).parse(n,o)},safeParse(n,o){let r=t.safeParse(o?.context??{},o);return r.success?e(r.data).safeParse(n,o):r}}}var Mn={boolean(t){let e=t?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return ge(n=>{let o;return Ae(n)&&(o=n.toLowerCase()),o==="true"||o==="yes"||o==="on"||o==="1"||n===1?true:o==="false"||o==="no"||o==="off"||o==="0"||n===0?false:n},Rt({...t,message:e}))},number(t){let e=t?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return ge(n=>{if(St(n))return Number(n);if(Ae(n)){let o=n.trim();if(o==="")return n;let r=Number(o);if(Number.isFinite(r))return r}return n},Nt({...t,message:e}))},string(t){let e=t?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return ge(n=>St(n)||bt(n)&&Number.isFinite(n)?String(n):n,_t({...t,message:e}))},date(t){let e=t?.message??(n=>`Cannot cast "${n}" to a valid date.`);return ge(n=>{let o;return Ae(n)&&(o=n.trim()),bt(n)&&Number.isFinite(n)||o?new Date(o??n):n},At({...t,message:e}))},json(t,e){let n=e?.message??(o=>`Cannot parse "${o}" as JSON.`);return v(t,"_parse",(o,r,s)=>{if(Ae(r))try{r=JSON.parse(r);}catch{let i={message:typeof n=="function"?n(r):n};return {success:false,error:i,errors:[i]}}return o(r,s)}),t}},wn={},g={object:kn,string:_t,number:Nt,boolean:Rt,date:At,function:Cn,enum:_n,array:Nn,any:Rn,preprocess:ge,union:An,literal:In,contextRef:Bn,withContext:vn,coerce:wn,cast:Mn};function xn(t){return e=>`The value "${e}" must be type of ${t} but is type of "${typeof e}".`}function v(t,e,n){let o=t[e];t[e]=(...r)=>n(o,...r);}function D(t,{type:e="any",name:n,message:o}={}){o=o||xn(e);let r={name:n,message:o,type:e},s={_getName(){return n},_getType(){return e},_getDescription(){return this._getName()??this._getType()},_parse(i,c){let a=t(i);if(a===true)return {success:true,data:i};if(typeof a=="object"&&a?.success===true)return a;let l={message:typeof o=="function"?o(i):o};return {success:false,error:l,errors:[l]}},parse(i,c){let a=this._parse(i,c);if(!a.success)throw a=a,new Error(a.error.message,{cause:a.error.cause});return a.data},safeParse(i,c){return this._parse(i,c)},transform(i){return v(this,"_parse",(c,a,l)=>{let u=c(a,l);return u.success&&(u.data=i(u.data)),u}),this},optional(){return xt(this,i=>i===void 0),this},nullable(){return xt(this,i=>i===null),this},nullish(){return xt(this,i=>i==null),this},default(i){return v(this,"_parse",(c,a,l)=>(a===void 0&&(a=typeof i=="function"?i({context:l?.context}):i),c(a,l))),this},catch(i){return v(this,"_parse",(c,a,l)=>{let u=c(a,l);return u.success?u:{success:true,data:typeof i=="function"?i({input:a,error:u.error}):i}}),this},pipe(i){return v(this,"_parse",(c,a,l)=>{let u=c(a,l);return u.success?i._parse(u.data,l):u}),this},refine(i,{message:c,type:a,jsonSchema:l}={}){if(a&&(c=c||xn(a),e=a),l){let u=[...this._getJsonSchemaHints?.()??[],l];this._getJsonSchemaHints=()=>u;}return v(this,"_parse",(u,f,m)=>{let d=u(f,m),{abortEarly:x}=ze(m);if(!d.success)return d;let C=i(d.data);if(C===true||typeof C=="object"&&C?.success===true)return d;let _={message:typeof c=="function"?c(f):c};return {success:false,error:_,errors:[_]}}),this},clone(){return {...this}}};return bn.length>0?bn.reduce((i,c)=>c(i,t,r)??i,s):s}var bn=[];var Uo=g.object({component:g.function(),id:g.string(),label:g.string(),keywords:g.array(g.string()),group:g.string(),order:g.number().default(({context:t})=>t?.index??0),settings:g.any().optional()});function Ko(t,e){let n=`block:${t}`;return e?.style==="UNORDERED"?`${n}:ul`:e?.style==="ORDERED"?`${n}:ol`:n}function Ln(t,e=0){let n=typeof t=="function",o=n?t:t?.component,r=n?{}:t,s=o.NAMESPACE??"",i=s.split(".").pop()||s,c=r.label||o.LABEL||i||s,a=Array.isArray(o.KEYWORDS)?o.KEYWORDS:[],l=r.keywords?.length?r.keywords.map(String):a.length?a.map(String):[c,i].filter(Boolean).map(String),u=r.settings;return Uo.parse({component:o,id:r.id||Ko(s,u),label:String(c),keywords:l,group:String(r.group||o.GROUP||"blocks"),...typeof r.order=="number"?{order:r.order}:{},...u?{settings:u}:{}},{context:{index:e}})}var Ge=class t extends de{#e=null;constructor(e){super(e),this.subscribe(()=>{this.#e=null;});}normalize(e,n){if(e==null)return null;try{return Ln(e,n)}catch{return null}}getByNamespace(e){return this.#n().get(e)}#n(){return this.#e??=t.buildNamespaceMap(this.list()),this.#e}static buildNamespaceMap(e){let n=new Map;for(let o of e){let r=o.component?.NAMESPACE;r&&!n.has(r)&&n.set(r,o.component);}return n}};var It="molecule.paragraph.Paragraph";var Tn="molecule.external.ExternalComponent",On="namespace.unknown.UnknownComponent";var Dn="molecule.headline.";var Bt=wt(),vt=wt(),Pn=wt(),Fo=Array.from({length:256},(t,e)=>(e<=15?"0":"")+e.toString(16));function wt(){return Math.floor(Math.random()*16777215)}function Ho(){return vt=(vt+1)%16777215,vt}function J(){let t=Math.floor(Date.now()/1e3);t=parseInt(t,10)%4294967295;let e=Ho(),n=String.fromCharCode(t>>24&255,t>>16&255,t>>8&255,t&255,Bt>>16&255,Bt>>8&255,Bt&255,Pn>>8&255,Pn&255,e>>16&255,e>>8&255,e&255),o="";for(let r=0;r<n.length;r++)o+=Fo[n.charCodeAt(r)];return o}var Ie=Symbol("block-element"),zo=Symbol("block-element-body"),he=Symbol("selectable-element");function qe(t,e){let n=t;for(n?.nodeType===Node.TEXT_NODE&&(n=n.parentElement);n&&n[e]===void 0;)n=n.parentElement;return n??null}function K(t){return t?qe(t.startContainer,Ie):null}function $n(t){return qe(t,Ie)}function Un(t){return t?qe(t.startContainer,he):null}function jn(t){return qe(t,he)}function Go(t){return t?t[he]!==void 0?[t]:[...t.children].filter(e=>e[he]!==void 0):[]}function qo(t,e){return e?Go(t).indexOf(e):-1}function Kn(t,e){let n=Un(e);return !n||!t?.contains(n)?null:{element:n,index:qo(t,n)}}function Lt(){return window.getSelection()}function F(){let t=Lt();return t.rangeCount>0?t.getRangeAt(0).cloneRange():null}function Tt(){let t=F();if(!t)return 0;t.collapse(true);let e=Un(t),n=K(t),o=e??I(n);return Ee(o,t.startContainer,t.startOffset)}function Ee(t,e,n){if(!t)return 0;if(e===t){if(e.nodeType===Node.TEXT_NODE)return n;let i=0,c=t.childNodes,a=Math.min(n,c.length);for(let l=0;l<a;l++)i+=c[l].textContent.length;return i}if(e.nodeType===Node.ELEMENT_NODE&&!t.contains(e))return 0;let o=0,r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),s=r.nextNode();for(;s;){if(s===e)return o+n;o+=s.textContent.length,s=r.nextNode();}return o}function Hn(t=F()){if(!t||t.collapsed)return null;let e=$n(t.startContainer),n=$n(t.endContainer);if(!e||!n)return null;let o=jn(t.startContainer)??I(e),r=jn(t.endContainer)??I(n);return {startBlock:e,endBlock:n,startOffset:Ee(o,t.startContainer,t.startOffset),endOffset:Ee(r,t.endContainer,t.endOffset)}}function Mt(t,e){let n=document.createRange();if(!t)return n;if(e<=0)return n.setStart(t,0),n.collapse(true),n;let o=0,r=[t];for(;r.length>0;){let s=r.pop();if(s.nodeType===Node.TEXT_NODE){let i=s.textContent.length;if(o+i>=e)return n.setEnd(s,e-o),n.setStart(s,e-o),n;o+=i;}else if(s.childNodes&&s.childNodes.length>0)for(let i=s.childNodes.length-1;i>=0;i--)r.push(s.childNodes[i]);}return n.setEnd(t,t.childNodes.length),n.setStart(t,t.childNodes.length),n}function Y(t,e){let n=Mt(t,e),o=Lt();o.removeAllRanges(),o.addRange(n);}function I(t){if(!t)return null;let e=zn(t);return e?.firstElementChild??e?.firstChild}function M(t){if(!t?.[Ie])return null;let e=I(t);return e?se(e)?.classInstance:null}function zn(t){if(!t)return null;for(let e of t.children)if(e[zo])return e;return null}function Ot(t){return zn(t)?.childNodes?.[0]?.contentEditable==="true"}function Ye(t,e,n,o=12){let r=t.getBoundingClientRect(),s=typeof e?.getBoundingClientRect=="function"?e.getBoundingClientRect():e??{left:0,top:0},i=n?.offsetHeight??40;return {x:s.left-r.left,y:s.top-r.top-i-o}}function Gn(t,e){let n=t.getBoundingClientRect(),o=e?.offsetWidth??420,r=e?.offsetHeight??320,s=16;return {x:Math.max(s,(n.width-o)/2),y:Math.max(s,(n.height-r)/2)}}var Ve=pt();var We=class extends Ke{state;element;mrakomor;constructor(e){super(e);let{state:n,observeDOMChanges:o=true}=e??{};this.state=n,this.element=null,this.mrakomor=gt(Ve),this._stale=false,this._observer=null,this._offInputStale=null,this._onInputMarkStale=null,this._observeDOMChanges=o;}static get NAMESPACE(){return "namespace.AbstractComponent"}static getStateSchema(){return g.object({component:g.string().default(this.NAMESPACE),properties:g.object().default({}),settings:g.object().default({})}).default({})}static getPropsSchema(){return g.object({state:this.getStateSchema(),observeDOMChanges:g.boolean().default(true)}).default({})}parseFromHTML(e){return this.constructor.getStateSchema(e).parse()}getState(){if(this._stale){let e=this.element;return this.parseFromHTML(e)}return this.state.peek()}isStale(){return this._stale}#e(){this._stale=true;}onMount(){!this.element||!this._observeDOMChanges||(this._observer=new MutationObserver(()=>{this.#e();}),this._observer.observe(this.element,{subtree:true,characterData:true,characterDataOldValue:true,childList:true,attributes:true,attributeOldValue:true}),this._onInputMarkStale=e=>{let n=e.target;n instanceof Node&&this.element?.contains(n)&&this.#e();},this.mrakomor?.emitter&&(this._offInputStale=this.mrakomor.emitter.on(p.INPUT,this._onInputMarkStale)));}onUnmount(){this._observer&&(this._observer.disconnect(),this._observer=null),this._offInputStale?.(),this._offInputStale=null,this._onInputMarkStale=null,this._stale=false;}};function $(t){return t===`
3
3
  `||t===`\r
4
- `?"":t??""}function oe({component:t,originComponent:e,properties:n,settings:o}={}){let r=n??{},s=Array.isArray(r.items)?r.items:[{text:r.text??"",inlineStyleRanges:r.inlineStyleRanges??[],entityRanges:r.entityRanges??[]}];return {...t?{component:t}:{},...e?{originComponent:e}:{},properties:{items:s},...o?{settings:o}:{}}}function Wn(t){let e="",n=[],o=[];return (t??[]).forEach((r,s)=>{s>0&&(e+=`
5
- `);let i=e.length;e+=Q(r?.text);for(let a of r?.inlineStyleRanges??[])n.push({...a,offset:a.offset+i});for(let a of r?.entityRanges??[])o.push({...a,offset:a.offset+i});}),{text:e,inlineStyleRanges:n,entityRanges:o}}function Xn(t){return {properties:{text:t?.text??"",inlineStyleRanges:t?.inlineStyleRanges??[],entityRanges:t?.entityRanges??[]}}}function jt(t,e,n,o){let r=t.toExchangeState(e),s=[...r.properties?.items??[]];if(!s[n])return e;s[n]={...s[n],...o};let i=t.fromExchangeState({...r,properties:{...r.properties,items:s}});return {...e,properties:i?.properties??e.properties,settings:i?.settings??e.settings}}function Ut(t,e,n){let o=t._getBlockElementState(e);if(!o)return null;let r=t.register.blocks.getByNamespace(o.component);if(!r)return null;let s=r.toExchangeState(o)?.properties?.items??[];if(!s.length)return null;let i=I(e),a=Fn(i,n),c=a?.element??i??e,l=a?.index??0,u=s[l];return u?{Constructor:r,current:o,element:c,itemIndex:l,item:u}:null}function Jn({mrakomor:t,resultIndex:e,cursor:n,fallbackBlockElement:o,itemIndex:r}){let s=()=>{if(typeof n!="number")return;let i=t._getBlockElements()[e]??o,a=D(i);if(a?.setCursor){a.setCursor({cursor:n,itemIndex:r});return}let c=I(i);c?.isConnected&&Y(c,n);};s(),A(s);}function Qe(t){let e=t?.component??"";return e===wt||e.startsWith(Pn)}function Kt(t,e){let n=Q(t.properties.text),o=Q(e.properties.text);return {state:{...t,properties:{...e.properties,...t.properties,text:n+o,inlineStyleRanges:[...t.properties.inlineStyleRanges??[],...(e.properties.inlineStyleRanges??[]).map(r=>({...r,offset:r.offset+n.length}))],entityRanges:[...t.properties.entityRanges??[],...(e.properties.entityRanges??[]).map(r=>({...r,offset:r.offset+n.length}))]},settings:{...e.settings,...t.settings}},cursor:n.length}}function Qn(t,{startIndex:e,endIndex:n,startOffset:o,endOffset:r}){let s=[...t],i=s[e],a=s[n],{originalLineState:c}=Vn(i,o),{newLineState:l}=Vn(a,r),{state:u,cursor:f}=Kt(c,l);return s.splice(e,n-e+1,u),{content:s,cursor:f,resultIndex:e}}function qn(t,e){return (t??[]).filter(n=>n.offset<e).map(n=>({...n,length:Math.min(n.length,e-n.offset)}))}function Yn(t,e){return (t??[]).filter(n=>n.offset+n.length>e).map(n=>({...n,offset:Math.max(0,n.offset-e),length:n.offset+n.length-Math.max(n.offset,e)}))}function Vn(t,e){let n=structuredClone(t),o=structuredClone(t);return n.properties.text=t.properties.text.slice(0,e),o.properties.text=t.properties.text.slice(e),n.properties.inlineStyleRanges=qn(t.properties.inlineStyleRanges,e),o.properties.inlineStyleRanges=Yn(t.properties.inlineStyleRanges,e),n.properties.entityRanges=qn(t.properties.entityRanges,e),o.properties.entityRanges=Yn(t.properties.entityRanges,e),o.componentId=J(),{originalLineState:n,newLineState:o}}function Zn(t,e){if(e.key!=="Enter")return false;e.preventDefault();let n=wt,o=t.mrakomor.resolveComponentConstructor(n);return t.mrakomor.command.insertBlockElement({range:q(),cursor:0,newLineState:t.mrakomor.normalizeComponentState(o.getStateSchema().parse({})),namespace:n}),true}function eo(t,e){let n=Ee(t,e.startContainer,e.startOffset),o=Ee(t,e.endContainer,e.endOffset);return {offset:n,length:Math.max(0,o-n)}}function Yo(t,{style:e,offset:n,length:o}){let r=t??[],s=n+o,i=r.find(a=>a.style===e&&a.offset<=n&&a.offset+a.length>=s);return i?r.filter(a=>a!==i):[...r,{style:e,offset:n,length:o}]}function Vo(t,e){return t.offset<e.offset+e.length&&e.offset<t.offset+t.length}function Wo(t,e){let n=e.offset+e.length,o=[];for(let r of t){if(!Vo(r,e)){o.push(r);continue}r.offset<e.offset&&o.push({...r,length:e.offset-r.offset});let s=r.offset+r.length;s>n&&o.push({...r,offset:n,length:s-n});}return o}function Xo(t,e){let n=t??[],o=e?.length??0;if(o===0)return null;let r=e.offset??0,s=e.entity?.type,i=n.find(a=>a.offset===r&&a.length===o&&a.entity?.type===s);return i?n.filter(a=>a!==i):[...Wo(n,e),e]}function to(t,e,n,o){if(!e||!n)return null;let{offset:r,length:s}=eo(e,n);return s===0?null:Yo(t??[],{style:o,offset:r,length:s})}function no(t,e,n,{namespace:o,entityData:r}){if(!e||!n)return null;let s={...r,entity:{type:o,...r?.entity},...eo(e,n)};return Xo(t??[],s)}var Ze=class extends Je{static get NAMESPACE(){return "namespace.block.BlockComponent"}static get LABEL(){return ""}static get KEYWORDS(){return []}static get GROUP(){return "blocks"}isAtomic(){return false}setCursor({cursor:e}={}){let n=()=>{if(!this.element?.isConnected)return;let o=typeof e=="number"?e:Q(this.getState()?.properties?.text).length;Y(this.element,o);};n(),A(n);}onKeydown(e){}static toExchangeState(e){let n=e?.properties,o={text:Q(n?.text)};return n?.inlineStyleRanges!==void 0&&(o.inlineStyleRanges=n.inlineStyleRanges),n?.entityRanges!==void 0&&(o.entityRanges=n.entityRanges),oe({originComponent:this.NAMESPACE,properties:{items:[o]},settings:e?.settings})}static fromExchangeState(e){let n=e?.properties?.items?.[0];return {properties:{text:n?.text??"",inlineStyleRanges:n?.inlineStyleRanges??[],entityRanges:n?.entityRanges??[]},settings:e?.settings}}static appendExchangeState(e,n){let o=Wn(n?.properties?.items);return Kt(e,Xn(o))}};var re=class t extends Ze{static get NAMESPACE(){return On}static getStateSchema(e){return d.object({component:d.string().default(t.NAMESPACE),componentId:d.string().default(e?.getAttribute("data-componentid")||J()),properties:d.object({}).default({}),settings:d.object({}).default({})}).default({})}constructor(e){super(e),this.root=null;}getState(){return this.state.peek()}isAtomic(){return true}static appendExchangeState(){return null}onMount(){}onUnmount(){}render(){let e=this.constructor.NAMESPACE.toLowerCase().replaceAll(".","-");return E("div",{className:e,contentEditable:false,style:"position: relative;",$ref:o=>{this.element=o;},"data-state":()=>JSON.stringify(this.state.get()),"data-componentid":this.state.peek().componentId},[E("div",{$ref:o=>{this.root=o;},style:"display: block;",contentEditable:false}),E("span",{style:"position: absolute; bottom: 0; right: 0; width: 10px; height: 100%; outline: none;",contentEditable:true,[he]:true},document.createTextNode("\xA0"))])}onKeydown(e){e.key!=="Backspace"&&e.key!=="ArrowUp"&&e.key!=="ArrowDown"&&e.preventDefault(),Zn(this,e);}};var ye=class extends re{static get NAMESPACE(){return Dn}onMount(){let e=E("div",{style:"user-select: none;",contentEditable:false},()=>`Unknown component: ${this.state.get().component}`);ee(this.root,e);}onUnmount(){this.root.innerHTML="";}};function Jo(t,e){let n=t._getBlockElementByComponentId(e);return D(n)?.isStale?.()??false}function oo(t){return (e,n)=>{if(!ie(e,n))return false;let o=n?.componentId??e?.componentId;return !(o&&Jo(t,o))}}function ro({mrakomor:t}){let e=t.get(),n=oo(e);yt(Xe,e);let o=W(r=>{e._setContentRoot(r??null);});return $e(()=>{e._onMount();}),je(()=>{e._onUnmount();}),E("div",{id:e._id,className:"mrakomor-editor"},[E("div",{className:"mrakomor-editor-surface"},[E("div",{className:"mrakomor-tools-container"}),E("div",{className:"mrakomor-content",contentEditable:true,style:{spellcheck:true,outline:"none"},$ref:o},[St(()=>e._getContentState(),r=>r.componentId,(r,s)=>E(()=>{let i;$e(()=>{i.getNodeComponent=()=>{let l=I(i);return l?se(l):null},e._setBlockElement(i,s);}),je(()=>{e._removeBlockElement(i);});let a=e.resolveComponent(r.get().component,r),c=e.wrapBlockElement(a);return E("div",{className:"mrakomor-block-element",[ve]:true,$ref:l=>{i=l;}},c)}),{equals:n})])])])}function et(t,e,n){let o=t._getBlockElementIndex(e);if(o===-1)return false;let r=t.getContent();return r.splice(o,1,t.normalizeComponentState(n)),t._setContentState(r),true}function Qo(t){let{mrakomor:e}=t,{blockElement:n,range:o,newLineState:r,originalLineState:s,namespace:i,position:a,cursor:c}=t,l,u;if(a||(n?l=e._getBlockElementIndex(n):o&&(l=e._getBlockElementIndex(G(o))),l===void 0||l===-1))return;u=l+1;let f=e.getContent();s&&f.splice(l,1,e.normalizeComponentState(s)),r&&(r.component=i,f.splice(u,0,e.normalizeComponentState(r))),e._setContentState(f),A(()=>{typeof c=="number"&&D(e._getBlockElements()[u])?.setCursor?.({cursor:c});});}function Zo(t){let{mrakomor:e}=t,{blockElement:n,range:o,blocks:r,cursor:s,cursorBlockIndex:i=0}=t;if(!Array.isArray(r)||r.length===0)return;let a=n??(o?G(o):null),c=e._getBlockElementIndex(a);if(c===-1)return;let l=[...e._getContentState()];l.splice(c,1,...r.map(u=>e.normalizeComponentState(u))),e._setContentState(l),A(()=>{if(typeof s!="number")return;e._syncBlockElementsFromDom();let u=I(e._getBlockElements()[c+i]);u?.isConnected&&Y(u,s);});}function er(t){let{mrakomor:e,blockElement:n,namespace:o}=t,r=e._getBlockElementState(n);if(!r)return;let s=e.register.blocks.getByNamespace(r.component),i=e.register.blocks.getByNamespace(o),a=(t.exchangeState&&oe(t.exchangeState))??s?.toExchangeState?.(r)??oe({properties:r.properties,settings:r.settings}),c=i?.fromExchangeState?.(a)??a;et(e,n,{...c,component:o,componentId:J()});}function tr(t){let{mrakomor:e,blockElement:n,targetIndex:o}=t,r=e._getBlockElementIndex(n);if(r===-1||typeof o!="number")return;let s=o>r?o-1:o;if(s===r)return;let i=[...e._getContentState()],[a]=i.splice(r,1);i.splice(s,0,a),e._setContentState(i);}function nr(t){let{mrakomor:e,blockElement:n,range:o}=t,r=e._getBlockElementIndex(n);if(r!==-1){let s=e.getContent();s.splice(r,1),e._setContentState(s);}A(()=>{let s=G(o);Y(I(s),0);});}function or(t){let{mrakomor:e,state:n,blockElement:o}=t,r=e._getBlockElementState(o);if(!r)return;let s=structuredClone(r),i=n?.offset,a=n?.length,c=n?.entity?.type;s.properties.entityRanges=(s.properties.entityRanges??[]).filter(l=>!(l?.offset===i&&l?.length===a&&l?.entity?.type===c)),et(e,o,s),e.command.closeDialog?.();}function rr(t){let{mrakomor:e,namespace:n,state:o}=t,r=t.range??q(),s=t.blockElement??G(r),i=Ut(e,s,r);if(!i||i.item.entityRanges===void 0)return;let{Constructor:a,current:c,element:l,itemIndex:u,item:f}=i,p=no(f.entityRanges,l,r,{namespace:n,entityData:o});if(p===null)return;let h=jt(a,c,u,{entityRanges:p});et(e,s,h);}function sr(t){let{mrakomor:e,style:n}=t,o=t.range??q(),r=t.blockElement??G(o),s=Ut(e,r,o);if(!s||s.item.inlineStyleRanges===void 0)return;let{Constructor:i,current:a,element:c,itemIndex:l,item:u}=s,f=to(u.inlineStyleRanges,c,o,n);if(f===null)return;let p=jt(i,a,l,{inlineStyleRanges:f});et(e,r,p);}function ir(t){let{mrakomor:e,blockElement:n,previousBlockElement:o}=t,r=e._getBlockElementIndex(o),s=e._getBlockElementIndex(n);if(r===-1||s===-1)return;let i=e.getContent(),a=i[s],c=i[r],l=e.register.blocks.getByNamespace(c.component),u=e.register.blocks.getByNamespace(a.component),f=(t.exchangeState&&oe(t.exchangeState))??u?.toExchangeState?.(a)??oe({properties:a.properties,settings:a.settings}),p=l?.appendExchangeState?.(c,f);p&&(i.splice(s,1),i.splice(r,1,e.normalizeComponentState(p.state)),e._setContentState(i),Jn({mrakomor:e,resultIndex:r,cursor:p.cursor,fallbackBlockElement:o,itemIndex:p.itemIndex}));}function ar(t){let{mrakomor:e}=t,n=e.getRoot(),o=t.relatedTarget instanceof Node&&n.contains(t.relatedTarget),r=n?.contains(document.activeElement)??false;if(o||r)return;let[i,a]=H(()=>[e.getContent(),e._getContentState()]);i.length===a.length&&i.every((l,u)=>l===a[u])||e.setContent(i);}function cr(t){let{mrakomor:e,clientX:n,clientY:o}=t;if(typeof o!="number")return;let r=e._getContentRoot(),s=e._getBlockElements(),i=s[0],a=s[s.length-1];if(!r||!i||!a)return;let c=o<i.getBoundingClientRect().top,l=o>a.getBoundingClientRect().bottom;if(!c&&!l)return;if(typeof n=="number"){let f=r.getBoundingClientRect();if(n<f.left||n>f.right)return}let u=I(c?i:a);u?.isConnected&&Y(u,c?0:u.textContent.length);}function lr(t){let e=q();return G(e)?.getNodeComponent?.()?.classInstance?.onKeydown?.(t)}function ur(t){D(t)?.setCursor?.();}function fr(t){if(t.key!=="Backspace")return;let{mrakomor:e}=t,n=q();if(!n)return;let o=G(n);if(!o)return;let r=Ve(o),s=o?.previousSibling,a=Ve(s)?.childNodes?.[0]?.contentEditable==="true",c=r?.childNodes?.[0]?.contentEditable==="true",l=I(o),u=!Q(l?.textContent),f=n.collapsed&&(n.startOffset===0||$t()===0||u);if(!n.collapsed){let g=zn(n);if(g&&g.startBlock!==g.endBlock){let y=e._getBlockElementIndex(g.startBlock),k=e._getBlockElementIndex(g.endBlock),C=e.getContent(),x=y>=0?C[y]:void 0,_=k>=0?C[k]:void 0;if(y>=0&&k>y&&typeof x?.properties?.text=="string"&&typeof _?.properties?.text=="string"){t.preventDefault();let{content:U,cursor:xe,resultIndex:ct}=Qn(C,{startIndex:y,endIndex:k,startOffset:g.startOffset,endOffset:g.endOffset});e._setContentState(U.map(Z=>e.normalizeComponentState(Z))),A(()=>{let Z=e._getBlockElements()[ct];Z&&typeof xe=="number"&&Y(I(Z),xe);});}}return}if(!f)return;let p=e._getBlockElementIndex(o),h=s?e._getBlockElementIndex(s):-1,b=e._getBlockElementState(o),R=e._getBlockElementState(s),N=s?D(s):null;if(!s||h<0){t.preventDefault();return}if(R&&b&&Qe(b)&&N&&!N.isAtomic?.()){if(u&&!Qe(R)){t.preventDefault();let g=e.getContent();g.splice(p,1),e._setContentState(g),ur(s);return}t.preventDefault(),e.command.mergeBlockElement({blockElement:o,previousBlockElement:s,range:n});return}N?.isAtomic?.()&&(!a&&n.startOffset===0||o?.textContent==="\xA0"&&!c)&&(t.preventDefault(),e.command.removeBlockElement({blockElement:s,range:n})),b&&!Qe(b)&&t.preventDefault();}function tt(t){return {resolveComponent:e=>e===re.NAMESPACE?re:ye,registerCommands(e){e.emitter.on(m.INSERT_BLOCK_ELEMENT,w(Qo)),e.emitter.on(m.REPLACE_BLOCK_ELEMENT,w(Zo)),e.emitter.on(m.TRANSFORM_BLOCK_ELEMENT,w(er)),e.emitter.on(m.MOVE_BLOCK_ELEMENT,w(tr)),e.emitter.on(m.REMOVE_BLOCK_ELEMENT,w(nr)),e.emitter.on(m.REMOVE_ENTITY_RANGE,w(or)),e.emitter.on(m.INSERT_ENTITY_RANGE,w(rr)),e.emitter.on(m.INSERT_INLINE_STYLE_RANGE,w(sr)),e.emitter.on(m.MERGE_BLOCK_ELEMENT,w(ir));},registerHandlers(e){e.emitter.on(m.FOCUSOUT,ar),e.emitter.on(m.KEYDOWN,w(lr)),e.emitter.on(m.KEYDOWN,w(fr)),e.emitter.on(m.CLICK,w(cr));},registerListeners(e){let n=e.getRoot(),{signal:o}=e.listenerAbortController;n.addEventListener("keydown",r=>e.emitDomEvent(m.KEYDOWN,r),{signal:o}),n.addEventListener("beforeinput",r=>e.emitDomEvent(m.BEFORE_INPUT,r),{signal:o}),n.addEventListener("input",r=>e.emitDomEvent(m.INPUT,r),{signal:o}),n.addEventListener("focusin",r=>e.emitDomEvent(m.FOCUSIN,r),{signal:o}),n.addEventListener("focusout",r=>e.emitDomEvent(m.FOCUSOUT,r),{signal:o}),n.addEventListener("click",r=>e.emitDomEvent(m.CLICK,r),{signal:o}),document.addEventListener("selectionchange",r=>e.emitDomEvent(m.SELECTION_CHANGE,r),{signal:o});}}}(function(){if(!(typeof document>"u")){var t="mrakomor/core/plugin/dialog/Dialog.css",e=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(o){return o.getAttribute("data-mrakomor-css-path")===t});if(!e){var n=document.createElement("style");n.setAttribute("data-mrakomor-css",""),n.setAttribute("data-mrakomor-css-path",t),n.textContent=`.mrakomor-dialog-container,.mrakomor-dialog-backdrop{pointer-events:all}.dialog[open]{background-color:#fff;border:1px solid black;border-radius:8px;box-shadow:0 0 5px #0000001a;padding:12px;display:flex;flex-flow:row wrap;justify-content:space-between}.dialog[open] .dialog-controls{text-align:right;width:100%}.dialog[open] .dialog-button-close{background-color:#f0f0f0;border:1px solid black;border-radius:4px;color:#000;cursor:pointer;display:inline-block;font-size:14px;margin-right:1px;padding:4px 8px;text-align:center}.dialog[open] .dialog-container{width:100%}
6
- `,document.head.appendChild(n);}}})();function mr(t,e,n,o){let r=t.getRoot()?.querySelector(e);if(!r)return {container:null,dispose:null};let s=document.createElement("div");s.className=n,r.append(s);let i=ee(s,o);return {container:s,dispose:i??null}}function nt(t,e,n){return mr(t,".mrakomor-tools-container",e,n)}var so="mrakomor.dialog.Dialog";function ot({open:t,placement:e,positionX:n,positionY:o,block:r,dialogRef:s}){let i=M(()=>{let c=e.get()==="center";return {position:"absolute",zIndex:c?"9100":"9000",top:`${o.get()}px`,left:`${n.get()}px`,...c?{padding:0,background:"transparent",border:"none",boxShadow:"none",minWidth:0}:{background:"#fff",border:"1px solid #ccc",borderRadius:"4px",padding:"8px 10px",boxShadow:"0 2px 8px rgba(0,0,0,.15)",minWidth:"220px"}}}),a=M(()=>({position:"absolute",inset:"0",zIndex:"9050",background:"rgba(15, 23, 42, 0.28)",pointerEvents:"all"}));return E("span",{style:{display:"contents"}},[Ae(()=>t.get()&&e.get()==="center",E("div",{className:"mrakomor-dialog-backdrop",contentEditable:false,style:a})),Ae(()=>t.get(),E("div",{className:"mrakomor-dialog-container",contenteditable:false,style:i,$ref:s},()=>r.get()))])}ot.NAMESPACE=so;function rt({mrakomor:t}){let e=null,n=S(false),o=S(false),r=S("anchor"),s=S(0),i=S(0),a=S(null),c=W(null),l=W(null);function u(){o.set(false),r.set("anchor"),c.set(null),A(()=>{n.set(false);});}return {resolveComponent(f){if(f===so)return ot},registerEvents(){m.OPEN_DIALOG="mrakomor:open-dialog",m.CLOSE_DIALOG="mrakomor:close-dialog";},registerCommands(f){f.command.openDialog=(p,h)=>{f.emit(m.OPEN_DIALOG,{...p,options:h});},f.command.closeDialog=()=>{f.emit(m.CLOSE_DIALOG);};},registerHandlers(){t.emitter.on(m.OPEN_DIALOG,({children:f,element:p,options:h={}})=>{a.set(f??E("div",{},"Empty dialog")),o.set(true),c.set(p??null),r.set(h.placement??"anchor"),A(()=>{let b=t.getRoot(),{x:R,y:N}=h.placement==="center"?Gn(b,l):We(b,p??{left:0,top:0},l);s.set(R),i.set(N),n.set(true);});}),t.emitter.on(m.CLOSE_DIALOG,u),t.emitter.on(m.KEYDOWN,f=>{f.key==="Escape"&&o.peek()===true&&t.command.closeDialog();}),t.emitter.on(m.CLICK,f=>{if(o.peek()!==true||n.peek()!==true)return;let p=f.target,h=l&&typeof l.contains=="function"&&l.contains(p),b=c&&typeof c.contains=="function"&&c.contains(p);!h&&!b&&t.command.closeDialog();});},onMount(){let{dispose:f}=nt(t,"mrakomor-dialog-plugin-container",E(ot,{open:o,placement:r,positionX:s,positionY:i,block:a,dialogRef:l}));e=f;},onUnmount(){e?.(),e=null;}}}function pr(){return d.object({id:d.string(),group:d.string().default("general"),description:d.string().default(""),commands:d.array(d.string()).default([]),shortcuts:d.array(d.string()).default([])}).default({})}function io(t){try{return pr().parse(t)}catch{return null}}var st=class extends de{constructor(e){super(e,{sort:n=>n});}normalize(e){return io(e)}};(function(){if(!(typeof document>"u")){var t="mrakomor/core/plugin/menu/Menu.css",e=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(o){return o.getAttribute("data-mrakomor-css-path")===t});if(!e){var n=document.createElement("style");n.setAttribute("data-mrakomor-css",""),n.setAttribute("data-mrakomor-css-path",t),n.textContent=`.mrakomor-menu{position:absolute;z-index:9300;display:flex;flex-direction:column;gap:2px;min-width:160px;max-height:240px;overflow-y:auto;background:#1a1a1a;border-radius:6px;padding:4px;box-shadow:0 3px 10px #00000040;pointer-events:all}.mrakomor-menu__item{display:flex;align-items:center;width:100%;padding:6px 10px;border:none;border-radius:4px;background:transparent;color:#fff;cursor:pointer;font-size:13px;font-weight:600;text-align:left;transition:background .1s}.mrakomor-menu__item:hover,.mrakomor-menu__item--active{background:#ffffff26}.mrakomor-menu__empty{padding:6px 10px;font-size:13px;font-weight:600;color:#ffffff80}
7
- `,document.head.appendChild(n);}}})();function dr(t,e=-1){if(!t.length)return E("div",{className:"mrakomor-menu__empty",role:"presentation"},"No results");let n=t.map((o,r)=>E("button",{type:"button",role:"option",id:`mrakomor-menu-option-${o.id}`,className:["mrakomor-menu__item",r===e?"mrakomor-menu__item--active":""].filter(Boolean).join(" "),title:o.label,"data-id":o.id,"aria-selected":r===e?"true":"false",onMouseDown:s=>{s.preventDefault();}},o.label));return E("span",{style:"display: contents"},n)}function Ft({open:t,positionX:e,positionY:n,entries:o,highlightIndex:r,ariaLabel:s,menuRef:i}){let a=M(()=>({left:`${e.get()}px`,top:`${n.get()}px`}));return Ae(()=>t.get(),E("div",{className:"mrakomor-menu",role:"listbox","aria-label":()=>s.get(),contenteditable:false,style:a,$ref:i},()=>dr(o.get(),r.get())))}function it({mrakomor:t}){let e=null,n=null,o=W(null),r=null,s=S(false),i=S(false),a=S(0),c=S(0),l=S([]),u=S(-1),f=S("Menu");function p(g){A(()=>{let y=t.getRoot();if(!y||!g)return;let k=o?.offsetHeight??200,C=y.getBoundingClientRect();if(g.top-C.top>k+8){let{x:_,y:v}=We(y,g,{offsetHeight:k},4);a.set(_),c.set(v);}else a.set(g.left-C.left),c.set(g.bottom-C.top+4);s.set(true);});}function h(){i.set(false),r=null,u.set(-1),l.set([]),A(()=>{s.set(false);});}function b(g){!g||!r||r(g);}function R(g){if(i.peek()!==true)return;let y=g.target?.closest?.(".mrakomor-menu__item");if(!y||!n?.contains(y))return;g.preventDefault(),g.stopPropagation();let k=y.getAttribute("data-id"),C=l.peek().find(x=>x.id===k);C&&b(C);}function N(g={}){let{entries:y=[],anchorRect:k,highlightIndex:C=-1,ariaLabel:x="Menu",onSelect:_=null}=g;l.set(y),u.set(C),f.set(x),_!==void 0&&(r=_),i.set(true),k?p(k):s.set(true);}return {registerEvents(){m.OPEN_MENU="mrakomor:open-menu",m.CLOSE_MENU="mrakomor:close-menu",m.UPDATE_MENU="mrakomor:update-menu";},registerCommands(g){g.command.openMenu=y=>{g.emit(m.OPEN_MENU,y);},g.command.updateMenu=y=>{g.emit(m.UPDATE_MENU,y);},g.command.closeMenu=()=>{g.emit(m.CLOSE_MENU);};},registerHandlers(){t.emitter.on(m.OPEN_MENU,N),t.emitter.on(m.UPDATE_MENU,N),t.emitter.on(m.CLOSE_MENU,h),t.emitter.on(m.CLICK,g=>{let y=o?.current??o;i.peek()===true&&s.peek()===true&&y&&typeof y.contains=="function"&&!y.contains(g.target)&&h();}),t.emitter.on(m.KEYDOWN,g=>{g.key==="Escape"&&i.peek()===true&&h();});},onMount(){let{container:g,dispose:y}=nt(t,"mrakomor-menu-plugin-container",E(Ft,{open:i,positionX:a,positionY:c,entries:l,highlightIndex:u,ariaLabel:f,menuRef:o}));n=g,n?.addEventListener("click",R),e=y;},onUnmount(){n?.removeEventListener("click",R),e?.(),e=null,n=null,o.current=null,r=null;}}}function gr(t){return t!=null&&typeof t=="object"&&(typeof Element>"u"?t.nodeType===1:t instanceof Element)}function ao(){return d.object({root:d.any().refine(gr,{message:"root must be a DOM Element"}),id:d.string().optional(),debug:d.boolean().optional(),content:d.array(d.any()).optional(),plugins:d.array(d.function()).optional(),blockComponents:d.array(d.any().refine(t=>typeof t=="function"||t!=null&&typeof t=="object"&&typeof t.component=="function",{message:"blockComponents entry must be a constructor or registration"})).optional(),slashActions:d.array(d.any().refine(t=>t!=null&&typeof t=="object"&&typeof t.handler=="function",{message:"slashActions entry must include a handler function"})).optional(),inlineStyles:d.array(d.function()).optional(),entityRanges:d.array(d.function()).optional(),tooltip:d.any().optional()})}function co(t){return [...t.filter(e=>e!==rt&&e!==it&&e!==tt),rt,it,tt]}function hr(t){ao().parse(t);let e={debug:false,content:[],plugins:[],blockComponents:[],slashActions:[],inlineStyles:[le,ue,pe,fe,me],entityRanges:[],tooltip:{}},n={...e,...t,plugins:co(t.plugins??e.plugins)},o=new at(n);return o._init(),o}var at=class{#e=J();#n;#r=null;#t=[];#o=[];#i;#c=false;listenerAbortController=new AbortController;#a=S([],{debug:"content"});#s=[];command;emitter;register;constructor(e){let{root:n,id:o,content:r}=e;this.#e=o||this.#e,this.#n=n,this.#s=r,this.#o=[],this.#i={...e,plugins:co(e.plugins??[])},this.register={blocks:new qe(this),help:new st(this)};let{emitter:s,command:i}=yn({mrakomor:this});this.command=i,this.emitter=s;}_init(){this.#u(),this.#a=S(this._normalizeContentState(this.#s),{debug:"content"});}#u(){this.#t=this.#i.plugins.map(e=>e?.({config:this.#i,root:this.#n,mrakomor:this}))??[],this.#i=this.#t.reduce((e,n)=>n?.resolveConfig?.(e)??e,this.#i),this.register.blocks.add(this.#i.blockComponents??[]),this.#t.forEach(e=>{e?.registerEvents?.(this);}),this.#t.forEach(e=>{e?.registerCommands?.(this);}),this.#t.forEach(e=>{this.emitter.on(m.KEYDOWN,n=>e?.onKeyDown?.(n));}),this.#t.forEach(e=>{e?.registerHandlers?.(this);}),this.#t.forEach(e=>{e?.registerListeners?.(this);});}emit(e,n={}){return this.emitter.emit(e,{...n,mrakomor:this})}on(e,n){return this.emitter.on(e,n)}onChangeContent(e){return this.on(m.CONTENT_CHANGE,e)}emitDomEvent(e,n){let{clipboardData:o,metaKey:r,altKey:s,code:i,ctrlKey:a,key:c,isComposing:l,repeat:u,button:f,shiftKey:p,which:h,detail:b,isTrusted:R,target:N,relatedTarget:g,data:y,inputType:k,clientX:C,clientY:x}=n??{},{defaultPrevented:_}=this.emit(e,{clipboardData:o,metaKey:r,altKey:s,code:i,ctrlKey:a,key:c,isComposing:l,repeat:u,button:f,shiftKey:p,which:h,detail:b,isTrusted:R,target:N,relatedTarget:g,data:y,inputType:k,clientX:C,clientY:x});return _&&n?.preventDefault?.(),_}getConfig(){return {...this.#i,blockComponents:this.register.blocks.list(),slashActions:this.register.slashActions?.list()??[]}}wrapBlockElement(e){for(let n of this.#t){let o=n.wrapBlockElement?.(e);if(o)return o}return e}getRoot(){return this.#n}_getContentRoot(){return this.#r}_setContentRoot(e){this.#r=e;}get _id(){return this.#e}getContent(){return this.#o.map(n=>D(n)?.getState())}setContent(e=[]){this._setContentState(this._normalizeContentState(e));}_syncBlockElementsFromDom(){let e=this.#r;e&&(this.#o=[...e.querySelectorAll(".mrakomor-block-element")]);}_getBlockElements(){return this.#o}_getContentState(){return this.#a.get()}_setContentState(e=[]){this.#a.set(e),this.emit(m.CONTENT_CHANGE,{content:e}),A(()=>{this._syncBlockElementsFromDom();});}_normalizeContentState(e=[]){return e.map(n=>{let o=this.normalizeComponentState(n);return o===void 0?void 0:structuredClone(o)}).filter(n=>n!==void 0)??[]}_setBlockElement(e,n=this.#o.length){this.#o.splice(n,0,e);}_removeBlockElement(e){this.#o=this.#o.filter(n=>n!==e);}#f(e){return D(e)?.state?.peek()?.componentId}#l(e){return e?this.#o.findIndex(n=>this.#f(n)===e):-1}_getBlockElementIndex(e){if(!e)return -1;let n=this.#o.indexOf(e);return n!==-1?n:this.#l(this.#f(e))}_getBlockElementByComponentId(e){let n=this.#l(e);return n===-1?null:this.#o[n]}_getBlockElementState(e){let n=this._getBlockElementIndex(e);if(n!==-1)return D(this.#o[n])?.getState()}mount(){let e=ee(this.#n,E(ro,{mrakomor:this}));return this.#c=true,e}unmount(){this.#c&&(this.#c=false,hn(this.#n));}_onUnmount(){this.listenerAbortController.abort(),this.#t.forEach(e=>{e?.onUnmount?.(this);}),this.emitter.removeAllListeners();}_onMount(){this.#t.forEach(e=>{e?.onMount?.(this);}),A(()=>{this._syncBlockElementsFromDom();});}resolveComponent(e,n){let o=this.resolveComponentConstructor(e);return o?E(o,{state:n}):E(ye,{state:n})}resolveComponentConstructor(e){let n=this.register.blocks.getByNamespace(e);if(!n){for(let o of this.#t)if(n=o?.resolveComponent?.(e),n)break}return n}normalizeComponentState(e){if(e==null){console.warn("normalizeComponentState() received a nullish state; dropping it.");return}let n="component"in e?e.component:e.entity.type;return this.resolveComponentConstructor(n)?.getStateSchema()?.parse(e)}};exports.Bold=le;exports.Dialog=ot;exports.EVENT=m;exports.Italic=ue;exports.Menu=Ft;exports.Mrakomor=at;exports.Subscript=fe;exports.Superscript=me;exports.Underline=pe;exports.createMrakomor=hr;exports.defaultMrakomorPlugin=tt;exports.dialogPlugin=rt;exports.menuPlugin=it;
4
+ `?"":t??""}function ne({component:t,originComponent:e,properties:n,settings:o}={}){let r=n??{},s=Array.isArray(r.items)?r.items:[{text:r.text??"",inlineStyleRanges:r.inlineStyleRanges??[],entityRanges:r.entityRanges??[]}];return {...t?{component:t}:{},...e?{originComponent:e}:{},properties:{items:s},...o?{settings:o}:{}}}function Wn(t){let e="",n=[],o=[];return (t??[]).forEach((r,s)=>{s>0&&(e+=`
5
+ `);let i=e.length;e+=$(r?.text);for(let c of r?.inlineStyleRanges??[])n.push({...c,offset:c.offset+i});for(let c of r?.entityRanges??[])o.push({...c,offset:c.offset+i});}),{text:e,inlineStyleRanges:n,entityRanges:o}}function Xn(t){return {properties:{text:t?.text??"",inlineStyleRanges:t?.inlineStyleRanges??[],entityRanges:t?.entityRanges??[]}}}function Dt(t,e,n,o){let r=t.toExchangeState(e),s=[...r.properties?.items??[]];if(!s[n])return e;s[n]={...s[n],...o};let i=t.fromExchangeState({...r,properties:{...r.properties,items:s}});return {...e,properties:i?.properties??e.properties,settings:i?.settings??e.settings}}function Pt(t,e,n){let o=t._getBlockElementState(e);if(!o)return null;let r=t.register.blocks.getByNamespace(o.component);if(!r)return null;let s=r.toExchangeState(o)?.properties?.items??[];if(!s.length)return null;let i=I(e),c=Kn(i,n),a=c?.element??i??e,l=c?.index??0,u=s[l];return u?{Constructor:r,current:o,element:a,itemIndex:l,item:u}:null}function Jn({mrakomor:t,resultIndex:e,cursor:n,fallbackBlockElement:o,itemIndex:r}){let s=()=>{if(typeof n!="number")return;let i=t._getBlockElements()[e]??o,c=M(i);if(c?.setCursor){c.setCursor({cursor:n,itemIndex:r});return}let a=I(i);a?.isConnected&&Y(a,n);};s(),R(s);}function oe(t){let e=t?.component??"";return e===It||e.startsWith(Dn)}function $t(t,e){let n=$(t.properties.text),o=$(e.properties.text);return {state:{...t,properties:{...e.properties,...t.properties,text:n+o,inlineStyleRanges:[...t.properties.inlineStyleRanges??[],...(e.properties.inlineStyleRanges??[]).map(r=>({...r,offset:r.offset+n.length}))],entityRanges:[...t.properties.entityRanges??[],...(e.properties.entityRanges??[]).map(r=>({...r,offset:r.offset+n.length}))]},settings:{...e.settings,...t.settings}},cursor:n.length}}function Qn(t,{startIndex:e,endIndex:n,startOffset:o,endOffset:r}){let s=[...t],i=s[e],c=s[n],{originalLineState:a}=Vn(i,o),{newLineState:l}=Vn(c,r),{state:u,cursor:f}=$t(a,l);return s.splice(e,n-e+1,u),{content:s,cursor:f,resultIndex:e}}function qn(t,e){return (t??[]).filter(n=>n.offset<e).map(n=>({...n,length:Math.min(n.length,e-n.offset)}))}function Yn(t,e){return (t??[]).filter(n=>n.offset+n.length>e).map(n=>({...n,offset:Math.max(0,n.offset-e),length:n.offset+n.length-Math.max(n.offset,e)}))}function Vn(t,e){let n=structuredClone(t),o=structuredClone(t);return n.properties.text=t.properties.text.slice(0,e),o.properties.text=t.properties.text.slice(e),n.properties.inlineStyleRanges=qn(t.properties.inlineStyleRanges,e),o.properties.inlineStyleRanges=Yn(t.properties.inlineStyleRanges,e),n.properties.entityRanges=qn(t.properties.entityRanges,e),o.properties.entityRanges=Yn(t.properties.entityRanges,e),o.componentId=J(),{originalLineState:n,newLineState:o}}function Zn(t,e){if(e.key!=="Enter")return false;e.preventDefault();let n=It,o=t.mrakomor.resolveComponentConstructor(n);return t.mrakomor.command.insertBlockElement({range:F(),cursor:0,newLineState:t.mrakomor.normalizeComponentState(o.getStateSchema().parse({})),namespace:n}),true}function eo(t,e){let n=Ee(t,e.startContainer,e.startOffset),o=Ee(t,e.endContainer,e.endOffset);return {offset:n,length:Math.max(0,o-n)}}function Wo(t,{style:e,offset:n,length:o}){let r=t??[],s=n+o,i=r.find(c=>c.style===e&&c.offset<=n&&c.offset+c.length>=s);return i?r.filter(c=>c!==i):[...r,{style:e,offset:n,length:o}]}function Xo(t,e){return t.offset<e.offset+e.length&&e.offset<t.offset+t.length}function Jo(t,e){let n=e.offset+e.length,o=[];for(let r of t){if(!Xo(r,e)){o.push(r);continue}r.offset<e.offset&&o.push({...r,length:e.offset-r.offset});let s=r.offset+r.length;s>n&&o.push({...r,offset:n,length:s-n});}return o}function Qo(t,e){let n=t??[],o=e?.length??0;if(o===0)return null;let r=e.offset??0,s=e.entity?.type,i=n.find(c=>c.offset===r&&c.length===o&&c.entity?.type===s);return i?n.filter(c=>c!==i):[...Jo(n,e),e]}function to(t,e,n,o){if(!e||!n)return null;let{offset:r,length:s}=eo(e,n);return s===0?null:Wo(t??[],{style:o,offset:r,length:s})}function no(t,e,n,{namespace:o,entityData:r}){if(!e||!n)return null;let s={...r,entity:{type:o,...r?.entity},...eo(e,n)};return Qo(t??[],s)}var Xe=class extends We{static get NAMESPACE(){return "namespace.block.BlockComponent"}static get LABEL(){return ""}static get KEYWORDS(){return []}static get GROUP(){return "blocks"}isAtomic(){return false}setCursor({cursor:e}={}){let n=()=>{if(!this.element?.isConnected)return;let o=typeof e=="number"?e:$(this.getState()?.properties?.text).length;Y(this.element,o);};n(),R(n);}onKeydown(e){}static toExchangeState(e){let n=e?.properties,o={text:$(n?.text)};return n?.inlineStyleRanges!==void 0&&(o.inlineStyleRanges=n.inlineStyleRanges),n?.entityRanges!==void 0&&(o.entityRanges=n.entityRanges),ne({originComponent:this.NAMESPACE,properties:{items:[o]},settings:e?.settings})}static fromExchangeState(e){let n=e?.properties?.items?.[0];return {properties:{text:n?.text??"",inlineStyleRanges:n?.inlineStyleRanges??[],entityRanges:n?.entityRanges??[]},settings:e?.settings}}static appendExchangeState(e,n){let o=Wn(n?.properties?.items);return $t(e,Xn(o))}};var re=class t extends Xe{static get NAMESPACE(){return Tn}static getStateSchema(e){return g.object({component:g.string().default(t.NAMESPACE),componentId:g.string().default(e?.getAttribute("data-componentid")||J()),properties:g.object({}).default({}),settings:g.object({}).default({})}).default({})}constructor(e){super(e),this.root=null;}getState(){return this.state.peek()}isAtomic(){return true}static appendExchangeState(){return null}onMount(){}onUnmount(){}render(){let e=this.constructor.NAMESPACE.toLowerCase().replaceAll(".","-");return h("div",{className:e,contentEditable:false,style:"position: relative;",$ref:o=>{this.element=o;},"data-state":()=>JSON.stringify(this.state.get()),"data-componentid":this.state.peek().componentId},[h("div",{$ref:o=>{this.root=o;},style:"display: block;",contentEditable:false}),h("span",{style:"position: absolute; bottom: 0; right: 0; width: 10px; height: 100%; outline: none;",contentEditable:true,[he]:true},document.createTextNode("\xA0"))])}onKeydown(e){e.key!=="Backspace"&&e.key!=="ArrowUp"&&e.key!=="ArrowDown"&&e.preventDefault(),Zn(this,e);}};var ye=class extends re{static get NAMESPACE(){return On}onMount(){let e=h("div",{style:"user-select: none;",contentEditable:false},()=>`Unknown component: ${this.state.get().component}`);Z(this.root,e);}onUnmount(){this.root.innerHTML="";}};function Zo(t,e){let n=t._getBlockElementByComponentId(e);return M(n)?.isStale?.()??false}function oo(t){return (e,n)=>{if(!ie(e,n))return false;let o=n?.componentId??e?.componentId;return !(o&&Zo(t,o))}}function ro({mrakomor:t}){let e=t.get(),n=oo(e);dt(Ve,e);let o=W(r=>{e._setContentRoot(r??null);});return Pe(()=>{e._onMount();}),$e(()=>{e._onUnmount();}),h("div",{id:e._id,className:"mrakomor-editor"},[h("div",{className:"mrakomor-editor-surface"},[h("div",{className:"mrakomor-tools-container"}),h("div",{className:"mrakomor-content",contentEditable:true,style:{spellcheck:true,outline:"none"},$ref:o},[Et(()=>e._getContentState(),r=>r.componentId,(r,s)=>h(()=>{let i;Pe(()=>{i.getNodeComponent=()=>{let l=I(i);return l?se(l):null},e._setBlockElement(i,s);}),$e(()=>{e._removeBlockElement(i);});let c=e.resolveComponent(r.get().component,r),a=e.wrapBlockElement(c);return h("div",{className:"mrakomor-block-element",[Ie]:true,$ref:l=>{i=l;}},a)}),{equals:n})])])])}function Je(t,e,n){let o=t._getBlockElementIndex(e);if(o===-1)return false;let r=t.getContent();return r.splice(o,1,t.normalizeComponentState(n)),t._setContentState(r),true}function er(t){let{mrakomor:e}=t,{blockElement:n,range:o,newLineState:r,originalLineState:s,namespace:i,position:c,cursor:a}=t,l,u;if(c||(n?l=e._getBlockElementIndex(n):o&&(l=e._getBlockElementIndex(K(o))),l===void 0||l===-1))return;u=l+1;let f=e.getContent();s&&f.splice(l,1,e.normalizeComponentState(s)),r&&(r.component=i,f.splice(u,0,e.normalizeComponentState(r))),e._setContentState(f),R(()=>{typeof a=="number"&&M(e._getBlockElements()[u])?.setCursor?.({cursor:a});});}function tr(t){let{mrakomor:e}=t,{blockElement:n,range:o,blocks:r,cursor:s,cursorBlockIndex:i=0}=t;if(!Array.isArray(r)||r.length===0)return;let c=n??(o?K(o):null),a=e._getBlockElementIndex(c);if(a===-1)return;let l=[...e._getContentState()];l.splice(a,1,...r.map(u=>e.normalizeComponentState(u))),e._setContentState(l),R(()=>{if(typeof s!="number")return;e._syncBlockElementsFromDom();let u=I(e._getBlockElements()[a+i]);u?.isConnected&&Y(u,s);});}function nr(t){let{mrakomor:e,blockElement:n,namespace:o}=t,r=e._getBlockElementState(n);if(!r)return;let s=e.register.blocks.getByNamespace(r.component),i=e.register.blocks.getByNamespace(o),c=(t.exchangeState&&ne(t.exchangeState))??s?.toExchangeState?.(r)??ne({properties:r.properties,settings:r.settings}),a=i?.fromExchangeState?.(c)??c;Je(e,n,{...a,component:o,componentId:J()});}function or(t){let{mrakomor:e,blockElement:n,targetIndex:o}=t,r=e._getBlockElementIndex(n);if(r===-1||typeof o!="number")return;let s=o>r?o-1:o;if(s===r)return;let i=[...e._getContentState()],[c]=i.splice(r,1);i.splice(s,0,c),e._setContentState(i);}function rr(t){let{mrakomor:e,blockElement:n,range:o}=t,r=e._getBlockElementIndex(n);if(r!==-1){let s=e.getContent();s.splice(r,1),e._setContentState(s);}R(()=>{let s=K(o);Y(I(s),0);});}function sr(t){let{mrakomor:e,state:n,blockElement:o}=t,r=e._getBlockElementState(o);if(!r)return;let s=structuredClone(r),i=n?.offset,c=n?.length,a=n?.entity?.type;s.properties.entityRanges=(s.properties.entityRanges??[]).filter(l=>!(l?.offset===i&&l?.length===c&&l?.entity?.type===a)),Je(e,o,s),e.command.closeDialog?.();}function ir(t){let{mrakomor:e,namespace:n,state:o}=t,r=t.range??F(),s=t.blockElement??K(r),i=Pt(e,s,r);if(!i||i.item.entityRanges===void 0)return;let{Constructor:c,current:a,element:l,itemIndex:u,item:f}=i,m=no(f.entityRanges,l,r,{namespace:n,entityData:o});if(m===null)return;let d=Dt(c,a,u,{entityRanges:m});Je(e,s,d);}function cr(t){let{mrakomor:e,style:n}=t,o=t.range??F(),r=t.blockElement??K(o),s=Pt(e,r,o);if(!s||s.item.inlineStyleRanges===void 0)return;let{Constructor:i,current:c,element:a,itemIndex:l,item:u}=s,f=to(u.inlineStyleRanges,a,o,n);if(f===null)return;let m=Dt(i,c,l,{inlineStyleRanges:f});Je(e,r,m);}function ar(t){let{mrakomor:e,blockElement:n,previousBlockElement:o}=t,r=e._getBlockElementIndex(o),s=e._getBlockElementIndex(n);if(r===-1||s===-1)return;let i=e.getContent(),c=i[s],a=i[r],l=e.register.blocks.getByNamespace(a.component),u=e.register.blocks.getByNamespace(c.component),f=(t.exchangeState&&ne(t.exchangeState))??u?.toExchangeState?.(c)??ne({properties:c.properties,settings:c.settings}),m=l?.appendExchangeState?.(a,f);m&&(i.splice(s,1),i.splice(r,1,e.normalizeComponentState(m.state)),e._setContentState(i),Jn({mrakomor:e,resultIndex:r,cursor:m.cursor,fallbackBlockElement:o,itemIndex:m.itemIndex}));}function lr(t){let{mrakomor:e}=t,n=e.getRoot(),o=t.relatedTarget instanceof Node&&n.contains(t.relatedTarget),r=n?.contains(document.activeElement)??false;if(o||r)return;let[i,c]=G(()=>[e.getContent(),e._getContentState()]);i.length===c.length&&i.every((l,u)=>l===c[u])||e.setContent(i);}function ur(t){let{mrakomor:e,clientX:n,clientY:o}=t;if(typeof o!="number")return;let r=e._getContentRoot(),s=e._getBlockElements(),i=s[0],c=s[s.length-1];if(!r||!i||!c)return;let a=o<i.getBoundingClientRect().top,l=o>c.getBoundingClientRect().bottom;if(!a&&!l)return;if(typeof n=="number"){let f=r.getBoundingClientRect();if(n<f.left||n>f.right)return}let u=I(a?i:c);u?.isConnected&&Y(u,a?0:u.textContent.length);}function fr(t){let e=F();return K(e)?.getNodeComponent?.()?.classInstance?.onKeydown?.(t)}function mr(t){M(t)?.setCursor?.();}function pr(t,e){if(!e)return true;let n=t.cloneRange();return n.setEnd(e,e.childNodes.length),!$(n.toString())}function so(t,e){let{mrakomor:n}=t,o=Hn(e);if(!o||o.startBlock===o.endBlock)return;let r=n._getBlockElementIndex(o.startBlock),s=n._getBlockElementIndex(o.endBlock),i=n.getContent(),c=r>=0?i[r]:void 0,a=s>=0?i[s]:void 0;if(!(r>=0&&s>r&&typeof c?.properties?.text=="string"&&typeof a?.properties?.text=="string"))return;t.preventDefault();let{content:u,cursor:f,resultIndex:m}=Qn(i,{startIndex:r,endIndex:s,startOffset:o.startOffset,endOffset:o.endOffset});n._setContentState(u.map(d=>n.normalizeComponentState(d))),R(()=>{let d=n._getBlockElements()[m];d&&typeof f=="number"&&Y(I(d),f);});}function dr(t){if(t.key!=="Backspace")return;let{mrakomor:e}=t,n=F();if(!n)return;let o=K(n);if(!o)return;if(!n.collapsed){so(t,n);return}let r=o?.previousSibling,s=Ot(r),i=Ot(o),c=I(o),a=!$(c?.textContent);if(!(n.startOffset===0||Tt()===0||a))return;let u=e._getBlockElementIndex(o),f=r?e._getBlockElementIndex(r):-1,m=e._getBlockElementState(o),d=e._getBlockElementState(r),x=r?M(r):null;if(!r||f<0){t.preventDefault();return}if(d&&m&&oe(m)&&x&&!x.isAtomic?.()){if(a&&!oe(d)){t.preventDefault();let C=e.getContent();C.splice(u,1),e._setContentState(C),mr(r);return}t.preventDefault(),e.command.mergeBlockElement({blockElement:o,previousBlockElement:r,range:n});return}x?.isAtomic?.()&&(!s&&n.startOffset===0||o?.textContent==="\xA0"&&!i)&&(t.preventDefault(),e.command.removeBlockElement({blockElement:r,range:n})),m&&!oe(m)&&t.preventDefault();}function gr(t){if(t.key!=="Delete")return;let{mrakomor:e}=t,n=F();if(!n)return;let o=K(n);if(!o)return;if(!n.collapsed){so(t,n);return}let r=I(o);if(!(!$(r?.textContent)||pr(n,r)))return;let c=e._getBlockElementIndex(o),a=o?.nextSibling,l=a?e._getBlockElementIndex(a):-1,u=e._getBlockElementState(o),f=e._getBlockElementState(a),m=M(o),d=a?M(a):null;if(!a||l<0){t.preventDefault();return}if(f&&u&&oe(f)&&m&&!m.isAtomic?.()){let x=I(a);if(!$(x?.textContent)&&!oe(u)){t.preventDefault();let _=e.getContent();_.splice(c+1,1),e._setContentState(_);return}t.preventDefault(),e.command.mergeBlockElement({blockElement:a,previousBlockElement:o,range:n});return}if(d?.isAtomic?.()){t.preventDefault(),e.command.removeBlockElement({blockElement:a,range:n});return}if(u&&!oe(u)){t.preventDefault();return}t.preventDefault();}function Qe(t){return {resolveComponent:e=>e===re.NAMESPACE?re:ye,registerCommands(e){e.emitter.on(p.INSERT_BLOCK_ELEMENT,B(er)),e.emitter.on(p.REPLACE_BLOCK_ELEMENT,B(tr)),e.emitter.on(p.TRANSFORM_BLOCK_ELEMENT,B(nr)),e.emitter.on(p.MOVE_BLOCK_ELEMENT,B(or)),e.emitter.on(p.REMOVE_BLOCK_ELEMENT,B(rr)),e.emitter.on(p.REMOVE_ENTITY_RANGE,B(sr)),e.emitter.on(p.INSERT_ENTITY_RANGE,B(ir)),e.emitter.on(p.INSERT_INLINE_STYLE_RANGE,B(cr)),e.emitter.on(p.MERGE_BLOCK_ELEMENT,B(ar));},registerHandlers(e){e.emitter.on(p.FOCUSOUT,lr),e.emitter.on(p.KEYDOWN,B(fr)),e.emitter.on(p.KEYDOWN,B(dr)),e.emitter.on(p.KEYDOWN,B(gr)),e.emitter.on(p.CLICK,B(ur));},registerListeners(e){let n=e.getRoot(),{signal:o}=e.listenerAbortController;n.addEventListener("keydown",r=>e.emitDomEvent(p.KEYDOWN,r),{signal:o}),n.addEventListener("beforeinput",r=>e.emitDomEvent(p.BEFORE_INPUT,r),{signal:o}),n.addEventListener("input",r=>e.emitDomEvent(p.INPUT,r),{signal:o}),n.addEventListener("focusin",r=>e.emitDomEvent(p.FOCUSIN,r),{signal:o}),n.addEventListener("focusout",r=>e.emitDomEvent(p.FOCUSOUT,r),{signal:o}),n.addEventListener("click",r=>e.emitDomEvent(p.CLICK,r),{signal:o}),document.addEventListener("selectionchange",r=>e.emitDomEvent(p.SELECTION_CHANGE,r),{signal:o});}}}(function(){if(!(typeof document>"u")){var t="mrakomor/core/plugin/dialog/Dialog.css",e=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(o){return o.getAttribute("data-mrakomor-css-path")===t});if(!e){var n=document.createElement("style");n.setAttribute("data-mrakomor-css",""),n.setAttribute("data-mrakomor-css-path",t),n.textContent=`.mrakomor-dialog-container,.mrakomor-dialog-backdrop{pointer-events:all}.dialog[open]{background-color:#fff;border:1px solid black;border-radius:8px;box-shadow:0 0 5px #0000001a;padding:12px;display:flex;flex-flow:row wrap;justify-content:space-between}.dialog[open] .dialog-controls{text-align:right;width:100%}.dialog[open] .dialog-button-close{background-color:#f0f0f0;border:1px solid black;border-radius:4px;color:#000;cursor:pointer;display:inline-block;font-size:14px;margin-right:1px;padding:4px 8px;text-align:center}.dialog[open] .dialog-container{width:100%}
6
+ `,document.head.appendChild(n);}}})();function hr(t,e,n,o){let r=t.getRoot()?.querySelector(e);if(!r)return {container:null,dispose:null};let s=document.createElement("div");s.className=n,r.append(s);let i=Z(s,o);return {container:s,dispose:i??null}}function Ze(t,e,n){return hr(t,".mrakomor-tools-container",e,n)}var io="mrakomor.dialog.Dialog";function et({open:t,placement:e,positionX:n,positionY:o,block:r,dialogRef:s}){let i=L(()=>{let a=e.get()==="center";return {position:"absolute",zIndex:a?"9100":"9000",top:`${o.get()}px`,left:`${n.get()}px`,...a?{padding:0,background:"transparent",border:"none",boxShadow:"none",minWidth:0}:{background:"#fff",border:"1px solid #ccc",borderRadius:"4px",padding:"8px 10px",boxShadow:"0 2px 8px rgba(0,0,0,.15)",minWidth:"220px"}}}),c=L(()=>({position:"absolute",inset:"0",zIndex:"9050",background:"rgba(15, 23, 42, 0.28)",pointerEvents:"all"}));return h("span",{style:{display:"contents"}},[Re(()=>t.get()&&e.get()==="center",h("div",{className:"mrakomor-dialog-backdrop",contentEditable:false,style:c})),Re(()=>t.get(),h("div",{className:"mrakomor-dialog-container",contenteditable:false,style:i,$ref:s},()=>r.get()))])}et.NAMESPACE=io;function tt({mrakomor:t}){let e=null,n=S(false),o=S(false),r=S("anchor"),s=S(0),i=S(0),c=S(null),a=W(null),l=W(null);function u(){o.set(false),r.set("anchor"),a.set(null),R(()=>{n.set(false);});}return {resolveComponent(f){if(f===io)return et},registerEvents(){p.OPEN_DIALOG="mrakomor:open-dialog",p.CLOSE_DIALOG="mrakomor:close-dialog";},registerCommands(f){f.command.openDialog=(m,d)=>{f.emit(p.OPEN_DIALOG,{...m,options:d});},f.command.closeDialog=()=>{f.emit(p.CLOSE_DIALOG);};},registerHandlers(){t.emitter.on(p.OPEN_DIALOG,({children:f,element:m,options:d={}})=>{c.set(f??h("div",{},"Empty dialog")),o.set(true),a.set(m??null),r.set(d.placement??"anchor"),R(()=>{let x=t.getRoot(),{x:C,y:_}=d.placement==="center"?Gn(x,l):Ye(x,m??{left:0,top:0},l);s.set(C),i.set(_),n.set(true);});}),t.emitter.on(p.CLOSE_DIALOG,u),t.emitter.on(p.KEYDOWN,f=>{f.key==="Escape"&&o.peek()===true&&t.command.closeDialog();}),t.emitter.on(p.CLICK,f=>{if(o.peek()!==true||n.peek()!==true)return;let m=f.target,d=l&&typeof l.contains=="function"&&l.contains(m),x=a&&typeof a.contains=="function"&&a.contains(m);!d&&!x&&t.command.closeDialog();});},onMount(){let{dispose:f}=Ze(t,"mrakomor-dialog-plugin-container",h(et,{open:o,placement:r,positionX:s,positionY:i,block:c,dialogRef:l}));e=f;},onUnmount(){e?.(),e=null;}}}function Er(){return g.object({id:g.string(),group:g.string().default("general"),description:g.string().default(""),commands:g.array(g.string()).default([]),shortcuts:g.array(g.string()).default([])}).default({})}function co(t){try{return Er().parse(t)}catch{return null}}var nt=class extends de{constructor(e){super(e,{sort:n=>n});}normalize(e){return co(e)}};(function(){if(!(typeof document>"u")){var t="mrakomor/core/plugin/menu/Menu.css",e=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(o){return o.getAttribute("data-mrakomor-css-path")===t});if(!e){var n=document.createElement("style");n.setAttribute("data-mrakomor-css",""),n.setAttribute("data-mrakomor-css-path",t),n.textContent=`.mrakomor-menu{position:absolute;z-index:9300;display:flex;flex-direction:column;gap:2px;min-width:160px;max-height:240px;overflow-y:auto;background:#1a1a1a;border-radius:6px;padding:4px;box-shadow:0 3px 10px #00000040;pointer-events:all}.mrakomor-menu__item{display:flex;align-items:center;width:100%;padding:6px 10px;border:none;border-radius:4px;background:transparent;color:#fff;cursor:pointer;font-size:13px;font-weight:600;text-align:left;transition:background .1s}.mrakomor-menu__item:hover,.mrakomor-menu__item--active{background:#ffffff26}.mrakomor-menu__empty{padding:6px 10px;font-size:13px;font-weight:600;color:#ffffff80}
7
+ `,document.head.appendChild(n);}}})();function yr(t,e=-1){if(!t.length)return h("div",{className:"mrakomor-menu__empty",role:"presentation"},"No results");let n=t.map((o,r)=>h("button",{type:"button",role:"option",id:`mrakomor-menu-option-${o.id}`,className:["mrakomor-menu__item",r===e?"mrakomor-menu__item--active":""].filter(Boolean).join(" "),title:o.label,"data-id":o.id,"aria-selected":r===e?"true":"false",onMouseDown:s=>{s.preventDefault();}},o.label));return h("span",{style:"display: contents"},n)}function jt({open:t,positionX:e,positionY:n,entries:o,highlightIndex:r,ariaLabel:s,menuRef:i}){let c=L(()=>({left:`${e.get()}px`,top:`${n.get()}px`}));return Re(()=>t.get(),h("div",{className:"mrakomor-menu",role:"listbox","aria-label":()=>s.get(),contenteditable:false,style:c,$ref:i},()=>yr(o.get(),r.get())))}function ot({mrakomor:t}){let e=null,n=null,o=W(null),r=null,s=S(false),i=S(false),c=S(0),a=S(0),l=S([]),u=S(-1),f=S("Menu");function m(E){R(()=>{let b=t.getRoot();if(!b||!E)return;let A=o?.offsetHeight??200,N=b.getBoundingClientRect();if(E.top-N.top>A+8){let{x:k,y:w}=Ye(b,E,{offsetHeight:A},4);c.set(k),a.set(w);}else c.set(E.left-N.left),a.set(E.bottom-N.top+4);s.set(true);});}function d(){i.set(false),r=null,u.set(-1),l.set([]),R(()=>{s.set(false);});}function x(E){!E||!r||r(E);}function C(E){if(i.peek()!==true)return;let b=E.target?.closest?.(".mrakomor-menu__item");if(!b||!n?.contains(b))return;E.preventDefault(),E.stopPropagation();let A=b.getAttribute("data-id"),N=l.peek().find(y=>y.id===A);N&&x(N);}function _(E={}){let{entries:b=[],anchorRect:A,highlightIndex:N=-1,ariaLabel:y="Menu",onSelect:k=null}=E;l.set(b),u.set(N),f.set(y),k!==void 0&&(r=k),i.set(true),A?m(A):s.set(true);}return {registerEvents(){p.OPEN_MENU="mrakomor:open-menu",p.CLOSE_MENU="mrakomor:close-menu",p.UPDATE_MENU="mrakomor:update-menu";},registerCommands(E){E.command.openMenu=b=>{E.emit(p.OPEN_MENU,b);},E.command.updateMenu=b=>{E.emit(p.UPDATE_MENU,b);},E.command.closeMenu=()=>{E.emit(p.CLOSE_MENU);};},registerHandlers(){t.emitter.on(p.OPEN_MENU,_),t.emitter.on(p.UPDATE_MENU,_),t.emitter.on(p.CLOSE_MENU,d),t.emitter.on(p.CLICK,E=>{let b=o?.current??o;i.peek()===true&&s.peek()===true&&b&&typeof b.contains=="function"&&!b.contains(E.target)&&d();}),t.emitter.on(p.KEYDOWN,E=>{E.key==="Escape"&&i.peek()===true&&d();});},onMount(){let{container:E,dispose:b}=Ze(t,"mrakomor-menu-plugin-container",h(jt,{open:i,positionX:c,positionY:a,entries:l,highlightIndex:u,ariaLabel:f,menuRef:o}));n=E,n?.addEventListener("click",C),e=b;},onUnmount(){n?.removeEventListener("click",C),e?.(),e=null,n=null,o.current=null,r=null;}}}function xr(t){return t!=null&&typeof t=="object"&&(typeof Element>"u"?t.nodeType===1:t instanceof Element)}function ao(){return g.object({root:g.any().refine(xr,{message:"root must be a DOM Element"}),id:g.string().optional(),debug:g.boolean().optional(),content:g.array(g.any()).optional(),plugins:g.array(g.function()).optional(),blockComponents:g.array(g.any().refine(t=>typeof t=="function"||t!=null&&typeof t=="object"&&typeof t.component=="function",{message:"blockComponents entry must be a constructor or registration"})).optional(),slashActions:g.array(g.any().refine(t=>t!=null&&typeof t=="object"&&typeof t.handler=="function",{message:"slashActions entry must include a handler function"})).optional(),inlineStyles:g.array(g.function()).optional(),entityRanges:g.array(g.function()).optional(),tooltip:g.any().optional()})}function lo(t){return [...t.filter(e=>e!==tt&&e!==ot&&e!==Qe),tt,ot,Qe]}function br(t){ao().parse(t);let e={debug:false,content:[],plugins:[],blockComponents:[],slashActions:[],inlineStyles:[le,ue,pe,fe,me],entityRanges:[],tooltip:{}},n={...e,...t,plugins:lo(t.plugins??e.plugins)},o=new rt(n);return o._init(),o}var rt=class{#e=J();#n;#r=null;#t=[];#o=[];#i;#a=false;listenerAbortController=new AbortController;#c=S([],{debug:"content"});#s=[];command;emitter;register;constructor(e){let{root:n,id:o,content:r}=e;this.#e=o||this.#e,this.#n=n,this.#s=r,this.#o=[],this.#i={...e,plugins:lo(e.plugins??[])},this.register={blocks:new Ge(this),help:new nt(this)};let{emitter:s,command:i}=En({mrakomor:this});this.command=i,this.emitter=s;}_init(){this.#u(),this.#c=S(this._normalizeContentState(this.#s),{debug:"content"});}#u(){this.#t=this.#i.plugins.map(e=>e?.({config:this.#i,root:this.#n,mrakomor:this}))??[],this.#i=this.#t.reduce((e,n)=>n?.resolveConfig?.(e)??e,this.#i),this.register.blocks.add(this.#i.blockComponents??[]),this.#t.forEach(e=>{e?.registerEvents?.(this);}),this.#t.forEach(e=>{e?.registerCommands?.(this);}),this.#t.forEach(e=>{this.emitter.on(p.KEYDOWN,n=>e?.onKeyDown?.(n));}),this.#t.forEach(e=>{e?.registerHandlers?.(this);}),this.#t.forEach(e=>{e?.registerListeners?.(this);});}emit(e,n={}){return this.emitter.emit(e,{...n,mrakomor:this})}on(e,n){return this.emitter.on(e,n)}onChangeContent(e){return this.on(p.CONTENT_CHANGE,e)}emitDomEvent(e,n){let{clipboardData:o,metaKey:r,altKey:s,code:i,ctrlKey:c,key:a,isComposing:l,repeat:u,button:f,shiftKey:m,which:d,detail:x,isTrusted:C,target:_,relatedTarget:E,data:b,inputType:A,clientX:N,clientY:y}=n??{},{defaultPrevented:k}=this.emit(e,{clipboardData:o,metaKey:r,altKey:s,code:i,ctrlKey:c,key:a,isComposing:l,repeat:u,button:f,shiftKey:m,which:d,detail:x,isTrusted:C,target:_,relatedTarget:E,data:b,inputType:A,clientX:N,clientY:y});return k&&n?.preventDefault?.(),k}getConfig(){return {...this.#i,blockComponents:this.register.blocks.list(),slashActions:this.register.slashActions?.list()??[]}}wrapBlockElement(e){for(let n of this.#t){let o=n.wrapBlockElement?.(e);if(o)return o}return e}getRoot(){return this.#n}_getContentRoot(){return this.#r}_setContentRoot(e){this.#r=e;}get _id(){return this.#e}getContent(){return this.#o.map(n=>M(n)?.getState())}setContent(e=[]){this._setContentState(this._normalizeContentState(e));}_syncBlockElementsFromDom(){let e=this.#r;e&&(this.#o=[...e.querySelectorAll(".mrakomor-block-element")]);}_getBlockElements(){return this.#o}_getContentState(){return this.#c.get()}_setContentState(e=[]){this.#c.set(e),this.emit(p.CONTENT_CHANGE,{content:e}),R(()=>{this._syncBlockElementsFromDom();});}_normalizeContentState(e=[]){return e.map(n=>{let o=this.normalizeComponentState(n);return o===void 0?void 0:structuredClone(o)}).filter(n=>n!==void 0)??[]}_setBlockElement(e,n=this.#o.length){this.#o.splice(n,0,e);}_removeBlockElement(e){this.#o=this.#o.filter(n=>n!==e);}#f(e){return M(e)?.state?.peek()?.componentId}#l(e){return e?this.#o.findIndex(n=>this.#f(n)===e):-1}_getBlockElementIndex(e){if(!e)return -1;let n=this.#o.indexOf(e);return n!==-1?n:this.#l(this.#f(e))}_getBlockElementByComponentId(e){let n=this.#l(e);return n===-1?null:this.#o[n]}_getBlockElementState(e){let n=this._getBlockElementIndex(e);if(n!==-1)return M(this.#o[n])?.getState()}mount(){let e=Z(this.#n,h(ro,{mrakomor:this}));return this.#a=true,e}unmount(){this.#a&&(this.#a=false,gn(this.#n));}_onUnmount(){this.listenerAbortController.abort(),this.#t.forEach(e=>{e?.onUnmount?.(this);}),this.emitter.removeAllListeners();}_onMount(){this.#t.forEach(e=>{e?.onMount?.(this);}),R(()=>{this._syncBlockElementsFromDom();});}resolveComponent(e,n){let o=this.resolveComponentConstructor(e);return o?h(o,{state:n}):h(ye,{state:n})}resolveComponentConstructor(e){let n=this.register.blocks.getByNamespace(e);if(!n){for(let o of this.#t)if(n=o?.resolveComponent?.(e),n)break}return n}normalizeComponentState(e){if(e==null){console.warn("normalizeComponentState() received a nullish state; dropping it.");return}let n="component"in e?e.component:e.entity.type;return this.resolveComponentConstructor(n)?.getStateSchema()?.parse(e)}};exports.Bold=le;exports.Dialog=et;exports.EVENT=p;exports.Italic=ue;exports.Menu=jt;exports.Mrakomor=rt;exports.Subscript=fe;exports.Superscript=me;exports.Underline=pe;exports.createMrakomor=br;exports.defaultMrakomorPlugin=Qe;exports.dialogPlugin=tt;exports.menuPlugin=ot;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import {a as a$5,c as c$3}from'./chunk-EXDY5TZH.mjs';import {a as a$4,c as c$2}from'./chunk-S2W6LYHT.mjs';export{c as defaultMrakomorPlugin}from'./chunk-S2W6LYHT.mjs';import'./chunk-GDDVUIEH.mjs';import {a as a$6}from'./chunk-ZHOZPQZH.mjs';import {a}from'./chunk-P7IKAZYZ.mjs';import {a as a$1}from'./chunk-ERNLRJPB.mjs';import'./chunk-FAXIFXQK.mjs';import {a as a$2,c as c$1}from'./chunk-B6JJAATK.mjs';export{a as EVENT}from'./chunk-B6JJAATK.mjs';import {y,x,a as a$3,v,o as o$1,u as u$1,b}from'./chunk-P7TUN2KD.mjs';import {p,c,u,e,g,o,s,t,q as q$1,k,m,n,r,h,i}from'./chunk-7CJLTNHZ.mjs';(function(){if(!(typeof document>"u")){var o="mrakomor/core/style/core.css",t=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(n){return n.getAttribute("data-mrakomor-css-path")===o});if(!t){var e=document.createElement("style");e.setAttribute("data-mrakomor-css",""),e.setAttribute("data-mrakomor-css-path",o),e.textContent=`.namespace-unknown-unknowncomponent{background-color:#f0f0f0;padding:12px 0;margin-bottom:8px}.mrakomor-editor:focus-visible{outline:none}.mrakomor-editor{display:flex;flex-direction:column;height:100%;min-height:0}.mrakomor-editor-surface{position:relative;flex:1 1 auto;min-height:0}.mrakomor-tools-container{position:absolute;inset:0;pointer-events:none;z-index:4}.mrakomor-content{position:relative;height:100%;min-height:0;overflow-y:auto}.mrakomor-content:focus-visible{outline:none}
1
+ import {a as a$5,c as c$3}from'./chunk-EXDY5TZH.mjs';import {a as a$4,c as c$2}from'./chunk-5AD5MQXI.mjs';export{c as defaultMrakomorPlugin}from'./chunk-5AD5MQXI.mjs';import'./chunk-SG5PCGIV.mjs';import {a as a$6}from'./chunk-ZHOZPQZH.mjs';import {a}from'./chunk-P7IKAZYZ.mjs';import {a as a$1}from'./chunk-ERNLRJPB.mjs';import'./chunk-D6K2L5O3.mjs';import {a as a$2,c as c$1}from'./chunk-B6JJAATK.mjs';export{a as EVENT}from'./chunk-B6JJAATK.mjs';import {y,x,a as a$3,v,o as o$1,u as u$1,b}from'./chunk-4WTPDNPA.mjs';import {p,c,u,e,g,o,s,t,q as q$1,k,m,n,r,h,i}from'./chunk-7CJLTNHZ.mjs';(function(){if(!(typeof document>"u")){var o="mrakomor/core/style/core.css",t=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(n){return n.getAttribute("data-mrakomor-css-path")===o});if(!t){var e=document.createElement("style");e.setAttribute("data-mrakomor-css",""),e.setAttribute("data-mrakomor-css-path",o),e.textContent=`.namespace-unknown-unknowncomponent{background-color:#f0f0f0;padding:12px 0;margin-bottom:8px}.mrakomor-editor:focus-visible{outline:none}.mrakomor-editor{display:flex;flex-direction:column;height:100%;min-height:0}.mrakomor-editor-surface{position:relative;flex:1 1 auto;min-height:0}.mrakomor-tools-container{position:absolute;inset:0;pointer-events:none;z-index:4}.mrakomor-content{position:relative;height:100%;min-height:0;overflow-y:auto}.mrakomor-content:focus-visible{outline:none}
2
2
  `,document.head.appendChild(e);}}})();var E=class extends q$1{static get nodeName(){return "span"}static get style(){return "SPAN"}static match(t){return t.nodeName===this.nodeName.toUpperCase()||t.style===this.style}getState(){return {style:this.constructor.style}}render(){return p(this.constructor.nodeName,{},this.props.children)}};var B=class extends E{static get nodeName(){return "b"}static get style(){return "BOLD"}static get LABEL(){return p("b",{},"B")}static match(t){return t.nodeName==="strong"?true:super.match(t)}};var w=class extends E{static get nodeName(){return "i"}static get style(){return "ITALIC"}static get LABEL(){return p("i",{},"I")}};var L=class extends E{static get nodeName(){return "sub"}static get style(){return "SUBSCRIPT"}static get LABEL(){return p("sub",{},"Sub")}};var R=class extends E{static get nodeName(){return "sup"}static get style(){return "SUPERSCRIPT"}static get LABEL(){return p("sup",{},"Sup")}};var O=class extends E{static get nodeName(){return "u"}static get style(){return "UNDERLINE"}static get LABEL(){return p("u",{},"U")}};var xt=a.object({component:a.function(),id:a.string(),label:a.string(),keywords:a.array(a.string()),group:a.string(),order:a.number().default(({context:o})=>o?.index??0),settings:a.any().optional()});function yt(o,t){let e=`block:${o}`;return t?.style==="UNORDERED"?`${e}:ul`:t?.style==="ORDERED"?`${e}:ol`:e}function dt(o,t=0){let e=typeof o=="function",n=e?o:o?.component,r=e?{}:o,c=n.NAMESPACE??"",l=c.split(".").pop()||c,h=r.label||n.LABEL||l||c,d=Array.isArray(n.KEYWORDS)?n.KEYWORDS:[],p=r.keywords?.length?r.keywords.map(String):d.length?d.map(String):[h,l].filter(Boolean).map(String),b=r.settings;return xt.parse({component:n,id:r.id||yt(c,b),label:String(h),keywords:p,group:String(r.group||n.GROUP||"blocks"),...typeof r.order=="number"?{order:r.order}:{},...b?{settings:b}:{}},{context:{index:t}})}var G=class o extends a$5{#o=null;constructor(t){super(t),this.subscribe(()=>{this.#o=null;});}normalize(t,e){if(t==null)return null;try{return dt(t,e)}catch{return null}}getByNamespace(t){return this.#n().get(t)}#n(){return this.#o??=o.buildNamespaceMap(this.list()),this.#o}static buildNamespaceMap(t){let e=new Map;for(let n of t){let r=n.component?.NAMESPACE;r&&!e.has(r)&&e.set(r,n.component);}return e}};function Ct(o,t){let e=o._getBlockElementByComponentId(t);return v(e)?.isStale?.()??false}function ft(o){return (t,e)=>{if(!i(t,e))return false;let n=e?.componentId??t?.componentId;return !(n&&Ct(o,n))}}function gt({mrakomor:o}){let t=o.get(),e=ft(t);k(a$6,t);let n$1=g(r=>{t._setContentRoot(r??null);});return m(()=>{t._onMount();}),n(()=>{t._onUnmount();}),p("div",{id:t._id,className:"mrakomor-editor"},[p("div",{className:"mrakomor-editor-surface"},[p("div",{className:"mrakomor-tools-container"}),p("div",{className:"mrakomor-content",contentEditable:true,style:{spellcheck:true,outline:"none"},$ref:n$1},[r(()=>t._getContentState(),r=>r.componentId,(r,c)=>p(()=>{let l;m(()=>{l.getNodeComponent=()=>{let p=u$1(l);return p?h(p):null},t._setBlockElement(l,c);}),n(()=>{t._removeBlockElement(l);});let h$1=t.resolveComponent(r.get().component,r),d=t.wrapBlockElement(h$1);return p("div",{className:"mrakomor-block-element",[b]:true,$ref:p=>{l=p;}},d)}),{equals:e})])])])}(function(){if(!(typeof document>"u")){var o="mrakomor/core/plugin/dialog/Dialog.css",t=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(n){return n.getAttribute("data-mrakomor-css-path")===o});if(!t){var e=document.createElement("style");e.setAttribute("data-mrakomor-css",""),e.setAttribute("data-mrakomor-css-path",o),e.textContent=`.mrakomor-dialog-container,.mrakomor-dialog-backdrop{pointer-events:all}.dialog[open]{background-color:#fff;border:1px solid black;border-radius:8px;box-shadow:0 0 5px #0000001a;padding:12px;display:flex;flex-flow:row wrap;justify-content:space-between}.dialog[open] .dialog-controls{text-align:right;width:100%}.dialog[open] .dialog-button-close{background-color:#f0f0f0;border:1px solid black;border-radius:4px;color:#000;cursor:pointer;display:inline-block;font-size:14px;margin-right:1px;padding:4px 8px;text-align:center}.dialog[open] .dialog-container{width:100%}
3
3
  `,document.head.appendChild(e);}}})();var ht="mrakomor.dialog.Dialog";function H({open:o,placement:t,positionX:e,positionY:n,block:r,dialogRef:c$1}){let l=c(()=>{let d=t.get()==="center";return {position:"absolute",zIndex:d?"9100":"9000",top:`${n.get()}px`,left:`${e.get()}px`,...d?{padding:0,background:"transparent",border:"none",boxShadow:"none",minWidth:0}:{background:"#fff",border:"1px solid #ccc",borderRadius:"4px",padding:"8px 10px",boxShadow:"0 2px 8px rgba(0,0,0,.15)",minWidth:"220px"}}}),h=c(()=>({position:"absolute",inset:"0",zIndex:"9050",background:"rgba(15, 23, 42, 0.28)",pointerEvents:"all"}));return p("span",{style:{display:"contents"}},[u(()=>o.get()&&t.get()==="center",p("div",{className:"mrakomor-dialog-backdrop",contentEditable:false,style:h})),u(()=>o.get(),p("div",{className:"mrakomor-dialog-container",contenteditable:false,style:l,$ref:c$1},()=>r.get()))])}H.NAMESPACE=ht;function q({mrakomor:o$2}){let t=null,e$1=e(false),n=e(false),r=e("anchor"),c=e(0),l=e(0),h=e(null),d=g(null),p$1=g(null);function b(){n.set(false),r.set("anchor"),o$1(),d.set(null),o(()=>{e$1.set(false);});}return {resolveComponent(f){if(f===ht)return H},registerEvents(){a$2.OPEN_DIALOG="mrakomor:open-dialog",a$2.CLOSE_DIALOG="mrakomor:close-dialog";},registerCommands(f){f.command.openDialog=(x,k)=>{f.emit(a$2.OPEN_DIALOG,{...x,options:k});},f.command.closeDialog=()=>{f.emit(a$2.CLOSE_DIALOG);};},registerHandlers(){o$2.emitter.on(a$2.OPEN_DIALOG,({children:f,element:x$1,options:k={}})=>{h.set(f??p("div",{},"Empty dialog")),n.set(true),d.set(x$1??null),r.set(k.placement??"anchor"),o(()=>{let N=o$2.getRoot(),{x:I,y:v}=k.placement==="center"?y(N,p$1):x(N,x$1??{left:0,top:0},p$1);c.set(I),l.set(v),e$1.set(true);});}),o$2.emitter.on(a$2.CLOSE_DIALOG,b),o$2.emitter.on(a$2.KEYDOWN,f=>{f.key==="Escape"&&n.peek()===true&&o$2.command.closeDialog();}),o$2.emitter.on(a$2.CLICK,f=>{if(n.peek()!==true||e$1.peek()!==true)return;let x=f.target,k=p$1&&typeof p$1.contains=="function"&&p$1.contains(x),N=d&&typeof d.contains=="function"&&d.contains(x);!k&&!N&&o$2.command.closeDialog();});},onMount(){let{dispose:f}=a$1(o$2,"mrakomor-dialog-plugin-container",p(H,{open:n,placement:r,positionX:c,positionY:l,block:h,dialogRef:p$1}));t=f;},onUnmount(){t?.(),t=null;}}}var Y=class extends a$5{constructor(t){super(t,{sort:e=>e});}normalize(t){return c$3(t)}};(function(){if(!(typeof document>"u")){var o="mrakomor/core/plugin/menu/Menu.css",t=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(n){return n.getAttribute("data-mrakomor-css-path")===o});if(!t){var e=document.createElement("style");e.setAttribute("data-mrakomor-css",""),e.setAttribute("data-mrakomor-css-path",o),e.textContent=`.mrakomor-menu{position:absolute;z-index:9300;display:flex;flex-direction:column;gap:2px;min-width:160px;max-height:240px;overflow-y:auto;background:#1a1a1a;border-radius:6px;padding:4px;box-shadow:0 3px 10px #00000040;pointer-events:all}.mrakomor-menu__item{display:flex;align-items:center;width:100%;padding:6px 10px;border:none;border-radius:4px;background:transparent;color:#fff;cursor:pointer;font-size:13px;font-weight:600;text-align:left;transition:background .1s}.mrakomor-menu__item:hover,.mrakomor-menu__item--active{background:#ffffff26}.mrakomor-menu__empty{padding:6px 10px;font-size:13px;font-weight:600;color:#ffffff80}
4
4
  `,document.head.appendChild(e);}}})();function St(o,t=-1){if(!o.length)return p("div",{className:"mrakomor-menu__empty",role:"presentation"},"No results");let e=o.map((n,r)=>p("button",{type:"button",role:"option",id:`mrakomor-menu-option-${n.id}`,className:["mrakomor-menu__item",r===t?"mrakomor-menu__item--active":""].filter(Boolean).join(" "),title:n.label,"data-id":n.id,"aria-selected":r===t?"true":"false",onMouseDown:c=>{c.preventDefault();}},n.label));return p("span",{style:"display: contents"},e)}function X({open:o,positionX:t,positionY:e,entries:n,highlightIndex:r,ariaLabel:c$1,menuRef:l}){let h=c(()=>({left:`${t.get()}px`,top:`${e.get()}px`}));return u(()=>o.get(),p("div",{className:"mrakomor-menu",role:"listbox","aria-label":()=>c$1.get(),contenteditable:false,style:h,$ref:l},()=>St(n.get(),r.get())))}function j({mrakomor:o$1}){let t=null,e$1=null,n=g(null),r=null,c=e(false),l=e(false),h=e(0),d=e(0),p$1=e([]),b=e(-1),f=e("Menu");function x$1(s){o(()=>{let u=o$1.getRoot();if(!u||!s)return;let C=n?.offsetHeight??200,y=u.getBoundingClientRect();if(s.top-y.top>C+8){let{x:_,y:bt}=x(u,s,{offsetHeight:C},4);h.set(_),d.set(bt);}else h.set(s.left-y.left),d.set(s.bottom-y.top+4);c.set(true);});}function k(){l.set(false),r=null,b.set(-1),p$1.set([]),o(()=>{c.set(false);});}function N(s){!s||!r||r(s);}function I(s){if(l.peek()!==true)return;let u=s.target?.closest?.(".mrakomor-menu__item");if(!u||!e$1?.contains(u))return;s.preventDefault(),s.stopPropagation();let C=u.getAttribute("data-id"),y=p$1.peek().find(D=>D.id===C);y&&N(y);}function v(s={}){let{entries:u=[],anchorRect:C,highlightIndex:y=-1,ariaLabel:D="Menu",onSelect:_=null}=s;p$1.set(u),b.set(y),f.set(D),_!==void 0&&(r=_),l.set(true),C?x$1(C):c.set(true);}return {registerEvents(){a$2.OPEN_MENU="mrakomor:open-menu",a$2.CLOSE_MENU="mrakomor:close-menu",a$2.UPDATE_MENU="mrakomor:update-menu";},registerCommands(s){s.command.openMenu=u=>{s.emit(a$2.OPEN_MENU,u);},s.command.updateMenu=u=>{s.emit(a$2.UPDATE_MENU,u);},s.command.closeMenu=()=>{s.emit(a$2.CLOSE_MENU);};},registerHandlers(){o$1.emitter.on(a$2.OPEN_MENU,v),o$1.emitter.on(a$2.UPDATE_MENU,v),o$1.emitter.on(a$2.CLOSE_MENU,k),o$1.emitter.on(a$2.CLICK,s=>{let u=n?.current??n;l.peek()===true&&c.peek()===true&&u&&typeof u.contains=="function"&&!u.contains(s.target)&&k();}),o$1.emitter.on(a$2.KEYDOWN,s=>{s.key==="Escape"&&l.peek()===true&&k();});},onMount(){let{container:s,dispose:u}=a$1(o$1,"mrakomor-menu-plugin-container",p(X,{open:l,positionX:h,positionY:d,entries:p$1,highlightIndex:b,ariaLabel:f,menuRef:n}));e$1=s,e$1?.addEventListener("click",I),t=u;},onUnmount(){e$1?.removeEventListener("click",I),t?.(),t=null,e$1=null,n.current=null,r=null;}}}function Nt(o){return o!=null&&typeof o=="object"&&(typeof Element>"u"?o.nodeType===1:o instanceof Element)}function kt(){return a.object({root:a.any().refine(Nt,{message:"root must be a DOM Element"}),id:a.string().optional(),debug:a.boolean().optional(),content:a.array(a.any()).optional(),plugins:a.array(a.function()).optional(),blockComponents:a.array(a.any().refine(o=>typeof o=="function"||o!=null&&typeof o=="object"&&typeof o.component=="function",{message:"blockComponents entry must be a constructor or registration"})).optional(),slashActions:a.array(a.any().refine(o=>o!=null&&typeof o=="object"&&typeof o.handler=="function",{message:"slashActions entry must include a handler function"})).optional(),inlineStyles:a.array(a.function()).optional(),entityRanges:a.array(a.function()).optional(),tooltip:a.any().optional()})}function Et(o){return [...o.filter(t=>t!==q&&t!==j&&t!==c$2),q,j,c$2]}function _t(o){kt().parse(o);let t={debug:false,content:[],plugins:[],blockComponents:[],slashActions:[],inlineStyles:[B,w,O,L,R],entityRanges:[],tooltip:{}},e={...t,...o,plugins:Et(o.plugins??t.plugins)},n=new W(e);return n._init(),n}var W=class{#o=a$3();#n;#i=null;#e=[];#t=[];#r;#s=false;listenerAbortController=new AbortController;#a=e([],{debug:"content"});#l=[];command;emitter;register;constructor(t){let{root:e,id:n,content:r}=t;this.#o=n||this.#o,this.#n=e,this.#l=r,this.#t=[],this.#r={...t,plugins:Et(t.plugins??[])},this.register={blocks:new G(this),help:new Y(this)};let{emitter:c,command:l}=c$1({mrakomor:this});this.command=l,this.emitter=c;}_init(){this.#u(),this.#a=e(this._normalizeContentState(this.#l),{debug:"content"});}#u(){this.#e=this.#r.plugins.map(t=>t?.({config:this.#r,root:this.#n,mrakomor:this}))??[],this.#r=this.#e.reduce((t,e)=>e?.resolveConfig?.(t)??t,this.#r),this.register.blocks.add(this.#r.blockComponents??[]),this.#e.forEach(t=>{t?.registerEvents?.(this);}),this.#e.forEach(t=>{t?.registerCommands?.(this);}),this.#e.forEach(t=>{this.emitter.on(a$2.KEYDOWN,e=>t?.onKeyDown?.(e));}),this.#e.forEach(t=>{t?.registerHandlers?.(this);}),this.#e.forEach(t=>{t?.registerListeners?.(this);});}emit(t,e={}){return this.emitter.emit(t,{...e,mrakomor:this})}on(t,e){return this.emitter.on(t,e)}onChangeContent(t){return this.on(a$2.CONTENT_CHANGE,t)}emitDomEvent(t,e){let{clipboardData:n,metaKey:r,altKey:c,code:l,ctrlKey:h,key:d,isComposing:p,repeat:b,button:f,shiftKey:x,which:k,detail:N,isTrusted:I,target:v,relatedTarget:s,data:u,inputType:C,clientX:y,clientY:D}=e??{},{defaultPrevented:_}=this.emit(t,{clipboardData:n,metaKey:r,altKey:c,code:l,ctrlKey:h,key:d,isComposing:p,repeat:b,button:f,shiftKey:x,which:k,detail:N,isTrusted:I,target:v,relatedTarget:s,data:u,inputType:C,clientX:y,clientY:D});return _&&e?.preventDefault?.(),_}getConfig(){return {...this.#r,blockComponents:this.register.blocks.list(),slashActions:this.register.slashActions?.list()??[]}}wrapBlockElement(t){for(let e of this.#e){let n=e.wrapBlockElement?.(t);if(n)return n}return t}getRoot(){return this.#n}_getContentRoot(){return this.#i}_setContentRoot(t){this.#i=t;}get _id(){return this.#o}getContent(){return this.#t.map(e=>v(e)?.getState())}setContent(t=[]){this._setContentState(this._normalizeContentState(t));}_syncBlockElementsFromDom(){let t=this.#i;t&&(this.#t=[...t.querySelectorAll(".mrakomor-block-element")]);}_getBlockElements(){return this.#t}_getContentState(){return this.#a.get()}_setContentState(t=[]){this.#a.set(t),this.emit(a$2.CONTENT_CHANGE,{content:t}),o(()=>{this._syncBlockElementsFromDom();});}_normalizeContentState(t=[]){return t.map(e=>{let n=this.normalizeComponentState(e);return n===void 0?void 0:structuredClone(n)}).filter(e=>e!==void 0)??[]}_setBlockElement(t,e=this.#t.length){this.#t.splice(e,0,t);}_removeBlockElement(t){this.#t=this.#t.filter(e=>e!==t);}#m(t){return v(t)?.state?.peek()?.componentId}#c(t){return t?this.#t.findIndex(e=>this.#m(e)===t):-1}_getBlockElementIndex(t){if(!t)return -1;let e=this.#t.indexOf(t);return e!==-1?e:this.#c(this.#m(t))}_getBlockElementByComponentId(t){let e=this.#c(t);return e===-1?null:this.#t[e]}_getBlockElementState(t){let e=this._getBlockElementIndex(t);if(e!==-1)return v(this.#t[e])?.getState()}mount(){let t=s(this.#n,p(gt,{mrakomor:this}));return this.#s=true,t}unmount(){this.#s&&(this.#s=false,t(this.#n));}_onUnmount(){this.listenerAbortController.abort(),this.#e.forEach(t=>{t?.onUnmount?.(this);}),this.emitter.removeAllListeners();}_onMount(){this.#e.forEach(t=>{t?.onMount?.(this);}),o(()=>{this._syncBlockElementsFromDom();});}resolveComponent(t,e){let n=this.resolveComponentConstructor(t);return n?p(n,{state:e}):p(a$4,{state:e})}resolveComponentConstructor(t){let e=this.register.blocks.getByNamespace(t);if(!e){for(let n of this.#e)if(e=n?.resolveComponent?.(t),e)break}return e}normalizeComponentState(t){if(t==null){console.warn("normalizeComponentState() received a nullish state; dropping it.");return}let e="component"in t?t.component:t.entity.type;return this.resolveComponentConstructor(e)?.getStateSchema()?.parse(t)}};export{B as Bold,H as Dialog,w as Italic,X as Menu,W as Mrakomor,L as Subscript,R as Superscript,O as Underline,_t as createMrakomor,q as dialogPlugin,j as menuPlugin};
package/dist/link.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import {a as a$1}from'./chunk-2C6UDFD4.mjs';import {b as b$1}from'./chunk-JVQ2YGII.mjs';import'./chunk-ZHOZPQZH.mjs';import {a}from'./chunk-P7IKAZYZ.mjs';import {f as f$1,m}from'./chunk-P7TUN2KD.mjs';import {g,o,p}from'./chunk-7CJLTNHZ.mjs';(function(){if(!(typeof document>"u")){var r="mrakomor/core/plugin/linkEntity/LinkEntity.css",e=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(a){return a.getAttribute("data-mrakomor-css-path")===r});if(!e){var t=document.createElement("style");t.setAttribute("data-mrakomor-css",""),t.setAttribute("data-mrakomor-css-path",r),t.textContent=`.link-toolbar{display:flex;flex-direction:column;gap:6px}.link-toolbar__row{display:flex;align-items:center;gap:4px;min-width:0}.link-toolbar__sep{width:1px;height:18px;background:#e0e0e0;flex-shrink:0;margin:0 2px}.link-toolbar__btn{display:flex;align-items:center;justify-content:center;flex-shrink:0;background:none;border:none;cursor:pointer;padding:4px;border-radius:4px;color:#555}.link-toolbar__btn:hover{background:#f0f0f0;color:#222}.link-toolbar__btn--danger:hover{color:#d32f2f;background:#fdecea}
1
+ import {a as a$1}from'./chunk-2C6UDFD4.mjs';import {b as b$1}from'./chunk-B2UFH244.mjs';import'./chunk-ZHOZPQZH.mjs';import {a}from'./chunk-P7IKAZYZ.mjs';import {f as f$1,m}from'./chunk-4WTPDNPA.mjs';import {g,o,p}from'./chunk-7CJLTNHZ.mjs';(function(){if(!(typeof document>"u")){var r="mrakomor/core/plugin/linkEntity/LinkEntity.css",e=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(a){return a.getAttribute("data-mrakomor-css-path")===r});if(!e){var t=document.createElement("style");t.setAttribute("data-mrakomor-css",""),t.setAttribute("data-mrakomor-css-path",r),t.textContent=`.link-toolbar{display:flex;flex-direction:column;gap:6px}.link-toolbar__row{display:flex;align-items:center;gap:4px;min-width:0}.link-toolbar__sep{width:1px;height:18px;background:#e0e0e0;flex-shrink:0;margin:0 2px}.link-toolbar__btn{display:flex;align-items:center;justify-content:center;flex-shrink:0;background:none;border:none;cursor:pointer;padding:4px;border-radius:4px;color:#555}.link-toolbar__btn:hover{background:#f0f0f0;color:#222}.link-toolbar__btn--danger:hover{color:#d32f2f;background:#fdecea}
2
2
  `,document.head.appendChild(t);}}})();var k=a.preprocess(r=>String(r??"").trim(),a.string().refine(r=>r===""||/^(?:https?:|mailto:)/i.test(r)||!/^[a-z][a-z0-9+.-]*:/i.test(r),{message:"Invalid link href"}).catch(""));function u(r){return k.parse(r)}var f='<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"><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>';var b='<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"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>';var i=class r extends a$1{static get nodeName(){return "a"}static get NAMESPACE(){return "atom.link.Link"}static getStateSchema(e){let t;if(e?.getAttribute("data-state"))try{t=JSON.parse(e.getAttribute("data-state"));}catch{}return b$1({type:r.NAMESPACE,data:a.object({href:a.string().default(t?.entity?.data?.href??e?.href??"").transform(a=>u(a)),target:a.string().default(t?.entity?.data?.target??e?.target??"")}).default({}),length:t?.length??0,offset:t?.offset??0}).default({})}constructor(e){super(e),this.input=g(t=>o(()=>{t.focus();}));}#e({entity:e,length:t,offset:a}){return p("div",{className:"link-toolbar"},[p("div",{className:"link-toolbar__row",style:{display:"flex"}},[p("button",{className:"link-toolbar__btn",title:"Copy URL",$dangerouslySetInnerHTML:f,onClick:()=>navigator.clipboard?.writeText(e.peek()?.data?.href??"")}),p("input",{type:"text",$ref:this.input,value:e.peek()?.data?.href??"",defaultValue:e.peek()?.data?.href??"",onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),o.stopPropagation(),this.mrakomor.command.closeDialog());},onInput:o=>{let s=o.currentTarget.value;e.set({...e.peek(),data:{...e.peek()?.data,href:s}});}}),p("select",{value:e.peek()?.data?.target??"",onChange:o=>{e.set({...e.peek(),data:{...e.peek()?.data,target:o.currentTarget.value}});}},[p("option",{value:"",selected:e.peek()?.data?.target===""},""),p("option",{value:"_self",selected:e.peek()?.data?.target==="_self"},"_self"),p("option",{value:"_blank",selected:e.peek()?.data?.target==="_blank"},"_blank"),p("option",{value:"_parent",selected:e.peek()?.data?.target==="_parent"},"_parent"),p("option",{value:"_top",selected:e.peek()?.data?.target==="_top"},"_top")]),p("span",{className:"link-toolbar__sep"}),p("button",{className:"link-toolbar__btn link-toolbar__btn--danger",title:"Remove link",$dangerouslySetInnerHTML:b,onClick:()=>{this.mrakomor.command.removeEntityRange?.({state:{entity:e.peek(),length:t.peek(),offset:a.peek()},blockElement:f$1(this.element)});}})])])}onMount(){let{entity:e}=this.props;e.peek()?.data?.href||this.mrakomor.command.openDialog({element:this.element,children:this.#e(this.props)});}render(){let{entity:e,length:t,offset:a,children:o$1}=this.props;return p("a",{href:()=>u(e.get()?.data?.href),target:()=>e.get()?.data?.target||null,rel:()=>e.get()?.data?.target==="_blank"?"noopener noreferrer":null,$ref:this.element,onClick:s=>{s.ctrlKey||s.metaKey||o(()=>{m(),this.mrakomor.command.openDialog({element:this.element,children:this.#e({entity:e,length:t,offset:a})});});},"data-state":()=>JSON.stringify({entity:e.get(),length:t.get(),offset:a.get()})},o$1)}};function v({mrakomor:r}){return {resolveConfig:e=>(e.entityRanges.push(i),e),resolveComponent:e=>{if(e===i.NAMESPACE)return i},registerHandlers(){r.register.help.add({id:"link.insert",group:"formatting",description:"Insert or edit a link on the selection",commands:[],shortcuts:["Mod+K"]});},onKeyDown(e){e.key==="k"&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),r.command.insertEntityRange({namespace:i.NAMESPACE}));}}}
3
3
  export{i as LinkEntity,v as linkEntityPlugin};