lakelib 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lake.min.js CHANGED
@@ -2,7 +2,7 @@ var Lake=function(e,t,n,o,i){"use strict";class s extends HTMLElement{}customEle
2
2
  <span class="lake-box-strip"><br /></span>
3
3
  <div class="lake-box-container" contenteditable="false"></div>
4
4
  <span class="lake-box-strip"><br /></span>
5
- `;class nt{constructor(e){if(this.event=new Xe,"string"==typeof e){const t=Ge.get(e);if(void 0===t)throw new Error(`Box '${e}' has not been defined yet.`);const n=d(t.type),o=d(t.name);this.node=V(h`<lake-box type="${n}" name="${o}"></lake-box>`),t.value&&(this.value=t.value)}else{this.node=V(e);const t=Ge.get(this.name);if(void 0===t)throw new Error(`Box '${this.name}' has not been defined yet.`);t.value&&!this.node.hasAttr("value")&&(this.value=t.value)}Ye[this.node.id]||(Ye[this.node.id]={}),et[this.node.id]||(et[this.node.id]={setup:[],cleanup:[]})}addFramework(){let e=this.getContainer();0===e.length?(this.node.html(tt),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",(()=>{H(`Box '${this.name}' (id = ${this.node.id}) value:`),H(this.value)}))}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(_e(e))}set value(e){this.node.attr("value",Ue(JSON.stringify(e)))}updateValue(e,t){const n=this.value;"string"==typeof e?n[e]=t:k(e,((e,t)=>{n[e]=t})),this.value=n}getData(e){return Ye[this.node.id][e]}setData(e,t){Ye[this.node.id][e]=t}getEditor(){const e=this.node.closestContainer();return e.length>0?Qe.get(e.id):void 0}getContainer(){return this.node.find(".lake-box-container")}useEffect(e){et[this.node.id].setup.push(e)}render(){et[this.node.id].setup=[],et[this.node.id].cleanup=[];const e=Ge.get(this.name);if(void 0===e)return;this.addFramework();const t=e.render(this);if(void 0!==t){const e=this.getContainer(),n=e.clone(!1);n.append(t),fe(e,n)}for(const e of et[this.node.id].setup){const t=e();void 0!==t&&et[this.node.id].cleanup.push(t)}H(`Box '${this.name}' (id = ${this.node.id}) rendered`)}unmount(){for(const e of et[this.node.id].cleanup)e();Ye[this.node.id]={},et[this.node.id].setup=[],et[this.node.id].cleanup=[],this.node.empty(),H(`Box '${this.name}' (id = ${this.node.id}) unmounted`)}getHTML(){const e=Ge.get(this.name);return void 0===e?"":void 0===e.html?this.node.outerHTML():e.html(this)}}const ot={id:/^[\w-]+$/,class:/^[\w-]+$/,style:{"text-align":["left","center","right","justify"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function it(){return{h1:Object.assign({},ot),h2:Object.assign({},ot),h3:Object.assign({},ot),h4:Object.assign({},ot),h5:Object.assign({},ot),h6:Object.assign({},ot),p:Object.assign({},ot),blockquote:Object.assign(Object.assign({},ot),{type:["success","info","warning","error"]}),ul:Object.assign(Object.assign({},ot),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},ot),{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:["left","center","right"]},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"]}}}class st{constructor(e,t=it()){this.rules=t,this.source="string"==typeof e?this.parseHTML(e):e}parseHTML(e){const t=(new DOMParser).parseFromString(e,"text/html");return new L(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 n=e.name,o=t[n];if(!o)return"";"string"==typeof o&&(n=o,o=t[n]);const i=e.get(0);if(!i.hasAttributes())return n;const s=new Map;for(const e of i.attributes)if(o[e.name]&&("style"!==e.name&&st.matchRule(o[e.name],e.value)&&s.set(e.name,e.value),"style"===e.name)){const t=o.style,n=new Map;k(m(e.value),((e,o)=>{t[e]&&st.matchRule(t[e],o)&&n.set(e,o)})),s.set("style",n)}let r=n;for(const[e,t]of s)if("style"===e){let e="";for(const[n,o]of t)e+=`${n}: ${o.replace(/"/g,"&quot;")}; `;""!==e&&(r+=` style="${e.trim()}"`)}else r+=` ${e}="${t}"`;return r}static getClosedTagString(e,t){let n=e.name;const o=t[n];return o?("string"==typeof o&&(n=o),n):""}static getTrimmedText(e){const t=e.parent(),n=e.prev(),o=e.next();let i=e.text();return(n.isBlock||n.isBlockBox)&&(o.isBlock||o.isBlockBox)||0===n.length&&0===o.length&&t.isBlock?i=i.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):n.isBlock||n.isBlockBox||0===n.length&&t.isBlock?i=i.replace(/^[\u0020\t\r\n]+/,""):(o.isBlock||o.isBlockBox||0===o.length&&t.isBlock)&&(i=i.replace(/[\u0020\t\r\n]+$/,"")),i}getHTML(){const e=this.rules;let t="";for(const n of function*t(n){let o=n.first();for(;o.length>0;){const n=o.next();if(o.isText)yield d(st.getTrimmedText(o));else if(o.isVoid){const t=st.getOpenTagString(o,e);""!==t&&(yield`<${t} />`)}else if(o.isElement){const n=st.getOpenTagString(o,e),i=st.getClosedTagString(o,e);""!==n&&(yield`<${n}>`),o.isBox||(yield*t(o)),""!==i&&(yield`</${i}>`)}o=n}}(this.source))t+=n;return t.trim()}getNodeList(){const e=this.getHTML();return this.parseHTML(e).children()}getFragment(){const e=this.getHTML(),t=this.parseHTML(e),n=document.createDocumentFragment();let o=t.first();for(;o.length>0;){const e=o.next();n.appendChild(o.get(0)),o=e}return n}}class rt{constructor(e){this.content=e}getHTML(){let e=this.content;return e=e.replace(/ {2}/g,"  "),e=d(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 st(this.getHTML()).getFragment()}}function at(e,t){if(e.commonAncestor.isOutside)return;const n=(t=V(t)).get(0),o=e.get();o.insertNode(n),o.setEndAfter(n),o.collapse(!1)}function lt(e){if(e.commonAncestor.isOutside)return{anchor:new L,focus:new L};const t=e.startNode.closest("lake-box");if(t.length>0)return e.isBoxLeft?t.attr("focus","left"):e.isBoxRight?t.attr("focus","right"):t.attr("focus","center"),{anchor:new L,focus:t};if(e.isCollapsed){const t=e.clone();t.collapseToEnd();const n=V('<lake-bookmark type="focus" />');return at(t,n),{anchor:new L,focus:n}}const n=e.clone();n.collapseToStart();const o=V('<lake-bookmark type="anchor" />');at(n,o);const i=e.clone();i.collapseToEnd();const s=V('<lake-bookmark type="focus" />');return at(i,s),{anchor:o,focus:s}}function ct(e,t){const n=e.prev(),o=e.next();if(n.isText&&o.isText){const t=e.parent();P(t),e.remove(),t.get(0).normalize()}else if(0===n.length&&0===o.length){if(e.parent().isMark&&t){const n=new L(document.createTextNode("​"));e.before(n),t.setStartAfter(n),t.collapseToStart()}e.remove()}else e.remove()}function dt(e,t){const n=t.anchor,o=t.focus;if(n.length>0&&0===o.length)ct(n);else{if(o.length>0&&0===n.length){if(o.isBox){const t=new nt(o);0===t.getContainer().length&&t.render();const n=o.attr("focus");return"left"===n?e.selectBoxLeft(o):"center"===n?e.selectBox(o):e.selectBoxRight(o),void o.removeAttr("focus")}return e.setStartBefore(o),e.collapseToStart(),void ct(o,e)}if(n.length>0&&o.length>0){const t=new $;t.selectNode(n),t.collapseToEnd(),-1===t.compareAfterNode(o)?(e.setStartBefore(o),ct(o),e.setEndBefore(n),ct(n)):(e.setStartBefore(n),ct(n),e.setEndBefore(o),ct(o))}}}function ht(e){if(e.commonAncestor.isOutside)return;q(e.getBlocks())}function ut(e){if(e.isCollapsed)return;if(e.adapt(),e.isInoperative)return;const t=e.startNode.closestBlock(),n=e.endNode.closestBlock(),o=t.get(0)===n.get(0);if(e.get().deleteContents(),e.adaptBlock(),o){const t=e.getBlocks()[0];return void(t&&t.isEmpty&&(I(t,V("<br />")),e.shrinkAfter(t)))}const i=e.getBlocks()[0];if(!i)return;const s=i.prev();if(0===s.length)return;const r=lt(e);R(s,i),dt(e,r),ht(e)}function ft(e,t){if(e.commonAncestor.isOutside)return;e.isCollapsed?e.adaptBox():ut(e);O(e.startNode.closestBlock());const n=lt(e);n.focus.before(t),dt(e,n),e.adaptBlock()}function pt(e,t){const n=V(t),o=document.createDocumentFragment();n.each((e=>{o.appendChild(e)})),ft(e,o)}function gt(e,t){if(e.commonAncestor.isOutside)return;if(e.isCollapsed&&e.isBox)return;if("string"!=typeof t){const n=e.getBlocks();for(const e of n)e.css(t);return}const n=V(t),o=n.name,i=n.get(0).attributes,s=e.getBlocks();if(s.length>0){const t=lt(e);for(const e of s)if(e.name===o&&0===n.first().length)for(const t of i)e.attr(t.name,t.value);else{const t=n.clone(!0);e.isList&&""!==e.attr("indent")&&t.attr("indent",e.attr("indent"));const o=z(t);let i=e.first();for(;i.length>0;){const e=i.next();o.append(i),o.name!==i.name&&"li"!==i.name||i.remove(!0),i=e}e.replaceWith(t)}return dt(e,t),void ht(e)}const r=lt(e),a=function(e){const t=e.commonAncestor.closest('div[contenteditable="true"],td');let n=[];if(0===t.length)return n;let o=t.first(),i=!0;for(;o.length>0;){if(o.isMark||o.isText||o.isBookmark||o.isInlineBox)n.push(o);else{if(!i)break;n=[]}e.intersectsNode(o)&&(i=!1),o=o.next()}return n}(e),l=j(a,n);dt(e,r),ht(e),l.isEmpty&&(I(l,V("<br />")),e.shrinkAfter(l))}function mt(e){if(e.commonAncestor.isOutside)return{left:null,right:null};e.isCollapsed?e.adaptBox():ut(e);const t=e.startNode,n=t.closestOperableBlock();if(0===n.length)return{left:null,right:null};let o=n.parent();o.isOutside&&(o=t.closestContainer());const i=Z(t,e.startOffset,o);let s=null,r=null;return i&&(s=i.left,r=i.right),!i&&t.isBlock&&(e.startOffset>0&&(s=t.children()[e.startOffset-1]),r=t.children()[e.startOffset],r&&!r.isBlock&&(r=null)),s&&s.isEmpty&&I(s,V("<br />")),r&&(r.isEmpty?(I(r,V("<br />")),e.shrinkAfter(r)):e.shrinkBefore(r)),ht(e),{left:s,right:r}}function vt(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function xt(e,t,n){let o=null,i=null,s=e.closestBlock();0===s.length&&(s=e.closestContainer());const r=Z(e,t,s);return r&&(n?(vt(r.left),vt(r.right),r.left.isEmpty||(o=r.left),r.right.isEmpty||(i=r.right)):(o=r.left,i=r.right)),{left:o,right:i}}function kt(e,t=!0){if(e.commonAncestor.isOutside)return{left:null,center:null,right:null};if(e.adaptBox(),e.isCollapsed){const n=xt(e.startNode,e.startOffset,t);return n.left?(e.setStartAfter(n.left),e.collapseToStart()):n.right&&(e.setStartBefore(n.right),e.collapseToStart()),{left:n.left,center:null,right:n.right}}const n=xt(e.startNode,e.startOffset,t);n.left?e.setStartAfter(n.left):n.right&&e.setStartBefore(n.right);const o=xt(e.endNode,e.endOffset,t);return o.left?e.setEndAfter(o.left):o.right&&e.setEndBefore(o.right),{left:n.left,center:o.left,right:o.right}}function wt(e,t){const n=e.text();let o=e;for(;o.length>0;){const e=o.parent();if(!e.isMark||n!==e.text()||!o.isText&&o.name===t&&""!==o.attr("style"))break;o=e}return o}function bt(e,t){if(e.commonAncestor.isOutside)return;let n=V(t);const o=n.name,i=m(n.attr("style"));if(e.isCollapsed){if(e.isBox){const t=e.startNode.closest("lake-box");if("block"===new nt(t).type){const n=V("<p><br /></p>");e.isBoxLeft?t.before(n):t.after(n),e.shrinkAfter(n)}else e.adaptBox()}O(e.startNode.closestBlock());const t=new L(document.createTextNode("​")),s=kt(e);if(s.left){const e=function(e){if(!e.isMark)return null;let t=e.clone(),n=e.last();for(;n.length>0;){if(n.isMark){const e=n.clone();t.append(e),t=e}n=n.last()}return t}(s.left);e&&(e.name===o?(e.css(i),n=e):(I(e,t),n.append(e)))}return""===n.text()&&n.append(t),at(e,n),function(e){const t=e.prev();t.length>0&&t.isText&&t.isEmpty&&t.remove();const n=e.next();n.length>0&&n.isText&&n.isEmpty&&n.remove()}(n),void e.shrinkAfter(n)}kt(e);const s=e.getMarks(!0),r=lt(e);for(const e of s)if(!e.isEmpty&&e.isText){const t=wt(e,o);if(t.isMark&&t.name===o)t.css(i);else{const e=n.clone();t.before(e),e.append(t)}}dt(e,r)}function yt(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function Bt(e,t){if(e.commonAncestor.isOutside)return;let n;if(t){n=V(t).name}if(e.isCollapsed){if(e.isBox)return;if(n&&0===e.commonAncestor.closest(n).length)return;const t=kt(e,!1);if(!t.left)return;t.right&&yt(t.right);const o=new L(document.createTextNode("​")),i=function(e,t){if(!e.isMark||!t)return null;let n=e.clone(),o=e.last();for(;o.length>0;){if(o.isMark&&o.name!==t){const e=o.clone();n.append(e),n=e}o=o.last()}if(n.name===t){if(!(n.first().length>0))return null;n=n.first()}return n}(t.left,n);return i?(I(i,o),t.left.after(i),yt(t.left),void e.shrinkAfter(i)):(t.left.after(o),yt(t.left),o.prev().isText?(e.setStartAfter(o.prev()),e.collapseToStart(),void o.remove()):(e.setStartAfter(o),void e.collapseToStart()))}kt(e);const o=e.getMarks(),i=lt(e);for(const e of o)if(!n||e.name===n){const t=e.parent();e.remove(!e.isEmpty),t.length>0&&t.get(0).normalize()}P(e.commonAncestor),dt(e,i)}function At(e,t){if(e.commonAncestor.isOutside)return null;const n=V(t);if(e.isCollapsed){let t=e.commonAncestor.closest("a");if(0===t.length){t=n.clone(!0);return O(e.startNode.closestBlock()),at(e,t),t}return""!==n.attr("href")&&t.attr({href:n.attr("href")}),t}kt(e);const o=lt(e);for(const t of e.commonAncestor.getWalker())"a"===t.name&&e.intersectsNode(t)&&t.remove(!0);const i=n.clone(!1);o.anchor.after(i);let s=i.next();for(;s.length>0;){const e=s.next();if(!s.isMark&&!s.isText)break;i.append(s),s=e}return 0===i.first().length&&i.remove(),dt(e,o),i}var Ct=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)},St="object"==typeof We&&We&&We.Object===Object&&We,Mt="object"==typeof self&&self&&self.Object===Object&&self,Tt=St||Mt||Function("return this")(),Ht=Tt,Et=function(){return Ht.Date.now()},Nt=/\s/;var Lt=function(e){for(var t=e.length;t--&&Nt.test(e.charAt(t)););return t},Vt=Lt,$t=/^\s+/;var Zt=function(e){return e?e.slice(0,Vt(e)+1).replace($t,""):e},It=Tt.Symbol,Ot=It,Dt=Object.prototype,Rt=Dt.hasOwnProperty,zt=Dt.toString,jt=Ot?Ot.toStringTag:void 0;var Pt=function(e){var t=Rt.call(e,jt),n=e[jt];try{e[jt]=void 0;var o=!0}catch(e){}var i=zt.call(e);return o&&(t?e[jt]=n:delete e[jt]),i},Ft=Object.prototype.toString;var qt=Pt,Ut=function(e){return Ft.call(e)},_t=It?It.toStringTag:void 0;var Wt=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":_t&&_t in Object(e)?qt(e):Ut(e)},Kt=function(e){return null!=e&&"object"==typeof e};var Jt=Zt,Xt=Ct,Gt=function(e){return"symbol"==typeof e||Kt(e)&&"[object Symbol]"==Wt(e)},Qt=/^[-+]0x[0-9a-f]+$/i,Yt=/^0b[01]+$/i,en=/^0o[0-7]+$/i,tn=parseInt;var nn=Ct,on=Et,sn=function(e){if("number"==typeof e)return e;if(Gt(e))return NaN;if(Xt(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=Xt(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=Jt(e);var n=Yt.test(e);return n||en.test(e)?tn(e.slice(2),n?2:8):Qt.test(e)?NaN:+e},rn=Math.max,an=Math.min;var ln=function(e,t,n){var o,i,s,r,a,l,c=0,d=!1,h=!1,u=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function f(t){var n=o,s=i;return o=i=void 0,c=t,r=e.apply(s,n)}function p(e){var n=e-l;return void 0===l||n>=t||n<0||h&&e-c>=s}function g(){var e=on();if(p(e))return m(e);a=setTimeout(g,function(e){var n=t-(e-l);return h?an(n,s-(e-c)):n}(e))}function m(e){return a=void 0,u&&o?f(e):(o=i=void 0,r)}function v(){var e=on(),n=p(e);if(o=arguments,i=this,l=e,n){if(void 0===a)return function(e){return c=e,a=setTimeout(g,t),d?f(e):r}(l);if(h)return clearTimeout(a),a=setTimeout(g,t),f(l)}return void 0===a&&(a=setTimeout(g,t)),r}return t=sn(t)||0,nn(n)&&(d=!!n.leading,s=(h="maxWait"in n)?rn(sn(n.maxWait)||0,t):s,u="trailing"in n?!!n.trailing:u),v.cancel=function(){void 0!==a&&clearTimeout(a),c=0,o=l=i=a=void 0},v.flush=function(){return void 0===a?r:m(on())},v},cn=Ke(ln),dn="0.0.2";function hn(e){const t=e.get(0),n={};if(t.hasAttributes())for(const e of t.attributes)n[e.name]=e.value;return n}class un{constructor(e){const t=window.getSelection();if(!t)throw new Error("Selection object is null.");this.selection=t,this.container=e,this.range=this.getRangeFromNativeSelection(),this.appliedItems=[]}getRangeFromNativeSelection(){if(this.selection.rangeCount>0){const e=this.selection.getRangeAt(0);return new $(e)}return new $}addRangeToNativeSelection(){this.selection.removeAllRanges(),this.selection.addRange(this.range.get())}syncByRange(){const e=this.getRangeFromNativeSelection();this.range.get()!==e.get()&&(this.range=e)}synByBookmark(){const e=this.range,t=this.container,n=t.find("lake-box[focus]");if(n.length>0)return dt(e,{anchor:new L,focus:n}),void this.addRangeToNativeSelection();dt(e,{anchor:t.find('lake-bookmark[type="anchor"]'),focus:t.find('lake-bookmark[type="focus"]')}),this.addRangeToNativeSelection()}getAppliedItems(){const e=[];return function(e,t){let n=t.startNode;for(n.isText&&(n=n.parent());n.length>0&&n.isInside;)e.push({node:n,name:n.name,attributes:hn(n),styles:m(n.attr("style"))}),n=n.parent()}(e,this.range),function(e,t){const n=t.startNode;let o;if(n.isText&&n.text().length===t.startOffset){const e=n.next();e.length>0&&e.isElement&&(o=e)}if(n.isElement){const e=n.children();if(e.length>0){const n=e[t.startOffset];n&&n.isElement&&(o=n)}}if(o){let t=o;for(;t.length>0;)t.isElement&&e.push({node:t,name:t.name,attributes:hn(t),styles:m(t.attr("style"))}),t=t.first()}}(e,this.range),e}insertBookmark(){return lt(this.range)}toBookmark(e){return dt(this.range,e)}insertNode(e){return at(this.range,e)}insertFragment(e){return ft(this.range,e)}insertContents(e){return pt(this.range,e)}deleteContents(){return ut(this.range)}setBlocks(e){return gt(this.range,e)}splitBlock(){return mt(this.range)}splitMarks(e){return kt(this.range,e)}addMark(e){return bt(this.range,e)}removeMark(e){return Bt(this.range,e)}fixList(){return ht(this.range)}insertLink(e){return At(this.range,e)}}class fn{constructor(){this.commandMap=new Map,this.event=new Xe}add(e,t){this.commandMap.set(e,t)}getNames(){return Array.from(this.commandMap.keys())}execute(e,...t){const n=this.commandMap.get(e);if(void 0===n)throw new Error(`Command '${e}' does not exist.`);this.event.emit("beforeexecute",e),n.apply(this,t),this.event.emit("execute",e),H(`Command '${e}' executed`)}}var pn,gn={exports:{}};pn=gn,function(e){function t(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function n(e,n,o,i,s,r){return t((a=t(t(n,e),t(i,r)))<<(l=s)|a>>>32-l,o);var a,l}function o(e,t,o,i,s,r,a){return n(t&o|~t&i,e,t,s,r,a)}function i(e,t,o,i,s,r,a){return n(t&i|o&~i,e,t,s,r,a)}function s(e,t,o,i,s,r,a){return n(t^o^i,e,t,s,r,a)}function r(e,t,o,i,s,r,a){return n(o^(t|~i),e,t,s,r,a)}function a(e,n){var a,l,c,d,h;e[n>>5]|=128<<n%32,e[14+(n+64>>>9<<4)]=n;var u=1732584193,f=-271733879,p=-1732584194,g=271733878;for(a=0;a<e.length;a+=16)l=u,c=f,d=p,h=g,u=o(u,f,p,g,e[a],7,-680876936),g=o(g,u,f,p,e[a+1],12,-389564586),p=o(p,g,u,f,e[a+2],17,606105819),f=o(f,p,g,u,e[a+3],22,-1044525330),u=o(u,f,p,g,e[a+4],7,-176418897),g=o(g,u,f,p,e[a+5],12,1200080426),p=o(p,g,u,f,e[a+6],17,-1473231341),f=o(f,p,g,u,e[a+7],22,-45705983),u=o(u,f,p,g,e[a+8],7,1770035416),g=o(g,u,f,p,e[a+9],12,-1958414417),p=o(p,g,u,f,e[a+10],17,-42063),f=o(f,p,g,u,e[a+11],22,-1990404162),u=o(u,f,p,g,e[a+12],7,1804603682),g=o(g,u,f,p,e[a+13],12,-40341101),p=o(p,g,u,f,e[a+14],17,-1502002290),u=i(u,f=o(f,p,g,u,e[a+15],22,1236535329),p,g,e[a+1],5,-165796510),g=i(g,u,f,p,e[a+6],9,-1069501632),p=i(p,g,u,f,e[a+11],14,643717713),f=i(f,p,g,u,e[a],20,-373897302),u=i(u,f,p,g,e[a+5],5,-701558691),g=i(g,u,f,p,e[a+10],9,38016083),p=i(p,g,u,f,e[a+15],14,-660478335),f=i(f,p,g,u,e[a+4],20,-405537848),u=i(u,f,p,g,e[a+9],5,568446438),g=i(g,u,f,p,e[a+14],9,-1019803690),p=i(p,g,u,f,e[a+3],14,-187363961),f=i(f,p,g,u,e[a+8],20,1163531501),u=i(u,f,p,g,e[a+13],5,-1444681467),g=i(g,u,f,p,e[a+2],9,-51403784),p=i(p,g,u,f,e[a+7],14,1735328473),u=s(u,f=i(f,p,g,u,e[a+12],20,-1926607734),p,g,e[a+5],4,-378558),g=s(g,u,f,p,e[a+8],11,-2022574463),p=s(p,g,u,f,e[a+11],16,1839030562),f=s(f,p,g,u,e[a+14],23,-35309556),u=s(u,f,p,g,e[a+1],4,-1530992060),g=s(g,u,f,p,e[a+4],11,1272893353),p=s(p,g,u,f,e[a+7],16,-155497632),f=s(f,p,g,u,e[a+10],23,-1094730640),u=s(u,f,p,g,e[a+13],4,681279174),g=s(g,u,f,p,e[a],11,-358537222),p=s(p,g,u,f,e[a+3],16,-722521979),f=s(f,p,g,u,e[a+6],23,76029189),u=s(u,f,p,g,e[a+9],4,-640364487),g=s(g,u,f,p,e[a+12],11,-421815835),p=s(p,g,u,f,e[a+15],16,530742520),u=r(u,f=s(f,p,g,u,e[a+2],23,-995338651),p,g,e[a],6,-198630844),g=r(g,u,f,p,e[a+7],10,1126891415),p=r(p,g,u,f,e[a+14],15,-1416354905),f=r(f,p,g,u,e[a+5],21,-57434055),u=r(u,f,p,g,e[a+12],6,1700485571),g=r(g,u,f,p,e[a+3],10,-1894986606),p=r(p,g,u,f,e[a+10],15,-1051523),f=r(f,p,g,u,e[a+1],21,-2054922799),u=r(u,f,p,g,e[a+8],6,1873313359),g=r(g,u,f,p,e[a+15],10,-30611744),p=r(p,g,u,f,e[a+6],15,-1560198380),f=r(f,p,g,u,e[a+13],21,1309151649),u=r(u,f,p,g,e[a+4],6,-145523070),g=r(g,u,f,p,e[a+11],10,-1120210379),p=r(p,g,u,f,e[a+2],15,718787259),f=r(f,p,g,u,e[a+9],21,-343485551),u=t(u,l),f=t(f,c),p=t(p,d),g=t(g,h);return[u,f,p,g]}function l(e){var t,n="",o=32*e.length;for(t=0;t<o;t+=8)n+=String.fromCharCode(e[t>>5]>>>t%32&255);return n}function c(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t<n.length;t+=1)n[t]=0;var o=8*e.length;for(t=0;t<o;t+=8)n[t>>5]|=(255&e.charCodeAt(t/8))<<t%32;return n}function d(e){var t,n,o="0123456789abcdef",i="";for(n=0;n<e.length;n+=1)t=e.charCodeAt(n),i+=o.charAt(t>>>4&15)+o.charAt(15&t);return i}function h(e){return unescape(encodeURIComponent(e))}function u(e){return function(e){return l(a(c(e),8*e.length))}(h(e))}function f(e,t){return function(e,t){var n,o,i=c(e),s=[],r=[];for(s[15]=r[15]=void 0,i.length>16&&(i=a(i,8*e.length)),n=0;n<16;n+=1)s[n]=909522486^i[n],r[n]=1549556828^i[n];return o=a(s.concat(c(t)),512+8*t.length),l(a(r.concat(o),640))}(h(e),h(t))}function p(e,t,n){return t?n?f(t,e):d(f(t,e)):n?u(e):d(u(e))}pn.exports?pn.exports=p:e.md5=p}(We);var mn=Ke(gn.exports);const vn=new Map;class xn{constructor(e){this.selection=e,this.container=e.container,this.list=[],this.index=0,this.canSave=!0,this.limit=100,this.event=new Xe}removeBookmark(e){return e.replace(/(<lake-box[^>]+)\s+focus="\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 st(e).getHTML()}addIdToBoxes(e){e.find("lake-box").each((e=>{const t=new L(e),n=mn(`${t.attr("type")}-${t.attr("name")}-${t.attr("value")}`);t.attr("id",n)}))}removeIdfromBoxes(e){e.find("lake-box").each((e=>{new L(e).removeAttr("id")}))}morphContainer(e){const t=this.container,n={beforeChildrenUpdated:e=>{if("lake-box"===new L(e).name)return!1},afterAttributeUpdated:(e,n)=>{const o=new L(n);if("value"===e&&"lake-box"===o.name){const e=vn.get(t.id);if(!e)return;e.delete(o.id)}}},o=e.clone(!0);this.addIdToBoxes(t),this.addIdToBoxes(o),fe(t,o,{callbacks:n}),this.removeIdfromBoxes(t),this.removeIdfromBoxes(o)}cloneContainer(){const e=this.selection.range,t=this.container.clone(!0);if(t.find("lake-box").each((e=>{new nt(e).getContainer().empty()})),e.commonAncestor.isOutside)return t;if(e.isInsideBox)return t;const n=e.startNode.path(),o=e.endNode.path(),i=t.find(n),s=t.find(o),r=e.clone();return r.setStart(i,e.startOffset),r.setEnd(s,e.endOffset),lt(r),t}get count(){return this.list.length}get canUndo(){return this.index>1&&!!this.list[this.index-1]}get canRedo(){return!!this.list[this.index]}undo(){if(!this.list[this.index-1])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index>0;){const t=this.list[this.index-1];if(!t)break;const n=this.getValue(t);if(this.removeBookmark(n)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("undo",n);break}if(1===this.index)break;this.index--}this.selection.synByBookmark(),H(`History undone, the last index is ${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 n=this.getValue(t);if(this.removeBookmark(n)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("redo",n);break}}this.selection.synByBookmark(),H(`History redone, the last index is ${this.index}`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(){if(!this.canSave)return;const e=this.cloneContainer(),t=this.getValue(e);this.list[this.index-1]&&this.removeBookmark(this.getValue(this.list[this.index-1]))===this.removeBookmark(t)||(this.list.splice(this.index,1/0,e),this.index++,this.list.length>this.limit&&(this.list.shift(),this.index=this.list.length),this.event.emit("save",t),H(`History saved, the last index is ${this.index}`))}}var kn=["Shift","Meta","Alt","Control"],wn="object"==typeof navigator?navigator.platform:"",bn=/Mac|iPod|iPhone|iPad/.test(wn),yn=bn?"Meta":"Control",Bn="Win32"===wn?["Control","Alt"]:bn?["Alt"]:[];function An(e,t){return"function"==typeof e.getModifierState&&(e.getModifierState(t)||Bn.includes(t)&&e.getModifierState("AltGraph"))}function Cn(e){return e.trim().split(" ").map((function(e){var t=e.split(/\b\+/),n=t.pop();return[t=t.map((function(e){return"$mod"===e?yn:e})),n]}))}function Sn(e,t){var n;void 0===t&&(t={});var o=null!=(n=t.timeout)?n:1e3,i=Object.keys(e).map((function(t){return[Cn(t),e[t]]})),s=new Map,r=null;return function(e){e instanceof KeyboardEvent&&(i.forEach((function(t){var n=t[0],o=t[1],i=s.get(n)||n;!function(e,t){return!(t[1].toUpperCase()!==e.key.toUpperCase()&&t[1]!==e.code||t[0].find((function(t){return!An(e,t)}))||kn.find((function(n){return!t[0].includes(n)&&t[1]!==n&&An(e,n)})))}(e,i[0])?An(e,e.key)||s.delete(n):i.length>1?s.set(n,i.slice(1)):(s.delete(n),o(e))})),r&&clearTimeout(r),r=setTimeout(s.clear.bind(s),o))}}const Mn=new Map([["#","shift+#"]]);class Tn{constructor(e){this.container=e,this.keydownEventList=[],this.keyupEventList=[]}normalizeType(e){var t;return e=(e=null!==(t=Mn.get(e))&&void 0!==t?t:e).replace(/(^|\+|\s)mod(\+|\s|$)/g,"$1$mod$2").replace(/shift|control|alt|meta|enter|tab|backspace|delete|space|escape|arrow-left|arrow-right|arrow-up|arrow-down/,(e=>e.charAt(0).toUpperCase()+u(e.substring(1)))).replace(/(^|\+|\s)([a-z])(\+|\s|$)/g,((e,t,n,o)=>`${t}Key${n.toUpperCase()}${o}`))}setKeydown(e,t){const n=Sn({[e=this.normalizeType(e)]:e=>t(e)});this.keydownEventList.push({type:e,listener:t}),this.container.on("keydown",n)}setKeyup(e,t){const n=Sn({[e=this.normalizeType(e)]:e=>t(e)});this.keyupEventList.push({type:e,listener:t}),this.container.on("keyup",n)}keydown(e){e=this.normalizeType(e);for(const t of this.keydownEventList)t.type===e&&t.listener(new Event(e))}keyup(e){e=this.normalizeType(e);for(const t of this.keyupEventList)t.type===e&&t.listener(new Event(e))}}const Hn={value:"<p><br /><focus /></p>",readonly:!1,spellcheck:!1,minChangeSize:5,imageRequestMethod:"POST",imageRequestAction:"/upload",imageRequestTypes:["image/gif","image/jpeg","image/png","image/svg+xml"]};class En{constructor(e){if(!e.root)throw new Error("The root of the config must be specified.");this.root=V(e.root),this.config=Object.assign(Object.assign({},Hn),e),this.containerWrapper=V('<div class="lake-container-wrapper" />'),this.container=V('<div class="lake-container" />'),this.overlayContainer=V('<div class="lake-overlay" />'),this.popupContainer=V('<div class="lake-popup lake-custom-properties" />'),this.isComposing=!1,this.readonly=this.config.readonly,this.root.addClass("lake-custom-properties"),this.container.attr({contenteditable:this.readonly?"false":"true",spellcheck:this.config.spellcheck?"true":"false"}),this.event=new Xe,this.selection=new un(this.container),this.command=new fn,this.history=new xn(this.selection),this.keystroke=new Tn(this.container),this.box=En.box,this.unsavedInputData="",Qe.set(this.container.id,this),this.beforeunloadListener=()=>{this.commitUnsavedInputData()};const t=cn((()=>{if(0===this.root.first().length)return;const e=this.selection.range,t=e.clone();t.adaptBox(),this.box.findAll(this).each((n=>{const o=new nt(n),i=o.getContainer();if(0!==i.length){if(e.compareBeforeNode(i)<0&&e.compareAfterNode(i)>0&&(!e.isCollapsed||e.startNode.get(0)!==i.get(0)||0!==e.startOffset))return i.removeClass("lake-box-selected"),i.removeClass("lake-box-focused"),void i.addClass("lake-box-activated");if(t.intersectsNode(o.node))return i.removeClass("lake-box-activated"),void(e.isCollapsed?(i.removeClass("lake-box-selected"),i.addClass("lake-box-focused")):(i.removeClass("lake-box-focused"),i.addClass("lake-box-selected")));i.removeClass("lake-box-activated"),i.removeClass("lake-box-focused"),i.removeClass("lake-box-selected")}}))}),50,{leading:!1,trailing:!0,maxWait:50});this.selectionchangeListener=()=>{this.selection.syncByRange(),this.selection.appliedItems=this.selection.getAppliedItems(),t(),this.event.emit("selectionchange")},this.clickListener=e=>{const t=new L(e.target);this.event.emit("click",t)},this.mouseoverListener=e=>{const t=new L(e.target);this.event.emit("mouseover",t)},this.resizeListener=()=>{this.event.emit("resize")}}inputInBoxStrip(){const e=this.selection,t=e.range,n=t.startNode.closest(".lake-box-strip"),o=n.closest("lake-box");if("inline"===new nt(o).type)t.isBoxLeft?(t.setStartBefore(o),t.collapseToStart()):(t.setStartAfter(o),t.collapseToStart());else{const e=V("<p />");t.isBoxLeft?o.before(e):o.after(e),t.shrinkAfter(e)}const i=n.text();n.html("<br />"),e.insertNode(document.createTextNode(i))}bindInputEvents(){this.container.on("compositionstart",(()=>{this.isComposing=!0})),this.container.on("compositionend",(()=>{this.isComposing=!1})),this.container.on("beforeinput",(()=>{const e=this.selection.range;(e.isBoxLeft||e.isBoxRight)&&this.commitUnsavedInputData()})),this.container.on("input",(e=>{const t=e;window.setTimeout((()=>{var e;const n=this.selection.range;if(!n.isInsideBox)if(this.isComposing)this.event.emit("input",t);else{if("insertText"===t.inputType||"insertCompositionText"===t.inputType)if(n.isBoxLeft||n.isBoxRight)this.inputInBoxStrip();else if(this.unsavedInputData+=null!==(e=t.data)&&void 0!==e?e:"",this.unsavedInputData.length<this.config.minChangeSize)return void this.event.emit("input",t);this.history.save(),this.unsavedInputData="",this.event.emit("input",t)}}),0)})),this.command.event.on("beforeexecute",(()=>this.commitUnsavedInputData()))}bindHistoryEvents(){this.history.event.on("undo",(e=>{this.box.renderAll(this),this.event.emit("change",e)})),this.history.event.on("redo",(e=>{this.box.renderAll(this),this.event.emit("change",e)})),this.history.event.on("save",(e=>{this.box.rectifyInstances(this),this.event.emit("change",e)}))}commitUnsavedInputData(){this.unsavedInputData.length>0&&(this.history.save(),this.unsavedInputData="")}prepareOperation(){this.commitUnsavedInputData(),this.history.pause()}commitOperation(){this.history.continue(),this.history.save()}focus(){this.container.focus()}blur(){this.container.blur()}setValue(e){e=v(e);const t=new st(e).getFragment();this.container.empty(),this.container.append(t),En.box.renderAll(this),this.selection.synByBookmark()}getValue(){const e=this.selection.insertBookmark();let t=new st(this.container).getHTML();return t=x(t),this.selection.toBookmark(e),t}insertBox(e,t){const n=function(e,t,n){if(e.commonAncestor.isOutside)return null;const o=new nt(t);n&&(o.value=n);const i=document.createDocumentFragment();if(i.appendChild(o.node.get(0)),"inline"===o.type)return ft(e,i),o.render(),e.selectBoxRight(o.node),o;const s=mt(e);return s.left&&(e.setEndAfter(s.left),e.collapseToEnd()),s.right&&s.right.isEmpty&&s.right.remove(),ft(e,i),o.render(),e.selectBoxRight(o.node),s.left&&s.left.isEmpty&&s.left.remove(),o}(this.selection.range,e,t);if(!n)return n;return this.box.getInstances(this).set(n.node.id,n),n}removeBox(){const e=function(e){if(e.commonAncestor.isOutside)return null;const t=e.commonAncestor.closest("lake-box");if(0===t.length)return null;const n=new nt(t);if("block"===n.type){const o=V("<p><br /></p>");return t.before(o),e.shrinkAfter(o),n.unmount(),t.remove(),n}e.setStartBefore(t),e.collapseToStart();const o=t.parent();return n.unmount(),t.remove(),o.isEmpty&&(I(o,V("<br />")),e.shrinkAfter(o)),n}(this.selection.range);if(e){this.box.getInstances(this).delete(e.node.id)}return e}innerWidth(){const e=parseInt(this.container.computedCSS("padding-left"),10)||0,t=parseInt(this.container.computedCSS("padding-right"),10)||0;return this.container.width()-e-t}render(){const e=v(this.config.value),t=new st(e).getFragment();this.root.empty(),this.root.append(this.containerWrapper),this.containerWrapper.append(this.container),this.containerWrapper.append(this.overlayContainer),V(document.body).append(this.popupContainer),this.container.append(t),this.readonly||(this.focus(),this.selection.synByBookmark(),this.history.save()),En.plugin.loadAll(this),En.box.renderAll(this),this.readonly||(window.addEventListener("beforeunload",this.beforeunloadListener),document.addEventListener("selectionchange",this.selectionchangeListener),this.bindInputEvents(),this.bindHistoryEvents()),document.addEventListener("click",this.clickListener),document.addEventListener("mouseover",this.mouseoverListener),window.addEventListener("resize",this.resizeListener)}unmount(){this.root.empty(),this.popupContainer.remove(),this.readonly||(window.removeEventListener("beforeunload",this.beforeunloadListener),document.removeEventListener("selectionchange",this.selectionchangeListener)),document.removeEventListener("click",this.clickListener),document.removeEventListener("mouseover",this.mouseoverListener),window.removeEventListener("resize",this.resizeListener)}}En.version=dn,En.box=new class{add(e){Ge.set(e.name,e)}remove(e){Ge.delete(e)}getNames(){return Array.from(Ge.keys())}getInstances(e){let t=vn.get(e.container.id);return t||(t=new Map,vn.set(e.container.id,t),t)}rectifyInstances(e){const t=this.getInstances(e);for(const e of t.values())e.node.get(0).isConnected||(e.unmount(),t.delete(e.node.id))}findAll(e){return e.container.find("lake-box")}renderAll(e){this.rectifyInstances(e);const t=this.getInstances(e);this.findAll(e).each((e=>{const n=new L(e);if(t.get(n.id))return;const o=new nt(n);o.render(),t.set(o.node.id,o)}))}},En.plugin=new class{constructor(){this.pluginList=[]}add(e){this.pluginList.push(e)}loadAll(e){this.pluginList.forEach((t=>{t(e)}))}};const Nn=[{icon:a.get("numberedList"),value:"numbered",text:"Numbered list"},{icon:a.get("bulletedList"),value:"bulleted",text:"Bulleted list"},{icon:a.get("checklist"),value:"checklist",text:"Checklist"}],Ln=[{icon:a.get("alignLeft"),value:"left",text:"Align left"},{icon:a.get("alignCenter"),value:"center",text:"Align center"},{icon:a.get("alignRight"),value:"right",text:"Align right"},{icon:a.get("alignJustify"),value:"justify",text:"Align justify"}],Vn=[{icon:a.get("increaseIndent"),value:"increase",text:"Increase indent"},{icon:a.get("decreaseIndent"),value:"decrease",text:"Decrease indent"}],$n=[{icon:a.get("italic"),value:"italic",text:"Italic"},{icon:a.get("underline"),value:"underline",text:"Underline"},{icon:a.get("strikethrough"),value:"strikethrough",text:"Strikethrough"},{icon:a.get("superscript"),value:"superscript",text:"Superscript"},{icon:a.get("subscript"),value:"subscript",text:"Subscript"},{icon:a.get("code"),value:"code",text:"Code"}],Zn=["#f5222d","#fa541c","#fa8c16","#faad14","#fadb14","#a0d911","#52c41a","#13c2c2","#1677ff","#2f54eb","#722ed1","#eb2f96","#fff1f0","#fff2e8","#fff7e6","#fffbe6","#feffe6","#fcffe6","#f6ffed","#e6fffb","#e6f4ff","#f0f5ff","#f9f0ff","#fff0f6","#ffccc7","#ffd8bf","#ffe7ba","#fff1b8","#ffffb8","#f4ffb8","#d9f7be","#b5f5ec","#bae0ff","#d6e4ff","#efdbff","#ffd6e7","#ffa39e","#ffbb96","#ffd591","#ffe58f","#fffb8f","#eaff8f","#b7eb8f","#87e8de","#91caff","#adc6ff","#d3adf7","#ffadd2","#ff7875","#ff9c6e","#ffc069","#ffd666","#fff566","#d3f261","#95de64","#5cdbd3","#69b1ff","#85a5ff","#b37feb","#ff85c0","#ff4d4f","#ff7a45","#ffa940","#ffc53d","#ffec3d","#bae637","#73d13d","#36cfc9","#4096ff","#597ef7","#9254de","#f759ab","#cf1322","#d4380d","#d46b08","#d48806","#d4b106","#7cb305","#389e0d","#08979c","#0958d9","#1d39c4","#531dab","#c41d7f","#a8071a","#ad2102","#ad4e00","#ad6800","#ad8b00","#5b8c00","#237804","#006d75","#003eb3","#10239e","#391085","#9e1068","#820014","#871400","#873800","#874d00","#876800","#3f6600","#135200","#00474f","#002c8c","#061178","#22075e","#780650","#5c0011","#610b00","#612500","#613400","#614700","#254000","#092b00","#002329","#001d66","#030852","#120338","#520339","#000000","#1f1f1f","#262626","#434343","#595959","#8c8c8c","#bfbfbf","#d9d9d9","#f0f0f0","#f5f5f5","#fafafa","#ffffff"],In=[{icon:a.get("removeFormat"),value:"",text:"Remove color"}];for(const e of Zn)In.push({value:e.toLowerCase(),text:e.toUpperCase()});const On=new Map([["strong","bold"],["em","italic"],["i","italic"],["u","underline"],["s","strikethrough"],["sup","superscript"],["sub","subscript"],["code","code"]]),Dn=[{name:"undo",type:"button",icon:a.get("undo"),tooltip:"Undo",onClick:(e,t)=>{e.command.execute(t)}},{name:"redo",type:"button",icon:a.get("redo"),tooltip:"Redo",onClick:(e,t)=>{e.command.execute(t)}},{name:"selectAll",type:"button",icon:a.get("selectAll"),tooltip:"Select all",onClick:(e,t)=>{e.command.execute(t)}},{name:"paragraph",type:"button",icon:a.get("paragraph"),tooltip:"Paragraph",isSelected:e=>!!e.find((e=>"p"===e.name)),onClick:e=>{e.command.execute("heading","p")}},{name:"blockQuote",type:"button",icon:a.get("blockQuote"),tooltip:"Block quotation",isSelected:e=>!!e.find((e=>"blockquote"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"numberedList",type:"button",icon:a.get("numberedList"),tooltip:"Numbered list",isSelected:e=>!!e.find((e=>"ol"===e.name)),onClick:e=>{e.command.execute("list","numbered")}},{name:"bulletedList",type:"button",icon:a.get("bulletedList"),tooltip:"Bulleted list",isSelected:e=>!!e.find((e=>"ul"===e.name&&!e.node.hasAttr("type"))),onClick:e=>{e.command.execute("list","bulleted")}},{name:"checklist",type:"button",icon:a.get("checklist"),tooltip:"Checklist",isSelected:e=>!!e.find((e=>"ul"===e.name&&"checklist"===e.node.attr("type"))),onClick:e=>{e.command.execute("list","checklist")}},{name:"alignLeft",type:"button",icon:a.get("alignLeft"),tooltip:"Align left",isSelected:e=>!!e.find((e=>e.node.isBlock&&"left"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","left")}},{name:"alignCenter",type:"button",icon:a.get("alignCenter"),tooltip:"Align center",isSelected:e=>!!e.find((e=>e.node.isBlock&&"center"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","center")}},{name:"alignRight",type:"button",icon:a.get("alignRight"),tooltip:"Align right",isSelected:e=>!!e.find((e=>e.node.isBlock&&"right"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","right")}},{name:"alignJustify",type:"button",icon:a.get("alignJustify"),tooltip:"Align justify",isSelected:e=>!!e.find((e=>e.node.isBlock&&"justify"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","justify")}},{name:"increaseIndent",type:"button",icon:a.get("increaseIndent"),tooltip:"Increase indent",onClick:e=>{e.command.execute("indent","increase")}},{name:"decreaseIndent",type:"button",icon:a.get("decreaseIndent"),tooltip:"Decrease indent",onClick:e=>{e.command.execute("indent","decrease")}},{name:"bold",type:"button",icon:a.get("bold"),tooltip:"Bold",isDisabled:e=>!!e.find((e=>e.node.isHeading)),isSelected:e=>!!e.find((e=>"strong"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"italic",type:"button",icon:a.get("italic"),tooltip:"Italic",isSelected:e=>!!e.find((e=>"i"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"underline",type:"button",icon:a.get("underline"),tooltip:"Underline",isSelected:e=>!!e.find((e=>"u"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"strikethrough",type:"button",icon:a.get("strikethrough"),tooltip:"Strikethrough",isSelected:e=>!!e.find((e=>"s"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"superscript",type:"button",icon:a.get("superscript"),tooltip:"Superscript",isSelected:e=>!!e.find((e=>"sup"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"subscript",type:"button",icon:a.get("subscript"),tooltip:"Subscript",isSelected:e=>!!e.find((e=>"sub"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"code",type:"button",icon:a.get("code"),tooltip:"Inline code",isSelected:e=>!!e.find((e=>"code"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"removeFormat",type:"button",icon:a.get("removeFormat"),tooltip:"Remove format",onClick:(e,t)=>{e.command.execute(t)}},{name:"formatPainter",type:"button",icon:a.get("formatPainter"),tooltip:"Format painter",onClick:(e,t)=>{e.command.execute(t)}},{name:"link",type:"button",icon:a.get("link"),tooltip:"Link",onClick:(e,t)=>{e.command.execute(t)}},{name:"hr",type:"button",icon:a.get("hr"),tooltip:"Horizontal line",onClick:(e,t)=>{e.command.execute(t)}},{name:"codeBlock",type:"button",icon:a.get("codeBlock"),tooltip:"Code block",onClick:(e,t)=>{e.command.execute(t)}},{name:"heading",type:"dropdown",downIcon:a.get("down"),defaultValue:"p",tooltip:"Heading",width:"100px",menuType:"list",menuItems:[{value:"h1",text:'<span style="font-weight: bold; font-size: 26px;">Heading 1</span>'},{value:"h2",text:'<span style="font-weight: bold; font-size: 24px;">Heading 2</span>'},{value:"h3",text:'<span style="font-weight: bold; font-size: 22px;">Heading 3</span>'},{value:"h4",text:'<span style="font-weight: bold; font-size: 20px;">Heading 4</span>'},{value:"h5",text:'<span style="font-weight: bold; font-size: 18px;">Heading 5</span>'},{value:"h6",text:'<span style="font-weight: bold; font-size: 16px;">Heading 6</span>'},{value:"p",text:"Paragraph"}],selectedValues:e=>{const t=e.find((e=>e.node.isHeading||"p"===e.name));return t?[t.name]:[]},onSelect:(e,t)=>{e.command.execute("heading",t)}},{name:"list",type:"dropdown",downIcon:a.get("down"),icon:a.get("list"),defaultValue:"",tooltip:"List",width:"auto",menuType:"list",menuItems:Nn,selectedValues:e=>{let t="";for(const n of e){if("ol"===n.name){t="numbered";break}if("ul"===n.name&&!n.node.hasAttr("type")){t="bulleted";break}if("ul"===n.name&&"checklist"===n.node.attr("type")){t="checklist";break}}return[t]},onSelect:(e,t)=>{e.command.execute("list",t)}},{name:"align",type:"dropdown",downIcon:a.get("down"),icon:a.get("alignLeft"),defaultValue:"",tooltip:"Alignment",width:"auto",menuType:"list",menuItems:Ln,selectedValues:e=>{let t="";for(const n of e)if(n.node.isBlock){t=n.node.computedCSS("text-align");break}return[t]},onSelect:(e,t)=>{e.command.execute("align",t)}},{name:"indent",type:"dropdown",downIcon:a.get("down"),icon:a.get("increaseIndent"),defaultValue:"",tooltip:"Indent",width:"auto",menuType:"list",menuItems:Vn,onSelect:(e,t)=>{e.command.execute("indent",t)}},{name:"fontFamily",type:"dropdown",downIcon:a.get("down"),defaultValue:"Segoe UI",tooltip:"Font family",width:"100px",menuType:"list",menuItems:[{value:"Arial",text:'<span style="font-family: Arial;">Arial</span>'},{value:"Arial Black",text:"<span style=\"font-family: 'Arial Black';\">Arial Black</span>"},{value:"Comic Sans MS",text:"<span style=\"font-family: 'Comic Sans MS';\">Comic Sans MS</span>"},{value:"Courier New",text:"<span style=\"font-family: 'Courier New';\">Courier New</span>"},{value:"Georgia",text:'<span style="font-family: Georgia;">Georgia</span>'},{value:"Helvetica",text:'<span style="font-family: Helvetica;">Helvetica</span>'},{value:"Impact",text:'<span style="font-family: Impact;">Impact</span>'},{value:"Segoe UI",text:"<span style=\"font-family: 'Segoe UI';\">Segoe UI</span>"},{value:"Tahoma",text:'<span style="font-family: Tahoma;">Tahoma</span>'},{value:"Times New Roman",text:"<span style=\"font-family: 'Times New Roman';\">Times New Roman</span>"},{value:"Trebuchet MS",text:"<span style=\"font-family: 'Trebuchet MS';\">Trebuchet MS</span>"},{value:"Verdana",text:'<span style="font-family: Verdana;">Verdana</span>'}],selectedValues:e=>{for(const t of e)if("span"===t.name){return[t.node.css("font-family").replace(/['"]/g,"")]}return[]},onSelect:(e,t)=>{e.command.execute("fontFamily",t)}},{name:"fontSize",type:"dropdown",downIcon:a.get("down"),defaultValue:"16px",tooltip:"Font size",width:"65px",menuType:"list",menuItems:[{value:"12px",text:"12px"},{value:"14px",text:"14px"},{value:"16px",text:"16px"},{value:"18px",text:"18px"},{value:"22px",text:"22px"},{value:"24px",text:"24px"},{value:"32px",text:"32px"}],isDisabled:e=>!!e.find((e=>e.node.isHeading)),selectedValues:e=>{for(const t of e)if("span"===t.name){return[t.node.css("font-size").replace(/\.\d+/,"")]}return[]},onSelect:(e,t)=>{e.command.execute("fontSize",t)}},{name:"moreStyle",type:"dropdown",icon:a.get("more"),defaultValue:"",tooltip:"More style",width:"auto",menuType:"list",menuItems:$n,selectedValues:e=>{var t;const n=[];for(const o of e)if(o.node.isMark){const e=null!==(t=On.get(o.name))&&void 0!==t?t:o.name;n.push(e)}return n},onSelect:(e,t)=>{e.command.execute(t)}},{name:"fontColor",type:"dropdown",downIcon:a.get("down"),icon:a.get("fontColor"),accentIcon:a.get("fontColorAccent"),defaultValue:"#f5222d",tooltip:"Font color",width:"auto",menuType:"color",menuItems:In,selectedValues:e=>{for(const t of e)if("span"===t.name){return[g(t.node.computedCSS("color"))]}return[]},onSelect:(e,t)=>{e.command.execute("fontColor",t)}},{name:"highlight",type:"dropdown",downIcon:a.get("down"),icon:a.get("highlight"),accentIcon:a.get("highlightAccent"),defaultValue:"#fadb14",tooltip:"Highlight",width:"auto",menuType:"color",menuItems:In,selectedValues:e=>{for(const t of e)if("span"===t.name){return[g(t.node.computedCSS("background-color"))]}return[]},onSelect:(e,t)=>{e.command.execute("highlight",t)}},{name:"image",type:"upload",icon:a.get("image"),tooltip:"Image",accept:"image/*",multiple:!0}];function Rn(e){const{editor:t,file:n,onError:o,onSuccess:i}=e,{imageRequestMethod:s,imageRequestAction:r,imageRequestTypes:a}=t.config;if(a.indexOf(n.type)<0)throw new Error(`Cannot upload file because its type '${n.type}' is not found in ['${a.join("', '")}'].`);const l=t.insertBox("image",{url:URL.createObjectURL(n),status:"uploading",name:n.name,size:n.size,type:n.type,lastModified:n.lastModified});if(!l)throw new Error("The image box cannot be inserted outside the editor.");const c=ge({onProgress:e=>{const t=l.node.find(".lake-percent"),n=Math.round(e.percent);t.text(`${n<100?n:99} %`)},onError:(e,t)=>{H(e.toString(),t),l.updateValue("status","error"),l.render(),o&&o()},onSuccess:e=>{if(!e.url)return l.updateValue("status","error"),l.render(),void(o&&o());l.updateValue({status:"done",url:e.url}),l.render(),t.history.save(),i&&i()},file:n,action:r,method:s});return l.setData("xhr",c),l}const zn=["undo","redo","|","heading","fontSize","|","formatPainter","removeFormat","bold","moreStyle","|","fontColor","highlight","|","align","list","indent","link","blockQuote","hr"],jn=new Map;Dn.forEach((e=>{jn.set(e.name,e)}));function Pn(e,t,n,o){return new(n||(n=Promise))((function(i,s){function r(e){try{l(o.next(e))}catch(e){s(e)}}function a(e){try{l(o.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}l((o=o.apply(e,t||[])).next())}))}function Fn(e,t){const n=t.getEditor();if(!n)return;const o=t.getContainer(),i=e.closest(".lake-resizer").find(".lake-resizer-info"),s=e.attr("class").indexOf("-right")>=0,r=o.width(),a=o.height()/r;let l=0,c=0;const d=e=>{const t=e.clientX-l,n=Math.round(s?c+t:c-t),r=Math.round(a*n);o.css({width:`${n}px`,height:`${r}px`}),i.text(`${n} x ${r}`)};e.on("pointerdown",(t=>{const n=t;e.get(0).setPointerCapture(n.pointerId),l=n.clientX,c=o.width(),i.show(),e.on("pointermove",d)})),e.on("pointerup",(()=>{e.off("pointermove"),i.hide(),c=t.getContainer().width();const o=Math.round(a*c);t.updateValue({width:c,height:o}),n.history.save()})),e.on("pointercancel",(()=>{e.off("pointermove"),i.hide()}))}function qn(e){return Pn(this,void 0,void 0,(function*(){const t=V("<img />");return t.css({position:"absolute",top:"0",left:"-8888px","z-index":"-1",visibility:"hidden"}),new Promise((n=>{t.on("load",(()=>{const e=t.get(0),o=e.width,i=e.height;t.remove(),t.removeAttr("style"),n({node:t,width:o,height:i})})),t.on("error",(()=>{t.remove(),n({node:t})})),t.attr("src",e),V(document.body).append(t)}))}))}function Un(e,t){return Pn(this,void 0,void 0,(function*(){const n=t.value;t.getContainer().css({width:"",height:""});const o=V(h`
5
+ `;class nt{constructor(e){if(this.event=new Xe,"string"==typeof e){const t=Ge.get(e);if(void 0===t)throw new Error(`Box '${e}' has not been defined yet.`);const n=d(t.type),o=d(t.name);this.node=V(h`<lake-box type="${n}" name="${o}"></lake-box>`),t.value&&(this.value=t.value)}else{this.node=V(e);const t=Ge.get(this.name);if(void 0===t)throw new Error(`Box '${this.name}' has not been defined yet.`);t.value&&!this.node.hasAttr("value")&&(this.value=t.value)}Ye[this.node.id]||(Ye[this.node.id]={}),et[this.node.id]||(et[this.node.id]={setup:[],cleanup:[]})}addFramework(){let e=this.getContainer();0===e.length?(this.node.html(tt),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",(()=>{H(`Box '${this.name}' (id = ${this.node.id}) value:`),H(this.value)}))}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(_e(e))}set value(e){this.node.attr("value",Ue(JSON.stringify(e)))}updateValue(e,t){const n=this.value;"string"==typeof e?n[e]=t:k(e,((e,t)=>{n[e]=t})),this.value=n}getData(e){return Ye[this.node.id][e]}setData(e,t){Ye[this.node.id][e]=t}getEditor(){const e=this.node.closestContainer();return e.length>0?Qe.get(e.id):void 0}getContainer(){return this.node.find(".lake-box-container")}useEffect(e){et[this.node.id].setup.push(e)}render(){et[this.node.id].setup=[],et[this.node.id].cleanup=[];const e=Ge.get(this.name);if(void 0===e)return;this.addFramework();const t=e.render(this);if(void 0!==t){const e=this.getContainer(),n=e.clone(!1);n.append(t),fe(e,n)}for(const e of et[this.node.id].setup){const t=e();void 0!==t&&et[this.node.id].cleanup.push(t)}H(`Box '${this.name}' (id = ${this.node.id}) rendered`)}unmount(){for(const e of et[this.node.id].cleanup)e();Ye[this.node.id]={},et[this.node.id].setup=[],et[this.node.id].cleanup=[],this.node.empty(),H(`Box '${this.name}' (id = ${this.node.id}) unmounted`)}getHTML(){const e=Ge.get(this.name);return void 0===e?"":void 0===e.html?this.node.outerHTML():e.html(this)}}const ot={id:/^[\w-]+$/,class:/^[\w-]+$/,style:{"text-align":["left","center","right","justify"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function it(){return{h1:Object.assign({},ot),h2:Object.assign({},ot),h3:Object.assign({},ot),h4:Object.assign({},ot),h5:Object.assign({},ot),h6:Object.assign({},ot),p:Object.assign({},ot),blockquote:Object.assign(Object.assign({},ot),{type:["success","info","warning","error"]}),ul:Object.assign(Object.assign({},ot),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},ot),{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:["left","center","right"]},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"]}}}class st{constructor(e,t=it()){this.rules=t,this.source="string"==typeof e?this.parseHTML(e):e}parseHTML(e){const t=(new DOMParser).parseFromString(e,"text/html");return new L(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 n=e.name,o=t[n];if(!o)return"";"string"==typeof o&&(n=o,o=t[n]);const i=e.get(0);if(!i.hasAttributes())return n;const s=new Map;for(const e of i.attributes)if(o[e.name]&&("style"!==e.name&&st.matchRule(o[e.name],e.value)&&s.set(e.name,e.value),"style"===e.name)){const t=o.style,n=new Map;k(m(e.value),((e,o)=>{t[e]&&st.matchRule(t[e],o)&&n.set(e,o)})),s.set("style",n)}let r=n;for(const[e,t]of s)if("style"===e){let e="";for(const[n,o]of t)e+=`${n}: ${o.replace(/"/g,"&quot;")}; `;""!==e&&(r+=` style="${e.trim()}"`)}else r+=` ${e}="${t}"`;return r}static getClosedTagString(e,t){let n=e.name;const o=t[n];return o?("string"==typeof o&&(n=o),n):""}static getTrimmedText(e){const t=e.parent(),n=e.prev(),o=e.next();let i=e.text();return(n.isBlock||n.isBlockBox)&&(o.isBlock||o.isBlockBox)||0===n.length&&0===o.length&&t.isBlock?i=i.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):n.isBlock||n.isBlockBox||0===n.length&&t.isBlock?i=i.replace(/^[\u0020\t\r\n]+/,""):(o.isBlock||o.isBlockBox||0===o.length&&t.isBlock)&&(i=i.replace(/[\u0020\t\r\n]+$/,"")),i}getHTML(){const e=this.rules;let t="";for(const n of function*t(n){let o=n.first();for(;o.length>0;){const n=o.next();if(o.isText)yield d(st.getTrimmedText(o));else if(o.isVoid){const t=st.getOpenTagString(o,e);""!==t&&(yield`<${t} />`)}else if(o.isElement){const n=st.getOpenTagString(o,e),i=st.getClosedTagString(o,e);""!==n&&(yield`<${n}>`),o.isBox||(yield*t(o)),""!==i&&(yield`</${i}>`)}o=n}}(this.source))t+=n;return t.trim()}getNodeList(){const e=this.getHTML();return this.parseHTML(e).children()}getFragment(){const e=this.getHTML(),t=this.parseHTML(e),n=document.createDocumentFragment();let o=t.first();for(;o.length>0;){const e=o.next();n.appendChild(o.get(0)),o=e}return n}}class rt{constructor(e){this.content=e}getHTML(){let e=this.content;return e=e.replace(/ {2}/g,"  "),e=d(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 st(this.getHTML()).getFragment()}}function at(e,t){if(e.commonAncestor.isOutside)return;const n=(t=V(t)).get(0),o=e.get();o.insertNode(n),o.setEndAfter(n),o.collapse(!1)}function lt(e){if(e.commonAncestor.isOutside)return{anchor:new L,focus:new L};const t=e.startNode.closest("lake-box");if(t.length>0)return e.isBoxLeft?t.attr("focus","left"):e.isBoxRight?t.attr("focus","right"):t.attr("focus","center"),{anchor:new L,focus:t};if(e.isCollapsed){const t=e.clone();t.collapseToEnd();const n=V('<lake-bookmark type="focus" />');return at(t,n),{anchor:new L,focus:n}}const n=e.clone();n.collapseToStart();const o=V('<lake-bookmark type="anchor" />');at(n,o);const i=e.clone();i.collapseToEnd();const s=V('<lake-bookmark type="focus" />');return at(i,s),{anchor:o,focus:s}}function ct(e,t){const n=e.prev(),o=e.next();if(n.isText&&o.isText){const t=e.parent();P(t),e.remove(),t.get(0).normalize()}else if(0===n.length&&0===o.length){if(e.parent().isMark&&t){const n=new L(document.createTextNode("​"));e.before(n),t.setStartAfter(n),t.collapseToStart()}e.remove()}else e.remove()}function dt(e,t){const n=t.anchor,o=t.focus;if(n.length>0&&0===o.length)ct(n);else{if(o.length>0&&0===n.length){if(o.isBox){const t=new nt(o);0===t.getContainer().length&&t.render();const n=o.attr("focus");return"left"===n?e.selectBoxLeft(o):"center"===n?e.selectBox(o):e.selectBoxRight(o),void o.removeAttr("focus")}return e.setStartBefore(o),e.collapseToStart(),void ct(o,e)}if(n.length>0&&o.length>0){const t=new $;t.selectNode(n),t.collapseToEnd(),-1===t.compareAfterNode(o)?(e.setStartBefore(o),ct(o),e.setEndBefore(n),ct(n)):(e.setStartBefore(n),ct(n),e.setEndBefore(o),ct(o))}}}function ht(e){if(e.commonAncestor.isOutside)return;q(e.getBlocks())}function ut(e){if(e.isCollapsed)return;if(e.adapt(),e.isInoperative)return;const t=e.startNode.closestBlock(),n=e.endNode.closestBlock(),o=t.get(0)===n.get(0);if(e.get().deleteContents(),e.adaptBlock(),o){const t=e.getBlocks()[0];return void(t&&t.isEmpty&&(I(t,V("<br />")),e.shrinkAfter(t)))}const i=e.getBlocks()[0];if(!i)return;const s=i.prev();if(0===s.length)return;const r=lt(e);R(s,i),dt(e,r),ht(e)}function ft(e,t){if(e.commonAncestor.isOutside)return;e.isCollapsed?e.adaptBox():ut(e);O(e.startNode.closestBlock());const n=lt(e);n.focus.before(t),dt(e,n),e.adaptBlock()}function pt(e,t){const n=V(t),o=document.createDocumentFragment();n.each((e=>{o.appendChild(e)})),ft(e,o)}function gt(e,t){if(e.commonAncestor.isOutside)return;if(e.isCollapsed&&e.isBox)return;if("string"!=typeof t){const n=e.getBlocks();for(const e of n)e.css(t);return}const n=V(t),o=n.name,i=n.get(0).attributes,s=e.getBlocks();if(s.length>0){const t=lt(e);for(const e of s)if(e.name===o&&0===n.first().length)for(const t of i)e.attr(t.name,t.value);else{const t=n.clone(!0);e.isList&&""!==e.attr("indent")&&t.attr("indent",e.attr("indent"));const o=z(t);let i=e.first();for(;i.length>0;){const e=i.next();o.append(i),o.name!==i.name&&"li"!==i.name||i.remove(!0),i=e}e.replaceWith(t)}return dt(e,t),void ht(e)}const r=lt(e),a=function(e){const t=e.commonAncestor.closest('div[contenteditable="true"],td');let n=[];if(0===t.length)return n;let o=t.first(),i=!0;for(;o.length>0;){if(o.isMark||o.isText||o.isBookmark||o.isInlineBox)n.push(o);else{if(!i)break;n=[]}e.intersectsNode(o)&&(i=!1),o=o.next()}return n}(e),l=j(a,n);dt(e,r),ht(e),l.isEmpty&&(I(l,V("<br />")),e.shrinkAfter(l))}function mt(e){if(e.commonAncestor.isOutside)return{left:null,right:null};e.isCollapsed?e.adaptBox():ut(e);const t=e.startNode,n=t.closestOperableBlock();if(0===n.length)return{left:null,right:null};let o=n.parent();o.isOutside&&(o=t.closestContainer());const i=Z(t,e.startOffset,o);let s=null,r=null;return i&&(s=i.left,r=i.right),!i&&t.isBlock&&(e.startOffset>0&&(s=t.children()[e.startOffset-1]),r=t.children()[e.startOffset],r&&!r.isBlock&&(r=null)),s&&s.isEmpty&&I(s,V("<br />")),r&&(r.isEmpty?(I(r,V("<br />")),e.shrinkAfter(r)):e.shrinkBefore(r)),ht(e),{left:s,right:r}}function vt(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function xt(e,t,n){let o=null,i=null,s=e.closestBlock();0===s.length&&(s=e.closestContainer());const r=Z(e,t,s);return r&&(n?(vt(r.left),vt(r.right),r.left.isEmpty||(o=r.left),r.right.isEmpty||(i=r.right)):(o=r.left,i=r.right)),{left:o,right:i}}function kt(e,t=!0){if(e.commonAncestor.isOutside)return{left:null,center:null,right:null};if(e.adaptBox(),e.isCollapsed){const n=xt(e.startNode,e.startOffset,t);return n.left?(e.setStartAfter(n.left),e.collapseToStart()):n.right&&(e.setStartBefore(n.right),e.collapseToStart()),{left:n.left,center:null,right:n.right}}const n=xt(e.startNode,e.startOffset,t);n.left?e.setStartAfter(n.left):n.right&&e.setStartBefore(n.right);const o=xt(e.endNode,e.endOffset,t);return o.left?e.setEndAfter(o.left):o.right&&e.setEndBefore(o.right),{left:n.left,center:o.left,right:o.right}}function wt(e,t){const n=e.text();let o=e;for(;o.length>0;){const e=o.parent();if(!e.isMark||n!==e.text()||!o.isText&&o.name===t&&""!==o.attr("style"))break;o=e}return o}function bt(e,t){if(e.commonAncestor.isOutside)return;let n=V(t);const o=n.name,i=m(n.attr("style"));if(e.isCollapsed){if(e.isBox){const t=e.startNode.closest("lake-box");if("block"===new nt(t).type){const n=V("<p><br /></p>");e.isBoxLeft?t.before(n):t.after(n),e.shrinkAfter(n)}else e.adaptBox()}O(e.startNode.closestBlock());const t=new L(document.createTextNode("​")),s=kt(e);if(s.left){const e=function(e){if(!e.isMark)return null;let t=e.clone(),n=e.last();for(;n.length>0;){if(n.isMark){const e=n.clone();t.append(e),t=e}n=n.last()}return t}(s.left);e&&(e.name===o?(e.css(i),n=e):(I(e,t),n.append(e)))}return""===n.text()&&n.append(t),at(e,n),function(e){const t=e.prev();t.length>0&&t.isText&&t.isEmpty&&t.remove();const n=e.next();n.length>0&&n.isText&&n.isEmpty&&n.remove()}(n),void e.shrinkAfter(n)}kt(e);const s=e.getMarks(!0),r=lt(e);for(const e of s)if(!e.isEmpty&&e.isText){const t=wt(e,o);if(t.isMark&&t.name===o)t.css(i);else{const e=n.clone();t.before(e),e.append(t)}}dt(e,r)}function yt(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function Bt(e,t){if(e.commonAncestor.isOutside)return;let n;if(t){n=V(t).name}if(e.isCollapsed){if(e.isBox)return;if(n&&0===e.commonAncestor.closest(n).length)return;const t=kt(e,!1);if(!t.left)return;t.right&&yt(t.right);const o=new L(document.createTextNode("​")),i=function(e,t){if(!e.isMark||!t)return null;let n=e.clone(),o=e.last();for(;o.length>0;){if(o.isMark&&o.name!==t){const e=o.clone();n.append(e),n=e}o=o.last()}if(n.name===t){if(!(n.first().length>0))return null;n=n.first()}return n}(t.left,n);return i?(I(i,o),t.left.after(i),yt(t.left),void e.shrinkAfter(i)):(t.left.after(o),yt(t.left),o.prev().isText?(e.setStartAfter(o.prev()),e.collapseToStart(),void o.remove()):(e.setStartAfter(o),void e.collapseToStart()))}kt(e);const o=e.getMarks(),i=lt(e);for(const e of o)if(!n||e.name===n){const t=e.parent();e.remove(!e.isEmpty),t.length>0&&t.get(0).normalize()}P(e.commonAncestor),dt(e,i)}function At(e,t){if(e.commonAncestor.isOutside)return null;const n=V(t);if(e.isCollapsed){let t=e.commonAncestor.closest("a");if(0===t.length){t=n.clone(!0);return O(e.startNode.closestBlock()),at(e,t),t}return""!==n.attr("href")&&t.attr({href:n.attr("href")}),t}kt(e);const o=lt(e);for(const t of e.commonAncestor.getWalker())"a"===t.name&&e.intersectsNode(t)&&t.remove(!0);const i=n.clone(!1);o.anchor.after(i);let s=i.next();for(;s.length>0;){const e=s.next();if(!s.isMark&&!s.isText)break;i.append(s),s=e}return 0===i.first().length&&i.remove(),dt(e,o),i}var Ct=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)},St="object"==typeof We&&We&&We.Object===Object&&We,Mt="object"==typeof self&&self&&self.Object===Object&&self,Tt=St||Mt||Function("return this")(),Ht=Tt,Et=function(){return Ht.Date.now()},Nt=/\s/;var Lt=function(e){for(var t=e.length;t--&&Nt.test(e.charAt(t)););return t},Vt=Lt,$t=/^\s+/;var Zt=function(e){return e?e.slice(0,Vt(e)+1).replace($t,""):e},It=Tt.Symbol,Ot=It,Dt=Object.prototype,Rt=Dt.hasOwnProperty,zt=Dt.toString,jt=Ot?Ot.toStringTag:void 0;var Pt=function(e){var t=Rt.call(e,jt),n=e[jt];try{e[jt]=void 0;var o=!0}catch(e){}var i=zt.call(e);return o&&(t?e[jt]=n:delete e[jt]),i},Ft=Object.prototype.toString;var qt=Pt,Ut=function(e){return Ft.call(e)},_t=It?It.toStringTag:void 0;var Wt=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":_t&&_t in Object(e)?qt(e):Ut(e)},Kt=function(e){return null!=e&&"object"==typeof e};var Jt=Zt,Xt=Ct,Gt=function(e){return"symbol"==typeof e||Kt(e)&&"[object Symbol]"==Wt(e)},Qt=/^[-+]0x[0-9a-f]+$/i,Yt=/^0b[01]+$/i,en=/^0o[0-7]+$/i,tn=parseInt;var nn=Ct,on=Et,sn=function(e){if("number"==typeof e)return e;if(Gt(e))return NaN;if(Xt(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=Xt(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=Jt(e);var n=Yt.test(e);return n||en.test(e)?tn(e.slice(2),n?2:8):Qt.test(e)?NaN:+e},rn=Math.max,an=Math.min;var ln=function(e,t,n){var o,i,s,r,a,l,c=0,d=!1,h=!1,u=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function f(t){var n=o,s=i;return o=i=void 0,c=t,r=e.apply(s,n)}function p(e){var n=e-l;return void 0===l||n>=t||n<0||h&&e-c>=s}function g(){var e=on();if(p(e))return m(e);a=setTimeout(g,function(e){var n=t-(e-l);return h?an(n,s-(e-c)):n}(e))}function m(e){return a=void 0,u&&o?f(e):(o=i=void 0,r)}function v(){var e=on(),n=p(e);if(o=arguments,i=this,l=e,n){if(void 0===a)return function(e){return c=e,a=setTimeout(g,t),d?f(e):r}(l);if(h)return clearTimeout(a),a=setTimeout(g,t),f(l)}return void 0===a&&(a=setTimeout(g,t)),r}return t=sn(t)||0,nn(n)&&(d=!!n.leading,s=(h="maxWait"in n)?rn(sn(n.maxWait)||0,t):s,u="trailing"in n?!!n.trailing:u),v.cancel=function(){void 0!==a&&clearTimeout(a),c=0,o=l=i=a=void 0},v.flush=function(){return void 0===a?r:m(on())},v},cn=Ke(ln),dn="0.0.1";function hn(e){const t=e.get(0),n={};if(t.hasAttributes())for(const e of t.attributes)n[e.name]=e.value;return n}class un{constructor(e){const t=window.getSelection();if(!t)throw new Error("Selection object is null.");this.selection=t,this.container=e,this.range=this.getRangeFromNativeSelection(),this.appliedItems=[]}getRangeFromNativeSelection(){if(this.selection.rangeCount>0){const e=this.selection.getRangeAt(0);return new $(e)}return new $}addRangeToNativeSelection(){this.selection.removeAllRanges(),this.selection.addRange(this.range.get())}syncByRange(){const e=this.getRangeFromNativeSelection();this.range.get()!==e.get()&&(this.range=e)}synByBookmark(){const e=this.range,t=this.container,n=t.find("lake-box[focus]");if(n.length>0)return dt(e,{anchor:new L,focus:n}),void this.addRangeToNativeSelection();dt(e,{anchor:t.find('lake-bookmark[type="anchor"]'),focus:t.find('lake-bookmark[type="focus"]')}),this.addRangeToNativeSelection()}getAppliedItems(){const e=[];return function(e,t){let n=t.startNode;for(n.isText&&(n=n.parent());n.length>0&&n.isInside;)e.push({node:n,name:n.name,attributes:hn(n),styles:m(n.attr("style"))}),n=n.parent()}(e,this.range),function(e,t){const n=t.startNode;let o;if(n.isText&&n.text().length===t.startOffset){const e=n.next();e.length>0&&e.isElement&&(o=e)}if(n.isElement){const e=n.children();if(e.length>0){const n=e[t.startOffset];n&&n.isElement&&(o=n)}}if(o){let t=o;for(;t.length>0;)t.isElement&&e.push({node:t,name:t.name,attributes:hn(t),styles:m(t.attr("style"))}),t=t.first()}}(e,this.range),e}insertBookmark(){return lt(this.range)}toBookmark(e){return dt(this.range,e)}insertNode(e){return at(this.range,e)}insertFragment(e){return ft(this.range,e)}insertContents(e){return pt(this.range,e)}deleteContents(){return ut(this.range)}setBlocks(e){return gt(this.range,e)}splitBlock(){return mt(this.range)}splitMarks(e){return kt(this.range,e)}addMark(e){return bt(this.range,e)}removeMark(e){return Bt(this.range,e)}fixList(){return ht(this.range)}insertLink(e){return At(this.range,e)}}class fn{constructor(){this.commandMap=new Map,this.event=new Xe}add(e,t){this.commandMap.set(e,t)}getNames(){return Array.from(this.commandMap.keys())}execute(e,...t){const n=this.commandMap.get(e);if(void 0===n)throw new Error(`Command '${e}' does not exist.`);this.event.emit("beforeexecute",e),n.apply(this,t),this.event.emit("execute",e),H(`Command '${e}' executed`)}}var pn,gn={exports:{}};pn=gn,function(e){function t(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function n(e,n,o,i,s,r){return t((a=t(t(n,e),t(i,r)))<<(l=s)|a>>>32-l,o);var a,l}function o(e,t,o,i,s,r,a){return n(t&o|~t&i,e,t,s,r,a)}function i(e,t,o,i,s,r,a){return n(t&i|o&~i,e,t,s,r,a)}function s(e,t,o,i,s,r,a){return n(t^o^i,e,t,s,r,a)}function r(e,t,o,i,s,r,a){return n(o^(t|~i),e,t,s,r,a)}function a(e,n){var a,l,c,d,h;e[n>>5]|=128<<n%32,e[14+(n+64>>>9<<4)]=n;var u=1732584193,f=-271733879,p=-1732584194,g=271733878;for(a=0;a<e.length;a+=16)l=u,c=f,d=p,h=g,u=o(u,f,p,g,e[a],7,-680876936),g=o(g,u,f,p,e[a+1],12,-389564586),p=o(p,g,u,f,e[a+2],17,606105819),f=o(f,p,g,u,e[a+3],22,-1044525330),u=o(u,f,p,g,e[a+4],7,-176418897),g=o(g,u,f,p,e[a+5],12,1200080426),p=o(p,g,u,f,e[a+6],17,-1473231341),f=o(f,p,g,u,e[a+7],22,-45705983),u=o(u,f,p,g,e[a+8],7,1770035416),g=o(g,u,f,p,e[a+9],12,-1958414417),p=o(p,g,u,f,e[a+10],17,-42063),f=o(f,p,g,u,e[a+11],22,-1990404162),u=o(u,f,p,g,e[a+12],7,1804603682),g=o(g,u,f,p,e[a+13],12,-40341101),p=o(p,g,u,f,e[a+14],17,-1502002290),u=i(u,f=o(f,p,g,u,e[a+15],22,1236535329),p,g,e[a+1],5,-165796510),g=i(g,u,f,p,e[a+6],9,-1069501632),p=i(p,g,u,f,e[a+11],14,643717713),f=i(f,p,g,u,e[a],20,-373897302),u=i(u,f,p,g,e[a+5],5,-701558691),g=i(g,u,f,p,e[a+10],9,38016083),p=i(p,g,u,f,e[a+15],14,-660478335),f=i(f,p,g,u,e[a+4],20,-405537848),u=i(u,f,p,g,e[a+9],5,568446438),g=i(g,u,f,p,e[a+14],9,-1019803690),p=i(p,g,u,f,e[a+3],14,-187363961),f=i(f,p,g,u,e[a+8],20,1163531501),u=i(u,f,p,g,e[a+13],5,-1444681467),g=i(g,u,f,p,e[a+2],9,-51403784),p=i(p,g,u,f,e[a+7],14,1735328473),u=s(u,f=i(f,p,g,u,e[a+12],20,-1926607734),p,g,e[a+5],4,-378558),g=s(g,u,f,p,e[a+8],11,-2022574463),p=s(p,g,u,f,e[a+11],16,1839030562),f=s(f,p,g,u,e[a+14],23,-35309556),u=s(u,f,p,g,e[a+1],4,-1530992060),g=s(g,u,f,p,e[a+4],11,1272893353),p=s(p,g,u,f,e[a+7],16,-155497632),f=s(f,p,g,u,e[a+10],23,-1094730640),u=s(u,f,p,g,e[a+13],4,681279174),g=s(g,u,f,p,e[a],11,-358537222),p=s(p,g,u,f,e[a+3],16,-722521979),f=s(f,p,g,u,e[a+6],23,76029189),u=s(u,f,p,g,e[a+9],4,-640364487),g=s(g,u,f,p,e[a+12],11,-421815835),p=s(p,g,u,f,e[a+15],16,530742520),u=r(u,f=s(f,p,g,u,e[a+2],23,-995338651),p,g,e[a],6,-198630844),g=r(g,u,f,p,e[a+7],10,1126891415),p=r(p,g,u,f,e[a+14],15,-1416354905),f=r(f,p,g,u,e[a+5],21,-57434055),u=r(u,f,p,g,e[a+12],6,1700485571),g=r(g,u,f,p,e[a+3],10,-1894986606),p=r(p,g,u,f,e[a+10],15,-1051523),f=r(f,p,g,u,e[a+1],21,-2054922799),u=r(u,f,p,g,e[a+8],6,1873313359),g=r(g,u,f,p,e[a+15],10,-30611744),p=r(p,g,u,f,e[a+6],15,-1560198380),f=r(f,p,g,u,e[a+13],21,1309151649),u=r(u,f,p,g,e[a+4],6,-145523070),g=r(g,u,f,p,e[a+11],10,-1120210379),p=r(p,g,u,f,e[a+2],15,718787259),f=r(f,p,g,u,e[a+9],21,-343485551),u=t(u,l),f=t(f,c),p=t(p,d),g=t(g,h);return[u,f,p,g]}function l(e){var t,n="",o=32*e.length;for(t=0;t<o;t+=8)n+=String.fromCharCode(e[t>>5]>>>t%32&255);return n}function c(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t<n.length;t+=1)n[t]=0;var o=8*e.length;for(t=0;t<o;t+=8)n[t>>5]|=(255&e.charCodeAt(t/8))<<t%32;return n}function d(e){var t,n,o="0123456789abcdef",i="";for(n=0;n<e.length;n+=1)t=e.charCodeAt(n),i+=o.charAt(t>>>4&15)+o.charAt(15&t);return i}function h(e){return unescape(encodeURIComponent(e))}function u(e){return function(e){return l(a(c(e),8*e.length))}(h(e))}function f(e,t){return function(e,t){var n,o,i=c(e),s=[],r=[];for(s[15]=r[15]=void 0,i.length>16&&(i=a(i,8*e.length)),n=0;n<16;n+=1)s[n]=909522486^i[n],r[n]=1549556828^i[n];return o=a(s.concat(c(t)),512+8*t.length),l(a(r.concat(o),640))}(h(e),h(t))}function p(e,t,n){return t?n?f(t,e):d(f(t,e)):n?u(e):d(u(e))}pn.exports?pn.exports=p:e.md5=p}(We);var mn=Ke(gn.exports);const vn=new Map;class xn{constructor(e){this.selection=e,this.container=e.container,this.list=[],this.index=0,this.canSave=!0,this.limit=100,this.event=new Xe}removeBookmark(e){return e.replace(/(<lake-box[^>]+)\s+focus="\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 st(e).getHTML()}addIdToBoxes(e){e.find("lake-box").each((e=>{const t=new L(e),n=mn(`${t.attr("type")}-${t.attr("name")}-${t.attr("value")}`);t.attr("id",n)}))}removeIdfromBoxes(e){e.find("lake-box").each((e=>{new L(e).removeAttr("id")}))}morphContainer(e){const t=this.container,n={beforeChildrenUpdated:e=>{if("lake-box"===new L(e).name)return!1},afterAttributeUpdated:(e,n)=>{const o=new L(n);if("value"===e&&"lake-box"===o.name){const e=vn.get(t.id);if(!e)return;e.delete(o.id)}}},o=e.clone(!0);this.addIdToBoxes(t),this.addIdToBoxes(o),fe(t,o,{callbacks:n}),this.removeIdfromBoxes(t),this.removeIdfromBoxes(o)}cloneContainer(){const e=this.selection.range,t=this.container.clone(!0);if(t.find("lake-box").each((e=>{new nt(e).getContainer().empty()})),e.commonAncestor.isOutside)return t;if(e.isInsideBox)return t;const n=e.startNode.path(),o=e.endNode.path(),i=t.find(n),s=t.find(o),r=e.clone();return r.setStart(i,e.startOffset),r.setEnd(s,e.endOffset),lt(r),t}get count(){return this.list.length}get canUndo(){return this.index>1&&!!this.list[this.index-1]}get canRedo(){return!!this.list[this.index]}undo(){if(!this.list[this.index-1])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index>0;){const t=this.list[this.index-1];if(!t)break;const n=this.getValue(t);if(this.removeBookmark(n)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("undo",n);break}if(1===this.index)break;this.index--}this.selection.synByBookmark(),H(`History undone, the last index is ${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 n=this.getValue(t);if(this.removeBookmark(n)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("redo",n);break}}this.selection.synByBookmark(),H(`History redone, the last index is ${this.index}`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(){if(!this.canSave)return;const e=this.cloneContainer(),t=this.getValue(e);this.list[this.index-1]&&this.removeBookmark(this.getValue(this.list[this.index-1]))===this.removeBookmark(t)||(this.list.splice(this.index,1/0,e),this.index++,this.list.length>this.limit&&(this.list.shift(),this.index=this.list.length),this.event.emit("save",t),H(`History saved, the last index is ${this.index}`))}}var kn=["Shift","Meta","Alt","Control"],wn="object"==typeof navigator?navigator.platform:"",bn=/Mac|iPod|iPhone|iPad/.test(wn),yn=bn?"Meta":"Control",Bn="Win32"===wn?["Control","Alt"]:bn?["Alt"]:[];function An(e,t){return"function"==typeof e.getModifierState&&(e.getModifierState(t)||Bn.includes(t)&&e.getModifierState("AltGraph"))}function Cn(e){return e.trim().split(" ").map((function(e){var t=e.split(/\b\+/),n=t.pop();return[t=t.map((function(e){return"$mod"===e?yn:e})),n]}))}function Sn(e,t){var n;void 0===t&&(t={});var o=null!=(n=t.timeout)?n:1e3,i=Object.keys(e).map((function(t){return[Cn(t),e[t]]})),s=new Map,r=null;return function(e){e instanceof KeyboardEvent&&(i.forEach((function(t){var n=t[0],o=t[1],i=s.get(n)||n;!function(e,t){return!(t[1].toUpperCase()!==e.key.toUpperCase()&&t[1]!==e.code||t[0].find((function(t){return!An(e,t)}))||kn.find((function(n){return!t[0].includes(n)&&t[1]!==n&&An(e,n)})))}(e,i[0])?An(e,e.key)||s.delete(n):i.length>1?s.set(n,i.slice(1)):(s.delete(n),o(e))})),r&&clearTimeout(r),r=setTimeout(s.clear.bind(s),o))}}const Mn=new Map([["#","shift+#"]]);class Tn{constructor(e){this.container=e,this.keydownEventList=[],this.keyupEventList=[]}normalizeType(e){var t;return e=(e=null!==(t=Mn.get(e))&&void 0!==t?t:e).replace(/(^|\+|\s)mod(\+|\s|$)/g,"$1$mod$2").replace(/shift|control|alt|meta|enter|tab|backspace|delete|space|escape|arrow-left|arrow-right|arrow-up|arrow-down/,(e=>e.charAt(0).toUpperCase()+u(e.substring(1)))).replace(/(^|\+|\s)([a-z])(\+|\s|$)/g,((e,t,n,o)=>`${t}Key${n.toUpperCase()}${o}`))}setKeydown(e,t){const n=Sn({[e=this.normalizeType(e)]:e=>t(e)});this.keydownEventList.push({type:e,listener:t}),this.container.on("keydown",n)}setKeyup(e,t){const n=Sn({[e=this.normalizeType(e)]:e=>t(e)});this.keyupEventList.push({type:e,listener:t}),this.container.on("keyup",n)}keydown(e){e=this.normalizeType(e);for(const t of this.keydownEventList)t.type===e&&t.listener(new Event(e))}keyup(e){e=this.normalizeType(e);for(const t of this.keyupEventList)t.type===e&&t.listener(new Event(e))}}const Hn={value:"<p><br /><focus /></p>",readonly:!1,spellcheck:!1,minChangeSize:5,imageRequestMethod:"POST",imageRequestAction:"/upload",imageRequestTypes:["image/gif","image/jpeg","image/png","image/svg+xml"]};class En{constructor(e){if(!e.root)throw new Error("The root of the config must be specified.");this.root=V(e.root),this.config=Object.assign(Object.assign({},Hn),e),this.containerWrapper=V('<div class="lake-container-wrapper" />'),this.container=V('<div class="lake-container" />'),this.overlayContainer=V('<div class="lake-overlay" />'),this.popupContainer=V('<div class="lake-popup lake-custom-properties" />'),this.isComposing=!1,this.readonly=this.config.readonly,this.root.addClass("lake-custom-properties"),this.container.attr({contenteditable:this.readonly?"false":"true",spellcheck:this.config.spellcheck?"true":"false"}),this.event=new Xe,this.selection=new un(this.container),this.command=new fn,this.history=new xn(this.selection),this.keystroke=new Tn(this.container),this.box=En.box,this.unsavedInputData="",Qe.set(this.container.id,this),this.beforeunloadListener=()=>{this.commitUnsavedInputData()};const t=cn((()=>{if(0===this.root.first().length)return;const e=this.selection.range,t=e.clone();t.adaptBox(),this.box.findAll(this).each((n=>{const o=new nt(n),i=o.getContainer();if(0!==i.length){if(e.compareBeforeNode(i)<0&&e.compareAfterNode(i)>0&&(!e.isCollapsed||e.startNode.get(0)!==i.get(0)||0!==e.startOffset))return i.removeClass("lake-box-selected"),i.removeClass("lake-box-focused"),void i.addClass("lake-box-activated");if(t.intersectsNode(o.node))return i.removeClass("lake-box-activated"),void(e.isCollapsed?(i.removeClass("lake-box-selected"),i.addClass("lake-box-focused")):(i.removeClass("lake-box-focused"),i.addClass("lake-box-selected")));i.removeClass("lake-box-activated"),i.removeClass("lake-box-focused"),i.removeClass("lake-box-selected")}}))}),50,{leading:!1,trailing:!0,maxWait:50});this.selectionchangeListener=()=>{this.selection.syncByRange(),this.selection.appliedItems=this.selection.getAppliedItems(),t(),this.event.emit("selectionchange")},this.clickListener=e=>{const t=new L(e.target);this.event.emit("click",t)},this.mouseoverListener=e=>{const t=new L(e.target);this.event.emit("mouseover",t)},this.resizeListener=()=>{this.event.emit("resize")}}inputInBoxStrip(){const e=this.selection,t=e.range,n=t.startNode.closest(".lake-box-strip"),o=n.closest("lake-box");if("inline"===new nt(o).type)t.isBoxLeft?(t.setStartBefore(o),t.collapseToStart()):(t.setStartAfter(o),t.collapseToStart());else{const e=V("<p />");t.isBoxLeft?o.before(e):o.after(e),t.shrinkAfter(e)}const i=n.text();n.html("<br />"),e.insertNode(document.createTextNode(i))}bindInputEvents(){this.container.on("compositionstart",(()=>{this.isComposing=!0})),this.container.on("compositionend",(()=>{this.isComposing=!1})),this.container.on("beforeinput",(()=>{const e=this.selection.range;(e.isBoxLeft||e.isBoxRight)&&this.commitUnsavedInputData()})),this.container.on("input",(e=>{const t=e;window.setTimeout((()=>{var e;const n=this.selection.range;if(!n.isInsideBox)if(this.isComposing)this.event.emit("input",t);else{if("insertText"===t.inputType||"insertCompositionText"===t.inputType)if(n.isBoxLeft||n.isBoxRight)this.inputInBoxStrip();else if(this.unsavedInputData+=null!==(e=t.data)&&void 0!==e?e:"",this.unsavedInputData.length<this.config.minChangeSize)return void this.event.emit("input",t);this.history.save(),this.unsavedInputData="",this.event.emit("input",t)}}),0)})),this.command.event.on("beforeexecute",(()=>this.commitUnsavedInputData()))}bindHistoryEvents(){this.history.event.on("undo",(e=>{this.box.renderAll(this),this.event.emit("change",e)})),this.history.event.on("redo",(e=>{this.box.renderAll(this),this.event.emit("change",e)})),this.history.event.on("save",(e=>{this.box.rectifyInstances(this),this.event.emit("change",e)}))}commitUnsavedInputData(){this.unsavedInputData.length>0&&(this.history.save(),this.unsavedInputData="")}prepareOperation(){this.commitUnsavedInputData(),this.history.pause()}commitOperation(){this.history.continue(),this.history.save()}focus(){this.container.focus()}blur(){this.container.blur()}setValue(e){e=v(e);const t=new st(e).getFragment();this.container.empty(),this.container.append(t),En.box.renderAll(this),this.selection.synByBookmark()}getValue(){const e=this.selection.insertBookmark();let t=new st(this.container).getHTML();return t=x(t),this.selection.toBookmark(e),t}insertBox(e,t){const n=function(e,t,n){if(e.commonAncestor.isOutside)return null;const o=new nt(t);n&&(o.value=n);const i=document.createDocumentFragment();if(i.appendChild(o.node.get(0)),"inline"===o.type)return ft(e,i),o.render(),e.selectBoxRight(o.node),o;const s=mt(e);return s.left&&(e.setEndAfter(s.left),e.collapseToEnd()),s.right&&s.right.isEmpty&&s.right.remove(),ft(e,i),o.render(),e.selectBoxRight(o.node),s.left&&s.left.isEmpty&&s.left.remove(),o}(this.selection.range,e,t);if(!n)return n;return this.box.getInstances(this).set(n.node.id,n),n}removeBox(){const e=function(e){if(e.commonAncestor.isOutside)return null;const t=e.commonAncestor.closest("lake-box");if(0===t.length)return null;const n=new nt(t);if("block"===n.type){const o=V("<p><br /></p>");return t.before(o),e.shrinkAfter(o),n.unmount(),t.remove(),n}e.setStartBefore(t),e.collapseToStart();const o=t.parent();return n.unmount(),t.remove(),o.isEmpty&&(I(o,V("<br />")),e.shrinkAfter(o)),n}(this.selection.range);if(e){this.box.getInstances(this).delete(e.node.id)}return e}innerWidth(){const e=parseInt(this.container.computedCSS("padding-left"),10)||0,t=parseInt(this.container.computedCSS("padding-right"),10)||0;return this.container.width()-e-t}render(){const e=v(this.config.value),t=new st(e).getFragment();this.root.empty(),this.root.append(this.containerWrapper),this.containerWrapper.append(this.container),this.containerWrapper.append(this.overlayContainer),V(document.body).append(this.popupContainer),this.container.append(t),this.readonly||(this.focus(),this.selection.synByBookmark(),this.history.save()),En.plugin.loadAll(this),En.box.renderAll(this),this.readonly||(window.addEventListener("beforeunload",this.beforeunloadListener),document.addEventListener("selectionchange",this.selectionchangeListener),this.bindInputEvents(),this.bindHistoryEvents()),document.addEventListener("click",this.clickListener),document.addEventListener("mouseover",this.mouseoverListener),window.addEventListener("resize",this.resizeListener)}unmount(){this.root.empty(),this.popupContainer.remove(),this.readonly||(window.removeEventListener("beforeunload",this.beforeunloadListener),document.removeEventListener("selectionchange",this.selectionchangeListener)),document.removeEventListener("click",this.clickListener),document.removeEventListener("mouseover",this.mouseoverListener),window.removeEventListener("resize",this.resizeListener)}}En.version=dn,En.box=new class{add(e){Ge.set(e.name,e)}remove(e){Ge.delete(e)}getNames(){return Array.from(Ge.keys())}getInstances(e){let t=vn.get(e.container.id);return t||(t=new Map,vn.set(e.container.id,t),t)}rectifyInstances(e){const t=this.getInstances(e);for(const e of t.values())e.node.get(0).isConnected||(e.unmount(),t.delete(e.node.id))}findAll(e){return e.container.find("lake-box")}renderAll(e){this.rectifyInstances(e);const t=this.getInstances(e);this.findAll(e).each((e=>{const n=new L(e);if(t.get(n.id))return;const o=new nt(n);o.render(),t.set(o.node.id,o)}))}},En.plugin=new class{constructor(){this.pluginList=[]}add(e){this.pluginList.push(e)}loadAll(e){this.pluginList.forEach((t=>{t(e)}))}};const Nn=[{icon:a.get("numberedList"),value:"numbered",text:"Numbered list"},{icon:a.get("bulletedList"),value:"bulleted",text:"Bulleted list"},{icon:a.get("checklist"),value:"checklist",text:"Checklist"}],Ln=[{icon:a.get("alignLeft"),value:"left",text:"Align left"},{icon:a.get("alignCenter"),value:"center",text:"Align center"},{icon:a.get("alignRight"),value:"right",text:"Align right"},{icon:a.get("alignJustify"),value:"justify",text:"Align justify"}],Vn=[{icon:a.get("increaseIndent"),value:"increase",text:"Increase indent"},{icon:a.get("decreaseIndent"),value:"decrease",text:"Decrease indent"}],$n=[{icon:a.get("italic"),value:"italic",text:"Italic"},{icon:a.get("underline"),value:"underline",text:"Underline"},{icon:a.get("strikethrough"),value:"strikethrough",text:"Strikethrough"},{icon:a.get("superscript"),value:"superscript",text:"Superscript"},{icon:a.get("subscript"),value:"subscript",text:"Subscript"},{icon:a.get("code"),value:"code",text:"Code"}],Zn=["#f5222d","#fa541c","#fa8c16","#faad14","#fadb14","#a0d911","#52c41a","#13c2c2","#1677ff","#2f54eb","#722ed1","#eb2f96","#fff1f0","#fff2e8","#fff7e6","#fffbe6","#feffe6","#fcffe6","#f6ffed","#e6fffb","#e6f4ff","#f0f5ff","#f9f0ff","#fff0f6","#ffccc7","#ffd8bf","#ffe7ba","#fff1b8","#ffffb8","#f4ffb8","#d9f7be","#b5f5ec","#bae0ff","#d6e4ff","#efdbff","#ffd6e7","#ffa39e","#ffbb96","#ffd591","#ffe58f","#fffb8f","#eaff8f","#b7eb8f","#87e8de","#91caff","#adc6ff","#d3adf7","#ffadd2","#ff7875","#ff9c6e","#ffc069","#ffd666","#fff566","#d3f261","#95de64","#5cdbd3","#69b1ff","#85a5ff","#b37feb","#ff85c0","#ff4d4f","#ff7a45","#ffa940","#ffc53d","#ffec3d","#bae637","#73d13d","#36cfc9","#4096ff","#597ef7","#9254de","#f759ab","#cf1322","#d4380d","#d46b08","#d48806","#d4b106","#7cb305","#389e0d","#08979c","#0958d9","#1d39c4","#531dab","#c41d7f","#a8071a","#ad2102","#ad4e00","#ad6800","#ad8b00","#5b8c00","#237804","#006d75","#003eb3","#10239e","#391085","#9e1068","#820014","#871400","#873800","#874d00","#876800","#3f6600","#135200","#00474f","#002c8c","#061178","#22075e","#780650","#5c0011","#610b00","#612500","#613400","#614700","#254000","#092b00","#002329","#001d66","#030852","#120338","#520339","#000000","#1f1f1f","#262626","#434343","#595959","#8c8c8c","#bfbfbf","#d9d9d9","#f0f0f0","#f5f5f5","#fafafa","#ffffff"],In=[{icon:a.get("removeFormat"),value:"",text:"Remove color"}];for(const e of Zn)In.push({value:e.toLowerCase(),text:e.toUpperCase()});const On=new Map([["strong","bold"],["em","italic"],["i","italic"],["u","underline"],["s","strikethrough"],["sup","superscript"],["sub","subscript"],["code","code"]]),Dn=[{name:"undo",type:"button",icon:a.get("undo"),tooltip:"Undo",onClick:(e,t)=>{e.command.execute(t)}},{name:"redo",type:"button",icon:a.get("redo"),tooltip:"Redo",onClick:(e,t)=>{e.command.execute(t)}},{name:"selectAll",type:"button",icon:a.get("selectAll"),tooltip:"Select all",onClick:(e,t)=>{e.command.execute(t)}},{name:"paragraph",type:"button",icon:a.get("paragraph"),tooltip:"Paragraph",isSelected:e=>!!e.find((e=>"p"===e.name)),onClick:e=>{e.command.execute("heading","p")}},{name:"blockQuote",type:"button",icon:a.get("blockQuote"),tooltip:"Block quotation",isSelected:e=>!!e.find((e=>"blockquote"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"numberedList",type:"button",icon:a.get("numberedList"),tooltip:"Numbered list",isSelected:e=>!!e.find((e=>"ol"===e.name)),onClick:e=>{e.command.execute("list","numbered")}},{name:"bulletedList",type:"button",icon:a.get("bulletedList"),tooltip:"Bulleted list",isSelected:e=>!!e.find((e=>"ul"===e.name&&!e.node.hasAttr("type"))),onClick:e=>{e.command.execute("list","bulleted")}},{name:"checklist",type:"button",icon:a.get("checklist"),tooltip:"Checklist",isSelected:e=>!!e.find((e=>"ul"===e.name&&"checklist"===e.node.attr("type"))),onClick:e=>{e.command.execute("list","checklist")}},{name:"alignLeft",type:"button",icon:a.get("alignLeft"),tooltip:"Align left",isSelected:e=>!!e.find((e=>e.node.isBlock&&"left"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","left")}},{name:"alignCenter",type:"button",icon:a.get("alignCenter"),tooltip:"Align center",isSelected:e=>!!e.find((e=>e.node.isBlock&&"center"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","center")}},{name:"alignRight",type:"button",icon:a.get("alignRight"),tooltip:"Align right",isSelected:e=>!!e.find((e=>e.node.isBlock&&"right"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","right")}},{name:"alignJustify",type:"button",icon:a.get("alignJustify"),tooltip:"Align justify",isSelected:e=>!!e.find((e=>e.node.isBlock&&"justify"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","justify")}},{name:"increaseIndent",type:"button",icon:a.get("increaseIndent"),tooltip:"Increase indent",onClick:e=>{e.command.execute("indent","increase")}},{name:"decreaseIndent",type:"button",icon:a.get("decreaseIndent"),tooltip:"Decrease indent",onClick:e=>{e.command.execute("indent","decrease")}},{name:"bold",type:"button",icon:a.get("bold"),tooltip:"Bold",isDisabled:e=>!!e.find((e=>e.node.isHeading)),isSelected:e=>!!e.find((e=>"strong"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"italic",type:"button",icon:a.get("italic"),tooltip:"Italic",isSelected:e=>!!e.find((e=>"i"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"underline",type:"button",icon:a.get("underline"),tooltip:"Underline",isSelected:e=>!!e.find((e=>"u"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"strikethrough",type:"button",icon:a.get("strikethrough"),tooltip:"Strikethrough",isSelected:e=>!!e.find((e=>"s"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"superscript",type:"button",icon:a.get("superscript"),tooltip:"Superscript",isSelected:e=>!!e.find((e=>"sup"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"subscript",type:"button",icon:a.get("subscript"),tooltip:"Subscript",isSelected:e=>!!e.find((e=>"sub"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"code",type:"button",icon:a.get("code"),tooltip:"Inline code",isSelected:e=>!!e.find((e=>"code"===e.name)),onClick:(e,t)=>{e.command.execute(t)}},{name:"removeFormat",type:"button",icon:a.get("removeFormat"),tooltip:"Remove format",onClick:(e,t)=>{e.command.execute(t)}},{name:"formatPainter",type:"button",icon:a.get("formatPainter"),tooltip:"Format painter",onClick:(e,t)=>{e.command.execute(t)}},{name:"link",type:"button",icon:a.get("link"),tooltip:"Link",onClick:(e,t)=>{e.command.execute(t)}},{name:"hr",type:"button",icon:a.get("hr"),tooltip:"Horizontal line",onClick:(e,t)=>{e.command.execute(t)}},{name:"codeBlock",type:"button",icon:a.get("codeBlock"),tooltip:"Code block",onClick:(e,t)=>{e.command.execute(t)}},{name:"heading",type:"dropdown",downIcon:a.get("down"),defaultValue:"p",tooltip:"Heading",width:"100px",menuType:"list",menuItems:[{value:"h1",text:'<span style="font-weight: bold; font-size: 26px;">Heading 1</span>'},{value:"h2",text:'<span style="font-weight: bold; font-size: 24px;">Heading 2</span>'},{value:"h3",text:'<span style="font-weight: bold; font-size: 22px;">Heading 3</span>'},{value:"h4",text:'<span style="font-weight: bold; font-size: 20px;">Heading 4</span>'},{value:"h5",text:'<span style="font-weight: bold; font-size: 18px;">Heading 5</span>'},{value:"h6",text:'<span style="font-weight: bold; font-size: 16px;">Heading 6</span>'},{value:"p",text:"Paragraph"}],selectedValues:e=>{const t=e.find((e=>e.node.isHeading||"p"===e.name));return t?[t.name]:[]},onSelect:(e,t)=>{e.command.execute("heading",t)}},{name:"list",type:"dropdown",downIcon:a.get("down"),icon:a.get("list"),defaultValue:"",tooltip:"List",width:"auto",menuType:"list",menuItems:Nn,selectedValues:e=>{let t="";for(const n of e){if("ol"===n.name){t="numbered";break}if("ul"===n.name&&!n.node.hasAttr("type")){t="bulleted";break}if("ul"===n.name&&"checklist"===n.node.attr("type")){t="checklist";break}}return[t]},onSelect:(e,t)=>{e.command.execute("list",t)}},{name:"align",type:"dropdown",downIcon:a.get("down"),icon:a.get("alignLeft"),defaultValue:"",tooltip:"Alignment",width:"auto",menuType:"list",menuItems:Ln,selectedValues:e=>{let t="";for(const n of e)if(n.node.isBlock){t=n.node.computedCSS("text-align");break}return[t]},onSelect:(e,t)=>{e.command.execute("align",t)}},{name:"indent",type:"dropdown",downIcon:a.get("down"),icon:a.get("increaseIndent"),defaultValue:"",tooltip:"Indent",width:"auto",menuType:"list",menuItems:Vn,onSelect:(e,t)=>{e.command.execute("indent",t)}},{name:"fontFamily",type:"dropdown",downIcon:a.get("down"),defaultValue:"Segoe UI",tooltip:"Font family",width:"100px",menuType:"list",menuItems:[{value:"Arial",text:'<span style="font-family: Arial;">Arial</span>'},{value:"Arial Black",text:"<span style=\"font-family: 'Arial Black';\">Arial Black</span>"},{value:"Comic Sans MS",text:"<span style=\"font-family: 'Comic Sans MS';\">Comic Sans MS</span>"},{value:"Courier New",text:"<span style=\"font-family: 'Courier New';\">Courier New</span>"},{value:"Georgia",text:'<span style="font-family: Georgia;">Georgia</span>'},{value:"Helvetica",text:'<span style="font-family: Helvetica;">Helvetica</span>'},{value:"Impact",text:'<span style="font-family: Impact;">Impact</span>'},{value:"Segoe UI",text:"<span style=\"font-family: 'Segoe UI';\">Segoe UI</span>"},{value:"Tahoma",text:'<span style="font-family: Tahoma;">Tahoma</span>'},{value:"Times New Roman",text:"<span style=\"font-family: 'Times New Roman';\">Times New Roman</span>"},{value:"Trebuchet MS",text:"<span style=\"font-family: 'Trebuchet MS';\">Trebuchet MS</span>"},{value:"Verdana",text:'<span style="font-family: Verdana;">Verdana</span>'}],selectedValues:e=>{for(const t of e)if("span"===t.name){return[t.node.css("font-family").replace(/['"]/g,"")]}return[]},onSelect:(e,t)=>{e.command.execute("fontFamily",t)}},{name:"fontSize",type:"dropdown",downIcon:a.get("down"),defaultValue:"16px",tooltip:"Font size",width:"65px",menuType:"list",menuItems:[{value:"12px",text:"12px"},{value:"14px",text:"14px"},{value:"16px",text:"16px"},{value:"18px",text:"18px"},{value:"22px",text:"22px"},{value:"24px",text:"24px"},{value:"32px",text:"32px"}],isDisabled:e=>!!e.find((e=>e.node.isHeading)),selectedValues:e=>{for(const t of e)if("span"===t.name){return[t.node.css("font-size").replace(/\.\d+/,"")]}return[]},onSelect:(e,t)=>{e.command.execute("fontSize",t)}},{name:"moreStyle",type:"dropdown",icon:a.get("more"),defaultValue:"",tooltip:"More style",width:"auto",menuType:"list",menuItems:$n,selectedValues:e=>{var t;const n=[];for(const o of e)if(o.node.isMark){const e=null!==(t=On.get(o.name))&&void 0!==t?t:o.name;n.push(e)}return n},onSelect:(e,t)=>{e.command.execute(t)}},{name:"fontColor",type:"dropdown",downIcon:a.get("down"),icon:a.get("fontColor"),accentIcon:a.get("fontColorAccent"),defaultValue:"#f5222d",tooltip:"Font color",width:"auto",menuType:"color",menuItems:In,selectedValues:e=>{for(const t of e)if("span"===t.name){return[g(t.node.computedCSS("color"))]}return[]},onSelect:(e,t)=>{e.command.execute("fontColor",t)}},{name:"highlight",type:"dropdown",downIcon:a.get("down"),icon:a.get("highlight"),accentIcon:a.get("highlightAccent"),defaultValue:"#fadb14",tooltip:"Highlight",width:"auto",menuType:"color",menuItems:In,selectedValues:e=>{for(const t of e)if("span"===t.name){return[g(t.node.computedCSS("background-color"))]}return[]},onSelect:(e,t)=>{e.command.execute("highlight",t)}},{name:"image",type:"upload",icon:a.get("image"),tooltip:"Image",accept:"image/*",multiple:!0}];function Rn(e){const{editor:t,file:n,onError:o,onSuccess:i}=e,{imageRequestMethod:s,imageRequestAction:r,imageRequestTypes:a}=t.config;if(a.indexOf(n.type)<0)throw new Error(`Cannot upload file because its type '${n.type}' is not found in ['${a.join("', '")}'].`);const l=t.insertBox("image",{url:URL.createObjectURL(n),status:"uploading",name:n.name,size:n.size,type:n.type,lastModified:n.lastModified});if(!l)throw new Error("The image box cannot be inserted outside the editor.");const c=ge({onProgress:e=>{const t=l.node.find(".lake-percent"),n=Math.round(e.percent);t.text(`${n<100?n:99} %`)},onError:(e,t)=>{H(e.toString(),t),l.updateValue("status","error"),l.render(),o&&o()},onSuccess:e=>{if(!e.url)return l.updateValue("status","error"),l.render(),void(o&&o());l.updateValue({status:"done",url:e.url}),l.render(),t.history.save(),i&&i()},file:n,action:r,method:s});return l.setData("xhr",c),l}const zn=["undo","redo","|","heading","fontSize","|","formatPainter","removeFormat","bold","moreStyle","|","fontColor","highlight","|","align","list","indent","link","blockQuote","hr"],jn=new Map;Dn.forEach((e=>{jn.set(e.name,e)}));function Pn(e,t,n,o){return new(n||(n=Promise))((function(i,s){function r(e){try{l(o.next(e))}catch(e){s(e)}}function a(e){try{l(o.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}l((o=o.apply(e,t||[])).next())}))}function Fn(e,t){const n=t.getEditor();if(!n)return;const o=t.getContainer(),i=e.closest(".lake-resizer").find(".lake-resizer-info"),s=e.attr("class").indexOf("-right")>=0,r=o.width(),a=o.height()/r;let l=0,c=0;const d=e=>{const t=e.clientX-l,n=Math.round(s?c+t:c-t),r=Math.round(a*n);o.css({width:`${n}px`,height:`${r}px`}),i.text(`${n} x ${r}`)};e.on("pointerdown",(t=>{const n=t;e.get(0).setPointerCapture(n.pointerId),l=n.clientX,c=o.width(),i.show(),e.on("pointermove",d)})),e.on("pointerup",(()=>{e.off("pointermove"),i.hide(),c=t.getContainer().width();const o=Math.round(a*c);t.updateValue({width:c,height:o}),n.history.save()})),e.on("pointercancel",(()=>{e.off("pointermove"),i.hide()}))}function qn(e){return Pn(this,void 0,void 0,(function*(){const t=V("<img />");return t.css({position:"absolute",top:"0",left:"-8888px","z-index":"-1",visibility:"hidden"}),new Promise((n=>{t.on("load",(()=>{const e=t.get(0),o=e.width,i=e.height;t.remove(),t.removeAttr("style"),n({node:t,width:o,height:i})})),t.on("error",(()=>{t.remove(),n({node:t})})),t.attr("src",e),V(document.body).append(t)}))}))}function Un(e,t){return Pn(this,void 0,void 0,(function*(){const n=t.value;t.getContainer().css({width:"",height:""});const o=V(h`
6
6
  <div class="lake-button-group">
7
7
  <button type="button" class="lake-button-remove" title="Delete"></button>
8
8
  </div>
@@ -32,7 +32,7 @@ var Lake=function(e,t,n,o,i){"use strict";class s extends HTMLElement{}customEle
32
32
  <div class="lake-resizer-bottom-right"></div>
33
33
  <div class="lake-resizer-info">${s} x ${r}</div>
34
34
  </div>
35
- `),g=i.node;g.addClass("lake-image-img"),g.attr({draggable:"false",alt:o.name}),Fn(p.find(".lake-resizer-top-left"),t),Fn(p.find(".lake-resizer-top-right"),t),Fn(p.find(".lake-resizer-bottom-left"),t),Fn(p.find(".lake-resizer-bottom-right"),t),e.append(l),e.append(p),e.append(g)}))}(r,e),l.then((()=>{s.empty(),s.append(r),r.find(".lake-button-view").on("click",(()=>function(e){const t=e.getEditor();if(!t)return;const i=[];let s=0;const r=t.container.find('lake-box[name="image"]');r.each(((t,n)=>{const o=new nt(t),r=o.value;"done"===r.status&&(i.push({id:n,src:r.originalUrl||r.url,width:r.originalWidth||r.width,height:r.originalHeight||r.height,alt:r.name}),e.node.id===o.node.id&&(s=n))}));const l=new n({pswpModule:o,dataSource:i,mainClass:"lake-pswp",zoom:!1,arrowPrevSVG:a.get("left"),arrowNextSVG:a.get("right"),closeSVG:a.get("close"),arrowPrevTitle:"Previous",arrowNextTitle:"Next",closeTitle:"Close (Esc)",errorMsg:"The image cannot be loaded"});l.on("uiRegister",(()=>{const e=l.pswp;e.ui.registerElement({name:"zoom-out-button",order:8,isButton:!0,title:"Zoom out",html:a.get("zoomOut"),onClick:()=>{const t=e.currSlide,n=(t.zoomLevels.max-t.zoomLevels.min)/5,o=t.currZoomLevel-n;t.zoomTo(o,void 0,333)}}),e.ui.registerElement({name:"zoom-in-button",order:9,isButton:!0,title:"Zoom in",html:a.get("zoomIn"),onClick:()=>{const t=e.currSlide,n=(t.zoomLevels.max-t.zoomLevels.min)/5,o=t.currZoomLevel+n;t.zoomTo(o,void 0,333)}})})),l.addFilter("thumbEl",((e,t)=>{const n=r.eq(t.id).find(".lake-image-img");return n.length>0?n.get(0):e})),l.addFilter("placeholderSrc",((e,t)=>{const n=r.eq(t.data.id).find(".lake-image-img");return n.length>0?n.attr("src"):e})),l.on("openingAnimationEnd",(()=>{e.event.emit("openfullscreen")})),l.init(),l.loadAndOpen(s)}(e))),r.find(".lake-button-remove").on("click",(t=>{t.stopPropagation(),function(e){const t=e.getEditor();if(!t)return;const n=e.getData("xhr");n&&n.abort(),t.selection.range.selectBox(e.node),t.removeBox(),t.history.save()}(e)})),e.event.emit("render")})),r.on("click",(()=>{t.selection.range.selectBox(e.node)}))},html:e=>{const t=e.node.attr("value");return h`<img src="${e.value.url}" data-lake-value="${t}" />`}},Wn={type:"block",name:"codeBlock",render:e=>{var t;const n=e.getEditor();if(!n)return;const o=n.innerWidth()-2,s=V('<div class="lake-code-block" />');s.css("width",`${o}px`);const r=e.getContainer();r.empty(),r.append(s);if(!s.get(0))return;const a=i({parent:s.get(0),value:null!==(t=e.value.code)&&void 0!==t?t:"",onChange:t=>{window.setTimeout((()=>{n.isComposing||(e.updateValue("code",t),n.history.save())}),0)}});e.setData("codeEditor",a)}};const Kn=Array.from(B).join(",");function Jn(e){const t=[e];for(const n of e.getWalker())t.push(n);for(const e of t)"div"===e.name?e.find(Kn).length>0?e.remove(!0):F(e,"p"):(e.isHeading||["blockquote","li"].indexOf(e.name)>=0)&&e.find(Kn).remove(!0)}function Xn(e,t){const n=e.selection,o=n.range;if(0===t.childNodes.length)return;const i=new L(t.firstChild);let s=new L(t.lastChild);0===o.getBlocks().length&&n.setBlocks("<p />"),function(e,t){const n=e.selection.range,o=n.startNode.closest("lake-box");if(o.length>0)if("inline"===new nt(o).type)n.isBoxLeft?(n.setStartBefore(o),n.collapseToStart()):n.isBoxRight?(n.setStartAfter(o),n.collapseToStart()):e.removeBox();else{const t=V("<p />");n.isBoxLeft?(o.before(t),n.shrinkAfter(t)):n.isBoxRight?(o.after(t),n.shrinkAfter(t)):e.removeBox()}const i=n.startNode.closestBlock();if(t.isBlockBox){const n=new nt(t),o=""!==t.attr("value")?n.value:void 0;return e.insertBox(n.name,o),void t.remove()}if(t.first().length>0&&O(i),i.isEmpty&&"p"===i.name)return i.replaceWith(t),t.find("lake-box").each((e=>{new nt(e).render()})),void n.shrinkAfter(t);let s=t.first();for(;s.length>0;){"li"===s.name&&(s=s.first());const t=s.next();e.selection.insertNode(s),s=t}t.remove()}(e,i);let r=new L(t.firstChild);for(;r.length>0;){const e=r.next();"br"===r.name&&r.remove(),r=e}if(s=new L(t.lastChild),t.childNodes.length>0){const e=n.splitBlock();e.left&&(o.setEndAfter(e.left),o.collapseToEnd()),e.right&&e.right.isEmpty&&e.right.remove(),n.insertFragment(t),o.shrinkAfter(s)}q(e.container.children().filter((e=>e.isBlock))),e.history.save()}function Gn(e){e.selection.setBlocks("<p />")}function Qn(e){e.selection.setBlocks("<ol><li></li></ol>")}function Yn(e){e.selection.setBlocks("<ul><li></li></ul>")}function eo(e,t){e.selection.setBlocks(`<ul type="checklist"><li value="${t}"></li></ul>`)}const to="strong";const no="sub";const oo="sup";const io="code";let so=[];const ro="lake-format-painter";class ao{constructor(e){this.linkNode=null,this.event=new Xe,this.root=V(h`
35
+ `),g=i.node;g.addClass("lake-image-img"),g.attr({draggable:"false",alt:o.name}),Fn(p.find(".lake-resizer-top-left"),t),Fn(p.find(".lake-resizer-top-right"),t),Fn(p.find(".lake-resizer-bottom-left"),t),Fn(p.find(".lake-resizer-bottom-right"),t),e.append(l),e.append(p),e.append(g)}))}(r,e),l.then((()=>{s.empty(),s.append(r),r.find(".lake-button-view").on("click",(()=>function(e){const t=e.getEditor();if(!t)return;const i=[];let s=0;const r=t.container.find('lake-box[name="image"]');r.each(((t,n)=>{const o=new nt(t),r=o.value;"done"===r.status&&(i.push({id:n,src:r.originalUrl||r.url,width:r.originalWidth||r.width,height:r.originalHeight||r.height,alt:r.name}),e.node.id===o.node.id&&(s=n))}));const l=new n({pswpModule:o,dataSource:i,mainClass:"lake-pswp",zoom:!1,arrowPrevSVG:a.get("left"),arrowNextSVG:a.get("right"),closeSVG:a.get("close"),arrowPrevTitle:"Previous",arrowNextTitle:"Next",closeTitle:"Close (Esc)",errorMsg:"The image cannot be loaded"});l.on("uiRegister",(()=>{const e=l.pswp;e.ui.registerElement({name:"zoom-out-button",order:8,isButton:!0,title:"Zoom out",html:a.get("zoomOut"),onClick:()=>{const t=e.currSlide,n=(t.zoomLevels.max-t.zoomLevels.min)/5,o=t.currZoomLevel-n;t.zoomTo(o,void 0,333)}}),e.ui.registerElement({name:"zoom-in-button",order:9,isButton:!0,title:"Zoom in",html:a.get("zoomIn"),onClick:()=>{const t=e.currSlide,n=(t.zoomLevels.max-t.zoomLevels.min)/5,o=t.currZoomLevel+n;t.zoomTo(o,void 0,333)}})})),l.addFilter("thumbEl",((e,t)=>{const n=r.eq(t.id).find(".lake-image-img");return n.length>0?n.get(0):e})),l.addFilter("placeholderSrc",((e,t)=>{const n=r.eq(t.data.id).find(".lake-image-img");return n.length>0?n.attr("src"):e})),l.on("openingAnimationEnd",(()=>{e.event.emit("openfullscreen")})),l.init(),l.loadAndOpen(s)}(e))),r.find(".lake-button-remove").on("click",(t=>{t.stopPropagation(),function(e){const t=e.getEditor();if(!t)return;const n=e.getData("xhr");n&&n.abort(),t.selection.range.selectBox(e.node),t.removeBox(),t.history.save()}(e)})),e.event.emit("render")})),r.on("click",(()=>{t.selection.range.selectBox(e.node)}))},html:e=>{const t=e.node.attr("value");return h`<img src="${e.value.url}" data-lake-value="${t}" />`}};const Wn={type:"block",name:"codeBlock",render:e=>{var t;const n=e.getEditor();if(!n)return;const o=n.innerWidth()-2,s=V('<div class="lake-code-block" />');s.css("width",`${o}px`);const r=e.getContainer();r.empty(),r.append(s);if(!s.get(0))return;const a=(l={parent:s.get(0),value:null!==(t=e.value.code)&&void 0!==t?t:"",onChange:t=>{window.setTimeout((()=>{n.isComposing||(e.updateValue("code",t),n.history.save())}),0)}},new i.EditorView({doc:l.value,extensions:[i.basicSetup,i.keymap.of([i.indentWithTab]),i.javascript(),i.EditorView.updateListener.of((e=>{e.docChanged&&l.onChange(e.state.doc.toString())}))],parent:l.parent}));var l;e.setData("codeEditor",a)}};const Kn=Array.from(B).join(",");function Jn(e){const t=[e];for(const n of e.getWalker())t.push(n);for(const e of t)"div"===e.name?e.find(Kn).length>0?e.remove(!0):F(e,"p"):(e.isHeading||["blockquote","li"].indexOf(e.name)>=0)&&e.find(Kn).remove(!0)}function Xn(e,t){const n=e.selection,o=n.range;if(0===t.childNodes.length)return;const i=new L(t.firstChild);let s=new L(t.lastChild);0===o.getBlocks().length&&n.setBlocks("<p />"),function(e,t){const n=e.selection.range,o=n.startNode.closest("lake-box");if(o.length>0)if("inline"===new nt(o).type)n.isBoxLeft?(n.setStartBefore(o),n.collapseToStart()):n.isBoxRight?(n.setStartAfter(o),n.collapseToStart()):e.removeBox();else{const t=V("<p />");n.isBoxLeft?(o.before(t),n.shrinkAfter(t)):n.isBoxRight?(o.after(t),n.shrinkAfter(t)):e.removeBox()}const i=n.startNode.closestBlock();if(t.isBlockBox){const n=new nt(t),o=""!==t.attr("value")?n.value:void 0;return e.insertBox(n.name,o),void t.remove()}if(t.first().length>0&&O(i),i.isEmpty&&"p"===i.name)return i.replaceWith(t),t.find("lake-box").each((e=>{new nt(e).render()})),void n.shrinkAfter(t);let s=t.first();for(;s.length>0;){"li"===s.name&&(s=s.first());const t=s.next();e.selection.insertNode(s),s=t}t.remove()}(e,i);let r=new L(t.firstChild);for(;r.length>0;){const e=r.next();"br"===r.name&&r.remove(),r=e}if(s=new L(t.lastChild),t.childNodes.length>0){const e=n.splitBlock();e.left&&(o.setEndAfter(e.left),o.collapseToEnd()),e.right&&e.right.isEmpty&&e.right.remove(),n.insertFragment(t),o.shrinkAfter(s)}q(e.container.children().filter((e=>e.isBlock))),e.history.save()}function Gn(e){e.selection.setBlocks("<p />")}function Qn(e){e.selection.setBlocks("<ol><li></li></ol>")}function Yn(e){e.selection.setBlocks("<ul><li></li></ul>")}function eo(e,t){e.selection.setBlocks(`<ul type="checklist"><li value="${t}"></li></ul>`)}const to="strong";const no="sub";const oo="sup";const io="code";let so=[];const ro="lake-format-painter";class ao{constructor(e){this.linkNode=null,this.event=new Xe,this.root=V(h`
36
36
  <div class="lake-link-popup">
37
37
  <div class="lake-row">URL</div>
38
38
  <div class="lake-row lake-url-row">
@@ -49,7 +49,7 @@ var Lake=function(e,t,n,o,i){"use strict";class s extends HTMLElement{}customEle
49
49
  <button type="button" class="lake-button-unlink"><span>Remove link</span></button>
50
50
  </div>
51
51
  </div>
52
- `);const t=a.get("open");t&&this.root.find(".lake-button-open").append(t);const n=this.root.find(".lake-button-copy"),o=a.get("copy");o&&n.append(o);const i=a.get("checkCircle");i&&n.append(i);const s=a.get("warningCircle");s&&n.append(s);const r=a.get("check");r&&this.root.find(".lake-button-save").prepend(r);const l=a.get("unlink");l&&this.root.find(".lake-button-unlink").prepend(l),e.append(this.root),this.bindEvents()}writeClipboardText(e,t){return Pn(this,void 0,void 0,(function*(){try{yield navigator.clipboard.writeText(e)}catch(e){t()}}))}bindEvents(){let e=null;this.root.find(".lake-button-copy").on("click",(()=>{if(!this.linkNode)return;const t=this.getInputValue("url");this.writeClipboardText(t,(()=>{const e=this.root.find(".lake-button-copy svg");e.hide(),e.eq(2).show("inline")}));const n=this.root.find(".lake-button-copy svg");n.hide(),n.eq(1).show("inline"),e&&window.clearTimeout(e),e=window.setTimeout((()=>{n.hide(),n.eq(0).show("inline")}),2e3)})),this.root.find(".lake-button-open").on("click",(()=>{if(!this.linkNode)return;const e=this.getInputValue("url");window.open(e)})),this.root.find(".lake-button-save").on("click",(()=>{this.linkNode&&(this.save(),this.hide(),this.event.emit("save"))})),this.root.find(".lake-button-unlink").on("click",(()=>{this.linkNode&&(this.linkNode.remove(!0),this.hide(),this.event.emit("remove"))}))}getInputValue(e){return this.root.find(`input[name="${e}"]`).get(0).value}setInputValue(e,t){this.root.find(`input[name="${e}"]`).get(0).value=t}save(){if(!this.linkNode)return;const e=this.getInputValue("url");let t=this.getInputValue("title");""===t&&(t="Link"),this.linkNode.attr("href",e),this.linkNode.text(t)}updatePosition(){if(!this.linkNode)return;const e=this.linkNode.get(0).getBoundingClientRect(),t=e.x+window.scrollX,n=e.y+window.scrollY;t<0||n<0?this.hide():(e.x+this.root.width()>window.innerWidth?this.root.css("left",`${t-this.root.width()+e.width}px`):this.root.css("left",`${t}px`),e.y+e.height+this.root.height()>window.innerHeight?this.root.css("top",n-this.root.height()+"px"):this.root.css("top",`${n+e.height}px`))}show(e){this.linkNode=e;const t=e.attr("href"),n=e.text();this.setInputValue("url",t),this.setInputValue("title",n),this.root.css("visibility","hidden"),this.root.show(),this.updatePosition(),this.root.css("visibility","")}hide(){this.linkNode=null,this.root.hide()}}function lo(e,t){const n=e.selection.range,o=n.getRightText();if(e.selection.splitBlock(),t=n.getBlocks()[0])return""!==o||!t.isHeading&&"blockquote"!==t.name?void(t.isList&&"checklist"===t.attr("type")&&t.find("li").attr("value","false")):(e.selection.setBlocks("<p />"),void e.history.save());e.history.save()}function co(e){const t=e.selection.range,n=t.startNode.closest("lake-box"),o=n.closestBlock();if(o.length>0&&!o.isContainer)return void(t.isBoxLeft?(t.setStartBefore(n),t.collapseToStart(),lo(e,o)):t.isBoxRight?(t.setStartAfter(n),t.collapseToStart(),lo(e,o)):e.removeBox());const i=V("<p><br /></p>");t.isBoxLeft?n.before(i):t.isBoxRight?(n.after(i),t.shrinkAfter(i)):e.removeBox()}function ho(e){const t=e.selection.range,n=t.startNode.closestBlock();if(n.length>0&&!n.isContainer){const n=t.getPrevNode(),o=t.getRightText();if("br"!==n.name&&""===o)return e.selection.insertContents("<br /><br />"),void e.history.save()}e.selection.insertContents("<br />")}function uo(e){const t=e.selection.range,n=t.startNode.closest("lake-box"),o=n.closestBlock();if(o.length>0&&!o.isContainer)return void(t.isBoxLeft?(t.setStartBefore(n),t.collapseToStart(),ho(e)):t.isBoxRight?(t.setStartAfter(n),t.collapseToStart(),ho(e)):e.removeBox());const i=V("<p><br /></p>");t.isBoxLeft?n.before(i):t.isBoxRight?(n.after(i),t.shrinkAfter(i)):e.removeBox()}function fo(e,t){const n=e.selection.range;let o=t.prev();if(0===o.length)return void("p"!==t.name&&e.selection.setBlocks("<p />"));if(o.isBox)return t.isEmpty&&t.remove(),void n.selectBoxRight(o);if("br"===o.name)return void o.remove();if(!o.isBlock){const e=new $;e.selectNodeContents(o),gt(e,"<p />"),o=e.startNode.closestBlock()}if(o.isEmpty)return void o.remove();const i=e.selection.insertBookmark();R(o,t),e.selection.toBookmark(i),e.selection.fixList()}function po(e,t){const n=e.selection.range;let o=t.next();if(0===o.length)return void e.history.save();if(o.isBox)return t.isEmpty&&t.remove(),n.selectBoxLeft(o),void e.history.save();if(!o.isBlock){const e=new $;e.selectNodeContents(o),gt(e,"<p />"),o=o.closestBlock()}const i=e.selection.insertBookmark();R(t,o),e.selection.toBookmark(i),e.selection.fixList()}const go=new Map([["#","h1"],["##","h2"],["###","h3"],["####","h4"],["#####","h5"],["######","h6"]]),mo=[{re:/\*\*(.+?)\*\*$/,getParameters:()=>["bold"]},{re:/__(.+?)__$/,getParameters:()=>["bold"]},{re:/_(.+?)_$/,getParameters:()=>["italic"]},{re:/\*(.+?)\*$/,getParameters:()=>["italic"]},{re:/==(.+?)==$/,getParameters:()=>["highlight","#fff566"]},{re:/~~(.+?)~~$/,getParameters:()=>["strikethrough"]},{re:/`(.+?)`$/,getParameters:()=>["code"]}],vo=[{re:/^#+$/,getParameters:e=>{var t;return["heading",null!==(t=go.get(e))&&void 0!==t?t:"h6"]}},{re:/^\d+\.$/,getParameters:()=>["list","numbered"]},{re:/^[*\-+]$/,getParameters:()=>["list","bulleted"]},{re:/^\[\s?\]$/,getParameters:()=>["list","checklist",!1]},{re:/^\[x\]$/i,getParameters:()=>["list","checklist",!0]},{re:/^>$/,getParameters:()=>["blockQuote"]}];function xo(e){const t=e.clone(!0);t.find("lake-bookmark").remove(),""===t.html()&&e.prepend("<br />")}return En.box.add({type:"block",name:"hr",render:e=>{const t=e.getEditor();if(t)return e.useEffect((()=>{e.getContainer().find(".lake-hr").on("click",(()=>{t.selection.range.selectBox(e.node)}))})),'<div class="lake-hr"><hr /></div>'},html:()=>"<hr />"}),En.box.add(_n),En.box.add(Wn),En.plugin.add((e=>{e.container.on("copy",(t=>{const n=e.selection.range;if(n.isInsideBox)return;const o=n.startNode.closest("lake-box");if(0===o.length)return;if(n.isBoxLeft||n.isBoxRight)return;t.preventDefault();const i=t.clipboardData;if(!i)return;const s=new nt(o).getHTML();i.setData("text/html",s)}))})),En.plugin.add((e=>{e.container.on("cut",(t=>{const n=e.selection.range;if(n.isInsideBox)return;const o=n.startNode.closest("lake-box");if(0===o.length)return;if(n.isBoxLeft||n.isBoxRight)return;t.preventDefault();const i=t.clipboardData;if(!i)return;const s=new nt(o).getHTML();i.setData("text/html",s),e.removeBox(),e.history.save()}))})),En.plugin.add((e=>{const{imageRequestTypes:t}=e.config;e.container.on("paste",(n=>{if(e.selection.range.isInsideBox)return;n.preventDefault();const o=n.clipboardData;if(!o)return;if(e.selection.deleteContents(),o.files.length>0){for(const n of o.files)t.indexOf(n.type)>=0&&Rn({editor:e,file:n});return}const i=o.types;if(1===i.length&&"text/plain"===i[0]){const t=o.getData("text/plain"),n=new rt(t).getFragment();return e.event.emit("beforepaste",n),void Xn(e,n)}const s=v(o.getData("text/html")),r=function(){const e=it();return e.div=e.p,k(e,((e,t)=>{delete t.id,delete t.class})),e}(),a=new st(s,r).getFragment();e.event.emit("beforepaste",a),function(e){let t=new L(e.firstChild);for(;t.length>0;){const e=t.next();t.isBlock&&Jn(t),t=e}let n=[];for(t=new L(e.firstChild);t.length>0;){const e=t.next();t.isMark||t.isText||t.isBookmark||t.isInlineBox?n.push(t):(j(n),n=[]),t=e}j(n)}(a),Xn(e,a),e.box.renderAll(e)}))})),En.plugin.add((e=>{e.command.add("undo",(()=>{e.history.undo()})),e.keystroke.setKeydown("mod+z",(t=>{e.selection.range.isInsideBox||(t.preventDefault(),e.command.execute("undo"))}))})),En.plugin.add((e=>{e.command.add("redo",(()=>{e.history.redo()})),e.keystroke.setKeydown("mod+y",(t=>{e.selection.range.isInsideBox||(t.preventDefault(),e.command.execute("redo"))}))})),En.plugin.add((e=>{e.command.add("selectAll",(()=>{const t=e.selection.range;t.selectNodeContents(e.container),t.shrink()}))})),En.plugin.add((e=>{e.command.add("heading",(t=>{e.selection.setBlocks(`<${t} />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("blockQuote",(()=>{e.selection.setBlocks("<blockquote />"),e.history.save()}))})),En.plugin.add((e=>{e.command.add("list",((t,n=!1)=>{const o=e.selection.range.getBlocks();let i=!1,s=!1,r=!1;for(const e of o)i||"ol"!==e.name||(i=!0),s||"ul"!==e.name||e.hasAttr("type")||(s=!0),r||"ul"!==e.name||"checklist"!==e.attr("type")||(r=!0);i?("numbered"===t&&Gn(e),"bulleted"===t&&Yn(e),"checklist"===t&&eo(e,n)):s?("numbered"===t&&Qn(e),"bulleted"===t&&Gn(e),"checklist"===t&&eo(e,n)):r?("numbered"===t&&Qn(e),"bulleted"===t&&Yn(e),"checklist"===t&&Gn(e)):("numbered"===t&&Qn(e),"bulleted"===t&&Yn(e),"checklist"===t&&eo(e,n)),e.history.save()})),e.container.on("click",(t=>{const n=t;if(e.readonly)return;if(!n.target)return;const o=V(n.target);"li"===o.name&&""!==o.attr("value")&&n.offsetX<=18&&(o.attr("value",("true"!==o.attr("value")).toString()),e.history.save())}))})),En.plugin.add((e=>{e.command.add("align",(t=>{e.selection.setBlocks({"text-align":t}),e.history.save()}))})),En.plugin.add((e=>{e.command.add("indent",(t=>{const n=e.selection.range.getBlocks();for(const e of n)U(e,t);e.history.save()}))})),En.plugin.add((e=>{e.command.add("bold",(()=>{e.selection.getAppliedItems().find((e=>e.name===to))?e.selection.removeMark(`<${to} />`):e.selection.addMark(`<${to} />`),e.history.save()})),e.keystroke.setKeydown("mod+b",(t=>{t.preventDefault(),e.command.execute("bold")}))})),En.plugin.add((e=>{e.command.add("italic",(()=>{e.selection.getAppliedItems().find((e=>"i"===e.name))?e.selection.removeMark("<i />"):e.selection.addMark("<i />"),e.history.save()})),e.keystroke.setKeydown("mod+i",(t=>{t.preventDefault(),e.command.execute("italic")}))})),En.plugin.add((e=>{e.command.add("underline",(()=>{e.selection.getAppliedItems().find((e=>"u"===e.name))?e.selection.removeMark("<u />"):e.selection.addMark("<u />"),e.history.save()})),e.keystroke.setKeydown("mod+u",(t=>{t.preventDefault(),e.command.execute("underline")}))})),En.plugin.add((e=>{e.command.add("strikethrough",(()=>{e.selection.getAppliedItems().find((e=>"s"===e.name))?e.selection.removeMark("<s />"):e.selection.addMark("<s />"),e.history.save()})),e.keystroke.setKeydown("mod+shift+x",(t=>{t.preventDefault(),e.command.execute("strikethrough")}))})),En.plugin.add((e=>{e.command.add("subscript",(()=>{e.selection.getAppliedItems().find((e=>e.name===no))?e.selection.removeMark(`<${no} />`):e.selection.addMark(`<${no} />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("superscript",(()=>{e.selection.getAppliedItems().find((e=>e.name===oo))?e.selection.removeMark(`<${oo} />`):e.selection.addMark(`<${oo} />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("code",(()=>{e.selection.getAppliedItems().find((e=>e.name===io))?e.selection.removeMark(`<${io} />`):e.selection.addMark(`<${io} />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("fontFamily",(t=>{e.selection.addMark(`<span style="font-family: ${t};" />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("fontSize",(t=>{e.selection.addMark(`<span style="font-size: ${t};" />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("fontColor",(t=>{e.selection.addMark(`<span style="color: ${t};" />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("highlight",(t=>{e.selection.addMark(`<span style="background-color: ${t};" />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("removeFormat",(()=>{e.selection.removeMark(),e.history.save()}))})),En.plugin.add((e=>{e.command.add("formatPainter",(()=>{e.container.addClass(ro);const t=e.selection.getAppliedItems();for(const e of t){const t=e.node.clone();t.isMark&&"a"!==t.name&&so.push(t)}})),e.container.on("click",(()=>{if(e.container.removeClass(ro),0!==so.length){for(const t of so)e.selection.addMark(t);so=[],e.history.save()}})),e.event.on("click",(t=>{if(t.isInside)return;const n=t.closest(".lake-toolbar-button");n.length>0&&"formatPainter"===n.attr("name")||(e.container.removeClass(ro),so=[])}))})),En.plugin.add((e=>{let t;const n=n=>{t||(t=new ao(e.popupContainer),t.event.on("save",(()=>{e.history.save()})),t.event.on("remove",(()=>{e.history.save()}))),t.show(n)};e.root.on("scroll",(()=>{t&&t.updatePosition()})),e.event.on("resize",(()=>{t&&t.updatePosition()})),e.event.on("click",(e=>{if(e.isOutside)return;if(e.closest("lake-box").length>0)return;const o=e.closest("a");0!==o.length?n(o):t&&t.hide()})),e.command.add("link",(()=>{const t=e.selection.insertLink('<a href="">New link</a>');t&&(e.history.save(),n(t))}))})),En.plugin.add((e=>{e.event.on("beforepaste",(e=>{new ve(e).find("hr").each((e=>{const t=V(e),n=new nt("hr");t.replaceWith(n.node)}))})),e.command.add("hr",(()=>{e.insertBox("hr"),e.history.save()}))})),En.plugin.add((e=>{e.event.on("beforepaste",(e=>{new ve(e).find("img").each((e=>{const t=V(e),n=new nt("image"),o=t.attr("data-lake-value");""===o?n.value={url:t.attr("src"),status:"done"}:n.node.attr("value",o),t.replaceWith(n.node)}))})),e.command.add("image",(t=>{e.insertBox("image",t),e.history.save()}))})),En.plugin.add((e=>{e.command.add("codeBlock",(()=>{const t=e.insertBox("codeBlock");if(!t)return;e.history.save();t.getData("codeEditor").focus()}))})),En.plugin.add((e=>{e.keystroke.setKeydown("enter",(t=>{const n=e.selection.range;if(n.isInsideBox)return;if(t.preventDefault(),n.isBox)return co(e),void e.history.save();if(n.adapt(),n.isInoperative)return;if(n.isBox)return co(e),void e.history.save();let o=n.getBlocks()[0];if(o||(e.selection.setBlocks("<p />"),o=n.getBlocks()[0]),o.isEmpty&&"p"!==o.name)return e.selection.setBlocks("<p />"),void e.history.save();lo(e,o),e.history.save()}))})),En.plugin.add((e=>{e.keystroke.setKeydown("shift+enter",(t=>{const n=e.selection.range;if(!n.isInsideBox){if(t.preventDefault(),n.isBox)return uo(e),void e.history.save();if(n.adapt(),!n.isInoperative){if(n.isBox)return uo(e),void e.history.save();ho(e),e.history.save()}}}))})),En.plugin.add((e=>{e.keystroke.setKeydown("backspace",(t=>{const n=e.selection.range;if(n.isInsideBox)return;if(n.isBoxLeft){const o=n.startNode.closest("lake-box"),i=o.prev();if(0===i.length){const n=o.closestBlock();return void(n.length>0&&!n.isContainer&&(t.preventDefault(),fo(e,n),e.history.save()))}if(i.isBlock)return i.isEmpty?(t.preventDefault(),i.remove(),e.selection.fixList(),void e.history.save()):(t.preventDefault(),void n.shrinkAfter(i));n.adaptBox()}if(n.isBox)return t.preventDefault(),e.removeBox(),void e.history.save();if(!n.isCollapsed)return t.preventDefault(),e.selection.deleteContents(),""===e.container.html().trim()&&e.setValue("<p><br /><focus /></p>"),void e.history.save();n.adapt();const o=n.getPrevNode();if(o.isBox)return t.preventDefault(),n.selectBox(o),e.removeBox(),void e.history.save();if(""===n.getLeftText()){t.preventDefault();let o=n.getBlocks()[0];return o||(e.selection.setBlocks("<p />"),o=n.getBlocks()[0]),""!==o.css("margin-left")||""!==o.css("text-indent")||""!==o.attr("indent")?(U(o,"decrease"),void e.history.save()):o.isList||"blockquote"===o.name?(e.selection.setBlocks("<p />"),void e.history.save()):(fo(e,o),void e.history.save())}"br"===o.name&&(t.preventDefault(),n.setStartBefore(o),n.collapseToStart(),o.remove(),e.history.save())}))})),En.plugin.add((e=>{e.keystroke.setKeydown("delete",(t=>{const n=e.selection.range;if(n.isInsideBox)return;if(n.isBoxRight){const o=n.startNode.closest("lake-box"),i=o.next();if(0===i.length){const n=o.closestBlock();return void(n.length>0&&!n.isContainer&&(t.preventDefault(),po(e,n),e.history.save()))}if(i.isBlock)return i.isEmpty?(t.preventDefault(),i.remove(),e.selection.fixList(),void e.history.save()):(t.preventDefault(),void n.shrinkBefore(i));n.adaptBox()}if(n.isBox)return t.preventDefault(),e.removeBox(),void e.history.save();if(!n.isCollapsed)return t.preventDefault(),e.selection.deleteContents(),""===e.container.html().trim()&&e.setValue("<p><br /><focus /></p>"),void e.history.save();n.adapt();const o=n.getNextNode();if(o.isBox)return t.preventDefault(),n.selectBox(o),e.removeBox(),void e.history.save();if(""===n.getRightText()){t.preventDefault();let o=n.getBlocks()[0];return o||(e.selection.setBlocks("<p />"),o=n.getBlocks()[0]),po(e,o),void e.history.save()}"br"===o.name&&(t.preventDefault(),n.setStartBefore(o),n.collapseToStart(),o.remove(),e.history.save())}))})),En.plugin.add((e=>{e.keystroke.setKeydown("tab",(t=>{t.preventDefault();e.selection.range.getBlocks().forEach((e=>{"p"===e.name&&"2em"!==e.css("text-indent")?e.css("text-indent","2em"):U(e,"increase")})),e.history.save()}))})),En.plugin.add((e=>{e.keystroke.setKeydown("arrow-left",(t=>{const n=e.selection.range;if(n.isInsideBox)return;const o=n.commonAncestor.closest("lake-box");if(o.length>0){if(n.isBoxLeft){const e=o.prev();return e.isBlock||e.isBox?(t.preventDefault(),e.isInlineBox?void n.selectBox(e):void n.shrinkAfter(e)):(n.setStartBefore(o),void n.collapseToStart())}return n.isBoxRight?(t.preventDefault(),void n.selectBox(o)):(t.preventDefault(),void n.selectBoxLeft(o))}if(!n.isCollapsed)return;const i=n.getPrevNode();i.isBox&&(t.preventDefault(),n.selectBox(i))})),e.keystroke.setKeydown("arrow-right",(t=>{const n=e.selection.range;if(n.isInsideBox)return;const o=n.commonAncestor.closest("lake-box");if(o.length>0){if(n.isBoxLeft)return t.preventDefault(),void n.selectBox(o);if(n.isBoxRight){const e=o.next();return e.isBlock||e.isBox?(t.preventDefault(),e.isInlineBox?void n.selectBox(e):void n.shrinkBefore(e)):(n.setStartAfter(o),void n.collapseToStart())}return t.preventDefault(),void n.selectBoxRight(o)}if(!n.isCollapsed)return;const i=n.getNextNode();i.isBox&&(t.preventDefault(),n.selectBox(i))})),e.keystroke.setKeydown("arrow-up",(t=>{const n=e.selection.range;if(n.isInsideBox)return;const o=n.commonAncestor.closest("lake-box");if(o.length>0){if(o.isBlockBox){const e=o.prev();if(e.isBlock||e.isBox)return t.preventDefault(),void n.shrinkAfter(e)}n.setStartBefore(o),n.collapseToStart()}})),e.keystroke.setKeydown("arrow-down",(t=>{const n=e.selection.range;if(n.isInsideBox)return;const o=n.commonAncestor.closest("lake-box");if(o.length>0){if(o.isBlockBox){const e=o.next();if(e.isBlock||e.isBox)return t.preventDefault(),void n.shrinkBefore(e)}n.setStartAfter(o),n.collapseToStart()}}))})),En.plugin.add((e=>{e.keystroke.setKeydown("space",(t=>{const n=e.selection,o=function(e){const t=e.selection.range;let n=t.startNode,o=t.startOffset;if(0!==o){if(n.isElement){const e=n.children()[o-1];if(!e||!e.isText)return;n=e,o=n.text().length}if(!(o<1))return{node:n,offset:o}}}(e);if(!o)return;if(function(e,t){const n=e.selection,o=n.range,i=t.offset,s=t.node.text().slice(0,i);for(const t of mo){const r=t.re.exec(s);if(null!==r){e.prepareOperation();const s=n.insertBookmark(),a=s.focus.prev(),l=a.text(),c=`${l.replace(t.re,"$1")}​`;a.get(0).nodeValue=c,o.setStart(a,i-r[0].length),o.setEnd(a,i-(l.length-c.length)-1);const d=t.getParameters();return e.command.execute(d.shift(),...d),n.toBookmark(s),e.commitOperation(),!0}}return!1}(e,o))return void t.preventDefault();const i=n.range.getBlocks()[0];i&&!i.isHeading&&"p"!==i.name||function(e,t){const n=e.selection,o=t.offset;let i=t.node.text().slice(0,o);i=i.replace(/[\u200B\u2060]/g,"");for(const t of vo)if(t.re.test(i)){e.prepareOperation();const o=n.insertBookmark();o.focus.prev().remove();const s=o.focus.closestBlock();xo(s),n.range.shrinkAfter(s);const r=t.getParameters(i);return e.command.execute(r.shift(),...r),n.toBookmark(o),e.commitOperation(),!0}return!1}(e,o)&&t.preventDefault()}))})),e.Box=nt,e.Editor=En,e.Fragment=ve,e.HTMLParser=st,e.Nodes=L,e.Range=$,e.TextParser=rt,e.Toolbar=class{constructor(e){this.items=e.items||zn,this.editor=e.editor,this.root=V(e.root),this.event=new Xe}getValue(e){const t=e.attr("value");return""===t?[]:JSON.parse(_e(t))}setValue(e,t){e.attr("value",Ue(JSON.stringify(t)))}appendDivider(){this.root.append('<div class="lake-toolbar-divider" />')}appendButton(e){const t=this.editor,n=V('<button type="button" class="lake-toolbar-button" />');n.attr("name",e.name),n.attr("title",e.tooltip),e.icon&&n.append(e.icon),this.root.append(n),n.on("mouseenter",(()=>{n.attr("disabled")||n.addClass("lake-toolbar-button-hovered")})),n.on("mouseleave",(()=>{n.attr("disabled")||n.removeClass("lake-toolbar-button-hovered")})),n.on("click",(n=>{n.preventDefault(),t.focus(),e.onClick(t,e.name)}))}getMenuMap(e){const t=new Map;if(!e.menuItems)return t;for(const n of e.menuItems){const e=n.text.replace(/<[^>]*>/g,"");t.set(n.value,e)}return t}updateColorAccent(e,t){const n=e.find(".lake-dropdown-icon svg").eq(1),o=n.find("line");o.length>0?o.attr("stroke",t):n.find("path").attr("fill",t)}addDropdownMenu(e,t){for(const n of t.menuItems){const o=V(l`
52
+ `);const t=a.get("open");t&&this.root.find(".lake-button-open").append(t);const n=this.root.find(".lake-button-copy"),o=a.get("copy");o&&n.append(o);const i=a.get("checkCircle");i&&n.append(i);const s=a.get("warningCircle");s&&n.append(s);const r=a.get("check");r&&this.root.find(".lake-button-save").prepend(r);const l=a.get("unlink");l&&this.root.find(".lake-button-unlink").prepend(l),e.append(this.root),this.bindEvents()}writeClipboardText(e,t){return Pn(this,void 0,void 0,(function*(){try{yield navigator.clipboard.writeText(e)}catch(e){t()}}))}bindEvents(){let e=null;this.root.find(".lake-button-copy").on("click",(()=>{if(!this.linkNode)return;const t=this.getInputValue("url");this.writeClipboardText(t,(()=>{const e=this.root.find(".lake-button-copy svg");e.hide(),e.eq(2).show("inline")}));const n=this.root.find(".lake-button-copy svg");n.hide(),n.eq(1).show("inline"),e&&window.clearTimeout(e),e=window.setTimeout((()=>{n.hide(),n.eq(0).show("inline")}),2e3)})),this.root.find(".lake-button-open").on("click",(()=>{if(!this.linkNode)return;const e=this.getInputValue("url");window.open(e)})),this.root.find(".lake-button-save").on("click",(()=>{this.linkNode&&(this.save(),this.hide(),this.event.emit("save"))})),this.root.find(".lake-button-unlink").on("click",(()=>{this.linkNode&&(this.linkNode.remove(!0),this.hide(),this.event.emit("remove"))}))}getInputValue(e){return this.root.find(`input[name="${e}"]`).get(0).value}setInputValue(e,t){this.root.find(`input[name="${e}"]`).get(0).value=t}save(){if(!this.linkNode)return;const e=this.getInputValue("url");let t=this.getInputValue("title");""===t&&(t="Link"),this.linkNode.attr("href",e),this.linkNode.text(t)}updatePosition(){if(!this.linkNode)return;const e=this.linkNode.get(0).getBoundingClientRect(),t=e.x+window.scrollX,n=e.y+window.scrollY;t<0||n<0?this.hide():(e.x+this.root.width()>window.innerWidth?this.root.css("left",`${t-this.root.width()+e.width}px`):this.root.css("left",`${t}px`),e.y+e.height+this.root.height()>window.innerHeight?this.root.css("top",n-this.root.height()+"px"):this.root.css("top",`${n+e.height}px`))}show(e){this.linkNode=e;const t=e.attr("href"),n=e.text();this.setInputValue("url",t),this.setInputValue("title",n),this.root.css("visibility","hidden"),this.root.show(),this.updatePosition(),this.root.css("visibility","")}hide(){this.linkNode=null,this.root.hide()}}function lo(e,t){const n=e.selection.range,o=n.getRightText();if(e.selection.splitBlock(),t=n.getBlocks()[0])return""!==o||!t.isHeading&&"blockquote"!==t.name?void(t.isList&&"checklist"===t.attr("type")&&t.find("li").attr("value","false")):(e.selection.setBlocks("<p />"),void e.history.save());e.history.save()}function co(e){const t=e.selection.range,n=t.startNode.closest("lake-box"),o=n.closestBlock();if(o.length>0&&!o.isContainer)return void(t.isBoxLeft?(t.setStartBefore(n),t.collapseToStart(),lo(e,o)):t.isBoxRight?(t.setStartAfter(n),t.collapseToStart(),lo(e,o)):e.removeBox());const i=V("<p><br /></p>");t.isBoxLeft?n.before(i):t.isBoxRight?(n.after(i),t.shrinkAfter(i)):e.removeBox()}function ho(e){const t=e.selection.range,n=t.startNode.closestBlock();if(n.length>0&&!n.isContainer){const n=t.getPrevNode(),o=t.getRightText();if("br"!==n.name&&""===o)return e.selection.insertContents("<br /><br />"),void e.history.save()}e.selection.insertContents("<br />")}function uo(e){const t=e.selection.range,n=t.startNode.closest("lake-box"),o=n.closestBlock();if(o.length>0&&!o.isContainer)return void(t.isBoxLeft?(t.setStartBefore(n),t.collapseToStart(),ho(e)):t.isBoxRight?(t.setStartAfter(n),t.collapseToStart(),ho(e)):e.removeBox());const i=V("<p><br /></p>");t.isBoxLeft?n.before(i):t.isBoxRight?(n.after(i),t.shrinkAfter(i)):e.removeBox()}function fo(e,t){const n=e.selection.range;let o=t.prev();if(0===o.length)return void("p"!==t.name&&e.selection.setBlocks("<p />"));if(o.isBox)return t.isEmpty&&t.remove(),void n.selectBoxRight(o);if("br"===o.name)return void o.remove();if(!o.isBlock){const e=new $;e.selectNodeContents(o),gt(e,"<p />"),o=e.startNode.closestBlock()}if(o.isEmpty)return void o.remove();const i=e.selection.insertBookmark();R(o,t),e.selection.toBookmark(i),e.selection.fixList()}function po(e,t){const n=e.selection.range;let o=t.next();if(0===o.length)return void e.history.save();if(o.isBox)return t.isEmpty&&t.remove(),n.selectBoxLeft(o),void e.history.save();if(!o.isBlock){const e=new $;e.selectNodeContents(o),gt(e,"<p />"),o=o.closestBlock()}const i=e.selection.insertBookmark();R(t,o),e.selection.toBookmark(i),e.selection.fixList()}const go=new Map([["#","h1"],["##","h2"],["###","h3"],["####","h4"],["#####","h5"],["######","h6"]]),mo=[{re:/\*\*(.+?)\*\*$/,getParameters:()=>["bold"]},{re:/__(.+?)__$/,getParameters:()=>["bold"]},{re:/_(.+?)_$/,getParameters:()=>["italic"]},{re:/\*(.+?)\*$/,getParameters:()=>["italic"]},{re:/==(.+?)==$/,getParameters:()=>["highlight","#fff566"]},{re:/~~(.+?)~~$/,getParameters:()=>["strikethrough"]},{re:/`(.+?)`$/,getParameters:()=>["code"]}],vo=[{re:/^#+$/,getParameters:e=>{var t;return["heading",null!==(t=go.get(e))&&void 0!==t?t:"h6"]}},{re:/^\d+\.$/,getParameters:()=>["list","numbered"]},{re:/^[*\-+]$/,getParameters:()=>["list","bulleted"]},{re:/^\[\s?\]$/,getParameters:()=>["list","checklist",!1]},{re:/^\[x\]$/i,getParameters:()=>["list","checklist",!0]},{re:/^>$/,getParameters:()=>["blockQuote"]}];function xo(e){const t=e.clone(!0);t.find("lake-bookmark").remove(),""===t.html()&&e.prepend("<br />")}return En.box.add({type:"block",name:"hr",render:e=>{const t=e.getEditor();if(t)return e.useEffect((()=>{e.getContainer().find(".lake-hr").on("click",(()=>{t.selection.range.selectBox(e.node)}))})),'<div class="lake-hr"><hr /></div>'},html:()=>"<hr />"}),En.box.add(_n),En.box.add(Wn),En.plugin.add((e=>{e.container.on("copy",(t=>{const n=e.selection.range;if(n.isInsideBox)return;const o=n.startNode.closest("lake-box");if(0===o.length)return;if(n.isBoxLeft||n.isBoxRight)return;t.preventDefault();const i=t.clipboardData;if(!i)return;const s=new nt(o).getHTML();i.setData("text/html",s)}))})),En.plugin.add((e=>{e.container.on("cut",(t=>{const n=e.selection.range;if(n.isInsideBox)return;const o=n.startNode.closest("lake-box");if(0===o.length)return;if(n.isBoxLeft||n.isBoxRight)return;t.preventDefault();const i=t.clipboardData;if(!i)return;const s=new nt(o).getHTML();i.setData("text/html",s),e.removeBox(),e.history.save()}))})),En.plugin.add((e=>{const{imageRequestTypes:t}=e.config;e.container.on("paste",(n=>{if(e.selection.range.isInsideBox)return;n.preventDefault();const o=n.clipboardData;if(!o)return;if(e.selection.deleteContents(),o.files.length>0){for(const n of o.files)t.indexOf(n.type)>=0&&Rn({editor:e,file:n});return}const i=o.types;if(1===i.length&&"text/plain"===i[0]){const t=o.getData("text/plain"),n=new rt(t).getFragment();return e.event.emit("beforepaste",n),void Xn(e,n)}const s=v(o.getData("text/html")),r=function(){const e=it();return e.div=e.p,k(e,((e,t)=>{delete t.id,delete t.class})),e}(),a=new st(s,r).getFragment();e.event.emit("beforepaste",a),function(e){let t=new L(e.firstChild);for(;t.length>0;){const e=t.next();t.isBlock&&Jn(t),t=e}let n=[];for(t=new L(e.firstChild);t.length>0;){const e=t.next();t.isMark||t.isText||t.isBookmark||t.isInlineBox?n.push(t):(j(n),n=[]),t=e}j(n)}(a),Xn(e,a),e.box.renderAll(e)}))})),En.plugin.add((e=>{e.command.add("undo",(()=>{e.history.undo()})),e.keystroke.setKeydown("mod+z",(t=>{e.selection.range.isInsideBox||(t.preventDefault(),e.command.execute("undo"))}))})),En.plugin.add((e=>{e.command.add("redo",(()=>{e.history.redo()})),e.keystroke.setKeydown("mod+y",(t=>{e.selection.range.isInsideBox||(t.preventDefault(),e.command.execute("redo"))}))})),En.plugin.add((e=>{e.command.add("selectAll",(()=>{const t=e.selection.range;t.selectNodeContents(e.container),t.shrink()}))})),En.plugin.add((e=>{e.command.add("heading",(t=>{e.selection.setBlocks(`<${t} />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("blockQuote",(()=>{e.selection.setBlocks("<blockquote />"),e.history.save()}))})),En.plugin.add((e=>{e.command.add("list",((t,n=!1)=>{const o=e.selection.range.getBlocks();let i=!1,s=!1,r=!1;for(const e of o)i||"ol"!==e.name||(i=!0),s||"ul"!==e.name||e.hasAttr("type")||(s=!0),r||"ul"!==e.name||"checklist"!==e.attr("type")||(r=!0);i?("numbered"===t&&Gn(e),"bulleted"===t&&Yn(e),"checklist"===t&&eo(e,n)):s?("numbered"===t&&Qn(e),"bulleted"===t&&Gn(e),"checklist"===t&&eo(e,n)):r?("numbered"===t&&Qn(e),"bulleted"===t&&Yn(e),"checklist"===t&&Gn(e)):("numbered"===t&&Qn(e),"bulleted"===t&&Yn(e),"checklist"===t&&eo(e,n)),e.history.save()})),e.container.on("click",(t=>{const n=t;if(e.readonly)return;if(!n.target)return;const o=V(n.target);"li"===o.name&&""!==o.attr("value")&&n.offsetX<=18&&(o.attr("value",("true"!==o.attr("value")).toString()),e.history.save())}))})),En.plugin.add((e=>{e.command.add("align",(t=>{e.selection.setBlocks({"text-align":t}),e.history.save()}))})),En.plugin.add((e=>{e.command.add("indent",(t=>{const n=e.selection.range.getBlocks();for(const e of n)U(e,t);e.history.save()}))})),En.plugin.add((e=>{e.command.add("bold",(()=>{e.selection.getAppliedItems().find((e=>e.name===to))?e.selection.removeMark(`<${to} />`):e.selection.addMark(`<${to} />`),e.history.save()})),e.keystroke.setKeydown("mod+b",(t=>{t.preventDefault(),e.command.execute("bold")}))})),En.plugin.add((e=>{e.command.add("italic",(()=>{e.selection.getAppliedItems().find((e=>"i"===e.name))?e.selection.removeMark("<i />"):e.selection.addMark("<i />"),e.history.save()})),e.keystroke.setKeydown("mod+i",(t=>{t.preventDefault(),e.command.execute("italic")}))})),En.plugin.add((e=>{e.command.add("underline",(()=>{e.selection.getAppliedItems().find((e=>"u"===e.name))?e.selection.removeMark("<u />"):e.selection.addMark("<u />"),e.history.save()})),e.keystroke.setKeydown("mod+u",(t=>{t.preventDefault(),e.command.execute("underline")}))})),En.plugin.add((e=>{e.command.add("strikethrough",(()=>{e.selection.getAppliedItems().find((e=>"s"===e.name))?e.selection.removeMark("<s />"):e.selection.addMark("<s />"),e.history.save()})),e.keystroke.setKeydown("mod+shift+x",(t=>{t.preventDefault(),e.command.execute("strikethrough")}))})),En.plugin.add((e=>{e.command.add("subscript",(()=>{e.selection.getAppliedItems().find((e=>e.name===no))?e.selection.removeMark(`<${no} />`):e.selection.addMark(`<${no} />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("superscript",(()=>{e.selection.getAppliedItems().find((e=>e.name===oo))?e.selection.removeMark(`<${oo} />`):e.selection.addMark(`<${oo} />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("code",(()=>{e.selection.getAppliedItems().find((e=>e.name===io))?e.selection.removeMark(`<${io} />`):e.selection.addMark(`<${io} />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("fontFamily",(t=>{e.selection.addMark(`<span style="font-family: ${t};" />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("fontSize",(t=>{e.selection.addMark(`<span style="font-size: ${t};" />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("fontColor",(t=>{e.selection.addMark(`<span style="color: ${t};" />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("highlight",(t=>{e.selection.addMark(`<span style="background-color: ${t};" />`),e.history.save()}))})),En.plugin.add((e=>{e.command.add("removeFormat",(()=>{e.selection.removeMark(),e.history.save()}))})),En.plugin.add((e=>{e.command.add("formatPainter",(()=>{e.container.addClass(ro);const t=e.selection.getAppliedItems();for(const e of t){const t=e.node.clone();t.isMark&&"a"!==t.name&&so.push(t)}})),e.container.on("click",(()=>{if(e.container.removeClass(ro),0!==so.length){for(const t of so)e.selection.addMark(t);so=[],e.history.save()}})),e.event.on("click",(t=>{if(t.isInside)return;const n=t.closest(".lake-toolbar-button");n.length>0&&"formatPainter"===n.attr("name")||(e.container.removeClass(ro),so=[])}))})),En.plugin.add((e=>{let t;const n=n=>{t||(t=new ao(e.popupContainer),t.event.on("save",(()=>{e.history.save()})),t.event.on("remove",(()=>{e.history.save()}))),t.show(n)};e.root.on("scroll",(()=>{t&&t.updatePosition()})),e.event.on("resize",(()=>{t&&t.updatePosition()})),e.event.on("click",(e=>{if(e.isOutside)return;if(e.closest("lake-box").length>0)return;const o=e.closest("a");0!==o.length?n(o):t&&t.hide()})),e.command.add("link",(()=>{const t=e.selection.insertLink('<a href="">New link</a>');t&&(e.history.save(),n(t))}))})),En.plugin.add((e=>{e.event.on("beforepaste",(e=>{new ve(e).find("hr").each((e=>{const t=V(e),n=new nt("hr");t.replaceWith(n.node)}))})),e.command.add("hr",(()=>{e.insertBox("hr"),e.history.save()}))})),En.plugin.add((e=>{e.event.on("beforepaste",(e=>{new ve(e).find("img").each((e=>{const t=V(e),n=new nt("image"),o=t.attr("data-lake-value");""===o?n.value={url:t.attr("src"),status:"done"}:n.node.attr("value",o),t.replaceWith(n.node)}))})),e.command.add("image",(t=>{e.insertBox("image",t),e.history.save()}))})),En.plugin.add((e=>{e.command.add("codeBlock",(()=>{const t=e.insertBox("codeBlock");if(!t)return;e.history.save();t.getData("codeEditor").focus()}))})),En.plugin.add((e=>{e.keystroke.setKeydown("enter",(t=>{const n=e.selection.range;if(n.isInsideBox)return;if(t.preventDefault(),n.isBox)return co(e),void e.history.save();if(n.adapt(),n.isInoperative)return;if(n.isBox)return co(e),void e.history.save();let o=n.getBlocks()[0];if(o||(e.selection.setBlocks("<p />"),o=n.getBlocks()[0]),o.isEmpty&&"p"!==o.name)return e.selection.setBlocks("<p />"),void e.history.save();lo(e,o),e.history.save()}))})),En.plugin.add((e=>{e.keystroke.setKeydown("shift+enter",(t=>{const n=e.selection.range;if(!n.isInsideBox){if(t.preventDefault(),n.isBox)return uo(e),void e.history.save();if(n.adapt(),!n.isInoperative){if(n.isBox)return uo(e),void e.history.save();ho(e),e.history.save()}}}))})),En.plugin.add((e=>{e.keystroke.setKeydown("backspace",(t=>{const n=e.selection.range;if(n.isInsideBox)return;if(n.isBoxLeft){const o=n.startNode.closest("lake-box"),i=o.prev();if(0===i.length){const n=o.closestBlock();return void(n.length>0&&!n.isContainer&&(t.preventDefault(),fo(e,n),e.history.save()))}if(i.isBlock)return i.isEmpty?(t.preventDefault(),i.remove(),e.selection.fixList(),void e.history.save()):(t.preventDefault(),void n.shrinkAfter(i));n.adaptBox()}if(n.isBox)return t.preventDefault(),e.removeBox(),void e.history.save();if(!n.isCollapsed)return t.preventDefault(),e.selection.deleteContents(),""===e.container.html().trim()&&e.setValue("<p><br /><focus /></p>"),void e.history.save();n.adapt();const o=n.getPrevNode();if(o.isBox)return t.preventDefault(),n.selectBox(o),e.removeBox(),void e.history.save();if(""===n.getLeftText()){t.preventDefault();let o=n.getBlocks()[0];return o||(e.selection.setBlocks("<p />"),o=n.getBlocks()[0]),""!==o.css("margin-left")||""!==o.css("text-indent")||""!==o.attr("indent")?(U(o,"decrease"),void e.history.save()):o.isList||"blockquote"===o.name?(e.selection.setBlocks("<p />"),void e.history.save()):(fo(e,o),void e.history.save())}"br"===o.name&&(t.preventDefault(),n.setStartBefore(o),n.collapseToStart(),o.remove(),e.history.save())}))})),En.plugin.add((e=>{e.keystroke.setKeydown("delete",(t=>{const n=e.selection.range;if(n.isInsideBox)return;if(n.isBoxRight){const o=n.startNode.closest("lake-box"),i=o.next();if(0===i.length){const n=o.closestBlock();return void(n.length>0&&!n.isContainer&&(t.preventDefault(),po(e,n),e.history.save()))}if(i.isBlock)return i.isEmpty?(t.preventDefault(),i.remove(),e.selection.fixList(),void e.history.save()):(t.preventDefault(),void n.shrinkBefore(i));n.adaptBox()}if(n.isBox)return t.preventDefault(),e.removeBox(),void e.history.save();if(!n.isCollapsed)return t.preventDefault(),e.selection.deleteContents(),""===e.container.html().trim()&&e.setValue("<p><br /><focus /></p>"),void e.history.save();n.adapt();const o=n.getNextNode();if(o.isBox)return t.preventDefault(),n.selectBox(o),e.removeBox(),void e.history.save();if(""===n.getRightText()){t.preventDefault();let o=n.getBlocks()[0];return o||(e.selection.setBlocks("<p />"),o=n.getBlocks()[0]),po(e,o),void e.history.save()}"br"===o.name&&(t.preventDefault(),n.setStartBefore(o),n.collapseToStart(),o.remove(),e.history.save())}))})),En.plugin.add((e=>{e.keystroke.setKeydown("tab",(t=>{t.preventDefault();e.selection.range.getBlocks().forEach((e=>{"p"===e.name&&"2em"!==e.css("text-indent")?e.css("text-indent","2em"):U(e,"increase")})),e.history.save()}))})),En.plugin.add((e=>{e.keystroke.setKeydown("arrow-left",(t=>{const n=e.selection.range;if(n.isInsideBox)return;const o=n.commonAncestor.closest("lake-box");if(o.length>0){if(n.isBoxLeft){const e=o.prev();return e.isBlock||e.isBox?(t.preventDefault(),e.isInlineBox?void n.selectBox(e):void n.shrinkAfter(e)):(n.setStartBefore(o),void n.collapseToStart())}return n.isBoxRight?(t.preventDefault(),void n.selectBox(o)):(t.preventDefault(),void n.selectBoxLeft(o))}if(!n.isCollapsed)return;const i=n.getPrevNode();i.isBox&&(t.preventDefault(),n.selectBox(i))})),e.keystroke.setKeydown("arrow-right",(t=>{const n=e.selection.range;if(n.isInsideBox)return;const o=n.commonAncestor.closest("lake-box");if(o.length>0){if(n.isBoxLeft)return t.preventDefault(),void n.selectBox(o);if(n.isBoxRight){const e=o.next();return e.isBlock||e.isBox?(t.preventDefault(),e.isInlineBox?void n.selectBox(e):void n.shrinkBefore(e)):(n.setStartAfter(o),void n.collapseToStart())}return t.preventDefault(),void n.selectBoxRight(o)}if(!n.isCollapsed)return;const i=n.getNextNode();i.isBox&&(t.preventDefault(),n.selectBox(i))})),e.keystroke.setKeydown("arrow-up",(t=>{const n=e.selection.range;if(n.isInsideBox)return;const o=n.commonAncestor.closest("lake-box");if(o.length>0){if(o.isBlockBox){const e=o.prev();if(e.isBlock||e.isBox)return t.preventDefault(),void n.shrinkAfter(e)}n.setStartBefore(o),n.collapseToStart()}})),e.keystroke.setKeydown("arrow-down",(t=>{const n=e.selection.range;if(n.isInsideBox)return;const o=n.commonAncestor.closest("lake-box");if(o.length>0){if(o.isBlockBox){const e=o.next();if(e.isBlock||e.isBox)return t.preventDefault(),void n.shrinkBefore(e)}n.setStartAfter(o),n.collapseToStart()}}))})),En.plugin.add((e=>{e.keystroke.setKeydown("space",(t=>{const n=e.selection,o=function(e){const t=e.selection.range;let n=t.startNode,o=t.startOffset;if(0!==o){if(n.isElement){const e=n.children()[o-1];if(!e||!e.isText)return;n=e,o=n.text().length}if(!(o<1))return{node:n,offset:o}}}(e);if(!o)return;if(function(e,t){const n=e.selection,o=n.range,i=t.offset,s=t.node.text().slice(0,i);for(const t of mo){const r=t.re.exec(s);if(null!==r){e.prepareOperation();const s=n.insertBookmark(),a=s.focus.prev(),l=a.text(),c=`${l.replace(t.re,"$1")}​`;a.get(0).nodeValue=c,o.setStart(a,i-r[0].length),o.setEnd(a,i-(l.length-c.length)-1);const d=t.getParameters();return e.command.execute(d.shift(),...d),n.toBookmark(s),e.commitOperation(),!0}}return!1}(e,o))return void t.preventDefault();const i=n.range.getBlocks()[0];i&&!i.isHeading&&"p"!==i.name||function(e,t){const n=e.selection,o=t.offset;let i=t.node.text().slice(0,o);i=i.replace(/[\u200B\u2060]/g,"");for(const t of vo)if(t.re.test(i)){e.prepareOperation();const o=n.insertBookmark();o.focus.prev().remove();const s=o.focus.closestBlock();xo(s),n.range.shrinkAfter(s);const r=t.getParameters(i);return e.command.execute(r.shift(),...r),n.toBookmark(o),e.commitOperation(),!0}return!1}(e,o)&&t.preventDefault()}))})),e.Box=nt,e.Editor=En,e.Fragment=ve,e.HTMLParser=st,e.Nodes=L,e.Range=$,e.TextParser=rt,e.Toolbar=class{constructor(e){this.items=e.items||zn,this.editor=e.editor,this.root=V(e.root),this.container=V('<div class="lake-toolbar" />'),this.event=new Xe,this.root.addClass("lake-custom-properties")}getValue(e){const t=e.attr("value");return""===t?[]:JSON.parse(_e(t))}setValue(e,t){e.attr("value",Ue(JSON.stringify(t)))}appendDivider(){this.container.append('<div class="lake-toolbar-divider" />')}appendButton(e){const t=this.editor,n=V('<button type="button" class="lake-toolbar-button" />');n.attr("name",e.name),n.attr("title",e.tooltip),e.icon&&n.append(e.icon),this.container.append(n),n.on("mouseenter",(()=>{n.attr("disabled")||n.addClass("lake-toolbar-button-hovered")})),n.on("mouseleave",(()=>{n.attr("disabled")||n.removeClass("lake-toolbar-button-hovered")})),n.on("click",(n=>{n.preventDefault(),t.focus(),e.onClick(t,e.name)}))}getMenuMap(e){const t=new Map;if(!e.menuItems)return t;for(const n of e.menuItems){const e=n.text.replace(/<[^>]*>/g,"");t.set(n.value,e)}return t}updateColorAccent(e,t){const n=e.find(".lake-dropdown-icon svg").eq(1),o=n.find("line");o.length>0?o.attr("stroke",t):n.find("path").attr("fill",t)}addDropdownMenu(e,t){for(const n of t.menuItems){const o=V(l`
53
53
  <li value="${n.value}">
54
54
  <div class="lake-dropdown-menu-text">${n.text}</div>
55
55
  </li>
@@ -67,9 +67,9 @@ var Lake=function(e,t,n,o,i){"use strict";class s extends HTMLElement{}customEle
67
67
  <div class="lake-dropdown-down-icon"></div>
68
68
  </button>
69
69
  </div>
70
- `);o.attr("name",e.name),o.addClass(`lake-dropdown-${e.menuType}`);const i=o.find(".lake-dropdown-title");e.downIcon||i.addClass("lake-dropdown-title-no-down"),i.css("width",e.width),i.attr("title",e.tooltip);const s=i.find(".lake-dropdown-text"),r=i.find(".lake-dropdown-icon");e.icon&&r.append(e.icon),e.accentIcon&&r.append(e.accentIcon);const a=i.find(".lake-dropdown-down-icon");e.downIcon&&a.append(e.downIcon);const l=V('<ul class="lake-dropdown-menu" />');l.addClass(`lake-dropdown-${e.menuType}-menu`),s.length>0&&s.text(null!==(t=n.get(e.defaultValue))&&void 0!==t?t:e.defaultValue),"color"===e.menuType&&this.updateColorAccent(i,e.defaultValue),this.addDropdownMenu(l,e),o.append(i),o.append(l),this.root.append(o),this.bindDropdownEvents(o,e)}appendUpload(e){const t=this.editor,n=V(h`
70
+ `);o.attr("name",e.name),o.addClass(`lake-dropdown-${e.menuType}`);const i=o.find(".lake-dropdown-title");e.downIcon||i.addClass("lake-dropdown-title-no-down"),i.css("width",e.width),i.attr("title",e.tooltip);const s=i.find(".lake-dropdown-text"),r=i.find(".lake-dropdown-icon");e.icon&&r.append(e.icon),e.accentIcon&&r.append(e.accentIcon);const a=i.find(".lake-dropdown-down-icon");e.downIcon&&a.append(e.downIcon);const l=V('<ul class="lake-dropdown-menu" />');l.addClass(`lake-dropdown-${e.menuType}-menu`),s.length>0&&s.text(null!==(t=n.get(e.defaultValue))&&void 0!==t?t:e.defaultValue),"color"===e.menuType&&this.updateColorAccent(i,e.defaultValue),this.addDropdownMenu(l,e),o.append(i),o.append(l),this.container.append(o),this.bindDropdownEvents(o,e)}appendUpload(e){const t=this.editor,n=V(h`
71
71
  <div class="lake-upload">
72
72
  <input type="file" />
73
73
  <button type="button" class="lake-toolbar-button" />
74
74
  </div>
75
- `),o=n.find('input[type="file"]'),i=o.get(0);e.accept&&o.attr("accept",e.accept),!0===e.multiple&&o.attr("multiple","true");const s=n.find("button");s.attr("name",e.name),s.attr("title",e.tooltip),e.icon&&s.append(e.icon),this.root.append(n),s.on("mouseenter",(()=>{s.addClass("lake-toolbar-button-hovered")})),s.on("mouseleave",(()=>{s.removeClass("lake-toolbar-button-hovered")})),s.on("click",(e=>{e.preventDefault(),i.click()})),o.on("click",(e=>e.stopPropagation())),o.on("change",(e=>{const n=e.target.files||[];for(const e of n)Rn({editor:t,file:e})}))}getUpdateStateHandler(e){const{editor:t,allMenuMap:n,buttonItemList:o,dropdownItemList:i}=e;return cn((()=>{var e;let s=t.selection.appliedItems;s.length>0&&s[0].node.closestContainer().get(0)!==t.container.get(0)&&(s=[]);for(const e of o){const n="lake-toolbar-button-selected",o=this.root.find(`button[name="${e.name}"]`),i=!!(e.isDisabled&&s.length>0)&&e.isDisabled(s,t);if(i?(o.attr("disabled","true"),o.removeClass(n)):o.removeAttr("disabled"),!i){!!(e.isSelected&&s.length>0)&&e.isSelected(s,t)?o.addClass(n):o.removeClass(n)}}for(const o of i){const i=o.selectedValues&&s.length>0?o.selectedValues(s,t):[],r=this.root.find(`div.lake-dropdown[name="${o.name}"]`),a=!!(o.isDisabled&&s.length>0)&&o.isDisabled(s,t);if(a?r.attr("disabled","true"):r.removeAttr("disabled"),!a){this.setValue(r,i);const t=r.find(".lake-dropdown-text");if(t.length>0){const s=i[0]||o.defaultValue,r=n.get(o.name),a=null!==(e=r&&r.get(s))&&void 0!==e?e:s;t.text(a)}}}this.event.emit("updatestate")}),100,{leading:!1,trailing:!0,maxWait:100})}render(){const e=this.editor;this.root.addClass("lake-custom-properties");const t=new Map,n=[],o=[];this.items.forEach((e=>{if("|"===e)return void this.appendDivider();let i;if("string"==typeof e){if(i=jn.get(e),!i)return}else i=e;return"button"===i.type?(n.push(i),void this.appendButton(i)):"dropdown"===i.type?(t.set(i.name,this.getMenuMap(i)),o.push(i),void this.appendDropdown(i)):void("upload"===i.type&&this.appendUpload(i))}));const i=this.getUpdateStateHandler({editor:e,allMenuMap:t,buttonItemList:n,dropdownItemList:o});e.event.on("selectionchange",i),e.event.on("change",i)}},e.Utils=me,e.addMark=bt,e.deleteContents=ut,e.fixList=ht,e.icons=a,e.insertBookmark=lt,e.insertContents=pt,e.insertFragment=ft,e.insertLink=At,e.insertNode=at,e.removeMark=Bt,e.setBlocks=gt,e.splitBlock=mt,e.splitMarks=kt,e.toBookmark=dt,e}({},0,PhotoSwipeLightbox,PhotoSwipe,CodeMirror);
75
+ `),o=n.find('input[type="file"]'),i=o.get(0);e.accept&&o.attr("accept",e.accept),!0===e.multiple&&o.attr("multiple","true");const s=n.find("button");s.attr("name",e.name),s.attr("title",e.tooltip),e.icon&&s.append(e.icon),this.container.append(n),s.on("mouseenter",(()=>{s.addClass("lake-toolbar-button-hovered")})),s.on("mouseleave",(()=>{s.removeClass("lake-toolbar-button-hovered")})),s.on("click",(e=>{e.preventDefault(),i.click()})),o.on("click",(e=>e.stopPropagation())),o.on("change",(e=>{const n=e.target.files||[];for(const e of n)Rn({editor:t,file:e})}))}getUpdateStateHandler(e){const{editor:t,allMenuMap:n,buttonItemList:o,dropdownItemList:i}=e;return cn((()=>{var e;let s=t.selection.appliedItems;s.length>0&&s[0].node.closestContainer().get(0)!==t.container.get(0)&&(s=[]);for(const e of o){const n="lake-toolbar-button-selected",o=this.container.find(`button[name="${e.name}"]`),i=!!(e.isDisabled&&s.length>0)&&e.isDisabled(s,t);if(i?(o.attr("disabled","true"),o.removeClass(n)):o.removeAttr("disabled"),!i){!!(e.isSelected&&s.length>0)&&e.isSelected(s,t)?o.addClass(n):o.removeClass(n)}}for(const o of i){const i=o.selectedValues&&s.length>0?o.selectedValues(s,t):[],r=this.container.find(`div.lake-dropdown[name="${o.name}"]`),a=!!(o.isDisabled&&s.length>0)&&o.isDisabled(s,t);if(a?r.attr("disabled","true"):r.removeAttr("disabled"),!a){this.setValue(r,i);const t=r.find(".lake-dropdown-text");if(t.length>0){const s=i[0]||o.defaultValue,r=n.get(o.name),a=null!==(e=r&&r.get(s))&&void 0!==e?e:s;t.text(a)}}}this.event.emit("updatestate")}),100,{leading:!1,trailing:!0,maxWait:100})}render(){const e=this.editor;this.root.empty(),this.root.append(this.container);const t=new Map,n=[],o=[];this.items.forEach((e=>{if("|"===e)return void this.appendDivider();let i;if("string"==typeof e){if(i=jn.get(e),!i)return}else i=e;return"button"===i.type?(n.push(i),void this.appendButton(i)):"dropdown"===i.type?(t.set(i.name,this.getMenuMap(i)),o.push(i),void this.appendDropdown(i)):void("upload"===i.type&&this.appendUpload(i))}));const i=this.getUpdateStateHandler({editor:e,allMenuMap:t,buttonItemList:n,dropdownItemList:o});e.event.on("selectionchange",i),e.event.on("change",i)}},e.Utils=me,e.addMark=bt,e.deleteContents=ut,e.fixList=ht,e.icons=a,e.insertBookmark=lt,e.insertContents=pt,e.insertFragment=ft,e.insertLink=At,e.insertNode=at,e.removeMark=Bt,e.setBlocks=gt,e.splitBlock=mt,e.splitMarks=kt,e.toBookmark=dt,e}({},0,PhotoSwipeLightbox,PhotoSwipe,CodeMirror);
package/lib/lake.css CHANGED
@@ -686,6 +686,9 @@ lake-box[name="codeBlock"] .lake-box-activated .lake-code-block {
686
686
  }
687
687
 
688
688
  .lake-toolbar {
689
+ font-family: var(--font-family);
690
+ color: var(--text-color);
691
+ background-color: #fff;
689
692
  padding: 4px;
690
693
  display: flex;
691
694
  flex-wrap: wrap;
package/lib/lake.js CHANGED
@@ -3991,9 +3991,9 @@ function insertLink(range, value) {
3991
3991
  return linkNode;
3992
3992
  }
3993
3993
 
3994
- var name = "lake-lib";
3994
+ var name = "lakelib";
3995
3995
  var description = "Rich text editor based on the browser";
3996
- var version = "0.0.2";
3996
+ var version = "0.0.1";
3997
3997
  var author = "Luo Longhao <luolonghao@gmail.com>";
3998
3998
  var license = "MIT";
3999
3999
  var homepage = "http://lakejs.com";
@@ -5731,7 +5731,9 @@ class Toolbar {
5731
5731
  this.items = config.items || defaultItems;
5732
5732
  this.editor = config.editor;
5733
5733
  this.root = query(config.root);
5734
+ this.container = query('<div class="lake-toolbar" />');
5734
5735
  this.event = new EventEmitter();
5736
+ this.root.addClass('lake-custom-properties');
5735
5737
  }
5736
5738
  // Returns the value of the node.
5737
5739
  getValue(node) {
@@ -5746,7 +5748,7 @@ class Toolbar {
5746
5748
  node.attr('value', Base64.encode(JSON.stringify(value)));
5747
5749
  }
5748
5750
  appendDivider() {
5749
- this.root.append('<div class="lake-toolbar-divider" />');
5751
+ this.container.append('<div class="lake-toolbar-divider" />');
5750
5752
  }
5751
5753
  appendButton(item) {
5752
5754
  const editor = this.editor;
@@ -5756,7 +5758,7 @@ class Toolbar {
5756
5758
  if (item.icon) {
5757
5759
  buttonNode.append(item.icon);
5758
5760
  }
5759
- this.root.append(buttonNode);
5761
+ this.container.append(buttonNode);
5760
5762
  buttonNode.on('mouseenter', () => {
5761
5763
  if (buttonNode.attr('disabled')) {
5762
5764
  return;
@@ -5970,7 +5972,7 @@ class Toolbar {
5970
5972
  this.addDropdownMenu(menuNode, item);
5971
5973
  dropdownNode.append(titleNode);
5972
5974
  dropdownNode.append(menuNode);
5973
- this.root.append(dropdownNode);
5975
+ this.container.append(dropdownNode);
5974
5976
  this.bindDropdownEvents(dropdownNode, item);
5975
5977
  }
5976
5978
  appendUpload(item) {
@@ -5995,7 +5997,7 @@ class Toolbar {
5995
5997
  if (item.icon) {
5996
5998
  buttonNode.append(item.icon);
5997
5999
  }
5998
- this.root.append(uploadNode);
6000
+ this.container.append(uploadNode);
5999
6001
  buttonNode.on('mouseenter', () => {
6000
6002
  buttonNode.addClass('lake-toolbar-button-hovered');
6001
6003
  });
@@ -6029,7 +6031,7 @@ class Toolbar {
6029
6031
  }
6030
6032
  for (const item of buttonItemList) {
6031
6033
  const selectedClass = 'lake-toolbar-button-selected';
6032
- const buttonNode = this.root.find(`button[name="${item.name}"]`);
6034
+ const buttonNode = this.container.find(`button[name="${item.name}"]`);
6033
6035
  const isDisabled = item.isDisabled && appliedItems.length > 0 ? item.isDisabled(appliedItems, editor) : false;
6034
6036
  if (isDisabled) {
6035
6037
  buttonNode.attr('disabled', 'true');
@@ -6050,7 +6052,7 @@ class Toolbar {
6050
6052
  }
6051
6053
  for (const item of dropdownItemList) {
6052
6054
  const selectedValues = item.selectedValues && appliedItems.length > 0 ? item.selectedValues(appliedItems, editor) : [];
6053
- const dropdownNode = this.root.find(`div.lake-dropdown[name="${item.name}"]`);
6055
+ const dropdownNode = this.container.find(`div.lake-dropdown[name="${item.name}"]`);
6054
6056
  const isDisabled = item.isDisabled && appliedItems.length > 0 ? item.isDisabled(appliedItems, editor) : false;
6055
6057
  if (isDisabled) {
6056
6058
  dropdownNode.attr('disabled', 'true');
@@ -6076,9 +6078,11 @@ class Toolbar {
6076
6078
  maxWait: 100,
6077
6079
  });
6078
6080
  }
6081
+ // Renders a toolbar for the specified editor.
6079
6082
  render() {
6080
6083
  const editor = this.editor;
6081
- this.root.addClass('lake-custom-properties');
6084
+ this.root.empty();
6085
+ this.root.append(this.container);
6082
6086
  const allMenuMap = new Map();
6083
6087
  const buttonItemList = [];
6084
6088
  const dropdownItemList = [];
@@ -6599,7 +6603,7 @@ const imageBox = {
6599
6603
  },
6600
6604
  };
6601
6605
 
6602
- function CodeMirror (config) {
6606
+ function CodeMirror(config) {
6603
6607
  const updateListener = (update) => {
6604
6608
  if (!update.docChanged) {
6605
6609
  return;
@@ -6617,7 +6621,6 @@ function CodeMirror (config) {
6617
6621
  parent: config.parent,
6618
6622
  });
6619
6623
  }
6620
-
6621
6624
  const codeBlockBox = {
6622
6625
  type: 'block',
6623
6626
  name: 'codeBlock',
@@ -1,8 +1,5 @@
1
- import { EditorView } from '@codemirror/view';
2
- type Config = {
3
- parent: Element;
4
- value: string;
5
- onChange: (value: string) => void;
6
- };
7
- export default function (config: Config): EditorView;
8
- export {};
1
+ import { basicSetup } from 'codemirror';
2
+ import { EditorView, type ViewUpdate, keymap } from '@codemirror/view';
3
+ import { indentWithTab } from '@codemirror/commands';
4
+ import { javascript } from '@codemirror/lang-javascript';
5
+ export { basicSetup, EditorView, ViewUpdate, keymap, indentWithTab, javascript, };