@massimo-cassandro/minimo 1.41.3 → 1.41.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +12 -12
  2. package/charts/src/node-helpers/create-svg-canvas-node.mjs +2 -2
  3. package/charts/src/node-helpers/svg-text-to-path.js +9 -9
  4. package/charts/src/rating-display/index.js +1 -1
  5. package/charts/src/rating-display/ratindDisplayAnimation.js +3 -3
  6. package/design-tokens/README.md +2 -2
  7. package/design-tokens/_src/_readme.md +26 -26
  8. package/dev-tools/README.md +16 -16
  9. package/dev-tools/create-favicons/README.md +31 -31
  10. package/dev-tools/create-favicons/src/create-ico.mjs +2 -2
  11. package/dev-tools/create-favicons/src/default-params.mjs +1 -1
  12. package/dev-tools/create-favicons/src/init.mjs +1 -1
  13. package/dev-tools/design-tokens-builder/README.md +102 -102
  14. package/dev-tools/design-tokens-builder/build-tokens-src/build-source-modes.mjs +85 -73
  15. package/dev-tools/design-tokens-builder/build-tokens-src/config.mjs +109 -85
  16. package/dev-tools/design-tokens-builder/build-tokens-src/formats/css.mjs +113 -90
  17. package/dev-tools/design-tokens-builder/build-tokens-src/formats/json.mjs +107 -95
  18. package/dev-tools/design-tokens-builder/build-tokens-src/legacy-tokens-parser.mjs +71 -64
  19. package/dev-tools/design-tokens-builder/build-tokens-src/light-dark.mjs +75 -65
  20. package/dev-tools/design-tokens-builder/build-tokens-src/merge-css.mjs +113 -102
  21. package/dev-tools/design-tokens-builder/build-tokens-src/platforms.mjs +36 -30
  22. package/dev-tools/design-tokens-builder/build-tokens-src/resolve-source-paths.mjs +15 -13
  23. package/dev-tools/design-tokens-builder/build-tokens-src/source-prefixes.mjs +44 -42
  24. package/dev-tools/design-tokens-builder/build-tokens-src/source-transforms.mjs +89 -83
  25. package/dev-tools/design-tokens-builder/build-tokens-src/token-rename-parser.mjs +99 -86
  26. package/dev-tools/design-tokens-builder/build-tokens-src/transforms.mjs +64 -48
  27. package/dev-tools/design-tokens-builder/build-tokens.mjs +80 -68
  28. package/dev-tools/design-tokens-builder/check-unresolved-custom-props.mjs +103 -77
  29. package/dev-tools/design-tokens-builder/tokens-config-sample.mjs +275 -238
  30. package/dev-tools/find-orphan-css-classes/find-orphan-css-classes.mjs +2 -2
  31. package/dev-tools/starter-kit/source_files/app/CLAUDE.md +4 -2
  32. package/dev-tools/starter-kit/source_files/app/index.css +10 -0
  33. package/dev-tools/starter-kit/source_files/app/index.js +1 -1
  34. package/dev-tools/starter-kit/source_files/root/_sf/controller/ImgViewerController.php +3 -3
  35. package/dev-tools/starter-kit/source_files/root/_sf/controller/ViewerController.php +2 -2
  36. package/dev-tools/starter-kit/source_files/root/stylelint.config.mjs +1 -1
  37. package/dev-tools/starter-kit/source_files/root/webpack-config-modules/css-rules.mjs +1 -1
  38. package/dev-tools/starter-kit/starter-install.sh +2 -2
  39. package/dev-tools/stylelint-config/README.md +7 -7
  40. package/dev-tools/svg-icons-tools/README.md +32 -32
  41. package/dev-tools/svg-icons-tools/src/config-manager.mjs +1 -1
  42. package/dev-tools/svg-icons-tools/src/default-config.mjs +118 -118
  43. package/dev-tools/svg-icons-tools/src/jsx-icon-file-builder.mjs +24 -24
  44. package/dev-tools/svg-icons-tools/src/parse-svg-filename.mjs +3 -3
  45. package/dev-tools/svg-icons-tools/src/parse-svg-files.mjs +1 -1
  46. package/dev-tools/svg-icons-tools/src/parse-svg-markup.mjs +4 -4
  47. package/dev-tools/svg-icons-tools/src/svg-to-jsx.mjs +2 -2
  48. package/dev-tools/svg-icons-tools/src/svg-to-optimized.mjs +2 -2
  49. package/dev-tools/svg-icons-tools/src/svg-to-symbols.mjs +2 -2
  50. package/dev-tools/upd@m/README.md +1 -1
  51. package/dev-tools/upd@m/index.mjs +1 -1
  52. package/dev-tools/update-version/README.md +9 -9
  53. package/index.js +1 -0
  54. package/package.json +3 -1
  55. package/snippets/unsplash-browser-app/README.md +1 -1
  56. package/snippets/unsplash-browser-app/unsplash-utilities.js +9 -9
  57. package/src/components/autocomplete/README.md +3 -3
  58. package/src/components/autocomplete/autocomplete-engine.js +75 -63
  59. package/src/components/autocomplete/check-autocomplete.js +3 -3
  60. package/src/components/dismiss-alerts.js +3 -3
  61. package/src/components/form-reset-submit.js +6 -6
  62. package/src/components/inner-nav/inner-nav.js +2 -2
  63. package/src/components/modal-alert/modal-alert.js +67 -65
  64. package/src/components/modal-alert/modal-alert.minimo.tokens.mjs +1 -1
  65. package/src/components/modal-popup/modal-popup.js +56 -56
  66. package/src/components/overlay/overlay.js +3 -3
  67. package/src/components/sf-macro/readme.md +1 -1
  68. package/src/components/sf-macro/sf-macro.js +27 -23
  69. package/src/components/slide-up-down-toggle/slide-up-down-toggle.js +83 -79
  70. package/src/components/slide-up-down-toggle/slide-up-down-toggle.module.css +44 -44
  71. package/src/components/snackbar/snackbar.js +19 -19
  72. package/src/components/spinner/spinner.js +3 -3
  73. package/src/components/unsplash-page/README.md +8 -8
  74. package/src/components/unsplash-page/fetch-unsplash-data.js +3 -3
  75. package/src/components/unsplash-page/unsplash-page.js +33 -33
  76. package/src/components/unsplash-page/unsplash-page.module.css +1 -1
  77. package/src/css/alerts.css +2 -2
  78. package/src/css/forms/forms.css +4 -4
  79. package/src/css/forms/validation.css +1 -1
  80. package/src/css/margin-padding-media.css +4 -4
  81. package/src/css/margin-padding.css +4 -4
  82. package/src/css/reset.css +11 -11
  83. package/src/icons/read-me.md +1 -1
  84. package/src/minimo.css +3 -9
  85. package/src/utilities/better-text-with-places.js +105 -105
  86. package/src/utilities/better-text.js +42 -35
  87. package/src/utilities/classnames.js +8 -8
  88. package/src/utilities/cookies.js +6 -6
  89. package/src/utilities/create-id.js +3 -3
  90. package/src/utilities/disable-btns-on-submit.js +2 -2
  91. package/src/utilities/dom-builder/dom-builder.js +89 -86
  92. package/src/utilities/dom-builder/domBuilderBasicSetup.js +9 -9
  93. package/src/utilities/dom-builder/parseDomString.js +23 -23
  94. package/src/utilities/dom-builder-helpers/README.md +2 -2
  95. package/src/utilities/dom-builder-helpers/form-tags.js +100 -100
  96. package/src/utilities/dom-builder-helpers/picture-tag.js +39 -39
  97. package/src/utilities/enable-submit-btns.js +1 -1
  98. package/src/utilities/escape-html.js +2 -2
  99. package/src/utilities/generate-pwd.js +4 -4
  100. package/src/utilities/linked-dates.js +13 -13
  101. package/src/utilities/parse-file-size.js +6 -6
  102. package/src/utilities/random-id.js +3 -3
  103. package/src/utilities/relative-date.js +40 -40
  104. package/src/utilities/sentence-case.js +1 -1
  105. package/src/utilities/strip-tags.js +1 -1
  106. package/src/utilities/title-case.js +1 -1
  107. package/src/utilities/truncate-string.js +5 -5
  108. package/src/utilities/validation-error-class.js +12 -12
  109. package/src/web-components/json-table/json-table-component.js +123 -121
  110. package/src/web-components/json-table/json-table-component.module.css +6 -6
  111. package/src/web-components/json-table/json-table.minimo.tokens.mjs +6 -6
  112. package/src/web-components/json-table/readme.md +76 -110
  113. package/src/web-components/json-table/src/cell-content.js +25 -25
  114. package/src/web-components/json-table/src/content-utils.js +21 -21
  115. package/src/web-components/json-table/src/data-types.js +32 -32
  116. package/src/web-components/json-table/src/defaults.js +230 -191
  117. package/src/web-components/json-table/src/get-data.js +55 -38
  118. package/src/web-components/json-table/src/icons.js +17 -17
  119. package/src/web-components/json-table/src/info-section.js +18 -18
  120. package/src/web-components/json-table/src/main-builder.js +45 -45
  121. package/src/web-components/json-table/src/pagination.js +32 -32
  122. package/src/web-components/json-table/src/parse-cols.js +18 -18
  123. package/src/web-components/json-table/src/parse-rows.js +17 -17
  124. package/src/web-components/json-table/src/resolve-params.js +53 -41
  125. package/src/web-components/json-table/src/search.js +13 -13
  126. package/src/web-components/json-table/src/sorting.js +20 -20
  127. package/src/web-components/json-table/src/table-body.js +13 -13
  128. package/src/web-components/json-table/src/table-builder.js +34 -34
  129. package/src/web-components/json-table/src/table-tfoot.js +8 -8
  130. package/src/web-components/json-table/src/table-thead.js +21 -21
  131. package/src/web-components/json-table/src/update-info.js +11 -11
  132. package/types/classes.d.ts +2 -2
  133. package/types/global.d.ts +18 -12
