@linker-design-plus/tiny-peony 1.4.39 → 1.4.40

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 CHANGED
@@ -65,7 +65,7 @@ Please report this to https://github.com/markedjs/marked.`,g){let B="<p>An error
65
65
 
66
66
  $2`),Q=lA.parse(B,{async:!1}),i=document.createElement("div");i.innerHTML=Q;const r=[],o=a=>{var f,y;if(a.nodeType===Node.TEXT_NODE){const w=(f=a.textContent)==null?void 0:f.trim();w&&r.push(`<p class="${CA}">${w}</p>`);return}if(a.nodeType!==Node.ELEMENT_NODE)return;const h=a,l=h.tagName,p={H1:"2em",H2:"1.5em",H3:"1.17em",H4:"1em",H5:"0.83em",H6:"0.67em"};switch(l){case"P":r.push(`<p class="${CA}">${h.innerHTML||"<br />"}</p>`);break;case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":r.push(`<p class="${CA}" style="font-size:${p[l]};font-weight:bold;">${h.innerHTML}</p>`);break;case"UL":case"OL":{const w=Array.from(h.querySelectorAll("li")),R=l==="OL";w.forEach((k,L)=>{const F=k.querySelector("p");F==null||F.classList.add(CA);const m=R?`${L+1}. `:"";r.push(`<p class="${CA}">${m}${(F==null?void 0:F.innerHTML)||""}</p>`)});break}case"BLOCKQUOTE":{Array.from(h.childNodes).forEach(R=>{var k;if(R.nodeType===Node.ELEMENT_NODE){const L=R;r.push(`<p class="${CA}">${L.innerHTML||"<br />"}</p>`)}else R.nodeType===Node.TEXT_NODE&&((k=R.textContent)!=null&&k.trim())&&r.push(`<p class="${CA}">${R.textContent.trim()}</p>`)});break}case"PRE":{const w=h.querySelector("code");(w?w.textContent??"":h.textContent??"").split(`
