@ankhorage/zora 28.5.2 → 28.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +5 -1
  3. package/dist/capabilities/index.js +73 -3
  4. package/dist/capabilities/index.js.map +3 -3
  5. package/dist/features/carousel/Carousel.d.ts.map +1 -1
  6. package/dist/features/carousel/Carousel.js +85 -8
  7. package/dist/features/carousel/Carousel.js.map +1 -1
  8. package/dist/features/form/select/adapters/inbound/Select.native.d.ts.map +1 -1
  9. package/dist/features/form/select/adapters/inbound/Select.native.js +71 -8
  10. package/dist/features/form/select/adapters/inbound/Select.native.js.map +1 -1
  11. package/dist/features/form/select/adapters/inbound/Select.web.d.ts.map +1 -1
  12. package/dist/features/form/select/adapters/inbound/Select.web.js +5 -3
  13. package/dist/features/form/select/adapters/inbound/Select.web.js.map +1 -1
  14. package/dist/features/form/select/composition/SelectSearchInput.d.ts +10 -0
  15. package/dist/features/form/select/composition/SelectSearchInput.d.ts.map +1 -0
  16. package/dist/features/form/select/composition/SelectSearchInput.js +11 -0
  17. package/dist/features/form/select/composition/SelectSearchInput.js.map +1 -0
  18. package/dist/features/form/select/composition/getVisibleSelectOptions.d.ts +4 -0
  19. package/dist/features/form/select/composition/getVisibleSelectOptions.d.ts.map +1 -0
  20. package/dist/features/form/select/composition/getVisibleSelectOptions.js +8 -0
  21. package/dist/features/form/select/composition/getVisibleSelectOptions.js.map +1 -0
  22. package/dist/features/form/select/composition/useSelectController.d.ts +3 -0
  23. package/dist/features/form/select/composition/useSelectController.d.ts.map +1 -1
  24. package/dist/features/form/select/composition/useSelectController.js +11 -2
  25. package/dist/features/form/select/composition/useSelectController.js.map +1 -1
  26. package/dist/features/form/select/selectMeta.d.ts +99 -1
  27. package/dist/features/form/select/selectMeta.d.ts.map +1 -1
  28. package/dist/features/form/select/selectMeta.js +71 -1
  29. package/dist/features/form/select/selectMeta.js.map +1 -1
  30. package/dist/features/registry/bindableComponentMeta.d.ts +79 -1
  31. package/dist/features/registry/bindableComponentMeta.d.ts.map +1 -1
  32. package/dist/features/registry/bindableComponentMeta.js +59 -1
  33. package/dist/features/registry/bindableComponentMeta.js.map +1 -1
  34. package/dist/types/select.d.ts +10 -0
  35. package/dist/types/select.d.ts.map +1 -1
  36. package/dist/types/select.js.map +1 -1
  37. package/package.json +29 -3
  38. package/src/features/carousel/Carousel.test.ts +243 -7
  39. package/src/features/carousel/Carousel.tsx +135 -26
  40. package/src/features/form/select/adapters/inbound/Select.native.test.tsx +322 -0
  41. package/src/features/form/select/adapters/inbound/Select.native.tsx +135 -13
  42. package/src/features/form/select/adapters/inbound/Select.web.tsx +6 -3
  43. package/src/features/form/select/composition/SelectSearchInput.tsx +33 -0
  44. package/src/features/form/select/composition/getVisibleSelectOptions.test.ts +22 -0
  45. package/src/features/form/select/composition/getVisibleSelectOptions.ts +13 -0
  46. package/src/features/form/select/composition/useSelectController.ts +25 -2
  47. package/src/features/form/select/public.test.ts +31 -1
  48. package/src/features/form/select/selectMeta.ts +71 -1
  49. package/src/features/registry/bindableComponentMeta.test.ts +6 -0
  50. package/src/features/registry/bindableComponentMeta.ts +59 -1
  51. package/src/features/registry/featureManifest.test.ts +10 -0
  52. package/src/types/select.ts +10 -0
  53. package/web-dist/chunks/{Accordion-sj1n06dw.js → Accordion-9dk62zn9.js} +84 -24
  54. package/web-dist/chunks/Accordion-ar8qe05j.js +53 -0
  55. package/web-dist/chunks/{Accordion-ge7cjtwy.js → Accordion-mpb070cf.js} +3 -3
  56. package/web-dist/chunks/{Accordion-554f42yj.js → Accordion-sj30964p.js} +4 -4
  57. package/web-dist/chunks/{Accordion-2bygfpwg.js → Accordion-xhxv2v0g.js} +62 -2
  58. package/web-dist/chunks/{RichTextClient-70qt7037.js → RichTextClient-7qqj2dpw.js} +3 -4
  59. package/web-dist/components/auth-screen/AuthScreen.js +2 -3
  60. package/web-dist/components/carousel/Carousel.js +97 -24
  61. package/web-dist/components/color-hue-scale/ColorHueScale.js +4 -3
  62. package/web-dist/components/color-picker/ColorPicker.js +4 -3
  63. package/web-dist/components/color-tone/ColorTone.js +4 -3
  64. package/web-dist/components/color-wheel/ColorWheel.js +4 -3
  65. package/web-dist/components/forgot-password-form/ForgotPasswordForm.js +2 -3
  66. package/web-dist/components/o-auth-provider-button/OAuthProviderButton.js +2 -3
  67. package/web-dist/components/o-auth-provider-list/OAuthProviderList.js +2 -3
  68. package/web-dist/components/otp-form/OtpForm.js +2 -3
  69. package/web-dist/components/rich-text/RichText.js +2 -2
  70. package/web-dist/components/search-input/SearchInput.js +5 -52
  71. package/web-dist/components/select/Select.js +3 -1
  72. package/web-dist/components/select/Select.types-0.d.ts +10 -0
  73. package/web-dist/components/sign-in-form/SignInForm.js +2 -3
  74. package/web-dist/components/sign-up-form/SignUpForm.js +2 -3
  75. package/web-dist/components/text-input/TextInput.js +4 -5
  76. package/web-dist/manifest.json +39 -41
  77. package/web-dist/chunks/Accordion-49d0frg7.js +0 -66
