@idraw/renderer 0.4.0-beta.3 → 0.4.0-beta.4
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/esm/index.d.ts +3 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/loader.d.ts +4 -11
- package/dist/esm/loader.js +110 -97
- package/dist/index.global.js +121 -92
- package/dist/index.global.min.js +1 -1
- package/package.json +3 -3
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from '@idraw/util';
|
|
2
|
+
import type { LoadItemMap } from '@idraw/types';
|
|
2
3
|
import type { Data, BoardRenderer, RendererOptions, RendererEventMap, RendererDrawOptions } from '@idraw/types';
|
|
3
4
|
export declare class Renderer extends EventEmitter<RendererEventMap> implements BoardRenderer {
|
|
4
5
|
#private;
|
|
@@ -6,4 +7,6 @@ export declare class Renderer extends EventEmitter<RendererEventMap> implements
|
|
|
6
7
|
updateOptions(opts: RendererOptions): void;
|
|
7
8
|
drawData(data: Data, opts: RendererDrawOptions): void;
|
|
8
9
|
scale(num: number): void;
|
|
10
|
+
setLoadItemMap(itemMap: LoadItemMap): void;
|
|
11
|
+
getLoadItemMap(): LoadItemMap;
|
|
9
12
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -65,6 +65,12 @@ export class Renderer extends EventEmitter {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
+
setLoadItemMap(itemMap) {
|
|
69
|
+
__classPrivateFieldGet(this, _Renderer_loader, "f").setLoadItemMap(itemMap);
|
|
70
|
+
}
|
|
71
|
+
getLoadItemMap() {
|
|
72
|
+
return __classPrivateFieldGet(this, _Renderer_loader, "f").getLoadItemMap();
|
|
73
|
+
}
|
|
68
74
|
}
|
|
69
75
|
_Renderer_opts = new WeakMap(), _Renderer_loader = new WeakMap(), _Renderer_instances = new WeakSet(), _Renderer_init = function _Renderer_init() {
|
|
70
76
|
const loader = __classPrivateFieldGet(this, _Renderer_loader, "f");
|
package/dist/esm/loader.d.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import type { RendererLoader, LoaderEventMap, LoadContent, LoadElementType, Element, ElementAssets } from '@idraw/types';
|
|
1
|
+
import type { RendererLoader, LoaderEventMap, LoadContent, LoadItemMap, LoadElementType, Element, ElementAssets } from '@idraw/types';
|
|
2
2
|
import { EventEmitter } from '@idraw/util';
|
|
3
3
|
export declare class Loader extends EventEmitter<LoaderEventMap> implements RendererLoader {
|
|
4
|
-
private
|
|
5
|
-
private _currentLoadItemMap;
|
|
6
|
-
private _storageLoadItemMap;
|
|
4
|
+
#private;
|
|
7
5
|
constructor();
|
|
8
|
-
private _registerLoadFunc;
|
|
9
|
-
private _getLoadElementSource;
|
|
10
|
-
private _createLoadItem;
|
|
11
|
-
private _emitLoad;
|
|
12
|
-
private _emitError;
|
|
13
|
-
private _loadResource;
|
|
14
|
-
private _isExistingErrorStorage;
|
|
15
6
|
load(element: Element<LoadElementType>, assets: ElementAssets): void;
|
|
16
7
|
getContent(element: Element<LoadElementType>): LoadContent | null;
|
|
8
|
+
getLoadItemMap(): LoadItemMap;
|
|
9
|
+
setLoadItemMap(itemMap: LoadItemMap): void;
|
|
17
10
|
}
|
package/dist/esm/loader.js
CHANGED
|
@@ -7,6 +7,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
11
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
13
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
+
};
|
|
15
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
16
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
17
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
18
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
19
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
20
|
+
};
|
|
21
|
+
var _Loader_instances, _Loader_loadFuncMap, _Loader_currentLoadItemMap, _Loader_storageLoadItemMap, _Loader_registerLoadFunc, _Loader_getLoadElementSource, _Loader_createLoadItem, _Loader_emitLoad, _Loader_emitError, _Loader_loadResource, _Loader_isExistingErrorStorage;
|
|
10
22
|
import { loadImage, loadHTML, loadSVG, EventEmitter, createAssetId, isAssetId, createUUID } from '@idraw/util';
|
|
11
23
|
const supportElementTypes = ['image', 'svg', 'html'];
|
|
12
24
|
const getAssetIdFromElement = (element) => {
|
|
@@ -32,10 +44,11 @@ const getAssetIdFromElement = (element) => {
|
|
|
32
44
|
export class Loader extends EventEmitter {
|
|
33
45
|
constructor() {
|
|
34
46
|
super();
|
|
35
|
-
this
|
|
36
|
-
this
|
|
37
|
-
this
|
|
38
|
-
|
|
47
|
+
_Loader_instances.add(this);
|
|
48
|
+
_Loader_loadFuncMap.set(this, {});
|
|
49
|
+
_Loader_currentLoadItemMap.set(this, {});
|
|
50
|
+
_Loader_storageLoadItemMap.set(this, {});
|
|
51
|
+
__classPrivateFieldGet(this, _Loader_instances, "m", _Loader_registerLoadFunc).call(this, 'image', (elem, assets) => __awaiter(this, void 0, void 0, function* () {
|
|
39
52
|
var _a;
|
|
40
53
|
const src = ((_a = assets[elem.detail.src]) === null || _a === void 0 ? void 0 : _a.value) || elem.detail.src;
|
|
41
54
|
const content = yield loadImage(src);
|
|
@@ -45,7 +58,7 @@ export class Loader extends EventEmitter {
|
|
|
45
58
|
content
|
|
46
59
|
};
|
|
47
60
|
}));
|
|
48
|
-
this.
|
|
61
|
+
__classPrivateFieldGet(this, _Loader_instances, "m", _Loader_registerLoadFunc).call(this, 'html', (elem, assets) => __awaiter(this, void 0, void 0, function* () {
|
|
49
62
|
var _b;
|
|
50
63
|
const html = ((_b = assets[elem.detail.html]) === null || _b === void 0 ? void 0 : _b.value) || elem.detail.html;
|
|
51
64
|
const content = yield loadHTML(html, {
|
|
@@ -58,7 +71,7 @@ export class Loader extends EventEmitter {
|
|
|
58
71
|
content
|
|
59
72
|
};
|
|
60
73
|
}));
|
|
61
|
-
this.
|
|
74
|
+
__classPrivateFieldGet(this, _Loader_instances, "m", _Loader_registerLoadFunc).call(this, 'svg', (elem, assets) => __awaiter(this, void 0, void 0, function* () {
|
|
62
75
|
var _c;
|
|
63
76
|
const svg = ((_c = assets[elem.detail.svg]) === null || _c === void 0 ? void 0 : _c.value) || elem.detail.svg;
|
|
64
77
|
const content = yield loadSVG(svg);
|
|
@@ -69,105 +82,105 @@ export class Loader extends EventEmitter {
|
|
|
69
82
|
};
|
|
70
83
|
}));
|
|
71
84
|
}
|
|
72
|
-
_registerLoadFunc(type, func) {
|
|
73
|
-
this._loadFuncMap[type] = func;
|
|
74
|
-
}
|
|
75
|
-
_getLoadElementSource(element) {
|
|
76
|
-
var _a, _b, _c;
|
|
77
|
-
let source = null;
|
|
78
|
-
if (element.type === 'image') {
|
|
79
|
-
source = ((_a = element === null || element === void 0 ? void 0 : element.detail) === null || _a === void 0 ? void 0 : _a.src) || null;
|
|
80
|
-
}
|
|
81
|
-
else if (element.type === 'svg') {
|
|
82
|
-
source = ((_b = element === null || element === void 0 ? void 0 : element.detail) === null || _b === void 0 ? void 0 : _b.svg) || null;
|
|
83
|
-
}
|
|
84
|
-
else if (element.type === 'html') {
|
|
85
|
-
source = ((_c = element === null || element === void 0 ? void 0 : element.detail) === null || _c === void 0 ? void 0 : _c.html) || null;
|
|
86
|
-
}
|
|
87
|
-
return source;
|
|
88
|
-
}
|
|
89
|
-
_createLoadItem(element) {
|
|
90
|
-
return {
|
|
91
|
-
element,
|
|
92
|
-
status: 'null',
|
|
93
|
-
content: null,
|
|
94
|
-
error: null,
|
|
95
|
-
startTime: -1,
|
|
96
|
-
endTime: -1,
|
|
97
|
-
source: this._getLoadElementSource(element)
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
_emitLoad(item) {
|
|
101
|
-
const assetId = getAssetIdFromElement(item.element);
|
|
102
|
-
const storageItem = this._storageLoadItemMap[assetId];
|
|
103
|
-
if (storageItem) {
|
|
104
|
-
if (storageItem.startTime < item.startTime) {
|
|
105
|
-
this._storageLoadItemMap[assetId] = item;
|
|
106
|
-
this.trigger('load', Object.assign(Object.assign({}, item), { countTime: item.endTime - item.startTime }));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
this._storageLoadItemMap[assetId] = item;
|
|
111
|
-
this.trigger('load', Object.assign(Object.assign({}, item), { countTime: item.endTime - item.startTime }));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
_emitError(item) {
|
|
115
|
-
const assetId = getAssetIdFromElement(item.element);
|
|
116
|
-
const storageItem = this._storageLoadItemMap[assetId];
|
|
117
|
-
if (storageItem) {
|
|
118
|
-
if (storageItem.startTime < item.startTime) {
|
|
119
|
-
this._storageLoadItemMap[assetId] = item;
|
|
120
|
-
this.trigger('error', Object.assign(Object.assign({}, item), { countTime: item.endTime - item.startTime }));
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
this._storageLoadItemMap[assetId] = item;
|
|
125
|
-
this.trigger('error', Object.assign(Object.assign({}, item), { countTime: item.endTime - item.startTime }));
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
_loadResource(element, assets) {
|
|
129
|
-
const item = this._createLoadItem(element);
|
|
130
|
-
const assetId = getAssetIdFromElement(element);
|
|
131
|
-
this._currentLoadItemMap[assetId] = item;
|
|
132
|
-
const loadFunc = this._loadFuncMap[element.type];
|
|
133
|
-
if (typeof loadFunc === 'function') {
|
|
134
|
-
item.startTime = Date.now();
|
|
135
|
-
loadFunc(element, assets)
|
|
136
|
-
.then((result) => {
|
|
137
|
-
item.content = result.content;
|
|
138
|
-
item.endTime = Date.now();
|
|
139
|
-
item.status = 'load';
|
|
140
|
-
this._emitLoad(item);
|
|
141
|
-
})
|
|
142
|
-
.catch((err) => {
|
|
143
|
-
console.warn(`Load element source "${item.source}" fail`, err, element);
|
|
144
|
-
item.endTime = Date.now();
|
|
145
|
-
item.status = 'error';
|
|
146
|
-
item.error = err;
|
|
147
|
-
this._emitError(item);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
_isExistingErrorStorage(element) {
|
|
152
|
-
var _a;
|
|
153
|
-
const assetId = getAssetIdFromElement(element);
|
|
154
|
-
const existItem = (_a = this._currentLoadItemMap) === null || _a === void 0 ? void 0 : _a[assetId];
|
|
155
|
-
if (existItem && existItem.status === 'error' && existItem.source && existItem.source === this._getLoadElementSource(element)) {
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
85
|
load(element, assets) {
|
|
161
|
-
if (this.
|
|
86
|
+
if (__classPrivateFieldGet(this, _Loader_instances, "m", _Loader_isExistingErrorStorage).call(this, element)) {
|
|
162
87
|
return;
|
|
163
88
|
}
|
|
164
89
|
if (supportElementTypes.includes(element.type)) {
|
|
165
|
-
this.
|
|
90
|
+
__classPrivateFieldGet(this, _Loader_instances, "m", _Loader_loadResource).call(this, element, assets);
|
|
166
91
|
}
|
|
167
92
|
}
|
|
168
93
|
getContent(element) {
|
|
169
94
|
var _a, _b;
|
|
170
95
|
const assetId = getAssetIdFromElement(element);
|
|
171
|
-
return ((_b = (_a = this
|
|
96
|
+
return ((_b = (_a = __classPrivateFieldGet(this, _Loader_storageLoadItemMap, "f")) === null || _a === void 0 ? void 0 : _a[assetId]) === null || _b === void 0 ? void 0 : _b.content) || null;
|
|
97
|
+
}
|
|
98
|
+
getLoadItemMap() {
|
|
99
|
+
return __classPrivateFieldGet(this, _Loader_storageLoadItemMap, "f");
|
|
100
|
+
}
|
|
101
|
+
setLoadItemMap(itemMap) {
|
|
102
|
+
__classPrivateFieldSet(this, _Loader_storageLoadItemMap, itemMap, "f");
|
|
172
103
|
}
|
|
173
104
|
}
|
|
105
|
+
_Loader_loadFuncMap = new WeakMap(), _Loader_currentLoadItemMap = new WeakMap(), _Loader_storageLoadItemMap = new WeakMap(), _Loader_instances = new WeakSet(), _Loader_registerLoadFunc = function _Loader_registerLoadFunc(type, func) {
|
|
106
|
+
__classPrivateFieldGet(this, _Loader_loadFuncMap, "f")[type] = func;
|
|
107
|
+
}, _Loader_getLoadElementSource = function _Loader_getLoadElementSource(element) {
|
|
108
|
+
var _a, _b, _c;
|
|
109
|
+
let source = null;
|
|
110
|
+
if (element.type === 'image') {
|
|
111
|
+
source = ((_a = element === null || element === void 0 ? void 0 : element.detail) === null || _a === void 0 ? void 0 : _a.src) || null;
|
|
112
|
+
}
|
|
113
|
+
else if (element.type === 'svg') {
|
|
114
|
+
source = ((_b = element === null || element === void 0 ? void 0 : element.detail) === null || _b === void 0 ? void 0 : _b.svg) || null;
|
|
115
|
+
}
|
|
116
|
+
else if (element.type === 'html') {
|
|
117
|
+
source = ((_c = element === null || element === void 0 ? void 0 : element.detail) === null || _c === void 0 ? void 0 : _c.html) || null;
|
|
118
|
+
}
|
|
119
|
+
return source;
|
|
120
|
+
}, _Loader_createLoadItem = function _Loader_createLoadItem(element) {
|
|
121
|
+
return {
|
|
122
|
+
element,
|
|
123
|
+
status: 'null',
|
|
124
|
+
content: null,
|
|
125
|
+
error: null,
|
|
126
|
+
startTime: -1,
|
|
127
|
+
endTime: -1,
|
|
128
|
+
source: __classPrivateFieldGet(this, _Loader_instances, "m", _Loader_getLoadElementSource).call(this, element)
|
|
129
|
+
};
|
|
130
|
+
}, _Loader_emitLoad = function _Loader_emitLoad(item) {
|
|
131
|
+
const assetId = getAssetIdFromElement(item.element);
|
|
132
|
+
const storageItem = __classPrivateFieldGet(this, _Loader_storageLoadItemMap, "f")[assetId];
|
|
133
|
+
if (storageItem) {
|
|
134
|
+
if (storageItem.startTime < item.startTime) {
|
|
135
|
+
__classPrivateFieldGet(this, _Loader_storageLoadItemMap, "f")[assetId] = item;
|
|
136
|
+
this.trigger('load', Object.assign(Object.assign({}, item), { countTime: item.endTime - item.startTime }));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
__classPrivateFieldGet(this, _Loader_storageLoadItemMap, "f")[assetId] = item;
|
|
141
|
+
this.trigger('load', Object.assign(Object.assign({}, item), { countTime: item.endTime - item.startTime }));
|
|
142
|
+
}
|
|
143
|
+
}, _Loader_emitError = function _Loader_emitError(item) {
|
|
144
|
+
const assetId = getAssetIdFromElement(item.element);
|
|
145
|
+
const storageItem = __classPrivateFieldGet(this, _Loader_storageLoadItemMap, "f")[assetId];
|
|
146
|
+
if (storageItem) {
|
|
147
|
+
if (storageItem.startTime < item.startTime) {
|
|
148
|
+
__classPrivateFieldGet(this, _Loader_storageLoadItemMap, "f")[assetId] = item;
|
|
149
|
+
this.trigger('error', Object.assign(Object.assign({}, item), { countTime: item.endTime - item.startTime }));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
__classPrivateFieldGet(this, _Loader_storageLoadItemMap, "f")[assetId] = item;
|
|
154
|
+
this.trigger('error', Object.assign(Object.assign({}, item), { countTime: item.endTime - item.startTime }));
|
|
155
|
+
}
|
|
156
|
+
}, _Loader_loadResource = function _Loader_loadResource(element, assets) {
|
|
157
|
+
const item = __classPrivateFieldGet(this, _Loader_instances, "m", _Loader_createLoadItem).call(this, element);
|
|
158
|
+
const assetId = getAssetIdFromElement(element);
|
|
159
|
+
__classPrivateFieldGet(this, _Loader_currentLoadItemMap, "f")[assetId] = item;
|
|
160
|
+
const loadFunc = __classPrivateFieldGet(this, _Loader_loadFuncMap, "f")[element.type];
|
|
161
|
+
if (typeof loadFunc === 'function') {
|
|
162
|
+
item.startTime = Date.now();
|
|
163
|
+
loadFunc(element, assets)
|
|
164
|
+
.then((result) => {
|
|
165
|
+
item.content = result.content;
|
|
166
|
+
item.endTime = Date.now();
|
|
167
|
+
item.status = 'load';
|
|
168
|
+
__classPrivateFieldGet(this, _Loader_instances, "m", _Loader_emitLoad).call(this, item);
|
|
169
|
+
})
|
|
170
|
+
.catch((err) => {
|
|
171
|
+
console.warn(`Load element source "${item.source}" fail`, err, element);
|
|
172
|
+
item.endTime = Date.now();
|
|
173
|
+
item.status = 'error';
|
|
174
|
+
item.error = err;
|
|
175
|
+
__classPrivateFieldGet(this, _Loader_instances, "m", _Loader_emitError).call(this, item);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}, _Loader_isExistingErrorStorage = function _Loader_isExistingErrorStorage(element) {
|
|
179
|
+
var _a;
|
|
180
|
+
const assetId = getAssetIdFromElement(element);
|
|
181
|
+
const existItem = (_a = __classPrivateFieldGet(this, _Loader_currentLoadItemMap, "f")) === null || _a === void 0 ? void 0 : _a[assetId];
|
|
182
|
+
if (existItem && existItem.status === 'error' && existItem.source && existItem.source === __classPrivateFieldGet(this, _Loader_instances, "m", _Loader_getLoadElementSource).call(this, element)) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
186
|
+
};
|
package/dist/index.global.js
CHANGED
|
@@ -22,7 +22,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
22
22
|
return method;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
var _opts, _loader, _init, init_fn;
|
|
25
|
+
var _loadFuncMap, _currentLoadItemMap, _storageLoadItemMap, _registerLoadFunc, registerLoadFunc_fn, _getLoadElementSource, getLoadElementSource_fn, _createLoadItem, createLoadItem_fn, _emitLoad, emitLoad_fn, _emitError, emitError_fn, _loadResource, loadResource_fn, _isExistingErrorStorage, isExistingErrorStorage_fn, _opts, _loader, _init, init_fn;
|
|
26
26
|
function isColorStr(color2) {
|
|
27
27
|
return typeof color2 === "string" && (/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color2) || /^[a-z]{1,}$/i.test(color2));
|
|
28
28
|
}
|
|
@@ -1272,10 +1272,17 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1272
1272
|
class Loader extends EventEmitter {
|
|
1273
1273
|
constructor() {
|
|
1274
1274
|
super();
|
|
1275
|
-
this
|
|
1276
|
-
this
|
|
1277
|
-
this
|
|
1278
|
-
this
|
|
1275
|
+
__privateAdd(this, _registerLoadFunc);
|
|
1276
|
+
__privateAdd(this, _getLoadElementSource);
|
|
1277
|
+
__privateAdd(this, _createLoadItem);
|
|
1278
|
+
__privateAdd(this, _emitLoad);
|
|
1279
|
+
__privateAdd(this, _emitError);
|
|
1280
|
+
__privateAdd(this, _loadResource);
|
|
1281
|
+
__privateAdd(this, _isExistingErrorStorage);
|
|
1282
|
+
__privateAdd(this, _loadFuncMap, {});
|
|
1283
|
+
__privateAdd(this, _currentLoadItemMap, {});
|
|
1284
|
+
__privateAdd(this, _storageLoadItemMap, {});
|
|
1285
|
+
__privateMethod(this, _registerLoadFunc, registerLoadFunc_fn).call(this, "image", async (elem, assets) => {
|
|
1279
1286
|
var _a;
|
|
1280
1287
|
const src = ((_a = assets[elem.detail.src]) == null ? void 0 : _a.value) || elem.detail.src;
|
|
1281
1288
|
const content = await loadImage(src);
|
|
@@ -1285,7 +1292,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1285
1292
|
content
|
|
1286
1293
|
};
|
|
1287
1294
|
});
|
|
1288
|
-
this.
|
|
1295
|
+
__privateMethod(this, _registerLoadFunc, registerLoadFunc_fn).call(this, "html", async (elem, assets) => {
|
|
1289
1296
|
var _a;
|
|
1290
1297
|
const html2 = ((_a = assets[elem.detail.html]) == null ? void 0 : _a.value) || elem.detail.html;
|
|
1291
1298
|
const content = await loadHTML(html2, {
|
|
@@ -1298,7 +1305,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1298
1305
|
content
|
|
1299
1306
|
};
|
|
1300
1307
|
});
|
|
1301
|
-
this.
|
|
1308
|
+
__privateMethod(this, _registerLoadFunc, registerLoadFunc_fn).call(this, "svg", async (elem, assets) => {
|
|
1302
1309
|
var _a;
|
|
1303
1310
|
const svg2 = ((_a = assets[elem.detail.svg]) == null ? void 0 : _a.value) || elem.detail.svg;
|
|
1304
1311
|
const content = await loadSVG(svg2);
|
|
@@ -1309,102 +1316,118 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1309
1316
|
};
|
|
1310
1317
|
});
|
|
1311
1318
|
}
|
|
1312
|
-
_registerLoadFunc(type, func) {
|
|
1313
|
-
this._loadFuncMap[type] = func;
|
|
1314
|
-
}
|
|
1315
|
-
_getLoadElementSource(element) {
|
|
1316
|
-
var _a, _b, _c;
|
|
1317
|
-
let source = null;
|
|
1318
|
-
if (element.type === "image") {
|
|
1319
|
-
source = ((_a = element == null ? void 0 : element.detail) == null ? void 0 : _a.src) || null;
|
|
1320
|
-
} else if (element.type === "svg") {
|
|
1321
|
-
source = ((_b = element == null ? void 0 : element.detail) == null ? void 0 : _b.svg) || null;
|
|
1322
|
-
} else if (element.type === "html") {
|
|
1323
|
-
source = ((_c = element == null ? void 0 : element.detail) == null ? void 0 : _c.html) || null;
|
|
1324
|
-
}
|
|
1325
|
-
return source;
|
|
1326
|
-
}
|
|
1327
|
-
_createLoadItem(element) {
|
|
1328
|
-
return {
|
|
1329
|
-
element,
|
|
1330
|
-
status: "null",
|
|
1331
|
-
content: null,
|
|
1332
|
-
error: null,
|
|
1333
|
-
startTime: -1,
|
|
1334
|
-
endTime: -1,
|
|
1335
|
-
source: this._getLoadElementSource(element)
|
|
1336
|
-
};
|
|
1337
|
-
}
|
|
1338
|
-
_emitLoad(item) {
|
|
1339
|
-
const assetId = getAssetIdFromElement(item.element);
|
|
1340
|
-
const storageItem = this._storageLoadItemMap[assetId];
|
|
1341
|
-
if (storageItem) {
|
|
1342
|
-
if (storageItem.startTime < item.startTime) {
|
|
1343
|
-
this._storageLoadItemMap[assetId] = item;
|
|
1344
|
-
this.trigger("load", { ...item, countTime: item.endTime - item.startTime });
|
|
1345
|
-
}
|
|
1346
|
-
} else {
|
|
1347
|
-
this._storageLoadItemMap[assetId] = item;
|
|
1348
|
-
this.trigger("load", { ...item, countTime: item.endTime - item.startTime });
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
_emitError(item) {
|
|
1352
|
-
const assetId = getAssetIdFromElement(item.element);
|
|
1353
|
-
const storageItem = this._storageLoadItemMap[assetId];
|
|
1354
|
-
if (storageItem) {
|
|
1355
|
-
if (storageItem.startTime < item.startTime) {
|
|
1356
|
-
this._storageLoadItemMap[assetId] = item;
|
|
1357
|
-
this.trigger("error", { ...item, countTime: item.endTime - item.startTime });
|
|
1358
|
-
}
|
|
1359
|
-
} else {
|
|
1360
|
-
this._storageLoadItemMap[assetId] = item;
|
|
1361
|
-
this.trigger("error", { ...item, countTime: item.endTime - item.startTime });
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
_loadResource(element, assets) {
|
|
1365
|
-
const item = this._createLoadItem(element);
|
|
1366
|
-
const assetId = getAssetIdFromElement(element);
|
|
1367
|
-
this._currentLoadItemMap[assetId] = item;
|
|
1368
|
-
const loadFunc = this._loadFuncMap[element.type];
|
|
1369
|
-
if (typeof loadFunc === "function") {
|
|
1370
|
-
item.startTime = Date.now();
|
|
1371
|
-
loadFunc(element, assets).then((result) => {
|
|
1372
|
-
item.content = result.content;
|
|
1373
|
-
item.endTime = Date.now();
|
|
1374
|
-
item.status = "load";
|
|
1375
|
-
this._emitLoad(item);
|
|
1376
|
-
}).catch((err) => {
|
|
1377
|
-
console.warn(`Load element source "${item.source}" fail`, err, element);
|
|
1378
|
-
item.endTime = Date.now();
|
|
1379
|
-
item.status = "error";
|
|
1380
|
-
item.error = err;
|
|
1381
|
-
this._emitError(item);
|
|
1382
|
-
});
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
_isExistingErrorStorage(element) {
|
|
1386
|
-
var _a;
|
|
1387
|
-
const assetId = getAssetIdFromElement(element);
|
|
1388
|
-
const existItem = (_a = this._currentLoadItemMap) == null ? void 0 : _a[assetId];
|
|
1389
|
-
if (existItem && existItem.status === "error" && existItem.source && existItem.source === this._getLoadElementSource(element)) {
|
|
1390
|
-
return true;
|
|
1391
|
-
}
|
|
1392
|
-
return false;
|
|
1393
|
-
}
|
|
1394
1319
|
load(element, assets) {
|
|
1395
|
-
if (this.
|
|
1320
|
+
if (__privateMethod(this, _isExistingErrorStorage, isExistingErrorStorage_fn).call(this, element)) {
|
|
1396
1321
|
return;
|
|
1397
1322
|
}
|
|
1398
1323
|
if (supportElementTypes.includes(element.type)) {
|
|
1399
|
-
this.
|
|
1324
|
+
__privateMethod(this, _loadResource, loadResource_fn).call(this, element, assets);
|
|
1400
1325
|
}
|
|
1401
1326
|
}
|
|
1402
1327
|
getContent(element) {
|
|
1403
1328
|
var _a, _b;
|
|
1404
1329
|
const assetId = getAssetIdFromElement(element);
|
|
1405
|
-
return ((_b = (_a = this
|
|
1330
|
+
return ((_b = (_a = __privateGet(this, _storageLoadItemMap)) == null ? void 0 : _a[assetId]) == null ? void 0 : _b.content) || null;
|
|
1331
|
+
}
|
|
1332
|
+
getLoadItemMap() {
|
|
1333
|
+
return __privateGet(this, _storageLoadItemMap);
|
|
1334
|
+
}
|
|
1335
|
+
setLoadItemMap(itemMap) {
|
|
1336
|
+
__privateSet(this, _storageLoadItemMap, itemMap);
|
|
1406
1337
|
}
|
|
1407
1338
|
}
|
|
1339
|
+
_loadFuncMap = new WeakMap();
|
|
1340
|
+
_currentLoadItemMap = new WeakMap();
|
|
1341
|
+
_storageLoadItemMap = new WeakMap();
|
|
1342
|
+
_registerLoadFunc = new WeakSet();
|
|
1343
|
+
registerLoadFunc_fn = function(type, func) {
|
|
1344
|
+
__privateGet(this, _loadFuncMap)[type] = func;
|
|
1345
|
+
};
|
|
1346
|
+
_getLoadElementSource = new WeakSet();
|
|
1347
|
+
getLoadElementSource_fn = function(element) {
|
|
1348
|
+
var _a, _b, _c;
|
|
1349
|
+
let source = null;
|
|
1350
|
+
if (element.type === "image") {
|
|
1351
|
+
source = ((_a = element == null ? void 0 : element.detail) == null ? void 0 : _a.src) || null;
|
|
1352
|
+
} else if (element.type === "svg") {
|
|
1353
|
+
source = ((_b = element == null ? void 0 : element.detail) == null ? void 0 : _b.svg) || null;
|
|
1354
|
+
} else if (element.type === "html") {
|
|
1355
|
+
source = ((_c = element == null ? void 0 : element.detail) == null ? void 0 : _c.html) || null;
|
|
1356
|
+
}
|
|
1357
|
+
return source;
|
|
1358
|
+
};
|
|
1359
|
+
_createLoadItem = new WeakSet();
|
|
1360
|
+
createLoadItem_fn = function(element) {
|
|
1361
|
+
return {
|
|
1362
|
+
element,
|
|
1363
|
+
status: "null",
|
|
1364
|
+
content: null,
|
|
1365
|
+
error: null,
|
|
1366
|
+
startTime: -1,
|
|
1367
|
+
endTime: -1,
|
|
1368
|
+
source: __privateMethod(this, _getLoadElementSource, getLoadElementSource_fn).call(this, element)
|
|
1369
|
+
};
|
|
1370
|
+
};
|
|
1371
|
+
_emitLoad = new WeakSet();
|
|
1372
|
+
emitLoad_fn = function(item) {
|
|
1373
|
+
const assetId = getAssetIdFromElement(item.element);
|
|
1374
|
+
const storageItem = __privateGet(this, _storageLoadItemMap)[assetId];
|
|
1375
|
+
if (storageItem) {
|
|
1376
|
+
if (storageItem.startTime < item.startTime) {
|
|
1377
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1378
|
+
this.trigger("load", { ...item, countTime: item.endTime - item.startTime });
|
|
1379
|
+
}
|
|
1380
|
+
} else {
|
|
1381
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1382
|
+
this.trigger("load", { ...item, countTime: item.endTime - item.startTime });
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
_emitError = new WeakSet();
|
|
1386
|
+
emitError_fn = function(item) {
|
|
1387
|
+
const assetId = getAssetIdFromElement(item.element);
|
|
1388
|
+
const storageItem = __privateGet(this, _storageLoadItemMap)[assetId];
|
|
1389
|
+
if (storageItem) {
|
|
1390
|
+
if (storageItem.startTime < item.startTime) {
|
|
1391
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1392
|
+
this.trigger("error", { ...item, countTime: item.endTime - item.startTime });
|
|
1393
|
+
}
|
|
1394
|
+
} else {
|
|
1395
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1396
|
+
this.trigger("error", { ...item, countTime: item.endTime - item.startTime });
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1399
|
+
_loadResource = new WeakSet();
|
|
1400
|
+
loadResource_fn = function(element, assets) {
|
|
1401
|
+
const item = __privateMethod(this, _createLoadItem, createLoadItem_fn).call(this, element);
|
|
1402
|
+
const assetId = getAssetIdFromElement(element);
|
|
1403
|
+
__privateGet(this, _currentLoadItemMap)[assetId] = item;
|
|
1404
|
+
const loadFunc = __privateGet(this, _loadFuncMap)[element.type];
|
|
1405
|
+
if (typeof loadFunc === "function") {
|
|
1406
|
+
item.startTime = Date.now();
|
|
1407
|
+
loadFunc(element, assets).then((result) => {
|
|
1408
|
+
item.content = result.content;
|
|
1409
|
+
item.endTime = Date.now();
|
|
1410
|
+
item.status = "load";
|
|
1411
|
+
__privateMethod(this, _emitLoad, emitLoad_fn).call(this, item);
|
|
1412
|
+
}).catch((err) => {
|
|
1413
|
+
console.warn(`Load element source "${item.source}" fail`, err, element);
|
|
1414
|
+
item.endTime = Date.now();
|
|
1415
|
+
item.status = "error";
|
|
1416
|
+
item.error = err;
|
|
1417
|
+
__privateMethod(this, _emitError, emitError_fn).call(this, item);
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
_isExistingErrorStorage = new WeakSet();
|
|
1422
|
+
isExistingErrorStorage_fn = function(element) {
|
|
1423
|
+
var _a;
|
|
1424
|
+
const assetId = getAssetIdFromElement(element);
|
|
1425
|
+
const existItem = (_a = __privateGet(this, _currentLoadItemMap)) == null ? void 0 : _a[assetId];
|
|
1426
|
+
if (existItem && existItem.status === "error" && existItem.source && existItem.source === __privateMethod(this, _getLoadElementSource, getLoadElementSource_fn).call(this, element)) {
|
|
1427
|
+
return true;
|
|
1428
|
+
}
|
|
1429
|
+
return false;
|
|
1430
|
+
};
|
|
1408
1431
|
class Renderer extends EventEmitter {
|
|
1409
1432
|
// private _draftContextTop: CanvasRenderingContext2D;
|
|
1410
1433
|
// private _draftContextMiddle: CanvasRenderingContext2D;
|
|
@@ -1464,6 +1487,12 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1464
1487
|
});
|
|
1465
1488
|
}
|
|
1466
1489
|
}
|
|
1490
|
+
setLoadItemMap(itemMap) {
|
|
1491
|
+
__privateGet(this, _loader).setLoadItemMap(itemMap);
|
|
1492
|
+
}
|
|
1493
|
+
getLoadItemMap() {
|
|
1494
|
+
return __privateGet(this, _loader).getLoadItemMap();
|
|
1495
|
+
}
|
|
1467
1496
|
}
|
|
1468
1497
|
_opts = new WeakMap();
|
|
1469
1498
|
_loader = new WeakMap();
|
package/dist/index.global.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var iDrawRenderer=function(e){"use strict";var t,n,o,i,a=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},l=(e,t,n)=>(a(e,t,"read from private field"),n?n.call(e):t.get(e)),r=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},s=(e,t,n,o)=>(a(e,t,"write to private field"),o?o.call(e,n):t.set(e,n),n);function c(e){return"string"==typeof e&&(/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e)||/^[a-z]{1,}$/i.test(e))}function d(e,t){if(1===t)return e;let n=1;const o=/^\#[0-9a-f]{6,6}$/i;let i=e;if(o.test(e)?n=parseInt(e.substring(5,7).replace(/^\#/,"0x")):/^\#[0-9a-f]{8,8}$/i.test(e)&&(n=parseInt(e.substring(7,9).replace(/^\#/,"0x")),i=e.substring(0,7)),n*=t,o.test(i)&&n>0&&n<1){const e=Math.max(0,Math.min(255,Math.ceil(256*n)));i=`${i.toUpperCase()}${e.toString(16).toUpperCase()}`}return i}function h(){function e(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${e()}${e()}-${e()}-${e()}-${e()}-${e()}${e()}${e()}`}function u(e){let t=0;for(let n=0;n<e.length;n++)t+=e.charCodeAt(n)*e.charCodeAt(n)*n*n;return t.toString(16).substring(0,4)}function f(e){const t=e.length,n=Math.floor(t/2),o=e.substring(0,4).padEnd(4,"0"),i=e.substring(0,4).padEnd(4,"0");return`@assets/${u(t.toString(16).padEnd(4,o))}${u(e.substring(n-4,n).padEnd(4,o)).padEnd(4,"f")}-${u(e.substring(n-8,n-4).padEnd(4,o)).padEnd(4,"f")}-${u(e.substring(n-12,n-8).padEnd(4,o)).padEnd(4,"f")}-${u(e.substring(n-16,n-12).padEnd(4,i)).padEnd(4,"f")}-${u(e.substring(n,n+4).padEnd(4,i)).padEnd(4,"f")}${u(e.substring(n+4,n+8).padEnd(4,i)).padEnd(4,"f")}${u(i.padEnd(4,o).padEnd(4,i))}`}function g(e){return(Object.prototype.toString.call(e)||"").replace(/(\[object|\])/gi,"").trim()}const w={type(e,t){const n=g(e);return!0===t?n.toLocaleLowerCase():n},array:e=>"Array"===g(e),json:e=>"Object"===g(e),function:e=>"Function"===g(e),asyncFunction:e=>"AsyncFunction"===g(e),string:e=>"String"===g(e),number:e=>"Number"===g(e),undefined:e=>"Undefined"===g(e),null:e=>"Null"===g(e),promise:e=>"Promise"===g(e)};var v=function(e,t,n,o){return new(n||(n=Promise))((function(i,a){function l(e){try{s(o.next(e))}catch(e){a(e)}}function r(e){try{s(o.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,r)}s((o=o.apply(e,t||[])).next())}))};const{Image:m}=window;function y(e){return new Promise(((t,n)=>{const o=new m;o.crossOrigin="anonymous",o.onload=function(){t(o)},o.onabort=n,o.onerror=n,o.src=e}))}function p(e){return v(this,void 0,void 0,(function*(){const t=yield function(e){return new Promise(((t,n)=>{const o=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),i=new FileReader;i.readAsDataURL(o),i.onload=function(e){var n;const o=null===(n=null==e?void 0:e.target)||void 0===n?void 0:n.result;t(o)},i.onerror=function(e){n(e)}}))}(e);return yield y(t)}))}function x(e,t){return v(this,void 0,void 0,(function*(){e=e.replace(/\&/gi,"&");const n=yield function(e,t){const{width:n,height:o}=t;return new Promise(((t,i)=>{const a=new Blob([`\n <svg \n xmlns="http://www.w3.org/2000/svg" \n width="${n||""}" \n height = "${o||""}">\n <foreignObject width="100%" height="100%">\n <div xmlns = "http://www.w3.org/1999/xhtml">\n ${e}\n </div>\n </foreignObject>\n </svg>\n `],{type:"image/svg+xml;charset=utf-8"}),l=new FileReader;l.readAsDataURL(a),l.onload=function(e){var n;const o=null===(n=null==e?void 0:e.target)||void 0===n?void 0:n.result;t(o)},l.onerror=function(e){i(e)}}))}(e,t);return yield y(n)}))}function S(e){return"number"==typeof e&&(e>0||e<=0)}function b(e){return"number"==typeof e&&e>=0}function I(e){return"string"==typeof e&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${e}`)}function z(e){return"string"==typeof e&&/^(data:image\/)/.test(`${e}`)}const A={x:function(e){return S(e)},y:function(e){return S(e)},w:b,h:function(e){return"number"==typeof e&&e>=0},angle:function(e){return"number"==typeof e&&e>=-360&&e<=360},number:S,numberStr:function(e){return/^(-?\d+(?:\.\d+)?)$/.test(`${e}`)},borderWidth:function(e){return b(e)},borderRadius:function(e){return S(e)&&e>=0},color:function(e){return c(e)},imageSrc:function(e){return z(e)||I(e)},imageURL:I,imageBase64:z,svg:function(e){return"string"==typeof e&&/^(<svg[\s]{1,}|<svg>)/i.test(`${e}`.trim())&&/<\/[\s]{0,}svg>$/i.test(`${e}`.trim())},html:function(e){let t=!1;if("string"==typeof e){let n=document.createElement("div");n.innerHTML=e,n.children.length>0&&(t=!0),n=null}return t},text:function(e){return"string"==typeof e},fontSize:function(e){return S(e)&&e>0},lineHeight:function(e){return S(e)&&e>0},textAlign:function(e){return["center","left","right"].includes(e)},fontFamily:function(e){return"string"==typeof e&&e.length>0},fontWeight:function(e){return["bold"].includes(e)},strokeWidth:function(e){return S(e)&&e>0}};class T{constructor(){this._listeners=new Map}on(e,t){if(this._listeners.has(e)){const n=this._listeners.get(e)||[];null==n||n.push(t),this._listeners.set(e,n)}else this._listeners.set(e,[t])}off(e,t){if(this._listeners.has(e)){const n=this._listeners.get(e);if(Array.isArray(n))for(let e=0;e<(null==n?void 0:n.length);e++)if(n[e]===t){n.splice(e,1);break}this._listeners.set(e,n||[])}}trigger(e,t){const n=this._listeners.get(e);return!!Array.isArray(n)&&(n.forEach((e=>{e(t)})),!0)}has(e){if(this._listeners.has(e)){const t=this._listeners.get(e);if(Array.isArray(t)&&t.length>0)return!0}return!1}}function E(e,t,n,o){const i=function(e){return e/180*Math.PI}(t||0);n&&(i>0||i<0)&&(e.translate(n.x,n.y),e.rotate(i),e.translate(-n.x,-n.y)),o(e),n&&(i>0||i<0)&&(e.translate(n.x,n.y),e.rotate(-i),e.translate(-n.x,-n.y))}function C(e,t,n){const o={x:(i=t).x+i.w/2,y:i.y+i.h/2};var i;E(e,t.angle||0,o,(()=>{n(e)}))}function $(e){let t="";return e.forEach((e=>{t+=e.type+e.params.join(" ")})),t}const _={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,lineHeight:20,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};function P(e,t){const{viewScaleInfo:n}=t,{scale:o}=n;let{borderRadius:i}=e.detail;const{boxSizing:a=_.boxSizing,borderWidth:l}=e.detail;"number"!=typeof l&&(i=0);let{x:r,y:s,w:c,h:d}=e,h=[0,0,0,0];if("number"==typeof i){const e=i*o;h=[e,e,e,e]}else Array.isArray(i)&&4===(null==i?void 0:i.length)&&(h=[i[0]*o,i[1]*o,i[2]*o,i[3]*o]);let u=0;return"number"==typeof l&&(u=(l||0)*o),"border-box"===a?(r=e.x+u/2,s=e.y+u/2,c=e.w-u,d=e.h-u):"content-box"===a?(r=e.x-u/2,s=e.y-u/2,c=e.w+u,d=e.h+u):(r=e.x,s=e.y,c=e.w,d=e.h),c=Math.max(c,1),d=Math.max(d,1),h=h.map((e=>Math.min(e,c/2,d/2))),{x:r,y:s,w:c,h:d,radiusList:h}}function L(e,t,n){if("string"==typeof t)return t;const{viewElementSize:o,viewScaleInfo:i,opacity:a=1}=n,{x:l,y:r}=o,{scale:s}=i;if("linear-gradient"===(null==t?void 0:t.type)){const{start:n,end:o,stops:i}=t,c={x:l+n.x*s,y:r+n.y*s},h={x:l+o.x*s,y:r+o.y*s},u=e.createLinearGradient(c.x,c.y,h.x,h.y);return i.forEach((e=>{u.addColorStop(e.offset,d(e.color,a))})),u}if("radial-gradient"===(null==t?void 0:t.type)){const{inner:n,outer:o,stops:i}=t,c={x:l+n.x*s,y:r+n.y*s,radius:n.radius*s},h={x:l+o.x*s,y:r+o.y*s,radius:o.radius*s},u=e.createRadialGradient(c.x,c.y,c.radius,h.x,h.y,h.radius);return i.forEach((e=>{u.addColorStop(e.offset,d(e.color,a))})),u}return"#000000"}const k={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,lineHeight:20,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};function M(e,t,n){const{pattern:o,renderContent:i,originElem:a,calcElemSize:l,viewScaleInfo:r,viewSizeInfo:s}=n||{};!function(e,t,n){const{renderContent:o,originElem:i,calcElemSize:a,viewScaleInfo:l,viewSizeInfo:r}=n,s=l.scale*r.devicePixelRatio,{clipPath:c}=(null==i?void 0:i.detail)||{};if(c&&a&&c.commands){const{x:n,y:i,w:l,h:r}=a,{originW:d,originH:h,originX:u,originY:f}=c,g=l/d,w=r/h,v=n-u*g,m=i-f*w;e.save(),e.translate(v,m),e.scale(s*g,s*w);const y=$(c.commands||[]),p=new Path2D(y);e.clip(p),e.translate(0-v,0-m),e.setTransform(1,0,0,1,0,0),C(e,{...t},(()=>{null==o||o()})),e.restore()}else null==o||o()}(e,t,{originElem:a,calcElemSize:l,viewScaleInfo:r,viewSizeInfo:s,renderContent:()=>{var n,a;void 0!==(null==(n=null==t?void 0:t.detail)?void 0:n.opacity)&&(null==(a=null==t?void 0:t.detail)?void 0:a.opacity)>=0?e.globalAlpha=t.detail.opacity:e.globalAlpha=1,function(e,t,n){var o,i;const{pattern:a,viewScaleInfo:l,viewSizeInfo:r}=n,s=[];if(t.detail,t.detail,t.detail.background||a){const{x:n,y:c,w:d,h:h,radiusList:u}=P(t,{viewScaleInfo:l,viewSizeInfo:r});if(e.beginPath(),e.moveTo(n+u[0],c),e.arcTo(n+d,c,n+d,c+h,u[1]),e.arcTo(n+d,c+h,n,c+h,u[2]),e.arcTo(n,c+h,n,c,u[3]),e.arcTo(n,c,n+d,c,u[0]),e.closePath(),"string"==typeof a)e.fillStyle=a;else if(["CanvasPattern"].includes(w.type(a)))e.fillStyle=a;else if("string"==typeof t.detail.background)e.fillStyle=t.detail.background;else if("linear-gradient"===(null==(o=t.detail.background)?void 0:o.type)){const o=L(e,t.detail.background,{viewElementSize:{x:n,y:c,w:d,h:h},viewScaleInfo:l,opacity:e.globalAlpha});e.fillStyle=o}else if("radial-gradient"===(null==(i=t.detail.background)?void 0:i.type)){const o=L(e,t.detail.background,{viewElementSize:{x:n,y:c,w:d,h:h},viewScaleInfo:l,opacity:e.globalAlpha});if(e.fillStyle=o,s&&s.length>0)for(let t=0;t<(null==s?void 0:s.length);t++){const o=s[t];"translate"===o.method?e.translate(o.args[0]+n,o.args[1]+c):"rotate"===o.method?e.rotate(...o.args):"scale"===o.method&&e.scale(...o.args)}}e.fill(),s&&s.length>0&&e.setTransform(1,0,0,1,0,0)}}(e,t,{pattern:o,viewScaleInfo:r,viewSizeInfo:s}),null==i||i(),function(e,t,n){var o,i;if(0===t.detail.borderWidth)return;if(!c(t.detail.borderColor))return;void 0!==(null==(o=null==t?void 0:t.detail)?void 0:o.opacity)&&(null==(i=null==t?void 0:t.detail)?void 0:i.opacity)>=0?e.globalAlpha=t.detail.opacity:e.globalAlpha=1;const{viewScaleInfo:a}=n,{scale:l}=a;let r=k.borderColor;!0===c(t.detail.borderColor)&&(r=t.detail.borderColor);const{borderWidth:s,borderRadius:d,borderDash:h,boxSizing:u=k.boxSizing}=t.detail;let f=0;"number"==typeof s&&(f=s||1);f*=l;let g=[0,0,0,0];if("number"==typeof d){const e=d*l;g=[e,e,e,e]}else Array.isArray(d)&&4===(null==d?void 0:d.length)&&(g=[d[0]*l,d[1]*l,d[2]*l,d[3]*l]);e.strokeStyle=r;let w=[];Array.isArray(h)&&h.length>0&&(w=h.map((e=>Math.ceil(e*l))));let v=0,m=0,y=0,p=0;Array.isArray(s)&&(v=(s[0]||0)*l,m=(s[1]||0)*l,y=(s[2]||0)*l,p=(s[3]||0)*l);if(p||m||v||y){e.lineCap="butt";let{x:n,y:o,w:i,h:a}=t;"border-box"===u?(n+=p/2,o+=v/2,i=i-p/2-m/2,a=a-v/2-y/2):"content-box"===u?(n-=p/2,o-=v/2,i=i+p/2+m/2,a=a+v/2+y/2):(n=t.x,o=t.y,i=t.w,a=t.h),v&&(e.beginPath(),e.lineWidth=v,e.moveTo(n-p/2,o),e.lineTo(n+i+m/2,o),e.closePath(),e.stroke()),m&&(e.beginPath(),e.lineWidth=m,e.moveTo(n+i,o-v/2),e.lineTo(n+i,o+a+y/2),e.closePath(),e.stroke()),y&&(e.beginPath(),e.lineWidth=y,e.moveTo(n-p/2,o+a),e.lineTo(n+i+m/2,o+a),e.closePath(),e.stroke()),p&&(e.beginPath(),e.lineWidth=p,e.moveTo(n,o-v/2),e.lineTo(n,o+a+y/2),e.closePath(),e.stroke())}else{let{x:n,y:o,w:i,h:a}=t;"border-box"===u?(n=t.x+f/2,o=t.y+f/2,i=t.w-f,a=t.h-f):"content-box"===u?(n=t.x-f/2,o=t.y-f/2,i=t.w+f,a=t.h+f):(n=t.x,o=t.y,i=t.w,a=t.h),w.length>0?e.lineCap="butt":e.lineCap="square",i=Math.max(i,1),a=Math.max(a,1),g=g.map((e=>Math.min(e,i/2,a/2))),e.setLineDash(w),e.lineWidth=f,e.beginPath(),e.moveTo(n+g[0],o),e.arcTo(n+i,o,n+i,o+a,g[1]),e.arcTo(n+i,o+a,n,o+a,g[2]),e.arcTo(n,o+a,n,o,g[3]),e.arcTo(n,o,n+i,o,g[0]),e.closePath(),e.stroke(),e.globalAlpha=1}e.setLineDash([])}(e,t,{viewScaleInfo:r,viewSizeInfo:s}),e.globalAlpha=1}})}function W(e,t,n){const{detail:o}=t,{viewScaleInfo:i,renderContent:a}=n,{shadowColor:l,shadowOffsetX:r,shadowOffsetY:s,shadowBlur:c}=o;A.number(c)?(e.save(),e.shadowColor=l||k.shadowColor,e.shadowOffsetX=(r||0)*i.scale,e.shadowOffsetY=(s||0)*i.scale,e.shadowBlur=(c||0)*i.scale,a(),e.restore()):a()}const R={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,lineHeight:20,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};function O(e,t,n){var o;if(!0!==(null==(o=null==t?void 0:t.operations)?void 0:o.invisible))try{switch(t.type){case"rect":!function(e,t,n){const{calculator:o,viewScaleInfo:i,viewSizeInfo:a}=n,{x:l,y:r,w:s,h:c,angle:d}=(null==o?void 0:o.elementSize(t,i,a))||t,h={...t,x:l,y:r,w:s,h:c,angle:d};C(e,{x:l,y:r,w:s,h:c,angle:d},(()=>{W(e,h,{viewScaleInfo:i,viewSizeInfo:a,renderContent:()=>{M(e,h,{originElem:t,calcElemSize:{x:l,y:r,w:s,h:c,angle:d},viewScaleInfo:i,viewSizeInfo:a,renderContent:()=>{}})}})}))}(e,t,n);break;case"circle":!function(e,t,n){const{detail:o,angle:i}=t,{background:a="#000000",borderColor:l="#000000",borderWidth:r=0}=o,{calculator:s,viewScaleInfo:c,viewSizeInfo:d}=n,{x:h,y:u,w:f,h:g}=(null==s?void 0:s.elementSize({x:t.x,y:t.y,w:t.w,h:t.h},c,d))||t,w={...t,x:h,y:u,w:f,h:g,angle:i};C(e,{x:h,y:u,w:f,h:g,angle:i},(()=>{W(e,w,{viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{var n,o;const i=f/2,s=g/2,d=h+i,w=u+s;if(void 0!==(null==(n=null==t?void 0:t.detail)?void 0:n.opacity)&&(null==(o=null==t?void 0:t.detail)?void 0:o.opacity)>=0?e.globalAlpha=t.detail.opacity:e.globalAlpha=1,"number"==typeof r&&r>0){const t=r/2+i,n=r/2+s;e.beginPath(),e.strokeStyle=l,e.lineWidth=r,e.circle(d,w,t,n,0,0,2*Math.PI),e.closePath(),e.stroke()}e.beginPath();const v=L(e,a,{viewElementSize:{x:h,y:u,w:f,h:g},viewScaleInfo:c,opacity:e.globalAlpha});e.fillStyle=v,e.circle(d,w,i,s,0,0,2*Math.PI),e.closePath(),e.fill(),e.globalAlpha=1}})}))}(e,t,n);break;case"text":!function(e,t,n){const{calculator:o,viewScaleInfo:i,viewSizeInfo:a}=n,{x:l,y:r,w:s,h:d,angle:h}=(null==o?void 0:o.elementSize(t,i,a))||t,u={...t,x:l,y:r,w:s,h:d,angle:h};C(e,{x:l,y:r,w:s,h:d,angle:h},(()=>{M(e,u,{originElem:t,calcElemSize:{x:l,y:r,w:s,h:d,angle:h},viewScaleInfo:i,viewSizeInfo:a,renderContent:()=>{const n={...R,...t.detail},o=(n.fontSize||R.fontSize)*i.scale,a=n.lineHeight?n.lineHeight*i.scale:o;e.fillStyle=t.detail.color||R.color,e.textBaseline="top",e.$setFont({fontWeight:n.fontWeight,fontSize:o,fontFamily:n.fontFamily});const h=n.text.replace(/\r\n/gi,"\n"),u=a,f=h.split("\n"),g=[];let w=0;f.forEach(((t,n)=>{let o="";if(t.length>0){for(let i=0;i<t.length&&(e.measureText(o+(t[i]||"")).width<e.$doPixelRatio(s)?o+=t[i]||"":(g.push({text:o,width:e.$undoPixelRatio(e.measureText(o).width)}),o=t[i]||"",w++),!((w+1)*u>d));i++)if(t.length-1===i&&(w+1)*u<d){g.push({text:o,width:e.$undoPixelRatio(e.measureText(o).width)}),n<f.length-1&&w++;break}}else g.push({text:"",width:0})}));let v=0;g.length*u<d&&("top"===t.detail.verticalAlign?v=0:"bottom"===t.detail.verticalAlign?v+=d-g.length*u:v+=(d-g.length*u)/2);{const t=r+v;void 0!==n.textShadowColor&&c(n.textShadowColor)&&(e.shadowColor=n.textShadowColor),void 0!==n.textShadowOffsetX&&A.number(n.textShadowOffsetX)&&(e.shadowOffsetX=n.textShadowOffsetX),void 0!==n.textShadowOffsetY&&A.number(n.textShadowOffsetY)&&(e.shadowOffsetY=n.textShadowOffsetY),void 0!==n.textShadowBlur&&A.number(n.textShadowBlur)&&(e.shadowBlur=n.textShadowBlur),g.forEach(((o,i)=>{let a=l;"center"===n.textAlign?a=l+(s-o.width)/2:"right"===n.textAlign&&(a=l+(s-o.width)),e.fillText(o.text,a,t+u*i)}))}}})}))}(e,t,n);break;case"image":!function(e,t,n){const o=n.loader.getContent(t),{calculator:i,viewScaleInfo:a,viewSizeInfo:l}=n,{x:r,y:s,w:c,h:d,angle:h}=(null==i?void 0:i.elementSize(t,a,l))||t,u={...t,x:r,y:s,w:c,h:d,angle:h};C(e,{x:r,y:s,w:c,h:d,angle:h},(()=>{W(e,u,{viewScaleInfo:a,viewSizeInfo:l,renderContent:()=>{M(e,u,{originElem:t,calcElemSize:{x:r,y:s,w:c,h:d,angle:h},viewScaleInfo:a,viewSizeInfo:l,renderContent:()=>{if(o||n.loader.load(t,n.elementAssets||{}),"image"===t.type&&o){const{opacity:n}=t.detail;e.globalAlpha=n||1;const{x:i,y:r,w:s,h:c,radiusList:d}=P(u,{viewScaleInfo:a,viewSizeInfo:l});e.save(),e.fillStyle="transparent",e.beginPath(),e.moveTo(i+d[0],r),e.arcTo(i+s,r,i+s,r+c,d[1]),e.arcTo(i+s,r+c,i,r+c,d[2]),e.arcTo(i,r+c,i,r,d[3]),e.arcTo(i,r,i+s,r,d[0]),e.closePath(),e.fill(),e.clip(),e.drawImage(o,i,r,s,c),e.globalAlpha=1,e.restore()}}})}})}))}(e,t,n);break;case"svg":!function(e,t,n){const o=n.loader.getContent(t),{calculator:i,viewScaleInfo:a,viewSizeInfo:l}=n,{x:r,y:s,w:c,h:d,angle:h}=(null==i?void 0:i.elementSize(t,a,l))||t;C(e,{x:r,y:s,w:c,h:d,angle:h},(()=>{if(o||n.loader.load(t,n.elementAssets||{}),"svg"===t.type&&o){const{opacity:n}=t.detail;e.globalAlpha=n||1,e.drawImage(o,r,s,c,d),e.globalAlpha=1}}))}(e,t,n);break;case"html":!function(e,t,n){const o=n.loader.getContent(t),{calculator:i,viewScaleInfo:a,viewSizeInfo:l}=n,{x:r,y:s,w:c,h:d,angle:h}=(null==i?void 0:i.elementSize(t,a,l))||t;C(e,{x:r,y:s,w:c,h:d,angle:h},(()=>{if(o||n.loader.load(t,n.elementAssets||{}),"html"===t.type&&o){const{opacity:n}=t.detail;e.globalAlpha=n||1,e.drawImage(o,r,s,c,d),e.globalAlpha=1}}))}(e,t,n);break;case"path":!function(e,t,n){const{detail:o}=t,{originX:i,originY:a,originW:l,originH:r}=o,{calculator:s,viewScaleInfo:c,viewSizeInfo:d}=n,{x:h,y:u,w:f,h:g,angle:w}=(null==s?void 0:s.elementSize(t,c,d))||t,v=f/l,m=g/r,y=h-i*v,p=u-a*m,x=c.scale*d.devicePixelRatio,S={...t,x:h,y:u,w:f,h:g,angle:w};C(e,{x:h,y:u,w:f,h:g,angle:w},(()=>{M(e,S,{originElem:t,calcElemSize:{x:h,y:u,w:f,h:g,angle:w},viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{W(e,S,{viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{e.save(),e.translate(y,p),e.scale(x*v/c.scale,x*m/c.scale);const t=$(o.commands||[]),n=new Path2D(t);o.fill&&(e.fillStyle=o.fill,e.fill(n)),o.stroke&&0!==o.strokeWidth&&(e.strokeStyle=o.stroke,e.lineWidth=(o.strokeWidth||1)/d.devicePixelRatio,e.lineCap=o.strokeLineCap||"square",e.stroke(n)),e.translate(-y,-p),e.restore()}})}})}))}(e,t,n);break;case"group":{const o={...n.elementAssets||{},...t.detail.assets||{}};!function(e,t,n){const{calculator:o,viewScaleInfo:i,viewSizeInfo:a}=n,{x:l,y:r,w:s,h:c,angle:d}=(null==o?void 0:o.elementSize({x:t.x,y:t.y,w:t.w,h:t.h,angle:t.angle},i,a))||t,h={...t,x:l,y:r,w:s,h:c,angle:d};C(e,{x:l,y:r,w:s,h:c,angle:d},(()=>{W(e,h,{viewScaleInfo:i,viewSizeInfo:a,renderContent:()=>{M(e,h,{originElem:t,calcElemSize:{x:l,y:r,w:s,h:c,angle:d},viewScaleInfo:i,viewSizeInfo:a,renderContent:()=>{const{x:o,y:l,w:r,h:s,radiusList:c}=P(h,{viewScaleInfo:i,viewSizeInfo:a});if("hidden"===t.detail.overflow&&(e.save(),e.fillStyle="transparent",e.beginPath(),e.moveTo(o+c[0],l),e.arcTo(o+r,l,o+r,l+s,c[1]),e.arcTo(o+r,l+s,o,l+s,c[2]),e.arcTo(o,l+s,o,l,c[3]),e.arcTo(o,l,o+r,l,c[0]),e.closePath(),e.fill(),e.clip()),Array.isArray(t.detail.children)){const{parentElementSize:o}=n,i={x:o.x+t.x,y:o.y+t.y,w:t.w||o.w,h:t.h||o.h,angle:t.angle},{calculator:a}=n;for(let o=0;o<t.detail.children.length;o++){let l=t.detail.children[o];if(l={...l,x:i.x+l.x,y:i.y+l.y},!0===n.forceDrawAll||(null==a?void 0:a.isElementInView(l,n.viewScaleInfo,n.viewSizeInfo)))try{O(e,l,{...n})}catch(e){console.error(e)}}}"hidden"===t.detail.overflow&&(e.globalAlpha=1,e.restore())}})}})}))}(e,t,{...n,elementAssets:o});break}}}catch(e){console.error(e)}}const D={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,lineHeight:20,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};const F=["image","svg","html"],B=e=>{var t,n,o;let i=null;return"image"===e.type?i=(null==(t=null==e?void 0:e.detail)?void 0:t.src)||null:"svg"===e.type?i=(null==(n=null==e?void 0:e.detail)?void 0:n.svg)||null:"html"===e.type&&(i=(null==(o=null==e?void 0:e.detail)?void 0:o.html)||null),"string"==typeof i&&i?/^@assets\/[0-9a-z]{8,8}\-[0-9a-z]{4,4}\-[0-9a-z]{4,4}\-[0-9a-z]{4,4}\-[0-9a-z]{12,12}$/.test(`${i}`)?i:f(i):f(`${h()}-${e.uuid}-${h()}-${h()}`)};class H extends T{constructor(){super(),this._loadFuncMap={},this._currentLoadItemMap={},this._storageLoadItemMap={},this._registerLoadFunc("image",(async(e,t)=>{var n;const o=(null==(n=t[e.detail.src])?void 0:n.value)||e.detail.src,i=await y(o);return{uuid:e.uuid,lastModified:Date.now(),content:i}})),this._registerLoadFunc("html",(async(e,t)=>{var n;const o=(null==(n=t[e.detail.html])?void 0:n.value)||e.detail.html,i=await x(o,{width:e.detail.width||e.w,height:e.detail.height||e.h});return{uuid:e.uuid,lastModified:Date.now(),content:i}})),this._registerLoadFunc("svg",(async(e,t)=>{var n;const o=(null==(n=t[e.detail.svg])?void 0:n.value)||e.detail.svg,i=await p(o);return{uuid:e.uuid,lastModified:Date.now(),content:i}}))}_registerLoadFunc(e,t){this._loadFuncMap[e]=t}_getLoadElementSource(e){var t,n,o;let i=null;return"image"===e.type?i=(null==(t=null==e?void 0:e.detail)?void 0:t.src)||null:"svg"===e.type?i=(null==(n=null==e?void 0:e.detail)?void 0:n.svg)||null:"html"===e.type&&(i=(null==(o=null==e?void 0:e.detail)?void 0:o.html)||null),i}_createLoadItem(e){return{element:e,status:"null",content:null,error:null,startTime:-1,endTime:-1,source:this._getLoadElementSource(e)}}_emitLoad(e){const t=B(e.element),n=this._storageLoadItemMap[t];n?n.startTime<e.startTime&&(this._storageLoadItemMap[t]=e,this.trigger("load",{...e,countTime:e.endTime-e.startTime})):(this._storageLoadItemMap[t]=e,this.trigger("load",{...e,countTime:e.endTime-e.startTime}))}_emitError(e){const t=B(e.element),n=this._storageLoadItemMap[t];n?n.startTime<e.startTime&&(this._storageLoadItemMap[t]=e,this.trigger("error",{...e,countTime:e.endTime-e.startTime})):(this._storageLoadItemMap[t]=e,this.trigger("error",{...e,countTime:e.endTime-e.startTime}))}_loadResource(e,t){const n=this._createLoadItem(e),o=B(e);this._currentLoadItemMap[o]=n;const i=this._loadFuncMap[e.type];"function"==typeof i&&(n.startTime=Date.now(),i(e,t).then((e=>{n.content=e.content,n.endTime=Date.now(),n.status="load",this._emitLoad(n)})).catch((t=>{console.warn(`Load element source "${n.source}" fail`,t,e),n.endTime=Date.now(),n.status="error",n.error=t,this._emitError(n)})))}_isExistingErrorStorage(e){var t;const n=B(e),o=null==(t=this._currentLoadItemMap)?void 0:t[n];return!(!o||"error"!==o.status||!o.source||o.source!==this._getLoadElementSource(e))}load(e,t){this._isExistingErrorStorage(e)||F.includes(e.type)&&this._loadResource(e,t)}getContent(e){var t,n;const o=B(e);return(null==(n=null==(t=this._storageLoadItemMap)?void 0:t[o])?void 0:n.content)||null}}return t=new WeakMap,n=new WeakMap,o=new WeakSet,i=function(){const e=l(this,n);e.on("load",(e=>{this.trigger("load",e)})),e.on("error",(()=>{}))},e.Renderer=class extends T{constructor(e){var l,c,d;super(),r(this,o),r(this,t,void 0),r(this,n,new H),s(this,t,e),(l=this,c=o,d=i,a(l,c,"access private method"),d).call(this)}updateOptions(e){s(this,t,e)}drawData(e,o){const i=l(this,n),{calculator:a}=l(this,t),r=l(this,t).viewContext;r.clearRect(0,0,r.canvas.width,r.canvas.height);!function(e,t,n){var o;const{elements:i=[]}=t;for(let t=0;t<i.length;t++){const a=i[t],l={...a,detail:{...D,...null==a?void 0:a.detail}};if(!0===n.forceDrawAll||(null==(o=n.calculator)?void 0:o.isElementInView(l,n.viewScaleInfo,n.viewSizeInfo)))try{O(e,l,n)}catch(e){console.error(e)}}}(r,e,{loader:i,calculator:a,parentElementSize:{x:0,y:0,w:o.viewSizeInfo.width,h:o.viewSizeInfo.height},elementAssets:e.assets,...o})}scale(e){const{sharer:n}=l(this,t);if(!n)return;const{data:o,offsetTop:i,offsetBottom:a,offsetLeft:r,offsetRight:s,width:c,height:d,contextHeight:h,contextWidth:u,devicePixelRatio:f}=n.getActiveStoreSnapshot();o&&this.drawData(o,{viewScaleInfo:{scale:e,offsetTop:i,offsetBottom:a,offsetLeft:r,offsetRight:s},viewSizeInfo:{width:c,height:d,contextHeight:h,contextWidth:u,devicePixelRatio:f}})}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});
|
|
1
|
+
var iDrawRenderer=function(e){"use strict";var t,n,i,o,l,a,r,s,c,d,h,f,u,g,w,v,y,m,p,S,x,b=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},I=(e,t,n)=>(b(e,t,"read from private field"),n?n.call(e):t.get(e)),z=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},A=(e,t,n,i)=>(b(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),T=(e,t,n)=>(b(e,t,"access private method"),n);function C(e){return"string"==typeof e&&(/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e)||/^[a-z]{1,}$/i.test(e))}function E(e,t){if(1===t)return e;let n=1;const i=/^\#[0-9a-f]{6,6}$/i;let o=e;if(i.test(e)?n=parseInt(e.substring(5,7).replace(/^\#/,"0x")):/^\#[0-9a-f]{8,8}$/i.test(e)&&(n=parseInt(e.substring(7,9).replace(/^\#/,"0x")),o=e.substring(0,7)),n*=t,i.test(o)&&n>0&&n<1){const e=Math.max(0,Math.min(255,Math.ceil(256*n)));o=`${o.toUpperCase()}${e.toString(16).toUpperCase()}`}return o}function k(){function e(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${e()}${e()}-${e()}-${e()}-${e()}-${e()}${e()}${e()}`}function W(e){let t=0;for(let n=0;n<e.length;n++)t+=e.charCodeAt(n)*e.charCodeAt(n)*n*n;return t.toString(16).substring(0,4)}function $(e){const t=e.length,n=Math.floor(t/2),i=e.substring(0,4).padEnd(4,"0"),o=e.substring(0,4).padEnd(4,"0");return`@assets/${W(t.toString(16).padEnd(4,i))}${W(e.substring(n-4,n).padEnd(4,i)).padEnd(4,"f")}-${W(e.substring(n-8,n-4).padEnd(4,i)).padEnd(4,"f")}-${W(e.substring(n-12,n-8).padEnd(4,i)).padEnd(4,"f")}-${W(e.substring(n-16,n-12).padEnd(4,o)).padEnd(4,"f")}-${W(e.substring(n,n+4).padEnd(4,o)).padEnd(4,"f")}${W(e.substring(n+4,n+8).padEnd(4,o)).padEnd(4,"f")}${W(o.padEnd(4,i).padEnd(4,o))}`}function P(e){return(Object.prototype.toString.call(e)||"").replace(/(\[object|\])/gi,"").trim()}const M={type(e,t){const n=P(e);return!0===t?n.toLocaleLowerCase():n},array:e=>"Array"===P(e),json:e=>"Object"===P(e),function:e=>"Function"===P(e),asyncFunction:e=>"AsyncFunction"===P(e),string:e=>"String"===P(e),number:e=>"Number"===P(e),undefined:e=>"Undefined"===P(e),null:e=>"Null"===P(e),promise:e=>"Promise"===P(e)};var O=function(e,t,n,i){return new(n||(n=Promise))((function(o,l){function a(e){try{s(i.next(e))}catch(e){l(e)}}function r(e){try{s(i.throw(e))}catch(e){l(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}s((i=i.apply(e,t||[])).next())}))};const{Image:R}=window;function L(e){return new Promise(((t,n)=>{const i=new R;i.crossOrigin="anonymous",i.onload=function(){t(i)},i.onabort=n,i.onerror=n,i.src=e}))}function D(e){return O(this,void 0,void 0,(function*(){const t=yield function(e){return new Promise(((t,n)=>{const i=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),o=new FileReader;o.readAsDataURL(i),o.onload=function(e){var n;const i=null===(n=null==e?void 0:e.target)||void 0===n?void 0:n.result;t(i)},o.onerror=function(e){n(e)}}))}(e);return yield L(t)}))}function B(e,t){return O(this,void 0,void 0,(function*(){e=e.replace(/\&/gi,"&");const n=yield function(e,t){const{width:n,height:i}=t;return new Promise(((t,o)=>{const l=new Blob([`\n <svg \n xmlns="http://www.w3.org/2000/svg" \n width="${n||""}" \n height = "${i||""}">\n <foreignObject width="100%" height="100%">\n <div xmlns = "http://www.w3.org/1999/xhtml">\n ${e}\n </div>\n </foreignObject>\n </svg>\n `],{type:"image/svg+xml;charset=utf-8"}),a=new FileReader;a.readAsDataURL(l),a.onload=function(e){var n;const i=null===(n=null==e?void 0:e.target)||void 0===n?void 0:n.result;t(i)},a.onerror=function(e){o(e)}}))}(e,t);return yield L(n)}))}function F(e){return"number"==typeof e&&(e>0||e<=0)}function H(e){return"number"==typeof e&&e>=0}function X(e){return"string"==typeof e&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${e}`)}function Y(e){return"string"==typeof e&&/^(data:image\/)/.test(`${e}`)}const _={x:function(e){return F(e)},y:function(e){return F(e)},w:H,h:function(e){return"number"==typeof e&&e>=0},angle:function(e){return"number"==typeof e&&e>=-360&&e<=360},number:F,numberStr:function(e){return/^(-?\d+(?:\.\d+)?)$/.test(`${e}`)},borderWidth:function(e){return H(e)},borderRadius:function(e){return F(e)&&e>=0},color:function(e){return C(e)},imageSrc:function(e){return Y(e)||X(e)},imageURL:X,imageBase64:Y,svg:function(e){return"string"==typeof e&&/^(<svg[\s]{1,}|<svg>)/i.test(`${e}`.trim())&&/<\/[\s]{0,}svg>$/i.test(`${e}`.trim())},html:function(e){let t=!1;if("string"==typeof e){let n=document.createElement("div");n.innerHTML=e,n.children.length>0&&(t=!0),n=null}return t},text:function(e){return"string"==typeof e},fontSize:function(e){return F(e)&&e>0},lineHeight:function(e){return F(e)&&e>0},textAlign:function(e){return["center","left","right"].includes(e)},fontFamily:function(e){return"string"==typeof e&&e.length>0},fontWeight:function(e){return["bold"].includes(e)},strokeWidth:function(e){return F(e)&&e>0}};class j{constructor(){this._listeners=new Map}on(e,t){if(this._listeners.has(e)){const n=this._listeners.get(e)||[];null==n||n.push(t),this._listeners.set(e,n)}else this._listeners.set(e,[t])}off(e,t){if(this._listeners.has(e)){const n=this._listeners.get(e);if(Array.isArray(n))for(let e=0;e<(null==n?void 0:n.length);e++)if(n[e]===t){n.splice(e,1);break}this._listeners.set(e,n||[])}}trigger(e,t){const n=this._listeners.get(e);return!!Array.isArray(n)&&(n.forEach((e=>{e(t)})),!0)}has(e){if(this._listeners.has(e)){const t=this._listeners.get(e);if(Array.isArray(t)&&t.length>0)return!0}return!1}}function U(e,t,n,i){const o=function(e){return e/180*Math.PI}(t||0);n&&(o>0||o<0)&&(e.translate(n.x,n.y),e.rotate(o),e.translate(-n.x,-n.y)),i(e),n&&(o>0||o<0)&&(e.translate(n.x,n.y),e.rotate(-o),e.translate(-n.x,-n.y))}function q(e,t,n){const i={x:(o=t).x+o.w/2,y:o.y+o.h/2};var o;U(e,t.angle||0,i,(()=>{n(e)}))}function G(e){let t="";return e.forEach((e=>{t+=e.type+e.params.join(" ")})),t}const N={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,lineHeight:20,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};function V(e,t){const{viewScaleInfo:n}=t,{scale:i}=n;let{borderRadius:o}=e.detail;const{boxSizing:l=N.boxSizing,borderWidth:a}=e.detail;"number"!=typeof a&&(o=0);let{x:r,y:s,w:c,h:d}=e,h=[0,0,0,0];if("number"==typeof o){const e=o*i;h=[e,e,e,e]}else Array.isArray(o)&&4===(null==o?void 0:o.length)&&(h=[o[0]*i,o[1]*i,o[2]*i,o[3]*i]);let f=0;return"number"==typeof a&&(f=(a||0)*i),"border-box"===l?(r=e.x+f/2,s=e.y+f/2,c=e.w-f,d=e.h-f):"content-box"===l?(r=e.x-f/2,s=e.y-f/2,c=e.w+f,d=e.h+f):(r=e.x,s=e.y,c=e.w,d=e.h),c=Math.max(c,1),d=Math.max(d,1),h=h.map((e=>Math.min(e,c/2,d/2))),{x:r,y:s,w:c,h:d,radiusList:h}}function J(e,t,n){if("string"==typeof t)return t;const{viewElementSize:i,viewScaleInfo:o,opacity:l=1}=n,{x:a,y:r}=i,{scale:s}=o;if("linear-gradient"===(null==t?void 0:t.type)){const{start:n,end:i,stops:o}=t,c={x:a+n.x*s,y:r+n.y*s},d={x:a+i.x*s,y:r+i.y*s},h=e.createLinearGradient(c.x,c.y,d.x,d.y);return o.forEach((e=>{h.addColorStop(e.offset,E(e.color,l))})),h}if("radial-gradient"===(null==t?void 0:t.type)){const{inner:n,outer:i,stops:o}=t,c={x:a+n.x*s,y:r+n.y*s,radius:n.radius*s},d={x:a+i.x*s,y:r+i.y*s,radius:i.radius*s},h=e.createRadialGradient(c.x,c.y,c.radius,d.x,d.y,d.radius);return o.forEach((e=>{h.addColorStop(e.offset,E(e.color,l))})),h}return"#000000"}const K={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,lineHeight:20,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};function Q(e,t,n){const{pattern:i,renderContent:o,originElem:l,calcElemSize:a,viewScaleInfo:r,viewSizeInfo:s}=n||{};!function(e,t,n){const{renderContent:i,originElem:o,calcElemSize:l,viewScaleInfo:a,viewSizeInfo:r}=n,s=a.scale*r.devicePixelRatio,{clipPath:c}=(null==o?void 0:o.detail)||{};if(c&&l&&c.commands){const{x:n,y:o,w:a,h:r}=l,{originW:d,originH:h,originX:f,originY:u}=c,g=a/d,w=r/h,v=n-f*g,y=o-u*w;e.save(),e.translate(v,y),e.scale(s*g,s*w);const m=G(c.commands||[]),p=new Path2D(m);e.clip(p),e.translate(0-v,0-y),e.setTransform(1,0,0,1,0,0),q(e,{...t},(()=>{null==i||i()})),e.restore()}else null==i||i()}(e,t,{originElem:l,calcElemSize:a,viewScaleInfo:r,viewSizeInfo:s,renderContent:()=>{var n,l;void 0!==(null==(n=null==t?void 0:t.detail)?void 0:n.opacity)&&(null==(l=null==t?void 0:t.detail)?void 0:l.opacity)>=0?e.globalAlpha=t.detail.opacity:e.globalAlpha=1,function(e,t,n){var i,o;const{pattern:l,viewScaleInfo:a,viewSizeInfo:r}=n,s=[];if(t.detail,t.detail,t.detail.background||l){const{x:n,y:c,w:d,h:h,radiusList:f}=V(t,{viewScaleInfo:a,viewSizeInfo:r});if(e.beginPath(),e.moveTo(n+f[0],c),e.arcTo(n+d,c,n+d,c+h,f[1]),e.arcTo(n+d,c+h,n,c+h,f[2]),e.arcTo(n,c+h,n,c,f[3]),e.arcTo(n,c,n+d,c,f[0]),e.closePath(),"string"==typeof l)e.fillStyle=l;else if(["CanvasPattern"].includes(M.type(l)))e.fillStyle=l;else if("string"==typeof t.detail.background)e.fillStyle=t.detail.background;else if("linear-gradient"===(null==(i=t.detail.background)?void 0:i.type)){const i=J(e,t.detail.background,{viewElementSize:{x:n,y:c,w:d,h:h},viewScaleInfo:a,opacity:e.globalAlpha});e.fillStyle=i}else if("radial-gradient"===(null==(o=t.detail.background)?void 0:o.type)){const i=J(e,t.detail.background,{viewElementSize:{x:n,y:c,w:d,h:h},viewScaleInfo:a,opacity:e.globalAlpha});if(e.fillStyle=i,s&&s.length>0)for(let t=0;t<(null==s?void 0:s.length);t++){const i=s[t];"translate"===i.method?e.translate(i.args[0]+n,i.args[1]+c):"rotate"===i.method?e.rotate(...i.args):"scale"===i.method&&e.scale(...i.args)}}e.fill(),s&&s.length>0&&e.setTransform(1,0,0,1,0,0)}}(e,t,{pattern:i,viewScaleInfo:r,viewSizeInfo:s}),null==o||o(),function(e,t,n){var i,o;if(0===t.detail.borderWidth)return;if(!C(t.detail.borderColor))return;void 0!==(null==(i=null==t?void 0:t.detail)?void 0:i.opacity)&&(null==(o=null==t?void 0:t.detail)?void 0:o.opacity)>=0?e.globalAlpha=t.detail.opacity:e.globalAlpha=1;const{viewScaleInfo:l}=n,{scale:a}=l;let r=K.borderColor;!0===C(t.detail.borderColor)&&(r=t.detail.borderColor);const{borderWidth:s,borderRadius:c,borderDash:d,boxSizing:h=K.boxSizing}=t.detail;let f=0;"number"==typeof s&&(f=s||1);f*=a;let u=[0,0,0,0];if("number"==typeof c){const e=c*a;u=[e,e,e,e]}else Array.isArray(c)&&4===(null==c?void 0:c.length)&&(u=[c[0]*a,c[1]*a,c[2]*a,c[3]*a]);e.strokeStyle=r;let g=[];Array.isArray(d)&&d.length>0&&(g=d.map((e=>Math.ceil(e*a))));let w=0,v=0,y=0,m=0;Array.isArray(s)&&(w=(s[0]||0)*a,v=(s[1]||0)*a,y=(s[2]||0)*a,m=(s[3]||0)*a);if(m||v||w||y){e.lineCap="butt";let{x:n,y:i,w:o,h:l}=t;"border-box"===h?(n+=m/2,i+=w/2,o=o-m/2-v/2,l=l-w/2-y/2):"content-box"===h?(n-=m/2,i-=w/2,o=o+m/2+v/2,l=l+w/2+y/2):(n=t.x,i=t.y,o=t.w,l=t.h),w&&(e.beginPath(),e.lineWidth=w,e.moveTo(n-m/2,i),e.lineTo(n+o+v/2,i),e.closePath(),e.stroke()),v&&(e.beginPath(),e.lineWidth=v,e.moveTo(n+o,i-w/2),e.lineTo(n+o,i+l+y/2),e.closePath(),e.stroke()),y&&(e.beginPath(),e.lineWidth=y,e.moveTo(n-m/2,i+l),e.lineTo(n+o+v/2,i+l),e.closePath(),e.stroke()),m&&(e.beginPath(),e.lineWidth=m,e.moveTo(n,i-w/2),e.lineTo(n,i+l+y/2),e.closePath(),e.stroke())}else{let{x:n,y:i,w:o,h:l}=t;"border-box"===h?(n=t.x+f/2,i=t.y+f/2,o=t.w-f,l=t.h-f):"content-box"===h?(n=t.x-f/2,i=t.y-f/2,o=t.w+f,l=t.h+f):(n=t.x,i=t.y,o=t.w,l=t.h),g.length>0?e.lineCap="butt":e.lineCap="square",o=Math.max(o,1),l=Math.max(l,1),u=u.map((e=>Math.min(e,o/2,l/2))),e.setLineDash(g),e.lineWidth=f,e.beginPath(),e.moveTo(n+u[0],i),e.arcTo(n+o,i,n+o,i+l,u[1]),e.arcTo(n+o,i+l,n,i+l,u[2]),e.arcTo(n,i+l,n,i,u[3]),e.arcTo(n,i,n+o,i,u[0]),e.closePath(),e.stroke(),e.globalAlpha=1}e.setLineDash([])}(e,t,{viewScaleInfo:r,viewSizeInfo:s}),e.globalAlpha=1}})}function Z(e,t,n){const{detail:i}=t,{viewScaleInfo:o,renderContent:l}=n,{shadowColor:a,shadowOffsetX:r,shadowOffsetY:s,shadowBlur:c}=i;_.number(c)?(e.save(),e.shadowColor=a||K.shadowColor,e.shadowOffsetX=(r||0)*o.scale,e.shadowOffsetY=(s||0)*o.scale,e.shadowBlur=(c||0)*o.scale,l(),e.restore()):l()}const ee={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,lineHeight:20,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};function te(e,t,n){var i;if(!0!==(null==(i=null==t?void 0:t.operations)?void 0:i.invisible))try{switch(t.type){case"rect":!function(e,t,n){const{calculator:i,viewScaleInfo:o,viewSizeInfo:l}=n,{x:a,y:r,w:s,h:c,angle:d}=(null==i?void 0:i.elementSize(t,o,l))||t,h={...t,x:a,y:r,w:s,h:c,angle:d};q(e,{x:a,y:r,w:s,h:c,angle:d},(()=>{Z(e,h,{viewScaleInfo:o,viewSizeInfo:l,renderContent:()=>{Q(e,h,{originElem:t,calcElemSize:{x:a,y:r,w:s,h:c,angle:d},viewScaleInfo:o,viewSizeInfo:l,renderContent:()=>{}})}})}))}(e,t,n);break;case"circle":!function(e,t,n){const{detail:i,angle:o}=t,{background:l="#000000",borderColor:a="#000000",borderWidth:r=0}=i,{calculator:s,viewScaleInfo:c,viewSizeInfo:d}=n,{x:h,y:f,w:u,h:g}=(null==s?void 0:s.elementSize({x:t.x,y:t.y,w:t.w,h:t.h},c,d))||t,w={...t,x:h,y:f,w:u,h:g,angle:o};q(e,{x:h,y:f,w:u,h:g,angle:o},(()=>{Z(e,w,{viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{var n,i;const o=u/2,s=g/2,d=h+o,w=f+s;if(void 0!==(null==(n=null==t?void 0:t.detail)?void 0:n.opacity)&&(null==(i=null==t?void 0:t.detail)?void 0:i.opacity)>=0?e.globalAlpha=t.detail.opacity:e.globalAlpha=1,"number"==typeof r&&r>0){const t=r/2+o,n=r/2+s;e.beginPath(),e.strokeStyle=a,e.lineWidth=r,e.circle(d,w,t,n,0,0,2*Math.PI),e.closePath(),e.stroke()}e.beginPath();const v=J(e,l,{viewElementSize:{x:h,y:f,w:u,h:g},viewScaleInfo:c,opacity:e.globalAlpha});e.fillStyle=v,e.circle(d,w,o,s,0,0,2*Math.PI),e.closePath(),e.fill(),e.globalAlpha=1}})}))}(e,t,n);break;case"text":!function(e,t,n){const{calculator:i,viewScaleInfo:o,viewSizeInfo:l}=n,{x:a,y:r,w:s,h:c,angle:d}=(null==i?void 0:i.elementSize(t,o,l))||t,h={...t,x:a,y:r,w:s,h:c,angle:d};q(e,{x:a,y:r,w:s,h:c,angle:d},(()=>{Q(e,h,{originElem:t,calcElemSize:{x:a,y:r,w:s,h:c,angle:d},viewScaleInfo:o,viewSizeInfo:l,renderContent:()=>{const n={...ee,...t.detail},i=(n.fontSize||ee.fontSize)*o.scale,l=n.lineHeight?n.lineHeight*o.scale:i;e.fillStyle=t.detail.color||ee.color,e.textBaseline="top",e.$setFont({fontWeight:n.fontWeight,fontSize:i,fontFamily:n.fontFamily});const d=n.text.replace(/\r\n/gi,"\n"),h=l,f=d.split("\n"),u=[];let g=0;f.forEach(((t,n)=>{let i="";if(t.length>0){for(let o=0;o<t.length&&(e.measureText(i+(t[o]||"")).width<e.$doPixelRatio(s)?i+=t[o]||"":(u.push({text:i,width:e.$undoPixelRatio(e.measureText(i).width)}),i=t[o]||"",g++),!((g+1)*h>c));o++)if(t.length-1===o&&(g+1)*h<c){u.push({text:i,width:e.$undoPixelRatio(e.measureText(i).width)}),n<f.length-1&&g++;break}}else u.push({text:"",width:0})}));let w=0;u.length*h<c&&("top"===t.detail.verticalAlign?w=0:"bottom"===t.detail.verticalAlign?w+=c-u.length*h:w+=(c-u.length*h)/2);{const t=r+w;void 0!==n.textShadowColor&&C(n.textShadowColor)&&(e.shadowColor=n.textShadowColor),void 0!==n.textShadowOffsetX&&_.number(n.textShadowOffsetX)&&(e.shadowOffsetX=n.textShadowOffsetX),void 0!==n.textShadowOffsetY&&_.number(n.textShadowOffsetY)&&(e.shadowOffsetY=n.textShadowOffsetY),void 0!==n.textShadowBlur&&_.number(n.textShadowBlur)&&(e.shadowBlur=n.textShadowBlur),u.forEach(((i,o)=>{let l=a;"center"===n.textAlign?l=a+(s-i.width)/2:"right"===n.textAlign&&(l=a+(s-i.width)),e.fillText(i.text,l,t+h*o)}))}}})}))}(e,t,n);break;case"image":!function(e,t,n){const i=n.loader.getContent(t),{calculator:o,viewScaleInfo:l,viewSizeInfo:a}=n,{x:r,y:s,w:c,h:d,angle:h}=(null==o?void 0:o.elementSize(t,l,a))||t,f={...t,x:r,y:s,w:c,h:d,angle:h};q(e,{x:r,y:s,w:c,h:d,angle:h},(()=>{Z(e,f,{viewScaleInfo:l,viewSizeInfo:a,renderContent:()=>{Q(e,f,{originElem:t,calcElemSize:{x:r,y:s,w:c,h:d,angle:h},viewScaleInfo:l,viewSizeInfo:a,renderContent:()=>{if(i||n.loader.load(t,n.elementAssets||{}),"image"===t.type&&i){const{opacity:n}=t.detail;e.globalAlpha=n||1;const{x:o,y:r,w:s,h:c,radiusList:d}=V(f,{viewScaleInfo:l,viewSizeInfo:a});e.save(),e.fillStyle="transparent",e.beginPath(),e.moveTo(o+d[0],r),e.arcTo(o+s,r,o+s,r+c,d[1]),e.arcTo(o+s,r+c,o,r+c,d[2]),e.arcTo(o,r+c,o,r,d[3]),e.arcTo(o,r,o+s,r,d[0]),e.closePath(),e.fill(),e.clip(),e.drawImage(i,o,r,s,c),e.globalAlpha=1,e.restore()}}})}})}))}(e,t,n);break;case"svg":!function(e,t,n){const i=n.loader.getContent(t),{calculator:o,viewScaleInfo:l,viewSizeInfo:a}=n,{x:r,y:s,w:c,h:d,angle:h}=(null==o?void 0:o.elementSize(t,l,a))||t;q(e,{x:r,y:s,w:c,h:d,angle:h},(()=>{if(i||n.loader.load(t,n.elementAssets||{}),"svg"===t.type&&i){const{opacity:n}=t.detail;e.globalAlpha=n||1,e.drawImage(i,r,s,c,d),e.globalAlpha=1}}))}(e,t,n);break;case"html":!function(e,t,n){const i=n.loader.getContent(t),{calculator:o,viewScaleInfo:l,viewSizeInfo:a}=n,{x:r,y:s,w:c,h:d,angle:h}=(null==o?void 0:o.elementSize(t,l,a))||t;q(e,{x:r,y:s,w:c,h:d,angle:h},(()=>{if(i||n.loader.load(t,n.elementAssets||{}),"html"===t.type&&i){const{opacity:n}=t.detail;e.globalAlpha=n||1,e.drawImage(i,r,s,c,d),e.globalAlpha=1}}))}(e,t,n);break;case"path":!function(e,t,n){const{detail:i}=t,{originX:o,originY:l,originW:a,originH:r}=i,{calculator:s,viewScaleInfo:c,viewSizeInfo:d}=n,{x:h,y:f,w:u,h:g,angle:w}=(null==s?void 0:s.elementSize(t,c,d))||t,v=u/a,y=g/r,m=h-o*v,p=f-l*y,S=c.scale*d.devicePixelRatio,x={...t,x:h,y:f,w:u,h:g,angle:w};q(e,{x:h,y:f,w:u,h:g,angle:w},(()=>{Q(e,x,{originElem:t,calcElemSize:{x:h,y:f,w:u,h:g,angle:w},viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{Z(e,x,{viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{e.save(),e.translate(m,p),e.scale(S*v/c.scale,S*y/c.scale);const t=G(i.commands||[]),n=new Path2D(t);i.fill&&(e.fillStyle=i.fill,e.fill(n)),i.stroke&&0!==i.strokeWidth&&(e.strokeStyle=i.stroke,e.lineWidth=(i.strokeWidth||1)/d.devicePixelRatio,e.lineCap=i.strokeLineCap||"square",e.stroke(n)),e.translate(-m,-p),e.restore()}})}})}))}(e,t,n);break;case"group":{const i={...n.elementAssets||{},...t.detail.assets||{}};!function(e,t,n){const{calculator:i,viewScaleInfo:o,viewSizeInfo:l}=n,{x:a,y:r,w:s,h:c,angle:d}=(null==i?void 0:i.elementSize({x:t.x,y:t.y,w:t.w,h:t.h,angle:t.angle},o,l))||t,h={...t,x:a,y:r,w:s,h:c,angle:d};q(e,{x:a,y:r,w:s,h:c,angle:d},(()=>{Z(e,h,{viewScaleInfo:o,viewSizeInfo:l,renderContent:()=>{Q(e,h,{originElem:t,calcElemSize:{x:a,y:r,w:s,h:c,angle:d},viewScaleInfo:o,viewSizeInfo:l,renderContent:()=>{const{x:i,y:a,w:r,h:s,radiusList:c}=V(h,{viewScaleInfo:o,viewSizeInfo:l});if("hidden"===t.detail.overflow&&(e.save(),e.fillStyle="transparent",e.beginPath(),e.moveTo(i+c[0],a),e.arcTo(i+r,a,i+r,a+s,c[1]),e.arcTo(i+r,a+s,i,a+s,c[2]),e.arcTo(i,a+s,i,a,c[3]),e.arcTo(i,a,i+r,a,c[0]),e.closePath(),e.fill(),e.clip()),Array.isArray(t.detail.children)){const{parentElementSize:i}=n,o={x:i.x+t.x,y:i.y+t.y,w:t.w||i.w,h:t.h||i.h,angle:t.angle},{calculator:l}=n;for(let i=0;i<t.detail.children.length;i++){let a=t.detail.children[i];if(a={...a,x:o.x+a.x,y:o.y+a.y},!0===n.forceDrawAll||(null==l?void 0:l.isElementInView(a,n.viewScaleInfo,n.viewSizeInfo)))try{te(e,a,{...n})}catch(e){console.error(e)}}}"hidden"===t.detail.overflow&&(e.globalAlpha=1,e.restore())}})}})}))}(e,t,{...n,elementAssets:i});break}}}catch(e){console.error(e)}}const ne={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,lineHeight:20,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};const ie=["image","svg","html"],oe=e=>{var t,n,i;let o=null;return"image"===e.type?o=(null==(t=null==e?void 0:e.detail)?void 0:t.src)||null:"svg"===e.type?o=(null==(n=null==e?void 0:e.detail)?void 0:n.svg)||null:"html"===e.type&&(o=(null==(i=null==e?void 0:e.detail)?void 0:i.html)||null),"string"==typeof o&&o?/^@assets\/[0-9a-z]{8,8}\-[0-9a-z]{4,4}\-[0-9a-z]{4,4}\-[0-9a-z]{4,4}\-[0-9a-z]{12,12}$/.test(`${o}`)?o:$(o):$(`${k()}-${e.uuid}-${k()}-${k()}`)};class le extends j{constructor(){super(),z(this,o),z(this,a),z(this,s),z(this,d),z(this,f),z(this,g),z(this,v),z(this,t,{}),z(this,n,{}),z(this,i,{}),T(this,o,l).call(this,"image",(async(e,t)=>{var n;const i=(null==(n=t[e.detail.src])?void 0:n.value)||e.detail.src,o=await L(i);return{uuid:e.uuid,lastModified:Date.now(),content:o}})),T(this,o,l).call(this,"html",(async(e,t)=>{var n;const i=(null==(n=t[e.detail.html])?void 0:n.value)||e.detail.html,o=await B(i,{width:e.detail.width||e.w,height:e.detail.height||e.h});return{uuid:e.uuid,lastModified:Date.now(),content:o}})),T(this,o,l).call(this,"svg",(async(e,t)=>{var n;const i=(null==(n=t[e.detail.svg])?void 0:n.value)||e.detail.svg,o=await D(i);return{uuid:e.uuid,lastModified:Date.now(),content:o}}))}load(e,t){T(this,v,y).call(this,e)||ie.includes(e.type)&&T(this,g,w).call(this,e,t)}getContent(e){var t,n;const o=oe(e);return(null==(n=null==(t=I(this,i))?void 0:t[o])?void 0:n.content)||null}getLoadItemMap(){return I(this,i)}setLoadItemMap(e){A(this,i,e)}}t=new WeakMap,n=new WeakMap,i=new WeakMap,o=new WeakSet,l=function(e,n){I(this,t)[e]=n},a=new WeakSet,r=function(e){var t,n,i;let o=null;return"image"===e.type?o=(null==(t=null==e?void 0:e.detail)?void 0:t.src)||null:"svg"===e.type?o=(null==(n=null==e?void 0:e.detail)?void 0:n.svg)||null:"html"===e.type&&(o=(null==(i=null==e?void 0:e.detail)?void 0:i.html)||null),o},s=new WeakSet,c=function(e){return{element:e,status:"null",content:null,error:null,startTime:-1,endTime:-1,source:T(this,a,r).call(this,e)}},d=new WeakSet,h=function(e){const t=oe(e.element),n=I(this,i)[t];n?n.startTime<e.startTime&&(I(this,i)[t]=e,this.trigger("load",{...e,countTime:e.endTime-e.startTime})):(I(this,i)[t]=e,this.trigger("load",{...e,countTime:e.endTime-e.startTime}))},f=new WeakSet,u=function(e){const t=oe(e.element),n=I(this,i)[t];n?n.startTime<e.startTime&&(I(this,i)[t]=e,this.trigger("error",{...e,countTime:e.endTime-e.startTime})):(I(this,i)[t]=e,this.trigger("error",{...e,countTime:e.endTime-e.startTime}))},g=new WeakSet,w=function(e,i){const o=T(this,s,c).call(this,e),l=oe(e);I(this,n)[l]=o;const a=I(this,t)[e.type];"function"==typeof a&&(o.startTime=Date.now(),a(e,i).then((e=>{o.content=e.content,o.endTime=Date.now(),o.status="load",T(this,d,h).call(this,o)})).catch((t=>{console.warn(`Load element source "${o.source}" fail`,t,e),o.endTime=Date.now(),o.status="error",o.error=t,T(this,f,u).call(this,o)})))},v=new WeakSet,y=function(e){var t;const i=oe(e),o=null==(t=I(this,n))?void 0:t[i];return!(!o||"error"!==o.status||!o.source||o.source!==T(this,a,r).call(this,e))};return m=new WeakMap,p=new WeakMap,S=new WeakSet,x=function(){const e=I(this,p);e.on("load",(e=>{this.trigger("load",e)})),e.on("error",(()=>{}))},e.Renderer=class extends j{constructor(e){super(),z(this,S),z(this,m,void 0),z(this,p,new le),A(this,m,e),T(this,S,x).call(this)}updateOptions(e){A(this,m,e)}drawData(e,t){const n=I(this,p),{calculator:i}=I(this,m),o=I(this,m).viewContext;o.clearRect(0,0,o.canvas.width,o.canvas.height);!function(e,t,n){var i;const{elements:o=[]}=t;for(let t=0;t<o.length;t++){const l=o[t],a={...l,detail:{...ne,...null==l?void 0:l.detail}};if(!0===n.forceDrawAll||(null==(i=n.calculator)?void 0:i.isElementInView(a,n.viewScaleInfo,n.viewSizeInfo)))try{te(e,a,n)}catch(e){console.error(e)}}}(o,e,{loader:n,calculator:i,parentElementSize:{x:0,y:0,w:t.viewSizeInfo.width,h:t.viewSizeInfo.height},elementAssets:e.assets,...t})}scale(e){const{sharer:t}=I(this,m);if(!t)return;const{data:n,offsetTop:i,offsetBottom:o,offsetLeft:l,offsetRight:a,width:r,height:s,contextHeight:c,contextWidth:d,devicePixelRatio:h}=t.getActiveStoreSnapshot();n&&this.drawData(n,{viewScaleInfo:{scale:e,offsetTop:i,offsetBottom:o,offsetLeft:l,offsetRight:a},viewSizeInfo:{width:r,height:s,contextHeight:c,contextWidth:d,devicePixelRatio:h}})}setLoadItemMap(e){I(this,p).setLoadItemMap(e)}getLoadItemMap(){return I(this,p).getLoadItemMap()}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idraw/renderer",
|
|
3
|
-
"version": "0.4.0-beta.
|
|
3
|
+
"version": "0.4.0-beta.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"author": "chenshenhai",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@idraw/types": "^0.4.0-beta.
|
|
24
|
+
"@idraw/types": "^0.4.0-beta.4"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@idraw/util": "^0.4.0-beta.
|
|
28
|
+
"@idraw/util": "^0.4.0-beta.4"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public",
|