@ids-group-ltd/ids-design-system 1.1.0 → 1.1.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 (119) hide show
  1. package/CHANGELOG.md +289 -0
  2. package/agent/INDEX.md +1 -1
  3. package/agent/feedback/ds-alert.md +3 -2
  4. package/agent/feedback/ds-chat-message.md +3 -3
  5. package/agent/feedback/ds-chat-step.md +1 -1
  6. package/agent/feedback/ds-chat-steps.md +1 -1
  7. package/agent/feedback/ds-chat-thread.md +2 -2
  8. package/agent/feedback/ds-empty-state.md +2 -1
  9. package/agent/feedback/ds-tree.md +4 -2
  10. package/agent/forms/ds-chat-input.md +3 -3
  11. package/agent/foundations/tokens.md +2 -2
  12. package/agent/navigation/ds-splitter.md +1 -1
  13. package/components.md +22 -18
  14. package/fesm2022/ids-group-ltd-ids-design-system-components-alert.mjs +5 -3
  15. package/fesm2022/ids-group-ltd-ids-design-system-components-alert.mjs.map +1 -1
  16. package/fesm2022/ids-group-ltd-ids-design-system-components-app-layout.mjs +2 -2
  17. package/fesm2022/ids-group-ltd-ids-design-system-components-app-layout.mjs.map +1 -1
  18. package/fesm2022/ids-group-ltd-ids-design-system-components-autocomplete.mjs +2 -2
  19. package/fesm2022/ids-group-ltd-ids-design-system-components-autocomplete.mjs.map +1 -1
  20. package/fesm2022/ids-group-ltd-ids-design-system-components-banner.mjs +2 -2
  21. package/fesm2022/ids-group-ltd-ids-design-system-components-banner.mjs.map +1 -1
  22. package/fesm2022/ids-group-ltd-ids-design-system-components-button.mjs +2 -2
  23. package/fesm2022/ids-group-ltd-ids-design-system-components-button.mjs.map +1 -1
  24. package/fesm2022/ids-group-ltd-ids-design-system-components-chart-legend.mjs +2 -2
  25. package/fesm2022/ids-group-ltd-ids-design-system-components-chart-legend.mjs.map +1 -1
  26. package/fesm2022/ids-group-ltd-ids-design-system-components-chat.mjs +184 -72
  27. package/fesm2022/ids-group-ltd-ids-design-system-components-chat.mjs.map +1 -1
  28. package/fesm2022/ids-group-ltd-ids-design-system-components-checkbox.mjs +2 -2
  29. package/fesm2022/ids-group-ltd-ids-design-system-components-checkbox.mjs.map +1 -1
  30. package/fesm2022/ids-group-ltd-ids-design-system-components-color-picker.mjs +2 -2
  31. package/fesm2022/ids-group-ltd-ids-design-system-components-color-picker.mjs.map +1 -1
  32. package/fesm2022/ids-group-ltd-ids-design-system-components-date-picker.mjs +2 -2
  33. package/fesm2022/ids-group-ltd-ids-design-system-components-date-picker.mjs.map +1 -1
  34. package/fesm2022/ids-group-ltd-ids-design-system-components-drawer.mjs +2 -2
  35. package/fesm2022/ids-group-ltd-ids-design-system-components-drawer.mjs.map +1 -1
  36. package/fesm2022/ids-group-ltd-ids-design-system-components-empty-state.mjs +14 -7
  37. package/fesm2022/ids-group-ltd-ids-design-system-components-empty-state.mjs.map +1 -1
  38. package/fesm2022/ids-group-ltd-ids-design-system-components-field-group.mjs +2 -2
  39. package/fesm2022/ids-group-ltd-ids-design-system-components-field-group.mjs.map +1 -1
  40. package/fesm2022/ids-group-ltd-ids-design-system-components-input.mjs +2 -2
  41. package/fesm2022/ids-group-ltd-ids-design-system-components-input.mjs.map +1 -1
  42. package/fesm2022/ids-group-ltd-ids-design-system-components-modal.mjs +4 -4
  43. package/fesm2022/ids-group-ltd-ids-design-system-components-modal.mjs.map +1 -1
  44. package/fesm2022/ids-group-ltd-ids-design-system-components-multi-select.mjs +2 -2
  45. package/fesm2022/ids-group-ltd-ids-design-system-components-multi-select.mjs.map +1 -1
  46. package/fesm2022/ids-group-ltd-ids-design-system-components-number-stepper.mjs +2 -2
  47. package/fesm2022/ids-group-ltd-ids-design-system-components-number-stepper.mjs.map +1 -1
  48. package/fesm2022/ids-group-ltd-ids-design-system-components-otp-input.mjs +2 -2
  49. package/fesm2022/ids-group-ltd-ids-design-system-components-otp-input.mjs.map +1 -1
  50. package/fesm2022/ids-group-ltd-ids-design-system-components-popover.mjs +23 -12
  51. package/fesm2022/ids-group-ltd-ids-design-system-components-popover.mjs.map +1 -1
  52. package/fesm2022/ids-group-ltd-ids-design-system-components-radio-group.mjs +2 -2
  53. package/fesm2022/ids-group-ltd-ids-design-system-components-radio-group.mjs.map +1 -1
  54. package/fesm2022/ids-group-ltd-ids-design-system-components-search.mjs +2 -2
  55. package/fesm2022/ids-group-ltd-ids-design-system-components-search.mjs.map +1 -1
  56. package/fesm2022/ids-group-ltd-ids-design-system-components-segmented.mjs +2 -2
  57. package/fesm2022/ids-group-ltd-ids-design-system-components-segmented.mjs.map +1 -1
  58. package/fesm2022/ids-group-ltd-ids-design-system-components-select.mjs +2 -2
  59. package/fesm2022/ids-group-ltd-ids-design-system-components-select.mjs.map +1 -1
  60. package/fesm2022/ids-group-ltd-ids-design-system-components-splitter.mjs +116 -10
  61. package/fesm2022/ids-group-ltd-ids-design-system-components-splitter.mjs.map +1 -1
  62. package/fesm2022/ids-group-ltd-ids-design-system-components-stepper.mjs +2 -2
  63. package/fesm2022/ids-group-ltd-ids-design-system-components-stepper.mjs.map +1 -1
  64. package/fesm2022/ids-group-ltd-ids-design-system-components-switch.mjs +2 -2
  65. package/fesm2022/ids-group-ltd-ids-design-system-components-switch.mjs.map +1 -1
  66. package/fesm2022/ids-group-ltd-ids-design-system-components-table-columns.mjs +2 -2
  67. package/fesm2022/ids-group-ltd-ids-design-system-components-table-columns.mjs.map +1 -1
  68. package/fesm2022/ids-group-ltd-ids-design-system-components-table.mjs +2 -2
  69. package/fesm2022/ids-group-ltd-ids-design-system-components-table.mjs.map +1 -1
  70. package/fesm2022/ids-group-ltd-ids-design-system-components-textarea.mjs +4 -2
  71. package/fesm2022/ids-group-ltd-ids-design-system-components-textarea.mjs.map +1 -1
  72. package/fesm2022/ids-group-ltd-ids-design-system-components-time-picker.mjs +2 -2
  73. package/fesm2022/ids-group-ltd-ids-design-system-components-time-picker.mjs.map +1 -1
  74. package/fesm2022/ids-group-ltd-ids-design-system-components-timeline.mjs +2 -2
  75. package/fesm2022/ids-group-ltd-ids-design-system-components-timeline.mjs.map +1 -1
  76. package/fesm2022/ids-group-ltd-ids-design-system-components-toggle-button.mjs +2 -2
  77. package/fesm2022/ids-group-ltd-ids-design-system-components-toggle-button.mjs.map +1 -1
  78. package/fesm2022/ids-group-ltd-ids-design-system-components-tooltip.mjs +4 -19
  79. package/fesm2022/ids-group-ltd-ids-design-system-components-tooltip.mjs.map +1 -1
  80. package/fesm2022/ids-group-ltd-ids-design-system-components-tree.mjs +84 -9
  81. package/fesm2022/ids-group-ltd-ids-design-system-components-tree.mjs.map +1 -1
  82. package/fesm2022/ids-group-ltd-ids-design-system-components.mjs +31 -4
  83. package/fesm2022/ids-group-ltd-ids-design-system-components.mjs.map +1 -1
  84. package/fesm2022/ids-group-ltd-ids-design-system-core.mjs +33 -0
  85. package/fesm2022/ids-group-ltd-ids-design-system-core.mjs.map +1 -1
  86. package/fesm2022/ids-group-ltd-ids-design-system-icons.mjs +4 -2
  87. package/fesm2022/ids-group-ltd-ids-design-system-icons.mjs.map +1 -1
  88. package/fesm2022/ids-group-ltd-ids-design-system.mjs +1 -1
  89. package/fesm2022/ids-group-ltd-ids-design-system.mjs.map +1 -1
  90. package/migrations/0.11.2.json +1 -0
  91. package/migrations/1.0.1.json +4 -0
  92. package/migrations/1.0.2.json +9 -1
  93. package/migrations/1.1.0.json +25 -0
  94. package/migrations/1.1.1.json +190 -0
  95. package/migrations/1.1.2.json +135 -0
  96. package/migrations/README.md +9 -7
  97. package/package.json +4 -1
  98. package/schematics/check-overrides/surface.json +29 -3
  99. package/stylelint/index.mjs +17 -3
  100. package/stylelint/known-tokens.mjs +139 -0
  101. package/stylelint/report.mjs +185 -0
  102. package/stylelint/tokens.mjs +160 -0
  103. package/stylelint/use-tokens.mjs +397 -0
  104. package/styles/_check-box.scss +2 -2
  105. package/styles/_dropdown-overlay.scss +5 -2
  106. package/styles/_field-box.scss +2 -2
  107. package/styles/_tokens.scss +8 -0
  108. package/themes/README.md +1 -1
  109. package/themes/_semantic.scss +13 -0
  110. package/themes/dark/_theme.scss +15 -3
  111. package/types/ids-group-ltd-ids-design-system-components-alert.d.ts +3 -1
  112. package/types/ids-group-ltd-ids-design-system-components-chat.d.ts +58 -5
  113. package/types/ids-group-ltd-ids-design-system-components-empty-state.d.ts +7 -2
  114. package/types/ids-group-ltd-ids-design-system-components-splitter.d.ts +15 -1
  115. package/types/ids-group-ltd-ids-design-system-components-textarea.d.ts +2 -0
  116. package/types/ids-group-ltd-ids-design-system-components-tree.d.ts +57 -3
  117. package/types/ids-group-ltd-ids-design-system-components.d.ts +8 -4
  118. package/types/ids-group-ltd-ids-design-system-core.d.ts +40 -0
  119. package/types/ids-group-ltd-ids-design-system.d.ts +3 -3
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.0",
2
+ "version": "1.1.2",
3
3
  "tokens": [
4
4
  "--ds-accordion-body-padding",
5
5
  "--ds-accordion-body-text-color",
@@ -261,10 +261,14 @@
261
261
  "--ds-chat-message-max-width",
262
262
  "--ds-chat-message-padding",
263
263
  "--ds-chat-message-radius",
264
+ "--ds-chat-message-system-bg-color",
265
+ "--ds-chat-message-system-border-color",
266
+ "--ds-chat-message-system-color",
264
267
  "--ds-chat-message-user-bg-color",
265
268
  "--ds-chat-message-user-color",
266
269
  "--ds-chat-thread-gap",
267
270
  "--ds-chat-thread-group-gap",
271
+ "--ds-chat-thread-inset-bottom",
268
272
  "--ds-chat-thread-padding",
269
273
  "--ds-check-mark-enter-duration",
270
274
  "--ds-check-mark-enter-easing",
@@ -841,6 +845,7 @@
841
845
  "--ds-split-button-pressed-shadow",
842
846
  "--ds-split-button-text-color",
843
847
  "--ds-splitter-drag-color",
848
+ "--ds-splitter-fog-color",
844
849
  "--ds-splitter-gap",
845
850
  "--ds-splitter-grip-color",
846
851
  "--ds-splitter-line-color",
@@ -1157,13 +1162,16 @@
1157
1162
  "a-body",
1158
1163
  "a-close",
1159
1164
  "a-icon",
1165
+ "a-lead",
1160
1166
  "a-title",
1161
1167
  "alert",
1162
1168
  "disabled",
1163
1169
  "error",
1170
+ "full-width",
1164
1171
  "is-disabled",
1165
1172
  "neutral",
1166
1173
  "success",
1174
+ "titled",
1167
1175
  "warning"
1168
1176
  ],
