@leafer-in/html 1.0.0-rc.10

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