@uniweb/core 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/icon-corpus.js +34 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/core",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
@@ -52,19 +52,51 @@
52
52
  */
53
53
  export const DEFAULT_ICON_BASE = 'https://uniweb.github.io/icons'
54
54
 
55
+ /**
56
+ * Families whose own sites spell a digit off by a hyphen (Lucide's `building-2` and `grid-2x2`,
57
+ * Heroicons' `bars-3`, Feather's `bar-chart-2`), where the corpus, named after react-icons, does
58
+ * not (`building2`, `grid2-x2`, `bars3`, `bar-chart2`). An author copies a name from the family's
59
+ * site, so for these the corpus answers that spelling too.
60
+ *
61
+ * ⛔ Only families the rule leaves every corpus name of unchanged, since the writer composes its
62
+ * paths with it too. Material's `3d-rotation` and Tabler's `cube3d-sphere` keep a letter after a
63
+ * digit unhyphenated, so the rule would move them. `_contracts/icon-corpus-names.test.js` holds
64
+ * these four to it, over every name their manifests list.
65
+ */
66
+ const UPSTREAM_SPELLED = new Set(['lu', 'hi', 'hi2', 'fi'])
67
+
68
+ /**
69
+ * An icon's name as the corpus spells it. In a family above, a digit takes no hyphen before it,
70
+ * and a letter after a digit takes one: `building-2` → `building2`, `grid-2x2` → `grid2-x2`. A
71
+ * name the corpus already spells comes back unchanged.
72
+ *
73
+ * ⛔ *Until 2026-10-24 a name was taken as written, so the 107 Lucide icons whose names hold a
74
+ * digit answered 404 to the spelling on Lucide's own site.*
75
+ *
76
+ * @param {string} family - short family code
77
+ * @param {string} name - icon id as written
78
+ * @returns {string}
79
+ */
80
+ export function corpusIconName(family, name) {
81
+ const written = String(name ?? '')
82
+ if (!UPSTREAM_SPELLED.has(family)) return written
83
+ return written.replace(/-(?=\d)/g, '').replace(/(\d)([a-z])/g, '$1-$2')
84
+ }
85
+
55
86
  /**
56
87
  * The corpus path for one icon, relative to any origin serving it.
57
88
  *
58
89
  * `{family}/{family}-{name}.svg` — the family repeats deliberately: the
59
90
  * directory groups, and the filename prefix keeps ids unique across families so
60
- * a name alone is never ambiguous.
91
+ * a name alone is never ambiguous. The name is the corpus's spelling of it
92
+ * (`corpusIconName`).
61
93
  *
62
94
  * @param {string} family - short family code (`lu`, `hi2`, `fa6`)
63
95
  * @param {string} name - icon id within that family (`house`, `a-arrow-down`)
64
96
  * @returns {string} e.g. `lu/lu-house.svg`
65
97
  */
66
98
  export function iconPath(family, name) {
67
- return `${family}/${family}-${name}.svg`
99
+ return `${family}/${family}-${corpusIconName(family, name)}.svg`
68
100
  }
69
101
 
70
102
  /**