pasito 0.1.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.
package/dist/react.js ADDED
@@ -0,0 +1,342 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/react/index.ts
22
+ var react_exports = {};
23
+ __export(react_exports, {
24
+ PillStepper: () => PillStepper,
25
+ useAutoPlay: () => useAutoPlay
26
+ });
27
+ module.exports = __toCommonJS(react_exports);
28
+
29
+ // src/react/hooks/useStepWindow.ts
30
+ var import_react = require("react");
31
+
32
+ // src/core/computeStepWindow.ts
33
+ var DOT_SIZE = 8;
34
+ var ACTIVE_WIDTH = 24;
35
+ var GAP = 6;
36
+ var SLOT_SIZE = DOT_SIZE + GAP;
37
+ function computeStepWindow(count, active, maxVisible, orientation) {
38
+ if (maxVisible == null || count <= maxVisible) {
39
+ return {
40
+ windowStart: 0,
41
+ transformValue: "none",
42
+ containerSize: void 0
43
+ };
44
+ }
45
+ const half = Math.floor(maxVisible / 2);
46
+ const windowStart = Math.max(0, Math.min(active - half, count - maxVisible));
47
+ const offset = windowStart * SLOT_SIZE;
48
+ const axis = orientation === "vertical" ? "Y" : "X";
49
+ const transformValue = `translate${axis}(-${offset}px)`;
50
+ const size = (maxVisible - 1) * DOT_SIZE + ACTIVE_WIDTH + (maxVisible - 1) * GAP;
51
+ return { windowStart, transformValue, containerSize: size };
52
+ }
53
+
54
+ // src/react/hooks/useStepWindow.ts
55
+ function useStepWindow(count, active, maxVisible, orientation) {
56
+ return (0, import_react.useMemo)(
57
+ () => computeStepWindow(count, active, maxVisible, orientation),
58
+ [count, active, maxVisible, orientation]
59
+ );
60
+ }
61
+
62
+ // src/react/hooks/useAnimatingSteps.ts
63
+ var import_react2 = require("react");
64
+
65
+ // src/core/StepAnimator.ts
66
+ var StepAnimator = class {
67
+ constructor(count) {
68
+ this.keyGen = count;
69
+ this.steps = Array.from({ length: count }, (_, i) => ({
70
+ key: i,
71
+ index: i,
72
+ phase: "stable"
73
+ }));
74
+ }
75
+ reconcile(newCount) {
76
+ const liveCount = this.steps.filter((s) => s.phase !== "exiting").length;
77
+ if (liveCount === newCount) {
78
+ return {
79
+ hasEntering: this.steps.some((s) => s.phase === "entering"),
80
+ exitingCount: this.steps.filter((s) => s.phase === "exiting").length
81
+ };
82
+ }
83
+ if (newCount < liveCount) {
84
+ let seen = 0;
85
+ this.steps = this.steps.map((s) => {
86
+ if (s.phase === "exiting") return s;
87
+ seen++;
88
+ if (seen > newCount) return { ...s, phase: "exiting" };
89
+ return s;
90
+ });
91
+ }
92
+ if (newCount > liveCount) {
93
+ for (let i = liveCount; i < newCount; i++) {
94
+ this.keyGen++;
95
+ this.steps.push({
96
+ key: this.keyGen,
97
+ index: i,
98
+ phase: "entering"
99
+ });
100
+ }
101
+ }
102
+ let idx = 0;
103
+ this.steps = this.steps.map(
104
+ (s) => s.phase === "exiting" ? s : { ...s, index: idx++ }
105
+ );
106
+ return {
107
+ hasEntering: this.steps.some((s) => s.phase === "entering"),
108
+ exitingCount: this.steps.filter((s) => s.phase === "exiting").length
109
+ };
110
+ }
111
+ promoteEntering() {
112
+ this.steps = this.steps.map(
113
+ (s) => s.phase === "entering" ? { ...s, phase: "stable" } : s
114
+ );
115
+ }
116
+ removeExiting() {
117
+ this.steps = this.steps.filter((s) => s.phase !== "exiting");
118
+ }
119
+ getSteps() {
120
+ return [...this.steps];
121
+ }
122
+ };
123
+
124
+ // src/react/hooks/useAnimatingSteps.ts
125
+ function useAnimatingSteps(count, _duration) {
126
+ const animatorRef = (0, import_react2.useRef)(null);
127
+ if (animatorRef.current === null) {
128
+ animatorRef.current = new StepAnimator(count);
129
+ }
130
+ const animator = animatorRef.current;
131
+ const [steps, setSteps] = (0, import_react2.useState)(() => animator.getSteps());
132
+ (0, import_react2.useLayoutEffect)(() => {
133
+ animator.reconcile(count);
134
+ setSteps(animator.getSteps());
135
+ }, [count, animator]);
136
+ const hasEntering = steps.some((s) => s.phase === "entering");
137
+ (0, import_react2.useEffect)(() => {
138
+ if (!hasEntering) return;
139
+ let raf1;
140
+ let raf2;
141
+ raf1 = requestAnimationFrame(() => {
142
+ raf2 = requestAnimationFrame(() => {
143
+ animator.promoteEntering();
144
+ setSteps(animator.getSteps());
145
+ });
146
+ });
147
+ return () => {
148
+ cancelAnimationFrame(raf1);
149
+ cancelAnimationFrame(raf2);
150
+ };
151
+ }, [hasEntering, animator]);
152
+ const exitingCount = steps.filter((s) => s.phase === "exiting").length;
153
+ (0, import_react2.useEffect)(() => {
154
+ if (exitingCount === 0) return;
155
+ const timer = setTimeout(() => {
156
+ animator.removeExiting();
157
+ setSteps(animator.getSteps());
158
+ }, 300);
159
+ return () => clearTimeout(timer);
160
+ }, [exitingCount, animator]);
161
+ return steps;
162
+ }
163
+
164
+ // src/react/PillStep.tsx
165
+ var import_jsx_runtime = require("react/jsx-runtime");
166
+ function PillStep({
167
+ index,
168
+ isActive,
169
+ phase,
170
+ transitionDuration,
171
+ filling,
172
+ fillDuration,
173
+ onClick
174
+ }) {
175
+ const classNames = [
176
+ "pasito-step",
177
+ isActive && "pasito-step-active",
178
+ isActive && filling && "pasito-step-filling",
179
+ phase === "entering" && "pasito-entering",
180
+ phase === "exiting" && "pasito-exiting"
181
+ ].filter(Boolean).join(" ");
182
+ const style = {
183
+ "--pill-duration": `${transitionDuration}ms`
184
+ };
185
+ if (isActive && filling && fillDuration) {
186
+ style["--pill-fill-duration"] = `${fillDuration}ms`;
187
+ }
188
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
189
+ "button",
190
+ {
191
+ className: classNames,
192
+ style,
193
+ onClick,
194
+ role: "tab",
195
+ "aria-selected": isActive,
196
+ "aria-label": `Step ${index + 1}`,
197
+ tabIndex: isActive ? 0 : -1
198
+ }
199
+ );
200
+ }
201
+
202
+ // src/react/PillStepper.tsx
203
+ var import_jsx_runtime2 = require("react/jsx-runtime");
204
+ function PillStepper({
205
+ count,
206
+ active,
207
+ onStepClick,
208
+ orientation = "horizontal",
209
+ maxVisible,
210
+ transitionDuration = 500,
211
+ easing,
212
+ className,
213
+ filling,
214
+ fillDuration
215
+ }) {
216
+ const { transformValue, containerSize } = useStepWindow(
217
+ count,
218
+ active,
219
+ maxVisible,
220
+ orientation
221
+ );
222
+ const animatingSteps = useAnimatingSteps(count, transitionDuration);
223
+ const containerClass = [
224
+ "pasito-container",
225
+ orientation === "vertical" && "pasito-vertical",
226
+ className
227
+ ].filter(Boolean).join(" ");
228
+ const sizeStyle = {};
229
+ if (containerSize != null) {
230
+ if (orientation === "vertical") {
231
+ sizeStyle.height = containerSize;
232
+ } else {
233
+ sizeStyle.width = containerSize;
234
+ }
235
+ }
236
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
237
+ "div",
238
+ {
239
+ className: containerClass,
240
+ role: "tablist",
241
+ "aria-label": "Progress steps",
242
+ style: {
243
+ "--pill-duration": `${transitionDuration}ms`,
244
+ ...easing && { "--pill-easing": easing },
245
+ ...sizeStyle
246
+ },
247
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
248
+ "div",
249
+ {
250
+ className: "pasito-track",
251
+ style: { transform: transformValue },
252
+ children: animatingSteps.map((step) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
253
+ PillStep,
254
+ {
255
+ index: step.index,
256
+ isActive: step.index === active,
257
+ phase: step.phase,
258
+ transitionDuration,
259
+ filling: step.index === active && filling,
260
+ fillDuration,
261
+ onClick: onStepClick ? () => onStepClick(step.index) : void 0
262
+ },
263
+ step.key
264
+ ))
265
+ }
266
+ )
267
+ }
268
+ );
269
+ }
270
+
271
+ // src/react/hooks/useAutoPlay.ts
272
+ var import_react3 = require("react");
273
+
274
+ // src/core/AutoPlayController.ts
275
+ var AutoPlayController = class {
276
+ constructor({ stepDuration = 3e3, loop = true } = {}) {
277
+ this.stepDuration = stepDuration;
278
+ this.loop = loop;
279
+ }
280
+ computeNext(active, count) {
281
+ return active < count - 1 ? active + 1 : this.loop ? 0 : null;
282
+ }
283
+ };
284
+
285
+ // src/react/hooks/useAutoPlay.ts
286
+ function useAutoPlay({
287
+ count,
288
+ active,
289
+ onStepChange,
290
+ stepDuration = 3e3,
291
+ loop = true,
292
+ enabled = true
293
+ }) {
294
+ const [playing, setPlaying] = (0, import_react3.useState)(false);
295
+ const timerRef = (0, import_react3.useRef)(null);
296
+ const controllerRef = (0, import_react3.useRef)(null);
297
+ if (!controllerRef.current) {
298
+ controllerRef.current = new AutoPlayController({ stepDuration, loop });
299
+ }
300
+ controllerRef.current.stepDuration = stepDuration;
301
+ controllerRef.current.loop = loop;
302
+ const clearTimer = (0, import_react3.useCallback)(() => {
303
+ if (timerRef.current) {
304
+ clearTimeout(timerRef.current);
305
+ timerRef.current = null;
306
+ }
307
+ }, []);
308
+ const toggle = (0, import_react3.useCallback)(() => setPlaying((p) => !p), []);
309
+ (0, import_react3.useEffect)(() => {
310
+ if (!enabled) {
311
+ setPlaying(false);
312
+ clearTimer();
313
+ }
314
+ }, [enabled, clearTimer]);
315
+ (0, import_react3.useEffect)(() => {
316
+ if (!playing || !enabled) {
317
+ clearTimer();
318
+ return;
319
+ }
320
+ timerRef.current = setTimeout(() => {
321
+ const nextStep = controllerRef.current.computeNext(active, count);
322
+ if (nextStep !== null) {
323
+ onStepChange(nextStep);
324
+ } else {
325
+ setPlaying(false);
326
+ }
327
+ }, stepDuration);
328
+ return clearTimer;
329
+ }, [playing, enabled, active, count, stepDuration, loop, onStepChange, clearTimer]);
330
+ const isActive = playing && enabled;
331
+ return {
332
+ playing: isActive,
333
+ toggle,
334
+ filling: isActive,
335
+ fillDuration: stepDuration
336
+ };
337
+ }
338
+ // Annotate the CommonJS export names for ESM import in node:
339
+ 0 && (module.exports = {
340
+ PillStepper,
341
+ useAutoPlay
342
+ });
package/dist/react.mjs ADDED
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import {
3
+ PillStepper,
4
+ useAutoPlay
5
+ } from "./chunk-HAF3VK2R.mjs";
6
+ import "./chunk-4JH2WF3D.mjs";
7
+ export {
8
+ PillStepper,
9
+ useAutoPlay
10
+ };
@@ -0,0 +1,44 @@
1
+ interface PillStepperProps {
2
+ /** Total number of steps */
3
+ count: number;
4
+ /** Zero-based active step index */
5
+ active: number;
6
+ /** Optional click handler */
7
+ onStepClick?: (index: number) => void;
8
+ /** Layout direction */
9
+ orientation?: "horizontal" | "vertical";
10
+ /** Max visible steps (enables windowing) */
11
+ maxVisible?: number;
12
+ /** Transition duration in ms */
13
+ transitionDuration?: number;
14
+ /** CSS transition timing function */
15
+ easing?: string;
16
+ /** Additional CSS class for overrides */
17
+ className?: string;
18
+ /** Whether the active step is filling (autoplay mode) */
19
+ filling?: boolean;
20
+ /** Duration of the fill animation in ms */
21
+ fillDuration?: number;
22
+ }
23
+ interface AnimatingStep {
24
+ key: number;
25
+ index: number;
26
+ phase: "entering" | "stable" | "exiting";
27
+ }
28
+ interface UseAutoPlayOptions {
29
+ count: number;
30
+ active: number;
31
+ onStepChange: (index: number) => void;
32
+ stepDuration?: number;
33
+ loop?: boolean;
34
+ /** When false, stops playback and resets playing state */
35
+ enabled?: boolean;
36
+ }
37
+ interface UseAutoPlayReturn {
38
+ playing: boolean;
39
+ toggle: () => void;
40
+ filling: boolean;
41
+ fillDuration: number;
42
+ }
43
+
44
+ export type { AnimatingStep as A, PillStepperProps as P, UseAutoPlayOptions as U, UseAutoPlayReturn as a };
@@ -0,0 +1,44 @@
1
+ interface PillStepperProps {
2
+ /** Total number of steps */
3
+ count: number;
4
+ /** Zero-based active step index */
5
+ active: number;
6
+ /** Optional click handler */
7
+ onStepClick?: (index: number) => void;
8
+ /** Layout direction */
9
+ orientation?: "horizontal" | "vertical";
10
+ /** Max visible steps (enables windowing) */
11
+ maxVisible?: number;
12
+ /** Transition duration in ms */
13
+ transitionDuration?: number;
14
+ /** CSS transition timing function */
15
+ easing?: string;
16
+ /** Additional CSS class for overrides */
17
+ className?: string;
18
+ /** Whether the active step is filling (autoplay mode) */
19
+ filling?: boolean;
20
+ /** Duration of the fill animation in ms */
21
+ fillDuration?: number;
22
+ }
23
+ interface AnimatingStep {
24
+ key: number;
25
+ index: number;
26
+ phase: "entering" | "stable" | "exiting";
27
+ }
28
+ interface UseAutoPlayOptions {
29
+ count: number;
30
+ active: number;
31
+ onStepChange: (index: number) => void;
32
+ stepDuration?: number;
33
+ loop?: boolean;
34
+ /** When false, stops playback and resets playing state */
35
+ enabled?: boolean;
36
+ }
37
+ interface UseAutoPlayReturn {
38
+ playing: boolean;
39
+ toggle: () => void;
40
+ filling: boolean;
41
+ fillDuration: number;
42
+ }
43
+
44
+ export type { AnimatingStep as A, PillStepperProps as P, UseAutoPlayOptions as U, UseAutoPlayReturn as a };
package/dist/vue.d.mts ADDED
@@ -0,0 +1,100 @@
1
+ import * as vue from 'vue';
2
+ import { PropType, Ref } from 'vue';
3
+ export { A as AnimatingStep, a as UseAutoPlayReturn } from './types-C_ERj5iI.mjs';
4
+
5
+ declare const PillStepper: vue.DefineComponent<vue.ExtractPropTypes<{
6
+ count: {
7
+ type: NumberConstructor;
8
+ required: true;
9
+ };
10
+ active: {
11
+ type: NumberConstructor;
12
+ required: true;
13
+ };
14
+ orientation: {
15
+ type: PropType<"horizontal" | "vertical">;
16
+ default: string;
17
+ };
18
+ maxVisible: {
19
+ type: NumberConstructor;
20
+ default: undefined;
21
+ };
22
+ transitionDuration: {
23
+ type: NumberConstructor;
24
+ default: number;
25
+ };
26
+ easing: {
27
+ type: StringConstructor;
28
+ default: undefined;
29
+ };
30
+ filling: {
31
+ type: BooleanConstructor;
32
+ default: boolean;
33
+ };
34
+ fillDuration: {
35
+ type: NumberConstructor;
36
+ default: undefined;
37
+ };
38
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
39
+ [key: string]: any;
40
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "step-click"[], "step-click", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
41
+ count: {
42
+ type: NumberConstructor;
43
+ required: true;
44
+ };
45
+ active: {
46
+ type: NumberConstructor;
47
+ required: true;
48
+ };
49
+ orientation: {
50
+ type: PropType<"horizontal" | "vertical">;
51
+ default: string;
52
+ };
53
+ maxVisible: {
54
+ type: NumberConstructor;
55
+ default: undefined;
56
+ };
57
+ transitionDuration: {
58
+ type: NumberConstructor;
59
+ default: number;
60
+ };
61
+ easing: {
62
+ type: StringConstructor;
63
+ default: undefined;
64
+ };
65
+ filling: {
66
+ type: BooleanConstructor;
67
+ default: boolean;
68
+ };
69
+ fillDuration: {
70
+ type: NumberConstructor;
71
+ default: undefined;
72
+ };
73
+ }>> & Readonly<{
74
+ "onStep-click"?: ((...args: any[]) => any) | undefined;
75
+ }>, {
76
+ transitionDuration: number;
77
+ filling: boolean;
78
+ fillDuration: number;
79
+ orientation: "horizontal" | "vertical";
80
+ maxVisible: number;
81
+ easing: string;
82
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
83
+
84
+ type MaybeRef<T> = T | Ref<T>;
85
+ interface UseAutoPlayOptions {
86
+ count: Ref<number>;
87
+ active: Ref<number>;
88
+ onStepChange: (index: number) => void;
89
+ stepDuration?: MaybeRef<number>;
90
+ loop?: MaybeRef<boolean>;
91
+ enabled?: MaybeRef<boolean>;
92
+ }
93
+ declare function useAutoPlay(options: UseAutoPlayOptions): {
94
+ playing: vue.ComputedRef<boolean>;
95
+ toggle: () => void;
96
+ filling: vue.ComputedRef<boolean>;
97
+ fillDuration: vue.ComputedRef<number>;
98
+ };
99
+
100
+ export { PillStepper, type UseAutoPlayOptions, useAutoPlay };
package/dist/vue.d.ts ADDED
@@ -0,0 +1,100 @@
1
+ import * as vue from 'vue';
2
+ import { PropType, Ref } from 'vue';
3
+ export { A as AnimatingStep, a as UseAutoPlayReturn } from './types-C_ERj5iI.js';
4
+
5
+ declare const PillStepper: vue.DefineComponent<vue.ExtractPropTypes<{
6
+ count: {
7
+ type: NumberConstructor;
8
+ required: true;
9
+ };
10
+ active: {
11
+ type: NumberConstructor;
12
+ required: true;
13
+ };
14
+ orientation: {
15
+ type: PropType<"horizontal" | "vertical">;
16
+ default: string;
17
+ };
18
+ maxVisible: {
19
+ type: NumberConstructor;
20
+ default: undefined;
21
+ };
22
+ transitionDuration: {
23
+ type: NumberConstructor;
24
+ default: number;
25
+ };
26
+ easing: {
27
+ type: StringConstructor;
28
+ default: undefined;
29
+ };
30
+ filling: {
31
+ type: BooleanConstructor;
32
+ default: boolean;
33
+ };
34
+ fillDuration: {
35
+ type: NumberConstructor;
36
+ default: undefined;
37
+ };
38
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
39
+ [key: string]: any;
40
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "step-click"[], "step-click", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
41
+ count: {
42
+ type: NumberConstructor;
43
+ required: true;
44
+ };
45
+ active: {
46
+ type: NumberConstructor;
47
+ required: true;
48
+ };
49
+ orientation: {
50
+ type: PropType<"horizontal" | "vertical">;
51
+ default: string;
52
+ };
53
+ maxVisible: {
54
+ type: NumberConstructor;
55
+ default: undefined;
56
+ };
57
+ transitionDuration: {
58
+ type: NumberConstructor;
59
+ default: number;
60
+ };
61
+ easing: {
62
+ type: StringConstructor;
63
+ default: undefined;
64
+ };
65
+ filling: {
66
+ type: BooleanConstructor;
67
+ default: boolean;
68
+ };
69
+ fillDuration: {
70
+ type: NumberConstructor;
71
+ default: undefined;
72
+ };
73
+ }>> & Readonly<{
74
+ "onStep-click"?: ((...args: any[]) => any) | undefined;
75
+ }>, {
76
+ transitionDuration: number;
77
+ filling: boolean;
78
+ fillDuration: number;
79
+ orientation: "horizontal" | "vertical";
80
+ maxVisible: number;
81
+ easing: string;
82
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
83
+
84
+ type MaybeRef<T> = T | Ref<T>;
85
+ interface UseAutoPlayOptions {
86
+ count: Ref<number>;
87
+ active: Ref<number>;
88
+ onStepChange: (index: number) => void;
89
+ stepDuration?: MaybeRef<number>;
90
+ loop?: MaybeRef<boolean>;
91
+ enabled?: MaybeRef<boolean>;
92
+ }
93
+ declare function useAutoPlay(options: UseAutoPlayOptions): {
94
+ playing: vue.ComputedRef<boolean>;
95
+ toggle: () => void;
96
+ filling: vue.ComputedRef<boolean>;
97
+ fillDuration: vue.ComputedRef<number>;
98
+ };
99
+
100
+ export { PillStepper, type UseAutoPlayOptions, useAutoPlay };