billboard.js 4.0.2 → 4.1.0-next.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 (272) hide show
  1. package/README.md +82 -7
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +1938 -557
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +19 -25
  6. package/dist/billboard.pkgd.js +1934 -742
  7. package/dist/billboard.pkgd.min.js +24 -30
  8. package/dist/billboard.react.js +205 -0
  9. package/dist/billboard.react.min.js +9 -0
  10. package/dist/billboard.worker.js +10 -0
  11. package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-sparkline.js +3 -2
  14. package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
  15. package/dist/plugin/billboardjs-plugin-stanford.js +3 -2
  16. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  17. package/dist/plugin/billboardjs-plugin-tableview.js +57 -27
  18. package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
  19. package/dist/plugin/billboardjs-plugin-textoverlap.js +72 -54
  20. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  21. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +2 -2
  22. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
  23. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +3 -2
  24. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
  25. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +3 -2
  26. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
  27. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +57 -27
  28. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
  29. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +65 -3556
  30. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
  31. package/dist/theme/dark.css +1 -1
  32. package/dist/theme/dark.min.css +1 -1
  33. package/dist/theme/datalab.css +1 -1
  34. package/dist/theme/datalab.min.css +1 -1
  35. package/dist/theme/graph.css +1 -1
  36. package/dist/theme/graph.min.css +1 -1
  37. package/dist/theme/insight.css +1 -1
  38. package/dist/theme/insight.min.css +1 -1
  39. package/dist/theme/modern.css +1 -1
  40. package/dist/theme/modern.min.css +1 -1
  41. package/dist-esm/Chart/Chart.js +134 -152
  42. package/dist-esm/Chart/api/axis.js +217 -237
  43. package/dist-esm/Chart/api/category.js +54 -54
  44. package/dist-esm/Chart/api/chart.js +172 -215
  45. package/dist-esm/Chart/api/color.js +21 -21
  46. package/dist-esm/Chart/api/data.js +172 -173
  47. package/dist-esm/Chart/api/export.js +242 -262
  48. package/dist-esm/Chart/api/flow.js +198 -254
  49. package/dist-esm/Chart/api/focus.js +136 -147
  50. package/dist-esm/Chart/api/grid.js +191 -190
  51. package/dist-esm/Chart/api/group.js +31 -34
  52. package/dist-esm/Chart/api/legend.js +54 -63
  53. package/dist-esm/Chart/api/load.js +237 -257
  54. package/dist-esm/Chart/api/regions.js +148 -168
  55. package/dist-esm/Chart/api/selection.js +181 -139
  56. package/dist-esm/Chart/api/show.js +133 -147
  57. package/dist-esm/Chart/api/stubs.js +43 -42
  58. package/dist-esm/Chart/api/subchart.js +155 -172
  59. package/dist-esm/Chart/api/tooltip.js +132 -177
  60. package/dist-esm/Chart/api/x.js +67 -71
  61. package/dist-esm/Chart/api/zoom.js +183 -220
  62. package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
  63. package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
  64. package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
  65. package/dist-esm/ChartInternal/ChartInternal.js +573 -749
  66. package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
  67. package/dist-esm/ChartInternal/data/convert.js +200 -229
  68. package/dist-esm/ChartInternal/data/data.js +970 -1147
  69. package/dist-esm/ChartInternal/data/load.js +145 -197
  70. package/dist-esm/ChartInternal/interactions/drag.js +86 -122
  71. package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
  72. package/dist-esm/ChartInternal/interactions/flow.js +151 -215
  73. package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
  74. package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
  75. package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
  76. package/dist-esm/ChartInternal/internals/category.js +18 -18
  77. package/dist-esm/ChartInternal/internals/class.js +89 -99
  78. package/dist-esm/ChartInternal/internals/clip.js +88 -119
  79. package/dist-esm/ChartInternal/internals/color.js +233 -288
  80. package/dist-esm/ChartInternal/internals/domain.js +452 -588
  81. package/dist-esm/ChartInternal/internals/format.js +64 -77
  82. package/dist-esm/ChartInternal/internals/grid.js +333 -457
  83. package/dist-esm/ChartInternal/internals/legend.js +675 -927
  84. package/dist-esm/ChartInternal/internals/redraw.js +200 -289
  85. package/dist-esm/ChartInternal/internals/region.js +106 -159
  86. package/dist-esm/ChartInternal/internals/scale.js +186 -215
  87. package/dist-esm/ChartInternal/internals/selection.js +132 -159
  88. package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
  89. package/dist-esm/ChartInternal/internals/size.js +286 -394
  90. package/dist-esm/ChartInternal/internals/style.js +39 -41
  91. package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
  92. package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
  93. package/dist-esm/ChartInternal/internals/text.js +368 -528
  94. package/dist-esm/ChartInternal/internals/text.util.js +179 -239
  95. package/dist-esm/ChartInternal/internals/title.js +96 -121
  96. package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
  97. package/dist-esm/ChartInternal/internals/transform.js +79 -97
  98. package/dist-esm/ChartInternal/internals/type.js +286 -245
  99. package/dist-esm/ChartInternal/shape/arc.js +825 -1112
  100. package/dist-esm/ChartInternal/shape/area.js +73 -94
  101. package/dist-esm/ChartInternal/shape/bar.js +227 -272
  102. package/dist-esm/ChartInternal/shape/bubble.js +9 -8
  103. package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
  104. package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
  105. package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
  106. package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
  107. package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
  108. package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
  109. package/dist-esm/ChartInternal/shape/core/path.js +142 -115
  110. package/dist-esm/ChartInternal/shape/core/point.js +105 -125
  111. package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
  112. package/dist-esm/ChartInternal/shape/funnel.js +310 -338
  113. package/dist-esm/ChartInternal/shape/gauge.js +71 -103
  114. package/dist-esm/ChartInternal/shape/line.js +208 -278
  115. package/dist-esm/ChartInternal/shape/point.js +310 -413
  116. package/dist-esm/ChartInternal/shape/polar.js +84 -109
  117. package/dist-esm/ChartInternal/shape/radar.js +228 -318
  118. package/dist-esm/ChartInternal/shape/shape.js +782 -828
  119. package/dist-esm/ChartInternal/shape/treemap.js +152 -190
  120. package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
  121. package/dist-esm/canvas/CanvasEngine.js +148 -166
  122. package/dist-esm/canvas/CanvasPainter.js +395 -411
  123. package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
  124. package/dist-esm/canvas/CanvasTheme.js +899 -802
  125. package/dist-esm/canvas/HitDetector.js +394 -463
  126. package/dist-esm/canvas/axisTicks.js +672 -786
  127. package/dist-esm/canvas/classes.js +19 -17
  128. package/dist-esm/canvas/color.js +40 -59
  129. package/dist-esm/canvas/geometry.js +38 -38
  130. package/dist-esm/canvas/labels.js +318 -371
  131. package/dist-esm/canvas/pointPattern.js +578 -580
  132. package/dist-esm/canvas/util.js +242 -262
  133. package/dist-esm/config/Options/Options.js +29 -32
  134. package/dist-esm/config/Options/axis/axis.js +101 -101
  135. package/dist-esm/config/Options/axis/x.js +759 -755
  136. package/dist-esm/config/Options/axis/y.js +525 -522
  137. package/dist-esm/config/Options/axis/y2.js +501 -485
  138. package/dist-esm/config/Options/common/boost.js +93 -32
  139. package/dist-esm/config/Options/common/color.js +88 -87
  140. package/dist-esm/config/Options/common/grid.js +74 -73
  141. package/dist-esm/config/Options/common/legend.js +180 -179
  142. package/dist-esm/config/Options/common/main.js +474 -473
  143. package/dist-esm/config/Options/common/point.js +160 -159
  144. package/dist-esm/config/Options/common/title.js +47 -46
  145. package/dist-esm/config/Options/common/tooltip.js +253 -252
  146. package/dist-esm/config/Options/data/axis.js +173 -172
  147. package/dist-esm/config/Options/data/data.js +958 -957
  148. package/dist-esm/config/Options/data/selection.js +131 -130
  149. package/dist-esm/config/Options/interaction/interaction.js +53 -52
  150. package/dist-esm/config/Options/interaction/subchart.js +164 -73
  151. package/dist-esm/config/Options/interaction/zoom.js +86 -85
  152. package/dist-esm/config/Options/shape/arc.js +150 -149
  153. package/dist-esm/config/Options/shape/area.js +69 -68
  154. package/dist-esm/config/Options/shape/bar.js +147 -146
  155. package/dist-esm/config/Options/shape/bubble.js +35 -34
  156. package/dist-esm/config/Options/shape/candlestick.js +61 -60
  157. package/dist-esm/config/Options/shape/donut.js +181 -180
  158. package/dist-esm/config/Options/shape/funnel.js +49 -48
  159. package/dist-esm/config/Options/shape/gauge.js +237 -236
  160. package/dist-esm/config/Options/shape/line.js +58 -57
  161. package/dist-esm/config/Options/shape/pie.js +185 -184
  162. package/dist-esm/config/Options/shape/polar.js +167 -166
  163. package/dist-esm/config/Options/shape/radar.js +76 -75
  164. package/dist-esm/config/Options/shape/scatter.js +36 -36
  165. package/dist-esm/config/Options/shape/spline.js +46 -46
  166. package/dist-esm/config/Options/shape/treemap.js +80 -79
  167. package/dist-esm/config/Store/Element.js +64 -62
  168. package/dist-esm/config/Store/State.js +189 -200
  169. package/dist-esm/config/Store/Store.js +25 -26
  170. package/dist-esm/config/classes.js +157 -155
  171. package/dist-esm/config/config.js +26 -35
  172. package/dist-esm/config/const.js +120 -128
  173. package/dist-esm/config/resolver/axis.core.js +25 -25
  174. package/dist-esm/config/resolver/axis.js +26 -27
  175. package/dist-esm/config/resolver/canvas.js +2071 -2472
  176. package/dist-esm/config/resolver/canvasShape.js +201 -177
  177. package/dist-esm/config/resolver/category.js +26 -27
  178. package/dist-esm/config/resolver/export.js +24 -26
  179. package/dist-esm/config/resolver/flow.js +29 -31
  180. package/dist-esm/config/resolver/grid.js +34 -35
  181. package/dist-esm/config/resolver/interaction/selection.js +17 -17
  182. package/dist-esm/config/resolver/interaction/subchart.js +17 -17
  183. package/dist-esm/config/resolver/interaction/zoom.js +17 -17
  184. package/dist-esm/config/resolver/regions.js +30 -31
  185. package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
  186. package/dist-esm/config/resolver/shape/area.js +17 -17
  187. package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
  188. package/dist-esm/config/resolver/shape/bar.js +13 -13
  189. package/dist-esm/config/resolver/shape/bubble.js +18 -14
  190. package/dist-esm/config/resolver/shape/candlestick.js +13 -13
  191. package/dist-esm/config/resolver/shape/donut.js +11 -11
  192. package/dist-esm/config/resolver/shape/funnel.js +11 -11
  193. package/dist-esm/config/resolver/shape/gauge.js +12 -12
  194. package/dist-esm/config/resolver/shape/line.js +10 -10
  195. package/dist-esm/config/resolver/shape/pie.js +11 -11
  196. package/dist-esm/config/resolver/shape/polar.js +12 -12
  197. package/dist-esm/config/resolver/shape/radar.js +22 -14
  198. package/dist-esm/config/resolver/shape/scatter.js +13 -13
  199. package/dist-esm/config/resolver/shape/treemap.js +11 -11
  200. package/dist-esm/core.js +208 -211
  201. package/dist-esm/index.canvas.js +14 -13
  202. package/dist-esm/index.esm.js +25 -24
  203. package/dist-esm/module/Cache.js +117 -129
  204. package/dist-esm/module/browser.js +30 -35
  205. package/dist-esm/module/dsv.js +107 -127
  206. package/dist-esm/module/error.js +45 -52
  207. package/dist-esm/module/generator.js +75 -83
  208. package/dist-esm/module/sanitize.js +302 -399
  209. package/dist-esm/module/util/brush.js +27 -38
  210. package/dist-esm/module/util/dom.js +288 -348
  211. package/dist-esm/module/util/object.js +277 -341
  212. package/dist-esm/module/util/type-checks.js +21 -25
  213. package/dist-esm/module/worker.js +312 -130
  214. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
  215. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
  216. package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
  217. package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
  218. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
  219. package/dist-esm/react/index.js +157 -0
  220. package/package.json +28 -8
  221. package/src/Chart/api/focus.ts +8 -12
  222. package/src/Chart/api/selection.ts +130 -5
  223. package/src/ChartInternal/Axis/Axis.ts +164 -65
  224. package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
  225. package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
  226. package/src/ChartInternal/ChartInternal.ts +1 -1
  227. package/src/ChartInternal/data/convert.ts +54 -4
  228. package/src/ChartInternal/data/data.ts +19 -6
  229. package/src/ChartInternal/interactions/eventrect.ts +6 -0
  230. package/src/ChartInternal/interactions/subchart.ts +437 -66
  231. package/src/ChartInternal/internals/color.ts +7 -6
  232. package/src/ChartInternal/internals/domain.ts +15 -3
  233. package/src/ChartInternal/internals/grid.ts +21 -1
  234. package/src/ChartInternal/internals/scale.ts +9 -2
  235. package/src/ChartInternal/internals/selection.ts +1 -1
  236. package/src/ChartInternal/internals/subchart.util.ts +55 -0
  237. package/src/ChartInternal/internals/text.arc.ts +3 -1
  238. package/src/ChartInternal/internals/text.ts +19 -6
  239. package/src/ChartInternal/internals/transform.ts +8 -2
  240. package/src/ChartInternal/internals/type.ts +131 -33
  241. package/src/ChartInternal/shape/IShape.ts +6 -3
  242. package/src/ChartInternal/shape/bar.ts +87 -37
  243. package/src/ChartInternal/shape/core/barRadius.ts +129 -0
  244. package/src/ChartInternal/shape/core/candlestick.ts +1 -1
  245. package/src/ChartInternal/shape/core/path.ts +76 -9
  246. package/src/ChartInternal/shape/funnel.ts +2 -3
  247. package/src/ChartInternal/shape/line.ts +1 -1
  248. package/src/ChartInternal/shape/point.ts +27 -13
  249. package/src/ChartInternal/shape/shape.ts +172 -18
  250. package/src/Plugin/stanford/index.ts +0 -4
  251. package/src/Plugin/tableview/index.ts +85 -3
  252. package/src/Plugin/textoverlap/index.ts +9 -15
  253. package/src/canvas/CanvasAxisRenderer.ts +184 -36
  254. package/src/canvas/CanvasRenderer.ts +247 -160
  255. package/src/canvas/CanvasTheme.ts +212 -0
  256. package/src/canvas/axisTicks.ts +122 -40
  257. package/src/config/Options/axis/y2.ts +13 -0
  258. package/src/config/Options/common/boost.ts +64 -4
  259. package/src/config/Options/common/color.ts +2 -2
  260. package/src/config/Options/interaction/subchart.ts +98 -1
  261. package/src/config/Options/shape/gauge.ts +1 -1
  262. package/src/config/Options/shape/treemap.ts +2 -2
  263. package/src/config/Store/Element.ts +3 -1
  264. package/src/config/Store/State.ts +1 -0
  265. package/src/config/classes.ts +1 -0
  266. package/src/config/resolver/canvas.ts +92 -10
  267. package/src/module/voronoi.ts +119 -0
  268. package/src/module/worker.entry.ts +61 -0
  269. package/src/module/worker.ts +346 -63
  270. package/src/react/index.ts +193 -0
  271. package/types/options.d.ts +206 -3
  272. package/types/react/index.d.ts +27 -0