@@ -2,21 +2,23 @@
2
2
  /// <reference types="node" />
3
3
  /* eslint-disable no-console */
4
4
 
5
- // build-tokens.mjs
6
- // Entry point: imports modules, runs the build, lints the CSS output, prints the log.
7
- //
8
- // Project structure:
9
- // build-tokens.mjs <- this file
10
- // build-tokens-src/config.mjs <- reads --config flag and resolves all paths
11
- // build-tokens-src/transforms.mjs <- registers custom Style Dictionary transforms
12
- // build-tokens-src/formats/css.mjs <- registers the css/variables-sorted format
13
- // build-tokens-src/formats/json.mjs <- registers the json/tokens format, exports helpers
14
- // build-tokens-src/platforms.mjs <- builds the platforms object (css + optional json)
15
- // build-tokens-src/build-source-modes.mjs <- alternative build path used when sourceModes is set
16
- // build-tokens-src/merge-css.mjs <- supports the mergeCustomProps option (flat and per-mode)
17
- // build-tokens-src/source-prefixes.mjs <- supports `{ src, prefix }` entries in source/sourceModes
18
- // build-tokens-src/source-transforms.mjs <- supports `{ src, transform }` entries in source/sourceModes
19
- // build-tokens-src/token-rename-parser.mjs <- parser applying the `transform` rename maps
5
+ /*
6
+ build-tokens.mjs
7
+ Entry point: importa i moduli, esegue la build, esegue il lint dell'output CSS, stampa il log.
8
+
9
+ Struttura del progetto:
10
+ build-tokens.mjs <- questo file
11
+ build-tokens-src/config.mjs <- legge il flag --config e risolve tutti i percorsi
12
+ build-tokens-src/transforms.mjs <- registra le transform personalizzate di Style Dictionary
13
+ build-tokens-src/formats/css.mjs <- registra il format css/variables-sorted
14
+ build-tokens-src/formats/json.mjs <- registra il format json/tokens, esporta gli helper
15
+ build-tokens-src/platforms.mjs <- costruisce l'oggetto platforms (css + json opzionale)
16
+ build-tokens-src/build-source-modes.mjs <- percorso di build alternativo usato quando sourceModes è impostato
17
+ build-tokens-src/merge-css.mjs <- supporta l'opzione mergeCustomProps (flat e per modalità)
18
+ build-tokens-src/source-prefixes.mjs <- supporta le voci `{ src, prefix }` in source/sourceModes
19
+ build-tokens-src/source-transforms.mjs <- supporta le voci `{ src, transform }` in source/sourceModes
20
+ build-tokens-src/token-rename-parser.mjs <- parser che applica le mappe di rinomina `transform`
21
+ */
20
22
 
