diff --git a/dist/index.js b/dist/index.js index 81a1d45..eedc786 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -(()=>{var t={888:t=>{"use strict";t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var n="",o=void 0!==e[5];return e[4]&&(n+="@supports (".concat(e[4],") {")),e[2]&&(n+="@media ".concat(e[2]," {")),o&&(n+="@layer".concat(e[5].length>0?" ".concat(e[5]):""," {")),n+=t(e),o&&(n+="}"),e[2]&&(n+="}"),e[4]&&(n+="}"),n})).join("")},e.i=function(t,n,o,r,i){"string"==typeof t&&(t=[[null,t,void 0]]);var s={};if(o)for(var a=0;a0?" ".concat(d[5]):""," {").concat(d[1],"}")),d[5]=i),n&&(d[2]?(d[1]="@media ".concat(d[2]," {").concat(d[1],"}"),d[2]=n):d[2]=n),r&&(d[4]?(d[1]="@supports (".concat(d[4],") {").concat(d[1],"}"),d[4]=r):d[4]="".concat(r)),e.push(d))}},e}},864:t=>{"use strict";t.exports=function(t,e){return e||(e={}),t?(t=String(t.__esModule?t.default:t),/^['"].*['"]$/.test(t)&&(t=t.slice(1,-1)),e.hash&&(t+=e.hash),/["'() \t\n]|(%20)/.test(t)||e.needQuotes?'"'.concat(t.replace(/"/g,'\\"').replace(/\n/g,"\\n"),'"'):t):t}},744:t=>{"use strict";t.exports=function(t){return t[1]}},424:()=>{window._iconfont_svg_string_3243125='',function(t){var e,n=(e=(e=document.getElementsByTagName("script"))[e.length-1]).getAttribute("data-injectcss");if(!(e=e.getAttribute("data-disable-injectsvg"))){var o,r,i,s,a;if(n&&!t.__iconfont__svg__cssinject__){t.__iconfont__svg__cssinject__=!0;try{document.write("")}catch(e){console&&console.log(e)}}o=function(){var e,n=document.createElement("div");n.innerHTML=t._iconfont_svg_string_3243125,(n=n.getElementsByTagName("svg")[0])&&(n.setAttribute("aria-hidden","true"),n.style.position="absolute",n.style.width=0,n.style.height=0,n.style.overflow="hidden",(e=document.body).firstChild?function(t,e){e.parentNode.insertBefore(t,e)}(n,e.firstChild):e.appendChild(n))},document.addEventListener?~["complete","loaded","interactive"].indexOf(document.readyState)?setTimeout(o,0):(r=function(){document.removeEventListener("DOMContentLoaded",r,!1),o()},document.addEventListener("DOMContentLoaded",r,!1)):document.attachEvent&&(i=o,s=t.document,a=!1,function t(){try{s.documentElement.doScroll("left")}catch(e){return void setTimeout(t,50)}l()}(),s.onreadystatechange=function(){"complete"==s.readyState&&(s.onreadystatechange=null,l())})}function l(){a||(a=!0,i())}}(window)},112:(t,e,n)=>{"use strict";n.d(e,{c:()=>p});var o=n(744),r=n.n(o),i=n(888),s=n.n(i),a=n(864),l=n.n(a),c=new URL(n(392),n.b),d=s()(r()),h=l()(c);d.push([t.id,`.editor-tool-bar{border:solid 1px #eee;background:#282828;padding:6px}.editor-tool-bar .icon{width:1.2em;height:1.2em;vertical-align:-.15em;fill:currentColor;overflow:hidden}.editor-tool-bar .editor-tool-bar-item{padding:4px 10px;display:inline-block;border-radius:4px;cursor:pointer;user-select:none}.editor-tool-bar #editor-content{padding:16px;min-height:200px}.editor-tool-bar .editor-tooltip{position:relative;display:inline-block}.editor-tool-bar .editor-tooltip .tooltiptext{opacity:0;width:60px;font-size:12px;background-color:#000;color:#fff;text-align:center;border-radius:6px;padding:5px 0;position:absolute;z-index:1;top:140%;left:50%;margin-left:-30px;transition:opacity 600ms ease-out}.editor-tool-bar .editor-tooltip .tooltiptext::after{content:'';position:absolute;left:50%;margin-left:-5px;border-width:5px;border-style:solid}.editor-tool-bar .editor-tooltip:hover .tooltiptext{opacity:1}.editor-tool-bar .editor-tooltip .tooltiptext.bottom{top:140%}.editor-tool-bar .editor-tooltip .tooltiptext.bottom::after{bottom:100%;border-color:transparent transparent #000 transparent}.editor-tool-bar .editor-tooltip .tooltiptext.top{top:-140%}.editor-tool-bar .editor-tooltip .tooltiptext.top::after{top:100%;border-color:#000 transparent transparent transparent}.editor-tool-bar .picker{display:flex;justify-content:space-between;margin-top:4px}.editor-tool-bar .left,.editor-tool-bar .hue{font-size:0;height:10px;width:200px;background:linear-gradient(to left,#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00)}.editor-tool-bar .left .hue-picker,.editor-tool-bar .hue .hue-picker{display:inline-block;position:relative;width:6px;height:12px;transform:translate(-6px,-1px);background-color:#f8f8f8;box-shadow:rgba(0,0,0,0.37) 0 1px 4px 0}.editor-tool-bar .transparency{position:relative;font-size:0;height:10px;width:200px;background:url(${h}) left center}.editor-tool-bar .transparency-picker-bg{height:100%}.editor-tool-bar .transparency-picker{display:inline-block;position:relative;width:6px;height:12px;transform:translate(-6px,-1px);background-color:#f8f8f8;box-shadow:rgba(0,0,0,0.37) 0 1px 4px 0}.editor-tool-bar .right{position:relative;cursor:pointer}.editor-tool-bar .color-block{width:24px;height:24px;position:absolute;top:0}.editor-tool-bar .color-block-bg{width:24px;height:24px;background:url(${h}) left center}.editor-tool-bar .palette{width:228px;height:150px;overflow:hidden;border:#eee solid 1px}.editor-tool-bar .palette-picker{pointer-events:none;display:inline-block;position:relative;width:12px;height:12px;border-radius:50%;box-shadow:#fff 0 0 0 1px inset;transform:translate(-6px,-6px)}`,""]);const p=d},196:(t,e,n)=>{"use strict";n.d(e,{c:()=>a});var o=n(744),r=n.n(o),i=n(888),s=n.n(i)()(r());s.push([t.id,"#editor-content:focus,.custom-input:focus{outline:none}#editor-content{word-break:break-all;padding:15px}#editor-content .custom-input-iframe{top:-100px;left:0;background:transparent;color:transparent;width:0;height:0;pointer-events:none;border:none;caret-color:transparent;position:absolute}#editor-content .custom-caret{top:-100px;left:0;pointer-events:none;position:absolute;width:2px;border:none;padding:0;display:block;animation:caret 1s infinite .5s steps(1,start)}#editor-content .editor-disabled{user-select:none}#editor-content ::selection{background:#bad2fa}#editor-content table td,#editor-content td{background-color:#fff}#editor-content table td,#editor-content th,#editor-content td{display:table-cell;margin:0;padding:0;text-align:left;vertical-align:middle}@-moz-keyframes static-caret{0%{opacity:1}100%{opacity:1}}@-webkit-keyframes static-caret{0%{opacity:1}100%{opacity:1}}@-o-keyframes static-caret{0%{opacity:1}100%{opacity:1}}@keyframes static-caret{0%{opacity:1}100%{opacity:1}}@-moz-keyframes caret{0%{opacity:1}50%{opacity:0}100%{opacity:1}}@-webkit-keyframes caret{0%{opacity:1}50%{opacity:0}100%{opacity:1}}@-o-keyframes caret{0%{opacity:1}50%{opacity:0}100%{opacity:1}}@keyframes caret{0%{opacity:1}50%{opacity:0}100%{opacity:1}}",""]);const a=s},764:t=>{"use strict";var e=[];function n(t){for(var n=-1,o=0;o{"use strict";var e={};t.exports=function(t,n){var o=function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(t){n=null}e[t]=n}return e[t]}(t);if(!o)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");o.appendChild(n)}},456:t=>{"use strict";t.exports=function(t){var e=document.createElement("style");return t.setAttributes(e,t.attributes),t.insert(e,t.options),e}},252:(t,e,n)=>{"use strict";t.exports=function(t){var e=n.nc;e&&t.setAttribute("nonce",e)}},520:t=>{"use strict";t.exports=function(t){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var e=t.insertStyleElement(t);return{update:function(n){!function(t,e,n){var o="";n.supports&&(o+="@supports (".concat(n.supports,") {")),n.media&&(o+="@media ".concat(n.media," {"));var r=void 0!==n.layer;r&&(o+="@layer".concat(n.layer.length>0?" ".concat(n.layer):""," {")),o+=n.css,r&&(o+="}"),n.media&&(o+="}"),n.supports&&(o+="}");var i=n.sourceMap;i&&"undefined"!=typeof btoa&&(o+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),e.styleTagTransform(o,t,e.options)}(e,t,n)},remove:function(){!function(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t)}(e)}}}},992:t=>{"use strict";t.exports=function(t,e){if(e.styleSheet)e.styleSheet.cssText=t;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(t))}}},392:t=>{"use strict";t.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAADFJREFUOE9jZGBgEGHAD97gk2YcNYBhmIQBgWSAP52AwoAQwJvQRg1gACckQoC2gQgAIF8IscwEtKYAAAAASUVORK5CYII="}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={id:o,exports:{}};return t[o](i,i.exports,n),i.exports}n.m=t,n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.b=document.baseURI||self.location.href,n.nc=void 0,(()=>{"use strict";var t={};n.r(t),n.d(t,{classCheck:()=>$,computeLen:()=>v,debounce:()=>x,isClass:()=>B,isDef:()=>g,isFunction:()=>z,isPrimitive:()=>y,isUndef:()=>m,mergeObj:()=>A,mergePointsContainer:()=>T,mergeTextPath:()=>N,multiplication:()=>k,positionCompare:()=>M,setStyle:()=>S,stringify:()=>O,styleToObj:()=>E,throttle:()=>b,times:()=>L,toRawType:()=>C,typeOf:()=>P,uuid:()=>R});var e={};n.r(e),n.d(e,{Caret:()=>me,appendChild:()=>Ve,createElm:()=>Me,domToVNode:()=>De,initIntercept:()=>Ne,insertBefore:()=>Fe,nativeDocument:()=>Be,nativeSelection:()=>_e,nativeWindow:()=>ze,removeChild:()=>Ie,replaceChild:()=>He,updateProps:()=>Le});const o=new WeakMap,r=new WeakMap,i=new WeakMap,s=new WeakMap;function a(t){return i.get(t)}function l(t){if(t.vnodeType){const e=s.get(t);if(e)return e;if(3===t.vnodeType)return null;const n=a(t),o=c(n);return 1===n.vnodeType?s.get(n):s.get(o)}{const e=s.get(t);if(!e)return;return e}}function c(t){return r.get(t)}function d(t){return 1===t.vnodeType?o.get(i.get(t)):2===t.vnodeType?o.get(i.get(r.get(t))):o.get(t)}function h(t,e){o.set(e,t).set(t,e)}function p(t,e){r.set(e,t).set(t,e)}function u(t,e){s.set(t,e).set(e,t)}function f(t,e){return i.set(e,t).set(t,e)}function m(t){return null==t}function g(t){return null!=t}function y(t){return"string"==typeof t||"number"==typeof t||"symbol"==typeof t||"boolean"==typeof t}function v(t){return y(t.node.data)?t.node.data.length:t.children.length?t.children.reduce(((t,e)=>t+v(e)),0):0}function b(t,e,n=!0){let o,r,i;return function(){const s=this,a=arguments;o?(clearTimeout(r),r=setTimeout((function(){Date.now()-i>=e&&(t.apply(s,a),i=Date.now())}),Math.max(e-(Date.now()-i),0))):(n&&t.apply(s,a),i=Date.now(),o=!0)}}function x(t,e=0){let n;return function(...o){clearTimeout(n),n=setTimeout((()=>t.apply(this,o)),e)}}window.aa={setVdomOrElm:h,setVnodeOrIns:p,setVdomOrPath:u,getVdomOrElm:d,getVdomOrPath:l,getVnodeOrIns:c};const w=Object.prototype.toString;function C(t){return w.call(t).slice(8,-1).toLowerCase()}function S(t,e){for(const n in e)t.style[n]=e[n]}function k(t,e){return t.replace(/(\d*).*/,(function(t,n){return n*e}))}function O(t){let e=[],n=JSON.stringify(t,((t,n)=>{if("object"==typeof n&&null!==n){if(-1!==e.indexOf(n))return"Circular reference";e.push(n)}return n}));return e=null,n}function E(t){return(t=t.trim()).split(";").filter((t=>t)).reduce(((t,e)=>{const n=e.split(":");return t[n[0].trim()]=n[1].trim(),t}),{})}function R(){return([1e3]+-1e3+-4e3+-8e3).replace(/[018]/g,(t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16)))}function A(t,e){for(let n in e)e.hasOwnProperty(n)&&m(t[n])&&!m(e[n])&&(t[n]=e[n])}function L(t,e,n=void 0,...o){let r=0;for(;r++r)return 1;if(e{if(!t.prototype.hasOwnProperty(e))throw new Error(`please overwrite ${e} method`)}))}function T(t,e,n){n.selection.rangePoints.filter((e=>e.container===t)).forEach((t=>{"start"===t.pointName?t.range.setStart(e,e.length+t.offset):t.range.setEnd(e,e.length+t.offset)}))}function N(t,e){const n=t[0],o=t.length;if(1===o)return n;for(let t=0;t{t.moveTo(e)})),e.insertAfter(this),[this,e]}}clone(t=!1){let e;return e=t?y(this.node.data)?this.node.data:JSON.parse(JSON.stringify(this.node.data)):y(this.node.data)?"":this.node.data?[]:{},F({data:e,formats:{...this.node.formats}})}positionCompare(t){return M(this,t)}originOf(t){return this.position.includes(t.position+"-")}insertBefore(t){this.delete(),t.parent.splice(t.index,0,this)}insertAfter(t){this.delete(),t.parent.splice(t.index+1,0,this)}moveTo(t){this.delete(),t.push(this)}delete(){this.parent&&(this.rebuildFlag=1,this.parent.rebuild(),this.parent.component.update())}push(...t){t.forEach((t=>t.rebuildFlag=0)),this.children.push(...t),this.rebuild(),this.component.update()}pop(){const t=this.children[this.children.length-1];return t.rebuildFlag=1,this.rebuild(),this.component.update(),t}unshift(...t){t.forEach((t=>t.rebuildFlag=0)),this.children.unshift(...t),this.rebuild(),this.component.update()}shift(){const t=this.children[0];return t.rebuildFlag=1,this.rebuild(),this.component.update(),t}splice(t,e,...n){const o=[];if(n.length&&(n.forEach((t=>t.rebuildFlag=0)),this.children.splice(t,0,...n)),e>0)for(let n=0;n{for(var i=0;it.rebuild()))}rebuild(t=!1){if("Array"!==this.dataType)return;let e=null;this.children=this.children.filter((t=>1!==t.rebuildFlag)),this.node.data.length=0,this.children.forEach(((t,n)=>{t.parent=this,this.node.data.push(t.node),t.prevSibling=e,e&&(e.nextSibling=t),t.nextSibling=null,e=t,t.index=n}))}}function F(t,e=null,n=null,o=null,r=0){t.formats||(t.formats={});const i=new _({node:t,parent:e,index:r,prevSibling:n,nextSibling:o,children:[]});if(t.data){let e=null;t.data.reduce?.(((t,n,o)=>(e=F(n,i,t,null,o),t&&(t.nextSibling=e),e.prevSibling=t,i.children.push(e),e)),null)}return i}function H(t,e){if(t instanceof _)return t;if(t.nodeType)return function(t){const e=d(t);return e?V(e):null}(t);if(t.vnodeType)return V(t);if("string"==typeof t)return I(t,e);throw"queryPath的参数必须是elm|vn|position"}function V(t){return l(t)||null}function I(t,e){return t.split("-").slice(1).reduce(((t,e)=>t.children[e]),e)}const D=["ref","key","ns"],j=["ns"];function K(t,e,n=[]){e=e||{};const o={},r={};for(let t of D)r[t]=e[t]||null;for(let t in e)D.includes(t)||("style"===t&&y(e[t])?o[t]=E(e[t]):o[t]=e[t]);return function(t,e,n,o){let r;if("text"===t)r={_uuid:R(),vnodeType:3,type:"text",children:o.join("")};else{r={_uuid:R(),vnodeType:B(t)?2:z(t)?1:4,type:t,...e,props:n};const i={};for(let t of j)i[t]=r[t];1===r.vnodeType||2===r.vnodeType?r.props.children=U(o,i):r.children=U(o,i)}return r}(t,r,o,n.flat())}const U=(t,e)=>t.filter((t=>""!==t)).map((t=>y(t)||m(t)?{_uuid:R(),type:"text",vnodeType:3,children:t}:(A(t,e),t))),q=class{formatMap=new Map;register(t){t.forEach((t=>{this.formatMap.set(t.name,t)}))}inject(t,e){this[t]=e}renderRoot(t){return this.render({children:[t]})}render(t){const e=this._group({paths:t.children,restFormats:this.types},0);return this._generateGroups(e,t.isBlock&&0===t.length)}_invokeRender(t,e){return e.fmt.render(t,e.value,K)}_generateGroups(t,e){return t.map((t=>{let n;const o=this._getFormats(t.commonFormats);if(0===t.commonFormats.length){if(-1!==t.children.findIndex((t=>"object"==typeof t.node.data)))throw"格式标记不合法,文本格式不可用于标记非文本的结构";const n=N(t.children,this.editor);let o=null;return e?(o=K("br"),u(n,n.parent.vn),n.clearFormat()):(""===n.node.data&&console.warn("非法空标签:",n),o=K("text",{},[n.node.data]),u(n,o)),o}if((n=o.filter((t=>"component"===t.fmt.type))).length){const e=t.children[0],o=n[0].fmt.render(null,{path:e,editor:this.editor},n[0].value,K);return u(e,o),o}{let n=null,r=null;const i=[];for(let t=0;t"object"==typeof t.data)))throw"格式标记不合法,文本格式不可用于标记非文本的结构";const n=N(t.children,this.editor);let o=null;e?(o=K("br"),u(n,r),n.clearFormat()):(""===n.node.data&&console.warn("非法空标签:",n),o=K("text",{},[n.node.data]),u(n,o)),r.children=[o]}return n}})).filter((t=>t))}get types(){return[...this.formatMap.keys()]}_getFormats(t){return t.map((t=>{const e=Object.keys(t)[0];return{fmt:this.formatMap.get(e),value:t[e]}}))}get(t){return this.formatMap.get(t)||{}}_canAdd(t,e,n){return!!t.node.formats[n]&&(!e.node.formats[n]||e.node.formats[n]===t.node.formats[n]||void 0)}_group(t,e,n=[]){const o={commonFormats:[],children:[]};let r=[],i=null,s={},a=0;for(;e{i?this._canAdd(l,i,t)&&s[t]++:(s[t]=0,l.node.formats[t]&&s[t]++)}));const c=Math.max(...Object.values(s));if(i&&Object.keys(l.node.formats).some((t=>"component"===this.get(t).type))){i=null;break}if(i&&Object.keys(i.node.formats).some((t=>"component"===this.get(t).type))){i=null;break}if(i&&0===a&&c>a){s=n;break}if(i&&c===a&&0!==c){s=n;break}o.children.push(l),o.commonFormats=Object.entries(s).filter((t=>t[1]&&t[1]===c)).map((n=>({[n[0]]:t.paths[e].node.formats[n[0]]}))),r=t.restFormats.filter((t=>!o.commonFormats.some((e=>e[t])))),a=c,i=l}return o.commonFormats.length>0&&o.children.length>1&&(o.children=this._group({paths:o.children,restFormats:r},0)),n.push(o),e{"function"==typeof t.onUnmounted&&t.onUnmounted()})),n=null}}}(t,n,a,c)}(n,r,o)}}function Z(t,e){if(e!==t){if(!t){const t=c(e),n=a(t),o=t.generateVdom(K);return f(t,o),W(o,n),d(o)}if(m(e))return xt.platform.createElm(t);if(g(e.nodeType)&&h(e,e=xt.platform.domToVNode(e)),G(t,e))W(t,e);else{let n=d([1,2].includes(e.vnodeType)?Q(e):e);const o=xt.platform.createElm(t);tt(e,"onUnmounted"),xt.platform.replaceChild(n.parentNode,o,n),tt(t,"onMounted")}return d([1,2].includes(t.vnodeType)?Q(t):t)}}function tt(t,e){const n=t.vnodeType?c(t):t;n&&"function"==typeof n[e]&&n[e]()}const et=[],nt=[];function ot(){let t,e;for(;t=et.shift();){const{partialState:e,component:n}=t;n.prevState||(n.prevState=Object.assign({},n.state)),"function"==typeof e?Object.assign(n.state,e(n.prevState,n.props)):Object.assign(n.state,e),n.prevState=n.state}for(;e=nt.shift();)e.shouldComponentUpdate()&&e.syncUpdate()}class rt{static isComponent=!0;get isComponent(){return!0}state={};$nextTick=t=>Promise.resolve().then(t);constructor(t){this.props=Object.freeze({...t})}render(t){throw Error('Component does not implement a required interface "render"')}generateVdom(t){return"function"==typeof this.onBeforeRender&&this.onBeforeRender(),this.render(t)}setState(t={}){return function(t,e){let n=null;var o;return 0===et.length&&(o=ot,n=Promise.resolve().then(o)),et.push({partialState:t,component:e}),nt.some((t=>t===e))||nt.push(e),n||Promise.resolve()}(t,this)}syncUpdate(){Z(null,c(this))}shouldComponentUpdate(){return!0}}function it(t,e,n){if(e.inputState.isComposing)return;if(!e.collapsed&&!n.shiftKey)return void e.collapse("left"===t);const{shiftKey:o}=n;if(e.collapsed||o)return e.container.component.onCaretMove(t,e,n);e.collapse("left"===t)}function st(t,e,n){e.inputState.isComposing||(e.collapsed||n.shiftKey?lt(e,"up"===t?"left":"right",{...e.caret.rect,block:e.container.block},{...e.caret.rect,block:e.container.block},!1,n):e.collapse("up"===t))}function at(t,e,n,o){if(n.block!==e.block)return!1;let r=!0;return("left"===o&&n.x>e.x||"right"===o&&n.xt===this));this.caret.remove(),this.editor.selection.ranges.splice(t,1)}}class gt{ranges=[];nativeSelection=xt.platform.nativeSelection;constructor(t){this.editor=t}get collapsed(){return this.ranges.every((t=>t.collapsed))}get rangeCount(){return this.ranges.length}get rangePoints(){const t=[];return this.ranges.forEach((e=>{t.push({container:e.startContainer,offset:e.startOffset,range:e,pointName:"start"},{container:e.endContainer,offset:e.endOffset,range:e,pointName:"end"})})),t}get rangesSnapshot(){return this.ranges.map((t=>t.snapshot))}clearRanges(){for(;this.ranges.length;)this.ranges.pop().caret.remove()}createRange(t){return new mt(t,this.editor)}createRangeFromNativeRange(t){const{startContainer:e,endContainer:n,startOffset:o,endOffset:r,collapsed:i}=t,{focusNode:s,focusOffset:a}=this.nativeSelection;let l=0;return l=i?0:s===n&&a===r?1:-1,this.createRange({startContainer:this.amendPathOffset(e).path,endContainer:this.amendPathOffset(n).path,startOffset:o,endOffset:r,d:l})}addRange(t){this.ranges.push(t)}collapse(t,e){this.nativeSelection.collapse(t,e),this._resetRangesFromNative()}amendPathOffset(t,e){const n=this.editor.queryPath(t);return n?n.isLeaf&&3!==n.pathType?this.amendPathOffset(n.elm.parentNode,n.index+1):{path:n,offset:e}:this.amendPathOffset(t.parentNode,e)}amendRange(t){const{startContainer:e,endContainer:n,startOffset:o,endOffset:r}=t,i=this.amendPathOffset(e,o),s=this.amendPathOffset(n,r);return t.setStart(i.path.elm,i.offset),t.setEnd(s.path.elm,s.offset),t}_resetRangesFromNative(){this.clearRanges();const t=this.nativeSelection.rangeCount;for(let e=0;e0){const e=this.amendRange(this.nativeSelection.getRangeAt(t-1));if(!e)return;let n=!1;if(this.ranges.forEach((t=>{t.endContainer===e.endContainer&&t.startOffset===e.startOffset&&(n=!0,t.remove())})),n)return;this.addRange(this.createRangeFromNativeRange(e))}}getRangeAt(t=0){return this.ranges[t]}removeAllRanges(){this.nativeSelection.removeAllRanges(),this.clearRanges()}createNativeRange({startContainer:t,startOffset:e,endContainer:n,endOffset:o}){const r=document.createRange();return r.setStart(t,e),r.setEnd(n,o),r}updatePoints(t,e,n,o){this.rangePoints.forEach((r=>{r.container===t&&e<=r.offset&&(r.range[r.pointName+"Offset"]+=n,o&&(r.range[r.pointName+"Container"]=o))}))}updateRangesFromNative(t){setTimeout((()=>{t?this._extendRangesFromNative():this._resetRangesFromNative(),this.updateCaret()}))}updateCaret(t=!0){this.ranges.forEach((e=>e.updateCaret(t))),this.rangeCount>1&&this._distinct(),t&&this.drawRangeBg()}_isCoverd(t,e){return t.y=e.y+e.height:e.y+e.height>=t.y+t.height}_distinct(){let t={},e=this.ranges.length;if(!(e<2)){for(let n=0;no.caret.rect.x===t[1].caret.rect.x));0===i.length?t[r]=o:this._isCoverd(o.caret.rect,i[0][1].caret.rect)?(o.caret.remove(),this.ranges.splice(n,1),e--,n--):t[r]=o}}t=null}}drawRangeBg(t){const e=t||this.getRangeAt(0);if(!e)return;const{startContainer:n,startOffset:o,endContainer:r,endOffset:i}=e;this.nativeSelection.removeAllRanges();const s={startContainer:n.elm,endContainer:r.elm,startOffset:o,endOffset:i};this.nativeSelection.addRange(this.createNativeRange(s))}getSeletedPath(){if(this.collapsed)return[];const t=this.ranges[0];let e,n,o,r=!1;if(t.collapsed)r=!0;else{if(0===t.startOffset)e=t.startContainer;else if(t.startOffset===t.startContainer.length)e=t.startContainer.nextLeaf;else{const n=t.startContainer.split(t.startOffset);this.updatePoints(t.startContainer,t.startOffset,-t.startOffset,n[1]),e=n[1]}if(0===t.endOffset)n=t.endContainer.prevLeaf;else if(t.endOffset===t.endContainer.length)n=t.endContainer;else{const e=t.endContainer.split(t.endOffset);this.updatePoints(t.endContainer,t.endOffset+1,-t.endOffset,e[1]),n=e[0]}}return o=e,{length:0,next:function(){if(r)return{value:void 0,done:r};{const t={value:o,done:r};return r=o===n,o=o.nextLeaf,this.length++,t}},[Symbol.iterator]:function(){return this}}}recoverRangesFromSnapshot(t){this.removeAllRanges(),this.ranges=t.map((t=>this.createRange({startContainer:this.editor.queryPath(t.startContainer),endContainer:this.editor.queryPath(t.endContainer),startOffset:t.startOffset,endOffset:t.endOffset,d:t.d}))),this.updateCaret()}}class yt{steps=[];startRanges=[];endRanges=[];commited=!1;constructor(t){this.editor=t,this.init()}init(){this.startRanges=this.editor.selection.rangesSnapshot}addAndApplyStep(t){return this.steps.push(t),t.apply(this.editor)}addStep(...t){this.steps.push(...t)}commit(){if(0===this.steps.length)return this;this.endRanges=this.editor.selection.rangesSnapshot,this.editor.history.push(this),this.commited=!0}apply(){for(let t=0;t{this.editor.selection.recoverRangesFromSnapshot(this.endRanges)}))}rollback(){for(let t=this.steps.length;t>0;t--)this.steps[t-1].invert(this.editor);setTimeout((()=>{this.editor.selection.recoverRangesFromSnapshot(this.startRanges)}))}}const vt={createPath:F,queryPath:H,Formater:q,Content:class extends rt{uuid=R();get renderContent(){return this.$editor.formater.render(this.$path)}get displayType(){return"inline"}constructor(t){super(t)}get contentLength(){return this.$path.length}get $path(){return this.props.path}get $editor(){return this.props.editor}shouldComponentUpdate(){return 1!==this.$path.rebuildFlag}onBeforeRender(){this.$path._$component=this}update(t,e){return this.onBeforeUpdate&&this.onBeforeUpdate({path:t||this.$path,range:e}),this.setState().then((()=>{this.$editor.selection.drawRangeBg(),this.onAfterUpdate&&this.onAfterUpdate({range:e,path:t})}))}onInsert({data:t,type:e,range:n}){if("text"===e){const e=new ft({range:n,data:t});return e.apply(),this.update().then((()=>{n.collapse(!1),n.updateCaret()})),e}}onContentDelete({range:t,ts:e}){console.log("删除",e);const{endContainer:n,endOffset:o,startContainer:r,startOffset:i,collapsed:s}=t,a=r.queryCommonPath(n);if(s){const i=r.prevLeaf;if(o>0){const s=new ut({range:t,count:1});e.addAndApplyStep(s),0===r.block.contentLength?(t.setStart(r,0).collapse(),r.block.$path.parent.component.update()):0===r.length?(r.delete(),i.block===r.block&&i?t.setStart(i,i.length).collapse():t.setStart(r.nextLeaf,0).collapse()):(this._updatePoints(n,o,-1),i?.block===r.block&&1===o&&t.setStart(i,i.length).collapse())}else if(0===r.block.contentLength)r.block.$path.delete(),t.setStart(i,i.length).collapse();else if(0===r.length)r.delete();else if(r.block!==i.block){const e=r.parent;0===i.length?(i.parent.pop(),i.parent.push(...r.parent.children),e.delete(),t.setStart(r,0)):(i.parent.splice(i.index+1,0,...r.parent.children),e.delete(),t.setStart(r,0).collapse())}else t.setStart(i,i.length).collapse(),this.onContentDelete(t)}else r===n?(r.textDelete(o,o-i),0===r.length&&(r.delete(),t.setStart(r.prevLeaf,r.prevLeaf.length).collapse()),t.collapse(!0)):(r.textDelete(r.length,r.length-i),n.textDelete(o,o),a.deleteBetween(r,n),r.block!==n.block&&(n.parent.delete(),r.parent.splice(r.index+1,0,...n.parent.children.filter((t=>t.length)))),t.collapse(!0),console.log(t.startOffset,t.endOffset,t));a.component.update(a,t).then((()=>{t.updateCaret()}))}enterPath(t,e){let n=null;if("left"===e){const e=t.endContainer;if(n=e.nextLeaf,!n)return null;const o=e.block===n.block;t.set(n,o?1:0)}else{if(n=t.startContainer.prevLeaf,!n)return null;t.set(n,n.length)}return{path:n,range:t}}leavePath(t,e){if("left"===e){const e=t.startContainer;let n=e.prevLeaf;return n&&e?(t.set(e,e.length),n.component.enterPath(t,"right")):null}{let e=t.endContainer.nextLeaf;return e?e.component.enterPath(t,"left"):null}}onCaretMove(t,e,n){const o=e.container,{shiftKey:r}=n;let i={path:o,range:e};return 0===e.d&&(e.d="left"===t?-1:1),this.isCaretShouldLeavePath(o,e,t)?i=this.leavePath(e,t):"left"===t?e.offset>0&&(e.offset-=1):e.offset{t.moveTo(n)})),e.set(n.children[0],0)}else n=e.container.parent.clone(!0),n.insertAfter(e.container.parent),e.set(n.children[0],0);n.parent.component.update().then((()=>{e.collapse(!0),e.updateCaret()}))}onKeydownArrowLeft({event:t,range:e}){it("left",e,t),this.$editor.selection.updateCaret()}onKeydownArrowRight({event:t,range:e}){it("right",e,t),this.$editor.selection.updateCaret()}onKeydownArrowUp({event:t,range:e}){st("up",e,t),this.$editor.selection.updateCaret()}onKeydownArrowDown({event:t,range:e}){st("down",e,t),this.$editor.selection.updateCaret()}onKeydownBackspace({event:t,range:e,ts:n}){ct({event:t,range:e,ts:n})}onKeydownEnter({event:t,range:e}){this.onLinefeed(t,e)}isCaretShouldLeavePath(t,e,n){if("left"===n&&e.offset<=1){let n=t.prevLeaf;return!!n&&(0===e.offset||t.block===n.block)}return"right"===n&&e.offset===t.length}_updatePoints(t,e,n,o){this.$editor.selection.updatePoints(t,e,n,o)}setFormat(t,e){const n=t.startContainer.queryCommonPath(t.endContainer),o=this.$editor.selection.getSeletedPath();for(const t of o)e(t);n.component.update().then((()=>{t.updateCaret(),this.$editor.selection.drawRangeBg()}))}},Path:_,Selection:gt,createRef:function(){return{current:null}},createVnode:K,patch:Z,Component:rt,utils:t,setVdomOrElm:h,setVnodeOrIns:p,setVdomOrPath:u,getVdomOrElm:d,getVdomOrPath:l,getVnodeOrIns:c,setVdomOrIns:f,getVdomOrIns:a,SplitText:ht};window.setFormat=function(t,e){const n=new yt(t);t.selection.ranges.forEach((t=>{const o=t.startContainer.queryCommonPath(t.endContainer),r=function(t,e,n){if(t.collapsed)return[];let o,r,i,s=!1;if(t.collapsed)s=!0;else{if(0===t.startOffset)o=t.startContainer;else if(t.startOffset===t.startContainer.length)o=t.startContainer.nextLeaf;else{const e=new ht(t.startContainer,t.startOffset);o=n.addAndApplyStep(e)[1]}if(0===t.endOffset)r=t.endContainer.prevLeaf;else if(t.endOffset===t.endContainer.length)r=t.endContainer;else{const e=new ht(t.endContainer,t.endOffset),o=n.addAndApplyStep(e);r=o[0]}}return i=o,{length:0,next:function(){if(s)return{value:void 0,done:s};{const t={value:i,done:s};return s=i===r,i=i.nextLeaf,this.length++,t}},[Symbol.iterator]:function(){return this}}}(t,0,n);for(const t of r){const o=new pt(t,0,e);n.addAndApplyStep(o)}n.commit(o),o.component.update()}))},window.deleteText=function(t,e){const n=new yt(t);t.selection.ranges.forEach((t=>{const o=new ut(t.container,t.offset,e);n.addAndApplyStep(o),n.commit(t.container.parent),t.container.parent.component.update()}))};const bt={},xt=bt;class wt{size=50;queue=[];idx=-1;editor=null;constructor({size:t,editor:e}){this.size=t||50,this.editor=e}get current(){return this.queue[this.idx]}push(t){this.current!==t&&(this.queue.length===this.size?this.queue.shift():this.idx++,this.queue.splice(this.idx,this.size,t))}redo(){return this.idx!==this.queue.length-1&&(this.idx++,this.current.apply())}undo(){if(-1===this.idx)return!1;{const t=this.current.rollback();return this.idx--,t}}}const Ct={value:"",isComposing:!1};function St(t){return t.replace(/( |^)[a-z]/g,(t=>t.toUpperCase()))}const kt=["mount"];class Ot{contentRef={current:null};renderContent(){return(0,arguments[arguments.length-1])("div",{id:"editor-content",style:"position:relative",ref:this.contentRef},[this.renderPath()])}constructor(t){$(new.target,Ot,kt),this.$path=t.path,t.path._editor=this,function({editor:t,formats:e,plugins:n}){const o=new q;var r;o.register(e),t.$eventBus={all:r=r||new Map,on:function(t,e){var n=r.get(t);n?n.push(e):r.set(t,[e])},off:function(t,e){var n=r.get(t);n&&(e?n.splice(n.indexOf(e)>>>0,1):r.set(t,[]))},emit:function(t,e){var n=r.get(t);n&&n.slice().map((function(t){t(e)})),(n=r.get("*"))&&n.slice().map((function(n){n(t,e)}))}},o.inject("editor",t),t.formater=o,t.history=new wt({editor:t}),(t=>{for(let e=0;e{xt.platform.initIntercept(t)})),function(t){let e,n=null;t.on("mouseEvents",(e=>{if(!e.shiftKey&&0===e.button){const n=xt.platform.nativeSelection.rangeCount;for(let t=0;t{if(n?n.commited||n.init():n=new yt(t),function(t){return t.type.startsWith("composition")||"input"===t.type}(o)){if(null===o.data)return;!function(t,e){const{data:n,type:o}=t;if("input"===o){let t=" "===n?" ":n||"";if(!Ct.isComposing&&n)e({data:t,type:"input"});else{const n=Ct.value.length;Ct.value=t,e({data:t,type:"compositioning",prevDataLength:n})}}else"compositionstart"===o?(Ct.value="",Ct.isComposing=!0):"compositionend"===o&&(setTimeout((()=>{e({data:Ct.value,type:"compositionend"}),Ct.value="",Ct.isComposing=!1})),t.target.value="")}(o,(({data:r,prevDataLength:i,type:s})=>{t.selection.ranges.forEach((a=>{a.collapsed||ct({event:o,range:a,ts:n,force:!0}),i&&L(i,ct,t,{event:o,range:a,ts:n,force:!0});const l=a.container;if("input"!==s&&"compositioning"!==s||(e=l.component.onInsert({type:"text",data:r,range:a,ts:n,event:o})),"input"===s||"compositionend"===s){n.addStep(e);const t=l.component.onInput;"function"==typeof t&&t.call(l.component,o,a,n)}}))}))}else{const e=o.key?`${o.type}${o.key}`:null,r=`${o.type}`;t.selection.ranges.forEach((t=>{const i=t.container,s=e?i.component[`on${St(e)}`]:null,a=i.component[`on${St(r)}`];"function"==typeof s&&s.call(i.component,{event:o,range:t,ts:n}),"function"==typeof a&&a.call(i.component,{event:o,range:t,ts:n})})),t.emit(e,o),t.emit(r,o)}n=n.commit()})),t.on("selectionchange-origin",(()=>{const e=xt.platform.nativeSelection,{startContainer:n,startOffset:o,endContainer:r,endOffset:i}=t.selection.ranges[0]||{};t.emit("selectionchange",{startContainer:n,startOffset:o,endContainer:r,endOffset:i}),e&&!e.isCollapsed&&t.selection.ranges.forEach((t=>{t.caret.hidden()}))})),t.on("keydownz",(e=>{e.ctrlKey&&t.history.undo()})),t.on("keydownZ",(e=>{e.ctrlKey&&t.history.redo()}))}(t)}({editor:this,formats:t.formats,plugins:t.plugins})}renderPath(){return this.formater.render({children:[this.$path]})}on(t,e){this.$eventBus.on(t,e)}emit(t,e){this.$eventBus.emit(t,e)}focus(t){this.$eventBus.emit("focus",t)}destroy(){this.$eventBus.emit("destroy")}queryPath(t){return H(t,this.$path)}queryCommonPath(t,e){const n=this.queryPath(t),o=this.queryPath(e);return n.queryCommonPath(o)}}const Et=vt.createPath,Rt=vt.Content,At=vt.createRef,Lt=vt.createVnode,Mt=vt.patch,Pt=vt.Component,$t=vt.utils;n(424);var Tt=n(764),Nt=n.n(Tt),Bt=n(520),zt=n.n(Bt),_t=n(668),Ft=n.n(_t),Ht=n(252),Vt=n.n(Ht),It=n(456),Dt=n.n(It),jt=n(992),Kt=n.n(jt),Ut=n(112),qt={};qt.styleTagTransform=Kt(),qt.setAttributes=Vt(),qt.insert=Ft().bind(null,"head"),qt.domAPI=zt(),qt.insertStyleElement=Dt(),Nt()(Ut.c,qt),Ut.c&&Ut.c.locals&&Ut.c.locals;class Gt extends Pt{constructor(t){super(t),this.state={visiable:!1},this.dialogRef=At()}render(){const t=arguments[arguments.length-1];return t("div",{ref:this.dialogRef},[this.state.visiable?t("div",{style:"background:#ddd;position:absolute;top:35px;z-index:1"},[this.props.children.length?this.props.children:"dialog"]):""])}outClickHandle=t=>{this.props.barItemRef.current.contains(t.target)||(this.setState({visiable:!1}),document.removeEventListener("click",this.outClickHandle))};toggle(t){this.state.visiable||document.addEventListener("click",this.outClickHandle),this.setState({visiable:!this.state.visiable})}}class Xt extends Pt{render(){const t=arguments[arguments.length-1];return t("div",{class:"editor-tooltip"},[this.props.children.length?this.props.children:"",t("span",{class:"tooltiptext top",style:`width:${this.props.width}px;margin-left:-${this.props.width/2}px;`},[this.props.content||"content"])])}}function Yt(t,e,n){n/=100;const o=e=>(e+t/30)%12,r=(e/=100)*Math.min(n,1-n),i=t=>n-r*Math.max(-1,Math.min(o(t)-3,Math.min(9-o(t),1)));return[255*i(0),255*i(8),255*i(4)].map((t=>Jt(t)))}function Jt(t,e=0){return Number(`${Math.round(`${t}e${e}`)}e-${e}`)}function Qt(t,e,n){const[o,r,i]=Yt(t,100,50),s=((255-r)*e+r)*n,a=((255-i)*e+i)*n;return[Jt(((255-o)*e+o)*n),Jt(s),Jt(a)]}const{throttle:Wt,isDef:Zt}=$t;function te(t){return t.stopPropagation&&t.stopPropagation(),t.preventDefault&&t.preventDefault(),t.cancelBubble=!0,t.returnValue=!1,!1}class ee extends Pt{constructor(t){super(t)}render(){return(0,arguments[arguments.length-1])("div",{style:"font-size:20px"},["hue:",this.props.hue.toFixed(0)])}}class ne extends Pt{constructor(t){super(t),this.state={hue:0,x:228,y:0,px:1,py:1},this.containerRef=At()}render(){const t=arguments[arguments.length-1];return t("div",{style:`background: linear-gradient(to top, rgba(0, 0, 0, 1), transparent), linear-gradient(to left, hsla(${this.state.hue}, 100%, 50%, 1), rgba(255, 255, 255, 1))`,onMousedown:this.handleMouseDown,class:"palette",ref:this.containerRef},[t("span",{style:`top:${this.state.y}px;left:${this.state.x}px;`,class:"palette-picker"},[]),t(ee,{hue:this.state.hue},[])])}handleChange=Wt((t=>{te(t);const e="number"==typeof t.pageX?t.pageX:t.touches[0].pageX,n="number"==typeof t.pageY?t.pageY:t.touches[0].pageY,o=e-(this.containerRef.current.getBoundingClientRect().left+window.scrollX),r=n-(this.containerRef.current.getBoundingClientRect().top+window.scrollY),i=(228-o)/228,s=(150-r)/150;this.setState({x:o>=228?228:o<=0?0:o,y:r>=150?150:r<=0?0:r,px:i,py:s});const[a,l,c]=Qt(this.state.hue,i,s);this.props.hue.current.color=`rgba(${a},${l},${c},${this.props.hue.current.state.A})`,this.props.hue.current.setState({R:a,G:l,B:c})}),32);handleMouseDown=t=>{te(t),this.handleChange(t),window.addEventListener("mousemove",this.handleChange),window.addEventListener("mouseup",this.handleMouseUp)};handleMouseUp=t=>{te(t),this.unbindEventListeners()};unbindEventListeners=()=>{window.removeEventListener("mousemove",this.handleChange),window.removeEventListener("mouseup",this.handleMouseUp)};setPalette(t,e,n,o){if(Zt(o)){const[r,i]=function(t,e,n,o){const r={R:e,G:n,B:o},[i,s,a]=Yt(t,100,50);let l,c,d,h;return[i,s,a].forEach(((t,e)=>{255===t&&(c=["R","G","B"][e]),0===t&&(l=["R","G","B"][e])})),h=r[c]/255,d=0===r[l]?0:r[l]/h/255,[Jt(d,2),Jt(h,2)]}(t,e,n,o);this.setState({x:228*(1-r),y:150*(1-i),px:r,py:i})}this.setState({hue:t})}}const{throttle:oe,isDef:re}=$t;function ie(t){return t.stopPropagation&&t.stopPropagation(),t.preventDefault&&t.preventDefault(),t.cancelBubble=!0,t.returnValue=!1,!1}class se extends Pt{constructor(t){super(t),this.color=this.props.color,this.state={x:200,x2:200,R:255,G:0,B:0,A:1},this.colorBlock=At(),this.hueContainer=At(),this.transparencyContainer=At()}render(){const t=arguments[arguments.length-1];return t("div",{class:"picker"},[t("div",{class:"left"},[t("div",{ref:this.hueContainer,onMousedown:this.handleHueMouseDown,class:"hue"},[t("div",{style:`left:${this.state.x}px`,class:"hue-picker"},[])]),t("div",{onMousedown:this.handleTransparencyMouseDown,class:"transparency",style:"margin-top:4px"},[t("div",{class:"transparency-picker-bg",style:`background: linear-gradient(to right, rgba(${this.state.R},${this.state.G},${this.state.B},0) 0%, rgba(${this.state.R},${this.state.G},${this.state.B},1)`},[]),t("div",{ref:this.transparencyContainer,style:"position:absolute;top:0"},[t("div",{style:`left:${this.state.x2}px;`,class:"transparency-picker"},[])])])]),t("div",{class:"right"},[t("div",{class:"color-block-bg"},[]),t("div",{style:`background:${this.color};`,ref:this.colorBlock,class:"color-block"},[])])])}onMounted(){let[t,e,n,o]=getComputedStyle(this.colorBlock.current).backgroundColor.match(/[\d||\.]+/g).map(Number);const[r]=function(t,e,n){t/=255,e/=255,n/=255;const o=Math.max(t,e,n),r=o-Math.min(t,e,n),i=r?o===t?(e-n)/r:o===e?2+(n-t)/r:4+(t-e)/r:0;return[60*i<0?60*i+360:60*i,100*(r?o<=.5?r/(2*o-r):r/(2-(2*o-r)):0),100*(2*o-r)/2].map((t=>Jt(t)))}(t,e,n);o=re(o)?o:1,this.props.paletteRef.current.setPalette(r,t,e,n);const i=200-5*r/9;this.setState({A:o,x2:200*o<=6?6:200*o,x:i<=6?6:i,R:t,G:e,B:n})}handleHueChange=oe((t=>{ie(t);let e=("number"==typeof t.pageX?t.pageX:t.touches[0].pageX)-(this.hueContainer.current.getBoundingClientRect().left+window.pageXOffset);e=e>=200?200:e<=0?0:e;const n=360*(1-e/200),[o,r,i]=Qt(n,this.props.paletteRef.current.state.px,this.props.paletteRef.current.state.py);this.color=`rgba(${o},${r},${i},${this.state.A})`,this.setState({x:e<=6?6:e,R:o,G:r,B:i}),this.props.paletteRef.current.setPalette(n)}),32);handleHueMouseDown=t=>{ie(t),this.handleHueChange(t),window.addEventListener("mousemove",this.handleHueChange),window.addEventListener("mouseup",this.handleMouseUp)};handleTransparencyChange=oe((t=>{ie(t);let e=("number"==typeof t.pageX?t.pageX:t.touches[0].pageX)-(this.transparencyContainer.current.getBoundingClientRect().left+window.pageXOffset);e=e>=200?200:e<=0?0:e;const n=e/200;this.color=`rgba(${this.state.R},${this.state.G},${this.state.B},${n})`,this.setState({x2:e<=6?6:e,A:n})}),32);handleTransparencyMouseDown=t=>{ie(t),this.handleTransparencyChange(t),window.addEventListener("mousemove",this.handleTransparencyChange),window.addEventListener("mouseup",this.handleMouseUp)};handleMouseUp=t=>{ie(t),this.unbindEventListeners()};unbindEventListeners(){window.removeEventListener("mousemove",this.handleHueChange),window.removeEventListener("mousemove",this.handleTransparencyChange),window.removeEventListener("mouseup",this.handleMouseUp)}}class ae extends Pt{constructor(t){super(t),this.paletteRef=At(),this.hueRef=At()}render(){const t=arguments[arguments.length-1];return t("div",{style:"font-size:0;width:228px;"},[t(ne,{ref:this.paletteRef,hue:this.hueRef},[]),t(se,{ref:this.hueRef,color:this.props.color,paletteRef:this.paletteRef},[])])}onMounted(){console.log("ColorPicker")}}const le={fontColor:(t,e)=>t("div",{id:"colorPicker"},[t(ae,{color:"#666600"},[])])};class ce extends Pt{constructor(t){super(t)}render(t){return le[this.props.options.componentName]?.(t,this)||t("span",{},["404"])}}class de extends Pt{toolBarItems=[];constructor(t){super(t),this.props.editor.on("selectionchange",(t=>{const{startContainer:e,endContainer:n}=t,o=[];let r=e;for(;o.push(r),r!==n;)r=r.nextLeaf;const i=function(t){if(0===t.length)return{};const e={};for(const n in t[0]){const o=t[0][n];t.every((t=>t[n]===o))&&(e[n]=o)}return e}(o.map((t=>t.node.formats)));this.notice(i)}))}notice(t){this.toolBarItems.forEach((e=>e.onNotice(t)))}render(){const t=arguments[arguments.length-1],{tools:e}=this.props;return t("div",{class:"editor-tool-bar"},[e.map((e=>t(Xt,{width:"64",content:e.tooltip},[t(he,{...{...e,onCommand:this.onCommand,toolBarItems:this.toolBarItems}},[])])))])}onCommand=(t,...e)=>{this.props.onCommand(t,...e)}}class he extends Pt{constructor(t){super(t),this.state={active:!1},this.props.toolBarItems.push(this),this.dialogRef=At(),this.barItemRef=At()}onNotice(t){t[this.props.commandName]!==this.state.active&&this.setState({active:t[this.props.commandName]})}render(){const t=arguments[arguments.length-1];return t("span",{class:"editor-tool-bar-item",ref:this.barItemRef,style:`color: ${this.state.active?"rgb(42 201 249)":"rgb(227 227 227);"};`},[t("svg",{onClick:this.clickHandle,class:"icon","aria-hidden":!0,ns:"http://www.w3.org/2000/svg"},[t("use",{"xlink:href":this.props.icon},[])]),this.props.options?t(Gt,{ref:this.dialogRef,barItemRef:this.barItemRef},[t(ce,{name:this.props.commandName,options:this.props.options},[])]):""])}emitComand=()=>{this.props.editor.command(this.props.commandName)};clickHandle=t=>{this.dialogRef.current?this.dialogRef.current.toggle(t):this.emitComand()}}function pe(t){return document.getElementById(t).appendChild(Mt(function(t){const e=arguments[arguments.length-1];return e("div",{class:"editor-wrappe"},[e(de,{tools:[...t.toolBarOption],editor:t},[]),t.renderContent(e)])}(this,Lt))),this}function ue(t,e){return t.replace(/(\d*).*/,(function(t,n){return n*e}))}let fe;fe=Range.prototype.getClientRects?t=>{const e=document.createRange();let n;3!==t.container.elm.nodeType?0===t.offset?(e.setStart(t.container.elm,t.offset),e.setEnd(t.container.elm,t.offset+1),n=e.getClientRects()[0]):(e.setStart(t.container.elm,t.offset-1),e.setEnd(t.container.elm,t.offset),n=e.getClientRects()[0],n.x+=n.width):(e.setStart(t.container.elm,t.offset),n=e.getClientRects()[0]),e.setStart(t.container.elm,t.offset);const o=ve(t.editor.contentRef.current),r=ye(t.editor.contentRef.current);return{x:n.x+o.x-r.x,y:n.y+o.y-r.y,height:n.height}}:t=>(new ge).measure(t.container.elm,t.offset);class me{dom=null;rect=null;defaultStyle={};style={};constructor(t){this.range=t,this.dom=document.createElement("span"),this.dom.classList.add("custom-caret"),this.setStyle(this.dom)}setStyle(t={}){Object.assign(this.style,this.defaultStyle,t)}remove(){this.dom.remove()}hidden(){"none"!==this.style.display&&(this.setStyle({display:"none"}),this.draw())}show(){"inline-block"!==this.style.display&&(this.setStyle({display:"inline-block"}),this.draw())}update(t=!0){if(this.rect=fe(this.range),!t)return;this.range.editor.contentRef.current.appendChild(this.dom);let e=this.range.startContainer.elm;if(!e)return;e instanceof Element||(e=e.parentNode);const n=getComputedStyle(e),o={top:this.rect.y+"px",left:this.rect.x-1+"px",height:this.rect.height+"px",fontSize:n.fontSize,background:n.color,display:this.range.collapsed?"inline-block":"none"};this.setStyle(o),this.draw()}draw(){((t,e)=>{for(const n in e)t.style[n]=e[n]})(this.dom,this.style)}}class ge{dom=null;instance=null;constructor(){if(ge.instance)return ge.instance;this.dom=document.createElement("text"),ge.instance=this}measure(t,e){let n;return 3===t.nodeType?e?(n=t.splitText(e),t.parentNode.insertBefore(this.dom,n)):t.parentNode.insertBefore(this.dom,t):t.childNodes[e-1]&&"BR"===t.childNodes[e-1].nodeName?t.insertBefore(this.dom,t.childNodes[e-1]):t.childNodes[e]?t.insertBefore(this.dom,t.childNodes[e]):t.appendChild(this.dom),this._getRect(t,e,n)}_getRect(t,e,n){let o=t;t instanceof Element||(o=t.parentNode);const r=ue(getComputedStyle(o).fontSize,1.3)/1,i={x:this.dom.offsetLeft,y:this.dom.offsetTop,height:r||this.dom.offsetHeight};return this.dom.remove(),3===t.nodeType&&e&&(!t.data&&t.nextSibling?t.nextSibling.remove():(t.data+=n.data,n.remove())),i}}function ye(t,e={x:0,y:0}){return e.height=e.height??t.offsetHeight,e.x+=t.offsetLeft,e.y+=t.offsetTop,t.offsetParent&&"HTML"!==t.offsetParent.tagName?ye(t.offsetParent,e):e}function ve(t,e={x:0,y:0}){return e.x+=t.scrollLeft||0,e.y+=t.scrollTop||0,t.parentNode?ve(t.parentNode,e):e}const be={};function xe(t,e,n){let o,r=n?.props,i=e.props;if((r||i)&&r!==i){for(o in r=r||{},i=i||{},i){if(/^on[A-Z]|class|style/.test(o))continue;const e=i[o];r[o]!==e&&(!0===e?t.setAttribute(o,""):!1===e?t.removeAttribute(o):120!==o.charCodeAt(0)?t.setAttribute(o,e):58===o.charCodeAt(3)?t.setAttributeNS("http://www.w3.org/XML/1998/namespace",o,e):58===o.charCodeAt(5)?t.setAttributeNS("http://www.w3.org/1999/xlink",o,e):t.setAttribute(o,e))}for(o in r)o in i||t.removeAttribute(o)}}const we={create:xe,update:xe};function Ce(t,e,n){let o=new Map,r=new Map;e&&Object.keys(e.props).forEach((t=>{/^on[A-Z]/.test(t)&&r.set(t.replace(/^on/,"").toLowerCase(),e.props[t])})),n&&Object.keys(n.props).forEach((t=>{/^on[A-Z]/.test(t)&&o.set(t.replace(/^on/,"").toLowerCase(),e.props[t])})),(o.size||r.size)&&(r.forEach(((e,n)=>{o.has(n)||t.addEventListener(n,e,!1)})),o.forEach(((e,n)=>{r.has(n)||t.removeEventListener(n,e,!1)})))}const Se={create:Ce,update:Ce};function ke(t,e,n){const o=(e?.props.class||"").trim();let r,i;o&&t.setAttribute("class",o);const s=(n?.props.class||"").trim(),a=(e?.props.class||"").trim();(s||a)&&s!==a&&(r=new Set(s?s.split(/\s+/g):[]),i=new Set(a?a.split(/\s+/g):[]),i.forEach((e=>{r.has(e)||t.classList.add(e)})),r.forEach((e=>{i.has(e)||t.classList.remove(key)})))}const Oe={create:ke,update:ke},Ee={};function Re(t,e,n){let o=n?.props.style,r=e?.props.style;(o||r)&&o!==r&&(o=o||Ee,r=r||Ee,Object.keys(o).forEach((e=>{r[e]||t.style.removeProperty(e.replace(/([A-Z])/g,"-$1").toLowerCase())})),Object.assign(t.style,r))}const Ae={create:Re,update:Re};function Le(t,e){if("function"==typeof t.type)return;const n=be.core.getVdomOrElm(t);"text"===t.type?t.children!==e.children&&(n.data=t.children):(Ae.update(n,t,e),Oe.update(n,t,e),Se.update(n,t,e),we.update(n,t,e))}function Me(t){let e;if(1===t.vnodeType){const n=t.type(be.core.createVnode,t.props);e=Me(n),t.ref&&(t.ref.current=e),be.core.setVdomOrIns(n,t),be.core.setVdomOrElm(e,n),Le(n)}else if(2===t.vnodeType){const n=new t.type(t.props),o=n.generateVdom(be.core.createVnode);e=Me(o),"function"==typeof n.onCreated&&n.onCreated(),t.ref&&(t.ref.current=n),be.core.setVdomOrIns(o,n),be.core.setVnodeOrIns(n,t),be.core.setVdomOrElm(e,o),Le(o)}else{if(3===t.vnodeType)return e=document.createTextNode(t.children),be.core.setVdomOrElm(e,t),e;e=t.ns?document.createElementNS(t.ns,t.type):document.createElement(t.type),t.ref&&(t.ref.current=e),be.core.setVdomOrElm(e,t),Le(t)}if(1===t.children?.length)e.appendChild(Me(t.children[0]));else if(t.children?.length>1){const n=document.createDocumentFragment();for(let e=0;et.apply(this,o)),e)}}((()=>{const t=window.getSelection(),e=this.editor.contentRef.current;if(t.anchorNode&&t.focusNode){const n=t.anchorNode.parentElement,o=t.focusNode.parentElement;(n===e||o===e||e.contains(n)||e.contains(o))&&this.editor.emit("selectionchange-origin")}}),200);handMousedown(t){if(this.editor.emit("mouseEvents",t),!t.shiftKey&&0===t.button){const e=$e.rangeCount;for(let t=0;te.focus(t))),t.on("destroy",(()=>{e.destroy(),n.destroy()}))}const Be=document,ze=window,_e=document.getSelection();function Fe(t,e,n){return t.insertBefore(e,n)}function He(t,e,n){return t.replaceChild(e,n)}function Ve(t,e){return t.appendChild(e)}function Ie(t,e){return t.removeChild(e)}function De(t){const e=t.tagName.toLowerCase()||"text";if("text"===e)return be.core.createVnode(e);const n={},o=[],r=t.attributes,i=t.childNodes;for(let t=0,e=r.length;t(be.core=n,t.platform=e,je.initIntercept);const Ke=je;class Ue extends Rt{state={initProp:null};render(){const t=arguments[arguments.length-1];return t("div",{style:"display:inline-block"},["我是image的一部分",t("div",{onMousedown:this.onMousedown,onClick:this.sizeChange,style:"display:inline-block;height:15px;width:15px;background:red;user-select:none"},[]),t("img",{onMousedown:this.onMousedown,onClick:this.sizeChange,...this.$path.node.data},[])])}onMousedown=t=>{t.preventDefault(),t.stopPropagation()};sizeChange=t=>{this.state.initProp||(this.state.initProp={...this.$path.node.data}),this.$path.node.data.width===this.state.initProp.width?(this.$path.node.data.width="100px",this.$path.node.data.height="100px"):(this.$path.node.data.width=this.state.initProp.width,this.$path.node.data.height=this.state.initProp.height),this.update()};onAfterUpdate(){this.$editor.selection.updateCaret()}onContentDelete(t,e){const{endOffset:n,collapsed:o}=e;if(o)if(n>0){const n=this.$path.parent.component;t.delete(),n.update(),n.onCaretEnterPath(this.$path.parent,e,!1)}else{const n=this.getPrevLeafPath(t);n&&n.component.onCaretEnterPath(n,e,!1)}}onCaretEnterPath(t,e,n){return e.set(t,"left"===n?0:1),{path:t,range:e}}get contentLength(){return 1}}class qe extends Rt{get displayType(){return"block"}onKeydownb(t,e){t?.ctrlKey&&(t?.preventDefault?.(),this.setFormat(e,(t=>{t.node.formats.bold=!t.node.formats.bold})))}onKeydownd(t,e){t?.ctrlKey&&(t?.preventDefault?.(),this.setFormat(e,(t=>{t.node.formats.deleteline=!t.node.formats.deleteline})))}onKeydowns(t,e){t?.ctrlKey&&(t?.preventDefault?.(),this.setFormat(e,(e=>{t.shiftKey?e.node.formats.sub=!e.node.formats.sub:e.node.formats.sup=!e.node.formats.sup})))}onKeydownu(t,e){t?.ctrlKey&&(t?.preventDefault?.(),this.setFormat(e,(t=>{t.node.formats.underline=!t.node.formats.underline})))}}class Ge extends qe{render(){const t=arguments[arguments.length-1];return t("div",{},[this.$path.children.length?this.$path.render():this.state.placeholder(t)])}}class Xe extends qe{render(){return(0,arguments[arguments.length-1])("p",{},[this.$path.render()])}}class Ye extends qe{render(t){return t(`h${this.props.level}`,null,this.$path.render())}}class Je extends qe{render(){return(0,arguments[arguments.length-1])("table",{border:"1",style:"border-collapse:collapse;width:600px"},[this.$path.render()])}}class Qe extends qe{render(){return(0,arguments[arguments.length-1])("tr",{},[this.$path.render()])}}class We extends qe{constructor(t){super(t),this.state._$root=At()}render(){return(0,arguments[arguments.length-1])("td",{ref:this.state._$root,style:"text-align:center;width:50%"},[this.$path.render()])}}const Ze=[{name:"root",type:"component",render(t,e){return(0,arguments[arguments.length-1])(Ge,{...e},[])}},{name:"bold",type:"tag",render(t){const e=(0,arguments[arguments.length-1])("strong",{},[]);return t&&t.children.push(e),e}},{name:"image",type:"component",render(t,e){const n=(0,arguments[arguments.length-1])(Ue,{...e},[]);return t&&t.children.push(n),n}},{name:"underline",type:"tag",render(t){const e=(0,arguments[arguments.length-1])("u",{},[]);return t&&t.children.push(e),e}},{name:"fontSize",type:"attribute",render(t,e){if(!t)return(0,arguments[arguments.length-1])("span",{style:{fontSize:e}},[]);t.props.style||(t.props.style={}),t.props.style.fontSize=e}},{name:"color",type:"attribute",render(t,e){if(!t)return(0,arguments[arguments.length-1])("span",{style:{color:e}},[]);t.props.style||(t.props.style={}),t.props.style.color=e}},{name:"paragraph",type:"component",render(t,e){const n=(0,arguments[arguments.length-1])(Xe,{...e,key:e.path._uuid},[]);return t&&t.children.push(n),n}},{name:"deleteline",type:"tag",render(t){const e=(0,arguments[arguments.length-1])("del",{},[]);return t&&t.children.push(e),e}},{name:"sup",type:"tag",render(t){const e=(0,arguments[arguments.length-1])("sup",{},[]);return t&&t.children.push(e),e}},{name:"sub",type:"tag",render(t){const e=(0,arguments[arguments.length-1])("sub",{},[]);return t&&t.children.push(e),e}},{name:"table",type:"component",render(t,e){const n=(0,arguments[arguments.length-1])(Je,{...e},[]);return t&&t.children.push(n),n}},{name:"row",type:"component",render(t,e){const n=(0,arguments[arguments.length-1])(Qe,{...e},[]);return t&&t.children.push(n),n}},{name:"col",type:"component",render(t,e){const n=(0,arguments[arguments.length-1])(We,{...e},[]);return t&&t.children.push(n),n}},{name:"background",type:"attribute",render(t,e){if(!t)return(0,arguments[arguments.length-1])("span",{style:{background:e}},[]);t.props.style||(t.props.style={}),t.props.style.background=e}},{name:"header",type:"component",render(t,e,n){const o=arguments[arguments.length-1];console.log(t,e);const r=o(Ye,{...e,level:n,key:e.path._uuid},[]);return t&&t.children.push(r),r}}],tn={data:[{data:[{data:"这是1121一个基于Typex编写的简单富文本编辑器demo",formats:{color:"#666",bold:!0,fontSize:"20px"}}],formats:{paragraph:!0}},{data:[{data:"这是一个基于Typex编写的简单富文本编辑器demo"}],formats:{header:4}},{data:[{data:"Typex",formats:{color:"#ff9999"}},{data:"是一款全新架构的编辑器内核,该内核不依赖contenteditable;自主实现了光标、模拟输入、模拟选区;数据驱动,组件化,插件化,支持多光标,跨平台的设计。优秀的格式排版系统避免了脏标签的产生(打开控制台你会发现它的标签非常简洁)。多光标:按住alt+左键;加粗/取消加粗:ctrl+b;删除线/取消删除线:ctrl+d;上标/取消上标:ctrl+s ....",formats:{color:"#999"}}],formats:{paragraph:!0}},{data:[{data:"红色删除线",formats:{deleteline:!0,color:"red"}},{data:"上标示例",formats:{sup:!0,color:"green",fontSize:"12px"}},{data:"绿色加粗下划线",formats:{underline:!0,color:"green",bold:!0}},{data:"下标示例",formats:{sub:!0,color:"red",fontSize:"12px"}},{data:"背景示例",formats:{sub:!0,color:"white",fontSize:"16px",background:"orange"}}],formats:{paragraph:!0}},{data:[{data:"带静态内容的行内图片示例",formats:{color:"#ff9999",fontSize:"24px"}},{data:{src:"https://img2.baidu.com/it/u=3979034437,2878656671&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=333",alt:"test image",width:"60px",height:"60px"},formats:{image:!0}},{data:{src:"https://img2.baidu.com/it/u=3979034437,2878656671&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=333",alt:"test image",width:"50px",height:"50px"},formats:{image:!0}}],formats:{paragraph:!0}},{data:[{data:"表格示例:",formats:{color:"#666",bold:!0}}],formats:{paragraph:!0}},{data:[{data:[{data:[{data:[{data:"表格内容1",formats:{color:"green"}}],formats:{paragraph:!0}},{data:[{data:"表格内容2",formats:{color:"red",fontSize:"12px"}}],formats:{paragraph:!0}}],formats:{col:!0}},{data:[{data:[{data:"表格内容2",formats:{color:"Orange",fontSize:"20px",background:"#ddd"}}],formats:{paragraph:!0}}],formats:{col:!0}}],formats:{row:!0}}],formats:{table:!0}}],formats:{root:!0}};class en extends Ot{conamndHandles={};toolBarOption=[];constructor(t){super({formats:Ze,plugins:[Ke],...t}),this.on("command",this.command)}mount(t){return pe.call(this,t),this}setToolBar(t){return this.toolBarOption=t,t.forEach((t=>{t.editor=this,this.conamndHandles[t.commandName]=t.commandHandle})),this}command(t,e){const n=this.conamndHandles[t];console.log(n),"function"==typeof n&&n(this,e)}}var nn=n(196),on={};function rn(t,e){t.selection.ranges.forEach((t=>{t.container.component.setFormat(t,e)}))}on.styleTagTransform=Kt(),on.setAttributes=Vt(),on.insert=Ft().bind(null,"head"),on.domAPI=zt(),on.insertStyleElement=Dt(),Nt()(nn.c,on),nn.c&&nn.c.locals&&nn.c.locals;const sn=[{tooltip:"撤销",commandName:"undo",icon:"#icon-undo",commandHandle:t=>{t.history.undo()}},{tooltip:"重做",commandName:"redo",icon:"#icon-todo",commandHandle:t=>{t.history.redo()}},{tooltip:"标题",commandName:"header",icon:"#icon-header"},{tooltip:"字体大小",commandName:"fontSize",icon:"#icon-font-size",options:{}},{tooltip:"字体颜色",commandName:"fontColor",icon:"#icon-color",options:{componentName:"fontColor"}},{tooltip:"加粗",commandName:"bold",icon:"#icon-bold",commandHandle:t=>rn(t,(t=>t.node.formats.bold=!t.node.formats.bold))},{tooltip:"下划线",commandName:"underline",icon:"#icon-underline",commandHandle:t=>rn(t,(t=>t.node.formats.underline=!t.node.formats.underline))},{tooltip:"删除线",commandName:"deleteline",icon:"#icon-del",commandHandle:t=>rn(t,(t=>t.node.formats.deleteline=!t.node.formats.deleteline))},{tooltip:"背景填充",commandName:"background",icon:"#icon-fill",options:{}},{tooltip:"左对齐",commandName:"leftAligned",icon:"#icon-align-left"},{tooltip:"居中",commandName:"middleAligned",icon:"#icon-align-middle"},{tooltip:"右对齐",commandName:"rightAligned",icon:"#icon-align-right"},{tooltip:"超链接",commandName:"link",icon:"#icon-link"},{tooltip:"图片",commandName:"img",icon:"#icon-img"},{tooltip:"代码段",commandName:"code",icon:"#icon-code"},{tooltip:"markdown",commandName:"markdown",icon:"#icon-markdown"},{tooltip:"视频",commandName:"radio",icon:"#icon-radio"},{tooltip:"清除样式",commandName:"clearStyle",icon:"#icon-clear-style",commandHandle:t=>rn(t,(t=>t.node.formats={}))}];setTimeout((()=>{window.editor=function(t={}){const e=Et(tn);return new en({path:e})}({data:"hello world"}).setToolBar(sn).mount("editor-root")}),0)})()})(); \ No newline at end of file +(()=>{var t={888:t=>{"use strict";t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var n="",o=void 0!==e[5];return e[4]&&(n+="@supports (".concat(e[4],") {")),e[2]&&(n+="@media ".concat(e[2]," {")),o&&(n+="@layer".concat(e[5].length>0?" ".concat(e[5]):""," {")),n+=t(e),o&&(n+="}"),e[2]&&(n+="}"),e[4]&&(n+="}"),n})).join("")},e.i=function(t,n,o,r,i){"string"==typeof t&&(t=[[null,t,void 0]]);var s={};if(o)for(var a=0;a0?" ".concat(d[5]):""," {").concat(d[1],"}")),d[5]=i),n&&(d[2]?(d[1]="@media ".concat(d[2]," {").concat(d[1],"}"),d[2]=n):d[2]=n),r&&(d[4]?(d[1]="@supports (".concat(d[4],") {").concat(d[1],"}"),d[4]=r):d[4]="".concat(r)),e.push(d))}},e}},864:t=>{"use strict";t.exports=function(t,e){return e||(e={}),t?(t=String(t.__esModule?t.default:t),/^['"].*['"]$/.test(t)&&(t=t.slice(1,-1)),e.hash&&(t+=e.hash),/["'() \t\n]|(%20)/.test(t)||e.needQuotes?'"'.concat(t.replace(/"/g,'\\"').replace(/\n/g,"\\n"),'"'):t):t}},744:t=>{"use strict";t.exports=function(t){return t[1]}},424:()=>{window._iconfont_svg_string_3243125='',function(t){var e,n=(e=(e=document.getElementsByTagName("script"))[e.length-1]).getAttribute("data-injectcss");if(!(e=e.getAttribute("data-disable-injectsvg"))){var o,r,i,s,a;if(n&&!t.__iconfont__svg__cssinject__){t.__iconfont__svg__cssinject__=!0;try{document.write("")}catch(e){console&&console.log(e)}}o=function(){var e,n=document.createElement("div");n.innerHTML=t._iconfont_svg_string_3243125,(n=n.getElementsByTagName("svg")[0])&&(n.setAttribute("aria-hidden","true"),n.style.position="absolute",n.style.width=0,n.style.height=0,n.style.overflow="hidden",(e=document.body).firstChild?function(t,e){e.parentNode.insertBefore(t,e)}(n,e.firstChild):e.appendChild(n))},document.addEventListener?~["complete","loaded","interactive"].indexOf(document.readyState)?setTimeout(o,0):(r=function(){document.removeEventListener("DOMContentLoaded",r,!1),o()},document.addEventListener("DOMContentLoaded",r,!1)):document.attachEvent&&(i=o,s=t.document,a=!1,function t(){try{s.documentElement.doScroll("left")}catch(e){return void setTimeout(t,50)}l()}(),s.onreadystatechange=function(){"complete"==s.readyState&&(s.onreadystatechange=null,l())})}function l(){a||(a=!0,i())}}(window)},112:(t,e,n)=>{"use strict";n.d(e,{c:()=>p});var o=n(744),r=n.n(o),i=n(888),s=n.n(i),a=n(864),l=n.n(a),c=new URL(n(392),n.b),d=s()(r()),h=l()(c);d.push([t.id,`.editor-tool-bar{border:solid 1px #eee;background:#282828;padding:6px}.editor-tool-bar .icon{width:1.2em;height:1.2em;vertical-align:-.15em;fill:currentColor;overflow:hidden}.editor-tool-bar .editor-tool-bar-item{padding:4px 10px;display:inline-block;border-radius:4px;cursor:pointer;user-select:none}.editor-tool-bar #editor-content{padding:16px;min-height:200px}.editor-tool-bar .editor-tooltip{position:relative;display:inline-block}.editor-tool-bar .editor-tooltip .tooltiptext{opacity:0;width:60px;font-size:12px;background-color:#000;color:#fff;text-align:center;border-radius:6px;padding:5px 0;position:absolute;z-index:1;top:140%;left:50%;margin-left:-30px;transition:opacity 600ms ease-out}.editor-tool-bar .editor-tooltip .tooltiptext::after{content:'';position:absolute;left:50%;margin-left:-5px;border-width:5px;border-style:solid}.editor-tool-bar .editor-tooltip:hover .tooltiptext{opacity:1}.editor-tool-bar .editor-tooltip .tooltiptext.bottom{top:140%}.editor-tool-bar .editor-tooltip .tooltiptext.bottom::after{bottom:100%;border-color:transparent transparent #000 transparent}.editor-tool-bar .editor-tooltip .tooltiptext.top{top:-140%}.editor-tool-bar .editor-tooltip .tooltiptext.top::after{top:100%;border-color:#000 transparent transparent transparent}.editor-tool-bar .picker{display:flex;justify-content:space-between;margin-top:4px}.editor-tool-bar .left,.editor-tool-bar .hue{font-size:0;height:10px;width:200px;background:linear-gradient(to left,#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00)}.editor-tool-bar .left .hue-picker,.editor-tool-bar .hue .hue-picker{display:inline-block;position:relative;width:6px;height:12px;transform:translate(-6px,-1px);background-color:#f8f8f8;box-shadow:rgba(0,0,0,0.37) 0 1px 4px 0}.editor-tool-bar .transparency{position:relative;font-size:0;height:10px;width:200px;background:url(${h}) left center}.editor-tool-bar .transparency-picker-bg{height:100%}.editor-tool-bar .transparency-picker{display:inline-block;position:relative;width:6px;height:12px;transform:translate(-6px,-1px);background-color:#f8f8f8;box-shadow:rgba(0,0,0,0.37) 0 1px 4px 0}.editor-tool-bar .right{position:relative;cursor:pointer}.editor-tool-bar .color-block{width:24px;height:24px;position:absolute;top:0}.editor-tool-bar .color-block-bg{width:24px;height:24px;background:url(${h}) left center}.editor-tool-bar .palette{width:228px;height:150px;overflow:hidden;border:#eee solid 1px}.editor-tool-bar .palette-picker{pointer-events:none;display:inline-block;position:relative;width:12px;height:12px;border-radius:50%;box-shadow:#fff 0 0 0 1px inset;transform:translate(-6px,-6px)}`,""]);const p=d},196:(t,e,n)=>{"use strict";n.d(e,{c:()=>a});var o=n(744),r=n.n(o),i=n(888),s=n.n(i)()(r());s.push([t.id,"#editor-content:focus,.custom-input:focus{outline:none}#editor-content{word-break:break-all;padding:15px}#editor-content .custom-input-iframe{top:-100px;left:0;background:transparent;color:transparent;width:0;height:0;pointer-events:none;border:none;caret-color:transparent;position:absolute}#editor-content .custom-caret{top:-100px;left:0;pointer-events:none;position:absolute;width:2px;border:none;padding:0;display:block;animation:caret 1s infinite .5s steps(1,start)}#editor-content .editor-disabled{user-select:none}#editor-content ::selection{background:#bad2fa}#editor-content table td,#editor-content td{background-color:#fff}#editor-content table td,#editor-content th,#editor-content td{display:table-cell;margin:0;padding:0;text-align:left;vertical-align:middle}@-moz-keyframes static-caret{0%{opacity:1}100%{opacity:1}}@-webkit-keyframes static-caret{0%{opacity:1}100%{opacity:1}}@-o-keyframes static-caret{0%{opacity:1}100%{opacity:1}}@keyframes static-caret{0%{opacity:1}100%{opacity:1}}@-moz-keyframes caret{0%{opacity:1}50%{opacity:0}100%{opacity:1}}@-webkit-keyframes caret{0%{opacity:1}50%{opacity:0}100%{opacity:1}}@-o-keyframes caret{0%{opacity:1}50%{opacity:0}100%{opacity:1}}@keyframes caret{0%{opacity:1}50%{opacity:0}100%{opacity:1}}",""]);const a=s},764:t=>{"use strict";var e=[];function n(t){for(var n=-1,o=0;o{"use strict";var e={};t.exports=function(t,n){var o=function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(t){n=null}e[t]=n}return e[t]}(t);if(!o)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");o.appendChild(n)}},456:t=>{"use strict";t.exports=function(t){var e=document.createElement("style");return t.setAttributes(e,t.attributes),t.insert(e,t.options),e}},252:(t,e,n)=>{"use strict";t.exports=function(t){var e=n.nc;e&&t.setAttribute("nonce",e)}},520:t=>{"use strict";t.exports=function(t){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var e=t.insertStyleElement(t);return{update:function(n){!function(t,e,n){var o="";n.supports&&(o+="@supports (".concat(n.supports,") {")),n.media&&(o+="@media ".concat(n.media," {"));var r=void 0!==n.layer;r&&(o+="@layer".concat(n.layer.length>0?" ".concat(n.layer):""," {")),o+=n.css,r&&(o+="}"),n.media&&(o+="}"),n.supports&&(o+="}");var i=n.sourceMap;i&&"undefined"!=typeof btoa&&(o+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),e.styleTagTransform(o,t,e.options)}(e,t,n)},remove:function(){!function(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t)}(e)}}}},992:t=>{"use strict";t.exports=function(t,e){if(e.styleSheet)e.styleSheet.cssText=t;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(t))}}},392:t=>{"use strict";t.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAADFJREFUOE9jZGBgEGHAD97gk2YcNYBhmIQBgWSAP52AwoAQwJvQRg1gACckQoC2gQgAIF8IscwEtKYAAAAASUVORK5CYII="}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={id:o,exports:{}};return t[o](i,i.exports,n),i.exports}n.m=t,n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.b=document.baseURI||self.location.href,n.nc=void 0,(()=>{"use strict";var t={};n.r(t),n.d(t,{classCheck:()=>$,computeLen:()=>v,debounce:()=>x,isClass:()=>B,isDef:()=>g,isFunction:()=>z,isPrimitive:()=>y,isUndef:()=>m,mergeObj:()=>A,mergePointsContainer:()=>T,mergeTextPath:()=>N,multiplication:()=>k,positionCompare:()=>M,setStyle:()=>S,stringify:()=>O,styleToObj:()=>E,throttle:()=>b,times:()=>L,toRawType:()=>C,typeOf:()=>P,uuid:()=>R});var e={};n.r(e),n.d(e,{Caret:()=>me,appendChild:()=>Ve,createElm:()=>Me,domToVNode:()=>De,initIntercept:()=>Ne,insertBefore:()=>Fe,nativeDocument:()=>Be,nativeSelection:()=>_e,nativeWindow:()=>ze,removeChild:()=>Ie,replaceChild:()=>He,updateProps:()=>Le});const o=new WeakMap,r=new WeakMap,i=new WeakMap,s=new WeakMap;function a(t){return i.get(t)}function l(t){if(t.vnodeType){const e=s.get(t);if(e)return e;if(3===t.vnodeType)return null;const n=a(t),o=c(n);return 1===n.vnodeType?s.get(n):s.get(o)}{const e=s.get(t);if(!e)return;return e}}function c(t){return r.get(t)}function d(t){return 1===t.vnodeType?o.get(i.get(t)):2===t.vnodeType?o.get(i.get(r.get(t))):o.get(t)}function h(t,e){o.set(e,t).set(t,e)}function p(t,e){r.set(e,t).set(t,e)}function u(t,e){s.set(t,e).set(e,t)}function f(t,e){return i.set(e,t).set(t,e)}function m(t){return null==t}function g(t){return null!=t}function y(t){return"string"==typeof t||"number"==typeof t||"symbol"==typeof t||"boolean"==typeof t}function v(t){return y(t.node.data)?t.node.data.length:t.children.length?t.children.reduce(((t,e)=>t+v(e)),0):0}function b(t,e,n=!0){let o,r,i;return function(){const s=this,a=arguments;o?(clearTimeout(r),r=setTimeout((function(){Date.now()-i>=e&&(t.apply(s,a),i=Date.now())}),Math.max(e-(Date.now()-i),0))):(n&&t.apply(s,a),i=Date.now(),o=!0)}}function x(t,e=0){let n;return function(...o){clearTimeout(n),n=setTimeout((()=>t.apply(this,o)),e)}}window.aa={setVdomOrElm:h,setVnodeOrIns:p,setVdomOrPath:u,getVdomOrElm:d,getVdomOrPath:l,getVnodeOrIns:c};const w=Object.prototype.toString;function C(t){return w.call(t).slice(8,-1).toLowerCase()}function S(t,e){for(const n in e)t.style[n]=e[n]}function k(t,e){return t.replace(/(\d*).*/,(function(t,n){return n*e}))}function O(t){let e=[],n=JSON.stringify(t,((t,n)=>{if("object"==typeof n&&null!==n){if(-1!==e.indexOf(n))return"Circular reference";e.push(n)}return n}));return e=null,n}function E(t){return(t=t.trim()).split(";").filter((t=>t)).reduce(((t,e)=>{const n=e.split(":");return t[n[0].trim()]=n[1].trim(),t}),{})}function R(){return([1e3]+-1e3+-4e3+-8e3).replace(/[018]/g,(t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16)))}function A(t,e){for(let n in e)e.hasOwnProperty(n)&&m(t[n])&&!m(e[n])&&(t[n]=e[n])}function L(t,e,n=void 0,...o){let r=0;for(;r++r)return 1;if(e{if(!t.prototype.hasOwnProperty(e))throw new Error(`please overwrite ${e} method`)}))}function T(t,e,n){n.selection.rangePoints.filter((e=>e.container===t)).forEach((t=>{"start"===t.pointName?t.range.setStart(e,e.length+t.offset):t.range.setEnd(e,e.length+t.offset)}))}function N(t,e){const n=t[0],o=t.length;if(1===o)return n;for(let t=0;t{t.moveTo(e)})),e.insertAfter(this),[this,e]}}clone(t=!1){let e;return e=t?y(this.node.data)?this.node.data:JSON.parse(JSON.stringify(this.node.data)):y(this.node.data)?"":this.node.data?[]:{},F({data:e,formats:{...this.node.formats}})}positionCompare(t){return M(this,t)}originOf(t){return this.position.includes(t.position+"-")}insertBefore(t){this.delete(),t.parent.splice(t.index,0,this)}insertAfter(t){this.delete(),t.parent.splice(t.index+1,0,this)}moveTo(t){this.delete(),t.push(this)}delete(){this.parent&&(this.rebuildFlag=1,this.parent.rebuild(),this.parent.component.update())}push(...t){t.forEach((t=>t.rebuildFlag=0)),this.children.push(...t),this.rebuild(),this.component.update()}pop(){const t=this.children[this.children.length-1];return t.rebuildFlag=1,this.rebuild(),this.component.update(),t}unshift(...t){t.forEach((t=>t.rebuildFlag=0)),this.children.unshift(...t),this.rebuild(),this.component.update()}shift(){const t=this.children[0];return t.rebuildFlag=1,this.rebuild(),this.component.update(),t}splice(t,e,...n){const o=[];if(n.length&&(n.forEach((t=>t.rebuildFlag=0)),this.children.splice(t,0,...n)),e>0)for(let n=0;n{for(var i=0;it.rebuild()))}rebuild(t=!1){if("Array"!==this.dataType)return;let e=null;this.children=this.children.filter((t=>1!==t.rebuildFlag)),this.node.data.length=0,this.children.forEach(((t,n)=>{t.parent=this,this.node.data.push(t.node),t.prevSibling=e,e&&(e.nextSibling=t),t.nextSibling=null,e=t,t.index=n}))}}function F(t,e=null,n=null,o=null,r=0){t.formats||(t.formats={});const i=new _({node:t,parent:e,index:r,prevSibling:n,nextSibling:o,children:[]});if(t.data){let e=null;t.data.reduce?.(((t,n,o)=>(e=F(n,i,t,null,o),t&&(t.nextSibling=e),e.prevSibling=t,i.children.push(e),e)),null)}return i}function H(t,e){if(t instanceof _)return t;if(t.nodeType)return function(t){const e=d(t);return e?V(e):null}(t);if(t.vnodeType)return V(t);if("string"==typeof t)return I(t,e);throw"queryPath的参数必须是elm|vn|position"}function V(t){return l(t)||null}function I(t,e){return t.split("-").slice(1).reduce(((t,e)=>t.children[e]),e)}const D=["ref","key","ns"],j=["ns"];function K(t,e,n=[]){e=e||{};const o={},r={};for(let t of D)r[t]=e[t]||null;for(let t in e)D.includes(t)||("style"===t&&y(e[t])?o[t]=E(e[t]):o[t]=e[t]);return function(t,e,n,o){let r;if("text"===t)r={_uuid:R(),vnodeType:3,type:"text",children:o.join("")};else{r={_uuid:R(),vnodeType:B(t)?2:z(t)?1:4,type:t,...e,props:n};const i={};for(let t of j)i[t]=r[t];1===r.vnodeType||2===r.vnodeType?r.props.children=U(o,i):r.children=U(o,i)}return r}(t,r,o,n.flat())}const U=(t,e)=>t.filter((t=>""!==t)).map((t=>y(t)||m(t)?{_uuid:R(),type:"text",vnodeType:3,children:t}:(A(t,e),t))),q=class{formatMap=new Map;register(t){t.forEach((t=>{this.formatMap.set(t.name,t)}))}inject(t,e){this[t]=e}renderRoot(t){return this.render({children:[t]})}render(t){const e=this._group({paths:t.children,restFormats:this.types},0);return this._generateGroups(e,t.isBlock&&0===t.length)}_invokeRender(t,e){return e.fmt.render(t,e.value,K)}_generateGroups(t,e){return t.map((t=>{let n;const o=this._getFormats(t.commonFormats);if(0===t.commonFormats.length){if(-1!==t.children.findIndex((t=>"object"==typeof t.node.data)))throw"格式标记不合法,文本格式不可用于标记非文本的结构";const n=N(t.children,this.editor);let o=null;return e?(o=K("br"),u(n,n.parent.vn),n.clearFormat()):(""===n.node.data&&console.warn("非法空标签:",n),o=K("text",{},[n.node.data]),u(n,o)),o}if((n=o.filter((t=>"component"===t.fmt.type))).length){const e=t.children[0],o=n[0].fmt.render(null,{path:e,editor:this.editor},n[0].value,K);return u(e,o),o}{let n=null,r=null;const i=[];for(let t=0;t"object"==typeof t.data)))throw"格式标记不合法,文本格式不可用于标记非文本的结构";const n=N(t.children,this.editor);let o=null;e?(o=K("br"),u(n,r),n.clearFormat()):(""===n.node.data&&console.warn("非法空标签:",n),o=K("text",{},[n.node.data]),u(n,o)),r.children=[o]}return n}})).filter((t=>t))}get types(){return[...this.formatMap.keys()]}_getFormats(t){return t.map((t=>{const e=Object.keys(t)[0];return{fmt:this.formatMap.get(e),value:t[e]}}))}get(t){return this.formatMap.get(t)||{}}_canAdd(t,e,n){return!!t.node.formats[n]&&(!e.node.formats[n]||e.node.formats[n]===t.node.formats[n]||void 0)}_group(t,e,n=[]){const o={commonFormats:[],children:[]};let r=[],i=null,s={},a=0;for(;e{i?this._canAdd(l,i,t)&&s[t]++:(s[t]=0,l.node.formats[t]&&s[t]++)}));const c=Math.max(...Object.values(s));if(i&&Object.keys(l.node.formats).some((t=>"component"===this.get(t).type))){i=null;break}if(i&&Object.keys(i.node.formats).some((t=>"component"===this.get(t).type))){i=null;break}if(i&&0===a&&c>a){s=n;break}if(i&&c===a&&0!==c){s=n;break}o.children.push(l),o.commonFormats=Object.entries(s).filter((t=>t[1]&&t[1]===c)).map((n=>({[n[0]]:t.paths[e].node.formats[n[0]]}))),r=t.restFormats.filter((t=>!o.commonFormats.some((e=>e[t])))),a=c,i=l}return o.commonFormats.length>0&&o.children.length>1&&(o.children=this._group({paths:o.children,restFormats:r},0)),n.push(o),e{"function"==typeof t.onUnmounted&&t.onUnmounted()})),n=null}}}(t,n,a,c)}(n,r,o)}}function Z(t,e){if(e!==t){if(!t){const t=c(e),n=a(t),o=t.generateVdom(K);return f(t,o),W(o,n),d(o)}if(m(e))return xt.platform.createElm(t);if(g(e.nodeType)&&h(e,e=xt.platform.domToVNode(e)),G(t,e))W(t,e);else{let n=d([1,2].includes(e.vnodeType)?Q(e):e);const o=xt.platform.createElm(t);tt(e,"onUnmounted"),xt.platform.replaceChild(n.parentNode,o,n),tt(t,"onMounted")}return d([1,2].includes(t.vnodeType)?Q(t):t)}}function tt(t,e){const n=t.vnodeType?c(t):t;n&&"function"==typeof n[e]&&n[e]()}const et=[],nt=[];function ot(){let t,e;for(;t=et.shift();){const{partialState:e,component:n}=t;n.prevState||(n.prevState=Object.assign({},n.state)),"function"==typeof e?Object.assign(n.state,e(n.prevState,n.props)):Object.assign(n.state,e),n.prevState=n.state}for(;e=nt.shift();)e.shouldComponentUpdate()&&e.syncUpdate()}class rt{static isComponent=!0;get isComponent(){return!0}state={};$nextTick=t=>Promise.resolve().then(t);constructor(t){this.props=Object.freeze({...t})}render(t){throw Error('Component does not implement a required interface "render"')}generateVdom(t){return"function"==typeof this.onBeforeRender&&this.onBeforeRender(),this.render(t)}setState(t={}){return function(t,e){let n=null;var o;return 0===et.length&&(o=ot,n=Promise.resolve().then(o)),et.push({partialState:t,component:e}),nt.some((t=>t===e))||nt.push(e),n||Promise.resolve()}(t,this)}syncUpdate(){Z(null,c(this))}shouldComponentUpdate(){return!0}}function it(t,e,n){if(e.inputState.isComposing)return;if(!e.collapsed&&!n.shiftKey)return void e.collapse("left"===t);const{shiftKey:o}=n;if(e.collapsed||o)return e.container.component.onCaretMove(t,e,n);e.collapse("left"===t)}function st(t,e,n){e.inputState.isComposing||(e.collapsed||n.shiftKey?lt(e,"up"===t?"left":"right",{...e.caret.rect,block:e.container.block},{...e.caret.rect,block:e.container.block},!1,n):e.collapse("up"===t))}function at(t,e,n,o){if(n.block!==e.block)return!1;let r=!0;return("left"===o&&n.x>e.x||"right"===o&&n.xt===this));this.caret.remove(),this.editor.selection.ranges.splice(t,1)}}class gt{ranges=[];nativeSelection=xt.platform.nativeSelection;constructor(t){this.editor=t}get collapsed(){return this.ranges.every((t=>t.collapsed))}get rangeCount(){return this.ranges.length}get rangePoints(){const t=[];return this.ranges.forEach((e=>{t.push({container:e.startContainer,offset:e.startOffset,range:e,pointName:"start"},{container:e.endContainer,offset:e.endOffset,range:e,pointName:"end"})})),t}get rangesSnapshot(){return this.ranges.map((t=>t.snapshot))}clearRanges(){for(;this.ranges.length;)this.ranges.pop().caret.remove()}createRange(t){return new mt(t,this.editor)}createRangeFromNativeRange(t){const{startContainer:e,endContainer:n,startOffset:o,endOffset:r,collapsed:i}=t,{focusNode:s,focusOffset:a}=this.nativeSelection;let l=0;return l=i?0:s===n&&a===r?1:-1,this.createRange({startContainer:this.amendPathOffset(e).path,endContainer:this.amendPathOffset(n).path,startOffset:o,endOffset:r,d:l})}addRange(t){this.ranges.push(t)}collapse(t,e){this.nativeSelection.collapse(t,e),this._resetRangesFromNative()}amendPathOffset(t,e){const n=this.editor.queryPath(t);return n?n.isLeaf&&3!==n.pathType?this.amendPathOffset(n.elm.parentNode,n.index+1):{path:n,offset:e}:this.amendPathOffset(t.parentNode,e)}amendRange(t){const{startContainer:e,endContainer:n,startOffset:o,endOffset:r}=t,i=this.amendPathOffset(e,o),s=this.amendPathOffset(n,r);return t.setStart(i.path.elm,i.offset),t.setEnd(s.path.elm,s.offset),t}_resetRangesFromNative(){this.clearRanges();const t=this.nativeSelection.rangeCount;for(let e=0;e0){const e=this.amendRange(this.nativeSelection.getRangeAt(t-1));if(!e)return;let n=!1;if(this.ranges.forEach((t=>{t.endContainer===e.endContainer&&t.startOffset===e.startOffset&&(n=!0,t.remove())})),n)return;this.addRange(this.createRangeFromNativeRange(e))}}getRangeAt(t=0){return this.ranges[t]}removeAllRanges(){this.nativeSelection.removeAllRanges(),this.clearRanges()}createNativeRange({startContainer:t,startOffset:e,endContainer:n,endOffset:o}){const r=document.createRange();return r.setStart(t,e),r.setEnd(n,o),r}updatePoints(t,e,n,o){this.rangePoints.forEach((r=>{r.container===t&&e<=r.offset&&(r.range[r.pointName+"Offset"]+=n,o&&(r.range[r.pointName+"Container"]=o))}))}updateRangesFromNative(t){setTimeout((()=>{t?this._extendRangesFromNative():this._resetRangesFromNative(),this.updateCaret()}))}updateCaret(t=!0){this.ranges.forEach((e=>e.updateCaret(t))),this.rangeCount>1&&this._distinct(),t&&this.drawRangeBg()}_isCoverd(t,e){return t.y=e.y+e.height:e.y+e.height>=t.y+t.height}_distinct(){let t={},e=this.ranges.length;if(!(e<2)){for(let n=0;no.caret.rect.x===t[1].caret.rect.x));0===i.length?t[r]=o:this._isCoverd(o.caret.rect,i[0][1].caret.rect)?(o.caret.remove(),this.ranges.splice(n,1),e--,n--):t[r]=o}}t=null}}drawRangeBg(t){const e=t||this.getRangeAt(0);if(!e)return;const{startContainer:n,startOffset:o,endContainer:r,endOffset:i}=e;this.nativeSelection.removeAllRanges();const s={startContainer:n.elm,endContainer:r.elm,startOffset:o,endOffset:i};this.nativeSelection.addRange(this.createNativeRange(s))}getSeletedPath(){if(this.collapsed)return[];const t=this.ranges[0];let e,n,o,r=!1;if(t.collapsed)r=!0;else{if(0===t.startOffset)e=t.startContainer;else if(t.startOffset===t.startContainer.length)e=t.startContainer.nextLeaf;else{const n=t.startContainer.split(t.startOffset);this.updatePoints(t.startContainer,t.startOffset,-t.startOffset,n[1]),e=n[1]}if(0===t.endOffset)n=t.endContainer.prevLeaf;else if(t.endOffset===t.endContainer.length)n=t.endContainer;else{const e=t.endContainer.split(t.endOffset);this.updatePoints(t.endContainer,t.endOffset+1,-t.endOffset,e[1]),n=e[0]}}return o=e,{length:0,next:function(){if(r)return{value:void 0,done:r};{const t={value:o,done:r};return r=o===n,o=o.nextLeaf,this.length++,t}},[Symbol.iterator]:function(){return this}}}recoverRangesFromSnapshot(t){this.removeAllRanges(),this.ranges=t.map((t=>this.createRange({startContainer:this.editor.queryPath(t.startContainer),endContainer:this.editor.queryPath(t.endContainer),startOffset:t.startOffset,endOffset:t.endOffset,d:t.d}))),this.updateCaret()}}class yt{steps=[];startRanges=[];endRanges=[];commited=!1;constructor(t){this.editor=t,this.init()}init(){this.startRanges=this.editor.selection.rangesSnapshot}addAndApplyStep(t){return this.steps.push(t),t.apply(this.editor)}addStep(...t){this.steps.push(...t)}commit(){if(0===this.steps.length)return this;this.endRanges=this.editor.selection.rangesSnapshot,this.editor.history.push(this),this.commited=!0}apply(){for(let t=0;t{this.editor.selection.recoverRangesFromSnapshot(this.endRanges)}))}rollback(){for(let t=this.steps.length;t>0;t--)this.steps[t-1].invert(this.editor);setTimeout((()=>{this.editor.selection.recoverRangesFromSnapshot(this.startRanges)}))}}const vt={createPath:F,queryPath:H,Formater:q,Content:class extends rt{uuid=R();get renderContent(){return this.$editor.formater.render(this.$path)}get displayType(){return"inline"}constructor(t){super(t)}get contentLength(){return this.$path.length}get $path(){return this.props.path}get $editor(){return this.props.editor}shouldComponentUpdate(){return 1!==this.$path.rebuildFlag}onBeforeRender(){this.$path._$component=this}update(t,e){return this.onBeforeUpdate&&this.onBeforeUpdate({path:t||this.$path,range:e}),this.setState().then((()=>{this.$editor.selection.drawRangeBg(),this.onAfterUpdate&&this.onAfterUpdate({range:e,path:t})}))}onInsert({data:t,type:e,range:n}){if("text"===e){const e=new ft({range:n,data:t});return e.apply(),this.update().then((()=>{n.collapse(!1),n.updateCaret()})),e}}onContentDelete({range:t,ts:e}){console.log("删除",e);const{endContainer:n,endOffset:o,startContainer:r,startOffset:i,collapsed:s}=t,a=r.queryCommonPath(n);if(s){const i=r.prevLeaf;if(o>0){const s=new ut({range:t,count:1});e.addAndApplyStep(s),0===r.block.contentLength?(t.setStart(r,0).collapse(),r.block.$path.parent.component.update()):0===r.length?(r.delete(),i.block===r.block&&i?t.setStart(i,i.length).collapse():t.setStart(r.nextLeaf,0).collapse()):(this._updatePoints(n,o,-1),i?.block===r.block&&1===o&&t.setStart(i,i.length).collapse())}else if(0===r.block.contentLength)r.block.$path.delete(),t.setStart(i,i.length).collapse();else if(0===r.length)r.delete();else if(r.block!==i.block){const e=r.parent;0===i.length?(i.parent.pop(),i.parent.push(...r.parent.children),e.delete(),t.setStart(r,0)):(i.parent.splice(i.index+1,0,...r.parent.children),e.delete(),t.setStart(r,0).collapse())}else t.setStart(i,i.length).collapse(),this.onContentDelete(t)}else r===n?(r.textDelete(o,o-i),0===r.length&&(r.delete(),t.setStart(r.prevLeaf,r.prevLeaf.length).collapse()),t.collapse(!0)):(r.textDelete(r.length,r.length-i),n.textDelete(o,o),a.deleteBetween(r,n),r.block!==n.block&&(n.parent.delete(),r.parent.splice(r.index+1,0,...n.parent.children.filter((t=>t.length)))),t.collapse(!0),console.log(t.startOffset,t.endOffset,t));a.component.update(a,t).then((()=>{t.updateCaret()}))}enterPath(t,e){let n=null;if("left"===e){const e=t.endContainer;if(n=e.nextLeaf,!n)return null;const o=e.block===n.block;t.set(n,o?1:0)}else{if(n=t.startContainer.prevLeaf,!n)return null;t.set(n,n.length)}return{path:n,range:t}}leavePath(t,e){if("left"===e){const e=t.startContainer;let n=e.prevLeaf;return n&&e?(t.set(e,e.length),n.component.enterPath(t,"right")):null}{let e=t.endContainer.nextLeaf;return e?e.component.enterPath(t,"left"):null}}onCaretMove(t,e,n){const o=e.container,{shiftKey:r}=n;let i={path:o,range:e};return 0===e.d&&(e.d="left"===t?-1:1),this.isCaretShouldLeavePath(o,e,t)?i=this.leavePath(e,t):"left"===t?e.offset>0&&(e.offset-=1):e.offset{t.moveTo(n)})),e.set(n.children[0],0)}else n=e.container.parent.clone(!0),n.insertAfter(e.container.parent),e.set(n.children[0],0);n.parent.component.update().then((()=>{e.collapse(!0),e.updateCaret()}))}onKeydownArrowLeft({event:t,range:e}){it("left",e,t),this.$editor.selection.updateCaret()}onKeydownArrowRight({event:t,range:e}){it("right",e,t),this.$editor.selection.updateCaret()}onKeydownArrowUp({event:t,range:e}){st("up",e,t),this.$editor.selection.updateCaret()}onKeydownArrowDown({event:t,range:e}){st("down",e,t),this.$editor.selection.updateCaret()}onKeydownBackspace({event:t,range:e,ts:n}){ct({event:t,range:e,ts:n})}onKeydownEnter({event:t,range:e}){this.onLinefeed(t,e)}isCaretShouldLeavePath(t,e,n){if("left"===n&&e.offset<=1){let n=t.prevLeaf;return!!n&&(0===e.offset||t.block===n.block)}return"right"===n&&e.offset===t.length}_updatePoints(t,e,n,o){this.$editor.selection.updatePoints(t,e,n,o)}setFormat(t,e){const n=t.startContainer.queryCommonPath(t.endContainer),o=this.$editor.selection.getSeletedPath();for(const t of o)e(t);n.component.update().then((()=>{t.updateCaret(),this.$editor.selection.drawRangeBg()}))}},Path:_,Selection:gt,createRef:function(){return{current:null}},createVnode:K,patch:Z,Component:rt,utils:t,setVdomOrElm:h,setVnodeOrIns:p,setVdomOrPath:u,getVdomOrElm:d,getVdomOrPath:l,getVnodeOrIns:c,setVdomOrIns:f,getVdomOrIns:a,SplitText:ht};window.setFormat=function(t,e){const n=new yt(t);t.selection.ranges.forEach((t=>{const o=t.startContainer.queryCommonPath(t.endContainer),r=function(t,e,n){if(t.collapsed)return[];let o,r,i,s=!1;if(t.collapsed)s=!0;else{if(0===t.startOffset)o=t.startContainer;else if(t.startOffset===t.startContainer.length)o=t.startContainer.nextLeaf;else{const e=new ht(t.startContainer,t.startOffset);o=n.addAndApplyStep(e)[1]}if(0===t.endOffset)r=t.endContainer.prevLeaf;else if(t.endOffset===t.endContainer.length)r=t.endContainer;else{const e=new ht(t.endContainer,t.endOffset),o=n.addAndApplyStep(e);r=o[0]}}return i=o,{length:0,next:function(){if(s)return{value:void 0,done:s};{const t={value:i,done:s};return s=i===r,i=i.nextLeaf,this.length++,t}},[Symbol.iterator]:function(){return this}}}(t,0,n);for(const t of r){const o=new pt(t,0,e);n.addAndApplyStep(o)}n.commit(o),o.component.update()}))},window.deleteText=function(t,e){const n=new yt(t);t.selection.ranges.forEach((t=>{const o=new ut(t.container,t.offset,e);n.addAndApplyStep(o),n.commit(t.container.parent),t.container.parent.component.update()}))};const bt={},xt=bt;class wt{size=50;queue=[];idx=-1;editor=null;constructor({size:t,editor:e}){this.size=t||50,this.editor=e}get current(){return this.queue[this.idx]}push(t){this.current!==t&&(this.queue.length===this.size?this.queue.shift():this.idx++,this.queue.splice(this.idx,this.size,t))}redo(){return this.idx!==this.queue.length-1&&(this.idx++,this.current.apply())}undo(){if(-1===this.idx)return!1;{const t=this.current.rollback();return this.idx--,t}}}const Ct={value:"",isComposing:!1};function St(t){return t.replace(/( |^)[a-z]/g,(t=>t.toUpperCase()))}const kt=["mount"];class Ot{contentRef={current:null};renderContent(){return(0,arguments[arguments.length-1])("div",{id:"editor-content",style:"position:relative",ref:this.contentRef},[this.renderPath()])}constructor(t){$(new.target,Ot,kt),this.$path=t.path,t.path._editor=this,function({editor:t,formats:e,plugins:n}){const o=new q;var r;o.register(e),t.$eventBus={all:r=r||new Map,on:function(t,e){var n=r.get(t);n?n.push(e):r.set(t,[e])},off:function(t,e){var n=r.get(t);n&&(e?n.splice(n.indexOf(e)>>>0,1):r.set(t,[]))},emit:function(t,e){var n=r.get(t);n&&n.slice().map((function(t){t(e)})),(n=r.get("*"))&&n.slice().map((function(n){n(t,e)}))}},o.inject("editor",t),t.formater=o,t.history=new wt({editor:t}),(t=>{for(let e=0;e{xt.platform.initIntercept(t)})),function(t){let e,n=null;t.on("mouseEvents",(e=>{if(!e.shiftKey&&0===e.button){const n=xt.platform.nativeSelection.rangeCount;for(let t=0;t{if(n?n.commited||n.init():n=new yt(t),function(t){return t.type.startsWith("composition")||"input"===t.type}(o)){if(null===o.data)return;!function(t,e){const{data:n,type:o}=t;if("input"===o){let t=" "===n?" ":n||"";if(!Ct.isComposing&&n)e({data:t,type:"input"});else{const n=Ct.value.length;Ct.value=t,e({data:t,type:"compositioning",prevDataLength:n})}}else"compositionstart"===o?(Ct.value="",Ct.isComposing=!0):"compositionend"===o&&(setTimeout((()=>{e({data:Ct.value,type:"compositionend"}),Ct.value="",Ct.isComposing=!1})),t.target.value="")}(o,(({data:r,prevDataLength:i,type:s})=>{t.selection.ranges.forEach((a=>{a.collapsed||ct({event:o,range:a,ts:n,force:!0}),i&&L(i,ct,t,{event:o,range:a,ts:n,force:!0});const l=a.container;if("input"!==s&&"compositioning"!==s||(e=l.component.onInsert({type:"text",data:r,range:a,ts:n,event:o})),"input"===s||"compositionend"===s){n.addStep(e);const t=l.component.onInput;"function"==typeof t&&t.call(l.component,o,a,n)}}))}))}else{const e=o.key?`${o.type}${o.key}`:null,r=`${o.type}`;t.selection.ranges.forEach((t=>{const i=t.container,s=e?i.component[`on${St(e)}`]:null,a=i.component[`on${St(r)}`];"function"==typeof s&&s.call(i.component,{event:o,range:t,ts:n}),"function"==typeof a&&a.call(i.component,{event:o,range:t,ts:n})})),t.emit(e,o),t.emit(r,o)}n=n.commit()})),t.on("selectionchange-origin",(()=>{const e=xt.platform.nativeSelection,{startContainer:n,startOffset:o,endContainer:r,endOffset:i}=t.selection.ranges[0]||{};t.emit("selectionchange",{startContainer:n,startOffset:o,endContainer:r,endOffset:i}),e&&!e.isCollapsed&&t.selection.ranges.forEach((t=>{t.caret.hidden()}))})),t.on("keydownz",(e=>{e.ctrlKey&&t.history.undo()})),t.on("keydownZ",(e=>{e.ctrlKey&&t.history.redo()}))}(t)}({editor:this,formats:t.formats,plugins:t.plugins})}renderPath(){return this.formater.render({children:[this.$path]})}on(t,e){this.$eventBus.on(t,e)}emit(t,e){this.$eventBus.emit(t,e)}focus(t){this.$eventBus.emit("focus",t)}destroy(){this.$eventBus.emit("destroy")}queryPath(t){return H(t,this.$path)}queryCommonPath(t,e){const n=this.queryPath(t),o=this.queryPath(e);return n.queryCommonPath(o)}}const Et=vt.createPath,Rt=vt.Content,At=vt.createRef,Lt=vt.createVnode,Mt=vt.patch,Pt=vt.Component,$t=vt.utils;n(424);var Tt=n(764),Nt=n.n(Tt),Bt=n(520),zt=n.n(Bt),_t=n(668),Ft=n.n(_t),Ht=n(252),Vt=n.n(Ht),It=n(456),Dt=n.n(It),jt=n(992),Kt=n.n(jt),Ut=n(112),qt={};qt.styleTagTransform=Kt(),qt.setAttributes=Vt(),qt.insert=Ft().bind(null,"head"),qt.domAPI=zt(),qt.insertStyleElement=Dt(),Nt()(Ut.c,qt),Ut.c&&Ut.c.locals&&Ut.c.locals;class Gt extends Pt{constructor(t){super(t),this.state={visiable:!1},this.dialogRef=At()}render(){const t=arguments[arguments.length-1];return t("div",{ref:this.dialogRef},[this.state.visiable?t("div",{style:"background:#ddd;position:absolute;top:35px;z-index:1"},[this.props.children.length?this.props.children:"dialog"]):""])}outClickHandle=t=>{this.props.barItemRef.current.contains(t.target)||(this.setState({visiable:!1}),document.removeEventListener("click",this.outClickHandle))};toggle(t){this.state.visiable||document.addEventListener("click",this.outClickHandle),this.setState({visiable:!this.state.visiable})}}class Xt extends Pt{render(){const t=arguments[arguments.length-1];return t("div",{class:"editor-tooltip"},[this.props.children.length?this.props.children:"",t("span",{class:"tooltiptext top",style:`width:${this.props.width}px;margin-left:-${this.props.width/2}px;`},[this.props.content||"content"])])}}function Yt(t,e,n){n/=100;const o=e=>(e+t/30)%12,r=(e/=100)*Math.min(n,1-n),i=t=>n-r*Math.max(-1,Math.min(o(t)-3,Math.min(9-o(t),1)));return[255*i(0),255*i(8),255*i(4)].map((t=>Jt(t)))}function Jt(t,e=0){return Number(`${Math.round(`${t}e${e}`)}e-${e}`)}function Qt(t,e,n){const[o,r,i]=Yt(t,100,50),s=((255-r)*e+r)*n,a=((255-i)*e+i)*n;return[Jt(((255-o)*e+o)*n),Jt(s),Jt(a)]}const{throttle:Wt,isDef:Zt}=$t;function te(t){return t.stopPropagation&&t.stopPropagation(),t.preventDefault&&t.preventDefault(),t.cancelBubble=!0,t.returnValue=!1,!1}class ee extends Pt{constructor(t){super(t)}render(){return(0,arguments[arguments.length-1])("div",{style:"font-size:20px"},["hue:",this.props.hue.toFixed(0)])}}class ne extends Pt{constructor(t){super(t),this.state={hue:0,x:228,y:0,px:1,py:1},this.containerRef=At()}render(){const t=arguments[arguments.length-1];return t("div",{style:`background: linear-gradient(to top, rgba(0, 0, 0, 1), transparent), linear-gradient(to left, hsla(${this.state.hue}, 100%, 50%, 1), rgba(255, 255, 255, 1))`,onMousedown:this.handleMouseDown,class:"palette",ref:this.containerRef},[t("span",{style:`top:${this.state.y}px;left:${this.state.x}px;`,class:"palette-picker"},[]),t(ee,{hue:this.state.hue},[])])}handleChange=Wt((t=>{te(t);const e="number"==typeof t.pageX?t.pageX:t.touches[0].pageX,n="number"==typeof t.pageY?t.pageY:t.touches[0].pageY,o=e-(this.containerRef.current.getBoundingClientRect().left+window.scrollX),r=n-(this.containerRef.current.getBoundingClientRect().top+window.scrollY),i=(228-o)/228,s=(150-r)/150;this.setState({x:o>=228?228:o<=0?0:o,y:r>=150?150:r<=0?0:r,px:i,py:s});const[a,l,c]=Qt(this.state.hue,i,s);this.props.hue.current.color=`rgba(${a},${l},${c},${this.props.hue.current.state.A})`,this.props.hue.current.setState({R:a,G:l,B:c})}),32);handleMouseDown=t=>{te(t),this.handleChange(t),window.addEventListener("mousemove",this.handleChange),window.addEventListener("mouseup",this.handleMouseUp)};handleMouseUp=t=>{te(t),this.unbindEventListeners()};unbindEventListeners=()=>{window.removeEventListener("mousemove",this.handleChange),window.removeEventListener("mouseup",this.handleMouseUp)};setPalette(t,e,n,o){if(Zt(o)){const[r,i]=function(t,e,n,o){const r={R:e,G:n,B:o},[i,s,a]=Yt(t,100,50);let l,c,d,h;return[i,s,a].forEach(((t,e)=>{255===t&&(c=["R","G","B"][e]),0===t&&(l=["R","G","B"][e])})),h=r[c]/255,d=0===r[l]?0:r[l]/h/255,[Jt(d,2),Jt(h,2)]}(t,e,n,o);this.setState({x:228*(1-r),y:150*(1-i),px:r,py:i})}this.setState({hue:t})}}const{throttle:oe,isDef:re}=$t;function ie(t){return t.stopPropagation&&t.stopPropagation(),t.preventDefault&&t.preventDefault(),t.cancelBubble=!0,t.returnValue=!1,!1}class se extends Pt{constructor(t){super(t),this.color=this.props.color,this.state={x:200,x2:200,R:255,G:0,B:0,A:1},this.colorBlock=At(),this.hueContainer=At(),this.transparencyContainer=At()}render(){const t=arguments[arguments.length-1];return t("div",{class:"picker"},[t("div",{class:"left"},[t("div",{ref:this.hueContainer,onMousedown:this.handleHueMouseDown,class:"hue"},[t("div",{style:`left:${this.state.x}px`,class:"hue-picker"},[])]),t("div",{onMousedown:this.handleTransparencyMouseDown,class:"transparency",style:"margin-top:4px"},[t("div",{class:"transparency-picker-bg",style:`background: linear-gradient(to right, rgba(${this.state.R},${this.state.G},${this.state.B},0) 0%, rgba(${this.state.R},${this.state.G},${this.state.B},1)`},[]),t("div",{ref:this.transparencyContainer,style:"position:absolute;top:0"},[t("div",{style:`left:${this.state.x2}px;`,class:"transparency-picker"},[])])])]),t("div",{class:"right"},[t("div",{class:"color-block-bg"},[]),t("div",{style:`background:${this.color};`,ref:this.colorBlock,class:"color-block"},[])])])}onMounted(){let[t,e,n,o]=getComputedStyle(this.colorBlock.current).backgroundColor.match(/[\d||\.]+/g).map(Number);const[r]=function(t,e,n){t/=255,e/=255,n/=255;const o=Math.max(t,e,n),r=o-Math.min(t,e,n),i=r?o===t?(e-n)/r:o===e?2+(n-t)/r:4+(t-e)/r:0;return[60*i<0?60*i+360:60*i,100*(r?o<=.5?r/(2*o-r):r/(2-(2*o-r)):0),100*(2*o-r)/2].map((t=>Jt(t)))}(t,e,n);o=re(o)?o:1,this.props.paletteRef.current.setPalette(r,t,e,n);const i=200-5*r/9;this.setState({A:o,x2:200*o<=6?6:200*o,x:i<=6?6:i,R:t,G:e,B:n})}handleHueChange=oe((t=>{ie(t);let e=("number"==typeof t.pageX?t.pageX:t.touches[0].pageX)-(this.hueContainer.current.getBoundingClientRect().left+window.scrollX);e=e>=200?200:e<=0?0:e;const n=360*(1-e/200),[o,r,i]=Qt(n,this.props.paletteRef.current.state.px,this.props.paletteRef.current.state.py);console.log(this.props.paletteRef.current.state),this.color=`rgba(${o},${r},${i},${this.state.A})`,this.setState({x:e<=6?6:e,R:o,G:r,B:i}),this.props.paletteRef.current.setPalette(n)}),32);handleHueMouseDown=t=>{ie(t),this.handleHueChange(t),window.addEventListener("mousemove",this.handleHueChange),window.addEventListener("mouseup",this.handleMouseUp)};handleTransparencyChange=oe((t=>{ie(t);let e=("number"==typeof t.pageX?t.pageX:t.touches[0].pageX)-(this.transparencyContainer.current.getBoundingClientRect().left+window.scrollX);e=e>=200?200:e<=0?0:e;const n=e/200;this.color=`rgba(${this.state.R},${this.state.G},${this.state.B},${n})`,this.setState({x2:e<=6?6:e,A:n})}),32);handleTransparencyMouseDown=t=>{ie(t),this.handleTransparencyChange(t),window.addEventListener("mousemove",this.handleTransparencyChange),window.addEventListener("mouseup",this.handleMouseUp)};handleMouseUp=t=>{ie(t),this.unbindEventListeners()};unbindEventListeners(){window.removeEventListener("mousemove",this.handleHueChange),window.removeEventListener("mousemove",this.handleTransparencyChange),window.removeEventListener("mouseup",this.handleMouseUp)}}class ae extends Pt{constructor(t){super(t),this.paletteRef=At(),this.hueRef=At()}render(){const t=arguments[arguments.length-1];return t("div",{style:"font-size:0;width:228px;"},[t(ne,{ref:this.paletteRef,hue:this.hueRef},[]),t(se,{ref:this.hueRef,color:this.props.color,paletteRef:this.paletteRef},[])])}onMounted(){console.log("ColorPicker")}}const le={fontColor:(t,e)=>t("div",{id:"colorPicker"},[t(ae,{color:"#666600"},[])])};class ce extends Pt{constructor(t){super(t)}render(t){return le[this.props.options.componentName]?.(t,this)||t("span",{},["404"])}}class de extends Pt{toolBarItems=[];constructor(t){super(t),this.props.editor.on("selectionchange",(t=>{const{startContainer:e,endContainer:n}=t,o=[];let r=e;for(;o.push(r),r!==n;)r=r.nextLeaf;const i=function(t){if(0===t.length)return{};const e={};for(const n in t[0]){const o=t[0][n];t.every((t=>t[n]===o))&&(e[n]=o)}return e}(o.map((t=>t.node.formats)));this.notice(i)}))}notice(t){this.toolBarItems.forEach((e=>e.onNotice(t)))}render(){const t=arguments[arguments.length-1],{tools:e}=this.props;return t("div",{class:"editor-tool-bar"},[e.map((e=>t(Xt,{width:"64",content:e.tooltip},[t(he,{...{...e,onCommand:this.onCommand,toolBarItems:this.toolBarItems}},[])])))])}onCommand=(t,...e)=>{this.props.onCommand(t,...e)}}class he extends Pt{constructor(t){super(t),this.state={active:!1},this.props.toolBarItems.push(this),this.dialogRef=At(),this.barItemRef=At()}onNotice(t){t[this.props.commandName]!==this.state.active&&this.setState({active:t[this.props.commandName]})}render(){const t=arguments[arguments.length-1];return t("span",{class:"editor-tool-bar-item",ref:this.barItemRef,style:`color: ${this.state.active?"rgb(42 201 249)":"rgb(227 227 227);"};`},[t("svg",{onClick:this.clickHandle,class:"icon","aria-hidden":!0,ns:"http://www.w3.org/2000/svg"},[t("use",{"xlink:href":this.props.icon},[])]),this.props.options?t(Gt,{ref:this.dialogRef,barItemRef:this.barItemRef},[t(ce,{name:this.props.commandName,options:this.props.options},[])]):""])}emitComand=()=>{this.props.editor.command(this.props.commandName)};clickHandle=t=>{this.dialogRef.current?this.dialogRef.current.toggle(t):this.emitComand()}}function pe(t){return document.getElementById(t).appendChild(Mt(function(t){const e=arguments[arguments.length-1];return e("div",{class:"editor-wrappe"},[e(de,{tools:[...t.toolBarOption],editor:t},[]),t.renderContent(e)])}(this,Lt))),this}function ue(t,e){return t.replace(/(\d*).*/,(function(t,n){return n*e}))}let fe;fe=Range.prototype.getClientRects?t=>{const e=document.createRange();let n;3!==t.container.elm.nodeType?0===t.offset?(e.setStart(t.container.elm,t.offset),e.setEnd(t.container.elm,t.offset+1),n=e.getClientRects()[0]):(e.setStart(t.container.elm,t.offset-1),e.setEnd(t.container.elm,t.offset),n=e.getClientRects()[0],n.x+=n.width):(e.setStart(t.container.elm,t.offset),n=e.getClientRects()[0]),e.setStart(t.container.elm,t.offset);const o=ve(t.editor.contentRef.current),r=ye(t.editor.contentRef.current);return{x:n.x+o.x-r.x,y:n.y+o.y-r.y,height:n.height}}:t=>(new ge).measure(t.container.elm,t.offset);class me{dom=null;rect=null;defaultStyle={};style={};constructor(t){this.range=t,this.dom=document.createElement("span"),this.dom.classList.add("custom-caret"),this.setStyle(this.dom)}setStyle(t={}){Object.assign(this.style,this.defaultStyle,t)}remove(){this.dom.remove()}hidden(){"none"!==this.style.display&&(this.setStyle({display:"none"}),this.draw())}show(){"inline-block"!==this.style.display&&(this.setStyle({display:"inline-block"}),this.draw())}update(t=!0){if(this.rect=fe(this.range),!t)return;this.range.editor.contentRef.current.appendChild(this.dom);let e=this.range.startContainer.elm;if(!e)return;e instanceof Element||(e=e.parentNode);const n=getComputedStyle(e),o={top:this.rect.y+"px",left:this.rect.x-1+"px",height:this.rect.height+"px",fontSize:n.fontSize,background:n.color,display:this.range.collapsed?"inline-block":"none"};this.setStyle(o),this.draw()}draw(){((t,e)=>{for(const n in e)t.style[n]=e[n]})(this.dom,this.style)}}class ge{dom=null;instance=null;constructor(){if(ge.instance)return ge.instance;this.dom=document.createElement("text"),ge.instance=this}measure(t,e){let n;return 3===t.nodeType?e?(n=t.splitText(e),t.parentNode.insertBefore(this.dom,n)):t.parentNode.insertBefore(this.dom,t):t.childNodes[e-1]&&"BR"===t.childNodes[e-1].nodeName?t.insertBefore(this.dom,t.childNodes[e-1]):t.childNodes[e]?t.insertBefore(this.dom,t.childNodes[e]):t.appendChild(this.dom),this._getRect(t,e,n)}_getRect(t,e,n){let o=t;t instanceof Element||(o=t.parentNode);const r=ue(getComputedStyle(o).fontSize,1.3)/1,i={x:this.dom.offsetLeft,y:this.dom.offsetTop,height:r||this.dom.offsetHeight};return this.dom.remove(),3===t.nodeType&&e&&(!t.data&&t.nextSibling?t.nextSibling.remove():(t.data+=n.data,n.remove())),i}}function ye(t,e={x:0,y:0}){return e.height=e.height??t.offsetHeight,e.x+=t.offsetLeft,e.y+=t.offsetTop,t.offsetParent&&"HTML"!==t.offsetParent.tagName?ye(t.offsetParent,e):e}function ve(t,e={x:0,y:0}){return e.x+=t.scrollLeft||0,e.y+=t.scrollTop||0,t.parentNode?ve(t.parentNode,e):e}const be={};function xe(t,e,n){let o,r=n?.props,i=e.props;if((r||i)&&r!==i){for(o in r=r||{},i=i||{},i){if(/^on[A-Z]|class|style/.test(o))continue;const e=i[o];r[o]!==e&&(!0===e?t.setAttribute(o,""):!1===e?t.removeAttribute(o):120!==o.charCodeAt(0)?t.setAttribute(o,e):58===o.charCodeAt(3)?t.setAttributeNS("http://www.w3.org/XML/1998/namespace",o,e):58===o.charCodeAt(5)?t.setAttributeNS("http://www.w3.org/1999/xlink",o,e):t.setAttribute(o,e))}for(o in r)o in i||t.removeAttribute(o)}}const we={create:xe,update:xe};function Ce(t,e,n){let o=new Map,r=new Map;e&&Object.keys(e.props).forEach((t=>{/^on[A-Z]/.test(t)&&r.set(t.replace(/^on/,"").toLowerCase(),e.props[t])})),n&&Object.keys(n.props).forEach((t=>{/^on[A-Z]/.test(t)&&o.set(t.replace(/^on/,"").toLowerCase(),e.props[t])})),(o.size||r.size)&&(r.forEach(((e,n)=>{o.has(n)||t.addEventListener(n,e,!1)})),o.forEach(((e,n)=>{r.has(n)||t.removeEventListener(n,e,!1)})))}const Se={create:Ce,update:Ce};function ke(t,e,n){const o=(e?.props.class||"").trim();let r,i;o&&t.setAttribute("class",o);const s=(n?.props.class||"").trim(),a=(e?.props.class||"").trim();(s||a)&&s!==a&&(r=new Set(s?s.split(/\s+/g):[]),i=new Set(a?a.split(/\s+/g):[]),i.forEach((e=>{r.has(e)||t.classList.add(e)})),r.forEach((e=>{i.has(e)||t.classList.remove(key)})))}const Oe={create:ke,update:ke},Ee={};function Re(t,e,n){let o=n?.props.style,r=e?.props.style;(o||r)&&o!==r&&(o=o||Ee,r=r||Ee,Object.keys(o).forEach((e=>{r[e]||t.style.removeProperty(e.replace(/([A-Z])/g,"-$1").toLowerCase())})),Object.assign(t.style,r))}const Ae={create:Re,update:Re};function Le(t,e){if("function"==typeof t.type)return;const n=be.core.getVdomOrElm(t);"text"===t.type?t.children!==e.children&&(n.data=t.children):(Ae.update(n,t,e),Oe.update(n,t,e),Se.update(n,t,e),we.update(n,t,e))}function Me(t){let e;if(1===t.vnodeType){const n=t.type(be.core.createVnode,t.props);e=Me(n),t.ref&&(t.ref.current=e),be.core.setVdomOrIns(n,t),be.core.setVdomOrElm(e,n),Le(n)}else if(2===t.vnodeType){const n=new t.type(t.props),o=n.generateVdom(be.core.createVnode);e=Me(o),"function"==typeof n.onCreated&&n.onCreated(),t.ref&&(t.ref.current=n),be.core.setVdomOrIns(o,n),be.core.setVnodeOrIns(n,t),be.core.setVdomOrElm(e,o),Le(o)}else{if(3===t.vnodeType)return e=document.createTextNode(t.children),be.core.setVdomOrElm(e,t),e;e=t.ns?document.createElementNS(t.ns,t.type):document.createElement(t.type),t.ref&&(t.ref.current=e),be.core.setVdomOrElm(e,t),Le(t)}if(1===t.children?.length)e.appendChild(Me(t.children[0]));else if(t.children?.length>1){const n=document.createDocumentFragment();for(let e=0;et.apply(this,o)),e)}}((()=>{const t=window.getSelection(),e=this.editor.contentRef.current;if(t.anchorNode&&t.focusNode){const n=t.anchorNode.parentElement,o=t.focusNode.parentElement;(n===e||o===e||e.contains(n)||e.contains(o))&&this.editor.emit("selectionchange-origin")}}),200);handMousedown(t){if(this.editor.emit("mouseEvents",t),!t.shiftKey&&0===t.button){const e=$e.rangeCount;for(let t=0;te.focus(t))),t.on("destroy",(()=>{e.destroy(),n.destroy()}))}const Be=document,ze=window,_e=document.getSelection();function Fe(t,e,n){return t.insertBefore(e,n)}function He(t,e,n){return t.replaceChild(e,n)}function Ve(t,e){return t.appendChild(e)}function Ie(t,e){return t.removeChild(e)}function De(t){const e=t.tagName.toLowerCase()||"text";if("text"===e)return be.core.createVnode(e);const n={},o=[],r=t.attributes,i=t.childNodes;for(let t=0,e=r.length;t(be.core=n,t.platform=e,je.initIntercept);const Ke=je;class Ue extends Rt{state={initProp:null};render(){const t=arguments[arguments.length-1];return t("div",{style:"display:inline-block"},["我是image的一部分",t("div",{onMousedown:this.onMousedown,onClick:this.sizeChange,style:"display:inline-block;height:15px;width:15px;background:red;user-select:none"},[]),t("img",{onMousedown:this.onMousedown,onClick:this.sizeChange,...this.$path.node.data},[])])}onMousedown=t=>{t.preventDefault(),t.stopPropagation()};sizeChange=t=>{this.state.initProp||(this.state.initProp={...this.$path.node.data}),this.$path.node.data.width===this.state.initProp.width?(this.$path.node.data.width="100px",this.$path.node.data.height="100px"):(this.$path.node.data.width=this.state.initProp.width,this.$path.node.data.height=this.state.initProp.height),this.update()};onAfterUpdate(){this.$editor.selection.updateCaret()}onContentDelete(t,e){const{endOffset:n,collapsed:o}=e;if(o)if(n>0){const n=this.$path.parent.component;t.delete(),n.update(),n.onCaretEnterPath(this.$path.parent,e,!1)}else{const n=this.getPrevLeafPath(t);n&&n.component.onCaretEnterPath(n,e,!1)}}onCaretEnterPath(t,e,n){return e.set(t,"left"===n?0:1),{path:t,range:e}}get contentLength(){return 1}}class qe extends Rt{get displayType(){return"block"}onKeydownb(t,e){t?.ctrlKey&&(t?.preventDefault?.(),this.setFormat(e,(t=>{t.node.formats.bold=!t.node.formats.bold})))}onKeydownd(t,e){t?.ctrlKey&&(t?.preventDefault?.(),this.setFormat(e,(t=>{t.node.formats.deleteline=!t.node.formats.deleteline})))}onKeydowns(t,e){t?.ctrlKey&&(t?.preventDefault?.(),this.setFormat(e,(e=>{t.shiftKey?e.node.formats.sub=!e.node.formats.sub:e.node.formats.sup=!e.node.formats.sup})))}onKeydownu(t,e){t?.ctrlKey&&(t?.preventDefault?.(),this.setFormat(e,(t=>{t.node.formats.underline=!t.node.formats.underline})))}}class Ge extends qe{render(){const t=arguments[arguments.length-1];return t("div",{},[this.$path.children.length?this.$path.render():this.state.placeholder(t)])}}class Xe extends qe{render(){return(0,arguments[arguments.length-1])("p",{},[this.$path.render()])}}class Ye extends qe{render(t){return t(`h${this.props.level}`,null,this.$path.render())}}class Je extends qe{render(){return(0,arguments[arguments.length-1])("table",{border:"1",style:"border-collapse:collapse;width:600px"},[this.$path.render()])}}class Qe extends qe{render(){return(0,arguments[arguments.length-1])("tr",{},[this.$path.render()])}}class We extends qe{constructor(t){super(t),this.state._$root=At()}render(){return(0,arguments[arguments.length-1])("td",{ref:this.state._$root,style:"text-align:center;width:50%"},[this.$path.render()])}}const Ze=[{name:"root",type:"component",render(t,e){return(0,arguments[arguments.length-1])(Ge,{...e},[])}},{name:"bold",type:"tag",render(t){const e=(0,arguments[arguments.length-1])("strong",{},[]);return t&&t.children.push(e),e}},{name:"image",type:"component",render(t,e){const n=(0,arguments[arguments.length-1])(Ue,{...e},[]);return t&&t.children.push(n),n}},{name:"underline",type:"tag",render(t){const e=(0,arguments[arguments.length-1])("u",{},[]);return t&&t.children.push(e),e}},{name:"fontSize",type:"attribute",render(t,e){if(!t)return(0,arguments[arguments.length-1])("span",{style:{fontSize:e}},[]);t.props.style||(t.props.style={}),t.props.style.fontSize=e}},{name:"color",type:"attribute",render(t,e){if(!t)return(0,arguments[arguments.length-1])("span",{style:{color:e}},[]);t.props.style||(t.props.style={}),t.props.style.color=e}},{name:"paragraph",type:"component",render(t,e){const n=(0,arguments[arguments.length-1])(Xe,{...e,key:e.path._uuid},[]);return t&&t.children.push(n),n}},{name:"deleteline",type:"tag",render(t){const e=(0,arguments[arguments.length-1])("del",{},[]);return t&&t.children.push(e),e}},{name:"sup",type:"tag",render(t){const e=(0,arguments[arguments.length-1])("sup",{},[]);return t&&t.children.push(e),e}},{name:"sub",type:"tag",render(t){const e=(0,arguments[arguments.length-1])("sub",{},[]);return t&&t.children.push(e),e}},{name:"table",type:"component",render(t,e){const n=(0,arguments[arguments.length-1])(Je,{...e},[]);return t&&t.children.push(n),n}},{name:"row",type:"component",render(t,e){const n=(0,arguments[arguments.length-1])(Qe,{...e},[]);return t&&t.children.push(n),n}},{name:"col",type:"component",render(t,e){const n=(0,arguments[arguments.length-1])(We,{...e},[]);return t&&t.children.push(n),n}},{name:"background",type:"attribute",render(t,e){if(!t)return(0,arguments[arguments.length-1])("span",{style:{background:e}},[]);t.props.style||(t.props.style={}),t.props.style.background=e}},{name:"header",type:"component",render(t,e,n){const o=arguments[arguments.length-1];console.log(t,e);const r=o(Ye,{...e,level:n,key:e.path._uuid},[]);return t&&t.children.push(r),r}}],tn={data:[{data:[{data:"这是1121一个基于Typex编写的简单富文本编辑器demo",formats:{color:"#666",bold:!0,fontSize:"20px"}}],formats:{paragraph:!0}},{data:[{data:"这是一个基于Typex编写的简单富文本编辑器demo"}],formats:{header:4}},{data:[{data:"Typex",formats:{color:"#ff9999"}},{data:"是一款全新架构的编辑器内核,该内核不依赖contenteditable;自主实现了光标、模拟输入、模拟选区;数据驱动,组件化,插件化,支持多光标,跨平台的设计。优秀的格式排版系统避免了脏标签的产生(打开控制台你会发现它的标签非常简洁)。多光标:按住alt+左键;加粗/取消加粗:ctrl+b;删除线/取消删除线:ctrl+d;上标/取消上标:ctrl+s ....",formats:{color:"#999"}}],formats:{paragraph:!0}},{data:[{data:"红色删除线",formats:{deleteline:!0,color:"red"}},{data:"上标示例",formats:{sup:!0,color:"green",fontSize:"12px"}},{data:"绿色加粗下划线",formats:{underline:!0,color:"green",bold:!0}},{data:"下标示例",formats:{sub:!0,color:"red",fontSize:"12px"}},{data:"背景示例",formats:{sub:!0,color:"white",fontSize:"16px",background:"orange"}}],formats:{paragraph:!0}},{data:[{data:"带静态内容的行内图片示例",formats:{color:"#ff9999",fontSize:"24px"}},{data:{src:"https://img2.baidu.com/it/u=3979034437,2878656671&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=333",alt:"test image",width:"60px",height:"60px"},formats:{image:!0}},{data:{src:"https://img2.baidu.com/it/u=3979034437,2878656671&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=333",alt:"test image",width:"50px",height:"50px"},formats:{image:!0}}],formats:{paragraph:!0}},{data:[{data:"表格示例:",formats:{color:"#666",bold:!0}}],formats:{paragraph:!0}},{data:[{data:[{data:[{data:[{data:"表格内容1",formats:{color:"green"}}],formats:{paragraph:!0}},{data:[{data:"表格内容2",formats:{color:"red",fontSize:"12px"}}],formats:{paragraph:!0}}],formats:{col:!0}},{data:[{data:[{data:"表格内容2",formats:{color:"Orange",fontSize:"20px",background:"#ddd"}}],formats:{paragraph:!0}}],formats:{col:!0}}],formats:{row:!0}}],formats:{table:!0}}],formats:{root:!0}};class en extends Ot{conamndHandles={};toolBarOption=[];constructor(t){super({formats:Ze,plugins:[Ke],...t}),this.on("command",this.command)}mount(t){return pe.call(this,t),this}setToolBar(t){return this.toolBarOption=t,t.forEach((t=>{t.editor=this,this.conamndHandles[t.commandName]=t.commandHandle})),this}command(t,e){const n=this.conamndHandles[t];console.log(n),"function"==typeof n&&n(this,e)}}var nn=n(196),on={};function rn(t,e){t.selection.ranges.forEach((t=>{t.container.component.setFormat(t,e)}))}on.styleTagTransform=Kt(),on.setAttributes=Vt(),on.insert=Ft().bind(null,"head"),on.domAPI=zt(),on.insertStyleElement=Dt(),Nt()(nn.c,on),nn.c&&nn.c.locals&&nn.c.locals;const sn=[{tooltip:"撤销",commandName:"undo",icon:"#icon-undo",commandHandle:t=>{t.history.undo()}},{tooltip:"重做",commandName:"redo",icon:"#icon-todo",commandHandle:t=>{t.history.redo()}},{tooltip:"标题",commandName:"header",icon:"#icon-header"},{tooltip:"字体大小",commandName:"fontSize",icon:"#icon-font-size",options:{}},{tooltip:"字体颜色",commandName:"fontColor",icon:"#icon-color",options:{componentName:"fontColor"}},{tooltip:"加粗",commandName:"bold",icon:"#icon-bold",commandHandle:t=>rn(t,(t=>t.node.formats.bold=!t.node.formats.bold))},{tooltip:"下划线",commandName:"underline",icon:"#icon-underline",commandHandle:t=>rn(t,(t=>t.node.formats.underline=!t.node.formats.underline))},{tooltip:"删除线",commandName:"deleteline",icon:"#icon-del",commandHandle:t=>rn(t,(t=>t.node.formats.deleteline=!t.node.formats.deleteline))},{tooltip:"背景填充",commandName:"background",icon:"#icon-fill",options:{}},{tooltip:"左对齐",commandName:"leftAligned",icon:"#icon-align-left"},{tooltip:"居中",commandName:"middleAligned",icon:"#icon-align-middle"},{tooltip:"右对齐",commandName:"rightAligned",icon:"#icon-align-right"},{tooltip:"超链接",commandName:"link",icon:"#icon-link"},{tooltip:"图片",commandName:"img",icon:"#icon-img"},{tooltip:"代码段",commandName:"code",icon:"#icon-code"},{tooltip:"markdown",commandName:"markdown",icon:"#icon-markdown"},{tooltip:"视频",commandName:"radio",icon:"#icon-radio"},{tooltip:"清除样式",commandName:"clearStyle",icon:"#icon-clear-style",commandHandle:t=>rn(t,(t=>t.node.formats={}))}];setTimeout((()=>{window.editor=function(t={}){const e=Et(tn);return new en({path:e})}({data:"hello world"}).setToolBar(sn).mount("editor-root")}),0)})()})(); \ No newline at end of file