@nice2dev/icons 1.3.7 → 1.3.9

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 (99) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/README.md +33 -16
  3. package/dist/cjs/NiceIconPicker.js +289 -92
  4. package/dist/cjs/NiceIconStacker.js +137 -108
  5. package/dist/cjs/client.js +6 -0
  6. package/dist/cjs/createIcon.js +17 -4
  7. package/dist/cjs/iconHtml.js +122 -0
  8. package/dist/cjs/iconParts.js +24 -2
  9. package/dist/cjs/iconStack.js +76 -5
  10. package/dist/cjs/icons/accessibility.js +9 -8
  11. package/dist/cjs/icons/actions.js +38 -35
  12. package/dist/cjs/icons/ai.js +12 -11
  13. package/dist/cjs/icons/brand.js +2 -2
  14. package/dist/cjs/icons/business.js +14 -16
  15. package/dist/cjs/icons/devtech.js +17 -15
  16. package/dist/cjs/icons/ecommerce.js +7 -12
  17. package/dist/cjs/icons/education.js +14 -16
  18. package/dist/cjs/icons/files.js +46 -22
  19. package/dist/cjs/icons/fintech.js +2 -11
  20. package/dist/cjs/icons/food.js +12 -8
  21. package/dist/cjs/icons/fun.js +11 -11
  22. package/dist/cjs/icons/gaming.js +20 -13
  23. package/dist/cjs/icons/health.js +9 -12
  24. package/dist/cjs/icons/index.js +1 -0
  25. package/dist/cjs/icons/input.js +31 -21
  26. package/dist/cjs/icons/legal.js +11 -11
  27. package/dist/cjs/icons/media.js +24 -15
  28. package/dist/cjs/icons/navigation.js +16 -13
  29. package/dist/cjs/icons/omniverk.js +2 -7
  30. package/dist/cjs/icons/realestate.js +14 -14
  31. package/dist/cjs/icons/saas.js +0 -10
  32. package/dist/cjs/icons/science.js +12 -12
  33. package/dist/cjs/icons/shapes.js +20 -17
  34. package/dist/cjs/icons/smarthome.js +0 -11
  35. package/dist/cjs/icons/social.js +7 -6
  36. package/dist/cjs/icons/sports.js +5 -6
  37. package/dist/cjs/icons/sustainability.js +12 -11
  38. package/dist/cjs/icons/travel.js +9 -9
  39. package/dist/cjs/icons/ui.js +55 -31
  40. package/dist/cjs/icons/weather.js +8 -13
  41. package/dist/cjs/index.js +7 -0
  42. package/dist/cjs/nicetodev-icons.css +1 -1
  43. package/dist/cjs/resolver.js +1 -0
  44. package/dist/cjs/stacking.js +38 -11
  45. package/dist/esm/NiceIconPicker.js +292 -95
  46. package/dist/esm/NiceIconStacker.js +141 -112
  47. package/dist/esm/client.js +2 -1
  48. package/dist/esm/createIcon.js +18 -5
  49. package/dist/esm/iconHtml.js +117 -0
  50. package/dist/esm/iconParts.js +24 -3
  51. package/dist/esm/iconStack.js +74 -6
  52. package/dist/esm/icons/accessibility.js +9 -8
  53. package/dist/esm/icons/actions.js +39 -36
  54. package/dist/esm/icons/ai.js +12 -11
  55. package/dist/esm/icons/brand.js +2 -2
  56. package/dist/esm/icons/business.js +15 -17
  57. package/dist/esm/icons/devtech.js +17 -15
  58. package/dist/esm/icons/ecommerce.js +7 -12
  59. package/dist/esm/icons/education.js +14 -16
  60. package/dist/esm/icons/files.js +47 -23
  61. package/dist/esm/icons/fintech.js +2 -11
  62. package/dist/esm/icons/food.js +12 -8
  63. package/dist/esm/icons/fun.js +11 -11
  64. package/dist/esm/icons/gaming.js +21 -14
  65. package/dist/esm/icons/health.js +9 -12
  66. package/dist/esm/icons/index.js +1 -1
  67. package/dist/esm/icons/input.js +31 -21
  68. package/dist/esm/icons/legal.js +12 -12
  69. package/dist/esm/icons/media.js +25 -16
  70. package/dist/esm/icons/navigation.js +16 -13
  71. package/dist/esm/icons/omniverk.js +2 -7
  72. package/dist/esm/icons/realestate.js +15 -15
  73. package/dist/esm/icons/saas.js +0 -10
  74. package/dist/esm/icons/science.js +12 -12
  75. package/dist/esm/icons/shapes.js +20 -17
  76. package/dist/esm/icons/smarthome.js +0 -11
  77. package/dist/esm/icons/social.js +8 -7
  78. package/dist/esm/icons/sports.js +6 -7
  79. package/dist/esm/icons/sustainability.js +12 -11
  80. package/dist/esm/icons/travel.js +10 -10
  81. package/dist/esm/icons/ui.js +56 -33
  82. package/dist/esm/icons/weather.js +9 -14
  83. package/dist/esm/index.js +3 -2
  84. package/dist/esm/nicetodev-icons.css +1 -1
  85. package/dist/esm/resolver.js +1 -0
  86. package/dist/esm/stacking.js +36 -12
  87. package/dist/types/NiceIconPicker.d.ts +66 -20
  88. package/dist/types/NiceIconStacker.d.ts +30 -9
  89. package/dist/types/client.d.ts +4 -2
  90. package/dist/types/createIcon.d.ts +16 -2
  91. package/dist/types/iconHtml.d.ts +44 -0
  92. package/dist/types/iconParts.d.ts +8 -2
  93. package/dist/types/iconStack.d.ts +30 -3
  94. package/dist/types/icons/index.d.ts +1 -1
  95. package/dist/types/icons/ui.d.ts +1 -0
  96. package/dist/types/index.d.ts +4 -2
  97. package/dist/types/stacking.d.ts +25 -5
  98. package/dist/types/types.d.ts +11 -7
  99. package/package.json +2 -2
@@ -1,31 +1,56 @@
1
1
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
- import { useNiceTranslation, useControllableState } from '@nice2dev/ui-core';
3
- import { forwardRef, useRef, useId, useState, useCallback, useMemo, useImperativeHandle } from 'react';
2
+ import { useNiceTranslation, useControllableState, useRovingFocus } from '@nice2dev/ui-core';
3
+ import React, { forwardRef, useState, useRef, useCallback, useMemo, useImperativeHandle } from 'react';
4
4
  import { NtdPlus, NtdTrash, NtdCheck, NtdCopy } from './icons/actions.js';
5
5
  import { NtdClose } from './icons/navigation.js';
6
- import { niceIconStackCode, renderIconStack, stackChildrenOf, isValidTextBinding, stackParentId } from './iconStack.js';
7
- import { defaultStackSize, defaultTextSize } from './stacking.js';
6
+ import { niceIconStackCode, iconDisplayName, stackParentId, stackChildrenOf, isValidTextBinding, renderIconStack, addStackLayer, removeStackLayer } from './iconStack.js';
7
+ import { BOX_PERFECT_STACK, defaultStackSize, defaultTextSize, perfectStackOf } from './stacking.js';
8
8
 
