@bornova/colorpicker 1.0.0 → 1.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.
@@ -1,45 +1,3 @@
1
- /**
2
- * Converts HSVA color values to RGBA.
3
- * @param {HSVA} hsva
4
- * @returns {RGBA}
5
- */
6
- export function HSVAtoRGBA(hsva: HSVA): RGBA;
7
- /**
8
- * Converts HSVA color values to HSLA.
9
- * @param {HSVA} hsva
10
- * @returns {HSLA}
11
- */
12
- export function HSVAtoHSLA(hsva: HSVA): HSLA;
13
- /**
14
- * Converts RGBA color values to HSVA.
15
- * @param {RGBA} rgba
16
- * @returns {HSVA}
17
- */
18
- export function RGBAtoHSVA(rgba: RGBA): HSVA;
19
- /**
20
- * Parses any valid CSS color string and returns its RGBA components.
21
- * @param {string} str - Any valid CSS color string.
22
- * @returns {RGBA}
23
- */
24
- export function strToRGBA(str: string): RGBA;
25
- /**
26
- * Converts RGBA color values to a CSS hex color string.
27
- * @param {RGBA} rgba
28
- * @returns {string} Hex color string (e.g. `#rrggbb` or `#rrggbbaa`).
29
- */
30
- export function RGBAToHex(rgba: RGBA): string;
31
- /**
32
- * Converts RGBA color values to a CSS `rgb()` or `rgba()` string.
33
- * @param {RGBA} rgba
34
- * @returns {string}
35
- */
36
- export function RGBAToStr(rgba: RGBA): string;
37
- /**
38
- * Converts HSLA color values to a CSS `hsl()` or `hsla()` string.
39
- * @param {HSLA} hsla
40
- * @returns {string}
41
- */
42
- export function HSLAToStr(hsla: HSLA): string;
43
1
  export type RGBA = {
44
2
  /**
45
3
  * - Red channel (0–255)
@@ -94,3 +52,45 @@ export type HSLA = {
94
52
  */
95
53
  a: number;
96
54
  };
55
+ /**
56
+ * Converts HSVA color values to RGBA.
57
+ * @param {HSVA} hsva
58
+ * @returns {RGBA}
59
+ */
60
+ export declare function HSVAtoRGBA(hsva: HSVA): RGBA;
61
+ /**
62
+ * Converts HSVA color values to HSLA.
63
+ * @param {HSVA} hsva
64
+ * @returns {HSLA}
65
+ */
66
+ export declare function HSVAtoHSLA(hsva: HSVA): HSLA;
67
+ /**
68
+ * Converts RGBA color values to HSVA.
69
+ * @param {RGBA} rgba
70
+ * @returns {HSVA}
71
+ */
72
+ export declare function RGBAtoHSVA(rgba: RGBA): HSVA;
73
+ /**
74
+ * Parses any valid CSS color string and returns its RGBA components.
75
+ * @param {string} str - Any valid CSS color string.
76
+ * @returns {RGBA}
77
+ */
78
+ export declare function strToRGBA(str: string): RGBA;
79
+ /**
80
+ * Converts RGBA color values to a CSS hex color string.
81
+ * @param {RGBA} rgba
82
+ * @returns {string} Hex color string (e.g. `#rrggbb` or `#rrggbbaa`).
83
+ */
84
+ export declare function RGBAToHex(rgba: RGBA): string;
85
+ /**
86
+ * Converts RGBA color values to a CSS `rgb()` or `rgba()` string.
87
+ * @param {RGBA} rgba
88
+ * @returns {string}
89
+ */
90
+ export declare function RGBAToStr(rgba: RGBA): string;
91
+ /**
92
+ * Converts HSLA color values to a CSS `hsl()` or `hsla()` string.
93
+ * @param {HSLA} hsla
94
+ * @returns {string}
95
+ */
96
+ export declare function HSLAToStr(hsla: HSLA): string;
@@ -3,7 +3,7 @@
3
3
  * @param {string} id
4
4
  * @returns {HTMLElement | null}
5
5
  */
