@idraw/util 0.4.0-beta.3 → 0.4.0-beta.31
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 +14 -8
- package/dist/esm/index.js +14 -8
- package/dist/esm/lib/canvas.d.ts +6 -1
- package/dist/esm/lib/canvas.js +42 -19
- package/dist/esm/lib/config.d.ts +5 -10
- package/dist/esm/lib/config.js +9 -9
- package/dist/esm/lib/context2d.d.ts +2 -0
- package/dist/esm/lib/context2d.js +14 -0
- package/dist/esm/lib/controller.d.ts +5 -1
- package/dist/esm/lib/controller.js +142 -0
- package/dist/esm/lib/data.d.ts +6 -2
- package/dist/esm/lib/data.js +95 -2
- package/dist/esm/lib/element.d.ts +1 -0
- package/dist/esm/lib/element.js +19 -0
- package/dist/esm/lib/event.d.ts +4 -2
- package/dist/esm/lib/event.js +31 -11
- package/dist/esm/lib/file.d.ts +7 -2
- package/dist/esm/lib/file.js +26 -7
- package/dist/esm/lib/flat.d.ts +2 -0
- package/dist/esm/lib/flat.js +132 -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/istype.d.ts +1 -0
- package/dist/esm/lib/istype.js +3 -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/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/store.d.ts +6 -5
- package/dist/esm/lib/store.js +30 -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 -3
- package/dist/esm/lib/view-calc.d.ts +20 -3
- package/dist/esm/lib/view-calc.js +171 -3
- package/dist/esm/lib/view-content.d.ts +14 -0
- package/dist/esm/lib/view-content.js +88 -0
- package/dist/esm/lib/view-visible.d.ts +21 -0
- package/dist/esm/lib/view-visible.js +93 -0
- package/dist/index.global.js +1272 -176
- package/dist/index.global.min.js +1 -1
- package/package.json +1 -1
|
@@ -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
|
+
}
|
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/store.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
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>> {
|
|
2
|
+
#private;
|
|
4
3
|
constructor(opts: {
|
|
5
4
|
defaultStorage: T;
|
|
6
5
|
});
|
|
7
6
|
set<K extends keyof T>(name: K, value: T[K]): void;
|
|
8
7
|
get<K extends keyof T>(name: K): T[K];
|
|
9
|
-
getSnapshot(
|
|
8
|
+
getSnapshot(opts?: {
|
|
9
|
+
deepClone?: boolean;
|
|
10
|
+
}): T;
|
|
10
11
|
clear(): void;
|
|
11
|
-
|
|
12
|
+
destroy(): void;
|
|
12
13
|
}
|
package/dist/esm/lib/store.js
CHANGED
|
@@ -1,22 +1,43 @@
|
|
|
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_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
|
+
__classPrivateFieldSet(this, _Store_backUpDefaultStorage, deepClone(opts.defaultStorage), "f");
|
|
20
|
+
__classPrivateFieldSet(this, _Store_temp, __classPrivateFieldGet(this, _Store_instances, "m", _Store_createTempStorage).call(this), "f");
|
|
6
21
|
}
|
|
7
22
|
set(name, value) {
|
|
8
|
-
this
|
|
23
|
+
__classPrivateFieldGet(this, _Store_temp, "f")[name] = value;
|
|
9
24
|
}
|
|
10
25
|
get(name) {
|
|
11
|
-
return this
|
|
26
|
+
return __classPrivateFieldGet(this, _Store_temp, "f")[name];
|
|
12
27
|
}
|
|
13
|
-
getSnapshot() {
|
|
14
|
-
|
|
28
|
+
getSnapshot(opts) {
|
|
29
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.deepClone) === true) {
|
|
30
|
+
return deepClone(__classPrivateFieldGet(this, _Store_temp, "f"));
|
|
31
|
+
}
|
|
32
|
+
return Object.assign({}, __classPrivateFieldGet(this, _Store_temp, "f"));
|
|
15
33
|
}
|
|
16
34
|
clear() {
|
|
17
|
-
this
|
|
35
|
+
__classPrivateFieldSet(this, _Store_temp, __classPrivateFieldGet(this, _Store_instances, "m", _Store_createTempStorage).call(this), "f");
|
|
18
36
|
}
|
|
19
|
-
|
|
20
|
-
|
|
37
|
+
destroy() {
|
|
38
|
+
__classPrivateFieldSet(this, _Store_temp, null, "f");
|
|
21
39
|
}
|
|
22
40
|
}
|
|
41
|
+
_Store_temp = new WeakMap(), _Store_backUpDefaultStorage = new WeakMap(), _Store_instances = new WeakSet(), _Store_createTempStorage = function _Store_createTempStorage() {
|
|
42
|
+
return deepClone(__classPrivateFieldGet(this, _Store_backUpDefaultStorage, "f"));
|
|
43
|
+
};
|
|
@@ -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
|
@@ -3,9 +3,10 @@ const defaultElemConfig = getDefaultElementDetailConfig();
|
|
|
3
3
|
export function calcViewBoxSize(viewElem, opts) {
|
|
4
4
|
const { viewScaleInfo } = opts;
|
|
5
5
|
const { scale } = viewScaleInfo;
|
|
6
|
-
let { borderRadius } = viewElem.detail;
|
|
6
|
+
let { borderRadius, borderDash } = viewElem.detail;
|
|
7
|
+
const hasBorderDash = Array.isArray(borderDash) && borderDash.length > 0;
|
|
7
8
|
const { boxSizing = defaultElemConfig.boxSizing, borderWidth } = viewElem.detail;
|
|
8
|
-
if (
|
|
9
|
+
if (Array.isArray(borderWidth)) {
|
|
9
10
|
borderRadius = 0;
|
|
10
11
|
}
|
|
11
12
|
let { x, y, w, h } = viewElem;
|
|
@@ -21,7 +22,7 @@ export function calcViewBoxSize(viewElem, opts) {
|
|
|
21
22
|
if (typeof borderWidth === 'number') {
|
|
22
23
|
bw = (borderWidth || 0) * scale;
|
|
23
24
|
}
|
|
24
|
-
if (boxSizing === 'border-box') {
|
|
25
|
+
if (boxSizing === 'border-box' && !hasBorderDash) {
|
|
25
26
|
x = viewElem.x + bw / 2;
|
|
26
27
|
y = viewElem.y + bw / 2;
|
|
27
28
|
w = viewElem.w - bw;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Point, PointSize, Data, ViewScaleInfo, ViewSizeInfo, Element, ElementType, ElementSize, ViewContext2D, ViewRectVertexes } from '@idraw/types';
|
|
1
|
+
import { Point, PointSize, Data, ViewScaleInfo, ViewSizeInfo, Element, ElementType, ElementSize, ViewContext2D, ViewRectVertexes, ViewRectInfo, ViewRectInfoMap } from '@idraw/types';
|
|
2
2
|
export declare function calcViewScaleInfo(info: {
|
|
3
3
|
scale: number;
|
|
4
4
|
offsetX: number;
|
|
@@ -23,11 +23,9 @@ export declare function viewScroll(opts: {
|
|
|
23
23
|
}): ViewScaleInfo;
|
|
24
24
|
export declare function calcViewElementSize(size: ElementSize, opts: {
|
|
25
25
|
viewScaleInfo: ViewScaleInfo;
|
|
26
|
-
viewSizeInfo: ViewSizeInfo;
|
|
27
26
|
}): ElementSize;
|
|
28
27
|
export declare function calcViewPointSize(size: PointSize, opts: {
|
|
29
28
|
viewScaleInfo: ViewScaleInfo;
|
|
30
|
-
viewSizeInfo: ViewSizeInfo;
|
|
31
29
|
}): PointSize;
|
|
32
30
|
export declare function calcViewVertexes(vertexes: ViewRectVertexes, opts: {
|
|
33
31
|
viewScaleInfo: ViewScaleInfo;
|
|
@@ -39,6 +37,12 @@ export declare function isViewPointInElement(p: Point, opts: {
|
|
|
39
37
|
viewScaleInfo: ViewScaleInfo;
|
|
40
38
|
viewSizeInfo: ViewSizeInfo;
|
|
41
39
|
}): boolean;
|
|
40
|
+
export declare function isViewPointInElementSize(p: Point, elemSize: ElementSize, opts?: {
|
|
41
|
+
includeBorder?: boolean;
|
|
42
|
+
}): boolean;
|
|
43
|
+
export declare function isViewPointInVertexes(p: Point, vertexes: ViewRectVertexes, opts?: {
|
|
44
|
+
includeBorder?: boolean;
|
|
45
|
+
}): boolean;
|
|
42
46
|
export declare function getViewPointAtElement(p: Point, opts: {
|
|
43
47
|
context2d: ViewContext2D;
|
|
44
48
|
data: Data;
|
|
@@ -54,3 +58,16 @@ export declare function isElementInView(elem: ElementSize, opts: {
|
|
|
54
58
|
viewScaleInfo: ViewScaleInfo;
|
|
55
59
|
viewSizeInfo: ViewSizeInfo;
|
|
56
60
|
}): boolean;
|
|
61
|
+
export declare function calcElementOriginRectInfo(elemSize: ElementSize, opts: {
|
|
62
|
+
groupQueue: Element<'group'>[];
|
|
63
|
+
}): ViewRectInfo;
|
|
64
|
+
export declare function originRectInfoToRangeRectInfo(originRectInfo: ViewRectInfo): ViewRectInfo;
|
|
65
|
+
export declare function calcElementViewRectInfo(elemSize: ElementSize, opts: {
|
|
66
|
+
groupQueue: Element<'group'>[];
|
|
67
|
+
viewScaleInfo: ViewScaleInfo;
|
|
68
|
+
range?: boolean;
|
|
69
|
+
}): ViewRectInfo;
|
|
70
|
+
export declare function calcElementViewRectInfoMap(elemSize: ElementSize, opts: {
|
|
71
|
+
groupQueue: Element<'group'>[];
|
|
72
|
+
viewScaleInfo: ViewScaleInfo;
|
|
73
|
+
}): ViewRectInfoMap;
|