9
- const ALIGNS = [
10
- 'center',
11
- 'top',
12
- 'bottom',
13
- 'left',
14
- 'right',
15
- 'top-left',
16
- 'top-right',
17
- 'bottom-left',
18
- 'bottom-right',
19
- 'half-top',
20
- 'half-bottom',
21
- 'half-left',
22
- 'half-right',
23
- 'half-top-left',
24
- 'half-top-right',
25
- 'half-bottom-left',
26
- 'half-bottom-right',
9
+ /** Where a layer can sit, laid out on the 5 × 5 pad as it sits in its parent. */
10
+ const PAD = [
11
+ { align: 'top-left', row: 1, col: 1 },
12
+ { align: 'top', row: 1, col: 3 },
13
+ { align: 'top-right', row: 1, col: 5 },
14
+ { align: 'half-top-left', row: 2, col: 2 },
15
+ { align: 'half-top', row: 2, col: 3 },
16
+ { align: 'half-top-right', row: 2, col: 4 },
17
+ { align: 'left', row: 3, col: 1 },
18
+ { align: 'half-left', row: 3, col: 2 },
19
+ { align: 'center', row: 3, col: 3 },
20
+ { align: 'half-right', row: 3, col: 4 },
21
+ { align: 'right', row: 3, col: 5 },
22
+ { align: 'half-bottom-left', row: 4, col: 2 },
23
+ { align: 'half-bottom', row: 4, col: 3 },
24
+ { align: 'half-bottom-right', row: 4, col: 4 },
25
+ { align: 'bottom-left', row: 5, col: 1 },
26
+ { align: 'bottom', row: 5, col: 3 },
27
+ { align: 'bottom-right', row: 5, col: 5 },
27
28
  ];
28
- const PREVIEW_SIZES = [96, 48, 24];
29
+ /** The positions' names, in words. */
30
+ function alignNames(t) {
31
+ return {
32
+ perfect: t('iconStacker.align.perfect', 'Auto'),
33
+ center: t('iconStacker.align.center', 'Centre'),
34
+ top: t('iconStacker.align.top', 'Top edge'),
35
+ bottom: t('iconStacker.align.bottom', 'Bottom edge'),
36
+ left: t('iconStacker.align.left', 'Left edge'),
37
+ right: t('iconStacker.align.right', 'Right edge'),
38
+ 'top-left': t('iconStacker.align.top-left', 'Top-left corner'),
39
+ 'top-right': t('iconStacker.align.top-right', 'Top-right corner'),
40
+ 'bottom-left': t('iconStacker.align.bottom-left', 'Bottom-left corner'),
41
+ 'bottom-right': t('iconStacker.align.bottom-right', 'Bottom-right corner'),
42
+ 'half-top': t('iconStacker.align.half-top', 'Halfway to the top'),
43
+ 'half-bottom': t('iconStacker.align.half-bottom', 'Halfway to the bottom'),
44
+ 'half-left': t('iconStacker.align.half-left', 'Halfway to the left'),
45
+ 'half-right': t('iconStacker.align.half-right', 'Halfway to the right'),
46
+ 'half-top-left': t('iconStacker.align.half-top-left', 'Halfway to the top-left corner'),
47
+ 'half-top-right': t('iconStacker.align.half-top-right', 'Halfway to the top-right corner'),
48
+ 'half-bottom-left': t('iconStacker.align.half-bottom-left', 'Halfway to the bottom-left corner'),
49
+ 'half-bottom-right': t('iconStacker.align.half-bottom-right', 'Halfway to the bottom-right corner'),
50
+ };
51
+ }
52
+ const STAGE_SIZE = 64;
53
+ const STAGE_SMALL = [32, 24, 16];
29
54
  const NO_LAYERS = [];
30
55
  /** What a colour field shows while the colour is unset (follows the parent). */
31
56
  const AUTO_SWATCH = '#808080';
@@ -43,57 +68,21 @@ function walk(layers) {
43
68
  }
44
69
  return out;
45
70
  }
46
- /** Removes a layer; what sat in it moves up into its parent (a removed base hands over to its first child). */
47
- function removeLayer(layers, id) {
48
- const base = layers[0];
49
- if (!base) {
50
- return [];
51
- }
52
- if (id !== base.id) {
53
- const gone = layers.find((l) => l.id === id);
54
- const up = gone ? stackParentId(layers, gone) : undefined;
55
- return layers
56
- .filter((l) => l.id !== id)
57
- .map((l) => (l.parent === id ? { ...l, parent: up === base.id ? undefined : up } : l));
58
- }
59
- const [heir, ...siblings] = stackChildrenOf(layers, base.id);
60
- if (!heir) {
61
- return [];
62
- }
63
- const newBase = {
64
- ...heir,
65
- parent: undefined,
66
- align: undefined,
67
- size: undefined,
68
- rotation: undefined,
69
- offsetX: undefined,
70
- offsetY: undefined,
71
- };
72
- return [
73
- newBase,
74
- ...layers
75
- .filter((l) => l.id !== base.id && l.id !== heir.id)
76
- .map((l) => siblings.includes(l)
77
- ? { ...l, parent: heir.id }
78
- : l.parent === heir.id
79
- ? { ...l, parent: undefined }
80
- : l),
81
- ];
82
- }
83
71
  /** A colour of the layer's own, or "auto" — following its parent — until one is picked. */
84
- function ColorField({ label, value, onChange, autoLabel, resetLabel }) {
85
- return (jsxs("span", { className: "nice-icon-stacker__color", children: [jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: label }), jsx("input", { type: "color", value: value !== null && value !== void 0 ? value : AUTO_SWATCH, onChange: (e) => onChange(e.target.value) })] }), value ? (jsx("button", { type: "button", className: "nice-icon-stacker__reset", onClick: () => onChange(undefined), "aria-label": resetLabel, title: resetLabel, children: jsx(NtdClose, { size: 12 }) })) : (jsx("small", { className: "nice-icon-stacker__auto", children: autoLabel }))] }));
72
+ function Swatch({ label, value, onChange, autoLabel, resetLabel }) {
73
+ return (jsxs("span", { className: "nice-icon-stacker__swatch", children: [jsxs("label", { className: `nice-icon-stacker__swatch-pick${value ? '' : ' nice-icon-stacker__swatch-pick--auto'}`, title: `${label}: ${value !== null && value !== void 0 ? value : autoLabel}`, children: [jsx("span", { className: "nice-icon-stacker__swatch-dot", style: value ? { background: value } : undefined }), jsx("span", { children: label }), jsx("input", { type: "color", value: value !== null && value !== void 0 ? value : AUTO_SWATCH, onChange: (e) => onChange(e.target.value) })] }), value && (jsx("button", { type: "button", className: "nice-icon-stacker__reset", onClick: () => onChange(undefined), "aria-label": `${resetLabel}: ${label}`, title: resetLabel, children: jsx(NtdClose, { size: 10 }) }))] }));
86
74
  }
87
75
  /**
88
- * NiceIconStacker (1.3.5) — builds an icon stack: the base icon and the icons stacked in it, each
89
- * with its position, size, turn and colours, nested any number of levels deep (1.3.6) with text
90
- * innermost — its size, colour and the value it is bound to — shown live at three sizes and as the
91
- * JSX that draws it. The "add" button puts `current` into the selected layer and selects it, so
92
- * adding again goes one level deeper; select an outer layer to add side by side. Layers leave one
93
- * by one or all at once. `NiceIconStack` draws a stack built here from data.
76
+ * NiceIconStacker (1.3.5) — builds an icon stack: the base icon and the icons stacked in it, nested
77
+ * any number of levels deep (1.3.6) with text innermost. Since 1.3.9 it is laid out to fit a picker's
78
+ * panel: the stack drawn large and small, the layers as a list, and under it the selected layer —
79
+ * where it sits (picked on a pad shaped like its parent), its size and text, with the turn, nudge,
80
+ * colours and binding folded under "More". A new icon goes into the selected layer and is selected,
81
+ * so adding again goes one level deeper; select an outer layer to add side by side. The JSX that
82
+ * draws the stack is folded at the end. `NiceIconStack` draws a stack built here from data.
94
83
  */
