@idraw/util 0.4.0-beta.9 → 0.4.0
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/index.d.ts +46 -31
- package/dist/esm/index.js +46 -31
- package/dist/esm/{lib → tool}/color.js +9 -6
- package/dist/esm/{lib → tool}/event.d.ts +1 -0
- package/dist/esm/{lib → tool}/event.js +3 -0
- package/dist/esm/tool/flat-object.d.ts +6 -0
- package/dist/esm/tool/flat-object.js +28 -0
- package/dist/esm/tool/get-set-del.d.ts +4 -0
- package/dist/esm/tool/get-set-del.js +65 -0
- package/dist/esm/{lib → tool}/html.d.ts +1 -1
- package/dist/esm/{lib → tool}/html.js +6 -2
- package/dist/esm/{lib → tool}/istype.d.ts +1 -0
- package/dist/esm/{lib → tool}/istype.js +3 -0
- package/dist/esm/tool/merge.d.ts +1 -0
- package/dist/esm/tool/merge.js +17 -0
- package/dist/esm/tool/omit.d.ts +1 -0
- package/dist/esm/tool/omit.js +7 -0
- package/dist/esm/tool/store.d.ts +16 -0
- package/dist/esm/{lib → tool}/store.js +17 -5
- package/dist/esm/tool/unflat-object.d.ts +3 -0
- package/dist/esm/tool/unflat-object.js +91 -0
- package/dist/esm/{lib → tool}/uuid.d.ts +1 -1
- package/dist/esm/tool/uuid.js +39 -0
- package/dist/esm/view/box.d.ts +2 -0
- package/dist/esm/view/box.js +173 -0
- package/dist/esm/{lib → view}/canvas.d.ts +0 -1
- package/dist/esm/view/canvas.js +57 -0
- package/dist/esm/{lib → view}/check.js +14 -14
- package/dist/esm/{lib → view}/config.js +2 -2
- package/dist/esm/{lib → view}/context2d.d.ts +4 -0
- package/dist/esm/{lib → view}/context2d.js +20 -0
- package/dist/esm/view/controller.d.ts +12 -0
- package/dist/esm/view/controller.js +321 -0
- package/dist/esm/{lib → view}/data.d.ts +1 -0
- package/dist/esm/{lib → view}/data.js +43 -22
- package/dist/esm/{lib → view}/element.d.ts +5 -0
- package/dist/esm/{lib → view}/element.js +66 -5
- package/dist/esm/view/flat.d.ts +2 -0
- package/dist/esm/view/flat.js +133 -0
- package/dist/esm/view/group.d.ts +3 -0
- package/dist/esm/view/group.js +81 -0
- package/dist/esm/{lib → view}/handle-element.d.ts +11 -1
- package/dist/esm/{lib → view}/handle-element.js +102 -51
- package/dist/esm/view/handle-global.d.ts +4 -0
- package/dist/esm/view/handle-global.js +28 -0
- package/dist/esm/view/handle-layout.d.ts +4 -0
- package/dist/esm/view/handle-layout.js +28 -0
- package/dist/esm/{lib → view}/is.d.ts +3 -1
- package/dist/esm/{lib → view}/is.js +22 -6
- package/dist/esm/view/modify-record.d.ts +4 -0
- package/dist/esm/view/modify-record.js +10 -0
- package/dist/esm/view/point-move-element.d.ts +5 -0
- package/dist/esm/view/point-move-element.js +26 -0
- package/dist/esm/view/position.d.ts +15 -0
- package/dist/esm/view/position.js +79 -0
- package/dist/esm/view/rect.js +11 -0
- package/dist/esm/view/resize-element.d.ts +4 -0
- package/dist/esm/view/resize-element.js +255 -0
- package/dist/esm/{lib → view}/rotate.js +8 -13
- package/dist/esm/view/text.d.ts +1 -0
- package/dist/esm/view/text.js +4 -0
- package/dist/esm/{lib → view}/view-box.js +3 -1
- package/dist/esm/{lib → view}/view-calc.d.ts +16 -3
- package/dist/esm/{lib → view}/view-calc.js +127 -3
- package/dist/esm/view/view-content.d.ts +14 -0
- package/dist/esm/view/view-content.js +88 -0
- package/dist/index.global.js +1938 -346
- package/dist/index.global.min.js +1 -1
- package/package.json +2 -2
- package/dist/esm/lib/canvas.js +0 -81
- package/dist/esm/lib/controller.d.ts +0 -6
- package/dist/esm/lib/controller.js +0 -103
- package/dist/esm/lib/rect.js +0 -11
- package/dist/esm/lib/resize-element.d.ts +0 -2
- package/dist/esm/lib/resize-element.js +0 -101
- package/dist/esm/lib/store.d.ts +0 -11
- package/dist/esm/lib/uuid.js +0 -31
- /package/dist/esm/{lib → tool}/color.d.ts +0 -0
- /package/dist/esm/{lib → tool}/file.d.ts +0 -0
- /package/dist/esm/{lib → tool}/file.js +0 -0
- /package/dist/esm/{lib → tool}/image.d.ts +0 -0
- /package/dist/esm/{lib → tool}/image.js +0 -0
- /package/dist/esm/{lib → tool}/number.d.ts +0 -0
- /package/dist/esm/{lib → tool}/number.js +0 -0
- /package/dist/esm/{lib → tool}/time.d.ts +0 -0
- /package/dist/esm/{lib → tool}/time.js +0 -0
- /package/dist/esm/{lib → view}/check.d.ts +0 -0
- /package/dist/esm/{lib → view}/config.d.ts +0 -0
- /package/dist/esm/{lib → view}/load.d.ts +0 -0
- /package/dist/esm/{lib → view}/load.js +0 -0
- /package/dist/esm/{lib → view}/matrix.d.ts +0 -0
- /package/dist/esm/{lib → view}/matrix.js +0 -0
- /package/dist/esm/{lib → view}/middleware.d.ts +0 -0
- /package/dist/esm/{lib → view}/middleware.js +0 -0
- /package/dist/esm/{lib → view}/parser.d.ts +0 -0
- /package/dist/esm/{lib → view}/parser.js +0 -0
- /package/dist/esm/{lib → view}/point.d.ts +0 -0
- /package/dist/esm/{lib → view}/point.js +0 -0
- /package/dist/esm/{lib → view}/rect.d.ts +0 -0
- /package/dist/esm/{lib → view}/rotate.d.ts +0 -0
- /package/dist/esm/{lib → view}/svg-path.d.ts +0 -0
- /package/dist/esm/{lib → view}/svg-path.js +0 -0
- /package/dist/esm/{lib → view}/vertex.d.ts +0 -0
- /package/dist/esm/{lib → view}/vertex.js +0 -0
- /package/dist/esm/{lib → view}/view-box.d.ts +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { calcElementVertexesInGroup } from './vertex';
|
|
13
|
+
import { limitAngle, parseAngleToRadian, calcElementCenterFromVertexes, rotatePoint } from './rotate';
|
|
14
|
+
function flatElementSize(elemSize, opts) {
|
|
15
|
+
const { groupQueue } = opts;
|
|
16
|
+
let { x, y } = elemSize;
|
|
17
|
+
const { w, h, angle = 0 } = elemSize;
|
|
18
|
+
let totalAngle = 0;
|
|
19
|
+
groupQueue.forEach((group) => {
|
|
20
|
+
x += group.x;
|
|
21
|
+
y += group.y;
|
|
22
|
+
totalAngle += group.angle || 0;
|
|
23
|
+
});
|
|
24
|
+
totalAngle = limitAngle(totalAngle);
|
|
25
|
+
if (totalAngle === 0) {
|
|
26
|
+
return {
|
|
27
|
+
x,
|
|
28
|
+
y,
|
|
29
|
+
w,
|
|
30
|
+
h,
|
|
31
|
+
angle
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
totalAngle += elemSize.angle || 0;
|
|
35
|
+
totalAngle = limitAngle(totalAngle);
|
|
36
|
+
const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
|
|
37
|
+
const center = calcElementCenterFromVertexes(vertexes);
|
|
38
|
+
const start = rotatePoint(center, vertexes[0], parseAngleToRadian(0 - totalAngle));
|
|
39
|
+
x = start.x;
|
|
40
|
+
y = start.y;
|
|
41
|
+
return {
|
|
42
|
+
x,
|
|
43
|
+
y,
|
|
44
|
+
w,
|
|
45
|
+
h,
|
|
46
|
+
angle: totalAngle
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function isValidElement(elem) {
|
|
50
|
+
var _a;
|
|
51
|
+
if (['rect', 'circle'].includes(elem.type)) {
|
|
52
|
+
const detail = elem.detail;
|
|
53
|
+
if (!detail.background && !detail.borderWidth) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (detail.background === 'transparent' && !detail.borderWidth) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (['group'].includes(elem.type)) {
|
|
61
|
+
const detail = elem.detail || {};
|
|
62
|
+
const { children } = detail;
|
|
63
|
+
if (!(children.length > 0) && !detail.background && !detail.borderWidth) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (!(children.length > 0) && detail.background === 'transparent' && !detail.borderWidth) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (elem.type === 'text') {
|
|
71
|
+
if (!elem.detail.text) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (elem.type === 'image') {
|
|
76
|
+
if (!elem.detail.src) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (elem.type === 'html') {
|
|
81
|
+
if (!elem.detail.html) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (elem.type === 'svg') {
|
|
86
|
+
if (!elem.detail.svg) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (elem.type === 'path') {
|
|
91
|
+
const detail = elem.detail;
|
|
92
|
+
if (!(((_a = detail === null || detail === void 0 ? void 0 : detail.commands) === null || _a === void 0 ? void 0 : _a.length) > 0)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
export function flatElementList(list) {
|
|
99
|
+
const elemeList = [];
|
|
100
|
+
const currentGroupQueue = [];
|
|
101
|
+
const _resetElemSize = (elem) => {
|
|
102
|
+
if (!isValidElement(elem)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const newSize = flatElementSize(elem, { groupQueue: currentGroupQueue });
|
|
106
|
+
const resizeElem = Object.assign(Object.assign({}, elem), newSize);
|
|
107
|
+
elemeList.push(resizeElem);
|
|
108
|
+
};
|
|
109
|
+
const _walk = (elem) => {
|
|
110
|
+
var _a;
|
|
111
|
+
if (((_a = elem === null || elem === void 0 ? void 0 : elem.operations) === null || _a === void 0 ? void 0 : _a.invisible) === true) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (elem.type === 'group') {
|
|
115
|
+
const { detail } = elem;
|
|
116
|
+
const { children } = detail, restDetail = __rest(detail, ["children"]);
|
|
117
|
+
_resetElemSize(Object.assign(Object.assign({}, elem), { detail: Object.assign(Object.assign({}, restDetail), { children: [] }) }));
|
|
118
|
+
currentGroupQueue.push(elem);
|
|
119
|
+
children.forEach((child) => {
|
|
120
|
+
_walk(child);
|
|
121
|
+
});
|
|
122
|
+
currentGroupQueue.pop();
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
_resetElemSize(elem);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
for (let i = 0; i < list.length; i++) {
|
|
129
|
+
const elem = list[i];
|
|
130
|
+
_walk(elem);
|
|
131
|
+
}
|
|
132
|
+
return elemeList;
|
|
133
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { findElementFromListByPosition, calcElementListSize } from './element';
|
|
2
|
+
import { deleteElementInListByPosition, insertElementToListByPosition } from './handle-element';
|
|
3
|
+
import { createUUID } from '../tool/uuid';
|
|
4
|
+
export function groupElementsByPosition(list, positions) {
|
|
5
|
+
if (positions.length > 1) {
|
|
6
|
+
let isValidPositions = true;
|
|
7
|
+
let lastIndexs = [];
|
|
8
|
+
for (let i = 1; i < positions.length; i++) {
|
|
9
|
+
const prevPosition = positions[i - 1];
|
|
10
|
+
const position = positions[i];
|
|
11
|
+
if (!(prevPosition.length > 0 && position.length > 0)) {
|
|
12
|
+
isValidPositions = false;
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
if (prevPosition.length !== position.length) {
|
|
16
|
+
isValidPositions = false;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
const temp1 = [...prevPosition];
|
|
20
|
+
const temp2 = [...position];
|
|
21
|
+
const lastIndex1 = temp1.pop();
|
|
22
|
+
const lastIndex2 = temp2.pop();
|
|
23
|
+
if (i === 1 && typeof lastIndex1 === 'number' && lastIndex1 >= 0) {
|
|
24
|
+
lastIndexs.push(lastIndex1);
|
|
25
|
+
}
|
|
26
|
+
if (typeof lastIndex2 === 'number' && lastIndex2 >= 0) {
|
|
27
|
+
lastIndexs.push(lastIndex2);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (isValidPositions !== true) {
|
|
31
|
+
console.error('[idraw]: The grouped elements are not siblings!');
|
|
32
|
+
return list;
|
|
33
|
+
}
|
|
34
|
+
lastIndexs.sort((a, b) => a - b);
|
|
35
|
+
const groupParentPosition = [...positions[0]].splice(0, positions[0].length - 1);
|
|
36
|
+
const groupChildren = [];
|
|
37
|
+
const groupPosition = [...groupParentPosition, lastIndexs[0]];
|
|
38
|
+
for (let i = 0; i < lastIndexs.length; i++) {
|
|
39
|
+
const position = [...groupParentPosition, lastIndexs[i]];
|
|
40
|
+
const elem = findElementFromListByPosition(position, list);
|
|
41
|
+
if (elem) {
|
|
42
|
+
groupChildren.push(elem);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const groupSize = calcElementListSize(groupChildren);
|
|
46
|
+
for (let i = 0; i < groupChildren.length; i++) {
|
|
47
|
+
const elem = groupChildren[i];
|
|
48
|
+
if (elem) {
|
|
49
|
+
elem.x -= groupSize.x;
|
|
50
|
+
elem.y -= groupSize.y;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
for (let i = lastIndexs.length - 1; i >= 0; i--) {
|
|
54
|
+
const position = [...groupParentPosition, lastIndexs[i]];
|
|
55
|
+
deleteElementInListByPosition(position, list);
|
|
56
|
+
}
|
|
57
|
+
const group = Object.assign(Object.assign({ name: 'Group', uuid: createUUID(), type: 'group' }, groupSize), { detail: {
|
|
58
|
+
children: groupChildren
|
|
59
|
+
} });
|
|
60
|
+
insertElementToListByPosition(group, groupPosition, list);
|
|
61
|
+
}
|
|
62
|
+
return list;
|
|
63
|
+
}
|
|
64
|
+
export function ungroupElementsByPosition(list, position) {
|
|
65
|
+
var _a;
|
|
66
|
+
const elem = findElementFromListByPosition(position, list);
|
|
67
|
+
if (!(elem && (elem === null || elem === void 0 ? void 0 : elem.type) === 'group' && Array.isArray((_a = elem === null || elem === void 0 ? void 0 : elem.detail) === null || _a === void 0 ? void 0 : _a.children))) {
|
|
68
|
+
console.error('[idraw]: The ungrouped element is not a group element!');
|
|
69
|
+
}
|
|
70
|
+
const groupParentPosition = [...position].splice(0, position.length - 1);
|
|
71
|
+
const groupLastIndex = position[position.length - 1];
|
|
72
|
+
const { x, y } = elem;
|
|
73
|
+
deleteElementInListByPosition(position, list);
|
|
74
|
+
elem.detail.children.forEach((child, i) => {
|
|
75
|
+
child.x += x;
|
|
76
|
+
child.y += y;
|
|
77
|
+
const elemPosition = [...groupParentPosition, groupLastIndex + i];
|
|
78
|
+
insertElementToListByPosition(child, elemPosition, list);
|
|
79
|
+
});
|
|
80
|
+
return list;
|
|
81
|
+
}
|
|
@@ -10,5 +10,15 @@ export declare function deleteElementInList(uuid: string, list: Element[]): bool
|
|
|
10
10
|
export declare function moveElementPosition(elements: Elements, opts: {
|
|
11
11
|
from: ElementPosition;
|
|
12
12
|
to: ElementPosition;
|
|
13
|
-
}):
|
|
13
|
+
}): {
|
|
14
|
+
elements: Elements;
|
|
15
|
+
from: ElementPosition;
|
|
16
|
+
to: ElementPosition;
|
|
17
|
+
};
|
|
18
|
+
export declare function mergeElement<T extends Element<ElementType> = Element<ElementType>>(originElem: T, updateContent: RecursivePartial<T>, opts?: {
|
|
19
|
+
strict?: boolean;
|
|
20
|
+
}): T;
|
|
14
21
|
export declare function updateElementInList(uuid: string, updateContent: RecursivePartial<Element<ElementType>>, elements: Element[]): Element | null;
|
|
22
|
+
export declare function updateElementInListByPosition(position: ElementPosition, updateContent: RecursivePartial<Element<ElementType>>, elements: Element[], opts?: {
|
|
23
|
+
strict?: boolean;
|
|
24
|
+
}): Element | null;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createUUID } from '
|
|
1
|
+
import { createUUID } from '../tool/uuid';
|
|
2
2
|
import { defaultText, getDefaultElementRectDetail, getDefaultElementCircleDetail, getDefaultElementTextDetail, getDefaultElementSVGDetail, getDefaultElementImageDetail, getDefaultElementGroupDetail } from './config';
|
|
3
|
-
import {
|
|
3
|
+
import { toFlattenElement } from './modify-record';
|
|
4
|
+
import { set, del } from '../tool/get-set-del';
|
|
4
5
|
import { findElementFromListByPosition, getElementPositionFromList } from './element';
|
|
5
|
-
import {
|
|
6
|
+
import { resizeEffectGroupElement } from './resize-element';
|
|
6
7
|
const defaultViewWidth = 200;
|
|
7
8
|
const defaultViewHeight = 200;
|
|
8
9
|
function createElementSize(type, opts) {
|
|
@@ -67,7 +68,7 @@ export function createElement(type, baseElem, opts) {
|
|
|
67
68
|
else if (type === 'group') {
|
|
68
69
|
detail = getDefaultElementGroupDetail();
|
|
69
70
|
}
|
|
70
|
-
const elem = Object.assign(Object.assign(Object.assign({}, elementSize), baseElem), {
|
|
71
|
+
const elem = Object.assign(Object.assign(Object.assign({ uuid: createUUID() }, elementSize), baseElem), { type, detail: Object.assign(Object.assign({}, detail), (baseElem.detail || {})) });
|
|
71
72
|
return elem;
|
|
72
73
|
}
|
|
73
74
|
export function insertElementToListByPosition(element, position, list) {
|
|
@@ -129,15 +130,16 @@ export function deleteElementInList(uuid, list) {
|
|
|
129
130
|
return deleteElementInListByPosition(position, list);
|
|
130
131
|
}
|
|
131
132
|
export function moveElementPosition(elements, opts) {
|
|
132
|
-
const
|
|
133
|
+
const from = [...opts.from];
|
|
134
|
+
const to = [...opts.to];
|
|
133
135
|
if (from.length === 0 || to.length === 0) {
|
|
134
|
-
return elements;
|
|
136
|
+
return { elements, from, to };
|
|
135
137
|
}
|
|
136
138
|
if (from.length <= to.length) {
|
|
137
139
|
for (let i = 0; i < from.length; i++) {
|
|
138
140
|
if (to[i] === from[i]) {
|
|
139
141
|
if (i === from.length - 1) {
|
|
140
|
-
return elements;
|
|
142
|
+
return { elements, from, to };
|
|
141
143
|
}
|
|
142
144
|
continue;
|
|
143
145
|
}
|
|
@@ -147,19 +149,64 @@ export function moveElementPosition(elements, opts) {
|
|
|
147
149
|
if (target) {
|
|
148
150
|
const insterResult = insertElementToListByPosition(target, to, elements);
|
|
149
151
|
if (!insterResult) {
|
|
150
|
-
return elements;
|
|
152
|
+
return { elements, from, to };
|
|
151
153
|
}
|
|
152
154
|
let trimDeletePosIndex = -1;
|
|
153
155
|
const trimDeletePosAction = 'down';
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
let isEffectToIndex = false;
|
|
157
|
+
if (from.length >= 1 && to.length >= 1) {
|
|
158
|
+
if (from.length <= to.length) {
|
|
159
|
+
if (from.length === 1) {
|
|
160
|
+
if (from[0] < to[0]) {
|
|
161
|
+
isEffectToIndex = true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
for (let i = 0; i < from.length; i++) {
|
|
166
|
+
if (from[i] === to[i]) {
|
|
167
|
+
if (from.length === from.length - 1) {
|
|
168
|
+
isEffectToIndex = true;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
157
177
|
}
|
|
158
|
-
if (
|
|
159
|
-
|
|
178
|
+
if (from.length >= to.length) {
|
|
179
|
+
if (to.length === 1) {
|
|
180
|
+
if (to[0] < from[0]) {
|
|
181
|
+
isEffectToIndex = true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
for (let i = 0; i < to.length; i++) {
|
|
186
|
+
if (i === to.length - 1 && to[i] < from[i]) {
|
|
187
|
+
isEffectToIndex = true;
|
|
188
|
+
}
|
|
189
|
+
if (from[i] === to[i]) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
160
197
|
}
|
|
161
|
-
|
|
162
|
-
|
|
198
|
+
}
|
|
199
|
+
if (isEffectToIndex === true) {
|
|
200
|
+
for (let i = 0; i < from.length; i++) {
|
|
201
|
+
if (!(to[i] >= 0)) {
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
if (to[i] === from[i]) {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (to[i] < from[i] && i == to.length - 1) {
|
|
208
|
+
trimDeletePosIndex = i;
|
|
209
|
+
}
|
|
163
210
|
}
|
|
164
211
|
}
|
|
165
212
|
if (trimDeletePosIndex >= 0) {
|
|
@@ -169,61 +216,65 @@ export function moveElementPosition(elements, opts) {
|
|
|
169
216
|
}
|
|
170
217
|
deleteElementInListByPosition(from, elements);
|
|
171
218
|
}
|
|
172
|
-
return elements;
|
|
219
|
+
return { elements, from, to };
|
|
173
220
|
}
|
|
174
|
-
function mergeElement(originElem, updateContent) {
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (!(originElem === null || originElem === void 0 ? void 0 : originElem.hasOwnProperty(commonKey))) {
|
|
185
|
-
originElem[commonKey] = {};
|
|
186
|
-
}
|
|
187
|
-
if (istype.json(originElem[commonKey])) {
|
|
188
|
-
originElem[commonKey] = Object.assign(Object.assign({}, originElem[commonKey]), updateContent[commonKey]);
|
|
189
|
-
}
|
|
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) => {
|
|
226
|
+
if (!ignoreKeys.includes(key)) {
|
|
227
|
+
const value = updatedFlatten[key];
|
|
228
|
+
del(originElem, key);
|
|
229
|
+
if (value !== undefined) {
|
|
230
|
+
set(originElem, key, value);
|
|
190
231
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
originElem
|
|
232
|
+
}
|
|
233
|
+
});
|
|
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) => {
|
|
238
|
+
if (!ignoreKeys.includes(key)) {
|
|
239
|
+
if (!updatedKeys.includes(key)) {
|
|
240
|
+
del(originElem, key);
|
|
200
241
|
}
|
|
201
242
|
}
|
|
202
|
-
}
|
|
243
|
+
});
|
|
203
244
|
}
|
|
204
245
|
return originElem;
|
|
205
246
|
}
|
|
206
247
|
export function updateElementInList(uuid, updateContent, elements) {
|
|
207
|
-
var _a, _b;
|
|
248
|
+
var _a, _b, _c;
|
|
208
249
|
let targetElement = null;
|
|
209
250
|
for (let i = 0; i < elements.length; i++) {
|
|
210
251
|
const elem = elements[i];
|
|
211
252
|
if (elem.uuid === uuid) {
|
|
212
|
-
if (elem.type === 'group' && ((_a = elem.operations) === null || _a === void 0 ? void 0 : _a.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
h: updateContent.h
|
|
217
|
-
});
|
|
218
|
-
}
|
|
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
|
|
256
|
+
});
|
|
219
257
|
}
|
|
220
258
|
mergeElement(elem, updateContent);
|
|
221
259
|
targetElement = elem;
|
|
222
260
|
break;
|
|
223
261
|
}
|
|
224
262
|
else if (elem.type === 'group') {
|
|
225
|
-
targetElement = updateElementInList(uuid, updateContent, ((
|
|
263
|
+
targetElement = updateElementInList(uuid, updateContent, ((_c = elem === null || elem === void 0 ? void 0 : elem.detail) === null || _c === void 0 ? void 0 : _c.children) || []);
|
|
226
264
|
}
|
|
227
265
|
}
|
|
228
266
|
return targetElement;
|
|
229
267
|
}
|
|
268
|
+
export function updateElementInListByPosition(position, updateContent, elements, opts) {
|
|
269
|
+
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
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
mergeElement(elem, updateContent, opts);
|
|
278
|
+
}
|
|
279
|
+
return elem;
|
|
280
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { toFlattenGlobal } from './modify-record';
|
|
2
|
+
import { set, del } from '../tool/get-set-del';
|
|
3
|
+
export function mergeGlobal(originGlobal, updateContent, opts) {
|
|
4
|
+
const updatedFlatten = toFlattenGlobal(updateContent);
|
|
5
|
+
const ignoreKeys = [];
|
|
6
|
+
const updatedKeys = Object.keys(updatedFlatten);
|
|
7
|
+
updatedKeys.forEach((key) => {
|
|
8
|
+
if (!ignoreKeys.includes(key)) {
|
|
9
|
+
const value = updatedFlatten[key];
|
|
10
|
+
del(originGlobal, key);
|
|
11
|
+
if (value !== undefined) {
|
|
12
|
+
set(originGlobal, key, value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.strict) === true) {
|
|
17
|
+
const originFlatten = toFlattenGlobal(originGlobal);
|
|
18
|
+
const originKeys = Object.keys(originFlatten);
|
|
19
|
+
originKeys.forEach((key) => {
|
|
20
|
+
if (!ignoreKeys.includes(key)) {
|
|
21
|
+
if (!updatedKeys.includes(key)) {
|
|
22
|
+
del(originGlobal, key);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return originGlobal;
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { toFlattenLayout } from './modify-record';
|
|
2
|
+
import { set, del } from '../tool/get-set-del';
|
|
3
|
+
export function mergeLayout(originLayout, updateContent, opts) {
|
|
4
|
+
const updatedFlatten = toFlattenLayout(updateContent);
|
|
5
|
+
const ignoreKeys = [];
|
|
6
|
+
const updatedKeys = Object.keys(updatedFlatten);
|
|
7
|
+
updatedKeys.forEach((key) => {
|
|
8
|
+
if (!ignoreKeys.includes(key)) {
|
|
9
|
+
const value = updatedFlatten[key];
|
|
10
|
+
del(originLayout, key);
|
|
11
|
+
if (value !== undefined) {
|
|
12
|
+
set(originLayout, key, value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.strict) === true) {
|
|
17
|
+
const originFlatten = toFlattenLayout(originLayout);
|
|
18
|
+
const originKeys = Object.keys(originFlatten);
|
|
19
|
+
originKeys.forEach((key) => {
|
|
20
|
+
if (!ignoreKeys.includes(key)) {
|
|
21
|
+
if (!updatedKeys.includes(key)) {
|
|
22
|
+
del(originLayout, key);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return originLayout;
|
|
28
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
declare function positiveNum(value: any): boolean;
|
|
1
2
|
declare function number(value: any): boolean;
|
|
2
3
|
declare function x(value: any): boolean;
|
|
3
4
|
declare function y(value: any): boolean;
|
|
@@ -12,7 +13,7 @@ declare function imageBase64(value: any): boolean;
|
|
|
12
13
|
declare function imageSrc(value: any): boolean;
|
|
13
14
|
declare function svg(value: any): boolean;
|
|
14
15
|
declare function html(value: any): boolean;
|
|
15
|
-
declare function text(value: any):
|
|
16
|
+
declare function text(value: any): value is string;
|
|
16
17
|
declare function fontSize(value: any): boolean;
|
|
17
18
|
declare function lineHeight(value: any): boolean;
|
|
18
19
|
declare function strokeWidth(value: any): boolean;
|
|
@@ -21,6 +22,7 @@ declare function fontFamily(value: any): boolean;
|
|
|
21
22
|
declare function fontWeight(value: any): boolean;
|
|
22
23
|
declare function numberStr(value: any): boolean;
|
|
23
24
|
export declare const is: {
|
|
25
|
+
positiveNum: typeof positiveNum;
|
|
24
26
|
x: typeof x;
|
|
25
27
|
y: typeof y;
|
|
26
28
|
w: typeof w;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { isColorStr } from '
|
|
1
|
+
import { isColorStr } from '../tool/color';
|
|
2
|
+
function positiveNum(value) {
|
|
3
|
+
return typeof value === 'number' && value >= 0;
|
|
4
|
+
}
|
|
2
5
|
function number(value) {
|
|
3
6
|
return typeof value === 'number' && (value > 0 || value <= 0);
|
|
4
7
|
}
|
|
@@ -9,19 +12,29 @@ function y(value) {
|
|
|
9
12
|
return number(value);
|
|
10
13
|
}
|
|
11
14
|
function w(value) {
|
|
12
|
-
return
|
|
15
|
+
return positiveNum(value);
|
|
13
16
|
}
|
|
14
17
|
function h(value) {
|
|
15
|
-
return
|
|
18
|
+
return positiveNum(value);
|
|
16
19
|
}
|
|
17
20
|
function angle(value) {
|
|
18
21
|
return typeof value === 'number' && value >= -360 && value <= 360;
|
|
19
22
|
}
|
|
20
23
|
function borderWidth(value) {
|
|
21
|
-
return
|
|
24
|
+
return (positiveNum(value) ||
|
|
25
|
+
(Array.isArray(value) &&
|
|
26
|
+
positiveNum(value[0]) &&
|
|
27
|
+
positiveNum(value[1]) &&
|
|
28
|
+
positiveNum(value[2]) &&
|
|
29
|
+
positiveNum(value[3])));
|
|
22
30
|
}
|
|
23
31
|
function borderRadius(value) {
|
|
24
|
-
return
|
|
32
|
+
return (positiveNum(value) ||
|
|
33
|
+
(Array.isArray(value) &&
|
|
34
|
+
positiveNum(value[0]) &&
|
|
35
|
+
positiveNum(value[1]) &&
|
|
36
|
+
positiveNum(value[2]) &&
|
|
37
|
+
positiveNum(value[3])));
|
|
25
38
|
}
|
|
26
39
|
function color(value) {
|
|
27
40
|
return isColorStr(value);
|
|
@@ -36,7 +49,9 @@ function imageSrc(value) {
|
|
|
36
49
|
return imageBase64(value) || imageURL(value);
|
|
37
50
|
}
|
|
38
51
|
function svg(value) {
|
|
39
|
-
return typeof value === 'string' &&
|
|
52
|
+
return (typeof value === 'string' &&
|
|
53
|
+
/^(<svg[\s]{1,}|<svg>)/i.test(`${value}`.trim()) &&
|
|
54
|
+
/<\/[\s]{0,}svg>$/i.test(`${value}`.trim()));
|
|
40
55
|
}
|
|
41
56
|
function html(value) {
|
|
42
57
|
let result = false;
|
|
@@ -75,6 +90,7 @@ function numberStr(value) {
|
|
|
75
90
|
return /^(-?\d+(?:\.\d+)?)$/.test(`${value}`);
|
|
76
91
|
}
|
|
77
92
|
export const is = {
|
|
93
|
+
positiveNum,
|
|
78
94
|
x,
|
|
79
95
|
y,
|
|
80
96
|
w,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FlattenElement, Element, RecursivePartial, DataLayout, DataGlobal } from '@idraw/types';
|
|
2
|
+
export declare function toFlattenElement(elem: Element | RecursivePartial<Element>): FlattenElement;
|
|
3
|
+
export declare function toFlattenLayout(layout: DataLayout | RecursivePartial<DataLayout>): FlattenElement;
|
|
4
|
+
export declare function toFlattenGlobal(global: DataGlobal | RecursivePartial<DataLayout>): FlattenElement;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { flatObject } from '../tool/flat-object';
|
|
2
|
+
export function toFlattenElement(elem) {
|
|
3
|
+
return flatObject(elem, { ignorePaths: ['detail.children'] });
|
|
4
|
+
}
|
|
5
|
+
export function toFlattenLayout(layout) {
|
|
6
|
+
return flatObject(layout);
|
|
7
|
+
}
|
|
8
|
+
export function toFlattenGlobal(global) {
|
|
9
|
+
return flatObject(global);
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { rotatePointInGroup } from './rotate';
|
|
2
|
+
export function calcPointMoveElementInGroup(start, end, groupQueue) {
|
|
3
|
+
let moveX = end.x - start.x;
|
|
4
|
+
let moveY = end.y - start.y;
|
|
5
|
+
const pointGroupQueue = [];
|
|
6
|
+
groupQueue.forEach((group) => {
|
|
7
|
+
const { x, y, w, h, angle = 0 } = group;
|
|
8
|
+
pointGroupQueue.push({
|
|
9
|
+
x,
|
|
10
|
+
y,
|
|
11
|
+
w,
|
|
12
|
+
h,
|
|
13
|
+
angle: 0 - angle
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
if ((groupQueue === null || groupQueue === void 0 ? void 0 : groupQueue.length) > 0) {
|
|
17
|
+
const startInGroup = rotatePointInGroup(start, pointGroupQueue);
|
|
18
|
+
const endInGroup = rotatePointInGroup(end, pointGroupQueue);
|
|
19
|
+
moveX = endInGroup.x - startInGroup.x;
|
|
20
|
+
moveY = endInGroup.y - startInGroup.y;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
moveX,
|
|
24
|
+
moveY
|
|
25
|
+
};
|
|
26
|
+
}
|