@@ -29,6 +29,9 @@ import {
29
29
  import {
30
30
  Text3
31
31
  } from "./Accordion-8skz71ct.js";
32
+ import {
33
+ SearchInput2
34
+ } from "./Accordion-ar8qe05j.js";
32
35
  import {
33
36
  useZoraTheme2
34
37
  } from "./Accordion-b1y5mjac.js";
@@ -118,8 +121,32 @@ function SelectOptionRow({
118
121
  });
119
122
  }
120
123
 
124
+ // src/features/form/select/composition/SelectSearchInput.tsx
125
+ import { jsx as jsx3 } from "react/jsx-runtime";
126
+ function SelectSearchInput({
127
+ onSearchChange,
128
+ props,
129
+ searchValue
130
+ }) {
131
+ if (!props.searchable)
132
+ return null;
133
+ return /* @__PURE__ */ jsx3(View2, {
134
+ pb: "xs",
135
+ children: /* @__PURE__ */ jsx3(SearchInput2, {
136
+ disabled: props.disabled,
137
+ interactionPolicy: props.interactionPolicy,
138
+ onValueChange: onSearchChange,
139
+ placeholder: props.searchPlaceholder ?? "Search options",
140
+ readOnly: props.readOnly,
141
+ size: "m",
142
+ testID: props.testID ? `${props.testID}-search` : undefined,
143
+ value: searchValue
144
+ })
145
+ });
146
+ }
147
+
121
148
  // src/features/form/select/composition/SelectTrigger.tsx
122
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
149
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
123
150
  var SELECT_CHEVRON_ICON = { name: "chevron-down" };