95
- const NiceIconStacker = forwardRef(function NiceIconStacker({ icons, layers: layersProp, defaultLayers, onLayersChange, current, previewProps, className }, ref) {
96
- var _a, _b, _c, _d;
84
+ const NiceIconStacker = forwardRef(function NiceIconStacker({ icons, layers: layersProp, defaultLayers, onLayersChange, current, onAddClick, previewProps, iconLabel = iconDisplayName, showCode = true, keepBase = false, className, }, ref) {
85
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
97
86
  const { t } = useNiceTranslation();
98
87
  const [layers, setLayers] = useControllableState({
99
88
  value: layersProp,
@@ -102,43 +91,47 @@ const NiceIconStacker = forwardRef(function NiceIconStacker({ icons, layers: lay
102
91
  onChange: onLayersChange,
103
92
  componentName: 'NiceIconStacker',
104
93
  });
105
- const nextId = useRef(0);
106
- const targetGroup = useId();
107
94
  const [copied, setCopied] = useState(false);
108
- // The layer the next icon goes into — the newest by default, so adding nests deeper.
95
+ // The layer being edited, which the next icon goes into — the newest by default, so adding nests deeper.
109
96
  const [selected, setSelected] = useState(undefined);
110
97
  const base = layers[0];
111
98
  const target = (_b = (_a = layers.find((l) => l.id === selected)) !== null && _a !== void 0 ? _a : layers[layers.length - 1]) !== null && _b !== void 0 ? _b : undefined;
99
+ const listRef = useRef(null);
100
+ useRovingFocus(listRef, {
101
+ orientation: 'vertical',
102
+ itemSelector: '.nice-icon-stacker__layer-select',
103
+ });
104
+ const padRef = useRef(null);
105
+ useRovingFocus(padRef, {
106
+ orientation: 'grid',
107
+ itemSelector: '[role="radio"]',
108
+ activateOnMove: true,
109
+ });
112
110
  const resolve = useCallback((name) => (typeof icons === 'function' ? icons(name) : icons[name]), [icons]);
113
111
  const tree = useMemo(() => walk(layers), [layers]);
114
- const code = useMemo(() => niceIconStackCode(layers), [layers]);
112
+ const code = useMemo(() => (showCode ? niceIconStackCode(layers) : ''), [layers, showCode]);
115
113
  const update = (id, patch) => setLayers((prev) => prev.map((l) => (l.id === id ? { ...l, ...patch } : l)));
116
- const add = () => {
117
- if (!current) {
114
+ const add = (icon = current) => {
115
+ if (!icon) {
118
116
  return;
119
117
  }
120
- nextId.current += 1;
121
- const id = `${current.icon}-${Date.now().toString(36)}-${nextId.current}`;
118
+ let added = '';
122
119
  setLayers((prev) => {
123
- const into = prev.find((l) => l.id === (target === null || target === void 0 ? void 0 : target.id));
124
- const layer = {
125
- id,
126
- icon: current.icon,
127
- variant: current.variant,
128
- ...(into && into !== prev[0] ? { parent: into.id } : {}),
129
- };
130
- return [...prev, layer];
120
+ var _a;
121
+ const next = addStackLayer(prev, icon, (_a = prev.find((l) => l.id === (target === null || target === void 0 ? void 0 : target.id))) === null || _a === void 0 ? void 0 : _a.id);
122
+ added = next.id;
123
+ return next.layers;
131
124
  });
132
- setSelected(id);
125
+ setSelected(added);
133
126
  };
134
127
  const remove = (id) => {
135
- setLayers((prev) => removeLayer(prev, id));
128
+ setLayers((prev) => removeStackLayer(prev, id));
136
129
  if (selected === id) {
137
130
  setSelected(undefined);
138
131
  }
139
132
  };
140
133
  const clear = () => {
141
- setLayers(NO_LAYERS);
134
+ setLayers((prev) => (keepBase && prev[0] ? [prev[0]] : NO_LAYERS));
142
135
  setSelected(undefined);
143
136
  };
144
137
  useImperativeHandle(ref, () => ({ add, clear }));
@@ -151,30 +144,66 @@ const NiceIconStacker = forwardRef(function NiceIconStacker({ icons, layers: lay
151
144
  };
152
145
  const autoLabel = t('iconStacker.auto', 'auto');
153
146
  const resetLabel = t('iconStacker.reset', 'Back to auto');
154
- const addLabel = base && target
155
- ? t('iconStacker.addInto', 'Add {icon} into {target}')
156
- .replace('{icon}', (_c = current === null || current === void 0 ? void 0 : current.icon) !== null && _c !== void 0 ? _c : '')
157
- .replace('{target}', target.icon)
158
- : t('iconStacker.add', 'Add {icon} to the stack').replace('{icon}', (_d = current === null || current === void 0 ? void 0 : current.icon) !== null && _d !== void 0 ? _d : '');
159
- return (jsxs("div", { className: ['nice-icon-stacker', className].filter(Boolean).join(' '), children: [jsxs("div", { className: "nice-icon-stacker__toolbar", children: [jsxs("button", { type: "button", onClick: add, disabled: !current, children: [jsx(NtdPlus, { size: 14 }), " ", addLabel] }), jsxs("button", { type: "button", onClick: clear, disabled: layers.length === 0, children: [jsx(NtdTrash, { size: 14 }), " ", t('iconStacker.clear', 'Clear the stack')] })] }), !base ? (jsx("p", { className: "nice-icon-stacker__empty", children: t('iconStacker.empty', 'The stack is empty. Add an icon to start one.') })) : (jsxs("div", { className: "nice-icon-stacker__body", children: [jsx("div", { className: "nice-icon-stacker__preview", "aria-label": t('iconStacker.preview', 'Preview'), role: "group", children: PREVIEW_SIZES.map((s) => (jsxs("span", { className: "nice-icon-stacker__preview-cell", children: [renderIconStack(layers, icons, {
160
- baseProps: { ...previewProps, size: s, title: base.icon },
161
- }), jsxs("small", { children: [s, "px"] })] }, s))) }), jsx("ol", { className: "nice-icon-stacker__layers", "aria-label": t('iconStacker.layers', 'Layers'), children: tree.map(({ layer: l, depth }) => {
162
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
163
- const Icon = resolve(l.icon);
164
- const isBase = l === base;
165
- const align = (_a = l.align) !== null && _a !== void 0 ? _a : 'center';
166
- const share = (_b = l.size) !== null && _b !== void 0 ? _b : defaultStackSize(align);
167
- const innermost = stackChildrenOf(layers, l.id).length === 0;
168
- const textSize = (_c = l.textSize) !== null && _c !== void 0 ? _c : defaultTextSize(((_d = l.text) !== null && _d !== void 0 ? _d : '').length || 1);
169
- const bindingInvalid = !!l.textBinding && !isValidTextBinding(l.textBinding);
170
- const depthStyle = {
171
- ['--nice-icon-stacker-depth']: String(depth),
172
- };
173
- const label = (key, fallback) => t(key, fallback).replace('{icon}', l.icon);
174
- return (jsxs("li", { className: "nice-icon-stacker__layer", style: depthStyle, children: [jsxs("div", { className: "nice-icon-stacker__layer-row", children: [jsx("input", { type: "radio", name: targetGroup, checked: (target === null || target === void 0 ? void 0 : target.id) === l.id, onChange: () => setSelected(l.id), "aria-label": label('iconStacker.target', 'Add the next icon into {icon}'), title: label('iconStacker.target', 'Add the next icon into {icon}') }), jsx("span", { className: "nice-icon-stacker__layer-icon", children: Icon ? jsx(Icon, { size: 24, variant: l.variant }) : null }), jsxs("span", { className: "nice-icon-stacker__layer-name", children: [l.icon, isBase && (jsx("span", { className: "nice-icon-stacker__badge", children: t('iconStacker.base', 'Base') }))] }), !isBase && (jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.align', 'Position') }), jsx("select", { value: align, onChange: (e) => update(l.id, { align: e.target.value }), children: ALIGNS.map((a) => (jsx("option", { value: a, children: a }, a))) })] })), !isBase && (jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.size', 'Size') }), jsx("input", { type: "range", min: 0.2, max: 1, step: 0.05, value: share, onChange: (e) => update(l.id, { size: Number(e.target.value) }) }), jsxs("output", { children: [Math.round(share * 100), "%"] })] })), jsx("button", { type: "button", className: "nice-icon-stacker__remove", onClick: () => remove(l.id), "aria-label": label('iconStacker.remove', 'Remove {icon}'), title: label('iconStacker.remove', 'Remove {icon}'), children: jsx(NtdTrash, { size: 14 }) })] }), jsxs("details", { className: "nice-icon-stacker__more", children: [jsx("summary", { children: t('iconStacker.more', 'More') }), jsxs("div", { className: "nice-icon-stacker__more-body", children: [!isBase && (jsxs(Fragment, { children: [jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.rotation', 'Turn') }), jsx("input", { type: "range", min: -180, max: 180, step: 15, value: (_e = l.rotation) !== null && _e !== void 0 ? _e : 0, onChange: (e) => update(l.id, { rotation: Number(e.target.value) || undefined }) }), jsxs("output", { children: [(_f = l.rotation) !== null && _f !== void 0 ? _f : 0, "\u00B0"] })] }), jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.offsetX', 'Shift right') }), jsx("input", { type: "range", min: -50, max: 50, step: 1, value: (_g = l.offsetX) !== null && _g !== void 0 ? _g : 0, onChange: (e) => update(l.id, { offsetX: Number(e.target.value) || undefined }) }), jsxs("output", { children: [(_h = l.offsetX) !== null && _h !== void 0 ? _h : 0, "%"] })] }), jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.offsetY', 'Shift down') }), jsx("input", { type: "range", min: -50, max: 50, step: 1, value: (_j = l.offsetY) !== null && _j !== void 0 ? _j : 0, onChange: (e) => update(l.id, { offsetY: Number(e.target.value) || undefined }) }), jsxs("output", { children: [(_k = l.offsetY) !== null && _k !== void 0 ? _k : 0, "%"] })] })] })), jsx(ColorField, { label: t('iconStacker.primary', 'Primary'), value: l.primaryColor, onChange: (v) => update(l.id, { primaryColor: v }), autoLabel: autoLabel, resetLabel: resetLabel }), jsx(ColorField, { label: t('iconStacker.secondary', 'Secondary'), value: l.secondaryColor, onChange: (v) => update(l.id, { secondaryColor: v }), autoLabel: autoLabel, resetLabel: resetLabel }), jsx(ColorField, { label: t('iconStacker.accent', 'Accent'), value: l.accentColor, onChange: (v) => update(l.id, { accentColor: v }), autoLabel: autoLabel, resetLabel: resetLabel })] })] }), (innermost || l.text || l.textBinding) && (jsxs("div", { className: "nice-icon-stacker__text", children: [jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.text', 'Text') }), jsx("input", { type: "text", value: (_l = l.text) !== null && _l !== void 0 ? _l : '', maxLength: 4, onChange: (e) => update(l.id, { text: e.target.value || undefined }) })] }), jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.textSize', 'Text size') }), jsx("input", { type: "range", min: 3, max: 14, step: 0.5, value: textSize, onChange: (e) => update(l.id, { textSize: Number(e.target.value) }) }), jsx("output", { children: textSize }), l.textSize !== undefined && (jsx("button", { type: "button", className: "nice-icon-stacker__reset", onClick: () => update(l.id, { textSize: undefined }), "aria-label": resetLabel, title: resetLabel, children: jsx(NtdClose, { size: 12 }) }))] }), jsx(ColorField, { label: t('iconStacker.textColor', 'Text colour'), value: l.textColor, onChange: (v) => update(l.id, { textColor: v }), autoLabel: autoLabel, resetLabel: resetLabel }), jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.bind', 'Bind to') }), jsx("input", { type: "text", value: (_m = l.textBinding) !== null && _m !== void 0 ? _m : '', "aria-invalid": bindingInvalid || undefined, title: t('iconStacker.bindHint', 'The name of the value the text shows, e.g. count — the text above is a sample'), onChange: (e) => update(l.id, { textBinding: e.target.value.trim() || undefined }) })] })] }))] }, l.id));
175
- }) }), jsxs("div", { className: "nice-icon-stacker__code", children: [jsx("pre", { children: code }), jsxs("button", { type: "button", onClick: copy, children: [copied ? jsx(NtdCheck, { size: 14 }) : jsx(NtdCopy, { size: 14 }), ' ', copied
147
+ const names = alignNames(t);
148
+ const alignName = (a) => names[a];
149
+ const currentName = current ? iconLabel(current.icon) : '';
150
+ const targetName = target ? iconLabel(target.icon) : '';
151
+ const asks = !!onAddClick || !current;
152
+ const addText = asks
153
+ ? t('iconStacker.addIcon', 'Add an icon')
154
+ : t('iconStacker.addShort', 'Add {icon}').replace('{icon}', currentName);
155
+ const addLabel = asks
156
+ ? base && target
157
+ ? t('iconStacker.addIconInto', 'Add an icon into {target}').replace('{target}', targetName)
158
+ : addText
159
+ : base && target
160
+ ? t('iconStacker.addInto', 'Add {icon} into {target}')
161
+ .replace('{icon}', currentName)
162
+ .replace('{target}', targetName)
163
+ : t('iconStacker.add', 'Add {icon} to the stack').replace('{icon}', currentName);
164
+ const clearLabel = keepBase
165
+ ? t('iconStacker.clearOverlays', 'Take off the stacked icons')
166
+ : t('iconStacker.clear', 'Clear the stack');
167
+ // the selected layer, as the inspector edits it
168
+ const edited = target;
169
+ const editedIcon = edited ? resolve(edited.icon) : undefined;
170
+ const editedIsBase = !!edited && edited === base;
171
+ const align = (_c = edited === null || edited === void 0 ? void 0 : edited.align) !== null && _c !== void 0 ? _c : 'perfect';
172
+ // the spot the parent keeps for stacked icons (1.3.8): its size and turn are the layer's
173
+ // defaults while it sits there
174
+ const parentId = edited ? stackParentId(layers, edited) : undefined;
175
+ const parentLayer = parentId ? layers.find((p) => p.id === parentId) : undefined;
176
+ const spot = (parentLayer && perfectStackOf(resolve(parentLayer.icon))) || BOX_PERFECT_STACK;
177
+ const atSpot = align === 'perfect';
178
+ const share = (_d = edited === null || edited === void 0 ? void 0 : edited.size) !== null && _d !== void 0 ? _d : (atSpot ? spot.size : defaultStackSize(align));
179
+ const turnDefault = atSpot ? spot.rotation : 0;
180
+ const turn = (_e = edited === null || edited === void 0 ? void 0 : edited.rotation) !== null && _e !== void 0 ? _e : turnDefault;
181
+ const innermost = !!edited && stackChildrenOf(layers, edited.id).length === 0;
182
+ const hasText = !!edited && (innermost || !!edited.text || !!edited.textBinding);
183
+ const textSize = (_f = edited === null || edited === void 0 ? void 0 : edited.textSize) !== null && _f !== void 0 ? _f : defaultTextSize(((_g = edited === null || edited === void 0 ? void 0 : edited.text) !== null && _g !== void 0 ? _g : '').length || 1, (_h = perfectStackOf(editedIcon)) === null || _h === void 0 ? void 0 : _h.size);
184
+ const bindingInvalid = !!(edited === null || edited === void 0 ? void 0 : edited.textBinding) && !isValidTextBinding(edited.textBinding);
185
+ return (jsxs("div", { className: ['nice-icon-stacker', className].filter(Boolean).join(' '), children: [jsxs("div", { className: "nice-icon-stacker__bar", children: [jsx("span", { className: "nice-icon-stacker__title", children: t('iconStacker.layers', 'Layers') }), jsxs("button", { type: "button", className: "nice-icon-stacker__add", onClick: () => (onAddClick ? onAddClick(target) : add()), disabled: !onAddClick && !current, "aria-label": addLabel, title: addLabel, children: [jsx(NtdPlus, { size: 14 }), " ", addText] }), jsx("button", { type: "button", className: "nice-icon-stacker__clear", onClick: clear, disabled: keepBase ? layers.length < 2 : layers.length === 0, "aria-label": clearLabel, title: clearLabel, children: jsx(NtdTrash, { size: 14 }) })] }), !base || !edited ? (jsx("p", { className: "nice-icon-stacker__empty", children: t('iconStacker.empty', 'The stack is empty. Add an icon to start one.') })) : (jsxs(Fragment, { children: [jsxs("div", { className: "nice-icon-stacker__top", children: [jsxs("div", { className: "nice-icon-stacker__preview", "aria-label": t('iconStacker.preview', 'Preview'), role: "group", children: [jsx("span", { className: "nice-icon-stacker__preview-main", title: `${STAGE_SIZE}px`, children: renderIconStack(layers, icons, {
186
+ baseProps: { ...previewProps, size: STAGE_SIZE, title: iconLabel(base.icon) },
187
+ }) }), jsx("span", { className: "nice-icon-stacker__preview-small", children: STAGE_SMALL.map((s) => (jsx("span", { title: `${s}px`, children: renderIconStack(layers, icons, { baseProps: { ...previewProps, size: s } }) }, s))) })] }), jsxs("div", { className: "nice-icon-stacker__layers-wrap", children: [jsx("ol", { ref: listRef, className: "nice-icon-stacker__layers", "aria-label": t('iconStacker.layers', 'Layers'), children: tree.map(({ layer: l, depth }) => {
188
+ const Icon = resolve(l.icon);
189
+ const isBase = l === base;
190
+ const isSelected = l === edited;
191
+ const name = iconLabel(l.icon);
192
+ const removable = !(isBase && keepBase);
193
+ const removeLabel = t('iconStacker.remove', 'Remove {icon}').replace('{icon}', name);
194
+ return (jsxs("li", { className: `nice-icon-stacker__layer${isSelected ? ' nice-icon-stacker__layer--selected' : ''}`, style: { ['--nice-icon-stacker-depth']: String(depth) }, children: [jsxs("button", { type: "button", className: "nice-icon-stacker__layer-select", "aria-pressed": isSelected, onClick: () => setSelected(l.id), onKeyDown: (e) => {
195
+ if (removable && (e.key === 'Delete' || e.key === 'Backspace')) {
196
+ e.preventDefault();
197
+ remove(l.id);
198
+ }
199
+ }, children: [jsx("span", { className: "nice-icon-stacker__layer-icon", children: Icon ? jsx(Icon, { size: 18, variant: l.variant }) : null }), jsx("span", { className: "nice-icon-stacker__layer-name", children: name }), l.text && (jsxs(Fragment, { children: [' ', jsx("span", { className: "nice-icon-stacker__layer-text", children: l.text })] })), isBase && (jsxs(Fragment, { children: [' ', jsx("span", { className: "nice-icon-stacker__badge", children: t('iconStacker.base', 'Base') })] }))] }), removable && (jsx("button", { type: "button", className: "nice-icon-stacker__remove", onClick: () => remove(l.id), "aria-label": removeLabel, title: removeLabel, children: jsx(NtdClose, { size: 10 }) }))] }, l.id));
200
+ }) }), jsx("small", { className: "nice-icon-stacker__hint", children: t('iconStacker.hint', 'A new icon goes into the selected layer.') })] })] }), jsxs("div", { className: "nice-icon-stacker__inspector", role: "group", "aria-label": iconLabel(edited.icon), children: [jsxs("div", { className: "nice-icon-stacker__inspector-head", children: [editedIcon &&
201
+ React.createElement(editedIcon, { size: 16, variant: edited.variant }), jsx("span", { children: iconLabel(edited.icon) }), parentLayer && (jsx("small", { children: t('iconStacker.inside', 'in {icon}').replace('{icon}', iconLabel(parentLayer.icon)) }))] }), jsxs("div", { className: "nice-icon-stacker__inspector-body", children: [!editedIsBase && (jsxs("div", { ref: padRef, className: "nice-icon-stacker__pad", role: "radiogroup", "aria-label": t('iconStacker.align', 'Position'), children: [jsx("button", { type: "button", role: "radio", "aria-checked": align === 'perfect', className: "nice-icon-stacker__pad-auto", title: t('iconStacker.align.perfectHint', 'The spot the icon keeps for what is stacked in it'), onClick: () => update(edited.id, { align: undefined }), children: alignName('perfect') }), jsx("span", { className: "nice-icon-stacker__pad-box", children: PAD.map(({ align: a, row, col }) => (jsx("button", { type: "button", role: "radio", "aria-checked": align === a, "aria-label": alignName(a), title: alignName(a), className: "nice-icon-stacker__pad-dot", style: { gridRow: row, gridColumn: col }, onClick: () => update(edited.id, { align: a }) }, a))) })] })), jsxs("div", { className: "nice-icon-stacker__fields", children: [!editedIsBase && (jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.size', 'Size') }), jsx("input", { type: "range", min: 0.2, max: 1, step: 0.05, value: share, onChange: (e) => update(edited.id, { size: Number(e.target.value) }) }), jsxs("output", { children: [Math.round(share * 100), "%"] })] })), hasText && (jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.text', 'Text') }), jsx("input", { type: "text", value: (_j = edited.text) !== null && _j !== void 0 ? _j : '', maxLength: 4, onChange: (e) => update(edited.id, { text: e.target.value || undefined }) })] }))] })] }), jsxs("details", { className: "nice-icon-stacker__more", children: [jsx("summary", { children: t('iconStacker.more', 'More') }), jsxs("div", { className: "nice-icon-stacker__more-body", children: [!editedIsBase && (jsxs(Fragment, { children: [jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.rotation', 'Turn') }), jsx("input", { type: "range", min: -180, max: 180, step: 15, value: turn, onChange: (e) => {
202
+ const v = Number(e.target.value);
203
+ update(edited.id, { rotation: v === turnDefault ? undefined : v });
204
+ } }), jsxs("output", { children: [turn, "\u00B0"] })] }), jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.offsetX', 'Shift right') }), jsx("input", { type: "range", min: -50, max: 50, step: 1, value: (_k = edited.offsetX) !== null && _k !== void 0 ? _k : 0, onChange: (e) => update(edited.id, { offsetX: Number(e.target.value) || undefined }) }), jsxs("output", { children: [(_l = edited.offsetX) !== null && _l !== void 0 ? _l : 0, "%"] })] }), jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.offsetY', 'Shift down') }), jsx("input", { type: "range", min: -50, max: 50, step: 1, value: (_m = edited.offsetY) !== null && _m !== void 0 ? _m : 0, onChange: (e) => update(edited.id, { offsetY: Number(e.target.value) || undefined }) }), jsxs("output", { children: [(_o = edited.offsetY) !== null && _o !== void 0 ? _o : 0, "%"] })] })] })), jsxs("div", { className: "nice-icon-stacker__swatches", children: [jsx(Swatch, { label: t('iconStacker.primary', 'Primary'), value: edited.primaryColor, onChange: (v) => update(edited.id, { primaryColor: v }), autoLabel: autoLabel, resetLabel: resetLabel }), jsx(Swatch, { label: t('iconStacker.secondary', 'Secondary'), value: edited.secondaryColor, onChange: (v) => update(edited.id, { secondaryColor: v }), autoLabel: autoLabel, resetLabel: resetLabel }), jsx(Swatch, { label: t('iconStacker.accent', 'Accent'), value: edited.accentColor, onChange: (v) => update(edited.id, { accentColor: v }), autoLabel: autoLabel, resetLabel: resetLabel }), hasText && (jsx(Swatch, { label: t('iconStacker.textColor', 'Text colour'), value: edited.textColor, onChange: (v) => update(edited.id, { textColor: v }), autoLabel: autoLabel, resetLabel: resetLabel }))] }), hasText && (jsxs(Fragment, { children: [jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.textSize', 'Text size') }), jsx("input", { type: "range", min: 3, max: 14, step: 0.5, value: textSize, onChange: (e) => update(edited.id, { textSize: Number(e.target.value) }) }), jsx("output", { children: textSize }), edited.textSize !== undefined && (jsx("button", { type: "button", className: "nice-icon-stacker__reset", onClick: () => update(edited.id, { textSize: undefined }), "aria-label": `${resetLabel}: ${t('iconStacker.textSize', 'Text size')}`, title: resetLabel, children: jsx(NtdClose, { size: 10 }) }))] }), jsxs("label", { className: "nice-icon-stacker__field", children: [jsx("span", { children: t('iconStacker.bind', 'Bind to') }), jsx("input", { type: "text", value: (_p = edited.textBinding) !== null && _p !== void 0 ? _p : '', "aria-invalid": bindingInvalid || undefined, title: t('iconStacker.bindHint', 'The name of the value the text shows, e.g. count — the text above is a sample'), onChange: (e) => update(edited.id, { textBinding: e.target.value.trim() || undefined }) })] })] }))] })] })] }), showCode && (jsxs("details", { className: "nice-icon-stacker__code", children: [jsx("summary", { children: t('iconStacker.code', 'JSX code') }), jsx("pre", { children: code }), jsxs("button", { type: "button", onClick: copy, children: [copied ? jsx(NtdCheck, { size: 14 }) : jsx(NtdCopy, { size: 14 }), ' ', copied
176
205
  ? t('iconStacker.copied', 'Copied')
177
- : t('iconStacker.copy', 'Copy the code')] })] })] }))] }));
206
+ : t('iconStacker.copy', 'Copy the code')] })] }))] }))] }));
178
207
  });