1169
1177
  "ds-app-layout": [
@@ -1500,6 +1508,8 @@
1500
1508
  "is-first",
1501
1509
  "is-grouped",
1502
1510
  "meta",
1511
+ "notice-lead",
1512
+ "notice-title",
1503
1513
  "speaker",
1504
1514
  "status",
1505
1515
  "steps",
@@ -1541,11 +1551,13 @@
1541
1551
  "layout-send-outside",
1542
1552
  "layout-split",
1543
1553
  "layout-toolbar",
1554
+ "queue",
1544
1555
  "send",
1545
1556
  "send-button",
1546
1557
  "status",
1547
1558
  "status-above",
1548
- "status-bar"
1559
+ "status-bar",
1560
+ "stop"
1549
1561
  ],
1550
1562
  "ds-attachment": [
1551
1563
  "disabled",
@@ -1706,8 +1718,10 @@
1706
1718
  "cta",
1707
1719
  "empty-state",
1708
1720
  "error",
1721
+ "icon",
1709
1722
  "icon-tile",
1710
1723
  "locked",
1724
+ "plain",
1711
1725
  "success",
1712
1726
  "title"
1713
1727
  ],
@@ -2313,6 +2327,9 @@
2313
2327
  ],
2314
2328
  "ds-splitter": [
2315
2329
  "dragging",
2330
+ "fog",
2331
+ "fog-end",
2332
+ "fog-start",
2316
2333
  "handle",
2317
2334
  "pane",
2318
2335
  "pane-end",
@@ -2516,11 +2533,13 @@
2516
2533
  "optional-marker",
2517
2534
  "over-limit",
2518
2535
  "overflow-mirror",
2536
+ "placeholder-line",
2519
2537
  "read-only",
2520
2538
  "req",
2521
2539
  "sm",
2522
2540
  "soft-limit",
2523
- "visually-hidden"
2541
+ "visually-hidden",
2542
+ "wraps"
2524
2543
  ],
