@astryxdesign/core 0.7.17-canary.g4ea41ce → 0.7.17-canary.g5a3fd39

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 (82) hide show
  1. package/dist/Badge/Badge.d.ts.map +1 -1
  2. package/dist/Badge/Badge.js +1 -0
  3. package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
  4. package/dist/BottomSheet/BottomSheetPanel.js +1 -0
  5. package/dist/Chat/useSpeechRecognition.d.ts.map +1 -1
  6. package/dist/Chat/useSpeechRecognition.js +6 -2
  7. package/dist/Dialog/Dialog.d.ts.map +1 -1
  8. package/dist/Dialog/Dialog.js +1 -0
  9. package/dist/Drawer/Drawer.d.ts.map +1 -1
  10. package/dist/Drawer/Drawer.js +1 -0
  11. package/dist/Layout/LayoutContent.d.ts.map +1 -1
  12. package/dist/Layout/LayoutContent.js +2 -1
  13. package/dist/Layout/LayoutFooter.d.ts.map +1 -1
  14. package/dist/Layout/LayoutFooter.js +2 -1
  15. package/dist/Layout/LayoutHeader.d.ts.map +1 -1
  16. package/dist/Layout/LayoutHeader.js +2 -1
  17. package/dist/Layout/LayoutPanel.d.ts.map +1 -1
  18. package/dist/Layout/LayoutPanel.js +2 -1
  19. package/dist/Layout/container.stylex.d.ts +4 -1
  20. package/dist/Layout/container.stylex.d.ts.map +1 -1
  21. package/dist/Layout/container.stylex.js +3 -2
  22. package/dist/Layout/containerBlockBleed.stylex.d.ts +27 -0
  23. package/dist/Layout/containerBlockBleed.stylex.d.ts.map +1 -0
  24. package/dist/Layout/containerBlockBleed.stylex.js +31 -0
  25. package/dist/Layout/layoutReset.d.ts +2 -0
  26. package/dist/Layout/layoutReset.d.ts.map +1 -1
  27. package/dist/Layout/overlayPaddingReset.stylex.d.ts +2 -0
  28. package/dist/Layout/overlayPaddingReset.stylex.d.ts.map +1 -1
  29. package/dist/Layout/overlayPaddingReset.stylex.js +2 -0
  30. package/dist/MobileNav/MobileNav.d.ts.map +1 -1
  31. package/dist/MobileNav/MobileNav.js +1 -0
  32. package/dist/MobileNav/MobileNav.textColor.a11y.chromium.spec.d.ts.map +1 -0
  33. package/dist/ScrollableArea/ScrollableArea.d.ts.map +1 -1
  34. package/dist/ScrollableArea/ScrollableArea.js +2 -1
  35. package/dist/Table/Table.d.ts.map +1 -1
  36. package/dist/Table/Table.js +4 -4
  37. package/dist/Toast/Toast.d.ts.map +1 -1
  38. package/dist/Toast/Toast.js +6 -4
  39. package/dist/Toast/ToastViewport.d.ts.map +1 -1
  40. package/dist/Toast/ToastViewport.js +1 -0
  41. package/dist/astryx.css +10 -2
  42. package/dist/hooks/mediaSide.d.ts +33 -0
  43. package/dist/hooks/mediaSide.d.ts.map +1 -0
  44. package/dist/hooks/mediaSide.js +67 -0
  45. package/dist/hooks/useAutoMediaMode.d.ts +6 -15
  46. package/dist/hooks/useAutoMediaMode.d.ts.map +1 -1
  47. package/dist/hooks/useAutoMediaMode.js +15 -35
  48. package/dist/hooks/useClipboard.d.ts +4 -2
  49. package/dist/hooks/useClipboard.d.ts.map +1 -1
  50. package/dist/hooks/useClipboard.js +75 -2
  51. package/dist/theme/localTokens.d.ts +7 -1
  52. package/dist/theme/localTokens.d.ts.map +1 -1
  53. package/dist/theme/localTokens.js +10 -2
  54. package/dist/theme/themeAdaptations.d.ts.map +1 -1
  55. package/dist/theme/themeAdaptations.js +29 -12
  56. package/package.json +4 -4
  57. package/src/Badge/Badge.doc.mjs +1 -1
  58. package/src/Badge/Badge.tsx +5 -0
  59. package/src/BottomSheet/BottomSheetPanel.tsx +4 -0
  60. package/src/Chat/useSpeechRecognition.doc.mjs +2 -1
  61. package/src/Chat/useSpeechRecognition.ts +5 -2
  62. package/src/Dialog/Dialog.doc.mjs +3 -3
  63. package/src/Dialog/Dialog.tsx +4 -0
  64. package/src/Drawer/Drawer.tsx +4 -0
  65. package/src/Layout/LayoutContent.tsx +2 -0
  66. package/src/Layout/LayoutFooter.tsx +2 -0
  67. package/src/Layout/LayoutHeader.tsx +2 -0
  68. package/src/Layout/LayoutPanel.tsx +2 -0
  69. package/src/Layout/container.stylex.ts +3 -0
  70. package/src/Layout/containerBlockBleed.stylex.ts +42 -0
  71. package/src/Layout/overlayPaddingReset.stylex.ts +4 -0
  72. package/src/MobileNav/MobileNav.tsx +4 -0
  73. package/src/ScrollableArea/ScrollableArea.tsx +2 -0
  74. package/src/Table/Table.tsx +12 -11
  75. package/src/Toast/Toast.tsx +10 -3
  76. package/src/Toast/ToastViewport.tsx +3 -0
  77. package/src/hooks/mediaSide.ts +87 -0
  78. package/src/hooks/useAutoMediaMode.ts +32 -48
  79. package/src/hooks/useClipboard.doc.mjs +2 -2
  80. package/src/hooks/useClipboard.ts +86 -4
  81. package/src/theme/localTokens.ts +9 -1
  82. package/src/theme/themeAdaptations.ts +44 -16
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @file mediaSide.ts
3
+ * @input A painted surface color, the page's text color and the theme's
4
+ * on-colors
5
+ * @output The media side text takes on the surface, or 'off'
6
+ * @position Internal; the rules useAutoMediaMode and Toast measure with.
7
+ * Pure color math with no React or StyleX, so contrast checks import it.
8
+ */
9
+ import type { RGBA } from '../utils/color.js';
10
+ /** A surface luminance context, or `"off"` when no media context is wanted. */
11
+ export type DetectedMediaMode = 'dark' | 'light' | 'off';
12
+ /**
13
+ * Which media context a surface wants: `'off'` when its ambient text already
14
+ * reads on the surface, otherwise whichever on-color reads better. Pure — the
15
+ * DOM read is the caller's. Ties between the two sides go to dark, matching
16
+ * the convention that an inverted surface is usually the dark one.
17
+ *
18
+ * The `'off'` answer is the point of measuring at all. A surface that a theme
19
+ * calls inverted but paints pale does not want an inverted context; its own
20
+ * text is already correct for it, and forcing one is how white-on-pale-grey
21
+ * happens.
22
+ */
23
+ export declare function pickMediaMode(background: RGBA, ambient: RGBA | null, onDark: RGBA | null, onLight: RGBA | null): DetectedMediaMode | null;
24
+ /**
25
+ * Pick the side for a surface that a component paints as inverted, such as a
26
+ * toast. Its text takes the on-color that reads best on the surface. It keeps
27
+ * the surface's own text only when that reads at least as well as both
28
+ * on-colors, as on a pale surface a theme calls inverted.
29
+ */
30
+ export declare function pickInvertedSide(background: RGBA, ambient: RGBA | null, onDark: RGBA | null, onLight: RGBA | null): DetectedMediaMode | null;
31
+ /** A rule that picks a media side from the painted colors. */
32
+ export type MediaSidePicker = typeof pickMediaMode;
33
+ //# sourceMappingURL=mediaSide.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mediaSide.d.ts","sourceRoot":"","sources":["../../src/hooks/mediaSide.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,gBAAgB,CAAC;AAGzC,+EAA+E;AAC/E,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAWzD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,IAAI,EAChB,OAAO,EAAE,IAAI,GAAG,IAAI,EACpB,MAAM,EAAE,IAAI,GAAG,IAAI,EACnB,OAAO,EAAE,IAAI,GAAG,IAAI,GACnB,iBAAiB,GAAG,IAAI,CAe1B;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,IAAI,EAChB,OAAO,EAAE,IAAI,GAAG,IAAI,EACpB,MAAM,EAAE,IAAI,GAAG,IAAI,EACnB,OAAO,EAAE,IAAI,GAAG,IAAI,GACnB,iBAAiB,GAAG,IAAI,CAa1B;AAED,8DAA8D;AAC9D,MAAM,MAAM,eAAe,GAAG,OAAO,aAAa,CAAC"}
@@ -0,0 +1,67 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file mediaSide.ts
5
+ * @input A painted surface color, the page's text color and the theme's
6
+ * on-colors
7
+ * @output The media side text takes on the surface, or 'off'
8
+ * @position Internal; the rules useAutoMediaMode and Toast measure with.
9
+ * Pure color math with no React or StyleX, so contrast checks import it.
10
+ */
11
+
12
+ import { contrastRatio } from "../theme/contrast.js";
13
+
14
+ /** A surface luminance context, or `"off"` when no media context is wanted. */
15
+
16
+ /**
17
+ * Contrast at which a surface's own text reads well enough that no media
18
+ * context is wanted. This is WCAG's large-text line. It is low on purpose: it
19
+ * decides if a surface is effectively inverted, not if its text meets a
20
+ * standard. A media context on a 3:1 pairing changes accent, overlays and
21
+ * borders with no legibility gain.
22
+ */
23
+ const AMBIENT_READS_AT = 3;
24
+
25
+ /**
26
+ * Which media context a surface wants: `'off'` when its ambient text already
27
+ * reads on the surface, otherwise whichever on-color reads better. Pure — the
28
+ * DOM read is the caller's. Ties between the two sides go to dark, matching
29
+ * the convention that an inverted surface is usually the dark one.
30
+ *
31
+ * The `'off'` answer is the point of measuring at all. A surface that a theme
32
+ * calls inverted but paints pale does not want an inverted context; its own
33
+ * text is already correct for it, and forcing one is how white-on-pale-grey
34
+ * happens.
35
+ */
36
+ export function pickMediaMode(background, ambient, onDark, onLight) {
37
+ if (onDark === null || onLight === null) {
38
+ return null;
39
+ }
40
+ if (ambient !== null && contrastRatio(ambient, background) >= AMBIENT_READS_AT) {
41
+ return 'off';
42
+ }
43
+ return contrastRatio(onDark, background) >= contrastRatio(onLight, background) ? 'dark' : 'light';
44
+ }
45
+
46
+ /**
47
+ * Pick the side for a surface that a component paints as inverted, such as a
48
+ * toast. Its text takes the on-color that reads best on the surface. It keeps
49
+ * the surface's own text only when that reads at least as well as both
50
+ * on-colors, as on a pale surface a theme calls inverted.
51
+ */
52
+ export function pickInvertedSide(background, ambient, onDark, onLight) {
53
+ if (onDark === null || onLight === null) {
54
+ return null;
55
+ }
56
+ const dark = contrastRatio(onDark, background);
57
+ const light = contrastRatio(onLight, background);
58
+ if (ambient !== null) {
59
+ const own = contrastRatio(ambient, background);
60
+ if (own >= dark && own >= light) {
61
+ return 'off';
62
+ }
63
+ }
64
+ return dark >= light ? 'dark' : 'light';
65
+ }
66
+
67
+ /** A rule that picks a media side from the painted colors. */
@@ -1,19 +1,5 @@
1
1
  import type { RefObject } from 'react';
