@chenyomi/leafer-htmltext-edit 2.4.1 → 2.4.3

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,4 +1,5 @@
1
- 'use strict';var editor=require('@leafer-in/editor'),leaferUi=require('leafer-ui'),S=require('crypto-js'),core=require('@leafer-ui/core'),w=require('quill');require('quill/dist/quill.core.css');var font=require('quill/formats/font'),html=require('@leafer-in/html');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var S__default=/*#__PURE__*/_interopDefault(S);var w__default=/*#__PURE__*/_interopDefault(w);var b=(t,i,n,e)=>{for(var o=i,s=t.length-1,a;s>=0;s--)(a=t[s])&&(o=(a(o))||o);return o};function P(t){let e=new DOMParser().parseFromString(t,"text/html").body;function o(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 d of Array.from(r.childNodes))o(d).forEach((f,h)=>{let g=r.cloneNode(false);g.appendChild(f),l.push(g);});return l}return []}let s=[];for(let r of Array.from(e.childNodes)){let l=o(r);s.push(...l);}let a=document.createElement("div");return s.forEach((r,l)=>{a.appendChild(r);}),a.innerHTML}var k="LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxaUFnU1hWM3dMKzh2YkZ2OVkwQwpEN1dBUjhPa2I4bjlmTWxpQjF3enZodTBrdVdZUWEvMUxvVDhHWVh6WWlRQVFBRk9zTTA0MGp2dlNRT2hRSWpiCjRaYXZ1NHUvWVA5bElPYjFKYnZnYkFoYVVOQnphL0l2UmFnaFlKYTJBc1cyRVhnZkVrdmMyUENNMS9zbVlFNnoKNjZiUmx1dnREK3FJZkpLVCtUUXJRRmp5TnNTZ0c2Z2R4MThrZTRMSStBejFPcklMbUsyMHlBU2tlRXpYT1BTVAplM3RNYThleHpZdmUzV0wyNHRHUHg5WHNvN1JyUEl1elZlajh0NDYrZ0c1Y0pQaVh0N1lqa0V2NEJOUUt5eUpoCkltOVRJdVZ6clFpa2NJNE14dExNSGdUMHpLcU9ZZ1NzcmEvTHNDd2ZOdzdtYWxITkU2c21YZWYyQ2E5RGhZODQKS1FJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==";function Z(t){let i=t.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");return _(i)}function _(t){let i=atob(t),n=new Uint8Array(i.length);for(let e=0;e<i.length;e++)n[e]=i.charCodeAt(e);return n.buffer}async function J(){let t=atob(k),i=Z(t);return await crypto.subtle.importKey("spki",i,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},false,["verify"])}async function z(t,i){try{let n=await J(),e=new TextEncoder().encode(t),o=_(i);return await crypto.subtle.verify("RSASSA-PKCS1-v1_5",n,o,e)}catch{return false}}var R="c19496eb17719960b6c3cebab0ef5eddfce5d0315ab8c5af86a52fbda434fea9",V="ce1e3e8974f1392b3c5803b34ecf659f";function $(t){try{let i=S__default.default.enc.Hex.parse(R),n=S__default.default.enc.Hex.parse(V),o=S__default.default.AES.decrypt(t,i,{iv:n,mode:S__default.default.mode.CBC,padding:S__default.default.pad.Pkcs7}).toString(S__default.default.enc.Utf8);if(!o)throw new Error("Decryption resulted in empty string - invalid ciphertext or wrong key");return o}catch(i){throw i}}async function j(t){try{let i=atob(t),n=JSON.parse(i);if(!n.data||!n.signature||!await z(n.data,n.signature))return null;let o=n.data;if(n.encrypted)try{o=$(n.data);}catch{return null}return JSON.parse(o)}catch{return null}}function X(t){if(!t||t.length===0)return true;let i=window.location.hostname;if(i==="localhost"||i==="127.0.0.1")return true;let n=t.some(e=>{if(e.startsWith("*.")){let o=e.slice(2);return i.endsWith(o)}return i===e});return n}function G(t){if(!t)return true;try{let i=new Date(t),n=new Date;return n>=i?!1:(Math.ceil((i.getTime()-n.getTime())/(1e3*60*60*24))<=7,!0)}catch{return false}}function tt(t){if(!t)return true;try{return !(new Date(t)>new Date)}catch{return true}}async function B(t){try{let i=await j(t);return i?tt(i.issueDate)?X(i.domains)?G(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 E=null,v=null,m=0;async function et(t){let i=await B(t);return i.valid&&i.data?(E=t,v=i.data,m=1,true):(E=null,v=null,m=0,false)}async function I(){return !E||!m?0:(m=(await B(E)).valid?1:0,m||(v=null),m)}function U(){return m?v:null}var p=async(t,i,n)=>{let{scaleX:e,scaleY:o}=t.worldTransform,s=Math.max(Math.abs(e),Math.abs(o)),a=document.querySelector("#textInnerEditor");if(a&&t.data.textData?.fontSize&&(a.style.fontSize=`${t.data.textData.fontSize*s}px`),a&&t.data.textData?.lineHeight&&(a.style.lineHeight=t.data.textData.lineHeight),a&&t.data.textData?.letterSpacing&&(a.style.letterSpacing=`${t.data.textData.letterSpacing}px`),a&&t.data.textData?.textShadow?a.style.textShadow=t.data.textData.textShadow:a.style.textShadow="none",a&&t.data.textData?.textStroke?(a.style.paintOrder="stroke fill",a.style.WebkitTextStroke=nt(t.data.textData.textStroke,s)):(a.style.paintOrder="unset",a.style.WebkitTextStroke="unset"),a&&t.data.textData?.alignContent){let d=a.querySelector(".ql-editor");d.style.alignContent=t.data.textData.alignContent;}let l=c.getQuill().getSemanticHTML();if(l==="<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 d=t.text.split("</style>")[0];if(n&&!d.includes(n)){let u=`@font-face {font-family: ${n.split(",")[0]};src: url(${i}) format('woff2') }</style>`;t.text=d+u+M(t,l,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=d+"</style>"+M(t,l,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&&n){let d=`<style>@font-face {font-family: ${n.split(",")[0]};src: url(${i}) format('woff2') }</style>`;t.text=d+M(t,l,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=M(t,l,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent,t.data.textData.textStroke);},M=(t,i,n=20.67,e=1.5,o=0,s="none",a="start",r="unset")=>{let{scaleX:l,scaleY:d}=t.worldTransform,u=Math.max(Math.abs(l),Math.abs(d)),f=document.createElement("div");f.innerHTML=i;let h={fontSize:`${n}px`,lineHeight:e,letterSpacing:`${o}px`,textShadow:s};r!=="unset"?(h.paintOrder="stroke fill",h.WebkitTextStroke=r):(h.paintOrder="unset",h.WebkitTextStroke="unset"),f.querySelectorAll("p,ol,ul").forEach(Y=>{Object.assign(Y.style,h);});let g=f.innerHTML;/<p\b[^>]*><\/p>/.test(g)&&(g=g.replace(/<p\b([^>]*)><\/p>/g,"<p$1>&nbsp;</p>")),/&quot;/.test(g)&&(g=g.replace(/&quot;/g,""));let x;document.querySelector("#textInnerEditor");let y=c.getQuill(),D=Number((y.scroll.domNode.scrollHeight/u).toFixed(0));Number((y.scroll.domNode.scrollWidth/u).toFixed(0));["center","end"].includes(t.data.textData.alignContent)?t.parent.height<D?x=(D||t.__layout.boxBounds.height)+"px":x=`${t.parent.height}px`:t.parent.height<D?x=(D||t.__layout.boxBounds.height)+"px":x=`${t.parent.height}px`;let L="<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>",T="";return t.parent.children[0].tag.includes("Shape")?T=L+`<div style="width: ${t.parent.width}px;height: ${t.parent.height}px;overflow-wrap:break-word;word-break:break-all;align-content:center;">${g}</div>`:t.data.canChangeBox?T=L+`<div style="width: ${t.parent.width}px;height:${x};overflow-wrap:break-word;word-break:break-all;align-content:${a};">${g}</div>`:t.data.textData.italic?T=L+g:T=L+`<div style="overflow-wrap:break-word;word-break:break-all;">${g}</div>`,T},At=(t,i,n)=>{let e=c.getQuill(),{editor:o,canvas:s}=c.getCanvas();if(!e)return;i===0&&(i="0");let a=e.selection.savedRange;c.dateEdit(async r=>{if(r.tag==="HTMLText")if(t==="font")o.innerEditing?(a&&a.length?e.formatText(a.index,a.length,t,i):e.formatText(0,e.getLength()-1,t,i),r.data.textData.fontFamily=i,p(r,n??null,i??null)):(c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),e.formatText(0,e.getLength()-1,t,i),r.data.textData.fontFamily=i,p(r,n??null,i??null));else if(t==="fontSize")r.data.textData[t]=i,c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),p(r,n??null);else if(t==="textCase"){if(o.innerEditing){let l=e.getText(a.index,a.length),d=e.getFormat(a.index,a.length);e.deleteText(a.index,a.length);let u;l===l.toUpperCase()&&/[A-Z]/.test(l)?u=l.toLowerCase():(l===l.toLowerCase()&&/[a-z]/.test(l),u=l.toUpperCase()),e.insertText(a.index,u,d),a&&o.innerEditing&&e.setSelection(a.index,a.length);}}else if(t==="script"){let l="sub";i==="super"&&(l="sup"),o.innerEditing?a&&a.length?e.formatText(a.index,a.length,t,e.getFormat(a).script===i?false:l):e.formatText(0,e.getLength()-1,t,e.getFormat().script===i?false:l):(c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),e.formatText(0,e.getLength()-1,t,e.getFormat().script===i?false:l),p(r));}else if(t==="align")c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),o.innerEditing?e.format(t,i):e.formatLine(0,e.getLength(),t,i),p(r);else if(t==="alignContent")c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=i,p(r);else if(t==="lineHeight"||t==="letterSpacing")c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=i,p(r);else if(t==="color")c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),a&&a.length?e.formatText(a.index,a.length,t,i):e.formatText(0,e.getLength()-1,t,i),r.tag==="HTMLText"?p(r):r.parent.findOne("HTMLText")&&p(r.parent.findOne("HTMLText"));else if(t==="textShadow"||t==="textStroke")c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=i,p(r);else if(t==="list"){if(c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),o.innerEditing){let[l]=e.getLine(a?.index||0);l.formats().list?e.format(t,false):e.format(t,i);}else {let[l]=e.getLine(a?.index||0);l.formats().list?e.formatLine(0,e.getLength(),t,false):e.formatLine(0,e.getLength(),t,i);}p(r);}else if(t==="textVertical"){let l=U();if(l&&l?.features?.length&&l?.features?.includes("textVertical")){e.clipboard.dangerouslyPasteHTML(r.text);let d=e.getSemanticHTML();e.clipboard.dangerouslyPasteHTML(P(d)),r.data.textData.align="center",p(r);}}else o.innerEditing?a&&a.length?e.formatText(a.index,a.length,t,i===void 0?!e.getFormat(a)[t]:i):e.formatText(0,e.getLength()-1,t,i===void 0?!e.getFormat()[t]:i):(c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),e.formatText(0,e.getLength()-1,t,i===void 0?!e.getFormat()[t]:i),p(r));},1);};function nt(t,i){return t.replace(/(-?\d*\.?\d+)px/g,(n,e)=>Number(e)*i+"px")}var C=class extends editor.EditTool{constructor(n){super(n);this.quill=null;this.isUpdatingPoints=false;this.curveAmount=0;this.eventIds=[],this.updateBoxDebounced=this.debounce(e=>{p(e);},300);}get tag(){return "TextEditTool"}debounce(n,e){let o=null;return((...s)=>{o!==null&&window.clearTimeout(o),o=window.setTimeout(()=>n.apply(this,s),e);})}addEvent(){let{editor:n}=c.getCanvas();if(n.multiple)return;let e=n.leafList.list[0].findOne("HTMLText");if(!e)return;let{scaleX:o,scaleY:s}=e.worldTransform,a=Math.max(Math.abs(o),Math.abs(s)),r=document.querySelector("#textInnerEditor"),{style:l}=r;this.eventIds=[n.on_(editor.EditorScaleEvent.SCALE,d=>{e.data.canChangeBox||(e.data.canChangeBox=true),e.data.canChangeBox&&(l.width=e.parent.width*a+"px",l.height="auto");let u=1;e.parent.tag==="HtmlText"&&e.parent.lockRatio&&e.data?.baseSize?.width&&(u=e.parent.width/e.data?.baseSize.width,e.data.textData.fontSize=e.data.textData.fontSize*u),e.data?.baseSize?.width&&(e.data.baseSize.width=e.parent.width),this.updateBoxDebounced(e);}),n.on_(leaferUi.PointerEvent.DOUBLE_TAP,()=>{e.parent.locked||n.openInnerEditor(e,true);})];}onLoad(){let{editor:n}=c.getCanvas();if(n.multiple)return;let e=n.leafList.list[0].findOne("HTMLText");if(!e)return;let{scaleX:o,scaleY:s}=e.worldTransform,a=Math.max(Math.abs(o),Math.abs(s));this.addEvent(),this.quill=c.getQuill(),this.quill.clipboard.dangerouslyPasteHTML(e.text);let r=document.querySelector("#textInnerEditor"),{style:l}=r;e.data.canChangeBox?(l.width=e.parent.width*a+"px",l.height=e.parent.height*a+"px"):(l.width="auto",l.height="auto");}updateChangeBoxBound(n){n&&n.set({width:n.__layout.boxBounds.width,height:n.__layout.boxBounds.height});}onUpdate(){let{editor:n}=c.getCanvas();if(n.multiple)return;let e=n.leafList.list[0].findOne("HTMLText");e&&this.curveAmount!=e.curveAmount&&this.isUpdatingPoints;}onUnload(){let{editor:n}=c.getCanvas();n.off_(this.eventIds);}onDestroy(){}};C=b([editor.registerEditTool()],C);var H=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.n=void 0;this.quill=null;this.isComposing=false;this.onInput=async()=>{let{editDom:n}=this;p(this.editTarget);};this.isUpdatingPoints=false;}get tag(){return "TextEditor"}onLoad(){let{editor:n}=this,{config:e}=n.app,o=this.editTarget,{scaleX:s,scaleY:a}=o.worldTransform,r=Math.max(Math.abs(s),Math.abs(a));this.isHTMLText=!(o instanceof Text),this.n=e.keyEvent,e.keyEvent=false;let l=this.editDom=document.querySelector("#textInnerEditor"),{style:d}=l;if(d.visibility="visible",o.data.canChangeBox?(d.width=o.parent.width*r+"px",d.height=o.parent.height*r+"px"):(d.width="auto",d.height="auto"),d.outline="solid #8499EF",o.data.textData.fontSize&&(l.style.fontSize=`${o.data.textData.fontSize*r}px`),o.data.textData.lineHeight&&(l.style.lineHeight=o.data.textData.lineHeight),o.data.textData.letterSpacing&&(l.style.letterSpacing=`${o.data.textData.letterSpacing}px`),o.data.textData.textShadow?l.style.textShadow=O(o.data.textData.textShadow,r):l.style.textShadow="none",o.data.textData.textStroke?(l.style.paintOrder="stroke fill",l.style.WebkitTextStroke=O(o.data.textData.textStroke,r)):(l.style.paintOrder="unset",l.style.WebkitTextStroke="unset"),o.data.textData.alignContent){let u=l.querySelector(".ql-editor");u.style.alignContent=`${o.data.textData.alignContent}`;}this.quill=c.getQuill(),this.quill.clipboard.dangerouslyPasteHTML(o.text),o.parent.children[0].tag.includes("Shape")?(d.width=o.parent.width*r+"px",d.left="0px",this.quill.formatLine(0,this.quill.getLength(),"align","center")):this.quill.setSelection(0,this.quill.getLength()-1),this.quill.on("text-change",this.onInput),this.eventIds=[n.app.on_(core.PointerEvent.DOWN,u=>{let{target:f}=u.origin,h=false;for(;f;)f===l&&(h=true),f=f.parentElement;h||(n.closeInnerEditor(),n.cancel());})];}onUpdate(){let{editTarget:n}=this,{scaleX:e,scaleY:o}=n.worldTransform,s=Math.max(Math.abs(e),Math.abs(o)),{width:a,height:r}=n.parent.__local;a*=s,r*=s;let{x:l,y:d}=this.inBody?n.app.clientBounds:n.app.tree.clientBounds,{a:u,b:f,c:h,d:g,e:x,f:F}=new core.Matrix(n.worldTransform).scale(1/s).translateInner(0,0),{style:y}=this.editDom;y.transform=`matrix(${u},${f},${h},${g},${x},${F})`,y.left=l+"px",y.top=d+"px",n.set({visible:false});}onUnload(){let{editTarget:n,editor:e,editDom:o}=this;n&&(this.onInput(),e.app&&(e.app.config.keyEvent=this.n),e.off_(this.eventIds),this.editDom.style.visibility="hidden",this.eventIds=[]),n.parent&&n.parent.name=="Text"&&n.parent.children.some(s=>s.tag==="Box")?(n.parent.findOne("Box").opacity=1,n.visible=false):n.set({visible:true}),this.quill.getLength()===1&&n.parent.name==="Text"&&n.parent.remove(),this.quill.off("text-change",this.onInput);}};H=b([editor.registerInnerEditor()],H);function O(t,i){return t.replace(/(-?\d*\.?\d+)px/g,(n,e)=>Number(e)*i+"px")}function A(t,{insertAt:i}={}){if(typeof document>"u")return;let n=document.head||document.getElementsByTagName("head")[0],e=document.createElement("style");e.type="text/css",i==="top"&&n.firstChild?n.insertBefore(e,n.firstChild):n.appendChild(e),e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t));}A(`.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}
2
- `);var N=class t{constructor(){this.quill=null;this.app_=null;this.t=0;}static getInstance(){return t.instance||(t.instance=new t),t.instance}async init(i){if(this.t=await I(),this.app_=this.t?i:null,this.quill)return this.quill;let n=document.getElementById("textInnerEditor");if(n)this.quill=this.app_?.editor?.quill||null;else return n=document.createElement("div"),n.id="textInnerEditor",n.style.position="fixed",n.style.transformOrigin="left top",n.style.overflowWrap="break-word",n.style.wordBreak="break-all",n.style.visibility="hidden",document.body.appendChild(n),this.quill=new w__default.default("#textInnerEditor",{theme:void 0,modules:{toolbar:false,keyboard:{bindings:{enter:{key:"Enter",handler:e=>{if(!this.t)return true;let[o]=this.quill.getLine(e.index),s=w__default.default.import("blots/block");if(!s?.bubbleFormats)return true;let a=s.bubbleFormats(o),r=new w.Delta().retain(e.index).delete(e.length).insert(`
3
- `,a);return this.quill.updateContents(r,w__default.default.sources.USER),this.quill.setSelection(e.index+1,w__default.default.sources.SILENT),false}}}}}}),this.app_?.editor&&(this.app_.editor.quill=this.quill),this.registerFonts(),this.quill}getQuill(){return this.t?this.quill:null}getCanvas(){return this.t?this.app_:null}getSelection(){return this.t?this.quill?.selection.savedRange:null}registerFonts(){this.t&&(font.FontStyle.whitelist=void 0,w__default.default.register("formats/font",font.FontStyle,true));}isMultiSelect(){return !this.t||!this.app_?.editor?false:this.app_.editor.multiple===true}dateEdit(i,n=0,e){let{editor:o}=this.app_||{};if(!o)return;let s=e||o.leafList?.list,a=r=>{n&&(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.t;for(let l=0;l<r;l++)a(s[l]);this.app_.unlockLayout(),o.updateEditBox();}else this.t&&a(s[0]);}},c=N.getInstance();exports.HtmlText=class q extends core.Box{get __tag(){return "HtmlText"}constructor(i){let{text:n,fontSize:e,fontFamily:o,lineHeight:s,letterSpacing:a,textShadow:r,alignContent:l,...d}=i||{};super({editOuter:"TextEditTool",name:"HtmlText",x:0,y:0,editable:true,draggable:true,overflow:"show",...d}),i&&this.createTextElement(i);}createTextElement(i){let{text:n,fontSize:e,fontFamily:o,lineHeight:s,letterSpacing:a,textShadow:r,alignContent:l}=i,d="<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
4
- rflow-wrap:break-word;word-break:break-all;"><p style="font-size: ${e}px; line-height: ${s}; letter-spacing: ${a}px; text-shadow: ${r};"><strong>Hello World</strong></p></div>`;if(i.children?.length>0)return;let f=new html.HTMLText({name:"Text",text:d+(n||u),x:0,y:0,data:{canChangeBox:false,textData:{fontFamily:o,fontSize:e,lineHeight:s,letterSpacing:a||0,textShadow:r,alignContent:l}},editConfig:{selectedStyle:{strokeWidth:0}}});this.add(f);}};exports.HtmlText=b([core.registerUI()],exports.HtmlText);exports.checkLicense=I;exports.getLicenseInfo=U;exports.htmlTextManage=c;exports.setHTMLText=At;exports.setLicense=et;exports.updataHtmlText=p;
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;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
- import * as Quill from 'quill';
2
- import Quill__default from 'quill';
1
+ import Quill from 'quill';
3
2
  import { Box } from '@leafer-ui/core';
