@q1travel/design-system 0.30.12 → 0.30.14

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.
package/README.md CHANGED
@@ -71,7 +71,7 @@ root.render(
71
71
  | --- | --- |
72
72
  | `npx q1-design ls` | 列出包内提供的组件、hook 与应用模板 |
73
73
  | `npx q1-design doc <组件名>` | 打印组件的公共 API;`doc app-base` 查看应用基础样式模板 |
74
- | `npx q1-design lint [路径...]` | 按 `Q1-DS-*` 规则检查样式用法,默认扫描 `src` |
74
+ | `npx q1-design lint [路径...]` | 按 `Q1-DS-*` 规则检查样式和组件枚举字面量,默认扫描 `src` |
75
75
  | `npx q1-design lint --diff <base-ref>` | 只检查相对 `base-ref` 有改动的文件 |
76
76
  | `npx q1-design overrides [路径...]` | 统计对组件外观的 `className` 覆写 |
77
77
  | `npx q1-design sync` | 将设计契约与 AI 编码指南同步为项目内的只读缓存 |
@@ -89,7 +89,7 @@ mkdir -p src/styles
89
89
  cp .claude/skills/product-design/contracts/app-base.css src/styles/app-base.css
90
90
  ```
91
91
 
92
- 在应用入口先引入 `@q1travel/design-system/tokens.css`(已引入 `style.css` 时无需重复),再引入 `./styles/app-base.css`。应用可修改该副本或在之后加载覆盖样式;升级并重新 `sync` 后自行审阅模板差异再采纳,CLI 不覆盖应用副本。模板只包含盒模型、页面边距与最小高度、画布文字字体与字体平滑、点按高亮、原生表单字体继承;根容器、读屏工具与组件运动/触控行为由各自所属层管理。
92
+ 在应用入口先引入 `@q1travel/design-system/tokens.css`(已引入 `style.css` 时无需重复),再引入 `./styles/app-base.css`。应用可修改该副本或在之后加载覆盖样式;升级并重新 `sync` 后自行审阅模板差异再采纳,CLI 不覆盖应用副本。模板只包含盒模型、页面边距与最小高度、画布文字字体与字体平滑、点按高亮;根容器、读屏工具与组件运动/触控行为由各自所属层管理。组件自带字体继承;应用中的非设计系统原生控件需自行处理字体。已复制旧模板的应用可保留或删除 `button, input, textarea, select { font: inherit; }`,按自身原生控件需求决定。
93
93
 
94
94
  ## 版本
95
95
 
@@ -0,0 +1,42 @@
1
+ export const COMPONENT_ENUM_RULE = 'Q1-DS-002';
2
+
3
+ // Match the CLI's import-based scan; only literal JSX attributes are checked.
4
+ export function lintComponentEnums(source, filename, loadSchema) {
5
+ const imports = new Map();
6
+ const importPattern = /import\s*\{([^{}]*?)\}\s*from\s*["']@q1travel\/design-system["']/gs;
7
+ for (const match of source.matchAll(importPattern)) {
8
+ for (const part of match[1].split(',')) {
9
+ if (/^\s*type\s/.test(part)) continue;
10
+ const [component, local = component] = part.trim().split(/\s+as\s+/);
11
+ if (/^[A-Z][A-Za-z0-9_]*$/.test(local)) imports.set(local, component);
12
+ }
13
+ }
14
+ for (const match of source.matchAll(/import\s*\*\s*as\s+(\w+)\s*from\s*["']@q1travel\/design-system["']/g)) {
15
+ imports.set(`${match[1]}.*`, '*');
16
+ }
17
+ if (!imports.size) return [];
18
+ const hits = [];
19
+ const tagPattern = /<([A-Z][\w.]*)\b((?:"[^"]*"|'[^']*'|\{(?:[^{}]|\{[^{}]*\})*\}|[^>"'{}])*)>/g;
20
+ for (const tag of source.matchAll(tagPattern)) {
21
+ const [namespace, member] = tag[1].split('.');
22
+ const component = member && imports.has(`${namespace}.*`) ? member : imports.get(tag[1]);
23
+ if (!component) continue;
24
+ const attributes = /(?:^|\s)(variant|size)\s*=\s*(?:"([^"]*)"|'([^']*)'|\{\s*(?:"([^"]*)"|'([^']*)')\s*\})/g;
25
+ for (const attribute of tag[2].matchAll(attributes)) {
26
+ let value = attribute[2] ?? attribute[3] ?? attribute[4] ?? attribute[5];
27
+ if (attribute[2] !== undefined || attribute[3] !== undefined) {
28
+ value = value.replace(/&#(x[\da-f]+|\d+);/gi, (_, code) => String.fromCodePoint(code[0].toLowerCase() === 'x' ? parseInt(code.slice(1), 16) : Number(code)));
29
+ }
30
+ const allowed = loadSchema()[component]?.[attribute[1]];
31
+ if (allowed && !allowed.includes(value)) {
32
+ const offset = tag.index + tag[0].indexOf(tag[2]) + attribute.index;
33
+ hits.push({
34
+ ruleId: COMPONENT_ENUM_RULE,
35
+ lineNumber: source.slice(0, offset + attribute[0].search(/\S/)).split('\n').length,
36
+ lineContent: `error ${component}.${attribute[1]}=${JSON.stringify(value)}; 允许值: ${allowed.join(' | ')}`,
37
+ });
38
+ }
39
+ }
40
+ }
41
+ return hits;
42
+ }
package/bin/q1-design.mjs CHANGED
@@ -22,6 +22,8 @@ import { createHash } from 'node:crypto';
22
22
  import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
23
23
  import { fileURLToPath, pathToFileURL } from 'node:url';
24
24
 
25
+ import { COMPONENT_ENUM_RULE, lintComponentEnums } from './lint-component-enums.mjs';
26
+
25
27
  const PACKAGE_NAME = '@q1travel/design-system';
26
28
  const SKILL_RELATIVE_DIR = '.claude/skills/product-design';
27
29
  const MANIFEST_FILE_NAME = '.q1-design-manifest.json';
@@ -644,6 +646,17 @@ const LINT_RULES = [
644
646
  function collectLintHits(inputPaths, baseDir) {
645
647
  const targetFiles = collectLintTargetFiles(inputPaths, baseDir);
646
648
  const hits = [];
649
+ let enumSchema;
650
+ const loadEnumSchema = () => {
651
+ if (!enumSchema) {
652
+ const relativePath = 'dist-pkg/component-enums.json';
653
+ const packageRoot = resolveInstalledPackageRoot(baseDir) ?? baseDir;
654
+ const schemaPath = join(packageRoot, relativePath);
655
+ if (!existsSync(schemaPath)) throw new Error(`[q1-design] 找不到 ${relativePath},无法检查组件枚举;请安装 ${PACKAGE_NAME} 或先运行 npm run build:lib。`);
656
+ enumSchema = JSON.parse(readFileSync(schemaPath, 'utf8'));
657
+ }
658
+ return enumSchema;
659
+ };
647
660
 
648
661
  for (const absoluteFilePath of targetFiles) {
649
662
  const fileContent = readFileSync(absoluteFilePath, 'utf8');
@@ -653,6 +666,14 @@ function collectLintHits(inputPaths, baseDir) {
653
666
  isTokens: isTokensPath(absoluteFilePath, baseDir),
654
667
  };
655
668
 
669
+ if (!fileFacts.isCssFile && !hasFileDisablePragma(fileContent, COMPONENT_ENUM_RULE)) {
670
+ const isSuppressed = createSuppressionTracker(COMPONENT_ENUM_RULE);
671
+ const suppressedLines = fileContent.split('\n').map((line) => isSuppressed(line));
672
+ for (const hit of lintComponentEnums(fileContent, absoluteFilePath, loadEnumSchema)) {
673
+ if (!suppressedLines[hit.lineNumber - 1]) hits.push({ ...hit, filePath: relativeFilePath });
674
+ }
675
+ }
676
+
656
677
  const activeRules = LINT_RULES.map((rule) => ({
657
678
  rule,
658
679
  applicable: rule.appliesToFile(fileFacts) && !hasFileDisablePragma(fileContent, rule.ruleId),
@@ -717,7 +738,7 @@ function runLint(inputPaths, consumerRootDir, diffBaseRef) {
717
738
 
718
739
  for (const hit of hits) {
719
740
  console.log(
720
- `${hit.ruleId} ${hit.filePath}:${hit.lineNumber} ${truncateLine(hit.lineContent)}`,
741
+ `${hit.ruleId} ${hit.filePath}:${hit.lineNumber} ${hit.ruleId === COMPONENT_ENUM_RULE ? hit.lineContent : truncateLine(hit.lineContent)}`,
721
742
  );
722
743
  }
723
744
  console.log(`[q1-design] 共 ${hits.length} 处命中`);
@@ -1109,7 +1130,12 @@ if (isDirectRun) {
1109
1130
  }
1110
1131
  args.splice(diffIndex, 2);
1111
1132
  }
1112
- runLint(args.length > 0 ? args : ['src'], consumerRootDir, diffBaseRef);
1133
+ try {
1134
+ runLint(args.length > 0 ? args : ['src'], consumerRootDir, diffBaseRef);
1135
+ } catch (error) {
1136
+ console.error(error.message);
1137
+ process.exit(1);
1138
+ }
1113
1139
  } else if (subcommand === 'eval') {
1114
1140
  runEval();
1115
1141
  } else if (subcommand === 'overrides') {
@@ -29,10 +29,3 @@ html {
29
29
  height: 100%;
30
30
  -webkit-tap-highlight-color: transparent;
31
31
  }
32
-
33
- button,
34
- input,
35
- textarea,
36
- select {
37
- font: inherit;
38
- }
@@ -30,6 +30,16 @@ Package-owned semantics are applied after native props. `type`, `className`, `di
30
30
 
31
31
  Button preserves an explicitly supplied native `aria-busy` when `busy` is false, including during `loading`; `loading` alone still does not add it. This lets consumers announce an external task immediately while controlling visual loading separately. `busy=true` always sets `aria-busy="true"`, even when a consumer passes false. ButtonLink keeps its existing package-owned busy semantics.
32
32
 
33
+ ## IconButton Attention
34
+
35
+ `attention?: boolean` is opt-in. Only `attention={true}` adds `data-icon-button-attention="true"` to the existing button. Omitting it or passing false preserves the previous markup and styling without a new class or wrapper.
36
+
37
+ The first direct child must be an icon or an icon-only container. Subsequent children may include a static Badge. Only that first element rotates, once, using the existing slow duration and in-out easing tokens. The button, Badge, layout, accessible name, native keyboard activation, and focus remain unchanged.
38
+
39
+ A persistent true value does not replay on rerender, hover, or focus. A committed false state observed by the browser, followed by true, starts another finite cycle. Batched false-to-true updates do not promise replay. No timer or background replay queue is provided.
40
+
41
+ Under `prefers-reduced-motion: reduce`, no attention animation runs and the static count remains visible. Consumers include the unread count in the accessible name and own count positioning.
42
+
33
43
  ## Loading and Busy States
34
44
 
35
45
  `loading` and `busy` are intentionally different public states:
@@ -385,7 +385,7 @@ components:
385
385
  backgroundColor: "{semantic-colors.surface-panel}"
386
386
  textColor: "{semantic-colors.text-primary}"
387
387
  placeholderColor: "{semantic-colors.text-muted}"
388
- borderColor: "{semantic-colors.border}"
388
+ borderColor: "{semantic-colors.border-control}"
389
389
  focusColor: "{semantic-colors.focus-ring}"
390
390
  typography: "{typography.label-14}"
391
391
  rounded: "{rounded.sm}"
@@ -385,7 +385,7 @@ components:
385
385
  backgroundColor: "{semantic-colors.surface-panel}"
386
386
  textColor: "{semantic-colors.text-primary}"
387
387
  placeholderColor: "{semantic-colors.text-muted}"
388
- borderColor: "{semantic-colors.border}"
388
+ borderColor: "{semantic-colors.border-control}"
389
389
  focusColor: "{semantic-colors.focus-ring}"
390
390
  typography: "{typography.label-14}"
391
391
  rounded: "{rounded.sm}"
@@ -112,7 +112,7 @@ Timeline / TimelineItem (ol/li, 8px token dot or Avatar), Marker (quiet actor/ti
112
112
 
113
113
  Accepted 2026-10-07: public `ToggleGroup` names a group of pressable controls with single or multiple selection. Its `items` API exposes `value`, `label`, optional `icon`, `disabled`, and `ariaLabel`; icon-only items require an icon and `ariaLabel`. `type="single"` accepts string `value` / `defaultValue` and `onValueChange`; `allowEmpty` defaults to false. `type="multiple"` accepts string arrays. Controlled values remain caller-owned; uncontrolled single selection falls back to the first enabled item when its value is absent or unknown and empty selection is disallowed. Disabling an existing selected item retains its pressed state and moves only the tabstop. No existing Switch consumer is migrated.
114
114
 
115
- Native buttons expose `aria-pressed` within `role="group"`. Roving tabindex and Arrow / Home / End move focus without selecting; Enter / Space activate through native clicks. Disabled items are skipped. Button-aligned sm32 / md40 / lg48 sizes use existing tokens, quiet selected background and primary text without a selected ring, shared focus shadow, and the shared coarse-pointer 44px TouchTarget with reserved neighbor space. The Tier A keyboard contract lives on `/components/toggle-group`; Switch retains radio semantics and Tabs retains panel semantics.
115
+ Native buttons expose `aria-pressed` within `role="group"`. Roving tabindex and Arrow / Home / End move focus without selecting; Enter / Space activate through native clicks. Disabled items are skipped. Button-aligned sm32 / md40 / lg48 sizes use existing tokens, quiet selected background and primary text with the shared `selection-recipe.css` inset border-strong selection edge (bg-subtle in light, bg-raised in dark); keyboard focus replaces that edge with the shared focus shadow, and the shared coarse-pointer 44px TouchTarget with reserved neighbor space. The Tier A keyboard contract lives on `/components/toggle-group`; Switch retains radio semantics and Tabs retains panel semantics.
116
116
  ## Checkbox task completion circle
117
117
  - Native base: `src/components/ui/ControlOption.tsx`; circle-only readonly/warning module: `src/components/ui/CircleCheckbox.tsx`; independent style: `src/styles/checkbox-circle.css`, imported at the top of global.css and included by build-style.mjs. Square defaults remain unchanged.
118
118
  - Documentation: `src/pages/CheckboxPage.tsx`, `CheckboxCircleDemo.tsx`, `src/styles/checkbox-circle-specimen.css`; circle completion is restricted to tasks/checklists and row completion treatment stays consumer-owned.
@@ -150,3 +150,7 @@ The announcement region wraps only the icon, the `q1-sr-only` 「错误:」 pr
150
150
  ## Cascader 层级选择
151
151
 
152
152
  `Cascader`(`src/components/ui/Cascader.tsx`)负责字段及触发器;`cascader/` 的 Types、model、window、Panel 分别负责受控边界、路径与独立选择、测量窗口、关联 listbox 与搜索。复用 Popover/useOverlay、RegionErrorState 和 Spinner;样式来自既有 surface、text、control、space、radius 与 focus token。窄屏同一弹层单列钻取,亮暗继承 anchor。完整约束、可选省略、公开面与回滚见 [Cascader](./cascader.md)。文档入口 `/components/cascader`,不迁移既有选择器。
153
+
154
+ ## ThemeSwitcher selection appearance
155
+
156
+ Accepted 2026-11-02 (#761): ThemeSwitcher keeps a single outer group border. Options have no border; selection uses `--q1-color-bg-selected-neutral` and primary text, with no inset selection edge. Unselected options keep secondary text and the container background. Light and dark selected and unselected text meet 4.5:1 contrast; the selected background differs from the container. Native labeled radios retain their keyboard behavior, hover changes enabled option text to primary, and keyboard focus uses the shared focus shadow. Public props, class names, DOM structure, exports, and tokens are unchanged.
@@ -0,0 +1,284 @@
1
+ {
2
+ "Badge": {
3
+ "size": [
4
+ "sm",
5
+ "md",
6
+ "lg"
7
+ ]
8
+ },
9
+ "Book": {
10
+ "variant": [
11
+ "stripe",
12
+ "simple"
13
+ ]
14
+ },
15
+ "Browser": {
16
+ "variant": [
17
+ "light",
18
+ "dark"
19
+ ]
20
+ },
21
+ "Button": {
22
+ "variant": [
23
+ "primary",
24
+ "secondary",
25
+ "ghost",
26
+ "warning",
27
+ "danger"
28
+ ],
29
+ "size": [
30
+ "sm",
31
+ "md",
32
+ "lg"
33
+ ]
34
+ },
35
+ "ButtonLink": {
36
+ "variant": [
37
+ "primary",
38
+ "secondary",
39
+ "ghost",
40
+ "warning",
41
+ "danger"
42
+ ],
43
+ "size": [
44
+ "sm",
45
+ "md",
46
+ "lg"
47
+ ]
48
+ },
49
+ "CalendarGrid": {
50
+ "size": [
51
+ "large",
52
+ "small"
53
+ ]
54
+ },
55
+ "Checkbox": {
56
+ "size": [
57
+ "sm",
58
+ "md"
59
+ ]
60
+ },
61
+ "CodeBlock": {
62
+ "variant": [
63
+ "default",
64
+ "flush"
65
+ ]
66
+ },
67
+ "Combobox": {
68
+ "size": [
69
+ "sm",
70
+ "md",
71
+ "lg"
72
+ ]
73
+ },
74
+ "DotsMenu": {
75
+ "size": [
76
+ "sm",
77
+ "md",
78
+ "lg"
79
+ ]
80
+ },
81
+ "ErrorMessage": {
82
+ "size": [
83
+ "sm",
84
+ "md",
85
+ "lg"
86
+ ]
87
+ },
88
+ "FilterChip": {
89
+ "size": [
90
+ "sm",
91
+ "md",
92
+ "lg"
93
+ ]
94
+ },
95
+ "Gauge": {
96
+ "size": [
97
+ "xs",
98
+ "sm",
99
+ "md",
100
+ "lg"
101
+ ]
102
+ },
103
+ "IconButton": {
104
+ "variant": [
105
+ "primary",
106
+ "secondary",
107
+ "ghost",
108
+ "warning",
109
+ "danger"
110
+ ],
111
+ "size": [
112
+ "sm",
113
+ "md",
114
+ "lg"
115
+ ]
116
+ },
117
+ "Input": {
118
+ "size": [
119
+ "xs",
120
+ "sm",
121
+ "md",
122
+ "lg"
123
+ ]
124
+ },
125
+ "InputOTP": {
126
+ "size": [
127
+ "md",
128
+ "lg"
129
+ ]
130
+ },
131
+ "Marker": {
132
+ "variant": [
133
+ "default",
134
+ "separator",
135
+ "unread"
136
+ ]
137
+ },
138
+ "Menu": {
139
+ "size": [
140
+ "sm",
141
+ "md",
142
+ "lg"
143
+ ]
144
+ },
145
+ "Navigation": {
146
+ "variant": [
147
+ "default",
148
+ "line"
149
+ ]
150
+ },
151
+ "Note": {
152
+ "size": [
153
+ "small",
154
+ "default",
155
+ "large"
156
+ ]
157
+ },
158
+ "PageFeedback": {
159
+ "variant": [
160
+ "rating",
161
+ "helpful"
162
+ ]
163
+ },
164
+ "Pill": {
165
+ "size": [
166
+ "sm",
167
+ "md",
168
+ "lg"
169
+ ]
170
+ },
171
+ "ProductLockup": {
172
+ "size": [
173
+ "sm",
174
+ "md"
175
+ ]
176
+ },
177
+ "ProjectBanner": {
178
+ "variant": [
179
+ "default",
180
+ "success",
181
+ "warning",
182
+ "error"
183
+ ]
184
+ },
185
+ "RangeField": {
186
+ "size": [
187
+ "large",
188
+ "small"
189
+ ]
190
+ },
191
+ "Select": {
192
+ "size": [
193
+ "xs",
194
+ "sm",
195
+ "md",
196
+ "lg"
197
+ ]
198
+ },
199
+ "Sheet": {
200
+ "size": [
201
+ "sm",
202
+ "md",
203
+ "lg",
204
+ "xl"
205
+ ]
206
+ },
207
+ "SidebarDrawer": {
208
+ "variant": [
209
+ "panel",
210
+ "plain"
211
+ ]
212
+ },
213
+ "Spinner": {
214
+ "size": [
215
+ "sm",
216
+ "md",
217
+ "lg",
218
+ "xl"
219
+ ]
220
+ },
221
+ "SplitButton": {
222
+ "variant": [
223
+ "default",
224
+ "secondary"
225
+ ],
226
+ "size": [
227
+ "sm",
228
+ "md",
229
+ "lg"
230
+ ]
231
+ },
232
+ "StatusPage": {
233
+ "size": [
234
+ "page",
235
+ "region"
236
+ ]
237
+ },
238
+ "Switch": {
239
+ "variant": [
240
+ "segmented",
241
+ "cards"
242
+ ],
243
+ "size": [
244
+ "sm",
245
+ "md",
246
+ "lg"
247
+ ]
248
+ },
249
+ "Tabs": {
250
+ "variant": [
251
+ "default",
252
+ "secondary",
253
+ "line"
254
+ ]
255
+ },
256
+ "Textarea": {
257
+ "size": [
258
+ "xs",
259
+ "sm",
260
+ "md",
261
+ "lg"
262
+ ]
263
+ },
264
+ "TextWithCopyButton": {
265
+ "size": [
266
+ "default",
267
+ "small"
268
+ ]
269
+ },
270
+ "Toggle": {
271
+ "size": [
272
+ "sm",
273
+ "md",
274
+ "lg"
275
+ ]
276
+ },
277
+ "ToggleGroup": {
278
+ "size": [
279
+ "sm",
280
+ "md",
281
+ "lg"
282
+ ]
283
+ }
284
+ }
@@ -1325,7 +1325,7 @@ export declare type HoverCardProps = {
1325
1325
  className?: string;
1326
1326
  };
1327
1327
 
1328
- export declare function IconButton({ 'aria-label': canonicalAriaLabel, ariaLabel: legacyAriaLabel, 'aria-pressed': ariaPressed, disabled, loading, onClick, onBlur, onKeyDown, onPointerCancel, onPointerDown, onPointerLeave, onPointerUp, onLostPointerCapture, ...rest }: IconButtonProps): JSX.Element;
1328
+ export declare function IconButton({ 'aria-label': canonicalAriaLabel, ariaLabel: legacyAriaLabel, 'aria-pressed': ariaPressed, disabled, loading, attention, onClick, onBlur, onKeyDown, onPointerCancel, onPointerDown, onPointerLeave, onPointerUp, onLostPointerCapture, ...rest }: IconButtonProps): JSX.Element;
1329
1329
 
1330
1330
  declare type IconButtonAccessibleName = {
1331
1331
  'aria-label': string;
@@ -1347,6 +1347,7 @@ declare type IconButtonBaseProps = {
1347
1347
  variant?: ButtonVariant;
1348
1348
  size?: ButtonSize;
1349
1349
  circle?: boolean;
1350
+ attention?: boolean;
1350
1351
  loading?: boolean;
1351
1352
  loadingLabel?: string;
1352
1353
  disabled?: boolean;