lakelib 0.3.5 → 0.3.6

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/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ---
8
8
 
9
- Lake is a browser-based rich text editor built for modern applications that require content creation like blog posts, user comments, and email composition. It aims to provide as many features as possible through a simple structure while remaining free for commercial use.
9
+ Lake is a rich text editor built for modern applications that require content creation like blog posts, user comments, and email composition. It aims to provide as many features as possible through a simple structure while remaining free for commercial use.
10
10
 
11
11
  [Examples](https://lakejs.org/examples/) · [Getting started](https://lakejs.org/guide/) · [Reference](https://lakejs.org/reference/)
12
12
 
package/dist/lake.min.js CHANGED
@@ -19,7 +19,7 @@ var Lake=function(e){"use strict";class t extends HTMLElement{}void 0!==customEl
19
19
  <span class="lake-box-strip"><br /></span>
20
20
  <div class="lake-box-container" contenteditable="false"></div>
21
21
  <span class="lake-box-strip"><br /></span>
22
- `),e=this.getContainer()):(e.off("mouseenter"),e.off("mouseleave"),e.off("click")),e.on("mouseenter",(()=>{e.hasClass("lake-box-selected")||e.hasClass("lake-box-focused")||e.hasClass("lake-box-activated")||e.addClass("lake-box-hovered")})),e.on("mouseleave",(()=>{e.removeClass("lake-box-hovered")})),e.on("click",(()=>{g(`Box "${this.name}" (id = ${this.node.id}) value:`),g(this.value)})),"block"===this.type&&this.node.isContentEditable&&e.attr("draggable","true")}get type(){return this.node.attr("type")}get name(){return this.node.attr("name")}get value(){const e=this.node.attr("value");return""===e?{}:JSON.parse(P(e))}set value(e){this.node.attr("value",M(JSON.stringify(e)))}updateValue(e,t){const i=this.value;if("string"==typeof e)i[e]=t;else for(const t of Object.keys(e))i[t]=e[t];this.value=i}getEditor(){const e=this.node.closest("div[contenteditable]"),t=e.length>0?E.get(e.id):void 0;if(!t)throw new Error(`Box "${this.name}" (id=${this.node.id}) is not rendered in the editor.`);return t}getContainer(){return this.node.find(".lake-box-container")}getHTML(){const e=I.get(this.name);return void 0===e?"":void 0===e.html?this.node.outerHTML():e.html(this)}setToolbar(e){const t=this.getEditor();this.event.on("focus",(()=>{this.toolbar&&this.toolbar.unmount(),this.toolbar=new fe({target:this.node,items:e}),this.toolbar.render();const i=t.selection.getActiveItems();this.toolbar.updateState({activeItems:i}),this.event.emit("renderfloatingtoolbar")})),this.event.on("blur",(()=>{this.toolbar&&(this.toolbar.unmount(),this.toolbar=null)}))}render(){const e=I.get(this.name);if(void 0===e)return;this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.initiate();const t=e.render(this);if(void 0!==t){const e=this.getContainer();e.empty(),e.append(t)}g(`Box "${this.name}" (id: ${this.node.id}) rendered`)}unmount(){this.event.emit("blur"),this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.node.empty(),g(`Box "${this.name}" (id: ${this.node.id}) unmounted`)}}function we(e){const t=S(0);if("string"==typeof e){const i=new ve(e);return t.set(i.node.id,i),i}const i=(e=y(e)).closestContainer();if(0===i.length){let i=t.get(e.id);return i||(i=new ve(e),t.set(e.id,i),i)}const n=S(i.id);let o=t.get(e.id);return o?(n.set(e.id,o),t.delete(e.id),o):(o=n.get(e.id),o||(o=new ve(e),n.set(e.id,o),o))}class ye{constructor(e){this.fragment=null!=e?e:document.createDocumentFragment()}get(){return this.fragment}find(e){const t=[];let i=new w(this.fragment.firstChild);for(;i.length>0;)i.matches(e)?t.push(i.get(0)):i.isElement&&i.find(e).each((e=>{t.push(e)})),i=i.next();return new w(t)}append(e){y(e).each((e=>{this.fragment.appendChild(e)}))}}const xe={id:/^[\w-]+$/,class:/^[\w\- ]+$/,style:{"text-align":["left","center","right","justify","start","end"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function be(){return{h1:Object.assign({},xe),h2:Object.assign({},xe),h3:Object.assign({},xe),h4:Object.assign({},xe),h5:Object.assign({},xe),h6:Object.assign({},xe),p:Object.assign({},xe),blockquote:Object.assign(Object.assign({},xe),{type:["info","tip","success","warning","error","danger"]}),ul:Object.assign(Object.assign({},xe),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},xe),{start:/^\d+$/,indent:/^\d+$/}),li:{value:["true","false"]},table:{style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/}},tr:{style:{height:/^-?\d+(px|%)$/i}},th:"td",td:{colspan:/^\d+$/,rowspan:/^\d+$/,style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/,"text-align":["left","center","right","justify"]}},"lake-box":{type:["inline","block"],name:/^[\w-]+$/,value:/^[^"]+$/,focus:["start","center","end"]},br:{},hr:{},img:{src:/^[^"]+$/,width:/^-?\d+px$/i,height:/^-?\d+px$/i,"data-lake-value":/^[^"]+$/,alt:/^[^"]+$/,style:{width:/^-?\d+px$/i,height:/^-?\d+px$/i}},span:{class:/^[\w\- ]+$/,style:{color:/^[^"]+$/,"background-color":/^[^"]+$/,"font-family":/^[^;]+$/,"font-size":/^[^"]+$/}},b:"strong",strong:{},em:"i",i:{},u:{},s:{},sub:{},sup:{},code:{},a:{class:/^[\w\- ]+$/,name:/^[\w-]+$/,href:/^[^"]+$/,target:/^[\w-]+$/,rel:/^[^"]+$/,download:/^[^"]+$/},"lake-bookmark":{type:["anchor","focus"]}}}function ke(e){e=e.replace(/&quot;/gi,'"');const t={},i=/\s*([\w-]+)\s*:([^;]*)(?:;|$)/g;let n;for(;null!==(n=i.exec(e));){const e=n[1].toLowerCase().trim(),i=m(n[2]).trim();t[e]=i}return t}class Ce{constructor(e,t=be()){this.rules=t,this.source="string"==typeof e?this.parseHTML(e):e}parseHTML(e){const t=(new DOMParser).parseFromString(e,"text/html");return new w(t.querySelector("body"))}static matchRule(e,t){return"string"==typeof e?e===t:Array.isArray(e)?e.indexOf(t)>=0:e instanceof RegExp&&e.test(t)}static getOpenTagString(e,t){let i=e.name,n=t[i];if(!n)return"";"string"==typeof n&&(i=n,n=t[i]);const o=e.get(0);if(!o.hasAttributes())return i;const s=new Map;for(const e of o.attributes)if(n[e.name]&&("style"!==e.name&&Ce.matchRule(n[e.name],e.value)&&s.set(e.name,e.value),"style"===e.name)){const t=n.style,i=new Map,o=ke(e.value);for(const e of Object.keys(o)){const n=o[e];t[e]&&Ce.matchRule(t[e],n)&&i.set(e,n)}s.set("style",i)}let r=i;for(const[e,t]of s)if("style"===e){let e="";for(const[i,n]of t)e+=`${i}: ${n.replace(/"/g,"&quot;")}; `;""!==e&&(r+=` style="${e.trim()}"`)}else r+=` ${e}="${t}"`;return r}static getClosedTagString(e,t){let i=e.name;const n=t[i];return n?("string"==typeof n&&(i=n),i):""}static getTrimmedText(e){const t=e.parent(),i=e.prev(),n=e.next();let o=e.text();return(i.isBlock||i.isBlockBox)&&(n.isBlock||n.isBlockBox)||0===i.length&&0===n.length&&t.isBlock?o=o.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):i.isBlock||i.isBlockBox||0===i.length&&t.isBlock?o=o.replace(/^[\u0020\t\r\n]+/,""):(n.isBlock||n.isBlockBox||0===n.length&&t.isBlock)&&(o=o.replace(/[\u0020\t\r\n]+$/,"")),o}getHTML(){const e=this.rules;let t="";for(const i of function*t(i){let n=i.first();for(;n.length>0;){const i=n.next();if(n.isText)yield b(Ce.getTrimmedText(n));else if(n.isVoid){const t=Ce.getOpenTagString(n,e);""!==t&&(yield`<${t} />`)}else if(n.isElement){const i=Ce.getOpenTagString(n,e),o=Ce.getClosedTagString(n,e);""!==i&&(yield`<${i}>`),n.isBox||(yield*t(n)),""!==o&&(yield`</${o}>`)}n=i}}(this.source))t+=i;return t.trim()}getFragment(){const e=this.getHTML(),t=this.parseHTML(e),i=document.createDocumentFragment();let n=t.first();for(;n.length>0;){const e=n.next();i.appendChild(n.get(0)),n=e}return i}}class Se{constructor(e){this.content=e}getHTML(){let e=this.content;return e=e.replace(/ {2}/g,"  "),e=b(e.trim()),e=`<p>${e}</p>`,e=e.replace(/(\r\n){2,}/g,"</p><p><br /></p><p>"),e=e.replace(/\r\n/g,"</p><p>"),e=e.replace(/[\r\n]{2,}/g,"</p><p><br /></p><p>"),e=e.replace(/[\r\n]/g,"</p><p>"),e}getFragment(){return new Ce(this.getHTML()).getFragment()}}function Be(e,t){const i=e.get(),n=t.get(0);i.insertNode(n),i.setEndAfter(n),i.collapse(!1)}function Ae(e){if(e.commonAncestor.isOutside)return{anchor:new w,focus:new w};const t=e.startNode.closest("lake-box");if(t.length>0)return e.isBoxStart?t.attr("focus","start"):e.isBoxEnd?t.attr("focus","end"):t.attr("focus","center"),{anchor:new w,focus:t};if(e.isCollapsed){const t=e.clone();t.collapseToEnd();const i=y('<lake-bookmark type="focus" />');return Be(t,i),{anchor:new w,focus:i}}const i=e.clone();i.collapseToStart();const n=y('<lake-bookmark type="anchor" />');Be(i,n);const o=e.clone();o.collapseToEnd();const s=y('<lake-bookmark type="focus" />');return Be(o,s),{anchor:n,focus:s}}function _e(e,t){const i=e.prev(),n=e.next();if(i.isText||n.isText){const t=e.parent();e.remove(),t.get(0).normalize()}else if(0===i.length&&0===n.length){if(e.parent().isMark&&t){const i=new w(document.createTextNode("​"));e.before(i),t.setStartAfter(i),t.collapseToStart()}e.remove()}else e.remove()}function Le(e,t){const i=t.anchor,n=t.focus;if(i.length>0&&0===n.length)_e(i);else{if(n.length>0&&0===i.length){if(n.isBox){const t=we(n);0===t.getContainer().length&&t.render();const i=n.attr("focus");return"start"===i?e.selectBoxStart(n):"center"===i?e.selectBox(n):e.selectBoxEnd(n),void n.removeAttr("focus")}return e.setStartBefore(n),e.collapseToStart(),void _e(n,e)}if(i.length>0&&n.length>0){const t=new Z;t.selectNode(i),t.collapseToEnd(),-1===t.compareAfterNode(n)?(e.setStartBefore(n),_e(n),e.setEndBefore(i),_e(i)):(e.setStartBefore(i),_e(i),e.setEndBefore(n),_e(n))}}}function Te(e){if(0===e.length)return;const t=[];let i=e.first();for(;i.length>0;){const e=i.next();i.isText&&""===i.text()||t.push(i),i=e}(1===t.length&&"br"===t[0].name||2===t.length&&"br"===t[0].name&&t[1].isBookmark)&&t[0].remove(),2===t.length&&t[0].isBookmark&&"br"===t[1].name&&t[1].remove()}function Ie(e){const t=y("<br />");let i=e;for(;i.isBlock;){let e=i.last();for(;e.isText&&e.isEmpty;)e=e.prev();if(!e.isBlock&&"br"!==e.name){i.append(t);break}i=e}return t}function Ee(e){if(e.isText)return{node:e,offset:e.text().length};const t=new Z;return t.setEndAfter(e),{node:t.endNode,offset:t.endOffset}}function Me(e,t){const i=t;if(["ul","ol"].indexOf(e.name)>=0){const t=e.find("li");e=t.eq(t.length-1)}if(["ul","ol"].indexOf(t.name)>=0){const e=t.find("li");t=e.eq(0)}if(e.isText||t.isText||e.isVoid||t.isVoid)return Ee(e);Te(e),Te(t),e.isBlock&&e.isEmpty&&t.isEmpty&&Ie(e);const n=e.last(),o=t.first();let s=o;for(;s.length>0;){const t=s.next();e.append(s),s=t}return i.remove(),n.length>0&&o.length>0&&n.isElement&&!n.isBox&&n.clone(!1).get(0).isEqualNode(o.clone(!1).get(0))?Me(n,o):0===n.length?{node:e,offset:0}:Ee(n)}function Pe(e){if(0===e.length)return;const t=e[0],i=e[e.length-1],n=[];let o=t.prev();for(;o.length>0&&"ol"===o.name;)n.push(o),o=o.prev();n.reverse(),n.push(...e);let s=i.next();for(;s.length>0&&"ol"===s.name;)n.push(s),s=s.next();let r=1;for(const e of n){const t=e.prev();if(0!==t.length&&"ol"===t.name||(r=1),"ol"===e.name){"ol"===t.name&&t.attr("indent")!==e.attr("indent")&&(r=1);const i=e.attr("start"),n=r.toString(10);i!==n&&e.attr("start",n),r++}}}function He(e){if(e.isCollapsed)return;if(e.adjustBox(),e.adjustTable(),e.isInoperative)return;const t=e.startNode.closestBlock(),i=e.endNode.closestBlock(),n=t.get(0)===i.get(0);if(e.get().deleteContents(),e.adjustBlock(),n){const t=e.getBlocks()[0];if(t&&t.isEmpty){const i=Ie(t);e.setStartBefore(i),e.collapseToStart()}return}const o=e.getBlocks()[0];if(!o)return;const s=o.prev();if(0===s.length)return;const r=Ae(e);Me(s,o),Pe([s]),Le(e,r)}function Ze(e,t){if(e.commonAncestor.isOutside)return;let i;t instanceof ye?i=t:t instanceof DocumentFragment?i=new ye(t):(i=new ye,i.append(t)),e.isCollapsed?e.adjustBox():He(e);Te(e.startNode.closestBlock());const n=e.get();n.insertNode(i.get()),n.collapse(!1),e.adjustBlock()}function De(e){let t=e;for(;t.length>0;){let e=t.first();if(e.isText&&e.isEmpty&&(e=e.next()),t.isElement&&!t.isVoid&&0===e.length)break;t=e}return t}function Ne(e,t){if(t=null!=t?t:y("<p />"),0===e.length)return t;const i=De(t=t.clone(!0));e[0].before(t);for(const t of e)i.append(t);return t}function ze(e,t){if(e.commonAncestor.isOutside)return;if(e.isCollapsed){if(e.commonAncestor.closest("lake-box").isBlockBox)return}if("string"!=typeof t){const i=e.getBlocks();for(const e of i)e.css(t);return}const i=y(t),n=i.name,o=i.get(0).attributes,s=e.getBlocks();if(s.length>0){const t=Ae(e);for(const e of s)if(e.name===n&&0===i.first().length)for(const t of o)e.attr(t.name,t.value);else{const t=i.clone(!0);t.isList&&e.isList&&""!==e.attr("indent")&&t.attr("indent",e.attr("indent"));const n=De(t);let o=e.first();for(;o.length>0;){const e=o.next();n.append(o),n.name!==o.name&&"li"!==o.name||o.remove(!0),o=e}e.replaceWith(t)}return Le(e,t),void Pe(e.getBlocks())}if(e.isCollapsed){const t=e.getNextNode();if("br"===t.name){const i=y("<p><br /></p>");return t.replaceWith(i),void e.shrinkBefore(i)}const i=e.getPrevNode();if("br"===i.name){const t=y("<p><br /></p>");return i.replaceWith(t),void e.shrinkBefore(t)}}const r=Ae(e),a=function(e){const t=e.commonAncestor.closest('div[contenteditable="true"],td');let i=[];if(0===t.length)return i;let n=t.first(),o=!0;for(;n.length>0;){if(n.isMark||n.isText||n.isBookmark||n.isInlineBox)i.push(n);else{if(!o)break;i=[]}e.intersectsNode(n)&&(o=!1),n=n.next()}return i}(e),l=Ne(a,i);if(Le(e,r),Pe(e.getBlocks()),l.isEmpty){const t=Ie(l);e.setStartBefore(t),e.collapseToStart()}}function Oe(e,t,i){const n=new Z;let o;if(e.isText){o=e.parent();const i=e.splitText(t);n.setStartAfter(e),""===e.text()&&e.remove(),""===i.text()&&i.remove()}else n.setStart(e,t),o=e;if("body"===o.name||"html"===o.name)return null;if(o.get(0)===i.get(0))return null;n.collapseToStart();const s=o.clone();let r=o.first();for(;r.length>0&&!(n.compareBeforeNode(r)>=0);){const e=r.next();s.append(r),r=e}return o.before(s),o.parent().length>0&&o.parent().get(0)!==i.get(0)?Oe(o.parent(),o.index(),i):{start:s,end:o}}function $e(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function Ve(e){if(e.commonAncestor.isOutside)return{start:null,end:null};e.isCollapsed?e.adjustBox():He(e);const t=e.startNode,i=t.closestOperableBlock();if(0===i.length)return{start:null,end:null};let n=i.parent();n.isOutside&&(n=t.closestContainer());const o=Oe(t,e.startOffset,n);let s=null,r=null;return o&&(s=o.start,r=o.end),!o&&t.isBlock&&(e.startOffset>0&&(s=t.children()[e.startOffset-1]),r=t.children()[e.startOffset],r&&!r.isBlock&&(r=null)),s&&s.isEmpty&&($e(s),Ie(s)),r&&(r.isEmpty&&($e(r),Ie(r)),e.shrinkBefore(r)),Pe(e.getBlocks()),{start:s,end:r}}function Re(e,t){if(e.commonAncestor.isOutside)return null;const i=y(t),n=Ve(e);return n.start&&($e(n.start),e.setEndAfter(n.start),e.collapseToEnd()),n.end&&($e(n.end),n.end.isEmpty&&n.end.remove()),Ze(e,i),i.isBox||e.shrinkAfter(i),n.start&&n.start.isEmpty&&n.start.remove(),i}function Fe(e,t,i){let n=null,o=null,s=e.closestBlock();0===s.length&&(s=e.closestContainer());const r=Oe(e,t,s);return r&&(i?($e(r.start),$e(r.end),r.start.isEmpty||(n=r.start),r.end.isEmpty||(o=r.end)):(n=r.start,o=r.end)),{start:n,end:o}}function We(e,t=!0){if(e.commonAncestor.isOutside)return{start:null,center:null,end:null};if(e.adjustBox(),e.isCollapsed){const i=Fe(e.startNode,e.startOffset,t);return i.start?(e.setStartAfter(i.start),e.collapseToStart()):i.end&&(e.setStartBefore(i.end),e.collapseToStart()),{start:i.start,center:null,end:i.end}}const i=Fe(e.startNode,e.startOffset,t);i.start?e.setStartAfter(i.start):i.end&&e.setStartBefore(i.end);const n=Fe(e.endNode,e.endOffset,t);return n.start?e.setEndAfter(n.start):n.end&&e.setEndBefore(n.end),{start:i.start,center:n.start,end:n.end}}function je(e,t){const i=e.text();let n=e;for(;n.length>0;){const e=n.parent();if(!e.isMark||i!==e.text()||!n.isText&&n.name===t&&""!==n.attr("style"))break;n=e}return n}function qe(e,t){if(e.commonAncestor.isOutside)return;let i=y(t);const n=i.name,o=ke(i.attr("style"));if(e.isCollapsed){if(e.isBox){const t=e.startNode.closest("lake-box");if("block"===we(t).type){const i=y("<p><br /></p>");e.isBoxStart?t.before(i):t.after(i),e.shrinkAfter(i)}else e.adjustBox()}Te(e.startNode.closestBlock());const t=new w(document.createTextNode("​")),s=function(e){let t=e;t.isText&&(t=t.parent());let i=null;for(;t.length>0&&t.isMark;){if(i){const e=t.clone();e.append(i),i=e}else i=t.clone();t=t.parent()}return i}(e.startNode);if(We(e),s){let e=s;for(;e.length>0;)e.name===n&&e.css(o),e=e.first();s.name===n?i=s:i.append(s)}if(""===i.text()){De(i).append(t)}return Ze(e,i),function(e){const t=e.prev();t.length>0&&t.isText&&t.isEmpty&&t.remove();const i=e.next();i.length>0&&i.isText&&i.isEmpty&&i.remove()}(i),void e.shrinkAfter(i)}We(e);const s=e.getMarks(!0),r=Ae(e);for(const e of s)if(!e.isEmpty&&e.isText){const t=je(e,n);if(t.isMark&&t.name===n)t.css(o);else{const e=i.clone();t.before(e),e.append(t)}}Le(e,r)}function Ue(e,t){if(e.commonAncestor.isOutside)return;let i;if(t){i=y(t).name}if(e.isCollapsed){if(e.isBox)return;if(i&&0===e.commonAncestor.closest(i).length)return;const t=We(e,!1);if(!t.start)return;t.end&&$e(t.end);const n=new w(document.createTextNode("​")),o=function(e,t){if(!e.isMark||!t)return null;let i=null,n=null,o=e;for(;o.length>0&&o.isMark;){if(o.name!==t)if(n){const e=o.clone();n.append(e),n=e}else i=o.clone(),n=i;o=o.last()}return i}(t.start,i);if(!o)return t.start.after(n),$e(t.start),n.prev().isText?(e.setStartAfter(n.prev()),e.collapseToStart(),void n.remove()):(e.setStartAfter(n),void e.collapseToStart());return De(o).append(n),t.start.after(o),$e(t.start),void e.shrinkAfter(o)}We(e);const n=e.getMarks(),o=Ae(e);for(const e of n)if(!i||e.name===i){const t=e.parent();e.remove(!e.isEmpty),t.length>0&&t.get(0).normalize()}!function(e){for(const t of e.getWalker())if(t.isText){const e=t.text();""===e?t.remove():e.length>1&&/\u200B/.test(e)&&(t.get(0).nodeValue=e.replace(/\u200B/g,""))}}(e.commonAncestor),Le(e,o)}function Ke(e,t,i){if(e.commonAncestor.isOutside)return null;const n=we(t);if(i&&(n.value=i),"inline"===n.type){if(We(e),Ze(e,n.node),n.render(),n.node.isTopInside){const e=y("<p />");n.node.before(e),e.append(n.node)}return e.selectBoxEnd(n.node),we(n.node)}return Re(e,n.node),n.render(),e.selectBoxEnd(n.node),we(n.node)}function Ge(e){const t=e.node.closestContainer();if(e.unmount(),e.node.remove(),t.length>0){S(t.id).delete(e.node.id);S(0).set(e.node.id,e)}return e}function Xe(e){if(e.commonAncestor.isOutside)return null;const t=e.commonAncestor.closest("lake-box");if(0===t.length)return null;const i=we(t);if("block"===i.type){const n=y("<p><br /></p>");return t.before(n),e.shrinkAfter(n),Ge(i)}e.setStartBefore(t),e.collapseToStart();const n=t.parent();if(Ge(i),n.isEmpty){const t=Ie(n);e.setStartBefore(t),e.collapseToStart()}return i}var Qe,Ye={exports:{}};function Je(){if(Qe)return Ye.exports;function e(e,t=100,i={}){if("function"!=typeof e)throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw new RangeError("`wait` must not be negative.");const{immediate:n}="boolean"==typeof i?{immediate:i}:i;let o,s,r,a,l;function c(){const t=o,i=s;return o=void 0,s=void 0,l=e.apply(t,i),l}function d(){const e=Date.now()-a;e<t&&e>=0?r=setTimeout(d,t-e):(r=void 0,n||(l=c()))}const h=function(...e){if(o&&this!==o&&Object.getPrototypeOf(this)===Object.getPrototypeOf(o))throw new Error("Debounced method called with different contexts of the same prototype.");o=this,s=e,a=Date.now();const i=n&&!r;return r||(r=setTimeout(d,t)),i&&(l=c()),l};return Object.defineProperty(h,"isPending",{get:()=>void 0!==r}),h.clear=()=>{r&&(clearTimeout(r),r=void 0)},h.flush=()=>{r&&h.trigger()},h.trigger=()=>{l=c(),h.clear()},h}return Qe=1,Ye.exports.debounce=e,Ye.exports=e,Ye.exports}var et,tt,it=B(Je());var nt=B(tt?et:(tt=1,et=function e(t,i){if(t===i)return!0;if(t&&i&&"object"==typeof t&&"object"==typeof i){if(t.constructor!==i.constructor)return!1;var n,o,s;if(Array.isArray(t)){if((n=t.length)!=i.length)return!1;for(o=n;0!=o--;)if(!e(t[o],i[o]))return!1;return!0}if(t instanceof Map&&i instanceof Map){if(t.size!==i.size)return!1;for(o of t.entries())if(!i.has(o[0]))return!1;for(o of t.entries())if(!e(o[1],i.get(o[0])))return!1;return!0}if(t instanceof Set&&i instanceof Set){if(t.size!==i.size)return!1;for(o of t.entries())if(!i.has(o[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(i)){if((n=t.length)!=i.length)return!1;for(o=n;0!=o--;)if(t[o]!==i[o])return!1;return!0}if(t.constructor===RegExp)return t.source===i.source&&t.flags===i.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===i.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===i.toString();if((n=(s=Object.keys(t)).length)!==Object.keys(i).length)return!1;for(o=n;0!=o--;)if(!Object.prototype.hasOwnProperty.call(i,s[o]))return!1;for(o=n;0!=o--;){var r=s[o];if(!e(t[r],i[r]))return!1}return!0}return t!=t&&i!=i}));function ot(e){return e.replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"<anchor />").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"<focus />")}function st(e){return e.replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box>|$)/gi,"$1</lake-box>").replace(/<anchor\s*\/>/gi,'<lake-bookmark type="anchor"></lake-bookmark>').replace(/<focus\s*\/>/gi,'<lake-bookmark type="focus"></lake-bookmark>')}function rt(e){const t=e.get(0),i={};if(t.hasAttributes())for(const e of t.attributes)i[e.name]=e.value;return i}class at{constructor(e){const t=window.getSelection();if(!t)throw new Error("Selection object is null.");this.selection=t,this.container=e,this.range=this.getCurrentRange()}getCurrentRange(){if(this.selection.rangeCount>0){const e=this.selection.getRangeAt(0);return new Z(e)}return new Z}sync(){this.container.contains(this.range.commonAncestor)&&(this.selection.removeAllRanges(),this.selection.addRange(this.range.get()))}updateByRange(){const e=this.getCurrentRange();this.container.contains(e.commonAncestor)&&(this.range.startNode.get(0)===e.startNode.get(0)&&this.range.startOffset===e.startOffset&&this.range.endNode.get(0)===e.endNode.get(0)&&this.range.endOffset===e.endOffset||(this.range=e))}updateByBookmark(){const e=this.range,t=this.container,i=t.find("lake-box[focus]");if(i.length>0)return Le(e,{anchor:new w,focus:i}),void this.sync();Le(e,{anchor:t.find('lake-bookmark[type="anchor"]'),focus:t.find('lake-bookmark[type="focus"]')}),this.sync()}getActiveItems(){const e=[];return function(e,t){let i=t.startNode;for(i.isText&&(i=i.parent());i.length>0&&i.isContentEditable&&!i.isContainer;)e.push({node:i,name:i.name,attributes:rt(i),styles:ke(i.attr("style"))}),i=i.parent()}(e,this.range),function(e,t){const i=t.startNode;let n;if(i.isText&&i.text().length===t.startOffset){const e=i.next();e.length>0&&e.isElement&&(n=e)}if(i.isElement){const e=i.children();if(e.length>0){const i=e[t.startOffset];i&&i.isElement&&(n=i)}}if(n){let t=n;for(;t.length>0;)t.isElement&&e.push({node:t,name:t.name,attributes:rt(t),styles:ke(t.attr("style"))}),t=t.first()}}(e,this.range),e}insertBookmark(){return Ae(this.range)}toBookmark(e){return Le(this.range,e)}insertContents(e){return Ze(this.range,e)}deleteContents(){return He(this.range)}setBlocks(e){return ze(this.range,e)}splitBlock(){return Ve(this.range)}insertBlock(e){return Re(this.range,e)}splitMarks(e){return We(this.range,e)}addMark(e){return qe(this.range,e)}removeMark(e){return Ue(this.range,e)}selectBox(e){let t=e;t=e instanceof ve?e.node:e,this.range.selectBox(t),this.sync()}insertBox(e,t){const i=Ke(this.range,e,t);if(!i)throw new Error(`Box "${e}" cannot be inserted into the outside of the editor.`);return i}removeBox(e=null){return e&&this.selectBox(e),Xe(this.range)}}class lt{constructor(e){this.commandMap=new Map,this.selection=e}add(e,t){this.commandMap.set(e,t)}delete(e){this.commandMap.delete(e)}getNames(){return Array.from(this.commandMap.keys())}has(e){return void 0!==this.commandMap.get(e)}getItem(e){const t=this.commandMap.get(e);if(void 0===t)throw new Error(`Command "${e}" has not been defined yet.`);return t}isDisabled(e){const t=this.getItem(e);if(!t.isDisabled)return!1;const i=this.selection.getActiveItems();return t.isDisabled(i)}isSelected(e){const t=this.getItem(e);if(!t.isSelected)return!1;const i=this.selection.getActiveItems();return t.isSelected(i)}selectedValues(e){const t=this.getItem(e);if(!t.selectedValues)return[];const i=this.selection.getActiveItems();return t.selectedValues(i)}execute(e,...t){const i=this.selection.container,n=this.selection.range;i.contains(n.commonAncestor)||n.shrinkAfter(i);this.getItem(e).execute.apply(this,t),g(`Command "${e}" executed`)}}const ct=new Set;function dt(){}const ht={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:dt,afterNodeAdded:dt,beforeNodeMorphed:dt,afterNodeMorphed:dt,beforeNodeRemoved:dt,afterNodeRemoved:dt,beforeAttributeUpdated:dt,afterAttributeUpdated:dt,beforeChildrenUpdated:dt},head:{style:"merge",shouldPreserve:e=>"true"===e.getAttribute("im-preserve"),shouldReAppend:e=>"true"===e.getAttribute("im-re-append"),shouldRemove:dt,afterHeadMorphed:dt}};function pt(e,t){return!e.deadIds.has(t)}function ut(e,t,i){return(e.idMap.get(i)||ct).has(t)}function mt(e,t){const i=e.idMap.get(t)||ct;for(const t of i)e.deadIds.add(t)}function gt(e,t,i){const n=e.idMap.get(t)||ct;let o=0;for(const t of n)pt(e,t)&&ut(e,t,i)&&++o;return o}function ft(e,t){const i=e.parentElement,n=e.querySelectorAll("[id]");for(const e of n){let n=e;for(;n!==i&&null!=n;){let i=t.get(n);null==i&&(i=new Set,t.set(n,i)),i.add(e.id),n=n.parentElement}}}function vt(e,t){const i=new Map;return ft(e,i),ft(t,i),i}function wt(e,t,i){return{target:e,newContent:t,config:i=function(e){const t={};return Object.assign(t,ht),Object.assign(t,e),t.callbacks={},Object.assign(t.callbacks,ht.callbacks),Object.assign(t.callbacks,e.callbacks),t.head={},Object.assign(t.head,ht.head),Object.assign(t.head,e.head),t}(i),morphStyle:i.morphStyle,ignoreActive:i.ignoreActive,ignoreActiveValue:i.ignoreActiveValue,idMap:vt(e,t),deadIds:new Set,callbacks:i.callbacks,head:i.head}}function yt(e,t,i){return null!=e&&null!=t&&(e.nodeType===t.nodeType&&e.tagName===t.tagName&&(""!==e.id&&e.id===t.id||gt(i,e,t)>0))}function xt(e,t){return null!=e&&null!=t&&(e.nodeType===t.nodeType&&e.tagName===t.tagName)}function bt(e,t){mt(t,e),!1!==t.callbacks.beforeNodeRemoved(e)&&(e.remove(),t.callbacks.afterNodeRemoved(e))}function kt(e,t,i){let n=e;for(;n&&n!==t;){const e=n;n=n.nextSibling,bt(e,i)}return mt(i,t),t.nextSibling}function Ct(e,t,i,n,o){const s=gt(o,i,t);let r=null;if(s>0){r=n;let t=0;for(;null!=r;){if(yt(i,r,o))return r;if(t+=gt(o,r,e),t>s)return null;r=r.nextSibling}}return r}function St(e,t,i,n,o){let s=n,r=i.nextSibling,a=0;for(;null!=s;){if(gt(o,s,e)>0)return null;if(xt(i,s))return s;if(xt(r,s)&&(a++,r=r?r.nextSibling:null,a>=2))return null;s=s?s.nextSibling:null}return s}function Bt(e,t,i){return xt(e,t)?.5+gt(i,e,t):0}function At(e,t,i,n){return!("value"!==e||!n.ignoreActiveValue||t!==document.activeElement)||!1===n.callbacks.beforeAttributeUpdated(e,t,i)}function _t(e,t,i){var n;if(!i.ignoreActive||e!==document.activeElement)return null==t?!1===i.callbacks.beforeNodeRemoved(e)?e:(e.remove(),i.callbacks.afterNodeRemoved(e),null):xt(e,t)?(!1===i.callbacks.beforeNodeMorphed(e,t)||(function(e,t,i){const n=e.nodeType;if(1===n){const n=e.attributes,o=t.attributes;for(const e of n)At(e.name,t,"update",i)||t.getAttribute(e.name)!==e.value&&(t.setAttribute(e.name,e.value),i.callbacks.afterAttributeUpdated(e.name,t,"update"));for(let n=o.length-1;n>=0;n--){const s=o[n];At(s.name,t,"remove",i)||e.hasAttribute(s.name)||(t.removeAttribute(s.name),i.callbacks.afterAttributeUpdated(s.name,t,"remove"))}}8!==n&&3!==n||t.nodeValue!==e.nodeValue&&(t.nodeValue=e.nodeValue)}(t,e,i),!1===i.callbacks.beforeChildrenUpdated(e,t)||function(e,t){return t.ignoreActiveValue&&e===document.activeElement}(e,i)||Lt(t,e,i),i.callbacks.afterNodeMorphed(e,t)),e):!1===i.callbacks.beforeNodeRemoved(e)||!1===i.callbacks.beforeNodeAdded(t)?e:(null===(n=e.parentElement)||void 0===n||n.replaceChild(t,e),i.callbacks.afterNodeAdded(t),i.callbacks.afterNodeRemoved(e),t)}function Lt(e,t,i){let n,o=e.firstChild,s=t.firstChild;for(;o;){if(n=o,o=n.nextSibling,null==s){if(!1===i.callbacks.beforeNodeAdded(n))return;t.appendChild(n),i.callbacks.afterNodeAdded(n),mt(i,n);continue}if(yt(n,s,i)){_t(s,n,i),s=s.nextSibling,mt(i,n);continue}const r=Ct(e,t,n,s,i);if(r){s=kt(s,r,i),_t(r,n,i),mt(i,n);continue}const a=St(e,0,n,s,i);if(a)s=kt(s,a,i),_t(a,n,i),mt(i,n);else{if(!1===i.callbacks.beforeNodeAdded(n))return;t.insertBefore(n,s),i.callbacks.afterNodeAdded(n),mt(i,n)}}for(;null!==s;){const e=s;s=s.nextSibling,bt(e,i)}}function Tt(e,t,i){if("innerHTML"===i.morphStyle)return Lt(t,e,i),e.children;const n=function(e,t,i){let n;n=e.firstChild;let o=n,s=0;for(;n;){const e=Bt(n,t,i);e>s&&(o=n,s=e),n=n.nextSibling}return o}(t,e,i),o=null==n?void 0:n.previousSibling,s=null==n?void 0:n.nextSibling,r=_t(e,n,i);return n?function(e,t,i){var n,o;const s=[],r=[];let a=e;for(;null!=a;)s.push(a),a=a.previousSibling;for(;s.length>0;){const e=s.pop();r.push(e),e&&(null===(n=t.parentElement)||void 0===n||n.insertBefore(e,t))}r.push(t);let l=i;for(;null!=l;)s.push(l),r.push(l),l=l.nextSibling;for(;s.length>0;){const e=s.pop();e&&(null===(o=t.parentElement)||void 0===o||o.insertBefore(e,t.nextSibling))}return r}(o,r,s):[]}function It(e,t,i={}){const n=function(e){if(null==e)return document.createElement("div");if(e instanceof Node){if(e.generatedByIdiomorph)return e;const t=document.createElement("div");return t.append(e),t}const t=document.createElement("div");for(const i of[...e])t.append(i);return t}(t.get(0)),o=wt(e.get(0),n,i);Tt(e.get(0),n,o)}class Et{constructor(e){this.canSave=!0,this.list=[],this.index=0,this.limit=100,this.event=new T,this.selection=e,this.container=e.container}removeBookmark(e){return e.replace(/(<lake-box[^>]+)\sfocus="\w+"([^>]*>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"")}getValue(e){return new Ce(e).getHTML()}addIdToBoxes(e){e.find("lake-box").each((e=>{const t=new w(e),i=`${t.attr("name")}-${t.attr("value")}`;t.attr("id",i)}))}removeIdfromBoxes(e){e.find("lake-box").each((e=>{new w(e).removeAttr("id")}))}morphContainer(e){const t=this.container,i={beforeChildrenUpdated:e=>{if("lake-box"===new w(e).name)return!1},afterAttributeUpdated:(e,i)=>{const n=new w(i);if(["name","value"].indexOf(e)>=0&&"lake-box"===n.name){we(n).unmount();S(t.id).delete(n.id)}}},n=e.clone(!0);this.addIdToBoxes(t),this.addIdToBoxes(n),It(t,n,{callbacks:i}),this.removeIdfromBoxes(t),this.removeIdfromBoxes(n)}get canUndo(){return this.index>1&&!!this.list[this.index-2]}get canRedo(){return!!this.list[this.index]}cloneContainer(){const e=this.selection.range,t=this.container.clone(!0);if(t.find("lake-box").each((e=>{we(e).getContainer().empty()})),!this.container.contains(e.commonAncestor))return t;if(e.isInsideBox){const i=e.commonAncestor.closest("lake-box").path(),n=t.find(i),o=e.clone();return o.selectBox(n),Ae(o),t}const i=e.startNode.path(),n=e.endNode.path(),o=t.find(i),s=t.find(n),r=e.clone();return r.setStart(o,e.startOffset),r.setEnd(s,e.endOffset),Ae(r),t}undo(){if(!this.list[this.index-2])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index>1;){const t=this.list[this.index-2];if(!t)break;this.index--;const i=this.getValue(t);if(this.removeBookmark(i)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("undo",i);break}}this.selection.updateByBookmark(),g(`History undone (index: ${this.index})`)}redo(){if(!this.list[this.index])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index<this.list.length;){const t=this.list[this.index];if(!t)break;this.index++;const i=this.getValue(t);if(this.removeBookmark(i)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("redo",i);break}}this.selection.updateByBookmark(),g(`History redone (index: ${this.index})`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(e={}){var t,i,n;const o=null!==(t=e.inputType)&&void 0!==t?t:"",s=null!==(i=e.update)&&void 0!==i&&i,r=null===(n=e.emitEvent)||void 0===n||n;if(!this.canSave)return;const a=this.cloneContainer(),l=this.getValue(a);this.list[this.index-1]&&this.removeBookmark(this.getValue(this.list[this.index-1]))===this.removeBookmark(l)||(s?this.list.splice(this.index-1,1/0,a):(this.list.splice(this.index,1/0,a),this.index++),this.list.length>this.limit&&(this.list.shift(),this.index=this.list.length),g(`History saved (index: ${this.index}, inputType: "${o}", update: ${s}, emitEvent: ${r})`),r&&this.event.emit("save",ot(l),{inputType:o,update:s,emitEvent:r}))}}var Mt,Pt={};var Ht=function(){if(Mt)return Pt;Mt=1,Object.defineProperty(Pt,"__esModule",{value:!0});for(var e="undefined"!=typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.platform),t={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},i={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:e?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},n={backspace:8,tab:9,enter:13,shift:16,control:17,alt:18,pause:19,capslock:20,escape:27," ":32,pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,insert:45,delete:46,meta:91,numlock:144,scrolllock:145,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},o=1;o<20;o++)n["f"+o]=111+o;function s(e,t,i){t&&!("byKey"in t)&&(i=t,t=null),Array.isArray(e)||(e=[e]);var n=e.map((function(e){return r(e,t)})),o=function(e){return n.some((function(t){return a(t,e)}))};return null==i?o:o(i)}function r(e,o){var s=o&&o.byKey,r={},a=(e=e.replace("++","+add")).split("+"),d=a.length;for(var h in t)r[t[h]]=!1;var p=!0,u=!1,m=void 0;try{for(var g,f=a[Symbol.iterator]();!(p=(g=f.next()).done);p=!0){var v=g.value,w=v.endsWith("?")&&v.length>1;w&&(v=v.slice(0,-1));var y=c(v),x=t[y];if(v.length>1&&!x&&!i[v]&&!n[y])throw new TypeError('Unknown modifier: "'+v+'"');1!==d&&x||(s?r.key=y:r.which=l(v)),x&&(r[x]=!w||null)}}catch(e){u=!0,m=e}finally{try{!p&&f.return&&f.return()}finally{if(u)throw m}}return r}function a(e,t){for(var i in e){var n=e[i],o=void 0;if(null!=n&&((null!=(o="key"===i&&null!=t.key?t.key.toLowerCase():"which"===i?91===n&&93===t.which?91:t.which:t[i])||!1!==n)&&o!==n))return!1}return!0}function l(e){return e=c(e),n[e]||e.toUpperCase().charCodeAt(0)}function c(e){return e=e.toLowerCase(),e=i[e]||e}return Pt.default=s,Pt.isHotkey=s,Pt.isCodeHotkey=function(e,t){return s(e,t)},Pt.isKeyHotkey=function(e,t){return s(e,{byKey:!0},t)},Pt.parseHotkey=r,Pt.compareHotkey=a,Pt.toKeyCode=l,Pt.toKeyName=c,Pt}();class Zt{constructor(e){this.keydownEventList=[],this.keyupEventList=[],this.container=e,this.container.on("keydown",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keydownEventList)if(Ht.isKeyHotkey(e.type,t)&&!1===e.listener(t))break})),this.container.on("keyup",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keyupEventList)if(Ht.isKeyHotkey(e.type,t)&&!1===e.listener(t))break}))}setKeydown(e,t){this.keydownEventList.push({type:e,listener:t})}setKeyup(e,t){this.keyupEventList.push({type:e,listener:t})}keydown(e){for(const t of this.keydownEventList)if(t.type===e&&!1===t.listener(new KeyboardEvent(e)))break}keyup(e){for(const t of this.keyupEventList)if(t.type===e&&!1===t.listener(new KeyboardEvent(e)))break}}const Dt={value:"<p><br /></p>",readonly:!1,spellcheck:!1,tabIndex:0,placeholder:"",indentWithTab:!0,lang:"en-US",minChangeSize:5,historySize:100,onMessage:(e,t)=>{"success"!==e?"warning"!==e?"error"===e&&console.error(t):console.warn(t):console.log(t)},slash:!1,mention:!1};class Nt{constructor(e){if(this.unsavedInputData="",this.unsavedInputCount=0,this.state={activeItems:[],disabledNameMap:new Map,selectedNameMap:new Map,selectedValuesMap:new Map},this.unmountPluginMap=new Map,this.event=new T,this.isComposing=!1,this.popup=null,this.copyListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("copy",e)},this.cutListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("cut",e)},this.pasteListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("paste",e)},this.selectionchangeListener=()=>{this.updateSelectionRange(),this.updateBoxSelectionStyle(),this.emitStateChangeEvent()},this.clickListener=e=>{const t=new w(e.target);t.get(0).isConnected&&this.event.emit("click",t)},this.updateSelectionRange=it((()=>{this.selection.updateByRange()}),1,{immediate:!0}),this.updateBoxSelectionStyle=it((()=>{if(0===this.root.first().length)return;const e=this.selection.getCurrentRange(),t=e.clone();t.adjustBox(),this.container.find("lake-box").each((i=>{const n=we(i),o=n.getContainer();if(0!==o.length){if(e.compareBeforeNode(o)<0&&e.compareAfterNode(o)>0&&(!e.isCollapsed||e.startNode.get(0)!==o.get(0)||0!==e.startOffset))return o.removeClass("lake-box-hovered"),o.removeClass("lake-box-selected"),o.removeClass("lake-box-focused"),o.addClass("lake-box-activated"),void n.event.emit("focus");if(t.intersectsNode(n.node))return o.removeClass("lake-box-activated"),void(e.isCollapsed?(o.removeClass("lake-box-hovered"),o.removeClass("lake-box-selected"),o.addClass("lake-box-focused"),n.event.emit("focus")):(o.removeClass("lake-box-focused"),o.addClass("lake-box-selected"),n.event.emit("blur")));o.removeClass("lake-box-activated"),o.removeClass("lake-box-focused"),o.removeClass("lake-box-selected"),n.event.emit("blur")}}))}),50,{immediate:!0}),this.emitStateChangeEvent=it((()=>{const e=this.command.getNames();let t=this.selection.getActiveItems();t.length>0&&!this.container.contains(t[0].node)&&(t=[]);const i=new Map,n=new Map,o=new Map;if(t.length>0)for(const s of e){const e=this.command.getItem(s);if(e.isDisabled&&e.isDisabled(t)&&i.set(s,!0),e.isSelected&&e.isSelected(t)&&n.set(s,!0),e.selectedValues){const i=e.selectedValues(t);i.length>0&&o.set(s,i)}}const s={activeItems:t,disabledNameMap:i,selectedNameMap:n,selectedValuesMap:o};nt(s,this.state)||(this.toolbar&&this.toolbar.updateState(s),this.event.emit("statechange",s),this.state=s)}),50,{immediate:!1}),!e.root)throw new Error("The root of the config must be specified.");this.root=y(e.root),this.toolbar=e.toolbar,this.config=Object.assign({},Dt);for(const t of Object.keys(e))this.config[t]=e[t];this.containerWrapper=y('<div class="lake-container-wrapper" />'),this.container=y('<div class="lake-container" />'),this.overlayContainer=y('<div class="lake-overlay" />'),this.readonly=this.config.readonly,this.container.attr({contenteditable:this.readonly?"false":"true",spellcheck:this.config.spellcheck?"true":"false",tabindex:this.config.tabIndex.toString(),readonly:this.readonly?"true":"false"}),""!==this.config.placeholder&&this.container.attr("placeholder",this.config.placeholder),this.selection=new at(this.container),this.command=new lt(this.selection),this.history=new Et(this.selection),this.history.limit=this.config.historySize,this.keystroke=new Zt(this.container),E.set(this.container.id,this)}togglePlaceholderClass(e){const t="lake-placeholder";"<p><br /></p>"===(e=ot(e)).replace("<focus />","")?this.container.addClass(t):this.container.removeClass(t)}moveBoxStripText(){const e=this.selection,t=e.range,i=t.startNode.closest(".lake-box-strip"),n=i.closest("lake-box");if("inline"===we(n).type)t.isBoxStart?(t.setStartBefore(n),t.collapseToStart()):(t.setStartAfter(n),t.collapseToStart());else{const e=y("<p />");t.isBoxStart?n.before(e):n.after(e),t.setStart(e,0),t.collapseToStart()}const o=i.text();i.html("<br />"),e.insertContents(document.createTextNode(o))}resetUnsavedInputData(){this.unsavedInputData="",this.unsavedInputCount=0}handleInputEvent(e){var t;this.selection.updateByRange();const i=this.selection.range;if(i.isInsideBox)return;if(i.isBoxStart||i.isBoxEnd)return this.moveBoxStripText(),void this.history.save();if("insertText"===(e instanceof CompositionEvent?"insertText":e.inputType)){const i=null!==(t=e.data)&&void 0!==t?t:"";return i.length>1?void this.history.save({inputType:"insertText",update:!1}):(this.unsavedInputData+=i,this.unsavedInputCount++,void(this.unsavedInputData.length<this.config.minChangeSize?this.history.save({inputType:"insertText",update:this.unsavedInputCount>1}):(this.history.save({inputType:"insertText",update:!0}),this.resetUnsavedInputData())))}this.history.save()}bindInputEvents(){this.container.on("compositionstart",(()=>{this.isComposing=!0,this.container.removeClass("lake-placeholder")})),this.container.on("compositionend",(e=>{this.isComposing=!1,this.handleInputEvent(e)})),this.container.on("input",(e=>{const t=e;this.isComposing=t.isComposing,this.isComposing||this.handleInputEvent(e)}))}removeBoxGarbage(){const e=S(this.container.id);for(const t of e.values())t.node.get(0).isConnected||(t.unmount(),e.delete(t.node.id))}bindHistoryEvents(){const e=e=>{this.fixContent()&&(this.history.save({update:!0,emitEvent:!1}),e=this.getValue()),this.emitStateChangeEvent(),this.togglePlaceholderClass(e),this.scrollToCursor(),this.event.emit("change",e)};this.history.event.on("undo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("redo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("save",((t,i)=>{this.removeBoxGarbage(),e(t),"insertText"!==i.inputType&&(this.selection.sync(),this.resetUnsavedInputData())}))}get locale(){return he(this.config.lang)}setPluginConfig(e,t){"object"!=typeof this.config[e]&&(this.config[e]={});for(const i of Object.keys(t))void 0===this.config[e][i]&&(this.config[e][i]=t[i])}fixContent(){const e=this.selection.range,t=e.commonAncestor.closest("td"),i=t.length>0?t:this.container;let n=!1,o=i.children();for(const e of o)(e.isBlock||e.isMark)&&""===e.html()&&(e.remove(),n=!0,g(`Content fixed: empty tag "${e.name}" was removed`));if(o=i.children(),0===o.length)i.html("<p><br /></p>"),e.shrinkBefore(i),n=!0,g("Content fixed: default paragraph was added");else if(1===o.length){const t=o[0];if(t.isVoid){const i=y("<p />");t.before(i),i.append(t),e.shrinkAfter(i),n=!0,g(`Content fixed: void element "${t.name}" was wrapped in paragraph`)}}return e.adjustBr(),n}renderBoxes(){this.removeBoxGarbage();const e=this.container,t=S(e.id);e.find("lake-box").each((e=>{const i=y(e);if(t.get(i.id))return;we(i).render()}))}scrollToCursor(){const e=this.selection.range;if(e.isBox)return;const t=e.getRect();if(0===t.x||0===t.y)return;const i=this.container.get(0).getBoundingClientRect(),n=y('<div class="lake-artificial-cursor" />'),o=t.x-i.x,s=t.y-i.y;n.css({position:"absolute",top:`${s}px`,left:`${o}px`,width:`${t.width}px`,height:`${t.height}px`,"z-index":"-1"}),this.overlayContainer.find(".lake-artificial-cursor").remove(),this.overlayContainer.append(n),function(e,t){const i=H(e);0===i.left&&0===i.right&&0===i.top&&0===i.bottom||e.get(0).scrollIntoView(t)}(n,{behavior:"instant",block:"nearest",inline:"nearest"}),n.remove()}hasFocus(){const e=document.activeElement;return!!e&&y(e).closest(".lake-container").get(0)===this.container.get(0)}focus(){const e=this.selection.range;this.container.contains(e.commonAncestor)&&e.isBox||this.container.focus()}blur(){this.container.blur()}setValue(e){e=st(e);const t=new Ce(e),i=t.getFragment();this.container.empty(),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.renderBoxes(),this.selection.updateByBookmark()}getValue(){const e=this.history.cloneContainer();let t=new Ce(e).getHTML();return t=ot(t),t}render(){const e=st(this.config.value),t=new Ce(e),i=t.getFragment();this.root.empty(),this.root.append(this.containerWrapper),this.containerWrapper.append(this.container),this.containerWrapper.append(this.overlayContainer),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.unmountPluginMap=Nt.plugin.loadAll(this),this.readonly||(this.selection.updateByBookmark(),this.history.save({emitEvent:!1})),this.renderBoxes(),this.toolbar&&this.toolbar.render(this),document.addEventListener("copy",this.copyListener),this.readonly||(document.addEventListener("cut",this.cutListener),document.addEventListener("paste",this.pasteListener),document.addEventListener("selectionchange",this.selectionchangeListener),document.addEventListener("click",this.clickListener),this.bindInputEvents(),this.bindHistoryEvents())}unmount(){this.updateSelectionRange.flush(),this.updateBoxSelectionStyle.flush(),this.emitStateChangeEvent.flush();for(const e of this.unmountPluginMap.keys()){const t=this.unmountPluginMap.get(e);t&&(t(),g(`Plugin "${e}" unmounted`))}this.toolbar&&this.toolbar.unmount(),this.removeBoxGarbage(),this.container.find("lake-box").each((e=>{we(y(e)).unmount()})),this.event.removeAllListeners(),this.history.event.removeAllListeners(),this.root.off(),this.root.empty(),document.removeEventListener("copy",this.copyListener),this.readonly||(document.removeEventListener("cut",this.cutListener),document.removeEventListener("paste",this.pasteListener),document.removeEventListener("selectionchange",this.selectionchangeListener),document.removeEventListener("click",this.clickListener))}}Nt.version="0.3.5",Nt.box=new class{add(e){I.set(e.name,e)}remove(e){I.delete(e)}getNames(){return Array.from(I.keys())}},Nt.plugin=new class{constructor(){this.pluginMap=new Map}add(e,t){this.pluginMap.set(e,t)}loadAll(e){const t=new Map;for(const i of this.pluginMap.keys()){const n=this.pluginMap.get(i);if(n&&!1!==e.config[i]){const o=n(e);o&&t.set(i,o)}}return t}};function zt(e,t){const i=e.get(0),n=y(k`<${t} />`);for(const e of i.attributes)n.attr(e.name,e.value);let o=e.first();for(;o.length>0;){const e=o.next();n.append(o),o=e}return e.replaceWith(n),n}const Ot=Array.from(s).join(",");function $t(e){const t=[e];for(const i of e.getWalker())t.push(i);for(const e of t)"div"===e.name?e.find(Ot).length>0?e.remove(!0):zt(e,"p"):(e.isHeading||["blockquote","li"].indexOf(e.name)>=0)&&e.find(Ot).remove(!0)}function Vt(e,t){const i=e.selection,n=i.range;if(0===t.childNodes.length)return;const o=new w(t.firstChild);let s=new w(t.lastChild);0===n.getBlocks().length&&i.setBlocks("<p />"),function(e,t){const i=e.selection.range,n=i.startNode.closest("lake-box");if(n.length>0)if("inline"===we(n).type)i.isBoxStart?(i.setStartBefore(n),i.collapseToStart()):i.isBoxEnd?(i.setStartAfter(n),i.collapseToStart()):e.selection.removeBox();else{const t=y("<p />");i.isBoxStart?(n.before(t),i.shrinkAfter(t)):i.isBoxEnd?(n.after(t),i.shrinkAfter(t)):e.selection.removeBox()}const o=i.startNode.closestBlock();if(t.isBlockBox){const i=we(t),n=""!==t.attr("value")?i.value:void 0;return e.selection.insertBox(i.name,n),void t.remove()}if(t.first().length>0&&Te(o),o.isEmpty&&"p"===o.name)return o.replaceWith(t),t.find("lake-box").each((e=>{we(e).render()})),void i.shrinkAfter(t);let s=t.first();for(;s.length>0;){"li"===s.name&&(s=s.first());const t=s.next();e.selection.insertContents(s),s.isBox?we(s).render():s.isElement&&s.find("lake-box").each((e=>{we(e).render()})),s=t}t.remove()}(e,o);let r=new w(t.firstChild);for(;r.length>0;){const e=r.next();"br"===r.name&&r.remove(),r=e}if(s=new w(t.lastChild),t.childNodes.length>0){const o=i.splitBlock();o.start&&(n.setEndAfter(o.start),n.collapseToEnd()),o.end&&o.end.isEmpty&&o.end.remove(),i.insertContents(t),e.renderBoxes(),n.shrinkAfter(s)}Pe(e.container.children().filter((e=>e.isBlock))),e.history.save()}const Rt=["info","tip","warning","danger"];function Ft(e){e.selection.setBlocks("<p />")}function Wt(e){e.selection.setBlocks("<ol><li></li></ol>")}function jt(e){e.selection.setBlocks("<ul><li></li></ul>")}function qt(e,t){e.selection.setBlocks(`<ul type="checklist"><li value="${t}"></li></ul>`)}function Ut(e){const t=e.startNode.closest("table"),i=y("<p><br /></p>");t.replaceWith(i),e.shrinkBefore(i),g(`deleteTable: table ${t.id}`)}function Kt(e){const t=[];for(let i=0;i<e.rows.length;i++)t[i]=[];for(let i=0;i<t.length;i++){const n=e.rows[i],o=t[i];let s=0;for(let e=0;e<n.cells.length;e++){for(s=e;o[s];)s++;const r=n.cells[e];for(let e=0;e<r.colSpan;e++)for(let n=0;n<r.rowSpan;n++){const o=t[i+n];o&&(o[s+e]=r)}}}return t}function Gt(e,t,i){const n=e[t];for(let e=0;e<n.length;e++){if(n[e]===i)return e}return-1}function Xt(e,t,i){const n=e[t],o=e[t-1];let s=i;for(let e=0;e<i;e++){const t=n[e];if(t===n[e+1])s--;else if(o){t===o[e]&&s--}}return s}function Qt(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0),a=i.get(0),l=r.rowIndex,c=Kt(s);let d=Gt(c,l,a);if("right"===t){const e=c[l];if(d++,e)for(;a===e[d];)d++}g(`insertColumn: rows ${s.rows.length}, column ${d}, ${t}`);for(let e=0;e<s.rows.length;e++){const t=s.rows[e],i=c[e],n=Xt(c,e,d),o=t.cells[n];if(o&&o.colSpan>1&&o===i[d-1])o.colSpan+=1,o.rowSpan>1&&(e+=o.rowSpan-1);else{t.insertCell(n).innerHTML="<p><br /></p>"}}}function Yt(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0);let a=Kt(s);const l=a[0].length;let c;c="up"===t?r.rowIndex:r.rowIndex+1;const d=s.rows[c];g(`insertRow: rows ${s.rows.length}, target row ${c}`);const h=s.insertRow(c);if(!d){for(let e=0;e<l;e++){h.insertCell(h.cells.length).innerHTML="<p><br /></p>"}return}a=Kt(s),c=d.rowIndex;let p=-1;for(let e=0;e<l;e++){const t=Xt(a,c,e);if(t!==p){p=t;const i=d.cells[t];if(!i)break;const n=h.insertCell(h.cells.length);n.innerHTML="<p><br /></p>",i.colSpan>1&&(n.colSpan=i.colSpan,e+=i.colSpan-1)}}for(let e=c-1;e>=0;e--){const t=s.rows[e].cells;for(let i=0;i<t.length;i++){const n=t[i];n.rowSpan>1&&n.rowSpan+1>c-e&&(n.rowSpan+=1)}}}const Jt=[{value:"insertLeft",text:e=>e.table.insertColumnLeft()},{value:"insertRight",text:e=>e.table.insertColumnRight()},{value:"delete",text:e=>e.table.deleteColumn()}],ei=[{value:"insertAbove",text:e=>e.table.insertRowAbove()},{value:"insertBelow",text:e=>e.table.insertRowBelow()},{value:"delete",text:e=>e.table.deleteRow()}],ti=[{value:"up",text:e=>e.table.mergeUp()},{value:"right",text:e=>e.table.mergeRight()},{value:"down",text:e=>e.table.mergeDown()},{value:"left",text:e=>e.table.mergeLeft()}],ii=[{value:"leftRight",text:e=>e.table.splitLeftRight()},{value:"topBottom",text:e=>e.table.splitTopBottom()}];function ni(e,t){const i=[{name:"expand",type:"button",icon:n.get("expand"),tooltip:e=>e.table.fitTable(),isSelected:()=>{const t=e.selection.range.startNode.closest("table");if(0===t.length)return!1;return t.css("width")===e.container.innerWidth()-2+"px"},onClick:()=>{const t=e.selection.range.startNode.closest("table");if(0===t.length)return;const i=t.css("width"),n=e.container.innerWidth()-2+"px";i===n?t.css("width",""):t.css("width",n),e.history.save()}},{name:"backgroundColor",type:"dropdown",downIcon:n.get("down"),icon:n.get("backgroundColor"),accentIcon:n.get("backgroundColorAccent"),defaultValue:t.backgroundColor,tooltip:e=>e.table.cellBackground(),menuType:"color",menuItems:V,menuWidth:"296px",selectedValues:()=>{const t=e.selection.range.startNode.closest("td");if(t.length>0){return[m(t.computedCSS("background-color"))]}return[]},onSelect:(i,n)=>{e.selection.range.startNode.closest("td").css("background-color",n),t.backgroundColor=n,e.history.save()}},{name:"tableColumn",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableColumn"),tooltip:e=>e.table.column(),menuType:"list",menuItems:Jt,menuCheck:!1,onSelect:(t,i)=>{const n=e.selection.range;"insertLeft"===i?Qt(n,"left"):"insertRight"===i?Qt(n,"right"):function(e){const t=e.startNode.closest("td"),i=t.closest("table"),n=t.closest("tr"),o=i.get(0),s=n.get(0),r=t.get(0),a=s.rowIndex,l=Kt(o),c=Gt(l,a,r);let d=null;const h=r.cellIndex;s.cells[h+1]?d=s.cells[h+1]:s.cells[h-1]&&(d=s.cells[h-1]),g(`deleteColumn: rows ${o.rows.length}, column ${c}`);const p=function(e,t){for(let i=0;i<e.length;i++){const n=e[i][t],o=e[i+1];if(o&&n.colSpan!==o[t].colSpan)return!1}return!0}(l,c);for(let t=0;t<o.rows.length;t++){const i=o.rows[t],n=Xt(l,t,c),s=i.cells[n];s.rowSpan>1&&(t+=s.rowSpan-1),s.colSpan>1&&!p?(s.colSpan-=1,1===s.colSpan&&s.removeAttribute("colSpan")):(s===r&&d&&e.shrinkBefore(y(d)),i.deleteCell(n))}0===o.rows[0].cells.length&&Ut(e)}(n),e.history.save()}},{name:"tableRow",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableRow"),tooltip:e=>e.table.row(),menuType:"list",menuItems:ei,menuCheck:!1,onSelect:(t,i)=>{const n=e.selection.range;"insertAbove"===i?Yt(n,"up"):"insertBelow"===i?Yt(n,"down"):function(e){const t=e.startNode.closest("td"),i=t.closest("table"),n=t.closest("tr"),o=i.get(0),s=n.get(0),r=t.get(0),a=s.rowIndex;let l=Kt(o);const c=l[0].length,d=Gt(l,a,r),h=o.rows[a+1]||o.rows[a-1];g(`deleteRow: rows ${o.rows.length}, target row ${a}, column ${d}`);for(let e=a-1;e>=0;e--){const t=o.rows[e].cells;for(let i=0;i<t.length;i++){const n=t[i];n.rowSpan>1&&n.rowSpan>a-e&&(n.rowSpan-=1,1===n.rowSpan&&n.removeAttribute("rowSpan"))}}const p=o.rows[a+1];if(p){let e=-1;for(let t=0;t<c;t++){const i=Xt(l,a,t);if(i!==e){e=i;const n=s.cells[i];if(n.rowSpan>1){const e=Xt(l,a+1,t);let i=p.insertCell(e);const o=n.cloneNode(!0);o.removeAttribute("rowSpan"),i.replaceWith(o),i=o,n.rowSpan>2&&(i.rowSpan=n.rowSpan-1)}}}}if(o.deleteRow(a),h){l=Kt(o);const t=Xt(l,h.rowIndex,d),i=h.cells[t];i&&e.shrinkBefore(y(i))}0===o.rows.length&&Ut(e)}(n),e.history.save()}},{name:"tableMerge",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableMerge"),tooltip:e=>e.table.merge(),menuType:"list",menuItems:ti,menuCheck:!1,onSelect:(t,i)=>{!function(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0),a=i.get(0),l=r.rowIndex,c=Kt(s);if("left"===t||"right"===t){const i=a.cellIndex;let n,o,s;if("left"===t?(n=r.cells[i-1],o=i,s=a):(n=a,o=i+1,s=r.cells[o]),!n||!s)return;if(g(`mergeCells: row ${l}, cell ${i}, other row ${l}, other cell ${o}`),n.rowSpan!==s.rowSpan)return;const d=c[l],h=Gt(c,l,n),p=Gt(c,l,s);if(d[h+1]!==s&&d[p-1]!==n)return;return n.colSpan+=s.colSpan,Me(y(n),y(s)),void e.shrinkBefore(y(n))}const d=Gt(c,l,a);let h,p,u,m,f,v;if("up"===t){h=-1,p=null;for(let e=r.rowIndex-1;e>=0;e--){const t=c[e];if(!t)break;const i=t[d];if(!i)break;if(p&&i!==p)break;h=e,p=i}u=r.rowIndex,m=r,f=a.cellIndex,v=a}else{h=r.rowIndex,p=a,u=-1,v=null,f=-1;for(let e=r.rowIndex+1;e<s.rows.length;e++){const t=c[e];if(!t)break;const i=t[d];if(!i)break;if(i!==v){u=e,v=i,f=v.cellIndex;break}}if(m=s.rows[u],!m)return}p&&v&&(g(`mergeCells: row ${h}, cell ${p.cellIndex}, other row ${u}, other cell ${f}`),p.colSpan===v.colSpan&&(p.rowSpan+=v.rowSpan,Me(y(p),y(v)),e.shrinkBefore(y(p))))}(e.selection.range,i),e.history.save()}},{name:"tableSplit",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableSplit"),tooltip:e=>e.table.split(),menuType:"list",menuItems:ii,menuCheck:!1,onSelect:(t,i)=>{!function(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0),a=i.get(0),l=r.rowIndex,c=a.rowSpan,d=a.colSpan;let h=Kt(s);const p=Gt(h,l,a);if(g(`splitCell: row ${l}, cell ${p}, ${t}`),"topBottom"!==t)for(let e=0;e<h.length;e++){const t=s.rows[e],i=h[e],n=i[p];if(n===a){const i=h[e-1];if(!i||n!==i[p]){const i=Xt(h,e,p),o=t.insertCell(i+1);o.innerHTML="<p><br /></p>",n.rowSpan>1&&(o.rowSpan=n.rowSpan),n.colSpan>2&&(o.colSpan=n.colSpan-1),n.removeAttribute("colSpan")}}else for(let e=p;e>=0;e--)if(0===e||n!==i[e]){1===d&&(n.colSpan+=1);break}}else{const e=h[l];for(let t=0;t<e.length;t++){const i=e[t];if(i===a){const e=c>1?s.rows[l+1]:s.insertRow(l+1),t=Xt(h,l+1,p),i=e.insertCell(t);i.innerHTML="<p><br /></p>",a.colSpan>1&&(i.colSpan=a.colSpan),a.rowSpan>2&&(i.rowSpan=a.rowSpan-1),a.removeAttribute("rowSpan"),h=Kt(s)}else if(1===c){for(let e=l;e>=0;e--){const n=h[e];if(0===e||i!==n[t]){i.rowSpan+=1;break}}h=Kt(s)}i.colSpan>1&&(t+=i.colSpan-1)}}}(e.selection.range,i),e.history.save()}},{name:"remove",type:"button",icon:n.get("remove"),tooltip:e=>e.table.remove(),onClick:()=>{Ut(e.selection.range),e.history.save()}}];return i}const oi={start:"left",end:"right"};function si(e,t){if(e.isList){let i=Number.parseInt(e.attr("indent"),10)||0;if("increase"===t?i++:i--,i<=0)i=0;else if(i>10)return;return 0===i?e.removeAttr("indent"):e.attr("indent",i.toString(10)),void Pe([e])}let i=Number.parseInt(e.css("margin-left"),10)||0;"decrease"!==t||0!==i||""===e.css("text-indent")?("increase"===t?i+=40:i-=40,i<=0&&(i=0),0===i?e.css("margin-left",""):e.css("margin-left",`${i}px`)):e.css("text-indent","")}const ri="strong";const ai="sub";const li="sup";const ci="code";const di="lake-format-painter";function hi(e,t,i,n){return new(i||(i=Promise))((function(o,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function a(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}l((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class pi{constructor(e){this.linkNode=null,this.scrollListener=()=>this.updatePosition(),this.resizeListener=()=>this.updatePosition(),this.config=e||{},this.locale=this.config.locale||he("en-US"),this.container=y(k`
22
+ `),e=this.getContainer()):(e.off("mouseenter"),e.off("mouseleave"),e.off("click")),e.on("mouseenter",(()=>{e.hasClass("lake-box-selected")||e.hasClass("lake-box-focused")||e.hasClass("lake-box-activated")||e.addClass("lake-box-hovered")})),e.on("mouseleave",(()=>{e.removeClass("lake-box-hovered")})),e.on("click",(()=>{g(`Box "${this.name}" (id = ${this.node.id}) value:`),g(this.value)})),"block"===this.type&&this.node.isContentEditable&&e.attr("draggable","true")}get type(){return this.node.attr("type")}get name(){return this.node.attr("name")}get value(){const e=this.node.attr("value");return""===e?{}:JSON.parse(P(e))}set value(e){this.node.attr("value",M(JSON.stringify(e)))}updateValue(e,t){const i=this.value;if("string"==typeof e)i[e]=t;else for(const t of Object.keys(e))i[t]=e[t];this.value=i}getEditor(){const e=this.node.closest("div[contenteditable]"),t=e.length>0?E.get(e.id):void 0;if(!t)throw new Error(`Box "${this.name}" (id=${this.node.id}) is not rendered in the editor.`);return t}getContainer(){return this.node.find(".lake-box-container")}getHTML(){const e=I.get(this.name);return void 0===e?"":void 0===e.html?this.node.outerHTML():e.html(this)}setToolbar(e){const t=this.getEditor();this.event.on("focus",(()=>{this.toolbar&&this.toolbar.unmount(),this.toolbar=new fe({target:this.node,items:e}),this.toolbar.render();const i=t.selection.getActiveItems();this.toolbar.updateState({activeItems:i}),this.event.emit("renderfloatingtoolbar")})),this.event.on("blur",(()=>{this.toolbar&&(this.toolbar.unmount(),this.toolbar=null)}))}render(){const e=I.get(this.name);if(void 0===e)return;this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.initiate();const t=e.render(this);if(void 0!==t){const e=this.getContainer();e.empty(),e.append(t)}g(`Box "${this.name}" (id: ${this.node.id}) rendered`)}unmount(){this.event.emit("blur"),this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.node.empty(),g(`Box "${this.name}" (id: ${this.node.id}) unmounted`)}}function we(e){const t=S(0);if("string"==typeof e){const i=new ve(e);return t.set(i.node.id,i),i}const i=(e=y(e)).closestContainer();if(0===i.length){let i=t.get(e.id);return i||(i=new ve(e),t.set(e.id,i),i)}const n=S(i.id);let o=t.get(e.id);return o?(n.set(e.id,o),t.delete(e.id),o):(o=n.get(e.id),o||(o=new ve(e),n.set(e.id,o),o))}class ye{constructor(e){this.fragment=null!=e?e:document.createDocumentFragment()}get(){return this.fragment}find(e){const t=[];let i=new w(this.fragment.firstChild);for(;i.length>0;)i.matches(e)?t.push(i.get(0)):i.isElement&&i.find(e).each((e=>{t.push(e)})),i=i.next();return new w(t)}append(e){y(e).each((e=>{this.fragment.appendChild(e)}))}}const xe={id:/^[\w-]+$/,class:/^[\w\- ]+$/,style:{"text-align":["left","center","right","justify","start","end"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function be(){return{h1:Object.assign({},xe),h2:Object.assign({},xe),h3:Object.assign({},xe),h4:Object.assign({},xe),h5:Object.assign({},xe),h6:Object.assign({},xe),p:Object.assign({},xe),blockquote:Object.assign(Object.assign({},xe),{type:["info","tip","success","warning","error","danger"]}),ul:Object.assign(Object.assign({},xe),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},xe),{start:/^\d+$/,indent:/^\d+$/}),li:{value:["true","false"]},table:{style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/}},tr:{style:{height:/^-?\d+(px|%)$/i}},th:"td",td:{colspan:/^\d+$/,rowspan:/^\d+$/,style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/,"text-align":["left","center","right","justify"]}},"lake-box":{type:["inline","block"],name:/^[\w-]+$/,value:/^[^"]+$/,focus:["start","center","end"]},br:{},hr:{},img:{src:/^[^"]+$/,width:/^-?\d+px$/i,height:/^-?\d+px$/i,"data-lake-value":/^[^"]+$/,alt:/^[^"]+$/,style:{width:/^-?\d+px$/i,height:/^-?\d+px$/i}},span:{class:/^[\w\- ]+$/,style:{color:/^[^"]+$/,"background-color":/^[^"]+$/,"font-family":/^[^;]+$/,"font-size":/^[^"]+$/}},b:"strong",strong:{},em:"i",i:{},u:{},s:{},sub:{},sup:{},code:{},a:{class:/^[\w\- ]+$/,name:/^[\w-]+$/,href:/^[^"]+$/,target:/^[\w-]+$/,rel:/^[^"]+$/,download:/^[^"]+$/},"lake-bookmark":{type:["anchor","focus"]}}}function ke(e){e=e.replace(/&quot;/gi,'"');const t={},i=/\s*([\w-]+)\s*:([^;]*)(?:;|$)/g;let n;for(;null!==(n=i.exec(e));){const e=n[1].toLowerCase().trim(),i=m(n[2]).trim();t[e]=i}return t}class Ce{constructor(e,t=be()){this.rules=t,this.source="string"==typeof e?this.parseHTML(e):e}parseHTML(e){const t=(new DOMParser).parseFromString(e,"text/html");return new w(t.querySelector("body"))}static matchRule(e,t){return"string"==typeof e?e===t:Array.isArray(e)?e.indexOf(t)>=0:e instanceof RegExp&&e.test(t)}static getOpenTagString(e,t){let i=e.name,n=t[i];if(!n)return"";"string"==typeof n&&(i=n,n=t[i]);const o=e.get(0);if(!o.hasAttributes())return i;const s=new Map;for(const e of o.attributes)if(n[e.name]&&("style"!==e.name&&Ce.matchRule(n[e.name],e.value)&&s.set(e.name,e.value),"style"===e.name)){const t=n.style,i=new Map,o=ke(e.value);for(const e of Object.keys(o)){const n=o[e];t[e]&&Ce.matchRule(t[e],n)&&i.set(e,n)}s.set("style",i)}let r=i;for(const[e,t]of s)if("style"===e){let e="";for(const[i,n]of t)e+=`${i}: ${n.replace(/"/g,"&quot;")}; `;""!==e&&(r+=` style="${e.trim()}"`)}else r+=` ${e}="${t}"`;return r}static getClosedTagString(e,t){let i=e.name;const n=t[i];return n?("string"==typeof n&&(i=n),i):""}static getTrimmedText(e){const t=e.parent(),i=e.prev(),n=e.next();let o=e.text();return(i.isBlock||i.isBlockBox)&&(n.isBlock||n.isBlockBox)||0===i.length&&0===n.length&&t.isBlock?o=o.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):i.isBlock||i.isBlockBox||0===i.length&&t.isBlock?o=o.replace(/^[\u0020\t\r\n]+/,""):(n.isBlock||n.isBlockBox||0===n.length&&t.isBlock)&&(o=o.replace(/[\u0020\t\r\n]+$/,"")),o}getHTML(){const e=this.rules;let t="";for(const i of function*t(i){let n=i.first();for(;n.length>0;){const i=n.next();if(n.isText)yield b(Ce.getTrimmedText(n));else if(n.isVoid){const t=Ce.getOpenTagString(n,e);""!==t&&(yield`<${t} />`)}else if(n.isElement){const i=Ce.getOpenTagString(n,e),o=Ce.getClosedTagString(n,e);""!==i&&(yield`<${i}>`),n.isBox||(yield*t(n)),""!==o&&(yield`</${o}>`)}n=i}}(this.source))t+=i;return t.trim()}getFragment(){const e=this.getHTML(),t=this.parseHTML(e),i=document.createDocumentFragment();let n=t.first();for(;n.length>0;){const e=n.next();i.appendChild(n.get(0)),n=e}return i}}class Se{constructor(e){this.content=e}getHTML(){let e=this.content;return e=e.replace(/ {2}/g,"  "),e=b(e.trim()),e=`<p>${e}</p>`,e=e.replace(/(\r\n){2,}/g,"</p><p><br /></p><p>"),e=e.replace(/\r\n/g,"</p><p>"),e=e.replace(/[\r\n]{2,}/g,"</p><p><br /></p><p>"),e=e.replace(/[\r\n]/g,"</p><p>"),e}getFragment(){return new Ce(this.getHTML()).getFragment()}}function Be(e,t){const i=e.get(),n=t.get(0);i.insertNode(n),i.setEndAfter(n),i.collapse(!1)}function Ae(e){if(e.commonAncestor.isOutside)return{anchor:new w,focus:new w};const t=e.startNode.closest("lake-box");if(t.length>0)return e.isBoxStart?t.attr("focus","start"):e.isBoxEnd?t.attr("focus","end"):t.attr("focus","center"),{anchor:new w,focus:t};if(e.isCollapsed){const t=e.clone();t.collapseToEnd();const i=y('<lake-bookmark type="focus" />');return Be(t,i),{anchor:new w,focus:i}}const i=e.clone();i.collapseToStart();const n=y('<lake-bookmark type="anchor" />');Be(i,n);const o=e.clone();o.collapseToEnd();const s=y('<lake-bookmark type="focus" />');return Be(o,s),{anchor:n,focus:s}}function _e(e,t){const i=e.prev(),n=e.next();if(i.isText||n.isText){const t=e.parent();e.remove(),t.get(0).normalize()}else if(0===i.length&&0===n.length){if(e.parent().isMark&&t){const i=new w(document.createTextNode("​"));e.before(i),t.setStartAfter(i),t.collapseToStart()}e.remove()}else e.remove()}function Le(e,t){const i=t.anchor,n=t.focus;if(i.length>0&&0===n.length)_e(i);else{if(n.length>0&&0===i.length){if(n.isBox){const t=we(n);0===t.getContainer().length&&t.render();const i=n.attr("focus");return"start"===i?e.selectBoxStart(n):"center"===i?e.selectBox(n):e.selectBoxEnd(n),void n.removeAttr("focus")}return e.setStartBefore(n),e.collapseToStart(),void _e(n,e)}if(i.length>0&&n.length>0){const t=new Z;t.selectNode(i),t.collapseToEnd(),-1===t.compareAfterNode(n)?(e.setStartBefore(n),_e(n),e.setEndBefore(i),_e(i)):(e.setStartBefore(i),_e(i),e.setEndBefore(n),_e(n))}}}function Te(e){if(0===e.length)return;const t=[];let i=e.first();for(;i.length>0;){const e=i.next();i.isText&&""===i.text()||t.push(i),i=e}(1===t.length&&"br"===t[0].name||2===t.length&&"br"===t[0].name&&t[1].isBookmark)&&t[0].remove(),2===t.length&&t[0].isBookmark&&"br"===t[1].name&&t[1].remove()}function Ie(e){const t=y("<br />");let i=e;for(;i.isBlock;){let e=i.last();for(;e.isText&&e.isEmpty;)e=e.prev();if(!e.isBlock&&"br"!==e.name){i.append(t);break}i=e}return t}function Ee(e){if(e.isText)return{node:e,offset:e.text().length};const t=new Z;return t.setEndAfter(e),{node:t.endNode,offset:t.endOffset}}function Me(e,t){const i=t;if(["ul","ol"].indexOf(e.name)>=0){const t=e.find("li");e=t.eq(t.length-1)}if(["ul","ol"].indexOf(t.name)>=0){const e=t.find("li");t=e.eq(0)}if(e.isText||t.isText||e.isVoid||t.isVoid)return Ee(e);Te(e),Te(t),e.isBlock&&e.isEmpty&&t.isEmpty&&Ie(e);const n=e.last(),o=t.first();let s=o;for(;s.length>0;){const t=s.next();e.append(s),s=t}return i.remove(),n.length>0&&o.length>0&&n.isElement&&!n.isBox&&n.clone(!1).get(0).isEqualNode(o.clone(!1).get(0))?Me(n,o):0===n.length?{node:e,offset:0}:Ee(n)}function Pe(e){if(0===e.length)return;const t=e[0],i=e[e.length-1],n=[];let o=t.prev();for(;o.length>0&&"ol"===o.name;)n.push(o),o=o.prev();n.reverse(),n.push(...e);let s=i.next();for(;s.length>0&&"ol"===s.name;)n.push(s),s=s.next();let r=1;for(const e of n){const t=e.prev();if(0!==t.length&&"ol"===t.name||(r=1),"ol"===e.name){"ol"===t.name&&t.attr("indent")!==e.attr("indent")&&(r=1);const i=e.attr("start"),n=r.toString(10);i!==n&&e.attr("start",n),r++}}}function He(e){if(e.isCollapsed)return;if(e.adjustBox(),e.adjustTable(),e.isInoperative)return;const t=e.startNode.closestBlock(),i=e.endNode.closestBlock(),n=t.get(0)===i.get(0);if(e.get().deleteContents(),e.adjustBlock(),n){const t=e.getBlocks()[0];if(t&&t.isEmpty){const i=Ie(t);e.setStartBefore(i),e.collapseToStart()}return}const o=e.getBlocks()[0];if(!o)return;const s=o.prev();if(0===s.length)return;const r=Ae(e);Me(s,o),Pe([s]),Le(e,r)}function Ze(e,t){if(e.commonAncestor.isOutside)return;let i;t instanceof ye?i=t:t instanceof DocumentFragment?i=new ye(t):(i=new ye,i.append(t)),e.isCollapsed?e.adjustBox():He(e);Te(e.startNode.closestBlock());const n=e.get();n.insertNode(i.get()),n.collapse(!1),e.adjustBlock()}function De(e){let t=e;for(;t.length>0;){let e=t.first();if(e.isText&&e.isEmpty&&(e=e.next()),t.isElement&&!t.isVoid&&0===e.length)break;t=e}return t}function Ne(e,t){if(t=null!=t?t:y("<p />"),0===e.length)return t;const i=De(t=t.clone(!0));e[0].before(t);for(const t of e)i.append(t);return t}function ze(e,t){if(e.commonAncestor.isOutside)return;if(e.isCollapsed){if(e.commonAncestor.closest("lake-box").isBlockBox)return}if("string"!=typeof t){const i=e.getBlocks();for(const e of i)e.css(t);return}const i=y(t),n=i.name,o=i.get(0).attributes,s=e.getBlocks();if(s.length>0){const t=Ae(e);for(const e of s)if(e.name===n&&0===i.first().length)for(const t of o)e.attr(t.name,t.value);else{const t=i.clone(!0);t.isList&&e.isList&&""!==e.attr("indent")&&t.attr("indent",e.attr("indent"));const n=De(t);let o=e.first();for(;o.length>0;){const e=o.next();n.append(o),n.name!==o.name&&"li"!==o.name||o.remove(!0),o=e}e.replaceWith(t)}return Le(e,t),void Pe(e.getBlocks())}if(e.isCollapsed){const t=e.getNextNode();if("br"===t.name){const i=y("<p><br /></p>");return t.replaceWith(i),void e.shrinkBefore(i)}const i=e.getPrevNode();if("br"===i.name){const t=y("<p><br /></p>");return i.replaceWith(t),void e.shrinkBefore(t)}}const r=Ae(e),a=function(e){const t=e.commonAncestor.closest('div[contenteditable="true"],td');let i=[];if(0===t.length)return i;let n=t.first(),o=!0;for(;n.length>0;){if(n.isMark||n.isText||n.isBookmark||n.isInlineBox)i.push(n);else{if(!o)break;i=[]}e.intersectsNode(n)&&(o=!1),n=n.next()}return i}(e),l=Ne(a,i);if(Le(e,r),Pe(e.getBlocks()),l.isEmpty){const t=Ie(l);e.setStartBefore(t),e.collapseToStart()}}function Oe(e,t,i){const n=new Z;let o;if(e.isText){o=e.parent();const i=e.splitText(t);n.setStartAfter(e),""===e.text()&&e.remove(),""===i.text()&&i.remove()}else n.setStart(e,t),o=e;if("body"===o.name||"html"===o.name)return null;if(o.get(0)===i.get(0))return null;n.collapseToStart();const s=o.clone();let r=o.first();for(;r.length>0&&!(n.compareBeforeNode(r)>=0);){const e=r.next();s.append(r),r=e}return o.before(s),o.parent().length>0&&o.parent().get(0)!==i.get(0)?Oe(o.parent(),o.index(),i):{start:s,end:o}}function $e(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function Ve(e){if(e.commonAncestor.isOutside)return{start:null,end:null};e.isCollapsed?e.adjustBox():He(e);const t=e.startNode,i=t.closestOperableBlock();if(0===i.length)return{start:null,end:null};let n=i.parent();n.isOutside&&(n=t.closestContainer());const o=Oe(t,e.startOffset,n);let s=null,r=null;return o&&(s=o.start,r=o.end),!o&&t.isBlock&&(e.startOffset>0&&(s=t.children()[e.startOffset-1]),r=t.children()[e.startOffset],r&&!r.isBlock&&(r=null)),s&&s.isEmpty&&($e(s),Ie(s)),r&&(r.isEmpty&&($e(r),Ie(r)),e.shrinkBefore(r)),Pe(e.getBlocks()),{start:s,end:r}}function Re(e,t){if(e.commonAncestor.isOutside)return null;const i=y(t),n=Ve(e);return n.start&&($e(n.start),e.setEndAfter(n.start),e.collapseToEnd()),n.end&&($e(n.end),n.end.isEmpty&&n.end.remove()),Ze(e,i),i.isBox||e.shrinkAfter(i),n.start&&n.start.isEmpty&&n.start.remove(),i}function Fe(e,t,i){let n=null,o=null,s=e.closestBlock();0===s.length&&(s=e.closestContainer());const r=Oe(e,t,s);return r&&(i?($e(r.start),$e(r.end),r.start.isEmpty||(n=r.start),r.end.isEmpty||(o=r.end)):(n=r.start,o=r.end)),{start:n,end:o}}function We(e,t=!0){if(e.commonAncestor.isOutside)return{start:null,center:null,end:null};if(e.adjustBox(),e.isCollapsed){const i=Fe(e.startNode,e.startOffset,t);return i.start?(e.setStartAfter(i.start),e.collapseToStart()):i.end&&(e.setStartBefore(i.end),e.collapseToStart()),{start:i.start,center:null,end:i.end}}const i=Fe(e.startNode,e.startOffset,t);i.start?e.setStartAfter(i.start):i.end&&e.setStartBefore(i.end);const n=Fe(e.endNode,e.endOffset,t);return n.start?e.setEndAfter(n.start):n.end&&e.setEndBefore(n.end),{start:i.start,center:n.start,end:n.end}}function je(e,t){const i=e.text();let n=e;for(;n.length>0;){const e=n.parent();if(!e.isMark||i!==e.text()||!n.isText&&n.name===t&&""!==n.attr("style"))break;n=e}return n}function qe(e,t){if(e.commonAncestor.isOutside)return;let i=y(t);const n=i.name,o=ke(i.attr("style"));if(e.isCollapsed){if(e.isBox){const t=e.startNode.closest("lake-box");if("block"===we(t).type){const i=y("<p><br /></p>");e.isBoxStart?t.before(i):t.after(i),e.shrinkAfter(i)}else e.adjustBox()}Te(e.startNode.closestBlock());const t=new w(document.createTextNode("​")),s=function(e){let t=e;t.isText&&(t=t.parent());let i=null;for(;t.length>0&&t.isMark;){if(i){const e=t.clone();e.append(i),i=e}else i=t.clone();t=t.parent()}return i}(e.startNode);if(We(e),s){let e=s;for(;e.length>0;)e.name===n&&e.css(o),e=e.first();s.name===n?i=s:i.append(s)}if(""===i.text()){De(i).append(t)}return Ze(e,i),function(e){const t=e.prev();t.length>0&&t.isText&&t.isEmpty&&t.remove();const i=e.next();i.length>0&&i.isText&&i.isEmpty&&i.remove()}(i),void e.shrinkAfter(i)}We(e);const s=e.getMarks(!0),r=Ae(e);for(const e of s)if(!e.isEmpty&&e.isText){const t=je(e,n);if(t.isMark&&t.name===n)t.css(o);else{const e=i.clone();t.before(e),e.append(t)}}Le(e,r)}function Ue(e,t){if(e.commonAncestor.isOutside)return;let i;if(t){i=y(t).name}if(e.isCollapsed){if(e.isBox)return;if(i&&0===e.commonAncestor.closest(i).length)return;const t=We(e,!1);if(!t.start)return;t.end&&$e(t.end);const n=new w(document.createTextNode("​")),o=function(e,t){if(!e.isMark||!t)return null;let i=null,n=null,o=e;for(;o.length>0&&o.isMark;){if(o.name!==t)if(n){const e=o.clone();n.append(e),n=e}else i=o.clone(),n=i;o=o.last()}return i}(t.start,i);if(!o)return t.start.after(n),$e(t.start),n.prev().isText?(e.setStartAfter(n.prev()),e.collapseToStart(),void n.remove()):(e.setStartAfter(n),void e.collapseToStart());return De(o).append(n),t.start.after(o),$e(t.start),void e.shrinkAfter(o)}We(e);const n=e.getMarks(),o=Ae(e);for(const e of n)if(!i||e.name===i){const t=e.parent();e.remove(!e.isEmpty),t.length>0&&t.get(0).normalize()}!function(e){for(const t of e.getWalker())if(t.isText){const e=t.text();""===e?t.remove():e.length>1&&/\u200B/.test(e)&&(t.get(0).nodeValue=e.replace(/\u200B/g,""))}}(e.commonAncestor),Le(e,o)}function Ke(e,t,i){if(e.commonAncestor.isOutside)return null;const n=we(t);if(i&&(n.value=i),"inline"===n.type){if(We(e),Ze(e,n.node),n.render(),n.node.isTopInside){const e=y("<p />");n.node.before(e),e.append(n.node)}return e.selectBoxEnd(n.node),we(n.node)}return Re(e,n.node),n.render(),e.selectBoxEnd(n.node),we(n.node)}function Ge(e){const t=e.node.closestContainer();if(e.unmount(),e.node.remove(),t.length>0){S(t.id).delete(e.node.id);S(0).set(e.node.id,e)}return e}function Xe(e){if(e.commonAncestor.isOutside)return null;const t=e.commonAncestor.closest("lake-box");if(0===t.length)return null;const i=we(t);if("block"===i.type){const n=y("<p><br /></p>");return t.before(n),e.shrinkAfter(n),Ge(i)}e.setStartBefore(t),e.collapseToStart();const n=t.parent();if(Ge(i),n.isEmpty){const t=Ie(n);e.setStartBefore(t),e.collapseToStart()}return i}var Qe,Ye={exports:{}};function Je(){if(Qe)return Ye.exports;function e(e,t=100,i={}){if("function"!=typeof e)throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw new RangeError("`wait` must not be negative.");const{immediate:n}="boolean"==typeof i?{immediate:i}:i;let o,s,r,a,l;function c(){const t=o,i=s;return o=void 0,s=void 0,l=e.apply(t,i),l}function d(){const e=Date.now()-a;e<t&&e>=0?r=setTimeout(d,t-e):(r=void 0,n||(l=c()))}const h=function(...e){if(o&&this!==o&&Object.getPrototypeOf(this)===Object.getPrototypeOf(o))throw new Error("Debounced method called with different contexts of the same prototype.");o=this,s=e,a=Date.now();const i=n&&!r;return r||(r=setTimeout(d,t)),i&&(l=c()),l};return Object.defineProperty(h,"isPending",{get:()=>void 0!==r}),h.clear=()=>{r&&(clearTimeout(r),r=void 0)},h.flush=()=>{r&&h.trigger()},h.trigger=()=>{l=c(),h.clear()},h}return Qe=1,Ye.exports.debounce=e,Ye.exports=e,Ye.exports}var et,tt,it=B(Je());var nt=B(tt?et:(tt=1,et=function e(t,i){if(t===i)return!0;if(t&&i&&"object"==typeof t&&"object"==typeof i){if(t.constructor!==i.constructor)return!1;var n,o,s;if(Array.isArray(t)){if((n=t.length)!=i.length)return!1;for(o=n;0!=o--;)if(!e(t[o],i[o]))return!1;return!0}if(t instanceof Map&&i instanceof Map){if(t.size!==i.size)return!1;for(o of t.entries())if(!i.has(o[0]))return!1;for(o of t.entries())if(!e(o[1],i.get(o[0])))return!1;return!0}if(t instanceof Set&&i instanceof Set){if(t.size!==i.size)return!1;for(o of t.entries())if(!i.has(o[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(i)){if((n=t.length)!=i.length)return!1;for(o=n;0!=o--;)if(t[o]!==i[o])return!1;return!0}if(t.constructor===RegExp)return t.source===i.source&&t.flags===i.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===i.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===i.toString();if((n=(s=Object.keys(t)).length)!==Object.keys(i).length)return!1;for(o=n;0!=o--;)if(!Object.prototype.hasOwnProperty.call(i,s[o]))return!1;for(o=n;0!=o--;){var r=s[o];if(!e(t[r],i[r]))return!1}return!0}return t!=t&&i!=i}));function ot(e){return e.replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"<anchor />").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"<focus />")}function st(e){return e.replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box>|$)/gi,"$1</lake-box>").replace(/<anchor\s*\/>/gi,'<lake-bookmark type="anchor"></lake-bookmark>').replace(/<focus\s*\/>/gi,'<lake-bookmark type="focus"></lake-bookmark>')}function rt(e){const t=e.get(0),i={};if(t.hasAttributes())for(const e of t.attributes)i[e.name]=e.value;return i}class at{constructor(e){const t=window.getSelection();if(!t)throw new Error("Selection object is null.");this.selection=t,this.container=e,this.range=this.getCurrentRange()}getCurrentRange(){if(this.selection.rangeCount>0){const e=this.selection.getRangeAt(0);return new Z(e)}return new Z}sync(){this.container.contains(this.range.commonAncestor)&&(this.selection.removeAllRanges(),this.selection.addRange(this.range.get()))}updateByRange(){const e=this.getCurrentRange();this.container.contains(e.commonAncestor)&&(this.range.startNode.get(0)===e.startNode.get(0)&&this.range.startOffset===e.startOffset&&this.range.endNode.get(0)===e.endNode.get(0)&&this.range.endOffset===e.endOffset||(this.range=e))}updateByBookmark(){const e=this.range,t=this.container,i=t.find("lake-box[focus]");if(i.length>0)return Le(e,{anchor:new w,focus:i}),void this.sync();Le(e,{anchor:t.find('lake-bookmark[type="anchor"]'),focus:t.find('lake-bookmark[type="focus"]')}),this.sync()}getActiveItems(){const e=[];return function(e,t){let i=t.startNode;for(i.isText&&(i=i.parent());i.length>0&&i.isContentEditable&&!i.isContainer;)e.push({node:i,name:i.name,attributes:rt(i),styles:ke(i.attr("style"))}),i=i.parent()}(e,this.range),function(e,t){const i=t.startNode;let n;if(i.isText&&i.text().length===t.startOffset){const e=i.next();e.length>0&&e.isElement&&(n=e)}if(i.isElement){const e=i.children();if(e.length>0){const i=e[t.startOffset];i&&i.isElement&&(n=i)}}if(n){let t=n;for(;t.length>0;)t.isElement&&e.push({node:t,name:t.name,attributes:rt(t),styles:ke(t.attr("style"))}),t=t.first()}}(e,this.range),e}insertBookmark(){return Ae(this.range)}toBookmark(e){return Le(this.range,e)}insertContents(e){return Ze(this.range,e)}deleteContents(){return He(this.range)}setBlocks(e){return ze(this.range,e)}splitBlock(){return Ve(this.range)}insertBlock(e){return Re(this.range,e)}splitMarks(e){return We(this.range,e)}addMark(e){return qe(this.range,e)}removeMark(e){return Ue(this.range,e)}selectBox(e){let t=e;t=e instanceof ve?e.node:e,this.range.selectBox(t),this.sync()}insertBox(e,t){const i=Ke(this.range,e,t);if(!i)throw new Error(`Box "${e}" cannot be inserted into the outside of the editor.`);return i}removeBox(e=null){return e&&this.selectBox(e),Xe(this.range)}}class lt{constructor(e){this.commandMap=new Map,this.selection=e}add(e,t){this.commandMap.set(e,t)}delete(e){this.commandMap.delete(e)}getNames(){return Array.from(this.commandMap.keys())}has(e){return void 0!==this.commandMap.get(e)}getItem(e){const t=this.commandMap.get(e);if(void 0===t)throw new Error(`Command "${e}" has not been defined yet.`);return t}isDisabled(e){const t=this.getItem(e);if(!t.isDisabled)return!1;const i=this.selection.getActiveItems();return t.isDisabled(i)}isSelected(e){const t=this.getItem(e);if(!t.isSelected)return!1;const i=this.selection.getActiveItems();return t.isSelected(i)}selectedValues(e){const t=this.getItem(e);if(!t.selectedValues)return[];const i=this.selection.getActiveItems();return t.selectedValues(i)}execute(e,...t){const i=this.selection.container,n=this.selection.range;i.contains(n.commonAncestor)||n.shrinkAfter(i);this.getItem(e).execute.apply(this,t),g(`Command "${e}" executed`)}}const ct=new Set;function dt(){}const ht={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:dt,afterNodeAdded:dt,beforeNodeMorphed:dt,afterNodeMorphed:dt,beforeNodeRemoved:dt,afterNodeRemoved:dt,beforeAttributeUpdated:dt,afterAttributeUpdated:dt,beforeChildrenUpdated:dt},head:{style:"merge",shouldPreserve:e=>"true"===e.getAttribute("im-preserve"),shouldReAppend:e=>"true"===e.getAttribute("im-re-append"),shouldRemove:dt,afterHeadMorphed:dt}};function pt(e,t){return!e.deadIds.has(t)}function ut(e,t,i){return(e.idMap.get(i)||ct).has(t)}function mt(e,t){const i=e.idMap.get(t)||ct;for(const t of i)e.deadIds.add(t)}function gt(e,t,i){const n=e.idMap.get(t)||ct;let o=0;for(const t of n)pt(e,t)&&ut(e,t,i)&&++o;return o}function ft(e,t){const i=e.parentElement,n=e.querySelectorAll("[id]");for(const e of n){let n=e;for(;n!==i&&null!=n;){let i=t.get(n);null==i&&(i=new Set,t.set(n,i)),i.add(e.id),n=n.parentElement}}}function vt(e,t){const i=new Map;return ft(e,i),ft(t,i),i}function wt(e,t,i){return{target:e,newContent:t,config:i=function(e){const t={};return Object.assign(t,ht),Object.assign(t,e),t.callbacks={},Object.assign(t.callbacks,ht.callbacks),Object.assign(t.callbacks,e.callbacks),t.head={},Object.assign(t.head,ht.head),Object.assign(t.head,e.head),t}(i),morphStyle:i.morphStyle,ignoreActive:i.ignoreActive,ignoreActiveValue:i.ignoreActiveValue,idMap:vt(e,t),deadIds:new Set,callbacks:i.callbacks,head:i.head}}function yt(e,t,i){return null!=e&&null!=t&&(e.nodeType===t.nodeType&&e.tagName===t.tagName&&(""!==e.id&&e.id===t.id||gt(i,e,t)>0))}function xt(e,t){return null!=e&&null!=t&&(e.nodeType===t.nodeType&&e.tagName===t.tagName)}function bt(e,t){mt(t,e),!1!==t.callbacks.beforeNodeRemoved(e)&&(e.remove(),t.callbacks.afterNodeRemoved(e))}function kt(e,t,i){let n=e;for(;n&&n!==t;){const e=n;n=n.nextSibling,bt(e,i)}return mt(i,t),t.nextSibling}function Ct(e,t,i,n,o){const s=gt(o,i,t);let r=null;if(s>0){r=n;let t=0;for(;null!=r;){if(yt(i,r,o))return r;if(t+=gt(o,r,e),t>s)return null;r=r.nextSibling}}return r}function St(e,t,i,n,o){let s=n,r=i.nextSibling,a=0;for(;null!=s;){if(gt(o,s,e)>0)return null;if(xt(i,s))return s;if(xt(r,s)&&(a++,r=r?r.nextSibling:null,a>=2))return null;s=s?s.nextSibling:null}return s}function Bt(e,t,i){return xt(e,t)?.5+gt(i,e,t):0}function At(e,t,i,n){return!("value"!==e||!n.ignoreActiveValue||t!==document.activeElement)||!1===n.callbacks.beforeAttributeUpdated(e,t,i)}function _t(e,t,i){var n;if(!i.ignoreActive||e!==document.activeElement)return null==t?!1===i.callbacks.beforeNodeRemoved(e)?e:(e.remove(),i.callbacks.afterNodeRemoved(e),null):xt(e,t)?(!1===i.callbacks.beforeNodeMorphed(e,t)||(function(e,t,i){const n=e.nodeType;if(1===n){const n=e.attributes,o=t.attributes;for(const e of n)At(e.name,t,"update",i)||t.getAttribute(e.name)!==e.value&&(t.setAttribute(e.name,e.value),i.callbacks.afterAttributeUpdated(e.name,t,"update"));for(let n=o.length-1;n>=0;n--){const s=o[n];At(s.name,t,"remove",i)||e.hasAttribute(s.name)||(t.removeAttribute(s.name),i.callbacks.afterAttributeUpdated(s.name,t,"remove"))}}8!==n&&3!==n||t.nodeValue!==e.nodeValue&&(t.nodeValue=e.nodeValue)}(t,e,i),!1===i.callbacks.beforeChildrenUpdated(e,t)||function(e,t){return t.ignoreActiveValue&&e===document.activeElement}(e,i)||Lt(t,e,i),i.callbacks.afterNodeMorphed(e,t)),e):!1===i.callbacks.beforeNodeRemoved(e)||!1===i.callbacks.beforeNodeAdded(t)?e:(null===(n=e.parentElement)||void 0===n||n.replaceChild(t,e),i.callbacks.afterNodeAdded(t),i.callbacks.afterNodeRemoved(e),t)}function Lt(e,t,i){let n,o=e.firstChild,s=t.firstChild;for(;o;){if(n=o,o=n.nextSibling,null==s){if(!1===i.callbacks.beforeNodeAdded(n))return;t.appendChild(n),i.callbacks.afterNodeAdded(n),mt(i,n);continue}if(yt(n,s,i)){_t(s,n,i),s=s.nextSibling,mt(i,n);continue}const r=Ct(e,t,n,s,i);if(r){s=kt(s,r,i),_t(r,n,i),mt(i,n);continue}const a=St(e,0,n,s,i);if(a)s=kt(s,a,i),_t(a,n,i),mt(i,n);else{if(!1===i.callbacks.beforeNodeAdded(n))return;t.insertBefore(n,s),i.callbacks.afterNodeAdded(n),mt(i,n)}}for(;null!==s;){const e=s;s=s.nextSibling,bt(e,i)}}function Tt(e,t,i){if("innerHTML"===i.morphStyle)return Lt(t,e,i),e.children;const n=function(e,t,i){let n;n=e.firstChild;let o=n,s=0;for(;n;){const e=Bt(n,t,i);e>s&&(o=n,s=e),n=n.nextSibling}return o}(t,e,i),o=null==n?void 0:n.previousSibling,s=null==n?void 0:n.nextSibling,r=_t(e,n,i);return n?function(e,t,i){var n,o;const s=[],r=[];let a=e;for(;null!=a;)s.push(a),a=a.previousSibling;for(;s.length>0;){const e=s.pop();r.push(e),e&&(null===(n=t.parentElement)||void 0===n||n.insertBefore(e,t))}r.push(t);let l=i;for(;null!=l;)s.push(l),r.push(l),l=l.nextSibling;for(;s.length>0;){const e=s.pop();e&&(null===(o=t.parentElement)||void 0===o||o.insertBefore(e,t.nextSibling))}return r}(o,r,s):[]}function It(e,t,i={}){const n=function(e){if(null==e)return document.createElement("div");if(e instanceof Node){if(e.generatedByIdiomorph)return e;const t=document.createElement("div");return t.append(e),t}const t=document.createElement("div");for(const i of[...e])t.append(i);return t}(t.get(0)),o=wt(e.get(0),n,i);Tt(e.get(0),n,o)}class Et{constructor(e){this.canSave=!0,this.list=[],this.index=0,this.limit=100,this.event=new T,this.selection=e,this.container=e.container}removeBookmark(e){return e.replace(/(<lake-box[^>]+)\sfocus="\w+"([^>]*>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"")}getValue(e){return new Ce(e).getHTML()}addIdToBoxes(e){e.find("lake-box").each((e=>{const t=new w(e),i=`${t.attr("name")}-${t.attr("value")}`;t.attr("id",i)}))}removeIdfromBoxes(e){e.find("lake-box").each((e=>{new w(e).removeAttr("id")}))}morphContainer(e){const t=this.container,i={beforeChildrenUpdated:e=>{if("lake-box"===new w(e).name)return!1},afterAttributeUpdated:(e,i)=>{const n=new w(i);if(["name","value"].indexOf(e)>=0&&"lake-box"===n.name){we(n).unmount();S(t.id).delete(n.id)}}},n=e.clone(!0);this.addIdToBoxes(t),this.addIdToBoxes(n),It(t,n,{callbacks:i}),this.removeIdfromBoxes(t),this.removeIdfromBoxes(n)}get canUndo(){return this.index>1&&!!this.list[this.index-2]}get canRedo(){return!!this.list[this.index]}cloneContainer(){const e=this.selection.range,t=this.container.clone(!0);if(t.find("lake-box").each((e=>{we(e).getContainer().empty()})),!this.container.contains(e.commonAncestor))return t;if(e.isInsideBox){const i=e.commonAncestor.closest("lake-box").path(),n=t.find(i),o=e.clone();return o.selectBox(n),Ae(o),t}const i=e.startNode.path(),n=e.endNode.path(),o=t.find(i),s=t.find(n),r=e.clone();return r.setStart(o,e.startOffset),r.setEnd(s,e.endOffset),Ae(r),t}undo(){if(!this.list[this.index-2])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index>1;){const t=this.list[this.index-2];if(!t)break;this.index--;const i=this.getValue(t);if(this.removeBookmark(i)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("undo",i);break}}this.selection.updateByBookmark(),g(`History undone (index: ${this.index})`)}redo(){if(!this.list[this.index])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index<this.list.length;){const t=this.list[this.index];if(!t)break;this.index++;const i=this.getValue(t);if(this.removeBookmark(i)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("redo",i);break}}this.selection.updateByBookmark(),g(`History redone (index: ${this.index})`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(e={}){var t,i,n;const o=null!==(t=e.inputType)&&void 0!==t?t:"",s=null!==(i=e.update)&&void 0!==i&&i,r=null===(n=e.emitEvent)||void 0===n||n;if(!this.canSave)return;const a=this.cloneContainer(),l=this.getValue(a);this.list[this.index-1]&&this.removeBookmark(this.getValue(this.list[this.index-1]))===this.removeBookmark(l)||(s?this.list.splice(this.index-1,1/0,a):(this.list.splice(this.index,1/0,a),this.index++),this.list.length>this.limit&&(this.list.shift(),this.index=this.list.length),g(`History saved (index: ${this.index}, inputType: "${o}", update: ${s}, emitEvent: ${r})`),r&&this.event.emit("save",ot(l),{inputType:o,update:s,emitEvent:r}))}}var Mt,Pt={};var Ht=function(){if(Mt)return Pt;Mt=1,Object.defineProperty(Pt,"__esModule",{value:!0});for(var e="undefined"!=typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.platform),t={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},i={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:e?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},n={backspace:8,tab:9,enter:13,shift:16,control:17,alt:18,pause:19,capslock:20,escape:27," ":32,pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,insert:45,delete:46,meta:91,numlock:144,scrolllock:145,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},o=1;o<20;o++)n["f"+o]=111+o;function s(e,t,i){t&&!("byKey"in t)&&(i=t,t=null),Array.isArray(e)||(e=[e]);var n=e.map((function(e){return r(e,t)})),o=function(e){return n.some((function(t){return a(t,e)}))};return null==i?o:o(i)}function r(e,o){var s=o&&o.byKey,r={},a=(e=e.replace("++","+add")).split("+"),d=a.length;for(var h in t)r[t[h]]=!1;var p=!0,u=!1,m=void 0;try{for(var g,f=a[Symbol.iterator]();!(p=(g=f.next()).done);p=!0){var v=g.value,w=v.endsWith("?")&&v.length>1;w&&(v=v.slice(0,-1));var y=c(v),x=t[y];if(v.length>1&&!x&&!i[v]&&!n[y])throw new TypeError('Unknown modifier: "'+v+'"');1!==d&&x||(s?r.key=y:r.which=l(v)),x&&(r[x]=!w||null)}}catch(e){u=!0,m=e}finally{try{!p&&f.return&&f.return()}finally{if(u)throw m}}return r}function a(e,t){for(var i in e){var n=e[i],o=void 0;if(null!=n&&((null!=(o="key"===i&&null!=t.key?t.key.toLowerCase():"which"===i?91===n&&93===t.which?91:t.which:t[i])||!1!==n)&&o!==n))return!1}return!0}function l(e){return e=c(e),n[e]||e.toUpperCase().charCodeAt(0)}function c(e){return e=e.toLowerCase(),e=i[e]||e}return Pt.default=s,Pt.isHotkey=s,Pt.isCodeHotkey=function(e,t){return s(e,t)},Pt.isKeyHotkey=function(e,t){return s(e,{byKey:!0},t)},Pt.parseHotkey=r,Pt.compareHotkey=a,Pt.toKeyCode=l,Pt.toKeyName=c,Pt}();class Zt{constructor(e){this.keydownEventList=[],this.keyupEventList=[],this.container=e,this.container.on("keydown",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keydownEventList)if(Ht.isKeyHotkey(e.type,t)&&!1===e.listener(t))break})),this.container.on("keyup",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keyupEventList)if(Ht.isKeyHotkey(e.type,t)&&!1===e.listener(t))break}))}setKeydown(e,t){this.keydownEventList.push({type:e,listener:t})}setKeyup(e,t){this.keyupEventList.push({type:e,listener:t})}keydown(e){for(const t of this.keydownEventList)if(t.type===e&&!1===t.listener(new KeyboardEvent(e)))break}keyup(e){for(const t of this.keyupEventList)if(t.type===e&&!1===t.listener(new KeyboardEvent(e)))break}}const Dt={value:"<p><br /></p>",readonly:!1,spellcheck:!1,tabIndex:0,placeholder:"",indentWithTab:!0,lang:"en-US",minChangeSize:5,historySize:100,onMessage:(e,t)=>{"success"!==e?"warning"!==e?"error"===e&&console.error(t):console.warn(t):console.log(t)},slash:!1,mention:!1};class Nt{constructor(e){if(this.unsavedInputData="",this.unsavedInputCount=0,this.state={activeItems:[],disabledNameMap:new Map,selectedNameMap:new Map,selectedValuesMap:new Map},this.unmountPluginMap=new Map,this.event=new T,this.isComposing=!1,this.popup=null,this.copyListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("copy",e)},this.cutListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("cut",e)},this.pasteListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("paste",e)},this.selectionchangeListener=()=>{this.updateSelectionRange(),this.updateBoxSelectionStyle(),this.emitStateChangeEvent()},this.clickListener=e=>{const t=new w(e.target);t.get(0).isConnected&&this.event.emit("click",t)},this.updateSelectionRange=it((()=>{this.selection.updateByRange()}),1,{immediate:!0}),this.updateBoxSelectionStyle=it((()=>{if(0===this.root.first().length)return;const e=this.selection.getCurrentRange(),t=e.clone();t.adjustBox(),this.container.find("lake-box").each((i=>{const n=we(i),o=n.getContainer();if(0!==o.length){if(e.compareBeforeNode(o)<0&&e.compareAfterNode(o)>0&&(!e.isCollapsed||e.startNode.get(0)!==o.get(0)||0!==e.startOffset))return o.removeClass("lake-box-hovered"),o.removeClass("lake-box-selected"),o.removeClass("lake-box-focused"),o.addClass("lake-box-activated"),void n.event.emit("focus");if(t.intersectsNode(n.node))return o.removeClass("lake-box-activated"),void(e.isCollapsed?(o.removeClass("lake-box-hovered"),o.removeClass("lake-box-selected"),o.addClass("lake-box-focused"),n.event.emit("focus")):(o.removeClass("lake-box-focused"),o.addClass("lake-box-selected"),n.event.emit("blur")));o.removeClass("lake-box-activated"),o.removeClass("lake-box-focused"),o.removeClass("lake-box-selected"),n.event.emit("blur")}}))}),50,{immediate:!0}),this.emitStateChangeEvent=it((()=>{const e=this.getState();nt(e,this.state)||(this.toolbar&&this.toolbar.updateState(e),this.event.emit("statechange",e),this.state=e)}),50,{immediate:!1}),!e.root)throw new Error("The root of the config must be specified.");this.root=y(e.root),this.toolbar=e.toolbar,this.config=Object.assign({},Dt);for(const t of Object.keys(e))this.config[t]=e[t];this.containerWrapper=y('<div class="lake-container-wrapper" />'),this.container=y('<div class="lake-container" />'),this.overlayContainer=y('<div class="lake-overlay" />'),this.readonly=this.config.readonly,this.container.attr({contenteditable:this.readonly?"false":"true",spellcheck:this.config.spellcheck?"true":"false",tabindex:this.config.tabIndex.toString(),readonly:this.readonly?"true":"false"}),""!==this.config.placeholder&&this.container.attr("placeholder",this.config.placeholder),this.selection=new at(this.container),this.command=new lt(this.selection),this.history=new Et(this.selection),this.history.limit=this.config.historySize,this.keystroke=new Zt(this.container),E.set(this.container.id,this)}togglePlaceholderClass(e){const t="lake-placeholder";"<p><br /></p>"===(e=ot(e)).replace("<focus />","")?this.container.addClass(t):this.container.removeClass(t)}moveBoxStripText(){const e=this.selection,t=e.range,i=t.startNode.closest(".lake-box-strip"),n=i.closest("lake-box");if("inline"===we(n).type)t.isBoxStart?(t.setStartBefore(n),t.collapseToStart()):(t.setStartAfter(n),t.collapseToStart());else{const e=y("<p />");t.isBoxStart?n.before(e):n.after(e),t.setStart(e,0),t.collapseToStart()}const o=i.text();i.html("<br />"),e.insertContents(document.createTextNode(o))}resetUnsavedInputData(){this.unsavedInputData="",this.unsavedInputCount=0}handleInputEvent(e){var t;this.selection.updateByRange();const i=this.selection.range;if(i.isInsideBox)return;if(i.isBoxStart||i.isBoxEnd)return this.moveBoxStripText(),void this.history.save();if("insertText"===(e instanceof CompositionEvent?"insertText":e.inputType)){const i=null!==(t=e.data)&&void 0!==t?t:"";return i.length>1?void this.history.save({inputType:"insertText",update:!1}):(this.unsavedInputData+=i,this.unsavedInputCount++,void(this.unsavedInputData.length<this.config.minChangeSize?this.history.save({inputType:"insertText",update:this.unsavedInputCount>1}):(this.history.save({inputType:"insertText",update:!0}),this.resetUnsavedInputData())))}this.history.save()}bindInputEvents(){this.container.on("compositionstart",(()=>{this.isComposing=!0,this.container.removeClass("lake-placeholder")})),this.container.on("compositionend",(e=>{this.isComposing=!1,this.handleInputEvent(e)})),this.container.on("input",(e=>{const t=e;this.isComposing=t.isComposing,this.isComposing||this.handleInputEvent(e)}))}removeBoxGarbage(){const e=S(this.container.id);for(const t of e.values())t.node.get(0).isConnected||(t.unmount(),e.delete(t.node.id))}bindHistoryEvents(){const e=e=>{this.fixContent()&&(this.history.save({update:!0,emitEvent:!1}),e=this.getValue()),this.emitStateChangeEvent(),this.togglePlaceholderClass(e),this.scrollToCursor(),this.event.emit("change",e)};this.history.event.on("undo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("redo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("save",((t,i)=>{this.removeBoxGarbage(),e(t),"insertText"!==i.inputType&&(this.selection.sync(),this.resetUnsavedInputData())}))}get locale(){return he(this.config.lang)}setPluginConfig(e,t){"object"!=typeof this.config[e]&&(this.config[e]={});for(const i of Object.keys(t))void 0===this.config[e][i]&&(this.config[e][i]=t[i])}fixContent(){const e=this.selection.range,t=e.commonAncestor.closest("td"),i=t.length>0?t:this.container;let n=!1,o=i.children();for(const e of o)(e.isBlock||e.isMark)&&""===e.html()&&(e.remove(),n=!0,g(`Content fixed: empty tag "${e.name}" was removed`));if(o=i.children(),0===o.length)i.html("<p><br /></p>"),e.shrinkBefore(i),n=!0,g("Content fixed: default paragraph was added");else if(1===o.length){const t=o[0];if(t.isVoid){const i=y("<p />");t.before(i),i.append(t),e.shrinkAfter(i),n=!0,g(`Content fixed: void element "${t.name}" was wrapped in paragraph`)}}return e.adjustBr(),n}renderBoxes(){this.removeBoxGarbage();const e=this.container,t=S(e.id);e.find("lake-box").each((e=>{const i=y(e);if(t.get(i.id))return;we(i).render()}))}scrollToCursor(){const e=this.selection.range;if(e.isBox)return;const t=e.getRect();if(0===t.x||0===t.y)return;const i=this.container.get(0).getBoundingClientRect(),n=y('<div class="lake-artificial-cursor" />'),o=t.x-i.x,s=t.y-i.y;n.css({position:"absolute",top:`${s}px`,left:`${o}px`,width:`${t.width}px`,height:`${t.height}px`,"z-index":"-1"}),this.overlayContainer.find(".lake-artificial-cursor").remove(),this.overlayContainer.append(n),function(e,t){const i=H(e);0===i.left&&0===i.right&&0===i.top&&0===i.bottom||e.get(0).scrollIntoView(t)}(n,{behavior:"instant",block:"nearest",inline:"nearest"}),n.remove()}hasFocus(){const e=document.activeElement;return!!e&&y(e).closest(".lake-container").get(0)===this.container.get(0)}focus(){const e=this.selection.range;this.container.contains(e.commonAncestor)&&e.isBox||this.container.focus()}blur(){this.container.blur()}getState(){const e=this.command.getNames();let t=this.selection.getActiveItems();t.length>0&&!this.container.contains(t[0].node)&&(t=[]);const i=new Map,n=new Map,o=new Map;for(const s of e){const e=this.command.getItem(s);if(e.isDisabled&&e.isDisabled(t)&&i.set(s,!0),e.isSelected&&e.isSelected(t)&&n.set(s,!0),t.length>0&&e.selectedValues){const i=e.selectedValues(t);i.length>0&&o.set(s,i)}}return{activeItems:t,disabledNameMap:i,selectedNameMap:n,selectedValuesMap:o}}setValue(e){e=st(e);const t=new Ce(e),i=t.getFragment();this.container.empty(),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.renderBoxes(),this.selection.updateByBookmark()}getValue(){const e=this.history.cloneContainer();let t=new Ce(e).getHTML();return t=ot(t),t}render(){const e=st(this.config.value),t=new Ce(e),i=t.getFragment();if(this.root.empty(),this.root.append(this.containerWrapper),this.containerWrapper.append(this.container),this.containerWrapper.append(this.overlayContainer),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.unmountPluginMap=Nt.plugin.loadAll(this),this.readonly||(this.selection.updateByBookmark(),this.history.save({emitEvent:!1})),this.renderBoxes(),this.toolbar){this.toolbar.render(this);const e=this.getState();this.toolbar.updateState(e)}document.addEventListener("copy",this.copyListener),this.readonly||(document.addEventListener("cut",this.cutListener),document.addEventListener("paste",this.pasteListener),document.addEventListener("selectionchange",this.selectionchangeListener),document.addEventListener("click",this.clickListener),this.bindInputEvents(),this.bindHistoryEvents())}unmount(){this.updateSelectionRange.flush(),this.updateBoxSelectionStyle.flush(),this.emitStateChangeEvent.flush();for(const e of this.unmountPluginMap.keys()){const t=this.unmountPluginMap.get(e);t&&(t(),g(`Plugin "${e}" unmounted`))}this.toolbar&&this.toolbar.unmount(),this.removeBoxGarbage(),this.container.find("lake-box").each((e=>{we(y(e)).unmount()})),this.event.removeAllListeners(),this.history.event.removeAllListeners(),this.root.off(),this.root.empty(),document.removeEventListener("copy",this.copyListener),this.readonly||(document.removeEventListener("cut",this.cutListener),document.removeEventListener("paste",this.pasteListener),document.removeEventListener("selectionchange",this.selectionchangeListener),document.removeEventListener("click",this.clickListener))}}Nt.version="0.3.6",Nt.box=new class{add(e){I.set(e.name,e)}remove(e){I.delete(e)}getNames(){return Array.from(I.keys())}},Nt.plugin=new class{constructor(){this.pluginMap=new Map}add(e,t){this.pluginMap.set(e,t)}loadAll(e){const t=new Map;for(const i of this.pluginMap.keys()){const n=this.pluginMap.get(i);if(n&&!1!==e.config[i]){const o=n(e);o&&t.set(i,o)}}return t}};function zt(e,t){const i=e.get(0),n=y(k`<${t} />`);for(const e of i.attributes)n.attr(e.name,e.value);let o=e.first();for(;o.length>0;){const e=o.next();n.append(o),o=e}return e.replaceWith(n),n}const Ot=Array.from(s).join(",");function $t(e){const t=[e];for(const i of e.getWalker())t.push(i);for(const e of t)"div"===e.name?e.find(Ot).length>0?e.remove(!0):zt(e,"p"):(e.isHeading||["blockquote","li"].indexOf(e.name)>=0)&&e.find(Ot).remove(!0)}function Vt(e,t){const i=e.selection,n=i.range;if(0===t.childNodes.length)return;const o=new w(t.firstChild);let s=new w(t.lastChild);0===n.getBlocks().length&&i.setBlocks("<p />"),function(e,t){const i=e.selection.range,n=i.startNode.closest("lake-box");if(n.length>0)if("inline"===we(n).type)i.isBoxStart?(i.setStartBefore(n),i.collapseToStart()):i.isBoxEnd?(i.setStartAfter(n),i.collapseToStart()):e.selection.removeBox();else{const t=y("<p />");i.isBoxStart?(n.before(t),i.shrinkAfter(t)):i.isBoxEnd?(n.after(t),i.shrinkAfter(t)):e.selection.removeBox()}const o=i.startNode.closestBlock();if(t.isBlockBox){const i=we(t),n=""!==t.attr("value")?i.value:void 0;return e.selection.insertBox(i.name,n),void t.remove()}if(t.first().length>0&&Te(o),o.isEmpty&&"p"===o.name)return o.replaceWith(t),t.find("lake-box").each((e=>{we(e).render()})),void i.shrinkAfter(t);let s=t.first();for(;s.length>0;){"li"===s.name&&(s=s.first());const t=s.next();e.selection.insertContents(s),s.isBox?we(s).render():s.isElement&&s.find("lake-box").each((e=>{we(e).render()})),s=t}t.remove()}(e,o);let r=new w(t.firstChild);for(;r.length>0;){const e=r.next();"br"===r.name&&r.remove(),r=e}if(s=new w(t.lastChild),t.childNodes.length>0){const o=i.splitBlock();o.start&&(n.setEndAfter(o.start),n.collapseToEnd()),o.end&&o.end.isEmpty&&o.end.remove(),i.insertContents(t),e.renderBoxes(),n.shrinkAfter(s)}Pe(e.container.children().filter((e=>e.isBlock))),e.history.save()}const Rt=["info","tip","warning","danger"];function Ft(e){e.selection.setBlocks("<p />")}function Wt(e){e.selection.setBlocks("<ol><li></li></ol>")}function jt(e){e.selection.setBlocks("<ul><li></li></ul>")}function qt(e,t){e.selection.setBlocks(`<ul type="checklist"><li value="${t}"></li></ul>`)}function Ut(e){const t=e.startNode.closest("table"),i=y("<p><br /></p>");t.replaceWith(i),e.shrinkBefore(i),g(`deleteTable: table ${t.id}`)}function Kt(e){const t=[];for(let i=0;i<e.rows.length;i++)t[i]=[];for(let i=0;i<t.length;i++){const n=e.rows[i],o=t[i];let s=0;for(let e=0;e<n.cells.length;e++){for(s=e;o[s];)s++;const r=n.cells[e];for(let e=0;e<r.colSpan;e++)for(let n=0;n<r.rowSpan;n++){const o=t[i+n];o&&(o[s+e]=r)}}}return t}function Gt(e,t,i){const n=e[t];for(let e=0;e<n.length;e++){if(n[e]===i)return e}return-1}function Xt(e,t,i){const n=e[t],o=e[t-1];let s=i;for(let e=0;e<i;e++){const t=n[e];if(t===n[e+1])s--;else if(o){t===o[e]&&s--}}return s}function Qt(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0),a=i.get(0),l=r.rowIndex,c=Kt(s);let d=Gt(c,l,a);if("right"===t){const e=c[l];if(d++,e)for(;a===e[d];)d++}g(`insertColumn: rows ${s.rows.length}, column ${d}, ${t}`);for(let e=0;e<s.rows.length;e++){const t=s.rows[e],i=c[e],n=Xt(c,e,d),o=t.cells[n];if(o&&o.colSpan>1&&o===i[d-1])o.colSpan+=1,o.rowSpan>1&&(e+=o.rowSpan-1);else{t.insertCell(n).innerHTML="<p><br /></p>"}}}function Yt(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0);let a=Kt(s);const l=a[0].length;let c;c="up"===t?r.rowIndex:r.rowIndex+1;const d=s.rows[c];g(`insertRow: rows ${s.rows.length}, target row ${c}`);const h=s.insertRow(c);if(!d){for(let e=0;e<l;e++){h.insertCell(h.cells.length).innerHTML="<p><br /></p>"}return}a=Kt(s),c=d.rowIndex;let p=-1;for(let e=0;e<l;e++){const t=Xt(a,c,e);if(t!==p){p=t;const i=d.cells[t];if(!i)break;const n=h.insertCell(h.cells.length);n.innerHTML="<p><br /></p>",i.colSpan>1&&(n.colSpan=i.colSpan,e+=i.colSpan-1)}}for(let e=c-1;e>=0;e--){const t=s.rows[e].cells;for(let i=0;i<t.length;i++){const n=t[i];n.rowSpan>1&&n.rowSpan+1>c-e&&(n.rowSpan+=1)}}}const Jt=[{value:"insertLeft",text:e=>e.table.insertColumnLeft()},{value:"insertRight",text:e=>e.table.insertColumnRight()},{value:"delete",text:e=>e.table.deleteColumn()}],ei=[{value:"insertAbove",text:e=>e.table.insertRowAbove()},{value:"insertBelow",text:e=>e.table.insertRowBelow()},{value:"delete",text:e=>e.table.deleteRow()}],ti=[{value:"up",text:e=>e.table.mergeUp()},{value:"right",text:e=>e.table.mergeRight()},{value:"down",text:e=>e.table.mergeDown()},{value:"left",text:e=>e.table.mergeLeft()}],ii=[{value:"leftRight",text:e=>e.table.splitLeftRight()},{value:"topBottom",text:e=>e.table.splitTopBottom()}];function ni(e,t){const i=[{name:"expand",type:"button",icon:n.get("expand"),tooltip:e=>e.table.fitTable(),isSelected:()=>{const t=e.selection.range.startNode.closest("table");if(0===t.length)return!1;return t.css("width")===e.container.innerWidth()-2+"px"},onClick:()=>{const t=e.selection.range.startNode.closest("table");if(0===t.length)return;const i=t.css("width"),n=e.container.innerWidth()-2+"px";i===n?t.css("width",""):t.css("width",n),e.history.save()}},{name:"backgroundColor",type:"dropdown",downIcon:n.get("down"),icon:n.get("backgroundColor"),accentIcon:n.get("backgroundColorAccent"),defaultValue:t.backgroundColor,tooltip:e=>e.table.cellBackground(),menuType:"color",menuItems:V,menuWidth:"296px",selectedValues:()=>{const t=e.selection.range.startNode.closest("td");if(t.length>0){return[m(t.computedCSS("background-color"))]}return[]},onSelect:(i,n)=>{e.selection.range.startNode.closest("td").css("background-color",n),t.backgroundColor=n,e.history.save()}},{name:"tableColumn",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableColumn"),tooltip:e=>e.table.column(),menuType:"list",menuItems:Jt,menuCheck:!1,onSelect:(t,i)=>{const n=e.selection.range;"insertLeft"===i?Qt(n,"left"):"insertRight"===i?Qt(n,"right"):function(e){const t=e.startNode.closest("td"),i=t.closest("table"),n=t.closest("tr"),o=i.get(0),s=n.get(0),r=t.get(0),a=s.rowIndex,l=Kt(o),c=Gt(l,a,r);let d=null;const h=r.cellIndex;s.cells[h+1]?d=s.cells[h+1]:s.cells[h-1]&&(d=s.cells[h-1]),g(`deleteColumn: rows ${o.rows.length}, column ${c}`);const p=function(e,t){for(let i=0;i<e.length;i++){const n=e[i][t],o=e[i+1];if(o&&n.colSpan!==o[t].colSpan)return!1}return!0}(l,c);for(let t=0;t<o.rows.length;t++){const i=o.rows[t],n=Xt(l,t,c),s=i.cells[n];s.rowSpan>1&&(t+=s.rowSpan-1),s.colSpan>1&&!p?(s.colSpan-=1,1===s.colSpan&&s.removeAttribute("colSpan")):(s===r&&d&&e.shrinkBefore(y(d)),i.deleteCell(n))}0===o.rows[0].cells.length&&Ut(e)}(n),e.history.save()}},{name:"tableRow",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableRow"),tooltip:e=>e.table.row(),menuType:"list",menuItems:ei,menuCheck:!1,onSelect:(t,i)=>{const n=e.selection.range;"insertAbove"===i?Yt(n,"up"):"insertBelow"===i?Yt(n,"down"):function(e){const t=e.startNode.closest("td"),i=t.closest("table"),n=t.closest("tr"),o=i.get(0),s=n.get(0),r=t.get(0),a=s.rowIndex;let l=Kt(o);const c=l[0].length,d=Gt(l,a,r),h=o.rows[a+1]||o.rows[a-1];g(`deleteRow: rows ${o.rows.length}, target row ${a}, column ${d}`);for(let e=a-1;e>=0;e--){const t=o.rows[e].cells;for(let i=0;i<t.length;i++){const n=t[i];n.rowSpan>1&&n.rowSpan>a-e&&(n.rowSpan-=1,1===n.rowSpan&&n.removeAttribute("rowSpan"))}}const p=o.rows[a+1];if(p){let e=-1;for(let t=0;t<c;t++){const i=Xt(l,a,t);if(i!==e){e=i;const n=s.cells[i];if(n.rowSpan>1){const e=Xt(l,a+1,t);let i=p.insertCell(e);const o=n.cloneNode(!0);o.removeAttribute("rowSpan"),i.replaceWith(o),i=o,n.rowSpan>2&&(i.rowSpan=n.rowSpan-1)}}}}if(o.deleteRow(a),h){l=Kt(o);const t=Xt(l,h.rowIndex,d),i=h.cells[t];i&&e.shrinkBefore(y(i))}0===o.rows.length&&Ut(e)}(n),e.history.save()}},{name:"tableMerge",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableMerge"),tooltip:e=>e.table.merge(),menuType:"list",menuItems:ti,menuCheck:!1,onSelect:(t,i)=>{!function(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0),a=i.get(0),l=r.rowIndex,c=Kt(s);if("left"===t||"right"===t){const i=a.cellIndex;let n,o,s;if("left"===t?(n=r.cells[i-1],o=i,s=a):(n=a,o=i+1,s=r.cells[o]),!n||!s)return;if(g(`mergeCells: row ${l}, cell ${i}, other row ${l}, other cell ${o}`),n.rowSpan!==s.rowSpan)return;const d=c[l],h=Gt(c,l,n),p=Gt(c,l,s);if(d[h+1]!==s&&d[p-1]!==n)return;return n.colSpan+=s.colSpan,Me(y(n),y(s)),void e.shrinkBefore(y(n))}const d=Gt(c,l,a);let h,p,u,m,f,v;if("up"===t){h=-1,p=null;for(let e=r.rowIndex-1;e>=0;e--){const t=c[e];if(!t)break;const i=t[d];if(!i)break;if(p&&i!==p)break;h=e,p=i}u=r.rowIndex,m=r,f=a.cellIndex,v=a}else{h=r.rowIndex,p=a,u=-1,v=null,f=-1;for(let e=r.rowIndex+1;e<s.rows.length;e++){const t=c[e];if(!t)break;const i=t[d];if(!i)break;if(i!==v){u=e,v=i,f=v.cellIndex;break}}if(m=s.rows[u],!m)return}p&&v&&(g(`mergeCells: row ${h}, cell ${p.cellIndex}, other row ${u}, other cell ${f}`),p.colSpan===v.colSpan&&(p.rowSpan+=v.rowSpan,Me(y(p),y(v)),e.shrinkBefore(y(p))))}(e.selection.range,i),e.history.save()}},{name:"tableSplit",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableSplit"),tooltip:e=>e.table.split(),menuType:"list",menuItems:ii,menuCheck:!1,onSelect:(t,i)=>{!function(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0),a=i.get(0),l=r.rowIndex,c=a.rowSpan,d=a.colSpan;let h=Kt(s);const p=Gt(h,l,a);if(g(`splitCell: row ${l}, cell ${p}, ${t}`),"topBottom"!==t)for(let e=0;e<h.length;e++){const t=s.rows[e],i=h[e],n=i[p];if(n===a){const i=h[e-1];if(!i||n!==i[p]){const i=Xt(h,e,p),o=t.insertCell(i+1);o.innerHTML="<p><br /></p>",n.rowSpan>1&&(o.rowSpan=n.rowSpan),n.colSpan>2&&(o.colSpan=n.colSpan-1),n.removeAttribute("colSpan")}}else for(let e=p;e>=0;e--)if(0===e||n!==i[e]){1===d&&(n.colSpan+=1);break}}else{const e=h[l];for(let t=0;t<e.length;t++){const i=e[t];if(i===a){const e=c>1?s.rows[l+1]:s.insertRow(l+1),t=Xt(h,l+1,p),i=e.insertCell(t);i.innerHTML="<p><br /></p>",a.colSpan>1&&(i.colSpan=a.colSpan),a.rowSpan>2&&(i.rowSpan=a.rowSpan-1),a.removeAttribute("rowSpan"),h=Kt(s)}else if(1===c){for(let e=l;e>=0;e--){const n=h[e];if(0===e||i!==n[t]){i.rowSpan+=1;break}}h=Kt(s)}i.colSpan>1&&(t+=i.colSpan-1)}}}(e.selection.range,i),e.history.save()}},{name:"remove",type:"button",icon:n.get("remove"),tooltip:e=>e.table.remove(),onClick:()=>{Ut(e.selection.range),e.history.save()}}];return i}const oi={start:"left",end:"right"};function si(e,t){if(e.isList){let i=Number.parseInt(e.attr("indent"),10)||0;if("increase"===t?i++:i--,i<=0)i=0;else if(i>10)return;return 0===i?e.removeAttr("indent"):e.attr("indent",i.toString(10)),void Pe([e])}let i=Number.parseInt(e.css("margin-left"),10)||0;"decrease"!==t||0!==i||""===e.css("text-indent")?("increase"===t?i+=40:i-=40,i<=0&&(i=0),0===i?e.css("margin-left",""):e.css("margin-left",`${i}px`)):e.css("text-indent","")}const ri="strong";const ai="sub";const li="sup";const ci="code";const di="lake-format-painter";function hi(e,t,i,n){return new(i||(i=Promise))((function(o,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function a(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}l((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class pi{constructor(e){this.linkNode=null,this.scrollListener=()=>this.updatePosition(),this.resizeListener=()=>this.updatePosition(),this.config=e||{},this.locale=this.config.locale||he("en-US"),this.container=y(k`
23
23
  <div class="lake-popup lake-link-popup">
24
24
  <div class="lake-row">${this.locale.link.url()}</div>
25
25
  <div class="lake-row lake-url-row">