2525
2544
  "ds-time-columns": [
2526
2545
  "col",
@@ -2630,10 +2649,17 @@
2630
2649
  ],
2631
2650
  "ds-tree": [
2632
2651
  "caret",
2652
+ "caret-button",
2633
2653
  "caret-spacer",
2654
+ "custom-label",
2655
+ "expanded",
2656
+ "is-animated",
2657
+ "is-entering",
2658
+ "is-leaving",
2634
2659
  "label",
2635
2660
  "node-icon",
2636
2661
  "row",
2662
+ "row-shell",
2637
2663
  "selected",
2638
2664
  "trailing"
2639
2665
  ],
@@ -1,7 +1,8 @@
1
- // Stylelint plugin for consumers of @ids-group-ltd/ids-design-system. The rule
1
+ // Stylelint plugins for consumers of @ids-group-ltd/ids-design-system. The rule
2
2
  // `ids-design-system/no-removed-tokens` reports every custom property this library removed or
3
3
  // renamed, read from `deprecated-tokens.json` (generated from the published migration manifests),
4
- // and autofixes a rename to the current name.
4
+ // and autofixes a rename to the current name. `use-tokens` and `known-tokens` live in their own
5
+ // files.
5
6
  import { readFileSync } from 'node:fs';
6
7
  import stylelint from 'stylelint';