6
- export function getEl(id: string): HTMLElement | null;
6
+ export declare function getEl(id: string): HTMLElement | null;
7
7
  /**
8
8
  * Attaches an event listener to an element, with optional CSS selector delegation.
9
9
  * @param {EventTarget} context - The element to attach the listener to.
@@ -12,11 +12,11 @@ export function getEl(id: string): HTMLElement | null;
12
12
  * @param {EventListener} [fn] - Event handler (required when `selector` is a string).
13
13
  * @returns {void}
14
14
  */
15
- export function addListener(context: EventTarget, type: string, selector: string | EventListener, fn?: EventListener): void;
15
+ export declare function addListener(context: EventTarget, type: string, selector: string | EventListener, fn?: EventListener): void;
16
16
  /**
17
17
  * Calls `fn` immediately if the DOM is ready, otherwise defers until `DOMContentLoaded`.
18
18
  * @param {Function} fn - The function to call.
19
19
  * @param {any[]} [args] - Arguments to pass to `fn`.
20
20
  * @returns {void}
21
21
  */
22
- export function DOMReady(fn: Function, args?: any[]): void;
22
+ export declare function DOMReady(fn: Function, args?: any[]): void;
@@ -1,4 +1,5 @@
1
- export default ColorPicker;
1
+ import type { ColorPickerOptions } from './settings.js';
2
+ import { DOMReady } from './dom.js';
2
3
  /**
3
4
  * Initializes the color picker, binding it to matching fields or applying global options.
4
5
  * @param {string | ColorPickerOptions} [options] - A CSS selector string to bind matching fields, or an options object.
@@ -6,13 +7,13 @@ export default ColorPicker;
6
7
  */
7
8
  declare function ColorPicker(options?: string | ColorPickerOptions): void;
8
9
  declare namespace ColorPicker {
9
- export function set(arg0: ColorPickerOptions): void;
10
- export function wrap(arg0: string | HTMLElement | HTMLElement[]): void;
11
- export function close(arg0?: boolean | undefined): void;
12
- export function setInstance(arg0: string, arg1: ColorPickerOptions): void;
13
- export function removeInstance(arg0: string): void;
14
- export function updatePosition(): void;
10
+ export var set: (options: ColorPickerOptions) => void;
11
+ export var wrap: (selector: string | HTMLElement | HTMLElement[] | NodeList) => void;
12
+ var _a: (revert?: boolean) => void;
13
+ export { _a as close };
14
+ export var setInstance: (selector: string, options: ColorPickerOptions) => void;
15
+ export var removeInstance: (selector: string) => void;
16
+ export var updatePosition: () => void;
15
17
  export { DOMReady as ready };
16
18
  }
17
- import type { ColorPickerOptions } from './settings.js';
18
- import { DOMReady } from './dom.js';
19
+ export default ColorPicker;
@@ -1,48 +1,48 @@
1
+ import type { ColorPickerOptions } from './settings.js';
1
2
  /**
2
3
  * Applies configuration options to the color picker.
3
4
  * @param {ColorPickerOptions} options
4
5
  * @returns {void}
5
6
  */
6
- export function configure(options: ColorPickerOptions): void;
7
+ export declare function configure(options: ColorPickerOptions): void;
7
8
  /**
8
9
  * Registers a virtual instance that applies custom options to fields matching a CSS selector.
9
10
  * @param {string} selector - CSS selector identifying the target field(s).
10
11
  * @param {ColorPickerOptions} options - Options to apply when the picker opens for a matching field.
11
12
  * @returns {void}
12
13
  */
13
- export function setVirtualInstance(selector: string, options: ColorPickerOptions): void;
14
+ export declare function setVirtualInstance(selector: string, options: ColorPickerOptions): void;
14
15
  /**
15
16
  * Removes a previously registered virtual instance.
16
17
  * @param {string} selector - The CSS selector of the instance to remove.
17
18
  * @returns {void}
18
19
  */
19
- export function removeVirtualInstance(selector: string): void;
20
+ export declare function removeVirtualInstance(selector: string): void;
20
21
  /**
21
22
  * Binds the color picker to one or more input fields.
22
- * @param {string | HTMLElement | HTMLElement[]} selector - A CSS selector string, a single element, or an array of elements.
23
+ * @param {string | HTMLElement | HTMLElement[] | NodeList} selector - A CSS selector string, a single element, or a list of elements.
23
24
  * @returns {void}
24
25
  */
