@idraw/util 0.4.0-beta.4 → 0.4.0-beta.40
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 +17 -7
- package/dist/esm/index.js +17 -7
- package/dist/esm/lib/box.d.ts +2 -0
- package/dist/esm/lib/box.js +173 -0
- package/dist/esm/lib/canvas.d.ts +0 -1
- package/dist/esm/lib/canvas.js +26 -50
- package/dist/esm/lib/color.js +9 -6
- package/dist/esm/lib/config.d.ts +5 -10
- package/dist/esm/lib/config.js +9 -9
- package/dist/esm/lib/context2d.d.ts +4 -0
- package/dist/esm/lib/context2d.js +20 -0
- package/dist/esm/lib/controller.d.ts +8 -2
- package/dist/esm/lib/controller.js +184 -9
- package/dist/esm/lib/data.d.ts +7 -2
- package/dist/esm/lib/data.js +114 -4
- package/dist/esm/lib/element.d.ts +5 -0
- package/dist/esm/lib/element.js +54 -1
- package/dist/esm/lib/event.d.ts +4 -2
- package/dist/esm/lib/event.js +31 -11
- package/dist/esm/lib/file.d.ts +2 -1
- package/dist/esm/lib/file.js +4 -1
- package/dist/esm/lib/flat.d.ts +2 -0
- package/dist/esm/lib/flat.js +132 -0
- package/dist/esm/lib/group.d.ts +3 -0
- package/dist/esm/lib/group.js +81 -0
- package/dist/esm/lib/handle-element.d.ts +6 -1
- package/dist/esm/lib/handle-element.js +108 -43
- package/dist/esm/lib/html.d.ts +1 -1
- package/dist/esm/lib/is.d.ts +3 -1
- package/dist/esm/lib/is.js +21 -5
- package/dist/esm/lib/istype.d.ts +1 -0
- package/dist/esm/lib/istype.js +3 -0
- package/dist/esm/lib/merge.d.ts +1 -0
- package/dist/esm/lib/merge.js +17 -0
- package/dist/esm/lib/modify-recorder.d.ts +15 -0
- package/dist/esm/lib/modify-recorder.js +177 -0
- package/dist/esm/lib/modify.d.ts +6 -0
- package/dist/esm/lib/modify.js +99 -0
- package/dist/esm/lib/omit.d.ts +1 -0
- package/dist/esm/lib/omit.js +7 -0
- package/dist/esm/lib/point-move-element.d.ts +5 -0
- package/dist/esm/lib/point-move-element.js +26 -0
- package/dist/esm/lib/rect.js +9 -9
- package/dist/esm/lib/resize-element.d.ts +2 -0
- package/dist/esm/lib/resize-element.js +101 -0
- package/dist/esm/lib/rotate.js +8 -13
- package/dist/esm/lib/store.d.ts +9 -5
- package/dist/esm/lib/store.js +39 -9
- package/dist/esm/lib/text.d.ts +1 -0
- package/dist/esm/lib/text.js +4 -0
- package/dist/esm/lib/time.d.ts +1 -0
- package/dist/esm/lib/time.js +13 -1
- package/dist/esm/lib/view-box.js +4 -2
- package/dist/esm/lib/view-calc.d.ts +16 -3
- package/dist/esm/lib/view-calc.js +127 -3
- package/dist/esm/lib/view-content.d.ts +14 -0
- package/dist/esm/lib/view-content.js +88 -0
- package/dist/index.global.js +1614 -257
- package/dist/index.global.min.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _ModifyRecorder_instances, _ModifyRecorder_doStack, _ModifyRecorder_undoStack, _ModifyRecorder_opts, _ModifyRecorder_wrapRecord;
|
|
13
|
+
import { deepClone } from './data';
|
|
14
|
+
import { modifyElement } from './modify';
|
|
15
|
+
export class ModifyRecorder {
|
|
16
|
+
constructor(opts) {
|
|
17
|
+
_ModifyRecorder_instances.add(this);
|
|
18
|
+
_ModifyRecorder_doStack.set(this, []);
|
|
19
|
+
_ModifyRecorder_undoStack.set(this, []);
|
|
20
|
+
_ModifyRecorder_opts.set(this, void 0);
|
|
21
|
+
__classPrivateFieldSet(this, _ModifyRecorder_opts, opts, "f");
|
|
22
|
+
}
|
|
23
|
+
$getDoStack() {
|
|
24
|
+
return __classPrivateFieldGet(this, _ModifyRecorder_doStack, "f");
|
|
25
|
+
}
|
|
26
|
+
$getUndoStack() {
|
|
27
|
+
return __classPrivateFieldGet(this, _ModifyRecorder_undoStack, "f");
|
|
28
|
+
}
|
|
29
|
+
clear() {
|
|
30
|
+
__classPrivateFieldSet(this, _ModifyRecorder_doStack, [], "f");
|
|
31
|
+
__classPrivateFieldSet(this, _ModifyRecorder_undoStack, [], "f");
|
|
32
|
+
}
|
|
33
|
+
destroy() {
|
|
34
|
+
this.clear();
|
|
35
|
+
__classPrivateFieldSet(this, _ModifyRecorder_doStack, null, "f");
|
|
36
|
+
__classPrivateFieldSet(this, _ModifyRecorder_undoStack, null, "f");
|
|
37
|
+
}
|
|
38
|
+
do(data, opts) {
|
|
39
|
+
const { data: modifiedData, content } = modifyElement(data, opts);
|
|
40
|
+
if (__classPrivateFieldGet(this, _ModifyRecorder_opts, "f").recordable === true) {
|
|
41
|
+
const record = __classPrivateFieldGet(this, _ModifyRecorder_instances, "m", _ModifyRecorder_wrapRecord).call(this, opts, content);
|
|
42
|
+
__classPrivateFieldGet(this, _ModifyRecorder_doStack, "f").push(record);
|
|
43
|
+
}
|
|
44
|
+
return modifiedData;
|
|
45
|
+
}
|
|
46
|
+
undo(data) {
|
|
47
|
+
if (__classPrivateFieldGet(this, _ModifyRecorder_opts, "f").recordable !== true) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
let modifiedData = null;
|
|
51
|
+
if (__classPrivateFieldGet(this, _ModifyRecorder_doStack, "f").length === 0) {
|
|
52
|
+
return data;
|
|
53
|
+
}
|
|
54
|
+
const item = __classPrivateFieldGet(this, _ModifyRecorder_doStack, "f").pop();
|
|
55
|
+
if (!item) {
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
if ((item === null || item === void 0 ? void 0 : item.type) === 'addElement') {
|
|
59
|
+
const record = item;
|
|
60
|
+
const { position, element } = record;
|
|
61
|
+
modifiedData = modifyElement(data, {
|
|
62
|
+
type: 'deleteElement',
|
|
63
|
+
content: {
|
|
64
|
+
position,
|
|
65
|
+
element
|
|
66
|
+
}
|
|
67
|
+
}).data;
|
|
68
|
+
}
|
|
69
|
+
else if ((item === null || item === void 0 ? void 0 : item.type) === 'updateElement') {
|
|
70
|
+
const record = item;
|
|
71
|
+
const { position, beforeModifiedElement, afterModifiedElement } = record;
|
|
72
|
+
modifiedData = modifyElement(data, {
|
|
73
|
+
type: 'updateElement',
|
|
74
|
+
content: {
|
|
75
|
+
position,
|
|
76
|
+
beforeModifiedElement: afterModifiedElement,
|
|
77
|
+
afterModifiedElement: beforeModifiedElement
|
|
78
|
+
}
|
|
79
|
+
}).data;
|
|
80
|
+
}
|
|
81
|
+
else if ((item === null || item === void 0 ? void 0 : item.type) === 'deleteElement') {
|
|
82
|
+
const record = item;
|
|
83
|
+
const { position, element } = record;
|
|
84
|
+
modifiedData = modifyElement(data, {
|
|
85
|
+
type: 'addElement',
|
|
86
|
+
content: {
|
|
87
|
+
position,
|
|
88
|
+
element
|
|
89
|
+
}
|
|
90
|
+
}).data;
|
|
91
|
+
}
|
|
92
|
+
else if ((item === null || item === void 0 ? void 0 : item.type) === 'moveElement') {
|
|
93
|
+
const record = item;
|
|
94
|
+
const { afterModifiedFrom, afterModifiedTo } = record;
|
|
95
|
+
const modifiedResult = modifyElement(data, {
|
|
96
|
+
type: 'moveElement',
|
|
97
|
+
content: {
|
|
98
|
+
from: afterModifiedTo,
|
|
99
|
+
to: afterModifiedFrom
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
modifiedData = modifiedResult.data;
|
|
103
|
+
}
|
|
104
|
+
__classPrivateFieldGet(this, _ModifyRecorder_undoStack, "f").push(deepClone(item));
|
|
105
|
+
return modifiedData;
|
|
106
|
+
}
|
|
107
|
+
redo(data) {
|
|
108
|
+
if (__classPrivateFieldGet(this, _ModifyRecorder_opts, "f").recordable !== true) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
let modifiedData = null;
|
|
112
|
+
if (__classPrivateFieldGet(this, _ModifyRecorder_undoStack, "f").length === 0) {
|
|
113
|
+
return modifiedData;
|
|
114
|
+
}
|
|
115
|
+
const item = __classPrivateFieldGet(this, _ModifyRecorder_undoStack, "f").pop();
|
|
116
|
+
if (!item) {
|
|
117
|
+
return modifiedData;
|
|
118
|
+
}
|
|
119
|
+
if ((item === null || item === void 0 ? void 0 : item.type) === 'addElement') {
|
|
120
|
+
const record = item;
|
|
121
|
+
const { position, element } = record;
|
|
122
|
+
modifiedData = modifyElement(data, {
|
|
123
|
+
type: 'addElement',
|
|
124
|
+
content: {
|
|
125
|
+
position,
|
|
126
|
+
element
|
|
127
|
+
}
|
|
128
|
+
}).data;
|
|
129
|
+
}
|
|
130
|
+
else if ((item === null || item === void 0 ? void 0 : item.type) === 'updateElement') {
|
|
131
|
+
const record = item;
|
|
132
|
+
const { position, beforeModifiedElement, afterModifiedElement } = record;
|
|
133
|
+
modifiedData = modifyElement(data, {
|
|
134
|
+
type: 'updateElement',
|
|
135
|
+
content: {
|
|
136
|
+
position,
|
|
137
|
+
beforeModifiedElement,
|
|
138
|
+
afterModifiedElement
|
|
139
|
+
}
|
|
140
|
+
}).data;
|
|
141
|
+
}
|
|
142
|
+
else if ((item === null || item === void 0 ? void 0 : item.type) === 'deleteElement') {
|
|
143
|
+
const record = item;
|
|
144
|
+
const { position, element } = record;
|
|
145
|
+
modifiedData = modifyElement(data, {
|
|
146
|
+
type: 'deleteElement',
|
|
147
|
+
content: {
|
|
148
|
+
position,
|
|
149
|
+
element
|
|
150
|
+
}
|
|
151
|
+
}).data;
|
|
152
|
+
}
|
|
153
|
+
else if ((item === null || item === void 0 ? void 0 : item.type) === 'moveElement') {
|
|
154
|
+
const record = item;
|
|
155
|
+
const { from, to } = record;
|
|
156
|
+
modifiedData = modifyElement(data, {
|
|
157
|
+
type: 'moveElement',
|
|
158
|
+
content: {
|
|
159
|
+
from,
|
|
160
|
+
to
|
|
161
|
+
}
|
|
162
|
+
}).data;
|
|
163
|
+
}
|
|
164
|
+
__classPrivateFieldGet(this, _ModifyRecorder_doStack, "f").push(deepClone(item));
|
|
165
|
+
return modifiedData;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
_ModifyRecorder_doStack = new WeakMap(), _ModifyRecorder_undoStack = new WeakMap(), _ModifyRecorder_opts = new WeakMap(), _ModifyRecorder_instances = new WeakSet(), _ModifyRecorder_wrapRecord = function _ModifyRecorder_wrapRecord(opts, modifiedContent) {
|
|
169
|
+
const content = opts.content;
|
|
170
|
+
const modifyRecord = Object.assign(Object.assign({}, deepClone(content)), { type: opts.type, time: Date.now() });
|
|
171
|
+
const record = modifyRecord;
|
|
172
|
+
if (opts.type === 'moveElement') {
|
|
173
|
+
modifyRecord.afterModifiedFrom = [...modifiedContent.from];
|
|
174
|
+
modifyRecord.afterModifiedTo = [...modifiedContent.to];
|
|
175
|
+
}
|
|
176
|
+
return record;
|
|
177
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Data, Element, ModifyOptions, ModifyType, ModifyContentMap, ModifiedElement } from '@idraw/types';
|
|
2
|
+
export declare function modifyElement<T extends ModifyType = ModifyType>(data: Data, options: ModifyOptions<T>): {
|
|
3
|
+
data: Data;
|
|
4
|
+
content: ModifyContentMap[T];
|
|
5
|
+
};
|
|
6
|
+
export declare function getModifiedElement(target: ModifiedElement, originElement: Element): ModifiedElement;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { insertElementToListByPosition, deleteElementInListByPosition, moveElementPosition, updateElementInListByPosition } from './handle-element';
|
|
2
|
+
import { istype } from './istype';
|
|
3
|
+
export function modifyElement(data, options) {
|
|
4
|
+
const { type } = options;
|
|
5
|
+
const content = Object.assign({}, options.content);
|
|
6
|
+
if (type === 'addElement') {
|
|
7
|
+
const opts = options;
|
|
8
|
+
const { element, position } = opts.content;
|
|
9
|
+
if ((position === null || position === void 0 ? void 0 : position.length) > 0) {
|
|
10
|
+
insertElementToListByPosition(element, [...position], data.elements);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
data.elements.push(element);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else if (type === 'deleteElement') {
|
|
17
|
+
const opts = options;
|
|
18
|
+
const { position } = opts.content;
|
|
19
|
+
deleteElementInListByPosition(position, data.elements);
|
|
20
|
+
}
|
|
21
|
+
else if (type === 'moveElement') {
|
|
22
|
+
const opts = options;
|
|
23
|
+
const { from, to } = opts.content;
|
|
24
|
+
const movedResult = moveElementPosition(data.elements, { from, to });
|
|
25
|
+
content.from = movedResult.from;
|
|
26
|
+
content.to = movedResult.to;
|
|
27
|
+
data.elements = movedResult.elements;
|
|
28
|
+
}
|
|
29
|
+
else if (type === 'updateElement') {
|
|
30
|
+
const opts = options;
|
|
31
|
+
const { position, afterModifiedElement } = opts.content;
|
|
32
|
+
updateElementInListByPosition(position, afterModifiedElement, data.elements);
|
|
33
|
+
}
|
|
34
|
+
return { data, content };
|
|
35
|
+
}
|
|
36
|
+
function _get(source, path, defaultValue = undefined) {
|
|
37
|
+
const keyList = path.split('.');
|
|
38
|
+
const result = keyList.reduce((obj, key) => {
|
|
39
|
+
return Object(obj)[key];
|
|
40
|
+
}, source);
|
|
41
|
+
return result === undefined ? defaultValue : result;
|
|
42
|
+
}
|
|
43
|
+
function _set(obj, path, value) {
|
|
44
|
+
const keys = path.split('.');
|
|
45
|
+
if (typeof obj !== 'object')
|
|
46
|
+
return obj;
|
|
47
|
+
keys.reduce((o, k, i, _) => {
|
|
48
|
+
if (i === _.length - 1) {
|
|
49
|
+
o[k] = value;
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
else if (k in o) {
|
|
53
|
+
return o[k];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
o[k] = /^[0-9]{1,}$/.test(_[i + 1]) ? [] : {};
|
|
57
|
+
return o[k];
|
|
58
|
+
}
|
|
59
|
+
}, obj);
|
|
60
|
+
return obj;
|
|
61
|
+
}
|
|
62
|
+
export function getModifiedElement(target, originElement) {
|
|
63
|
+
const modifiedElement = {};
|
|
64
|
+
const pathList = [];
|
|
65
|
+
const _walk = (t) => {
|
|
66
|
+
if (istype.json(t)) {
|
|
67
|
+
const keys = Object.keys(t);
|
|
68
|
+
keys.forEach((key) => {
|
|
69
|
+
pathList.push(key);
|
|
70
|
+
if (istype.json(t[key]) || istype.array(t[key])) {
|
|
71
|
+
_walk(t[key]);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const pathStr = pathList.join('.');
|
|
75
|
+
if (pathStr !== 'uuid') {
|
|
76
|
+
const value = _get(originElement, pathStr);
|
|
77
|
+
_set(modifiedElement, pathList.join('.'), value);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
pathList.pop();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
else if (istype.array(t)) {
|
|
84
|
+
t.forEach((index) => {
|
|
85
|
+
pathList.push(index);
|
|
86
|
+
if (istype.json(t[index]) || istype.array(t[index])) {
|
|
87
|
+
_walk(t[index]);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const value = _get(originElement, pathList.join('.'));
|
|
91
|
+
_set(modifiedElement, pathList.join('.'), value);
|
|
92
|
+
}
|
|
93
|
+
pathList.pop();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
_walk(target);
|
|
98
|
+
return modifiedElement;
|
|
99
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
@@ -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
|
+
}
|
package/dist/esm/lib/rect.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export function checkRectIntersect(rect1, rect2) {
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
return
|
|
2
|
+
const rect1MinX = rect1.x;
|
|
3
|
+
const rect1MinY = rect1.y;
|
|
4
|
+
const rect1MaxX = rect1.x + rect1.w;
|
|
5
|
+
const rect1MaxY = rect1.y + rect1.h;
|
|
6
|
+
const rect2MinX = rect2.x;
|
|
7
|
+
const rect2MinY = rect2.y;
|
|
8
|
+
const rect2MaxX = rect2.x + rect2.w;
|
|
9
|
+
const rect2MaxY = rect2.y + rect2.h;
|
|
10
|
+
return rect1MinX <= rect2MaxX && rect1MaxX >= rect2MinX && rect1MinY <= rect2MaxY && rect1MaxY >= rect2MinY;
|
|
11
11
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { formatNumber } from './number';
|
|
2
|
+
const doNum = (n) => {
|
|
3
|
+
return formatNumber(n, { decimalPlaces: 4 });
|
|
4
|
+
};
|
|
5
|
+
function resizeElementBaseDetail(elem, opts) {
|
|
6
|
+
const { detail } = elem;
|
|
7
|
+
const { xRatio, yRatio, maxRatio } = opts;
|
|
8
|
+
const middleRatio = (xRatio + yRatio) / 2;
|
|
9
|
+
const { borderWidth, borderRadius, borderDash, shadowOffsetX, shadowOffsetY, shadowBlur } = detail;
|
|
10
|
+
if (typeof borderWidth === 'number') {
|
|
11
|
+
detail.borderWidth = doNum(borderWidth * middleRatio);
|
|
12
|
+
}
|
|
13
|
+
else if (Array.isArray(detail.borderWidth)) {
|
|
14
|
+
const bw = borderWidth;
|
|
15
|
+
detail.borderWidth = [doNum(bw[0] * yRatio), doNum(bw[1] * xRatio), doNum(bw[2] * yRatio), doNum(bw[3] * xRatio)];
|
|
16
|
+
}
|
|
17
|
+
if (typeof borderRadius === 'number') {
|
|
18
|
+
detail.borderRadius = doNum(borderRadius * middleRatio);
|
|
19
|
+
}
|
|
20
|
+
else if (Array.isArray(detail.borderRadius)) {
|
|
21
|
+
const br = borderRadius;
|
|
22
|
+
detail.borderRadius = [br[0] * xRatio, br[1] * xRatio, br[2] * yRatio, br[3] * yRatio];
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(borderDash)) {
|
|
25
|
+
borderDash.forEach((dash, i) => {
|
|
26
|
+
detail.borderDash[i] = doNum(dash * maxRatio);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (typeof shadowOffsetX === 'number') {
|
|
30
|
+
detail.shadowOffsetX = doNum(shadowOffsetX * maxRatio);
|
|
31
|
+
}
|
|
32
|
+
if (typeof shadowOffsetY === 'number') {
|
|
33
|
+
detail.shadowOffsetX = doNum(shadowOffsetY * maxRatio);
|
|
34
|
+
}
|
|
35
|
+
if (typeof shadowBlur === 'number') {
|
|
36
|
+
detail.shadowOffsetX = doNum(shadowBlur * maxRatio);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function resizeElementBase(elem, opts) {
|
|
40
|
+
const { xRatio, yRatio } = opts;
|
|
41
|
+
const { x, y, w, h } = elem;
|
|
42
|
+
elem.x = doNum(x * xRatio);
|
|
43
|
+
elem.y = doNum(y * yRatio);
|
|
44
|
+
elem.w = doNum(w * xRatio);
|
|
45
|
+
elem.h = doNum(h * yRatio);
|
|
46
|
+
resizeElementBaseDetail(elem, opts);
|
|
47
|
+
}
|
|
48
|
+
function resizeTextElementDetail(elem, opts) {
|
|
49
|
+
const { minRatio, maxRatio } = opts;
|
|
50
|
+
const { fontSize, lineHeight } = elem.detail;
|
|
51
|
+
const ratio = (minRatio + maxRatio) / 2;
|
|
52
|
+
if (fontSize && fontSize > 0) {
|
|
53
|
+
elem.detail.fontSize = doNum(fontSize * ratio);
|
|
54
|
+
}
|
|
55
|
+
if (lineHeight && lineHeight > 0) {
|
|
56
|
+
elem.detail.lineHeight = doNum(lineHeight * ratio);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function resizeElement(elem, opts) {
|
|
60
|
+
const { type } = elem;
|
|
61
|
+
resizeElementBase(elem, opts);
|
|
62
|
+
if (type === 'circle') {
|
|
63
|
+
}
|
|
64
|
+
else if (type === 'text') {
|
|
65
|
+
resizeTextElementDetail(elem, opts);
|
|
66
|
+
}
|
|
67
|
+
else if (type === 'image') {
|
|
68
|
+
}
|
|
69
|
+
else if (type === 'svg') {
|
|
70
|
+
}
|
|
71
|
+
else if (type === 'html') {
|
|
72
|
+
}
|
|
73
|
+
else if (type === 'path') {
|
|
74
|
+
}
|
|
75
|
+
else if (type === 'group' && Array.isArray(elem.detail.children)) {
|
|
76
|
+
elem.detail.children.forEach((child) => {
|
|
77
|
+
resizeElement(child, opts);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export function deepResizeGroupElement(elem, size) {
|
|
82
|
+
const resizeW = size.w && size.w > 0 ? size.w : elem.w;
|
|
83
|
+
const resizeH = size.h && size.h > 0 ? size.h : elem.h;
|
|
84
|
+
const xRatio = resizeW / elem.w;
|
|
85
|
+
const yRatio = resizeH / elem.h;
|
|
86
|
+
if (xRatio === yRatio && xRatio === 1) {
|
|
87
|
+
return elem;
|
|
88
|
+
}
|
|
89
|
+
const minRatio = Math.min(xRatio, yRatio);
|
|
90
|
+
const maxRatio = Math.max(xRatio, yRatio);
|
|
91
|
+
elem.w = resizeW;
|
|
92
|
+
elem.h = resizeH;
|
|
93
|
+
const opts = { xRatio, yRatio, minRatio, maxRatio };
|
|
94
|
+
if (elem.type === 'group' && Array.isArray(elem.detail.children)) {
|
|
95
|
+
elem.detail.children.forEach((child) => {
|
|
96
|
+
resizeElement(child, opts);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
resizeElementBaseDetail(elem, opts);
|
|
100
|
+
return elem;
|
|
101
|
+
}
|
package/dist/esm/lib/rotate.js
CHANGED
|
@@ -46,18 +46,10 @@ export function calcElementCenterFromVertexes(ves) {
|
|
|
46
46
|
return calcElementCenter(elemSize);
|
|
47
47
|
}
|
|
48
48
|
export function calcRadian(center, start, end) {
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
return endAngle + (Math.PI * 2 - startAngle);
|
|
54
|
-
}
|
|
55
|
-
else if (endAngle > (Math.PI * 3) / 2 && startAngle < Math.PI / 2) {
|
|
56
|
-
return startAngle + (Math.PI * 2 - endAngle);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
return endAngle - startAngle;
|
|
60
|
-
}
|
|
49
|
+
const startRadian = calcLineRadian(center, start);
|
|
50
|
+
const endRadian = calcLineRadian(center, end);
|
|
51
|
+
if (endRadian !== null && startRadian !== null) {
|
|
52
|
+
return endRadian - startRadian;
|
|
61
53
|
}
|
|
62
54
|
else {
|
|
63
55
|
return 0;
|
|
@@ -199,12 +191,15 @@ export function rotateVertexes(center, ves, radian) {
|
|
|
199
191
|
];
|
|
200
192
|
}
|
|
201
193
|
export function limitAngle(angle) {
|
|
202
|
-
if (!(angle > 0 || angle < 0) || angle === 0) {
|
|
194
|
+
if (!(angle > 0 || angle < 0) || angle === 0 || angle === 360) {
|
|
203
195
|
return 0;
|
|
204
196
|
}
|
|
205
197
|
let num = angle % 360;
|
|
206
198
|
if (num < 0) {
|
|
207
199
|
num += 360;
|
|
208
200
|
}
|
|
201
|
+
else if (angle === 360) {
|
|
202
|
+
num = 0;
|
|
203
|
+
}
|
|
209
204
|
return num;
|
|
210
205
|
}
|
package/dist/esm/lib/store.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
export declare class Store<T extends Record<string | symbol, any>> {
|
|
2
|
-
private
|
|
3
|
-
private _backUpDefaultStorage;
|
|
1
|
+
export declare class Store<T extends Record<string | symbol, any> = Record<string | symbol, any>, S extends Record<string | symbol, any> = Record<string | symbol, any>> {
|
|
2
|
+
#private;
|
|
4
3
|
constructor(opts: {
|
|
5
4
|
defaultStorage: T;
|
|
5
|
+
defaultStatic?: S;
|
|
6
6
|
});
|
|
7
7
|
set<K extends keyof T>(name: K, value: T[K]): void;
|
|
8
8
|
get<K extends keyof T>(name: K): T[K];
|
|
9
|
-
|
|
9
|
+
setStatic<K extends keyof S>(name: K, value: S[K]): void;
|
|
10
|
+
getStatic<K extends keyof S>(name: K): S[K] | undefined;
|
|
11
|
+
getSnapshot(opts?: {
|
|
12
|
+
deepClone?: boolean;
|
|
13
|
+
}): T;
|
|
10
14
|
clear(): void;
|
|
11
|
-
|
|
15
|
+
destroy(): void;
|
|
12
16
|
}
|
package/dist/esm/lib/store.js
CHANGED
|
@@ -1,22 +1,52 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _Store_instances, _Store_temp, _Store_backUpDefaultStorage, _Store_static, _Store_createTempStorage;
|
|
1
13
|
import { deepClone } from './data';
|
|
2
14
|
export class Store {
|
|
3
15
|
constructor(opts) {
|
|
4
|
-
|
|
5
|
-
this
|
|
16
|
+
_Store_instances.add(this);
|
|
17
|
+
_Store_temp.set(this, void 0);
|
|
18
|
+
_Store_backUpDefaultStorage.set(this, void 0);
|
|
19
|
+
_Store_static.set(this, void 0);
|
|
20
|
+
__classPrivateFieldSet(this, _Store_backUpDefaultStorage, deepClone(opts.defaultStorage), "f");
|
|
21
|
+
__classPrivateFieldSet(this, _Store_temp, __classPrivateFieldGet(this, _Store_instances, "m", _Store_createTempStorage).call(this), "f");
|
|
22
|
+
__classPrivateFieldSet(this, _Store_static, opts.defaultStatic || {}, "f");
|
|
6
23
|
}
|
|
7
24
|
set(name, value) {
|
|
8
|
-
this
|
|
25
|
+
__classPrivateFieldGet(this, _Store_temp, "f")[name] = value;
|
|
9
26
|
}
|
|
10
27
|
get(name) {
|
|
11
|
-
return this
|
|
28
|
+
return __classPrivateFieldGet(this, _Store_temp, "f")[name];
|
|
12
29
|
}
|
|
13
|
-
|
|
14
|
-
|
|
30
|
+
setStatic(name, value) {
|
|
31
|
+
__classPrivateFieldGet(this, _Store_static, "f")[name] = value;
|
|
32
|
+
}
|
|
33
|
+
getStatic(name) {
|
|
34
|
+
return __classPrivateFieldGet(this, _Store_static, "f")[name];
|
|
35
|
+
}
|
|
36
|
+
getSnapshot(opts) {
|
|
37
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.deepClone) === true) {
|
|
38
|
+
return deepClone(__classPrivateFieldGet(this, _Store_temp, "f"));
|
|
39
|
+
}
|
|
40
|
+
return Object.assign({}, __classPrivateFieldGet(this, _Store_temp, "f"));
|
|
15
41
|
}
|
|
16
42
|
clear() {
|
|
17
|
-
this
|
|
43
|
+
__classPrivateFieldSet(this, _Store_temp, __classPrivateFieldGet(this, _Store_instances, "m", _Store_createTempStorage).call(this), "f");
|
|
18
44
|
}
|
|
19
|
-
|
|
20
|
-
|
|
45
|
+
destroy() {
|
|
46
|
+
__classPrivateFieldSet(this, _Store_temp, null, "f");
|
|
47
|
+
__classPrivateFieldSet(this, _Store_static, null, "f");
|
|
21
48
|
}
|
|
22
49
|
}
|
|
50
|
+
_Store_temp = new WeakMap(), _Store_backUpDefaultStorage = new WeakMap(), _Store_static = new WeakMap(), _Store_instances = new WeakSet(), _Store_createTempStorage = function _Store_createTempStorage() {
|
|
51
|
+
return deepClone(__classPrivateFieldGet(this, _Store_backUpDefaultStorage, "f"));
|
|
52
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function enhanceFontFamliy(fontFamily?: string): string;
|
package/dist/esm/lib/time.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ type Middleware = (ctx: any, next: Middleware) => any;
|
|
|
2
2
|
export declare function compose(middleware: Middleware[]): (context: any, next?: Middleware) => any;
|
|
3
3
|
export declare function delay(time: number): Promise<void>;
|
|
4
4
|
export declare function throttle(fn: (...args: any[]) => any, timeout: number): (...args: any[]) => any;
|
|
5
|
+
export declare function debounce(fn: (...args: any[]) => any, timeout: number): (...args: any[]) => any;
|
|
5
6
|
export {};
|
package/dist/esm/lib/time.js
CHANGED
|
@@ -27,7 +27,7 @@ export function delay(time) {
|
|
|
27
27
|
export function throttle(fn, timeout) {
|
|
28
28
|
let timer = -1;
|
|
29
29
|
return function (...args) {
|
|
30
|
-
if (timer
|
|
30
|
+
if (timer >= 0) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
timer = setTimeout(() => {
|
|
@@ -36,3 +36,15 @@ export function throttle(fn, timeout) {
|
|
|
36
36
|
}, timeout);
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
export function debounce(fn, timeout) {
|
|
40
|
+
let timer = -1;
|
|
41
|
+
return function (...args) {
|
|
42
|
+
if (timer >= 0) {
|
|
43
|
+
window.clearTimeout(timer);
|
|
44
|
+
}
|
|
45
|
+
timer = setTimeout(() => {
|
|
46
|
+
fn(...args);
|
|
47
|
+
timer = -1;
|
|
48
|
+
}, timeout);
|
|
49
|
+
};
|
|
50
|
+
}
|
package/dist/esm/lib/view-box.js
CHANGED
|
@@ -4,8 +4,10 @@ export function calcViewBoxSize(viewElem, opts) {
|
|
|
4
4
|
const { viewScaleInfo } = opts;
|
|
5
5
|
const { scale } = viewScaleInfo;
|
|
6
6
|
let { borderRadius } = viewElem.detail;
|
|
7
|
+
const { borderDash } = viewElem.detail;
|
|
8
|
+
const hasBorderDash = Array.isArray(borderDash) && borderDash.length > 0;
|
|
7
9
|
const { boxSizing = defaultElemConfig.boxSizing, borderWidth } = viewElem.detail;
|
|
8
|
-
if (
|
|
10
|
+
if (Array.isArray(borderWidth)) {
|
|
9
11
|
borderRadius = 0;
|
|
10
12
|
}
|
|
11
13
|
let { x, y, w, h } = viewElem;
|
|
@@ -21,7 +23,7 @@ export function calcViewBoxSize(viewElem, opts) {
|
|
|
21
23
|
if (typeof borderWidth === 'number') {
|
|
22
24
|
bw = (borderWidth || 0) * scale;
|
|
23
25
|
}
|
|
24
|
-
if (boxSizing === 'border-box') {
|
|
26
|
+
if (boxSizing === 'border-box' && !hasBorderDash) {
|
|
25
27
|
x = viewElem.x + bw / 2;
|
|
26
28
|
y = viewElem.y + bw / 2;
|
|
27
29
|
w = viewElem.w - bw;
|