@chenyomi/leafer-htmltext-edit 2.3.0 → 2.4.0

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,4 @@
1
- 'use strict';var editor=require('@leafer-in/editor'),leaferUi=require('leafer-ui'),m=require('crypto-js'),core=require('@leafer-ui/core'),S=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 m__default=/*#__PURE__*/_interopDefault(m);var S__default=/*#__PURE__*/_interopDefault(S);function _(t){let i=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 c of Array.from(r.childNodes))o(c).forEach((g,p)=>{let h=r.cloneNode(false);h.appendChild(g),l.push(h);});return l}return []}let s=[];for(let r of Array.from(i.childNodes)){let l=o(r);s.push(...l);}let a=document.createElement("div");return s.forEach((r,l)=>{a.appendChild(r);}),a.innerHTML}var A="LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxaUFnU1hWM3dMKzh2YkZ2OVkwQwpEN1dBUjhPa2I4bjlmTWxpQjF3enZodTBrdVdZUWEvMUxvVDhHWVh6WWlRQVFBRk9zTTA0MGp2dlNRT2hRSWpiCjRaYXZ1NHUvWVA5bElPYjFKYnZnYkFoYVVOQnphL0l2UmFnaFlKYTJBc1cyRVhnZkVrdmMyUENNMS9zbVlFNnoKNjZiUmx1dnREK3FJZkpLVCtUUXJRRmp5TnNTZ0c2Z2R4MThrZTRMSStBejFPcklMbUsyMHlBU2tlRXpYT1BTVAplM3RNYThleHpZdmUzV0wyNHRHUHg5WHNvN1JyUEl1elZlajh0NDYrZ0c1Y0pQaVh0N1lqa0V2NEJOUUt5eUpoCkltOVRJdVZ6clFpa2NJNE14dExNSGdUMHpLcU9ZZ1NzcmEvTHNDd2ZOdzdtYWxITkU2c21YZWYyQ2E5RGhZODQKS1FJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==";function Y(t){let e=t.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");return F(e)}function F(t){let e=atob(t),n=new Uint8Array(e.length);for(let i=0;i<e.length;i++)n[i]=e.charCodeAt(i);return n.buffer}async function K(){let t=atob(A),e=Y(t);return await crypto.subtle.importKey("spki",e,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},false,["verify"])}async function P(t,e){try{let n=await K(),i=new TextEncoder().encode(t),o=F(e);return await crypto.subtle.verify("RSASSA-PKCS1-v1_5",n,o,i)}catch(n){return console.error("[RSA] Signature verification failed:",n),false}}var U="c19496eb17719960b6c3cebab0ef5eddfce5d0315ab8c5af86a52fbda434fea9",I="ce1e3e8974f1392b3c5803b34ecf659f";function N(t){try{let e=m__default.default.enc.Hex.parse(U),n=m__default.default.enc.Hex.parse(I),o=m__default.default.AES.decrypt(t,e,{iv:n,mode:m__default.default.mode.CBC,padding:m__default.default.pad.Pkcs7}).toString(m__default.default.enc.Utf8);if(!o)throw new Error("Decryption resulted in empty string - invalid ciphertext or wrong key");return o}catch(e){throw console.error("[AES] Decryption failed:",e),e}}async function Q(t){try{let e=atob(t),n=JSON.parse(e);if(!n.data||!n.signature||!await P(n.data,n.signature))return null;let o=n.data;if(n.encrypted)try{o=N(n.data);}catch{return null}return JSON.parse(o)}catch{return null}}function Z(t){if(!t||t.length===0)return true;let e=window.location.hostname;if(e==="localhost"||e==="127.0.0.1")return console.log("[License] Local development environment detected"),true;let n=t.some(i=>{if(i.startsWith("*.")){let o=i.slice(2);return e.endsWith(o)}return e===i});return n||(console.error(`[License] Domain not authorized: ${e}`),console.error("[License] Allowed domains:",t)),n}function W(t){if(!t)return true;try{let e=new Date(t),n=new Date;if(n>=e)return console.error(`[License] License has expired on ${t}`),!1;let i=Math.ceil((e.getTime()-n.getTime())/(1e3*60*60*24));return i<=7&&console.warn(`[License] License will expire in ${i} days`),!0}catch{return console.error("[License] Invalid expire date format:",t),false}}function j(t){if(!t)return true;try{return new Date(t)>new Date?(console.error("[License] License issue date is in the future"),!1):!0}catch{return true}}async function D(t){try{let e=await Q(t);return e?j(e.issueDate)?Z(e.domains)?W(e.expireDate)?{valid:!0,data:e}:{valid:!1,error:"License has expired",data:e}:{valid:!1,error:`License not valid for domain: ${window.location.hostname}`,data:e}:{valid:!1,error:"Invalid license issue date",data:e}:{valid:!1,error:"Invalid license key or signature verification failed"}}catch(e){return console.error("[License] Validation error:",e),{valid:false,error:"License validation failed"}}}var E=null,L=null,y=false;async function J(t){console.log("[License] Activating license...");let e=await D(t);return e.valid&&e.data?(E=t,L=e.data,y=true,console.log("[License] \u2705 License activated successfully"),console.log(`[License] Valid until: ${e.data.expireDate||"unlimited"}`),true):(E=null,L=null,y=false,console.error("[License] \u274C License activation failed:",e.error),false)}async function M(){if(!E)return console.warn("[License] No license key provided"),false;if(!y)return console.warn("[License] License is not valid"),false;let t=await D(E);return y=t.valid,y||(console.error("[License] License validation failed:",t.error),L=null),y}function C(){return L}var f=async(t,e,n)=>{let{scaleX:i,scaleY:o}=t.worldTransform,s=Math.max(Math.abs(i),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?.alignContent){let c=a.querySelector(".ql-editor");c.style.alignContent=t.data.textData.alignContent;}let l=d.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 c=t.text.split("</style>")[0];if(n&&!c.includes(n)){let u=`@font-face {font-family: ${n.split(",")[0]};src: url(${e}) format('woff2') }</style>`;t.text=c+u+v(t,l,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent);}else t.text=c+"</style>"+v(t,l,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent);}else if(e&&n){let c=`<style>@font-face {font-family: ${n.split(",")[0]};src: url(${e}) format('woff2') }</style>`;t.text=c+v(t,l,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent);}else t.text=v(t,l,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent);},v=(t,e,n=20.67,i=1.5,o=0,s="none",a="start")=>{let{scaleX:r,scaleY:l}=t.worldTransform,c=Math.max(Math.abs(r),Math.abs(l)),u=document.createElement("div");u.innerHTML=e;let g={fontSize:`${n}px`,lineHeight:i,letterSpacing:`${o}px`,textShadow:s};u.querySelectorAll("p,ol,ul").forEach(O=>{Object.assign(O.style,g);});let p=u.innerHTML;/<p\b[^>]*><\/p>/.test(p)&&(p=p.replace(/<p\b([^>]*)><\/p>/g,"<p$1>&nbsp;</p>")),/&quot;/.test(p)&&(p=p.replace(/&quot;/g,""));let h;document.querySelector("#textInnerEditor");let B=d.getQuill(),w=Number((B.scroll.domNode.scrollHeight/c).toFixed(0));Number((B.scroll.domNode.scrollWidth/c).toFixed(0));["center","end"].includes(t.data.textData.alignContent)?t.parent.height<w?h=(w||t.__layout.boxBounds.height)+"px":h=`${t.parent.height}px`:t.parent.height<w?h=(w||t.__layout.boxBounds.height)+"px":h=`${t.parent.height}px`;let b="<style>p{margin:0;}sub,sup{font-size:63%;}.ql-ui{position:absolute}ol,ul{counter-reset:list-0;padding-left:1.5em;margin:0}ol>li,ul>li{counter-increment:list-0;list-style-type:none;position:relative;padding-left:0;margin:0}ol>li::before{content:counter(list-0,decimal) '. ';position:absolute;left:-1.5em;width:1.2em;text-align:right}ul>li::before{content:'\u2022';position:absolute;left:-1.5em;width:1.2em;text-align:right}li[data-list]{counter-set:list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-align-center{text-align:center}.ql-align-right{text-align:right}.ql-align-left{text-align:left}.ql-align-justify{text-align:justify}</style>",x="";return t.parent.children[0].tag.includes("Shape")?x=b+`<div style="width: ${t.parent.width}px;height: ${t.parent.height}px;overflow-wrap:break-word;word-break:break-all;align-content:center;">${p}</div>`:t.data.canChangeBox?x=b+`<div style="width: ${t.parent.width}px;height:${h};overflow-wrap:break-word;word-break:break-all;align-content:${a};">${p}</div>`:t.data.textData.italic?x=b+p:x=b+`<div style="overflow-wrap:break-word;word-break:break-all;">${p}</div>`,console.log(x,"\u6700\u7EC8\u7684html\u5185\u5BB9"),x},Ut=(t,e,n)=>{let i=d.getQuill(),{editor:o,canvas:s}=d.getCanvas();if(!i)return;e===0&&(e="0");let a=i.selection.savedRange;d.dateEdit(async r=>{if(r.tag!=="HTMLText"){console.log("\u975EHtml\u6587\u672C\u5143\u7D20\u65E0\u6CD5\u4FEE\u6539");return}if(t==="font")o.innerEditing?(a&&a.length?i.formatText(a.index,a.length,t,e):i.formatText(0,i.getLength()-1,t,e),r.data.textData.fontFamily=e,f(r,n??null,e??null)):(d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),i.formatText(0,i.getLength()-1,t,e),r.data.textData.fontFamily=e,f(r,n??null,e??null));else if(t==="fontSize")r.data.textData[t]=e,d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),f(r,n??null);else if(t==="textCase"){if(o.innerEditing){let l=i.getText(a.index,a.length),c=i.getFormat(a.index,a.length);i.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()),i.insertText(a.index,u,c),a&&o.innerEditing&&i.setSelection(a.index,a.length);}}else if(t==="script"){let l="sub";e==="super"&&(l="sup"),o.innerEditing?a&&a.length?i.formatText(a.index,a.length,t,i.getFormat(a).script===e?false:l):i.formatText(0,i.getLength()-1,t,i.getFormat().script===e?false:l):(d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),i.formatText(0,i.getLength()-1,t,i.getFormat().script===e?false:l),f(r));}else if(t==="align")d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),o.innerEditing?i.format(t,e):i.formatLine(0,i.getLength(),t,e),f(r);else if(t==="alignContent")d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=e,f(r);else if(t==="lineHeight"||t==="letterSpacing")d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=e,f(r);else if(t==="color")d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),a&&a.length?i.formatText(a.index,a.length,t,e):i.formatText(0,i.getLength()-1,t,e),r.tag==="HTMLText"?f(r):r.parent.findOne("HTMLText")&&f(r.parent.findOne("HTMLText"));else if(t==="textShadow")d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=e,f(r);else if(t==="list"){if(d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),o.innerEditing){let[l]=i.getLine(a?.index||0);l.formats().list?i.format(t,false):i.format(t,e);}else {let[l]=i.getLine(a?.index||0);l.formats().list?i.formatLine(0,i.getLength(),t,false):i.formatLine(0,i.getLength(),t,e);}f(r);}else if(t==="textVertical"){let l=C();if(l&&l?.features?.length&&l?.features?.includes("textVertical")){i.clipboard.dangerouslyPasteHTML(r.text);let c=i.getSemanticHTML();i.clipboard.dangerouslyPasteHTML(_(c)),r.data.textData.align="center",f(r);}}else o.innerEditing?a&&a.length?i.formatText(a.index,a.length,t,e===void 0?!i.getFormat(a)[t]:e):i.formatText(0,i.getLength()-1,t,e===void 0?!i.getFormat()[t]:e):(d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),i.formatText(0,i.getLength()-1,t,e===void 0?!i.getFormat()[t]:e),f(r));},1);};var G=(t,e,n,i)=>{for(var o=e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(o=(a(o))||o);return o},z=class extends editor.EditTool{constructor(t){super(t),this.quill=null,this.isUpdatingPoints=false,this.curveAmount=0,this.eventIds=[],this.updateBoxDebounced=this.debounce(e=>{f(e);},300);}get tag(){return "TextEditTool"}debounce(t,e){let n=null;return((...i)=>{n!==null&&window.clearTimeout(n),n=window.setTimeout(()=>t.apply(this,i),e);})}addEvent(){let{editor:t}=d.getCanvas();if(t.multiple)return;let e=t.leafList.list[0].findOne("HTMLText");if(!e)return;let{scaleX:n,scaleY:i}=e.worldTransform,o=Math.max(Math.abs(n),Math.abs(i)),s=document.querySelector("#textInnerEditor"),{style:a}=s;this.eventIds=[t.on_(editor.EditorScaleEvent.SCALE,r=>{e.data.canChangeBox||(e.data.canChangeBox=true),e.data.canChangeBox&&(a.width=e.parent.width*o+"px",a.height="auto");let l=1;e.parent.tag==="HtmlText"&&e.parent.lockRatio&&e.data?.baseSize?.width&&(l=e.parent.width/e.data?.baseSize.width,e.data.textData.fontSize=e.data.textData.fontSize*l),e.data?.baseSize?.width&&(e.data.baseSize.width=e.parent.width),this.updateBoxDebounced(e);}),t.on_(leaferUi.PointerEvent.DOUBLE_TAP,()=>{e.parent.locked||t.openInnerEditor(e,true);})];}onLoad(){let{editor:t}=d.getCanvas();if(t.multiple)return;let e=t.leafList.list[0].findOne("HTMLText");if(!e)return;let{scaleX:n,scaleY:i}=e.worldTransform,o=Math.max(Math.abs(n),Math.abs(i));this.addEvent(),this.quill=d.getQuill(),this.quill.clipboard.dangerouslyPasteHTML(e.text);let s=document.querySelector("#textInnerEditor"),{style:a}=s;e.data.canChangeBox?(a.width=e.parent.width*o+"px",a.height=e.parent.height*o+"px"):(a.width="auto",a.height="auto");}updateChangeBoxBound(t){t&&t.set({width:t.__layout.boxBounds.width,height:t.__layout.boxBounds.height});}onUpdate(){let{editor:t}=d.getCanvas();if(t.multiple)return;let e=t.leafList.list[0].findOne("HTMLText");e&&(console.log("\u6587\u672Cbound\u66F4\u65B0"),this.curveAmount!=e.curveAmount&&this.isUpdatingPoints);}onUnload(){let{editor:t}=d.getCanvas();t.off_(this.eventIds);}onDestroy(){}};z=G([editor.registerEditTool()],z);var ot=(t,e,n,i)=>{for(var o=e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(o=(a(o))||o);return o},V=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._keyEvent=void 0,this.quill=null,this.isComposing=false,this.onInput=async()=>{let{editDom:t}=this;f(this.editTarget);},this.isUpdatingPoints=false;}get tag(){return "TextEditor"}onLoad(){let{editor:t}=this,{config:e}=t.app,n=this.editTarget,{scaleX:i,scaleY:o}=n.worldTransform,s=Math.max(Math.abs(i),Math.abs(o));this.isHTMLText=!(n instanceof Text),this._keyEvent=e.keyEvent,e.keyEvent=false;let a=this.editDom=document.querySelector("#textInnerEditor"),{style:r}=a;if(r.visibility="visible",n.data.canChangeBox?(r.width=n.parent.width*s+"px",r.height=n.parent.height*s+"px"):(r.width="auto",r.height="auto"),r.outline="solid #8499EF",n.data.textData.fontSize&&(a.style.fontSize=`${n.data.textData.fontSize*s}px`),n.data.textData.lineHeight&&(a.style.lineHeight=n.data.textData.lineHeight),n.data.textData.letterSpacing&&(a.style.letterSpacing=`${n.data.textData.letterSpacing}px`),n.data.textData.textShadow?a.style.textShadow=`${n.data.textData.textShadow}`:a.style.textShadow="none",n.data.textData.alignContent){let l=a.querySelector(".ql-editor");l.style.alignContent=`${n.data.textData.alignContent}`;}this.quill=d.getQuill(),this.quill.clipboard.dangerouslyPasteHTML(n.text),n.parent.children[0].tag.includes("Shape")?(r.width=n.parent.width*s+"px",r.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=[t.app.on_(core.PointerEvent.DOWN,l=>{let{target:c}=l.origin,u=false;for(;c;)c===a&&(u=true),c=c.parentElement;u||(t.closeInnerEditor(),t.cancel());})];}onUpdate(){let{editTarget:t}=this,{scaleX:e,scaleY:n}=t.worldTransform,i=Math.max(Math.abs(e),Math.abs(n)),{width:o,height:s}=t.parent.__local;o*=i,s*=i;let{x:a,y:r}=this.inBody?t.app.clientBounds:t.app.tree.clientBounds,{a:l,b:c,c:u,d:g,e:p,f:h}=new core.Matrix(t.worldTransform).scale(1/i).translateInner(0,0),{style:T}=this.editDom;T.transform=`matrix(${l},${c},${u},${g},${p},${h})`,T.left=a+"px",T.top=r+"px",t.set({visible:false});}onUnload(){let{editTarget:t,editor:e,editDom:n}=this;t&&(this.onInput(),e.app&&(e.app.config.keyEvent=this._keyEvent),e.off_(this.eventIds),this.editDom.style.visibility="hidden",this.eventIds=[]),t.parent&&t.parent.name=="Text"&&t.parent.children.some(i=>i.tag==="Box")?(t.parent.findOne("Box").opacity=1,t.visible=false):t.set({visible:true}),this.quill.getLength()===1&&t.parent.name==="Text"&&t.parent.remove(),this.quill.off("text-change",this.onInput);}};V=ot([editor.registerInnerEditor()],V);function q(t,{insertAt:e}={}){if(typeof document>"u")return;let n=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css",e==="top"&&n.firstChild?n.insertBefore(i,n.firstChild):n.appendChild(i),i.styleSheet?i.styleSheet.cssText=t:i.appendChild(document.createTextNode(t));}q(`.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 H=class t{constructor(){this.quill=null,this.app_=null;}static getInstance(){return t.instance||(t.instance=new t),t.instance}async init(e){if(!await M())throw new Error("[HtmlTextManage] \u6388\u6743\u5931\u8D25\u8BF7\u8054\u7CFB\u4F5C\u8005\u83B7\u53D6\u6388\u6743 \u90AE\u7BB1 : 408550179@qq.com \u5FAE\u4FE1 : cym5640");if(this.app_=e,this.quill)return this.quill;let i=document.getElementById("textInnerEditor");if(i)this.quill=this.app_.editor.quill;else return i=document.createElement("div"),i.id="textInnerEditor",i.style.position="fixed",i.style.transformOrigin="left top",i.style.overflowWrap="break-word",i.style.wordBreak="break-all",i.style.visibility="hidden",document.body.appendChild(i),this.quill=new S__default.default("#textInnerEditor",{theme:void 0,modules:{toolbar:false,keyboard:{bindings:{enter:{key:"Enter",handler:o=>{let[s]=this.quill.getLine(o.index),a=S__default.default.import("blots/block");if(!a?.bubbleFormats)return true;let r=a.bubbleFormats(s),l=new S.Delta().retain(o.index).delete(o.length).insert(`
3
- `,r);return this.quill.updateContents(l,S__default.default.sources.USER),this.quill.setSelection(o.index+1,S__default.default.sources.SILENT),false}}}}}}),this.app_.editor.quill=this.quill,this.registerFonts(),this.quill}getQuill(){if(!this.quill)throw new Error("Quill editor not initialized. Call init() first.");return this.quill}getCanvas(){if(!this.app_)throw new Error("app_ editor not initialized. Call init() first.");return this.app_}getSelection(){return console.log(this.quill?.selection.savedRange,"this.quill?.selection.savedRange"),this.quill?.selection.savedRange}registerFonts(){font.FontStyle.whitelist=void 0,S__default.default.register("formats/font",font.FontStyle,true);}isMultiSelect(){return this.app_.editor?this.app_.editor.multiple===true:false}dateEdit(e,n=0,i){let{editor:o}=this.app_,s=i||o.leafList.list,a=r=>{n&&(r.tag==="Box"||r.name==="Text")?e(r.children?.[0]||r):e(r);};s.length&&(Array.isArray(s)&&s.length>1?(this.app_.lockLayout(),s.forEach(a),this.app_.unlockLayout(),o.updateEditBox()):a(s[0]));}},d=H.getInstance();var ht=(t,e,n,i)=>{for(var o=e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(o=(a(o))||o);return o};exports.HtmlText=class R extends core.Box{get __tag(){return "HtmlText"}constructor(t){let{text:e,fontSize:n,fontFamily:i,lineHeight:o,letterSpacing:s,textShadow:a,alignContent:r,...l}=t||{};super({editOuter:"TextEditTool",name:"HtmlText",x:0,y:0,editable:true,draggable:true,overflow:"show",...l}),t&&this.createTextElement(t);}createTextElement(t){let{text:e,fontSize:n,fontFamily:i,lineHeight:o,letterSpacing:s,textShadow:a,alignContent:r}=t,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>",c=`<div style="ove
4
- rflow-wrap:break-word;word-break:break-all;"><p style="font-size: ${n}px; line-height: ${o}; letter-spacing: ${s}px; text-shadow: ${a};"><strong>Hello World</strong></p></div>`;if(t.children?.length>0)return;let u=new html.HTMLText({name:"Text",text:l+(e||c),x:0,y:0,data:{canChangeBox:false,textData:{fontFamily:i,fontSize:n,lineHeight:o,letterSpacing:s||0,textShadow:a,alignContent:r}},editConfig:{selectedStyle:{strokeWidth:0}}});this.add(u);}};exports.HtmlText=ht([core.registerUI()],exports.HtmlText);exports.checkLicense=M;exports.getLicenseInfo=C;exports.htmlTextManage=d;exports.setHTMLText=Ut;exports.setLicense=J;exports.updataHtmlText=f;
1
+ 'use strict';var editor=require('@leafer-in/editor'),leaferUi=require('leafer-ui'),b=require('crypto-js'),core=require('@leafer-ui/core'),T=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 b__default=/*#__PURE__*/_interopDefault(b);var T__default=/*#__PURE__*/_interopDefault(T);var y=(e,i,n,t)=>{for(var r=i,s=e.length-1,o;s>=0;s--)(o=e[s])&&(r=(o(r))||r);return r};function N(e){let t=new DOMParser().parseFromString(e,"text/html").body;function r(a){if(a.nodeType===Node.TEXT_NODE){let l=a.textContent;return l?Array.from(l).map(d=>document.createTextNode(d)):[]}else if(a.nodeType===Node.ELEMENT_NODE){let l=[];for(let c of Array.from(a.childNodes))r(c).forEach((g,f)=>{let h=a.cloneNode(false);h.appendChild(g),l.push(h);});return l}return []}let s=[];for(let a of Array.from(t.childNodes)){let l=r(a);s.push(...l);}let o=document.createElement("div");return s.forEach((a,l)=>{o.appendChild(a);}),o.innerHTML}var P="LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxaUFnU1hWM3dMKzh2YkZ2OVkwQwpEN1dBUjhPa2I4bjlmTWxpQjF3enZodTBrdVdZUWEvMUxvVDhHWVh6WWlRQVFBRk9zTTA0MGp2dlNRT2hRSWpiCjRaYXZ1NHUvWVA5bElPYjFKYnZnYkFoYVVOQnphL0l2UmFnaFlKYTJBc1cyRVhnZkVrdmMyUENNMS9zbVlFNnoKNjZiUmx1dnREK3FJZkpLVCtUUXJRRmp5TnNTZ0c2Z2R4MThrZTRMSStBejFPcklMbUsyMHlBU2tlRXpYT1BTVAplM3RNYThleHpZdmUzV0wyNHRHUHg5WHNvN1JyUEl1elZlajh0NDYrZ0c1Y0pQaVh0N1lqa0V2NEJOUUt5eUpoCkltOVRJdVZ6clFpa2NJNE14dExNSGdUMHpLcU9ZZ1NzcmEvTHNDd2ZOdzdtYWxITkU2c21YZWYyQ2E5RGhZODQKS1FJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==";function Z(e){let i=e.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");return z(i)}function z(e){let i=atob(e),n=new Uint8Array(i.length);for(let t=0;t<i.length;t++)n[t]=i.charCodeAt(t);return n.buffer}async function O(){let e=atob(P),i=Z(e);return await crypto.subtle.importKey("spki",i,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},false,["verify"])}async function _(e,i){try{let n=await O(),t=new TextEncoder().encode(e),r=z(i);return await crypto.subtle.verify("RSASSA-PKCS1-v1_5",n,r,t)}catch{return false}}var R="c19496eb17719960b6c3cebab0ef5eddfce5d0315ab8c5af86a52fbda434fea9",V="ce1e3e8974f1392b3c5803b34ecf659f";function $(e){try{let i=b__default.default.enc.Hex.parse(R),n=b__default.default.enc.Hex.parse(V),r=b__default.default.AES.decrypt(e,i,{iv:n,mode:b__default.default.mode.CBC,padding:b__default.default.pad.Pkcs7}).toString(b__default.default.enc.Utf8);if(!r)throw new Error("Decryption resulted in empty string - invalid ciphertext or wrong key");return r}catch(i){throw i}}async function W(e){try{let i=atob(e),n=JSON.parse(i);if(!n.data||!n.signature||!await _(n.data,n.signature))return null;let r=n.data;if(n.encrypted)try{r=$(n.data);}catch{return null}return JSON.parse(r)}catch{return null}}function J(e){if(!e||e.length===0)return true;let i=window.location.hostname;if(i==="localhost"||i==="127.0.0.1")return true;let n=e.some(t=>{if(t.startsWith("*.")){let r=t.slice(2);return i.endsWith(r)}return i===t});return n}function j(e){if(!e)return true;try{let i=new Date(e),n=new Date;return n>=i?!1:(Math.ceil((i.getTime()-n.getTime())/(1e3*60*60*24))<=7,!0)}catch{return false}}function X(e){if(!e)return true;try{return !(new Date(e)>new Date)}catch{return true}}async function q(e){try{let i=await W(e);return i?X(i.issueDate)?J(i.domains)?j(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 L=null,E=null,m=0;async function G(e){let i=await q(e);return i.valid&&i.data?(L=e,E=i.data,m=1,true):(L=null,E=null,m=0,false)}async function B(){return !L||!m?0:(m=(await q(L)).valid?1:0,m||(E=null),m)}function I(){return m?E:null}var p=async(e,i,n)=>{let{scaleX:t,scaleY:r}=e.worldTransform,s=Math.max(Math.abs(t),Math.abs(r)),o=document.querySelector("#textInnerEditor");if(o&&e.data.textData?.fontSize&&(o.style.fontSize=`${e.data.textData.fontSize*s}px`),o&&e.data.textData?.lineHeight&&(o.style.lineHeight=e.data.textData.lineHeight),o&&e.data.textData?.letterSpacing&&(o.style.letterSpacing=`${e.data.textData.letterSpacing}px`),o&&e.data.textData?.textShadow?o.style.textShadow=e.data.textData.textShadow:o.style.textShadow="none",o&&e.data.textData?.alignContent){let c=o.querySelector(".ql-editor");c.style.alignContent=e.data.textData.alignContent;}let l=u.getQuill().getSemanticHTML();if(l==="<p></p>"){e.text.includes("<style>@font-face")?e.text=e.text.split("</style>")[0]+"</style>":e.text="";return}if(e.text.includes("<style>@font-face")){let c=e.text.split("</style>")[0];if(n&&!c.includes(n)){let d=`@font-face {font-family: ${n.split(",")[0]};src: url(${i}) format('woff2') }</style>`;e.text=c+d+v(e,l,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent);}else e.text=c+"</style>"+v(e,l,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent);}else if(i&&n){let c=`<style>@font-face {font-family: ${n.split(",")[0]};src: url(${i}) format('woff2') }</style>`;e.text=c+v(e,l,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent);}else e.text=v(e,l,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent);},v=(e,i,n=20.67,t=1.5,r=0,s="none",o="start")=>{let{scaleX:a,scaleY:l}=e.worldTransform,c=Math.max(Math.abs(a),Math.abs(l)),d=document.createElement("div");d.innerHTML=i;let g={fontSize:`${n}px`,lineHeight:t,letterSpacing:`${r}px`,textShadow:s};d.querySelectorAll("p,ol,ul").forEach(k=>{Object.assign(k.style,g);});let f=d.innerHTML;/<p\b[^>]*><\/p>/.test(f)&&(f=f.replace(/<p\b([^>]*)><\/p>/g,"<p$1>&nbsp;</p>")),/&quot;/.test(f)&&(f=f.replace(/&quot;/g,""));let h;document.querySelector("#textInnerEditor");let w=u.getQuill(),x=Number((w.scroll.domNode.scrollHeight/c).toFixed(0));Number((w.scroll.domNode.scrollWidth/c).toFixed(0));["center","end"].includes(e.data.textData.alignContent)?e.parent.height<x?h=(x||e.__layout.boxBounds.height)+"px":h=`${e.parent.height}px`:e.parent.height<x?h=(x||e.__layout.boxBounds.height)+"px":h=`${e.parent.height}px`;let 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>",S="";return e.parent.children[0].tag.includes("Shape")?S=D+`<div style="width: ${e.parent.width}px;height: ${e.parent.height}px;overflow-wrap:break-word;word-break:break-all;align-content:center;">${f}</div>`:e.data.canChangeBox?S=D+`<div style="width: ${e.parent.width}px;height:${h};overflow-wrap:break-word;word-break:break-all;align-content:${o};">${f}</div>`:e.data.textData.italic?S=D+f:S=D+`<div style="overflow-wrap:break-word;word-break:break-all;">${f}</div>`,S},Bt=(e,i,n)=>{let t=u.getQuill(),{editor:r,canvas:s}=u.getCanvas();if(!t)return;i===0&&(i="0");let o=t.selection.savedRange;u.dateEdit(async a=>{if(a.tag==="HTMLText")if(e==="font")r.innerEditing?(o&&o.length?t.formatText(o.index,o.length,e,i):t.formatText(0,t.getLength()-1,e,i),a.data.textData.fontFamily=i,p(a,n??null,i??null)):(u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),t.formatText(0,t.getLength()-1,e,i),a.data.textData.fontFamily=i,p(a,n??null,i??null));else if(e==="fontSize")a.data.textData[e]=i,u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),p(a,n??null);else if(e==="textCase"){if(r.innerEditing){let l=t.getText(o.index,o.length),c=t.getFormat(o.index,o.length);t.deleteText(o.index,o.length);let d;l===l.toUpperCase()&&/[A-Z]/.test(l)?d=l.toLowerCase():(l===l.toLowerCase()&&/[a-z]/.test(l),d=l.toUpperCase()),t.insertText(o.index,d,c),o&&r.innerEditing&&t.setSelection(o.index,o.length);}}else if(e==="script"){let l="sub";i==="super"&&(l="sup"),r.innerEditing?o&&o.length?t.formatText(o.index,o.length,e,t.getFormat(o).script===i?false:l):t.formatText(0,t.getLength()-1,e,t.getFormat().script===i?false:l):(u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),t.formatText(0,t.getLength()-1,e,t.getFormat().script===i?false:l),p(a));}else if(e==="align")u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),r.innerEditing?t.format(e,i):t.formatLine(0,t.getLength(),e,i),p(a);else if(e==="alignContent")u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),a.data.textData[e]=i,p(a);else if(e==="lineHeight"||e==="letterSpacing")u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),a.data.textData[e]=i,p(a);else if(e==="color")u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),o&&o.length?t.formatText(o.index,o.length,e,i):t.formatText(0,t.getLength()-1,e,i),a.tag==="HTMLText"?p(a):a.parent.findOne("HTMLText")&&p(a.parent.findOne("HTMLText"));else if(e==="textShadow")u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),a.data.textData[e]=i,p(a);else if(e==="list"){if(u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),r.innerEditing){let[l]=t.getLine(o?.index||0);l.formats().list?t.format(e,false):t.format(e,i);}else {let[l]=t.getLine(o?.index||0);l.formats().list?t.formatLine(0,t.getLength(),e,false):t.formatLine(0,t.getLength(),e,i);}p(a);}else if(e==="textVertical"){let l=I();if(l&&l?.features?.length&&l?.features?.includes("textVertical")){t.clipboard.dangerouslyPasteHTML(a.text);let c=t.getSemanticHTML();t.clipboard.dangerouslyPasteHTML(N(c)),a.data.textData.align="center",p(a);}}else r.innerEditing?o&&o.length?t.formatText(o.index,o.length,e,i===void 0?!t.getFormat(o)[e]:i):t.formatText(0,t.getLength()-1,e,i===void 0?!t.getFormat()[e]:i):(u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),t.formatText(0,t.getLength()-1,e,i===void 0?!t.getFormat()[e]:i),p(a));},1);};var M=class extends editor.EditTool{constructor(n){super(n);this.quill=null;this.isUpdatingPoints=false;this.curveAmount=0;this.eventIds=[],this.updateBoxDebounced=this.debounce(t=>{p(t);},300);}get tag(){return "TextEditTool"}debounce(n,t){let r=null;return((...s)=>{r!==null&&window.clearTimeout(r),r=window.setTimeout(()=>n.apply(this,s),t);})}addEvent(){let{editor:n}=u.getCanvas();if(n.multiple)return;let t=n.leafList.list[0].findOne("HTMLText");if(!t)return;let{scaleX:r,scaleY:s}=t.worldTransform,o=Math.max(Math.abs(r),Math.abs(s)),a=document.querySelector("#textInnerEditor"),{style:l}=a;this.eventIds=[n.on_(editor.EditorScaleEvent.SCALE,c=>{t.data.canChangeBox||(t.data.canChangeBox=true),t.data.canChangeBox&&(l.width=t.parent.width*o+"px",l.height="auto");let d=1;t.parent.tag==="HtmlText"&&t.parent.lockRatio&&t.data?.baseSize?.width&&(d=t.parent.width/t.data?.baseSize.width,t.data.textData.fontSize=t.data.textData.fontSize*d),t.data?.baseSize?.width&&(t.data.baseSize.width=t.parent.width),this.updateBoxDebounced(t);}),n.on_(leaferUi.PointerEvent.DOUBLE_TAP,()=>{t.parent.locked||n.openInnerEditor(t,true);})];}onLoad(){let{editor:n}=u.getCanvas();if(n.multiple)return;let t=n.leafList.list[0].findOne("HTMLText");if(!t)return;let{scaleX:r,scaleY:s}=t.worldTransform,o=Math.max(Math.abs(r),Math.abs(s));this.addEvent(),this.quill=u.getQuill(),this.quill.clipboard.dangerouslyPasteHTML(t.text);let a=document.querySelector("#textInnerEditor"),{style:l}=a;t.data.canChangeBox?(l.width=t.parent.width*o+"px",l.height=t.parent.height*o+"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}=u.getCanvas();if(n.multiple)return;let t=n.leafList.list[0].findOne("HTMLText");t&&this.curveAmount!=t.curveAmount&&this.isUpdatingPoints;}onUnload(){let{editor:n}=u.getCanvas();n.off_(this.eventIds);}onDestroy(){}};M=y([editor.registerEditTool()],M);var C=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:t}=n.app,r=this.editTarget,{scaleX:s,scaleY:o}=r.worldTransform,a=Math.max(Math.abs(s),Math.abs(o));this.isHTMLText=!(r instanceof Text),this.n=t.keyEvent,t.keyEvent=false;let l=this.editDom=document.querySelector("#textInnerEditor"),{style:c}=l;if(c.visibility="visible",r.data.canChangeBox?(c.width=r.parent.width*a+"px",c.height=r.parent.height*a+"px"):(c.width="auto",c.height="auto"),c.outline="solid #8499EF",r.data.textData.fontSize&&(l.style.fontSize=`${r.data.textData.fontSize*a}px`),r.data.textData.lineHeight&&(l.style.lineHeight=r.data.textData.lineHeight),r.data.textData.letterSpacing&&(l.style.letterSpacing=`${r.data.textData.letterSpacing}px`),r.data.textData.textShadow?l.style.textShadow=`${r.data.textData.textShadow}`:l.style.textShadow="none",r.data.textData.alignContent){let d=l.querySelector(".ql-editor");d.style.alignContent=`${r.data.textData.alignContent}`;}this.quill=u.getQuill(),this.quill.clipboard.dangerouslyPasteHTML(r.text),r.parent.children[0].tag.includes("Shape")?(c.width=r.parent.width*a+"px",c.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,d=>{let{target:g}=d.origin,f=false;for(;g;)g===l&&(f=true),g=g.parentElement;f||(n.closeInnerEditor(),n.cancel());})];}onUpdate(){let{editTarget:n}=this,{scaleX:t,scaleY:r}=n.worldTransform,s=Math.max(Math.abs(t),Math.abs(r)),{width:o,height:a}=n.parent.__local;o*=s,a*=s;let{x:l,y:c}=this.inBody?n.app.clientBounds:n.app.tree.clientBounds,{a:d,b:g,c:f,d:h,e:F,f:w}=new core.Matrix(n.worldTransform).scale(1/s).translateInner(0,0),{style:x}=this.editDom;x.transform=`matrix(${d},${g},${f},${h},${F},${w})`,x.left=l+"px",x.top=c+"px",n.set({visible:false});}onUnload(){let{editTarget:n,editor:t,editDom:r}=this;n&&(this.onInput(),t.app&&(t.app.config.keyEvent=this.n),t.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);}};C=y([editor.registerInnerEditor()],C);function U(e,{insertAt:i}={}){if(typeof document>"u")return;let n=document.head||document.getElementsByTagName("head")[0],t=document.createElement("style");t.type="text/css",i==="top"&&n.firstChild?n.insertBefore(t,n.firstChild):n.appendChild(t),t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e));}U(`.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 A=class e{constructor(){this.quill=null;this.app_=null;this.t=0;}static getInstance(){return e.instance||(e.instance=new e),e.instance}async init(i){if(this.t=await B(),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 T__default.default("#textInnerEditor",{theme:void 0,modules:{toolbar:false,keyboard:{bindings:{enter:{key:"Enter",handler:t=>{if(!this.t)return true;let[r]=this.quill.getLine(t.index),s=T__default.default.import("blots/block");if(!s?.bubbleFormats)return true;let o=s.bubbleFormats(r),a=new T.Delta().retain(t.index).delete(t.length).insert(`
3
+ `,o);return this.quill.updateContents(a,T__default.default.sources.USER),this.quill.setSelection(t.index+1,T__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,T__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,t){let{editor:r}=this.app_||{};if(!r)return;let s=t||r.leafList?.list,o=a=>{n&&(a.tag==="Box"||a.name==="Text")?i(a.children?.[0]||a):i(a);};if(s?.length)if(Array.isArray(s)&&s.length>1){this.app_.lockLayout();let a=s.length*this.t;for(let l=0;l<a;l++)o(s[l]);this.app_.unlockLayout(),r.updateEditBox();}else this.t&&o(s[0]);}},u=A.getInstance();exports.HtmlText=class H extends core.Box{get __tag(){return "HtmlText"}constructor(i){let{text:n,fontSize:t,fontFamily:r,lineHeight:s,letterSpacing:o,textShadow:a,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:n,fontSize:t,fontFamily:r,lineHeight:s,letterSpacing:o,textShadow:a,alignContent:l}=i,c="<style>p{margin:0;}sub,sup{font-size:63%;}.ql-ui{position:absolute}ol,ul{counter-reset:list-0;padding-left:1.5em;margin:0}ol>li,ul>li{counter-increment:list-0;list-style-type:none;position:relative;padding-left:0;margin:0}ol>li::before{content:counter(list-0,decimal) '. ';position:absolute;left:-1.5em;width:1.2em;text-align:right}ul>li::before{content:'\u2022';position:absolute;left:-1.5em;width:1.2em;text-align:right}li[data-list]{counter-set:list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-align-center{text-align:center}.ql-align-right{text-align:right}.ql-align-left{text-align:left}.ql-align-justify{text-align:justify}</style>",d=`<div style="ove
4
+ rflow-wrap:break-word;word-break:break-all;"><p style="font-size: ${t}px; line-height: ${s}; letter-spacing: ${o}px; text-shadow: ${a};"><strong>Hello World</strong></p></div>`;if(i.children?.length>0)return;let g=new html.HTMLText({name:"Text",text:c+(n||d),x:0,y:0,data:{canChangeBox:false,textData:{fontFamily:r,fontSize:t,lineHeight:s,letterSpacing:o||0,textShadow:a,alignContent:l}},editConfig:{selectedStyle:{strokeWidth:0}}});this.add(g);}};exports.HtmlText=y([core.registerUI()],exports.HtmlText);exports.checkLicense=B;exports.getLicenseInfo=I;exports.htmlTextManage=u;exports.setHTMLText=Bt;exports.setLicense=G;exports.updataHtmlText=p;
package/dist/index.d.mts CHANGED
@@ -7,12 +7,13 @@ declare class HtmlTextManage {
7
7
  private static instance;
8
8
  private quill;
9
9
  app_: any | null;
10
+ private _m;
10
11
  private constructor();
11
12
  static getInstance(): HtmlTextManage;
12
13
  init(app: any): Promise<Quill__default | undefined>;
13
- getQuill(): Quill__default;
14
+ getQuill(): Quill__default | null;
14
15
  getCanvas(): any;
15
- getSelection(): Quill.Range | undefined;
16
+ getSelection(): Quill.Range | null | undefined;
16
17
  private registerFonts;
17
18
  isMultiSelect(): boolean;
18
19
  dateEdit(callback: (leaf: any) => void, level?: number, listNew?: any): void;
@@ -59,28 +60,20 @@ interface LicenseData {
59
60
  }
60
61
 
61
62
  /**
62
- * License 管理器
63
- *
64
- * 提供统一的 License 管理接口
63
+ * License 管理器 - 加固版本
64
+ * 使用数值计算替代布尔判断,移除所有可搜索的敏感信息
65
65
  */
66
66
 
67
67
  /**
68
68
  * 设置 License
69
- *
70
- * @param license - License Key 字符串
71
- * @returns 是否激活成功
72
69
  */
73
70
  declare function setLicense(license: string): Promise<boolean>;
74
71
  /**
75
- * 检查 License 是否有效
76
- *
77
- * @returns License 是否有效
72
+ * 检查 License - 返回数值乘数 (0 或 1)
78
73
  */
79
- declare function checkLicense(): Promise<boolean>;
74
+ declare function checkLicense(): Promise<number>;
80
75
  /**
81
76
  * 获取 License 信息
82
- *
83
- * @returns License 数据或 null
84
77
  */
85
78
  declare function getLicenseInfo(): LicenseData | null;
86
79
 
package/dist/index.d.ts CHANGED
@@ -7,12 +7,13 @@ declare class HtmlTextManage {
7
7
  private static instance;
8
8
  private quill;
9
9
  app_: any | null;
10
+ private _m;
10
11
  private constructor();
11
12
  static getInstance(): HtmlTextManage;
12
13
  init(app: any): Promise<Quill__default | undefined>;
13
- getQuill(): Quill__default;
14
+ getQuill(): Quill__default | null;
14
15
  getCanvas(): any;
15
- getSelection(): Quill.Range | undefined;
16
+ getSelection(): Quill.Range | null | undefined;
16
17
  private registerFonts;
17
18
  isMultiSelect(): boolean;
18
19
  dateEdit(callback: (leaf: any) => void, level?: number, listNew?: any): void;
@@ -59,28 +60,20 @@ interface LicenseData {
59
60
  }
60
61
 
61
62
  /**
62
- * License 管理器
63
- *
64
- * 提供统一的 License 管理接口
63
+ * License 管理器 - 加固版本
64
+ * 使用数值计算替代布尔判断,移除所有可搜索的敏感信息
65
65
  */
66
66
 
67
67
  /**
68
68
  * 设置 License
69
- *
70
- * @param license - License Key 字符串
71
- * @returns 是否激活成功
72
69
  */
73
70
  declare function setLicense(license: string): Promise<boolean>;
74
71
  /**
75
- * 检查 License 是否有效
76
- *
77
- * @returns License 是否有效
72
+ * 检查 License - 返回数值乘数 (0 或 1)
78
73
  */
79
- declare function checkLicense(): Promise<boolean>;
74
+ declare function checkLicense(): Promise<number>;
80
75
  /**
81
76
  * 获取 License 信息
82
- *
83
- * @returns License 数据或 null
84
77
  */
85
78
  declare function getLicenseInfo(): LicenseData | null;
86
79
 
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import {registerEditTool,registerInnerEditor,EditTool,EditorScaleEvent,InnerEditor}from'@leafer-in/editor';import {PointerEvent}from'leafer-ui';import m from'crypto-js';import {registerUI,Box,PointerEvent as PointerEvent$1,Matrix}from'@leafer-ui/core';import S,{Delta}from'quill';import'quill/dist/quill.core.css';import {FontStyle}from'quill/formats/font';import {HTMLText}from'@leafer-in/html';function _(t){let i=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 c of Array.from(r.childNodes))o(c).forEach((g,p)=>{let h=r.cloneNode(false);h.appendChild(g),l.push(h);});return l}return []}let s=[];for(let r of Array.from(i.childNodes)){let l=o(r);s.push(...l);}let a=document.createElement("div");return s.forEach((r,l)=>{a.appendChild(r);}),a.innerHTML}var A="LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxaUFnU1hWM3dMKzh2YkZ2OVkwQwpEN1dBUjhPa2I4bjlmTWxpQjF3enZodTBrdVdZUWEvMUxvVDhHWVh6WWlRQVFBRk9zTTA0MGp2dlNRT2hRSWpiCjRaYXZ1NHUvWVA5bElPYjFKYnZnYkFoYVVOQnphL0l2UmFnaFlKYTJBc1cyRVhnZkVrdmMyUENNMS9zbVlFNnoKNjZiUmx1dnREK3FJZkpLVCtUUXJRRmp5TnNTZ0c2Z2R4MThrZTRMSStBejFPcklMbUsyMHlBU2tlRXpYT1BTVAplM3RNYThleHpZdmUzV0wyNHRHUHg5WHNvN1JyUEl1elZlajh0NDYrZ0c1Y0pQaVh0N1lqa0V2NEJOUUt5eUpoCkltOVRJdVZ6clFpa2NJNE14dExNSGdUMHpLcU9ZZ1NzcmEvTHNDd2ZOdzdtYWxITkU2c21YZWYyQ2E5RGhZODQKS1FJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==";function Y(t){let e=t.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");return F(e)}function F(t){let e=atob(t),n=new Uint8Array(e.length);for(let i=0;i<e.length;i++)n[i]=e.charCodeAt(i);return n.buffer}async function K(){let t=atob(A),e=Y(t);return await crypto.subtle.importKey("spki",e,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},false,["verify"])}async function P(t,e){try{let n=await K(),i=new TextEncoder().encode(t),o=F(e);return await crypto.subtle.verify("RSASSA-PKCS1-v1_5",n,o,i)}catch(n){return console.error("[RSA] Signature verification failed:",n),false}}var U="c19496eb17719960b6c3cebab0ef5eddfce5d0315ab8c5af86a52fbda434fea9",I="ce1e3e8974f1392b3c5803b34ecf659f";function N(t){try{let e=m.enc.Hex.parse(U),n=m.enc.Hex.parse(I),o=m.AES.decrypt(t,e,{iv:n,mode:m.mode.CBC,padding:m.pad.Pkcs7}).toString(m.enc.Utf8);if(!o)throw new Error("Decryption resulted in empty string - invalid ciphertext or wrong key");return o}catch(e){throw console.error("[AES] Decryption failed:",e),e}}async function Q(t){try{let e=atob(t),n=JSON.parse(e);if(!n.data||!n.signature||!await P(n.data,n.signature))return null;let o=n.data;if(n.encrypted)try{o=N(n.data);}catch{return null}return JSON.parse(o)}catch{return null}}function Z(t){if(!t||t.length===0)return true;let e=window.location.hostname;if(e==="localhost"||e==="127.0.0.1")return console.log("[License] Local development environment detected"),true;let n=t.some(i=>{if(i.startsWith("*.")){let o=i.slice(2);return e.endsWith(o)}return e===i});return n||(console.error(`[License] Domain not authorized: ${e}`),console.error("[License] Allowed domains:",t)),n}function W(t){if(!t)return true;try{let e=new Date(t),n=new Date;if(n>=e)return console.error(`[License] License has expired on ${t}`),!1;let i=Math.ceil((e.getTime()-n.getTime())/(1e3*60*60*24));return i<=7&&console.warn(`[License] License will expire in ${i} days`),!0}catch{return console.error("[License] Invalid expire date format:",t),false}}function j(t){if(!t)return true;try{return new Date(t)>new Date?(console.error("[License] License issue date is in the future"),!1):!0}catch{return true}}async function D(t){try{let e=await Q(t);return e?j(e.issueDate)?Z(e.domains)?W(e.expireDate)?{valid:!0,data:e}:{valid:!1,error:"License has expired",data:e}:{valid:!1,error:`License not valid for domain: ${window.location.hostname}`,data:e}:{valid:!1,error:"Invalid license issue date",data:e}:{valid:!1,error:"Invalid license key or signature verification failed"}}catch(e){return console.error("[License] Validation error:",e),{valid:false,error:"License validation failed"}}}var E=null,L=null,y=false;async function J(t){console.log("[License] Activating license...");let e=await D(t);return e.valid&&e.data?(E=t,L=e.data,y=true,console.log("[License] \u2705 License activated successfully"),console.log(`[License] Valid until: ${e.data.expireDate||"unlimited"}`),true):(E=null,L=null,y=false,console.error("[License] \u274C License activation failed:",e.error),false)}async function M(){if(!E)return console.warn("[License] No license key provided"),false;if(!y)return console.warn("[License] License is not valid"),false;let t=await D(E);return y=t.valid,y||(console.error("[License] License validation failed:",t.error),L=null),y}function C(){return L}var f=async(t,e,n)=>{let{scaleX:i,scaleY:o}=t.worldTransform,s=Math.max(Math.abs(i),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?.alignContent){let c=a.querySelector(".ql-editor");c.style.alignContent=t.data.textData.alignContent;}let l=d.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 c=t.text.split("</style>")[0];if(n&&!c.includes(n)){let u=`@font-face {font-family: ${n.split(",")[0]};src: url(${e}) format('woff2') }</style>`;t.text=c+u+v(t,l,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent);}else t.text=c+"</style>"+v(t,l,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent);}else if(e&&n){let c=`<style>@font-face {font-family: ${n.split(",")[0]};src: url(${e}) format('woff2') }</style>`;t.text=c+v(t,l,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent);}else t.text=v(t,l,t.data.textData.fontSize,t.data.textData.lineHeight,t.data.textData.letterSpacing,t.data.textData.textShadow,t.data.textData?.alignContent);},v=(t,e,n=20.67,i=1.5,o=0,s="none",a="start")=>{let{scaleX:r,scaleY:l}=t.worldTransform,c=Math.max(Math.abs(r),Math.abs(l)),u=document.createElement("div");u.innerHTML=e;let g={fontSize:`${n}px`,lineHeight:i,letterSpacing:`${o}px`,textShadow:s};u.querySelectorAll("p,ol,ul").forEach(O=>{Object.assign(O.style,g);});let p=u.innerHTML;/<p\b[^>]*><\/p>/.test(p)&&(p=p.replace(/<p\b([^>]*)><\/p>/g,"<p$1>&nbsp;</p>")),/&quot;/.test(p)&&(p=p.replace(/&quot;/g,""));let h;document.querySelector("#textInnerEditor");let B=d.getQuill(),w=Number((B.scroll.domNode.scrollHeight/c).toFixed(0));Number((B.scroll.domNode.scrollWidth/c).toFixed(0));["center","end"].includes(t.data.textData.alignContent)?t.parent.height<w?h=(w||t.__layout.boxBounds.height)+"px":h=`${t.parent.height}px`:t.parent.height<w?h=(w||t.__layout.boxBounds.height)+"px":h=`${t.parent.height}px`;let b="<style>p{margin:0;}sub,sup{font-size:63%;}.ql-ui{position:absolute}ol,ul{counter-reset:list-0;padding-left:1.5em;margin:0}ol>li,ul>li{counter-increment:list-0;list-style-type:none;position:relative;padding-left:0;margin:0}ol>li::before{content:counter(list-0,decimal) '. ';position:absolute;left:-1.5em;width:1.2em;text-align:right}ul>li::before{content:'\u2022';position:absolute;left:-1.5em;width:1.2em;text-align:right}li[data-list]{counter-set:list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-align-center{text-align:center}.ql-align-right{text-align:right}.ql-align-left{text-align:left}.ql-align-justify{text-align:justify}</style>",x="";return t.parent.children[0].tag.includes("Shape")?x=b+`<div style="width: ${t.parent.width}px;height: ${t.parent.height}px;overflow-wrap:break-word;word-break:break-all;align-content:center;">${p}</div>`:t.data.canChangeBox?x=b+`<div style="width: ${t.parent.width}px;height:${h};overflow-wrap:break-word;word-break:break-all;align-content:${a};">${p}</div>`:t.data.textData.italic?x=b+p:x=b+`<div style="overflow-wrap:break-word;word-break:break-all;">${p}</div>`,console.log(x,"\u6700\u7EC8\u7684html\u5185\u5BB9"),x},Ut=(t,e,n)=>{let i=d.getQuill(),{editor:o,canvas:s}=d.getCanvas();if(!i)return;e===0&&(e="0");let a=i.selection.savedRange;d.dateEdit(async r=>{if(r.tag!=="HTMLText"){console.log("\u975EHtml\u6587\u672C\u5143\u7D20\u65E0\u6CD5\u4FEE\u6539");return}if(t==="font")o.innerEditing?(a&&a.length?i.formatText(a.index,a.length,t,e):i.formatText(0,i.getLength()-1,t,e),r.data.textData.fontFamily=e,f(r,n??null,e??null)):(d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),i.formatText(0,i.getLength()-1,t,e),r.data.textData.fontFamily=e,f(r,n??null,e??null));else if(t==="fontSize")r.data.textData[t]=e,d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),f(r,n??null);else if(t==="textCase"){if(o.innerEditing){let l=i.getText(a.index,a.length),c=i.getFormat(a.index,a.length);i.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()),i.insertText(a.index,u,c),a&&o.innerEditing&&i.setSelection(a.index,a.length);}}else if(t==="script"){let l="sub";e==="super"&&(l="sup"),o.innerEditing?a&&a.length?i.formatText(a.index,a.length,t,i.getFormat(a).script===e?false:l):i.formatText(0,i.getLength()-1,t,i.getFormat().script===e?false:l):(d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),i.formatText(0,i.getLength()-1,t,i.getFormat().script===e?false:l),f(r));}else if(t==="align")d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),o.innerEditing?i.format(t,e):i.formatLine(0,i.getLength(),t,e),f(r);else if(t==="alignContent")d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=e,f(r);else if(t==="lineHeight"||t==="letterSpacing")d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=e,f(r);else if(t==="color")d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),a&&a.length?i.formatText(a.index,a.length,t,e):i.formatText(0,i.getLength()-1,t,e),r.tag==="HTMLText"?f(r):r.parent.findOne("HTMLText")&&f(r.parent.findOne("HTMLText"));else if(t==="textShadow")d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),r.data.textData[t]=e,f(r);else if(t==="list"){if(d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),o.innerEditing){let[l]=i.getLine(a?.index||0);l.formats().list?i.format(t,false):i.format(t,e);}else {let[l]=i.getLine(a?.index||0);l.formats().list?i.formatLine(0,i.getLength(),t,false):i.formatLine(0,i.getLength(),t,e);}f(r);}else if(t==="textVertical"){let l=C();if(l&&l?.features?.length&&l?.features?.includes("textVertical")){i.clipboard.dangerouslyPasteHTML(r.text);let c=i.getSemanticHTML();i.clipboard.dangerouslyPasteHTML(_(c)),r.data.textData.align="center",f(r);}}else o.innerEditing?a&&a.length?i.formatText(a.index,a.length,t,e===void 0?!i.getFormat(a)[t]:e):i.formatText(0,i.getLength()-1,t,e===void 0?!i.getFormat()[t]:e):(d.isMultiSelect()&&i.clipboard.dangerouslyPasteHTML(r.text),i.formatText(0,i.getLength()-1,t,e===void 0?!i.getFormat()[t]:e),f(r));},1);};var G=(t,e,n,i)=>{for(var o=e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(o=(a(o))||o);return o},z=class extends EditTool{constructor(t){super(t),this.quill=null,this.isUpdatingPoints=false,this.curveAmount=0,this.eventIds=[],this.updateBoxDebounced=this.debounce(e=>{f(e);},300);}get tag(){return "TextEditTool"}debounce(t,e){let n=null;return((...i)=>{n!==null&&window.clearTimeout(n),n=window.setTimeout(()=>t.apply(this,i),e);})}addEvent(){let{editor:t}=d.getCanvas();if(t.multiple)return;let e=t.leafList.list[0].findOne("HTMLText");if(!e)return;let{scaleX:n,scaleY:i}=e.worldTransform,o=Math.max(Math.abs(n),Math.abs(i)),s=document.querySelector("#textInnerEditor"),{style:a}=s;this.eventIds=[t.on_(EditorScaleEvent.SCALE,r=>{e.data.canChangeBox||(e.data.canChangeBox=true),e.data.canChangeBox&&(a.width=e.parent.width*o+"px",a.height="auto");let l=1;e.parent.tag==="HtmlText"&&e.parent.lockRatio&&e.data?.baseSize?.width&&(l=e.parent.width/e.data?.baseSize.width,e.data.textData.fontSize=e.data.textData.fontSize*l),e.data?.baseSize?.width&&(e.data.baseSize.width=e.parent.width),this.updateBoxDebounced(e);}),t.on_(PointerEvent.DOUBLE_TAP,()=>{e.parent.locked||t.openInnerEditor(e,true);})];}onLoad(){let{editor:t}=d.getCanvas();if(t.multiple)return;let e=t.leafList.list[0].findOne("HTMLText");if(!e)return;let{scaleX:n,scaleY:i}=e.worldTransform,o=Math.max(Math.abs(n),Math.abs(i));this.addEvent(),this.quill=d.getQuill(),this.quill.clipboard.dangerouslyPasteHTML(e.text);let s=document.querySelector("#textInnerEditor"),{style:a}=s;e.data.canChangeBox?(a.width=e.parent.width*o+"px",a.height=e.parent.height*o+"px"):(a.width="auto",a.height="auto");}updateChangeBoxBound(t){t&&t.set({width:t.__layout.boxBounds.width,height:t.__layout.boxBounds.height});}onUpdate(){let{editor:t}=d.getCanvas();if(t.multiple)return;let e=t.leafList.list[0].findOne("HTMLText");e&&(console.log("\u6587\u672Cbound\u66F4\u65B0"),this.curveAmount!=e.curveAmount&&this.isUpdatingPoints);}onUnload(){let{editor:t}=d.getCanvas();t.off_(this.eventIds);}onDestroy(){}};z=G([registerEditTool()],z);var ot=(t,e,n,i)=>{for(var o=e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(o=(a(o))||o);return o},V=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._keyEvent=void 0,this.quill=null,this.isComposing=false,this.onInput=async()=>{let{editDom:t}=this;f(this.editTarget);},this.isUpdatingPoints=false;}get tag(){return "TextEditor"}onLoad(){let{editor:t}=this,{config:e}=t.app,n=this.editTarget,{scaleX:i,scaleY:o}=n.worldTransform,s=Math.max(Math.abs(i),Math.abs(o));this.isHTMLText=!(n instanceof Text),this._keyEvent=e.keyEvent,e.keyEvent=false;let a=this.editDom=document.querySelector("#textInnerEditor"),{style:r}=a;if(r.visibility="visible",n.data.canChangeBox?(r.width=n.parent.width*s+"px",r.height=n.parent.height*s+"px"):(r.width="auto",r.height="auto"),r.outline="solid #8499EF",n.data.textData.fontSize&&(a.style.fontSize=`${n.data.textData.fontSize*s}px`),n.data.textData.lineHeight&&(a.style.lineHeight=n.data.textData.lineHeight),n.data.textData.letterSpacing&&(a.style.letterSpacing=`${n.data.textData.letterSpacing}px`),n.data.textData.textShadow?a.style.textShadow=`${n.data.textData.textShadow}`:a.style.textShadow="none",n.data.textData.alignContent){let l=a.querySelector(".ql-editor");l.style.alignContent=`${n.data.textData.alignContent}`;}this.quill=d.getQuill(),this.quill.clipboard.dangerouslyPasteHTML(n.text),n.parent.children[0].tag.includes("Shape")?(r.width=n.parent.width*s+"px",r.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=[t.app.on_(PointerEvent$1.DOWN,l=>{let{target:c}=l.origin,u=false;for(;c;)c===a&&(u=true),c=c.parentElement;u||(t.closeInnerEditor(),t.cancel());})];}onUpdate(){let{editTarget:t}=this,{scaleX:e,scaleY:n}=t.worldTransform,i=Math.max(Math.abs(e),Math.abs(n)),{width:o,height:s}=t.parent.__local;o*=i,s*=i;let{x:a,y:r}=this.inBody?t.app.clientBounds:t.app.tree.clientBounds,{a:l,b:c,c:u,d:g,e:p,f:h}=new Matrix(t.worldTransform).scale(1/i).translateInner(0,0),{style:T}=this.editDom;T.transform=`matrix(${l},${c},${u},${g},${p},${h})`,T.left=a+"px",T.top=r+"px",t.set({visible:false});}onUnload(){let{editTarget:t,editor:e,editDom:n}=this;t&&(this.onInput(),e.app&&(e.app.config.keyEvent=this._keyEvent),e.off_(this.eventIds),this.editDom.style.visibility="hidden",this.eventIds=[]),t.parent&&t.parent.name=="Text"&&t.parent.children.some(i=>i.tag==="Box")?(t.parent.findOne("Box").opacity=1,t.visible=false):t.set({visible:true}),this.quill.getLength()===1&&t.parent.name==="Text"&&t.parent.remove(),this.quill.off("text-change",this.onInput);}};V=ot([registerInnerEditor()],V);function q(t,{insertAt:e}={}){if(typeof document>"u")return;let n=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css",e==="top"&&n.firstChild?n.insertBefore(i,n.firstChild):n.appendChild(i),i.styleSheet?i.styleSheet.cssText=t:i.appendChild(document.createTextNode(t));}q(`.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 H=class t{constructor(){this.quill=null,this.app_=null;}static getInstance(){return t.instance||(t.instance=new t),t.instance}async init(e){if(!await M())throw new Error("[HtmlTextManage] \u6388\u6743\u5931\u8D25\u8BF7\u8054\u7CFB\u4F5C\u8005\u83B7\u53D6\u6388\u6743 \u90AE\u7BB1 : 408550179@qq.com \u5FAE\u4FE1 : cym5640");if(this.app_=e,this.quill)return this.quill;let i=document.getElementById("textInnerEditor");if(i)this.quill=this.app_.editor.quill;else return i=document.createElement("div"),i.id="textInnerEditor",i.style.position="fixed",i.style.transformOrigin="left top",i.style.overflowWrap="break-word",i.style.wordBreak="break-all",i.style.visibility="hidden",document.body.appendChild(i),this.quill=new S("#textInnerEditor",{theme:void 0,modules:{toolbar:false,keyboard:{bindings:{enter:{key:"Enter",handler:o=>{let[s]=this.quill.getLine(o.index),a=S.import("blots/block");if(!a?.bubbleFormats)return true;let r=a.bubbleFormats(s),l=new Delta().retain(o.index).delete(o.length).insert(`
3
- `,r);return this.quill.updateContents(l,S.sources.USER),this.quill.setSelection(o.index+1,S.sources.SILENT),false}}}}}}),this.app_.editor.quill=this.quill,this.registerFonts(),this.quill}getQuill(){if(!this.quill)throw new Error("Quill editor not initialized. Call init() first.");return this.quill}getCanvas(){if(!this.app_)throw new Error("app_ editor not initialized. Call init() first.");return this.app_}getSelection(){return console.log(this.quill?.selection.savedRange,"this.quill?.selection.savedRange"),this.quill?.selection.savedRange}registerFonts(){FontStyle.whitelist=void 0,S.register("formats/font",FontStyle,true);}isMultiSelect(){return this.app_.editor?this.app_.editor.multiple===true:false}dateEdit(e,n=0,i){let{editor:o}=this.app_,s=i||o.leafList.list,a=r=>{n&&(r.tag==="Box"||r.name==="Text")?e(r.children?.[0]||r):e(r);};s.length&&(Array.isArray(s)&&s.length>1?(this.app_.lockLayout(),s.forEach(a),this.app_.unlockLayout(),o.updateEditBox()):a(s[0]));}},d=H.getInstance();var ht=(t,e,n,i)=>{for(var o=e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(o=(a(o))||o);return o},R=class extends Box{get __tag(){return "HtmlText"}constructor(t){let{text:e,fontSize:n,fontFamily:i,lineHeight:o,letterSpacing:s,textShadow:a,alignContent:r,...l}=t||{};super({editOuter:"TextEditTool",name:"HtmlText",x:0,y:0,editable:true,draggable:true,overflow:"show",...l}),t&&this.createTextElement(t);}createTextElement(t){let{text:e,fontSize:n,fontFamily:i,lineHeight:o,letterSpacing:s,textShadow:a,alignContent:r}=t,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>",c=`<div style="ove
4
- rflow-wrap:break-word;word-break:break-all;"><p style="font-size: ${n}px; line-height: ${o}; letter-spacing: ${s}px; text-shadow: ${a};"><strong>Hello World</strong></p></div>`;if(t.children?.length>0)return;let u=new HTMLText({name:"Text",text:l+(e||c),x:0,y:0,data:{canChangeBox:false,textData:{fontFamily:i,fontSize:n,lineHeight:o,letterSpacing:s||0,textShadow:a,alignContent:r}},editConfig:{selectedStyle:{strokeWidth:0}}});this.add(u);}};R=ht([registerUI()],R);export{R as HtmlText,M as checkLicense,C as getLicenseInfo,d as htmlTextManage,Ut as setHTMLText,J as setLicense,f as updataHtmlText};
1
+ import {registerEditTool,registerInnerEditor,EditTool,EditorScaleEvent,InnerEditor}from'@leafer-in/editor';import {PointerEvent}from'leafer-ui';import b from'crypto-js';import {registerUI,Box,PointerEvent as PointerEvent$1,Matrix}from'@leafer-ui/core';import T,{Delta}from'quill';import'quill/dist/quill.core.css';import {FontStyle}from'quill/formats/font';import {HTMLText}from'@leafer-in/html';var y=(e,i,n,t)=>{for(var r=i,s=e.length-1,o;s>=0;s--)(o=e[s])&&(r=(o(r))||r);return r};function N(e){let t=new DOMParser().parseFromString(e,"text/html").body;function r(a){if(a.nodeType===Node.TEXT_NODE){let l=a.textContent;return l?Array.from(l).map(d=>document.createTextNode(d)):[]}else if(a.nodeType===Node.ELEMENT_NODE){let l=[];for(let c of Array.from(a.childNodes))r(c).forEach((g,f)=>{let h=a.cloneNode(false);h.appendChild(g),l.push(h);});return l}return []}let s=[];for(let a of Array.from(t.childNodes)){let l=r(a);s.push(...l);}let o=document.createElement("div");return s.forEach((a,l)=>{o.appendChild(a);}),o.innerHTML}var P="LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxaUFnU1hWM3dMKzh2YkZ2OVkwQwpEN1dBUjhPa2I4bjlmTWxpQjF3enZodTBrdVdZUWEvMUxvVDhHWVh6WWlRQVFBRk9zTTA0MGp2dlNRT2hRSWpiCjRaYXZ1NHUvWVA5bElPYjFKYnZnYkFoYVVOQnphL0l2UmFnaFlKYTJBc1cyRVhnZkVrdmMyUENNMS9zbVlFNnoKNjZiUmx1dnREK3FJZkpLVCtUUXJRRmp5TnNTZ0c2Z2R4MThrZTRMSStBejFPcklMbUsyMHlBU2tlRXpYT1BTVAplM3RNYThleHpZdmUzV0wyNHRHUHg5WHNvN1JyUEl1elZlajh0NDYrZ0c1Y0pQaVh0N1lqa0V2NEJOUUt5eUpoCkltOVRJdVZ6clFpa2NJNE14dExNSGdUMHpLcU9ZZ1NzcmEvTHNDd2ZOdzdtYWxITkU2c21YZWYyQ2E5RGhZODQKS1FJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==";function Z(e){let i=e.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");return z(i)}function z(e){let i=atob(e),n=new Uint8Array(i.length);for(let t=0;t<i.length;t++)n[t]=i.charCodeAt(t);return n.buffer}async function O(){let e=atob(P),i=Z(e);return await crypto.subtle.importKey("spki",i,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},false,["verify"])}async function _(e,i){try{let n=await O(),t=new TextEncoder().encode(e),r=z(i);return await crypto.subtle.verify("RSASSA-PKCS1-v1_5",n,r,t)}catch{return false}}var R="c19496eb17719960b6c3cebab0ef5eddfce5d0315ab8c5af86a52fbda434fea9",V="ce1e3e8974f1392b3c5803b34ecf659f";function $(e){try{let i=b.enc.Hex.parse(R),n=b.enc.Hex.parse(V),r=b.AES.decrypt(e,i,{iv:n,mode:b.mode.CBC,padding:b.pad.Pkcs7}).toString(b.enc.Utf8);if(!r)throw new Error("Decryption resulted in empty string - invalid ciphertext or wrong key");return r}catch(i){throw i}}async function W(e){try{let i=atob(e),n=JSON.parse(i);if(!n.data||!n.signature||!await _(n.data,n.signature))return null;let r=n.data;if(n.encrypted)try{r=$(n.data);}catch{return null}return JSON.parse(r)}catch{return null}}function J(e){if(!e||e.length===0)return true;let i=window.location.hostname;if(i==="localhost"||i==="127.0.0.1")return true;let n=e.some(t=>{if(t.startsWith("*.")){let r=t.slice(2);return i.endsWith(r)}return i===t});return n}function j(e){if(!e)return true;try{let i=new Date(e),n=new Date;return n>=i?!1:(Math.ceil((i.getTime()-n.getTime())/(1e3*60*60*24))<=7,!0)}catch{return false}}function X(e){if(!e)return true;try{return !(new Date(e)>new Date)}catch{return true}}async function q(e){try{let i=await W(e);return i?X(i.issueDate)?J(i.domains)?j(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 L=null,E=null,m=0;async function G(e){let i=await q(e);return i.valid&&i.data?(L=e,E=i.data,m=1,true):(L=null,E=null,m=0,false)}async function B(){return !L||!m?0:(m=(await q(L)).valid?1:0,m||(E=null),m)}function I(){return m?E:null}var p=async(e,i,n)=>{let{scaleX:t,scaleY:r}=e.worldTransform,s=Math.max(Math.abs(t),Math.abs(r)),o=document.querySelector("#textInnerEditor");if(o&&e.data.textData?.fontSize&&(o.style.fontSize=`${e.data.textData.fontSize*s}px`),o&&e.data.textData?.lineHeight&&(o.style.lineHeight=e.data.textData.lineHeight),o&&e.data.textData?.letterSpacing&&(o.style.letterSpacing=`${e.data.textData.letterSpacing}px`),o&&e.data.textData?.textShadow?o.style.textShadow=e.data.textData.textShadow:o.style.textShadow="none",o&&e.data.textData?.alignContent){let c=o.querySelector(".ql-editor");c.style.alignContent=e.data.textData.alignContent;}let l=u.getQuill().getSemanticHTML();if(l==="<p></p>"){e.text.includes("<style>@font-face")?e.text=e.text.split("</style>")[0]+"</style>":e.text="";return}if(e.text.includes("<style>@font-face")){let c=e.text.split("</style>")[0];if(n&&!c.includes(n)){let d=`@font-face {font-family: ${n.split(",")[0]};src: url(${i}) format('woff2') }</style>`;e.text=c+d+v(e,l,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent);}else e.text=c+"</style>"+v(e,l,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent);}else if(i&&n){let c=`<style>@font-face {font-family: ${n.split(",")[0]};src: url(${i}) format('woff2') }</style>`;e.text=c+v(e,l,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent);}else e.text=v(e,l,e.data.textData.fontSize,e.data.textData.lineHeight,e.data.textData.letterSpacing,e.data.textData.textShadow,e.data.textData?.alignContent);},v=(e,i,n=20.67,t=1.5,r=0,s="none",o="start")=>{let{scaleX:a,scaleY:l}=e.worldTransform,c=Math.max(Math.abs(a),Math.abs(l)),d=document.createElement("div");d.innerHTML=i;let g={fontSize:`${n}px`,lineHeight:t,letterSpacing:`${r}px`,textShadow:s};d.querySelectorAll("p,ol,ul").forEach(k=>{Object.assign(k.style,g);});let f=d.innerHTML;/<p\b[^>]*><\/p>/.test(f)&&(f=f.replace(/<p\b([^>]*)><\/p>/g,"<p$1>&nbsp;</p>")),/&quot;/.test(f)&&(f=f.replace(/&quot;/g,""));let h;document.querySelector("#textInnerEditor");let w=u.getQuill(),x=Number((w.scroll.domNode.scrollHeight/c).toFixed(0));Number((w.scroll.domNode.scrollWidth/c).toFixed(0));["center","end"].includes(e.data.textData.alignContent)?e.parent.height<x?h=(x||e.__layout.boxBounds.height)+"px":h=`${e.parent.height}px`:e.parent.height<x?h=(x||e.__layout.boxBounds.height)+"px":h=`${e.parent.height}px`;let 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>",S="";return e.parent.children[0].tag.includes("Shape")?S=D+`<div style="width: ${e.parent.width}px;height: ${e.parent.height}px;overflow-wrap:break-word;word-break:break-all;align-content:center;">${f}</div>`:e.data.canChangeBox?S=D+`<div style="width: ${e.parent.width}px;height:${h};overflow-wrap:break-word;word-break:break-all;align-content:${o};">${f}</div>`:e.data.textData.italic?S=D+f:S=D+`<div style="overflow-wrap:break-word;word-break:break-all;">${f}</div>`,S},Bt=(e,i,n)=>{let t=u.getQuill(),{editor:r,canvas:s}=u.getCanvas();if(!t)return;i===0&&(i="0");let o=t.selection.savedRange;u.dateEdit(async a=>{if(a.tag==="HTMLText")if(e==="font")r.innerEditing?(o&&o.length?t.formatText(o.index,o.length,e,i):t.formatText(0,t.getLength()-1,e,i),a.data.textData.fontFamily=i,p(a,n??null,i??null)):(u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),t.formatText(0,t.getLength()-1,e,i),a.data.textData.fontFamily=i,p(a,n??null,i??null));else if(e==="fontSize")a.data.textData[e]=i,u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),p(a,n??null);else if(e==="textCase"){if(r.innerEditing){let l=t.getText(o.index,o.length),c=t.getFormat(o.index,o.length);t.deleteText(o.index,o.length);let d;l===l.toUpperCase()&&/[A-Z]/.test(l)?d=l.toLowerCase():(l===l.toLowerCase()&&/[a-z]/.test(l),d=l.toUpperCase()),t.insertText(o.index,d,c),o&&r.innerEditing&&t.setSelection(o.index,o.length);}}else if(e==="script"){let l="sub";i==="super"&&(l="sup"),r.innerEditing?o&&o.length?t.formatText(o.index,o.length,e,t.getFormat(o).script===i?false:l):t.formatText(0,t.getLength()-1,e,t.getFormat().script===i?false:l):(u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),t.formatText(0,t.getLength()-1,e,t.getFormat().script===i?false:l),p(a));}else if(e==="align")u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),r.innerEditing?t.format(e,i):t.formatLine(0,t.getLength(),e,i),p(a);else if(e==="alignContent")u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),a.data.textData[e]=i,p(a);else if(e==="lineHeight"||e==="letterSpacing")u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),a.data.textData[e]=i,p(a);else if(e==="color")u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),o&&o.length?t.formatText(o.index,o.length,e,i):t.formatText(0,t.getLength()-1,e,i),a.tag==="HTMLText"?p(a):a.parent.findOne("HTMLText")&&p(a.parent.findOne("HTMLText"));else if(e==="textShadow")u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),a.data.textData[e]=i,p(a);else if(e==="list"){if(u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),r.innerEditing){let[l]=t.getLine(o?.index||0);l.formats().list?t.format(e,false):t.format(e,i);}else {let[l]=t.getLine(o?.index||0);l.formats().list?t.formatLine(0,t.getLength(),e,false):t.formatLine(0,t.getLength(),e,i);}p(a);}else if(e==="textVertical"){let l=I();if(l&&l?.features?.length&&l?.features?.includes("textVertical")){t.clipboard.dangerouslyPasteHTML(a.text);let c=t.getSemanticHTML();t.clipboard.dangerouslyPasteHTML(N(c)),a.data.textData.align="center",p(a);}}else r.innerEditing?o&&o.length?t.formatText(o.index,o.length,e,i===void 0?!t.getFormat(o)[e]:i):t.formatText(0,t.getLength()-1,e,i===void 0?!t.getFormat()[e]:i):(u.isMultiSelect()&&t.clipboard.dangerouslyPasteHTML(a.text),t.formatText(0,t.getLength()-1,e,i===void 0?!t.getFormat()[e]:i),p(a));},1);};var M=class extends EditTool{constructor(n){super(n);this.quill=null;this.isUpdatingPoints=false;this.curveAmount=0;this.eventIds=[],this.updateBoxDebounced=this.debounce(t=>{p(t);},300);}get tag(){return "TextEditTool"}debounce(n,t){let r=null;return((...s)=>{r!==null&&window.clearTimeout(r),r=window.setTimeout(()=>n.apply(this,s),t);})}addEvent(){let{editor:n}=u.getCanvas();if(n.multiple)return;let t=n.leafList.list[0].findOne("HTMLText");if(!t)return;let{scaleX:r,scaleY:s}=t.worldTransform,o=Math.max(Math.abs(r),Math.abs(s)),a=document.querySelector("#textInnerEditor"),{style:l}=a;this.eventIds=[n.on_(EditorScaleEvent.SCALE,c=>{t.data.canChangeBox||(t.data.canChangeBox=true),t.data.canChangeBox&&(l.width=t.parent.width*o+"px",l.height="auto");let d=1;t.parent.tag==="HtmlText"&&t.parent.lockRatio&&t.data?.baseSize?.width&&(d=t.parent.width/t.data?.baseSize.width,t.data.textData.fontSize=t.data.textData.fontSize*d),t.data?.baseSize?.width&&(t.data.baseSize.width=t.parent.width),this.updateBoxDebounced(t);}),n.on_(PointerEvent.DOUBLE_TAP,()=>{t.parent.locked||n.openInnerEditor(t,true);})];}onLoad(){let{editor:n}=u.getCanvas();if(n.multiple)return;let t=n.leafList.list[0].findOne("HTMLText");if(!t)return;let{scaleX:r,scaleY:s}=t.worldTransform,o=Math.max(Math.abs(r),Math.abs(s));this.addEvent(),this.quill=u.getQuill(),this.quill.clipboard.dangerouslyPasteHTML(t.text);let a=document.querySelector("#textInnerEditor"),{style:l}=a;t.data.canChangeBox?(l.width=t.parent.width*o+"px",l.height=t.parent.height*o+"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}=u.getCanvas();if(n.multiple)return;let t=n.leafList.list[0].findOne("HTMLText");t&&this.curveAmount!=t.curveAmount&&this.isUpdatingPoints;}onUnload(){let{editor:n}=u.getCanvas();n.off_(this.eventIds);}onDestroy(){}};M=y([registerEditTool()],M);var C=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:t}=n.app,r=this.editTarget,{scaleX:s,scaleY:o}=r.worldTransform,a=Math.max(Math.abs(s),Math.abs(o));this.isHTMLText=!(r instanceof Text),this.n=t.keyEvent,t.keyEvent=false;let l=this.editDom=document.querySelector("#textInnerEditor"),{style:c}=l;if(c.visibility="visible",r.data.canChangeBox?(c.width=r.parent.width*a+"px",c.height=r.parent.height*a+"px"):(c.width="auto",c.height="auto"),c.outline="solid #8499EF",r.data.textData.fontSize&&(l.style.fontSize=`${r.data.textData.fontSize*a}px`),r.data.textData.lineHeight&&(l.style.lineHeight=r.data.textData.lineHeight),r.data.textData.letterSpacing&&(l.style.letterSpacing=`${r.data.textData.letterSpacing}px`),r.data.textData.textShadow?l.style.textShadow=`${r.data.textData.textShadow}`:l.style.textShadow="none",r.data.textData.alignContent){let d=l.querySelector(".ql-editor");d.style.alignContent=`${r.data.textData.alignContent}`;}this.quill=u.getQuill(),this.quill.clipboard.dangerouslyPasteHTML(r.text),r.parent.children[0].tag.includes("Shape")?(c.width=r.parent.width*a+"px",c.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,d=>{let{target:g}=d.origin,f=false;for(;g;)g===l&&(f=true),g=g.parentElement;f||(n.closeInnerEditor(),n.cancel());})];}onUpdate(){let{editTarget:n}=this,{scaleX:t,scaleY:r}=n.worldTransform,s=Math.max(Math.abs(t),Math.abs(r)),{width:o,height:a}=n.parent.__local;o*=s,a*=s;let{x:l,y:c}=this.inBody?n.app.clientBounds:n.app.tree.clientBounds,{a:d,b:g,c:f,d:h,e:F,f:w}=new Matrix(n.worldTransform).scale(1/s).translateInner(0,0),{style:x}=this.editDom;x.transform=`matrix(${d},${g},${f},${h},${F},${w})`,x.left=l+"px",x.top=c+"px",n.set({visible:false});}onUnload(){let{editTarget:n,editor:t,editDom:r}=this;n&&(this.onInput(),t.app&&(t.app.config.keyEvent=this.n),t.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);}};C=y([registerInnerEditor()],C);function U(e,{insertAt:i}={}){if(typeof document>"u")return;let n=document.head||document.getElementsByTagName("head")[0],t=document.createElement("style");t.type="text/css",i==="top"&&n.firstChild?n.insertBefore(t,n.firstChild):n.appendChild(t),t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e));}U(`.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 A=class e{constructor(){this.quill=null;this.app_=null;this.t=0;}static getInstance(){return e.instance||(e.instance=new e),e.instance}async init(i){if(this.t=await B(),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 T("#textInnerEditor",{theme:void 0,modules:{toolbar:false,keyboard:{bindings:{enter:{key:"Enter",handler:t=>{if(!this.t)return true;let[r]=this.quill.getLine(t.index),s=T.import("blots/block");if(!s?.bubbleFormats)return true;let o=s.bubbleFormats(r),a=new Delta().retain(t.index).delete(t.length).insert(`
3
+ `,o);return this.quill.updateContents(a,T.sources.USER),this.quill.setSelection(t.index+1,T.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,T.register("formats/font",FontStyle,true));}isMultiSelect(){return !this.t||!this.app_?.editor?false:this.app_.editor.multiple===true}dateEdit(i,n=0,t){let{editor:r}=this.app_||{};if(!r)return;let s=t||r.leafList?.list,o=a=>{n&&(a.tag==="Box"||a.name==="Text")?i(a.children?.[0]||a):i(a);};if(s?.length)if(Array.isArray(s)&&s.length>1){this.app_.lockLayout();let a=s.length*this.t;for(let l=0;l<a;l++)o(s[l]);this.app_.unlockLayout(),r.updateEditBox();}else this.t&&o(s[0]);}},u=A.getInstance();var H=class extends Box{get __tag(){return "HtmlText"}constructor(i){let{text:n,fontSize:t,fontFamily:r,lineHeight:s,letterSpacing:o,textShadow:a,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:n,fontSize:t,fontFamily:r,lineHeight:s,letterSpacing:o,textShadow:a,alignContent:l}=i,c="<style>p{margin:0;}sub,sup{font-size:63%;}.ql-ui{position:absolute}ol,ul{counter-reset:list-0;padding-left:1.5em;margin:0}ol>li,ul>li{counter-increment:list-0;list-style-type:none;position:relative;padding-left:0;margin:0}ol>li::before{content:counter(list-0,decimal) '. ';position:absolute;left:-1.5em;width:1.2em;text-align:right}ul>li::before{content:'\u2022';position:absolute;left:-1.5em;width:1.2em;text-align:right}li[data-list]{counter-set:list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-align-center{text-align:center}.ql-align-right{text-align:right}.ql-align-left{text-align:left}.ql-align-justify{text-align:justify}</style>",d=`<div style="ove
4
+ rflow-wrap:break-word;word-break:break-all;"><p style="font-size: ${t}px; line-height: ${s}; letter-spacing: ${o}px; text-shadow: ${a};"><strong>Hello World</strong></p></div>`;if(i.children?.length>0)return;let g=new HTMLText({name:"Text",text:c+(n||d),x:0,y:0,data:{canChangeBox:false,textData:{fontFamily:r,fontSize:t,lineHeight:s,letterSpacing:o||0,textShadow:a,alignContent:l}},editConfig:{selectedStyle:{strokeWidth:0}}});this.add(g);}};H=y([registerUI()],H);export{H as HtmlText,B as checkLicense,I as getLicenseInfo,u as htmlTextManage,Bt as setHTMLText,G as setLicense,p as updataHtmlText};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenyomi/leafer-htmltext-edit",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
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",
@@ -40,9 +40,10 @@
40
40
  "@types/lodash": "^4.17.23",
41
41
  "@types/node": "^20.0.0",
42
42
  "esbuild-plugin-obfuscator": "^1.4.0",
43
- "javascript-obfuscator": "^5.2.1",
43
+ "javascript-obfuscator": "^5.3.0",
44
44
  "tsup": "^8.0.0",
45
- "typescript": "^5.0.0"
45
+ "typescript": "^5.0.0",
46
+ "vite-plugin-javascript-obfuscator": "^3.1.0"
46
47
  },
47
48
  "peerDependencies": {
48
49
  "@leafer-in/editor": "^2.0.0",