@meta2d/core 1.0.55 → 1.0.57

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 (223) hide show
  1. package/index.d.ts +9 -9
  2. package/index.js +9 -9
  3. package/package.json +38 -39
  4. package/src/canvas/canvas.d.ts +456 -456
  5. package/src/canvas/canvas.js +7583 -8186
  6. package/src/canvas/canvas.js.map +1 -1
  7. package/src/canvas/canvasImage.d.ts +27 -28
  8. package/src/canvas/canvasImage.js +440 -502
  9. package/src/canvas/canvasImage.js.map +1 -1
  10. package/src/canvas/canvasTemplate.d.ts +18 -19
  11. package/src/canvas/canvasTemplate.js +208 -228
  12. package/src/canvas/canvasTemplate.js.map +1 -1
  13. package/src/canvas/index.d.ts +2 -2
  14. package/src/canvas/index.js +2 -2
  15. package/src/canvas/magnifierCanvas.d.ts +19 -20
  16. package/src/canvas/magnifierCanvas.js +101 -100
  17. package/src/canvas/magnifierCanvas.js.map +1 -1
  18. package/src/canvas/offscreen.d.ts +1 -2
  19. package/src/canvas/offscreen.js +13 -13
  20. package/src/canvas/offscreen.js.map +1 -1
  21. package/src/core.d.ts +479 -479
  22. package/src/core.js +4589 -5198
  23. package/src/core.js.map +1 -1
  24. package/src/data.d.ts +34 -34
  25. package/src/data.js +84 -84
  26. package/src/data.js.map +1 -1
  27. package/src/diagrams/arrow.d.ts +4 -4
  28. package/src/diagrams/arrow.js +46 -46
  29. package/src/diagrams/arrow.js.map +1 -1
  30. package/src/diagrams/circle.d.ts +2 -2
  31. package/src/diagrams/circle.js +8 -8
  32. package/src/diagrams/circle.js.map +1 -1
  33. package/src/diagrams/cloud.d.ts +2 -2
  34. package/src/diagrams/cloud.js +11 -11
  35. package/src/diagrams/cloud.js.map +1 -1
  36. package/src/diagrams/cube.d.ts +2 -2
  37. package/src/diagrams/cube.js +67 -69
  38. package/src/diagrams/cube.js.map +1 -1
  39. package/src/diagrams/diamond.d.ts +2 -2
  40. package/src/diagrams/diamond.js +12 -12
  41. package/src/diagrams/diamond.js.map +1 -1
  42. package/src/diagrams/file.d.ts +2 -2
  43. package/src/diagrams/file.js +17 -17
  44. package/src/diagrams/file.js.map +1 -1
  45. package/src/diagrams/gif.d.ts +5 -5
  46. package/src/diagrams/gif.js +88 -89
  47. package/src/diagrams/gif.js.map +1 -1
  48. package/src/diagrams/hexagon.d.ts +2 -2
  49. package/src/diagrams/hexagon.js +54 -54
  50. package/src/diagrams/hexagon.js.map +1 -1
  51. package/src/diagrams/iframe.d.ts +2 -2
  52. package/src/diagrams/iframe.js +337 -355
  53. package/src/diagrams/iframe.js.map +1 -1
  54. package/src/diagrams/index.d.ts +71 -71
  55. package/src/diagrams/index.js +76 -76
  56. package/src/diagrams/index.js.map +1 -1
  57. package/src/diagrams/line/arrow.d.ts +2 -2
  58. package/src/diagrams/line/arrow.js +127 -127
  59. package/src/diagrams/line/arrow.js.map +1 -1
  60. package/src/diagrams/line/curve.d.ts +16 -16
  61. package/src/diagrams/line/curve.js +226 -235
  62. package/src/diagrams/line/curve.js.map +1 -1
  63. package/src/diagrams/line/index.d.ts +5 -5
  64. package/src/diagrams/line/index.js +5 -5
  65. package/src/diagrams/line/line.d.ts +42 -42
  66. package/src/diagrams/line/line.js +369 -430
  67. package/src/diagrams/line/line.js.map +1 -1
  68. package/src/diagrams/line/polyline.d.ts +10 -10
  69. package/src/diagrams/line/polyline.js +626 -656
  70. package/src/diagrams/line/polyline.js.map +1 -1
  71. package/src/diagrams/line/smooth.d.ts +3 -3
  72. package/src/diagrams/line/smooth.js +135 -173
  73. package/src/diagrams/line/smooth.js.map +1 -1
  74. package/src/diagrams/message.d.ts +2 -2
  75. package/src/diagrams/message.js +14 -14
  76. package/src/diagrams/message.js.map +1 -1
  77. package/src/diagrams/mindLine.d.ts +3 -3
  78. package/src/diagrams/mindLine.js +29 -30
  79. package/src/diagrams/mindLine.js.map +1 -1
  80. package/src/diagrams/mindNode.d.ts +3 -3
  81. package/src/diagrams/mindNode.js +160 -188
  82. package/src/diagrams/mindNode.js.map +1 -1
  83. package/src/diagrams/panel.d.ts +2 -2
  84. package/src/diagrams/panel.js +130 -130
  85. package/src/diagrams/panel.js.map +1 -1
  86. package/src/diagrams/pentagon.d.ts +3 -3
  87. package/src/diagrams/pentagon.js +44 -45
  88. package/src/diagrams/pentagon.js.map +1 -1
  89. package/src/diagrams/pentagram.d.ts +3 -3
  90. package/src/diagrams/pentagram.js +50 -76
  91. package/src/diagrams/pentagram.js.map +1 -1
  92. package/src/diagrams/people.d.ts +2 -2
  93. package/src/diagrams/people.js +18 -18
  94. package/src/diagrams/people.js.map +1 -1
  95. package/src/diagrams/rectangle.d.ts +3 -3
  96. package/src/diagrams/rectangle.js +25 -25
  97. package/src/diagrams/rectangle.js.map +1 -1
  98. package/src/diagrams/svg/parse.d.ts +15 -15
  99. package/src/diagrams/svg/parse.js +278 -325
  100. package/src/diagrams/svg/parse.js.map +1 -1
  101. package/src/diagrams/svgPath.d.ts +2 -2
  102. package/src/diagrams/svgPath.js +28 -29
  103. package/src/diagrams/svgPath.js.map +1 -1
  104. package/src/diagrams/triangle.d.ts +3 -3
  105. package/src/diagrams/triangle.js +39 -40
  106. package/src/diagrams/triangle.js.map +1 -1
  107. package/src/diagrams/video.d.ts +5 -5
  108. package/src/diagrams/video.js +183 -184
  109. package/src/diagrams/video.js.map +1 -1
  110. package/src/dialog/dialog.d.ts +21 -21
  111. package/src/dialog/dialog.js +156 -97
  112. package/src/dialog/dialog.js.map +1 -1
  113. package/src/dialog/index.d.ts +1 -1
  114. package/src/dialog/index.js +1 -1
  115. package/src/event/event.d.ts +102 -102
  116. package/src/event/event.js +21 -21
  117. package/src/event/index.d.ts +1 -1
  118. package/src/event/index.js +1 -1
  119. package/src/map/index.d.ts +1 -1
  120. package/src/map/index.js +1 -1
  121. package/src/map/map.d.ts +21 -21
  122. package/src/map/map.js +211 -209
  123. package/src/map/map.js.map +1 -1
  124. package/src/options.d.ts +130 -130
  125. package/src/options.js +79 -79
  126. package/src/options.js.map +1 -1
  127. package/src/pen/arrow.d.ts +4 -4
  128. package/src/pen/arrow.js +187 -187
  129. package/src/pen/arrow.js.map +1 -1
  130. package/src/pen/index.d.ts +6 -6
  131. package/src/pen/index.js +6 -6
  132. package/src/pen/math.d.ts +28 -28
  133. package/src/pen/math.js +212 -303
  134. package/src/pen/math.js.map +1 -1
  135. package/src/pen/model.d.ts +514 -514
  136. package/src/pen/model.js +209 -209
  137. package/src/pen/model.js.map +1 -1
  138. package/src/pen/plugin.d.ts +5 -5
  139. package/src/pen/plugin.js +57 -87
  140. package/src/pen/plugin.js.map +1 -1
  141. package/src/pen/render.d.ts +146 -147
  142. package/src/pen/render.js +3233 -3235
  143. package/src/pen/render.js.map +1 -1
  144. package/src/pen/text.d.ts +8 -8
  145. package/src/pen/text.js +315 -374
  146. package/src/pen/text.js.map +1 -1
  147. package/src/pen/utils.d.ts +2 -2
  148. package/src/pen/utils.js +18 -40
  149. package/src/pen/utils.js.map +1 -1
  150. package/src/point/index.d.ts +1 -1
  151. package/src/point/index.js +1 -1
  152. package/src/point/point.d.ts +65 -65
  153. package/src/point/point.js +177 -178
  154. package/src/point/point.js.map +1 -1
  155. package/src/rect/index.d.ts +1 -1
  156. package/src/rect/index.js +1 -1
  157. package/src/rect/rect.d.ts +52 -52
  158. package/src/rect/rect.js +426 -485
  159. package/src/rect/rect.js.map +1 -1
  160. package/src/rect/triangle.d.ts +2 -2
  161. package/src/rect/triangle.js +9 -9
  162. package/src/rect/triangle.js.map +1 -1
  163. package/src/scroll/index.d.ts +1 -1
  164. package/src/scroll/index.js +1 -1
  165. package/src/scroll/scroll.d.ts +35 -35
  166. package/src/scroll/scroll.js +233 -220
  167. package/src/scroll/scroll.js.map +1 -1
  168. package/src/store/global.d.ts +25 -25
  169. package/src/store/global.js +17 -17
  170. package/src/store/global.js.map +1 -1
  171. package/src/store/index.d.ts +2 -2
  172. package/src/store/index.js +2 -2
  173. package/src/store/store.d.ts +228 -228
  174. package/src/store/store.js +86 -120
  175. package/src/store/store.js.map +1 -1
  176. package/src/theme.d.ts +13 -13
  177. package/src/theme.js +22 -22
  178. package/src/theme.js.map +1 -1
  179. package/src/title/index.d.ts +1 -1
  180. package/src/title/index.js +1 -1
  181. package/src/title/title.d.ts +30 -30
  182. package/src/title/title.js +98 -98
  183. package/src/title/title.js.map +1 -1
  184. package/src/tooltip/index.d.ts +1 -1
  185. package/src/tooltip/index.js +1 -1
  186. package/src/tooltip/tooltip.d.ts +40 -40
  187. package/src/tooltip/tooltip.js +171 -166
  188. package/src/tooltip/tooltip.js.map +1 -1
  189. package/src/utils/clone.d.ts +8 -8
  190. package/src/utils/clone.js +83 -87
  191. package/src/utils/clone.js.map +1 -1
  192. package/src/utils/color.d.ts +3 -3
  193. package/src/utils/color.js +109 -125
  194. package/src/utils/color.js.map +1 -1
  195. package/src/utils/error.d.ts +2 -2
  196. package/src/utils/error.js +5 -5
  197. package/src/utils/error.js.map +1 -1
  198. package/src/utils/file.d.ts +3 -3
  199. package/src/utils/file.js +39 -91
  200. package/src/utils/file.js.map +1 -1
  201. package/src/utils/index.d.ts +9 -8
  202. package/src/utils/index.js +9 -8
  203. package/src/utils/index.js.map +1 -1
  204. package/src/utils/math.d.ts +18 -18
  205. package/src/utils/math.js +113 -151
  206. package/src/utils/math.js.map +1 -1
  207. package/src/utils/object.d.ts +2 -2
  208. package/src/utils/object.js +20 -20
  209. package/src/utils/object.js.map +1 -1
  210. package/src/utils/padding.d.ts +7 -7
  211. package/src/utils/padding.js +46 -46
  212. package/src/utils/padding.js.map +1 -1
  213. package/src/utils/time.d.ts +1 -1
  214. package/src/utils/time.js +16 -16
  215. package/src/utils/time.js.map +1 -1
  216. package/src/utils/url.d.ts +4 -4
  217. package/src/utils/url.js +26 -26
  218. package/src/utils/url.js.map +1 -1
  219. package/src/utils/uuid.d.ts +4 -4
  220. package/src/utils/uuid.js +12 -12
  221. package/src/utils/browser.d.ts +0 -1
  222. package/src/utils/browser.js +0 -4
  223. package/src/utils/browser.js.map +0 -1