25
- export function bindFields(selector: string | HTMLElement | HTMLElement[]): void;
26
+ export declare function bindFields(selector: string | HTMLElement | HTMLElement[] | NodeList): void;
26
27
  /**
27
28
  * Recalculates and applies the picker's position relative to the active input field.
28
29
  * @returns {void}
29
30
  */
30
- export function updatePickerPosition(): void;
31
+ export declare function updatePickerPosition(): void;
31
32
  /**
32
33
  * Wraps one or more color input fields in a `.clr-field` container with a preview button.
33
- * @param {string | HTMLElement | HTMLElement[]} selector - A CSS selector string, a single element, or an array of elements.
34
+ * @param {string | HTMLElement | HTMLElement[] | NodeList} selector - A CSS selector string, a single element, or a list of elements.
34
35
  * @returns {void}
35
36
  */
36
- export function wrapFields(selector: string | HTMLElement | HTMLElement[]): void;
37
+ export declare function wrapFields(selector: string | HTMLElement | HTMLElement[] | NodeList): void;
37
38
  /**
38
39
  * Closes the color picker, optionally reverting the color to its pre-open value.
39
40
  * @param {boolean} [revert] - If `true`, restores the field value to what it was when the picker opened.
40
41
  * @returns {void}
41
42
  */
42
- export function closePicker(revert?: boolean): void;
43
+ export declare function closePicker(revert?: boolean): void;
43
44
  /**
44
45
  * Creates the picker DOM, appends it to the document, and binds all event listeners.
45
46
  * @returns {void}
46
47
  */
47
- export function init(): void;
48
- import type { ColorPickerOptions } from './settings.js';
48
+ export declare function init(): void;
@@ -11,9 +11,71 @@
11
11
  * @property {string} swatch
12
12
  * @property {string} instruction
13
13
  */
14
+ export type A11yLabels = {
15
+ open: string;
16
+ close: string;
17
+ clear: string;
18
+ marker: string;
19
+ hueSlider: string;
20
+ alphaSlider: string;
21
+ input: string;
22
+ format: string;
23
+ swatch: string;
24
+ instruction: string;
25
+ };
26
+ export type ColorPickerOptions = {
27
+ el?: string | HTMLElement | HTMLElement[] | NodeList;
28
+ parent?: string | HTMLElement;
29
+ theme?: string;
30
+ themeMode?: 'light' | 'dark' | 'auto';
31
+ rtl?: boolean;
32
+ wrap?: boolean;
33
+ margin?: number;
34
+ format?: 'hex' | 'rgb' | 'hsl' | 'auto' | 'mixed';
35
+ formatToggle?: boolean;
36
+ swatches?: string[];
37
+ swatchesOnly?: boolean;
38
+ alpha?: boolean;
39
+ forceAlpha?: boolean;
40
+ focusInput?: boolean;
41
+ selectInput?: boolean;
42
+ inline?: boolean;
43
+ defaultColor?: string;
44
+ clearButton?: boolean;
45
+ clearLabel?: string;
46
+ closeButton?: boolean;
47
+ closeLabel?: string;
48
+ onChange?: (color: string, input?: HTMLElement) => void;
49
+ a11y?: Partial<A11yLabels>;
50
+ };
51
+ export type Settings = {
52
+ el: string;
53
+ parent: string | HTMLElement;
54
+ theme: string;
55
+ themeMode: string;
56
+ rtl: boolean;
57
+ wrap: boolean;
58
+ margin: number;
59
+ format: string;
60
+ formatToggle: boolean;
61
+ swatches: string[];
62
+ swatchesOnly: boolean;
63
+ alpha: boolean;
64
+ forceAlpha: boolean;
65
+ focusInput: boolean;
66
+ selectInput: boolean;
67
+ inline: boolean;
68
+ defaultColor: string;
69
+ clearButton: boolean;
70
+ clearLabel: string;
71
+ closeButton: boolean;
72
+ closeLabel: string;
73
+ onChange: (color: string, input?: HTMLElement) => void;
74
+ a11y: A11yLabels;
75
+ };
14
76
  /**
15
77
  * @typedef {Object} ColorPickerOptions
16
- * @property {string|HTMLElement|HTMLElement[]} [el]
78
+ * @property {string|HTMLElement|HTMLElement[]|NodeList} [el]
17
79
  * @property {string|HTMLElement} [parent]
18
80
  * @property {string} [theme]
19
81
  * @property {'light'|'dark'|'auto'} [themeMode]
@@ -30,17 +92,17 @@
30
92
  * @property {boolean} [selectInput]
31
93
  * @property {boolean} [inline]
32
94
  * @property {string} [defaultColor]
33
- * @property {boolean|{show: boolean, label: string}} [clearButton]
95
+ * @property {boolean} [clearButton]
34
96
  * @property {string} [clearLabel]
35
97
  * @property {boolean} [closeButton]
36
98
  * @property {string} [closeLabel]
37
- * @property {function(string, HTMLElement=): void} [onChange]
99
+ * @property {(color: string, input?: HTMLElement) => void} [onChange]
38
100
  * @property {Partial<A11yLabels>} [a11y]
39
101
  */
