digitojs 1.2.2 → 1.2.4

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/src/core/types.ts DELETED
@@ -1,199 +0,0 @@
1
- /**
2
- * digito/core/types
3
- * ─────────────────────────────────────────────────────────────────────────────
4
- * Shared TypeScript interfaces and type aliases used across the core modules.
5
- *
6
- * @author Olawale Balo — Product Designer + Design Engineer
7
- * @license MIT
8
- */
9
-
10
- /** The set of characters each slot will accept. */
11
- export type InputType = 'numeric' | 'alphabet' | 'alphanumeric' | 'any'
12
-
13
- /** Snapshot of the OTP field state at any point in time. */
14
- export type DigitoState = {
15
- /** Current value of each slot. Empty string means unfilled. */
16
- slotValues: string[]
17
- /** Index of the currently focused slot. */
18
- activeSlot: number
19
- /** Whether an error state is active. */
20
- hasError: boolean
21
- /** True when every slot contains a valid character. */
22
- isComplete: boolean
23
- /**
24
- * Mirrors the initial timer value — NOT a live countdown.
25
- * The live countdown is managed by each adapter layer.
26
- * Do not use this field to read remaining time; use the adapter's onTick callback instead.
27
- */
28
- timerSeconds: number
29
- /** Whether the input is currently disabled. Reflects the latest `setDisabled()` call. */
30
- isDisabled: boolean
31
- /** Whether the input is currently read-only. Reflects the latest `setReadOnly()` call. */
32
- isReadOnly: boolean
33
- }
34
-
35
- /** Configuration options passed to `createDigito` or `initDigito`. */
36
- export type DigitoOptions = {
37
- /** Number of input slots. Default: `6`. */
38
- length?: number
39
- /** Character set accepted by each slot. Default: `'numeric'`. */
40
- type?: InputType
41
- /** Countdown duration in seconds. `0` disables the timer. Default: `0`. */
42
- timer?: number
43
- /** Resend cooldown in seconds after the user clicks Resend. Default: `30`. */
44
- resendAfter?: number
45
- /** Called with the joined code string when all slots are filled. */
46
- onComplete?: (code: string) => void
47
- /**
48
- * Called every second with the remaining seconds. Use to drive a custom timer UI.
49
- *
50
- * **Adapter note:** Only fires in adapters that include a built-in countdown timer
51
- * (vanilla, alpine, web component). In React, Vue, and Svelte the timer is managed
52
- * separately inside each adapter — pass `onTick` as part of those adapters' options.
53
- * Has no effect when passed directly to `createDigito`.
54
- */
55
- onTick?: (remainingSeconds: number) => void
56
- /** Called when the countdown reaches zero. */
57
- onExpire?: () => void
58
- /**
59
- * Called when the resend action is triggered.
60
- *
61
- * **Adapter note:** Only fires automatically in adapters with a built-in Resend button
62
- * (vanilla, alpine, web component). In React, Vue, and Svelte there is no built-in
63
- * Resend button — call `onResend` manually in your own UI handler.
64
- * Has no effect when passed directly to `createDigito`.
65
- */
66
- onResend?: () => void
67
- /** Vibrate on completion and error via `navigator.vibrate`. Default: `true`. */
68
- haptic?: boolean
69
- /** Play a short tone on completion via Web Audio API. Default: `false`. */
70
- sound?: boolean
71
- /**
72
- * When `true`, all input actions (typing, backspace, paste) are silently ignored.
73
- * Use this during async verification to prevent the user modifying the code.
74
- * Default: `false`.
75
- */
76
- disabled?: boolean
77
- /**
78
- * Arbitrary per-character regex. When provided, each typed/pasted character must
79
- * match this pattern to be accepted into a slot.
80
- *
81
- * Takes precedence over the named `type` for character validation only —
82
- * `type` still controls `inputMode` and ARIA labels on the hidden input.
83
- *
84
- * The regex should match a **single character**:
85
- * @example pattern: /^[0-9A-F]$/ — uppercase hex only
86
- * @example pattern: /^[2-9A-HJ-NP-Z]$/ — ambiguity-free alphanumeric (no 0/O, 1/I/L)
87
- */
88
- pattern?: RegExp
89
- /**
90
- * Optional transform applied to the raw clipboard text before it is filtered
91
- * and distributed into slots. Runs before `filterString` inside `pasteString()`.
92
- *
93
- * Use to strip formatting from pasted codes that real users copy from emails or
94
- * SMS messages (e.g. `"G-123456"` → `"123456"`, `"123 456"` → `"123456"`).
95
- *
96
- * The return value is then passed through the normal `filterString` + `pattern`
97
- * validation, so you only need to handle the structural formatting — character
98
- * validity is still enforced automatically.
99
- *
100
- * @example pasteTransformer: (raw) => raw.replace(/\s+|-/g, '')
101
- * @example pasteTransformer: (raw) => raw.toUpperCase()
102
- */
103
- pasteTransformer?: (raw: string) => string
104
- /**
105
- * Auto-focus the hidden input when the component mounts.
106
- * Set to `false` to prevent the field from stealing focus on load.
107
- * Default: `true`.
108
- */
109
- autoFocus?: boolean
110
- /**
111
- * The `name` attribute to set on the hidden input for native HTML form
112
- * submission and `FormData` compatibility.
113
- * @example name: 'otp' → FormData includes otp=123456
114
- */
115
- name?: string
116
- /**
117
- * Called when the hidden input gains browser focus.
118
- * Use to show contextual help or update surrounding UI.
119
- */
120
- onFocus?: () => void
121
- /**
122
- * Called when the hidden input loses browser focus.
123
- * Use to trigger validation or hide contextual help.
124
- */
125
- onBlur?: () => void
126
- /**
127
- * Character to display in empty (unfilled) slots as a visual hint.
128
- * Common choices: `'○'`, `'_'`, `'·'`, `'•'`.
129
- * Default: `''` (blank — no placeholder).
130
- * @example placeholder: '○'
131
- */
132
- placeholder?: string
133
- /**
134
- * When `true`, focusing a slot that already contains a character selects that
135
- * character so the next keystroke replaces it in-place.
136
- * When `false` (default), the cursor is placed at the slot position and the
137
- * existing character must be deleted before a new one can be entered.
138
- * Default: `false`.
139
- */
140
- selectOnFocus?: boolean
141
- /**
142
- * When `true`, the hidden input is automatically blurred when all slots are
143
- * filled. Removes focus styling and hides the fake caret once the code is
144
- * complete. Useful for flows that immediately submit or verify on completion.
145
- * Default: `false`.
146
- */
147
- blurOnComplete?: boolean
148
- /**
149
- * Uncontrolled initial value applied once on mount.
150
- * Distributed across slots exactly like user input but does NOT trigger
151
- * `onComplete` or fire change events. Ignored when a `value` prop is present.
152
- * Default: `undefined` (no pre-fill).
153
- */
154
- defaultValue?: string
155
- /**
156
- * When `true`, all slot mutations (typing, backspace, delete, paste) are
157
- * blocked while focus, selection, arrow navigation, and copy remain allowed.
158
- * Semantically distinct from `disabled` — the field is readable and focusable.
159
- * Default: `false`.
160
- */
161
- readOnly?: boolean
162
- /**
163
- * Called when the user types or pastes a character that is rejected by the
164
- * current `type` or `pattern` filter.
165
- *
166
- * Receives the raw rejected character and the zero-based slot index where
167
- * entry was attempted. Use to display inline feedback such as
168
- * "Only digits are allowed" or highlight the offending slot.
169
- *
170
- * @example
171
- * onInvalidChar: (char, index) => console.warn(`Rejected "${char}" at slot ${index}`)
172
- */
173
- onInvalidChar?: (char: string, index: number) => void
174
- }
175
-
176
- /** Options for the standalone `createTimer` utility. */
177
- export type TimerOptions = {
178
- /** Total countdown duration in seconds. */
179
- totalSeconds: number
180
- /** Called every second with the remaining seconds. */
181
- onTick?: (remainingSeconds: number) => void
182
- /** Called when the countdown reaches zero. */
183
- onExpire?: () => void
184
- }
185
-
186
- /** Controls returned by `createTimer`. */
187
- export type TimerControls = {
188
- /** Start the countdown. */
189
- start: () => void
190
- /** Stop and pause the countdown. */
191
- stop: () => void
192
- /** Reset remaining time back to `totalSeconds` without starting. */
193
- reset: () => void
194
- /** Reset and immediately start again. */
195
- restart: () => void
196
- }
197
-
198
- /** Listener function invoked after every state mutation in `createDigito`. */
199
- export type StateListener = (state: DigitoState) => void
package/src/index.ts DELETED
@@ -1,50 +0,0 @@
1
- /**
2
- * digito
3
- * ─────────────────────────────────────────────────────────────────────────────
4
- * OTP input library for the modern web.
5
- * Vanilla JS · React · Vue · Svelte · Alpine · Web Components
6
- *
7
- * @author Olawale Balo — Product Designer + Design Engineer
8
- * @license MIT
9
- */
10
-
11
- // Core — pure logic, zero DOM
12
- export {
13
- createDigito,
14
- createTimer,
15
- filterChar,
16
- filterString,
17
- triggerHapticFeedback,
18
- triggerSoundFeedback,
19
- type InputType,
20
- type DigitoState,
21
- type DigitoOptions,
22
- type TimerOptions,
23
- type TimerControls,
24
- type StateListener,
25
- } from './core/index.js'
26
-
27
- // Vanilla DOM adapter
28
- export {
29
- initDigito,
30
- type DigitoInstance,
31
- } from './adapters/vanilla.js'
32
-
33
- // React hook + components
34
- export {
35
- useOTP as useOTPReact,
36
- HiddenOTPInput,
37
- type SlotRenderProps,
38
- } from './adapters/react.js'
39
-
40
- // Vue composable
41
- export { useOTP as useOTPVue } from './adapters/vue.js'
42
-
43
- // Svelte store + action
44
- export { useOTP as useOTPSvelte } from './adapters/svelte.js'
45
-
46
- // Alpine plugin
47
- export { DigitoAlpine } from './adapters/alpine.js'
48
-
49
- // Web Component
50
- export { DigitoInput } from './adapters/web-component.js'