@idraw/util 0.4.2 → 1.0.0-alpha.1

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 (96) hide show
  1. package/dist/esm/converter/data-svg.d.ts +2 -0
  2. package/dist/esm/converter/data-svg.js +19 -0
  3. package/dist/esm/converter/material-svg.d.ts +2 -0
  4. package/dist/esm/converter/material-svg.js +63 -0
  5. package/dist/esm/converter/svg-material.d.ts +2 -0
  6. package/dist/esm/converter/svg-material.js +188 -0
  7. package/dist/esm/index.d.ts +32 -21
  8. package/dist/esm/index.js +32 -21
  9. package/dist/esm/static.d.ts +1 -0
  10. package/dist/esm/static.js +1 -0
  11. package/dist/esm/tool/file.js +2 -2
  12. package/dist/esm/tool/html.js +27 -27
  13. package/dist/esm/tool/id.d.ts +1 -0
  14. package/dist/esm/tool/id.js +4 -0
  15. package/dist/esm/tool/image.js +6 -6
  16. package/dist/esm/tool/path-to-box.d.ts +3 -0
  17. package/dist/esm/tool/path-to-box.js +353 -0
  18. package/dist/esm/tool/path-to-command.d.ts +4 -0
  19. package/dist/esm/tool/path-to-command.js +392 -0
  20. package/dist/esm/tool/path.d.ts +18 -0
  21. package/dist/esm/tool/path.js +421 -0
  22. package/dist/esm/tool/svg-path.d.ts +3 -0
  23. package/dist/esm/{view → tool}/svg-path.js +4 -16
  24. package/dist/esm/tool/time.d.ts +2 -2
  25. package/dist/esm/tool/time.js +4 -4
  26. package/dist/esm/tool/uuid.d.ts +1 -1
  27. package/dist/esm/tool/uuid.js +6 -6
  28. package/dist/esm/view/box.d.ts +0 -2
  29. package/dist/esm/view/box.js +1 -173
  30. package/dist/esm/view/canvas.js +3 -3
  31. package/dist/esm/view/check.d.ts +8 -7
  32. package/dist/esm/view/check.js +34 -34
  33. package/dist/esm/view/config.d.ts +0 -9
  34. package/dist/esm/view/config.js +1 -71
  35. package/dist/esm/view/context2d.d.ts +10 -3
  36. package/dist/esm/view/context2d.js +39 -18
  37. package/dist/esm/view/controller.d.ts +5 -5
  38. package/dist/esm/view/controller.js +105 -102
  39. package/dist/esm/view/data.d.ts +2 -2
  40. package/dist/esm/view/data.js +65 -65
  41. package/dist/esm/view/dom.d.ts +23 -0
  42. package/dist/esm/view/dom.js +190 -0
  43. package/dist/esm/view/flat.d.ts +2 -2
  44. package/dist/esm/view/flat.js +53 -53
  45. package/dist/esm/view/group.d.ts +3 -3
  46. package/dist/esm/view/group.js +25 -28
  47. package/dist/esm/view/handle-material.d.ts +24 -0
  48. package/dist/esm/view/{handle-element.js → handle-material.js} +98 -75
  49. package/dist/esm/view/is.d.ts +10 -12
  50. package/dist/esm/view/is.js +15 -19
  51. package/dist/esm/view/load.d.ts +2 -2
  52. package/dist/esm/view/load.js +7 -7
  53. package/dist/esm/view/material.d.ts +40 -0
  54. package/dist/esm/view/material.js +476 -0
  55. package/dist/esm/view/middleware.d.ts +1 -0
  56. package/dist/esm/view/middleware.js +14 -2
  57. package/dist/esm/view/modify-record.d.ts +4 -4
  58. package/dist/esm/view/modify-record.js +2 -2
  59. package/dist/esm/view/parser.d.ts +2 -2
  60. package/dist/esm/view/parser.js +3 -3
  61. package/dist/esm/view/path.d.ts +2 -0
  62. package/dist/esm/view/path.js +30 -0
  63. package/dist/esm/view/point-move-material.d.ts +5 -0
  64. package/dist/esm/view/{point-move-element.js → point-move-material.js} +6 -6
  65. package/dist/esm/view/point.d.ts +3 -8
  66. package/dist/esm/view/point.js +1 -21
  67. package/dist/esm/view/position.d.ts +9 -9
  68. package/dist/esm/view/position.js +1 -1
  69. package/dist/esm/view/rect.d.ts +2 -2
  70. package/dist/esm/view/rect.js +4 -4
  71. package/dist/esm/view/resize-material.d.ts +4 -0
  72. package/dist/esm/view/resize-material.js +266 -0
  73. package/dist/esm/view/rotate.d.ts +11 -11
  74. package/dist/esm/view/rotate.js +24 -24
  75. package/dist/esm/view/static.d.ts +13 -0
  76. package/dist/esm/view/static.js +89 -0
  77. package/dist/esm/view/styles.d.ts +11 -0
  78. package/dist/esm/view/styles.js +78 -0
  79. package/dist/esm/view/vertex.d.ts +8 -8
  80. package/dist/esm/view/vertex.js +28 -28
  81. package/dist/esm/view/view-box.d.ts +2 -6
  82. package/dist/esm/view/view-box.js +8 -64
  83. package/dist/esm/view/view-calc.d.ts +23 -20
  84. package/dist/esm/view/view-calc.js +104 -93
  85. package/dist/esm/view/view-content.d.ts +2 -2
  86. package/dist/esm/view/view-content.js +34 -34
  87. package/dist/index.global.js +3144 -1548
  88. package/dist/index.global.min.js +1 -1
  89. package/package.json +1 -1
  90. package/dist/esm/view/element.d.ts +0 -35
  91. package/dist/esm/view/element.js +0 -471
  92. package/dist/esm/view/handle-element.d.ts +0 -24
  93. package/dist/esm/view/point-move-element.d.ts +0 -5
  94. package/dist/esm/view/resize-element.d.ts +0 -4
  95. package/dist/esm/view/resize-element.js +0 -255
  96. package/dist/esm/view/svg-path.d.ts +0 -10