@@ -1,503 +1,441 @@
1
- var __values = (this && this.__values) || function(o) {
2
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
- if (m) return m.call(o);
4
- if (o && typeof o.length === "number") return {
5
- next: function () {
6
- if (o && i >= o.length) o = void 0;
7
- return { value: o && o[i++], done: !o };
8
- }
9
- };
10
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
- };
12
- import { ctxFlip, ctxRotate, drawImage, setGlobalAlpha, getParent, CanvasLayer, } from '../pen';
13
- import { rgba } from '../utils';
14
- import { createOffscreen } from './offscreen';
15
- var CanvasImage = /** @class */ (function () {
16
- function CanvasImage(parentElement, store, isBottom) {
17
- this.parentElement = parentElement;
18
- this.store = store;
19
- this.isBottom = isBottom;
20
- this.canvas = document.createElement('canvas');
21
- /**
22
- * 非图片的绘制
23
- * isBottom true 指背景颜色,背景网格
24
- * isBottom false 指 标尺
25
- */
26
- this.otherOffsreen = createOffscreen(); // 非图片的
27
- this.offscreen = createOffscreen();
28
- this.animateOffsScreen = createOffscreen();
29
- this.fitOffscreen = createOffscreen();
30
- this.fitFlag = false; //开启自定义填充
31
- parentElement.appendChild(this.canvas);
32
- this.canvas.style.backgroundRepeat = 'no-repeat';
33
- this.canvas.style.backgroundSize = '100% 100%';
34
- this.canvas.style.position = 'absolute';
35
- this.canvas.style.top = '0';
36
- this.canvas.style.left = '0';
37
- }
38
- CanvasImage.prototype.resize = function (w, h) {
39
- this.canvas.style.width = w + 'px';
40
- this.canvas.style.height = h + 'px';
41
- w = (w * this.store.dpiRatio) | 0;
42
- h = (h * this.store.dpiRatio) | 0;
43
- this.canvas.width = w;
44
- this.canvas.height = h;
45
- this.otherOffsreen.width = w;
46
- this.otherOffsreen.height = h;
47
- this.offscreen.width = w;
48
- this.offscreen.height = h;
49
- this.animateOffsScreen.width = w;
50
- this.animateOffsScreen.height = h;
51
- this.fitOffscreen.width = w;
52
- this.fitOffscreen.height = h;
53
- this.otherOffsreen
54
- .getContext('2d')
55
- .scale(this.store.dpiRatio, this.store.dpiRatio);
56
- this.otherOffsreen.getContext('2d').textBaseline = 'middle';
57
- this.offscreen
58
- .getContext('2d')
59
- .scale(this.store.dpiRatio, this.store.dpiRatio);
60
- this.offscreen.getContext('2d').textBaseline = 'middle';
61
- this.animateOffsScreen
62
- .getContext('2d')
63
- .scale(this.store.dpiRatio, this.store.dpiRatio);
64
- this.animateOffsScreen.getContext('2d').textBaseline = 'middle';
65
- this.fitOffscreen
66
- .getContext('2d')
67
- .scale(this.store.dpiRatio, this.store.dpiRatio);
68
- this.fitOffscreen.getContext('2d').textBaseline = 'middle';
69
- this.init();
70
- };
71
- CanvasImage.prototype.init = function () {
72
- var e_1, _a;
73
- this.offscreen
74
- .getContext('2d')
75
- .clearRect(0, 0, this.canvas.width, this.canvas.height);
76
- this.animateOffsScreen
77
- .getContext('2d')
78
- .clearRect(0, 0, this.canvas.width, this.canvas.height);
79
- this.fitOffscreen
80
- .getContext('2d')
81
- .clearRect(0, 0, this.canvas.width, this.canvas.height);
82
- try {
83
- for (var _b = __values(this.store.data.pens), _c = _b.next(); !_c.done; _c = _b.next()) {
84
- var pen = _c.value;
85
- if (this.hasImage(pen)) {
86
- // 只影响本层的
87
- pen.calculative.imageDrawed = false;
88
- }
89
- }
90
- }
91
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
92
- finally {
93
- try {
94
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
95
- }
96
- finally { if (e_1) throw e_1.error; }
97
- }
98
- if (this.isBottom) {
99
- this.store.patchFlagsBackground = true;
100
- }
101
- else {
102
- this.store.patchFlagsTop = true;
103
- }
104
- };
105
- CanvasImage.prototype.clear = function () {
106
- this.otherOffsreen
107
- .getContext('2d')
108
- .clearRect(0, 0, this.otherOffsreen.width, this.otherOffsreen.height);
109
- this.offscreen
110
- .getContext('2d')
111
- .clearRect(0, 0, this.canvas.width, this.canvas.height);
112
- this.animateOffsScreen
113
- .getContext('2d')
114
- .clearRect(0, 0, this.canvas.width, this.canvas.height);
115
- this.fitOffscreen
116
- .getContext('2d')
117
- .clearRect(0, 0, this.canvas.width, this.canvas.height);
118
- this.canvas
119
- .getContext('2d')
120
- .clearRect(0, 0, this.canvas.width, this.canvas.height);
121
- };
122
- CanvasImage.prototype.hasImage = function (pen) {
123
- pen.calculative.hasImage =
124
- pen.calculative &&
125
- pen.calculative.inView &&
126
- // !pen.isBottom == !this.isBottom && // undefined == false 结果 false
127
- ((this.isBottom && pen.canvasLayer === CanvasLayer.CanvasImageBottom) ||
128
- (!this.isBottom && pen.canvasLayer === CanvasLayer.CanvasImage)) &&
129
- pen.image &&
130
- pen.calculative.img &&
131
- pen.name !== 'gif';
132
- return pen.calculative.hasImage;
133
- };
134
- CanvasImage.prototype.render = function () {
135
- var e_2, _a, e_3, _b, e_4, _c, e_5, _d;
136
- var _e;
137
- var patchFlags = false;
138
- var patchFlagsAnimate = false;
139
- try {
140
- for (var _f = __values(this.store.data.pens), _g = _f.next(); !_g.done; _g = _f.next()) {
141
- var pen = _g.value;
142
- if (this.hasImage(pen)) {
143
- if (this.store.animates.has(pen)) {
144
- patchFlagsAnimate = true;
145
- }
146
- else if (!pen.calculative.imageDrawed) {
147
- patchFlags = true;
148
- }
149
- if (pen.parentId && this.store.animates.has(getParent(pen, true))) {
150
- patchFlagsAnimate = true;
151
- }
152
- }
153
- }
154
- }
155
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
156
- finally {
157
- try {
158
- if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
159
- }
160
- finally { if (e_2) throw e_2.error; }
161
- }
162
- var patchFlagsBackground = this.store.patchFlagsBackground;
163
- // if (patchFlagsBackground && this.isBottom) {
164
- // const ctx = this.otherOffsreen.getContext('2d');
165
- // ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
166
- // const width = this.store.data.width || this.store.options.width;
167
- // const height = this.store.data.height || this.store.options.height;
168
- // const x = this.store.data.x || this.store.options.x;
169
- // const y = this.store.data.y || this.store.options.y;
170
- // if (width && height && this.store.bkImg) {
171
- // ctx.save();
172
- // ctx.drawImage(
173
- // this.store.bkImg,
174
- // this.store.data.origin.x + x,
175
- // this.store.data.origin.y + y,
176
- // width * this.store.data.scale,
177
- // height * this.store.data.scale
178
- // );
179
- // ctx.restore();
180
- // }
181
- // const background =
182
- // this.store.data.background ||
183
- // (this.store.bkImg ? undefined : this.store.options.background);
184
- // if (background) {
185
- // ctx.save();
186
- // ctx.fillStyle = background;
187
- // if (width && height) {
188
- // ctx.fillRect(
189
- // this.store.data.origin.x + x,
190
- // this.store.data.origin.y + y,
191
- // width * this.store.data.scale,
192
- // height * this.store.data.scale
193
- // );
194
- // } else {
195
- // ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
196
- // }
197
- // ctx.restore();
198
- // }
199
- // this.renderGrid(ctx);
200
- // }
201
- var patchFlagsTop = this.store.patchFlagsTop;
202
- if (patchFlagsTop && !this.isBottom) {
203
- var ctx = this.otherOffsreen.getContext('2d');
204
- ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
205
- this.renderRule(ctx);
206
- }
207
- // 从有图片画布层切换到无图片画布
208
- var patchFlagsLast = this.store.patchFlagsLast;
209
- if (patchFlagsLast) {
210
- var ctx = this.offscreen.getContext('2d');
211
- ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
212
- }
213
- if (patchFlags) {
214
- var ctx = this.offscreen.getContext('2d');
215
- ctx.save();
216
- ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
217
- ctx.translate(this.store.data.x, this.store.data.y);
218
- try {
219
- for (var _h = __values(this.store.data.pens), _j = _h.next(); !_j.done; _j = _h.next()) {
220
- var pen = _j.value;
221
- //pen.calculative.imageDrawed 只用于判断是否需要重绘整块画布,不用于判断改图片节点是否绘制过
222
- if (!pen.calculative.hasImage ||
223
- this.store.animates.has(pen) ||
224
- this.store.animates.has(getParent(pen, true))) {
225
- continue;
226
- }
227
- // if (pen.template) {
228
- if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
229
- continue;
230
- }
231
- pen.calculative.imageDrawed = true;
232
- ctx.save();
233
- ctxFlip(ctx, pen);
234
- if (pen.calculative.rotate) {
235
- ctxRotate(ctx, pen);
236
- }
237
- setGlobalAlpha(ctx, pen);
238
- drawImage(ctx, pen);
239
- ctx.restore();
240
- }
241
- }
242
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
243
- finally {
244
- try {
245
- if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
246
- }
247
- finally { if (e_3) throw e_3.error; }
248
- }
249
- ctx.restore();
250
- }
251
- if (patchFlagsAnimate) {
252
- var ctx = this.animateOffsScreen.getContext('2d');
253
- ctx.save();
254
- ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
255
- ctx.translate(this.store.data.x, this.store.data.y);
256
- try {
257
- for (var _k = __values(this.store.animates), _l = _k.next(); !_l.done; _l = _k.next()) {
258
- var pen = _l.value;
259
- if (!pen.calculative.hasImage) {
260
- continue;
261
- }
262
- // if (pen.template) {
263
- if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
264
- continue;
265
- }
266
- pen.calculative.imageDrawed = true;
267
- ctx.save();
268
- ctxFlip(ctx, pen);
269
- if (pen.calculative.rotate) {
270
- ctxRotate(ctx, pen);
271
- }
272
- setGlobalAlpha(ctx, pen);
273
- drawImage(ctx, pen);
274
- ctx.restore();
275
- }
276
- }
277
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
278
- finally {
279
- try {
280
- if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
281
- }
282
- finally { if (e_4) throw e_4.error; }
283
- }
284
- try {
285
- //图片组合节点 动画
286
- for (var _m = __values(this.store.data.pens), _o = _m.next(); !_o.done; _o = _m.next()) {
287
- var pen = _o.value;
288
- if (!pen.calculative.hasImage || !pen.parentId) {
289
- continue;
290
- }
291
- // if (pen.template) {
292
- if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
293
- continue;
294
- }
295
- if (this.store.animates.has(getParent(pen, true))) {
296
- pen.calculative.imageDrawed = true;
297
- ctx.save();
298
- ctxFlip(ctx, pen);
299
- if (pen.calculative.rotate) {
300
- ctxRotate(ctx, pen);
301
- }
302
- setGlobalAlpha(ctx, pen);
303
- drawImage(ctx, pen);
304
- ctx.restore();
305
- }
306
- }
307
- }
308
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
309
- finally {
310
- try {
311
- if (_o && !_o.done && (_d = _m.return)) _d.call(_m);
312
- }
313
- finally { if (e_5) throw e_5.error; }
314
- }
315
- ctx.restore();
316
- }
317
- if (!this.isBottom && !this.store.data.locked && this.fitFlag) {
318
- var width_1 = (this.store.data.width || this.store.options.width) *
319
- this.store.data.scale;
320
- var height_1 = (this.store.data.height || this.store.options.height) *
321
- this.store.data.scale;
322
- var x_1 = this.store.data.origin.x + this.store.data.x ||
323
- this.store.options.x ||
324
- 0;
325
- var y_1 = this.store.data.origin.y + this.store.data.y ||
326
- this.store.options.y ||
327
- 0;
328
- var ctx_1 = this.fitOffscreen.getContext('2d');
329
- ctx_1.save();
330
- ctx_1.clearRect(0, 0, this.canvas.width, this.canvas.height);
331
- ctx_1.fillStyle = '#ffffff66';
332
- ctx_1.strokeStyle = this.store.options.activeColor;
333
- (_e = this.store.data.fits) === null || _e === void 0 ? void 0 : _e.forEach(function (item, index) {
334
- ctx_1.fillRect(x_1 + width_1 * item.x, y_1 + height_1 * item.y, width_1 * item.width, height_1 * item.height);
335
- if (item.active) {
336
- ctx_1.strokeRect(x_1 + width_1 * item.x, y_1 + height_1 * item.y, width_1 * item.width, height_1 * item.height);
337
- }
338
- });
339
- ctx_1.restore();
340
- }
341
- if (patchFlags ||
342
- patchFlagsAnimate ||
343
- (patchFlagsBackground && this.isBottom) ||
344
- // this.isBottom ||
345
- (patchFlagsTop && !this.isBottom)) {
346
- var ctxCanvas = this.canvas.getContext('2d');
347
- ctxCanvas.clearRect(0, 0, this.canvas.width, this.canvas.height);
348
- if (this.isBottom) {
349
- // ctxCanvas.drawImage(
350
- // this.otherOffsreen,
351
- // 0,
352
- // 0,
353
- // this.canvas.width,
354
- // this.canvas.height
355
- // );
356
- this.store.patchFlagsBackground = false;
357
- }
358
- ctxCanvas.drawImage(this.offscreen, 0, 0, this.canvas.width, this.canvas.height);
359
- ctxCanvas.drawImage(this.animateOffsScreen, 0, 0, this.canvas.width, this.canvas.height);
360
- if (!this.isBottom) {
361
- ctxCanvas.drawImage(this.otherOffsreen, 0, 0, this.canvas.width, this.canvas.height);
362
- this.store.patchFlagsTop = false;
363
- if (!this.store.data.locked && this.fitFlag) {
364
- ctxCanvas.drawImage(this.fitOffscreen, 0, 0, this.canvas.width, this.canvas.height);
365
- }
366
- }
367
- }
368
- };
369
- // renderGrid(
370
- // ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D
371
- // ) {
372
- // const { data, options } = this.store;
373
- // const { grid, gridRotate, gridColor, gridSize, scale } = data;
374
- // if (!(grid ?? options.grid)) {
375
- // // grid false 时不绘制, undefined 时看 options.grid
376
- // return;
377
- // }
378
- // ctx.save();
379
- // const { width, height } = this.canvas;
380
- // if (gridRotate) {
381
- // ctx.translate(width / 2, height / 2);
382
- // ctx.rotate((gridRotate * Math.PI) / 180);
383
- // ctx.translate(-width / 2, -height / 2);
384
- // }
385
- // ctx.lineWidth = 1;
386
- // ctx.strokeStyle = gridColor || options.gridColor;
387
- // ctx.beginPath();
388
- // const size = (gridSize || options.gridSize) * scale;
389
- // const longSide = Math.max(width, height);
390
- // const count = Math.ceil(longSide / size);
391
- // for (let i = -size * count; i < longSide * 2; i += size) {
392
- // ctx.moveTo(i, -longSide);
393
- // ctx.lineTo(i, longSide * 2);
394
- // }
395
- // for (let i = -size * count; i < longSide * 2; i += size) {
396
- // ctx.moveTo(-longSide, i);
397
- // ctx.lineTo(longSide * 2, i);
398
- // }
399
- // ctx.stroke();
400
- // ctx.restore();
401
- // }
402
- CanvasImage.prototype.renderRule = function (ctx) {
403
- var _a, _b, _c, _d, _e, _f, _g, _h;
404
- var _j = this.store, data = _j.data, options = _j.options;
405
- var rule = data.rule, ruleColor = data.ruleColor, scale = data.scale, origin = data.origin;
406
- if (!(rule !== null && rule !== void 0 ? rule : options.rule)) {
407
- // rule false 时不绘制, undefined 时看 options.rule
408
- return;
409
- }
410
- var span = scale * 10;
411
- ctx.save();
412
- var finalRuleColor = ruleColor || options.ruleColor;
413
- ctx.strokeStyle = rgba(finalRuleColor, 0.7);
414
- var x = origin.x + data.x;
415
- var y = origin.y + data.y;
416
- var _k = this.canvas, width = _k.width, height = _k.height;
417
- var h = ((_a = options.ruleOptions) === null || _a === void 0 ? void 0 : _a.height) || 20;
418
- if ((_b = options.ruleOptions) === null || _b === void 0 ? void 0 : _b.background) {
419
- //背景颜色
420
- ctx.beginPath();
421
- ctx.fillStyle = (_c = options.ruleOptions) === null || _c === void 0 ? void 0 : _c.background;
422
- ctx.rect(0, 0, width, h);
423
- ctx.fill();
424
- ctx.rect(0, 0, h, height);
425
- ctx.fill();
426
- }
427
- if ((_d = options.ruleOptions) === null || _d === void 0 ? void 0 : _d.underline) {
428
- ctx.beginPath();
429
- ctx.fillStyle = rgba(finalRuleColor, 0.7);
430
- ctx.moveTo(0, h);
431
- ctx.lineTo(width, h);
432
- ctx.stroke();
433
- ctx.moveTo(h, 0);
434
- ctx.lineTo(h, height);
435
- ctx.stroke();
436
- }
437
- var b_y = h / 4;
438
- if (((_e = options.ruleOptions) === null || _e === void 0 ? void 0 : _e.baseline) === "bottom") {
439
- b_y = h * 3 / 4;
440
- }
441
- // horizontal rule
442
- ctx.beginPath();
443
- ctx.lineWidth = h / 2;
444
- ctx.lineDashOffset = -x % span;
445
- ctx.setLineDash([1, span - 1]);
446
- ctx.moveTo(0, b_y);
447
- ctx.lineTo(width, b_y);
448
- ctx.stroke();
449
- // vertical rule
450
- ctx.beginPath();
451
- ctx.lineDashOffset = -y % span;
452
- ctx.moveTo(b_y, 0);
453
- ctx.lineTo(b_y, height);
454
- ctx.stroke();
455
- // the big rule
456
- ctx.strokeStyle = finalRuleColor;
457
- ctx.beginPath();
458
- ctx.lineWidth = h;
459
- ctx.lineDashOffset = -x % (span * 10);
460
- ctx.setLineDash([1, span * 10 - 1]);
461
- ctx.moveTo(0, h / 2);
462
- ctx.lineTo(width, h / 2);
463
- ctx.stroke();
464
- ctx.beginPath();
465
- ctx.lineDashOffset = -y % (span * 10);
466
- ctx.moveTo(h / 2, 0);
467
- ctx.lineTo(h / 2, height);
468
- ctx.stroke();
469
- ctx.beginPath();
470
- ctx.fillStyle = ((_f = options.ruleOptions) === null || _f === void 0 ? void 0 : _f.textColor) || ctx.strokeStyle;
471
- var text = 0 - Math.floor(x / span / 10) * 100;
472
- var textTop = ((_g = options.ruleOptions) === null || _g === void 0 ? void 0 : _g.textTop) || 16;
473
- var textLeft = ((_h = options.ruleOptions) === null || _h === void 0 ? void 0 : _h.textLeft) || 4;
474
- if (x < 0) {
475
- text -= 100;
476
- }
477
- for (var i = x % (span * 10); i < width; i += 10 * span, text += 100) {
478
- if (span < 3 && text % 500) {
479
- continue;
480
- }
481
- ctx.fillText(text.toString(), i + textLeft, textTop);
482
- }
483
- text = 0 - Math.floor(y / span / 10) * 100;
484
- if (y < 0) {
485
- text -= 100;
486
- }
487
- for (var i = y % (span * 10); i < height; i += 10 * span, text += 100) {
488
- if (span < 3 && text % 500) {
489
- continue;
490
- }
491
- ctx.save();
492
- ctx.beginPath();
493
- ctx.translate(textTop, i - textLeft);
494
- ctx.rotate((270 * Math.PI) / 180);
495
- ctx.fillText(text.toString(), 0, 0);
496
- ctx.restore();
497
- }
498
- ctx.restore();
499
- };
500
- return CanvasImage;
501
- }());
502
- export { CanvasImage };
1
+ import { ctxFlip, ctxRotate, drawImage, setGlobalAlpha, getParent, CanvasLayer, } from '../pen';
2
+ import { rgba } from '../utils';
3
+ import { createOffscreen } from './offscreen';
4
+ export class CanvasImage {
5
+ parentElement;
6
+ store;
7
+ isBottom;
8
+ canvas = document.createElement('canvas');
9
+ /**
10
+ * 非图片的绘制
11
+ * isBottom true 指背景颜色,背景网格
12
+ * isBottom false 标尺
13
+ */
14
+ otherOffsreen = createOffscreen(); // 非图片的
15
+ offscreen = createOffscreen();
16
+ animateOffsScreen = createOffscreen();
17
+ fitOffscreen = createOffscreen();
18
+ fitFlag = false; //开启自定义填充
19
+ currentFit;
20
+ activeFit;
21
+ constructor(parentElement, store, isBottom) {
22
+ this.parentElement = parentElement;
23
+ this.store = store;
24
+ this.isBottom = isBottom;
25
+ parentElement.appendChild(this.canvas);
26
+ this.canvas.style.backgroundRepeat = 'no-repeat';
27
+ this.canvas.style.backgroundSize = '100% 100%';
28
+ this.canvas.style.position = 'absolute';
29
+ this.canvas.style.top = '0';
30
+ this.canvas.style.left = '0';
31
+ }
32
+ resize(w, h) {
33
+ this.canvas.style.width = w + 'px';
34
+ this.canvas.style.height = h + 'px';
35
+ w = (w * this.store.dpiRatio) | 0;
36
+ h = (h * this.store.dpiRatio) | 0;
37
+ this.canvas.width = w;
38
+ this.canvas.height = h;
39
+ this.otherOffsreen.width = w;
40
+ this.otherOffsreen.height = h;
41
+ this.offscreen.width = w;
42
+ this.offscreen.height = h;
43
+ this.animateOffsScreen.width = w;
44
+ this.animateOffsScreen.height = h;
45
+ this.fitOffscreen.width = w;
46
+ this.fitOffscreen.height = h;
47
+ this.otherOffsreen
48
+ .getContext('2d')
49
+ .scale(this.store.dpiRatio, this.store.dpiRatio);
50
+ this.otherOffsreen.getContext('2d').textBaseline = 'middle';
51
+ this.offscreen
52
+ .getContext('2d')
53
+ .scale(this.store.dpiRatio, this.store.dpiRatio);
54
+ this.offscreen.getContext('2d').textBaseline = 'middle';
55
+ this.animateOffsScreen
56
+ .getContext('2d')
57
+ .scale(this.store.dpiRatio, this.store.dpiRatio);
58
+ this.animateOffsScreen.getContext('2d').textBaseline = 'middle';
59
+ this.fitOffscreen
60
+ .getContext('2d')
61
+ .scale(this.store.dpiRatio, this.store.dpiRatio);
62
+ this.fitOffscreen.getContext('2d').textBaseline = 'middle';
63
+ this.init();
64
+ }
65
+ init() {
66
+ this.offscreen
67
+ .getContext('2d')
68
+ .clearRect(0, 0, this.canvas.width, this.canvas.height);
69
+ this.animateOffsScreen
70
+ .getContext('2d')
71
+ .clearRect(0, 0, this.canvas.width, this.canvas.height);
72
+ this.fitOffscreen
73
+ .getContext('2d')
74
+ .clearRect(0, 0, this.canvas.width, this.canvas.height);
75
+ for (const pen of this.store.data.pens) {
76
+ if (this.hasImage(pen)) {
77
+ // 只影响本层的
78
+ pen.calculative.imageDrawed = false;
79
+ }
80
+ }
81
+ if (this.isBottom) {
82
+ this.store.patchFlagsBackground = true;
83
+ }
84
+ else {
85
+ this.store.patchFlagsTop = true;
86
+ }
87
+ }
88
+ clear() {
89
+ this.otherOffsreen
90
+ .getContext('2d')
91
+ .clearRect(0, 0, this.otherOffsreen.width, this.otherOffsreen.height);
92
+ this.offscreen
93
+ .getContext('2d')
94
+ .clearRect(0, 0, this.canvas.width, this.canvas.height);
95
+ this.animateOffsScreen
96
+ .getContext('2d')
97
+ .clearRect(0, 0, this.canvas.width, this.canvas.height);
98
+ this.fitOffscreen
99
+ .getContext('2d')
100
+ .clearRect(0, 0, this.canvas.width, this.canvas.height);
101
+ this.canvas
102
+ .getContext('2d')
103
+ .clearRect(0, 0, this.canvas.width, this.canvas.height);
104
+ }
105
+ hasImage(pen) {
106
+ pen.calculative.hasImage =
107
+ pen.calculative &&
108
+ pen.calculative.inView &&
109
+ // !pen.isBottom == !this.isBottom && // undefined == false 结果 false
110
+ ((this.isBottom && pen.canvasLayer === CanvasLayer.CanvasImageBottom) ||
111
+ (!this.isBottom && pen.canvasLayer === CanvasLayer.CanvasImage)) &&
112
+ pen.image &&
113
+ pen.calculative.img &&
114
+ pen.name !== 'gif';
115
+ return pen.calculative.hasImage;
116
+ }
117
+ render() {
118
+ let patchFlags = false;
119
+ let patchFlagsAnimate = false;
120
+ for (const pen of this.store.data.pens) {
121
+ if (this.hasImage(pen)) {
122
+ if (this.store.animates.has(pen)) {
123
+ patchFlagsAnimate = true;
124
+ }
125
+ else if (!pen.calculative.imageDrawed) {
126
+ patchFlags = true;
127
+ }
128
+ if (pen.parentId && this.store.animates.has(getParent(pen, true))) {
129
+ patchFlagsAnimate = true;
130
+ }
131
+ }
132
+ }
133
+ const patchFlagsBackground = this.store.patchFlagsBackground;
134
+ // if (patchFlagsBackground && this.isBottom) {
135
+ // const ctx = this.otherOffsreen.getContext('2d');
136
+ // ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
137
+ // const width = this.store.data.width || this.store.options.width;
138
+ // const height = this.store.data.height || this.store.options.height;
139
+ // const x = this.store.data.x || this.store.options.x;
140
+ // const y = this.store.data.y || this.store.options.y;
141
+ // if (width && height && this.store.bkImg) {
142
+ // ctx.save();
143
+ // ctx.drawImage(
144
+ // this.store.bkImg,
145
+ // this.store.data.origin.x + x,
146
+ // this.store.data.origin.y + y,
147
+ // width * this.store.data.scale,
148
+ // height * this.store.data.scale
149
+ // );
150
+ // ctx.restore();
151
+ // }
152
+ // const background =
153
+ // this.store.data.background ||
154
+ // (this.store.bkImg ? undefined : this.store.options.background);
155
+ // if (background) {
156
+ // ctx.save();
157
+ // ctx.fillStyle = background;
158
+ // if (width && height) {
159
+ // ctx.fillRect(
160
+ // this.store.data.origin.x + x,
161
+ // this.store.data.origin.y + y,
162
+ // width * this.store.data.scale,
163
+ // height * this.store.data.scale
164
+ // );
165
+ // } else {
166
+ // ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
167
+ // }
168
+ // ctx.restore();
169
+ // }
170
+ // this.renderGrid(ctx);
171
+ // }
172
+ const patchFlagsTop = this.store.patchFlagsTop;
173
+ if (patchFlagsTop && !this.isBottom) {
174
+ const ctx = this.otherOffsreen.getContext('2d');
175
+ ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
176
+ this.renderRule(ctx);
177
+ }
178
+ // 从有图片画布层切换到无图片画布
179
+ const patchFlagsLast = this.store.patchFlagsLast;
180
+ if (patchFlagsLast) {
181
+ const ctx = this.offscreen.getContext('2d');
182
+ ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
183
+ }
184
+ if (patchFlags) {
185
+ const ctx = this.offscreen.getContext('2d');
186
+ ctx.save();
187
+ ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
188
+ ctx.translate(this.store.data.x, this.store.data.y);
189
+ for (const pen of this.store.data.pens) {
190
+ //pen.calculative.imageDrawed 只用于判断是否需要重绘整块画布,不用于判断改图片节点是否绘制过
191
+ if (!pen.calculative.hasImage ||
192
+ this.store.animates.has(pen) ||
193
+ this.store.animates.has(getParent(pen, true))) {
194
+ continue;
195
+ }
196
+ // if (pen.template) {
197
+ if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
198
+ continue;
199
+ }
200
+ pen.calculative.imageDrawed = true;
201
+ ctx.save();
202
+ ctxFlip(ctx, pen);
203
+ if (pen.calculative.rotate) {
204
+ ctxRotate(ctx, pen);
205
+ }
206
+ setGlobalAlpha(ctx, pen);
207
+ drawImage(ctx, pen);
208
+ ctx.restore();
209
+ }
210
+ ctx.restore();
211
+ }
212
+ if (patchFlagsAnimate) {
213
+ const ctx = this.animateOffsScreen.getContext('2d');
214
+ ctx.save();
215
+ ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
216
+ ctx.translate(this.store.data.x, this.store.data.y);
217
+ for (const pen of this.store.animates) {
218
+ if (!pen.calculative.hasImage) {
219
+ continue;
220
+ }
221
+ // if (pen.template) {
222
+ if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
223
+ continue;
224
+ }
225
+ pen.calculative.imageDrawed = true;
226
+ ctx.save();
227
+ ctxFlip(ctx, pen);
228
+ if (pen.calculative.rotate) {
229
+ ctxRotate(ctx, pen);
230
+ }
231
+ setGlobalAlpha(ctx, pen);
232
+ drawImage(ctx, pen);
233
+ ctx.restore();
234
+ }
235
+ //图片组合节点 动画
236
+ for (const pen of this.store.data.pens) {
237
+ if (!pen.calculative.hasImage || !pen.parentId) {
238
+ continue;
239
+ }
240
+ // if (pen.template) {
241
+ if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
242
+ continue;
243
+ }
244
+ if (this.store.animates.has(getParent(pen, true))) {
245
+ pen.calculative.imageDrawed = true;
246
+ ctx.save();
247
+ ctxFlip(ctx, pen);
248
+ if (pen.calculative.rotate) {
249
+ ctxRotate(ctx, pen);
250
+ }
251
+ setGlobalAlpha(ctx, pen);
252
+ drawImage(ctx, pen);
253
+ ctx.restore();
254
+ }
255
+ }
256
+ ctx.restore();
257
+ }
258
+ if (!this.isBottom && !this.store.data.locked && this.fitFlag) {
259
+ const width = (this.store.data.width || this.store.options.width) *
260
+ this.store.data.scale;
261
+ const height = (this.store.data.height || this.store.options.height) *
262
+ this.store.data.scale;
263
+ const x = this.store.data.origin.x + this.store.data.x ||
264
+ this.store.options.x ||
265
+ 0;
266
+ const y = this.store.data.origin.y + this.store.data.y ||
267
+ this.store.options.y ||
268
+ 0;
269
+ const ctx = this.fitOffscreen.getContext('2d');
270
+ ctx.save();
271
+ ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
272
+ ctx.fillStyle = '#ffffff66';
273
+ ctx.strokeStyle = this.store.options.activeColor;
274
+ this.store.data.fits?.forEach((item, index) => {
275
+ ctx.fillRect(x + width * item.x, y + height * item.y, width * item.width, height * item.height);
276
+ if (item.active) {
277
+ ctx.strokeRect(x + width * item.x, y + height * item.y, width * item.width, height * item.height);
278
+ }
279
+ });
280
+ ctx.restore();
281
+ }
282
+ if (patchFlags ||
283
+ patchFlagsAnimate ||
284
+ (patchFlagsBackground && this.isBottom) ||
285
+ // this.isBottom ||
286
+ (patchFlagsTop && !this.isBottom)) {
287
+ const ctxCanvas = this.canvas.getContext('2d');
288
+ ctxCanvas.clearRect(0, 0, this.canvas.width, this.canvas.height);
289
+ if (this.isBottom) {
290
+ // ctxCanvas.drawImage(
291
+ // this.otherOffsreen,
292
+ // 0,
293
+ // 0,
294
+ // this.canvas.width,
295
+ // this.canvas.height
296
+ // );
297
+ this.store.patchFlagsBackground = false;
298
+ }
299
+ ctxCanvas.drawImage(this.offscreen, 0, 0, this.canvas.width, this.canvas.height);
300
+ ctxCanvas.drawImage(this.animateOffsScreen, 0, 0, this.canvas.width, this.canvas.height);
301
+ if (!this.isBottom) {
302
+ ctxCanvas.drawImage(this.otherOffsreen, 0, 0, this.canvas.width, this.canvas.height);
303
+ this.store.patchFlagsTop = false;
304
+ if (!this.store.data.locked && this.fitFlag) {
305
+ ctxCanvas.drawImage(this.fitOffscreen, 0, 0, this.canvas.width, this.canvas.height);
306
+ }
307
+ }
308
+ }
309
+ }
310
+ // renderGrid(
311
+ // ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D
312
+ // ) {
313
+ // const { data, options } = this.store;
314
+ // const { grid, gridRotate, gridColor, gridSize, scale } = data;
315
+ // if (!(grid ?? options.grid)) {
316
+ // // grid false 时不绘制, undefined 时看 options.grid
317
+ // return;
318
+ // }
319
+ // ctx.save();
320
+ // const { width, height } = this.canvas;
321
+ // if (gridRotate) {
322
+ // ctx.translate(width / 2, height / 2);
323
+ // ctx.rotate((gridRotate * Math.PI) / 180);
324
+ // ctx.translate(-width / 2, -height / 2);
325
+ // }
326
+ // ctx.lineWidth = 1;
327
+ // ctx.strokeStyle = gridColor || options.gridColor;
328
+ // ctx.beginPath();
329
+ // const size = (gridSize || options.gridSize) * scale;
330
+ // const longSide = Math.max(width, height);
331
+ // const count = Math.ceil(longSide / size);
332
+ // for (let i = -size * count; i < longSide * 2; i += size) {
333
+ // ctx.moveTo(i, -longSide);
334
+ // ctx.lineTo(i, longSide * 2);
335
+ // }
336
+ // for (let i = -size * count; i < longSide * 2; i += size) {
337
+ // ctx.moveTo(-longSide, i);
338
+ // ctx.lineTo(longSide * 2, i);
339
+ // }
340
+ // ctx.stroke();
341
+ // ctx.restore();
342
+ // }
343
+ renderRule(ctx) {
344
+ const { data, options } = this.store;
345
+ const { rule, ruleColor, scale, origin } = data;
346
+ if (!(rule ?? options.rule)) {
347
+ // rule false 时不绘制, undefined 时看 options.rule
348
+ return;
349
+ }
350
+ const span = scale * 10;
351
+ ctx.save();
352
+ const finalRuleColor = ruleColor || options.ruleColor;
353
+ ctx.strokeStyle = rgba(finalRuleColor, 0.7);
354
+ const x = origin.x + data.x;
355
+ const y = origin.y + data.y;
356
+ const { width, height } = this.canvas;
357
+ let h = options.ruleOptions?.height || 20;
358
+ if (options.ruleOptions?.background) {
359
+ //背景颜色
360
+ ctx.beginPath();
361
+ ctx.fillStyle = options.ruleOptions?.background;
362
+ ctx.rect(0, 0, width, h);
363
+ ctx.fill();
364
+ ctx.rect(0, 0, h, height);
365
+ ctx.fill();
366
+ }
367
+ if (options.ruleOptions?.underline) {
368
+ ctx.beginPath();
369
+ ctx.fillStyle = rgba(finalRuleColor, 0.7);
370
+ ctx.moveTo(0, h);
371
+ ctx.lineTo(width, h);
372
+ ctx.stroke();
373
+ ctx.moveTo(h, 0);
374
+ ctx.lineTo(h, height);
375
+ ctx.stroke();
376
+ }
377
+ let b_y = h / 4;
378
+ if (options.ruleOptions?.baseline === "bottom") {
379
+ b_y = h * 3 / 4;
380
+ }
381
+ // horizontal rule
382
+ ctx.beginPath();
383
+ ctx.lineWidth = h / 2;
384
+ ctx.lineDashOffset = -x % span;
385
+ ctx.setLineDash([1, span - 1]);
386
+ ctx.moveTo(0, b_y);
387
+ ctx.lineTo(width, b_y);
388
+ ctx.stroke();
389
+ // vertical rule
390
+ ctx.beginPath();
391
+ ctx.lineDashOffset = -y % span;
392
+ ctx.moveTo(b_y, 0);
393
+ ctx.lineTo(b_y, height);
394
+ ctx.stroke();
395
+ // the big rule
396
+ ctx.strokeStyle = finalRuleColor;
397
+ ctx.beginPath();
398
+ ctx.lineWidth = h;
399
+ ctx.lineDashOffset = -x % (span * 10);
400
+ ctx.setLineDash([1, span * 10 - 1]);
401
+ ctx.moveTo(0, h / 2);
402
+ ctx.lineTo(width, h / 2);
403
+ ctx.stroke();
404
+ ctx.beginPath();
405
+ ctx.lineDashOffset = -y % (span * 10);
406
+ ctx.moveTo(h / 2, 0);
407
+ ctx.lineTo(h / 2, height);
408
+ ctx.stroke();
409
+ ctx.beginPath();
410
+ ctx.fillStyle = options.ruleOptions?.textColor || ctx.strokeStyle;
411
+ let text = 0 - Math.floor(x / span / 10) * 100;
412
+ let textTop = options.ruleOptions?.textTop || 16;
413
+ let textLeft = options.ruleOptions?.textLeft || 4;
414
+ if (x < 0) {
415
+ text -= 100;
416
+ }
417
+ for (let i = x % (span * 10); i < width; i += 10 * span, text += 100) {
418
+ if (span < 3 && text % 500) {
419
+ continue;
420
+ }
421
+ ctx.fillText(text.toString(), i + textLeft, textTop);
422
+ }
423
+ text = 0 - Math.floor(y / span / 10) * 100;
424
+ if (y < 0) {
425
+ text -= 100;
426
+ }
427
+ for (let i = y % (span * 10); i < height; i += 10 * span, text += 100) {
428
+ if (span < 3 && text % 500) {
429
+ continue;
430
+ }
431
+ ctx.save();
432
+ ctx.beginPath();
433
+ ctx.translate(textTop, i - textLeft);
434
+ ctx.rotate((270 * Math.PI) / 180);
435
+ ctx.fillText(text.toString(), 0, 0);
436
+ ctx.restore();
437
+ }
438
+ ctx.restore();
439
+ }
440
+ }
503
441
  //# sourceMappingURL=canvasImage.js.map