@idraw/util 0.4.0-beta.9 → 0.4.0

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 (105) hide show
  1. package/dist/esm/index.d.ts +46 -31
  2. package/dist/esm/index.js +46 -31
  3. package/dist/esm/{lib → tool}/color.js +9 -6
  4. package/dist/esm/{lib → tool}/event.d.ts +1 -0
  5. package/dist/esm/{lib → tool}/event.js +3 -0
  6. package/dist/esm/tool/flat-object.d.ts +6 -0
  7. package/dist/esm/tool/flat-object.js +28 -0
  8. package/dist/esm/tool/get-set-del.d.ts +4 -0
  9. package/dist/esm/tool/get-set-del.js +65 -0
  10. package/dist/esm/{lib → tool}/html.d.ts +1 -1
  11. package/dist/esm/{lib → tool}/html.js +6 -2
  12. package/dist/esm/{lib → tool}/istype.d.ts +1 -0
  13. package/dist/esm/{lib → tool}/istype.js +3 -0
  14. package/dist/esm/tool/merge.d.ts +1 -0
  15. package/dist/esm/tool/merge.js +17 -0
  16. package/dist/esm/tool/omit.d.ts +1 -0
  17. package/dist/esm/tool/omit.js +7 -0
  18. package/dist/esm/tool/store.d.ts +16 -0
  19. package/dist/esm/{lib → tool}/store.js +17 -5
  20. package/dist/esm/tool/unflat-object.d.ts +3 -0
  21. package/dist/esm/tool/unflat-object.js +91 -0
  22. package/dist/esm/{lib → tool}/uuid.d.ts +1 -1
  23. package/dist/esm/tool/uuid.js +39 -0
  24. package/dist/esm/view/box.d.ts +2 -0
  25. package/dist/esm/view/box.js +173 -0
  26. package/dist/esm/{lib → view}/canvas.d.ts +0 -1
  27. package/dist/esm/view/canvas.js +57 -0
  28. package/dist/esm/{lib → view}/check.js +14 -14
  29. package/dist/esm/{lib → view}/config.js +2 -2
  30. package/dist/esm/{lib → view}/context2d.d.ts +4 -0
  31. package/dist/esm/{lib → view}/context2d.js +20 -0
  32. package/dist/esm/view/controller.d.ts +12 -0
  33. package/dist/esm/view/controller.js +321 -0
  34. package/dist/esm/{lib → view}/data.d.ts +1 -0
  35. package/dist/esm/{lib → view}/data.js +43 -22
  36. package/dist/esm/{lib → view}/element.d.ts +5 -0
  37. package/dist/esm/{lib → view}/element.js +66 -5
  38. package/dist/esm/view/flat.d.ts +2 -0
  39. package/dist/esm/view/flat.js +133 -0
  40. package/dist/esm/view/group.d.ts +3 -0
  41. package/dist/esm/view/group.js +81 -0
  42. package/dist/esm/{lib → view}/handle-element.d.ts +11 -1
  43. package/dist/esm/{lib → view}/handle-element.js +102 -51
  44. package/dist/esm/view/handle-global.d.ts +4 -0
  45. package/dist/esm/view/handle-global.js +28 -0
  46. package/dist/esm/view/handle-layout.d.ts +4 -0
  47. package/dist/esm/view/handle-layout.js +28 -0
  48. package/dist/esm/{lib → view}/is.d.ts +3 -1
  49. package/dist/esm/{lib → view}/is.js +22 -6
  50. package/dist/esm/view/modify-record.d.ts +4 -0
  51. package/dist/esm/view/modify-record.js +10 -0
  52. package/dist/esm/view/point-move-element.d.ts +5 -0
  53. package/dist/esm/view/point-move-element.js +26 -0
  54. package/dist/esm/view/position.d.ts +15 -0
  55. package/dist/esm/view/position.js +79 -0
  56. package/dist/esm/view/rect.js +11 -0
  57. package/dist/esm/view/resize-element.d.ts +4 -0
  58. package/dist/esm/view/resize-element.js +255 -0
  59. package/dist/esm/{lib → view}/rotate.js +8 -13
  60. package/dist/esm/view/text.d.ts +1 -0
  61. package/dist/esm/view/text.js +4 -0
  62. package/dist/esm/{lib → view}/view-box.js +3 -1
  63. package/dist/esm/{lib → view}/view-calc.d.ts +16 -3
  64. package/dist/esm/{lib → view}/view-calc.js +127 -3
  65. package/dist/esm/view/view-content.d.ts +14 -0
  66. package/dist/esm/view/view-content.js +88 -0
  67. package/dist/index.global.js +1938 -346
  68. package/dist/index.global.min.js +1 -1
  69. package/package.json +2 -2
  70. package/dist/esm/lib/canvas.js +0 -81
  71. package/dist/esm/lib/controller.d.ts +0 -6
  72. package/dist/esm/lib/controller.js +0 -103
  73. package/dist/esm/lib/rect.js +0 -11
  74. package/dist/esm/lib/resize-element.d.ts +0 -2
  75. package/dist/esm/lib/resize-element.js +0 -101
  76. package/dist/esm/lib/store.d.ts +0 -11
  77. package/dist/esm/lib/uuid.js +0 -31
  78. /package/dist/esm/{lib → tool}/color.d.ts +0 -0
  79. /package/dist/esm/{lib → tool}/file.d.ts +0 -0
  80. /package/dist/esm/{lib → tool}/file.js +0 -0
  81. /package/dist/esm/{lib → tool}/image.d.ts +0 -0
  82. /package/dist/esm/{lib → tool}/image.js +0 -0
  83. /package/dist/esm/{lib → tool}/number.d.ts +0 -0
  84. /package/dist/esm/{lib → tool}/number.js +0 -0
  85. /package/dist/esm/{lib → tool}/time.d.ts +0 -0
  86. /package/dist/esm/{lib → tool}/time.js +0 -0
  87. /package/dist/esm/{lib → view}/check.d.ts +0 -0
  88. /package/dist/esm/{lib → view}/config.d.ts +0 -0
  89. /package/dist/esm/{lib → view}/load.d.ts +0 -0
  90. /package/dist/esm/{lib → view}/load.js +0 -0
  91. /package/dist/esm/{lib → view}/matrix.d.ts +0 -0
  92. /package/dist/esm/{lib → view}/matrix.js +0 -0
  93. /package/dist/esm/{lib → view}/middleware.d.ts +0 -0
  94. /package/dist/esm/{lib → view}/middleware.js +0 -0
  95. /package/dist/esm/{lib → view}/parser.d.ts +0 -0
  96. /package/dist/esm/{lib → view}/parser.js +0 -0
  97. /package/dist/esm/{lib → view}/point.d.ts +0 -0
  98. /package/dist/esm/{lib → view}/point.js +0 -0
  99. /package/dist/esm/{lib → view}/rect.d.ts +0 -0
  100. /package/dist/esm/{lib → view}/rotate.d.ts +0 -0
  101. /package/dist/esm/{lib → view}/svg-path.d.ts +0 -0
  102. /package/dist/esm/{lib → view}/svg-path.js +0 -0
  103. /package/dist/esm/{lib → view}/vertex.d.ts +0 -0
  104. /package/dist/esm/{lib → view}/vertex.js +0 -0
  105. /package/dist/esm/{lib → view}/view-box.d.ts +0 -0