179
208
  if (process.env.NODE_ENV !== 'production') {
180
209
  NiceIconStacker.displayName = 'NiceIconStacker';
@@ -1,7 +1,8 @@
1
1
  export { AnimationController, InteractiveIcon, PRESET_INTERACTIONS, PRESET_SEQUENCES, createAnimationSequence, createClickAnimation, createHoverAnimation, createVisibilityAnimation, useAnimationSequence } from './animationControls.js';
2
2
  export { NiceIconPicker } from './NiceIconPicker.js';
3
+ export { NiceIconHtml, parseIconHtml } from './iconHtml.js';
3
4
  export { NiceIconStacker } from './NiceIconStacker.js';
4
- export { NiceIconStack, isValidTextBinding, niceIconStackCode, renderIconStack } from './iconStack.js';
5
+ export { NiceIconStack, addStackLayer, iconDisplayName, isValidTextBinding, niceIconStackCode, removeStackLayer, renderIconStack } from './iconStack.js';
5
6
  export { NtdIconMorph, NtdMorphPair, NtdPathMorph, useMorphState } from './NtdIconMorph.js';
6
7
  export { NtdBadge, NtdIconOverlay, NtdIconStack, NtdStatusDot } from './NtdIconBadge.js';
7
8
  export { SMIL_ANIMATION_TYPES, SmilAnimationWrapper, createSmilAnimationDef, generateSmilAnimation, isSmilSupported } from './smilAnimations.js';
@@ -2,7 +2,7 @@ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
2
  import { forwardRef, useId, useSyncExternalStore } from 'react';
3
3
  import { sharpenTree, roundTree, wireTree, MINI_SCALE } from './sharpen.js';
4
4
  import { generateSmilAnimation } from './smilAnimations.js';
5
- import { renderStackChildren, NTD_ICON_MARK } from './stacking.js';
5
+ import { BOX_PERFECT_STACK, renderStackChildren, NTD_ICON_MARK, PERFECT_STACK } from './stacking.js';
6
6
  import { SEMANTIC_COLOR_VARS, SEMANTIC_COLOR_DEFAULTS, SIZE_MAP, GRADIENT_PRESETS } from './types.js';
7
7
 
8
8
  /* ── Dark mode detection hook ───────────────────────── */
@@ -113,7 +113,15 @@ function renderCutoutShape(shape, fill, maskId) {
113
113
  }
114
114
  }