@@ -0,0 +1,421 @@
1
+ import { createId } from './id';
2
+ export function shiftPathCommand(command, x, y) {
3
+ const { type } = command;
4
+ const params = [...command.params];
5
+ const id = command.id;
6
+ let anchorInfo = { id };
7
+ if (command.start && command.end) {
8
+ const start = Object.assign({}, command.start);
9
+ const end = Object.assign({}, command.end);
10
+ start.x += x;
11
+ start.y += y;
12
+ end.x += x;
13
+ end.y += y;
14
+ anchorInfo = { id, start, end };
15
+ }
16
+ switch (type) {
17
+ case 'M': {
18
+ params[0] += x;
19
+ params[1] += y;
20
+ return Object.assign({ type, params }, anchorInfo);
21
+ }
22
+ case 'L': {
23
+ params[0] += x;
24
+ params[1] += y;
25
+ return Object.assign({ type, params }, anchorInfo);
26
+ }
27
+ case 'H': {
28
+ params[0] += x;
29
+ return Object.assign({ type, params }, anchorInfo);
30
+ }
31
+ case 'V': {
32
+ params[0] += y;
33
+ return Object.assign({ type, params }, anchorInfo);
34
+ }
35
+ case 'C': {
36
+ params[0] += x;
37
+ params[1] += y;
38
+ params[2] += x;
39
+ params[3] += y;
40
+ params[4] += x;
41
+ params[5] += y;
42
+ return Object.assign({ type, params }, anchorInfo);
43
+ }
44
+ case 'S': {
45
+ params[0] += x;
46
+ params[1] += y;
47
+ params[2] += x;
48
+ params[3] += y;
49
+ return Object.assign({ type, params }, anchorInfo);
50
+ }
51
+ case 'Q': {
52
+ params[0] += x;
53
+ params[1] += y;
54
+ params[2] += x;
55
+ params[3] += y;
56
+ return Object.assign({ type, params }, anchorInfo);
57
+ }
58
+ case 'T': {
59
+ params[0] += x;
60
+ params[1] += y;
61
+ return Object.assign({ type, params }, anchorInfo);
62
+ }
63
+ case 'A': {
64
+ params[5] += x;
65
+ params[6] += y;
66
+ return Object.assign({ type, params }, anchorInfo);
67
+ }
68
+ case 'Z': {
69
+ return Object.assign({ type, params }, anchorInfo);
70
+ }
71
+ default: {
72
+ return Object.assign({ type, params }, anchorInfo);
73
+ }
74
+ }
75
+ }
76
+ export function shiftPathCommands(commands, x, y) {
77
+ const cmds = [];
78
+ commands.forEach((command) => {
79
+ const cmd = shiftPathCommand(command, x, y);
80
+ cmds.push(cmd);
81
+ });
82
+ return cmds;
83
+ }
84
+ export function scalePathCommands(path, scaleX, scaleY) {
85
+ return path.map((cmd) => {
86
+ const { id, type, params } = cmd;
87
+ const newParams = [];
88
+ let anchorInfo = { id };
89
+ if (cmd.start && cmd.end) {
90
+ const start = Object.assign({}, cmd.start);
91
+ const end = Object.assign({}, cmd.end);
92
+ start.x *= scaleX;
93
+ start.y *= scaleY;
94
+ end.x *= scaleX;
95
+ end.y *= scaleY;
96
+ anchorInfo = { id, start, end };
97
+ }
98
+ switch (type.toUpperCase()) {
99
+ case 'M':
100
+ case 'L':
101
+ case 'T':
102
+ for (let i = 0; i < params.length; i += 2) {
103
+ newParams.push(params[i] * scaleX, params[i + 1] * scaleY);
104
+ }
105
+ break;
106
+ case 'C':
107
+ for (let i = 0; i < params.length; i += 6) {
108
+ newParams.push(params[i] * scaleX, params[i + 1] * scaleY, params[i + 2] * scaleX, params[i + 3] * scaleY, params[i + 4] * scaleX, params[i + 5] * scaleY);
109
+ }
110
+ break;
111
+ case 'S':
112
+ for (let i = 0; i < params.length; i += 4) {
113
+ newParams.push(params[i] * scaleX, params[i + 1] * scaleY, params[i + 2] * scaleX, params[i + 3] * scaleY);
114
+ }
115
+ break;
116
+ case 'Q':
117
+ for (let i = 0; i < params.length; i += 4) {
118
+ newParams.push(params[i] * scaleX, params[i + 1] * scaleY, params[i + 2] * scaleX, params[i + 3] * scaleY);
119
+ }
120
+ break;
121
+ case 'H':
122
+ params.forEach((val) => newParams.push(val * scaleX));
123
+ break;
124
+ case 'V':
125
+ params.forEach((val) => newParams.push(val * scaleY));
126
+ break;
127
+ case 'A':
128
+ for (let i = 0; i < params.length; i += 7) {
129
+ newParams.push(params[i] * scaleX, params[i + 1] * scaleY, params[i + 2], params[i + 3], params[i + 4], params[i + 5] * scaleX, params[i + 6] * scaleY);
130
+ }
131
+ break;
132
+ case 'M':
133
+ case 'L':
134
+ case 'C':
135
+ case 'S':
136
+ case 'Q':
137
+ case 'T':
138
+ case 'A':
139
+ case 'H':
140
+ case 'V':
141
+ for (let i = 0; i < params.length; i++) {
142
+ const isXParam = (type === 'a' && (i % 7 === 0 || i % 7 === 5)) ||
143
+ type === 'h' ||
144
+ (type !== 'v' && i % 2 === 0);
145
+ newParams.push(params[i] * (isXParam ? scaleX : scaleY));
146
+ }
147
+ break;
148
+ default:
149
+ return Object.assign({ type, params: [...params] }, anchorInfo);
150
+ }
151
+ return Object.assign({ type, params: newParams }, anchorInfo);
152
+ });
153
+ }
154
+ export function convertPathCommandsToACLMZ(commands) {
155
+ const output = [];
156
+ let currentPoint = { x: 0, y: 0 };
157
+ let startPoint = { x: 0, y: 0 };
158
+ let prevControlPoint = null;
159
+ for (const command of commands) {
160
+ const type = command.type;
161
+ const params = command.params;
162
+ const isRelative = type === type.toLowerCase();
163
+ const absCommand = type.toUpperCase();
164
+ const id = command.id;
165
+ switch (absCommand) {
166
+ case 'M': {
167
+ const [x, y] = params;
168
+ const point = isRelative ? { x: currentPoint.x + x, y: currentPoint.y + y } : { x, y };
169
+ output.push({ id, type: 'M', params: [point.x, point.y], start: { x, y }, end: { x, y } });
170
+ currentPoint = point;
171
+ startPoint = point;
172
+ prevControlPoint = null;
173
+ break;
174
+ }
175
+ case 'L': {
176
+ const [x, y] = params;
177
+ const point = isRelative ? { x: currentPoint.x + x, y: currentPoint.y + y } : { x, y };
178
+ output.push({
179
+ id,
180
+ type: 'L',
181
+ params: [point.x, point.y],
182
+ start: Object.assign({}, currentPoint),
183
+ end: Object.assign({}, point),
184
+ });
185
+ currentPoint = point;
186
+ prevControlPoint = null;
187
+ break;
188
+ }
189
+ case 'H': {
190
+ const [x] = params;
191
+ const point = isRelative ? { x: currentPoint.x + x, y: currentPoint.y } : { x, y: currentPoint.y };
192
+ output.push({
193
+ id,
194
+ type: 'L',
195
+ params: [point.x, point.y],
196
+ start: Object.assign({}, currentPoint),
197
+ end: Object.assign({}, point),
198
+ });
199
+ currentPoint = point;
200
+ prevControlPoint = null;
201
+ break;
202
+ }
203
+ case 'V': {
204
+ const [y] = params;
205
+ const point = isRelative ? { x: currentPoint.x, y: currentPoint.y + y } : { x: currentPoint.x, y };
206
+ output.push({
207
+ id,
208
+ type: 'L',
209
+ params: [point.x, point.y],
210
+ start: Object.assign({}, currentPoint),
211
+ end: Object.assign({}, point),
212
+ });
213
+ currentPoint = point;
214
+ prevControlPoint = null;
215
+ break;
216
+ }
217
+ case 'C': {
218
+ const [x1, y1, x2, y2, x, y] = params;
219
+ const c1 = isRelative ? { x: currentPoint.x + x1, y: currentPoint.y + y1 } : { x: x1, y: y1 };
220
+ const c2 = isRelative ? { x: currentPoint.x + x2, y: currentPoint.y + y2 } : { x: x2, y: y2 };
221
+ const point = isRelative ? { x: currentPoint.x + x, y: currentPoint.y + y } : { x, y };
222
+ output.push({
223
+ id,
224
+ type: 'C',
225
+ params: [c1.x, c1.y, c2.x, c2.y, point.x, point.y],
226
+ start: Object.assign({}, currentPoint),
227
+ end: Object.assign({}, point),
228
+ });
229
+ currentPoint = point;
230
+ prevControlPoint = c2;
231
+ break;
232
+ }
233
+ case 'S': {
234
+ const [x2, y2, x, y] = params;
235
+ const c1 = prevControlPoint
236
+ ? {
237
+ x: 2 * currentPoint.x - prevControlPoint.x,
238
+ y: 2 * currentPoint.y - prevControlPoint.y,
239
+ }
240
+ : currentPoint;
241
+ const c2 = isRelative ? { x: currentPoint.x + x2, y: currentPoint.y + y2 } : { x: x2, y: y2 };
242
+ const point = isRelative ? { x: currentPoint.x + x, y: currentPoint.y + y } : { x, y };
243
+ output.push({
244
+ id,
245
+ type: 'C',
246
+ params: [c1.x, c1.y, c2.x, c2.y, point.x, point.y],
247
+ start: Object.assign({}, currentPoint),
248
+ end: Object.assign({}, point),
249
+ });
250
+ currentPoint = point;
251
+ prevControlPoint = c2;
252
+ break;
253
+ }
254
+ case 'Q': {
255
+ const [x1, y1, x, y] = params;
256
+ const cp1 = isRelative ? { x: currentPoint.x + x1, y: currentPoint.y + y1 } : { x: x1, y: y1 };
257
+ const endPoint = isRelative ? { x: currentPoint.x + x, y: currentPoint.y + y } : { x, y };
258
+ output.push({
259
+ id,
260
+ type: 'C',
261
+ params: [
262
+ currentPoint.x + (2 / 3) * (cp1.x - currentPoint.x),
263
+ currentPoint.y + (2 / 3) * (cp1.y - currentPoint.y),
264
+ endPoint.x + (2 / 3) * (cp1.x - endPoint.x),
265
+ endPoint.y + (2 / 3) * (cp1.y - endPoint.y),
266
+ endPoint.x,
267
+ endPoint.y,
268
+ ],
269
+ start: Object.assign({}, currentPoint),
270
+ end: Object.assign({}, endPoint),
271
+ });
272
+ currentPoint = endPoint;
273
+ prevControlPoint = cp1;
274
+ break;
275
+ }
276
+ case 'T': {
277
+ const [x, y] = params;
278
+ const endPoint = isRelative ? { x: currentPoint.x + x, y: currentPoint.y + y } : { x, y };
279
+ const cp1 = prevControlPoint
280
+ ? {
281
+ x: 2 * currentPoint.x - prevControlPoint.x,
282
+ y: 2 * currentPoint.y - prevControlPoint.y,
283
+ }
284
+ : currentPoint;
285
+ output.push({
286
+ id,
287
+ type: 'C',
288
+ params: [
289
+ currentPoint.x + (2 / 3) * (cp1.x - currentPoint.x),
290
+ currentPoint.y + (2 / 3) * (cp1.y - currentPoint.y),
291
+ endPoint.x + (2 / 3) * (cp1.x - endPoint.x),
292
+ endPoint.y + (2 / 3) * (cp1.y - endPoint.y),
293
+ endPoint.x,
294
+ endPoint.y,
295
+ ],
296
+ start: Object.assign({}, currentPoint),
297
+ end: Object.assign({}, endPoint),
298
+ });
299
+ currentPoint = endPoint;
300
+ prevControlPoint = cp1;
301
+ break;
302
+ }
303
+ case 'A': {
304
+ const [rx, ry, rotation, largeArc, sweep, x, y] = params;
305
+ const point = isRelative ? { x: currentPoint.x + x, y: currentPoint.y + y } : { x, y };
306
+ output.push({
307
+ id,
308
+ type: 'A',
309
+ params: [rx, ry, rotation, largeArc, sweep, point.x, point.y],
310
+ start: Object.assign({}, currentPoint),
311
+ end: Object.assign({}, point),
312
+ });
313
+ currentPoint = point;
314
+ prevControlPoint = null;
315
+ break;
316
+ }
317
+ case 'Z': {
318
+ output.push({ id, type: 'Z', params: [], start: Object.assign({}, currentPoint), end: Object.assign({}, startPoint) });
319
+ currentPoint = startPoint;
320
+ prevControlPoint = null;
321
+ break;
322
+ }
323
+ default:
324
+ throw new Error(`Unsupported command: ${type}`);
325
+ }
326
+ }
327
+ return output;
328
+ }
329
+ export function moveInAnchorCommands(acmds, opts) {
330
+ const cmds = [];
331
+ const { index, moveX, moveY } = opts;
332
+ acmds.forEach((acmd) => {
333
+ const { id, type, params } = acmd;
334
+ const cmd = { id, type, params: [...params] };
335
+ cmds.push(cmd);
336
+ });
337
+ const cmd = cmds[index];
338
+ const prevCmd = cmds[index - 1];
339
+ if (opts.type === 'start') {
340
+ if (!(prevCmd && cmd)) {
341
+ return convertPathCommandsToACLMZ(cmds);
342
+ }
343
+ if (cmd.type === 'M') {
344
+ cmd.params[0] += moveX;
345
+ cmd.params[1] += moveY;
346
+ }
347
+ if (cmd.type === 'C') {
348
+ cmd.params[0] += moveX;
349
+ cmd.params[1] += moveY;
350
+ }
351
+ switch (prevCmd.type) {
352
+ case 'M': {
353
+ prevCmd.params[0] += moveX;
354
+ prevCmd.params[1] += moveY;
355
+ break;
356
+ }
357
+ case 'L': {
358
+ prevCmd.params[0] += moveX;
359
+ prevCmd.params[1] += moveY;
360
+ break;
361
+ }
362
+ case 'A': {
363
+ prevCmd.params[5] += moveX;
364
+ prevCmd.params[6] += moveY;
365
+ break;
366
+ }
367
+ case 'C': {
368
+ prevCmd.params[2] += moveX;
369
+ prevCmd.params[3] += moveY;
370
+ prevCmd.params[4] += moveX;
371
+ prevCmd.params[5] += moveY;
372
+ break;
373
+ }
374
+ case 'Z': {
375
+ prevCmd.params[0] += moveX;
376
+ prevCmd.params[1] += moveY;
377
+ break;
378
+ }
379
+ default: {
380
+ break;
381
+ }
382
+ }
383
+ }
384
+ else {
385
+ }
386
+ return convertPathCommandsToACLMZ(cmds);
387
+ }
388
+ export function moveCurveCtrlInAnchorCommands(acmds, opts) {
389
+ const cmds = [];
390
+ const { index, type, moveX, moveY } = opts;
391
+ acmds.forEach((acmd) => {
392
+ const { id, type, params } = acmd;
393
+ const cmd = { id, type, params: [...params] };
394
+ cmds.push(cmd);
395
+ });
396
+ const cmd = cmds[index];
397
+ if (cmd.type === 'C') {
398
+ if (type === 'curve-ctrl1') {
399
+ cmd.params[0] += moveX;
400
+ cmd.params[1] += moveY;
401
+ }
402
+ else if (type === 'curve-ctrl2') {
403
+ cmd.params[2] += moveX;
404
+ cmd.params[3] += moveY;
405
+ }
406
+ }
407
+ return convertPathCommandsToACLMZ(cmds);
408
+ }
409
+ export function convertLineToExactCurveCommand(startPoint, endPoint) {
410
+ const endX = endPoint.x;
411
+ const endY = endPoint.y;
412
+ const cp1x = startPoint.x + (endX - startPoint.x) / 3;
413
+ const cp1y = startPoint.y + (endY - startPoint.y) / 3;
414
+ const cp2x = startPoint.x + (2 * (endX - startPoint.x)) / 3;
415
+ const cp2y = startPoint.y + (2 * (endY - startPoint.y)) / 3;
416
+ return {
417
+ id: createId(),
418
+ type: 'C',
419
+ params: [cp1x, cp1y, cp2x, cp2y, endX, endY],
420
+ };
421
+ }
@@ -0,0 +1,3 @@
1
+ import type { PathCommand } from '@idraw/types';
2
+ export declare function parseSVGPath(path: string): PathCommand[];
3
+ export declare function convertPathCommandsToStr(commands: PathCommand[]): string;
@@ -7,30 +7,18 @@ export function parseSVGPath(path) {
7
7
  const params = matchParams ? matchParams.map(Number) : [];
8
8
  const command = {
9
9
  type: cmd,
10
- params
10
+ params,
11
11
  };
12
12
  commands.push(command);
13
13
  return match;
14
14
  });