2
- import type { RGBA } from '../utils/color.js';
3
- /** A surface luminance context, or `"off"` when no media context is wanted. */
4
- export type DetectedMediaMode = 'dark' | 'light' | 'off';
5
- /**
6
- * Which media context a surface wants: `'off'` when its ambient text already
7
- * reads on the surface, otherwise whichever on-color reads better. Pure — the
8
- * DOM read is the caller's. Ties between the two sides go to dark, matching
9
- * the convention that an inverted surface is usually the dark one.
10
- *
11
- * The `'off'` answer is the point of measuring at all. A surface that a theme
12
- * calls inverted but paints pale does not want an inverted context; its own
13
- * text is already correct for it, and forcing one is how white-on-pale-grey
14
- * happens.
15
- */
16
- export declare function pickMediaMode(background: RGBA, ambient: RGBA | null, onDark: RGBA | null, onLight: RGBA | null): DetectedMediaMode | null;
2
+ import { type DetectedMediaMode, type MediaSidePicker } from './mediaSide.js';
17
3
  /**
18
4
  * Detect the media context for the element's surroundings.
19
5
  *
@@ -28,4 +14,9 @@ export declare function pickMediaMode(background: RGBA, ambient: RGBA | null, on
28
14
  * The caller renders its fallback for those.
29
15
  */
