@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/group.js
CHANGED
|
@@ -1,60 +1,65 @@
|
|
|
1
|
-
import { rotateElement, calcViewBoxSize, calcViewElementSize } from '@idraw/util';
|
|
2
|
-
import { drawCircle } from './circle';
|
|
3
1
|
import { drawRect } from './rect';
|
|
2
|
+
import { drawCircle } from './circle';
|
|
3
|
+
import { drawEllipse } from './ellipse';
|
|
4
4
|
import { drawImage } from './image';
|
|
5
5
|
import { drawText } from './text';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { drawBox, drawBoxShadow, getOpacity } from './box';
|
|
6
|
+
import { drawSVGCode } from './svg-code';
|
|
7
|
+
import { drawForeignObject } from './foreign-object';
|
|
9
8
|
import { drawPath } from './path';
|
|
9
|
+
import { drawBase, rotateViewMaterial } from './base';
|
|
10
10
|
const visiableMinSize = 0.4;
|
|
11
|
-
export function
|
|
11
|
+
export function drawMaterial(ctx, mtrl, opts) {
|
|
12
12
|
var _a, _b, _c;
|
|
13
|
-
if (((_a =
|
|
13
|
+
if (((_a = mtrl === null || mtrl === void 0 ? void 0 : mtrl.operations) === null || _a === void 0 ? void 0 : _a.invisible) === true) {
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
|
-
const {
|
|
16
|
+
const { width, height } = mtrl;
|
|
17
17
|
const { scale } = opts.viewScaleInfo;
|
|
18
|
-
if ((scale < 1 && (
|
|
18
|
+
if ((scale < 1 && (width * scale < visiableMinSize || height * scale < visiableMinSize)) ||
|
|
19
|
+
opts.parentOpacity === 0) {
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
|
-
const {
|
|
22
|
-
if ((_c = (_b =
|
|
22
|
+
const { overrideMaterialMap } = opts;
|
|
23
|
+
if ((_c = (_b = overrideMaterialMap === null || overrideMaterialMap === void 0 ? void 0 : overrideMaterialMap[mtrl.id]) === null || _b === void 0 ? void 0 : _b.operations) === null || _c === void 0 ? void 0 : _c.invisible) {
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
25
26
|
try {
|
|
26
|
-
switch (
|
|
27
|
+
switch (mtrl.type) {
|
|
27
28
|
case 'rect': {
|
|
28
|
-
drawRect(ctx,
|
|
29
|
+
drawRect(ctx, mtrl, opts);
|
|
29
30
|
break;
|
|
30
31
|
}
|
|
31
32
|
case 'circle': {
|
|
32
|
-
drawCircle(ctx,
|
|
33
|
+
drawCircle(ctx, mtrl, opts);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case 'ellipse': {
|
|
37
|
+
drawEllipse(ctx, mtrl, opts);
|
|
33
38
|
break;
|
|
34
39
|
}
|
|
35
40
|
case 'text': {
|
|
36
|
-
drawText(ctx,
|
|
41
|
+
drawText(ctx, mtrl, opts);
|
|
37
42
|
break;
|
|
38
43
|
}
|
|
39
44
|
case 'image': {
|
|
40
|
-
drawImage(ctx,
|
|
45
|
+
drawImage(ctx, mtrl, opts);
|
|
41
46
|
break;
|
|
42
47
|
}
|
|
43
|
-
case '
|
|
44
|
-
|
|
48
|
+
case 'svgCode': {
|
|
49
|
+
drawSVGCode(ctx, mtrl, opts);
|
|
45
50
|
break;
|
|
46
51
|
}
|
|
47
|
-
case '
|
|
48
|
-
|
|
52
|
+
case 'foreignObject': {
|
|
53
|
+
drawForeignObject(ctx, mtrl, opts);
|
|
49
54
|
break;
|
|
50
55
|
}
|
|
51
56
|
case 'path': {
|
|
52
|
-
drawPath(ctx,
|
|
57
|
+
drawPath(ctx, mtrl, opts);
|
|
53
58
|
break;
|
|
54
59
|
}
|
|
55
60
|
case 'group': {
|
|
56
|
-
const assets = Object.assign(Object.assign({}, (opts.
|
|
57
|
-
drawGroup(ctx,
|
|
61
|
+
const assets = Object.assign(Object.assign({}, (opts.materialAssets || {})), (mtrl.assets || {}));
|
|
62
|
+
drawGroup(ctx, mtrl, Object.assign(Object.assign({}, opts), { materialAssets: assets }));
|
|
58
63
|
break;
|
|
59
64
|
}
|
|
60
65
|
default: {
|
|
@@ -66,76 +71,37 @@ export function drawElement(ctx, elem, opts) {
|
|
|
66
71
|
console.error(err);
|
|
67
72
|
}
|
|
68
73
|
}
|
|
69
|
-
export function drawGroup(ctx,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const viewElem = Object.assign(Object.assign({}, elem), { x, y, w, h, angle });
|
|
73
|
-
rotateElement(ctx, { x, y, w, h, angle }, () => {
|
|
74
|
-
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
75
|
-
drawBoxShadow(ctx, viewElem, {
|
|
76
|
-
viewScaleInfo,
|
|
77
|
-
viewSizeInfo,
|
|
78
|
-
renderContent: () => {
|
|
79
|
-
drawBox(ctx, viewElem, {
|
|
80
|
-
originElem: elem,
|
|
81
|
-
calcElemSize: { x, y, w, h, angle },
|
|
82
|
-
viewScaleInfo,
|
|
83
|
-
viewSizeInfo,
|
|
84
|
-
parentOpacity,
|
|
85
|
-
renderContent: () => {
|
|
86
|
-
const { x, y, w, h, radiusList } = calcViewBoxSize(viewElem, {
|
|
87
|
-
viewScaleInfo,
|
|
88
|
-
viewSizeInfo
|
|
89
|
-
});
|
|
90
|
-
if (elem.detail.overflow === 'hidden') {
|
|
91
|
-
ctx.save();
|
|
92
|
-
ctx.fillStyle = 'transparent';
|
|
93
|
-
ctx.beginPath();
|
|
94
|
-
ctx.moveTo(x + radiusList[0], y);
|
|
95
|
-
ctx.arcTo(x + w, y, x + w, y + h, radiusList[1]);
|
|
96
|
-
ctx.arcTo(x + w, y + h, x, y + h, radiusList[2]);
|
|
97
|
-
ctx.arcTo(x, y + h, x, y, radiusList[3]);
|
|
98
|
-
ctx.arcTo(x, y, x + w, y, radiusList[0]);
|
|
99
|
-
ctx.closePath();
|
|
100
|
-
ctx.fill('nonzero');
|
|
101
|
-
ctx.clip('nonzero');
|
|
102
|
-
}
|
|
103
|
-
if (Array.isArray(elem.detail.children)) {
|
|
104
|
-
const { parentElementSize: parentSize } = opts;
|
|
105
|
-
const newParentSize = {
|
|
106
|
-
x: parentSize.x + elem.x,
|
|
107
|
-
y: parentSize.y + elem.y,
|
|
108
|
-
w: elem.w || parentSize.w,
|
|
109
|
-
h: elem.h || parentSize.h,
|
|
110
|
-
angle: elem.angle
|
|
111
|
-
};
|
|
112
|
-
const { calculator } = opts;
|
|
113
|
-
for (let i = 0; i < elem.detail.children.length; i++) {
|
|
114
|
-
let child = elem.detail.children[i];
|
|
115
|
-
child = Object.assign(Object.assign({}, child), {
|
|
116
|
-
x: newParentSize.x + child.x,
|
|
117
|
-
y: newParentSize.y + child.y
|
|
118
|
-
});
|
|
119
|
-
if (opts.forceDrawAll !== true) {
|
|
120
|
-
if (!(calculator === null || calculator === void 0 ? void 0 : calculator.needRender(child))) {
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
try {
|
|
125
|
-
drawElement(ctx, child, Object.assign(Object.assign({}, opts), { parentOpacity: parentOpacity * getOpacity(elem) }));
|
|
126
|
-
}
|
|
127
|
-
catch (err) {
|
|
128
|
-
console.error(err);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (elem.detail.overflow === 'hidden') {
|
|
133
|
-
ctx.restore();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
ctx.globalAlpha = parentOpacity;
|
|
74
|
+
export function drawGroup(ctx, mtrl, opts) {
|
|
75
|
+
rotateViewMaterial(ctx, mtrl, opts, () => {
|
|
76
|
+
drawBase(ctx, mtrl, opts);
|
|
140
77
|
});
|
|
78
|
+
if (Array.isArray(mtrl.children)) {
|
|
79
|
+
const { parentMaterialSize: parentSize } = opts;
|
|
80
|
+
const newParentSize = {
|
|
81
|
+
x: parentSize.x + mtrl.x,
|
|
82
|
+
y: parentSize.y + mtrl.y,
|
|
83
|
+
width: mtrl.width || parentSize.width,
|
|
84
|
+
height: mtrl.height || parentSize.height,
|
|
85
|
+
angle: mtrl.angle,
|
|
86
|
+
};
|
|
87
|
+
const { calculator } = opts;
|
|
88
|
+
for (let i = 0; i < mtrl.children.length; i++) {
|
|
89
|
+
let child = mtrl.children[i];
|
|
90
|
+
child = Object.assign(Object.assign({}, child), {
|
|
91
|
+
x: newParentSize.x + child.x,
|
|
92
|
+
y: newParentSize.y + child.y,
|
|
93
|
+
});
|
|
94
|
+
if (opts.forceDrawAll !== true) {
|
|
95
|
+
if (!(calculator === null || calculator === void 0 ? void 0 : calculator.needRender(child))) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
drawMaterial(ctx, child, opts);
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
console.error(err);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
141
107
|
}
|
package/dist/esm/draw/image.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function drawImage(ctx: ViewContext2D,
|
|
1
|
+
import type { StrictMaterial, RendererDrawMaterialOptions, ViewContext2D } from '@idraw/types';
|
|
2
|
+
export declare function drawImage(ctx: ViewContext2D, mtrl: StrictMaterial<'image'>, opts: RendererDrawMaterialOptions): void;
|
package/dist/esm/draw/image.js
CHANGED
|
@@ -1,90 +1,74 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const dy = y;
|
|
51
|
-
const dWidth = w;
|
|
52
|
-
const dHeight = h;
|
|
53
|
-
if (imageW > elem.w || imageH > elem.h) {
|
|
54
|
-
if (scaleMode === 'fill') {
|
|
55
|
-
const sourceScale = Math.max(elem.w / imageW, elem.h / imageH);
|
|
56
|
-
const newImageWidth = imageW * sourceScale;
|
|
57
|
-
const newImageHeight = imageH * sourceScale;
|
|
58
|
-
sx = (newImageWidth - elem.w) / 2 / sourceScale;
|
|
59
|
-
sy = (newImageHeight - elem.h) / 2 / sourceScale;
|
|
60
|
-
sWidth = elem.w / sourceScale;
|
|
61
|
-
sHeight = elem.h / sourceScale;
|
|
62
|
-
}
|
|
63
|
-
else if (scaleMode === 'tile') {
|
|
64
|
-
sx = 0;
|
|
65
|
-
sy = 0;
|
|
66
|
-
sWidth = elem.w;
|
|
67
|
-
sHeight = elem.h;
|
|
68
|
-
}
|
|
69
|
-
else if (scaleMode === 'fit') {
|
|
70
|
-
const sourceScale = Math.min(elem.w / imageW, elem.h / imageH);
|
|
71
|
-
sx = (imageW - elem.w / sourceScale) / 2;
|
|
72
|
-
sy = (imageH - elem.h / sourceScale) / 2;
|
|
73
|
-
sWidth = elem.w / sourceScale;
|
|
74
|
-
sHeight = elem.h / sourceScale;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
ctx.drawImage(content, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
ctx.drawImage(content, x, y, w, h);
|
|
81
|
-
}
|
|
82
|
-
ctx.globalAlpha = parentOpacity;
|
|
83
|
-
ctx.restore();
|
|
84
|
-
}
|
|
1
|
+
import { calcViewMaterialSize } from '@idraw/util';
|
|
2
|
+
import { getOpacity } from './box';
|
|
3
|
+
import { rotateViewMaterial } from './base';
|
|
4
|
+
export function drawImage(ctx, mtrl, opts) {
|
|
5
|
+
const content = opts.loader.getContent(mtrl);
|
|
6
|
+
const { viewScaleInfo, parentOpacity } = opts;
|
|
7
|
+
const { x, y, width, height, angle } = calcViewMaterialSize(mtrl, { viewScaleInfo }) || mtrl;
|
|
8
|
+
const viewMtrl = Object.assign(Object.assign({}, mtrl), { x, y, width, height, angle });
|
|
9
|
+
rotateViewMaterial(ctx, mtrl, opts, () => {
|
|
10
|
+
if (!content && !opts.loader.isDestroyed()) {
|
|
11
|
+
opts.loader.load(mtrl, opts.materialAssets || {});
|
|
12
|
+
}
|
|
13
|
+
if (mtrl.type === 'image' && content) {
|
|
14
|
+
ctx.globalAlpha = getOpacity(mtrl) * parentOpacity;
|
|
15
|
+
const { x, y, width, height } = viewMtrl;
|
|
16
|
+
const radiusList = [0, 0, 0, 0];
|
|
17
|
+
const attributes = mtrl;
|
|
18
|
+
const { scaleMode, originW = 0, originH = 0 } = attributes;
|
|
19
|
+
const imageW = ctx.$undoPixelRatio(originW);
|
|
20
|
+
const imageH = ctx.$undoPixelRatio(originH);
|
|
21
|
+
ctx.save();
|
|
22
|
+
ctx.fillStyle = 'transparent';
|
|
23
|
+
ctx.beginPath();
|
|
24
|
+
ctx.moveTo(x + radiusList[0], y);
|
|
25
|
+
ctx.arcTo(x + width, y, x + width, y + height, radiusList[1]);
|
|
26
|
+
ctx.arcTo(x + width, y + height, x, y + height, radiusList[2]);
|
|
27
|
+
ctx.arcTo(x, y + height, x, y, radiusList[3]);
|
|
28
|
+
ctx.arcTo(x, y, x + width, y, radiusList[0]);
|
|
29
|
+
ctx.closePath();
|
|
30
|
+
ctx.fill('nonzero');
|
|
31
|
+
ctx.clip('nonzero');
|
|
32
|
+
if (scaleMode && originH && originW) {
|
|
33
|
+
let sx = 0;
|
|
34
|
+
let sy = 0;
|
|
35
|
+
let sWidth = imageW;
|
|
36
|
+
let sHeight = imageH;
|
|
37
|
+
const dx = x;
|
|
38
|
+
const dy = y;
|
|
39
|
+
const dWidth = width;
|
|
40
|
+
const dHeight = height;
|
|
41
|
+
if (imageW > mtrl.width || imageH > mtrl.height) {
|
|
42
|
+
if (scaleMode === 'fill') {
|
|
43
|
+
const sourceScale = Math.max(mtrl.width / imageW, mtrl.height / imageH);
|
|
44
|
+
const newImageWidth = imageW * sourceScale;
|
|
45
|
+
const newImageHeight = imageH * sourceScale;
|
|
46
|
+
sx = (newImageWidth - mtrl.width) / 2 / sourceScale;
|
|
47
|
+
sy = (newImageHeight - mtrl.height) / 2 / sourceScale;
|
|
48
|
+
sWidth = mtrl.width / sourceScale;
|
|
49
|
+
sHeight = mtrl.height / sourceScale;
|
|
85
50
|
}
|
|
86
|
-
|
|
51
|
+
else if (scaleMode === 'tile') {
|
|
52
|
+
sx = 0;
|
|
53
|
+
sy = 0;
|
|
54
|
+
sWidth = mtrl.width;
|
|
55
|
+
sHeight = mtrl.height;
|
|
56
|
+
}
|
|
57
|
+
else if (scaleMode === 'fit') {
|
|
58
|
+
const sourceScale = Math.min(mtrl.width / imageW, mtrl.height / imageH);
|
|
59
|
+
sx = (imageW - mtrl.width / sourceScale) / 2;
|
|
60
|
+
sy = (imageH - mtrl.height / sourceScale) / 2;
|
|
61
|
+
sWidth = mtrl.width / sourceScale;
|
|
62
|
+
sHeight = mtrl.height / sourceScale;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
ctx.drawImage(content, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
ctx.drawImage(content, x, y, width, height);
|
|
87
69
|
}
|
|
88
|
-
|
|
70
|
+
ctx.globalAlpha = parentOpacity;
|
|
71
|
+
ctx.restore();
|
|
72
|
+
}
|
|
89
73
|
});
|
|
90
74
|
}
|
package/dist/esm/draw/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export { drawCircle } from './circle';
|
|
2
1
|
export { drawRect } from './rect';
|
|
2
|
+
export { drawCircle } from './circle';
|
|
3
|
+
export { drawEllipse } from './ellipse';
|
|
3
4
|
export { drawImage } from './image';
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
5
|
+
export { drawSVGCode } from './svg-code';
|
|
6
|
+
export { drawForeignObject } from './foreign-object';
|
|
6
7
|
export { drawText } from './text';
|
|
7
|
-
export { drawGroup,
|
|
8
|
-
export {
|
|
8
|
+
export { drawGroup, drawMaterial } from './group';
|
|
9
|
+
export { drawMaterialList } from './materials';
|
|
9
10
|
export { drawLayout } from './layout';
|
|
10
11
|
export { drawGlobalBackground } from './global';
|
package/dist/esm/draw/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export { drawCircle } from './circle';
|
|
2
1
|
export { drawRect } from './rect';
|
|
2
|
+
export { drawCircle } from './circle';
|
|
3
|
+
export { drawEllipse } from './ellipse';
|
|
3
4
|
export { drawImage } from './image';
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
5
|
+
export { drawSVGCode } from './svg-code';
|
|
6
|
+
export { drawForeignObject } from './foreign-object';
|
|
6
7
|
export { drawText } from './text';
|
|
7
|
-
export { drawGroup,
|
|
8
|
-
export {
|
|
8
|
+
export { drawGroup, drawMaterial } from './group';
|
|
9
|
+
export { drawMaterialList } from './materials';
|
|
9
10
|
export { drawLayout } from './layout';
|
|
10
11
|
export { drawGlobalBackground } from './global';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function drawLayout(ctx: ViewContext2D, layout: DataLayout, opts:
|
|
1
|
+
import type { RendererDrawMaterialOptions, ViewContext2D, DataLayout } from '@idraw/types';
|
|
2
|
+
export declare function drawLayout(ctx: ViewContext2D, layout: DataLayout, opts: RendererDrawMaterialOptions, renderContent: (ctx: ViewContext2D) => void): void;
|
package/dist/esm/draw/layout.js
CHANGED
|
@@ -1,44 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { calcViewMaterialSize } from '@idraw/util';
|
|
2
|
+
import { createColor } from './color';
|
|
3
3
|
export function drawLayout(ctx, layout, opts, renderContent) {
|
|
4
|
-
const {
|
|
5
|
-
const elem = Object.assign({ uuid: 'layout', type: 'group' }, layout);
|
|
6
|
-
const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
7
|
-
const angle = 0;
|
|
8
|
-
const viewElem = Object.assign(Object.assign({}, elem), { x, y, w, h, angle });
|
|
4
|
+
const { parentOpacity } = opts;
|
|
9
5
|
ctx.globalAlpha = 1;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
ctx.fillStyle = 'transparent';
|
|
28
|
-
ctx.beginPath();
|
|
29
|
-
ctx.moveTo(x + radiusList[0], y);
|
|
30
|
-
ctx.arcTo(x + w, y, x + w, y + h, radiusList[1]);
|
|
31
|
-
ctx.arcTo(x + w, y + h, x, y + h, radiusList[2]);
|
|
32
|
-
ctx.arcTo(x, y + h, x, y, radiusList[3]);
|
|
33
|
-
ctx.arcTo(x, y, x + w, y, radiusList[0]);
|
|
34
|
-
ctx.closePath();
|
|
35
|
-
ctx.fill('nonzero');
|
|
6
|
+
const { viewScaleInfo } = opts;
|
|
7
|
+
const mtrl = Object.assign({ id: 'layout', type: 'group' }, layout);
|
|
8
|
+
const viewMtrlSize = calcViewMaterialSize(mtrl, { viewScaleInfo }) || mtrl;
|
|
9
|
+
const viewMtrl = Object.assign(Object.assign({}, mtrl), viewMtrlSize);
|
|
10
|
+
const { x, y, width, height, fill } = viewMtrl;
|
|
11
|
+
const radiusList = [0, 0, 0, 0];
|
|
12
|
+
ctx.save();
|
|
13
|
+
ctx.fillStyle = createColor(ctx, fill, { viewMaterialSize: viewMtrlSize, viewScaleInfo, opacity: mtrl.opacity || 1 });
|
|
14
|
+
ctx.beginPath();
|
|
15
|
+
ctx.moveTo(x + radiusList[0], y);
|
|
16
|
+
ctx.arcTo(x + width, y, x + width, y + height, radiusList[1]);
|
|
17
|
+
ctx.arcTo(x + width, y + height, x, y + height, radiusList[2]);
|
|
18
|
+
ctx.arcTo(x, y + height, x, y, radiusList[3]);
|
|
19
|
+
ctx.arcTo(x, y, x + width, y, radiusList[0]);
|
|
20
|
+
ctx.closePath();
|
|
21
|
+
ctx.fill('nonzero');
|
|
22
|
+
if (layout.overflow === 'hidden') {
|
|
36
23
|
ctx.clip('nonzero');
|
|
37
24
|
}
|
|
38
25
|
renderContent(ctx);
|
|
39
|
-
if (layout.
|
|
26
|
+
if (layout.overflow === 'hidden') {
|
|
40
27
|
ctx.restore();
|
|
41
28
|
}
|
|
42
|
-
drawBoxBorder(ctx, viewElem, { originElem: elem, viewScaleInfo, viewSizeInfo });
|
|
43
29
|
ctx.globalAlpha = parentOpacity;
|
|
44
30
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getDefaultMaterialAttributes } from '@idraw/util';
|
|
2
|
+
import { drawMaterial } from './group';
|
|
3
|
+
const defaultAttributes = getDefaultMaterialAttributes();
|
|
4
|
+
export function drawMaterialList(ctx, data, opts) {
|
|
5
|
+
var _a;
|
|
6
|
+
const { materials = [] } = data;
|
|
7
|
+
const { parentOpacity } = opts;
|
|
8
|
+
for (let i = 0; i < materials.length; i++) {
|
|
9
|
+
const material = materials[i];
|
|
10
|
+
const mtrl = Object.assign(Object.assign({}, material), {
|
|
11
|
+
attributes: Object.assign(Object.assign({}, defaultAttributes), material),
|
|
12
|
+
});
|
|
13
|
+
if (opts.forceDrawAll !== true) {
|
|
14
|
+
if (!((_a = opts.calculator) === null || _a === void 0 ? void 0 : _a.needRender(mtrl))) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
drawMaterial(ctx, mtrl, Object.assign(Object.assign({}, opts), {
|
|
20
|
+
parentOpacity,
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
console.error(err);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/esm/draw/path.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function drawPath(ctx: ViewContext2D,
|
|
1
|
+
import type { StrictMaterial, RendererDrawMaterialOptions, ViewContext2D } from '@idraw/types';
|
|
2
|
+
export declare function drawPath(ctx: ViewContext2D, mtrl: StrictMaterial<'path'>, opts: RendererDrawMaterialOptions): void;
|
package/dist/esm/draw/path.js
CHANGED
|
@@ -1,91 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 { rotateElement, generateSVGPath, calcViewElementSize } from '@idraw/util';
|
|
13
|
-
import { drawBox, drawBoxShadow } from './box';
|
|
14
|
-
export function drawPath(ctx, elem, opts) {
|
|
15
|
-
var _a, _b;
|
|
16
|
-
const { detail } = elem;
|
|
17
|
-
const { originX, originY, originW, originH, fillRule } = detail;
|
|
18
|
-
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
19
|
-
const { x, y, w, h, angle } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
20
|
-
const scaleW = w / originW;
|
|
21
|
-
const scaleH = h / originH;
|
|
22
|
-
const viewOriginX = originX * scaleW;
|
|
23
|
-
const viewOriginY = originY * scaleH;
|
|
24
|
-
const internalX = x - viewOriginX;
|
|
25
|
-
const internalY = y - viewOriginY;
|
|
26
|
-
const _c = elem.detail, { clipPath, clipPathStrokeColor, clipPathStrokeWidth } = _c, restDetail = __rest(_c, ["clipPath", "clipPathStrokeColor", "clipPathStrokeWidth"]);
|
|
27
|
-
const scaleNum = viewScaleInfo.scale * viewSizeInfo.devicePixelRatio;
|
|
28
|
-
const viewElem = Object.assign(Object.assign({}, elem), { x, y, w, h, angle });
|
|
29
|
-
let boxViewElem = Object.assign({}, viewElem);
|
|
30
|
-
boxViewElem.detail = restDetail;
|
|
31
|
-
let boxOriginElem = Object.assign({}, elem);
|
|
32
|
-
boxOriginElem.detail = restDetail;
|
|
33
|
-
if (detail.fill &&
|
|
34
|
-
detail.fill !== 'string' &&
|
|
35
|
-
((_b = (_a = detail.fill) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.includes('gradient'))) {
|
|
36
|
-
boxViewElem = Object.assign(Object.assign({}, viewElem), {
|
|
37
|
-
detail: Object.assign(Object.assign({}, viewElem.detail), {
|
|
38
|
-
background: detail.fill,
|
|
39
|
-
clipPath: {
|
|
40
|
-
commands: detail.commands,
|
|
41
|
-
originX,
|
|
42
|
-
originY,
|
|
43
|
-
originW,
|
|
44
|
-
originH
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
});
|
|
48
|
-
boxOriginElem.detail = Object.assign({}, boxViewElem.detail);
|
|
49
|
-
}
|
|
50
|
-
rotateElement(ctx, { x, y, w, h, angle }, () => {
|
|
51
|
-
drawBox(ctx, boxViewElem, {
|
|
52
|
-
originElem: boxOriginElem,
|
|
53
|
-
calcElemSize: { x, y, w, h, angle },
|
|
54
|
-
viewScaleInfo,
|
|
55
|
-
viewSizeInfo,
|
|
56
|
-
parentOpacity,
|
|
57
|
-
renderContent: () => {
|
|
58
|
-
drawBoxShadow(ctx, viewElem, {
|
|
59
|
-
viewScaleInfo,
|
|
60
|
-
viewSizeInfo,
|
|
61
|
-
renderContent: () => {
|
|
62
|
-
ctx.save();
|
|
63
|
-
ctx.translate(internalX, internalY);
|
|
64
|
-
ctx.scale((scaleNum * scaleW) / viewScaleInfo.scale, (scaleNum * scaleH) / viewScaleInfo.scale);
|
|
65
|
-
const pathStr = generateSVGPath(detail.commands || []);
|
|
66
|
-
const path2d = new Path2D(pathStr);
|
|
67
|
-
if (detail.fill) {
|
|
68
|
-
if (typeof detail.fill === 'string') {
|
|
69
|
-
ctx.fillStyle = detail.fill;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
ctx.fillStyle = 'transparent';
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (detail.fill) {
|
|
76
|
-
ctx.fill(path2d, fillRule || 'nonzero');
|
|
77
|
-
}
|
|
78
|
-
if (detail.stroke && detail.strokeWidth !== 0) {
|
|
79
|
-
ctx.strokeStyle = detail.stroke;
|
|
80
|
-
ctx.lineWidth = (detail.strokeWidth || 1) / viewSizeInfo.devicePixelRatio;
|
|
81
|
-
ctx.lineCap = detail.strokeLineCap || 'square';
|
|
82
|
-
ctx.stroke(path2d);
|
|
83
|
-
}
|
|
84
|
-
ctx.translate(-internalX, -internalY);
|
|
85
|
-
ctx.restore();
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
});
|
|
1
|
+
import { rotateViewMaterial, drawBase } from './base';
|
|
2
|
+
export function drawPath(ctx, mtrl, opts) {
|
|
3
|
+
rotateViewMaterial(ctx, mtrl, opts, () => {
|
|
4
|
+
drawBase(ctx, mtrl, opts);
|
|
90
5
|
});
|
|
91
6
|
}
|
package/dist/esm/draw/rect.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function drawRect(ctx: ViewContext2D,
|
|
1
|
+
import type { StrictMaterial, RendererDrawMaterialOptions, ViewContext2D } from '@idraw/types';
|
|
2
|
+
export declare function drawRect(ctx: ViewContext2D, mtrl: StrictMaterial<'rect'>, opts: RendererDrawMaterialOptions): void;
|