@idraw/util 0.4.0-beta.4 → 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.
Files changed (60) hide show
  1. package/dist/esm/index.d.ts +17 -7
  2. package/dist/esm/index.js +17 -7
  3. package/dist/esm/lib/box.d.ts +2 -0
  4. package/dist/esm/lib/box.js +173 -0
  5. package/dist/esm/lib/canvas.d.ts +0 -1
  6. package/dist/esm/lib/canvas.js +26 -50
  7. package/dist/esm/lib/color.js +9 -6
  8. package/dist/esm/lib/config.d.ts +5 -10
  9. package/dist/esm/lib/config.js +9 -9
  10. package/dist/esm/lib/context2d.d.ts +4 -0
  11. package/dist/esm/lib/context2d.js +20 -0
  12. package/dist/esm/lib/controller.d.ts +8 -2
  13. package/dist/esm/lib/controller.js +184 -9
  14. package/dist/esm/lib/data.d.ts +7 -2
  15. package/dist/esm/lib/data.js +114 -4
  16. package/dist/esm/lib/element.d.ts +5 -0
  17. package/dist/esm/lib/element.js +54 -1
  18. package/dist/esm/lib/event.d.ts +4 -2
  19. package/dist/esm/lib/event.js +31 -11
  20. package/dist/esm/lib/file.d.ts +2 -1
  21. package/dist/esm/lib/file.js +4 -1
  22. package/dist/esm/lib/flat.d.ts +2 -0
  23. package/dist/esm/lib/flat.js +132 -0
  24. package/dist/esm/lib/group.d.ts +3 -0
  25. package/dist/esm/lib/group.js +81 -0
  26. package/dist/esm/lib/handle-element.d.ts +6 -1
  27. package/dist/esm/lib/handle-element.js +108 -43
  28. package/dist/esm/lib/html.d.ts +1 -1
  29. package/dist/esm/lib/is.d.ts +3 -1
  30. package/dist/esm/lib/is.js +21 -5
  31. package/dist/esm/lib/istype.d.ts +1 -0
  32. package/dist/esm/lib/istype.js +3 -0
  33. package/dist/esm/lib/merge.d.ts +1 -0
  34. package/dist/esm/lib/merge.js +17 -0
  35. package/dist/esm/lib/modify-recorder.d.ts +15 -0
  36. package/dist/esm/lib/modify-recorder.js +177 -0
  37. package/dist/esm/lib/modify.d.ts +6 -0
  38. package/dist/esm/lib/modify.js +99 -0
  39. package/dist/esm/lib/omit.d.ts +1 -0
  40. package/dist/esm/lib/omit.js +7 -0
  41. package/dist/esm/lib/point-move-element.d.ts +5 -0
  42. package/dist/esm/lib/point-move-element.js +26 -0
  43. package/dist/esm/lib/rect.js +9 -9
  44. package/dist/esm/lib/resize-element.d.ts +2 -0
  45. package/dist/esm/lib/resize-element.js +101 -0
  46. package/dist/esm/lib/rotate.js +8 -13
  47. package/dist/esm/lib/store.d.ts +9 -5
  48. package/dist/esm/lib/store.js +39 -9
  49. package/dist/esm/lib/text.d.ts +1 -0
  50. package/dist/esm/lib/text.js +4 -0
  51. package/dist/esm/lib/time.d.ts +1 -0
  52. package/dist/esm/lib/time.js +13 -1
  53. package/dist/esm/lib/view-box.js +4 -2
  54. package/dist/esm/lib/view-calc.d.ts +16 -3
  55. package/dist/esm/lib/view-calc.js +127 -3
  56. package/dist/esm/lib/view-content.d.ts +14 -0
  57. package/dist/esm/lib/view-content.js +88 -0
  58. package/dist/index.global.js +1614 -257
  59. package/dist/index.global.min.js +1 -1
  60. package/package.json +2 -2
