@idraw/util 0.4.0-beta.9 → 0.4.0

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 (105) hide show
  1. package/dist/esm/index.d.ts +46 -31
  2. package/dist/esm/index.js +46 -31
  3. package/dist/esm/{lib → tool}/color.js +9 -6
  4. package/dist/esm/{lib → tool}/event.d.ts +1 -0
  5. package/dist/esm/{lib → tool}/event.js +3 -0
  6. package/dist/esm/tool/flat-object.d.ts +6 -0
  7. package/dist/esm/tool/flat-object.js +28 -0
  8. package/dist/esm/tool/get-set-del.d.ts +4 -0
  9. package/dist/esm/tool/get-set-del.js +65 -0
  10. package/dist/esm/{lib → tool}/html.d.ts +1 -1
  11. package/dist/esm/{lib → tool}/html.js +6 -2
  12. package/dist/esm/{lib → tool}/istype.d.ts +1 -0
  13. package/dist/esm/{lib → tool}/istype.js +3 -0
  14. package/dist/esm/tool/merge.d.ts +1 -0
  15. package/dist/esm/tool/merge.js +17 -0
  16. package/dist/esm/tool/omit.d.ts +1 -0
  17. package/dist/esm/tool/omit.js +7 -0
  18. package/dist/esm/tool/store.d.ts +16 -0
  19. package/dist/esm/{lib → tool}/store.js +17 -5
  20. package/dist/esm/tool/unflat-object.d.ts +3 -0
  21. package/dist/esm/tool/unflat-object.js +91 -0
  22. package/dist/esm/{lib → tool}/uuid.d.ts +1 -1
  23. package/dist/esm/tool/uuid.js +39 -0
  24. package/dist/esm/view/box.d.ts +2 -0
  25. package/dist/esm/view/box.js +173 -0
  26. package/dist/esm/{lib → view}/canvas.d.ts +0 -1
  27. package/dist/esm/view/canvas.js +57 -0
  28. package/dist/esm/{lib → view}/check.js +14 -14
  29. package/dist/esm/{lib → view}/config.js +2 -2
  30. package/dist/esm/{lib → view}/context2d.d.ts +4 -0
  31. package/dist/esm/{lib → view}/context2d.js +20 -0
  32. package/dist/esm/view/controller.d.ts +12 -0
  33. package/dist/esm/view/controller.js +321 -0
  34. package/dist/esm/{lib → view}/data.d.ts +1 -0
  35. package/dist/esm/{lib → view}/data.js +43 -22
  36. package/dist/esm/{lib → view}/element.d.ts +5 -0
  37. package/dist/esm/{lib → view}/element.js +66 -5
  38. package/dist/esm/view/flat.d.ts +2 -0
  39. package/dist/esm/view/flat.js +133 -0
  40. package/dist/esm/view/group.d.ts +3 -0
  41. package/dist/esm/view/group.js +81 -0
  42. package/dist/esm/{lib → view}/handle-element.d.ts +11 -1
  43. package/dist/esm/{lib → view}/handle-element.js +102 -51
  44. package/dist/esm/view/handle-global.d.ts +4 -0
  45. package/dist/esm/view/handle-global.js +28 -0
  46. package/dist/esm/view/handle-layout.d.ts +4 -0
  47. package/dist/esm/view/handle-layout.js +28 -0
  48. package/dist/esm/{lib → view}/is.d.ts +3 -1
  49. package/dist/esm/{lib → view}/is.js +22 -6
  50. package/dist/esm/view/modify-record.d.ts +4 -0
  51. package/dist/esm/view/modify-record.js +10 -0
  52. package/dist/esm/view/point-move-element.d.ts +5 -0
  53. package/dist/esm/view/point-move-element.js +26 -0
  54. package/dist/esm/view/position.d.ts +15 -0
  55. package/dist/esm/view/position.js +79 -0
  56. package/dist/esm/view/rect.js +11 -0
  57. package/dist/esm/view/resize-element.d.ts +4 -0
  58. package/dist/esm/view/resize-element.js +255 -0
  59. package/dist/esm/{lib → view}/rotate.js +8 -13
  60. package/dist/esm/view/text.d.ts +1 -0
  61. package/dist/esm/view/text.js +4 -0
  62. package/dist/esm/{lib → view}/view-box.js +3 -1
  63. package/dist/esm/{lib → view}/view-calc.d.ts +16 -3
  64. package/dist/esm/{lib → view}/view-calc.js +127 -3
  65. package/dist/esm/view/view-content.d.ts +14 -0
  66. package/dist/esm/view/view-content.js +88 -0
  67. package/dist/index.global.js +1938 -346
  68. package/dist/index.global.min.js +1 -1
  69. package/package.json +2 -2
  70. package/dist/esm/lib/canvas.js +0 -81
  71. package/dist/esm/lib/controller.d.ts +0 -6
  72. package/dist/esm/lib/controller.js +0 -103
  73. package/dist/esm/lib/rect.js +0 -11
  74. package/dist/esm/lib/resize-element.d.ts +0 -2
  75. package/dist/esm/lib/resize-element.js +0 -101
  76. package/dist/esm/lib/store.d.ts +0 -11
  77. package/dist/esm/lib/uuid.js +0 -31
  78. /package/dist/esm/{lib → tool}/color.d.ts +0 -0
  79. /package/dist/esm/{lib → tool}/file.d.ts +0 -0
  80. /package/dist/esm/{lib → tool}/file.js +0 -0
  81. /package/dist/esm/{lib → tool}/image.d.ts +0 -0
  82. /package/dist/esm/{lib → tool}/image.js +0 -0
  83. /package/dist/esm/{lib → tool}/number.d.ts +0 -0
  84. /package/dist/esm/{lib → tool}/number.js +0 -0
  85. /package/dist/esm/{lib → tool}/time.d.ts +0 -0
  86. /package/dist/esm/{lib → tool}/time.js +0 -0
  87. /package/dist/esm/{lib → view}/check.d.ts +0 -0
  88. /package/dist/esm/{lib → view}/config.d.ts +0 -0
  89. /package/dist/esm/{lib → view}/load.d.ts +0 -0
  90. /package/dist/esm/{lib → view}/load.js +0 -0
  91. /package/dist/esm/{lib → view}/matrix.d.ts +0 -0
  92. /package/dist/esm/{lib → view}/matrix.js +0 -0
  93. /package/dist/esm/{lib → view}/middleware.d.ts +0 -0
  94. /package/dist/esm/{lib → view}/middleware.js +0 -0
  95. /package/dist/esm/{lib → view}/parser.d.ts +0 -0
  96. /package/dist/esm/{lib → view}/parser.js +0 -0
  97. /package/dist/esm/{lib → view}/point.d.ts +0 -0
  98. /package/dist/esm/{lib → view}/point.js +0 -0
  99. /package/dist/esm/{lib → view}/rect.d.ts +0 -0
  100. /package/dist/esm/{lib → view}/rotate.d.ts +0 -0
  101. /package/dist/esm/{lib → view}/svg-path.d.ts +0 -0
  102. /package/dist/esm/{lib → view}/svg-path.js +0 -0
  103. /package/dist/esm/{lib → view}/vertex.d.ts +0 -0
  104. /package/dist/esm/{lib → view}/vertex.js +0 -0
  105. /package/dist/esm/{lib → view}/view-box.d.ts +0 -0
