@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
@@ -0,0 +1,132 @@
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
+ };
12
+ import { calcElementVertexesInGroup } from './vertex';
13
+ import { limitAngle, parseAngleToRadian, calcElementCenterFromVertexes, rotatePoint } from './rotate';
14
+ function flatElementSize(elemSize, opts) {
15
+ const { groupQueue } = opts;
16
+ let { x, y, w, h, angle = 0 } = elemSize;
17
+ let totalAngle = 0;
18
+ groupQueue.forEach((group) => {
19
+ x += group.x;
20
+ y += group.y;
21
+ totalAngle += group.angle || 0;
22
+ });
23
+ totalAngle = limitAngle(totalAngle);
24
+ if (totalAngle === 0) {
25
+ return {
26
+ x,
27
+ y,
28
+ w,
29
+ h,
30
+ angle
31
+ };
32
+ }
33
+ totalAngle += elemSize.angle || 0;
34
+ totalAngle = limitAngle(totalAngle);
35
+ const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
36
+ const center = calcElementCenterFromVertexes(vertexes);
37
+ const start = rotatePoint(center, vertexes[0], parseAngleToRadian(0 - totalAngle));
38
+ x = start.x;
39
+ y = start.y;
40
+ return {
41
+ x,
42
+ y,
43
+ w,
44
+ h,
45
+ angle: totalAngle
46
+ };
47
+ }
48
+ function isValidElement(elem) {
49
+ var _a;
50
+ if (['rect', 'circle'].includes(elem.type)) {
51
+ const detail = elem.detail;
52
+ if (!detail.background && !detail.borderWidth) {
53
+ return false;
54
+ }
55
+ if (detail.background === 'transparent' && !detail.borderWidth) {
56
+ return false;
57
+ }
58
+ }
59
+ if (['group'].includes(elem.type)) {
60
+ const detail = elem.detail || {};
61
+ const { children } = detail;
62
+ if (!(children.length > 0) && !detail.background && !detail.borderWidth) {
63
+ return false;
64
+ }
65
+ if (!(children.length > 0) && detail.background === 'transparent' && !detail.borderWidth) {
66
+ return false;
67
+ }
68
+ }
69
+ if (elem.type === 'text') {
70
+ if (!elem.detail.text) {
71
+ return false;
72
+ }
73
+ }
74
+ if (elem.type === 'image') {
75
+ if (!elem.detail.src) {
76
+ return false;
77
+ }
78
+ }
79
+ if (elem.type === 'html') {
80
+ if (!elem.detail.html) {
81
+ return false;
82
+ }
83
+ }
84
+ if (elem.type === 'svg') {
85
+ if (!elem.detail.svg) {
86
+ return false;
87
+ }
88
+ }
89
+ if (elem.type === 'path') {
90
+ const detail = elem.detail;
91
+ if (!(((_a = detail === null || detail === void 0 ? void 0 : detail.commands) === null || _a === void 0 ? void 0 : _a.length) > 0)) {
92
+ return false;
93
+ }
94
+ }
95
+ return true;
96
+ }
97
+ export function flatElementList(list) {
98
+ const elemeList = [];
99
+ const currentGroupQueue = [];
100
+ const _resetElemSize = (elem) => {
101
+ if (!isValidElement(elem)) {
102
+ return;
103
+ }
104
+ const newSize = flatElementSize(elem, { groupQueue: currentGroupQueue });
105
+ const resizeElem = Object.assign(Object.assign({}, elem), newSize);
106
+ elemeList.push(resizeElem);
107
+ };
108
+ const _walk = (elem) => {
109
+ var _a;
110
+ if (((_a = elem === null || elem === void 0 ? void 0 : elem.operations) === null || _a === void 0 ? void 0 : _a.invisible) === true) {
111
+ return;
112
+ }
113
+ if (elem.type === 'group') {
114
+ const { detail } = elem;
115
+ const { children } = detail, restDetail = __rest(detail, ["children"]);
116
+ _resetElemSize(Object.assign(Object.assign({}, elem), { detail: Object.assign(Object.assign({}, restDetail), { children: [] }) }));
117
+ currentGroupQueue.push(elem);
118
+ children.forEach((child) => {
119
+ _walk(child);
120
+ });
121
+ currentGroupQueue.pop();
122
+ }
123
+ else {
124
+ _resetElemSize(elem);
125
+ }
126
+ };
127
+ for (let i = 0; i < list.length; i++) {
128
+ const elem = list[i];
129
+ _walk(elem);
130
+ }
131
+ return elemeList;
132
+ }
@@ -0,0 +1,3 @@
1
+ import type { Elements, ElementPosition } from '@idraw/types';
2
+ export declare function groupElementsByPosition(list: Elements, positions: ElementPosition[]): Elements;
3
+ export declare function ungroupElementsByPosition(list: Elements, position: ElementPosition): Elements;
@@ -0,0 +1,81 @@
1
+ import { findElementFromListByPosition, calcElementListSize } from './element';
2
+ import { deleteElementInListByPosition, insertElementToListByPosition } from './handle-element';
3
+ import { createUUID } from './uuid';
4
+ export function groupElementsByPosition(list, positions) {
5
+ if (positions.length > 1) {
6
+ let isValidPositions = true;
7
+ let lastIndexs = [];
8
+ for (let i = 1; i < positions.length; i++) {
9
+ const prevPosition = positions[i - 1];
10
+ const position = positions[i];
11
+ if (!(prevPosition.length > 0 && position.length > 0)) {
12
+ isValidPositions = false;
13
+ break;
14
+ }
15
+ if (prevPosition.length !== position.length) {
16
+ isValidPositions = false;
17
+ break;
18
+ }
19
+ const temp1 = [...prevPosition];
20
+ const temp2 = [...position];
21
+ const lastIndex1 = temp1.pop();
22
+ const lastIndex2 = temp2.pop();
23
+ if (i === 1 && typeof lastIndex1 === 'number' && lastIndex1 >= 0) {
24
+ lastIndexs.push(lastIndex1);
25
+ }
26
+ if (typeof lastIndex2 === 'number' && lastIndex2 >= 0) {
27
+ lastIndexs.push(lastIndex2);
28
+ }
29
+ }
30
+ if (isValidPositions !== true) {
31
+ console.error('[idraw]: The grouped elements are not siblings!');
32
+ return list;
33
+ }
34
+ lastIndexs.sort((a, b) => a - b);
35
+ const groupParentPosition = [...positions[0]].splice(0, positions[0].length - 1);
36
+ const groupChildren = [];
37
+ const groupPosition = [...groupParentPosition, lastIndexs[0]];
38
+ for (let i = 0; i < lastIndexs.length; i++) {
39
+ const position = [...groupParentPosition, lastIndexs[i]];
40
+ const elem = findElementFromListByPosition(position, list);
41
+ if (elem) {
42
+ groupChildren.push(elem);
43
+ }
44
+ }
45
+ const groupSize = calcElementListSize(groupChildren);
46
+ for (let i = 0; i < groupChildren.length; i++) {
47
+ const elem = groupChildren[i];
48
+ if (elem) {
49
+ elem.x -= groupSize.x;
50
+ elem.y -= groupSize.y;
51
+ }
52
+ }
53
+ for (let i = lastIndexs.length - 1; i >= 0; i--) {
54
+ const position = [...groupParentPosition, lastIndexs[i]];
55
+ deleteElementInListByPosition(position, list);
56
+ }
57
+ const group = Object.assign(Object.assign({ name: 'Group', uuid: createUUID(), type: 'group' }, groupSize), { detail: {
58
+ children: groupChildren
59
+ } });
60
+ insertElementToListByPosition(group, groupPosition, list);
61
+ }
62
+ return list;
63
+ }
64
+ export function ungroupElementsByPosition(list, position) {
65
+ var _a;
66
+ const elem = findElementFromListByPosition(position, list);
67
+ if (!(elem && (elem === null || elem === void 0 ? void 0 : elem.type) === 'group' && Array.isArray((_a = elem === null || elem === void 0 ? void 0 : elem.detail) === null || _a === void 0 ? void 0 : _a.children))) {
68
+ console.error('[idraw]: The ungrouped element is not a group element!');
69
+ }
70
+ const groupParentPosition = [...position].splice(0, position.length - 1);
71
+ const groupLastIndex = position[position.length - 1];
72
+ const { x, y } = elem;
73
+ deleteElementInListByPosition(position, list);
74
+ elem.detail.children.forEach((child, i) => {
75
+ child.x += x;
76
+ child.y += y;
77
+ const elemPosition = [...groupParentPosition, groupLastIndex + i];
78
+ insertElementToListByPosition(child, elemPosition, list);
79
+ });
80
+ return list;
81
+ }
@@ -10,5 +10,10 @@ export declare function deleteElementInList(uuid: string, list: Element[]): bool
10
10
  export declare function moveElementPosition(elements: Elements, opts: {
11
11
  from: ElementPosition;
12
12
  to: ElementPosition;
13
- }): Elements;
13
+ }): {
14
+ elements: Elements;
15
+ from: ElementPosition;
16
+ to: ElementPosition;
17
+ };
14
18
  export declare function updateElementInList(uuid: string, updateContent: RecursivePartial<Element<ElementType>>, elements: Element[]): Element | null;
