@idraw/util 0.4.2 → 1.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/converter/data-svg.d.ts +2 -0
- package/dist/esm/converter/data-svg.js +19 -0
- package/dist/esm/converter/material-svg.d.ts +2 -0
- package/dist/esm/converter/material-svg.js +63 -0
- package/dist/esm/converter/svg-material.d.ts +2 -0
- package/dist/esm/converter/svg-material.js +188 -0
- package/dist/esm/index.d.ts +32 -21
- package/dist/esm/index.js +32 -21
- package/dist/esm/static.d.ts +1 -0
- package/dist/esm/static.js +1 -0
- package/dist/esm/tool/file.js +2 -2
- package/dist/esm/tool/html.js +27 -27
- package/dist/esm/tool/id.d.ts +1 -0
- package/dist/esm/tool/id.js +4 -0
- package/dist/esm/tool/image.js +6 -6
- package/dist/esm/tool/path-to-box.d.ts +3 -0
- package/dist/esm/tool/path-to-box.js +353 -0
- package/dist/esm/tool/path-to-command.d.ts +4 -0
- package/dist/esm/tool/path-to-command.js +392 -0
- package/dist/esm/tool/path.d.ts +18 -0
- package/dist/esm/tool/path.js +421 -0
- package/dist/esm/tool/svg-path.d.ts +3 -0
- package/dist/esm/{view → tool}/svg-path.js +4 -16
- package/dist/esm/tool/time.d.ts +2 -2
- package/dist/esm/tool/time.js +4 -4
- package/dist/esm/tool/uuid.d.ts +1 -1
- package/dist/esm/tool/uuid.js +6 -6
- package/dist/esm/view/box.d.ts +0 -2
- package/dist/esm/view/box.js +1 -173
- package/dist/esm/view/canvas.js +3 -3
- package/dist/esm/view/check.d.ts +8 -7
- package/dist/esm/view/check.js +34 -34
- package/dist/esm/view/config.d.ts +0 -9
- package/dist/esm/view/config.js +1 -71
- package/dist/esm/view/context2d.d.ts +10 -3
- package/dist/esm/view/context2d.js +39 -18
- package/dist/esm/view/controller.d.ts +5 -5
- package/dist/esm/view/controller.js +105 -102
- package/dist/esm/view/data.d.ts +2 -2
- package/dist/esm/view/data.js +65 -65
- package/dist/esm/view/dom.d.ts +23 -0
- package/dist/esm/view/dom.js +190 -0
- package/dist/esm/view/flat.d.ts +2 -2
- package/dist/esm/view/flat.js +53 -53
- package/dist/esm/view/group.d.ts +3 -3
- package/dist/esm/view/group.js +25 -28
- package/dist/esm/view/handle-material.d.ts +24 -0
- package/dist/esm/view/{handle-element.js → handle-material.js} +98 -75
- package/dist/esm/view/is.d.ts +10 -12
- package/dist/esm/view/is.js +15 -19
- package/dist/esm/view/load.d.ts +2 -2
- package/dist/esm/view/load.js +7 -7
- package/dist/esm/view/material.d.ts +40 -0
- package/dist/esm/view/material.js +476 -0
- package/dist/esm/view/middleware.d.ts +1 -0
- package/dist/esm/view/middleware.js +14 -2
- package/dist/esm/view/modify-record.d.ts +4 -4
- package/dist/esm/view/modify-record.js +2 -2
- package/dist/esm/view/parser.d.ts +2 -2
- package/dist/esm/view/parser.js +3 -3
- package/dist/esm/view/path.d.ts +2 -0
- package/dist/esm/view/path.js +30 -0
- package/dist/esm/view/point-move-material.d.ts +5 -0
- package/dist/esm/view/{point-move-element.js → point-move-material.js} +6 -6
- package/dist/esm/view/point.d.ts +3 -8
- package/dist/esm/view/point.js +1 -21
- package/dist/esm/view/position.d.ts +9 -9
- package/dist/esm/view/position.js +1 -1
- package/dist/esm/view/rect.d.ts +2 -2
- package/dist/esm/view/rect.js +4 -4
- package/dist/esm/view/resize-material.d.ts +4 -0
- package/dist/esm/view/resize-material.js +266 -0
- package/dist/esm/view/rotate.d.ts +11 -11
- package/dist/esm/view/rotate.js +24 -24
- package/dist/esm/view/static.d.ts +13 -0
- package/dist/esm/view/static.js +89 -0
- package/dist/esm/view/styles.d.ts +11 -0
- package/dist/esm/view/styles.js +78 -0
- package/dist/esm/view/vertex.d.ts +8 -8
- package/dist/esm/view/vertex.js +28 -28
- package/dist/esm/view/view-box.d.ts +2 -6
- package/dist/esm/view/view-box.js +8 -64
- package/dist/esm/view/view-calc.d.ts +23 -20
- package/dist/esm/view/view-calc.js +104 -93
- package/dist/esm/view/view-content.d.ts +2 -2
- package/dist/esm/view/view-content.js +34 -34
- package/dist/index.global.js +3144 -1548
- package/dist/index.global.min.js +1 -1
- package/package.json +1 -1
- package/dist/esm/view/element.d.ts +0 -35
- package/dist/esm/view/element.js +0 -471
- package/dist/esm/view/handle-element.d.ts +0 -24
- package/dist/esm/view/point-move-element.d.ts +0 -5
- package/dist/esm/view/resize-element.d.ts +0 -4
- package/dist/esm/view/resize-element.js +0 -255
- package/dist/esm/view/svg-path.d.ts +0 -10
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
groupQueue:
|
|
1
|
+
import { StrictMaterial, MaterialSize, ViewRectVertexes } from '@idraw/types';
|
|
2
|
+
export declare function getMaterialVertexes(mtrlSize: MaterialSize): ViewRectVertexes;
|
|
3
|
+
export declare function calcMaterialVertexes(mtrlSize: MaterialSize): ViewRectVertexes;
|
|
4
|
+
export declare function calcMaterialQueueVertexesQueueInGroup(groupQueue: MaterialSize[]): ViewRectVertexes[];
|
|
5
|
+
export declare function calcMaterialVertexesQueueInGroup(targetMtrl: MaterialSize, opts: {
|
|
6
|
+
groupQueue: StrictMaterial<'group'>[];
|
|
7
7
|
}): ViewRectVertexes[];
|
|
8
|
-
export declare function
|
|
9
|
-
groupQueue:
|
|
8
|
+
export declare function calcMaterialVertexesInGroup(targetMtrl: MaterialSize, opts: {
|
|
9
|
+
groupQueue: StrictMaterial<'group'>[];
|
|
10
10
|
}): ViewRectVertexes | null;
|
package/dist/esm/view/vertex.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export function
|
|
3
|
-
const { x, y,
|
|
1
|
+
import { getMaterialRotateVertexes, calcMaterialCenter, parseAngleToRadian, rotateVertexes, calcMaterialCenterFromVertexes, } from './rotate';
|
|
2
|
+
export function getMaterialVertexes(mtrlSize) {
|
|
3
|
+
const { x, y, height, width } = mtrlSize;
|
|
4
4
|
return [
|
|
5
5
|
{ x, y },
|
|
6
|
-
{ x: x +
|
|
7
|
-
{ x: x +
|
|
8
|
-
{ x, y: y +
|
|
6
|
+
{ x: x + width, y },
|
|
7
|
+
{ x: x + width, y: y + height },
|
|
8
|
+
{ x, y: y + height },
|
|
9
9
|
];
|
|
10
10
|
}
|
|
11
|
-
export function
|
|
12
|
-
const { x, y,
|
|
11
|
+
export function calcMaterialVertexes(mtrlSize) {
|
|
12
|
+
const { x, y, width, height, angle = 0 } = mtrlSize;
|
|
13
13
|
if (angle === 0) {
|
|
14
|
-
return
|
|
14
|
+
return getMaterialVertexes(mtrlSize);
|
|
15
15
|
}
|
|
16
|
-
return
|
|
16
|
+
return getMaterialRotateVertexes(mtrlSize, calcMaterialCenter({ x, y, width, height, angle }), angle);
|
|
17
17
|
}
|
|
18
|
-
export function
|
|
18
|
+
export function calcMaterialQueueVertexesQueueInGroup(groupQueue) {
|
|
19
19
|
const vesList = [];
|
|
20
20
|
let totalX = 0;
|
|
21
21
|
let totalY = 0;
|
|
22
22
|
const rotateActionList = [];
|
|
23
|
-
const
|
|
24
|
-
for (let i = 0; i <
|
|
25
|
-
const { x, y,
|
|
23
|
+
const mtrlQueue = [...groupQueue];
|
|
24
|
+
for (let i = 0; i < mtrlQueue.length; i++) {
|
|
25
|
+
const { x, y, width, height, angle = 0 } = mtrlQueue[i];
|
|
26
26
|
totalX += x;
|
|
27
27
|
totalY += y;
|
|
28
28
|
let ves;
|
|
29
29
|
if (i === 0) {
|
|
30
|
-
const
|
|
31
|
-
ves =
|
|
30
|
+
const mtrlSize = { x: totalX, y: totalY, width, height, angle };
|
|
31
|
+
ves = calcMaterialVertexes({ x, y, width, height, angle });
|
|
32
32
|
rotateActionList.push({
|
|
33
|
-
center:
|
|
33
|
+
center: calcMaterialCenter(mtrlSize),
|
|
34
34
|
angle,
|
|
35
|
-
radian: parseAngleToRadian(angle)
|
|
35
|
+
radian: parseAngleToRadian(angle),
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
const
|
|
40
|
-
ves =
|
|
39
|
+
const mtrlSize = { x: totalX, y: totalY, width, height, angle };
|
|
40
|
+
ves = getMaterialVertexes(mtrlSize);
|
|
41
41
|
for (let aIdx = 0; aIdx < rotateActionList.length; aIdx++) {
|
|
42
42
|
const { center, radian } = rotateActionList[aIdx];
|
|
43
43
|
ves = rotateVertexes(center, ves, radian);
|
|
44
44
|
}
|
|
45
|
-
const vesCenter =
|
|
45
|
+
const vesCenter = calcMaterialCenterFromVertexes(ves);
|
|
46
46
|
if (angle > 0 || angle < 0) {
|
|
47
47
|
const radian = parseAngleToRadian(angle);
|
|
48
48
|
ves = rotateVertexes(vesCenter, ves, radian);
|
|
@@ -50,24 +50,24 @@ export function calcElementQueueVertexesQueueInGroup(groupQueue) {
|
|
|
50
50
|
rotateActionList.push({
|
|
51
51
|
center: vesCenter,
|
|
52
52
|
angle,
|
|
53
|
-
radian: parseAngleToRadian(angle)
|
|
53
|
+
radian: parseAngleToRadian(angle),
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
vesList.push(ves);
|
|
57
57
|
}
|
|
58
58
|
return vesList;
|
|
59
59
|
}
|
|
60
|
-
export function
|
|
60
|
+
export function calcMaterialVertexesQueueInGroup(targetMtrl, opts) {
|
|
61
61
|
const { groupQueue } = opts;
|
|
62
62
|
if (!(groupQueue.length > 0)) {
|
|
63
|
-
return [
|
|
63
|
+
return [calcMaterialVertexes(targetMtrl)];
|
|
64
64
|
}
|
|
65
|
-
const
|
|
66
|
-
const vesList =
|
|
65
|
+
const mtrlQueue = [...groupQueue, ...[targetMtrl]];
|
|
66
|
+
const vesList = calcMaterialQueueVertexesQueueInGroup(mtrlQueue);
|
|
67
67
|
return vesList;
|
|
68
68
|
}
|
|
69
|
-
export function
|
|
70
|
-
const vesList =
|
|
69
|
+
export function calcMaterialVertexesInGroup(targetMtrl, opts) {
|
|
70
|
+
const vesList = calcMaterialVertexesQueueInGroup(targetMtrl, opts);
|
|
71
71
|
const ves = vesList.pop();
|
|
72
72
|
return ves || null;
|
|
73
73
|
}
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import type { Data,
|
|
2
|
-
export declare function
|
|
3
|
-
viewScaleInfo: ViewScaleInfo;
|
|
4
|
-
viewSizeInfo: ViewSizeInfo;
|
|
5
|
-
}): ViewBoxSize;
|
|
6
|
-
export declare function calcVisiableViewSize(data: Data): Omit<ElementSize, 'angle'>;
|
|
1
|
+
import type { Data, MaterialSize } from '@idraw/types';
|
|
2
|
+
export declare function calcVisiableViewSize(data: Data): Omit<MaterialSize, 'angle'>;
|
|
@@ -1,75 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { calcElementListSize } from './element';
|
|
3
|
-
const defaultElemConfig = getDefaultElementDetailConfig();
|
|
4
|
-
export function calcViewBoxSize(viewElem, opts) {
|
|
5
|
-
const { viewScaleInfo } = opts;
|
|
6
|
-
const { scale } = viewScaleInfo;
|
|
7
|
-
let { borderRadius } = viewElem.detail;
|
|
8
|
-
const { borderDash } = viewElem.detail;
|
|
9
|
-
const hasBorderDash = Array.isArray(borderDash) && borderDash.length > 0;
|
|
10
|
-
const { boxSizing = defaultElemConfig.boxSizing, borderWidth } = viewElem.detail;
|
|
11
|
-
if (Array.isArray(borderWidth)) {
|
|
12
|
-
borderRadius = 0;
|
|
13
|
-
}
|
|
14
|
-
let { x, y, w, h } = viewElem;
|
|
15
|
-
let radiusList = [0, 0, 0, 0];
|
|
16
|
-
if (typeof borderRadius === 'number') {
|
|
17
|
-
const br = borderRadius * scale;
|
|
18
|
-
radiusList = [br, br, br, br];
|
|
19
|
-
}
|
|
20
|
-
else if (Array.isArray(borderRadius) && (borderRadius === null || borderRadius === void 0 ? void 0 : borderRadius.length) === 4) {
|
|
21
|
-
radiusList = [borderRadius[0] * scale, borderRadius[1] * scale, borderRadius[2] * scale, borderRadius[3] * scale];
|
|
22
|
-
}
|
|
23
|
-
let bw = 0;
|
|
24
|
-
if (typeof borderWidth === 'number') {
|
|
25
|
-
bw = (borderWidth || 0) * scale;
|
|
26
|
-
}
|
|
27
|
-
if (boxSizing === 'border-box' && !hasBorderDash) {
|
|
28
|
-
x = viewElem.x + bw / 2;
|
|
29
|
-
y = viewElem.y + bw / 2;
|
|
30
|
-
w = viewElem.w - bw;
|
|
31
|
-
h = viewElem.h - bw;
|
|
32
|
-
}
|
|
33
|
-
else if (boxSizing === 'content-box') {
|
|
34
|
-
x = viewElem.x - bw / 2;
|
|
35
|
-
y = viewElem.y - bw / 2;
|
|
36
|
-
w = viewElem.w + bw;
|
|
37
|
-
h = viewElem.h + bw;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
x = viewElem.x;
|
|
41
|
-
y = viewElem.y;
|
|
42
|
-
w = viewElem.w;
|
|
43
|
-
h = viewElem.h;
|
|
44
|
-
}
|
|
45
|
-
w = Math.max(w, 1);
|
|
46
|
-
h = Math.max(h, 1);
|
|
47
|
-
radiusList = radiusList.map((r) => {
|
|
48
|
-
return Math.min(r, w / 2, h / 2);
|
|
49
|
-
});
|
|
50
|
-
return {
|
|
51
|
-
x,
|
|
52
|
-
y,
|
|
53
|
-
w,
|
|
54
|
-
h,
|
|
55
|
-
radiusList
|
|
56
|
-
};
|
|
57
|
-
}
|
|
1
|
+
import { calcMaterialListSize } from './material';
|
|
58
2
|
export function calcVisiableViewSize(data) {
|
|
59
|
-
var _a
|
|
60
|
-
const outputSize =
|
|
3
|
+
var _a;
|
|
4
|
+
const outputSize = calcMaterialListSize(data.materials);
|
|
61
5
|
if (data.layout) {
|
|
62
|
-
if (((
|
|
6
|
+
if (((_a = data.layout) === null || _a === void 0 ? void 0 : _a.overflow) === 'hidden') {
|
|
63
7
|
outputSize.x = data.layout.x;
|
|
64
8
|
outputSize.y = data.layout.y;
|
|
65
|
-
outputSize.
|
|
66
|
-
outputSize.
|
|
9
|
+
outputSize.width = data.layout.width;
|
|
10
|
+
outputSize.height = data.layout.height;
|
|
67
11
|
}
|
|
68
12
|
else {
|
|
69
13
|
outputSize.x = Math.min(outputSize.x, data.layout.x);
|
|
70
14
|
outputSize.y = Math.min(outputSize.y, data.layout.y);
|
|
71
|
-
outputSize.
|
|
72
|
-
outputSize.
|
|
15
|
+
outputSize.width = Math.max(outputSize.width, data.layout.width);
|
|
16
|
+
outputSize.height = Math.max(outputSize.height, data.layout.height);
|
|
73
17
|
}
|
|
74
18
|
}
|
|
75
19
|
return outputSize;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Point,
|
|
1
|
+
import { Point, Data, ViewScaleInfo, ViewSizeInfo, StrictMaterial, MaterialType, MaterialSize, ViewContext2D, ViewRectVertexes, BoundingInfo } from '@idraw/types';
|
|
2
2
|
export declare function calcViewScaleInfo(info: {
|
|
3
3
|
scale: number;
|
|
4
4
|
offsetX: number;
|
|
@@ -8,7 +8,7 @@ export declare function calcViewScaleInfo(info: {
|
|
|
8
8
|
}): ViewScaleInfo;
|
|
9
9
|
export declare function viewScale(opts: {
|
|
10
10
|
scale: number;
|
|
11
|
-
point:
|
|
11
|
+
point: Point;
|
|
12
12
|
viewScaleInfo: ViewScaleInfo;
|
|
13
13
|
viewSizeInfo: ViewSizeInfo;
|
|
14
14
|
}): {
|
|
@@ -21,49 +21,52 @@ export declare function viewScroll(opts: {
|
|
|
21
21
|
viewScaleInfo: ViewScaleInfo;
|
|
22
22
|
viewSizeInfo: ViewSizeInfo;
|
|
23
23
|
}): ViewScaleInfo;
|
|
24
|
-
export declare function
|
|
24
|
+
export declare function calcViewMaterialSize(size: MaterialSize, opts: {
|
|
25
|
+
viewScaleInfo: Partial<ViewScaleInfo>;
|
|
26
|
+
}): MaterialSize;
|
|
27
|
+
export declare function calcViewPoint(size: Point, opts: {
|
|
25
28
|
viewScaleInfo: ViewScaleInfo;
|
|
26
|
-
}):
|
|
27
|
-
export declare function
|
|
29
|
+
}): Point;
|
|
30
|
+
export declare function calcPointFromView(viewPoint: Point, opts: {
|
|
28
31
|
viewScaleInfo: ViewScaleInfo;
|
|
29
|
-
}):
|
|
32
|
+
}): Point;
|
|
30
33
|
export declare function calcViewVertexes(vertexes: ViewRectVertexes, opts: {
|
|
31
34
|
viewScaleInfo: ViewScaleInfo;
|
|
32
35
|
viewSizeInfo: ViewSizeInfo;
|
|
33
36
|
}): ViewRectVertexes;
|
|
34
|
-
export declare function
|
|
37
|
+
export declare function isViewPointInMaterial(p: Point, opts: {
|
|
35
38
|
context2d: ViewContext2D;
|
|
36
|
-
|
|
39
|
+
material: MaterialSize;
|
|
37
40
|
viewScaleInfo: ViewScaleInfo;
|
|
38
41
|
viewSizeInfo: ViewSizeInfo;
|
|
39
42
|
}): boolean;
|
|
40
|
-
export declare function
|
|
43
|
+
export declare function isViewPointInMaterialSize(p: Point, mtrlSize: MaterialSize, opts?: {
|
|
41
44
|
includeBorder?: boolean;
|
|
42
45
|
}): boolean;
|
|
43
46
|
export declare function isViewPointInVertexes(p: Point, vertexes: ViewRectVertexes, opts?: {
|
|
44
47
|
includeBorder?: boolean;
|
|
45
48
|
}): boolean;
|
|
46
|
-
export declare function
|
|
49
|
+
export declare function getViewPointAtMaterial(p: Point, opts: {
|
|
47
50
|
context2d: ViewContext2D;
|
|
48
51
|
data: Data;
|
|
49
52
|
viewScaleInfo: ViewScaleInfo;
|
|
50
53
|
viewSizeInfo: ViewSizeInfo;
|
|
51
|
-
groupQueue?:
|
|
54
|
+
groupQueue?: StrictMaterial<'group'>[];
|
|
52
55
|
}): {
|
|
53
56
|
index: number;
|
|
54
|
-
|
|
57
|
+
material: null | StrictMaterial<MaterialType>;
|
|
55
58
|
groupQueueIndex: number;
|
|
56
59
|
};
|
|
57
|
-
export declare function
|
|
60
|
+
export declare function isMaterialInView(mtrl: MaterialSize, opts: {
|
|
58
61
|
viewScaleInfo: ViewScaleInfo;
|
|
59
62
|
viewSizeInfo: ViewSizeInfo;
|
|
60
63
|
}): boolean;
|
|
61
|
-
export declare function
|
|
62
|
-
groupQueue:
|
|
63
|
-
}):
|
|
64
|
-
export declare function
|
|
65
|
-
export declare function
|
|
66
|
-
groupQueue:
|
|
64
|
+
export declare function calcMaterialBoundingInfo(mtrlSize: MaterialSize, opts: {
|
|
65
|
+
groupQueue: StrictMaterial<'group'>[];
|
|
66
|
+
}): BoundingInfo;
|
|
67
|
+
export declare function boundingInfoToRangeBoundingInfo(boundingInfo: BoundingInfo): BoundingInfo;
|
|
68
|
+
export declare function calcMaterialViewBoundingInfo(mtrlSize: MaterialSize, opts: {
|
|
69
|
+
groupQueue: StrictMaterial<'group'>[];
|
|
67
70
|
viewScaleInfo: ViewScaleInfo;
|
|
68
71
|
range?: boolean;
|
|
69
|
-
}):
|
|
72
|
+
}): BoundingInfo;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { rotateMaterialVertexes } from './rotate';
|
|
2
2
|
import { checkRectIntersect } from './rect';
|
|
3
|
-
import {
|
|
3
|
+
import { calcMaterialVertexesInGroup, calcMaterialVertexes } from './vertex';
|
|
4
4
|
import { getCenterFromTwoPoints } from './point';
|
|
5
5
|
export function calcViewScaleInfo(info, opts) {
|
|
6
6
|
const { scale, offsetX, offsetY } = info;
|
|
@@ -17,7 +17,7 @@ export function calcViewScaleInfo(info, opts) {
|
|
|
17
17
|
offsetLeft,
|
|
18
18
|
offsetTop,
|
|
19
19
|
offsetRight,
|
|
20
|
-
offsetBottom
|
|
20
|
+
offsetBottom,
|
|
21
21
|
};
|
|
22
22
|
return newScaleInfo;
|
|
23
23
|
}
|
|
@@ -31,7 +31,7 @@ export function viewScale(opts) {
|
|
|
31
31
|
const moveY = y0 - y0 * scaleDiff + (offsetTop * scaleDiff - offsetTop);
|
|
32
32
|
return {
|
|
33
33
|
moveX,
|
|
34
|
-
moveY
|
|
34
|
+
moveY,
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
export function viewScroll(opts) {
|
|
@@ -53,45 +53,56 @@ export function viewScroll(opts) {
|
|
|
53
53
|
offsetTop,
|
|
54
54
|
offsetLeft,
|
|
55
55
|
offsetRight,
|
|
56
|
-
offsetBottom
|
|
56
|
+
offsetBottom,
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
export function
|
|
59
|
+
export function calcViewMaterialSize(size, opts) {
|
|
60
60
|
const { viewScaleInfo } = opts;
|
|
61
|
-
const { x, y,
|
|
62
|
-
const { scale, offsetTop, offsetLeft } = viewScaleInfo;
|
|
61
|
+
const { id, x, y, width, height, angle } = size;
|
|
62
|
+
const { scale = 1, offsetTop = 0, offsetLeft = 0 } = viewScaleInfo;
|
|
63
63
|
const newSize = {
|
|
64
|
+
id,
|
|
64
65
|
x: x * scale + offsetLeft,
|
|
65
66
|
y: y * scale + offsetTop,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
angle
|
|
67
|
+
width: width * scale,
|
|
68
|
+
height: height * scale,
|
|
69
|
+
angle,
|
|
69
70
|
};
|
|
70
71
|
return newSize;
|
|
71
72
|
}
|
|
72
|
-
export function
|
|
73
|
+
export function calcViewPoint(size, opts) {
|
|
73
74
|
const { viewScaleInfo } = opts;
|
|
74
75
|
const { x, y } = size;
|
|
75
76
|
const { scale, offsetTop, offsetLeft } = viewScaleInfo;
|
|
76
77
|
const newSize = {
|
|
77
78
|
x: x * scale + offsetLeft,
|
|
78
|
-
y: y * scale + offsetTop
|
|
79
|
+
y: y * scale + offsetTop,
|
|
80
|
+
};
|
|
81
|
+
return newSize;
|
|
82
|
+
}
|
|
83
|
+
export function calcPointFromView(viewPoint, opts) {
|
|
84
|
+
const { viewScaleInfo } = opts;
|
|
85
|
+
const { x, y } = viewPoint;
|
|
86
|
+
const { scale, offsetTop, offsetLeft } = viewScaleInfo;
|
|
87
|
+
const newSize = {
|
|
88
|
+
x: (x - offsetLeft) / scale,
|
|
89
|
+
y: (y - offsetTop) / scale,
|
|
79
90
|
};
|
|
80
91
|
return newSize;
|
|
81
92
|
}
|
|
82
93
|
export function calcViewVertexes(vertexes, opts) {
|
|
83
94
|
return [
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
95
|
+
calcViewPoint(vertexes[0], opts),
|
|
96
|
+
calcViewPoint(vertexes[1], opts),
|
|
97
|
+
calcViewPoint(vertexes[2], opts),
|
|
98
|
+
calcViewPoint(vertexes[3], opts),
|
|
88
99
|
];
|
|
89
100
|
}
|
|
90
|
-
export function
|
|
91
|
-
const { context2d: ctx,
|
|
92
|
-
const { angle = 0 } =
|
|
93
|
-
const { x, y,
|
|
94
|
-
const vertexes =
|
|
101
|
+
export function isViewPointInMaterial(p, opts) {
|
|
102
|
+
const { context2d: ctx, material: mtrl, viewScaleInfo } = opts;
|
|
103
|
+
const { angle = 0 } = mtrl;
|
|
104
|
+
const { x, y, width, height } = calcViewMaterialSize(mtrl, { viewScaleInfo });
|
|
105
|
+
const vertexes = rotateMaterialVertexes({ x, y, width, height, angle });
|
|
95
106
|
if (vertexes.length >= 2) {
|
|
96
107
|
ctx.beginPath();
|
|
97
108
|
ctx.moveTo(vertexes[0].x, vertexes[0].y);
|
|
@@ -105,8 +116,8 @@ export function isViewPointInElement(p, opts) {
|
|
|
105
116
|
}
|
|
106
117
|
return false;
|
|
107
118
|
}
|
|
108
|
-
export function
|
|
109
|
-
const vertexes =
|
|
119
|
+
export function isViewPointInMaterialSize(p, mtrlSize, opts) {
|
|
120
|
+
const vertexes = calcMaterialVertexes(mtrlSize);
|
|
110
121
|
return isViewPointInVertexes(p, vertexes, opts);
|
|
111
122
|
}
|
|
112
123
|
export function isViewPointInVertexes(p, vertexes, opts) {
|
|
@@ -124,13 +135,13 @@ export function isViewPointInVertexes(p, vertexes, opts) {
|
|
|
124
135
|
}
|
|
125
136
|
return false;
|
|
126
137
|
}
|
|
127
|
-
export function
|
|
128
|
-
var _a, _b
|
|
138
|
+
export function getViewPointAtMaterial(p, opts) {
|
|
139
|
+
var _a, _b;
|
|
129
140
|
const { context2d: ctx, data, viewScaleInfo, viewSizeInfo, groupQueue } = opts;
|
|
130
141
|
const result = {
|
|
131
142
|
index: -1,
|
|
132
|
-
|
|
133
|
-
groupQueueIndex: -1
|
|
143
|
+
material: null,
|
|
144
|
+
groupQueueIndex: -1,
|
|
134
145
|
};
|
|
135
146
|
if (groupQueue && Array.isArray(groupQueue) && (groupQueue === null || groupQueue === void 0 ? void 0 : groupQueue.length) > 0) {
|
|
136
147
|
for (let gIdx = groupQueue.length - 1; gIdx >= 0; gIdx--) {
|
|
@@ -143,22 +154,22 @@ export function getViewPointAtElement(p, opts) {
|
|
|
143
154
|
totalAngle += groupQueue[i].angle || 0;
|
|
144
155
|
}
|
|
145
156
|
const lastGroup = groupQueue[gIdx];
|
|
146
|
-
if (lastGroup && lastGroup.type === 'group' && Array.isArray(
|
|
147
|
-
for (let i = 0; i < lastGroup.
|
|
148
|
-
const child = lastGroup.
|
|
149
|
-
if (((
|
|
157
|
+
if (lastGroup && lastGroup.type === 'group' && Array.isArray(lastGroup === null || lastGroup === void 0 ? void 0 : lastGroup.children)) {
|
|
158
|
+
for (let i = 0; i < lastGroup.children.length; i++) {
|
|
159
|
+
const child = lastGroup.children[i];
|
|
160
|
+
if (((_a = child === null || child === void 0 ? void 0 : child.operations) === null || _a === void 0 ? void 0 : _a.invisible) === true) {
|
|
150
161
|
continue;
|
|
151
162
|
}
|
|
152
163
|
if (child) {
|
|
153
|
-
const
|
|
164
|
+
const mtrlSize = {
|
|
154
165
|
x: totalX + child.x,
|
|
155
166
|
y: totalY + child.y,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
angle: totalAngle + (child.angle || 0)
|
|
167
|
+
width: child.width,
|
|
168
|
+
height: child.height,
|
|
169
|
+
angle: totalAngle + (child.angle || 0),
|
|
159
170
|
};
|
|
160
|
-
if (
|
|
161
|
-
result.
|
|
171
|
+
if (isViewPointInMaterial(p, { context2d: ctx, material: mtrlSize, viewScaleInfo, viewSizeInfo })) {
|
|
172
|
+
result.material = child;
|
|
162
173
|
if (gIdx < groupQueue.length - 1 || child.type !== 'group') {
|
|
163
174
|
result.groupQueueIndex = gIdx;
|
|
164
175
|
}
|
|
@@ -170,44 +181,44 @@ export function getViewPointAtElement(p, opts) {
|
|
|
170
181
|
}
|
|
171
182
|
}
|
|
172
183
|
}
|
|
173
|
-
if (result.
|
|
184
|
+
if (result.material) {
|
|
174
185
|
break;
|
|
175
186
|
}
|
|
176
187
|
}
|
|
177
188
|
}
|
|
178
|
-
if (result.
|
|
189
|
+
if (result.material) {
|
|
179
190
|
return result;
|
|
180
191
|
}
|
|
181
|
-
for (let i = data.
|
|
182
|
-
const
|
|
183
|
-
if (((
|
|
192
|
+
for (let i = data.materials.length - 1; i >= 0; i--) {
|
|
193
|
+
const mtrl = data.materials[i];
|
|
194
|
+
if (((_b = mtrl === null || mtrl === void 0 ? void 0 : mtrl.operations) === null || _b === void 0 ? void 0 : _b.invisible) === true) {
|
|
184
195
|
continue;
|
|
185
196
|
}
|
|
186
|
-
if (
|
|
197
|
+
if (isViewPointInMaterial(p, { context2d: ctx, material: mtrl, viewScaleInfo, viewSizeInfo })) {
|
|
187
198
|
result.index = i;
|
|
188
|
-
result.
|
|
199
|
+
result.material = mtrl;
|
|
189
200
|
break;
|
|
190
201
|
}
|
|
191
202
|
}
|
|
192
203
|
return result;
|
|
193
204
|
}
|
|
194
|
-
export function
|
|
205
|
+
export function isMaterialInView(mtrl, opts) {
|
|
195
206
|
const { viewSizeInfo, viewScaleInfo } = opts;
|
|
196
207
|
const { width, height } = viewSizeInfo;
|
|
197
|
-
const { angle } =
|
|
198
|
-
const { x, y, w, h } =
|
|
199
|
-
const ves =
|
|
200
|
-
const viewSize = { x: 0, y: 0,
|
|
201
|
-
const
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
return checkRectIntersect(viewSize,
|
|
208
|
+
const { angle } = mtrl;
|
|
209
|
+
const { x, y, width: w, height: h } = calcViewMaterialSize(mtrl, { viewScaleInfo });
|
|
210
|
+
const ves = rotateMaterialVertexes({ x, y, width: w, height: h, angle });
|
|
211
|
+
const viewSize = { x: 0, y: 0, width, height };
|
|
212
|
+
const mtrlStartX = Math.min(ves[0].x, ves[1].x, ves[2].x, ves[3].x);
|
|
213
|
+
const mtrlStartY = Math.min(ves[0].y, ves[1].y, ves[2].y, ves[3].y);
|
|
214
|
+
const mtrlEndX = Math.max(ves[0].x, ves[1].x, ves[2].x, ves[3].x);
|
|
215
|
+
const mtrlEndY = Math.max(ves[0].y, ves[1].y, ves[2].y, ves[3].y);
|
|
216
|
+
const mtrlSize = { x: mtrlStartX, y: mtrlStartY, width: mtrlEndX - mtrlStartX, height: mtrlEndY - mtrlStartY };
|
|
217
|
+
return checkRectIntersect(viewSize, mtrlSize);
|
|
207
218
|
}
|
|
208
|
-
export function
|
|
219
|
+
export function calcMaterialBoundingInfo(mtrlSize, opts) {
|
|
209
220
|
const { groupQueue } = opts;
|
|
210
|
-
const vertexes =
|
|
221
|
+
const vertexes = calcMaterialVertexesInGroup(mtrlSize, { groupQueue });
|
|
211
222
|
const top = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
|
|
212
223
|
const right = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
|
|
213
224
|
const bottom = getCenterFromTwoPoints(vertexes[2], vertexes[3]);
|
|
@@ -222,9 +233,9 @@ export function calcElementOriginRectInfo(elemSize, opts) {
|
|
|
222
233
|
const minY = Math.min(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
|
|
223
234
|
const center = {
|
|
224
235
|
x: (maxX + minX) / 2,
|
|
225
|
-
y: (maxY + minY) / 2
|
|
236
|
+
y: (maxY + minY) / 2,
|
|
226
237
|
};
|
|
227
|
-
const
|
|
238
|
+
const boundingBox = {
|
|
228
239
|
center,
|
|
229
240
|
topLeft,
|
|
230
241
|
topRight,
|
|
@@ -233,16 +244,16 @@ export function calcElementOriginRectInfo(elemSize, opts) {
|
|
|
233
244
|
top,
|
|
234
245
|
right,
|
|
235
246
|
left,
|
|
236
|
-
bottom
|
|
247
|
+
bottom,
|
|
237
248
|
};
|
|
238
|
-
return
|
|
249
|
+
return boundingBox;
|
|
239
250
|
}
|
|
240
|
-
export function
|
|
241
|
-
const rangeMaxX = Math.max(
|
|
242
|
-
const rangeMaxY = Math.max(
|
|
243
|
-
const rangeMinX = Math.min(
|
|
244
|
-
const rangeMinY = Math.min(
|
|
245
|
-
const rangeCenter = { x:
|
|
251
|
+
export function boundingInfoToRangeBoundingInfo(boundingInfo) {
|
|
252
|
+
const rangeMaxX = Math.max(boundingInfo.topLeft.x, boundingInfo.topRight.x, boundingInfo.bottomRight.x, boundingInfo.bottomLeft.x);
|
|
253
|
+
const rangeMaxY = Math.max(boundingInfo.topLeft.y, boundingInfo.topRight.y, boundingInfo.bottomRight.y, boundingInfo.bottomLeft.y);
|
|
254
|
+
const rangeMinX = Math.min(boundingInfo.topLeft.x, boundingInfo.topRight.x, boundingInfo.bottomRight.x, boundingInfo.bottomLeft.x);
|
|
255
|
+
const rangeMinY = Math.min(boundingInfo.topLeft.y, boundingInfo.topRight.y, boundingInfo.bottomRight.y, boundingInfo.bottomLeft.y);
|
|
256
|
+
const rangeCenter = { x: boundingInfo.center.x, y: boundingInfo.center.y };
|
|
246
257
|
const rangeTopLeft = { x: rangeMinX, y: rangeMinY };
|
|
247
258
|
const rangeTopRight = { x: rangeMaxX, y: rangeMinY };
|
|
248
259
|
const rangeBottomRight = { x: rangeMaxX, y: rangeMaxY };
|
|
@@ -251,7 +262,7 @@ export function originRectInfoToRangeRectInfo(originRectInfo) {
|
|
|
251
262
|
const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
|
|
252
263
|
const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
|
|
253
264
|
const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
|
|
254
|
-
const
|
|
265
|
+
const rangeBoundingInfo = {
|
|
255
266
|
center: rangeCenter,
|
|
256
267
|
topLeft: rangeTopLeft,
|
|
257
268
|
topRight: rangeTopRight,
|
|
@@ -260,31 +271,31 @@ export function originRectInfoToRangeRectInfo(originRectInfo) {
|
|
|
260
271
|
top: rangeTop,
|
|
261
272
|
right: rangeRight,
|
|
262
273
|
left: rangeLeft,
|
|
263
|
-
bottom: rangeBottom
|
|
274
|
+
bottom: rangeBottom,
|
|
264
275
|
};
|
|
265
|
-
return
|
|
276
|
+
return rangeBoundingInfo;
|
|
266
277
|
}
|
|
267
|
-
export function
|
|
278
|
+
export function calcMaterialViewBoundingInfo(mtrlSize, opts) {
|
|
268
279
|
const { groupQueue, viewScaleInfo, range } = opts;
|
|
269
|
-
const
|
|
270
|
-
const { center, top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight } =
|
|
271
|
-
const
|
|
272
|
-
center:
|
|
273
|
-
topLeft:
|
|
274
|
-
topRight:
|
|
275
|
-
bottomLeft:
|
|
276
|
-
bottomRight:
|
|
277
|
-
top:
|
|
278
|
-
right:
|
|
279
|
-
left:
|
|
280
|
-
bottom:
|
|
280
|
+
const boundingInfo = calcMaterialBoundingInfo(mtrlSize, { groupQueue });
|
|
281
|
+
const { center, top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight } = boundingInfo;
|
|
282
|
+
const viewBoundingInfo = {
|
|
283
|
+
center: calcViewPoint(center, { viewScaleInfo }),
|
|
284
|
+
topLeft: calcViewPoint(topLeft, { viewScaleInfo }),
|
|
285
|
+
topRight: calcViewPoint(topRight, { viewScaleInfo }),
|
|
286
|
+
bottomLeft: calcViewPoint(bottomLeft, { viewScaleInfo }),
|
|
287
|
+
bottomRight: calcViewPoint(bottomRight, { viewScaleInfo }),
|
|
288
|
+
top: calcViewPoint(top, { viewScaleInfo }),
|
|
289
|
+
right: calcViewPoint(right, { viewScaleInfo }),
|
|
290
|
+
left: calcViewPoint(left, { viewScaleInfo }),
|
|
291
|
+
bottom: calcViewPoint(bottom, { viewScaleInfo }),
|
|
281
292
|
};
|
|
282
293
|
if (range === true) {
|
|
283
|
-
const viewMaxX = Math.max(
|
|
284
|
-
const viewMaxY = Math.max(
|
|
285
|
-
const viewMinX = Math.min(
|
|
286
|
-
const viewMinY = Math.min(
|
|
287
|
-
const rangeCenter = { x:
|
|
294
|
+
const viewMaxX = Math.max(viewBoundingInfo.topLeft.x, viewBoundingInfo.topRight.x, viewBoundingInfo.bottomRight.x, viewBoundingInfo.bottomLeft.x);
|
|
295
|
+
const viewMaxY = Math.max(viewBoundingInfo.topLeft.y, viewBoundingInfo.topRight.y, viewBoundingInfo.bottomRight.y, viewBoundingInfo.bottomLeft.y);
|
|
296
|
+
const viewMinX = Math.min(viewBoundingInfo.topLeft.x, viewBoundingInfo.topRight.x, viewBoundingInfo.bottomRight.x, viewBoundingInfo.bottomLeft.x);
|
|
297
|
+
const viewMinY = Math.min(viewBoundingInfo.topLeft.y, viewBoundingInfo.topRight.y, viewBoundingInfo.bottomRight.y, viewBoundingInfo.bottomLeft.y);
|
|
298
|
+
const rangeCenter = { x: viewBoundingInfo.center.x, y: viewBoundingInfo.center.y };
|
|
288
299
|
const rangeTopLeft = { x: viewMinX, y: viewMinY };
|
|
289
300
|
const rangeTopRight = { x: viewMaxX, y: viewMinY };
|
|
290
301
|
const rangeBottomRight = { x: viewMaxX, y: viewMaxY };
|
|
@@ -293,7 +304,7 @@ export function calcElementViewRectInfo(elemSize, opts) {
|
|
|
293
304
|
const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
|
|
294
305
|
const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
|
|
295
306
|
const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
|
|
296
|
-
const
|
|
307
|
+
const rangeBoundingInfo = {
|
|
297
308
|
center: rangeCenter,
|
|
298
309
|
topLeft: rangeTopLeft,
|
|
299
310
|
topRight: rangeTopRight,
|
|
@@ -302,9 +313,9 @@ export function calcElementViewRectInfo(elemSize, opts) {
|
|
|
302
313
|
top: rangeTop,
|
|
303
314
|
right: rangeRight,
|
|
304
315
|
left: rangeLeft,
|
|
305
|
-
bottom: rangeBottom
|
|
316
|
+
bottom: rangeBottom,
|
|
306
317
|
};
|
|
307
|
-
return
|
|
318
|
+
return rangeBoundingInfo;
|
|
308
319
|
}
|
|
309
|
-
return
|
|
320
|
+
return viewBoundingInfo;
|
|
310
321
|
}
|