124
151
  function SelectTrigger({
125
152
  displayLabel,
@@ -130,7 +157,7 @@ function SelectTrigger({
130
157
  const { theme } = useZoraTheme2();
131
158
  const media = leadingMedia ?? props.leadingMedia;
132
159
  if (media) {
133
- return /* @__PURE__ */ jsx3(Pressable, {
160
+ return /* @__PURE__ */ jsx4(Pressable, {
134
161
  accessibilityLabel: displayLabel ?? props.placeholder ?? "Select",
135
162
  disabled: props.disabled,
136
163
  interactionPolicy: props.interactionPolicy,
@@ -148,16 +175,16 @@ function SelectTrigger({
148
175
  px: "m",
149
176
  radius: "m",
150
177
  children: [
151
- /* @__PURE__ */ jsx3(Image2, {
178
+ /* @__PURE__ */ jsx4(Image2, {
152
179
  alt: "",
153
180
  height: 28,
154
181
  radius: "s",
155
182
  source: media,
156
183
  width: 28
157
184
  }),
158
- /* @__PURE__ */ jsx3(View2, {
185
+ /* @__PURE__ */ jsx4(View2, {
159
186
  flex: 1,
160
- children: /* @__PURE__ */ jsx3(Text3, {
187
+ children: /* @__PURE__ */ jsx4(Text3, {
161
188
  emphasis: displayLabel ? "default" : "muted",
162
189
  numberOfLines: 1,
163
190
  variant: "label",
@@ -165,7 +192,7 @@ function SelectTrigger({
165
192
  children: displayLabel ?? props.placeholder ?? "Select"
166
193
  })
167
194
  }),
168
- /* @__PURE__ */ jsx3(Icon2, {
195
+ /* @__PURE__ */ jsx4(Icon2, {
169
196
  name: "chevron-down",
170
197
  size: 18
171
198
  })
@@ -173,7 +200,7 @@ function SelectTrigger({
173
200
  })
174
201
  });
175
202
  }
176
- return /* @__PURE__ */ jsx3(Button3, {
203
+ return /* @__PURE__ */ jsx4(Button3, {
177
204
  color: props.invalid ? "danger" : "neutral",
178
205
  disabled: props.disabled,
179
206
  fullWidth: true,
@@ -191,21 +218,47 @@ function SelectTrigger({
191
218
 
192
219
  // src/features/form/select/composition/useSelectController.ts
193
220
  import React from "react";
221
+
222
+ // src/features/form/select/composition/getVisibleSelectOptions.ts
223
+ function getVisibleSelectOptions(options, searchable, searchValue) {
224
+ const query = searchValue.trim().toLocaleLowerCase();
225
+ if (!searchable || query.length === 0)
226
+ return options;
227
+ return options.filter((option) => option.label.toLocaleLowerCase().includes(query));
228
+ }
229
+
230
+ // src/features/form/select/composition/useSelectController.ts
194
231
  function useSelectController(props) {
195
- const { defaultValue, onValueChange, options, value: controlledValue } = props;
232
+ const {
233
+ defaultSearchValue,
234
+ defaultValue,
235
+ onSearchChange,
236
+ onValueChange,
237
+ options,
238
+ searchValue: controlledSearchValue,
239
+ value: controlledValue
240
+ } = props;
196
241
  const [localValue, setLocalValue] = React.useState(defaultValue);
242
+ const [localSearchValue, setLocalSearchValue] = React.useState(defaultSearchValue ?? "");
197
243
  const value = controlledValue ?? localValue;
244
+ const searchValue = controlledSearchValue ?? localSearchValue;
198
245
  const selectedOption = options.find((option) => option.value === value);
246
+ const visibleOptions = React.useMemo(() => getVisibleSelectOptions(options, props.searchable, searchValue), [options, props.searchable, searchValue]);
199
247
  const select = React.useCallback((nextValue) => {
200
248
  if (controlledValue === undefined)
201
249
  setLocalValue(nextValue);
202
250
  onValueChange?.(nextValue);
203
251
  }, [controlledValue, onValueChange]);
204
- return { select, selectedOption, value };
252
+ const search = React.useCallback((nextValue) => {
253
+ if (controlledSearchValue === undefined)
254
+ setLocalSearchValue(nextValue);
255
+ onSearchChange?.(nextValue);
256
+ }, [controlledSearchValue, onSearchChange]);
257
+ return { search, searchValue, select, selectedOption, value, visibleOptions };
205
258
  }
206
259
 
207
260
  // src/features/form/select/adapters/inbound/Select.web.tsx
208
- import { jsx as jsx4 } from "react/jsx-runtime";
261
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
209
262
  var Select2 = withZoraThemeScope(SelectInner);
210
263
  function SelectInner({
211
264
  themeId: _themeId,
@@ -213,16 +266,16 @@ function SelectInner({
213
266
  ...props
214
267
  }) {
215
268
  const [open, setOpen] = React2.useState(false);
216
- const { select, selectedOption, value } = useSelectController(props);
217
- const { interactionPolicy, options, testID } = props;
269
+ const { search, searchValue, select, selectedOption, value, visibleOptions } = useSelectController(props);
270
+ const { interactionPolicy, testID } = props;
218
271
  const selectAndClose = React2.useCallback((nextValue) => {
219
272
  select(nextValue);
220
273
  setOpen(false);
221
274
  }, [select]);
222
- return /* @__PURE__ */ jsx4(SelectField, {
275
+ return /* @__PURE__ */ jsx5(SelectField, {
223
276
  props,
224
- children: /* @__PURE__ */ jsx4(Popover2, {
225
- anchor: ({ toggle }) => /* @__PURE__ */ jsx4(SelectTrigger, {
277
+ children: /* @__PURE__ */ jsx5(Popover2, {
278
+ anchor: ({ toggle }) => /* @__PURE__ */ jsx5(SelectTrigger, {
226
279
  displayLabel: selectedOption?.label,
227
280
  leadingMedia: selectedOption?.leadingMedia,
228
281
  onPress: toggle,
@@ -233,18 +286,25 @@ function SelectInner({
233
286
  open,
234
287
  placement: "bottom-start",
235
288
  testID: testID ? `${testID}-popover` : undefined,
236
- children: /* @__PURE__ */ jsx4(Surface2, {
289
+ children: /* @__PURE__ */ jsx5(Surface2, {
237
290
  variant: "raised",
238
- children: /* @__PURE__ */ jsx4(View2, {
291
+ children: /* @__PURE__ */ jsxs3(View2, {
239
292
  gap: "xs",
240
293
  p: "xs",
241
- children: options.map((option) => /* @__PURE__ */ jsx4(SelectOptionRow, {
242
- interactionPolicy,
243
- onSelect: selectAndClose,
244
- option,
245
- selected: value === option.value,
246
- testID
247
- }, option.value))
294
+ children: [
295
+ /* @__PURE__ */ jsx5(SelectSearchInput, {
296
+ onSearchChange: search,
297
+ props,
298
+ searchValue
299
+ }),
300
+ visibleOptions.map((option) => /* @__PURE__ */ jsx5(SelectOptionRow, {
301
+ interactionPolicy,
302
+ onSelect: selectAndClose,
303
+ option,
304
+ selected: value === option.value,
305
+ testID
306
+ }, option.value))
307
+ ]
248
308
  })
249
309
  })
250
310
  })
@@ -0,0 +1,53 @@
1
+ 'use client';
2
+ import {
3
+ withZoraThemeScope
4
+ } from "./Accordion-tk8zf9ff.js";
5
+ import {
6
+ TextInput3
7
+ } from "./Accordion-xhxv2v0g.js";
8
+
9
+ // src/features/form/search-input/adapters/inbound/SearchInput.tsx
10
+ import { jsx } from "react/jsx-runtime";
11
+ var SearchInput2 = withZoraThemeScope(SearchInputInner);
12
+ function SearchInputInner({
13
+ themeId: _themeId,
14
+ mode: _mode,
15
+ testID,
16
+ value = "",
17
+ onValueChange,
18
+ placeholder = "Search",
19
+ onSubmit,
20
+ onClear,
21
+ clearable = true,
22
+ size = "l",
23
+ disabled,
24
+ readOnly,
25
+ interactionPolicy
26
+ }) {
27
+ const passive = interactionPolicy === "passive";
28
+ const trailingAction = clearable && value.length > 0 ? {
29
+ icon: { name: "close-circle" },
30
+ label: "Clear search",
31
+ onPress: () => {
32
+ if (passive)
33
+ return;
34
+ onValueChange?.("");
35
+ onClear?.();
36
+ }
37
+ } : undefined;
38
+ return /* @__PURE__ */ jsx(TextInput3, {
39
+ disabled,
40
+ interactionPolicy,
41
+ leadingIcon: { name: "search-outline" },
42
+ onChangeText: onValueChange,
43
+ onSubmitEditing: onSubmit ? passive ? undefined : () => onSubmit(value) : undefined,
44
+ placeholder,
45
+ readOnly,
46
+ returnKeyType: "search",
47
+ size,
48
+ testID,
49
+ trailingAction,
50
+ value
51
+ });
52
+ }
53
+ export { SearchInput2 };
@@ -29,8 +29,8 @@ import {
29
29
  Field2
30
30
  } from "./Accordion-gs838h0n.js";
31
31
  import {
32
- TextInput2
33
- } from "./Accordion-49d0frg7.js";
32
+ TextInput3
33
+ } from "./Accordion-xhxv2v0g.js";
34
34
  import {
35
35
  require_cjs
36
36
  } from "./Accordion-xgpzh4wq.js";
@@ -267,7 +267,7 @@ function AuthFormField({
267
267
  readOnly: field.readOnly,
268
268
  required: field.required ?? hasRequiredRule(field.rules),
269
269
  testID: field.testID,
270
- children: /* @__PURE__ */ jsx3(TextInput2, {
270
+ children: /* @__PURE__ */ jsx3(TextInput3, {
271
271
  accessibilityLabel: typeof field.label === "string" ? field.label : undefined,
272
272
  autoCapitalize: field.autoCapitalize ?? (["email", "password", "url"].includes(field.type ?? "text") ? "none" : undefined),
273
273
  autoComplete: field.autoComplete,
@@ -27,8 +27,8 @@ import {
27
27
  writeClipboardTextAsync
28
28
  } from "./Accordion-chdbfcm6.js";
29
29
  import {
30
- TextInput3
31
- } from "./Accordion-2bygfpwg.js";
30
+ TextInput2
31
+ } from "./Accordion-xhxv2v0g.js";
32
32
  import {
33
33
  Button2,
34
34
  Circle,
@@ -51,7 +51,7 @@ import {
51
51
  } from "./Accordion-3zzzw7a8.js";
52
52
  import {
53
53
  Select2
54
- } from "./Accordion-sj1n06dw.js";
54
+ } from "./Accordion-9dk62zn9.js";
55
55
  import {
56
56
  Gradient2
57
57
  } from "./Accordion-zd15byha.js";
@@ -84,7 +84,7 @@ function ColorHexField({
84
84
  }
85
85
  return /* @__PURE__ */ jsxs(View2, {
86
86
  children: [
87
- /* @__PURE__ */ jsx(TextInput3, {
87
+ /* @__PURE__ */ jsx(TextInput2, {
88
88
  accessibilityLabel: "Color hex value",
89
89
  disabled,
90
90
  leadingAccessory: /* @__PURE__ */ jsx(View2, {
@@ -1,7 +1,19 @@
1
1
  'use client';
2
+ import {
3
+ Icon3
4
+ } from "./Accordion-0dj1r7w3.js";
2
5
  import {
3
6
  useTheme
4
7
  } from "./Accordion-9d38cgqj.js";
8
+ import {
9
+ IconButton2
10
+ } from "./Accordion-9tgvr155.js";
11
+ import {
12
+ withZoraThemeScope
13
+ } from "./Accordion-tk8zf9ff.js";
14
+ import {
15
+ resolveIconSize
16
+ } from "./Accordion-961ncx4e.js";
5
17
  import {
6
18
  resolveControlSize,
7
19
  resolveFieldState,
@@ -9,6 +21,9 @@ import {
9
21
  resolveInputColors,
10
22
  resolveTextStyles
11
23
  } from "./Accordion-akwd4brm.js";
24
+ import {
25
+ useZoraTheme2
26
+ } from "./Accordion-b1y5mjac.js";
12
27
  import {
13
28
  require_cjs
14
29
  } from "./Accordion-xgpzh4wq.js";
@@ -72,7 +87,7 @@ function resolveTextInputHeights(controlSize, multiline, numberOfLines, lineHeig
72
87
 
73
88
  // node_modules/@ankhorage/surface/src/features/form/text-input/adapters/inbound/TextInput.tsx
74
89
  import { jsx, jsxs } from "react/jsx-runtime";
75
- function TextInput3(props) {
90
+ function TextInput2(props) {
76
91
  const { theme } = useTheme();
77
92
  const [focused, setFocused] = React.useState(false);
78
93
  const {
@@ -133,4 +148,49 @@ function resolveAccessoryStyle(spacing, position) {
133
148
  return position === "leading" ? { marginRight: spacing } : { marginLeft: spacing };
134
149
  }
135
150
 
136
- export { TextInput3 };
151
+ // src/features/form/text-input/adapters/inbound/TextInput.tsx
152
+ import { jsx as jsx2 } from "react/jsx-runtime";
153
+ function TextInputInner({
154
+ themeId: _themeId,
155
+ mode: _mode,
156
+ size = "l",
157
+ leadingIcon,
158
+ trailingIcon,
159
+ trailingAction,
160
+ disabled,
161
+ readOnly,
162
+ interactionPolicy,
163
+ ...props
164
+ }) {
165
+ const { theme } = useZoraTheme2();
166
+ const iconSize = resolveIconSize(size);
167
+ const iconColor = theme.semantics.content.muted;
168
+ return /* @__PURE__ */ jsx2(TextInput2, {
169
+ ...props,
170
+ disabled,
171
+ interactionPolicy,
172
+ leadingAccessory: leadingIcon ? /* @__PURE__ */ jsx2(Icon3, {
173
+ ...leadingIcon,
174
+ color: iconColor,
175
+ size: iconSize
176
+ }) : undefined,
177
+ readOnly,
178
+ size,
179
+ trailingAccessory: trailingAction ? /* @__PURE__ */ jsx2(IconButton2, {
180
+ icon: trailingAction.icon,
181
+ interactionPolicy,
182
+ label: trailingAction.label,
183
+ disabled: disabled ?? readOnly,
184
+ variant: "ghost",
185
+ size: size === "l" ? "m" : size,
186
+ color: "neutral",
187
+ onPress: trailingAction.onPress
188
+ }) : trailingIcon ? /* @__PURE__ */ jsx2(Icon3, {
189
+ ...trailingIcon,
190
+ color: iconColor,
191
+ size: iconSize
192
+ }) : undefined
193
+ });
194
+ }
195
+ var TextInput3 = withZoraThemeScope(TextInputInner);
196
+ export { TextInput2, TextInput3 };
@@ -13,10 +13,9 @@ import"./Accordion-tk8zf9ff.js";
13
13
  import {
14
14
  View2
15
15
  } from "./Accordion-4mg3epm9.js";
16
- import"./Accordion-2bygfpwg.js";
17
16
  import {
18
- TextInput2
19
- } from "./Accordion-49d0frg7.js";
17
+ TextInput3
18
+ } from "./Accordion-xhxv2v0g.js";
20
19
  import"./Accordion-pdjhezmz.js";
21
20
  import"./Accordion-78astqx3.js";
22
21
  import"./Accordion-8skz71ct.js";
@@ -1521,7 +1520,7 @@ function RichTextClient({
1521
1520
  direction: "row",
1522
1521
  gap: "s",
1523
1522
  children: [
1524
- /* @__PURE__ */ jsx(TextInput2, {
1523
+ /* @__PURE__ */ jsx(TextInput3, {
1525
1524
  disabled: !canEdit,
1526
1525
  onChangeText: setLinkUrl,
1527
1526
  placeholder: "https://example.com",
@@ -15,12 +15,11 @@ import"../../chunks/Accordion-9b4bsxwe.js";
15
15
  import"../../chunks/Accordion-9tgvr155.js";
16
16
  import {
17
17
  AuthScreen2
18
- } from "../../chunks/Accordion-ge7cjtwy.js";
18
+ } from "../../chunks/Accordion-mpb070cf.js";
19
19
  import"../../chunks/Accordion-ytf9ba8v.js";
20
20
  import"../../chunks/Accordion-khfjh10v.js";
21
21
  import"../../chunks/Accordion-gs838h0n.js";
22
- import"../../chunks/Accordion-2bygfpwg.js";
23
- import"../../chunks/Accordion-49d0frg7.js";
22
+ import"../../chunks/Accordion-xhxv2v0g.js";
24
23
  import"../../chunks/Accordion-61e19g3e.js";
25
24
  import"../../chunks/Accordion-c6edgxay.js";
26
25
  import"../../chunks/Accordion-yrac5a7m.js";
@@ -136,6 +136,10 @@ function Carousel({
136
136
  }) {
137
137
  const { theme } = useZoraTheme2();
138
138
  const [width, setWidth] = React2.useState(0);
139
+ const initialIndex = normalizeSlideIndex(index ?? defaultIndex ?? 0, slides.length);
140
+ const initialSlide = slides.at(initialIndex);
141
+ const [mountedSlideKeys, setMountedSlideKeys] = React2.useState(() => initialSlide ? new Set([initialSlide.key]) : new Set);
142
+ const [readySlideKeys, setReadySlideKeys] = React2.useState(() => new Set);
139
143
  const {
140
144
  activeIndex,
141
145
  controlledWithoutHandler,
@@ -155,6 +159,24 @@ function Carousel({
155
159
  intervalMs,
156
160
  reducedMotion
157
161
  });
162
+ const activeSlide = slides.at(activeIndex);
163
+ const nextIndex = getNextSlideIndex(activeIndex, slides.length, enabledLoop);
164
+ const nextSlide = nextIndex === undefined ? undefined : slides.at(nextIndex);
165
+ const activeSlideKey = activeSlide?.key;
166
+ const nextSlideKey = nextSlide?.key;
167
+ const mountedKeys = ensureMountedSlide(ensureMountedSlide(mountedSlideKeys, activeSlideKey), getPreloadedSlideKey(activeSlideKey, nextSlideKey, readySlideKeys));
168
+ const markSlideLoaded = React2.useCallback((slideKey) => {
169
+ setReadySlideKeys((current) => ensureMountedSlide(current, slideKey));
170
+ if (slideKey === activeSlideKey) {
171
+ setMountedSlideKeys((current) => ensureMountedSlide(current, nextSlideKey));
172
+ }
173
+ }, [activeSlideKey, nextSlideKey]);
174
+ const completeTransition = React2.useCallback((completedSlideKey) => {
175
+ if (!activeSlideKey || completedSlideKey !== activeSlideKey)
176
+ return;
177
+ const transitionRetentionKeys = [activeSlideKey, nextSlideKey].filter((slideKey) => slideKey !== undefined);
178
+ setMountedSlideKeys((current) => new Set(transitionRetentionKeys.filter((slideKey) => slideKey === activeSlideKey || current.has(slideKey) || readySlideKeys.has(activeSlideKey))));
179
+ }, [activeSlideKey, nextSlideKey, readySlideKeys]);
158
180
  if (slides.length === 0)
159
181
  return null;
160
182
  const canPrevious = enabledLoop || activeIndex > 0;
@@ -166,23 +188,27 @@ function Carousel({
166
188
  testID,
167
189
  style: [{ position: "relative", overflow: "hidden", width: "100%", height: "100%" }, style],
168
190
  children: [
169
- slides.map((slide, slideIndex) => /* @__PURE__ */ jsx(CarouselLayer, {
170
- active: activeIndex === slideIndex,
171
- animate: slides.length > 1,
172
- animateOnMount,
173
- direction,
174
- enterDurationMs,
175
- exitDurationMs,
176
- imageStyle,
177
- initialScale,
178
- reducedMotion: shouldReduceMotion,
179
- renderImage,
180
- resizeMode,
181
- slide,
182
- slideIndex,
183
- transition,
184
- width
185
- }, slide.key)),
191
+ slides.flatMap((slide, slideIndex) => mountedKeys.has(slide.key) ? [
192
+ /* @__PURE__ */ jsx(CarouselLayer, {
193
+ active: activeIndex === slideIndex,
194
+ animate: slides.length > 1,
195
+ animateOnMount: animateOnMount || activeIndex !== initialIndex,
196
+ direction,
197
+ enterDurationMs,
198
+ exitDurationMs,
199
+ imageStyle,
200
+ initialScale,
201
+ onImageLoad: () => markSlideLoaded(slide.key),
202
+ onTransitionComplete: completeTransition,
203
+ reducedMotion: shouldReduceMotion,
204
+ renderImage,
205
+ resizeMode,
206
+ slide,
207
+ slideIndex,
208
+ transition,
209
+ width
210
+ }, slide.key)
211
+ ] : []),
186
212
  /* @__PURE__ */ jsx(CarouselControls, {
187
213
  activeIndex,
188
214
  canNext,
@@ -231,6 +257,8 @@ function CarouselLayer({
231
257
  enterDurationMs = 1200,
232
258
  exitDurationMs = 800,
233
259
  initialScale = 1.06,
260
+ onImageLoad,
261
+ onTransitionComplete,
234
262
  reducedMotion,
235
263
  renderImage,
236
264
  resizeMode,
@@ -242,6 +270,10 @@ function CarouselLayer({
242
270
  const [scale] = React2.useState(() => new import_react_native2.Animated.Value(active && animateOnMount ? initialScale : 1));
243
271
  const [offset] = React2.useState(() => new import_react_native2.Animated.Value(0));
244
272
  const hasMounted = React2.useRef(false);
273
+ const widthRef = React2.useRef(width);
274
+ React2.useEffect(() => {
275
+ widthRef.current = width;
276
+ }, [width]);
245
277
  React2.useEffect(() => {
246
278
  const firstRender = !hasMounted.current;
247
279
  hasMounted.current = true;
@@ -254,17 +286,19 @@ function CarouselLayer({
254
286
  opacity.setValue(active ? 1 : 0);
255
287
  scale.setValue(1);
256
288
  offset.setValue(0);
289
+ if (active)
290
+ onTransitionComplete(slide.key);
257
291
  return;
258
292
  }
259
293
  if (transition === "slide") {
260
294
  scale.setValue(1);
261
295
  if (active) {
262
- offset.setValue(direction * width);
296
+ offset.setValue(direction * widthRef.current);
263
297
  opacity.setValue(1);
264
298
  }
265
299
  import_react_native2.Animated.parallel([
266
300
  import_react_native2.Animated.timing(offset, {
267
- toValue: active ? 0 : -direction * width,
301
+ toValue: active ? 0 : -direction * widthRef.current,
268
302
  duration: Math.max(0, active ? enterDurationMs : exitDurationMs),
269
303
  easing: import_react_native2.Easing.bezier(0.4, 0, 0.2, 1),
270
304
  useNativeDriver: true
@@ -275,7 +309,10 @@ function CarouselLayer({
275
309
  easing: import_react_native2.Easing.linear,
276
310
  useNativeDriver: true
277
311
  })
278
- ]).start();
312
+ ]).start(({ finished }) => {
313
+ if (active && finished)
314
+ onTransitionComplete(slide.key);
315
+ });
279
316
  } else if (active) {
280
317
  opacity.setValue(0);
281
318
  scale.setValue(initialScale);
@@ -292,7 +329,10 @@ function CarouselLayer({
292
329
  easing: import_react_native2.Easing.bezier(0.4, 0, 0.2, 1),
293
330
  useNativeDriver: true
294
331
  })
295
- ]).start();
332
+ ]).start(({ finished }) => {
333
+ if (finished)
334
+ onTransitionComplete(slide.key);
335
+ });
296
336
  } else {
297
337
  import_react_native2.Animated.timing(opacity, {
298
338
  toValue: 0,
@@ -319,7 +359,8 @@ function CarouselLayer({
319
359
  reducedMotion,
320
360
  scale,
321
361
  transition,
322
- width
362
+ onTransitionComplete,
363
+ slide.key
323
364
  ]);
324
365
  return /* @__PURE__ */ jsxs(import_react_native2.Animated.View, {
325
366
  accessibilityElementsHidden: !active,
@@ -327,17 +368,49 @@ function CarouselLayer({
327
368
  pointerEvents: active ? "auto" : "none",
328
369
  style: [import_react_native2.StyleSheet.absoluteFill, { opacity, transform: [{ scale }, { translateX: offset }] }],
329
370
  children: [
330
- slide.source !== undefined ? renderImage ? renderImage(slide, slideIndex) : /* @__PURE__ */ jsx(import_react_native2.Image, {
371
+ slide.source !== undefined ? renderImage ? renderCarouselImage(renderImage(slide, slideIndex), onImageLoad) : /* @__PURE__ */ jsx(import_react_native2.Image, {
331
372
  accessibilityLabel: slide.alt,
332
373
  accessible: Boolean(slide.alt),
333
374
  resizeMode,
334
375
  source: typeof slide.source === "string" ? { uri: slide.source } : slide.source,
335
- style: [import_react_native2.StyleSheet.absoluteFill, imageStyle]
376
+ style: [import_react_native2.StyleSheet.absoluteFill, imageStyle],
377
+ onLoad: onImageLoad
336
378
  }) : null,
337
379
  slide.content
338
380
  ]
339
381
  });
340
382
  }
383
+ function renderCarouselImage(image, onImageLoad) {
384
+ if (!React2.isValidElement(image))
385
+ return image;
386
+ const existingOnLoad = image.props.onLoad;
387
+ return React2.cloneElement(image, {
388
+ onLoad: (event) => {
389
+ existingOnLoad?.(event);
390
+ onImageLoad();
391
+ }
392
+ });
393
+ }
394
+ function ensureMountedSlide(mountedSlideKeys, slideKey) {
395
+ if (!slideKey || mountedSlideKeys.has(slideKey))
396
+ return mountedSlideKeys;
397
+ return new Set([...mountedSlideKeys, slideKey]);
398
+ }
399
+ function getPreloadedSlideKey(activeSlideKey, nextSlideKey, readySlideKeys) {
400
+ if (!activeSlideKey || !readySlideKeys.has(activeSlideKey))
401
+ return;
402
+ return nextSlideKey;
403
+ }
404
+ function getNextSlideIndex(index, length, loop) {
405
+ if (length < 2 || !loop && index === length - 1)
406
+ return;
407
+ return (index + 1) % length;
408
+ }
409
+ function normalizeSlideIndex(index, length) {
410
+ if (length === 0)
411
+ return 0;
412
+ return Math.min(Math.max(Math.trunc(index), 0), length - 1);
413
+ }
341
414
  function CarouselControls({
342
415
  activeIndex,
343
416
  canNext,
@@ -8,13 +8,13 @@ import"../../chunks/Accordion-ww4f12ty.js";
8
8
  import"../../chunks/Accordion-4mg3epm9.js";
9
9
  import"../../chunks/Accordion-8skz71ct.js";
10
10
  import"../../chunks/Accordion-chdbfcm6.js";
11
- import"../../chunks/Accordion-2bygfpwg.js";
11
+ import"../../chunks/Accordion-xhxv2v0g.js";
12
12
  import"../../chunks/Accordion-0dj1r7w3.js";
13
13
  import"../../chunks/Accordion-9b4bsxwe.js";
14
14
  import"../../chunks/Accordion-9tgvr155.js";
15
15
  import {
16
16
  ColorHueScale2
17
- } from "../../chunks/Accordion-554f42yj.js";
17
+ } from "../../chunks/Accordion-sj30964p.js";
18
18
  import"../../chunks/Accordion-pdjhezmz.js";
19
19
  import"../../chunks/Accordion-78astqx3.js";
20
20
  import"../../chunks/Accordion-224snqz3.js";
@@ -26,7 +26,8 @@ import"../../chunks/Accordion-7nn4r909.js";
26
26
  import"../../chunks/Accordion-2yat0x6x.js";
27
27
  import"../../chunks/Accordion-5mga7hty.js";
28
28
  import"../../chunks/Accordion-khfjh10v.js";
29
- import"../../chunks/Accordion-sj1n06dw.js";
29
+ import"../../chunks/Accordion-9dk62zn9.js";
30
+ import"../../chunks/Accordion-ar8qe05j.js";
30
31
  import"../../chunks/Accordion-zd15byha.js";
31
32
  import"../../chunks/Accordion-eqvdv7tt.js";
32
33
  import"../../chunks/Accordion-61e19g3e.js";