@astryxdesign/core 0.4.0 → 0.4.1-canary.1ce0b4c

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 (271) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/AspectRatio/AspectRatio.d.ts.map +1 -1
  3. package/dist/AspectRatio/AspectRatio.js +1 -2
  4. package/dist/AspectRatio/index.d.ts.map +1 -1
  5. package/dist/AspectRatio/index.js +1 -2
  6. package/dist/Badge/Badge.d.ts.map +1 -1
  7. package/dist/Badge/Badge.js +1 -2
  8. package/dist/Badge/index.d.ts.map +1 -1
  9. package/dist/Badge/index.js +1 -2
  10. package/dist/Banner/Banner.d.ts +3 -0
  11. package/dist/Banner/Banner.d.ts.map +1 -1
  12. package/dist/Banner/Banner.js +17 -3
  13. package/dist/Blockquote/Blockquote.d.ts.map +1 -1
  14. package/dist/Blockquote/Blockquote.js +1 -2
  15. package/dist/Blockquote/index.d.ts.map +1 -1
  16. package/dist/Blockquote/index.js +1 -2
  17. package/dist/Button/Button.d.ts.map +1 -1
  18. package/dist/Button/Button.js +11 -9
  19. package/dist/Card/Card.d.ts.map +1 -1
  20. package/dist/Card/Card.js +1 -2
  21. package/dist/Card/index.d.ts.map +1 -1
  22. package/dist/Card/index.js +1 -2
  23. package/dist/Center/Center.d.ts.map +1 -1
  24. package/dist/Center/Center.js +1 -2
  25. package/dist/Center/index.d.ts.map +1 -1
  26. package/dist/Center/index.js +1 -2
  27. package/dist/Code/Code.d.ts.map +1 -1
  28. package/dist/Code/Code.js +1 -2
  29. package/dist/CommandPalette/CommandPalette.d.ts.map +1 -1
  30. package/dist/CommandPalette/CommandPalette.js +5 -0
  31. package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
  32. package/dist/ComplexSelector/ComplexSelector.js +7 -8
  33. package/dist/DateInput/DateInput.d.ts.map +1 -1
  34. package/dist/DateInput/DateInput.js +23 -10
  35. package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
  36. package/dist/DateRangeInput/DateRangeInput.js +44 -16
  37. package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
  38. package/dist/DateTimeInput/DateTimeInput.js +32 -13
  39. package/dist/DropdownMenu/DropdownMenuRadioGroup.d.ts +1 -1
  40. package/dist/DropdownMenu/DropdownMenuRadioGroup.d.ts.map +1 -1
  41. package/dist/DropdownMenu/DropdownMenuRadioGroup.js +10 -3
  42. package/dist/Field/PanelSearchInput.d.ts +81 -0
  43. package/dist/Field/PanelSearchInput.d.ts.map +1 -0
  44. package/dist/Field/PanelSearchInput.js +151 -0
  45. package/dist/FileInput/FileInput.d.ts.map +1 -1
  46. package/dist/FileInput/FileInput.js +21 -10
  47. package/dist/Grid/Grid.d.ts.map +1 -1
  48. package/dist/Grid/Grid.js +1 -2
  49. package/dist/Grid/index.d.ts.map +1 -1
  50. package/dist/Grid/index.js +1 -2
  51. package/dist/HoverCard/HoverCard.d.ts +1 -1
  52. package/dist/HoverCard/HoverCard.d.ts.map +1 -1
  53. package/dist/HoverCard/HoverCard.js +5 -13
  54. package/dist/HoverCard/useHoverCard.d.ts.map +1 -1
  55. package/dist/HoverCard/useHoverCard.js +6 -5
  56. package/dist/Icon/globalIconRegistry.d.ts +5 -4
  57. package/dist/Icon/globalIconRegistry.d.ts.map +1 -1
  58. package/dist/Icon/globalIconRegistry.js +5 -4
  59. package/dist/Indicator/index.d.ts +1 -1
  60. package/dist/Indicator/index.d.ts.map +1 -1
  61. package/dist/Indicator/types.d.ts +10 -0
  62. package/dist/Indicator/types.d.ts.map +1 -1
  63. package/dist/InputGroup/groupStyles.d.ts.map +1 -1
  64. package/dist/InputGroup/groupStyles.js +7 -2
  65. package/dist/Layer/layerHost.d.ts +24 -0
  66. package/dist/Layer/layerHost.d.ts.map +1 -0
  67. package/dist/Layer/layerHost.js +79 -0
  68. package/dist/Layer/useLayer.d.ts +14 -6
  69. package/dist/Layer/useLayer.d.ts.map +1 -1
  70. package/dist/Layer/useLayer.js +155 -29
  71. package/dist/Lightbox/Lightbox.d.ts.map +1 -1
  72. package/dist/Lightbox/Lightbox.js +24 -50
  73. package/dist/MultiSelector/MultiSelector.d.ts +8 -1
  74. package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
  75. package/dist/MultiSelector/MultiSelector.js +134 -102
  76. package/dist/NavItem/navItemStyles.stylex.d.ts +17 -5
  77. package/dist/NavItem/navItemStyles.stylex.d.ts.map +1 -1
  78. package/dist/NavItem/navItemStyles.stylex.js +11 -5
  79. package/dist/Popover/usePopover.d.ts +15 -0
  80. package/dist/Popover/usePopover.d.ts.map +1 -1
  81. package/dist/Popover/usePopover.js +14 -2
  82. package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
  83. package/dist/ProgressBar/ProgressBar.js +2 -3
  84. package/dist/Section/Section.d.ts.map +1 -1
  85. package/dist/Section/Section.js +1 -2
  86. package/dist/Section/index.d.ts.map +1 -1
  87. package/dist/Section/index.js +1 -2
  88. package/dist/Selector/Selector.d.ts +10 -0
  89. package/dist/Selector/Selector.d.ts.map +1 -1
  90. package/dist/Selector/Selector.js +135 -95
  91. package/dist/SideNav/SideNav.d.ts +7 -9
  92. package/dist/SideNav/SideNav.d.ts.map +1 -1
  93. package/dist/SideNav/SideNav.js +32 -5
  94. package/dist/SideNav/SideNavCollapseButton.d.ts +25 -9
  95. package/dist/SideNav/SideNavCollapseButton.d.ts.map +1 -1
  96. package/dist/SideNav/SideNavCollapseButton.js +39 -15
  97. package/dist/SideNav/SideNavCollapseContext.d.ts +21 -0
  98. package/dist/SideNav/SideNavCollapseContext.d.ts.map +1 -1
  99. package/dist/SideNav/SideNavCollapseContext.js +16 -2
  100. package/dist/SideNav/SideNavHeading.d.ts.map +1 -1
  101. package/dist/SideNav/SideNavHeading.js +70 -24
  102. package/dist/SideNav/SideNavItem.d.ts +7 -2
  103. package/dist/SideNav/SideNavItem.d.ts.map +1 -1
  104. package/dist/SideNav/SideNavItem.js +114 -75
  105. package/dist/SideNav/SideNavSection.d.ts.map +1 -1
  106. package/dist/SideNav/SideNavSection.js +7 -16
  107. package/dist/SideNav/index.d.ts +1 -1
  108. package/dist/SideNav/index.d.ts.map +1 -1
  109. package/dist/Skeleton/Skeleton.d.ts.map +1 -1
  110. package/dist/Skeleton/Skeleton.js +1 -2
  111. package/dist/Skeleton/index.d.ts.map +1 -1
  112. package/dist/Skeleton/index.js +1 -2
  113. package/dist/Slider/Slider.d.ts.map +1 -1
  114. package/dist/Slider/Slider.js +2 -6
  115. package/dist/Switch/Switch.d.ts.map +1 -1
  116. package/dist/Switch/Switch.js +3 -3
  117. package/dist/Table/TableRow.d.ts +1 -1
  118. package/dist/Table/TableRow.d.ts.map +1 -1
  119. package/dist/Table/TableRow.js +4 -2
  120. package/dist/TimeInput/TimeInput.d.ts.map +1 -1
  121. package/dist/TimeInput/TimeInput.js +7 -2
  122. package/dist/Timestamp/Timestamp.d.ts.map +1 -1
  123. package/dist/Timestamp/Timestamp.js +14 -3
  124. package/dist/Timestamp/formatInstant.d.ts +11 -1
  125. package/dist/Timestamp/formatInstant.d.ts.map +1 -1
  126. package/dist/Timestamp/formatInstant.js +3 -1
  127. package/dist/TopNav/TopNavMegaMenu.js +1 -1
  128. package/dist/TopNav/TopNavMegaMenuItem.js +1 -1
  129. package/dist/TopNav/TopNavMenu.d.ts.map +1 -1
  130. package/dist/TopNav/TopNavMenu.js +2 -2
  131. package/dist/VisuallyHidden/VisuallyHidden.d.ts.map +1 -1
  132. package/dist/VisuallyHidden/VisuallyHidden.js +1 -2
  133. package/dist/VisuallyHidden/index.d.ts.map +1 -1
  134. package/dist/VisuallyHidden/index.js +1 -2
  135. package/dist/astryx.css +23 -24
  136. package/dist/astryx.umd.js +48 -48
  137. package/dist/astryx.umd.js.map +4 -4
  138. package/dist/hooks/index.d.ts +1 -1
  139. package/dist/hooks/index.d.ts.map +1 -1
  140. package/dist/hooks/index.js +1 -1
  141. package/dist/hooks/useFocusTrap.d.ts.map +1 -1
  142. package/dist/hooks/useFocusTrap.js +16 -2
  143. package/dist/hooks/useInputStatusIcon.d.ts.map +1 -1
  144. package/dist/hooks/useInputStatusIcon.js +17 -4
  145. package/dist/theme/defineTheme.d.ts +2 -2
  146. package/dist/theme/defineTheme.d.ts.map +1 -1
  147. package/dist/theme/defineTheme.js +2 -1
  148. package/dist/theme/index.d.ts +1 -1
  149. package/dist/theme/index.d.ts.map +1 -1
  150. package/dist/theme/index.js +1 -1
  151. package/dist/theme/tokens.stylex.d.ts +12 -0
  152. package/dist/theme/tokens.stylex.d.ts.map +1 -1
  153. package/dist/theme/tokens.stylex.js +23 -0
  154. package/dist/utils/focusOutline.stylex.d.ts +34 -19
  155. package/dist/utils/focusOutline.stylex.d.ts.map +1 -1
  156. package/dist/utils/focusOutline.stylex.js +46 -33
  157. package/dist/utils/index.d.ts +1 -0
  158. package/dist/utils/index.d.ts.map +1 -1
  159. package/dist/utils/index.js +5 -1
  160. package/dist/utils/interactionModality.d.ts +34 -0
  161. package/dist/utils/interactionModality.d.ts.map +1 -0
  162. package/dist/utils/interactionModality.js +70 -0
  163. package/locales/en.json +44 -0
  164. package/locales/pseudo.json +33 -0
  165. package/package.json +3 -3
  166. package/src/AppShell/AppShell.doc.mjs +3 -0
  167. package/src/AspectRatio/AspectRatio.tsx +0 -2
  168. package/src/AspectRatio/index.ts +0 -2
  169. package/src/Badge/Badge.tsx +0 -2
  170. package/src/Badge/index.ts +0 -2
  171. package/src/Banner/Banner.test.tsx +58 -1
  172. package/src/Banner/Banner.tsx +24 -5
  173. package/src/Blockquote/Blockquote.tsx +0 -2
  174. package/src/Blockquote/index.ts +0 -2
  175. package/src/Button/Button.doc.mjs +2 -2
  176. package/src/Button/Button.tsx +10 -7
  177. package/src/ButtonGroup/ButtonGroup.test.tsx +7 -4
  178. package/src/Card/Card.tsx +0 -2
  179. package/src/Card/index.ts +0 -2
  180. package/src/Center/Center.tsx +0 -2
  181. package/src/Center/index.ts +0 -2
  182. package/src/CheckboxInput/CheckboxInput.test.tsx +8 -3
  183. package/src/Code/Code.tsx +0 -2
  184. package/src/CommandPalette/CommandPalette.test.tsx +54 -0
  185. package/src/CommandPalette/CommandPalette.tsx +5 -0
  186. package/src/ComplexSelector/ComplexSelector.test.tsx +15 -6
  187. package/src/ComplexSelector/ComplexSelector.tsx +6 -10
  188. package/src/DateInput/DateInput.test.tsx +19 -0
  189. package/src/DateInput/DateInput.tsx +3 -6
  190. package/src/DateRangeInput/DateRangeInput.tsx +3 -9
  191. package/src/DateTimeInput/DateTimeInput.test.tsx +79 -1
  192. package/src/DateTimeInput/DateTimeInput.tsx +23 -9
  193. package/src/DropdownMenu/DropdownMenuRadioGroup.tsx +2 -1
  194. package/src/Field/PanelSearchInput.tsx +271 -0
  195. package/src/FileInput/FileInput.tsx +21 -8
  196. package/src/Grid/Grid.tsx +0 -2
  197. package/src/Grid/index.ts +0 -2
  198. package/src/HoverCard/HoverCard.doc.mjs +3 -3
  199. package/src/HoverCard/HoverCard.test.tsx +283 -55
  200. package/src/HoverCard/HoverCard.tsx +5 -13
  201. package/src/HoverCard/useHoverCard.tsx +8 -11
  202. package/src/Icon/globalIconRegistry.tsx +5 -4
  203. package/src/Indicator/Indicator.doc.mjs +1 -1
  204. package/src/Indicator/index.ts +1 -0
  205. package/src/Indicator/types.ts +11 -0
  206. package/src/InputGroup/groupStyles.ts +7 -8
  207. package/src/Layer/layerHost.test.ts +99 -0
  208. package/src/Layer/layerHost.ts +141 -0
  209. package/src/Layer/useLayer.doc.mjs +14 -4
  210. package/src/Layer/useLayer.test.tsx +318 -7
  211. package/src/Layer/useLayer.tsx +229 -35
  212. package/src/Lightbox/Lightbox.tsx +2 -11
  213. package/src/MultiSelector/MultiSelector.doc.mjs +9 -0
  214. package/src/MultiSelector/MultiSelector.test.tsx +135 -5
  215. package/src/MultiSelector/MultiSelector.tsx +170 -127
  216. package/src/NavItem/navItemStyles.stylex.ts +31 -5
  217. package/src/Popover/Popover.doc.mjs +2 -0
  218. package/src/Popover/usePopover.tsx +37 -4
  219. package/src/ProgressBar/ProgressBar.tsx +2 -8
  220. package/src/Section/Section.tsx +0 -2
  221. package/src/Section/index.ts +0 -2
  222. package/src/Selector/Selector.doc.mjs +10 -0
  223. package/src/Selector/Selector.test.tsx +386 -2
  224. package/src/Selector/Selector.tsx +182 -122
  225. package/src/SideNav/SideNav.doc.mjs +13 -4
  226. package/src/SideNav/SideNav.test.tsx +771 -2
  227. package/src/SideNav/SideNav.tsx +37 -16
  228. package/src/SideNav/SideNavCollapseButton.doc.mjs +28 -6
  229. package/src/SideNav/SideNavCollapseButton.tsx +67 -15
  230. package/src/SideNav/SideNavCollapseContext.ts +29 -9
  231. package/src/SideNav/SideNavHeading.tsx +28 -10
  232. package/src/SideNav/SideNavItem.doc.mjs +13 -0
  233. package/src/SideNav/SideNavItem.tsx +92 -84
  234. package/src/SideNav/SideNavSection.tsx +6 -20
  235. package/src/SideNav/index.ts +2 -0
  236. package/src/Skeleton/Skeleton.tsx +0 -2
  237. package/src/Skeleton/index.ts +0 -2
  238. package/src/Slider/Slider.tsx +2 -11
  239. package/src/Switch/Switch.tsx +10 -2
  240. package/src/Table/Table.test.tsx +31 -0
  241. package/src/Table/TableRow.tsx +6 -0
  242. package/src/Text/Text.doc.mjs +1 -1
  243. package/src/TimeInput/TimeInput.test.tsx +54 -0
  244. package/src/TimeInput/TimeInput.tsx +17 -2
  245. package/src/Timestamp/Timestamp.test.tsx +125 -30
  246. package/src/Timestamp/Timestamp.tsx +14 -2
  247. package/src/Timestamp/formatInstant.ts +16 -1
  248. package/src/Toolbar/Toolbar.test.tsx +14 -14
  249. package/src/TopNav/TopNavMegaMenu.doc.mjs +5 -0
  250. package/src/TopNav/TopNavMegaMenu.test.tsx +43 -0
  251. package/src/TopNav/TopNavMegaMenu.tsx +4 -1
  252. package/src/TopNav/TopNavMegaMenuItem.tsx +1 -1
  253. package/src/TopNav/TopNavMenu.test.tsx +41 -0
  254. package/src/TopNav/TopNavMenu.tsx +8 -2
  255. package/src/TreeList/TreeList.test.tsx +3 -2
  256. package/src/VisuallyHidden/VisuallyHidden.tsx +0 -2
  257. package/src/VisuallyHidden/index.ts +0 -2
  258. package/src/hooks/index.ts +5 -1
  259. package/src/hooks/useFocusTrap.test.tsx +16 -0
  260. package/src/hooks/useFocusTrap.ts +20 -2
  261. package/src/hooks/useInputStatusIcon.tsx +8 -8
  262. package/src/serverSafeComponents.test.ts +665 -0
  263. package/src/theme/defineTheme.ts +3 -0
  264. package/src/theme/generateThemeRules.test.ts +17 -0
  265. package/src/theme/index.ts +2 -0
  266. package/src/theme/themingTargets.test.ts +152 -26
  267. package/src/theme/tokens.stylex.ts +18 -0
  268. package/src/theme/tokens.test.ts +37 -0
  269. package/src/utils/focusOutline.stylex.ts +37 -23
  270. package/src/utils/index.ts +4 -0
  271. package/src/utils/interactionModality.ts +74 -0
