@zhin.js/console-ui 0.0.0-stage → 1.1.0

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 (129) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/LICENSE +21 -0
  3. package/README.md +195 -2
  4. package/audit/index.mjs +21 -0
  5. package/audit/layout-audit.mjs +492 -0
  6. package/audit/mount-page.jsx +90 -0
  7. package/audit/plugin-pages.mjs +186 -0
  8. package/dist/cn.d.ts +4 -0
  9. package/dist/cn.js +6 -0
  10. package/dist/components/BrandMark.d.ts +16 -0
  11. package/dist/components/BrandMark.js +21 -0
  12. package/dist/components/InfoHint.d.ts +12 -0
  13. package/dist/components/InfoHint.js +13 -0
  14. package/dist/components/PageHeader.d.ts +18 -0
  15. package/dist/components/PageHeader.js +11 -0
  16. package/dist/components/PageShell.d.ts +26 -0
  17. package/dist/components/PageShell.js +10 -0
  18. package/dist/components/RefreshControl.d.ts +28 -0
  19. package/dist/components/RefreshControl.js +68 -0
  20. package/dist/components/StatCard.d.ts +41 -0
  21. package/dist/components/StatCard.js +53 -0
  22. package/dist/components/StatusBadge.d.ts +14 -0
  23. package/dist/components/StatusBadge.js +19 -0
  24. package/dist/components/actions.d.ts +53 -0
  25. package/dist/components/actions.js +50 -0
  26. package/dist/components/code.d.ts +11 -0
  27. package/dist/components/code.js +10 -0
  28. package/dist/components/confirm-dialog-model.d.ts +9 -0
  29. package/dist/components/confirm-dialog-model.js +20 -0
  30. package/dist/components/confirm-dialog.d.ts +32 -0
  31. package/dist/components/confirm-dialog.js +72 -0
  32. package/dist/components/content-blocks.d.ts +141 -0
  33. package/dist/components/content-blocks.js +77 -0
  34. package/dist/components/empty-illustrations.d.ts +15 -0
  35. package/dist/components/empty-illustrations.js +36 -0
  36. package/dist/components/empty-state.d.ts +35 -0
  37. package/dist/components/empty-state.js +43 -0
  38. package/dist/components/error-alert.d.ts +15 -0
  39. package/dist/components/error-alert.js +23 -0
  40. package/dist/components/icon.d.ts +11 -0
  41. package/dist/components/icon.js +8 -0
  42. package/dist/components/layout.d.ts +38 -0
  43. package/dist/components/layout.js +28 -0
  44. package/dist/components/page-chrome.d.ts +53 -0
  45. package/dist/components/page-chrome.js +66 -0
  46. package/dist/components/refresh-control-model.d.ts +9 -0
  47. package/dist/components/refresh-control-model.js +26 -0
  48. package/dist/components/ui/accordion.d.ts +7 -0
  49. package/dist/components/ui/accordion.js +15 -0
  50. package/dist/components/ui/alert.d.ts +8 -0
  51. package/dist/components/ui/alert.js +24 -0
  52. package/dist/components/ui/badge.d.ts +9 -0
  53. package/dist/components/ui/badge.js +30 -0
  54. package/dist/components/ui/button.d.ts +20 -0
  55. package/dist/components/ui/button.js +52 -0
  56. package/dist/components/ui/card.d.ts +17 -0
  57. package/dist/components/ui/card.js +17 -0
  58. package/dist/components/ui/checkbox.d.ts +4 -0
  59. package/dist/components/ui/checkbox.js +10 -0
  60. package/dist/components/ui/control-variant.d.ts +10 -0
  61. package/dist/components/ui/control-variant.js +6 -0
  62. package/dist/components/ui/date-field-model.d.ts +39 -0
  63. package/dist/components/ui/date-field-model.js +105 -0
  64. package/dist/components/ui/date-field.d.ts +33 -0
  65. package/dist/components/ui/date-field.js +161 -0
  66. package/dist/components/ui/dialog.d.ts +24 -0
  67. package/dist/components/ui/dialog.js +27 -0
  68. package/dist/components/ui/dropdown-menu.d.ts +19 -0
  69. package/dist/components/ui/dropdown-menu.js +26 -0
  70. package/dist/components/ui/input.d.ts +8 -0
  71. package/dist/components/ui/input.js +9 -0
  72. package/dist/components/ui/list-item-button.d.ts +10 -0
  73. package/dist/components/ui/list-item-button.js +6 -0
  74. package/dist/components/ui/popover.d.ts +6 -0
  75. package/dist/components/ui/popover.js +9 -0
  76. package/dist/components/ui/radio-group.d.ts +5 -0
  77. package/dist/components/ui/radio-group.js +10 -0
  78. package/dist/components/ui/scroll-area.d.ts +5 -0
  79. package/dist/components/ui/scroll-area.js +13 -0
  80. package/dist/components/ui/searchable-select-model.d.ts +29 -0
  81. package/dist/components/ui/searchable-select-model.js +38 -0
  82. package/dist/components/ui/searchable-select.d.ts +26 -0
  83. package/dist/components/ui/searchable-select.js +85 -0
  84. package/dist/components/ui/select.d.ts +29 -0
  85. package/dist/components/ui/select.js +39 -0
  86. package/dist/components/ui/separator.d.ts +4 -0
  87. package/dist/components/ui/separator.js +11 -0
  88. package/dist/components/ui/sheet.d.ts +27 -0
  89. package/dist/components/ui/sheet.js +27 -0
  90. package/dist/components/ui/skeleton.d.ts +3 -0
  91. package/dist/components/ui/skeleton.js +6 -0
  92. package/dist/components/ui/switch.d.ts +4 -0
  93. package/dist/components/ui/switch.js +8 -0
  94. package/dist/components/ui/table.d.ts +27 -0
  95. package/dist/components/ui/table.js +47 -0
  96. package/dist/components/ui/tabs.d.ts +7 -0
  97. package/dist/components/ui/tabs.js +13 -0
  98. package/dist/components/ui/textarea.d.ts +8 -0
  99. package/dist/components/ui/textarea.js +9 -0
  100. package/dist/components/ui/tooltip.d.ts +7 -0
  101. package/dist/components/ui/tooltip.js +11 -0
  102. package/dist/components/use-container-width.d.ts +13 -0
  103. package/dist/components/use-container-width.js +30 -0
  104. package/dist/custom-media.css +13 -0
  105. package/dist/exports.json +178 -0
  106. package/dist/i18n/index.d.ts +27 -0
  107. package/dist/i18n/index.js +33 -0
  108. package/dist/i18n/messages.d.ts +55 -0
  109. package/dist/i18n/messages.js +110 -0
  110. package/dist/index.d.ts +56 -0
  111. package/dist/index.js +55 -0
  112. package/dist/scale.json +643 -0
  113. package/dist/shared-module.d.ts +28 -0
  114. package/dist/shared-module.js +24 -0
  115. package/dist/styles.css +3399 -0
  116. package/dist/theme.css +469 -0
  117. package/dist/tokens.css +652 -0
  118. package/dist/version.d.ts +6 -0
  119. package/dist/version.js +2 -0
  120. package/lint/eslint-plugin.mjs +128 -0
  121. package/lint/stylelint-config.mjs +43 -0
  122. package/lint/stylelint-plugin.mjs +195 -0
  123. package/lint/tailwind-classes.mjs +121 -0
  124. package/package.json +103 -3
  125. package/tokens/color.mjs +104 -0
  126. package/tokens/colors.css +220 -0
  127. package/tokens/generate.mjs +288 -0
  128. package/tokens/scale.mjs +137 -0
  129. package/tokens/tokens.mjs +362 -0
