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-all.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;
@@ -2,7 +2,7 @@ var Lake=function(t){"use strict";class e extends HTMLElement{}customElements.de
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 Kt{constructor(t){if(this.event=new Nt,"string"==typeof t){const e=jt.get(t);if(void 0===e)throw new Error(`Box '${t}' has not been defined yet.`);const i=r(e.type),n=r(e.name);this.node=C(a`<lake-box type="${i}" name="${n}"></lake-box>`),e.value&&(this.value=e.value)}else{this.node=C(t);const e=jt.get(this.name);if(void 0===e)throw new Error(`Box '${this.name}' has not been defined yet.`);e.value&&!this.node.hasAttr("value")&&(this.value=e.value)}Gt[this.node.id]||(Gt[this.node.id]={}),Ut[this.node.id]||(Ut[this.node.id]={setup:[],cleanup:[]})}addFramework(){let t=this.getContainer();0===t.length?(this.node.html(Ft),t=this.getContainer()):(t.off("mouseenter"),t.off("mouseleave"),t.off("click")),t.on("mouseenter",(()=>{t.hasClass("lake-box-selected")||t.hasClass("lake-box-focused")||t.hasClass("lake-box-activated")||t.addClass("lake-box-hovered")})),t.on("mouseleave",(()=>{t.removeClass("lake-box-hovered")})),t.on("click",(()=>{Q(`Box '${this.name}' (id = ${this.node.id}) value:`),Q(this.value)}))}get type(){return this.node.attr("type")}get name(){return this.node.attr("name")}get value(){const t=this.node.attr("value");return""===t?{}:JSON.parse(Lt(t))}set value(t){this.node.attr("value",It(JSON.stringify(t)))}updateValue(t,e){const i=this.value;"string"==typeof t?i[t]=e:m(t,((t,e)=>{i[t]=e})),this.value=i}getData(t){return Gt[this.node.id][t]}setData(t,e){Gt[this.node.id][t]=e}getEditor(){const t=this.node.closestContainer();return t.length>0?Ht.get(t.id):void 0}getContainer(){return this.node.find(".lake-box-container")}useEffect(t){Ut[this.node.id].setup.push(t)}render(){Ut[this.node.id].setup=[],Ut[this.node.id].cleanup=[];const t=jt.get(this.name);if(void 0===t)return;this.addFramework();const e=t.render(this);if(void 0!==e){const t=this.getContainer(),i=t.clone(!1);i.append(e),ht(t,i)}for(const t of Ut[this.node.id].setup){const e=t();void 0!==e&&Ut[this.node.id].cleanup.push(e)}Q(`Box '${this.name}' (id = ${this.node.id}) rendered`)}unmount(){for(const t of Ut[this.node.id].cleanup)t();Gt[this.node.id]={},Ut[this.node.id].setup=[],Ut[this.node.id].cleanup=[],this.node.empty(),Q(`Box '${this.name}' (id = ${this.node.id}) unmounted`)}getHTML(){const t=jt.get(this.name);return void 0===t?"":void 0===t.html?this.node.outerHTML():t.html(this)}}const Jt={id:/^[\w-]+$/,class:/^[\w-]+$/,style:{"text-align":["left","center","right","justify"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function te(){return{h1:Object.assign({},Jt),h2:Object.assign({},Jt),h3:Object.assign({},Jt),h4:Object.assign({},Jt),h5:Object.assign({},Jt),h6:Object.assign({},Jt),p:Object.assign({},Jt),blockquote:Object.assign(Object.assign({},Jt),{type:["success","info","warning","error"]}),ul:Object.assign(Object.assign({},Jt),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},Jt),{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 ee{constructor(t,e=te()){this.rules=e,this.source="string"==typeof t?this.parseHTML(t):t}parseHTML(t){const e=(new DOMParser).parseFromString(t,"text/html");return new Z(e.querySelector("body"))}static matchRule(t,e){return"string"==typeof t?t===e:Array.isArray(t)?t.indexOf(e)>=0:t instanceof RegExp&&t.test(e)}static getOpenTagString(t,e){let i=t.name,n=e[i];if(!n)return"";"string"==typeof n&&(i=n,n=e[i]);const s=t.get(0);if(!s.hasAttributes())return i;const o=new Map;for(const t of s.attributes)if(n[t.name]&&("style"!==t.name&&ee.matchRule(n[t.name],t.value)&&o.set(t.name,t.value),"style"===t.name)){const e=n.style,i=new Map;m(u(t.value),((t,n)=>{e[t]&&ee.matchRule(e[t],n)&&i.set(t,n)})),o.set("style",i)}let r=i;for(const[t,e]of o)if("style"===t){let t="";for(const[i,n]of e)t+=`${i}: ${n.replace(/"/g,"&quot;")}; `;""!==t&&(r+=` style="${t.trim()}"`)}else r+=` ${t}="${e}"`;return r}static getClosedTagString(t,e){let i=t.name;const n=e[i];return n?("string"==typeof n&&(i=n),i):""}static getTrimmedText(t){const e=t.parent(),i=t.prev(),n=t.next();let s=t.text();return(i.isBlock||i.isBlockBox)&&(n.isBlock||n.isBlockBox)||0===i.length&&0===n.length&&e.isBlock?s=s.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):i.isBlock||i.isBlockBox||0===i.length&&e.isBlock?s=s.replace(/^[\u0020\t\r\n]+/,""):(n.isBlock||n.isBlockBox||0===n.length&&e.isBlock)&&(s=s.replace(/[\u0020\t\r\n]+$/,"")),s}getHTML(){const t=this.rules;let e="";for(const i of function*e(i){let n=i.first();for(;n.length>0;){const i=n.next();if(n.isText)yield r(ee.getTrimmedText(n));else if(n.isVoid){const e=ee.getOpenTagString(n,t);""!==e&&(yield`<${e} />`)}else if(n.isElement){const i=ee.getOpenTagString(n,t),s=ee.getClosedTagString(n,t);""!==i&&(yield`<${i}>`),n.isBox||(yield*e(n)),""!==s&&(yield`</${s}>`)}n=i}}(this.source))e+=i;return e.trim()}getNodeList(){const t=this.getHTML();return this.parseHTML(t).children()}getFragment(){const t=this.getHTML(),e=this.parseHTML(t),i=document.createDocumentFragment();let n=e.first();for(;n.length>0;){const t=n.next();i.appendChild(n.get(0)),n=t}return i}}class ie{constructor(t){this.content=t}getHTML(){let t=this.content;return t=t.replace(/ {2}/g,"  "),t=r(t.trim()),t=`<p>${t}</p>`,t=t.replace(/(\r\n){2,}/g,"</p><p><br /></p><p>"),t=t.replace(/\r\n/g,"</p><p>"),t=t.replace(/[\r\n]{2,}/g,"</p><p><br /></p><p>"),t=t.replace(/[\r\n]/g,"</p><p>"),t}getFragment(){return new ee(this.getHTML()).getFragment()}}function ne(t,e){if(t.commonAncestor.isOutside)return;const i=(e=C(e)).get(0),n=t.get();n.insertNode(i),n.setEndAfter(i),n.collapse(!1)}function se(t){if(t.commonAncestor.isOutside)return{anchor:new Z,focus:new Z};const e=t.startNode.closest("lake-box");if(e.length>0)return t.isBoxLeft?e.attr("focus","left"):t.isBoxRight?e.attr("focus","right"):e.attr("focus","center"),{anchor:new Z,focus:e};if(t.isCollapsed){const e=t.clone();e.collapseToEnd();const i=C('<lake-bookmark type="focus" />');return ne(e,i),{anchor:new Z,focus:i}}const i=t.clone();i.collapseToStart();const n=C('<lake-bookmark type="anchor" />');ne(i,n);const s=t.clone();s.collapseToEnd();const o=C('<lake-bookmark type="focus" />');return ne(s,o),{anchor:n,focus:o}}function oe(t,e){const i=t.prev(),n=t.next();if(i.isText&&n.isText){const e=t.parent();X(e),t.remove(),e.get(0).normalize()}else if(0===i.length&&0===n.length){if(t.parent().isMark&&e){const i=new Z(document.createTextNode("​"));t.before(i),e.setStartAfter(i),e.collapseToStart()}t.remove()}else t.remove()}function re(t,e){const i=e.anchor,n=e.focus;if(i.length>0&&0===n.length)oe(i);else{if(n.length>0&&0===i.length){if(n.isBox){const e=new Kt(n);0===e.getContainer().length&&e.render();const i=n.attr("focus");return"left"===i?t.selectBoxLeft(n):"center"===i?t.selectBox(n):t.selectBoxRight(n),void n.removeAttr("focus")}return t.setStartBefore(n),t.collapseToStart(),void oe(n,t)}if(i.length>0&&n.length>0){const e=new A;e.selectNode(i),e.collapseToEnd(),-1===e.compareAfterNode(n)?(t.setStartBefore(n),oe(n),t.setEndBefore(i),oe(i)):(t.setStartBefore(i),oe(i),t.setEndBefore(n),oe(n))}}}function ae(t){if(t.commonAncestor.isOutside)return;q(t.getBlocks())}function le(t){if(t.isCollapsed)return;if(t.adapt(),t.isInoperative)return;const e=t.startNode.closestBlock(),i=t.endNode.closestBlock(),n=e.get(0)===i.get(0);if(t.get().deleteContents(),t.adaptBlock(),n){const e=t.getBlocks()[0];return void(e&&e.isEmpty&&(_(e,C("<br />")),t.shrinkAfter(e)))}const s=t.getBlocks()[0];if(!s)return;const o=s.prev();if(0===o.length)return;const r=se(t);E(o,s),re(t,r),ae(t)}function he(t,e){if(t.commonAncestor.isOutside)return;t.isCollapsed?t.adaptBox():le(t);M(t.startNode.closestBlock());const i=se(t);i.focus.before(e),re(t,i),t.adaptBlock()}function ce(t,e){const i=C(e),n=document.createDocumentFragment();i.each((t=>{n.appendChild(t)})),he(t,n)}function de(t,e){if(t.commonAncestor.isOutside)return;if(t.isCollapsed&&t.isBox)return;if("string"!=typeof e){const i=t.getBlocks();for(const t of i)t.css(e);return}const i=C(e),n=i.name,s=i.get(0).attributes,o=t.getBlocks();if(o.length>0){const e=se(t);for(const t of o)if(t.name===n&&0===i.first().length)for(const e of s)t.attr(e.name,e.value);else{const e=i.clone(!0);t.isList&&""!==t.attr("indent")&&e.attr("indent",t.attr("indent"));const n=R(e);let s=t.first();for(;s.length>0;){const t=s.next();n.append(s),n.name!==s.name&&"li"!==s.name||s.remove(!0),s=t}t.replaceWith(e)}return re(t,e),void ae(t)}const r=se(t),a=function(t){const e=t.commonAncestor.closest('div[contenteditable="true"],td');let i=[];if(0===e.length)return i;let n=e.first(),s=!0;for(;n.length>0;){if(n.isMark||n.isText||n.isBookmark||n.isInlineBox)i.push(n);else{if(!s)break;i=[]}t.intersectsNode(n)&&(s=!1),n=n.next()}return i}(t),l=W(a,i);re(t,r),ae(t),l.isEmpty&&(_(l,C("<br />")),t.shrinkAfter(l))}function ue(t){if(t.commonAncestor.isOutside)return{left:null,right:null};t.isCollapsed?t.adaptBox():le(t);const e=t.startNode,i=e.closestOperableBlock();if(0===i.length)return{left:null,right:null};let n=i.parent();n.isOutside&&(n=e.closestContainer());const s=T(e,t.startOffset,n);let o=null,r=null;return s&&(o=s.left,r=s.right),!s&&e.isBlock&&(t.startOffset>0&&(o=e.children()[t.startOffset-1]),r=e.children()[t.startOffset],r&&!r.isBlock&&(r=null)),o&&o.isEmpty&&_(o,C("<br />")),r&&(r.isEmpty?(_(r,C("<br />")),t.shrinkAfter(r)):t.shrinkBefore(r)),ae(t),{left:o,right:r}}function pe(t){if(t.isMark&&t.isEmpty)t.remove();else for(const e of t.getWalker())e.isMark&&e.isEmpty&&e.remove()}function fe(t,e,i){let n=null,s=null,o=t.closestBlock();0===o.length&&(o=t.closestContainer());const r=T(t,e,o);return r&&(i?(pe(r.left),pe(r.right),r.left.isEmpty||(n=r.left),r.right.isEmpty||(s=r.right)):(n=r.left,s=r.right)),{left:n,right:s}}function me(t,e=!0){if(t.commonAncestor.isOutside)return{left:null,center:null,right:null};if(t.adaptBox(),t.isCollapsed){const i=fe(t.startNode,t.startOffset,e);return i.left?(t.setStartAfter(i.left),t.collapseToStart()):i.right&&(t.setStartBefore(i.right),t.collapseToStart()),{left:i.left,center:null,right:i.right}}const i=fe(t.startNode,t.startOffset,e);i.left?t.setStartAfter(i.left):i.right&&t.setStartBefore(i.right);const n=fe(t.endNode,t.endOffset,e);return n.left?t.setEndAfter(n.left):n.right&&t.setEndBefore(n.right),{left:i.left,center:n.left,right:n.right}}function ge(t,e){const i=t.text();let n=t;for(;n.length>0;){const t=n.parent();if(!t.isMark||i!==t.text()||!n.isText&&n.name===e&&""!==n.attr("style"))break;n=t}return n}function Oe(t,e){if(t.commonAncestor.isOutside)return;let i=C(e);const n=i.name,s=u(i.attr("style"));if(t.isCollapsed){if(t.isBox){const e=t.startNode.closest("lake-box");if("block"===new Kt(e).type){const i=C("<p><br /></p>");t.isBoxLeft?e.before(i):e.after(i),t.shrinkAfter(i)}else t.adaptBox()}M(t.startNode.closestBlock());const e=new Z(document.createTextNode("​")),o=me(t);if(o.left){const t=function(t){if(!t.isMark)return null;let e=t.clone(),i=t.last();for(;i.length>0;){if(i.isMark){const t=i.clone();e.append(t),e=t}i=i.last()}return e}(o.left);t&&(t.name===n?(t.css(s),i=t):(_(t,e),i.append(t)))}return""===i.text()&&i.append(e),ne(t,i),function(t){const e=t.prev();e.length>0&&e.isText&&e.isEmpty&&e.remove();const i=t.next();i.length>0&&i.isText&&i.isEmpty&&i.remove()}(i),void t.shrinkAfter(i)}me(t);const o=t.getMarks(!0),r=se(t);for(const t of o)if(!t.isEmpty&&t.isText){const e=ge(t,n);if(e.isMark&&e.name===n)e.css(s);else{const t=i.clone();e.before(t),t.append(e)}}re(t,r)}function ve(t){if(t.isMark&&t.isEmpty)t.remove();else for(const e of t.getWalker())e.isMark&&e.isEmpty&&e.remove()}function we(t,e){if(t.commonAncestor.isOutside)return;let i;if(e){i=C(e).name}if(t.isCollapsed){if(t.isBox)return;if(i&&0===t.commonAncestor.closest(i).length)return;const e=me(t,!1);if(!e.left)return;e.right&&ve(e.right);const n=new Z(document.createTextNode("​")),s=function(t,e){if(!t.isMark||!e)return null;let i=t.clone(),n=t.last();for(;n.length>0;){if(n.isMark&&n.name!==e){const t=n.clone();i.append(t),i=t}n=n.last()}if(i.name===e){if(!(i.first().length>0))return null;i=i.first()}return i}(e.left,i);return s?(_(s,n),e.left.after(s),ve(e.left),void t.shrinkAfter(s)):(e.left.after(n),ve(e.left),n.prev().isText?(t.setStartAfter(n.prev()),t.collapseToStart(),void n.remove()):(t.setStartAfter(n),void t.collapseToStart()))}me(t);const n=t.getMarks(),s=se(t);for(const t of n)if(!i||t.name===i){const e=t.parent();t.remove(!t.isEmpty),e.length>0&&e.get(0).normalize()}X(t.commonAncestor),re(t,s)}function ye(t,e){if(t.commonAncestor.isOutside)return null;const i=C(e);if(t.isCollapsed){let e=t.commonAncestor.closest("a");if(0===e.length){e=i.clone(!0);return M(t.startNode.closestBlock()),ne(t,e),e}return""!==i.attr("href")&&e.attr({href:i.attr("href")}),e}me(t);const n=se(t);for(const e of t.commonAncestor.getWalker())"a"===e.name&&t.intersectsNode(e)&&e.remove(!0);const s=i.clone(!1);n.anchor.after(s);let o=s.next();for(;o.length>0;){const t=o.next();if(!o.isMark&&!o.isText)break;s.append(o),o=t}return 0===s.first().length&&s.remove(),re(t,n),s}var be=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},xe="object"==typeof Yt&&Yt&&Yt.Object===Object&&Yt,ke="object"==typeof self&&self&&self.Object===Object&&self,Se=xe||ke||Function("return this")(),Qe=Se,Pe=function(){return Qe.Date.now()},$e=/\s/;var Ze=function(t){for(var e=t.length;e--&&$e.test(t.charAt(e)););return e},Ce=Ze,Ae=/^\s+/;var Te=function(t){return t?t.slice(0,Ce(t)+1).replace(Ae,""):t},_e=Se.Symbol,Me=_e,Be=Object.prototype,Ee=Be.hasOwnProperty,Re=Be.toString,We=Me?Me.toStringTag:void 0;var Xe=function(t){var e=Ee.call(t,We),i=t[We];try{t[We]=void 0;var n=!0}catch(t){}var s=Re.call(t);return n&&(e?t[We]=i:delete t[We]),s},De=Object.prototype.toString;var qe=Xe,Ie=function(t){return De.call(t)},Le=_e?_e.toStringTag:void 0;var Ye=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":Le&&Le in Object(t)?qe(t):Ie(t)},Ve=function(t){return null!=t&&"object"==typeof t};var ze=Te,Ne=be,je=function(t){return"symbol"==typeof t||Ve(t)&&"[object Symbol]"==Ye(t)},He=/^[-+]0x[0-9a-f]+$/i,Ge=/^0b[01]+$/i,Ue=/^0o[0-7]+$/i,Fe=parseInt;var Ke=be,Je=Pe,ti=function(t){if("number"==typeof t)return t;if(je(t))return NaN;if(Ne(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Ne(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=ze(t);var i=Ge.test(t);return i||Ue.test(t)?Fe(t.slice(2),i?2:8):He.test(t)?NaN:+t},ei=Math.max,ii=Math.min;var ni=function(t,e,i){var n,s,o,r,a,l,h=0,c=!1,d=!1,u=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function p(e){var i=n,o=s;return n=s=void 0,h=e,r=t.apply(o,i)}function f(t){var i=t-l;return void 0===l||i>=e||i<0||d&&t-h>=o}function m(){var t=Je();if(f(t))return g(t);a=setTimeout(m,function(t){var i=e-(t-l);return d?ii(i,o-(t-h)):i}(t))}function g(t){return a=void 0,u&&n?p(t):(n=s=void 0,r)}function O(){var t=Je(),i=f(t);if(n=arguments,s=this,l=t,i){if(void 0===a)return function(t){return h=t,a=setTimeout(m,e),c?p(t):r}(l);if(d)return clearTimeout(a),a=setTimeout(m,e),p(l)}return void 0===a&&(a=setTimeout(m,e)),r}return e=ti(e)||0,Ke(i)&&(c=!!i.leading,o=(d="maxWait"in i)?ei(ti(i.maxWait)||0,e):o,u="trailing"in i?!!i.trailing:u),O.cancel=function(){void 0!==a&&clearTimeout(a),h=0,n=l=s=a=void 0},O.flush=function(){return void 0===a?r:g(Je())},O},si=Vt(ni),oi="0.0.2";function ri(t){const e=t.get(0),i={};if(e.hasAttributes())for(const t of e.attributes)i[t.name]=t.value;return i}class ai{constructor(t){const e=window.getSelection();if(!e)throw new Error("Selection object is null.");this.selection=e,this.container=t,this.range=this.getRangeFromNativeSelection(),this.appliedItems=[]}getRangeFromNativeSelection(){if(this.selection.rangeCount>0){const t=this.selection.getRangeAt(0);return new A(t)}return new A}addRangeToNativeSelection(){this.selection.removeAllRanges(),this.selection.addRange(this.range.get())}syncByRange(){const t=this.getRangeFromNativeSelection();this.range.get()!==t.get()&&(this.range=t)}synByBookmark(){const t=this.range,e=this.container,i=e.find("lake-box[focus]");if(i.length>0)return re(t,{anchor:new Z,focus:i}),void this.addRangeToNativeSelection();re(t,{anchor:e.find('lake-bookmark[type="anchor"]'),focus:e.find('lake-bookmark[type="focus"]')}),this.addRangeToNativeSelection()}getAppliedItems(){const t=[];return function(t,e){let i=e.startNode;for(i.isText&&(i=i.parent());i.length>0&&i.isInside;)t.push({node:i,name:i.name,attributes:ri(i),styles:u(i.attr("style"))}),i=i.parent()}(t,this.range),function(t,e){const i=e.startNode;let n;if(i.isText&&i.text().length===e.startOffset){const t=i.next();t.length>0&&t.isElement&&(n=t)}if(i.isElement){const t=i.children();if(t.length>0){const i=t[e.startOffset];i&&i.isElement&&(n=i)}}if(n){let e=n;for(;e.length>0;)e.isElement&&t.push({node:e,name:e.name,attributes:ri(e),styles:u(e.attr("style"))}),e=e.first()}}(t,this.range),t}insertBookmark(){return se(this.range)}toBookmark(t){return re(this.range,t)}insertNode(t){return ne(this.range,t)}insertFragment(t){return he(this.range,t)}insertContents(t){return ce(this.range,t)}deleteContents(){return le(this.range)}setBlocks(t){return de(this.range,t)}splitBlock(){return ue(this.range)}splitMarks(t){return me(this.range,t)}addMark(t){return Oe(this.range,t)}removeMark(t){return we(this.range,t)}fixList(){return ae(this.range)}insertLink(t){return ye(this.range,t)}}class li{constructor(){this.commandMap=new Map,this.event=new Nt}add(t,e){this.commandMap.set(t,e)}getNames(){return Array.from(this.commandMap.keys())}execute(t,...e){const i=this.commandMap.get(t);if(void 0===i)throw new Error(`Command '${t}' does not exist.`);this.event.emit("beforeexecute",t),i.apply(this,e),this.event.emit("execute",t),Q(`Command '${t}' executed`)}}var hi,ci={exports:{}};hi=ci,function(t){function e(t,e){var i=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(i>>16)<<16|65535&i}function i(t,i,n,s,o,r){return e((a=e(e(i,t),e(s,r)))<<(l=o)|a>>>32-l,n);var a,l}function n(t,e,n,s,o,r,a){return i(e&n|~e&s,t,e,o,r,a)}function s(t,e,n,s,o,r,a){return i(e&s|n&~s,t,e,o,r,a)}function o(t,e,n,s,o,r,a){return i(e^n^s,t,e,o,r,a)}function r(t,e,n,s,o,r,a){return i(n^(e|~s),t,e,o,r,a)}function a(t,i){var a,l,h,c,d;t[i>>5]|=128<<i%32,t[14+(i+64>>>9<<4)]=i;var u=1732584193,p=-271733879,f=-1732584194,m=271733878;for(a=0;a<t.length;a+=16)l=u,h=p,c=f,d=m,u=n(u,p,f,m,t[a],7,-680876936),m=n(m,u,p,f,t[a+1],12,-389564586),f=n(f,m,u,p,t[a+2],17,606105819),p=n(p,f,m,u,t[a+3],22,-1044525330),u=n(u,p,f,m,t[a+4],7,-176418897),m=n(m,u,p,f,t[a+5],12,1200080426),f=n(f,m,u,p,t[a+6],17,-1473231341),p=n(p,f,m,u,t[a+7],22,-45705983),u=n(u,p,f,m,t[a+8],7,1770035416),m=n(m,u,p,f,t[a+9],12,-1958414417),f=n(f,m,u,p,t[a+10],17,-42063),p=n(p,f,m,u,t[a+11],22,-1990404162),u=n(u,p,f,m,t[a+12],7,1804603682),m=n(m,u,p,f,t[a+13],12,-40341101),f=n(f,m,u,p,t[a+14],17,-1502002290),u=s(u,p=n(p,f,m,u,t[a+15],22,1236535329),f,m,t[a+1],5,-165796510),m=s(m,u,p,f,t[a+6],9,-1069501632),f=s(f,m,u,p,t[a+11],14,643717713),p=s(p,f,m,u,t[a],20,-373897302),u=s(u,p,f,m,t[a+5],5,-701558691),m=s(m,u,p,f,t[a+10],9,38016083),f=s(f,m,u,p,t[a+15],14,-660478335),p=s(p,f,m,u,t[a+4],20,-405537848),u=s(u,p,f,m,t[a+9],5,568446438),m=s(m,u,p,f,t[a+14],9,-1019803690),f=s(f,m,u,p,t[a+3],14,-187363961),p=s(p,f,m,u,t[a+8],20,1163531501),u=s(u,p,f,m,t[a+13],5,-1444681467),m=s(m,u,p,f,t[a+2],9,-51403784),f=s(f,m,u,p,t[a+7],14,1735328473),u=o(u,p=s(p,f,m,u,t[a+12],20,-1926607734),f,m,t[a+5],4,-378558),m=o(m,u,p,f,t[a+8],11,-2022574463),f=o(f,m,u,p,t[a+11],16,1839030562),p=o(p,f,m,u,t[a+14],23,-35309556),u=o(u,p,f,m,t[a+1],4,-1530992060),m=o(m,u,p,f,t[a+4],11,1272893353),f=o(f,m,u,p,t[a+7],16,-155497632),p=o(p,f,m,u,t[a+10],23,-1094730640),u=o(u,p,f,m,t[a+13],4,681279174),m=o(m,u,p,f,t[a],11,-358537222),f=o(f,m,u,p,t[a+3],16,-722521979),p=o(p,f,m,u,t[a+6],23,76029189),u=o(u,p,f,m,t[a+9],4,-640364487),m=o(m,u,p,f,t[a+12],11,-421815835),f=o(f,m,u,p,t[a+15],16,530742520),u=r(u,p=o(p,f,m,u,t[a+2],23,-995338651),f,m,t[a],6,-198630844),m=r(m,u,p,f,t[a+7],10,1126891415),f=r(f,m,u,p,t[a+14],15,-1416354905),p=r(p,f,m,u,t[a+5],21,-57434055),u=r(u,p,f,m,t[a+12],6,1700485571),m=r(m,u,p,f,t[a+3],10,-1894986606),f=r(f,m,u,p,t[a+10],15,-1051523),p=r(p,f,m,u,t[a+1],21,-2054922799),u=r(u,p,f,m,t[a+8],6,1873313359),m=r(m,u,p,f,t[a+15],10,-30611744),f=r(f,m,u,p,t[a+6],15,-1560198380),p=r(p,f,m,u,t[a+13],21,1309151649),u=r(u,p,f,m,t[a+4],6,-145523070),m=r(m,u,p,f,t[a+11],10,-1120210379),f=r(f,m,u,p,t[a+2],15,718787259),p=r(p,f,m,u,t[a+9],21,-343485551),u=e(u,l),p=e(p,h),f=e(f,c),m=e(m,d);return[u,p,f,m]}function l(t){var e,i="",n=32*t.length;for(e=0;e<n;e+=8)i+=String.fromCharCode(t[e>>5]>>>e%32&255);return i}function h(t){var e,i=[];for(i[(t.length>>2)-1]=void 0,e=0;e<i.length;e+=1)i[e]=0;var n=8*t.length;for(e=0;e<n;e+=8)i[e>>5]|=(255&t.charCodeAt(e/8))<<e%32;return i}function c(t){var e,i,n="0123456789abcdef",s="";for(i=0;i<t.length;i+=1)e=t.charCodeAt(i),s+=n.charAt(e>>>4&15)+n.charAt(15&e);return s}function d(t){return unescape(encodeURIComponent(t))}function u(t){return function(t){return l(a(h(t),8*t.length))}(d(t))}function p(t,e){return function(t,e){var i,n,s=h(t),o=[],r=[];for(o[15]=r[15]=void 0,s.length>16&&(s=a(s,8*t.length)),i=0;i<16;i+=1)o[i]=909522486^s[i],r[i]=1549556828^s[i];return n=a(o.concat(h(e)),512+8*e.length),l(a(r.concat(n),640))}(d(t),d(e))}function f(t,e,i){return e?i?p(e,t):c(p(e,t)):i?u(t):c(u(t))}hi.exports?hi.exports=f:t.md5=f}(Yt);var di=Vt(ci.exports);const ui=new Map;class pi{constructor(t){this.selection=t,this.container=t.container,this.list=[],this.index=0,this.canSave=!0,this.limit=100,this.event=new Nt}removeBookmark(t){return t.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(t){return new ee(t).getHTML()}addIdToBoxes(t){t.find("lake-box").each((t=>{const e=new Z(t),i=di(`${e.attr("type")}-${e.attr("name")}-${e.attr("value")}`);e.attr("id",i)}))}removeIdfromBoxes(t){t.find("lake-box").each((t=>{new Z(t).removeAttr("id")}))}morphContainer(t){const e=this.container,i={beforeChildrenUpdated:t=>{if("lake-box"===new Z(t).name)return!1},afterAttributeUpdated:(t,i)=>{const n=new Z(i);if("value"===t&&"lake-box"===n.name){const t=ui.get(e.id);if(!t)return;t.delete(n.id)}}},n=t.clone(!0);this.addIdToBoxes(e),this.addIdToBoxes(n),ht(e,n,{callbacks:i}),this.removeIdfromBoxes(e),this.removeIdfromBoxes(n)}cloneContainer(){const t=this.selection.range,e=this.container.clone(!0);if(e.find("lake-box").each((t=>{new Kt(t).getContainer().empty()})),t.commonAncestor.isOutside)return e;if(t.isInsideBox)return e;const i=t.startNode.path(),n=t.endNode.path(),s=e.find(i),o=e.find(n),r=t.clone();return r.setStart(s,t.startOffset),r.setEnd(o,t.endOffset),se(r),e}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 t=this.getValue(this.container);for(;this.index>0;){const e=this.list[this.index-1];if(!e)break;const i=this.getValue(e);if(this.removeBookmark(i)!==this.removeBookmark(t)){this.morphContainer(e),this.event.emit("undo",i);break}if(1===this.index)break;this.index--}this.selection.synByBookmark(),Q(`History undone, the last index is ${this.index}`)}redo(){if(!this.list[this.index])return;this.selection.insertBookmark();const t=this.getValue(this.container);for(;this.index<this.list.length;){const e=this.list[this.index];if(!e)break;this.index++;const i=this.getValue(e);if(this.removeBookmark(i)!==this.removeBookmark(t)){this.morphContainer(e),this.event.emit("redo",i);break}}this.selection.synByBookmark(),Q(`History redone, the last index is ${this.index}`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(){if(!this.canSave)return;const t=this.cloneContainer(),e=this.getValue(t);this.list[this.index-1]&&this.removeBookmark(this.getValue(this.list[this.index-1]))===this.removeBookmark(e)||(this.list.splice(this.index,1/0,t),this.index++,this.list.length>this.limit&&(this.list.shift(),this.index=this.list.length),this.event.emit("save",e),Q(`History saved, the last index is ${this.index}`))}}var fi=["Shift","Meta","Alt","Control"],mi="object"==typeof navigator?navigator.platform:"",gi=/Mac|iPod|iPhone|iPad/.test(mi),Oi=gi?"Meta":"Control",vi="Win32"===mi?["Control","Alt"]:gi?["Alt"]:[];function wi(t,e){return"function"==typeof t.getModifierState&&(t.getModifierState(e)||vi.includes(e)&&t.getModifierState("AltGraph"))}function yi(t){return t.trim().split(" ").map((function(t){var e=t.split(/\b\+/),i=e.pop();return[e=e.map((function(t){return"$mod"===t?Oi:t})),i]}))}function bi(t,e){var i;void 0===e&&(e={});var n=null!=(i=e.timeout)?i:1e3,s=Object.keys(t).map((function(e){return[yi(e),t[e]]})),o=new Map,r=null;return function(t){t instanceof KeyboardEvent&&(s.forEach((function(e){var i=e[0],n=e[1],s=o.get(i)||i;!function(t,e){return!(e[1].toUpperCase()!==t.key.toUpperCase()&&e[1]!==t.code||e[0].find((function(e){return!wi(t,e)}))||fi.find((function(i){return!e[0].includes(i)&&e[1]!==i&&wi(t,i)})))}(t,s[0])?wi(t,t.key)||o.delete(i):s.length>1?o.set(i,s.slice(1)):(o.delete(i),n(t))})),r&&clearTimeout(r),r=setTimeout(o.clear.bind(o),n))}}const xi=new Map([["#","shift+#"]]);class ki{constructor(t){this.container=t,this.keydownEventList=[],this.keyupEventList=[]}normalizeType(t){var e;return t=(t=null!==(e=xi.get(t))&&void 0!==e?e:t).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/,(t=>t.charAt(0).toUpperCase()+l(t.substring(1)))).replace(/(^|\+|\s)([a-z])(\+|\s|$)/g,((t,e,i,n)=>`${e}Key${i.toUpperCase()}${n}`))}setKeydown(t,e){const i=bi({[t=this.normalizeType(t)]:t=>e(t)});this.keydownEventList.push({type:t,listener:e}),this.container.on("keydown",i)}setKeyup(t,e){const i=bi({[t=this.normalizeType(t)]:t=>e(t)});this.keyupEventList.push({type:t,listener:e}),this.container.on("keyup",i)}keydown(t){t=this.normalizeType(t);for(const e of this.keydownEventList)e.type===t&&e.listener(new Event(t))}keyup(t){t=this.normalizeType(t);for(const e of this.keyupEventList)e.type===t&&e.listener(new Event(t))}}const Si={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 Qi{constructor(t){if(!t.root)throw new Error("The root of the config must be specified.");this.root=C(t.root),this.config=Object.assign(Object.assign({},Si),t),this.containerWrapper=C('<div class="lake-container-wrapper" />'),this.container=C('<div class="lake-container" />'),this.overlayContainer=C('<div class="lake-overlay" />'),this.popupContainer=C('<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 Nt,this.selection=new ai(this.container),this.command=new li,this.history=new pi(this.selection),this.keystroke=new ki(this.container),this.box=Qi.box,this.unsavedInputData="",Ht.set(this.container.id,this),this.beforeunloadListener=()=>{this.commitUnsavedInputData()};const e=si((()=>{if(0===this.root.first().length)return;const t=this.selection.range,e=t.clone();e.adaptBox(),this.box.findAll(this).each((i=>{const n=new Kt(i),s=n.getContainer();if(0!==s.length){if(t.compareBeforeNode(s)<0&&t.compareAfterNode(s)>0&&(!t.isCollapsed||t.startNode.get(0)!==s.get(0)||0!==t.startOffset))return s.removeClass("lake-box-selected"),s.removeClass("lake-box-focused"),void s.addClass("lake-box-activated");if(e.intersectsNode(n.node))return s.removeClass("lake-box-activated"),void(t.isCollapsed?(s.removeClass("lake-box-selected"),s.addClass("lake-box-focused")):(s.removeClass("lake-box-focused"),s.addClass("lake-box-selected")));s.removeClass("lake-box-activated"),s.removeClass("lake-box-focused"),s.removeClass("lake-box-selected")}}))}),50,{leading:!1,trailing:!0,maxWait:50});this.selectionchangeListener=()=>{this.selection.syncByRange(),this.selection.appliedItems=this.selection.getAppliedItems(),e(),this.event.emit("selectionchange")},this.clickListener=t=>{const e=new Z(t.target);this.event.emit("click",e)},this.mouseoverListener=t=>{const e=new Z(t.target);this.event.emit("mouseover",e)},this.resizeListener=()=>{this.event.emit("resize")}}inputInBoxStrip(){const t=this.selection,e=t.range,i=e.startNode.closest(".lake-box-strip"),n=i.closest("lake-box");if("inline"===new Kt(n).type)e.isBoxLeft?(e.setStartBefore(n),e.collapseToStart()):(e.setStartAfter(n),e.collapseToStart());else{const t=C("<p />");e.isBoxLeft?n.before(t):n.after(t),e.shrinkAfter(t)}const s=i.text();i.html("<br />"),t.insertNode(document.createTextNode(s))}bindInputEvents(){this.container.on("compositionstart",(()=>{this.isComposing=!0})),this.container.on("compositionend",(()=>{this.isComposing=!1})),this.container.on("beforeinput",(()=>{const t=this.selection.range;(t.isBoxLeft||t.isBoxRight)&&this.commitUnsavedInputData()})),this.container.on("input",(t=>{const e=t;window.setTimeout((()=>{var t;const i=this.selection.range;if(!i.isInsideBox)if(this.isComposing)this.event.emit("input",e);else{if("insertText"===e.inputType||"insertCompositionText"===e.inputType)if(i.isBoxLeft||i.isBoxRight)this.inputInBoxStrip();else if(this.unsavedInputData+=null!==(t=e.data)&&void 0!==t?t:"",this.unsavedInputData.length<this.config.minChangeSize)return void this.event.emit("input",e);this.history.save(),this.unsavedInputData="",this.event.emit("input",e)}}),0)})),this.command.event.on("beforeexecute",(()=>this.commitUnsavedInputData()))}bindHistoryEvents(){this.history.event.on("undo",(t=>{this.box.renderAll(this),this.event.emit("change",t)})),this.history.event.on("redo",(t=>{this.box.renderAll(this),this.event.emit("change",t)})),this.history.event.on("save",(t=>{this.box.rectifyInstances(this),this.event.emit("change",t)}))}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(t){t=p(t);const e=new ee(t).getFragment();this.container.empty(),this.container.append(e),Qi.box.renderAll(this),this.selection.synByBookmark()}getValue(){const t=this.selection.insertBookmark();let e=new ee(this.container).getHTML();return e=f(e),this.selection.toBookmark(t),e}insertBox(t,e){const i=function(t,e,i){if(t.commonAncestor.isOutside)return null;const n=new Kt(e);i&&(n.value=i);const s=document.createDocumentFragment();if(s.appendChild(n.node.get(0)),"inline"===n.type)return he(t,s),n.render(),t.selectBoxRight(n.node),n;const o=ue(t);return o.left&&(t.setEndAfter(o.left),t.collapseToEnd()),o.right&&o.right.isEmpty&&o.right.remove(),he(t,s),n.render(),t.selectBoxRight(n.node),o.left&&o.left.isEmpty&&o.left.remove(),n}(this.selection.range,t,e);if(!i)return i;return this.box.getInstances(this).set(i.node.id,i),i}removeBox(){const t=function(t){if(t.commonAncestor.isOutside)return null;const e=t.commonAncestor.closest("lake-box");if(0===e.length)return null;const i=new Kt(e);if("block"===i.type){const n=C("<p><br /></p>");return e.before(n),t.shrinkAfter(n),i.unmount(),e.remove(),i}t.setStartBefore(e),t.collapseToStart();const n=e.parent();return i.unmount(),e.remove(),n.isEmpty&&(_(n,C("<br />")),t.shrinkAfter(n)),i}(this.selection.range);if(t){this.box.getInstances(this).delete(t.node.id)}return t}innerWidth(){const t=parseInt(this.container.computedCSS("padding-left"),10)||0,e=parseInt(this.container.computedCSS("padding-right"),10)||0;return this.container.width()-t-e}render(){const t=p(this.config.value),e=new ee(t).getFragment();this.root.empty(),this.root.append(this.containerWrapper),this.containerWrapper.append(this.container),this.containerWrapper.append(this.overlayContainer),C(document.body).append(this.popupContainer),this.container.append(e),this.readonly||(this.focus(),this.selection.synByBookmark(),this.history.save()),Qi.plugin.loadAll(this),Qi.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)}}Qi.version=oi,Qi.box=new class{add(t){jt.set(t.name,t)}remove(t){jt.delete(t)}getNames(){return Array.from(jt.keys())}getInstances(t){let e=ui.get(t.container.id);return e||(e=new Map,ui.set(t.container.id,e),e)}rectifyInstances(t){const e=this.getInstances(t);for(const t of e.values())t.node.get(0).isConnected||(t.unmount(),e.delete(t.node.id))}findAll(t){return t.container.find("lake-box")}renderAll(t){this.rectifyInstances(t);const e=this.getInstances(t);this.findAll(t).each((t=>{const i=new Z(t);if(e.get(i.id))return;const n=new Kt(i);n.render(),e.set(n.node.id,n)}))}},Qi.plugin=new class{constructor(){this.pluginList=[]}add(t){this.pluginList.push(t)}loadAll(t){this.pluginList.forEach((e=>{e(t)}))}};const Pi=[{icon:n.get("numberedList"),value:"numbered",text:"Numbered list"},{icon:n.get("bulletedList"),value:"bulleted",text:"Bulleted list"},{icon:n.get("checklist"),value:"checklist",text:"Checklist"}],$i=[{icon:n.get("alignLeft"),value:"left",text:"Align left"},{icon:n.get("alignCenter"),value:"center",text:"Align center"},{icon:n.get("alignRight"),value:"right",text:"Align right"},{icon:n.get("alignJustify"),value:"justify",text:"Align justify"}],Zi=[{icon:n.get("increaseIndent"),value:"increase",text:"Increase indent"},{icon:n.get("decreaseIndent"),value:"decrease",text:"Decrease indent"}],Ci=[{icon:n.get("italic"),value:"italic",text:"Italic"},{icon:n.get("underline"),value:"underline",text:"Underline"},{icon:n.get("strikethrough"),value:"strikethrough",text:"Strikethrough"},{icon:n.get("superscript"),value:"superscript",text:"Superscript"},{icon:n.get("subscript"),value:"subscript",text:"Subscript"},{icon:n.get("code"),value:"code",text:"Code"}],Ai=["#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"],Ti=[{icon:n.get("removeFormat"),value:"",text:"Remove color"}];for(const t of Ai)Ti.push({value:t.toLowerCase(),text:t.toUpperCase()});const _i=new Map([["strong","bold"],["em","italic"],["i","italic"],["u","underline"],["s","strikethrough"],["sup","superscript"],["sub","subscript"],["code","code"]]),Mi=[{name:"undo",type:"button",icon:n.get("undo"),tooltip:"Undo",onClick:(t,e)=>{t.command.execute(e)}},{name:"redo",type:"button",icon:n.get("redo"),tooltip:"Redo",onClick:(t,e)=>{t.command.execute(e)}},{name:"selectAll",type:"button",icon:n.get("selectAll"),tooltip:"Select all",onClick:(t,e)=>{t.command.execute(e)}},{name:"paragraph",type:"button",icon:n.get("paragraph"),tooltip:"Paragraph",isSelected:t=>!!t.find((t=>"p"===t.name)),onClick:t=>{t.command.execute("heading","p")}},{name:"blockQuote",type:"button",icon:n.get("blockQuote"),tooltip:"Block quotation",isSelected:t=>!!t.find((t=>"blockquote"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"numberedList",type:"button",icon:n.get("numberedList"),tooltip:"Numbered list",isSelected:t=>!!t.find((t=>"ol"===t.name)),onClick:t=>{t.command.execute("list","numbered")}},{name:"bulletedList",type:"button",icon:n.get("bulletedList"),tooltip:"Bulleted list",isSelected:t=>!!t.find((t=>"ul"===t.name&&!t.node.hasAttr("type"))),onClick:t=>{t.command.execute("list","bulleted")}},{name:"checklist",type:"button",icon:n.get("checklist"),tooltip:"Checklist",isSelected:t=>!!t.find((t=>"ul"===t.name&&"checklist"===t.node.attr("type"))),onClick:t=>{t.command.execute("list","checklist")}},{name:"alignLeft",type:"button",icon:n.get("alignLeft"),tooltip:"Align left",isSelected:t=>!!t.find((t=>t.node.isBlock&&"left"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","left")}},{name:"alignCenter",type:"button",icon:n.get("alignCenter"),tooltip:"Align center",isSelected:t=>!!t.find((t=>t.node.isBlock&&"center"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","center")}},{name:"alignRight",type:"button",icon:n.get("alignRight"),tooltip:"Align right",isSelected:t=>!!t.find((t=>t.node.isBlock&&"right"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","right")}},{name:"alignJustify",type:"button",icon:n.get("alignJustify"),tooltip:"Align justify",isSelected:t=>!!t.find((t=>t.node.isBlock&&"justify"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","justify")}},{name:"increaseIndent",type:"button",icon:n.get("increaseIndent"),tooltip:"Increase indent",onClick:t=>{t.command.execute("indent","increase")}},{name:"decreaseIndent",type:"button",icon:n.get("decreaseIndent"),tooltip:"Decrease indent",onClick:t=>{t.command.execute("indent","decrease")}},{name:"bold",type:"button",icon:n.get("bold"),tooltip:"Bold",isDisabled:t=>!!t.find((t=>t.node.isHeading)),isSelected:t=>!!t.find((t=>"strong"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"italic",type:"button",icon:n.get("italic"),tooltip:"Italic",isSelected:t=>!!t.find((t=>"i"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"underline",type:"button",icon:n.get("underline"),tooltip:"Underline",isSelected:t=>!!t.find((t=>"u"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"strikethrough",type:"button",icon:n.get("strikethrough"),tooltip:"Strikethrough",isSelected:t=>!!t.find((t=>"s"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"superscript",type:"button",icon:n.get("superscript"),tooltip:"Superscript",isSelected:t=>!!t.find((t=>"sup"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"subscript",type:"button",icon:n.get("subscript"),tooltip:"Subscript",isSelected:t=>!!t.find((t=>"sub"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"code",type:"button",icon:n.get("code"),tooltip:"Inline code",isSelected:t=>!!t.find((t=>"code"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"removeFormat",type:"button",icon:n.get("removeFormat"),tooltip:"Remove format",onClick:(t,e)=>{t.command.execute(e)}},{name:"formatPainter",type:"button",icon:n.get("formatPainter"),tooltip:"Format painter",onClick:(t,e)=>{t.command.execute(e)}},{name:"link",type:"button",icon:n.get("link"),tooltip:"Link",onClick:(t,e)=>{t.command.execute(e)}},{name:"hr",type:"button",icon:n.get("hr"),tooltip:"Horizontal line",onClick:(t,e)=>{t.command.execute(e)}},{name:"codeBlock",type:"button",icon:n.get("codeBlock"),tooltip:"Code block",onClick:(t,e)=>{t.command.execute(e)}},{name:"heading",type:"dropdown",downIcon:n.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:t=>{const e=t.find((t=>t.node.isHeading||"p"===t.name));return e?[e.name]:[]},onSelect:(t,e)=>{t.command.execute("heading",e)}},{name:"list",type:"dropdown",downIcon:n.get("down"),icon:n.get("list"),defaultValue:"",tooltip:"List",width:"auto",menuType:"list",menuItems:Pi,selectedValues:t=>{let e="";for(const i of t){if("ol"===i.name){e="numbered";break}if("ul"===i.name&&!i.node.hasAttr("type")){e="bulleted";break}if("ul"===i.name&&"checklist"===i.node.attr("type")){e="checklist";break}}return[e]},onSelect:(t,e)=>{t.command.execute("list",e)}},{name:"align",type:"dropdown",downIcon:n.get("down"),icon:n.get("alignLeft"),defaultValue:"",tooltip:"Alignment",width:"auto",menuType:"list",menuItems:$i,selectedValues:t=>{let e="";for(const i of t)if(i.node.isBlock){e=i.node.computedCSS("text-align");break}return[e]},onSelect:(t,e)=>{t.command.execute("align",e)}},{name:"indent",type:"dropdown",downIcon:n.get("down"),icon:n.get("increaseIndent"),defaultValue:"",tooltip:"Indent",width:"auto",menuType:"list",menuItems:Zi,onSelect:(t,e)=>{t.command.execute("indent",e)}},{name:"fontFamily",type:"dropdown",downIcon:n.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:t=>{for(const e of t)if("span"===e.name){return[e.node.css("font-family").replace(/['"]/g,"")]}return[]},onSelect:(t,e)=>{t.command.execute("fontFamily",e)}},{name:"fontSize",type:"dropdown",downIcon:n.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:t=>!!t.find((t=>t.node.isHeading)),selectedValues:t=>{for(const e of t)if("span"===e.name){return[e.node.css("font-size").replace(/\.\d+/,"")]}return[]},onSelect:(t,e)=>{t.command.execute("fontSize",e)}},{name:"moreStyle",type:"dropdown",icon:n.get("more"),defaultValue:"",tooltip:"More style",width:"auto",menuType:"list",menuItems:Ci,selectedValues:t=>{var e;const i=[];for(const n of t)if(n.node.isMark){const t=null!==(e=_i.get(n.name))&&void 0!==e?e:n.name;i.push(t)}return i},onSelect:(t,e)=>{t.command.execute(e)}},{name:"fontColor",type:"dropdown",downIcon:n.get("down"),icon:n.get("fontColor"),accentIcon:n.get("fontColorAccent"),defaultValue:"#f5222d",tooltip:"Font color",width:"auto",menuType:"color",menuItems:Ti,selectedValues:t=>{for(const e of t)if("span"===e.name){return[d(e.node.computedCSS("color"))]}return[]},onSelect:(t,e)=>{t.command.execute("fontColor",e)}},{name:"highlight",type:"dropdown",downIcon:n.get("down"),icon:n.get("highlight"),accentIcon:n.get("highlightAccent"),defaultValue:"#fadb14",tooltip:"Highlight",width:"auto",menuType:"color",menuItems:Ti,selectedValues:t=>{for(const e of t)if("span"===e.name){return[d(e.node.computedCSS("background-color"))]}return[]},onSelect:(t,e)=>{t.command.execute("highlight",e)}},{name:"image",type:"upload",icon:n.get("image"),tooltip:"Image",accept:"image/*",multiple:!0}];function Bi(t){const{editor:e,file:i,onError:n,onSuccess:s}=t,{imageRequestMethod:o,imageRequestAction:r,imageRequestTypes:a}=e.config;if(a.indexOf(i.type)<0)throw new Error(`Cannot upload file because its type '${i.type}' is not found in ['${a.join("', '")}'].`);const l=e.insertBox("image",{url:URL.createObjectURL(i),status:"uploading",name:i.name,size:i.size,type:i.type,lastModified:i.lastModified});if(!l)throw new Error("The image box cannot be inserted outside the editor.");const h=dt({onProgress:t=>{const e=l.node.find(".lake-percent"),i=Math.round(t.percent);e.text(`${i<100?i:99} %`)},onError:(t,e)=>{Q(t.toString(),e),l.updateValue("status","error"),l.render(),n&&n()},onSuccess:t=>{if(!t.url)return l.updateValue("status","error"),l.render(),void(n&&n());l.updateValue({status:"done",url:t.url}),l.render(),e.history.save(),s&&s()},file:i,action:r,method:o});return l.setData("xhr",h),l}const Ei=["undo","redo","|","heading","fontSize","|","formatPainter","removeFormat","bold","moreStyle","|","fontColor","highlight","|","align","list","indent","link","blockQuote","hr"],Ri=new Map;Mi.forEach((t=>{Ri.set(t.name,t)}));function Wi(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{l(n.next(t))}catch(t){o(t)}}function a(t){try{l(n.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}l((n=n.apply(t,e||[])).next())}))}
5
+ `;class Kt{constructor(t){if(this.event=new Nt,"string"==typeof t){const e=jt.get(t);if(void 0===e)throw new Error(`Box '${t}' has not been defined yet.`);const i=r(e.type),n=r(e.name);this.node=C(a`<lake-box type="${i}" name="${n}"></lake-box>`),e.value&&(this.value=e.value)}else{this.node=C(t);const e=jt.get(this.name);if(void 0===e)throw new Error(`Box '${this.name}' has not been defined yet.`);e.value&&!this.node.hasAttr("value")&&(this.value=e.value)}Gt[this.node.id]||(Gt[this.node.id]={}),Ut[this.node.id]||(Ut[this.node.id]={setup:[],cleanup:[]})}addFramework(){let t=this.getContainer();0===t.length?(this.node.html(Ft),t=this.getContainer()):(t.off("mouseenter"),t.off("mouseleave"),t.off("click")),t.on("mouseenter",(()=>{t.hasClass("lake-box-selected")||t.hasClass("lake-box-focused")||t.hasClass("lake-box-activated")||t.addClass("lake-box-hovered")})),t.on("mouseleave",(()=>{t.removeClass("lake-box-hovered")})),t.on("click",(()=>{Q(`Box '${this.name}' (id = ${this.node.id}) value:`),Q(this.value)}))}get type(){return this.node.attr("type")}get name(){return this.node.attr("name")}get value(){const t=this.node.attr("value");return""===t?{}:JSON.parse(Lt(t))}set value(t){this.node.attr("value",It(JSON.stringify(t)))}updateValue(t,e){const i=this.value;"string"==typeof t?i[t]=e:m(t,((t,e)=>{i[t]=e})),this.value=i}getData(t){return Gt[this.node.id][t]}setData(t,e){Gt[this.node.id][t]=e}getEditor(){const t=this.node.closestContainer();return t.length>0?Ht.get(t.id):void 0}getContainer(){return this.node.find(".lake-box-container")}useEffect(t){Ut[this.node.id].setup.push(t)}render(){Ut[this.node.id].setup=[],Ut[this.node.id].cleanup=[];const t=jt.get(this.name);if(void 0===t)return;this.addFramework();const e=t.render(this);if(void 0!==e){const t=this.getContainer(),i=t.clone(!1);i.append(e),ht(t,i)}for(const t of Ut[this.node.id].setup){const e=t();void 0!==e&&Ut[this.node.id].cleanup.push(e)}Q(`Box '${this.name}' (id = ${this.node.id}) rendered`)}unmount(){for(const t of Ut[this.node.id].cleanup)t();Gt[this.node.id]={},Ut[this.node.id].setup=[],Ut[this.node.id].cleanup=[],this.node.empty(),Q(`Box '${this.name}' (id = ${this.node.id}) unmounted`)}getHTML(){const t=jt.get(this.name);return void 0===t?"":void 0===t.html?this.node.outerHTML():t.html(this)}}const Jt={id:/^[\w-]+$/,class:/^[\w-]+$/,style:{"text-align":["left","center","right","justify"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function te(){return{h1:Object.assign({},Jt),h2:Object.assign({},Jt),h3:Object.assign({},Jt),h4:Object.assign({},Jt),h5:Object.assign({},Jt),h6:Object.assign({},Jt),p:Object.assign({},Jt),blockquote:Object.assign(Object.assign({},Jt),{type:["success","info","warning","error"]}),ul:Object.assign(Object.assign({},Jt),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},Jt),{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 ee{constructor(t,e=te()){this.rules=e,this.source="string"==typeof t?this.parseHTML(t):t}parseHTML(t){const e=(new DOMParser).parseFromString(t,"text/html");return new Z(e.querySelector("body"))}static matchRule(t,e){return"string"==typeof t?t===e:Array.isArray(t)?t.indexOf(e)>=0:t instanceof RegExp&&t.test(e)}static getOpenTagString(t,e){let i=t.name,n=e[i];if(!n)return"";"string"==typeof n&&(i=n,n=e[i]);const s=t.get(0);if(!s.hasAttributes())return i;const o=new Map;for(const t of s.attributes)if(n[t.name]&&("style"!==t.name&&ee.matchRule(n[t.name],t.value)&&o.set(t.name,t.value),"style"===t.name)){const e=n.style,i=new Map;m(u(t.value),((t,n)=>{e[t]&&ee.matchRule(e[t],n)&&i.set(t,n)})),o.set("style",i)}let r=i;for(const[t,e]of o)if("style"===t){let t="";for(const[i,n]of e)t+=`${i}: ${n.replace(/"/g,"&quot;")}; `;""!==t&&(r+=` style="${t.trim()}"`)}else r+=` ${t}="${e}"`;return r}static getClosedTagString(t,e){let i=t.name;const n=e[i];return n?("string"==typeof n&&(i=n),i):""}static getTrimmedText(t){const e=t.parent(),i=t.prev(),n=t.next();let s=t.text();return(i.isBlock||i.isBlockBox)&&(n.isBlock||n.isBlockBox)||0===i.length&&0===n.length&&e.isBlock?s=s.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):i.isBlock||i.isBlockBox||0===i.length&&e.isBlock?s=s.replace(/^[\u0020\t\r\n]+/,""):(n.isBlock||n.isBlockBox||0===n.length&&e.isBlock)&&(s=s.replace(/[\u0020\t\r\n]+$/,"")),s}getHTML(){const t=this.rules;let e="";for(const i of function*e(i){let n=i.first();for(;n.length>0;){const i=n.next();if(n.isText)yield r(ee.getTrimmedText(n));else if(n.isVoid){const e=ee.getOpenTagString(n,t);""!==e&&(yield`<${e} />`)}else if(n.isElement){const i=ee.getOpenTagString(n,t),s=ee.getClosedTagString(n,t);""!==i&&(yield`<${i}>`),n.isBox||(yield*e(n)),""!==s&&(yield`</${s}>`)}n=i}}(this.source))e+=i;return e.trim()}getNodeList(){const t=this.getHTML();return this.parseHTML(t).children()}getFragment(){const t=this.getHTML(),e=this.parseHTML(t),i=document.createDocumentFragment();let n=e.first();for(;n.length>0;){const t=n.next();i.appendChild(n.get(0)),n=t}return i}}class ie{constructor(t){this.content=t}getHTML(){let t=this.content;return t=t.replace(/ {2}/g,"  "),t=r(t.trim()),t=`<p>${t}</p>`,t=t.replace(/(\r\n){2,}/g,"</p><p><br /></p><p>"),t=t.replace(/\r\n/g,"</p><p>"),t=t.replace(/[\r\n]{2,}/g,"</p><p><br /></p><p>"),t=t.replace(/[\r\n]/g,"</p><p>"),t}getFragment(){return new ee(this.getHTML()).getFragment()}}function ne(t,e){if(t.commonAncestor.isOutside)return;const i=(e=C(e)).get(0),n=t.get();n.insertNode(i),n.setEndAfter(i),n.collapse(!1)}function se(t){if(t.commonAncestor.isOutside)return{anchor:new Z,focus:new Z};const e=t.startNode.closest("lake-box");if(e.length>0)return t.isBoxLeft?e.attr("focus","left"):t.isBoxRight?e.attr("focus","right"):e.attr("focus","center"),{anchor:new Z,focus:e};if(t.isCollapsed){const e=t.clone();e.collapseToEnd();const i=C('<lake-bookmark type="focus" />');return ne(e,i),{anchor:new Z,focus:i}}const i=t.clone();i.collapseToStart();const n=C('<lake-bookmark type="anchor" />');ne(i,n);const s=t.clone();s.collapseToEnd();const o=C('<lake-bookmark type="focus" />');return ne(s,o),{anchor:n,focus:o}}function oe(t,e){const i=t.prev(),n=t.next();if(i.isText&&n.isText){const e=t.parent();X(e),t.remove(),e.get(0).normalize()}else if(0===i.length&&0===n.length){if(t.parent().isMark&&e){const i=new Z(document.createTextNode("​"));t.before(i),e.setStartAfter(i),e.collapseToStart()}t.remove()}else t.remove()}function re(t,e){const i=e.anchor,n=e.focus;if(i.length>0&&0===n.length)oe(i);else{if(n.length>0&&0===i.length){if(n.isBox){const e=new Kt(n);0===e.getContainer().length&&e.render();const i=n.attr("focus");return"left"===i?t.selectBoxLeft(n):"center"===i?t.selectBox(n):t.selectBoxRight(n),void n.removeAttr("focus")}return t.setStartBefore(n),t.collapseToStart(),void oe(n,t)}if(i.length>0&&n.length>0){const e=new A;e.selectNode(i),e.collapseToEnd(),-1===e.compareAfterNode(n)?(t.setStartBefore(n),oe(n),t.setEndBefore(i),oe(i)):(t.setStartBefore(i),oe(i),t.setEndBefore(n),oe(n))}}}function ae(t){if(t.commonAncestor.isOutside)return;q(t.getBlocks())}function le(t){if(t.isCollapsed)return;if(t.adapt(),t.isInoperative)return;const e=t.startNode.closestBlock(),i=t.endNode.closestBlock(),n=e.get(0)===i.get(0);if(t.get().deleteContents(),t.adaptBlock(),n){const e=t.getBlocks()[0];return void(e&&e.isEmpty&&(_(e,C("<br />")),t.shrinkAfter(e)))}const s=t.getBlocks()[0];if(!s)return;const o=s.prev();if(0===o.length)return;const r=se(t);E(o,s),re(t,r),ae(t)}function he(t,e){if(t.commonAncestor.isOutside)return;t.isCollapsed?t.adaptBox():le(t);M(t.startNode.closestBlock());const i=se(t);i.focus.before(e),re(t,i),t.adaptBlock()}function ce(t,e){const i=C(e),n=document.createDocumentFragment();i.each((t=>{n.appendChild(t)})),he(t,n)}function de(t,e){if(t.commonAncestor.isOutside)return;if(t.isCollapsed&&t.isBox)return;if("string"!=typeof e){const i=t.getBlocks();for(const t of i)t.css(e);return}const i=C(e),n=i.name,s=i.get(0).attributes,o=t.getBlocks();if(o.length>0){const e=se(t);for(const t of o)if(t.name===n&&0===i.first().length)for(const e of s)t.attr(e.name,e.value);else{const e=i.clone(!0);t.isList&&""!==t.attr("indent")&&e.attr("indent",t.attr("indent"));const n=R(e);let s=t.first();for(;s.length>0;){const t=s.next();n.append(s),n.name!==s.name&&"li"!==s.name||s.remove(!0),s=t}t.replaceWith(e)}return re(t,e),void ae(t)}const r=se(t),a=function(t){const e=t.commonAncestor.closest('div[contenteditable="true"],td');let i=[];if(0===e.length)return i;let n=e.first(),s=!0;for(;n.length>0;){if(n.isMark||n.isText||n.isBookmark||n.isInlineBox)i.push(n);else{if(!s)break;i=[]}t.intersectsNode(n)&&(s=!1),n=n.next()}return i}(t),l=W(a,i);re(t,r),ae(t),l.isEmpty&&(_(l,C("<br />")),t.shrinkAfter(l))}function ue(t){if(t.commonAncestor.isOutside)return{left:null,right:null};t.isCollapsed?t.adaptBox():le(t);const e=t.startNode,i=e.closestOperableBlock();if(0===i.length)return{left:null,right:null};let n=i.parent();n.isOutside&&(n=e.closestContainer());const s=T(e,t.startOffset,n);let o=null,r=null;return s&&(o=s.left,r=s.right),!s&&e.isBlock&&(t.startOffset>0&&(o=e.children()[t.startOffset-1]),r=e.children()[t.startOffset],r&&!r.isBlock&&(r=null)),o&&o.isEmpty&&_(o,C("<br />")),r&&(r.isEmpty?(_(r,C("<br />")),t.shrinkAfter(r)):t.shrinkBefore(r)),ae(t),{left:o,right:r}}function pe(t){if(t.isMark&&t.isEmpty)t.remove();else for(const e of t.getWalker())e.isMark&&e.isEmpty&&e.remove()}function fe(t,e,i){let n=null,s=null,o=t.closestBlock();0===o.length&&(o=t.closestContainer());const r=T(t,e,o);return r&&(i?(pe(r.left),pe(r.right),r.left.isEmpty||(n=r.left),r.right.isEmpty||(s=r.right)):(n=r.left,s=r.right)),{left:n,right:s}}function me(t,e=!0){if(t.commonAncestor.isOutside)return{left:null,center:null,right:null};if(t.adaptBox(),t.isCollapsed){const i=fe(t.startNode,t.startOffset,e);return i.left?(t.setStartAfter(i.left),t.collapseToStart()):i.right&&(t.setStartBefore(i.right),t.collapseToStart()),{left:i.left,center:null,right:i.right}}const i=fe(t.startNode,t.startOffset,e);i.left?t.setStartAfter(i.left):i.right&&t.setStartBefore(i.right);const n=fe(t.endNode,t.endOffset,e);return n.left?t.setEndAfter(n.left):n.right&&t.setEndBefore(n.right),{left:i.left,center:n.left,right:n.right}}function ge(t,e){const i=t.text();let n=t;for(;n.length>0;){const t=n.parent();if(!t.isMark||i!==t.text()||!n.isText&&n.name===e&&""!==n.attr("style"))break;n=t}return n}function Oe(t,e){if(t.commonAncestor.isOutside)return;let i=C(e);const n=i.name,s=u(i.attr("style"));if(t.isCollapsed){if(t.isBox){const e=t.startNode.closest("lake-box");if("block"===new Kt(e).type){const i=C("<p><br /></p>");t.isBoxLeft?e.before(i):e.after(i),t.shrinkAfter(i)}else t.adaptBox()}M(t.startNode.closestBlock());const e=new Z(document.createTextNode("​")),o=me(t);if(o.left){const t=function(t){if(!t.isMark)return null;let e=t.clone(),i=t.last();for(;i.length>0;){if(i.isMark){const t=i.clone();e.append(t),e=t}i=i.last()}return e}(o.left);t&&(t.name===n?(t.css(s),i=t):(_(t,e),i.append(t)))}return""===i.text()&&i.append(e),ne(t,i),function(t){const e=t.prev();e.length>0&&e.isText&&e.isEmpty&&e.remove();const i=t.next();i.length>0&&i.isText&&i.isEmpty&&i.remove()}(i),void t.shrinkAfter(i)}me(t);const o=t.getMarks(!0),r=se(t);for(const t of o)if(!t.isEmpty&&t.isText){const e=ge(t,n);if(e.isMark&&e.name===n)e.css(s);else{const t=i.clone();e.before(t),t.append(e)}}re(t,r)}function ve(t){if(t.isMark&&t.isEmpty)t.remove();else for(const e of t.getWalker())e.isMark&&e.isEmpty&&e.remove()}function we(t,e){if(t.commonAncestor.isOutside)return;let i;if(e){i=C(e).name}if(t.isCollapsed){if(t.isBox)return;if(i&&0===t.commonAncestor.closest(i).length)return;const e=me(t,!1);if(!e.left)return;e.right&&ve(e.right);const n=new Z(document.createTextNode("​")),s=function(t,e){if(!t.isMark||!e)return null;let i=t.clone(),n=t.last();for(;n.length>0;){if(n.isMark&&n.name!==e){const t=n.clone();i.append(t),i=t}n=n.last()}if(i.name===e){if(!(i.first().length>0))return null;i=i.first()}return i}(e.left,i);return s?(_(s,n),e.left.after(s),ve(e.left),void t.shrinkAfter(s)):(e.left.after(n),ve(e.left),n.prev().isText?(t.setStartAfter(n.prev()),t.collapseToStart(),void n.remove()):(t.setStartAfter(n),void t.collapseToStart()))}me(t);const n=t.getMarks(),s=se(t);for(const t of n)if(!i||t.name===i){const e=t.parent();t.remove(!t.isEmpty),e.length>0&&e.get(0).normalize()}X(t.commonAncestor),re(t,s)}function ye(t,e){if(t.commonAncestor.isOutside)return null;const i=C(e);if(t.isCollapsed){let e=t.commonAncestor.closest("a");if(0===e.length){e=i.clone(!0);return M(t.startNode.closestBlock()),ne(t,e),e}return""!==i.attr("href")&&e.attr({href:i.attr("href")}),e}me(t);const n=se(t);for(const e of t.commonAncestor.getWalker())"a"===e.name&&t.intersectsNode(e)&&e.remove(!0);const s=i.clone(!1);n.anchor.after(s);let o=s.next();for(;o.length>0;){const t=o.next();if(!o.isMark&&!o.isText)break;s.append(o),o=t}return 0===s.first().length&&s.remove(),re(t,n),s}var be=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},xe="object"==typeof Yt&&Yt&&Yt.Object===Object&&Yt,ke="object"==typeof self&&self&&self.Object===Object&&self,Se=xe||ke||Function("return this")(),Qe=Se,Pe=function(){return Qe.Date.now()},$e=/\s/;var Ze=function(t){for(var e=t.length;e--&&$e.test(t.charAt(e)););return e},Ce=Ze,Ae=/^\s+/;var Te=function(t){return t?t.slice(0,Ce(t)+1).replace(Ae,""):t},_e=Se.Symbol,Me=_e,Be=Object.prototype,Ee=Be.hasOwnProperty,Re=Be.toString,We=Me?Me.toStringTag:void 0;var Xe=function(t){var e=Ee.call(t,We),i=t[We];try{t[We]=void 0;var n=!0}catch(t){}var s=Re.call(t);return n&&(e?t[We]=i:delete t[We]),s},De=Object.prototype.toString;var qe=Xe,Ie=function(t){return De.call(t)},Le=_e?_e.toStringTag:void 0;var Ye=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":Le&&Le in Object(t)?qe(t):Ie(t)},Ve=function(t){return null!=t&&"object"==typeof t};var ze=Te,Ne=be,je=function(t){return"symbol"==typeof t||Ve(t)&&"[object Symbol]"==Ye(t)},He=/^[-+]0x[0-9a-f]+$/i,Ge=/^0b[01]+$/i,Ue=/^0o[0-7]+$/i,Fe=parseInt;var Ke=be,Je=Pe,ti=function(t){if("number"==typeof t)return t;if(je(t))return NaN;if(Ne(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Ne(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=ze(t);var i=Ge.test(t);return i||Ue.test(t)?Fe(t.slice(2),i?2:8):He.test(t)?NaN:+t},ei=Math.max,ii=Math.min;var ni=function(t,e,i){var n,s,o,r,a,l,h=0,c=!1,d=!1,u=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function p(e){var i=n,o=s;return n=s=void 0,h=e,r=t.apply(o,i)}function f(t){var i=t-l;return void 0===l||i>=e||i<0||d&&t-h>=o}function m(){var t=Je();if(f(t))return g(t);a=setTimeout(m,function(t){var i=e-(t-l);return d?ii(i,o-(t-h)):i}(t))}function g(t){return a=void 0,u&&n?p(t):(n=s=void 0,r)}function O(){var t=Je(),i=f(t);if(n=arguments,s=this,l=t,i){if(void 0===a)return function(t){return h=t,a=setTimeout(m,e),c?p(t):r}(l);if(d)return clearTimeout(a),a=setTimeout(m,e),p(l)}return void 0===a&&(a=setTimeout(m,e)),r}return e=ti(e)||0,Ke(i)&&(c=!!i.leading,o=(d="maxWait"in i)?ei(ti(i.maxWait)||0,e):o,u="trailing"in i?!!i.trailing:u),O.cancel=function(){void 0!==a&&clearTimeout(a),h=0,n=l=s=a=void 0},O.flush=function(){return void 0===a?r:g(Je())},O},si=Vt(ni),oi="0.0.1";function ri(t){const e=t.get(0),i={};if(e.hasAttributes())for(const t of e.attributes)i[t.name]=t.value;return i}class ai{constructor(t){const e=window.getSelection();if(!e)throw new Error("Selection object is null.");this.selection=e,this.container=t,this.range=this.getRangeFromNativeSelection(),this.appliedItems=[]}getRangeFromNativeSelection(){if(this.selection.rangeCount>0){const t=this.selection.getRangeAt(0);return new A(t)}return new A}addRangeToNativeSelection(){this.selection.removeAllRanges(),this.selection.addRange(this.range.get())}syncByRange(){const t=this.getRangeFromNativeSelection();this.range.get()!==t.get()&&(this.range=t)}synByBookmark(){const t=this.range,e=this.container,i=e.find("lake-box[focus]");if(i.length>0)return re(t,{anchor:new Z,focus:i}),void this.addRangeToNativeSelection();re(t,{anchor:e.find('lake-bookmark[type="anchor"]'),focus:e.find('lake-bookmark[type="focus"]')}),this.addRangeToNativeSelection()}getAppliedItems(){const t=[];return function(t,e){let i=e.startNode;for(i.isText&&(i=i.parent());i.length>0&&i.isInside;)t.push({node:i,name:i.name,attributes:ri(i),styles:u(i.attr("style"))}),i=i.parent()}(t,this.range),function(t,e){const i=e.startNode;let n;if(i.isText&&i.text().length===e.startOffset){const t=i.next();t.length>0&&t.isElement&&(n=t)}if(i.isElement){const t=i.children();if(t.length>0){const i=t[e.startOffset];i&&i.isElement&&(n=i)}}if(n){let e=n;for(;e.length>0;)e.isElement&&t.push({node:e,name:e.name,attributes:ri(e),styles:u(e.attr("style"))}),e=e.first()}}(t,this.range),t}insertBookmark(){return se(this.range)}toBookmark(t){return re(this.range,t)}insertNode(t){return ne(this.range,t)}insertFragment(t){return he(this.range,t)}insertContents(t){return ce(this.range,t)}deleteContents(){return le(this.range)}setBlocks(t){return de(this.range,t)}splitBlock(){return ue(this.range)}splitMarks(t){return me(this.range,t)}addMark(t){return Oe(this.range,t)}removeMark(t){return we(this.range,t)}fixList(){return ae(this.range)}insertLink(t){return ye(this.range,t)}}class li{constructor(){this.commandMap=new Map,this.event=new Nt}add(t,e){this.commandMap.set(t,e)}getNames(){return Array.from(this.commandMap.keys())}execute(t,...e){const i=this.commandMap.get(t);if(void 0===i)throw new Error(`Command '${t}' does not exist.`);this.event.emit("beforeexecute",t),i.apply(this,e),this.event.emit("execute",t),Q(`Command '${t}' executed`)}}var hi,ci={exports:{}};hi=ci,function(t){function e(t,e){var i=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(i>>16)<<16|65535&i}function i(t,i,n,s,o,r){return e((a=e(e(i,t),e(s,r)))<<(l=o)|a>>>32-l,n);var a,l}function n(t,e,n,s,o,r,a){return i(e&n|~e&s,t,e,o,r,a)}function s(t,e,n,s,o,r,a){return i(e&s|n&~s,t,e,o,r,a)}function o(t,e,n,s,o,r,a){return i(e^n^s,t,e,o,r,a)}function r(t,e,n,s,o,r,a){return i(n^(e|~s),t,e,o,r,a)}function a(t,i){var a,l,h,c,d;t[i>>5]|=128<<i%32,t[14+(i+64>>>9<<4)]=i;var u=1732584193,p=-271733879,f=-1732584194,m=271733878;for(a=0;a<t.length;a+=16)l=u,h=p,c=f,d=m,u=n(u,p,f,m,t[a],7,-680876936),m=n(m,u,p,f,t[a+1],12,-389564586),f=n(f,m,u,p,t[a+2],17,606105819),p=n(p,f,m,u,t[a+3],22,-1044525330),u=n(u,p,f,m,t[a+4],7,-176418897),m=n(m,u,p,f,t[a+5],12,1200080426),f=n(f,m,u,p,t[a+6],17,-1473231341),p=n(p,f,m,u,t[a+7],22,-45705983),u=n(u,p,f,m,t[a+8],7,1770035416),m=n(m,u,p,f,t[a+9],12,-1958414417),f=n(f,m,u,p,t[a+10],17,-42063),p=n(p,f,m,u,t[a+11],22,-1990404162),u=n(u,p,f,m,t[a+12],7,1804603682),m=n(m,u,p,f,t[a+13],12,-40341101),f=n(f,m,u,p,t[a+14],17,-1502002290),u=s(u,p=n(p,f,m,u,t[a+15],22,1236535329),f,m,t[a+1],5,-165796510),m=s(m,u,p,f,t[a+6],9,-1069501632),f=s(f,m,u,p,t[a+11],14,643717713),p=s(p,f,m,u,t[a],20,-373897302),u=s(u,p,f,m,t[a+5],5,-701558691),m=s(m,u,p,f,t[a+10],9,38016083),f=s(f,m,u,p,t[a+15],14,-660478335),p=s(p,f,m,u,t[a+4],20,-405537848),u=s(u,p,f,m,t[a+9],5,568446438),m=s(m,u,p,f,t[a+14],9,-1019803690),f=s(f,m,u,p,t[a+3],14,-187363961),p=s(p,f,m,u,t[a+8],20,1163531501),u=s(u,p,f,m,t[a+13],5,-1444681467),m=s(m,u,p,f,t[a+2],9,-51403784),f=s(f,m,u,p,t[a+7],14,1735328473),u=o(u,p=s(p,f,m,u,t[a+12],20,-1926607734),f,m,t[a+5],4,-378558),m=o(m,u,p,f,t[a+8],11,-2022574463),f=o(f,m,u,p,t[a+11],16,1839030562),p=o(p,f,m,u,t[a+14],23,-35309556),u=o(u,p,f,m,t[a+1],4,-1530992060),m=o(m,u,p,f,t[a+4],11,1272893353),f=o(f,m,u,p,t[a+7],16,-155497632),p=o(p,f,m,u,t[a+10],23,-1094730640),u=o(u,p,f,m,t[a+13],4,681279174),m=o(m,u,p,f,t[a],11,-358537222),f=o(f,m,u,p,t[a+3],16,-722521979),p=o(p,f,m,u,t[a+6],23,76029189),u=o(u,p,f,m,t[a+9],4,-640364487),m=o(m,u,p,f,t[a+12],11,-421815835),f=o(f,m,u,p,t[a+15],16,530742520),u=r(u,p=o(p,f,m,u,t[a+2],23,-995338651),f,m,t[a],6,-198630844),m=r(m,u,p,f,t[a+7],10,1126891415),f=r(f,m,u,p,t[a+14],15,-1416354905),p=r(p,f,m,u,t[a+5],21,-57434055),u=r(u,p,f,m,t[a+12],6,1700485571),m=r(m,u,p,f,t[a+3],10,-1894986606),f=r(f,m,u,p,t[a+10],15,-1051523),p=r(p,f,m,u,t[a+1],21,-2054922799),u=r(u,p,f,m,t[a+8],6,1873313359),m=r(m,u,p,f,t[a+15],10,-30611744),f=r(f,m,u,p,t[a+6],15,-1560198380),p=r(p,f,m,u,t[a+13],21,1309151649),u=r(u,p,f,m,t[a+4],6,-145523070),m=r(m,u,p,f,t[a+11],10,-1120210379),f=r(f,m,u,p,t[a+2],15,718787259),p=r(p,f,m,u,t[a+9],21,-343485551),u=e(u,l),p=e(p,h),f=e(f,c),m=e(m,d);return[u,p,f,m]}function l(t){var e,i="",n=32*t.length;for(e=0;e<n;e+=8)i+=String.fromCharCode(t[e>>5]>>>e%32&255);return i}function h(t){var e,i=[];for(i[(t.length>>2)-1]=void 0,e=0;e<i.length;e+=1)i[e]=0;var n=8*t.length;for(e=0;e<n;e+=8)i[e>>5]|=(255&t.charCodeAt(e/8))<<e%32;return i}function c(t){var e,i,n="0123456789abcdef",s="";for(i=0;i<t.length;i+=1)e=t.charCodeAt(i),s+=n.charAt(e>>>4&15)+n.charAt(15&e);return s}function d(t){return unescape(encodeURIComponent(t))}function u(t){return function(t){return l(a(h(t),8*t.length))}(d(t))}function p(t,e){return function(t,e){var i,n,s=h(t),o=[],r=[];for(o[15]=r[15]=void 0,s.length>16&&(s=a(s,8*t.length)),i=0;i<16;i+=1)o[i]=909522486^s[i],r[i]=1549556828^s[i];return n=a(o.concat(h(e)),512+8*e.length),l(a(r.concat(n),640))}(d(t),d(e))}function f(t,e,i){return e?i?p(e,t):c(p(e,t)):i?u(t):c(u(t))}hi.exports?hi.exports=f:t.md5=f}(Yt);var di=Vt(ci.exports);const ui=new Map;class pi{constructor(t){this.selection=t,this.container=t.container,this.list=[],this.index=0,this.canSave=!0,this.limit=100,this.event=new Nt}removeBookmark(t){return t.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(t){return new ee(t).getHTML()}addIdToBoxes(t){t.find("lake-box").each((t=>{const e=new Z(t),i=di(`${e.attr("type")}-${e.attr("name")}-${e.attr("value")}`);e.attr("id",i)}))}removeIdfromBoxes(t){t.find("lake-box").each((t=>{new Z(t).removeAttr("id")}))}morphContainer(t){const e=this.container,i={beforeChildrenUpdated:t=>{if("lake-box"===new Z(t).name)return!1},afterAttributeUpdated:(t,i)=>{const n=new Z(i);if("value"===t&&"lake-box"===n.name){const t=ui.get(e.id);if(!t)return;t.delete(n.id)}}},n=t.clone(!0);this.addIdToBoxes(e),this.addIdToBoxes(n),ht(e,n,{callbacks:i}),this.removeIdfromBoxes(e),this.removeIdfromBoxes(n)}cloneContainer(){const t=this.selection.range,e=this.container.clone(!0);if(e.find("lake-box").each((t=>{new Kt(t).getContainer().empty()})),t.commonAncestor.isOutside)return e;if(t.isInsideBox)return e;const i=t.startNode.path(),n=t.endNode.path(),s=e.find(i),o=e.find(n),r=t.clone();return r.setStart(s,t.startOffset),r.setEnd(o,t.endOffset),se(r),e}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 t=this.getValue(this.container);for(;this.index>0;){const e=this.list[this.index-1];if(!e)break;const i=this.getValue(e);if(this.removeBookmark(i)!==this.removeBookmark(t)){this.morphContainer(e),this.event.emit("undo",i);break}if(1===this.index)break;this.index--}this.selection.synByBookmark(),Q(`History undone, the last index is ${this.index}`)}redo(){if(!this.list[this.index])return;this.selection.insertBookmark();const t=this.getValue(this.container);for(;this.index<this.list.length;){const e=this.list[this.index];if(!e)break;this.index++;const i=this.getValue(e);if(this.removeBookmark(i)!==this.removeBookmark(t)){this.morphContainer(e),this.event.emit("redo",i);break}}this.selection.synByBookmark(),Q(`History redone, the last index is ${this.index}`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(){if(!this.canSave)return;const t=this.cloneContainer(),e=this.getValue(t);this.list[this.index-1]&&this.removeBookmark(this.getValue(this.list[this.index-1]))===this.removeBookmark(e)||(this.list.splice(this.index,1/0,t),this.index++,this.list.length>this.limit&&(this.list.shift(),this.index=this.list.length),this.event.emit("save",e),Q(`History saved, the last index is ${this.index}`))}}var fi=["Shift","Meta","Alt","Control"],mi="object"==typeof navigator?navigator.platform:"",gi=/Mac|iPod|iPhone|iPad/.test(mi),Oi=gi?"Meta":"Control",vi="Win32"===mi?["Control","Alt"]:gi?["Alt"]:[];function wi(t,e){return"function"==typeof t.getModifierState&&(t.getModifierState(e)||vi.includes(e)&&t.getModifierState("AltGraph"))}function yi(t){return t.trim().split(" ").map((function(t){var e=t.split(/\b\+/),i=e.pop();return[e=e.map((function(t){return"$mod"===t?Oi:t})),i]}))}function bi(t,e){var i;void 0===e&&(e={});var n=null!=(i=e.timeout)?i:1e3,s=Object.keys(t).map((function(e){return[yi(e),t[e]]})),o=new Map,r=null;return function(t){t instanceof KeyboardEvent&&(s.forEach((function(e){var i=e[0],n=e[1],s=o.get(i)||i;!function(t,e){return!(e[1].toUpperCase()!==t.key.toUpperCase()&&e[1]!==t.code||e[0].find((function(e){return!wi(t,e)}))||fi.find((function(i){return!e[0].includes(i)&&e[1]!==i&&wi(t,i)})))}(t,s[0])?wi(t,t.key)||o.delete(i):s.length>1?o.set(i,s.slice(1)):(o.delete(i),n(t))})),r&&clearTimeout(r),r=setTimeout(o.clear.bind(o),n))}}const xi=new Map([["#","shift+#"]]);class ki{constructor(t){this.container=t,this.keydownEventList=[],this.keyupEventList=[]}normalizeType(t){var e;return t=(t=null!==(e=xi.get(t))&&void 0!==e?e:t).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/,(t=>t.charAt(0).toUpperCase()+l(t.substring(1)))).replace(/(^|\+|\s)([a-z])(\+|\s|$)/g,((t,e,i,n)=>`${e}Key${i.toUpperCase()}${n}`))}setKeydown(t,e){const i=bi({[t=this.normalizeType(t)]:t=>e(t)});this.keydownEventList.push({type:t,listener:e}),this.container.on("keydown",i)}setKeyup(t,e){const i=bi({[t=this.normalizeType(t)]:t=>e(t)});this.keyupEventList.push({type:t,listener:e}),this.container.on("keyup",i)}keydown(t){t=this.normalizeType(t);for(const e of this.keydownEventList)e.type===t&&e.listener(new Event(t))}keyup(t){t=this.normalizeType(t);for(const e of this.keyupEventList)e.type===t&&e.listener(new Event(t))}}const Si={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 Qi{constructor(t){if(!t.root)throw new Error("The root of the config must be specified.");this.root=C(t.root),this.config=Object.assign(Object.assign({},Si),t),this.containerWrapper=C('<div class="lake-container-wrapper" />'),this.container=C('<div class="lake-container" />'),this.overlayContainer=C('<div class="lake-overlay" />'),this.popupContainer=C('<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 Nt,this.selection=new ai(this.container),this.command=new li,this.history=new pi(this.selection),this.keystroke=new ki(this.container),this.box=Qi.box,this.unsavedInputData="",Ht.set(this.container.id,this),this.beforeunloadListener=()=>{this.commitUnsavedInputData()};const e=si((()=>{if(0===this.root.first().length)return;const t=this.selection.range,e=t.clone();e.adaptBox(),this.box.findAll(this).each((i=>{const n=new Kt(i),s=n.getContainer();if(0!==s.length){if(t.compareBeforeNode(s)<0&&t.compareAfterNode(s)>0&&(!t.isCollapsed||t.startNode.get(0)!==s.get(0)||0!==t.startOffset))return s.removeClass("lake-box-selected"),s.removeClass("lake-box-focused"),void s.addClass("lake-box-activated");if(e.intersectsNode(n.node))return s.removeClass("lake-box-activated"),void(t.isCollapsed?(s.removeClass("lake-box-selected"),s.addClass("lake-box-focused")):(s.removeClass("lake-box-focused"),s.addClass("lake-box-selected")));s.removeClass("lake-box-activated"),s.removeClass("lake-box-focused"),s.removeClass("lake-box-selected")}}))}),50,{leading:!1,trailing:!0,maxWait:50});this.selectionchangeListener=()=>{this.selection.syncByRange(),this.selection.appliedItems=this.selection.getAppliedItems(),e(),this.event.emit("selectionchange")},this.clickListener=t=>{const e=new Z(t.target);this.event.emit("click",e)},this.mouseoverListener=t=>{const e=new Z(t.target);this.event.emit("mouseover",e)},this.resizeListener=()=>{this.event.emit("resize")}}inputInBoxStrip(){const t=this.selection,e=t.range,i=e.startNode.closest(".lake-box-strip"),n=i.closest("lake-box");if("inline"===new Kt(n).type)e.isBoxLeft?(e.setStartBefore(n),e.collapseToStart()):(e.setStartAfter(n),e.collapseToStart());else{const t=C("<p />");e.isBoxLeft?n.before(t):n.after(t),e.shrinkAfter(t)}const s=i.text();i.html("<br />"),t.insertNode(document.createTextNode(s))}bindInputEvents(){this.container.on("compositionstart",(()=>{this.isComposing=!0})),this.container.on("compositionend",(()=>{this.isComposing=!1})),this.container.on("beforeinput",(()=>{const t=this.selection.range;(t.isBoxLeft||t.isBoxRight)&&this.commitUnsavedInputData()})),this.container.on("input",(t=>{const e=t;window.setTimeout((()=>{var t;const i=this.selection.range;if(!i.isInsideBox)if(this.isComposing)this.event.emit("input",e);else{if("insertText"===e.inputType||"insertCompositionText"===e.inputType)if(i.isBoxLeft||i.isBoxRight)this.inputInBoxStrip();else if(this.unsavedInputData+=null!==(t=e.data)&&void 0!==t?t:"",this.unsavedInputData.length<this.config.minChangeSize)return void this.event.emit("input",e);this.history.save(),this.unsavedInputData="",this.event.emit("input",e)}}),0)})),this.command.event.on("beforeexecute",(()=>this.commitUnsavedInputData()))}bindHistoryEvents(){this.history.event.on("undo",(t=>{this.box.renderAll(this),this.event.emit("change",t)})),this.history.event.on("redo",(t=>{this.box.renderAll(this),this.event.emit("change",t)})),this.history.event.on("save",(t=>{this.box.rectifyInstances(this),this.event.emit("change",t)}))}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(t){t=p(t);const e=new ee(t).getFragment();this.container.empty(),this.container.append(e),Qi.box.renderAll(this),this.selection.synByBookmark()}getValue(){const t=this.selection.insertBookmark();let e=new ee(this.container).getHTML();return e=f(e),this.selection.toBookmark(t),e}insertBox(t,e){const i=function(t,e,i){if(t.commonAncestor.isOutside)return null;const n=new Kt(e);i&&(n.value=i);const s=document.createDocumentFragment();if(s.appendChild(n.node.get(0)),"inline"===n.type)return he(t,s),n.render(),t.selectBoxRight(n.node),n;const o=ue(t);return o.left&&(t.setEndAfter(o.left),t.collapseToEnd()),o.right&&o.right.isEmpty&&o.right.remove(),he(t,s),n.render(),t.selectBoxRight(n.node),o.left&&o.left.isEmpty&&o.left.remove(),n}(this.selection.range,t,e);if(!i)return i;return this.box.getInstances(this).set(i.node.id,i),i}removeBox(){const t=function(t){if(t.commonAncestor.isOutside)return null;const e=t.commonAncestor.closest("lake-box");if(0===e.length)return null;const i=new Kt(e);if("block"===i.type){const n=C("<p><br /></p>");return e.before(n),t.shrinkAfter(n),i.unmount(),e.remove(),i}t.setStartBefore(e),t.collapseToStart();const n=e.parent();return i.unmount(),e.remove(),n.isEmpty&&(_(n,C("<br />")),t.shrinkAfter(n)),i}(this.selection.range);if(t){this.box.getInstances(this).delete(t.node.id)}return t}innerWidth(){const t=parseInt(this.container.computedCSS("padding-left"),10)||0,e=parseInt(this.container.computedCSS("padding-right"),10)||0;return this.container.width()-t-e}render(){const t=p(this.config.value),e=new ee(t).getFragment();this.root.empty(),this.root.append(this.containerWrapper),this.containerWrapper.append(this.container),this.containerWrapper.append(this.overlayContainer),C(document.body).append(this.popupContainer),this.container.append(e),this.readonly||(this.focus(),this.selection.synByBookmark(),this.history.save()),Qi.plugin.loadAll(this),Qi.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)}}Qi.version=oi,Qi.box=new class{add(t){jt.set(t.name,t)}remove(t){jt.delete(t)}getNames(){return Array.from(jt.keys())}getInstances(t){let e=ui.get(t.container.id);return e||(e=new Map,ui.set(t.container.id,e),e)}rectifyInstances(t){const e=this.getInstances(t);for(const t of e.values())t.node.get(0).isConnected||(t.unmount(),e.delete(t.node.id))}findAll(t){return t.container.find("lake-box")}renderAll(t){this.rectifyInstances(t);const e=this.getInstances(t);this.findAll(t).each((t=>{const i=new Z(t);if(e.get(i.id))return;const n=new Kt(i);n.render(),e.set(n.node.id,n)}))}},Qi.plugin=new class{constructor(){this.pluginList=[]}add(t){this.pluginList.push(t)}loadAll(t){this.pluginList.forEach((e=>{e(t)}))}};const Pi=[{icon:n.get("numberedList"),value:"numbered",text:"Numbered list"},{icon:n.get("bulletedList"),value:"bulleted",text:"Bulleted list"},{icon:n.get("checklist"),value:"checklist",text:"Checklist"}],$i=[{icon:n.get("alignLeft"),value:"left",text:"Align left"},{icon:n.get("alignCenter"),value:"center",text:"Align center"},{icon:n.get("alignRight"),value:"right",text:"Align right"},{icon:n.get("alignJustify"),value:"justify",text:"Align justify"}],Zi=[{icon:n.get("increaseIndent"),value:"increase",text:"Increase indent"},{icon:n.get("decreaseIndent"),value:"decrease",text:"Decrease indent"}],Ci=[{icon:n.get("italic"),value:"italic",text:"Italic"},{icon:n.get("underline"),value:"underline",text:"Underline"},{icon:n.get("strikethrough"),value:"strikethrough",text:"Strikethrough"},{icon:n.get("superscript"),value:"superscript",text:"Superscript"},{icon:n.get("subscript"),value:"subscript",text:"Subscript"},{icon:n.get("code"),value:"code",text:"Code"}],Ai=["#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"],Ti=[{icon:n.get("removeFormat"),value:"",text:"Remove color"}];for(const t of Ai)Ti.push({value:t.toLowerCase(),text:t.toUpperCase()});const _i=new Map([["strong","bold"],["em","italic"],["i","italic"],["u","underline"],["s","strikethrough"],["sup","superscript"],["sub","subscript"],["code","code"]]),Mi=[{name:"undo",type:"button",icon:n.get("undo"),tooltip:"Undo",onClick:(t,e)=>{t.command.execute(e)}},{name:"redo",type:"button",icon:n.get("redo"),tooltip:"Redo",onClick:(t,e)=>{t.command.execute(e)}},{name:"selectAll",type:"button",icon:n.get("selectAll"),tooltip:"Select all",onClick:(t,e)=>{t.command.execute(e)}},{name:"paragraph",type:"button",icon:n.get("paragraph"),tooltip:"Paragraph",isSelected:t=>!!t.find((t=>"p"===t.name)),onClick:t=>{t.command.execute("heading","p")}},{name:"blockQuote",type:"button",icon:n.get("blockQuote"),tooltip:"Block quotation",isSelected:t=>!!t.find((t=>"blockquote"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"numberedList",type:"button",icon:n.get("numberedList"),tooltip:"Numbered list",isSelected:t=>!!t.find((t=>"ol"===t.name)),onClick:t=>{t.command.execute("list","numbered")}},{name:"bulletedList",type:"button",icon:n.get("bulletedList"),tooltip:"Bulleted list",isSelected:t=>!!t.find((t=>"ul"===t.name&&!t.node.hasAttr("type"))),onClick:t=>{t.command.execute("list","bulleted")}},{name:"checklist",type:"button",icon:n.get("checklist"),tooltip:"Checklist",isSelected:t=>!!t.find((t=>"ul"===t.name&&"checklist"===t.node.attr("type"))),onClick:t=>{t.command.execute("list","checklist")}},{name:"alignLeft",type:"button",icon:n.get("alignLeft"),tooltip:"Align left",isSelected:t=>!!t.find((t=>t.node.isBlock&&"left"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","left")}},{name:"alignCenter",type:"button",icon:n.get("alignCenter"),tooltip:"Align center",isSelected:t=>!!t.find((t=>t.node.isBlock&&"center"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","center")}},{name:"alignRight",type:"button",icon:n.get("alignRight"),tooltip:"Align right",isSelected:t=>!!t.find((t=>t.node.isBlock&&"right"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","right")}},{name:"alignJustify",type:"button",icon:n.get("alignJustify"),tooltip:"Align justify",isSelected:t=>!!t.find((t=>t.node.isBlock&&"justify"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","justify")}},{name:"increaseIndent",type:"button",icon:n.get("increaseIndent"),tooltip:"Increase indent",onClick:t=>{t.command.execute("indent","increase")}},{name:"decreaseIndent",type:"button",icon:n.get("decreaseIndent"),tooltip:"Decrease indent",onClick:t=>{t.command.execute("indent","decrease")}},{name:"bold",type:"button",icon:n.get("bold"),tooltip:"Bold",isDisabled:t=>!!t.find((t=>t.node.isHeading)),isSelected:t=>!!t.find((t=>"strong"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"italic",type:"button",icon:n.get("italic"),tooltip:"Italic",isSelected:t=>!!t.find((t=>"i"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"underline",type:"button",icon:n.get("underline"),tooltip:"Underline",isSelected:t=>!!t.find((t=>"u"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"strikethrough",type:"button",icon:n.get("strikethrough"),tooltip:"Strikethrough",isSelected:t=>!!t.find((t=>"s"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"superscript",type:"button",icon:n.get("superscript"),tooltip:"Superscript",isSelected:t=>!!t.find((t=>"sup"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"subscript",type:"button",icon:n.get("subscript"),tooltip:"Subscript",isSelected:t=>!!t.find((t=>"sub"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"code",type:"button",icon:n.get("code"),tooltip:"Inline code",isSelected:t=>!!t.find((t=>"code"===t.name)),onClick:(t,e)=>{t.command.execute(e)}},{name:"removeFormat",type:"button",icon:n.get("removeFormat"),tooltip:"Remove format",onClick:(t,e)=>{t.command.execute(e)}},{name:"formatPainter",type:"button",icon:n.get("formatPainter"),tooltip:"Format painter",onClick:(t,e)=>{t.command.execute(e)}},{name:"link",type:"button",icon:n.get("link"),tooltip:"Link",onClick:(t,e)=>{t.command.execute(e)}},{name:"hr",type:"button",icon:n.get("hr"),tooltip:"Horizontal line",onClick:(t,e)=>{t.command.execute(e)}},{name:"codeBlock",type:"button",icon:n.get("codeBlock"),tooltip:"Code block",onClick:(t,e)=>{t.command.execute(e)}},{name:"heading",type:"dropdown",downIcon:n.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:t=>{const e=t.find((t=>t.node.isHeading||"p"===t.name));return e?[e.name]:[]},onSelect:(t,e)=>{t.command.execute("heading",e)}},{name:"list",type:"dropdown",downIcon:n.get("down"),icon:n.get("list"),defaultValue:"",tooltip:"List",width:"auto",menuType:"list",menuItems:Pi,selectedValues:t=>{let e="";for(const i of t){if("ol"===i.name){e="numbered";break}if("ul"===i.name&&!i.node.hasAttr("type")){e="bulleted";break}if("ul"===i.name&&"checklist"===i.node.attr("type")){e="checklist";break}}return[e]},onSelect:(t,e)=>{t.command.execute("list",e)}},{name:"align",type:"dropdown",downIcon:n.get("down"),icon:n.get("alignLeft"),defaultValue:"",tooltip:"Alignment",width:"auto",menuType:"list",menuItems:$i,selectedValues:t=>{let e="";for(const i of t)if(i.node.isBlock){e=i.node.computedCSS("text-align");break}return[e]},onSelect:(t,e)=>{t.command.execute("align",e)}},{name:"indent",type:"dropdown",downIcon:n.get("down"),icon:n.get("increaseIndent"),defaultValue:"",tooltip:"Indent",width:"auto",menuType:"list",menuItems:Zi,onSelect:(t,e)=>{t.command.execute("indent",e)}},{name:"fontFamily",type:"dropdown",downIcon:n.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:t=>{for(const e of t)if("span"===e.name){return[e.node.css("font-family").replace(/['"]/g,"")]}return[]},onSelect:(t,e)=>{t.command.execute("fontFamily",e)}},{name:"fontSize",type:"dropdown",downIcon:n.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:t=>!!t.find((t=>t.node.isHeading)),selectedValues:t=>{for(const e of t)if("span"===e.name){return[e.node.css("font-size").replace(/\.\d+/,"")]}return[]},onSelect:(t,e)=>{t.command.execute("fontSize",e)}},{name:"moreStyle",type:"dropdown",icon:n.get("more"),defaultValue:"",tooltip:"More style",width:"auto",menuType:"list",menuItems:Ci,selectedValues:t=>{var e;const i=[];for(const n of t)if(n.node.isMark){const t=null!==(e=_i.get(n.name))&&void 0!==e?e:n.name;i.push(t)}return i},onSelect:(t,e)=>{t.command.execute(e)}},{name:"fontColor",type:"dropdown",downIcon:n.get("down"),icon:n.get("fontColor"),accentIcon:n.get("fontColorAccent"),defaultValue:"#f5222d",tooltip:"Font color",width:"auto",menuType:"color",menuItems:Ti,selectedValues:t=>{for(const e of t)if("span"===e.name){return[d(e.node.computedCSS("color"))]}return[]},onSelect:(t,e)=>{t.command.execute("fontColor",e)}},{name:"highlight",type:"dropdown",downIcon:n.get("down"),icon:n.get("highlight"),accentIcon:n.get("highlightAccent"),defaultValue:"#fadb14",tooltip:"Highlight",width:"auto",menuType:"color",menuItems:Ti,selectedValues:t=>{for(const e of t)if("span"===e.name){return[d(e.node.computedCSS("background-color"))]}return[]},onSelect:(t,e)=>{t.command.execute("highlight",e)}},{name:"image",type:"upload",icon:n.get("image"),tooltip:"Image",accept:"image/*",multiple:!0}];function Bi(t){const{editor:e,file:i,onError:n,onSuccess:s}=t,{imageRequestMethod:o,imageRequestAction:r,imageRequestTypes:a}=e.config;if(a.indexOf(i.type)<0)throw new Error(`Cannot upload file because its type '${i.type}' is not found in ['${a.join("', '")}'].`);const l=e.insertBox("image",{url:URL.createObjectURL(i),status:"uploading",name:i.name,size:i.size,type:i.type,lastModified:i.lastModified});if(!l)throw new Error("The image box cannot be inserted outside the editor.");const h=dt({onProgress:t=>{const e=l.node.find(".lake-percent"),i=Math.round(t.percent);e.text(`${i<100?i:99} %`)},onError:(t,e)=>{Q(t.toString(),e),l.updateValue("status","error"),l.render(),n&&n()},onSuccess:t=>{if(!t.url)return l.updateValue("status","error"),l.render(),void(n&&n());l.updateValue({status:"done",url:t.url}),l.render(),e.history.save(),s&&s()},file:i,action:r,method:o});return l.setData("xhr",h),l}const Ei=["undo","redo","|","heading","fontSize","|","formatPainter","removeFormat","bold","moreStyle","|","fontColor","highlight","|","align","list","indent","link","blockQuote","hr"],Ri=new Map;Mi.forEach((t=>{Ri.set(t.name,t)}));function Wi(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{l(n.next(t))}catch(t){o(t)}}function a(t){try{l(n.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}l((n=n.apply(t,e||[])).next())}))}
6
6
  /*!
7
7
  * PhotoSwipe Lightbox 5.4.3 - https://photoswipe.com
8
8
  * (c) 2023 Dmytro Semenov
@@ -58,7 +58,7 @@ function Xi(t,e,i){const n=document.createElement(e);return t&&(n.className=t),i
58
58
  <button type="button" class="lake-button-unlink"><span>Remove link</span></button>
59
59
  </div>
60
60
  </div>
61
- `);const e=n.get("open");e&&this.root.find(".lake-button-open").append(e);const i=this.root.find(".lake-button-copy"),s=n.get("copy");s&&i.append(s);const o=n.get("checkCircle");o&&i.append(o);const r=n.get("warningCircle");r&&i.append(r);const l=n.get("check");l&&this.root.find(".lake-button-save").prepend(l);const h=n.get("unlink");h&&this.root.find(".lake-button-unlink").prepend(h),t.append(this.root),this.bindEvents()}writeClipboardText(t,e){return Wi(this,void 0,void 0,(function*(){try{yield navigator.clipboard.writeText(t)}catch(t){e()}}))}bindEvents(){let t=null;this.root.find(".lake-button-copy").on("click",(()=>{if(!this.linkNode)return;const e=this.getInputValue("url");this.writeClipboardText(e,(()=>{const t=this.root.find(".lake-button-copy svg");t.hide(),t.eq(2).show("inline")}));const i=this.root.find(".lake-button-copy svg");i.hide(),i.eq(1).show("inline"),t&&window.clearTimeout(t),t=window.setTimeout((()=>{i.hide(),i.eq(0).show("inline")}),2e3)})),this.root.find(".lake-button-open").on("click",(()=>{if(!this.linkNode)return;const t=this.getInputValue("url");window.open(t)})),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(t){return this.root.find(`input[name="${t}"]`).get(0).value}setInputValue(t,e){this.root.find(`input[name="${t}"]`).get(0).value=e}save(){if(!this.linkNode)return;const t=this.getInputValue("url");let e=this.getInputValue("title");""===e&&(e="Link"),this.linkNode.attr("href",t),this.linkNode.text(e)}updatePosition(){if(!this.linkNode)return;const t=this.linkNode.get(0).getBoundingClientRect(),e=t.x+window.scrollX,i=t.y+window.scrollY;e<0||i<0?this.hide():(t.x+this.root.width()>window.innerWidth?this.root.css("left",`${e-this.root.width()+t.width}px`):this.root.css("left",`${e}px`),t.y+t.height+this.root.height()>window.innerHeight?this.root.css("top",i-this.root.height()+"px"):this.root.css("top",`${i+t.height}px`))}show(t){this.linkNode=t;const e=t.attr("href"),i=t.text();this.setInputValue("url",e),this.setInputValue("title",i),this.root.css("visibility","hidden"),this.root.show(),this.updatePosition(),this.root.css("visibility","")}hide(){this.linkNode=null,this.root.hide()}}function Sy(t,e){const i=t.selection.range,n=i.getRightText();if(t.selection.splitBlock(),e=i.getBlocks()[0])return""!==n||!e.isHeading&&"blockquote"!==e.name?void(e.isList&&"checklist"===e.attr("type")&&e.find("li").attr("value","false")):(t.selection.setBlocks("<p />"),void t.history.save());t.history.save()}function Qy(t){const e=t.selection.range,i=e.startNode.closest("lake-box"),n=i.closestBlock();if(n.length>0&&!n.isContainer)return void(e.isBoxLeft?(e.setStartBefore(i),e.collapseToStart(),Sy(t,n)):e.isBoxRight?(e.setStartAfter(i),e.collapseToStart(),Sy(t,n)):t.removeBox());const s=C("<p><br /></p>");e.isBoxLeft?i.before(s):e.isBoxRight?(i.after(s),e.shrinkAfter(s)):t.removeBox()}function Py(t){const e=t.selection.range,i=e.startNode.closestBlock();if(i.length>0&&!i.isContainer){const i=e.getPrevNode(),n=e.getRightText();if("br"!==i.name&&""===n)return t.selection.insertContents("<br /><br />"),void t.history.save()}t.selection.insertContents("<br />")}function $y(t){const e=t.selection.range,i=e.startNode.closest("lake-box"),n=i.closestBlock();if(n.length>0&&!n.isContainer)return void(e.isBoxLeft?(e.setStartBefore(i),e.collapseToStart(),Py(t)):e.isBoxRight?(e.setStartAfter(i),e.collapseToStart(),Py(t)):t.removeBox());const s=C("<p><br /></p>");e.isBoxLeft?i.before(s):e.isBoxRight?(i.after(s),e.shrinkAfter(s)):t.removeBox()}function Zy(t,e){const i=t.selection.range;let n=e.prev();if(0===n.length)return void("p"!==e.name&&t.selection.setBlocks("<p />"));if(n.isBox)return e.isEmpty&&e.remove(),void i.selectBoxRight(n);if("br"===n.name)return void n.remove();if(!n.isBlock){const t=new A;t.selectNodeContents(n),de(t,"<p />"),n=t.startNode.closestBlock()}if(n.isEmpty)return void n.remove();const s=t.selection.insertBookmark();E(n,e),t.selection.toBookmark(s),t.selection.fixList()}function Cy(t,e){const i=t.selection.range;let n=e.next();if(0===n.length)return void t.history.save();if(n.isBox)return e.isEmpty&&e.remove(),i.selectBoxLeft(n),void t.history.save();if(!n.isBlock){const t=new A;t.selectNodeContents(n),de(t,"<p />"),n=n.closestBlock()}const s=t.selection.insertBookmark();E(e,n),t.selection.toBookmark(s),t.selection.fixList()}const Ay=new Map([["#","h1"],["##","h2"],["###","h3"],["####","h4"],["#####","h5"],["######","h6"]]),Ty=[{re:/\*\*(.+?)\*\*$/,getParameters:()=>["bold"]},{re:/__(.+?)__$/,getParameters:()=>["bold"]},{re:/_(.+?)_$/,getParameters:()=>["italic"]},{re:/\*(.+?)\*$/,getParameters:()=>["italic"]},{re:/==(.+?)==$/,getParameters:()=>["highlight","#fff566"]},{re:/~~(.+?)~~$/,getParameters:()=>["strikethrough"]},{re:/`(.+?)`$/,getParameters:()=>["code"]}],_y=[{re:/^#+$/,getParameters:t=>{var e;return["heading",null!==(e=Ay.get(t))&&void 0!==e?e:"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 My(t){const e=t.clone(!0);e.find("lake-bookmark").remove(),""===e.html()&&t.prepend("<br />")}return Qi.box.add({type:"block",name:"hr",render:t=>{const e=t.getEditor();if(e)return t.useEffect((()=>{t.getContainer().find(".lake-hr").on("click",(()=>{e.selection.range.selectBox(t.node)}))})),'<div class="lake-hr"><hr /></div>'},html:()=>"<hr />"}),Qi.box.add(us),Qi.box.add(hy),Qi.plugin.add((t=>{t.container.on("copy",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.startNode.closest("lake-box");if(0===n.length)return;if(i.isBoxLeft||i.isBoxRight)return;e.preventDefault();const s=e.clipboardData;if(!s)return;const o=new Kt(n).getHTML();s.setData("text/html",o)}))})),Qi.plugin.add((t=>{t.container.on("cut",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.startNode.closest("lake-box");if(0===n.length)return;if(i.isBoxLeft||i.isBoxRight)return;e.preventDefault();const s=e.clipboardData;if(!s)return;const o=new Kt(n).getHTML();s.setData("text/html",o),t.removeBox(),t.history.save()}))})),Qi.plugin.add((t=>{const{imageRequestTypes:e}=t.config;t.container.on("paste",(i=>{if(t.selection.range.isInsideBox)return;i.preventDefault();const n=i.clipboardData;if(!n)return;if(t.selection.deleteContents(),n.files.length>0){for(const i of n.files)e.indexOf(i.type)>=0&&Bi({editor:t,file:i});return}const s=n.types;if(1===s.length&&"text/plain"===s[0]){const e=n.getData("text/plain"),i=new ie(e).getFragment();return t.event.emit("beforepaste",i),void uy(t,i)}const o=p(n.getData("text/html")),r=function(){const t=te();return t.div=t.p,m(t,((t,e)=>{delete e.id,delete e.class})),t}(),a=new ee(o,r).getFragment();t.event.emit("beforepaste",a),function(t){let e=new Z(t.firstChild);for(;e.length>0;){const t=e.next();e.isBlock&&dy(e),e=t}let i=[];for(e=new Z(t.firstChild);e.length>0;){const t=e.next();e.isMark||e.isText||e.isBookmark||e.isInlineBox?i.push(e):(W(i),i=[]),e=t}W(i)}(a),uy(t,a),t.box.renderAll(t)}))})),Qi.plugin.add((t=>{t.command.add("undo",(()=>{t.history.undo()})),t.keystroke.setKeydown("mod+z",(e=>{t.selection.range.isInsideBox||(e.preventDefault(),t.command.execute("undo"))}))})),Qi.plugin.add((t=>{t.command.add("redo",(()=>{t.history.redo()})),t.keystroke.setKeydown("mod+y",(e=>{t.selection.range.isInsideBox||(e.preventDefault(),t.command.execute("redo"))}))})),Qi.plugin.add((t=>{t.command.add("selectAll",(()=>{const e=t.selection.range;e.selectNodeContents(t.container),e.shrink()}))})),Qi.plugin.add((t=>{t.command.add("heading",(e=>{t.selection.setBlocks(`<${e} />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("blockQuote",(()=>{t.selection.setBlocks("<blockquote />"),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("list",((e,i=!1)=>{const n=t.selection.range.getBlocks();let s=!1,o=!1,r=!1;for(const t of n)s||"ol"!==t.name||(s=!0),o||"ul"!==t.name||t.hasAttr("type")||(o=!0),r||"ul"!==t.name||"checklist"!==t.attr("type")||(r=!0);s?("numbered"===e&&py(t),"bulleted"===e&&my(t),"checklist"===e&&gy(t,i)):o?("numbered"===e&&fy(t),"bulleted"===e&&py(t),"checklist"===e&&gy(t,i)):r?("numbered"===e&&fy(t),"bulleted"===e&&my(t),"checklist"===e&&py(t)):("numbered"===e&&fy(t),"bulleted"===e&&my(t),"checklist"===e&&gy(t,i)),t.history.save()})),t.container.on("click",(e=>{const i=e;if(t.readonly)return;if(!i.target)return;const n=C(i.target);"li"===n.name&&""!==n.attr("value")&&i.offsetX<=18&&(n.attr("value",("true"!==n.attr("value")).toString()),t.history.save())}))})),Qi.plugin.add((t=>{t.command.add("align",(e=>{t.selection.setBlocks({"text-align":e}),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("indent",(e=>{const i=t.selection.range.getBlocks();for(const t of i)I(t,e);t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("bold",(()=>{t.selection.getAppliedItems().find((t=>t.name===Oy))?t.selection.removeMark(`<${Oy} />`):t.selection.addMark(`<${Oy} />`),t.history.save()})),t.keystroke.setKeydown("mod+b",(e=>{e.preventDefault(),t.command.execute("bold")}))})),Qi.plugin.add((t=>{t.command.add("italic",(()=>{t.selection.getAppliedItems().find((t=>"i"===t.name))?t.selection.removeMark("<i />"):t.selection.addMark("<i />"),t.history.save()})),t.keystroke.setKeydown("mod+i",(e=>{e.preventDefault(),t.command.execute("italic")}))})),Qi.plugin.add((t=>{t.command.add("underline",(()=>{t.selection.getAppliedItems().find((t=>"u"===t.name))?t.selection.removeMark("<u />"):t.selection.addMark("<u />"),t.history.save()})),t.keystroke.setKeydown("mod+u",(e=>{e.preventDefault(),t.command.execute("underline")}))})),Qi.plugin.add((t=>{t.command.add("strikethrough",(()=>{t.selection.getAppliedItems().find((t=>"s"===t.name))?t.selection.removeMark("<s />"):t.selection.addMark("<s />"),t.history.save()})),t.keystroke.setKeydown("mod+shift+x",(e=>{e.preventDefault(),t.command.execute("strikethrough")}))})),Qi.plugin.add((t=>{t.command.add("subscript",(()=>{t.selection.getAppliedItems().find((t=>t.name===vy))?t.selection.removeMark(`<${vy} />`):t.selection.addMark(`<${vy} />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("superscript",(()=>{t.selection.getAppliedItems().find((t=>t.name===wy))?t.selection.removeMark(`<${wy} />`):t.selection.addMark(`<${wy} />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("code",(()=>{t.selection.getAppliedItems().find((t=>t.name===yy))?t.selection.removeMark(`<${yy} />`):t.selection.addMark(`<${yy} />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("fontFamily",(e=>{t.selection.addMark(`<span style="font-family: ${e};" />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("fontSize",(e=>{t.selection.addMark(`<span style="font-size: ${e};" />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("fontColor",(e=>{t.selection.addMark(`<span style="color: ${e};" />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("highlight",(e=>{t.selection.addMark(`<span style="background-color: ${e};" />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("removeFormat",(()=>{t.selection.removeMark(),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("formatPainter",(()=>{t.container.addClass(xy);const e=t.selection.getAppliedItems();for(const t of e){const e=t.node.clone();e.isMark&&"a"!==e.name&&by.push(e)}})),t.container.on("click",(()=>{if(t.container.removeClass(xy),0!==by.length){for(const e of by)t.selection.addMark(e);by=[],t.history.save()}})),t.event.on("click",(e=>{if(e.isInside)return;const i=e.closest(".lake-toolbar-button");i.length>0&&"formatPainter"===i.attr("name")||(t.container.removeClass(xy),by=[])}))})),Qi.plugin.add((t=>{let e;const i=i=>{e||(e=new ky(t.popupContainer),e.event.on("save",(()=>{t.history.save()})),e.event.on("remove",(()=>{t.history.save()}))),e.show(i)};t.root.on("scroll",(()=>{e&&e.updatePosition()})),t.event.on("resize",(()=>{e&&e.updatePosition()})),t.event.on("click",(t=>{if(t.isOutside)return;if(t.closest("lake-box").length>0)return;const n=t.closest("a");0!==n.length?i(n):e&&e.hide()})),t.command.add("link",(()=>{const e=t.selection.insertLink('<a href="">New link</a>');e&&(t.history.save(),i(e))}))})),Qi.plugin.add((t=>{t.event.on("beforepaste",(t=>{new pt(t).find("hr").each((t=>{const e=C(t),i=new Kt("hr");e.replaceWith(i.node)}))})),t.command.add("hr",(()=>{t.insertBox("hr"),t.history.save()}))})),Qi.plugin.add((t=>{t.event.on("beforepaste",(t=>{new pt(t).find("img").each((t=>{const e=C(t),i=new Kt("image"),n=e.attr("data-lake-value");""===n?i.value={url:e.attr("src"),status:"done"}:i.node.attr("value",n),e.replaceWith(i.node)}))})),t.command.add("image",(e=>{t.insertBox("image",e),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("codeBlock",(()=>{const e=t.insertBox("codeBlock");if(!e)return;t.history.save();e.getData("codeEditor").focus()}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("enter",(e=>{const i=t.selection.range;if(i.isInsideBox)return;if(e.preventDefault(),i.isBox)return Qy(t),void t.history.save();if(i.adapt(),i.isInoperative)return;if(i.isBox)return Qy(t),void t.history.save();let n=i.getBlocks()[0];if(n||(t.selection.setBlocks("<p />"),n=i.getBlocks()[0]),n.isEmpty&&"p"!==n.name)return t.selection.setBlocks("<p />"),void t.history.save();Sy(t,n),t.history.save()}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("shift+enter",(e=>{const i=t.selection.range;if(!i.isInsideBox){if(e.preventDefault(),i.isBox)return $y(t),void t.history.save();if(i.adapt(),!i.isInoperative){if(i.isBox)return $y(t),void t.history.save();Py(t),t.history.save()}}}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("backspace",(e=>{const i=t.selection.range;if(i.isInsideBox)return;if(i.isBoxLeft){const n=i.startNode.closest("lake-box"),s=n.prev();if(0===s.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(e.preventDefault(),Zy(t,i),t.history.save()))}if(s.isBlock)return s.isEmpty?(e.preventDefault(),s.remove(),t.selection.fixList(),void t.history.save()):(e.preventDefault(),void i.shrinkAfter(s));i.adaptBox()}if(i.isBox)return e.preventDefault(),t.removeBox(),void t.history.save();if(!i.isCollapsed)return e.preventDefault(),t.selection.deleteContents(),""===t.container.html().trim()&&t.setValue("<p><br /><focus /></p>"),void t.history.save();i.adapt();const n=i.getPrevNode();if(n.isBox)return e.preventDefault(),i.selectBox(n),t.removeBox(),void t.history.save();if(""===i.getLeftText()){e.preventDefault();let n=i.getBlocks()[0];return n||(t.selection.setBlocks("<p />"),n=i.getBlocks()[0]),""!==n.css("margin-left")||""!==n.css("text-indent")||""!==n.attr("indent")?(I(n,"decrease"),void t.history.save()):n.isList||"blockquote"===n.name?(t.selection.setBlocks("<p />"),void t.history.save()):(Zy(t,n),void t.history.save())}"br"===n.name&&(e.preventDefault(),i.setStartBefore(n),i.collapseToStart(),n.remove(),t.history.save())}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("delete",(e=>{const i=t.selection.range;if(i.isInsideBox)return;if(i.isBoxRight){const n=i.startNode.closest("lake-box"),s=n.next();if(0===s.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(e.preventDefault(),Cy(t,i),t.history.save()))}if(s.isBlock)return s.isEmpty?(e.preventDefault(),s.remove(),t.selection.fixList(),void t.history.save()):(e.preventDefault(),void i.shrinkBefore(s));i.adaptBox()}if(i.isBox)return e.preventDefault(),t.removeBox(),void t.history.save();if(!i.isCollapsed)return e.preventDefault(),t.selection.deleteContents(),""===t.container.html().trim()&&t.setValue("<p><br /><focus /></p>"),void t.history.save();i.adapt();const n=i.getNextNode();if(n.isBox)return e.preventDefault(),i.selectBox(n),t.removeBox(),void t.history.save();if(""===i.getRightText()){e.preventDefault();let n=i.getBlocks()[0];return n||(t.selection.setBlocks("<p />"),n=i.getBlocks()[0]),Cy(t,n),void t.history.save()}"br"===n.name&&(e.preventDefault(),i.setStartBefore(n),i.collapseToStart(),n.remove(),t.history.save())}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("tab",(e=>{e.preventDefault();t.selection.range.getBlocks().forEach((t=>{"p"===t.name&&"2em"!==t.css("text-indent")?t.css("text-indent","2em"):I(t,"increase")})),t.history.save()}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("arrow-left",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(i.isBoxLeft){const t=n.prev();return t.isBlock||t.isBox?(e.preventDefault(),t.isInlineBox?void i.selectBox(t):void i.shrinkAfter(t)):(i.setStartBefore(n),void i.collapseToStart())}return i.isBoxRight?(e.preventDefault(),void i.selectBox(n)):(e.preventDefault(),void i.selectBoxLeft(n))}if(!i.isCollapsed)return;const s=i.getPrevNode();s.isBox&&(e.preventDefault(),i.selectBox(s))})),t.keystroke.setKeydown("arrow-right",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(i.isBoxLeft)return e.preventDefault(),void i.selectBox(n);if(i.isBoxRight){const t=n.next();return t.isBlock||t.isBox?(e.preventDefault(),t.isInlineBox?void i.selectBox(t):void i.shrinkBefore(t)):(i.setStartAfter(n),void i.collapseToStart())}return e.preventDefault(),void i.selectBoxRight(n)}if(!i.isCollapsed)return;const s=i.getNextNode();s.isBox&&(e.preventDefault(),i.selectBox(s))})),t.keystroke.setKeydown("arrow-up",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(n.isBlockBox){const t=n.prev();if(t.isBlock||t.isBox)return e.preventDefault(),void i.shrinkAfter(t)}i.setStartBefore(n),i.collapseToStart()}})),t.keystroke.setKeydown("arrow-down",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(n.isBlockBox){const t=n.next();if(t.isBlock||t.isBox)return e.preventDefault(),void i.shrinkBefore(t)}i.setStartAfter(n),i.collapseToStart()}}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("space",(e=>{const i=t.selection,n=function(t){const e=t.selection.range;let i=e.startNode,n=e.startOffset;if(0!==n){if(i.isElement){const t=i.children()[n-1];if(!t||!t.isText)return;i=t,n=i.text().length}if(!(n<1))return{node:i,offset:n}}}(t);if(!n)return;if(function(t,e){const i=t.selection,n=i.range,s=e.offset,o=e.node.text().slice(0,s);for(const e of Ty){const r=e.re.exec(o);if(null!==r){t.prepareOperation();const o=i.insertBookmark(),a=o.focus.prev(),l=a.text(),h=`${l.replace(e.re,"$1")}​`;a.get(0).nodeValue=h,n.setStart(a,s-r[0].length),n.setEnd(a,s-(l.length-h.length)-1);const c=e.getParameters();return t.command.execute(c.shift(),...c),i.toBookmark(o),t.commitOperation(),!0}}return!1}(t,n))return void e.preventDefault();const s=i.range.getBlocks()[0];s&&!s.isHeading&&"p"!==s.name||function(t,e){const i=t.selection,n=e.offset;let s=e.node.text().slice(0,n);s=s.replace(/[\u200B\u2060]/g,"");for(const e of _y)if(e.re.test(s)){t.prepareOperation();const n=i.insertBookmark();n.focus.prev().remove();const o=n.focus.closestBlock();My(o),i.range.shrinkAfter(o);const r=e.getParameters(s);return t.command.execute(r.shift(),...r),i.toBookmark(n),t.commitOperation(),!0}return!1}(t,n)&&e.preventDefault()}))})),t.Box=Kt,t.Editor=Qi,t.Fragment=pt,t.HTMLParser=ee,t.Nodes=Z,t.Range=A,t.TextParser=ie,t.Toolbar=class{constructor(t){this.items=t.items||Ei,this.editor=t.editor,this.root=C(t.root),this.event=new Nt}getValue(t){const e=t.attr("value");return""===e?[]:JSON.parse(Lt(e))}setValue(t,e){t.attr("value",It(JSON.stringify(e)))}appendDivider(){this.root.append('<div class="lake-toolbar-divider" />')}appendButton(t){const e=this.editor,i=C('<button type="button" class="lake-toolbar-button" />');i.attr("name",t.name),i.attr("title",t.tooltip),t.icon&&i.append(t.icon),this.root.append(i),i.on("mouseenter",(()=>{i.attr("disabled")||i.addClass("lake-toolbar-button-hovered")})),i.on("mouseleave",(()=>{i.attr("disabled")||i.removeClass("lake-toolbar-button-hovered")})),i.on("click",(i=>{i.preventDefault(),e.focus(),t.onClick(e,t.name)}))}getMenuMap(t){const e=new Map;if(!t.menuItems)return e;for(const i of t.menuItems){const t=i.text.replace(/<[^>]*>/g,"");e.set(i.value,t)}return e}updateColorAccent(t,e){const i=t.find(".lake-dropdown-icon svg").eq(1),n=i.find("line");n.length>0?n.attr("stroke",e):i.find("path").attr("fill",e)}addDropdownMenu(t,e){for(const i of e.menuItems){const o=C(s`
61
+ `);const e=n.get("open");e&&this.root.find(".lake-button-open").append(e);const i=this.root.find(".lake-button-copy"),s=n.get("copy");s&&i.append(s);const o=n.get("checkCircle");o&&i.append(o);const r=n.get("warningCircle");r&&i.append(r);const l=n.get("check");l&&this.root.find(".lake-button-save").prepend(l);const h=n.get("unlink");h&&this.root.find(".lake-button-unlink").prepend(h),t.append(this.root),this.bindEvents()}writeClipboardText(t,e){return Wi(this,void 0,void 0,(function*(){try{yield navigator.clipboard.writeText(t)}catch(t){e()}}))}bindEvents(){let t=null;this.root.find(".lake-button-copy").on("click",(()=>{if(!this.linkNode)return;const e=this.getInputValue("url");this.writeClipboardText(e,(()=>{const t=this.root.find(".lake-button-copy svg");t.hide(),t.eq(2).show("inline")}));const i=this.root.find(".lake-button-copy svg");i.hide(),i.eq(1).show("inline"),t&&window.clearTimeout(t),t=window.setTimeout((()=>{i.hide(),i.eq(0).show("inline")}),2e3)})),this.root.find(".lake-button-open").on("click",(()=>{if(!this.linkNode)return;const t=this.getInputValue("url");window.open(t)})),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(t){return this.root.find(`input[name="${t}"]`).get(0).value}setInputValue(t,e){this.root.find(`input[name="${t}"]`).get(0).value=e}save(){if(!this.linkNode)return;const t=this.getInputValue("url");let e=this.getInputValue("title");""===e&&(e="Link"),this.linkNode.attr("href",t),this.linkNode.text(e)}updatePosition(){if(!this.linkNode)return;const t=this.linkNode.get(0).getBoundingClientRect(),e=t.x+window.scrollX,i=t.y+window.scrollY;e<0||i<0?this.hide():(t.x+this.root.width()>window.innerWidth?this.root.css("left",`${e-this.root.width()+t.width}px`):this.root.css("left",`${e}px`),t.y+t.height+this.root.height()>window.innerHeight?this.root.css("top",i-this.root.height()+"px"):this.root.css("top",`${i+t.height}px`))}show(t){this.linkNode=t;const e=t.attr("href"),i=t.text();this.setInputValue("url",e),this.setInputValue("title",i),this.root.css("visibility","hidden"),this.root.show(),this.updatePosition(),this.root.css("visibility","")}hide(){this.linkNode=null,this.root.hide()}}function Sy(t,e){const i=t.selection.range,n=i.getRightText();if(t.selection.splitBlock(),e=i.getBlocks()[0])return""!==n||!e.isHeading&&"blockquote"!==e.name?void(e.isList&&"checklist"===e.attr("type")&&e.find("li").attr("value","false")):(t.selection.setBlocks("<p />"),void t.history.save());t.history.save()}function Qy(t){const e=t.selection.range,i=e.startNode.closest("lake-box"),n=i.closestBlock();if(n.length>0&&!n.isContainer)return void(e.isBoxLeft?(e.setStartBefore(i),e.collapseToStart(),Sy(t,n)):e.isBoxRight?(e.setStartAfter(i),e.collapseToStart(),Sy(t,n)):t.removeBox());const s=C("<p><br /></p>");e.isBoxLeft?i.before(s):e.isBoxRight?(i.after(s),e.shrinkAfter(s)):t.removeBox()}function Py(t){const e=t.selection.range,i=e.startNode.closestBlock();if(i.length>0&&!i.isContainer){const i=e.getPrevNode(),n=e.getRightText();if("br"!==i.name&&""===n)return t.selection.insertContents("<br /><br />"),void t.history.save()}t.selection.insertContents("<br />")}function $y(t){const e=t.selection.range,i=e.startNode.closest("lake-box"),n=i.closestBlock();if(n.length>0&&!n.isContainer)return void(e.isBoxLeft?(e.setStartBefore(i),e.collapseToStart(),Py(t)):e.isBoxRight?(e.setStartAfter(i),e.collapseToStart(),Py(t)):t.removeBox());const s=C("<p><br /></p>");e.isBoxLeft?i.before(s):e.isBoxRight?(i.after(s),e.shrinkAfter(s)):t.removeBox()}function Zy(t,e){const i=t.selection.range;let n=e.prev();if(0===n.length)return void("p"!==e.name&&t.selection.setBlocks("<p />"));if(n.isBox)return e.isEmpty&&e.remove(),void i.selectBoxRight(n);if("br"===n.name)return void n.remove();if(!n.isBlock){const t=new A;t.selectNodeContents(n),de(t,"<p />"),n=t.startNode.closestBlock()}if(n.isEmpty)return void n.remove();const s=t.selection.insertBookmark();E(n,e),t.selection.toBookmark(s),t.selection.fixList()}function Cy(t,e){const i=t.selection.range;let n=e.next();if(0===n.length)return void t.history.save();if(n.isBox)return e.isEmpty&&e.remove(),i.selectBoxLeft(n),void t.history.save();if(!n.isBlock){const t=new A;t.selectNodeContents(n),de(t,"<p />"),n=n.closestBlock()}const s=t.selection.insertBookmark();E(e,n),t.selection.toBookmark(s),t.selection.fixList()}const Ay=new Map([["#","h1"],["##","h2"],["###","h3"],["####","h4"],["#####","h5"],["######","h6"]]),Ty=[{re:/\*\*(.+?)\*\*$/,getParameters:()=>["bold"]},{re:/__(.+?)__$/,getParameters:()=>["bold"]},{re:/_(.+?)_$/,getParameters:()=>["italic"]},{re:/\*(.+?)\*$/,getParameters:()=>["italic"]},{re:/==(.+?)==$/,getParameters:()=>["highlight","#fff566"]},{re:/~~(.+?)~~$/,getParameters:()=>["strikethrough"]},{re:/`(.+?)`$/,getParameters:()=>["code"]}],_y=[{re:/^#+$/,getParameters:t=>{var e;return["heading",null!==(e=Ay.get(t))&&void 0!==e?e:"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 My(t){const e=t.clone(!0);e.find("lake-bookmark").remove(),""===e.html()&&t.prepend("<br />")}return Qi.box.add({type:"block",name:"hr",render:t=>{const e=t.getEditor();if(e)return t.useEffect((()=>{t.getContainer().find(".lake-hr").on("click",(()=>{e.selection.range.selectBox(t.node)}))})),'<div class="lake-hr"><hr /></div>'},html:()=>"<hr />"}),Qi.box.add(us),Qi.box.add(hy),Qi.plugin.add((t=>{t.container.on("copy",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.startNode.closest("lake-box");if(0===n.length)return;if(i.isBoxLeft||i.isBoxRight)return;e.preventDefault();const s=e.clipboardData;if(!s)return;const o=new Kt(n).getHTML();s.setData("text/html",o)}))})),Qi.plugin.add((t=>{t.container.on("cut",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.startNode.closest("lake-box");if(0===n.length)return;if(i.isBoxLeft||i.isBoxRight)return;e.preventDefault();const s=e.clipboardData;if(!s)return;const o=new Kt(n).getHTML();s.setData("text/html",o),t.removeBox(),t.history.save()}))})),Qi.plugin.add((t=>{const{imageRequestTypes:e}=t.config;t.container.on("paste",(i=>{if(t.selection.range.isInsideBox)return;i.preventDefault();const n=i.clipboardData;if(!n)return;if(t.selection.deleteContents(),n.files.length>0){for(const i of n.files)e.indexOf(i.type)>=0&&Bi({editor:t,file:i});return}const s=n.types;if(1===s.length&&"text/plain"===s[0]){const e=n.getData("text/plain"),i=new ie(e).getFragment();return t.event.emit("beforepaste",i),void uy(t,i)}const o=p(n.getData("text/html")),r=function(){const t=te();return t.div=t.p,m(t,((t,e)=>{delete e.id,delete e.class})),t}(),a=new ee(o,r).getFragment();t.event.emit("beforepaste",a),function(t){let e=new Z(t.firstChild);for(;e.length>0;){const t=e.next();e.isBlock&&dy(e),e=t}let i=[];for(e=new Z(t.firstChild);e.length>0;){const t=e.next();e.isMark||e.isText||e.isBookmark||e.isInlineBox?i.push(e):(W(i),i=[]),e=t}W(i)}(a),uy(t,a),t.box.renderAll(t)}))})),Qi.plugin.add((t=>{t.command.add("undo",(()=>{t.history.undo()})),t.keystroke.setKeydown("mod+z",(e=>{t.selection.range.isInsideBox||(e.preventDefault(),t.command.execute("undo"))}))})),Qi.plugin.add((t=>{t.command.add("redo",(()=>{t.history.redo()})),t.keystroke.setKeydown("mod+y",(e=>{t.selection.range.isInsideBox||(e.preventDefault(),t.command.execute("redo"))}))})),Qi.plugin.add((t=>{t.command.add("selectAll",(()=>{const e=t.selection.range;e.selectNodeContents(t.container),e.shrink()}))})),Qi.plugin.add((t=>{t.command.add("heading",(e=>{t.selection.setBlocks(`<${e} />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("blockQuote",(()=>{t.selection.setBlocks("<blockquote />"),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("list",((e,i=!1)=>{const n=t.selection.range.getBlocks();let s=!1,o=!1,r=!1;for(const t of n)s||"ol"!==t.name||(s=!0),o||"ul"!==t.name||t.hasAttr("type")||(o=!0),r||"ul"!==t.name||"checklist"!==t.attr("type")||(r=!0);s?("numbered"===e&&py(t),"bulleted"===e&&my(t),"checklist"===e&&gy(t,i)):o?("numbered"===e&&fy(t),"bulleted"===e&&py(t),"checklist"===e&&gy(t,i)):r?("numbered"===e&&fy(t),"bulleted"===e&&my(t),"checklist"===e&&py(t)):("numbered"===e&&fy(t),"bulleted"===e&&my(t),"checklist"===e&&gy(t,i)),t.history.save()})),t.container.on("click",(e=>{const i=e;if(t.readonly)return;if(!i.target)return;const n=C(i.target);"li"===n.name&&""!==n.attr("value")&&i.offsetX<=18&&(n.attr("value",("true"!==n.attr("value")).toString()),t.history.save())}))})),Qi.plugin.add((t=>{t.command.add("align",(e=>{t.selection.setBlocks({"text-align":e}),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("indent",(e=>{const i=t.selection.range.getBlocks();for(const t of i)I(t,e);t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("bold",(()=>{t.selection.getAppliedItems().find((t=>t.name===Oy))?t.selection.removeMark(`<${Oy} />`):t.selection.addMark(`<${Oy} />`),t.history.save()})),t.keystroke.setKeydown("mod+b",(e=>{e.preventDefault(),t.command.execute("bold")}))})),Qi.plugin.add((t=>{t.command.add("italic",(()=>{t.selection.getAppliedItems().find((t=>"i"===t.name))?t.selection.removeMark("<i />"):t.selection.addMark("<i />"),t.history.save()})),t.keystroke.setKeydown("mod+i",(e=>{e.preventDefault(),t.command.execute("italic")}))})),Qi.plugin.add((t=>{t.command.add("underline",(()=>{t.selection.getAppliedItems().find((t=>"u"===t.name))?t.selection.removeMark("<u />"):t.selection.addMark("<u />"),t.history.save()})),t.keystroke.setKeydown("mod+u",(e=>{e.preventDefault(),t.command.execute("underline")}))})),Qi.plugin.add((t=>{t.command.add("strikethrough",(()=>{t.selection.getAppliedItems().find((t=>"s"===t.name))?t.selection.removeMark("<s />"):t.selection.addMark("<s />"),t.history.save()})),t.keystroke.setKeydown("mod+shift+x",(e=>{e.preventDefault(),t.command.execute("strikethrough")}))})),Qi.plugin.add((t=>{t.command.add("subscript",(()=>{t.selection.getAppliedItems().find((t=>t.name===vy))?t.selection.removeMark(`<${vy} />`):t.selection.addMark(`<${vy} />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("superscript",(()=>{t.selection.getAppliedItems().find((t=>t.name===wy))?t.selection.removeMark(`<${wy} />`):t.selection.addMark(`<${wy} />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("code",(()=>{t.selection.getAppliedItems().find((t=>t.name===yy))?t.selection.removeMark(`<${yy} />`):t.selection.addMark(`<${yy} />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("fontFamily",(e=>{t.selection.addMark(`<span style="font-family: ${e};" />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("fontSize",(e=>{t.selection.addMark(`<span style="font-size: ${e};" />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("fontColor",(e=>{t.selection.addMark(`<span style="color: ${e};" />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("highlight",(e=>{t.selection.addMark(`<span style="background-color: ${e};" />`),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("removeFormat",(()=>{t.selection.removeMark(),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("formatPainter",(()=>{t.container.addClass(xy);const e=t.selection.getAppliedItems();for(const t of e){const e=t.node.clone();e.isMark&&"a"!==e.name&&by.push(e)}})),t.container.on("click",(()=>{if(t.container.removeClass(xy),0!==by.length){for(const e of by)t.selection.addMark(e);by=[],t.history.save()}})),t.event.on("click",(e=>{if(e.isInside)return;const i=e.closest(".lake-toolbar-button");i.length>0&&"formatPainter"===i.attr("name")||(t.container.removeClass(xy),by=[])}))})),Qi.plugin.add((t=>{let e;const i=i=>{e||(e=new ky(t.popupContainer),e.event.on("save",(()=>{t.history.save()})),e.event.on("remove",(()=>{t.history.save()}))),e.show(i)};t.root.on("scroll",(()=>{e&&e.updatePosition()})),t.event.on("resize",(()=>{e&&e.updatePosition()})),t.event.on("click",(t=>{if(t.isOutside)return;if(t.closest("lake-box").length>0)return;const n=t.closest("a");0!==n.length?i(n):e&&e.hide()})),t.command.add("link",(()=>{const e=t.selection.insertLink('<a href="">New link</a>');e&&(t.history.save(),i(e))}))})),Qi.plugin.add((t=>{t.event.on("beforepaste",(t=>{new pt(t).find("hr").each((t=>{const e=C(t),i=new Kt("hr");e.replaceWith(i.node)}))})),t.command.add("hr",(()=>{t.insertBox("hr"),t.history.save()}))})),Qi.plugin.add((t=>{t.event.on("beforepaste",(t=>{new pt(t).find("img").each((t=>{const e=C(t),i=new Kt("image"),n=e.attr("data-lake-value");""===n?i.value={url:e.attr("src"),status:"done"}:i.node.attr("value",n),e.replaceWith(i.node)}))})),t.command.add("image",(e=>{t.insertBox("image",e),t.history.save()}))})),Qi.plugin.add((t=>{t.command.add("codeBlock",(()=>{const e=t.insertBox("codeBlock");if(!e)return;t.history.save();e.getData("codeEditor").focus()}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("enter",(e=>{const i=t.selection.range;if(i.isInsideBox)return;if(e.preventDefault(),i.isBox)return Qy(t),void t.history.save();if(i.adapt(),i.isInoperative)return;if(i.isBox)return Qy(t),void t.history.save();let n=i.getBlocks()[0];if(n||(t.selection.setBlocks("<p />"),n=i.getBlocks()[0]),n.isEmpty&&"p"!==n.name)return t.selection.setBlocks("<p />"),void t.history.save();Sy(t,n),t.history.save()}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("shift+enter",(e=>{const i=t.selection.range;if(!i.isInsideBox){if(e.preventDefault(),i.isBox)return $y(t),void t.history.save();if(i.adapt(),!i.isInoperative){if(i.isBox)return $y(t),void t.history.save();Py(t),t.history.save()}}}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("backspace",(e=>{const i=t.selection.range;if(i.isInsideBox)return;if(i.isBoxLeft){const n=i.startNode.closest("lake-box"),s=n.prev();if(0===s.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(e.preventDefault(),Zy(t,i),t.history.save()))}if(s.isBlock)return s.isEmpty?(e.preventDefault(),s.remove(),t.selection.fixList(),void t.history.save()):(e.preventDefault(),void i.shrinkAfter(s));i.adaptBox()}if(i.isBox)return e.preventDefault(),t.removeBox(),void t.history.save();if(!i.isCollapsed)return e.preventDefault(),t.selection.deleteContents(),""===t.container.html().trim()&&t.setValue("<p><br /><focus /></p>"),void t.history.save();i.adapt();const n=i.getPrevNode();if(n.isBox)return e.preventDefault(),i.selectBox(n),t.removeBox(),void t.history.save();if(""===i.getLeftText()){e.preventDefault();let n=i.getBlocks()[0];return n||(t.selection.setBlocks("<p />"),n=i.getBlocks()[0]),""!==n.css("margin-left")||""!==n.css("text-indent")||""!==n.attr("indent")?(I(n,"decrease"),void t.history.save()):n.isList||"blockquote"===n.name?(t.selection.setBlocks("<p />"),void t.history.save()):(Zy(t,n),void t.history.save())}"br"===n.name&&(e.preventDefault(),i.setStartBefore(n),i.collapseToStart(),n.remove(),t.history.save())}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("delete",(e=>{const i=t.selection.range;if(i.isInsideBox)return;if(i.isBoxRight){const n=i.startNode.closest("lake-box"),s=n.next();if(0===s.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(e.preventDefault(),Cy(t,i),t.history.save()))}if(s.isBlock)return s.isEmpty?(e.preventDefault(),s.remove(),t.selection.fixList(),void t.history.save()):(e.preventDefault(),void i.shrinkBefore(s));i.adaptBox()}if(i.isBox)return e.preventDefault(),t.removeBox(),void t.history.save();if(!i.isCollapsed)return e.preventDefault(),t.selection.deleteContents(),""===t.container.html().trim()&&t.setValue("<p><br /><focus /></p>"),void t.history.save();i.adapt();const n=i.getNextNode();if(n.isBox)return e.preventDefault(),i.selectBox(n),t.removeBox(),void t.history.save();if(""===i.getRightText()){e.preventDefault();let n=i.getBlocks()[0];return n||(t.selection.setBlocks("<p />"),n=i.getBlocks()[0]),Cy(t,n),void t.history.save()}"br"===n.name&&(e.preventDefault(),i.setStartBefore(n),i.collapseToStart(),n.remove(),t.history.save())}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("tab",(e=>{e.preventDefault();t.selection.range.getBlocks().forEach((t=>{"p"===t.name&&"2em"!==t.css("text-indent")?t.css("text-indent","2em"):I(t,"increase")})),t.history.save()}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("arrow-left",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(i.isBoxLeft){const t=n.prev();return t.isBlock||t.isBox?(e.preventDefault(),t.isInlineBox?void i.selectBox(t):void i.shrinkAfter(t)):(i.setStartBefore(n),void i.collapseToStart())}return i.isBoxRight?(e.preventDefault(),void i.selectBox(n)):(e.preventDefault(),void i.selectBoxLeft(n))}if(!i.isCollapsed)return;const s=i.getPrevNode();s.isBox&&(e.preventDefault(),i.selectBox(s))})),t.keystroke.setKeydown("arrow-right",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(i.isBoxLeft)return e.preventDefault(),void i.selectBox(n);if(i.isBoxRight){const t=n.next();return t.isBlock||t.isBox?(e.preventDefault(),t.isInlineBox?void i.selectBox(t):void i.shrinkBefore(t)):(i.setStartAfter(n),void i.collapseToStart())}return e.preventDefault(),void i.selectBoxRight(n)}if(!i.isCollapsed)return;const s=i.getNextNode();s.isBox&&(e.preventDefault(),i.selectBox(s))})),t.keystroke.setKeydown("arrow-up",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(n.isBlockBox){const t=n.prev();if(t.isBlock||t.isBox)return e.preventDefault(),void i.shrinkAfter(t)}i.setStartBefore(n),i.collapseToStart()}})),t.keystroke.setKeydown("arrow-down",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(n.isBlockBox){const t=n.next();if(t.isBlock||t.isBox)return e.preventDefault(),void i.shrinkBefore(t)}i.setStartAfter(n),i.collapseToStart()}}))})),Qi.plugin.add((t=>{t.keystroke.setKeydown("space",(e=>{const i=t.selection,n=function(t){const e=t.selection.range;let i=e.startNode,n=e.startOffset;if(0!==n){if(i.isElement){const t=i.children()[n-1];if(!t||!t.isText)return;i=t,n=i.text().length}if(!(n<1))return{node:i,offset:n}}}(t);if(!n)return;if(function(t,e){const i=t.selection,n=i.range,s=e.offset,o=e.node.text().slice(0,s);for(const e of Ty){const r=e.re.exec(o);if(null!==r){t.prepareOperation();const o=i.insertBookmark(),a=o.focus.prev(),l=a.text(),h=`${l.replace(e.re,"$1")}​`;a.get(0).nodeValue=h,n.setStart(a,s-r[0].length),n.setEnd(a,s-(l.length-h.length)-1);const c=e.getParameters();return t.command.execute(c.shift(),...c),i.toBookmark(o),t.commitOperation(),!0}}return!1}(t,n))return void e.preventDefault();const s=i.range.getBlocks()[0];s&&!s.isHeading&&"p"!==s.name||function(t,e){const i=t.selection,n=e.offset;let s=e.node.text().slice(0,n);s=s.replace(/[\u200B\u2060]/g,"");for(const e of _y)if(e.re.test(s)){t.prepareOperation();const n=i.insertBookmark();n.focus.prev().remove();const o=n.focus.closestBlock();My(o),i.range.shrinkAfter(o);const r=e.getParameters(s);return t.command.execute(r.shift(),...r),i.toBookmark(n),t.commitOperation(),!0}return!1}(t,n)&&e.preventDefault()}))})),t.Box=Kt,t.Editor=Qi,t.Fragment=pt,t.HTMLParser=ee,t.Nodes=Z,t.Range=A,t.TextParser=ie,t.Toolbar=class{constructor(t){this.items=t.items||Ei,this.editor=t.editor,this.root=C(t.root),this.container=C('<div class="lake-toolbar" />'),this.event=new Nt,this.root.addClass("lake-custom-properties")}getValue(t){const e=t.attr("value");return""===e?[]:JSON.parse(Lt(e))}setValue(t,e){t.attr("value",It(JSON.stringify(e)))}appendDivider(){this.container.append('<div class="lake-toolbar-divider" />')}appendButton(t){const e=this.editor,i=C('<button type="button" class="lake-toolbar-button" />');i.attr("name",t.name),i.attr("title",t.tooltip),t.icon&&i.append(t.icon),this.container.append(i),i.on("mouseenter",(()=>{i.attr("disabled")||i.addClass("lake-toolbar-button-hovered")})),i.on("mouseleave",(()=>{i.attr("disabled")||i.removeClass("lake-toolbar-button-hovered")})),i.on("click",(i=>{i.preventDefault(),e.focus(),t.onClick(e,t.name)}))}getMenuMap(t){const e=new Map;if(!t.menuItems)return e;for(const i of t.menuItems){const t=i.text.replace(/<[^>]*>/g,"");e.set(i.value,t)}return e}updateColorAccent(t,e){const i=t.find(".lake-dropdown-icon svg").eq(1),n=i.find("line");n.length>0?n.attr("stroke",e):i.find("path").attr("fill",e)}addDropdownMenu(t,e){for(const i of e.menuItems){const o=C(s`
62
62
  <li value="${i.value}">
63
63
  <div class="lake-dropdown-menu-text">${i.text}</div>
64
64
  </li>
@@ -76,9 +76,9 @@ function Xi(t,e,i){const n=document.createElement(e);return t&&(n.className=t),i
76
76
  <div class="lake-dropdown-down-icon"></div>
77
77
  </button>
78
78
  </div>
79
- `);n.attr("name",t.name),n.addClass(`lake-dropdown-${t.menuType}`);const s=n.find(".lake-dropdown-title");t.downIcon||s.addClass("lake-dropdown-title-no-down"),s.css("width",t.width),s.attr("title",t.tooltip);const o=s.find(".lake-dropdown-text"),r=s.find(".lake-dropdown-icon");t.icon&&r.append(t.icon),t.accentIcon&&r.append(t.accentIcon);const l=s.find(".lake-dropdown-down-icon");t.downIcon&&l.append(t.downIcon);const h=C('<ul class="lake-dropdown-menu" />');h.addClass(`lake-dropdown-${t.menuType}-menu`),o.length>0&&o.text(null!==(e=i.get(t.defaultValue))&&void 0!==e?e:t.defaultValue),"color"===t.menuType&&this.updateColorAccent(s,t.defaultValue),this.addDropdownMenu(h,t),n.append(s),n.append(h),this.root.append(n),this.bindDropdownEvents(n,t)}appendUpload(t){const e=this.editor,i=C(a`
79
+ `);n.attr("name",t.name),n.addClass(`lake-dropdown-${t.menuType}`);const s=n.find(".lake-dropdown-title");t.downIcon||s.addClass("lake-dropdown-title-no-down"),s.css("width",t.width),s.attr("title",t.tooltip);const o=s.find(".lake-dropdown-text"),r=s.find(".lake-dropdown-icon");t.icon&&r.append(t.icon),t.accentIcon&&r.append(t.accentIcon);const l=s.find(".lake-dropdown-down-icon");t.downIcon&&l.append(t.downIcon);const h=C('<ul class="lake-dropdown-menu" />');h.addClass(`lake-dropdown-${t.menuType}-menu`),o.length>0&&o.text(null!==(e=i.get(t.defaultValue))&&void 0!==e?e:t.defaultValue),"color"===t.menuType&&this.updateColorAccent(s,t.defaultValue),this.addDropdownMenu(h,t),n.append(s),n.append(h),this.container.append(n),this.bindDropdownEvents(n,t)}appendUpload(t){const e=this.editor,i=C(a`
80
80
  <div class="lake-upload">
81
81
  <input type="file" />
82
82
  <button type="button" class="lake-toolbar-button" />
83
83
  </div>
84
- `),n=i.find('input[type="file"]'),s=n.get(0);t.accept&&n.attr("accept",t.accept),!0===t.multiple&&n.attr("multiple","true");const o=i.find("button");o.attr("name",t.name),o.attr("title",t.tooltip),t.icon&&o.append(t.icon),this.root.append(i),o.on("mouseenter",(()=>{o.addClass("lake-toolbar-button-hovered")})),o.on("mouseleave",(()=>{o.removeClass("lake-toolbar-button-hovered")})),o.on("click",(t=>{t.preventDefault(),s.click()})),n.on("click",(t=>t.stopPropagation())),n.on("change",(t=>{const i=t.target.files||[];for(const t of i)Bi({editor:e,file:t})}))}getUpdateStateHandler(t){const{editor:e,allMenuMap:i,buttonItemList:n,dropdownItemList:s}=t;return si((()=>{var t;let o=e.selection.appliedItems;o.length>0&&o[0].node.closestContainer().get(0)!==e.container.get(0)&&(o=[]);for(const t of n){const i="lake-toolbar-button-selected",n=this.root.find(`button[name="${t.name}"]`),s=!!(t.isDisabled&&o.length>0)&&t.isDisabled(o,e);if(s?(n.attr("disabled","true"),n.removeClass(i)):n.removeAttr("disabled"),!s){!!(t.isSelected&&o.length>0)&&t.isSelected(o,e)?n.addClass(i):n.removeClass(i)}}for(const n of s){const s=n.selectedValues&&o.length>0?n.selectedValues(o,e):[],r=this.root.find(`div.lake-dropdown[name="${n.name}"]`),a=!!(n.isDisabled&&o.length>0)&&n.isDisabled(o,e);if(a?r.attr("disabled","true"):r.removeAttr("disabled"),!a){this.setValue(r,s);const e=r.find(".lake-dropdown-text");if(e.length>0){const o=s[0]||n.defaultValue,r=i.get(n.name),a=null!==(t=r&&r.get(o))&&void 0!==t?t:o;e.text(a)}}}this.event.emit("updatestate")}),100,{leading:!1,trailing:!0,maxWait:100})}render(){const t=this.editor;this.root.addClass("lake-custom-properties");const e=new Map,i=[],n=[];this.items.forEach((t=>{if("|"===t)return void this.appendDivider();let s;if("string"==typeof t){if(s=Ri.get(t),!s)return}else s=t;return"button"===s.type?(i.push(s),void this.appendButton(s)):"dropdown"===s.type?(e.set(s.name,this.getMenuMap(s)),n.push(s),void this.appendDropdown(s)):void("upload"===s.type&&this.appendUpload(s))}));const s=this.getUpdateStateHandler({editor:t,allMenuMap:e,buttonItemList:i,dropdownItemList:n});t.event.on("selectionchange",s),t.event.on("change",s)}},t.Utils=ut,t.addMark=Oe,t.deleteContents=le,t.fixList=ae,t.icons=n,t.insertBookmark=se,t.insertContents=ce,t.insertFragment=he,t.insertLink=ye,t.insertNode=ne,t.removeMark=we,t.setBlocks=de,t.splitBlock=ue,t.splitMarks=me,t.toBookmark=re,t}({});
84
+ `),n=i.find('input[type="file"]'),s=n.get(0);t.accept&&n.attr("accept",t.accept),!0===t.multiple&&n.attr("multiple","true");const o=i.find("button");o.attr("name",t.name),o.attr("title",t.tooltip),t.icon&&o.append(t.icon),this.container.append(i),o.on("mouseenter",(()=>{o.addClass("lake-toolbar-button-hovered")})),o.on("mouseleave",(()=>{o.removeClass("lake-toolbar-button-hovered")})),o.on("click",(t=>{t.preventDefault(),s.click()})),n.on("click",(t=>t.stopPropagation())),n.on("change",(t=>{const i=t.target.files||[];for(const t of i)Bi({editor:e,file:t})}))}getUpdateStateHandler(t){const{editor:e,allMenuMap:i,buttonItemList:n,dropdownItemList:s}=t;return si((()=>{var t;let o=e.selection.appliedItems;o.length>0&&o[0].node.closestContainer().get(0)!==e.container.get(0)&&(o=[]);for(const t of n){const i="lake-toolbar-button-selected",n=this.container.find(`button[name="${t.name}"]`),s=!!(t.isDisabled&&o.length>0)&&t.isDisabled(o,e);if(s?(n.attr("disabled","true"),n.removeClass(i)):n.removeAttr("disabled"),!s){!!(t.isSelected&&o.length>0)&&t.isSelected(o,e)?n.addClass(i):n.removeClass(i)}}for(const n of s){const s=n.selectedValues&&o.length>0?n.selectedValues(o,e):[],r=this.container.find(`div.lake-dropdown[name="${n.name}"]`),a=!!(n.isDisabled&&o.length>0)&&n.isDisabled(o,e);if(a?r.attr("disabled","true"):r.removeAttr("disabled"),!a){this.setValue(r,s);const e=r.find(".lake-dropdown-text");if(e.length>0){const o=s[0]||n.defaultValue,r=i.get(n.name),a=null!==(t=r&&r.get(o))&&void 0!==t?t:o;e.text(a)}}}this.event.emit("updatestate")}),100,{leading:!1,trailing:!0,maxWait:100})}render(){const t=this.editor;this.root.empty(),this.root.append(this.container);const e=new Map,i=[],n=[];this.items.forEach((t=>{if("|"===t)return void this.appendDivider();let s;if("string"==typeof t){if(s=Ri.get(t),!s)return}else s=t;return"button"===s.type?(i.push(s),void this.appendButton(s)):"dropdown"===s.type?(e.set(s.name,this.getMenuMap(s)),n.push(s),void this.appendDropdown(s)):void("upload"===s.type&&this.appendUpload(s))}));const s=this.getUpdateStateHandler({editor:t,allMenuMap:e,buttonItemList:i,dropdownItemList:n});t.event.on("selectionchange",s),t.event.on("change",s)}},t.Utils=ut,t.addMark=Oe,t.deleteContents=le,t.fixList=ae,t.icons=n,t.insertBookmark=se,t.insertContents=ce,t.insertFragment=he,t.insertLink=ye,t.insertNode=ne,t.removeMark=we,t.setBlocks=de,t.splitBlock=ue,t.splitMarks=me,t.toBookmark=re,t}({});
package/dist/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;