@ds-mo/ui 2.9.0 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/.build-stamp +1 -1
  2. package/dist/components/ds-badge.js +1 -1
  3. package/dist/components/ds-bar-nav.js +1 -1
  4. package/dist/components/ds-button-filled.js +1 -1
  5. package/dist/components/ds-button-unfilled-icon.js +1 -1
  6. package/dist/components/ds-card-setting.js +1 -1
  7. package/dist/components/ds-fade.js +1 -1
  8. package/dist/components/ds-icon.js +1 -1
  9. package/dist/components/ds-panel-nav.js +1 -1
  10. package/dist/components/ds-panel-tools.js +1 -1
  11. package/dist/components/ds-tab-group-nav.js +1 -1
  12. package/dist/components/ds-tab-group.js +1 -1
  13. package/dist/components/{p-g6MCxfm4.js → p-BFPfyJ8Z.js} +1 -1
  14. package/dist/components/p-BFPfyJ8Z.js.map +1 -0
  15. package/dist/components/{p-CiEc8Nwx.js → p-BOpHKDOG.js} +2 -2
  16. package/dist/components/p-BOpHKDOG.js.map +1 -0
  17. package/dist/components/p-Cynjsv-P.js +2 -0
  18. package/dist/components/p-Cynjsv-P.js.map +1 -0
  19. package/dist/components/{p-C_hgdYcC.js → p-Dul5eGGE.js} +2 -2
  20. package/dist/components/{p-BA6a6P0b.js → p-evjnuLjj.js} +2 -2
  21. package/dist/components/{p-Cv5NDZug.js → p-w2Wrf0jC.js} +2 -2
  22. package/dist/types/components/Badge/Badge.d.ts +5 -1
  23. package/dist/types/components/Icon/Icon.d.ts +14 -1
  24. package/dist/types/components/Icon/flag-icon-catalog.d.ts +2 -1
  25. package/dist/types/components/Icon/icon-cache.d.ts +25 -0
  26. package/dist/types/components/Icon/icon-svg.d.ts +26 -0
  27. package/dist/types/components/Icon/system-icon-catalog.d.ts +2 -1
  28. package/dist/types/components.d.ts +2 -2
  29. package/dist/types/utils/index.d.ts +1 -0
  30. package/package.json +2 -2
  31. package/src/wc/components/Badge/Badge.tsx +6 -2
  32. package/src/wc/components/Icon/Icon.tsx +82 -22
  33. package/src/wc/components/Icon/flag-icon-catalog.ts +33 -65
  34. package/src/wc/components/Icon/icon-cache.ts +47 -0
  35. package/src/wc/components/Icon/icon-svg.ts +73 -0
  36. package/src/wc/components/Icon/system-icon-catalog.ts +398 -795
  37. package/src/wc/components.d.ts +2 -2
  38. package/src/wc/nav/badge-gradient-ring.ts +4 -1
  39. package/src/wc/utils/index.ts +1 -0
  40. package/dist/components/p-CF4avTQw.js +0 -2
  41. package/dist/components/p-CF4avTQw.js.map +0 -1
  42. package/dist/components/p-CiEc8Nwx.js.map +0 -1
  43. package/dist/components/p-g6MCxfm4.js.map +0 -1
  44. /package/dist/components/{p-C_hgdYcC.js.map → p-Dul5eGGE.js.map} +0 -0
  45. /package/dist/components/{p-BA6a6P0b.js.map → p-evjnuLjj.js.map} +0 -0
  46. /package/dist/components/{p-Cv5NDZug.js.map → p-w2Wrf0jC.js.map} +0 -0
@@ -1,2 +1,3 @@
1
- export declare const flagIconCatalog: Record<string, string>;
1
+ /** Auto-generated by scripts/generate-icon-catalog.mjs do not edit. */
2
+ export declare const flagIconLoaders: Record<string, () => Promise<string>>;
2
3
  //# sourceMappingURL=flag-icon-catalog.d.ts.map