4
3
  import { IBoxInputData } from '@leafer-ui/interface';
5
4
 
@@ -8,18 +7,30 @@ declare class HtmlTextManage {
8
7
  private quill;
9
8
  app_: any | null;
10
9
  private _m;
10
+ private selectionRange;
11
11
  private constructor();
12
12
  static getInstance(): HtmlTextManage;
13
- init(app: any): Promise<Quill__default | undefined>;
14
- getQuill(): Quill__default | null;
13
+ init(app: any): Promise<Quill | undefined>;
14
+ getQuill(): Quill | null;
15
15
  getCanvas(): any;
16
- getSelection(): Quill.Range | null | undefined;
16
+ getSelection(): {
17
+ index: number;
18
+ length: number;
19
+ } | null;
20
+ setSelection(range: {
21
+ index: number;
22
+ length: number;
23
+ } | null): void;
24
+ clearSelection(): void;
17
25
  private registerFonts;
18
26
  isMultiSelect(): boolean;
19
27
  dateEdit(callback: (leaf: any) => void, level?: number, listNew?: any): void;
20
28
  }
21
29
  declare const htmlTextManage: HtmlTextManage;
22
30
 
31
+ declare const syncInnerEditorLetterSpacing: (dom: HTMLElement | null, letterSpacing: string | number | undefined, zoomScale: number) => void;
32
+ declare const getHTMLTextZoomScale: (text: any) => number;
33
+ declare const syncInnerEditorVerticalLayout: (dom: HTMLElement | null, alignContent: string | undefined, shouldUseFixedHeightLayout: boolean) => void;
23
34
  declare const updataHtmlText: (e?: any, base64font?: any, fontObj?: any) => Promise<void>;