30
16
  export declare function useAutoMediaMode(ref: RefObject<HTMLElement | null>, isEnabled: boolean): DetectedMediaMode | null;
17
+ /**
18
+ * Detect the media side for the surface `ref` paints itself, by `pick`.
19
+ * Returns null until a measurement succeeds, as useAutoMediaMode does.
20
+ */
21
+ export declare function useSurfaceMediaMode(ref: RefObject<HTMLElement | null>, isEnabled: boolean, pick: MediaSidePicker): DetectedMediaMode | null;
31
22
  //# sourceMappingURL=useAutoMediaMode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAutoMediaMode.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoMediaMode.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AACrC,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,gBAAgB,CAAC;AAMzC,+EAA+E;AAC/E,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AA4EzD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,IAAI,EAChB,OAAO,EAAE,IAAI,GAAG,IAAI,EACpB,MAAM,EAAE,IAAI,GAAG,IAAI,EACnB,OAAO,EAAE,IAAI,GAAG,IAAI,GACnB,iBAAiB,GAAG,IAAI,CAe1B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAClC,SAAS,EAAE,OAAO,GACjB,iBAAiB,GAAG,IAAI,CAoD1B"}
1
+ {"version":3,"file":"useAutoMediaMode.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoMediaMode.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAMrC,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AAmErB;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAClC,SAAS,EAAE,OAAO,GACjB,iBAAiB,GAAG,IAAI,CAM1B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAClC,SAAS,EAAE,OAAO,EAClB,IAAI,EAAE,eAAe,GACpB,iBAAiB,GAAG,IAAI,CAE1B"}
@@ -21,11 +21,10 @@
21
21
  // so a chromatic but legible surface loses nothing.
22
22
  import { useRef, useState } from 'react';
