@idraw/renderer 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/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/draw/box.js
CHANGED
|
@@ -1,339 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { createColorStyle } from './color';
|
|
3
|
-
const defaultElemConfig = getDefaultElementDetailConfig();
|
|
4
|
-
export function getOpacity(elem) {
|
|
5
|
-
var _a, _b, _c, _d;
|
|
1
|
+
export function getOpacity(mtrl) {
|
|
6
2
|
let opacity = 1;
|
|
7
|
-
if ((
|
|
8
|
-
opacity =
|
|
3
|
+
if ((mtrl === null || mtrl === void 0 ? void 0 : mtrl.opacity) !== undefined && (mtrl === null || mtrl === void 0 ? void 0 : mtrl.opacity) >= 0 && (mtrl === null || mtrl === void 0 ? void 0 : mtrl.opacity) <= 1) {
|
|
4
|
+
opacity = mtrl === null || mtrl === void 0 ? void 0 : mtrl.opacity;
|
|
9
5
|
}
|
|
10
6
|
return opacity;
|
|
11
7
|
}
|
|
12
|
-
export function drawBox(ctx, viewElem, opts) {
|
|
13
|
-
const { pattern, renderContent, originElem, calcElemSize, viewScaleInfo, viewSizeInfo } = opts || {};
|
|
14
|
-
const { parentOpacity } = opts;
|
|
15
|
-
const opacity = getOpacity(originElem) * parentOpacity;
|
|
16
|
-
const { clipPath, clipPathStrokeColor, clipPathStrokeWidth } = originElem.detail;
|
|
17
|
-
const mainRender = () => {
|
|
18
|
-
ctx.globalAlpha = opacity;
|
|
19
|
-
drawBoxBackground(ctx, viewElem, { pattern, viewScaleInfo, viewSizeInfo });
|
|
20
|
-
renderContent === null || renderContent === void 0 ? void 0 : renderContent();
|
|
21
|
-
drawBoxBorder(ctx, viewElem, { originElem, viewScaleInfo, viewSizeInfo });
|
|
22
|
-
ctx.globalAlpha = parentOpacity;
|
|
23
|
-
};
|
|
24
|
-
if (clipPath) {
|
|
25
|
-
drawClipPath(ctx, viewElem, {
|
|
26
|
-
originElem,
|
|
27
|
-
calcElemSize,
|
|
28
|
-
viewScaleInfo,
|
|
29
|
-
viewSizeInfo,
|
|
30
|
-
renderContent: () => {
|
|
31
|
-
mainRender();
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
if (typeof clipPathStrokeWidth === 'number' && clipPathStrokeWidth > 0 && clipPathStrokeColor) {
|
|
35
|
-
drawClipPathStroke(ctx, viewElem, {
|
|
36
|
-
originElem,
|
|
37
|
-
calcElemSize,
|
|
38
|
-
viewScaleInfo,
|
|
39
|
-
viewSizeInfo,
|
|
40
|
-
parentOpacity
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
mainRender();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function drawClipPath(ctx, viewElem, opts) {
|
|
49
|
-
const { renderContent, originElem, calcElemSize, viewSizeInfo } = opts;
|
|
50
|
-
const totalScale = viewSizeInfo.devicePixelRatio;
|
|
51
|
-
const { clipPath } = (originElem === null || originElem === void 0 ? void 0 : originElem.detail) || {};
|
|
52
|
-
if (clipPath && calcElemSize && clipPath.commands) {
|
|
53
|
-
const { x, y, w, h } = calcElemSize;
|
|
54
|
-
const { originW, originH, originX, originY } = clipPath;
|
|
55
|
-
const scaleW = w / originW;
|
|
56
|
-
const scaleH = h / originH;
|
|
57
|
-
const viewOriginX = originX * scaleW;
|
|
58
|
-
const viewOriginY = originY * scaleH;
|
|
59
|
-
const internalX = x - viewOriginX;
|
|
60
|
-
const internalY = y - viewOriginY;
|
|
61
|
-
ctx.save();
|
|
62
|
-
ctx.translate(internalX, internalY);
|
|
63
|
-
ctx.scale(totalScale * scaleW, totalScale * scaleH);
|
|
64
|
-
const pathStr = generateSVGPath(clipPath.commands || []);
|
|
65
|
-
const path2d = new Path2D(pathStr);
|
|
66
|
-
ctx.clip(path2d, 'nonzero');
|
|
67
|
-
ctx.translate(0 - internalX, 0 - internalY);
|
|
68
|
-
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
69
|
-
rotateElement(ctx, Object.assign({}, viewElem), () => {
|
|
70
|
-
renderContent === null || renderContent === void 0 ? void 0 : renderContent();
|
|
71
|
-
});
|
|
72
|
-
ctx.restore();
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
renderContent === null || renderContent === void 0 ? void 0 : renderContent();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function drawClipPathStroke(ctx, viewElem, opts) {
|
|
79
|
-
const { renderContent, originElem, calcElemSize, viewSizeInfo, parentOpacity } = opts;
|
|
80
|
-
const totalScale = viewSizeInfo.devicePixelRatio;
|
|
81
|
-
const { clipPath, clipPathStrokeColor, clipPathStrokeWidth } = (originElem === null || originElem === void 0 ? void 0 : originElem.detail) || {};
|
|
82
|
-
if (clipPath &&
|
|
83
|
-
calcElemSize &&
|
|
84
|
-
clipPath.commands &&
|
|
85
|
-
typeof clipPathStrokeWidth === 'number' &&
|
|
86
|
-
clipPathStrokeWidth > 0 &&
|
|
87
|
-
clipPathStrokeColor) {
|
|
88
|
-
const { x, y, w, h } = calcElemSize;
|
|
89
|
-
const { originW, originH, originX, originY } = clipPath;
|
|
90
|
-
const scaleW = w / originW;
|
|
91
|
-
const scaleH = h / originH;
|
|
92
|
-
const viewOriginX = originX * scaleW;
|
|
93
|
-
const viewOriginY = originY * scaleH;
|
|
94
|
-
const internalX = x - viewOriginX;
|
|
95
|
-
const internalY = y - viewOriginY;
|
|
96
|
-
ctx.save();
|
|
97
|
-
ctx.globalAlpha = parentOpacity;
|
|
98
|
-
ctx.translate(internalX, internalY);
|
|
99
|
-
ctx.scale(totalScale * scaleW, totalScale * scaleH);
|
|
100
|
-
const pathStr = generateSVGPath(clipPath.commands || []);
|
|
101
|
-
const path2d = new Path2D(pathStr);
|
|
102
|
-
ctx.strokeStyle = clipPathStrokeColor;
|
|
103
|
-
ctx.lineWidth = clipPathStrokeWidth;
|
|
104
|
-
ctx.stroke(path2d);
|
|
105
|
-
ctx.translate(0 - internalX, 0 - internalY);
|
|
106
|
-
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
107
|
-
rotateElement(ctx, Object.assign({}, viewElem), () => {
|
|
108
|
-
renderContent === null || renderContent === void 0 ? void 0 : renderContent();
|
|
109
|
-
});
|
|
110
|
-
ctx.restore();
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
renderContent === null || renderContent === void 0 ? void 0 : renderContent();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
export function drawBoxBackground(ctx, viewElem, opts) {
|
|
117
|
-
var _a, _b;
|
|
118
|
-
const { pattern, viewScaleInfo, viewSizeInfo } = opts;
|
|
119
|
-
const transform = [];
|
|
120
|
-
if (viewElem.detail.background || pattern) {
|
|
121
|
-
const { x, y, w, h, radiusList } = calcViewBoxSize(viewElem, {
|
|
122
|
-
viewScaleInfo,
|
|
123
|
-
viewSizeInfo
|
|
124
|
-
});
|
|
125
|
-
ctx.beginPath();
|
|
126
|
-
ctx.moveTo(x + radiusList[0], y);
|
|
127
|
-
ctx.arcTo(x + w, y, x + w, y + h, radiusList[1]);
|
|
128
|
-
ctx.arcTo(x + w, y + h, x, y + h, radiusList[2]);
|
|
129
|
-
ctx.arcTo(x, y + h, x, y, radiusList[3]);
|
|
130
|
-
ctx.arcTo(x, y, x + w, y, radiusList[0]);
|
|
131
|
-
ctx.closePath();
|
|
132
|
-
if (typeof pattern === 'string') {
|
|
133
|
-
ctx.fillStyle = pattern;
|
|
134
|
-
}
|
|
135
|
-
else if (['CanvasPattern'].includes(istype.type(pattern))) {
|
|
136
|
-
ctx.fillStyle = pattern;
|
|
137
|
-
}
|
|
138
|
-
else if (typeof viewElem.detail.background === 'string') {
|
|
139
|
-
ctx.fillStyle = viewElem.detail.background;
|
|
140
|
-
}
|
|
141
|
-
else if (((_a = viewElem.detail.background) === null || _a === void 0 ? void 0 : _a.type) === 'linear-gradient') {
|
|
142
|
-
const colorStyle = createColorStyle(ctx, viewElem.detail.background, {
|
|
143
|
-
viewElementSize: { x, y, w, h },
|
|
144
|
-
viewScaleInfo,
|
|
145
|
-
opacity: ctx.globalAlpha
|
|
146
|
-
});
|
|
147
|
-
ctx.fillStyle = colorStyle;
|
|
148
|
-
}
|
|
149
|
-
else if (((_b = viewElem.detail.background) === null || _b === void 0 ? void 0 : _b.type) === 'radial-gradient') {
|
|
150
|
-
const colorStyle = createColorStyle(ctx, viewElem.detail.background, {
|
|
151
|
-
viewElementSize: { x, y, w, h },
|
|
152
|
-
viewScaleInfo,
|
|
153
|
-
opacity: ctx.globalAlpha
|
|
154
|
-
});
|
|
155
|
-
ctx.fillStyle = colorStyle;
|
|
156
|
-
if (transform && transform.length > 0) {
|
|
157
|
-
for (let i = 0; i < (transform === null || transform === void 0 ? void 0 : transform.length); i++) {
|
|
158
|
-
const action = transform[i];
|
|
159
|
-
if (action.method === 'translate') {
|
|
160
|
-
ctx.translate(action.args[0] + x, action.args[1] + y);
|
|
161
|
-
}
|
|
162
|
-
else if (action.method === 'rotate') {
|
|
163
|
-
ctx.rotate(...action.args);
|
|
164
|
-
}
|
|
165
|
-
else if (action.method === 'scale') {
|
|
166
|
-
ctx.scale(...action.args);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
ctx.fill('nonzero');
|
|
172
|
-
if (transform && transform.length > 0) {
|
|
173
|
-
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
export function drawBoxBorder(ctx, viewElem, opts) {
|
|
178
|
-
if (viewElem.detail.borderWidth === 0) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (!isColorStr(viewElem.detail.borderColor)) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
const { viewScaleInfo } = opts;
|
|
185
|
-
const { scale } = viewScaleInfo;
|
|
186
|
-
let borderColor = defaultElemConfig.borderColor;
|
|
187
|
-
if (isColorStr(viewElem.detail.borderColor) === true) {
|
|
188
|
-
borderColor = viewElem.detail.borderColor;
|
|
189
|
-
}
|
|
190
|
-
const { borderDash, borderWidth, borderRadius, boxSizing = defaultElemConfig.boxSizing } = viewElem.detail;
|
|
191
|
-
let viewBorderDash = [];
|
|
192
|
-
if (Array.isArray(borderDash) && borderDash.length > 0) {
|
|
193
|
-
viewBorderDash = borderDash.map((num) => Math.ceil(num * scale));
|
|
194
|
-
}
|
|
195
|
-
if (viewBorderDash.length > 0) {
|
|
196
|
-
ctx.lineCap = 'butt';
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
ctx.lineCap = 'square';
|
|
200
|
-
}
|
|
201
|
-
let radiusList = [0, 0, 0, 0];
|
|
202
|
-
if (typeof borderRadius === 'number') {
|
|
203
|
-
const br = borderRadius * scale;
|
|
204
|
-
radiusList = [br, br, br, br];
|
|
205
|
-
}
|
|
206
|
-
else if (Array.isArray(borderRadius) && (borderRadius === null || borderRadius === void 0 ? void 0 : borderRadius.length) === 4) {
|
|
207
|
-
radiusList = [borderRadius[0] * scale, borderRadius[1] * scale, borderRadius[2] * scale, borderRadius[3] * scale];
|
|
208
|
-
}
|
|
209
|
-
let bw = 0;
|
|
210
|
-
if (typeof borderWidth === 'number') {
|
|
211
|
-
bw = borderWidth || 1;
|
|
212
|
-
}
|
|
213
|
-
bw = bw * scale;
|
|
214
|
-
ctx.strokeStyle = borderColor;
|
|
215
|
-
let borderTop = 0;
|
|
216
|
-
let borderRight = 0;
|
|
217
|
-
let borderBottom = 0;
|
|
218
|
-
let borderLeft = 0;
|
|
219
|
-
if (Array.isArray(borderWidth)) {
|
|
220
|
-
borderTop = (borderWidth[0] || 0) * scale;
|
|
221
|
-
borderRight = (borderWidth[1] || 0) * scale;
|
|
222
|
-
borderBottom = (borderWidth[2] || 0) * scale;
|
|
223
|
-
borderLeft = (borderWidth[3] || 0) * scale;
|
|
224
|
-
}
|
|
225
|
-
if (borderLeft || borderRight || borderTop || borderBottom) {
|
|
226
|
-
ctx.lineCap = 'butt';
|
|
227
|
-
let { x, y, w, h } = viewElem;
|
|
228
|
-
if (boxSizing === 'border-box') {
|
|
229
|
-
x = x + borderLeft / 2;
|
|
230
|
-
y = y + borderTop / 2;
|
|
231
|
-
w = w - borderLeft / 2 - borderRight / 2;
|
|
232
|
-
h = h - borderTop / 2 - borderBottom / 2;
|
|
233
|
-
}
|
|
234
|
-
else if (boxSizing === 'content-box') {
|
|
235
|
-
x = x - borderLeft / 2;
|
|
236
|
-
y = y - borderTop / 2;
|
|
237
|
-
w = w + borderLeft / 2 + borderRight / 2;
|
|
238
|
-
h = h + borderTop / 2 + borderBottom / 2;
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
x = viewElem.x;
|
|
242
|
-
y = viewElem.y;
|
|
243
|
-
w = viewElem.w;
|
|
244
|
-
h = viewElem.h;
|
|
245
|
-
}
|
|
246
|
-
if (borderTop) {
|
|
247
|
-
ctx.beginPath();
|
|
248
|
-
ctx.lineWidth = borderTop;
|
|
249
|
-
ctx.moveTo(x - borderLeft / 2, y);
|
|
250
|
-
ctx.lineTo(x + w + borderRight / 2, y);
|
|
251
|
-
ctx.closePath();
|
|
252
|
-
ctx.stroke();
|
|
253
|
-
}
|
|
254
|
-
if (borderRight) {
|
|
255
|
-
ctx.beginPath();
|
|
256
|
-
ctx.lineWidth = borderRight;
|
|
257
|
-
ctx.moveTo(x + w, y - borderTop / 2);
|
|
258
|
-
ctx.lineTo(x + w, y + h + borderBottom / 2);
|
|
259
|
-
ctx.closePath();
|
|
260
|
-
ctx.stroke();
|
|
261
|
-
}
|
|
262
|
-
if (borderBottom) {
|
|
263
|
-
ctx.beginPath();
|
|
264
|
-
ctx.lineWidth = borderBottom;
|
|
265
|
-
ctx.moveTo(x - borderLeft / 2, y + h);
|
|
266
|
-
ctx.lineTo(x + w + borderRight / 2, y + h);
|
|
267
|
-
ctx.closePath();
|
|
268
|
-
ctx.stroke();
|
|
269
|
-
}
|
|
270
|
-
if (borderLeft) {
|
|
271
|
-
ctx.beginPath();
|
|
272
|
-
ctx.lineWidth = borderLeft;
|
|
273
|
-
ctx.moveTo(x, y - borderTop / 2);
|
|
274
|
-
ctx.lineTo(x, y + h + borderBottom / 2);
|
|
275
|
-
ctx.closePath();
|
|
276
|
-
ctx.stroke();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
let { x, y, w, h } = viewElem;
|
|
281
|
-
if (boxSizing === 'border-box') {
|
|
282
|
-
x = viewElem.x + bw / 2;
|
|
283
|
-
y = viewElem.y + bw / 2;
|
|
284
|
-
w = viewElem.w - bw;
|
|
285
|
-
h = viewElem.h - bw;
|
|
286
|
-
}
|
|
287
|
-
else if (boxSizing === 'content-box') {
|
|
288
|
-
x = viewElem.x - bw / 2;
|
|
289
|
-
y = viewElem.y - bw / 2;
|
|
290
|
-
w = viewElem.w + bw;
|
|
291
|
-
h = viewElem.h + bw;
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
x = viewElem.x;
|
|
295
|
-
y = viewElem.y;
|
|
296
|
-
w = viewElem.w;
|
|
297
|
-
h = viewElem.h;
|
|
298
|
-
}
|
|
299
|
-
w = Math.max(w, 1);
|
|
300
|
-
h = Math.max(h, 1);
|
|
301
|
-
radiusList = radiusList.map((r) => {
|
|
302
|
-
return Math.min(r, w / 2, h / 2);
|
|
303
|
-
});
|
|
304
|
-
ctx.setLineDash(viewBorderDash);
|
|
305
|
-
ctx.lineWidth = bw;
|
|
306
|
-
ctx.beginPath();
|
|
307
|
-
ctx.moveTo(x + radiusList[0], y);
|
|
308
|
-
ctx.arcTo(x + w, y, x + w, y + h, radiusList[1]);
|
|
309
|
-
ctx.arcTo(x + w, y + h, x, y + h, radiusList[2]);
|
|
310
|
-
ctx.arcTo(x, y + h, x, y, radiusList[3]);
|
|
311
|
-
ctx.arcTo(x, y, x + w, y, radiusList[0]);
|
|
312
|
-
ctx.closePath();
|
|
313
|
-
ctx.stroke();
|
|
314
|
-
}
|
|
315
|
-
ctx.setLineDash([]);
|
|
316
|
-
}
|
|
317
|
-
export function drawBoxShadow(ctx, viewElem, opts) {
|
|
318
|
-
const { detail } = viewElem;
|
|
319
|
-
const { viewScaleInfo, renderContent } = opts;
|
|
320
|
-
const { shadowColor, shadowOffsetX, shadowOffsetY, shadowBlur } = detail;
|
|
321
|
-
if (is.number(shadowBlur)) {
|
|
322
|
-
ctx.save();
|
|
323
|
-
ctx.shadowColor = shadowColor || defaultElemConfig.shadowColor;
|
|
324
|
-
ctx.shadowOffsetX = (shadowOffsetX || 0) * viewScaleInfo.scale;
|
|
325
|
-
ctx.shadowOffsetY = (shadowOffsetY || 0) * viewScaleInfo.scale;
|
|
326
|
-
ctx.shadowBlur = (shadowBlur || 0) * viewScaleInfo.scale;
|
|
327
|
-
renderContent();
|
|
328
|
-
ctx.restore();
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
ctx.save();
|
|
332
|
-
ctx.shadowColor = 'transparent';
|
|
333
|
-
ctx.shadowOffsetX = 0;
|
|
334
|
-
ctx.shadowOffsetY = 0;
|
|
335
|
-
ctx.shadowBlur = 0;
|
|
336
|
-
renderContent();
|
|
337
|
-
ctx.restore();
|
|
338
|
-
}
|
|
339
|
-
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function drawCircle(ctx: ViewContext2D,
|
|
1
|
+
import type { StrictMaterial, RendererDrawMaterialOptions, ViewContext2D } from '@idraw/types';
|
|
2
|
+
export declare function drawCircle(ctx: ViewContext2D, mtrl: StrictMaterial<'circle'>, opts: RendererDrawMaterialOptions): void;
|
package/dist/esm/draw/circle.js
CHANGED
|
@@ -1,74 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { detail, angle } = elem;
|
|
6
|
-
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
7
|
-
const { background = '#000000', borderColor = '#000000', boxSizing, borderWidth = 0, borderDash } = detail;
|
|
8
|
-
let bw = 0;
|
|
9
|
-
if (typeof borderWidth === 'number' && borderWidth > 0) {
|
|
10
|
-
bw = borderWidth;
|
|
11
|
-
}
|
|
12
|
-
else if (Array.isArray(borderWidth) && typeof borderWidth[0] === 'number' && borderWidth[0] > 0) {
|
|
13
|
-
bw = borderWidth[0];
|
|
14
|
-
}
|
|
15
|
-
bw = bw * viewScaleInfo.scale;
|
|
16
|
-
const { x, y, w, h } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h }, { viewScaleInfo }) || elem;
|
|
17
|
-
const viewElem = Object.assign(Object.assign({}, elem), { x, y, w, h, angle });
|
|
18
|
-
rotateElement(ctx, { x, y, w, h, angle }, () => {
|
|
19
|
-
drawBoxShadow(ctx, viewElem, {
|
|
20
|
-
viewScaleInfo,
|
|
21
|
-
viewSizeInfo,
|
|
22
|
-
renderContent: () => {
|
|
23
|
-
let a = w / 2;
|
|
24
|
-
let b = h / 2;
|
|
25
|
-
const centerX = x + a;
|
|
26
|
-
const centerY = y + b;
|
|
27
|
-
const radiusA = a;
|
|
28
|
-
const radiusB = b;
|
|
29
|
-
if (bw > 0) {
|
|
30
|
-
if (boxSizing === 'content-box') {
|
|
31
|
-
}
|
|
32
|
-
else if (boxSizing === 'center-line') {
|
|
33
|
-
a = a - bw / 2;
|
|
34
|
-
b = b - bw / 2;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
a = a - bw;
|
|
38
|
-
b = b - bw;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (a >= 0 && b >= 0) {
|
|
42
|
-
const opacity = getOpacity(viewElem) * parentOpacity;
|
|
43
|
-
ctx.globalAlpha = opacity;
|
|
44
|
-
ctx.beginPath();
|
|
45
|
-
const fillStyle = createColorStyle(ctx, background, {
|
|
46
|
-
viewElementSize: { x, y, w, h },
|
|
47
|
-
viewScaleInfo,
|
|
48
|
-
opacity: ctx.globalAlpha
|
|
49
|
-
});
|
|
50
|
-
ctx.fillStyle = fillStyle;
|
|
51
|
-
ctx.circle(centerX, centerY, radiusA, radiusB, 0, 0, 2 * Math.PI);
|
|
52
|
-
ctx.closePath();
|
|
53
|
-
ctx.fill('nonzero');
|
|
54
|
-
ctx.globalAlpha = parentOpacity;
|
|
55
|
-
if (typeof bw === 'number' && bw > 0) {
|
|
56
|
-
const ba = bw / 2 + a;
|
|
57
|
-
const bb = bw / 2 + b;
|
|
58
|
-
ctx.beginPath();
|
|
59
|
-
if (borderDash) {
|
|
60
|
-
const lineDash = borderDash.map((n) => n * viewScaleInfo.scale);
|
|
61
|
-
ctx.setLineDash(lineDash);
|
|
62
|
-
}
|
|
63
|
-
ctx.strokeStyle = borderColor;
|
|
64
|
-
ctx.lineWidth = bw;
|
|
65
|
-
ctx.circle(centerX, centerY, ba, bb, 0, 0, 2 * Math.PI);
|
|
66
|
-
ctx.closePath();
|
|
67
|
-
ctx.stroke();
|
|
68
|
-
ctx.setLineDash([]);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
});
|
|
1
|
+
import { drawBase, rotateViewMaterial } from './base';
|
|
2
|
+
export function drawCircle(ctx, mtrl, opts) {
|
|
3
|
+
rotateViewMaterial(ctx, mtrl, opts, () => {
|
|
4
|
+
drawBase(ctx, mtrl, opts);
|
|
73
5
|
});
|
|
74
6
|
}
|
package/dist/esm/draw/color.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ViewContext2D, ViewScaleInfo,
|
|
2
|
-
export declare function
|
|
3
|
-
|
|
1
|
+
import type { ViewContext2D, ViewScaleInfo, MaterialSize, LinearGradientColor, RadialGradientColor } from '@idraw/types';
|
|
2
|
+
export declare function createColor(ctx: ViewContext2D, color: string | LinearGradientColor | RadialGradientColor | undefined, opts: {
|
|
3
|
+
viewMaterialSize: MaterialSize;
|
|
4
4
|
viewScaleInfo: ViewScaleInfo;
|
|
5
5
|
opacity: number;
|
|
6
6
|
}): string | CanvasPattern | CanvasGradient;
|
package/dist/esm/draw/color.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { mergeHexColorAlpha } from '@idraw/util';
|
|
2
|
-
export function
|
|
2
|
+
export function createColor(ctx, color, opts) {
|
|
3
3
|
if (typeof color === 'string') {
|
|
4
4
|
return color;
|
|
5
5
|
}
|
|
6
|
-
const {
|
|
7
|
-
const { x, y } =
|
|
6
|
+
const { viewMaterialSize, viewScaleInfo, opacity = 1 } = opts;
|
|
7
|
+
const { x, y } = viewMaterialSize;
|
|
8
8
|
const { scale } = viewScaleInfo;
|
|
9
9
|
if ((color === null || color === void 0 ? void 0 : color.type) === 'linear-gradient') {
|
|
10
10
|
const { start, end, stops } = color;
|
|
11
11
|
const viewStart = {
|
|
12
12
|
x: x + start.x * scale,
|
|
13
|
-
y: y + start.y * scale
|
|
13
|
+
y: y + start.y * scale,
|
|
14
14
|
};
|
|
15
15
|
const viewEnd = {
|
|
16
16
|
x: x + end.x * scale,
|
|
17
|
-
y: y + end.y * scale
|
|
17
|
+
y: y + end.y * scale,
|
|
18
18
|
};
|
|
19
19
|
const linearGradient = ctx.createLinearGradient(viewStart.x, viewStart.y, viewEnd.x, viewEnd.y);
|
|
20
20
|
stops.forEach((stop) => {
|
|
21
|
-
|
|
21
|
+
if (stop.offset >= 0 && stop.color) {
|
|
22
|
+
linearGradient.addColorStop(stop.offset, mergeHexColorAlpha(stop.color, opacity));
|
|
23
|
+
}
|
|
22
24
|
});
|
|
23
25
|
return linearGradient;
|
|
24
26
|
}
|
|
@@ -27,12 +29,12 @@ export function createColorStyle(ctx, color, opts) {
|
|
|
27
29
|
const viewInner = {
|
|
28
30
|
x: x + inner.x * scale,
|
|
29
31
|
y: y + inner.y * scale,
|
|
30
|
-
radius: inner.radius * scale
|
|
32
|
+
radius: inner.radius * scale,
|
|
31
33
|
};
|
|
32
34
|
const viewOuter = {
|
|
33
35
|
x: x + outer.x * scale,
|
|
34
36
|
y: y + outer.y * scale,
|
|
35
|
-
radius: outer.radius * scale
|
|
37
|
+
radius: outer.radius * scale,
|
|
36
38
|
};
|
|
37
39
|
const radialGradient = ctx.createRadialGradient(viewInner.x, viewInner.y, viewInner.radius, viewOuter.x, viewOuter.y, viewOuter.radius);
|
|
38
40
|
stops.forEach((stop) => {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { calcViewMaterialSize } from '@idraw/util';
|
|
2
|
+
import { rotateViewMaterial } from './base';
|
|
3
|
+
export function drawForeignObject(ctx, mtrl, opts) {
|
|
4
|
+
const content = opts.loader.getContent(mtrl);
|
|
5
|
+
const { viewScaleInfo } = opts;
|
|
6
|
+
const { x, y, width, height } = calcViewMaterialSize(mtrl, { viewScaleInfo }) || mtrl;
|
|
7
|
+
rotateViewMaterial(ctx, mtrl, opts, () => {
|
|
8
|
+
if (!content && !opts.loader.isDestroyed()) {
|
|
9
|
+
opts.loader.load(mtrl, opts.materialAssets || {});
|
|
10
|
+
}
|
|
11
|
+
if (mtrl.type === 'foreignObject' && content) {
|
|
12
|
+
ctx.drawImage(content, x, y, width, height);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function drawGlobalBackground(ctx: ViewContext2D, global:
|
|
1
|
+
import type { RendererDrawMaterialOptions, ViewContext2D, DataGlobal } from '@idraw/types';
|
|
2
|
+
export declare function drawGlobalBackground(ctx: ViewContext2D, global: DataGlobal | undefined, opts: RendererDrawMaterialOptions): void;
|
package/dist/esm/draw/global.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export function drawGlobalBackground(ctx, global, opts) {
|
|
2
|
-
if (typeof (global === null || global === void 0 ? void 0 : global.
|
|
2
|
+
if (typeof (global === null || global === void 0 ? void 0 : global.fill) === 'string') {
|
|
3
3
|
const { viewSizeInfo } = opts;
|
|
4
4
|
const { width, height } = viewSizeInfo;
|
|
5
5
|
ctx.globalAlpha = 1;
|
|
6
|
-
ctx.fillStyle = global.
|
|
6
|
+
ctx.fillStyle = global.fill;
|
|
7
7
|
ctx.fillRect(0, 0, width, height);
|
|
8
8
|
}
|
|
9
9
|
}
|
package/dist/esm/draw/group.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function drawGroup(ctx: ViewContext2D,
|
|
1
|
+
import type { StrictMaterial, MaterialType, RendererDrawMaterialOptions, ViewContext2D } from '@idraw/types';
|
|
2
|
+
export declare function drawMaterial(ctx: ViewContext2D, mtrl: StrictMaterial<MaterialType>, opts: RendererDrawMaterialOptions): void;
|
|
3
|
+
export declare function drawGroup(ctx: ViewContext2D, mtrl: StrictMaterial<'group'>, opts: RendererDrawMaterialOptions): void;
|