@@ -5,654 +5,652 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 4.0.2
8
+ * @version 4.1.0-next.1
9
9
  */
10
- import { window as win } from '../module/browser.js';
11
- import { withOpacity } from './color.js';
12
- import { sanitize } from '../module/sanitize.js';
13
-
10
+ import { window as win } from "../module/browser.js";
11
+ import { sanitize } from "../module/sanitize.js";
12
+ import { withOpacity } from "./color.js";
13
+ //#region src/canvas/pointPattern.ts
14
14
  /**
15
- * Copyright (c) 2017 ~ present NAVER Corp.
16
- * billboard.js project is licensed under the MIT license
17
- */
18
- // Fallback coordinate box for custom SVG point patterns without a viewBox. SVG can
19
- // render the markup directly; canvas needs an explicit box to normalize coordinates.
20
- const DEFAULT_POINT_VIEWBOX = { x: 0, y: 0, w: 8, h: 8 };
21
- const customPointPatternCache = new Map();
22
- const IDENTITY_POINT_MATRIX = [1, 0, 0, 1, 0, 0];
15
+ * Copyright (c) 2017 ~ present NAVER Corp.
16
+ * billboard.js project is licensed under the MIT license
17
+ */
18
+ const DEFAULT_POINT_VIEWBOX = {
19
+ x: 0,
20
+ y: 0,
21
+ w: 8,
22
+ h: 8
23
+ };
24
+ const customPointPatternCache = /* @__PURE__ */ new Map();
25
+ const IDENTITY_POINT_MATRIX = [
26
+ 1,
27
+ 0,
28
+ 0,
29
+ 1,
30
+ 0,
31
+ 0
32
+ ];
23
33
  /**
24
- * Check if point type can be drawn by the built-in point renderer.
25
- * @param {string} type Point type
26
- * @returns {boolean} Whether type is built-in
27
- * @private
28
- */
34
+ * Check if point type can be drawn by the built-in point renderer.
35
+ * @param {string} type Point type
36
+ * @returns {boolean} Whether type is built-in
37
+ * @private
38
+ */
29
39
  function isBuiltinPointType(type) {
30
- return type === "circle" || type === "rectangle";
40
+ return type === "circle" || type === "rectangle";
31
41
  }
