@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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { calcMaterialListSize } from '@idraw/util';
|
|
2
|
+
import { materialToSVG } from './material-svg';
|
|
3
|
+
export function dataToSVG(data) {
|
|
4
|
+
const { layout, materials } = data;
|
|
5
|
+
const size = calcMaterialListSize(data.materials);
|
|
6
|
+
let { x, y, width, height } = size;
|
|
7
|
+
if (layout) {
|
|
8
|
+
x = layout.x;
|
|
9
|
+
y = layout.y;
|
|
10
|
+
width = layout.width;
|
|
11
|
+
height = layout.height;
|
|
12
|
+
}
|
|
13
|
+
let result = `<svg viewBox="0 0 ${width} ${height}">`;
|
|
14
|
+
materials.forEach((mtrl) => {
|
|
15
|
+
result += materialToSVG(Object.assign(Object.assign({}, mtrl), { x: mtrl.x - x, y: mtrl.y - y }));
|
|
16
|
+
});
|
|
17
|
+
result += '</svg>';
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export function materialToSVG(mtrl) {
|
|
2
|
+
return serializeNode(mtrl);
|
|
3
|
+
}
|
|
4
|
+
const materialTypeMap = {
|
|
5
|
+
group: 'g',
|
|
6
|
+
};
|
|
7
|
+
function serializeNode(node, indent = '', level = 0) {
|
|
8
|
+
const tagName = materialTypeMap[node.type] || node.type;
|
|
9
|
+
const attributes = serializeAttributes(node);
|
|
10
|
+
const children = node.children || [];
|
|
11
|
+
const textContent = node.text || '';
|
|
12
|
+
const selfClosingTags = ['circle', 'rect', 'path', 'line', 'polygon', 'polyline', 'ellipse', 'use'];
|
|
13
|
+
const isSelfClosing = selfClosingTags.includes(tagName) && children.length === 0 && !textContent;
|
|
14
|
+
if (isSelfClosing) {
|
|
15
|
+
return `${indent}<${tagName}${attributes} />`;
|
|
16
|
+
}
|
|
17
|
+
let result = `${indent}<${tagName}${attributes}`;
|
|
18
|
+
if (children.length === 0 && !textContent) {
|
|
19
|
+
result += `></${tagName}>`;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
result += '>';
|
|
23
|
+
if (textContent) {
|
|
24
|
+
result += escapeMaterialText(textContent);
|
|
25
|
+
}
|
|
26
|
+
if (children.length > 0) {
|
|
27
|
+
const childIndent = indent + ' ';
|
|
28
|
+
result += '\n';
|
|
29
|
+
result += children.map((child) => serializeNode(child, childIndent, level + 1)).join('\n');
|
|
30
|
+
result += `\n${indent}`;
|
|
31
|
+
}
|
|
32
|
+
result += `</${tagName}>`;
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
function serializeAttributes(node) {
|
|
37
|
+
const reservedProps = ['type', 'children', 'textContent'];
|
|
38
|
+
const attributes = [];
|
|
39
|
+
for (const key in node) {
|
|
40
|
+
if (reservedProps.includes(key))
|
|
41
|
+
continue;
|
|
42
|
+
const value = node[key];
|
|
43
|
+
if (value !== undefined && value !== null) {
|
|
44
|
+
const attrName = camelToKebabCase(key);
|
|
45
|
+
attributes.push(`${attrName}="${escapeMaterialAttribute(String(value))}"`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return attributes.length > 0 ? ' ' + attributes.join(' ') : '';
|
|
49
|
+
}
|
|
50
|
+
function camelToKebabCase(str) {
|
|
51
|
+
return str.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
|
|
52
|
+
}
|
|
53
|
+
function escapeMaterialText(text) {
|
|
54
|
+
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
55
|
+
}
|
|
56
|
+
function escapeMaterialAttribute(value) {
|
|
57
|
+
return value
|
|
58
|
+
.replace(/&/g, '&')
|
|
59
|
+
.replace(/"/g, '"')
|
|
60
|
+
.replace(/'/g, ''')
|
|
61
|
+
.replace(/</g, '<')
|
|
62
|
+
.replace(/>/g, '>');
|
|
63
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { createUUID } from '@idraw/util';
|
|
2
|
+
const svgMaterialTypeMap = {
|
|
3
|
+
svg: 'group',
|
|
4
|
+
g: 'group',
|
|
5
|
+
};
|
|
6
|
+
const validAttributes = [
|
|
7
|
+
'x',
|
|
8
|
+
'y',
|
|
9
|
+
'width',
|
|
10
|
+
'height',
|
|
11
|
+
'angle',
|
|
12
|
+
'id',
|
|
13
|
+
'name',
|
|
14
|
+
'transform',
|
|
15
|
+
'opacity',
|
|
16
|
+
'display',
|
|
17
|
+
'visibility',
|
|
18
|
+
'overflow',
|
|
19
|
+
'fill',
|
|
20
|
+
'fillOpacity',
|
|
21
|
+
'fillRule',
|
|
22
|
+
'stroke',
|
|
23
|
+
'strokeWidth',
|
|
24
|
+
'strokeOpacity',
|
|
25
|
+
'strokeLinecap',
|
|
26
|
+
'strokeLinejoin',
|
|
27
|
+
'strokeDasharray',
|
|
28
|
+
'strokeDashoffset',
|
|
29
|
+
'strokeMiterlimit',
|
|
30
|
+
'fontSize',
|
|
31
|
+
'fontFamily',
|
|
32
|
+
'fontWeight',
|
|
33
|
+
'fontStyle',
|
|
34
|
+
'textAnchor',
|
|
35
|
+
'textDecoration',
|
|
36
|
+
'letterSpacing',
|
|
37
|
+
'wordSpacing',
|
|
38
|
+
'writingMode',
|
|
39
|
+
'textAlign',
|
|
40
|
+
'verticalAlign',
|
|
41
|
+
'cornerRadius',
|
|
42
|
+
'commands',
|
|
43
|
+
'children',
|
|
44
|
+
'rx',
|
|
45
|
+
'ry',
|
|
46
|
+
'cx',
|
|
47
|
+
'cy',
|
|
48
|
+
'r',
|
|
49
|
+
];
|
|
50
|
+
const numArrAttrKeys = ['strokeDasharray'];
|
|
51
|
+
const numAttrKeys = [
|
|
52
|
+
'x',
|
|
53
|
+
'y',
|
|
54
|
+
'width',
|
|
55
|
+
'height',
|
|
56
|
+
'opacity',
|
|
57
|
+
'fillOpacity',
|
|
58
|
+
'strokeWidth',
|
|
59
|
+
'strokeOpacity',
|
|
60
|
+
'strokeDashoffset',
|
|
61
|
+
'fontSize',
|
|
62
|
+
'fontWeight',
|
|
63
|
+
'rx',
|
|
64
|
+
'ry',
|
|
65
|
+
'cx',
|
|
66
|
+
'cy',
|
|
67
|
+
'r',
|
|
68
|
+
];
|
|
69
|
+
function parseAttrValue(key, value) {
|
|
70
|
+
var _a;
|
|
71
|
+
if (numAttrKeys.includes(key) && /^[0-9.]{0,}$/.test(value)) {
|
|
72
|
+
return parseFloat(value);
|
|
73
|
+
}
|
|
74
|
+
if (numArrAttrKeys.includes(key)) {
|
|
75
|
+
return (_a = value
|
|
76
|
+
.match(/[0-9.]{0,}/g)) === null || _a === void 0 ? void 0 : _a.filter((str) => !!str).map((str) => parseFloat(str));
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
function prepareSVGString(svgString) {
|
|
81
|
+
return svgString
|
|
82
|
+
.replace(/<\?xml[^>]*\?>/g, '')
|
|
83
|
+
.replace(/<!DOCTYPE[^>]*>/g, '')
|
|
84
|
+
.trim();
|
|
85
|
+
}
|
|
86
|
+
function kebabToCamelCase(str) {
|
|
87
|
+
return str.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase());
|
|
88
|
+
}
|
|
89
|
+
function setNodeProperty(node, key, value) {
|
|
90
|
+
node[key] = parseAttrValue(key, value);
|
|
91
|
+
}
|
|
92
|
+
function parseStyleAttribute(style, node) {
|
|
93
|
+
const stylePairs = style.split(';');
|
|
94
|
+
for (const pair of stylePairs) {
|
|
95
|
+
const [key, value] = pair.split(':').map((s) => s.trim());
|
|
96
|
+
if (key && value) {
|
|
97
|
+
const camelCaseKey = kebabToCamelCase(key);
|
|
98
|
+
setNodeProperty(node, camelCaseKey, value);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function processTransformAttribute(element, node) {
|
|
103
|
+
const transform = element.getAttribute('transform');
|
|
104
|
+
if (transform) {
|
|
105
|
+
setNodeProperty(node, 'transform', transform);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function processAttributes(element, node) {
|
|
109
|
+
for (let i = 0; i < element.attributes.length; i++) {
|
|
110
|
+
const attr = element.attributes[i];
|
|
111
|
+
const camelCaseKey = kebabToCamelCase(attr.name);
|
|
112
|
+
if (validAttributes.includes(camelCaseKey)) {
|
|
113
|
+
setNodeProperty(node, camelCaseKey, attr.value);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!node.id) {
|
|
117
|
+
node.id = createUUID();
|
|
118
|
+
}
|
|
119
|
+
const style = element.getAttribute('style');
|
|
120
|
+
if (style) {
|
|
121
|
+
parseStyleAttribute(style, node);
|
|
122
|
+
}
|
|
123
|
+
processTransformAttribute(element, node);
|
|
124
|
+
}
|
|
125
|
+
function getTextContent(element) {
|
|
126
|
+
var _a;
|
|
127
|
+
let text = '';
|
|
128
|
+
for (const node of Array.from(element.childNodes)) {
|
|
129
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
130
|
+
text += ((_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '';
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return text;
|
|
134
|
+
}
|
|
135
|
+
function parseElement(element) {
|
|
136
|
+
const tagName = element.tagName;
|
|
137
|
+
const node = {
|
|
138
|
+
type: (svgMaterialTypeMap[tagName] || tagName),
|
|
139
|
+
children: [],
|
|
140
|
+
};
|
|
141
|
+
if (tagName === 'svg') {
|
|
142
|
+
const viewBox = element.getAttribute('viewBox') || '';
|
|
143
|
+
const items = viewBox.split(' ');
|
|
144
|
+
const nums = [];
|
|
145
|
+
if (items.length) {
|
|
146
|
+
items.forEach((str) => {
|
|
147
|
+
const num = parseFloat(str);
|
|
148
|
+
if (num >= 0 || num < 0) {
|
|
149
|
+
nums.push(num);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (nums.length >= 4) {
|
|
154
|
+
node.x = nums[0];
|
|
155
|
+
node.y = nums[1];
|
|
156
|
+
node.width = nums[2];
|
|
157
|
+
node.height = nums[3];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
processAttributes(element, node);
|
|
161
|
+
const text = getTextContent(element);
|
|
162
|
+
if (text) {
|
|
163
|
+
node.text = text;
|
|
164
|
+
}
|
|
165
|
+
node.children = [];
|
|
166
|
+
for (let i = 0; i < element.children.length; i++) {
|
|
167
|
+
const child = element.children[i];
|
|
168
|
+
const mtrl = parseElement(child);
|
|
169
|
+
if (mtrl) {
|
|
170
|
+
node.children.push(mtrl);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return node;
|
|
174
|
+
}
|
|
175
|
+
export function svgToMaterial(svg) {
|
|
176
|
+
const parser = new DOMParser();
|
|
177
|
+
const cleanSVGString = prepareSVGString(svg);
|
|
178
|
+
const xmlDoc = parser.parseFromString(cleanSVGString, 'image/svg+xml');
|
|
179
|
+
const parseError = xmlDoc.getElementsByTagName('parsererror')[0];
|
|
180
|
+
if (parseError) {
|
|
181
|
+
throw new Error(`SVG parsing error: ${parseError.textContent}`);
|
|
182
|
+
}
|
|
183
|
+
const svgElement = xmlDoc.documentElement;
|
|
184
|
+
if (svgElement.tagName.toLowerCase() !== 'svg') {
|
|
185
|
+
throw new Error('Input is not a valid SVG document');
|
|
186
|
+
}
|
|
187
|
+
return parseElement(svgElement);
|
|
188
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,46 +1,57 @@
|
|
|
1
1
|
export { delay, compose, throttle, debounce } from './tool/time';
|
|
2
|
-
export { downloadImageFromCanvas, parseFileToBase64, pickFile, parseFileToText, downloadFileFromText } from './tool/file';
|
|
3
|
-
export { toColorHexStr, toColorHexNum, isColorStr, colorNameToHex, colorToCSS, colorToLinearGradientCSS, mergeHexColorAlpha } from './tool/color';
|
|
2
|
+
export { downloadImageFromCanvas, parseFileToBase64, pickFile, parseFileToText, downloadFileFromText, } from './tool/file';
|
|
3
|
+
export { toColorHexStr, toColorHexNum, isColorStr, colorNameToHex, colorToCSS, colorToLinearGradientCSS, mergeHexColorAlpha, } from './tool/color';
|
|
4
4
|
export { createUUID, isAssetId, createAssetId } from './tool/uuid';
|
|
5
|
-
export { deepClone, sortDataAsserts,
|
|
5
|
+
export { deepClone, sortDataAsserts, deepCloneMaterial, deepCloneData, filterCompactData } from './view/data';
|
|
6
6
|
export { istype } from './tool/istype';
|
|
7
|
-
export { loadImage,
|
|
7
|
+
export { loadImage, loadSVGCode, loadForeignObject } from './view/load';
|
|
8
8
|
export { is } from './view/is';
|
|
9
9
|
export { check } from './view/check';
|
|
10
10
|
export { createBoardContent, createContext2D, createOffscreenContext2D } from './view/canvas';
|
|
11
11
|
export { EventEmitter } from './tool/event';
|
|
12
|
-
export { calcDistance,
|
|
12
|
+
export { calcDistance, getCenterFromTwoPoints, } from './view/point';
|
|
13
13
|
export { Store } from './tool/store';
|
|
14
|
-
export {
|
|
14
|
+
export { parseXMLToDataURL, parseSVGCodeToDataURL } from './view/parser';
|
|
15
|
+
export { convertSVGPathToContext2DCommands, convertPathCommandsToContext2DCommands, convertContext2DCommandsToSVGPath, } from './tool/path-to-command';
|
|
16
|
+
export { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot, getMiddlewareValidStyles } from './view/middleware';
|
|
15
17
|
export { Context2D } from './view/context2d';
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
+
export { rotateMaterial, parseRadianToAngle, parseAngleToRadian, rotateMaterialVertexes, getMaterialRotateVertexes, calcMaterialCenter, calcMaterialCenterFromVertexes, rotatePointInGroup, limitAngle, calcRadian, } from './view/rotate';
|
|
19
|
+
export { getSelectedMaterialUUIDs, validateMaterials, calcMaterialsContextSize, calcMaterialsViewInfo, getMaterialsAssetIds, findMaterialFromList, findMaterialsFromList, findMaterialFromListByPosition, findMaterialQueueFromListByPosition, findMaterialsFromListByPositions, getGroupQueueFromList, getMaterialAndGroupQueueFromList, getGroupQueueByMaterialPosition, getMaterialSize, mergeMaterialAsset, filterMaterialAsset, isResourceMaterial, getMaterialPositionFromList, getMaterialPositionMapFromList, calcMaterialListSize, isSameMaterialSize, } from './view/material';
|
|
18
20
|
export { checkRectIntersect } from './view/rect';
|
|
19
|
-
export { viewScale, viewScroll,
|
|
21
|
+
export { viewScale, viewScroll, calcViewMaterialSize, calcViewPoint, calcPointFromView, calcViewVertexes, isViewPointInMaterial, getViewPointAtMaterial, isMaterialInView, calcViewScaleInfo, calcMaterialViewBoundingInfo, calcMaterialBoundingInfo, boundingInfoToRangeBoundingInfo, isViewPointInMaterialSize, isViewPointInVertexes, } from './view/view-calc';
|
|
20
22
|
export { rotatePoint, rotateVertexes, rotateByCenter } from './view/rotate';
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
23
|
+
export { getMaterialVertexes, calcMaterialVertexesInGroup, calcMaterialVertexesQueueInGroup, calcMaterialQueueVertexesQueueInGroup, } from './view/vertex';
|
|
24
|
+
export { calcMaterialSizeController, calcLayoutSizeController } from './view/controller';
|
|
25
|
+
export { convertPathCommandsToStr, parseSVGPath } from './tool/svg-path';
|
|
24
26
|
export { generateHTML, parseHTML } from './tool/html';
|
|
25
27
|
export { compressImage } from './tool/image';
|
|
26
28
|
export { formatNumber } from './tool/number';
|
|
27
29
|
export { matrixToAngle, matrixToRadian } from './view/matrix';
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
30
|
+
export { getDefaultMaterialAttributes, getDefaultMaterialRectAttributes } from './view/static';
|
|
31
|
+
export { calcVisiableViewSize } from './view/view-box';
|
|
32
|
+
export { mergeMaterial, createMaterial, insertMaterialToListByPosition, deleteMaterialInListByPosition, deleteMaterialInList, moveMaterialPosition, updateMaterialInList, updateMaterialInListByPosition, } from './view/handle-material';
|
|
33
|
+
export { resizeEffectGroupMaterial } from './view/resize-material';
|
|
32
34
|
export { calcViewCenterContent, calcViewCenter } from './view/view-content';
|
|
33
|
-
export {
|
|
35
|
+
export { toFlattenMaterial, toFlattenLayout, toFlattenGlobal } from './view/modify-record';
|
|
34
36
|
export { enhanceFontFamliy } from './view/text';
|
|
35
|
-
export {
|
|
36
|
-
export {
|
|
37
|
-
export {
|
|
37
|
+
export { flatMaterialList } from './view/flat';
|
|
38
|
+
export { groupMaterialsByPosition, ungroupMaterialsByPosition } from './view/group';
|
|
39
|
+
export { calcPointMoveMaterialInGroup } from './view/point-move-material';
|
|
38
40
|
export { mergeLayout } from './view/handle-layout';
|
|
39
41
|
export { mergeGlobal } from './view/handle-global';
|
|
40
42
|
export { calcRevertMovePosition, calcResultMovePosition } from './view/position';
|
|
43
|
+
export { refinePathMaterial } from './view/path';
|
|
44
|
+
export { createHTMLElement, assembleHTMLElement, setHTMLCSSProps, sanitizeHTMLStr, parseHTMLStr, addClassName, removeClassName, getHTMLElementRectInPage, bubbleHTMLElement, isPointInMiddlewareElement, } from './view/dom';
|
|
45
|
+
export { parseStyles, injectStyles, removeStyles } from './view/styles';
|
|
41
46
|
export { merge } from './tool/merge';
|
|
42
47
|
export { omit } from './tool/omit';
|
|
43
|
-
export { elementToBoxInfo } from './view/box';
|
|
44
48
|
export { get, set, toPath } from './tool/get-set-del';
|
|
45
49
|
export { flatObject } from './tool/flat-object';
|
|
46
50
|
export { unflatObject } from './tool/unflat-object';
|
|
51
|
+
export { calcSVGPathBoundingBox, calcPathCommondsBoundingBox } from './tool/path-to-box';
|
|
52
|
+
export { createId } from './tool/id';
|
|
53
|
+
export { shiftPathCommands, shiftPathCommand, scalePathCommands, convertPathCommandsToACLMZ, moveInAnchorCommands, moveCurveCtrlInAnchorCommands, convertLineToExactCurveCommand, } from './tool/path';
|
|
54
|
+
export { svgToMaterial } from './converter/svg-material';
|
|
55
|
+
export { materialToSVG } from './converter/material-svg';
|
|
56
|
+
export { dataToSVG } from './converter/data-svg';
|
|
57
|
+
export { ATTR_VALID_WATCH } from './static';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,46 +1,57 @@
|
|
|
1
1
|
export { delay, compose, throttle, debounce } from './tool/time';
|
|
2
|
-
export { downloadImageFromCanvas, parseFileToBase64, pickFile, parseFileToText, downloadFileFromText } from './tool/file';
|
|
3
|
-
export { toColorHexStr, toColorHexNum, isColorStr, colorNameToHex, colorToCSS, colorToLinearGradientCSS, mergeHexColorAlpha } from './tool/color';
|
|
2
|
+
export { downloadImageFromCanvas, parseFileToBase64, pickFile, parseFileToText, downloadFileFromText, } from './tool/file';
|
|
3
|
+
export { toColorHexStr, toColorHexNum, isColorStr, colorNameToHex, colorToCSS, colorToLinearGradientCSS, mergeHexColorAlpha, } from './tool/color';
|
|
4
4
|
export { createUUID, isAssetId, createAssetId } from './tool/uuid';
|
|
5
|
-
export { deepClone, sortDataAsserts,
|
|
5
|
+
export { deepClone, sortDataAsserts, deepCloneMaterial, deepCloneData, filterCompactData } from './view/data';
|
|
6
6
|
export { istype } from './tool/istype';
|
|
7
|
-
export { loadImage,
|
|
7
|
+
export { loadImage, loadSVGCode, loadForeignObject } from './view/load';
|
|
8
8
|
export { is } from './view/is';
|
|
9
9
|
export { check } from './view/check';
|
|
10
10
|
export { createBoardContent, createContext2D, createOffscreenContext2D } from './view/canvas';
|
|
11
11
|
export { EventEmitter } from './tool/event';
|
|
12
|
-
export { calcDistance,
|
|
12
|
+
export { calcDistance, getCenterFromTwoPoints, } from './view/point';
|
|
13
13
|
export { Store } from './tool/store';
|
|
14
|
-
export {
|
|
14
|
+
export { parseXMLToDataURL, parseSVGCodeToDataURL } from './view/parser';
|
|
15
|
+
export { convertSVGPathToContext2DCommands, convertPathCommandsToContext2DCommands, convertContext2DCommandsToSVGPath, } from './tool/path-to-command';
|
|
16
|
+
export { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot, getMiddlewareValidStyles } from './view/middleware';
|
|
15
17
|
export { Context2D } from './view/context2d';
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
+
export { rotateMaterial, parseRadianToAngle, parseAngleToRadian, rotateMaterialVertexes, getMaterialRotateVertexes, calcMaterialCenter, calcMaterialCenterFromVertexes, rotatePointInGroup, limitAngle, calcRadian, } from './view/rotate';
|
|
19
|
+
export { getSelectedMaterialUUIDs, validateMaterials, calcMaterialsContextSize, calcMaterialsViewInfo, getMaterialsAssetIds, findMaterialFromList, findMaterialsFromList, findMaterialFromListByPosition, findMaterialQueueFromListByPosition, findMaterialsFromListByPositions, getGroupQueueFromList, getMaterialAndGroupQueueFromList, getGroupQueueByMaterialPosition, getMaterialSize, mergeMaterialAsset, filterMaterialAsset, isResourceMaterial, getMaterialPositionFromList, getMaterialPositionMapFromList, calcMaterialListSize, isSameMaterialSize, } from './view/material';
|
|
18
20
|
export { checkRectIntersect } from './view/rect';
|
|
19
|
-
export { viewScale, viewScroll,
|
|
21
|
+
export { viewScale, viewScroll, calcViewMaterialSize, calcViewPoint, calcPointFromView, calcViewVertexes, isViewPointInMaterial, getViewPointAtMaterial, isMaterialInView, calcViewScaleInfo, calcMaterialViewBoundingInfo, calcMaterialBoundingInfo, boundingInfoToRangeBoundingInfo, isViewPointInMaterialSize, isViewPointInVertexes, } from './view/view-calc';
|
|
20
22
|
export { rotatePoint, rotateVertexes, rotateByCenter } from './view/rotate';
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
23
|
+
export { getMaterialVertexes, calcMaterialVertexesInGroup, calcMaterialVertexesQueueInGroup, calcMaterialQueueVertexesQueueInGroup, } from './view/vertex';
|
|
24
|
+
export { calcMaterialSizeController, calcLayoutSizeController } from './view/controller';
|
|
25
|
+
export { convertPathCommandsToStr, parseSVGPath } from './tool/svg-path';
|
|
24
26
|
export { generateHTML, parseHTML } from './tool/html';
|
|
25
27
|
export { compressImage } from './tool/image';
|
|
26
28
|
export { formatNumber } from './tool/number';
|
|
27
29
|
export { matrixToAngle, matrixToRadian } from './view/matrix';
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
30
|
+
export { getDefaultMaterialAttributes, getDefaultMaterialRectAttributes } from './view/static';
|
|
31
|
+
export { calcVisiableViewSize } from './view/view-box';
|
|
32
|
+
export { mergeMaterial, createMaterial, insertMaterialToListByPosition, deleteMaterialInListByPosition, deleteMaterialInList, moveMaterialPosition, updateMaterialInList, updateMaterialInListByPosition, } from './view/handle-material';
|
|
33
|
+
export { resizeEffectGroupMaterial } from './view/resize-material';
|
|
32
34
|
export { calcViewCenterContent, calcViewCenter } from './view/view-content';
|
|
33
|
-
export {
|
|
35
|
+
export { toFlattenMaterial, toFlattenLayout, toFlattenGlobal } from './view/modify-record';
|
|
34
36
|
export { enhanceFontFamliy } from './view/text';
|
|
35
|
-
export {
|
|
36
|
-
export {
|
|
37
|
-
export {
|
|
37
|
+
export { flatMaterialList } from './view/flat';
|
|
38
|
+
export { groupMaterialsByPosition, ungroupMaterialsByPosition } from './view/group';
|
|
39
|
+
export { calcPointMoveMaterialInGroup } from './view/point-move-material';
|
|
38
40
|
export { mergeLayout } from './view/handle-layout';
|
|
39
41
|
export { mergeGlobal } from './view/handle-global';
|
|
40
42
|
export { calcRevertMovePosition, calcResultMovePosition } from './view/position';
|
|
43
|
+
export { refinePathMaterial } from './view/path';
|
|
44
|
+
export { createHTMLElement, assembleHTMLElement, setHTMLCSSProps, sanitizeHTMLStr, parseHTMLStr, addClassName, removeClassName, getHTMLElementRectInPage, bubbleHTMLElement, isPointInMiddlewareElement, } from './view/dom';
|
|
45
|
+
export { parseStyles, injectStyles, removeStyles } from './view/styles';
|
|
41
46
|
export { merge } from './tool/merge';
|
|
42
47
|
export { omit } from './tool/omit';
|
|
43
|
-
export { elementToBoxInfo } from './view/box';
|
|
44
48
|
export { get, set, toPath } from './tool/get-set-del';
|
|
45
49
|
export { flatObject } from './tool/flat-object';
|
|
46
50
|
export { unflatObject } from './tool/unflat-object';
|
|
51
|
+
export { calcSVGPathBoundingBox, calcPathCommondsBoundingBox } from './tool/path-to-box';
|
|
52
|
+
export { createId } from './tool/id';
|
|
53
|
+
export { shiftPathCommands, shiftPathCommand, scalePathCommands, convertPathCommandsToACLMZ, moveInAnchorCommands, moveCurveCtrlInAnchorCommands, convertLineToExactCurveCommand, } from './tool/path';
|
|
54
|
+
export { svgToMaterial } from './converter/svg-material';
|
|
55
|
+
export { materialToSVG } from './converter/material-svg';
|
|
56
|
+
export { dataToSVG } from './converter/data-svg';
|
|
57
|
+
export { ATTR_VALID_WATCH } from './static';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ATTR_VALID_WATCH = "data-idraw-valid-watch";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ATTR_VALID_WATCH = 'data-idraw-valid-watch';
|
package/dist/esm/tool/file.js
CHANGED
|
@@ -18,7 +18,7 @@ export function pickFile(opts) {
|
|
|
18
18
|
var _a;
|
|
19
19
|
const file = (_a = input.files) === null || _a === void 0 ? void 0 : _a[0];
|
|
20
20
|
success({
|
|
21
|
-
file: file
|
|
21
|
+
file: file,
|
|
22
22
|
});
|
|
23
23
|
input = null;
|
|
24
24
|
});
|
|
@@ -69,7 +69,7 @@ export function parseFileToText(file) {
|
|
|
69
69
|
export function parseTextToBlobURL(text) {
|
|
70
70
|
const bytes = new TextEncoder().encode(text);
|
|
71
71
|
const blob = new Blob([bytes], {
|
|
72
|
-
type: 'text/plain;charset=utf-8'
|
|
72
|
+
type: 'text/plain;charset=utf-8',
|
|
73
73
|
});
|
|
74
74
|
const blobURL = window.URL.createObjectURL(blob);
|
|
75
75
|
return blobURL;
|
package/dist/esm/tool/html.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
const attrRegExp = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;
|
|
2
|
-
const
|
|
2
|
+
const mtrlRegExp = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g;
|
|
3
3
|
const whitespaceReg = /^\s*$/;
|
|
4
|
-
const
|
|
5
|
-
function
|
|
4
|
+
const singleMaterials = {};
|
|
5
|
+
function parseMaterial(material) {
|
|
6
6
|
const node = {
|
|
7
|
-
type: '
|
|
7
|
+
type: 'material',
|
|
8
8
|
name: '',
|
|
9
9
|
isVoid: false,
|
|
10
10
|
attributes: {},
|
|
11
|
-
children: []
|
|
11
|
+
children: [],
|
|
12
12
|
};
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
node.name =
|
|
16
|
-
if (
|
|
13
|
+
const materialMatch = material.match(/<\/?([^\s]+?)[/\s>]/);
|
|
14
|
+
if (materialMatch) {
|
|
15
|
+
node.name = materialMatch[1];
|
|
16
|
+
if (singleMaterials[materialMatch[1]] || material.charAt(material.length - 2) === '/') {
|
|
17
17
|
node.isVoid = true;
|
|
18
18
|
}
|
|
19
19
|
if (node.name.startsWith('!--')) {
|
|
20
|
-
const endIndex =
|
|
20
|
+
const endIndex = material.indexOf('-->');
|
|
21
21
|
return {
|
|
22
22
|
type: 'comment',
|
|
23
23
|
name: null,
|
|
24
24
|
attributes: {},
|
|
25
25
|
children: [],
|
|
26
26
|
isVoid: false,
|
|
27
|
-
comment: endIndex !== -1 ?
|
|
27
|
+
comment: endIndex !== -1 ? material.slice(4, endIndex) : '',
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
const reg = new RegExp(attrRegExp);
|
|
32
32
|
let result = null;
|
|
33
33
|
while (true) {
|
|
34
|
-
result = reg.exec(
|
|
34
|
+
result = reg.exec(material);
|
|
35
35
|
if (result === null) {
|
|
36
36
|
break;
|
|
37
37
|
}
|
|
@@ -59,33 +59,33 @@ export function parseHTML(html) {
|
|
|
59
59
|
let current;
|
|
60
60
|
let level = -1;
|
|
61
61
|
let inComponent = false;
|
|
62
|
-
html.replace(
|
|
62
|
+
html.replace(mtrlRegExp, (material, index) => {
|
|
63
63
|
if (inComponent && !Array.isArray(current)) {
|
|
64
|
-
if (
|
|
65
|
-
return
|
|
64
|
+
if (material !== '</' + current.name + '>') {
|
|
65
|
+
return material;
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
68
68
|
inComponent = false;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
const isOpen =
|
|
72
|
-
const isComment =
|
|
73
|
-
const start = index +
|
|
71
|
+
const isOpen = material.charAt(1) !== '/';
|
|
72
|
+
const isComment = material.startsWith('<!--');
|
|
73
|
+
const start = index + material.length;
|
|
74
74
|
const nextChar = html.charAt(start);
|
|
75
75
|
let parent;
|
|
76
76
|
if (isComment) {
|
|
77
|
-
const comment =
|
|
77
|
+
const comment = parseMaterial(material);
|
|
78
78
|
if (level < 0) {
|
|
79
79
|
result.push(comment);
|
|
80
|
-
return
|
|
80
|
+
return material;
|
|
81
81
|
}
|
|
82
82
|
parent = arr[level];
|
|
83
83
|
parent.children.push(comment);
|
|
84
|
-
return
|
|
84
|
+
return material;
|
|
85
85
|
}
|
|
86
86
|
if (isOpen) {
|
|
87
87
|
level++;
|
|
88
|
-
current =
|
|
88
|
+
current = parseMaterial(material);
|
|
89
89
|
if (!current.isVoid && !inComponent && nextChar && nextChar !== '<') {
|
|
90
90
|
const content = html.slice(start, html.indexOf('<', start));
|
|
91
91
|
if (content.trim()) {
|
|
@@ -95,7 +95,7 @@ export function parseHTML(html) {
|
|
|
95
95
|
attributes: {},
|
|
96
96
|
children: [],
|
|
97
97
|
isVoid: false,
|
|
98
|
-
textContent: content.trim()
|
|
98
|
+
textContent: content.trim(),
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -109,7 +109,7 @@ export function parseHTML(html) {
|
|
|
109
109
|
arr[level] = current;
|
|
110
110
|
}
|
|
111
111
|
if (!isOpen || (!Array.isArray(current) && current.isVoid)) {
|
|
112
|
-
if (level > -1 && !Array.isArray(current) && (current.isVoid || current.name ===
|
|
112
|
+
if (level > -1 && !Array.isArray(current) && (current.isVoid || current.name === material.slice(2, -1))) {
|
|
113
113
|
level--;
|
|
114
114
|
current = level === -1 ? result : arr[level];
|
|
115
115
|
}
|
|
@@ -128,13 +128,13 @@ export function parseHTML(html) {
|
|
|
128
128
|
attributes: {},
|
|
129
129
|
children: [],
|
|
130
130
|
isVoid: false,
|
|
131
|
-
textContent: content.trim()
|
|
131
|
+
textContent: content.trim(),
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
return
|
|
137
|
+
return material;
|
|
138
138
|
});
|
|
139
139
|
return result;
|
|
140
140
|
}
|
|
@@ -152,7 +152,7 @@ function stringify(buff, htmlNode) {
|
|
|
152
152
|
switch (htmlNode.type) {
|
|
153
153
|
case 'text':
|
|
154
154
|
return buff + htmlNode.textContent;
|
|
155
|
-
case '
|
|
155
|
+
case 'material':
|
|
156
156
|
buff +=
|
|
157
157
|
'<' +
|
|
158
158
|
htmlNode.name +
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createId(): string;
|