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/index.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/index.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
+ };
package/dist/react.css ADDED
@@ -0,0 +1,125 @@
1
+ /* src/styles/PillStepper.css */
2
+ .pasito-container {
3
+ --pill-dot-size: 8px;
4
+ --pill-active-width: 24px;
5
+ --pill-gap: 6px;
6
+ --pill-duration: 500ms;
7
+ --pill-easing: cubic-bezier(0.215, 0.61, 0.355, 1);
8
+ --pill-bg: rgba(0, 0, 0, 0.12);
9
+ --pill-active-bg: rgba(0, 0, 0, 0.8);
10
+ --pill-fill-bg: rgba(255, 255, 255, 0.45);
11
+ --pill-container-bg: rgba(0, 0, 0, 0.04);
12
+ --pill-container-radius: 999px;
13
+ --pill-container-border: rgba(0, 0, 0, 0.06);
14
+ display: inline-flex;
15
+ padding: 6px 10px;
16
+ background: var(--pill-container-bg);
17
+ border-radius: var(--pill-container-radius);
18
+ border: 1px solid var(--pill-container-border);
19
+ overflow: hidden;
20
+ }
21
+ .pasito-track {
22
+ display: flex;
23
+ align-items: center;
24
+ margin-left: calc(-1 * var(--pill-gap));
25
+ transition: transform var(--pill-duration) var(--pill-easing);
26
+ }
27
+ .pasito-vertical .pasito-track {
28
+ flex-direction: column;
29
+ margin-left: 0;
30
+ margin-top: calc(-1 * var(--pill-gap));
31
+ }
32
+ .pasito-step {
33
+ position: relative;
34
+ width: var(--pill-dot-size);
35
+ height: var(--pill-dot-size);
36
+ border-radius: 999px;
37
+ border: none;
38
+ padding: 0;
39
+ cursor: pointer;
40
+ background: var(--pill-bg);
41
+ flex-shrink: 0;
42
+ overflow: hidden;
43
+ margin-left: var(--pill-gap);
44
+ margin-top: 0;
45
+ transform-origin: center center;
46
+ transition:
47
+ width var(--pill-duration) var(--pill-easing),
48
+ height var(--pill-duration) var(--pill-easing),
49
+ background var(--pill-duration) var(--pill-easing),
50
+ opacity var(--pill-duration) var(--pill-easing),
51
+ transform var(--pill-duration) var(--pill-easing),
52
+ margin-left var(--pill-duration) var(--pill-easing),
53
+ margin-top var(--pill-duration) var(--pill-easing);
54
+ }
55
+ .pasito-vertical .pasito-step {
56
+ margin-left: 0;
57
+ margin-top: var(--pill-gap);
58
+ }
59
+ .pasito-step:focus-visible {
60
+ outline: 2px solid rgba(0, 0, 0, 0.3);
61
+ outline-offset: 2px;
62
+ }
63
+ .pasito-step-active {
64
+ width: var(--pill-active-width);
65
+ background: var(--pill-active-bg);
66
+ }
67
+ .pasito-vertical .pasito-step-active {
68
+ width: var(--pill-dot-size);
69
+ height: var(--pill-active-width);
70
+ }
71
+ .pasito-step::after {
72
+ content: "";
73
+ position: absolute;
74
+ inset: 0;
75
+ border-radius: inherit;
76
+ background: var(--pill-fill-bg);
77
+ transform: scaleX(0);
78
+ transform-origin: left center;
79
+ pointer-events: none;
80
+ }
81
+ .pasito-vertical .pasito-step::after {
82
+ transform: scaleY(0);
83
+ transform-origin: center top;
84
+ }
85
+ .pasito-step-filling::after {
86
+ transform: scaleX(1);
87
+ transition: transform var(--pill-fill-duration, 3000ms) linear;
88
+ }
89
+ .pasito-vertical .pasito-step-filling::after {
90
+ transform: scaleY(1);
91
+ transition: transform var(--pill-fill-duration, 3000ms) linear;
92
+ }
93
+ .pasito-entering {
94
+ width: 0;
95
+ margin-left: 0;
96
+ margin-top: 0;
97
+ opacity: 0;
98
+ transform: scale(0);
99
+ transition-duration: 250ms;
100
+ }
101
+ .pasito-vertical .pasito-entering {
102
+ width: var(--pill-dot-size);
103
+ height: 0;
104
+ }
105
+ .pasito-exiting {
106
+ width: 0;
107
+ margin-left: 0;
108
+ margin-top: 0;
109
+ opacity: 0;
110
+ transform: scale(0);
111
+ transition-duration: 250ms;
112
+ }
113
+ .pasito-vertical .pasito-exiting {
114
+ width: var(--pill-dot-size);
115
+ height: 0;
116
+ }
117
+ @media (prefers-reduced-motion: reduce) {
118
+ .pasito-step,
119
+ .pasito-track {
120
+ transition-duration: 0ms !important;
121
+ }
122
+ .pasito-step-filling::after {
123
+ transition-duration: 0ms !important;
124
+ }
125
+ }
@@ -0,0 +1,2 @@
1
+ export { PillStepper, useAutoPlay } from './index.mjs';
2
+ export { P as PillStepperProps, U as UseAutoPlayOptions, a as UseAutoPlayReturn } from './types-C_ERj5iI.mjs';
@@ -0,0 +1,2 @@
1
+ export { PillStepper, useAutoPlay } from './index.js';
2
+ export { P as PillStepperProps, U as UseAutoPlayOptions, a as UseAutoPlayReturn } from './types-C_ERj5iI.js';