@primer/react 0.0.0-20260225211348 → 0.0.0-20260225214420

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 (83) hide show
  1. package/CHANGELOG.md +37 -5
  2. package/dist/ActionBar/ActionBar.d.ts.map +1 -1
  3. package/dist/ActionBar/ActionBar.js +431 -281
  4. package/dist/ActionList/ActionList-c04a02d6.css +2 -0
  5. package/dist/ActionList/ActionList-c04a02d6.css.map +1 -0
  6. package/dist/ActionList/ActionList.module.css.js +1 -1
  7. package/dist/ActionList/Item.d.ts.map +1 -1
  8. package/dist/ActionList/Item.js +1 -0
  9. package/dist/Autocomplete/Autocomplete.js +76 -159
  10. package/dist/Autocomplete/AutocompleteMenu.js +128 -333
  11. package/dist/Autocomplete/AutocompleteOverlay.js +49 -130
  12. package/dist/Banner/Banner.js +64 -238
  13. package/dist/Blankslate/{Blankslate-f5a9755a.css → Blankslate-a039d79a.css} +2 -2
  14. package/dist/Blankslate/Blankslate-a039d79a.css.map +1 -0
  15. package/dist/Blankslate/Blankslate.module.css.js +1 -1
  16. package/dist/Button/ButtonBase.d.ts.map +1 -1
  17. package/dist/Button/ButtonBase.js +9 -14
  18. package/dist/Checkbox/Checkbox.js +55 -163
  19. package/dist/Dialog/Dialog-1a86df19.css +2 -0
  20. package/dist/Dialog/Dialog-1a86df19.css.map +1 -0
  21. package/dist/Dialog/Dialog.d.ts +7 -0
  22. package/dist/Dialog/Dialog.d.ts.map +1 -1
  23. package/dist/Dialog/Dialog.js +112 -347
  24. package/dist/Dialog/Dialog.module.css.js +1 -1
  25. package/dist/FilteredActionList/FilteredActionList-02db90c6.css +2 -0
  26. package/dist/FilteredActionList/FilteredActionList-02db90c6.css.map +1 -0
  27. package/dist/FilteredActionList/FilteredActionList.d.ts +16 -1
  28. package/dist/FilteredActionList/FilteredActionList.d.ts.map +1 -1
  29. package/dist/FilteredActionList/FilteredActionList.js +147 -42
  30. package/dist/FilteredActionList/FilteredActionList.module.css.js +2 -2
  31. package/dist/Overlay/Overlay-15519c09.css +2 -0
  32. package/dist/Overlay/Overlay-15519c09.css.map +1 -0
  33. package/dist/Overlay/Overlay.module.css.js +1 -1
  34. package/dist/PageLayout/PageLayout-3444a142.css +2 -0
  35. package/dist/PageLayout/PageLayout-3444a142.css.map +1 -0
  36. package/dist/PageLayout/PageLayout.d.ts +72 -2
  37. package/dist/PageLayout/PageLayout.d.ts.map +1 -1
  38. package/dist/PageLayout/PageLayout.js +750 -1235
  39. package/dist/PageLayout/PageLayout.module.css.js +2 -2
  40. package/dist/PageLayout/usePaneWidth.d.ts +18 -6
  41. package/dist/PageLayout/usePaneWidth.d.ts.map +1 -1
  42. package/dist/PageLayout/usePaneWidth.js +126 -112
  43. package/dist/SelectPanel/SelectPanel.d.ts +1 -1
  44. package/dist/SelectPanel/SelectPanel.d.ts.map +1 -1
  45. package/dist/SelectPanel/SelectPanel.js +85 -33
  46. package/dist/SplitPageLayout/SplitPageLayout.d.ts +4 -1
  47. package/dist/SplitPageLayout/SplitPageLayout.d.ts.map +1 -1
  48. package/dist/SplitPageLayout/SplitPageLayout.js +54 -2
  49. package/dist/Text/Text.d.ts +1 -1
  50. package/dist/Text/Text.d.ts.map +1 -1
  51. package/dist/Text/Text.js +10 -13
  52. package/dist/UnderlineNav/UnderlineNavItem.js +56 -149
  53. package/dist/experimental/SelectPanel2/SelectPanel-f0c4b9ca.css +2 -0
  54. package/dist/experimental/SelectPanel2/{SelectPanel-1f8c23b5.css.map → SelectPanel-f0c4b9ca.css.map} +1 -1
  55. package/dist/experimental/SelectPanel2/SelectPanel.js +209 -593
  56. package/dist/experimental/SelectPanel2/SelectPanel.module.css.js +1 -1
  57. package/dist/hooks/useRefObjectAsForwardedRef.d.ts.map +1 -1
  58. package/dist/hooks/useRefObjectAsForwardedRef.js +10 -2
  59. package/dist/hooks/useScrollFlash.d.ts.map +1 -1
  60. package/dist/hooks/useScrollFlash.js +14 -22
  61. package/dist/hooks/useSlots.d.ts +50 -6
  62. package/dist/hooks/useSlots.d.ts.map +1 -1
  63. package/dist/hooks/useSlots.js +114 -36
  64. package/dist/live-region/Announce.d.ts.map +1 -1
  65. package/dist/live-region/Announce.js +7 -4
  66. package/dist/utils/environment.js +9 -0
  67. package/generated/components.json +216 -5
  68. package/package.json +4 -4
  69. package/dist/ActionList/ActionList-f4ac3b54.css +0 -2
  70. package/dist/ActionList/ActionList-f4ac3b54.css.map +0 -1
  71. package/dist/Blankslate/Blankslate-f5a9755a.css.map +0 -1
  72. package/dist/Dialog/Dialog-9e7a4691.css +0 -2
  73. package/dist/Dialog/Dialog-9e7a4691.css.map +0 -1
  74. package/dist/FilteredActionList/FilteredActionList-f6c2dc7a.css +0 -2
  75. package/dist/FilteredActionList/FilteredActionList-f6c2dc7a.css.map +0 -1
  76. package/dist/Overlay/Overlay-43cda449.css +0 -2
  77. package/dist/Overlay/Overlay-43cda449.css.map +0 -1
  78. package/dist/PageLayout/PageLayout-cb491b47.css +0 -2
  79. package/dist/PageLayout/PageLayout-cb491b47.css.map +0 -1
  80. package/dist/experimental/SelectPanel2/SelectPanel-1f8c23b5.css +0 -2
  81. package/dist/utils/descendant-registry.d.ts +0 -32
  82. package/dist/utils/descendant-registry.d.ts.map +0 -1
  83. package/dist/utils/descendant-registry.js +0 -222