23
23
  import { parseColor, formatColor } from "../utils/color.js";
24
- import { contrastRatio, compositeOver } from "../theme/contrast.js";
24
+ import { compositeOver } from "../theme/contrast.js";
25
25
  import { useTheme } from "../theme/useTheme.js";
26
26
  import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
27
-
28
- /** A surface luminance context, or `"off"` when no media context is wanted. */
27
+ import { pickMediaMode } from "./mediaSide.js";
29
28
 
30
29
  /**
31
30
  * Resolve token references to the colors they paint, through a hidden probe.
@@ -84,36 +83,6 @@ function resolveBackdrop(element) {
84
83
  return layers.reduceRight((backdrop, layer) => compositeOver(layer, backdrop), base);
85
84
  }
86
85
 
87
- /**
88
- * Contrast at which a surface's own text reads well enough that no media
89
- * context is wanted. This is WCAG's large-text line. It is low on purpose: it
90
- * decides if a surface is effectively inverted, not if its text meets a
91
- * standard. A media context on a 3:1 pairing changes accent, overlays and
92
- * borders with no legibility gain.
93
- */
94
- const AMBIENT_READS_AT = 3;
95
-
96
- /**
97
- * Which media context a surface wants: `'off'` when its ambient text already
98
- * reads on the surface, otherwise whichever on-color reads better. Pure — the
99
- * DOM read is the caller's. Ties between the two sides go to dark, matching
100
- * the convention that an inverted surface is usually the dark one.
101
- *
102
- * The `'off'` answer is the point of measuring at all. A surface that a theme
103
- * calls inverted but paints pale does not want an inverted context; its own
104
- * text is already correct for it, and forcing one is how white-on-pale-grey
105
- * happens.
106
- */
107
- export function pickMediaMode(background, ambient, onDark, onLight) {
108
- if (onDark === null || onLight === null) {
109
- return null;
110
- }
111
- if (ambient !== null && contrastRatio(ambient, background) >= AMBIENT_READS_AT) {
112
- return 'off';
113
- }
114
- return contrastRatio(onDark, background) >= contrastRatio(onLight, background) ? 'dark' : 'light';
115
- }
116
-
117
86
  /**
118
87
  * Detect the media context for the element's surroundings.
119
88
  *
@@ -128,6 +97,17 @@ export function pickMediaMode(background, ambient, onDark, onLight) {
128
97
  * The caller renders its fallback for those.
129
98
  */