@@ -0,0 +1,25 @@
1
+ type IconCacheMap = Map<string, string>;
2
+ export declare function iconCacheKey(name: string, flag: boolean): string;
3
+ export declare function iconCache(): IconCacheMap;
4
+ /**
5
+ * Pre-register glyphs so ds-icon renders them synchronously — no lazy-chunk
6
+ * fetch, no first-paint pop-in. Import the SVG strings from `@ds-mo/icons`
7
+ * in the app (statically, so they ship in the app's own bundle):
8
+ *
9
+ * ```ts
10
+ * import { Bell } from '@ds-mo/icons/svg/Bell';
11
+ * import { US } from '@ds-mo/icons/svg/flags/US';
12
+ * import { registerIcons } from '@ds-mo/ui/utils';
13
+ *
14
+ * registerIcons({ Bell });
15
+ * registerIcons({ US }, { flag: true });
16
+ * ```
17
+ *
18
+ * Icons that are not registered still work — they lazy-load on first render
19
+ * and stay cached afterwards.
20
+ */
21
+ export declare function registerIcons(icons: Record<string, string>, options?: {
22
+ flag?: boolean;
23
+ }): void;
24
+ export {};
25
+ //# sourceMappingURL=icon-cache.d.ts.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Glyph markup validation + Trusted-Types-safe parsing for ds-icon.
3
+ *
4
+ * Glyphs normally come from the trusted @ds-mo/icons build pipeline, but
5
+ * `registerIcons` accepts arbitrary app-provided strings and injection is a
6
+ * sink — so every glyph is validated at the render boundary. Injection uses
7
+ * parsed DOM nodes (never innerHTML), which keeps ds-icon working under a
8
+ * strict CSP with `require-trusted-types-for 'script'`.
9
+ */
10
+ /** Structural view of an element so the walk is unit-testable without a DOM. */
11
+ export interface IconSvgElementLike {
12
+ localName: string;
13
+ getAttributeNames(): string[];
14
+ getAttribute(name: string): string | null;
15
+ children: ArrayLike<IconSvgElementLike>;
16
+ }
17
+ /** True when `root` is an `<svg>` whose whole tree passes validation. */
18
+ export declare function isValidIconSvgRoot(root: IconSvgElementLike | null): boolean;
19
+ /**
20
+ * Parse + validate glyph markup. Returns a detached `<svg>` element ready to
21
+ * append (appending adopts it into the document), or `null` when the markup
22
+ * is not well-formed XML, not rooted at `<svg>`, or fails validation —
23
+ * ds-icon renders an empty fixed-size box in that case.
24
+ */
25
+ export declare function parseIconSvg(svg: string): SVGElement | null;
26
+ //# sourceMappingURL=icon-svg.d.ts.map
@@ -1,2 +1,3 @@
1
- export declare const systemIconCatalog: Record<string, string>;
1
+ /** Auto-generated by scripts/generate-icon-catalog.mjs do not edit. */
2
+ export declare const systemIconLoaders: Record<string, () => Promise<string>>;
2
3
  //# sourceMappingURL=system-icon-catalog.d.ts.map