32
42
  /**
33
- * Get numeric SVG attribute.
34
- * @param {Element} node SVG element
35
- * @param {string} name Attribute name
36
- * @param {number} fallback Fallback value
37
- * @returns {number} Numeric attribute value
38
- * @private
39
- */
43
+ * Get numeric SVG attribute.
44
+ * @param {Element} node SVG element
45
+ * @param {string} name Attribute name
46
+ * @param {number} fallback Fallback value
47
+ * @returns {number} Numeric attribute value
48
+ * @private
49
+ */
40
50
  function getSvgNumber(node, name, fallback = 0) {
41
- const value = node.getAttribute(name);
42
- const parsed = value === null ? NaN : parseFloat(value);
43
- return Number.isFinite(parsed) ? parsed : fallback;
51
+ const value = node.getAttribute(name);
52
+ const parsed = value === null ? NaN : parseFloat(value);
53
+ return Number.isFinite(parsed) ? parsed : fallback;
44
54
  }
45
55
  /**
46
- * Parse an SVG points attribute.
47
- * @param {string} value Points attribute
48
- * @returns {Array} Coordinate pairs
49
- * @private
50
- */
56
+ * Parse an SVG points attribute.
57
+ * @param {string} value Points attribute
58
+ * @returns {Array} Coordinate pairs
59
+ * @private
60
+ */
51
61
  function parseSvgPoints(value) {
52
- const nums = (value.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/gi) || [])
53
- .map(Number)
54
- .filter(Number.isFinite);
55
- const points = [];
56
- for (let i = 0; i < nums.length - 1; i += 2) {
57
- points.push([nums[i], nums[i + 1]]);
58
- }
59
- return points;
62
+ const nums = (value.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/gi) || []).map(Number).filter(Number.isFinite);
63
+ const points = [];
64
+ for (let i = 0; i < nums.length - 1; i += 2) points.push([nums[i], nums[i + 1]]);
65
+ return points;
60
66
  }
61
67
  /**
62
- * Parse an SVG viewBox attribute.
63
- * @param {string|null} value viewBox value
64
- * @returns {object|null} Parsed box
65
- * @private
66
- */
68
+ * Parse an SVG viewBox attribute.
69
+ * @param {string|null} value viewBox value
70
+ * @returns {object|null} Parsed box
71
+ * @private
72
+ */
67
73
  function parseViewBox(value) {
68
- const values = value?.trim().split(/[\s,]+/).map(Number).filter(Number.isFinite) || [];
69
- return values.length === 4 ?
70
- {
71
- x: values[0],
72
- y: values[1],
73
- w: values[2],
74
- h: values[3]
75
- } :
76
- null;
74
+ const values = value?.trim().split(/[\s,]+/).map(Number).filter(Number.isFinite) || [];
75
+ return values.length === 4 ? {
76
+ x: values[0],
77
+ y: values[1],
78
+ w: values[2],
79
+ h: values[3]
80
+ } : null;
77
81
  }
78
82
  /**
79
- * Get bounds for coordinate pairs.
80
- * @param {Array} points Coordinate pairs
81
- * @returns {object} Bounds
82
- * @private
83
- */
83
+ * Get bounds for coordinate pairs.
84
+ * @param {Array} points Coordinate pairs
85
+ * @returns {object} Bounds
86
+ * @private
87
+ */
84
88
  function getPointsBox(points) {
85
- const xs = points.map(([x]) => x);
86
- const ys = points.map(([, y]) => y);
87
- const x = Math.min(...xs);
88
- const y = Math.min(...ys);
89
- return {
90
- x,
91
- y,
92
- w: Math.max(...xs) - x,
93
- h: Math.max(...ys) - y
94
- };
89
+ const xs = points.map(([x]) => x);
90
+ const ys = points.map(([, y]) => y);
91
+ const x = Math.min(...xs);
92
+ const y = Math.min(...ys);
93
+ return {
94
+ x,
95
+ y,
96
+ w: Math.max(...xs) - x,
97
+ h: Math.max(...ys) - y
98
+ };
95
99
  }
96
100
  /**
97
- * Merge multiple bounds.
98
- * @param {Array} boxes Bounds
99
- * @returns {object} Merged bounds
100
- * @private
101
- */
101
+ * Merge multiple bounds.
102
+ * @param {Array} boxes Bounds
103
+ * @returns {object} Merged bounds
104
+ * @private
105
+ */
102
106
  function mergePointBoxes(boxes) {
103
- const validBoxes = boxes.filter(box => Number.isFinite(box.x) &&
104
- Number.isFinite(box.y) &&
105
- Number.isFinite(box.w) &&
106
- Number.isFinite(box.h));
107
- if (!validBoxes.length) {
108
- return { ...DEFAULT_POINT_VIEWBOX };
109
- }
110
- const x = Math.min(...validBoxes.map(box => box.x));
111
- const y = Math.min(...validBoxes.map(box => box.y));
112
- const right = Math.max(...validBoxes.map(box => box.x + box.w));
113
- const bottom = Math.max(...validBoxes.map(box => box.y + box.h));
114
- return {
115
- x,
116
- y,
117
- w: right - x,
118
- h: bottom - y
119
- };
107
+ const validBoxes = boxes.filter((box) => Number.isFinite(box.x) && Number.isFinite(box.y) && Number.isFinite(box.w) && Number.isFinite(box.h));
108
+ if (!validBoxes.length) return { ...DEFAULT_POINT_VIEWBOX };
109
+ const x = Math.min(...validBoxes.map((box) => box.x));
110
+ const y = Math.min(...validBoxes.map((box) => box.y));
111
+ const right = Math.max(...validBoxes.map((box) => box.x + box.w));
112
+ const bottom = Math.max(...validBoxes.map((box) => box.y + box.h));
113
+ return {
114
+ x,
115
+ y,
116
+ w: right - x,
117
+ h: bottom - y
118
+ };
120
119
  }
121
120
  /**
122
- * Multiply SVG affine matrices.
123
- * @param {Array} a Base matrix
124
- * @param {Array} b Matrix to append
125
- * @returns {Array} Combined matrix
126
- * @private
127
- */
121
+ * Multiply SVG affine matrices.
122
+ * @param {Array} a Base matrix
123
+ * @param {Array} b Matrix to append
124
+ * @returns {Array} Combined matrix
125
+ * @private
126
+ */
128
127
  function multiplyPointMatrix(a, b) {
129
- return [
130
- a[0] * b[0] + a[2] * b[1],
131
- a[1] * b[0] + a[3] * b[1],
132
- a[0] * b[2] + a[2] * b[3],
133
- a[1] * b[2] + a[3] * b[3],
134
- a[0] * b[4] + a[2] * b[5] + a[4],
135
- a[1] * b[4] + a[3] * b[5] + a[5]
136
- ];
128
+ return [
129
+ a[0] * b[0] + a[2] * b[1],
130
+ a[1] * b[0] + a[3] * b[1],
131
+ a[0] * b[2] + a[2] * b[3],
132
+ a[1] * b[2] + a[3] * b[3],
133
+ a[0] * b[4] + a[2] * b[5] + a[4],
134
+ a[1] * b[4] + a[3] * b[5] + a[5]
135
+ ];
137
136
  }
