@linker-design-plus/tiny-peony 1.3.11 → 1.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var iE=Object.defineProperty;var rE=(C,t,B)=>t in C?iE(C,t,{enumerable:!0,configurable:!0,writable:!0,value:B}):C[t]=B;var Z=(C,t,B)=>rE(C,typeof t!="symbol"?t+"":t,B);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const E=require("vue"),aA=require("@arco-design/web-vue");var ZI=C=>Object.prototype.toString.call(C),aE=C=>ZI(C)==="[object Null]",sE=C=>ZI(C)==="[object Number]",cE=C=>ZI(C)==="[object String]",jI=(C,t)=>t?typeof t=="string"?` ${C}--${t}`:Array.isArray(t)?t.reduce((B,o)=>B+jI(C,o),""):Object.keys(t).reduce((B,o)=>B+(t[o]?jI(C,o):""),""):"",lE=C=>(t,B)=>(t&&typeof t!="string"&&(B=t,t=""),t=t?`${C}__${t}`:C,`${t}${jI(t,B)}`),VC=C=>t=>{const B=`${C}-${t}`;return[lE(B),B]};const Ug=VC("tag"),KA=VC("c"),_I=C=>{let t=!1;return function(...o){t||(requestAnimationFrame(()=>{C.apply(this,o),t=!1}),t=!0)}},wE=()=>typeof window>"u"?!1:window.location.protocol==="https:",eI=C=>Object.prototype.toString.call(C).slice(8,-1).toLocaleLowerCase(),PC=C=>eI(C)==="string",jC=C=>eI(C)==="array",dE=C=>eI(C)==="null",hE=C=>eI(C)==="undefined",H=C=>dE(C)||hE(C),QA=C=>C instanceof HTMLElement,lA=C=>(C==null?void 0:C.nodeType)===Node.TEXT_NODE;var WC=(C=>(C.None="None",C.Caret="Caret",C.Range="Range",C))(WC||{}),x=(C=>(C.pausation="pausation",C.pronunciation="pronunciation",C.anchor="anchor",C.homophones="homophones",C.highlight="highlight",C))(x||{}),BI=(C=>(C.single="single",C.multiple="multiple",C))(BI||{});class OC{}class XC{}class zC{}class ZC{}class _C{}class Mg{}class DE extends _C{constructor(B,o){super();Z(this,"contentManager");Z(this,"cursorManager");this.contentManager=B,this.cursorManager=o}executeUndo(){}executeRedo(){}}const uE=(C,t)=>{var u;t.preventDefault();const B=((u=t.data)==null?void 0:u.length)??0,o=C.content.calcTextCount()-B,i=C.maxLength-o;if(i>=B||!B)return;const c=i<=0?B:B-i,a=window.getSelection(),r=a==null?void 0:a.getRangeAt(0);if(H(a)||H(r))return;const{endContainer:h,endOffset:d}=r,D=document.createRange();D.setStart(h,d-c),D.setEnd(h,d),D.deleteContents(),a.removeAllRanges(),a.addRange(D)},yE=(C,t)=>{const{inputType:B}=t;C.content.calcTextCount()>=C.maxLength&&B.includes("insert")&&B!=="insertParagraph"&&t.preventDefault()},tI=(C,t)=>{const B=[],o=C.content.calcTextCount();let i=C.maxLength-o;if(i<=0||!t.length)return[];let c=t.shift();for(;i>0&&c;){if(c.length>=i)return B.push(c.slice(0,i)),B;B.push(c),i-=c.length,c=t.shift()}return B};class fE extends XC{constructor(B,o){super();Z(this,"_editorElement");Z(this,"_editor");this._editorElement=B,this._editor=o}insertEmptyPara(){this._editorElement.innerHTML=UE}calcTextCount(){return this.getTextContent().reduce((B,o)=>B+o.length,0)}getContent(){return this._editorElement.innerHTML}getHtml(){return this.getContent()}setContent(B){this._editorElement.innerHTML=B}setHtml(B){this.setContent(B)}appendContent(B,o){var r;const i=tI(this._editor,jC(B)?B:[B]),c=this.getParas()[0],a=(r=c.textContent)!=null&&r.length?void 0:i.shift();a&&(c.innerHTML=a,o==null||o(c)),i.forEach(h=>{const d=document.createElement("p");d.innerHTML=h,d.classList.add(NA),this._editorElement.appendChild(d),o==null||o(d)})}insert(B){this._insert(B)}delete(){this._delete()}update(B){this._update(B)}getParas(){return Array.from(this._editorElement.querySelectorAll(`.${NA}`))}getTextContent(){const B=this.getParas(),o=i=>{const c=Array.from(i.childNodes);let a="";for(let r=0;r<c.length;r++){const h=c[r];lA(h)?a+=h.textContent??"":QA(h)&&(a+=x.anchor===h.dataset.type?o(h):x.pronunciation===h.dataset.type?h.dataset.value:h.dataset.raw??"")}return a};return B.map(o)}_insert(B){const o=window.getSelection(),i=this._editor.cursor.isRangeInEditor()?o==null?void 0:o.getRangeAt(0):this._editor.cursor.range;if(H(o)||!o.rangeCount||H(i))return;const c=document.createDocumentFragment();if(PC(B)){const d=document.createElement("div");for(d.innerHTML=B;d.firstChild;)c.appendChild(d.firstChild)}else c.appendChild(B);const a=c.lastChild;(this._calcRange(i)??i).insertNode(c);const h=document.createRange();h.setStartAfter(a),h.setEndAfter(a),o.removeAllRanges(),o.addRange(h)}_delete(){const{range:B}=this._editor.cursor;B==null||B.deleteContents()}_update(B){this._delete(),this._insert(B)}_calcRange(B){const o=B.commonAncestorContainer;if(o.tagName!=="DIV")return B;const i=B.startOffset,c=Array.from(o.children).filter(h=>h.tagName==="P");if(i<=0||i-1>=c.length)return console.warn("上一个 <p> 不存在"),B;const a=c[i-1];if(!a)return console.warn("未找到上一个 <p>"),B;const r=document.createRange();return r.selectNodeContents(a),r.collapse(!1),r}}class RE extends zC{constructor(B){super();Z(this,"_editorElement");Z(this,"range");this._editorElement=B,this._recordRange=this._recordRange.bind(this),document.addEventListener("selectionchange",this._recordRange)}destroy(){document.removeEventListener("selectionchange",this._recordRange)}_recordRange(B){var o;this.isRangeInEditor()&&(this.range=(o=window.getSelection())==null?void 0:o.getRangeAt(0).cloneRange())}isRangeInEditor(){const B=window.getSelection();if(H(B)||!B.rangeCount)return!1;const o=B.getRangeAt(0);return this._editorElement.contains(o.commonAncestorContainer)}isCaret(){var B;return((B=this.range)==null?void 0:B.collapsed)===!0}isRange(){var B;return((B=this.range)==null?void 0:B.collapsed)===!1}getRangeContent(){var B;return this.isCaret()?"":((B=this.range)==null?void 0:B.toString())??""}toEnd(B){const o=window.getSelection();if(H(o))return;const i=document.createRange();i.setStartAfter(B),i.setEndAfter(B),o.removeAllRanges(),o.addRange(i)}getRangeTop(){var B;return(((B=this.range)==null?void 0:B.getBoundingClientRect().top)??0)-this._editorElement.getBoundingClientRect().top+16}}class FE extends ZC{constructor(B,o,i){super();Z(this,"_editor");Z(this,"_onUndoChange");Z(this,"contentManager");Z(this,"undoStack");Z(this,"redoStack");this._editor=B,this.contentManager=o,this.undoStack=[],this.redoStack=[],this._onUndoChange=i,this._handleInput=this._handleInput.bind(this),this._handleUndoOrRedo=this._handleUndoOrRedo.bind(this),this._editor.element.addEventListener("beforeinput",this._handleInput),this._editor.element.addEventListener("keydown",this._handleUndoOrRedo)}saveState(){}undo(){}redo(){}destroy(){this._editor.element.removeEventListener("beforeinput",this._handleInput),this._editor.element.removeEventListener("keydown",this._handleUndoOrRedo)}_calcNodePathMatches(B){const o=[];let i=B;for(;i&&i.parentElement;){const a=Array.from(i.parentElement.childNodes).indexOf(i);if(o.unshift({index:a}),QA(i)&&i.tagName==="P"&&i.classList.contains(NA))break;i=i.parentElement}return o}_record(){var D;const B=this._editor.cursor.range,o=this._editor.content.getParas(),i=bA(B.startContainer),c=o.indexOf(i),a=this._calcNodePathMatches(B.startContainer),r=bA(B.endContainer),h=o.indexOf(r),d=this._calcNodePathMatches(B.endContainer);return{startParaIndex:c,startMatchedIndexes:a,startOffset:B.startOffset,endParaIndex:h,endMatchedIndexes:d,endOffset:B.endOffset,content:this._editor.element.innerHTML,anchorContent:JSON.stringify(((D=this._editor.plugin.anchor)==null?void 0:D.data)??{})}}_handleInput(){this.undoStack.push(this._record()),this.redoStack=[]}_handleUndoOrRedo(B){var o;if(B.ctrlKey&&B.key==="z"&&(B.preventDefault(),this.undoStack.length>0)){this.redoStack.push(this._record());const i=this.undoStack.pop();this._editor.content.calcTextCount()&&requestAnimationFrame(()=>this._restoreCursor(i)),this._editor.element.innerHTML=i.content,(o=this._onUndoChange)==null||o.call(this,i.anchorContent)}}_restoreCursor(B){const o=window.getSelection();if(H(o))return;const i=h=>{let d=this._editor.content.getParas(),{index:D}=h[0],u=null,R=0;for(;R<h.length;){if(u=d[D],lA(u))return u;if(d=Array.from(u.childNodes),R++,R>=h.length)break;D=h[R].index}return u},c=i(B.startMatchedIndexes),a=i(B.endMatchedIndexes),r=document.createRange();r.setStart(c,B.startOffset),r.setEnd(a,B.endOffset),o.removeAllRanges(),o.addRange(r)}}const uA=[];for(let C=0;C<256;++C)uA.push((C+256).toString(16).slice(1));function NE(C,t=0){return(uA[C[t+0]]+uA[C[t+1]]+uA[C[t+2]]+uA[C[t+3]]+"-"+uA[C[t+4]]+uA[C[t+5]]+"-"+uA[C[t+6]]+uA[C[t+7]]+"-"+uA[C[t+8]]+uA[C[t+9]]+"-"+uA[C[t+10]]+uA[C[t+11]]+uA[C[t+12]]+uA[C[t+13]]+uA[C[t+14]]+uA[C[t+15]]).toLowerCase()}let LI;const kE=new Uint8Array(16);function GE(){if(!LI){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");LI=crypto.getRandomValues.bind(crypto)}return LI(kE)}const SE=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),YC={randomUUID:SE};function $C(C,t,B){var i;if(YC.randomUUID&&!C)return YC.randomUUID();C=C||{};const o=C.random??((i=C.rng)==null?void 0:i.call(C))??GE();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,NE(o)}const II=(C,t)=>{var c;const B=window.getSelection(),o=document.createRange(),i=t.lastChild;H(i)||H(B)||(o.setStartAfter(i),o.setEndAfter(i),B.removeAllRanges(),B.addRange(o),(c=C.plugin.pausation)==null||c.add({delay:1}))},oI=(C,t)=>{const B=new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,inputType:"insertText",data:"Hello"});C.element.dispatchEvent(B);const{range:o}=C.cursor,i=t[0],c=t[t.length-1],a=t.slice(1,-1);let r=o;if(!i||!r)return;let h=null,d=0,D=null;if(C.cursor.isRange()&&(h=r.startContainer,d=r.startOffset,D=r.endContainer,r.deleteContents()),t.length===1){C.content.insert(i);return}if(QA(r.commonAncestorContainer)&&r.commonAncestorContainer.tagName==="DIV"){const v=bA(h),O=bA(D),_=document.createDocumentFragment();for(;O!=null&&O.firstChild;)_.appendChild(O.firstChild);v==null||v.appendChild(_),O==null||O.remove();const V=window.getSelection(),BA=document.createRange();BA.setStart(h,d),BA.setEnd(h,d),V==null||V.removeAllRanges(),V==null||V.addRange(BA)}r=window.getSelection().getRangeAt(0),r=lA(r.commonAncestorContainer)&&r.commonAncestorContainer.textContent==="粘贴文本"?o:r;const[R]=kA(r.commonAncestorContainer,v=>v.tagName==="P"&&v.classList.contains(NA)),[F]=kA(r.startContainer,v=>v.tagName==="SPAN"&&v.dataset.type===x.anchor),f=document.createRange(),N=!!F;f.setStart(r.startContainer,r.startOffset),f.setEndAfter(R.lastChild);const U=f.extractContents();if(!(R!=null&&R.textContent))R.innerHTML=i;else if(lA(R.lastChild))R.lastChild.textContent+=i;else if(QA(R.lastChild)&&R.lastChild.dataset.type===x.anchor){const{lastChild:v}=R.lastChild;lA(v)?v.textContent+=i:v==null||v.appendChild(document.createTextNode(i))}else R.appendChild(document.createTextNode(i));II(C,N?R.lastChild:R);let{nextSibling:p}=R;if(a.forEach(v=>{var _;const O=document.createElement("p");if(O.classList.add(NA),O.textContent=v,(_=R==null?void 0:R.parentNode)==null||_.insertBefore(O,p),p=O.nextSibling,II(C,O),N){const V=F.cloneNode(!1);V.innerHTML=O.innerHTML,O.innerHTML=V.outerHTML}}),!c)return;const S=document.createElement("p");if(S.classList.add(NA),S.appendChild(U),!S.textContent)S.innerHTML=c;else if(lA(S.firstChild))S.firstChild.textContent=c+S.firstChild.textContent;else if(QA(S.firstChild)&&S.firstChild.dataset.type===x.anchor){const{firstChild:v}=S.firstChild;lA(v)?v.textContent=c+v.textContent:v==null||v.insertBefore(document.createTextNode(c),v.firstChild)}else S.insertBefore(document.createTextNode(c),S.firstChild);C.element.insertBefore(S,p),[.5,1,1.5,2,2.5].every(v=>{var O;return!((O=S.textContent)!=null&&O.trim().endsWith(`停顿: ${v}S`))})&&II(C,S)},[LE]=KA("paragraph"),NA=LE(),UE=`<p class="${NA}"><br /></p>`;class ME extends OC{constructor(B,o){super();Z(this,"_observer",null);Z(this,"_onchange");Z(this,"_editorElement");Z(this,"_uid");Z(this,"content");Z(this,"cursor");Z(this,"undo");Z(this,"command");Z(this,"maxLength");Z(this,"plugin");this._uid=$C(),this._editorElement=B,this.content=new fE(B,this),this.cursor=new RE(B),this.undo=new FE(this,this.content,o==null?void 0:o.onUndoChange),this.command=new DE(this.content,this.cursor),this.maxLength=(o==null?void 0:o.maxLength)??1e4,this.plugin=((o==null?void 0:o.plugins)??[]).reduce((i,c)=>{const a=new c(this),r=a.prefix;return i[r]=a,i},{}),this._onchange=o==null?void 0:o.onChange,this._handleBackspace=this._handleBackspace.bind(this),this._handlePaste=this._handlePaste.bind(this),this._handleBeforeInput=this._handleBeforeInput.bind(this),this._handleCompositionEnd=this._handleCompositionEnd.bind(this),this._setup()}destroy(){this._teardown()}editorTop(){return this._editorElement.getBoundingClientRect().top}editorLeft(){return this._editorElement.getBoundingClientRect().left}appendContent(B){this.content.appendContent(B,o=>II(this,o))}get element(){return this._editorElement}_setup(){this._observer=new MutationObserver(([B])=>{var o;if(B.removedNodes.length){const i=B.removedNodes[0];if(QA(i)&&i.dataset.type===x.highlight){const c=window.getSelection(),{range:a}=this.cursor;if(H(a)||H(c))return;const r=document.createTextNode(""),h=document.createRange();a.insertNode(r),h.setStartAfter(r),h.setEndAfter(r),c.removeAllRanges(),c.addRange(h)}}B.addedNodes.forEach(i=>{QA(i)&&i.tagName==="P"&&!i.classList.contains(NA)&&i.classList.add(NA)}),B.removedNodes.length&&!this.content.getParas().length&&this.content.insertEmptyPara(),(o=this._onchange)==null||o.call(this,this.content.calcTextCount()),Array.from(document.querySelectorAll("p span")).forEach(i=>{var D;const c=i.parentNode,a=i.firstChild,r=i&&i.style.textIndent==="20px"&&i.style.fontSize&&i.style.color,h=i&&i.style.backgroundColor&&((D=i.parentElement)==null?void 0:D.style.textIndent)==="0px",d=i&&Array.from(i.childNodes).every(u=>lA(u)&&!u.textContent||QA(u)&&u.tagName==="BR");if(r||h){for(;i.firstChild;)c==null||c.insertBefore(i.firstChild,i);c==null||c.removeChild(i),TA(a)}if(d&&(c==null||c.removeChild(i)),h){c.removeAttribute("style");const u=window.getSelection(),F=(u==null?void 0:u.getRangeAt(0)).cloneRange();F.setStartAfter(F.startContainer),F.setEndAfter(F.endContainer),u==null||u.removeAllRanges(),u==null||u.addRange(F)}}),this.content.getParas().forEach(i=>{const c=i.firstChild,a=i.lastChild;i.childNodes.length>1&&(QA(a)&&a.tagName==="BR"&&a.remove(),QA(c)&&c.tagName==="BR"&&c.remove()),(i.childNodes.length===0||i.childNodes.length===1&&lA(i.childNodes[0])&&i.childNodes[0].textContent==="")&&i.remove()})}),this._observer.observe(this._editorElement,{childList:!0,subtree:!0,characterData:!0}),this._editorElement.addEventListener("keydown",this._handleBackspace),this._editorElement.addEventListener("paste",this._handlePaste),this._editorElement.addEventListener("beforeinput",this._handleBeforeInput),this._editorElement.addEventListener("compositionend",this._handleCompositionEnd),Object.values(this.plugin).forEach(B=>B.setup())}_teardown(){var B;(B=this._observer)==null||B.disconnect(),this._observer=null,this.cursor.destroy(),this.undo.destroy(),this._editorElement.removeEventListener("keydown",this._handleBackspace),this._editorElement.removeEventListener("paste",this._handlePaste),this._editorElement.removeEventListener("beforeinput",this._handleBeforeInput),this._editorElement.removeEventListener("compositionend",this._handleCompositionEnd),Object.values(this.plugin).forEach(o=>o.destroy())}_handleBackspace(B){var c;const o=window.getSelection(),i=o.getRangeAt(0);if(B.key==="Backspace"&&i.startOffset===0&&i.collapsed){const[a]=kA(i.startContainer,h=>h.tagName==="P"&&h.classList.contains(NA)),r=a==null?void 0:a.previousElementSibling;if(r){B.preventDefault();const h=r.childNodes,d=r.childNodes[0];if(h.length===1&&(lA(d)&&d.textContent===""||QA(d)&&d.tagName==="BR")){r.remove();const D=document.createRange();D.setStartBefore(a.firstChild),D.setEndBefore(a.firstChild),o.removeAllRanges(),o.addRange(D)}else{const D=document.createRange();D.selectNodeContents(r),D.collapse(!1),o.removeAllRanges(),o.addRange(D);const u=document.createDocumentFragment(),R=a.firstChild;for(;a.firstChild;)u.appendChild(a.firstChild);D.insertNode(u),a.remove();const F=document.createRange();F.setStartBefore(R),F.setEndBefore(R),o.removeAllRanges(),o.addRange(F)}}}if(B.key==="Delete"&&pE()){const a=getSelection(),r=(c=getSelection())==null?void 0:c.getRangeAt(0);if(H(a)||H(r))return;const h=bA(r.endContainer),d=h==null?void 0:h.nextElementSibling;if(H(h)||H(d))return;const D=document.createRange();for(D.selectNodeContents(h),D.collapse(!1);d.firstChild;)h.appendChild(d.firstChild);d.remove(),a.removeAllRanges(),a.addRange(D),h.normalize()}if(B.key==="Enter"){const{range:a}=this.cursor;if(aE(a))return;const[r]=kA(a==null?void 0:a.commonAncestorContainer,h=>h.tagName==="SPAN"&&h.dataset.type===x.anchor);if(a!=null&&a.collapsed&&a.startOffset===0&&r){B.preventDefault();const h=document.createElement("p");h.innerHTML="<br />",this._editorElement.insertBefore(h,r.parentElement)}}if(i.startOffset===0&&i.endContainer.tagName==="P"&&bA(i.startContainer)===bA(i.endContainer)){const a=bA(i.endContainer);if(H(a))return;B.key==="Backspace"&&mE(a,o)}}_handlePaste(B){var i,c;B.preventDefault(),JE(this._editorElement);const o=((c=(i=B.clipboardData)==null?void 0:i.getData("text/plain"))==null?void 0:c.split(/(?:\r?\n){2,}/).map(a=>a.trim()).filter(a=>a))??[];oI(this,tI(this,o))}_handleBeforeInput(B){yE(this,B)}_handleCompositionEnd(B){uE(this,B)}}const hg=(C,t,B,o)=>{if(Object.keys(t).forEach(i=>{C.setAttribute(i,String(t[i]))}),Object.keys(B).forEach(i=>{C.dataset[i]=String(B[i])}),!H(o))if(PC(o)){const i=document.createDocumentFragment(),c=document.createElement("div");for(c.innerHTML=o;c.firstChild;)i.appendChild(c.firstChild);C.appendChild(i)}else C.appendChild(o)},kA=(C,t)=>{const B=jC(t)?t:[t];let o=C;for(;o;){const i=o,c=B.map(a=>a(i)).map(a=>a?i:null);if(c.some(a=>a))return c;o=o.parentElement}return new Array(B.length).fill(null)},bA=C=>{const[t]=kA(C,B=>B.tagName==="P"&&B.classList.contains(NA));return t},AB=(C,t)=>{if(C===t)return[];const B=[];let o=C.nextElementSibling;for(;o&&o!==t;)B.push(o),o=o.nextElementSibling;return B},$I=C=>{const t=document.createElement("div");return t.setAttribute("class",`editor-${C}-tag-modal`),t},TA=(C,t,B)=>{var a,r,h;const o=C.previousSibling,i=C.nextSibling,c=t??C.textContent??"";if(B&&(!o&&!i||QA(o)&&o.dataset.type===x.pausation||QA(o)&&[x.anchor,x.homophones,x.pausation,x.pronunciation].includes(o.dataset.type))){QA(C)&&C.dataset.type!==x.pausation?C.replaceWith(C.dataset.raw??""):(a=C.parentNode)==null||a.removeChild(C);return}if(lA(o)){o.textContent+=c,(r=C.parentNode)==null||r.removeChild(C),TA(o,o.textContent,!1);return}lA(i)&&(i.textContent=c+i.textContent,(h=C.parentNode)==null||h.removeChild(C),TA(i,i.textContent,!1))},UI=(C,t)=>{const B=C.length,o=t.length,i=new Array(o).fill(0);let c=i[0],a=0,r=0;for(let h=1;h<=B;h++){for(let d=1;d<=o;d++){const D=i[d];C[h-1]===t[d-1]?(i[d]=c+1,i[d]>a&&(a=Math.max(a,i[d]),r=d-1)):i[d]=0,c=D}c=i[0]}return t.substring(r-a+1,r+1)},pE=()=>{const C=window.getSelection();if(!C||!C.rangeCount||C.type!=="Caret")return!1;const t=C.getRangeAt(0);let B=t.endContainer;for(;B&&B.nodeName!=="P";)B=B.parentNode;if(!B)return!1;const o=t.cloneRange();return o.setEndAfter(B),o.toString().length===0},JE=C=>{const t=window.getSelection();if(!t.rangeCount)return;const B=Array.from(C.querySelectorAll("p"));if(B.length===0)return;let o=!1;for(const i of B)if(i.contains(t.anchorNode)){o=!0;break}if(!o){const i=document.createRange(),c=B[B.length-1];i.selectNodeContents(c),i.collapse(!1),t.removeAllRanges(),t.addRange(i)}},mE=(C,t)=>{if(!C)return;for(;C.firstChild;)C.removeChild(C.firstChild);C.appendChild(document.createElement("br"));const B=document.createRange();B.selectNodeContents(C),B.collapse(!1),t.removeAllRanges(),t.addRange(B)},gB=(C,t,B=0)=>{if(!C||!t)return{top:0,left:0,width:0,height:0};const o=C,i=t,c=i.bottom-o.top+B,a=i.left-o.left;return{top:c,left:a,width:i.width,height:i.height}};function IB(C){return E.getCurrentScope()?(E.onScopeDispose(C),!0):!1}const AC=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const YE=Object.prototype.toString,HE=C=>YE.call(C)==="[object Object]",WI=()=>{};function KE(C){let t;function B(){return t||(t=C()),t}return B.reset=async()=>{const o=t;t=void 0,o&&await o},B}function HC(C){return Array.isArray(C)?C:[C]}function vE(C,t,B={}){const{immediate:o=!0}=B,i=E.ref(!1);let c=null;function a(){c&&(clearTimeout(c),c=null)}function r(){i.value=!1,a()}function h(...d){a(),i.value=!0,c=setTimeout(()=>{i.value=!1,c=null,C(...d)},E.toValue(t))}return o&&(i.value=!0,AC&&h()),IB(r),{isPending:E.readonly(i),start:h,stop:r}}function CI(C=!1,t={}){const{truthyValue:B=!0,falsyValue:o=!1}=t,i=E.isRef(C),c=E.ref(C);function a(r){if(arguments.length)return c.value=r,c.value;{const h=E.toValue(B);return c.value=c.value===h?E.toValue(o):h,c.value}}return i?a:[c,a]}const CB=AC?window:void 0,BB=AC?window.navigator:void 0;function qE(C){var t;const B=E.toValue(C);return(t=B==null?void 0:B.$el)!=null?t:B}function cg(...C){let t,B,o,i;if(typeof C[0]=="string"||Array.isArray(C[0])?([B,o,i]=C,t=CB):[t,B,o,i]=C,!t)return WI;B=HC(B),o=HC(o);const c=[],a=()=>{c.forEach(D=>D()),c.length=0},r=(D,u,R,F)=>(D.addEventListener(u,R,F),()=>D.removeEventListener(u,R,F)),h=E.watch(()=>[qE(t),E.toValue(i)],([D,u])=>{if(a(),!D)return;const R=HE(u)?{...u}:u;c.push(...B.flatMap(F=>o.map(f=>r(D,F,f,R))))},{immediate:!0,flush:"post"}),d=()=>{h(),a()};return IB(d),d}function xE(){const C=E.ref(!1),t=E.getCurrentInstance();return t&&E.onMounted(()=>{C.value=!0},t),C}function QB(C){const t=xE();return E.computed(()=>(t.value,!!C()))}function KC(C,t={}){const{controls:B=!1,navigator:o=BB}=t,i=QB(()=>o&&"permissions"in o),c=E.shallowRef(),a=typeof C=="string"?{name:C}:C,r=E.shallowRef(),h=()=>{var D,u;r.value=(u=(D=c.value)==null?void 0:D.state)!=null?u:"prompt"};cg(c,"change",h,{passive:!0});const d=KE(async()=>{if(i.value){if(!c.value)try{c.value=await o.permissions.query(a)}catch{c.value=void 0}finally{h()}if(B)return E.toRaw(c.value)}});return d(),B?{state:r,isSupported:i,query:d}:r}function bE(C={}){const{navigator:t=BB,read:B=!1,source:o,copiedDuring:i=1500,legacy:c=!1}=C,a=QB(()=>t&&"clipboard"in t),r=KC("clipboard-read"),h=KC("clipboard-write"),d=E.computed(()=>a.value||c),D=E.ref(""),u=E.ref(!1),R=vE(()=>u.value=!1,i,{immediate:!1});function F(){a.value&&p(r.value)?t.clipboard.readText().then(S=>{D.value=S}):D.value=U()}d.value&&B&&cg(["copy","cut"],F,{passive:!0});async function f(S=E.toValue(o)){d.value&&S!=null&&(a.value&&p(h.value)?await t.clipboard.writeText(S):N(S),D.value=S,u.value=!0,R.start())}function N(S){const X=document.createElement("textarea");X.value=S??"",X.style.position="absolute",X.style.opacity="0",document.body.appendChild(X),X.select(),document.execCommand("copy"),X.remove()}function U(){var S,X,v;return(v=(X=(S=document==null?void 0:document.getSelection)==null?void 0:S.call(document))==null?void 0:X.toString())!=null?v:""}function p(S){return S==="granted"||S==="prompt"}return{isSupported:d,text:D,copied:u,copy:f}}const TE={page:C=>[C.pageX,C.pageY],client:C=>[C.clientX,C.clientY],screen:C=>[C.screenX,C.screenY],movement:C=>C instanceof Touch?null:[C.movementX,C.movementY]};function nI(C={}){const{type:t="page",touch:B=!0,resetOnTouchEnds:o=!1,initialValue:i={x:0,y:0},window:c=CB,target:a=c,scroll:r=!0,eventFilter:h}=C;let d=null,D=0,u=0;const R=E.ref(i.x),F=E.ref(i.y),f=E.ref(null),N=typeof t=="function"?t:TE[t],U=V=>{const BA=N(V);d=V,BA&&([R.value,F.value]=BA,f.value="mouse"),c&&(D=c.scrollX,u=c.scrollY)},p=V=>{if(V.touches.length>0){const BA=N(V.touches[0]);BA&&([R.value,F.value]=BA,f.value="touch")}},S=()=>{if(!d||!c)return;const V=N(d);d instanceof MouseEvent&&V&&(R.value=V[0]+c.scrollX-D,F.value=V[1]+c.scrollY-u)},X=()=>{R.value=i.x,F.value=i.y},v=h?V=>h(()=>U(V),{}):V=>U(V),O=h?V=>h(()=>p(V),{}):V=>p(V),_=h?()=>h(()=>S(),{}):()=>S();if(a){const V={passive:!0};cg(a,["mousemove","dragover"],v,V),B&&t!=="movement"&&(cg(a,["touchstart","touchmove"],O,V),o&&cg(a,"touchend",X,V)),r&&t==="page"&&cg(c,"scroll",_,V)}return{x:R,y:F,sourceType:f}}const VE=["onClick"],PE=E.defineComponent({__name:"pausationor",props:{visible:{type:Boolean}},emits:["ok"],setup(C,{emit:t}){const B=C,o=t,[i]=KA("pausation-tag-selector"),c=[{label:"0.5S",value:.5},{label:"1S",value:1},{label:"1.5S",value:1.5},{label:"2S",value:2},{label:"2.5S",value:2.5}];return(a,r)=>E.withDirectives((E.openBlock(),E.createElementBlock("ul",{class:E.normalizeClass(E.unref(i)()),contenteditable:"false",onClick:r[0]||(r[0]=E.withModifiers(()=>{},["stop"]))},[(E.openBlock(),E.createElementBlock(E.Fragment,null,E.renderList(c,(h,d)=>E.createElementVNode("li",{key:d,class:E.normalizeClass(E.unref(i)("item")),onClick:D=>o("ok",D,h.value)},E.toDisplayString(h.label),11,VE)),64))],2)),[[E.vShow,B.visible]])}}),wA=(C,t)=>{const B=C.__vccOpts||C;for(const[o,i]of t)B[o]=i;return B},EB=wA(PE,[["__scopeId","data-v-a957cba2"]]),jE=0,lg=x.pausation,[OI]=Ug(lg),eB=OI("close"),{x:WE,y:OE}=nI(),XE=`<svg class="${eB}" width="18px" height="18px" viewBox="0 0 18 18" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
1
|
+
"use strict";var iE=Object.defineProperty;var rE=(C,t,B)=>t in C?iE(C,t,{enumerable:!0,configurable:!0,writable:!0,value:B}):C[t]=B;var Z=(C,t,B)=>rE(C,typeof t!="symbol"?t+"":t,B);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const E=require("vue"),aA=require("@arco-design/web-vue");var ZI=C=>Object.prototype.toString.call(C),aE=C=>ZI(C)==="[object Null]",sE=C=>ZI(C)==="[object Number]",cE=C=>ZI(C)==="[object String]",jI=(C,t)=>t?typeof t=="string"?` ${C}--${t}`:Array.isArray(t)?t.reduce((B,o)=>B+jI(C,o),""):Object.keys(t).reduce((B,o)=>B+(t[o]?jI(C,o):""),""):"",lE=C=>(t,B)=>(t&&typeof t!="string"&&(B=t,t=""),t=t?`${C}__${t}`:C,`${t}${jI(t,B)}`),VC=C=>t=>{const B=`${C}-${t}`;return[lE(B),B]};const Ug=VC("tag"),KA=VC("c"),_I=C=>{let t=!1;return function(...o){t||(requestAnimationFrame(()=>{C.apply(this,o),t=!1}),t=!0)}},wE=()=>typeof window>"u"?!1:window.location.protocol==="https:",eI=C=>Object.prototype.toString.call(C).slice(8,-1).toLocaleLowerCase(),PC=C=>eI(C)==="string",jC=C=>eI(C)==="array",dE=C=>eI(C)==="null",hE=C=>eI(C)==="undefined",H=C=>dE(C)||hE(C),QA=C=>C instanceof HTMLElement,lA=C=>(C==null?void 0:C.nodeType)===Node.TEXT_NODE;var WC=(C=>(C.None="None",C.Caret="Caret",C.Range="Range",C))(WC||{}),x=(C=>(C.pausation="pausation",C.pronunciation="pronunciation",C.anchor="anchor",C.homophones="homophones",C.highlight="highlight",C))(x||{}),BI=(C=>(C.single="single",C.multiple="multiple",C))(BI||{});class OC{}class XC{}class zC{}class ZC{}class _C{}class Mg{}class DE extends _C{constructor(B,o){super();Z(this,"contentManager");Z(this,"cursorManager");this.contentManager=B,this.cursorManager=o}executeUndo(){}executeRedo(){}}const uE=(C,t)=>{var u;t.preventDefault();const B=((u=t.data)==null?void 0:u.length)??0,o=C.content.calcTextCount()-B,i=C.maxLength-o;if(i>=B||!B)return;const c=i<=0?B:B-i,a=window.getSelection(),r=a==null?void 0:a.getRangeAt(0);if(H(a)||H(r))return;const{endContainer:h,endOffset:d}=r,D=document.createRange();D.setStart(h,d-c),D.setEnd(h,d),D.deleteContents(),a.removeAllRanges(),a.addRange(D)},yE=(C,t)=>{const{inputType:B}=t;C.content.calcTextCount()>=C.maxLength&&B.includes("insert")&&B!=="insertParagraph"&&t.preventDefault()},tI=(C,t)=>{const B=[],o=C.content.calcTextCount();let i=C.maxLength-o;if(i<=0||!t.length)return[];let c=t.shift();for(;i>0&&c;){if(c.length>=i)return B.push(c.slice(0,i)),B;B.push(c),i-=c.length,c=t.shift()}return B};class fE extends XC{constructor(B,o){super();Z(this,"_editorElement");Z(this,"_editor");this._editorElement=B,this._editor=o}insertEmptyPara(){this._editorElement.innerHTML=UE}calcTextCount(){return this.getTextContent().reduce((B,o)=>B+o.length,0)}getContent(){return this._editorElement.innerHTML}getHtml(){return this.getContent()}setContent(B){this._editorElement.innerHTML=B}setHtml(B){this.setContent(B)}appendContent(B,o){var r;const i=tI(this._editor,jC(B)?B:[B]),c=this.getParas()[0],a=(r=c.textContent)!=null&&r.length?void 0:i.shift();a&&(c.innerHTML=a,o==null||o(c)),i.forEach(h=>{const d=document.createElement("p");d.innerHTML=h,d.classList.add(NA),this._editorElement.appendChild(d),o==null||o(d)})}insert(B){this._insert(B)}delete(){this._delete()}update(B){this._update(B)}getParas(){return Array.from(this._editorElement.querySelectorAll(`.${NA}`))}getTextContent(){const B=this.getParas(),o=i=>{const c=Array.from(i.childNodes);let a="";for(let r=0;r<c.length;r++){const h=c[r];lA(h)?a+=h.textContent??"":QA(h)&&(a+=x.anchor===h.dataset.type?o(h):x.pronunciation===h.dataset.type?h.dataset.value:h.dataset.raw??"")}return a};return B.map(o)}_insert(B){const o=window.getSelection(),i=this._editor.cursor.isRangeInEditor()?o==null?void 0:o.getRangeAt(0):this._editor.cursor.range;if(H(o)||!o.rangeCount||H(i))return;const c=document.createDocumentFragment();if(PC(B)){const d=document.createElement("div");for(d.innerHTML=B;d.firstChild;)c.appendChild(d.firstChild)}else c.appendChild(B);const a=c.lastChild;(this._calcRange(i)??i).insertNode(c);const h=document.createRange();h.setStartAfter(a),h.setEndAfter(a),o.removeAllRanges(),o.addRange(h)}_delete(){const{range:B}=this._editor.cursor;B==null||B.deleteContents()}_update(B){this._delete(),this._insert(B)}_calcRange(B){const o=B.commonAncestorContainer;if(o.tagName!=="DIV")return B;const i=B.startOffset,c=Array.from(o.children).filter(h=>h.tagName==="P");if(i<=0||i-1>=c.length)return console.warn("上一个 <p> 不存在"),B;const a=c[i-1];if(!a)return console.warn("未找到上一个 <p>"),B;const r=document.createRange();return r.selectNodeContents(a),r.collapse(!1),r}}class RE extends zC{constructor(B){super();Z(this,"_editorElement");Z(this,"range");this._editorElement=B,this._recordRange=this._recordRange.bind(this),document.addEventListener("selectionchange",this._recordRange)}destroy(){document.removeEventListener("selectionchange",this._recordRange)}_recordRange(B){var o;this.isRangeInEditor()&&(this.range=(o=window.getSelection())==null?void 0:o.getRangeAt(0).cloneRange())}isRangeInEditor(){const B=window.getSelection();if(H(B)||!B.rangeCount)return!1;const o=B.getRangeAt(0);return this._editorElement.contains(o.commonAncestorContainer)}isCaret(){var B;return((B=this.range)==null?void 0:B.collapsed)===!0}isRange(){var B;return((B=this.range)==null?void 0:B.collapsed)===!1}getRangeContent(){var B;return this.isCaret()?"":((B=this.range)==null?void 0:B.toString())??""}toEnd(B){const o=window.getSelection();if(H(o))return;const i=document.createRange();i.setStartAfter(B),i.setEndAfter(B),o.removeAllRanges(),o.addRange(i)}getRangeTop(){var B;return(((B=this.range)==null?void 0:B.getBoundingClientRect().top)??0)-this._editorElement.getBoundingClientRect().top+16}}class FE extends ZC{constructor(B,o,i){super();Z(this,"_editor");Z(this,"_onUndoChange");Z(this,"contentManager");Z(this,"undoStack");Z(this,"redoStack");this._editor=B,this.contentManager=o,this.undoStack=[],this.redoStack=[],this._onUndoChange=i,this._handleInput=this._handleInput.bind(this),this._handleUndoOrRedo=this._handleUndoOrRedo.bind(this),this._editor.element.addEventListener("beforeinput",this._handleInput),this._editor.element.addEventListener("keydown",this._handleUndoOrRedo)}saveState(){}undo(){}redo(){}destroy(){this._editor.element.removeEventListener("beforeinput",this._handleInput),this._editor.element.removeEventListener("keydown",this._handleUndoOrRedo)}_calcNodePathMatches(B){const o=[];let i=B;for(;i&&i.parentElement;){const a=Array.from(i.parentElement.childNodes).indexOf(i);if(o.unshift({index:a}),QA(i)&&i.tagName==="P"&&i.classList.contains(NA))break;i=i.parentElement}return o}_record(){var D;const B=this._editor.cursor.range,o=this._editor.content.getParas(),i=bA(B.startContainer),c=o.indexOf(i),a=this._calcNodePathMatches(B.startContainer),r=bA(B.endContainer),h=o.indexOf(r),d=this._calcNodePathMatches(B.endContainer);return{startParaIndex:c,startMatchedIndexes:a,startOffset:B.startOffset,endParaIndex:h,endMatchedIndexes:d,endOffset:B.endOffset,content:this._editor.element.innerHTML,anchorContent:JSON.stringify(((D=this._editor.plugin.anchor)==null?void 0:D.data)??{})}}_handleInput(){this.undoStack.push(this._record()),this.redoStack=[]}_handleUndoOrRedo(B){var o;if(B.ctrlKey&&B.key==="z"&&(B.preventDefault(),this.undoStack.length>0)){this.redoStack.push(this._record());const i=this.undoStack.pop();this._editor.content.calcTextCount()&&requestAnimationFrame(()=>this._restoreCursor(i)),this._editor.element.innerHTML=i.content,(o=this._onUndoChange)==null||o.call(this,i.anchorContent)}}_restoreCursor(B){const o=window.getSelection();if(H(o))return;const i=h=>{let d=this._editor.content.getParas(),{index:D}=h[0],u=null,R=0;for(;R<h.length;){if(u=d[D],lA(u))return u;if(d=Array.from(u.childNodes),R++,R>=h.length)break;D=h[R].index}return u},c=i(B.startMatchedIndexes),a=i(B.endMatchedIndexes),r=document.createRange();r.setStart(c,B.startOffset),r.setEnd(a,B.endOffset),o.removeAllRanges(),o.addRange(r)}}const uA=[];for(let C=0;C<256;++C)uA.push((C+256).toString(16).slice(1));function NE(C,t=0){return(uA[C[t+0]]+uA[C[t+1]]+uA[C[t+2]]+uA[C[t+3]]+"-"+uA[C[t+4]]+uA[C[t+5]]+"-"+uA[C[t+6]]+uA[C[t+7]]+"-"+uA[C[t+8]]+uA[C[t+9]]+"-"+uA[C[t+10]]+uA[C[t+11]]+uA[C[t+12]]+uA[C[t+13]]+uA[C[t+14]]+uA[C[t+15]]).toLowerCase()}let LI;const kE=new Uint8Array(16);function GE(){if(!LI){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");LI=crypto.getRandomValues.bind(crypto)}return LI(kE)}const SE=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),YC={randomUUID:SE};function $C(C,t,B){var i;if(YC.randomUUID&&!C)return YC.randomUUID();C=C||{};const o=C.random??((i=C.rng)==null?void 0:i.call(C))??GE();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,NE(o)}const II=(C,t)=>{var c;const B=window.getSelection(),o=document.createRange(),i=t.lastChild;H(i)||H(B)||(o.setStartAfter(i),o.setEndAfter(i),B.removeAllRanges(),B.addRange(o),(c=C.plugin.pausation)==null||c.add({delay:1}))},oI=(C,t)=>{const B=new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,inputType:"insertText",data:"Hello"});C.element.dispatchEvent(B);const{range:o}=C.cursor,i=t[0],c=t[t.length-1],a=t.slice(1,-1);let r=o;if(!i||!r)return;let h=null,d=0,D=null;if(C.cursor.isRange()&&(h=r.startContainer,d=r.startOffset,D=r.endContainer,r.deleteContents()),t.length===1){C.content.insert(i);return}if(QA(r.commonAncestorContainer)&&r.commonAncestorContainer.tagName==="DIV"){const v=bA(h),O=bA(D),_=document.createDocumentFragment();for(;O!=null&&O.firstChild;)_.appendChild(O.firstChild);v==null||v.appendChild(_),O==null||O.remove();const V=window.getSelection(),BA=document.createRange();BA.setStart(h,d),BA.setEnd(h,d),V==null||V.removeAllRanges(),V==null||V.addRange(BA)}r=C.cursor.isRangeInEditor()?window.getSelection().getRangeAt(0):o,r=lA(r.commonAncestorContainer)&&r.commonAncestorContainer.textContent==="粘贴文本"?o:r;const[R]=kA(r.commonAncestorContainer,v=>v.tagName==="P"&&v.classList.contains(NA)),[F]=kA(r.startContainer,v=>v.tagName==="SPAN"&&v.dataset.type===x.anchor),f=document.createRange(),N=!!F;f.setStart(r.startContainer,r.startOffset),f.setEndAfter(R.lastChild);const U=f.extractContents();if(!(R!=null&&R.textContent))R.innerHTML=i;else if(lA(R.lastChild))R.lastChild.textContent+=i;else if(QA(R.lastChild)&&R.lastChild.dataset.type===x.anchor){const{lastChild:v}=R.lastChild;lA(v)?v.textContent+=i:v==null||v.appendChild(document.createTextNode(i))}else R.appendChild(document.createTextNode(i));II(C,N?R.lastChild:R);let{nextSibling:p}=R;if(a.forEach(v=>{var _;const O=document.createElement("p");if(O.classList.add(NA),O.textContent=v,(_=R==null?void 0:R.parentNode)==null||_.insertBefore(O,p),p=O.nextSibling,II(C,O),N){const V=F.cloneNode(!1);V.innerHTML=O.innerHTML,O.innerHTML=V.outerHTML}}),!c)return;const S=document.createElement("p");if(S.classList.add(NA),S.appendChild(U),!S.textContent)S.innerHTML=c;else if(lA(S.firstChild))S.firstChild.textContent=c+S.firstChild.textContent;else if(QA(S.firstChild)&&S.firstChild.dataset.type===x.anchor){const{firstChild:v}=S.firstChild;lA(v)?v.textContent=c+v.textContent:v==null||v.insertBefore(document.createTextNode(c),v.firstChild)}else S.insertBefore(document.createTextNode(c),S.firstChild);C.element.insertBefore(S,p),[.5,1,1.5,2,2.5].every(v=>{var O;return!((O=S.textContent)!=null&&O.trim().endsWith(`停顿: ${v}S`))})&&II(C,S)},[LE]=KA("paragraph"),NA=LE(),UE=`<p class="${NA}"><br /></p>`;class ME extends OC{constructor(B,o){super();Z(this,"_observer",null);Z(this,"_onchange");Z(this,"_editorElement");Z(this,"_uid");Z(this,"content");Z(this,"cursor");Z(this,"undo");Z(this,"command");Z(this,"maxLength");Z(this,"plugin");this._uid=$C(),this._editorElement=B,this.content=new fE(B,this),this.cursor=new RE(B),this.undo=new FE(this,this.content,o==null?void 0:o.onUndoChange),this.command=new DE(this.content,this.cursor),this.maxLength=(o==null?void 0:o.maxLength)??1e4,this.plugin=((o==null?void 0:o.plugins)??[]).reduce((i,c)=>{const a=new c(this),r=a.prefix;return i[r]=a,i},{}),this._onchange=o==null?void 0:o.onChange,this._handleBackspace=this._handleBackspace.bind(this),this._handlePaste=this._handlePaste.bind(this),this._handleBeforeInput=this._handleBeforeInput.bind(this),this._handleCompositionEnd=this._handleCompositionEnd.bind(this),this._setup()}destroy(){this._teardown()}editorTop(){return this._editorElement.getBoundingClientRect().top}editorLeft(){return this._editorElement.getBoundingClientRect().left}appendContent(B){this.content.appendContent(B,o=>II(this,o))}get element(){return this._editorElement}_setup(){this._observer=new MutationObserver(([B])=>{var o;if(B.removedNodes.length){const i=B.removedNodes[0];if(QA(i)&&i.dataset.type===x.highlight){const c=window.getSelection(),{range:a}=this.cursor;if(H(a)||H(c))return;const r=document.createTextNode(""),h=document.createRange();a.insertNode(r),h.setStartAfter(r),h.setEndAfter(r),c.removeAllRanges(),c.addRange(h)}}B.addedNodes.forEach(i=>{QA(i)&&i.tagName==="P"&&!i.classList.contains(NA)&&i.classList.add(NA)}),B.removedNodes.length&&!this.content.getParas().length&&this.content.insertEmptyPara(),(o=this._onchange)==null||o.call(this,this.content.calcTextCount()),Array.from(document.querySelectorAll("p span")).forEach(i=>{var D;const c=i.parentNode,a=i.firstChild,r=i&&i.style.textIndent==="20px"&&i.style.fontSize&&i.style.color,h=i&&i.style.backgroundColor&&((D=i.parentElement)==null?void 0:D.style.textIndent)==="0px",d=i&&Array.from(i.childNodes).every(u=>lA(u)&&!u.textContent||QA(u)&&u.tagName==="BR");if(r||h){for(;i.firstChild;)c==null||c.insertBefore(i.firstChild,i);c==null||c.removeChild(i),TA(a)}if(d&&(c==null||c.removeChild(i)),h){c.removeAttribute("style");const u=window.getSelection(),F=(u==null?void 0:u.getRangeAt(0)).cloneRange();F.setStartAfter(F.startContainer),F.setEndAfter(F.endContainer),u==null||u.removeAllRanges(),u==null||u.addRange(F)}}),this.content.getParas().forEach(i=>{const c=i.firstChild,a=i.lastChild;i.childNodes.length>1&&(QA(a)&&a.tagName==="BR"&&a.remove(),QA(c)&&c.tagName==="BR"&&c.remove()),(i.childNodes.length===0||i.childNodes.length===1&&lA(i.childNodes[0])&&i.childNodes[0].textContent==="")&&i.remove()})}),this._observer.observe(this._editorElement,{childList:!0,subtree:!0,characterData:!0}),this._editorElement.addEventListener("keydown",this._handleBackspace),this._editorElement.addEventListener("paste",this._handlePaste),this._editorElement.addEventListener("beforeinput",this._handleBeforeInput),this._editorElement.addEventListener("compositionend",this._handleCompositionEnd),Object.values(this.plugin).forEach(B=>B.setup())}_teardown(){var B;(B=this._observer)==null||B.disconnect(),this._observer=null,this.cursor.destroy(),this.undo.destroy(),this._editorElement.removeEventListener("keydown",this._handleBackspace),this._editorElement.removeEventListener("paste",this._handlePaste),this._editorElement.removeEventListener("beforeinput",this._handleBeforeInput),this._editorElement.removeEventListener("compositionend",this._handleCompositionEnd),Object.values(this.plugin).forEach(o=>o.destroy())}_handleBackspace(B){var c;const o=window.getSelection(),i=o.getRangeAt(0);if(B.key==="Backspace"&&i.startOffset===0&&i.collapsed){const[a]=kA(i.startContainer,h=>h.tagName==="P"&&h.classList.contains(NA)),r=a==null?void 0:a.previousElementSibling;if(r){B.preventDefault();const h=r.childNodes,d=r.childNodes[0];if(h.length===1&&(lA(d)&&d.textContent===""||QA(d)&&d.tagName==="BR")){r.remove();const D=document.createRange();D.setStartBefore(a.firstChild),D.setEndBefore(a.firstChild),o.removeAllRanges(),o.addRange(D)}else{const D=document.createRange();D.selectNodeContents(r),D.collapse(!1),o.removeAllRanges(),o.addRange(D);const u=document.createDocumentFragment(),R=a.firstChild;for(;a.firstChild;)u.appendChild(a.firstChild);D.insertNode(u),a.remove();const F=document.createRange();F.setStartBefore(R),F.setEndBefore(R),o.removeAllRanges(),o.addRange(F)}}}if(B.key==="Delete"&&pE()){const a=getSelection(),r=(c=getSelection())==null?void 0:c.getRangeAt(0);if(H(a)||H(r))return;const h=bA(r.endContainer),d=h==null?void 0:h.nextElementSibling;if(H(h)||H(d))return;const D=document.createRange();for(D.selectNodeContents(h),D.collapse(!1);d.firstChild;)h.appendChild(d.firstChild);d.remove(),a.removeAllRanges(),a.addRange(D),h.normalize()}if(B.key==="Enter"){const{range:a}=this.cursor;if(aE(a))return;const[r]=kA(a==null?void 0:a.commonAncestorContainer,h=>h.tagName==="SPAN"&&h.dataset.type===x.anchor);if(a!=null&&a.collapsed&&a.startOffset===0&&r){B.preventDefault();const h=document.createElement("p");h.innerHTML="<br />",this._editorElement.insertBefore(h,r.parentElement)}}if(i.startOffset===0&&i.endContainer.tagName==="P"&&bA(i.startContainer)===bA(i.endContainer)){const a=bA(i.endContainer);if(H(a))return;B.key==="Backspace"&&mE(a,o)}}_handlePaste(B){var i,c;B.preventDefault(),JE(this._editorElement);const o=((c=(i=B.clipboardData)==null?void 0:i.getData("text/plain"))==null?void 0:c.split(/(?:\r?\n){2,}/).map(a=>a.trim()).filter(a=>a))??[];oI(this,tI(this,o))}_handleBeforeInput(B){yE(this,B)}_handleCompositionEnd(B){uE(this,B)}}const hg=(C,t,B,o)=>{if(Object.keys(t).forEach(i=>{C.setAttribute(i,String(t[i]))}),Object.keys(B).forEach(i=>{C.dataset[i]=String(B[i])}),!H(o))if(PC(o)){const i=document.createDocumentFragment(),c=document.createElement("div");for(c.innerHTML=o;c.firstChild;)i.appendChild(c.firstChild);C.appendChild(i)}else C.appendChild(o)},kA=(C,t)=>{const B=jC(t)?t:[t];let o=C;for(;o;){const i=o,c=B.map(a=>a(i)).map(a=>a?i:null);if(c.some(a=>a))return c;o=o.parentElement}return new Array(B.length).fill(null)},bA=C=>{const[t]=kA(C,B=>B.tagName==="P"&&B.classList.contains(NA));return t},AB=(C,t)=>{if(C===t)return[];const B=[];let o=C.nextElementSibling;for(;o&&o!==t;)B.push(o),o=o.nextElementSibling;return B},$I=C=>{const t=document.createElement("div");return t.setAttribute("class",`editor-${C}-tag-modal`),t},TA=(C,t,B)=>{var a,r,h;const o=C.previousSibling,i=C.nextSibling,c=t??C.textContent??"";if(B&&(!o&&!i||QA(o)&&o.dataset.type===x.pausation||QA(o)&&[x.anchor,x.homophones,x.pausation,x.pronunciation].includes(o.dataset.type))){QA(C)&&C.dataset.type!==x.pausation?C.replaceWith(C.dataset.raw??""):(a=C.parentNode)==null||a.removeChild(C);return}if(lA(o)){o.textContent+=c,(r=C.parentNode)==null||r.removeChild(C),TA(o,o.textContent,!1);return}lA(i)&&(i.textContent=c+i.textContent,(h=C.parentNode)==null||h.removeChild(C),TA(i,i.textContent,!1))},UI=(C,t)=>{const B=C.length,o=t.length,i=new Array(o).fill(0);let c=i[0],a=0,r=0;for(let h=1;h<=B;h++){for(let d=1;d<=o;d++){const D=i[d];C[h-1]===t[d-1]?(i[d]=c+1,i[d]>a&&(a=Math.max(a,i[d]),r=d-1)):i[d]=0,c=D}c=i[0]}return t.substring(r-a+1,r+1)},pE=()=>{const C=window.getSelection();if(!C||!C.rangeCount||C.type!=="Caret")return!1;const t=C.getRangeAt(0);let B=t.endContainer;for(;B&&B.nodeName!=="P";)B=B.parentNode;if(!B)return!1;const o=t.cloneRange();return o.setEndAfter(B),o.toString().length===0},JE=C=>{const t=window.getSelection();if(!t.rangeCount)return;const B=Array.from(C.querySelectorAll("p"));if(B.length===0)return;let o=!1;for(const i of B)if(i.contains(t.anchorNode)){o=!0;break}if(!o){const i=document.createRange(),c=B[B.length-1];i.selectNodeContents(c),i.collapse(!1),t.removeAllRanges(),t.addRange(i)}},mE=(C,t)=>{if(!C)return;for(;C.firstChild;)C.removeChild(C.firstChild);C.appendChild(document.createElement("br"));const B=document.createRange();B.selectNodeContents(C),B.collapse(!1),t.removeAllRanges(),t.addRange(B)},gB=(C,t,B=0)=>{if(!C||!t)return{top:0,left:0,width:0,height:0};const o=C,i=t,c=i.bottom-o.top+B,a=i.left-o.left;return{top:c,left:a,width:i.width,height:i.height}};function IB(C){return E.getCurrentScope()?(E.onScopeDispose(C),!0):!1}const AC=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const YE=Object.prototype.toString,HE=C=>YE.call(C)==="[object Object]",WI=()=>{};function KE(C){let t;function B(){return t||(t=C()),t}return B.reset=async()=>{const o=t;t=void 0,o&&await o},B}function HC(C){return Array.isArray(C)?C:[C]}function vE(C,t,B={}){const{immediate:o=!0}=B,i=E.ref(!1);let c=null;function a(){c&&(clearTimeout(c),c=null)}function r(){i.value=!1,a()}function h(...d){a(),i.value=!0,c=setTimeout(()=>{i.value=!1,c=null,C(...d)},E.toValue(t))}return o&&(i.value=!0,AC&&h()),IB(r),{isPending:E.readonly(i),start:h,stop:r}}function CI(C=!1,t={}){const{truthyValue:B=!0,falsyValue:o=!1}=t,i=E.isRef(C),c=E.ref(C);function a(r){if(arguments.length)return c.value=r,c.value;{const h=E.toValue(B);return c.value=c.value===h?E.toValue(o):h,c.value}}return i?a:[c,a]}const CB=AC?window:void 0,BB=AC?window.navigator:void 0;function qE(C){var t;const B=E.toValue(C);return(t=B==null?void 0:B.$el)!=null?t:B}function cg(...C){let t,B,o,i;if(typeof C[0]=="string"||Array.isArray(C[0])?([B,o,i]=C,t=CB):[t,B,o,i]=C,!t)return WI;B=HC(B),o=HC(o);const c=[],a=()=>{c.forEach(D=>D()),c.length=0},r=(D,u,R,F)=>(D.addEventListener(u,R,F),()=>D.removeEventListener(u,R,F)),h=E.watch(()=>[qE(t),E.toValue(i)],([D,u])=>{if(a(),!D)return;const R=HE(u)?{...u}:u;c.push(...B.flatMap(F=>o.map(f=>r(D,F,f,R))))},{immediate:!0,flush:"post"}),d=()=>{h(),a()};return IB(d),d}function xE(){const C=E.ref(!1),t=E.getCurrentInstance();return t&&E.onMounted(()=>{C.value=!0},t),C}function QB(C){const t=xE();return E.computed(()=>(t.value,!!C()))}function KC(C,t={}){const{controls:B=!1,navigator:o=BB}=t,i=QB(()=>o&&"permissions"in o),c=E.shallowRef(),a=typeof C=="string"?{name:C}:C,r=E.shallowRef(),h=()=>{var D,u;r.value=(u=(D=c.value)==null?void 0:D.state)!=null?u:"prompt"};cg(c,"change",h,{passive:!0});const d=KE(async()=>{if(i.value){if(!c.value)try{c.value=await o.permissions.query(a)}catch{c.value=void 0}finally{h()}if(B)return E.toRaw(c.value)}});return d(),B?{state:r,isSupported:i,query:d}:r}function bE(C={}){const{navigator:t=BB,read:B=!1,source:o,copiedDuring:i=1500,legacy:c=!1}=C,a=QB(()=>t&&"clipboard"in t),r=KC("clipboard-read"),h=KC("clipboard-write"),d=E.computed(()=>a.value||c),D=E.ref(""),u=E.ref(!1),R=vE(()=>u.value=!1,i,{immediate:!1});function F(){a.value&&p(r.value)?t.clipboard.readText().then(S=>{D.value=S}):D.value=U()}d.value&&B&&cg(["copy","cut"],F,{passive:!0});async function f(S=E.toValue(o)){d.value&&S!=null&&(a.value&&p(h.value)?await t.clipboard.writeText(S):N(S),D.value=S,u.value=!0,R.start())}function N(S){const X=document.createElement("textarea");X.value=S??"",X.style.position="absolute",X.style.opacity="0",document.body.appendChild(X),X.select(),document.execCommand("copy"),X.remove()}function U(){var S,X,v;return(v=(X=(S=document==null?void 0:document.getSelection)==null?void 0:S.call(document))==null?void 0:X.toString())!=null?v:""}function p(S){return S==="granted"||S==="prompt"}return{isSupported:d,text:D,copied:u,copy:f}}const TE={page:C=>[C.pageX,C.pageY],client:C=>[C.clientX,C.clientY],screen:C=>[C.screenX,C.screenY],movement:C=>C instanceof Touch?null:[C.movementX,C.movementY]};function nI(C={}){const{type:t="page",touch:B=!0,resetOnTouchEnds:o=!1,initialValue:i={x:0,y:0},window:c=CB,target:a=c,scroll:r=!0,eventFilter:h}=C;let d=null,D=0,u=0;const R=E.ref(i.x),F=E.ref(i.y),f=E.ref(null),N=typeof t=="function"?t:TE[t],U=V=>{const BA=N(V);d=V,BA&&([R.value,F.value]=BA,f.value="mouse"),c&&(D=c.scrollX,u=c.scrollY)},p=V=>{if(V.touches.length>0){const BA=N(V.touches[0]);BA&&([R.value,F.value]=BA,f.value="touch")}},S=()=>{if(!d||!c)return;const V=N(d);d instanceof MouseEvent&&V&&(R.value=V[0]+c.scrollX-D,F.value=V[1]+c.scrollY-u)},X=()=>{R.value=i.x,F.value=i.y},v=h?V=>h(()=>U(V),{}):V=>U(V),O=h?V=>h(()=>p(V),{}):V=>p(V),_=h?()=>h(()=>S(),{}):()=>S();if(a){const V={passive:!0};cg(a,["mousemove","dragover"],v,V),B&&t!=="movement"&&(cg(a,["touchstart","touchmove"],O,V),o&&cg(a,"touchend",X,V)),r&&t==="page"&&cg(c,"scroll",_,V)}return{x:R,y:F,sourceType:f}}const VE=["onClick"],PE=E.defineComponent({__name:"pausationor",props:{visible:{type:Boolean}},emits:["ok"],setup(C,{emit:t}){const B=C,o=t,[i]=KA("pausation-tag-selector"),c=[{label:"0.5S",value:.5},{label:"1S",value:1},{label:"1.5S",value:1.5},{label:"2S",value:2},{label:"2.5S",value:2.5}];return(a,r)=>E.withDirectives((E.openBlock(),E.createElementBlock("ul",{class:E.normalizeClass(E.unref(i)()),contenteditable:"false",onClick:r[0]||(r[0]=E.withModifiers(()=>{},["stop"]))},[(E.openBlock(),E.createElementBlock(E.Fragment,null,E.renderList(c,(h,d)=>E.createElementVNode("li",{key:d,class:E.normalizeClass(E.unref(i)("item")),onClick:D=>o("ok",D,h.value)},E.toDisplayString(h.label),11,VE)),64))],2)),[[E.vShow,B.visible]])}}),wA=(C,t)=>{const B=C.__vccOpts||C;for(const[o,i]of t)B[o]=i;return B},EB=wA(PE,[["__scopeId","data-v-a957cba2"]]),jE=0,lg=x.pausation,[OI]=Ug(lg),eB=OI("close"),{x:WE,y:OE}=nI(),XE=`<svg class="${eB}" width="18px" height="18px" viewBox="0 0 18 18" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
2
2
|
<g id="V1.0" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
3
3
|
<g id="虚拟精品录音间-插入停顿" transform="translate(-1287, -152)" fill="currentColor" fill-rule="nonzero">
|
|
4
4
|
<g id="编组-4备份-4" transform="translate(1227, 149)">
|