@idraw/renderer 0.4.3 → 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/calculator.d.ts +17 -12
- package/dist/esm/calculator.js +103 -88
- package/dist/esm/draw/base.d.ts +19 -0
- package/dist/esm/draw/base.js +141 -0
- package/dist/esm/draw/box.d.ts +2 -28
- package/dist/esm/draw/box.js +3 -335
- package/dist/esm/draw/circle.d.ts +2 -2
- package/dist/esm/draw/circle.js +4 -72
- package/dist/esm/draw/color.d.ts +3 -3
- package/dist/esm/draw/color.js +10 -8
- package/dist/esm/draw/ellipse.d.ts +2 -0
- package/dist/esm/draw/ellipse.js +6 -0
- package/dist/esm/draw/foreign-object.d.ts +2 -0
- package/dist/esm/draw/foreign-object.js +15 -0
- package/dist/esm/draw/global.d.ts +2 -2
- package/dist/esm/draw/global.js +2 -2
- package/dist/esm/draw/group.d.ts +3 -3
- package/dist/esm/draw/group.js +60 -94
- package/dist/esm/draw/image.d.ts +2 -2
- package/dist/esm/draw/image.js +70 -86
- package/dist/esm/draw/index.d.ts +6 -5
- package/dist/esm/draw/index.js +6 -5
- package/dist/esm/draw/layout.d.ts +2 -2
- package/dist/esm/draw/layout.js +21 -35
- package/dist/esm/draw/materials.d.ts +2 -0
- package/dist/esm/draw/materials.js +27 -0
- package/dist/esm/draw/path.d.ts +2 -2
- package/dist/esm/draw/path.js +4 -89
- package/dist/esm/draw/rect.d.ts +2 -2
- package/dist/esm/draw/rect.js +4 -22
- package/dist/esm/draw/svg-code.d.ts +2 -0
- package/dist/esm/draw/svg-code.js +15 -0
- package/dist/esm/draw/text.d.ts +2 -2
- package/dist/esm/draw/text.js +60 -50
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +15 -15
- package/dist/esm/loader.d.ts +4 -4
- package/dist/esm/loader.js +68 -70
- package/dist/esm/virtual/base.d.ts +2 -0
- package/dist/esm/virtual/base.js +52 -0
- package/dist/esm/virtual/circle.d.ts +2 -0
- package/dist/esm/virtual/circle.js +38 -0
- package/dist/esm/virtual/ellipse.d.ts +2 -0
- package/dist/esm/virtual/ellipse.js +40 -0
- package/dist/esm/virtual/index.d.ts +6 -0
- package/dist/esm/virtual/index.js +77 -0
- package/dist/esm/virtual/path.d.ts +2 -0
- package/dist/esm/virtual/path.js +10 -0
- package/dist/esm/virtual/rect.d.ts +2 -0
- package/dist/esm/virtual/rect.js +146 -0
- package/dist/esm/virtual/text.d.ts +2 -0
- package/dist/esm/virtual/text.js +165 -0
- package/dist/esm/visible/index.d.ts +22 -0
- package/dist/esm/{view-visible → visible}/index.js +29 -23
- package/dist/index.global.js +1794 -1578
- package/dist/index.global.min.js +1 -1
- package/package.json +3 -3
- package/dist/esm/draw/elements.d.ts +0 -2
- package/dist/esm/draw/elements.js +0 -27
- package/dist/esm/draw/html.d.ts +0 -2
- package/dist/esm/draw/html.js +0 -17
- package/dist/esm/draw/svg.d.ts +0 -2
- package/dist/esm/draw/svg.js +0 -17
- package/dist/esm/view-visible/index.d.ts +0 -22
- package/dist/esm/virtual-flat/index.d.ts +0 -7
- package/dist/esm/virtual-flat/index.js +0 -45
- package/dist/esm/virtual-flat/text.d.ts +0 -2
- package/dist/esm/virtual-flat/text.js +0 -151
package/dist/esm/calculator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Point, Data,
|
|
1
|
+
import type { Point, Data, StrictMaterial, MaterialType, ViewCalculator, ViewCalculatorOptions, ViewScaleInfo, ViewSizeInfo, BoundingInfo, ModifyInfo, VirtualItem } from '@idraw/types';
|
|
2
2
|
export declare class Calculator implements ViewCalculator {
|
|
3
3
|
#private;
|
|
4
4
|
constructor(opts: ViewCalculatorOptions);
|
|
@@ -6,17 +6,18 @@ export declare class Calculator implements ViewCalculator {
|
|
|
6
6
|
ignore?: boolean;
|
|
7
7
|
}): number;
|
|
8
8
|
destroy(): void;
|
|
9
|
-
needRender(
|
|
10
|
-
|
|
9
|
+
needRender(mtrl: StrictMaterial<MaterialType>): boolean;
|
|
10
|
+
forceVisiable(id: string): void;
|
|
11
|
+
getPointMaterial(p: Point, opts: {
|
|
11
12
|
data: Data;
|
|
12
13
|
viewScaleInfo: ViewScaleInfo;
|
|
13
14
|
viewSizeInfo: ViewSizeInfo;
|
|
14
15
|
}): {
|
|
15
16
|
index: number;
|
|
16
|
-
|
|
17
|
+
material: null | StrictMaterial<MaterialType>;
|
|
17
18
|
groupQueueIndex: number;
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
+
resetVirtualItemMap(data: Data, opts: {
|
|
20
21
|
viewScaleInfo: ViewScaleInfo;
|
|
21
22
|
viewSizeInfo: ViewSizeInfo;
|
|
22
23
|
}): void;
|
|
@@ -24,21 +25,25 @@ export declare class Calculator implements ViewCalculator {
|
|
|
24
25
|
viewScaleInfo: ViewScaleInfo;
|
|
25
26
|
viewSizeInfo: ViewSizeInfo;
|
|
26
27
|
}): void;
|
|
27
|
-
|
|
28
|
+
calcViewBoundingInfoFromOrigin(id: string, opts: {
|
|
28
29
|
checkVisible?: boolean;
|
|
29
30
|
viewScaleInfo: ViewScaleInfo;
|
|
30
31
|
viewSizeInfo: ViewSizeInfo;
|
|
31
|
-
}):
|
|
32
|
-
|
|
32
|
+
}): BoundingInfo | null;
|
|
33
|
+
calcViewBoundingInfoFromRange(id: string, opts: {
|
|
33
34
|
checkVisible?: boolean;
|
|
34
35
|
viewScaleInfo: ViewScaleInfo;
|
|
35
36
|
viewSizeInfo: ViewSizeInfo;
|
|
36
|
-
}):
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
}): BoundingInfo | null;
|
|
38
|
+
modifyVirtualAttributes(material: StrictMaterial, opts: {
|
|
39
|
+
viewScaleInfo: ViewScaleInfo;
|
|
40
|
+
viewSizeInfo: ViewSizeInfo;
|
|
41
|
+
groupQueue: StrictMaterial<'group'>[];
|
|
42
|
+
}): void;
|
|
43
|
+
modifyVirtualItemMap(data: Data, opts: {
|
|
39
44
|
modifyInfo: ModifyInfo;
|
|
40
45
|
viewScaleInfo: ViewScaleInfo;
|
|
41
46
|
viewSizeInfo: ViewSizeInfo;
|
|
42
47
|
}): void;
|
|
43
|
-
|
|
48
|
+
getVirtualItem(id: string): VirtualItem | null;
|
|
44
49
|
}
|
package/dist/esm/calculator.js
CHANGED
|
@@ -10,10 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _Calculator_opts, _Calculator_store;
|
|
13
|
-
import { is,
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { calcVirtualTextDetail } from './virtual-flat/text';
|
|
13
|
+
import { is, getViewPointAtMaterial, Store, calcViewPoint, findMaterialFromListByPosition, getGroupQueueByMaterialPosition, calcMaterialBoundingInfo, boundingInfoToRangeBoundingInfo, } from '@idraw/util';
|
|
14
|
+
import { sortMaterialsViewVisiableInfoMap, updateVirtualItemMapStatus } from './visible';
|
|
15
|
+
import { calcVirtualAttributes } from './virtual';
|
|
17
16
|
export class Calculator {
|
|
18
17
|
constructor(opts) {
|
|
19
18
|
_Calculator_opts.set(this, void 0);
|
|
@@ -21,10 +20,10 @@ export class Calculator {
|
|
|
21
20
|
__classPrivateFieldSet(this, _Calculator_opts, opts, "f");
|
|
22
21
|
__classPrivateFieldSet(this, _Calculator_store, new Store({
|
|
23
22
|
defaultStorage: {
|
|
24
|
-
|
|
23
|
+
virtualItemMap: {},
|
|
25
24
|
visibleCount: 0,
|
|
26
|
-
invisibleCount: 0
|
|
27
|
-
}
|
|
25
|
+
invisibleCount: 0,
|
|
26
|
+
},
|
|
28
27
|
}), "f");
|
|
29
28
|
}
|
|
30
29
|
toGridNum(num, opts) {
|
|
@@ -36,145 +35,161 @@ export class Calculator {
|
|
|
36
35
|
destroy() {
|
|
37
36
|
__classPrivateFieldSet(this, _Calculator_opts, null, "f");
|
|
38
37
|
}
|
|
39
|
-
needRender(
|
|
40
|
-
const
|
|
41
|
-
const info =
|
|
38
|
+
needRender(mtrl) {
|
|
39
|
+
const virtualItemMap = __classPrivateFieldGet(this, _Calculator_store, "f").get('virtualItemMap');
|
|
40
|
+
const info = virtualItemMap[mtrl.id];
|
|
42
41
|
if (!info) {
|
|
43
42
|
return true;
|
|
44
43
|
}
|
|
45
44
|
return info.isVisibleInView;
|
|
46
45
|
}
|
|
47
|
-
|
|
46
|
+
forceVisiable(id) {
|
|
47
|
+
const virtualItemMap = __classPrivateFieldGet(this, _Calculator_store, "f").get('virtualItemMap');
|
|
48
|
+
const info = virtualItemMap[id];
|
|
49
|
+
if (info) {
|
|
50
|
+
info.isVisibleInView = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
getPointMaterial(p, opts) {
|
|
48
54
|
const context2d = __classPrivateFieldGet(this, _Calculator_opts, "f").tempContext;
|
|
49
|
-
return
|
|
55
|
+
return getViewPointAtMaterial(p, Object.assign(Object.assign({}, opts), { context2d }));
|
|
50
56
|
}
|
|
51
|
-
|
|
57
|
+
resetVirtualItemMap(data, opts) {
|
|
52
58
|
if (data) {
|
|
53
|
-
const {
|
|
54
|
-
tempContext: __classPrivateFieldGet(this, _Calculator_opts, "f").tempContext
|
|
59
|
+
const { virtualItemMap, invisibleCount, visibleCount } = sortMaterialsViewVisiableInfoMap(data.materials, Object.assign(Object.assign({}, opts), {
|
|
60
|
+
tempContext: __classPrivateFieldGet(this, _Calculator_opts, "f").tempContext,
|
|
55
61
|
}));
|
|
56
|
-
__classPrivateFieldGet(this, _Calculator_store, "f").set('
|
|
62
|
+
__classPrivateFieldGet(this, _Calculator_store, "f").set('virtualItemMap', virtualItemMap);
|
|
57
63
|
__classPrivateFieldGet(this, _Calculator_store, "f").set('invisibleCount', invisibleCount);
|
|
58
64
|
__classPrivateFieldGet(this, _Calculator_store, "f").set('visibleCount', visibleCount);
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
updateVisiableStatus(opts) {
|
|
62
|
-
const {
|
|
63
|
-
__classPrivateFieldGet(this, _Calculator_store, "f").set('
|
|
68
|
+
const { virtualItemMap, invisibleCount, visibleCount } = updateVirtualItemMapStatus(__classPrivateFieldGet(this, _Calculator_store, "f").get('virtualItemMap'), opts);
|
|
69
|
+
__classPrivateFieldGet(this, _Calculator_store, "f").set('virtualItemMap', virtualItemMap);
|
|
64
70
|
__classPrivateFieldGet(this, _Calculator_store, "f").set('invisibleCount', invisibleCount);
|
|
65
71
|
__classPrivateFieldGet(this, _Calculator_store, "f").set('visibleCount', visibleCount);
|
|
66
72
|
}
|
|
67
|
-
|
|
68
|
-
const infoData = __classPrivateFieldGet(this, _Calculator_store, "f").get('
|
|
69
|
-
if (!(infoData === null || infoData === void 0 ? void 0 : infoData.
|
|
73
|
+
calcViewBoundingInfoFromOrigin(id, opts) {
|
|
74
|
+
const infoData = __classPrivateFieldGet(this, _Calculator_store, "f").get('virtualItemMap')[id];
|
|
75
|
+
if (!(infoData === null || infoData === void 0 ? void 0 : infoData.boundingInfo)) {
|
|
70
76
|
return null;
|
|
71
77
|
}
|
|
72
78
|
const { checkVisible, viewScaleInfo, viewSizeInfo } = opts;
|
|
73
|
-
const { center, left, right, bottom, top, topLeft, topRight, bottomLeft, bottomRight } = infoData.
|
|
79
|
+
const { center, left, right, bottom, top, topLeft, topRight, bottomLeft, bottomRight } = infoData.boundingInfo;
|
|
74
80
|
if (checkVisible === true && infoData.isVisibleInView === false) {
|
|
75
81
|
return null;
|
|
76
82
|
}
|
|
77
83
|
const calcOpts = { viewScaleInfo, viewSizeInfo };
|
|
78
|
-
const
|
|
79
|
-
center:
|
|
80
|
-
left:
|
|
81
|
-
right:
|
|
82
|
-
bottom:
|
|
83
|
-
top:
|
|
84
|
-
topLeft:
|
|
85
|
-
topRight:
|
|
86
|
-
bottomLeft:
|
|
87
|
-
bottomRight:
|
|
84
|
+
const viewBoundingBox = {
|
|
85
|
+
center: calcViewPoint(center, calcOpts),
|
|
86
|
+
left: calcViewPoint(left, calcOpts),
|
|
87
|
+
right: calcViewPoint(right, calcOpts),
|
|
88
|
+
bottom: calcViewPoint(bottom, calcOpts),
|
|
89
|
+
top: calcViewPoint(top, calcOpts),
|
|
90
|
+
topLeft: calcViewPoint(topLeft, calcOpts),
|
|
91
|
+
topRight: calcViewPoint(topRight, calcOpts),
|
|
92
|
+
bottomLeft: calcViewPoint(bottomLeft, calcOpts),
|
|
93
|
+
bottomRight: calcViewPoint(bottomRight, calcOpts),
|
|
88
94
|
};
|
|
89
|
-
return
|
|
95
|
+
return viewBoundingBox;
|
|
90
96
|
}
|
|
91
|
-
|
|
92
|
-
const infoData = __classPrivateFieldGet(this, _Calculator_store, "f").get('
|
|
93
|
-
if (!(infoData === null || infoData === void 0 ? void 0 : infoData.
|
|
97
|
+
calcViewBoundingInfoFromRange(id, opts) {
|
|
98
|
+
const infoData = __classPrivateFieldGet(this, _Calculator_store, "f").get('virtualItemMap')[id];
|
|
99
|
+
if (!(infoData === null || infoData === void 0 ? void 0 : infoData.boundingInfo)) {
|
|
94
100
|
return null;
|
|
95
101
|
}
|
|
96
102
|
const { checkVisible, viewScaleInfo, viewSizeInfo } = opts;
|
|
97
|
-
const { center, left, right, bottom, top, topLeft, topRight, bottomLeft, bottomRight } = infoData.
|
|
103
|
+
const { center, left, right, bottom, top, topLeft, topRight, bottomLeft, bottomRight } = infoData.rangeBoundingInfo;
|
|
98
104
|
if (checkVisible === true && infoData.isVisibleInView === false) {
|
|
99
105
|
return null;
|
|
100
106
|
}
|
|
101
107
|
const calcOpts = { viewScaleInfo, viewSizeInfo };
|
|
102
|
-
const
|
|
103
|
-
center:
|
|
104
|
-
left:
|
|
105
|
-
right:
|
|
106
|
-
bottom:
|
|
107
|
-
top:
|
|
108
|
-
topLeft:
|
|
109
|
-
topRight:
|
|
110
|
-
bottomLeft:
|
|
111
|
-
bottomRight:
|
|
108
|
+
const info = {
|
|
109
|
+
center: calcViewPoint(center, calcOpts),
|
|
110
|
+
left: calcViewPoint(left, calcOpts),
|
|
111
|
+
right: calcViewPoint(right, calcOpts),
|
|
112
|
+
bottom: calcViewPoint(bottom, calcOpts),
|
|
113
|
+
top: calcViewPoint(top, calcOpts),
|
|
114
|
+
topLeft: calcViewPoint(topLeft, calcOpts),
|
|
115
|
+
topRight: calcViewPoint(topRight, calcOpts),
|
|
116
|
+
bottomLeft: calcViewPoint(bottomLeft, calcOpts),
|
|
117
|
+
bottomRight: calcViewPoint(bottomRight, calcOpts),
|
|
112
118
|
};
|
|
113
|
-
return
|
|
119
|
+
return info;
|
|
114
120
|
}
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
modifyVirtualAttributes(material, opts) {
|
|
122
|
+
const { viewSizeInfo, groupQueue } = opts;
|
|
123
|
+
const virtualItemMap = __classPrivateFieldGet(this, _Calculator_store, "f").get('virtualItemMap');
|
|
124
|
+
const vItem = virtualItemMap[material.id];
|
|
125
|
+
const vAttributes = calcVirtualAttributes(material, {
|
|
126
|
+
tempContext: __classPrivateFieldGet(this, _Calculator_opts, "f").tempContext,
|
|
127
|
+
dpr: viewSizeInfo.devicePixelRatio,
|
|
128
|
+
groupQueue,
|
|
129
|
+
});
|
|
130
|
+
if (vAttributes) {
|
|
131
|
+
const boundingInfo = calcMaterialBoundingInfo(material, {
|
|
132
|
+
groupQueue,
|
|
133
|
+
});
|
|
134
|
+
const newVirtualItem = Object.assign(Object.assign(Object.assign({}, vItem), vAttributes), { boundingInfo, rangeBoundingInfo: is.angle(material.angle) ? boundingInfoToRangeBoundingInfo(boundingInfo) : boundingInfo });
|
|
135
|
+
virtualItemMap[material.id] = newVirtualItem;
|
|
136
|
+
__classPrivateFieldGet(this, _Calculator_store, "f").set('virtualItemMap', virtualItemMap);
|
|
124
137
|
}
|
|
125
138
|
}
|
|
126
|
-
|
|
139
|
+
modifyVirtualItemMap(data, opts) {
|
|
127
140
|
const { modifyInfo, viewScaleInfo, viewSizeInfo } = opts;
|
|
128
141
|
const { type, content } = modifyInfo;
|
|
129
|
-
const list = data.
|
|
130
|
-
const
|
|
131
|
-
if (type === '
|
|
132
|
-
const {
|
|
133
|
-
const
|
|
142
|
+
const list = data.materials;
|
|
143
|
+
const virtualItemMap = __classPrivateFieldGet(this, _Calculator_store, "f").get('virtualItemMap');
|
|
144
|
+
if (type === 'deleteMaterial') {
|
|
145
|
+
const { material } = content;
|
|
146
|
+
const ids = [];
|
|
134
147
|
const _walk = (e) => {
|
|
135
|
-
|
|
136
|
-
if (e.type === 'group' && Array.isArray(e.
|
|
137
|
-
e.
|
|
148
|
+
ids.push(e.id);
|
|
149
|
+
if (e.type === 'group' && Array.isArray(e.children)) {
|
|
150
|
+
e.children.forEach((child) => {
|
|
138
151
|
_walk(child);
|
|
139
152
|
});
|
|
140
153
|
}
|
|
141
154
|
};
|
|
142
|
-
_walk(
|
|
143
|
-
|
|
144
|
-
delete
|
|
155
|
+
_walk(material);
|
|
156
|
+
ids.forEach((id) => {
|
|
157
|
+
delete virtualItemMap[id];
|
|
145
158
|
});
|
|
146
|
-
__classPrivateFieldGet(this, _Calculator_store, "f").set('
|
|
159
|
+
__classPrivateFieldGet(this, _Calculator_store, "f").set('virtualItemMap', virtualItemMap);
|
|
147
160
|
}
|
|
148
|
-
else if (type === '
|
|
161
|
+
else if (type === 'addMaterial' || type === 'updateMaterial') {
|
|
149
162
|
const { position } = content;
|
|
150
|
-
const
|
|
151
|
-
const groupQueue =
|
|
152
|
-
if (
|
|
153
|
-
if (type === '
|
|
154
|
-
this.
|
|
163
|
+
const material = findMaterialFromListByPosition(position, data.materials);
|
|
164
|
+
const groupQueue = getGroupQueueByMaterialPosition(list, position);
|
|
165
|
+
if (material) {
|
|
166
|
+
if (type === 'updateMaterial' && material.type === 'group') {
|
|
167
|
+
this.resetVirtualItemMap(data, { viewScaleInfo, viewSizeInfo });
|
|
155
168
|
}
|
|
156
169
|
else {
|
|
157
|
-
const
|
|
158
|
-
groupQueue: groupQueue || []
|
|
170
|
+
const boundingInfo = calcMaterialBoundingInfo(material, {
|
|
171
|
+
groupQueue: groupQueue || [],
|
|
159
172
|
});
|
|
160
|
-
const
|
|
161
|
-
tempContext: __classPrivateFieldGet(this, _Calculator_opts, "f").tempContext
|
|
173
|
+
const newVirtualItem = Object.assign({ type: material.type, boundingInfo, rangeBoundingInfo: is.angle(material.angle) ? boundingInfoToRangeBoundingInfo(boundingInfo) : boundingInfo, isVisibleInView: true, position: [...position] }, calcVirtualAttributes(material, {
|
|
174
|
+
tempContext: __classPrivateFieldGet(this, _Calculator_opts, "f").tempContext,
|
|
175
|
+
dpr: viewSizeInfo.devicePixelRatio,
|
|
176
|
+
groupQueue: groupQueue || [],
|
|
162
177
|
}));
|
|
163
|
-
|
|
164
|
-
__classPrivateFieldGet(this, _Calculator_store, "f").set('
|
|
165
|
-
if (type === '
|
|
178
|
+
virtualItemMap[material.id] = newVirtualItem;
|
|
179
|
+
__classPrivateFieldGet(this, _Calculator_store, "f").set('virtualItemMap', virtualItemMap);
|
|
180
|
+
if (type === 'updateMaterial') {
|
|
166
181
|
this.updateVisiableStatus({ viewScaleInfo, viewSizeInfo });
|
|
167
182
|
}
|
|
168
183
|
}
|
|
169
184
|
}
|
|
170
185
|
}
|
|
171
|
-
else if (type === '
|
|
172
|
-
this.
|
|
186
|
+
else if (type === 'moveMaterial') {
|
|
187
|
+
this.resetVirtualItemMap(data, { viewScaleInfo, viewSizeInfo });
|
|
173
188
|
}
|
|
174
189
|
}
|
|
175
|
-
|
|
176
|
-
const itemMap = __classPrivateFieldGet(this, _Calculator_store, "f").get('
|
|
177
|
-
return itemMap[
|
|
190
|
+
getVirtualItem(id) {
|
|
191
|
+
const itemMap = __classPrivateFieldGet(this, _Calculator_store, "f").get('virtualItemMap');
|
|
192
|
+
return itemMap[id] || null;
|
|
178
193
|
}
|
|
179
194
|
}
|
|
180
195
|
_Calculator_opts = new WeakMap(), _Calculator_store = new WeakMap();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Point, Material, MaterialSize, RendererDrawMaterialOptions, ViewContext2D, ViewScaleInfo, ViewSizeInfo, ViewCalculator } from '@idraw/types';
|
|
2
|
+
export declare function drawBase(ctx: ViewContext2D, mtrl: Material, opts: RendererDrawMaterialOptions): void;
|
|
3
|
+
export declare function drawShadow(ctx: ViewContext2D, viewMtrl: Material, opts: {
|
|
4
|
+
viewScaleInfo: ViewScaleInfo;
|
|
5
|
+
viewSizeInfo: ViewSizeInfo;
|
|
6
|
+
tempContext: ViewContext2D;
|
|
7
|
+
path2d: Path2D;
|
|
8
|
+
}): void;
|
|
9
|
+
export declare function drawClipPath(ctx: ViewContext2D, mtrl: Material, opts: {
|
|
10
|
+
path2d?: Path2D;
|
|
11
|
+
viewScaleInfo: ViewScaleInfo;
|
|
12
|
+
viewSizeInfo: ViewSizeInfo;
|
|
13
|
+
renderContent?: () => void;
|
|
14
|
+
calculator: ViewCalculator;
|
|
15
|
+
}): void;
|
|
16
|
+
export declare function rotateViewMaterial(ctx: ViewContext2D, mtrl: Material, opts: RendererDrawMaterialOptions, callback: (e: {
|
|
17
|
+
viewWorldCenter: Point;
|
|
18
|
+
viewWorldSize: MaterialSize;
|
|
19
|
+
}) => void): void;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { scalePathCommands, shiftPathCommands, convertPathCommandsToStr, getDefaultMaterialAttributes, omit, calcViewPoint, calcViewMaterialSize, rotateByCenter, is, } from '@idraw/util';
|
|
13
|
+
import { createColor } from './color';
|
|
14
|
+
let defaultAttrs = getDefaultMaterialAttributes();
|
|
15
|
+
defaultAttrs = omit(defaultAttrs, ['fill']);
|
|
16
|
+
export function drawBase(ctx, mtrl, opts) {
|
|
17
|
+
const { viewScaleInfo, viewSizeInfo, calculator } = opts;
|
|
18
|
+
const { opacity, fill, fillOpacity, fillRule, stroke, strokeWidth, strokeOpacity, strokeLinecap, strokeLinejoin, strokeDasharray, strokeDashoffset, strokeMiterlimit, } = Object.assign(Object.assign({}, defaultAttrs), mtrl);
|
|
19
|
+
const { scale, offsetLeft, offsetTop } = viewScaleInfo;
|
|
20
|
+
const { devicePixelRatio } = viewSizeInfo;
|
|
21
|
+
const virtualAttributes = calculator.getVirtualItem(mtrl.id);
|
|
22
|
+
const { commands, worldCenter } = virtualAttributes;
|
|
23
|
+
const { width, height } = mtrl;
|
|
24
|
+
let cmds = commands;
|
|
25
|
+
cmds = scalePathCommands(cmds, scale, scale);
|
|
26
|
+
cmds = shiftPathCommands(cmds, (offsetLeft + (worldCenter.x - width / 2) * scale) * devicePixelRatio, (offsetTop + (worldCenter.y - height / 2) * scale) * devicePixelRatio);
|
|
27
|
+
const originGlobalAlpha = ctx.globalAlpha;
|
|
28
|
+
const pathStr = convertPathCommandsToStr(cmds);
|
|
29
|
+
const path2d = new Path2D(pathStr);
|
|
30
|
+
drawShadow(ctx, mtrl, Object.assign(Object.assign({}, opts), { path2d }));
|
|
31
|
+
drawClipPath(ctx, mtrl, {
|
|
32
|
+
path2d,
|
|
33
|
+
viewScaleInfo,
|
|
34
|
+
viewSizeInfo,
|
|
35
|
+
calculator,
|
|
36
|
+
renderContent: () => {
|
|
37
|
+
if (fill) {
|
|
38
|
+
const viewMaterialSize = calcViewMaterialSize(mtrl, { viewScaleInfo });
|
|
39
|
+
if (typeof fillOpacity === 'number' && fillOpacity > 0) {
|
|
40
|
+
ctx.globalAlpha = originGlobalAlpha * fillOpacity * opacity;
|
|
41
|
+
}
|
|
42
|
+
ctx.fillStyle = createColor(ctx, fill, { viewMaterialSize, viewScaleInfo, opacity: mtrl.opacity || 1 });
|
|
43
|
+
ctx.fill(path2d, fillRule);
|
|
44
|
+
ctx.globalAlpha = originGlobalAlpha;
|
|
45
|
+
}
|
|
46
|
+
if (typeof strokeWidth === 'number' && strokeWidth > 0) {
|
|
47
|
+
if (typeof strokeOpacity === 'number' && strokeOpacity > 0) {
|
|
48
|
+
ctx.globalAlpha = originGlobalAlpha * strokeOpacity * opacity;
|
|
49
|
+
}
|
|
50
|
+
ctx.lineCap = strokeLinecap;
|
|
51
|
+
ctx.lineJoin = strokeLinejoin;
|
|
52
|
+
ctx.lineDashOffset = strokeDashoffset;
|
|
53
|
+
ctx.miterLimit = strokeMiterlimit;
|
|
54
|
+
if (Array.isArray(strokeDasharray)) {
|
|
55
|
+
const lineDash = strokeDasharray.map((dash) => scale * dash);
|
|
56
|
+
ctx.setLineDash(lineDash);
|
|
57
|
+
}
|
|
58
|
+
ctx.lineWidth = strokeWidth * scale;
|
|
59
|
+
ctx.strokeStyle = stroke;
|
|
60
|
+
ctx.stroke(path2d);
|
|
61
|
+
ctx.setLineDash([]);
|
|
62
|
+
ctx.lineCap = defaultAttrs.strokeLinecap;
|
|
63
|
+
ctx.lineJoin = defaultAttrs.strokeLinejoin;
|
|
64
|
+
ctx.lineDashOffset = defaultAttrs.strokeDashoffset;
|
|
65
|
+
ctx.miterLimit = defaultAttrs.strokeMiterlimit;
|
|
66
|
+
ctx.globalAlpha = originGlobalAlpha;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export function drawShadow(ctx, viewMtrl, opts) {
|
|
72
|
+
const detail = __rest(viewMtrl, []);
|
|
73
|
+
const { viewScaleInfo, viewSizeInfo, tempContext, path2d } = opts;
|
|
74
|
+
const { width, height } = viewSizeInfo;
|
|
75
|
+
const { shadowColor, shadowOffsetX, shadowOffsetY, shadowBlur } = detail;
|
|
76
|
+
if (is.number(shadowBlur) && shadowColor) {
|
|
77
|
+
tempContext.clearRect(0, 0, tempContext.canvas.width, tempContext.canvas.height);
|
|
78
|
+
tempContext.save();
|
|
79
|
+
tempContext.shadowColor = shadowColor;
|
|
80
|
+
tempContext.shadowOffsetX = (shadowOffsetX || 0) * viewScaleInfo.scale;
|
|
81
|
+
tempContext.shadowOffsetY = (shadowOffsetY || 0) * viewScaleInfo.scale;
|
|
82
|
+
tempContext.shadowBlur = (shadowBlur || 0) * viewScaleInfo.scale;
|
|
83
|
+
tempContext.fillStyle = '#ffffff';
|
|
84
|
+
tempContext.fill(path2d);
|
|
85
|
+
tempContext.restore();
|
|
86
|
+
tempContext.save();
|
|
87
|
+
tempContext.globalCompositeOperation = 'destination-out';
|
|
88
|
+
tempContext.fillStyle = '#ffffff';
|
|
89
|
+
tempContext.fill(path2d);
|
|
90
|
+
tempContext.restore();
|
|
91
|
+
ctx.drawImage(tempContext.canvas, 0, 0, width, height);
|
|
92
|
+
tempContext.clearRect(0, 0, tempContext.canvas.width, tempContext.canvas.height);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export function drawClipPath(ctx, mtrl, opts) {
|
|
96
|
+
const { renderContent, calculator, viewScaleInfo, viewSizeInfo } = opts;
|
|
97
|
+
if (mtrl.overflow === 'hidden') {
|
|
98
|
+
let path2d = opts.path2d;
|
|
99
|
+
if (!path2d) {
|
|
100
|
+
const { scale, offsetLeft, offsetTop } = viewScaleInfo;
|
|
101
|
+
const { devicePixelRatio } = viewSizeInfo;
|
|
102
|
+
const virtualAttributes = calculator.getVirtualItem(mtrl.id);
|
|
103
|
+
const { commands, worldCenter } = virtualAttributes;
|
|
104
|
+
const { width, height } = mtrl;
|
|
105
|
+
let cmds = commands;
|
|
106
|
+
cmds = scalePathCommands(cmds, scale, scale);
|
|
107
|
+
cmds = shiftPathCommands(cmds, (offsetLeft + (worldCenter.x - width / 2) * scale) * devicePixelRatio, (offsetTop + (worldCenter.y - height / 2) * scale) * devicePixelRatio);
|
|
108
|
+
const pathStr = convertPathCommandsToStr(cmds);
|
|
109
|
+
path2d = new Path2D(pathStr);
|
|
110
|
+
}
|
|
111
|
+
ctx.save();
|
|
112
|
+
ctx.clip(path2d, 'nonzero');
|
|
113
|
+
renderContent === null || renderContent === void 0 ? void 0 : renderContent();
|
|
114
|
+
ctx.restore();
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
renderContent === null || renderContent === void 0 ? void 0 : renderContent();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export function rotateViewMaterial(ctx, mtrl, opts, callback) {
|
|
121
|
+
const { viewScaleInfo, calculator } = opts;
|
|
122
|
+
const virtualAttributes = calculator === null || calculator === void 0 ? void 0 : calculator.getVirtualItem(mtrl.id);
|
|
123
|
+
if (virtualAttributes) {
|
|
124
|
+
const { worldAngle, worldCenter } = virtualAttributes;
|
|
125
|
+
const viewWorldCenter = calcViewPoint(worldCenter, { viewScaleInfo });
|
|
126
|
+
const { scale } = viewScaleInfo;
|
|
127
|
+
rotateByCenter(ctx, worldAngle, viewWorldCenter, () => {
|
|
128
|
+
const width = mtrl.width * scale;
|
|
129
|
+
const height = mtrl.height * scale;
|
|
130
|
+
const viewWorldSize = {
|
|
131
|
+
x: viewWorldCenter.x - width / 2,
|
|
132
|
+
y: viewWorldCenter.y - height / 2,
|
|
133
|
+
width,
|
|
134
|
+
height,
|
|
135
|
+
};
|
|
136
|
+
callback({ viewWorldCenter, viewWorldSize });
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
}
|
|
141
|
+
}
|
package/dist/esm/draw/box.d.ts
CHANGED
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function getOpacity(elem: Element): number;
|
|
4
|
-
export declare function drawBox(ctx: ViewContext2D, viewElem: Element, opts: {
|
|
5
|
-
originElem: Element;
|
|
6
|
-
calcElemSize: ElementSize;
|
|
7
|
-
pattern?: string | CanvasPattern | null;
|
|
8
|
-
renderContent?: () => void;
|
|
9
|
-
viewScaleInfo: ViewScaleInfo;
|
|
10
|
-
viewSizeInfo: ViewSizeInfo;
|
|
11
|
-
parentOpacity: number;
|
|
12
|
-
}): void;
|
|
13
|
-
export declare function drawBoxBackground(ctx: ViewContext2D, viewElem: Element<ElementType>, opts: {
|
|
14
|
-
pattern?: string | CanvasPattern | null;
|
|
15
|
-
viewScaleInfo: ViewScaleInfo;
|
|
16
|
-
viewSizeInfo: ViewSizeInfo;
|
|
17
|
-
}): void;
|
|
18
|
-
export declare function drawBoxBorder(ctx: ViewContext2D, viewElem: Element<ElementType>, opts: {
|
|
19
|
-
originElem: Element;
|
|
20
|
-
viewScaleInfo: ViewScaleInfo;
|
|
21
|
-
viewSizeInfo: ViewSizeInfo;
|
|
22
|
-
calculator?: Calculator;
|
|
23
|
-
}): void;
|
|
24
|
-
export declare function drawBoxShadow(ctx: ViewContext2D, viewElem: Element<ElementType>, opts: {
|
|
25
|
-
viewScaleInfo: ViewScaleInfo;
|
|
26
|
-
viewSizeInfo: ViewSizeInfo;
|
|
27
|
-
renderContent: () => void;
|
|
28
|
-
}): void;
|
|
1
|
+
import { StrictMaterial } from '@idraw/types';
|
|
2
|
+
export declare function getOpacity(mtrl: StrictMaterial): number;
|