138
137
  /**
139
- * Parse SVG transform attribute into a canvas matrix.
140
- * @param {string|null} value Transform attribute
141
- * @returns {Array} Matrix
142
- * @private
143
- */
138
+ * Parse SVG transform attribute into a canvas matrix.
139
+ * @param {string|null} value Transform attribute
140
+ * @returns {Array} Matrix
141
+ * @private
142
+ */
144
143
  function parsePointTransform(value) {
145
- let matrix = [...IDENTITY_POINT_MATRIX];
146
- (value?.match(/[a-z]+\([^)]*\)/gi) || []).forEach(token => {
147
- const [, rawName, body] = token.match(/^([a-z]+)\(([^)]*)\)$/i) || [];
148
- const name = rawName?.toLowerCase();
149
- const values = (body?.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/gi) || [])
150
- .map(Number)
151
- .filter(Number.isFinite);
152
- let next = null;
153
- if (name === "matrix" && values.length >= 6) {
154
- next = values.slice(0, 6);
155
- }
156
- else if (name === "translate" && values.length) {
157
- next = [1, 0, 0, 1, values[0], values[1] || 0];
158
- }
159
- else if (name === "scale" && values.length) {
160
- next = [values[0], 0, 0, values[1] ?? values[0], 0, 0];
161
- }
162
- else if (name === "rotate" && values.length) {
163
- const angle = values[0] * Math.PI / 180;
164
- const cos = Math.cos(angle);
165
- const sin = Math.sin(angle);
166
- const rotate = [cos, sin, -sin, cos, 0, 0];
167
- next = values.length >= 3 ?
168
- multiplyPointMatrix(multiplyPointMatrix([1, 0, 0, 1, values[1], values[2]], rotate), [1, 0, 0, 1, -values[1], -values[2]]) :
169
- rotate;
170
- }
171
- else if (name === "skewx" && values.length) {
172
- next = [1, 0, Math.tan(values[0] * Math.PI / 180), 1, 0, 0];
173
- }
174
- else if (name === "skewy" && values.length) {
175
- next = [1, Math.tan(values[0] * Math.PI / 180), 0, 1, 0, 0];
176
- }
177
- next && (matrix = multiplyPointMatrix(matrix, next));
178
- });
179
- return matrix;
144
+ let matrix = [...IDENTITY_POINT_MATRIX];
145
+ (value?.match(/[a-z]+\([^)]*\)/gi) || []).forEach((token) => {
146
+ const [, rawName, body] = token.match(/^([a-z]+)\(([^)]*)\)$/i) || [];
147
+ const name = rawName?.toLowerCase();
148
+ const values = (body?.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/gi) || []).map(Number).filter(Number.isFinite);
149
+ let next = null;
150
+ if (name === "matrix" && values.length >= 6) next = values.slice(0, 6);
151
+ else if (name === "translate" && values.length) next = [
152
+ 1,
153
+ 0,
154
+ 0,
155
+ 1,
156
+ values[0],
157
+ values[1] || 0
158
+ ];
159
+ else if (name === "scale" && values.length) next = [
160
+ values[0],
161
+ 0,
162
+ 0,
163
+ values[1] ?? values[0],
164
+ 0,
165
+ 0
166
+ ];
167
+ else if (name === "rotate" && values.length) {
168
+ const angle = values[0] * Math.PI / 180;
169
+ const cos = Math.cos(angle);
170
+ const sin = Math.sin(angle);
171
+ const rotate = [
172
+ cos,
173
+ sin,
174
+ -sin,
175
+ cos,
176
+ 0,
177
+ 0
178
+ ];
179
+ next = values.length >= 3 ? multiplyPointMatrix(multiplyPointMatrix([
180
+ 1,
181
+ 0,
182
+ 0,
183
+ 1,
184
+ values[1],
185
+ values[2]
186
+ ], rotate), [
187
+ 1,
188
+ 0,
189
+ 0,
190
+ 1,
191
+ -values[1],
192
+ -values[2]
193
+ ]) : rotate;
194
+ } else if (name === "skewx" && values.length) next = [
195
+ 1,
196
+ 0,
197
+ Math.tan(values[0] * Math.PI / 180),
198
+ 1,
199
+ 0,
200
+ 0
201
+ ];
202
+ else if (name === "skewy" && values.length) next = [
203
+ 1,
204
+ Math.tan(values[0] * Math.PI / 180),
205
+ 0,
206
+ 1,
207
+ 0,
208
+ 0
209
+ ];
210
+ next && (matrix = multiplyPointMatrix(matrix, next));
211
+ });
212
+ return matrix;
180
213
  }
181
214
  /**
182
- * Read style or presentation attribute.
183
- * @param {Element} node SVG element
184
- * @param {string} name Property name
185
- * @returns {string|null} Property value
186
- * @private
187
- */
215
+ * Read style or presentation attribute.
216
+ * @param {Element} node SVG element
217
+ * @param {string} name Property name
218
+ * @returns {string|null} Property value
219
+ * @private
220
+ */
188
221
  function getPointPresentationValue(node, name) {
189
- const style = node.getAttribute("style");
190
- const attr = node.getAttribute(name);
191
- const match = style?.match(new RegExp(`(?:^|;)\\s*${name}\\s*:\\s*([^;]+)`, "i"));
192
- return (match?.[1] || attr || "").trim() || null;
222
+ const style = node.getAttribute("style");
223
+ const attr = node.getAttribute(name);
224
+ return ((style?.match(new RegExp(`(?:^|;)\\s*${name}\\s*:\\s*([^;]+)`, "i")))?.[1] || attr || "").trim() || null;
193
225
  }
194
226
  /**
195
- * Parse inherited point style from SVG presentation attributes.
196
- * @param {Element} node SVG element
197
- * @param {object} inherited Inherited style
198
- * @returns {object} Resolved style
199
- * @private
200
- */
227
+ * Parse inherited point style from SVG presentation attributes.
228
+ * @param {Element} node SVG element
229
+ * @param {object} inherited Inherited style
230
+ * @returns {object} Resolved style
231
+ * @private
232
+ */
201
233
  function parsePointStyle(node, inherited) {
202
- const style = { ...inherited };
203
- const fill = getPointPresentationValue(node, "fill");
204
- const stroke = getPointPresentationValue(node, "stroke");
205
- const strokeWidth = getPointPresentationValue(node, "stroke-width");
206
- const opacity = getPointPresentationValue(node, "opacity");
207
- const fillOpacity = getPointPresentationValue(node, "fill-opacity");
208
- const strokeOpacity = getPointPresentationValue(node, "stroke-opacity");
209
- if (fill) {
210
- style.fill = fill === "none" ? null : fill;
211
- }
212
- if (stroke) {
213
- style.stroke = stroke === "none" ? null : stroke;
214
- }
215
- if (strokeWidth) {
216
- const lineWidth = parseFloat(strokeWidth);
217
- Number.isFinite(lineWidth) && (style.lineWidth = lineWidth);
218
- }
219
- [opacity, fillOpacity, strokeOpacity].forEach(value => {
220
- const alpha = value === null ? NaN : parseFloat(value);
221
- Number.isFinite(alpha) && (style.alpha = (style.alpha ?? 1) * alpha);
222
- });
223
- return style;
234
+ const style = { ...inherited };
235
+ const fill = getPointPresentationValue(node, "fill");
236
+ const stroke = getPointPresentationValue(node, "stroke");
237
+ const strokeWidth = getPointPresentationValue(node, "stroke-width");
238
+ const opacity = getPointPresentationValue(node, "opacity");
239
+ const fillOpacity = getPointPresentationValue(node, "fill-opacity");
240
+ const strokeOpacity = getPointPresentationValue(node, "stroke-opacity");
241
+ if (fill) style.fill = fill === "none" ? null : fill;
242
+ if (stroke) style.stroke = stroke === "none" ? null : stroke;
243
+ if (strokeWidth) {
244
+ const lineWidth = parseFloat(strokeWidth);
245
+ Number.isFinite(lineWidth) && (style.lineWidth = lineWidth);
246
+ }
247
+ [
248
+ opacity,
249
+ fillOpacity,
250
+ strokeOpacity
251
+ ].forEach((value) => {
252
+ const alpha = value === null ? NaN : parseFloat(value);
253
+ Number.isFinite(alpha) && (style.alpha = (style.alpha ?? 1) * alpha);
254
+ });
255
+ return style;
224
256
  }
225
257
  /**
226
- * Collect local SVG definitions addressable by id.
227
- * @param {Element} root SVG root element
228
- * @returns {Map} Local definition map
229
- * @private
230
- */
258
+ * Collect local SVG definitions addressable by id.
259
+ * @param {Element} root SVG root element
260
+ * @returns {Map} Local definition map
261
+ * @private
262
+ */
231
263
  function collectPointDefs(root) {
232
- const defs = new Map();
233
- Array.from(root.querySelectorAll("[id]")).forEach(node => {
234
- const id = node.getAttribute("id");
235
- id && defs.set(id, node);
236
- });
237
- return defs;
264
+ const defs = /* @__PURE__ */ new Map();
265
+ Array.from(root.querySelectorAll("[id]")).forEach((node) => {
266
+ const id = node.getAttribute("id");
267
+ id && defs.set(id, node);
268
+ });
269
+ return defs;
238
270
  }