@@ -1,4 +1,4 @@
1
- import './SelectPanel-1f8c23b5.css';
1
+ import './SelectPanel-f0c4b9ca.css';
2
2
 
3
3
  var classes = {"Overlay":"prc-SelectPanel2-Overlay--Q-FI","Form":"prc-SelectPanel2-Form-bZ9HS","Container":"prc-SelectPanel2-Container-e5e6-","HeaderContent":"prc-SelectPanel2-HeaderContent-MsaAS","TitleWrapper":"prc-SelectPanel2-TitleWrapper-HzPu3","TextInput":"prc-SelectPanel2-TextInput-lHH1n","Checkbox":"prc-SelectPanel2-Checkbox-AYR38","FlexBox":"prc-SelectPanel2-FlexBox-gWPRg","Title":"prc-SelectPanel2-Title-T-h3f","Description":"prc-SelectPanel2-Description-qTXfi","ClearAction":"prc-SelectPanel2-ClearAction-tQj-f","Footer":"prc-SelectPanel2-Footer-TibV0","FooterContent":"prc-SelectPanel2-FooterContent-UjAOM","FooterActions":"prc-SelectPanel2-FooterActions-T6yQR","SecondaryCheckbox":"prc-SelectPanel2-SecondaryCheckbox-omkf-","SmallText":"prc-SelectPanel2-SmallText-c42ay","SelectPanelLoading":"prc-SelectPanel2-SelectPanelLoading-mtyhD","LoadingText":"prc-SelectPanel2-LoadingText-DB0wN","MessageFull":"prc-SelectPanel2-MessageFull-nY-qF","Octicon":"prc-SelectPanel2-Octicon-zt-zU","Error":"prc-SelectPanel2-Error-ZrZQQ","Warning":"prc-SelectPanel2-Warning-PDsVF","MessageTitle":"prc-SelectPanel2-MessageTitle-T7v9d","MessageContent":"prc-SelectPanel2-MessageContent-UZ9vY","MessageInline":"prc-SelectPanel2-MessageInline-sErQf","Header":"prc-SelectPanel2-Header-LKyEJ"};
