@destyler/carousel 0.0.7-beta.1

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.
@@ -0,0 +1,249 @@
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+ import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, OrientationProperty, NormalizeProps } from '@zag-js/types';
3
+ export { Orientation } from '@zag-js/types';
4
+ import * as _zag_js_core from '@zag-js/core';
5
+ import { Machine, StateMachine, ContextRef } from '@zag-js/core';
6
+
7
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "itemGroup" | "item" | "control" | "nextTrigger" | "prevTrigger" | "indicatorGroup" | "indicator" | "autoplayTrigger">;
8
+
9
+ interface PageChangeDetails {
10
+ page: number;
11
+ pageSnapPoint: number;
12
+ }
13
+ interface DragStatusDetails {
14
+ type: 'dragging.start' | 'dragging' | 'dragging.end';
15
+ page: number;
16
+ isDragging: boolean;
17
+ }
18
+ interface AutoplayStatusDetails {
19
+ type: 'autoplay.start' | 'autoplay' | 'autoplay.stop';
20
+ page: number;
21
+ isPlaying: boolean;
22
+ }
23
+ interface IntlTranslations {
24
+ nextTrigger: string;
25
+ prevTrigger: string;
26
+ indicator: (index: number) => string;
27
+ item: (index: number, count: number) => string;
28
+ autoplayStart: string;
29
+ autoplayStop: string;
30
+ }
31
+ type ElementIds = Partial<{
32
+ root: string;
33
+ item: (index: number) => string;
34
+ itemGroup: string;
35
+ nextTrigger: string;
36
+ prevTrigger: string;
37
+ indicatorGroup: string;
38
+ indicator: (index: number) => string;
39
+ }>;
40
+ interface PublicContext extends DirectionProperty, CommonProperties, OrientationProperty {
41
+ /**
42
+ * The ids of the elements in the carousel. Useful for composition.
43
+ */
44
+ ids?: ElementIds | undefined;
45
+ /**
46
+ * The localized messages to use.
47
+ */
48
+ translations: IntlTranslations;
49
+ /**
50
+ * The number of slides to show at a time.
51
+ * @default 1
52
+ */
53
+ slidesPerPage: number;
54
+ /**
55
+ * The number of slides to scroll at a time.
56
+ *
57
+ * When set to `auto`, the number of slides to scroll is determined by the
58
+ * `slidesPerPage` property.
59
+ *
60
+ * @default "auto"
61
+ */
62
+ slidesPerMove: number | 'auto';
63
+ /**
64
+ * Whether to scroll automatically. The default delay is 4000ms.
65
+ * @default false
66
+ */
67
+ autoplay?: boolean | {
68
+ delay: number;
69
+ } | undefined;
70
+ /**
71
+ * Whether to allow scrolling via dragging with mouse
72
+ * @default false
73
+ */
74
+ allowMouseDrag: boolean;
75
+ /**
76
+ * Whether the carousel should loop around.
77
+ * @default false
78
+ */
79
+ loop: boolean;
80
+ /**
81
+ * The index of the active page.
82
+ */
83
+ page: number;
84
+ /**
85
+ * The amount of space between items.
86
+ * @default "0px"
87
+ */
88
+ spacing: string;
89
+ /**
90
+ * Defines the extra space added around the scrollable area,
91
+ * enabling nearby items to remain partially in view.
92
+ */
93
+ padding?: string;
94
+ /**
95
+ * Function called when the page changes.
96
+ */
97
+ onPageChange?: ((details: PageChangeDetails) => void) | undefined;
98
+ /**
99
+ * The threshold for determining if an item is in view.
100
+ * @default 0.6
101
+ */
102
+ inViewThreshold: number | number[];
103
+ /**
104
+ * The snap type of the item.
105
+ * @default "mandatory"
106
+ */
107
+ snapType: 'proximity' | 'mandatory';
108
+ /**
109
+ * The total number of slides.
110
+ * Useful for SSR to render the initial ating the snap points.
111
+ */
112
+ slideCount?: number | undefined;
113
+ /**
114
+ * Function called when the drag status changes.
115
+ */
116
+ onDragStatusChange?: ((details: DragStatusDetails) => void) | undefined;
117
+ /**
118
+ * Function called when the autoplay status changes.
119
+ */
120
+ onAutoplayStatusChange?: ((details: AutoplayStatusDetails) => void) | undefined;
121
+ }
122
+ interface PrivateContext {
123
+ pageSnapPoints: number[];
124
+ slidesInView: number[];
125
+ timeoutRef: ContextRef<ReturnType<typeof setTimeout>>;
126
+ }
127
+ type ComputedContext = Readonly<{
128
+ isRtl: boolean;
129
+ isHorizontal: boolean;
130
+ canScrollNext: boolean;
131
+ canScrollPrev: boolean;
132
+ autoplayInterval: number;
133
+ }>;
134
+ type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
135
+ interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
136
+ }
137
+ interface MachineState {
138
+ value: 'idle' | 'dragging' | 'autoplay';
139
+ }
140
+ type State = StateMachine.State<MachineContext, MachineState>;
141
+ type Send = StateMachine.Send<StateMachine.AnyEventObject>;
142
+ type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
143
+ interface ItemProps {
144
+ /**
145
+ * The index of the item.
146
+ */
147
+ index: number;
148
+ /**
149
+ * The snap alignment of the item.
150
+ * @default "start"
151
+ */
152
+ snapAlign?: 'start' | 'end' | 'center' | undefined;
153
+ }
154
+ interface IndicatorProps {
155
+ /**
156
+ * The index of the indicator.
157
+ */
158
+ index: number;
159
+ /**
160
+ * Whether the indicator is read only.
161
+ * @default false
162
+ */
163
+ readOnly?: boolean | undefined;
164
+ }
165
+ interface MachineApi<T extends PropTypes = PropTypes> {
166
+ /**
167
+ * The current index of the carousel
168
+ */
169
+ page: number;
170
+ /**
171
+ * The current snap points of the carousel
172
+ */
173
+ pageSnapPoints: number[];
174
+ /**
175
+ * Whether the carousel is auto playing
176
+ */
177
+ isPlaying: boolean;
178
+ /**
179
+ * Whether the carousel is being dragged. This only works when `draggable` is true.
180
+ */
181
+ isDragging: boolean;
182
+ /**
183
+ * Whether the carousel is can scroll to the next view
184
+ */
185
+ canScrollNext: boolean;
186
+ /**
187
+ * Whether the carousel is can scroll to the previous view
188
+ */
189
+ canScrollPrev: boolean;
190
+ /**
191
+ * Function to scroll to a specific item index
192
+ */
193
+ scrollToIndex: (index: number, instant?: boolean) => void;
194
+ /**
195
+ * Function to scroll to a specific page
196
+ */
197
+ scrollTo: (page: number, instant?: boolean) => void;
198
+ /**
199
+ * Function to scroll to the next page
200
+ */
201
+ scrollNext: (instant?: boolean) => void;
202
+ /**
203
+ * Function to scroll to the previous page
204
+ */
205
+ scrollPrev: (instant?: boolean) => void;
206
+ /**
207
+ * Returns the current scroll progress as a percentage
208
+ */
209
+ getProgress: () => number;
210
+ /**
211
+ * Function to start/resume autoplay
212
+ */
213
+ play: () => void;
214
+ /**
215
+ * Function to pause autoplay
216
+ */
217
+ pause: () => void;
218
+ /**
219
+ * Whether the item is in view
220
+ */
221
+ isInView: (index: number) => boolean;
222
+ /**
223
+ * Function to re-compute the snap points
224
+ * and clamp the page
225
+ */
226
+ refresh: () => void;
227
+ getRootProps: () => T['element'];
228
+ getControlProps: () => T['element'];
229
+ getItemGroupProps: () => T['element'];
230
+ getItemProps: (props: ItemProps) => T['element'];
231
+ getPrevTriggerProps: () => T['button'];
232
+ getNextTriggerProps: () => T['button'];
233
+ getAutoplayTriggerProps: () => T['button'];
234
+ getIndicatorGroupProps: () => T['element'];
235
+ getIndicatorProps: (props: IndicatorProps) => T['button'];
236
+ }
237
+
238
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
239
+
240
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
241
+
242
+ declare const props: ("autoplay" | "ids" | "translations" | "slidesPerPage" | "slidesPerMove" | "allowMouseDrag" | "loop" | "page" | "spacing" | "padding" | "onPageChange" | "inViewThreshold" | "snapType" | "slideCount" | "onDragStatusChange" | "onAutoplayStatusChange" | "id" | "dir" | "getRootNode" | "orientation")[];
243
+ declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "autoplay" | "ids" | "translations" | "slidesPerPage" | "slidesPerMove" | "allowMouseDrag" | "loop" | "page" | "spacing" | "padding" | "onPageChange" | "inViewThreshold" | "snapType" | "slideCount" | "onDragStatusChange" | "onAutoplayStatusChange" | "id" | "dir" | "getRootNode" | "orientation">];
244
+ declare const indicatorProps: (keyof IndicatorProps)[];
245
+ declare const splitIndicatorProps: <Props extends IndicatorProps>(props: Props) => [IndicatorProps, Omit<Props, keyof IndicatorProps>];
246
+ declare const itemProps: (keyof ItemProps)[];
247
+ declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
248
+
249
+ export { type MachineApi as Api, type AutoplayStatusDetails, type UserDefinedContext as Context, type DragStatusDetails, type ElementIds, type IndicatorProps, type IntlTranslations, type ItemProps, type PageChangeDetails, type Service, anatomy, connect, indicatorProps, itemProps, machine, props, splitIndicatorProps, splitItemProps, splitProps };
@@ -0,0 +1,249 @@
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+ import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, OrientationProperty, NormalizeProps } from '@zag-js/types';
3
+ export { Orientation } from '@zag-js/types';
4
+ import * as _zag_js_core from '@zag-js/core';
5
+ import { Machine, StateMachine, ContextRef } from '@zag-js/core';
6
+
7
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "itemGroup" | "item" | "control" | "nextTrigger" | "prevTrigger" | "indicatorGroup" | "indicator" | "autoplayTrigger">;
8
+
9
+ interface PageChangeDetails {
10
+ page: number;
11
+ pageSnapPoint: number;
12
+ }
13
+ interface DragStatusDetails {
14
+ type: 'dragging.start' | 'dragging' | 'dragging.end';
15
+ page: number;
16
+ isDragging: boolean;
17
+ }
18
+ interface AutoplayStatusDetails {
19
+ type: 'autoplay.start' | 'autoplay' | 'autoplay.stop';
20
+ page: number;
21
+ isPlaying: boolean;
22
+ }
23
+ interface IntlTranslations {
24
+ nextTrigger: string;
25
+ prevTrigger: string;
26
+ indicator: (index: number) => string;
27
+ item: (index: number, count: number) => string;
28
+ autoplayStart: string;
29
+ autoplayStop: string;
30
+ }
31
+ type ElementIds = Partial<{
32
+ root: string;
33
+ item: (index: number) => string;
34
+ itemGroup: string;
35
+ nextTrigger: string;
36
+ prevTrigger: string;
37
+ indicatorGroup: string;
38
+ indicator: (index: number) => string;
39
+ }>;
40
+ interface PublicContext extends DirectionProperty, CommonProperties, OrientationProperty {
41
+ /**
42
+ * The ids of the elements in the carousel. Useful for composition.
43
+ */
44
+ ids?: ElementIds | undefined;
45
+ /**
46
+ * The localized messages to use.
47
+ */
48
+ translations: IntlTranslations;
49
+ /**
50
+ * The number of slides to show at a time.
51
+ * @default 1
52
+ */
53
+ slidesPerPage: number;
54
+ /**
55
+ * The number of slides to scroll at a time.
56
+ *
57
+ * When set to `auto`, the number of slides to scroll is determined by the
58
+ * `slidesPerPage` property.
59
+ *
60
+ * @default "auto"
61
+ */
62
+ slidesPerMove: number | 'auto';
63
+ /**
64
+ * Whether to scroll automatically. The default delay is 4000ms.
65
+ * @default false
66
+ */
67
+ autoplay?: boolean | {
68
+ delay: number;
69
+ } | undefined;
70
+ /**
71
+ * Whether to allow scrolling via dragging with mouse
72
+ * @default false
73
+ */
74
+ allowMouseDrag: boolean;
75
+ /**
76
+ * Whether the carousel should loop around.
77
+ * @default false
78
+ */
79
+ loop: boolean;
80
+ /**
81
+ * The index of the active page.
82
+ */
83
+ page: number;
84
+ /**
85
+ * The amount of space between items.
86
+ * @default "0px"
87
+ */
88
+ spacing: string;
89
+ /**
90
+ * Defines the extra space added around the scrollable area,
91
+ * enabling nearby items to remain partially in view.
92
+ */
93
+ padding?: string;
94
+ /**
95
+ * Function called when the page changes.
96
+ */
97
+ onPageChange?: ((details: PageChangeDetails) => void) | undefined;
98
+ /**
99
+ * The threshold for determining if an item is in view.
100
+ * @default 0.6
101
+ */
102
+ inViewThreshold: number | number[];
103
+ /**
104
+ * The snap type of the item.
105
+ * @default "mandatory"
106
+ */
107
+ snapType: 'proximity' | 'mandatory';
108
+ /**
109
+ * The total number of slides.
110
+ * Useful for SSR to render the initial ating the snap points.
111
+ */
112
+ slideCount?: number | undefined;
113
+ /**
114
+ * Function called when the drag status changes.
115
+ */
116
+ onDragStatusChange?: ((details: DragStatusDetails) => void) | undefined;
117
+ /**
118
+ * Function called when the autoplay status changes.
119
+ */
120
+ onAutoplayStatusChange?: ((details: AutoplayStatusDetails) => void) | undefined;
121
+ }
122
+ interface PrivateContext {
123
+ pageSnapPoints: number[];
124
+ slidesInView: number[];
125
+ timeoutRef: ContextRef<ReturnType<typeof setTimeout>>;
126
+ }
127
+ type ComputedContext = Readonly<{
128
+ isRtl: boolean;
129
+ isHorizontal: boolean;
130
+ canScrollNext: boolean;
131
+ canScrollPrev: boolean;
132
+ autoplayInterval: number;
133
+ }>;
134
+ type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
135
+ interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
136
+ }
137
+ interface MachineState {
138
+ value: 'idle' | 'dragging' | 'autoplay';
139
+ }
140
+ type State = StateMachine.State<MachineContext, MachineState>;
141
+ type Send = StateMachine.Send<StateMachine.AnyEventObject>;
142
+ type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
143
+ interface ItemProps {
144
+ /**
145
+ * The index of the item.
146
+ */
147
+ index: number;
148
+ /**
149
+ * The snap alignment of the item.
150
+ * @default "start"
151
+ */
152
+ snapAlign?: 'start' | 'end' | 'center' | undefined;
153
+ }
154
+ interface IndicatorProps {
155
+ /**
156
+ * The index of the indicator.
157
+ */
158
+ index: number;
159
+ /**
160
+ * Whether the indicator is read only.
161
+ * @default false
162
+ */
163
+ readOnly?: boolean | undefined;
164
+ }
165
+ interface MachineApi<T extends PropTypes = PropTypes> {
166
+ /**
167
+ * The current index of the carousel
168
+ */
169
+ page: number;
170
+ /**
171
+ * The current snap points of the carousel
172
+ */
173
+ pageSnapPoints: number[];
174
+ /**
175
+ * Whether the carousel is auto playing
176
+ */
177
+ isPlaying: boolean;
178
+ /**
179
+ * Whether the carousel is being dragged. This only works when `draggable` is true.
180
+ */
181
+ isDragging: boolean;
182
+ /**
183
+ * Whether the carousel is can scroll to the next view
184
+ */
185
+ canScrollNext: boolean;
186
+ /**
187
+ * Whether the carousel is can scroll to the previous view
188
+ */
189
+ canScrollPrev: boolean;
190
+ /**
191
+ * Function to scroll to a specific item index
192
+ */
193
+ scrollToIndex: (index: number, instant?: boolean) => void;
194
+ /**
195
+ * Function to scroll to a specific page
196
+ */
197
+ scrollTo: (page: number, instant?: boolean) => void;
198
+ /**
199
+ * Function to scroll to the next page
200
+ */
201
+ scrollNext: (instant?: boolean) => void;
202
+ /**
203
+ * Function to scroll to the previous page
204
+ */
205
+ scrollPrev: (instant?: boolean) => void;
206
+ /**
207
+ * Returns the current scroll progress as a percentage
208
+ */
209
+ getProgress: () => number;
210
+ /**
211
+ * Function to start/resume autoplay
212
+ */
213
+ play: () => void;
214
+ /**
215
+ * Function to pause autoplay
216
+ */
217
+ pause: () => void;
218
+ /**
219
+ * Whether the item is in view
220
+ */
221
+ isInView: (index: number) => boolean;
222
+ /**
223
+ * Function to re-compute the snap points
224
+ * and clamp the page
225
+ */
226
+ refresh: () => void;
227
+ getRootProps: () => T['element'];
228
+ getControlProps: () => T['element'];
229
+ getItemGroupProps: () => T['element'];
230
+ getItemProps: (props: ItemProps) => T['element'];
231
+ getPrevTriggerProps: () => T['button'];
232
+ getNextTriggerProps: () => T['button'];
233
+ getAutoplayTriggerProps: () => T['button'];
234
+ getIndicatorGroupProps: () => T['element'];
235
+ getIndicatorProps: (props: IndicatorProps) => T['button'];
236
+ }
237
+
238
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
239
+
240
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
241
+
242
+ declare const props: ("autoplay" | "ids" | "translations" | "slidesPerPage" | "slidesPerMove" | "allowMouseDrag" | "loop" | "page" | "spacing" | "padding" | "onPageChange" | "inViewThreshold" | "snapType" | "slideCount" | "onDragStatusChange" | "onAutoplayStatusChange" | "id" | "dir" | "getRootNode" | "orientation")[];
243
+ declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "autoplay" | "ids" | "translations" | "slidesPerPage" | "slidesPerMove" | "allowMouseDrag" | "loop" | "page" | "spacing" | "padding" | "onPageChange" | "inViewThreshold" | "snapType" | "slideCount" | "onDragStatusChange" | "onAutoplayStatusChange" | "id" | "dir" | "getRootNode" | "orientation">];
244
+ declare const indicatorProps: (keyof IndicatorProps)[];
245
+ declare const splitIndicatorProps: <Props extends IndicatorProps>(props: Props) => [IndicatorProps, Omit<Props, keyof IndicatorProps>];
246
+ declare const itemProps: (keyof ItemProps)[];
247
+ declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
248
+
249
+ export { type MachineApi as Api, type AutoplayStatusDetails, type UserDefinedContext as Context, type DragStatusDetails, type ElementIds, type IndicatorProps, type IntlTranslations, type ItemProps, type PageChangeDetails, type Service, anatomy, connect, indicatorProps, itemProps, machine, props, splitIndicatorProps, splitItemProps, splitProps };