21
23
  import StyleDictionary from 'style-dictionary';
22
24
  import * as path from 'node:path';
@@ -25,7 +27,7 @@ import { homedir } from 'node:os';
25
27
  import stylelint from 'stylelint';
26
28
  import { pathToFileURL } from 'node:url';
27
29
 
28
- // ── 1. Configuration (args + resolved paths) ────────────────────────────────
30
+ // ── 1. Configurazione (argomenti + percorsi risolti) ────────────────────────
29
31
  import {
30
32
  configAbsPath,
31
33
  buildPath,
@@ -48,29 +50,33 @@ import {
48
50
  customPropsSelector,
49
51
  } from './build-tokens-src/config.mjs';
50
52
 
51
- // ── 2. Custom transforms ─────────────────────────────────────────────────────
53
+ // ── 2. Transform personalizzate ──────────────────────────────────────────────
52
54
  import './build-tokens-src/transforms.mjs';
53
55
 
54
- // ── 2b. Legacy token syntax bridge ───────────────────────────────────────────
55
- // Converts legacy (non-DTCG, e.g. Open Props) .json/.jsonc source files to
56
- // DTCG v5 syntax at parse time — see build-tokens-src/legacy-tokens-parser.mjs.
56
+ // ── 2b. Bridge per la sintassi legacy dei token ──────────────────────────────
57
+ // Converte i file sorgente .json/.jsonc legacy (non DTCG, ad es. Open Props) alla
58
+ // sintassi DTCG v5 in fase di parsing — vedi build-tokens-src/legacy-tokens-parser.mjs.
57
59
  import { LEGACY_TOKENS_PARSER_NAME, registerLegacyTokensParser } from './build-tokens-src/legacy-tokens-parser.mjs';
58
60
  registerLegacyTokensParser();
59
61
 
60
- // ── 2c. Per-source custom property prefixes ──────────────────────────────────
61
- // Expands the `{ src, prefix }` entries of source/sourceModes into the file ->
62
- // prefix map read by the name/kebab-prefixed transform (needs the legacy
63
- // parser above, to load legacy .json sources) — see source-prefixes.mjs.
62
+ // ── 2c. Prefissi delle custom properties per sorgente ────────────────────────
63
+ /*
64
+ Espande le voci `{ src, prefix }` di source/sourceModes nella mappa file ->
65
+ prefisso letta dalla transform name/kebab-prefixed (richiede il parser legacy
66
+ qui sopra, per caricare le sorgenti .json legacy) — vedi source-prefixes.mjs.
67
+ */
64
68
  import { registerSourcePrefixes } from './build-tokens-src/source-prefixes.mjs';
65
69
  await registerSourcePrefixes(prefixedSources);
66
70
 
67
- // ── 2d. Per-source token rename maps ─────────────────────────────────────────
68
- // Expands the `{ src, transform }` entries of source/sourceModes into the
69
- // file -> rename-map read by the token-rename parser, and registers that
70
- // parser (only if at least one file actually has a transform) — see
71
- // source-transforms.mjs / token-rename-parser.mjs. `parserNames` is reused
72
- // below and passed down to buildSourceModes() so every Style Dictionary
73
- // instance opts in consistently.
71
+ // ── 2d. Mappe di rinomina dei token per sorgente ─────────────────────────────
72
+ /*
73
+ Espande le voci `{ src, transform }` di source/sourceModes nella mappa
74
+ file -> rinomina letta dal parser di rinomina dei token, e registra quel
75
+ parser (solo se almeno un file ha effettivamente una transform) — vedi
76
+ source-transforms.mjs / token-rename-parser.mjs. `parserNames` viene riutilizzato
77
+ più sotto e passato a buildSourceModes() in modo che ogni istanza di
78
+ Style Dictionary lo adotti in modo coerente.
79
+ */
74
80
  import { registerSourceTransforms, transformedFilesPattern, hasRegisteredTransforms } from './build-tokens-src/source-transforms.mjs';
75
81
  import {
76
82
  TOKEN_RENAME_PARSER_NAME,
@@ -83,34 +89,36 @@ const tokenRenamePattern = transformedFilesPattern();
83
89
  if (tokenRenamePattern) registerTokenRenameParser(tokenRenamePattern);
84
90
  registerTokenRenamePreprocessor();
85
91
  const parserNames = [LEGACY_TOKENS_PARSER_NAME, ...(hasRegisteredTransforms() ? [TOKEN_RENAME_PARSER_NAME] : [])];
86
- // Rewrites {references} to any renamed token's OLD path, tree-wide, once all
87
- // files are merged (see registerTokenRenamePreprocessor() above).
92
+ // Riscrive i {riferimenti} al VECCHIO percorso di ogni token rinominato, in tutto l'albero,
93
+ // una volta uniti tutti i file (vedi registerTokenRenamePreprocessor() qui sopra).
88
94
  const preprocessorNames = hasRegisteredTransforms() ? [TOKEN_RENAME_PREPROCESSOR_NAME] : [];
89
95
 
90
- // ── 3. CSS format ─────────────────────────────────────────────────────────────
91
- // customPropsCount is updated by the format at render time
92
- // loadExistingCustomProps supports the mergeCustomProps option (see below)
96
+ // ── 3. Format CSS ─────────────────────────────────────────────────────────────
97
+ // customPropsCount viene aggiornato dal format al momento del rendering
98
+ // loadExistingCustomProps supporta l'opzione mergeCustomProps (vedi sotto)
93
99
  import { customPropsCount } from './build-tokens-src/formats/css.mjs';
94
100
  import { loadExistingCustomProps } from './build-tokens-src/merge-css.mjs';
95
101
 
96
- // ── 4. JSON format ────────────────────────────────────────────────────────────
102
+ // ── 4. Format JSON ────────────────────────────────────────────────────────────
97
103
  import { buildJsonFiles, collectConcreteFilePaths } from './build-tokens-src/formats/json.mjs';
98
104
 
99
- // ── 5. Platforms builder ──────────────────────────────────────────────────────
105
+ // ── 5. Builder delle platform ─────────────────────────────────────────────────
100
106
  import { buildPlatforms } from './build-tokens-src/platforms.mjs';
101
107
 
102
- // ── 5b. sourceModes builder (alternative to the single-source build below) ──
108
+ // ── 5b. Builder sourceModes (alternativa alla build a sorgente singola più sotto) ──
103
109
  import { buildSourceModes } from './build-tokens-src/build-source-modes.mjs';
104
110
 
105
- // ── 6. Clean json output directory ───────────────────────────────────────────
106
- // Remove only previously generated *.json/*.jsonc files, so that tokens
107
- // removed from the source are not left behind as stale artefacts, while any
108
- // other file placed in jsonBuildPath by the user (e.g. a README) is left
109
- // untouched. Files are written flat in jsonBuildPath (no subdirectories), so
110
- // only its top level is scanned. Runs regardless of sourceModes.
111
+ // ── 6. Pulizia della directory di output json ────────────────────────────────
112
+ /*
113
+ Rimuove solo i file *.json/*.jsonc generati in precedenza, in modo che i token
114
+ rimossi dalla sorgente non restino come artefatti obsoleti, lasciando intatto
115
+ ogni altro file inserito dall'utente in jsonBuildPath (ad es. un README). I file
116
+ vengono scritti nella stessa cartella jsonBuildPath (senza sottocartelle), quindi
117
+ viene analizzato solo il suo primo livello. Viene eseguito a prescindere da sourceModes.
118
+ */
111
119
  if (jsonBuildPath) {
112
- // Local const: narrowing of the imported `jsonBuildPath` binding is lost
113
- // inside the .map() callback below.
120
+ // Costante locale: il narrowing del binding importato `jsonBuildPath` si perde
121
+ // dentro la callback .map() qui sotto.
114
122
  const jsonDir = jsonBuildPath;
115
123
  const { readdir, rm, mkdir } = await import('fs/promises');
116
124
  const existingEntries = await readdir(jsonDir, { withFileTypes: true }).catch(() => []);
@@ -123,15 +131,15 @@ if (jsonBuildPath) {
123
131
  }
124
132
 
125
133
  // ── 7. Build ──────────────────────────────────────────────────────────────────
126
- // concreteFilePaths / modeResult are used below in the log section (10).
134
+ // concreteFilePaths / modeResult sono usati più sotto nella sezione di log (10).
127
135
  /** @type {string[]} */
128
136
  let concreteFilePaths = [];
129
137
  /** @type {Awaited<ReturnType<typeof buildSourceModes>>|null} */
130
138
  let modeResult = null;
131
139
 
132
140
  if (sourceModes) {
133
- // sourceModes build: one StyleDictionary instance per mode, composed into
134
- // a single destFile — see build-tokens-src/build-source-modes.mjs.
141
+ // Build con sourceModes: un'istanza di StyleDictionary per modalità, composte in
142
+ // un unico destFile — vedi build-tokens-src/build-source-modes.mjs.
135
143
  modeResult = await buildSourceModes({
136
144
  sourceModes,
137
145
  baseMode: sourceModesBase,
@@ -152,28 +160,32 @@ if (sourceModes) {
152
160
  });
153
161
 
154
162
  } else {
155
- // Single-source build (default).
163
+ // Build a sorgente singola (default).
156
164
 
157
- // Pre-existing custom properties (mergeCustomProps option): read before
158
- // Style Dictionary runs, since it overwrites the destination file. The
159
- // css/variables-sorted format (formats/css.mjs) merges these values in —
160
- // pre-existing values take priority — right before serialising the final
161
- // CSS output. See merge-css.mjs.
165
+ /*
166
+ Custom properties preesistenti (opzione mergeCustomProps): lette prima
167
+ che Style Dictionary venga eseguito, perché sovrascrive il file di destinazione. Il
168
+ format css/variables-sorted (formats/css.mjs) vi unisce questi valori —
169
+ i valori preesistenti hanno priorità — subito prima di serializzare l'output
170
+ CSS finale. Vedi merge-css.mjs.
171
+ */
162
172
  if (mergeCustomProps) {
163
173
  loadExistingCustomProps(path.join(buildPath, destFile), mergeCustomProps);
164
174
  }
165
175
 
166
- // Collect concrete source file paths (multi-file JSON mode only). Source
167
- // entries may be glob patterns. SD expands them internally and stores the
168
- // concrete path in token.filePath. We need those concrete paths to build
169
- // the per-file descriptors for the json platform.
170
- //
171
- // SD v5 lazy-loads sources: `await sd.hasInitialized` triggers loading;
172
- // after that sd.allTokens is a plain synchronous array with filePath populated.
173
- //
174
- // In single-file mode (jsonDestFile is set) we skip this step entirely.
175
- // source is only null when sourceModes is set (see config.mjs); this
176
- // branch runs exclusively when sourceModes is not set.
176
+ /*
177
+ Raccoglie i percorsi dei file sorgente concreti (solo modalità JSON multi-file). Le
178
+ voci di source possono essere pattern glob. SD li espande internamente e memorizza il
179
+ percorso concreto in token.filePath. Servono questi percorsi concreti per costruire
180
+ i descrittori per file per la platform json.
181
+
182
+ SD v5 carica le sorgenti in modo lazy: `await sd.hasInitialized` attiva il caricamento;
183
+ dopo, sd.allTokens è un normale array sincrono con filePath popolato.
184
+
185
+ In modalità file singolo (jsonDestFile è impostato) questo passaggio viene saltato del tutto.
186
+ source è null solo quando sourceModes è impostato (vedi config.mjs); questo
187
+ ramo viene eseguito esclusivamente quando sourceModes non è impostato.
188
+ */
177
189
  const singleSource = /** @type {string[]} */ (source);
178
190
 
179
191
  if (jsonBuildPath && !jsonDestFile) {
@@ -210,7 +222,7 @@ if (sourceModes) {
210
222
  await sd.buildAllPlatforms();
211
223
  }
212
224
 
213
- // ── 8. CSS lint ───────────────────────────────────────────────────────────────
225
+ // ── 8. Lint CSS ───────────────────────────────────────────────────────────────
214
226
  const stylelintConfig = await import(pathToFileURL(stylelintConfigPath).href).then(m => m.default);
215
227
 
216
228
 
@@ -3,14 +3,16 @@
3
3
 
4
4
  /* eslint-disable no-console */
5
5
 
6
- // check-unresolved-custom-props.mjs
7
- // Scans CSS files in the configured directory and reports:
8
- // - unresolved properties: custom property references (var(--...)) that
9
- // are not defined in the generated token file
10
- // - unused properties: custom properties defined in the generated token
11
- // file but never referenced via var() in any scanned CSS file
12
- //
13
- // Usage: node check-unresolved-custom-props.mjs --config ./path/to/config.mjs
6
+ /*
7
+ check-unresolved-custom-props.mjs
8
+ Analizza i file CSS nella directory configurata e segnala:
9
+ - proprietà non risolte: riferimenti a custom properties (var(--...)) che
10
+ non sono definite nel file dei token generato
11
+ - proprietà non usate: custom properties definite nel file dei token
12
+ generato ma mai referenziate tramite var() in alcun file CSS analizzato
13
+
14
+ Utilizzo: node check-unresolved-custom-props.mjs --config ./path/to/config.mjs
15
+ */
14
16
 
15
17
 
16
18
  /* globals process */
@@ -57,30 +59,34 @@ if (!configArgPath) {
57
59
  const absoluteConfigPath = path.resolve(process.cwd(), configArgPath);
58
60
  const configDir = path.dirname(absoluteConfigPath);
59
61
 
60
- // ---------------------------------------------------------------------------
61
- // 2. Main
62
- // ---------------------------------------------------------------------------
62
+ /*
63
+ ---------------------------------------------------------------------------
64
+ 2. Main
65
+ ---------------------------------------------------------------------------
66
+ */
63
67
  async function run() {
64
68
  try {
65
69
  const { default: config } = await import(pathToFileURL(absoluteConfigPath).href);
66
70
 
67
- // Path of the generated CSS file containing all custom property definitions
71
+ // Percorso del file CSS generato che contiene tutte le definizioni delle custom properties
68
72
  const custom_prop_file_path = path.resolve(configDir, path.join(config.buildPath, config.destFile));
69
73
 
70
- // Directory to scan for CSS files
74
+ // Directory in cui cercare i file CSS
71
75
  const checkdir = path.resolve(configDir, config.dirToCheck);
72
76
 
73
- // Patterns for custom properties to exclude from the unresolved check
77
+ // Pattern delle custom properties da escludere dal controllo delle non risolte
74
78
  /** @type {RegExp[]} */
75
79
  const exclude = config.excludePattern ?? [];
76
80
 
77
- // Collect all .css files in the scan directory, excluding any file under a
78
- // directory whose name starts with "TODO" (work-in-progress folders).
79
- // The token file itself (custom_prop_file_path) is intentionally included:
80
- // custom properties are often composed from other custom properties
81
- // (e.g. `--malert-box-shadow: ... var(--malert-box-shadow-color) ...`)
82
- // and those internal var() references must count as usage, otherwise the
83
- // referenced property is wrongly reported as unused.
81
+ /*
82
+ Raccoglie tutti i file .css nella directory da analizzare, escludendo ogni file sotto una
83
+ directory il cui nome inizia con "TODO" (cartelle in lavorazione).
84
+ Il file dei token stesso (custom_prop_file_path) è volutamente incluso:
85
+ le custom properties sono spesso composte da altre custom properties
86
+ (ad es. `--malert-box-shadow: ... var(--malert-box-shadow-color) ...`)
87
+ e quei riferimenti var() interni devono contare come utilizzo, altrimenti la
88
+ proprietà referenziata viene segnalata erroneamente come non usata.
89
+ */
84
90
  const files = [];
85
91
  for await (const entry of glob(path.join(checkdir, '/**/*.css'))) {
86
92
  const relDirSegments = path.relative(checkdir, path.dirname(entry)).split(path.sep);
@@ -95,27 +101,33 @@ async function run() {
95
101
  throw new Error(`Token CSS file not found: ${custom_prop_file_path}`);
96
102
  }
97
103
 
98
- // ---------------------------------------------------------------------------
99
- // 3. Build the list of defined custom properties
100
- // ---------------------------------------------------------------------------
104
+ /*
105
+ ---------------------------------------------------------------------------
106
+ 3. Costruisce l'elenco delle custom properties definite
107
+ ---------------------------------------------------------------------------
108
+ */
101
109
  const definitionRegex = /--([a-z0-9-]+)(?=\s*:)/g;
102
110
 
103
- // defined_props keeps file/line info too, so unused properties (section 6)
104
- // can be reported with a link back to their definition. With sourceModes
105
- // (see build-tokens-src/config.mjs), the same prop name can legitimately
106
- // appear once per mode with a different value — `mode` disambiguates
107
- // which one a given entry is, so section 5 resolves each to the correct
108
- // per-mode source file instead of mixing them up (see findMediaModeBlocks
109
- // in build-tokens-src/merge-css.mjs).
111
+ /*
112
+ defined_props conserva anche le informazioni su file/riga, così che le proprietà non usate (sezione 6)
113
+ possano essere segnalate con un link alla loro definizione. Con sourceModes
114
+ (vedi build-tokens-src/config.mjs), lo stesso nome di proprietà può legittimamente
115
+ comparire una volta per modalità con un valore diverso — `mode` indica
116
+ di quale si tratta, così la sezione 5 risolve ognuna nel file sorgente corretto
117
+ della propria modalità invece di confonderle (vedi findMediaModeBlocks
118
+ in build-tokens-src/merge-css.mjs).
119
+ */
110
120
  /** @type {{file: string, line: number, prop: string, mode: string|null}[]} */
111
121
  const defined_props = [];
112
122
 
113
123
  const cssContent = fs.readFileSync(custom_prop_file_path, 'utf-8');
114
124
  const custom_prop_relpath = path.relative(configDir, custom_prop_file_path);
115
125
 
116
- // sourceModesBase mirrors the default-resolution logic in
117
- // build-tokens-src/config.mjs: the configured sourceModesBase if it's
118
- // actually a key of sourceModes, otherwise the first key.
126
+ /*
127
+ sourceModesBase replica la logica di risoluzione del default di
128
+ build-tokens-src/config.mjs: il sourceModesBase configurato se è
129
+ effettivamente una chiave di sourceModes, altrimenti la prima chiave.
130
+ */
119
131
  const sourceModeNames = config.sourceModes ? Object.keys(config.sourceModes) : [];
120
132
  const sourceModesBase = sourceModeNames.includes(config.sourceModesBase)
121
133
  ? config.sourceModesBase
@@ -134,8 +146,8 @@ async function run() {
134
146
  defined_props.push({ file: custom_prop_relpath, line, prop: `--${m[1]}`, mode: modeAtIndex(m.index) });
135
147
  });
136
148
 
137
- // Also include any extra CSS files declared in extraCustomPropsFiles.
138
- // These are plain (non-sourceModes) files, so mode is always null.
149
+ // Include anche gli eventuali file CSS extra dichiarati in extraCustomPropsFiles.
150
+ // Sono file semplici (non sourceModes), quindi mode è sempre null.
139
151
  for (const extraFile of (config.extraCustomPropsFiles ?? [])) {
140
152
  const extraFilePath = path.resolve(configDir, extraFile);
141
153
  const extraContent = fs.readFileSync(extraFilePath, 'utf-8');
@@ -148,9 +160,11 @@ async function run() {
148
160
 
149
161
  const propertyNamesList = defined_props.map(item => item.prop);
150
162
 
151
- // ---------------------------------------------------------------------------
152
- // 4. Scan files for unresolved var() references
153
- // ---------------------------------------------------------------------------
163
+ /*
164
+ ---------------------------------------------------------------------------
165
+ 4. Analizza i file alla ricerca di riferimenti var() non risolti
166
+ ---------------------------------------------------------------------------
167
+ */
154
168
  const usageRegex = /var\(\s*(--[a-z0-9-]+)\s*(,.*?)?\)/g;
155
169
  /** @type {{file: string, line: number, prop: string}[]} */
156
170
  const unresolved_props = [];
@@ -177,44 +191,52 @@ async function run() {
177
191
 
178
192
  unresolved_props.sort((a, b) => a.file.localeCompare(b.file));
179
193
 
180
- // Unused-properties census is opt-in (config.checkUnused: true) since it
181
- // re-runs the Style Dictionary transform pipeline over the token sources
182
- // just to resolve source files, which adds a noticeable cost.
194
+ /*
195
+ Il censimento delle proprietà non usate è opt-in (config.checkUnused: true) perché
196
+ riesegue la pipeline di trasformazione di Style Dictionary sui sorgenti dei token
197
+ solo per risalire ai file sorgente, con un costo apprezzabile.
198
+ */
183
199
  const checkUnused = config.checkUnused === true;
184
200
 
185
- // If true (default), properties sourced from a token file under
186
- // node_modules (e.g. a third-party token package) are never reported as
187
- // unused — the consuming project isn't expected to prune those.
201
+ /*
202
+ Se true (default), le proprietà provenienti da un file token sotto
203
+ node_modules (ad es. un pacchetto di token di terze parti) non vengono mai segnalate
204
+ come non usate — il progetto che le usa non è tenuto a ripulirle.
205
+ */
188
206
  const ignoreUnusedInNodeModules = config.ignoreUnusedInNodeModules !== false;
189
207
 
190
- // ---------------------------------------------------------------------------
191
- // 5. Best-effort: resolve the .mjs token source file for each defined
192
- // property, by running the same transform pipeline used to generate the
193
- // CSS (see build-tokens-src/formats/css.mjs) over the token sources
194
- // declared in config.source. Properties that only exist in the generated
195
- // CSS (or an extraCustomPropsFiles entry) — e.g. manual additions kept
196
- // across rebuilds via the mergeCustomProps option — have no token source
197
- // and are reported by name only.
198
- //
199
- // With sourceModes, resolution runs once PER MODE, keyed by mode name in
200
- // sourceFileByPropByMode: the same prop name can be defined by a
201
- // different source file in each mode (see the `dead: {...}` example in
202
- // both a light and dark token file), so a single flattened name -> file
203
- // map would silently point some entries at the wrong mode's file.
204
- // sourceFileByProp (mode: null) covers the non-sourceModes case and
205
- // extraCustomPropsFiles entries.
206
- // ---------------------------------------------------------------------------
208
+ /*
209
+ ---------------------------------------------------------------------------
210
+ 5. Best-effort: risale al file sorgente .mjs dei token per ogni proprietà
211
+ definita, eseguendo la stessa pipeline di trasformazione usata per generare il
212
+ CSS (vedi build-tokens-src/formats/css.mjs) sui sorgenti dei token
213
+ dichiarati in config.source. Le proprietà che esistono solo nel CSS generato
214
+ (o in una voce di extraCustomPropsFiles) — ad es. aggiunte manuali conservate
215
+ tra una build e l'altra tramite l'opzione mergeCustomProps — non hanno un
216
+ sorgente token e vengono segnalate solo per nome.
217
+
218
+ Con sourceModes, la risoluzione viene eseguita una volta PER MODALITÀ, indicizzata per nome
219
+ della modalità in sourceFileByPropByMode: lo stesso nome di proprietà può essere definito da un
220
+ file sorgente diverso in ogni modalità (vedi l'esempio `dead: {...}` in
221
+ un file token light e in uno dark), quindi una singola mappa nome -> file
222
+ appiattita punterebbe in silenzio alcune voci al file della modalità sbagliata.
223
+ sourceFileByProp (mode: null) copre il caso senza sourceModes e le voci di
224
+ extraCustomPropsFiles.
225
+ ---------------------------------------------------------------------------
226
+ */
207
227
  /** @type {Map<string, string>} */
208
228
  const sourceFileByProp = new Map();
209
229
  /** @type {Map<string, Map<string, string>>} */
210
230
  const sourceFileByPropByMode = new Map();
211
231
 
212
- // includeEntries: base-mode sources, passed as `include` for non-base
213
- // modes so cross-mode references resolve (same as build-source-modes.mjs).
232
+ // includeEntries: sorgenti della modalità base, passate come `include` per le
233
+ // modalità non base così che i riferimenti tra modalità vengano risolti (come in build-source-modes.mjs).
214
234
  /** @param {Parameters<typeof splitSourceEntries>[0]} sourceEntries @param {Parameters<typeof splitSourceEntries>[0]} [includeEntries] @returns {Promise<Map<string,string>>} */
215
- // Entries can be strings or `{ src, prefix, transform }` objects (see
216
- // build-tokens-src/source-prefixes.mjs): both are registered before the
217
- // transform pipeline runs, so token names match the generated CSS.
235
+ /*
236
+ Le voci possono essere stringhe od oggetti `{ src, prefix, transform }` (vedi
237
+ build-tokens-src/source-prefixes.mjs): entrambi vengono registrati prima che la
238
+ pipeline di trasformazione venga eseguita, così i nomi dei token corrispondono al CSS generato.
239
+ */
218
240
  const resolveSourceFileMap = async (sourceEntries, includeEntries = []) => {
219
241
  /** @type {Map<string, string>} */
220
242
  const map = new Map();
@@ -243,7 +265,7 @@ async function run() {
243
265
  if (token.filePath && token.isSource !== false) map.set(`--${token.name}`, token.filePath);
244
266
  }
245
267
  } catch {
246
- // Non-fatal: unused properties will be reported by name only.
268
+ // Non bloccante: le proprietà non usate verranno segnalate solo per nome.
247
269
  }
248
270
  return map;
249
271
  };
@@ -264,12 +286,14 @@ async function run() {
264
286
  ? sourceFileByPropByMode.get(item.mode)?.get(item.prop)
265
287
  : sourceFileByProp.get(item.prop);
266
288
 
267
- // ---------------------------------------------------------------------------
268
- // 6. Build the list of unused custom properties (defined but never
269
- // referenced via var() in any scanned CSS file) — the opposite check
270
- // of section 4. Properties sourced from node_modules are skipped when
271
- // ignoreUnusedInNodeModules is true (default).
272
- // ---------------------------------------------------------------------------
289
+ /*
290
+ ---------------------------------------------------------------------------
291
+ 6. Costruisce l'elenco delle custom properties non usate (definite ma mai
292
+ referenziate tramite var() in alcun file CSS analizzato) — il controllo opposto
293
+ a quello della sezione 4. Le proprietà provenienti da node_modules vengono saltate quando
294
+ ignoreUnusedInNodeModules è true (default).
295
+ ---------------------------------------------------------------------------
296
+ */
273
297
  const unused_props = checkUnused
274
298
  ? defined_props
275
299
  .filter(item => !used_props_set.has(item.prop))
@@ -282,9 +306,11 @@ async function run() {
282
306
  .sort((a, b) => a.prop.localeCompare(b.prop))
283
307
  : [];
284
308
 
285
- // ---------------------------------------------------------------------------
286
- // 7. Write the report
287
- // ---------------------------------------------------------------------------
309
+ /*
310
+ ---------------------------------------------------------------------------
311
+ 7. Scrive il report
312
+ ---------------------------------------------------------------------------
313
+ */
288
314
  const result_file = path.resolve(configDir, 'unresolved-unused-props.md');
289
315
 
290
316
  const logParts = [`${unresolved_props.length} unresolved custom properties found`];