@t007/input 0.0.5 → 0.0.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 OLUWATOBILOBA OKETADE
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,248 @@
1
+ # @t007/input
2
+
3
+ > An advanced, highly customizable, and fully automated vanilla JavaScript form management system. Features floating labels, automatic validation, mutation observing, and native file-size enforcement.
4
+
5
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+ [![NPM Version](https://img.shields.io/npm/v/@t007/input.svg)](https://www.npmjs.com/package/@t007/input)
7
+
8
+ [Live Demo](https://tobi007-del.github.io/t007-tools/packages/input/src/index.html) | [Report Bug](https://github.com/Tobi007-del/t007-tools/issues)
9
+
10
+ ---
11
+
12
+ ## Table of contents
13
+
14
+ - [@t007/input](#t007input)
15
+ - [Table of contents](#table-of-contents)
16
+ - [Overview](#overview)
17
+ - [Demo \& Screenshots](#demo--screenshots)
18
+ - [Features](#features)
19
+ - [Tech Stack](#tech-stack)
20
+ - [Getting Started](#getting-started)
21
+ - [Usage](#usage)
22
+ - [API Reference](#api-reference)
23
+ - [Advanced Usage](#advanced-usage)
24
+ - [Customization](#customization)
25
+ - [Author](#author)
26
+ - [Acknowledgments](#acknowledgments)
27
+ - [Star History](#star-history)
28
+
29
+ ---
30
+
31
+ ## Overview
32
+
33
+ **@t007/input** is a powerful Form Manager (FM) designed to take the pain out of HTML5 forms. It automatically handles floating labels, injects custom icons, tracks password strength, and strictly enforces validation rules (including deep file-size and mime-type checks) without requiring a massive framework.
34
+
35
+ ### Why @t007/input?
36
+
37
+ - ✅ **DOM Mutation Auto-Tracking:** Automatically initializes new inputs added to the DOM dynamically.
38
+ - ✅ **Advanced File Validation:** Built-in checks for `maxSize`, `minSize`, `maxTotalSize`, and specific MIME types.
39
+ - ✅ **Intelligent Password UX:** Ships with a built-in password strength meter, confirm-password matching, and toggleable visibility icons.
40
+ - ✅ **Zero Frameworks:** Pure vanilla JS. Drop it into React, Vue, or a static HTML site.
41
+ - ✅ **Global Injection:** Automatically attaches to `window.field` and `window.handleFormValidation` for instant legacy integration.
42
+
43
+ ---
44
+
45
+ ## Demo & Screenshots
46
+
47
+ ### Standard Input Fields
48
+ Beautiful floating labels with native error state handling.
49
+ <img src="https://raw.githubusercontent.com/Tobi007-del/t007-tools/refs/heads/main/assets/images/input_library_desktop_preview.png" alt="Desktop Preview" width="600" />
50
+
51
+ ### Mobile & Responsive State
52
+ <img src="https://raw.githubusercontent.com/Tobi007-del/t007-tools/refs/heads/main/assets/images/input_library_mobile_preview.png" alt="Mobile Preview" width="300" />
53
+
54
+ ### Form Validation in Action
55
+ <img src="https://raw.githubusercontent.com/Tobi007-del/t007-tools/refs/heads/main/assets/images/input_library_sample_1.png" alt="Validation Example 1" width="600" />
56
+ <img src="https://raw.githubusercontent.com/Tobi007-del/t007-tools/refs/heads/main/assets/images/input_library_sample_2.png" alt="Validation Example 2" width="600" />
57
+
58
+ ---
59
+
60
+ ## Features
61
+
62
+ - **Programmatic Field Generation**: Create complex DOM inputs (with icons, meters, and helpers) via a single JS object.
63
+ - **Client & Server Sync**: Supports `form.validateOnServer()` hooks before allowing submission.
64
+ - **Automatic Error Shaking**: Visual feedback (shake animation) on invalid focus-out or submit.
65
+ - **Horizontal Scroll Assist**: Built-in helper for long error messages overflowing the container.
66
+ - **Tree-Shakeable**: Import only the utilities you need.
67
+
68
+ ---
69
+
70
+ ## Tech Stack
71
+
72
+ ### Built with
73
+
74
+ - Vanilla JavaScript (ES6+)
75
+ - HTML5 Form Validation API
76
+ - MutationObserver API
77
+ - Bundled via `tsup` (ESM, CJS, IIFE outputs)
78
+
79
+ ---
80
+
81
+ ## Getting Started
82
+
83
+ ### Installation
84
+
85
+ Install via your preferred package manager:
86
+
87
+ ```bash
88
+ npm install @t007/input
89
+ # or
90
+ yarn add @t007/input
91
+ # or
92
+ pnpm add @t007/input
93
+ ````
94
+
95
+ -----
96
+
97
+ ## Usage
98
+
99
+ ### Modern Bundlers (ESM)
100
+
101
+ ```javascript
102
+ import '@t007/input/style.css';
103
+ import { field, handleFormValidation, formManager } from '@t007/input'; // also attached to window.t007
104
+
105
+ // 1. Create a complex input field programmatically
106
+ const emailInput = field({
107
+ type: 'email',
108
+ label: 'Email Address',
109
+ placeholder: 'Enter your email',
110
+ required: true,
111
+ helperText: {
112
+ info: "We'll never share your email.",
113
+ typeMismatch: "Please enter a valid email address."
114
+ }
115
+ });
116
+
117
+ // 2. Append to a form
118
+ const myForm = document.querySelector('.t007-input-form');
119
+ myForm.appendChild(emailInput);
120
+
121
+ // 3. Initialize the validation engine
122
+ handleFormValidation(myForm);
123
+ ```
124
+
125
+ ### CDN / Browser (Global)
126
+
127
+ When loaded via a `<script>` tag, the library automatically scans the DOM for forms with the class `.t007-input-form` and initializes them.
128
+
129
+ ```html
130
+ <!DOCTYPE html>
131
+ <html>
132
+ <head>
133
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/index.min.css">
134
+ </head>
135
+ <body>
136
+
137
+ <form class="t007-input-form" novalidate>
138
+ <div class="t007-input-field">
139
+ <label class="t007-input-wrapper">
140
+ <span class="t007-input-outline">
141
+ <span class="t007-input-outline-leading"></span>
142
+ <span class="t007-input-outline-notch">
143
+ <span class="t007-input-floating-label">Username</span>
144
+ </span>
145
+ <span class="t007-input-outline-trailing"></span>
146
+ </span>
147
+ <input type="text" class="t007-input" required minlength="3">
148
+ </label>
149
+ </div>
150
+ <button type="submit">Submit</button>
151
+ </form>
152
+
153
+ <script src="https://cdn.jsdelivr.net/npm/@t007/input@latest"></script>
154
+ </body>
155
+ </html>
156
+ ```
157
+
158
+ -----
159
+
160
+ ## API Reference
161
+
162
+ ### `field(config)`
163
+
164
+ Programmatically generates the complex DOM structure required for the floating labels, icons, and error states.
165
+
166
+ - **`config.type`** *(String)*: Standard HTML input type, or `"select"`, `"textarea"`.
167
+ - **`config.label`** *(String)*: The floating label text.
168
+ - **`config.placeholder`** *(String)*: Standard placeholder.
169
+ - **`config.options`** *(Array)*: Used only when `type="select"`. Array of strings or `{value, option}` objects.
170
+ - **`config.helperText`** *(Object | Boolean)*: Maps native HTML5 validity states to custom error messages.
171
+ - `info`: Default helper text.
172
+ - `valueMissing`: Shown when `required` fails.
173
+ - `typeMismatch`: Shown when email/url format fails.
174
+ - *(Set to `false` to disable the helper line entirely).*
175
+ - **`config.passwordMeter`** *(Boolean)*: Enables the 4-tier password strength bar.
176
+ - **`config.eyeToggler`** *(Boolean)*: Enables the show/hide password icons.
177
+ - **`...otherProps`**: Any standard HTML attributes (`required`, `minlength`, `disabled`) are passed directly to the input.
178
+
179
+ ### `handleFormValidation(formElement)`
180
+
181
+ Attaches the event listeners to a specific form, preventing default submission if inputs are invalid, and triggering the `.t007-input-shake` animations on errors.
182
+
183
+ ### `The Form Manager (t007.FM)`
184
+
185
+ The core object injected into the global namespace containing utility functions like `togglePasswordType`, `getFilesHelper`, and `observeDOMForFields()`.
186
+
187
+ -----
188
+
189
+ ## Advanced Usage
190
+
191
+ ### File Validation
192
+
193
+ The library extends native file inputs with custom attributes for strict size enforcement:
194
+
195
+ ```javascript
196
+ const fileUploader = field({
197
+ type: 'file',
198
+ label: 'Upload Avatar',
199
+ accept: 'image/png, image/jpeg',
200
+ multiple: true,
201
+ maxSize: 5000000, // 5MB max per file
202
+ maxTotalSize: 15000000, // 15MB max total upload
203
+ maxLength: 3 // Max 3 files allowed
204
+ });
205
+ ```
206
+
207
+ ### Password Management
208
+
209
+ Setting an input's custom attribute to `password` or `confirm_password` automatically links their validation states.
210
+
211
+ ```javascript
212
+ // Master password
213
+ field({ type: 'password', custom: 'password', label: 'Password' });
214
+
215
+ // Confirmation (Automatically errors if it doesn't match the master)
216
+ field({ type: 'password', custom: 'confirm_password', label: 'Confirm Password' });
217
+ ```
218
+
219
+ -----
220
+
221
+ ## Customization
222
+
223
+ You can deeply customize the look and feel by overriding the built-in CSS variables or targeting the specific classes.
224
+
225
+ ### Important Selectors
226
+
227
+ - `.t007-input`: The actual `<input>` element.
228
+ - `.t007-input-floating-label`: The label text.
229
+ - `.t007-input-outline`: The border wrapper holding the label.
230
+ - `[data-error]`: Attribute added dynamically on validation failure.
231
+ - `.t007-input-password-strength-meter`: The container for the 4 strength bars.
232
+
233
+ -----
234
+
235
+ ## Author
236
+
237
+ - Developer - [Oketade Oluwatobiloba (Tobi007-del)](https://github.com/Tobi007-del)
238
+ - Project - [t007-tools](https://github.com/Tobi007-del/t007-tools)
239
+
240
+ ## Acknowledgments
241
+
242
+ Built to provide a robust, dependency-free form validation engine that rivals heavyweight frontend frameworks. Part of the `@t007` utility ecosystem.
243
+
244
+ ## Star History
245
+
246
+ If you find this project useful, please consider giving it a star! ⭐
247
+
248
+ [![Star History Chart](https://api.star-history.com/svg?repos=Tobi007-del/t007-tools&type=Date)](https://github.com/Tobi007-del/t007-tools)
@@ -25,8 +25,11 @@
25
25
  for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
26
26
  }
27
27
  }
28
- function loadResource(src, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
28
+ var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
29
+ function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
29
30
  w.t007._resourceCache ??= {};
31
+ if (req === VIRTUAL_RESOURCE || "symbol" === typeof req) return Promise.resolve();
32
+ const src = req;
30
33
  if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
31
34
  const existing = type === "script" ? Array.prototype.find.call(w.document.scripts, (s) => isSameURL(s.src, src)) : type === "style" ? Array.prototype.find.call(w.document.styleSheets, (s) => isSameURL(s.href, src)) : null;
32
35
  if (existing) return w.t007._resourceCache[src] = Promise.resolve(existing);
@@ -123,12 +126,13 @@
123
126
  }
124
127
  if (typeof window !== "undefined") {
125
128
  window.t007 ??= {};
129
+ t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
126
130
  window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
127
131
  window.T007_INPUT_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest`;
128
132
  window.T007_DIALOG_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest`;
129
- window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/index.css`;
130
- window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/index.css`;
131
- window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/index.css`;
133
+ window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/index.min.css`;
134
+ window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/index.min.css`;
135
+ window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/index.min.css`;
132
136
  }
133
137
 
134
138
  // src/index.js
@@ -23,8 +23,11 @@ function assignEl(el, props, dataset, styles) {
23
23
  for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
24
24
  }
25
25
  }
26
- function loadResource(src, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
26
+ var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
27
+ function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
27
28
  w.t007._resourceCache ??= {};
29
+ if (req === VIRTUAL_RESOURCE || "symbol" === typeof req) return Promise.resolve();
30
+ const src = req;
28
31
  if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
29
32
  const existing = type === "script" ? Array.prototype.find.call(w.document.scripts, (s) => isSameURL(s.src, src)) : type === "style" ? Array.prototype.find.call(w.document.styleSheets, (s) => isSameURL(s.href, src)) : null;
30
33
  if (existing) return w.t007._resourceCache[src] = Promise.resolve(existing);
@@ -121,12 +124,13 @@ function initScrollAssist(el, { pxPerSecond = 80, assistClassName = "tmg-video-c
121
124
  }
122
125
  if (typeof window !== "undefined") {
123
126
  window.t007 ??= {};
127
+ t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
124
128
  window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
125
129
  window.T007_INPUT_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest`;
126
130
  window.T007_DIALOG_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest`;
127
- window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/index.css`;
128
- window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/index.css`;
129
- window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/index.css`;
131
+ window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/index.min.css`;
132
+ window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/index.min.css`;
133
+ window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/index.min.css`;
130
134
  }
131
135
 
132
136
  // src/index.js
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@t007/input",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "A lightweight, pure JS input system.",
5
5
  "author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/tobi007-del/t007-tools.git",
9
+ "url": "git+https://github.com/Tobi007-del/t007-tools.git",
10
10
  "directory": "packages/input"
11
11
  },
12
- "homepage": "https://github.com/tobi007-del/t007-tools/tree/main/packages/input#readme",
12
+ "homepage": "https://github.com/Tobi007-del/t007-tools/tree/main/packages/input#readme",
13
13
  "bugs": {
14
- "url": "https://github.com/tobi007-del/t007-tools/issues"
14
+ "url": "https://github.com/Tobi007-del/t007-tools/issues"
15
15
  },
16
16
  "type": "module",
17
17
  "main": "./dist/index.js",
@@ -33,24 +33,27 @@
33
33
  "./global": "./dist/index.global.js",
34
34
  "./style.css": "./dist/index.css"
35
35
  },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
36
39
  "scripts": {
37
- "build": "tsup --config ../../tsup.config.ts"
40
+ "build": "tsup --config ../../tsup.config.ts",
41
+ "prepublishOnly": "shx cp ../../LICENSE ."
38
42
  },
39
43
  "files": [
40
- "dist",
41
- "./dist/index.d.ts",
42
- "./dist/index.css"
44
+ "dist"
43
45
  ],
44
46
  "keywords": [
47
+ "t007",
48
+ "ecosystem",
49
+ "ui",
50
+ "vanilla-js",
45
51
  "input",
46
52
  "form",
47
53
  "form-validation",
48
54
  "form-manager",
49
55
  "file-upload",
50
56
  "password-meter",
51
- "t007",
52
- "ui",
53
- "vanilla-js",
54
57
  "monkey-patch"
55
58
  ],
56
59
  "dependencies": {