@@ -0,0 +1,173 @@
1
+ import { is } from './is';
2
+ export function elementToBoxInfo(elem) {
3
+ const { x, y, w, h, detail } = elem;
4
+ const { borderWidth, borderRadius, boxSizing } = detail;
5
+ let btw = 0;
6
+ let brw = 0;
7
+ let bbw = 0;
8
+ let blw = 0;
9
+ let btlr = 0;
10
+ let btrr = 0;
11
+ let bblr = 0;
12
+ let bbrr = 0;
13
+ if (typeof borderWidth === 'number' && borderWidth > 0) {
14
+ btw = borderWidth;
15
+ brw = borderWidth;
16
+ bbw = borderWidth;
17
+ blw = borderWidth;
18
+ }
19
+ else if (Array.isArray(borderWidth)) {
20
+ btw = is.positiveNum(borderWidth[0]) ? borderWidth[0] : 0;
21
+ brw = is.positiveNum(borderWidth[1]) ? borderWidth[0] : 0;
22
+ bbw = is.positiveNum(borderWidth[2]) ? borderWidth[0] : 0;
23
+ blw = is.positiveNum(borderWidth[3]) ? borderWidth[0] : 0;
24
+ }
25
+ if (typeof borderRadius === 'number' && borderRadius > 0) {
26
+ btlr = borderRadius;
27
+ btrr = borderRadius;
28
+ bblr = borderRadius;
29
+ bbrr = borderRadius;
30
+ }
31
+ else if (Array.isArray(borderRadius)) {
32
+ btlr = is.positiveNum(borderRadius[0]) ? borderRadius[0] : 0;
33
+ btrr = is.positiveNum(borderRadius[0]) ? borderRadius[0] : 0;
34
+ bblr = is.positiveNum(borderRadius[0]) ? borderRadius[0] : 0;
35
+ bbrr = is.positiveNum(borderRadius[0]) ? borderRadius[0] : 0;
36
+ }
37
+ const p0 = { x: x, y: y };
38
+ const p1 = { x: x + w, y: y };
39
+ const p2 = { x: x + w, y: y + h };
40
+ const p3 = { x: x, y: y + h };
41
+ const p0s = { x: x, y: y + btlr };
42
+ const p0e = { x: x + btlr, y: y };
43
+ const p1s = { x: x + w - btrr, y: y };
44
+ const p1e = { x: x + w, y: y + btrr };
45
+ const p2s = { x: x + w, y: y + h - bbrr };
46
+ const p2e = { x: x + w - bbrr, y: y + h };
47
+ const p3s = { x: x + bblr, y: y + h };
48
+ const p3e = { x: x, y: y + h - bblr };
49
+ let op0 = Object.assign({}, p0);
50
+ let op1 = Object.assign({}, p1);
51
+ let op2 = Object.assign({}, p2);
52
+ let op3 = Object.assign({}, p3);
53
+ let op0s = Object.assign({}, p0s);
54
+ let op0e = Object.assign({}, p0e);
55
+ let op1s = Object.assign({}, p1s);
56
+ let op1e = Object.assign({}, p1e);
57
+ let op2s = Object.assign({}, p2s);
58
+ let op2e = Object.assign({}, p2e);
59
+ let op3s = Object.assign({}, p3s);
60
+ let op3e = Object.assign({}, p3e);
61
+ let ip0 = Object.assign({}, p0);
62
+ let ip1 = Object.assign({}, p1);
63
+ let ip2 = Object.assign({}, p2);
64
+ let ip3 = Object.assign({}, p3);
65
+ let ip0s = Object.assign({}, p0s);
66
+ let ip0e = Object.assign({}, p0e);
67
+ let ip1s = Object.assign({}, p1s);
68
+ let ip1e = Object.assign({}, p1e);
69
+ let ip2s = Object.assign({}, p2s);
70
+ let ip2e = Object.assign({}, p2e);
71
+ let ip3s = Object.assign({}, p3s);
72
+ let ip3e = Object.assign({}, p3e);
73
+ if (boxSizing === 'border-box') {
74
+ ip0 = { x: ip0.x + blw, y: ip0.y + btw };
75
+ ip1 = { x: ip1.x - brw, y: ip1.y + btw };
76
+ ip2 = { x: ip2.x - brw, y: ip2.y - bbw };
77
+ ip3 = { x: ip3.x + blw, y: ip3.y - bbw };
78
+ ip0s = { x: ip0s.x + blw, y: ip0s.y + btw };
79
+ ip0e = { x: ip0e.x + blw, y: ip0e.y + btw };
80
+ ip1s = { x: ip1s.x - brw, y: ip1s.y + btw };
81
+ ip1e = { x: ip1e.x - brw, y: ip1e.y + btw };
82
+ ip2s = { x: ip2s.x - brw, y: ip2s.y - bbw };
83
+ ip2e = { x: ip2e.x - brw, y: ip2e.y - bbw };
84
+ ip3s = { x: ip3s.x + blw, y: ip3s.y - bbw };
85
+ ip3e = { x: ip3e.x + blw, y: ip3e.y - bbw };
86
+ }
87
+ else if (boxSizing === 'content-box') {
88
+ op0 = { x: op0.x - blw, y: op0.y - btw };
89
+ op1 = { x: op1.x + brw, y: op1.y - btw };
90
+ op2 = { x: op2.x + brw, y: op2.y + bbw };
91
+ op3 = { x: op3.x - blw, y: op3.y + bbw };
92
+ op0s = { x: op0s.x - blw, y: op0s.y - btw };
93
+ op0e = { x: op0e.x - blw, y: op0e.y - btw };
94
+ op1s = { x: op1s.x + brw, y: op1s.y - btw };
95
+ op1e = { x: op1e.x + brw, y: op1e.y - btw };
96
+ op2s = { x: op2s.x + brw, y: op2s.y + bbw };
97
+ op2e = { x: op2e.x + brw, y: op2e.y + bbw };
98
+ op3s = { x: op3s.x - blw, y: op3s.y + bbw };
99
+ op3e = { x: op3e.x - blw, y: op3e.y + bbw };
100
+ }
101
+ else {
102
+ ip0 = { x: ip0.x + blw / 2, y: ip0.y + btw / 2 };
103
+ ip1 = { x: ip1.x - brw / 2, y: ip1.y + btw / 2 };
104
+ ip2 = { x: ip2.x - brw / 2, y: ip2.y - bbw / 2 };
105
+ ip3 = { x: ip3.x + blw / 2, y: ip3.y - bbw / 2 };
106
+ ip0s = { x: ip0s.x + blw / 2, y: ip0s.y + btw / 2 };
107
+ ip0e = { x: ip0e.x + blw / 2, y: ip0e.y + btw / 2 };
108
+ ip1s = { x: ip1s.x - brw / 2, y: ip1s.y + btw / 2 };
109
+ ip1e = { x: ip1e.x - brw / 2, y: ip1e.y + btw / 2 };
110
+ ip2s = { x: ip2s.x - brw / 2, y: ip2s.y - bbw / 2 };
111
+ ip2e = { x: ip2e.x - brw / 2, y: ip2e.y - bbw / 2 };
112
+ ip3s = { x: ip3s.x + blw / 2, y: ip3s.y - bbw / 2 };
113
+ ip3e = { x: ip3e.x + blw / 2, y: ip3e.y - bbw / 2 };
114
+ op0 = { x: op0.x - blw / 2, y: op0.y - btw / 2 };
115
+ op1 = { x: op1.x + brw / 2, y: op1.y - btw / 2 };
116
+ op2 = { x: op2.x + brw / 2, y: op2.y + bbw / 2 };
117
+ op3 = { x: op3.x - blw / 2, y: op3.y + bbw / 2 };
118
+ op0s = { x: op0s.x - blw / 2, y: op0s.y - btw / 2 };
119
+ op0e = { x: op0e.x - blw / 2, y: op0e.y - btw / 2 };
120
+ op1s = { x: op1s.x + brw / 2, y: op1s.y - btw / 2 };
121
+ op1e = { x: op1e.x + brw / 2, y: op1e.y - btw / 2 };
122
+ op2s = { x: op2s.x + brw / 2, y: op2s.y + bbw / 2 };
123
+ op2e = { x: op2e.x + brw / 2, y: op2e.y + bbw / 2 };
124
+ op3s = { x: op3s.x - blw / 2, y: op3s.y + bbw / 2 };
125
+ op3e = { x: op3e.x - blw / 2, y: op3e.y + bbw / 2 };
126
+ }
127
+ return {
128
+ btw,
129
+ brw,
130
+ bbw,
131
+ blw,
132
+ btlr,
133
+ btrr,
134
+ bblr,
135
+ bbrr,
136
+ p0,
137
+ p1,
138
+ p2,
139
+ p3,
140
+ p0s,
141
+ p0e,
142
+ p1s,
143
+ p1e,
144
+ p2s,
145
+ p2e,
146
+ p3s,
147
+ p3e,
148
+ op0,
149
+ op1,
150
+ op2,
151
+ op3,
152
+ op0s,
153
+ op0e,
154
+ op1s,
155
+ op1e,
156
+ op2s,
157
+ op2e,
158
+ op3s,
159
+ op3e,
160
+ ip0,
161
+ ip1,
162
+ ip2,
163
+ ip3,
164
+ ip0s,
165
+ ip0e,
166
+ ip1s,
167
+ ip1e,
168
+ ip2s,
169
+ ip2e,
170
+ ip3s,
171
+ ip3e
172
+ };
173
+ }
@@ -15,5 +15,4 @@ export declare function createBoardContent(canvas: HTMLCanvasElement, opts: {
15
15
  width: number;
16
16
  height: number;
17
17
  devicePixelRatio: number;
18
- offscreen?: boolean;
19
18
  }): BoardContent;