130
99
  export function useAutoMediaMode(ref, isEnabled) {
100
+ return useMeasuredMediaMode(() => ref.current?.parentElement ?? null, isEnabled, pickMediaMode);
101
+ }
102
+
103
+ /**
104
+ * Detect the media side for the surface `ref` paints itself, by `pick`.
105
+ * Returns null until a measurement succeeds, as useAutoMediaMode does.
106
+ */
107
+ export function useSurfaceMediaMode(ref, isEnabled, pick) {
108
+ return useMeasuredMediaMode(() => ref.current, isEnabled, pick);
109
+ }
110
+ function useMeasuredMediaMode(surfaceOf, isEnabled, pick) {
131
111
  const [detected, setDetected] = useState(null);
132
112
  // `tokens` is a stable reference unless the theme or color mode changes.
133
113
  const {
@@ -141,7 +121,7 @@ export function useAutoMediaMode(ref, isEnabled) {
141
121
  // name catches that. So the measurement runs on each render, and it skips
142
122
  // its expensive half when nothing moved (see the early return below).
143
123
  useIsomorphicLayoutEffect(() => {
144
- const surface = ref.current?.parentElement ?? null;
124
+ const surface = surfaceOf();
145
125
  if (!isEnabled || surface === null) {
146
126
  return;
147
127
  }
@@ -163,7 +143,7 @@ export function useAutoMediaMode(ref, isEnabled) {
163
143
  tokens
164
144
  };
165
145
  const [ambient, onDark, onLight] = resolvePaintedColors(surface, ['--color-text-primary', '--color-on-dark', '--color-on-light']);
166
- const next = pickMediaMode(background, ambient, onDark, onLight);
146
+ const next = pick(background, ambient, onDark, onLight);
167
147
  if (next === null) {
168
148
  return;
169
149
  }
@@ -23,8 +23,10 @@ export interface UseClipboardReturn {
23
23
  /**
24
24
  * Write `text` to the clipboard. On success, flips `isCopied` to true,
25
25
  * announces the configured message, and (re)starts the reset timer;
26
- * resolves `true`. A clipboard rejection is a silent no-op that leaves the
27
- * copied state unchanged and resolves `false`.
26
+ * resolves `true`. Where the frame refuses the async Clipboard API, or the
27
+ * browser refuses the write, the text is copied with the browser copy
28
+ * command inside the reader's click or key press. A failed write is a silent
29
+ * no-op that leaves the copied state unchanged and resolves `false`.
28
30
  */
29
31
  copy: (text: string) => Promise<boolean>;
30
32
  /** True for `resetAfterMs` after the most recent successful copy. */
@@ -1 +1 @@
1
- {"version":3,"file":"useClipboard.d.ts","sourceRoot":"","sources":["../../src/hooks/useClipboard.ts"],"names":[],"mappings":"AA8BA;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG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B,CAGpB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;IAClE,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC;AAED,gDAAgD;AAChD,MAAM,WAAW,sBAAuB,SAAQ,kBAAkB;IAChE;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,uBAA4B,GACpC,sBAAsB,CAkFxB"}
@@ -4,7 +4,8 @@
4
4
 
5
5
  /**
6
6
  * @file useClipboard.ts
7
- * @input Uses React state/effect/callback; navigator.clipboard; useAnnounce
7
+ * @input Uses React state/effect/callback; navigator.clipboard (else the
8
+ * copy command and its copy event); useAnnounce
8
9
  * @output Exports useClipboard hook plus its options/return types
9
10
  * @position Core behavior hook; owns the copy-to-clipboard behavior shared by
10
11
  * CodeBlock and Timestamp — the clipboard write, the transient "copied"
@@ -27,6 +28,78 @@ import { useAnnounce } from "./useAnnounce.js";
27
28
  */
28
29
  const DEFAULT_RESET_AFTER_MS = 2000;
29
30
 
31
+ /**
32
+ * Whether this document may use the async Clipboard API to write. A frame
33
+ * whose permissions policy does not allow `clipboard-write` (a sandboxed
34
+ * viewer or an embed) refuses it, and the browser logs a policy violation for
35
+ * each try. Without a policy API, the write is tried.
36
+ */
37
+ function clipboardWriteAllowed() {
38
+ const doc = document;
39
+ const policy = doc.permissionsPolicy ?? doc.featurePolicy;
40
+ return typeof policy?.allowsFeature === 'function' ? policy.allowsFeature('clipboard-write') : true;
41
+ }
42
+
43
+ /**
44
+ * Copy text with the browser's copy command, which a click can still run where
45
+ * the async Clipboard API is refused. The text goes in through the `copy` event
46
+ * the command fires, so no element takes focus or the selection: a control in
47
+ * a hover card or an open modal dialog keeps both.
48
+ * @throws when the browser does not copy
49
+ */
50
+ function copyThroughCopyCommand(text) {
51
+ const activation = navigator.userActivation;
52
+ if (activation?.isActive === false) {
53
+ throw new Error('The copy command runs only in a click or a key press.');
54
+ }
55
+ let written = false;
56
+ const write = event => {
57
+ if (event.clipboardData == null) {
58
+ return;
59
+ }
60
+ event.clipboardData.setData('text/plain', text);
61
+ event.preventDefault();
62
+ // The copy is the hook's own, so the page's copy handlers do not change it.
63
+ event.stopImmediatePropagation();
64
+ written = true;
65
+ };
66
+ window.addEventListener('copy', write, true);
67
+ let copied;
68
+ try {
69
+ copied = document.execCommand('copy');
70
+ } finally {
71
+ window.removeEventListener('copy', write, true);
72
+ }
73
+ if (!copied || !written) {
74
+ throw new Error('The browser did not copy the text.');
75
+ }
76
+ }
77
+
78
+ /**
79
+ * The async Clipboard API comes first. Where the frame refuses it, the copy
80
+ * command copies instead: the policy says so before a try, which the browser
81
+ * would log as a violation, and a write the browser refuses says so after.
82
+ */
83
+ async function writeClipboardText(text) {
84
+ if (!clipboardWriteAllowed()) {
85
+ copyThroughCopyCommand(text);
86
+ return;
87
+ }
88
+ try {
89
+ await navigator.clipboard.writeText(text);
90
+ } catch (error) {
91
+ if (!(error instanceof DOMException && error.name === 'NotAllowedError')) {
92
+ throw error;
93
+ }
94
+ try {
95
+ copyThroughCopyCommand(text);
96
+ } catch {
97
+ // The browser's refusal says more than the copy command's failure.
98
+ throw error;
99
+ }
100
+ }
101
+ }
102
+
30
103
  /**
31
104
  * Options for {@link useClipboard}.
32
105
  */
@@ -113,7 +186,7 @@ export function useClipboardCopy(options = {}) {
113
186
  }, []);
114
187
  const copy = useCallback(async text => {
115
188
  try {
116
- await navigator.clipboard.writeText(text);
189
+ await writeClipboardText(text);
117
190
  } catch (error) {
118
191
  if (!isMountedRef.current) {
119
192
  onError?.(error);
@@ -11,7 +11,13 @@ export interface ResolvedLocalTokenContract {
11
11
  owners: Record<string, string>;
12
12
  lineage: string[];
13
13
  }
14
- export declare function assertNoTokenCycles(tokenValues: Record<string, string>, context?: string, relevantNames?: ReadonlySet<string>): void;
14
+ /**
15
+ * Throws when a token map holds a value that never ends (an object inside
16
+ * itself) or tokens that read each other. `context` names where the map
17
+ * comes from; `contextOf`, when given, names where one token's value comes
18
+ * from instead (a merged map holds the root's values beside a rule's).
19
+ */
20
+ export declare function assertNoTokenCycles(tokenValues: Record<string, string>, context?: string, relevantNames?: ReadonlySet<string>, contextOf?: (name: string) => string): void;
15
21
  /**
16
22
  * Resolve and validate the opt-in theme-local token contract.
17
23
  *
@@ -1 +1 @@
1
- {"version":3,"file":"localTokens.d.ts","sourceRoot":"","sources":["../../src/theme/localTokens.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAC,YAAY,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AAY5D,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AA+DD,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,OAAO,CAAC,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAClC,IAAI,CAsHN;AAwDD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE;IACL,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CAC1C,EACD,IAAI,EAAE,YAAY,GAAG,SAAS,EAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAC/C,0BAA0B,GAAG,SAAS,CAyExC;AAED;;;;;;GAMG;AACH,wBAAgB,4B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AACH,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,SAAS,EACpD,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAClD,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CA2BpC"}
@@ -53,7 +53,14 @@ function collectCustomPropertyReferences(value, refs, holding = new Set()) {
53
53
  holding.delete(value);
54
54
  }
55
55
  }
56
- export function assertNoTokenCycles(tokenValues, context, relevantNames) {
56
+
57
+ /**
58
+ * Throws when a token map holds a value that never ends (an object inside
59
+ * itself) or tokens that read each other. `context` names where the map
60
+ * comes from; `contextOf`, when given, names where one token's value comes
61
+ * from instead (a merged map holds the root's values beside a rule's).
62
+ */
63
+ export function assertNoTokenCycles(tokenValues, context, relevantNames, contextOf) {
57
64
  const dependencies = new Map();
58
65
  for (const [name, value] of Object.entries(tokenValues)) {
59
66
  const refs = new Set();
@@ -63,7 +70,8 @@ export function assertNoTokenCycles(tokenValues, context, relevantNames) {
63
70
  if (!(error instanceof SelfReferenceError)) {
64
71
  throw error;
65
72
  }
66
- throw new Error(`${context ? `${context}: ` : ''}tokens refers to itself: the value of ${name} holds an object it sits in, so it never ends and is no token value.`, {
73
+ const where = contextOf?.(name) ?? context;
74
+ throw new Error(`${where ? `${where}: ` : ''}tokens refers to itself: the value of ${name} holds an object it sits in, so it never ends and is no token value.`, {
67
75
  cause: error
68
76
  });
69
77
  }
@@ -1 +1 @@
1
- {"version":3,"file":"themeAdaptations.d.ts","sourceRoot":"","sources":["../../src/theme/themeAdaptations.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAC,iBAAiB,EAAE,SAAS,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AAC5E,OAAO,KAAK,EAAC,gBAAgB,EAA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AC/B,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,uDAAuD;IACvD,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAChC;AA4PD;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,0BAA0B,GAAG,SAAS,EACjD,KAAK,EAAE,gBAAgB,GAAG,SAAS,GAClC,0BAA0B,CAmD5B;AAyYD;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,mBAAmB,GAAG,SAAS,EAC1C,GAAG,EAAE,mBAAmB,GACvB,mBAAmB,CAqFrB;AAsCD,6DAA6D;AAC7D,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,0BAA0B,EACvC,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EACnD,cAAc,CAAC,EAAE,iBAAiB,GACjC,2BAA2B,EAAE,GAAG,SAAS,CAmF3C"}
@@ -117,16 +117,29 @@ function assertAllowedKeys(value, allowed, path) {
117
117
  }
118
118
  }
119
119
  }
120
- function cloneData(value) {
121
- if (Array.isArray(value)) {
122
- const cloned = [];
123
- for (const item of value) {
124
- cloned.push(cloneData(item));
120
+
121
+ /**
122
+ * A deep copy of plain data. A value inside the objects that hold it never
123
+ * ends, so it is refused by name (`path`) instead of overflowing the stack.
124
+ */
125
+ function cloneData(value, path = 'value', holding = new Set()) {
126
+ if (Array.isArray(value) || isRecord(value)) {
127
+ if (holding.has(value)) {
128
+ throw new Error(`${path} holds an object it sits in, so it never ends and is no theme value.`);
129
+ }
130
+ holding.add(value);
131
+ try {
132
+ if (Array.isArray(value)) {
133
+ const cloned = [];
134
+ for (const [i, item] of value.entries()) {
135
+ cloned.push(cloneData(item, `${path}[${i}]`, holding));
136
+ }
137
+ return cloned;
138
+ }
139
+ return Object.fromEntries(Object.entries(value).map(([key, nested]) => [key, cloneData(nested, `${path}.${key}`, holding)]));
140
+ } finally {
141
+ holding.delete(value);
125
142
  }
126
- return cloned;
127
- }
128
- if (isRecord(value)) {
129
- return Object.fromEntries(Object.entries(value).map(([key, nested]) => [key, cloneData(nested)]));
130
143
  }
131
144
  return value;
132
145
  }
@@ -178,7 +191,7 @@ function normalizeCondition(value, path) {
178
191
  if (Object.keys(defined).length === 0) {
179
192
  throw new Error(`${path} must contain at least one condition.`);
180
193
  }
181
- const condition = cloneData(defined);
194
+ const condition = cloneData(defined, path);
182
195
  if (condition.width !== undefined) {
183
196
  assertRecord(condition.width, `${path}.width`);
184
197
  assertAllowedKeys(condition.width, WIDTH_CONDITION_KEYS, `${path}.width`);
@@ -212,7 +225,7 @@ function normalizeValue(value, path) {
212
225
  throw new Error(`${path}.${key} must be an object.`);
213
226
  }
214
227
  }
215
- return cloneData(value);
228
+ return cloneData(value, path);
216
229
  }
217
230
  function normalizeRule(value, path) {
218
231
  assertRecord(value, path);
@@ -536,7 +549,11 @@ function assertNoReachableTokenCycles(themeName, points, rootTokens, rootLocalTo
536
549
  }
537
550
  const indexes = matchingRuleIndexes.join(', ');
538
551
  const queries = matchingRuleIndexes.map(index => rules[index].query).join('; ');
539
- assertNoTokenCycles(effective, `defineTheme("${themeName}").adaptations ${matchingRuleIndexes.length === 1 ? 'rule' : 'overlapping rules'} [${indexes}] (${queries})`, relevantNames);
552
+ const ruleContext = `defineTheme("${themeName}").adaptations ${matchingRuleIndexes.length === 1 ? 'rule' : 'overlapping rules'} [${indexes}] (${queries})`;
553
+ assertNoTokenCycles(effective, ruleContext, relevantNames,
554
+ // A value no matching rule sets is the theme's own root token (a
555
+ // root local token that holds itself is refused before this).
556
+ name => relevantNames.has(name) ? ruleContext : `defineTheme("${themeName}").tokens`);
540
557
  }
541
558
  }
542
559
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/core",
3
- "version": "0.7.17-canary.g4ea41ce",
3
+ "version": "0.7.17-canary.g5a3fd39",
4
4
  "displayName": "Astryx Core",
5
5
  "description": "The Astryx component library: accessible, themeable React components with built-in spacing, dark mode, and StyleX styling.",
6
6
  "author": "Meta Open Source",
@@ -940,9 +940,9 @@
940
940
  "react-dom": ">=19.0.0"
941
941
  },
942
942
  "devDependencies": {
943
- "@astryxdesign/a11y-spec": "0.7.17-canary.g4ea41ce",
944
- "@astryxdesign/cli": "0.7.17-canary.g4ea41ce",
945
- "@astryxdesign/interaction-harness": "0.7.17-canary.g4ea41ce",
943
+ "@astryxdesign/a11y-spec": "0.7.17-canary.g5a3fd39",
944
+ "@astryxdesign/cli": "0.7.17-canary.g5a3fd39",
945
+ "@astryxdesign/interaction-harness": "0.7.17-canary.g5a3fd39",
946
946
  "@babel/cli": "^7.29.7",
947
947
  "@babel/core": "^7.29.7",
948
948
  "@babel/preset-react": "^7.29.7",
@@ -20,7 +20,7 @@ export const docs = {
20
20
  type: 'ReactNode',
21
21
  required: true,
22
22
  description:
23
- 'Badge text content. A badge is one line and at least as tall as that line of its label, so it grows with its text (a larger text size); a label wider than the space available is cut with an ellipsis rather than escaping its container; a string or number label is also set as the badge\'s title so the full text stays reachable on hover.',
23
+ 'Badge text content. A badge is one line and at least as tall as that line of its label, so it grows with its text (a larger text size); it is as wide as its label, so it does not stretch to fill a grid cell or a stack; a label wider than the space available is cut with an ellipsis rather than escaping its container; a string or number label is also set as the badge\'s title so the full text stays reachable on hover.',
24
24
  },
25
25
  {
26
26
  name: 'icon',
@@ -48,6 +48,11 @@ const styles = stylex.create({
48
48
  lineHeight: typeScaleVars['--text-supporting-leading'],
49
49
  fontWeight: fontWeightVars['--font-weight-medium'],
50
50
  whiteSpace: 'nowrap',
51
+ // A badge is as wide as its label. A grid cell and the cross axis of a
52
+ // stack stretch a child whose width is `auto`. In a flex row the badge
53
+ // still shrinks: its flex basis follows this width, and the minimum below
54
+ // lets it go under.
55
+ width: 'fit-content',
51
56
  // A badge is one line by construction — one line tall, `nowrap` — so a
52
57
  // label wider than the space available has to go somewhere. Without these
53
58
  // it went *outside* its container: `nowrap` with nothing to clip it
@@ -341,6 +341,10 @@ const styles = stylex.create({
341
341
  width: '100%',
342
342
  maxWidth: 640,
343
343
  backgroundColor: colorVars['--color-background-surface'],
344
+ // The surface's text color. The browser gives a dialog and a popover
345
+ // CanvasText, which follows the color scheme and not the theme, so text
346
+ // that sets no color of its own (a selected nav row) needs this.
347
+ color: colorVars['--color-text-primary'],
344
348
  // A hairline on the three edges that face the scrim. In dark mode the
345
349
  // surface and the scrim are only a few RGB steps apart, and the shadow is
346
350
  // black on near-black, so the side edges disappear. The block-end edge
@@ -83,7 +83,8 @@ export const docs = {
83
83
  {
84
84
  name: 'isSupported',
85
85
  type: 'boolean',
86
- description: 'Whether this browser provides speech recognition.',
86
+ description:
87
+ 'Whether this browser provides speech recognition. It is false on the server and in the render that hydrates server markup, and turns true in the next render when the browser supports it.',
87
88
  },
88
89
  {
89
90
  name: 'isListening',
@@ -13,8 +13,9 @@
13
13
  * volume level from the microphone via AudioContext analyser.
14
14
  */
15
15
 
16
- import {useState, useCallback, useEffect, useMemo, useRef} from 'react';
16
+ import {useState, useCallback, useEffect, useRef} from 'react';
17
17
  import {useLocale} from '../i18n';
18
+ import {useIsHydrating} from '../hooks/useIsHydrating';
18
19
  import {useIsomorphicLayoutEffect} from '../hooks/useIsomorphicLayoutEffect';
19
20
  import {
20
21
  registerEnglishFallback,
@@ -287,7 +288,9 @@ export function useSpeechRecognition(
287
288
  [externalAudioContext],
288
289
  );
289
290
 
290
- const isSupported = useMemo(() => getSpeechRecognition() != null, []);
291
+ // The server and the render that hydrates its markup report no support,
292
+ // so both draw the same tree.
293
+ const isSupported = !useIsHydrating() && getSpeechRecognition() != null;
291
294
  const [isListening, setIsListening] = useState(false);
292
295
  const [isSpeaking, setIsSpeaking] = useState(false);
293
296
  const [volume, setVolume] = useState(0);
@@ -171,7 +171,7 @@ export const docs = {
171
171
  {
172
172
  guidance: false,
173
173
  description:
174
- 'Nest dialogs inside other dialogs; restructure the flow into steps within a single dialog instead.',
174
+ 'Nest dialogs inside other dialogs; restructure the flow into steps within a single dialog instead. The one exception is an AlertDialog that confirms a destructive action: it asks one question, and Escape closes only the alert.',
175
175
  },
176
176
  {
177
177
  guidance: false,
@@ -242,7 +242,7 @@ export const docsZh = {
242
242
  {
243
243
  guidance: false,
244
244
  description:
245
- 'Nest dialogs inside other dialogs; restructure the flow into steps within a single dialog instead.',
245
+ 'Nest dialogs inside other dialogs; restructure the flow into steps within a single dialog instead. The one exception is an AlertDialog that confirms a destructive action: it asks one question, and Escape closes only the alert.',
246
246
  },
247
247
  {
248
248
  guidance: false,
@@ -315,7 +315,7 @@ export const docsDense = {
315
315
  {
316
316
  guidance: false,
317
317
  description:
318
- 'Nest dialogs inside other dialogs; restructure the flow into steps within a single dialog instead.',
318
+ 'Nest dialogs inside other dialogs; use steps in one dialog. Exception: an AlertDialog confirming a destructive action (one question; Escape closes only the alert).',
319
319
  },
320
320
  {
321
321
  guidance: false,
@@ -217,6 +217,10 @@ const styles = stylex.create({
217
217
  '@media (forced-colors: active)': 'CanvasText',
218
218
  },
219
219
  backgroundColor: colorVars['--color-background-surface'],
220
+ // The surface's text color. The browser gives a dialog and a popover
221
+ // CanvasText, which follows the color scheme and not the theme, so text
222
+ // that sets no color of its own (a selected nav row) needs this.
223
+ color: colorVars['--color-text-primary'],
220
224
  '--_dialog-radius': radiusVars['--radius-container'],
221
225
  borderRadius: 'var(--_dialog-radius)',
222
226
  boxShadow: shadowVars['--shadow-high'],
@@ -131,6 +131,10 @@ const styles = stylex.create({
131
131
  boxSizing: 'border-box',
132
132
  flexDirection: 'column',
133
133
  backgroundColor: colorVars['--color-background-surface'],
134
+ // The surface's text color. The browser gives a dialog and a popover
135
+ // CanvasText, which follows the color scheme and not the theme, so text
136
+ // that sets no color of its own (a selected nav row) needs this.
137
+ color: colorVars['--color-text-primary'],
134
138
  boxShadow: shadowVars['--shadow-high'],
135
139
  // `clip`, not `hidden`: `hidden` makes the panel a scroll container, and
136
140
  // Chromium then holds a finger's drag on the page beside an open