239
271
  /**
240
- * Parse SVG length or percentage for custom point paint coordinates.
241
- * @param {string|null} value SVG length value
242
- * @param {string|number} fallback Fallback value
243
- * @returns {string|number} Parsed value
244
- * @private
245
- */
272
+ * Parse SVG length or percentage for custom point paint coordinates.
273
+ * @param {string|null} value SVG length value
274
+ * @param {string|number} fallback Fallback value
275
+ * @returns {string|number} Parsed value
276
+ * @private
277
+ */
246
278
  function parsePointPaintLength(value, fallback) {
247
- const text = value?.trim();
248
- if (!text) {
249
- return fallback;
250
- }
251
- return /%$/.test(text) ? text : parseFloat(text);
279
+ const text = value?.trim();
280
+ if (!text) return fallback;
281
+ return /%$/.test(text) ? text : parseFloat(text);
252
282
  }
253
283
  /**
254
- * Convert SVG length/percentage into custom point coordinate space.
255
- * @param {string|number|undefined} value Length value
256
- * @param {number} origin Box origin
257
- * @param {number} size Box size
258
- * @param {number} fallback Fallback value
259
- * @returns {number} Coordinate
260
- * @private
261
- */
284
+ * Convert SVG length/percentage into custom point coordinate space.
285
+ * @param {string|number|undefined} value Length value
286
+ * @param {number} origin Box origin
287
+ * @param {number} size Box size
288
+ * @param {number} fallback Fallback value
289
+ * @returns {number} Coordinate
290
+ * @private
291
+ */
262
292
  function pointPaintCoord(value, origin, size, fallback) {
263
- if (typeof value === "number") {
264
- return Number.isFinite(value) ? value : fallback;
265
- }
266
- if (typeof value === "string" && /%$/.test(value)) {
267
- const percent = parseFloat(value);
268
- return Number.isFinite(percent) ? origin + size * percent / 100 : fallback;
269
- }
270
- const parsed = parseFloat(value ?? "");
271
- return Number.isFinite(parsed) ? parsed : fallback;
293
+ if (typeof value === "number") return Number.isFinite(value) ? value : fallback;
294
+ if (typeof value === "string" && /%$/.test(value)) {
295
+ const percent = parseFloat(value);
296
+ return Number.isFinite(percent) ? origin + size * percent / 100 : fallback;
297
+ }
298
+ const parsed = parseFloat(value ?? "");
299
+ return Number.isFinite(parsed) ? parsed : fallback;
272
300
  }
273
301
  /**
274
- * Parse SVG gradient stop offset.
275
- * @param {string|null} value Stop offset
276
- * @returns {number} Offset
277
- * @private
278
- */
302
+ * Parse SVG gradient stop offset.
303
+ * @param {string|null} value Stop offset
304
+ * @returns {number} Offset
305
+ * @private
306
+ */
279
307
  function parsePointPaintOffset(value) {
280
- const text = value?.trim() || "0";
281
- const parsed = parseFloat(text);
282
- const offset = /%$/.test(text) ? parsed / 100 : parsed;
283
- return Math.max(0, Math.min(1, Number.isFinite(offset) ? offset : 0));
308
+ const text = value?.trim() || "0";
309
+ const parsed = parseFloat(text);
310
+ const offset = /%$/.test(text) ? parsed / 100 : parsed;
311
+ return Math.max(0, Math.min(1, Number.isFinite(offset) ? offset : 0));
284
312
  }
285
313
  /**
286
- * Parse SVG gradient stops.
287
- * @param {Element} node Gradient node
288
- * @returns {Array} Stops
289
- * @private
290
- */
314
+ * Parse SVG gradient stops.
315
+ * @param {Element} node Gradient node
316
+ * @returns {Array} Stops
317
+ * @private
318
+ */
291
319
  function parsePointPaintStops(node) {
292
- return Array.from(node.children || [])
293
- .filter(child => child.tagName.toLowerCase() === "stop")
294
- .map(stop => {
295
- const color = getPointPresentationValue(stop, "stop-color") || "#000";
296
- const opacity = getPointPresentationValue(stop, "stop-opacity");
297
- const parsedOpacity = opacity === null ? NaN : parseFloat(opacity);
298
- return {
299
- offset: parsePointPaintOffset(stop.getAttribute("offset")),
300
- color,
301
- opacity: Number.isFinite(parsedOpacity) ? parsedOpacity : undefined
302
- };
303
- });
320
+ return Array.from(node.children || []).filter((child) => child.tagName.toLowerCase() === "stop").map((stop) => {
321
+ const color = getPointPresentationValue(stop, "stop-color") || "#000";
322
+ const opacity = getPointPresentationValue(stop, "stop-opacity");
323
+ const parsedOpacity = opacity === null ? NaN : parseFloat(opacity);
324
+ return {
325
+ offset: parsePointPaintOffset(stop.getAttribute("offset")),
326
+ color,
327
+ opacity: Number.isFinite(parsedOpacity) ? parsedOpacity : void 0
328
+ };
329
+ });
304
330
  }
305
331
  /**
306
- * Collect local linear/radial gradients addressable by id.
307
- * @param {Map} defs Local definition map
308
- * @returns {Map} Paint map
309
- * @private
310
- */
332
+ * Collect local linear/radial gradients addressable by id.
333
+ * @param {Map} defs Local definition map
334
+ * @returns {Map} Paint map
335
+ * @private
336
+ */
311
337
  function collectPointPaints(defs) {
312
- const paints = new Map();
313
- defs.forEach((node, id) => {
314
- const tagName = node.tagName.toLowerCase();
315
- const stops = parsePointPaintStops(node);
316
- if (!stops.length) {
317
- return;
318
- }
319
- if (tagName === "lineargradient") {
320
- paints.set(id, {
321
- type: "linearGradient",
322
- x1: parsePointPaintLength(node.getAttribute("x1"), "0%"),
323
- y1: parsePointPaintLength(node.getAttribute("y1"), "0%"),
324
- x2: parsePointPaintLength(node.getAttribute("x2"), "100%"),
325
- y2: parsePointPaintLength(node.getAttribute("y2"), "0%"),
326
- stops
327
- });
328
- }
329
- else if (tagName === "radialgradient") {
330
- paints.set(id, {
331
- type: "radialGradient",
332
- cx: parsePointPaintLength(node.getAttribute("cx"), "50%"),
333
- cy: parsePointPaintLength(node.getAttribute("cy"), "50%"),
334
- r: parsePointPaintLength(node.getAttribute("r"), "50%"),
335
- fx: parsePointPaintLength(node.getAttribute("fx"), "50%"),
336
- fy: parsePointPaintLength(node.getAttribute("fy"), "50%"),
337
- fr: parsePointPaintLength(node.getAttribute("fr"), 0),
338
- stops
339
- });
340
- }
341
- });
342
- return paints;
338
+ const paints = /* @__PURE__ */ new Map();
339
+ defs.forEach((node, id) => {
340
+ const tagName = node.tagName.toLowerCase();
341
+ const stops = parsePointPaintStops(node);
342
+ if (!stops.length) return;
343
+ if (tagName === "lineargradient") paints.set(id, {
344
+ type: "linearGradient",
345
+ x1: parsePointPaintLength(node.getAttribute("x1"), "0%"),
346
+ y1: parsePointPaintLength(node.getAttribute("y1"), "0%"),
347
+ x2: parsePointPaintLength(node.getAttribute("x2"), "100%"),
348
+ y2: parsePointPaintLength(node.getAttribute("y2"), "0%"),
349
+ stops
350
+ });
351
+ else if (tagName === "radialgradient") paints.set(id, {
352
+ type: "radialGradient",
353
+ cx: parsePointPaintLength(node.getAttribute("cx"), "50%"),
354
+ cy: parsePointPaintLength(node.getAttribute("cy"), "50%"),
355
+ r: parsePointPaintLength(node.getAttribute("r"), "50%"),
356
+ fx: parsePointPaintLength(node.getAttribute("fx"), "50%"),
357
+ fy: parsePointPaintLength(node.getAttribute("fy"), "50%"),
358
+ fr: parsePointPaintLength(node.getAttribute("fr"), 0),
359
+ stops
360
+ });
361
+ });
362
+ return paints;
343
363
  }