115
115
  function createIcon(options) {
116
+ var _a, _b, _c, _d;
116
117
  const { displayName, viewBox = '0 0 24 24', paths, textCenter = BOX_CENTER } = options;
118
+ const solidDuotone = (props) => paths.solid({ ...props, accentColor: props.secondaryColor, accentOpacity: 1 });
119
+ const perfect = {
120
+ x: (_a = options.perfectStackX) !== null && _a !== void 0 ? _a : textCenter[0],
121
+ y: (_b = options.perfectStackY) !== null && _b !== void 0 ? _b : textCenter[1],
122
+ rotation: (_c = options.perfectStackRotation) !== null && _c !== void 0 ? _c : BOX_PERFECT_STACK.rotation,
123
+ size: (_d = options.perfectStackSize) !== null && _d !== void 0 ? _d : BOX_PERFECT_STACK.size,
124
+ };
117
125
  const Icon = forwardRef(({ size = 'md', variant = 'solid', cutoutShape = 'rounded-square', color, lightColor, darkColor, primaryColor: propPrimaryColor = 'currentColor', secondaryColor, accentColor, primaryOpacity = 1, secondaryOpacity = 0.4, accentOpacity = 1, strokeWidth = 1, strokeLinecap: propLinecap, strokeLinejoin: propLinejoin, animation, animationDuration, smilAnimation, smilDuration = 1, smilRepeatCount = 'indefinite', smilEasing = 'ease-in-out', smilDelay = 0, gradient, gradientType = 'linear', gradientAngle = 135, gradientAnimation,
118
126
  // Transform props
119
127
  rotate, flipX, flipY, scale, transition, transformOrigin = 'center center',
@@ -156,10 +164,13 @@ function createIcon(options) {
156
164
  };
157
165
  // Resolve renderer with fallback chain. `wireframe` has no authored layer
158
166
  // at all — it is a mechanical re-draw of the full `solid` construction, so
159
- // it never indexes `paths`.
167
+ // it never indexes `paths`. A duotone left out is the solid with its details
168
+ // in secondary (1.3.8): the body keeps primary, the larger area.
160
169
  const renderer = variant === 'wireframe'
161
170
  ? paths.solid
162
- : ((_g = (_f = (_e = (_d = (_c = (_b = paths[variant]) !== null && _b !== void 0 ? _b : (variant === 'sharp' ? paths.solid : undefined)) !== null && _c !== void 0 ? _c : (variant === 'rounded' ? paths.solid : undefined)) !== null && _d !== void 0 ? _d : (variant === 'mini' ? paths.solid : undefined)) !== null && _e !== void 0 ? _e : (variant === '3d' ? paths.solid : undefined)) !== null && _f !== void 0 ? _f : (variant === 'vivid' ? paths.solid : undefined)) !== null && _g !== void 0 ? _g : paths.solid);
171
+ : variant === 'duotone' && !paths.duotone
172
+ ? solidDuotone
173
+ : ((_g = (_f = (_e = (_d = (_c = (_b = paths[variant]) !== null && _b !== void 0 ? _b : (variant === 'sharp' ? paths.solid : undefined)) !== null && _c !== void 0 ? _c : (variant === 'rounded' ? paths.solid : undefined)) !== null && _d !== void 0 ? _d : (variant === 'mini' ? paths.solid : undefined)) !== null && _e !== void 0 ? _e : (variant === '3d' ? paths.solid : undefined)) !== null && _f !== void 0 ? _f : (variant === 'vivid' ? paths.solid : undefined)) !== null && _g !== void 0 ? _g : paths.solid);
163
174
  // 3D variant uses a filter for depth effect
164
175
  const is3d = variant === '3d';
165
176
  const filterId = useId();
@@ -234,7 +245,7 @@ function createIcon(options) {
234
245
  accentColor: resolvedAccent,
235
246
  tileColor: gradient ? effectivePrimary : resolvedSecondary,
236
247
  strokeWidth,
237
- textCenter,
248
+ perfect,
238
249
  textColor,
239
250
  textSize,
240
251
  });
@@ -252,8 +263,10 @@ function createIcon(options) {
252
263
  }) })] }) })), smilAnimation ? (needsSmilScaleWrapper ? (jsxs("g", { transform: `translate(${center.x}, ${center.y})`, filter: is3d ? `url(#${filterId})` : undefined, children: [jsx("g", { transform: `translate(-${center.x}, -${center.y})`, children: iconContent }), smilAnimationElements] })) : (jsxs("g", { filter: is3d ? `url(#${filterId})` : undefined, children: [iconContent, smilAnimationElements] }))) : is3d ? (jsx("g", { filter: `url(#${filterId})`, children: iconContent })) : (iconContent)] }));