@@ -0,0 +1,128 @@
1
+ /**
2
+ * ESLint plugin of @zhin.js/console-ui (`@zhin.js/console-ui/eslint`, ADR 0063 D20 第 1 条).
3
+ *
4
+ * Rules:
5
+ * console-ui/no-arbitrary-values Tailwind arbitrary values of scale utilities (`p-[…]`, `rounded-[…]`,
6
+ * `text-[13px]`, `[padding:…]`); colors from tokens stay allowed
7
+ * console-ui/no-off-scale-classes spacing keys off the 8-step scale (`p-5`, `gap-2.5`), Tailwind
8
+ * default shadows / radii / font sizes / weights, wide borders
9
+ * console-ui/no-native-controls native <button>, <input>, <select>, <textarea>, <table>, <dialog>
10
+ *
11
+ * Classes are read from `className` / `class` attributes and from the arguments of `cn`, `clsx`,
12
+ * `cva`, `cx`, `twMerge`, `classNames` and `tv`.
13
+ *
14
+ * Flat config:
15
+ * import consoleUi from '@zhin.js/console-ui/eslint';
16
+ * export default [consoleUi.configs.recommended]; // all three as errors
17
+ * // or pick: { plugins: { 'console-ui': consoleUi }, rules: { 'console-ui/no-off-scale-classes': 'error' } }
18
+ */
19
+ import { classifyClass } from './tailwind-classes.mjs';
20
+
21
+ const CLASS_FUNCTIONS = new Set(['cn', 'clsx', 'cva', 'cx', 'twMerge', 'classNames', 'tv']);
22
+ const NATIVE_CONTROLS = ['button', 'input', 'select', 'textarea', 'table', 'dialog'];
23
+ const REPLACEMENT = {
24
+ button: 'Button',
25
+ input: 'Input',
26
+ select: 'SelectField / SearchableSelectField',
27
+ textarea: 'Textarea',
28
+ table: 'Table',
29
+ dialog: 'Dialog / ConfirmDialog',
30
+ };
31
+
32
+ function calleeName(node) {
33
+ if (node.type === 'Identifier') return node.name;
34
+ if (node.type === 'MemberExpression' && node.property.type === 'Identifier') return node.property.name;
35
+ return null;
36
+ }
37
+
38
+ /** Whether a string node sits in a class context (className attribute or a class helper call). */
39
+ function inClassContext(sourceCode, node) {
40
+ for (const ancestor of [...sourceCode.getAncestors(node)].reverse()) {
41
+ if (ancestor.type === 'JSXAttribute') {
42
+ const name = ancestor.name.type === 'JSXIdentifier' ? ancestor.name.name : null;
43
+ return name === 'className' || name === 'class';
44
+ }
45
+ if (ancestor.type === 'CallExpression') {
46
+ const name = calleeName(ancestor.callee);
47
+ if (name && CLASS_FUNCTIONS.has(name)) return true;
48
+ }
49
+ }
50
+ return false;
51
+ }
52
+
53
+ function classRule(kind, description) {
54
+ return {
55
+ meta: {
56
+ type: 'problem',
57
+ docs: { description },
58
+ schema: [],
59
+ messages: { finding: '{{message}}' },
60
+ },
61
+ create(context) {
62
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
63
+ const check = (node, text) => {
64
+ if (!text || !inClassContext(sourceCode, node)) return;
65
+ // Object keys (cva variant names) are not classes.
66
+ if (node.parent?.type === 'Property' && node.parent.key === node) return;
67
+ for (const token of text.split(/\s+/u)) {
68
+ if (!token) continue;
69
+ const finding = classifyClass(token);
70
+ if (finding?.rule === kind) context.report({ node, messageId: 'finding', data: { message: finding.message } });
71
+ }
72
+ };
73
+ return {
74
+ Literal(node) {
75
+ if (typeof node.value === 'string') check(node, node.value);
76
+ },
77
+ TemplateElement(node) {
78
+ check(node, node.value.cooked ?? node.value.raw);
79
+ },
80
+ };
81
+ },
82
+ };
83
+ }
84
+
85
+ const noNativeControls = {
86
+ meta: {
87
+ type: 'problem',
88
+ docs: { description: 'Use the @zhin.js/console-ui controls instead of native elements (ADR 0063 D19 / D20 第 6 条)' },
89
+ schema: [{ type: 'object', properties: { allow: { type: 'array', items: { enum: NATIVE_CONTROLS } } }, additionalProperties: false }],
90
+ messages: {
91
+ native: 'Native <{{element}}>: use {{replacement}} from @zhin.js/console-ui (touch size, focus ring, themes, narrow layouts). Exempt only with an inline disable comment that names the reason.',
92
+ },
93
+ },
94
+ create(context) {
95
+ const allow = new Set(context.options[0]?.allow ?? []);
96
+ return {
97
+ JSXOpeningElement(node) {
98
+ if (node.name.type !== 'JSXIdentifier') return;
99
+ const element = node.name.name;
100
+ if (!NATIVE_CONTROLS.includes(element) || allow.has(element)) return;
101
+ context.report({ node, messageId: 'native', data: { element, replacement: REPLACEMENT[element] } });
102
+ },
103
+ };
104
+ },
105
+ };
106
+
107
+ const plugin = {
108
+ meta: { name: '@zhin.js/console-ui/eslint' },
109
+ rules: {
110
+ 'no-arbitrary-values': classRule('arbitrary', 'Disallow Tailwind arbitrary values of scale utilities (ADR 0063 D20)'),
111
+ 'no-off-scale-classes': classRule('off-scale', 'Disallow Tailwind classes off the Console scale (ADR 0063 D17)'),
112
+ 'no-native-controls': noNativeControls,
113
+ },
114
+ configs: {},
115
+ };
116
+
117
+ plugin.configs.recommended = {
118
+ name: '@zhin.js/console-ui/recommended',
119
+ plugins: { 'console-ui': plugin },
120
+ rules: {
121
+ 'console-ui/no-arbitrary-values': 'error',
122
+ 'console-ui/no-off-scale-classes': 'error',
123
+ 'console-ui/no-native-controls': 'error',
124
+ },
125
+ };
126
+
127
+ export default plugin;
128
+ export { plugin as consoleUiEslintPlugin };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Shared stylelint config of ADR 0063 D20 (`@zhin.js/console-ui/stylelint`), for
3
+ * @zhin.js/console-ui itself and for zhinjs/console:
4
+ *
5
+ * // stylelint.config.mjs
6
+ * import { createConsoleStylelintConfig } from '@zhin.js/console-ui/stylelint';
7
+ * export default createConsoleStylelintConfig({
8
+ * shellFiles: ['console-ui/src/shell\\.css$', 'console-ui/src/layouts/'], // may use @media
9
+ * });
10
+ *
11
+ * Options:
12
+ * shellFiles regex sources of files allowed to use @media (global shell only)
13
+ * semanticOnly components read tier-2 tokens only (default true)
14
+ * allowTierOneIn regex sources of files that may read tier-1 spacing / radius / elevation
15
+ * deprecatedTokens severity of `console/no-deprecated-tokens` ('error' default; 'warning'
16
+ * while a codebase moves off the old names, until P4)
17
+ * motionTokens severity of `console/motion-tokens` ('error' default; 'warning' while a
18
+ * codebase moves its transitions onto the motion tokens; false turns it off)
19
+ */
20
+ import plugins from './stylelint-plugin.mjs';
21
+
22
+ export function createConsoleStylelintConfig({
23
+ shellFiles = [],
24
+ semanticOnly = true,
25
+ allowTierOneIn = [],
26
+ deprecatedTokens = 'error',
27
+ motionTokens = 'error',
28
+ ignoreFiles = [],
29
+ } = {}) {
30
+ return {
31
+ plugins,
32
+ ignoreFiles: ['**/node_modules/**', '**/dist/**', ...ignoreFiles],
33
+ rules: {
34
+ 'console/scale-values': [true, { semanticOnly, allowTierOneIn }],
35
+ 'console/no-unknown-tokens': true,
36
+ 'console/no-deprecated-tokens': [true, { severity: deprecatedTokens }],
37
+ 'console/media-queries': [true, { shellFiles }],
38
+ 'console/motion-tokens': motionTokens ? [true, { severity: motionTokens }] : null,
39
+ },
40
+ };
41
+ }
42
+
43
+ export default createConsoleStylelintConfig();
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Stylelint plugin of @zhin.js/console-ui (`@zhin.js/console-ui/stylelint-plugin`, ADR 0063 D20 第 1 条).
3
+ *
4
+ * Rules (allowed values come from tokens/scale.mjs, the same derivation as the generated files):
5
+ * console/scale-values font-size, font-weight, border-radius, box-shadow, border-width,
6
+ * padding, margin, gap: only `0`, keywords and `var(--console-…)`
7
+ * (also inside calc / min / max / clamp). With `{ semanticOnly: true }`
8
+ * spacing, radius and elevation must be tier-2 (semantic) tokens.
9
+ * console/no-unknown-tokens `var(--console-…)` names that are not defined
10
+ * console/no-deprecated-tokens old names kept as aliases until P4 (`--console-radius-md`, …)
11
+ * console/media-queries `@media` only in shell files (`{ shellFiles: [regex…] }`) and only
12
+ * with the generated breakpoints; `@container` only with breakpoints
13
+ * console/motion-tokens transition / animation (and their -duration / -delay /
14
+ * -timing-function): no time literals (`150ms`, `0.2s`) and no easing
15
+ * literals (`ease`, `cubic-bezier(…)`); use --console-motion-fast /
16
+ * -base / -slow and --console-ease-out (zhinjs/console#125). The
17
+ * `prefers-reduced-motion: reduce` reset is exempt.
18
+ */
19
+ import stylelint from 'stylelint';
20
+ import { buildScale } from '../tokens/scale.mjs';
21
+
22
+ const { createPlugin, utils } = stylelint;
23
+ const scale = buildScale();
24
+ const BASE = new Set(scale.css.baseTokens);
25
+ const SEMANTIC = new Set(scale.css.semanticTokens);
26
+ const ALIASES = new Set(scale.css.aliasTokens.filter((name) => name.startsWith('--console-')));
27
+ const KNOWN = new Set([...BASE, ...SEMANTIC, ...ALIASES]);
28
+ /** Tier-1 tokens that have semantic replacements (D16: components use tier 2). */
29
+ const TIER_ONE_SIZED = /^--console-(?:space-[1-8]|radius-(?:\d|full)|elevation-\d|border-(?:hairline|focus))$/u;
30
+ const MEDIA = new Set(scale.css.mediaParams.map(normalizeParams));
31
+ const CONTAINER = new Set(scale.css.containerParams.map(normalizeParams));
32
+ const CUSTOM_MEDIA = new Set(Object.keys(scale.css.customMedia));
33
+
34
+ const GOVERNED = /^(?:font-size|font-weight|border(?:-(?:top|right|bottom|left|block|inline)(?:-(?:start|end))?)?(?:-width)?|border-width|border-(?:top|bottom|start|end)-(?:left|right|start|end)-radius|border-radius|box-shadow|padding(?:-[a-z-]+)?|margin(?:-[a-z-]+)?|gap|row-gap|column-gap)$/u;
35
+ const KEYWORDS = new Set(['inherit', 'initial', 'unset', 'revert', 'revert-layer', 'none', 'normal', 'auto', 'solid', 'dashed', 'dotted', 'double', 'transparent', 'currentcolor']);
36
+
37
+ function normalizeParams(params) {
38
+ return params.replace(/\s+/gu, ' ').replace(/\(\s+/gu, '(').replace(/\s+\)/gu, ')').trim().toLowerCase();
39
+ }
40
+
41
+ /** Removes balanced `name(...)` calls for the given function names. */
42
+ function stripCalls(value, names) {
43
+ let out = value;
44
+ for (;;) {
45
+ const match = new RegExp(`\\b(?:${names.join('|')})\\(`, 'iu').exec(out);
46
+ if (!match) return out;
47
+ let depth = 0;
48
+ let end = match.index + match[0].length - 1;
49
+ for (; end < out.length; end += 1) {
50
+ if (out[end] === '(') depth += 1;
51
+ else if (out[end] === ')') { depth -= 1; if (depth === 0) break; }
52
+ }
53
+ out = `${out.slice(0, match.index)} ${out.slice(end + 1)}`;
54
+ }
55
+ }
56
+
57
+ function varsIn(value) {
58
+ return [...value.matchAll(/var\(\s*(--[a-z0-9-]+)/giu)].map((match) => match[1]);
59
+ }
60
+
61
+ /** Literal values left after removing allowed parts (tokens, keywords, colors in borders). */
62
+ function literalsIn(property, value) {
63
+ let rest = value.replace(/!important/giu, '');
64
+ rest = stripCalls(rest, ['var', 'env']);
65
+ if (/^border/u.test(property) && !/radius/u.test(property)) rest = stripCalls(rest, ['hsl', 'hsla', 'rgb', 'rgba', 'oklch', 'oklab', 'color-mix']).replace(/#[0-9a-f]{3,8}\b/giu, ' ');
66
+ rest = rest.replace(/\b(?:calc|min|max|clamp)\(/giu, ' ').replace(/[(),*+/]/gu, ' ');
67
+ const literals = [];
68
+ for (const word of rest.split(/\s+/u).filter(Boolean)) {
69
+ if (KEYWORDS.has(word.toLowerCase())) continue;
70
+ if (/^-$/u.test(word)) continue;
71
+ const number = /^-?(\d*\.?\d+)([a-z%]*)$/iu.exec(word);
72
+ if (number) {
73
+ if (Number(number[1]) === 0) continue;
74
+ if (!number[2] && property !== 'font-weight') continue; // calc multipliers
75
+ literals.push(word);
76
+ continue;
77
+ }
78
+ if (property === 'font-weight' && /^(?:bold|bolder|lighter)$/iu.test(word)) literals.push(word);
79
+ }
80
+ return literals;
81
+ }
82
+
83
+ const scaleValuesName = 'console/scale-values';
84
+ const scaleValues = createPlugin(scaleValuesName, (primary, secondary = {}) => (root, result) => {
85
+ if (!utils.validateOptions(result, scaleValuesName, { actual: primary })) return;
86
+ const semanticOnly = Boolean(secondary.semanticOnly);
87
+ const allowTierOne = (secondary.allowTierOneIn ?? []).map((source) => new RegExp(source, 'u'));
88
+ const file = root.source?.input.file ?? '';
89
+ const tierOneAllowed = allowTierOne.some((pattern) => pattern.test(file));
90
+ root.walkDecls((decl) => {
91
+ const property = decl.prop.toLowerCase();
92
+ if (property.startsWith('--') || !GOVERNED.test(property)) return;
93
+ if (property === 'box-shadow' && /\b(?:hsla?|rgba?|oklch)\(|#[0-9a-f]{3,8}\b/iu.test(stripCalls(decl.value, ['var']))) {
94
+ utils.report({ ruleName: scaleValuesName, result, node: decl, message: `box-shadow: literal shadow; use an elevation token (ADR 0063 D16) (${scaleValuesName})` });
95
+ return;
96
+ }
97
+ for (const literal of literalsIn(property, decl.value)) {
98
+ utils.report({ ruleName: scaleValuesName, result, node: decl, word: literal, message: `${property}: literal "${literal}"; use a Console token (var(--console-…)) or 0 (ADR 0063 D20) (${scaleValuesName})` });
99
+ }
100
+ if (semanticOnly && !tierOneAllowed) {
101
+ for (const name of varsIn(decl.value)) {
102
+ if (TIER_ONE_SIZED.test(name)) {
103
+ utils.report({ ruleName: scaleValuesName, result, node: decl, word: name, message: `${property}: ${name} is a base-scale token; components use semantic tokens (ADR 0063 D16) (${scaleValuesName})` });
104
+ }
105
+ }
106
+ }
107
+ });
108
+ });
109
+ scaleValues.ruleName = scaleValuesName;
110
+
111
+ const unknownName = 'console/no-unknown-tokens';
112
+ const unknownTokens = createPlugin(unknownName, (primary) => (root, result) => {
113
+ if (!utils.validateOptions(result, unknownName, { actual: primary })) return;
114
+ const defined = new Set();
115
+ root.walkDecls(/^--console-/u, (decl) => defined.add(decl.prop));
116
+ root.walkDecls((decl) => {
117
+ for (const name of varsIn(decl.value)) {
118
+ if (!name.startsWith('--console-') || KNOWN.has(name) || defined.has(name)) continue;
119
+ utils.report({ ruleName: unknownName, result, node: decl, word: name, message: `${name} is not a Console token (${unknownName})` });
120
+ }
121
+ });
122
+ });
123
+
124
+ const deprecatedName = 'console/no-deprecated-tokens';
125
+ const deprecatedTokens = createPlugin(deprecatedName, (primary) => (root, result) => {
126
+ if (!utils.validateOptions(result, deprecatedName, { actual: primary })) return;
127
+ root.walkDecls((decl) => {
128
+ for (const name of varsIn(decl.value)) {
129
+ if (ALIASES.has(name)) utils.report({ ruleName: deprecatedName, result, node: decl, word: name, message: `${name} is deprecated (alias until ADR 0063 P4); use its successor (${deprecatedName})` });
130
+ }
131
+ });
132
+ });
133
+
134
+ const mediaName = 'console/media-queries';
135
+ const mediaQueries = createPlugin(mediaName, (primary, secondary = {}) => (root, result) => {
136
+ if (!utils.validateOptions(result, mediaName, { actual: primary })) return;
137
+ const shellFiles = (secondary.shellFiles ?? []).map((source) => new RegExp(source, 'u'));
138
+ const file = root.source?.input.file ?? '';
139
+ const isShell = shellFiles.some((pattern) => pattern.test(file));
140
+ root.walkAtRules((rule) => {
141
+ const name = rule.name.toLowerCase();
142
+ if (name === 'media') {
143
+ if (!isShell) {
144
+ utils.report({ ruleName: mediaName, result, node: rule, message: `@media only in shell files; components follow their container (@container), ADR 0063 D18 (${mediaName})` });
145
+ return;
146
+ }
147
+ for (const query of rule.params.split(',')) {
148
+ for (const part of query.split(/\band\b/iu)) {
149
+ const normalized = normalizeParams(part);
150
+ const custom = /^\((--[a-z0-9-]+)\)$/u.exec(normalized);
151
+ if (custom ? CUSTOM_MEDIA.has(custom[1]) : MEDIA.has(normalized)) continue;
152
+ utils.report({ ruleName: mediaName, result, node: rule, word: part.trim(), message: `@media ${part.trim()}: only the Console breakpoints (${Object.keys(scale.css.customMedia).filter((key) => !key.includes('below')).join(', ')}) and user preferences (${mediaName})` });
153
+ }
154
+ }
155
+ }
156
+ if (name === 'container') {
157
+ const params = normalizeParams(rule.params.replace(/^[a-z][a-z0-9-]*\s+(?=\()/iu, ''));
158
+ if (!CONTAINER.has(params)) {
159
+ utils.report({ ruleName: mediaName, result, node: rule, message: `@container ${rule.params}: only the Console breakpoints (${Object.values(scale.breakpoints).join(', ')}) (${mediaName})` });
160
+ }
161
+ }
162
+ });
163
+ });
164
+
165
+ const motionName = 'console/motion-tokens';
166
+ const MOTION_PROPERTY = /^(?:transition|animation)(?:-(?:duration|delay|timing-function))?$/u;
167
+ const EASING_KEYWORDS = new Set(['ease', 'ease-in', 'ease-out', 'ease-in-out']);
168
+
169
+ function inReducedMotionReset(node) {
170
+ for (let parent = node.parent; parent; parent = parent.parent) {
171
+ if (parent.type === 'atrule' && parent.name.toLowerCase() === 'media' && /prefers-reduced-motion:\s*reduce/iu.test(parent.params)) return true;
172
+ }
173
+ return false;
174
+ }
175
+
176
+ const motionTokens = createPlugin(motionName, (primary) => (root, result) => {
177
+ if (!utils.validateOptions(result, motionName, { actual: primary })) return;
178
+ root.walkDecls((decl) => {
179
+ const property = decl.prop.toLowerCase();
180
+ if (!MOTION_PROPERTY.test(property) || inReducedMotionReset(decl)) return;
181
+ const rest = stripCalls(decl.value, ['var', 'env']);
182
+ for (const match of rest.matchAll(/(?<![\w-])(-?\d*\.?\d+)(ms|s)\b/giu)) {
183
+ if (Number(match[1]) === 0) continue;
184
+ utils.report({ ruleName: motionName, result, node: decl, word: match[0], message: `${property}: literal duration "${match[0]}"; use var(--console-motion-fast | -base | -slow) (zhinjs/console#125) (${motionName})` });
185
+ }
186
+ const easings = [...rest.matchAll(/\b(?:cubic-bezier|steps)\(/giu)].map((match) => match[0].slice(0, -1));
187
+ easings.push(...rest.split(/[\s,]+/u).filter((word) => EASING_KEYWORDS.has(word.toLowerCase())));
188
+ for (const easing of easings) {
189
+ utils.report({ ruleName: motionName, result, node: decl, word: easing, message: `${property}: literal easing "${easing}"; use var(--console-ease-out) (zhinjs/console#125) (${motionName})` });
190
+ }
191
+ });
192
+ });
193
+
194
+ export const consoleStylelintPlugins = [scaleValues, unknownTokens, deprecatedTokens, mediaQueries, motionTokens];
195
+ export default consoleStylelintPlugins;
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Tailwind class checks of ADR 0063 D17 / D20, shared by the ESLint plugin
3
+ * (`@zhin.js/console-ui/eslint`) and `zhin plugin check` (`@zhin.js/console-ui/tailwind-classes`).
4
+ *
5
+ * classifyClass('p-5') → { rule: 'off-scale', … } spacing key not in 0, px, 1, 2, 3, 4, 6, 8, 12, 16
6
+ * classifyClass('p-[5px]') → { rule: 'arbitrary', … } arbitrary value of a scale utility
7
+ * classifyClass('shadow-md') → { rule: 'off-scale', … } Tailwind default shadow
8
+ * classifyClass('h-11') → null sizing keys are not limited by the spacing scale
9
+ * classifyClass('bg-[hsl(var(--primary))]') → null colors from theme tokens are fine
10
+ *
11
+ * The allowed keys come from tokens/scale.mjs, the same derivation as the generated theme.
12
+ */
13
+ import { buildScale } from '../tokens/scale.mjs';
14
+
15
+ const scale = buildScale();
16
+ const SPACING = new Set(scale.tailwind.spacingKeys);
17
+ const SIZING = new Set(scale.tailwind.sizingKeys);
18
+ const RADIUS = new Set(scale.tailwind.radiusKeys);
19
+ const SHADOW = new Set(scale.tailwind.shadowKeys);
20
+ const TEXT = new Set(scale.tailwind.textKeys);
21
+ const WEIGHT = new Set(scale.tailwind.fontWeightKeys);
22
+
23
+ const TAILWIND_TEXT_SIZES = new Set(['xs', 'sm', 'base', 'lg', 'xl', '2xl', '3xl', '4xl', '5xl', '6xl', '7xl', '8xl', '9xl']);
24
+ const TAILWIND_WEIGHTS = new Set(['thin', 'extralight', 'light', 'normal', 'semibold', 'bold', 'extrabold', 'black']);
25
+ const GOVERNED_PROPERTIES = /^\[(?:padding|margin|gap|row-gap|column-gap|font-size|font-weight|border-radius|box-shadow|border(?:-[a-z]+)?-width)(?:-[a-z]+)?:/u;
26
+ const COLOR_VALUE = /^\[(?:color:|hsl|rgb|oklch|oklab|lab|lch|hwb|#|transparent|currentcolor)/iu;
27
+
28
+ /** Splits off variants (`md:hover:p-4` → `p-4`), the important flag and the negative sign. */
29
+ export function utilityOf(token) {
30
+ let depth = 0;
31
+ let start = 0;
32
+ for (let index = 0; index < token.length; index += 1) {
33
+ const char = token[index];
34
+ if (char === '[' || char === '(') depth += 1;
35
+ else if (char === ']' || char === ')') depth -= 1;
36
+ else if (char === ':' && depth === 0) start = index + 1;
37
+ }
38
+ return token.slice(start).replace(/^!|!$/gu, '').replace(/^-/u, '').replace(/\/[^/\]]+$/u, (opacity) => (opacity.includes('[') ? opacity : ''));
39
+ }
40
+
41
+ const isArbitrary = (value) => value.startsWith('[') || value.startsWith('(');
42
+
43
+ /**
44
+ * @param {string} token one class name
45
+ * @returns {null | { rule: 'arbitrary' | 'off-scale', message: string }}
46
+ */
47
+ export function classifyClass(token) {
48
+ const utility = utilityOf(token);
49
+ if (!utility) return null;
50
+ // CSS-wide keywords carry no value of their own (`rounded-[inherit]`).
51
+ if (/-\[(?:inherit|initial|unset|revert)\]$/u.test(utility)) return null;
52
+ const arbitrary = (what) => ({ rule: 'arbitrary', message: `\`${token}\`: arbitrary ${what} value; use a scale key or a component (ADR 0063 D20)` });
53
+ const offScale = (what, allowed) => ({ rule: 'off-scale', message: `\`${token}\`: ${what} is not on the scale (allowed: ${allowed}); see ADR 0063 D17` });
54
+
55
+ if (GOVERNED_PROPERTIES.test(utility)) return arbitrary('property');
56
+
57
+ let match = /^(?:p[xytrblse]?|p(?:bs|be)|m[xytrblse]?|m(?:bs|be)|gap(?:-[xy])?|space-[xy])-(.+)$/u.exec(utility);
58
+ if (match) {
59
+ const value = match[1];
60
+ if (isArbitrary(value)) return arbitrary('spacing');
61
+ if (value === 'auto' || value === 'reverse') return null;
62
+ if (!SPACING.has(value)) return offScale('spacing key', [...SPACING].join(', '));
63
+ return null;
64
+ }
65
+
66
+ match = /^(?:w|h|size|min-w|min-h|max-w|max-h|inset(?:-[xy])?|top|right|bottom|left|start|end|translate-[xy]|basis)-(.+)$/u.exec(utility);
67
+ if (match) {
68
+ const value = match[1];
69
+ if (/^\d+(?:\.\d+)?$/u.test(value) && !SIZING.has(value)) return offScale('size key', 'Tailwind numeric keys up to 96 and control, control-compact, touch, touch-min, badge');
70
+ return null;
71
+ }
72
+
73
+ match = /^rounded(?:-(?:t|r|b|l|tl|tr|br|bl|s|e|ss|se|es|ee))?(?:-(.+))?$/u.exec(utility);
74
+ if (match) {
75
+ const value = match[1];
76
+ if (value === undefined) return offScale('bare `rounded`', [...RADIUS].map((key) => `rounded-${key}`).join(', '));
77
+ if (isArbitrary(value)) return arbitrary('radius');
78
+ if (!RADIUS.has(value)) return offScale('radius key', [...RADIUS].join(', '));
79
+ return null;
80
+ }
81
+
82
+ match = /^shadow(?:-(.+))?$/u.exec(utility);
83
+ if (match) {
84
+ const value = match[1];
85
+ if (value === undefined) return offScale('bare `shadow`', [...SHADOW].map((key) => `shadow-${key}`).join(', '));
86
+ if (isArbitrary(value)) return arbitrary('shadow');
87
+ if (!SHADOW.has(value)) return offScale('shadow', [...SHADOW].join(', '));
88
+ return null;
89
+ }
90
+
91
+ match = /^text-(.+)$/u.exec(utility);
92
+ if (match) {
93
+ const value = match[1];
94
+ if (isArbitrary(value)) return COLOR_VALUE.test(value) ? null : arbitrary('font-size');
95
+ if (TAILWIND_TEXT_SIZES.has(value)) return offScale('font size', [...TEXT].map((key) => `text-${key}`).join(', '));
96
+ return null;
97
+ }
98
+
99
+ match = /^font-(.+)$/u.exec(utility);
100
+ if (match) {
101
+ const value = match[1];
102
+ if (isArbitrary(value)) return arbitrary('font');
103
+ if (TAILWIND_WEIGHTS.has(value)) return offScale('font weight', [...WEIGHT].map((key) => `font-${key}`).join(', '));
104
+ return null;
105
+ }
106
+
107
+ match = /^border(?:-[xytrblse])?-(\d+|\[.+\]|\(.+\))$/u.exec(utility);
108
+ if (match) {
109
+ const value = match[1];
110
+ if (isArbitrary(value)) return COLOR_VALUE.test(value) ? null : arbitrary('border width');
111
+ if (value !== '0') return offScale('border width', 'border (hairline), border-0');
112
+ return null;
113
+ }
114
+
115
+ return null;
116
+ }
117
+
118
+ /** All findings in a whitespace-separated class string. */
119
+ export function classifyClassList(value) {
120
+ return value.split(/\s+/u).filter(Boolean).map((token) => ({ token, finding: classifyClass(token) })).filter((entry) => entry.finding);
121
+ }
package/package.json CHANGED
@@ -1,6 +1,106 @@
1
1
  {
2
2
  "name": "@zhin.js/console-ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.1.0",
4
+ "description": "Zhin Console component library: shared React components, page shell and design tokens for the Console and plugin pages, with precompiled CSS (ADR 0063)",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "sideEffects": [
9
+ "*.css"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ },
16
+ "./cn": {
17
+ "types": "./dist/cn.d.ts",
18
+ "import": "./dist/cn.js"
19
+ },
20
+ "./styles.css": "./dist/styles.css",
21
+ "./tokens.css": "./dist/tokens.css",
22
+ "./exports.json": "./dist/exports.json",
23
+ "./theme.css": "./dist/theme.css",
24
+ "./custom-media.css": "./dist/custom-media.css",
25
+ "./scale.json": "./dist/scale.json",
26
+ "./tokens": "./tokens/tokens.mjs",
27
+ "./scale": "./tokens/scale.mjs",
28
+ "./stylelint": "./lint/stylelint-config.mjs",
29
+ "./stylelint-plugin": "./lint/stylelint-plugin.mjs",
30
+ "./eslint": "./lint/eslint-plugin.mjs",
31
+ "./tailwind-classes": "./lint/tailwind-classes.mjs",
32
+ "./audit": "./audit/index.mjs",
33
+ "./package.json": "./package.json"
34
+ },
35
+ "dependencies": {
36
+ "class-variance-authority": "^0.7.1",
37
+ "clsx": "^2.1.1",
38
+ "lucide-react": "^1.16.0",
39
+ "radix-ui": "^1.4.3",
40
+ "tailwind-merge": "^3.6.0"
41
+ },
42
+ "peerDependencies": {
43
+ "react": ">=18",
44
+ "react-dom": ">=18",
45
+ "@playwright/test": ">=1.50",
46
+ "esbuild": ">=0.25",
47
+ "stylelint": ">=16"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "@playwright/test": {
51
+ "optional": true
52
+ },
53
+ "esbuild": {
54
+ "optional": true
55
+ },
56
+ "stylelint": {
57
+ "optional": true
58
+ }
59
+ },
60
+ "devDependencies": {
61
+ "@playwright/test": "1.62.1",
62
+ "@types/react": "^19.2.18",
63
+ "@types/react-dom": "^19.2.4",
64
+ "esbuild": "^0.28.1",
65
+ "react": "^19.2.8",
66
+ "react-dom": "^19.2.8",
67
+ "rimraf": "^6.1.4",
68
+ "stylelint": "17.16.0",
69
+ "tailwindcss": "4.3.3",
70
+ "typescript": "^6.0.3"
71
+ },
72
+ "files": [
73
+ "dist",
74
+ "tokens",
75
+ "lint",
76
+ "audit",
77
+ "README.md",
78
+ "CHANGELOG.md"
79
+ ],
80
+ "repository": {
81
+ "type": "git",
82
+ "url": "git+https://github.com/zhinjs/zhin.git",
83
+ "directory": "packages/console/ui"
84
+ },
85
+ "publishConfig": {
86
+ "access": "public",
87
+ "registry": "https://registry.npmjs.org"
88
+ },
89
+ "license": "MIT",
90
+ "author": {
91
+ "name": "lc-cn",
92
+ "email": "admin@liucl.cn",
93
+ "url": "https://github.com/lc-cn"
94
+ },
95
+ "engines": {
96
+ "node": ">=22.19.0"
97
+ },
98
+ "scripts": {
99
+ "build": "node scripts/build.mjs",
100
+ "clean": "rimraf dist",
101
+ "test": "vitest run --root ../../.. packages/console/ui/tests",
102
+ "test:visual": "playwright test --config visual/playwright.config.ts console-ui.spec.ts",
103
+ "test:audit": "playwright test --config visual/playwright.config.ts audit.spec.ts",
104
+ "lint:css": "stylelint \"client/styles/**/*.css\" && node tokens/generate.mjs --check"
105
+ }
6
106
  }