@idraw/util 0.4.0-alpha.5 → 0.4.0-alpha.6
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 +4 -3
- package/dist/esm/index.js +4 -3
- package/dist/esm/lib/config.d.ts +13 -1
- package/dist/esm/lib/config.js +52 -2
- package/dist/esm/lib/element.d.ts +5 -1
- package/dist/esm/lib/element.js +82 -0
- package/dist/esm/lib/handle-element.d.ts +10 -0
- package/dist/esm/lib/handle-element.js +119 -0
- package/dist/esm/lib/view-box.js +6 -1
- package/dist/esm/lib/view-calc.d.ts +7 -0
- package/dist/esm/lib/view-calc.js +19 -0
- package/dist/index.global.js +273 -3
- package/dist/index.global.min.js +1 -1
- package/package.json +1 -1
package/dist/esm/index.d.ts
CHANGED
|
@@ -14,9 +14,9 @@ export { Store } from './lib/store';
|
|
|
14
14
|
export { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from './lib/middleware';
|
|
15
15
|
export { Context2D } from './lib/context2d';
|
|
16
16
|
export { rotateElement, parseRadianToAngle, parseAngleToRadian, rotateElementVertexes, getElementRotateVertexes, calcElementCenter, calcElementCenterFromVertexes, rotatePointInGroup, limitAngle } from './lib/rotate';
|
|
17
|
-
export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, updateElementInList, getGroupQueueFromList, getElementSize, mergeElementAsset, filterElementAsset, isResourceElement } from './lib/element';
|
|
17
|
+
export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, findElementFromListByPosition, findElementsFromListByPositions, updateElementInList, getGroupQueueFromList, getElementSize, mergeElementAsset, filterElementAsset, isResourceElement } from './lib/element';
|
|
18
18
|
export { checkRectIntersect } from './lib/rect';
|
|
19
|
-
export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView } from './lib/view-calc';
|
|
19
|
+
export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView, calcViewScaleInfo } from './lib/view-calc';
|
|
20
20
|
export { rotatePoint, rotateVertexes, rotateByCenter } from './lib/rotate';
|
|
21
21
|
export { getElementVertexes, calcElementVertexesInGroup, calcElementVertexesQueueInGroup, calcElementQueueVertexesQueueInGroup } from './lib/vertex';
|
|
22
22
|
export { calcElementSizeController } from './lib/controller';
|
|
@@ -25,5 +25,6 @@ export { generateHTML, parseHTML } from './lib/html';
|
|
|
25
25
|
export { compressImage } from './lib/image';
|
|
26
26
|
export { formatNumber } from './lib/number';
|
|
27
27
|
export { matrixToAngle, matrixToRadian } from './lib/matrix';
|
|
28
|
-
export { getDefaultElementDetailConfig } from './lib/config';
|
|
28
|
+
export { getDefaultElementDetailConfig, getDefaultElementRectDetail } from './lib/config';
|
|
29
29
|
export { calcViewBoxSize } from './lib/view-box';
|
|
30
|
+
export { createElement, moveElementPosition } from './lib/handle-element';
|
package/dist/esm/index.js
CHANGED
|
@@ -14,9 +14,9 @@ export { Store } from './lib/store';
|
|
|
14
14
|
export { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from './lib/middleware';
|
|
15
15
|
export { Context2D } from './lib/context2d';
|
|
16
16
|
export { rotateElement, parseRadianToAngle, parseAngleToRadian, rotateElementVertexes, getElementRotateVertexes, calcElementCenter, calcElementCenterFromVertexes, rotatePointInGroup, limitAngle } from './lib/rotate';
|
|
17
|
-
export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, updateElementInList, getGroupQueueFromList, getElementSize, mergeElementAsset, filterElementAsset, isResourceElement } from './lib/element';
|
|
17
|
+
export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, findElementFromListByPosition, findElementsFromListByPositions, updateElementInList, getGroupQueueFromList, getElementSize, mergeElementAsset, filterElementAsset, isResourceElement } from './lib/element';
|
|
18
18
|
export { checkRectIntersect } from './lib/rect';
|
|
19
|
-
export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView } from './lib/view-calc';
|
|
19
|
+
export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView, calcViewScaleInfo } from './lib/view-calc';
|
|
20
20
|
export { rotatePoint, rotateVertexes, rotateByCenter } from './lib/rotate';
|
|
21
21
|
export { getElementVertexes, calcElementVertexesInGroup, calcElementVertexesQueueInGroup, calcElementQueueVertexesQueueInGroup } from './lib/vertex';
|
|
22
22
|
export { calcElementSizeController } from './lib/controller';
|
|
@@ -25,5 +25,6 @@ export { generateHTML, parseHTML } from './lib/html';
|
|
|
25
25
|
export { compressImage } from './lib/image';
|
|
26
26
|
export { formatNumber } from './lib/number';
|
|
27
27
|
export { matrixToAngle, matrixToRadian } from './lib/matrix';
|
|
28
|
-
export { getDefaultElementDetailConfig } from './lib/config';
|
|
28
|
+
export { getDefaultElementDetailConfig, getDefaultElementRectDetail } from './lib/config';
|
|
29
29
|
export { calcViewBoxSize } from './lib/view-box';
|
|
30
|
+
export { createElement, moveElementPosition } from './lib/handle-element';
|
package/dist/esm/lib/config.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import type { DefaultElementDetailConfig } from '@idraw/types';
|
|
1
|
+
import type { ViewScaleInfo, DefaultElementDetailConfig, ElementRectDetail, ElementCircleDetail, ElementTextDetail, ElementSVGDetail, ElementImageDetail, ElementGroupDetail } from '@idraw/types';
|
|
2
2
|
export declare function getDefaultElementDetailConfig(): DefaultElementDetailConfig;
|
|
3
|
+
export declare function getDefaultElementRectDetail(): ElementRectDetail;
|
|
4
|
+
export declare function getDefaultElementCircleDetail(opts: {
|
|
5
|
+
radius: number;
|
|
6
|
+
}): ElementCircleDetail;
|
|
7
|
+
export declare function getDefaultElementTextDetail(opts?: {
|
|
8
|
+
viewScaleInfo: ViewScaleInfo;
|
|
9
|
+
}): ElementTextDetail;
|
|
10
|
+
export declare function getDefaultElementSVGDetail(): ElementSVGDetail;
|
|
11
|
+
export declare function getDefaultElementImageDetail(): ElementImageDetail;
|
|
12
|
+
export declare function getDefaultElementGroupDetail(opts?: {
|
|
13
|
+
viewScaleInfo: ViewScaleInfo;
|
|
14
|
+
}): ElementGroupDetail;
|
package/dist/esm/lib/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export function getDefaultElementDetailConfig() {
|
|
2
2
|
const config = {
|
|
3
|
-
boxSizing: '
|
|
3
|
+
boxSizing: 'border-box',
|
|
4
4
|
borderWidth: 0,
|
|
5
5
|
borderColor: '#000000',
|
|
6
6
|
shadowColor: '#000000',
|
|
@@ -16,7 +16,57 @@ export function getDefaultElementDetailConfig() {
|
|
|
16
16
|
fontSize: 16,
|
|
17
17
|
lineHeight: 20,
|
|
18
18
|
fontFamily: 'sans-serif',
|
|
19
|
-
fontWeight: 400
|
|
19
|
+
fontWeight: 400,
|
|
20
|
+
overflow: 'hidden'
|
|
20
21
|
};
|
|
21
22
|
return config;
|
|
22
23
|
}
|
|
24
|
+
export function getDefaultElementRectDetail() {
|
|
25
|
+
const detail = {
|
|
26
|
+
background: '#D9D9D9'
|
|
27
|
+
};
|
|
28
|
+
return detail;
|
|
29
|
+
}
|
|
30
|
+
export function getDefaultElementCircleDetail(opts) {
|
|
31
|
+
const detail = {
|
|
32
|
+
background: '#D9D9D9',
|
|
33
|
+
radius: 0
|
|
34
|
+
};
|
|
35
|
+
return detail;
|
|
36
|
+
}
|
|
37
|
+
export function getDefaultElementTextDetail(opts) {
|
|
38
|
+
var _a;
|
|
39
|
+
const detailConfig = getDefaultElementDetailConfig();
|
|
40
|
+
const scale = ((_a = opts === null || opts === void 0 ? void 0 : opts.viewScaleInfo) === null || _a === void 0 ? void 0 : _a.scale) || 1;
|
|
41
|
+
const detail = {
|
|
42
|
+
text: 'Text Element',
|
|
43
|
+
color: detailConfig.color,
|
|
44
|
+
fontFamily: detailConfig.fontFamily,
|
|
45
|
+
fontWeight: detailConfig.fontWeight,
|
|
46
|
+
lineHeight: detailConfig.fontSize * scale,
|
|
47
|
+
fontSize: detailConfig.fontSize * scale,
|
|
48
|
+
textAlign: 'center',
|
|
49
|
+
verticalAlign: 'middle'
|
|
50
|
+
};
|
|
51
|
+
return detail;
|
|
52
|
+
}
|
|
53
|
+
export function getDefaultElementSVGDetail() {
|
|
54
|
+
const detail = {
|
|
55
|
+
svg: '<svg t="1701004189871" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M908.1 353.1l-253.9-36.9L540.7 86.1c-3.1-6.3-8.2-11.4-14.5-14.5-15.8-7.8-35-1.3-42.9 14.5L369.8 316.2l-253.9 36.9c-7 1-13.4 4.3-18.3 9.3-12.3 12.7-12.1 32.9 0.6 45.3l183.7 179.1-43.4 252.9c-1.2 6.9-0.1 14.1 3.2 20.3 8.2 15.6 27.6 21.7 43.2 13.4L512 754l227.1 119.4c6.2 3.3 13.4 4.4 20.3 3.2 17.4-3 29.1-19.5 26.1-36.9l-43.4-252.9 183.7-179.1c5-4.9 8.3-11.3 9.3-18.3 2.7-17.5-9.5-33.7-27-36.3zM664.8 561.6l36.1 210.3L512 672.7 323.1 772l36.1-210.3-152.8-149L417.6 382 512 190.7 606.4 382l211.2 30.7-152.8 148.9z" fill="#2c2c2c"></path></svg>'
|
|
56
|
+
};
|
|
57
|
+
return detail;
|
|
58
|
+
}
|
|
59
|
+
export function getDefaultElementImageDetail() {
|
|
60
|
+
const detail = {
|
|
61
|
+
src: 'data:image/svg+xml;base64,PHN2ZyAgIHZpZXdCb3g9IjAgMCAxMDI0IDEwMjQiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiAgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiPjxwYXRoIGQ9Ik05MjggMTYwSDk2Yy0xNy43IDAtMzIgMTQuMy0zMiAzMnY2NDBjMCAxNy43IDE0LjMgMzIgMzIgMzJoODMyYzE3LjcgMCAzMi0xNC4zIDMyLTMyVjE5MmMwLTE3LjctMTQuMy0zMi0zMi0zMnogbS00MCA2MzJIMTM2di0zOS45bDEzOC41LTE2NC4zIDE1MC4xIDE3OEw2NTguMSA0ODkgODg4IDc2MS42Vjc5MnogbTAtMTI5LjhMNjY0LjIgMzk2LjhjLTMuMi0zLjgtOS0zLjgtMTIuMiAwTDQyNC42IDY2Ni40bC0xNDQtMTcwLjdjLTMuMi0zLjgtOS0zLjgtMTIuMiAwTDEzNiA2NTIuN1YyMzJoNzUydjQzMC4yeiIgIGZpbGw9IiM1MTUxNTEiPjwvcGF0aD48cGF0aCBkPSJNMzA0IDQ1NmM0OC42IDAgODgtMzkuNCA4OC04OHMtMzkuNC04OC04OC04OC04OCAzOS40LTg4IDg4IDM5LjQgODggODggODh6IG0wLTExNmMxNS41IDAgMjggMTIuNSAyOCAyOHMtMTIuNSAyOC0yOCAyOC0yOC0xMi41LTI4LTI4IDEyLjUtMjggMjgtMjh6IiAgZmlsbD0iIzUxNTE1MSI+PC9wYXRoPjwvc3ZnPg=='
|
|
62
|
+
};
|
|
63
|
+
return detail;
|
|
64
|
+
}
|
|
65
|
+
export function getDefaultElementGroupDetail(opts) {
|
|
66
|
+
const detail = {
|
|
67
|
+
children: [],
|
|
68
|
+
background: '#D9D9D9',
|
|
69
|
+
overflow: 'hidden'
|
|
70
|
+
};
|
|
71
|
+
return detail;
|
|
72
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Data, Element, Elements, ElementType, ElementSize, ViewContextSize, ViewSizeInfo, RecursivePartial, ElementAssets, ElementAssetsItem, LoadElementType } from '@idraw/types';
|
|
1
|
+
import type { Data, Element, Elements, ElementType, ElementSize, ViewContextSize, ViewSizeInfo, RecursivePartial, ElementAssets, ElementAssetsItem, LoadElementType, ElementPosition } from '@idraw/types';
|
|
2
2
|
export declare function getSelectedElementUUIDs(data: Data, indexes: Array<number | string>): string[];
|
|
3
3
|
export declare function validateElements(elements: Array<Element<ElementType>>): boolean;
|
|
4
4
|
export declare function calcElementsContextSize(elements: Array<Element<ElementType>>, opts?: {
|
|
@@ -24,3 +24,7 @@ export declare function filterElementAsset<T extends Element<LoadElementType>>(e
|
|
|
24
24
|
assetItem: ElementAssetsItem | null;
|
|
25
25
|
};
|
|
26
26
|
export declare function isResourceElement(elem: Element): boolean;
|
|
27
|
+
export declare function findElementsFromListByPositions(positions: ElementPosition[], list: Element[]): Element[];
|
|
28
|
+
export declare function findElementFromListByPosition(position: ElementPosition, list: Element[]): Element | null;
|
|
29
|
+
export declare function insertElementToListByPosition(element: Element, position: ElementPosition, list: Element[]): boolean;
|
|
30
|
+
export declare function deleteElementInListByPosition(position: ElementPosition, list: Element[]): boolean;
|
package/dist/esm/lib/element.js
CHANGED
|
@@ -328,3 +328,85 @@ export function filterElementAsset(element) {
|
|
|
328
328
|
export function isResourceElement(elem) {
|
|
329
329
|
return ['image', 'svg', 'html'].includes(elem === null || elem === void 0 ? void 0 : elem.type);
|
|
330
330
|
}
|
|
331
|
+
export function findElementsFromListByPositions(positions, list) {
|
|
332
|
+
const elements = [];
|
|
333
|
+
positions.forEach((pos) => {
|
|
334
|
+
const elem = findElementFromListByPosition(pos, list);
|
|
335
|
+
if (elem) {
|
|
336
|
+
elements.push(elem);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
return elements;
|
|
340
|
+
}
|
|
341
|
+
export function findElementFromListByPosition(position, list) {
|
|
342
|
+
let result = null;
|
|
343
|
+
let tempList = list;
|
|
344
|
+
for (let i = 0; i < position.length; i++) {
|
|
345
|
+
const pos = position[i];
|
|
346
|
+
const item = tempList[pos];
|
|
347
|
+
if (i < position.length - 1 && item.type === 'group') {
|
|
348
|
+
tempList = item.detail.children;
|
|
349
|
+
}
|
|
350
|
+
else if (i === position.length - 1) {
|
|
351
|
+
result = item;
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
export function insertElementToListByPosition(element, position, list) {
|
|
360
|
+
let result = false;
|
|
361
|
+
if (position.length === 1) {
|
|
362
|
+
const pos = position[0];
|
|
363
|
+
list.splice(pos, 0, element);
|
|
364
|
+
result = true;
|
|
365
|
+
}
|
|
366
|
+
else if (position.length > 1) {
|
|
367
|
+
let tempList = list;
|
|
368
|
+
for (let i = 0; i < position.length; i++) {
|
|
369
|
+
const pos = position[i];
|
|
370
|
+
const item = tempList[pos];
|
|
371
|
+
if (i === position.length - 1) {
|
|
372
|
+
const pos = position[i];
|
|
373
|
+
tempList.splice(pos, 0, element);
|
|
374
|
+
result = true;
|
|
375
|
+
}
|
|
376
|
+
else if (i < position.length - 1 && item.type === 'group') {
|
|
377
|
+
tempList = item.detail.children;
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return result;
|
|
385
|
+
}
|
|
386
|
+
export function deleteElementInListByPosition(position, list) {
|
|
387
|
+
let result = false;
|
|
388
|
+
if (position.length === 1) {
|
|
389
|
+
const pos = position[0];
|
|
390
|
+
list.splice(pos, 1);
|
|
391
|
+
result = true;
|
|
392
|
+
}
|
|
393
|
+
else if (position.length > 1) {
|
|
394
|
+
let tempList = list;
|
|
395
|
+
for (let i = 0; i < position.length; i++) {
|
|
396
|
+
const pos = position[i];
|
|
397
|
+
const item = tempList[pos];
|
|
398
|
+
if (i === position.length - 1) {
|
|
399
|
+
const pos = position[i];
|
|
400
|
+
tempList.splice(pos, 1);
|
|
401
|
+
result = true;
|
|
402
|
+
}
|
|
403
|
+
else if (i < position.length - 1 && item.type === 'group') {
|
|
404
|
+
tempList = item.detail.children;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return result;
|
|
412
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RecursivePartial, Element, Elements, ElementPosition, ElementType, ViewScaleInfo, ViewSizeInfo } from '@idraw/types';
|
|
2
|
+
export declare function createElement<T extends ElementType>(type: T, baseElem: RecursivePartial<Element<T>>, opts?: {
|
|
3
|
+
viewScaleInfo: ViewScaleInfo;
|
|
4
|
+
viewSizeInfo: ViewSizeInfo;
|
|
5
|
+
limitRatio?: boolean;
|
|
6
|
+
}): Element<T>;
|
|
7
|
+
export declare function moveElementPosition(elements: Elements, opts: {
|
|
8
|
+
from: ElementPosition;
|
|
9
|
+
to: ElementPosition;
|
|
10
|
+
}): Elements;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { createUUID } from './uuid';
|
|
2
|
+
import { getDefaultElementDetailConfig, getDefaultElementRectDetail, getDefaultElementCircleDetail, getDefaultElementTextDetail, getDefaultElementSVGDetail, getDefaultElementImageDetail, getDefaultElementGroupDetail } from './config';
|
|
3
|
+
import { findElementFromListByPosition, insertElementToListByPosition, deleteElementInListByPosition } from './element';
|
|
4
|
+
const defaultViewWidth = 200;
|
|
5
|
+
const defaultViewHeight = 200;
|
|
6
|
+
const defaultDetail = getDefaultElementDetailConfig();
|
|
7
|
+
function createElementSize(type, opts) {
|
|
8
|
+
let x = 0;
|
|
9
|
+
let y = 0;
|
|
10
|
+
let w = defaultViewWidth;
|
|
11
|
+
let h = defaultViewHeight;
|
|
12
|
+
if (opts) {
|
|
13
|
+
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
14
|
+
const { scale, offsetLeft, offsetTop } = viewScaleInfo;
|
|
15
|
+
const { width, height } = viewSizeInfo;
|
|
16
|
+
if (type === 'text') {
|
|
17
|
+
const textDetail = getDefaultElementTextDetail();
|
|
18
|
+
w = defaultDetail.fontSize * scale * textDetail.text.length;
|
|
19
|
+
h = defaultDetail.fontSize * scale * 2;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const limitViewWidth = width / 4;
|
|
23
|
+
const limitViewHeight = height / 4;
|
|
24
|
+
if (defaultViewWidth >= limitViewWidth) {
|
|
25
|
+
w = limitViewWidth / scale;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
w = defaultViewWidth / scale;
|
|
29
|
+
}
|
|
30
|
+
if (defaultViewHeight >= limitViewHeight) {
|
|
31
|
+
h = limitViewHeight / scale;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
h = defaultViewHeight / scale;
|
|
35
|
+
}
|
|
36
|
+
if (['circle', 'svg', 'image'].includes(type)) {
|
|
37
|
+
w = h = Math.max(w, h);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
x = (0 - offsetLeft + width / 2 - (w * scale) / 2) / scale;
|
|
41
|
+
y = (0 - offsetTop + height / 2 - (h * scale) / 2) / scale;
|
|
42
|
+
}
|
|
43
|
+
const elemSize = {
|
|
44
|
+
x,
|
|
45
|
+
y,
|
|
46
|
+
w,
|
|
47
|
+
h
|
|
48
|
+
};
|
|
49
|
+
return elemSize;
|
|
50
|
+
}
|
|
51
|
+
export function createElement(type, baseElem, opts) {
|
|
52
|
+
const elemSize = createElementSize(type, opts);
|
|
53
|
+
let detail = {};
|
|
54
|
+
if (type === 'rect') {
|
|
55
|
+
detail = getDefaultElementRectDetail();
|
|
56
|
+
}
|
|
57
|
+
else if (type === 'circle') {
|
|
58
|
+
detail = getDefaultElementCircleDetail({
|
|
59
|
+
radius: elemSize.w
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else if (type === 'text') {
|
|
63
|
+
detail = getDefaultElementTextDetail(opts);
|
|
64
|
+
}
|
|
65
|
+
else if (type === 'svg') {
|
|
66
|
+
detail = getDefaultElementSVGDetail();
|
|
67
|
+
}
|
|
68
|
+
else if (type === 'image') {
|
|
69
|
+
detail = getDefaultElementImageDetail();
|
|
70
|
+
}
|
|
71
|
+
else if (type === 'group') {
|
|
72
|
+
detail = getDefaultElementGroupDetail();
|
|
73
|
+
}
|
|
74
|
+
const elem = Object.assign(Object.assign(Object.assign({}, elemSize), baseElem), { uuid: createUUID(), type, detail: Object.assign(Object.assign({}, detail), (baseElem.detail || {})) });
|
|
75
|
+
return elem;
|
|
76
|
+
}
|
|
77
|
+
export function moveElementPosition(elements, opts) {
|
|
78
|
+
const { from, to } = opts;
|
|
79
|
+
if (from.length === 0 || to.length === 0) {
|
|
80
|
+
return elements;
|
|
81
|
+
}
|
|
82
|
+
if (from.length <= to.length) {
|
|
83
|
+
for (let i = 0; i < from.length; i++) {
|
|
84
|
+
if (to[i] === from[i]) {
|
|
85
|
+
if (i === from.length - 1) {
|
|
86
|
+
return elements;
|
|
87
|
+
}
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const target = findElementFromListByPosition(from, elements);
|
|
93
|
+
if (target) {
|
|
94
|
+
const insterResult = insertElementToListByPosition(target, to, elements);
|
|
95
|
+
if (!insterResult) {
|
|
96
|
+
return elements;
|
|
97
|
+
}
|
|
98
|
+
let trimDeletePosIndex = -1;
|
|
99
|
+
const trimDeletePosAction = 'down';
|
|
100
|
+
for (let i = 0; i < from.length; i++) {
|
|
101
|
+
if (!(to[i] >= 0)) {
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (to[i] === from[i]) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (to[i] < from[i] && i == to.length - 1) {
|
|
108
|
+
trimDeletePosIndex = i;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (trimDeletePosIndex >= 0) {
|
|
112
|
+
if (trimDeletePosAction === 'down') {
|
|
113
|
+
from[trimDeletePosIndex] = from[trimDeletePosIndex] + 1;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
deleteElementInListByPosition(from, elements);
|
|
117
|
+
}
|
|
118
|
+
return elements;
|
|
119
|
+
}
|
package/dist/esm/lib/view-box.js
CHANGED
|
@@ -18,7 +18,7 @@ export function calcViewBoxSize(viewElem, opts) {
|
|
|
18
18
|
}
|
|
19
19
|
let bw = 0;
|
|
20
20
|
if (typeof borderWidth === 'number') {
|
|
21
|
-
bw = (borderWidth ||
|
|
21
|
+
bw = (borderWidth || 0) * scale;
|
|
22
22
|
}
|
|
23
23
|
if (boxSizing === 'border-box') {
|
|
24
24
|
x = viewElem.x + bw / 2;
|
|
@@ -38,6 +38,11 @@ export function calcViewBoxSize(viewElem, opts) {
|
|
|
38
38
|
w = viewElem.w;
|
|
39
39
|
h = viewElem.h;
|
|
40
40
|
}
|
|
41
|
+
w = Math.max(w, 1);
|
|
42
|
+
h = Math.max(h, 1);
|
|
43
|
+
radiusList = radiusList.map((r) => {
|
|
44
|
+
return Math.min(r, w / 2, h / 2);
|
|
45
|
+
});
|
|
41
46
|
return {
|
|
42
47
|
x,
|
|
43
48
|
y,
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { Point, PointSize, Data, ViewScaleInfo, ViewSizeInfo, Element, ElementType, ElementSize, ViewContext2D, ViewRectVertexes } from '@idraw/types';
|
|
2
|
+
export declare function calcViewScaleInfo(info: {
|
|
3
|
+
scale: number;
|
|
4
|
+
offsetX: number;
|
|
5
|
+
offsetY: number;
|
|
6
|
+
}, opts: {
|
|
7
|
+
viewSizeInfo: ViewSizeInfo;
|
|
8
|
+
}): ViewScaleInfo;
|
|
2
9
|
export declare function viewScale(opts: {
|
|
3
10
|
scale: number;
|
|
4
11
|
point: PointSize;
|
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import { rotateElementVertexes } from './rotate';
|
|
2
2
|
import { checkRectIntersect } from './rect';
|
|
3
|
+
export function calcViewScaleInfo(info, opts) {
|
|
4
|
+
const { scale, offsetX, offsetY } = info;
|
|
5
|
+
const { viewSizeInfo } = opts;
|
|
6
|
+
const { width, height, contextWidth, contextHeight } = viewSizeInfo;
|
|
7
|
+
const w = contextWidth * scale;
|
|
8
|
+
const h = contextHeight * scale;
|
|
9
|
+
const offsetLeft = 0 - offsetX * scale;
|
|
10
|
+
const offsetTop = 0 - offsetY * scale;
|
|
11
|
+
const offsetRight = width - (w + offsetLeft / scale);
|
|
12
|
+
const offsetBottom = height - (h + offsetTop / scale);
|
|
13
|
+
const newScaleInfo = {
|
|
14
|
+
scale,
|
|
15
|
+
offsetLeft,
|
|
16
|
+
offsetTop,
|
|
17
|
+
offsetRight,
|
|
18
|
+
offsetBottom
|
|
19
|
+
};
|
|
20
|
+
return newScaleInfo;
|
|
21
|
+
}
|
|
3
22
|
export function viewScale(opts) {
|
|
4
23
|
const { scale, point, viewScaleInfo: prevViewScaleInfo } = opts;
|
|
5
24
|
const { offsetLeft, offsetTop } = prevViewScaleInfo;
|
package/dist/index.global.js
CHANGED
|
@@ -1665,6 +1665,80 @@ var iDrawUtil = function(exports) {
|
|
|
1665
1665
|
function isResourceElement(elem) {
|
|
1666
1666
|
return ["image", "svg", "html"].includes(elem == null ? void 0 : elem.type);
|
|
1667
1667
|
}
|
|
1668
|
+
function findElementsFromListByPositions(positions, list) {
|
|
1669
|
+
const elements = [];
|
|
1670
|
+
positions.forEach((pos) => {
|
|
1671
|
+
const elem = findElementFromListByPosition(pos, list);
|
|
1672
|
+
if (elem) {
|
|
1673
|
+
elements.push(elem);
|
|
1674
|
+
}
|
|
1675
|
+
});
|
|
1676
|
+
return elements;
|
|
1677
|
+
}
|
|
1678
|
+
function findElementFromListByPosition(position, list) {
|
|
1679
|
+
let result = null;
|
|
1680
|
+
let tempList = list;
|
|
1681
|
+
for (let i = 0; i < position.length; i++) {
|
|
1682
|
+
const pos = position[i];
|
|
1683
|
+
const item = tempList[pos];
|
|
1684
|
+
if (i < position.length - 1 && item.type === "group") {
|
|
1685
|
+
tempList = item.detail.children;
|
|
1686
|
+
} else if (i === position.length - 1) {
|
|
1687
|
+
result = item;
|
|
1688
|
+
} else {
|
|
1689
|
+
break;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
return result;
|
|
1693
|
+
}
|
|
1694
|
+
function insertElementToListByPosition(element, position, list) {
|
|
1695
|
+
let result = false;
|
|
1696
|
+
if (position.length === 1) {
|
|
1697
|
+
const pos = position[0];
|
|
1698
|
+
list.splice(pos, 0, element);
|
|
1699
|
+
result = true;
|
|
1700
|
+
} else if (position.length > 1) {
|
|
1701
|
+
let tempList = list;
|
|
1702
|
+
for (let i = 0; i < position.length; i++) {
|
|
1703
|
+
const pos = position[i];
|
|
1704
|
+
const item = tempList[pos];
|
|
1705
|
+
if (i === position.length - 1) {
|
|
1706
|
+
const pos2 = position[i];
|
|
1707
|
+
tempList.splice(pos2, 0, element);
|
|
1708
|
+
result = true;
|
|
1709
|
+
} else if (i < position.length - 1 && item.type === "group") {
|
|
1710
|
+
tempList = item.detail.children;
|
|
1711
|
+
} else {
|
|
1712
|
+
break;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
return result;
|
|
1717
|
+
}
|
|
1718
|
+
function deleteElementInListByPosition(position, list) {
|
|
1719
|
+
let result = false;
|
|
1720
|
+
if (position.length === 1) {
|
|
1721
|
+
const pos = position[0];
|
|
1722
|
+
list.splice(pos, 1);
|
|
1723
|
+
result = true;
|
|
1724
|
+
} else if (position.length > 1) {
|
|
1725
|
+
let tempList = list;
|
|
1726
|
+
for (let i = 0; i < position.length; i++) {
|
|
1727
|
+
const pos = position[i];
|
|
1728
|
+
const item = tempList[pos];
|
|
1729
|
+
if (i === position.length - 1) {
|
|
1730
|
+
const pos2 = position[i];
|
|
1731
|
+
tempList.splice(pos2, 1);
|
|
1732
|
+
result = true;
|
|
1733
|
+
} else if (i < position.length - 1 && item.type === "group") {
|
|
1734
|
+
tempList = item.detail.children;
|
|
1735
|
+
} else {
|
|
1736
|
+
break;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
return result;
|
|
1741
|
+
}
|
|
1668
1742
|
function checkRectIntersect(rect1, rect2) {
|
|
1669
1743
|
const react1MinX = rect1.x;
|
|
1670
1744
|
const react1MinY = rect1.y;
|
|
@@ -1676,6 +1750,25 @@ var iDrawUtil = function(exports) {
|
|
|
1676
1750
|
const react2MaxY = rect2.y + rect2.h;
|
|
1677
1751
|
return react1MinX <= react2MaxX && react1MaxX >= react2MinX && react1MinY <= react2MaxY && react1MaxY >= react2MinY;
|
|
1678
1752
|
}
|
|
1753
|
+
function calcViewScaleInfo(info, opts) {
|
|
1754
|
+
const { scale, offsetX, offsetY } = info;
|
|
1755
|
+
const { viewSizeInfo } = opts;
|
|
1756
|
+
const { width, height, contextWidth, contextHeight } = viewSizeInfo;
|
|
1757
|
+
const w2 = contextWidth * scale;
|
|
1758
|
+
const h2 = contextHeight * scale;
|
|
1759
|
+
const offsetLeft = 0 - offsetX * scale;
|
|
1760
|
+
const offsetTop = 0 - offsetY * scale;
|
|
1761
|
+
const offsetRight = width - (w2 + offsetLeft / scale);
|
|
1762
|
+
const offsetBottom = height - (h2 + offsetTop / scale);
|
|
1763
|
+
const newScaleInfo = {
|
|
1764
|
+
scale,
|
|
1765
|
+
offsetLeft,
|
|
1766
|
+
offsetTop,
|
|
1767
|
+
offsetRight,
|
|
1768
|
+
offsetBottom
|
|
1769
|
+
};
|
|
1770
|
+
return newScaleInfo;
|
|
1771
|
+
}
|
|
1679
1772
|
function viewScale(opts) {
|
|
1680
1773
|
const { scale, point, viewScaleInfo: prevViewScaleInfo } = opts;
|
|
1681
1774
|
const { offsetLeft, offsetTop } = prevViewScaleInfo;
|
|
@@ -2246,7 +2339,7 @@ var iDrawUtil = function(exports) {
|
|
|
2246
2339
|
}
|
|
2247
2340
|
function getDefaultElementDetailConfig() {
|
|
2248
2341
|
const config = {
|
|
2249
|
-
boxSizing: "
|
|
2342
|
+
boxSizing: "border-box",
|
|
2250
2343
|
borderWidth: 0,
|
|
2251
2344
|
borderColor: "#000000",
|
|
2252
2345
|
shadowColor: "#000000",
|
|
@@ -2262,10 +2355,60 @@ var iDrawUtil = function(exports) {
|
|
|
2262
2355
|
fontSize: 16,
|
|
2263
2356
|
lineHeight: 20,
|
|
2264
2357
|
fontFamily: "sans-serif",
|
|
2265
|
-
fontWeight: 400
|
|
2358
|
+
fontWeight: 400,
|
|
2359
|
+
overflow: "hidden"
|
|
2266
2360
|
};
|
|
2267
2361
|
return config;
|
|
2268
2362
|
}
|
|
2363
|
+
function getDefaultElementRectDetail() {
|
|
2364
|
+
const detail = {
|
|
2365
|
+
background: "#D9D9D9"
|
|
2366
|
+
};
|
|
2367
|
+
return detail;
|
|
2368
|
+
}
|
|
2369
|
+
function getDefaultElementCircleDetail(opts) {
|
|
2370
|
+
const detail = {
|
|
2371
|
+
background: "#D9D9D9",
|
|
2372
|
+
radius: 0
|
|
2373
|
+
};
|
|
2374
|
+
return detail;
|
|
2375
|
+
}
|
|
2376
|
+
function getDefaultElementTextDetail(opts) {
|
|
2377
|
+
var _a;
|
|
2378
|
+
const detailConfig = getDefaultElementDetailConfig();
|
|
2379
|
+
const scale = ((_a = opts == null ? void 0 : opts.viewScaleInfo) == null ? void 0 : _a.scale) || 1;
|
|
2380
|
+
const detail = {
|
|
2381
|
+
text: "Text Element",
|
|
2382
|
+
color: detailConfig.color,
|
|
2383
|
+
fontFamily: detailConfig.fontFamily,
|
|
2384
|
+
fontWeight: detailConfig.fontWeight,
|
|
2385
|
+
lineHeight: detailConfig.fontSize * scale,
|
|
2386
|
+
fontSize: detailConfig.fontSize * scale,
|
|
2387
|
+
textAlign: "center",
|
|
2388
|
+
verticalAlign: "middle"
|
|
2389
|
+
};
|
|
2390
|
+
return detail;
|
|
2391
|
+
}
|
|
2392
|
+
function getDefaultElementSVGDetail() {
|
|
2393
|
+
const detail = {
|
|
2394
|
+
svg: '<svg t="1701004189871" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M908.1 353.1l-253.9-36.9L540.7 86.1c-3.1-6.3-8.2-11.4-14.5-14.5-15.8-7.8-35-1.3-42.9 14.5L369.8 316.2l-253.9 36.9c-7 1-13.4 4.3-18.3 9.3-12.3 12.7-12.1 32.9 0.6 45.3l183.7 179.1-43.4 252.9c-1.2 6.9-0.1 14.1 3.2 20.3 8.2 15.6 27.6 21.7 43.2 13.4L512 754l227.1 119.4c6.2 3.3 13.4 4.4 20.3 3.2 17.4-3 29.1-19.5 26.1-36.9l-43.4-252.9 183.7-179.1c5-4.9 8.3-11.3 9.3-18.3 2.7-17.5-9.5-33.7-27-36.3zM664.8 561.6l36.1 210.3L512 672.7 323.1 772l36.1-210.3-152.8-149L417.6 382 512 190.7 606.4 382l211.2 30.7-152.8 148.9z" fill="#2c2c2c"></path></svg>'
|
|
2395
|
+
};
|
|
2396
|
+
return detail;
|
|
2397
|
+
}
|
|
2398
|
+
function getDefaultElementImageDetail() {
|
|
2399
|
+
const detail = {
|
|
2400
|
+
src: "data:image/svg+xml;base64,PHN2ZyAgIHZpZXdCb3g9IjAgMCAxMDI0IDEwMjQiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiAgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiPjxwYXRoIGQ9Ik05MjggMTYwSDk2Yy0xNy43IDAtMzIgMTQuMy0zMiAzMnY2NDBjMCAxNy43IDE0LjMgMzIgMzIgMzJoODMyYzE3LjcgMCAzMi0xNC4zIDMyLTMyVjE5MmMwLTE3LjctMTQuMy0zMi0zMi0zMnogbS00MCA2MzJIMTM2di0zOS45bDEzOC41LTE2NC4zIDE1MC4xIDE3OEw2NTguMSA0ODkgODg4IDc2MS42Vjc5MnogbTAtMTI5LjhMNjY0LjIgMzk2LjhjLTMuMi0zLjgtOS0zLjgtMTIuMiAwTDQyNC42IDY2Ni40bC0xNDQtMTcwLjdjLTMuMi0zLjgtOS0zLjgtMTIuMiAwTDEzNiA2NTIuN1YyMzJoNzUydjQzMC4yeiIgIGZpbGw9IiM1MTUxNTEiPjwvcGF0aD48cGF0aCBkPSJNMzA0IDQ1NmM0OC42IDAgODgtMzkuNCA4OC04OHMtMzkuNC04OC04OC04OC04OCAzOS40LTg4IDg4IDM5LjQgODggODggODh6IG0wLTExNmMxNS41IDAgMjggMTIuNSAyOCAyOHMtMTIuNSAyOC0yOCAyOC0yOC0xMi41LTI4LTI4IDEyLjUtMjggMjgtMjh6IiAgZmlsbD0iIzUxNTE1MSI+PC9wYXRoPjwvc3ZnPg=="
|
|
2401
|
+
};
|
|
2402
|
+
return detail;
|
|
2403
|
+
}
|
|
2404
|
+
function getDefaultElementGroupDetail(opts) {
|
|
2405
|
+
const detail = {
|
|
2406
|
+
children: [],
|
|
2407
|
+
background: "#D9D9D9",
|
|
2408
|
+
overflow: "hidden"
|
|
2409
|
+
};
|
|
2410
|
+
return detail;
|
|
2411
|
+
}
|
|
2269
2412
|
const defaultElemConfig = getDefaultElementDetailConfig();
|
|
2270
2413
|
function calcViewBoxSize(viewElem, opts) {
|
|
2271
2414
|
const { viewScaleInfo } = opts;
|
|
@@ -2284,7 +2427,7 @@ var iDrawUtil = function(exports) {
|
|
|
2284
2427
|
}
|
|
2285
2428
|
let bw = 0;
|
|
2286
2429
|
if (typeof borderWidth2 === "number") {
|
|
2287
|
-
bw = (borderWidth2 ||
|
|
2430
|
+
bw = (borderWidth2 || 0) * scale;
|
|
2288
2431
|
}
|
|
2289
2432
|
if (boxSizing === "border-box") {
|
|
2290
2433
|
x2 = viewElem.x + bw / 2;
|
|
@@ -2302,6 +2445,11 @@ var iDrawUtil = function(exports) {
|
|
|
2302
2445
|
w2 = viewElem.w;
|
|
2303
2446
|
h2 = viewElem.h;
|
|
2304
2447
|
}
|
|
2448
|
+
w2 = Math.max(w2, 1);
|
|
2449
|
+
h2 = Math.max(h2, 1);
|
|
2450
|
+
radiusList = radiusList.map((r) => {
|
|
2451
|
+
return Math.min(r, w2 / 2, h2 / 2);
|
|
2452
|
+
});
|
|
2305
2453
|
return {
|
|
2306
2454
|
x: x2,
|
|
2307
2455
|
y: y2,
|
|
@@ -2310,6 +2458,122 @@ var iDrawUtil = function(exports) {
|
|
|
2310
2458
|
radiusList
|
|
2311
2459
|
};
|
|
2312
2460
|
}
|
|
2461
|
+
const defaultViewWidth = 200;
|
|
2462
|
+
const defaultViewHeight = 200;
|
|
2463
|
+
const defaultDetail = getDefaultElementDetailConfig();
|
|
2464
|
+
function createElementSize(type, opts) {
|
|
2465
|
+
let x2 = 0;
|
|
2466
|
+
let y2 = 0;
|
|
2467
|
+
let w2 = defaultViewWidth;
|
|
2468
|
+
let h2 = defaultViewHeight;
|
|
2469
|
+
if (opts) {
|
|
2470
|
+
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
2471
|
+
const { scale, offsetLeft, offsetTop } = viewScaleInfo;
|
|
2472
|
+
const { width, height } = viewSizeInfo;
|
|
2473
|
+
if (type === "text") {
|
|
2474
|
+
const textDetail = getDefaultElementTextDetail();
|
|
2475
|
+
w2 = defaultDetail.fontSize * scale * textDetail.text.length;
|
|
2476
|
+
h2 = defaultDetail.fontSize * scale * 2;
|
|
2477
|
+
} else {
|
|
2478
|
+
const limitViewWidth = width / 4;
|
|
2479
|
+
const limitViewHeight = height / 4;
|
|
2480
|
+
if (defaultViewWidth >= limitViewWidth) {
|
|
2481
|
+
w2 = limitViewWidth / scale;
|
|
2482
|
+
} else {
|
|
2483
|
+
w2 = defaultViewWidth / scale;
|
|
2484
|
+
}
|
|
2485
|
+
if (defaultViewHeight >= limitViewHeight) {
|
|
2486
|
+
h2 = limitViewHeight / scale;
|
|
2487
|
+
} else {
|
|
2488
|
+
h2 = defaultViewHeight / scale;
|
|
2489
|
+
}
|
|
2490
|
+
if (["circle", "svg", "image"].includes(type)) {
|
|
2491
|
+
w2 = h2 = Math.max(w2, h2);
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
x2 = (0 - offsetLeft + width / 2 - w2 * scale / 2) / scale;
|
|
2495
|
+
y2 = (0 - offsetTop + height / 2 - h2 * scale / 2) / scale;
|
|
2496
|
+
}
|
|
2497
|
+
const elemSize = {
|
|
2498
|
+
x: x2,
|
|
2499
|
+
y: y2,
|
|
2500
|
+
w: w2,
|
|
2501
|
+
h: h2
|
|
2502
|
+
};
|
|
2503
|
+
return elemSize;
|
|
2504
|
+
}
|
|
2505
|
+
function createElement(type, baseElem, opts) {
|
|
2506
|
+
const elemSize = createElementSize(type, opts);
|
|
2507
|
+
let detail = {};
|
|
2508
|
+
if (type === "rect") {
|
|
2509
|
+
detail = getDefaultElementRectDetail();
|
|
2510
|
+
} else if (type === "circle") {
|
|
2511
|
+
detail = getDefaultElementCircleDetail({
|
|
2512
|
+
radius: elemSize.w
|
|
2513
|
+
});
|
|
2514
|
+
} else if (type === "text") {
|
|
2515
|
+
detail = getDefaultElementTextDetail(opts);
|
|
2516
|
+
} else if (type === "svg") {
|
|
2517
|
+
detail = getDefaultElementSVGDetail();
|
|
2518
|
+
} else if (type === "image") {
|
|
2519
|
+
detail = getDefaultElementImageDetail();
|
|
2520
|
+
} else if (type === "group") {
|
|
2521
|
+
detail = getDefaultElementGroupDetail();
|
|
2522
|
+
}
|
|
2523
|
+
const elem = {
|
|
2524
|
+
...elemSize,
|
|
2525
|
+
...baseElem,
|
|
2526
|
+
uuid: createUUID(),
|
|
2527
|
+
type,
|
|
2528
|
+
detail: {
|
|
2529
|
+
...detail,
|
|
2530
|
+
...baseElem.detail || {}
|
|
2531
|
+
}
|
|
2532
|
+
};
|
|
2533
|
+
return elem;
|
|
2534
|
+
}
|
|
2535
|
+
function moveElementPosition(elements, opts) {
|
|
2536
|
+
const { from, to } = opts;
|
|
2537
|
+
if (from.length === 0 || to.length === 0) {
|
|
2538
|
+
return elements;
|
|
2539
|
+
}
|
|
2540
|
+
if (from.length <= to.length) {
|
|
2541
|
+
for (let i = 0; i < from.length; i++) {
|
|
2542
|
+
if (to[i] === from[i]) {
|
|
2543
|
+
if (i === from.length - 1) {
|
|
2544
|
+
return elements;
|
|
2545
|
+
}
|
|
2546
|
+
continue;
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
const target = findElementFromListByPosition(from, elements);
|
|
2551
|
+
if (target) {
|
|
2552
|
+
const insterResult = insertElementToListByPosition(target, to, elements);
|
|
2553
|
+
if (!insterResult) {
|
|
2554
|
+
return elements;
|
|
2555
|
+
}
|
|
2556
|
+
let trimDeletePosIndex = -1;
|
|
2557
|
+
for (let i = 0; i < from.length; i++) {
|
|
2558
|
+
if (!(to[i] >= 0)) {
|
|
2559
|
+
break;
|
|
2560
|
+
}
|
|
2561
|
+
if (to[i] === from[i]) {
|
|
2562
|
+
continue;
|
|
2563
|
+
}
|
|
2564
|
+
if (to[i] < from[i] && i == to.length - 1) {
|
|
2565
|
+
trimDeletePosIndex = i;
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
if (trimDeletePosIndex >= 0) {
|
|
2569
|
+
{
|
|
2570
|
+
from[trimDeletePosIndex] = from[trimDeletePosIndex] + 1;
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
deleteElementInListByPosition(from, elements);
|
|
2574
|
+
}
|
|
2575
|
+
return elements;
|
|
2576
|
+
}
|
|
2313
2577
|
exports.Context2D = Context2D;
|
|
2314
2578
|
exports.EventEmitter = EventEmitter;
|
|
2315
2579
|
exports.Store = Store;
|
|
@@ -2326,6 +2590,7 @@ var iDrawUtil = function(exports) {
|
|
|
2326
2590
|
exports.calcViewBoxSize = calcViewBoxSize;
|
|
2327
2591
|
exports.calcViewElementSize = calcViewElementSize;
|
|
2328
2592
|
exports.calcViewPointSize = calcViewPointSize;
|
|
2593
|
+
exports.calcViewScaleInfo = calcViewScaleInfo;
|
|
2329
2594
|
exports.calcViewVertexes = calcViewVertexes;
|
|
2330
2595
|
exports.check = check;
|
|
2331
2596
|
exports.checkRectIntersect = checkRectIntersect;
|
|
@@ -2337,6 +2602,7 @@ var iDrawUtil = function(exports) {
|
|
|
2337
2602
|
exports.createAssetId = createAssetId;
|
|
2338
2603
|
exports.createBoardContexts = createBoardContexts;
|
|
2339
2604
|
exports.createContext2D = createContext2D;
|
|
2605
|
+
exports.createElement = createElement;
|
|
2340
2606
|
exports.createOffscreenContext2D = createOffscreenContext2D;
|
|
2341
2607
|
exports.createUUID = createUUID;
|
|
2342
2608
|
exports.deepClone = deepClone;
|
|
@@ -2346,12 +2612,15 @@ var iDrawUtil = function(exports) {
|
|
|
2346
2612
|
exports.equalTouchPoint = equalTouchPoint;
|
|
2347
2613
|
exports.filterElementAsset = filterElementAsset;
|
|
2348
2614
|
exports.findElementFromList = findElementFromList;
|
|
2615
|
+
exports.findElementFromListByPosition = findElementFromListByPosition;
|
|
2349
2616
|
exports.findElementsFromList = findElementsFromList;
|
|
2617
|
+
exports.findElementsFromListByPositions = findElementsFromListByPositions;
|
|
2350
2618
|
exports.formatNumber = formatNumber;
|
|
2351
2619
|
exports.generateHTML = generateHTML;
|
|
2352
2620
|
exports.generateSVGPath = generateSVGPath;
|
|
2353
2621
|
exports.getCenterFromTwoPoints = getCenterFromTwoPoints;
|
|
2354
2622
|
exports.getDefaultElementDetailConfig = getDefaultElementDetailConfig;
|
|
2623
|
+
exports.getDefaultElementRectDetail = getDefaultElementRectDetail;
|
|
2355
2624
|
exports.getElemenetsAssetIds = getElemenetsAssetIds;
|
|
2356
2625
|
exports.getElementRotateVertexes = getElementRotateVertexes;
|
|
2357
2626
|
exports.getElementSize = getElementSize;
|
|
@@ -2376,6 +2645,7 @@ var iDrawUtil = function(exports) {
|
|
|
2376
2645
|
exports.matrixToRadian = matrixToRadian;
|
|
2377
2646
|
exports.mergeElementAsset = mergeElementAsset;
|
|
2378
2647
|
exports.mergeHexColorAlpha = mergeHexColorAlpha;
|
|
2648
|
+
exports.moveElementPosition = moveElementPosition;
|
|
2379
2649
|
exports.parseAngleToRadian = parseAngleToRadian;
|
|
2380
2650
|
exports.parseFileToBase64 = parseFileToBase64;
|
|
2381
2651
|
exports.parseFileToText = parseFileToText;
|
package/dist/index.global.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var iDrawUtil=function(t){"use strict";function e(t){return"string"==typeof t&&(/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)||/^[a-z]{1,}$/i.test(t))}const n={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4","indianred ":"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};function i(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${t()}${t()}-${t()}-${t()}-${t()}-${t()}${t()}${t()}`}function o(t){let e=0;for(let n=0;n<t.length;n++)e+=t.charCodeAt(n)*t.charCodeAt(n)*n*n;return e.toString(16).substring(0,4)}function r(t){const e=t.length,n=Math.floor(e/2),i=t.substring(0,4).padEnd(4,"0"),r=t.substring(0,4).padEnd(4,"0");return`@assets/${o(e.toString(16).padEnd(4,i))}${o(t.substring(n-4,n).padEnd(4,i)).padEnd(4,"f")}-${o(t.substring(n-8,n-4).padEnd(4,i)).padEnd(4,"f")}-${o(t.substring(n-12,n-8).padEnd(4,i)).padEnd(4,"f")}-${o(t.substring(n-16,n-12).padEnd(4,r)).padEnd(4,"f")}-${o(t.substring(n,n+4).padEnd(4,r)).padEnd(4,"f")}${o(t.substring(n+4,n+8).padEnd(4,r)).padEnd(4,"f")}${o(r.padEnd(4,i).padEnd(4,r))}`}function a(t){return/^@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(`${t}`)}function l(t){return function t(e){const n=function(t){return Object.prototype.toString.call(t).replace(/[\]|\[]{1,1}/gi,"").split(" ")[1]}(e);if(["Null","Number","String","Boolean","Undefined"].indexOf(n)>=0)return e;if("Array"===n){const n=[];return e.forEach((e=>{n.push(t(e))})),n}if("Object"===n){const n={};Object.keys(e).forEach((i=>{n[i]=t(e[i])}));return Object.getOwnPropertySymbols(e).forEach((i=>{n[i]=t(e[i])})),n}}(t)}function s(t){return(Object.prototype.toString.call(t)||"").replace(/(\[object|\])/gi,"").trim()}const c={type(t,e){const n=s(t);return!0===e?n.toLocaleLowerCase():n},array:t=>"Array"===s(t),json:t=>"Object"===s(t),function:t=>"Function"===s(t),asyncFunction:t=>"AsyncFunction"===s(t),string:t=>"String"===s(t),number:t=>"Number"===s(t),undefined:t=>"Undefined"===s(t),null:t=>"Null"===s(t),promise:t=>"Promise"===s(t)};const{Image:u}=window;function h(t){return new Promise(((e,n)=>{const i=new u;i.crossOrigin="anonymous",i.onload=function(){e(i)},i.onabort=n,i.onerror=n,i.src=t}))}function d(t){return"number"==typeof t&&(t>0||t<=0)}function f(t){return"number"==typeof t&&t>=0}function g(t){return"string"==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${t}`)}function x(t){return"string"==typeof t&&/^(data:image\/)/.test(`${t}`)}const p={x:function(t){return d(t)},y:function(t){return d(t)},w:f,h:function(t){return"number"==typeof t&&t>=0},angle:function(t){return"number"==typeof t&&t>=-360&&t<=360},number:d,numberStr:function(t){return/^(-?\d+(?:\.\d+)?)$/.test(`${t}`)},borderWidth:function(t){return f(t)},borderRadius:function(t){return d(t)&&t>=0},color:function(t){return e(t)},imageSrc:function(t){return x(t)||g(t)},imageURL:g,imageBase64:x,svg:function(t){return"string"==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test(`${t}`.trim())&&/<\/[\s]{0,}svg>$/i.test(`${t}`.trim())},html:function(t){let e=!1;if("string"==typeof t){let n=document.createElement("div");n.innerHTML=t,n.children.length>0&&(e=!0),n=null}return e},text:function(t){return"string"==typeof t},fontSize:function(t){return d(t)&&t>0},lineHeight:function(t){return d(t)&&t>0},textAlign:function(t){return["center","left","right"].includes(t)},fontFamily:function(t){return"string"==typeof t&&t.length>0},fontWeight:function(t){return["bold"].includes(t)},strokeWidth:function(t){return d(t)&&t>0}};function y(t={}){const{borderColor:e,borderRadius:n,borderWidth:i}=t;return!(t.hasOwnProperty("borderColor")&&!p.color(e))&&(!(t.hasOwnProperty("borderRadius")&&!p.number(n))&&!(t.hasOwnProperty("borderWidth")&&!p.number(i)))}const m={attrs:function(t){const{x:e,y:n,w:i,h:o,angle:r}=t;return!!(p.x(e)&&p.y(n)&&p.w(i)&&p.h(o)&&p.angle(r))&&(r>=-360&&r<=360)},textDesc:function(t){const{text:e,color:n,fontSize:i,lineHeight:o,fontFamily:r,textAlign:a,fontWeight:l,background:s,strokeWidth:c,strokeColor:u}=t;return!!p.text(e)&&(!!p.color(n)&&(!!p.fontSize(i)&&(!(t.hasOwnProperty("background")&&!p.color(s))&&(!(t.hasOwnProperty("fontWeight")&&!p.fontWeight(l))&&(!(t.hasOwnProperty("lineHeight")&&!p.lineHeight(o))&&(!(t.hasOwnProperty("fontFamily")&&!p.fontFamily(r))&&(!(t.hasOwnProperty("textAlign")&&!p.textAlign(a))&&(!(t.hasOwnProperty("strokeWidth")&&!p.strokeWidth(c))&&(!(t.hasOwnProperty("strokeColor")&&!p.color(u))&&!!y(t))))))))))},rectDesc:function(t){const{background:e}=t;return!(t.hasOwnProperty("background")&&!p.color(e))&&!!y(t)},circleDesc:function(t){const{background:e,borderColor:n,borderWidth:i}=t;return!(t.hasOwnProperty("background")&&!p.color(e))&&(!(t.hasOwnProperty("borderColor")&&!p.color(n))&&!(t.hasOwnProperty("borderWidth")&&!p.number(i)))},imageDesc:function(t){const{src:e}=t;return!!p.imageSrc(e)},svgDesc:function(t){const{svg:e}=t;return!!p.svg(e)},htmlDesc:function(t){const{html:e}=t;return!!p.html(e)}};class v{constructor(t,e){this._devicePixelRatio=1;const{devicePixelRatio:n=1}=e;this._ctx=t,this._devicePixelRatio=n}$undoPixelRatio(t){return t/this._devicePixelRatio}$doPixelRatio(t){return this._devicePixelRatio*t}$getContext(){return this._ctx}$setFont(t){const e=[];t.fontWeight&&e.push(`${t.fontWeight}`),e.push(`${this.$doPixelRatio(t.fontSize||12)}px`),e.push(`${t.fontFamily||"sans-serif"}`),this._ctx.font=`${e.join(" ")}`}$resize(t){const{width:e,height:n,devicePixelRatio:i}=t,{canvas:o}=this._ctx;o.width=e*i,o.height=n*i,this._devicePixelRatio=i}get canvas(){return this._ctx.canvas}get fillStyle(){return this._ctx.fillStyle}set fillStyle(t){this._ctx.fillStyle=t}get strokeStyle(){return this._ctx.strokeStyle}set strokeStyle(t){this._ctx.strokeStyle=t}get lineWidth(){return this.$undoPixelRatio(this._ctx.lineWidth)}set lineWidth(t){this._ctx.lineWidth=this.$doPixelRatio(t)}get textAlign(){return this._ctx.textAlign}set textAlign(t){this._ctx.textAlign=t}get textBaseline(){return this._ctx.textBaseline}set textBaseline(t){this._ctx.textBaseline=t}get globalAlpha(){return this._ctx.globalAlpha}set globalAlpha(t){this._ctx.globalAlpha=t}get shadowColor(){return this._ctx.shadowColor}set shadowColor(t){this._ctx.shadowColor=t}get shadowOffsetX(){return this.$undoPixelRatio(this._ctx.shadowOffsetX)}set shadowOffsetX(t){this._ctx.shadowOffsetX=this.$doPixelRatio(t)}get shadowOffsetY(){return this.$undoPixelRatio(this._ctx.shadowOffsetY)}set shadowOffsetY(t){this._ctx.shadowOffsetY=this.$doPixelRatio(t)}get shadowBlur(){return this.$undoPixelRatio(this._ctx.shadowBlur)}set shadowBlur(t){this._ctx.shadowBlur=this.$doPixelRatio(t)}get lineCap(){return this._ctx.lineCap}set lineCap(t){this._ctx.lineCap=t}get globalCompositeOperation(){return this._ctx.globalCompositeOperation}set globalCompositeOperation(t){this._ctx.globalCompositeOperation=t}fill(...t){return this._ctx.fill(...t)}arc(t,e,n,i,o,r){return this._ctx.arc(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),i,o,r)}rect(t,e,n,i){return this._ctx.rect(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i))}fillRect(t,e,n,i){return this._ctx.fillRect(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i))}clearRect(t,e,n,i){return this._ctx.clearRect(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i))}beginPath(){return this._ctx.beginPath()}closePath(){return this._ctx.closePath()}lineTo(t,e){return this._ctx.lineTo(this.$doPixelRatio(t),this.$doPixelRatio(e))}moveTo(t,e){return this._ctx.moveTo(this.$doPixelRatio(t),this.$doPixelRatio(e))}arcTo(t,e,n,i,o){return this._ctx.arcTo(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i),this.$doPixelRatio(o))}getLineDash(){return this._ctx.getLineDash()}setLineDash(t){const e=t.map((t=>this.$doPixelRatio(t)));return this._ctx.setLineDash(e)}stroke(t){return t?this._ctx.stroke(t):this._ctx.stroke()}translate(t,e){return this._ctx.translate(this.$doPixelRatio(t),this.$doPixelRatio(e))}rotate(t){return this._ctx.rotate(t)}drawImage(...t){const e=t[0],n=t[1],i=t[2],o=t[3],r=t[4],a=t[t.length-4],l=t[t.length-3],s=t[t.length-2],c=t[t.length-1];return 9===t.length?this._ctx.drawImage(e,this.$doPixelRatio(n),this.$doPixelRatio(i),this.$doPixelRatio(o),this.$doPixelRatio(r),this.$doPixelRatio(a),this.$doPixelRatio(l),this.$doPixelRatio(s),this.$doPixelRatio(c)):this._ctx.drawImage(e,this.$doPixelRatio(a),this.$doPixelRatio(l),this.$doPixelRatio(s),this.$doPixelRatio(c))}createPattern(t,e){return this._ctx.createPattern(t,e)}measureText(t){return this._ctx.measureText(t)}fillText(t,e,n,i){return void 0!==i?this._ctx.fillText(t,this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i)):this._ctx.fillText(t,this.$doPixelRatio(e),this.$doPixelRatio(n))}strokeText(t,e,n,i){return void 0!==i?this._ctx.strokeText(t,this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i)):this._ctx.strokeText(t,this.$doPixelRatio(e),this.$doPixelRatio(n))}save(){this._ctx.save()}restore(){this._ctx.restore()}scale(t,e){this._ctx.scale(t,e)}circle(t,e,n,i,o,r,a,l){this._ctx.ellipse(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i),o,r,a,l)}isPointInPath(t,e){return this._ctx.isPointInPath(this.$doPixelRatio(t),this.$doPixelRatio(e))}clip(...t){return this._ctx.clip(...t)}setTransform(t,e,n,i,o,r){return this._ctx.setTransform(t,e,n,i,o,r)}getTransform(){return this._ctx.getTransform()}createLinearGradient(t,e,n,i){return this._ctx.createLinearGradient(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i))}createRadialGradient(t,e,n,i,o,r){return this._ctx.createRadialGradient(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i),this.$doPixelRatio(o),this.$doPixelRatio(r))}createConicGradient(t,e,n){return this._ctx.createConicGradient(t,this.$doPixelRatio(e),this.$doPixelRatio(n))}}function b(t){const{width:e,height:n,ctx:i,devicePixelRatio:o}=t;let r=i;if(!r){const t=document.createElement("canvas");t.width=e*o,t.height=n*o,r=t.getContext("2d")}return new v(r,t)}function w(t,e){const n=(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y);return 0===n?n:Math.sqrt(n)}function P(t,e){return t.x===e.x&&t.y===e.y&&t.t===e.t}function $(t){return t>=0||t<0}function R(t){return $(t.x)&&$(t.y)&&t.t>0}function M(t,e){return{x:t.x+(e.x-t.x)/2,y:t.y+(e.y-t.y)/2}}function _(t){return t/180*Math.PI}function I(t,e,n,i){const o=_(e||0);n&&(o>0||o<0)&&(t.translate(n.x,n.y),t.rotate(o),t.translate(-n.x,-n.y)),i(t),n&&(o>0||o<0)&&(t.translate(n.x,n.y),t.rotate(-o),t.translate(-n.x,-n.y))}function S(t){return{x:t.x+t.w/2,y:t.y+t.h/2}}function E(t){const e=Math.min(t[0].x,t[1].x,t[2].x,t[3].x),n=Math.min(t[0].y,t[1].y,t[2].y,t[3].y);return S({x:e,y:n,w:Math.max(t[0].x,t[1].x,t[2].x,t[3].x)-e,h:Math.max(t[0].y,t[1].y,t[2].y,t[3].y)-n})}function k(t,e,n){const i=function(t,e){const n=e.x-t.x,i=e.y-t.y;if(0===n){if(i<0)return 0;if(i>0)return Math.PI}else if(0===i){if(n<0)return 3*Math.PI/2;if(n>0)return Math.PI/2}return n>0&&i<0?Math.atan(Math.abs(n)/Math.abs(i)):n>0&&i>0?Math.PI-Math.atan(Math.abs(n)/Math.abs(i)):n<0&&i>0?Math.PI+Math.atan(Math.abs(n)/Math.abs(i)):n<0&&i<0?2*Math.PI-Math.atan(Math.abs(n)/Math.abs(i)):0}(t,e);let o=i+n;o>2*Math.PI?o-=2*Math.PI:o<0-2*Math.PI&&(o+=2*Math.PI),o<0&&(o+=2*Math.PI);const r=w(t,e);let a=0,l=0;return 0===o?(a=0,l=0-r):o>0&&o<Math.PI/2?(a=Math.sin(o)*r,l=0-Math.cos(o)*r):o===Math.PI/2?(a=r,l=0):o>Math.PI/2&&o<Math.PI?(a=Math.sin(Math.PI-o)*r,l=Math.cos(Math.PI-o)*r):o===Math.PI?(a=0,l=r):o>Math.PI&&o<1.5*Math.PI?(a=0-Math.sin(o-Math.PI)*r,l=Math.cos(o-Math.PI)*r):o===1.5*Math.PI?(a=0-r,l=0):o>1.5*Math.PI&&o<2*Math.PI?(a=0-Math.sin(2*Math.PI-o)*r,l=0-Math.cos(2*Math.PI-o)*r):o===2*Math.PI&&(a=0,l=0-r),a+=t.x,l+=t.y,{x:a,y:l}}function A(t,e,n){const{x:i,y:o,w:r,h:a}=t;let l={x:i,y:o},s={x:i+r,y:o},c={x:i+r,y:o+a},u={x:i,y:o+a};if(n&&(n>0||n<0)){const t=_(T(n));l=k(e,l,t),s=k(e,s,t),c=k(e,c,t),u=k(e,u,t)}return[l,s,c,u]}function C(t){const{angle:e=0}=t;return A(t,S(t),e)}function O(t,e,n){return[k(t,{x:e[0].x,y:e[0].y},n),k(t,{x:e[1].x,y:e[1].y},n),k(t,{x:e[2].x,y:e[2].y},n),k(t,{x:e[3].x,y:e[3].y},n)]}function T(t){if(!(t>0||t<0)||0===t)return 0;let e=t%360;return e<0&&(e+=360),e}function L(t,e){const n={x:0,y:0,w:0,h:0};t.forEach((t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h,angle:t.angle};if(e.angle&&(e.angle>0||e.angle<0)){const t=C(e);if(4===t.length){const n=[t[0].x,t[1].x,t[2].x,t[3].x],i=[t[0].y,t[1].y,t[2].y,t[3].y];e.x=Math.min(...n),e.y=Math.min(...i),e.w=Math.abs(Math.max(...n)-Math.min(...n)),e.h=Math.abs(Math.max(...i)-Math.min(...i))}}const i=Math.min(e.x,n.x),o=Math.min(e.y,n.y),r=Math.max(e.x+e.w,n.x+n.w),a=Math.max(e.y+e.h,n.y+n.h);n.x=i,n.y=o,n.w=Math.abs(r-i),n.h=Math.abs(a-o)})),(null==e?void 0:e.extend)&&(n.x=Math.min(n.x,0),n.y=Math.min(n.y,0));const i={contextWidth:n.w,contextHeight:n.h};return(null==e?void 0:e.viewWidth)&&(null==e?void 0:e.viewHeight)&&(null==e?void 0:e.viewWidth)>0&&(null==e?void 0:e.viewHeight)>0&&(e.viewWidth>n.x+n.w&&(i.contextWidth=e.viewWidth-n.x),e.viewHeight>n.y+n.h&&(i.contextHeight=e.viewHeight-n.y)),i}function z(t,e){var n;const i=Object.keys(e);for(let o=0;o<i.length;o++){const r=i[o];["x","y","w","h","angle","name"].includes(r)?t[r]=e[r]:["detail","operations"].includes(r)&&(c.json(e[r])?((null==t?void 0:t.hasOwnProperty(r))||(t[r]={}),c.json(t[r])&&(t[r]={...t[r],...e[r]})):c.array(e[r])&&((null==t?void 0:t.hasOwnProperty(r))||(t[r]=[]),c.array(t[r])&&(null==(n=null==e?void 0:e[r])||n.forEach(((e,n)=>{t[r][n]=e})),t[r]=[...t[r],...e[r]])))}return t}function W(t,e){const n=t.x,i=t.y,o=t.x+t.w,r=t.y+t.h,a=e.x,l=e.y,s=e.x+e.w,c=e.y+e.h;return n<=s&&o>=a&&i<=c&&r>=l}function V(t,e){const{viewScaleInfo:n}=e,{x:i,y:o,w:r,h:a,angle:l}=t,{scale:s,offsetTop:c,offsetLeft:u}=n;return{x:i*s+u,y:o*s+c,w:r*s,h:a*s,angle:l}}function D(t,e){const{viewScaleInfo:n}=e,{x:i,y:o}=t,{scale:r,offsetTop:a,offsetLeft:l}=n;return{x:i*r+l,y:o*r+a}}function F(t,e){const{context2d:n,element:i,viewScaleInfo:o,viewSizeInfo:r}=e,{angle:a=0}=i,{x:l,y:s,w:c,h:u}=V(i,{viewScaleInfo:o,viewSizeInfo:r}),h=C({x:l,y:s,w:c,h:u,angle:a});if(h.length>=2){n.beginPath(),n.moveTo(h[0].x,h[0].y);for(let t=1;t<h.length;t++)n.lineTo(h[t].x,h[t].y);n.closePath()}return!!n.isPointInPath(t.x,t.y)}function H(t){const{x:e,y:n,h:i,w:o}=t;return[{x:e,y:n},{x:e+o,y:n},{x:e+o,y:n+i},{x:e,y:n+i}]}function j(t){const{x:e,y:n,w:i,h:o,angle:r=0}=t;return 0===r?H(t):A(t,S({x:e,y:n,w:i,h:o,angle:r}),r)}function B(t){const e=[];let n=0,i=0;const o=[],r=[...t];for(let t=0;t<r.length;t++){const{x:a,y:l,w:s,h:c,angle:u=0}=r[t];let h;if(n+=a,i+=l,0===t){const t={x:n,y:i,w:s,h:c,angle:u};h=j({x:a,y:l,w:s,h:c,angle:u}),o.push({center:S(t),angle:u,radian:_(u)})}else{h=H({x:n,y:i,w:s,h:c,angle:u});for(let t=0;t<o.length;t++){const{center:e,radian:n}=o[t];h=O(e,h,n)}const t=E(h);if(u>0||u<0){h=O(t,h,_(u))}o.push({center:t,angle:u,radian:_(u)})}e.push(h)}return e}function U(t,e){const{groupQueue:n}=e;if(!(n.length>0))return[j(t)];return B([...n,t])}function G(t,e){return U(t,e).pop()||null}function q(t,e){const{x:n,y:i}=t,{size:o,angle:r}=e;return{x:n-o/2,y:i-o/2,w:o,h:o,angle:r}}const Q=/([astvzqmhlc])([^astvzqmhlc]*)/gi,N=/(-?\d+(?:\.\d+)?)/gi;const X=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g,Y=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,Z=/^\s*$/,J={};function K(t){const e={type:"element",name:"",isVoid:!1,attributes:{},children:[]},n=t.match(/<\/?([^\s]+?)[/\s>]/);if(n&&(e.name=n[1],(J[n[1]]||"/"===t.charAt(t.length-2))&&(e.isVoid=!0),e.name.startsWith("!--"))){const e=t.indexOf("--\x3e");return{type:"comment",name:null,attributes:{},children:[],isVoid:!1,comment:-1!==e?t.slice(4,e):""}}const i=new RegExp(X);let o=null;for(;o=i.exec(t),null!==o;)if(o[0].trim())if(o[1]){const t=o[1].trim();let n=[t,""];t.indexOf("=")>-1&&(n=t.split("=")),e.attributes[n[0]]=n[1],i.lastIndex--}else o[2]&&(e.attributes[o[2]]=o[3].trim().substring(1,o[3].length-1));return e}function tt(t,e){switch(e.type){case"text":return t+e.textContent;case"element":return t+="<"+e.name+(e.attributes?function(t){const e=[];for(let n in t)e.push(n+'="'+t[n]+'"');return e.length?" "+e.join(" "):""}(e.attributes):"")+(e.isVoid?"/>":">"),e.isVoid?t:t+e.children.reduce(tt,"")+"</"+e.name+">";case"comment":return t+="\x3c!--"+e.comment+"--\x3e"}}function et(t){return t[1]!=-1*t[3]||t[4]!=t[0]||t[0]*t[4]-t[3]*t[1]!=1?null:Math.acos(t[0])}function nt(){return{boxSizing:"center-line",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}}const it={boxSizing:"center-line",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};return t.Context2D=v,t.EventEmitter=class{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const n=this._listeners.get(t)||[];null==n||n.push(e),this._listeners.set(t,n)}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const n=this._listeners.get(t);if(Array.isArray(n))for(let t=0;t<(null==n?void 0:n.length);t++)if(n[t]===e){n.splice(t,1);break}this._listeners.set(t,n||[])}}trigger(t,e){const n=this._listeners.get(t);return!!Array.isArray(n)&&(n.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}},t.Store=class{constructor(t){this._backUpDefaultStorage=l(t.defaultStorage),this._temp=this._createTempStorage()}set(t,e){this._temp[t]=e}get(t){return this._temp[t]}getSnapshot(){return l(this._temp)}clear(){this._temp=this._createTempStorage()}_createTempStorage(){return l(this._backUpDefaultStorage)}},t.calcDistance=w,t.calcElementCenter=S,t.calcElementCenterFromVertexes=E,t.calcElementQueueVertexesQueueInGroup=B,t.calcElementSizeController=function(t,e){const{groupQueue:n,controllerSize:o,viewScaleInfo:r}=e,a=(o&&o>0?o:8)/r.scale,{x:l,y:s,w:c,h:u,angle:h=0}=t,d=[{uuid:i(),x:l,y:s,w:c,h:u,angle:h,type:"group",detail:{children:[]}},...n];let f=0;d.forEach((({angle:t=0})=>{f+=t}));const g=G(t,{groupQueue:n}),x=M(g[0],g[1]),p=M(g[1],g[2]),y=M(g[2],g[3]),m=M(g[3],g[0]),v=g[0],b=g[1],w=g[2],P=g[3],$=q(v,{size:a,angle:f}),R=q(b,{size:a,angle:f}),_=q(P,{size:a,angle:f}),I=q(w,{size:a,angle:f}),S=j($),E=j(R),k=j(_),A=j(I),C=[S[1],E[0],E[3],S[2]],O=[E[3],E[2],A[1],A[0]],T=[k[1],A[0],A[3],k[2]];return{elementWrapper:g,left:{type:"left",vertexes:[S[3],S[2],k[1],k[0]],center:m},right:{type:"right",vertexes:O,center:p},top:{type:"top",vertexes:C,center:x},bottom:{type:"bottom",vertexes:T,center:y},topLeft:{type:"top-left",vertexes:S,center:v},topRight:{type:"top-right",vertexes:E,center:b},bottomLeft:{type:"bottom-left",vertexes:k,center:P},bottomRight:{type:"bottom-right",vertexes:A,center:w}}},t.calcElementVertexesInGroup=G,t.calcElementVertexesQueueInGroup=U,t.calcElementsContextSize=L,t.calcElementsViewInfo=function(t,e,n){const i=L(t,{viewWidth:e.width,viewHeight:e.height,extend:null==n?void 0:n.extend});return!0===(null==n?void 0:n.extend)&&(i.contextWidth=Math.max(i.contextWidth,e.contextWidth),i.contextHeight=Math.max(i.contextHeight,e.contextHeight)),{contextSize:i}},t.calcSpeed=function(t,e){return w(t,e)/Math.abs(e.t-t.t)},t.calcViewBoxSize=function(t,e){const{viewScaleInfo:n}=e,{scale:i}=n;let{borderRadius:o,boxSizing:r=it.boxSizing,borderWidth:a}=t.detail;"number"!=typeof a&&(o=0);let{x:l,y:s,w:c,h:u}=t,h=[0,0,0,0];if("number"==typeof o){const t=o*i;h=[t,t,t,t]}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 d=0;return"number"==typeof a&&(d=(a||1)*i),"border-box"===r?(l=t.x+d/2,s=t.y+d/2,c=t.w-d,u=t.h-d):"content-box"===r?(l=t.x-d/2,s=t.y-d/2,c=t.w+d,u=t.h+d):(l=t.x,s=t.y,c=t.w,u=t.h),{x:l,y:s,w:c,h:u,radiusList:h}},t.calcViewElementSize=V,t.calcViewPointSize=D,t.calcViewVertexes=function(t,e){return[D(t[0],e),D(t[1],e),D(t[2],e),D(t[3],e)]},t.check=m,t.checkRectIntersect=W,t.colorNameToHex=function(t){const e=t.toLowerCase(),i=n[e];return"string"==typeof i?i:null},t.colorToCSS=function(t){let e="transparent";if("string"==typeof t)e=t;else if("linear-gradient"===(null==t?void 0:t.type)){const n=[];"number"==typeof t.angle?n.push(`${t.angle}deg`):n.push("180deg"),Array.isArray(t.stops)&&t.stops.forEach((t=>{n.push(`${t.color} ${100*t.offset}%`)})),e=`linear-gradient(${n.join(", ")})`}else if("radial-gradient"===(null==t?void 0:t.type)){const n=[];Array.isArray(t.stops)&&t.stops.forEach((t=>{n.push(`${t.color} ${100*t.offset}%`)})),e=`radial-gradient(circle, ${n.join(", ")})`}return e},t.colorToLinearGradientCSS=function(t){let e="transparent";if("string"==typeof t)e=t;else if("radial-gradient"===(null==t?void 0:t.type)||"linear-gradient"===(null==t?void 0:t.type)){const n=[];Array.isArray(t.stops)&&t.stops.length>0&&(t.stops.forEach(((e,i)=>{n.push(`${e.color} ${100*e.offset}%`),i===t.stops.length-1&&e.offset<1&&n.push(`${e.color} ${100*e.offset}%`)})),e=`linear-gradient(90deg, ${n.join(", ")})`)}return e},t.compose=function(t){return function(e,n){return function i(o){let r=t[o];o===t.length&&n&&(r=n);if(!r)return Promise.resolve();try{return Promise.resolve(r(e,i.bind(null,o+1)))}catch(t){return Promise.reject(t)}}(0)}},t.compressImage=function(t,e){let n=.5;const i=(null==e?void 0:e.type)||"image/png";return(null==e?void 0:e.radio)&&(null==e?void 0:e.radio)>0&&(null==e?void 0:e.radio)<=1&&(n=null==e?void 0:e.radio),new Promise(((e,o)=>{const r=new Image;r.addEventListener("load",(()=>{const{width:t,height:o}=r,a=t*n,l=o*n;let s=document.createElement("canvas");s.width=a,s.height=l;s.getContext("2d").drawImage(r,0,0,a,l);const c=s.toDataURL(i);s=null,e(c)})),r.addEventListener("error",(t=>{o(t)})),r.src=t}))},t.createAssetId=r,t.createBoardContexts=function(t,e){const n={width:t.canvas.width,height:t.canvas.height,devicePixelRatio:(null==e?void 0:e.devicePixelRatio)||1},i=b(n),o=b(n);return{underContext:b(n),viewContext:i,helperContext:o,boardContext:b({ctx:t,...n})}},t.createContext2D=b,t.createOffscreenContext2D=function(t){const{width:e,height:n}=t;return new OffscreenCanvas(e,n).getContext("2d").canvas.getContext("2d")},t.createUUID=i,t.deepClone=l,t.delay=function(t){return new Promise((e=>{setTimeout((()=>{e()}),t)}))},t.downloadImageFromCanvas=function(t,e){const{filename:n,type:i="image/jpeg"}=e,o=t.toDataURL(i),r=document.createElement("a");r.href=o,r.download=n;const a=document.createEvent("MouseEvents");a.initEvent("click",!0,!1),r.dispatchEvent(a)},t.equalPoint=P,t.equalTouchPoint=function(t,e){return!0===P(t,e)&&t.f===e.f},t.filterElementAsset=function(t){let e=null,n=null,i=null;return"image"===t.type?i=t.detail.src:"svg"===t.type?i=t.detail.svg:"html"===t.type&&(i=t.detail.html),"string"!=typeof i||a(i)||(e=r(i),n={type:t.type,value:i},"image"===t.type?t.detail.src=e:"svg"===t.type?t.detail.svg=e:"html"===t.type&&(t.detail.html=e)),{element:t,assetId:e,assetItem:n}},t.findElementFromList=function t(e,n){var i;let o=null;for(let r=0;r<n.length;r++){const a=n[r];if(a.uuid===e){o=a;break}if(!o&&"group"===a.type){const n=t(e,(null==(i=null==a?void 0:a.detail)?void 0:i.children)||[]);if((null==n?void 0:n.uuid)===e){o=n;break}}}return o},t.findElementsFromList=function(t,e){const n=[];return function e(i){var o;for(let r=0;r<i.length;r++){const a=i[r];t.includes(a.uuid)?n.push(a):"group"===a.type&&e((null==(o=null==a?void 0:a.detail)?void 0:o.children)||[])}}(e),n},t.formatNumber=function(t,e){let n=2;return void 0!==(null==e?void 0:e.decimalPlaces)&&(null==e?void 0:e.decimalPlaces)>=0&&(n=e.decimalPlaces),parseFloat(t.toFixed(n))},t.generateHTML=function(t){return t.reduce((function(t,e){return t+tt("",e)}),"")},t.generateSVGPath=function(t){let e="";return t.forEach((t=>{e+=t.type+t.params.join(" ")})),e},t.getCenterFromTwoPoints=M,t.getDefaultElementDetailConfig=nt,t.getElemenetsAssetIds=function(t){const e=[],n=t=>{t.forEach((t=>{"image"===t.type&&a(t.detail.src)?e.push(t.detail.src):"svg"===t.type&&a(t.detail.svg)?e.push(t.detail.svg):"html"===t.type&&t.detail.html?e.push(t.detail.html):"group"===t.type&&Array.isArray(t.detail.children)&&n(t.detail.children)}))};return n(t),e},t.getElementRotateVertexes=A,t.getElementSize=function(t){const{x:e,y:n,w:i,h:o,angle:r}=t;return{x:e,y:n,w:i,h:o,angle:r}},t.getElementVertexes=H,t.getGroupQueueFromList=function(t,e){const n=[];return function t(e,i){var o;let r=null;for(let a=0;a<i.length;a++){const l=i[a];if(l.uuid===e){r=l;break}if(!r&&"group"===l.type){n.push(l);const i=t(e,(null==(o=null==l?void 0:l.detail)?void 0:o.children)||[]);if((null==i?void 0:i.uuid)===e){r=i;break}n.pop()}}return r}(t,e),n},t.getSelectedElementUUIDs=function(t,e){var n;let i=[];return Array.isArray(null==t?void 0:t.elements)&&(null==(n=null==t?void 0:t.elements)?void 0:n.length)>0&&Array.isArray(e)&&e.length>0&&e.forEach((e=>{var n;"number"==typeof e?(null==(n=null==t?void 0:t.elements)?void 0:n[e])&&i.push(t.elements[e].uuid):"string"==typeof e&&(i=i.concat(function(t,e){var n;const i=[];if("string"==typeof e&&/^\d+(\.\d+)*$/.test(e)){const o=e.split(".");let r=t;for(;o.length>0;){const t=o.shift();if("string"==typeof t){const e=r[parseInt(t)];e&&0===o.length?i.push(e.uuid):"group"===e.type&&o.length>0&&(r=(null==(n=null==e?void 0:e.detail)?void 0:n.children)||[])}break}}return i}(t.elements,e)))})),i},t.getViewPointAtElement=function(t,e){var n,i,o;const{context2d:r,data:a,viewScaleInfo:l,viewSizeInfo:s,groupQueue:c}=e,u={index:-1,element:null,groupQueueIndex:-1};if(c&&Array.isArray(c)&&(null==c?void 0:c.length)>0)for(let e=c.length-1;e>=0;e--){let o=0,a=0,h=0;for(let t=0;t<=e;t++)o+=c[t].x,a+=c[t].y,h+=c[t].angle||0;const d=c[e];if(d&&"group"===d.type&&Array.isArray(null==(n=d.detail)?void 0:n.children))for(let n=0;n<d.detail.children.length;n++){const f=d.detail.children[n];if(!0!==(null==(i=null==f?void 0:f.operations)?void 0:i.invisible)){if(!f)break;if(F(t,{context2d:r,element:{x:o+f.x,y:a+f.y,w:f.w,h:f.h,angle:h+(f.angle||0)},viewScaleInfo:l,viewSizeInfo:s})){u.element=f,(e<c.length-1||"group"!==f.type)&&(u.groupQueueIndex=e);break}}}if(u.element)break}if(u.element)return u;for(let e=a.elements.length-1;e>=0;e--){const n=a.elements[e];if(!0!==(null==(o=null==n?void 0:n.operations)?void 0:o.invisible)&&F(t,{context2d:r,element:n,viewScaleInfo:l,viewSizeInfo:s})){u.index=e,u.element=n;break}}return u},t.getViewScaleInfoFromSnapshot=function(t){const{activeStore:e}=t;return{scale:null==e?void 0:e.scale,offsetTop:null==e?void 0:e.offsetTop,offsetBottom:null==e?void 0:e.offsetBottom,offsetLeft:null==e?void 0:e.offsetLeft,offsetRight:null==e?void 0:e.offsetRight}},t.getViewSizeInfoFromSnapshot=function(t){const{activeStore:e}=t;return{devicePixelRatio:e.devicePixelRatio,width:null==e?void 0:e.width,height:null==e?void 0:e.height,contextWidth:null==e?void 0:e.contextWidth,contextHeight:null==e?void 0:e.contextHeight}},t.is=p,t.isAssetId=a,t.isColorStr=e,t.isElementInView=function(t,e){const{viewSizeInfo:n,viewScaleInfo:i}=e,{width:o,height:r}=n,{angle:a}=t,{x:l,y:s,w:c,h:u}=V(t,{viewScaleInfo:i,viewSizeInfo:n}),h=C({x:l,y:s,w:c,h:u,angle:a}),d={x:0,y:0,w:o,h:r},f=Math.min(h[0].x,h[1].x,h[2].x,h[3].x),g=Math.min(h[0].y,h[1].y,h[2].y,h[3].y);return W(d,{x:f,y:g,w:Math.max(h[0].x,h[1].x,h[2].x,h[3].x)-f,h:Math.max(h[0].y,h[1].y,h[2].y,h[3].y)-g})},t.isResourceElement=function(t){return["image","svg","html"].includes(null==t?void 0:t.type)},t.isViewPointInElement=F,t.istype=c,t.limitAngle=T,t.loadHTML=async function(t,e){t=t.replace(/\&/gi,"&");const n=await function(t,e){const{width:n,height:i}=e;return new Promise(((e,o)=>{const r=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 ${t}\n </div>\n </foreignObject>\n </svg>\n `],{type:"image/svg+xml;charset=utf-8"}),a=new FileReader;a.readAsDataURL(r),a.onload=function(t){var n;const i=null==(n=null==t?void 0:t.target)?void 0:n.result;e(i)},a.onerror=function(t){o(t)}}))}(t,e);return await h(n)},t.loadImage=h,t.loadSVG=async function(t){const e=await function(t){return new Promise(((e,n)=>{const i=new Blob([t],{type:"image/svg+xml;charset=utf-8"}),o=new FileReader;o.readAsDataURL(i),o.onload=function(t){var n;const i=null==(n=null==t?void 0:t.target)?void 0:n.result;e(i)},o.onerror=function(t){n(t)}}))}(t);return await h(e)},t.matrixToAngle=function(t){const e=et(t);if("number"==typeof e){return 180*e/Math.PI}return e},t.matrixToRadian=et,t.mergeElementAsset=function(t,e){const n=t;let i=null,o=null;return"image"===n.type?i=n.detail.src:"svg"===n.type?i=n.detail.svg:"html"===n.type&&(i=n.detail.html),i&&(null==i?void 0:i.startsWith("@assets/"))&&(o=e[i]),(null==o?void 0:o.type)===n.type&&"string"==typeof(null==o?void 0:o.value)&&(null==o?void 0:o.value)&&("image"===n.type?n.detail.src=o.value:"svg"===n.type?n.detail.svg=o.value:"html"===n.type&&(n.detail.html=o.value)),n},t.mergeHexColorAlpha=function(t,e){if(1===e)return t;let n=1;const i=/^\#[0-9a-f]{6,6}$/i;let o=t;if(i.test(t)?n=parseInt(t.substring(5,7).replace(/^\#/,"0x")):/^\#[0-9a-f]{8,8}$/i.test(t)&&(n=parseInt(t.substring(7,9).replace(/^\#/,"0x")),o=t.substring(0,7)),n*=e,i.test(o)&&n>0&&n<1){const t=Math.max(0,Math.min(255,Math.ceil(256*n)));o=`${o.toUpperCase()}${t.toString(16).toUpperCase()}`}return o},t.parseAngleToRadian=_,t.parseFileToBase64=function(t){return new Promise((function(e,n){let i=new FileReader;i.addEventListener("load",(function(){e(i.result),i=null})),i.addEventListener("error",(function(t){n(t),i=null})),i.addEventListener("abort",(function(){n(new Error("abort")),i=null})),i.readAsDataURL(t)}))},t.parseFileToText=function(t){return new Promise((function(e,n){let i=new FileReader;i.addEventListener("load",(function(){e(i.result),i=null})),i.addEventListener("error",(function(t){n(t),i=null})),i.addEventListener("abort",(function(){n(new Error("abort")),i=null})),i.readAsText(t)}))},t.parseHTML=function(t){const e=[],n=[];let i,o=-1;return t.replace(Y,((r,a)=>{const l="/"!==r.charAt(1),s=r.startsWith("\x3c!--"),c=a+r.length,u=t.charAt(c);let h;if(s){const t=K(r);return o<0?(e.push(t),r):(h=n[o],h.children.push(t),r)}if(l){if(o++,i=K(r),!i.isVoid&&u&&"<"!==u){const e=t.slice(c,t.indexOf("<",c));e.trim()&&i.children.push({type:"text",name:null,attributes:{},children:[],isVoid:!1,textContent:e.trim()})}0===o&&e.push(i),h=n[o-1],h&&h.children.push(i),n[o]=i}if((!l||!Array.isArray(i)&&i.isVoid)&&(o>-1&&!Array.isArray(i)&&(i.isVoid||i.name===r.slice(2,-1))&&(o--,i=-1===o?e:n[o]),"<"!==u&&u)){h=-1===o?e:n[o].children;const i=t.indexOf("<",c);let r=t.slice(c,-1===i?void 0:i);Z.test(r)&&(r=" "),(i>-1&&o+h.length>=0||" "!==r)&&r.trim()&&h.push({type:"text",name:null,attributes:{},children:[],isVoid:!1,textContent:r.trim()})}return r})),e},t.parseRadianToAngle=function(t){return t/Math.PI*180},t.parseSVGPath=function(t){const e=[];return t.replace(Q,((t,n,i)=>{const o=i.match(N),r={type:n,params:o?o.map(Number):[]};return e.push(r),t})),e},t.pickFile=function(t){const{success:e,error:n}=t;let i=document.createElement("input");i.type="file",i.addEventListener("change",(function(){var t;const n=null==(t=i.files)?void 0:t[0];e({file:n}),i=null})),i.addEventListener("error",(function(t){"function"==typeof n&&n(t),i=null})),i.click()},t.rotateByCenter=I,t.rotateElement=function(t,e,n){const i=S(e);I(t,e.angle||0,i,(()=>{n(t)}))},t.rotateElementVertexes=C,t.rotatePoint=k,t.rotatePointInGroup=function(t,e){if((null==e?void 0:e.length)>0){let n=t.x,i=t.y;return e.forEach((t=>{const{x:e,y:o,w:r,h:a,angle:l=0}=t,s=k(S({x:e,y:o,w:r,h:a,angle:l}),{x:n,y:i},_(l));n=s.x,i=s.y})),{x:n,y:i}}return t},t.rotateVertexes=O,t.sortDataAsserts=function(t,e){const n=t.assets||{};let i=t;!0===(null==e?void 0:e.clone)&&(i=l(t));const o=t=>{t.forEach((t=>{if("image"===t.type&&t.detail.src){const e=t.detail.src,i=r(e);n[i]||(n[i]={type:"image",value:e}),t.detail.src=i}else if("svg"===t.type){const e=t.detail.svg,i=r(e);n[i]||(n[i]={type:"svg",value:e}),t.detail.svg=i}else if("html"===t.type){const e=t.detail.html,i=r(e);n[i]||(n[i]={type:"svg",value:e}),t.detail.html=i}else if("group"===t.type&&Array.isArray(t.detail.children)){const e=t.detail.assets||{};Object.keys(e).forEach((t=>{n[t]||(n[t]=e[t])})),delete t.detail.assets,o(t.detail.children)}}))};return o(i.elements),i.assets=n,i},t.throttle=function(t,e){let n=-1;return function(...i){n>0||(n=setTimeout((()=>{t(...i),n=-1}),e))}},t.toColorHexNum=function(t){return parseInt(t.replace(/^\#/,"0x"))},t.toColorHexStr=function(t){return"#"+t.toString(16)},t.updateElementInList=function t(e,n,i){var o;let r=null;for(let a=0;a<i.length;a++){const l=i[a];if(l.uuid===e){z(l,n),r=l;break}"group"===l.type&&(r=t(e,n,(null==(o=null==l?void 0:l.detail)?void 0:o.children)||[]))}return r},t.vaildPoint=R,t.vaildTouchPoint=function(t){return!0===R(t)&&t.f>=0},t.validateElements=function t(e){let n=!0;if(Array.isArray(e)){const i=[];e.forEach((e=>{var o;"string"==typeof e.uuid&&e.uuid?i.includes(e.uuid)?(n=!1,console.warn(`Duplicate uuids: ${e.uuid}`)):i.push(e.uuid):(n=!1,console.warn("Element missing uuid",e)),"group"===e.type&&(n=t(null==(o=null==e?void 0:e.detail)?void 0:o.children))}))}return n},t.viewScale=function(t){const{scale:e,point:n,viewScaleInfo:i}=t,{offsetLeft:o,offsetTop:r}=i,a=e/i.scale,l=n.x,s=n.y;return{moveX:l-l*a+(o*a-o),moveY:s-s*a+(r*a-r)}},t.viewScroll=function(t){const{moveX:e=0,moveY:n=0,viewScaleInfo:i,viewSizeInfo:o}=t,{scale:r}=i,{width:a,height:l,contextWidth:s,contextHeight:c}=o;let u=i.offsetLeft,h=i.offsetRight,d=i.offsetTop,f=i.offsetBottom;return u+=e,d+=n,h=a-(s*r+u),f=l-(c*r+d),{scale:r,offsetTop:d,offsetLeft:u,offsetRight:h,offsetBottom:f}},Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),t}({});
|
|
1
|
+
var iDrawUtil=function(t){"use strict";function e(t){return"string"==typeof t&&(/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)||/^[a-z]{1,}$/i.test(t))}const n={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4","indianred ":"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};function i(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${t()}${t()}-${t()}-${t()}-${t()}-${t()}${t()}${t()}`}function o(t){let e=0;for(let n=0;n<t.length;n++)e+=t.charCodeAt(n)*t.charCodeAt(n)*n*n;return e.toString(16).substring(0,4)}function r(t){const e=t.length,n=Math.floor(e/2),i=t.substring(0,4).padEnd(4,"0"),r=t.substring(0,4).padEnd(4,"0");return`@assets/${o(e.toString(16).padEnd(4,i))}${o(t.substring(n-4,n).padEnd(4,i)).padEnd(4,"f")}-${o(t.substring(n-8,n-4).padEnd(4,i)).padEnd(4,"f")}-${o(t.substring(n-12,n-8).padEnd(4,i)).padEnd(4,"f")}-${o(t.substring(n-16,n-12).padEnd(4,r)).padEnd(4,"f")}-${o(t.substring(n,n+4).padEnd(4,r)).padEnd(4,"f")}${o(t.substring(n+4,n+8).padEnd(4,r)).padEnd(4,"f")}${o(r.padEnd(4,i).padEnd(4,r))}`}function l(t){return/^@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(`${t}`)}function a(t){return function t(e){const n=function(t){return Object.prototype.toString.call(t).replace(/[\]|\[]{1,1}/gi,"").split(" ")[1]}(e);if(["Null","Number","String","Boolean","Undefined"].indexOf(n)>=0)return e;if("Array"===n){const n=[];return e.forEach((e=>{n.push(t(e))})),n}if("Object"===n){const n={};Object.keys(e).forEach((i=>{n[i]=t(e[i])}));return Object.getOwnPropertySymbols(e).forEach((i=>{n[i]=t(e[i])})),n}}(t)}function s(t){return(Object.prototype.toString.call(t)||"").replace(/(\[object|\])/gi,"").trim()}const c={type(t,e){const n=s(t);return!0===e?n.toLocaleLowerCase():n},array:t=>"Array"===s(t),json:t=>"Object"===s(t),function:t=>"Function"===s(t),asyncFunction:t=>"AsyncFunction"===s(t),string:t=>"String"===s(t),number:t=>"Number"===s(t),undefined:t=>"Undefined"===s(t),null:t=>"Null"===s(t),promise:t=>"Promise"===s(t)};const{Image:u}=window;function f(t){return new Promise(((e,n)=>{const i=new u;i.crossOrigin="anonymous",i.onload=function(){e(i)},i.onabort=n,i.onerror=n,i.src=t}))}function h(t){return"number"==typeof t&&(t>0||t<=0)}function d(t){return"number"==typeof t&&t>=0}function g(t){return"string"==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${t}`)}function x(t){return"string"==typeof t&&/^(data:image\/)/.test(`${t}`)}const y={x:function(t){return h(t)},y:function(t){return h(t)},w:d,h:function(t){return"number"==typeof t&&t>=0},angle:function(t){return"number"==typeof t&&t>=-360&&t<=360},number:h,numberStr:function(t){return/^(-?\d+(?:\.\d+)?)$/.test(`${t}`)},borderWidth:function(t){return d(t)},borderRadius:function(t){return h(t)&&t>=0},color:function(t){return e(t)},imageSrc:function(t){return x(t)||g(t)},imageURL:g,imageBase64:x,svg:function(t){return"string"==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test(`${t}`.trim())&&/<\/[\s]{0,}svg>$/i.test(`${t}`.trim())},html:function(t){let e=!1;if("string"==typeof t){let n=document.createElement("div");n.innerHTML=t,n.children.length>0&&(e=!0),n=null}return e},text:function(t){return"string"==typeof t},fontSize:function(t){return h(t)&&t>0},lineHeight:function(t){return h(t)&&t>0},textAlign:function(t){return["center","left","right"].includes(t)},fontFamily:function(t){return"string"==typeof t&&t.length>0},fontWeight:function(t){return["bold"].includes(t)},strokeWidth:function(t){return h(t)&&t>0}};function p(t={}){const{borderColor:e,borderRadius:n,borderWidth:i}=t;return!(t.hasOwnProperty("borderColor")&&!y.color(e))&&(!(t.hasOwnProperty("borderRadius")&&!y.number(n))&&!(t.hasOwnProperty("borderWidth")&&!y.number(i)))}const m={attrs:function(t){const{x:e,y:n,w:i,h:o,angle:r}=t;return!!(y.x(e)&&y.y(n)&&y.w(i)&&y.h(o)&&y.angle(r))&&(r>=-360&&r<=360)},textDesc:function(t){const{text:e,color:n,fontSize:i,lineHeight:o,fontFamily:r,textAlign:l,fontWeight:a,background:s,strokeWidth:c,strokeColor:u}=t;return!!y.text(e)&&(!!y.color(n)&&(!!y.fontSize(i)&&(!(t.hasOwnProperty("background")&&!y.color(s))&&(!(t.hasOwnProperty("fontWeight")&&!y.fontWeight(a))&&(!(t.hasOwnProperty("lineHeight")&&!y.lineHeight(o))&&(!(t.hasOwnProperty("fontFamily")&&!y.fontFamily(r))&&(!(t.hasOwnProperty("textAlign")&&!y.textAlign(l))&&(!(t.hasOwnProperty("strokeWidth")&&!y.strokeWidth(c))&&(!(t.hasOwnProperty("strokeColor")&&!y.color(u))&&!!p(t))))))))))},rectDesc:function(t){const{background:e}=t;return!(t.hasOwnProperty("background")&&!y.color(e))&&!!p(t)},circleDesc:function(t){const{background:e,borderColor:n,borderWidth:i}=t;return!(t.hasOwnProperty("background")&&!y.color(e))&&(!(t.hasOwnProperty("borderColor")&&!y.color(n))&&!(t.hasOwnProperty("borderWidth")&&!y.number(i)))},imageDesc:function(t){const{src:e}=t;return!!y.imageSrc(e)},svgDesc:function(t){const{svg:e}=t;return!!y.svg(e)},htmlDesc:function(t){const{html:e}=t;return!!y.html(e)}};class v{constructor(t,e){this._devicePixelRatio=1;const{devicePixelRatio:n=1}=e;this._ctx=t,this._devicePixelRatio=n}$undoPixelRatio(t){return t/this._devicePixelRatio}$doPixelRatio(t){return this._devicePixelRatio*t}$getContext(){return this._ctx}$setFont(t){const e=[];t.fontWeight&&e.push(`${t.fontWeight}`),e.push(`${this.$doPixelRatio(t.fontSize||12)}px`),e.push(`${t.fontFamily||"sans-serif"}`),this._ctx.font=`${e.join(" ")}`}$resize(t){const{width:e,height:n,devicePixelRatio:i}=t,{canvas:o}=this._ctx;o.width=e*i,o.height=n*i,this._devicePixelRatio=i}get canvas(){return this._ctx.canvas}get fillStyle(){return this._ctx.fillStyle}set fillStyle(t){this._ctx.fillStyle=t}get strokeStyle(){return this._ctx.strokeStyle}set strokeStyle(t){this._ctx.strokeStyle=t}get lineWidth(){return this.$undoPixelRatio(this._ctx.lineWidth)}set lineWidth(t){this._ctx.lineWidth=this.$doPixelRatio(t)}get textAlign(){return this._ctx.textAlign}set textAlign(t){this._ctx.textAlign=t}get textBaseline(){return this._ctx.textBaseline}set textBaseline(t){this._ctx.textBaseline=t}get globalAlpha(){return this._ctx.globalAlpha}set globalAlpha(t){this._ctx.globalAlpha=t}get shadowColor(){return this._ctx.shadowColor}set shadowColor(t){this._ctx.shadowColor=t}get shadowOffsetX(){return this.$undoPixelRatio(this._ctx.shadowOffsetX)}set shadowOffsetX(t){this._ctx.shadowOffsetX=this.$doPixelRatio(t)}get shadowOffsetY(){return this.$undoPixelRatio(this._ctx.shadowOffsetY)}set shadowOffsetY(t){this._ctx.shadowOffsetY=this.$doPixelRatio(t)}get shadowBlur(){return this.$undoPixelRatio(this._ctx.shadowBlur)}set shadowBlur(t){this._ctx.shadowBlur=this.$doPixelRatio(t)}get lineCap(){return this._ctx.lineCap}set lineCap(t){this._ctx.lineCap=t}get globalCompositeOperation(){return this._ctx.globalCompositeOperation}set globalCompositeOperation(t){this._ctx.globalCompositeOperation=t}fill(...t){return this._ctx.fill(...t)}arc(t,e,n,i,o,r){return this._ctx.arc(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),i,o,r)}rect(t,e,n,i){return this._ctx.rect(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i))}fillRect(t,e,n,i){return this._ctx.fillRect(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i))}clearRect(t,e,n,i){return this._ctx.clearRect(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i))}beginPath(){return this._ctx.beginPath()}closePath(){return this._ctx.closePath()}lineTo(t,e){return this._ctx.lineTo(this.$doPixelRatio(t),this.$doPixelRatio(e))}moveTo(t,e){return this._ctx.moveTo(this.$doPixelRatio(t),this.$doPixelRatio(e))}arcTo(t,e,n,i,o){return this._ctx.arcTo(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i),this.$doPixelRatio(o))}getLineDash(){return this._ctx.getLineDash()}setLineDash(t){const e=t.map((t=>this.$doPixelRatio(t)));return this._ctx.setLineDash(e)}stroke(t){return t?this._ctx.stroke(t):this._ctx.stroke()}translate(t,e){return this._ctx.translate(this.$doPixelRatio(t),this.$doPixelRatio(e))}rotate(t){return this._ctx.rotate(t)}drawImage(...t){const e=t[0],n=t[1],i=t[2],o=t[3],r=t[4],l=t[t.length-4],a=t[t.length-3],s=t[t.length-2],c=t[t.length-1];return 9===t.length?this._ctx.drawImage(e,this.$doPixelRatio(n),this.$doPixelRatio(i),this.$doPixelRatio(o),this.$doPixelRatio(r),this.$doPixelRatio(l),this.$doPixelRatio(a),this.$doPixelRatio(s),this.$doPixelRatio(c)):this._ctx.drawImage(e,this.$doPixelRatio(l),this.$doPixelRatio(a),this.$doPixelRatio(s),this.$doPixelRatio(c))}createPattern(t,e){return this._ctx.createPattern(t,e)}measureText(t){return this._ctx.measureText(t)}fillText(t,e,n,i){return void 0!==i?this._ctx.fillText(t,this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i)):this._ctx.fillText(t,this.$doPixelRatio(e),this.$doPixelRatio(n))}strokeText(t,e,n,i){return void 0!==i?this._ctx.strokeText(t,this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i)):this._ctx.strokeText(t,this.$doPixelRatio(e),this.$doPixelRatio(n))}save(){this._ctx.save()}restore(){this._ctx.restore()}scale(t,e){this._ctx.scale(t,e)}circle(t,e,n,i,o,r,l,a){this._ctx.ellipse(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i),o,r,l,a)}isPointInPath(t,e){return this._ctx.isPointInPath(this.$doPixelRatio(t),this.$doPixelRatio(e))}clip(...t){return this._ctx.clip(...t)}setTransform(t,e,n,i,o,r){return this._ctx.setTransform(t,e,n,i,o,r)}getTransform(){return this._ctx.getTransform()}createLinearGradient(t,e,n,i){return this._ctx.createLinearGradient(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i))}createRadialGradient(t,e,n,i,o,r){return this._ctx.createRadialGradient(this.$doPixelRatio(t),this.$doPixelRatio(e),this.$doPixelRatio(n),this.$doPixelRatio(i),this.$doPixelRatio(o),this.$doPixelRatio(r))}createConicGradient(t,e,n){return this._ctx.createConicGradient(t,this.$doPixelRatio(e),this.$doPixelRatio(n))}}function w(t){const{width:e,height:n,ctx:i,devicePixelRatio:o}=t;let r=i;if(!r){const t=document.createElement("canvas");t.width=e*o,t.height=n*o,r=t.getContext("2d")}return new v(r,t)}function b(t,e){const n=(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y);return 0===n?n:Math.sqrt(n)}function P(t,e){return t.x===e.x&&t.y===e.y&&t.t===e.t}function M(t){return t>=0||t<0}function I(t){return M(t.x)&&M(t.y)&&t.t>0}function $(t,e){return{x:t.x+(e.x-t.x)/2,y:t.y+(e.y-t.y)/2}}function R(t){return t/180*Math.PI}function S(t,e,n,i){const o=R(e||0);n&&(o>0||o<0)&&(t.translate(n.x,n.y),t.rotate(o),t.translate(-n.x,-n.y)),i(t),n&&(o>0||o<0)&&(t.translate(n.x,n.y),t.rotate(-o),t.translate(-n.x,-n.y))}function E(t){return{x:t.x+t.w/2,y:t.y+t.h/2}}function A(t){const e=Math.min(t[0].x,t[1].x,t[2].x,t[3].x),n=Math.min(t[0].y,t[1].y,t[2].y,t[3].y);return E({x:e,y:n,w:Math.max(t[0].x,t[1].x,t[2].x,t[3].x)-e,h:Math.max(t[0].y,t[1].y,t[2].y,t[3].y)-n})}function C(t,e,n){const i=function(t,e){const n=e.x-t.x,i=e.y-t.y;if(0===n){if(i<0)return 0;if(i>0)return Math.PI}else if(0===i){if(n<0)return 3*Math.PI/2;if(n>0)return Math.PI/2}return n>0&&i<0?Math.atan(Math.abs(n)/Math.abs(i)):n>0&&i>0?Math.PI-Math.atan(Math.abs(n)/Math.abs(i)):n<0&&i>0?Math.PI+Math.atan(Math.abs(n)/Math.abs(i)):n<0&&i<0?2*Math.PI-Math.atan(Math.abs(n)/Math.abs(i)):0}(t,e);let o=i+n;o>2*Math.PI?o-=2*Math.PI:o<0-2*Math.PI&&(o+=2*Math.PI),o<0&&(o+=2*Math.PI);const r=b(t,e);let l=0,a=0;return 0===o?(l=0,a=0-r):o>0&&o<Math.PI/2?(l=Math.sin(o)*r,a=0-Math.cos(o)*r):o===Math.PI/2?(l=r,a=0):o>Math.PI/2&&o<Math.PI?(l=Math.sin(Math.PI-o)*r,a=Math.cos(Math.PI-o)*r):o===Math.PI?(l=0,a=r):o>Math.PI&&o<1.5*Math.PI?(l=0-Math.sin(o-Math.PI)*r,a=Math.cos(o-Math.PI)*r):o===1.5*Math.PI?(l=0-r,a=0):o>1.5*Math.PI&&o<2*Math.PI?(l=0-Math.sin(2*Math.PI-o)*r,a=0-Math.cos(2*Math.PI-o)*r):o===2*Math.PI&&(l=0,a=0-r),l+=t.x,a+=t.y,{x:l,y:a}}function k(t,e,n){const{x:i,y:o,w:r,h:l}=t;let a={x:i,y:o},s={x:i+r,y:o},c={x:i+r,y:o+l},u={x:i,y:o+l};if(n&&(n>0||n<0)){const t=R(O(n));a=C(e,a,t),s=C(e,s,t),c=C(e,c,t),u=C(e,u,t)}return[a,s,c,u]}function _(t){const{angle:e=0}=t;return k(t,E(t),e)}function z(t,e,n){return[C(t,{x:e[0].x,y:e[0].y},n),C(t,{x:e[1].x,y:e[1].y},n),C(t,{x:e[2].x,y:e[2].y},n),C(t,{x:e[3].x,y:e[3].y},n)]}function O(t){if(!(t>0||t<0)||0===t)return 0;let e=t%360;return e<0&&(e+=360),e}function T(t,e){const n={x:0,y:0,w:0,h:0};t.forEach((t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h,angle:t.angle};if(e.angle&&(e.angle>0||e.angle<0)){const t=_(e);if(4===t.length){const n=[t[0].x,t[1].x,t[2].x,t[3].x],i=[t[0].y,t[1].y,t[2].y,t[3].y];e.x=Math.min(...n),e.y=Math.min(...i),e.w=Math.abs(Math.max(...n)-Math.min(...n)),e.h=Math.abs(Math.max(...i)-Math.min(...i))}}const i=Math.min(e.x,n.x),o=Math.min(e.y,n.y),r=Math.max(e.x+e.w,n.x+n.w),l=Math.max(e.y+e.h,n.y+n.h);n.x=i,n.y=o,n.w=Math.abs(r-i),n.h=Math.abs(l-o)})),(null==e?void 0:e.extend)&&(n.x=Math.min(n.x,0),n.y=Math.min(n.y,0));const i={contextWidth:n.w,contextHeight:n.h};return(null==e?void 0:e.viewWidth)&&(null==e?void 0:e.viewHeight)&&(null==e?void 0:e.viewWidth)>0&&(null==e?void 0:e.viewHeight)>0&&(e.viewWidth>n.x+n.w&&(i.contextWidth=e.viewWidth-n.x),e.viewHeight>n.y+n.h&&(i.contextHeight=e.viewHeight-n.y)),i}function D(t,e){var n;const i=Object.keys(e);for(let o=0;o<i.length;o++){const r=i[o];["x","y","w","h","angle","name"].includes(r)?t[r]=e[r]:["detail","operations"].includes(r)&&(c.json(e[r])?((null==t?void 0:t.hasOwnProperty(r))||(t[r]={}),c.json(t[r])&&(t[r]={...t[r],...e[r]})):c.array(e[r])&&((null==t?void 0:t.hasOwnProperty(r))||(t[r]=[]),c.array(t[r])&&(null==(n=null==e?void 0:e[r])||n.forEach(((e,n)=>{t[r][n]=e})),t[r]=[...t[r],...e[r]])))}return t}function L(t,e){let n=null,i=e;for(let e=0;e<t.length;e++){const o=i[t[e]];if(e<t.length-1&&"group"===o.type)i=o.detail.children;else{if(e!==t.length-1)break;n=o}}return n}function j(t,e){const n=t.x,i=t.y,o=t.x+t.w,r=t.y+t.h,l=e.x,a=e.y,s=e.x+e.w,c=e.y+e.h;return n<=s&&o>=l&&i<=c&&r>=a}function W(t,e){const{viewScaleInfo:n}=e,{x:i,y:o,w:r,h:l,angle:a}=t,{scale:s,offsetTop:c,offsetLeft:u}=n;return{x:i*s+u,y:o*s+c,w:r*s,h:l*s,angle:a}}function H(t,e){const{viewScaleInfo:n}=e,{x:i,y:o}=t,{scale:r,offsetTop:l,offsetLeft:a}=n;return{x:i*r+a,y:o*r+l}}function F(t,e){const{context2d:n,element:i,viewScaleInfo:o,viewSizeInfo:r}=e,{angle:l=0}=i,{x:a,y:s,w:c,h:u}=W(i,{viewScaleInfo:o,viewSizeInfo:r}),f=_({x:a,y:s,w:c,h:u,angle:l});if(f.length>=2){n.beginPath(),n.moveTo(f[0].x,f[0].y);for(let t=1;t<f.length;t++)n.lineTo(f[t].x,f[t].y);n.closePath()}return!!n.isPointInPath(t.x,t.y)}function V(t){const{x:e,y:n,h:i,w:o}=t;return[{x:e,y:n},{x:e+o,y:n},{x:e+o,y:n+i},{x:e,y:n+i}]}function N(t){const{x:e,y:n,w:i,h:o,angle:r=0}=t;return 0===r?V(t):k(t,E({x:e,y:n,w:i,h:o,angle:r}),r)}function B(t){const e=[];let n=0,i=0;const o=[],r=[...t];for(let t=0;t<r.length;t++){const{x:l,y:a,w:s,h:c,angle:u=0}=r[t];let f;if(n+=l,i+=a,0===t){const t={x:n,y:i,w:s,h:c,angle:u};f=N({x:l,y:a,w:s,h:c,angle:u}),o.push({center:E(t),angle:u,radian:R(u)})}else{f=V({x:n,y:i,w:s,h:c,angle:u});for(let t=0;t<o.length;t++){const{center:e,radian:n}=o[t];f=z(e,f,n)}const t=A(f);if(u>0||u<0){f=z(t,f,R(u))}o.push({center:t,angle:u,radian:R(u)})}e.push(f)}return e}function G(t,e){const{groupQueue:n}=e;if(!(n.length>0))return[N(t)];return B([...n,t])}function U(t,e){return G(t,e).pop()||null}function Y(t,e){const{x:n,y:i}=t,{size:o,angle:r}=e;return{x:n-o/2,y:i-o/2,w:o,h:o,angle:r}}const Q=/([astvzqmhlc])([^astvzqmhlc]*)/gi,q=/(-?\d+(?:\.\d+)?)/gi;const X=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g,Z=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,J=/^\s*$/,K={};function tt(t){const e={type:"element",name:"",isVoid:!1,attributes:{},children:[]},n=t.match(/<\/?([^\s]+?)[/\s>]/);if(n&&(e.name=n[1],(K[n[1]]||"/"===t.charAt(t.length-2))&&(e.isVoid=!0),e.name.startsWith("!--"))){const e=t.indexOf("--\x3e");return{type:"comment",name:null,attributes:{},children:[],isVoid:!1,comment:-1!==e?t.slice(4,e):""}}const i=new RegExp(X);let o=null;for(;o=i.exec(t),null!==o;)if(o[0].trim())if(o[1]){const t=o[1].trim();let n=[t,""];t.indexOf("=")>-1&&(n=t.split("=")),e.attributes[n[0]]=n[1],i.lastIndex--}else o[2]&&(e.attributes[o[2]]=o[3].trim().substring(1,o[3].length-1));return e}function et(t,e){switch(e.type){case"text":return t+e.textContent;case"element":return t+="<"+e.name+(e.attributes?function(t){const e=[];for(let n in t)e.push(n+'="'+t[n]+'"');return e.length?" "+e.join(" "):""}(e.attributes):"")+(e.isVoid?"/>":">"),e.isVoid?t:t+e.children.reduce(et,"")+"</"+e.name+">";case"comment":return t+="\x3c!--"+e.comment+"--\x3e"}}function nt(t){return t[1]!=-1*t[3]||t[4]!=t[0]||t[0]*t[4]-t[3]*t[1]!=1?null:Math.acos(t[0])}function it(){return{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 ot(){return{background:"#D9D9D9"}}function rt(t){var e;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"},i=(null==(e=null==t?void 0:t.viewScaleInfo)?void 0:e.scale)||1;return{text:"Text Element",color:n.color,fontFamily:n.fontFamily,fontWeight:n.fontWeight,lineHeight:n.fontSize*i,fontSize:n.fontSize*i,textAlign:"center",verticalAlign:"middle"}}const lt={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 at=200,st=200,ct={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"};return t.Context2D=v,t.EventEmitter=class{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const n=this._listeners.get(t)||[];null==n||n.push(e),this._listeners.set(t,n)}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const n=this._listeners.get(t);if(Array.isArray(n))for(let t=0;t<(null==n?void 0:n.length);t++)if(n[t]===e){n.splice(t,1);break}this._listeners.set(t,n||[])}}trigger(t,e){const n=this._listeners.get(t);return!!Array.isArray(n)&&(n.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}},t.Store=class{constructor(t){this._backUpDefaultStorage=a(t.defaultStorage),this._temp=this._createTempStorage()}set(t,e){this._temp[t]=e}get(t){return this._temp[t]}getSnapshot(){return a(this._temp)}clear(){this._temp=this._createTempStorage()}_createTempStorage(){return a(this._backUpDefaultStorage)}},t.calcDistance=b,t.calcElementCenter=E,t.calcElementCenterFromVertexes=A,t.calcElementQueueVertexesQueueInGroup=B,t.calcElementSizeController=function(t,e){const{groupQueue:n,controllerSize:o,viewScaleInfo:r}=e,l=(o&&o>0?o:8)/r.scale,{x:a,y:s,w:c,h:u,angle:f=0}=t,h=[{uuid:i(),x:a,y:s,w:c,h:u,angle:f,type:"group",detail:{children:[]}},...n];let d=0;h.forEach((({angle:t=0})=>{d+=t}));const g=U(t,{groupQueue:n}),x=$(g[0],g[1]),y=$(g[1],g[2]),p=$(g[2],g[3]),m=$(g[3],g[0]),v=g[0],w=g[1],b=g[2],P=g[3],M=Y(v,{size:l,angle:d}),I=Y(w,{size:l,angle:d}),R=Y(P,{size:l,angle:d}),S=Y(b,{size:l,angle:d}),E=N(M),A=N(I),C=N(R),k=N(S),_=[E[1],A[0],A[3],E[2]],z=[A[3],A[2],k[1],k[0]],O=[C[1],k[0],k[3],C[2]];return{elementWrapper:g,left:{type:"left",vertexes:[E[3],E[2],C[1],C[0]],center:m},right:{type:"right",vertexes:z,center:y},top:{type:"top",vertexes:_,center:x},bottom:{type:"bottom",vertexes:O,center:p},topLeft:{type:"top-left",vertexes:E,center:v},topRight:{type:"top-right",vertexes:A,center:w},bottomLeft:{type:"bottom-left",vertexes:C,center:P},bottomRight:{type:"bottom-right",vertexes:k,center:b}}},t.calcElementVertexesInGroup=U,t.calcElementVertexesQueueInGroup=G,t.calcElementsContextSize=T,t.calcElementsViewInfo=function(t,e,n){const i=T(t,{viewWidth:e.width,viewHeight:e.height,extend:null==n?void 0:n.extend});return!0===(null==n?void 0:n.extend)&&(i.contextWidth=Math.max(i.contextWidth,e.contextWidth),i.contextHeight=Math.max(i.contextHeight,e.contextHeight)),{contextSize:i}},t.calcSpeed=function(t,e){return b(t,e)/Math.abs(e.t-t.t)},t.calcViewBoxSize=function(t,e){const{viewScaleInfo:n}=e,{scale:i}=n;let{borderRadius:o,boxSizing:r=lt.boxSizing,borderWidth:l}=t.detail;"number"!=typeof l&&(o=0);let{x:a,y:s,w:c,h:u}=t,f=[0,0,0,0];if("number"==typeof o){const t=o*i;f=[t,t,t,t]}else Array.isArray(o)&&4===(null==o?void 0:o.length)&&(f=[o[0]*i,o[1]*i,o[2]*i,o[3]*i]);let h=0;return"number"==typeof l&&(h=(l||0)*i),"border-box"===r?(a=t.x+h/2,s=t.y+h/2,c=t.w-h,u=t.h-h):"content-box"===r?(a=t.x-h/2,s=t.y-h/2,c=t.w+h,u=t.h+h):(a=t.x,s=t.y,c=t.w,u=t.h),c=Math.max(c,1),u=Math.max(u,1),f=f.map((t=>Math.min(t,c/2,u/2))),{x:a,y:s,w:c,h:u,radiusList:f}},t.calcViewElementSize=W,t.calcViewPointSize=H,t.calcViewScaleInfo=function(t,e){const{scale:n,offsetX:i,offsetY:o}=t,{viewSizeInfo:r}=e,{width:l,height:a,contextWidth:s,contextHeight:c}=r,u=0-i*n,f=0-o*n;return{scale:n,offsetLeft:u,offsetTop:f,offsetRight:l-(s*n+u/n),offsetBottom:a-(c*n+f/n)}},t.calcViewVertexes=function(t,e){return[H(t[0],e),H(t[1],e),H(t[2],e),H(t[3],e)]},t.check=m,t.checkRectIntersect=j,t.colorNameToHex=function(t){const e=t.toLowerCase(),i=n[e];return"string"==typeof i?i:null},t.colorToCSS=function(t){let e="transparent";if("string"==typeof t)e=t;else if("linear-gradient"===(null==t?void 0:t.type)){const n=[];"number"==typeof t.angle?n.push(`${t.angle}deg`):n.push("180deg"),Array.isArray(t.stops)&&t.stops.forEach((t=>{n.push(`${t.color} ${100*t.offset}%`)})),e=`linear-gradient(${n.join(", ")})`}else if("radial-gradient"===(null==t?void 0:t.type)){const n=[];Array.isArray(t.stops)&&t.stops.forEach((t=>{n.push(`${t.color} ${100*t.offset}%`)})),e=`radial-gradient(circle, ${n.join(", ")})`}return e},t.colorToLinearGradientCSS=function(t){let e="transparent";if("string"==typeof t)e=t;else if("radial-gradient"===(null==t?void 0:t.type)||"linear-gradient"===(null==t?void 0:t.type)){const n=[];Array.isArray(t.stops)&&t.stops.length>0&&(t.stops.forEach(((e,i)=>{n.push(`${e.color} ${100*e.offset}%`),i===t.stops.length-1&&e.offset<1&&n.push(`${e.color} ${100*e.offset}%`)})),e=`linear-gradient(90deg, ${n.join(", ")})`)}return e},t.compose=function(t){return function(e,n){return function i(o){let r=t[o];o===t.length&&n&&(r=n);if(!r)return Promise.resolve();try{return Promise.resolve(r(e,i.bind(null,o+1)))}catch(t){return Promise.reject(t)}}(0)}},t.compressImage=function(t,e){let n=.5;const i=(null==e?void 0:e.type)||"image/png";return(null==e?void 0:e.radio)&&(null==e?void 0:e.radio)>0&&(null==e?void 0:e.radio)<=1&&(n=null==e?void 0:e.radio),new Promise(((e,o)=>{const r=new Image;r.addEventListener("load",(()=>{const{width:t,height:o}=r,l=t*n,a=o*n;let s=document.createElement("canvas");s.width=l,s.height=a;s.getContext("2d").drawImage(r,0,0,l,a);const c=s.toDataURL(i);s=null,e(c)})),r.addEventListener("error",(t=>{o(t)})),r.src=t}))},t.createAssetId=r,t.createBoardContexts=function(t,e){const n={width:t.canvas.width,height:t.canvas.height,devicePixelRatio:(null==e?void 0:e.devicePixelRatio)||1},i=w(n),o=w(n);return{underContext:w(n),viewContext:i,helperContext:o,boardContext:w({ctx:t,...n})}},t.createContext2D=w,t.createElement=function(t,e,n){const o=function(t,e){let n=0,i=0,o=at,r=st;if(e){const{viewScaleInfo:l,viewSizeInfo:a}=e,{scale:s,offsetLeft:c,offsetTop:u}=l,{width:f,height:h}=a;if("text"===t){const t=rt();o=ct.fontSize*s*t.text.length,r=ct.fontSize*s*2}else{const e=f/4,n=h/4;o=at>=e?e/s:at/s,r=st>=n?n/s:st/s,["circle","svg","image"].includes(t)&&(o=r=Math.max(o,r))}n=(0-c+f/2-o*s/2)/s,i=(0-u+h/2-r*s/2)/s}return{x:n,y:i,w:o,h:r}}(t,n);let r={};return"rect"===t?r={background:"#D9D9D9"}:"circle"===t?(o.w,r={background:"#D9D9D9",radius:0}):"text"===t?r=rt(n):"svg"===t?r={svg:'<svg t="1701004189871" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M908.1 353.1l-253.9-36.9L540.7 86.1c-3.1-6.3-8.2-11.4-14.5-14.5-15.8-7.8-35-1.3-42.9 14.5L369.8 316.2l-253.9 36.9c-7 1-13.4 4.3-18.3 9.3-12.3 12.7-12.1 32.9 0.6 45.3l183.7 179.1-43.4 252.9c-1.2 6.9-0.1 14.1 3.2 20.3 8.2 15.6 27.6 21.7 43.2 13.4L512 754l227.1 119.4c6.2 3.3 13.4 4.4 20.3 3.2 17.4-3 29.1-19.5 26.1-36.9l-43.4-252.9 183.7-179.1c5-4.9 8.3-11.3 9.3-18.3 2.7-17.5-9.5-33.7-27-36.3zM664.8 561.6l36.1 210.3L512 672.7 323.1 772l36.1-210.3-152.8-149L417.6 382 512 190.7 606.4 382l211.2 30.7-152.8 148.9z" fill="#2c2c2c"></path></svg>'}:"image"===t?r={src:"data:image/svg+xml;base64,PHN2ZyAgIHZpZXdCb3g9IjAgMCAxMDI0IDEwMjQiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiAgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiPjxwYXRoIGQ9Ik05MjggMTYwSDk2Yy0xNy43IDAtMzIgMTQuMy0zMiAzMnY2NDBjMCAxNy43IDE0LjMgMzIgMzIgMzJoODMyYzE3LjcgMCAzMi0xNC4zIDMyLTMyVjE5MmMwLTE3LjctMTQuMy0zMi0zMi0zMnogbS00MCA2MzJIMTM2di0zOS45bDEzOC41LTE2NC4zIDE1MC4xIDE3OEw2NTguMSA0ODkgODg4IDc2MS42Vjc5MnogbTAtMTI5LjhMNjY0LjIgMzk2LjhjLTMuMi0zLjgtOS0zLjgtMTIuMiAwTDQyNC42IDY2Ni40bC0xNDQtMTcwLjdjLTMuMi0zLjgtOS0zLjgtMTIuMiAwTDEzNiA2NTIuN1YyMzJoNzUydjQzMC4yeiIgIGZpbGw9IiM1MTUxNTEiPjwvcGF0aD48cGF0aCBkPSJNMzA0IDQ1NmM0OC42IDAgODgtMzkuNCA4OC04OHMtMzkuNC04OC04OC04OC04OCAzOS40LTg4IDg4IDM5LjQgODggODggODh6IG0wLTExNmMxNS41IDAgMjggMTIuNSAyOCAyOHMtMTIuNSAyOC0yOCAyOC0yOC0xMi41LTI4LTI4IDEyLjUtMjggMjgtMjh6IiAgZmlsbD0iIzUxNTE1MSI+PC9wYXRoPjwvc3ZnPg=="}:"group"===t&&(r={children:[],background:"#D9D9D9",overflow:"hidden"}),{...o,...e,uuid:i(),type:t,detail:{...r,...e.detail||{}}}},t.createOffscreenContext2D=function(t){const{width:e,height:n}=t;return new OffscreenCanvas(e,n).getContext("2d").canvas.getContext("2d")},t.createUUID=i,t.deepClone=a,t.delay=function(t){return new Promise((e=>{setTimeout((()=>{e()}),t)}))},t.downloadImageFromCanvas=function(t,e){const{filename:n,type:i="image/jpeg"}=e,o=t.toDataURL(i),r=document.createElement("a");r.href=o,r.download=n;const l=document.createEvent("MouseEvents");l.initEvent("click",!0,!1),r.dispatchEvent(l)},t.equalPoint=P,t.equalTouchPoint=function(t,e){return!0===P(t,e)&&t.f===e.f},t.filterElementAsset=function(t){let e=null,n=null,i=null;return"image"===t.type?i=t.detail.src:"svg"===t.type?i=t.detail.svg:"html"===t.type&&(i=t.detail.html),"string"!=typeof i||l(i)||(e=r(i),n={type:t.type,value:i},"image"===t.type?t.detail.src=e:"svg"===t.type?t.detail.svg=e:"html"===t.type&&(t.detail.html=e)),{element:t,assetId:e,assetItem:n}},t.findElementFromList=function t(e,n){var i;let o=null;for(let r=0;r<n.length;r++){const l=n[r];if(l.uuid===e){o=l;break}if(!o&&"group"===l.type){const n=t(e,(null==(i=null==l?void 0:l.detail)?void 0:i.children)||[]);if((null==n?void 0:n.uuid)===e){o=n;break}}}return o},t.findElementFromListByPosition=L,t.findElementsFromList=function(t,e){const n=[];return function e(i){var o;for(let r=0;r<i.length;r++){const l=i[r];t.includes(l.uuid)?n.push(l):"group"===l.type&&e((null==(o=null==l?void 0:l.detail)?void 0:o.children)||[])}}(e),n},t.findElementsFromListByPositions=function(t,e){const n=[];return t.forEach((t=>{const i=L(t,e);i&&n.push(i)})),n},t.formatNumber=function(t,e){let n=2;return void 0!==(null==e?void 0:e.decimalPlaces)&&(null==e?void 0:e.decimalPlaces)>=0&&(n=e.decimalPlaces),parseFloat(t.toFixed(n))},t.generateHTML=function(t){return t.reduce((function(t,e){return t+et("",e)}),"")},t.generateSVGPath=function(t){let e="";return t.forEach((t=>{e+=t.type+t.params.join(" ")})),e},t.getCenterFromTwoPoints=$,t.getDefaultElementDetailConfig=it,t.getDefaultElementRectDetail=ot,t.getElemenetsAssetIds=function(t){const e=[],n=t=>{t.forEach((t=>{"image"===t.type&&l(t.detail.src)?e.push(t.detail.src):"svg"===t.type&&l(t.detail.svg)?e.push(t.detail.svg):"html"===t.type&&t.detail.html?e.push(t.detail.html):"group"===t.type&&Array.isArray(t.detail.children)&&n(t.detail.children)}))};return n(t),e},t.getElementRotateVertexes=k,t.getElementSize=function(t){const{x:e,y:n,w:i,h:o,angle:r}=t;return{x:e,y:n,w:i,h:o,angle:r}},t.getElementVertexes=V,t.getGroupQueueFromList=function(t,e){const n=[];return function t(e,i){var o;let r=null;for(let l=0;l<i.length;l++){const a=i[l];if(a.uuid===e){r=a;break}if(!r&&"group"===a.type){n.push(a);const i=t(e,(null==(o=null==a?void 0:a.detail)?void 0:o.children)||[]);if((null==i?void 0:i.uuid)===e){r=i;break}n.pop()}}return r}(t,e),n},t.getSelectedElementUUIDs=function(t,e){var n;let i=[];return Array.isArray(null==t?void 0:t.elements)&&(null==(n=null==t?void 0:t.elements)?void 0:n.length)>0&&Array.isArray(e)&&e.length>0&&e.forEach((e=>{var n;"number"==typeof e?(null==(n=null==t?void 0:t.elements)?void 0:n[e])&&i.push(t.elements[e].uuid):"string"==typeof e&&(i=i.concat(function(t,e){var n;const i=[];if("string"==typeof e&&/^\d+(\.\d+)*$/.test(e)){const o=e.split(".");let r=t;for(;o.length>0;){const t=o.shift();if("string"==typeof t){const e=r[parseInt(t)];e&&0===o.length?i.push(e.uuid):"group"===e.type&&o.length>0&&(r=(null==(n=null==e?void 0:e.detail)?void 0:n.children)||[])}break}}return i}(t.elements,e)))})),i},t.getViewPointAtElement=function(t,e){var n,i,o;const{context2d:r,data:l,viewScaleInfo:a,viewSizeInfo:s,groupQueue:c}=e,u={index:-1,element:null,groupQueueIndex:-1};if(c&&Array.isArray(c)&&(null==c?void 0:c.length)>0)for(let e=c.length-1;e>=0;e--){let o=0,l=0,f=0;for(let t=0;t<=e;t++)o+=c[t].x,l+=c[t].y,f+=c[t].angle||0;const h=c[e];if(h&&"group"===h.type&&Array.isArray(null==(n=h.detail)?void 0:n.children))for(let n=0;n<h.detail.children.length;n++){const d=h.detail.children[n];if(!0!==(null==(i=null==d?void 0:d.operations)?void 0:i.invisible)){if(!d)break;if(F(t,{context2d:r,element:{x:o+d.x,y:l+d.y,w:d.w,h:d.h,angle:f+(d.angle||0)},viewScaleInfo:a,viewSizeInfo:s})){u.element=d,(e<c.length-1||"group"!==d.type)&&(u.groupQueueIndex=e);break}}}if(u.element)break}if(u.element)return u;for(let e=l.elements.length-1;e>=0;e--){const n=l.elements[e];if(!0!==(null==(o=null==n?void 0:n.operations)?void 0:o.invisible)&&F(t,{context2d:r,element:n,viewScaleInfo:a,viewSizeInfo:s})){u.index=e,u.element=n;break}}return u},t.getViewScaleInfoFromSnapshot=function(t){const{activeStore:e}=t;return{scale:null==e?void 0:e.scale,offsetTop:null==e?void 0:e.offsetTop,offsetBottom:null==e?void 0:e.offsetBottom,offsetLeft:null==e?void 0:e.offsetLeft,offsetRight:null==e?void 0:e.offsetRight}},t.getViewSizeInfoFromSnapshot=function(t){const{activeStore:e}=t;return{devicePixelRatio:e.devicePixelRatio,width:null==e?void 0:e.width,height:null==e?void 0:e.height,contextWidth:null==e?void 0:e.contextWidth,contextHeight:null==e?void 0:e.contextHeight}},t.is=y,t.isAssetId=l,t.isColorStr=e,t.isElementInView=function(t,e){const{viewSizeInfo:n,viewScaleInfo:i}=e,{width:o,height:r}=n,{angle:l}=t,{x:a,y:s,w:c,h:u}=W(t,{viewScaleInfo:i,viewSizeInfo:n}),f=_({x:a,y:s,w:c,h:u,angle:l}),h={x:0,y:0,w:o,h:r},d=Math.min(f[0].x,f[1].x,f[2].x,f[3].x),g=Math.min(f[0].y,f[1].y,f[2].y,f[3].y);return j(h,{x:d,y:g,w:Math.max(f[0].x,f[1].x,f[2].x,f[3].x)-d,h:Math.max(f[0].y,f[1].y,f[2].y,f[3].y)-g})},t.isResourceElement=function(t){return["image","svg","html"].includes(null==t?void 0:t.type)},t.isViewPointInElement=F,t.istype=c,t.limitAngle=O,t.loadHTML=async function(t,e){t=t.replace(/\&/gi,"&");const n=await function(t,e){const{width:n,height:i}=e;return new Promise(((e,o)=>{const r=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 ${t}\n </div>\n </foreignObject>\n </svg>\n `],{type:"image/svg+xml;charset=utf-8"}),l=new FileReader;l.readAsDataURL(r),l.onload=function(t){var n;const i=null==(n=null==t?void 0:t.target)?void 0:n.result;e(i)},l.onerror=function(t){o(t)}}))}(t,e);return await f(n)},t.loadImage=f,t.loadSVG=async function(t){const e=await function(t){return new Promise(((e,n)=>{const i=new Blob([t],{type:"image/svg+xml;charset=utf-8"}),o=new FileReader;o.readAsDataURL(i),o.onload=function(t){var n;const i=null==(n=null==t?void 0:t.target)?void 0:n.result;e(i)},o.onerror=function(t){n(t)}}))}(t);return await f(e)},t.matrixToAngle=function(t){const e=nt(t);if("number"==typeof e){return 180*e/Math.PI}return e},t.matrixToRadian=nt,t.mergeElementAsset=function(t,e){const n=t;let i=null,o=null;return"image"===n.type?i=n.detail.src:"svg"===n.type?i=n.detail.svg:"html"===n.type&&(i=n.detail.html),i&&(null==i?void 0:i.startsWith("@assets/"))&&(o=e[i]),(null==o?void 0:o.type)===n.type&&"string"==typeof(null==o?void 0:o.value)&&(null==o?void 0:o.value)&&("image"===n.type?n.detail.src=o.value:"svg"===n.type?n.detail.svg=o.value:"html"===n.type&&(n.detail.html=o.value)),n},t.mergeHexColorAlpha=function(t,e){if(1===e)return t;let n=1;const i=/^\#[0-9a-f]{6,6}$/i;let o=t;if(i.test(t)?n=parseInt(t.substring(5,7).replace(/^\#/,"0x")):/^\#[0-9a-f]{8,8}$/i.test(t)&&(n=parseInt(t.substring(7,9).replace(/^\#/,"0x")),o=t.substring(0,7)),n*=e,i.test(o)&&n>0&&n<1){const t=Math.max(0,Math.min(255,Math.ceil(256*n)));o=`${o.toUpperCase()}${t.toString(16).toUpperCase()}`}return o},t.moveElementPosition=function(t,e){const{from:n,to:i}=e;if(0===n.length||0===i.length)return t;if(n.length<=i.length)for(let e=0;e<n.length;e++)if(i[e]!==n[e]);else if(e===n.length-1)return t;const o=L(n,t);if(o){if(!function(t,e,n){let i=!1;if(1===e.length){const o=e[0];n.splice(o,0,t),i=!0}else if(e.length>1){let o=n;for(let n=0;n<e.length;n++){const r=o[e[n]];if(n===e.length-1){const r=e[n];o.splice(r,0,t),i=!0}else{if(!(n<e.length-1&&"group"===r.type))break;o=r.detail.children}}}return i}(o,i,t))return t;let e=-1;for(let t=0;t<n.length&&i[t]>=0;t++)i[t]!==n[t]&&i[t]<n[t]&&t==i.length-1&&(e=t);e>=0&&(n[e]=n[e]+1),function(t,e){let n=!1;if(1===t.length){const i=t[0];e.splice(i,1),n=!0}else if(t.length>1){let i=e;for(let e=0;e<t.length;e++){const o=i[t[e]];if(e===t.length-1){const o=t[e];i.splice(o,1),n=!0}else{if(!(e<t.length-1&&"group"===o.type))break;i=o.detail.children}}}}(n,t)}return t},t.parseAngleToRadian=R,t.parseFileToBase64=function(t){return new Promise((function(e,n){let i=new FileReader;i.addEventListener("load",(function(){e(i.result),i=null})),i.addEventListener("error",(function(t){n(t),i=null})),i.addEventListener("abort",(function(){n(new Error("abort")),i=null})),i.readAsDataURL(t)}))},t.parseFileToText=function(t){return new Promise((function(e,n){let i=new FileReader;i.addEventListener("load",(function(){e(i.result),i=null})),i.addEventListener("error",(function(t){n(t),i=null})),i.addEventListener("abort",(function(){n(new Error("abort")),i=null})),i.readAsText(t)}))},t.parseHTML=function(t){const e=[],n=[];let i,o=-1;return t.replace(Z,((r,l)=>{const a="/"!==r.charAt(1),s=r.startsWith("\x3c!--"),c=l+r.length,u=t.charAt(c);let f;if(s){const t=tt(r);return o<0?(e.push(t),r):(f=n[o],f.children.push(t),r)}if(a){if(o++,i=tt(r),!i.isVoid&&u&&"<"!==u){const e=t.slice(c,t.indexOf("<",c));e.trim()&&i.children.push({type:"text",name:null,attributes:{},children:[],isVoid:!1,textContent:e.trim()})}0===o&&e.push(i),f=n[o-1],f&&f.children.push(i),n[o]=i}if((!a||!Array.isArray(i)&&i.isVoid)&&(o>-1&&!Array.isArray(i)&&(i.isVoid||i.name===r.slice(2,-1))&&(o--,i=-1===o?e:n[o]),"<"!==u&&u)){f=-1===o?e:n[o].children;const i=t.indexOf("<",c);let r=t.slice(c,-1===i?void 0:i);J.test(r)&&(r=" "),(i>-1&&o+f.length>=0||" "!==r)&&r.trim()&&f.push({type:"text",name:null,attributes:{},children:[],isVoid:!1,textContent:r.trim()})}return r})),e},t.parseRadianToAngle=function(t){return t/Math.PI*180},t.parseSVGPath=function(t){const e=[];return t.replace(Q,((t,n,i)=>{const o=i.match(q),r={type:n,params:o?o.map(Number):[]};return e.push(r),t})),e},t.pickFile=function(t){const{success:e,error:n}=t;let i=document.createElement("input");i.type="file",i.addEventListener("change",(function(){var t;const n=null==(t=i.files)?void 0:t[0];e({file:n}),i=null})),i.addEventListener("error",(function(t){"function"==typeof n&&n(t),i=null})),i.click()},t.rotateByCenter=S,t.rotateElement=function(t,e,n){const i=E(e);S(t,e.angle||0,i,(()=>{n(t)}))},t.rotateElementVertexes=_,t.rotatePoint=C,t.rotatePointInGroup=function(t,e){if((null==e?void 0:e.length)>0){let n=t.x,i=t.y;return e.forEach((t=>{const{x:e,y:o,w:r,h:l,angle:a=0}=t,s=C(E({x:e,y:o,w:r,h:l,angle:a}),{x:n,y:i},R(a));n=s.x,i=s.y})),{x:n,y:i}}return t},t.rotateVertexes=z,t.sortDataAsserts=function(t,e){const n=t.assets||{};let i=t;!0===(null==e?void 0:e.clone)&&(i=a(t));const o=t=>{t.forEach((t=>{if("image"===t.type&&t.detail.src){const e=t.detail.src,i=r(e);n[i]||(n[i]={type:"image",value:e}),t.detail.src=i}else if("svg"===t.type){const e=t.detail.svg,i=r(e);n[i]||(n[i]={type:"svg",value:e}),t.detail.svg=i}else if("html"===t.type){const e=t.detail.html,i=r(e);n[i]||(n[i]={type:"svg",value:e}),t.detail.html=i}else if("group"===t.type&&Array.isArray(t.detail.children)){const e=t.detail.assets||{};Object.keys(e).forEach((t=>{n[t]||(n[t]=e[t])})),delete t.detail.assets,o(t.detail.children)}}))};return o(i.elements),i.assets=n,i},t.throttle=function(t,e){let n=-1;return function(...i){n>0||(n=setTimeout((()=>{t(...i),n=-1}),e))}},t.toColorHexNum=function(t){return parseInt(t.replace(/^\#/,"0x"))},t.toColorHexStr=function(t){return"#"+t.toString(16)},t.updateElementInList=function t(e,n,i){var o;let r=null;for(let l=0;l<i.length;l++){const a=i[l];if(a.uuid===e){D(a,n),r=a;break}"group"===a.type&&(r=t(e,n,(null==(o=null==a?void 0:a.detail)?void 0:o.children)||[]))}return r},t.vaildPoint=I,t.vaildTouchPoint=function(t){return!0===I(t)&&t.f>=0},t.validateElements=function t(e){let n=!0;if(Array.isArray(e)){const i=[];e.forEach((e=>{var o;"string"==typeof e.uuid&&e.uuid?i.includes(e.uuid)?(n=!1,console.warn(`Duplicate uuids: ${e.uuid}`)):i.push(e.uuid):(n=!1,console.warn("Element missing uuid",e)),"group"===e.type&&(n=t(null==(o=null==e?void 0:e.detail)?void 0:o.children))}))}return n},t.viewScale=function(t){const{scale:e,point:n,viewScaleInfo:i}=t,{offsetLeft:o,offsetTop:r}=i,l=e/i.scale,a=n.x,s=n.y;return{moveX:a-a*l+(o*l-o),moveY:s-s*l+(r*l-r)}},t.viewScroll=function(t){const{moveX:e=0,moveY:n=0,viewScaleInfo:i,viewSizeInfo:o}=t,{scale:r}=i,{width:l,height:a,contextWidth:s,contextHeight:c}=o;let u=i.offsetLeft,f=i.offsetRight,h=i.offsetTop,d=i.offsetBottom;return u+=e,h+=n,f=l-(s*r+u),d=a-(c*r+h),{scale:r,offsetTop:h,offsetLeft:u,offsetRight:f,offsetBottom:d}},Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),t}({});
|