@juice-js/icons 3.0.0-alpha.6 → 3.0.0-alpha.8

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.
@@ -3,6 +3,28 @@ import { InjectionToken, makeEnvironmentProviders, input, inject, ElementRef, DO
3
3
 
4
4
  /** Multi token: every `provideJuiceIcons` call contributes one set; later sets win on a name clash. */
5
5
  const JUICE_ICONS = new InjectionToken('JUICE_ICONS');
6
+ /**
7
+ * The icon drawn for a name nobody registered (a module's menu entry may send any Material name). Default: a dashed circle,
8
+ * neutral and clearly a placeholder. `provideJuiceIconFallback(null)` draws nothing instead; a dev-mode warning names the icon either way.
9
+ */
10
+ const JUICE_ICON_FALLBACK = new InjectionToken('JUICE_ICON_FALLBACK', {
11
+ providedIn: 'root',
12
+ // lucide's circle-dashed, inlined so the fallback needs no registration.
13
+ factory: () => [
14
+ ['path', { d: 'M10.1 2.182a10 10 0 0 1 3.8 0' }],
15
+ ['path', { d: 'M13.9 21.818a10 10 0 0 1-3.8 0' }],
16
+ ['path', { d: 'M17.609 3.721a10 10 0 0 1 2.69 2.7' }],
17
+ ['path', { d: 'M2.182 13.9a10 10 0 0 1 0-3.8' }],
18
+ ['path', { d: 'M20.279 17.609a10 10 0 0 1-2.7 2.69' }],
19
+ ['path', { d: 'M21.818 10.1a10 10 0 0 1 0 3.8' }],
20
+ ['path', { d: 'M3.721 6.391a10 10 0 0 1 2.7-2.69' }],
21
+ ['path', { d: 'M6.391 20.279a10 10 0 0 1-2.69-2.7' }],
22
+ ],
23
+ });
24
+ /** Replaces the fallback icon for unregistered names, or turns it off (`null`: draw nothing). */
25
+ function provideJuiceIconFallback(icon) {
26
+ return makeEnvironmentProviders([{ provide: JUICE_ICON_FALLBACK, useValue: icon }]);
27
+ }
6
28
  /**
7
29
  * Registers icons for `<juice-icon>`. Pass only the icons the app uses so the rest tree-shake away:
8
30
  * `provideJuiceIcons({ search: Search, 'chevron-down': ChevronDown })`, with the nodes imported from `lucide`.
@@ -15,7 +37,8 @@ const SVG_NS = 'http://www.w3.org/2000/svg';
15
37
  const warned = new Set();
16
38
  /**
17
39
  * Inline SVG icon drawn from the registered lucide data. It inherits `currentColor`, is `aria-hidden` unless
18
- * `label` is set, and renders nothing for an unknown name (with a dev-mode warning).
40
+ * `label` is set. An unregistered name draws the fallback icon (a dashed circle, JUICE_ICON_FALLBACK), marked
41
+ * `data-icon-fallback`, with a dev-mode warning: a module may send any icon name, and a blank gap reads as a bug.
19
42
  */
20
43
  class JuiceIcon {
21
44
  constructor() {
@@ -31,7 +54,9 @@ class JuiceIcon {
31
54
  this.host = inject(ElementRef).nativeElement;
32
55
  this.doc = inject(DOCUMENT);
33
56
  this.sets = inject(JUICE_ICONS, { optional: true }) ?? [];
34
- this.node = computed(() => {
57
+ this.fallback = inject(JUICE_ICON_FALLBACK);
58
+ /** The registered icon for the name, or undefined. */
59
+ this.registered = computed(() => {
35
60
  const name = this.name();
36
61
  for (let i = this.sets.length - 1; i >= 0; i--) {
37
62
  const set = this.sets[i];
@@ -40,10 +65,14 @@ class JuiceIcon {
40
65
  }
41
66
  if (isDevMode() && !warned.has(name)) {
42
67
  warned.add(name);
43
- console.warn(`[juice-icon] Unknown icon "${name}". Register it with provideJuiceIcons().`);
68
+ console.warn(`[juice-icon] Unknown icon "${name}"; drawing the fallback. Register it with provideJuiceIcons().`);
44
69
  }
45
70
  return undefined;
46
71
  }, /* @ts-ignore */
72
+ ...(ngDevMode ? [{ debugName: "registered" }] : /* istanbul ignore next */ []));
73
+ this.isFallback = computed(() => !this.registered() && !!this.fallback, /* @ts-ignore */
74
+ ...(ngDevMode ? [{ debugName: "isFallback" }] : /* istanbul ignore next */ []));
75
+ this.node = computed(() => this.registered() ?? this.fallback ?? undefined, /* @ts-ignore */
47
76
  ...(ngDevMode ? [{ debugName: "node" }] : /* istanbul ignore next */ []));
48
77
  effect(() => {
49
78
  const node = this.node();
@@ -78,7 +107,7 @@ class JuiceIcon {
78
107
  });
79
108
  }
80
109
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: JuiceIcon, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
81
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.0.6", type: JuiceIcon, isStandalone: true, selector: "juice-icon", inputs: { name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: true, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.role": "label() ? \"img\" : null", "attr.aria-label": "label() || null", "attr.aria-hidden": "label() ? null : \"true\"" } }, ngImport: i0, template: '', isInline: true, styles: ["juice-icon{display:inline-flex;flex:none;align-items:center;justify-content:center;line-height:0;vertical-align:middle}juice-icon>svg{display:block}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
110
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.0.6", type: JuiceIcon, isStandalone: true, selector: "juice-icon", inputs: { name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: true, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.role": "label() ? \"img\" : null", "attr.aria-label": "label() || null", "attr.aria-hidden": "label() ? null : \"true\"", "attr.data-icon-fallback": "isFallback() ? \"\" : null" } }, ngImport: i0, template: '', isInline: true, styles: ["juice-icon{display:inline-flex;flex:none;align-items:center;justify-content:center;line-height:0;vertical-align:middle}juice-icon>svg{display:block}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
82
111
  }
83
112
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: JuiceIcon, decorators: [{
84
113
  type: Component,
@@ -86,6 +115,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
86
115
  '[attr.role]': 'label() ? "img" : null',
87
116
  '[attr.aria-label]': 'label() || null',
88
117
  '[attr.aria-hidden]': 'label() ? null : "true"',
118
+ '[attr.data-icon-fallback]': 'isFallback() ? "" : null',
89
119
  }, styles: ["juice-icon{display:inline-flex;flex:none;align-items:center;justify-content:center;line-height:0;vertical-align:middle}juice-icon>svg{display:block}\n"] }]
90
120
  }], ctorParameters: () => [], propDecorators: { name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: true }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }] } });
