@leafer-in/text-editor 1.0.0-rc.25 → 1.0.0-rc.26

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.
@@ -1 +1 @@
1
- "use strict";var t=require("@leafer-ui/core"),e=require("@leafer-in/editor");"function"==typeof SuppressedError&&SuppressedError;const n={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},o={top:"flex-start",middle:"center",bottom:"flex-end"},i=t.inviteCode;function s(t,e,i){const{style:s}=t;s.fontFamily=e.fontFamily,s.fontSize=e.fontSize*i+"px",s.color=e.fill,s.fontStyle=e.italic?"italic":"normal",s.fontWeight=e.fontWeight,s.textDecoration="delete"===e.textDecoration?"line-through":e.textDecoration,s.textTransform=n[e.textCase],s.textAlign=e.textAlign,s.display="flex",s.flexDirection="column",s.justifyContent=o[e.verticalAlign],s.lineHeight=(e.__.__lineHeight||0)*i+"px",s.letterSpacing=(e.__.__letterSpacing||0)*i+"px",s.textIndent=(e.paraIndent||0)*i+"px",s.padding=e.padding instanceof Array?e.padding.map((t=>t*i+"px")).join(" "):(e.padding||0)*i+"px",s.textOverflow="show"===e.textOverflow?"":"hide"===e.textOverflow?"clip":e.textOverflow}function r(t){return t.length>6&&"e"===t[6]}let l=s;setTimeout((function(){Object.values(i).some(r)||(l=()=>s)})),exports.TextEditor=class extends e.InnerEditor{constructor(){super(...arguments),this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:e}=this;e.config.keyEvent=!1;const n=this.text=e.element;n.visible=!1;const o=this.dom=document.createElement("div"),{style:i}=o;o.contentEditable="true",o.innerText=n.text,i.position="fixed",i.transformOrigin="left top";const{scaleX:s,scaleY:r}=n.worldTransform;this.textScale=Math.max(Math.abs(s),Math.abs(r));const l=n.fontSize*this.textScale;l<12&&(this.textScale*=12/l),e.app.view.appendChild(o),this.eventIds=[e.app.on_(t.PointerEvent.DOWN,(t=>{t.origin.target!==o&&e.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),o.addEventListener("focus",this.onFocus),o.addEventListener("input",this.onInput),window.addEventListener("scroll",this.onUpdate);const a=window.getSelection(),d=document.createRange();d.selectNodeContents(o),a.removeAllRanges(),a.addRange(d)}onInput(){this.text.text=this.dom.innerText}onFocus(){this.dom.style.outline="none"}onUpdate(){const{text:e,textScale:n}=this,{style:o}=this.dom,{x:i,y:s}=e.app.tree.clientBounds,{a:r,b:a,c:d,d:c,e:p,f:h}=new t.Matrix(this.text.worldTransform).scale(1/n);o.transform=`matrix(${r},${a},${d},${c},${p},${h})`,o.left=i-window.scrollX+"px",o.top=s-window.scrollY+"px",o.width=e.width*n+(e.__.__autoWidth?20:0)+"px",o.height=e.height*n+(e.__.__autoHeight?20:0)+"px",l(this.dom,this.text,this.textScale)}onUnload(){const{text:t,editor:e,dom:n}=this;t&&(t.text=n.innerText,t.visible=!0,e.config.keyEvent=!0,e.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.text=this.dom=this.eventIds=void 0)}},exports.TextEditor=function(t,e,n,o){var i,s=arguments.length,r=s<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,o);else for(var l=t.length-1;l>=0;l--)(i=t[l])&&(r=(s<3?i(r):s>3?i(e,n,r):i(e,n))||r);return s>3&&r&&Object.defineProperty(e,n,r),r}([e.registerInnerEditor()],exports.TextEditor);
1
+ "use strict";var e=require("@leafer-ui/core"),t=require("@leafer-in/editor");"function"==typeof SuppressedError&&SuppressedError;const n={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},o={top:"flex-start",middle:"center",bottom:"flex-end"},i=e.inviteCode;function s(t,i,s){const{style:r}=t,{fill:a,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=i;r.fontFamily=i.fontFamily,r.fontSize=i.fontSize*s+"px",function(t,n){let o="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":o=e.ColorConvert.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const t=n.stops[0];o=e.ColorConvert.string("string"==typeof t?t:t.color);break;default:void 0!==n.r&&(o=e.ColorConvert.string(n))}else o=n;t.color=o}(r,a),r.fontStyle=i.italic?"italic":"normal",r.fontWeight=i.fontWeight,r.textDecoration="delete"===p?"line-through":p,r.textTransform=n[i.textCase],r.textAlign=i.textAlign,r.display="flex",r.flexDirection="column",r.justifyContent=o[i.verticalAlign],r.lineHeight=(i.__.__lineHeight||0)*s+"px",r.letterSpacing=(i.__.__letterSpacing||0)*s+"px","none"===c?r.whiteSpace="nowrap":"break"===c&&(r.wordBreak="break-all"),r.textIndent=(i.paraIndent||0)*s+"px",r.padding=l instanceof Array?l.map((e=>e*s+"px")).join(" "):(l||0)*s+"px",r.textOverflow="show"===d?"":"hide"===d?"clip":d}function r(e){return e.length>6&&"e"===e[6]}let a=s;setTimeout((function(){Object.values(i).some(r)||(a=()=>s)})),exports.TextEditor=class extends t.InnerEditor{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:t}=this,{config:n}=t.app;this._keyEvent=n.keyEvent,n.keyEvent=!1;const o=this.editTarget;o.visible=!1;const i=this.editDom=document.createElement("div"),{style:s}=i;i.contentEditable="true",i.innerText=o.text,s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box";const{scaleX:r,scaleY:a}=o.worldTransform;this.textScale=Math.max(Math.abs(r),Math.abs(a));const l=o.fontSize*this.textScale;l<12&&(this.textScale*=12/l),t.app.view.appendChild(i),this.eventIds=[t.app.on_(e.PointerEvent.DOWN,(e=>{e.origin.target!==i&&t.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),this.onEscape=this.onEscape.bind(this),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const c=window.getSelection(),d=document.createRange();if(this.config.selectAll)d.selectNodeContents(i);else{const e=i.childNodes[0];d.setStartAfter(e),d.setEndAfter(e),d.collapse(!0)}c.removeAllRanges(),c.addRange(d)}onInput(){this.editTarget.text=this.editDom.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:t,textScale:n}=this,{style:o}=this.editDom,{x:i,y:s}=t.app.tree.clientBounds,{a:r,b:l,c:c,d:d,e:p,f:h}=new e.Matrix(t.worldTransform).scale(1/n);o.transform=`matrix(${r},${l},${c},${d},${p},${h})`,o.left=i-window.scrollX+"px",o.top=s-window.scrollY+"px",o.width=t.width*n+(t.__.__autoWidth?20:0)+"px",o.height=t.height*n+(t.__.__autoHeight?20:0)+"px",a(this.editDom,t,this.textScale)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,t.app.config.keyEvent=this._keyEvent,t.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("keydown",this.onEscape),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.editDom=this.eventIds=void 0)}},exports.TextEditor=function(e,t,n,o){var i,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([t.registerInnerEditor()],exports.TextEditor);
@@ -1 +1 @@
1
- import{inviteCode as t,PointerEvent as e,Matrix as n}from"@leafer-ui/core";import{registerInnerEditor as o,InnerEditor as i}from"@leafer-in/editor";"function"==typeof SuppressedError&&SuppressedError;const s={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},r={top:"flex-start",middle:"center",bottom:"flex-end"},l=t;function a(t,e,n){const{style:o}=t;o.fontFamily=e.fontFamily,o.fontSize=e.fontSize*n+"px",o.color=e.fill,o.fontStyle=e.italic?"italic":"normal",o.fontWeight=e.fontWeight,o.textDecoration="delete"===e.textDecoration?"line-through":e.textDecoration,o.textTransform=s[e.textCase],o.textAlign=e.textAlign,o.display="flex",o.flexDirection="column",o.justifyContent=r[e.verticalAlign],o.lineHeight=(e.__.__lineHeight||0)*n+"px",o.letterSpacing=(e.__.__letterSpacing||0)*n+"px",o.textIndent=(e.paraIndent||0)*n+"px",o.padding=e.padding instanceof Array?e.padding.map((t=>t*n+"px")).join(" "):(e.padding||0)*n+"px",o.textOverflow="show"===e.textOverflow?"":"hide"===e.textOverflow?"clip":e.textOverflow}function c(t){return t.length>6&&"e"===t[6]}let d=a;setTimeout((function(){Object.values(l).some(c)||(d=()=>a)}));let p=class extends i{constructor(){super(...arguments),this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:t}=this;t.config.keyEvent=!1;const n=this.text=t.element;n.visible=!1;const o=this.dom=document.createElement("div"),{style:i}=o;o.contentEditable="true",o.innerText=n.text,i.position="fixed",i.transformOrigin="left top";const{scaleX:s,scaleY:r}=n.worldTransform;this.textScale=Math.max(Math.abs(s),Math.abs(r));const l=n.fontSize*this.textScale;l<12&&(this.textScale*=12/l),t.app.view.appendChild(o),this.eventIds=[t.app.on_(e.DOWN,(e=>{e.origin.target!==o&&t.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),o.addEventListener("focus",this.onFocus),o.addEventListener("input",this.onInput),window.addEventListener("scroll",this.onUpdate);const a=window.getSelection(),c=document.createRange();c.selectNodeContents(o),a.removeAllRanges(),a.addRange(c)}onInput(){this.text.text=this.dom.innerText}onFocus(){this.dom.style.outline="none"}onUpdate(){const{text:t,textScale:e}=this,{style:o}=this.dom,{x:i,y:s}=t.app.tree.clientBounds,{a:r,b:l,c:a,d:c,e:p,f:h}=new n(this.text.worldTransform).scale(1/e);o.transform=`matrix(${r},${l},${a},${c},${p},${h})`,o.left=i-window.scrollX+"px",o.top=s-window.scrollY+"px",o.width=t.width*e+(t.__.__autoWidth?20:0)+"px",o.height=t.height*e+(t.__.__autoHeight?20:0)+"px",d(this.dom,this.text,this.textScale)}onUnload(){const{text:t,editor:e,dom:n}=this;t&&(t.text=n.innerText,t.visible=!0,e.config.keyEvent=!0,e.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.text=this.dom=this.eventIds=void 0)}};p=function(t,e,n,o){var i,s=arguments.length,r=s<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,o);else for(var l=t.length-1;l>=0;l--)(i=t[l])&&(r=(s<3?i(r):s>3?i(e,n,r):i(e,n))||r);return s>3&&r&&Object.defineProperty(e,n,r),r}([o()],p);export{p as TextEditor};
1
+ import{inviteCode as e,ColorConvert as t,PointerEvent as n,Matrix as o}from"@leafer-ui/core";import{registerInnerEditor as i,InnerEditor as s}from"@leafer-in/editor";"function"==typeof SuppressedError&&SuppressedError;const r={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},a={top:"flex-start",middle:"center",bottom:"flex-end"},l=e;function c(e,n,o){const{style:i}=e,{fill:s,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=n;i.fontFamily=n.fontFamily,i.fontSize=n.fontSize*o+"px",function(e,n){let o="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":o=t.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const e=n.stops[0];o=t.string("string"==typeof e?e:e.color);break;default:void 0!==n.r&&(o=t.string(n))}else o=n;e.color=o}(i,s),i.fontStyle=n.italic?"italic":"normal",i.fontWeight=n.fontWeight,i.textDecoration="delete"===p?"line-through":p,i.textTransform=r[n.textCase],i.textAlign=n.textAlign,i.display="flex",i.flexDirection="column",i.justifyContent=a[n.verticalAlign],i.lineHeight=(n.__.__lineHeight||0)*o+"px",i.letterSpacing=(n.__.__letterSpacing||0)*o+"px","none"===c?i.whiteSpace="nowrap":"break"===c&&(i.wordBreak="break-all"),i.textIndent=(n.paraIndent||0)*o+"px",i.padding=l instanceof Array?l.map((e=>e*o+"px")).join(" "):(l||0)*o+"px",i.textOverflow="show"===d?"":"hide"===d?"clip":d}function d(e){return e.length>6&&"e"===e[6]}let p=c;setTimeout((function(){Object.values(l).some(d)||(p=()=>c)}));let h=class extends s{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:e}=this,{config:t}=e.app;this._keyEvent=t.keyEvent,t.keyEvent=!1;const o=this.editTarget;o.visible=!1;const i=this.editDom=document.createElement("div"),{style:s}=i;i.contentEditable="true",i.innerText=o.text,s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box";const{scaleX:r,scaleY:a}=o.worldTransform;this.textScale=Math.max(Math.abs(r),Math.abs(a));const l=o.fontSize*this.textScale;l<12&&(this.textScale*=12/l),e.app.view.appendChild(i),this.eventIds=[e.app.on_(n.DOWN,(t=>{t.origin.target!==i&&e.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),this.onEscape=this.onEscape.bind(this),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const c=window.getSelection(),d=document.createRange();if(this.config.selectAll)d.selectNodeContents(i);else{const e=i.childNodes[0];d.setStartAfter(e),d.setEndAfter(e),d.collapse(!0)}c.removeAllRanges(),c.addRange(d)}onInput(){this.editTarget.text=this.editDom.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:e,textScale:t}=this,{style:n}=this.editDom,{x:i,y:s}=e.app.tree.clientBounds,{a:r,b:a,c:l,d:c,e:d,f:h}=new o(e.worldTransform).scale(1/t);n.transform=`matrix(${r},${a},${l},${c},${d},${h})`,n.left=i-window.scrollX+"px",n.top=s-window.scrollY+"px",n.width=e.width*t+(e.__.__autoWidth?20:0)+"px",n.height=e.height*t+(e.__.__autoHeight?20:0)+"px",p(this.editDom,e,this.textScale)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,t.app.config.keyEvent=this._keyEvent,t.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("keydown",this.onEscape),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.editDom=this.eventIds=void 0)}};h=function(e,t,n,o){var i,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([i()],h);export{h as TextEditor};
@@ -1 +1 @@
1
- import{inviteCode as t,PointerEvent as e,Matrix as n}from"@leafer-ui/core";import{registerInnerEditor as o,InnerEditor as i}from"@leafer-in/editor";"function"==typeof SuppressedError&&SuppressedError;const s={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},r={top:"flex-start",middle:"center",bottom:"flex-end"},l=t;function a(t,e,n){const{style:o}=t;o.fontFamily=e.fontFamily,o.fontSize=e.fontSize*n+"px",o.color=e.fill,o.fontStyle=e.italic?"italic":"normal",o.fontWeight=e.fontWeight,o.textDecoration="delete"===e.textDecoration?"line-through":e.textDecoration,o.textTransform=s[e.textCase],o.textAlign=e.textAlign,o.display="flex",o.flexDirection="column",o.justifyContent=r[e.verticalAlign],o.lineHeight=(e.__.__lineHeight||0)*n+"px",o.letterSpacing=(e.__.__letterSpacing||0)*n+"px",o.textIndent=(e.paraIndent||0)*n+"px",o.padding=e.padding instanceof Array?e.padding.map((t=>t*n+"px")).join(" "):(e.padding||0)*n+"px",o.textOverflow="show"===e.textOverflow?"":"hide"===e.textOverflow?"clip":e.textOverflow}function c(t){return t.length>6&&"e"===t[6]}let d=a;setTimeout((function(){Object.values(l).some(c)||(d=()=>a)}));let p=class extends i{constructor(){super(...arguments),this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:t}=this;t.config.keyEvent=!1;const n=this.text=t.element;n.visible=!1;const o=this.dom=document.createElement("div"),{style:i}=o;o.contentEditable="true",o.innerText=n.text,i.position="fixed",i.transformOrigin="left top";const{scaleX:s,scaleY:r}=n.worldTransform;this.textScale=Math.max(Math.abs(s),Math.abs(r));const l=n.fontSize*this.textScale;l<12&&(this.textScale*=12/l),t.app.view.appendChild(o),this.eventIds=[t.app.on_(e.DOWN,(e=>{e.origin.target!==o&&t.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),o.addEventListener("focus",this.onFocus),o.addEventListener("input",this.onInput),window.addEventListener("scroll",this.onUpdate);const a=window.getSelection(),c=document.createRange();c.selectNodeContents(o),a.removeAllRanges(),a.addRange(c)}onInput(){this.text.text=this.dom.innerText}onFocus(){this.dom.style.outline="none"}onUpdate(){const{text:t,textScale:e}=this,{style:o}=this.dom,{x:i,y:s}=t.app.tree.clientBounds,{a:r,b:l,c:a,d:c,e:p,f:h}=new n(this.text.worldTransform).scale(1/e);o.transform=`matrix(${r},${l},${a},${c},${p},${h})`,o.left=i-window.scrollX+"px",o.top=s-window.scrollY+"px",o.width=t.width*e+(t.__.__autoWidth?20:0)+"px",o.height=t.height*e+(t.__.__autoHeight?20:0)+"px",d(this.dom,this.text,this.textScale)}onUnload(){const{text:t,editor:e,dom:n}=this;t&&(t.text=n.innerText,t.visible=!0,e.config.keyEvent=!0,e.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.text=this.dom=this.eventIds=void 0)}};p=function(t,e,n,o){var i,s=arguments.length,r=s<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,o);else for(var l=t.length-1;l>=0;l--)(i=t[l])&&(r=(s<3?i(r):s>3?i(e,n,r):i(e,n))||r);return s>3&&r&&Object.defineProperty(e,n,r),r}([o()],p);export{p as TextEditor};
1
+ import{inviteCode as e,ColorConvert as t,PointerEvent as n,Matrix as o}from"@leafer-ui/core";import{registerInnerEditor as i,InnerEditor as s}from"@leafer-in/editor";"function"==typeof SuppressedError&&SuppressedError;const r={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},a={top:"flex-start",middle:"center",bottom:"flex-end"},l=e;function c(e,n,o){const{style:i}=e,{fill:s,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=n;i.fontFamily=n.fontFamily,i.fontSize=n.fontSize*o+"px",function(e,n){let o="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":o=t.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const e=n.stops[0];o=t.string("string"==typeof e?e:e.color);break;default:void 0!==n.r&&(o=t.string(n))}else o=n;e.color=o}(i,s),i.fontStyle=n.italic?"italic":"normal",i.fontWeight=n.fontWeight,i.textDecoration="delete"===p?"line-through":p,i.textTransform=r[n.textCase],i.textAlign=n.textAlign,i.display="flex",i.flexDirection="column",i.justifyContent=a[n.verticalAlign],i.lineHeight=(n.__.__lineHeight||0)*o+"px",i.letterSpacing=(n.__.__letterSpacing||0)*o+"px","none"===c?i.whiteSpace="nowrap":"break"===c&&(i.wordBreak="break-all"),i.textIndent=(n.paraIndent||0)*o+"px",i.padding=l instanceof Array?l.map((e=>e*o+"px")).join(" "):(l||0)*o+"px",i.textOverflow="show"===d?"":"hide"===d?"clip":d}function d(e){return e.length>6&&"e"===e[6]}let p=c;setTimeout((function(){Object.values(l).some(d)||(p=()=>c)}));let h=class extends s{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:e}=this,{config:t}=e.app;this._keyEvent=t.keyEvent,t.keyEvent=!1;const o=this.editTarget;o.visible=!1;const i=this.editDom=document.createElement("div"),{style:s}=i;i.contentEditable="true",i.innerText=o.text,s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box";const{scaleX:r,scaleY:a}=o.worldTransform;this.textScale=Math.max(Math.abs(r),Math.abs(a));const l=o.fontSize*this.textScale;l<12&&(this.textScale*=12/l),e.app.view.appendChild(i),this.eventIds=[e.app.on_(n.DOWN,(t=>{t.origin.target!==i&&e.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),this.onEscape=this.onEscape.bind(this),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const c=window.getSelection(),d=document.createRange();if(this.config.selectAll)d.selectNodeContents(i);else{const e=i.childNodes[0];d.setStartAfter(e),d.setEndAfter(e),d.collapse(!0)}c.removeAllRanges(),c.addRange(d)}onInput(){this.editTarget.text=this.editDom.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:e,textScale:t}=this,{style:n}=this.editDom,{x:i,y:s}=e.app.tree.clientBounds,{a:r,b:a,c:l,d:c,e:d,f:h}=new o(e.worldTransform).scale(1/t);n.transform=`matrix(${r},${a},${l},${c},${d},${h})`,n.left=i-window.scrollX+"px",n.top=s-window.scrollY+"px",n.width=e.width*t+(e.__.__autoWidth?20:0)+"px",n.height=e.height*t+(e.__.__autoHeight?20:0)+"px",p(this.editDom,e,this.textScale)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,t.app.config.keyEvent=this._keyEvent,t.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("keydown",this.onEscape),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.editDom=this.eventIds=void 0)}};h=function(e,t,n,o){var i,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([i()],h);export{h as TextEditor};
@@ -1 +1 @@
1
- this.LeaferIN=this.LeaferIN||{},this.LeaferIN.textEditor=function(t,e,n){"use strict";"function"==typeof SuppressedError&&SuppressedError;const i={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},o={top:"flex-start",middle:"center",bottom:"flex-end"},s=e.inviteCode;function r(t,e,n){const{style:s}=t;s.fontFamily=e.fontFamily,s.fontSize=e.fontSize*n+"px",s.color=e.fill,s.fontStyle=e.italic?"italic":"normal",s.fontWeight=e.fontWeight,s.textDecoration="delete"===e.textDecoration?"line-through":e.textDecoration,s.textTransform=i[e.textCase],s.textAlign=e.textAlign,s.display="flex",s.flexDirection="column",s.justifyContent=o[e.verticalAlign],s.lineHeight=(e.__.__lineHeight||0)*n+"px",s.letterSpacing=(e.__.__letterSpacing||0)*n+"px",s.textIndent=(e.paraIndent||0)*n+"px",s.padding=e.padding instanceof Array?e.padding.map((t=>t*n+"px")).join(" "):(e.padding||0)*n+"px",s.textOverflow="show"===e.textOverflow?"":"hide"===e.textOverflow?"clip":e.textOverflow}function a(t){return t.length>6&&"e"===t[6]}let l=r;return setTimeout((function(){Object.values(s).some(a)||(l=()=>r)})),t.TextEditor=class extends n.InnerEditor{constructor(){super(...arguments),this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:t}=this;t.config.keyEvent=!1;const n=this.text=t.element;n.visible=!1;const i=this.dom=document.createElement("div"),{style:o}=i;i.contentEditable="true",i.innerText=n.text,o.position="fixed",o.transformOrigin="left top";const{scaleX:s,scaleY:r}=n.worldTransform;this.textScale=Math.max(Math.abs(s),Math.abs(r));const a=n.fontSize*this.textScale;a<12&&(this.textScale*=12/a),t.app.view.appendChild(i),this.eventIds=[t.app.on_(e.PointerEvent.DOWN,(e=>{e.origin.target!==i&&t.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("scroll",this.onUpdate);const l=window.getSelection(),d=document.createRange();d.selectNodeContents(i),l.removeAllRanges(),l.addRange(d)}onInput(){this.text.text=this.dom.innerText}onFocus(){this.dom.style.outline="none"}onUpdate(){const{text:t,textScale:n}=this,{style:i}=this.dom,{x:o,y:s}=t.app.tree.clientBounds,{a:r,b:a,c:d,d:c,e:h,f:p}=new e.Matrix(this.text.worldTransform).scale(1/n);i.transform=`matrix(${r},${a},${d},${c},${h},${p})`,i.left=o-window.scrollX+"px",i.top=s-window.scrollY+"px",i.width=t.width*n+(t.__.__autoWidth?20:0)+"px",i.height=t.height*n+(t.__.__autoHeight?20:0)+"px",l(this.dom,this.text,this.textScale)}onUnload(){const{text:t,editor:e,dom:n}=this;t&&(t.text=n.innerText,t.visible=!0,e.config.keyEvent=!0,e.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.text=this.dom=this.eventIds=void 0)}},t.TextEditor=function(t,e,n,i){var o,s=arguments.length,r=s<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(s<3?o(r):s>3?o(e,n,r):o(e,n))||r);return s>3&&r&&Object.defineProperty(e,n,r),r}([n.registerInnerEditor()],t.TextEditor),t}({},LeaferUI,LeaferIN.editor);
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.textEditor=function(e,t,n){"use strict";"function"==typeof SuppressedError&&SuppressedError;const o={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},i={top:"flex-start",middle:"center",bottom:"flex-end"},s=t.inviteCode;function r(e,n,s){const{style:r}=e,{fill:a,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=n;r.fontFamily=n.fontFamily,r.fontSize=n.fontSize*s+"px",function(e,n){let o="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":o=t.ColorConvert.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const e=n.stops[0];o=t.ColorConvert.string("string"==typeof e?e:e.color);break;default:void 0!==n.r&&(o=t.ColorConvert.string(n))}else o=n;e.color=o}(r,a),r.fontStyle=n.italic?"italic":"normal",r.fontWeight=n.fontWeight,r.textDecoration="delete"===p?"line-through":p,r.textTransform=o[n.textCase],r.textAlign=n.textAlign,r.display="flex",r.flexDirection="column",r.justifyContent=i[n.verticalAlign],r.lineHeight=(n.__.__lineHeight||0)*s+"px",r.letterSpacing=(n.__.__letterSpacing||0)*s+"px","none"===c?r.whiteSpace="nowrap":"break"===c&&(r.wordBreak="break-all"),r.textIndent=(n.paraIndent||0)*s+"px",r.padding=l instanceof Array?l.map((e=>e*s+"px")).join(" "):(l||0)*s+"px",r.textOverflow="show"===d?"":"hide"===d?"clip":d}function a(e){return e.length>6&&"e"===e[6]}let l=r;return setTimeout((function(){Object.values(s).some(a)||(l=()=>r)})),e.TextEditor=class extends n.InnerEditor{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:e}=this,{config:n}=e.app;this._keyEvent=n.keyEvent,n.keyEvent=!1;const o=this.editTarget;o.visible=!1;const i=this.editDom=document.createElement("div"),{style:s}=i;i.contentEditable="true",i.innerText=o.text,s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box";const{scaleX:r,scaleY:a}=o.worldTransform;this.textScale=Math.max(Math.abs(r),Math.abs(a));const l=o.fontSize*this.textScale;l<12&&(this.textScale*=12/l),e.app.view.appendChild(i),this.eventIds=[e.app.on_(t.PointerEvent.DOWN,(t=>{t.origin.target!==i&&e.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),this.onEscape=this.onEscape.bind(this),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const c=window.getSelection(),d=document.createRange();if(this.config.selectAll)d.selectNodeContents(i);else{const e=i.childNodes[0];d.setStartAfter(e),d.setEndAfter(e),d.collapse(!0)}c.removeAllRanges(),c.addRange(d)}onInput(){this.editTarget.text=this.editDom.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:e,textScale:n}=this,{style:o}=this.editDom,{x:i,y:s}=e.app.tree.clientBounds,{a:r,b:a,c:c,d:d,e:p,f:h}=new t.Matrix(e.worldTransform).scale(1/n);o.transform=`matrix(${r},${a},${c},${d},${p},${h})`,o.left=i-window.scrollX+"px",o.top=s-window.scrollY+"px",o.width=e.width*n+(e.__.__autoWidth?20:0)+"px",o.height=e.height*n+(e.__.__autoHeight?20:0)+"px",l(this.editDom,e,this.textScale)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,t.app.config.keyEvent=this._keyEvent,t.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("keydown",this.onEscape),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.editDom=this.eventIds=void 0)}},e.TextEditor=function(e,t,n,o){var i,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([n.registerInnerEditor()],e.TextEditor),e}({},LeaferUI,LeaferIN.editor);
@@ -1 +1 @@
1
- "use strict";var t=require("@leafer-ui/core"),e=require("@leafer-in/editor");"function"==typeof SuppressedError&&SuppressedError;const n={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},o={top:"flex-start",middle:"center",bottom:"flex-end"},i=t.inviteCode;function s(t,e,i){const{style:s}=t;s.fontFamily=e.fontFamily,s.fontSize=e.fontSize*i+"px",s.color=e.fill,s.fontStyle=e.italic?"italic":"normal",s.fontWeight=e.fontWeight,s.textDecoration="delete"===e.textDecoration?"line-through":e.textDecoration,s.textTransform=n[e.textCase],s.textAlign=e.textAlign,s.display="flex",s.flexDirection="column",s.justifyContent=o[e.verticalAlign],s.lineHeight=(e.__.__lineHeight||0)*i+"px",s.letterSpacing=(e.__.__letterSpacing||0)*i+"px",s.textIndent=(e.paraIndent||0)*i+"px",s.padding=e.padding instanceof Array?e.padding.map((t=>t*i+"px")).join(" "):(e.padding||0)*i+"px",s.textOverflow="show"===e.textOverflow?"":"hide"===e.textOverflow?"clip":e.textOverflow}function r(t){return t.length>6&&"e"===t[6]}let l=s;setTimeout((function(){Object.values(i).some(r)||(l=()=>s)})),exports.TextEditor=class extends e.InnerEditor{constructor(){super(...arguments),this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:e}=this;e.config.keyEvent=!1;const n=this.text=e.element;n.visible=!1;const o=this.dom=document.createElement("div"),{style:i}=o;o.contentEditable="true",o.innerText=n.text,i.position="fixed",i.transformOrigin="left top";const{scaleX:s,scaleY:r}=n.worldTransform;this.textScale=Math.max(Math.abs(s),Math.abs(r));const l=n.fontSize*this.textScale;l<12&&(this.textScale*=12/l),e.app.view.appendChild(o),this.eventIds=[e.app.on_(t.PointerEvent.DOWN,(t=>{t.origin.target!==o&&e.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),o.addEventListener("focus",this.onFocus),o.addEventListener("input",this.onInput),window.addEventListener("scroll",this.onUpdate);const a=window.getSelection(),d=document.createRange();d.selectNodeContents(o),a.removeAllRanges(),a.addRange(d)}onInput(){this.text.text=this.dom.innerText}onFocus(){this.dom.style.outline="none"}onUpdate(){const{text:e,textScale:n}=this,{style:o}=this.dom,{x:i,y:s}=e.app.tree.clientBounds,{a:r,b:a,c:d,d:c,e:p,f:h}=new t.Matrix(this.text.worldTransform).scale(1/n);o.transform=`matrix(${r},${a},${d},${c},${p},${h})`,o.left=i-window.scrollX+"px",o.top=s-window.scrollY+"px",o.width=e.width*n+(e.__.__autoWidth?20:0)+"px",o.height=e.height*n+(e.__.__autoHeight?20:0)+"px",l(this.dom,this.text,this.textScale)}onUnload(){const{text:t,editor:e,dom:n}=this;t&&(t.text=n.innerText,t.visible=!0,e.config.keyEvent=!0,e.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.text=this.dom=this.eventIds=void 0)}},exports.TextEditor=function(t,e,n,o){var i,s=arguments.length,r=s<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,o);else for(var l=t.length-1;l>=0;l--)(i=t[l])&&(r=(s<3?i(r):s>3?i(e,n,r):i(e,n))||r);return s>3&&r&&Object.defineProperty(e,n,r),r}([e.registerInnerEditor()],exports.TextEditor);
1
+ "use strict";var e=require("@leafer-ui/core"),t=require("@leafer-in/editor");"function"==typeof SuppressedError&&SuppressedError;const n={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},o={top:"flex-start",middle:"center",bottom:"flex-end"},i=e.inviteCode;function s(t,i,s){const{style:r}=t,{fill:a,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=i;r.fontFamily=i.fontFamily,r.fontSize=i.fontSize*s+"px",function(t,n){let o="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":o=e.ColorConvert.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const t=n.stops[0];o=e.ColorConvert.string("string"==typeof t?t:t.color);break;default:void 0!==n.r&&(o=e.ColorConvert.string(n))}else o=n;t.color=o}(r,a),r.fontStyle=i.italic?"italic":"normal",r.fontWeight=i.fontWeight,r.textDecoration="delete"===p?"line-through":p,r.textTransform=n[i.textCase],r.textAlign=i.textAlign,r.display="flex",r.flexDirection="column",r.justifyContent=o[i.verticalAlign],r.lineHeight=(i.__.__lineHeight||0)*s+"px",r.letterSpacing=(i.__.__letterSpacing||0)*s+"px","none"===c?r.whiteSpace="nowrap":"break"===c&&(r.wordBreak="break-all"),r.textIndent=(i.paraIndent||0)*s+"px",r.padding=l instanceof Array?l.map((e=>e*s+"px")).join(" "):(l||0)*s+"px",r.textOverflow="show"===d?"":"hide"===d?"clip":d}function r(e){return e.length>6&&"e"===e[6]}let a=s;setTimeout((function(){Object.values(i).some(r)||(a=()=>s)})),exports.TextEditor=class extends t.InnerEditor{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:t}=this,{config:n}=t.app;this._keyEvent=n.keyEvent,n.keyEvent=!1;const o=this.editTarget;o.visible=!1;const i=this.editDom=document.createElement("div"),{style:s}=i;i.contentEditable="true",i.innerText=o.text,s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box";const{scaleX:r,scaleY:a}=o.worldTransform;this.textScale=Math.max(Math.abs(r),Math.abs(a));const l=o.fontSize*this.textScale;l<12&&(this.textScale*=12/l),t.app.view.appendChild(i),this.eventIds=[t.app.on_(e.PointerEvent.DOWN,(e=>{e.origin.target!==i&&t.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),this.onEscape=this.onEscape.bind(this),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const c=window.getSelection(),d=document.createRange();if(this.config.selectAll)d.selectNodeContents(i);else{const e=i.childNodes[0];d.setStartAfter(e),d.setEndAfter(e),d.collapse(!0)}c.removeAllRanges(),c.addRange(d)}onInput(){this.editTarget.text=this.editDom.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:t,textScale:n}=this,{style:o}=this.editDom,{x:i,y:s}=t.app.tree.clientBounds,{a:r,b:l,c:c,d:d,e:p,f:h}=new e.Matrix(t.worldTransform).scale(1/n);o.transform=`matrix(${r},${l},${c},${d},${p},${h})`,o.left=i-window.scrollX+"px",o.top=s-window.scrollY+"px",o.width=t.width*n+(t.__.__autoWidth?20:0)+"px",o.height=t.height*n+(t.__.__autoHeight?20:0)+"px",a(this.editDom,t,this.textScale)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,t.app.config.keyEvent=this._keyEvent,t.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("keydown",this.onEscape),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.editDom=this.eventIds=void 0)}},exports.TextEditor=function(e,t,n,o){var i,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([t.registerInnerEditor()],exports.TextEditor);
@@ -1 +1 @@
1
- this.LeaferIN=this.LeaferIN||{},this.LeaferIN.textEditor=function(t,e,n){"use strict";"function"==typeof SuppressedError&&SuppressedError;const i={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},o={top:"flex-start",middle:"center",bottom:"flex-end"},s=e.inviteCode;function r(t,e,n){const{style:s}=t;s.fontFamily=e.fontFamily,s.fontSize=e.fontSize*n+"px",s.color=e.fill,s.fontStyle=e.italic?"italic":"normal",s.fontWeight=e.fontWeight,s.textDecoration="delete"===e.textDecoration?"line-through":e.textDecoration,s.textTransform=i[e.textCase],s.textAlign=e.textAlign,s.display="flex",s.flexDirection="column",s.justifyContent=o[e.verticalAlign],s.lineHeight=(e.__.__lineHeight||0)*n+"px",s.letterSpacing=(e.__.__letterSpacing||0)*n+"px",s.textIndent=(e.paraIndent||0)*n+"px",s.padding=e.padding instanceof Array?e.padding.map((t=>t*n+"px")).join(" "):(e.padding||0)*n+"px",s.textOverflow="show"===e.textOverflow?"":"hide"===e.textOverflow?"clip":e.textOverflow}function a(t){return t.length>6&&"e"===t[6]}let l=r;return setTimeout((function(){Object.values(s).some(a)||(l=()=>r)})),t.TextEditor=class extends n.InnerEditor{constructor(){super(...arguments),this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:t}=this;t.config.keyEvent=!1;const n=this.text=t.element;n.visible=!1;const i=this.dom=document.createElement("div"),{style:o}=i;i.contentEditable="true",i.innerText=n.text,o.position="fixed",o.transformOrigin="left top";const{scaleX:s,scaleY:r}=n.worldTransform;this.textScale=Math.max(Math.abs(s),Math.abs(r));const a=n.fontSize*this.textScale;a<12&&(this.textScale*=12/a),t.app.view.appendChild(i),this.eventIds=[t.app.on_(e.PointerEvent.DOWN,(e=>{e.origin.target!==i&&t.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("scroll",this.onUpdate);const l=window.getSelection(),d=document.createRange();d.selectNodeContents(i),l.removeAllRanges(),l.addRange(d)}onInput(){this.text.text=this.dom.innerText}onFocus(){this.dom.style.outline="none"}onUpdate(){const{text:t,textScale:n}=this,{style:i}=this.dom,{x:o,y:s}=t.app.tree.clientBounds,{a:r,b:a,c:d,d:c,e:h,f:p}=new e.Matrix(this.text.worldTransform).scale(1/n);i.transform=`matrix(${r},${a},${d},${c},${h},${p})`,i.left=o-window.scrollX+"px",i.top=s-window.scrollY+"px",i.width=t.width*n+(t.__.__autoWidth?20:0)+"px",i.height=t.height*n+(t.__.__autoHeight?20:0)+"px",l(this.dom,this.text,this.textScale)}onUnload(){const{text:t,editor:e,dom:n}=this;t&&(t.text=n.innerText,t.visible=!0,e.config.keyEvent=!0,e.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.text=this.dom=this.eventIds=void 0)}},t.TextEditor=function(t,e,n,i){var o,s=arguments.length,r=s<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(s<3?o(r):s>3?o(e,n,r):o(e,n))||r);return s>3&&r&&Object.defineProperty(e,n,r),r}([n.registerInnerEditor()],t.TextEditor),t}({},LeaferUI,LeaferIN.editor);
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.textEditor=function(e,t,n){"use strict";"function"==typeof SuppressedError&&SuppressedError;const o={none:"none",title:"capitalize",upper:"uppercase",lower:"lowercase","small-caps":"small-caps"},i={top:"flex-start",middle:"center",bottom:"flex-end"},s=t.inviteCode;function r(e,n,s){const{style:r}=e,{fill:a,padding:l,textWrap:c,textOverflow:d,textDecoration:p}=n;r.fontFamily=n.fontFamily,r.fontSize=n.fontSize*s+"px",function(e,n){let o="black";n instanceof Array&&(n=n[0]);if("object"==typeof n)switch(n.type){case"solid":o=t.ColorConvert.string(n.color);break;case"image":break;case"linear":case"radial":case"angular":const e=n.stops[0];o=t.ColorConvert.string("string"==typeof e?e:e.color);break;default:void 0!==n.r&&(o=t.ColorConvert.string(n))}else o=n;e.color=o}(r,a),r.fontStyle=n.italic?"italic":"normal",r.fontWeight=n.fontWeight,r.textDecoration="delete"===p?"line-through":p,r.textTransform=o[n.textCase],r.textAlign=n.textAlign,r.display="flex",r.flexDirection="column",r.justifyContent=i[n.verticalAlign],r.lineHeight=(n.__.__lineHeight||0)*s+"px",r.letterSpacing=(n.__.__letterSpacing||0)*s+"px","none"===c?r.whiteSpace="nowrap":"break"===c&&(r.wordBreak="break-all"),r.textIndent=(n.paraIndent||0)*s+"px",r.padding=l instanceof Array?l.map((e=>e*s+"px")).join(" "):(l||0)*s+"px",r.textOverflow="show"===d?"":"hide"===d?"clip":d}function a(e){return e.length>6&&"e"===e[6]}let l=r;return setTimeout((function(){Object.values(s).some(a)||(l=()=>r)})),e.TextEditor=class extends n.InnerEditor{constructor(){super(...arguments),this.config={selectAll:!0},this.eventIds=[]}get tag(){return"TextEditor"}onLoad(){const{editor:e}=this,{config:n}=e.app;this._keyEvent=n.keyEvent,n.keyEvent=!1;const o=this.editTarget;o.visible=!1;const i=this.editDom=document.createElement("div"),{style:s}=i;i.contentEditable="true",i.innerText=o.text,s.position="fixed",s.transformOrigin="left top",s.boxSizing="border-box";const{scaleX:r,scaleY:a}=o.worldTransform;this.textScale=Math.max(Math.abs(r),Math.abs(a));const l=o.fontSize*this.textScale;l<12&&(this.textScale*=12/l),e.app.view.appendChild(i),this.eventIds=[e.app.on_(t.PointerEvent.DOWN,(t=>{t.origin.target!==i&&e.closeInnerEditor()}))],this.onFocus=this.onFocus.bind(this),this.onInput=this.onInput.bind(this),this.onUpdate=this.onUpdate.bind(this),this.onEscape=this.onEscape.bind(this),i.addEventListener("focus",this.onFocus),i.addEventListener("input",this.onInput),window.addEventListener("keydown",this.onEscape),window.addEventListener("scroll",this.onUpdate);const c=window.getSelection(),d=document.createRange();if(this.config.selectAll)d.selectNodeContents(i);else{const e=i.childNodes[0];d.setStartAfter(e),d.setEndAfter(e),d.collapse(!0)}c.removeAllRanges(),c.addRange(d)}onInput(){this.editTarget.text=this.editDom.innerText.replace(/\n\n/,"\n")}onFocus(){this.editDom.style.outline="none"}onEscape(e){"Escape"===e.code&&this.editor.closeInnerEditor()}onUpdate(){const{editTarget:e,textScale:n}=this,{style:o}=this.editDom,{x:i,y:s}=e.app.tree.clientBounds,{a:r,b:a,c:c,d:d,e:p,f:h}=new t.Matrix(e.worldTransform).scale(1/n);o.transform=`matrix(${r},${a},${c},${d},${p},${h})`,o.left=i-window.scrollX+"px",o.top=s-window.scrollY+"px",o.width=e.width*n+(e.__.__autoWidth?20:0)+"px",o.height=e.height*n+(e.__.__autoHeight?20:0)+"px",l(this.editDom,e,this.textScale)}onUnload(){const{editTarget:e,editor:t,editDom:n}=this;e&&(this.onInput(),e.visible=!0,t.app.config.keyEvent=this._keyEvent,t.off_(this.eventIds),n.removeEventListener("focus",this.onFocus),n.removeEventListener("input",this.onInput),window.removeEventListener("keydown",this.onEscape),window.removeEventListener("scroll",this.onUpdate),n.remove(),this.editDom=this.eventIds=void 0)}},e.TextEditor=function(e,t,n,o){var i,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}([n.registerInnerEditor()],e.TextEditor),e}({},LeaferUI,LeaferIN.editor);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/text-editor",
3
- "version": "1.0.0-rc.25",
3
+ "version": "1.0.0-rc.26",
4
4
  "description": "@leafer-in/text-editor",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -24,9 +24,9 @@
24
24
  "leaferjs"
25
25
  ],
26
26
  "dependencies": {
27
- "@leafer-ui/core": "1.0.0-rc.25",
28
- "@leafer-in/editor": "1.0.0-rc.25",
29
- "@leafer-ui/interface": "1.0.0-rc.25",
30
- "@leafer-in/interface": "1.0.0-rc.25"
27
+ "@leafer-ui/core": "1.0.0-rc.26",
28
+ "@leafer-in/editor": "1.0.0-rc.26",
29
+ "@leafer-ui/interface": "1.0.0-rc.26",
30
+ "@leafer-in/interface": "1.0.0-rc.26"
31
31
  }
32
32
  }
package/types/index.d.ts CHANGED
@@ -3,13 +3,18 @@ import { InnerEditor } from '@leafer-in/editor';
3
3
 
4
4
  declare class TextEditor extends InnerEditor {
5
5
  get tag(): string;
6
- dom: HTMLDivElement;
7
- text: IText;
6
+ editTarget: IText;
7
+ editDom: HTMLDivElement;
8
8
  textScale: number;
9
+ config: {
10
+ selectAll: boolean;
11
+ };
9
12
  eventIds: IEventListenerId[];
13
+ protected _keyEvent: boolean;
10
14
  onLoad(): void;
11
15
  protected onInput(): void;
12
16
  protected onFocus(): void;
17
+ protected onEscape(e: KeyboardEvent): void;
13
18
  onUpdate(): void;
14
19
  onUnload(): void;
15
20
  }