@chenyomi/leafer-htmltext-edit 2.4.3 → 2.4.6

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.cjs CHANGED
@@ -1,5 +1,5 @@
1
- 'use strict';var editor=require('@leafer-in/editor'),core=require('@leafer-ui/core'),L=require('crypto-js'),html=require('@leafer-in/html'),C=require('quill');require('quill/dist/quill.core.css');var font=require('quill/formats/font');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var L__default=/*#__PURE__*/_interopDefault(L);var C__default=/*#__PURE__*/_interopDefault(C);var E=(t,i,e,n)=>{for(var a=i,s=t.length-1,o;s>=0;s--)(o=t[s])&&(a=(o(a))||a);return a};function W(t){let n=new DOMParser().parseFromString(t,"text/html").body;function a(r){if(r.nodeType===Node.TEXT_NODE){let l=r.textContent;return l?Array.from(l).map(u=>document.createTextNode(u)):[]}else if(r.nodeType===Node.ELEMENT_NODE){let l=[];for(let c of Array.from(r.childNodes))a(c).forEach((p,m)=>{let g=r.cloneNode(false);g.appendChild(p),l.push(g);});return l}return []}let s=[];for(let r of Array.from(n.childNodes)){let l=a(r);s.push(...l);}let o=document.createElement("div");return s.forEach((r,l)=>{o.appendChild(r);}),o.innerHTML}var Y="LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxaUFnU1hWM3dMKzh2YkZ2OVkwQwpEN1dBUjhPa2I4bjlmTWxpQjF3enZodTBrdVdZUWEvMUxvVDhHWVh6WWlRQVFBRk9zTTA0MGp2dlNRT2hRSWpiCjRaYXZ1NHUvWVA5bElPYjFKYnZnYkFoYVVOQnphL0l2UmFnaFlKYTJBc1cyRVhnZkVrdmMyUENNMS9zbVlFNnoKNjZiUmx1dnREK3FJZkpLVCtUUXJRRmp5TnNTZ0c2Z2R4MThrZTRMSStBejFPcklMbUsyMHlBU2tlRXpYT1BTVAplM3RNYThleHpZdmUzV0wyNHRHUHg5WHNvN1JyUEl1elZlajh0NDYrZ0c1Y0pQaVh0N1lqa0V2NEJOUUt5eUpoCkltOVRJdVZ6clFpa2NJNE14dExNSGdUMHpLcU9ZZ1NzcmEvTHNDd2ZOdzdtYWxITkU2c21YZWYyQ2E5RGhZODQKS1FJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==";function lt(t){let i=t.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");return K(i)}function K(t){let i=atob(t),e=new Uint8Array(i.length);for(let n=0;n<i.length;n++)e[n]=i.charCodeAt(n);return e.buffer}async function ct(){let t=atob(Y),i=lt(t);return await crypto.subtle.importKey("spki",i,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},false,["verify"])}async function Q(t,i){try{let e=await ct(),n=new TextEncoder().encode(t),a=K(i);return await crypto.subtle.verify("RSASSA-PKCS1-v1_5",e,a,n)}catch{return false}}var j="c19496eb17719960b6c3cebab0ef5eddfce5d0315ab8c5af86a52fbda434fea9",J="ce1e3e8974f1392b3c5803b34ecf659f";function X(t){try{let i=L__default.default.enc.Hex.parse(j),e=L__default.default.enc.Hex.parse(J),a=L__default.default.AES.decrypt(t,i,{iv:e,mode:L__default.default.mode.CBC,padding:L__default.default.pad.Pkcs7}).toString(L__default.default.enc.Utf8);if(!a)throw new Error("Decryption resulted in empty string - invalid ciphertext or wrong key");return a}catch(i){throw i}}async function dt(t){try{let i=atob(t),e=JSON.parse(i);if(!e.data||!e.signature||!await Q(e.data,e.signature))return null;let a=e.data;if(e.encrypted)try{a=X(e.data);}catch{return null}return JSON.parse(a)}catch{return null}}function ut(t){if(!t||t.length===0)return true;let i=window.location.hostname;if(i==="localhost"||i==="127.0.0.1")return true;let e=t.some(n=>{if(n.startsWith("*.")){let a=n.slice(2);return i.endsWith(a)}return i===n});return e}function pt(t){if(!t)return true;try{let i=new Date(t),e=new Date;return e>=i?!1:(Math.ceil((i.getTime()-e.getTime())/(1e3*60*60*24))<=7,!0)}catch{return false}}function ft(t){if(!t)return true;try{return !(new Date(t)>new Date)}catch{return true}}async function k(t){try{let i=await dt(t);return i?ft(i.issueDate)?ut(i.domains)?pt(i.expireDate)?{valid:!0,data:i}:{valid:!1,error:"License has expired",data:i}:{valid:!1,error:`License not valid for domain: ${window.location.hostname}`,data:i}:{valid:!1,error:"Invalid license issue date",data:i}:{valid:!1,error:"Invalid license key or signature verification failed"}}catch{return {valid:false,error:"ERR"}}}var M=null,H=null,b=0;async function ht(t){let i=await k(t);return i.valid&&i.data?(M=t,H=i.data,b=1,true):(M=null,H=null,b=0,false)}async function P(){return !M||!b?0:(b=(await k(M)).valid?1:0,b||(H=null),b)}function $(){return b?H:null}var G=t=>{let i=Number(t?.data?.__innerEditorZoomScale);return Number.isFinite(i)&&i>0?i:1},F=(t,i,e)=>{if(!t)return;let s=`${(Number(i)||0)*(Number.isFinite(e)&&e>0?e:1)}px`;t.style.letterSpacing=s;let o=t.querySelector(".ql-editor");o&&(o.style.letterSpacing=s,o.querySelectorAll("p, li, ol, ul").forEach(r=>{r.style.letterSpacing=s;}));},v=t=>{if(!t?.worldTransform)return 1;let{scaleX:i,scaleY:e}=t.worldTransform,n=Math.max(Math.abs(typeof t.scaleX=="number"?t.scaleX:1),Math.abs(typeof t.scaleY=="number"?t.scaleY:1));return Math.max(Math.abs(i),Math.abs(e))/(n||1)},tt=t=>{switch(t){case "center":return "center";case "end":return "flex-end";default:return "flex-start"}},V=(t,i,e)=>{if(!t)return;let n=t.querySelector(".ql-editor");n&&(e?(n.style.display="flex",n.style.flexDirection="column",n.style.height="100%",n.style.justifyContent=tt(i)):(n.style.display="",n.style.flexDirection="",n.style.height="",n.style.justifyContent=""));},f=async(t,i,e)=>{if(!(!t||!t.parent)&&(t.data||(t.data={}),!t.data.__syncingInnerHTMLText)){t.data.__syncingInnerHTMLText=true;try{let n=G(t),a=document.querySelector("#textInnerEditor"),s=!!t?.parent?.children?.[0]?.tag?.includes?.("Shape");a&&t.data.textData?.fontSize&&(a.style.fontSize=`${t.data.textData.fontSize*n}px`),a&&t.data.textData?.lineHeight&&(a.style.lineHeight=t.data.textData.lineHeight),F(a,t.data.textData?.letterSpacing,n),a&&t.data.textData?.textShadow?a.style.textShadow=t.data.textData.textShadow:a&&(a.style.textShadow="none"),a&&t.data.textData?.textStroke?(a.style.paintOrder="stroke fill",a.style.webkitTextStroke=gt(t.data.textData.textStroke,n)):a&&(a.style.paintOrder="unset",a.style.webkitTextStroke="unset"),V(a,t.data.textData?.alignContent,s||!!t.data.canChangeBox);let r=d.getQuill().getSemanticHTML();if(r==="<p></p>"){t.text.includes("<style>@font-face")?t.text=t.text.split("</style>")[0]+"</style>":t.text="";return}if(t.text.includes("<style>@font-face")){let l=t.text.split("</style>")[0];if(e&&!l.includes(e)){let c=`@font-face {font-family: ${e.split(",")[0]};src: url(${i}) format('woff2') }</style>`;t.text=l+c+q(t,r,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent,t.data.textData.textStroke);}else t.text=l+"</style>"+q(t,r,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent,t.data.textData.textStroke);}else if(i&&e){let l=`<style>@font-face {font-family: ${e.split(",")[0]};src: url(${i}) format('woff2') }</style>`;t.text=l+q(t,r,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent,t.data.textData.textStroke);}else t.text=q(t,r,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent,t.data.textData.textStroke);}finally{t?.data&&(t.data.__syncingInnerHTMLText=false);}}},q=(t,i,e=20.67,n=1.5,a=0,s="none",o="start",r="unset")=>{let l=G(t),c=!!t?.parent?.children?.[0]?.tag?.includes?.("Shape"),u=t?.data?.textData?.fontFamily||"",p=u.replace(/"/g,"").trim(),m=document.createElement("div");m.innerHTML=i;let g={fontSize:`${e}px`,lineHeight:n,letterSpacing:`${a}px`,textShadow:s};r!=="unset"?(g.paintOrder="stroke fill",g.WebkitTextStroke=r):(g.paintOrder="unset",g.WebkitTextStroke="unset"),c&&u&&(g.fontFamily=u),m.querySelectorAll("p,ol,ul").forEach(_=>{Object.assign(_.style,g);});let h=m.innerHTML;/<p\b[^>]*><\/p>/.test(h)&&(h=h.replace(/<p\b([^>]*)><\/p>/g,"<p$1>&nbsp;</p>")),/&quot;/.test(h)&&(h=h.replace(/&quot;/g,""));let y=d.getQuill(),D=Number((y.scroll.domNode.scrollHeight/l).toFixed(0)),x=Number(D||t.__layout.boxBounds.height||0),z=Number(t.parent?.height??0),T=t.data.canChangeBox?Math.max(z,x):x,w=`<style>p{margin:0;}sub,sup{font-size:63%;}.ql-ui{position:absolute}ol,ul{counter-reset:list-0;padding-left:1.5em;margin:0}ol>li,ul>li{counter-increment:list-0;list-style-type:none;position:relative;padding-left:0;margin:0}ol>li::before{content:counter(list-0,decimal) '. ';position:absolute;left:-1.5em;width:1.2em;text-align:right}ul>li::before{content:'\u2022';position:absolute;left:-1.5em;width:1.2em;text-align:right}li[data-list]{counter-set:list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-align-center{text-align:center}.ql-align-right{text-align:right}.ql-align-left{text-align:left}.ql-align-justify{text-align:justify}*{font-variant-ligatures:none;font-feature-settings:"liga" 0,"clig" 0;}em{font-style:oblique;}strong{font-weight:bolder;}</style>`,S="";if(t.parent.children[0].tag.includes("Shape")){let _=p?`font-family:${p};`:"";S=w+`<div style="width: ${t.parent.width}px;height: ${t.parent.height}px;overflow-wrap:break-word;word-break:break-all;display:flex;flex-direction:column;justify-content:center;${_}">${h}</div>`;}else t.data.canChangeBox?S=w+`<div style="width: ${t.parent.width}px;height:${T}px;overflow-wrap:break-word;word-break:break-all;display:flex;flex-direction:column;justify-content:${tt(o)};">${h}</div>`:t.data.textData.italic?S=w+h:S=w+`<div style="overflow-wrap:break-word;word-break:break-all;">${h}</div>`;return S},ae=(t,i,e)=>{let n=d.getQuill(),{editor:a,canvas:s}=d.getCanvas();if(!n)return;i===0&&(i="0");let o=d.getSelection();d.dateEdit(async r=>{if(r.tag==="HTMLText")if(t==="font")a.innerEditing?(o&&o.length?n.formatText(o.index,o.length,t,i):n.formatText(0,n.getLength()-1,t,i),r.data.textData.fontFamily=i,f(r,e??null,i??null)):(d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),n.formatText(0,n.getLength()-1,t,i),r.data.textData.fontFamily=i,f(r,e??null,i??null));else if(t==="fontSize"){r.data.textData[t]=i;let l=Number(r.scaleX??1),c=Number(r.scaleY??1);Number.isFinite(l)&&Math.abs(l-1)>1e-4&&(r.scaleX=1),Number.isFinite(c)&&Math.abs(c-1)>1e-4&&(r.scaleY=1),d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),f(r,e??null);}else if(t==="textCase"){if(a.innerEditing){if(!o||!o.length)return;let l=n.getText(o.index,o.length),c=n.getFormat(o.index,o.length);n.deleteText(o.index,o.length);let u;l===l.toUpperCase()&&/[A-Z]/.test(l)?u=l.toLowerCase():(l===l.toLowerCase()&&/[a-z]/.test(l),u=l.toUpperCase()),n.insertText(o.index,u,c),o&&a.innerEditing&&n.setSelection(o.index,o.length);}}else if(t==="script"){let l="sub";i==="super"&&(l="sup"),a.innerEditing?o&&o.length?n.formatText(o.index,o.length,t,n.getFormat(o).script===i?false:l):n.formatText(0,n.getLength()-1,t,n.getFormat().script===i?false:l):(d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),n.formatText(0,n.getLength()-1,t,n.getFormat().script===i?false:l),f(r));}else if(t==="align")d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),a.innerEditing?n.format(t,i):n.formatLine(0,n.getLength(),t,i),f(r);else if(t==="alignContent")d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=i,f(r);else if(t==="lineHeight"||t==="letterSpacing")d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=i,f(r);else if(t==="color")d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),o&&o.length?n.formatText(o.index,o.length,t,i):n.formatText(0,n.getLength()-1,t,i),r.tag==="HTMLText"?f(r):r.parent.findOne("HTMLText")&&f(r.parent.findOne("HTMLText"));else if(t==="textShadow"||t==="textStroke")d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=i,f(r);else if(t==="list"){if(d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),a.innerEditing){let[l]=n.getLine(o?.index||0);l.formats().list?n.format(t,false):n.format(t,i);}else {let[l]=n.getLine(o?.index||0);l.formats().list?n.formatLine(0,n.getLength(),t,false):n.formatLine(0,n.getLength(),t,i);}f(r);}else if(t==="textVertical"){let l=$();if(l&&l?.features?.length&&l?.features?.includes("textVertical")){n.clipboard.dangerouslyPasteHTML(r.text);let c=n.getSemanticHTML();n.clipboard.dangerouslyPasteHTML(W(c)),r.data.textData.align="center",f(r);}}else a.innerEditing?o&&o.length?n.formatText(o.index,o.length,t,i===void 0?!n.getFormat(o)[t]:i):n.formatText(0,n.getLength()-1,t,i===void 0?!n.getFormat()[t]:i):(d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),n.formatText(0,n.getLength()-1,t,i===void 0?!n.getFormat()[t]:i),f(r));},1);};function gt(t,i){return t.replace(/(-?\d*\.?\d+)px/g,(e,n)=>Number(n)*i+"px")}function St(t,i){return i===0?1/0:330*t*72/96/Math.abs(i)}var R=(t,i)=>{let e=t.findOne("Box");e&&t.remove(e);let n=t.findOne("HTMLText"),{boxBounds:a,x:s,y:o}=n,{width:r}=a;if(!n.curveAmount){n.opacity=1,n.visible=true;return}n.text=n.text.replace(/\u200B/g,"").replace(/<br\s*\/?>/gi,`
2
- `),n.opacity=0;let l=St(n.fontSize,n.curveAmount),c=2*Math.PI*l,u=n.text.length+2,p=r/u,m=0;c>p*n.text.length&&(m=(c-p*n.text.length)/2);let g=m*360/c,h=new core.Box({x:0,y:0,editable:false,resizeChildren:true}),y,D=n.fontSize*n.lineHeight.value||0,x=n.curveAmount>0?l+D:-l;if(n.curveAmount>0)y=`G ${s+r/2} ${x} ${l} ${l} 90 ${g} ${360-g} 0`;else {let T=180-g;y=`G ${s+r/2} ${x} ${l} ${l} 90 ${T} ${-T} 1`;}let z=new core.Path({x:0,y:0,motionPath:true,editable:false,path:y});h.add(z),h.set({opacity:i?.2:1}),Array.from(n.text).forEach((T,w)=>{let S=new html.HTMLText({text:T,around:n.curveAmount>0?"bottom":"top",fontSize:n.fontSize,fontFamily:n.fontFamily,fontWeight:n.fontWeight,motion:w*p+p/2,textDecoration:n.textDecoration,textCase:n.textCase,textAlign:n.textAlign,motionRotation:n.curveAmount>0?3:-2,fill:n.fill});h.add(S);}),t.add(h);},I={0:"\u2070",1:"\xB9",2:"\xB2",3:"\xB3",4:"\u2074",5:"\u2075",6:"\u2076",7:"\u2077",8:"\u2078",9:"\u2079",a:"\u1D43",b:"\u1D47",c:"\u1D9C",d:"\u1D48",e:"\u1D49",f:"\u1DA0",g:"\u1D4D",h:"\u02B0",i:"\u2071",j:"\u02B2",k:"\u1D4F",l:"\u02E1",m:"\u1D50",n:"\u207F",o:"\u1D52",p:"\u1D56",r:"\u02B3",s:"\u02E2",t:"\u1D57",u:"\u1D58",v:"\u1D5B",w:"\u02B7",x:"\u02E3",y:"\u02B8",z:"\u1DBB",A:"\u1D2C",B:"\u1D2E",D:"\u1D30",E:"\u1D31",G:"\u1D33",H:"\u1D34",I:"\u1D35",J:"\u1D36",K:"\u1D37",L:"\u1D38",M:"\u1D39",N:"\u1D3A",O:"\u1D3C",P:"\u1D3E",R:"\u1D3F",T:"\u1D40",U:"\u1D41",W:"\u1D42","+":"\u207A","-":"\u207B","=":"\u207C","(":"\u207D",")":"\u207E"},B={0:"\u2080",1:"\u2081",2:"\u2082",3:"\u2083",4:"\u2084",5:"\u2085",6:"\u2086",7:"\u2087",8:"\u2088",9:"\u2089",a:"\u2090",e:"\u2091",h:"\u2095",i:"\u1D62",j:"\u2C7C",k:"\u2096",l:"\u2097",m:"\u2098",n:"\u2099",o:"\u2092",p:"\u209A",r:"\u1D63",s:"\u209B",t:"\u209C",u:"\u1D64",v:"\u1D65",x:"\u2093","+":"\u208A","-":"\u208B","=":"\u208C","(":"\u208D",")":"\u208E",\u03B2:"\u1D66",\u03B3:"\u1D67",\u03C1:"\u1D68",\u03C6:"\u1D69",\u03C7:"\u1D6A"};function et(t){let i={};for(let e in t)i[t[e]]=t[e];return i}et(I);et(B);var A=class extends editor.EditTool{constructor(e){super(e);this.quill=null;this.C=null;this.q=null;this.F=null;this.isUpdatingPoints=false;this.eventIds=[];}get tag(){return "TextEditTool"}syncResizeBaseline(e){e?.data||(e.data={}),e.data.baseSize={...e.data.baseSize||{},width:Number(e.parent?.width??e.data?.baseSize?.width??0),fontSize:Number(e.data?.textData?.fontSize??e.data?.baseSize?.fontSize??0)};}addEvent(){let e=this.editor.element?.findOne("HTMLText");if(!e||!e.worldTransform)return;this.syncResizeBaseline(e);let n=document.querySelector("#textInnerEditor"),{style:a}=n;this.eventIds=[this.editor.on_(core.DragEvent.START,s=>{s?.target?.pointType==="resize"&&this.syncResizeBaseline(e);}),this.editor.on_(editor.EditorScaleEvent.SCALE,()=>{if(e.data.canChangeBox||(e.data.canChangeBox=true),e.data.canChangeBox){let s=v(e);a.width=e.parent.width*s+"px",a.height="auto",a.minHeight=e.parent.height*s+"px";}if(e.parent.tag==="Box"&&e.parent.lockRatio){let s=Number(e.data?.baseSize?.width??e.parent.width??0),o=Number(e.data?.baseSize?.fontSize??e.data?.textData?.fontSize??0);if(s>0&&o>0){let r=e.parent.width/s;e.data.textData.fontSize=Number((o*r).toFixed(2)),this.C===null&&(this.C=requestAnimationFrame(()=>{this.C=null;let l=Number(e.data?.baseSize?.width??0);if(l>0){let c=Number((e.parent.width/l).toFixed(4));e.scaleX=c,e.scaleY=c;}}));}}}),this.editor.on_(core.DragEvent.END,s=>{s?.target?.pointType==="resize"&&(this.C!==null&&(cancelAnimationFrame(this.C),this.C=null),e.parent?.lockRatio?(e.scaleX=1,e.scaleY=1,f(e)):f(e),this.syncResizeBaseline(e));}),this.editor.on_(core.PointerEvent.DOUBLE_TAP,s=>{!e.parent.locked&&s.target.tag!=="Group"&&this.editor.openInnerEditor(e,true);})];}onLoad(){let e=this.editor.element?.findOne("HTMLText");if(!e||!e.worldTransform)return;this.syncResizeBaseline(e);let n=v(e);this.editor.element?.set({editConfig:{resizeable:!e.data.textData.curveAmount}}),this.addEvent(),this.editBox.add(this.view);let a=this.editor.element;this.q=a?.width??null,this.F=a?.height??null,this.quill=d.getQuill(),this.quill&&this.quill.clipboard.dangerouslyPasteHTML(e.text);let s=document.querySelector("#textInnerEditor"),{style:o}=s;e.data.canChangeBox?(o.width=e.parent.width*n+"px",o.height="auto",o.minHeight=e.parent.height*n+"px"):(o.width="auto",o.height="auto",o.minHeight="0px");}updateChangeBoxBound(e){e&&e.set({width:e.__layout.boxBounds.width,height:e.__layout.boxBounds.height});}onUpdate(){let e=this.editor.element;if(!e)return;let n=e.findOne("HTMLText");if(!(!n||!n.data?.textData?.curveAmount)&&!this.isUpdatingPoints&&(e.name==="Text"&&e.tag==="Box"||e.name==="Text"&&e.tag==="Group")){if(e.app?.editor?.isUndoRedo){setTimeout(()=>{e.app.editor.isUndoRedo=false;},100);return}let a=e.width,s=e.height;if(a===this.q&&s===this.F)return;this.q=a,this.F=s,this.isUpdatingPoints=true,R(e,false),setTimeout(()=>{this.isUpdatingPoints=false;},50);}}onUnload(){this.C!==null&&(cancelAnimationFrame(this.C),this.C=null),this.editor.off_(this.eventIds);}onDestroy(){}};A=E([editor.registerEditTool()],A);var it=new Set,At=t=>{if(!t||typeof document>"u")return;let i=t.match(/<style[^>]*>[\s\S]*?<\/style>/gi)||[];i.length&&i.forEach(e=>{(e.replace(/<style[^>]*>|<\/style>/gi,"").match(/@font-face\s*\{[\s\S]*?\}/gi)||[]).forEach(s=>{let o=s.trim();if(!o||it.has(o))return;let r=document.createElement("style");r.setAttribute("data-inner-editor-font-face","true"),r.textContent=o,document.head.appendChild(r),it.add(o);});});},N=class extends editor.InnerEditor{constructor(){super(...arguments);this.config={selectAll:false};this.eventIds=[];this.selectText=void 0;this.inBody=void 0;this.isHTMLText=void 0;this._=void 0;this.quill=null;this.isComposing=false;this.inputSyncFrame=null;this.quillRoot=null;this.handleCompositionStart=()=>{this.isComposing=true,this.inputSyncFrame!==null&&(cancelAnimationFrame(this.inputSyncFrame),this.inputSyncFrame=null);};this.handleCompositionEnd=()=>{this.isComposing=false,this.scheduleInputSync();};this.scheduleInputSync=()=>{this.inputSyncFrame!==null&&cancelAnimationFrame(this.inputSyncFrame),this.inputSyncFrame=requestAnimationFrame(()=>{this.inputSyncFrame=null,f(this.editTarget);});};this.onInput=async()=>{this.isComposing||this.scheduleInputSync();};this.onSelectionChange=e=>{d.setSelection(e);};this.isUpdatingPoints=false;}get tag(){return "TextEditor"}onLoad(){let{editor:e}=this,{config:n}=e.app,a=this.editTarget,s=v(a);a.data={...a.data||{},__innerEditorZoomScale:s},this.isHTMLText=!(a instanceof Text),this._=n.keyEvent,n.keyEvent=false;let o=this.editDom=document.querySelector("#textInnerEditor"),{style:r}=o;r.visibility="visible",r.pointerEvents="auto",r.userSelect="text",r.webkitUserSelect="text",r.zIndex="10001",r.caretColor=a.data.textData?.fill||"#111111",r.fontVariantLigatures="none",r.fontFeatureSettings='"liga" 0, "clig" 0';let c=!!a?.parent?.children?.[0]?.tag?.includes?.("Shape")||!!a.data?.canChangeBox;a.data.canChangeBox?(r.width=a.parent.width*s+"px",r.height=c?a.parent.height*s+"px":"auto",r.minHeight=a.parent.height*s+"px"):(r.width="auto",r.height="auto",r.minHeight="0px"),r.outline="1px solid #8499EF",a.data.textData.fontSize&&(o.style.fontSize=`${a.data.textData.fontSize*s}px`),a.data.textData.fontFamily&&(o.style.fontFamily=`${a.data.textData.fontFamily}`),a.data.textData.lineHeight?o.style.lineHeight=a.data.textData.lineHeight:o.style.lineHeight="1.5",F(o,a.data.textData.letterSpacing,s),a.data.textData.textShadow?o.style.textShadow=at(a.data.textData.textShadow,s):o.style.textShadow="none",a.data.textData.textStroke?(o.style.paintOrder="stroke fill",o.style.WebkitTextStroke=at(a.data.textData.textStroke,s)):(o.style.paintOrder="unset",o.style.WebkitTextStroke="unset"),V(o,a.data.textData.alignContent,c),this.quill=d.getQuill(),this.quillRoot=this.quill?.root,this.quillRoot&&(this.quillRoot.contentEditable="true",this.quillRoot.tabIndex=0,this.quillRoot.style.pointerEvents="auto",this.quillRoot.style.userSelect="text",this.quillRoot.style.webkitUserSelect="text",this.quillRoot.style.outline="none",this.quillRoot.style.fontVariantLigatures="none",this.quillRoot.style.fontFeatureSettings='"liga" 0, "clig" 0',this.quillRoot.addEventListener("compositionstart",this.handleCompositionStart),this.quillRoot.addEventListener("compositionend",this.handleCompositionEnd)),At(a.text),this.quill.clipboard.dangerouslyPasteHTML(a.text),F(o,a.data.textData.letterSpacing,s),a?.parent?.children?.length&&a.parent.children[0].tag.includes("Shape")&&this.quill.formatLine(0,this.quill.getLength(),"align","center"),this.quill.setSelection(0,this.quill.getLength()-1),this.quill.focus(),requestAnimationFrame(()=>{this.quill&&(this.quill.focus(),this.quill.getSelection()||this.quill.setSelection(0,this.quill.getLength()-1));}),this.quill.on("text-change",this.onInput),this.quill.on("selection-change",this.onSelectionChange),d.clearSelection(),this.eventIds=[e.app.on_(core.PointerEvent.DOWN,u=>{if(this.eventIds===void 0)return;let{target:p}=u.origin,m=false;for(;p;)p===o&&(m=true),p=p.parentElement;m||(e.closeInnerEditor(),e.cancel());})];}onUpdate(){let{editTarget:e}=this,{scaleX:n,scaleY:a}=e.worldTransform,s=Math.max(Math.abs(n),Math.abs(a)),o=v(e);e.data={...e.data||{},__innerEditorZoomScale:o};let{width:r,height:l}=e.parent.__local;r*=o,l*=o;let{x:c,y:u}=this.inBody?e.app.clientBounds:e.app.tree.clientBounds,{a:p,b:m,c:g,d:h,e:y,f:D}=new core.Matrix(e.worldTransform).scale(1/(s||1)).translateInner(0,0),{style:x}=this.editDom;if(x.transform=`matrix(${p},${m},${g},${h},${y},${D})`,x.left=c+"px",x.top=u+"px",e.parent.name=="Text"&&e.parent.tag=="Box"||e.parent.name=="Text"&&e.parent.tag=="Group"){if(this.isUpdatingPoints)return;this.isUpdatingPoints=true,R(e.parent,true),setTimeout(()=>{this.isUpdatingPoints=false;},50);}e.set({visible:false});}onUnload(){let{editTarget:e,editor:n,editDom:a}=this;if(e&&(this.inputSyncFrame!==null&&(cancelAnimationFrame(this.inputSyncFrame),this.inputSyncFrame=null),this.isComposing=false,f(e),n.app&&(n.app.config.keyEvent=this._),n.off_(this.eventIds),this.editDom.style.visibility="hidden",this.eventIds=void 0),e.parent&&e.parent.name=="Text"&&e.parent.children.some(s=>s.tag==="Box")){let s=e.parent.find("Box"),o=s?.at(-1);o&&s.length>1&&o.name!=="Text"&&(o.opacity=1,e.visible=false);}else e.set({visible:true});this.quill.getLength()===1&&e.parent.name==="Text"&&e.parent.remove(),e?.parent?.children?.length&&e.parent.children[0].tag.includes("Shape")&&this.quill.getContents().ops.length===1&&e.remove(),e.data&&"__innerEditorZoomScale"in e.data&&delete e.data.__innerEditorZoomScale,this.quillRoot&&(this.quillRoot.removeEventListener("compositionstart",this.handleCompositionStart),this.quillRoot.removeEventListener("compositionend",this.handleCompositionEnd),this.quillRoot=null),this.quill.off("text-change",this.onInput),this.quill.off("selection-change",this.onSelectionChange),d.clearSelection();}};N=E([editor.registerInnerEditor()],N);function at(t,i){return t.replace(/(-?\d*\.?\d+)px/g,(e,n)=>Number(n)*i+"px")}function O(t,{insertAt:i}={}){if(typeof document>"u")return;let e=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",i==="top"&&e.firstChild?e.insertBefore(n,e.firstChild):e.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t));}O(`.ql-editor{padding:0!important;line-height:unset!important;overflow:unset!important;outline:0}.ql-container{font-family:unset!important}.ql-editor p{margin:0!important}.ql-editor sub,.ql-editor sup{font-size:63%}.ql-editor sup{top:-.58em}.ql-editor sub{bottom:-.38em}.ql-editor ol{padding-left:0!important}
3
- `);var Z=class t{constructor(){this.quill=null;this.app_=null;this.S=0;this.selectionRange=null;}static getInstance(){return t.instance||(t.instance=new t),t.instance}async init(i){if(this.S=await P(),this.app_=this.S?i:null,this.quill)return this.quill;let e=document.getElementById("textInnerEditor");if(e)this.quill=this.app_?.editor?.quill||null;else return e=document.createElement("div"),e.id="textInnerEditor",e.style.position="fixed",e.style.transformOrigin="left top",e.style.overflowWrap="break-word",e.style.wordBreak="break-all",e.style.visibility="hidden",document.body.appendChild(e),this.quill=new C__default.default("#textInnerEditor",{theme:void 0,modules:{toolbar:false,keyboard:{bindings:{enter:{key:"Enter",handler:n=>{if(!this.S)return true;let[a]=this.quill.getLine(n.index),s=C__default.default.import("blots/block");if(!s?.bubbleFormats)return true;let o=s.bubbleFormats(a),r=new C.Delta().retain(n.index).delete(n.length).insert(`
4
- `,o);return this.quill.updateContents(r,C__default.default.sources.USER),this.quill.setSelection(n.index+1,C__default.default.sources.SILENT),false}}}}}}),this.app_?.editor&&(this.app_.editor.quill=this.quill),this.registerFonts(),this.quill}getQuill(){return this.S?this.quill:null}getCanvas(){return this.S?this.app_:null}getSelection(){return this.S?this.selectionRange?this.selectionRange:this.quill?.getSelection()||this.quill?.selection?.savedRange||null:null}setSelection(i){this.selectionRange=i;}clearSelection(){this.selectionRange=null;}registerFonts(){this.S&&(font.FontStyle.whitelist=void 0,C__default.default.register("formats/font",font.FontStyle,true));}isMultiSelect(){return !this.S||!this.app_?.editor?false:this.app_.editor.multiple===true}dateEdit(i,e=0,n){let{editor:a}=this.app_||{};if(!a)return;let s=n||a.leafList?.list,o=r=>{e&&(r.tag==="Box"||r.name==="Text")?i(r.children?.[0]||r):i(r);};if(s?.length)if(Array.isArray(s)&&s.length>1){this.app_.lockLayout();let r=s.length*this.S;for(let l=0;l<r;l++)o(s[l]);this.app_.unlockLayout(),a.updateEditBox();}else this.S&&o(s[0]);}},d=Z.getInstance();exports.HtmlText=class U extends core.Box{get __tag(){return "HtmlText"}constructor(i){let{text:e,fontSize:n,fontFamily:a,lineHeight:s,letterSpacing:o,textShadow:r,alignContent:l,...c}=i||{};super({editOuter:"TextEditTool",name:"HtmlText",x:0,y:0,editable:true,draggable:true,overflow:"show",...c}),i&&this.createTextElement(i);}createTextElement(i){let{text:e,fontSize:n,fontFamily:a,lineHeight:s,letterSpacing:o,textShadow:r,alignContent:l}=i,c="<style>p{margin:0;}sub,sup{font-size:63%;}.ql-ui{position:absolute}ol,ul{counter-reset:list-0;padding-left:1.5em;margin:0}ol>li,ul>li{counter-increment:list-0;list-style-type:none;position:relative;padding-left:0;margin:0}ol>li::before{content:counter(list-0,decimal) '. ';position:absolute;left:-1.5em;width:1.2em;text-align:right}ul>li::before{content:'\u2022';position:absolute;left:-1.5em;width:1.2em;text-align:right}li[data-list]{counter-set:list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-align-center{text-align:center}.ql-align-right{text-align:right}.ql-align-left{text-align:left}.ql-align-justify{text-align:justify}</style>",u=`<div style="ove
5
- rflow-wrap:break-word;word-break:break-all;"><p style="font-size: ${n}px; line-height: ${s}; letter-spacing: ${o}px; text-shadow: ${r};"><strong>Hello World</strong></p></div>`;if(i.children?.length>0)return;let p=new html.HTMLText({name:"Text",text:c+(e||u),x:0,y:0,data:{canChangeBox:false,textData:{fontFamily:a,fontSize:n,lineHeight:s,letterSpacing:o||0,textShadow:r,alignContent:l}},editConfig:{selectedStyle:{strokeWidth:0}}});this.add(p);}};exports.HtmlText=E([core.registerUI()],exports.HtmlText);exports.checkLicense=P;exports.getHTMLTextZoomScale=v;exports.getLicenseInfo=$;exports.htmlTextManage=d;exports.setHTMLText=ae;exports.setLicense=ht;exports.syncInnerEditorLetterSpacing=F;exports.syncInnerEditorVerticalLayout=V;exports.updataHtmlText=f;
1
+ 'use strict';var editor=require('@leafer-in/editor'),core=require('@leafer-ui/core'),L=require('crypto-js'),html=require('@leafer-in/html'),M=require('quill');require('quill/dist/quill.core.css');var font=require('quill/formats/font');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var L__default=/*#__PURE__*/_interopDefault(L);var M__default=/*#__PURE__*/_interopDefault(M);var v=(e,i,t,n)=>{for(var a=i,s=e.length-1,r;s>=0;s--)(r=e[s])&&(a=(r(a))||a);return a};function at(e){let n=new DOMParser().parseFromString(e,"text/html").body;function a(o){if(o.nodeType===Node.TEXT_NODE){let l=o.textContent;return l?Array.from(l).map(d=>document.createTextNode(d)):[]}else if(o.nodeType===Node.ELEMENT_NODE){let l=[];for(let c of Array.from(o.childNodes))a(c).forEach((h,m)=>{let g=o.cloneNode(false);g.appendChild(h),l.push(g);});return l}return []}let s=[];for(let o of Array.from(n.childNodes)){let l=a(o);s.push(...l);}let r=document.createElement("div");return s.forEach((o,l)=>{r.appendChild(o);}),r.innerHTML}var rt="LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxaUFnU1hWM3dMKzh2YkZ2OVkwQwpEN1dBUjhPa2I4bjlmTWxpQjF3enZodTBrdVdZUWEvMUxvVDhHWVh6WWlRQVFBRk9zTTA0MGp2dlNRT2hRSWpiCjRaYXZ1NHUvWVA5bElPYjFKYnZnYkFoYVVOQnphL0l2UmFnaFlKYTJBc1cyRVhnZkVrdmMyUENNMS9zbVlFNnoKNjZiUmx1dnREK3FJZkpLVCtUUXJRRmp5TnNTZ0c2Z2R4MThrZTRMSStBejFPcklMbUsyMHlBU2tlRXpYT1BTVAplM3RNYThleHpZdmUzV0wyNHRHUHg5WHNvN1JyUEl1elZlajh0NDYrZ0c1Y0pQaVh0N1lqa0V2NEJOUUt5eUpoCkltOVRJdVZ6clFpa2NJNE14dExNSGdUMHpLcU9ZZ1NzcmEvTHNDd2ZOdzdtYWxITkU2c21YZWYyQ2E5RGhZODQKS1FJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==";function Et(e){let i=e.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");return ot(i)}function ot(e){let i=atob(e),t=new Uint8Array(i.length);for(let n=0;n<i.length;n++)t[n]=i.charCodeAt(n);return t.buffer}async function vt(){let e=atob(rt),i=Et(e);return await crypto.subtle.importKey("spki",i,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},false,["verify"])}async function st(e,i){try{let t=await vt(),n=new TextEncoder().encode(e),a=ot(i);return await crypto.subtle.verify("RSASSA-PKCS1-v1_5",t,a,n)}catch{return false}}var lt="c19496eb17719960b6c3cebab0ef5eddfce5d0315ab8c5af86a52fbda434fea9",ct="ce1e3e8974f1392b3c5803b34ecf659f";function dt(e){try{let i=L__default.default.enc.Hex.parse(lt),t=L__default.default.enc.Hex.parse(ct),a=L__default.default.AES.decrypt(e,i,{iv:t,mode:L__default.default.mode.CBC,padding:L__default.default.pad.Pkcs7}).toString(L__default.default.enc.Utf8);if(!a)throw new Error("Decryption resulted in empty string - invalid ciphertext or wrong key");return a}catch(i){throw i}}async function Lt(e){try{let i=atob(e),t=JSON.parse(i);if(!t.data||!t.signature||!await st(t.data,t.signature))return null;let a=t.data;if(t.encrypted)try{a=dt(t.data);}catch{return null}return JSON.parse(a)}catch{return null}}function Dt(e){if(!e||e.length===0)return true;let i=window.location.hostname;if(i==="localhost"||i==="127.0.0.1")return true;let t=e.some(n=>{if(n.startsWith("*.")){let a=n.slice(2);return i.endsWith(a)}return i===n});return t}function Mt(e){if(!e)return true;try{let i=new Date(e),t=new Date;return t>=i?!1:(Math.ceil((i.getTime()-t.getTime())/(1e3*60*60*24))<=7,!0)}catch{return false}}function Ht(e){if(!e)return true;try{return !(new Date(e)>new Date)}catch{return true}}async function Y(e){try{let i=await Lt(e);return i?Ht(i.issueDate)?Dt(i.domains)?Mt(i.expireDate)?{valid:!0,data:i}:{valid:!1,error:"License has expired",data:i}:{valid:!1,error:`License not valid for domain: ${window.location.hostname}`,data:i}:{valid:!1,error:"Invalid license issue date",data:i}:{valid:!1,error:"Invalid license key or signature verification failed"}}catch{return {valid:false,error:"ERR"}}}var I=null,B=null,T=0;async function Ct(e){let i=await Y(e);return i.valid&&i.data?(I=e,B=i.data,T=1,true):(I=null,B=null,T=0,false)}async function K(){return !I||!T?0:(T=(await Y(I)).valid?1:0,T||(B=null),T)}function Q(){return T?B:null}var ut=e=>{let i=Number(e?.data?.__innerEditorZoomScale);return Number.isFinite(i)&&i>0?i:1},k=(e,i,t)=>{if(!e)return;let s=`${(Number(i)||0)*(Number.isFinite(t)&&t>0?t:1)}px`;e.style.letterSpacing=s;let r=e.querySelector(".ql-editor");r&&(r.style.letterSpacing=s,r.querySelectorAll("p, li, ol, ul").forEach(o=>{o.style.letterSpacing=s;}));},D=e=>{if(!e?.worldTransform)return 1;let{scaleX:i,scaleY:t}=e.worldTransform,n=Math.max(Math.abs(typeof e.scaleX=="number"?e.scaleX:1),Math.abs(typeof e.scaleY=="number"?e.scaleY:1));return Math.max(Math.abs(i),Math.abs(t))/(n||1)},pt=e=>{switch(e){case "center":return "center";case "end":return "flex-end";default:return "flex-start"}},j=(e,i,t)=>{if(!e)return;let n=e.querySelector(".ql-editor");n&&(t?(n.style.display="flex",n.style.flexDirection="column",n.style.height="100%",n.style.justifyContent=pt(i)):(n.style.display="",n.style.flexDirection="",n.style.height="",n.style.justifyContent=""));},f=async(e,i,t)=>{if(!(!e||!e.parent)&&(e.data||(e.data={}),!e.data.__syncingInnerHTMLText)){e.data.__syncingInnerHTMLText=true;try{let n=ut(e),a=document.querySelector("#textInnerEditor"),s=!!e?.parent?.children?.[0]?.tag?.includes?.("Shape");a&&e.data.textData?.fontSize&&(a.style.fontSize=`${e.data.textData.fontSize*n}px`),a&&e.data.textData?.lineHeight&&(a.style.lineHeight=e.data.textData.lineHeight),k(a,e.data.textData?.letterSpacing,n),a&&e.data.textData?.textShadow?a.style.textShadow=e.data.textData.textShadow:a&&(a.style.textShadow="none"),a&&e.data.textData?.textStroke?(a.style.paintOrder="stroke fill",a.style.webkitTextStroke=Ft(e.data.textData.textStroke,n)):a&&(a.style.paintOrder="unset",a.style.webkitTextStroke="unset"),j(a,e.data.textData?.alignContent,s||!!e.data.canChangeBox);let o=u.getQuill().getSemanticHTML();if(o==="<p></p>"){e.text.includes("<style>@font-face")?e.text=e.text.split("</style>")[0]+"</style>":e.text="";return}if(e.text.includes("<style>@font-face")){let l=e.text.split("</style>")[0];if(t&&!l.includes(t)){let c=`@font-face {font-family: ${t.split(",")[0]};src: url(${i}) format('woff2') }</style>`;e.text=l+c+_(e,o,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent,e.data.textData.textStroke);}else e.text=l+"</style>"+_(e,o,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent,e.data.textData.textStroke);}else if(i&&t){let l=`<style>@font-face {font-family: ${t.split(",")[0]};src: url(${i}) format('woff2') }</style>`;e.text=l+_(e,o,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent,e.data.textData.textStroke);}else e.text=_(e,o,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent,e.data.textData.textStroke);}finally{e?.data&&(e.data.__syncingInnerHTMLText=false);}}},_=(e,i,t=20.67,n=1.5,a=0,s="none",r="start",o="unset")=>{let l=ut(e),c=!!e?.parent?.children?.[0]?.tag?.includes?.("Shape"),d=e?.data?.textData?.fontFamily||"",h=d.replace(/"/g,"").trim(),m=document.createElement("div");m.innerHTML=i;let g={fontSize:`${t}px`,lineHeight:n,letterSpacing:`${a}px`,textShadow:s};o!=="unset"?(g.paintOrder="stroke fill",g.WebkitTextStroke=o):(g.paintOrder="unset",g.WebkitTextStroke="unset"),c&&d&&(g.fontFamily=d),m.querySelectorAll("p,ol,ul").forEach(E=>{Object.assign(E.style,g);});let p=m.innerHTML;/<p\b[^>]*><\/p>/.test(p)&&(p=p.replace(/<p\b([^>]*)><\/p>/g,"<p$1>&nbsp;</p>")),/&quot;/.test(p)&&(p=p.replace(/&quot;/g,""));let H=u.getQuill(),w=Number((H.scroll.domNode.scrollHeight/l).toFixed(0)),y=Number(w||e.__layout.boxBounds.height||0),C=Number(e.parent?.height??0),F=e.data.canChangeBox?Math.max(C,y):y,b=`<style>p{margin:0;}sub,sup{font-size:63%;}.ql-ui{position:absolute}ol,ul{counter-reset:list-0;padding-left:1.5em;margin:0}ol>li,ul>li{counter-increment:list-0;list-style-type:none;position:relative;padding-left:0;margin:0}ol>li::before{content:counter(list-0,decimal) '. ';position:absolute;left:-1.5em;width:1.2em;text-align:right}ul>li::before{content:'\u2022';position:absolute;left:-1.5em;width:1.2em;text-align:right}li[data-list]{counter-set:list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-align-center{text-align:center}.ql-align-right{text-align:right}.ql-align-left{text-align:left}.ql-align-justify{text-align:justify}*{font-variant-ligatures:none;font-feature-settings:"liga" 0,"clig" 0;}em{font-style:oblique;}strong{font-weight:bolder;}</style>`,S="";if(e.parent.children[0].tag.includes("Shape")){let E=h?`font-family:${h};`:"";S=b+`<div style="width: ${e.parent.width}px;height: ${e.parent.height}px;overflow-wrap:break-word;word-break:break-all;display:flex;flex-direction:column;justify-content:center;${E}">${p}</div>`;}else e.data.canChangeBox?S=b+`<div style="width: ${e.parent.width}px;height:${F}px;overflow-wrap:break-word;word-break:break-all;display:flex;flex-direction:column;justify-content:${pt(r)};">${p}</div>`:e.data.textData.italic?S=b+p:S=b+`<div style="overflow-wrap:break-word;word-break:break-all;">${p}</div>`;return S},we=(e,i,t)=>{let n=u.getQuill(),{editor:a,canvas:s}=u.getCanvas();if(!n)return;i===0&&(i="0");let r=u.getSelection();u.dateEdit(async o=>{if(o.tag==="HTMLText")if(e==="font")a.innerEditing?(r&&r.length?n.formatText(r.index,r.length,e,i):n.formatText(0,n.getLength()-1,e,i),o.data.textData.fontFamily=i,f(o,t??null,i??null)):(u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),n.formatText(0,n.getLength()-1,e,i),o.data.textData.fontFamily=i,f(o,t??null,i??null));else if(e==="fontSize"){o.data.textData[e]=i;let l=Number(o.scaleX??1),c=Number(o.scaleY??1);Number.isFinite(l)&&Math.abs(l-1)>1e-4&&(o.scaleX=1),Number.isFinite(c)&&Math.abs(c-1)>1e-4&&(o.scaleY=1),u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),f(o,t??null);}else if(e==="textCase"){if(a.innerEditing){if(!r||!r.length)return;let l=n.getText(r.index,r.length),c=n.getFormat(r.index,r.length);n.deleteText(r.index,r.length);let d;l===l.toUpperCase()&&/[A-Z]/.test(l)?d=l.toLowerCase():(l===l.toLowerCase()&&/[a-z]/.test(l),d=l.toUpperCase()),n.insertText(r.index,d,c),r&&a.innerEditing&&n.setSelection(r.index,r.length);}}else if(e==="script"){let l="sub";i==="super"&&(l="sup"),a.innerEditing?r&&r.length?n.formatText(r.index,r.length,e,n.getFormat(r).script===i?false:l):n.formatText(0,n.getLength()-1,e,n.getFormat().script===i?false:l):(u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),n.formatText(0,n.getLength()-1,e,n.getFormat().script===i?false:l),f(o));}else if(e==="align")u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),a.innerEditing?n.format(e,i):n.formatLine(0,n.getLength(),e,i),f(o);else if(e==="alignContent")u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),o.data.textData[e]=i,f(o);else if(e==="lineHeight"||e==="letterSpacing")u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),o.data.textData[e]=i,f(o);else if(e==="color")u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),r&&r.length?n.formatText(r.index,r.length,e,i):n.formatText(0,n.getLength()-1,e,i),o.tag==="HTMLText"?f(o):o.parent.findOne("HTMLText")&&f(o.parent.findOne("HTMLText"));else if(e==="textShadow"||e==="textStroke")u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),o.data.textData[e]=i,f(o);else if(e==="list"){if(u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),a.innerEditing){let[l]=n.getLine(r?.index||0);l.formats().list?n.format(e,false):n.format(e,i);}else {let[l]=n.getLine(r?.index||0);l.formats().list?n.formatLine(0,n.getLength(),e,false):n.formatLine(0,n.getLength(),e,i);}f(o);}else if(e==="textVertical"){let l=Q();if(l&&l?.features?.length&&l?.features?.includes("textVertical")){n.clipboard.dangerouslyPasteHTML(o.text);let c=n.getSemanticHTML();n.clipboard.dangerouslyPasteHTML(at(c)),o.data.textData.align="center",f(o);}}else a.innerEditing?r&&r.length?n.formatText(r.index,r.length,e,i===void 0?!n.getFormat(r)[e]:i):n.formatText(0,n.getLength()-1,e,i===void 0?!n.getFormat()[e]:i):(u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),n.formatText(0,n.getLength()-1,e,i===void 0?!n.getFormat()[e]:i),f(o));},1);};function Ft(e,i){return e.replace(/(-?\d*\.?\d+)px/g,(t,n)=>Number(n)*i+"px")}function Bt(e,i){return i===0?1/0:330*e*72/96/Math.abs(i)}var _t=e=>{let t=(e.children||[]).slice().filter(n=>n?.tag==="Box");return t.forEach(n=>e.remove(n)),t.length};function kt(e,i,t,n="normal"){let s=document.createElement("canvas").getContext("2d");return s.font=`${n} ${i}px ${t}`,e.map(r=>s.measureText(r).width)}var N=(e,i)=>{_t(e);let t=e.findOne("HTMLText");if(!t)return;let n=(e.width??0)/2,a=t.data?.textData?.curveAmount;if(!a){t.opacity=1,t.visible=true;return}let s=u.getQuill();if(!s){t.opacity=1,t.visible=true;return}!i&&t.text&&s.clipboard.dangerouslyPasteHTML(t.text),t.opacity=0;let r=Number(t.data.textData.fontSize)||16,o=t.data.textData.lineHeight,l=o?.value??(typeof o=="number"?o:1),c=t.data.textData.fontFamily||"",d=Bt(r,a),h=2*Math.PI*d,m=s.getText(),g=m.endsWith(`
2
+ `)?m.slice(0,-1):m,p=Array.from(g);if(!p.length){t.opacity=1,t.visible=true;return}let w=s.getFormat(0,1).bold?"bold":"normal",y=kt(p,r,c,w),C=Math.max(.2,Math.min(1.8,r*.03*l)),F=a>0?C:C*.6,b=y.map(x=>Math.max(1,x-F)),S=b.reduce((x,R)=>x+R,0),E=0;h>S&&(E=(h-S)/2);let V=E*360/h,q=new core.Box({x:0,y:0,editable:false,resizeChildren:true}),yt=r*l,tt=a>0?d+yt:-d,O;if(a>0)O=`G ${n} ${tt} ${d} ${d} 90 ${V} ${360-V} 0`;else {let x=180-V;O=`G ${n} ${tt} ${d} ${d} 90 ${x} ${-x} 1`;}let St=new core.Path({x:0,y:a>0?r/2:0,motionPath:true,editable:false,path:O});q.add(St),q.set({opacity:i?.2:1});let et=0;p.forEach((x,R)=>{let nt=s.getFormat(R,1),W=nt.bold?"bold":"normal",Z=b[R];if(W!==w){let it=document.createElement("canvas").getContext("2d");it.font=`${W} ${r}px ${c}`,Z=Math.max(1,it.measureText(x).width-F);}et+=Z;let bt=new html.HTMLText({text:x,around:a>0?"bottom":"top",fontSize:r,fontFamily:c||void 0,fontWeight:W,motion:et-Z/2,motionRotation:a>0?3:-2,fill:nt.color||void 0});q.add(bt);}),e.add(q);},A={0:"\u2070",1:"\xB9",2:"\xB2",3:"\xB3",4:"\u2074",5:"\u2075",6:"\u2076",7:"\u2077",8:"\u2078",9:"\u2079",a:"\u1D43",b:"\u1D47",c:"\u1D9C",d:"\u1D48",e:"\u1D49",f:"\u1DA0",g:"\u1D4D",h:"\u02B0",i:"\u2071",j:"\u02B2",k:"\u1D4F",l:"\u02E1",m:"\u1D50",n:"\u207F",o:"\u1D52",p:"\u1D56",r:"\u02B3",s:"\u02E2",t:"\u1D57",u:"\u1D58",v:"\u1D5B",w:"\u02B7",x:"\u02E3",y:"\u02B8",z:"\u1DBB",A:"\u1D2C",B:"\u1D2E",D:"\u1D30",E:"\u1D31",G:"\u1D33",H:"\u1D34",I:"\u1D35",J:"\u1D36",K:"\u1D37",L:"\u1D38",M:"\u1D39",N:"\u1D3A",O:"\u1D3C",P:"\u1D3E",R:"\u1D3F",T:"\u1D40",U:"\u1D41",W:"\u1D42","+":"\u207A","-":"\u207B","=":"\u207C","(":"\u207D",")":"\u207E"},U={0:"\u2080",1:"\u2081",2:"\u2082",3:"\u2083",4:"\u2084",5:"\u2085",6:"\u2086",7:"\u2087",8:"\u2088",9:"\u2089",a:"\u2090",e:"\u2091",h:"\u2095",i:"\u1D62",j:"\u2C7C",k:"\u2096",l:"\u2097",m:"\u2098",n:"\u2099",o:"\u2092",p:"\u209A",r:"\u1D63",s:"\u209B",t:"\u209C",u:"\u1D64",v:"\u1D65",x:"\u2093","+":"\u208A","-":"\u208B","=":"\u208C","(":"\u208D",")":"\u208E",\u03B2:"\u1D66",\u03B3:"\u1D67",\u03C1:"\u1D68",\u03C6:"\u1D69",\u03C7:"\u1D6A"};function ft(e){let i={};for(let t in e)i[e[t]]=e[t];return i}ft(A);ft(U);var z=class extends editor.EditTool{constructor(t){super(t);this.quill=null;this.C=null;this.F=null;this.q=null;this.isUpdatingPoints=false;this.eventIds=[];}get tag(){return "TextEditTool"}syncResizeBaseline(t){t?.data||(t.data={}),t.data.baseSize={...t.data.baseSize||{},width:Number(t.parent?.width??t.data?.baseSize?.width??0),fontSize:Number(t.data?.textData?.fontSize??t.data?.baseSize?.fontSize??0),textStroke:t.data?.textData?.textStroke??null};}addEvent(){let t=this.editor.element?.findOne("HTMLText");if(!t||!t.worldTransform)return;this.syncResizeBaseline(t);let n=document.querySelector("#textInnerEditor"),{style:a}=n;this.eventIds=[this.editor.on_(core.DragEvent.START,s=>{s?.target?.pointType==="resize"&&this.syncResizeBaseline(t);}),this.editor.on_(editor.EditorScaleEvent.SCALE,()=>{if(t.data.canChangeBox||(t.data.canChangeBox=true),t.data.canChangeBox){let s=D(t);a.width=t.parent.width*s+"px",a.height="auto",a.minHeight=t.parent.height*s+"px";}if((t.parent.tag==="Box"||t.parent.tag==="HtmlText")&&t.parent.lockRatio){let s=Number(t.data?.baseSize?.width??t.parent.width??0),r=Number(t.data?.baseSize?.fontSize??t.data?.textData?.fontSize??0);if(s>0&&r>0){let o=t.parent.width/s;t.data.textData.fontSize=Number((r*o).toFixed(2));let l=t.data?.baseSize?.textStroke??null;l&&l!=="unset"&&t.data?.textData&&(t.data.textData.textStroke=l.replace(/^(\d+(?:\.\d+)?)px/,(c,d)=>`${Number((parseFloat(d)*o).toFixed(2))}px`)),this.C===null&&(this.C=requestAnimationFrame(()=>{this.C=null;let c=Number(t.data?.baseSize?.width??0);if(c>0){let d=Number((t.parent.width/c).toFixed(4));t.scaleX=d,t.scaleY=d;}}));}}}),this.editor.on_(core.DragEvent.END,s=>{if(s?.target?.pointType==="resize"){if(this.C!==null&&(cancelAnimationFrame(this.C),this.C=null),t.parent?.lockRatio){t.scaleX=1,t.scaleY=1,t.data&&(t.data.__syncingInnerHTMLText=false);let r=typeof t.opacity=="number"?t.opacity:1;t.opacity=0,f(t).finally(()=>{t.opacity=r;});}else f(t);this.syncResizeBaseline(t);}}),this.editor.on_(core.PointerEvent.DOUBLE_TAP,s=>{!t.parent.locked&&s.target.tag!=="Group"&&this.editor.openInnerEditor(t,true);})];}onLoad(){let t=this.editor.element?.findOne("HTMLText");if(!t||!t.worldTransform)return;this.syncResizeBaseline(t);let n=D(t);this.editor.element?.set({editConfig:{resizeable:!t.data.textData.curveAmount}}),this.addEvent(),this.editBox.add(this.view);let a=this.editor.element;this.F=a?.width??null,this.q=a?.height??null,this.quill=u.getQuill(),this.quill&&this.quill.clipboard.dangerouslyPasteHTML(t.text);let s=document.querySelector("#textInnerEditor"),{style:r}=s;t.data.canChangeBox?(r.width=t.parent.width*n+"px",r.height="auto",r.minHeight=t.parent.height*n+"px"):(r.width="auto",r.height="auto",r.minHeight="0px");}updateChangeBoxBound(t){t&&t.set({width:t.__layout.boxBounds.width,height:t.__layout.boxBounds.height});}onUpdate(){let t=this.editor.element;if(!t)return;let n=t.findOne("HTMLText");if(!(!n||!n.data?.textData?.curveAmount)&&!this.isUpdatingPoints&&(t.tag==="HtmlText"||t.name==="Text"&&t.tag==="Box"||t.name==="Text"&&t.tag==="Group")){if(t.app?.editor?.isUndoRedo){setTimeout(()=>{t.app.editor.isUndoRedo=false;},100);return}let a=t.width,s=t.height;if(a===this.F&&s===this.q)return;this.F=a,this.q=s,this.isUpdatingPoints=true,N(t,false),setTimeout(()=>{this.isUpdatingPoints=false;},50);}}onUnload(){this.C!==null&&(cancelAnimationFrame(this.C),this.C=null),this.editor.off_(this.eventIds);}onDestroy(){}};z=v([editor.registerEditTool()],z);var gt=new Set,Xt=e=>{if(!e||typeof document>"u")return;let i=e.match(/<style[^>]*>[\s\S]*?<\/style>/gi)||[];i.length&&i.forEach(t=>{(t.replace(/<style[^>]*>|<\/style>/gi,"").match(/@font-face\s*\{[\s\S]*?\}/gi)||[]).forEach(s=>{let r=s.trim();if(!r||gt.has(r))return;let o=document.createElement("style");o.setAttribute("data-inner-editor-font-face","true"),o.textContent=r,document.head.appendChild(o),gt.add(r);});});},P=class extends editor.InnerEditor{constructor(){super(...arguments);this.config={selectAll:false};this.eventIds=[];this.selectText=void 0;this.inBody=void 0;this.isHTMLText=void 0;this._=void 0;this.quill=null;this.isComposing=false;this.inputSyncFrame=null;this.quillRoot=null;this.handleCompositionStart=()=>{this.isComposing=true,this.inputSyncFrame!==null&&(cancelAnimationFrame(this.inputSyncFrame),this.inputSyncFrame=null);};this.handleCompositionEnd=()=>{this.isComposing=false,this.scheduleInputSync();};this.scheduleInputSync=()=>{this.inputSyncFrame!==null&&cancelAnimationFrame(this.inputSyncFrame),this.inputSyncFrame=requestAnimationFrame(()=>{this.inputSyncFrame=null,f(this.editTarget);});};this.onInput=async()=>{this.isComposing||this.scheduleInputSync();};this.onSelectionChange=t=>{u.setSelection(t);};this.isUpdatingPoints=false;}get tag(){return "TextEditor"}onLoad(){let{editor:t}=this,{config:n}=t.app,a=this.editTarget,s=D(a);a.data={...a.data||{},__innerEditorZoomScale:s},this.isHTMLText=!(a instanceof Text),this._=n.keyEvent,n.keyEvent=false;let r=this.editDom=document.querySelector("#textInnerEditor"),{style:o}=r;o.visibility="visible",o.pointerEvents="auto",o.userSelect="text",o.webkitUserSelect="text",o.zIndex="10001",o.caretColor=a.data.textData?.fill||"#111111",o.fontVariantLigatures="none",o.fontFeatureSettings='"liga" 0, "clig" 0';let c=!!a?.parent?.children?.[0]?.tag?.includes?.("Shape")||!!a.data?.canChangeBox;a.data.canChangeBox?(o.width=a.parent.width*s+"px",o.height=c?a.parent.height*s+"px":"auto",o.minHeight=a.parent.height*s+"px"):(o.width="auto",o.height="auto",o.minHeight="0px"),o.outline="1px solid #8499EF",a.data.textData.fontSize&&(r.style.fontSize=`${a.data.textData.fontSize*s}px`),a.data.textData.fontFamily&&(r.style.fontFamily=`${a.data.textData.fontFamily}`),a.data.textData.lineHeight?r.style.lineHeight=a.data.textData.lineHeight:r.style.lineHeight="1.5",k(r,a.data.textData.letterSpacing,s),a.data.textData.textShadow?r.style.textShadow=mt(a.data.textData.textShadow,s):r.style.textShadow="none";let h=r.querySelector(".ql-editor")||r;if(a.data.textData.textStroke&&a.data.textData.textStroke!=="unset"){h.style.paintOrder="stroke fill";let m=mt(a.data.textData.textStroke,s);h.style.webkitTextStroke=m;}else h.style.paintOrder="unset",h.style.webkitTextStroke="unset";j(r,a.data.textData.alignContent,c),this.quill=u.getQuill(),this.quillRoot=this.quill?.root,this.quillRoot&&(this.quillRoot.contentEditable="true",this.quillRoot.tabIndex=0,this.quillRoot.style.pointerEvents="auto",this.quillRoot.style.userSelect="text",this.quillRoot.style.webkitUserSelect="text",this.quillRoot.style.outline="none",this.quillRoot.style.fontVariantLigatures="none",this.quillRoot.style.fontFeatureSettings='"liga" 0, "clig" 0',this.quillRoot.addEventListener("compositionstart",this.handleCompositionStart),this.quillRoot.addEventListener("compositionend",this.handleCompositionEnd)),Xt(a.text),this.quill.clipboard.dangerouslyPasteHTML(a.text),k(r,a.data.textData.letterSpacing,s),a?.parent?.children?.length&&a.parent.children[0].tag.includes("Shape")&&this.quill.formatLine(0,this.quill.getLength(),"align","center"),this.quill.setSelection(0,this.quill.getLength()-1),this.quill.focus(),requestAnimationFrame(()=>{this.quill&&(this.quill.focus(),this.quill.getSelection()||this.quill.setSelection(0,this.quill.getLength()-1));}),this.quill.on("text-change",this.onInput),this.quill.on("selection-change",this.onSelectionChange),u.clearSelection(),this.eventIds=[t.app.on_(core.PointerEvent.DOWN,m=>{if(this.eventIds===void 0)return;let{target:g}=m.origin,p=false;for(;g;)g===r&&(p=true),g=g.parentElement;p||(t.closeInnerEditor(),t.cancel());})];}onUpdate(){let{editTarget:t}=this,{scaleX:n,scaleY:a}=t.worldTransform,s=Math.max(Math.abs(n),Math.abs(a)),r=D(t);t.data={...t.data||{},__innerEditorZoomScale:r};let{width:o,height:l}=t.parent.__local;o*=r,l*=r;let{x:c,y:d}=this.inBody?t.app.clientBounds:t.app.tree.clientBounds,{a:h,b:m,c:g,d:p,e:H,f:w}=new core.Matrix(t.worldTransform).scale(1/(s||1)).translateInner(0,0),{style:y}=this.editDom;if(y.transform=`matrix(${h},${m},${g},${p},${H},${w})`,y.left=c+"px",y.top=d+"px",t.parent.tag==="HtmlText"||t.parent.name=="Text"&&t.parent.tag=="Box"||t.parent.name=="Text"&&t.parent.tag=="Group"){if(this.isUpdatingPoints)return;this.isUpdatingPoints=true,N(t.parent,true),setTimeout(()=>{this.isUpdatingPoints=false;},50);}t.set({visible:false});}onUnload(){let{editTarget:t,editor:n,editDom:a}=this;if(t&&(this.inputSyncFrame!==null&&(cancelAnimationFrame(this.inputSyncFrame),this.inputSyncFrame=null),this.isComposing=false,f(t),n.app&&(n.app.config.keyEvent=this._),n.off_(this.eventIds),this.editDom.style.visibility="hidden",this.eventIds=void 0),t.parent&&(t.parent.name=="Text"||t.parent.tag==="HtmlText")&&t.parent.children.some(s=>s.tag==="Box")){let s=t.parent.find("Box"),r=s?.at(-1);r&&s.length>1&&r.name!=="Text"&&(r.opacity=1,t.visible=false);}else t.set({visible:true});this.quill.getLength()===1&&(t.parent.name==="Text"||t.parent.tag==="HtmlText")&&t.parent.remove(),t?.parent?.children?.length&&t.parent.children[0].tag.includes("Shape")&&this.quill.getContents().ops.length===1&&t.remove(),t.data&&"__innerEditorZoomScale"in t.data&&delete t.data.__innerEditorZoomScale,this.quillRoot&&(this.quillRoot.removeEventListener("compositionstart",this.handleCompositionStart),this.quillRoot.removeEventListener("compositionend",this.handleCompositionEnd),this.quillRoot=null),this.quill.off("text-change",this.onInput),this.quill.off("selection-change",this.onSelectionChange),u.clearSelection();}};P=v([editor.registerInnerEditor()],P);function mt(e,i){return e.replace(/(-?\d*\.?\d+)px/g,(t,n)=>Number(n)*i+"px")}function J(e,{insertAt:i}={}){if(typeof document>"u")return;let t=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",i==="top"&&t.firstChild?t.insertBefore(n,t.firstChild):t.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e));}J(`.ql-editor{padding:0!important;line-height:unset!important;overflow:unset!important;outline:0}.ql-container{font-family:unset!important}.ql-editor p{margin:0!important}.ql-editor sub,.ql-editor sup{font-size:63%}.ql-editor sup{top:-.58em}.ql-editor sub{bottom:-.38em}.ql-editor ol{padding-left:0!important}
3
+ `);var X=class e{constructor(){this.quill=null;this.app_=null;this.S=0;this.selectionRange=null;}static getInstance(){return e.instance||(e.instance=new e),e.instance}async init(i){if(this.S=await K(),this.app_=this.S?i:null,this.quill)return this.quill;let t=document.getElementById("textInnerEditor");if(t)this.quill=this.app_?.editor?.quill||null;else return t=document.createElement("div"),t.id="textInnerEditor",t.style.position="fixed",t.style.transformOrigin="left top",t.style.overflowWrap="break-word",t.style.wordBreak="break-all",t.style.visibility="hidden",document.body.appendChild(t),this.quill=new M__default.default("#textInnerEditor",{theme:void 0,modules:{toolbar:false,keyboard:{bindings:{enter:{key:"Enter",handler:n=>{if(!this.S)return true;let[a]=this.quill.getLine(n.index),s=M__default.default.import("blots/block");if(!s?.bubbleFormats)return true;let r=s.bubbleFormats(a),o=new M.Delta().retain(n.index).delete(n.length).insert(`
4
+ `,r);return this.quill.updateContents(o,M__default.default.sources.USER),this.quill.setSelection(n.index+1,M__default.default.sources.SILENT),false}}}}}}),this.app_?.editor&&(this.app_.editor.quill=this.quill),this.registerFonts(),this.quill}getQuill(){return this.S?this.quill:null}getCanvas(){return this.S?this.app_:null}getSelection(){return this.S?this.selectionRange?this.selectionRange:this.quill?.getSelection()||this.quill?.selection?.savedRange||null:null}setSelection(i){this.selectionRange=i;}clearSelection(){this.selectionRange=null;}registerFonts(){this.S&&(font.FontStyle.whitelist=void 0,M__default.default.register("formats/font",font.FontStyle,true));}isMultiSelect(){return !this.S||!this.app_?.editor?false:this.app_.editor.multiple===true}dateEdit(i,t=0,n){let{editor:a}=this.app_||{};if(!a)return;let s=n||a.leafList?.list,r=o=>{t&&(o.tag==="Box"||o.name==="Text")?i(o.children?.[0]||o):i(o);};if(s?.length)if(Array.isArray(s)&&s.length>1){this.app_.lockLayout();let o=s.length*this.S;for(let l=0;l<o;l++)r(s[l]);this.app_.unlockLayout(),a.updateEditBox();}else this.S&&r(s[0]);}},u=X.getInstance();var ne=html.HTMLText.prototype.__updateBoxBounds;html.HTMLText.prototype.__updateBoxBounds=function(){let e=this.__;if(e.__htmlChanged){let i=document.createElement("div"),{style:t}=i,n=this.text?.replace(/&nbsp;/g,"\xA0")??"";t.all="initial",t.position="absolute",t.visibility="hidden",t.whiteSpace="pre-wrap",t.wordBreak="break-word",t.overflowWrap="break-word",t.display="inline-block",i.innerHTML=n,document.body.appendChild(i);let{width:a,height:s}=i.getBoundingClientRect();if(i.remove(),a===0||s===0){e.__htmlChanged=false;return}let r=Math.ceil(a)+1;n.includes("<em>")&&(r+=10);let o=`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${s}"><foreignObject width="${r}" height="${s}"><style>*{margin:0;padding:0;box-sizing:border-box;}</style><body xmlns="http://www.w3.org/1999/xhtml">${n}</body></foreignObject></svg>`;e.__setImageFill("data:image/svg+xml,"+encodeURIComponent(o)),e.__naturalWidth=r/(e.pixelRatio??1),e.__naturalHeight=s/(e.pixelRatio??1),e.__htmlChanged=false;}ne.call(this);};exports.HtmlText=class $ extends core.Box{get __tag(){return "HtmlText"}constructor(i){let{text:t,fontSize:n,fontFamily:a,lineHeight:s,letterSpacing:r,textShadow:o,alignContent:l,...c}=i||{};super({editOuter:"TextEditTool",name:"HtmlText",x:0,y:0,editable:true,draggable:true,overflow:"show",...c}),i&&this.createTextElement(i);}createTextElement(i){let{text:t,fontSize:n,fontFamily:a,lineHeight:s,letterSpacing:r,textShadow:o,alignContent:l}=i,c="<style>p{margin:0;}sub,sup{font-size:63%;}.ql-ui{position:absolute}ol,ul{counter-reset:list-0;padding-left:1.5em;margin:0}ol>li,ul>li{counter-increment:list-0;list-style-type:none;position:relative;padding-left:0;margin:0}ol>li::before{content:counter(list-0,decimal) '. ';position:absolute;left:-1.5em;width:1.2em;text-align:right}ul>li::before{content:'\u2022';position:absolute;left:-1.5em;width:1.2em;text-align:right}li[data-list]{counter-set:list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-align-center{text-align:center}.ql-align-right{text-align:right}.ql-align-left{text-align:left}.ql-align-justify{text-align:justify}</style>",d=`<div style="ove
5
+ rflow-wrap:break-word;word-break:break-all;"><p style="font-size: ${n}px; line-height: ${s}; letter-spacing: ${r}px; text-shadow: ${o};"><strong>Hello World</strong></p></div>`;if(i.children?.length>0)return;let h=new html.HTMLText({name:"Text",text:c+(t||d),x:0,y:0,data:{canChangeBox:false,textData:{fontFamily:a,fontSize:n,lineHeight:s,letterSpacing:r||0,textShadow:o,alignContent:l}},editConfig:{selectedStyle:{strokeWidth:0}}});this.add(h);}};exports.HtmlText=v([core.registerUI()],exports.HtmlText);exports.checkLicense=K;exports.getHTMLTextZoomScale=D;exports.getLicenseInfo=Q;exports.htmlTextManage=u;exports.setHTMLText=we;exports.setLicense=Ct;exports.syncInnerEditorLetterSpacing=k;exports.syncInnerEditorVerticalLayout=j;exports.updataHtmlText=f;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import {registerEditTool,registerInnerEditor,EditTool,EditorScaleEvent,InnerEditor}from'@leafer-in/editor';import {registerUI,Box,DragEvent,PointerEvent,Matrix,Path}from'@leafer-ui/core';import L from'crypto-js';import {HTMLText}from'@leafer-in/html';import C,{Delta}from'quill';import'quill/dist/quill.core.css';import {FontStyle}from'quill/formats/font';var E=(t,i,e,n)=>{for(var a=i,s=t.length-1,o;s>=0;s--)(o=t[s])&&(a=(o(a))||a);return a};function W(t){let n=new DOMParser().parseFromString(t,"text/html").body;function a(r){if(r.nodeType===Node.TEXT_NODE){let l=r.textContent;return l?Array.from(l).map(u=>document.createTextNode(u)):[]}else if(r.nodeType===Node.ELEMENT_NODE){let l=[];for(let c of Array.from(r.childNodes))a(c).forEach((p,m)=>{let g=r.cloneNode(false);g.appendChild(p),l.push(g);});return l}return []}let s=[];for(let r of Array.from(n.childNodes)){let l=a(r);s.push(...l);}let o=document.createElement("div");return s.forEach((r,l)=>{o.appendChild(r);}),o.innerHTML}var Y="LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxaUFnU1hWM3dMKzh2YkZ2OVkwQwpEN1dBUjhPa2I4bjlmTWxpQjF3enZodTBrdVdZUWEvMUxvVDhHWVh6WWlRQVFBRk9zTTA0MGp2dlNRT2hRSWpiCjRaYXZ1NHUvWVA5bElPYjFKYnZnYkFoYVVOQnphL0l2UmFnaFlKYTJBc1cyRVhnZkVrdmMyUENNMS9zbVlFNnoKNjZiUmx1dnREK3FJZkpLVCtUUXJRRmp5TnNTZ0c2Z2R4MThrZTRMSStBejFPcklMbUsyMHlBU2tlRXpYT1BTVAplM3RNYThleHpZdmUzV0wyNHRHUHg5WHNvN1JyUEl1elZlajh0NDYrZ0c1Y0pQaVh0N1lqa0V2NEJOUUt5eUpoCkltOVRJdVZ6clFpa2NJNE14dExNSGdUMHpLcU9ZZ1NzcmEvTHNDd2ZOdzdtYWxITkU2c21YZWYyQ2E5RGhZODQKS1FJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==";function lt(t){let i=t.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");return K(i)}function K(t){let i=atob(t),e=new Uint8Array(i.length);for(let n=0;n<i.length;n++)e[n]=i.charCodeAt(n);return e.buffer}async function ct(){let t=atob(Y),i=lt(t);return await crypto.subtle.importKey("spki",i,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},false,["verify"])}async function Q(t,i){try{let e=await ct(),n=new TextEncoder().encode(t),a=K(i);return await crypto.subtle.verify("RSASSA-PKCS1-v1_5",e,a,n)}catch{return false}}var j="c19496eb17719960b6c3cebab0ef5eddfce5d0315ab8c5af86a52fbda434fea9",J="ce1e3e8974f1392b3c5803b34ecf659f";function X(t){try{let i=L.enc.Hex.parse(j),e=L.enc.Hex.parse(J),a=L.AES.decrypt(t,i,{iv:e,mode:L.mode.CBC,padding:L.pad.Pkcs7}).toString(L.enc.Utf8);if(!a)throw new Error("Decryption resulted in empty string - invalid ciphertext or wrong key");return a}catch(i){throw i}}async function dt(t){try{let i=atob(t),e=JSON.parse(i);if(!e.data||!e.signature||!await Q(e.data,e.signature))return null;let a=e.data;if(e.encrypted)try{a=X(e.data);}catch{return null}return JSON.parse(a)}catch{return null}}function ut(t){if(!t||t.length===0)return true;let i=window.location.hostname;if(i==="localhost"||i==="127.0.0.1")return true;let e=t.some(n=>{if(n.startsWith("*.")){let a=n.slice(2);return i.endsWith(a)}return i===n});return e}function pt(t){if(!t)return true;try{let i=new Date(t),e=new Date;return e>=i?!1:(Math.ceil((i.getTime()-e.getTime())/(1e3*60*60*24))<=7,!0)}catch{return false}}function ft(t){if(!t)return true;try{return !(new Date(t)>new Date)}catch{return true}}async function k(t){try{let i=await dt(t);return i?ft(i.issueDate)?ut(i.domains)?pt(i.expireDate)?{valid:!0,data:i}:{valid:!1,error:"License has expired",data:i}:{valid:!1,error:`License not valid for domain: ${window.location.hostname}`,data:i}:{valid:!1,error:"Invalid license issue date",data:i}:{valid:!1,error:"Invalid license key or signature verification failed"}}catch{return {valid:false,error:"ERR"}}}var M=null,H=null,b=0;async function ht(t){let i=await k(t);return i.valid&&i.data?(M=t,H=i.data,b=1,true):(M=null,H=null,b=0,false)}async function P(){return !M||!b?0:(b=(await k(M)).valid?1:0,b||(H=null),b)}function $(){return b?H:null}var G=t=>{let i=Number(t?.data?.__innerEditorZoomScale);return Number.isFinite(i)&&i>0?i:1},F=(t,i,e)=>{if(!t)return;let s=`${(Number(i)||0)*(Number.isFinite(e)&&e>0?e:1)}px`;t.style.letterSpacing=s;let o=t.querySelector(".ql-editor");o&&(o.style.letterSpacing=s,o.querySelectorAll("p, li, ol, ul").forEach(r=>{r.style.letterSpacing=s;}));},v=t=>{if(!t?.worldTransform)return 1;let{scaleX:i,scaleY:e}=t.worldTransform,n=Math.max(Math.abs(typeof t.scaleX=="number"?t.scaleX:1),Math.abs(typeof t.scaleY=="number"?t.scaleY:1));return Math.max(Math.abs(i),Math.abs(e))/(n||1)},tt=t=>{switch(t){case "center":return "center";case "end":return "flex-end";default:return "flex-start"}},V=(t,i,e)=>{if(!t)return;let n=t.querySelector(".ql-editor");n&&(e?(n.style.display="flex",n.style.flexDirection="column",n.style.height="100%",n.style.justifyContent=tt(i)):(n.style.display="",n.style.flexDirection="",n.style.height="",n.style.justifyContent=""));},f=async(t,i,e)=>{if(!(!t||!t.parent)&&(t.data||(t.data={}),!t.data.__syncingInnerHTMLText)){t.data.__syncingInnerHTMLText=true;try{let n=G(t),a=document.querySelector("#textInnerEditor"),s=!!t?.parent?.children?.[0]?.tag?.includes?.("Shape");a&&t.data.textData?.fontSize&&(a.style.fontSize=`${t.data.textData.fontSize*n}px`),a&&t.data.textData?.lineHeight&&(a.style.lineHeight=t.data.textData.lineHeight),F(a,t.data.textData?.letterSpacing,n),a&&t.data.textData?.textShadow?a.style.textShadow=t.data.textData.textShadow:a&&(a.style.textShadow="none"),a&&t.data.textData?.textStroke?(a.style.paintOrder="stroke fill",a.style.webkitTextStroke=gt(t.data.textData.textStroke,n)):a&&(a.style.paintOrder="unset",a.style.webkitTextStroke="unset"),V(a,t.data.textData?.alignContent,s||!!t.data.canChangeBox);let r=d.getQuill().getSemanticHTML();if(r==="<p></p>"){t.text.includes("<style>@font-face")?t.text=t.text.split("</style>")[0]+"</style>":t.text="";return}if(t.text.includes("<style>@font-face")){let l=t.text.split("</style>")[0];if(e&&!l.includes(e)){let c=`@font-face {font-family: ${e.split(",")[0]};src: url(${i}) format('woff2') }</style>`;t.text=l+c+q(t,r,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent,t.data.textData.textStroke);}else t.text=l+"</style>"+q(t,r,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent,t.data.textData.textStroke);}else if(i&&e){let l=`<style>@font-face {font-family: ${e.split(",")[0]};src: url(${i}) format('woff2') }</style>`;t.text=l+q(t,r,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent,t.data.textData.textStroke);}else t.text=q(t,r,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent,t.data.textData.textStroke);}finally{t?.data&&(t.data.__syncingInnerHTMLText=false);}}},q=(t,i,e=20.67,n=1.5,a=0,s="none",o="start",r="unset")=>{let l=G(t),c=!!t?.parent?.children?.[0]?.tag?.includes?.("Shape"),u=t?.data?.textData?.fontFamily||"",p=u.replace(/"/g,"").trim(),m=document.createElement("div");m.innerHTML=i;let g={fontSize:`${e}px`,lineHeight:n,letterSpacing:`${a}px`,textShadow:s};r!=="unset"?(g.paintOrder="stroke fill",g.WebkitTextStroke=r):(g.paintOrder="unset",g.WebkitTextStroke="unset"),c&&u&&(g.fontFamily=u),m.querySelectorAll("p,ol,ul").forEach(_=>{Object.assign(_.style,g);});let h=m.innerHTML;/<p\b[^>]*><\/p>/.test(h)&&(h=h.replace(/<p\b([^>]*)><\/p>/g,"<p$1>&nbsp;</p>")),/&quot;/.test(h)&&(h=h.replace(/&quot;/g,""));let y=d.getQuill(),D=Number((y.scroll.domNode.scrollHeight/l).toFixed(0)),x=Number(D||t.__layout.boxBounds.height||0),z=Number(t.parent?.height??0),T=t.data.canChangeBox?Math.max(z,x):x,w=`<style>p{margin:0;}sub,sup{font-size:63%;}.ql-ui{position:absolute}ol,ul{counter-reset:list-0;padding-left:1.5em;margin:0}ol>li,ul>li{counter-increment:list-0;list-style-type:none;position:relative;padding-left:0;margin:0}ol>li::before{content:counter(list-0,decimal) '. ';position:absolute;left:-1.5em;width:1.2em;text-align:right}ul>li::before{content:'\u2022';position:absolute;left:-1.5em;width:1.2em;text-align:right}li[data-list]{counter-set:list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-align-center{text-align:center}.ql-align-right{text-align:right}.ql-align-left{text-align:left}.ql-align-justify{text-align:justify}*{font-variant-ligatures:none;font-feature-settings:"liga" 0,"clig" 0;}em{font-style:oblique;}strong{font-weight:bolder;}</style>`,S="";if(t.parent.children[0].tag.includes("Shape")){let _=p?`font-family:${p};`:"";S=w+`<div style="width: ${t.parent.width}px;height: ${t.parent.height}px;overflow-wrap:break-word;word-break:break-all;display:flex;flex-direction:column;justify-content:center;${_}">${h}</div>`;}else t.data.canChangeBox?S=w+`<div style="width: ${t.parent.width}px;height:${T}px;overflow-wrap:break-word;word-break:break-all;display:flex;flex-direction:column;justify-content:${tt(o)};">${h}</div>`:t.data.textData.italic?S=w+h:S=w+`<div style="overflow-wrap:break-word;word-break:break-all;">${h}</div>`;return S},ae=(t,i,e)=>{let n=d.getQuill(),{editor:a,canvas:s}=d.getCanvas();if(!n)return;i===0&&(i="0");let o=d.getSelection();d.dateEdit(async r=>{if(r.tag==="HTMLText")if(t==="font")a.innerEditing?(o&&o.length?n.formatText(o.index,o.length,t,i):n.formatText(0,n.getLength()-1,t,i),r.data.textData.fontFamily=i,f(r,e??null,i??null)):(d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),n.formatText(0,n.getLength()-1,t,i),r.data.textData.fontFamily=i,f(r,e??null,i??null));else if(t==="fontSize"){r.data.textData[t]=i;let l=Number(r.scaleX??1),c=Number(r.scaleY??1);Number.isFinite(l)&&Math.abs(l-1)>1e-4&&(r.scaleX=1),Number.isFinite(c)&&Math.abs(c-1)>1e-4&&(r.scaleY=1),d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),f(r,e??null);}else if(t==="textCase"){if(a.innerEditing){if(!o||!o.length)return;let l=n.getText(o.index,o.length),c=n.getFormat(o.index,o.length);n.deleteText(o.index,o.length);let u;l===l.toUpperCase()&&/[A-Z]/.test(l)?u=l.toLowerCase():(l===l.toLowerCase()&&/[a-z]/.test(l),u=l.toUpperCase()),n.insertText(o.index,u,c),o&&a.innerEditing&&n.setSelection(o.index,o.length);}}else if(t==="script"){let l="sub";i==="super"&&(l="sup"),a.innerEditing?o&&o.length?n.formatText(o.index,o.length,t,n.getFormat(o).script===i?false:l):n.formatText(0,n.getLength()-1,t,n.getFormat().script===i?false:l):(d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),n.formatText(0,n.getLength()-1,t,n.getFormat().script===i?false:l),f(r));}else if(t==="align")d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),a.innerEditing?n.format(t,i):n.formatLine(0,n.getLength(),t,i),f(r);else if(t==="alignContent")d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=i,f(r);else if(t==="lineHeight"||t==="letterSpacing")d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=i,f(r);else if(t==="color")d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),o&&o.length?n.formatText(o.index,o.length,t,i):n.formatText(0,n.getLength()-1,t,i),r.tag==="HTMLText"?f(r):r.parent.findOne("HTMLText")&&f(r.parent.findOne("HTMLText"));else if(t==="textShadow"||t==="textStroke")d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=i,f(r);else if(t==="list"){if(d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),a.innerEditing){let[l]=n.getLine(o?.index||0);l.formats().list?n.format(t,false):n.format(t,i);}else {let[l]=n.getLine(o?.index||0);l.formats().list?n.formatLine(0,n.getLength(),t,false):n.formatLine(0,n.getLength(),t,i);}f(r);}else if(t==="textVertical"){let l=$();if(l&&l?.features?.length&&l?.features?.includes("textVertical")){n.clipboard.dangerouslyPasteHTML(r.text);let c=n.getSemanticHTML();n.clipboard.dangerouslyPasteHTML(W(c)),r.data.textData.align="center",f(r);}}else a.innerEditing?o&&o.length?n.formatText(o.index,o.length,t,i===void 0?!n.getFormat(o)[t]:i):n.formatText(0,n.getLength()-1,t,i===void 0?!n.getFormat()[t]:i):(d.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(r.text),n.formatText(0,n.getLength()-1,t,i===void 0?!n.getFormat()[t]:i),f(r));},1);};function gt(t,i){return t.replace(/(-?\d*\.?\d+)px/g,(e,n)=>Number(n)*i+"px")}function St(t,i){return i===0?1/0:330*t*72/96/Math.abs(i)}var R=(t,i)=>{let e=t.findOne("Box");e&&t.remove(e);let n=t.findOne("HTMLText"),{boxBounds:a,x:s,y:o}=n,{width:r}=a;if(!n.curveAmount){n.opacity=1,n.visible=true;return}n.text=n.text.replace(/\u200B/g,"").replace(/<br\s*\/?>/gi,`
2
- `),n.opacity=0;let l=St(n.fontSize,n.curveAmount),c=2*Math.PI*l,u=n.text.length+2,p=r/u,m=0;c>p*n.text.length&&(m=(c-p*n.text.length)/2);let g=m*360/c,h=new Box({x:0,y:0,editable:false,resizeChildren:true}),y,D=n.fontSize*n.lineHeight.value||0,x=n.curveAmount>0?l+D:-l;if(n.curveAmount>0)y=`G ${s+r/2} ${x} ${l} ${l} 90 ${g} ${360-g} 0`;else {let T=180-g;y=`G ${s+r/2} ${x} ${l} ${l} 90 ${T} ${-T} 1`;}let z=new Path({x:0,y:0,motionPath:true,editable:false,path:y});h.add(z),h.set({opacity:i?.2:1}),Array.from(n.text).forEach((T,w)=>{let S=new HTMLText({text:T,around:n.curveAmount>0?"bottom":"top",fontSize:n.fontSize,fontFamily:n.fontFamily,fontWeight:n.fontWeight,motion:w*p+p/2,textDecoration:n.textDecoration,textCase:n.textCase,textAlign:n.textAlign,motionRotation:n.curveAmount>0?3:-2,fill:n.fill});h.add(S);}),t.add(h);},I={0:"\u2070",1:"\xB9",2:"\xB2",3:"\xB3",4:"\u2074",5:"\u2075",6:"\u2076",7:"\u2077",8:"\u2078",9:"\u2079",a:"\u1D43",b:"\u1D47",c:"\u1D9C",d:"\u1D48",e:"\u1D49",f:"\u1DA0",g:"\u1D4D",h:"\u02B0",i:"\u2071",j:"\u02B2",k:"\u1D4F",l:"\u02E1",m:"\u1D50",n:"\u207F",o:"\u1D52",p:"\u1D56",r:"\u02B3",s:"\u02E2",t:"\u1D57",u:"\u1D58",v:"\u1D5B",w:"\u02B7",x:"\u02E3",y:"\u02B8",z:"\u1DBB",A:"\u1D2C",B:"\u1D2E",D:"\u1D30",E:"\u1D31",G:"\u1D33",H:"\u1D34",I:"\u1D35",J:"\u1D36",K:"\u1D37",L:"\u1D38",M:"\u1D39",N:"\u1D3A",O:"\u1D3C",P:"\u1D3E",R:"\u1D3F",T:"\u1D40",U:"\u1D41",W:"\u1D42","+":"\u207A","-":"\u207B","=":"\u207C","(":"\u207D",")":"\u207E"},B={0:"\u2080",1:"\u2081",2:"\u2082",3:"\u2083",4:"\u2084",5:"\u2085",6:"\u2086",7:"\u2087",8:"\u2088",9:"\u2089",a:"\u2090",e:"\u2091",h:"\u2095",i:"\u1D62",j:"\u2C7C",k:"\u2096",l:"\u2097",m:"\u2098",n:"\u2099",o:"\u2092",p:"\u209A",r:"\u1D63",s:"\u209B",t:"\u209C",u:"\u1D64",v:"\u1D65",x:"\u2093","+":"\u208A","-":"\u208B","=":"\u208C","(":"\u208D",")":"\u208E",\u03B2:"\u1D66",\u03B3:"\u1D67",\u03C1:"\u1D68",\u03C6:"\u1D69",\u03C7:"\u1D6A"};function et(t){let i={};for(let e in t)i[t[e]]=t[e];return i}et(I);et(B);var A=class extends EditTool{constructor(e){super(e);this.quill=null;this.C=null;this.q=null;this.F=null;this.isUpdatingPoints=false;this.eventIds=[];}get tag(){return "TextEditTool"}syncResizeBaseline(e){e?.data||(e.data={}),e.data.baseSize={...e.data.baseSize||{},width:Number(e.parent?.width??e.data?.baseSize?.width??0),fontSize:Number(e.data?.textData?.fontSize??e.data?.baseSize?.fontSize??0)};}addEvent(){let e=this.editor.element?.findOne("HTMLText");if(!e||!e.worldTransform)return;this.syncResizeBaseline(e);let n=document.querySelector("#textInnerEditor"),{style:a}=n;this.eventIds=[this.editor.on_(DragEvent.START,s=>{s?.target?.pointType==="resize"&&this.syncResizeBaseline(e);}),this.editor.on_(EditorScaleEvent.SCALE,()=>{if(e.data.canChangeBox||(e.data.canChangeBox=true),e.data.canChangeBox){let s=v(e);a.width=e.parent.width*s+"px",a.height="auto",a.minHeight=e.parent.height*s+"px";}if(e.parent.tag==="Box"&&e.parent.lockRatio){let s=Number(e.data?.baseSize?.width??e.parent.width??0),o=Number(e.data?.baseSize?.fontSize??e.data?.textData?.fontSize??0);if(s>0&&o>0){let r=e.parent.width/s;e.data.textData.fontSize=Number((o*r).toFixed(2)),this.C===null&&(this.C=requestAnimationFrame(()=>{this.C=null;let l=Number(e.data?.baseSize?.width??0);if(l>0){let c=Number((e.parent.width/l).toFixed(4));e.scaleX=c,e.scaleY=c;}}));}}}),this.editor.on_(DragEvent.END,s=>{s?.target?.pointType==="resize"&&(this.C!==null&&(cancelAnimationFrame(this.C),this.C=null),e.parent?.lockRatio?(e.scaleX=1,e.scaleY=1,f(e)):f(e),this.syncResizeBaseline(e));}),this.editor.on_(PointerEvent.DOUBLE_TAP,s=>{!e.parent.locked&&s.target.tag!=="Group"&&this.editor.openInnerEditor(e,true);})];}onLoad(){let e=this.editor.element?.findOne("HTMLText");if(!e||!e.worldTransform)return;this.syncResizeBaseline(e);let n=v(e);this.editor.element?.set({editConfig:{resizeable:!e.data.textData.curveAmount}}),this.addEvent(),this.editBox.add(this.view);let a=this.editor.element;this.q=a?.width??null,this.F=a?.height??null,this.quill=d.getQuill(),this.quill&&this.quill.clipboard.dangerouslyPasteHTML(e.text);let s=document.querySelector("#textInnerEditor"),{style:o}=s;e.data.canChangeBox?(o.width=e.parent.width*n+"px",o.height="auto",o.minHeight=e.parent.height*n+"px"):(o.width="auto",o.height="auto",o.minHeight="0px");}updateChangeBoxBound(e){e&&e.set({width:e.__layout.boxBounds.width,height:e.__layout.boxBounds.height});}onUpdate(){let e=this.editor.element;if(!e)return;let n=e.findOne("HTMLText");if(!(!n||!n.data?.textData?.curveAmount)&&!this.isUpdatingPoints&&(e.name==="Text"&&e.tag==="Box"||e.name==="Text"&&e.tag==="Group")){if(e.app?.editor?.isUndoRedo){setTimeout(()=>{e.app.editor.isUndoRedo=false;},100);return}let a=e.width,s=e.height;if(a===this.q&&s===this.F)return;this.q=a,this.F=s,this.isUpdatingPoints=true,R(e,false),setTimeout(()=>{this.isUpdatingPoints=false;},50);}}onUnload(){this.C!==null&&(cancelAnimationFrame(this.C),this.C=null),this.editor.off_(this.eventIds);}onDestroy(){}};A=E([registerEditTool()],A);var it=new Set,At=t=>{if(!t||typeof document>"u")return;let i=t.match(/<style[^>]*>[\s\S]*?<\/style>/gi)||[];i.length&&i.forEach(e=>{(e.replace(/<style[^>]*>|<\/style>/gi,"").match(/@font-face\s*\{[\s\S]*?\}/gi)||[]).forEach(s=>{let o=s.trim();if(!o||it.has(o))return;let r=document.createElement("style");r.setAttribute("data-inner-editor-font-face","true"),r.textContent=o,document.head.appendChild(r),it.add(o);});});},N=class extends InnerEditor{constructor(){super(...arguments);this.config={selectAll:false};this.eventIds=[];this.selectText=void 0;this.inBody=void 0;this.isHTMLText=void 0;this._=void 0;this.quill=null;this.isComposing=false;this.inputSyncFrame=null;this.quillRoot=null;this.handleCompositionStart=()=>{this.isComposing=true,this.inputSyncFrame!==null&&(cancelAnimationFrame(this.inputSyncFrame),this.inputSyncFrame=null);};this.handleCompositionEnd=()=>{this.isComposing=false,this.scheduleInputSync();};this.scheduleInputSync=()=>{this.inputSyncFrame!==null&&cancelAnimationFrame(this.inputSyncFrame),this.inputSyncFrame=requestAnimationFrame(()=>{this.inputSyncFrame=null,f(this.editTarget);});};this.onInput=async()=>{this.isComposing||this.scheduleInputSync();};this.onSelectionChange=e=>{d.setSelection(e);};this.isUpdatingPoints=false;}get tag(){return "TextEditor"}onLoad(){let{editor:e}=this,{config:n}=e.app,a=this.editTarget,s=v(a);a.data={...a.data||{},__innerEditorZoomScale:s},this.isHTMLText=!(a instanceof Text),this._=n.keyEvent,n.keyEvent=false;let o=this.editDom=document.querySelector("#textInnerEditor"),{style:r}=o;r.visibility="visible",r.pointerEvents="auto",r.userSelect="text",r.webkitUserSelect="text",r.zIndex="10001",r.caretColor=a.data.textData?.fill||"#111111",r.fontVariantLigatures="none",r.fontFeatureSettings='"liga" 0, "clig" 0';let c=!!a?.parent?.children?.[0]?.tag?.includes?.("Shape")||!!a.data?.canChangeBox;a.data.canChangeBox?(r.width=a.parent.width*s+"px",r.height=c?a.parent.height*s+"px":"auto",r.minHeight=a.parent.height*s+"px"):(r.width="auto",r.height="auto",r.minHeight="0px"),r.outline="1px solid #8499EF",a.data.textData.fontSize&&(o.style.fontSize=`${a.data.textData.fontSize*s}px`),a.data.textData.fontFamily&&(o.style.fontFamily=`${a.data.textData.fontFamily}`),a.data.textData.lineHeight?o.style.lineHeight=a.data.textData.lineHeight:o.style.lineHeight="1.5",F(o,a.data.textData.letterSpacing,s),a.data.textData.textShadow?o.style.textShadow=at(a.data.textData.textShadow,s):o.style.textShadow="none",a.data.textData.textStroke?(o.style.paintOrder="stroke fill",o.style.WebkitTextStroke=at(a.data.textData.textStroke,s)):(o.style.paintOrder="unset",o.style.WebkitTextStroke="unset"),V(o,a.data.textData.alignContent,c),this.quill=d.getQuill(),this.quillRoot=this.quill?.root,this.quillRoot&&(this.quillRoot.contentEditable="true",this.quillRoot.tabIndex=0,this.quillRoot.style.pointerEvents="auto",this.quillRoot.style.userSelect="text",this.quillRoot.style.webkitUserSelect="text",this.quillRoot.style.outline="none",this.quillRoot.style.fontVariantLigatures="none",this.quillRoot.style.fontFeatureSettings='"liga" 0, "clig" 0',this.quillRoot.addEventListener("compositionstart",this.handleCompositionStart),this.quillRoot.addEventListener("compositionend",this.handleCompositionEnd)),At(a.text),this.quill.clipboard.dangerouslyPasteHTML(a.text),F(o,a.data.textData.letterSpacing,s),a?.parent?.children?.length&&a.parent.children[0].tag.includes("Shape")&&this.quill.formatLine(0,this.quill.getLength(),"align","center"),this.quill.setSelection(0,this.quill.getLength()-1),this.quill.focus(),requestAnimationFrame(()=>{this.quill&&(this.quill.focus(),this.quill.getSelection()||this.quill.setSelection(0,this.quill.getLength()-1));}),this.quill.on("text-change",this.onInput),this.quill.on("selection-change",this.onSelectionChange),d.clearSelection(),this.eventIds=[e.app.on_(PointerEvent.DOWN,u=>{if(this.eventIds===void 0)return;let{target:p}=u.origin,m=false;for(;p;)p===o&&(m=true),p=p.parentElement;m||(e.closeInnerEditor(),e.cancel());})];}onUpdate(){let{editTarget:e}=this,{scaleX:n,scaleY:a}=e.worldTransform,s=Math.max(Math.abs(n),Math.abs(a)),o=v(e);e.data={...e.data||{},__innerEditorZoomScale:o};let{width:r,height:l}=e.parent.__local;r*=o,l*=o;let{x:c,y:u}=this.inBody?e.app.clientBounds:e.app.tree.clientBounds,{a:p,b:m,c:g,d:h,e:y,f:D}=new Matrix(e.worldTransform).scale(1/(s||1)).translateInner(0,0),{style:x}=this.editDom;if(x.transform=`matrix(${p},${m},${g},${h},${y},${D})`,x.left=c+"px",x.top=u+"px",e.parent.name=="Text"&&e.parent.tag=="Box"||e.parent.name=="Text"&&e.parent.tag=="Group"){if(this.isUpdatingPoints)return;this.isUpdatingPoints=true,R(e.parent,true),setTimeout(()=>{this.isUpdatingPoints=false;},50);}e.set({visible:false});}onUnload(){let{editTarget:e,editor:n,editDom:a}=this;if(e&&(this.inputSyncFrame!==null&&(cancelAnimationFrame(this.inputSyncFrame),this.inputSyncFrame=null),this.isComposing=false,f(e),n.app&&(n.app.config.keyEvent=this._),n.off_(this.eventIds),this.editDom.style.visibility="hidden",this.eventIds=void 0),e.parent&&e.parent.name=="Text"&&e.parent.children.some(s=>s.tag==="Box")){let s=e.parent.find("Box"),o=s?.at(-1);o&&s.length>1&&o.name!=="Text"&&(o.opacity=1,e.visible=false);}else e.set({visible:true});this.quill.getLength()===1&&e.parent.name==="Text"&&e.parent.remove(),e?.parent?.children?.length&&e.parent.children[0].tag.includes("Shape")&&this.quill.getContents().ops.length===1&&e.remove(),e.data&&"__innerEditorZoomScale"in e.data&&delete e.data.__innerEditorZoomScale,this.quillRoot&&(this.quillRoot.removeEventListener("compositionstart",this.handleCompositionStart),this.quillRoot.removeEventListener("compositionend",this.handleCompositionEnd),this.quillRoot=null),this.quill.off("text-change",this.onInput),this.quill.off("selection-change",this.onSelectionChange),d.clearSelection();}};N=E([registerInnerEditor()],N);function at(t,i){return t.replace(/(-?\d*\.?\d+)px/g,(e,n)=>Number(n)*i+"px")}function O(t,{insertAt:i}={}){if(typeof document>"u")return;let e=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",i==="top"&&e.firstChild?e.insertBefore(n,e.firstChild):e.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t));}O(`.ql-editor{padding:0!important;line-height:unset!important;overflow:unset!important;outline:0}.ql-container{font-family:unset!important}.ql-editor p{margin:0!important}.ql-editor sub,.ql-editor sup{font-size:63%}.ql-editor sup{top:-.58em}.ql-editor sub{bottom:-.38em}.ql-editor ol{padding-left:0!important}
3
- `);var Z=class t{constructor(){this.quill=null;this.app_=null;this.S=0;this.selectionRange=null;}static getInstance(){return t.instance||(t.instance=new t),t.instance}async init(i){if(this.S=await P(),this.app_=this.S?i:null,this.quill)return this.quill;let e=document.getElementById("textInnerEditor");if(e)this.quill=this.app_?.editor?.quill||null;else return e=document.createElement("div"),e.id="textInnerEditor",e.style.position="fixed",e.style.transformOrigin="left top",e.style.overflowWrap="break-word",e.style.wordBreak="break-all",e.style.visibility="hidden",document.body.appendChild(e),this.quill=new C("#textInnerEditor",{theme:void 0,modules:{toolbar:false,keyboard:{bindings:{enter:{key:"Enter",handler:n=>{if(!this.S)return true;let[a]=this.quill.getLine(n.index),s=C.import("blots/block");if(!s?.bubbleFormats)return true;let o=s.bubbleFormats(a),r=new Delta().retain(n.index).delete(n.length).insert(`
4
- `,o);return this.quill.updateContents(r,C.sources.USER),this.quill.setSelection(n.index+1,C.sources.SILENT),false}}}}}}),this.app_?.editor&&(this.app_.editor.quill=this.quill),this.registerFonts(),this.quill}getQuill(){return this.S?this.quill:null}getCanvas(){return this.S?this.app_:null}getSelection(){return this.S?this.selectionRange?this.selectionRange:this.quill?.getSelection()||this.quill?.selection?.savedRange||null:null}setSelection(i){this.selectionRange=i;}clearSelection(){this.selectionRange=null;}registerFonts(){this.S&&(FontStyle.whitelist=void 0,C.register("formats/font",FontStyle,true));}isMultiSelect(){return !this.S||!this.app_?.editor?false:this.app_.editor.multiple===true}dateEdit(i,e=0,n){let{editor:a}=this.app_||{};if(!a)return;let s=n||a.leafList?.list,o=r=>{e&&(r.tag==="Box"||r.name==="Text")?i(r.children?.[0]||r):i(r);};if(s?.length)if(Array.isArray(s)&&s.length>1){this.app_.lockLayout();let r=s.length*this.S;for(let l=0;l<r;l++)o(s[l]);this.app_.unlockLayout(),a.updateEditBox();}else this.S&&o(s[0]);}},d=Z.getInstance();var U=class extends Box{get __tag(){return "HtmlText"}constructor(i){let{text:e,fontSize:n,fontFamily:a,lineHeight:s,letterSpacing:o,textShadow:r,alignContent:l,...c}=i||{};super({editOuter:"TextEditTool",name:"HtmlText",x:0,y:0,editable:true,draggable:true,overflow:"show",...c}),i&&this.createTextElement(i);}createTextElement(i){let{text:e,fontSize:n,fontFamily:a,lineHeight:s,letterSpacing:o,textShadow:r,alignContent:l}=i,c="<style>p{margin:0;}sub,sup{font-size:63%;}.ql-ui{position:absolute}ol,ul{counter-reset:list-0;padding-left:1.5em;margin:0}ol>li,ul>li{counter-increment:list-0;list-style-type:none;position:relative;padding-left:0;margin:0}ol>li::before{content:counter(list-0,decimal) '. ';position:absolute;left:-1.5em;width:1.2em;text-align:right}ul>li::before{content:'\u2022';position:absolute;left:-1.5em;width:1.2em;text-align:right}li[data-list]{counter-set:list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-align-center{text-align:center}.ql-align-right{text-align:right}.ql-align-left{text-align:left}.ql-align-justify{text-align:justify}</style>",u=`<div style="ove
5
- rflow-wrap:break-word;word-break:break-all;"><p style="font-size: ${n}px; line-height: ${s}; letter-spacing: ${o}px; text-shadow: ${r};"><strong>Hello World</strong></p></div>`;if(i.children?.length>0)return;let p=new HTMLText({name:"Text",text:c+(e||u),x:0,y:0,data:{canChangeBox:false,textData:{fontFamily:a,fontSize:n,lineHeight:s,letterSpacing:o||0,textShadow:r,alignContent:l}},editConfig:{selectedStyle:{strokeWidth:0}}});this.add(p);}};U=E([registerUI()],U);export{U as HtmlText,P as checkLicense,v as getHTMLTextZoomScale,$ as getLicenseInfo,d as htmlTextManage,ae as setHTMLText,ht as setLicense,F as syncInnerEditorLetterSpacing,V as syncInnerEditorVerticalLayout,f as updataHtmlText};
1
+ import {registerEditTool,registerInnerEditor,EditTool,EditorScaleEvent,InnerEditor}from'@leafer-in/editor';import {registerUI,Box,DragEvent,PointerEvent,Matrix,Path}from'@leafer-ui/core';import L from'crypto-js';import {HTMLText}from'@leafer-in/html';import M,{Delta}from'quill';import'quill/dist/quill.core.css';import {FontStyle}from'quill/formats/font';var v=(e,i,t,n)=>{for(var a=i,s=e.length-1,r;s>=0;s--)(r=e[s])&&(a=(r(a))||a);return a};function at(e){let n=new DOMParser().parseFromString(e,"text/html").body;function a(o){if(o.nodeType===Node.TEXT_NODE){let l=o.textContent;return l?Array.from(l).map(d=>document.createTextNode(d)):[]}else if(o.nodeType===Node.ELEMENT_NODE){let l=[];for(let c of Array.from(o.childNodes))a(c).forEach((h,m)=>{let g=o.cloneNode(false);g.appendChild(h),l.push(g);});return l}return []}let s=[];for(let o of Array.from(n.childNodes)){let l=a(o);s.push(...l);}let r=document.createElement("div");return s.forEach((o,l)=>{r.appendChild(o);}),r.innerHTML}var rt="LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxaUFnU1hWM3dMKzh2YkZ2OVkwQwpEN1dBUjhPa2I4bjlmTWxpQjF3enZodTBrdVdZUWEvMUxvVDhHWVh6WWlRQVFBRk9zTTA0MGp2dlNRT2hRSWpiCjRaYXZ1NHUvWVA5bElPYjFKYnZnYkFoYVVOQnphL0l2UmFnaFlKYTJBc1cyRVhnZkVrdmMyUENNMS9zbVlFNnoKNjZiUmx1dnREK3FJZkpLVCtUUXJRRmp5TnNTZ0c2Z2R4MThrZTRMSStBejFPcklMbUsyMHlBU2tlRXpYT1BTVAplM3RNYThleHpZdmUzV0wyNHRHUHg5WHNvN1JyUEl1elZlajh0NDYrZ0c1Y0pQaVh0N1lqa0V2NEJOUUt5eUpoCkltOVRJdVZ6clFpa2NJNE14dExNSGdUMHpLcU9ZZ1NzcmEvTHNDd2ZOdzdtYWxITkU2c21YZWYyQ2E5RGhZODQKS1FJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==";function Et(e){let i=e.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");return ot(i)}function ot(e){let i=atob(e),t=new Uint8Array(i.length);for(let n=0;n<i.length;n++)t[n]=i.charCodeAt(n);return t.buffer}async function vt(){let e=atob(rt),i=Et(e);return await crypto.subtle.importKey("spki",i,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},false,["verify"])}async function st(e,i){try{let t=await vt(),n=new TextEncoder().encode(e),a=ot(i);return await crypto.subtle.verify("RSASSA-PKCS1-v1_5",t,a,n)}catch{return false}}var lt="c19496eb17719960b6c3cebab0ef5eddfce5d0315ab8c5af86a52fbda434fea9",ct="ce1e3e8974f1392b3c5803b34ecf659f";function dt(e){try{let i=L.enc.Hex.parse(lt),t=L.enc.Hex.parse(ct),a=L.AES.decrypt(e,i,{iv:t,mode:L.mode.CBC,padding:L.pad.Pkcs7}).toString(L.enc.Utf8);if(!a)throw new Error("Decryption resulted in empty string - invalid ciphertext or wrong key");return a}catch(i){throw i}}async function Lt(e){try{let i=atob(e),t=JSON.parse(i);if(!t.data||!t.signature||!await st(t.data,t.signature))return null;let a=t.data;if(t.encrypted)try{a=dt(t.data);}catch{return null}return JSON.parse(a)}catch{return null}}function Dt(e){if(!e||e.length===0)return true;let i=window.location.hostname;if(i==="localhost"||i==="127.0.0.1")return true;let t=e.some(n=>{if(n.startsWith("*.")){let a=n.slice(2);return i.endsWith(a)}return i===n});return t}function Mt(e){if(!e)return true;try{let i=new Date(e),t=new Date;return t>=i?!1:(Math.ceil((i.getTime()-t.getTime())/(1e3*60*60*24))<=7,!0)}catch{return false}}function Ht(e){if(!e)return true;try{return !(new Date(e)>new Date)}catch{return true}}async function Y(e){try{let i=await Lt(e);return i?Ht(i.issueDate)?Dt(i.domains)?Mt(i.expireDate)?{valid:!0,data:i}:{valid:!1,error:"License has expired",data:i}:{valid:!1,error:`License not valid for domain: ${window.location.hostname}`,data:i}:{valid:!1,error:"Invalid license issue date",data:i}:{valid:!1,error:"Invalid license key or signature verification failed"}}catch{return {valid:false,error:"ERR"}}}var I=null,B=null,T=0;async function Ct(e){let i=await Y(e);return i.valid&&i.data?(I=e,B=i.data,T=1,true):(I=null,B=null,T=0,false)}async function K(){return !I||!T?0:(T=(await Y(I)).valid?1:0,T||(B=null),T)}function Q(){return T?B:null}var ut=e=>{let i=Number(e?.data?.__innerEditorZoomScale);return Number.isFinite(i)&&i>0?i:1},k=(e,i,t)=>{if(!e)return;let s=`${(Number(i)||0)*(Number.isFinite(t)&&t>0?t:1)}px`;e.style.letterSpacing=s;let r=e.querySelector(".ql-editor");r&&(r.style.letterSpacing=s,r.querySelectorAll("p, li, ol, ul").forEach(o=>{o.style.letterSpacing=s;}));},D=e=>{if(!e?.worldTransform)return 1;let{scaleX:i,scaleY:t}=e.worldTransform,n=Math.max(Math.abs(typeof e.scaleX=="number"?e.scaleX:1),Math.abs(typeof e.scaleY=="number"?e.scaleY:1));return Math.max(Math.abs(i),Math.abs(t))/(n||1)},pt=e=>{switch(e){case "center":return "center";case "end":return "flex-end";default:return "flex-start"}},j=(e,i,t)=>{if(!e)return;let n=e.querySelector(".ql-editor");n&&(t?(n.style.display="flex",n.style.flexDirection="column",n.style.height="100%",n.style.justifyContent=pt(i)):(n.style.display="",n.style.flexDirection="",n.style.height="",n.style.justifyContent=""));},f=async(e,i,t)=>{if(!(!e||!e.parent)&&(e.data||(e.data={}),!e.data.__syncingInnerHTMLText)){e.data.__syncingInnerHTMLText=true;try{let n=ut(e),a=document.querySelector("#textInnerEditor"),s=!!e?.parent?.children?.[0]?.tag?.includes?.("Shape");a&&e.data.textData?.fontSize&&(a.style.fontSize=`${e.data.textData.fontSize*n}px`),a&&e.data.textData?.lineHeight&&(a.style.lineHeight=e.data.textData.lineHeight),k(a,e.data.textData?.letterSpacing,n),a&&e.data.textData?.textShadow?a.style.textShadow=e.data.textData.textShadow:a&&(a.style.textShadow="none"),a&&e.data.textData?.textStroke?(a.style.paintOrder="stroke fill",a.style.webkitTextStroke=Ft(e.data.textData.textStroke,n)):a&&(a.style.paintOrder="unset",a.style.webkitTextStroke="unset"),j(a,e.data.textData?.alignContent,s||!!e.data.canChangeBox);let o=u.getQuill().getSemanticHTML();if(o==="<p></p>"){e.text.includes("<style>@font-face")?e.text=e.text.split("</style>")[0]+"</style>":e.text="";return}if(e.text.includes("<style>@font-face")){let l=e.text.split("</style>")[0];if(t&&!l.includes(t)){let c=`@font-face {font-family: ${t.split(",")[0]};src: url(${i}) format('woff2') }</style>`;e.text=l+c+_(e,o,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent,e.data.textData.textStroke);}else e.text=l+"</style>"+_(e,o,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent,e.data.textData.textStroke);}else if(i&&t){let l=`<style>@font-face {font-family: ${t.split(",")[0]};src: url(${i}) format('woff2') }</style>`;e.text=l+_(e,o,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent,e.data.textData.textStroke);}else e.text=_(e,o,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent,e.data.textData.textStroke);}finally{e?.data&&(e.data.__syncingInnerHTMLText=false);}}},_=(e,i,t=20.67,n=1.5,a=0,s="none",r="start",o="unset")=>{let l=ut(e),c=!!e?.parent?.children?.[0]?.tag?.includes?.("Shape"),d=e?.data?.textData?.fontFamily||"",h=d.replace(/"/g,"").trim(),m=document.createElement("div");m.innerHTML=i;let g={fontSize:`${t}px`,lineHeight:n,letterSpacing:`${a}px`,textShadow:s};o!=="unset"?(g.paintOrder="stroke fill",g.WebkitTextStroke=o):(g.paintOrder="unset",g.WebkitTextStroke="unset"),c&&d&&(g.fontFamily=d),m.querySelectorAll("p,ol,ul").forEach(E=>{Object.assign(E.style,g);});let p=m.innerHTML;/<p\b[^>]*><\/p>/.test(p)&&(p=p.replace(/<p\b([^>]*)><\/p>/g,"<p$1>&nbsp;</p>")),/&quot;/.test(p)&&(p=p.replace(/&quot;/g,""));let H=u.getQuill(),w=Number((H.scroll.domNode.scrollHeight/l).toFixed(0)),y=Number(w||e.__layout.boxBounds.height||0),C=Number(e.parent?.height??0),F=e.data.canChangeBox?Math.max(C,y):y,b=`<style>p{margin:0;}sub,sup{font-size:63%;}.ql-ui{position:absolute}ol,ul{counter-reset:list-0;padding-left:1.5em;margin:0}ol>li,ul>li{counter-increment:list-0;list-style-type:none;position:relative;padding-left:0;margin:0}ol>li::before{content:counter(list-0,decimal) '. ';position:absolute;left:-1.5em;width:1.2em;text-align:right}ul>li::before{content:'\u2022';position:absolute;left:-1.5em;width:1.2em;text-align:right}li[data-list]{counter-set:list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-align-center{text-align:center}.ql-align-right{text-align:right}.ql-align-left{text-align:left}.ql-align-justify{text-align:justify}*{font-variant-ligatures:none;font-feature-settings:"liga" 0,"clig" 0;}em{font-style:oblique;}strong{font-weight:bolder;}</style>`,S="";if(e.parent.children[0].tag.includes("Shape")){let E=h?`font-family:${h};`:"";S=b+`<div style="width: ${e.parent.width}px;height: ${e.parent.height}px;overflow-wrap:break-word;word-break:break-all;display:flex;flex-direction:column;justify-content:center;${E}">${p}</div>`;}else e.data.canChangeBox?S=b+`<div style="width: ${e.parent.width}px;height:${F}px;overflow-wrap:break-word;word-break:break-all;display:flex;flex-direction:column;justify-content:${pt(r)};">${p}</div>`:e.data.textData.italic?S=b+p:S=b+`<div style="overflow-wrap:break-word;word-break:break-all;">${p}</div>`;return S},we=(e,i,t)=>{let n=u.getQuill(),{editor:a,canvas:s}=u.getCanvas();if(!n)return;i===0&&(i="0");let r=u.getSelection();u.dateEdit(async o=>{if(o.tag==="HTMLText")if(e==="font")a.innerEditing?(r&&r.length?n.formatText(r.index,r.length,e,i):n.formatText(0,n.getLength()-1,e,i),o.data.textData.fontFamily=i,f(o,t??null,i??null)):(u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),n.formatText(0,n.getLength()-1,e,i),o.data.textData.fontFamily=i,f(o,t??null,i??null));else if(e==="fontSize"){o.data.textData[e]=i;let l=Number(o.scaleX??1),c=Number(o.scaleY??1);Number.isFinite(l)&&Math.abs(l-1)>1e-4&&(o.scaleX=1),Number.isFinite(c)&&Math.abs(c-1)>1e-4&&(o.scaleY=1),u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),f(o,t??null);}else if(e==="textCase"){if(a.innerEditing){if(!r||!r.length)return;let l=n.getText(r.index,r.length),c=n.getFormat(r.index,r.length);n.deleteText(r.index,r.length);let d;l===l.toUpperCase()&&/[A-Z]/.test(l)?d=l.toLowerCase():(l===l.toLowerCase()&&/[a-z]/.test(l),d=l.toUpperCase()),n.insertText(r.index,d,c),r&&a.innerEditing&&n.setSelection(r.index,r.length);}}else if(e==="script"){let l="sub";i==="super"&&(l="sup"),a.innerEditing?r&&r.length?n.formatText(r.index,r.length,e,n.getFormat(r).script===i?false:l):n.formatText(0,n.getLength()-1,e,n.getFormat().script===i?false:l):(u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),n.formatText(0,n.getLength()-1,e,n.getFormat().script===i?false:l),f(o));}else if(e==="align")u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),a.innerEditing?n.format(e,i):n.formatLine(0,n.getLength(),e,i),f(o);else if(e==="alignContent")u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),o.data.textData[e]=i,f(o);else if(e==="lineHeight"||e==="letterSpacing")u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),o.data.textData[e]=i,f(o);else if(e==="color")u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),r&&r.length?n.formatText(r.index,r.length,e,i):n.formatText(0,n.getLength()-1,e,i),o.tag==="HTMLText"?f(o):o.parent.findOne("HTMLText")&&f(o.parent.findOne("HTMLText"));else if(e==="textShadow"||e==="textStroke")u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),o.data.textData[e]=i,f(o);else if(e==="list"){if(u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),a.innerEditing){let[l]=n.getLine(r?.index||0);l.formats().list?n.format(e,false):n.format(e,i);}else {let[l]=n.getLine(r?.index||0);l.formats().list?n.formatLine(0,n.getLength(),e,false):n.formatLine(0,n.getLength(),e,i);}f(o);}else if(e==="textVertical"){let l=Q();if(l&&l?.features?.length&&l?.features?.includes("textVertical")){n.clipboard.dangerouslyPasteHTML(o.text);let c=n.getSemanticHTML();n.clipboard.dangerouslyPasteHTML(at(c)),o.data.textData.align="center",f(o);}}else a.innerEditing?r&&r.length?n.formatText(r.index,r.length,e,i===void 0?!n.getFormat(r)[e]:i):n.formatText(0,n.getLength()-1,e,i===void 0?!n.getFormat()[e]:i):(u.isMultiSelect()&&n.clipboard.dangerouslyPasteHTML(o.text),n.formatText(0,n.getLength()-1,e,i===void 0?!n.getFormat()[e]:i),f(o));},1);};function Ft(e,i){return e.replace(/(-?\d*\.?\d+)px/g,(t,n)=>Number(n)*i+"px")}function Bt(e,i){return i===0?1/0:330*e*72/96/Math.abs(i)}var _t=e=>{let t=(e.children||[]).slice().filter(n=>n?.tag==="Box");return t.forEach(n=>e.remove(n)),t.length};function kt(e,i,t,n="normal"){let s=document.createElement("canvas").getContext("2d");return s.font=`${n} ${i}px ${t}`,e.map(r=>s.measureText(r).width)}var N=(e,i)=>{_t(e);let t=e.findOne("HTMLText");if(!t)return;let n=(e.width??0)/2,a=t.data?.textData?.curveAmount;if(!a){t.opacity=1,t.visible=true;return}let s=u.getQuill();if(!s){t.opacity=1,t.visible=true;return}!i&&t.text&&s.clipboard.dangerouslyPasteHTML(t.text),t.opacity=0;let r=Number(t.data.textData.fontSize)||16,o=t.data.textData.lineHeight,l=o?.value??(typeof o=="number"?o:1),c=t.data.textData.fontFamily||"",d=Bt(r,a),h=2*Math.PI*d,m=s.getText(),g=m.endsWith(`
2
+ `)?m.slice(0,-1):m,p=Array.from(g);if(!p.length){t.opacity=1,t.visible=true;return}let w=s.getFormat(0,1).bold?"bold":"normal",y=kt(p,r,c,w),C=Math.max(.2,Math.min(1.8,r*.03*l)),F=a>0?C:C*.6,b=y.map(x=>Math.max(1,x-F)),S=b.reduce((x,R)=>x+R,0),E=0;h>S&&(E=(h-S)/2);let V=E*360/h,q=new Box({x:0,y:0,editable:false,resizeChildren:true}),yt=r*l,tt=a>0?d+yt:-d,O;if(a>0)O=`G ${n} ${tt} ${d} ${d} 90 ${V} ${360-V} 0`;else {let x=180-V;O=`G ${n} ${tt} ${d} ${d} 90 ${x} ${-x} 1`;}let St=new Path({x:0,y:a>0?r/2:0,motionPath:true,editable:false,path:O});q.add(St),q.set({opacity:i?.2:1});let et=0;p.forEach((x,R)=>{let nt=s.getFormat(R,1),W=nt.bold?"bold":"normal",Z=b[R];if(W!==w){let it=document.createElement("canvas").getContext("2d");it.font=`${W} ${r}px ${c}`,Z=Math.max(1,it.measureText(x).width-F);}et+=Z;let bt=new HTMLText({text:x,around:a>0?"bottom":"top",fontSize:r,fontFamily:c||void 0,fontWeight:W,motion:et-Z/2,motionRotation:a>0?3:-2,fill:nt.color||void 0});q.add(bt);}),e.add(q);},A={0:"\u2070",1:"\xB9",2:"\xB2",3:"\xB3",4:"\u2074",5:"\u2075",6:"\u2076",7:"\u2077",8:"\u2078",9:"\u2079",a:"\u1D43",b:"\u1D47",c:"\u1D9C",d:"\u1D48",e:"\u1D49",f:"\u1DA0",g:"\u1D4D",h:"\u02B0",i:"\u2071",j:"\u02B2",k:"\u1D4F",l:"\u02E1",m:"\u1D50",n:"\u207F",o:"\u1D52",p:"\u1D56",r:"\u02B3",s:"\u02E2",t:"\u1D57",u:"\u1D58",v:"\u1D5B",w:"\u02B7",x:"\u02E3",y:"\u02B8",z:"\u1DBB",A:"\u1D2C",B:"\u1D2E",D:"\u1D30",E:"\u1D31",G:"\u1D33",H:"\u1D34",I:"\u1D35",J:"\u1D36",K:"\u1D37",L:"\u1D38",M:"\u1D39",N:"\u1D3A",O:"\u1D3C",P:"\u1D3E",R:"\u1D3F",T:"\u1D40",U:"\u1D41",W:"\u1D42","+":"\u207A","-":"\u207B","=":"\u207C","(":"\u207D",")":"\u207E"},U={0:"\u2080",1:"\u2081",2:"\u2082",3:"\u2083",4:"\u2084",5:"\u2085",6:"\u2086",7:"\u2087",8:"\u2088",9:"\u2089",a:"\u2090",e:"\u2091",h:"\u2095",i:"\u1D62",j:"\u2C7C",k:"\u2096",l:"\u2097",m:"\u2098",n:"\u2099",o:"\u2092",p:"\u209A",r:"\u1D63",s:"\u209B",t:"\u209C",u:"\u1D64",v:"\u1D65",x:"\u2093","+":"\u208A","-":"\u208B","=":"\u208C","(":"\u208D",")":"\u208E",\u03B2:"\u1D66",\u03B3:"\u1D67",\u03C1:"\u1D68",\u03C6:"\u1D69",\u03C7:"\u1D6A"};function ft(e){let i={};for(let t in e)i[e[t]]=e[t];return i}ft(A);ft(U);var z=class extends EditTool{constructor(t){super(t);this.quill=null;this.C=null;this.F=null;this.q=null;this.isUpdatingPoints=false;this.eventIds=[];}get tag(){return "TextEditTool"}syncResizeBaseline(t){t?.data||(t.data={}),t.data.baseSize={...t.data.baseSize||{},width:Number(t.parent?.width??t.data?.baseSize?.width??0),fontSize:Number(t.data?.textData?.fontSize??t.data?.baseSize?.fontSize??0),textStroke:t.data?.textData?.textStroke??null};}addEvent(){let t=this.editor.element?.findOne("HTMLText");if(!t||!t.worldTransform)return;this.syncResizeBaseline(t);let n=document.querySelector("#textInnerEditor"),{style:a}=n;this.eventIds=[this.editor.on_(DragEvent.START,s=>{s?.target?.pointType==="resize"&&this.syncResizeBaseline(t);}),this.editor.on_(EditorScaleEvent.SCALE,()=>{if(t.data.canChangeBox||(t.data.canChangeBox=true),t.data.canChangeBox){let s=D(t);a.width=t.parent.width*s+"px",a.height="auto",a.minHeight=t.parent.height*s+"px";}if((t.parent.tag==="Box"||t.parent.tag==="HtmlText")&&t.parent.lockRatio){let s=Number(t.data?.baseSize?.width??t.parent.width??0),r=Number(t.data?.baseSize?.fontSize??t.data?.textData?.fontSize??0);if(s>0&&r>0){let o=t.parent.width/s;t.data.textData.fontSize=Number((r*o).toFixed(2));let l=t.data?.baseSize?.textStroke??null;l&&l!=="unset"&&t.data?.textData&&(t.data.textData.textStroke=l.replace(/^(\d+(?:\.\d+)?)px/,(c,d)=>`${Number((parseFloat(d)*o).toFixed(2))}px`)),this.C===null&&(this.C=requestAnimationFrame(()=>{this.C=null;let c=Number(t.data?.baseSize?.width??0);if(c>0){let d=Number((t.parent.width/c).toFixed(4));t.scaleX=d,t.scaleY=d;}}));}}}),this.editor.on_(DragEvent.END,s=>{if(s?.target?.pointType==="resize"){if(this.C!==null&&(cancelAnimationFrame(this.C),this.C=null),t.parent?.lockRatio){t.scaleX=1,t.scaleY=1,t.data&&(t.data.__syncingInnerHTMLText=false);let r=typeof t.opacity=="number"?t.opacity:1;t.opacity=0,f(t).finally(()=>{t.opacity=r;});}else f(t);this.syncResizeBaseline(t);}}),this.editor.on_(PointerEvent.DOUBLE_TAP,s=>{!t.parent.locked&&s.target.tag!=="Group"&&this.editor.openInnerEditor(t,true);})];}onLoad(){let t=this.editor.element?.findOne("HTMLText");if(!t||!t.worldTransform)return;this.syncResizeBaseline(t);let n=D(t);this.editor.element?.set({editConfig:{resizeable:!t.data.textData.curveAmount}}),this.addEvent(),this.editBox.add(this.view);let a=this.editor.element;this.F=a?.width??null,this.q=a?.height??null,this.quill=u.getQuill(),this.quill&&this.quill.clipboard.dangerouslyPasteHTML(t.text);let s=document.querySelector("#textInnerEditor"),{style:r}=s;t.data.canChangeBox?(r.width=t.parent.width*n+"px",r.height="auto",r.minHeight=t.parent.height*n+"px"):(r.width="auto",r.height="auto",r.minHeight="0px");}updateChangeBoxBound(t){t&&t.set({width:t.__layout.boxBounds.width,height:t.__layout.boxBounds.height});}onUpdate(){let t=this.editor.element;if(!t)return;let n=t.findOne("HTMLText");if(!(!n||!n.data?.textData?.curveAmount)&&!this.isUpdatingPoints&&(t.tag==="HtmlText"||t.name==="Text"&&t.tag==="Box"||t.name==="Text"&&t.tag==="Group")){if(t.app?.editor?.isUndoRedo){setTimeout(()=>{t.app.editor.isUndoRedo=false;},100);return}let a=t.width,s=t.height;if(a===this.F&&s===this.q)return;this.F=a,this.q=s,this.isUpdatingPoints=true,N(t,false),setTimeout(()=>{this.isUpdatingPoints=false;},50);}}onUnload(){this.C!==null&&(cancelAnimationFrame(this.C),this.C=null),this.editor.off_(this.eventIds);}onDestroy(){}};z=v([registerEditTool()],z);var gt=new Set,Xt=e=>{if(!e||typeof document>"u")return;let i=e.match(/<style[^>]*>[\s\S]*?<\/style>/gi)||[];i.length&&i.forEach(t=>{(t.replace(/<style[^>]*>|<\/style>/gi,"").match(/@font-face\s*\{[\s\S]*?\}/gi)||[]).forEach(s=>{let r=s.trim();if(!r||gt.has(r))return;let o=document.createElement("style");o.setAttribute("data-inner-editor-font-face","true"),o.textContent=r,document.head.appendChild(o),gt.add(r);});});},P=class extends InnerEditor{constructor(){super(...arguments);this.config={selectAll:false};this.eventIds=[];this.selectText=void 0;this.inBody=void 0;this.isHTMLText=void 0;this._=void 0;this.quill=null;this.isComposing=false;this.inputSyncFrame=null;this.quillRoot=null;this.handleCompositionStart=()=>{this.isComposing=true,this.inputSyncFrame!==null&&(cancelAnimationFrame(this.inputSyncFrame),this.inputSyncFrame=null);};this.handleCompositionEnd=()=>{this.isComposing=false,this.scheduleInputSync();};this.scheduleInputSync=()=>{this.inputSyncFrame!==null&&cancelAnimationFrame(this.inputSyncFrame),this.inputSyncFrame=requestAnimationFrame(()=>{this.inputSyncFrame=null,f(this.editTarget);});};this.onInput=async()=>{this.isComposing||this.scheduleInputSync();};this.onSelectionChange=t=>{u.setSelection(t);};this.isUpdatingPoints=false;}get tag(){return "TextEditor"}onLoad(){let{editor:t}=this,{config:n}=t.app,a=this.editTarget,s=D(a);a.data={...a.data||{},__innerEditorZoomScale:s},this.isHTMLText=!(a instanceof Text),this._=n.keyEvent,n.keyEvent=false;let r=this.editDom=document.querySelector("#textInnerEditor"),{style:o}=r;o.visibility="visible",o.pointerEvents="auto",o.userSelect="text",o.webkitUserSelect="text",o.zIndex="10001",o.caretColor=a.data.textData?.fill||"#111111",o.fontVariantLigatures="none",o.fontFeatureSettings='"liga" 0, "clig" 0';let c=!!a?.parent?.children?.[0]?.tag?.includes?.("Shape")||!!a.data?.canChangeBox;a.data.canChangeBox?(o.width=a.parent.width*s+"px",o.height=c?a.parent.height*s+"px":"auto",o.minHeight=a.parent.height*s+"px"):(o.width="auto",o.height="auto",o.minHeight="0px"),o.outline="1px solid #8499EF",a.data.textData.fontSize&&(r.style.fontSize=`${a.data.textData.fontSize*s}px`),a.data.textData.fontFamily&&(r.style.fontFamily=`${a.data.textData.fontFamily}`),a.data.textData.lineHeight?r.style.lineHeight=a.data.textData.lineHeight:r.style.lineHeight="1.5",k(r,a.data.textData.letterSpacing,s),a.data.textData.textShadow?r.style.textShadow=mt(a.data.textData.textShadow,s):r.style.textShadow="none";let h=r.querySelector(".ql-editor")||r;if(a.data.textData.textStroke&&a.data.textData.textStroke!=="unset"){h.style.paintOrder="stroke fill";let m=mt(a.data.textData.textStroke,s);h.style.webkitTextStroke=m;}else h.style.paintOrder="unset",h.style.webkitTextStroke="unset";j(r,a.data.textData.alignContent,c),this.quill=u.getQuill(),this.quillRoot=this.quill?.root,this.quillRoot&&(this.quillRoot.contentEditable="true",this.quillRoot.tabIndex=0,this.quillRoot.style.pointerEvents="auto",this.quillRoot.style.userSelect="text",this.quillRoot.style.webkitUserSelect="text",this.quillRoot.style.outline="none",this.quillRoot.style.fontVariantLigatures="none",this.quillRoot.style.fontFeatureSettings='"liga" 0, "clig" 0',this.quillRoot.addEventListener("compositionstart",this.handleCompositionStart),this.quillRoot.addEventListener("compositionend",this.handleCompositionEnd)),Xt(a.text),this.quill.clipboard.dangerouslyPasteHTML(a.text),k(r,a.data.textData.letterSpacing,s),a?.parent?.children?.length&&a.parent.children[0].tag.includes("Shape")&&this.quill.formatLine(0,this.quill.getLength(),"align","center"),this.quill.setSelection(0,this.quill.getLength()-1),this.quill.focus(),requestAnimationFrame(()=>{this.quill&&(this.quill.focus(),this.quill.getSelection()||this.quill.setSelection(0,this.quill.getLength()-1));}),this.quill.on("text-change",this.onInput),this.quill.on("selection-change",this.onSelectionChange),u.clearSelection(),this.eventIds=[t.app.on_(PointerEvent.DOWN,m=>{if(this.eventIds===void 0)return;let{target:g}=m.origin,p=false;for(;g;)g===r&&(p=true),g=g.parentElement;p||(t.closeInnerEditor(),t.cancel());})];}onUpdate(){let{editTarget:t}=this,{scaleX:n,scaleY:a}=t.worldTransform,s=Math.max(Math.abs(n),Math.abs(a)),r=D(t);t.data={...t.data||{},__innerEditorZoomScale:r};let{width:o,height:l}=t.parent.__local;o*=r,l*=r;let{x:c,y:d}=this.inBody?t.app.clientBounds:t.app.tree.clientBounds,{a:h,b:m,c:g,d:p,e:H,f:w}=new Matrix(t.worldTransform).scale(1/(s||1)).translateInner(0,0),{style:y}=this.editDom;if(y.transform=`matrix(${h},${m},${g},${p},${H},${w})`,y.left=c+"px",y.top=d+"px",t.parent.tag==="HtmlText"||t.parent.name=="Text"&&t.parent.tag=="Box"||t.parent.name=="Text"&&t.parent.tag=="Group"){if(this.isUpdatingPoints)return;this.isUpdatingPoints=true,N(t.parent,true),setTimeout(()=>{this.isUpdatingPoints=false;},50);}t.set({visible:false});}onUnload(){let{editTarget:t,editor:n,editDom:a}=this;if(t&&(this.inputSyncFrame!==null&&(cancelAnimationFrame(this.inputSyncFrame),this.inputSyncFrame=null),this.isComposing=false,f(t),n.app&&(n.app.config.keyEvent=this._),n.off_(this.eventIds),this.editDom.style.visibility="hidden",this.eventIds=void 0),t.parent&&(t.parent.name=="Text"||t.parent.tag==="HtmlText")&&t.parent.children.some(s=>s.tag==="Box")){let s=t.parent.find("Box"),r=s?.at(-1);r&&s.length>1&&r.name!=="Text"&&(r.opacity=1,t.visible=false);}else t.set({visible:true});this.quill.getLength()===1&&(t.parent.name==="Text"||t.parent.tag==="HtmlText")&&t.parent.remove(),t?.parent?.children?.length&&t.parent.children[0].tag.includes("Shape")&&this.quill.getContents().ops.length===1&&t.remove(),t.data&&"__innerEditorZoomScale"in t.data&&delete t.data.__innerEditorZoomScale,this.quillRoot&&(this.quillRoot.removeEventListener("compositionstart",this.handleCompositionStart),this.quillRoot.removeEventListener("compositionend",this.handleCompositionEnd),this.quillRoot=null),this.quill.off("text-change",this.onInput),this.quill.off("selection-change",this.onSelectionChange),u.clearSelection();}};P=v([registerInnerEditor()],P);function mt(e,i){return e.replace(/(-?\d*\.?\d+)px/g,(t,n)=>Number(n)*i+"px")}function J(e,{insertAt:i}={}){if(typeof document>"u")return;let t=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",i==="top"&&t.firstChild?t.insertBefore(n,t.firstChild):t.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e));}J(`.ql-editor{padding:0!important;line-height:unset!important;overflow:unset!important;outline:0}.ql-container{font-family:unset!important}.ql-editor p{margin:0!important}.ql-editor sub,.ql-editor sup{font-size:63%}.ql-editor sup{top:-.58em}.ql-editor sub{bottom:-.38em}.ql-editor ol{padding-left:0!important}
3
+ `);var X=class e{constructor(){this.quill=null;this.app_=null;this.S=0;this.selectionRange=null;}static getInstance(){return e.instance||(e.instance=new e),e.instance}async init(i){if(this.S=await K(),this.app_=this.S?i:null,this.quill)return this.quill;let t=document.getElementById("textInnerEditor");if(t)this.quill=this.app_?.editor?.quill||null;else return t=document.createElement("div"),t.id="textInnerEditor",t.style.position="fixed",t.style.transformOrigin="left top",t.style.overflowWrap="break-word",t.style.wordBreak="break-all",t.style.visibility="hidden",document.body.appendChild(t),this.quill=new M("#textInnerEditor",{theme:void 0,modules:{toolbar:false,keyboard:{bindings:{enter:{key:"Enter",handler:n=>{if(!this.S)return true;let[a]=this.quill.getLine(n.index),s=M.import("blots/block");if(!s?.bubbleFormats)return true;let r=s.bubbleFormats(a),o=new Delta().retain(n.index).delete(n.length).insert(`
4
+ `,r);return this.quill.updateContents(o,M.sources.USER),this.quill.setSelection(n.index+1,M.sources.SILENT),false}}}}}}),this.app_?.editor&&(this.app_.editor.quill=this.quill),this.registerFonts(),this.quill}getQuill(){return this.S?this.quill:null}getCanvas(){return this.S?this.app_:null}getSelection(){return this.S?this.selectionRange?this.selectionRange:this.quill?.getSelection()||this.quill?.selection?.savedRange||null:null}setSelection(i){this.selectionRange=i;}clearSelection(){this.selectionRange=null;}registerFonts(){this.S&&(FontStyle.whitelist=void 0,M.register("formats/font",FontStyle,true));}isMultiSelect(){return !this.S||!this.app_?.editor?false:this.app_.editor.multiple===true}dateEdit(i,t=0,n){let{editor:a}=this.app_||{};if(!a)return;let s=n||a.leafList?.list,r=o=>{t&&(o.tag==="Box"||o.name==="Text")?i(o.children?.[0]||o):i(o);};if(s?.length)if(Array.isArray(s)&&s.length>1){this.app_.lockLayout();let o=s.length*this.S;for(let l=0;l<o;l++)r(s[l]);this.app_.unlockLayout(),a.updateEditBox();}else this.S&&r(s[0]);}},u=X.getInstance();var ne=HTMLText.prototype.__updateBoxBounds;HTMLText.prototype.__updateBoxBounds=function(){let e=this.__;if(e.__htmlChanged){let i=document.createElement("div"),{style:t}=i,n=this.text?.replace(/&nbsp;/g,"\xA0")??"";t.all="initial",t.position="absolute",t.visibility="hidden",t.whiteSpace="pre-wrap",t.wordBreak="break-word",t.overflowWrap="break-word",t.display="inline-block",i.innerHTML=n,document.body.appendChild(i);let{width:a,height:s}=i.getBoundingClientRect();if(i.remove(),a===0||s===0){e.__htmlChanged=false;return}let r=Math.ceil(a)+1;n.includes("<em>")&&(r+=10);let o=`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${s}"><foreignObject width="${r}" height="${s}"><style>*{margin:0;padding:0;box-sizing:border-box;}</style><body xmlns="http://www.w3.org/1999/xhtml">${n}</body></foreignObject></svg>`;e.__setImageFill("data:image/svg+xml,"+encodeURIComponent(o)),e.__naturalWidth=r/(e.pixelRatio??1),e.__naturalHeight=s/(e.pixelRatio??1),e.__htmlChanged=false;}ne.call(this);};var $=class extends Box{get __tag(){return "HtmlText"}constructor(i){let{text:t,fontSize:n,fontFamily:a,lineHeight:s,letterSpacing:r,textShadow:o,alignContent:l,...c}=i||{};super({editOuter:"TextEditTool",name:"HtmlText",x:0,y:0,editable:true,draggable:true,overflow:"show",...c}),i&&this.createTextElement(i);}createTextElement(i){let{text:t,fontSize:n,fontFamily:a,lineHeight:s,letterSpacing:r,textShadow:o,alignContent:l}=i,c="<style>p{margin:0;}sub,sup{font-size:63%;}.ql-ui{position:absolute}ol,ul{counter-reset:list-0;padding-left:1.5em;margin:0}ol>li,ul>li{counter-increment:list-0;list-style-type:none;position:relative;padding-left:0;margin:0}ol>li::before{content:counter(list-0,decimal) '. ';position:absolute;left:-1.5em;width:1.2em;text-align:right}ul>li::before{content:'\u2022';position:absolute;left:-1.5em;width:1.2em;text-align:right}li[data-list]{counter-set:list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-align-center{text-align:center}.ql-align-right{text-align:right}.ql-align-left{text-align:left}.ql-align-justify{text-align:justify}</style>",d=`<div style="ove
5
+ rflow-wrap:break-word;word-break:break-all;"><p style="font-size: ${n}px; line-height: ${s}; letter-spacing: ${r}px; text-shadow: ${o};"><strong>Hello World</strong></p></div>`;if(i.children?.length>0)return;let h=new HTMLText({name:"Text",text:c+(t||d),x:0,y:0,data:{canChangeBox:false,textData:{fontFamily:a,fontSize:n,lineHeight:s,letterSpacing:r||0,textShadow:o,alignContent:l}},editConfig:{selectedStyle:{strokeWidth:0}}});this.add(h);}};$=v([registerUI()],$);export{$ as HtmlText,K as checkLicense,D as getHTMLTextZoomScale,Q as getLicenseInfo,u as htmlTextManage,we as setHTMLText,Ct as setLicense,k as syncInnerEditorLetterSpacing,j as syncInnerEditorVerticalLayout,f as updataHtmlText};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenyomi/leafer-htmltext-edit",
3
- "version": "2.4.3",
3
+ "version": "2.4.6",
4
4
  "description": "A text editor plugin for Leafer UI with HTML text support",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",