24
35
  declare const setHTMLText: (key: string, value?: any, base64font?: any) => void;
25
36
 
@@ -77,4 +88,4 @@ declare function checkLicense(): Promise<number>;
77
88
  */
78
89
  declare function getLicenseInfo(): LicenseData | null;
79
90
 
80
- export { HtmlText, type LicenseData, checkLicense, getLicenseInfo, htmlTextManage, setHTMLText, setLicense, updataHtmlText };
91
+ export { HtmlText, type LicenseData, checkLicense, getHTMLTextZoomScale, getLicenseInfo, htmlTextManage, setHTMLText, setLicense, syncInnerEditorLetterSpacing, syncInnerEditorVerticalLayout, updataHtmlText };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import * as Quill from 'quill';
2
- import Quill__default from 'quill';
1
+ import Quill from 'quill';
3
2
  import { Box } from '@leafer-ui/core';
4
3
  import { IBoxInputData } from '@leafer-ui/interface';
5
4
 
@@ -8,18 +7,30 @@ declare class HtmlTextManage {
8
7
  private quill;
9
8
  app_: any | null;
10
9
  private _m;
10
+ private selectionRange;
11
11
  private constructor();
12
12
  static getInstance(): HtmlTextManage;
13
- init(app: any): Promise<Quill__default | undefined>;
14
- getQuill(): Quill__default | null;
13
+ init(app: any): Promise<Quill | undefined>;
14
+ getQuill(): Quill | null;
15
15
  getCanvas(): any;
16
- getSelection(): Quill.Range | null | undefined;
16
+ getSelection(): {
17
+ index: number;
18
+ length: number;
19
+ } | null;
20
+ setSelection(range: {
21
+ index: number;
22
+ length: number;
23
+ } | null): void;
24
+ clearSelection(): void;
17
25
  private registerFonts;
18
26
  isMultiSelect(): boolean;
19
27
  dateEdit(callback: (leaf: any) => void, level?: number, listNew?: any): void;
20
28
  }