@@ -0,0 +1,57 @@
1
+ import { Context2D } from './context2d';
2
+ export function createContext2D(opts) {
3
+ const { width, height, ctx, devicePixelRatio } = opts;
4
+ let context = ctx;
5
+ if (!context) {
6
+ const canvas = document.createElement('canvas');
7
+ canvas.width = width * devicePixelRatio;
8
+ canvas.height = height * devicePixelRatio;
9
+ context = canvas.getContext('2d');
10
+ }
11
+ const context2d = new Context2D(context, opts);
12
+ return context2d;
13
+ }
14
+ export function createOffscreenContext2D(opts) {
15
+ const { width, height, devicePixelRatio } = opts;
16
+ const offCanvas = new OffscreenCanvas(width * devicePixelRatio, height * devicePixelRatio);
17
+ const offRenderCtx = offCanvas.getContext('2d');
18
+ const offCtx = offRenderCtx.canvas.getContext('2d');
19
+ const context2d = new Context2D(offCtx, {
20
+ devicePixelRatio,
21
+ offscreenCanvas: offCanvas
22
+ });
23
+ return context2d;
24
+ }
25
+ export function createBoardContent(canvas, opts) {
26
+ const { width, height, devicePixelRatio } = opts;
27
+ const ctxOpts = {
28
+ width,
29
+ height,
30
+ devicePixelRatio
31
+ };
32
+ const ctx = canvas.getContext('2d');
33
+ const viewContext = createOffscreenContext2D(ctxOpts);
34
+ const overlayContext = createOffscreenContext2D(ctxOpts);
35
+ const underlayContext = createOffscreenContext2D(ctxOpts);
36
+ const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
37
+ const tempContext = createOffscreenContext2D(ctxOpts);
38
+ const drawView = () => {
39
+ const { width: w, height: h } = viewContext.$getSize();
40
+ boardContext.clearRect(0, 0, w, h);
41
+ boardContext.drawImage(underlayContext.canvas, 0, 0, w, h);
42
+ boardContext.drawImage(viewContext.canvas, 0, 0, w, h);
43
+ boardContext.drawImage(overlayContext.canvas, 0, 0, w, h);
44
+ underlayContext.clearRect(0, 0, w, h);
45
+ viewContext.clearRect(0, 0, w, h);
46
+ overlayContext.clearRect(0, 0, w, h);
47
+ };
48
+ const content = {
49
+ underlayContext,
50
+ viewContext,
51
+ overlayContext,
52
+ boardContext,
53
+ tempContext,
54
+ drawView
55
+ };
56
+ return content;
57
+ }
@@ -11,20 +11,20 @@ function attrs(attrs) {
11
11
  }
