@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.
Files changed (68) hide show
  1. package/dist/esm/calculator.d.ts +17 -12
  2. package/dist/esm/calculator.js +103 -88
  3. package/dist/esm/draw/base.d.ts +19 -0
  4. package/dist/esm/draw/base.js +141 -0
  5. package/dist/esm/draw/box.d.ts +2 -28
  6. package/dist/esm/draw/box.js +3 -335
  7. package/dist/esm/draw/circle.d.ts +2 -2
  8. package/dist/esm/draw/circle.js +4 -72
  9. package/dist/esm/draw/color.d.ts +3 -3
  10. package/dist/esm/draw/color.js +10 -8
  11. package/dist/esm/draw/ellipse.d.ts +2 -0
  12. package/dist/esm/draw/ellipse.js +6 -0
  13. package/dist/esm/draw/foreign-object.d.ts +2 -0
  14. package/dist/esm/draw/foreign-object.js +15 -0
  15. package/dist/esm/draw/global.d.ts +2 -2
  16. package/dist/esm/draw/global.js +2 -2
  17. package/dist/esm/draw/group.d.ts +3 -3
  18. package/dist/esm/draw/group.js +60 -94
  19. package/dist/esm/draw/image.d.ts +2 -2
  20. package/dist/esm/draw/image.js +70 -86
  21. package/dist/esm/draw/index.d.ts +6 -5
  22. package/dist/esm/draw/index.js +6 -5
  23. package/dist/esm/draw/layout.d.ts +2 -2
  24. package/dist/esm/draw/layout.js +21 -35
  25. package/dist/esm/draw/materials.d.ts +2 -0
  26. package/dist/esm/draw/materials.js +27 -0
  27. package/dist/esm/draw/path.d.ts +2 -2
  28. package/dist/esm/draw/path.js +4 -89
  29. package/dist/esm/draw/rect.d.ts +2 -2
  30. package/dist/esm/draw/rect.js +4 -22
  31. package/dist/esm/draw/svg-code.d.ts +2 -0
  32. package/dist/esm/draw/svg-code.js +15 -0
  33. package/dist/esm/draw/text.d.ts +2 -2
  34. package/dist/esm/draw/text.js +60 -50
  35. package/dist/esm/index.d.ts +1 -1
  36. package/dist/esm/index.js +15 -15
  37. package/dist/esm/loader.d.ts +4 -4
  38. package/dist/esm/loader.js +68 -70
  39. package/dist/esm/virtual/base.d.ts +2 -0
  40. package/dist/esm/virtual/base.js +52 -0
  41. package/dist/esm/virtual/circle.d.ts +2 -0
  42. package/dist/esm/virtual/circle.js +38 -0
  43. package/dist/esm/virtual/ellipse.d.ts +2 -0
  44. package/dist/esm/virtual/ellipse.js +40 -0
  45. package/dist/esm/virtual/index.d.ts +6 -0
  46. package/dist/esm/virtual/index.js +77 -0
  47. package/dist/esm/virtual/path.d.ts +2 -0
  48. package/dist/esm/virtual/path.js +10 -0
  49. package/dist/esm/virtual/rect.d.ts +2 -0
  50. package/dist/esm/virtual/rect.js +146 -0
  51. package/dist/esm/virtual/text.d.ts +2 -0
  52. package/dist/esm/virtual/text.js +165 -0
  53. package/dist/esm/visible/index.d.ts +22 -0
  54. package/dist/esm/{view-visible → visible}/index.js +29 -23
  55. package/dist/index.global.js +1794 -1578
  56. package/dist/index.global.min.js +1 -1
  57. package/package.json +3 -3
  58. package/dist/esm/draw/elements.d.ts +0 -2
  59. package/dist/esm/draw/elements.js +0 -27
  60. package/dist/esm/draw/html.d.ts +0 -2
  61. package/dist/esm/draw/html.js +0 -17
  62. package/dist/esm/draw/svg.d.ts +0 -2
  63. package/dist/esm/draw/svg.js +0 -17
  64. package/dist/esm/view-visible/index.d.ts +0 -22
  65. package/dist/esm/virtual-flat/index.d.ts +0 -7
  66. package/dist/esm/virtual-flat/index.js +0 -45
  67. package/dist/esm/virtual-flat/text.d.ts +0 -2
  68. package/dist/esm/virtual-flat/text.js +0 -151