19
+ export declare function updateElementInListByPosition(position: ElementPosition, updateContent: RecursivePartial<Element<ElementType>>, elements: Element[]): Element | null;
@@ -1,10 +1,10 @@
1
1
  import { createUUID } from './uuid';
2
- import { getDefaultElementDetailConfig, getDefaultElementRectDetail, getDefaultElementCircleDetail, getDefaultElementTextDetail, getDefaultElementSVGDetail, getDefaultElementImageDetail, getDefaultElementGroupDetail } from './config';
2
+ import { defaultText, getDefaultElementRectDetail, getDefaultElementCircleDetail, getDefaultElementTextDetail, getDefaultElementSVGDetail, getDefaultElementImageDetail, getDefaultElementGroupDetail } from './config';
3
3
  import { istype } from './istype';
4
4
  import { findElementFromListByPosition, getElementPositionFromList } from './element';
5
+ import { deepResizeGroupElement } from './resize-element';
5
6
  const defaultViewWidth = 200;
6
7
  const defaultViewHeight = 200;
7
- const defaultDetail = getDefaultElementDetailConfig();
8
8
  function createElementSize(type, opts) {
9
9
  let x = 0;
10
10
  let y = 0;
@@ -14,29 +14,26 @@ function createElementSize(type, opts) {
14
14
  const { viewScaleInfo, viewSizeInfo } = opts;
15
15
  const { scale, offsetLeft, offsetTop } = viewScaleInfo;
16
16
  const { width, height } = viewSizeInfo;
17
- if (type === 'text') {
18
- const textDetail = getDefaultElementTextDetail();
19
- w = defaultDetail.fontSize * scale * textDetail.text.length;
20
- h = defaultDetail.fontSize * scale * 2;
17
+ const limitViewWidth = width / 4;
18
+ const limitViewHeight = height / 4;
19
+ if (defaultViewWidth >= limitViewWidth) {
20
+ w = limitViewWidth / scale;
21
21
  }
22
22
  else {
23
- const limitViewWidth = width / 4;
24
- const limitViewHeight = height / 4;
25
- if (defaultViewWidth >= limitViewWidth) {
26
- w = limitViewWidth / scale;
27
- }
28
- else {
29
- w = defaultViewWidth / scale;
30
- }
31
- if (defaultViewHeight >= limitViewHeight) {
32
- h = limitViewHeight / scale;
33
- }
34
- else {
35
- h = defaultViewHeight / scale;
36
- }
37
- if (['circle', 'svg', 'image'].includes(type)) {
38
- w = h = Math.max(w, h);
39
- }
23
+ w = defaultViewWidth / scale;
24
+ }
25
+ if (defaultViewHeight >= limitViewHeight) {
26
+ h = limitViewHeight / scale;
27
+ }
28
+ else {
29
+ h = defaultViewHeight / scale;
30
+ }
31
+ if (['circle', 'svg', 'image'].includes(type)) {
32
+ w = h = Math.max(w, h);
33
+ }
34
+ else if (type === 'text') {
35
+ const fontSize = w / defaultText.length;
36
+ h = fontSize * 2;
40
37
  }
41
38
  x = (0 - offsetLeft + width / 2 - (w * scale) / 2) / scale;
42
39
  y = (0 - offsetTop + height / 2 - (h * scale) / 2) / scale;
@@ -50,18 +47,16 @@ function createElementSize(type, opts) {
50
47
  return elemSize;
51
48
  }
52
49
  export function createElement(type, baseElem, opts) {
53
- const elemSize = createElementSize(type, opts);
50
+ const elementSize = createElementSize(type, opts);
54
51
  let detail = {};
55
52
  if (type === 'rect') {
56
53
  detail = getDefaultElementRectDetail();
57
54
  }
58
55
  else if (type === 'circle') {
59
- detail = getDefaultElementCircleDetail({
60
- radius: elemSize.w
61
- });
56
+ detail = getDefaultElementCircleDetail();
62
57
  }
63
58
  else if (type === 'text') {
64
- detail = getDefaultElementTextDetail(opts);
59
+ detail = getDefaultElementTextDetail(elementSize);
65
60
  }
66
61
  else if (type === 'svg') {
67
62
  detail = getDefaultElementSVGDetail();
@@ -72,7 +67,7 @@ export function createElement(type, baseElem, opts) {
72
67
  else if (type === 'group') {
73
68
  detail = getDefaultElementGroupDetail();
74
69
  }
75
- const elem = Object.assign(Object.assign(Object.assign({}, elemSize), baseElem), { uuid: createUUID(), type, detail: Object.assign(Object.assign({}, detail), (baseElem.detail || {})) });
70
+ const elem = Object.assign(Object.assign(Object.assign({}, elementSize), baseElem), { uuid: createUUID(), type, detail: Object.assign(Object.assign({}, detail), (baseElem.detail || {})) });
76
71
  return elem;
77
72
  }
78
73
  export function insertElementToListByPosition(element, position, list) {
@@ -134,15 +129,16 @@ export function deleteElementInList(uuid, list) {
134
129
  return deleteElementInListByPosition(position, list);
135
130
  }
136
131
  export function moveElementPosition(elements, opts) {
137
- const { from, to } = opts;
132
+ const from = [...opts.from];
133
+ const to = [...opts.to];
138
134
  if (from.length === 0 || to.length === 0) {
139
- return elements;
135
+ return { elements, from, to };
140
136
  }
141
137
  if (from.length <= to.length) {
142
138
  for (let i = 0; i < from.length; i++) {
143
139
  if (to[i] === from[i]) {
144
140
  if (i === from.length - 1) {
145
- return elements;
141
+ return { elements, from, to };
146
142
  }
147
143
  continue;
148
144
  }
@@ -152,19 +148,64 @@ export function moveElementPosition(elements, opts) {
152
148
  if (target) {
153
149
  const insterResult = insertElementToListByPosition(target, to, elements);
154
150
  if (!insterResult) {
155
- return elements;
151
+ return { elements, from, to };
156
152
  }
157
153
  let trimDeletePosIndex = -1;
158
154
  const trimDeletePosAction = 'down';
159
- for (let i = 0; i < from.length; i++) {
160
- if (!(to[i] >= 0)) {
161
- break;
155
+ let isEffectToIndex = false;
156
+ if (from.length >= 1 && to.length >= 1) {
157
+ if (from.length <= to.length) {
158
+ if (from.length === 1) {
159
+ if (from[0] < to[0]) {
160
+ isEffectToIndex = true;
161
+ }
162
+ }
163
+ else {
164
+ for (let i = 0; i < from.length; i++) {
165
+ if (from[i] === to[i]) {
166
+ if (from.length === from.length - 1) {
167
+ isEffectToIndex = true;
168
+ break;
169
+ }
170
+ }
171
+ else {
172
+ break;
173
+ }
174
+ }
175
+ }
162
176
  }
163
- if (to[i] === from[i]) {
164
- continue;
177
+ if (from.length >= to.length) {
178
+ if (to.length === 1) {
179
+ if (to[0] < from[0]) {
180
+ isEffectToIndex = true;
181
+ }
182
+ }
183
+ else {
184
+ for (let i = 0; i < to.length; i++) {
185
+ if (i === to.length - 1 && to[i] < from[i]) {
186
+ isEffectToIndex = true;
187
+ }
188
+ if (from[i] === to[i]) {
189
+ continue;
190
+ }
191
+ else {
192
+ break;
193
+ }
194
+ }
195
+ }
165
196
  }
166
- if (to[i] < from[i] && i == to.length - 1) {
167
- trimDeletePosIndex = i;
197
+ }
198
+ if (isEffectToIndex === true) {
199
+ for (let i = 0; i < from.length; i++) {
200
+ if (!(to[i] >= 0)) {
201
+ break;
202
+ }
203
+ if (to[i] === from[i]) {
204
+ continue;
205
+ }
206
+ if (to[i] < from[i] && i == to.length - 1) {
207
+ trimDeletePosIndex = i;
208
+ }
168
209
  }
169
210
  }
170
211
  if (trimDeletePosIndex >= 0) {
@@ -174,7 +215,7 @@ export function moveElementPosition(elements, opts) {
174
215
  }
175
216
  deleteElementInListByPosition(from, elements);
176
217
  }
177
- return elements;
218
+ return { elements, from, to };
178
219
  }
179
220
  function mergeElement(originElem, updateContent) {
180
221
  var _a;
@@ -209,18 +250,42 @@ function mergeElement(originElem, updateContent) {
209
250
  return originElem;
210
251
  }
211
252
  export function updateElementInList(uuid, updateContent, elements) {
212
- var _a;
253
+ var _a, _b;
213
254
  let targetElement = null;
214
255
  for (let i = 0; i < elements.length; i++) {
215
256
  const elem = elements[i];
216
257
  if (elem.uuid === uuid) {
258
+ if (elem.type === 'group' && ((_a = elem.operations) === null || _a === void 0 ? void 0 : _a.deepResize) === true) {
259
+ if ((updateContent.w && updateContent.w > 0) || (updateContent.h && updateContent.h > 0)) {
260
+ deepResizeGroupElement(elem, {
261
+ w: updateContent.w,
262
+ h: updateContent.h
263
+ });
264
+ }
265
+ }
217
266
  mergeElement(elem, updateContent);
218
267
  targetElement = elem;
219
268
  break;
220
269
  }
221
270
  else if (elem.type === 'group') {
222
- targetElement = updateElementInList(uuid, updateContent, ((_a = elem === null || elem === void 0 ? void 0 : elem.detail) === null || _a === void 0 ? void 0 : _a.children) || []);
271
+ targetElement = updateElementInList(uuid, updateContent, ((_b = elem === null || elem === void 0 ? void 0 : elem.detail) === null || _b === void 0 ? void 0 : _b.children) || []);
223
272
  }
224
273
  }
225
274
  return targetElement;
226
275
  }
276
+ export function updateElementInListByPosition(position, updateContent, elements) {
277
+ var _a;
278
+ const elem = findElementFromListByPosition(position, elements);
279
+ if (elem) {
280
+ if (elem.type === 'group' && ((_a = elem.operations) === null || _a === void 0 ? void 0 : _a.deepResize) === true) {
281
+ if ((updateContent.w && updateContent.w > 0) || (updateContent.h && updateContent.h > 0)) {
282
+ deepResizeGroupElement(elem, {
283
+ w: updateContent.w,
284
+ h: updateContent.h
285
+ });
286
+ }
287
+ }
288
+ mergeElement(elem, updateContent);
289
+ }
290
+ return elem;
291
+ }
@@ -1,3 +1,3 @@
1
1
  import { HTMLNode } from '@idraw/types';
2
2
  export declare function parseHTML(html: string): HTMLNode[];
3
- export declare function generateHTML(htmlNodes: HTMLNode[]): HTMLNode;
3
+ export declare function generateHTML(htmlNodes: HTMLNode[]): string;
@@ -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;
@@ -12,7 +13,7 @@ declare function imageBase64(value: any): boolean;
12
13
  declare function imageSrc(value: any): boolean;
13
14
  declare function svg(value: any): boolean;
14
15
  declare function html(value: any): boolean;
15
- declare function text(value: any): boolean;
16
+ declare function text(value: any): value is string;
16
17
  declare function fontSize(value: any): boolean;
17
18
  declare function lineHeight(value: any): boolean;
18
19
  declare function strokeWidth(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;
@@ -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 typeof value === 'number' && value >= 0;
15
+ return positiveNum(value);
13
16
  }
14
17
  function h(value) {
15
- return typeof value === 'number' && value >= 0;
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 w(value);
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 number(value) && value >= 0;
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' && /^(<svg[\s]{1,}|<svg>)/i.test(`${value}`.trim()) && /<\/[\s]{0,}svg>$/i.test(`${value}`.trim());
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,
@@ -4,6 +4,7 @@ export declare const istype: {
4
4
  json(data: any): boolean;
5
5
  function(data: any): boolean;
6
6
  asyncFunction(data: any): boolean;
7
+ boolean(data: any): boolean;
7
8
  string(data: any): boolean;
8
9
  number(data: any): boolean;
9
10
  undefined(data: any): boolean;
@@ -20,6 +20,9 @@ export const istype = {
20
20
  asyncFunction(data) {
21
21
  return parsePrototype(data) === 'AsyncFunction';
22
22
  },
23
+ boolean(data) {
24
+ return parsePrototype(data) === 'Boolean';
25
+ },
23
26
  string(data) {
24
27
  return parsePrototype(data) === 'String';
25
28
  },
@@ -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,15 @@
1
+ import type { Data, ModifyType, ModifyOptions, ModifyRecord } from '@idraw/types';
2
+ export interface ModifyRecorderOptions {
3
+ recordable: boolean;
4
+ }
5
+ export declare class ModifyRecorder {
6
+ #private;
7
+ constructor(opts: ModifyRecorderOptions);
8
+ $getDoStack(): ModifyRecord[];
9
+ $getUndoStack(): ModifyRecord[];
10
+ clear(): void;
11
+ destroy(): void;
12
+ do<T extends ModifyType>(data: Data, opts: ModifyOptions<T>): Data;
13
+ undo(data: Data): Data | null;
14
+ redo(data: Data): Data | null;
15
+ }