@idraw/util 0.3.1 → 0.4.0-alpha.2
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 +26 -71
- package/dist/esm/index.js +26 -29
- package/dist/esm/lib/canvas.d.ts +15 -0
- package/dist/esm/lib/canvas.js +36 -0
- package/dist/esm/lib/check.d.ts +8 -8
- package/dist/esm/lib/check.js +32 -33
- package/dist/esm/lib/color.d.ts +1 -0
- package/dist/esm/lib/color.js +152 -1
- package/dist/esm/lib/context2d.d.ts +75 -0
- package/dist/esm/lib/context2d.js +226 -0
- package/dist/esm/lib/controller.d.ts +6 -0
- package/dist/esm/lib/controller.js +99 -0
- package/dist/esm/lib/data.d.ts +5 -1
- package/dist/esm/lib/data.js +67 -2
- package/dist/esm/lib/element.d.ts +18 -0
- package/dist/esm/lib/element.js +241 -0
- package/dist/esm/lib/event.d.ts +9 -0
- package/dist/esm/lib/event.js +50 -0
- package/dist/esm/lib/html.d.ts +3 -0
- package/dist/esm/lib/html.js +170 -0
- package/dist/esm/lib/image.d.ts +4 -0
- package/dist/esm/lib/image.js +27 -0
- package/dist/esm/lib/is.d.ts +4 -2
- package/dist/esm/lib/is.js +34 -15
- package/dist/esm/lib/istype.d.ts +1 -2
- package/dist/esm/lib/istype.js +3 -4
- package/dist/esm/lib/{loader.js → load.js} +2 -2
- package/dist/esm/lib/middleware.d.ts +3 -0
- package/dist/esm/lib/middleware.js +22 -0
- package/dist/esm/lib/number.d.ts +3 -0
- package/dist/esm/lib/number.js +4 -0
- package/dist/esm/lib/parser.js +4 -1
- package/dist/esm/lib/point.d.ts +8 -0
- package/dist/esm/lib/point.js +30 -0
- package/dist/esm/lib/rect.d.ts +2 -0
- package/dist/esm/lib/rect.js +11 -0
- package/dist/esm/lib/rotate.d.ts +13 -0
- package/dist/esm/lib/rotate.js +205 -0
- package/dist/esm/lib/store.d.ts +12 -0
- package/dist/esm/lib/store.js +22 -0
- package/dist/esm/lib/svg-path.d.ts +10 -0
- package/dist/esm/lib/svg-path.js +36 -0
- package/dist/esm/lib/uuid.d.ts +2 -0
- package/dist/esm/lib/uuid.js +27 -2
- package/dist/esm/lib/vertex.d.ts +10 -0
- package/dist/esm/lib/vertex.js +73 -0
- package/dist/esm/lib/view-calc.d.ts +49 -0
- package/dist/esm/lib/view-calc.js +167 -0
- package/dist/index.global.js +1706 -330
- package/dist/index.global.min.js +1 -1
- package/package.json +4 -4
- package/LICENSE +0 -21
- package/dist/esm/lib/context.d.ts +0 -80
- package/dist/esm/lib/context.js +0 -194
- /package/dist/esm/lib/{loader.d.ts → load.d.ts} +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export class EventEmitter {
|
|
2
|
+
constructor() {
|
|
3
|
+
this._listeners = new Map();
|
|
4
|
+
}
|
|
5
|
+
on(eventKey, callback) {
|
|
6
|
+
if (this._listeners.has(eventKey)) {
|
|
7
|
+
const callbacks = this._listeners.get(eventKey) || [];
|
|
8
|
+
callbacks === null || callbacks === void 0 ? void 0 : callbacks.push(callback);
|
|
9
|
+
this._listeners.set(eventKey, callbacks);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
this._listeners.set(eventKey, [callback]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
off(eventKey, callback) {
|
|
16
|
+
if (this._listeners.has(eventKey)) {
|
|
17
|
+
const callbacks = this._listeners.get(eventKey);
|
|
18
|
+
if (Array.isArray(callbacks)) {
|
|
19
|
+
for (let i = 0; i < (callbacks === null || callbacks === void 0 ? void 0 : callbacks.length); i++) {
|
|
20
|
+
if (callbacks[i] === callback) {
|
|
21
|
+
callbacks.splice(i, 1);
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
this._listeners.set(eventKey, callbacks || []);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
trigger(eventKey, e) {
|
|
30
|
+
const callbacks = this._listeners.get(eventKey);
|
|
31
|
+
if (Array.isArray(callbacks)) {
|
|
32
|
+
callbacks.forEach((cb) => {
|
|
33
|
+
cb(e);
|
|
34
|
+
});
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
has(name) {
|
|
42
|
+
if (this._listeners.has(name)) {
|
|
43
|
+
const list = this._listeners.get(name);
|
|
44
|
+
if (Array.isArray(list) && list.length > 0) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
const attrRegExp = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;
|
|
2
|
+
const elemRegExp = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g;
|
|
3
|
+
const whitespaceReg = /^\s*$/;
|
|
4
|
+
const singleElements = {};
|
|
5
|
+
function parseElement(element) {
|
|
6
|
+
const node = {
|
|
7
|
+
type: 'element',
|
|
8
|
+
name: '',
|
|
9
|
+
isVoid: false,
|
|
10
|
+
attributes: {},
|
|
11
|
+
children: []
|
|
12
|
+
};
|
|
13
|
+
const elementMatch = element.match(/<\/?([^\s]+?)[/\s>]/);
|
|
14
|
+
if (elementMatch) {
|
|
15
|
+
node.name = elementMatch[1];
|
|
16
|
+
if (singleElements[elementMatch[1]] || element.charAt(element.length - 2) === '/') {
|
|
17
|
+
node.isVoid = true;
|
|
18
|
+
}
|
|
19
|
+
if (node.name.startsWith('!--')) {
|
|
20
|
+
const endIndex = element.indexOf('-->');
|
|
21
|
+
return {
|
|
22
|
+
type: 'comment',
|
|
23
|
+
name: null,
|
|
24
|
+
attributes: {},
|
|
25
|
+
children: [],
|
|
26
|
+
isVoid: false,
|
|
27
|
+
comment: endIndex !== -1 ? element.slice(4, endIndex) : ''
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const reg = new RegExp(attrRegExp);
|
|
32
|
+
let result = null;
|
|
33
|
+
while (true) {
|
|
34
|
+
result = reg.exec(element);
|
|
35
|
+
if (result === null) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
if (!result[0].trim()) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (result[1]) {
|
|
42
|
+
const attr = result[1].trim();
|
|
43
|
+
let arr = [attr, ''];
|
|
44
|
+
if (attr.indexOf('=') > -1) {
|
|
45
|
+
arr = attr.split('=');
|
|
46
|
+
}
|
|
47
|
+
node.attributes[arr[0]] = arr[1];
|
|
48
|
+
reg.lastIndex--;
|
|
49
|
+
}
|
|
50
|
+
else if (result[2]) {
|
|
51
|
+
node.attributes[result[2]] = result[3].trim().substring(1, result[3].length - 1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return node;
|
|
55
|
+
}
|
|
56
|
+
export function parseHTML(html) {
|
|
57
|
+
const result = [];
|
|
58
|
+
const arr = [];
|
|
59
|
+
let current;
|
|
60
|
+
let level = -1;
|
|
61
|
+
let inComponent = false;
|
|
62
|
+
html.replace(elemRegExp, (element, index) => {
|
|
63
|
+
if (inComponent && !Array.isArray(current)) {
|
|
64
|
+
if (element !== '</' + current.name + '>') {
|
|
65
|
+
return element;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
inComponent = false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const isOpen = element.charAt(1) !== '/';
|
|
72
|
+
const isComment = element.startsWith('<!--');
|
|
73
|
+
const start = index + element.length;
|
|
74
|
+
const nextChar = html.charAt(start);
|
|
75
|
+
let parent;
|
|
76
|
+
if (isComment) {
|
|
77
|
+
const comment = parseElement(element);
|
|
78
|
+
if (level < 0) {
|
|
79
|
+
result.push(comment);
|
|
80
|
+
return element;
|
|
81
|
+
}
|
|
82
|
+
parent = arr[level];
|
|
83
|
+
parent.children.push(comment);
|
|
84
|
+
return element;
|
|
85
|
+
}
|
|
86
|
+
if (isOpen) {
|
|
87
|
+
level++;
|
|
88
|
+
current = parseElement(element);
|
|
89
|
+
if (!current.isVoid && !inComponent && nextChar && nextChar !== '<') {
|
|
90
|
+
const content = html.slice(start, html.indexOf('<', start));
|
|
91
|
+
if (content.trim()) {
|
|
92
|
+
current.children.push({
|
|
93
|
+
type: 'text',
|
|
94
|
+
name: null,
|
|
95
|
+
attributes: {},
|
|
96
|
+
children: [],
|
|
97
|
+
isVoid: false,
|
|
98
|
+
textContent: content.trim()
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (level === 0) {
|
|
103
|
+
result.push(current);
|
|
104
|
+
}
|
|
105
|
+
parent = arr[level - 1];
|
|
106
|
+
if (parent) {
|
|
107
|
+
parent.children.push(current);
|
|
108
|
+
}
|
|
109
|
+
arr[level] = current;
|
|
110
|
+
}
|
|
111
|
+
if (!isOpen || (!Array.isArray(current) && current.isVoid)) {
|
|
112
|
+
if (level > -1 && !Array.isArray(current) && (current.isVoid || current.name === element.slice(2, -1))) {
|
|
113
|
+
level--;
|
|
114
|
+
current = level === -1 ? result : arr[level];
|
|
115
|
+
}
|
|
116
|
+
if (!inComponent && nextChar !== '<' && nextChar) {
|
|
117
|
+
parent = level === -1 ? result : arr[level].children;
|
|
118
|
+
const end = html.indexOf('<', start);
|
|
119
|
+
let content = html.slice(start, end === -1 ? undefined : end);
|
|
120
|
+
if (whitespaceReg.test(content)) {
|
|
121
|
+
content = ' ';
|
|
122
|
+
}
|
|
123
|
+
if ((end > -1 && level + parent.length >= 0) || content !== ' ') {
|
|
124
|
+
if (content.trim()) {
|
|
125
|
+
parent.push({
|
|
126
|
+
type: 'text',
|
|
127
|
+
name: null,
|
|
128
|
+
attributes: {},
|
|
129
|
+
children: [],
|
|
130
|
+
isVoid: false,
|
|
131
|
+
textContent: content.trim()
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return element;
|
|
138
|
+
});
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
function attrString(attrs) {
|
|
142
|
+
const buff = [];
|
|
143
|
+
for (let key in attrs) {
|
|
144
|
+
buff.push(key + '="' + attrs[key] + '"');
|
|
145
|
+
}
|
|
146
|
+
if (!buff.length) {
|
|
147
|
+
return '';
|
|
148
|
+
}
|
|
149
|
+
return ' ' + buff.join(' ');
|
|
150
|
+
}
|
|
151
|
+
function stringify(buff, htmlNode) {
|
|
152
|
+
switch (htmlNode.type) {
|
|
153
|
+
case 'text':
|
|
154
|
+
return buff + htmlNode.textContent;
|
|
155
|
+
case 'element':
|
|
156
|
+
buff += '<' + htmlNode.name + (htmlNode.attributes ? attrString(htmlNode.attributes) : '') + (htmlNode.isVoid ? '/>' : '>');
|
|
157
|
+
if (htmlNode.isVoid) {
|
|
158
|
+
return buff;
|
|
159
|
+
}
|
|
160
|
+
return buff + htmlNode.children.reduce(stringify, '') + '</' + htmlNode.name + '>';
|
|
161
|
+
case 'comment':
|
|
162
|
+
buff += '<!--' + htmlNode.comment + '-->';
|
|
163
|
+
return buff;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export function generateHTML(htmlNodes) {
|
|
167
|
+
return htmlNodes.reduce(function (token, rootEl) {
|
|
168
|
+
return token + stringify('', rootEl);
|
|
169
|
+
}, '');
|
|
170
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function compressImage(src, opts) {
|
|
2
|
+
let radio = 0.5;
|
|
3
|
+
const type = (opts === null || opts === void 0 ? void 0 : opts.type) || 'image/png';
|
|
4
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.radio) && (opts === null || opts === void 0 ? void 0 : opts.radio) > 0 && (opts === null || opts === void 0 ? void 0 : opts.radio) <= 1) {
|
|
5
|
+
radio = opts === null || opts === void 0 ? void 0 : opts.radio;
|
|
6
|
+
}
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const image = new Image();
|
|
9
|
+
image.addEventListener('load', () => {
|
|
10
|
+
const { width, height } = image;
|
|
11
|
+
const resultW = width * radio;
|
|
12
|
+
const resultH = height * radio;
|
|
13
|
+
let canvas = document.createElement('canvas');
|
|
14
|
+
canvas.width = resultW;
|
|
15
|
+
canvas.height = resultH;
|
|
16
|
+
const ctx = canvas.getContext('2d');
|
|
17
|
+
ctx.drawImage(image, 0, 0, resultW, resultH);
|
|
18
|
+
const base64 = canvas.toDataURL(type);
|
|
19
|
+
canvas = null;
|
|
20
|
+
resolve(base64);
|
|
21
|
+
});
|
|
22
|
+
image.addEventListener('error', (err) => {
|
|
23
|
+
reject(err);
|
|
24
|
+
});
|
|
25
|
+
image.src = src;
|
|
26
|
+
});
|
|
27
|
+
}
|
package/dist/esm/lib/is.d.ts
CHANGED
|
@@ -19,13 +19,15 @@ declare function strokeWidth(value: any): boolean;
|
|
|
19
19
|
declare function textAlign(value: any): boolean;
|
|
20
20
|
declare function fontFamily(value: any): boolean;
|
|
21
21
|
declare function fontWeight(value: any): boolean;
|
|
22
|
-
declare
|
|
22
|
+
declare function numberStr(value: any): boolean;
|
|
23
|
+
export declare const is: {
|
|
23
24
|
x: typeof x;
|
|
24
25
|
y: typeof y;
|
|
25
26
|
w: typeof w;
|
|
26
27
|
h: typeof h;
|
|
27
28
|
angle: typeof angle;
|
|
28
29
|
number: typeof number;
|
|
30
|
+
numberStr: typeof numberStr;
|
|
29
31
|
borderWidth: typeof borderWidth;
|
|
30
32
|
borderRadius: typeof borderRadius;
|
|
31
33
|
color: typeof color;
|
|
@@ -42,4 +44,4 @@ declare const is: {
|
|
|
42
44
|
fontWeight: typeof fontWeight;
|
|
43
45
|
strokeWidth: typeof strokeWidth;
|
|
44
46
|
};
|
|
45
|
-
export
|
|
47
|
+
export {};
|
package/dist/esm/lib/is.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isColorStr } from './color';
|
|
2
2
|
function number(value) {
|
|
3
|
-
return
|
|
3
|
+
return typeof value === 'number' && (value > 0 || value <= 0);
|
|
4
4
|
}
|
|
5
5
|
function x(value) {
|
|
6
6
|
return number(value);
|
|
@@ -9,13 +9,13 @@ function y(value) {
|
|
|
9
9
|
return number(value);
|
|
10
10
|
}
|
|
11
11
|
function w(value) {
|
|
12
|
-
return
|
|
12
|
+
return typeof value === 'number' && value >= 0;
|
|
13
13
|
}
|
|
14
14
|
function h(value) {
|
|
15
|
-
return
|
|
15
|
+
return typeof value === 'number' && value >= 0;
|
|
16
16
|
}
|
|
17
17
|
function angle(value) {
|
|
18
|
-
return
|
|
18
|
+
return typeof value === 'number' && value >= -360 && value <= 360;
|
|
19
19
|
}
|
|
20
20
|
function borderWidth(value) {
|
|
21
21
|
return w(value);
|
|
@@ -27,16 +27,16 @@ function color(value) {
|
|
|
27
27
|
return isColorStr(value);
|
|
28
28
|
}
|
|
29
29
|
function imageURL(value) {
|
|
30
|
-
return
|
|
30
|
+
return typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${value}`);
|
|
31
31
|
}
|
|
32
32
|
function imageBase64(value) {
|
|
33
|
-
return
|
|
33
|
+
return typeof value === 'string' && /^(data:image\/)/.test(`${value}`);
|
|
34
34
|
}
|
|
35
35
|
function imageSrc(value) {
|
|
36
|
-
return
|
|
36
|
+
return imageBase64(value) || imageURL(value);
|
|
37
37
|
}
|
|
38
38
|
function svg(value) {
|
|
39
|
-
return
|
|
39
|
+
return typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test(`${value}`.trim()) && /<\/[\s]{0,}svg>$/i.test(`${value}`.trim());
|
|
40
40
|
}
|
|
41
41
|
function html(value) {
|
|
42
42
|
let result = false;
|
|
@@ -71,11 +71,30 @@ function fontFamily(value) {
|
|
|
71
71
|
function fontWeight(value) {
|
|
72
72
|
return ['bold'].includes(value);
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
function numberStr(value) {
|
|
75
|
+
return /^(-?\d+(?:\.\d+)?)$/.test(`${value}`);
|
|
76
|
+
}
|
|
77
|
+
export const is = {
|
|
78
|
+
x,
|
|
79
|
+
y,
|
|
80
|
+
w,
|
|
81
|
+
h,
|
|
82
|
+
angle,
|
|
83
|
+
number,
|
|
84
|
+
numberStr,
|
|
85
|
+
borderWidth,
|
|
86
|
+
borderRadius,
|
|
87
|
+
color,
|
|
88
|
+
imageSrc,
|
|
89
|
+
imageURL,
|
|
90
|
+
imageBase64,
|
|
91
|
+
svg,
|
|
92
|
+
html,
|
|
93
|
+
text,
|
|
94
|
+
fontSize,
|
|
95
|
+
lineHeight,
|
|
96
|
+
textAlign,
|
|
97
|
+
fontFamily,
|
|
98
|
+
fontWeight,
|
|
99
|
+
strokeWidth
|
|
80
100
|
};
|
|
81
|
-
export default is;
|
package/dist/esm/lib/istype.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const istype: {
|
|
1
|
+
export declare const istype: {
|
|
2
2
|
type(data: any, lowerCase?: boolean): string;
|
|
3
3
|
array(data: any): boolean;
|
|
4
4
|
json(data: any): boolean;
|
|
@@ -10,4 +10,3 @@ declare const istype: {
|
|
|
10
10
|
null(data: any): boolean;
|
|
11
11
|
promise(data: any): boolean;
|
|
12
12
|
};
|
|
13
|
-
export default istype;
|
package/dist/esm/lib/istype.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
function parsePrototype(data) {
|
|
2
2
|
const typeStr = Object.prototype.toString.call(data) || '';
|
|
3
|
-
const result = typeStr.replace(/(\[object|\])/
|
|
3
|
+
const result = typeStr.replace(/(\[object|\])/gi, '').trim();
|
|
4
4
|
return result;
|
|
5
5
|
}
|
|
6
|
-
const istype = {
|
|
6
|
+
export const istype = {
|
|
7
7
|
type(data, lowerCase) {
|
|
8
8
|
const result = parsePrototype(data);
|
|
9
9
|
return lowerCase === true ? result.toLocaleLowerCase() : result;
|
|
@@ -34,6 +34,5 @@ const istype = {
|
|
|
34
34
|
},
|
|
35
35
|
promise(data) {
|
|
36
36
|
return parsePrototype(data) === 'Promise';
|
|
37
|
-
}
|
|
37
|
+
}
|
|
38
38
|
};
|
|
39
|
-
export default istype;
|
|
@@ -11,7 +11,7 @@ import { parseHTMLToDataURL, parseSVGToDataURL } from './parser';
|
|
|
11
11
|
const { Image } = window;
|
|
12
12
|
export function loadImage(src) {
|
|
13
13
|
return new Promise((resolve, reject) => {
|
|
14
|
-
const img = new Image;
|
|
14
|
+
const img = new Image();
|
|
15
15
|
img.crossOrigin = 'anonymous';
|
|
16
16
|
img.onload = function () {
|
|
17
17
|
resolve(img);
|
|
@@ -29,7 +29,7 @@ export function loadSVG(svg) {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
function filterAmpersand(str) {
|
|
32
|
-
return str.replace(/\&/
|
|
32
|
+
return str.replace(/\&/gi, '&');
|
|
33
33
|
}
|
|
34
34
|
export function loadHTML(html, opts) {
|
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BoardViewerFrameSnapshot, ViewScaleInfo, ViewSizeInfo } from '@idraw/types';
|
|
2
|
+
export declare function getViewScaleInfoFromSnapshot(snapshot: BoardViewerFrameSnapshot): ViewScaleInfo;
|
|
3
|
+
export declare function getViewSizeInfoFromSnapshot(snapshot: BoardViewerFrameSnapshot): ViewSizeInfo;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function getViewScaleInfoFromSnapshot(snapshot) {
|
|
2
|
+
const { activeStore } = snapshot;
|
|
3
|
+
const sacelInfo = {
|
|
4
|
+
scale: activeStore === null || activeStore === void 0 ? void 0 : activeStore.scale,
|
|
5
|
+
offsetTop: activeStore === null || activeStore === void 0 ? void 0 : activeStore.offsetTop,
|
|
6
|
+
offsetBottom: activeStore === null || activeStore === void 0 ? void 0 : activeStore.offsetBottom,
|
|
7
|
+
offsetLeft: activeStore === null || activeStore === void 0 ? void 0 : activeStore.offsetLeft,
|
|
8
|
+
offsetRight: activeStore === null || activeStore === void 0 ? void 0 : activeStore.offsetRight
|
|
9
|
+
};
|
|
10
|
+
return sacelInfo;
|
|
11
|
+
}
|
|
12
|
+
export function getViewSizeInfoFromSnapshot(snapshot) {
|
|
13
|
+
const { activeStore } = snapshot;
|
|
14
|
+
const sacelInfo = {
|
|
15
|
+
devicePixelRatio: activeStore.devicePixelRatio,
|
|
16
|
+
width: activeStore === null || activeStore === void 0 ? void 0 : activeStore.width,
|
|
17
|
+
height: activeStore === null || activeStore === void 0 ? void 0 : activeStore.height,
|
|
18
|
+
contextWidth: activeStore === null || activeStore === void 0 ? void 0 : activeStore.contextWidth,
|
|
19
|
+
contextHeight: activeStore === null || activeStore === void 0 ? void 0 : activeStore.contextHeight
|
|
20
|
+
};
|
|
21
|
+
return sacelInfo;
|
|
22
|
+
}
|
package/dist/esm/lib/parser.js
CHANGED
|
@@ -2,7 +2,10 @@ export function parseHTMLToDataURL(html, opts) {
|
|
|
2
2
|
const { width, height } = opts;
|
|
3
3
|
return new Promise((resolve, reject) => {
|
|
4
4
|
const _svg = `
|
|
5
|
-
<svg
|
|
5
|
+
<svg
|
|
6
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
7
|
+
width="${width || ''}"
|
|
8
|
+
height = "${height || ''}">
|
|
6
9
|
<foreignObject width="100%" height="100%">
|
|
7
10
|
<div xmlns = "http://www.w3.org/1999/xhtml">
|
|
8
11
|
${html}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Point, PointSize, TouchPoint } from '@idraw/types';
|
|
2
|
+
export declare function calcDistance(start: PointSize, end: PointSize): number;
|
|
3
|
+
export declare function calcSpeed(start: Point, end: Point): number;
|
|
4
|
+
export declare function equalPoint(p1: Point, p2: Point): boolean;
|
|
5
|
+
export declare function equalTouchPoint(p1: TouchPoint, p2: TouchPoint): boolean;
|
|
6
|
+
export declare function vaildPoint(p: Point): boolean;
|
|
7
|
+
export declare function vaildTouchPoint(p: TouchPoint): boolean;
|
|
8
|
+
export declare function getCenterFromTwoPoints(p1: PointSize, p2: PointSize): PointSize;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function calcDistance(start, end) {
|
|
2
|
+
const distance = (start.x - end.x) * (start.x - end.x) + (start.y - end.y) * (start.y - end.y);
|
|
3
|
+
return distance === 0 ? distance : Math.sqrt(distance);
|
|
4
|
+
}
|
|
5
|
+
export function calcSpeed(start, end) {
|
|
6
|
+
const distance = calcDistance(start, end);
|
|
7
|
+
const speed = distance / Math.abs(end.t - start.t);
|
|
8
|
+
return speed;
|
|
9
|
+
}
|
|
10
|
+
export function equalPoint(p1, p2) {
|
|
11
|
+
return p1.x === p2.x && p1.y === p2.y && p1.t === p2.t;
|
|
12
|
+
}
|
|
13
|
+
export function equalTouchPoint(p1, p2) {
|
|
14
|
+
return equalPoint(p1, p2) === true && p1.f === p2.f;
|
|
15
|
+
}
|
|
16
|
+
function isNum(num) {
|
|
17
|
+
return num >= 0 || num < 0;
|
|
18
|
+
}
|
|
19
|
+
export function vaildPoint(p) {
|
|
20
|
+
return isNum(p.x) && isNum(p.y) && p.t > 0;
|
|
21
|
+
}
|
|
22
|
+
export function vaildTouchPoint(p) {
|
|
23
|
+
return vaildPoint(p) === true && p.f >= 0;
|
|
24
|
+
}
|
|
25
|
+
export function getCenterFromTwoPoints(p1, p2) {
|
|
26
|
+
return {
|
|
27
|
+
x: p1.x + (p2.x - p1.x) / 2,
|
|
28
|
+
y: p1.y + (p2.y - p1.y) / 2
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function checkRectIntersect(rect1, rect2) {
|
|
2
|
+
const react1MinX = rect1.x;
|
|
3
|
+
const react1MinY = rect1.y;
|
|
4
|
+
const react1MaxX = rect1.x + rect1.w;
|
|
5
|
+
const react1MaxY = rect1.y + rect1.h;
|
|
6
|
+
const react2MinX = rect2.x;
|
|
7
|
+
const react2MinY = rect2.y;
|
|
8
|
+
const react2MaxX = rect2.x + rect2.w;
|
|
9
|
+
const react2MaxY = rect2.y + rect2.h;
|
|
10
|
+
return react1MinX <= react2MaxX && react1MaxX >= react2MinX && react1MinY <= react2MaxY && react1MaxY >= react2MinY;
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ViewContext2D, PointSize, ElementSize, ViewRectVertexes, Element } from '@idraw/types';
|
|
2
|
+
export declare function parseRadianToAngle(radian: number): number;
|
|
3
|
+
export declare function parseAngleToRadian(angle: number): number;
|
|
4
|
+
export declare function rotateElement(ctx: ViewContext2D | CanvasRenderingContext2D | ViewContext2D, elemSize: ElementSize, callback: (ctx: ViewContext2D | CanvasRenderingContext2D) => void): void;
|
|
5
|
+
export declare function calcElementCenter(elem: ElementSize): PointSize;
|
|
6
|
+
export declare function calcElementCenterFromVertexes(ves: ViewRectVertexes): PointSize;
|
|
7
|
+
export declare function calcRadian(center: PointSize, start: PointSize, end: PointSize): number;
|
|
8
|
+
export declare function rotatePoint(center: PointSize, start: PointSize, radian: number): PointSize;
|
|
9
|
+
export declare function rotatePointInGroup(point: PointSize, groupQueue: Element<'group'>[]): PointSize;
|
|
10
|
+
export declare function getElementRotateVertexes(elemSize: ElementSize, center: PointSize, angle: number): ViewRectVertexes;
|
|
11
|
+
export declare function rotateElementVertexes(elemSize: ElementSize): ViewRectVertexes;
|
|
12
|
+
export declare function rotateVertexes(center: PointSize, ves: ViewRectVertexes, radian: number): ViewRectVertexes;
|
|
13
|
+
export declare function limitAngle(angle: number): number;
|