344
364
  /**
345
- * Parse custom SVG point element into canvas drawable shapes.
346
- * @param {Element} node SVG element
347
- * @param {object} fallbackBox Fallback bounds for path-only shapes
348
- * @param {Map} defs Local definitions
349
- * @param {Array} matrix Current transform matrix
350
- * @param {object} inheritedStyle Current inherited style
351
- * @param {Set} seen Already resolved definition ids
352
- * @returns {Array} Parsed shapes
353
- * @private
354
- */
355
- function parseCustomPointNode(node, fallbackBox, defs, matrix = IDENTITY_POINT_MATRIX, inheritedStyle = {}, seen = new Set()) {
356
- const tagName = node.tagName.toLowerCase();
357
- const children = Array.from(node.children || []);
358
- const style = parsePointStyle(node, inheritedStyle);
359
- const transform = multiplyPointMatrix(matrix, parsePointTransform(node.getAttribute("transform")));
360
- const shapeBase = { matrix: transform, style };
361
- if (tagName === "defs") {
362
- return [];
363
- }
364
- if (tagName === "svg" || tagName === "g" || tagName === "symbol") {
365
- return children.reduce((shapes, child) => shapes.concat(parseCustomPointNode(child, fallbackBox, defs, transform, style, seen)), []);
366
- }
367
- if (tagName === "use") {
368
- const href = node.getAttribute("href") || node.getAttribute("xlink:href") || "";
369
- const id = href.charAt(0) === "#" ? href.slice(1) : "";
370
- const target = id && defs.get(id);
371
- if (!target || seen.has(id)) {
372
- return [];
373
- }
374
- const x = getSvgNumber(node, "x", 0);
375
- const y = getSvgNumber(node, "y", 0);
376
- const useTransform = multiplyPointMatrix(transform, [1, 0, 0, 1, x, y]);
377
- seen.add(id);
378
- const shapes = parseCustomPointNode(target, fallbackBox, defs, useTransform, style, seen);
379
- seen.delete(id);
380
- return shapes;
381
- }
382
- if (tagName === "polygon" || tagName === "polyline") {
383
- const points = parseSvgPoints(node.getAttribute("points") || "");
384
- return points.length ?
385
- [{
386
- type: tagName,
387
- points,
388
- box: getPointsBox(points),
389
- ...shapeBase
390
- }] :
391
- [];
392
- }
393
- if (tagName === "circle") {
394
- const cx = getSvgNumber(node, "cx", 0);
395
- const cy = getSvgNumber(node, "cy", 0);
396
- const r = getSvgNumber(node, "r", 0);
397
- return r > 0 ?
398
- [{
399
- type: "circle",
400
- cx,
401
- cy,
402
- r,
403
- box: { x: cx - r, y: cy - r, w: r * 2, h: r * 2 },
404
- ...shapeBase
405
- }] :
406
- [];
407
- }
408
- if (tagName === "ellipse") {
409
- const cx = getSvgNumber(node, "cx", 0);
410
- const cy = getSvgNumber(node, "cy", 0);
411
- const rx = getSvgNumber(node, "rx", 0);
412
- const ry = getSvgNumber(node, "ry", 0);
413
- return rx > 0 && ry > 0 ?
414
- [{
415
- type: "ellipse",
416
- cx,
417
- cy,
418
- rx,
419
- ry,
420
- box: { x: cx - rx, y: cy - ry, w: rx * 2, h: ry * 2 },
421
- ...shapeBase
422
- }] :
423
- [];
424
- }
425
- if (tagName === "rect") {
426
- const x = getSvgNumber(node, "x", 0);
427
- const y = getSvgNumber(node, "y", 0);
428
- const w = getSvgNumber(node, "width", 0);
429
- const h = getSvgNumber(node, "height", 0);
430
- return w > 0 && h > 0 ?
431
- [{
432
- type: "rect",
433
- x,
434
- y,
435
- w,
436
- h,
437
- box: { x, y, w, h },
438
- ...shapeBase
439
- }] :
440
- [];
441
- }
442
- if (tagName === "line") {
443
- const x1 = getSvgNumber(node, "x1", 0);
444
- const y1 = getSvgNumber(node, "y1", 0);
445
- const x2 = getSvgNumber(node, "x2", 0);
446
- const y2 = getSvgNumber(node, "y2", 0);
447
- return [{
448
- type: "line",
449
- x1,
450
- y1,
451
- x2,
452
- y2,
453
- box: getPointsBox([[x1, y1], [x2, y2]]),
454
- ...shapeBase
455
- }];
456
- }
457
- if (tagName === "path") {
458
- const d = node.getAttribute("d") || "";
459
- return d ?
460
- [{
461
- type: "path",
462
- d,
463
- box: fallbackBox,
464
- ...shapeBase
465
- }] :
466
- [];
467
- }
468
- return [];
365
+ * Parse custom SVG point element into canvas drawable shapes.
366
+ * @param {Element} node SVG element
367
+ * @param {object} fallbackBox Fallback bounds for path-only shapes
368
+ * @param {Map} defs Local definitions
369
+ * @param {Array} matrix Current transform matrix
370
+ * @param {object} inheritedStyle Current inherited style
371
+ * @param {Set} seen Already resolved definition ids
372
+ * @returns {Array} Parsed shapes
373
+ * @private
374
+ */
375
+ function parseCustomPointNode(node, fallbackBox, defs, matrix = IDENTITY_POINT_MATRIX, inheritedStyle = {}, seen = /* @__PURE__ */ new Set()) {
376
+ const tagName = node.tagName.toLowerCase();
377
+ const children = Array.from(node.children || []);
378
+ const style = parsePointStyle(node, inheritedStyle);
379
+ const transform = multiplyPointMatrix(matrix, parsePointTransform(node.getAttribute("transform")));
380
+ const shapeBase = {
381
+ matrix: transform,
382
+ style
383
+ };
384
+ if (tagName === "defs") return [];
385
+ if (tagName === "svg" || tagName === "g" || tagName === "symbol") return children.reduce((shapes, child) => shapes.concat(parseCustomPointNode(child, fallbackBox, defs, transform, style, seen)), []);
386
+ if (tagName === "use") {
387
+ const href = node.getAttribute("href") || node.getAttribute("xlink:href") || "";
388
+ const id = href.charAt(0) === "#" ? href.slice(1) : "";
389
+ const target = id && defs.get(id);
390
+ if (!target || seen.has(id)) return [];
391
+ const useTransform = multiplyPointMatrix(transform, [
392
+ 1,
393
+ 0,
394
+ 0,
395
+ 1,
396
+ getSvgNumber(node, "x", 0),
397
+ getSvgNumber(node, "y", 0)
398
+ ]);
399
+ seen.add(id);
400
+ const shapes = parseCustomPointNode(target, fallbackBox, defs, useTransform, style, seen);
401
+ seen.delete(id);
402
+ return shapes;
403
+ }
404
+ if (tagName === "polygon" || tagName === "polyline") {
405
+ const points = parseSvgPoints(node.getAttribute("points") || "");
406
+ return points.length ? [{
407
+ type: tagName,
408
+ points,
409
+ box: getPointsBox(points),
410
+ ...shapeBase
411
+ }] : [];
412
+ }
413
+ if (tagName === "circle") {
414
+ const cx = getSvgNumber(node, "cx", 0);
415
+ const cy = getSvgNumber(node, "cy", 0);
416
+ const r = getSvgNumber(node, "r", 0);
417
+ return r > 0 ? [{
418
+ type: "circle",
419
+ cx,
420
+ cy,
421
+ r,
422
+ box: {
423
+ x: cx - r,
424
+ y: cy - r,
425
+ w: r * 2,
426
+ h: r * 2
427
+ },
428
+ ...shapeBase
429
+ }] : [];
430
+ }
431
+ if (tagName === "ellipse") {
432
+ const cx = getSvgNumber(node, "cx", 0);
433
+ const cy = getSvgNumber(node, "cy", 0);
434
+ const rx = getSvgNumber(node, "rx", 0);
435
+ const ry = getSvgNumber(node, "ry", 0);
436
+ return rx > 0 && ry > 0 ? [{
437
+ type: "ellipse",
438
+ cx,
439
+ cy,
440
+ rx,
441
+ ry,
442
+ box: {
443
+ x: cx - rx,
444
+ y: cy - ry,
445
+ w: rx * 2,
446
+ h: ry * 2
447
+ },
448
+ ...shapeBase
449
+ }] : [];
450
+ }
451
+ if (tagName === "rect") {
452
+ const x = getSvgNumber(node, "x", 0);
453
+ const y = getSvgNumber(node, "y", 0);
454
+ const w = getSvgNumber(node, "width", 0);
455
+ const h = getSvgNumber(node, "height", 0);
456
+ return w > 0 && h > 0 ? [{
457
+ type: "rect",
458
+ x,
459
+ y,
460
+ w,
461
+ h,
462
+ box: {
463
+ x,
464
+ y,
465
+ w,
466
+ h
467
+ },
468
+ ...shapeBase
469
+ }] : [];
470
+ }
471
+ if (tagName === "line") {
472
+ const x1 = getSvgNumber(node, "x1", 0);
473
+ const y1 = getSvgNumber(node, "y1", 0);
474
+ const x2 = getSvgNumber(node, "x2", 0);
475
+ const y2 = getSvgNumber(node, "y2", 0);
476
+ return [{
477
+ type: "line",
478
+ x1,
479
+ y1,
480
+ x2,
481
+ y2,
482
+ box: getPointsBox([[x1, y1], [x2, y2]]),
483
+ ...shapeBase
484
+ }];
485
+ }
486
+ if (tagName === "path") {
487
+ const d = node.getAttribute("d") || "";
488
+ return d ? [{
489
+ type: "path",
490
+ d,
491
+ box: fallbackBox,
492
+ ...shapeBase
493
+ }] : [];
494
+ }
495
+ return [];
469
496
  }
470
497
  /**
471
- * Parse a custom SVG point pattern string.
472
- * @param {string} pattern SVG pattern
473
- * @returns {object|null} Parsed pattern
474
- * @private
475
- */
498
+ * Parse a custom SVG point pattern string.
499
+ * @param {string} pattern SVG pattern
500
+ * @returns {object|null} Parsed pattern
501
+ * @private
502
+ */
476
503
  function parseCustomPointPattern(pattern) {
477
- if (!/^</.test(pattern)) {
478
- return null;
479
- }
480
- if (customPointPatternCache.has(pattern)) {
481
- return customPointPatternCache.get(pattern) || null;
482
- }
483
- let parsed = null;
484
- try {
485
- const doc = new win.DOMParser().parseFromString(sanitize(pattern), "image/svg+xml");
486
- const root = doc.documentElement;
487
- const fallbackBox = parseViewBox(root.getAttribute("viewBox")) || DEFAULT_POINT_VIEWBOX;
488
- const defs = collectPointDefs(root);
489
- const shapes = parseCustomPointNode(root, fallbackBox, defs);
490
- if (shapes.length) {
491
- parsed = {
492
- shapes,
493
- box: root.tagName.toLowerCase() === "svg" ?
494
- fallbackBox :
495
- mergePointBoxes(shapes.map(shape => shape.box)),
496
- paints: collectPointPaints(defs)
497
- };
498
- }
499
- }
500
- catch {
501
- parsed = null;
502
- }
503
- customPointPatternCache.set(pattern, parsed);
504
- return parsed;
504
+ if (!/^</.test(pattern)) return null;
505
+ if (customPointPatternCache.has(pattern)) return customPointPatternCache.get(pattern) || null;
506
+ let parsed = null;
507
+ try {
508
+ const root = new win.DOMParser().parseFromString(sanitize(pattern), "image/svg+xml").documentElement;
509
+ const fallbackBox = parseViewBox(root.getAttribute("viewBox")) || DEFAULT_POINT_VIEWBOX;
510
+ const defs = collectPointDefs(root);
511
+ const shapes = parseCustomPointNode(root, fallbackBox, defs);
512
+ if (shapes.length) parsed = {
513
+ shapes,
514
+ box: root.tagName.toLowerCase() === "svg" ? fallbackBox : mergePointBoxes(shapes.map((shape) => shape.box)),
515
+ paints: collectPointPaints(defs)
516
+ };
517
+ } catch {
518
+ parsed = null;
519
+ }
520
+ customPointPatternCache.set(pattern, parsed);
521
+ return parsed;
505
522
  }
506
523
  /**
507
- * Trace a parsed custom SVG point shape.
508
- * @param {CanvasRenderingContext2D} ctx Canvas context
509
- * @param {object} shape Parsed shape
510
- * @private
511
- */
524
+ * Trace a parsed custom SVG point shape.
525
+ * @param {CanvasRenderingContext2D} ctx Canvas context
526
+ * @param {object} shape Parsed shape
527
+ * @private
528
+ */
512
529
  function traceCustomPointShape(ctx, shape) {
513
- if (shape.type === "polygon" || shape.type === "polyline") {
514
- const [start, ...rest] = shape.points;
515
- ctx.moveTo(start[0], start[1]);
516
- rest.forEach(([x, y]) => ctx.lineTo(x, y));
517
- shape.type === "polygon" && ctx.closePath();
518
- }
519
- else if (shape.type === "circle") {
520
- ctx.moveTo(shape.cx + shape.r, shape.cy);
521
- ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2);
522
- }
523
- else if (shape.type === "ellipse") {
524
- ctx.moveTo(shape.cx + shape.rx, shape.cy);
525
- ctx.ellipse(shape.cx, shape.cy, shape.rx, shape.ry, 0, 0, Math.PI * 2);
526
- }
527
- else if (shape.type === "rect") {
528
- ctx.rect(shape.x, shape.y, shape.w, shape.h);
529
- }
530
- else if (shape.type === "line") {
531
- ctx.moveTo(shape.x1, shape.y1);
532
- ctx.lineTo(shape.x2, shape.y2);
533
- }
530
+ if (shape.type === "polygon" || shape.type === "polyline") {
531
+ const [start, ...rest] = shape.points;
532
+ ctx.moveTo(start[0], start[1]);
533
+ rest.forEach(([x, y]) => ctx.lineTo(x, y));
534
+ shape.type === "polygon" && ctx.closePath();
535
+ } else if (shape.type === "circle") {
536
+ ctx.moveTo(shape.cx + shape.r, shape.cy);
537
+ ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2);
538
+ } else if (shape.type === "ellipse") {
539
+ ctx.moveTo(shape.cx + shape.rx, shape.cy);
540
+ ctx.ellipse(shape.cx, shape.cy, shape.rx, shape.ry, 0, 0, Math.PI * 2);
541
+ } else if (shape.type === "rect") ctx.rect(shape.x, shape.y, shape.w, shape.h);
542
+ else if (shape.type === "line") {
543
+ ctx.moveTo(shape.x1, shape.y1);
544
+ ctx.lineTo(shape.x2, shape.y2);
545
+ }
534
546
  }