@@ -1,8 +1,8 @@
1
- export { delay, compose, throttle } from './lib/time';
1
+ 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 } 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';
@@ -13,13 +13,13 @@ export { calcDistance, calcSpeed, equalPoint, equalTouchPoint, vaildPoint, vaild
13
13
  export { Store } from './lib/store';
14
14
  export { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from './lib/middleware';
15
15
  export { Context2D } from './lib/context2d';
16
- export { rotateElement, parseRadianToAngle, parseAngleToRadian, rotateElementVertexes, getElementRotateVertexes, calcElementCenter, calcElementCenterFromVertexes, rotatePointInGroup, limitAngle } from './lib/rotate';
17
- export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, findElementFromListByPosition, findElementQueueFromListByPosition, findElementsFromListByPositions, getGroupQueueFromList, getElementSize, mergeElementAsset, filterElementAsset, isResourceElement, getElementPositionFromList, calcElementListSize } from './lib/element';
16
+ export { rotateElement, parseRadianToAngle, parseAngleToRadian, rotateElementVertexes, getElementRotateVertexes, calcElementCenter, calcElementCenterFromVertexes, rotatePointInGroup, limitAngle, calcRadian } from './lib/rotate';
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 } from './lib/view-calc';
19
+ export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView, calcViewScaleInfo, calcElementViewRectInfo, calcElementOriginRectInfo, originRectInfoToRangeRectInfo, isViewPointInElementSize, isViewPointInVertexes } from './lib/view-calc';
20
20
  export { rotatePoint, rotateVertexes, rotateByCenter } from './lib/rotate';
21
21
  export { getElementVertexes, calcElementVertexesInGroup, calcElementVertexesQueueInGroup, calcElementQueueVertexesQueueInGroup } from './lib/vertex';
22
- export { calcElementSizeController } from './lib/controller';
22
+ export { calcElementSizeController, calcLayoutSizeController } from './lib/controller';
23
23
  export { generateSVGPath, parseSVGPath } from './lib/svg-path';
24
24
  export { generateHTML, parseHTML } from './lib/html';
25
25
  export { compressImage } from './lib/image';
@@ -27,4 +27,14 @@ export { formatNumber } from './lib/number';
27
27
  export { matrixToAngle, matrixToRadian } from './lib/matrix';
28
28
  export { getDefaultElementDetailConfig, getDefaultElementRectDetail } from './lib/config';
29
29
  export { calcViewBoxSize } from './lib/view-box';
30
- export { createElement, insertElementToListByPosition, deleteElementInListByPosition, deleteElementInList, moveElementPosition, updateElementInList } from './lib/handle-element';
30
+ export { createElement, insertElementToListByPosition, deleteElementInListByPosition, deleteElementInList, moveElementPosition, updateElementInList, updateElementInListByPosition } from './lib/handle-element';
31
+ export { deepResizeGroupElement } from './lib/resize-element';
32
+ export { calcViewCenterContent, calcViewCenter } from './lib/view-content';
33
+ export { modifyElement, getModifiedElement } from './lib/modify';
34
+ export { enhanceFontFamliy } from './lib/text';
35
+ export { flatElementList } from './lib/flat';
36
+ export { groupElementsByPosition, ungroupElementsByPosition } from './lib/group';
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
@@ -1,8 +1,8 @@
1
- export { delay, compose, throttle } from './lib/time';
1
+ 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 } 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';
@@ -13,13 +13,13 @@ export { calcDistance, calcSpeed, equalPoint, equalTouchPoint, vaildPoint, vaild
13
13
  export { Store } from './lib/store';
14
14
  export { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from './lib/middleware';
15
15
  export { Context2D } from './lib/context2d';
16
- export { rotateElement, parseRadianToAngle, parseAngleToRadian, rotateElementVertexes, getElementRotateVertexes, calcElementCenter, calcElementCenterFromVertexes, rotatePointInGroup, limitAngle } from './lib/rotate';
17
- export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, findElementFromListByPosition, findElementQueueFromListByPosition, findElementsFromListByPositions, getGroupQueueFromList, getElementSize, mergeElementAsset, filterElementAsset, isResourceElement, getElementPositionFromList, calcElementListSize } from './lib/element';
16
+ export { rotateElement, parseRadianToAngle, parseAngleToRadian, rotateElementVertexes, getElementRotateVertexes, calcElementCenter, calcElementCenterFromVertexes, rotatePointInGroup, limitAngle, calcRadian } from './lib/rotate';
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 } from './lib/view-calc';
19
+ export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView, calcViewScaleInfo, calcElementViewRectInfo, calcElementOriginRectInfo, originRectInfoToRangeRectInfo, isViewPointInElementSize, isViewPointInVertexes } from './lib/view-calc';
20
20
  export { rotatePoint, rotateVertexes, rotateByCenter } from './lib/rotate';