12
12
  function box(detail = {}) {
13
13
  const { borderColor, borderRadius, borderWidth } = detail;
14
- if (detail.hasOwnProperty('borderColor') && !is.color(borderColor)) {
14
+ if (Object.prototype.hasOwnProperty.call(detail, 'borderColor') && !is.color(borderColor)) {
15
15
  return false;
16
16
  }
17
- if (detail.hasOwnProperty('borderRadius') && !is.number(borderRadius)) {
17
+ if (Object.prototype.hasOwnProperty.call(detail, 'borderRadius') && !is.number(borderRadius)) {
18
18
  return false;
19
19
  }
20
- if (detail.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
20
+ if (Object.prototype.hasOwnProperty.call(detail, 'borderWidth') && !is.number(borderWidth)) {
21
21
  return false;
22
22
  }
23
23
  return true;
24
24
  }
25
25
  function rectDesc(detail) {
26
26
  const { background } = detail;
27
- if (detail.hasOwnProperty('background') && !is.color(background)) {
27
+ if (Object.prototype.hasOwnProperty.call(detail, 'background') && !is.color(background)) {
28
28
  return false;
29
29
  }
30
30
  if (!box(detail)) {
@@ -34,13 +34,13 @@ function rectDesc(detail) {
34
34
  }
35
35
  function circleDesc(detail) {
36
36
  const { background, borderColor, borderWidth } = detail;
37
- if (detail.hasOwnProperty('background') && !is.color(background)) {
37
+ if (Object.prototype.hasOwnProperty.call(detail, 'background') && !is.color(background)) {
38
38
  return false;
39
39
  }
40
- if (detail.hasOwnProperty('borderColor') && !is.color(borderColor)) {
40
+ if (Object.prototype.hasOwnProperty.call(detail, 'borderColor') && !is.color(borderColor)) {
41
41
  return false;
42
42
  }
43
- if (detail.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
43
+ if (Object.prototype.hasOwnProperty.call(detail, 'borderWidth') && !is.number(borderWidth)) {
44
44
  return false;
45
45
  }
46
46
  return true;
@@ -77,25 +77,25 @@ function textDesc(detail) {
77
77
  if (!is.fontSize(fontSize)) {
78
78
  return false;
79
79
  }
80
- if (detail.hasOwnProperty('background') && !is.color(background)) {
80
+ if (Object.prototype.hasOwnProperty.call(detail, 'background') && !is.color(background)) {
81
81
  return false;
82
82
  }
83
- if (detail.hasOwnProperty('fontWeight') && !is.fontWeight(fontWeight)) {
83
+ if (Object.prototype.hasOwnProperty.call(detail, 'fontWeight') && !is.fontWeight(fontWeight)) {
84
84
  return false;
85
85
  }
86
- if (detail.hasOwnProperty('lineHeight') && !is.lineHeight(lineHeight)) {
86
+ if (Object.prototype.hasOwnProperty.call(detail, 'lineHeight') && !is.lineHeight(lineHeight)) {
87
87
  return false;
88
88
  }
89
- if (detail.hasOwnProperty('fontFamily') && !is.fontFamily(fontFamily)) {
89
+ if (Object.prototype.hasOwnProperty.call(detail, 'fontFamily') && !is.fontFamily(fontFamily)) {
90
90
  return false;
91
91
  }
92
- if (detail.hasOwnProperty('textAlign') && !is.textAlign(textAlign)) {
92
+ if (Object.prototype.hasOwnProperty.call(detail, 'textAlign') && !is.textAlign(textAlign)) {
93
93
  return false;
94
94
  }
95
- if (detail.hasOwnProperty('strokeWidth') && !is.strokeWidth(strokeWidth)) {
95
+ if (Object.prototype.hasOwnProperty.call(detail, 'strokeWidth') && !is.strokeWidth(strokeWidth)) {
96
96
  return false;
97
97
  }
98
- if (detail.hasOwnProperty('strokeColor') && !is.color(strokeColor)) {
98
+ if (Object.prototype.hasOwnProperty.call(detail, 'strokeColor') && !is.color(strokeColor)) {
99
99
  return false;
100
100
  }
101
101
  if (!box(detail)) {
@@ -15,9 +15,10 @@ export function getDefaultElementDetailConfig() {
15
15
  textAlign: 'left',
16
16
  verticalAlign: 'top',
17
17
  fontSize: 16,
18
- lineHeight: 20,
19
18
  fontFamily: 'sans-serif',
20
19
  fontWeight: 400,
20
+ minInlineSize: 'auto',
21
+ wordBreak: 'break-all',
21
22
  overflow: 'hidden'
22
23
  };
23
24
  return config;
@@ -42,7 +43,6 @@ export function getDefaultElementTextDetail(elementSize) {
42
43
  color: detailConfig.color,
43
44
  fontFamily: detailConfig.fontFamily,
44
45
  fontWeight: detailConfig.fontWeight,
45
- lineHeight: elementSize.w / defaultText.length,
46
46
  fontSize: elementSize.w / defaultText.length,
47
47
  textAlign: 'center',
48
48
  verticalAlign: 'middle'
@@ -5,11 +5,13 @@ export declare class Context2D implements ViewContext2D {
5
5
  $undoPixelRatio(num: number): number;
6
6
  $doPixelRatio(num: number): number;
7
7
  $getContext(): CanvasRenderingContext2D;
8
+ $setContext(ctx: CanvasRenderingContext2D): void;
8
9
  $setFont(opts: {
9
10
  fontSize: number;
10
11
  fontFamily?: string;
11
12
  fontWeight?: 'bold' | number | string;
12
13
  }): void;
14
+ $resetFont(): void;
13
15
  $getOffscreenCanvas(): OffscreenCanvas | null;
14
16
  $resize(opts: {
15
17
  width: number;
@@ -57,6 +59,8 @@ export declare class Context2D implements ViewContext2D {
57
59
  lineTo(x: number, y: number): void;
58
60
  moveTo(x: number, y: number): void;
59
61
  arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
62
+ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
63
+ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
60
64
  getLineDash(): number[];
61
65
  setLineDash(nums: number[]): void;
62
66
  stroke(path?: Path2D): void;
@@ -10,12 +10,16 @@ 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 _Context2D_ctx, _Context2D_opts;
13
+ const defaultFontSize = 12;
14
+ const defaultFontWeight = '400';
15
+ const defaultFontFamily = `-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'`;
13
16
  export class Context2D {
14
17
  constructor(ctx, opts) {
15
18
  _Context2D_ctx.set(this, void 0);
16
19
  _Context2D_opts.set(this, void 0);
17
20
  __classPrivateFieldSet(this, _Context2D_ctx, ctx, "f");
18
21
  __classPrivateFieldSet(this, _Context2D_opts, Object.assign({ devicePixelRatio: 1, offscreenCanvas: null }, opts), "f");
22
+ this.$resetFont();
19
23
  }
20
24
  $undoPixelRatio(num) {
21
25
  return num / __classPrivateFieldGet(this, _Context2D_opts, "f").devicePixelRatio;
@@ -26,6 +30,9 @@ export class Context2D {
26
30
  $getContext() {
27
31
  return __classPrivateFieldGet(this, _Context2D_ctx, "f");
28
32
  }
33
+ $setContext(ctx) {
34
+ __classPrivateFieldSet(this, _Context2D_ctx, ctx, "f");
35
+ }
29
36
  $setFont(opts) {
30
37
  const strList = [];
31
38
  if (opts.fontWeight) {
@@ -35,6 +42,13 @@ export class Context2D {
35
42
  strList.push(`${opts.fontFamily || 'sans-serif'}`);
36
43
  __classPrivateFieldGet(this, _Context2D_ctx, "f").font = `${strList.join(' ')}`;
37
44
  }
45
+ $resetFont() {
46
+ this.$setFont({
47
+ fontSize: defaultFontSize,
48
+ fontFamily: defaultFontFamily,
49
+ fontWeight: defaultFontWeight
50
+ });
51
+ }
38
52
  $getOffscreenCanvas() {
39
53
  return __classPrivateFieldGet(this, _Context2D_opts, "f").offscreenCanvas;
40
54
  }
@@ -165,6 +179,12 @@ export class Context2D {
165
179
  arcTo(x1, y1, x2, y2, radius) {
166
180
  return __classPrivateFieldGet(this, _Context2D_ctx, "f").arcTo(this.$doPixelRatio(x1), this.$doPixelRatio(y1), this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius));
167
181
  }
182
+ bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
183
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").bezierCurveTo(this.$doPixelRatio(cp1x), this.$doPixelRatio(cp1y), this.$doPixelRatio(cp2x), this.$doPixelRatio(cp2y), this.$doPixelRatio(x), this.$doPixelRatio(y));
184
+ }
185
+ quadraticCurveTo(cpx, cpy, x, y) {
186
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").quadraticCurveTo(this.$doPixelRatio(cpx), this.$doPixelRatio(cpy), this.$doPixelRatio(x), this.$doPixelRatio(y));
187
+ }
168
188
  getLineDash() {
169
189
  return __classPrivateFieldGet(this, _Context2D_ctx, "f").getLineDash();
170
190
  }
@@ -0,0 +1,12 @@
1
+ import type { Element, ElementSize, ElementSizeController, ViewScaleInfo, LayoutSizeController } from '@idraw/types';
2
+ export declare function calcElementSizeController(elemSize: ElementSize, opts: {
3
+ groupQueue: Element<'group'>[];
4
+ controllerSize: number;
5
+ rotateControllerSize: number;
6
+ rotateControllerPosition: number;
7
+ viewScaleInfo: ViewScaleInfo;
8
+ }): ElementSizeController;
9
+ export declare function calcLayoutSizeController(layoutSize: Pick<ElementSize, 'x' | 'y' | 'w' | 'h'>, opts: {
10
+ controllerSize?: number;
11
+ viewScaleInfo: ViewScaleInfo;
12
+ }): LayoutSizeController;