billboard.js 4.0.3 → 4.1.0-next.2

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 (271) hide show
  1. package/README.md +82 -7
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +1848 -494
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +19 -24
  6. package/dist/billboard.pkgd.js +1844 -679
  7. package/dist/billboard.pkgd.min.js +24 -29
  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 +5 -3
  12. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-sparkline.js +6 -3
  14. package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
  15. package/dist/plugin/billboardjs-plugin-stanford.js +6 -3
  16. package/dist/plugin/billboardjs-plugin-stanford.min.js +3 -3
  17. package/dist/plugin/billboardjs-plugin-tableview.js +59 -27
  18. package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
  19. package/dist/plugin/billboardjs-plugin-textoverlap.js +75 -55
  20. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  21. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +5 -3
  22. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
  23. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +6 -3
  24. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
  25. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +6 -3
  26. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
  27. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +59 -27
  28. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
  29. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +68 -3557
  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 -143
  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 +967 -1153
  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 +285 -236
  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 -288
  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 -425
  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 -843
  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/selection.ts +130 -5
  222. package/src/ChartInternal/Axis/Axis.ts +164 -65
  223. package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
  224. package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
  225. package/src/ChartInternal/ChartInternal.ts +1 -1
  226. package/src/ChartInternal/data/convert.ts +54 -4
  227. package/src/ChartInternal/data/data.ts +4 -1
  228. package/src/ChartInternal/interactions/eventrect.ts +8 -2
  229. package/src/ChartInternal/interactions/subchart.ts +437 -66
  230. package/src/ChartInternal/internals/color.ts +2 -2
  231. package/src/ChartInternal/internals/domain.ts +15 -3
  232. package/src/ChartInternal/internals/grid.ts +21 -1
  233. package/src/ChartInternal/internals/scale.ts +9 -2
  234. package/src/ChartInternal/internals/selection.ts +1 -1
  235. package/src/ChartInternal/internals/subchart.util.ts +55 -0
  236. package/src/ChartInternal/internals/text.arc.ts +3 -1
  237. package/src/ChartInternal/internals/text.ts +18 -5
  238. package/src/ChartInternal/internals/transform.ts +8 -2
  239. package/src/ChartInternal/internals/type.ts +105 -1
  240. package/src/ChartInternal/shape/IShape.ts +6 -3
  241. package/src/ChartInternal/shape/bar.ts +62 -31
  242. package/src/ChartInternal/shape/core/barRadius.ts +129 -0
  243. package/src/ChartInternal/shape/core/candlestick.ts +1 -1
  244. package/src/ChartInternal/shape/core/path.ts +76 -9
  245. package/src/ChartInternal/shape/funnel.ts +2 -3
  246. package/src/ChartInternal/shape/point.ts +2 -2
  247. package/src/ChartInternal/shape/shape.ts +149 -17
  248. package/src/Plugin/stanford/index.ts +0 -4
  249. package/src/Plugin/tableview/index.ts +85 -3
  250. package/src/Plugin/textoverlap/index.ts +9 -15
  251. package/src/canvas/CanvasAxisRenderer.ts +184 -36
  252. package/src/canvas/CanvasRenderer.ts +247 -160
  253. package/src/canvas/CanvasTheme.ts +212 -0
  254. package/src/canvas/axisTicks.ts +122 -40
  255. package/src/config/Options/axis/y2.ts +13 -0
  256. package/src/config/Options/common/boost.ts +64 -4
  257. package/src/config/Options/common/color.ts +2 -2
  258. package/src/config/Options/interaction/subchart.ts +98 -1
  259. package/src/config/Options/shape/gauge.ts +1 -1
  260. package/src/config/Options/shape/treemap.ts +2 -2
  261. package/src/config/Store/Element.ts +3 -1
  262. package/src/config/Store/State.ts +1 -0
  263. package/src/config/classes.ts +1 -0
  264. package/src/config/resolver/canvas.ts +92 -10
  265. package/src/module/util/type-checks.ts +3 -1
  266. package/src/module/voronoi.ts +119 -0
  267. package/src/module/worker.entry.ts +61 -0
  268. package/src/module/worker.ts +346 -63
  269. package/src/react/index.ts +193 -0
  270. package/types/options.d.ts +206 -3
  271. package/types/react/index.d.ts +27 -0
