@leafer-in/html 1.0.0-rc.22 → 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/dist/html.cjs ADDED
@@ -0,0 +1,86 @@
1
+ 'use strict';
2
+
3
+ var draw = require('@leafer-ui/draw');
4
+
5
+ /******************************************************************************
6
+ Copyright (c) Microsoft Corporation.
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ ***************************************************************************** */
19
+ /* global Reflect, Promise, SuppressedError, Symbol */
20
+
21
+
22
+ function __decorate(decorators, target, key, desc) {
23
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
24
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
25
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
26
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
27
+ }
28
+
29
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
30
+ var e = new Error(message);
31
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
32
+ };
33
+
34
+ class HTMLTextData extends draw.ImageData {
35
+ setText(value) {
36
+ this._text = value;
37
+ this.__htmlChanged = true;
38
+ }
39
+ }
40
+
41
+ exports.HTMLText = class HTMLText extends draw.Image {
42
+ get __tag() { return 'HTMLText'; }
43
+ constructor(data) {
44
+ super(data);
45
+ }
46
+ __updateBoxBounds() {
47
+ if (this.__.__htmlChanged) {
48
+ const div = document.createElement('div');
49
+ const { style } = div;
50
+ style.all = 'initial';
51
+ style.position = 'absolute';
52
+ style.visibility = 'hidden';
53
+ div.innerHTML = this.text;
54
+ document.body.appendChild(div);
55
+ 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}">
59
+ <style>
60
+ * {
61
+ margin: 0;
62
+ padding: 0;
63
+ box-sizing: border-box;
64
+ }
65
+ </style>
66
+ <body xmlns="http://www.w3.org/1999/xhtml">
67
+ ${this.text}
68
+ </body>
69
+ </foreignObject>
70
+ </svg>`;
71
+ this.__.__setImageFill('data:image/svg+xml,' + encodeURIComponent(svg));
72
+ this.__.__htmlChanged = false;
73
+ div.remove();
74
+ }
75
+ super.__updateBoxBounds();
76
+ }
77
+ };
78
+ __decorate([
79
+ draw.dataProcessor(HTMLTextData)
80
+ ], exports.HTMLText.prototype, "__", void 0);
81
+ __decorate([
82
+ draw.boundsType('')
83
+ ], exports.HTMLText.prototype, "text", void 0);
84
+ exports.HTMLText = __decorate([
85
+ draw.registerUI()
86
+ ], exports.HTMLText);
@@ -0,0 +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);
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@leafer-in/html",
3
- "version": "1.0.0-rc.22",
3
+ "version": "1.0.0-rc.24",
4
4
  "description": "@leafer-in/html",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
+ "type": "module",
7
8
  "main": "dist/html.esm.js",
9
+ "exports": {
10
+ "import": "./dist/html.esm.js",
11
+ "require": "./dist/html.cjs",
12
+ "types": "./types/index.d.ts"
13
+ },
14
+ "types": "types/index.d.ts",
8
15
  "unpkg": "dist/html.js",
9
16
  "jsdelivr": "dist/html.js",
10
- "types": "types/index.d.ts",
11
17
  "files": [
12
18
  "src",
13
19
  "types",
@@ -28,8 +34,8 @@
28
34
  "leaferjs"
29
35
  ],
30
36
  "dependencies": {
31
- "@leafer-ui/draw": "1.0.0-rc.22",
32
- "@leafer-ui/interface": "1.0.0-rc.22",
33
- "@leafer-in/interface": "1.0.0-rc.22"
37
+ "@leafer-ui/draw": "1.0.0-rc.24",
38
+ "@leafer-ui/interface": "1.0.0-rc.24",
39
+ "@leafer-in/interface": "1.0.0-rc.24"
34
40
  }
35
41
  }