21
21
  export { getElementVertexes, calcElementVertexesInGroup, calcElementVertexesQueueInGroup, calcElementQueueVertexesQueueInGroup } from './lib/vertex';
22
- export { calcElementSizeController } from './lib/controller';
22
+ export { calcElementSizeController, calcLayoutSizeController } from './lib/controller';
23
23
  export { generateSVGPath, parseSVGPath } from './lib/svg-path';
24
24
  export { generateHTML, parseHTML } from './lib/html';
25
25
  export { compressImage } from './lib/image';
@@ -27,4 +27,14 @@ export { formatNumber } from './lib/number';
27
27
  export { matrixToAngle, matrixToRadian } from './lib/matrix';
28
28
  export { getDefaultElementDetailConfig, getDefaultElementRectDetail } from './lib/config';
29
29
  export { calcViewBoxSize } from './lib/view-box';
30
- export { createElement, insertElementToListByPosition, deleteElementInListByPosition, deleteElementInList, moveElementPosition, updateElementInList } from './lib/handle-element';
30
+ export { createElement, insertElementToListByPosition, deleteElementInListByPosition, deleteElementInList, moveElementPosition, updateElementInList, updateElementInListByPosition } from './lib/handle-element';
31
+ export { deepResizeGroupElement } from './lib/resize-element';
32
+ export { calcViewCenterContent, calcViewCenter } from './lib/view-content';
33
+ export { modifyElement, getModifiedElement } from './lib/modify';
34
+ export { enhanceFontFamliy } from './lib/text';
35
+ export { flatElementList } from './lib/flat';
36
+ export { groupElementsByPosition, ungroupElementsByPosition } from './lib/group';
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,2 @@
1
+ import type { BoxInfo, Element } from '@idraw/types';
2
+ export declare function elementToBoxInfo(elem: Element): BoxInfo;
@@ -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
+ }
@@ -15,5 +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
18
  }): BoardContent;
@@ -23,59 +23,35 @@ export function createOffscreenContext2D(opts) {
23
23
  return context2d;
24
24
  }
25
25
  export function createBoardContent(canvas, opts) {
26
- const { width, height, devicePixelRatio, offscreen } = opts;
26
+ const { width, height, devicePixelRatio } = opts;
27
27
  const ctxOpts = {
28
28
  width,
29
29
  height,
30
30
  devicePixelRatio
31
31
  };
32
- if (offscreen === true) {
33
- const ctx = canvas.getContext('2d');
34
- const viewContext = createOffscreenContext2D(ctxOpts);
35
- const helperContext = createOffscreenContext2D(ctxOpts);
36
- const underContext = createOffscreenContext2D(ctxOpts);
37
- const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
38
- const drawView = () => {
39
- const { width: w, height: h } = viewContext.$getSize();
40
- boardContext.clearRect(0, 0, w, h);
41
- boardContext.drawImage(underContext.canvas, 0, 0, w, h);
42
- boardContext.drawImage(viewContext.canvas, 0, 0, w, h);
43
- boardContext.drawImage(helperContext.canvas, 0, 0, w, h);
44
- underContext.clearRect(0, 0, w, h);
45
- viewContext.clearRect(0, 0, w, h);
46
- helperContext.clearRect(0, 0, w, h);
47
- };
48
- const content = {
49
- underContext,
50
- viewContext,
51
- helperContext,
52
- boardContext,
53
- drawView
54
- };
55
- return content;
56
- }
57
- else {
58
- const ctx = canvas.getContext('2d');
59
- const viewContext = createContext2D(ctxOpts);
60
- const helperContext = createContext2D(ctxOpts);
61
- const underContext = createContext2D(ctxOpts);
62
- const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
63
- const drawView = () => {
64
- boardContext.clearRect(0, 0, width, height);
65
- boardContext.drawImage(underContext.canvas, 0, 0, width, height);
66
- boardContext.drawImage(viewContext.canvas, 0, 0, width, height);
67
- boardContext.drawImage(helperContext.canvas, 0, 0, width, height);
68
- underContext.clearRect(0, 0, width, height);
69
- viewContext.clearRect(0, 0, width, height);
70
- helperContext.clearRect(0, 0, width, height);
71
- };
72
- const content = {
73
- underContext,
74
- viewContext,
75
- helperContext,
76
- boardContext,
77
- drawView
78
- };
79
- return content;
80
- }
32
+ const ctx = canvas.getContext('2d');
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;
81
57
  }