40
102
  /**
41
103
  * @typedef {Object} Settings
42
104
  * @property {string} el
43
- * @property {string} parent
105
+ * @property {string|HTMLElement} parent
44
106
  * @property {string} theme
45
107
  * @property {string} themeMode
46
108
  * @property {boolean} rtl
@@ -60,73 +122,8 @@
60
122
  * @property {string} clearLabel
61
123
  * @property {boolean} closeButton
62
124
  * @property {string} closeLabel
63
- * @property {function(string, HTMLElement=): void} onChange
125
+ * @property {(color: string, input?: HTMLElement) => void} onChange
64
126
  * @property {A11yLabels} a11y
65
127
  */
66
128
  /** @type {Settings} */
67
- export const settings: Settings;
68
- export type A11yLabels = {
69
- open: string;
70
- close: string;
71
- clear: string;
72
- marker: string;
73
- hueSlider: string;
74
- alphaSlider: string;
75
- input: string;
76
- format: string;
77
- swatch: string;
78
- instruction: string;
79
- };
80
- export type ColorPickerOptions = {
81
- el?: string | HTMLElement | HTMLElement[] | undefined;
82
- parent?: string | HTMLElement | undefined;
83
- theme?: string | undefined;
84
- themeMode?: "auto" | "light" | "dark" | undefined;
85
- rtl?: boolean | undefined;
86
- wrap?: boolean | undefined;
87
- margin?: number | undefined;
88
- format?: "auto" | "rgb" | "hex" | "hsl" | "mixed" | undefined;
89
- formatToggle?: boolean | undefined;
90
- swatches?: string[] | undefined;
91
- swatchesOnly?: boolean | undefined;
92
- alpha?: boolean | undefined;
93
- forceAlpha?: boolean | undefined;
94
- focusInput?: boolean | undefined;
95
- selectInput?: boolean | undefined;
96
- inline?: boolean | undefined;
97
- defaultColor?: string | undefined;
98
- clearButton?: boolean | {
99
- show: boolean;
100
- label: string;
101
- } | undefined;
102
- clearLabel?: string | undefined;
103
- closeButton?: boolean | undefined;
104
- closeLabel?: string | undefined;
105
- onChange?: ((arg0: string, arg1?: HTMLElement | undefined) => void) | undefined;
106
- a11y?: Partial<A11yLabels> | undefined;
107
- };
108
- export type Settings = {
109
- el: string;
110
- parent: string;
111
- theme: string;
112
- themeMode: string;
113
- rtl: boolean;
114
- wrap: boolean;
115
- margin: number;
116
- format: string;
117
- formatToggle: boolean;
118
- swatches: string[];
119
- swatchesOnly: boolean;
120
- alpha: boolean;
121
- forceAlpha: boolean;
122
- focusInput: boolean;
123
- selectInput: boolean;
124
- inline: boolean;
125
- defaultColor: string;
126
- clearButton: boolean;
127
- clearLabel: string;
128
- closeButton: boolean;
129
- closeLabel: string;
130
- onChange: (arg0: string, arg1: HTMLElement | undefined) => void;
131
- a11y: A11yLabels;
132
- };
129
+ export declare const settings: Settings;
package/package.json CHANGED
@@ -1,51 +1,56 @@
1
- {
2
- "name": "@bornova/colorpicker",
3
- "version": "1.0.0",
4
- "description": "A lightweight and elegant JavaScript color picker written in vanilla JavaScript. Zero dependencies.",
5
- "keywords": [
6
- "color",
7
- "picker",
8
- "javascript"
9
- ],
10
- "homepage": "https://github.com/bornova/ColorPicker#readme",
11
- "bugs": {
12
- "url": "https://github.com/bornova/ColorPicker/issues"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/bornova/ColorPicker.git"
17
- },
18
- "license": "MIT",
19
- "type": "module",
20
- "exports": {
21
- ".": {
22
- "types": "./dist/types/index.d.ts",
23
- "import": "./dist/esm/colorpicker.js"
24
- }
25
- },
26
- "jsdelivr": "./dist/browser/colorpicker.min.js",
27
- "unpkg": "./dist/browser/colorpicker.min.js",
28
- "types": "./dist/types/index.d.ts",
29
- "files": [
30
- "dist"
31
- ],
32
- "scripts": {
33
- "prebuild": "npm run lint && npm run prettier",
34
- "build": "rollup -c && npm run types",
35
- "format": "npm run prettier:fix && npm run lint:fix",
36
- "lint": "eslint .",
37
- "lint:fix": "eslint --fix .",
38
- "prettier": "prettier --check .",
39
- "prettier:fix": "prettier --write .",
40
- "types": "tsc"
41
- },
42
- "devDependencies": {
43
- "@eslint/js": "^10.0.1",
44
- "@rollup/plugin-terser": "^1.0.0",
45
- "eslint": "^10.4.0",
46
- "globals": "^17.6.0",
47
- "prettier": "^3.8.3",
48
- "rollup": "^4.60.4",
49
- "typescript": "^6.0.3"
50
- }
51
- }
1
+ {
2
+ "name": "@bornova/colorpicker",
3
+ "version": "1.1.0",
4
+ "description": "A lightweight and elegant JavaScript color picker written in vanilla JavaScript. Zero dependencies.",
5
+ "keywords": [
6
+ "color",
7
+ "picker",
8
+ "javascript",
9
+ "colorpicker"
10
+ ],
11
+ "homepage": "https://github.com/bornova/ColorPicker#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/bornova/ColorPicker/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/bornova/ColorPicker.git"
18
+ },
19
+ "license": "MIT",
20
+ "type": "module",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/types/index.d.ts",
24
+ "import": "./dist/esm/colorpicker.js"
25
+ },
26
+ "./colorpicker.css": "./dist/colorpicker.css",
27
+ "./dist/colorpicker.css": "./dist/colorpicker.css"
28
+ },
29
+ "style": "./dist/colorpicker.css",
30
+ "jsdelivr": "./dist/browser/colorpicker.min.js",
31
+ "unpkg": "./dist/browser/colorpicker.min.js",
32
+ "types": "./dist/types/index.d.ts",
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "scripts": {
37
+ "prebuild": "npm run lint && npm run prettier && npm test",
38
+ "build": "rollup -c && npm run types",
39
+ "format": "npm run prettier:fix && npm run lint:fix",
40
+ "lint": "eslint .",
41
+ "lint:fix": "eslint --fix .",
42
+ "prettier": "prettier --check .",
43
+ "prettier:fix": "prettier --write .",
44
+ "test": "node --test",
45
+ "types": "tsc"
46
+ },
47
+ "devDependencies": {
48
+ "@eslint/js": "^10.0.1",
49
+ "@rollup/plugin-terser": "^1.0.2",
50
+ "eslint": "^10.14.0",
51
+ "globals": "^17.14.0",
52
+ "prettier": "^3.9.10",
53
+ "rollup": "^4.68.0",
54
+ "typescript": "^7.0.2"
55
+ }
56
+ }