67
67
  `).forEach(L=>{r.push(`<p class="${CA}">${L.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")||"<br />"}</p>`)});break}case"HR":r.push(`<p class="${CA}">———</p>`);break;case"TABLE":{const w=h.querySelector(":scope > thead"),R=h.querySelector(":scope > tbody");w&&Array.from(w.querySelectorAll(":scope > tr")).forEach(L=>{const F=Array.from(L.querySelectorAll(":scope > th, :scope > td"));F.length&&r.push(`<p class="${CA}"><strong>${F.map(m=>m.innerHTML).join(" | ")}</strong></p>`)}),R&&Array.from(R.querySelectorAll(":scope > tr")).forEach(L=>{const F=Array.from(L.querySelectorAll(":scope > td, :scope > th"));F.length&&r.push(`<p class="${CA}">${F.map(m=>m.innerHTML).join(" | ")}</p>`)}),!w&&!R&&Array.from(h.querySelectorAll(":scope > tr")).forEach(L=>{const F=Array.from(L.querySelectorAll(":scope > td, :scope > th"));F.length&&r.push(`<p class="${CA}">${F.map(m=>m.innerHTML).join(" | ")}</p>`)});break}default:r.push(`<p class="${CA}">${(y=h.innerHTML)!=null&&y.trim()?h.innerHTML:"<br />"}</p>`);break}};return Array.from(i.childNodes).forEach(a=>{o(a)}),r.length>0?r.join(""):$g}getMarkdownContent(){const I=this.getParas(),B={"2em":"#","1.5em":"##","1.17em":"###","1em":"####","0.83em":"#####","0.67em":"######"},Q=[];return I.forEach(i=>{var p,f;const r=i.getAttribute("style")||"",{innerHTML:o}=i;if(!((p=i.textContent)!=null&&p.trim())||o==="<br>"||o==="<br />"){Q.push("");return}const a=r.match(/font-size:\s*([\d.]+em)/);if(a&&r.includes("font-weight:bold")&&B[a[1]]){const y=B[a[1]];Q.push(`${y} ${this._htmlToMarkdownInline(o)}`);return}const h=((f=i.textContent)==null?void 0:f.trim())??"";if(h==="———"){Q.push("---");return}if(h.startsWith("· ")){Q.push(`- ${this._htmlToMarkdownInline(o.replace(/^·\s*/,""))}`);return}const l=h.match(/^(\d+)\.\s/);if(l){const y=`${l[1]}. `,w=o.replace(new RegExp(`^${l[1]}\\.\\s*`),"");Q.push(`${y}${this._htmlToMarkdownInline(w)}`);return}Q.push(this._htmlToMarkdownInline(o))}),Q.join(`
68
- `)}_htmlToMarkdownInline(I){const B=document.createElement("span");B.innerHTML=I;const Q=i=>{if(i.nodeType===Node.TEXT_NODE)return i.textContent??"";if(i.nodeType!==Node.ELEMENT_NODE)return"";const r=i,o=r.tagName,a=Array.from(r.childNodes).map(Q).join("");switch(o){case"STRONG":case"B":return`**${a}**`;case"EM":case"I":return`*${a}*`;case"DEL":case"S":return`~~${a}~~`;case"CODE":return`\`${a}\``;case"A":{const h=r.getAttribute("href")??"";return`[${a}](${h})`}case"IMG":{const h=r.getAttribute("src")??"";return`![${r.getAttribute("alt")??""}](${h})`}case"BR":return"";default:return a}};return Array.from(B.childNodes).map(Q).join("")}appendContent(I,B){var o;const Q=Sg(this._editor,JI(I)?I:[I]),i=this.getParas()[0],r=(o=i.textContent)!=null&&o.length?void 0:Q.shift();r&&(i.innerHTML=r,B==null||B(i)),Q.forEach(a=>{const h=document.createElement("p");h.innerHTML=a,h.classList.add(CA),this._editorElement.appendChild(h),B==null||B(h)})}insert(I){this._insert(I)}delete(){this._delete()}update(I){this._update(I)}getParas(){return Array.from(this._editorElement.querySelectorAll(`.${CA}`))}getTextContent(){const I=this.getParas(),B=Q=>{const i=Array.from(Q.childNodes);let r="";for(let o=0;o<i.length;o++){const a=i[o];JA(a)?r+=a.textContent??"":$(a)&&(r+=(l=>{let p="";const{type:f,value:y,raw:w}=l.dataset;if([K.placeholderoldSpace].includes(f))return p=fE(l,f)??"",p;if([K.anchor].includes(f)){const R=B(l);return typeof R=="string"?R:""}return f===K.pronunciation?y??"":w??l.innerText??""})(a))}return r};return I.map(B)}_insert(I){const B=window.getSelection(),Q=this._editor.cursor.isRangeInEditor()?B==null?void 0:B.getRangeAt(0):this._editor.cursor.range;if(v(B)||!B.rangeCount||v(Q))return;const i=document.createDocumentFragment();if(UI(I)){const h=document.createElement("div");for(h.innerHTML=I;h.firstChild;)i.appendChild(h.firstChild)}else i.appendChild(I);const r=i.lastChild;(this._calcRange(Q)??Q).insertNode(i);const a=document.createRange();a.setStartAfter(r),a.setEndAfter(r),B.removeAllRanges(),B.addRange(a)}_delete(){const{range:I}=this._editor.cursor;I==null||I.deleteContents()}_update(I){this._delete(),this._insert(I)}_calcRange(I){const B=I.commonAncestorContainer;if($(I.startContainer)&&I.startContainer.dataset.type===K.highlight&&I.endContainer.nodeType===Node.TEXT_NODE){const a=document.createRange();return a.setStartAfter(I.startContainer),a.collapse(!0),a}if(B.tagName!=="DIV")return I;const Q=I.startOffset,i=Array.from(B.children).filter(a=>a.tagName==="P");if(Q<=0||Q-1>=i.length)return console.warn("上一个 <p> 不存在"),I;const r=i[Q-1];if(!r)return console.warn("未找到上一个 <p>"),I;const o=document.createRange();return o.selectNodeContents(r),o.collapse(!1),o}}class oE extends vI{constructor(I){super();b(this,"_editorElement");b(this,"range");this._editorElement=I,this._recordRange=this._recordRange.bind(this),document.addEventListener("selectionchange",this._recordRange)}destroy(){document.removeEventListener("selectionchange",this._recordRange)}_recordRange(I){var B;this.isRangeInEditor()&&(this.range=(B=window.getSelection())==null?void 0:B.getRangeAt(0).cloneRange())}isRangeInEditor(){const I=window.getSelection();if(v(I)||!I.rangeCount)return!1;const B=I.getRangeAt(0);return this._editorElement.contains(B.commonAncestorContainer)}isCaret(){var I;return((I=this.range)==null?void 0:I.collapsed)===!0}isRange(){var I;return((I=this.range)==null?void 0:I.collapsed)===!1}getRangeContent(){var I;return this.isCaret()?"":((I=this.range)==null?void 0:I.toString())??""}toEnd(I){const B=window.getSelection();if(v(B))return;const Q=document.createRange();Q.setStartAfter(I),Q.setEndAfter(I),B.removeAllRanges(),B.addRange(Q)}getRangeTop(){var I;return(((I=this.range)==null?void 0:I.getBoundingClientRect().top)??0)-this._editorElement.getBoundingClientRect().top+16}}class nE extends qI{constructor(I,B,Q){super();b(this,"_editor");b(this,"_onUndoChange");b(this,"contentManager");b(this,"undoStack");b(this,"redoStack");this._editor=I,this.contentManager=B,this.undoStack=[],this.redoStack=[],this._onUndoChange=Q,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(I){const B=[];let Q=I;for(;Q&&Q.parentElement;){const r=Array.from(Q.parentElement.childNodes).indexOf(Q);if(B.unshift({index:r}),$(Q)&&Q.tagName==="P"&&Q.classList.contains(CA))break;Q=Q.parentElement}return B}_record(){var l;const I=this._editor.cursor.range,B=this._editor.content.getParas(),Q=jA(I.startContainer),i=B.indexOf(Q),r=this._calcNodePathMatches(I.startContainer),o=jA(I.endContainer),a=B.indexOf(o),h=this._calcNodePathMatches(I.endContainer);return{startParaIndex:i,startMatchedIndexes:r,startOffset:I.startOffset,endParaIndex:a,endMatchedIndexes:h,endOffset:I.endOffset,content:this._editor.element.innerHTML,anchorContent:JSON.stringify(((l=this._editor.plugin.anchor)==null?void 0:l.data)??{})}}_handleInput(){this.undoStack.push(this._record()),this.redoStack=[]}_handleUndoOrRedo(I){var B;if(I.ctrlKey&&I.key==="z"&&(I.preventDefault(),this.undoStack.length>0)){this.redoStack.push(this._record());const Q=this.undoStack.pop();this._editor.content.calcTextCount()&&requestAnimationFrame(()=>this._restoreCursor(Q)),this._editor.element.innerHTML=Q.content,(B=this._onUndoChange)==null||B.call(this,Q.anchorContent)}}_restoreCursor(I){const B=window.getSelection();if(v(B))return;const Q=a=>{let h=this._editor.content.getParas(),{index:l}=a[0],p=null,f=0;for(;f<a.length;){if(p=h[l],JA(p))return p;if(h=Array.from(p.childNodes),f++,f>=a.length)break;l=a[f].index}return p},i=Q(I.startMatchedIndexes),r=Q(I.endMatchedIndexes),o=document.createRange();o.setStart(i,I.startOffset),o.setEnd(r,I.endOffset),B.removeAllRanges(),B.addRange(o)}}const YA=[];for(let g=0;g<256;++g)YA.push((g+256).toString(16).slice(1));function iE(g,t=0){return(YA[g[t+0]]+YA[g[t+1]]+YA[g[t+2]]+YA[g[t+3]]+"-"+YA[g[t+4]]+YA[g[t+5]]+"-"+YA[g[t+6]]+YA[g[t+7]]+"-"+YA[g[t+8]]+YA[g[t+9]]+"-"+YA[g[t+10]]+YA[g[t+11]]+YA[g[t+12]]+YA[g[t+13]]+YA[g[t+14]]+YA[g[t+15]]).toLowerCase()}let _g;const rE=new Uint8Array(16);function sE(){if(!_g){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");_g=crypto.getRandomValues.bind(crypto)}return _g(rE)}const aE=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),kI={randomUUID:aE};function _I(g,t,I){var Q;if(kI.randomUUID&&!g)return kI.randomUUID();g=g||{};const B=g.random??((Q=g.rng)==null?void 0:Q.call(g))??sE();if(B.length<16)throw new Error("Random bytes length must be >= 16");return B[6]=B[6]&15|64,B[8]=B[8]&63|128,iE(B)}const wg=(g,t)=>{var i;const I=window.getSelection(),B=document.createRange(),Q=t.lastChild;v(Q)||v(I)||(B.setStartAfter(Q),B.setEndAfter(Q),I.removeAllRanges(),I.addRange(B),(i=g.plugin.pausation)==null||i.add({delay:1}))},mg=(g,t)=>{const I=new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,inputType:"insertText",data:"Hello"});g.element.dispatchEvent(I);const{range:B}=g.cursor,Q=t[0],i=t[t.length-1],r=t.slice(1,-1);let o=B;if(!Q||!o)return;let a=null,h=0,l=null;if(g.cursor.isRange()&&(a=o.startContainer,h=o.startOffset,l=o.endContainer,o.deleteContents()),t.length===1){g.content.insert(Q);return}if($(o.commonAncestorContainer)&&o.commonAncestorContainer.tagName==="DIV"){const J=jA(a),P=jA(l),z=document.createDocumentFragment();for(;P!=null&&P.firstChild;)z.appendChild(P.firstChild);J==null||J.appendChild(z),P==null||P.remove();const Y=window.getSelection(),q=document.createRange();q.setStart(a,h),q.setEnd(a,h),Y==null||Y.removeAllRanges(),Y==null||Y.addRange(q)}o=g.cursor.isRangeInEditor()?window.getSelection().getRangeAt(0):B,o=JA(o.commonAncestorContainer)&&o.commonAncestorContainer.textContent==="粘贴文本"?B:o;const[f]=vA(o.commonAncestorContainer,J=>J.tagName==="P"&&J.classList.contains(CA)),[y]=vA(o.startContainer,J=>J.tagName==="SPAN"&&J.dataset.type===K.anchor),w=document.createRange(),R=!!y;w.setStart(o.startContainer,o.startOffset),w.setEndAfter(f.lastChild);const k=w.extractContents();if(!(f!=null&&f.textContent))f.innerHTML=Q;else if(JA(f.lastChild))f.lastChild.textContent+=Q;else if($(f.lastChild)&&f.lastChild.dataset.type===K.anchor){const{lastChild:J}=f.lastChild;JA(J)?J.textContent+=Q:J==null||J.appendChild(document.createTextNode(Q))}else f.appendChild(document.createTextNode(Q));wg(g,R?f.lastChild:f);let{nextSibling:L}=f;if(r.forEach(J=>{var z;const P=document.createElement("p");if(P.classList.add(CA),P.textContent=J,(z=f==null?void 0:f.parentNode)==null||z.insertBefore(P,L),L=P.nextSibling,wg(g,P),R){const Y=y.cloneNode(!1);Y.innerHTML=P.innerHTML,P.innerHTML=Y.outerHTML}}),!i)return;const F=document.createElement("p");if(F.classList.add(CA),F.appendChild(k),!F.textContent)F.innerHTML=i;else if(JA(F.firstChild))F.firstChild.textContent=i+F.firstChild.textContent;else if($(F.firstChild)&&F.firstChild.dataset.type===K.anchor){const{firstChild:J}=F.firstChild;JA(J)?J.textContent=i+J.textContent:J==null||J.insertBefore(document.createTextNode(i),J.firstChild)}else F.insertBefore(document.createTextNode(i),F.firstChild);g.element.insertBefore(F,L),[.5,1,1.5,2,2.5].every(J=>{var P;return!((P=F.textContent)!=null&&P.trim().endsWith(`停顿: ${J}S`))})&&wg(g,F)},[lE]=ZA("paragraph"),CA=lE(),$g=`<p class="${CA}"><br /></p>`;class cE extends YI{constructor(I,B){super();b(this,"_observer",null);b(this,"_onchange");b(this,"_editorElement");b(this,"wordLimitTip","");b(this,"_uid");b(this,"content");b(this,"cursor");b(this,"undo");b(this,"command");b(this,"maxLength");b(this,"plugin");this._uid=_I(),this._editorElement=I,this.content=new EE(I,this),this.cursor=new oE(I),this.undo=new nE(this,this.content,B==null?void 0:B.onUndoChange),this.command=new dQ(this.content,this.cursor),this.maxLength=(B==null?void 0:B.maxLength)??1e4,this.wordLimitTip=(B==null?void 0:B.wordLimitTip)??"",this.plugin=((B==null?void 0:B.plugins)??[]).reduce((Q,i)=>{const r=new i(this),o=r.prefix;return Q[o]=r,Q},{}),this._onchange=B==null?void 0:B.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(I){this.content.appendContent(I,B=>wg(this,B))}get element(){return this._editorElement}_setup(){this._observer=new MutationObserver(([I])=>{var B;if(I.removedNodes.length){const Q=I.removedNodes[0];if($(Q)&&Q.dataset.type===K.highlight){const i=window.getSelection(),{range:r}=this.cursor;if(v(r)||v(i))return;const o=document.createTextNode(""),a=document.createRange();r.insertNode(o),a.setStartAfter(o),a.setEndAfter(o),i.removeAllRanges(),i.addRange(a)}}I.addedNodes.forEach(Q=>{$(Q)&&Q.tagName==="P"&&!Q.classList.contains(CA)&&Q.classList.add(CA)}),I.removedNodes.length&&!this.content.getParas().length&&this.content.insertEmptyPara(),(B=this._onchange)==null||B.call(this,this.content.calcTextCount()),Array.from(document.querySelectorAll("p")).forEach(Q=>{Array.from(Q.style).includes("text-indent")&&Q.removeAttribute("style"),Array.from(Q.childNodes).forEach(r=>{var o;if($(r)&&r.tagName==="FONT"&&$(r.firstChild)&&((o=r.firstChild)==null?void 0:o.tagName)==="SPAN"){const a=r.firstChild;r.replaceWith(a.textContent??""),Q.normalize()}})}),Array.from(document.querySelectorAll("p span")).forEach(Q=>{var f;const i=Q.parentNode,r=Q.firstChild;if(Q&&Q.getAttribute("data-placeholder")!==null)return;const a=Q&&Q.style.textIndent==="20px",h=Q&&Q.style.backgroundColor&&((f=Q.parentElement)==null?void 0:f.style.textIndent)==="0px",l=Q&&Array.from(Q.childNodes).every(y=>JA(y)&&!y.textContent||$(y)&&y.tagName==="BR"),p=Q&&$(Q.firstChild)&&Q.firstChild.tagName==="BR";if(a||h){for(;Q.firstChild;)i==null||i.insertBefore(Q.firstChild,Q);i==null||i.removeChild(Q),se(r)}if(l&&(i==null||i.removeChild(Q)),h){i.removeAttribute("style");const y=window.getSelection(),R=(y==null?void 0:y.getRangeAt(0)).cloneRange();R.setStartAfter(R.startContainer),R.setEndAfter(R.endContainer),y==null||y.removeAllRanges(),y==null||y.addRange(R)}p&&Q.removeChild(Q.firstChild)}),this.content.getParas().forEach(Q=>{const i=Q.firstChild,r=Q.lastChild;Q.childNodes.length>1&&($(r)&&r.tagName==="BR"&&r.remove(),$(i)&&i.tagName==="BR"&&i.remove(),Array.from(Q.childNodes).forEach(o=>{$(o)&&o.tagName==="BR"&&o.remove()})),(Q.childNodes.length===0||Q.childNodes.length===1&&JA(Q.childNodes[0])&&Q.childNodes[0].textContent==="")&&Q.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(I=>I.setup())}_teardown(){var I;(I=this._observer)==null||I.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(B=>B.destroy())}_handleBackspace(I){var i,r,o,a,h;const B=window.getSelection(),Q=B.getRangeAt(0);if(I.key==="Backspace"){console.log(111);const{startContainer:l}=Q;if(l.nodeType===Node.ELEMENT_NODE){DE(l,"data-image-style-select");return}if(Q.startOffset===0&&Q.collapsed){const[p]=vA(Q.startContainer,y=>y.tagName==="P"&&y.classList.contains(CA)),f=p==null?void 0:p.previousElementSibling;if(f){I.preventDefault();const y=f.childNodes,w=f.childNodes[0];if(y.length===1&&(JA(w)&&w.textContent===""||$(w)&&w.tagName==="BR")){f.remove();const R=document.createRange();R.setStart(p.firstChild,0),R.collapse(!0),B.removeAllRanges(),B.addRange(R)}else{const R=document.createRange();R.selectNodeContents(f),R.collapse(!1),B.removeAllRanges(),B.addRange(R);const k=document.createDocumentFragment(),L=p.firstChild;for(;p.firstChild;)k.appendChild(p.firstChild);R.insertNode(k),p.remove();const F=document.createRange();F.setStartBefore(L),F.setEndBefore(L),B.removeAllRanges(),B.addRange(F)}}}}if(I.key==="Delete"&&hE()){const l=getSelection(),p=(i=getSelection())==null?void 0:i.getRangeAt(0);if(v(l)||v(p))return;const f=jA(p.endContainer),y=f==null?void 0:f.nextElementSibling;if(v(f)||v(y))return;const w=document.createRange();for(w.selectNodeContents(f),w.collapse(!1);y.firstChild;)f.appendChild(y.firstChild);y.remove(),l.removeAllRanges(),l.addRange(w),f.normalize()}if(I.key==="Enter"){const{range:l}=this.cursor;if(iQ(l))return;const[p]=vA(l==null?void 0:l.commonAncestorContainer,y=>y.tagName==="SPAN"&&y.dataset.type===K.anchor);if(l!=null&&l.collapsed&&l.startOffset===0&&p){I.preventDefault();const y=document.createElement("p");y.innerHTML="<br />",this._editorElement.insertBefore(y,p.parentElement)}const[f]=vA(l==null?void 0:l.commonAncestorContainer,y=>y.tagName==="SPAN"&&y.dataset.type===K.placeholderoldSpace);if(l&&I.shiftKey&&!f){const y=jA(l.startContainer);if(((r=y==null?void 0:y.textContent)==null?void 0:r.length)===l.startOffset&&((o=y==null?void 0:y.textContent)==null?void 0:o.length)!==0){I.preventDefault();const w=document.createElement("p");w.innerHTML="<br />",y==null||y.appendChild(w);const R=document.createRange();R.setStart(w.firstChild||w,0),R.collapse(!0),B.removeAllRanges(),B.addRange(R)}else if(l.startOffset===0){I.preventDefault();const w=document.createElement("p");w.classList.add(CA),w.innerHTML="<br />",(a=y==null?void 0:y.textContent)!=null&&a.length?y==null||y.before(w):y==null||y.after(w);const R=document.createRange();R.setStart(w.firstChild||w,0),R.collapse(!0),B.removeAllRanges(),B.addRange(R)}else{I.preventDefault();const w=document.createElement("p");w.classList.add(CA);const R=document.createRange();R.setStart(l.startContainer,l.startOffset),R.setEndAfter(y.lastChild);const k=R.extractContents();w.appendChild(k),w.textContent||(w.innerHTML="<br />"),(h=y==null?void 0:y.parentNode)==null||h.insertBefore(w,y.nextSibling);const L=document.createRange();L.setStart(w.firstChild||w,0),L.collapse(!0),B.removeAllRanges(),B.addRange(L)}}}if(Q.startOffset===0&&Q.endContainer.tagName==="P"&&jA(Q.startContainer)===jA(Q.endContainer)){const l=jA(Q.endContainer);if(v(l))return;I.key==="Backspace"&&wE(l,B)}}_handlePaste(I){var Q,i;I.preventDefault(),dE(this._editorElement);const B=((i=(Q=I.clipboardData)==null?void 0:Q.getData("text/plain"))==null?void 0:i.split(/(?:\r?\n){2,}/).map(r=>r.trim()).filter(r=>r))??[];mg(this,Sg(this,B))}_handleBeforeInput(I){uQ(this,I)}_handleCompositionEnd(I){wQ(this,I)}}const Me=(g,t,I,B)=>{if(Object.keys(t).forEach(Q=>{g.setAttribute(Q,String(t[Q]))}),Object.keys(I).forEach(Q=>{g.dataset[Q]=String(I[Q])}),!v(B))if(UI(B)){const Q=document.createDocumentFragment(),i=document.createElement("div");for(i.innerHTML=B;i.firstChild;)Q.appendChild(i.firstChild);g.appendChild(Q)}else g.appendChild(B)},vA=(g,t)=>{const I=JI(t)?t:[t];let B=g;for(;B;){const Q=B,i=I.map(r=>r(Q)).map(r=>r?Q:null);if(i.some(r=>r))return i;B=B.parentElement}return new Array(I.length).fill(null)},jA=g=>{const[t]=vA(g,I=>I.tagName==="P"&&I.classList.contains(CA));return t},Dt=(g,t)=>{if(g===t)return[];const I=[];let B=g.nextElementSibling;for(;B&&B!==t;)I.push(B),B=B.nextElementSibling;return I},Ht=g=>{const t=document.createElement("div");return t.setAttribute("class",`editor-${g}-tag-modal`),t},se=(g,t,I)=>{var r,o,a;const B=g.previousSibling,Q=g.nextSibling,i=t??g.textContent??"";if(I&&(!B&&!Q||$(B)&&B.dataset.type===K.pausation||$(B)&&[K.anchor,K.homophones,K.pausation,K.pronunciation].includes(B.dataset.type))){$(g)&&g.dataset.type!==K.pausation?g.replaceWith(g.dataset.raw??""):(r=g.parentNode)==null||r.removeChild(g);return}if(JA(B)){B.textContent+=i,(o=g.parentNode)==null||o.removeChild(g),se(B,B.textContent,!1);return}JA(Q)&&(Q.textContent=i+Q.textContent,(a=g.parentNode)==null||a.removeChild(g),se(Q,Q.textContent,!1))},At=(g,t)=>{const I=g.length,B=t.length,Q=new Array(B).fill(0);let i=Q[0],r=0,o=0;for(let a=1;a<=I;a++){for(let h=1;h<=B;h++){const l=Q[h];g[a-1]===t[h-1]?(Q[h]=i+1,Q[h]>r&&(r=Math.max(r,Q[h]),o=h-1)):Q[h]=0,i=l}i=Q[0]}return t.substring(o-r+1,o+1)},hE=()=>{const g=window.getSelection();if(!g||!g.rangeCount||g.type!=="Caret")return!1;const t=g.getRangeAt(0);let I=t.endContainer;for(;I&&I.nodeName!=="P";)I=I.parentNode;if(!I)return!1;const B=t.cloneRange();return B.setEndAfter(I),B.toString().length===0},dE=g=>{const t=window.getSelection();if(!t.rangeCount)return;const I=Array.from(g.querySelectorAll("p"));if(I.length===0)return;let B=!1;for(const Q of I)if(Q.contains(t.anchorNode)){B=!0;break}if(!B){const Q=document.createRange(),i=I[I.length-1];Q.selectNodeContents(i),Q.collapse(!1),t.removeAllRanges(),t.addRange(Q)}},wE=(g,t)=>{if(!g)return;for(;g.firstChild;)g.removeChild(g.firstChild);g.appendChild(document.createElement("br"));const I=document.createRange();I.selectNodeContents(g),I.collapse(!1),t.removeAllRanges(),t.addRange(I)},$I=(g,t,I=0)=>{if(!g||!t)return{top:0,left:0,width:0,height:0};const B=g,Q=t,i=Q.bottom-B.top+I,r=Q.left-B.left;return{top:i,left:r,width:Q.width,height:Q.height}},uE=g=>{const t=Array.from(document.querySelectorAll(`span[data-frag-id="anchor_${g.id}"]`));return g.uid?t.filter(I=>I.dataset.uid===g.uid):t.filter(I=>!I.dataset.uid)};function DE(g,t,I){if(!(g instanceof HTMLElement))return console.error("parentNode 必须是有效的 DOM 元素"),0;if(t.trim()==="")return console.error("targetAttr 必须是有效的字符串"),0;const B=Array.from(g.children);let Q=0;return B.forEach(i=>{i.hasAttribute(t)&&(g.removeChild(i),Q++)}),Q}function fE(g,t){if(!(g instanceof HTMLElement))return console.error("传入的 node 必须是有效的 DOM 元素"),"";if(typeof t!="string"||t.trim()==="")return console.error("targetAttr 必须是非空字符串"),"";if(g.getAttribute("data-type")!==t)return"";function I(Q){let i="";return Array.from(Q.childNodes).forEach(r=>{var o;switch(r.nodeType){case Node.TEXT_NODE:i+=`${((o=r.textContent)==null?void 0:o.trim())??""} `;break;case Node.ELEMENT_NODE:i+=I(r);break}}),i}return I(g).replace(/\s+/g," ").trim()}function AC(g){return n.getCurrentScope()?(n.onScopeDispose(g),!0):!1}const Yt=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const yE=Object.prototype.toString,pE=g=>yE.call(g)==="[object Object]",NI=()=>{};function RE(g){let t;function I(){return t||(t=g()),t}return I.reset=async()=>{const B=t;t=void 0,B&&await B},I}function et(g){return Array.isArray(g)?g:[g]}function kE(g,t,I={}){const{immediate:B=!0,immediateCallback:Q=!1}=I,i=n.shallowRef(!1);let r=null;function o(){r&&(clearTimeout(r),r=null)}function a(){i.value=!1,o()}function h(...l){Q&&g(),o(),i.value=!0,r=setTimeout(()=>{i.value=!1,r=null,g(...l)},n.toValue(t))}return B&&(i.value=!0,Yt&&h()),AC(a),{isPending:n.readonly(i),start:h,stop:a}}function ug(g=!1,t={}){const{truthyValue:I=!0,falsyValue:B=!1}=t,Q=n.isRef(g),i=n.shallowRef(g);function r(o){if(arguments.length)return i.value=o,i.value;{const a=n.toValue(I);return i.value=i.value===a?n.toValue(B):a,i.value}}return Q?r:[i,r]}function NE(g,t,I){return n.watch(g,t,{...I,immediate:!0})}const eC=Yt?window:void 0,gC=Yt?window.navigator:void 0;function FE(g){var t;const I=n.toValue(g);return(t=I==null?void 0:I.$el)!=null?t:I}function Fe(...g){const t=[],I=()=>{t.forEach(o=>o()),t.length=0},B=(o,a,h,l)=>(o.addEventListener(a,h,l),()=>o.removeEventListener(a,h,l)),Q=n.computed(()=>{const o=et(n.toValue(g[0])).filter(a=>a!=null);return o.every(a=>typeof a!="string")?o:void 0}),i=NE(()=>{var o,a;return[(a=(o=Q.value)==null?void 0:o.map(h=>FE(h)))!=null?a:[eC].filter(h=>h!=null),et(n.toValue(Q.value?g[1]:g[0])),et(n.unref(Q.value?g[2]:g[1])),n.toValue(Q.value?g[3]:g[2])]},([o,a,h,l])=>{if(I(),!(o!=null&&o.length)||!(a!=null&&a.length)||!(h!=null&&h.length))return;const p=pE(l)?{...l}:l;t.push(...o.flatMap(f=>a.flatMap(y=>h.map(w=>B(f,y,w,p)))))},{flush:"post"}),r=()=>{i(),I()};return AC(I),r}function SE(){const g=n.shallowRef(!1),t=n.getCurrentInstance();return t&&n.onMounted(()=>{g.value=!0},t),g}function tC(g){const t=SE();return n.computed(()=>(t.value,!!g()))}function FI(g,t={}){const{controls:I=!1,navigator:B=gC}=t,Q=tC(()=>B&&"permissions"in B),i=n.shallowRef(),r=typeof g=="string"?{name:g}:g,o=n.shallowRef(),a=()=>{var l,p;o.value=(p=(l=i.value)==null?void 0:l.state)!=null?p:"prompt"};Fe(i,"change",a,{passive:!0});const h=RE(async()=>{if(Q.value){if(!i.value)try{i.value=await B.permissions.query(r)}catch{i.value=void 0}finally{a()}if(I)return n.toRaw(i.value)}});return h(),I?{state:o,isSupported:Q,query:h}:o}function LE(g={}){const{navigator:t=gC,read:I=!1,source:B,copiedDuring:Q=1500,legacy:i=!1}=g,r=tC(()=>t&&"clipboard"in t),o=FI("clipboard-read"),a=FI("clipboard-write"),h=n.computed(()=>r.value||i),l=n.shallowRef(""),p=n.shallowRef(!1),f=kE(()=>p.value=!1,Q,{immediate:!1});async function y(){let F=!(r.value&&L(o.value));if(!F)try{l.value=await t.clipboard.readText()}catch{F=!0}F&&(l.value=k())}h.value&&I&&Fe(["copy","cut"],y,{passive:!0});async function w(F=n.toValue(B)){if(h.value&&F!=null){let m=!(r.value&&L(a.value));if(!m)try{await t.clipboard.writeText(F)}catch{m=!0}m&&R(F),l.value=F,p.value=!0,f.start()}}function R(F){const m=document.createElement("textarea");m.value=F??"",m.style.position="absolute",m.style.opacity="0",document.body.appendChild(m),m.select(),document.execCommand("copy"),m.remove()}function k(){var F,m,J;return(J=(m=(F=document==null?void 0:document.getSelection)==null?void 0:F.call(document))==null?void 0:m.toString())!=null?J:""}function L(F){return F==="granted"||F==="prompt"}return{isSupported:h,text:l,copied:p,copy:w}}const GE={page:g=>[g.pageX,g.pageY],client:g=>[g.clientX,g.clientY],screen:g=>[g.screenX,g.screenY],movement:g=>g instanceof MouseEvent?[g.movementX,g.movementY]:null};function Mg(g={}){const{type:t="page",touch:I=!0,resetOnTouchEnds:B=!1,initialValue:Q={x:0,y:0},window:i=eC,target:r=i,scroll:o=!0,eventFilter:a}=g;let h=null,l=0,p=0;const f=n.shallowRef(Q.x),y=n.shallowRef(Q.y),w=n.shallowRef(null),R=typeof t=="function"?t:GE[t],k=Y=>{const q=R(Y);h=Y,q&&([f.value,y.value]=q,w.value="mouse"),i&&(l=i.scrollX,p=i.scrollY)},L=Y=>{if(Y.touches.length>0){const q=R(Y.touches[0]);q&&([f.value,y.value]=q,w.value="touch")}},F=()=>{if(!h||!i)return;const Y=R(h);h instanceof MouseEvent&&Y&&(f.value=Y[0]+i.scrollX-l,y.value=Y[1]+i.scrollY-p)},m=()=>{f.value=Q.x,y.value=Q.y},J=a?Y=>a(()=>k(Y),{}):Y=>k(Y),P=a?Y=>a(()=>L(Y),{}):Y=>L(Y),z=a?()=>a(()=>F(),{}):()=>F();if(r){const Y={passive:!0};Fe(r,["mousemove","dragover"],J,Y),I&&t!=="movement"&&(Fe(r,["touchstart","touchmove"],P,Y),B&&Fe(r,"touchend",m,Y)),o&&t==="page"&&Fe(i,"scroll",z,Y)}return{x:f,y,sourceType:w}}const mE=["onClick"],ME=n.defineComponent({__name:"pausationor",props:{visible:{type:Boolean}},emits:["ok"],setup(g,{emit:t}){const I=g,B=t,[Q]=ZA("pausation-tag-selector"),i=[{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(r,o)=>n.withDirectives((n.openBlock(),n.createElementBlock("ul",{class:n.normalizeClass(n.unref(Q)()),contenteditable:"false",onClick:o[0]||(o[0]=n.withModifiers(()=>{},["stop"]))},[(n.openBlock(),n.createElementBlock(n.Fragment,null,n.renderList(i,(a,h)=>n.createElementVNode("li",{key:h,class:n.normalizeClass(n.unref(Q)("item")),onClick:l=>B("ok",l,a.value)},n.toDisplayString(a.label),11,mE)),64))],2)),[[n.vShow,I.visible]])}}),mA=(g,t)=>{const I=g.__vccOpts||g;for(const[B,Q]of t)I[B]=Q;return I},IC=mA(ME,[["__scopeId","data-v-a957cba2"]]),UE=0,Se=K.pausation,[ft]=Ze(Se),CC=ft("close"),{x:JE,y:HE}=Mg(),YE=`<svg class="${CC}" 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">
68
+ `)}_htmlToMarkdownInline(I){const B=document.createElement("span");B.innerHTML=I;const Q=i=>{if(i.nodeType===Node.TEXT_NODE)return i.textContent??"";if(i.nodeType!==Node.ELEMENT_NODE)return"";const r=i,o=r.tagName,a=Array.from(r.childNodes).map(Q).join("");switch(o){case"STRONG":case"B":return`**${a}**`;case"EM":case"I":return`*${a}*`;case"DEL":case"S":return`~~${a}~~`;case"CODE":return`\`${a}\``;case"A":{const h=r.getAttribute("href")??"";return`[${a}](${h})`}case"IMG":{const h=r.getAttribute("src")??"";return`![${r.getAttribute("alt")??""}](${h})`}case"BR":return"";default:return a}};return Array.from(B.childNodes).map(Q).join("")}appendContent(I,B){var o;const Q=Sg(this._editor,JI(I)?I:[I]),i=this.getParas()[0],r=(o=i.textContent)!=null&&o.length?void 0:Q.shift();r&&(i.innerHTML=r,B==null||B(i)),Q.forEach(a=>{const h=document.createElement("p");h.innerHTML=a,h.classList.add(CA),this._editorElement.appendChild(h),B==null||B(h)})}insert(I){this._insert(I)}delete(){this._delete()}update(I){this._update(I)}getParas(){return Array.from(this._editorElement.querySelectorAll(`.${CA}`))}getTextContent(){const I=this.getParas(),B=Q=>{const i=Array.from(Q.childNodes);let r="";for(let o=0;o<i.length;o++){const a=i[o];JA(a)?r+=a.textContent??"":$(a)&&(r+=(l=>{let p="";const{type:f,value:y,raw:w}=l.dataset;if([K.placeholderoldSpace].includes(f))return p=fE(l,f)??"",p;if([K.anchor].includes(f)){const R=B(l);return typeof R=="string"?R:""}return f===K.pronunciation?y??"":w??l.innerText??""})(a))}return r};return I.map(B)}_insert(I){const B=window.getSelection(),Q=this._editor.cursor.isRangeInEditor()?B==null?void 0:B.getRangeAt(0):this._editor.cursor.range;if(v(B)||!B.rangeCount||v(Q))return;const i=document.createDocumentFragment();if(UI(I)){const h=document.createElement("div");for(h.innerHTML=I;h.firstChild;)i.appendChild(h.firstChild)}else i.appendChild(I);const r=i.lastChild;(this._calcRange(Q)??Q).insertNode(i);const a=document.createRange();a.setStartAfter(r),a.setEndAfter(r),B.removeAllRanges(),B.addRange(a)}_delete(){const{range:I}=this._editor.cursor;I==null||I.deleteContents()}_update(I){this._delete(),this._insert(I)}_calcRange(I){const B=I.commonAncestorContainer;if($(I.startContainer)&&I.startContainer.dataset.type===K.highlight&&I.endContainer.nodeType===Node.TEXT_NODE){const a=document.createRange();return a.setStartAfter(I.startContainer),a.collapse(!0),a}if(B.tagName!=="DIV")return I;const Q=I.startOffset,i=Array.from(B.children).filter(a=>a.tagName==="P");if(Q<=0||Q-1>=i.length)return console.warn("上一个 <p> 不存在"),I;const r=i[Q-1];if(!r)return console.warn("未找到上一个 <p>"),I;const o=document.createRange();return o.selectNodeContents(r),o.collapse(!1),o}}class oE extends vI{constructor(I){super();b(this,"_editorElement");b(this,"range");this._editorElement=I,this._recordRange=this._recordRange.bind(this),document.addEventListener("selectionchange",this._recordRange)}destroy(){document.removeEventListener("selectionchange",this._recordRange)}_recordRange(I){var B;this.isRangeInEditor()&&(this.range=(B=window.getSelection())==null?void 0:B.getRangeAt(0).cloneRange())}isRangeInEditor(){const I=window.getSelection();if(v(I)||!I.rangeCount)return!1;const B=I.getRangeAt(0);return this._editorElement.contains(B.commonAncestorContainer)}isCaret(){var I;return((I=this.range)==null?void 0:I.collapsed)===!0}isRange(){var I;return((I=this.range)==null?void 0:I.collapsed)===!1}getRangeContent(){var I;return this.isCaret()?"":((I=this.range)==null?void 0:I.toString())??""}toEnd(I){const B=window.getSelection();if(v(B))return;const Q=document.createRange();Q.setStartAfter(I),Q.setEndAfter(I),B.removeAllRanges(),B.addRange(Q)}getRangeTop(){var I;return(((I=this.range)==null?void 0:I.getBoundingClientRect().top)??0)-this._editorElement.getBoundingClientRect().top+16}}class nE extends qI{constructor(I,B,Q){super();b(this,"_editor");b(this,"_onUndoChange");b(this,"contentManager");b(this,"undoStack");b(this,"redoStack");this._editor=I,this.contentManager=B,this.undoStack=[],this.redoStack=[],this._onUndoChange=Q,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(I){const B=[];let Q=I;for(;Q&&Q.parentElement;){const r=Array.from(Q.parentElement.childNodes).indexOf(Q);if(B.unshift({index:r}),$(Q)&&Q.tagName==="P"&&Q.classList.contains(CA))break;Q=Q.parentElement}return B}_record(){var l;const I=this._editor.cursor.range,B=this._editor.content.getParas(),Q=jA(I.startContainer),i=B.indexOf(Q),r=this._calcNodePathMatches(I.startContainer),o=jA(I.endContainer),a=B.indexOf(o),h=this._calcNodePathMatches(I.endContainer);return{startParaIndex:i,startMatchedIndexes:r,startOffset:I.startOffset,endParaIndex:a,endMatchedIndexes:h,endOffset:I.endOffset,content:this._editor.element.innerHTML,anchorContent:JSON.stringify(((l=this._editor.plugin.anchor)==null?void 0:l.data)??{})}}_handleInput(){this.undoStack.push(this._record()),this.redoStack=[]}_handleUndoOrRedo(I){var B;if(I.ctrlKey&&I.key==="z"&&(I.preventDefault(),this.undoStack.length>0)){this.redoStack.push(this._record());const Q=this.undoStack.pop();this._editor.content.calcTextCount()&&requestAnimationFrame(()=>this._restoreCursor(Q)),this._editor.element.innerHTML=Q.content,(B=this._onUndoChange)==null||B.call(this,Q.anchorContent)}}_restoreCursor(I){const B=window.getSelection();if(v(B))return;const Q=a=>{let h=this._editor.content.getParas(),{index:l}=a[0],p=null,f=0;for(;f<a.length;){if(p=h[l],JA(p))return p;if(h=Array.from(p.childNodes),f++,f>=a.length)break;l=a[f].index}return p},i=Q(I.startMatchedIndexes),r=Q(I.endMatchedIndexes),o=document.createRange();o.setStart(i,I.startOffset),o.setEnd(r,I.endOffset),B.removeAllRanges(),B.addRange(o)}}const YA=[];for(let g=0;g<256;++g)YA.push((g+256).toString(16).slice(1));function iE(g,t=0){return(YA[g[t+0]]+YA[g[t+1]]+YA[g[t+2]]+YA[g[t+3]]+"-"+YA[g[t+4]]+YA[g[t+5]]+"-"+YA[g[t+6]]+YA[g[t+7]]+"-"+YA[g[t+8]]+YA[g[t+9]]+"-"+YA[g[t+10]]+YA[g[t+11]]+YA[g[t+12]]+YA[g[t+13]]+YA[g[t+14]]+YA[g[t+15]]).toLowerCase()}let _g;const rE=new Uint8Array(16);function sE(){if(!_g){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");_g=crypto.getRandomValues.bind(crypto)}return _g(rE)}const aE=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),kI={randomUUID:aE};function _I(g,t,I){var Q;if(kI.randomUUID&&!g)return kI.randomUUID();g=g||{};const B=g.random??((Q=g.rng)==null?void 0:Q.call(g))??sE();if(B.length<16)throw new Error("Random bytes length must be >= 16");return B[6]=B[6]&15|64,B[8]=B[8]&63|128,iE(B)}const wg=(g,t)=>{var i;const I=window.getSelection(),B=document.createRange(),Q=t.lastChild;v(Q)||v(I)||(B.setStartAfter(Q),B.setEndAfter(Q),I.removeAllRanges(),I.addRange(B),(i=g.plugin.pausation)==null||i.add({delay:1}))},mg=(g,t)=>{const I=new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,inputType:"insertText",data:"Hello"});g.element.dispatchEvent(I);const{range:B}=g.cursor,Q=t[0],i=t[t.length-1],r=t.slice(1,-1);let o=B;if(!Q||!o)return;let a=null,h=0,l=null;if(g.cursor.isRange()&&(a=o.startContainer,h=o.startOffset,l=o.endContainer,o.deleteContents()),t.length===1){g.content.insert(Q);return}if($(o.commonAncestorContainer)&&o.commonAncestorContainer.tagName==="DIV"){const J=jA(a),P=jA(l),z=document.createDocumentFragment();for(;P!=null&&P.firstChild;)z.appendChild(P.firstChild);J==null||J.appendChild(z),P==null||P.remove();const Y=window.getSelection(),q=document.createRange();q.setStart(a,h),q.setEnd(a,h),Y==null||Y.removeAllRanges(),Y==null||Y.addRange(q)}o=g.cursor.isRangeInEditor()?window.getSelection().getRangeAt(0):B,o=JA(o.commonAncestorContainer)&&o.commonAncestorContainer.textContent==="粘贴文本"?B:o;const[f]=vA(o.commonAncestorContainer,J=>J.tagName==="P"&&J.classList.contains(CA)),[y]=vA(o.startContainer,J=>J.tagName==="SPAN"&&J.dataset.type===K.anchor),w=document.createRange(),R=!!y;w.setStart(o.startContainer,o.startOffset),w.setEndAfter(f.lastChild);const k=w.extractContents();if(!(f!=null&&f.textContent))f.innerHTML=Q;else if(JA(f.lastChild))f.lastChild.textContent+=Q;else if($(f.lastChild)&&f.lastChild.dataset.type===K.anchor){const{lastChild:J}=f.lastChild;JA(J)?J.textContent+=Q:J==null||J.appendChild(document.createTextNode(Q))}else f.appendChild(document.createTextNode(Q));wg(g,R?f.lastChild:f);let{nextSibling:L}=f;if(r.forEach(J=>{var z;const P=document.createElement("p");if(P.classList.add(CA),P.textContent=J,(z=f==null?void 0:f.parentNode)==null||z.insertBefore(P,L),L=P.nextSibling,wg(g,P),R){const Y=y.cloneNode(!1);Y.innerHTML=P.innerHTML,P.innerHTML=Y.outerHTML}}),!i)return;const F=document.createElement("p");if(F.classList.add(CA),F.appendChild(k),!F.textContent)F.innerHTML=i;else if(JA(F.firstChild))F.firstChild.textContent=i+F.firstChild.textContent;else if($(F.firstChild)&&F.firstChild.dataset.type===K.anchor){const{firstChild:J}=F.firstChild;JA(J)?J.textContent=i+J.textContent:J==null||J.insertBefore(document.createTextNode(i),J.firstChild)}else F.insertBefore(document.createTextNode(i),F.firstChild);g.element.insertBefore(F,L),[.5,1,1.5,2,2.5].every(J=>{var P;return!((P=F.textContent)!=null&&P.trim().endsWith(`停顿: ${J}S`))})&&wg(g,F)},[lE]=ZA("paragraph"),CA=lE(),$g=`<p class="${CA}"><br /></p>`;class cE extends YI{constructor(I,B){super();b(this,"_observer",null);b(this,"_onchange");b(this,"_editorElement");b(this,"wordLimitTip","");b(this,"_uid");b(this,"content");b(this,"cursor");b(this,"undo");b(this,"command");b(this,"maxLength");b(this,"plugin");this._uid=_I(),this._editorElement=I,this.content=new EE(I,this),this.cursor=new oE(I),this.undo=new nE(this,this.content,B==null?void 0:B.onUndoChange),this.command=new dQ(this.content,this.cursor),this.maxLength=(B==null?void 0:B.maxLength)??1e4,this.wordLimitTip=(B==null?void 0:B.wordLimitTip)??"",this.plugin=((B==null?void 0:B.plugins)??[]).reduce((Q,i)=>{const r=new i(this),o=r.prefix;return Q[o]=r,Q},{}),this._onchange=B==null?void 0:B.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(I){this.content.appendContent(I,B=>wg(this,B))}get element(){return this._editorElement}_setup(){this._observer=new MutationObserver(([I])=>{var B;if(I.removedNodes.length){const Q=I.removedNodes[0];if($(Q)&&Q.dataset.type===K.highlight){const i=window.getSelection(),{range:r}=this.cursor;if(v(r)||v(i))return;const o=document.createTextNode(""),a=document.createRange();r.insertNode(o),a.setStartAfter(o),a.setEndAfter(o),i.removeAllRanges(),i.addRange(a)}}I.addedNodes.forEach(Q=>{$(Q)&&Q.tagName==="P"&&!Q.classList.contains(CA)&&Q.classList.add(CA)}),I.removedNodes.length&&!this.content.getParas().length&&this.content.insertEmptyPara(),(B=this._onchange)==null||B.call(this,this.content.calcTextCount()),Array.from(document.querySelectorAll("p")).forEach(Q=>{Array.from(Q.style).includes("text-indent")&&Q.removeAttribute("style"),Array.from(Q.childNodes).forEach(r=>{var o;if($(r)&&r.tagName==="FONT"&&$(r.firstChild)&&((o=r.firstChild)==null?void 0:o.tagName)==="SPAN"){const a=r.firstChild;r.replaceWith(a.textContent??""),Q.normalize()}})}),Array.from(document.querySelectorAll("p span")).forEach(Q=>{var f;const i=Q.parentNode,r=Q.firstChild;if(Q&&Q.getAttribute("data-placeholder")!==null)return;const a=Q&&Q.style.textIndent==="20px",h=Q&&Q.style.backgroundColor&&((f=Q.parentElement)==null?void 0:f.style.textIndent)==="0px",l=Q&&Array.from(Q.childNodes).every(y=>JA(y)&&!y.textContent||$(y)&&y.tagName==="BR"),p=Q&&$(Q.firstChild)&&Q.firstChild.tagName==="BR";if(a||h){for(;Q.firstChild;)i==null||i.insertBefore(Q.firstChild,Q);i==null||i.removeChild(Q),se(r)}if(l&&(i==null||i.removeChild(Q)),h){i.removeAttribute("style");const y=window.getSelection(),R=(y==null?void 0:y.getRangeAt(0)).cloneRange();R.setStartAfter(R.startContainer),R.setEndAfter(R.endContainer),y==null||y.removeAllRanges(),y==null||y.addRange(R)}p&&Q.removeChild(Q.firstChild)}),this.content.getParas().forEach(Q=>{const i=Q.firstChild,r=Q.lastChild;Q.childNodes.length>1&&($(r)&&r.tagName==="BR"&&r.remove(),$(i)&&i.tagName==="BR"&&i.remove(),Array.from(Q.childNodes).forEach(o=>{$(o)&&o.tagName==="BR"&&o.remove()})),(Q.childNodes.length===0||Q.childNodes.length===1&&JA(Q.childNodes[0])&&Q.childNodes[0].textContent==="")&&Q.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(I=>I.setup())}_teardown(){var I;(I=this._observer)==null||I.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(B=>B.destroy())}_handleBackspace(I){var i,r,o,a,h;const B=window.getSelection(),Q=B.getRangeAt(0);if(I.key==="Backspace"){const{startContainer:l}=Q;if(l.nodeType===Node.ELEMENT_NODE){DE(l,"data-image-style-select");return}if(Q.startOffset===0&&Q.collapsed){const[p]=vA(Q.startContainer,y=>y.tagName==="P"&&y.classList.contains(CA)),f=p==null?void 0:p.previousElementSibling;if(f){I.preventDefault();const y=f.childNodes,w=f.childNodes[0];if(y.length===1&&(JA(w)&&w.textContent===""||$(w)&&w.tagName==="BR")){f.remove();const R=document.createRange();R.setStart(p.firstChild,0),R.collapse(!0),B.removeAllRanges(),B.addRange(R)}else{const R=document.createRange();R.selectNodeContents(f),R.collapse(!1),B.removeAllRanges(),B.addRange(R);const k=document.createDocumentFragment(),L=p.firstChild;for(;p.firstChild;)k.appendChild(p.firstChild);R.insertNode(k),p.remove();const F=document.createRange();F.setStartBefore(L),F.setEndBefore(L),B.removeAllRanges(),B.addRange(F)}}}}if(I.key==="Delete"&&hE()){const l=getSelection(),p=(i=getSelection())==null?void 0:i.getRangeAt(0);if(v(l)||v(p))return;const f=jA(p.endContainer),y=f==null?void 0:f.nextElementSibling;if(v(f)||v(y))return;const w=document.createRange();for(w.selectNodeContents(f),w.collapse(!1);y.firstChild;)f.appendChild(y.firstChild);y.remove(),l.removeAllRanges(),l.addRange(w),f.normalize()}if(I.key==="Enter"){const{range:l}=this.cursor;if(iQ(l))return;const[p]=vA(l==null?void 0:l.commonAncestorContainer,y=>y.tagName==="SPAN"&&y.dataset.type===K.anchor);if(l!=null&&l.collapsed&&l.startOffset===0&&p){I.preventDefault();const y=document.createElement("p");y.innerHTML="<br />",this._editorElement.insertBefore(y,p.parentElement)}const[f]=vA(l==null?void 0:l.commonAncestorContainer,y=>y.tagName==="SPAN"&&y.dataset.type===K.placeholderoldSpace);if(l&&I.shiftKey&&!f){const y=jA(l.startContainer);if(((r=y==null?void 0:y.textContent)==null?void 0:r.length)===l.startOffset&&((o=y==null?void 0:y.textContent)==null?void 0:o.length)!==0){I.preventDefault();const w=document.createElement("p");w.innerHTML="<br />",y==null||y.appendChild(w);const R=document.createRange();R.setStart(w.firstChild||w,0),R.collapse(!0),B.removeAllRanges(),B.addRange(R)}else if(l.startOffset===0){I.preventDefault();const w=document.createElement("p");w.classList.add(CA),w.innerHTML="<br />",(a=y==null?void 0:y.textContent)!=null&&a.length?y==null||y.before(w):y==null||y.after(w);const R=document.createRange();R.setStart(w.firstChild||w,0),R.collapse(!0),B.removeAllRanges(),B.addRange(R)}else{I.preventDefault();const w=document.createElement("p");w.classList.add(CA);const R=document.createRange();R.setStart(l.startContainer,l.startOffset),R.setEndAfter(y.lastChild);const k=R.extractContents();w.appendChild(k),w.textContent||(w.innerHTML="<br />"),(h=y==null?void 0:y.parentNode)==null||h.insertBefore(w,y.nextSibling);const L=document.createRange();L.setStart(w.firstChild||w,0),L.collapse(!0),B.removeAllRanges(),B.addRange(L)}}}if(Q.startOffset===0&&Q.endContainer.tagName==="P"&&jA(Q.startContainer)===jA(Q.endContainer)){const l=jA(Q.endContainer);if(v(l))return;I.key==="Backspace"&&wE(l,B)}}_handlePaste(I){var Q,i;I.preventDefault(),dE(this._editorElement);const B=((i=(Q=I.clipboardData)==null?void 0:Q.getData("text/plain"))==null?void 0:i.split(/(?:\r?\n){2,}/).map(r=>r.trim()).filter(r=>r))??[];mg(this,Sg(this,B))}_handleBeforeInput(I){uQ(this,I)}_handleCompositionEnd(I){wQ(this,I)}}const Me=(g,t,I,B)=>{if(Object.keys(t).forEach(Q=>{g.setAttribute(Q,String(t[Q]))}),Object.keys(I).forEach(Q=>{g.dataset[Q]=String(I[Q])}),!v(B))if(UI(B)){const Q=document.createDocumentFragment(),i=document.createElement("div");for(i.innerHTML=B;i.firstChild;)Q.appendChild(i.firstChild);g.appendChild(Q)}else g.appendChild(B)},vA=(g,t)=>{const I=JI(t)?t:[t];let B=g;for(;B;){const Q=B,i=I.map(r=>r(Q)).map(r=>r?Q:null);if(i.some(r=>r))return i;B=B.parentElement}return new Array(I.length).fill(null)},jA=g=>{const[t]=vA(g,I=>I.tagName==="P"&&I.classList.contains(CA));return t},Dt=(g,t)=>{if(g===t)return[];const I=[];let B=g.nextElementSibling;for(;B&&B!==t;)I.push(B),B=B.nextElementSibling;return I},Ht=g=>{const t=document.createElement("div");return t.setAttribute("class",`editor-${g}-tag-modal`),t},se=(g,t,I)=>{var r,o,a;const B=g.previousSibling,Q=g.nextSibling,i=t??g.textContent??"";if(I&&(!B&&!Q||$(B)&&B.dataset.type===K.pausation||$(B)&&[K.anchor,K.homophones,K.pausation,K.pronunciation].includes(B.dataset.type))){$(g)&&g.dataset.type!==K.pausation?g.replaceWith(g.dataset.raw??""):(r=g.parentNode)==null||r.removeChild(g);return}if(JA(B)){B.textContent+=i,(o=g.parentNode)==null||o.removeChild(g),se(B,B.textContent,!1);return}JA(Q)&&(Q.textContent=i+Q.textContent,(a=g.parentNode)==null||a.removeChild(g),se(Q,Q.textContent,!1))},At=(g,t)=>{const I=g.length,B=t.length,Q=new Array(B).fill(0);let i=Q[0],r=0,o=0;for(let a=1;a<=I;a++){for(let h=1;h<=B;h++){const l=Q[h];g[a-1]===t[h-1]?(Q[h]=i+1,Q[h]>r&&(r=Math.max(r,Q[h]),o=h-1)):Q[h]=0,i=l}i=Q[0]}return t.substring(o-r+1,o+1)},hE=()=>{const g=window.getSelection();if(!g||!g.rangeCount||g.type!=="Caret")return!1;const t=g.getRangeAt(0);let I=t.endContainer;for(;I&&I.nodeName!=="P";)I=I.parentNode;if(!I)return!1;const B=t.cloneRange();return B.setEndAfter(I),B.toString().length===0},dE=g=>{const t=window.getSelection();if(!t.rangeCount)return;const I=Array.from(g.querySelectorAll("p"));if(I.length===0)return;let B=!1;for(const Q of I)if(Q.contains(t.anchorNode)){B=!0;break}if(!B){const Q=document.createRange(),i=I[I.length-1];Q.selectNodeContents(i),Q.collapse(!1),t.removeAllRanges(),t.addRange(Q)}},wE=(g,t)=>{if(!g)return;for(;g.firstChild;)g.removeChild(g.firstChild);g.appendChild(document.createElement("br"));const I=document.createRange();I.selectNodeContents(g),I.collapse(!1),t.removeAllRanges(),t.addRange(I)},$I=(g,t,I=0)=>{if(!g||!t)return{top:0,left:0,width:0,height:0};const B=g,Q=t,i=Q.bottom-B.top+I,r=Q.left-B.left;return{top:i,left:r,width:Q.width,height:Q.height}},uE=g=>{const t=Array.from(document.querySelectorAll(`span[data-frag-id="anchor_${g.id}"]`));return g.uid?t.filter(I=>I.dataset.uid===g.uid):t.filter(I=>!I.dataset.uid)};function DE(g,t,I){if(!(g instanceof HTMLElement))return console.error("parentNode 必须是有效的 DOM 元素"),0;if(t.trim()==="")return console.error("targetAttr 必须是有效的字符串"),0;const B=Array.from(g.children);let Q=0;return B.forEach(i=>{i.hasAttribute(t)&&(g.removeChild(i),Q++)}),Q}function fE(g,t){if(!(g instanceof HTMLElement))return console.error("传入的 node 必须是有效的 DOM 元素"),"";if(typeof t!="string"||t.trim()==="")return console.error("targetAttr 必须是非空字符串"),"";if(g.getAttribute("data-type")!==t)return"";function I(Q){let i="";return Array.from(Q.childNodes).forEach(r=>{var o;switch(r.nodeType){case Node.TEXT_NODE:i+=`${((o=r.textContent)==null?void 0:o.trim())??""} `;break;case Node.ELEMENT_NODE:i+=I(r);break}}),i}return I(g).replace(/\s+/g," ").trim()}function AC(g){return n.getCurrentScope()?(n.onScopeDispose(g),!0):!1}const Yt=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const yE=Object.prototype.toString,pE=g=>yE.call(g)==="[object Object]",NI=()=>{};function RE(g){let t;function I(){return t||(t=g()),t}return I.reset=async()=>{const B=t;t=void 0,B&&await B},I}function et(g){return Array.isArray(g)?g:[g]}function kE(g,t,I={}){const{immediate:B=!0,immediateCallback:Q=!1}=I,i=n.shallowRef(!1);let r=null;function o(){r&&(clearTimeout(r),r=null)}function a(){i.value=!1,o()}function h(...l){Q&&g(),o(),i.value=!0,r=setTimeout(()=>{i.value=!1,r=null,g(...l)},n.toValue(t))}return B&&(i.value=!0,Yt&&h()),AC(a),{isPending:n.readonly(i),start:h,stop:a}}function ug(g=!1,t={}){const{truthyValue:I=!0,falsyValue:B=!1}=t,Q=n.isRef(g),i=n.shallowRef(g);function r(o){if(arguments.length)return i.value=o,i.value;{const a=n.toValue(I);return i.value=i.value===a?n.toValue(B):a,i.value}}return Q?r:[i,r]}function NE(g,t,I){return n.watch(g,t,{...I,immediate:!0})}const eC=Yt?window:void 0,gC=Yt?window.navigator:void 0;function FE(g){var t;const I=n.toValue(g);return(t=I==null?void 0:I.$el)!=null?t:I}function Fe(...g){const t=[],I=()=>{t.forEach(o=>o()),t.length=0},B=(o,a,h,l)=>(o.addEventListener(a,h,l),()=>o.removeEventListener(a,h,l)),Q=n.computed(()=>{const o=et(n.toValue(g[0])).filter(a=>a!=null);return o.every(a=>typeof a!="string")?o:void 0}),i=NE(()=>{var o,a;return[(a=(o=Q.value)==null?void 0:o.map(h=>FE(h)))!=null?a:[eC].filter(h=>h!=null),et(n.toValue(Q.value?g[1]:g[0])),et(n.unref(Q.value?g[2]:g[1])),n.toValue(Q.value?g[3]:g[2])]},([o,a,h,l])=>{if(I(),!(o!=null&&o.length)||!(a!=null&&a.length)||!(h!=null&&h.length))return;const p=pE(l)?{...l}:l;t.push(...o.flatMap(f=>a.flatMap(y=>h.map(w=>B(f,y,w,p)))))},{flush:"post"}),r=()=>{i(),I()};return AC(I),r}function SE(){const g=n.shallowRef(!1),t=n.getCurrentInstance();return t&&n.onMounted(()=>{g.value=!0},t),g}function tC(g){const t=SE();return n.computed(()=>(t.value,!!g()))}function FI(g,t={}){const{controls:I=!1,navigator:B=gC}=t,Q=tC(()=>B&&"permissions"in B),i=n.shallowRef(),r=typeof g=="string"?{name:g}:g,o=n.shallowRef(),a=()=>{var l,p;o.value=(p=(l=i.value)==null?void 0:l.state)!=null?p:"prompt"};Fe(i,"change",a,{passive:!0});const h=RE(async()=>{if(Q.value){if(!i.value)try{i.value=await B.permissions.query(r)}catch{i.value=void 0}finally{a()}if(I)return n.toRaw(i.value)}});return h(),I?{state:o,isSupported:Q,query:h}:o}function LE(g={}){const{navigator:t=gC,read:I=!1,source:B,copiedDuring:Q=1500,legacy:i=!1}=g,r=tC(()=>t&&"clipboard"in t),o=FI("clipboard-read"),a=FI("clipboard-write"),h=n.computed(()=>r.value||i),l=n.shallowRef(""),p=n.shallowRef(!1),f=kE(()=>p.value=!1,Q,{immediate:!1});async function y(){let F=!(r.value&&L(o.value));if(!F)try{l.value=await t.clipboard.readText()}catch{F=!0}F&&(l.value=k())}h.value&&I&&Fe(["copy","cut"],y,{passive:!0});async function w(F=n.toValue(B)){if(h.value&&F!=null){let m=!(r.value&&L(a.value));if(!m)try{await t.clipboard.writeText(F)}catch{m=!0}m&&R(F),l.value=F,p.value=!0,f.start()}}function R(F){const m=document.createElement("textarea");m.value=F??"",m.style.position="absolute",m.style.opacity="0",document.body.appendChild(m),m.select(),document.execCommand("copy"),m.remove()}function k(){var F,m,J;return(J=(m=(F=document==null?void 0:document.getSelection)==null?void 0:F.call(document))==null?void 0:m.toString())!=null?J:""}function L(F){return F==="granted"||F==="prompt"}return{isSupported:h,text:l,copied:p,copy:w}}const GE={page:g=>[g.pageX,g.pageY],client:g=>[g.clientX,g.clientY],screen:g=>[g.screenX,g.screenY],movement:g=>g instanceof MouseEvent?[g.movementX,g.movementY]:null};function Mg(g={}){const{type:t="page",touch:I=!0,resetOnTouchEnds:B=!1,initialValue:Q={x:0,y:0},window:i=eC,target:r=i,scroll:o=!0,eventFilter:a}=g;let h=null,l=0,p=0;const f=n.shallowRef(Q.x),y=n.shallowRef(Q.y),w=n.shallowRef(null),R=typeof t=="function"?t:GE[t],k=Y=>{const q=R(Y);h=Y,q&&([f.value,y.value]=q,w.value="mouse"),i&&(l=i.scrollX,p=i.scrollY)},L=Y=>{if(Y.touches.length>0){const q=R(Y.touches[0]);q&&([f.value,y.value]=q,w.value="touch")}},F=()=>{if(!h||!i)return;const Y=R(h);h instanceof MouseEvent&&Y&&(f.value=Y[0]+i.scrollX-l,y.value=Y[1]+i.scrollY-p)},m=()=>{f.value=Q.x,y.value=Q.y},J=a?Y=>a(()=>k(Y),{}):Y=>k(Y),P=a?Y=>a(()=>L(Y),{}):Y=>L(Y),z=a?()=>a(()=>F(),{}):()=>F();if(r){const Y={passive:!0};Fe(r,["mousemove","dragover"],J,Y),I&&t!=="movement"&&(Fe(r,["touchstart","touchmove"],P,Y),B&&Fe(r,"touchend",m,Y)),o&&t==="page"&&Fe(i,"scroll",z,Y)}return{x:f,y,sourceType:w}}const mE=["onClick"],ME=n.defineComponent({__name:"pausationor",props:{visible:{type:Boolean}},emits:["ok"],setup(g,{emit:t}){const I=g,B=t,[Q]=ZA("pausation-tag-selector"),i=[{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(r,o)=>n.withDirectives((n.openBlock(),n.createElementBlock("ul",{class:n.normalizeClass(n.unref(Q)()),contenteditable:"false",onClick:o[0]||(o[0]=n.withModifiers(()=>{},["stop"]))},[(n.openBlock(),n.createElementBlock(n.Fragment,null,n.renderList(i,(a,h)=>n.createElementVNode("li",{key:h,class:n.normalizeClass(n.unref(Q)("item")),onClick:l=>B("ok",l,a.value)},n.toDisplayString(a.label),11,mE)),64))],2)),[[n.vShow,I.visible]])}}),mA=(g,t)=>{const I=g.__vccOpts||g;for(const[B,Q]of t)I[B]=Q;return I},IC=mA(ME,[["__scopeId","data-v-a957cba2"]]),UE=0,Se=K.pausation,[ft]=Ze(Se),CC=ft("close"),{x:JE,y:HE}=Mg(),YE=`<svg class="${CC}" 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">
69
69
  <g id="V1.0" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
70
70
  <g id="虚拟精品录音间-插入停顿" transform="translate(-1287, -152)" fill="currentColor" fill-rule="nonzero">
71
71
  <g id="编组-4备份-4" transform="translate(1227, 149)">