@leafer-in/html 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/html.cjs CHANGED
@@ -40,11 +40,13 @@ class HTMLTextData extends draw.ImageData {
40
40
 
41
41
  exports.HTMLText = class HTMLText extends draw.Image {
42
42
  get __tag() { return 'HTMLText'; }
43
+ get editInner() { return 'TextEditor'; }
43
44
  constructor(data) {
44
45
  super(data);
45
46
  }
46
47
  __updateBoxBounds() {
47
- if (this.__.__htmlChanged) {
48
+ const data = this.__;
49
+ if (data.__htmlChanged) {
48
50
  const div = document.createElement('div');
49
51
  const { style } = div;
50
52
  style.all = 'initial';
@@ -53,9 +55,9 @@ exports.HTMLText = class HTMLText extends draw.Image {
53
55
  div.innerHTML = this.text;
54
56
  document.body.appendChild(div);
55
57
  const { width, height } = div.getBoundingClientRect();
56
- const italicWidth = 10;
57
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width + italicWidth}" height="${height}">
58
- <foreignObject width="${width + italicWidth}" height="${height}">
58
+ const realWidth = width + 10;
59
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${realWidth}" height="${height}">
60
+ <foreignObject width="${realWidth}" height="${height}">
59
61
  <style>
60
62
  * {
61
63
  margin: 0;
@@ -68,8 +70,10 @@ exports.HTMLText = class HTMLText extends draw.Image {
68
70
  </body>
69
71
  </foreignObject>
70
72
  </svg>`;
71
- this.__.__setImageFill('data:image/svg+xml,' + encodeURIComponent(svg));
72
- this.__.__htmlChanged = false;
73
+ data.__setImageFill('data:image/svg+xml,' + encodeURIComponent(svg));
74
+ data.__naturalWidth = realWidth / data.pixelRatio;
75
+ data.__naturalHeight = height / data.pixelRatio;
76
+ data.__htmlChanged = false;
73
77
  div.remove();
74
78
  }
75
79
  super.__updateBoxBounds();
package/dist/html.esm.js CHANGED
@@ -38,11 +38,13 @@ class HTMLTextData extends ImageData {
38
38
 
39
39
  let HTMLText = class HTMLText extends Image {
40
40
  get __tag() { return 'HTMLText'; }
41
+ get editInner() { return 'TextEditor'; }
41
42
  constructor(data) {
42
43
  super(data);
43
44
  }
44
45
  __updateBoxBounds() {
45
- if (this.__.__htmlChanged) {
46
+ const data = this.__;
47
+ if (data.__htmlChanged) {
46
48
  const div = document.createElement('div');
47
49
  const { style } = div;
48
50
  style.all = 'initial';
@@ -51,9 +53,9 @@ let HTMLText = class HTMLText extends Image {
51
53
  div.innerHTML = this.text;
52
54
  document.body.appendChild(div);
53
55
  const { width, height } = div.getBoundingClientRect();
54
- const italicWidth = 10;
55
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width + italicWidth}" height="${height}">
56
- <foreignObject width="${width + italicWidth}" height="${height}">
56
+ const realWidth = width + 10;
57
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${realWidth}" height="${height}">
58
+ <foreignObject width="${realWidth}" height="${height}">
57
59
  <style>
58
60
  * {
59
61
  margin: 0;
@@ -66,8 +68,10 @@ let HTMLText = class HTMLText extends Image {
66
68
  </body>
67
69
  </foreignObject>
68
70
  </svg>`;
69
- this.__.__setImageFill('data:image/svg+xml,' + encodeURIComponent(svg));
70
- this.__.__htmlChanged = false;
71
+ data.__setImageFill('data:image/svg+xml,' + encodeURIComponent(svg));
72
+ data.__naturalWidth = realWidth / data.pixelRatio;
73
+ data.__naturalHeight = height / data.pixelRatio;
74
+ data.__htmlChanged = false;
71
75
  div.remove();
72
76
  }
73
77
  super.__updateBoxBounds();
@@ -1 +1 @@
1
- import{ImageData as t,dataProcessor as e,boundsType as n,registerUI as o,Image as i}from"@leafer-ui/draw";function r(t,e,n,o){var i,r=arguments.length,s=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,o);else for(var d=t.length-1;d>=0;d--)(i=t[d])&&(s=(r<3?i(s):r>3?i(e,n,s):i(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s}"function"==typeof SuppressedError&&SuppressedError;class s extends t{setText(t){this._text=t,this.__htmlChanged=!0}}let d=class extends i{get __tag(){return"HTMLText"}constructor(t){super(t)}__updateBoxBounds(){if(this.__.__htmlChanged){const t=document.createElement("div"),{style:e}=t;e.all="initial",e.position="absolute",e.visibility="hidden",t.innerHTML=this.text,document.body.appendChild(t);const{width:n,height:o}=t.getBoundingClientRect(),i=10,r=`<svg xmlns="http://www.w3.org/2000/svg" width="${n+i}" height="${o}">\n <foreignObject width="${n+i}" height="${o}">\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n </style>\n <body xmlns="http://www.w3.org/1999/xhtml">\n ${this.text}\n </body>\n </foreignObject>\n </svg>`;this.__.__setImageFill("data:image/svg+xml,"+encodeURIComponent(r)),this.__.__htmlChanged=!1,t.remove()}super.__updateBoxBounds()}};r([e(s)],d.prototype,"__",void 0),r([n("")],d.prototype,"text",void 0),d=r([o()],d);export{d as HTMLText,s as HTMLTextData};
1
+ import{ImageData as t,dataProcessor as e,boundsType as n,registerUI as o,Image as i}from"@leafer-ui/draw";function r(t,e,n,o){var i,r=arguments.length,s=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,o);else for(var d=t.length-1;d>=0;d--)(i=t[d])&&(s=(r<3?i(s):r>3?i(e,n,s):i(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s}"function"==typeof SuppressedError&&SuppressedError;class s extends t{setText(t){this._text=t,this.__htmlChanged=!0}}let d=class extends i{get __tag(){return"HTMLText"}get editInner(){return"TextEditor"}constructor(t){super(t)}__updateBoxBounds(){const t=this.__;if(t.__htmlChanged){const e=document.createElement("div"),{style:n}=e;n.all="initial",n.position="absolute",n.visibility="hidden",e.innerHTML=this.text,document.body.appendChild(e);const{width:o,height:i}=e.getBoundingClientRect(),r=o+10,s=`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${i}">\n <foreignObject width="${r}" height="${i}">\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n </style>\n <body xmlns="http://www.w3.org/1999/xhtml">\n ${this.text}\n </body>\n </foreignObject>\n </svg>`;t.__setImageFill("data:image/svg+xml,"+encodeURIComponent(s)),t.__naturalWidth=r/t.pixelRatio,t.__naturalHeight=i/t.pixelRatio,t.__htmlChanged=!1,e.remove()}super.__updateBoxBounds()}};r([e(s)],d.prototype,"__",void 0),r([n("")],d.prototype,"text",void 0),d=r([o()],d);export{d as HTMLText,s as HTMLTextData};
package/dist/html.js CHANGED
@@ -40,11 +40,13 @@ this.LeaferIN.html = (function (exports, draw) {
40
40
 
41
41
  exports.HTMLText = class HTMLText extends draw.Image {
42
42
  get __tag() { return 'HTMLText'; }
43
+ get editInner() { return 'TextEditor'; }
43
44
  constructor(data) {
44
45
  super(data);
45
46
  }
46
47
  __updateBoxBounds() {
47
- if (this.__.__htmlChanged) {
48
+ const data = this.__;
49
+ if (data.__htmlChanged) {
48
50
  const div = document.createElement('div');
49
51
  const { style } = div;
50
52
  style.all = 'initial';
@@ -53,9 +55,9 @@ this.LeaferIN.html = (function (exports, draw) {
53
55
  div.innerHTML = this.text;
54
56
  document.body.appendChild(div);
55
57
  const { width, height } = div.getBoundingClientRect();
56
- const italicWidth = 10;
57
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width + italicWidth}" height="${height}">
58
- <foreignObject width="${width + italicWidth}" height="${height}">
58
+ const realWidth = width + 10;
59
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${realWidth}" height="${height}">
60
+ <foreignObject width="${realWidth}" height="${height}">
59
61
  <style>
60
62
  * {
61
63
  margin: 0;
@@ -68,8 +70,10 @@ this.LeaferIN.html = (function (exports, draw) {
68
70
  </body>
69
71
  </foreignObject>
70
72
  </svg>`;
71
- this.__.__setImageFill('data:image/svg+xml,' + encodeURIComponent(svg));
72
- this.__.__htmlChanged = false;
73
+ data.__setImageFill('data:image/svg+xml,' + encodeURIComponent(svg));
74
+ data.__naturalWidth = realWidth / data.pixelRatio;
75
+ data.__naturalHeight = height / data.pixelRatio;
76
+ data.__htmlChanged = false;
73
77
  div.remove();
74
78
  }
75
79
  super.__updateBoxBounds();
package/dist/html.min.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("@leafer-ui/draw");function t(e,t,n,o){var r,s=arguments.length,i=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,o);else for(var d=e.length-1;d>=0;d--)(r=e[d])&&(i=(s<3?r(i):s>3?r(t,n,i):r(t,n))||i);return s>3&&i&&Object.defineProperty(t,n,i),i}"function"==typeof SuppressedError&&SuppressedError;class n extends e.ImageData{setText(e){this._text=e,this.__htmlChanged=!0}}exports.HTMLText=class extends e.Image{get __tag(){return"HTMLText"}constructor(e){super(e)}__updateBoxBounds(){if(this.__.__htmlChanged){const e=document.createElement("div"),{style:t}=e;t.all="initial",t.position="absolute",t.visibility="hidden",e.innerHTML=this.text,document.body.appendChild(e);const{width:n,height:o}=e.getBoundingClientRect(),r=10,s=`<svg xmlns="http://www.w3.org/2000/svg" width="${n+r}" height="${o}">\n <foreignObject width="${n+r}" height="${o}">\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n </style>\n <body xmlns="http://www.w3.org/1999/xhtml">\n ${this.text}\n </body>\n </foreignObject>\n </svg>`;this.__.__setImageFill("data:image/svg+xml,"+encodeURIComponent(s)),this.__.__htmlChanged=!1,e.remove()}super.__updateBoxBounds()}},t([e.dataProcessor(n)],exports.HTMLText.prototype,"__",void 0),t([e.boundsType("")],exports.HTMLText.prototype,"text",void 0),exports.HTMLText=t([e.registerUI()],exports.HTMLText),exports.HTMLTextData=n;
1
+ "use strict";var e=require("@leafer-ui/draw");function t(e,t,n,o){var r,i=arguments.length,s=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,o);else for(var d=e.length-1;d>=0;d--)(r=e[d])&&(s=(i<3?r(s):i>3?r(t,n,s):r(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s}"function"==typeof SuppressedError&&SuppressedError;class n extends e.ImageData{setText(e){this._text=e,this.__htmlChanged=!0}}exports.HTMLText=class extends e.Image{get __tag(){return"HTMLText"}get editInner(){return"TextEditor"}constructor(e){super(e)}__updateBoxBounds(){const e=this.__;if(e.__htmlChanged){const t=document.createElement("div"),{style:n}=t;n.all="initial",n.position="absolute",n.visibility="hidden",t.innerHTML=this.text,document.body.appendChild(t);const{width:o,height:r}=t.getBoundingClientRect(),i=o+10,s=`<svg xmlns="http://www.w3.org/2000/svg" width="${i}" height="${r}">\n <foreignObject width="${i}" height="${r}">\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n </style>\n <body xmlns="http://www.w3.org/1999/xhtml">\n ${this.text}\n </body>\n </foreignObject>\n </svg>`;e.__setImageFill("data:image/svg+xml,"+encodeURIComponent(s)),e.__naturalWidth=i/e.pixelRatio,e.__naturalHeight=r/e.pixelRatio,e.__htmlChanged=!1,t.remove()}super.__updateBoxBounds()}},t([e.dataProcessor(n)],exports.HTMLText.prototype,"__",void 0),t([e.boundsType("")],exports.HTMLText.prototype,"text",void 0),exports.HTMLText=t([e.registerUI()],exports.HTMLText),exports.HTMLTextData=n;
package/dist/html.min.js CHANGED
@@ -1 +1 @@
1
- this.LeaferIN=this.LeaferIN||{},this.LeaferIN.html=function(e,t){"use strict";function n(e,t,n,o){var i,r=arguments.length,s=r<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,o);else for(var d=e.length-1;d>=0;d--)(i=e[d])&&(s=(r<3?i(s):r>3?i(t,n,s):i(t,n))||s);return r>3&&s&&Object.defineProperty(t,n,s),s}"function"==typeof SuppressedError&&SuppressedError;class o extends t.ImageData{setText(e){this._text=e,this.__htmlChanged=!0}}return e.HTMLText=class extends t.Image{get __tag(){return"HTMLText"}constructor(e){super(e)}__updateBoxBounds(){if(this.__.__htmlChanged){const e=document.createElement("div"),{style:t}=e;t.all="initial",t.position="absolute",t.visibility="hidden",e.innerHTML=this.text,document.body.appendChild(e);const{width:n,height:o}=e.getBoundingClientRect(),i=10,r=`<svg xmlns="http://www.w3.org/2000/svg" width="${n+i}" height="${o}">\n <foreignObject width="${n+i}" height="${o}">\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n </style>\n <body xmlns="http://www.w3.org/1999/xhtml">\n ${this.text}\n </body>\n </foreignObject>\n </svg>`;this.__.__setImageFill("data:image/svg+xml,"+encodeURIComponent(r)),this.__.__htmlChanged=!1,e.remove()}super.__updateBoxBounds()}},n([t.dataProcessor(o)],e.HTMLText.prototype,"__",void 0),n([t.boundsType("")],e.HTMLText.prototype,"text",void 0),e.HTMLText=n([t.registerUI()],e.HTMLText),e.HTMLTextData=o,e}({},LeaferUI);
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.html=function(e,t){"use strict";function n(e,t,n,i){var o,r=arguments.length,s=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(r<3?o(s):r>3?o(t,n,s):o(t,n))||s);return r>3&&s&&Object.defineProperty(t,n,s),s}"function"==typeof SuppressedError&&SuppressedError;class i extends t.ImageData{setText(e){this._text=e,this.__htmlChanged=!0}}return e.HTMLText=class extends t.Image{get __tag(){return"HTMLText"}get editInner(){return"TextEditor"}constructor(e){super(e)}__updateBoxBounds(){const e=this.__;if(e.__htmlChanged){const t=document.createElement("div"),{style:n}=t;n.all="initial",n.position="absolute",n.visibility="hidden",t.innerHTML=this.text,document.body.appendChild(t);const{width:i,height:o}=t.getBoundingClientRect(),r=i+10,s=`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${o}">\n <foreignObject width="${r}" height="${o}">\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n </style>\n <body xmlns="http://www.w3.org/1999/xhtml">\n ${this.text}\n </body>\n </foreignObject>\n </svg>`;e.__setImageFill("data:image/svg+xml,"+encodeURIComponent(s)),e.__naturalWidth=r/e.pixelRatio,e.__naturalHeight=o/e.pixelRatio,e.__htmlChanged=!1,t.remove()}super.__updateBoxBounds()}},n([t.dataProcessor(i)],e.HTMLText.prototype,"__",void 0),n([t.boundsType("")],e.HTMLText.prototype,"text",void 0),e.HTMLText=n([t.registerUI()],e.HTMLText),e.HTMLTextData=i,e}({},LeaferUI);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/html",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "@leafer-in/html",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,8 +34,8 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "dependencies": {
37
- "@leafer-ui/draw": "1.0.1",
38
- "@leafer-ui/interface": "1.0.1",
39
- "@leafer-in/interface": "1.0.1"
37
+ "@leafer-ui/draw": "^1.0.3",
38
+ "@leafer-ui/interface": "^1.0.3",
39
+ "@leafer-in/interface": "^1.0.3"
40
40
  }
41
41
  }
package/src/HTMLText.ts CHANGED
@@ -17,13 +17,17 @@ export class HTMLText extends Image implements IImage {
17
17
  @boundsType('')
18
18
  public text?: IString
19
19
 
20
+ public get editInner(): string { return 'TextEditor' }
21
+
20
22
  constructor(data?: IHTMLTextInputData) {
21
23
  super(data)
22
24
  }
23
25
 
24
26
  public __updateBoxBounds(): void {
25
27
 
26
- if (this.__.__htmlChanged) {
28
+ const data = this.__
29
+
30
+ if (data.__htmlChanged) {
27
31
 
28
32
  const div = document.createElement('div')
29
33
  const { style } = div
@@ -35,10 +39,10 @@ export class HTMLText extends Image implements IImage {
35
39
  document.body.appendChild(div)
36
40
 
37
41
  const { width, height } = div.getBoundingClientRect()
38
- const italicWidth = 10 // add italic width
42
+ const realWidth = width + 10 // add italic width
39
43
 
40
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width + italicWidth}" height="${height}">
41
- <foreignObject width="${width + italicWidth}" height="${height}">
44
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${realWidth}" height="${height}">
45
+ <foreignObject width="${realWidth}" height="${height}">
42
46
  <style>
43
47
  * {
44
48
  margin: 0;
@@ -52,8 +56,12 @@ export class HTMLText extends Image implements IImage {
52
56
  </foreignObject>
53
57
  </svg>`
54
58
 
55
- this.__.__setImageFill('data:image/svg+xml,' + encodeURIComponent(svg))
56
- this.__.__htmlChanged = false
59
+ data.__setImageFill('data:image/svg+xml,' + encodeURIComponent(svg))
60
+
61
+ data.__naturalWidth = realWidth / data.pixelRatio
62
+ data.__naturalHeight = height / data.pixelRatio
63
+
64
+ data.__htmlChanged = false
57
65
 
58
66
  div.remove()
59
67
  }
package/types/index.d.ts CHANGED
@@ -6,6 +6,7 @@ declare class HTMLText extends Image implements IImage {
6
6
  get __tag(): string;
7
7
  __: IHTMLTextData;
8
8
  text?: IString;
9
+ get editInner(): string;
9
10
  constructor(data?: IHTMLTextInputData);
10
11
  __updateBoxBounds(): void;
11
12
  }