@@ -90,6 +90,7 @@ export {
90
90
  spacingDefaults,
91
91
  sizeDefaults,
92
92
  borderDefaults,
93
+ focusDefaults,
93
94
  radiusDefaults,
94
95
  shadowDefaults,
95
96
  durationDefaults,
@@ -102,6 +103,7 @@ export {
102
103
  spacingVars,
103
104
  sizeVars,
104
105
  borderVars,
106
+ focusVars,
105
107
  radiusVars,
106
108
  shadowVars,
107
109
  durationVars,
@@ -26,7 +26,7 @@
26
26
 
27
27
  import {describe, it, expect} from 'vitest';
28
28
  import {readdirSync, readFileSync} from 'node:fs';
29
- import {join} from 'node:path';
29
+ import {join, relative} from 'node:path';
30
30
  import ts from 'typescript';
31
31
  import {stableClassName} from '../naming';
32
32
 
@@ -45,6 +45,61 @@ interface ThemeTargetSite {
45
45
  isOpaque: boolean;
46
46
  }
47
47
 
48
+ /**
49
+ * Keys of a spread whose operand is a conditional object literal:
50
+ * `...(cond && {a})`, `...(cond ? {a} : null)`, `...(cond || {a})`.
51
+ * Returns null when the operand is anything else (a bag like `...rest`, or an
52
+ * object with a computed key), which the caller treats as opaque.
53
+ */
54
+ function conditionalSpreadKeys(expression: ts.Expression): string[] | null {
55
+ const unwrap = (node: ts.Expression): ts.Expression =>
56
+ ts.isParenthesizedExpression(node) ? unwrap(node.expression) : node;
57
+
58
+ const expr = unwrap(expression);
59
+ const branches: ts.Expression[] = [];
60
+ if (
61
+ ts.isBinaryExpression(expr) &&
62
+ (expr.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken ||
63
+ expr.operatorToken.kind === ts.SyntaxKind.BarBarToken)
64
+ ) {
65
+ branches.push(expr.right);
66
+ } else if (ts.isConditionalExpression(expr)) {
67
+ branches.push(expr.whenTrue, expr.whenFalse);
68
+ } else if (ts.isObjectLiteralExpression(expr)) {
69
+ branches.push(expr);
70
+ } else {
71
+ return null;
72
+ }
73
+
74
+ const keys: string[] = [];
75
+ for (const branch of branches) {
76
+ const object = unwrap(branch);
77
+ // A falsy filler arm (`null`, `undefined`) contributes no keys; anything
78
+ // else that is not an object literal hides its keys, so give up.
79
+ if (
80
+ object.kind === ts.SyntaxKind.NullKeyword ||
81
+ (ts.isIdentifier(object) && object.text === 'undefined')
82
+ ) {
83
+ continue;
84
+ }
85
+ if (!ts.isObjectLiteralExpression(object)) {
86
+ return null;
87
+ }
88
+ for (const prop of object.properties) {
89
+ const name = prop.name;
90
+ if (
91
+ name != null &&
92
+ (ts.isIdentifier(name) || ts.isStringLiteralLike(name))
93
+ ) {
94
+ keys.push(name.text);
95
+ } else {
96
+ return null;
97
+ }
98
+ }
99
+ }
100
+ return keys;
101
+ }
102
+
48
103
  /**
49
104
  * Extract every `themeProps('name', {...})` call from a source file.
50
105
  *
@@ -88,8 +143,16 @@ function extractThemeTargets(
88
143
  if (ts.isObjectLiteralExpression(propsArg)) {
89
144
  for (const prop of propsArg.properties) {
90
145
  if (ts.isSpreadAssignment(prop)) {
91
- // {...rest} — keys unknown at parse time.
92
- site.isOpaque = true;
146
+ // A conditional spread of an object literal — `...(type &&
147
+ // {type})` — has statically known keys. Treating it as opaque
148
+ // is how `astryx-heading`'s `type` stayed undocumented: the
149
+ // same drift this file exists to catch (#3652, #3680).
150
+ const spreadKeys = conditionalSpreadKeys(prop.expression);
151
+ if (spreadKeys == null) {
152
+ site.isOpaque = true;
153
+ } else {
154
+ site.propKeys.push(...spreadKeys);
155
+ }
93
156
  continue;
94
157
  }
95
158
  const name = prop.name;
@@ -194,12 +257,35 @@ describe('extractThemeTargets', () => {
194
257
  ]);
195
258
  });
196
259
 
260
+ it('reads the keys of a conditional spread', () => {
261
+ // Heading's real call site: `{level, color, ...(type && {type})}`.
262
+ const [site] = extractThemeTargets(
263
+ `themeProps('heading', {level, color, ...(type && {type})})`,
264
+ );
265
+ expect(site.propKeys).toEqual(['level', 'color', 'type']);
266
+ expect(site.isOpaque).toBe(false);
267
+ });
268
+
269
+ it('reads both arms of a ternary spread', () => {
270
+ const [site] = extractThemeTargets(
271
+ `themeProps('card', {...(isOpen ? {expanded} : {collapsed})})`,
272
+ );
273
+ expect(site.propKeys).toEqual(['expanded', 'collapsed']);
274
+ expect(site.isOpaque).toBe(false);
275
+ });
276
+
197
277
  it('marks a spread props bag opaque rather than guessing its keys', () => {
198
278
  const [site] = extractThemeTargets(`themeProps('card', {...rest})`);
199
279
  expect(site.isOpaque).toBe(true);
200
280
  expect(site.propKeys).toEqual([]);
201
281
  });
202
282
 
283
+ it('marks a conditional spread of a non-literal opaque', () => {
284
+ const [site] = extractThemeTargets(`themeProps('card', {...(on && rest)})`);
285
+ expect(site.isOpaque).toBe(true);
286
+ expect(site.propKeys).toEqual([]);
287
+ });
288
+
203
289
  it('marks a non-literal props bag opaque', () => {
204
290
  const [site] = extractThemeTargets(`themeProps('card', visualProps)`);
205
291
  expect(site.isOpaque).toBe(true);
@@ -231,7 +317,37 @@ interface ComponentInfo {
231
317
  dir: string;
232
318
  sites: ThemeTargetSite[];
233
319
  /** The doc blocks that carry theming.targets, by the key they live under. */
234
- docBlocks: {key: 'docs' | 'docsZh'; targets: DocTarget[]}[];
320
+ docBlocks: {key: 'docs' | 'docsZh'; file: string; targets: DocTarget[]}[];
321
+ }
322
+
323
+ /**
324
+ * Every `*.doc.mjs` under src that declares a theming target for one of
325
+ * `classNames`. Lets a component be checked against the doc that documents it,
326
+ * wherever that file lives.
327
+ *
328
+ * Reads the file as text rather than requiring it: this runs for directories
329
+ * that have no doc of their own, so most candidates are misses.
330
+ */
331
+ function docFilesDocumenting(classNames: Set<string>): string[] {
332
+ const matches: string[] = [];
333
+ const walk = (dir: string): void => {
334
+ for (const entry of readdirSync(dir, {withFileTypes: true})) {
335
+ const p = join(dir, entry.name);
336
+ if (entry.isDirectory()) {
337
+ walk(p);
338
+ } else if (entry.name.endsWith('.doc.mjs')) {
339
+ const source = readFileSync(p, 'utf-8');
340
+ for (const className of classNames) {
341
+ if (source.includes(`'${className}'`)) {
342
+ matches.push(p);
343
+ break;
344
+ }
345
+ }
346
+ }
347
+ }
348
+ };
349
+ walk(SRC_DIR);
350
+ return matches;
235
351
  }
236
352
 
237
353
  function discoverComponents(): ComponentInfo[] {
@@ -262,27 +378,37 @@ function discoverComponents(): ComponentInfo[] {
262
378
  continue;
263
379
  }
264
380
 
265
- // Match the on-disk listing rather than existsSync: on case-insensitive
266
- // filesystems existsSync would match a differently-cased doc file that CI
267
- // never checks. (Same guard as derivedVarRegistry.test.ts.)
268
- if (!dirEntries.includes(`${dir}.doc.mjs`)) {
269
- continue;
270
- }
271
-
272
- let mod: ComponentDocModule;
273
- try {
274
- mod = require(join(dirPath, `${dir}.doc.mjs`)) as ComponentDocModule;
275
- } catch {
381
+ // A component's doc file usually sits beside its source, but not always:
382
+ // `Heading/Heading.tsx` is documented by `Text/Text.doc.mjs`. Requiring a
383
+ // same-directory doc silently exempted every such component — Heading
384
+ // among them. Fall back to whichever doc file documents the classes this
385
+ // directory renders.
386
+ //
387
+ // Both paths match the on-disk listing rather than existsSync: on
388
+ // case-insensitive filesystems existsSync would match a differently-cased
389
+ // doc file that CI never checks. (Same guard as derivedVarRegistry.test.ts.)
390
+ const docFiles = dirEntries.includes(`${dir}.doc.mjs`)
391
+ ? [join(dirPath, `${dir}.doc.mjs`)]
392
+ : docFilesDocumenting(new Set(sites.map(s => s.className)));
393
+ if (docFiles.length === 0) {
276
394
  continue;
277
395
  }
278
396
 
279
397
  const docBlocks: ComponentInfo['docBlocks'] = [];
280
- for (const key of ['docs', 'docsZh'] as const) {
281
- const targets = mod[key]?.theming?.targets;
282
- // Only blocks that already document a theming surface are held to it —
283
- // a doc with no theming block at all is a separate (documentation) gap.
284
- if (targets != null) {
285
- docBlocks.push({key, targets});
398
+ for (const docFile of docFiles) {
399
+ let mod: ComponentDocModule;
400
+ try {
401
+ mod = require(docFile) as ComponentDocModule;
402
+ } catch {
403
+ continue;
404
+ }
405
+ for (const key of ['docs', 'docsZh'] as const) {
406
+ const targets = mod[key]?.theming?.targets;
407
+ // Only blocks that already document a theming surface are held to it —
408
+ // a doc with no theming block at all is a separate (documentation) gap.
409
+ if (targets != null) {
410
+ docBlocks.push({key, file: relative(SRC_DIR, docFile), targets});
411
+ }
286
412
  }
287
413
  }
288
414
  if (docBlocks.length === 0) {
@@ -309,22 +435,22 @@ describe('theming.targets matches the themeProps() call sites', () => {
309
435
  for (const {dir, sites, docBlocks} of components) {
310
436
  const renderedClasses = [...new Set(sites.map(s => s.className))].sort();
311
437
 
312
- for (const {key, targets} of docBlocks) {
438
+ for (const {key, file, targets} of docBlocks) {
313
439
  const documented = new Set(targets.map(t => t.className));
314
440
 
315
- it(`${dir} (${key}): every rendered class is documented`, () => {
441
+ it(`${dir} (${file} ${key}): every rendered class is documented`, () => {
316
442
  const undocumented = renderedClasses.filter(c => !documented.has(c));
317
443
  expect(
318
444
  undocumented,
319
445
  `${dir} renders ${undocumented.length} astryx-* class(es) that ` +
320
- `${dir}.doc.mjs ${key}.theming.targets does not document: ` +
446
+ `${file} ${key}.theming.targets does not document: ` +
321
447
  `${undocumented.join(', ')}. An undocumented class is an ` +
322
448
  `unthemeable element — theme authors and codegen read targets[] ` +
323
449
  `to learn which selectors exist. Add {className: '...'} entries.`,
324
450
  ).toEqual([]);
325
451
  });
326
452
 
327
- it(`${dir} (${key}): every visual prop passed to themeProps is documented`, () => {
453
+ it(`${dir} (${file} ${key}): every visual prop passed to themeProps is documented`, () => {
328
454
  const missing: string[] = [];
329
455
  for (const site of sites) {
330
456
  const target = targets.find(t => t.className === site.className);
@@ -343,7 +469,7 @@ describe('theming.targets matches the themeProps() call sites', () => {
343
469
  }
344
470
  expect(
345
471
  [...new Set(missing)],
346
- `${dir} passes prop keys to themeProps() that ${dir}.doc.mjs ` +
472
+ `${dir} passes prop keys to themeProps() that ${file} ` +
347
473
  `${key}.theming.targets does not list under visualProps/states. ` +
348
474
  `Each one is a [data-*] selector consumers cannot discover.`,
349
475
  ).toEqual([]);
@@ -193,6 +193,24 @@ export const borderVars = stylex.defineVars(borderDefaults);
193
193
 
194
194
  export type BorderVarName = keyof typeof borderDefaults;
195
195
 
196
+ // =============================================================================
197
+ // Focus Tokens
198
+ // =============================================================================
199
+ // The keyboard focus ring, as one definition for the whole system. Values come
200
+ // from Design Conventions §User Interaction States: 2px --color-accent at 3px
201
+ // offset. Components read these through utils/focusOutline.stylex.ts; the
202
+ // `:focus-visible` condition stays in core, so a theme can restyle the ring
203
+ // but cannot show it to pointer users.
204
+
205
+ export const focusDefaults = {
206
+ '--focus-outline-width': '2px',
207
+ '--focus-outline-style': 'solid',
208
+ '--focus-outline-color': 'var(--color-accent)',
209
+ '--focus-outline-offset': '3px',
210
+ } as const;
211
+
212
+ export const focusVars = stylex.defineVars(focusDefaults);
213
+
196
214
  // =============================================================================
197
215
  // Radius Tokens
198
216
  // =============================================================================
@@ -280,3 +280,40 @@ describe('resolveThemeTokens — generated themes end to end', () => {
280
280
  expect(light['--color-icon-accent']).toBe(light['--color-accent']);
281
281
  });
282
282
  });
283
+
284
+ describe('focus outline tokens', () => {
285
+ it('default to the accent ring from Design Conventions', () => {
286
+ const tokens = resolveThemeTokens(null, {mode: 'light'});
287
+
288
+ expect(tokens['--focus-outline-width']).toBe('2px');
289
+ expect(tokens['--focus-outline-style']).toBe('solid');
290
+ expect(tokens['--focus-outline-offset']).toBe('3px');
291
+ // Tracks the theme's accent unless a theme says otherwise.
292
+ expect(tokens['--focus-outline-color']).toBe(tokens['--color-accent']);
293
+ });
294
+
295
+ it('follows a theme accent without an explicit focus override', () => {
296
+ const theme = defineTheme({name: 'brand', color: {accent: '#AA0000'}});
297
+ const tokens = resolveThemeTokens(theme, {mode: 'light'});
298
+
299
+ expect(tokens['--focus-outline-color']).toBe(tokens['--color-accent']);
300
+ expect(tokens['--focus-outline-color']).not.toContain('var(');
301
+ });
302
+
303
+ it('takes an explicit ring over the accent', () => {
304
+ const theme = defineTheme({
305
+ name: 'brand',
306
+ color: {accent: '#AA0000'},
307
+ tokens: {
308
+ '--focus-outline-color': '#00FF00',
309
+ '--focus-outline-width': '4px',
310
+ '--focus-outline-offset': '0px',
311
+ },
312
+ });
313
+ const tokens = resolveThemeTokens(theme, {mode: 'light'});
314
+
315
+ expect(tokens['--focus-outline-color']).toBe('#00FF00');
316
+ expect(tokens['--focus-outline-width']).toBe('4px');
317
+ expect(tokens['--focus-outline-offset']).toBe('0px');
318
+ });
319
+ });
@@ -7,28 +7,42 @@
7
7
  * @position Internal utility for consistent keyboard focus outlines across core components
8
8
  *
9
9
  * Centralizes the standard Astryx focus outline, shown only for keyboard focus.
10
- * Every focusable surface drew the same 2px accent ring at 2px offset already;
11
- * writing it per component meant five identical definitions to keep in step.
10
+ * Every focusable surface drew the same 2px accent ring already; writing it per
11
+ * component meant dozens of identical definitions to keep in step, and they did
12
+ * not stay in step — offsets drifted and one ring was a border-width thick.
12
13
  *
13
- * These are utility styles, deliberately NOT a theme target. A shared
14
- * `astryx-focus-outline` class was tried and pulled: a theme can only override
15
- * the ring unconditionally through it (`generateThemeRules` mangles
16
- * `:focus-visible` into `.focus-visible` and truncates `:has(:focus-visible)`
17
- * at the paren), so the one thing such a target exists for — restyling a
18
- * STATE — is exactly what it cannot express. Making focus outlines themeable
19
- * is worth doing on top of this consolidation, once that is fixed.
14
+ * Every ring in core and lab is drawn from here, with one exception recorded in
15
+ * Switch: its condition is a component-scoped ancestor marker, which cannot be
16
+ * shared without leaking focus state between components. A component may still
17
+ * override the OFFSET (a ring that must sit inset, or clear of a field border);
18
+ * width, style and color are not restated anywhere.
19
+ *
20
+ * Every value comes from the `--focus-outline-*` tokens, which is how a theme
21
+ * restyles the ring: one override reaches every component at once. The
22
+ * `:focus-visible` condition is not themeable and stays here, so a theme can
23
+ * change what the ring looks like but cannot show it to pointer users.
20
24
  */
21
25
 
22
26
  import * as stylex from '@stylexjs/stylex';
23
- import {colorVars} from '../theme/tokens.stylex';
27
+ import {focusVars} from '../theme/tokens.stylex';
28
+
29
+ const FOCUS_OUTLINE_WIDTH = focusVars['--focus-outline-width'];
30
+ const FOCUS_OUTLINE_STYLE = focusVars['--focus-outline-style'];
31
+ const FOCUS_OUTLINE_COLOR = focusVars['--focus-outline-color'];
32
+
33
+ const FOCUS_OUTLINE_OFFSET = focusVars['--focus-outline-offset'];
24
34
 
25
- const FOCUS_OUTLINE_WIDTH = '2px';
26
- // 3px, per Design Conventions §User Interaction States: "2px --color-accent
27
- // outline at 3px offset". Most components had drifted to 2px; Button, Calendar,
28
- // Dialog and Pagination were the ones matching the spec, so the consolidation
29
- // takes their value rather than the majority's.
30
- const FOCUS_OUTLINE_OFFSET = '3px';
31
- const FOCUS_OUTLINE_COLOR = colorVars['--color-accent'];
35
+ /**
36
+ * The ring as a single `outline` value, for reading it at runtime — an
37
+ * assertion, or an element styled imperatively.
38
+ *
39
+ * NOT usable inside another file's `stylex.create`: StyleX resolves imported
40
+ * `defineVars` and nothing else, so a component whose condition
41
+ * {@link focusOutlineStyles} cannot express (Switch, whose ring keys off a
42
+ * component-scoped ancestor marker) has to compose the `focusVars` tokens
43
+ * itself.
44
+ */
45
+ export const FOCUS_OUTLINE = `${FOCUS_OUTLINE_WIDTH} ${FOCUS_OUTLINE_STYLE} ${FOCUS_OUTLINE_COLOR}`;
32
46
 
33
47
  /**
34
48
  * Written as longhands rather than the `outline` shorthand.
@@ -40,7 +54,7 @@ const FOCUS_OUTLINE_COLOR = colorVars['--color-accent'];
40
54
  */
41
55
  const focusOutlineLonghands = {
42
56
  outlineWidth: FOCUS_OUTLINE_WIDTH,
43
- outlineStyle: 'solid',
57
+ outlineStyle: FOCUS_OUTLINE_STYLE,
44
58
  outlineColor: FOCUS_OUTLINE_COLOR,
45
59
  } as const;
46
60
 
@@ -53,8 +67,8 @@ const focusOutlineLonghands = {
53
67
  * Longhands, not the `outline` shorthand, for the same reason the styles are:
54
68
  * a shorthand resets every longhand it covers, so a caller could not re-color
55
69
  * the ring without restating its width and style. Split, each part is
56
- * independently overridable — and `--color-accent` stays a var, so a theme's
57
- * accent still flows through.
70
+ * independently overridable — and every part stays a var, so a theme's
71
+ * `--focus-outline-*` overrides still flow through.
58
72
  *
59
73
  * Keys are camelCase to match `HTMLElement.style`, so this spreads straight
60
74
  * onto an element:
@@ -66,7 +80,7 @@ const focusOutlineLonghands = {
66
80
  */
67
81
  export const FOCUS_OUTLINE_PARTS = {
68
82
  outlineWidth: FOCUS_OUTLINE_WIDTH,
69
- outlineStyle: 'solid',
83
+ outlineStyle: FOCUS_OUTLINE_STYLE,
70
84
  outlineColor: FOCUS_OUTLINE_COLOR,
71
85
  outlineOffset: FOCUS_OUTLINE_OFFSET,
72
86
  } as const;
@@ -113,7 +127,7 @@ export const focusOutlineStyles = stylex.create({
113
127
  publishFocusVisibleVars: {
114
128
  '--_focus-outline': {
115
129
  default: 'none',
116
- ':focus-visible': `${FOCUS_OUTLINE_WIDTH} solid ${FOCUS_OUTLINE_COLOR}`,
130
+ ':focus-visible': FOCUS_OUTLINE,
117
131
  },
118
132
  '--_focus-outline-offset': {
119
133
  default: '0',
@@ -123,7 +137,7 @@ export const focusOutlineStyles = stylex.create({
123
137
  focusWithinOrPublished: {
124
138
  outline: {
125
139
  default: 'var(--_focus-outline, none)',
126
- ':has(:focus-visible)': `${FOCUS_OUTLINE_WIDTH} solid ${FOCUS_OUTLINE_COLOR}`,
140
+ ':has(:focus-visible)': FOCUS_OUTLINE,
127
141
  },
128
142
  outlineOffset: {
129
143
  default: 'var(--_focus-outline-offset, 0)',
@@ -101,3 +101,7 @@ export type {RGBA} from './color';
101
101
  export {devWarn, devError, warnOnce, formatDevMessage} from './devWarning';
102
102
 
103
103
  export {rtlStyles} from './rtlStyles';
104
+
105
+ // The shared focus ring, exported for @astryxdesign/lab — same reason
106
+ // rtlStyles is: a style that must be identical across packages, not copied.
107
+ export {focusOutlineStyles, focusOutlineProps} from './focusOutline.stylex';
@@ -0,0 +1,74 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file interactionModality.ts
5
+ * @input Global pointerdown/keydown events
6
+ * @output `getInteractionModality()` — how the user last interacted
7
+ * @position Internal utility; used where `:focus-visible` alone is too broad
8
+ *
9
+ * `:focus-visible` is the right selector for a focus ring and should stay the
10
+ * condition that draws one. It is not, on its own, "focused by keyboard":
11
+ * per CSS Selectors 4 a pointer-focused element that supports text entry
12
+ * matches it too, deliberately, so that a clicked text field still shows where
13
+ * typing will go. Measured in Chromium — a bare `<input>` clicked with a mouse
14
+ * matches `:focus-visible`.
15
+ *
16
+ * A component that wants a ring for keyboard focus ONLY therefore needs one bit
17
+ * `:focus-visible` cannot give it: which device moved focus. This records that,
18
+ * to be used as a gate ALONGSIDE `:focus-visible`, never as a replacement for
19
+ * it — the browser's heuristic still decides everything else, including
20
+ * `focus({focusVisible: true})`.
21
+ *
22
+ * Listeners are registered once for the document, in the capture phase so they
23
+ * run before the focus they explain, and are never removed: two passive
24
+ * listeners for the whole app, versus a pair per mounted input.
25
+ */
26
+
27
+ export type InteractionModality = 'keyboard' | 'pointer';
28
+
29
+ // Default to keyboard: with no interaction yet, focus arrived programmatically
30
+ // or from the browser restoring it, and showing a ring is the safe error.
31
+ let modality: InteractionModality = 'keyboard';
32
+ let isListening = false;
33
+
34
+ function onPointerDown(): void {
35
+ modality = 'pointer';
36
+ }
37
+
38
+ function onKeyDown(event: KeyboardEvent): void {
39
+ // Modifier-only presses are not navigation — holding Shift before a click
40
+ // must not turn that click into "keyboard".
41
+ if (event.metaKey || event.altKey || event.ctrlKey) {
42
+ return;
43
+ }
44
+ modality = 'keyboard';
45
+ }
46
+
47
+ /**
48
+ * Start tracking, once per document. Safe to call repeatedly and on the server
49
+ * (where it does nothing).
50
+ */
51
+ export function trackInteractionModality(): void {
52
+ if (isListening || typeof document === 'undefined') {
53
+ return;
54
+ }
55
+ isListening = true;
56
+ document.addEventListener('pointerdown', onPointerDown, {
57
+ capture: true,
58
+ passive: true,
59
+ });
60
+ document.addEventListener('keydown', onKeyDown, {
61
+ capture: true,
62
+ passive: true,
63
+ });
64
+ }
65
+
66
+ /** How the user last interacted with the page. */
67
+ export function getInteractionModality(): InteractionModality {
68
+ return modality;
69
+ }
70
+
71
+ /** Test-only: restore the initial state between cases. */
72
+ export function __resetInteractionModalityForTest(): void {
73
+ modality = 'keyboard';
74
+ }