lakelib 0.1.21 → 0.1.22
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 +3 -3
- package/dist/lake.min.js.map +1 -1
- package/lib/lake.js +66 -73
- package/lib/lake.js.map +1 -1
- package/lib/types/editor.d.ts +1 -0
- package/package.json +1 -1
package/dist/lake.min.js
CHANGED
|
@@ -15,7 +15,7 @@ var Lake=function(t){"use strict";class e 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 Dt{constructor(t){if(this.event=new vt,"string"==typeof t){const e=wt.get(t);if(void 0===e)throw new Error(`The box "${t}" has not been defined yet.`);const i=r(e.type),n=r(e.name);this.node=I(a`<lake-box type="${i}" name="${n}"></lake-box>`),e.value&&(this.value=e.value)}else{this.node=I(t);const e=wt.get(this.name);if(void 0===e)throw new Error(`The box "${this.name}" has not been defined yet.`);e.value&&!this.node.hasAttr("value")&&(this.value=e.value)}}addFramework(){let t=this.getContainer();0===t.length?(this.node.html($t),t=this.getContainer()):(t.off("mouseenter"),t.off("mouseleave"),t.off("click")),t.on("mouseenter",(()=>{t.hasClass("lake-box-selected")||t.hasClass("lake-box-focused")||t.hasClass("lake-box-activated")||t.addClass("lake-box-hovered")})),t.on("mouseleave",(()=>{t.removeClass("lake-box-hovered")})),t.on("click",(()=>{A(`The box "${this.name}" (id = ${this.node.id}) value:`),A(this.value)})),"block"===this.type&&this.node.isContentEditable&&t.attr("draggable","true")}get type(){return this.node.attr("type")}get name(){return this.node.attr("name")}get value(){const t=this.node.attr("value");return""===t?{}:JSON.parse(h(t))}set value(t){this.node.attr("value",d(JSON.stringify(t)))}updateValue(t,e){const i=this.value;if("string"==typeof t)i[t]=e;else for(const e of Object.keys(t))i[e]=t[e];this.value=i}getEditor(){const t=this.node.closest("div[contenteditable]");return t.length>0?yt.get(t.id):void 0}getContainer(){return this.node.find(".lake-box-container")}setToolbar(t){const e=this.getEditor();let i=null;const n=()=>{i&&i.updatePosition()};this.event.on("focus",(()=>{i=new Ht({root:e?e.popupContainer:I(document.body),box:this,items:t,locale:e?e.locale:void 0}),i.render(),e&&e.root.on("scroll",n)})),this.event.on("blur",(()=>{i&&(i.unmount(),i=null),e&&e.root.off("scroll",n)}))}render(){const t=wt.get(this.name);if(void 0===t)return;this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.addFramework();const e=t.render(this);if(void 0!==e){const t=this.getContainer();t.empty(),t.append(e)}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 t=wt.get(this.name);return void 0===t?"":void 0===t.html?this.node.outerHTML():t.html(this)}}function Vt(t){const e=mt(0);if("string"==typeof t){const i=new Dt(t);return e.set(i.node.id,i),i}const i=(t=I(t)).closestContainer();if(0===i.length){let i=e.get(t.id);return i||(i=new Dt(t),e.set(t.id,i),i)}const n=mt(i.id);let s=e.get(t.id);return s?(n.set(t.id,s),e.delete(t.id),s):(s=n.get(t.id),s||(s=new Dt(t),n.set(t.id,s),s))}function Ft(t){const e=t.responseText||t.response;if(!e)return e;try{return JSON.parse(e)}catch(t){return e}}function Rt(t){const e=new XMLHttpRequest;t.onProgress&&e.upload&&(e.upload.onprogress=e=>{e.total>0&&(e.percent=e.loaded/e.total*100),t.onProgress&&t.onProgress(e)});const i=new FormData,n=t.data||{};Object.keys(n).forEach((t=>{const e=n[t];Array.isArray(e)?e.forEach((e=>{i.append(`${t}[]`,e)})):i.append(t,e)}));const s=t.filename||"file";t.file instanceof Blob?i.append(s,t.file,t.file.name):i.append(s,t.file),e.onerror=e=>{t.onError&&t.onError(e)},e.onload=()=>{if(e.status<200||e.status>=300){if(!t.onError)return;return t.onError(function(t,e){const i=`Cannot ${t.method} ${t.action} ${e.status}'`,n=new Error(i);return n.status=e.status,n.method=t.method,n.url=t.action,n}(t,e),Ft(e))}if(t.onSuccess)return t.onSuccess(Ft(e),e)},e.open(t.method,t.action,!0),t.withCredentials&&"withCredentials"in e&&(e.withCredentials=!0);const o=t.headers||{};return null!==o["X-Requested-With"]&&e.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(o).forEach((t=>{null!==o[t]&&e.setRequestHeader(t,o[t])})),e.send(i),e}function jt(t){const{editor:e,name:i,file:n,onError:s,onSuccess:o}=t,{requestMethod:r,requestAction:a,requestTypes:l}=e.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=e.selection.insertBox(i,{url:URL.createObjectURL(n),status:"uploading",name:n.name,size:n.size,type:n.type,lastModified:n.lastModified});let d=Rt({onProgress:t=>{const e=c.node.find(".lake-percent"),i=Math.round(t.percent);e.text(`${i<100?i:99} %`)},onError:(t,e)=>{d=null,A(t.toString(),e),c.updateValue("status","error"),c.render(),s&&s(t.toString())},onSuccess:t=>{if(d=null,!t.url)return c.updateValue("status","error"),c.render(),void(s&&s("Cannot find the url field."));c.updateValue({status:"done",url:t.url}),c.render(),e.history.save(),o&&o()},file:n,action:a,method:r});return c.event.on("beforeunmount",(()=>{d&&(d.abort(),A("Upload canceled"))})),c}var Wt=Object.freeze({__proto__:null,appendBreak:Z,camelCase:l,changeTagName:V,debug:A,denormalizeValue:g,encode:r,fileSize:w,fixNumberedList:F,fromBase64:h,getBox:Vt,getCSS:y,getDeepElement:H,inString:c,mergeNodes:z,modifierText:v,morph:ht,nodeAndView:pt,normalizeValue:f,parseStyle:m,query:I,removeBreak:N,removeZWS:D,request:Rt,safeTemplate:a,setBlockIndent:R,splitNodes:P,template:s,toBase64:d,toHex:u,toNodeList:x,uploadFile:jt,wrapNodeList:$});class qt{constructor(t){this.fragment=null!=t?t:document.createDocumentFragment()}get(){return this.fragment}find(t){const e=[];let i=new L(this.fragment.firstChild);for(;i.length>0;)i.matches(t)?e.push(i.get(0)):i.isElement&&i.find(t).each((t=>{e.push(t)})),i=i.next();return new L(e)}append(t){I(t).each((t=>{this.fragment.appendChild(t)}))}}const Ut={id:/^[\w-]+$/,class:/^[\w- ]+$/,style:{"text-align":["left","center","right","justify","start","end"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function Kt(){return{h1:Object.assign({},Ut),h2:Object.assign({},Ut),h3:Object.assign({},Ut),h4:Object.assign({},Ut),h5:Object.assign({},Ut),h6:Object.assign({},Ut),p:Object.assign({},Ut),blockquote:Object.assign(Object.assign({},Ut),{type:["info","tip","success","warning","error","danger"]}),ul:Object.assign(Object.assign({},Ut),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},Ut),{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 Gt{constructor(t,e=Kt()){this.rules=e,this.source="string"==typeof t?this.parseHTML(t):t}parseHTML(t){const e=(new DOMParser).parseFromString(t,"text/html");return new L(e.querySelector("body"))}static matchRule(t,e){return"string"==typeof t?t===e:Array.isArray(t)?t.indexOf(e)>=0:t instanceof RegExp&&t.test(e)}static getOpenTagString(t,e){let i=t.name,n=e[i];if(!n)return"";"string"==typeof n&&(i=n,n=e[i]);const s=t.get(0);if(!s.hasAttributes())return i;const o=new Map;for(const t of s.attributes)if(n[t.name]&&("style"!==t.name&&Gt.matchRule(n[t.name],t.value)&&o.set(t.name,t.value),"style"===t.name)){const e=n.style,i=new Map,s=m(t.value);for(const t of Object.keys(s)){const n=s[t];e[t]&&Gt.matchRule(e[t],n)&&i.set(t,n)}o.set("style",i)}let r=i;for(const[t,e]of o)if("style"===t){let t="";for(const[i,n]of e)t+=`${i}: ${n.replace(/"/g,""")}; `;""!==t&&(r+=` style="${t.trim()}"`)}else r+=` ${t}="${e}"`;return r}static getClosedTagString(t,e){let i=t.name;const n=e[i];return n?("string"==typeof n&&(i=n),i):""}static getTrimmedText(t){const e=t.parent(),i=t.prev(),n=t.next();let s=t.text();return(i.isBlock||i.isBlockBox)&&(n.isBlock||n.isBlockBox)||0===i.length&&0===n.length&&e.isBlock?s=s.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):i.isBlock||i.isBlockBox||0===i.length&&e.isBlock?s=s.replace(/^[\u0020\t\r\n]+/,""):(n.isBlock||n.isBlockBox||0===n.length&&e.isBlock)&&(s=s.replace(/[\u0020\t\r\n]+$/,"")),s}getHTML(){const t=this.rules;let e="";for(const i of function*e(i){let n=i.first();for(;n.length>0;){const i=n.next();if(n.isText)yield r(Gt.getTrimmedText(n));else if(n.isVoid){const e=Gt.getOpenTagString(n,t);""!==e&&(yield`<${e} />`)}else if(n.isElement){const i=Gt.getOpenTagString(n,t),s=Gt.getClosedTagString(n,t);""!==i&&(yield`<${i}>`),n.isBox||(yield*e(n)),""!==s&&(yield`</${s}>`)}n=i}}(this.source))e+=i;return e.trim()}getFragment(){const t=this.getHTML(),e=this.parseHTML(t),i=document.createDocumentFragment();let n=e.first();for(;n.length>0;){const t=n.next();i.appendChild(n.get(0)),n=t}return i}}class Xt{constructor(t){this.content=t}getHTML(){let t=this.content;return t=t.replace(/ {2}/g," "),t=r(t.trim()),t=`<p>${t}</p>`,t=t.replace(/(\r\n){2,}/g,"</p><p><br /></p><p>"),t=t.replace(/\r\n/g,"</p><p>"),t=t.replace(/[\r\n]{2,}/g,"</p><p><br /></p><p>"),t=t.replace(/[\r\n]/g,"</p><p>"),t}getFragment(){return new Gt(this.getHTML()).getFragment()}}function Yt(t,e){if(t.commonAncestor.isOutside)return;const i=(e=I(e)).get(0),n=t.get();n.insertNode(i),n.setEndAfter(i),n.collapse(!1)}function Jt(t){if(t.commonAncestor.isOutside)return{anchor:new L,focus:new L};const e=t.startNode.closest("lake-box");if(e.length>0)return t.isBoxStart?e.attr("focus","start"):t.isBoxEnd?e.attr("focus","end"):e.attr("focus","center"),{anchor:new L,focus:e};if(t.isCollapsed){const e=t.clone();e.collapseToEnd();const i=I('<lake-bookmark type="focus" />');return Yt(e,i),{anchor:new L,focus:i}}const i=t.clone();i.collapseToStart();const n=I('<lake-bookmark type="anchor" />');Yt(i,n);const s=t.clone();s.collapseToEnd();const o=I('<lake-bookmark type="focus" />');return Yt(s,o),{anchor:n,focus:o}}function Qt(t,e){const i=t.prev(),n=t.next();if(i.isText||n.isText){const e=t.parent();t.remove(),e.get(0).normalize()}else if(0===i.length&&0===n.length){if(t.parent().isMark&&e){const i=new L(document.createTextNode(""));t.before(i),e.setStartAfter(i),e.collapseToStart()}t.remove()}else t.remove()}function te(t,e){const i=e.anchor,n=e.focus;if(i.length>0&&0===n.length)Qt(i);else{if(n.length>0&&0===i.length){if(n.isBox){const e=Vt(n);0===e.getContainer().length&&e.render();const i=n.attr("focus");return"start"===i?t.selectBoxStart(n):"center"===i?t.selectBox(n):t.selectBoxEnd(n),void n.removeAttr("focus")}return t.setStartBefore(n),t.collapseToStart(),void Qt(n,t)}if(i.length>0&&n.length>0){const e=new M;e.selectNode(i),e.collapseToEnd(),-1===e.compareAfterNode(n)?(t.setStartBefore(n),Qt(n),t.setEndBefore(i),Qt(i)):(t.setStartBefore(i),Qt(i),t.setEndBefore(n),Qt(n))}}}function ee(t){if(t.commonAncestor.isOutside)return;F(t.getBlocks())}function ie(t){if(t.isCollapsed)return;if(t.adjustBox(),t.adjustTable(),t.isInoperative)return;const e=t.startNode.closestBlock(),i=t.endNode.closestBlock(),n=e.get(0)===i.get(0);if(t.get().deleteContents(),t.adjustBlock(),n){const e=t.getBlocks()[0];if(e&&e.isEmpty){const i=Z(e);t.setStartBefore(i),t.collapseToStart()}return}const s=t.getBlocks()[0];if(!s)return;const o=s.prev();if(0===o.length)return;const r=Jt(t);z(o,s),te(t,r),ee(t)}function ne(t,e){if(e instanceof qt&&(e=e.get()),t.commonAncestor.isOutside)return;t.isCollapsed?t.adjustBox():ie(t);N(t.startNode.closestBlock());const i=Jt(t);i.focus.before(e),te(t,i),t.adjustBlock()}function se(t,e){if(t.commonAncestor.isOutside)return;if(t.isCollapsed){if(t.commonAncestor.closest("lake-box").isBlockBox)return}if("string"!=typeof e){const i=t.getBlocks();for(const t of i)t.css(e);return}const i=I(e),n=i.name,s=i.get(0).attributes,o=t.getBlocks();if(o.length>0){const e=Jt(t);for(const t of o)if(t.name===n&&0===i.first().length)for(const e of s)t.attr(e.name,e.value);else{const e=i.clone(!0);e.isList&&t.isList&&""!==t.attr("indent")&&e.attr("indent",t.attr("indent"));const n=H(e);let s=t.first();for(;s.length>0;){const t=s.next();n.append(s),n.name!==s.name&&"li"!==s.name||s.remove(!0),s=t}t.replaceWith(e)}return te(t,e),void ee(t)}const r=Jt(t),a=function(t){const e=t.commonAncestor.closest('div[contenteditable="true"],td');let i=[];if(0===e.length)return i;let n=e.first(),s=!0;for(;n.length>0;){if(n.isMark||n.isText||n.isBookmark||n.isInlineBox)i.push(n);else{if(!s)break;i=[]}t.intersectsNode(n)&&(s=!1),n=n.next()}return i}(t),l=$(a,i);if(te(t,r),ee(t),l.isEmpty){const e=Z(l);t.setStartBefore(e),t.collapseToStart()}}function oe(t){if(t.commonAncestor.isOutside)return{start:null,end:null};t.isCollapsed?t.adjustBox():ie(t);const e=t.startNode,i=e.closestOperableBlock();if(0===i.length)return{start:null,end:null};let n=i.parent();n.isOutside&&(n=e.closestContainer());const s=P(e,t.startOffset,n);let o=null,r=null;return s&&(o=s.start,r=s.end),!s&&e.isBlock&&(t.startOffset>0&&(o=e.children()[t.startOffset-1]),r=e.children()[t.startOffset],r&&!r.isBlock&&(r=null)),o&&o.isEmpty&&Z(o),r&&(r.isEmpty&&Z(r),t.shrinkBefore(r)),ee(t),{start:o,end:r}}function re(t){if(t.isMark&&t.isEmpty)t.remove();else for(const e of t.getWalker())e.isMark&&e.isEmpty&&e.remove()}function ae(t,e,i){let n=null,s=null,o=t.closestBlock();0===o.length&&(o=t.closestContainer());const r=P(t,e,o);return r&&(i?(re(r.start),re(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 le(t,e=!0){if(t.commonAncestor.isOutside)return{start:null,center:null,end:null};if(t.adjustBox(),t.isCollapsed){const i=ae(t.startNode,t.startOffset,e);return i.start?(t.setStartAfter(i.start),t.collapseToStart()):i.end&&(t.setStartBefore(i.end),t.collapseToStart()),{start:i.start,center:null,end:i.end}}const i=ae(t.startNode,t.startOffset,e);i.start?t.setStartAfter(i.start):i.end&&t.setStartBefore(i.end);const n=ae(t.endNode,t.endOffset,e);return n.start?t.setEndAfter(n.start):n.end&&t.setEndBefore(n.end),{start:i.start,center:n.start,end:n.end}}function ce(t,e){const i=t.text();let n=t;for(;n.length>0;){const t=n.parent();if(!t.isMark||i!==t.text()||!n.isText&&n.name===e&&""!==n.attr("style"))break;n=t}return n}function de(t,e){if(t.commonAncestor.isOutside)return;let i=I(e);const n=i.name,s=m(i.attr("style"));if(t.isCollapsed){if(t.isBox){const e=t.startNode.closest("lake-box");if("block"===Vt(e).type){const i=I("<p><br /></p>");t.isBoxStart?e.before(i):e.after(i),t.shrinkAfter(i)}else t.adjustBox()}N(t.startNode.closestBlock());const e=new L(document.createTextNode("")),o=le(t);if(o.start){const t=function(t){if(!t.isMark)return null;let e=t.clone(),i=t.last();for(;i.length>0;){if(i.isMark){const t=i.clone();e.append(t),e=t}i=i.last()}return e}(o.start);if(t)if(t.name===n)t.css(s),i=t;else{H(t).append(e),i.append(t)}}return""===i.text()&&i.append(e),Yt(t,i),function(t){const e=t.prev();e.length>0&&e.isText&&e.isEmpty&&e.remove();const i=t.next();i.length>0&&i.isText&&i.isEmpty&&i.remove()}(i),void t.shrinkAfter(i)}le(t);const o=t.getMarks(!0),r=Jt(t);for(const t of o)if(!t.isEmpty&&t.isText){const e=ce(t,n);if(e.isMark&&e.name===n)e.css(s);else{const t=i.clone();e.before(t),t.append(e)}}te(t,r)}function he(t){if(t.isMark&&t.isEmpty)t.remove();else for(const e of t.getWalker())e.isMark&&e.isEmpty&&e.remove()}function pe(t,e){if(t.commonAncestor.isOutside)return;let i;if(e){i=I(e).name}if(t.isCollapsed){if(t.isBox)return;if(i&&0===t.commonAncestor.closest(i).length)return;const e=le(t,!1);if(!e.start)return;e.end&&he(e.end);const n=new L(document.createTextNode("")),s=function(t,e){if(!t.isMark||!e)return null;let i=t.clone(),n=t.last();for(;n.length>0;){if(n.isMark&&n.name!==e){const t=n.clone();i.append(t),i=t}n=n.last()}if(i.name===e){if(!(i.first().length>0))return null;i=i.first()}return i}(e.start,i);if(!s)return e.start.after(n),he(e.start),n.prev().isText?(t.setStartAfter(n.prev()),t.collapseToStart(),void n.remove()):(t.setStartAfter(n),void t.collapseToStart());return H(s).append(n),e.start.after(s),he(e.start),void t.shrinkAfter(s)}le(t);const n=t.getMarks(),s=Jt(t);for(const t of n)if(!i||t.name===i){const e=t.parent();t.remove(!t.isEmpty),e.length>0&&e.get(0).normalize()}D(t.commonAncestor),te(t,s)}function ue(t,e){if(t.commonAncestor.isOutside)return null;const i=I(e);if(t.isCollapsed){let e=t.commonAncestor.closest("a");if(0===e.length){e=i.clone(!0);return N(t.startNode.closestBlock()),Yt(t,e),e}return""!==i.attr("href")&&e.attr({href:i.attr("href")}),e}le(t);const n=Jt(t);for(const e of t.commonAncestor.getWalker())"a"===e.name&&t.intersectsNode(e)&&e.remove(!0);const s=i.clone(!1);n.anchor.after(s);let o=s.next();for(;o.length>0;){const t=o.next();if(!o.isMark&&!o.isText)break;s.append(o),o=t}return 0===s.first().length&&s.remove(),te(t,n),s}function me(t,e,i){if(t.commonAncestor.isOutside)return null;const n=Vt(e);i&&(n.value=i);const s=document.createDocumentFragment();if(s.appendChild(n.node.get(0)),"inline"===n.type)return ne(t,s),n.render(),t.selectBoxEnd(n.node),Vt(n.node);const o=oe(t);return o.start&&(t.setEndAfter(o.start),t.collapseToEnd()),o.end&&o.end.isEmpty&&o.end.remove(),ne(t,s),n.render(),t.selectBoxEnd(n.node),o.start&&o.start.isEmpty&&o.start.remove(),Vt(n.node)}function fe(t){const e=t.node.closestContainer();if(t.unmount(),t.node.remove(),e.length>0){mt(e.id).delete(t.node.id);mt(0).set(t.node.id,t)}return t}function ge(t){if(t.commonAncestor.isOutside)return null;const e=t.commonAncestor.closest("lake-box");if(0===e.length)return null;const i=Vt(e);if("block"===i.type){const n=I("<p><br /></p>");return e.before(n),t.shrinkAfter(n),fe(i)}t.setStartBefore(e),t.collapseToStart();const n=e.parent();if(fe(i),n.isEmpty){const e=Z(n);t.setStartBefore(e),t.collapseToStart()}return i}var ve={exports:{}};function we(t,e=100,i={}){if("function"!=typeof t)throw new TypeError(`Expected the first parameter to be a function, got \`${typeof t}\`.`);if(e<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 e=s,i=o;return s=void 0,o=void 0,l=t.apply(e,i),l}function d(){const t=Date.now()-a;t<e&&t>=0?r=setTimeout(d,e-t):(r=void 0,n||(l=c()))}const h=function(...t){if(s&&this!==s)throw new Error("Debounced method called with different contexts.");s=this,o=t,a=Date.now();const i=n&&!r;return r||(r=setTimeout(d,e)),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}ve.exports.debounce=we,ve.exports=we;var ye=ft(ve.exports),xe=ft((function t(e,i){if(e===i)return!0;if(e&&i&&"object"==typeof e&&"object"==typeof i){if(e.constructor!==i.constructor)return!1;var n,s,o;if(Array.isArray(e)){if((n=e.length)!=i.length)return!1;for(s=n;0!=s--;)if(!t(e[s],i[s]))return!1;return!0}if(e instanceof Map&&i instanceof Map){if(e.size!==i.size)return!1;for(s of e.entries())if(!i.has(s[0]))return!1;for(s of e.entries())if(!t(s[1],i.get(s[0])))return!1;return!0}if(e instanceof Set&&i instanceof Set){if(e.size!==i.size)return!1;for(s of e.entries())if(!i.has(s[0]))return!1;return!0}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(i)){if((n=e.length)!=i.length)return!1;for(s=n;0!=s--;)if(e[s]!==i[s])return!1;return!0}if(e.constructor===RegExp)return e.source===i.source&&e.flags===i.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===i.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===i.toString();if((n=(o=Object.keys(e)).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(!t(e[r],i[r]))return!1}return!0}return e!=e&&i!=i}));function be(t){const e=t.get(0),i={};if(e.hasAttributes())for(const t of e.attributes)i[t.name]=t.value;return i}class ke{constructor(t){const e=window.getSelection();if(!e)throw new Error("Selection object is null.");this.selection=e,this.container=t,this.range=this.getRangeFromNativeSelection()}getRangeFromNativeSelection(){if(this.selection.rangeCount>0){const t=this.selection.getRangeAt(0);return new M(t)}return new M}sync(){this.selection.removeAllRanges(),this.selection.addRange(this.range.get())}updateByRange(){const t=this.getRangeFromNativeSelection();this.container.contains(t.commonAncestor)&&(this.range.startNode.get(0)===t.startNode.get(0)&&this.range.startOffset===t.startOffset&&this.range.endNode.get(0)===t.endNode.get(0)&&this.range.endOffset===t.endOffset||(this.range=t))}updateByBookmark(){const t=this.range,e=this.container,i=e.find("lake-box[focus]");if(i.length>0)return te(t,{anchor:new L,focus:i}),void this.sync();te(t,{anchor:e.find('lake-bookmark[type="anchor"]'),focus:e.find('lake-bookmark[type="focus"]')}),this.sync()}getAppliedItems(){const t=[];return function(t,e){let i=e.startNode;for(i.isText&&(i=i.parent());i.length>0&&i.isInside;)t.push({node:i,name:i.name,attributes:be(i),styles:m(i.attr("style"))}),i=i.parent()}(t,this.range),function(t,e){const i=e.startNode;let n;if(i.isText&&i.text().length===e.startOffset){const t=i.next();t.length>0&&t.isElement&&(n=t)}if(i.isElement){const t=i.children();if(t.length>0){const i=t[e.startOffset];i&&i.isElement&&(n=i)}}if(n){let e=n;for(;e.length>0;)e.isElement&&t.push({node:e,name:e.name,attributes:be(e),styles:m(e.attr("style"))}),e=e.first()}}(t,this.range),t}insertBookmark(){return Jt(this.range)}toBookmark(t){return te(this.range,t)}insertNode(t){return Yt(this.range,t)}insertFragment(t){return ne(this.range,t)}deleteContents(){return ie(this.range)}setBlocks(t){return se(this.range,t)}splitBlock(){return oe(this.range)}splitMarks(t){return le(this.range,t)}addMark(t){return de(this.range,t)}removeMark(t){return pe(this.range,t)}fixList(){return ee(this.range)}insertLink(t){return ue(this.range,t)}selectBox(t){let e=t;e=t instanceof Dt?t.node:t,this.range.selectBox(e)}insertBox(t,e){const i=me(this.range,t,e);if(!i)throw new Error(`The box "${t}" cannot be inserted outside the editor.`);return i}removeBox(t=null){return t&&this.selectBox(t),ge(this.range)}}class Se{constructor(t){this.commandMap=new Map,this.selection=t}add(t,e){this.commandMap.set(t,e)}delete(t){this.commandMap.delete(t)}getNames(){return Array.from(this.commandMap.keys())}has(t){return void 0!==this.commandMap.get(t)}getItem(t){const e=this.commandMap.get(t);if(void 0===e)throw new Error(`Command "${t}" has not been defined yet.`);return e}isDisabled(t){const e=this.getItem(t);if(!e.isDisabled)return!1;const i=this.selection.getAppliedItems();return e.isDisabled(i)}isSelected(t){const e=this.getItem(t);if(!e.isSelected)return!1;const i=this.selection.getAppliedItems();return e.isSelected(i)}selectedValues(t){const e=this.getItem(t);if(!e.selectedValues)return[];const i=this.selection.getAppliedItems();return e.selectedValues(i)}execute(t,...e){this.getItem(t).execute.apply(this,e),A(`Command "${t}" executed`)}}class Ce{constructor(t){this.canSave=!0,this.list=[],this.index=0,this.limit=100,this.event=new vt,this.selection=t,this.container=t.container}removeBookmark(t){return t.replace(/(<lake-box[^>]+)\s+focus="\w+"([^>]*>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"")}getValue(t){return new Gt(t).getHTML()}addIdToBoxes(t){t.find("lake-box").each((t=>{const e=new L(t),i=`${e.attr("name")}-${e.attr("value")}`;e.attr("id",i)}))}removeIdfromBoxes(t){t.find("lake-box").each((t=>{new L(t).removeAttr("id")}))}morphContainer(t){const e=this.container,i={beforeChildrenUpdated:t=>{if("lake-box"===new L(t).name)return!1},afterAttributeUpdated:(t,i)=>{const n=new L(i);if(["name","value"].indexOf(t)>=0&&"lake-box"===n.name){Vt(n).unmount();mt(e.id).delete(n.id)}}},n=t.clone(!0);this.addIdToBoxes(e),this.addIdToBoxes(n),ht(e,n,{callbacks:i}),this.removeIdfromBoxes(e),this.removeIdfromBoxes(n)}get canUndo(){return this.index>1&&!!this.list[this.index-2]}get canRedo(){return!!this.list[this.index]}cloneContainer(){const t=this.selection.range,e=this.container.clone(!0);if(e.find("lake-box").each((t=>{Vt(t).getContainer().empty()})),!this.container.contains(t.commonAncestor))return e;if(t.isInsideBox){const i=t.commonAncestor.closest("lake-box").path(),n=e.find(i),s=t.clone();return s.selectBox(n),Jt(s),e}const i=t.startNode.path(),n=t.endNode.path(),s=e.find(i),o=e.find(n),r=t.clone();return r.setStart(s,t.startOffset),r.setEnd(o,t.endOffset),Jt(r),e}undo(){if(!this.list[this.index-2])return;this.selection.insertBookmark();const t=this.getValue(this.container);for(;this.index>1;){const e=this.list[this.index-2];if(!e)break;this.index--;const i=this.getValue(e);if(this.removeBookmark(i)!==this.removeBookmark(t)){this.morphContainer(e),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 t=this.getValue(this.container);for(;this.index<this.list.length;){const e=this.list[this.index];if(!e)break;this.index++;const i=this.getValue(e);if(this.removeBookmark(i)!==this.removeBookmark(t)){this.morphContainer(e),this.event.emit("redo",i);break}}this.selection.updateByBookmark(),A(`History redone (index: ${this.index})`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(t={}){var e,i,n;const s=null!==(e=t.inputType)&&void 0!==e?e:"",o=null!==(i=t.update)&&void 0!==i&&i,r=null===(n=t.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",g(l),{inputType:s,update:o,emitEvent:r}))}}var _e={};Object.defineProperty(_e,"__esModule",{value:!0});for(var Be="undefined"!=typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.platform),Ae={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},Te={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:Be?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},Ee={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},Le=1;Le<20;Le++)Ee["f"+Le]=111+Le;function Ie(t,e,i){e&&!("byKey"in e)&&(i=e,e=null),Array.isArray(t)||(t=[t]);var n=t.map((function(t){return Me(t,e)})),s=function(t){return n.some((function(e){return Pe(e,t)}))};return null==i?s:s(i)}function Me(t,e){var i=e&&e.byKey,n={},s=(t=t.replace("++","+add")).split("+"),o=s.length;for(var r in Ae)n[Ae[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=Ne(p),f=Ae[m];if(p.length>1&&!f&&!Te[p]&&!Ee[m])throw new TypeError('Unknown modifier: "'+p+'"');1!==o&&f||(i?n.key=m:n.which=Ze(p)),f&&(n[f]=!u||null)}}catch(t){l=!0,c=t}finally{try{!a&&h.return&&h.return()}finally{if(l)throw c}}return n}function Pe(t,e){for(var i in t){var n=t[i],s=void 0;if(null!=n&&((null!=(s="key"===i&&null!=e.key?e.key.toLowerCase():"which"===i?91===n&&93===e.which?91:e.which:e[i])||!1!==n)&&s!==n))return!1}return!0}function Ze(t){return t=Ne(t),Ee[t]||t.toUpperCase().charCodeAt(0)}function Ne(t){return t=t.toLowerCase(),t=Te[t]||t}_e.default=Ie,_e.isHotkey=Ie,_e.isCodeHotkey=function(t,e){return Ie(t,e)};var Oe=_e.isKeyHotkey=function(t,e){return Ie(t,{byKey:!0},e)};_e.parseHotkey=Me,_e.compareHotkey=Pe,_e.toKeyCode=Ze,_e.toKeyName=Ne;const ze=new Map([["arrow-left","left"],["arrow-right","right"],["arrow-up","up"],["arrow-down","down"]]);class He{constructor(t){this.keydownEventList=[],this.keyupEventList=[],this.container=t,this.container.on("keydown",(t=>{const e=t;if(!e.isComposing)for(const t of this.keydownEventList)if(Oe(t.type,e)&&!1===t.listener(e))break})),this.container.on("keyup",(t=>{const e=t;if(!e.isComposing)for(const t of this.keyupEventList)if(Oe(t.type,e)&&!1===t.listener(e))break}))}normalizeType(t){var e;return t=null!==(e=ze.get(t))&&void 0!==e?e:t}setKeydown(t,e){t=this.normalizeType(t),this.keydownEventList.push({type:t,listener:e})}setKeyup(t,e){t=this.normalizeType(t),this.keyupEventList.push({type:t,listener:e})}keydown(t){t=this.normalizeType(t);for(const e of this.keydownEventList)if(e.type===t&&!1===e.listener(new KeyboardEvent(t)))break}keyup(t){t=this.normalizeType(t);for(const e of this.keyupEventList)if(e.type===t&&!1===e.listener(new KeyboardEvent(t)))break}}const $e={value:"<p><br /></p>",readonly:!1,spellcheck:!1,tabIndex:0,placeholder:"",indentWithTab:!0,lang:"en-US",minChangeSize:5,historySize:100,onMessage:(t,e)=>{"success"!==t?"warning"!==t?"error"===t&&console.error(e):console.warn(e):console.log(e)}};class De{constructor(t){if(this.unsavedInputData="",this.unsavedInputCount=0,this.state={appliedItems:[],disabledNameMap:new Map,selectedNameMap:new Map,selectedValuesMap:new Map},this.isComposing=!1,this.event=new vt,this.box=De.box,this.copyListener=t=>{const e=this.selection.range;this.container.contains(e.commonAncestor)&&this.event.emit("copy",t)},this.cutListener=t=>{const e=this.selection.range;this.container.contains(e.commonAncestor)&&this.event.emit("cut",t)},this.pasteListener=t=>{const e=this.selection.range;this.container.contains(e.commonAncestor)&&this.event.emit("paste",t)},this.selectionchangeListener=()=>{this.updateSelectionRange(),this.updateBoxSelectionStyle(),this.emitStateChangeEvent()},this.clickListener=t=>{const e=new L(t.target);!e.get(0).isConnected||e.closest(".lake-popup").length>0||this.event.emit("click",e)},this.resizeListener=()=>{this.event.emit("resize")},this.updateSelectionRange=ye((()=>{this.selection.updateByRange()}),1,{immediate:!0}),this.updateBoxSelectionStyle=ye((()=>{if(0===this.root.first().length)return;const t=this.selection.range,e=t.clone();e.adjustBox(),this.container.find("lake-box").each((i=>{const n=Vt(i),s=n.getContainer();if(0!==s.length){if(t.compareBeforeNode(s)<0&&t.compareAfterNode(s)>0&&(!t.isCollapsed||t.startNode.get(0)!==s.get(0)||0!==t.startOffset))return s.removeClass("lake-box-hovered"),s.removeClass("lake-box-selected"),s.removeClass("lake-box-focused"),s.addClass("lake-box-activated"),void n.event.emit("focus");if(e.intersectsNode(n.node))return s.removeClass("lake-box-activated"),void(t.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=ye((()=>{const t=this.command.getNames();let e=this.selection.getAppliedItems();e.length>0&&!this.container.contains(e[0].node)&&(e=[]);const i=new Map,n=new Map,s=new Map;if(e.length>0)for(const o of t){const t=this.command.getItem(o);if(t.isDisabled&&t.isDisabled(e)&&i.set(o,!0),t.isSelected&&t.isSelected(e)&&n.set(o,!0),t.selectedValues){const i=t.selectedValues(e);i.length>0&&s.set(o,i)}}const o={appliedItems:e,disabledNameMap:i,selectedNameMap:n,selectedValuesMap:s};xe(o,this.state)||(this.toolbar&&this.toolbar.updateState(o),this.event.emit("statechange",o),this.state=o)}),50,{immediate:!1}),!t.root)throw new Error("The root of the config must be specified.");this.root=I(t.root),this.toolbar=t.toolbar,this.config=Object.assign({},$e);for(const e of Object.keys(t))this.config[e]=t[e];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 ke(this.container),this.command=new Se(this.selection),this.history=new Ce(this.selection),this.history.limit=this.config.historySize,this.keystroke=new He(this.container),yt.set(this.container.id,this)}togglePlaceholderClass(t){const e="lake-placeholder";"<p><br /></p>"===(t=g(t)).replace("<focus />","")?this.container.addClass(e):this.container.removeClass(e)}moveBoxStripText(){const t=this.selection,e=t.range,i=e.startNode.closest(".lake-box-strip"),n=i.closest("lake-box");if("inline"===Vt(n).type)e.isBoxStart?(e.setStartBefore(n),e.collapseToStart()):(e.setStartAfter(n),e.collapseToStart());else{const t=I("<p />");e.isBoxStart?n.before(t):n.after(t),e.setStart(t,0),e.collapseToStart()}const s=i.text();i.html("<br />"),t.insertNode(document.createTextNode(s))}resetUnsavedInputData(){this.unsavedInputData="",this.unsavedInputCount=0}bindInputEvents(){this.container.on("compositionstart",(()=>{this.isComposing=!0})),this.container.on("compositionend",(()=>{this.isComposing=!1})),this.container.on("input",(t=>{const e=t;window.setTimeout((()=>{var t;const i=this.selection.range;if(!i.isInsideBox){if(this.isComposing)return"insertCompositionText"===e.inputType&&this.container.removeClass("lake-placeholder"),void this.event.emit("input",e);if(i.isBoxStart||i.isBoxEnd)return this.moveBoxStripText(),this.history.save(),void this.event.emit("input",e);if("insertText"===e.inputType||"insertCompositionText"===e.inputType)return this.unsavedInputData+=null!==(t=e.data)&&void 0!==t?t:"",this.unsavedInputCount++,this.unsavedInputData.length<this.config.minChangeSize?this.history.save({inputType:"insertText",update:this.unsavedInputCount>1}):(this.history.save({inputType:"insertText",update:!0}),this.resetUnsavedInputData()),void this.event.emit("input",e);this.history.save(),this.event.emit("input",e)}}),0)}))}bindHistoryEvents(){const t=t=>{this.fixContent()&&(this.history.save({update:!0,emitEvent:!1}),t=this.getValue()),this.emitStateChangeEvent(),this.togglePlaceholderClass(t),this.scrollToCaret(),this.event.emit("change",t)};this.history.event.on("undo",(e=>{this.renderBoxes(),t(e),this.resetUnsavedInputData()})),this.history.event.on("redo",(e=>{this.renderBoxes(),t(e),this.resetUnsavedInputData()})),this.history.event.on("save",((e,i)=>{this.removeBoxGarbage(),t(e),this.selection.sync(),"insertText"!==i.inputType&&this.resetUnsavedInputData()}))}get hasFocus(){const t=document.activeElement;return!!t&&I(t).closest(".lake-container").get(0)===this.container.get(0)}get locale(){return Ot(this.config.lang)}fixContent(){const t=this.selection.range;let e=!1,i=this.container.children();for(const t of i)(t.isBlock||t.isMark)&&""===t.html()&&(t.remove(),e=!0,A(`Content fixed: empty tag "${t.name}" was removed`));if(i=this.container.children(),0===i.length)this.container.html("<p><br /></p>"),t.shrinkBefore(this.container),e=!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),t.shrinkAfter(i),e=!0,A(`Content fixed: void element "${n.name}" was wrapped in paragraph`)}}return t.adjustBr(),e}setPluginConfig(t,e){this.config[t]||(this.config[t]={});for(const i of Object.keys(e))void 0===this.config[t][i]&&(this.config[t][i]=e[i])}removeBoxGarbage(){const t=mt(this.container.id);for(const e of t.values())e.node.get(0).isConnected||(e.unmount(),t.delete(e.node.id))}renderBoxes(){this.removeBoxGarbage();const t=this.container,e=mt(t.id);t.find("lake-box").each((t=>{const i=I(t);if(e.get(i.id))return;Vt(i).render()}))}focus(){this.container.focus()}blur(){this.container.blur()}scrollToCaret(){const t=this.selection.range;if(t.isBox)return;const e=t.getRect();if(0===e.x||0===e.y)return;const i=this.container.get(0).getBoundingClientRect(),n=I('<div class="lake-artificial-caret" />'),s=e.x-i.x,o=e.y-i.y;n.css({position:"absolute",top:`${o}px`,left:`${s}px`,width:`${e.width}px`,height:`${e.height}px`,"z-index":"-1"}),this.overlayContainer.find(".lake-artificial-caret").remove(),this.overlayContainer.append(n);const r=pt(n);(r.left<0||r.right<0||r.top<0||r.bottom<0)&&n.get(0).scrollIntoView({behavior:"instant",block:"center",inline:"nearest"}),n.remove()}setValue(t){t=f(t);const e=new Gt(t),i=e.getFragment();this.container.empty(),this.togglePlaceholderClass(e.getHTML()),this.container.append(i),this.renderBoxes(),this.selection.updateByBookmark()}getValue(){const t=this.history.cloneContainer();let e=new Gt(t).getHTML();return e=g(e),e}render(){const t=f(this.config.value),e=new Gt(t),i=e.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(e.getHTML()),this.container.append(i),De.plugin.loadAll(this),this.readonly||(this.selection.updateByBookmark(),this.history.save({emitEvent:!1})),this.renderBoxes(),this.toolbar&&this.toolbar.render(this),document.addEventListener("copy",this.copyListener),this.readonly||(document.addEventListener("cut",this.cutListener),document.addEventListener("paste",this.pasteListener),document.addEventListener("selectionchange",this.selectionchangeListener),document.addEventListener("click",this.clickListener),window.addEventListener("resize",this.resizeListener),this.bindInputEvents(),this.bindHistoryEvents())}unmount(){this.event.removeAllListeners(),this.history.event.removeAllListeners(),this.root.empty(),this.popupContainer.remove(),document.removeEventListener("copy",this.copyListener),this.readonly||(document.removeEventListener("cut",this.cutListener),document.removeEventListener("paste",this.pasteListener),document.removeEventListener("selectionchange",this.selectionchangeListener),document.removeEventListener("click",this.clickListener),window.removeEventListener("resize",this.resizeListener))}}De.version="0.1.21",De.box=new class{add(t){wt.set(t.name,t)}remove(t){wt.delete(t)}getNames(){return Array.from(wt.keys())}},De.plugin=new class{constructor(){this.pluginList=[]}add(t){this.pluginList.push(t)}loadAll(t){for(const e of this.pluginList)e(t)}};const Ve=[{icon:n.get("numberedList"),value:"numbered",text:t=>t.toolbar.numberedList()},{icon:n.get("bulletedList"),value:"bulleted",text:t=>t.toolbar.bulletedList()},{icon:n.get("checklist"),value:"checklist",text:t=>t.toolbar.checklist()}],Fe=[{icon:n.get("alignLeft"),value:"left",text:t=>t.toolbar.alignLeft()},{icon:n.get("alignCenter"),value:"center",text:t=>t.toolbar.alignCenter()},{icon:n.get("alignRight"),value:"right",text:t=>t.toolbar.alignRight()},{icon:n.get("alignJustify"),value:"justify",text:t=>t.toolbar.alignJustify()}],Re=[{icon:n.get("increaseIndent"),value:"increase",text:t=>t.toolbar.increaseIndent()},{icon:n.get("decreaseIndent"),value:"decrease",text:t=>t.toolbar.decreaseIndent()}],je=[{icon:n.get("italic"),value:"italic",text:t=>t.toolbar.italic()},{icon:n.get("underline"),value:"underline",text:t=>t.toolbar.underline()},{icon:n.get("strikethrough"),value:"strikethrough",text:t=>t.toolbar.strikethrough()},{icon:n.get("superscript"),value:"superscript",text:t=>t.toolbar.superscript()},{icon:n.get("subscript"),value:"subscript",text:t=>t.toolbar.subscript()},{icon:n.get("code"),value:"code",text:t=>t.toolbar.code()}],We=["#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"],qe=[{icon:n.get("removeFormat"),value:"",text:t=>t.toolbar.removeColor()}];for(const t of We)qe.push({value:t.toLowerCase(),text:t.toUpperCase()});const Ue=new Map([["strong","bold"],["em","italic"],["i","italic"],["u","underline"],["s","strikethrough"],["sup","superscript"],["sub","subscript"],["code","code"]]),Ke=[{name:"undo",type:"button",icon:n.get("undo"),tooltip:t=>t.toolbar.undo(),onClick:(t,e)=>{t.command.execute(e)}},{name:"redo",type:"button",icon:n.get("redo"),tooltip:t=>t.toolbar.redo(),onClick:(t,e)=>{t.command.execute(e)}},{name:"selectAll",type:"button",icon:n.get("selectAll"),tooltip:t=>t.toolbar.selectAll(),onClick:(t,e)=>{t.command.execute(e)}},{name:"paragraph",type:"button",icon:n.get("paragraph"),tooltip:t=>t.toolbar.paragraph(),isSelected:t=>!!t.find((t=>"p"===t.name)),onClick:t=>{t.command.execute("heading","p")}},{name:"blockQuote",type:"button",icon:n.get("blockQuote"),tooltip:t=>t.toolbar.blockQuote(),onClick:(t,e)=>{t.command.execute(e)}},{name:"numberedList",type:"button",icon:n.get("numberedList"),tooltip:t=>t.toolbar.numberedList(),isSelected:t=>!!t.find((t=>"ol"===t.name)),onClick:t=>{t.command.execute("list","numbered")}},{name:"bulletedList",type:"button",icon:n.get("bulletedList"),tooltip:t=>t.toolbar.bulletedList(),isSelected:t=>!!t.find((t=>"ul"===t.name&&!t.node.hasAttr("type"))),onClick:t=>{t.command.execute("list","bulleted")}},{name:"checklist",type:"button",icon:n.get("checklist"),tooltip:t=>t.toolbar.checklist(),isSelected:t=>!!t.find((t=>"ul"===t.name&&"checklist"===t.node.attr("type"))),onClick:t=>{t.command.execute("list","checklist")}},{name:"alignLeft",type:"button",icon:n.get("alignLeft"),tooltip:t=>t.toolbar.alignLeft(),isSelected:t=>!!t.find((t=>t.node.isBlock&&"left"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","left")}},{name:"alignCenter",type:"button",icon:n.get("alignCenter"),tooltip:t=>t.toolbar.alignCenter(),isSelected:t=>!!t.find((t=>t.node.isBlock&&"center"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","center")}},{name:"alignRight",type:"button",icon:n.get("alignRight"),tooltip:t=>t.toolbar.alignRight(),isSelected:t=>!!t.find((t=>t.node.isBlock&&"right"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","right")}},{name:"alignJustify",type:"button",icon:n.get("alignJustify"),tooltip:t=>t.toolbar.alignJustify(),isSelected:t=>!!t.find((t=>t.node.isBlock&&"justify"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","justify")}},{name:"increaseIndent",type:"button",icon:n.get("increaseIndent"),tooltip:t=>t.toolbar.increaseIndent(),onClick:t=>{t.command.execute("indent","increase")}},{name:"decreaseIndent",type:"button",icon:n.get("decreaseIndent"),tooltip:t=>t.toolbar.decreaseIndent(),onClick:t=>{t.command.execute("indent","decrease")}},{name:"bold",type:"button",icon:n.get("bold"),tooltip:t=>t.toolbar.bold(),onClick:(t,e)=>{t.command.execute(e)}},{name:"italic",type:"button",icon:n.get("italic"),tooltip:t=>t.toolbar.italic(),onClick:(t,e)=>{t.command.execute(e)}},{name:"underline",type:"button",icon:n.get("underline"),tooltip:t=>t.toolbar.underline(),onClick:(t,e)=>{t.command.execute(e)}},{name:"strikethrough",type:"button",icon:n.get("strikethrough"),tooltip:t=>t.toolbar.strikethrough(),onClick:(t,e)=>{t.command.execute(e)}},{name:"superscript",type:"button",icon:n.get("superscript"),tooltip:t=>t.toolbar.superscript(),onClick:(t,e)=>{t.command.execute(e)}},{name:"subscript",type:"button",icon:n.get("subscript"),tooltip:t=>t.toolbar.subscript(),onClick:(t,e)=>{t.command.execute(e)}},{name:"code",type:"button",icon:n.get("code"),tooltip:t=>t.toolbar.code(),onClick:(t,e)=>{t.command.execute(e)}},{name:"removeFormat",type:"button",icon:n.get("removeFormat"),tooltip:t=>t.toolbar.removeFormat(),onClick:(t,e)=>{t.command.execute(e)}},{name:"formatPainter",type:"button",icon:n.get("formatPainter"),tooltip:t=>t.toolbar.formatPainter(),onClick:(t,e)=>{t.command.execute(e)}},{name:"link",type:"button",icon:n.get("link"),tooltip:t=>t.toolbar.link(),onClick:(t,e)=>{t.command.execute(e)}},{name:"hr",type:"button",icon:n.get("hr"),tooltip:t=>t.toolbar.hr(),onClick:(t,e)=>{t.command.execute(e)}},{name:"codeBlock",type:"button",icon:n.get("codeBlock"),tooltip:t=>t.toolbar.codeBlock(),onClick:(t,e)=>{t.command.execute(e)}},{name:"video",type:"button",icon:n.get("video"),tooltip:t=>t.toolbar.video(),onClick:(t,e)=>{t.command.execute(e)}},{name:"equation",type:"button",icon:n.get("equation"),tooltip:t=>t.toolbar.equation(),onClick:(t,e)=>{t.command.execute(e)}},{name:"heading",type:"dropdown",downIcon:n.get("down"),defaultValue:"p",tooltip:t=>t.toolbar.heading(),width:"100px",menuType:"list",menuItems:[{value:"h1",text:t=>`<span style="font-weight: bold; font-size: 26px;">${t.toolbar.heading1()}</span>`},{value:"h2",text:t=>`<span style="font-weight: bold; font-size: 24px;">${t.toolbar.heading2()}</span>`},{value:"h3",text:t=>`<span style="font-weight: bold; font-size: 22px;">${t.toolbar.heading3()}</span>`},{value:"h4",text:t=>`<span style="font-weight: bold; font-size: 20px;">${t.toolbar.heading4()}</span>`},{value:"h5",text:t=>`<span style="font-weight: bold; font-size: 18px;">${t.toolbar.heading5()}</span>`},{value:"h6",text:t=>`<span style="font-weight: bold; font-size: 16px;">${t.toolbar.heading6()}</span>`},{value:"p",text:t=>t.toolbar.paragraph()}],onSelect:(t,e)=>{t.command.execute("heading",e)}},{name:"list",type:"dropdown",downIcon:n.get("down"),icon:n.get("list"),tooltip:t=>t.toolbar.list(),menuType:"list",menuItems:Ve,onSelect:(t,e)=>{t.command.execute("list",e)}},{name:"align",type:"dropdown",downIcon:n.get("down"),icon:n.get("alignLeft"),tooltip:t=>t.toolbar.align(),menuType:"list",menuItems:Fe,onSelect:(t,e)=>{t.command.execute("align",e)}},{name:"indent",type:"dropdown",downIcon:n.get("down"),icon:n.get("increaseIndent"),tooltip:t=>t.toolbar.indent(),menuType:"list",menuItems:Re,onSelect:(t,e)=>{t.command.execute("indent",e)}},{name:"fontFamily",type:"dropdown",downIcon:n.get("down"),defaultValue:"Segoe UI",tooltip:t=>t.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:(t,e)=>{t.command.execute("fontFamily",e)}},{name:"fontSize",type:"dropdown",downIcon:n.get("down"),defaultValue:"16px",tooltip:t=>t.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:(t,e)=>{t.command.execute("fontSize",e)}},{name:"moreStyle",type:"dropdown",icon:n.get("more"),tooltip:t=>t.toolbar.moreStyle(),menuType:"list",menuItems:je,selectedValues:t=>{var e;const i=[];for(const n of t)if(n.node.isMark){const t=null!==(e=Ue.get(n.name))&&void 0!==e?e:n.name;i.push(t)}return i},onSelect:(t,e)=>{t.command.execute(e)}},{name:"fontColor",type:"dropdown",downIcon:n.get("down"),icon:n.get("fontColor"),accentIcon:n.get("fontColorAccent"),defaultValue:"#f5222d",tooltip:t=>t.toolbar.fontColor(),menuType:"color",menuItems:qe,menuWidth:"296px",onSelect:(t,e)=>{t.command.execute("fontColor",e)}},{name:"highlight",type:"dropdown",downIcon:n.get("down"),icon:n.get("highlight"),accentIcon:n.get("highlightAccent"),defaultValue:"#fadb14",tooltip:t=>t.toolbar.highlight(),menuType:"color",menuItems:qe,menuWidth:"296px",onSelect:(t,e)=>{t.command.execute("highlight",e)}},{name:"image",type:"upload",icon:n.get("image"),tooltip:t=>t.toolbar.image(),accept:"image/*",multiple:!0},{name:"file",type:"upload",icon:n.get("attachment"),tooltip:t=>t.toolbar.file(),accept:"*",multiple:!0}],Ge=["undo","redo","|","heading","|","formatPainter","removeFormat","bold","moreStyle","|","fontColor","highlight","|","align","list","indent","link","blockQuote","hr"],Xe=new Map;for(const t of Ke)Xe.set(t.name,t);const Ye={type:"block",name:"hr",render:t=>{const e=t.getEditor();if(!e)return;const i=t.getContainer(),n=I('<div class="lake-hr"><hr /></div>');i.empty(),i.append(n),n.on("click",(()=>{e.selection.selectBox(t)}))},html:()=>"<hr />"},Je="#57606a",Qe="#444d56",ti="#953800",ei="#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",fi="#cf222e",gi="#57606a",vi="#57606a",wi="#8250df",yi="#0550ae",xi="#f6f8fa",bi="#cf222e",ki="#0550ae",Si="#005cc5",Ci="#444d56",_i="#444d56";function Bi(t){const{HighlightStyle:e,tags:i}=t;return e.define([{tag:[i.comment,i.lineComment,i.blockComment,i.docComment],color:Je},{tag:[i.name],color:Qe},{tag:[i.variableName,i.self],color:ti},{tag:[i.typeName,i.tagName],color:ei},{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:fi},{tag:[i.punctuation,i.separator,i.bracket,i.angleBracket,i.squareBracket,i.paren,i.brace,i.contentSeparator],color:gi},{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:Si},{tag:[i.standard(i.name)],color:Ci},{tag:[i.special(i.variableName)],color:_i}])}const Ai={type:"block",name:"codeBlock",render:t=>{var e;const i=t.getEditor();if(!i)return;const s=I('<div class="lake-code-block" />'),o=t.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 t.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(t)})));const{EditorState:l,Compartment:c,EditorView:d,keymap:h,history:p,defaultKeymap:u,historyKeymap:m,indentWithTab:f,syntaxHighlighting:g}=a,v=a.langItems,w=i.config.codeBlock,y=v.filter((t=>w.langList.indexOf(t.value)>=0)),x=new Map;for(const t of y)x.set(t.value,t);const b=t.value,k=x.get(b.lang),S=new c,C=d.updateListener.of((e=>{var n;e.docChanged&&(n=e.state.doc.toString(),window.setTimeout((()=>{i.isComposing||(t.updateValue("code",n),i.history.save())}),0))})),_=new d({parent:r,doc:null!==(e=b.code)&&void 0!==e?e:"",extensions:[l.readOnly.of(i.readonly),d.editable.of(!i.readonly),p(),h.of([...u,...m,f]),g(Bi(a)),S.of(k&&k.component?k.component():[]),C]});s.find('[contenteditable="true"]').attr("tabindex","-1");new zt({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((t=>({value:t.value,text:t.text}))),onSelect:e=>{t.updateValue({lang:e}),t.unmount(),t.render(),i.selection.selectBox(t),i.history.save()}}).render();const B=()=>{o.css("width",i.container.innerWidth()-2+"px")};i.event.on("resize",B),s.on("click",(()=>{_.hasFocus||_.focus()})),t.event.on("beforeunmount",(()=>{_.destroy(),i.event.off("resize",B),A("CodeMirror destroyed")}))}};function Ti(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{l(n.next(t))}catch(t){o(t)}}function a(t){try{l(n.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}l((n=n.apply(t,e||[])).next())}))}
|
|
18
|
+
`;class Dt{constructor(t){if(this.event=new vt,"string"==typeof t){const e=wt.get(t);if(void 0===e)throw new Error(`The box "${t}" has not been defined yet.`);const i=r(e.type),n=r(e.name);this.node=I(a`<lake-box type="${i}" name="${n}"></lake-box>`),e.value&&(this.value=e.value)}else{this.node=I(t);const e=wt.get(this.name);if(void 0===e)throw new Error(`The box "${this.name}" has not been defined yet.`);e.value&&!this.node.hasAttr("value")&&(this.value=e.value)}}addFramework(){let t=this.getContainer();0===t.length?(this.node.html($t),t=this.getContainer()):(t.off("mouseenter"),t.off("mouseleave"),t.off("click")),t.on("mouseenter",(()=>{t.hasClass("lake-box-selected")||t.hasClass("lake-box-focused")||t.hasClass("lake-box-activated")||t.addClass("lake-box-hovered")})),t.on("mouseleave",(()=>{t.removeClass("lake-box-hovered")})),t.on("click",(()=>{A(`The box "${this.name}" (id = ${this.node.id}) value:`),A(this.value)})),"block"===this.type&&this.node.isContentEditable&&t.attr("draggable","true")}get type(){return this.node.attr("type")}get name(){return this.node.attr("name")}get value(){const t=this.node.attr("value");return""===t?{}:JSON.parse(h(t))}set value(t){this.node.attr("value",d(JSON.stringify(t)))}updateValue(t,e){const i=this.value;if("string"==typeof t)i[t]=e;else for(const e of Object.keys(t))i[e]=t[e];this.value=i}getEditor(){const t=this.node.closest("div[contenteditable]");return t.length>0?yt.get(t.id):void 0}getContainer(){return this.node.find(".lake-box-container")}setToolbar(t){const e=this.getEditor();let i=null;const n=()=>{i&&i.updatePosition()};this.event.on("focus",(()=>{i=new Ht({root:e?e.popupContainer:I(document.body),box:this,items:t,locale:e?e.locale:void 0}),i.render(),e&&e.root.on("scroll",n)})),this.event.on("blur",(()=>{i&&(i.unmount(),i=null),e&&e.root.off("scroll",n)}))}render(){const t=wt.get(this.name);if(void 0===t)return;this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.addFramework();const e=t.render(this);if(void 0!==e){const t=this.getContainer();t.empty(),t.append(e)}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 t=wt.get(this.name);return void 0===t?"":void 0===t.html?this.node.outerHTML():t.html(this)}}function Vt(t){const e=mt(0);if("string"==typeof t){const i=new Dt(t);return e.set(i.node.id,i),i}const i=(t=I(t)).closestContainer();if(0===i.length){let i=e.get(t.id);return i||(i=new Dt(t),e.set(t.id,i),i)}const n=mt(i.id);let s=e.get(t.id);return s?(n.set(t.id,s),e.delete(t.id),s):(s=n.get(t.id),s||(s=new Dt(t),n.set(t.id,s),s))}function Ft(t){const e=t.responseText||t.response;if(!e)return e;try{return JSON.parse(e)}catch(t){return e}}function Rt(t){const e=new XMLHttpRequest;t.onProgress&&e.upload&&(e.upload.onprogress=e=>{e.total>0&&(e.percent=e.loaded/e.total*100),t.onProgress&&t.onProgress(e)});const i=new FormData,n=t.data||{};Object.keys(n).forEach((t=>{const e=n[t];Array.isArray(e)?e.forEach((e=>{i.append(`${t}[]`,e)})):i.append(t,e)}));const s=t.filename||"file";t.file instanceof Blob?i.append(s,t.file,t.file.name):i.append(s,t.file),e.onerror=e=>{t.onError&&t.onError(e)},e.onload=()=>{if(e.status<200||e.status>=300){if(!t.onError)return;return t.onError(function(t,e){const i=`Cannot ${t.method} ${t.action} ${e.status}'`,n=new Error(i);return n.status=e.status,n.method=t.method,n.url=t.action,n}(t,e),Ft(e))}if(t.onSuccess)return t.onSuccess(Ft(e),e)},e.open(t.method,t.action,!0),t.withCredentials&&"withCredentials"in e&&(e.withCredentials=!0);const o=t.headers||{};return null!==o["X-Requested-With"]&&e.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(o).forEach((t=>{null!==o[t]&&e.setRequestHeader(t,o[t])})),e.send(i),e}function jt(t){const{editor:e,name:i,file:n,onError:s,onSuccess:o}=t,{requestMethod:r,requestAction:a,requestTypes:l}=e.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=e.selection.insertBox(i,{url:URL.createObjectURL(n),status:"uploading",name:n.name,size:n.size,type:n.type,lastModified:n.lastModified});let d=Rt({onProgress:t=>{const e=c.node.find(".lake-percent"),i=Math.round(t.percent);e.text(`${i<100?i:99} %`)},onError:(t,e)=>{d=null,A(t.toString(),e),c.updateValue("status","error"),c.render(),s&&s(t.toString())},onSuccess:t=>{if(d=null,!t.url)return c.updateValue("status","error"),c.render(),void(s&&s("Cannot find the url field."));c.updateValue({status:"done",url:t.url}),c.render(),e.history.save(),o&&o()},file:n,action:a,method:r});return c.event.on("beforeunmount",(()=>{d&&(d.abort(),A("Upload canceled"))})),c}var Wt=Object.freeze({__proto__:null,appendBreak:Z,camelCase:l,changeTagName:V,debug:A,denormalizeValue:g,encode:r,fileSize:w,fixNumberedList:F,fromBase64:h,getBox:Vt,getCSS:y,getDeepElement:H,inString:c,mergeNodes:z,modifierText:v,morph:ht,nodeAndView:pt,normalizeValue:f,parseStyle:m,query:I,removeBreak:N,removeZWS:D,request:Rt,safeTemplate:a,setBlockIndent:R,splitNodes:P,template:s,toBase64:d,toHex:u,toNodeList:x,uploadFile:jt,wrapNodeList:$});class qt{constructor(t){this.fragment=null!=t?t:document.createDocumentFragment()}get(){return this.fragment}find(t){const e=[];let i=new L(this.fragment.firstChild);for(;i.length>0;)i.matches(t)?e.push(i.get(0)):i.isElement&&i.find(t).each((t=>{e.push(t)})),i=i.next();return new L(e)}append(t){I(t).each((t=>{this.fragment.appendChild(t)}))}}const Ut={id:/^[\w-]+$/,class:/^[\w- ]+$/,style:{"text-align":["left","center","right","justify","start","end"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function Kt(){return{h1:Object.assign({},Ut),h2:Object.assign({},Ut),h3:Object.assign({},Ut),h4:Object.assign({},Ut),h5:Object.assign({},Ut),h6:Object.assign({},Ut),p:Object.assign({},Ut),blockquote:Object.assign(Object.assign({},Ut),{type:["info","tip","success","warning","error","danger"]}),ul:Object.assign(Object.assign({},Ut),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},Ut),{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 Gt{constructor(t,e=Kt()){this.rules=e,this.source="string"==typeof t?this.parseHTML(t):t}parseHTML(t){const e=(new DOMParser).parseFromString(t,"text/html");return new L(e.querySelector("body"))}static matchRule(t,e){return"string"==typeof t?t===e:Array.isArray(t)?t.indexOf(e)>=0:t instanceof RegExp&&t.test(e)}static getOpenTagString(t,e){let i=t.name,n=e[i];if(!n)return"";"string"==typeof n&&(i=n,n=e[i]);const s=t.get(0);if(!s.hasAttributes())return i;const o=new Map;for(const t of s.attributes)if(n[t.name]&&("style"!==t.name&&Gt.matchRule(n[t.name],t.value)&&o.set(t.name,t.value),"style"===t.name)){const e=n.style,i=new Map,s=m(t.value);for(const t of Object.keys(s)){const n=s[t];e[t]&&Gt.matchRule(e[t],n)&&i.set(t,n)}o.set("style",i)}let r=i;for(const[t,e]of o)if("style"===t){let t="";for(const[i,n]of e)t+=`${i}: ${n.replace(/"/g,""")}; `;""!==t&&(r+=` style="${t.trim()}"`)}else r+=` ${t}="${e}"`;return r}static getClosedTagString(t,e){let i=t.name;const n=e[i];return n?("string"==typeof n&&(i=n),i):""}static getTrimmedText(t){const e=t.parent(),i=t.prev(),n=t.next();let s=t.text();return(i.isBlock||i.isBlockBox)&&(n.isBlock||n.isBlockBox)||0===i.length&&0===n.length&&e.isBlock?s=s.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):i.isBlock||i.isBlockBox||0===i.length&&e.isBlock?s=s.replace(/^[\u0020\t\r\n]+/,""):(n.isBlock||n.isBlockBox||0===n.length&&e.isBlock)&&(s=s.replace(/[\u0020\t\r\n]+$/,"")),s}getHTML(){const t=this.rules;let e="";for(const i of function*e(i){let n=i.first();for(;n.length>0;){const i=n.next();if(n.isText)yield r(Gt.getTrimmedText(n));else if(n.isVoid){const e=Gt.getOpenTagString(n,t);""!==e&&(yield`<${e} />`)}else if(n.isElement){const i=Gt.getOpenTagString(n,t),s=Gt.getClosedTagString(n,t);""!==i&&(yield`<${i}>`),n.isBox||(yield*e(n)),""!==s&&(yield`</${s}>`)}n=i}}(this.source))e+=i;return e.trim()}getFragment(){const t=this.getHTML(),e=this.parseHTML(t),i=document.createDocumentFragment();let n=e.first();for(;n.length>0;){const t=n.next();i.appendChild(n.get(0)),n=t}return i}}class Xt{constructor(t){this.content=t}getHTML(){let t=this.content;return t=t.replace(/ {2}/g," "),t=r(t.trim()),t=`<p>${t}</p>`,t=t.replace(/(\r\n){2,}/g,"</p><p><br /></p><p>"),t=t.replace(/\r\n/g,"</p><p>"),t=t.replace(/[\r\n]{2,}/g,"</p><p><br /></p><p>"),t=t.replace(/[\r\n]/g,"</p><p>"),t}getFragment(){return new Gt(this.getHTML()).getFragment()}}function Yt(t,e){if(t.commonAncestor.isOutside)return;const i=(e=I(e)).get(0),n=t.get();n.insertNode(i),n.setEndAfter(i),n.collapse(!1)}function Jt(t){if(t.commonAncestor.isOutside)return{anchor:new L,focus:new L};const e=t.startNode.closest("lake-box");if(e.length>0)return t.isBoxStart?e.attr("focus","start"):t.isBoxEnd?e.attr("focus","end"):e.attr("focus","center"),{anchor:new L,focus:e};if(t.isCollapsed){const e=t.clone();e.collapseToEnd();const i=I('<lake-bookmark type="focus" />');return Yt(e,i),{anchor:new L,focus:i}}const i=t.clone();i.collapseToStart();const n=I('<lake-bookmark type="anchor" />');Yt(i,n);const s=t.clone();s.collapseToEnd();const o=I('<lake-bookmark type="focus" />');return Yt(s,o),{anchor:n,focus:o}}function Qt(t,e){const i=t.prev(),n=t.next();if(i.isText||n.isText){const e=t.parent();t.remove(),e.get(0).normalize()}else if(0===i.length&&0===n.length){if(t.parent().isMark&&e){const i=new L(document.createTextNode(""));t.before(i),e.setStartAfter(i),e.collapseToStart()}t.remove()}else t.remove()}function te(t,e){const i=e.anchor,n=e.focus;if(i.length>0&&0===n.length)Qt(i);else{if(n.length>0&&0===i.length){if(n.isBox){const e=Vt(n);0===e.getContainer().length&&e.render();const i=n.attr("focus");return"start"===i?t.selectBoxStart(n):"center"===i?t.selectBox(n):t.selectBoxEnd(n),void n.removeAttr("focus")}return t.setStartBefore(n),t.collapseToStart(),void Qt(n,t)}if(i.length>0&&n.length>0){const e=new M;e.selectNode(i),e.collapseToEnd(),-1===e.compareAfterNode(n)?(t.setStartBefore(n),Qt(n),t.setEndBefore(i),Qt(i)):(t.setStartBefore(i),Qt(i),t.setEndBefore(n),Qt(n))}}}function ee(t){if(t.commonAncestor.isOutside)return;F(t.getBlocks())}function ie(t){if(t.isCollapsed)return;if(t.adjustBox(),t.adjustTable(),t.isInoperative)return;const e=t.startNode.closestBlock(),i=t.endNode.closestBlock(),n=e.get(0)===i.get(0);if(t.get().deleteContents(),t.adjustBlock(),n){const e=t.getBlocks()[0];if(e&&e.isEmpty){const i=Z(e);t.setStartBefore(i),t.collapseToStart()}return}const s=t.getBlocks()[0];if(!s)return;const o=s.prev();if(0===o.length)return;const r=Jt(t);z(o,s),te(t,r),ee(t)}function ne(t,e){if(e instanceof qt&&(e=e.get()),t.commonAncestor.isOutside)return;t.isCollapsed?t.adjustBox():ie(t);N(t.startNode.closestBlock());const i=Jt(t);i.focus.before(e),te(t,i),t.adjustBlock()}function se(t,e){if(t.commonAncestor.isOutside)return;if(t.isCollapsed){if(t.commonAncestor.closest("lake-box").isBlockBox)return}if("string"!=typeof e){const i=t.getBlocks();for(const t of i)t.css(e);return}const i=I(e),n=i.name,s=i.get(0).attributes,o=t.getBlocks();if(o.length>0){const e=Jt(t);for(const t of o)if(t.name===n&&0===i.first().length)for(const e of s)t.attr(e.name,e.value);else{const e=i.clone(!0);e.isList&&t.isList&&""!==t.attr("indent")&&e.attr("indent",t.attr("indent"));const n=H(e);let s=t.first();for(;s.length>0;){const t=s.next();n.append(s),n.name!==s.name&&"li"!==s.name||s.remove(!0),s=t}t.replaceWith(e)}return te(t,e),void ee(t)}const r=Jt(t),a=function(t){const e=t.commonAncestor.closest('div[contenteditable="true"],td');let i=[];if(0===e.length)return i;let n=e.first(),s=!0;for(;n.length>0;){if(n.isMark||n.isText||n.isBookmark||n.isInlineBox)i.push(n);else{if(!s)break;i=[]}t.intersectsNode(n)&&(s=!1),n=n.next()}return i}(t),l=$(a,i);if(te(t,r),ee(t),l.isEmpty){const e=Z(l);t.setStartBefore(e),t.collapseToStart()}}function oe(t){if(t.commonAncestor.isOutside)return{start:null,end:null};t.isCollapsed?t.adjustBox():ie(t);const e=t.startNode,i=e.closestOperableBlock();if(0===i.length)return{start:null,end:null};let n=i.parent();n.isOutside&&(n=e.closestContainer());const s=P(e,t.startOffset,n);let o=null,r=null;return s&&(o=s.start,r=s.end),!s&&e.isBlock&&(t.startOffset>0&&(o=e.children()[t.startOffset-1]),r=e.children()[t.startOffset],r&&!r.isBlock&&(r=null)),o&&o.isEmpty&&Z(o),r&&(r.isEmpty&&Z(r),t.shrinkBefore(r)),ee(t),{start:o,end:r}}function re(t){if(t.isMark&&t.isEmpty)t.remove();else for(const e of t.getWalker())e.isMark&&e.isEmpty&&e.remove()}function ae(t,e,i){let n=null,s=null,o=t.closestBlock();0===o.length&&(o=t.closestContainer());const r=P(t,e,o);return r&&(i?(re(r.start),re(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 le(t,e=!0){if(t.commonAncestor.isOutside)return{start:null,center:null,end:null};if(t.adjustBox(),t.isCollapsed){const i=ae(t.startNode,t.startOffset,e);return i.start?(t.setStartAfter(i.start),t.collapseToStart()):i.end&&(t.setStartBefore(i.end),t.collapseToStart()),{start:i.start,center:null,end:i.end}}const i=ae(t.startNode,t.startOffset,e);i.start?t.setStartAfter(i.start):i.end&&t.setStartBefore(i.end);const n=ae(t.endNode,t.endOffset,e);return n.start?t.setEndAfter(n.start):n.end&&t.setEndBefore(n.end),{start:i.start,center:n.start,end:n.end}}function ce(t,e){const i=t.text();let n=t;for(;n.length>0;){const t=n.parent();if(!t.isMark||i!==t.text()||!n.isText&&n.name===e&&""!==n.attr("style"))break;n=t}return n}function de(t,e){if(t.commonAncestor.isOutside)return;let i=I(e);const n=i.name,s=m(i.attr("style"));if(t.isCollapsed){if(t.isBox){const e=t.startNode.closest("lake-box");if("block"===Vt(e).type){const i=I("<p><br /></p>");t.isBoxStart?e.before(i):e.after(i),t.shrinkAfter(i)}else t.adjustBox()}N(t.startNode.closestBlock());const e=new L(document.createTextNode("")),o=le(t);if(o.start){const t=function(t){if(!t.isMark)return null;let e=t.clone(),i=t.last();for(;i.length>0;){if(i.isMark){const t=i.clone();e.append(t),e=t}i=i.last()}return e}(o.start);if(t)if(t.name===n)t.css(s),i=t;else{H(t).append(e),i.append(t)}}return""===i.text()&&i.append(e),Yt(t,i),function(t){const e=t.prev();e.length>0&&e.isText&&e.isEmpty&&e.remove();const i=t.next();i.length>0&&i.isText&&i.isEmpty&&i.remove()}(i),void t.shrinkAfter(i)}le(t);const o=t.getMarks(!0),r=Jt(t);for(const t of o)if(!t.isEmpty&&t.isText){const e=ce(t,n);if(e.isMark&&e.name===n)e.css(s);else{const t=i.clone();e.before(t),t.append(e)}}te(t,r)}function he(t){if(t.isMark&&t.isEmpty)t.remove();else for(const e of t.getWalker())e.isMark&&e.isEmpty&&e.remove()}function pe(t,e){if(t.commonAncestor.isOutside)return;let i;if(e){i=I(e).name}if(t.isCollapsed){if(t.isBox)return;if(i&&0===t.commonAncestor.closest(i).length)return;const e=le(t,!1);if(!e.start)return;e.end&&he(e.end);const n=new L(document.createTextNode("")),s=function(t,e){if(!t.isMark||!e)return null;let i=t.clone(),n=t.last();for(;n.length>0;){if(n.isMark&&n.name!==e){const t=n.clone();i.append(t),i=t}n=n.last()}if(i.name===e){if(!(i.first().length>0))return null;i=i.first()}return i}(e.start,i);if(!s)return e.start.after(n),he(e.start),n.prev().isText?(t.setStartAfter(n.prev()),t.collapseToStart(),void n.remove()):(t.setStartAfter(n),void t.collapseToStart());return H(s).append(n),e.start.after(s),he(e.start),void t.shrinkAfter(s)}le(t);const n=t.getMarks(),s=Jt(t);for(const t of n)if(!i||t.name===i){const e=t.parent();t.remove(!t.isEmpty),e.length>0&&e.get(0).normalize()}D(t.commonAncestor),te(t,s)}function ue(t,e){if(t.commonAncestor.isOutside)return null;const i=I(e);if(t.isCollapsed){let e=t.commonAncestor.closest("a");if(0===e.length){e=i.clone(!0);return N(t.startNode.closestBlock()),Yt(t,e),e}return""!==i.attr("href")&&e.attr({href:i.attr("href")}),e}le(t);const n=Jt(t);for(const e of t.commonAncestor.getWalker())"a"===e.name&&t.intersectsNode(e)&&e.remove(!0);const s=i.clone(!1);n.anchor.after(s);let o=s.next();for(;o.length>0;){const t=o.next();if(!o.isMark&&!o.isText)break;s.append(o),o=t}return 0===s.first().length&&s.remove(),te(t,n),s}function me(t,e,i){if(t.commonAncestor.isOutside)return null;const n=Vt(e);i&&(n.value=i);const s=document.createDocumentFragment();if(s.appendChild(n.node.get(0)),"inline"===n.type)return ne(t,s),n.render(),t.selectBoxEnd(n.node),Vt(n.node);const o=oe(t);return o.start&&(t.setEndAfter(o.start),t.collapseToEnd()),o.end&&o.end.isEmpty&&o.end.remove(),ne(t,s),n.render(),t.selectBoxEnd(n.node),o.start&&o.start.isEmpty&&o.start.remove(),Vt(n.node)}function fe(t){const e=t.node.closestContainer();if(t.unmount(),t.node.remove(),e.length>0){mt(e.id).delete(t.node.id);mt(0).set(t.node.id,t)}return t}function ge(t){if(t.commonAncestor.isOutside)return null;const e=t.commonAncestor.closest("lake-box");if(0===e.length)return null;const i=Vt(e);if("block"===i.type){const n=I("<p><br /></p>");return e.before(n),t.shrinkAfter(n),fe(i)}t.setStartBefore(e),t.collapseToStart();const n=e.parent();if(fe(i),n.isEmpty){const e=Z(n);t.setStartBefore(e),t.collapseToStart()}return i}var ve={exports:{}};function we(t,e=100,i={}){if("function"!=typeof t)throw new TypeError(`Expected the first parameter to be a function, got \`${typeof t}\`.`);if(e<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 e=s,i=o;return s=void 0,o=void 0,l=t.apply(e,i),l}function d(){const t=Date.now()-a;t<e&&t>=0?r=setTimeout(d,e-t):(r=void 0,n||(l=c()))}const h=function(...t){if(s&&this!==s)throw new Error("Debounced method called with different contexts.");s=this,o=t,a=Date.now();const i=n&&!r;return r||(r=setTimeout(d,e)),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}ve.exports.debounce=we,ve.exports=we;var ye=ft(ve.exports),xe=ft((function t(e,i){if(e===i)return!0;if(e&&i&&"object"==typeof e&&"object"==typeof i){if(e.constructor!==i.constructor)return!1;var n,s,o;if(Array.isArray(e)){if((n=e.length)!=i.length)return!1;for(s=n;0!=s--;)if(!t(e[s],i[s]))return!1;return!0}if(e instanceof Map&&i instanceof Map){if(e.size!==i.size)return!1;for(s of e.entries())if(!i.has(s[0]))return!1;for(s of e.entries())if(!t(s[1],i.get(s[0])))return!1;return!0}if(e instanceof Set&&i instanceof Set){if(e.size!==i.size)return!1;for(s of e.entries())if(!i.has(s[0]))return!1;return!0}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(i)){if((n=e.length)!=i.length)return!1;for(s=n;0!=s--;)if(e[s]!==i[s])return!1;return!0}if(e.constructor===RegExp)return e.source===i.source&&e.flags===i.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===i.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===i.toString();if((n=(o=Object.keys(e)).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(!t(e[r],i[r]))return!1}return!0}return e!=e&&i!=i}));function be(t){const e=t.get(0),i={};if(e.hasAttributes())for(const t of e.attributes)i[t.name]=t.value;return i}class ke{constructor(t){const e=window.getSelection();if(!e)throw new Error("Selection object is null.");this.selection=e,this.container=t,this.range=this.getRangeFromNativeSelection()}getRangeFromNativeSelection(){if(this.selection.rangeCount>0){const t=this.selection.getRangeAt(0);return new M(t)}return new M}sync(){this.selection.removeAllRanges(),this.selection.addRange(this.range.get())}updateByRange(){const t=this.getRangeFromNativeSelection();this.container.contains(t.commonAncestor)&&(this.range.startNode.get(0)===t.startNode.get(0)&&this.range.startOffset===t.startOffset&&this.range.endNode.get(0)===t.endNode.get(0)&&this.range.endOffset===t.endOffset||(this.range=t))}updateByBookmark(){const t=this.range,e=this.container,i=e.find("lake-box[focus]");if(i.length>0)return te(t,{anchor:new L,focus:i}),void this.sync();te(t,{anchor:e.find('lake-bookmark[type="anchor"]'),focus:e.find('lake-bookmark[type="focus"]')}),this.sync()}getAppliedItems(){const t=[];return function(t,e){let i=e.startNode;for(i.isText&&(i=i.parent());i.length>0&&i.isInside;)t.push({node:i,name:i.name,attributes:be(i),styles:m(i.attr("style"))}),i=i.parent()}(t,this.range),function(t,e){const i=e.startNode;let n;if(i.isText&&i.text().length===e.startOffset){const t=i.next();t.length>0&&t.isElement&&(n=t)}if(i.isElement){const t=i.children();if(t.length>0){const i=t[e.startOffset];i&&i.isElement&&(n=i)}}if(n){let e=n;for(;e.length>0;)e.isElement&&t.push({node:e,name:e.name,attributes:be(e),styles:m(e.attr("style"))}),e=e.first()}}(t,this.range),t}insertBookmark(){return Jt(this.range)}toBookmark(t){return te(this.range,t)}insertNode(t){return Yt(this.range,t)}insertFragment(t){return ne(this.range,t)}deleteContents(){return ie(this.range)}setBlocks(t){return se(this.range,t)}splitBlock(){return oe(this.range)}splitMarks(t){return le(this.range,t)}addMark(t){return de(this.range,t)}removeMark(t){return pe(this.range,t)}fixList(){return ee(this.range)}insertLink(t){return ue(this.range,t)}selectBox(t){let e=t;e=t instanceof Dt?t.node:t,this.range.selectBox(e)}insertBox(t,e){const i=me(this.range,t,e);if(!i)throw new Error(`The box "${t}" cannot be inserted outside the editor.`);return i}removeBox(t=null){return t&&this.selectBox(t),ge(this.range)}}class Se{constructor(t){this.commandMap=new Map,this.selection=t}add(t,e){this.commandMap.set(t,e)}delete(t){this.commandMap.delete(t)}getNames(){return Array.from(this.commandMap.keys())}has(t){return void 0!==this.commandMap.get(t)}getItem(t){const e=this.commandMap.get(t);if(void 0===e)throw new Error(`Command "${t}" has not been defined yet.`);return e}isDisabled(t){const e=this.getItem(t);if(!e.isDisabled)return!1;const i=this.selection.getAppliedItems();return e.isDisabled(i)}isSelected(t){const e=this.getItem(t);if(!e.isSelected)return!1;const i=this.selection.getAppliedItems();return e.isSelected(i)}selectedValues(t){const e=this.getItem(t);if(!e.selectedValues)return[];const i=this.selection.getAppliedItems();return e.selectedValues(i)}execute(t,...e){this.getItem(t).execute.apply(this,e),A(`Command "${t}" executed`)}}class Ce{constructor(t){this.canSave=!0,this.list=[],this.index=0,this.limit=100,this.event=new vt,this.selection=t,this.container=t.container}removeBookmark(t){return t.replace(/(<lake-box[^>]+)\s+focus="\w+"([^>]*>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"")}getValue(t){return new Gt(t).getHTML()}addIdToBoxes(t){t.find("lake-box").each((t=>{const e=new L(t),i=`${e.attr("name")}-${e.attr("value")}`;e.attr("id",i)}))}removeIdfromBoxes(t){t.find("lake-box").each((t=>{new L(t).removeAttr("id")}))}morphContainer(t){const e=this.container,i={beforeChildrenUpdated:t=>{if("lake-box"===new L(t).name)return!1},afterAttributeUpdated:(t,i)=>{const n=new L(i);if(["name","value"].indexOf(t)>=0&&"lake-box"===n.name){Vt(n).unmount();mt(e.id).delete(n.id)}}},n=t.clone(!0);this.addIdToBoxes(e),this.addIdToBoxes(n),ht(e,n,{callbacks:i}),this.removeIdfromBoxes(e),this.removeIdfromBoxes(n)}get canUndo(){return this.index>1&&!!this.list[this.index-2]}get canRedo(){return!!this.list[this.index]}cloneContainer(){const t=this.selection.range,e=this.container.clone(!0);if(e.find("lake-box").each((t=>{Vt(t).getContainer().empty()})),!this.container.contains(t.commonAncestor))return e;if(t.isInsideBox){const i=t.commonAncestor.closest("lake-box").path(),n=e.find(i),s=t.clone();return s.selectBox(n),Jt(s),e}const i=t.startNode.path(),n=t.endNode.path(),s=e.find(i),o=e.find(n),r=t.clone();return r.setStart(s,t.startOffset),r.setEnd(o,t.endOffset),Jt(r),e}undo(){if(!this.list[this.index-2])return;this.selection.insertBookmark();const t=this.getValue(this.container);for(;this.index>1;){const e=this.list[this.index-2];if(!e)break;this.index--;const i=this.getValue(e);if(this.removeBookmark(i)!==this.removeBookmark(t)){this.morphContainer(e),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 t=this.getValue(this.container);for(;this.index<this.list.length;){const e=this.list[this.index];if(!e)break;this.index++;const i=this.getValue(e);if(this.removeBookmark(i)!==this.removeBookmark(t)){this.morphContainer(e),this.event.emit("redo",i);break}}this.selection.updateByBookmark(),A(`History redone (index: ${this.index})`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(t={}){var e,i,n;const s=null!==(e=t.inputType)&&void 0!==e?e:"",o=null!==(i=t.update)&&void 0!==i&&i,r=null===(n=t.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",g(l),{inputType:s,update:o,emitEvent:r}))}}var _e={};Object.defineProperty(_e,"__esModule",{value:!0});for(var Be="undefined"!=typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.platform),Ae={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},Te={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:Be?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},Ee={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},Le=1;Le<20;Le++)Ee["f"+Le]=111+Le;function Ie(t,e,i){e&&!("byKey"in e)&&(i=e,e=null),Array.isArray(t)||(t=[t]);var n=t.map((function(t){return Me(t,e)})),s=function(t){return n.some((function(e){return Pe(e,t)}))};return null==i?s:s(i)}function Me(t,e){var i=e&&e.byKey,n={},s=(t=t.replace("++","+add")).split("+"),o=s.length;for(var r in Ae)n[Ae[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=Ne(p),f=Ae[m];if(p.length>1&&!f&&!Te[p]&&!Ee[m])throw new TypeError('Unknown modifier: "'+p+'"');1!==o&&f||(i?n.key=m:n.which=Ze(p)),f&&(n[f]=!u||null)}}catch(t){l=!0,c=t}finally{try{!a&&h.return&&h.return()}finally{if(l)throw c}}return n}function Pe(t,e){for(var i in t){var n=t[i],s=void 0;if(null!=n&&((null!=(s="key"===i&&null!=e.key?e.key.toLowerCase():"which"===i?91===n&&93===e.which?91:e.which:e[i])||!1!==n)&&s!==n))return!1}return!0}function Ze(t){return t=Ne(t),Ee[t]||t.toUpperCase().charCodeAt(0)}function Ne(t){return t=t.toLowerCase(),t=Te[t]||t}_e.default=Ie,_e.isHotkey=Ie,_e.isCodeHotkey=function(t,e){return Ie(t,e)};var Oe=_e.isKeyHotkey=function(t,e){return Ie(t,{byKey:!0},e)};_e.parseHotkey=Me,_e.compareHotkey=Pe,_e.toKeyCode=Ze,_e.toKeyName=Ne;const ze=new Map([["arrow-left","left"],["arrow-right","right"],["arrow-up","up"],["arrow-down","down"]]);class He{constructor(t){this.keydownEventList=[],this.keyupEventList=[],this.container=t,this.container.on("keydown",(t=>{const e=t;if(!e.isComposing)for(const t of this.keydownEventList)if(Oe(t.type,e)&&!1===t.listener(e))break})),this.container.on("keyup",(t=>{const e=t;if(!e.isComposing)for(const t of this.keyupEventList)if(Oe(t.type,e)&&!1===t.listener(e))break}))}normalizeType(t){var e;return t=null!==(e=ze.get(t))&&void 0!==e?e:t}setKeydown(t,e){t=this.normalizeType(t),this.keydownEventList.push({type:t,listener:e})}setKeyup(t,e){t=this.normalizeType(t),this.keyupEventList.push({type:t,listener:e})}keydown(t){t=this.normalizeType(t);for(const e of this.keydownEventList)if(e.type===t&&!1===e.listener(new KeyboardEvent(t)))break}keyup(t){t=this.normalizeType(t);for(const e of this.keyupEventList)if(e.type===t&&!1===e.listener(new KeyboardEvent(t)))break}}const $e={value:"<p><br /></p>",readonly:!1,spellcheck:!1,tabIndex:0,placeholder:"",indentWithTab:!0,lang:"en-US",minChangeSize:5,historySize:100,onMessage:(t,e)=>{"success"!==t?"warning"!==t?"error"===t&&console.error(e):console.warn(e):console.log(e)}};class De{constructor(t){if(this.unsavedInputData="",this.unsavedInputCount=0,this.state={appliedItems:[],disabledNameMap:new Map,selectedNameMap:new Map,selectedValuesMap:new Map},this.isComposing=!1,this.event=new vt,this.box=De.box,this.copyListener=t=>{const e=this.selection.range;this.container.contains(e.commonAncestor)&&this.event.emit("copy",t)},this.cutListener=t=>{const e=this.selection.range;this.container.contains(e.commonAncestor)&&this.event.emit("cut",t)},this.pasteListener=t=>{const e=this.selection.range;this.container.contains(e.commonAncestor)&&this.event.emit("paste",t)},this.selectionchangeListener=()=>{this.updateSelectionRange(),this.updateBoxSelectionStyle(),this.emitStateChangeEvent()},this.clickListener=t=>{const e=new L(t.target);!e.get(0).isConnected||e.closest(".lake-popup").length>0||this.event.emit("click",e)},this.resizeListener=()=>{this.event.emit("resize")},this.updateSelectionRange=ye((()=>{this.selection.updateByRange()}),1,{immediate:!0}),this.updateBoxSelectionStyle=ye((()=>{if(0===this.root.first().length)return;const t=this.selection.range,e=t.clone();e.adjustBox(),this.container.find("lake-box").each((i=>{const n=Vt(i),s=n.getContainer();if(0!==s.length){if(t.compareBeforeNode(s)<0&&t.compareAfterNode(s)>0&&(!t.isCollapsed||t.startNode.get(0)!==s.get(0)||0!==t.startOffset))return s.removeClass("lake-box-hovered"),s.removeClass("lake-box-selected"),s.removeClass("lake-box-focused"),s.addClass("lake-box-activated"),void n.event.emit("focus");if(e.intersectsNode(n.node))return s.removeClass("lake-box-activated"),void(t.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=ye((()=>{const t=this.command.getNames();let e=this.selection.getAppliedItems();e.length>0&&!this.container.contains(e[0].node)&&(e=[]);const i=new Map,n=new Map,s=new Map;if(e.length>0)for(const o of t){const t=this.command.getItem(o);if(t.isDisabled&&t.isDisabled(e)&&i.set(o,!0),t.isSelected&&t.isSelected(e)&&n.set(o,!0),t.selectedValues){const i=t.selectedValues(e);i.length>0&&s.set(o,i)}}const o={appliedItems:e,disabledNameMap:i,selectedNameMap:n,selectedValuesMap:s};xe(o,this.state)||(this.toolbar&&this.toolbar.updateState(o),this.event.emit("statechange",o),this.state=o)}),50,{immediate:!1}),!t.root)throw new Error("The root of the config must be specified.");this.root=I(t.root),this.toolbar=t.toolbar,this.config=Object.assign({},$e);for(const e of Object.keys(t))this.config[e]=t[e];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 ke(this.container),this.command=new Se(this.selection),this.history=new Ce(this.selection),this.history.limit=this.config.historySize,this.keystroke=new He(this.container),yt.set(this.container.id,this)}togglePlaceholderClass(t){const e="lake-placeholder";"<p><br /></p>"===(t=g(t)).replace("<focus />","")?this.container.addClass(e):this.container.removeClass(e)}moveBoxStripText(){const t=this.selection,e=t.range,i=e.startNode.closest(".lake-box-strip"),n=i.closest("lake-box");if("inline"===Vt(n).type)e.isBoxStart?(e.setStartBefore(n),e.collapseToStart()):(e.setStartAfter(n),e.collapseToStart());else{const t=I("<p />");e.isBoxStart?n.before(t):n.after(t),e.setStart(t,0),e.collapseToStart()}const s=i.text();i.html("<br />"),t.insertNode(document.createTextNode(s))}resetUnsavedInputData(){this.unsavedInputData="",this.unsavedInputCount=0}handleInputEvent(t){var e;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"===(t instanceof CompositionEvent?"insertText":t.inputType)){const i=null!==(e=t.data)&&void 0!==e?e:"";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",(t=>{this.isComposing=!1,this.handleInputEvent(t)})),this.container.on("input",(t=>{const e=t;this.isComposing=e.isComposing,this.isComposing||this.handleInputEvent(t)}))}bindHistoryEvents(){const t=t=>{this.fixContent()&&(this.history.save({update:!0,emitEvent:!1}),t=this.getValue()),this.emitStateChangeEvent(),this.togglePlaceholderClass(t),this.scrollToCaret(),this.event.emit("change",t)};this.history.event.on("undo",(e=>{this.renderBoxes(),t(e),this.resetUnsavedInputData()})),this.history.event.on("redo",(e=>{this.renderBoxes(),t(e),this.resetUnsavedInputData()})),this.history.event.on("save",((e,i)=>{this.removeBoxGarbage(),t(e),"insertText"!==i.inputType&&(this.selection.sync(),this.resetUnsavedInputData())}))}get hasFocus(){const t=document.activeElement;return!!t&&I(t).closest(".lake-container").get(0)===this.container.get(0)}get locale(){return Ot(this.config.lang)}fixContent(){const t=this.selection.range;let e=!1,i=this.container.children();for(const t of i)(t.isBlock||t.isMark)&&""===t.html()&&(t.remove(),e=!0,A(`Content fixed: empty tag "${t.name}" was removed`));if(i=this.container.children(),0===i.length)this.container.html("<p><br /></p>"),t.shrinkBefore(this.container),e=!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),t.shrinkAfter(i),e=!0,A(`Content fixed: void element "${n.name}" was wrapped in paragraph`)}}return t.adjustBr(),e}setPluginConfig(t,e){this.config[t]||(this.config[t]={});for(const i of Object.keys(e))void 0===this.config[t][i]&&(this.config[t][i]=e[i])}removeBoxGarbage(){const t=mt(this.container.id);for(const e of t.values())e.node.get(0).isConnected||(e.unmount(),t.delete(e.node.id))}renderBoxes(){this.removeBoxGarbage();const t=this.container,e=mt(t.id);t.find("lake-box").each((t=>{const i=I(t);if(e.get(i.id))return;Vt(i).render()}))}focus(){this.container.focus()}blur(){this.container.blur()}scrollToCaret(){const t=this.selection.range;if(t.isBox)return;const e=t.getRect();if(0===e.x||0===e.y)return;const i=this.container.get(0).getBoundingClientRect(),n=I('<div class="lake-artificial-caret" />'),s=e.x-i.x,o=e.y-i.y;n.css({position:"absolute",top:`${o}px`,left:`${s}px`,width:`${e.width}px`,height:`${e.height}px`,"z-index":"-1"}),this.overlayContainer.find(".lake-artificial-caret").remove(),this.overlayContainer.append(n);const r=pt(n);(r.left<0||r.right<0||r.top<0||r.bottom<0)&&n.get(0).scrollIntoView({behavior:"instant",block:"center",inline:"nearest"}),n.remove()}setValue(t){t=f(t);const e=new Gt(t),i=e.getFragment();this.container.empty(),this.togglePlaceholderClass(e.getHTML()),this.container.append(i),this.renderBoxes(),this.selection.updateByBookmark()}getValue(){const t=this.history.cloneContainer();let e=new Gt(t).getHTML();return e=g(e),e}render(){const t=f(this.config.value),e=new Gt(t),i=e.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(e.getHTML()),this.container.append(i),De.plugin.loadAll(this),this.readonly||(this.selection.updateByBookmark(),this.history.save({emitEvent:!1})),this.renderBoxes(),this.toolbar&&this.toolbar.render(this),document.addEventListener("copy",this.copyListener),this.readonly||(document.addEventListener("cut",this.cutListener),document.addEventListener("paste",this.pasteListener),document.addEventListener("selectionchange",this.selectionchangeListener),document.addEventListener("click",this.clickListener),window.addEventListener("resize",this.resizeListener),this.bindInputEvents(),this.bindHistoryEvents())}unmount(){this.event.removeAllListeners(),this.history.event.removeAllListeners(),this.root.empty(),this.popupContainer.remove(),document.removeEventListener("copy",this.copyListener),this.readonly||(document.removeEventListener("cut",this.cutListener),document.removeEventListener("paste",this.pasteListener),document.removeEventListener("selectionchange",this.selectionchangeListener),document.removeEventListener("click",this.clickListener),window.removeEventListener("resize",this.resizeListener))}}De.version="0.1.22",De.box=new class{add(t){wt.set(t.name,t)}remove(t){wt.delete(t)}getNames(){return Array.from(wt.keys())}},De.plugin=new class{constructor(){this.pluginList=[]}add(t){this.pluginList.push(t)}loadAll(t){for(const e of this.pluginList)e(t)}};const Ve=[{icon:n.get("numberedList"),value:"numbered",text:t=>t.toolbar.numberedList()},{icon:n.get("bulletedList"),value:"bulleted",text:t=>t.toolbar.bulletedList()},{icon:n.get("checklist"),value:"checklist",text:t=>t.toolbar.checklist()}],Fe=[{icon:n.get("alignLeft"),value:"left",text:t=>t.toolbar.alignLeft()},{icon:n.get("alignCenter"),value:"center",text:t=>t.toolbar.alignCenter()},{icon:n.get("alignRight"),value:"right",text:t=>t.toolbar.alignRight()},{icon:n.get("alignJustify"),value:"justify",text:t=>t.toolbar.alignJustify()}],Re=[{icon:n.get("increaseIndent"),value:"increase",text:t=>t.toolbar.increaseIndent()},{icon:n.get("decreaseIndent"),value:"decrease",text:t=>t.toolbar.decreaseIndent()}],je=[{icon:n.get("italic"),value:"italic",text:t=>t.toolbar.italic()},{icon:n.get("underline"),value:"underline",text:t=>t.toolbar.underline()},{icon:n.get("strikethrough"),value:"strikethrough",text:t=>t.toolbar.strikethrough()},{icon:n.get("superscript"),value:"superscript",text:t=>t.toolbar.superscript()},{icon:n.get("subscript"),value:"subscript",text:t=>t.toolbar.subscript()},{icon:n.get("code"),value:"code",text:t=>t.toolbar.code()}],We=["#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"],qe=[{icon:n.get("removeFormat"),value:"",text:t=>t.toolbar.removeColor()}];for(const t of We)qe.push({value:t.toLowerCase(),text:t.toUpperCase()});const Ue=new Map([["strong","bold"],["em","italic"],["i","italic"],["u","underline"],["s","strikethrough"],["sup","superscript"],["sub","subscript"],["code","code"]]),Ke=[{name:"undo",type:"button",icon:n.get("undo"),tooltip:t=>t.toolbar.undo(),onClick:(t,e)=>{t.command.execute(e)}},{name:"redo",type:"button",icon:n.get("redo"),tooltip:t=>t.toolbar.redo(),onClick:(t,e)=>{t.command.execute(e)}},{name:"selectAll",type:"button",icon:n.get("selectAll"),tooltip:t=>t.toolbar.selectAll(),onClick:(t,e)=>{t.command.execute(e)}},{name:"paragraph",type:"button",icon:n.get("paragraph"),tooltip:t=>t.toolbar.paragraph(),isSelected:t=>!!t.find((t=>"p"===t.name)),onClick:t=>{t.command.execute("heading","p")}},{name:"blockQuote",type:"button",icon:n.get("blockQuote"),tooltip:t=>t.toolbar.blockQuote(),onClick:(t,e)=>{t.command.execute(e)}},{name:"numberedList",type:"button",icon:n.get("numberedList"),tooltip:t=>t.toolbar.numberedList(),isSelected:t=>!!t.find((t=>"ol"===t.name)),onClick:t=>{t.command.execute("list","numbered")}},{name:"bulletedList",type:"button",icon:n.get("bulletedList"),tooltip:t=>t.toolbar.bulletedList(),isSelected:t=>!!t.find((t=>"ul"===t.name&&!t.node.hasAttr("type"))),onClick:t=>{t.command.execute("list","bulleted")}},{name:"checklist",type:"button",icon:n.get("checklist"),tooltip:t=>t.toolbar.checklist(),isSelected:t=>!!t.find((t=>"ul"===t.name&&"checklist"===t.node.attr("type"))),onClick:t=>{t.command.execute("list","checklist")}},{name:"alignLeft",type:"button",icon:n.get("alignLeft"),tooltip:t=>t.toolbar.alignLeft(),isSelected:t=>!!t.find((t=>t.node.isBlock&&"left"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","left")}},{name:"alignCenter",type:"button",icon:n.get("alignCenter"),tooltip:t=>t.toolbar.alignCenter(),isSelected:t=>!!t.find((t=>t.node.isBlock&&"center"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","center")}},{name:"alignRight",type:"button",icon:n.get("alignRight"),tooltip:t=>t.toolbar.alignRight(),isSelected:t=>!!t.find((t=>t.node.isBlock&&"right"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","right")}},{name:"alignJustify",type:"button",icon:n.get("alignJustify"),tooltip:t=>t.toolbar.alignJustify(),isSelected:t=>!!t.find((t=>t.node.isBlock&&"justify"===t.node.css("text-align"))),onClick:t=>{t.command.execute("align","justify")}},{name:"increaseIndent",type:"button",icon:n.get("increaseIndent"),tooltip:t=>t.toolbar.increaseIndent(),onClick:t=>{t.command.execute("indent","increase")}},{name:"decreaseIndent",type:"button",icon:n.get("decreaseIndent"),tooltip:t=>t.toolbar.decreaseIndent(),onClick:t=>{t.command.execute("indent","decrease")}},{name:"bold",type:"button",icon:n.get("bold"),tooltip:t=>t.toolbar.bold(),onClick:(t,e)=>{t.command.execute(e)}},{name:"italic",type:"button",icon:n.get("italic"),tooltip:t=>t.toolbar.italic(),onClick:(t,e)=>{t.command.execute(e)}},{name:"underline",type:"button",icon:n.get("underline"),tooltip:t=>t.toolbar.underline(),onClick:(t,e)=>{t.command.execute(e)}},{name:"strikethrough",type:"button",icon:n.get("strikethrough"),tooltip:t=>t.toolbar.strikethrough(),onClick:(t,e)=>{t.command.execute(e)}},{name:"superscript",type:"button",icon:n.get("superscript"),tooltip:t=>t.toolbar.superscript(),onClick:(t,e)=>{t.command.execute(e)}},{name:"subscript",type:"button",icon:n.get("subscript"),tooltip:t=>t.toolbar.subscript(),onClick:(t,e)=>{t.command.execute(e)}},{name:"code",type:"button",icon:n.get("code"),tooltip:t=>t.toolbar.code(),onClick:(t,e)=>{t.command.execute(e)}},{name:"removeFormat",type:"button",icon:n.get("removeFormat"),tooltip:t=>t.toolbar.removeFormat(),onClick:(t,e)=>{t.command.execute(e)}},{name:"formatPainter",type:"button",icon:n.get("formatPainter"),tooltip:t=>t.toolbar.formatPainter(),onClick:(t,e)=>{t.command.execute(e)}},{name:"link",type:"button",icon:n.get("link"),tooltip:t=>t.toolbar.link(),onClick:(t,e)=>{t.command.execute(e)}},{name:"hr",type:"button",icon:n.get("hr"),tooltip:t=>t.toolbar.hr(),onClick:(t,e)=>{t.command.execute(e)}},{name:"codeBlock",type:"button",icon:n.get("codeBlock"),tooltip:t=>t.toolbar.codeBlock(),onClick:(t,e)=>{t.command.execute(e)}},{name:"video",type:"button",icon:n.get("video"),tooltip:t=>t.toolbar.video(),onClick:(t,e)=>{t.command.execute(e)}},{name:"equation",type:"button",icon:n.get("equation"),tooltip:t=>t.toolbar.equation(),onClick:(t,e)=>{t.command.execute(e)}},{name:"heading",type:"dropdown",downIcon:n.get("down"),defaultValue:"p",tooltip:t=>t.toolbar.heading(),width:"100px",menuType:"list",menuItems:[{value:"h1",text:t=>`<span style="font-weight: bold; font-size: 26px;">${t.toolbar.heading1()}</span>`},{value:"h2",text:t=>`<span style="font-weight: bold; font-size: 24px;">${t.toolbar.heading2()}</span>`},{value:"h3",text:t=>`<span style="font-weight: bold; font-size: 22px;">${t.toolbar.heading3()}</span>`},{value:"h4",text:t=>`<span style="font-weight: bold; font-size: 20px;">${t.toolbar.heading4()}</span>`},{value:"h5",text:t=>`<span style="font-weight: bold; font-size: 18px;">${t.toolbar.heading5()}</span>`},{value:"h6",text:t=>`<span style="font-weight: bold; font-size: 16px;">${t.toolbar.heading6()}</span>`},{value:"p",text:t=>t.toolbar.paragraph()}],onSelect:(t,e)=>{t.command.execute("heading",e)}},{name:"list",type:"dropdown",downIcon:n.get("down"),icon:n.get("list"),tooltip:t=>t.toolbar.list(),menuType:"list",menuItems:Ve,onSelect:(t,e)=>{t.command.execute("list",e)}},{name:"align",type:"dropdown",downIcon:n.get("down"),icon:n.get("alignLeft"),tooltip:t=>t.toolbar.align(),menuType:"list",menuItems:Fe,onSelect:(t,e)=>{t.command.execute("align",e)}},{name:"indent",type:"dropdown",downIcon:n.get("down"),icon:n.get("increaseIndent"),tooltip:t=>t.toolbar.indent(),menuType:"list",menuItems:Re,onSelect:(t,e)=>{t.command.execute("indent",e)}},{name:"fontFamily",type:"dropdown",downIcon:n.get("down"),defaultValue:"Segoe UI",tooltip:t=>t.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:(t,e)=>{t.command.execute("fontFamily",e)}},{name:"fontSize",type:"dropdown",downIcon:n.get("down"),defaultValue:"16px",tooltip:t=>t.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:(t,e)=>{t.command.execute("fontSize",e)}},{name:"moreStyle",type:"dropdown",icon:n.get("more"),tooltip:t=>t.toolbar.moreStyle(),menuType:"list",menuItems:je,selectedValues:t=>{var e;const i=[];for(const n of t)if(n.node.isMark){const t=null!==(e=Ue.get(n.name))&&void 0!==e?e:n.name;i.push(t)}return i},onSelect:(t,e)=>{t.command.execute(e)}},{name:"fontColor",type:"dropdown",downIcon:n.get("down"),icon:n.get("fontColor"),accentIcon:n.get("fontColorAccent"),defaultValue:"#f5222d",tooltip:t=>t.toolbar.fontColor(),menuType:"color",menuItems:qe,menuWidth:"296px",onSelect:(t,e)=>{t.command.execute("fontColor",e)}},{name:"highlight",type:"dropdown",downIcon:n.get("down"),icon:n.get("highlight"),accentIcon:n.get("highlightAccent"),defaultValue:"#fadb14",tooltip:t=>t.toolbar.highlight(),menuType:"color",menuItems:qe,menuWidth:"296px",onSelect:(t,e)=>{t.command.execute("highlight",e)}},{name:"image",type:"upload",icon:n.get("image"),tooltip:t=>t.toolbar.image(),accept:"image/*",multiple:!0},{name:"file",type:"upload",icon:n.get("attachment"),tooltip:t=>t.toolbar.file(),accept:"*",multiple:!0}],Ge=["undo","redo","|","heading","|","formatPainter","removeFormat","bold","moreStyle","|","fontColor","highlight","|","align","list","indent","link","blockQuote","hr"],Xe=new Map;for(const t of Ke)Xe.set(t.name,t);const Ye={type:"block",name:"hr",render:t=>{const e=t.getEditor();if(!e)return;const i=t.getContainer(),n=I('<div class="lake-hr"><hr /></div>');i.empty(),i.append(n),n.on("click",(()=>{e.selection.selectBox(t)}))},html:()=>"<hr />"},Je="#57606a",Qe="#444d56",ti="#953800",ei="#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",fi="#cf222e",gi="#57606a",vi="#57606a",wi="#8250df",yi="#0550ae",xi="#f6f8fa",bi="#cf222e",ki="#0550ae",Si="#005cc5",Ci="#444d56",_i="#444d56";function Bi(t){const{HighlightStyle:e,tags:i}=t;return e.define([{tag:[i.comment,i.lineComment,i.blockComment,i.docComment],color:Je},{tag:[i.name],color:Qe},{tag:[i.variableName,i.self],color:ti},{tag:[i.typeName,i.tagName],color:ei},{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:fi},{tag:[i.punctuation,i.separator,i.bracket,i.angleBracket,i.squareBracket,i.paren,i.brace,i.contentSeparator],color:gi},{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:Si},{tag:[i.standard(i.name)],color:Ci},{tag:[i.special(i.variableName)],color:_i}])}const Ai={type:"block",name:"codeBlock",render:t=>{var e;const i=t.getEditor();if(!i)return;const s=I('<div class="lake-code-block" />'),o=t.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 t.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(t)})));const{EditorState:l,Compartment:c,EditorView:d,keymap:h,history:p,defaultKeymap:u,historyKeymap:m,indentWithTab:f,syntaxHighlighting:g}=a,v=a.langItems,w=i.config.codeBlock,y=v.filter((t=>w.langList.indexOf(t.value)>=0)),x=new Map;for(const t of y)x.set(t.value,t);const b=t.value,k=x.get(b.lang),S=new c,C=ye((e=>{i.selection.updateByRange(),i.isComposing||(t.updateValue("code",e),i.history.save())}),1,{immediate:!1}),_=d.updateListener.of((t=>{t.docChanged&&C(t.state.doc.toString())})),B=new d({parent:r,doc:null!==(e=b.code)&&void 0!==e?e:"",extensions:[l.readOnly.of(i.readonly),d.editable.of(!i.readonly),p(),h.of([...u,...m,f]),g(Bi(a)),S.of(k&&k.component?k.component():[]),_]});s.find('[contenteditable="true"]').attr("tabindex","-1");new zt({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((t=>({value:t.value,text:t.text}))),onSelect:e=>{t.updateValue({lang:e}),t.unmount(),t.render(),i.selection.selectBox(t),i.history.save()}}).render();const T=()=>{o.css("width",i.container.innerWidth()-2+"px")};i.event.on("resize",T),s.on("click",(()=>{B.hasFocus||B.focus()})),t.event.on("beforeunmount",(()=>{B.destroy(),i.event.off("resize",T),A("CodeMirror destroyed")}))}};function Ti(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{l(n.next(t))}catch(t){o(t)}}function a(t){try{l(n.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}l((n=n.apply(t,e||[])).next())}))}
|
|
19
19
|
/*!
|
|
20
20
|
* PhotoSwipe Lightbox 5.4.4 - https://photoswipe.com
|
|
21
21
|
* (c) 2024 Dmytro Semenov
|
|
@@ -54,7 +54,7 @@ function Ei(t,e,i){const n=document.createElement(e);return t&&(n.className=t),i
|
|
|
54
54
|
<button type="button" tabindex="-1" class="lake-button-view" title="${i.locale.image.view()}"></button>
|
|
55
55
|
<button type="button" tabindex="-1" class="lake-button-remove" title="${i.locale.image.remove()}"></button>
|
|
56
56
|
</div>
|
|
57
|
-
`),h=d.find(".lake-button-view"),p=n.get("maximize");p&&h.append(p),(l<80||null===Wi)&&h.hide();const u=d.find(".lake-button-remove"),m=n.get("remove");m&&u.append(m);const f=r.node;f.addClass("lake-image-img"),f.attr({draggable:"false",alt:o.name}),t.append(d),new ts({root:t,box:e,width:l,height:c,onStop:(t,n)=>{e.updateValue({width:t,height:n}),i.history.save()}}).render(),t.append(f)}))}(o,t),r.then((()=>{s.empty(),s.append(o),o.find(".lake-button-view").on("click",(()=>function(t){const e=t.getEditor();if(!e)return;const i=[];let s=0;const o=e.container.find('lake-box[name="image"]');o.each(((e,n)=>{const o=Vt(e),r=o.value;"done"===r.status&&(i.push({id:n,src:r.originalUrl||r.url,width:r.originalWidth||r.width,height:r.originalHeight||r.height,alt:r.name}),t.node.id===o.node.id&&(s=n))}));const r=new Wi({pswpModule:Qn,dataSource:i,mainClass:"lake-pswp",zoom:!1,returnFocus:!1,arrowPrevSVG:n.get("left"),arrowNextSVG:n.get("right"),closeSVG:n.get("close"),arrowPrevTitle:e.locale.image.previous(),arrowNextTitle:e.locale.image.next(),closeTitle:e.locale.image.close(),errorMsg:e.locale.image.loadingError()});
|
|
57
|
+
`),h=d.find(".lake-button-view"),p=n.get("maximize");p&&h.append(p),(l<80||null===Wi)&&h.hide();const u=d.find(".lake-button-remove"),m=n.get("remove");m&&u.append(m);const f=r.node;f.addClass("lake-image-img"),f.attr({draggable:"false",alt:o.name}),t.append(d),new ts({root:t,box:e,width:l,height:c,onStop:(t,n)=>{e.updateValue({width:t,height:n}),i.history.save()}}).render(),t.append(f)}))}(o,t),r.then((()=>{s.empty(),s.append(o),o.find(".lake-button-view").on("click",(()=>function(t){const e=t.getEditor();if(!e)return;const i=[];let s=0;const o=e.container.find('lake-box[name="image"]');o.each(((e,n)=>{const o=Vt(e),r=o.value;"done"===r.status&&(i.push({id:n,src:r.originalUrl||r.url,width:r.originalWidth||r.width,height:r.originalHeight||r.height,alt:r.name}),t.node.id===o.node.id&&(s=n))}));const r=new Wi({pswpModule:Qn,dataSource:i,mainClass:"lake-pswp",zoom:!1,returnFocus:!1,arrowPrevSVG:n.get("left"),arrowNextSVG:n.get("right"),closeSVG:n.get("close"),arrowPrevTitle:e.locale.image.previous(),arrowNextTitle:e.locale.image.next(),closeTitle:e.locale.image.close(),errorMsg:e.locale.image.loadingError()});r.on("uiRegister",(()=>{const t=r.pswp;t.ui.registerElement({name:"zoom-out-button",order:8,isButton:!0,title:e.locale.image.zoomOut(),html:n.get("zoomOut"),onClick:()=>{const e=t.currSlide,i=(e.zoomLevels.max-e.zoomLevels.min)/5,n=e.currZoomLevel-i;e.zoomTo(n,void 0,333)}}),t.ui.registerElement({name:"zoom-in-button",order:9,isButton:!0,title:e.locale.image.zoomIn(),html:n.get("zoomIn"),onClick:()=>{const e=t.currSlide,i=(e.zoomLevels.max-e.zoomLevels.min)/5,n=e.currZoomLevel+i;e.zoomTo(n,void 0,333)}})})),r.addFilter("thumbEl",((t,e)=>{const i=o.eq(e.id).find(".lake-image-img");return i.length>0?i.get(0):t})),r.addFilter("placeholderSrc",((t,e)=>{const i=o.eq(e.data.id).find(".lake-image-img");return i.length>0?i.attr("src"):t})),r.on("openingAnimationEnd",(()=>{t.event.emit("openfullscreen")})),r.on("destroy",(()=>{t.event.emit("closefullscreen")})),r.init(),r.loadAndOpen(s)}(t))),e.readonly?o.find(".lake-button-remove").hide():o.find(".lake-button-remove").on("click",(i=>{i.stopPropagation(),e.selection.removeBox(t),e.history.save()})),t.event.emit("render")})),o.on("click",(()=>{e.selection.selectBox(t)}))},html:t=>{const e=t.node.attr("value");return a`<img src="${t.value.url}" data-lake-value="${e}" />`}};function ss(t){const e=/\w+$/i.exec(t||"");return e?e[0]:""}function os(t){const e=t.getEditor();if(!e)return;const i=t.getContainer().find(".lake-video"),s=I(a`
|
|
58
58
|
<div class="lake-button-group">
|
|
59
59
|
<button type="button" tabindex="-1" class="lake-button-remove" title="${e.locale.video.remove()}"></button>
|
|
60
60
|
</div>
|
|
@@ -107,7 +107,7 @@ function Ei(t,e,i){const n=document.createElement(e);return t&&(n.className=t),i
|
|
|
107
107
|
<path d="M181.66,133.66l-80,80A8,8,0,0,1,88,208V48a8,8,0,0,1,13.66-5.66l80,80A8,8,0,0,1,181.66,133.66Z"></path>
|
|
108
108
|
</svg>
|
|
109
109
|
</div>
|
|
110
|
-
`),t.overlayContainer.append(i)):s.preventDefault()})),t.container.on("dragover",(e=>{const o=e;o.preventDefault();const r=o.dataTransfer;if(!r)return;if(r.dropEffect="move",!i)return;const a=I(o.target);if(a.isContainer)return;const l=a.closest("lake-box");n=l.length>0?l.isBlockBox?l:l.closestBlock():a.closestBlock();const c=t.container.get(0).getBoundingClientRect();let d=n.get(0).getBoundingClientRect();s="bottom";let h=d.x-c.x,p=d.y+d.height-c.y+parseInt(n.computedCSS("margin-bottom"),10)/2;if(o.clientY<d.y+d.height/2){const e=n.prev();e.length>0&&e.isBlock||e.isBlockBox?(n=e,d=n.get(0).getBoundingClientRect(),h=d.x-c.x,p=d.y+d.height-c.y+parseInt(n.computedCSS("margin-bottom"),10)/2):(s="top",p=d.y-c.y-parseInt(t.container.computedCSS("padding-top"),10)/2)}i.css({top:`${p}px`,left:`${h}px`,width:`${d.width}px`,display:"block"})})),t.container.on("dragend",(()=>{i&&(i.remove(),i=null)})),t.container.on("drop",(o=>{const r=o;if(r.dataTransfer&&i&&(i.remove(),i=null,e&&n&&e.isBox)){if(e.get(0)===n.get(0))return;if("bottom"===s&&e.get(0)===n.next().get(0))return;r.preventDefault();const i=Vt(e),o=t.selection.range;n.isBox?"top"===s?o.selectBoxStart(n):o.selectBoxEnd(n):(o.selectNodeContents(n),"top"===s?o.collapseToStart():o.collapseToEnd()),t.selection.insertBox(i.name,i.value),e.remove(),t.history.save()}}))})),De.plugin.add((t=>{t.readonly||(t.command.add("undo",{isDisabled:()=>!t.history.canUndo,execute:()=>{t.history.undo()}}),t.keystroke.setKeydown("mod+z",(e=>{t.selection.range.isInsideBox||(e.preventDefault(),t.command.execute("undo"))})))})),De.plugin.add((t=>{if(t.readonly)return;t.command.add("redo",{isDisabled:()=>!t.history.canRedo,execute:()=>{t.history.redo()}});const e=e=>{t.selection.range.isInsideBox||(e.preventDefault(),t.command.execute("redo"))};t.keystroke.setKeydown("mod+y",e),t.keystroke.setKeydown("mod+shift+z",e)})),De.plugin.add((t=>{t.readonly||t.command.add("selectAll",{execute:()=>{const e=t.selection.range;e.selectNodeContents(t.container),e.shrink()}})})),De.plugin.add((t=>{t.readonly||t.command.add("heading",{selectedValues:t=>{const e=t.find((t=>t.node.isHeading||"p"===t.name));return e?[e.name]:[]},execute:e=>{t.selection.setBlocks(`<${e} />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("blockQuote",{isSelected:t=>!!t.find((t=>"blockquote"===t.name)),execute:e=>{e&&gs.indexOf(e)>=0?t.selection.setBlocks(a`<blockquote type="${e}" />`):t.selection.setBlocks("<blockquote />"),t.history.save()}})})),De.plugin.add((t=>{t.readonly||(t.command.add("list",{selectedValues:t=>{let e;for(const i of t){if("ol"===i.name){e="numbered";break}if("ul"===i.name&&!i.node.hasAttr("type")){e="bulleted";break}if("ul"===i.name&&"checklist"===i.node.attr("type")){e="checklist";break}}return e?[e]:[]},execute:(e,i=!1)=>{const n=t.selection.range.getBlocks();let s=!1,o=!1,r=!1;for(const t of n)s||"ol"!==t.name||(s=!0),o||"ul"!==t.name||t.hasAttr("type")||(o=!0),r||"ul"!==t.name||"checklist"!==t.attr("type")||(r=!0);s?("numbered"===e&&vs(t),"bulleted"===e&&ys(t),"checklist"===e&&xs(t,i)):o?("numbered"===e&&ws(t),"bulleted"===e&&vs(t),"checklist"===e&&xs(t,i)):r?("numbered"===e&&ws(t),"bulleted"===e&&ys(t),"checklist"===e&&vs(t)):("numbered"===e&&ws(t),"bulleted"===e&&ys(t),"checklist"===e&&xs(t,i)),t.history.save()}}),t.container.on("click",(e=>{const i=e;if(!i.target)return;const n=I(i.target);"li"===n.name&&""!==n.attr("value")&&i.offsetX<=18&&(n.attr("value",("true"!==n.attr("value")).toString()),t.history.save())})))})),De.plugin.add((t=>{t.readonly||t.command.add("align",{selectedValues:t=>{let e;for(const i of t)if(i.node.isBlock){e=i.node.computedCSS("text-align");break}return e?[bs[e]||e]:[]},execute:e=>{t.selection.setBlocks({"text-align":e}),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("indent",{execute:e=>{const i=t.selection.range.getBlocks();for(const t of i)R(t,e);t.history.save()}})})),De.plugin.add((t=>{t.readonly||(t.command.add("bold",{isDisabled:t=>!!t.find((t=>t.node.isHeading)),isSelected:t=>!!t.find((t=>t.name===ks)),execute:()=>{t.command.isSelected("bold")?t.selection.removeMark(`<${ks} />`):t.selection.addMark(`<${ks} />`),t.history.save()}}),t.keystroke.setKeydown("mod+b",(e=>{e.preventDefault(),t.command.execute("bold")})))})),De.plugin.add((t=>{t.readonly||(t.command.add("italic",{isSelected:t=>!!t.find((t=>"i"===t.name)),execute:()=>{t.command.isSelected("italic")?t.selection.removeMark("<i />"):t.selection.addMark("<i />"),t.history.save()}}),t.keystroke.setKeydown("mod+i",(e=>{e.preventDefault(),t.command.execute("italic")})))})),De.plugin.add((t=>{t.readonly||(t.command.add("underline",{isSelected:t=>!!t.find((t=>"u"===t.name)),execute:()=>{t.command.isSelected("underline")?t.selection.removeMark("<u />"):t.selection.addMark("<u />"),t.history.save()}}),t.keystroke.setKeydown("mod+u",(e=>{e.preventDefault(),t.command.execute("underline")})))})),De.plugin.add((t=>{t.readonly||(t.command.add("strikethrough",{isSelected:t=>!!t.find((t=>"s"===t.name)),execute:()=>{t.command.isSelected("strikethrough")?t.selection.removeMark("<s />"):t.selection.addMark("<s />"),t.history.save()}}),t.keystroke.setKeydown("mod+shift+x",(e=>{e.preventDefault(),t.command.execute("strikethrough")})))})),De.plugin.add((t=>{t.readonly||t.command.add("subscript",{isSelected:t=>!!t.find((t=>t.name===Ss)),execute:()=>{t.command.isSelected("subscript")?t.selection.removeMark(`<${Ss} />`):t.selection.addMark(`<${Ss} />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("superscript",{isSelected:t=>!!t.find((t=>t.name===Cs)),execute:()=>{t.command.isSelected("superscript")?t.selection.removeMark(`<${Cs} />`):t.selection.addMark(`<${Cs} />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("code",{isSelected:t=>!!t.find((t=>t.name===_s)),execute:()=>{t.command.isSelected("code")?t.selection.removeMark(`<${_s} />`):t.selection.addMark(`<${_s} />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("fontFamily",{selectedValues:t=>{for(const e of t)if("span"===e.name){return[e.node.css("font-family").replace(/['"]/g,"")]}return[]},execute:e=>{t.selection.addMark(`<span style="font-family: ${e};" />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("fontSize",{isDisabled:t=>!!t.find((t=>t.node.isHeading)),selectedValues:t=>{for(const e of t)if("span"===e.name){return[e.node.css("font-size").replace(/\.\d+/,"")]}return[]},execute:e=>{t.selection.addMark(`<span style="font-size: ${e};" />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("fontColor",{selectedValues:t=>{for(const e of t)if("span"===e.name){return[u(e.node.computedCSS("color"))]}return[]},execute:e=>{t.selection.addMark(`<span style="color: ${e};" />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("highlight",{selectedValues:t=>{for(const e of t)if("span"===e.name){return[u(e.node.computedCSS("background-color"))]}return[]},execute:e=>{t.selection.addMark(`<span style="background-color: ${e};" />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("removeFormat",{execute:()=>{t.selection.removeMark(),t.history.save()}})})),De.plugin.add((t=>{if(t.readonly)return;let e=[];t.command.add("formatPainter",{execute:()=>{t.container.addClass(Bs);const i=t.selection.getAppliedItems();for(const t of i){const i=t.node.clone();i.isMark&&"a"!==i.name&&e.push(i)}}}),t.container.on("click",(()=>{if(t.container.removeClass(Bs),0!==e.length){for(const i of e)t.selection.addMark(i);e=[],t.history.save()}})),t.event.on("click",(i=>{if(t.container.contains(i))return;i.closest('button[name="formatPainter"]').length>0||(t.container.removeClass(Bs),e=[])}))})),De.plugin.add((t=>{if(t.readonly)return;const e=new As({root:t.popupContainer,locale:t.locale,onSave:e=>{const i=t.selection.range;i.setStartAfter(e),i.collapseToStart(),t.history.save()},onRemove:e=>{const i=t.selection.range;i.setStartAfter(e),i.collapseToStart(),t.history.save()}});t.root.on("scroll",(()=>{e.updatePosition()})),t.event.on("resize",(()=>{e.updatePosition()})),t.event.on("click",(i=>{if(i.closest('button[name="link"]').length>0)return;const n=i.closest("a");0!==n.length?!t.container.contains(n)||n.closest("lake-box").length>0?e.hide():e.show(n):e.hide()})),t.command.add("link",{execute:()=>{const i=t.selection.insertLink(`<a href="">${t.locale.link.newLink()}</a>`);i&&(t.history.save(),e.show(i))}})})),De.plugin.add((t=>{t.readonly||(t.event.on("beforepaste",(t=>{new qt(t).find("hr").each((t=>{const e=I(t),i=Vt("hr");e.replaceWith(i.node)}))})),t.command.add("hr",{execute:()=>{t.selection.insertBox("hr"),t.history.save()}}))})),De.plugin.add((t=>{window.LakeCodeMirror&&(t.setPluginConfig("codeBlock",{langList:Ts,defaultLang:"text"}),t.readonly||t.command.add("codeBlock",{execute:e=>{const i=t.selection.insertBox("codeBlock",e);t.history.save(),i.getContainer().find(".lake-code-block").emit("click")}}))})),De.plugin.add((t=>{t.setPluginConfig("image",{requestMethod:"POST",requestTypes:["image/gif","image/jpeg","image/png","image/svg+xml"]}),t.readonly||(t.event.on("beforepaste",(t=>{new qt(t).find("img").each((t=>{const e=I(t),i=Vt("image"),n=e.attr("data-lake-value");""===n?i.value={url:e.attr("src"),status:"done"}:i.node.attr("value",n),e.replaceWith(i.node)}))})),t.command.add("image",{execute:e=>{t.selection.insertBox("image",e),t.history.save()}}))})),De.plugin.add((t=>{t.readonly||t.command.add("video",{execute:e=>{const i=t.selection.insertBox("video",e);t.history.save(),i&&i.getContainer().find('input[name="url"]').focus()}})})),De.plugin.add((t=>{t.setPluginConfig("file",{requestMethod:"POST",requestTypes:["application/zip","application/x-zip-compressed","application/vnd.rar","image/gif","image/jpeg","image/png","image/svg+xml","text/plain","text/html","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation"]}),t.readonly||t.command.add("file",{execute:e=>{t.selection.insertBox("file",e),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("emoji",{execute:e=>{t.selection.insertBox("emoji",e),t.history.save()}})})),De.plugin.add((t=>{window.katex&&(t.readonly||t.command.add("equation",{execute:e=>{const i=t.selection.insertBox("equation",e);t.selection.selectBox(i),t.history.save()}}))})),De.plugin.add((t=>{t.readonly||t.command.add("specialCharacter",{execute:e=>{const i=new qt;i.append(document.createTextNode(e)),t.selection.insertFragment(i),t.history.save()}})})),De.plugin.add((t=>{t.readonly||(t.keystroke.setKeydown("space",(e=>{const i=t.selection.range;if(i.isBox)return;const n=function(t){const e=t.selection.range;let i=e.startNode,n=e.startOffset;if(0!==n){if(i.isElement){const t=i.children()[n-1];if(!t||!t.isText)return;i=t,n=i.text().length}if(!(n<1))return{node:i,offset:n}}}(t);if(!n)return;if(function(t,e){const i=t.selection,n=i.range,s=e.offset,o=e.node.text().slice(0,s);for(const e of Is){const r=e.re.exec(o);if(null!==r){const o=e.getParameters(),a=o.shift();if(!t.command.has(a))return!1;t.history.pause();const l=i.insertBookmark(),c=l.focus.prev(),d=c.text(),h=`${d.replace(e.re,"$1")}`;return c.get(0).nodeValue=h,n.setStart(c,s-r[0].length),n.setEnd(c,s-(d.length-h.length)-1),t.command.execute(a,...o),i.toBookmark(l),t.history.continue(),t.history.save(),!0}}return!1}(t,n))return void e.preventDefault();const s=i.getBlocks()[0];s&&(s.isHeading||"p"===s.name)&&function(t,e){const i=t.selection,n=e.offset;let s=e.node.text().slice(0,n);s=s.replace(/[\u200B\u2060]/g,"");for(const e of Ms){const n=e.re.exec(s);if(null!==n){const s=e.getParameters(n),o=s.shift();if(!t.command.has(o))return!1;const r=i.insertBookmark();r.focus.prev().remove();const a=r.focus.closestBlock();return Zs(a),i.range.shrinkAfter(a),i.toBookmark(r),t.command.execute(o,...s),!0}}return!1}(t,n)&&e.preventDefault()})),t.keystroke.setKeydown("enter",(e=>{const i=t.selection.range;if(i.isBox)return;const n=i.getBlocks()[0];return!n||!n.isHeading&&"p"!==n.name||n.find("lake-box").length>0||""!==i.getEndText()?void 0:function(t,e){const i=t.selection;let n=e.text();n=n.replace(/[\u200B\u2060]/g,"");for(const s of Ps){const o=s.re.exec(n);if(null!==o){const n=s.getParameters(o),r=n.shift();return!!t.command.has(r)&&(e.empty(),Zs(e),i.range.shrinkAfter(e),t.command.execute(r,...n),!0)}}return!1}(t,n)?(e.preventDefault(),e.stopImmediatePropagation(),!1):void 0})))})),De.plugin.add((t=>{t.readonly||t.keystroke.setKeydown("enter",(e=>{const i=t.selection.range;if(i.isInsideBox)return;if(e.preventDefault(),t.fixContent(),i.isBox)return Os(t),void t.history.save();if(i.adjust(),i.isInoperative)return;if(i.isBox)return Os(t),void t.history.save();let n=i.getBlocks()[0];if(n||(t.selection.setBlocks("<p />"),n=i.getBlocks()[0]),n.isEmpty&&"p"!==n.name)return t.selection.setBlocks("<p />"),void t.history.save();Ns(t,n),t.history.save()}))})),De.plugin.add((t=>{t.readonly||t.keystroke.setKeydown("shift+enter",(e=>{const i=t.selection.range;if(!i.isInsideBox){if(t.fixContent(),e.preventDefault(),i.isBox)return Hs(t),void t.history.save();if(i.adjust(),!i.isInoperative){if(i.isBox)return Hs(t),void t.history.save();zs(t),t.history.save()}}}))})),De.plugin.add((t=>{t.readonly||t.keystroke.setKeydown("backspace",(e=>{const i=t.selection.range;if(i.isInsideBox){const n=Vt(i.commonAncestor.closest("lake-box")),s=n.value;return void("codeBlock"!==n.name||void 0!==s.code&&""!==s.code||(e.preventDefault(),t.selection.removeBox(n),t.history.save()))}if(t.fixContent(),i.isBoxStart){const n=i.startNode.closest("lake-box"),s=n.prev();if(0===s.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(e.preventDefault(),$s(t,i),t.history.save()))}if(s.isBlock)return s.isEmpty?(e.preventDefault(),s.remove(),t.selection.fixList(),void t.history.save()):(e.preventDefault(),void i.shrinkAfter(s));if(s.isText&&1===s.text().length)return e.preventDefault(),s.remove(),void t.history.save();i.adjustBox()}if(i.isBox)return e.preventDefault(),t.selection.removeBox(),void t.history.save();if(!i.isCollapsed)return e.preventDefault(),t.selection.deleteContents(),""===t.container.html().trim()&&t.setValue("<p><br /><focus /></p>"),void t.history.save();i.adjust();const n=i.getPrevNode();if(n.isBox)return e.preventDefault(),t.selection.removeBox(n),void t.history.save();if(n.isText&&1===n.text().length&&n.parent().isBlock){e.preventDefault();const s=n.closestBlock();if(i.setStartBefore(n),i.collapseToStart(),n.remove(),s.isEmpty){const t=Z(s);i.setStartBefore(t),i.collapseToStart()}return void t.history.save()}const s=i.getNextNode();if("br"===n.name&&s.length>0)return e.preventDefault(),i.setStartBefore(n),i.collapseToStart(),n.remove(),void t.history.save();if(""===i.getStartText()){e.preventDefault();let n=i.getBlocks()[0];if(n||(t.selection.setBlocks("<p />"),n=i.getBlocks()[0]),""!==n.css("margin-left")||""!==n.css("text-indent")||""!==n.attr("indent"))return R(n,"decrease"),void t.history.save();if(n.isList||"blockquote"===n.name)return t.selection.setBlocks("<p />"),void t.history.save();$s(t,n),t.history.save()}}))})),De.plugin.add((t=>{t.readonly||t.keystroke.setKeydown("delete",(e=>{const i=t.selection.range;if(i.isInsideBox)return;if(t.fixContent(),i.isBoxEnd){const n=i.startNode.closest("lake-box"),s=n.next();if(0===s.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(e.preventDefault(),Ds(t,i),t.history.save()))}if(s.isBlock)return s.isEmpty?(e.preventDefault(),s.remove(),t.selection.fixList(),void t.history.save()):(e.preventDefault(),void i.shrinkBefore(s));i.adjustBox()}if(i.isBox)return e.preventDefault(),t.selection.removeBox(),void t.history.save();if(!i.isCollapsed)return e.preventDefault(),t.selection.deleteContents(),""===t.container.html().trim()&&t.setValue("<p><br /><focus /></p>"),void t.history.save();i.adjust();const n=i.getNextNode();if(n.isBox)return e.preventDefault(),t.selection.removeBox(n),void t.history.save();"br"===n.name&&n.next().length>0&&(e.preventDefault(),i.setStartBefore(n),i.collapseToStart(),n.remove(),t.history.save());if(""===i.getEndText()){e.preventDefault();let n=i.getBlocks()[0];n||(t.selection.setBlocks("<p />"),n=i.getBlocks()[0]),Ds(t,n),t.history.save()}}))})),De.plugin.add((t=>{t.readonly||t.keystroke.setKeydown("tab",(e=>{if(!1===t.config.indentWithTab)return;const i=t.selection.range;if(i.isInsideBox)return;e.preventDefault();const n=i.getBlocks();for(const t of n)"p"!==t.name||"2em"===t.css("text-indent")?R(t,"increase"):t.css("text-indent","2em");t.history.save()}))})),De.plugin.add((t=>{t.readonly||(t.keystroke.setKeydown("arrow-left",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(i.isBoxStart){const t=n.prev();return t.isBlock||t.isBox?(e.preventDefault(),t.isInlineBox?void i.selectBox(t):void i.shrinkAfter(t)):(i.setStartBefore(n),void i.collapseToStart())}return i.isBoxEnd?(e.preventDefault(),void i.selectBox(n)):(e.preventDefault(),void i.selectBoxStart(n))}if(!i.isCollapsed)return;const s=i.getPrevNode();s.isBox&&(e.preventDefault(),i.selectBox(s))})),t.keystroke.setKeydown("arrow-right",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(i.isBoxStart)return e.preventDefault(),void i.selectBox(n);if(i.isBoxEnd){const t=n.next();return t.isBlock||t.isBox?(e.preventDefault(),t.isInlineBox?void i.selectBox(t):void i.shrinkBefore(t)):(i.setStartAfter(n),void i.collapseToStart())}return e.preventDefault(),void i.selectBoxEnd(n)}if(!i.isCollapsed)return;const s=i.getNextNode();s.isBox&&(e.preventDefault(),i.selectBox(s))})),t.keystroke.setKeydown("arrow-up",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(n.isBlockBox){const t=n.prev();if(t.isBlock||t.isBox)return e.preventDefault(),void i.shrinkAfter(t)}i.setStartBefore(n),i.collapseToStart()}})),t.keystroke.setKeydown("arrow-down",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(n.isBlockBox){const t=n.next();if(t.isBlock||t.isBox)return e.preventDefault(),void i.shrinkBefore(t)}i.setStartAfter(n),i.collapseToStart()}})))})),De.plugin.add((t=>{t.readonly||t.keystroke.setKeydown("escape",(e=>{const i=t.selection,n=i.range;if(n.isBoxCenter||n.isInsideBox){e.preventDefault();const t=n.commonAncestor.closest("lake-box");return n.selectBoxEnd(t),void i.sync()}t.hasFocus&&(e.preventDefault(),t.blur())}))})),t.Box=Dt,t.Button=xt,t.Dropdown=zt,t.Editor=De,t.Fragment=qt,t.HTMLParser=Gt,t.Nodes=L,t.Range=M,t.TextParser=Xt,t.Toolbar=class{constructor(t){this.placement="top",this.allMenuMap=new Map,this.buttonItemList=[],this.dropdownItemList=[],this.root=I(t.root),this.items=t.items||Ge,t.placement&&(this.placement=t.placement),this.container=I('<div class="lake-toolbar" />'),this.root.addClass("lake-custom-properties")}appendDivider(){this.container.append('<div class="lake-toolbar-divider" />')}appendButton(t,e){new xt({root:this.container,name:e.name,icon:e.icon,tooltip:"string"==typeof e.tooltip?e.tooltip:e.tooltip(t.locale),tabIndex:-1,onClick:()=>{t.focus();const i=t.selection.range;t.container.contains(i.commonAncestor)||i.shrinkAfter(t.container),e.onClick(t,e.name)}}).render()}appendDropdown(t,e){new zt({root:this.container,locale:t.locale,name:e.name,icon:e.icon,accentIcon:e.accentIcon,downIcon:e.downIcon,defaultValue:e.defaultValue,tooltip:e.tooltip,width:e.width,menuType:e.menuType,menuItems:e.menuItems,menuWidth:e.menuWidth,menuHeight:e.menuHeight,tabIndex:-1,placement:"top"===this.placement?"bottom":"top",onSelect:i=>{t.focus(),e.onSelect(t,i)}}).render()}appendUpload(t,e){const i=I(a`
|
|
110
|
+
`),t.overlayContainer.append(i)):s.preventDefault()})),t.container.on("dragover",(e=>{const o=e;o.preventDefault();const r=o.dataTransfer;if(!r)return;if(r.dropEffect="move",!i)return;const a=I(o.target);if(a.isContainer)return;const l=a.closest("lake-box");n=l.length>0?l.isBlockBox?l:l.closestBlock():a.closestBlock();const c=t.container.get(0).getBoundingClientRect();let d=n.get(0).getBoundingClientRect();s="bottom";let h=d.x-c.x,p=d.y+d.height-c.y+parseInt(n.computedCSS("margin-bottom"),10)/2;if(o.clientY<d.y+d.height/2){const e=n.prev();e.length>0&&e.isBlock||e.isBlockBox?(n=e,d=n.get(0).getBoundingClientRect(),h=d.x-c.x,p=d.y+d.height-c.y+parseInt(n.computedCSS("margin-bottom"),10)/2):(s="top",p=d.y-c.y-parseInt(t.container.computedCSS("padding-top"),10)/2)}i.css({top:`${p}px`,left:`${h}px`,width:`${d.width}px`,display:"block"})})),t.container.on("dragend",(()=>{i&&(i.remove(),i=null)})),t.container.on("drop",(o=>{const r=o;if(r.dataTransfer&&i&&(i.remove(),i=null,e&&n&&e.isBox)){if(e.get(0)===n.get(0))return;if("bottom"===s&&e.get(0)===n.next().get(0))return;r.preventDefault();const i=Vt(e),o=t.selection.range;n.isBox?"top"===s?o.selectBoxStart(n):o.selectBoxEnd(n):(o.selectNodeContents(n),"top"===s?o.collapseToStart():o.collapseToEnd()),t.selection.insertBox(i.name,i.value),e.remove(),t.history.save()}}))})),De.plugin.add((t=>{t.readonly||(t.command.add("undo",{isDisabled:()=>!t.history.canUndo,execute:()=>{t.history.undo()}}),t.keystroke.setKeydown("mod+z",(e=>{t.selection.range.isInsideBox||(e.preventDefault(),t.command.execute("undo"))})))})),De.plugin.add((t=>{if(t.readonly)return;t.command.add("redo",{isDisabled:()=>!t.history.canRedo,execute:()=>{t.history.redo()}});const e=e=>{t.selection.range.isInsideBox||(e.preventDefault(),t.command.execute("redo"))};t.keystroke.setKeydown("mod+y",e),t.keystroke.setKeydown("mod+shift+z",e)})),De.plugin.add((t=>{t.readonly||t.command.add("selectAll",{execute:()=>{const e=t.selection.range;e.selectNodeContents(t.container),e.shrink()}})})),De.plugin.add((t=>{t.readonly||t.command.add("heading",{selectedValues:t=>{const e=t.find((t=>t.node.isHeading||"p"===t.name));return e?[e.name]:[]},execute:e=>{t.selection.setBlocks(`<${e} />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("blockQuote",{isSelected:t=>!!t.find((t=>"blockquote"===t.name)),execute:e=>{e&&gs.indexOf(e)>=0?t.selection.setBlocks(a`<blockquote type="${e}" />`):t.selection.setBlocks("<blockquote />"),t.history.save()}})})),De.plugin.add((t=>{t.readonly||(t.command.add("list",{selectedValues:t=>{let e;for(const i of t){if("ol"===i.name){e="numbered";break}if("ul"===i.name&&!i.node.hasAttr("type")){e="bulleted";break}if("ul"===i.name&&"checklist"===i.node.attr("type")){e="checklist";break}}return e?[e]:[]},execute:(e,i=!1)=>{const n=t.selection.range.getBlocks();let s=!1,o=!1,r=!1;for(const t of n)s||"ol"!==t.name||(s=!0),o||"ul"!==t.name||t.hasAttr("type")||(o=!0),r||"ul"!==t.name||"checklist"!==t.attr("type")||(r=!0);s?("numbered"===e&&vs(t),"bulleted"===e&&ys(t),"checklist"===e&&xs(t,i)):o?("numbered"===e&&ws(t),"bulleted"===e&&vs(t),"checklist"===e&&xs(t,i)):r?("numbered"===e&&ws(t),"bulleted"===e&&ys(t),"checklist"===e&&vs(t)):("numbered"===e&&ws(t),"bulleted"===e&&ys(t),"checklist"===e&&xs(t,i)),t.history.save()}}),t.container.on("click",(e=>{const i=e;if(!i.target)return;const n=I(i.target);"li"===n.name&&""!==n.attr("value")&&i.offsetX<=18&&(n.attr("value",("true"!==n.attr("value")).toString()),t.history.save())})))})),De.plugin.add((t=>{t.readonly||t.command.add("align",{selectedValues:t=>{let e;for(const i of t)if(i.node.isBlock){e=i.node.computedCSS("text-align");break}return e?[bs[e]||e]:[]},execute:e=>{t.selection.setBlocks({"text-align":e}),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("indent",{execute:e=>{const i=t.selection.range.getBlocks();for(const t of i)R(t,e);t.history.save()}})})),De.plugin.add((t=>{t.readonly||(t.command.add("bold",{isDisabled:t=>!!t.find((t=>t.node.isHeading)),isSelected:t=>!!t.find((t=>t.name===ks)),execute:()=>{t.command.isSelected("bold")?t.selection.removeMark(`<${ks} />`):t.selection.addMark(`<${ks} />`),t.history.save()}}),t.keystroke.setKeydown("mod+b",(e=>{e.preventDefault(),t.command.execute("bold")})))})),De.plugin.add((t=>{t.readonly||(t.command.add("italic",{isSelected:t=>!!t.find((t=>"i"===t.name)),execute:()=>{t.command.isSelected("italic")?t.selection.removeMark("<i />"):t.selection.addMark("<i />"),t.history.save()}}),t.keystroke.setKeydown("mod+i",(e=>{e.preventDefault(),t.command.execute("italic")})))})),De.plugin.add((t=>{t.readonly||(t.command.add("underline",{isSelected:t=>!!t.find((t=>"u"===t.name)),execute:()=>{t.command.isSelected("underline")?t.selection.removeMark("<u />"):t.selection.addMark("<u />"),t.history.save()}}),t.keystroke.setKeydown("mod+u",(e=>{e.preventDefault(),t.command.execute("underline")})))})),De.plugin.add((t=>{t.readonly||(t.command.add("strikethrough",{isSelected:t=>!!t.find((t=>"s"===t.name)),execute:()=>{t.command.isSelected("strikethrough")?t.selection.removeMark("<s />"):t.selection.addMark("<s />"),t.history.save()}}),t.keystroke.setKeydown("mod+shift+x",(e=>{e.preventDefault(),t.command.execute("strikethrough")})))})),De.plugin.add((t=>{t.readonly||t.command.add("subscript",{isSelected:t=>!!t.find((t=>t.name===Ss)),execute:()=>{t.command.isSelected("subscript")?t.selection.removeMark(`<${Ss} />`):t.selection.addMark(`<${Ss} />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("superscript",{isSelected:t=>!!t.find((t=>t.name===Cs)),execute:()=>{t.command.isSelected("superscript")?t.selection.removeMark(`<${Cs} />`):t.selection.addMark(`<${Cs} />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("code",{isSelected:t=>!!t.find((t=>t.name===_s)),execute:()=>{t.command.isSelected("code")?t.selection.removeMark(`<${_s} />`):t.selection.addMark(`<${_s} />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("fontFamily",{selectedValues:t=>{for(const e of t)if("span"===e.name){return[e.node.css("font-family").replace(/['"]/g,"")]}return[]},execute:e=>{t.selection.addMark(`<span style="font-family: ${e};" />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("fontSize",{isDisabled:t=>!!t.find((t=>t.node.isHeading)),selectedValues:t=>{for(const e of t)if("span"===e.name){return[e.node.css("font-size").replace(/\.\d+/,"")]}return[]},execute:e=>{t.selection.addMark(`<span style="font-size: ${e};" />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("fontColor",{selectedValues:t=>{for(const e of t)if("span"===e.name){return[u(e.node.computedCSS("color"))]}return[]},execute:e=>{t.selection.addMark(`<span style="color: ${e};" />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("highlight",{selectedValues:t=>{for(const e of t)if("span"===e.name){return[u(e.node.computedCSS("background-color"))]}return[]},execute:e=>{t.selection.addMark(`<span style="background-color: ${e};" />`),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("removeFormat",{execute:()=>{t.selection.removeMark(),t.history.save()}})})),De.plugin.add((t=>{if(t.readonly)return;let e=[];t.command.add("formatPainter",{execute:()=>{t.container.addClass(Bs);const i=t.selection.getAppliedItems();for(const t of i){const i=t.node.clone();i.isMark&&"a"!==i.name&&e.push(i)}}}),t.container.on("click",(()=>{if(t.container.removeClass(Bs),0!==e.length){for(const i of e)t.selection.addMark(i);e=[],t.history.save()}})),t.event.on("click",(i=>{if(t.container.contains(i))return;i.closest('button[name="formatPainter"]').length>0||(t.container.removeClass(Bs),e=[])}))})),De.plugin.add((t=>{if(t.readonly)return;const e=new As({root:t.popupContainer,locale:t.locale,onSave:e=>{const i=t.selection.range;i.setStartAfter(e),i.collapseToStart(),t.history.save()},onRemove:e=>{const i=t.selection.range;i.setStartAfter(e),i.collapseToStart(),t.history.save()}});t.root.on("scroll",(()=>{e.updatePosition()})),t.event.on("resize",(()=>{e.updatePosition()})),t.event.on("click",(i=>{if(i.closest('button[name="link"]').length>0)return;const n=i.closest("a");0!==n.length?!t.container.contains(n)||n.closest("lake-box").length>0?e.hide():e.show(n):e.hide()})),t.command.add("link",{execute:()=>{const i=t.selection.insertLink(`<a href="">${t.locale.link.newLink()}</a>`);i&&(t.history.save(),e.show(i))}})})),De.plugin.add((t=>{t.readonly||(t.event.on("beforepaste",(t=>{new qt(t).find("hr").each((t=>{const e=I(t),i=Vt("hr");e.replaceWith(i.node)}))})),t.command.add("hr",{execute:()=>{t.selection.insertBox("hr"),t.history.save()}}))})),De.plugin.add((t=>{window.LakeCodeMirror&&(t.setPluginConfig("codeBlock",{langList:Ts,defaultLang:"text"}),t.readonly||t.command.add("codeBlock",{execute:e=>{const i=t.selection.insertBox("codeBlock",e);t.history.save(),i.getContainer().find(".lake-code-block").emit("click")}}))})),De.plugin.add((t=>{t.setPluginConfig("image",{requestMethod:"POST",requestTypes:["image/gif","image/jpeg","image/png","image/svg+xml"]}),t.readonly||(t.event.on("beforepaste",(t=>{new qt(t).find("img").each((t=>{const e=I(t),i=Vt("image"),n=e.attr("data-lake-value");""===n?i.value={url:e.attr("src"),status:"done"}:i.node.attr("value",n),e.replaceWith(i.node)}))})),t.command.add("image",{execute:e=>{t.selection.insertBox("image",e),t.history.save()}}))})),De.plugin.add((t=>{t.readonly||t.command.add("video",{execute:e=>{const i=t.selection.insertBox("video",e);t.history.save(),i&&i.getContainer().find('input[name="url"]').focus()}})})),De.plugin.add((t=>{t.setPluginConfig("file",{requestMethod:"POST",requestTypes:["application/zip","application/x-zip-compressed","application/vnd.rar","image/gif","image/jpeg","image/png","image/svg+xml","text/plain","text/html","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation"]}),t.readonly||t.command.add("file",{execute:e=>{t.selection.insertBox("file",e),t.history.save()}})})),De.plugin.add((t=>{t.readonly||t.command.add("emoji",{execute:e=>{t.selection.insertBox("emoji",e),t.history.save()}})})),De.plugin.add((t=>{window.katex&&(t.readonly||t.command.add("equation",{execute:e=>{const i=t.selection.insertBox("equation",e);t.selection.selectBox(i),t.history.save()}}))})),De.plugin.add((t=>{t.readonly||t.command.add("specialCharacter",{execute:e=>{const i=new qt;i.append(document.createTextNode(e)),t.selection.insertFragment(i),t.history.save()}})})),De.plugin.add((t=>{t.readonly||(t.keystroke.setKeydown("space",(e=>{const i=t.selection.range;if(i.isBox)return;const n=function(t){const e=t.selection.range;let i=e.startNode,n=e.startOffset;if(0!==n){if(i.isElement){const t=i.children()[n-1];if(!t||!t.isText)return;i=t,n=i.text().length}if(!(n<1))return{node:i,offset:n}}}(t);if(!n)return;if(function(t,e){const i=t.selection,n=i.range,s=e.offset,o=e.node.text().slice(0,s);for(const e of Is){const r=e.re.exec(o);if(null!==r){const o=e.getParameters(),a=o.shift();if(!t.command.has(a))return!1;t.history.pause();const l=i.insertBookmark(),c=l.focus.prev(),d=c.text(),h=`${d.replace(e.re,"$1")}`;return c.get(0).nodeValue=h,n.setStart(c,s-r[0].length),n.setEnd(c,s-(d.length-h.length)-1),t.command.execute(a,...o),i.toBookmark(l),t.history.continue(),t.history.save(),!0}}return!1}(t,n))return void e.preventDefault();const s=i.getBlocks()[0];s&&(s.isHeading||"p"===s.name)&&function(t,e){const i=t.selection,n=e.offset;let s=e.node.text().slice(0,n);s=s.replace(/[\u200B\u2060]/g,"");for(const e of Ms){const n=e.re.exec(s);if(null!==n){const s=e.getParameters(n),o=s.shift();if(!t.command.has(o))return!1;const r=i.insertBookmark();r.focus.prev().remove();const a=r.focus.closestBlock();return Zs(a),i.range.shrinkAfter(a),i.toBookmark(r),t.command.execute(o,...s),!0}}return!1}(t,n)&&e.preventDefault()})),t.keystroke.setKeydown("enter",(e=>{const i=t.selection.range;if(i.isBox)return;const n=i.getBlocks()[0];return!n||!n.isHeading&&"p"!==n.name||n.find("lake-box").length>0||""!==i.getEndText()?void 0:function(t,e){const i=t.selection;let n=e.text();n=n.replace(/[\u200B\u2060]/g,"");for(const s of Ps){const o=s.re.exec(n);if(null!==o){const n=s.getParameters(o),r=n.shift();return!!t.command.has(r)&&(e.empty(),Zs(e),i.range.shrinkAfter(e),t.command.execute(r,...n),!0)}}return!1}(t,n)?(e.preventDefault(),e.stopImmediatePropagation(),!1):void 0})))})),De.plugin.add((t=>{t.readonly||t.keystroke.setKeydown("enter",(e=>{const i=t.selection.range;if(i.isInsideBox)return;if(e.preventDefault(),t.fixContent(),i.isBox)return Os(t),void t.history.save();if(i.adjust(),i.isInoperative)return;if(i.isBox)return Os(t),void t.history.save();let n=i.getBlocks()[0];if(n||(t.selection.setBlocks("<p />"),n=i.getBlocks()[0]),n.isEmpty&&"p"!==n.name)return t.selection.setBlocks("<p />"),void t.history.save();Ns(t,n),t.history.save()}))})),De.plugin.add((t=>{t.readonly||t.keystroke.setKeydown("shift+enter",(e=>{const i=t.selection.range;if(!i.isInsideBox){if(t.fixContent(),e.preventDefault(),i.isBox)return Hs(t),void t.history.save();if(i.adjust(),!i.isInoperative){if(i.isBox)return Hs(t),void t.history.save();zs(t),t.history.save()}}}))})),De.plugin.add((t=>{t.readonly||t.keystroke.setKeydown("backspace",(e=>{const i=t.selection.range;if(i.isInsideBox){const n=Vt(i.commonAncestor.closest("lake-box")),s=n.value;return void(!i.isCollapsed||"codeBlock"!==n.name||void 0!==s.code&&""!==s.code||(e.preventDefault(),t.selection.removeBox(n),t.history.save()))}if(t.fixContent(),i.isBoxStart){const n=i.startNode.closest("lake-box"),s=n.prev();if(0===s.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(e.preventDefault(),$s(t,i),t.history.save()))}if(s.isBlock)return s.isEmpty?(e.preventDefault(),s.remove(),t.selection.fixList(),void t.history.save()):(e.preventDefault(),void i.shrinkAfter(s));if(s.isText&&1===s.text().length)return e.preventDefault(),s.remove(),void t.history.save();i.adjustBox()}if(i.isBox)return e.preventDefault(),t.selection.removeBox(),void t.history.save();if(!i.isCollapsed)return e.preventDefault(),t.selection.deleteContents(),""===t.container.html().trim()&&t.setValue("<p><br /><focus /></p>"),void t.history.save();i.adjust();const n=i.getPrevNode();if(n.isBox)return e.preventDefault(),t.selection.removeBox(n),void t.history.save();if(n.isText&&1===n.text().length&&n.parent().isBlock){e.preventDefault();const s=n.closestBlock();if(i.setStartBefore(n),i.collapseToStart(),n.remove(),s.isEmpty){const t=Z(s);i.setStartBefore(t),i.collapseToStart()}return void t.history.save()}const s=i.getNextNode();if("br"===n.name&&s.length>0)return e.preventDefault(),i.setStartBefore(n),i.collapseToStart(),n.remove(),void t.history.save();if(""===i.getStartText()){e.preventDefault();let n=i.getBlocks()[0];if(n||(t.selection.setBlocks("<p />"),n=i.getBlocks()[0]),""!==n.css("margin-left")||""!==n.css("text-indent")||""!==n.attr("indent"))return R(n,"decrease"),void t.history.save();if(n.isList||"blockquote"===n.name)return t.selection.setBlocks("<p />"),void t.history.save();$s(t,n),t.history.save()}}))})),De.plugin.add((t=>{t.readonly||t.keystroke.setKeydown("delete",(e=>{const i=t.selection.range;if(i.isInsideBox)return;if(t.fixContent(),i.isBoxEnd){const n=i.startNode.closest("lake-box"),s=n.next();if(0===s.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(e.preventDefault(),Ds(t,i),t.history.save()))}if(s.isBlock)return s.isEmpty?(e.preventDefault(),s.remove(),t.selection.fixList(),void t.history.save()):(e.preventDefault(),void i.shrinkBefore(s));i.adjustBox()}if(i.isBox)return e.preventDefault(),t.selection.removeBox(),void t.history.save();if(!i.isCollapsed)return e.preventDefault(),t.selection.deleteContents(),""===t.container.html().trim()&&t.setValue("<p><br /><focus /></p>"),void t.history.save();i.adjust();const n=i.getNextNode();if(n.isBox)return e.preventDefault(),t.selection.removeBox(n),void t.history.save();"br"===n.name&&n.next().length>0&&(e.preventDefault(),i.setStartBefore(n),i.collapseToStart(),n.remove(),t.history.save());if(""===i.getEndText()){e.preventDefault();let n=i.getBlocks()[0];n||(t.selection.setBlocks("<p />"),n=i.getBlocks()[0]),Ds(t,n),t.history.save()}}))})),De.plugin.add((t=>{t.readonly||t.keystroke.setKeydown("tab",(e=>{if(!1===t.config.indentWithTab)return;const i=t.selection.range;if(i.isInsideBox)return;e.preventDefault();const n=i.getBlocks();for(const t of n)"p"!==t.name||"2em"===t.css("text-indent")?R(t,"increase"):t.css("text-indent","2em");t.history.save()}))})),De.plugin.add((t=>{t.readonly||(t.keystroke.setKeydown("arrow-left",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(i.isBoxStart){const t=n.prev();return t.isBlock||t.isBox?(e.preventDefault(),t.isInlineBox?void i.selectBox(t):void i.shrinkAfter(t)):(i.setStartBefore(n),void i.collapseToStart())}return i.isBoxEnd?(e.preventDefault(),void i.selectBox(n)):(e.preventDefault(),void i.selectBoxStart(n))}if(!i.isCollapsed)return;const s=i.getPrevNode();s.isBox&&(e.preventDefault(),i.selectBox(s))})),t.keystroke.setKeydown("arrow-right",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(i.isBoxStart)return e.preventDefault(),void i.selectBox(n);if(i.isBoxEnd){const t=n.next();return t.isBlock||t.isBox?(e.preventDefault(),t.isInlineBox?void i.selectBox(t):void i.shrinkBefore(t)):(i.setStartAfter(n),void i.collapseToStart())}return e.preventDefault(),void i.selectBoxEnd(n)}if(!i.isCollapsed)return;const s=i.getNextNode();s.isBox&&(e.preventDefault(),i.selectBox(s))})),t.keystroke.setKeydown("arrow-up",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(n.isBlockBox){const t=n.prev();if(t.isBlock||t.isBox)return e.preventDefault(),void i.shrinkAfter(t)}i.setStartBefore(n),i.collapseToStart()}})),t.keystroke.setKeydown("arrow-down",(e=>{const i=t.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(n.isBlockBox){const t=n.next();if(t.isBlock||t.isBox)return e.preventDefault(),void i.shrinkBefore(t)}i.setStartAfter(n),i.collapseToStart()}})))})),De.plugin.add((t=>{t.readonly||t.keystroke.setKeydown("escape",(e=>{const i=t.selection,n=i.range;if(n.isBoxCenter||n.isInsideBox){e.preventDefault();const t=n.commonAncestor.closest("lake-box");return n.selectBoxEnd(t),void i.sync()}t.hasFocus&&(e.preventDefault(),t.blur())}))})),t.Box=Dt,t.Button=xt,t.Dropdown=zt,t.Editor=De,t.Fragment=qt,t.HTMLParser=Gt,t.Nodes=L,t.Range=M,t.TextParser=Xt,t.Toolbar=class{constructor(t){this.placement="top",this.allMenuMap=new Map,this.buttonItemList=[],this.dropdownItemList=[],this.root=I(t.root),this.items=t.items||Ge,t.placement&&(this.placement=t.placement),this.container=I('<div class="lake-toolbar" />'),this.root.addClass("lake-custom-properties")}appendDivider(){this.container.append('<div class="lake-toolbar-divider" />')}appendButton(t,e){new xt({root:this.container,name:e.name,icon:e.icon,tooltip:"string"==typeof e.tooltip?e.tooltip:e.tooltip(t.locale),tabIndex:-1,onClick:()=>{t.focus(),e.onClick(t,e.name)}}).render()}appendDropdown(t,e){new zt({root:this.container,locale:t.locale,name:e.name,icon:e.icon,accentIcon:e.accentIcon,downIcon:e.downIcon,defaultValue:e.defaultValue,tooltip:e.tooltip,width:e.width,menuType:e.menuType,menuItems:e.menuItems,menuWidth:e.menuWidth,menuHeight:e.menuHeight,tabIndex:-1,placement:"top"===this.placement?"bottom":"top",onSelect:i=>{t.focus(),e.onSelect(t,i)}}).render()}appendUpload(t,e){const i=I(a`
|
|
111
111
|
<div class="lake-upload" name="${e.name}">
|
|
112
112
|
<input type="file" />
|
|
113
113
|
</div>
|