15
15
  return commands;
16
16
  }
17
- export function generateSVGPath(commands) {
17
+ export function convertPathCommandsToStr(commands) {
18
18
  let path = '';
19
19
  commands.forEach((item) => {
20
- path += item.type + item.params.join(' ');
20
+ var _a, _b;
21
+ path += item.type + ((_b = (_a = item.params) === null || _a === void 0 ? void 0 : _a.join) === null || _b === void 0 ? void 0 : _b.call(_a, ' '));
21
22
  });
22
23
  return path;
23
24
  }
24
- export function filterSVGPath(commands) {
25
- const filteredCommands = [];
26
- const result = {
27
- x: 0,
28
- y: 0,
29
- h: 0,
30
- w: 0,
31
- detail: {
32
- commands: filteredCommands
33
- }
34
- };
35
- return result;
36
- }
@@ -1,6 +1,6 @@
1
1
  type Middleware = (ctx: any, next: Middleware) => any;
2
2
  export declare function compose(middleware: Middleware[]): (context: any, next?: Middleware) => any;
3
3
  export declare function delay(time: number): Promise<void>;
4
- export declare function throttle(fn: (...args: any[]) => any, timeout: number): (...args: any[]) => any;
5
- export declare function debounce(fn: (...args: any[]) => any, timeout: number): (...args: any[]) => any;
4
+ export declare function throttle(fn: (...params: any[]) => any, timeout: number): (...params: any[]) => any;
5
+ export declare function debounce(fn: (...params: any[]) => any, timeout: number): (...params: any[]) => any;
6
6
  export {};
@@ -26,24 +26,24 @@ export function delay(time) {
26
26
  }
27
27
  export function throttle(fn, timeout) {
28
28
  let timer = -1;
29
- return function (...args) {
29
+ return function (...params) {
30
30
  if (timer >= 0) {
31
31
  return;
32
32
  }
33
33
  timer = setTimeout(() => {
34
- fn(...args);
34
+ fn(...params);
35
35
  timer = -1;
36
36
  }, timeout);
37
37
  };
38
38
  }
39
39
  export function debounce(fn, timeout) {
40
40
  let timer = -1;
41
- return function (...args) {
41
+ return function (...params) {
42
42
  if (timer >= 0) {
43
43
  window.clearTimeout(timer);
44
44
  }
45
45
  timer = setTimeout(() => {
46
- fn(...args);
46
+ fn(...params);
47
47
  timer = -1;
48
48
  }, timeout);
49
49
  };
@@ -1,3 +1,3 @@
1
1
  export declare function createUUID(): string;
2
- export declare function createAssetId(assetStr: string, elemUUID: string): string;
2
+ export declare function createAssetId(assetStr: string, mtrlUUID: string): string;
3
3
  export declare function isAssetId(id: any | string): boolean;
@@ -1,8 +1,8 @@
1
+ function createStr(num) {
2
+ return (((1 + Math.random()) * 0x10000) | 0).toString(num || 16).substring(1);
3
+ }
1
4
  export function createUUID() {
2
- function _createStr() {
3
- return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
4
- }
5
- return `${_createStr()}${_createStr()}-${_createStr()}-${_createStr()}-${_createStr()}-${_createStr()}${_createStr()}${_createStr()}`;
5
+ return `${createStr()}${createStr()}-${createStr()}-${createStr()}-${createStr()}-${createStr()}${createStr()}${createStr()}`;
6
6
  }
7
7
  function limitHexStr(str, seed) {
8
8
  let count = 0;
@@ -18,9 +18,9 @@ function sumCharCodes(str) {
18
18
  }
19
19
  return sum;
20
20
  }
21
- export function createAssetId(assetStr, elemUUID) {
21
+ export function createAssetId(assetStr, mtrlUUID) {
22
22
  const len = assetStr.length;
23
- const seed = sumCharCodes(elemUUID);
23
+ const seed = sumCharCodes(mtrlUUID);
24
24
  const mid = Math.floor(len / 2);
25
25
  const start4 = assetStr.substring(0, 4).padStart(4, '0');
26
26
  const end4 = assetStr.substring(0, 4).padStart(4, '0');
@@ -1,2 +0,0 @@
1
- import type { BoxInfo, Element } from '@idraw/types';
2
- export declare function elementToBoxInfo(elem: Element): BoxInfo;