91
121
  function setAttrs(el, attrs) {
@@ -100,5 +130,5 @@ function setAttrs(el, attrs) {
100
130
  * Generated bundle index. Do not edit.
101
131
  */
102
132
 
103
- export { JUICE_ICONS, JuiceIcon, provideJuiceIcons };
133
+ export { JUICE_ICONS, JUICE_ICON_FALLBACK, JuiceIcon, provideJuiceIconFallback, provideJuiceIcons };
104
134
  //# sourceMappingURL=juice-js-icons.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"juice-js-icons.mjs","sources":["../../../../projects/juice-js/icons/src/lib/icons.ts","../../../../projects/juice-js/icons/src/lib/icon.component.ts","../../../../projects/juice-js/icons/src/juice-js-icons.ts"],"sourcesContent":["import { EnvironmentProviders, InjectionToken, makeEnvironmentProviders } from '@angular/core';\nimport type { IconNode } from 'lucide';\n\nexport type { IconNode } from 'lucide';\n\n/** A registry of icon data, keyed by the name used in `<juice-icon name>`. */\nexport type JuiceIconSet = Readonly<Record<string, IconNode>>;\n\n/** Multi token: every `provideJuiceIcons` call contributes one set; later sets win on a name clash. */\nexport const JUICE_ICONS = new InjectionToken<JuiceIconSet[]>('JUICE_ICONS');\n\n/**\n * Registers icons for `<juice-icon>`. Pass only the icons the app uses so the rest tree-shake away:\n * `provideJuiceIcons({ search: Search, 'chevron-down': ChevronDown })`, with the nodes imported from `lucide`.\n */\nexport function provideJuiceIcons(icons: Record<string, IconNode>): EnvironmentProviders {\n return makeEnvironmentProviders([{ provide: JUICE_ICONS, useValue: icons, multi: true }]);\n}\n","import {\n ChangeDetectionStrategy,\n Component,\n DOCUMENT,\n ViewEncapsulation,\n computed,\n effect,\n ElementRef,\n inject,\n input,\n isDevMode,\n} from '@angular/core';\nimport { JUICE_ICONS, IconNode } from './icons';\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\nconst warned = new Set<string>();\n\n/**\n * Inline SVG icon drawn from the registered lucide data. It inherits `currentColor`, is `aria-hidden` unless\n * `label` is set, and renders nothing for an unknown name (with a dev-mode warning).\n */\n@Component({\n selector: 'juice-icon',\n template: '',\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n styles: `\n juice-icon {\n display: inline-flex;\n flex: none;\n align-items: center;\n justify-content: center;\n line-height: 0;\n vertical-align: middle;\n }\n juice-icon > svg {\n display: block;\n }\n `,\n host: {\n '[attr.role]': 'label() ? \"img\" : null',\n '[attr.aria-label]': 'label() || null',\n '[attr.aria-hidden]': 'label() ? null : \"true\"',\n },\n})\nexport class JuiceIcon {\n /** Registered icon name. */\n readonly name = input.required<string>();\n /** Edge length in px (or any CSS length string). */\n readonly size = input<number | string>(16);\n /** Accessible name. Without it the icon is decorative. */\n readonly label = input<string>('');\n\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly doc = inject(DOCUMENT);\n private readonly sets = inject(JUICE_ICONS, { optional: true }) ?? [];\n\n private readonly node = computed<IconNode | undefined>(() => {\n const name = this.name();\n for (let i = this.sets.length - 1; i >= 0; i--) {\n const set = this.sets[i];\n if (Object.prototype.hasOwnProperty.call(set, name)) return set[name];\n }\n if (isDevMode() && !warned.has(name)) {\n warned.add(name);\n console.warn(`[juice-icon] Unknown icon \"${name}\". Register it with provideJuiceIcons().`);\n }\n return undefined;\n });\n\n constructor() {\n effect(() => {\n const node = this.node();\n const size = this.size();\n this.host.replaceChildren();\n if (!node) return;\n const length = typeof size === 'number' ? `${size}px` : size;\n const svg = this.doc.createElementNS(SVG_NS, 'svg');\n setAttrs(svg, {\n xmlns: SVG_NS,\n viewBox: '0 0 24 24',\n fill: 'none',\n stroke: 'currentColor',\n 'stroke-width': '2',\n 'stroke-linecap': 'round',\n 'stroke-linejoin': 'round',\n 'aria-hidden': 'true',\n focusable: 'false',\n });\n svg.style.width = length;\n svg.style.height = length;\n for (const [tag, attrs] of node) {\n // lucide data only uses graphic primitives; refuse anything else so a bad icon set cannot inject script.\n if (!/^[a-z]+$/.test(tag) || tag === 'script' || tag === 'foreignObject') continue;\n const child = this.doc.createElementNS(SVG_NS, tag);\n setAttrs(child, attrs as Record<string, unknown>);\n svg.appendChild(child);\n }\n this.host.appendChild(svg);\n });\n }\n}\n\nfunction setAttrs(el: Element, attrs: Record<string, unknown>): void {\n for (const [key, value] of Object.entries(attrs)) {\n if (value == null || /^on/i.test(key) || !/^[A-Za-z][\\w:-]*$/.test(key)) continue;\n el.setAttribute(key, String(value));\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAQA;MACa,WAAW,GAAG,IAAI,cAAc,CAAiB,aAAa;AAE3E;;;AAGG;AACG,SAAU,iBAAiB,CAAC,KAA+B,EAAA;AAC/D,IAAA,OAAO,wBAAwB,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3F;;ACHA,MAAM,MAAM,GAAG,4BAA4B;AAC3C,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU;AAEhC;;;AAGG;MAyBU,SAAS,CAAA;AAyBpB,IAAA,WAAA,GAAA;;QAvBS,IAAA,CA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/icons/src/lib/icon.component.ts","../../../../projects/juice-js/icons/src/juice-js-icons.ts"],"sourcesContent":["import { EnvironmentProviders, InjectionToken, makeEnvironmentProviders } from '@angular/core';\nimport type { IconNode } from 'lucide';\n\nexport type { IconNode } from 'lucide';\n\n/** A registry of icon data, keyed by the name used in `<juice-icon name>`. */\nexport type JuiceIconSet = Readonly<Record<string, IconNode>>;\n\n/** Multi token: every `provideJuiceIcons` call contributes one set; later sets win on a name clash. */\nexport const JUICE_ICONS = new InjectionToken<JuiceIconSet[]>('JUICE_ICONS');\n\n/**\n * The icon drawn for a name nobody registered (a module's menu entry may send any Material name). Default: a dashed circle,\n * neutral and clearly a placeholder. `provideJuiceIconFallback(null)` draws nothing instead; a dev-mode warning names the icon either way.\n */\nexport const JUICE_ICON_FALLBACK = new InjectionToken<IconNode | null>('JUICE_ICON_FALLBACK', {\n providedIn: 'root',\n // lucide's circle-dashed, inlined so the fallback needs no registration.\n factory: () => [\n ['path', { d: 'M10.1 2.182a10 10 0 0 1 3.8 0' }],\n ['path', { d: 'M13.9 21.818a10 10 0 0 1-3.8 0' }],\n ['path', { d: 'M17.609 3.721a10 10 0 0 1 2.69 2.7' }],\n ['path', { d: 'M2.182 13.9a10 10 0 0 1 0-3.8' }],\n ['path', { d: 'M20.279 17.609a10 10 0 0 1-2.7 2.69' }],\n ['path', { d: 'M21.818 10.1a10 10 0 0 1 0 3.8' }],\n ['path', { d: 'M3.721 6.391a10 10 0 0 1 2.7-2.69' }],\n ['path', { d: 'M6.391 20.279a10 10 0 0 1-2.69-2.7' }],\n ] as unknown as IconNode,\n});\n\n/** Replaces the fallback icon for unregistered names, or turns it off (`null`: draw nothing). */\nexport function provideJuiceIconFallback(icon: IconNode | null): EnvironmentProviders {\n return makeEnvironmentProviders([{ provide: JUICE_ICON_FALLBACK, useValue: icon }]);\n}\n\n/**\n * Registers icons for `<juice-icon>`. Pass only the icons the app uses so the rest tree-shake away:\n * `provideJuiceIcons({ search: Search, 'chevron-down': ChevronDown })`, with the nodes imported from `lucide`.\n */\nexport function provideJuiceIcons(icons: Record<string, IconNode>): EnvironmentProviders {\n return makeEnvironmentProviders([{ provide: JUICE_ICONS, useValue: icons, multi: true }]);\n}\n","import {\n ChangeDetectionStrategy,\n Component,\n DOCUMENT,\n ViewEncapsulation,\n computed,\n effect,\n ElementRef,\n inject,\n input,\n isDevMode,\n} from '@angular/core';\nimport { JUICE_ICONS, JUICE_ICON_FALLBACK, IconNode } from './icons';\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\nconst warned = new Set<string>();\n\n/**\n * Inline SVG icon drawn from the registered lucide data. It inherits `currentColor`, is `aria-hidden` unless\n * `label` is set. An unregistered name draws the fallback icon (a dashed circle, JUICE_ICON_FALLBACK), marked\n * `data-icon-fallback`, with a dev-mode warning: a module may send any icon name, and a blank gap reads as a bug.\n */\n@Component({\n selector: 'juice-icon',\n template: '',\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n styles: `\n juice-icon {\n display: inline-flex;\n flex: none;\n align-items: center;\n justify-content: center;\n line-height: 0;\n vertical-align: middle;\n }\n juice-icon > svg {\n display: block;\n }\n `,\n host: {\n '[attr.role]': 'label() ? \"img\" : null',\n '[attr.aria-label]': 'label() || null',\n '[attr.aria-hidden]': 'label() ? null : \"true\"',\n '[attr.data-icon-fallback]': 'isFallback() ? \"\" : null',\n },\n})\nexport class JuiceIcon {\n /** Registered icon name. */\n readonly name = input.required<string>();\n /** Edge length in px (or any CSS length string). */\n readonly size = input<number | string>(16);\n /** Accessible name. Without it the icon is decorative. */\n readonly label = input<string>('');\n\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly doc = inject(DOCUMENT);\n private readonly sets = inject(JUICE_ICONS, { optional: true }) ?? [];\n private readonly fallback = inject(JUICE_ICON_FALLBACK);\n\n /** The registered icon for the name, or undefined. */\n private readonly registered = computed<IconNode | undefined>(() => {\n const name = this.name();\n for (let i = this.sets.length - 1; i >= 0; i--) {\n const set = this.sets[i];\n if (Object.prototype.hasOwnProperty.call(set, name)) return set[name];\n }\n if (isDevMode() && !warned.has(name)) {\n warned.add(name);\n console.warn(`[juice-icon] Unknown icon \"${name}\"; drawing the fallback. Register it with provideJuiceIcons().`);\n }\n return undefined;\n });\n protected readonly isFallback = computed(() => !this.registered() && !!this.fallback);\n private readonly node = computed<IconNode | undefined>(() => this.registered() ?? this.fallback ?? undefined);\n\n constructor() {\n effect(() => {\n const node = this.node();\n const size = this.size();\n this.host.replaceChildren();\n if (!node) return;\n const length = typeof size === 'number' ? `${size}px` : size;\n const svg = this.doc.createElementNS(SVG_NS, 'svg');\n setAttrs(svg, {\n xmlns: SVG_NS,\n viewBox: '0 0 24 24',\n fill: 'none',\n stroke: 'currentColor',\n 'stroke-width': '2',\n 'stroke-linecap': 'round',\n 'stroke-linejoin': 'round',\n 'aria-hidden': 'true',\n focusable: 'false',\n });\n svg.style.width = length;\n svg.style.height = length;\n for (const [tag, attrs] of node) {\n // lucide data only uses graphic primitives; refuse anything else so a bad icon set cannot inject script.\n if (!/^[a-z]+$/.test(tag) || tag === 'script' || tag === 'foreignObject') continue;\n const child = this.doc.createElementNS(SVG_NS, tag);\n setAttrs(child, attrs as Record<string, unknown>);\n svg.appendChild(child);\n }\n this.host.appendChild(svg);\n });\n }\n}\n\nfunction setAttrs(el: Element, attrs: Record<string, unknown>): void {\n for (const [key, value] of Object.entries(attrs)) {\n if (value == null || /^on/i.test(key) || !/^[A-Za-z][\\w:-]*$/.test(key)) continue;\n el.setAttribute(key, String(value));\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAQA;MACa,WAAW,GAAG,IAAI,cAAc,CAAiB,aAAa;AAE3E;;;AAGG;MACU,mBAAmB,GAAG,IAAI,cAAc,CAAkB,qBAAqB,EAAE;AAC5F,IAAA,UAAU,EAAE,MAAM;;IAElB,OAAO,EAAE,MAAM;AACb,QAAA,CAAC,M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ACzE,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IACrC;AACF;;AClHA;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juice-js/icons",
3
- "version": "3.0.0-alpha.6",
3
+ "version": "3.0.0-alpha.8",
4
4
  "description": "Juice icons: an inline SVG icon component over the lucide data package",
5
5
  "author": "Pavellis Labs <dev@pavellis.com>",
6
6
  "license": "MIT",
@@ -5,7 +5,8 @@ export { IconNode } from 'lucide';
5
5
 
6
6
  /**
7
7
  * Inline SVG icon drawn from the registered lucide data. It inherits `currentColor`, is `aria-hidden` unless
8
- * `label` is set, and renders nothing for an unknown name (with a dev-mode warning).
8
+ * `label` is set. An unregistered name draws the fallback icon (a dashed circle, JUICE_ICON_FALLBACK), marked
9
+ * `data-icon-fallback`, with a dev-mode warning: a module may send any icon name, and a blank gap reads as a bug.
9
10
  */
10
11
  declare class JuiceIcon {
11
12
  /** Registered icon name. */
@@ -17,6 +18,10 @@ declare class JuiceIcon {
17
18
  private readonly host;
18
19
  private readonly doc;
19
20
  private readonly sets;
21
+ private readonly fallback;
22
+ /** The registered icon for the name, or undefined. */
23
+ private readonly registered;
24
+ protected readonly isFallback: _angular_core.Signal<boolean>;
20
25
  private readonly node;
21
26
  constructor();
22
27
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<JuiceIcon, never>;
@@ -27,11 +32,18 @@ declare class JuiceIcon {
27
32
  type JuiceIconSet = Readonly<Record<string, IconNode>>;
28
33
  /** Multi token: every `provideJuiceIcons` call contributes one set; later sets win on a name clash. */
29
34
  declare const JUICE_ICONS: InjectionToken<Readonly<Record<string, IconNode>>[]>;
35
+ /**
36
+ * The icon drawn for a name nobody registered (a module's menu entry may send any Material name). Default: a dashed circle,
37
+ * neutral and clearly a placeholder. `provideJuiceIconFallback(null)` draws nothing instead; a dev-mode warning names the icon either way.
38
+ */
39
+ declare const JUICE_ICON_FALLBACK: InjectionToken<IconNode | null>;
40
+ /** Replaces the fallback icon for unregistered names, or turns it off (`null`: draw nothing). */
41
+ declare function provideJuiceIconFallback(icon: IconNode | null): EnvironmentProviders;
30
42
  /**
31
43
  * Registers icons for `<juice-icon>`. Pass only the icons the app uses so the rest tree-shake away:
32
44
  * `provideJuiceIcons({ search: Search, 'chevron-down': ChevronDown })`, with the nodes imported from `lucide`.
33
45
  */
34
46
  declare function provideJuiceIcons(icons: Record<string, IconNode>): EnvironmentProviders;
35
47
 
36
- export { JUICE_ICONS, JuiceIcon, provideJuiceIcons };
48
+ export { JUICE_ICONS, JUICE_ICON_FALLBACK, JuiceIcon, provideJuiceIconFallback, provideJuiceIcons };
37
49
  export type { JuiceIconSet };