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