@@ -5,446 +5,349 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 4.0.3
8
+ * @version 4.1.0-next.2
9
9
  */
10
+ //#region src/module/sanitize.ts
10
11
  /**
11
- * Copyright (c) 2017 ~ present NAVER Corp.
12
- * billboard.js project is licensed under the MIT license
13
- * @ignore
14
- */
12
+ * Copyright (c) 2017 ~ present NAVER Corp.
13
+ * billboard.js project is licensed under the MIT license
14
+ * @ignore
15
+ */
15
16
  /**
16
- * HTML/SVG Sanitization module
17
- * Pure whitelist approach - only explicitly allowed tags, attributes, and protocols pass through
18
- */
19
- // Whitelist of allowed HTML/SVG tags
20
- const ALLOWED_TAGS = new Set([
21
- // HTML tags for tooltip/legend templates
22
- "span",
23
- "div",
24
- "p",
25
- "br",
26
- "b",
27
- "i",
28
- "em",
29
- "small",
30
- "strong",
31
- "mark",
32
- "u",
33
- "s",
34
- "sub",
35
- "sup",
36
- "h1",
37
- "h2",
38
- "h3",
39
- "h4",
40
- "h5",
41
- "h6",
42
- "ul",
43
- "ol",
44
- "li",
45
- "dl",
46
- "dt",
47
- "dd",
48
- "table",
49
- "thead",
50
- "tbody",
51
- "tfoot",
52
- "tr",
53
- "th",
54
- "td",
55
- "caption",
56
- "colgroup",
57
- "col",
58
- "hr",
59
- "pre",
60
- "code",
61
- "blockquote",
62
- "abbr",
63
- "ins",
64
- "del",
65
- "a",
66
- "img",
67
- "figure",
68
- "figcaption",
69
- // SVG tags for point patterns
70
- "svg",
71
- "g",
72
- "path",
73
- "circle",
74
- "ellipse",
75
- "rect",
76
- "line",
77
- "polyline",
78
- "polygon",
79
- "text",
80
- "tspan",
81
- "textPath",
82
- "use",
83
- "defs",
84
- "symbol",
85
- "clipPath",
86
- "mask",
87
- "linearGradient",
88
- "radialGradient",
89
- "stop",
90
- "pattern",
91
- "marker",
92
- "title",
93
- "desc"
17
+ * HTML/SVG Sanitization module
18
+ * Pure whitelist approach - only explicitly allowed tags, attributes, and protocols pass through
19
+ */
20
+ const ALLOWED_TAGS = /* @__PURE__ */ new Set([
21
+ "span",
22
+ "div",
23
+ "p",
24
+ "br",
25
+ "b",
26
+ "i",
27
+ "em",
28
+ "small",
29
+ "strong",
30
+ "mark",
31
+ "u",
32
+ "s",
33
+ "sub",
34
+ "sup",
35
+ "h1",
36
+ "h2",
37
+ "h3",
38
+ "h4",
39
+ "h5",
40
+ "h6",
41
+ "ul",
42
+ "ol",
43
+ "li",
44
+ "dl",
45
+ "dt",
46
+ "dd",
47
+ "table",
48
+ "thead",
49
+ "tbody",
50
+ "tfoot",
51
+ "tr",
52
+ "th",
53
+ "td",
54
+ "caption",
55
+ "colgroup",
56
+ "col",
57
+ "hr",
58
+ "pre",
59
+ "code",
60
+ "blockquote",
61
+ "abbr",
62
+ "ins",
63
+ "del",
64
+ "a",
65
+ "img",
66
+ "figure",
67
+ "figcaption",
68
+ "svg",
69
+ "g",
70
+ "path",
71
+ "circle",
72
+ "ellipse",
73
+ "rect",
74
+ "line",
75
+ "polyline",
76
+ "polygon",
77
+ "text",
78
+ "tspan",
79
+ "textPath",
80
+ "use",
81
+ "defs",
82
+ "symbol",
83
+ "clipPath",
84
+ "mask",
85
+ "linearGradient",
86
+ "radialGradient",
87
+ "stop",
88
+ "pattern",
89
+ "marker",
90
+ "title",
91
+ "desc"
92
+ ]);
93
+ const ALLOWED_ATTRS = /* @__PURE__ */ new Set([
94
+ "class",
95
+ "id",
96
+ "style",
97
+ "title",
98
+ "lang",
99
+ "dir",
100
+ "href",
101
+ "src",
102
+ "alt",
103
+ "width",
104
+ "height",
105
+ "colspan",
106
+ "rowspan",
107
+ "scope",
108
+ "headers",
109
+ "d",
110
+ "points",
111
+ "x",
112
+ "y",
113
+ "x1",
114
+ "x2",
115
+ "y1",
116
+ "y2",
117
+ "cx",
118
+ "cy",
119
+ "r",
120
+ "rx",
121
+ "ry",
122
+ "dx",
123
+ "dy",
124
+ "viewBox",
125
+ "preserveAspectRatio",
126
+ "transform",
127
+ "fill",
128
+ "fill-opacity",
129
+ "fill-rule",
130
+ "stroke",
131
+ "stroke-width",
132
+ "stroke-opacity",
133
+ "stroke-linecap",
134
+ "stroke-linejoin",
135
+ "stroke-dasharray",
136
+ "stroke-dashoffset",
137
+ "opacity",
138
+ "clip-path",
139
+ "clip-rule",
140
+ "mask",
141
+ "font-family",
142
+ "font-size",
143
+ "font-weight",
144
+ "font-style",
145
+ "text-anchor",
146
+ "dominant-baseline",
147
+ "offset",
148
+ "stop-color",
149
+ "stop-opacity",
150
+ "gradientUnits",
151
+ "gradientTransform",
152
+ "spreadMethod",
153
+ "patternUnits",
154
+ "patternTransform",
155
+ "marker-start",
156
+ "marker-mid",
157
+ "marker-end",
158
+ "markerWidth",
159
+ "markerHeight",
160
+ "refX",
161
+ "refY",
162
+ "xlink:href"
94
163
  ]);
95
- // Whitelist of allowed attributes
96
- const ALLOWED_ATTRS = new Set([
97
- // Common attributes
98
- "class",
99
- "id",
100
- "style",
101
- "title",
102
- "lang",
103
- "dir",
104
- // HTML specific
105
- "href",
106
- "src",
107
- "alt",
108
- "width",
109
- "height",
110
- "colspan",
111
- "rowspan",
112
- "scope",
113
- "headers",
114
- // SVG presentation attributes
115
- "d",
116
- "points",
117
- "x",
118
- "y",
119
- "x1",
120
- "x2",
121
- "y1",
122
- "y2",
123
- "cx",
124
- "cy",
125
- "r",
126
- "rx",
127
- "ry",
128
- "dx",
129
- "dy",
130
- "viewBox",
131
- "preserveAspectRatio",
132
- "transform",
133
- "fill",
134
- "fill-opacity",
135
- "fill-rule",
136
- "stroke",
137
- "stroke-width",
138
- "stroke-opacity",
139
- "stroke-linecap",
140
- "stroke-linejoin",
141
- "stroke-dasharray",
142
- "stroke-dashoffset",
143
- "opacity",
144
- "clip-path",
145
- "clip-rule",
146
- "mask",
147
- "font-family",
148
- "font-size",
149
- "font-weight",
150
- "font-style",
151
- "text-anchor",
152
- "dominant-baseline",
153
- "offset",
154
- "stop-color",
155
- "stop-opacity",
156
- "gradientUnits",
157
- "gradientTransform",
158
- "spreadMethod",
159
- "patternUnits",
160
- "patternTransform",
161
- "marker-start",
162
- "marker-mid",
163
- "marker-end",
164
- "markerWidth",
165
- "markerHeight",
166
- "refX",
167
- "refY",
168
- "xlink:href"
164
+ const TAG_CASE_MAP = /* @__PURE__ */ new Map();
165
+ ALLOWED_TAGS.forEach((tag) => TAG_CASE_MAP.set(tag.toLowerCase(), tag));
166
+ const ATTR_CASE_MAP = /* @__PURE__ */ new Map();
167
+ ALLOWED_ATTRS.forEach((attr) => ATTR_CASE_MAP.set(attr.toLowerCase(), attr));
168
+ const ALLOWED_URI_PROTOCOLS = /* @__PURE__ */ new Set([
169
+ "http:",
170
+ "https:",
171
+ "mailto:"
169
172
  ]);
170
- // Case-insensitive lookup maps: lowercase key → canonical casing from whitelists
171
- const TAG_CASE_MAP = new Map();
172
- ALLOWED_TAGS.forEach(tag => TAG_CASE_MAP.set(tag.toLowerCase(), tag));
173
- const ATTR_CASE_MAP = new Map();
174
- ALLOWED_ATTRS.forEach(attr => ATTR_CASE_MAP.set(attr.toLowerCase(), attr));
175
- // Whitelist of allowed URI protocols
176
- const ALLOWED_URI_PROTOCOLS = new Set([
177
- "http:",
178
- "https:",
179
- "mailto:"
173
+ const URI_ATTRS = /* @__PURE__ */ new Set([
174
+ "href",
175
+ "src",
176
+ "xlink:href"
180
177
  ]);
181
- // Attributes that contain URIs
182
- const URI_ATTRS = new Set(["href", "src", "xlink:href"]);
183
- // Pre-compiled regex patterns for performance
184
178
  const TAG_NAME_REGEX = /^<\/?([a-zA-Z][a-zA-Z0-9]*)/;
185
179
  const CLOSING_TAG_REGEX = /^<\/([a-zA-Z][a-zA-Z0-9]*)\s*>$/;
186
180
  const OPENING_TAG_REGEX = /^<([a-zA-Z][a-zA-Z0-9]*)([\s\S]*?)(\/?)>$/;
187
181
  const ATTR_REGEX = /([a-zA-Z][\w:-]*)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/g;
188
182
  const URL_IN_STYLE_REGEX = /url\s*\(\s*["']?([^"')]+)["']?\s*\)/gi;
189
- // Dangerous CSS patterns
190
183
  const DANGEROUS_CSS_PATTERNS = [
191
- "expression(",
192
- "behavior:",
193
- "binding:",
194
- "@import",
195
- "@charset",
196
- "-moz-binding:"
184
+ "expression(",
185
+ "behavior:",
186
+ "binding:",
187
+ "@import",
188
+ "@charset",
189
+ "-moz-binding:"
197
190
  ];
198
191
  /**
199
- * Decode HTML entities in a string
200
- * @param {string} str String with potential HTML entities
201
- * @returns {string} Decoded string
202
- * @private
203
- */
192
+ * Decode HTML entities in a string
193
+ * @param {string} str String with potential HTML entities
194
+ * @returns {string} Decoded string
195
+ * @private
196
+ */
204
197
  function decodeHTMLEntities(str) {
205
- return str
206
- // Named entities
207
- .replace(/&colon;/gi, ":")
208
- .replace(/&newline;/gi, "\n")
209
- .replace(/&tab;/gi, "\t")
210
- .replace(/&nbsp;/gi, " ")
211
- .replace(/&lt;/gi, "<")
212
- .replace(/&gt;/gi, ">")
213
- .replace(/&amp;/gi, "&")
214
- .replace(/&quot;/gi, "\"")
215
- .replace(/&apos;/gi, "'")
216
- // Numeric entities (decimal) - trailing semicolon is optional per HTML5 tokenizer
217
- .replace(/&#(\d+);?/gi, (_, code) => String.fromCharCode(parseInt(code, 10)))
218
- // Numeric entities (hex) - trailing semicolon is optional per HTML5 tokenizer
219
- .replace(/&#x([0-9a-f]+);?/gi, (_, code) => String.fromCharCode(parseInt(code, 16)));
198
+ return str.replace(/&colon;/gi, ":").replace(/&newline;/gi, "\n").replace(/&tab;/gi, " ").replace(/&nbsp;/gi, " ").replace(/&lt;/gi, "<").replace(/&gt;/gi, ">").replace(/&amp;/gi, "&").replace(/&quot;/gi, "\"").replace(/&apos;/gi, "'").replace(/&#(\d+);?/gi, (_, code) => String.fromCharCode(parseInt(code, 10))).replace(/&#x([0-9a-f]+);?/gi, (_, code) => String.fromCharCode(parseInt(code, 16)));
220
199
  }
221
200
  /**
222
- * Check if a URI is safe (whitelist approach)
223
- * @param {string} uri URI to check
224
- * @returns {boolean} Whether the URI is safe
225
- * @private
226
- */
201
+ * Check if a URI is safe (whitelist approach)
202
+ * @param {string} uri URI to check
203
+ * @returns {boolean} Whether the URI is safe
204
+ * @private
205
+ */
227
206
  function isSafeURI(uri) {
228
- // Decode HTML entities first to prevent bypass
229
- const decoded = decodeHTMLEntities(uri).trim();
230
- // Remove any whitespace/control characters that could be used for bypass
231
- // eslint-disable-next-line no-control-regex
232
- const normalized = decoded.replace(/[\s\u0000-\u001f]/g, "").toLowerCase();
233
- // Empty or fragment-only URIs are safe
234
- if (!normalized || normalized.startsWith("#")) {
235
- return true;
236
- }
237
- // A ':' appearing before the first '/', '?' or '#' denotes a URI scheme.
238
- // Reject the value unless that scheme is whitelisted - do NOT infer safety
239
- // merely from the absence of a literal colon (which could be reconstructed
240
- // from an alternate encoding once assigned to innerHTML).
241
- const schemeMatch = normalized.match(/^[^/?#]*:/);
242
- if (schemeMatch) {
243
- return ALLOWED_URI_PROTOCOLS.has(schemeMatch[0]);
244
- }
245
- // No scheme → relative path / query / fragment only → safe
246
- return true;
207
+ const normalized = decodeHTMLEntities(uri).trim().replace(/[\s\u0000-\u001f]/g, "").toLowerCase();
208
+ if (!normalized || normalized.startsWith("#")) return true;
209
+ const schemeMatch = normalized.match(/^[^/?#]*:/);
210
+ if (schemeMatch) return ALLOWED_URI_PROTOCOLS.has(schemeMatch[0]);
211
+ return true;
247
212
  }
248
213
  /**
249
- * Check if a style value is safe (whitelist approach)
250
- * @param {string} style Style attribute value
251
- * @returns {string|null} Sanitized style or null if unsafe
252
- * @private
253
- */
214
+ * Check if a style value is safe (whitelist approach)
215
+ * @param {string} style Style attribute value
216
+ * @returns {string|null} Sanitized style or null if unsafe
217
+ * @private
218
+ */
254
219
  function sanitizeStyleValue(style) {
255
- // Decode HTML entities first
256
- const decoded = decodeHTMLEntities(style);
257
- // Remove any control characters
258
- // eslint-disable-next-line no-control-regex
259
- const cleaned = decoded.replace(/[\u0000-\u001f]/g, "");
260
- // Check for url() - only allow safe URIs inside
261
- URL_IN_STYLE_REGEX.lastIndex = 0;
262
- let match;
263
- while ((match = URL_IN_STYLE_REGEX.exec(cleaned)) !== null) {
264
- if (!isSafeURI(match[1])) {
265
- return null;
266
- }
267
- }
268
- // Check for dangerous CSS patterns (expression, behavior, etc.)
269
- const normalizedLower = cleaned.toLowerCase().replace(/\s/g, "");
270
- for (const pattern of DANGEROUS_CSS_PATTERNS) {
271
- if (normalizedLower.includes(pattern)) {
272
- return null;
273
- }
274
- }
275
- return style;
220
+ const cleaned = decodeHTMLEntities(style).replace(/[\u0000-\u001f]/g, "");
221
+ URL_IN_STYLE_REGEX.lastIndex = 0;
222
+ let match;
223
+ while ((match = URL_IN_STYLE_REGEX.exec(cleaned)) !== null) if (!isSafeURI(match[1])) return null;
224
+ const normalizedLower = cleaned.toLowerCase().replace(/\s/g, "");
225
+ for (const pattern of DANGEROUS_CSS_PATTERNS) if (normalizedLower.includes(pattern)) return null;
226
+ return style;
276
227
  }
277
- // Lookup table for encoding dangerous characters in attribute values
278
228
  const ATTR_ENCODE_MAP = {
279
- "\"": "&quot;",
280
- "'": "&#39;",
281
- "`": "&#96;"
229
+ "\"": "&quot;",
230
+ "'": "&#39;",
231
+ "`": "&#96;"
282
232
  };
283
233
  const ATTR_ENCODE_REGEX = /["'`]/g;
284
234
  /**
285
- * Encode dangerous characters in attribute values to HTML entities
286
- * This prevents attribute injection attacks where quotes/backticks break out of the attribute context
287
- * @param {string} value Attribute value
288
- * @returns {string} Encoded value
289
- * @private
290
- */
235
+ * Encode dangerous characters in attribute values to HTML entities
236
+ * This prevents attribute injection attacks where quotes/backticks break out of the attribute context
237
+ * @param {string} value Attribute value
238
+ * @returns {string} Encoded value
239
+ * @private
240
+ */
291
241
  function encodeAttrValue(value) {
292
- return value.replace(ATTR_ENCODE_REGEX, char => ATTR_ENCODE_MAP[char]);
242
+ return value.replace(ATTR_ENCODE_REGEX, (char) => ATTR_ENCODE_MAP[char]);
293
243
  }
294
244
  /**
295
- * Sanitize attribute value using whitelist approach
296
- * @param {string} name Attribute name
297
- * @param {string} value Attribute value
298
- * @param {boolean} wasUnquoted Whether the value was originally unquoted
299
- * @returns {string|null} Sanitized value if safe, null if should be removed
300
- * @private
301
- */
245
+ * Sanitize attribute value using whitelist approach
246
+ * @param {string} name Attribute name
247
+ * @param {string} value Attribute value
248
+ * @param {boolean} wasUnquoted Whether the value was originally unquoted
249
+ * @returns {string|null} Sanitized value if safe, null if should be removed
250
+ * @private
251
+ */
302
252
  function sanitizeAttrValue(name, value, wasUnquoted = false) {
303
- // Check URI attributes with whitelist
304
- if (URI_ATTRS.has(name)) {
305
- if (!isSafeURI(value)) {
306
- return null;
307
- }
308
- // Encode dangerous characters in URI values to prevent attribute injection
309
- return wasUnquoted ? encodeAttrValue(value) : value;
310
- }
311
- // Check style attribute
312
- if (name === "style") {
313
- const sanitizedStyle = sanitizeStyleValue(value);
314
- if (sanitizedStyle === null) {
315
- return null;
316
- }
317
- // Encode dangerous characters in style values
318
- return wasUnquoted ? encodeAttrValue(sanitizedStyle) : sanitizedStyle;
319
- }
320
- // For other attributes, check for embedded event handlers
321
- const decoded = decodeHTMLEntities(value).toLowerCase().replace(/\s/g, "");
322
- if (/\bon\w+=/.test(decoded)) {
323
- return null;
324
- }
325
- // Encode dangerous characters to prevent attribute injection
326
- return wasUnquoted ? encodeAttrValue(value) : value;
253
+ if (URI_ATTRS.has(name)) {
254
+ if (!isSafeURI(value)) return null;
255
+ return wasUnquoted ? encodeAttrValue(value) : value;
256
+ }
257
+ if (name === "style") {
258
+ const sanitizedStyle = sanitizeStyleValue(value);
259
+ if (sanitizedStyle === null) return null;
260
+ return wasUnquoted ? encodeAttrValue(sanitizedStyle) : sanitizedStyle;
261
+ }
262
+ const decoded = decodeHTMLEntities(value).toLowerCase().replace(/\s/g, "");
263
+ if (/\bon\w+=/.test(decoded)) return null;
264
+ return wasUnquoted ? encodeAttrValue(value) : value;
327
265
  }
328
266
  /**
329
- * Extract tag name from a tag string
330
- * Returns null if not a valid tag format
331
- * @param {string} tag Tag string starting with <
332
- * @returns {string|null} Lowercase tag name or null
333
- * @private
334
- */
267
+ * Extract tag name from a tag string
268
+ * Returns null if not a valid tag format
269
+ * @param {string} tag Tag string starting with <
270
+ * @returns {string|null} Lowercase tag name or null
271
+ * @private
272
+ */
335
273
  function extractTagName(tag) {
336
- // Must start with < followed immediately by letter (no spaces allowed)
337
- const match = tag.match(TAG_NAME_REGEX);
338
- return match ? match[1].toLowerCase() : null;
274
+ const match = tag.match(TAG_NAME_REGEX);
275
+ return match ? match[1].toLowerCase() : null;
339
276
  }
340
277
  /**
341
- * Check if a tag is in the whitelist
342
- * @param {string} tag Tag string
343
- * @returns {boolean} Whether tag is allowed
344
- * @private
345
- */
278
+ * Check if a tag is in the whitelist
279
+ * @param {string} tag Tag string
280
+ * @returns {boolean} Whether tag is allowed
281
+ * @private
282
+ */
346
283
  function isAllowedTag(tag) {
347
- const tagName = extractTagName(tag);
348
- return tagName !== null && TAG_CASE_MAP.has(tagName);
284
+ const tagName = extractTagName(tag);
285
+ return tagName !== null && TAG_CASE_MAP.has(tagName);
349
286
  }
350
287
  /**
351
- * Sanitize a single HTML/SVG tag (only called for allowed tags)
352
- * @param {string} fullTag The full tag string including < and >
353
- * @returns {string} Sanitized tag
354
- * @private
355
- */
288
+ * Sanitize a single HTML/SVG tag (only called for allowed tags)
289
+ * @param {string} fullTag The full tag string including < and >
290
+ * @returns {string} Sanitized tag
291
+ * @private
292
+ */
356
293
  function sanitizeTag(fullTag) {
357
- // Closing tag
358
- const closingMatch = fullTag.match(CLOSING_TAG_REGEX);
359
- if (closingMatch) {
360
- const lowerName = closingMatch[1].toLowerCase();
361
- return `</${TAG_CASE_MAP.get(lowerName) ?? lowerName}>`;
362
- }
363
- // Opening tag
364
- const openingMatch = fullTag.match(OPENING_TAG_REGEX);
365
- if (!openingMatch) {
366
- return "";
367
- }
368
- const [, tagName, attrString, selfClose] = openingMatch;
369
- const lowerTagName = tagName.toLowerCase();
370
- const canonicalTagName = TAG_CASE_MAP.get(lowerTagName) ?? lowerTagName;
371
- // Parse and filter attributes, preserving original quote style
372
- const allowedAttrs = [];
373
- ATTR_REGEX.lastIndex = 0;
374
- let attrMatch;
375
- while ((attrMatch = ATTR_REGEX.exec(attrString)) !== null) {
376
- const lowerAttrName = attrMatch[1].toLowerCase();
377
- const doubleQuotedValue = attrMatch[2];
378
- const singleQuotedValue = attrMatch[3];
379
- const unquotedValue = attrMatch[4];
380
- // Skip event handlers (on*)
381
- if (lowerAttrName.startsWith("on")) {
382
- continue;
383
- }
384
- const canonicalAttrName = ATTR_CASE_MAP.get(lowerAttrName) ?? lowerAttrName;
385
- // Determine original quote style and value
386
- let attrValue;
387
- let quoteChar;
388
- if (doubleQuotedValue !== undefined) {
389
- attrValue = doubleQuotedValue;
390
- quoteChar = "\"";
391
- }
392
- else if (singleQuotedValue !== undefined) {
393
- attrValue = singleQuotedValue;
394
- quoteChar = "'";
395
- }
396
- else if (unquotedValue !== undefined) {
397
- attrValue = unquotedValue;
398
- quoteChar = "\"";
399
- }
400
- else {
401
- // Boolean attribute (no value)
402
- if (ATTR_CASE_MAP.has(lowerAttrName)) {
403
- allowedAttrs.push(canonicalAttrName);
404
- }
405
- continue;
406
- }
407
- if (ATTR_CASE_MAP.has(lowerAttrName)) {
408
- const wasUnquoted = unquotedValue !== undefined;
409
- const sanitizedValue = sanitizeAttrValue(lowerAttrName, attrValue, wasUnquoted);
410
- if (sanitizedValue !== null) {
411
- allowedAttrs.push(`${canonicalAttrName}=${quoteChar}${sanitizedValue}${quoteChar}`);
412
- }
413
- }
414
- }
415
- const attrsStr = allowedAttrs.length > 0 ? ` ${allowedAttrs.join(" ")}` : "";
416
- const selfCloseStr = selfClose ? "/>" : ">";
417
- return `<${canonicalTagName}${attrsStr}${selfCloseStr}`;
294
+ const closingMatch = fullTag.match(CLOSING_TAG_REGEX);
295
+ if (closingMatch) {
296
+ const lowerName = closingMatch[1].toLowerCase();
297
+ return `</${TAG_CASE_MAP.get(lowerName) ?? lowerName}>`;
298
+ }
299
+ const openingMatch = fullTag.match(OPENING_TAG_REGEX);
300
+ if (!openingMatch) return "";
301
+ const [, tagName, attrString, selfClose] = openingMatch;
302
+ const lowerTagName = tagName.toLowerCase();
303
+ const canonicalTagName = TAG_CASE_MAP.get(lowerTagName) ?? lowerTagName;
304
+ const allowedAttrs = [];
305
+ ATTR_REGEX.lastIndex = 0;
306
+ let attrMatch;
307
+ while ((attrMatch = ATTR_REGEX.exec(attrString)) !== null) {
308
+ const lowerAttrName = attrMatch[1].toLowerCase();
309
+ const doubleQuotedValue = attrMatch[2];
310
+ const singleQuotedValue = attrMatch[3];
311
+ const unquotedValue = attrMatch[4];
312
+ if (lowerAttrName.startsWith("on")) continue;
313
+ const canonicalAttrName = ATTR_CASE_MAP.get(lowerAttrName) ?? lowerAttrName;
314
+ let attrValue;
315
+ let quoteChar;
316
+ if (doubleQuotedValue !== void 0) {
317
+ attrValue = doubleQuotedValue;
318
+ quoteChar = "\"";
319
+ } else if (singleQuotedValue !== void 0) {
320
+ attrValue = singleQuotedValue;
321
+ quoteChar = "'";
322
+ } else if (unquotedValue !== void 0) {
323
+ attrValue = unquotedValue;
324
+ quoteChar = "\"";
325
+ } else {
326
+ if (ATTR_CASE_MAP.has(lowerAttrName)) allowedAttrs.push(canonicalAttrName);
327
+ continue;
328
+ }
329
+ if (ATTR_CASE_MAP.has(lowerAttrName)) {
330
+ const sanitizedValue = sanitizeAttrValue(lowerAttrName, attrValue, unquotedValue !== void 0);
331
+ if (sanitizedValue !== null) allowedAttrs.push(`${canonicalAttrName}=${quoteChar}${sanitizedValue}${quoteChar}`);
332
+ }
333
+ }
334
+ return `<${canonicalTagName}${allowedAttrs.length > 0 ? ` ${allowedAttrs.join(" ")}` : ""}${selfClose ? "/>" : ">"}`;
418
335
  }
419
336
  /**
420
- * Sanitize HTML string to prevent XSS attacks
421
- * Pure whitelist approach - allowed tags are sanitized, others are escaped
422
- * @param {string} str Target string value
423
- * @returns {string} Sanitized string with only allowed elements
424
- * @private
425
- */
337
+ * Sanitize HTML string to prevent XSS attacks
338
+ * Pure whitelist approach - allowed tags are sanitized, others are escaped
339
+ * @param {string} str Target string value
340
+ * @returns {string} Sanitized string with only allowed elements
341
+ * @private
342
+ */
426
343
  function sanitize(str) {
427
- if (typeof str !== "string" || !str || str.indexOf("<") === -1) {
428
- return str;
429
- }
430
- // Single pass: sanitize allowed tags, escape disallowed ones
431
- // Also match orphaned fragments like "ipt>" from broken tags
432
- return str.replace(/<\/?[^>]*>|[^<>\s]+>/g, match => {
433
- // Remove HTML comments
434
- if (match.startsWith("<!--")) {
435
- return "";
436
- }
437
- // Orphaned fragment (e.g., "ipt>") → escape '>'
438
- if (!match.startsWith("<")) {
439
- return match.slice(0, -1) + "&gt;";
440
- }
441
- // Allowed tag → sanitize attributes
442
- if (isAllowedTag(match)) {
443
- return sanitizeTag(match);
444
- }
445
- // Disallowed tag → escape all '<' to prevent execution
446
- return match.replace(/</g, "&lt;");
447
- });
344
+ if (typeof str !== "string" || !str || str.indexOf("<") === -1) return str;
345
+ return str.replace(/<\/?[^>]*>|[^<>\s]+>/g, (match) => {
346
+ if (match.startsWith("<!--")) return "";
347
+ if (!match.startsWith("<")) return match.slice(0, -1) + "&gt;";
348
+ if (isAllowedTag(match)) return sanitizeTag(match);
349
+ return match.replace(/</g, "&lt;");
350
+ });
448
351
  }
449
-
352
+ //#endregion
450
353
  export { sanitize };