7
8
  import { VERSION, inRange } from './since-version.mjs';
@@ -91,4 +92,17 @@ rule.meta = {
91
92
  fixable: true,
92
93
  };
93
94
 
94
- export default createPlugin(ruleName, rule);
95
+ // An auto-update plugin before 1.20.1 lints from a copy of this folder that points only this file at
96
+ // `stylelint`, so the token rules cannot load there; that copy still runs `no-removed-tokens`.
97
+ const tokenRules = await Promise.all([
98
+ import('./use-tokens.mjs'),
99
+ import('./known-tokens.mjs'),
100
+ ])
101
+ .then((modules) => modules.map((module) => module.default))
102
+ .catch((error) => {
103
+ if (error.code === 'ERR_MODULE_NOT_FOUND' || error.code === 'ENOENT')
104
+ return [];
105
+ throw error;
106
+ });
107
+
108
+ export default [createPlugin(ruleName, rule), ...tokenRules];
@@ -0,0 +1,139 @@
1
+ // `ids-design-system/known-tokens`: reports a `var(--name)` whose name nothing declares, neither the
2
+ // design system nor the consumer's own sources. Such a read falls back or resolves to nothing, and
3
+ // looks exactly like a working token.
4
+ import { existsSync, readFileSync } from 'node:fs';
5
+ import { createRequire } from 'node:module';
6
+ import stylelint from 'stylelint';
7
+ import { libraryNames } from './tokens.mjs';
8
+
9
+ const fromStylelint = createRequire(import.meta.resolve('stylelint'));
10
+ const fastGlob = fromStylelint('fast-glob');
11
+
12
+ const {
13
+ createPlugin,
14
+ utils: { report, ruleMessages, validateOptions },
15
+ } = stylelint;
16
+
17
+ export const ruleName = 'ids-design-system/known-tokens';
18
+
19
+ const deprecated = new Set(
20
+ JSON.parse(
21
+ readFileSync(new URL('./deprecated-tokens.json', import.meta.url), 'utf8'),
22
+ ).map((entry) => entry.name),
23
+ );
24
+
25
+ const messages = ruleMessages(ruleName, {
26
+ unknown: (name, closest) =>
27
+ `"${name}" is declared neither by the design system nor in this project${closest ? `, did you mean "${closest}"?` : ''}`,
28
+ });
29
+
30
+ const NAME = /(?<![\w-])--[a-zA-Z][\w-]*/g;
31
+ const READ = /var\(\s*(--[a-zA-Z][\w-]*)/g;
32
+
33
+ // Any name in a scanned file that is not a `var()` read counts as declared there: a stylesheet
34
+ // declaration, `[style.--x]` in a template, `setProperty('--x', …)` in TypeScript.
35
+ const scanned = new Map();
36
+ const declaredIn = (globs) => {
37
+ const key = JSON.stringify(globs);
38
+ if (!scanned.has(key)) {
39
+ const names = new Set();
40
+ const paths = globs.filter((entry) => existsSync(entry));
41
+ const patterns = globs.filter((entry) => !existsSync(entry));
42
+ for (const file of [
43
+ ...paths,
44
+ ...fastGlob.sync(patterns, {
45
+ ignore: ['**/node_modules/**', '**/dist/**', '**/.angular/**'],
46
+ absolute: true,
47
+ }),
48
+ ]) {
49
+ const text = readFileSync(file, 'utf8');
50
+ for (const match of text.matchAll(NAME)) {
51
+ const before = text.slice(Math.max(0, match.index - 8), match.index);
52
+ if (!/var\(\s*$/.test(before)) names.add(match[0]);
53
+ }
54
+ }
55
+ scanned.set(key, names);
56
+ }
57
+ return scanned.get(key);
58
+ };
59
+
60
+ // Only a size name one letter longer or shorter is offered (`--radius-s` is `--radius-sm`,
61
+ // `--font-size-sm` is `--font-size-s`): any other edit inside a scale points at the wrong step, as
62
+ // `--font-size-xl` at `--font-size-xs`.
63
+ const closestLibraryName = (name) =>
64
+ [...libraryNames].find(
65
+ (candidate) =>
66
+ (candidate.startsWith(name) &&
67
+ /^[a-z]$/.test(candidate.slice(name.length))) ||
68
+ (name.startsWith(candidate) &&
69
+ /^[a-z]$/.test(name.slice(candidate.length))),
70
+ );
71
+
72
+ const rule =
73
+ (primary, secondary = {}) =>
74
+ (root, result) => {
75
+ if (
76
+ !validateOptions(
77
+ result,
78
+ ruleName,
79
+ { actual: primary },
80
+ {
81
+ actual: secondary,
82
+ possible: {
83
+ declarationsFrom: [(value) => typeof value === 'string'],
84
+ ignore: [(value) => typeof value === 'string'],
85
+ },
86
+ optional: true,
87
+ },
88
+ )
89
+ )
90
+ return;
91
+
92
+ const fromProject = secondary.declarationsFrom?.length
93
+ ? declaredIn(secondary.declarationsFrom)
94
+ : new Set();
95
+ const ignored = (secondary.ignore ?? []).map((pattern) =>
96
+ pattern.startsWith('/') && pattern.endsWith('/')
97
+ ? new RegExp(pattern.slice(1, -1))
98
+ : new RegExp(
99
+ `^${pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/\\\*/g, '.*')}$`,
100
+ ),
101
+ );
102
+ const local = new Set();
103
+ root.walkDecls((declaration) => {
104
+ if (declaration.prop.startsWith('--')) local.add(declaration.prop);
105
+ });
106
+ const known = (name) =>
107
+ libraryNames.has(name) ||
108
+ local.has(name) ||
109
+ fromProject.has(name) ||
110
+ deprecated.has(name) ||
111
+ ignored.some((pattern) => pattern.test(name));
112
+
113
+ root.walkDecls((declaration) => {
114
+ if (declaration.value.includes('#{')) return;
115
+ const valueIndex =
116
+ declaration.prop.length + (declaration.raws.between ?? ':').length;
117
+ for (const match of declaration.value.matchAll(READ)) {
118
+ const name = match[1];
119
+ if (known(name)) continue;
120
+ const index = valueIndex + match.index + match[0].indexOf(name);
121
+ report({
122
+ ruleName,
123
+ result,
124
+ node: declaration,
125
+ index,
126
+ endIndex: index + name.length,
127
+ message: messages.unknown(name, closestLibraryName(name)),
128
+ });
129
+ }
130
+ });
131
+ };
132
+
133
+ rule.ruleName = ruleName;
134
+ rule.messages = messages;
135
+ rule.meta = {
136
+ url: 'https://www.npmjs.com/package/@ids-group-ltd/ids-design-system',
137
+ };
138
+
139
+ export default createPlugin(ruleName, rule);
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env node
2
+ // Read-only audit of how far a project's styles are on design-system tokens:
3
+ //
4
+ // npx ids-design-system-token-report "src/**/*.{scss,css,ts}" [--ignore <glob>]... [--json <file>]
5
+ //
6
+ // Lints every matched .scss and .css file, and every inline `styles` template of a matched .ts
7
+ // file, with `use-tokens` and `known-tokens` only, then prints the findings with their suggestions
8
+ // and the counts per category, property, file and value. Names the project declares in the matched
9
+ // files, ignored ones included, or in the template beside a matched component count as known.
10
+ // Nothing is written except the `--json` file.
11
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
12
+ import { createRequire } from 'node:module';
13
+ import { join, relative } from 'node:path';
14
+ import stylelint from 'stylelint';
15
+ import knownTokens, { ruleName as knownName } from './known-tokens.mjs';
16
+ import useTokens, { ruleName as useName } from './use-tokens.mjs';
17
+
18
+ const fastGlob = createRequire(import.meta.resolve('stylelint'))('fast-glob');
19
+
20
+ const args = process.argv.slice(2);
21
+ const flag = (name) =>
22
+ args.flatMap((arg, index) => (args[index - 1] === name ? [arg] : []));
23
+ const globs = args.filter(
24
+ (arg, index) =>
25
+ !arg.startsWith('--') && !['--ignore', '--json'].includes(args[index - 1]),
26
+ );
27
+ if (!globs.length) {
28
+ console.error(
29
+ 'usage: ids-design-system-token-report <glob>... [--ignore <glob>]... [--json <file>]',
30
+ );
31
+ process.exit(2);
32
+ }
33
+ const built = ['**/node_modules/**', '**/dist/**', '**/.angular/**'];
34
+ const ignore = [...built, ...flag('--ignore')];
35
+ const jsonOut = flag('--json')[0];
36
+ const asGlob = (pattern) => pattern.replaceAll('\\', '/');
37
+
38
+ const scssSyntax = () => {
39
+ for (const base of [join(process.cwd(), 'noop.js'), import.meta.url]) {
40
+ try {
41
+ return createRequire(base)('postcss-scss');
42
+ } catch {}
43
+ }
44
+ console.error(
45
+ 'Reading .scss needs postcss-scss: npm install -D postcss-scss',
46
+ );
47
+ process.exit(2);
48
+ };
49
+
50
+ const files = fastGlob
51
+ .sync(globs.map(asGlob), { ignore, absolute: true })
52
+ .filter((file) => /\.(scss|css|ts)$/.test(file))
53
+ .sort();
54
+ const display = (file) => relative(process.cwd(), file).replaceAll('\\', '/');
55
+
56
+ const sources = [];
57
+ for (const file of files) {
58
+ const text = readFileSync(file, 'utf8');
59
+ if (!file.endsWith('.ts')) {
60
+ sources.push({
61
+ file,
62
+ code: text,
63
+ lineOffset: 0,
64
+ scss: file.endsWith('.scss'),
65
+ });
66
+ continue;
67
+ }
68
+ for (const match of text.matchAll(/styles\s*:\s*\[?\s*`([\s\S]*?)`/g)) {
69
+ const start = match.index + match[0].indexOf('`');
70
+ sources.push({
71
+ file,
72
+ code: match[1].replace(/\$\{[^}]*\}/g, '0'),
73
+ lineOffset: text.slice(0, start).split('\n').length - 1,
74
+ scss: true,
75
+ });
76
+ }
77
+ }
78
+
79
+ // An ignored file still declares names (a brand layer), and a component sets custom properties
80
+ // from its template too (`[style.--x]`).
81
+ const declaring = fastGlob
82
+ .sync(globs.map(asGlob), { ignore: built, absolute: true })
83
+ .filter((file) => /.(scss|css|ts)$/.test(file));
84
+ const templates = declaring
85
+ .map((file) => file.replace(/\.ts$/, '.html'))
86
+ .filter((file) => file.endsWith('.html') && existsSync(file));
87
+
88
+ const config = {
89
+ plugins: [useTokens, knownTokens],
90
+ rules: {
91
+ [useName]: true,
92
+ [knownName]: [true, { declarationsFrom: [...declaring, ...templates] }],
93
+ },
94
+ };
95
+ const syntax = sources.some((source) => source.scss) ? scssSyntax() : undefined;
96
+
97
+ const KIND = [
98
+ [/ has no exact token, nearest /, 'nearest'],
99
+ [/ matches no design-system colour$/, 'none'],
100
+ [/, use /, 'exact'],
101
+ ];
102
+ const findings = [];
103
+ for (const source of sources) {
104
+ const { results } = await stylelint.lint({
105
+ code: source.code,
106
+ codeFilename: source.file,
107
+ config: { ...config, customSyntax: source.scss ? syntax : undefined },
108
+ });
109
+ for (const warning of results[0].warnings) {
110
+ const text = warning.text.replace(/ \(ids-design-system\/[\w-]+\)$/, '');
111
+ const base = {
112
+ file: display(source.file),
113
+ line: warning.line + source.lineOffset,
114
+ text,
115
+ };
116
+ if (warning.rule === knownName) {
117
+ findings.push({
118
+ ...base,
119
+ category: 'unknown-token',
120
+ prop: '',
121
+ raw: text.match(/"(--[\w-]+)"/)[1],
122
+ kind: 'unknown',
123
+ });
124
+ } else if (warning.rule === useName) {
125
+ const [, category, raw, prop] = text.match(
126
+ /^([\w-]+): raw "([\s\S]*?)" in ([\w-]+)/,
127
+ );
128
+ const kind = KIND.find(([pattern]) => pattern.test(text))[1];
129
+ findings.push({ ...base, category, prop, raw, kind });
130
+ }
131
+ }
132
+ }
133
+
134
+ const countBy = (key) =>
135
+ Object.entries(
136
+ findings.reduce((counts, finding) => {
137
+ counts[key(finding)] = (counts[key(finding)] ?? 0) + 1;
138
+ return counts;
139
+ }, {}),
140
+ ).sort((a, b) => b[1] - a[1]);
141
+ const table = (title, rows) => {
142
+ console.log(`\n${title}`);
143
+ for (const [label, count] of rows)
144
+ console.log(` ${String(count).padStart(5)} ${label}`);
145
+ };
146
+
147
+ console.log('findings');
148
+ for (const finding of findings)
149
+ console.log(` ${finding.file}:${finding.line} ${finding.text}`);
150
+ console.log(
151
+ `\nfiles ${files.length}, style sources ${sources.length} (inline .ts templates ${sources.filter((source) => source.file.endsWith('.ts')).length})`,
152
+ );
153
+ const tokenFindings = findings.filter((finding) => finding.kind !== 'unknown');
154
+ console.log(
155
+ `use-tokens ${tokenFindings.length} in ${new Set(tokenFindings.map((finding) => finding.file)).size} files, known-tokens ${findings.length - tokenFindings.length}`,
156
+ );
157
+ table(
158
+ 'by category',
159
+ countBy((finding) => finding.category),
160
+ );
161
+ table(
162
+ 'by category and kind',
163
+ countBy((finding) => `${finding.category} ${finding.kind}`),
164
+ );
165
+ table(
166
+ 'by property',
167
+ countBy((finding) => finding.prop).filter(([prop]) => prop),
168
+ );
169
+ table(
170
+ 'by file',
171
+ countBy((finding) => finding.file),
172
+ );
173
+ table(
174
+ 'by value',
175
+ countBy((finding) => `${finding.category} ${finding.raw}`),
176
+ );
177
+ if (jsonOut)
178
+ writeFileSync(
179
+ jsonOut,
180
+ JSON.stringify(
181
+ { files: files.length, sources: sources.length, findings },
182
+ null,
183
+ 1,
184
+ ),
185
+ );
@@ -0,0 +1,160 @@
1
+ // The token tables `use-tokens` matches raw values against and the names `known-tokens` accepts,
2
+ // read at load time from the stylesheets and the bundle that sit beside this folder (`styles/`,
3
+ // `themes/`, `fesm2022/`).
4
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
5
+ import { join } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const packageRoot = fileURLToPath(new URL('..', import.meta.url));
9
+ const lib = existsSync(join(packageRoot, 'styles/_tokens.scss'))
10
+ ? packageRoot
11
+ : join(packageRoot, 'src/lib');
12
+
13
+ const stripComments = (text) =>
14
+ text.replace(/\/\*[\s\S]*?\*\//g, '').replace(/(^|[^:])\/\/.*$/gm, '$1');
15
+
16
+ const declarations = (file) =>
17
+ [
18
+ ...stripComments(readFileSync(join(lib, file), 'utf8')).matchAll(
19
+ /(--[\w-]+)\s*:\s*([^;{}]+);/g,
20
+ ),
21
+ ].map((match) => [match[1], match[2].replace(/\s+/g, ' ').trim()]);
22
+
23
+ const hex2 = (number) =>
24
+ Math.round(number).toString(16).padStart(2, '0').toUpperCase();
25
+
26
+ const hslToHex = (hue, saturation, lightness) => {
27
+ const s = saturation / 100;
28
+ const l = lightness / 100;
29
+ const k = (n) => (n + hue / 30) % 12;
30
+ const a = s * Math.min(l, 1 - l);
31
+ const channel = (n) =>
32
+ l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
33
+ return `#${hex2(channel(0) * 255)}${hex2(channel(8) * 255)}${hex2(channel(4) * 255)}`;
34
+ };
35
+
36
+ // An opaque colour as `#RRGGBB`, or null for anything translucent or not a literal colour.
37
+ export const normalizeColor = (raw) => {
38
+ const value = raw.trim().toLowerCase();
39
+ let match = value.match(/^#([0-9a-f]{3,8})$/);
40
+ if (match) {
41
+ let hex = match[1];
42
+ if (hex.length === 3 || hex.length === 4)
43
+ hex = [...hex].map((digit) => digit + digit).join('');
44
+ if (hex.length === 8 && hex.endsWith('ff')) hex = hex.slice(0, 6);
45
+ return hex.length === 6 ? `#${hex.toUpperCase()}` : null;
46
+ }
47
+ match = value.match(
48
+ /^hsla?\(\s*(-?[\d.]+)(?:deg)?[\s,]+([\d.]+)%[\s,]+([\d.]+)%\s*(?:[,/]\s*(1|100%))?\s*\)$/,
49
+ );
50
+ if (match) return hslToHex(+match[1], +match[2], +match[3]);
51
+ match = value.match(
52
+ /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)\s*(?:[,/]\s*(1|100%))?\s*\)$/,
53
+ );
54
+ if (match) return `#${hex2(+match[1])}${hex2(+match[2])}${hex2(+match[3])}`;
55
+ if (value === 'white') return '#FFFFFF';
56
+ if (value === 'black') return '#000000';
57
+ return null;
58
+ };
59
+
60
+ const scale = new Map(declarations('styles/_tokens.scss').reverse());
61
+ const colorDeclarations = new Map();
62
+ const semantic = new Set();
63
+ for (const file of [
64
+ 'themes/_base-palette.scss',
65
+ 'themes/light/_palette.scss',
66
+ 'themes/_semantic.scss',
67
+ ])
68
+ for (const [name, value] of declarations(file)) {
69
+ if (!colorDeclarations.has(name)) colorDeclarations.set(name, value);
70
+ if (file.includes('_semantic')) semantic.add(name);
71
+ }
72
+
73
+ const all = new Map([...scale, ...colorDeclarations]);
74
+ const resolve = (value, depth = 0) => {
75
+ if (depth > 20) return value;
76
+ const next = value.replace(/var\((--[\w-]+)(?:,[^()]*)?\)/g, (whole, name) =>
77
+ all.has(name) ? resolve(all.get(name), depth + 1) : whole,
78
+ );
79
+ return next.replace(/calc\(\s*(-?[\d.]+)\s*-\s*([\d.]+)\s*\)/g, (_, a, b) =>
80
+ String(a - b),
81
+ );
82
+ };
83
+
84
+ const colorsByHex = new Map();
85
+ for (const [name, value] of colorDeclarations) {
86
+ const hex = normalizeColor(resolve(value));
87
+ if (!hex) continue;
88
+ if (!colorsByHex.has(hex))
89
+ colorsByHex.set(hex, { semantic: [], palette: [] });
90
+ colorsByHex.get(hex)[semantic.has(name) ? 'semantic' : 'palette'].push(name);
91
+ }
92
+
93
+ const group = (prefix, exclude = []) =>
94
+ [...scale.keys()]
95
+ .filter(
96
+ (name) =>
97
+ name.startsWith(prefix) && !exclude.some((part) => name.includes(part)),
98
+ )
99
+ .map((name) => ({ name, value: resolve(scale.get(name)) }));
100
+
101
+ const inPx = (list) =>
102
+ list
103
+ .filter((token) => /^(0|[\d.]+px)$/.test(token.value))
104
+ .map((token) => ({ ...token, number: parseFloat(token.value) }));
105
+
106
+ const numeric = (list) =>
107
+ list.map((token) => ({ ...token, number: +token.value }));
108
+
109
+ export const tokens = {
110
+ colorsByHex,
111
+ space: inPx(group('--space-', ['stack', 'inline'])),
112
+ radius: inPx(group('--radius-', ['pill-value', 'flat'])),
113
+ fontSize: inPx(group('--font-size-', ['h5-strong', 'mono'])),
114
+ fontWeight: numeric(group('--font-weight-')),
115
+ lineHeight: numeric(group('--line-height-')),
116
+ layer: numeric(group('--layer-')),
117
+ duration: group('--duration-', ['loop']).map((token) => ({
118
+ ...token,
119
+ number: parseFloat(token.value),
120
+ })),
121
+ ease: group('--ease-').map((token) => ({
122
+ ...token,
123
+ normalized: normalizeEase(token.value),
124
+ })),
125
+ shadow: group('--shadow-')
126
+ .filter((token) => /^--shadow-\d$/.test(token.name))
127
+ .map((token) => {
128
+ const [, y, blur] = token.value.match(/^0 (\d+)px (\d+)px/) ?? [];
129
+ return { ...token, y: +y, blur: +blur };
130
+ }),
131
+ };
132
+
133
+ export function normalizeEase(value) {
134
+ return value.replace(/\s+/g, '').replace(/(^|[(,])0\./g, '$1.');
135
+ }
136
+
137
+ // Every custom property name the library declares or reads: tokens, theme roles and the `--ds-*`
138
+ // hooks its components read, which live in the compiled bundle rather than in `styles/`.
139
+ const filesUnder = (directory, pattern) =>
140
+ existsSync(directory)
141
+ ? readdirSync(directory, { recursive: true })
142
+ .filter((file) => pattern.test(file))
143
+ .map((file) => join(directory, file))
144
+ : [];
145
+
146
+ export const libraryNames = new Set(
147
+ [
148
+ ...(lib === packageRoot
149
+ ? [
150
+ ...filesUnder(join(lib, 'styles'), /\.s?css$/),
151
+ ...filesUnder(join(lib, 'themes'), /\.s?css$/),
152
+ ...filesUnder(join(lib, 'fesm2022'), /\.mjs$/),
153
+ ]
154
+ : filesUnder(lib, /\.(scss|ts)$/)),
155
+ ].flatMap((file) =>
156
+ [...readFileSync(file, 'utf8').matchAll(/(?<![\w-])--[a-zA-Z][\w-]*/g)].map(
157
+ (match) => match[0],
158
+ ),
159
+ ),
160
+ );