@pantoken/utils 0.2.4 → 0.2.5

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.
package/dist/index.d.mts CHANGED
@@ -63,6 +63,13 @@ declare function focusOutlineRules(selector?: string): string;
63
63
  //#region src/index.d.ts
64
64
  /** The colour mode to collapse `light-dark()` to. */
65
65
  type Mode = "light" | "dark";
66
+ /**
67
+ * Strip `<script>` elements and event-handler attributes from SVG markup.
68
+ *
69
+ * Defense-in-depth for SVG decoded from vendored data URIs or contributed by plugins.
70
+ * Not a full HTML parser — relies on the upstream source being trusted and pinned.
71
+ */
72
+ declare function sanitizeSvg(svg: string): string;
66
73
  /** A `var(--custom-prop)` reference (optional fallback); capture group 1 is the property name. */
67
74
  declare const VAR_RE: RegExp;
68
75
  /** A `light-dark(<light>, <dark>)` value; capture groups 1 and 2 are the two branches. */
@@ -304,4 +311,4 @@ interface TokenUtilityGroup {
304
311
  */
305
312
  declare function tokenUtilitiesCss(groups: readonly TokenUtilityGroup[], options?: UtilityOptions): string;
306
313
  //#endregion
307
- export { ColorUtilityNames, ELEVATION_NAMES, FOCUSABLE_SELECTOR, LIGHT_DARK_RE, Mode, ResolveOptions, Rgba, TokenUtilityGroup, UtilityOptions, VAR_RE, camelCase, colorUtilitiesCss, danglingReferences, elevationDeclarations, extractInstuiRefs, focusOutlineDeclarations, focusOutlineRules, makeResolver, parseHexColor, resolveTokens, tokenNames, tokenUtilitiesCss, unknownReferences };
314
+ export { ColorUtilityNames, ELEVATION_NAMES, FOCUSABLE_SELECTOR, LIGHT_DARK_RE, Mode, ResolveOptions, Rgba, TokenUtilityGroup, UtilityOptions, VAR_RE, camelCase, colorUtilitiesCss, danglingReferences, elevationDeclarations, extractInstuiRefs, focusOutlineDeclarations, focusOutlineRules, makeResolver, parseHexColor, resolveTokens, sanitizeSvg, tokenNames, tokenUtilitiesCss, unknownReferences };
package/dist/index.mjs CHANGED
@@ -130,6 +130,25 @@ function focusOutlineRules(selector = FOCUSABLE_SELECTOR) {
130
130
  * @module
131
131
  * @beta
132
132
  */
133
+ /**
134
+ * Strip `<script>` elements and event-handler attributes from SVG markup.
135
+ *
136
+ * Defense-in-depth for SVG decoded from vendored data URIs or contributed by plugins.
137
+ * Not a full HTML parser — relies on the upstream source being trusted and pinned.
138
+ */
139
+ function sanitizeSvg(svg) {
140
+ let sanitized = svg;
141
+ let previous;
142
+ do {
143
+ previous = sanitized;
144
+ sanitized = sanitized.replace(/<script\b[^>]*>[\s\S]*?<\/script\b[^>]*>/gi, "");
145
+ } while (sanitized !== previous);
146
+ do {
147
+ previous = sanitized;
148
+ sanitized = sanitized.replace(/\son\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "");
149
+ } while (sanitized !== previous);
150
+ return sanitized;
151
+ }
133
152
  const VAR_SOURCE = "var\\(\\s*(--[\\w-]+)[^)]*\\)";
134
153
  const LIGHT_DARK_SOURCE = "^light-dark\\(\\s*(.+?)\\s*,\\s*(.+?)\\s*\\)$";
135
154
  /** A `var(--custom-prop)` reference (optional fallback); capture group 1 is the property name. */
@@ -401,4 +420,4 @@ function tokenUtilitiesCss(groups, options = {}) {
401
420
  })).join("\n")}\n`;
402
421
  }
403
422
  //#endregion
404
- export { ELEVATION_NAMES, FOCUSABLE_SELECTOR, LIGHT_DARK_RE, VAR_RE, camelCase, colorUtilitiesCss, danglingReferences, elevationDeclarations, extractInstuiRefs, focusOutlineDeclarations, focusOutlineRules, makeResolver, parseHexColor, resolveTokens, tokenNames, tokenUtilitiesCss, unknownReferences };
423
+ export { ELEVATION_NAMES, FOCUSABLE_SELECTOR, LIGHT_DARK_RE, VAR_RE, camelCase, colorUtilitiesCss, danglingReferences, elevationDeclarations, extractInstuiRefs, focusOutlineDeclarations, focusOutlineRules, makeResolver, parseHexColor, resolveTokens, sanitizeSvg, tokenNames, tokenUtilitiesCss, unknownReferences };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pantoken/utils",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Shared pantoken helpers: token reference resolver, typed regexes (arkregex), name-case, and hex-colour parsing.",
5
5
  "homepage": "https://pantoken.iywahl.com",
6
6
  "bugs": "https://github.com/thedannywahl/pantoken/issues",