lakelib 0.1.23 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lake.min.js +1 -1
- package/dist/lake.min.js.map +1 -1
- package/lib/lake.js +4 -1
- package/lib/lake.js.map +1 -1
- package/package.json +1 -1
package/dist/lake.min.js
CHANGED
|
@@ -15,7 +15,7 @@ var Lake=function(e){"use strict";class t extends HTMLElement{}void 0!==customEl
|
|
|
15
15
|
<span class="lake-box-strip"><br /></span>
|
|
16
16
|
<div class="lake-box-container" contenteditable="false"></div>
|
|
17
17
|
<span class="lake-box-strip"><br /></span>
|
|
18
|
-
`;class Ve{constructor(e){if(this.event=new we,"string"==typeof e){const t=ye.get(e);if(void 0===t)throw new Error(`The box "${e}" has not been defined yet.`);const i=r(t.type),n=r(t.name);this.node=I(a`<lake-box type="${i}" name="${n}"></lake-box>`),t.value&&(this.value=t.value)}else{this.node=I(e);const t=ye.get(this.name);if(void 0===t)throw new Error(`The box "${this.name}" has not been defined yet.`);t.value&&!this.node.hasAttr("value")&&(this.value=t.value)}}addFramework(){let e=this.getContainer();0===e.length?(this.node.html($e),e=this.getContainer()):(e.off("mouseenter"),e.off("mouseleave"),e.off("click")),e.on("mouseenter",(()=>{e.hasClass("lake-box-selected")||e.hasClass("lake-box-focused")||e.hasClass("lake-box-activated")||e.addClass("lake-box-hovered")})),e.on("mouseleave",(()=>{e.removeClass("lake-box-hovered")})),e.on("click",(()=>{A(`The box "${this.name}" (id = ${this.node.id}) value:`),A(this.value)})),"block"===this.type&&this.node.isContentEditable&&e.attr("draggable","true")}get type(){return this.node.attr("type")}get name(){return this.node.attr("name")}get value(){const e=this.node.attr("value");return""===e?{}:JSON.parse(h(e))}set value(e){this.node.attr("value",d(JSON.stringify(e)))}updateValue(e,t){const i=this.value;if("string"==typeof e)i[e]=t;else for(const t of Object.keys(e))i[t]=e[t];this.value=i}getEditor(){const e=this.node.closest("div[contenteditable]"),t=e.length>0?xe.get(e.id):void 0;if(!t)throw new Error(`The box "${this.name}" (id=${this.node.id}) is not rendered in the editor.`);return t}getContainer(){return this.node.find(".lake-box-container")}setToolbar(e){let t;try{t=this.getEditor()}catch(e){}let i=null;const n=()=>{i&&i.position()};this.event.on("focus",(()=>{i=new ze({root:t?t.popupContainer:I(document.body),box:this,items:e,locale:t?t.locale:void 0}),i.render(),t&&t.root.on("scroll",n)})),this.event.on("blur",(()=>{i&&(i.unmount(),i=null),t&&t.root.off("scroll",n)}))}render(){const e=ye.get(this.name);if(void 0===e)return;this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.addFramework();const t=e.render(this);if(void 0!==t){const e=this.getContainer();e.empty(),e.append(t)}A(`The box "${this.name}" (id: ${this.node.id}) rendered`)}unmount(){this.event.emit("blur"),this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.node.empty(),A(`The box "${this.name}" (id: ${this.node.id}) unmounted`)}getHTML(){const e=ye.get(this.name);return void 0===e?"":void 0===e.html?this.node.outerHTML():e.html(this)}}function Fe(e){const t=ge(0);if("string"==typeof e){const i=new Ve(e);return t.set(i.node.id,i),i}const i=(e=I(e)).closestContainer();if(0===i.length){let i=t.get(e.id);return i||(i=new Ve(e),t.set(e.id,i),i)}const n=ge(i.id);let s=t.get(e.id);return s?(n.set(e.id,s),t.delete(e.id),s):(s=n.get(e.id),s||(s=new Ve(e),n.set(e.id,s),s))}function Re(e){const t=e.responseText||e.response;if(!t)return t;try{return JSON.parse(t)}catch(e){return t}}function je(e){const t=new XMLHttpRequest;e.onProgress&&t.upload&&(t.upload.onprogress=t=>{t.total>0&&(t.percent=t.loaded/t.total*100),e.onProgress&&e.onProgress(t)});const i=new FormData,n=e.data||{};Object.keys(n).forEach((e=>{const t=n[e];Array.isArray(t)?t.forEach((t=>{i.append(`${e}[]`,t)})):i.append(e,t)}));const s=e.filename||"file";e.file instanceof Blob?i.append(s,e.file,e.file.name):i.append(s,e.file),t.onerror=t=>{e.onError&&e.onError(t)},t.onload=()=>{if(t.status<200||t.status>=300){if(!e.onError)return;return e.onError(function(e,t){const i=`Cannot ${e.method} ${e.action} ${t.status}'`,n=new Error(i);return n.status=t.status,n.method=e.method,n.url=e.action,n}(e,t),Re(t))}if(e.onSuccess)return e.onSuccess(Re(t),t)},t.open(e.method,e.action,!0),e.withCredentials&&"withCredentials"in t&&(t.withCredentials=!0);const o=e.headers||{};return null!==o["X-Requested-With"]&&t.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(o).forEach((e=>{null!==o[e]&&t.setRequestHeader(e,o[e])})),t.send(i),t}function qe(e){const{editor:t,name:i,file:n,onError:s,onSuccess:o}=e,{requestMethod:r,requestAction:a,requestTypes:l}=t.config[i];if(l.indexOf(n.type)<0)throw s&&s(`File "${n.name}" is not allowed for uploading.`),new Error(`Cannot upload file "${n.name}" because its type "${n.type}" is not found in ['${l.join("', '")}'].`);const c=t.selection.insertBox(i,{url:URL.createObjectURL(n),status:"uploading",name:n.name,size:n.size,type:n.type,lastModified:n.lastModified});let d=je({onProgress:e=>{const t=c.node.find(".lake-percent"),i=Math.round(e.percent);t.text(`${i<100?i:99} %`)},onError:(e,t)=>{d=null,A(e.toString(),t),c.updateValue("status","error"),c.render(),s&&s(e.toString())},onSuccess:e=>{if(d=null,!e.url)return c.updateValue("status","error"),c.render(),void(s&&s("Cannot find the url field."));c.updateValue({status:"done",url:e.url}),c.render(),t.history.save(),o&&o()},file:n,action:a,method:r});return c.event.on("beforeunmount",(()=>{d&&(d.abort(),A("Upload canceled"))})),c}var We=Object.freeze({__proto__:null,appendBreak:D,camelCase:l,changeTagName:V,debug:A,denormalizeValue:f,encode:r,fileSize:w,fixNumberedList:F,fromBase64:h,getBox:Fe,getCSS:y,getDeepElement:H,inString:c,mergeNodes:O,modifierText:v,morph:he,nodePosition:pe,normalizeValue:g,parseStyle:m,query:I,removeBreak:Z,removeZWS:$,request:je,safeTemplate:a,scrollToNode:ue,setBlockIndent:R,splitNodes:P,template:s,toBase64:d,toHex:u,toNodeList:x,uploadFile:qe,wrapNodeList:z});class Ue{constructor(e){this.fragment=null!=e?e:document.createDocumentFragment()}get(){return this.fragment}find(e){const t=[];let i=new E(this.fragment.firstChild);for(;i.length>0;)i.matches(e)?t.push(i.get(0)):i.isElement&&i.find(e).each((e=>{t.push(e)})),i=i.next();return new E(t)}append(e){I(e).each((e=>{this.fragment.appendChild(e)}))}}const Ke={id:/^[\w-]+$/,class:/^[\w- ]+$/,style:{"text-align":["left","center","right","justify","start","end"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function Ge(){return{h1:Object.assign({},Ke),h2:Object.assign({},Ke),h3:Object.assign({},Ke),h4:Object.assign({},Ke),h5:Object.assign({},Ke),h6:Object.assign({},Ke),p:Object.assign({},Ke),blockquote:Object.assign(Object.assign({},Ke),{type:["info","tip","success","warning","error","danger"]}),ul:Object.assign(Object.assign({},Ke),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},Ke),{start:/^\d+$/,indent:/^\d+$/}),li:{value:["true","false"]},table:{style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/}},tr:{style:{height:/^-?\d+(px|%)$/i}},th:"td",td:{colspan:/^\d+$/,rowspan:/^\d+$/,style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/,"text-align":["left","center","right","justify"]}},"lake-box":{type:["inline","block"],name:/^[\w-]+$/,value:/^[^"]+$/,focus:["start","center","end"]},br:{},hr:{},img:{src:/^[^"]+$/,width:/^-?\d+px$/i,height:/^-?\d+px$/i,"data-lake-value":/^[^"]+$/,alt:/^[^"]+$/,style:{width:/^-?\d+px$/i,height:/^-?\d+px$/i}},span:{class:/^[\w- ]+$/,style:{color:/^[^"]+$/,"background-color":/^[^"]+$/,"font-family":/^[^;]+$/,"font-size":/^[^"]+$/}},b:"strong",strong:{},em:"i",i:{},u:{},s:{},sub:{},sup:{},code:{},a:{class:/^[\w- ]+$/,name:/^[\w-]+$/,href:/^[^"]+$/,target:/^[\w-]+$/,rel:/^[^"]+$/,download:/^[^"]+$/},"lake-bookmark":{type:["anchor","focus"]}}}class Xe{constructor(e,t=Ge()){this.rules=t,this.source="string"==typeof e?this.parseHTML(e):e}parseHTML(e){const t=(new DOMParser).parseFromString(e,"text/html");return new E(t.querySelector("body"))}static matchRule(e,t){return"string"==typeof e?e===t:Array.isArray(e)?e.indexOf(t)>=0:e instanceof RegExp&&e.test(t)}static getOpenTagString(e,t){let i=e.name,n=t[i];if(!n)return"";"string"==typeof n&&(i=n,n=t[i]);const s=e.get(0);if(!s.hasAttributes())return i;const o=new Map;for(const e of s.attributes)if(n[e.name]&&("style"!==e.name&&Xe.matchRule(n[e.name],e.value)&&o.set(e.name,e.value),"style"===e.name)){const t=n.style,i=new Map,s=m(e.value);for(const e of Object.keys(s)){const n=s[e];t[e]&&Xe.matchRule(t[e],n)&&i.set(e,n)}o.set("style",i)}let r=i;for(const[e,t]of o)if("style"===e){let e="";for(const[i,n]of t)e+=`${i}: ${n.replace(/"/g,""")}; `;""!==e&&(r+=` style="${e.trim()}"`)}else r+=` ${e}="${t}"`;return r}static getClosedTagString(e,t){let i=e.name;const n=t[i];return n?("string"==typeof n&&(i=n),i):""}static getTrimmedText(e){const t=e.parent(),i=e.prev(),n=e.next();let s=e.text();return(i.isBlock||i.isBlockBox)&&(n.isBlock||n.isBlockBox)||0===i.length&&0===n.length&&t.isBlock?s=s.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):i.isBlock||i.isBlockBox||0===i.length&&t.isBlock?s=s.replace(/^[\u0020\t\r\n]+/,""):(n.isBlock||n.isBlockBox||0===n.length&&t.isBlock)&&(s=s.replace(/[\u0020\t\r\n]+$/,"")),s}getHTML(){const e=this.rules;let t="";for(const i of function*t(i){let n=i.first();for(;n.length>0;){const i=n.next();if(n.isText)yield r(Xe.getTrimmedText(n));else if(n.isVoid){const t=Xe.getOpenTagString(n,e);""!==t&&(yield`<${t} />`)}else if(n.isElement){const i=Xe.getOpenTagString(n,e),s=Xe.getClosedTagString(n,e);""!==i&&(yield`<${i}>`),n.isBox||(yield*t(n)),""!==s&&(yield`</${s}>`)}n=i}}(this.source))t+=i;return t.trim()}getFragment(){const e=this.getHTML(),t=this.parseHTML(e),i=document.createDocumentFragment();let n=t.first();for(;n.length>0;){const e=n.next();i.appendChild(n.get(0)),n=e}return i}}class Qe{constructor(e){this.content=e}getHTML(){let e=this.content;return e=e.replace(/ {2}/g," "),e=r(e.trim()),e=`<p>${e}</p>`,e=e.replace(/(\r\n){2,}/g,"</p><p><br /></p><p>"),e=e.replace(/\r\n/g,"</p><p>"),e=e.replace(/[\r\n]{2,}/g,"</p><p><br /></p><p>"),e=e.replace(/[\r\n]/g,"</p><p>"),e}getFragment(){return new Xe(this.getHTML()).getFragment()}}function Ye(e,t){if(e.commonAncestor.isOutside)return;const i=(t=I(t)).get(0),n=e.get();n.insertNode(i),n.setEndAfter(i),n.collapse(!1)}function Je(e){if(e.commonAncestor.isOutside)return{anchor:new E,focus:new E};const t=e.startNode.closest("lake-box");if(t.length>0)return e.isBoxStart?t.attr("focus","start"):e.isBoxEnd?t.attr("focus","end"):t.attr("focus","center"),{anchor:new E,focus:t};if(e.isCollapsed){const t=e.clone();t.collapseToEnd();const i=I('<lake-bookmark type="focus" />');return Ye(t,i),{anchor:new E,focus:i}}const i=e.clone();i.collapseToStart();const n=I('<lake-bookmark type="anchor" />');Ye(i,n);const s=e.clone();s.collapseToEnd();const o=I('<lake-bookmark type="focus" />');return Ye(s,o),{anchor:n,focus:o}}function et(e,t){const i=e.prev(),n=e.next();if(i.isText||n.isText){const t=e.parent();e.remove(),t.get(0).normalize()}else if(0===i.length&&0===n.length){if(e.parent().isMark&&t){const i=new E(document.createTextNode(""));e.before(i),t.setStartAfter(i),t.collapseToStart()}e.remove()}else e.remove()}function tt(e,t){const i=t.anchor,n=t.focus;if(i.length>0&&0===n.length)et(i);else{if(n.length>0&&0===i.length){if(n.isBox){const t=Fe(n);0===t.getContainer().length&&t.render();const i=n.attr("focus");return"start"===i?e.selectBoxStart(n):"center"===i?e.selectBox(n):e.selectBoxEnd(n),void n.removeAttr("focus")}return e.setStartBefore(n),e.collapseToStart(),void et(n,e)}if(i.length>0&&n.length>0){const t=new M;t.selectNode(i),t.collapseToEnd(),-1===t.compareAfterNode(n)?(e.setStartBefore(n),et(n),e.setEndBefore(i),et(i)):(e.setStartBefore(i),et(i),e.setEndBefore(n),et(n))}}}function it(e){if(e.commonAncestor.isOutside)return;F(e.getBlocks())}function nt(e){if(e.isCollapsed)return;if(e.adjustBox(),e.adjustTable(),e.isInoperative)return;const t=e.startNode.closestBlock(),i=e.endNode.closestBlock(),n=t.get(0)===i.get(0);if(e.get().deleteContents(),e.adjustBlock(),n){const t=e.getBlocks()[0];if(t&&t.isEmpty){const i=D(t);e.setStartBefore(i),e.collapseToStart()}return}const s=e.getBlocks()[0];if(!s)return;const o=s.prev();if(0===o.length)return;const r=Je(e);O(o,s),tt(e,r),it(e)}function st(e,t){if(t instanceof Ue&&(t=t.get()),e.commonAncestor.isOutside)return;e.isCollapsed?e.adjustBox():nt(e);Z(e.startNode.closestBlock());const i=Je(e);i.focus.before(t),tt(e,i),e.adjustBlock()}function ot(e,t){if(e.commonAncestor.isOutside)return;if(e.isCollapsed){if(e.commonAncestor.closest("lake-box").isBlockBox)return}if("string"!=typeof t){const i=e.getBlocks();for(const e of i)e.css(t);return}const i=I(t),n=i.name,s=i.get(0).attributes,o=e.getBlocks();if(o.length>0){const t=Je(e);for(const e of o)if(e.name===n&&0===i.first().length)for(const t of s)e.attr(t.name,t.value);else{const t=i.clone(!0);t.isList&&e.isList&&""!==e.attr("indent")&&t.attr("indent",e.attr("indent"));const n=H(t);let s=e.first();for(;s.length>0;){const e=s.next();n.append(s),n.name!==s.name&&"li"!==s.name||s.remove(!0),s=e}e.replaceWith(t)}return tt(e,t),void it(e)}const r=Je(e),a=function(e){const t=e.commonAncestor.closest('div[contenteditable="true"],td');let i=[];if(0===t.length)return i;let n=t.first(),s=!0;for(;n.length>0;){if(n.isMark||n.isText||n.isBookmark||n.isInlineBox)i.push(n);else{if(!s)break;i=[]}e.intersectsNode(n)&&(s=!1),n=n.next()}return i}(e),l=z(a,i);if(tt(e,r),it(e),l.isEmpty){const t=D(l);e.setStartBefore(t),e.collapseToStart()}}function rt(e){if(e.commonAncestor.isOutside)return{start:null,end:null};e.isCollapsed?e.adjustBox():nt(e);const t=e.startNode,i=t.closestOperableBlock();if(0===i.length)return{start:null,end:null};let n=i.parent();n.isOutside&&(n=t.closestContainer());const s=P(t,e.startOffset,n);let o=null,r=null;return s&&(o=s.start,r=s.end),!s&&t.isBlock&&(e.startOffset>0&&(o=t.children()[e.startOffset-1]),r=t.children()[e.startOffset],r&&!r.isBlock&&(r=null)),o&&o.isEmpty&&D(o),r&&(r.isEmpty&&D(r),e.shrinkBefore(r)),it(e),{start:o,end:r}}function at(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function lt(e,t,i){let n=null,s=null,o=e.closestBlock();0===o.length&&(o=e.closestContainer());const r=P(e,t,o);return r&&(i?(at(r.start),at(r.end),r.start.isEmpty||(n=r.start),r.end.isEmpty||(s=r.end)):(n=r.start,s=r.end)),{start:n,end:s}}function ct(e,t=!0){if(e.commonAncestor.isOutside)return{start:null,center:null,end:null};if(e.adjustBox(),e.isCollapsed){const i=lt(e.startNode,e.startOffset,t);return i.start?(e.setStartAfter(i.start),e.collapseToStart()):i.end&&(e.setStartBefore(i.end),e.collapseToStart()),{start:i.start,center:null,end:i.end}}const i=lt(e.startNode,e.startOffset,t);i.start?e.setStartAfter(i.start):i.end&&e.setStartBefore(i.end);const n=lt(e.endNode,e.endOffset,t);return n.start?e.setEndAfter(n.start):n.end&&e.setEndBefore(n.end),{start:i.start,center:n.start,end:n.end}}function dt(e,t){const i=e.text();let n=e;for(;n.length>0;){const e=n.parent();if(!e.isMark||i!==e.text()||!n.isText&&n.name===t&&""!==n.attr("style"))break;n=e}return n}function ht(e,t){if(e.commonAncestor.isOutside)return;let i=I(t);const n=i.name,s=m(i.attr("style"));if(e.isCollapsed){if(e.isBox){const t=e.startNode.closest("lake-box");if("block"===Fe(t).type){const i=I("<p><br /></p>");e.isBoxStart?t.before(i):t.after(i),e.shrinkAfter(i)}else e.adjustBox()}Z(e.startNode.closestBlock());const t=new E(document.createTextNode("")),o=ct(e);if(o.start){const e=function(e){if(!e.isMark)return null;let t=e.clone(),i=e.last();for(;i.length>0;){if(i.isMark){const e=i.clone();t.append(e),t=e}i=i.last()}return t}(o.start);if(e)if(e.name===n)e.css(s),i=e;else{H(e).append(t),i.append(e)}}return""===i.text()&&i.append(t),Ye(e,i),function(e){const t=e.prev();t.length>0&&t.isText&&t.isEmpty&&t.remove();const i=e.next();i.length>0&&i.isText&&i.isEmpty&&i.remove()}(i),void e.shrinkAfter(i)}ct(e);const o=e.getMarks(!0),r=Je(e);for(const e of o)if(!e.isEmpty&&e.isText){const t=dt(e,n);if(t.isMark&&t.name===n)t.css(s);else{const e=i.clone();t.before(e),e.append(t)}}tt(e,r)}function pt(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function ut(e,t){if(e.commonAncestor.isOutside)return;let i;if(t){i=I(t).name}if(e.isCollapsed){if(e.isBox)return;if(i&&0===e.commonAncestor.closest(i).length)return;const t=ct(e,!1);if(!t.start)return;t.end&&pt(t.end);const n=new E(document.createTextNode("")),s=function(e,t){if(!e.isMark||!t)return null;let i=e.clone(),n=e.last();for(;n.length>0;){if(n.isMark&&n.name!==t){const e=n.clone();i.append(e),i=e}n=n.last()}if(i.name===t){if(!(i.first().length>0))return null;i=i.first()}return i}(t.start,i);if(!s)return t.start.after(n),pt(t.start),n.prev().isText?(e.setStartAfter(n.prev()),e.collapseToStart(),void n.remove()):(e.setStartAfter(n),void e.collapseToStart());return H(s).append(n),t.start.after(s),pt(t.start),void e.shrinkAfter(s)}ct(e);const n=e.getMarks(),s=Je(e);for(const e of n)if(!i||e.name===i){const t=e.parent();e.remove(!e.isEmpty),t.length>0&&t.get(0).normalize()}$(e.commonAncestor),tt(e,s)}function mt(e,t){if(e.commonAncestor.isOutside)return null;const i=I(t);if(e.isCollapsed){let t=e.commonAncestor.closest("a");if(0===t.length){t=i.clone(!0);return Z(e.startNode.closestBlock()),Ye(e,t),t}return""!==i.attr("href")&&t.attr({href:i.attr("href")}),t}ct(e);const n=Je(e);for(const t of e.commonAncestor.getWalker())"a"===t.name&&e.intersectsNode(t)&&t.remove(!0);const s=i.clone(!1);n.anchor.after(s);let o=s.next();for(;o.length>0;){const e=o.next();if(!o.isMark&&!o.isText)break;s.append(o),o=e}return 0===s.first().length&&s.remove(),tt(e,n),s}function gt(e,t,i){if(e.commonAncestor.isOutside)return null;const n=Fe(t);i&&(n.value=i);const s=document.createDocumentFragment();if(s.appendChild(n.node.get(0)),"inline"===n.type)return st(e,s),n.render(),e.selectBoxEnd(n.node),Fe(n.node);const o=rt(e);return o.start&&(e.setEndAfter(o.start),e.collapseToEnd()),o.end&&o.end.isEmpty&&o.end.remove(),st(e,s),n.render(),e.selectBoxEnd(n.node),o.start&&o.start.isEmpty&&o.start.remove(),Fe(n.node)}function ft(e){const t=e.node.closestContainer();if(e.unmount(),e.node.remove(),t.length>0){ge(t.id).delete(e.node.id);ge(0).set(e.node.id,e)}return e}function vt(e){if(e.commonAncestor.isOutside)return null;const t=e.commonAncestor.closest("lake-box");if(0===t.length)return null;const i=Fe(t);if("block"===i.type){const n=I("<p><br /></p>");return t.before(n),e.shrinkAfter(n),ft(i)}e.setStartBefore(t),e.collapseToStart();const n=t.parent();if(ft(i),n.isEmpty){const t=D(n);e.setStartBefore(t),e.collapseToStart()}return i}var wt={exports:{}};function yt(e,t=100,i={}){if("function"!=typeof e)throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw new RangeError("`wait` must not be negative.");const{immediate:n}="boolean"==typeof i?{immediate:i}:i;let s,o,r,a,l;function c(){const t=s,i=o;return s=void 0,o=void 0,l=e.apply(t,i),l}function d(){const e=Date.now()-a;e<t&&e>=0?r=setTimeout(d,t-e):(r=void 0,n||(l=c()))}const h=function(...e){if(s&&this!==s)throw new Error("Debounced method called with different contexts.");s=this,o=e,a=Date.now();const i=n&&!r;return r||(r=setTimeout(d,t)),i&&(l=c()),l};return h.clear=()=>{r&&(clearTimeout(r),r=void 0)},h.flush=()=>{r&&h.trigger()},h.trigger=()=>{l=c(),h.clear()},h}wt.exports.debounce=yt,wt.exports=yt;var xt=fe(wt.exports),bt=fe((function e(t,i){if(t===i)return!0;if(t&&i&&"object"==typeof t&&"object"==typeof i){if(t.constructor!==i.constructor)return!1;var n,s,o;if(Array.isArray(t)){if((n=t.length)!=i.length)return!1;for(s=n;0!=s--;)if(!e(t[s],i[s]))return!1;return!0}if(t instanceof Map&&i instanceof Map){if(t.size!==i.size)return!1;for(s of t.entries())if(!i.has(s[0]))return!1;for(s of t.entries())if(!e(s[1],i.get(s[0])))return!1;return!0}if(t instanceof Set&&i instanceof Set){if(t.size!==i.size)return!1;for(s of t.entries())if(!i.has(s[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(i)){if((n=t.length)!=i.length)return!1;for(s=n;0!=s--;)if(t[s]!==i[s])return!1;return!0}if(t.constructor===RegExp)return t.source===i.source&&t.flags===i.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===i.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===i.toString();if((n=(o=Object.keys(t)).length)!==Object.keys(i).length)return!1;for(s=n;0!=s--;)if(!Object.prototype.hasOwnProperty.call(i,o[s]))return!1;for(s=n;0!=s--;){var r=o[s];if(!e(t[r],i[r]))return!1}return!0}return t!=t&&i!=i}));function kt(e){const t=e.get(0),i={};if(t.hasAttributes())for(const e of t.attributes)i[e.name]=e.value;return i}class Ct{constructor(e){const t=window.getSelection();if(!t)throw new Error("Selection object is null.");this.selection=t,this.container=e,this.range=this.getCurrentRange()}getCurrentRange(){if(this.selection.rangeCount>0){const e=this.selection.getRangeAt(0);return new M(e)}return new M}sync(){this.selection.removeAllRanges(),this.selection.addRange(this.range.get())}updateByRange(){const e=this.getCurrentRange();this.container.contains(e.commonAncestor)&&(this.range.startNode.get(0)===e.startNode.get(0)&&this.range.startOffset===e.startOffset&&this.range.endNode.get(0)===e.endNode.get(0)&&this.range.endOffset===e.endOffset||(this.range=e))}updateByBookmark(){const e=this.range,t=this.container,i=t.find("lake-box[focus]");if(i.length>0)return tt(e,{anchor:new E,focus:i}),void this.sync();tt(e,{anchor:t.find('lake-bookmark[type="anchor"]'),focus:t.find('lake-bookmark[type="focus"]')}),this.sync()}getAppliedItems(){const e=[];return function(e,t){let i=t.startNode;for(i.isText&&(i=i.parent());i.length>0&&i.isInside;)e.push({node:i,name:i.name,attributes:kt(i),styles:m(i.attr("style"))}),i=i.parent()}(e,this.range),function(e,t){const i=t.startNode;let n;if(i.isText&&i.text().length===t.startOffset){const e=i.next();e.length>0&&e.isElement&&(n=e)}if(i.isElement){const e=i.children();if(e.length>0){const i=e[t.startOffset];i&&i.isElement&&(n=i)}}if(n){let t=n;for(;t.length>0;)t.isElement&&e.push({node:t,name:t.name,attributes:kt(t),styles:m(t.attr("style"))}),t=t.first()}}(e,this.range),e}insertBookmark(){return Je(this.range)}toBookmark(e){return tt(this.range,e)}insertNode(e){return Ye(this.range,e)}insertFragment(e){return st(this.range,e)}deleteContents(){return nt(this.range)}setBlocks(e){return ot(this.range,e)}splitBlock(){return rt(this.range)}splitMarks(e){return ct(this.range,e)}addMark(e){return ht(this.range,e)}removeMark(e){return ut(this.range,e)}fixList(){return it(this.range)}insertLink(e){return mt(this.range,e)}selectBox(e){let t=e;t=e instanceof Ve?e.node:e,this.range.selectBox(t)}insertBox(e,t){const i=gt(this.range,e,t);if(!i)throw new Error(`The box "${e}" cannot be inserted outside the editor.`);return i}removeBox(e=null){return e&&this.selectBox(e),vt(this.range)}}class St{constructor(e){this.commandMap=new Map,this.selection=e}add(e,t){this.commandMap.set(e,t)}delete(e){this.commandMap.delete(e)}getNames(){return Array.from(this.commandMap.keys())}has(e){return void 0!==this.commandMap.get(e)}getItem(e){const t=this.commandMap.get(e);if(void 0===t)throw new Error(`Command "${e}" has not been defined yet.`);return t}isDisabled(e){const t=this.getItem(e);if(!t.isDisabled)return!1;const i=this.selection.getAppliedItems();return t.isDisabled(i)}isSelected(e){const t=this.getItem(e);if(!t.isSelected)return!1;const i=this.selection.getAppliedItems();return t.isSelected(i)}selectedValues(e){const t=this.getItem(e);if(!t.selectedValues)return[];const i=this.selection.getAppliedItems();return t.selectedValues(i)}execute(e,...t){const i=this.selection.container,n=this.selection.range;i.contains(n.commonAncestor)||n.shrinkAfter(i);this.getItem(e).execute.apply(this,t),A(`Command "${e}" executed`)}}class Bt{constructor(e){this.canSave=!0,this.list=[],this.index=0,this.limit=100,this.event=new we,this.selection=e,this.container=e.container}removeBookmark(e){return e.replace(/(<lake-box[^>]+)\s+focus="\w+"([^>]*>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"")}getValue(e){return new Xe(e).getHTML()}addIdToBoxes(e){e.find("lake-box").each((e=>{const t=new E(e),i=`${t.attr("name")}-${t.attr("value")}`;t.attr("id",i)}))}removeIdfromBoxes(e){e.find("lake-box").each((e=>{new E(e).removeAttr("id")}))}morphContainer(e){const t=this.container,i={beforeChildrenUpdated:e=>{if("lake-box"===new E(e).name)return!1},afterAttributeUpdated:(e,i)=>{const n=new E(i);if(["name","value"].indexOf(e)>=0&&"lake-box"===n.name){Fe(n).unmount();ge(t.id).delete(n.id)}}},n=e.clone(!0);this.addIdToBoxes(t),this.addIdToBoxes(n),he(t,n,{callbacks:i}),this.removeIdfromBoxes(t),this.removeIdfromBoxes(n)}get canUndo(){return this.index>1&&!!this.list[this.index-2]}get canRedo(){return!!this.list[this.index]}cloneContainer(){const e=this.selection.range,t=this.container.clone(!0);if(t.find("lake-box").each((e=>{Fe(e).getContainer().empty()})),!this.container.contains(e.commonAncestor))return t;if(e.isInsideBox){const i=e.commonAncestor.closest("lake-box").path(),n=t.find(i),s=e.clone();return s.selectBox(n),Je(s),t}const i=e.startNode.path(),n=e.endNode.path(),s=t.find(i),o=t.find(n),r=e.clone();return r.setStart(s,e.startOffset),r.setEnd(o,e.endOffset),Je(r),t}undo(){if(!this.list[this.index-2])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index>1;){const t=this.list[this.index-2];if(!t)break;this.index--;const i=this.getValue(t);if(this.removeBookmark(i)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("undo",i);break}}this.selection.updateByBookmark(),A(`History undone (index: ${this.index})`)}redo(){if(!this.list[this.index])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index<this.list.length;){const t=this.list[this.index];if(!t)break;this.index++;const i=this.getValue(t);if(this.removeBookmark(i)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("redo",i);break}}this.selection.updateByBookmark(),A(`History redone (index: ${this.index})`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(e={}){var t,i,n;const s=null!==(t=e.inputType)&&void 0!==t?t:"",o=null!==(i=e.update)&&void 0!==i&&i,r=null===(n=e.emitEvent)||void 0===n||n;if(!this.canSave)return;const a=this.cloneContainer(),l=this.getValue(a);this.list[this.index-1]&&this.removeBookmark(this.getValue(this.list[this.index-1]))===this.removeBookmark(l)||(o?this.list.splice(this.index-1,1/0,a):(this.list.splice(this.index,1/0,a),this.index++),this.list.length>this.limit&&(this.list.shift(),this.index=this.list.length),A(`History saved (index: ${this.index}, inputType: "${s}", update: ${o}, emitEvent: ${r})`),r&&this.event.emit("save",f(l),{inputType:s,update:o,emitEvent:r}))}}var _t={};Object.defineProperty(_t,"__esModule",{value:!0});for(var At="undefined"!=typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.platform),Lt={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},Tt={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:At?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},Et={backspace:8,tab:9,enter:13,shift:16,control:17,alt:18,pause:19,capslock:20,escape:27," ":32,pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,insert:45,delete:46,meta:91,numlock:144,scrolllock:145,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},It=1;It<20;It++)Et["f"+It]=111+It;function Mt(e,t,i){t&&!("byKey"in t)&&(i=t,t=null),Array.isArray(e)||(e=[e]);var n=e.map((function(e){return Pt(e,t)})),s=function(e){return n.some((function(t){return Dt(t,e)}))};return null==i?s:s(i)}function Pt(e,t){var i=t&&t.byKey,n={},s=(e=e.replace("++","+add")).split("+"),o=s.length;for(var r in Lt)n[Lt[r]]=!1;var a=!0,l=!1,c=void 0;try{for(var d,h=s[Symbol.iterator]();!(a=(d=h.next()).done);a=!0){var p=d.value,u=p.endsWith("?")&&p.length>1;u&&(p=p.slice(0,-1));var m=Nt(p),g=Lt[m];if(p.length>1&&!g&&!Tt[p]&&!Et[m])throw new TypeError('Unknown modifier: "'+p+'"');1!==o&&g||(i?n.key=m:n.which=Zt(p)),g&&(n[g]=!u||null)}}catch(e){l=!0,c=e}finally{try{!a&&h.return&&h.return()}finally{if(l)throw c}}return n}function Dt(e,t){for(var i in e){var n=e[i],s=void 0;if(null!=n&&((null!=(s="key"===i&&null!=t.key?t.key.toLowerCase():"which"===i?91===n&&93===t.which?91:t.which:t[i])||!1!==n)&&s!==n))return!1}return!0}function Zt(e){return e=Nt(e),Et[e]||e.toUpperCase().charCodeAt(0)}function Nt(e){return e=e.toLowerCase(),e=Tt[e]||e}_t.default=Mt,_t.isHotkey=Mt,_t.isCodeHotkey=function(e,t){return Mt(e,t)};var Ot=_t.isKeyHotkey=function(e,t){return Mt(e,{byKey:!0},t)};_t.parseHotkey=Pt,_t.compareHotkey=Dt,_t.toKeyCode=Zt,_t.toKeyName=Nt;class Ht{constructor(e){this.keydownEventList=[],this.keyupEventList=[],this.container=e,this.container.on("keydown",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keydownEventList)if(Ot(e.type,t)&&!1===e.listener(t))break})),this.container.on("keyup",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keyupEventList)if(Ot(e.type,t)&&!1===e.listener(t))break}))}setKeydown(e,t){this.keydownEventList.push({type:e,listener:t})}setKeyup(e,t){this.keyupEventList.push({type:e,listener:t})}keydown(e){for(const t of this.keydownEventList)if(t.type===e&&!1===t.listener(new KeyboardEvent(e)))break}keyup(e){for(const t of this.keyupEventList)if(t.type===e&&!1===t.listener(new KeyboardEvent(e)))break}}const zt={value:"<p><br /></p>",readonly:!1,spellcheck:!1,tabIndex:0,placeholder:"",indentWithTab:!0,lang:"en-US",minChangeSize:5,historySize:100,onMessage:(e,t)=>{"success"!==e?"warning"!==e?"error"===e&&console.error(t):console.warn(t):console.log(t)},slash:!1};class $t{constructor(e){if(this.unsavedInputData="",this.unsavedInputCount=0,this.state={appliedItems:[],disabledNameMap:new Map,selectedNameMap:new Map,selectedValuesMap:new Map},this.unmountPluginMap=new Map,this.isComposing=!1,this.event=new we,this.box=$t.box,this.copyListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("copy",e)},this.cutListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("cut",e)},this.pasteListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("paste",e)},this.selectionchangeListener=()=>{this.updateSelectionRange(),this.updateBoxSelectionStyle(),this.emitStateChangeEvent()},this.clickListener=e=>{const t=new E(e.target);t.get(0).isConnected&&this.event.emit("click",t)},this.resizeListener=()=>{this.event.emit("resize")},this.scrollListener=()=>{this.event.emit("scroll")},this.updateSelectionRange=xt((()=>{this.selection.updateByRange()}),1,{immediate:!0}),this.updateBoxSelectionStyle=xt((()=>{if(0===this.root.first().length)return;const e=this.selection.range,t=e.clone();t.adjustBox(),this.container.find("lake-box").each((i=>{const n=Fe(i),s=n.getContainer();if(0!==s.length){if(e.compareBeforeNode(s)<0&&e.compareAfterNode(s)>0&&(!e.isCollapsed||e.startNode.get(0)!==s.get(0)||0!==e.startOffset))return s.removeClass("lake-box-hovered"),s.removeClass("lake-box-selected"),s.removeClass("lake-box-focused"),s.addClass("lake-box-activated"),void n.event.emit("focus");if(t.intersectsNode(n.node))return s.removeClass("lake-box-activated"),void(e.isCollapsed?(s.removeClass("lake-box-hovered"),s.removeClass("lake-box-selected"),s.addClass("lake-box-focused"),n.event.emit("focus")):(s.removeClass("lake-box-focused"),s.addClass("lake-box-selected"),n.event.emit("blur")));s.removeClass("lake-box-activated"),s.removeClass("lake-box-focused"),s.removeClass("lake-box-selected"),n.event.emit("blur")}}))}),50,{immediate:!0}),this.emitStateChangeEvent=xt((()=>{const e=this.command.getNames();let t=this.selection.getAppliedItems();t.length>0&&!this.container.contains(t[0].node)&&(t=[]);const i=new Map,n=new Map,s=new Map;if(t.length>0)for(const o of e){const e=this.command.getItem(o);if(e.isDisabled&&e.isDisabled(t)&&i.set(o,!0),e.isSelected&&e.isSelected(t)&&n.set(o,!0),e.selectedValues){const i=e.selectedValues(t);i.length>0&&s.set(o,i)}}const o={appliedItems:t,disabledNameMap:i,selectedNameMap:n,selectedValuesMap:s};bt(o,this.state)||(this.toolbar&&this.toolbar.updateState(o),this.event.emit("statechange",o),this.state=o)}),50,{immediate:!1}),!e.root)throw new Error("The root of the config must be specified.");this.root=I(e.root),this.toolbar=e.toolbar,this.config=Object.assign({},zt);for(const t of Object.keys(e))this.config[t]=e[t];this.containerWrapper=I('<div class="lake-container-wrapper" />'),this.container=I('<div class="lake-container" />'),this.overlayContainer=I('<div class="lake-overlay" />'),this.popupContainer=I('<div class="lake-popup lake-custom-properties" />'),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",tabindex:this.config.tabIndex.toString()}),""!==this.config.placeholder&&this.container.attr("placeholder",this.config.placeholder),this.selection=new Ct(this.container),this.command=new St(this.selection),this.history=new Bt(this.selection),this.history.limit=this.config.historySize,this.keystroke=new Ht(this.container),xe.set(this.container.id,this)}togglePlaceholderClass(e){const t="lake-placeholder";"<p><br /></p>"===(e=f(e)).replace("<focus />","")?this.container.addClass(t):this.container.removeClass(t)}moveBoxStripText(){const e=this.selection,t=e.range,i=t.startNode.closest(".lake-box-strip"),n=i.closest("lake-box");if("inline"===Fe(n).type)t.isBoxStart?(t.setStartBefore(n),t.collapseToStart()):(t.setStartAfter(n),t.collapseToStart());else{const e=I("<p />");t.isBoxStart?n.before(e):n.after(e),t.setStart(e,0),t.collapseToStart()}const s=i.text();i.html("<br />"),e.insertNode(document.createTextNode(s))}resetUnsavedInputData(){this.unsavedInputData="",this.unsavedInputCount=0}handleInputEvent(e){var t;this.selection.updateByRange();const i=this.selection.range;if(i.isInsideBox)return;if(i.isBoxStart||i.isBoxEnd)return this.moveBoxStripText(),void this.history.save();if("insertText"===(e instanceof CompositionEvent?"insertText":e.inputType)){const i=null!==(t=e.data)&&void 0!==t?t:"";return i.length>1?void this.history.save({inputType:"insertText",update:!1}):(this.unsavedInputData+=i,this.unsavedInputCount++,void(this.unsavedInputData.length<this.config.minChangeSize?this.history.save({inputType:"insertText",update:this.unsavedInputCount>1}):(this.history.save({inputType:"insertText",update:!0}),this.resetUnsavedInputData())))}this.history.save()}bindInputEvents(){this.container.on("compositionstart",(()=>{this.isComposing=!0,this.container.removeClass("lake-placeholder")})),this.container.on("compositionend",(e=>{this.isComposing=!1,this.handleInputEvent(e)})),this.container.on("input",(e=>{const t=e;this.isComposing=t.isComposing,this.isComposing||this.handleInputEvent(e)}))}bindHistoryEvents(){const e=e=>{this.fixContent()&&(this.history.save({update:!0,emitEvent:!1}),e=this.getValue()),this.emitStateChangeEvent(),this.togglePlaceholderClass(e),this.scrollToCaret(),this.event.emit("change",e)};this.history.event.on("undo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("redo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("save",((t,i)=>{this.removeBoxGarbage(),e(t),"insertText"!==i.inputType&&(this.selection.sync(),this.resetUnsavedInputData())}))}get hasFocus(){const e=document.activeElement;return!!e&&I(e).closest(".lake-container").get(0)===this.container.get(0)}get locale(){return Oe(this.config.lang)}fixContent(){const e=this.selection.range;let t=!1,i=this.container.children();for(const e of i)(e.isBlock||e.isMark)&&""===e.html()&&(e.remove(),t=!0,A(`Content fixed: empty tag "${e.name}" was removed`));if(i=this.container.children(),0===i.length)this.container.html("<p><br /></p>"),e.shrinkBefore(this.container),t=!0,A("Content fixed: default paragraph was added");else if(1===i.length){const n=i[0];if(n.isVoid){const i=I("<p />");n.before(i),i.append(n),e.shrinkAfter(i),t=!0,A(`Content fixed: void element "${n.name}" was wrapped in paragraph`)}}return e.adjustBr(),t}setPluginConfig(e,t){"object"!=typeof this.config[e]&&(this.config[e]={});for(const i of Object.keys(t))void 0===this.config[e][i]&&(this.config[e][i]=t[i])}removeBoxGarbage(){const e=ge(this.container.id);for(const t of e.values())t.node.get(0).isConnected||(t.unmount(),e.delete(t.node.id))}renderBoxes(){this.removeBoxGarbage();const e=this.container,t=ge(e.id);e.find("lake-box").each((e=>{const i=I(e);if(t.get(i.id))return;Fe(i).render()}))}focus(){this.container.focus()}blur(){this.container.blur()}scrollToCaret(){const e=this.selection.range;if(e.isBox)return;const t=e.getRect();if(0===t.x||0===t.y)return;const i=this.container.get(0).getBoundingClientRect(),n=I('<div class="lake-artificial-caret" />'),s=t.x-i.x,o=t.y-i.y;n.css({position:"absolute",top:`${o}px`,left:`${s}px`,width:`${t.width}px`,height:`${t.height}px`,"z-index":"-1"}),this.overlayContainer.find(".lake-artificial-caret").remove(),this.overlayContainer.append(n),ue(n,{behavior:"instant",block:"center",inline:"nearest"}),n.remove()}setValue(e){e=g(e);const t=new Xe(e),i=t.getFragment();this.container.empty(),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.renderBoxes(),this.selection.updateByBookmark()}getValue(){const e=this.history.cloneContainer();let t=new Xe(e).getHTML();return t=f(t),t}render(){const e=g(this.config.value),t=new Xe(e),i=t.getFragment();this.root.empty(),this.root.append(this.containerWrapper),this.containerWrapper.append(this.container),this.containerWrapper.append(this.overlayContainer),I(document.body).append(this.popupContainer),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.unmountPluginMap=$t.plugin.loadAll(this),this.readonly||(this.selection.updateByBookmark(),this.history.save({emitEvent:!1})),this.renderBoxes(),this.toolbar&&this.toolbar.render(this),this.root.on("scroll",this.scrollListener),document.addEventListener("copy",this.copyListener),window.addEventListener("resize",this.resizeListener),this.readonly||(document.addEventListener("cut",this.cutListener),document.addEventListener("paste",this.pasteListener),document.addEventListener("selectionchange",this.selectionchangeListener),document.addEventListener("click",this.clickListener),this.bindInputEvents(),this.bindHistoryEvents())}unmount(){this.updateSelectionRange.flush(),this.updateBoxSelectionStyle.flush(),this.emitStateChangeEvent.flush();for(const e of this.unmountPluginMap.keys()){const t=this.unmountPluginMap.get(e);t&&(t(),A(`The plugin "${e}" unmounted`))}this.toolbar&&this.toolbar.unmount(),this.removeBoxGarbage(),this.container.find("lake-box").each((e=>{Fe(I(e)).unmount()})),this.event.removeAllListeners(),this.history.event.removeAllListeners(),this.root.off(),this.root.removeClass("lake-custom-properties"),this.root.empty(),this.popupContainer.remove(),document.removeEventListener("copy",this.copyListener),window.removeEventListener("resize",this.resizeListener),this.readonly||(document.removeEventListener("cut",this.cutListener),document.removeEventListener("paste",this.pasteListener),document.removeEventListener("selectionchange",this.selectionchangeListener),document.removeEventListener("click",this.clickListener))}}$t.version="0.1.23",$t.box=new class{add(e){ye.set(e.name,e)}remove(e){ye.delete(e)}getNames(){return Array.from(ye.keys())}},$t.plugin=new class{constructor(){this.pluginMap=new Map}add(e,t){if(this.pluginMap.get(e))throw new Error(`Plugin "${e}" is already defined.`);this.pluginMap.set(e,t)}loadAll(e){const t=new Map;for(const i of this.pluginMap.keys()){const n=this.pluginMap.get(i);if(n&&!1!==e.config[i]){const s=n(e);s&&t.set(i,s)}}return t}};const Vt=[{icon:n.get("numberedList"),value:"numbered",text:e=>e.toolbar.numberedList()},{icon:n.get("bulletedList"),value:"bulleted",text:e=>e.toolbar.bulletedList()},{icon:n.get("checklist"),value:"checklist",text:e=>e.toolbar.checklist()}],Ft=[{icon:n.get("alignLeft"),value:"left",text:e=>e.toolbar.alignLeft()},{icon:n.get("alignCenter"),value:"center",text:e=>e.toolbar.alignCenter()},{icon:n.get("alignRight"),value:"right",text:e=>e.toolbar.alignRight()},{icon:n.get("alignJustify"),value:"justify",text:e=>e.toolbar.alignJustify()}],Rt=[{icon:n.get("increaseIndent"),value:"increase",text:e=>e.toolbar.increaseIndent()},{icon:n.get("decreaseIndent"),value:"decrease",text:e=>e.toolbar.decreaseIndent()}],jt=[{icon:n.get("italic"),value:"italic",text:e=>e.toolbar.italic()},{icon:n.get("underline"),value:"underline",text:e=>e.toolbar.underline()},{icon:n.get("strikethrough"),value:"strikethrough",text:e=>e.toolbar.strikethrough()},{icon:n.get("superscript"),value:"superscript",text:e=>e.toolbar.superscript()},{icon:n.get("subscript"),value:"subscript",text:e=>e.toolbar.subscript()},{icon:n.get("code"),value:"code",text:e=>e.toolbar.code()}],qt=["#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"],Wt=[{icon:n.get("removeFormat"),value:"",text:e=>e.toolbar.removeColor()}];for(const e of qt)Wt.push({value:e.toLowerCase(),text:e.toUpperCase()});const Ut=new Map([["strong","bold"],["em","italic"],["i","italic"],["u","underline"],["s","strikethrough"],["sup","superscript"],["sub","subscript"],["code","code"]]),Kt=[{name:"undo",type:"button",icon:n.get("undo"),tooltip:e=>e.toolbar.undo(),onClick:(e,t)=>{e.command.execute(t)}},{name:"redo",type:"button",icon:n.get("redo"),tooltip:e=>e.toolbar.redo(),onClick:(e,t)=>{e.command.execute(t)}},{name:"selectAll",type:"button",icon:n.get("selectAll"),tooltip:e=>e.toolbar.selectAll(),onClick:(e,t)=>{e.command.execute(t)}},{name:"paragraph",type:"button",icon:n.get("paragraph"),tooltip:e=>e.toolbar.paragraph(),isSelected:e=>!!e.find((e=>"p"===e.name)),onClick:e=>{e.command.execute("heading","p")}},{name:"blockQuote",type:"button",icon:n.get("blockQuote"),tooltip:e=>e.toolbar.blockQuote(),onClick:(e,t)=>{e.command.execute(t)}},{name:"numberedList",type:"button",icon:n.get("numberedList"),tooltip:e=>e.toolbar.numberedList(),isSelected:e=>!!e.find((e=>"ol"===e.name)),onClick:e=>{e.command.execute("list","numbered")}},{name:"bulletedList",type:"button",icon:n.get("bulletedList"),tooltip:e=>e.toolbar.bulletedList(),isSelected:e=>!!e.find((e=>"ul"===e.name&&!e.node.hasAttr("type"))),onClick:e=>{e.command.execute("list","bulleted")}},{name:"checklist",type:"button",icon:n.get("checklist"),tooltip:e=>e.toolbar.checklist(),isSelected:e=>!!e.find((e=>"ul"===e.name&&"checklist"===e.node.attr("type"))),onClick:e=>{e.command.execute("list","checklist")}},{name:"alignLeft",type:"button",icon:n.get("alignLeft"),tooltip:e=>e.toolbar.alignLeft(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"left"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","left")}},{name:"alignCenter",type:"button",icon:n.get("alignCenter"),tooltip:e=>e.toolbar.alignCenter(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"center"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","center")}},{name:"alignRight",type:"button",icon:n.get("alignRight"),tooltip:e=>e.toolbar.alignRight(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"right"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","right")}},{name:"alignJustify",type:"button",icon:n.get("alignJustify"),tooltip:e=>e.toolbar.alignJustify(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"justify"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","justify")}},{name:"increaseIndent",type:"button",icon:n.get("increaseIndent"),tooltip:e=>e.toolbar.increaseIndent(),onClick:e=>{e.command.execute("indent","increase")}},{name:"decreaseIndent",type:"button",icon:n.get("decreaseIndent"),tooltip:e=>e.toolbar.decreaseIndent(),onClick:e=>{e.command.execute("indent","decrease")}},{name:"bold",type:"button",icon:n.get("bold"),tooltip:e=>e.toolbar.bold(),onClick:(e,t)=>{e.command.execute(t)}},{name:"italic",type:"button",icon:n.get("italic"),tooltip:e=>e.toolbar.italic(),onClick:(e,t)=>{e.command.execute(t)}},{name:"underline",type:"button",icon:n.get("underline"),tooltip:e=>e.toolbar.underline(),onClick:(e,t)=>{e.command.execute(t)}},{name:"strikethrough",type:"button",icon:n.get("strikethrough"),tooltip:e=>e.toolbar.strikethrough(),onClick:(e,t)=>{e.command.execute(t)}},{name:"superscript",type:"button",icon:n.get("superscript"),tooltip:e=>e.toolbar.superscript(),onClick:(e,t)=>{e.command.execute(t)}},{name:"subscript",type:"button",icon:n.get("subscript"),tooltip:e=>e.toolbar.subscript(),onClick:(e,t)=>{e.command.execute(t)}},{name:"code",type:"button",icon:n.get("code"),tooltip:e=>e.toolbar.code(),onClick:(e,t)=>{e.command.execute(t)}},{name:"removeFormat",type:"button",icon:n.get("removeFormat"),tooltip:e=>e.toolbar.removeFormat(),onClick:(e,t)=>{e.command.execute(t)}},{name:"formatPainter",type:"button",icon:n.get("formatPainter"),tooltip:e=>e.toolbar.formatPainter(),onClick:(e,t)=>{e.command.execute(t)}},{name:"link",type:"button",icon:n.get("link"),tooltip:e=>e.toolbar.link(),onClick:(e,t)=>{e.command.execute(t)}},{name:"hr",type:"button",icon:n.get("hr"),tooltip:e=>e.toolbar.hr(),onClick:(e,t)=>{e.command.execute(t)}},{name:"codeBlock",type:"button",icon:n.get("codeBlock"),tooltip:e=>e.toolbar.codeBlock(),onClick:(e,t)=>{e.command.execute(t)}},{name:"video",type:"button",icon:n.get("video"),tooltip:e=>e.toolbar.video(),onClick:(e,t)=>{e.command.execute(t)}},{name:"equation",type:"button",icon:n.get("equation"),tooltip:e=>e.toolbar.equation(),onClick:(e,t)=>{e.command.execute(t)}},{name:"heading",type:"dropdown",downIcon:n.get("down"),defaultValue:"p",tooltip:e=>e.toolbar.heading(),width:"100px",menuType:"list",menuItems:[{value:"h1",text:e=>`<span style="font-weight: bold; font-size: 26px;">${e.toolbar.heading1()}</span>`},{value:"h2",text:e=>`<span style="font-weight: bold; font-size: 24px;">${e.toolbar.heading2()}</span>`},{value:"h3",text:e=>`<span style="font-weight: bold; font-size: 22px;">${e.toolbar.heading3()}</span>`},{value:"h4",text:e=>`<span style="font-weight: bold; font-size: 20px;">${e.toolbar.heading4()}</span>`},{value:"h5",text:e=>`<span style="font-weight: bold; font-size: 18px;">${e.toolbar.heading5()}</span>`},{value:"h6",text:e=>`<span style="font-weight: bold; font-size: 16px;">${e.toolbar.heading6()}</span>`},{value:"p",text:e=>e.toolbar.paragraph()}],onSelect:(e,t)=>{e.command.execute("heading",t)}},{name:"list",type:"dropdown",downIcon:n.get("down"),icon:n.get("list"),tooltip:e=>e.toolbar.list(),menuType:"list",menuItems:Vt,onSelect:(e,t)=>{e.command.execute("list",t)}},{name:"align",type:"dropdown",downIcon:n.get("down"),icon:n.get("alignLeft"),tooltip:e=>e.toolbar.align(),menuType:"list",menuItems:Ft,onSelect:(e,t)=>{e.command.execute("align",t)}},{name:"indent",type:"dropdown",downIcon:n.get("down"),icon:n.get("increaseIndent"),tooltip:e=>e.toolbar.indent(),menuType:"list",menuItems:Rt,onSelect:(e,t)=>{e.command.execute("indent",t)}},{name:"fontFamily",type:"dropdown",downIcon:n.get("down"),defaultValue:"Segoe UI",tooltip:e=>e.toolbar.fontFamily(),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>'}],onSelect:(e,t)=>{e.command.execute("fontFamily",t)}},{name:"fontSize",type:"dropdown",downIcon:n.get("down"),defaultValue:"16px",tooltip:e=>e.toolbar.fontSize(),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"}],onSelect:(e,t)=>{e.command.execute("fontSize",t)}},{name:"moreStyle",type:"dropdown",icon:n.get("more"),tooltip:e=>e.toolbar.moreStyle(),menuType:"list",menuItems:jt,selectedValues:e=>{var t;const i=[];for(const n of e)if(n.node.isMark){const e=null!==(t=Ut.get(n.name))&&void 0!==t?t:n.name;i.push(e)}return i},onSelect:(e,t)=>{e.command.execute(t)}},{name:"fontColor",type:"dropdown",downIcon:n.get("down"),icon:n.get("fontColor"),accentIcon:n.get("fontColorAccent"),defaultValue:"#f5222d",tooltip:e=>e.toolbar.fontColor(),menuType:"color",menuItems:Wt,menuWidth:"296px",onSelect:(e,t)=>{e.command.execute("fontColor",t)}},{name:"highlight",type:"dropdown",downIcon:n.get("down"),icon:n.get("highlight"),accentIcon:n.get("highlightAccent"),defaultValue:"#fadb14",tooltip:e=>e.toolbar.highlight(),menuType:"color",menuItems:Wt,menuWidth:"296px",onSelect:(e,t)=>{e.command.execute("highlight",t)}},{name:"image",type:"upload",icon:n.get("image"),tooltip:e=>e.toolbar.image(),accept:"image/*",multiple:!0},{name:"file",type:"upload",icon:n.get("attachment"),tooltip:e=>e.toolbar.file(),accept:"*",multiple:!0}],Gt=["undo","redo","|","heading","|","formatPainter","removeFormat","bold","moreStyle","|","fontColor","highlight","|","align","list","indent","link","blockQuote","hr"],Xt=new Map;for(const e of Kt)Xt.set(e.name,e);var Qt={type:"block",name:"hr",render:e=>{const t=e.getEditor(),i=e.getContainer(),n=I('<div class="lake-hr"><hr /></div>');i.empty(),i.append(n),n.on("click",(()=>{t.selection.selectBox(e)}))},html:()=>"<hr />"};const Yt="#57606a",Jt="#444d56",ei="#953800",ti="#0550ae",ii="#444d56",ni="#24292e",si="#005cc5",oi="#0550ae",ri="#444d56",ai="#444d56",li="#0a3069",ci="#0550ae",di="#0550ae",hi="#116329",pi="#0550ae",ui="#cf222e",mi="#24292f",gi="#cf222e",fi="#57606a",vi="#57606a",wi="#8250df",yi="#0550ae",xi="#f6f8fa",bi="#cf222e",ki="#0550ae",Ci="#005cc5",Si="#444d56",Bi="#444d56";function _i(e){const{HighlightStyle:t,tags:i}=e;return t.define([{tag:[i.comment,i.lineComment,i.blockComment,i.docComment],color:Yt},{tag:[i.name],color:Jt},{tag:[i.variableName,i.self],color:ei},{tag:[i.typeName,i.tagName],color:ti},{tag:[i.propertyName,i.attributeName],color:ii},{tag:[i.className],color:ni},{tag:[i.labelName],color:si},{tag:[i.namespace],color:oi},{tag:[i.macroName],color:ri},{tag:[i.literal],color:ai},{tag:[i.string,i.docString,i.character,i.attributeValue,i.unit],color:li},{tag:[i.number,i.integer,i.float],color:ci},{tag:[i.bool,i.null,i.atom],color:di},{tag:[i.regexp,i.escape,i.url],color:hi},{tag:[i.color],color:pi},{tag:[i.keyword,i.operatorKeyword,i.controlKeyword,i.definitionKeyword,i.moduleKeyword],color:ui},{tag:[i.modifier],color:mi},{tag:[i.operator,i.derefOperator,i.arithmeticOperator,i.logicOperator,i.bitwiseOperator,i.compareOperator,i.updateOperator,i.definitionOperator,i.typeOperator,i.controlOperator],color:gi},{tag:[i.punctuation,i.separator,i.bracket,i.angleBracket,i.squareBracket,i.paren,i.brace,i.contentSeparator],color:fi},{tag:[i.content],color:vi},{tag:[i.meta,i.documentMeta,i.annotation,i.processingInstruction],color:wi},{tag:i.heading,fontWeight:"bold",color:yi},{tag:i.strong,fontWeight:"bold"},{tag:i.emphasis,fontStyle:"italic"},{tag:i.link,textDecoration:"underline"},{tag:i.strikethrough,textDecoration:"line-through"},{tag:[i.invalid,i.inserted,i.deleted,i.changed],color:xi},{tag:[i.definition(i.name)],color:bi},{tag:[i.constant(i.name)],color:ki},{tag:[i.function(i.variableName)],color:Ci},{tag:[i.standard(i.name)],color:Si},{tag:[i.special(i.variableName)],color:Bi}])}var Ai={type:"block",name:"codeBlock",render:e=>{var t;const i=e.getEditor(),s=I('<div class="lake-code-block" />'),o=e.getContainer();o.css("width",i.container.innerWidth()-2+"px"),o.empty(),o.append(s);const r=s.get(0);if(!r)return;const a=window.LakeCodeMirror;if(!a)return i.readonly?void e.node.hide():(s.addClass("lake-code-block-error"),s.text('\n The code cannot be displayed because window.LakeCodeMirror is not found.\n Please check if the "lake-codemirror" library is added to this page.\n '.trim()),void s.on("click",(()=>{i.selection.selectBox(e)})));const{EditorState:l,Compartment:c,EditorView:d,keymap:h,history:p,defaultKeymap:u,historyKeymap:m,indentWithTab:g,syntaxHighlighting:f}=a,v=a.langItems,w=i.config.codeBlock,y=v.filter((e=>w.langList.indexOf(e.value)>=0)),x=new Map;for(const e of y)x.set(e.value,e);const b=e.value,k=x.get(b.lang),C=new c,S=xt((t=>{i.selection.updateByRange(),i.isComposing||(e.updateValue("code",t),i.history.save())}),1,{immediate:!1}),B=d.updateListener.of((e=>{e.docChanged&&S(e.state.doc.toString())})),_=new d({parent:r,doc:null!==(t=b.code)&&void 0!==t?t:"",extensions:[l.readOnly.of(i.readonly),d.editable.of(!i.readonly),p(),h.of([...u,...m,g]),f(_i(a)),C.of(k&&k.component?k.component():[]),B]});s.find('[contenteditable="true"]').attr("tabindex","-1");const L=new He({root:s,name:"langType",downIcon:n.get("down"),defaultValue:k?b.lang:w.defaultLang,tooltip:i.locale.codeBlock.langType(),menuType:"list",menuHeight:"200px",menuItems:y.map((e=>({value:e.value,text:e.text}))),onSelect:t=>{e.updateValue({lang:t}),e.unmount(),e.render(),i.selection.selectBox(e),i.history.save()}});L.render();const T=()=>{o.css("width",i.container.innerWidth()-2+"px")};i.event.on("resize",T),s.on("click",(()=>{_.hasFocus||_.focus()})),e.event.on("beforeunmount",(()=>{L.unmount(),_.destroy(),i.event.off("resize",T),A("CodeMirror destroyed")}))}};function Li(e,t,i,n){return new(i||(i=Promise))((function(s,o){function r(e){try{l(n.next(e))}catch(e){o(e)}}function a(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}l((n=n.apply(e,t||[])).next())}))}
|
|
18
|
+
`;class Ve{constructor(e){if(this.event=new we,"string"==typeof e){const t=ye.get(e);if(void 0===t)throw new Error(`The box "${e}" has not been defined yet.`);const i=r(t.type),n=r(t.name);this.node=I(a`<lake-box type="${i}" name="${n}"></lake-box>`),t.value&&(this.value=t.value)}else{this.node=I(e);const t=ye.get(this.name);if(void 0===t)throw new Error(`The box "${this.name}" has not been defined yet.`);t.value&&!this.node.hasAttr("value")&&(this.value=t.value)}}addFramework(){let e=this.getContainer();0===e.length?(this.node.html($e),e=this.getContainer()):(e.off("mouseenter"),e.off("mouseleave"),e.off("click")),e.on("mouseenter",(()=>{e.hasClass("lake-box-selected")||e.hasClass("lake-box-focused")||e.hasClass("lake-box-activated")||e.addClass("lake-box-hovered")})),e.on("mouseleave",(()=>{e.removeClass("lake-box-hovered")})),e.on("click",(()=>{A(`The box "${this.name}" (id = ${this.node.id}) value:`),A(this.value)})),"block"===this.type&&this.node.isContentEditable&&e.attr("draggable","true")}get type(){return this.node.attr("type")}get name(){return this.node.attr("name")}get value(){const e=this.node.attr("value");return""===e?{}:JSON.parse(h(e))}set value(e){this.node.attr("value",d(JSON.stringify(e)))}updateValue(e,t){const i=this.value;if("string"==typeof e)i[e]=t;else for(const t of Object.keys(e))i[t]=e[t];this.value=i}getEditor(){const e=this.node.closest("div[contenteditable]"),t=e.length>0?xe.get(e.id):void 0;if(!t)throw new Error(`The box "${this.name}" (id=${this.node.id}) is not rendered in the editor.`);return t}getContainer(){return this.node.find(".lake-box-container")}setToolbar(e){let t;try{t=this.getEditor()}catch(e){}let i=null;const n=()=>{i&&i.position()};this.event.on("focus",(()=>{i=new ze({root:t?t.popupContainer:I(document.body),box:this,items:e,locale:t?t.locale:void 0}),i.render(),t&&t.root.on("scroll",n)})),this.event.on("blur",(()=>{i&&(i.unmount(),i=null),t&&t.root.off("scroll",n)}))}render(){const e=ye.get(this.name);if(void 0===e)return;this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.addFramework();const t=e.render(this);if(void 0!==t){const e=this.getContainer();e.empty(),e.append(t)}A(`The box "${this.name}" (id: ${this.node.id}) rendered`)}unmount(){this.event.emit("blur"),this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.node.empty(),A(`The box "${this.name}" (id: ${this.node.id}) unmounted`)}getHTML(){const e=ye.get(this.name);return void 0===e?"":void 0===e.html?this.node.outerHTML():e.html(this)}}function Fe(e){const t=ge(0);if("string"==typeof e){const i=new Ve(e);return t.set(i.node.id,i),i}const i=(e=I(e)).closestContainer();if(0===i.length){let i=t.get(e.id);return i||(i=new Ve(e),t.set(e.id,i),i)}const n=ge(i.id);let s=t.get(e.id);return s?(n.set(e.id,s),t.delete(e.id),s):(s=n.get(e.id),s||(s=new Ve(e),n.set(e.id,s),s))}function Re(e){const t=e.responseText||e.response;if(!t)return t;try{return JSON.parse(t)}catch(e){return t}}function je(e){const t=new XMLHttpRequest;e.onProgress&&t.upload&&(t.upload.onprogress=t=>{t.total>0&&(t.percent=t.loaded/t.total*100),e.onProgress&&e.onProgress(t)});const i=new FormData,n=e.data||{};Object.keys(n).forEach((e=>{const t=n[e];Array.isArray(t)?t.forEach((t=>{i.append(`${e}[]`,t)})):i.append(e,t)}));const s=e.filename||"file";e.file instanceof Blob?i.append(s,e.file,e.file.name):i.append(s,e.file),t.onerror=t=>{e.onError&&e.onError(t)},t.onload=()=>{if(t.status<200||t.status>=300){if(!e.onError)return;return e.onError(function(e,t){const i=`Cannot ${e.method} ${e.action} ${t.status}'`,n=new Error(i);return n.status=t.status,n.method=e.method,n.url=e.action,n}(e,t),Re(t))}if(e.onSuccess)return e.onSuccess(Re(t),t)},t.open(e.method,e.action,!0),e.withCredentials&&"withCredentials"in t&&(t.withCredentials=!0);const o=e.headers||{};return null!==o["X-Requested-With"]&&t.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(o).forEach((e=>{null!==o[e]&&t.setRequestHeader(e,o[e])})),t.send(i),t}function qe(e){const{editor:t,name:i,file:n,onError:s,onSuccess:o}=e,{requestMethod:r,requestAction:a,requestTypes:l}=t.config[i];if(l.indexOf(n.type)<0)throw s&&s(`File "${n.name}" is not allowed for uploading.`),new Error(`Cannot upload file "${n.name}" because its type "${n.type}" is not found in ['${l.join("', '")}'].`);const c=t.selection.insertBox(i,{url:URL.createObjectURL(n),status:"uploading",name:n.name,size:n.size,type:n.type,lastModified:n.lastModified});let d=je({onProgress:e=>{const t=c.node.find(".lake-percent"),i=Math.round(e.percent);t.text(`${i<100?i:99} %`)},onError:(e,t)=>{d=null,A(e.toString(),t),c.updateValue("status","error"),c.render(),s&&s(e.toString())},onSuccess:e=>{if(d=null,!e.url)return c.updateValue("status","error"),c.render(),void(s&&s("Cannot find the url field."));c.updateValue({status:"done",url:e.url}),c.render(),t.history.save(),o&&o()},file:n,action:a,method:r});return c.event.on("beforeunmount",(()=>{d&&(d.abort(),A("Upload canceled"))})),c}var We=Object.freeze({__proto__:null,appendBreak:D,camelCase:l,changeTagName:V,debug:A,denormalizeValue:f,encode:r,fileSize:w,fixNumberedList:F,fromBase64:h,getBox:Fe,getCSS:y,getDeepElement:H,inString:c,mergeNodes:O,modifierText:v,morph:he,nodePosition:pe,normalizeValue:g,parseStyle:m,query:I,removeBreak:Z,removeZWS:$,request:je,safeTemplate:a,scrollToNode:ue,setBlockIndent:R,splitNodes:P,template:s,toBase64:d,toHex:u,toNodeList:x,uploadFile:qe,wrapNodeList:z});class Ue{constructor(e){this.fragment=null!=e?e:document.createDocumentFragment()}get(){return this.fragment}find(e){const t=[];let i=new E(this.fragment.firstChild);for(;i.length>0;)i.matches(e)?t.push(i.get(0)):i.isElement&&i.find(e).each((e=>{t.push(e)})),i=i.next();return new E(t)}append(e){I(e).each((e=>{this.fragment.appendChild(e)}))}}const Ke={id:/^[\w-]+$/,class:/^[\w- ]+$/,style:{"text-align":["left","center","right","justify","start","end"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function Ge(){return{h1:Object.assign({},Ke),h2:Object.assign({},Ke),h3:Object.assign({},Ke),h4:Object.assign({},Ke),h5:Object.assign({},Ke),h6:Object.assign({},Ke),p:Object.assign({},Ke),blockquote:Object.assign(Object.assign({},Ke),{type:["info","tip","success","warning","error","danger"]}),ul:Object.assign(Object.assign({},Ke),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},Ke),{start:/^\d+$/,indent:/^\d+$/}),li:{value:["true","false"]},table:{style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/}},tr:{style:{height:/^-?\d+(px|%)$/i}},th:"td",td:{colspan:/^\d+$/,rowspan:/^\d+$/,style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/,"text-align":["left","center","right","justify"]}},"lake-box":{type:["inline","block"],name:/^[\w-]+$/,value:/^[^"]+$/,focus:["start","center","end"]},br:{},hr:{},img:{src:/^[^"]+$/,width:/^-?\d+px$/i,height:/^-?\d+px$/i,"data-lake-value":/^[^"]+$/,alt:/^[^"]+$/,style:{width:/^-?\d+px$/i,height:/^-?\d+px$/i}},span:{class:/^[\w- ]+$/,style:{color:/^[^"]+$/,"background-color":/^[^"]+$/,"font-family":/^[^;]+$/,"font-size":/^[^"]+$/}},b:"strong",strong:{},em:"i",i:{},u:{},s:{},sub:{},sup:{},code:{},a:{class:/^[\w- ]+$/,name:/^[\w-]+$/,href:/^[^"]+$/,target:/^[\w-]+$/,rel:/^[^"]+$/,download:/^[^"]+$/},"lake-bookmark":{type:["anchor","focus"]}}}class Xe{constructor(e,t=Ge()){this.rules=t,this.source="string"==typeof e?this.parseHTML(e):e}parseHTML(e){const t=(new DOMParser).parseFromString(e,"text/html");return new E(t.querySelector("body"))}static matchRule(e,t){return"string"==typeof e?e===t:Array.isArray(e)?e.indexOf(t)>=0:e instanceof RegExp&&e.test(t)}static getOpenTagString(e,t){let i=e.name,n=t[i];if(!n)return"";"string"==typeof n&&(i=n,n=t[i]);const s=e.get(0);if(!s.hasAttributes())return i;const o=new Map;for(const e of s.attributes)if(n[e.name]&&("style"!==e.name&&Xe.matchRule(n[e.name],e.value)&&o.set(e.name,e.value),"style"===e.name)){const t=n.style,i=new Map,s=m(e.value);for(const e of Object.keys(s)){const n=s[e];t[e]&&Xe.matchRule(t[e],n)&&i.set(e,n)}o.set("style",i)}let r=i;for(const[e,t]of o)if("style"===e){let e="";for(const[i,n]of t)e+=`${i}: ${n.replace(/"/g,""")}; `;""!==e&&(r+=` style="${e.trim()}"`)}else r+=` ${e}="${t}"`;return r}static getClosedTagString(e,t){let i=e.name;const n=t[i];return n?("string"==typeof n&&(i=n),i):""}static getTrimmedText(e){const t=e.parent(),i=e.prev(),n=e.next();let s=e.text();return(i.isBlock||i.isBlockBox)&&(n.isBlock||n.isBlockBox)||0===i.length&&0===n.length&&t.isBlock?s=s.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):i.isBlock||i.isBlockBox||0===i.length&&t.isBlock?s=s.replace(/^[\u0020\t\r\n]+/,""):(n.isBlock||n.isBlockBox||0===n.length&&t.isBlock)&&(s=s.replace(/[\u0020\t\r\n]+$/,"")),s}getHTML(){const e=this.rules;let t="";for(const i of function*t(i){let n=i.first();for(;n.length>0;){const i=n.next();if(n.isText)yield r(Xe.getTrimmedText(n));else if(n.isVoid){const t=Xe.getOpenTagString(n,e);""!==t&&(yield`<${t} />`)}else if(n.isElement){const i=Xe.getOpenTagString(n,e),s=Xe.getClosedTagString(n,e);""!==i&&(yield`<${i}>`),n.isBox||(yield*t(n)),""!==s&&(yield`</${s}>`)}n=i}}(this.source))t+=i;return t.trim()}getFragment(){const e=this.getHTML(),t=this.parseHTML(e),i=document.createDocumentFragment();let n=t.first();for(;n.length>0;){const e=n.next();i.appendChild(n.get(0)),n=e}return i}}class Qe{constructor(e){this.content=e}getHTML(){let e=this.content;return e=e.replace(/ {2}/g," "),e=r(e.trim()),e=`<p>${e}</p>`,e=e.replace(/(\r\n){2,}/g,"</p><p><br /></p><p>"),e=e.replace(/\r\n/g,"</p><p>"),e=e.replace(/[\r\n]{2,}/g,"</p><p><br /></p><p>"),e=e.replace(/[\r\n]/g,"</p><p>"),e}getFragment(){return new Xe(this.getHTML()).getFragment()}}function Ye(e,t){if(e.commonAncestor.isOutside)return;const i=(t=I(t)).get(0),n=e.get();n.insertNode(i),n.setEndAfter(i),n.collapse(!1)}function Je(e){if(e.commonAncestor.isOutside)return{anchor:new E,focus:new E};const t=e.startNode.closest("lake-box");if(t.length>0)return e.isBoxStart?t.attr("focus","start"):e.isBoxEnd?t.attr("focus","end"):t.attr("focus","center"),{anchor:new E,focus:t};if(e.isCollapsed){const t=e.clone();t.collapseToEnd();const i=I('<lake-bookmark type="focus" />');return Ye(t,i),{anchor:new E,focus:i}}const i=e.clone();i.collapseToStart();const n=I('<lake-bookmark type="anchor" />');Ye(i,n);const s=e.clone();s.collapseToEnd();const o=I('<lake-bookmark type="focus" />');return Ye(s,o),{anchor:n,focus:o}}function et(e,t){const i=e.prev(),n=e.next();if(i.isText||n.isText){const t=e.parent();e.remove(),t.get(0).normalize()}else if(0===i.length&&0===n.length){if(e.parent().isMark&&t){const i=new E(document.createTextNode(""));e.before(i),t.setStartAfter(i),t.collapseToStart()}e.remove()}else e.remove()}function tt(e,t){const i=t.anchor,n=t.focus;if(i.length>0&&0===n.length)et(i);else{if(n.length>0&&0===i.length){if(n.isBox){const t=Fe(n);0===t.getContainer().length&&t.render();const i=n.attr("focus");return"start"===i?e.selectBoxStart(n):"center"===i?e.selectBox(n):e.selectBoxEnd(n),void n.removeAttr("focus")}return e.setStartBefore(n),e.collapseToStart(),void et(n,e)}if(i.length>0&&n.length>0){const t=new M;t.selectNode(i),t.collapseToEnd(),-1===t.compareAfterNode(n)?(e.setStartBefore(n),et(n),e.setEndBefore(i),et(i)):(e.setStartBefore(i),et(i),e.setEndBefore(n),et(n))}}}function it(e){if(e.commonAncestor.isOutside)return;F(e.getBlocks())}function nt(e){if(e.isCollapsed)return;if(e.adjustBox(),e.adjustTable(),e.isInoperative)return;const t=e.startNode.closestBlock(),i=e.endNode.closestBlock(),n=t.get(0)===i.get(0);if(e.get().deleteContents(),e.adjustBlock(),n){const t=e.getBlocks()[0];if(t&&t.isEmpty){const i=D(t);e.setStartBefore(i),e.collapseToStart()}return}const s=e.getBlocks()[0];if(!s)return;const o=s.prev();if(0===o.length)return;const r=Je(e);O(o,s),tt(e,r),it(e)}function st(e,t){if(t instanceof Ue&&(t=t.get()),e.commonAncestor.isOutside)return;e.isCollapsed?e.adjustBox():nt(e);Z(e.startNode.closestBlock());const i=Je(e);i.focus.before(t),tt(e,i),e.adjustBlock()}function ot(e,t){if(e.commonAncestor.isOutside)return;if(e.isCollapsed){if(e.commonAncestor.closest("lake-box").isBlockBox)return}if("string"!=typeof t){const i=e.getBlocks();for(const e of i)e.css(t);return}const i=I(t),n=i.name,s=i.get(0).attributes,o=e.getBlocks();if(o.length>0){const t=Je(e);for(const e of o)if(e.name===n&&0===i.first().length)for(const t of s)e.attr(t.name,t.value);else{const t=i.clone(!0);t.isList&&e.isList&&""!==e.attr("indent")&&t.attr("indent",e.attr("indent"));const n=H(t);let s=e.first();for(;s.length>0;){const e=s.next();n.append(s),n.name!==s.name&&"li"!==s.name||s.remove(!0),s=e}e.replaceWith(t)}return tt(e,t),void it(e)}const r=Je(e),a=function(e){const t=e.commonAncestor.closest('div[contenteditable="true"],td');let i=[];if(0===t.length)return i;let n=t.first(),s=!0;for(;n.length>0;){if(n.isMark||n.isText||n.isBookmark||n.isInlineBox)i.push(n);else{if(!s)break;i=[]}e.intersectsNode(n)&&(s=!1),n=n.next()}return i}(e),l=z(a,i);if(tt(e,r),it(e),l.isEmpty){const t=D(l);e.setStartBefore(t),e.collapseToStart()}}function rt(e){if(e.commonAncestor.isOutside)return{start:null,end:null};e.isCollapsed?e.adjustBox():nt(e);const t=e.startNode,i=t.closestOperableBlock();if(0===i.length)return{start:null,end:null};let n=i.parent();n.isOutside&&(n=t.closestContainer());const s=P(t,e.startOffset,n);let o=null,r=null;return s&&(o=s.start,r=s.end),!s&&t.isBlock&&(e.startOffset>0&&(o=t.children()[e.startOffset-1]),r=t.children()[e.startOffset],r&&!r.isBlock&&(r=null)),o&&o.isEmpty&&D(o),r&&(r.isEmpty&&D(r),e.shrinkBefore(r)),it(e),{start:o,end:r}}function at(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function lt(e,t,i){let n=null,s=null,o=e.closestBlock();0===o.length&&(o=e.closestContainer());const r=P(e,t,o);return r&&(i?(at(r.start),at(r.end),r.start.isEmpty||(n=r.start),r.end.isEmpty||(s=r.end)):(n=r.start,s=r.end)),{start:n,end:s}}function ct(e,t=!0){if(e.commonAncestor.isOutside)return{start:null,center:null,end:null};if(e.adjustBox(),e.isCollapsed){const i=lt(e.startNode,e.startOffset,t);return i.start?(e.setStartAfter(i.start),e.collapseToStart()):i.end&&(e.setStartBefore(i.end),e.collapseToStart()),{start:i.start,center:null,end:i.end}}const i=lt(e.startNode,e.startOffset,t);i.start?e.setStartAfter(i.start):i.end&&e.setStartBefore(i.end);const n=lt(e.endNode,e.endOffset,t);return n.start?e.setEndAfter(n.start):n.end&&e.setEndBefore(n.end),{start:i.start,center:n.start,end:n.end}}function dt(e,t){const i=e.text();let n=e;for(;n.length>0;){const e=n.parent();if(!e.isMark||i!==e.text()||!n.isText&&n.name===t&&""!==n.attr("style"))break;n=e}return n}function ht(e,t){if(e.commonAncestor.isOutside)return;let i=I(t);const n=i.name,s=m(i.attr("style"));if(e.isCollapsed){if(e.isBox){const t=e.startNode.closest("lake-box");if("block"===Fe(t).type){const i=I("<p><br /></p>");e.isBoxStart?t.before(i):t.after(i),e.shrinkAfter(i)}else e.adjustBox()}Z(e.startNode.closestBlock());const t=new E(document.createTextNode("")),o=ct(e);if(o.start){const e=function(e){if(!e.isMark)return null;let t=e.clone(),i=e.last();for(;i.length>0;){if(i.isMark){const e=i.clone();t.append(e),t=e}i=i.last()}return t}(o.start);if(e)if(e.name===n)e.css(s),i=e;else{H(e).append(t),i.append(e)}}return""===i.text()&&i.append(t),Ye(e,i),function(e){const t=e.prev();t.length>0&&t.isText&&t.isEmpty&&t.remove();const i=e.next();i.length>0&&i.isText&&i.isEmpty&&i.remove()}(i),void e.shrinkAfter(i)}ct(e);const o=e.getMarks(!0),r=Je(e);for(const e of o)if(!e.isEmpty&&e.isText){const t=dt(e,n);if(t.isMark&&t.name===n)t.css(s);else{const e=i.clone();t.before(e),e.append(t)}}tt(e,r)}function pt(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function ut(e,t){if(e.commonAncestor.isOutside)return;let i;if(t){i=I(t).name}if(e.isCollapsed){if(e.isBox)return;if(i&&0===e.commonAncestor.closest(i).length)return;const t=ct(e,!1);if(!t.start)return;t.end&&pt(t.end);const n=new E(document.createTextNode("")),s=function(e,t){if(!e.isMark||!t)return null;let i=e.clone(),n=e.last();for(;n.length>0;){if(n.isMark&&n.name!==t){const e=n.clone();i.append(e),i=e}n=n.last()}if(i.name===t){if(!(i.first().length>0))return null;i=i.first()}return i}(t.start,i);if(!s)return t.start.after(n),pt(t.start),n.prev().isText?(e.setStartAfter(n.prev()),e.collapseToStart(),void n.remove()):(e.setStartAfter(n),void e.collapseToStart());return H(s).append(n),t.start.after(s),pt(t.start),void e.shrinkAfter(s)}ct(e);const n=e.getMarks(),s=Je(e);for(const e of n)if(!i||e.name===i){const t=e.parent();e.remove(!e.isEmpty),t.length>0&&t.get(0).normalize()}$(e.commonAncestor),tt(e,s)}function mt(e,t){if(e.commonAncestor.isOutside)return null;const i=I(t);if(e.isCollapsed){let t=e.commonAncestor.closest("a");if(0===t.length){t=i.clone(!0);return Z(e.startNode.closestBlock()),Ye(e,t),t}return""!==i.attr("href")&&t.attr({href:i.attr("href")}),t}ct(e);const n=Je(e);for(const t of e.commonAncestor.getWalker())"a"===t.name&&e.intersectsNode(t)&&t.remove(!0);const s=i.clone(!1);n.anchor.after(s);let o=s.next();for(;o.length>0;){const e=o.next();if(!o.isMark&&!o.isText)break;s.append(o),o=e}return 0===s.first().length&&s.remove(),tt(e,n),s}function gt(e,t,i){if(e.commonAncestor.isOutside)return null;const n=Fe(t);i&&(n.value=i);const s=document.createDocumentFragment();if(s.appendChild(n.node.get(0)),"inline"===n.type)return st(e,s),n.render(),e.selectBoxEnd(n.node),Fe(n.node);const o=rt(e);return o.start&&(e.setEndAfter(o.start),e.collapseToEnd()),o.end&&o.end.isEmpty&&o.end.remove(),st(e,s),n.render(),e.selectBoxEnd(n.node),o.start&&o.start.isEmpty&&o.start.remove(),Fe(n.node)}function ft(e){const t=e.node.closestContainer();if(e.unmount(),e.node.remove(),t.length>0){ge(t.id).delete(e.node.id);ge(0).set(e.node.id,e)}return e}function vt(e){if(e.commonAncestor.isOutside)return null;const t=e.commonAncestor.closest("lake-box");if(0===t.length)return null;const i=Fe(t);if("block"===i.type){const n=I("<p><br /></p>");return t.before(n),e.shrinkAfter(n),ft(i)}e.setStartBefore(t),e.collapseToStart();const n=t.parent();if(ft(i),n.isEmpty){const t=D(n);e.setStartBefore(t),e.collapseToStart()}return i}var wt={exports:{}};function yt(e,t=100,i={}){if("function"!=typeof e)throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw new RangeError("`wait` must not be negative.");const{immediate:n}="boolean"==typeof i?{immediate:i}:i;let s,o,r,a,l;function c(){const t=s,i=o;return s=void 0,o=void 0,l=e.apply(t,i),l}function d(){const e=Date.now()-a;e<t&&e>=0?r=setTimeout(d,t-e):(r=void 0,n||(l=c()))}const h=function(...e){if(s&&this!==s)throw new Error("Debounced method called with different contexts.");s=this,o=e,a=Date.now();const i=n&&!r;return r||(r=setTimeout(d,t)),i&&(l=c()),l};return h.clear=()=>{r&&(clearTimeout(r),r=void 0)},h.flush=()=>{r&&h.trigger()},h.trigger=()=>{l=c(),h.clear()},h}wt.exports.debounce=yt,wt.exports=yt;var xt=fe(wt.exports),bt=fe((function e(t,i){if(t===i)return!0;if(t&&i&&"object"==typeof t&&"object"==typeof i){if(t.constructor!==i.constructor)return!1;var n,s,o;if(Array.isArray(t)){if((n=t.length)!=i.length)return!1;for(s=n;0!=s--;)if(!e(t[s],i[s]))return!1;return!0}if(t instanceof Map&&i instanceof Map){if(t.size!==i.size)return!1;for(s of t.entries())if(!i.has(s[0]))return!1;for(s of t.entries())if(!e(s[1],i.get(s[0])))return!1;return!0}if(t instanceof Set&&i instanceof Set){if(t.size!==i.size)return!1;for(s of t.entries())if(!i.has(s[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(i)){if((n=t.length)!=i.length)return!1;for(s=n;0!=s--;)if(t[s]!==i[s])return!1;return!0}if(t.constructor===RegExp)return t.source===i.source&&t.flags===i.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===i.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===i.toString();if((n=(o=Object.keys(t)).length)!==Object.keys(i).length)return!1;for(s=n;0!=s--;)if(!Object.prototype.hasOwnProperty.call(i,o[s]))return!1;for(s=n;0!=s--;){var r=o[s];if(!e(t[r],i[r]))return!1}return!0}return t!=t&&i!=i}));function kt(e){const t=e.get(0),i={};if(t.hasAttributes())for(const e of t.attributes)i[e.name]=e.value;return i}class Ct{constructor(e){const t=window.getSelection();if(!t)throw new Error("Selection object is null.");this.selection=t,this.container=e,this.range=this.getCurrentRange()}getCurrentRange(){if(this.selection.rangeCount>0){const e=this.selection.getRangeAt(0);return new M(e)}return new M}sync(){this.container.contains(this.range.commonAncestor)&&(this.selection.removeAllRanges(),this.selection.addRange(this.range.get()))}updateByRange(){const e=this.getCurrentRange();this.container.contains(e.commonAncestor)&&(this.range.startNode.get(0)===e.startNode.get(0)&&this.range.startOffset===e.startOffset&&this.range.endNode.get(0)===e.endNode.get(0)&&this.range.endOffset===e.endOffset||(this.range=e))}updateByBookmark(){const e=this.range,t=this.container,i=t.find("lake-box[focus]");if(i.length>0)return tt(e,{anchor:new E,focus:i}),void this.sync();tt(e,{anchor:t.find('lake-bookmark[type="anchor"]'),focus:t.find('lake-bookmark[type="focus"]')}),this.sync()}getAppliedItems(){const e=[];return function(e,t){let i=t.startNode;for(i.isText&&(i=i.parent());i.length>0&&i.isInside;)e.push({node:i,name:i.name,attributes:kt(i),styles:m(i.attr("style"))}),i=i.parent()}(e,this.range),function(e,t){const i=t.startNode;let n;if(i.isText&&i.text().length===t.startOffset){const e=i.next();e.length>0&&e.isElement&&(n=e)}if(i.isElement){const e=i.children();if(e.length>0){const i=e[t.startOffset];i&&i.isElement&&(n=i)}}if(n){let t=n;for(;t.length>0;)t.isElement&&e.push({node:t,name:t.name,attributes:kt(t),styles:m(t.attr("style"))}),t=t.first()}}(e,this.range),e}insertBookmark(){return Je(this.range)}toBookmark(e){return tt(this.range,e)}insertNode(e){return Ye(this.range,e)}insertFragment(e){return st(this.range,e)}deleteContents(){return nt(this.range)}setBlocks(e){return ot(this.range,e)}splitBlock(){return rt(this.range)}splitMarks(e){return ct(this.range,e)}addMark(e){return ht(this.range,e)}removeMark(e){return ut(this.range,e)}fixList(){return it(this.range)}insertLink(e){return mt(this.range,e)}selectBox(e){let t=e;t=e instanceof Ve?e.node:e,this.range.selectBox(t)}insertBox(e,t){const i=gt(this.range,e,t);if(!i)throw new Error(`The box "${e}" cannot be inserted outside the editor.`);return i}removeBox(e=null){return e&&this.selectBox(e),vt(this.range)}}class St{constructor(e){this.commandMap=new Map,this.selection=e}add(e,t){this.commandMap.set(e,t)}delete(e){this.commandMap.delete(e)}getNames(){return Array.from(this.commandMap.keys())}has(e){return void 0!==this.commandMap.get(e)}getItem(e){const t=this.commandMap.get(e);if(void 0===t)throw new Error(`Command "${e}" has not been defined yet.`);return t}isDisabled(e){const t=this.getItem(e);if(!t.isDisabled)return!1;const i=this.selection.getAppliedItems();return t.isDisabled(i)}isSelected(e){const t=this.getItem(e);if(!t.isSelected)return!1;const i=this.selection.getAppliedItems();return t.isSelected(i)}selectedValues(e){const t=this.getItem(e);if(!t.selectedValues)return[];const i=this.selection.getAppliedItems();return t.selectedValues(i)}execute(e,...t){const i=this.selection.container,n=this.selection.range;i.contains(n.commonAncestor)||n.shrinkAfter(i);this.getItem(e).execute.apply(this,t),A(`Command "${e}" executed`)}}class Bt{constructor(e){this.canSave=!0,this.list=[],this.index=0,this.limit=100,this.event=new we,this.selection=e,this.container=e.container}removeBookmark(e){return e.replace(/(<lake-box[^>]+)\s+focus="\w+"([^>]*>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"")}getValue(e){return new Xe(e).getHTML()}addIdToBoxes(e){e.find("lake-box").each((e=>{const t=new E(e),i=`${t.attr("name")}-${t.attr("value")}`;t.attr("id",i)}))}removeIdfromBoxes(e){e.find("lake-box").each((e=>{new E(e).removeAttr("id")}))}morphContainer(e){const t=this.container,i={beforeChildrenUpdated:e=>{if("lake-box"===new E(e).name)return!1},afterAttributeUpdated:(e,i)=>{const n=new E(i);if(["name","value"].indexOf(e)>=0&&"lake-box"===n.name){Fe(n).unmount();ge(t.id).delete(n.id)}}},n=e.clone(!0);this.addIdToBoxes(t),this.addIdToBoxes(n),he(t,n,{callbacks:i}),this.removeIdfromBoxes(t),this.removeIdfromBoxes(n)}get canUndo(){return this.index>1&&!!this.list[this.index-2]}get canRedo(){return!!this.list[this.index]}cloneContainer(){const e=this.selection.range,t=this.container.clone(!0);if(t.find("lake-box").each((e=>{Fe(e).getContainer().empty()})),!this.container.contains(e.commonAncestor))return t;if(e.isInsideBox){const i=e.commonAncestor.closest("lake-box").path(),n=t.find(i),s=e.clone();return s.selectBox(n),Je(s),t}const i=e.startNode.path(),n=e.endNode.path(),s=t.find(i),o=t.find(n),r=e.clone();return r.setStart(s,e.startOffset),r.setEnd(o,e.endOffset),Je(r),t}undo(){if(!this.list[this.index-2])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index>1;){const t=this.list[this.index-2];if(!t)break;this.index--;const i=this.getValue(t);if(this.removeBookmark(i)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("undo",i);break}}this.selection.updateByBookmark(),A(`History undone (index: ${this.index})`)}redo(){if(!this.list[this.index])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index<this.list.length;){const t=this.list[this.index];if(!t)break;this.index++;const i=this.getValue(t);if(this.removeBookmark(i)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("redo",i);break}}this.selection.updateByBookmark(),A(`History redone (index: ${this.index})`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(e={}){var t,i,n;const s=null!==(t=e.inputType)&&void 0!==t?t:"",o=null!==(i=e.update)&&void 0!==i&&i,r=null===(n=e.emitEvent)||void 0===n||n;if(!this.canSave)return;const a=this.cloneContainer(),l=this.getValue(a);this.list[this.index-1]&&this.removeBookmark(this.getValue(this.list[this.index-1]))===this.removeBookmark(l)||(o?this.list.splice(this.index-1,1/0,a):(this.list.splice(this.index,1/0,a),this.index++),this.list.length>this.limit&&(this.list.shift(),this.index=this.list.length),A(`History saved (index: ${this.index}, inputType: "${s}", update: ${o}, emitEvent: ${r})`),r&&this.event.emit("save",f(l),{inputType:s,update:o,emitEvent:r}))}}var _t={};Object.defineProperty(_t,"__esModule",{value:!0});for(var At="undefined"!=typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.platform),Lt={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},Tt={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:At?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},Et={backspace:8,tab:9,enter:13,shift:16,control:17,alt:18,pause:19,capslock:20,escape:27," ":32,pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,insert:45,delete:46,meta:91,numlock:144,scrolllock:145,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},It=1;It<20;It++)Et["f"+It]=111+It;function Mt(e,t,i){t&&!("byKey"in t)&&(i=t,t=null),Array.isArray(e)||(e=[e]);var n=e.map((function(e){return Pt(e,t)})),s=function(e){return n.some((function(t){return Dt(t,e)}))};return null==i?s:s(i)}function Pt(e,t){var i=t&&t.byKey,n={},s=(e=e.replace("++","+add")).split("+"),o=s.length;for(var r in Lt)n[Lt[r]]=!1;var a=!0,l=!1,c=void 0;try{for(var d,h=s[Symbol.iterator]();!(a=(d=h.next()).done);a=!0){var p=d.value,u=p.endsWith("?")&&p.length>1;u&&(p=p.slice(0,-1));var m=Nt(p),g=Lt[m];if(p.length>1&&!g&&!Tt[p]&&!Et[m])throw new TypeError('Unknown modifier: "'+p+'"');1!==o&&g||(i?n.key=m:n.which=Zt(p)),g&&(n[g]=!u||null)}}catch(e){l=!0,c=e}finally{try{!a&&h.return&&h.return()}finally{if(l)throw c}}return n}function Dt(e,t){for(var i in e){var n=e[i],s=void 0;if(null!=n&&((null!=(s="key"===i&&null!=t.key?t.key.toLowerCase():"which"===i?91===n&&93===t.which?91:t.which:t[i])||!1!==n)&&s!==n))return!1}return!0}function Zt(e){return e=Nt(e),Et[e]||e.toUpperCase().charCodeAt(0)}function Nt(e){return e=e.toLowerCase(),e=Tt[e]||e}_t.default=Mt,_t.isHotkey=Mt,_t.isCodeHotkey=function(e,t){return Mt(e,t)};var Ot=_t.isKeyHotkey=function(e,t){return Mt(e,{byKey:!0},t)};_t.parseHotkey=Pt,_t.compareHotkey=Dt,_t.toKeyCode=Zt,_t.toKeyName=Nt;class Ht{constructor(e){this.keydownEventList=[],this.keyupEventList=[],this.container=e,this.container.on("keydown",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keydownEventList)if(Ot(e.type,t)&&!1===e.listener(t))break})),this.container.on("keyup",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keyupEventList)if(Ot(e.type,t)&&!1===e.listener(t))break}))}setKeydown(e,t){this.keydownEventList.push({type:e,listener:t})}setKeyup(e,t){this.keyupEventList.push({type:e,listener:t})}keydown(e){for(const t of this.keydownEventList)if(t.type===e&&!1===t.listener(new KeyboardEvent(e)))break}keyup(e){for(const t of this.keyupEventList)if(t.type===e&&!1===t.listener(new KeyboardEvent(e)))break}}const zt={value:"<p><br /></p>",readonly:!1,spellcheck:!1,tabIndex:0,placeholder:"",indentWithTab:!0,lang:"en-US",minChangeSize:5,historySize:100,onMessage:(e,t)=>{"success"!==e?"warning"!==e?"error"===e&&console.error(t):console.warn(t):console.log(t)},slash:!1};class $t{constructor(e){if(this.unsavedInputData="",this.unsavedInputCount=0,this.state={appliedItems:[],disabledNameMap:new Map,selectedNameMap:new Map,selectedValuesMap:new Map},this.unmountPluginMap=new Map,this.isComposing=!1,this.event=new we,this.box=$t.box,this.copyListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("copy",e)},this.cutListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("cut",e)},this.pasteListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("paste",e)},this.selectionchangeListener=()=>{this.updateSelectionRange(),this.updateBoxSelectionStyle(),this.emitStateChangeEvent()},this.clickListener=e=>{const t=new E(e.target);t.get(0).isConnected&&this.event.emit("click",t)},this.resizeListener=()=>{this.event.emit("resize")},this.scrollListener=()=>{this.event.emit("scroll")},this.updateSelectionRange=xt((()=>{this.selection.updateByRange()}),1,{immediate:!0}),this.updateBoxSelectionStyle=xt((()=>{if(0===this.root.first().length)return;const e=this.selection.range,t=e.clone();t.adjustBox(),this.container.find("lake-box").each((i=>{const n=Fe(i),s=n.getContainer();if(0!==s.length){if(e.compareBeforeNode(s)<0&&e.compareAfterNode(s)>0&&(!e.isCollapsed||e.startNode.get(0)!==s.get(0)||0!==e.startOffset))return s.removeClass("lake-box-hovered"),s.removeClass("lake-box-selected"),s.removeClass("lake-box-focused"),s.addClass("lake-box-activated"),void n.event.emit("focus");if(t.intersectsNode(n.node))return s.removeClass("lake-box-activated"),void(e.isCollapsed?(s.removeClass("lake-box-hovered"),s.removeClass("lake-box-selected"),s.addClass("lake-box-focused"),n.event.emit("focus")):(s.removeClass("lake-box-focused"),s.addClass("lake-box-selected"),n.event.emit("blur")));s.removeClass("lake-box-activated"),s.removeClass("lake-box-focused"),s.removeClass("lake-box-selected"),n.event.emit("blur")}}))}),50,{immediate:!0}),this.emitStateChangeEvent=xt((()=>{const e=this.command.getNames();let t=this.selection.getAppliedItems();t.length>0&&!this.container.contains(t[0].node)&&(t=[]);const i=new Map,n=new Map,s=new Map;if(t.length>0)for(const o of e){const e=this.command.getItem(o);if(e.isDisabled&&e.isDisabled(t)&&i.set(o,!0),e.isSelected&&e.isSelected(t)&&n.set(o,!0),e.selectedValues){const i=e.selectedValues(t);i.length>0&&s.set(o,i)}}const o={appliedItems:t,disabledNameMap:i,selectedNameMap:n,selectedValuesMap:s};bt(o,this.state)||(this.toolbar&&this.toolbar.updateState(o),this.event.emit("statechange",o),this.state=o)}),50,{immediate:!1}),!e.root)throw new Error("The root of the config must be specified.");this.root=I(e.root),this.toolbar=e.toolbar,this.config=Object.assign({},zt);for(const t of Object.keys(e))this.config[t]=e[t];this.containerWrapper=I('<div class="lake-container-wrapper" />'),this.container=I('<div class="lake-container" />'),this.overlayContainer=I('<div class="lake-overlay" />'),this.popupContainer=I('<div class="lake-popup lake-custom-properties" />'),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",tabindex:this.config.tabIndex.toString()}),""!==this.config.placeholder&&this.container.attr("placeholder",this.config.placeholder),this.selection=new Ct(this.container),this.command=new St(this.selection),this.history=new Bt(this.selection),this.history.limit=this.config.historySize,this.keystroke=new Ht(this.container),xe.set(this.container.id,this)}togglePlaceholderClass(e){const t="lake-placeholder";"<p><br /></p>"===(e=f(e)).replace("<focus />","")?this.container.addClass(t):this.container.removeClass(t)}moveBoxStripText(){const e=this.selection,t=e.range,i=t.startNode.closest(".lake-box-strip"),n=i.closest("lake-box");if("inline"===Fe(n).type)t.isBoxStart?(t.setStartBefore(n),t.collapseToStart()):(t.setStartAfter(n),t.collapseToStart());else{const e=I("<p />");t.isBoxStart?n.before(e):n.after(e),t.setStart(e,0),t.collapseToStart()}const s=i.text();i.html("<br />"),e.insertNode(document.createTextNode(s))}resetUnsavedInputData(){this.unsavedInputData="",this.unsavedInputCount=0}handleInputEvent(e){var t;this.selection.updateByRange();const i=this.selection.range;if(i.isInsideBox)return;if(i.isBoxStart||i.isBoxEnd)return this.moveBoxStripText(),void this.history.save();if("insertText"===(e instanceof CompositionEvent?"insertText":e.inputType)){const i=null!==(t=e.data)&&void 0!==t?t:"";return i.length>1?void this.history.save({inputType:"insertText",update:!1}):(this.unsavedInputData+=i,this.unsavedInputCount++,void(this.unsavedInputData.length<this.config.minChangeSize?this.history.save({inputType:"insertText",update:this.unsavedInputCount>1}):(this.history.save({inputType:"insertText",update:!0}),this.resetUnsavedInputData())))}this.history.save()}bindInputEvents(){this.container.on("compositionstart",(()=>{this.isComposing=!0,this.container.removeClass("lake-placeholder")})),this.container.on("compositionend",(e=>{this.isComposing=!1,this.handleInputEvent(e)})),this.container.on("input",(e=>{const t=e;this.isComposing=t.isComposing,this.isComposing||this.handleInputEvent(e)}))}bindHistoryEvents(){const e=e=>{this.fixContent()&&(this.history.save({update:!0,emitEvent:!1}),e=this.getValue()),this.emitStateChangeEvent(),this.togglePlaceholderClass(e),this.scrollToCaret(),this.event.emit("change",e)};this.history.event.on("undo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("redo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("save",((t,i)=>{this.removeBoxGarbage(),e(t),"insertText"!==i.inputType&&(this.selection.sync(),this.resetUnsavedInputData())}))}get hasFocus(){const e=document.activeElement;return!!e&&I(e).closest(".lake-container").get(0)===this.container.get(0)}get locale(){return Oe(this.config.lang)}fixContent(){const e=this.selection.range;let t=!1,i=this.container.children();for(const e of i)(e.isBlock||e.isMark)&&""===e.html()&&(e.remove(),t=!0,A(`Content fixed: empty tag "${e.name}" was removed`));if(i=this.container.children(),0===i.length)this.container.html("<p><br /></p>"),e.shrinkBefore(this.container),t=!0,A("Content fixed: default paragraph was added");else if(1===i.length){const n=i[0];if(n.isVoid){const i=I("<p />");n.before(i),i.append(n),e.shrinkAfter(i),t=!0,A(`Content fixed: void element "${n.name}" was wrapped in paragraph`)}}return e.adjustBr(),t}setPluginConfig(e,t){"object"!=typeof this.config[e]&&(this.config[e]={});for(const i of Object.keys(t))void 0===this.config[e][i]&&(this.config[e][i]=t[i])}removeBoxGarbage(){const e=ge(this.container.id);for(const t of e.values())t.node.get(0).isConnected||(t.unmount(),e.delete(t.node.id))}renderBoxes(){this.removeBoxGarbage();const e=this.container,t=ge(e.id);e.find("lake-box").each((e=>{const i=I(e);if(t.get(i.id))return;Fe(i).render()}))}focus(){this.container.focus()}blur(){this.container.blur()}scrollToCaret(){const e=this.selection.range;if(e.isBox)return;const t=e.getRect();if(0===t.x||0===t.y)return;const i=this.container.get(0).getBoundingClientRect(),n=I('<div class="lake-artificial-caret" />'),s=t.x-i.x,o=t.y-i.y;n.css({position:"absolute",top:`${o}px`,left:`${s}px`,width:`${t.width}px`,height:`${t.height}px`,"z-index":"-1"}),this.overlayContainer.find(".lake-artificial-caret").remove(),this.overlayContainer.append(n),ue(n,{behavior:"instant",block:"center",inline:"nearest"}),n.remove()}setValue(e){e=g(e);const t=new Xe(e),i=t.getFragment();this.container.empty(),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.renderBoxes(),this.selection.updateByBookmark()}getValue(){const e=this.history.cloneContainer();let t=new Xe(e).getHTML();return t=f(t),t}render(){const e=g(this.config.value),t=new Xe(e),i=t.getFragment();this.root.empty(),this.root.append(this.containerWrapper),this.containerWrapper.append(this.container),this.containerWrapper.append(this.overlayContainer),I(document.body).append(this.popupContainer),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.unmountPluginMap=$t.plugin.loadAll(this),this.readonly||(this.selection.updateByBookmark(),this.history.save({emitEvent:!1})),this.renderBoxes(),this.toolbar&&this.toolbar.render(this),this.root.on("scroll",this.scrollListener),document.addEventListener("copy",this.copyListener),window.addEventListener("resize",this.resizeListener),this.readonly||(document.addEventListener("cut",this.cutListener),document.addEventListener("paste",this.pasteListener),document.addEventListener("selectionchange",this.selectionchangeListener),document.addEventListener("click",this.clickListener),this.bindInputEvents(),this.bindHistoryEvents())}unmount(){this.updateSelectionRange.flush(),this.updateBoxSelectionStyle.flush(),this.emitStateChangeEvent.flush();for(const e of this.unmountPluginMap.keys()){const t=this.unmountPluginMap.get(e);t&&(t(),A(`The plugin "${e}" unmounted`))}this.toolbar&&this.toolbar.unmount(),this.removeBoxGarbage(),this.container.find("lake-box").each((e=>{Fe(I(e)).unmount()})),this.event.removeAllListeners(),this.history.event.removeAllListeners(),this.root.off(),this.root.removeClass("lake-custom-properties"),this.root.empty(),this.popupContainer.remove(),document.removeEventListener("copy",this.copyListener),window.removeEventListener("resize",this.resizeListener),this.readonly||(document.removeEventListener("cut",this.cutListener),document.removeEventListener("paste",this.pasteListener),document.removeEventListener("selectionchange",this.selectionchangeListener),document.removeEventListener("click",this.clickListener))}}$t.version="0.1.24",$t.box=new class{add(e){ye.set(e.name,e)}remove(e){ye.delete(e)}getNames(){return Array.from(ye.keys())}},$t.plugin=new class{constructor(){this.pluginMap=new Map}add(e,t){if(this.pluginMap.get(e))throw new Error(`Plugin "${e}" is already defined.`);this.pluginMap.set(e,t)}loadAll(e){const t=new Map;for(const i of this.pluginMap.keys()){const n=this.pluginMap.get(i);if(n&&!1!==e.config[i]){const s=n(e);s&&t.set(i,s)}}return t}};const Vt=[{icon:n.get("numberedList"),value:"numbered",text:e=>e.toolbar.numberedList()},{icon:n.get("bulletedList"),value:"bulleted",text:e=>e.toolbar.bulletedList()},{icon:n.get("checklist"),value:"checklist",text:e=>e.toolbar.checklist()}],Ft=[{icon:n.get("alignLeft"),value:"left",text:e=>e.toolbar.alignLeft()},{icon:n.get("alignCenter"),value:"center",text:e=>e.toolbar.alignCenter()},{icon:n.get("alignRight"),value:"right",text:e=>e.toolbar.alignRight()},{icon:n.get("alignJustify"),value:"justify",text:e=>e.toolbar.alignJustify()}],Rt=[{icon:n.get("increaseIndent"),value:"increase",text:e=>e.toolbar.increaseIndent()},{icon:n.get("decreaseIndent"),value:"decrease",text:e=>e.toolbar.decreaseIndent()}],jt=[{icon:n.get("italic"),value:"italic",text:e=>e.toolbar.italic()},{icon:n.get("underline"),value:"underline",text:e=>e.toolbar.underline()},{icon:n.get("strikethrough"),value:"strikethrough",text:e=>e.toolbar.strikethrough()},{icon:n.get("superscript"),value:"superscript",text:e=>e.toolbar.superscript()},{icon:n.get("subscript"),value:"subscript",text:e=>e.toolbar.subscript()},{icon:n.get("code"),value:"code",text:e=>e.toolbar.code()}],qt=["#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"],Wt=[{icon:n.get("removeFormat"),value:"",text:e=>e.toolbar.removeColor()}];for(const e of qt)Wt.push({value:e.toLowerCase(),text:e.toUpperCase()});const Ut=new Map([["strong","bold"],["em","italic"],["i","italic"],["u","underline"],["s","strikethrough"],["sup","superscript"],["sub","subscript"],["code","code"]]),Kt=[{name:"undo",type:"button",icon:n.get("undo"),tooltip:e=>e.toolbar.undo(),onClick:(e,t)=>{e.command.execute(t)}},{name:"redo",type:"button",icon:n.get("redo"),tooltip:e=>e.toolbar.redo(),onClick:(e,t)=>{e.command.execute(t)}},{name:"selectAll",type:"button",icon:n.get("selectAll"),tooltip:e=>e.toolbar.selectAll(),onClick:(e,t)=>{e.command.execute(t)}},{name:"paragraph",type:"button",icon:n.get("paragraph"),tooltip:e=>e.toolbar.paragraph(),isSelected:e=>!!e.find((e=>"p"===e.name)),onClick:e=>{e.command.execute("heading","p")}},{name:"blockQuote",type:"button",icon:n.get("blockQuote"),tooltip:e=>e.toolbar.blockQuote(),onClick:(e,t)=>{e.command.execute(t)}},{name:"numberedList",type:"button",icon:n.get("numberedList"),tooltip:e=>e.toolbar.numberedList(),isSelected:e=>!!e.find((e=>"ol"===e.name)),onClick:e=>{e.command.execute("list","numbered")}},{name:"bulletedList",type:"button",icon:n.get("bulletedList"),tooltip:e=>e.toolbar.bulletedList(),isSelected:e=>!!e.find((e=>"ul"===e.name&&!e.node.hasAttr("type"))),onClick:e=>{e.command.execute("list","bulleted")}},{name:"checklist",type:"button",icon:n.get("checklist"),tooltip:e=>e.toolbar.checklist(),isSelected:e=>!!e.find((e=>"ul"===e.name&&"checklist"===e.node.attr("type"))),onClick:e=>{e.command.execute("list","checklist")}},{name:"alignLeft",type:"button",icon:n.get("alignLeft"),tooltip:e=>e.toolbar.alignLeft(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"left"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","left")}},{name:"alignCenter",type:"button",icon:n.get("alignCenter"),tooltip:e=>e.toolbar.alignCenter(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"center"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","center")}},{name:"alignRight",type:"button",icon:n.get("alignRight"),tooltip:e=>e.toolbar.alignRight(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"right"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","right")}},{name:"alignJustify",type:"button",icon:n.get("alignJustify"),tooltip:e=>e.toolbar.alignJustify(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"justify"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","justify")}},{name:"increaseIndent",type:"button",icon:n.get("increaseIndent"),tooltip:e=>e.toolbar.increaseIndent(),onClick:e=>{e.command.execute("indent","increase")}},{name:"decreaseIndent",type:"button",icon:n.get("decreaseIndent"),tooltip:e=>e.toolbar.decreaseIndent(),onClick:e=>{e.command.execute("indent","decrease")}},{name:"bold",type:"button",icon:n.get("bold"),tooltip:e=>e.toolbar.bold(),onClick:(e,t)=>{e.command.execute(t)}},{name:"italic",type:"button",icon:n.get("italic"),tooltip:e=>e.toolbar.italic(),onClick:(e,t)=>{e.command.execute(t)}},{name:"underline",type:"button",icon:n.get("underline"),tooltip:e=>e.toolbar.underline(),onClick:(e,t)=>{e.command.execute(t)}},{name:"strikethrough",type:"button",icon:n.get("strikethrough"),tooltip:e=>e.toolbar.strikethrough(),onClick:(e,t)=>{e.command.execute(t)}},{name:"superscript",type:"button",icon:n.get("superscript"),tooltip:e=>e.toolbar.superscript(),onClick:(e,t)=>{e.command.execute(t)}},{name:"subscript",type:"button",icon:n.get("subscript"),tooltip:e=>e.toolbar.subscript(),onClick:(e,t)=>{e.command.execute(t)}},{name:"code",type:"button",icon:n.get("code"),tooltip:e=>e.toolbar.code(),onClick:(e,t)=>{e.command.execute(t)}},{name:"removeFormat",type:"button",icon:n.get("removeFormat"),tooltip:e=>e.toolbar.removeFormat(),onClick:(e,t)=>{e.command.execute(t)}},{name:"formatPainter",type:"button",icon:n.get("formatPainter"),tooltip:e=>e.toolbar.formatPainter(),onClick:(e,t)=>{e.command.execute(t)}},{name:"link",type:"button",icon:n.get("link"),tooltip:e=>e.toolbar.link(),onClick:(e,t)=>{e.command.execute(t)}},{name:"hr",type:"button",icon:n.get("hr"),tooltip:e=>e.toolbar.hr(),onClick:(e,t)=>{e.command.execute(t)}},{name:"codeBlock",type:"button",icon:n.get("codeBlock"),tooltip:e=>e.toolbar.codeBlock(),onClick:(e,t)=>{e.command.execute(t)}},{name:"video",type:"button",icon:n.get("video"),tooltip:e=>e.toolbar.video(),onClick:(e,t)=>{e.command.execute(t)}},{name:"equation",type:"button",icon:n.get("equation"),tooltip:e=>e.toolbar.equation(),onClick:(e,t)=>{e.command.execute(t)}},{name:"heading",type:"dropdown",downIcon:n.get("down"),defaultValue:"p",tooltip:e=>e.toolbar.heading(),width:"100px",menuType:"list",menuItems:[{value:"h1",text:e=>`<span style="font-weight: bold; font-size: 26px;">${e.toolbar.heading1()}</span>`},{value:"h2",text:e=>`<span style="font-weight: bold; font-size: 24px;">${e.toolbar.heading2()}</span>`},{value:"h3",text:e=>`<span style="font-weight: bold; font-size: 22px;">${e.toolbar.heading3()}</span>`},{value:"h4",text:e=>`<span style="font-weight: bold; font-size: 20px;">${e.toolbar.heading4()}</span>`},{value:"h5",text:e=>`<span style="font-weight: bold; font-size: 18px;">${e.toolbar.heading5()}</span>`},{value:"h6",text:e=>`<span style="font-weight: bold; font-size: 16px;">${e.toolbar.heading6()}</span>`},{value:"p",text:e=>e.toolbar.paragraph()}],onSelect:(e,t)=>{e.command.execute("heading",t)}},{name:"list",type:"dropdown",downIcon:n.get("down"),icon:n.get("list"),tooltip:e=>e.toolbar.list(),menuType:"list",menuItems:Vt,onSelect:(e,t)=>{e.command.execute("list",t)}},{name:"align",type:"dropdown",downIcon:n.get("down"),icon:n.get("alignLeft"),tooltip:e=>e.toolbar.align(),menuType:"list",menuItems:Ft,onSelect:(e,t)=>{e.command.execute("align",t)}},{name:"indent",type:"dropdown",downIcon:n.get("down"),icon:n.get("increaseIndent"),tooltip:e=>e.toolbar.indent(),menuType:"list",menuItems:Rt,onSelect:(e,t)=>{e.command.execute("indent",t)}},{name:"fontFamily",type:"dropdown",downIcon:n.get("down"),defaultValue:"Segoe UI",tooltip:e=>e.toolbar.fontFamily(),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>'}],onSelect:(e,t)=>{e.command.execute("fontFamily",t)}},{name:"fontSize",type:"dropdown",downIcon:n.get("down"),defaultValue:"16px",tooltip:e=>e.toolbar.fontSize(),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"}],onSelect:(e,t)=>{e.command.execute("fontSize",t)}},{name:"moreStyle",type:"dropdown",icon:n.get("more"),tooltip:e=>e.toolbar.moreStyle(),menuType:"list",menuItems:jt,selectedValues:e=>{var t;const i=[];for(const n of e)if(n.node.isMark){const e=null!==(t=Ut.get(n.name))&&void 0!==t?t:n.name;i.push(e)}return i},onSelect:(e,t)=>{e.command.execute(t)}},{name:"fontColor",type:"dropdown",downIcon:n.get("down"),icon:n.get("fontColor"),accentIcon:n.get("fontColorAccent"),defaultValue:"#f5222d",tooltip:e=>e.toolbar.fontColor(),menuType:"color",menuItems:Wt,menuWidth:"296px",onSelect:(e,t)=>{e.command.execute("fontColor",t)}},{name:"highlight",type:"dropdown",downIcon:n.get("down"),icon:n.get("highlight"),accentIcon:n.get("highlightAccent"),defaultValue:"#fadb14",tooltip:e=>e.toolbar.highlight(),menuType:"color",menuItems:Wt,menuWidth:"296px",onSelect:(e,t)=>{e.command.execute("highlight",t)}},{name:"image",type:"upload",icon:n.get("image"),tooltip:e=>e.toolbar.image(),accept:"image/*",multiple:!0},{name:"file",type:"upload",icon:n.get("attachment"),tooltip:e=>e.toolbar.file(),accept:"*",multiple:!0}],Gt=["undo","redo","|","heading","|","formatPainter","removeFormat","bold","moreStyle","|","fontColor","highlight","|","align","list","indent","link","blockQuote","hr"],Xt=new Map;for(const e of Kt)Xt.set(e.name,e);var Qt={type:"block",name:"hr",render:e=>{const t=e.getEditor(),i=e.getContainer(),n=I('<div class="lake-hr"><hr /></div>');i.empty(),i.append(n),n.on("click",(()=>{t.selection.selectBox(e)}))},html:()=>"<hr />"};const Yt="#57606a",Jt="#444d56",ei="#953800",ti="#0550ae",ii="#444d56",ni="#24292e",si="#005cc5",oi="#0550ae",ri="#444d56",ai="#444d56",li="#0a3069",ci="#0550ae",di="#0550ae",hi="#116329",pi="#0550ae",ui="#cf222e",mi="#24292f",gi="#cf222e",fi="#57606a",vi="#57606a",wi="#8250df",yi="#0550ae",xi="#f6f8fa",bi="#cf222e",ki="#0550ae",Ci="#005cc5",Si="#444d56",Bi="#444d56";function _i(e){const{HighlightStyle:t,tags:i}=e;return t.define([{tag:[i.comment,i.lineComment,i.blockComment,i.docComment],color:Yt},{tag:[i.name],color:Jt},{tag:[i.variableName,i.self],color:ei},{tag:[i.typeName,i.tagName],color:ti},{tag:[i.propertyName,i.attributeName],color:ii},{tag:[i.className],color:ni},{tag:[i.labelName],color:si},{tag:[i.namespace],color:oi},{tag:[i.macroName],color:ri},{tag:[i.literal],color:ai},{tag:[i.string,i.docString,i.character,i.attributeValue,i.unit],color:li},{tag:[i.number,i.integer,i.float],color:ci},{tag:[i.bool,i.null,i.atom],color:di},{tag:[i.regexp,i.escape,i.url],color:hi},{tag:[i.color],color:pi},{tag:[i.keyword,i.operatorKeyword,i.controlKeyword,i.definitionKeyword,i.moduleKeyword],color:ui},{tag:[i.modifier],color:mi},{tag:[i.operator,i.derefOperator,i.arithmeticOperator,i.logicOperator,i.bitwiseOperator,i.compareOperator,i.updateOperator,i.definitionOperator,i.typeOperator,i.controlOperator],color:gi},{tag:[i.punctuation,i.separator,i.bracket,i.angleBracket,i.squareBracket,i.paren,i.brace,i.contentSeparator],color:fi},{tag:[i.content],color:vi},{tag:[i.meta,i.documentMeta,i.annotation,i.processingInstruction],color:wi},{tag:i.heading,fontWeight:"bold",color:yi},{tag:i.strong,fontWeight:"bold"},{tag:i.emphasis,fontStyle:"italic"},{tag:i.link,textDecoration:"underline"},{tag:i.strikethrough,textDecoration:"line-through"},{tag:[i.invalid,i.inserted,i.deleted,i.changed],color:xi},{tag:[i.definition(i.name)],color:bi},{tag:[i.constant(i.name)],color:ki},{tag:[i.function(i.variableName)],color:Ci},{tag:[i.standard(i.name)],color:Si},{tag:[i.special(i.variableName)],color:Bi}])}var Ai={type:"block",name:"codeBlock",render:e=>{var t;const i=e.getEditor(),s=I('<div class="lake-code-block" />'),o=e.getContainer();o.css("width",i.container.innerWidth()-2+"px"),o.empty(),o.append(s);const r=s.get(0);if(!r)return;const a=window.LakeCodeMirror;if(!a)return i.readonly?void e.node.hide():(s.addClass("lake-code-block-error"),s.text('\n The code cannot be displayed because window.LakeCodeMirror is not found.\n Please check if the "lake-codemirror" library is added to this page.\n '.trim()),void s.on("click",(()=>{i.selection.selectBox(e)})));const{EditorState:l,Compartment:c,EditorView:d,keymap:h,history:p,defaultKeymap:u,historyKeymap:m,indentWithTab:g,syntaxHighlighting:f}=a,v=a.langItems,w=i.config.codeBlock,y=v.filter((e=>w.langList.indexOf(e.value)>=0)),x=new Map;for(const e of y)x.set(e.value,e);const b=e.value,k=x.get(b.lang),C=new c,S=xt((t=>{i.selection.updateByRange(),i.isComposing||(e.updateValue("code",t),i.history.save())}),1,{immediate:!1}),B=d.updateListener.of((e=>{e.docChanged&&S(e.state.doc.toString())})),_=new d({parent:r,doc:null!==(t=b.code)&&void 0!==t?t:"",extensions:[l.readOnly.of(i.readonly),d.editable.of(!i.readonly),p(),h.of([...u,...m,g]),f(_i(a)),C.of(k&&k.component?k.component():[]),B]});s.find('[contenteditable="true"]').attr("tabindex","-1");const L=new He({root:s,name:"langType",downIcon:n.get("down"),defaultValue:k?b.lang:w.defaultLang,tooltip:i.locale.codeBlock.langType(),menuType:"list",menuHeight:"200px",menuItems:y.map((e=>({value:e.value,text:e.text}))),onSelect:t=>{e.updateValue({lang:t}),e.unmount(),e.render(),i.selection.selectBox(e),i.history.save()}});L.render();const T=()=>{o.css("width",i.container.innerWidth()-2+"px")};i.event.on("resize",T),s.on("click",(()=>{_.hasFocus||_.focus()})),e.event.on("beforeunmount",(()=>{L.unmount(),_.destroy(),i.event.off("resize",T),A("CodeMirror destroyed")}))}};function Li(e,t,i,n){return new(i||(i=Promise))((function(s,o){function r(e){try{l(n.next(e))}catch(e){o(e)}}function a(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}l((n=n.apply(e,t||[])).next())}))}
|
|
19
19
|
/*!
|
|
20
20
|
* PhotoSwipe Lightbox 5.4.4 - https://photoswipe.com
|
|
21
21
|
* (c) 2024 Dmytro Semenov
|