@idraw/util 0.4.0-beta.39 → 0.4.0-beta.40
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 +5 -3
- package/dist/esm/index.js +5 -3
- package/dist/esm/lib/box.d.ts +2 -0
- package/dist/esm/lib/box.js +173 -0
- package/dist/esm/lib/canvas.d.ts +1 -7
- package/dist/esm/lib/canvas.js +25 -72
- package/dist/esm/lib/color.js +9 -6
- package/dist/esm/lib/context2d.d.ts +2 -0
- package/dist/esm/lib/context2d.js +6 -0
- package/dist/esm/lib/data.d.ts +1 -0
- package/dist/esm/lib/data.js +19 -2
- package/dist/esm/lib/is.d.ts +2 -0
- package/dist/esm/lib/is.js +21 -5
- package/dist/esm/lib/merge.d.ts +1 -0
- package/dist/esm/lib/merge.js +17 -0
- package/dist/esm/lib/omit.d.ts +1 -0
- package/dist/esm/lib/omit.js +7 -0
- package/dist/esm/lib/view-box.js +2 -1
- package/dist/esm/lib/view-calc.d.ts +1 -5
- package/dist/esm/lib/view-calc.js +0 -44
- package/dist/index.global.js +357 -244
- package/dist/index.global.min.js +1 -1
- package/package.json +2 -2
- package/dist/esm/lib/view-visible.d.ts +0 -21
- package/dist/esm/lib/view-visible.js +0 -93
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { delay, compose, throttle, debounce } from './lib/time';
|
|
|
2
2
|
export { downloadImageFromCanvas, parseFileToBase64, pickFile, parseFileToText, downloadFileFromText } from './lib/file';
|
|
3
3
|
export { toColorHexStr, toColorHexNum, isColorStr, colorNameToHex, colorToCSS, colorToLinearGradientCSS, mergeHexColorAlpha } from './lib/color';
|
|
4
4
|
export { createUUID, isAssetId, createAssetId } from './lib/uuid';
|
|
5
|
-
export { deepClone, sortDataAsserts, deepCloneElement, filterCompactData } from './lib/data';
|
|
5
|
+
export { deepClone, sortDataAsserts, deepCloneElement, deepCloneData, filterCompactData } from './lib/data';
|
|
6
6
|
export { istype } from './lib/istype';
|
|
7
7
|
export { loadImage, loadSVG, loadHTML } from './lib/load';
|
|
8
8
|
export { is } from './lib/is';
|
|
@@ -16,8 +16,7 @@ export { Context2D } from './lib/context2d';
|
|
|
16
16
|
export { rotateElement, parseRadianToAngle, parseAngleToRadian, rotateElementVertexes, getElementRotateVertexes, calcElementCenter, calcElementCenterFromVertexes, rotatePointInGroup, limitAngle, calcRadian } from './lib/rotate';
|
|
17
17
|
export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, findElementFromListByPosition, findElementQueueFromListByPosition, findElementsFromListByPositions, getGroupQueueFromList, getGroupQueueByElementPosition, getElementSize, mergeElementAsset, filterElementAsset, isResourceElement, getElementPositionFromList, getElementPositionMapFromList, calcElementListSize, isSameElementSize } from './lib/element';
|
|
18
18
|
export { checkRectIntersect } from './lib/rect';
|
|
19
|
-
export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView, calcViewScaleInfo, calcElementViewRectInfo, calcElementOriginRectInfo,
|
|
20
|
-
export { sortElementsViewVisiableInfoMap, calcVisibleOriginCanvasRectInfo, updateViewVisibleInfoMapStatus } from './lib/view-visible';
|
|
19
|
+
export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView, calcViewScaleInfo, calcElementViewRectInfo, calcElementOriginRectInfo, originRectInfoToRangeRectInfo, isViewPointInElementSize, isViewPointInVertexes } from './lib/view-calc';
|
|
21
20
|
export { rotatePoint, rotateVertexes, rotateByCenter } from './lib/rotate';
|
|
22
21
|
export { getElementVertexes, calcElementVertexesInGroup, calcElementVertexesQueueInGroup, calcElementQueueVertexesQueueInGroup } from './lib/vertex';
|
|
23
22
|
export { calcElementSizeController, calcLayoutSizeController } from './lib/controller';
|
|
@@ -36,3 +35,6 @@ export { enhanceFontFamliy } from './lib/text';
|
|
|
36
35
|
export { flatElementList } from './lib/flat';
|
|
37
36
|
export { groupElementsByPosition, ungroupElementsByPosition } from './lib/group';
|
|
38
37
|
export { calcPointMoveElementInGroup } from './lib/point-move-element';
|
|
38
|
+
export { merge } from './lib/merge';
|
|
39
|
+
export { omit } from './lib/omit';
|
|
40
|
+
export { elementToBoxInfo } from './lib/box';
|
package/dist/esm/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export { delay, compose, throttle, debounce } from './lib/time';
|
|
|
2
2
|
export { downloadImageFromCanvas, parseFileToBase64, pickFile, parseFileToText, downloadFileFromText } from './lib/file';
|
|
3
3
|
export { toColorHexStr, toColorHexNum, isColorStr, colorNameToHex, colorToCSS, colorToLinearGradientCSS, mergeHexColorAlpha } from './lib/color';
|
|
4
4
|
export { createUUID, isAssetId, createAssetId } from './lib/uuid';
|
|
5
|
-
export { deepClone, sortDataAsserts, deepCloneElement, filterCompactData } from './lib/data';
|
|
5
|
+
export { deepClone, sortDataAsserts, deepCloneElement, deepCloneData, filterCompactData } from './lib/data';
|
|
6
6
|
export { istype } from './lib/istype';
|
|
7
7
|
export { loadImage, loadSVG, loadHTML } from './lib/load';
|
|
8
8
|
export { is } from './lib/is';
|
|
@@ -16,8 +16,7 @@ export { Context2D } from './lib/context2d';
|
|
|
16
16
|
export { rotateElement, parseRadianToAngle, parseAngleToRadian, rotateElementVertexes, getElementRotateVertexes, calcElementCenter, calcElementCenterFromVertexes, rotatePointInGroup, limitAngle, calcRadian } from './lib/rotate';
|
|
17
17
|
export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, findElementFromListByPosition, findElementQueueFromListByPosition, findElementsFromListByPositions, getGroupQueueFromList, getGroupQueueByElementPosition, getElementSize, mergeElementAsset, filterElementAsset, isResourceElement, getElementPositionFromList, getElementPositionMapFromList, calcElementListSize, isSameElementSize } from './lib/element';
|
|
18
18
|
export { checkRectIntersect } from './lib/rect';
|
|
19
|
-
export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView, calcViewScaleInfo, calcElementViewRectInfo, calcElementOriginRectInfo,
|
|
20
|
-
export { sortElementsViewVisiableInfoMap, calcVisibleOriginCanvasRectInfo, updateViewVisibleInfoMapStatus } from './lib/view-visible';
|
|
19
|
+
export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView, calcViewScaleInfo, calcElementViewRectInfo, calcElementOriginRectInfo, originRectInfoToRangeRectInfo, isViewPointInElementSize, isViewPointInVertexes } from './lib/view-calc';
|
|
21
20
|
export { rotatePoint, rotateVertexes, rotateByCenter } from './lib/rotate';
|
|
22
21
|
export { getElementVertexes, calcElementVertexesInGroup, calcElementVertexesQueueInGroup, calcElementQueueVertexesQueueInGroup } from './lib/vertex';
|
|
23
22
|
export { calcElementSizeController, calcLayoutSizeController } from './lib/controller';
|
|
@@ -36,3 +35,6 @@ export { enhanceFontFamliy } from './lib/text';
|
|
|
36
35
|
export { flatElementList } from './lib/flat';
|
|
37
36
|
export { groupElementsByPosition, ungroupElementsByPosition } from './lib/group';
|
|
38
37
|
export { calcPointMoveElementInGroup } from './lib/point-move-element';
|
|
38
|
+
export { merge } from './lib/merge';
|
|
39
|
+
export { omit } from './lib/omit';
|
|
40
|
+
export { elementToBoxInfo } from './lib/box';
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { is } from './is';
|
|
2
|
+
export function elementToBoxInfo(elem) {
|
|
3
|
+
const { x, y, w, h, detail } = elem;
|
|
4
|
+
const { borderWidth, borderRadius, boxSizing } = detail;
|
|
5
|
+
let btw = 0;
|
|
6
|
+
let brw = 0;
|
|
7
|
+
let bbw = 0;
|
|
8
|
+
let blw = 0;
|
|
9
|
+
let btlr = 0;
|
|
10
|
+
let btrr = 0;
|
|
11
|
+
let bblr = 0;
|
|
12
|
+
let bbrr = 0;
|
|
13
|
+
if (typeof borderWidth === 'number' && borderWidth > 0) {
|
|
14
|
+
btw = borderWidth;
|
|
15
|
+
brw = borderWidth;
|
|
16
|
+
bbw = borderWidth;
|
|
17
|
+
blw = borderWidth;
|
|
18
|
+
}
|
|
19
|
+
else if (Array.isArray(borderWidth)) {
|
|
20
|
+
btw = is.positiveNum(borderWidth[0]) ? borderWidth[0] : 0;
|
|
21
|
+
brw = is.positiveNum(borderWidth[1]) ? borderWidth[0] : 0;
|
|
22
|
+
bbw = is.positiveNum(borderWidth[2]) ? borderWidth[0] : 0;
|
|
23
|
+
blw = is.positiveNum(borderWidth[3]) ? borderWidth[0] : 0;
|
|
24
|
+
}
|
|
25
|
+
if (typeof borderRadius === 'number' && borderRadius > 0) {
|
|
26
|
+
btlr = borderRadius;
|
|
27
|
+
btrr = borderRadius;
|
|
28
|
+
bblr = borderRadius;
|
|
29
|
+
bbrr = borderRadius;
|
|
30
|
+
}
|
|
31
|
+
else if (Array.isArray(borderRadius)) {
|
|
32
|
+
btlr = is.positiveNum(borderRadius[0]) ? borderRadius[0] : 0;
|
|
33
|
+
btrr = is.positiveNum(borderRadius[0]) ? borderRadius[0] : 0;
|
|
34
|
+
bblr = is.positiveNum(borderRadius[0]) ? borderRadius[0] : 0;
|
|
35
|
+
bbrr = is.positiveNum(borderRadius[0]) ? borderRadius[0] : 0;
|
|
36
|
+
}
|
|
37
|
+
const p0 = { x: x, y: y };
|
|
38
|
+
const p1 = { x: x + w, y: y };
|
|
39
|
+
const p2 = { x: x + w, y: y + h };
|
|
40
|
+
const p3 = { x: x, y: y + h };
|
|
41
|
+
const p0s = { x: x, y: y + btlr };
|
|
42
|
+
const p0e = { x: x + btlr, y: y };
|
|
43
|
+
const p1s = { x: x + w - btrr, y: y };
|
|
44
|
+
const p1e = { x: x + w, y: y + btrr };
|
|
45
|
+
const p2s = { x: x + w, y: y + h - bbrr };
|
|
46
|
+
const p2e = { x: x + w - bbrr, y: y + h };
|
|
47
|
+
const p3s = { x: x + bblr, y: y + h };
|
|
48
|
+
const p3e = { x: x, y: y + h - bblr };
|
|
49
|
+
let op0 = Object.assign({}, p0);
|
|
50
|
+
let op1 = Object.assign({}, p1);
|
|
51
|
+
let op2 = Object.assign({}, p2);
|
|
52
|
+
let op3 = Object.assign({}, p3);
|
|
53
|
+
let op0s = Object.assign({}, p0s);
|
|
54
|
+
let op0e = Object.assign({}, p0e);
|
|
55
|
+
let op1s = Object.assign({}, p1s);
|
|
56
|
+
let op1e = Object.assign({}, p1e);
|
|
57
|
+
let op2s = Object.assign({}, p2s);
|
|
58
|
+
let op2e = Object.assign({}, p2e);
|
|
59
|
+
let op3s = Object.assign({}, p3s);
|
|
60
|
+
let op3e = Object.assign({}, p3e);
|
|
61
|
+
let ip0 = Object.assign({}, p0);
|
|
62
|
+
let ip1 = Object.assign({}, p1);
|
|
63
|
+
let ip2 = Object.assign({}, p2);
|
|
64
|
+
let ip3 = Object.assign({}, p3);
|
|
65
|
+
let ip0s = Object.assign({}, p0s);
|
|
66
|
+
let ip0e = Object.assign({}, p0e);
|
|
67
|
+
let ip1s = Object.assign({}, p1s);
|
|
68
|
+
let ip1e = Object.assign({}, p1e);
|
|
69
|
+
let ip2s = Object.assign({}, p2s);
|
|
70
|
+
let ip2e = Object.assign({}, p2e);
|
|
71
|
+
let ip3s = Object.assign({}, p3s);
|
|
72
|
+
let ip3e = Object.assign({}, p3e);
|
|
73
|
+
if (boxSizing === 'border-box') {
|
|
74
|
+
ip0 = { x: ip0.x + blw, y: ip0.y + btw };
|
|
75
|
+
ip1 = { x: ip1.x - brw, y: ip1.y + btw };
|
|
76
|
+
ip2 = { x: ip2.x - brw, y: ip2.y - bbw };
|
|
77
|
+
ip3 = { x: ip3.x + blw, y: ip3.y - bbw };
|
|
78
|
+
ip0s = { x: ip0s.x + blw, y: ip0s.y + btw };
|
|
79
|
+
ip0e = { x: ip0e.x + blw, y: ip0e.y + btw };
|
|
80
|
+
ip1s = { x: ip1s.x - brw, y: ip1s.y + btw };
|
|
81
|
+
ip1e = { x: ip1e.x - brw, y: ip1e.y + btw };
|
|
82
|
+
ip2s = { x: ip2s.x - brw, y: ip2s.y - bbw };
|
|
83
|
+
ip2e = { x: ip2e.x - brw, y: ip2e.y - bbw };
|
|
84
|
+
ip3s = { x: ip3s.x + blw, y: ip3s.y - bbw };
|
|
85
|
+
ip3e = { x: ip3e.x + blw, y: ip3e.y - bbw };
|
|
86
|
+
}
|
|
87
|
+
else if (boxSizing === 'content-box') {
|
|
88
|
+
op0 = { x: op0.x - blw, y: op0.y - btw };
|
|
89
|
+
op1 = { x: op1.x + brw, y: op1.y - btw };
|
|
90
|
+
op2 = { x: op2.x + brw, y: op2.y + bbw };
|
|
91
|
+
op3 = { x: op3.x - blw, y: op3.y + bbw };
|
|
92
|
+
op0s = { x: op0s.x - blw, y: op0s.y - btw };
|
|
93
|
+
op0e = { x: op0e.x - blw, y: op0e.y - btw };
|
|
94
|
+
op1s = { x: op1s.x + brw, y: op1s.y - btw };
|
|
95
|
+
op1e = { x: op1e.x + brw, y: op1e.y - btw };
|
|
96
|
+
op2s = { x: op2s.x + brw, y: op2s.y + bbw };
|
|
97
|
+
op2e = { x: op2e.x + brw, y: op2e.y + bbw };
|
|
98
|
+
op3s = { x: op3s.x - blw, y: op3s.y + bbw };
|
|
99
|
+
op3e = { x: op3e.x - blw, y: op3e.y + bbw };
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
ip0 = { x: ip0.x + blw / 2, y: ip0.y + btw / 2 };
|
|
103
|
+
ip1 = { x: ip1.x - brw / 2, y: ip1.y + btw / 2 };
|
|
104
|
+
ip2 = { x: ip2.x - brw / 2, y: ip2.y - bbw / 2 };
|
|
105
|
+
ip3 = { x: ip3.x + blw / 2, y: ip3.y - bbw / 2 };
|
|
106
|
+
ip0s = { x: ip0s.x + blw / 2, y: ip0s.y + btw / 2 };
|
|
107
|
+
ip0e = { x: ip0e.x + blw / 2, y: ip0e.y + btw / 2 };
|
|
108
|
+
ip1s = { x: ip1s.x - brw / 2, y: ip1s.y + btw / 2 };
|
|
109
|
+
ip1e = { x: ip1e.x - brw / 2, y: ip1e.y + btw / 2 };
|
|
110
|
+
ip2s = { x: ip2s.x - brw / 2, y: ip2s.y - bbw / 2 };
|
|
111
|
+
ip2e = { x: ip2e.x - brw / 2, y: ip2e.y - bbw / 2 };
|
|
112
|
+
ip3s = { x: ip3s.x + blw / 2, y: ip3s.y - bbw / 2 };
|
|
113
|
+
ip3e = { x: ip3e.x + blw / 2, y: ip3e.y - bbw / 2 };
|
|
114
|
+
op0 = { x: op0.x - blw / 2, y: op0.y - btw / 2 };
|
|
115
|
+
op1 = { x: op1.x + brw / 2, y: op1.y - btw / 2 };
|
|
116
|
+
op2 = { x: op2.x + brw / 2, y: op2.y + bbw / 2 };
|
|
117
|
+
op3 = { x: op3.x - blw / 2, y: op3.y + bbw / 2 };
|
|
118
|
+
op0s = { x: op0s.x - blw / 2, y: op0s.y - btw / 2 };
|
|
119
|
+
op0e = { x: op0e.x - blw / 2, y: op0e.y - btw / 2 };
|
|
120
|
+
op1s = { x: op1s.x + brw / 2, y: op1s.y - btw / 2 };
|
|
121
|
+
op1e = { x: op1e.x + brw / 2, y: op1e.y - btw / 2 };
|
|
122
|
+
op2s = { x: op2s.x + brw / 2, y: op2s.y + bbw / 2 };
|
|
123
|
+
op2e = { x: op2e.x + brw / 2, y: op2e.y + bbw / 2 };
|
|
124
|
+
op3s = { x: op3s.x - blw / 2, y: op3s.y + bbw / 2 };
|
|
125
|
+
op3e = { x: op3e.x - blw / 2, y: op3e.y + bbw / 2 };
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
btw,
|
|
129
|
+
brw,
|
|
130
|
+
bbw,
|
|
131
|
+
blw,
|
|
132
|
+
btlr,
|
|
133
|
+
btrr,
|
|
134
|
+
bblr,
|
|
135
|
+
bbrr,
|
|
136
|
+
p0,
|
|
137
|
+
p1,
|
|
138
|
+
p2,
|
|
139
|
+
p3,
|
|
140
|
+
p0s,
|
|
141
|
+
p0e,
|
|
142
|
+
p1s,
|
|
143
|
+
p1e,
|
|
144
|
+
p2s,
|
|
145
|
+
p2e,
|
|
146
|
+
p3s,
|
|
147
|
+
p3e,
|
|
148
|
+
op0,
|
|
149
|
+
op1,
|
|
150
|
+
op2,
|
|
151
|
+
op3,
|
|
152
|
+
op0s,
|
|
153
|
+
op0e,
|
|
154
|
+
op1s,
|
|
155
|
+
op1e,
|
|
156
|
+
op2s,
|
|
157
|
+
op2e,
|
|
158
|
+
op3s,
|
|
159
|
+
op3e,
|
|
160
|
+
ip0,
|
|
161
|
+
ip1,
|
|
162
|
+
ip2,
|
|
163
|
+
ip3,
|
|
164
|
+
ip0s,
|
|
165
|
+
ip0e,
|
|
166
|
+
ip1s,
|
|
167
|
+
ip1e,
|
|
168
|
+
ip2s,
|
|
169
|
+
ip2e,
|
|
170
|
+
ip3s,
|
|
171
|
+
ip3e
|
|
172
|
+
};
|
|
173
|
+
}
|
package/dist/esm/lib/canvas.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BoardContent
|
|
1
|
+
import type { BoardContent } from '@idraw/types';
|
|
2
2
|
import { Context2D } from './context2d';
|
|
3
3
|
export declare function createContext2D(opts: {
|
|
4
4
|
ctx?: CanvasRenderingContext2D;
|
|
@@ -15,10 +15,4 @@ export declare function createBoardContent(canvas: HTMLCanvasElement, opts: {
|
|
|
15
15
|
width: number;
|
|
16
16
|
height: number;
|
|
17
17
|
devicePixelRatio: number;
|
|
18
|
-
offscreen?: boolean;
|
|
19
|
-
createCustomContext2D?: (opts: {
|
|
20
|
-
width: number;
|
|
21
|
-
height: number;
|
|
22
|
-
devicePixelRatio: number;
|
|
23
|
-
}) => ViewContext2D;
|
|
24
18
|
}): BoardContent;
|
package/dist/esm/lib/canvas.js
CHANGED
|
@@ -23,82 +23,35 @@ export function createOffscreenContext2D(opts) {
|
|
|
23
23
|
return context2d;
|
|
24
24
|
}
|
|
25
25
|
export function createBoardContent(canvas, opts) {
|
|
26
|
-
const { width, height, devicePixelRatio
|
|
26
|
+
const { width, height, devicePixelRatio } = opts;
|
|
27
27
|
const ctxOpts = {
|
|
28
28
|
width,
|
|
29
29
|
height,
|
|
30
30
|
devicePixelRatio
|
|
31
31
|
};
|
|
32
32
|
const ctx = canvas.getContext('2d');
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (offscreen === true) {
|
|
58
|
-
const viewContext = createOffscreenContext2D(ctxOpts);
|
|
59
|
-
const overlayContext = createOffscreenContext2D(ctxOpts);
|
|
60
|
-
const underlayContext = createOffscreenContext2D(ctxOpts);
|
|
61
|
-
const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
|
|
62
|
-
const drawView = () => {
|
|
63
|
-
const { width: w, height: h } = viewContext.$getSize();
|
|
64
|
-
boardContext.clearRect(0, 0, w, h);
|
|
65
|
-
boardContext.drawImage(underlayContext.canvas, 0, 0, w, h);
|
|
66
|
-
boardContext.drawImage(viewContext.canvas, 0, 0, w, h);
|
|
67
|
-
boardContext.drawImage(overlayContext.canvas, 0, 0, w, h);
|
|
68
|
-
underlayContext.clearRect(0, 0, w, h);
|
|
69
|
-
viewContext.clearRect(0, 0, w, h);
|
|
70
|
-
overlayContext.clearRect(0, 0, w, h);
|
|
71
|
-
};
|
|
72
|
-
const content = {
|
|
73
|
-
underlayContext,
|
|
74
|
-
viewContext,
|
|
75
|
-
overlayContext,
|
|
76
|
-
boardContext,
|
|
77
|
-
drawView
|
|
78
|
-
};
|
|
79
|
-
return content;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
const viewContext = createContext2D(ctxOpts);
|
|
83
|
-
const overlayContext = createContext2D(ctxOpts);
|
|
84
|
-
const underlayContext = createContext2D(ctxOpts);
|
|
85
|
-
const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
|
|
86
|
-
const drawView = () => {
|
|
87
|
-
boardContext.clearRect(0, 0, width, height);
|
|
88
|
-
boardContext.drawImage(underlayContext.canvas, 0, 0, width, height);
|
|
89
|
-
boardContext.drawImage(viewContext.canvas, 0, 0, width, height);
|
|
90
|
-
boardContext.drawImage(overlayContext.canvas, 0, 0, width, height);
|
|
91
|
-
underlayContext.clearRect(0, 0, width, height);
|
|
92
|
-
viewContext.clearRect(0, 0, width, height);
|
|
93
|
-
overlayContext.clearRect(0, 0, width, height);
|
|
94
|
-
};
|
|
95
|
-
const content = {
|
|
96
|
-
underlayContext,
|
|
97
|
-
viewContext,
|
|
98
|
-
overlayContext,
|
|
99
|
-
boardContext,
|
|
100
|
-
drawView
|
|
101
|
-
};
|
|
102
|
-
return content;
|
|
103
|
-
}
|
|
33
|
+
const viewContext = createOffscreenContext2D(ctxOpts);
|
|
34
|
+
const overlayContext = createOffscreenContext2D(ctxOpts);
|
|
35
|
+
const underlayContext = createOffscreenContext2D(ctxOpts);
|
|
36
|
+
const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
|
|
37
|
+
const tempContext = createOffscreenContext2D(ctxOpts);
|
|
38
|
+
const drawView = () => {
|
|
39
|
+
const { width: w, height: h } = viewContext.$getSize();
|
|
40
|
+
boardContext.clearRect(0, 0, w, h);
|
|
41
|
+
boardContext.drawImage(underlayContext.canvas, 0, 0, w, h);
|
|
42
|
+
boardContext.drawImage(viewContext.canvas, 0, 0, w, h);
|
|
43
|
+
boardContext.drawImage(overlayContext.canvas, 0, 0, w, h);
|
|
44
|
+
underlayContext.clearRect(0, 0, w, h);
|
|
45
|
+
viewContext.clearRect(0, 0, w, h);
|
|
46
|
+
overlayContext.clearRect(0, 0, w, h);
|
|
47
|
+
};
|
|
48
|
+
const content = {
|
|
49
|
+
underlayContext,
|
|
50
|
+
viewContext,
|
|
51
|
+
overlayContext,
|
|
52
|
+
boardContext,
|
|
53
|
+
tempContext,
|
|
54
|
+
drawView
|
|
55
|
+
};
|
|
56
|
+
return content;
|
|
104
57
|
}
|
package/dist/esm/lib/color.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export function toColorHexNum(color) {
|
|
2
|
-
return parseInt(color.replace(
|
|
2
|
+
return parseInt(color.replace(/^#/, '0x'));
|
|
3
3
|
}
|
|
4
4
|
export function toColorHexStr(color) {
|
|
5
5
|
return '#' + color.toString(16);
|
|
6
6
|
}
|
|
7
7
|
export function isColorStr(color) {
|
|
8
|
-
return typeof color === 'string' && (
|
|
8
|
+
return (typeof color === 'string' && (/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color) || /^[a-z]{1,}$/i.test(color)));
|
|
9
9
|
}
|
|
10
10
|
const colorNameMap = {
|
|
11
11
|
aliceblue: '#f0f8ff',
|
|
@@ -163,6 +163,9 @@ export function colorToCSS(color) {
|
|
|
163
163
|
if (typeof color === 'string') {
|
|
164
164
|
css = color;
|
|
165
165
|
}
|
|
166
|
+
else if ((color === null || color === void 0 ? void 0 : color.stops.length) === 1) {
|
|
167
|
+
css = color.stops[0].color;
|
|
168
|
+
}
|
|
166
169
|
else if ((color === null || color === void 0 ? void 0 : color.type) === 'linear-gradient') {
|
|
167
170
|
const items = [];
|
|
168
171
|
if (typeof color.angle === 'number') {
|
|
@@ -213,14 +216,14 @@ export function mergeHexColorAlpha(hex, alpha) {
|
|
|
213
216
|
return hex;
|
|
214
217
|
}
|
|
215
218
|
let hexAlpha = 1;
|
|
216
|
-
const regHex1 =
|
|
217
|
-
const regHex2 =
|
|
219
|
+
const regHex1 = /^#[0-9a-f]{6,6}$/i;
|
|
220
|
+
const regHex2 = /^#[0-9a-f]{8,8}$/i;
|
|
218
221
|
let result = hex;
|
|
219
222
|
if (regHex1.test(hex)) {
|
|
220
|
-
hexAlpha = parseInt(hex.substring(5, 7).replace(
|
|
223
|
+
hexAlpha = parseInt(hex.substring(5, 7).replace(/^#/, '0x'));
|
|
221
224
|
}
|
|
222
225
|
else if (regHex2.test(hex)) {
|
|
223
|
-
hexAlpha = parseInt(hex.substring(7, 9).replace(
|
|
226
|
+
hexAlpha = parseInt(hex.substring(7, 9).replace(/^#/, '0x'));
|
|
224
227
|
result = hex.substring(0, 7);
|
|
225
228
|
}
|
|
226
229
|
hexAlpha = hexAlpha * alpha;
|
|
@@ -59,6 +59,8 @@ export declare class Context2D implements ViewContext2D {
|
|
|
59
59
|
lineTo(x: number, y: number): void;
|
|
60
60
|
moveTo(x: number, y: number): void;
|
|
61
61
|
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
|
|
62
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
|
|
63
|
+
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
|
|
62
64
|
getLineDash(): number[];
|
|
63
65
|
setLineDash(nums: number[]): void;
|
|
64
66
|
stroke(path?: Path2D): void;
|
|
@@ -179,6 +179,12 @@ export class Context2D {
|
|
|
179
179
|
arcTo(x1, y1, x2, y2, radius) {
|
|
180
180
|
return __classPrivateFieldGet(this, _Context2D_ctx, "f").arcTo(this.$doPixelRatio(x1), this.$doPixelRatio(y1), this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius));
|
|
181
181
|
}
|
|
182
|
+
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
183
|
+
return __classPrivateFieldGet(this, _Context2D_ctx, "f").bezierCurveTo(this.$doPixelRatio(cp1x), this.$doPixelRatio(cp1y), this.$doPixelRatio(cp2x), this.$doPixelRatio(cp2y), this.$doPixelRatio(x), this.$doPixelRatio(y));
|
|
184
|
+
}
|
|
185
|
+
quadraticCurveTo(cpx, cpy, x, y) {
|
|
186
|
+
return __classPrivateFieldGet(this, _Context2D_ctx, "f").quadraticCurveTo(this.$doPixelRatio(cpx), this.$doPixelRatio(cpy), this.$doPixelRatio(x), this.$doPixelRatio(y));
|
|
187
|
+
}
|
|
182
188
|
getLineDash() {
|
|
183
189
|
return __classPrivateFieldGet(this, _Context2D_ctx, "f").getLineDash();
|
|
184
190
|
}
|
package/dist/esm/lib/data.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Data, Element, LoadItemMap } from '@idraw/types';
|
|
2
2
|
export declare function deepClone<T = any>(target: T): T;
|
|
3
3
|
export declare function deepCloneElement<T extends Element = Element>(element: T): T;
|
|
4
|
+
export declare function deepCloneData(data: Data): Data;
|
|
4
5
|
export declare function sortDataAsserts(data: Data, opts?: {
|
|
5
6
|
clone?: boolean;
|
|
6
7
|
}): Data;
|
package/dist/esm/lib/data.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
1
12
|
import { createAssetId, createUUID, isAssetId } from './uuid';
|
|
2
13
|
export function deepClone(target) {
|
|
3
14
|
function _clone(t) {
|
|
@@ -40,11 +51,17 @@ export function deepCloneElement(element) {
|
|
|
40
51
|
_resetUUID(elem);
|
|
41
52
|
return elem;
|
|
42
53
|
}
|
|
54
|
+
export function deepCloneData(data) {
|
|
55
|
+
const { elements } = data, restData = __rest(data, ["elements"]);
|
|
56
|
+
return Object.assign(Object.assign({}, deepClone(restData)), {
|
|
57
|
+
elements: elements.map((elem) => deepCloneElement(elem))
|
|
58
|
+
});
|
|
59
|
+
}
|
|
43
60
|
function is(target) {
|
|
44
|
-
return Object.prototype.toString
|
|
61
|
+
return (Object.prototype.toString
|
|
45
62
|
.call(target)
|
|
46
63
|
.replace(/[\]|\[]{1,1}/gi, '')
|
|
47
|
-
.split(' ')[1];
|
|
64
|
+
.split(' ')[1]);
|
|
48
65
|
}
|
|
49
66
|
export function sortDataAsserts(data, opts) {
|
|
50
67
|
const assets = data.assets || {};
|
package/dist/esm/lib/is.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
declare function positiveNum(value: any): boolean;
|
|
1
2
|
declare function number(value: any): boolean;
|
|
2
3
|
declare function x(value: any): boolean;
|
|
3
4
|
declare function y(value: any): boolean;
|
|
@@ -21,6 +22,7 @@ declare function fontFamily(value: any): boolean;
|
|
|
21
22
|
declare function fontWeight(value: any): boolean;
|
|
22
23
|
declare function numberStr(value: any): boolean;
|
|
23
24
|
export declare const is: {
|
|
25
|
+
positiveNum: typeof positiveNum;
|
|
24
26
|
x: typeof x;
|
|
25
27
|
y: typeof y;
|
|
26
28
|
w: typeof w;
|
package/dist/esm/lib/is.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { isColorStr } from './color';
|
|
2
|
+
function positiveNum(value) {
|
|
3
|
+
return typeof value === 'number' && value >= 0;
|
|
4
|
+
}
|
|
2
5
|
function number(value) {
|
|
3
6
|
return typeof value === 'number' && (value > 0 || value <= 0);
|
|
4
7
|
}
|
|
@@ -9,19 +12,29 @@ function y(value) {
|
|
|
9
12
|
return number(value);
|
|
10
13
|
}
|
|
11
14
|
function w(value) {
|
|
12
|
-
return
|
|
15
|
+
return positiveNum(value);
|
|
13
16
|
}
|
|
14
17
|
function h(value) {
|
|
15
|
-
return
|
|
18
|
+
return positiveNum(value);
|
|
16
19
|
}
|
|
17
20
|
function angle(value) {
|
|
18
21
|
return typeof value === 'number' && value >= -360 && value <= 360;
|
|
19
22
|
}
|
|
20
23
|
function borderWidth(value) {
|
|
21
|
-
return
|
|
24
|
+
return (positiveNum(value) ||
|
|
25
|
+
(Array.isArray(value) &&
|
|
26
|
+
positiveNum(value[0]) &&
|
|
27
|
+
positiveNum(value[1]) &&
|
|
28
|
+
positiveNum(value[2]) &&
|
|
29
|
+
positiveNum(value[3])));
|
|
22
30
|
}
|
|
23
31
|
function borderRadius(value) {
|
|
24
|
-
return
|
|
32
|
+
return (positiveNum(value) ||
|
|
33
|
+
(Array.isArray(value) &&
|
|
34
|
+
positiveNum(value[0]) &&
|
|
35
|
+
positiveNum(value[1]) &&
|
|
36
|
+
positiveNum(value[2]) &&
|
|
37
|
+
positiveNum(value[3])));
|
|
25
38
|
}
|
|
26
39
|
function color(value) {
|
|
27
40
|
return isColorStr(value);
|
|
@@ -36,7 +49,9 @@ function imageSrc(value) {
|
|
|
36
49
|
return imageBase64(value) || imageURL(value);
|
|
37
50
|
}
|
|
38
51
|
function svg(value) {
|
|
39
|
-
return typeof value === 'string' &&
|
|
52
|
+
return (typeof value === 'string' &&
|
|
53
|
+
/^(<svg[\s]{1,}|<svg>)/i.test(`${value}`.trim()) &&
|
|
54
|
+
/<\/[\s]{0,}svg>$/i.test(`${value}`.trim()));
|
|
40
55
|
}
|
|
41
56
|
function html(value) {
|
|
42
57
|
let result = false;
|
|
@@ -75,6 +90,7 @@ function numberStr(value) {
|
|
|
75
90
|
return /^(-?\d+(?:\.\d+)?)$/.test(`${value}`);
|
|
76
91
|
}
|
|
77
92
|
export const is = {
|
|
93
|
+
positiveNum,
|
|
78
94
|
x,
|
|
79
95
|
y,
|
|
80
96
|
w,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function merge<T extends Record<string, any> = any, U extends Record<string, any> = any>(target: T, source: U): T & U;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function merge(target, source) {
|
|
2
|
+
const result = target;
|
|
3
|
+
for (const key in source) {
|
|
4
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
5
|
+
if (typeof source[key] === 'object' &&
|
|
6
|
+
source[key] !== null &&
|
|
7
|
+
typeof result[key] === 'object' &&
|
|
8
|
+
result[key] !== null) {
|
|
9
|
+
result[key] = merge(result[key], source[key]);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
result[key] = source[key];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return target;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
package/dist/esm/lib/view-box.js
CHANGED
|
@@ -3,7 +3,8 @@ const defaultElemConfig = getDefaultElementDetailConfig();
|
|
|
3
3
|
export function calcViewBoxSize(viewElem, opts) {
|
|
4
4
|
const { viewScaleInfo } = opts;
|
|
5
5
|
const { scale } = viewScaleInfo;
|
|
6
|
-
let { borderRadius
|
|
6
|
+
let { borderRadius } = viewElem.detail;
|
|
7
|
+
const { borderDash } = viewElem.detail;
|
|
7
8
|
const hasBorderDash = Array.isArray(borderDash) && borderDash.length > 0;
|
|
8
9
|
const { boxSizing = defaultElemConfig.boxSizing, borderWidth } = viewElem.detail;
|
|
9
10
|
if (Array.isArray(borderWidth)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Point, PointSize, Data, ViewScaleInfo, ViewSizeInfo, Element, ElementType, ElementSize, ViewContext2D, ViewRectVertexes, ViewRectInfo
|
|
1
|
+
import { Point, PointSize, Data, ViewScaleInfo, ViewSizeInfo, Element, ElementType, ElementSize, ViewContext2D, ViewRectVertexes, ViewRectInfo } from '@idraw/types';
|
|
2
2
|
export declare function calcViewScaleInfo(info: {
|
|
3
3
|
scale: number;
|
|
4
4
|
offsetX: number;
|
|
@@ -67,7 +67,3 @@ export declare function calcElementViewRectInfo(elemSize: ElementSize, opts: {
|
|
|
67
67
|
viewScaleInfo: ViewScaleInfo;
|
|
68
68
|
range?: boolean;
|
|
69
69
|
}): ViewRectInfo;
|
|
70
|
-
export declare function calcElementViewRectInfoMap(elemSize: ElementSize, opts: {
|
|
71
|
-
groupQueue: Element<'group'>[];
|
|
72
|
-
viewScaleInfo: ViewScaleInfo;
|
|
73
|
-
}): ViewRectInfoMap;
|
|
@@ -308,47 +308,3 @@ export function calcElementViewRectInfo(elemSize, opts) {
|
|
|
308
308
|
}
|
|
309
309
|
return viewRectInfo;
|
|
310
310
|
}
|
|
311
|
-
export function calcElementViewRectInfoMap(elemSize, opts) {
|
|
312
|
-
const { groupQueue, viewScaleInfo } = opts;
|
|
313
|
-
const originRectInfo = calcElementOriginRectInfo(elemSize, { groupQueue });
|
|
314
|
-
const { center, top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight } = originRectInfo;
|
|
315
|
-
const viewRectInfo = {
|
|
316
|
-
center: calcViewPointSize(center, { viewScaleInfo }),
|
|
317
|
-
topLeft: calcViewPointSize(topLeft, { viewScaleInfo }),
|
|
318
|
-
topRight: calcViewPointSize(topRight, { viewScaleInfo }),
|
|
319
|
-
bottomLeft: calcViewPointSize(bottomLeft, { viewScaleInfo }),
|
|
320
|
-
bottomRight: calcViewPointSize(bottomRight, { viewScaleInfo }),
|
|
321
|
-
top: calcViewPointSize(top, { viewScaleInfo }),
|
|
322
|
-
right: calcViewPointSize(right, { viewScaleInfo }),
|
|
323
|
-
left: calcViewPointSize(left, { viewScaleInfo }),
|
|
324
|
-
bottom: calcViewPointSize(bottom, { viewScaleInfo })
|
|
325
|
-
};
|
|
326
|
-
const viewMaxX = Math.max(viewRectInfo.topLeft.x, viewRectInfo.topRight.x, viewRectInfo.bottomRight.x, viewRectInfo.bottomLeft.x);
|
|
327
|
-
const viewMaxY = Math.max(viewRectInfo.topLeft.y, viewRectInfo.topRight.y, viewRectInfo.bottomRight.y, viewRectInfo.bottomLeft.y);
|
|
328
|
-
const viewMinX = Math.min(viewRectInfo.topLeft.x, viewRectInfo.topRight.x, viewRectInfo.bottomRight.x, viewRectInfo.bottomLeft.x);
|
|
329
|
-
const viewMinY = Math.min(viewRectInfo.topLeft.y, viewRectInfo.topRight.y, viewRectInfo.bottomRight.y, viewRectInfo.bottomLeft.y);
|
|
330
|
-
const rangeCenter = { x: viewRectInfo.center.x, y: viewRectInfo.center.y };
|
|
331
|
-
const rangeTopLeft = { x: viewMinX, y: viewMinY };
|
|
332
|
-
const rangeTopRight = { x: viewMaxX, y: viewMinY };
|
|
333
|
-
const rangeBottomRight = { x: viewMaxX, y: viewMaxY };
|
|
334
|
-
const rangeBottomLeft = { x: viewMinX, y: viewMaxY };
|
|
335
|
-
const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
|
|
336
|
-
const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
|
|
337
|
-
const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
|
|
338
|
-
const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
|
|
339
|
-
const rangeRectInfo = {
|
|
340
|
-
center: rangeCenter,
|
|
341
|
-
topLeft: rangeTopLeft,
|
|
342
|
-
topRight: rangeTopRight,
|
|
343
|
-
bottomLeft: rangeBottomLeft,
|
|
344
|
-
bottomRight: rangeBottomRight,
|
|
345
|
-
top: rangeTop,
|
|
346
|
-
right: rangeRight,
|
|
347
|
-
left: rangeLeft,
|
|
348
|
-
bottom: rangeBottom
|
|
349
|
-
};
|
|
350
|
-
return {
|
|
351
|
-
originRectInfo,
|
|
352
|
-
rangeRectInfo
|
|
353
|
-
};
|
|
354
|
-
}
|