@@ -0,0 +1,15 @@
1
+ import type { ElementPosition } from '@idraw/types';
2
+ export declare function calcResultMovePosition(opts: {
3
+ from: ElementPosition;
4
+ to: ElementPosition;
5
+ }): {
6
+ from: ElementPosition;
7
+ to: ElementPosition;
8
+ } | null;
9
+ export declare function calcRevertMovePosition(opts: {
10
+ from: ElementPosition;
11
+ to: ElementPosition;
12
+ }): {
13
+ from: ElementPosition;
14
+ to: ElementPosition;
15
+ } | null;
@@ -0,0 +1,79 @@
1
+ export function calcResultMovePosition(opts) {
2
+ const from = [...opts.from];
3
+ const to = [...opts.to];
4
+ if (from.length === 0 || to.length === 0) {
5
+ return null;
6
+ }
7
+ if (from.length <= to.length) {
8
+ for (let i = 0; i < from.length; i++) {
9
+ if (to[i] === from[i]) {
10
+ if (i === from.length - 1) {
11
+ return null;
12
+ }
13
+ continue;
14
+ }
15
+ }
16
+ }
17
+ let moveDirection = null;
18
+ if (from.length >= 1 && to.length >= 1) {
19
+ if (from.length <= to.length) {
20
+ if (from.length === 1) {
21
+ if (from[0] < to[0]) {
22
+ moveDirection = 'up-down';
23
+ }
24
+ }
25
+ else {
26
+ for (let i = 0; i < from.length; i++) {
27
+ if (from[i] === to[i]) {
28
+ if (from.length === from.length - 1) {
29
+ moveDirection = 'up-down';
30
+ break;
31
+ }
32
+ }
33
+ else {
34
+ break;
35
+ }
36
+ }
37
+ }
38
+ }
39
+ if (from.length >= to.length) {
40
+ if (to.length === 1) {
41
+ if (to[0] < from[0]) {
42
+ moveDirection = 'down-up';
43
+ }
44
+ }
45
+ else {
46
+ for (let i = 0; i < to.length; i++) {
47
+ if (i === to.length - 1 && to[i] < from[i]) {
48
+ moveDirection = 'down-up';
49
+ }
50
+ if (from[i] === to[i]) {
51
+ continue;
52
+ }
53
+ else {
54
+ break;
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+ const startEffectIndex = from.length - 1;
61
+ const endEffectIndex = to.length - 1;
62
+ if (moveDirection === 'up-down' && startEffectIndex >= 0) {
63
+ to[startEffectIndex] -= 1;
64
+ }
65
+ else if (moveDirection === 'down-up' && endEffectIndex >= 0) {
66
+ from[endEffectIndex] += 1;
67
+ }
68
+ return { from, to };
69
+ }
70
+ export function calcRevertMovePosition(opts) {
71
+ const result = calcResultMovePosition(opts);
72
+ if (!result) {
73
+ return result;
74
+ }
75
+ return {
76
+ from: [...result.to],
77
+ to: [...result.from]
78
+ };
79
+ }
@@ -0,0 +1,11 @@
1
+ export function checkRectIntersect(rect1, rect2) {
2
+ const rect1MinX = rect1.x;
3
+ const rect1MinY = rect1.y;
4
+ const rect1MaxX = rect1.x + rect1.w;
5
+ const rect1MaxY = rect1.y + rect1.h;
6
+ const rect2MinX = rect2.x;
7
+ const rect2MinY = rect2.y;
8
+ const rect2MaxX = rect2.x + rect2.w;
9
+ const rect2MaxY = rect2.y + rect2.h;
10
+ return rect1MinX <= rect2MaxX && rect1MaxX >= rect2MinX && rect1MinY <= rect2MaxY && rect1MaxY >= rect2MinY;
11
+ }
@@ -0,0 +1,4 @@
1
+ import type { Element, ElementSize, ElementOperations, ModifyRecord } from '@idraw/types';
2
+ export declare function resizeEffectGroupElement(elem: Element<'group'>, size: Partial<ElementSize>, opts?: {
3
+ resizeEffect?: ElementOperations['resizeEffect'];
4
+ }): ModifyRecord<'resizeElements'> | null;
@@ -0,0 +1,255 @@
1
+ import { istype } from '../tool/istype';
2
+ import { formatNumber } from '../tool/number';
3
+ import { toFlattenElement } from '../view/modify-record';
4
+ const doNum = (n) => {
5
+ return formatNumber(n, { decimalPlaces: 4 });
6
+ };
7
+ function resizeElementBaseDetailByRatio(elem, opts) {
8
+ const beforeElem = { detail: {} };
9
+ const afterElem = { detail: {} };
10
+ const record = {
11
+ type: 'modifyElement',
12
+ time: Date.now(),
13
+ content: {
14
+ method: 'modifyElement',
15
+ uuid: elem.uuid,
16
+ before: null,
17
+ after: null
18
+ }
19
+ };
20
+ const { detail } = elem;
21
+ const { xRatio, yRatio, maxRatio } = opts;
22
+ const middleRatio = (xRatio + yRatio) / 2;
23
+ const { borderWidth, borderRadius, borderDash, shadowOffsetX, shadowOffsetY, shadowBlur } = detail;
24
+ if (typeof borderWidth === 'number') {
25
+ detail.borderWidth = doNum(borderWidth * middleRatio);
26
+ beforeElem.detail.borderWidth = borderWidth;
27
+ afterElem.detail.borderWidth = detail.borderWidth;
28
+ }
29
+ else if (Array.isArray(detail.borderWidth)) {
30
+ const bw = borderWidth;
31
+ detail.borderWidth = [doNum(bw[0] * yRatio), doNum(bw[1] * xRatio), doNum(bw[2] * yRatio), doNum(bw[3] * xRatio)];
32
+ beforeElem.detail.borderWidth = [...bw];
33
+ afterElem.detail.borderWidth = [...detail.borderWidth];
34
+ }
35
+ if (typeof borderRadius === 'number') {
36
+ detail.borderRadius = doNum(borderRadius * middleRatio);
37
+ beforeElem.detail.borderRadius = borderRadius;
38
+ afterElem.detail.borderRadius = detail.borderRadius;
39
+ }
40
+ else if (Array.isArray(detail.borderRadius)) {
41
+ const br = borderRadius;
42
+ detail.borderRadius = [br[0] * xRatio, br[1] * xRatio, br[2] * yRatio, br[3] * yRatio];
43
+ beforeElem.detail.borderRadius = [...br];
44
+ afterElem.detail.borderRadius = [...detail.borderRadius];
45
+ }
46
+ if (Array.isArray(borderDash)) {
47
+ borderDash.forEach((dash, i) => {
48
+ detail.borderDash[i] = doNum(dash * maxRatio);
49
+ });
50
+ beforeElem.detail.borderDash = [...borderDash];
51
+ afterElem.detail.borderDash = [...detail.borderDash];
52
+ }
53
+ if (typeof shadowOffsetX === 'number') {
54
+ detail.shadowOffsetX = doNum(shadowOffsetX * maxRatio);
55
+ beforeElem.detail.shadowOffsetX = shadowOffsetX;
56
+ afterElem.detail.shadowOffsetX = detail.shadowOffsetX;
57
+ }
58
+ if (typeof shadowOffsetY === 'number') {
59
+ detail.shadowOffsetY = doNum(shadowOffsetY * maxRatio);
60
+ beforeElem.detail.shadowOffsetY = shadowOffsetY;
61
+ afterElem.detail.shadowOffsetY = detail.shadowOffsetY;
62
+ }
63
+ if (typeof shadowBlur === 'number') {
64
+ detail.shadowBlur = doNum(shadowBlur * maxRatio);
65
+ beforeElem.detail.shadowBlur = shadowBlur;
66
+ afterElem.detail.shadowBlur = detail.shadowBlur;
67
+ }
68
+ record.content.before = toFlattenElement(beforeElem);
69
+ record.content.after = toFlattenElement(afterElem);
70
+ return record;
71
+ }
72
+ function resizeElementBaseByRatio(elem, opts) {
73
+ const { xRatio, yRatio } = opts;
74
+ const { uuid, x, y, w, h } = elem;
75
+ elem.x = doNum(x * xRatio);
76
+ elem.y = doNum(y * yRatio);
77
+ elem.w = doNum(w * xRatio);
78
+ elem.h = doNum(h * yRatio);
79
+ const record = {
80
+ type: 'modifyElement',
81
+ time: Date.now(),
82
+ content: {
83
+ method: 'modifyElement',
84
+ uuid: uuid,
85
+ before: { x, y, w, h },
86
+ after: { x: elem.x, y: elem.y, w: elem.w, h: elem.h }
87
+ }
88
+ };
89
+ const detailRecord = resizeElementBaseDetailByRatio(elem, opts);
90
+ record.content.before = Object.assign(Object.assign({}, record.content.before), detailRecord.content.before);
91
+ record.content.after = Object.assign(Object.assign({}, record.content.after), detailRecord.content.after);
92
+ return record;
93
+ }
94
+ function resizeTextElementDetailByRatio(elem, opts) {
95
+ const { minRatio, maxRatio } = opts;
96
+ const { fontSize, lineHeight } = elem.detail;
97
+ const ratio = (minRatio + maxRatio) / 2;
98
+ const beforeFlattenElem = {};
99
+ const afterFlattenElem = {};
100
+ if (fontSize && fontSize > 0) {
101
+ elem.detail.fontSize = doNum(fontSize * ratio);
102
+ beforeFlattenElem['detail.fontSize'] = fontSize;
103
+ afterFlattenElem['detail.fontSize'] = elem.detail.fontSize;
104
+ }
105
+ if (lineHeight && lineHeight > 0) {
106
+ elem.detail.lineHeight = doNum(lineHeight * ratio);
107
+ beforeFlattenElem['detail.lineHeight'] = lineHeight;
108
+ afterFlattenElem['detail.lineHeight'] = elem.detail.lineHeight;
109
+ }
110
+ const record = {
111
+ type: 'modifyElement',
112
+ time: Date.now(),
113
+ content: {
114
+ method: 'modifyElement',
115
+ uuid: elem.uuid,
116
+ before: beforeFlattenElem,
117
+ after: afterFlattenElem
118
+ }
119
+ };
120
+ return record;
121
+ }
122
+ function deepResizeElementByRatio(elem, opts, record) {
123
+ const { type, uuid } = elem;
124
+ const rootRecord = resizeElementBaseByRatio(elem, opts);
125
+ const rootRecordBefore = Object.assign(Object.assign({}, rootRecord.content.before), { uuid });
126
+ const rootRecordAfter = Object.assign(Object.assign({}, rootRecord.content.after), { uuid });
127
+ record === null || record === void 0 ? void 0 : record.content.before.push(rootRecordBefore);
128
+ record === null || record === void 0 ? void 0 : record.content.after.push(rootRecordAfter);
129
+ if (type === 'circle') {
130
+ }
131
+ else if (type === 'text') {
132
+ const textRecord = resizeTextElementDetailByRatio(elem, opts);
133
+ Object.keys(textRecord.content.before || {}).forEach((key) => {
134
+ var _a;
135
+ rootRecordBefore[key] = (_a = textRecord.content.before) === null || _a === void 0 ? void 0 : _a[key];
136
+ });
137
+ Object.keys(textRecord.content.after || {}).forEach((key) => {
138
+ var _a;
139
+ rootRecordAfter[key] = (_a = textRecord.content.after) === null || _a === void 0 ? void 0 : _a[key];
140
+ });
141
+ }
142
+ else if (type === 'image') {
143
+ }
144
+ else if (type === 'svg') {
145
+ }
146
+ else if (type === 'html') {
147
+ }
148
+ else if (type === 'path') {
149
+ }
150
+ else if (type === 'group' && Array.isArray(elem.detail.children)) {
151
+ elem.detail.children.forEach((child) => {
152
+ deepResizeElementByRatio(child, opts, record);
153
+ });
154
+ }
155
+ }
156
+ function fixedResizeGroupElementChildren(elem, opts, record) {
157
+ if (!(elem.type === 'group' && Array.isArray(elem.detail.children))) {
158
+ return;
159
+ }
160
+ const { moveX, moveY, moveH, moveW } = opts;
161
+ let childChangedX = 0;
162
+ let childChangedY = 0;
163
+ let needReszieChildren = false;
164
+ if ((moveX !== 0 || moveY !== 0) && (moveH !== 0 || moveW !== 0)) {
165
+ needReszieChildren = true;
166
+ childChangedX = -moveX;
167
+ childChangedY = -moveY;
168
+ }
169
+ if (needReszieChildren !== true) {
170
+ return;
171
+ }
172
+ elem.detail.children.forEach((child) => {
173
+ const { uuid, x, y } = child;
174
+ const afterX = x + childChangedX;
175
+ const afterY = y + childChangedY;
176
+ const before = { uuid, x, y };
177
+ const after = { uuid, x: afterX, y: afterY };
178
+ child.x = afterX;
179
+ child.y = afterY;
180
+ record === null || record === void 0 ? void 0 : record.content.before.push(before);
181
+ record === null || record === void 0 ? void 0 : record.content.after.push(after);
182
+ });
183
+ }
184
+ export function resizeEffectGroupElement(elem, size, opts) {
185
+ const record = {
186
+ type: 'resizeElements',
187
+ time: Date.now(),
188
+ content: {
189
+ method: 'modifyElements',
190
+ before: [],
191
+ after: []
192
+ }
193
+ };
194
+ const uuid = elem.uuid;
195
+ const originX = elem.x;
196
+ const originY = elem.y;
197
+ const originW = elem.w;
198
+ const originH = elem.h;
199
+ const resizeX = (istype.number(size.x) ? size.x : elem.x);
200
+ const resizeY = (istype.number(size.y) ? size.y : elem.y);
201
+ const resizeW = (size.w && size.w > 0 ? size.w : elem.w) || 0;
202
+ const resizeH = (size.h && size.h > 0 ? size.h : elem.h) || 0;
203
+ const beforeGroupElem = { uuid, x: originX, y: originY, w: originW, h: originH };
204
+ const afterGroupElem = { uuid, x: resizeX, y: resizeY, w: resizeW, h: resizeH };
205
+ if ((opts === null || opts === void 0 ? void 0 : opts.resizeEffect) === 'deepResize') {
206
+ record.content.before.push(beforeGroupElem);
207
+ record.content.after.push(afterGroupElem);
208
+ const xRatio = resizeW / elem.w;
209
+ const yRatio = resizeH / elem.h;
210
+ if (xRatio === yRatio && xRatio === 1) {
211
+ return record;
212
+ }
213
+ const minRatio = Math.min(xRatio, yRatio);
214
+ const maxRatio = Math.max(xRatio, yRatio);
215
+ elem.w = resizeW;
216
+ elem.h = resizeH;
217
+ const resizeRadioOpts = { xRatio, yRatio, minRatio, maxRatio };
218
+ if (elem.type === 'group' && Array.isArray(elem.detail.children)) {
219
+ elem.detail.children.forEach((child) => {
220
+ deepResizeElementByRatio(child, resizeRadioOpts, record);
221
+ });
222
+ }
223
+ const groupDetailRecord = resizeElementBaseDetailByRatio(elem, resizeRadioOpts);
224
+ Object.keys(groupDetailRecord.content.before || {}).forEach((key) => {
225
+ var _a;
226
+ beforeGroupElem[key] = (_a = groupDetailRecord.content.before) === null || _a === void 0 ? void 0 : _a[key];
227
+ });
228
+ Object.keys(groupDetailRecord.content.after || {}).forEach((key) => {
229
+ var _a;
230
+ afterGroupElem[key] = (_a = groupDetailRecord.content.after) === null || _a === void 0 ? void 0 : _a[key];
231
+ });
232
+ return record;
233
+ }
234
+ if ((opts === null || opts === void 0 ? void 0 : opts.resizeEffect) === 'fixed') {
235
+ record.content.before.push(beforeGroupElem);
236
+ record.content.after.push(afterGroupElem);
237
+ const moveX = resizeX - elem.x;
238
+ const moveY = resizeY - elem.y;
239
+ const moveW = resizeW - elem.w;
240
+ const moveH = resizeH - elem.h;
241
+ fixedResizeGroupElementChildren(elem, { moveX, moveY, moveH, moveW }, record);
242
+ elem.w = resizeW;
243
+ elem.h = resizeH;
244
+ elem.x = resizeX;
245
+ elem.y = resizeY;
246
+ return record;
247
+ }
248
+ elem.w = resizeW;
249
+ elem.h = resizeH;
250
+ elem.x = resizeX;
251
+ elem.y = resizeY;
252
+ record.content.before.push(beforeGroupElem);
253
+ record.content.after.push(afterGroupElem);
254
+ return record;
255
+ }
@@ -46,18 +46,10 @@ export function calcElementCenterFromVertexes(ves) {
46
46
  return calcElementCenter(elemSize);
47
47
  }
48
48
  export function calcRadian(center, start, end) {
49
- const startAngle = calcLineRadian(center, start);
50
- const endAngle = calcLineRadian(center, end);
51
- if (endAngle !== null && startAngle !== null) {
52
- if (startAngle > (Math.PI * 3) / 2 && endAngle < Math.PI / 2) {
53
- return endAngle + (Math.PI * 2 - startAngle);
54
- }
55
- else if (endAngle > (Math.PI * 3) / 2 && startAngle < Math.PI / 2) {
56
- return startAngle + (Math.PI * 2 - endAngle);
57
- }
58
- else {
59
- return endAngle - startAngle;
60
- }
49
+ const startRadian = calcLineRadian(center, start);
50
+ const endRadian = calcLineRadian(center, end);
51
+ if (endRadian !== null && startRadian !== null) {
52
+ return endRadian - startRadian;
61
53
  }
62
54
  else {
63
55
  return 0;
@@ -199,12 +191,15 @@ export function rotateVertexes(center, ves, radian) {
199
191
  ];
200
192
  }
201
193
  export function limitAngle(angle) {
202
- if (!(angle > 0 || angle < 0) || angle === 0) {
194
+ if (!(angle > 0 || angle < 0) || angle === 0 || angle === 360) {
203
195
  return 0;
204
196
  }
205
197
  let num = angle % 360;
206
198
  if (num < 0) {
207
199
  num += 360;
208
200
  }
201
+ else if (angle === 360) {
202
+ num = 0;
203
+ }
209
204
  return num;
210
205
  }
@@ -0,0 +1 @@
1
+ export declare function enhanceFontFamliy(fontFamily?: string): string;
@@ -0,0 +1,4 @@
1
+ const baseFontFamilyList = ['-apple-system', '"system-ui"', ' "Segoe UI"', ' Roboto', '"Helvetica Neue"', 'Arial', '"Noto Sans"', ' sans-serif'];
2
+ export function enhanceFontFamliy(fontFamily) {
3
+ return [fontFamily, ...baseFontFamilyList].join(', ');
4
+ }
@@ -4,6 +4,8 @@ export function calcViewBoxSize(viewElem, opts) {
4
4
  const { viewScaleInfo } = opts;
5
5
  const { scale } = viewScaleInfo;
6
6
  let { borderRadius } = viewElem.detail;
7
+ const { borderDash } = viewElem.detail;
8
+ const hasBorderDash = Array.isArray(borderDash) && borderDash.length > 0;
7
9
  const { boxSizing = defaultElemConfig.boxSizing, borderWidth } = viewElem.detail;
8
10
  if (Array.isArray(borderWidth)) {
9
11
  borderRadius = 0;
@@ -21,7 +23,7 @@ export function calcViewBoxSize(viewElem, opts) {
21
23
  if (typeof borderWidth === 'number') {
22
24
  bw = (borderWidth || 0) * scale;
23
25
  }
24
- if (boxSizing === 'border-box') {
26
+ if (boxSizing === 'border-box' && !hasBorderDash) {
25
27
  x = viewElem.x + bw / 2;
26
28
  y = viewElem.y + bw / 2;
27
29
  w = viewElem.w - bw;
@@ -1,4 +1,4 @@
1
- import { Point, PointSize, Data, ViewScaleInfo, ViewSizeInfo, Element, ElementType, ElementSize, ViewContext2D, ViewRectVertexes } from '@idraw/types';
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;
@@ -23,11 +23,9 @@ export declare function viewScroll(opts: {
23
23
  }): ViewScaleInfo;
24
24
  export declare function calcViewElementSize(size: ElementSize, opts: {
25
25
  viewScaleInfo: ViewScaleInfo;
26
- viewSizeInfo: ViewSizeInfo;
27
26
  }): ElementSize;
28
27
  export declare function calcViewPointSize(size: PointSize, opts: {
29
28
  viewScaleInfo: ViewScaleInfo;
30
- viewSizeInfo: ViewSizeInfo;
31
29
  }): PointSize;
32
30
  export declare function calcViewVertexes(vertexes: ViewRectVertexes, opts: {
33
31
  viewScaleInfo: ViewScaleInfo;
@@ -39,6 +37,12 @@ export declare function isViewPointInElement(p: Point, opts: {
39
37
  viewScaleInfo: ViewScaleInfo;
40
38
  viewSizeInfo: ViewSizeInfo;
41
39
  }): boolean;
40
+ export declare function isViewPointInElementSize(p: Point, elemSize: ElementSize, opts?: {
41
+ includeBorder?: boolean;
42
+ }): boolean;
43
+ export declare function isViewPointInVertexes(p: Point, vertexes: ViewRectVertexes, opts?: {
44
+ includeBorder?: boolean;
45
+ }): boolean;
42
46
  export declare function getViewPointAtElement(p: Point, opts: {
43
47
  context2d: ViewContext2D;
44
48
  data: Data;
@@ -54,3 +58,12 @@ export declare function isElementInView(elem: ElementSize, opts: {
54
58
  viewScaleInfo: ViewScaleInfo;
55
59
  viewSizeInfo: ViewSizeInfo;
56
60
  }): boolean;
61
+ export declare function calcElementOriginRectInfo(elemSize: ElementSize, opts: {
62
+ groupQueue: Element<'group'>[];
63
+ }): ViewRectInfo;
64
+ export declare function originRectInfoToRangeRectInfo(originRectInfo: ViewRectInfo): ViewRectInfo;
65
+ export declare function calcElementViewRectInfo(elemSize: ElementSize, opts: {
66
+ groupQueue: Element<'group'>[];
67
+ viewScaleInfo: ViewScaleInfo;
68
+ range?: boolean;
69
+ }): ViewRectInfo;
@@ -1,5 +1,7 @@
1
1
  import { rotateElementVertexes } from './rotate';
2
2
  import { checkRectIntersect } from './rect';
3
+ import { calcElementVertexesInGroup, calcElementVertexes } from './vertex';
4
+ import { getCenterFromTwoPoints } from './point';
3
5
  export function calcViewScaleInfo(info, opts) {
4
6
  const { scale, offsetX, offsetY } = info;
5
7
  const { viewSizeInfo } = opts;
@@ -86,9 +88,9 @@ export function calcViewVertexes(vertexes, opts) {
86
88
  ];
87
89
  }
88
90
  export function isViewPointInElement(p, opts) {
89
- const { context2d: ctx, element: elem, viewScaleInfo, viewSizeInfo } = opts;
91
+ const { context2d: ctx, element: elem, viewScaleInfo } = opts;
90
92
  const { angle = 0 } = elem;
91
- const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo });
93
+ const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo });
92
94
  const vertexes = rotateElementVertexes({ x, y, w, h, angle });
93
95
  if (vertexes.length >= 2) {
94
96
  ctx.beginPath();
@@ -103,6 +105,25 @@ export function isViewPointInElement(p, opts) {
103
105
  }
104
106
  return false;
105
107
  }
108
+ export function isViewPointInElementSize(p, elemSize, opts) {
109
+ const vertexes = calcElementVertexes(elemSize);
110
+ return isViewPointInVertexes(p, vertexes, opts);
111
+ }
112
+ export function isViewPointInVertexes(p, vertexes, opts) {
113
+ const xList = [vertexes[0].x, vertexes[1].x, vertexes[2].x, vertexes[3].x];
114
+ const yList = [vertexes[0].y, vertexes[1].y, vertexes[2].y, vertexes[3].y];
115
+ const mixX = Math.min(...xList);
116
+ const maxX = Math.max(...xList);
117
+ const mixY = Math.min(...yList);
118
+ const maxY = Math.max(...yList);
119
+ if (p.x > mixX && p.x < maxX && p.y > mixY && p.y < maxY) {
120
+ return true;
121
+ }
122
+ if ((opts === null || opts === void 0 ? void 0 : opts.includeBorder) === true && (p.x === mixX || p.x === maxX || p.y === mixY || p.y === maxY)) {
123
+ return true;
124
+ }
125
+ return false;
126
+ }
106
127
  export function getViewPointAtElement(p, opts) {
107
128
  var _a, _b, _c;
108
129
  const { context2d: ctx, data, viewScaleInfo, viewSizeInfo, groupQueue } = opts;
@@ -174,7 +195,7 @@ export function isElementInView(elem, opts) {
174
195
  const { viewSizeInfo, viewScaleInfo } = opts;
175
196
  const { width, height } = viewSizeInfo;
176
197
  const { angle } = elem;
177
- const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo });
198
+ const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo });
178
199
  const ves = rotateElementVertexes({ x, y, w, h, angle });
179
200
  const viewSize = { x: 0, y: 0, w: width, h: height };
180
201
  const elemStartX = Math.min(ves[0].x, ves[1].x, ves[2].x, ves[3].x);
@@ -184,3 +205,106 @@ export function isElementInView(elem, opts) {
184
205
  const elemSize = { x: elemStartX, y: elemStartY, w: elemEndX - elemStartX, h: elemEndY - elemStartY };
185
206
  return checkRectIntersect(viewSize, elemSize);
186
207
  }
208
+ export function calcElementOriginRectInfo(elemSize, opts) {
209
+ const { groupQueue } = opts;
210
+ const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
211
+ const top = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
212
+ const right = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
213
+ const bottom = getCenterFromTwoPoints(vertexes[2], vertexes[3]);
214
+ const left = getCenterFromTwoPoints(vertexes[3], vertexes[0]);
215
+ const topLeft = vertexes[0];
216
+ const topRight = vertexes[1];
217
+ const bottomRight = vertexes[2];
218
+ const bottomLeft = vertexes[3];
219
+ const maxX = Math.max(topLeft.x, topRight.x, bottomRight.x, bottomLeft.x);
220
+ const maxY = Math.max(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
221
+ const minX = Math.min(topLeft.x, topRight.x, bottomRight.x, bottomLeft.x);
222
+ const minY = Math.min(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
223
+ const center = {
224
+ x: (maxX + minX) / 2,
225
+ y: (maxY + minY) / 2
226
+ };
227
+ const rectInfo = {
228
+ center,
229
+ topLeft,
230
+ topRight,
231
+ bottomLeft,
232
+ bottomRight,
233
+ top,
234
+ right,
235
+ left,
236
+ bottom
237
+ };
238
+ return rectInfo;
239
+ }
240
+ export function originRectInfoToRangeRectInfo(originRectInfo) {
241
+ const rangeMaxX = Math.max(originRectInfo.topLeft.x, originRectInfo.topRight.x, originRectInfo.bottomRight.x, originRectInfo.bottomLeft.x);
242
+ const rangeMaxY = Math.max(originRectInfo.topLeft.y, originRectInfo.topRight.y, originRectInfo.bottomRight.y, originRectInfo.bottomLeft.y);
243
+ const rangeMinX = Math.min(originRectInfo.topLeft.x, originRectInfo.topRight.x, originRectInfo.bottomRight.x, originRectInfo.bottomLeft.x);
244
+ const rangeMinY = Math.min(originRectInfo.topLeft.y, originRectInfo.topRight.y, originRectInfo.bottomRight.y, originRectInfo.bottomLeft.y);
245
+ const rangeCenter = { x: originRectInfo.center.x, y: originRectInfo.center.y };
246
+ const rangeTopLeft = { x: rangeMinX, y: rangeMinY };
247
+ const rangeTopRight = { x: rangeMaxX, y: rangeMinY };
248
+ const rangeBottomRight = { x: rangeMaxX, y: rangeMaxY };
249
+ const rangeBottomLeft = { x: rangeMinX, y: rangeMaxY };
250
+ const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
251
+ const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
252
+ const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
253
+ const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
254
+ const rangeRectInfo = {
255
+ center: rangeCenter,
256
+ topLeft: rangeTopLeft,
257
+ topRight: rangeTopRight,
258
+ bottomLeft: rangeBottomLeft,
259
+ bottomRight: rangeBottomRight,
260
+ top: rangeTop,
261
+ right: rangeRight,
262
+ left: rangeLeft,
263
+ bottom: rangeBottom
264
+ };
265
+ return rangeRectInfo;
266
+ }
267
+ export function calcElementViewRectInfo(elemSize, opts) {
268
+ const { groupQueue, viewScaleInfo, range } = opts;
269
+ const originRectInfo = calcElementOriginRectInfo(elemSize, { groupQueue });
270
+ const { center, top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight } = originRectInfo;
271
+ const viewRectInfo = {
272
+ center: calcViewPointSize(center, { viewScaleInfo }),
273
+ topLeft: calcViewPointSize(topLeft, { viewScaleInfo }),
274
+ topRight: calcViewPointSize(topRight, { viewScaleInfo }),
275
+ bottomLeft: calcViewPointSize(bottomLeft, { viewScaleInfo }),
276
+ bottomRight: calcViewPointSize(bottomRight, { viewScaleInfo }),
277
+ top: calcViewPointSize(top, { viewScaleInfo }),
278
+ right: calcViewPointSize(right, { viewScaleInfo }),
279
+ left: calcViewPointSize(left, { viewScaleInfo }),
280
+ bottom: calcViewPointSize(bottom, { viewScaleInfo })
281
+ };
282
+ if (range === true) {
283
+ const viewMaxX = Math.max(viewRectInfo.topLeft.x, viewRectInfo.topRight.x, viewRectInfo.bottomRight.x, viewRectInfo.bottomLeft.x);
284
+ const viewMaxY = Math.max(viewRectInfo.topLeft.y, viewRectInfo.topRight.y, viewRectInfo.bottomRight.y, viewRectInfo.bottomLeft.y);
285
+ const viewMinX = Math.min(viewRectInfo.topLeft.x, viewRectInfo.topRight.x, viewRectInfo.bottomRight.x, viewRectInfo.bottomLeft.x);
286
+ const viewMinY = Math.min(viewRectInfo.topLeft.y, viewRectInfo.topRight.y, viewRectInfo.bottomRight.y, viewRectInfo.bottomLeft.y);
287
+ const rangeCenter = { x: viewRectInfo.center.x, y: viewRectInfo.center.y };
288
+ const rangeTopLeft = { x: viewMinX, y: viewMinY };
289
+ const rangeTopRight = { x: viewMaxX, y: viewMinY };
290
+ const rangeBottomRight = { x: viewMaxX, y: viewMaxY };
291
+ const rangeBottomLeft = { x: viewMinX, y: viewMaxY };
292
+ const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
293
+ const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
294
+ const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
295
+ const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
296
+ const rangeRectInfo = {
297
+ center: rangeCenter,
298
+ topLeft: rangeTopLeft,
299
+ topRight: rangeTopRight,
300
+ bottomLeft: rangeBottomLeft,
301
+ bottomRight: rangeBottomRight,
302
+ top: rangeTop,
303
+ right: rangeRight,
304
+ left: rangeLeft,
305
+ bottom: rangeBottom
306
+ };
307
+ return rangeRectInfo;
308
+ }
309
+ return viewRectInfo;
310
+ }
@@ -0,0 +1,14 @@
1
+ import type { Data, ViewSizeInfo, ViewScaleInfo, PointSize } from '@idraw/types';
2
+ interface ViewCenterContentResult {
3
+ offsetX: number;
4
+ offsetY: number;
5
+ scale: number;
6
+ }
7
+ export declare function calcViewCenterContent(data: Data, opts: {
8
+ viewSizeInfo: ViewSizeInfo;
9
+ }): ViewCenterContentResult;
10
+ export declare function calcViewCenter(opts?: {
11
+ viewScaleInfo: ViewScaleInfo;
12
+ viewSizeInfo: ViewSizeInfo;
13
+ }): PointSize;
14
+ export {};