@leafer-in/text-editor 1.0.0-rc.24

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023-present, Chao (Leafer) Wan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @leafer-in/text-editor
@@ -0,0 +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);
@@ -0,0 +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};
@@ -0,0 +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};
@@ -0,0 +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);
@@ -0,0 +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);
@@ -0,0 +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);
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@leafer-in/text-editor",
3
+ "version": "1.0.0-rc.24",
4
+ "description": "@leafer-in/text-editor",
5
+ "author": "Chao (Leafer) Wan",
6
+ "license": "MIT",
7
+ "main": "dist/text-editor.esm.js",
8
+ "unpkg": "dist/text-editor.js",
9
+ "jsdelivr": "dist/text-editor.js",
10
+ "types": "types/index.d.ts",
11
+ "files": ["types","dist"],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/leaferjs/in.git"
15
+ },
16
+ "homepage": "https://github.com/leaferjs/in/tree/main/packages/text-editor",
17
+ "bugs": "https://github.com/leaferjs/in/issues",
18
+ "keywords": [
19
+ "leafer text-editor",
20
+ "leafer-text-editor",
21
+ "leafer-in",
22
+ "text-editor",
23
+ "leafer-ui",
24
+ "leaferjs"
25
+ ],
26
+ "dependencies": {
27
+ "@leafer-ui/core": "1.0.0-rc.24",
28
+ "@leafer-in/editor": "1.0.0-rc.24",
29
+ "@leafer-ui/interface": "1.0.0-rc.24",
30
+ "@leafer-in/interface": "1.0.0-rc.24"
31
+ }
32
+ }
@@ -0,0 +1,17 @@
1
+ import { IText, IEventListenerId } from '@leafer-in/interface';
2
+ import { InnerEditor } from '@leafer-in/editor';
3
+
4
+ declare class TextEditor extends InnerEditor {
5
+ get tag(): string;
6
+ dom: HTMLDivElement;
7
+ text: IText;
8
+ textScale: number;
9
+ eventIds: IEventListenerId[];
10
+ onLoad(): void;
11
+ protected onInput(): void;
12
+ protected onFocus(): void;
13
+ onUpdate(): void;
14
+ onUnload(): void;
15
+ }
16
+
17
+ export { TextEditor };