253
264
  });
254
265
  Icon.displayName = displayName;
255
- // lets a parent icon tell this one among its children (stacking, 1.3.5)
266
+ // lets a parent icon tell this one among its children (stacking, 1.3.5), and tells the stacker
267
+ // where a child of this one goes by default (1.3.8)
256
268
  Icon[NTD_ICON_MARK] = true;
269
+ Icon[PERFECT_STACK] = perfect;
257
270
  return Icon;
258
271
  }
259
272
 
@@ -0,0 +1,117 @@
1
+ import { jsx, Fragment } from 'react/jsx-runtime';
2
+ import { renderIconStack } from './iconStack.js';
3
+
4
+ /**
5
+ * An icon — or a stack of icons — kept as HTML (1.3.9): the `<svg>` NiceIconPicker draws, ready to
6
+ * store in a database and to show anywhere, even without React. What it was drawn from rides along
7
+ * in data attributes on the root, so the picker reads its own value back.
8
+ */
9
+ const ATTR_ICON = 'data-ntd-icon';
10
+ const ATTR_VARIANT = 'data-ntd-variant';
11
+ const ATTR_STACK = 'data-ntd-stack';
12
+ const ENTITIES = {
13
+ amp: '&',
14
+ quot: '"',
15
+ apos: "'",
16
+ '#39': "'",
17
+ lt: '<',
18
+ gt: '>',
19
+ };
20
+ /** The value of a data attribute of the root element (the first one in the markup). */
21
+ function readAttr(html, name) {
22
+ const hit = new RegExp(`\\s${name}="([^"]*)"`).exec(html);
23
+ return hit
24
+ ? hit[1].replace(/&(amp|quot|apos|#39|lt|gt);/g, (_, e) => ENTITIES[e])
25
+ : undefined;
26
+ }
27
+ function isLayer(value) {
28
+ const layer = value;
29
+ return (!!layer &&
30
+ typeof layer === 'object' &&
31
+ typeof layer.id === 'string' &&
32
+ typeof layer.icon === 'string');
33
+ }
34
+ /**
35
+ * Reads back what an icon's HTML was drawn from — the base icon and the stack. `null` for anything
36
+ * else: empty, plain text or HTML the picker did not write.
37
+ */
38
+ function parseIconHtml(html) {
39
+ if (!html) {
40
+ return null;
41
+ }
42
+ const icon = readAttr(html, ATTR_ICON);
43
+ if (!icon) {
44
+ return null;
45
+ }
46
+ const stack = readAttr(html, ATTR_STACK);
47
+ if (stack) {
48
+ try {
49
+ const parsed = JSON.parse(stack);
50
+ const layers = Array.isArray(parsed) ? parsed.filter(isLayer) : [];
51
+ if (layers.length > 0) {
52
+ return { icon: layers[0].icon, layers };
53
+ }
54
+ }
55
+ catch (_a) {
56
+ // a damaged stack still shows its base
57
+ }
58
+ }
59
+ const variant = readAttr(html, ATTR_VARIANT);
60
+ return { icon, layers: [{ id: '1', icon, ...(variant ? { variant } : {}) }] };
61
+ }
62
+ /** The data attributes that let the HTML of a stack be read back: the base, and the stack unless it is a plain icon. */
63
+ function iconHtmlAttributes(layers) {
64
+ const base = layers[0];
65
+ if (!base) {
66
+ return {};
67
+ }
68
+ const plain = layers.length === 1 &&
69
+ Object.entries(base).every(([key, value]) => value === undefined || key === 'id' || key === 'icon' || key === 'variant');
70
+ if (plain) {
71
+ return { [ATTR_ICON]: base.icon, ...(base.variant ? { [ATTR_VARIANT]: base.variant } : {}) };
72
+ }
73
+ return { [ATTR_ICON]: base.icon, [ATTR_STACK]: JSON.stringify(layers) };
74
+ }
75
+ /** djb2, base 36 — a short, stable name for a drawing. */
76
+ function hash(text) {
77
+ let h = 5381;
78
+ for (let i = 0; i < text.length; i++) {
79
+ h = ((h << 5) + h + text.charCodeAt(i)) | 0;
80
+ }
81
+ return (h >>> 0).toString(36);
82
+ }
83
+ /**
84
+ * Renames the ids inside an icon's markup (masks, gradients, clip paths) after the drawing itself.
85
+ * React's ids (`_r_3_`) are unique only within the page that drew them; pasted into another page they
86
+ * could hit an element of its own and borrow the wrong mask. Named after the drawing, two copies of
87
+ * one icon share ids that point at identical definitions.
88
+ */
89
+ function scopeIconHtmlIds(markup) {
90
+ const ids = [...new Set([...markup.matchAll(/\sid="([^"]+)"/g)].map((m) => m[1]))];
91
+ if (ids.length === 0) {
92
+ return markup;
93
+ }
94
+ const index = new Map(ids.map((id, i) => [id, i]));
95
+ const rename = (fn) => markup
96
+ .replace(/(\sid=")([^"]+)(")/g, (all, a, id, b) => index.has(id) ? a + fn(id) + b : all)
97
+ .replace(/url\(#([^)]+)\)/g, (all, id) => (index.has(id) ? `url(#${fn(id)})` : all))
98
+ .replace(/(href=")#([^"]+)(")/g, (all, a, id, b) => index.has(id) ? `${a}#${fn(id)}${b}` : all);
99
+ const name = hash(rename((id) => `#${index.get(id)}`));
100
+ return rename((id) => `ntd-${name}-${index.get(id)}`);
101
+ }
102
+ /**
103
+ * NiceIconHtml (1.3.9) — shows an icon kept as HTML in a React page by drawing it again from its
104
+ * data attributes; the markup itself is never injected, so HTML from a database cannot run anything.
105
+ * A plain export name (`'NtdStar'`) works too. The rest of the props go to the base icon.
106
+ */
107
+ function NiceIconHtml({ html, icons, values, fallback = null, ...baseProps }) {
108
+ var _a;
109
+ const source = (_a = parseIconHtml(html)) !== null && _a !== void 0 ? _a : (html && !html.includes('<') ? { layers: [{ id: '1', icon: html }] } : null);
110
+ const drawn = source ? renderIconStack(source.layers, icons, { baseProps, values }) : null;
111
+ return jsx(Fragment, { children: drawn !== null && drawn !== void 0 ? drawn : fallback });
112
+ }
113
+ if (process.env.NODE_ENV !== 'production') {
114
+ NiceIconHtml.displayName = 'NiceIconHtml';
115
+ }
116
+
117
+ export { NiceIconHtml, iconHtmlAttributes, parseIconHtml, scopeIconHtmlIds };
@@ -9,6 +9,19 @@ import { createIcon } from './createIcon.js';
9
9
  function detailColor({ variant, secondaryColor, accentColor }) {
10
10
  return variant === 'cutout' ? accentColor : secondaryColor;
11
11
  }
12
+ /**
13
+ * A duotone renderer with its two colours swapped, at full strength (1.3.8) — for a duotone that
14
+ * drew its larger area in secondary (a pale body under a primary outline): the body turns
15
+ * primary, the outline and the details secondary.
16
+ */
17
+ function swapDuotone(render) {
18
+ return (props) => render({
19
+ ...props,
20
+ primaryColor: props.secondaryColor,
21
+ secondaryColor: props.primaryColor,
22
+ secondaryOpacity: 1,
23
+ });
24
+ }
12
25
  /**
13
26
  * `content` drawn only inside `shape` — for accent lines that read as a cut through a shape (a
14
27
  * pencil's band, a calendar's header line, an envelope's flap): clipped, they meet the shape's
@@ -40,6 +53,10 @@ function bellIcon(displayName, ringing) {
40
53
  const parts = ({ primaryColor, strokeWidth }, detail, rings, ringsOpacity = 1) => (jsxs(Fragment, { children: [jsx("path", { d: BELL, fill: primaryColor }), jsx("path", { d: BELL_CLAPPER, fill: detail }), ringing && (jsx("path", { d: BELL_RINGS, stroke: rings, strokeWidth: strokeWidth, opacity: ringsOpacity }))] }));
41
54
  return createIcon({
42
55
  displayName,
56
+ // stacked icons and text go into the bell's body, above the clapper (1.3.8)
57
+ perfectStackX: 12,
58
+ perfectStackY: 10.5,
59
+ perfectStackSize: 0.4,
43
60
  paths: {
44
61
  solid: (props) => parts(props, props.primaryColor, props.primaryColor),
45
62
  outline: ({ primaryColor, strokeWidth }) => (jsx("path", { d: `${BELL}${BELL_CLAPPER_LINE}${ringing ? BELL_RINGS : ''}`, stroke: primaryColor, strokeWidth: strokeWidth, fill: "none" })),
@@ -58,20 +75,24 @@ const PAPER_FOLD_SHARP = 'M12 2v8h8z';
58
75
  * A paper icon — NtdFile, and every document drawn on the same page (NtdFileText, NtdInvoice,
59
76
  * NtdContract, …), so their pages and folds match. The fold is secondary when the page is filled;
60
77
  * `text` is the document's writing, a path of strokes kept below the fold (y ≥ 11, x 7–17),
61
- * drawn in the accent colour on a filled page and in primary on a stroked one.
78
+ * drawn in the accent colour on a filled page (secondary in duotone) and in primary on a stroked one.
62
79
  */
63
80
  function paperIcon(displayName, text = '') {
64
81
  return createIcon({
65
82
  displayName,
83
+ // stacked icons and text go onto the page below the fold (1.3.8), the same on every paper
84
+ perfectStackX: 12,
85
+ perfectStackY: 14,
86
+ perfectStackSize: 0.5,
66
87
  paths: {
67
88
  solid: ({ primaryColor, secondaryColor, accentColor, accentOpacity }) => (jsxs(Fragment, { children: [jsx("path", { d: PAPER, fill: primaryColor }), jsx("path", { d: PAPER_FOLD, fill: secondaryColor }), text && (jsx("path", { d: text, stroke: accentColor, strokeOpacity: accentOpacity, strokeWidth: "1.5", strokeLinecap: "round", fill: "none" }))] })),
68
89
  // square at every corner, the fold included — the derived `sharp` keeps a path's arcs round
69
90
  sharp: ({ primaryColor, secondaryColor, accentColor, accentOpacity }) => (jsxs(Fragment, { children: [jsx("path", { d: PAPER_SHARP, fill: primaryColor }), jsx("path", { d: PAPER_FOLD_SHARP, fill: secondaryColor }), text && (jsx("path", { d: text, stroke: accentColor, strokeOpacity: accentOpacity, strokeWidth: "1.5", fill: "none" }))] })),
70
91
  outline: ({ primaryColor, strokeWidth }) => (jsx("path", { d: `${PAPER}${PAPER_FOLD_LINE}${text}`, stroke: primaryColor, strokeWidth: strokeWidth, fill: "none" })),
71
- duotone: ({ primaryColor, secondaryColor, secondaryOpacity, strokeWidth }) => (jsxs(Fragment, { children: [jsx("path", { d: PAPER, fill: secondaryColor, opacity: secondaryOpacity }), jsx("path", { d: PAPER_FOLD_SHARP, fill: primaryColor, opacity: secondaryOpacity + 0.1 }), jsx("path", { d: `${PAPER}${PAPER_FOLD_LINE}${text}`, stroke: primaryColor, strokeWidth: strokeWidth, fill: "none" })] })),
92
+ // duotone (1.3.8): createIcon's default — the solid page, its writing in secondary like the fold
72
93
  vivid: ({ primaryColor, secondaryColor }) => (jsxs(Fragment, { children: [jsx("path", { d: PAPER, fill: primaryColor }), jsx("path", { d: PAPER, fill: "white", opacity: "0.1" }), jsx("path", { d: PAPER_FOLD, fill: secondaryColor }), text && (jsx("path", { d: text, stroke: "white", strokeOpacity: "0.9", strokeWidth: "1.5", strokeLinecap: "round", fill: "none" }))] })),
73
94
  },
74
95
  });
75
96
  }
76
97
 
77
- export { bellIcon, detailColor, paperIcon, within };
98
+ export { bellIcon, detailColor, paperIcon, swapDuotone, within };