@@ -1,11 +1,11 @@
1
1
  export function toColorHexNum(color) {
2
- return parseInt(color.replace(/^\#/, '0x'));
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' && (/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color) || /^[a-z]{1,}$/i.test(color));
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 = /^\#[0-9a-f]{6,6}$/i;
217
- const regHex2 = /^\#[0-9a-f]{8,8}$/i;
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(/^\#/, '0x'));
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(/^\#/, '0x'));
226
+ hexAlpha = parseInt(hex.substring(7, 9).replace(/^#/, '0x'));
224
227
  result = hex.substring(0, 7);
225
228
  }
226
229
  hexAlpha = hexAlpha * alpha;
@@ -1,14 +1,9 @@
1
- import type { ViewScaleInfo, DefaultElementDetailConfig, ElementRectDetail, ElementCircleDetail, ElementTextDetail, ElementSVGDetail, ElementImageDetail, ElementGroupDetail } from '@idraw/types';
1
+ import type { DefaultElementDetailConfig, ElementSize, ElementRectDetail, ElementCircleDetail, ElementTextDetail, ElementSVGDetail, ElementImageDetail, ElementGroupDetail } from '@idraw/types';
2
+ export declare const defaultText = "Text Element";
2
3
  export declare function getDefaultElementDetailConfig(): DefaultElementDetailConfig;
3
4
  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;
5
+ export declare function getDefaultElementCircleDetail(): ElementCircleDetail;
6
+ export declare function getDefaultElementTextDetail(elementSize: ElementSize): ElementTextDetail;
10
7
  export declare function getDefaultElementSVGDetail(): ElementSVGDetail;
11
8
  export declare function getDefaultElementImageDetail(): ElementImageDetail;
12
- export declare function getDefaultElementGroupDetail(opts?: {
13
- viewScaleInfo: ViewScaleInfo;
14
- }): ElementGroupDetail;
9
+ export declare function getDefaultElementGroupDetail(): ElementGroupDetail;
@@ -1,3 +1,4 @@
1
+ export const defaultText = 'Text Element';
1
2
  export function getDefaultElementDetailConfig() {
2
3
  const config = {
3
4
  boxSizing: 'border-box',
@@ -14,9 +15,10 @@ export function getDefaultElementDetailConfig() {
14
15
  textAlign: 'left',
15
16
  verticalAlign: 'top',
16
17
  fontSize: 16,
17
- lineHeight: 20,
18
18
  fontFamily: 'sans-serif',
19
19
  fontWeight: 400,
20
+ minInlineSize: 'auto',
21
+ wordBreak: 'break-all',
20
22
  overflow: 'hidden'
21
23
  };
22
24
  return config;
@@ -27,24 +29,22 @@ export function getDefaultElementRectDetail() {
27
29
  };
28
30
  return detail;
29
31
  }
30
- export function getDefaultElementCircleDetail(opts) {
32
+ export function getDefaultElementCircleDetail() {
31
33
  const detail = {
32
34
  background: '#D9D9D9',
33
35
  radius: 0
34
36
  };
35
37
  return detail;
36
38
  }
37
- export function getDefaultElementTextDetail(opts) {
38
- var _a;
39
+ export function getDefaultElementTextDetail(elementSize) {
39
40
  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
41
  const detail = {
42
- text: 'Text Element',
42
+ text: defaultText,
43
43
  color: detailConfig.color,
44
44
  fontFamily: detailConfig.fontFamily,
45
45
  fontWeight: detailConfig.fontWeight,
46
- lineHeight: detailConfig.fontSize * scale,
47
- fontSize: detailConfig.fontSize * scale,
46
+ lineHeight: elementSize.w / defaultText.length,
47
+ fontSize: elementSize.w / defaultText.length,
48
48
  textAlign: 'center',
49
49
  verticalAlign: 'middle'
50
50
  };
@@ -62,7 +62,7 @@ export function getDefaultElementImageDetail() {
62
62
  };
63
63
  return detail;
64
64
  }
65
- export function getDefaultElementGroupDetail(opts) {
65
+ export function getDefaultElementGroupDetail() {
66
66
  const detail = {
67
67
  children: [],
68
68
  background: '#D9D9D9',
@@ -5,11 +5,13 @@ export declare class Context2D implements ViewContext2D {
5
5
  $undoPixelRatio(num: number): number;
6
6
  $doPixelRatio(num: number): number;
7
7
  $getContext(): CanvasRenderingContext2D;
8
+ $setContext(ctx: CanvasRenderingContext2D): void;
8
9
  $setFont(opts: {
9
10
  fontSize: number;
10
11
  fontFamily?: string;
11
12
  fontWeight?: 'bold' | number | string;
12
13
  }): void;
14
+ $resetFont(): void;
13
15
  $getOffscreenCanvas(): OffscreenCanvas | null;
14
16
  $resize(opts: {
15
17
  width: number;
@@ -57,6 +59,8 @@ export declare class Context2D implements ViewContext2D {
57
59
  lineTo(x: number, y: number): void;
58
60
  moveTo(x: number, y: number): void;
59
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;
60
64
  getLineDash(): number[];
61
65
  setLineDash(nums: number[]): void;
62
66
  stroke(path?: Path2D): void;
@@ -10,12 +10,16 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _Context2D_ctx, _Context2D_opts;
13
+ const defaultFontSize = 12;
14
+ const defaultFontWeight = '400';
15
+ const defaultFontFamily = `-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'`;
13
16
  export class Context2D {
14
17
  constructor(ctx, opts) {
15
18
  _Context2D_ctx.set(this, void 0);
16
19
  _Context2D_opts.set(this, void 0);
17
20
  __classPrivateFieldSet(this, _Context2D_ctx, ctx, "f");
18
21
  __classPrivateFieldSet(this, _Context2D_opts, Object.assign({ devicePixelRatio: 1, offscreenCanvas: null }, opts), "f");
22
+ this.$resetFont();
19
23
  }
20
24
  $undoPixelRatio(num) {
21
25
  return num / __classPrivateFieldGet(this, _Context2D_opts, "f").devicePixelRatio;
@@ -26,6 +30,9 @@ export class Context2D {
26
30
  $getContext() {
27
31
  return __classPrivateFieldGet(this, _Context2D_ctx, "f");
28
32
  }
33
+ $setContext(ctx) {
34
+ __classPrivateFieldSet(this, _Context2D_ctx, ctx, "f");
35
+ }
29
36
  $setFont(opts) {
30
37
  const strList = [];
31
38
  if (opts.fontWeight) {
@@ -35,6 +42,13 @@ export class Context2D {
35
42
  strList.push(`${opts.fontFamily || 'sans-serif'}`);
36
43
  __classPrivateFieldGet(this, _Context2D_ctx, "f").font = `${strList.join(' ')}`;
37
44
  }
45
+ $resetFont() {
46
+ this.$setFont({
47
+ fontSize: defaultFontSize,
48
+ fontFamily: defaultFontFamily,
49
+ fontWeight: defaultFontWeight
50
+ });
51
+ }
38
52
  $getOffscreenCanvas() {
39
53
  return __classPrivateFieldGet(this, _Context2D_opts, "f").offscreenCanvas;
40
54
  }
@@ -165,6 +179,12 @@ export class Context2D {
165
179
  arcTo(x1, y1, x2, y2, radius) {
166
180
  return __classPrivateFieldGet(this, _Context2D_ctx, "f").arcTo(this.$doPixelRatio(x1), this.$doPixelRatio(y1), this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius));
167
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
+ }
168
188
  getLineDash() {
169
189
  return __classPrivateFieldGet(this, _Context2D_ctx, "f").getLineDash();
170
190
  }
@@ -1,6 +1,12 @@
1
- import type { Element, ElementSize, ElementSizeController, ViewScaleInfo } from '@idraw/types';
1
+ import type { Element, ElementSize, ElementSizeController, ViewScaleInfo, LayoutSizeController } from '@idraw/types';
2
2
  export declare function calcElementSizeController(elemSize: ElementSize, opts: {
3
3
  groupQueue: Element<'group'>[];
4
- controllerSize?: number;
4
+ controllerSize: number;
5
+ rotateControllerSize: number;
6
+ rotateControllerPosition: number;
5
7
  viewScaleInfo: ViewScaleInfo;
6
8
  }): ElementSizeController;
9
+ export declare function calcLayoutSizeController(layoutSize: Pick<ElementSize, 'x' | 'y' | 'w' | 'h'>, opts: {
10
+ controllerSize?: number;
11
+ viewScaleInfo: ViewScaleInfo;
12
+ }): LayoutSizeController;