@linker-design-plus/tiny-peony 1.4.4 → 1.4.5
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 re=Object.defineProperty;var ae=(I,t,B)=>t in I?re(I,t,{enumerable:!0,configurable:!0,writable:!0,value:B}):I[t]=B;var AA=(I,t,B)=>ae(I,typeof t!="symbol"?t+"":t,B);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),RA=require("@arco-design/web-vue");var AC=I=>Object.prototype.toString.call(I),se=I=>AC(I)==="[object Null]",ce=I=>AC(I)==="[object Number]",le=I=>AC(I)==="[object String]",OI=(I,t)=>t?typeof t=="string"?` ${I}--${t}`:Array.isArray(t)?t.reduce((B,n)=>B+OI(I,n),""):Object.keys(t).reduce((B,n)=>B+(t[n]?OI(I,n):""),""):"",de=I=>(t,B)=>(t&&typeof t!="string"&&(B=t,t=""),t=t?`${I}__${t}`:I,`${t}${OI(t,B)}`),jC=I=>t=>{const B=`${I}-${t}`;return[de(B),B]};const Yg=jC("tag"),bA=jC("c"),EI=I=>{let t=!1;return function(...n){t||(requestAnimationFrame(()=>{I.apply(this,n),t=!1}),t=!0)}},we=()=>typeof window>"u"?!1:window.location.protocol==="https:",nI=I=>Object.prototype.toString.call(I).slice(8,-1).toLocaleLowerCase(),WC=I=>nI(I)==="string",OC=I=>nI(I)==="array",he=I=>nI(I)==="null",De=I=>nI(I)==="undefined",v=I=>he(I)||De(I),CA=I=>I instanceof HTMLElement,FA=I=>(I==null?void 0:I.nodeType)===Node.TEXT_NODE;var zC=(I=>(I.None="None",I.Caret="Caret",I.Range="Range",I))(zC||{}),b=(I=>(I.pausation="pausation",I.pronunciation="pronunciation",I.anchor="anchor",I.homophones="homophones",I.highlight="highlight",I))(b||{}),gC=(I=>(I.single="single",I.multiple="multiple",I))(gC||{});class XC{}class ZC{}class _C{}class $C{}class AB{}class Hg{}class ue extends AB{constructor(B,n){super();AA(this,"contentManager");AA(this,"cursorManager");this.contentManager=B,this.cursorManager=n}executeUndo(){}executeRedo(){}}const ye=(I,t)=>{var f;t.preventDefault();const B=((f=t.data)==null?void 0:f.length)??0,n=I.content.calcTextCount()-B,o=I.maxLength-n;if(o>=B||!B)return;const c=o<=0?B:B-o,a=window.getSelection(),r=a==null?void 0:a.getRangeAt(0);if(v(a)||v(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)},fe=(I,t)=>{const{inputType:B}=t;I.content.calcTextCount()>=I.maxLength&&B.includes("insert")&&B!=="insertParagraph"&&t.preventDefault()},iI=(I,t)=>{const B=[],n=I.content.calcTextCount();let o=I.maxLength-n;if(o<=0||!t.length)return[];let c=t.shift();for(;o>0&&c;){if(c.length>=o)return B.push(c.slice(0,o)),B;B.push(c),o-=c.length,c=t.shift()}return B};class Re extends ZC{constructor(B,n){super();AA(this,"_editorElement");AA(this,"_editor");this._editorElement=B,this._editor=n}insertEmptyPara(){this._editorElement.innerHTML=Me}calcTextCount(){return this.getTextContent().reduce((B,n)=>B+n.length,0)}getContent(){return this._editorElement.innerHTML}getHtml(){return this.getContent()}setContent(B){this._editorElement.innerHTML=B}setHtml(B){this.setContent(B)}appendContent(B,n){var r;const o=iI(this._editor,OC(B)?B:[B]),c=this.getParas()[0],a=(r=c.textContent)!=null&&r.length?void 0:o.shift();a&&(c.innerHTML=a,n==null||n(c)),o.forEach(h=>{const d=document.createElement("p");d.innerHTML=h,d.classList.add(yA),this._editorElement.appendChild(d),n==null||n(d)})}insert(B){this._insert(B)}delete(){this._delete()}update(B){this._update(B)}getParas(){return Array.from(this._editorElement.querySelectorAll(`.${yA}`))}getTextContent(){const B=this.getParas(),n=o=>{const c=Array.from(o.childNodes);let a="";for(let r=0;r<c.length;r++){const h=c[r];FA(h)?a+=h.textContent??"":CA(h)&&(a+=b.anchor===h.dataset.type?n(h):b.pronunciation===h.dataset.type?h.dataset.value:h.dataset.raw??"")}return a};return B.map(n)}_insert(B){const n=window.getSelection(),o=this._editor.cursor.isRangeInEditor()?n==null?void 0:n.getRangeAt(0):this._editor.cursor.range;if(v(n)||!n.rangeCount||v(o))return;const c=document.createDocumentFragment();if(WC(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(o)??o).insertNode(c);const h=document.createRange();h.setStartAfter(a),h.setEndAfter(a),n.removeAllRanges(),n.addRange(h)}_delete(){const{range:B}=this._editor.cursor;B==null||B.deleteContents()}_update(B){this._delete(),this._insert(B)}_calcRange(B){const n=B.commonAncestorContainer;if(n.tagName!=="DIV")return B;const o=B.startOffset,c=Array.from(n.children).filter(h=>h.tagName==="P");if(o<=0||o-1>=c.length)return console.warn("上一个 <p> 不存在"),B;const a=c[o-1];if(!a)return console.warn("未找到上一个 <p>"),B;const r=document.createRange();return r.selectNodeContents(a),r.collapse(!1),r}}class Fe extends _C{constructor(B){super();AA(this,"_editorElement");AA(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 n;this.isRangeInEditor()&&(this.range=(n=window.getSelection())==null?void 0:n.getRangeAt(0).cloneRange())}isRangeInEditor(){const B=window.getSelection();if(v(B)||!B.rangeCount)return!1;const n=B.getRangeAt(0);return this._editorElement.contains(n.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 n=window.getSelection();if(v(n))return;const o=document.createRange();o.setStartAfter(B),o.setEndAfter(B),n.removeAllRanges(),n.addRange(o)}getRangeTop(){var B;return(((B=this.range)==null?void 0:B.getBoundingClientRect().top)??0)-this._editorElement.getBoundingClientRect().top+16}}class Ne extends $C{constructor(B,n,o){super();AA(this,"_editor");AA(this,"_onUndoChange");AA(this,"contentManager");AA(this,"undoStack");AA(this,"redoStack");this._editor=B,this.contentManager=n,this.undoStack=[],this.redoStack=[],this._onUndoChange=o,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 n=[];let o=B;for(;o&&o.parentElement;){const a=Array.from(o.parentElement.childNodes).indexOf(o);if(n.unshift({index:a}),CA(o)&&o.tagName==="P"&&o.classList.contains(yA))break;o=o.parentElement}return n}_record(){var D;const B=this._editor.cursor.range,n=this._editor.content.getParas(),o=vA(B.startContainer),c=n.indexOf(o),a=this._calcNodePathMatches(B.startContainer),r=vA(B.endContainer),h=n.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 n;if(B.ctrlKey&&B.key==="z"&&(B.preventDefault(),this.undoStack.length>0)){this.redoStack.push(this._record());const o=this.undoStack.pop();this._editor.content.calcTextCount()&&requestAnimationFrame(()=>this._restoreCursor(o)),this._editor.element.innerHTML=o.content,(n=this._onUndoChange)==null||n.call(this,o.anchorContent)}}_restoreCursor(B){const n=window.getSelection();if(v(n))return;const o=h=>{let d=this._editor.content.getParas(),{index:D}=h[0],f=null,u=0;for(;u<h.length;){if(f=d[D],FA(f))return f;if(d=Array.from(f.childNodes),u++,u>=h.length)break;D=h[u].index}return f},c=o(B.startMatchedIndexes),a=o(B.endMatchedIndexes),r=document.createRange();r.setStart(c,B.startOffset),r.setEnd(a,B.endOffset),n.removeAllRanges(),n.addRange(r)}}const SA=[];for(let I=0;I<256;++I)SA.push((I+256).toString(16).slice(1));function ke(I,t=0){return(SA[I[t+0]]+SA[I[t+1]]+SA[I[t+2]]+SA[I[t+3]]+"-"+SA[I[t+4]]+SA[I[t+5]]+"-"+SA[I[t+6]]+SA[I[t+7]]+"-"+SA[I[t+8]]+SA[I[t+9]]+"-"+SA[I[t+10]]+SA[I[t+11]]+SA[I[t+12]]+SA[I[t+13]]+SA[I[t+14]]+SA[I[t+15]]).toLowerCase()}let MI;const Ge=new Uint8Array(16);function Se(){if(!MI){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");MI=crypto.getRandomValues.bind(crypto)}return MI(Ge)}const Le=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),vC={randomUUID:Le};function gB(I,t,B){var o;if(vC.randomUUID&&!I)return vC.randomUUID();I=I||{};const n=I.random??((o=I.rng)==null?void 0:o.call(I))??Se();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,ke(n)}const QI=(I,t)=>{var c;const B=window.getSelection(),n=document.createRange(),o=t.lastChild;v(o)||v(B)||(n.setStartAfter(o),n.setEndAfter(o),B.removeAllRanges(),B.addRange(n),(c=I.plugin.pausation)==null||c.add({delay:1}))},rI=(I,t)=>{const B=new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,inputType:"insertText",data:"Hello"});I.element.dispatchEvent(B);const{range:n}=I.cursor,o=t[0],c=t[t.length-1],a=t.slice(1,-1);let r=n;if(!o||!r)return;let h=null,d=0,D=null;if(I.cursor.isRange()&&(h=r.startContainer,d=r.startOffset,D=r.endContainer,r.deleteContents()),t.length===1){I.content.insert(o);return}if(CA(r.commonAncestorContainer)&&r.commonAncestorContainer.tagName==="DIV"){const H=vA(h),z=vA(D),_=document.createDocumentFragment();for(;z!=null&&z.firstChild;)_.appendChild(z.firstChild);H==null||H.appendChild(_),z==null||z.remove();const m=window.getSelection(),O=document.createRange();O.setStart(h,d),O.setEnd(h,d),m==null||m.removeAllRanges(),m==null||m.addRange(O)}r=I.cursor.isRangeInEditor()?window.getSelection().getRangeAt(0):n,r=FA(r.commonAncestorContainer)&&r.commonAncestorContainer.textContent==="粘贴文本"?n:r;const[u]=JA(r.commonAncestorContainer,H=>H.tagName==="P"&&H.classList.contains(yA)),[N]=JA(r.startContainer,H=>H.tagName==="SPAN"&&H.dataset.type===b.anchor),R=document.createRange(),k=!!N;R.setStart(r.startContainer,r.startOffset),R.setEndAfter(u.lastChild);const M=R.extractContents();if(!(u!=null&&u.textContent))u.innerHTML=o;else if(FA(u.lastChild))u.lastChild.textContent+=o;else if(CA(u.lastChild)&&u.lastChild.dataset.type===b.anchor){const{lastChild:H}=u.lastChild;FA(H)?H.textContent+=o:H==null||H.appendChild(document.createTextNode(o))}else u.appendChild(document.createTextNode(o));QI(I,k?u.lastChild:u);let{nextSibling:S}=u;if(a.forEach(H=>{var _;const z=document.createElement("p");if(z.classList.add(yA),z.textContent=H,(_=u==null?void 0:u.parentNode)==null||_.insertBefore(z,S),S=z.nextSibling,QI(I,z),k){const m=N.cloneNode(!1);m.innerHTML=z.innerHTML,z.innerHTML=m.outerHTML}}),!c)return;const F=document.createElement("p");if(F.classList.add(yA),F.appendChild(M),!F.textContent)F.innerHTML=c;else if(FA(F.firstChild))F.firstChild.textContent=c+F.firstChild.textContent;else if(CA(F.firstChild)&&F.firstChild.dataset.type===b.anchor){const{firstChild:H}=F.firstChild;FA(H)?H.textContent=c+H.textContent:H==null||H.insertBefore(document.createTextNode(c),H.firstChild)}else F.insertBefore(document.createTextNode(c),F.firstChild);I.element.insertBefore(F,S),[.5,1,1.5,2,2.5].every(H=>{var z;return!((z=F.textContent)!=null&&z.trim().endsWith(`停顿: ${H}S`))})&&QI(I,F)},[Ue]=bA("paragraph"),yA=Ue(),Me=`<p class="${yA}"><br /></p>`;class pe extends XC{constructor(B,n){super();AA(this,"_observer",null);AA(this,"_onchange");AA(this,"_editorElement");AA(this,"_uid");AA(this,"content");AA(this,"cursor");AA(this,"undo");AA(this,"command");AA(this,"maxLength");AA(this,"plugin");this._uid=gB(),this._editorElement=B,this.content=new Re(B,this),this.cursor=new Fe(B),this.undo=new Ne(this,this.content,n==null?void 0:n.onUndoChange),this.command=new ue(this.content,this.cursor),this.maxLength=(n==null?void 0:n.maxLength)??1e4,this.plugin=((n==null?void 0:n.plugins)??[]).reduce((o,c)=>{const a=new c(this),r=a.prefix;return o[r]=a,o},{}),this._onchange=n==null?void 0:n.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,n=>QI(this,n))}get element(){return this._editorElement}_setup(){this._observer=new MutationObserver(([B])=>{var n;if(B.removedNodes.length){const o=B.removedNodes[0];if(CA(o)&&o.dataset.type===b.highlight){const c=window.getSelection(),{range:a}=this.cursor;if(v(a)||v(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(o=>{CA(o)&&o.tagName==="P"&&!o.classList.contains(yA)&&o.classList.add(yA)}),B.removedNodes.length&&!this.content.getParas().length&&this.content.insertEmptyPara(),(n=this._onchange)==null||n.call(this,this.content.calcTextCount()),Array.from(document.querySelectorAll("p")).forEach(o=>{Array.from(o.style).includes("text-indent")&&o.removeAttribute("style"),Array.from(o.childNodes).forEach(a=>{var r;if(CA(a)&&a.tagName==="FONT"&&CA(a.firstChild)&&((r=a.firstChild)==null?void 0:r.tagName)==="SPAN"){const h=a.firstChild;a.replaceWith(h.textContent??""),o.normalize()}})}),Array.from(document.querySelectorAll("p span")).forEach(o=>{var f;const c=o.parentNode,a=o.firstChild,r=o&&o.style.textIndent==="20px"&&o.style.fontSize&&o.style.color,h=o&&o.style.backgroundColor&&((f=o.parentElement)==null?void 0:f.style.textIndent)==="0px",d=o&&Array.from(o.childNodes).every(u=>FA(u)&&!u.textContent||CA(u)&&u.tagName==="BR"),D=o&&CA(o.firstChild)&&o.firstChild.tagName==="BR";if(r||h){for(;o.firstChild;)c==null||c.insertBefore(o.firstChild,o);c==null||c.removeChild(o),Bg(a)}if(d&&(c==null||c.removeChild(o)),h){c.removeAttribute("style");const u=window.getSelection(),R=(u==null?void 0:u.getRangeAt(0)).cloneRange();R.setStartAfter(R.startContainer),R.setEndAfter(R.endContainer),u==null||u.removeAllRanges(),u==null||u.addRange(R)}D&&o.removeChild(o.firstChild)}),this.content.getParas().forEach(o=>{const c=o.firstChild,a=o.lastChild;o.childNodes.length>1&&(CA(a)&&a.tagName==="BR"&&a.remove(),CA(c)&&c.tagName==="BR"&&c.remove()),(o.childNodes.length===0||o.childNodes.length===1&&FA(o.childNodes[0])&&o.childNodes[0].textContent==="")&&o.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(n=>n.destroy())}_handleBackspace(B){var c;const n=window.getSelection(),o=n.getRangeAt(0);if(B.key==="Backspace"&&o.startOffset===0&&o.collapsed){const[a]=JA(o.startContainer,h=>h.tagName==="P"&&h.classList.contains(yA)),r=a==null?void 0:a.previousElementSibling;if(r){B.preventDefault();const h=r.childNodes,d=r.childNodes[0];if(h.length===1&&(FA(d)&&d.textContent===""||CA(d)&&d.tagName==="BR")){r.remove();const D=document.createRange();D.setStartBefore(a.firstChild),D.setEndBefore(a.firstChild),n.removeAllRanges(),n.addRange(D)}else{const D=document.createRange();D.selectNodeContents(r),D.collapse(!1),n.removeAllRanges(),n.addRange(D);const f=document.createDocumentFragment(),u=a.firstChild;for(;a.firstChild;)f.appendChild(a.firstChild);D.insertNode(f),a.remove();const N=document.createRange();N.setStartBefore(u),N.setEndBefore(u),n.removeAllRanges(),n.addRange(N)}}}if(B.key==="Delete"&&Je()){const a=getSelection(),r=(c=getSelection())==null?void 0:c.getRangeAt(0);if(v(a)||v(r))return;const h=vA(r.endContainer),d=h==null?void 0:h.nextElementSibling;if(v(h)||v(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(se(a))return;const[r]=JA(a==null?void 0:a.commonAncestorContainer,h=>h.tagName==="SPAN"&&h.dataset.type===b.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(o.startOffset===0&&o.endContainer.tagName==="P"&&vA(o.startContainer)===vA(o.endContainer)){const a=vA(o.endContainer);if(v(a))return;B.key==="Backspace"&&Ye(a,n)}}_handlePaste(B){var o,c;B.preventDefault(),me(this._editorElement);const n=((c=(o=B.clipboardData)==null?void 0:o.getData("text/plain"))==null?void 0:c.split(/(?:\r?\n){2,}/).map(a=>a.trim()).filter(a=>a))??[];rI(this,iI(this,n))}_handleBeforeInput(B){fe(this,B)}_handleCompositionEnd(B){ye(this,B)}}const fg=(I,t,B,n)=>{if(Object.keys(t).forEach(o=>{I.setAttribute(o,String(t[o]))}),Object.keys(B).forEach(o=>{I.dataset[o]=String(B[o])}),!v(n))if(WC(n)){const o=document.createDocumentFragment(),c=document.createElement("div");for(c.innerHTML=n;c.firstChild;)o.appendChild(c.firstChild);I.appendChild(o)}else I.appendChild(n)},JA=(I,t)=>{const B=OC(t)?t:[t];let n=I;for(;n;){const o=n,c=B.map(a=>a(o)).map(a=>a?o:null);if(c.some(a=>a))return c;n=n.parentElement}return new Array(B.length).fill(null)},vA=I=>{const[t]=JA(I,B=>B.tagName==="P"&&B.classList.contains(yA));return t},zI=(I,t)=>{if(I===t)return[];const B=[];let n=I.nextElementSibling;for(;n&&n!==t;)B.push(n),n=n.nextElementSibling;return B},IC=I=>{const t=document.createElement("div");return t.setAttribute("class",`editor-${I}-tag-modal`),t},Bg=(I,t,B)=>{var a,r,h;const n=I.previousSibling,o=I.nextSibling,c=t??I.textContent??"";if(B&&(!n&&!o||CA(n)&&n.dataset.type===b.pausation||CA(n)&&[b.anchor,b.homophones,b.pausation,b.pronunciation].includes(n.dataset.type))){CA(I)&&I.dataset.type!==b.pausation?I.replaceWith(I.dataset.raw??""):(a=I.parentNode)==null||a.removeChild(I);return}if(FA(n)){n.textContent+=c,(r=I.parentNode)==null||r.removeChild(I),Bg(n,n.textContent,!1);return}FA(o)&&(o.textContent=c+o.textContent,(h=I.parentNode)==null||h.removeChild(I),Bg(o,o.textContent,!1))},pI=(I,t)=>{const B=I.length,n=t.length,o=new Array(n).fill(0);let c=o[0],a=0,r=0;for(let h=1;h<=B;h++){for(let d=1;d<=n;d++){const D=o[d];I[h-1]===t[d-1]?(o[d]=c+1,o[d]>a&&(a=Math.max(a,o[d]),r=d-1)):o[d]=0,c=D}c=o[0]}return t.substring(r-a+1,r+1)},Je=()=>{const I=window.getSelection();if(!I||!I.rangeCount||I.type!=="Caret")return!1;const t=I.getRangeAt(0);let B=t.endContainer;for(;B&&B.nodeName!=="P";)B=B.parentNode;if(!B)return!1;const n=t.cloneRange();return n.setEndAfter(B),n.toString().length===0},me=I=>{const t=window.getSelection();if(!t.rangeCount)return;const B=Array.from(I.querySelectorAll("p"));if(B.length===0)return;let n=!1;for(const o of B)if(o.contains(t.anchorNode)){n=!0;break}if(!n){const o=document.createRange(),c=B[B.length-1];o.selectNodeContents(c),o.collapse(!1),t.removeAllRanges(),t.addRange(o)}},Ye=(I,t)=>{if(!I)return;for(;I.firstChild;)I.removeChild(I.firstChild);I.appendChild(document.createElement("br"));const B=document.createRange();B.selectNodeContents(I),B.collapse(!1),t.removeAllRanges(),t.addRange(B)},IB=(I,t,B=0)=>{if(!I||!t)return{top:0,left:0,width:0,height:0};const n=I,o=t,c=o.bottom-n.top+B,a=o.left-n.left;return{top:c,left:a,width:o.width,height:o.height}},He=I=>{const t=Array.from(document.querySelectorAll(`span[data-frag-id="anchor_${I.id}"]`));return I.uid?t.filter(B=>B.dataset.uid===I.uid):t.filter(B=>!B.dataset.uid)};function CB(I){return e.getCurrentScope()?(e.onScopeDispose(I),!0):!1}const CC=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Ke=Object.prototype.toString,ve=I=>Ke.call(I)==="[object Object]",XI=()=>{};function qe(I){let t;function B(){return t||(t=I()),t}return B.reset=async()=>{const n=t;t=void 0,n&&await n},B}function qC(I){return Array.isArray(I)?I:[I]}function xe(I,t,B={}){const{immediate:n=!0}=B,o=e.ref(!1);let c=null;function a(){c&&(clearTimeout(c),c=null)}function r(){o.value=!1,a()}function h(...d){a(),o.value=!0,c=setTimeout(()=>{o.value=!1,c=null,I(...d)},e.toValue(t))}return n&&(o.value=!0,CC&&h()),CB(r),{isPending:e.readonly(o),start:h,stop:r}}function eI(I=!1,t={}){const{truthyValue:B=!0,falsyValue:n=!1}=t,o=e.isRef(I),c=e.ref(I);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(n):h,c.value}}return o?a:[c,a]}const BB=CC?window:void 0,QB=CC?window.navigator:void 0;function be(I){var t;const B=e.toValue(I);return(t=B==null?void 0:B.$el)!=null?t:B}function hg(...I){let t,B,n,o;if(typeof I[0]=="string"||Array.isArray(I[0])?([B,n,o]=I,t=BB):[t,B,n,o]=I,!t)return XI;B=qC(B),n=qC(n);const c=[],a=()=>{c.forEach(D=>D()),c.length=0},r=(D,f,u,N)=>(D.addEventListener(f,u,N),()=>D.removeEventListener(f,u,N)),h=e.watch(()=>[be(t),e.toValue(o)],([D,f])=>{if(a(),!D)return;const u=ve(f)?{...f}:f;c.push(...B.flatMap(N=>n.map(R=>r(D,N,R,u))))},{immediate:!0,flush:"post"}),d=()=>{h(),a()};return CB(d),d}function Te(){const I=e.ref(!1),t=e.getCurrentInstance();return t&&e.onMounted(()=>{I.value=!0},t),I}function eB(I){const t=Te();return e.computed(()=>(t.value,!!I()))}function xC(I,t={}){const{controls:B=!1,navigator:n=QB}=t,o=eB(()=>n&&"permissions"in n),c=e.shallowRef(),a=typeof I=="string"?{name:I}:I,r=e.shallowRef(),h=()=>{var D,f;r.value=(f=(D=c.value)==null?void 0:D.state)!=null?f:"prompt"};hg(c,"change",h,{passive:!0});const d=qe(async()=>{if(o.value){if(!c.value)try{c.value=await n.permissions.query(a)}catch{c.value=void 0}finally{h()}if(B)return e.toRaw(c.value)}});return d(),B?{state:r,isSupported:o,query:d}:r}function Ve(I={}){const{navigator:t=QB,read:B=!1,source:n,copiedDuring:o=1500,legacy:c=!1}=I,a=eB(()=>t&&"clipboard"in t),r=xC("clipboard-read"),h=xC("clipboard-write"),d=e.computed(()=>a.value||c),D=e.ref(""),f=e.ref(!1),u=xe(()=>f.value=!1,o,{immediate:!1});function N(){a.value&&S(r.value)?t.clipboard.readText().then(F=>{D.value=F}):D.value=M()}d.value&&B&&hg(["copy","cut"],N,{passive:!0});async function R(F=e.toValue(n)){d.value&&F!=null&&(a.value&&S(h.value)?await t.clipboard.writeText(F):k(F),D.value=F,f.value=!0,u.start())}function k(F){const j=document.createElement("textarea");j.value=F??"",j.style.position="absolute",j.style.opacity="0",document.body.appendChild(j),j.select(),document.execCommand("copy"),j.remove()}function M(){var F,j,H;return(H=(j=(F=document==null?void 0:document.getSelection)==null?void 0:F.call(document))==null?void 0:j.toString())!=null?H:""}function S(F){return F==="granted"||F==="prompt"}return{isSupported:d,text:D,copied:f,copy:R}}const Pe={page:I=>[I.pageX,I.pageY],client:I=>[I.clientX,I.clientY],screen:I=>[I.screenX,I.screenY],movement:I=>I instanceof Touch?null:[I.movementX,I.movementY]};function aI(I={}){const{type:t="page",touch:B=!0,resetOnTouchEnds:n=!1,initialValue:o={x:0,y:0},window:c=BB,target:a=c,scroll:r=!0,eventFilter:h}=I;let d=null,D=0,f=0;const u=e.ref(o.x),N=e.ref(o.y),R=e.ref(null),k=typeof t=="function"?t:Pe[t],M=m=>{const O=k(m);d=m,O&&([u.value,N.value]=O,R.value="mouse"),c&&(D=c.scrollX,f=c.scrollY)},S=m=>{if(m.touches.length>0){const O=k(m.touches[0]);O&&([u.value,N.value]=O,R.value="touch")}},F=()=>{if(!d||!c)return;const m=k(d);d instanceof MouseEvent&&m&&(u.value=m[0]+c.scrollX-D,N.value=m[1]+c.scrollY-f)},j=()=>{u.value=o.x,N.value=o.y},H=h?m=>h(()=>M(m),{}):m=>M(m),z=h?m=>h(()=>S(m),{}):m=>S(m),_=h?()=>h(()=>F(),{}):()=>F();if(a){const m={passive:!0};hg(a,["mousemove","dragover"],H,m),B&&t!=="movement"&&(hg(a,["touchstart","touchmove"],z,m),n&&hg(a,"touchend",j,m)),r&&t==="page"&&hg(c,"scroll",_,m)}return{x:u,y:N,sourceType:R}}const je=["onClick"],We=e.defineComponent({__name:"pausationor",props:{visible:{type:Boolean}},emits:["ok"],setup(I,{emit:t}){const B=I,n=t,[o]=bA("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(o)()),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(o)("item")),onClick:D=>n("ok",D,h.value)},e.toDisplayString(h.label),11,je)),64))],2)),[[e.vShow,B.visible]])}}),NA=(I,t)=>{const B=I.__vccOpts||I;for(const[n,o]of t)B[n]=o;return B},EB=NA(We,[["__scopeId","data-v-a957cba2"]]),Oe=0,Dg=b.pausation,[ZI]=Yg(Dg),tB=ZI("close"),{x:ze,y:Xe}=aI(),Ze=`<svg class="${tB}" 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 re=Object.defineProperty;var ae=(I,t,B)=>t in I?re(I,t,{enumerable:!0,configurable:!0,writable:!0,value:B}):I[t]=B;var AA=(I,t,B)=>ae(I,typeof t!="symbol"?t+"":t,B);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),RA=require("@arco-design/web-vue");var AC=I=>Object.prototype.toString.call(I),se=I=>AC(I)==="[object Null]",ce=I=>AC(I)==="[object Number]",le=I=>AC(I)==="[object String]",OI=(I,t)=>t?typeof t=="string"?` ${I}--${t}`:Array.isArray(t)?t.reduce((B,n)=>B+OI(I,n),""):Object.keys(t).reduce((B,n)=>B+(t[n]?OI(I,n):""),""):"",de=I=>(t,B)=>(t&&typeof t!="string"&&(B=t,t=""),t=t?`${I}__${t}`:I,`${t}${OI(t,B)}`),jC=I=>t=>{const B=`${I}-${t}`;return[de(B),B]};const Yg=jC("tag"),bA=jC("c"),EI=I=>{let t=!1;return function(...n){t||(requestAnimationFrame(()=>{I.apply(this,n),t=!1}),t=!0)}},we=()=>typeof window>"u"?!1:window.location.protocol==="https:",nI=I=>Object.prototype.toString.call(I).slice(8,-1).toLocaleLowerCase(),WC=I=>nI(I)==="string",OC=I=>nI(I)==="array",he=I=>nI(I)==="null",De=I=>nI(I)==="undefined",v=I=>he(I)||De(I),CA=I=>I instanceof HTMLElement,FA=I=>(I==null?void 0:I.nodeType)===Node.TEXT_NODE;var zC=(I=>(I.None="None",I.Caret="Caret",I.Range="Range",I))(zC||{}),b=(I=>(I.pausation="pausation",I.pronunciation="pronunciation",I.anchor="anchor",I.homophones="homophones",I.highlight="highlight",I))(b||{}),gC=(I=>(I.single="single",I.multiple="multiple",I))(gC||{});class XC{}class ZC{}class _C{}class $C{}class AB{}class Hg{}class ue extends AB{constructor(B,n){super();AA(this,"contentManager");AA(this,"cursorManager");this.contentManager=B,this.cursorManager=n}executeUndo(){}executeRedo(){}}const ye=(I,t)=>{var f;t.preventDefault();const B=((f=t.data)==null?void 0:f.length)??0,n=I.content.calcTextCount()-B,o=I.maxLength-n;if(o>=B||!B)return;const c=o<=0?B:B-o,a=window.getSelection(),r=a==null?void 0:a.getRangeAt(0);if(v(a)||v(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)},fe=(I,t)=>{const{inputType:B}=t;I.content.calcTextCount()>=I.maxLength&&B.includes("insert")&&B!=="insertParagraph"&&t.preventDefault()},iI=(I,t)=>{const B=[],n=I.content.calcTextCount();let o=I.maxLength-n;if(o<=0||!t.length)return[];let c=t.shift();for(;o>0&&c;){if(c.length>=o)return B.push(c.slice(0,o)),B;B.push(c),o-=c.length,c=t.shift()}return B};class Re extends ZC{constructor(B,n){super();AA(this,"_editorElement");AA(this,"_editor");this._editorElement=B,this._editor=n}insertEmptyPara(){this._editorElement.innerHTML=Me}calcTextCount(){return this.getTextContent().reduce((B,n)=>B+n.length,0)}getContent(){return this._editorElement.innerHTML}getHtml(){return this.getContent()}setContent(B){this._editorElement.innerHTML=B}setHtml(B){this.setContent(B)}appendContent(B,n){var r;const o=iI(this._editor,OC(B)?B:[B]),c=this.getParas()[0],a=(r=c.textContent)!=null&&r.length?void 0:o.shift();a&&(c.innerHTML=a,n==null||n(c)),o.forEach(h=>{const d=document.createElement("p");d.innerHTML=h,d.classList.add(yA),this._editorElement.appendChild(d),n==null||n(d)})}insert(B){this._insert(B)}delete(){this._delete()}update(B){this._update(B)}getParas(){return Array.from(this._editorElement.querySelectorAll(`.${yA}`))}getTextContent(){const B=this.getParas(),n=o=>{const c=Array.from(o.childNodes);let a="";for(let r=0;r<c.length;r++){const h=c[r];FA(h)?a+=h.textContent??"":CA(h)&&(a+=b.anchor===h.dataset.type?n(h):b.pronunciation===h.dataset.type?h.dataset.value:h.dataset.raw??"")}return a};return B.map(n)}_insert(B){const n=window.getSelection(),o=this._editor.cursor.isRangeInEditor()?n==null?void 0:n.getRangeAt(0):this._editor.cursor.range;if(v(n)||!n.rangeCount||v(o))return;const c=document.createDocumentFragment();if(WC(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(o)??o).insertNode(c);const h=document.createRange();h.setStartAfter(a),h.setEndAfter(a),n.removeAllRanges(),n.addRange(h)}_delete(){const{range:B}=this._editor.cursor;B==null||B.deleteContents()}_update(B){this._delete(),this._insert(B)}_calcRange(B){const n=B.commonAncestorContainer;if(n.tagName!=="DIV")return B;const o=B.startOffset,c=Array.from(n.children).filter(h=>h.tagName==="P");if(o<=0||o-1>=c.length)return console.warn("上一个 <p> 不存在"),B;const a=c[o-1];if(!a)return console.warn("未找到上一个 <p>"),B;const r=document.createRange();return r.selectNodeContents(a),r.collapse(!1),r}}class Fe extends _C{constructor(B){super();AA(this,"_editorElement");AA(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 n;this.isRangeInEditor()&&(this.range=(n=window.getSelection())==null?void 0:n.getRangeAt(0).cloneRange())}isRangeInEditor(){const B=window.getSelection();if(v(B)||!B.rangeCount)return!1;const n=B.getRangeAt(0);return this._editorElement.contains(n.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 n=window.getSelection();if(v(n))return;const o=document.createRange();o.setStartAfter(B),o.setEndAfter(B),n.removeAllRanges(),n.addRange(o)}getRangeTop(){var B;return(((B=this.range)==null?void 0:B.getBoundingClientRect().top)??0)-this._editorElement.getBoundingClientRect().top+16}}class Ne extends $C{constructor(B,n,o){super();AA(this,"_editor");AA(this,"_onUndoChange");AA(this,"contentManager");AA(this,"undoStack");AA(this,"redoStack");this._editor=B,this.contentManager=n,this.undoStack=[],this.redoStack=[],this._onUndoChange=o,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 n=[];let o=B;for(;o&&o.parentElement;){const a=Array.from(o.parentElement.childNodes).indexOf(o);if(n.unshift({index:a}),CA(o)&&o.tagName==="P"&&o.classList.contains(yA))break;o=o.parentElement}return n}_record(){var D;const B=this._editor.cursor.range,n=this._editor.content.getParas(),o=vA(B.startContainer),c=n.indexOf(o),a=this._calcNodePathMatches(B.startContainer),r=vA(B.endContainer),h=n.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 n;if(B.ctrlKey&&B.key==="z"&&(B.preventDefault(),this.undoStack.length>0)){this.redoStack.push(this._record());const o=this.undoStack.pop();this._editor.content.calcTextCount()&&requestAnimationFrame(()=>this._restoreCursor(o)),this._editor.element.innerHTML=o.content,(n=this._onUndoChange)==null||n.call(this,o.anchorContent)}}_restoreCursor(B){const n=window.getSelection();if(v(n))return;const o=h=>{let d=this._editor.content.getParas(),{index:D}=h[0],f=null,u=0;for(;u<h.length;){if(f=d[D],FA(f))return f;if(d=Array.from(f.childNodes),u++,u>=h.length)break;D=h[u].index}return f},c=o(B.startMatchedIndexes),a=o(B.endMatchedIndexes),r=document.createRange();r.setStart(c,B.startOffset),r.setEnd(a,B.endOffset),n.removeAllRanges(),n.addRange(r)}}const SA=[];for(let I=0;I<256;++I)SA.push((I+256).toString(16).slice(1));function ke(I,t=0){return(SA[I[t+0]]+SA[I[t+1]]+SA[I[t+2]]+SA[I[t+3]]+"-"+SA[I[t+4]]+SA[I[t+5]]+"-"+SA[I[t+6]]+SA[I[t+7]]+"-"+SA[I[t+8]]+SA[I[t+9]]+"-"+SA[I[t+10]]+SA[I[t+11]]+SA[I[t+12]]+SA[I[t+13]]+SA[I[t+14]]+SA[I[t+15]]).toLowerCase()}let MI;const Ge=new Uint8Array(16);function Se(){if(!MI){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");MI=crypto.getRandomValues.bind(crypto)}return MI(Ge)}const Le=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),vC={randomUUID:Le};function gB(I,t,B){var o;if(vC.randomUUID&&!I)return vC.randomUUID();I=I||{};const n=I.random??((o=I.rng)==null?void 0:o.call(I))??Se();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,ke(n)}const QI=(I,t)=>{var c;const B=window.getSelection(),n=document.createRange(),o=t.lastChild;v(o)||v(B)||(n.setStartAfter(o),n.setEndAfter(o),B.removeAllRanges(),B.addRange(n),(c=I.plugin.pausation)==null||c.add({delay:1}))},rI=(I,t)=>{const B=new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,inputType:"insertText",data:"Hello"});I.element.dispatchEvent(B);const{range:n}=I.cursor,o=t[0],c=t[t.length-1],a=t.slice(1,-1);let r=n;if(!o||!r)return;let h=null,d=0,D=null;if(I.cursor.isRange()&&(h=r.startContainer,d=r.startOffset,D=r.endContainer,r.deleteContents()),t.length===1){I.content.insert(o);return}if(CA(r.commonAncestorContainer)&&r.commonAncestorContainer.tagName==="DIV"){const H=vA(h),z=vA(D),_=document.createDocumentFragment();for(;z!=null&&z.firstChild;)_.appendChild(z.firstChild);H==null||H.appendChild(_),z==null||z.remove();const m=window.getSelection(),O=document.createRange();O.setStart(h,d),O.setEnd(h,d),m==null||m.removeAllRanges(),m==null||m.addRange(O)}r=I.cursor.isRangeInEditor()?window.getSelection().getRangeAt(0):n,r=FA(r.commonAncestorContainer)&&r.commonAncestorContainer.textContent==="粘贴文本"?n:r;const[u]=JA(r.commonAncestorContainer,H=>H.tagName==="P"&&H.classList.contains(yA)),[N]=JA(r.startContainer,H=>H.tagName==="SPAN"&&H.dataset.type===b.anchor),R=document.createRange(),k=!!N;R.setStart(r.startContainer,r.startOffset),R.setEndAfter(u.lastChild);const M=R.extractContents();if(!(u!=null&&u.textContent))u.innerHTML=o;else if(FA(u.lastChild))u.lastChild.textContent+=o;else if(CA(u.lastChild)&&u.lastChild.dataset.type===b.anchor){const{lastChild:H}=u.lastChild;FA(H)?H.textContent+=o:H==null||H.appendChild(document.createTextNode(o))}else u.appendChild(document.createTextNode(o));QI(I,k?u.lastChild:u);let{nextSibling:S}=u;if(a.forEach(H=>{var _;const z=document.createElement("p");if(z.classList.add(yA),z.textContent=H,(_=u==null?void 0:u.parentNode)==null||_.insertBefore(z,S),S=z.nextSibling,QI(I,z),k){const m=N.cloneNode(!1);m.innerHTML=z.innerHTML,z.innerHTML=m.outerHTML}}),!c)return;const F=document.createElement("p");if(F.classList.add(yA),F.appendChild(M),!F.textContent)F.innerHTML=c;else if(FA(F.firstChild))F.firstChild.textContent=c+F.firstChild.textContent;else if(CA(F.firstChild)&&F.firstChild.dataset.type===b.anchor){const{firstChild:H}=F.firstChild;FA(H)?H.textContent=c+H.textContent:H==null||H.insertBefore(document.createTextNode(c),H.firstChild)}else F.insertBefore(document.createTextNode(c),F.firstChild);I.element.insertBefore(F,S),[.5,1,1.5,2,2.5].every(H=>{var z;return!((z=F.textContent)!=null&&z.trim().endsWith(`停顿: ${H}S`))})&&QI(I,F)},[Ue]=bA("paragraph"),yA=Ue(),Me=`<p class="${yA}"><br /></p>`;class pe extends XC{constructor(B,n){super();AA(this,"_observer",null);AA(this,"_onchange");AA(this,"_editorElement");AA(this,"_uid");AA(this,"content");AA(this,"cursor");AA(this,"undo");AA(this,"command");AA(this,"maxLength");AA(this,"plugin");this._uid=gB(),this._editorElement=B,this.content=new Re(B,this),this.cursor=new Fe(B),this.undo=new Ne(this,this.content,n==null?void 0:n.onUndoChange),this.command=new ue(this.content,this.cursor),this.maxLength=(n==null?void 0:n.maxLength)??1e4,this.plugin=((n==null?void 0:n.plugins)??[]).reduce((o,c)=>{const a=new c(this),r=a.prefix;return o[r]=a,o},{}),this._onchange=n==null?void 0:n.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,n=>QI(this,n))}get element(){return this._editorElement}_setup(){this._observer=new MutationObserver(([B])=>{var n;if(B.removedNodes.length){const o=B.removedNodes[0];if(CA(o)&&o.dataset.type===b.highlight){const c=window.getSelection(),{range:a}=this.cursor;if(v(a)||v(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(o=>{CA(o)&&o.tagName==="P"&&!o.classList.contains(yA)&&o.classList.add(yA)}),B.removedNodes.length&&!this.content.getParas().length&&this.content.insertEmptyPara(),(n=this._onchange)==null||n.call(this,this.content.calcTextCount()),Array.from(document.querySelectorAll("p")).forEach(o=>{Array.from(o.style).includes("text-indent")&&o.removeAttribute("style"),Array.from(o.childNodes).forEach(a=>{var r;if(CA(a)&&a.tagName==="FONT"&&CA(a.firstChild)&&((r=a.firstChild)==null?void 0:r.tagName)==="SPAN"){const h=a.firstChild;a.replaceWith(h.textContent??""),o.normalize()}})}),Array.from(document.querySelectorAll("p span")).forEach(o=>{var f;const c=o.parentNode,a=o.firstChild,r=o&&o.style.textIndent==="20px"&&o.style.fontSize&&o.style.color,h=o&&o.style.backgroundColor&&((f=o.parentElement)==null?void 0:f.style.textIndent)==="0px",d=o&&Array.from(o.childNodes).every(u=>FA(u)&&!u.textContent||CA(u)&&u.tagName==="BR"),D=o&&CA(o.firstChild)&&o.firstChild.tagName==="BR";if(r||h){for(;o.firstChild;)c==null||c.insertBefore(o.firstChild,o);c==null||c.removeChild(o),Bg(a)}if(d&&(c==null||c.removeChild(o)),h){c.removeAttribute("style");const u=window.getSelection(),R=(u==null?void 0:u.getRangeAt(0)).cloneRange();R.setStartAfter(R.startContainer),R.setEndAfter(R.endContainer),u==null||u.removeAllRanges(),u==null||u.addRange(R)}D&&o.removeChild(o.firstChild)}),this.content.getParas().forEach(o=>{const c=o.firstChild,a=o.lastChild;o.childNodes.length>1&&(CA(a)&&a.tagName==="BR"&&a.remove(),CA(c)&&c.tagName==="BR"&&c.remove()),(o.childNodes.length===0||o.childNodes.length===1&&FA(o.childNodes[0])&&o.childNodes[0].textContent==="")&&o.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(n=>n.destroy())}_handleBackspace(B){var c;const n=window.getSelection(),o=n.getRangeAt(0);if(B.key==="Backspace"&&o.startOffset===0&&o.collapsed){const[a]=JA(o.startContainer,h=>h.tagName==="P"&&h.classList.contains(yA)),r=a==null?void 0:a.previousElementSibling;if(r){B.preventDefault();const h=r.childNodes,d=r.childNodes[0];if(h.length===1&&(FA(d)&&d.textContent===""||CA(d)&&d.tagName==="BR")){r.remove();const D=document.createRange();D.setStart(a.firstChild,0),D.collapse(!0),n.removeAllRanges(),n.addRange(D)}else{const D=document.createRange();D.selectNodeContents(r),D.collapse(!1),n.removeAllRanges(),n.addRange(D);const f=document.createDocumentFragment(),u=a.firstChild;for(;a.firstChild;)f.appendChild(a.firstChild);D.insertNode(f),a.remove();const N=document.createRange();N.setStartBefore(u),N.setEndBefore(u),n.removeAllRanges(),n.addRange(N)}}}if(B.key==="Delete"&&Je()){const a=getSelection(),r=(c=getSelection())==null?void 0:c.getRangeAt(0);if(v(a)||v(r))return;const h=vA(r.endContainer),d=h==null?void 0:h.nextElementSibling;if(v(h)||v(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(se(a))return;const[r]=JA(a==null?void 0:a.commonAncestorContainer,h=>h.tagName==="SPAN"&&h.dataset.type===b.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(o.startOffset===0&&o.endContainer.tagName==="P"&&vA(o.startContainer)===vA(o.endContainer)){const a=vA(o.endContainer);if(v(a))return;B.key==="Backspace"&&Ye(a,n)}}_handlePaste(B){var o,c;B.preventDefault(),me(this._editorElement);const n=((c=(o=B.clipboardData)==null?void 0:o.getData("text/plain"))==null?void 0:c.split(/(?:\r?\n){2,}/).map(a=>a.trim()).filter(a=>a))??[];rI(this,iI(this,n))}_handleBeforeInput(B){fe(this,B)}_handleCompositionEnd(B){ye(this,B)}}const fg=(I,t,B,n)=>{if(Object.keys(t).forEach(o=>{I.setAttribute(o,String(t[o]))}),Object.keys(B).forEach(o=>{I.dataset[o]=String(B[o])}),!v(n))if(WC(n)){const o=document.createDocumentFragment(),c=document.createElement("div");for(c.innerHTML=n;c.firstChild;)o.appendChild(c.firstChild);I.appendChild(o)}else I.appendChild(n)},JA=(I,t)=>{const B=OC(t)?t:[t];let n=I;for(;n;){const o=n,c=B.map(a=>a(o)).map(a=>a?o:null);if(c.some(a=>a))return c;n=n.parentElement}return new Array(B.length).fill(null)},vA=I=>{const[t]=JA(I,B=>B.tagName==="P"&&B.classList.contains(yA));return t},zI=(I,t)=>{if(I===t)return[];const B=[];let n=I.nextElementSibling;for(;n&&n!==t;)B.push(n),n=n.nextElementSibling;return B},IC=I=>{const t=document.createElement("div");return t.setAttribute("class",`editor-${I}-tag-modal`),t},Bg=(I,t,B)=>{var a,r,h;const n=I.previousSibling,o=I.nextSibling,c=t??I.textContent??"";if(B&&(!n&&!o||CA(n)&&n.dataset.type===b.pausation||CA(n)&&[b.anchor,b.homophones,b.pausation,b.pronunciation].includes(n.dataset.type))){CA(I)&&I.dataset.type!==b.pausation?I.replaceWith(I.dataset.raw??""):(a=I.parentNode)==null||a.removeChild(I);return}if(FA(n)){n.textContent+=c,(r=I.parentNode)==null||r.removeChild(I),Bg(n,n.textContent,!1);return}FA(o)&&(o.textContent=c+o.textContent,(h=I.parentNode)==null||h.removeChild(I),Bg(o,o.textContent,!1))},pI=(I,t)=>{const B=I.length,n=t.length,o=new Array(n).fill(0);let c=o[0],a=0,r=0;for(let h=1;h<=B;h++){for(let d=1;d<=n;d++){const D=o[d];I[h-1]===t[d-1]?(o[d]=c+1,o[d]>a&&(a=Math.max(a,o[d]),r=d-1)):o[d]=0,c=D}c=o[0]}return t.substring(r-a+1,r+1)},Je=()=>{const I=window.getSelection();if(!I||!I.rangeCount||I.type!=="Caret")return!1;const t=I.getRangeAt(0);let B=t.endContainer;for(;B&&B.nodeName!=="P";)B=B.parentNode;if(!B)return!1;const n=t.cloneRange();return n.setEndAfter(B),n.toString().length===0},me=I=>{const t=window.getSelection();if(!t.rangeCount)return;const B=Array.from(I.querySelectorAll("p"));if(B.length===0)return;let n=!1;for(const o of B)if(o.contains(t.anchorNode)){n=!0;break}if(!n){const o=document.createRange(),c=B[B.length-1];o.selectNodeContents(c),o.collapse(!1),t.removeAllRanges(),t.addRange(o)}},Ye=(I,t)=>{if(!I)return;for(;I.firstChild;)I.removeChild(I.firstChild);I.appendChild(document.createElement("br"));const B=document.createRange();B.selectNodeContents(I),B.collapse(!1),t.removeAllRanges(),t.addRange(B)},IB=(I,t,B=0)=>{if(!I||!t)return{top:0,left:0,width:0,height:0};const n=I,o=t,c=o.bottom-n.top+B,a=o.left-n.left;return{top:c,left:a,width:o.width,height:o.height}},He=I=>{const t=Array.from(document.querySelectorAll(`span[data-frag-id="anchor_${I.id}"]`));return I.uid?t.filter(B=>B.dataset.uid===I.uid):t.filter(B=>!B.dataset.uid)};function CB(I){return e.getCurrentScope()?(e.onScopeDispose(I),!0):!1}const CC=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Ke=Object.prototype.toString,ve=I=>Ke.call(I)==="[object Object]",XI=()=>{};function qe(I){let t;function B(){return t||(t=I()),t}return B.reset=async()=>{const n=t;t=void 0,n&&await n},B}function qC(I){return Array.isArray(I)?I:[I]}function xe(I,t,B={}){const{immediate:n=!0}=B,o=e.ref(!1);let c=null;function a(){c&&(clearTimeout(c),c=null)}function r(){o.value=!1,a()}function h(...d){a(),o.value=!0,c=setTimeout(()=>{o.value=!1,c=null,I(...d)},e.toValue(t))}return n&&(o.value=!0,CC&&h()),CB(r),{isPending:e.readonly(o),start:h,stop:r}}function eI(I=!1,t={}){const{truthyValue:B=!0,falsyValue:n=!1}=t,o=e.isRef(I),c=e.ref(I);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(n):h,c.value}}return o?a:[c,a]}const BB=CC?window:void 0,QB=CC?window.navigator:void 0;function be(I){var t;const B=e.toValue(I);return(t=B==null?void 0:B.$el)!=null?t:B}function hg(...I){let t,B,n,o;if(typeof I[0]=="string"||Array.isArray(I[0])?([B,n,o]=I,t=BB):[t,B,n,o]=I,!t)return XI;B=qC(B),n=qC(n);const c=[],a=()=>{c.forEach(D=>D()),c.length=0},r=(D,f,u,N)=>(D.addEventListener(f,u,N),()=>D.removeEventListener(f,u,N)),h=e.watch(()=>[be(t),e.toValue(o)],([D,f])=>{if(a(),!D)return;const u=ve(f)?{...f}:f;c.push(...B.flatMap(N=>n.map(R=>r(D,N,R,u))))},{immediate:!0,flush:"post"}),d=()=>{h(),a()};return CB(d),d}function Te(){const I=e.ref(!1),t=e.getCurrentInstance();return t&&e.onMounted(()=>{I.value=!0},t),I}function eB(I){const t=Te();return e.computed(()=>(t.value,!!I()))}function xC(I,t={}){const{controls:B=!1,navigator:n=QB}=t,o=eB(()=>n&&"permissions"in n),c=e.shallowRef(),a=typeof I=="string"?{name:I}:I,r=e.shallowRef(),h=()=>{var D,f;r.value=(f=(D=c.value)==null?void 0:D.state)!=null?f:"prompt"};hg(c,"change",h,{passive:!0});const d=qe(async()=>{if(o.value){if(!c.value)try{c.value=await n.permissions.query(a)}catch{c.value=void 0}finally{h()}if(B)return e.toRaw(c.value)}});return d(),B?{state:r,isSupported:o,query:d}:r}function Ve(I={}){const{navigator:t=QB,read:B=!1,source:n,copiedDuring:o=1500,legacy:c=!1}=I,a=eB(()=>t&&"clipboard"in t),r=xC("clipboard-read"),h=xC("clipboard-write"),d=e.computed(()=>a.value||c),D=e.ref(""),f=e.ref(!1),u=xe(()=>f.value=!1,o,{immediate:!1});function N(){a.value&&S(r.value)?t.clipboard.readText().then(F=>{D.value=F}):D.value=M()}d.value&&B&&hg(["copy","cut"],N,{passive:!0});async function R(F=e.toValue(n)){d.value&&F!=null&&(a.value&&S(h.value)?await t.clipboard.writeText(F):k(F),D.value=F,f.value=!0,u.start())}function k(F){const j=document.createElement("textarea");j.value=F??"",j.style.position="absolute",j.style.opacity="0",document.body.appendChild(j),j.select(),document.execCommand("copy"),j.remove()}function M(){var F,j,H;return(H=(j=(F=document==null?void 0:document.getSelection)==null?void 0:F.call(document))==null?void 0:j.toString())!=null?H:""}function S(F){return F==="granted"||F==="prompt"}return{isSupported:d,text:D,copied:f,copy:R}}const Pe={page:I=>[I.pageX,I.pageY],client:I=>[I.clientX,I.clientY],screen:I=>[I.screenX,I.screenY],movement:I=>I instanceof Touch?null:[I.movementX,I.movementY]};function aI(I={}){const{type:t="page",touch:B=!0,resetOnTouchEnds:n=!1,initialValue:o={x:0,y:0},window:c=BB,target:a=c,scroll:r=!0,eventFilter:h}=I;let d=null,D=0,f=0;const u=e.ref(o.x),N=e.ref(o.y),R=e.ref(null),k=typeof t=="function"?t:Pe[t],M=m=>{const O=k(m);d=m,O&&([u.value,N.value]=O,R.value="mouse"),c&&(D=c.scrollX,f=c.scrollY)},S=m=>{if(m.touches.length>0){const O=k(m.touches[0]);O&&([u.value,N.value]=O,R.value="touch")}},F=()=>{if(!d||!c)return;const m=k(d);d instanceof MouseEvent&&m&&(u.value=m[0]+c.scrollX-D,N.value=m[1]+c.scrollY-f)},j=()=>{u.value=o.x,N.value=o.y},H=h?m=>h(()=>M(m),{}):m=>M(m),z=h?m=>h(()=>S(m),{}):m=>S(m),_=h?()=>h(()=>F(),{}):()=>F();if(a){const m={passive:!0};hg(a,["mousemove","dragover"],H,m),B&&t!=="movement"&&(hg(a,["touchstart","touchmove"],z,m),n&&hg(a,"touchend",j,m)),r&&t==="page"&&hg(c,"scroll",_,m)}return{x:u,y:N,sourceType:R}}const je=["onClick"],We=e.defineComponent({__name:"pausationor",props:{visible:{type:Boolean}},emits:["ok"],setup(I,{emit:t}){const B=I,n=t,[o]=bA("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(o)()),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(o)("item")),onClick:D=>n("ok",D,h.value)},e.toDisplayString(h.label),11,je)),64))],2)),[[e.vShow,B.visible]])}}),NA=(I,t)=>{const B=I.__vccOpts||I;for(const[n,o]of t)B[n]=o;return B},EB=NA(We,[["__scopeId","data-v-a957cba2"]]),Oe=0,Dg=b.pausation,[ZI]=Yg(Dg),tB=ZI("close"),{x:ze,y:Xe}=aI(),Ze=`<svg class="${tB}" 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)">
|