@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
@@ -1,12 +1,12 @@
1
1
  import { createUUID } from '../tool/uuid';
2
- import { defaultText, getDefaultElementRectDetail, getDefaultElementCircleDetail, getDefaultElementTextDetail, getDefaultElementSVGDetail, getDefaultElementImageDetail, getDefaultElementGroupDetail } from './config';
3
- import { toFlattenElement } from './modify-record';
2
+ import { defaultText, getDefaultMaterialRectAttributes, getDefaultMaterialCircleAttributes, getDefaultMaterialTextAttributes, getDefaultMaterialSVGAttributes, getDefaultMaterialImageAttributes, getDefaultMaterialGroupAttributes, } from './static';
3
+ import { toFlattenMaterial } from './modify-record';
4
4
  import { set, del } from '../tool/get-set-del';
5
- import { findElementFromListByPosition, getElementPositionFromList } from './element';
6
- import { resizeEffectGroupElement } from './resize-element';
5
+ import { findMaterialFromListByPosition, getMaterialPositionFromList } from './material';
6
+ import { resizeEffectGroupMaterial } from './resize-material';
7
7
  const defaultViewWidth = 200;
8
8
  const defaultViewHeight = 200;
9
- function createElementSize(type, opts) {
9
+ function createMaterialSize(type, opts) {
10
10
  let x = 0;
11
11
  let y = 0;
12
12
  let w = defaultViewWidth;
@@ -29,7 +29,7 @@ function createElementSize(type, opts) {
29
29
  else {
30
30
  h = defaultViewHeight / scale;
31
31
  }
32
- if (['circle', 'svg', 'image'].includes(type)) {
32
+ if (['circle', 'svgCode', 'image'].includes(type)) {
33
33
  w = h = Math.max(w, h);
34
34
  }
35
35
  else if (type === 'text') {
@@ -39,43 +39,47 @@ function createElementSize(type, opts) {
39
39
  x = (0 - offsetLeft + width / 2 - (w * scale) / 2) / scale;
40
40
  y = (0 - offsetTop + height / 2 - (h * scale) / 2) / scale;
41
41
  }
42
- const elemSize = {
42
+ const mtrlSize = {
43
43
  x,
44
44
  y,
45
- w,
46
- h
45
+ width: w,
46
+ height: h,
47
47
  };
48
- return elemSize;
48
+ return mtrlSize;
49
49
  }
50
- export function createElement(type, baseElem, opts) {
51
- const elementSize = createElementSize(type, opts);
52
- let detail = {};
50
+ export function createMaterial(type, baseMtrl, opts) {
51
+ const materialSize = createMaterialSize(type, opts);
52
+ let attributes = {};
53
53
  if (type === 'rect') {
54
- detail = getDefaultElementRectDetail();
54
+ attributes = getDefaultMaterialRectAttributes();
55
55
  }
56
56
  else if (type === 'circle') {
57
- detail = getDefaultElementCircleDetail();
57
+ attributes = getDefaultMaterialCircleAttributes();
58
58
  }
59
59
  else if (type === 'text') {
60
- detail = getDefaultElementTextDetail(elementSize);
60
+ attributes = getDefaultMaterialTextAttributes(materialSize);
61
61
  }
62
- else if (type === 'svg') {
63
- detail = getDefaultElementSVGDetail();
62
+ else if (type === 'svgCode') {
63
+ attributes = getDefaultMaterialSVGAttributes();
64
64
  }
65
65
  else if (type === 'image') {
66
- detail = getDefaultElementImageDetail();
66
+ attributes = getDefaultMaterialImageAttributes();
67
67
  }
68
68
  else if (type === 'group') {
69
- detail = getDefaultElementGroupDetail();
69
+ attributes = getDefaultMaterialGroupAttributes();
70
+ const groupBase = baseMtrl;
71
+ if (Array.isArray(groupBase.children) && groupBase.children.length > 0) {
72
+ attributes.children = [...groupBase.children];
73
+ }
70
74
  }
71
- const elem = Object.assign(Object.assign(Object.assign({ uuid: createUUID() }, elementSize), baseElem), { type, detail: Object.assign(Object.assign({}, detail), (baseElem.detail || {})) });
72
- return elem;
75
+ const mtrl = Object.assign(Object.assign(Object.assign({ id: createUUID(), type }, materialSize), attributes), baseMtrl);
76
+ return mtrl;
73
77
  }
74
- export function insertElementToListByPosition(element, position, list) {
78
+ export function insertMaterialToListByPosition(material, position, list) {
75
79
  let result = false;
76
80
  if (position.length === 1) {
77
81
  const pos = position[0];
78
- list.splice(pos, 0, element);
82
+ list.splice(pos, 0, material);
79
83
  result = true;
80
84
  }
81
85
  else if (position.length > 1) {
@@ -85,11 +89,11 @@ export function insertElementToListByPosition(element, position, list) {
85
89
  const item = tempList[pos];
86
90
  if (i === position.length - 1) {
87
91
  const pos = position[i];
88
- tempList.splice(pos, 0, element);
92
+ tempList.splice(pos, 0, material);
89
93
  result = true;
90
94
  }
91
95
  else if (i < position.length - 1 && item.type === 'group') {
92
- tempList = item.detail.children;
96
+ tempList = item.children;
93
97
  }
94
98
  else {
95
99
  break;
@@ -98,7 +102,7 @@ export function insertElementToListByPosition(element, position, list) {
98
102
  }
99
103
  return result;
100
104
  }
101
- export function deleteElementInListByPosition(position, list) {
105
+ export function deleteMaterialInListByPosition(position, list) {
102
106
  let result = false;
103
107
  if (position.length === 1) {
104
108
  const pos = position[0];
@@ -116,7 +120,7 @@ export function deleteElementInListByPosition(position, list) {
116
120
  result = true;
117
121
  }
118
122
  else if (i < position.length - 1 && item.type === 'group') {
119
- tempList = item.detail.children;
123
+ tempList = item.children;
120
124
  }
121
125
  else {
122
126
  break;
@@ -125,31 +129,31 @@ export function deleteElementInListByPosition(position, list) {
125
129
  }
126
130
  return result;
127
131
  }
128
- export function deleteElementInList(uuid, list) {
129
- const position = getElementPositionFromList(uuid, list);
130
- return deleteElementInListByPosition(position, list);
132
+ export function deleteMaterialInList(id, list) {
133
+ const position = getMaterialPositionFromList(id, list);
134
+ return deleteMaterialInListByPosition(position, list);
131
135
  }
132
- export function moveElementPosition(elements, opts) {
136
+ export function moveMaterialPosition(materials, opts) {
133
137
  const from = [...opts.from];
134
138
  const to = [...opts.to];
135
139
  if (from.length === 0 || to.length === 0) {
136
- return { elements, from, to };
140
+ return { materials, from, to };
137
141
  }
138
142
  if (from.length <= to.length) {
139
143
  for (let i = 0; i < from.length; i++) {
140
144
  if (to[i] === from[i]) {
141
145
  if (i === from.length - 1) {
142
- return { elements, from, to };
146
+ return { materials, from, to };
143
147
  }
144
148
  continue;
145
149
  }
146
150
  }
147
151
  }
148
- const target = findElementFromListByPosition(from, elements);
152
+ const target = findMaterialFromListByPosition(from, materials);
149
153
  if (target) {
150
- const insterResult = insertElementToListByPosition(target, to, elements);
154
+ const insterResult = insertMaterialToListByPosition(target, to, materials);
151
155
  if (!insterResult) {
152
- return { elements, from, to };
156
+ return { materials, from, to };
153
157
  }
154
158
  let trimDeletePosIndex = -1;
155
159
  const trimDeletePosAction = 'down';
@@ -214,67 +218,86 @@ export function moveElementPosition(elements, opts) {
214
218
  from[trimDeletePosIndex] = from[trimDeletePosIndex] + 1;
215
219
  }
216
220
  }
217
- deleteElementInListByPosition(from, elements);
221
+ deleteMaterialInListByPosition(from, materials);
222
+ }
223
+ return { materials, from, to };
224
+ }
225
+ function clearMaterialColor(color) {
226
+ if (Array.isArray(color === null || color === void 0 ? void 0 : color.stops)) {
227
+ const emptyIndexes = [];
228
+ const stops = color === null || color === void 0 ? void 0 : color.stops;
229
+ for (let i = stops.length - 1; i >= 0; i--) {
230
+ const stop = stops[i];
231
+ if (!(stop.color && stop.offset >= 0)) {
232
+ emptyIndexes.push(i);
233
+ }
234
+ }
235
+ emptyIndexes.forEach((idx) => {
236
+ stops.splice(idx, 1);
237
+ });
218
238
  }
219
- return { elements, from, to };
239
+ return color;
220
240
  }
221
- export function mergeElement(originElem, updateContent, opts) {
222
- const updatedFlatten = toFlattenElement(updateContent);
223
- const ignoreKeys = ['uuid', 'type'];
224
- const updatedKeys = Object.keys(updatedFlatten);
225
- updatedKeys.forEach((key) => {
241
+ export function mergeMaterial(originMtrl, updateContent, opts) {
242
+ const updatedFlatten = toFlattenMaterial(updateContent);
243
+ const ignoreKeys = ['id', 'type'];
244
+ const updatedFlattenKeys = Object.keys(updatedFlatten);
245
+ updatedFlattenKeys.forEach((key) => {
226
246
  if (!ignoreKeys.includes(key)) {
227
247
  const value = updatedFlatten[key];
228
- del(originElem, key);
248
+ del(originMtrl, key);
229
249
  if (value !== undefined) {
230
- set(originElem, key, value);
250
+ set(originMtrl, key, value);
231
251
  }
232
252
  }
233
253
  });
234
- if ((opts === null || opts === void 0 ? void 0 : opts.strict) === true) {
235
- const originFlatten = toFlattenElement(originElem);
236
- const originKeys = Object.keys(originFlatten);
237
- originKeys.forEach((key) => {
254
+ if ((opts === null || opts === void 0 ? void 0 : opts.onlyUpdateContent) === true) {
255
+ const originFlatten = toFlattenMaterial(originMtrl);
256
+ const originFlattenKeys = Object.keys(originFlatten);
257
+ originFlattenKeys.forEach((key) => {
238
258
  if (!ignoreKeys.includes(key)) {
239
- if (!updatedKeys.includes(key)) {
240
- del(originElem, key);
259
+ if (!updatedFlattenKeys.includes(key)) {
260
+ del(originMtrl, key);
241
261
  }
242
262
  }
243
263
  });
244
264
  }
245
- return originElem;
265
+ if (originMtrl.fill) {
266
+ originMtrl.fill = clearMaterialColor(originMtrl.fill);
267
+ }
268
+ return originMtrl;
246
269
  }
247
- export function updateElementInList(uuid, updateContent, elements) {
248
- var _a, _b, _c;
249
- let targetElement = null;
250
- for (let i = 0; i < elements.length; i++) {
251
- const elem = elements[i];
252
- if (elem.uuid === uuid) {
253
- if (elem.type === 'group' && ((_a = elem.operations) === null || _a === void 0 ? void 0 : _a.resizeEffect)) {
254
- resizeEffectGroupElement(elem, Object.assign({}, updateContent), {
255
- resizeEffect: (_b = elem.operations) === null || _b === void 0 ? void 0 : _b.resizeEffect
270
+ export function updateMaterialInList(id, updateContent, materials) {
271
+ var _a, _b;
272
+ let targetMaterial = null;
273
+ for (let i = 0; i < materials.length; i++) {
274
+ const mtrl = materials[i];
275
+ if (mtrl.id === id) {
276
+ if (mtrl.type === 'group' && ((_a = mtrl.operations) === null || _a === void 0 ? void 0 : _a.resizeEffect)) {
277
+ resizeEffectGroupMaterial(mtrl, Object.assign({}, updateContent), {
278
+ resizeEffect: (_b = mtrl.operations) === null || _b === void 0 ? void 0 : _b.resizeEffect,
256
279
  });
257
280
  }
258
- mergeElement(elem, updateContent);
259
- targetElement = elem;
281
+ mergeMaterial(mtrl, updateContent);
282
+ targetMaterial = mtrl;
260
283
  break;
261
284
  }
262
- else if (elem.type === 'group') {
263
- targetElement = updateElementInList(uuid, updateContent, ((_c = elem === null || elem === void 0 ? void 0 : elem.detail) === null || _c === void 0 ? void 0 : _c.children) || []);
285
+ else if (mtrl.type === 'group') {
286
+ targetMaterial = updateMaterialInList(id, updateContent, (mtrl === null || mtrl === void 0 ? void 0 : mtrl.children) || []);
264
287
  }
265
288
  }
266
- return targetElement;
289
+ return targetMaterial;
267
290
  }
268
- export function updateElementInListByPosition(position, updateContent, elements, opts) {
291
+ export function updateMaterialInListByPosition(position, updateContent, materials, opts) {
269
292
  var _a, _b;
270
- const elem = findElementFromListByPosition(position, elements);
271
- if (elem) {
272
- if (elem.type === 'group' && ((_a = elem.operations) === null || _a === void 0 ? void 0 : _a.resizeEffect)) {
273
- resizeEffectGroupElement(elem, Object.assign({}, updateContent), {
274
- resizeEffect: (_b = elem.operations) === null || _b === void 0 ? void 0 : _b.resizeEffect
293
+ const mtrl = findMaterialFromListByPosition(position, materials);
294
+ if (mtrl) {
295
+ if (mtrl.type === 'group' && ((_a = mtrl.operations) === null || _a === void 0 ? void 0 : _a.resizeEffect)) {
296
+ resizeEffectGroupMaterial(mtrl, Object.assign({}, updateContent), {
297
+ resizeEffect: (_b = mtrl.operations) === null || _b === void 0 ? void 0 : _b.resizeEffect,
275
298
  });
276
299
  }
277
- mergeElement(elem, updateContent, opts);
300
+ mergeMaterial(mtrl, updateContent, opts);
278
301
  }
279
- return elem;
302
+ return mtrl;
280
303
  }
@@ -2,11 +2,11 @@ declare function positiveNum(value: any): boolean;
2
2
  declare function number(value: any): boolean;
3
3
  declare function x(value: any): boolean;
4
4
  declare function y(value: any): boolean;
5
- declare function w(value: any): boolean;
6
- declare function h(value: any): boolean;
5
+ declare function width(value: any): boolean;
6
+ declare function height(value: any): boolean;
7
7
  declare function angle(value: any): boolean;
8
- declare function borderWidth(value: any): boolean;
9
- declare function borderRadius(value: any): boolean;
8
+ declare function strokeWidth(value: any): boolean;
9
+ declare function cornerRadius(value: any): boolean;
10
10
  declare function color(value: any): boolean;
11
11
  declare function imageURL(value: any): boolean;
12
12
  declare function imageBase64(value: any): boolean;
@@ -16,30 +16,29 @@ declare function html(value: any): boolean;
16
16
  declare function text(value: any): value is string;
17
17
  declare function fontSize(value: any): boolean;
18
18
  declare function lineHeight(value: any): boolean;
19
- declare function strokeWidth(value: any): boolean;
20
19
  declare function textAlign(value: any): boolean;
21
20
  declare function fontFamily(value: any): boolean;
22
21
  declare function fontWeight(value: any): boolean;
23
22
  declare function numberStr(value: any): boolean;
24
23
  declare function type(value: any): boolean;
25
- declare function element(elem: any): boolean;
24
+ declare function material(mtrl: any): boolean;
26
25
  declare function layout(value: any): boolean;
27
26
  declare function data(d: any): boolean;
28
27
  export declare const is: {
29
28
  positiveNum: typeof positiveNum;
30
29
  data: typeof data;
31
- element: typeof element;
30
+ material: typeof material;
32
31
  layout: typeof layout;
33
32
  type: typeof type;
34
33
  x: typeof x;
35
34
  y: typeof y;
36
- w: typeof w;
37
- h: typeof h;
35
+ width: typeof width;
36
+ height: typeof height;
38
37
  angle: typeof angle;
39
38
  number: typeof number;
40
39
  numberStr: typeof numberStr;
41
- borderWidth: typeof borderWidth;
42
- borderRadius: typeof borderRadius;
40
+ strokeWidth: typeof strokeWidth;
41
+ cornerRadius: typeof cornerRadius;
43
42
  color: typeof color;
44
43
  imageSrc: typeof imageSrc;
45
44
  imageURL: typeof imageURL;
@@ -52,6 +51,5 @@ export declare const is: {
52
51
  textAlign: typeof textAlign;
53
52
  fontFamily: typeof fontFamily;
54
53
  fontWeight: typeof fontWeight;
55
- strokeWidth: typeof strokeWidth;
56
54
  };
57
55
  export {};
@@ -11,16 +11,16 @@ function x(value) {
11
11
  function y(value) {
12
12
  return number(value);
13
13
  }
14
- function w(value) {
14
+ function width(value) {
15
15
  return positiveNum(value);
16
16
  }
17
- function h(value) {
17
+ function height(value) {
18
18
  return positiveNum(value);
19
19
  }
20
20
  function angle(value) {
21
21
  return typeof value === 'number' && value >= -360 && value <= 360;
22
22
  }
23
- function borderWidth(value) {
23
+ function strokeWidth(value) {
24
24
  return (positiveNum(value) ||
25
25
  (Array.isArray(value) &&
26
26
  positiveNum(value[0]) &&
@@ -28,7 +28,7 @@ function borderWidth(value) {
28
28
  positiveNum(value[2]) &&
29
29
  positiveNum(value[3])));
30
30
  }
31
- function borderRadius(value) {
31
+ function cornerRadius(value) {
32
32
  return (positiveNum(value) ||
33
33
  (Array.isArray(value) &&
34
34
  positiveNum(value[0]) &&
@@ -74,9 +74,6 @@ function fontSize(value) {
74
74
  function lineHeight(value) {
75
75
  return number(value) && value > 0;
76
76
  }
77
- function strokeWidth(value) {
78
- return number(value) && value > 0;
79
- }
80
77
  function textAlign(value) {
81
78
  return ['center', 'left', 'right'].includes(value);
82
79
  }
@@ -90,22 +87,22 @@ function numberStr(value) {
90
87
  return /^(-?\d+(?:\.\d+)?)$/.test(`${value}`);
91
88
  }
92
89
  function type(value) {
93
- return ['rect', 'circle', 'text', 'image', 'svg', 'html', 'group'].includes(value);
90
+ return ['rect', 'circle', 'text', 'image', 'svgCode', 'foreignObject', 'group'].includes(value);
94
91
  }
95
- function element(elem) {
96
- if (!elem) {
92
+ function material(mtrl) {
93
+ if (!mtrl) {
97
94
  return false;
98
95
  }
99
- return type(elem === null || elem === void 0 ? void 0 : elem.type) && x(elem === null || elem === void 0 ? void 0 : elem.x) && y(elem === null || elem === void 0 ? void 0 : elem.y) && w(elem === null || elem === void 0 ? void 0 : elem.w) && h(elem === null || elem === void 0 ? void 0 : elem.h);
96
+ return type(mtrl === null || mtrl === void 0 ? void 0 : mtrl.type) && x(mtrl === null || mtrl === void 0 ? void 0 : mtrl.x) && y(mtrl === null || mtrl === void 0 ? void 0 : mtrl.y) && width(mtrl === null || mtrl === void 0 ? void 0 : mtrl.w) && height(mtrl === null || mtrl === void 0 ? void 0 : mtrl.h);
100
97
  }
101
98
  function layout(value) {
102
99
  if (!value) {
103
100
  return false;
104
101
  }
105
- return x(value === null || value === void 0 ? void 0 : value.x) && y(value === null || value === void 0 ? void 0 : value.y) && w(value === null || value === void 0 ? void 0 : value.w) && h(value === null || value === void 0 ? void 0 : value.h);
102
+ return x(value === null || value === void 0 ? void 0 : value.x) && y(value === null || value === void 0 ? void 0 : value.y) && width(value === null || value === void 0 ? void 0 : value.w) && height(value === null || value === void 0 ? void 0 : value.h);
106
103
  }
107
104
  function data(d) {
108
- if (Array(d === null || d === void 0 ? void 0 : d.elements) && (d === null || d === void 0 ? void 0 : d.elements.length) >= 0) {
105
+ if (Array(d === null || d === void 0 ? void 0 : d.materials) && (d === null || d === void 0 ? void 0 : d.materials.length) >= 0) {
109
106
  return true;
110
107
  }
111
108
  return false;
@@ -113,18 +110,18 @@ function data(d) {
113
110
  export const is = {
114
111
  positiveNum,
115
112
  data,
116
- element,
113
+ material,
117
114
  layout,
118
115
  type,
119
116
  x,
120
117
  y,
121
- w,
122
- h,
118
+ width,
119
+ height,
123
120
  angle,
124
121
  number,
125
122
  numberStr,
126
- borderWidth,
127
- borderRadius,
123
+ strokeWidth,
124
+ cornerRadius,
128
125
  color,
129
126
  imageSrc,
130
127
  imageURL,
@@ -137,5 +134,4 @@ export const is = {
137
134
  textAlign,
138
135
  fontFamily,
139
136
  fontWeight,
140
- strokeWidth
141
137
  };
@@ -1,6 +1,6 @@
1
1
  export declare function loadImage(src: string): Promise<HTMLImageElement>;
2
- export declare function loadSVG(svg: string): Promise<HTMLImageElement>;
3
- export declare function loadHTML(html: string, opts: {
2
+ export declare function loadSVGCode(code: string): Promise<HTMLImageElement>;
3
+ export declare function loadForeignObject(content: string, opts: {
4
4
  width: number;
5
5
  height: number;
6
6
  }): Promise<HTMLImageElement>;
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { parseHTMLToDataURL, parseSVGToDataURL } from './parser';
10
+ import { parseXMLToDataURL, parseSVGCodeToDataURL } from './parser';
11
11
  const { Image } = window;
12
12
  export function loadImage(src) {
13
13
  return new Promise((resolve, reject) => {
@@ -21,20 +21,20 @@ export function loadImage(src) {
21
21
  img.src = src;
22
22
  });
23
23
  }
24
- export function loadSVG(svg) {
24
+ export function loadSVGCode(code) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
- const dataURL = yield parseSVGToDataURL(svg);
26
+ const dataURL = yield parseSVGCodeToDataURL(code);
27
27
  const image = yield loadImage(dataURL);
28
28
  return image;
29
29
  });
30
30
  }
31
31
  function filterAmpersand(str) {
32
- return str.replace(/\&/gi, '&amp;');
32
+ return str.replace(/&/gi, '&amp;');
33
33
  }
34
- export function loadHTML(html, opts) {
34
+ export function loadForeignObject(content, opts) {
35
35
  return __awaiter(this, void 0, void 0, function* () {
36
- html = filterAmpersand(html);
37
- const dataURL = yield parseHTMLToDataURL(html, opts);
36
+ content = filterAmpersand(content);
37
+ const dataURL = yield parseXMLToDataURL(content, opts);
38
38
  const image = yield loadImage(dataURL);
39
39
  return image;
40
40
  });
@@ -0,0 +1,40 @@
1
+ import type { Data, Material, StrictMaterial, MaterialType, MaterialSize, ViewContextSize, ViewSizeInfo, MaterialAssets, MaterialAssetsItem, LoadMaterialType, MaterialPosition } from '@idraw/types';
2
+ export declare function getSelectedMaterialUUIDs(data: Data, indexes: Array<number | string>): string[];
3
+ export declare function validateMaterials(materials: Array<StrictMaterial<MaterialType>>): boolean;
4
+ export declare function calcMaterialListSize(list: StrictMaterial[]): MaterialSize;
5
+ export declare function calcMaterialsContextSize(materials: Array<StrictMaterial<MaterialType>>, opts?: {
6
+ viewWidth: number;
7
+ viewHeight: number;
8
+ extend?: boolean;
9
+ }): ViewContextSize;
10
+ export declare function calcMaterialsViewInfo(materials: Array<StrictMaterial<MaterialType>>, prevViewSize: ViewSizeInfo, options?: {
11
+ extend: boolean;
12
+ }): {
13
+ contextSize: ViewContextSize;
14
+ };
15
+ export declare function getMaterialsAssetIds(materials: StrictMaterial[]): string[];
16
+ export declare function findMaterialFromList(id: string, list: StrictMaterial<MaterialType>[]): StrictMaterial<MaterialType> | null;
17
+ export declare function findMaterialsFromList(ids: string[], list: StrictMaterial<MaterialType>[]): StrictMaterial<MaterialType>[];
18
+ export declare function getMaterialAndGroupQueueFromList(id: string, materials: StrictMaterial<MaterialType>[]): {
19
+ groupQueue: StrictMaterial<'group'>[];
20
+ material: Material | null;
21
+ position: MaterialPosition;
22
+ };
23
+ export declare function getGroupQueueFromList(id: string, materials: StrictMaterial<MaterialType>[]): StrictMaterial<'group'>[];
24
+ export declare function getGroupQueueByMaterialPosition(materials: StrictMaterial<MaterialType>[], position: MaterialPosition): StrictMaterial<'group'>[] | null;
25
+ export declare function getMaterialSize(mtrl: StrictMaterial): MaterialSize;
26
+ export declare function mergeMaterialAsset<T extends StrictMaterial<LoadMaterialType>>(material: T, assets: MaterialAssets): T;
27
+ export declare function filterMaterialAsset<T extends StrictMaterial<LoadMaterialType>>(material: T): {
28
+ material: T;
29
+ assetId: string | null;
30
+ assetItem: MaterialAssetsItem | null;
31
+ };
32
+ export declare function isResourceMaterial(mtrl: StrictMaterial): boolean;
33
+ export declare function findMaterialsFromListByPositions(positions: MaterialPosition[], list: StrictMaterial[]): StrictMaterial[];
34
+ export declare function findMaterialFromListByPosition(position: MaterialPosition, list: StrictMaterial[]): StrictMaterial | null;
35
+ export declare function findMaterialQueueFromListByPosition(position: MaterialPosition, list: StrictMaterial[]): StrictMaterial[];
36
+ export declare function getMaterialPositionFromList(id: string, materials: StrictMaterial<MaterialType>[]): MaterialPosition;
37
+ export declare function getMaterialPositionMapFromList(ids: string[], materials: StrictMaterial<MaterialType>[]): {
38
+ [id: string]: MaterialPosition;
39
+ };
40
+ export declare function isSameMaterialSize(mtrl1: MaterialSize, mtrl2: MaterialSize): boolean;