@idraw/util 0.4.3 → 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.
- package/dist/esm/converter/data-svg.d.ts +2 -0
- package/dist/esm/converter/data-svg.js +19 -0
- package/dist/esm/converter/material-svg.d.ts +2 -0
- package/dist/esm/converter/material-svg.js +63 -0
- package/dist/esm/converter/svg-material.d.ts +2 -0
- package/dist/esm/converter/svg-material.js +188 -0
- package/dist/esm/index.d.ts +32 -21
- package/dist/esm/index.js +32 -21
- package/dist/esm/static.d.ts +1 -0
- package/dist/esm/static.js +1 -0
- package/dist/esm/tool/file.js +2 -2
- package/dist/esm/tool/html.js +27 -27
- package/dist/esm/tool/id.d.ts +1 -0
- package/dist/esm/tool/id.js +4 -0
- package/dist/esm/tool/image.js +6 -6
- package/dist/esm/tool/path-to-box.d.ts +3 -0
- package/dist/esm/tool/path-to-box.js +353 -0
- package/dist/esm/tool/path-to-command.d.ts +4 -0
- package/dist/esm/tool/path-to-command.js +392 -0
- package/dist/esm/tool/path.d.ts +18 -0
- package/dist/esm/tool/path.js +421 -0
- package/dist/esm/tool/svg-path.d.ts +3 -0
- package/dist/esm/{view → tool}/svg-path.js +4 -16
- package/dist/esm/tool/time.d.ts +2 -2
- package/dist/esm/tool/time.js +4 -4
- package/dist/esm/tool/uuid.d.ts +1 -1
- package/dist/esm/tool/uuid.js +6 -6
- package/dist/esm/view/box.d.ts +0 -2
- package/dist/esm/view/box.js +1 -173
- package/dist/esm/view/canvas.js +3 -3
- package/dist/esm/view/check.d.ts +8 -7
- package/dist/esm/view/check.js +34 -34
- package/dist/esm/view/config.d.ts +0 -9
- package/dist/esm/view/config.js +1 -71
- package/dist/esm/view/context2d.d.ts +10 -3
- package/dist/esm/view/context2d.js +39 -18
- package/dist/esm/view/controller.d.ts +5 -5
- package/dist/esm/view/controller.js +105 -102
- package/dist/esm/view/data.d.ts +2 -2
- package/dist/esm/view/data.js +65 -65
- package/dist/esm/view/dom.d.ts +23 -0
- package/dist/esm/view/dom.js +190 -0
- package/dist/esm/view/flat.d.ts +2 -2
- package/dist/esm/view/flat.js +53 -53
- package/dist/esm/view/group.d.ts +3 -3
- package/dist/esm/view/group.js +25 -28
- package/dist/esm/view/handle-material.d.ts +24 -0
- package/dist/esm/view/{handle-element.js → handle-material.js} +98 -75
- package/dist/esm/view/is.d.ts +10 -12
- package/dist/esm/view/is.js +15 -19
- package/dist/esm/view/load.d.ts +2 -2
- package/dist/esm/view/load.js +7 -7
- package/dist/esm/view/material.d.ts +40 -0
- package/dist/esm/view/material.js +476 -0
- package/dist/esm/view/middleware.d.ts +1 -0
- package/dist/esm/view/middleware.js +14 -2
- package/dist/esm/view/modify-record.d.ts +4 -4
- package/dist/esm/view/modify-record.js +2 -2
- package/dist/esm/view/parser.d.ts +2 -2
- package/dist/esm/view/parser.js +3 -3
- package/dist/esm/view/path.d.ts +2 -0
- package/dist/esm/view/path.js +30 -0
- package/dist/esm/view/point-move-material.d.ts +5 -0
- package/dist/esm/view/{point-move-element.js → point-move-material.js} +6 -6
- package/dist/esm/view/point.d.ts +3 -8
- package/dist/esm/view/point.js +1 -21
- package/dist/esm/view/position.d.ts +9 -9
- package/dist/esm/view/position.js +1 -1
- package/dist/esm/view/rect.d.ts +2 -2
- package/dist/esm/view/rect.js +4 -4
- package/dist/esm/view/resize-material.d.ts +4 -0
- package/dist/esm/view/resize-material.js +266 -0
- package/dist/esm/view/rotate.d.ts +11 -11
- package/dist/esm/view/rotate.js +24 -24
- package/dist/esm/view/static.d.ts +13 -0
- package/dist/esm/view/static.js +89 -0
- package/dist/esm/view/styles.d.ts +11 -0
- package/dist/esm/view/styles.js +78 -0
- package/dist/esm/view/vertex.d.ts +8 -8
- package/dist/esm/view/vertex.js +28 -28
- package/dist/esm/view/view-box.d.ts +2 -6
- package/dist/esm/view/view-box.js +8 -64
- package/dist/esm/view/view-calc.d.ts +23 -20
- package/dist/esm/view/view-calc.js +104 -93
- package/dist/esm/view/view-content.d.ts +2 -2
- package/dist/esm/view/view-content.js +34 -34
- package/dist/index.global.js +3144 -1548
- package/dist/index.global.min.js +1 -1
- package/package.json +1 -1
- package/dist/esm/view/element.d.ts +0 -35
- package/dist/esm/view/element.js +0 -471
- package/dist/esm/view/handle-element.d.ts +0 -24
- package/dist/esm/view/point-move-element.d.ts +0 -5
- package/dist/esm/view/resize-element.d.ts +0 -4
- package/dist/esm/view/resize-element.js +0 -255
- package/dist/esm/view/svg-path.d.ts +0 -10
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createUUID } from '../tool/uuid';
|
|
2
|
-
import { defaultText,
|
|
3
|
-
import {
|
|
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 {
|
|
6
|
-
import {
|
|
5
|
+
import { findMaterialFromListByPosition, getMaterialPositionFromList } from './material';
|
|
6
|
+
import { resizeEffectGroupMaterial } from './resize-material';
|
|
7
7
|
const defaultViewWidth = 200;
|
|
8
8
|
const defaultViewHeight = 200;
|
|
9
|
-
function
|
|
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', '
|
|
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
|
|
42
|
+
const mtrlSize = {
|
|
43
43
|
x,
|
|
44
44
|
y,
|
|
45
|
-
w,
|
|
46
|
-
h
|
|
45
|
+
width: w,
|
|
46
|
+
height: h,
|
|
47
47
|
};
|
|
48
|
-
return
|
|
48
|
+
return mtrlSize;
|
|
49
49
|
}
|
|
50
|
-
export function
|
|
51
|
-
const
|
|
52
|
-
let
|
|
50
|
+
export function createMaterial(type, baseMtrl, opts) {
|
|
51
|
+
const materialSize = createMaterialSize(type, opts);
|
|
52
|
+
let attributes = {};
|
|
53
53
|
if (type === 'rect') {
|
|
54
|
-
|
|
54
|
+
attributes = getDefaultMaterialRectAttributes();
|
|
55
55
|
}
|
|
56
56
|
else if (type === 'circle') {
|
|
57
|
-
|
|
57
|
+
attributes = getDefaultMaterialCircleAttributes();
|
|
58
58
|
}
|
|
59
59
|
else if (type === 'text') {
|
|
60
|
-
|
|
60
|
+
attributes = getDefaultMaterialTextAttributes(materialSize);
|
|
61
61
|
}
|
|
62
|
-
else if (type === '
|
|
63
|
-
|
|
62
|
+
else if (type === 'svgCode') {
|
|
63
|
+
attributes = getDefaultMaterialSVGAttributes();
|
|
64
64
|
}
|
|
65
65
|
else if (type === 'image') {
|
|
66
|
-
|
|
66
|
+
attributes = getDefaultMaterialImageAttributes();
|
|
67
67
|
}
|
|
68
68
|
else if (type === 'group') {
|
|
69
|
-
|
|
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
|
|
72
|
-
return
|
|
75
|
+
const mtrl = Object.assign(Object.assign(Object.assign({ id: createUUID(), type }, materialSize), attributes), baseMtrl);
|
|
76
|
+
return mtrl;
|
|
73
77
|
}
|
|
74
|
-
export function
|
|
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,
|
|
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,
|
|
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.
|
|
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
|
|
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.
|
|
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
|
|
129
|
-
const position =
|
|
130
|
-
return
|
|
132
|
+
export function deleteMaterialInList(id, list) {
|
|
133
|
+
const position = getMaterialPositionFromList(id, list);
|
|
134
|
+
return deleteMaterialInListByPosition(position, list);
|
|
131
135
|
}
|
|
132
|
-
export function
|
|
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 {
|
|
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 {
|
|
146
|
+
return { materials, from, to };
|
|
143
147
|
}
|
|
144
148
|
continue;
|
|
145
149
|
}
|
|
146
150
|
}
|
|
147
151
|
}
|
|
148
|
-
const target =
|
|
152
|
+
const target = findMaterialFromListByPosition(from, materials);
|
|
149
153
|
if (target) {
|
|
150
|
-
const insterResult =
|
|
154
|
+
const insterResult = insertMaterialToListByPosition(target, to, materials);
|
|
151
155
|
if (!insterResult) {
|
|
152
|
-
return {
|
|
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
|
-
|
|
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
|
|
239
|
+
return color;
|
|
220
240
|
}
|
|
221
|
-
export function
|
|
222
|
-
const updatedFlatten =
|
|
223
|
-
const ignoreKeys = ['
|
|
224
|
-
const
|
|
225
|
-
|
|
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(
|
|
248
|
+
del(originMtrl, key);
|
|
229
249
|
if (value !== undefined) {
|
|
230
|
-
set(
|
|
250
|
+
set(originMtrl, key, value);
|
|
231
251
|
}
|
|
232
252
|
}
|
|
233
253
|
});
|
|
234
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.
|
|
235
|
-
const originFlatten =
|
|
236
|
-
const
|
|
237
|
-
|
|
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 (!
|
|
240
|
-
del(
|
|
259
|
+
if (!updatedFlattenKeys.includes(key)) {
|
|
260
|
+
del(originMtrl, key);
|
|
241
261
|
}
|
|
242
262
|
}
|
|
243
263
|
});
|
|
244
264
|
}
|
|
245
|
-
|
|
265
|
+
if (originMtrl.fill) {
|
|
266
|
+
originMtrl.fill = clearMaterialColor(originMtrl.fill);
|
|
267
|
+
}
|
|
268
|
+
return originMtrl;
|
|
246
269
|
}
|
|
247
|
-
export function
|
|
248
|
-
var _a, _b
|
|
249
|
-
let
|
|
250
|
-
for (let i = 0; i <
|
|
251
|
-
const
|
|
252
|
-
if (
|
|
253
|
-
if (
|
|
254
|
-
|
|
255
|
-
resizeEffect: (_b =
|
|
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
|
-
|
|
259
|
-
|
|
281
|
+
mergeMaterial(mtrl, updateContent);
|
|
282
|
+
targetMaterial = mtrl;
|
|
260
283
|
break;
|
|
261
284
|
}
|
|
262
|
-
else if (
|
|
263
|
-
|
|
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
|
|
289
|
+
return targetMaterial;
|
|
267
290
|
}
|
|
268
|
-
export function
|
|
291
|
+
export function updateMaterialInListByPosition(position, updateContent, materials, opts) {
|
|
269
292
|
var _a, _b;
|
|
270
|
-
const
|
|
271
|
-
if (
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
-
resizeEffect: (_b =
|
|
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
|
-
|
|
300
|
+
mergeMaterial(mtrl, updateContent, opts);
|
|
278
301
|
}
|
|
279
|
-
return
|
|
302
|
+
return mtrl;
|
|
280
303
|
}
|
package/dist/esm/view/is.d.ts
CHANGED
|
@@ -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
|
|
6
|
-
declare function
|
|
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
|
|
9
|
-
declare function
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
37
|
-
|
|
35
|
+
width: typeof width;
|
|
36
|
+
height: typeof height;
|
|
38
37
|
angle: typeof angle;
|
|
39
38
|
number: typeof number;
|
|
40
39
|
numberStr: typeof numberStr;
|
|
41
|
-
|
|
42
|
-
|
|
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 {};
|
package/dist/esm/view/is.js
CHANGED
|
@@ -11,16 +11,16 @@ function x(value) {
|
|
|
11
11
|
function y(value) {
|
|
12
12
|
return number(value);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function width(value) {
|
|
15
15
|
return positiveNum(value);
|
|
16
16
|
}
|
|
17
|
-
function
|
|
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
|
|
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
|
|
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', '
|
|
90
|
+
return ['rect', 'circle', 'text', 'image', 'svgCode', 'foreignObject', 'group'].includes(value);
|
|
94
91
|
}
|
|
95
|
-
function
|
|
96
|
-
if (!
|
|
92
|
+
function material(mtrl) {
|
|
93
|
+
if (!mtrl) {
|
|
97
94
|
return false;
|
|
98
95
|
}
|
|
99
|
-
return type(
|
|
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) &&
|
|
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.
|
|
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
|
-
|
|
113
|
+
material,
|
|
117
114
|
layout,
|
|
118
115
|
type,
|
|
119
116
|
x,
|
|
120
117
|
y,
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
width,
|
|
119
|
+
height,
|
|
123
120
|
angle,
|
|
124
121
|
number,
|
|
125
122
|
numberStr,
|
|
126
|
-
|
|
127
|
-
|
|
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
|
};
|
package/dist/esm/view/load.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare function loadImage(src: string): Promise<HTMLImageElement>;
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
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>;
|
package/dist/esm/view/load.js
CHANGED
|
@@ -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 {
|
|
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
|
|
24
|
+
export function loadSVGCode(code) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const dataURL = yield
|
|
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(
|
|
32
|
+
return str.replace(/&/gi, '&');
|
|
33
33
|
}
|
|
34
|
-
export function
|
|
34
|
+
export function loadForeignObject(content, opts) {
|
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
|
|
37
|
-
const dataURL = yield
|
|
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;
|