tiny-essentials 1.23.1 → 1.24.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/changelog/1/23/2.md +32 -0
- package/changelog/1/24/0.md +10 -0
- package/dist/v1/TinyColorValidator.min.js +1 -0
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/build/TinyColorValidator.cjs +7 -0
- package/dist/v1/build/TinyColorValidator.d.mts +3 -0
- package/dist/v1/build/TinyColorValidator.mjs +2 -0
- package/dist/v1/css/TinyLoadingScreen.min.css +1 -1
- package/dist/v1/index.cjs +2 -0
- package/dist/v1/index.d.mts +2 -1
- package/dist/v1/index.mjs +2 -1
- package/dist/v1/libs/TinyColorValidator.cjs +907 -0
- package/dist/v1/libs/TinyColorValidator.d.mts +452 -0
- package/dist/v1/libs/TinyColorValidator.mjs +853 -0
- package/dist/v1/libs/TinyHtml.cjs +42 -2
- package/dist/v1/libs/TinyHtml.d.mts +12 -0
- package/dist/v1/libs/TinyHtml.mjs +42 -2
- package/dist/v1/libs/TinyUploadClicker.cjs +1 -0
- package/docs/v1/README.md +1 -0
- package/docs/v1/libs/TinyColorValidator.md +532 -0
- package/docs/v1/libs/TinyHtmlTips.md +31 -0
- package/package.json +5 -1
|
@@ -5281,6 +5281,26 @@ class TinyHtml {
|
|
|
5281
5281
|
|
|
5282
5282
|
// TITLE: Class Stuff
|
|
5283
5283
|
|
|
5284
|
+
/** @type {boolean} */
|
|
5285
|
+
static #classCanWhitespace = false;
|
|
5286
|
+
|
|
5287
|
+
/**
|
|
5288
|
+
* Gets the value of classCanWhitespace.
|
|
5289
|
+
* @returns {boolean}
|
|
5290
|
+
*/
|
|
5291
|
+
static get classCanWhitespace() {
|
|
5292
|
+
return this.#classCanWhitespace;
|
|
5293
|
+
}
|
|
5294
|
+
|
|
5295
|
+
/**
|
|
5296
|
+
* Sets the value of classCanWhitespace.
|
|
5297
|
+
* @param {boolean} value
|
|
5298
|
+
*/
|
|
5299
|
+
static set classCanWhitespace(value) {
|
|
5300
|
+
if (typeof value !== 'boolean') throw new TypeError('classCanWhitespace must be a boolean');
|
|
5301
|
+
this.#classCanWhitespace = value;
|
|
5302
|
+
}
|
|
5303
|
+
|
|
5284
5304
|
/**
|
|
5285
5305
|
* Adds one or more CSS class names to the element.
|
|
5286
5306
|
* @template {TinyElement|TinyElement[]} T
|
|
@@ -5289,7 +5309,17 @@ class TinyHtml {
|
|
|
5289
5309
|
* @returns {T}
|
|
5290
5310
|
*/
|
|
5291
5311
|
static addClass(el, ...args) {
|
|
5292
|
-
|
|
5312
|
+
/** @type {string[]} */
|
|
5313
|
+
const classes = [];
|
|
5314
|
+
for (const name of args) {
|
|
5315
|
+
if (!TinyHtml.#classCanWhitespace) classes.push(name);
|
|
5316
|
+
else {
|
|
5317
|
+
const classesList = name.split(' ');
|
|
5318
|
+
for (const name2 of classesList) classes.push(name2);
|
|
5319
|
+
}
|
|
5320
|
+
}
|
|
5321
|
+
|
|
5322
|
+
TinyHtml._preElems(el, 'addClass').forEach((elem) => elem.classList.add(...classes));
|
|
5293
5323
|
return el;
|
|
5294
5324
|
}
|
|
5295
5325
|
|
|
@@ -5310,7 +5340,17 @@ class TinyHtml {
|
|
|
5310
5340
|
* @returns {T}
|
|
5311
5341
|
*/
|
|
5312
5342
|
static removeClass(el, ...args) {
|
|
5313
|
-
|
|
5343
|
+
/** @type {string[]} */
|
|
5344
|
+
const classes = [];
|
|
5345
|
+
for (const name of args) {
|
|
5346
|
+
if (!TinyHtml.#classCanWhitespace) classes.push(name);
|
|
5347
|
+
else {
|
|
5348
|
+
const classesList = name.split(' ');
|
|
5349
|
+
for (const name2 of classesList) classes.push(name2);
|
|
5350
|
+
}
|
|
5351
|
+
}
|
|
5352
|
+
|
|
5353
|
+
TinyHtml._preElems(el, 'removeClass').forEach((elem) => elem.classList.remove(...classes));
|
|
5314
5354
|
return el;
|
|
5315
5355
|
}
|
|
5316
5356
|
|
|
@@ -1958,6 +1958,18 @@ declare class TinyHtml<TinyHtmlT extends TinyHtmlConstructor> {
|
|
|
1958
1958
|
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) paddings, and each side individually.
|
|
1959
1959
|
*/
|
|
1960
1960
|
static padding(el: TinyElement): HtmlElBoxSides;
|
|
1961
|
+
/** @type {boolean} */
|
|
1962
|
+
static "__#8@#classCanWhitespace": boolean;
|
|
1963
|
+
/**
|
|
1964
|
+
* Sets the value of classCanWhitespace.
|
|
1965
|
+
* @param {boolean} value
|
|
1966
|
+
*/
|
|
1967
|
+
static set classCanWhitespace(value: boolean);
|
|
1968
|
+
/**
|
|
1969
|
+
* Gets the value of classCanWhitespace.
|
|
1970
|
+
* @returns {boolean}
|
|
1971
|
+
*/
|
|
1972
|
+
static get classCanWhitespace(): boolean;
|
|
1961
1973
|
/**
|
|
1962
1974
|
* Adds one or more CSS class names to the element.
|
|
1963
1975
|
* @template {TinyElement|TinyElement[]} T
|
|
@@ -4714,6 +4714,24 @@ class TinyHtml {
|
|
|
4714
4714
|
}
|
|
4715
4715
|
/////////////////////////////////////////////
|
|
4716
4716
|
// TITLE: Class Stuff
|
|
4717
|
+
/** @type {boolean} */
|
|
4718
|
+
static #classCanWhitespace = false;
|
|
4719
|
+
/**
|
|
4720
|
+
* Gets the value of classCanWhitespace.
|
|
4721
|
+
* @returns {boolean}
|
|
4722
|
+
*/
|
|
4723
|
+
static get classCanWhitespace() {
|
|
4724
|
+
return this.#classCanWhitespace;
|
|
4725
|
+
}
|
|
4726
|
+
/**
|
|
4727
|
+
* Sets the value of classCanWhitespace.
|
|
4728
|
+
* @param {boolean} value
|
|
4729
|
+
*/
|
|
4730
|
+
static set classCanWhitespace(value) {
|
|
4731
|
+
if (typeof value !== 'boolean')
|
|
4732
|
+
throw new TypeError('classCanWhitespace must be a boolean');
|
|
4733
|
+
this.#classCanWhitespace = value;
|
|
4734
|
+
}
|
|
4717
4735
|
/**
|
|
4718
4736
|
* Adds one or more CSS class names to the element.
|
|
4719
4737
|
* @template {TinyElement|TinyElement[]} T
|
|
@@ -4722,7 +4740,18 @@ class TinyHtml {
|
|
|
4722
4740
|
* @returns {T}
|
|
4723
4741
|
*/
|
|
4724
4742
|
static addClass(el, ...args) {
|
|
4725
|
-
|
|
4743
|
+
/** @type {string[]} */
|
|
4744
|
+
const classes = [];
|
|
4745
|
+
for (const name of args) {
|
|
4746
|
+
if (!TinyHtml.#classCanWhitespace)
|
|
4747
|
+
classes.push(name);
|
|
4748
|
+
else {
|
|
4749
|
+
const classesList = name.split(' ');
|
|
4750
|
+
for (const name2 of classesList)
|
|
4751
|
+
classes.push(name2);
|
|
4752
|
+
}
|
|
4753
|
+
}
|
|
4754
|
+
TinyHtml._preElems(el, 'addClass').forEach((elem) => elem.classList.add(...classes));
|
|
4726
4755
|
return el;
|
|
4727
4756
|
}
|
|
4728
4757
|
/**
|
|
@@ -4741,7 +4770,18 @@ class TinyHtml {
|
|
|
4741
4770
|
* @returns {T}
|
|
4742
4771
|
*/
|
|
4743
4772
|
static removeClass(el, ...args) {
|
|
4744
|
-
|
|
4773
|
+
/** @type {string[]} */
|
|
4774
|
+
const classes = [];
|
|
4775
|
+
for (const name of args) {
|
|
4776
|
+
if (!TinyHtml.#classCanWhitespace)
|
|
4777
|
+
classes.push(name);
|
|
4778
|
+
else {
|
|
4779
|
+
const classesList = name.split(' ');
|
|
4780
|
+
for (const name2 of classesList)
|
|
4781
|
+
classes.push(name2);
|
|
4782
|
+
}
|
|
4783
|
+
}
|
|
4784
|
+
TinyHtml._preElems(el, 'removeClass').forEach((elem) => elem.classList.remove(...classes));
|
|
4745
4785
|
return el;
|
|
4746
4786
|
}
|
|
4747
4787
|
/**
|
package/docs/v1/README.md
CHANGED
|
@@ -59,6 +59,7 @@ This folder contains the core scripts we have worked on so far. Each file is a m
|
|
|
59
59
|
- 🎲 **[TinySimpleDice](./libs/TinySimpleDice.md)** — A lightweight and flexible dice rolling utility with configurable maximum values, zero allowance, and array/Set index rolling support.
|
|
60
60
|
- 👀 **[TinyElementObserver](./libs/TinyElementObserver.md)** — A DOM mutation tracking utility built on MutationObserver, with customizable detectors for handling changes, event dispatching, and lifecycle management.
|
|
61
61
|
- ⏳ **[TinyLoadingScreen](./libs/TinyLoadingScreen.md)** — A lightweight, fully-configurable loading overlay with fade-in/out animations, custom messages (string or HTMLElement), HTML rendering option, and status-change callbacks.
|
|
62
|
+
- 🎨 **[TinyColorValidator](./libs/TinyColorValidator.md)** — A comprehensive CSS color validation and parsing utility supporting HEX, HEXA, RGB, RGBA, HSL, HSLA, HWB, Lab, LCH, standard HTML color names, and special keywords, with automatic type detection and parsing.
|
|
62
63
|
|
|
63
64
|
### 3. **`fileManager/`**
|
|
64
65
|
* 📁 **[Main](./fileManager/main.md)** — A Node.js file/directory utility module with support for JSON, backups, renaming, size analysis, and more.
|
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
# 🎨 TinyColorValidator Documentation
|
|
2
|
+
|
|
3
|
+
## 📐 Angle Units
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
/**
|
|
7
|
+
* Represents the allowed angle unit types for CSS color functions.
|
|
8
|
+
*
|
|
9
|
+
* - `deg` → Degrees (0–360).
|
|
10
|
+
* - `grad` → Gradians (0–400).
|
|
11
|
+
* - `rad` → Radians (0–2π).
|
|
12
|
+
* - `turn` → Turns (0–1).
|
|
13
|
+
*/
|
|
14
|
+
type AngleUnit = 'deg' | 'grad' | 'rad' | 'turn';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 🌈 TinyColorValidator Class
|
|
20
|
+
|
|
21
|
+
The `TinyColorValidator` class provides utilities for validating and parsing **CSS color values** in multiple formats.
|
|
22
|
+
It supports **hex, RGB/RGBA, HSL/HSLA, HWB, LAB, LCH, HTML named colors, and special keywords**.
|
|
23
|
+
|
|
24
|
+
### ✨ Features
|
|
25
|
+
|
|
26
|
+
* Validate (`isHex`, `isRgb`, `isHsl`, etc.) color formats.
|
|
27
|
+
* Parse (`parseRgb`, `parseHsl`, etc.) into numeric components.
|
|
28
|
+
* Manage and extend HTML color names and special keywords dynamically.
|
|
29
|
+
|
|
30
|
+
### 🧩 Example
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
const validator = new TinyColorValidator("rgb(255, 0, 0)");
|
|
34
|
+
|
|
35
|
+
console.log(validator.isRgb()); // true ✅
|
|
36
|
+
console.log(validator.parseRgb()); // [255, 0, 0]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 🎨 Supported Formats
|
|
42
|
+
|
|
43
|
+
* **Hexadecimal** → `#RGB`, `#RRGGBB`, `#RRGGBBAA`
|
|
44
|
+
* **RGB / RGBA** → `rgb(r, g, b)`, `rgba(r, g, b, a)`
|
|
45
|
+
* **HSL / HSLA** → `hsl(h, s%, l%)`, `hsla(h, s%, l%, a)`
|
|
46
|
+
* **HWB** → `hwb(hue whiteness% blackness%)`
|
|
47
|
+
* **LAB** → `lab(L a b)`
|
|
48
|
+
* **LCH** → `lch(L C H)`
|
|
49
|
+
* **HTML Named Colors** → e.g. `red`, `blue`, `rebeccapurple`
|
|
50
|
+
* **Special Keywords** → `transparent`, `currentColor`
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 🖌️ HTML Color Names API
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
TinyColorValidator.getNames(): string[]
|
|
58
|
+
TinyColorValidator.addName(name: string): boolean
|
|
59
|
+
TinyColorValidator.removeName(name: string): boolean
|
|
60
|
+
TinyColorValidator.hasName(name: string): boolean
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
* **`getNames()`** → Returns all HTML color names as an array.
|
|
64
|
+
* **`addName(name)`** → Adds a new HTML color name (case-insensitive).
|
|
65
|
+
* **`removeName(name)`** → Removes an existing HTML color name.
|
|
66
|
+
* **`hasName(name)`** → Checks if a given name exists.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 🌟 Special Color Names API
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
TinyColorValidator.getSpecialNames(): string[]
|
|
74
|
+
TinyColorValidator.addSpecialName(name: string): boolean
|
|
75
|
+
TinyColorValidator.removeSpecialName(name: string): boolean
|
|
76
|
+
TinyColorValidator.hasSpecialName(name: string): boolean
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
* **`getSpecialNames()`** → Returns all special keywords.
|
|
80
|
+
* **`addSpecialName(name)`** → Adds a new special keyword.
|
|
81
|
+
* **`removeSpecialName(name)`** → Removes an existing keyword.
|
|
82
|
+
* **`hasSpecialName(name)`** → Checks if the keyword exists.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 🧱 Instance Properties
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
class TinyColorValidator {
|
|
90
|
+
#code: string;
|
|
91
|
+
|
|
92
|
+
constructor(code: TinyColorValidatorT);
|
|
93
|
+
get code(): string;
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
* **`#code`** → Internal storage for the provided color string.
|
|
98
|
+
* **`get code()`** → Retrieves the original input string.
|
|
99
|
+
* **`constructor(code)`** → Creates a new validator instance with the given color string.
|
|
100
|
+
|
|
101
|
+
### 🏷️ Color Type Storage
|
|
102
|
+
|
|
103
|
+
* **Private property:** `#type`
|
|
104
|
+
* **Type:** `ColorTypes | null`
|
|
105
|
+
* **Description:** Internal storage for the detected type of the CSS color.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
/**
|
|
109
|
+
* Internal storage for the code type.
|
|
110
|
+
* @type {ColorTypes|null}
|
|
111
|
+
*/
|
|
112
|
+
#type;
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
* **Getter:** `type`
|
|
116
|
+
* **Returns:** `ColorTypes | null`
|
|
117
|
+
* **Description:** Returns the currently stored color type.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
/**
|
|
121
|
+
* Gets the current code type.
|
|
122
|
+
* @returns {ColorTypes|null} The stored code type.
|
|
123
|
+
*/
|
|
124
|
+
get type() {
|
|
125
|
+
return this.#type;
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 🎨 HEX & HEXA Validation
|
|
132
|
+
|
|
133
|
+
### 🔍 `static isHex(input: string): boolean`
|
|
134
|
+
|
|
135
|
+
Validates whether a string is a valid HEX color (`#RGB` or `#RRGGBB`).
|
|
136
|
+
|
|
137
|
+
* ✅ Returns `true` if valid.
|
|
138
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
### 🔍 `isHex(): boolean`
|
|
143
|
+
|
|
144
|
+
Instance method that validates the stored color code as a HEX color.
|
|
145
|
+
|
|
146
|
+
* ✅ Returns `true` if valid.
|
|
147
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
### 🔍 `static isHexa(input: string): boolean`
|
|
152
|
+
|
|
153
|
+
Validates whether a string is a valid HEXA color (`#RRGGBBAA`).
|
|
154
|
+
|
|
155
|
+
* ✅ Returns `true` if valid.
|
|
156
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
### 🔍 `isHexa(): boolean`
|
|
161
|
+
|
|
162
|
+
Instance method that validates the stored color code as a HEXA color.
|
|
163
|
+
|
|
164
|
+
* ✅ Returns `true` if valid.
|
|
165
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## 🎨 RGB & RGBA Validation
|
|
170
|
+
|
|
171
|
+
### 🔍 `static isRgb(input: string): boolean`
|
|
172
|
+
|
|
173
|
+
Validates whether a string is a valid RGB color.
|
|
174
|
+
|
|
175
|
+
* ✅ Returns `true` if valid.
|
|
176
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
### 🔍 `isRgb(): boolean`
|
|
181
|
+
|
|
182
|
+
Instance method that validates the stored color code as an RGB color.
|
|
183
|
+
|
|
184
|
+
* ✅ Returns `true` if valid.
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
### 🔍 `static isRgba(input: string): boolean`
|
|
189
|
+
|
|
190
|
+
Validates whether a string is a valid RGBA color.
|
|
191
|
+
|
|
192
|
+
* ✅ Returns `true` if valid.
|
|
193
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
### 🔍 `isRgba(): boolean`
|
|
198
|
+
|
|
199
|
+
Instance method that validates the stored color code as an RGBA color.
|
|
200
|
+
|
|
201
|
+
* ✅ Returns `true` if valid.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 🎨 HSL & HSLA Validation
|
|
206
|
+
|
|
207
|
+
### 🔍 `static isHsl(input: string): boolean`
|
|
208
|
+
|
|
209
|
+
Validates whether a string is a valid HSL color.
|
|
210
|
+
|
|
211
|
+
* ✅ Returns `true` if valid.
|
|
212
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
### 🔍 `isHsl(): boolean`
|
|
217
|
+
|
|
218
|
+
Instance method that validates the stored color code as an HSL color.
|
|
219
|
+
|
|
220
|
+
* ✅ Returns `true` if valid.
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
### 🔍 `static isHsla(input: string): boolean`
|
|
225
|
+
|
|
226
|
+
Validates whether a string is a valid HSLA color.
|
|
227
|
+
|
|
228
|
+
* ✅ Returns `true` if valid.
|
|
229
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
### 🔍 `isHsla(): boolean`
|
|
234
|
+
|
|
235
|
+
Instance method that validates the stored color code as an HSLA color.
|
|
236
|
+
|
|
237
|
+
* ✅ Returns `true` if valid.
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## 🎨 HWB, Lab & LCH Validation
|
|
242
|
+
|
|
243
|
+
### 🔍 `static isHwb(input: string): boolean`
|
|
244
|
+
|
|
245
|
+
Validates whether a string is a valid HWB color.
|
|
246
|
+
|
|
247
|
+
* ✅ Returns `true` if valid.
|
|
248
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
### 🔍 `isHwb(): boolean`
|
|
253
|
+
|
|
254
|
+
Instance method that validates the stored color code as an HWB color.
|
|
255
|
+
|
|
256
|
+
* ✅ Returns `true` if valid.
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
### 🔍 `static isLab(input: string): boolean`
|
|
261
|
+
|
|
262
|
+
Validates whether a string is a valid CIELAB (Lab) color.
|
|
263
|
+
|
|
264
|
+
* ✅ Returns `true` if valid.
|
|
265
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
### 🔍 `isLab(): boolean`
|
|
270
|
+
|
|
271
|
+
Instance method that validates the stored color code as a Lab color.
|
|
272
|
+
|
|
273
|
+
* ✅ Returns `true` if valid.
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
### 🔍 `static isLch(input: string): boolean`
|
|
278
|
+
|
|
279
|
+
Validates whether a string is a valid LCH color.
|
|
280
|
+
|
|
281
|
+
* ✅ Returns `true` if valid.
|
|
282
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
### 🔍 `isLch(): boolean`
|
|
287
|
+
|
|
288
|
+
Instance method that validates the stored color code as an LCH color.
|
|
289
|
+
|
|
290
|
+
* ✅ Returns `true` if valid.
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## 🎨 Named Colors
|
|
295
|
+
|
|
296
|
+
### 🔍 `static isName(input: string): boolean`
|
|
297
|
+
|
|
298
|
+
Validates whether a string matches a **standard HTML color name**.
|
|
299
|
+
|
|
300
|
+
* ✅ Returns `true` if valid.
|
|
301
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
### 🔍 `isName(): boolean`
|
|
306
|
+
|
|
307
|
+
Instance method that validates the stored color code as a **standard HTML color name**.
|
|
308
|
+
|
|
309
|
+
* ✅ Returns `true` if valid.
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
### 🔍 `static isSpecialName(input: string): boolean`
|
|
314
|
+
|
|
315
|
+
Validates whether a string matches a **special CSS color keyword** (e.g., `currentColor`, `transparent`).
|
|
316
|
+
|
|
317
|
+
* ✅ Returns `true` if valid.
|
|
318
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
### 🔍 `isSpecialName(): boolean`
|
|
323
|
+
|
|
324
|
+
Instance method that validates the stored color code as a **special CSS color keyword**.
|
|
325
|
+
|
|
326
|
+
* ✅ Returns `true` if valid.
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## 🎨 Universal Color Validation
|
|
331
|
+
|
|
332
|
+
### 🔍 `static isColor(input: string): string|null`
|
|
333
|
+
|
|
334
|
+
Checks whether a string is **any valid CSS color**, including:
|
|
335
|
+
|
|
336
|
+
* HEX / HEXA
|
|
337
|
+
|
|
338
|
+
* RGB / RGBA
|
|
339
|
+
|
|
340
|
+
* HSL / HSLA
|
|
341
|
+
|
|
342
|
+
* HWB
|
|
343
|
+
|
|
344
|
+
* Lab
|
|
345
|
+
|
|
346
|
+
* LCH
|
|
347
|
+
|
|
348
|
+
* HTML color names
|
|
349
|
+
|
|
350
|
+
* Special CSS keywords
|
|
351
|
+
|
|
352
|
+
* ✅ Returns `true` if valid.
|
|
353
|
+
|
|
354
|
+
* ⚠️ Throws `TypeError` if input is not a string.
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## 🎨 Color Parsing
|
|
359
|
+
|
|
360
|
+
### 🔍 `parse(): any[] | string | null`
|
|
361
|
+
|
|
362
|
+
Automatically parses the stored color code based on its detected type (`#type`).
|
|
363
|
+
|
|
364
|
+
* 📤 Returns numeric components for functional colors (RGB, HSL, Lab, etc.) or the lowercase string for named/special colors. Returns `null` if the code is invalid.
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
### 🔎 `static parseHex(input: string): string|null`
|
|
369
|
+
|
|
370
|
+
Parses a HEX color (`#RGB` or `#RRGGBB`).
|
|
371
|
+
|
|
372
|
+
* 📥 Input: HEX string.
|
|
373
|
+
* 📤 Output: Regex match group or `null` if invalid.
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
### 🔎 `parseHex(): string|null`
|
|
378
|
+
|
|
379
|
+
Parses the stored color code as a HEX color.
|
|
380
|
+
|
|
381
|
+
* 📤 Returns match result or `null` if invalid.
|
|
382
|
+
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
### 🔎 `static parseHexa(input: string): string|null`
|
|
386
|
+
|
|
387
|
+
Parses a HEXA color (`#RRGGBBAA`).
|
|
388
|
+
|
|
389
|
+
* 📥 Input: HEXA string.
|
|
390
|
+
* 📤 Output: Regex match group or `null` if invalid.
|
|
391
|
+
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
### 🔎 `parseHexa(): string|null`
|
|
395
|
+
|
|
396
|
+
Parses the stored color code as a HEXA color.
|
|
397
|
+
|
|
398
|
+
* 📤 Returns match result or `null` if invalid.
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
## 🎨 Parsing RGB & RGBA
|
|
403
|
+
|
|
404
|
+
### 🔎 `static parseRgb(input: string): [number, number, number]|null`
|
|
405
|
+
|
|
406
|
+
Parses an RGB color (`rgb(r, g, b)`).
|
|
407
|
+
|
|
408
|
+
* 📥 Input: RGB string.
|
|
409
|
+
* 📤 Output: `[r, g, b]` as numbers, or `null` if invalid.
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
### 🔎 `parseRgb(): [number, number, number]|null`
|
|
414
|
+
|
|
415
|
+
Parses the stored color code as an RGB color.
|
|
416
|
+
|
|
417
|
+
* 📤 Returns `[r, g, b]` or `null`.
|
|
418
|
+
|
|
419
|
+
---
|
|
420
|
+
|
|
421
|
+
### 🔎 `static parseRgba(input: string): [number, number, number, number]|null`
|
|
422
|
+
|
|
423
|
+
Parses an RGBA color (`rgba(r, g, b, a)`).
|
|
424
|
+
|
|
425
|
+
* 📥 Input: RGBA string.
|
|
426
|
+
* 📤 Output: `[r, g, b, a]` as numbers, or `null` if invalid.
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
### 🔎 `parseRgba(): [number, number, number, number]|null`
|
|
431
|
+
|
|
432
|
+
Parses the stored color code as an RGBA color.
|
|
433
|
+
|
|
434
|
+
* 📤 Returns `[r, g, b, a]` or `null`.
|
|
435
|
+
|
|
436
|
+
---
|
|
437
|
+
|
|
438
|
+
## 🎨 Parsing HSL & HSLA
|
|
439
|
+
|
|
440
|
+
### 🔎 `static parseHsl(input: string): [number, number, number]|null`
|
|
441
|
+
|
|
442
|
+
Parses an HSL color string (`hsl(h, s%, l%)`).
|
|
443
|
+
|
|
444
|
+
* 📥 Input: HSL string
|
|
445
|
+
* 📤 Output: `[h, s, l]` as numbers, or `null` if invalid
|
|
446
|
+
* ⚠️ Throws `TypeError` if input is not a string
|
|
447
|
+
|
|
448
|
+
---
|
|
449
|
+
|
|
450
|
+
### 🔎 `parseHsl(): [number, number, number]|null`
|
|
451
|
+
|
|
452
|
+
Parses the stored color code as an HSL color.
|
|
453
|
+
|
|
454
|
+
* 📤 Returns `[h, s, l]` or `null`
|
|
455
|
+
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
### 🔎 `static parseHsla(input: string): [number, number, number, number]|null`
|
|
459
|
+
|
|
460
|
+
Parses an HSLA color string (`hsla(h, s%, l%, a)`).
|
|
461
|
+
|
|
462
|
+
* 📥 Input: HSLA string
|
|
463
|
+
* 📤 Output: `[h, s, l, a]` as numbers, or `null` if invalid
|
|
464
|
+
* ⚠️ Throws `TypeError` if input is not a string
|
|
465
|
+
|
|
466
|
+
---
|
|
467
|
+
|
|
468
|
+
### 🔎 `parseHsla(): [number, number, number, number]|null`
|
|
469
|
+
|
|
470
|
+
Parses the stored color code as an HSLA color.
|
|
471
|
+
|
|
472
|
+
* 📤 Returns `[h, s, l, a]` or `null`
|
|
473
|
+
|
|
474
|
+
---
|
|
475
|
+
|
|
476
|
+
## 🎨 Parsing HWB
|
|
477
|
+
|
|
478
|
+
### 🔎 `static parseHwb(input: string): [number, AngleUnit|null, number, number]|null`
|
|
479
|
+
|
|
480
|
+
Parses an HWB color string (`hwb(hue, whiteness%, blackness%[, alpha])`).
|
|
481
|
+
|
|
482
|
+
* 📥 Input: HWB string
|
|
483
|
+
* 📤 Output: `[hue, angleUnit, whiteness, blackness]` or `null`
|
|
484
|
+
* ⚠️ Throws `TypeError` if input is not a string
|
|
485
|
+
|
|
486
|
+
---
|
|
487
|
+
|
|
488
|
+
### 🔎 `parseHwb(): [number, AngleUnit|null, number, number]|null`
|
|
489
|
+
|
|
490
|
+
Parses the stored color code as an HWB color.
|
|
491
|
+
|
|
492
|
+
* 📤 Returns `[hue, angleUnit, whiteness, blackness]` or `null`
|
|
493
|
+
|
|
494
|
+
---
|
|
495
|
+
|
|
496
|
+
## 🎨 Parsing Lab (CIELAB)
|
|
497
|
+
|
|
498
|
+
### 🔎 `static parseLab(input: string): [number, number, number]|null`
|
|
499
|
+
|
|
500
|
+
Parses a Lab color string (`lab(L a b[/alpha])`).
|
|
501
|
+
|
|
502
|
+
* 📥 Input: Lab string
|
|
503
|
+
* 📤 Output: `[L, a, b]` as numbers, or `null` if invalid
|
|
504
|
+
* ⚠️ Throws `TypeError` if input is not a string
|
|
505
|
+
|
|
506
|
+
---
|
|
507
|
+
|
|
508
|
+
### 🔎 `parseLab(): [number, number, number]|null`
|
|
509
|
+
|
|
510
|
+
Parses the stored color code as a Lab color.
|
|
511
|
+
|
|
512
|
+
* 📤 Returns `[L, a, b]` or `null`
|
|
513
|
+
|
|
514
|
+
---
|
|
515
|
+
|
|
516
|
+
## 🎨 Parsing LCH
|
|
517
|
+
|
|
518
|
+
### 🔎 `static parseLch(input: string): [number, number, number, AngleUnit|null]|null`
|
|
519
|
+
|
|
520
|
+
Parses an LCH color string (`lch(L C H[/alpha])`).
|
|
521
|
+
|
|
522
|
+
* 📥 Input: LCH string
|
|
523
|
+
* 📤 Output: `[L, C, H, angleUnit]` or `null`
|
|
524
|
+
* ⚠️ Throws `TypeError` if input is not a string
|
|
525
|
+
|
|
526
|
+
---
|
|
527
|
+
|
|
528
|
+
### 🔎 `parseLch(): [number, number, number, AngleUnit|null]|null`
|
|
529
|
+
|
|
530
|
+
Parses the stored color code as an LCH color.
|
|
531
|
+
|
|
532
|
+
* 📤 Returns `[L, C, H, angleUnit]` or `null`
|