21
29
  declare const htmlTextManage: HtmlTextManage;
22
30
 
31
+ declare const syncInnerEditorLetterSpacing: (dom: HTMLElement | null, letterSpacing: string | number | undefined, zoomScale: number) => void;
32
+ declare const getHTMLTextZoomScale: (text: any) => number;
33
+ declare const syncInnerEditorVerticalLayout: (dom: HTMLElement | null, alignContent: string | undefined, shouldUseFixedHeightLayout: boolean) => void;
23
34
  declare const updataHtmlText: (e?: any, base64font?: any, fontObj?: any) => Promise<void>;
24
35
  declare const setHTMLText: (key: string, value?: any, base64font?: any) => void;
25
36
 
@@ -77,4 +88,4 @@ declare function checkLicense(): Promise<number>;
77
88
  */
78
89
  declare function getLicenseInfo(): LicenseData | null;
79
90
 
80
- export { HtmlText, type LicenseData, checkLicense, getLicenseInfo, htmlTextManage, setHTMLText, setLicense, updataHtmlText };
91
+ export { HtmlText, type LicenseData, checkLicense, getHTMLTextZoomScale, getLicenseInfo, htmlTextManage, setHTMLText, setLicense, syncInnerEditorLetterSpacing, syncInnerEditorVerticalLayout, updataHtmlText };
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import {registerEditTool,registerInnerEditor,EditTool,EditorScaleEvent,InnerEditor}from'@leafer-in/editor';import {PointerEvent}from'leafer-ui';import S from'crypto-js';import {registerUI,Box,PointerEvent as PointerEvent$1,Matrix}from'@leafer-ui/core';import w,{Delta}from'quill';import'quill/dist/quill.core.css';import {FontStyle}from'quill/formats/font';import {HTMLText}from'@leafer-in/html';var b=(t,i,n,e)=>{for(var o=i,s=t.length-1,a;s>=0;s--)(a=t[s])&&(o=(a(o))||o);return o};function P(t){let e=new DOMParser().parseFromString(t,"text/html").body;function o(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 d of Array.from(r.childNodes))o(d).forEach((f,h)=>{let g=r.cloneNode(false);g.appendChild(f),l.push(g);});return l}return []}let s=[];for(let r of Array.from(e.childNodes)){let l=o(r);s.push(...l);}let a=document.createElement("div");return s.forEach((r,l)=>{a.appendChild(r);}),a.innerHTML}var k="LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxaUFnU1hWM3dMKzh2YkZ2OVkwQwpEN1dBUjhPa2I4bjlmTWxpQjF3enZodTBrdVdZUWEvMUxvVDhHWVh6WWlRQVFBRk9zTTA0MGp2dlNRT2hRSWpiCjRaYXZ1NHUvWVA5bElPYjFKYnZnYkFoYVVOQnphL0l2UmFnaFlKYTJBc1cyRVhnZkVrdmMyUENNMS9zbVlFNnoKNjZiUmx1dnREK3FJZkpLVCtUUXJRRmp5TnNTZ0c2Z2R4MThrZTRMSStBejFPcklMbUsyMHlBU2tlRXpYT1BTVAplM3RNYThleHpZdmUzV0wyNHRHUHg5WHNvN1JyUEl1elZlajh0NDYrZ0c1Y0pQaVh0N1lqa0V2NEJOUUt5eUpoCkltOVRJdVZ6clFpa2NJNE14dExNSGdUMHpLcU9ZZ1NzcmEvTHNDd2ZOdzdtYWxITkU2c21YZWYyQ2E5RGhZODQKS1FJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==";function Z(t){let i=t.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");return _(i)}function _(t){let i=atob(t),n=new Uint8Array(i.length);for(let e=0;e<i.length;e++)n[e]=i.charCodeAt(e);return n.buffer}async function J(){let t=atob(k),i=Z(t);return await crypto.subtle.importKey("spki",i,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},false,["verify"])}async function z(t,i){try{let n=await J(),e=new TextEncoder().encode(t),o=_(i);return await crypto.subtle.verify("RSASSA-PKCS1-v1_5",n,o,e)}catch{return false}}var R="c19496eb17719960b6c3cebab0ef5eddfce5d0315ab8c5af86a52fbda434fea9",V="ce1e3e8974f1392b3c5803b34ecf659f";function $(t){try{let i=S.enc.Hex.parse(R),n=S.enc.Hex.parse(V),o=S.AES.decrypt(t,i,{iv:n,mode:S.mode.CBC,padding:S.pad.Pkcs7}).toString(S.enc.Utf8);if(!o)throw new Error("Decryption resulted in empty string - invalid ciphertext or wrong key");return o}catch(i){throw i}}async function j(t){try{let i=atob(t),n=JSON.parse(i);if(!n.data||!n.signature||!await z(n.data,n.signature))return null;let o=n.data;if(n.encrypted)try{o=$(n.data);}catch{return null}return JSON.parse(o)}catch{return null}}function X(t){if(!t||t.length===0)return true;let i=window.location.hostname;if(i==="localhost"||i==="127.0.0.1")return true;let n=t.some(e=>{if(e.startsWith("*.")){let o=e.slice(2);return i.endsWith(o)}return i===e});return n}function G(t){if(!t)return true;try{let i=new Date(t),n=new Date;return n>=i?!1:(Math.ceil((i.getTime()-n.getTime())/(1e3*60*60*24))<=7,!0)}catch{return false}}function tt(t){if(!t)return true;try{return !(new Date(t)>new Date)}catch{return true}}async function B(t){try{let i=await j(t);return i?tt(i.issueDate)?X(i.domains)?G(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 E=null,v=null,m=0;async function et(t){let i=await B(t);return i.valid&&i.data?(E=t,v=i.data,m=1,true):(E=null,v=null,m=0,false)}async function I(){return !E||!m?0:(m=(await B(E)).valid?1:0,m||(v=null),m)}function U(){return m?v:null}var p=async(t,i,n)=>{let{scaleX:e,scaleY:o}=t.worldTransform,s=Math.max(Math.abs(e),Math.abs(o)),a=document.querySelector("#textInnerEditor");if(a&&t.data.textData?.fontSize&&(a.style.fontSize=`${t.data.textData.fontSize*s}px`),a&&t.data.textData?.lineHeight&&(a.style.lineHeight=t.data.textData.lineHeight),a&&t.data.textData?.letterSpacing&&(a.style.letterSpacing=`${t.data.textData.letterSpacing}px`),a&&t.data.textData?.textShadow?a.style.textShadow=t.data.textData.textShadow:a.style.textShadow="none",a&&t.data.textData?.textStroke?(a.style.paintOrder="stroke fill",a.style.WebkitTextStroke=nt(t.data.textData.textStroke,s)):(a.style.paintOrder="unset",a.style.WebkitTextStroke="unset"),a&&t.data.textData?.alignContent){let d=a.querySelector(".ql-editor");d.style.alignContent=t.data.textData.alignContent;}let l=c.getQuill().getSemanticHTML();if(l==="<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 d=t.text.split("</style>")[0];if(n&&!d.includes(n)){let u=`@font-face {font-family: ${n.split(",")[0]};src: url(${i}) format('woff2') }</style>`;t.text=d+u+M(t,l,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=d+"</style>"+M(t,l,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&&n){let d=`<style>@font-face {font-family: ${n.split(",")[0]};src: url(${i}) format('woff2') }</style>`;t.text=d+M(t,l,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=M(t,l,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent,t.data.textData.textStroke);},M=(t,i,n=20.67,e=1.5,o=0,s="none",a="start",r="unset")=>{let{scaleX:l,scaleY:d}=t.worldTransform,u=Math.max(Math.abs(l),Math.abs(d)),f=document.createElement("div");f.innerHTML=i;let h={fontSize:`${n}px`,lineHeight:e,letterSpacing:`${o}px`,textShadow:s};r!=="unset"?(h.paintOrder="stroke fill",h.WebkitTextStroke=r):(h.paintOrder="unset",h.WebkitTextStroke="unset"),f.querySelectorAll("p,ol,ul").forEach(Y=>{Object.assign(Y.style,h);});let g=f.innerHTML;/<p\b[^>]*><\/p>/.test(g)&&(g=g.replace(/<p\b([^>]*)><\/p>/g,"<p$1>&nbsp;</p>")),/&quot;/.test(g)&&(g=g.replace(/&quot;/g,""));let x;document.querySelector("#textInnerEditor");let y=c.getQuill(),D=Number((y.scroll.domNode.scrollHeight/u).toFixed(0));Number((y.scroll.domNode.scrollWidth/u).toFixed(0));["center","end"].includes(t.data.textData.alignContent)?t.parent.height<D?x=(D||t.__layout.boxBounds.height)+"px":x=`${t.parent.height}px`:t.parent.height<D?x=(D||t.__layout.boxBounds.height)+"px":x=`${t.parent.height}px`;let L="<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>",T="";return t.parent.children[0].tag.includes("Shape")?T=L+`<div style="width: ${t.parent.width}px;height: ${t.parent.height}px;overflow-wrap:break-word;word-break:break-all;align-content:center;">${g}</div>`:t.data.canChangeBox?T=L+`<div style="width: ${t.parent.width}px;height:${x};overflow-wrap:break-word;word-break:break-all;align-content:${a};">${g}</div>`:t.data.textData.italic?T=L+g:T=L+`<div style="overflow-wrap:break-word;word-break:break-all;">${g}</div>`,T},At=(t,i,n)=>{let e=c.getQuill(),{editor:o,canvas:s}=c.getCanvas();if(!e)return;i===0&&(i="0");let a=e.selection.savedRange;c.dateEdit(async r=>{if(r.tag==="HTMLText")if(t==="font")o.innerEditing?(a&&a.length?e.formatText(a.index,a.length,t,i):e.formatText(0,e.getLength()-1,t,i),r.data.textData.fontFamily=i,p(r,n??null,i??null)):(c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),e.formatText(0,e.getLength()-1,t,i),r.data.textData.fontFamily=i,p(r,n??null,i??null));else if(t==="fontSize")r.data.textData[t]=i,c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),p(r,n??null);else if(t==="textCase"){if(o.innerEditing){let l=e.getText(a.index,a.length),d=e.getFormat(a.index,a.length);e.deleteText(a.index,a.length);let u;l===l.toUpperCase()&&/[A-Z]/.test(l)?u=l.toLowerCase():(l===l.toLowerCase()&&/[a-z]/.test(l),u=l.toUpperCase()),e.insertText(a.index,u,d),a&&o.innerEditing&&e.setSelection(a.index,a.length);}}else if(t==="script"){let l="sub";i==="super"&&(l="sup"),o.innerEditing?a&&a.length?e.formatText(a.index,a.length,t,e.getFormat(a).script===i?false:l):e.formatText(0,e.getLength()-1,t,e.getFormat().script===i?false:l):(c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),e.formatText(0,e.getLength()-1,t,e.getFormat().script===i?false:l),p(r));}else if(t==="align")c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),o.innerEditing?e.format(t,i):e.formatLine(0,e.getLength(),t,i),p(r);else if(t==="alignContent")c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=i,p(r);else if(t==="lineHeight"||t==="letterSpacing")c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=i,p(r);else if(t==="color")c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),a&&a.length?e.formatText(a.index,a.length,t,i):e.formatText(0,e.getLength()-1,t,i),r.tag==="HTMLText"?p(r):r.parent.findOne("HTMLText")&&p(r.parent.findOne("HTMLText"));else if(t==="textShadow"||t==="textStroke")c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=i,p(r);else if(t==="list"){if(c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),o.innerEditing){let[l]=e.getLine(a?.index||0);l.formats().list?e.format(t,false):e.format(t,i);}else {let[l]=e.getLine(a?.index||0);l.formats().list?e.formatLine(0,e.getLength(),t,false):e.formatLine(0,e.getLength(),t,i);}p(r);}else if(t==="textVertical"){let l=U();if(l&&l?.features?.length&&l?.features?.includes("textVertical")){e.clipboard.dangerouslyPasteHTML(r.text);let d=e.getSemanticHTML();e.clipboard.dangerouslyPasteHTML(P(d)),r.data.textData.align="center",p(r);}}else o.innerEditing?a&&a.length?e.formatText(a.index,a.length,t,i===void 0?!e.getFormat(a)[t]:i):e.formatText(0,e.getLength()-1,t,i===void 0?!e.getFormat()[t]:i):(c.isMultiSelect()&&e.clipboard.dangerouslyPasteHTML(r.text),e.formatText(0,e.getLength()-1,t,i===void 0?!e.getFormat()[t]:i),p(r));},1);};function nt(t,i){return t.replace(/(-?\d*\.?\d+)px/g,(n,e)=>Number(e)*i+"px")}var C=class extends EditTool{constructor(n){super(n);this.quill=null;this.isUpdatingPoints=false;this.curveAmount=0;this.eventIds=[],this.updateBoxDebounced=this.debounce(e=>{p(e);},300);}get tag(){return "TextEditTool"}debounce(n,e){let o=null;return((...s)=>{o!==null&&window.clearTimeout(o),o=window.setTimeout(()=>n.apply(this,s),e);})}addEvent(){let{editor:n}=c.getCanvas();if(n.multiple)return;let e=n.leafList.list[0].findOne("HTMLText");if(!e)return;let{scaleX:o,scaleY:s}=e.worldTransform,a=Math.max(Math.abs(o),Math.abs(s)),r=document.querySelector("#textInnerEditor"),{style:l}=r;this.eventIds=[n.on_(EditorScaleEvent.SCALE,d=>{e.data.canChangeBox||(e.data.canChangeBox=true),e.data.canChangeBox&&(l.width=e.parent.width*a+"px",l.height="auto");let u=1;e.parent.tag==="HtmlText"&&e.parent.lockRatio&&e.data?.baseSize?.width&&(u=e.parent.width/e.data?.baseSize.width,e.data.textData.fontSize=e.data.textData.fontSize*u),e.data?.baseSize?.width&&(e.data.baseSize.width=e.parent.width),this.updateBoxDebounced(e);}),n.on_(PointerEvent.DOUBLE_TAP,()=>{e.parent.locked||n.openInnerEditor(e,true);})];}onLoad(){let{editor:n}=c.getCanvas();if(n.multiple)return;let e=n.leafList.list[0].findOne("HTMLText");if(!e)return;let{scaleX:o,scaleY:s}=e.worldTransform,a=Math.max(Math.abs(o),Math.abs(s));this.addEvent(),this.quill=c.getQuill(),this.quill.clipboard.dangerouslyPasteHTML(e.text);let r=document.querySelector("#textInnerEditor"),{style:l}=r;e.data.canChangeBox?(l.width=e.parent.width*a+"px",l.height=e.parent.height*a+"px"):(l.width="auto",l.height="auto");}updateChangeBoxBound(n){n&&n.set({width:n.__layout.boxBounds.width,height:n.__layout.boxBounds.height});}onUpdate(){let{editor:n}=c.getCanvas();if(n.multiple)return;let e=n.leafList.list[0].findOne("HTMLText");e&&this.curveAmount!=e.curveAmount&&this.isUpdatingPoints;}onUnload(){let{editor:n}=c.getCanvas();n.off_(this.eventIds);}onDestroy(){}};C=b([registerEditTool()],C);var H=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.n=void 0;this.quill=null;this.isComposing=false;this.onInput=async()=>{let{editDom:n}=this;p(this.editTarget);};this.isUpdatingPoints=false;}get tag(){return "TextEditor"}onLoad(){let{editor:n}=this,{config:e}=n.app,o=this.editTarget,{scaleX:s,scaleY:a}=o.worldTransform,r=Math.max(Math.abs(s),Math.abs(a));this.isHTMLText=!(o instanceof Text),this.n=e.keyEvent,e.keyEvent=false;let l=this.editDom=document.querySelector("#textInnerEditor"),{style:d}=l;if(d.visibility="visible",o.data.canChangeBox?(d.width=o.parent.width*r+"px",d.height=o.parent.height*r+"px"):(d.width="auto",d.height="auto"),d.outline="solid #8499EF",o.data.textData.fontSize&&(l.style.fontSize=`${o.data.textData.fontSize*r}px`),o.data.textData.lineHeight&&(l.style.lineHeight=o.data.textData.lineHeight),o.data.textData.letterSpacing&&(l.style.letterSpacing=`${o.data.textData.letterSpacing}px`),o.data.textData.textShadow?l.style.textShadow=O(o.data.textData.textShadow,r):l.style.textShadow="none",o.data.textData.textStroke?(l.style.paintOrder="stroke fill",l.style.WebkitTextStroke=O(o.data.textData.textStroke,r)):(l.style.paintOrder="unset",l.style.WebkitTextStroke="unset"),o.data.textData.alignContent){let u=l.querySelector(".ql-editor");u.style.alignContent=`${o.data.textData.alignContent}`;}this.quill=c.getQuill(),this.quill.clipboard.dangerouslyPasteHTML(o.text),o.parent.children[0].tag.includes("Shape")?(d.width=o.parent.width*r+"px",d.left="0px",this.quill.formatLine(0,this.quill.getLength(),"align","center")):this.quill.setSelection(0,this.quill.getLength()-1),this.quill.on("text-change",this.onInput),this.eventIds=[n.app.on_(PointerEvent$1.DOWN,u=>{let{target:f}=u.origin,h=false;for(;f;)f===l&&(h=true),f=f.parentElement;h||(n.closeInnerEditor(),n.cancel());})];}onUpdate(){let{editTarget:n}=this,{scaleX:e,scaleY:o}=n.worldTransform,s=Math.max(Math.abs(e),Math.abs(o)),{width:a,height:r}=n.parent.__local;a*=s,r*=s;let{x:l,y:d}=this.inBody?n.app.clientBounds:n.app.tree.clientBounds,{a:u,b:f,c:h,d:g,e:x,f:F}=new Matrix(n.worldTransform).scale(1/s).translateInner(0,0),{style:y}=this.editDom;y.transform=`matrix(${u},${f},${h},${g},${x},${F})`,y.left=l+"px",y.top=d+"px",n.set({visible:false});}onUnload(){let{editTarget:n,editor:e,editDom:o}=this;n&&(this.onInput(),e.app&&(e.app.config.keyEvent=this.n),e.off_(this.eventIds),this.editDom.style.visibility="hidden",this.eventIds=[]),n.parent&&n.parent.name=="Text"&&n.parent.children.some(s=>s.tag==="Box")?(n.parent.findOne("Box").opacity=1,n.visible=false):n.set({visible:true}),this.quill.getLength()===1&&n.parent.name==="Text"&&n.parent.remove(),this.quill.off("text-change",this.onInput);}};H=b([registerInnerEditor()],H);function O(t,i){return t.replace(/(-?\d*\.?\d+)px/g,(n,e)=>Number(e)*i+"px")}function A(t,{insertAt:i}={}){if(typeof document>"u")return;let n=document.head||document.getElementsByTagName("head")[0],e=document.createElement("style");e.type="text/css",i==="top"&&n.firstChild?n.insertBefore(e,n.firstChild):n.appendChild(e),e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t));}A(`.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}
2
- `);var N=class t{constructor(){this.quill=null;this.app_=null;this.t=0;}static getInstance(){return t.instance||(t.instance=new t),t.instance}async init(i){if(this.t=await I(),this.app_=this.t?i:null,this.quill)return this.quill;let n=document.getElementById("textInnerEditor");if(n)this.quill=this.app_?.editor?.quill||null;else return n=document.createElement("div"),n.id="textInnerEditor",n.style.position="fixed",n.style.transformOrigin="left top",n.style.overflowWrap="break-word",n.style.wordBreak="break-all",n.style.visibility="hidden",document.body.appendChild(n),this.quill=new w("#textInnerEditor",{theme:void 0,modules:{toolbar:false,keyboard:{bindings:{enter:{key:"Enter",handler:e=>{if(!this.t)return true;let[o]=this.quill.getLine(e.index),s=w.import("blots/block");if(!s?.bubbleFormats)return true;let a=s.bubbleFormats(o),r=new Delta().retain(e.index).delete(e.length).insert(`
3
- `,a);return this.quill.updateContents(r,w.sources.USER),this.quill.setSelection(e.index+1,w.sources.SILENT),false}}}}}}),this.app_?.editor&&(this.app_.editor.quill=this.quill),this.registerFonts(),this.quill}getQuill(){return this.t?this.quill:null}getCanvas(){return this.t?this.app_:null}getSelection(){return this.t?this.quill?.selection.savedRange:null}registerFonts(){this.t&&(FontStyle.whitelist=void 0,w.register("formats/font",FontStyle,true));}isMultiSelect(){return !this.t||!this.app_?.editor?false:this.app_.editor.multiple===true}dateEdit(i,n=0,e){let{editor:o}=this.app_||{};if(!o)return;let s=e||o.leafList?.list,a=r=>{n&&(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.t;for(let l=0;l<r;l++)a(s[l]);this.app_.unlockLayout(),o.updateEditBox();}else this.t&&a(s[0]);}},c=N.getInstance();var q=class extends Box{get __tag(){return "HtmlText"}constructor(i){let{text:n,fontSize:e,fontFamily:o,lineHeight:s,letterSpacing:a,textShadow:r,alignContent:l,...d}=i||{};super({editOuter:"TextEditTool",name:"HtmlText",x:0,y:0,editable:true,draggable:true,overflow:"show",...d}),i&&this.createTextElement(i);}createTextElement(i){let{text:n,fontSize:e,fontFamily:o,lineHeight:s,letterSpacing:a,textShadow:r,alignContent:l}=i,d="<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
4
- rflow-wrap:break-word;word-break:break-all;"><p style="font-size: ${e}px; line-height: ${s}; letter-spacing: ${a}px; text-shadow: ${r};"><strong>Hello World</strong></p></div>`;if(i.children?.length>0)return;let f=new HTMLText({name:"Text",text:d+(n||u),x:0,y:0,data:{canChangeBox:false,textData:{fontFamily:o,fontSize:e,lineHeight:s,letterSpacing:a||0,textShadow:r,alignContent:l}},editConfig:{selectedStyle:{strokeWidth:0}}});this.add(f);}};q=b([registerUI()],q);export{q as HtmlText,I as checkLicense,U as getLicenseInfo,c as htmlTextManage,At as setHTMLText,et as setLicense,p 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 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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenyomi/leafer-htmltext-edit",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
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",
@@ -37,19 +37,18 @@
37
37
  "homepage": "https://github.com/chenyomi/leafer-htmltext-edit#readme",
38
38
  "devDependencies": {
39
39
  "@types/crypto-js": "^4.2.2",
40
- "@types/lodash": "^4.17.23",
41
- "@types/node": "^20.0.0",
40
+ "@types/lodash": "^4.17.24",
41
+ "@types/node": "^20.19.39",
42
42
  "esbuild-plugin-obfuscator": "^1.4.0",
43
- "javascript-obfuscator": "^5.3.0",
44
- "tsup": "^8.0.0",
45
- "typescript": "^5.0.0",
43
+ "javascript-obfuscator": "^5.4.2",
44
+ "tsup": "^8.5.1",
45
+ "typescript": "^5.9.3",
46
46
  "vite-plugin-javascript-obfuscator": "^3.1.0"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@leafer-in/editor": "^2.0.0",
50
50
  "@leafer-in/html": "^2.0.0",
51
51
  "@leafer-ui/core": "^2.0.0",
52
- "leafer-ui": "^2.0.0",
53
52
  "quill": "^2.0.0"
54
53
  },
55
54
  "dependencies": {