4
4
 
@@ -1 +1 @@
1
- {"version":3,"file":"useRefObjectAsForwardedRef.d.ts","sourceRoot":"","sources":["../../src/hooks/useRefObjectAsForwardedRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,SAAS,EAAC,MAAM,OAAO,CAAA;AAGlD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAEjH"}
1
+ {"version":3,"file":"useRefObjectAsForwardedRef.d.ts","sourceRoot":"","sources":["../../src/hooks/useRefObjectAsForwardedRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,SAAS,EAAC,MAAM,OAAO,CAAA;AAGlD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAIjH"}
@@ -9,7 +9,7 @@ import { useImperativeHandle } from 'react';
9
9
  * **NOTE**: The `refObject` should be passed to the underlying element, NOT the `forwardedRef`.
10
10
  */
11
11
  function useRefObjectAsForwardedRef(forwardedRef, refObject) {
12
- const $ = c(2);
12
+ const $ = c(4);
13
13
  let t0;
14
14
  if ($[0] !== refObject.current) {
15
15
  t0 = () => refObject.current;
@@ -18,7 +18,15 @@ function useRefObjectAsForwardedRef(forwardedRef, refObject) {
18
18
  } else {
19
19
  t0 = $[1];
20
20
  }
21
- useImperativeHandle(forwardedRef, t0);
21
+ let t1;
22
+ if ($[2] !== refObject) {
23
+ t1 = [refObject];
24
+ $[2] = refObject;
25
+ $[3] = t1;
26
+ } else {
27
+ t1 = $[3];
28
+ }
29
+ useImperativeHandle(forwardedRef, t0, t1);
22
30
  }
23
31
 
24
32
  export { useRefObjectAsForwardedRef };
@@ -1 +1 @@
1
- {"version":3,"file":"useScrollFlash.d.ts","sourceRoot":"","sources":["../../src/hooks/useScrollFlash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,kBAAkB,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,QAe7F"}
1
+ {"version":3,"file":"useScrollFlash.d.ts","sourceRoot":"","sources":["../../src/hooks/useScrollFlash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,kBAAkB,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,QAoB7F"}
@@ -1,4 +1,3 @@
1
- import { c } from 'react-compiler-runtime';
2
1
  import { useEffect } from 'react';
3
2
 
4
3
  /**
@@ -6,30 +5,23 @@ import { useEffect } from 'react';
6
5
  * @param scrollContainerRef The ref of the scrollable content
7
6
  */
8
7
  function useScrollFlash(scrollContainerRef) {
9
- const $ = c(3);
10
- let t0;
11
- let t1;
12
- if ($[0] !== scrollContainerRef) {
13
- t0 = () => {
14
- const scrollContainer = scrollContainerRef.current;
15
- if (!scrollContainer) {
16
- return;
17
- }
8
+ // https://adxlv.computer/projects/flash-scrollers/
9
+ useEffect(() => {
10
+ const scrollContainer = scrollContainerRef.current;
11
+ if (!scrollContainer) {
12
+ return;
13
+ }
14
+
15
+ // Defer to the next frame to avoid forcing a synchronous reflow
16
+ // when the effect runs immediately after React commits DOM changes.
17
+ const id = requestAnimationFrame(() => {
18
18
  const currentScroll = scrollContainer.scrollTop;
19
- const maxScroll = scrollContainer.scrollHeight;
20
- const altScroll = currentScroll < Math.min(1, maxScroll) ? currentScroll + 1 : currentScroll - 1;
19
+ const altScroll = currentScroll < 1 ? currentScroll + 1 : currentScroll - 1;
21
20
  scrollContainer.scrollTop = altScroll;
22
21
  scrollContainer.scrollTop = currentScroll;
23
- };
24
- t1 = [scrollContainerRef];
25
- $[0] = scrollContainerRef;
26
- $[1] = t0;
27
- $[2] = t1;
28
- } else {
29
- t0 = $[1];
30
- t1 = $[2];
31
- }
32
- useEffect(t0, t1);
22
+ });
23
+ return () => cancelAnimationFrame(id);
24
+ }, [scrollContainerRef]);
33
25
  }
34
26
 
35
27
  export { useScrollFlash as default };
@@ -1,8 +1,56 @@
1
1
  import React from 'react';
2
+ /**
3
+ * useSlots - Extract slot components from children for SSR-compatible slot APIs.
4
+ *
5
+ * Given a list of children and a config mapping slot names to component types,
6
+ * separates children into two groups: matched slots and the rest.
7
+ *
8
+ * Config: { leadingVisual: LeadingVisual, description: Description }
9
+ *
10
+ * Children: Matching: Output:
11
+ * +----------------+ slots = {
12
+ * | LeadingVisual | -> matches slot 0 --> leadingVisual: <LeadingVisual />
13
+ * | "Project name" | -> no match --> description: <Description />
14
+ * | Description | -> matches slot 1 --> }
15
+ * | TrailingVisual | -> no match --> rest = ["Project name", <TrailingVisual />]
16
+ * +----------------+
17
+ *
18
+ * Performance-sensitive: called per item in lists (e.g. 100-item ActionList
19
+ * calls this 101 times per render).
20
+ *
21
+ * Once all slots are filled, remaining children skip matching entirely in
22
+ * production (single integer comparison). In dev, we still scan for duplicates
23
+ * to emit a warning.
24
+ *
25
+ * Flow per child:
26
+ *
27
+ * child ──> isValidElement? ──no──> rest[]
28
+ * |
29
+ * yes
30
+ * |
31
+ * v
32
+ * all slots filled? ──yes──> rest[] (prod)
33
+ * | |
34
+ * no [dev: check for
35
+ * | duplicate warning]
36
+ * v
37
+ * match against unfilled slots
38
+ * |
39
+ * found match? ──no──> rest[]
40
+ * |
41
+ * yes
42
+ * |
43
+ * v
44
+ * slots[key] = child, slotsFound++
45
+ *
46
+ * Slot config supports two matcher styles:
47
+ * 1. Component reference: { visual: LeadingVisual }
48
+ * 2. Component + test fn: { block: [Description, props => props.variant === 'block'] }
49
+ */
50
+ type Props = any;
2
51
  type ComponentMatcher = React.ElementType<Props>;
3
52
  type ComponentAndPropsMatcher = [ComponentMatcher, (props: Props) => boolean];
4
53
  export type SlotConfig = Record<string, ComponentMatcher | ComponentAndPropsMatcher>;
5
- type Props = any;
6
54
  type SlotElements<Config extends SlotConfig> = {
7
55
  [Property in keyof Config]: SlotValue<Config, Property>;
8
56
  };
@@ -10,11 +58,7 @@ type SlotValue<Config, Property extends keyof Config> = Config[Property] extends
10
58
  infer ElementType extends React.ElementType,
11
59
  infer _testFn
12
60
  ] ? React.ReactElement<React.ComponentPropsWithoutRef<ElementType>, ElementType> : never;
13
- /**
14
- * Extract components from `children` so we can render them in different places,
15
- * allowing us to implement components with SSR-compatible slot APIs.
16
- * Note: We can only extract direct children, not nested ones.
17
- */
61
+ /** Extract slot components from children. See file header for details. */
18
62
  export declare function useSlots<Config extends SlotConfig>(children: React.ReactNode, config: Config): [Partial<SlotElements<Config>>, React.ReactNode[]];
19
63
  export {};
20
64
  //# sourceMappingURL=useSl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AY,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAqDpD"}
@@ -2,29 +2,85 @@ import React from 'react';
2
2
  import { warning } from '../utils/warning.js';
3
3
  import { isSlot } from '../utils/is-slot.js';
4
4
 
5
- // slot config allows 2 options:
6
- // 1. Component to match, example: { leadingVisual: LeadingVisual }
5
+ /**
6
+ * useSlots - Extract slot components from children for SSR-compatible slot APIs.
7
+ *
8
+ * Given a list of children and a config mapping slot names to component types,
9
+ * separates children into two groups: matched slots and the rest.
10
+ *
11
+ * Config: { leadingVisual: LeadingVisual, description: Description }
12
+ *
13
+ * Children: Matching: Output:
14
+ * +----------------+ slots = {
15
+ * | LeadingVisual | -> matches slot 0 --> leadingVisual: <LeadingVisual />
16
+ * | "Project name" | -> no match --> description: <Description />
17
+ * | Description | -> matches slot 1 --> }
18
+ * | TrailingVisual | -> no match --> rest = ["Project name", <TrailingVisual />]
19
+ * +----------------+
20
+ *
21
+ * Performance-sensitive: called per item in lists (e.g. 100-item ActionList
22
+ * calls this 101 times per render).
23
+ *
24
+ * Once all slots are filled, remaining children skip matching entirely in
25
+ * production (single integer comparison). In dev, we still scan for duplicates
26
+ * to emit a warning.
27
+ *
28
+ * Flow per child:
29
+ *
30
+ * child ──> isValidElement? ──no──> rest[]
31
+ * |
32
+ * yes
33
+ * |
34
+ * v
35
+ * all slots filled? ──yes──> rest[] (prod)
36
+ * | |
37
+ * no [dev: check for
38
+ * | duplicate warning]
39
+ * v
40
+ * match against unfilled slots
41
+ * |
42
+ * found match? ──no──> rest[]
43
+ * |
44
+ * yes
45
+ * |
46
+ * v
47
+ * slots[key] = child, slotsFound++
48
+ *
49
+ * Slot config supports two matcher styles:
50
+ * 1. Component reference: { visual: LeadingVisual }
51
+ * 2. Component + test fn: { block: [Description, props => props.variant === 'block'] }
52
+ */
7
53
 
8
- // 2. Component to match + a test function, example: { blockDescription: [Description, props => props.variant === 'block'] }
54
+ // --- Types ---
9
55
 
10
- // We don't know what the props are yet, we set them later based on slot config
11
56
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
57
 
13
- // useful for narrowing types, third option is not possible
58
+ // --- Matching ---
14
59
 
15
- /**
16
- * Extract components from `children` so we can render them in different places,
17
- * allowing us to implement components with SSR-compatible slot APIs.
18
- * Note: We can only extract direct children, not nested ones.
19
- */
20
- function useSlots(children, config) {
21
- // Object mapping slot names to their elements
22
- const slots = mapValues(config, () => undefined);
60
+ /** Check if a child element matches a slot config entry, either by direct type comparison or slot symbol. */
61
+ function childMatchesSlot(child, slotValue) {
62
+ if (Array.isArray(slotValue)) {
63
+ const [component, testFn] = slotValue;
64
+ return (child.type === component || isSlot(child, component)) && testFn(child.props);
65
+ }
66
+ return child.type === slotValue || isSlot(child, slotValue);
67
+ }
23
68
 
24
- // Array of elements that are not slots
69
+ // --- Hook ---
70
+
71
+ /** Extract slot components from children. See file header for details. */
72
+ function useSlots(children, config) {
25
73
  const rest = [];
26
74
  const keys = Object.keys(config);
27
75
  const values = Object.values(config);
76
+ const totalSlots = keys.length;
77
+
78
+ // Initialize all slot keys to undefined so callers can check `slots.x === undefined`
79
+ const slots = {};
80
+ for (let i = 0; i < totalSlots; i++) {
81
+ slots[keys[i]] = undefined;
82
+ }
83
+ let slotsFound = 0;
28
84
 
29
85
  // eslint-disable-next-line github/array-foreach
30
86
  React.Children.forEach(children, child => {
@@ -32,41 +88,63 @@ function useSlots(children, config) {
32
88
  rest.push(child);
33
89
  return;
34
90
  }
35
- const index = values.findIndex(value => {
36
- if (Array.isArray(value)) {
37
- const [component, testFn] = value;
38
- return (child.type === component || isSlot(child, component)) && testFn(child.props);
39
- } else {
40
- return child.type === value || isSlot(child, value);
41
- }
42
- });
43
91
 
44
- // If the child is not a slot, add it to the `rest` array
45
- if (index === -1) {
92
+ // Short-circuit: all slots filled, no more matching needed
93
+ if (slotsFound === totalSlots) {
94
+ if (process.env.NODE_ENV !== "production" && warnIfDuplicate(child, keys, values, totalSlots)) {
95
+ return;
96
+ }
46
97
  rest.push(child);
47
98
  return;
48
99
  }
49
- const slotKey = keys[index];
50
100
 
51
- // If slot is already filled, ignore duplicates
52
- if (slots[slotKey]) {
53
- process.env.NODE_ENV !== "production" ? warning(true, `Found duplicate "${String(slotKey)}" slot. Only the first will be rendered.`) : void 0;
101
+ // Try to match child against a slot
102
+ const matchedIndex = findMatchingSlot(child, values, totalSlots);
103
+ if (matchedIndex === -1) {
104
+ rest.push(child);
54
105
  return;
55
106
  }
107
+ const slotKey = keys[matchedIndex];
56
108
 
57
- // If the child is a slot, add it to the `slots` object
58
-
109
+ // Duplicate: slot already filled by an earlier child
110
+ if (slots[slotKey] !== undefined) {
111
+ if (process.env.NODE_ENV !== "production") {
112
+ process.env.NODE_ENV !== "production" ? warning(true, `Found duplicate "${String(slotKey)}" slot. Only the first will be rendered.`) : void 0;
113
+ }
114
+ return;
115
+ }
59
116
  slots[slotKey] = child;
117
+ slotsFound++;
60
118
  });
61
119
  return [slots, rest];
62
120
  }
63
121
 
64
- /** Map the values of an object */
65
- function mapValues(obj, fn) {
66
- return Object.keys(obj).reduce((result, key) => {
67
- result[key] = fn(obj[key]);
68
- return result;
69
- }, {});
122
+ // --- Helpers ---
123
+
124
+ /**
125
+ * Find the first slot config entry matching this child.
126
+ * Returns the config index, or -1 if no match.
127
+ */
128
+ function findMatchingSlot(child, values, totalSlots) {
129
+ for (let i = 0; i < totalSlots; i++) {
130
+ if (childMatchesSlot(child, values[i])) return i;
131
+ }
132
+ return -1;
133
+ }
134
+
135
+ /**
136
+ * Dev-only: check if a child duplicates an already-filled slot.
137
+ * Returns true (and warns) if a duplicate is found, false otherwise.
138
+ * Used in the short-circuit path where all slots are already filled.
139
+ */
140
+ function warnIfDuplicate(child, keys, values, totalSlots) {
141
+ for (let i = 0; i < totalSlots; i++) {
142
+ if (childMatchesSlot(child, values[i])) {
143
+ process.env.NODE_ENV !== "production" ? warning(true, `Found duplicate "${String(keys[i])}" slot. Only the first will be rendered.`) : void 0;
144
+ return true;
145
+ }
146
+ }
147
+ return false;
70
148
  }
71
149
 
72
150
  export { useSlots };
@@ -1 +1 @@
1
- {"version":3,"file":"Announce.d.ts","sourceRoot":"","sources":["../../src/live-region/Announce.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAA;AAEjE,MAAM,MAAM,aAAa,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,IAAI,gBAAgB,CACxE,EAAE,EACF,KAAK,EACL;IACE;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IAExB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,UAAU,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;CACpC,CACF,CAAA;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,GAAG,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC,qBAgGtF"}
1
+ {"version":3,"file":"Announce.d.ts","sourceRoot":"","sources":["../../src/live-region/Announce.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAA;AAEjE,MAAM,MAAM,aAAa,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,IAAI,gBAAgB,CACxE,EAAE,EACF,KAAK,EACL;IACE;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IAExB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,UAAU,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;CACpC,CACF,CAAA;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,GAAG,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC,qBAwGtF"}
@@ -66,6 +66,13 @@ function Announce(props) {
66
66
  if (hidden) {
67
67
  return;
68
68
  }
69
+ const textContent = getTextContent(element);
70
+ if (!textContent) {
71
+ return;
72
+ }
73
+ if (textContent === previousAnnouncementText) {
74
+ return;
75
+ }
69
76
  const style = window.getComputedStyle(element);
70
77
  if (style.display === "none") {
71
78
  return;
@@ -73,10 +80,6 @@ function Announce(props) {
73
80
  if (style.visibility === "hidden") {
74
81
  return;
75
82
  }
76
- const textContent = getTextContent(element);
77
- if (textContent === previousAnnouncementText) {
78
- return;
79
- }
80
83
  (_savedAnnouncement$cu = savedAnnouncement.current) === null || _savedAnnouncement$cu === void 0 ? void 0 : _savedAnnouncement$cu.cancel();
81
84
  savedAnnouncement.current = announceFromElement(element, politeness === "assertive" ? {
82
85
  politeness
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Indicate whether current execution environment can access the DOM.
3
+ *
4
+ * @see https://github.com/facebook/fbjs/blob/4d1751311d3f67af2dcce2e40df8512a23c7b9c6/packages/fbjs/src/core/ExecutionEnvironment.js#L12
5
+ */
6
+ // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
7
+ const canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
8
+
9
+ export { canUseDOM };