@@ -135,7 +135,7 @@ export namespace Components {
135
135
  */
136
136
  "count": number;
137
137
  /**
138
- * Ring samples the shell gradient stack (base fill + wash) instead of a flat `box-shadow`. Auto-enabled in `componentDidLoad` under `ds-app-shell[gradient]`; set `on-gradient-background` to opt in/out explicitly.
138
+ * Ring samples the shell gradient stack (base fill + wash) instead of a flat `box-shadow`. Auto-enabled in `componentDidLoad` under `ds-app-shell[gradient]`; set `gradient-background` to opt in/out explicitly. The attribute must NOT start with `on` — Stencil's setAccessor routes any unknown `on*` member down the event-listener path during attribute reflection, calling addEventListener with a non-listener and throwing.
139
139
  * @default false
140
140
  */
141
141
  "gradientBackground": boolean;
@@ -1800,7 +1800,7 @@ declare namespace LocalJSX {
1800
1800
  */
1801
1801
  "count"?: number;
1802
1802
  /**
1803
- * Ring samples the shell gradient stack (base fill + wash) instead of a flat `box-shadow`. Auto-enabled in `componentDidLoad` under `ds-app-shell[gradient]`; set `on-gradient-background` to opt in/out explicitly.
1803
+ * Ring samples the shell gradient stack (base fill + wash) instead of a flat `box-shadow`. Auto-enabled in `componentDidLoad` under `ds-app-shell[gradient]`; set `gradient-background` to opt in/out explicitly. The attribute must NOT start with `on` — Stencil's setAccessor routes any unknown `on*` member down the event-listener path during attribute reflection, calling addEventListener with a non-listener and throwing.
1804
1804
  * @default false
1805
1805
  */
1806
1806
  "gradientBackground"?: boolean;
@@ -1,3 +1,4 @@
1
+ export { registerIcons } from '../components/Icon/icon-cache';
1
2
  export { clearCssLengthPxCache, resolveCssLengthPx } from './resolve-css-length-px';
2
3
  export { parseCssTimeMs, resolveCssTimeMs } from './resolve-css-time-ms';
3
4
  export { SCROLL_EDGE_FADE_DEFAULT_SIZE, SCROLL_EDGE_FADE_SIZE_VAR, scrollEdgeFadeMaskImage, scrollEdgeFadeMaskStyle, } from './scroll-edge-fade';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ds-mo/ui",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "description": "CompoMo — composable web components styled with TokoMo design tokens",
5
5
  "keywords": [
6
6
  "web-components",
@@ -69,7 +69,7 @@
69
69
  "pretest": "node scripts/generate-icon-catalog.mjs",
70
70
  "build": "stencil build && node scripts/patch-index-types.mjs && node scripts/patch-components-d-exports.mjs && node scripts/verify-icons-externalized.mjs && node scripts/write-build-stamp.mjs",
71
71
  "verify:pack": "node scripts/verify-npm-pack.mjs && node scripts/verify-nav-import.mjs",
72
- "test": "node --import tsx/esm --test tests/panel-nav-utils.test.ts tests/panel-tools.test.ts tests/shell-shortcuts.test.ts tests/shell-gradient-presets.test.ts tests/shell-view-transition.test.ts tests/shell-gradient.test.ts tests/shell-chrome-metrics.test.ts tests/shell-chrome-layer.test.ts tests/chrome-transition.test.ts tests/bar-nav-overflow-hysteresis.test.ts tests/badge-gradient-ring.test.ts tests/scroll-edge-fade.test.ts tests/resolve-css-length-px.test.ts tests/resolve-css-time-ms.test.ts tests/overlay-positioning.test.ts tests/menu-position.test.ts tests/menu-placement.test.ts tests/bar-nav-utils.test.ts tests/bar-nav-tabs-menu-utils.test.ts tests/bar-nav-dom-utils.test.ts tests/icon-catalog.test.ts",
72
+ "test": "node --import tsx/esm --test tests/panel-nav-utils.test.ts tests/panel-tools.test.ts tests/shell-shortcuts.test.ts tests/shell-gradient-presets.test.ts tests/shell-view-transition.test.ts tests/shell-gradient.test.ts tests/shell-chrome-metrics.test.ts tests/shell-chrome-layer.test.ts tests/chrome-transition.test.ts tests/bar-nav-overflow-hysteresis.test.ts tests/badge-gradient-ring.test.ts tests/scroll-edge-fade.test.ts tests/resolve-css-length-px.test.ts tests/resolve-css-time-ms.test.ts tests/overlay-positioning.test.ts tests/menu-position.test.ts tests/menu-placement.test.ts tests/bar-nav-utils.test.ts tests/bar-nav-tabs-menu-utils.test.ts tests/bar-nav-dom-utils.test.ts tests/icon-catalog.test.ts tests/icon-cache.test.ts tests/icon-svg.test.ts",
73
73
  "test:e2e": "npm run build && playwright test",
74
74
  "test:e2e:install": "playwright install chromium",
75
75
  "build:docs": "stencil build --docs",
@@ -52,9 +52,13 @@ export class Badge {
52
52
  /**
53
53
  * Ring samples the shell gradient stack (base fill + wash) instead of a flat
54
54
  * `box-shadow`. Auto-enabled in `componentDidLoad` under `ds-app-shell[gradient]`;
55
- * set `on-gradient-background` to opt in/out explicitly.
55
+ * set `gradient-background` to opt in/out explicitly.
56
+ *
57
+ * The attribute must NOT start with `on` — Stencil's setAccessor routes any
58
+ * unknown `on*` member down the event-listener path during attribute
59
+ * reflection, calling addEventListener with a non-listener and throwing.
56
60
  */
57
- @Prop({ attribute: 'on-gradient-background', reflect: true }) gradientBackground: boolean = false;
61
+ @Prop({ attribute: 'gradient-background', reflect: true }) gradientBackground: boolean = false;
58
62
 
59
63
  /** Deprecated alias for selected counter styling. Prefer context-specific color in the parent. */
60
64
  @Prop() isSelected: boolean = false;
@@ -1,6 +1,8 @@
1
- import { Component, Prop, Element, Watch, h, Host } from '@stencil/core';
2
- import { flagIconCatalog } from './flag-icon-catalog';
3
- import { systemIconCatalog } from './system-icon-catalog';
1
+ import { Component, Prop, Element, State, Watch, h, Host } from '@stencil/core';
2
+ import { flagIconLoaders } from './flag-icon-catalog';
3
+ import { systemIconLoaders } from './system-icon-catalog';
4
+ import { iconCache, iconCacheKey } from './icon-cache';
5
+ import { parseIconSvg } from './icon-svg';
4
6
 
5
7
  export type IconSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl';
6
8
 
@@ -47,36 +49,94 @@ export class Icon {
47
49
  /** Set `true` to look up from the flag icon set instead of the system icon set. */
48
50
  @Prop() flag: boolean = false;
49
51
 
50
- private get svgString(): string {
51
- const source = this.flag ? flagIconCatalog : systemIconCatalog;
52
- return source[this.name] ?? '';
52
+ /** Resolved SVG markup — set synchronously on cache hit, async after a lazy load. */
53
+ @State() private svg: string = '';
54
+
55
+ /** Guards against out-of-order async resolutions when `name`/`flag` change quickly. */
56
+ private loadToken = 0;
57
+
58
+ /**
59
+ * Cache hit → render synchronously (pre-registered via `registerIcons` or
60
+ * previously loaded). Miss → fire the per-icon lazy loader; the glyph pops in
61
+ * when the (tiny, per-icon) chunk resolves and stays cached for every other
62
+ * ds-icon instance.
63
+ */
64
+ private resolveSvg() {
65
+ const flag = this.flag;
66
+ const key = iconCacheKey(this.name, flag);
67
+ const token = ++this.loadToken;
68
+
69
+ const cached = iconCache().get(key);
70
+ if (cached !== undefined) {
71
+ this.svg = cached;
72
+ return;
73
+ }
74
+
75
+ // Own-key lookup only: names resolve by exact canonical IcoMo export key —
76
+ // never meta.json aliases (not in the maps) and never inherited prototype
77
+ // keys ('constructor', 'toString', …) that a bare index access would hit.
78
+ const loaders = flag ? flagIconLoaders : systemIconLoaders;
79
+ const loader = Object.prototype.hasOwnProperty.call(loaders, this.name)
80
+ ? loaders[this.name]
81
+ : undefined;
82
+ if (!loader) {
83
+ this.svg = '';
84
+ return;
85
+ }
86
+
87
+ loader()
88
+ .then(svg => {
89
+ iconCache().set(key, svg);
90
+ if (token === this.loadToken) this.svg = svg;
91
+ })
92
+ .catch(() => {
93
+ if (token === this.loadToken) this.svg = '';
94
+ });
53
95
  }
54
96
 
97
+ componentWillLoad() {
98
+ // Fire-and-forget: do not return the promise — a cache miss must not block
99
+ // the parent render tree on a network fetch.
100
+ this.resolveSvg();
101
+ }
102
+
103
+ /** Last markup injected into the DOM — skips redundant re-parse on unrelated re-renders. */
104
+ private renderedSvg: string | null = null;
105
+
55
106
  private updateSvg() {
56
107
  const container = this.el.querySelector<HTMLElement>('.icon__svg');
57
108
  if (!container) return;
58
- container.innerHTML = this.svgString;
59
- // Stencil's scoped CSS cannot reach innerHTML-injected elements (no sc-* class).
60
- // Apply width/height as inline styles so sizing works regardless of scope class.
61
- const svg = container.querySelector<SVGElement>('svg');
62
- if (svg) {
63
- svg.removeAttribute('width');
64
- svg.removeAttribute('height');
65
- // Prevent SVG from being natively focusable (Firefox/IE default) while
66
- // sitting inside an aria-hidden parent — fixes aria-hidden-focus violation.
67
- svg.setAttribute('focusable', 'false');
68
- svg.setAttribute('aria-hidden', 'true');
69
- svg.style.display = 'block';
70
- svg.style.flexShrink = '0';
71
- svg.style.width = '100%';
72
- svg.style.height = '100%';
109
+ if (this.svg === this.renderedSvg) return;
110
+ this.renderedSvg = this.svg;
111
+
112
+ // Validate + inject as parsed DOM nodes — never innerHTML. Keeps ds-icon
113
+ // Trusted-Types compatible and rejects executable/foreign content in
114
+ // glyph strings (registerIcons accepts app-provided markup).
115
+ const svg = this.svg ? parseIconSvg(this.svg) : null;
116
+ if (!svg) {
117
+ container.replaceChildren();
118
+ return;
73
119
  }
120
+
121
+ // Stencil's scoped CSS cannot reach injected elements (no sc-* class).
122
+ // Apply width/height as inline styles so sizing works regardless of scope class.
123
+ svg.removeAttribute('width');
124
+ svg.removeAttribute('height');
125
+ // Prevent SVG from being natively focusable (Firefox/IE default) while
126
+ // sitting inside an aria-hidden parent — fixes aria-hidden-focus violation.
127
+ svg.setAttribute('focusable', 'false');
128
+ svg.setAttribute('aria-hidden', 'true');
129
+ svg.style.display = 'block';
130
+ svg.style.flexShrink = '0';
131
+ svg.style.width = '100%';
132
+ svg.style.height = '100%';
133
+ container.replaceChildren(svg);
74
134
  }
75
135
 
76
136
  @Watch('name')
77
137
  @Watch('flag')
78
138
  onIconChange() {
79
- this.updateSvg();
139
+ this.resolveSvg();
80
140
  }
81
141
 
82
142
  componentDidRender() {
@@ -1,68 +1,36 @@
1
1
  /** Auto-generated by scripts/generate-icon-catalog.mjs — do not edit. */
2
- import { FlagAustria } from '@ds-mo/icons/svg/flags/FlagAustria';
3
- import { FlagBelgium } from '@ds-mo/icons/svg/flags/FlagBelgium';
4
- import { FlagBulgaria } from '@ds-mo/icons/svg/flags/FlagBulgaria';
5
- import { FlagCanada } from '@ds-mo/icons/svg/flags/FlagCanada';
6
- import { FlagCroatia } from '@ds-mo/icons/svg/flags/FlagCroatia';
7
- import { FlagCyprus } from '@ds-mo/icons/svg/flags/FlagCyprus';
8
- import { FlagCzechRepublic } from '@ds-mo/icons/svg/flags/FlagCzechRepublic';
9
- import { FlagDenmark } from '@ds-mo/icons/svg/flags/FlagDenmark';
10
- import { FlagEU } from '@ds-mo/icons/svg/flags/FlagEU';
11
- import { FlagEstonia } from '@ds-mo/icons/svg/flags/FlagEstonia';
12
- import { FlagFinland } from '@ds-mo/icons/svg/flags/FlagFinland';
13
- import { FlagFrance } from '@ds-mo/icons/svg/flags/FlagFrance';
14
- import { FlagGermany } from '@ds-mo/icons/svg/flags/FlagGermany';
15
- import { FlagGreece } from '@ds-mo/icons/svg/flags/FlagGreece';
16
- import { FlagHungary } from '@ds-mo/icons/svg/flags/FlagHungary';
17
- import { FlagIreland } from '@ds-mo/icons/svg/flags/FlagIreland';
18
- import { FlagItaly } from '@ds-mo/icons/svg/flags/FlagItaly';
19
- import { FlagLatvia } from '@ds-mo/icons/svg/flags/FlagLatvia';
20
- import { FlagLithuania } from '@ds-mo/icons/svg/flags/FlagLithuania';
21
- import { FlagLuxembourg } from '@ds-mo/icons/svg/flags/FlagLuxembourg';
22
- import { FlagMalta } from '@ds-mo/icons/svg/flags/FlagMalta';
23
- import { FlagMexico } from '@ds-mo/icons/svg/flags/FlagMexico';
24
- import { FlagNetherlands } from '@ds-mo/icons/svg/flags/FlagNetherlands';
25
- import { FlagPoland } from '@ds-mo/icons/svg/flags/FlagPoland';
26
- import { FlagPortugal } from '@ds-mo/icons/svg/flags/FlagPortugal';
27
- import { FlagRomania } from '@ds-mo/icons/svg/flags/FlagRomania';
28
- import { FlagSlovakia } from '@ds-mo/icons/svg/flags/FlagSlovakia';
29
- import { FlagSlovenia } from '@ds-mo/icons/svg/flags/FlagSlovenia';
30
- import { FlagSpain } from '@ds-mo/icons/svg/flags/FlagSpain';
31
- import { FlagSweden } from '@ds-mo/icons/svg/flags/FlagSweden';
32
- import { FlagUnitedKingdom } from '@ds-mo/icons/svg/flags/FlagUnitedKingdom';
33
- import { FlagUnitedStates } from '@ds-mo/icons/svg/flags/FlagUnitedStates';
34
2
 
35
- export const flagIconCatalog: Record<string, string> = {
36
- FlagAustria,
37
- FlagBelgium,
38
- FlagBulgaria,
39
- FlagCanada,
40
- FlagCroatia,
41
- FlagCyprus,
42
- FlagCzechRepublic,
43
- FlagDenmark,
44
- FlagEU,
45
- FlagEstonia,
46
- FlagFinland,
47
- FlagFrance,
48
- FlagGermany,
49
- FlagGreece,
50
- FlagHungary,
51
- FlagIreland,
52
- FlagItaly,
53
- FlagLatvia,
54
- FlagLithuania,
55
- FlagLuxembourg,
56
- FlagMalta,
57
- FlagMexico,
58
- FlagNetherlands,
59
- FlagPoland,
60
- FlagPortugal,
61
- FlagRomania,
62
- FlagSlovakia,
63
- FlagSlovenia,
64
- FlagSpain,
65
- FlagSweden,
66
- FlagUnitedKingdom,
67
- FlagUnitedStates,
3
+ export const flagIconLoaders: Record<string, () => Promise<string>> = {
4
+ FlagAustria: () => import('@ds-mo/icons/svg/flags/FlagAustria').then(m => m.FlagAustria),
5
+ FlagBelgium: () => import('@ds-mo/icons/svg/flags/FlagBelgium').then(m => m.FlagBelgium),
6
+ FlagBulgaria: () => import('@ds-mo/icons/svg/flags/FlagBulgaria').then(m => m.FlagBulgaria),
7
+ FlagCanada: () => import('@ds-mo/icons/svg/flags/FlagCanada').then(m => m.FlagCanada),
8
+ FlagCroatia: () => import('@ds-mo/icons/svg/flags/FlagCroatia').then(m => m.FlagCroatia),
9
+ FlagCyprus: () => import('@ds-mo/icons/svg/flags/FlagCyprus').then(m => m.FlagCyprus),
10
+ FlagCzechRepublic: () => import('@ds-mo/icons/svg/flags/FlagCzechRepublic').then(m => m.FlagCzechRepublic),
11
+ FlagDenmark: () => import('@ds-mo/icons/svg/flags/FlagDenmark').then(m => m.FlagDenmark),
12
+ FlagEU: () => import('@ds-mo/icons/svg/flags/FlagEU').then(m => m.FlagEU),
13
+ FlagEstonia: () => import('@ds-mo/icons/svg/flags/FlagEstonia').then(m => m.FlagEstonia),
14
+ FlagFinland: () => import('@ds-mo/icons/svg/flags/FlagFinland').then(m => m.FlagFinland),
15
+ FlagFrance: () => import('@ds-mo/icons/svg/flags/FlagFrance').then(m => m.FlagFrance),
16
+ FlagGermany: () => import('@ds-mo/icons/svg/flags/FlagGermany').then(m => m.FlagGermany),
17
+ FlagGreece: () => import('@ds-mo/icons/svg/flags/FlagGreece').then(m => m.FlagGreece),
18
+ FlagHungary: () => import('@ds-mo/icons/svg/flags/FlagHungary').then(m => m.FlagHungary),
19
+ FlagIreland: () => import('@ds-mo/icons/svg/flags/FlagIreland').then(m => m.FlagIreland),
20
+ FlagItaly: () => import('@ds-mo/icons/svg/flags/FlagItaly').then(m => m.FlagItaly),
21
+ FlagLatvia: () => import('@ds-mo/icons/svg/flags/FlagLatvia').then(m => m.FlagLatvia),
22
+ FlagLithuania: () => import('@ds-mo/icons/svg/flags/FlagLithuania').then(m => m.FlagLithuania),
23
+ FlagLuxembourg: () => import('@ds-mo/icons/svg/flags/FlagLuxembourg').then(m => m.FlagLuxembourg),
24
+ FlagMalta: () => import('@ds-mo/icons/svg/flags/FlagMalta').then(m => m.FlagMalta),
25
+ FlagMexico: () => import('@ds-mo/icons/svg/flags/FlagMexico').then(m => m.FlagMexico),
26
+ FlagNetherlands: () => import('@ds-mo/icons/svg/flags/FlagNetherlands').then(m => m.FlagNetherlands),
27
+ FlagPoland: () => import('@ds-mo/icons/svg/flags/FlagPoland').then(m => m.FlagPoland),
28
+ FlagPortugal: () => import('@ds-mo/icons/svg/flags/FlagPortugal').then(m => m.FlagPortugal),
29
+ FlagRomania: () => import('@ds-mo/icons/svg/flags/FlagRomania').then(m => m.FlagRomania),
30
+ FlagSlovakia: () => import('@ds-mo/icons/svg/flags/FlagSlovakia').then(m => m.FlagSlovakia),
31
+ FlagSlovenia: () => import('@ds-mo/icons/svg/flags/FlagSlovenia').then(m => m.FlagSlovenia),
32
+ FlagSpain: () => import('@ds-mo/icons/svg/flags/FlagSpain').then(m => m.FlagSpain),
33
+ FlagSweden: () => import('@ds-mo/icons/svg/flags/FlagSweden').then(m => m.FlagSweden),
34
+ FlagUnitedKingdom: () => import('@ds-mo/icons/svg/flags/FlagUnitedKingdom').then(m => m.FlagUnitedKingdom),
35
+ FlagUnitedStates: () => import('@ds-mo/icons/svg/flags/FlagUnitedStates').then(m => m.FlagUnitedStates),
68
36
  };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Shared SVG glyph cache for ds-icon.
3
+ *
4
+ * Keyed on a global symbol so every module instance (the compiled Stencil chunk
5
+ * inside dist/components and any direct source import, e.g. via `@ds-mo/ui/utils`)
6
+ * reads and writes the same cache. Without this, `registerIcons` called from an
7
+ * app would fill a different Map than the one ds-icon resolves from.
8
+ */
9
+ const CACHE_KEY = Symbol.for('ds-mo.icon-svg-cache');
10
+
11
+ type IconCacheMap = Map<string, string>;
12
+
13
+ type GlobalWithIconCache = { [CACHE_KEY]?: IconCacheMap };
14
+
15
+ export function iconCacheKey(name: string, flag: boolean): string {
16
+ return flag ? `flag:${name}` : `system:${name}`;
17
+ }
18
+
19
+ export function iconCache(): IconCacheMap {
20
+ const g = globalThis as GlobalWithIconCache;
21
+ return (g[CACHE_KEY] ??= new Map());
22
+ }
23
+
24
+ /**
25
+ * Pre-register glyphs so ds-icon renders them synchronously — no lazy-chunk
26
+ * fetch, no first-paint pop-in. Import the SVG strings from `@ds-mo/icons`
27
+ * in the app (statically, so they ship in the app's own bundle):
28
+ *
29
+ * ```ts
30
+ * import { Bell } from '@ds-mo/icons/svg/Bell';
31
+ * import { US } from '@ds-mo/icons/svg/flags/US';
32
+ * import { registerIcons } from '@ds-mo/ui/utils';
33
+ *
34
+ * registerIcons({ Bell });
35
+ * registerIcons({ US }, { flag: true });
36
+ * ```
37
+ *
38
+ * Icons that are not registered still work — they lazy-load on first render
39
+ * and stay cached afterwards.
40
+ */
41
+ export function registerIcons(icons: Record<string, string>, options?: { flag?: boolean }): void {
42
+ const cache = iconCache();
43
+ const flag = options?.flag === true;
44
+ for (const [name, svg] of Object.entries(icons)) {
45
+ cache.set(iconCacheKey(name, flag), svg);
46
+ }
47
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Glyph markup validation + Trusted-Types-safe parsing for ds-icon.
3
+ *
4
+ * Glyphs normally come from the trusted @ds-mo/icons build pipeline, but
5
+ * `registerIcons` accepts arbitrary app-provided strings and injection is a
6
+ * sink — so every glyph is validated at the render boundary. Injection uses
7
+ * parsed DOM nodes (never innerHTML), which keeps ds-icon working under a
8
+ * strict CSP with `require-trusted-types-for 'script'`.
9
+ */
10
+
11
+ /** Structural view of an element so the walk is unit-testable without a DOM. */
12
+ export interface IconSvgElementLike {
13
+ localName: string;
14
+ getAttributeNames(): string[];
15
+ getAttribute(name: string): string | null;
16
+ children: ArrayLike<IconSvgElementLike>;
17
+ }
18
+
19
+ /** Elements that can execute or embed foreign content — never valid in a glyph. */
20
+ const FORBIDDEN_ELEMENTS = new Set([
21
+ 'script',
22
+ 'foreignobject',
23
+ 'iframe',
24
+ 'object',
25
+ 'embed',
26
+ 'animation', // SVG 1.2 external-content element (distinct from animate/animateTransform)
27
+ ]);
28
+
29
+ function isValidIconSvgElement(el: IconSvgElementLike): boolean {
30
+ if (FORBIDDEN_ELEMENTS.has(el.localName.toLowerCase())) return false;
31
+
32
+ for (const attr of el.getAttributeNames()) {
33
+ const lower = attr.toLowerCase();
34
+ // Event handler attributes (onclick, onload, …) — any casing.
35
+ if (lower.startsWith('on')) return false;
36
+ // References must stay internal (#gradient-id); rejects javascript:, data:,
37
+ // and external URLs on <use>, <a>, <image>, …
38
+ if (lower === 'href' || lower === 'xlink:href') {
39
+ const value = el.getAttribute(attr) ?? '';
40
+ if (!value.startsWith('#')) return false;
41
+ }
42
+ }
43
+
44
+ for (let i = 0; i < el.children.length; i++) {
45
+ if (!isValidIconSvgElement(el.children[i])) return false;
46
+ }
47
+
48
+ return true;
49
+ }
50
+
51
+ /** True when `root` is an `<svg>` whose whole tree passes validation. */
52
+ export function isValidIconSvgRoot(root: IconSvgElementLike | null): boolean {
53
+ return root != null && root.localName === 'svg' && isValidIconSvgElement(root);
54
+ }
55
+
56
+ /**
57
+ * Parse + validate glyph markup. Returns a detached `<svg>` element ready to
58
+ * append (appending adopts it into the document), or `null` when the markup
59
+ * is not well-formed XML, not rooted at `<svg>`, or fails validation —
60
+ * ds-icon renders an empty fixed-size box in that case.
61
+ */
62
+ export function parseIconSvg(svg: string): SVGElement | null {
63
+ if (typeof DOMParser === 'undefined') return null;
64
+
65
+ const doc = new DOMParser().parseFromString(svg, 'image/svg+xml');
66
+ // Malformed XML yields a parsererror document (root or nested, per browser).
67
+ if (doc.querySelector('parsererror')) return null;
68
+
69
+ const root = doc.documentElement as unknown as IconSvgElementLike;
70
+ if (!isValidIconSvgRoot(root)) return null;
71
+
72
+ return doc.documentElement as unknown as SVGElement;
73
+ }