@@ -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 { drawSVG } from './svg';
7
- import { drawHTML } from './html';
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 drawElement(ctx, elem, opts) {
11
+ export function drawMaterial(ctx, mtrl, opts) {
12
12
  var _a, _b, _c;
13
- if (((_a = elem === null || elem === void 0 ? void 0 : elem.operations) === null || _a === void 0 ? void 0 : _a.invisible) === true) {
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 { w, h } = elem;
16
+ const { width, height } = mtrl;
17
17
  const { scale } = opts.viewScaleInfo;
18
- if ((scale < 1 && (w * scale < visiableMinSize || h * scale < visiableMinSize)) || opts.parentOpacity === 0) {
18
+ if ((scale < 1 && (width * scale < visiableMinSize || height * scale < visiableMinSize)) ||
19
+ opts.parentOpacity === 0) {
19
20
  return;
20
21
  }
21
- const { overrideElementMap } = opts;
22
- if ((_c = (_b = overrideElementMap === null || overrideElementMap === void 0 ? void 0 : overrideElementMap[elem.uuid]) === null || _b === void 0 ? void 0 : _b.operations) === null || _c === void 0 ? void 0 : _c.invisible) {
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 (elem.type) {
27
+ switch (mtrl.type) {
27
28
  case 'rect': {
28
- drawRect(ctx, elem, opts);
29
+ drawRect(ctx, mtrl, opts);
29
30
  break;
30
31
  }
31
32
  case 'circle': {
32
- drawCircle(ctx, elem, opts);
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, elem, opts);
41
+ drawText(ctx, mtrl, opts);
37
42
  break;
38
43
  }
39
44
  case 'image': {
40
- drawImage(ctx, elem, opts);
45
+ drawImage(ctx, mtrl, opts);
41
46
  break;
42
47
  }
43
- case 'svg': {
44
- drawSVG(ctx, elem, opts);
48
+ case 'svgCode': {
49
+ drawSVGCode(ctx, mtrl, opts);
45
50
  break;
46
51
  }
47
- case 'html': {
48
- drawHTML(ctx, elem, opts);
52
+ case 'foreignObject': {
53
+ drawForeignObject(ctx, mtrl, opts);
49
54
  break;
50
55
  }
51
56
  case 'path': {
52
- drawPath(ctx, elem, opts);
57
+ drawPath(ctx, mtrl, opts);
53
58
  break;
54
59
  }
55
60
  case 'group': {
56
- const assets = Object.assign(Object.assign({}, (opts.elementAssets || {})), (elem.detail.assets || {}));
57
- drawGroup(ctx, elem, Object.assign(Object.assign({}, opts), { elementAssets: assets }));
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, elem, opts) {
70
- const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
71
- const { x, y, w, h, angle } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h, angle: elem.angle }, { viewScaleInfo }) || elem;
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
  }
@@ -1,2 +1,2 @@
1
- import type { Element, RendererDrawElementOptions, ViewContext2D } from '@idraw/types';
2
- export declare function drawImage(ctx: ViewContext2D, elem: Element<'image'>, opts: RendererDrawElementOptions): void;
1
+ import type { StrictMaterial, RendererDrawMaterialOptions, ViewContext2D } from '@idraw/types';
2
+ export declare function drawImage(ctx: ViewContext2D, mtrl: StrictMaterial<'image'>, opts: RendererDrawMaterialOptions): void;
@@ -1,90 +1,74 @@
1
- import { rotateElement, calcViewBoxSize, calcViewElementSize } from '@idraw/util';
2
- import { drawBox, drawBoxShadow, getOpacity } from './box';
3
- export function drawImage(ctx, elem, opts) {
4
- const content = opts.loader.getContent(elem);
5
- const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
6
- const { x, y, w, h, angle } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
7
- const viewElem = Object.assign(Object.assign({}, elem), { x, y, w, h, angle });
8
- rotateElement(ctx, { x, y, w, h, angle }, () => {
9
- drawBoxShadow(ctx, viewElem, {
10
- viewScaleInfo,
11
- viewSizeInfo,
12
- renderContent: () => {
13
- drawBox(ctx, viewElem, {
14
- originElem: elem,
15
- calcElemSize: { x, y, w, h, angle },
16
- viewScaleInfo,
17
- viewSizeInfo,
18
- parentOpacity,
19
- renderContent: () => {
20
- if (!content && !opts.loader.isDestroyed()) {
21
- opts.loader.load(elem, opts.elementAssets || {});
22
- }
23
- if (elem.type === 'image' && content) {
24
- ctx.globalAlpha = getOpacity(elem) * parentOpacity;
25
- const { x, y, w, h, radiusList } = calcViewBoxSize(viewElem, {
26
- viewScaleInfo,
27
- viewSizeInfo
28
- });
29
- const { detail } = elem;
30
- const { scaleMode, originW = 0, originH = 0 } = detail;
31
- const imageW = ctx.$undoPixelRatio(originW);
32
- const imageH = ctx.$undoPixelRatio(originH);
33
- ctx.save();
34
- ctx.fillStyle = 'transparent';
35
- ctx.beginPath();
36
- ctx.moveTo(x + radiusList[0], y);
37
- ctx.arcTo(x + w, y, x + w, y + h, radiusList[1]);
38
- ctx.arcTo(x + w, y + h, x, y + h, radiusList[2]);
39
- ctx.arcTo(x, y + h, x, y, radiusList[3]);
40
- ctx.arcTo(x, y, x + w, y, radiusList[0]);
41
- ctx.closePath();
42
- ctx.fill('nonzero');
43
- ctx.clip('nonzero');
44
- if (scaleMode && originH && originW) {
45
- let sx = 0;
46
- let sy = 0;
47
- let sWidth = imageW;
48
- let sHeight = imageH;
49
- const dx = x;
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
  }
@@ -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 { drawSVG } from './svg';
5
- export { drawHTML } from './html';
5
+ export { drawSVGCode } from './svg-code';
6
+ export { drawForeignObject } from './foreign-object';
6
7
  export { drawText } from './text';
7
- export { drawGroup, drawElement } from './group';
8
- export { drawElementList } from './elements';
8
+ export { drawGroup, drawMaterial } from './group';
9
+ export { drawMaterialList } from './materials';
9
10
  export { drawLayout } from './layout';
10
11
  export { drawGlobalBackground } from './global';
@@ -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 { drawSVG } from './svg';
5
- export { drawHTML } from './html';
5
+ export { drawSVGCode } from './svg-code';
6
+ export { drawForeignObject } from './foreign-object';
6
7
  export { drawText } from './text';
7
- export { drawGroup, drawElement } from './group';
8
- export { drawElementList } from './elements';
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 { RendererDrawElementOptions, ViewContext2D, DataLayout } from '@idraw/types';
2
- export declare function drawLayout(ctx: ViewContext2D, layout: DataLayout, opts: RendererDrawElementOptions, renderContent: (ctx: ViewContext2D) => void): void;
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;
@@ -1,44 +1,30 @@
1
- import { calcViewElementSize, calcViewBoxSize } from '@idraw/util';
2
- import { drawBoxShadow, drawBoxBackground, drawBoxBorder } from './box';
1
+ import { calcViewMaterialSize } from '@idraw/util';
2
+ import { createColor } from './color';
3
3
  export function drawLayout(ctx, layout, opts, renderContent) {
4
- const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
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
- drawBoxShadow(ctx, viewElem, {
11
- viewScaleInfo,
12
- viewSizeInfo,
13
- renderContent: () => {
14
- drawBoxBackground(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
15
- }
16
- });
17
- if (layout.detail.overflow === 'hidden') {
18
- const { viewScaleInfo, viewSizeInfo } = opts;
19
- const elem = Object.assign({ uuid: 'layout', type: 'group' }, layout);
20
- const viewElemSize = calcViewElementSize(elem, { viewScaleInfo }) || elem;
21
- const viewElem = Object.assign(Object.assign({}, elem), viewElemSize);
22
- const { x, y, w, h, radiusList } = calcViewBoxSize(viewElem, {
23
- viewScaleInfo,
24
- viewSizeInfo
25
- });
26
- ctx.save();
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.detail.overflow === 'hidden') {
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,2 @@
1
+ import type { Data, RendererDrawMaterialOptions, ViewContext2D } from '@idraw/types';
2
+ export declare function drawMaterialList(ctx: ViewContext2D, data: Data, opts: RendererDrawMaterialOptions): void;
@@ -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
+ }
@@ -1,2 +1,2 @@
1
- import type { Element, RendererDrawElementOptions, ViewContext2D } from '@idraw/types';
2
- export declare function drawPath(ctx: ViewContext2D, elem: Element<'path'>, opts: RendererDrawElementOptions): void;
1
+ import type { StrictMaterial, RendererDrawMaterialOptions, ViewContext2D } from '@idraw/types';
2
+ export declare function drawPath(ctx: ViewContext2D, mtrl: StrictMaterial<'path'>, opts: RendererDrawMaterialOptions): void;
@@ -1,91 +1,6 @@
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 { 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
  }
@@ -1,2 +1,2 @@
1
- import type { Element, RendererDrawElementOptions, ViewContext2D } from '@idraw/types';
2
- export declare function drawRect(ctx: ViewContext2D, elem: Element<'rect'>, opts: RendererDrawElementOptions): void;
1
+ import type { StrictMaterial, RendererDrawMaterialOptions, ViewContext2D } from '@idraw/types';
2
+ export declare function drawRect(ctx: ViewContext2D, mtrl: StrictMaterial<'rect'>, opts: RendererDrawMaterialOptions): void;