535
547
  /**
536
- * Extract local SVG paint server id.
537
- * @param {string|null|undefined} value Paint value
538
- * @returns {string|null} Paint id
539
- * @private
540
- */
548
+ * Extract local SVG paint server id.
549
+ * @param {string|null|undefined} value Paint value
550
+ * @returns {string|null} Paint id
551
+ * @private
552
+ */
541
553
  function getCustomPointPaintId(value) {
542
- const match = value?.match(/^url\(#([^)]+)\)$/);
543
- return match?.[1] || null;
554
+ return (value?.match(/^url\(#([^)]+)\)$/))?.[1] || null;
544
555
  }
545
556
  /**
546
- * Create canvas gradient for a local custom point paint server.
547
- * @param {CanvasRenderingContext2D} ctx Canvas context
548
- * @param {object} paint Paint server
549
- * @param {object} box Pattern box
550
- * @returns {CanvasGradient} Canvas gradient
551
- * @private
552
- */
557
+ * Create canvas gradient for a local custom point paint server.
558
+ * @param {CanvasRenderingContext2D} ctx Canvas context
559
+ * @param {object} paint Paint server
560
+ * @param {object} box Pattern box
561
+ * @returns {CanvasGradient} Canvas gradient
562
+ * @private
563
+ */
553
564
  function createCustomPointPaint(ctx, paint, box) {
554
- const { x, y, w, h } = box;
555
- const gradient = paint.type === "linearGradient" ?
556
- ctx.createLinearGradient(pointPaintCoord(paint.x1, x, w, x), pointPaintCoord(paint.y1, y, h, y), pointPaintCoord(paint.x2, x, w, x + w), pointPaintCoord(paint.y2, y, h, y)) :
557
- ctx.createRadialGradient(pointPaintCoord(paint.fx, x, w, x + w / 2), pointPaintCoord(paint.fy, y, h, y + h / 2), pointPaintCoord(paint.fr, x, Math.max(w, h), 0), pointPaintCoord(paint.cx, x, w, x + w / 2), pointPaintCoord(paint.cy, y, h, y + h / 2), Math.max(0.01, pointPaintCoord(paint.r, 0, Math.max(w, h), Math.max(w, h) / 2)));
558
- paint.stops.forEach(({ offset, color, opacity }) => {
559
- gradient.addColorStop(offset, opacity === undefined ? color : withOpacity(color, opacity));
560
- });
561
- return gradient;
565
+ const { x, y, w, h } = box;
566
+ const gradient = paint.type === "linearGradient" ? ctx.createLinearGradient(pointPaintCoord(paint.x1, x, w, x), pointPaintCoord(paint.y1, y, h, y), pointPaintCoord(paint.x2, x, w, x + w), pointPaintCoord(paint.y2, y, h, y)) : ctx.createRadialGradient(pointPaintCoord(paint.fx, x, w, x + w / 2), pointPaintCoord(paint.fy, y, h, y + h / 2), pointPaintCoord(paint.fr, x, Math.max(w, h), 0), pointPaintCoord(paint.cx, x, w, x + w / 2), pointPaintCoord(paint.cy, y, h, y + h / 2), Math.max(.01, pointPaintCoord(paint.r, 0, Math.max(w, h), Math.max(w, h) / 2)));
567
+ paint.stops.forEach(({ offset, color, opacity }) => {
568
+ gradient.addColorStop(offset, opacity === void 0 ? color : withOpacity(color, opacity));
569
+ });
570
+ return gradient;
562
571
  }
563
572
  /**
564
- * Resolve custom SVG point shape style against the caller-provided canvas style.
565
- * @param {CanvasRenderingContext2D} ctx Canvas context
566
- * @param {object} base Base canvas style
567
- * @param {object} shapeStyle SVG shape style
568
- * @param {Map} paints Local paint servers
569
- * @param {object} box Pattern box
570
- * @returns {object} Draw style and paint flags
571
- * @private
572
- */
573
+ * Resolve custom SVG point shape style against the caller-provided canvas style.
574
+ * @param {CanvasRenderingContext2D} ctx Canvas context
575
+ * @param {object} base Base canvas style
576
+ * @param {object} shapeStyle SVG shape style
577
+ * @param {Map} paints Local paint servers
578
+ * @param {object} box Pattern box
579
+ * @returns {object} Draw style and paint flags
580
+ * @private
581
+ */
573
582
  function getCustomPointDrawStyle(ctx, base, shapeStyle, paints, box) {
574
- const style = { ...(base || {}) };
575
- if (shapeStyle.fill !== undefined) {
576
- if (shapeStyle.fill === null) {
577
- delete style.fill;
578
- }
579
- else if (getCustomPointPaintId(shapeStyle.fill)) {
580
- const paint = paints.get(getCustomPointPaintId(shapeStyle.fill));
581
- paint && (style.fill = createCustomPointPaint(ctx, paint, box));
582
- }
583
- else if (!/^url\(/.test(shapeStyle.fill)) {
584
- style.fill = shapeStyle.fill;
585
- }
586
- }
587
- if (shapeStyle.stroke !== undefined) {
588
- if (shapeStyle.stroke === null) {
589
- delete style.stroke;
590
- }
591
- else if (getCustomPointPaintId(shapeStyle.stroke)) {
592
- const paint = paints.get(getCustomPointPaintId(shapeStyle.stroke));
593
- paint && (style.stroke = createCustomPointPaint(ctx, paint, box));
594
- }
595
- else if (!/^url\(/.test(shapeStyle.stroke)) {
596
- style.stroke = shapeStyle.stroke;
597
- }
598
- }
599
- shapeStyle.lineWidth !== undefined && (style.lineWidth = shapeStyle.lineWidth);
600
- return {
601
- style,
602
- shouldFill: shapeStyle.fill !== null && (!style.stroke || style.fill !== undefined),
603
- shouldStroke: shapeStyle.stroke !== null && style.stroke !== undefined,
604
- alpha: shapeStyle.alpha
605
- };
583
+ const style = { ...base || {} };
584
+ if (shapeStyle.fill !== void 0) {
585
+ if (shapeStyle.fill === null) delete style.fill;
586
+ else if (getCustomPointPaintId(shapeStyle.fill)) {
587
+ const paint = paints.get(getCustomPointPaintId(shapeStyle.fill));
588
+ paint && (style.fill = createCustomPointPaint(ctx, paint, box));
589
+ } else if (!/^url\(/.test(shapeStyle.fill)) style.fill = shapeStyle.fill;
590
+ }
591
+ if (shapeStyle.stroke !== void 0) {
592
+ if (shapeStyle.stroke === null) delete style.stroke;
593
+ else if (getCustomPointPaintId(shapeStyle.stroke)) {
594
+ const paint = paints.get(getCustomPointPaintId(shapeStyle.stroke));
595
+ paint && (style.stroke = createCustomPointPaint(ctx, paint, box));
596
+ } else if (!/^url\(/.test(shapeStyle.stroke)) style.stroke = shapeStyle.stroke;
597
+ }
598
+ shapeStyle.lineWidth !== void 0 && (style.lineWidth = shapeStyle.lineWidth);
599
+ return {
600
+ style,
601
+ shouldFill: shapeStyle.fill !== null && (!style.stroke || style.fill !== void 0),
602
+ shouldStroke: shapeStyle.stroke !== null && style.stroke !== void 0,
603
+ alpha: shapeStyle.alpha
604
+ };
606
605
  }
607
606
  /**
608
- * Draw built-in or custom SVG point pattern.
609
- * @param {CanvasPainter} painter Canvas painter
610
- * @param {string} pattern Point type or SVG pattern
611
- * @param {number} x X coordinate
612
- * @param {number} y Y coordinate
613
- * @param {number} r Radius
614
- * @param {object} style Optional style
615
- * @param {number} baseR Unexpanded radius used to resolve custom pattern scale
616
- * @private
617
- */
607
+ * Draw built-in or custom SVG point pattern.
608
+ * @param {CanvasPainter} painter Canvas painter
609
+ * @param {string} pattern Point type or SVG pattern
610
+ * @param {number} x X coordinate
611
+ * @param {number} y Y coordinate
612
+ * @param {number} r Radius
613
+ * @param {object} style Optional style
614
+ * @param {number} baseR Unexpanded radius used to resolve custom pattern scale
615
+ * @private
616
+ */
618
617
  function drawPointPattern(painter, pattern, x, y, r, style, baseR = r) {
619
- if (isBuiltinPointType(pattern)) {
620
- painter.point(pattern, x, y, r, style);
621
- return;
622
- }
623
- const parsed = parseCustomPointPattern(pattern);
624
- if (!parsed || r <= 0) {
625
- painter.point("circle", x, y, r, style);
626
- return;
627
- }
628
- painter.withState(ctx => {
629
- const { box, paints, shapes } = parsed;
630
- const scale = baseR > 0 ? r / baseR : 1;
631
- const drawShape = (shape) => {
632
- const { style: drawStyle, shouldFill, shouldStroke, alpha } = getCustomPointDrawStyle(ctx, style, shape.style, paints, box);
633
- ctx.save();
634
- painter.applyStyle(drawStyle);
635
- alpha !== undefined && (ctx.globalAlpha *= alpha);
636
- ctx.transform(...shape.matrix);
637
- ctx.beginPath();
638
- if (shape.type === "path") {
639
- if (win.Path2D) {
640
- const path = shape.path2D || (shape.path2D = new win.Path2D(shape.d));
641
- shouldFill && ctx.fill(path);
642
- shouldStroke && ctx.stroke(path);
643
- }
644
- }
645
- else {
646
- traceCustomPointShape(ctx, shape);
647
- shouldFill && ctx.fill();
648
- shouldStroke && ctx.stroke();
649
- }
650
- ctx.restore();
651
- };
652
- ctx.translate(x - (box.x + box.w / 2) * scale, y - (box.y + box.h / 2) * scale);
653
- ctx.scale(scale, scale);
654
- shapes.forEach(drawShape);
655
- });
618
+ if (isBuiltinPointType(pattern)) {
619
+ painter.point(pattern, x, y, r, style);
620
+ return;
621
+ }
622
+ const parsed = parseCustomPointPattern(pattern);
623
+ if (!parsed || r <= 0) {
624
+ painter.point("circle", x, y, r, style);
625
+ return;
626
+ }
627
+ painter.withState((ctx) => {
628
+ const { box, paints, shapes } = parsed;
629
+ const scale = baseR > 0 ? r / baseR : 1;
630
+ const drawShape = (shape) => {
631
+ const { style: drawStyle, shouldFill, shouldStroke, alpha } = getCustomPointDrawStyle(ctx, style, shape.style, paints, box);
632
+ ctx.save();
633
+ painter.applyStyle(drawStyle);
634
+ alpha !== void 0 && (ctx.globalAlpha *= alpha);
635
+ ctx.transform(...shape.matrix);
636
+ ctx.beginPath();
637
+ if (shape.type === "path") {
638
+ if (win.Path2D) {
639
+ const path = shape.path2D || (shape.path2D = new win.Path2D(shape.d));
640
+ shouldFill && ctx.fill(path);
641
+ shouldStroke && ctx.stroke(path);
642
+ }
643
+ } else {
644
+ traceCustomPointShape(ctx, shape);
645
+ shouldFill && ctx.fill();
646
+ shouldStroke && ctx.stroke();
647
+ }
648
+ ctx.restore();
649
+ };
650
+ ctx.translate(x - (box.x + box.w / 2) * scale, y - (box.y + box.h / 2) * scale);
651
+ ctx.scale(scale, scale);
652
+ shapes.forEach(drawShape);
653
+ });
656
654
  }
657
-
655
+ //#endregion
658
656
  export { drawPointPattern };