@spectrum-web-components/reactive-controllers 1.2.0-beta.13 → 1.2.0-beta.15
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/README.md +1 -1
- package/package.json +7 -6
- package/src/ColorController.d.ts +219 -0
- package/src/ColorController.dev.js +455 -0
- package/src/ColorController.dev.js.map +7 -0
- package/src/ColorController.js +2 -0
- package/src/ColorController.js.map +7 -0
- package/test/color-controller.test.js +208 -0
- package/test/color-controller.test.js.map +7 -0
- package/src/Color.d.ts +0 -46
- package/src/Color.dev.js +0 -198
- package/src/Color.dev.js.map +0 -7
- package/src/Color.js +0 -2
- package/src/Color.js.map +0 -7
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/reactive-controllers",
|
|
3
|
-
"version": "1.2.0-beta.
|
|
3
|
+
"version": "1.2.0-beta.15",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"default": "./src/index.js"
|
|
26
26
|
},
|
|
27
27
|
"./package.json": "./package.json",
|
|
28
|
-
"./src/
|
|
29
|
-
"development": "./src/
|
|
30
|
-
"default": "./src/
|
|
28
|
+
"./src/ColorController.js": {
|
|
29
|
+
"development": "./src/ColorController.dev.js",
|
|
30
|
+
"default": "./src/ColorController.js"
|
|
31
31
|
},
|
|
32
32
|
"./src/DependencyManger.js": {
|
|
33
33
|
"development": "./src/DependencyManger.dev.js",
|
|
@@ -84,7 +84,8 @@
|
|
|
84
84
|
"reactive controllers"
|
|
85
85
|
],
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@spectrum-web-components/progress-circle": "^1.2.0-beta.
|
|
87
|
+
"@spectrum-web-components/progress-circle": "^1.2.0-beta.15",
|
|
88
|
+
"colorjs.io": "^0.5.2",
|
|
88
89
|
"lit": "^2.5.0 || ^3.1.3"
|
|
89
90
|
},
|
|
90
91
|
"types": "./src/index.d.ts",
|
|
@@ -92,5 +93,5 @@
|
|
|
92
93
|
"sideEffects": [
|
|
93
94
|
"./**/*.dev.js"
|
|
94
95
|
],
|
|
95
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "5c0f2503090b66781f578b2485d9bde4f4984730"
|
|
96
97
|
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import type { ReactiveElement } from 'lit';
|
|
2
|
+
import Color from 'colorjs.io';
|
|
3
|
+
import type { ColorObject, ColorTypes as DefaultColorTypes } from 'colorjs.io/types/src/color';
|
|
4
|
+
import type ColorSpace from 'colorjs.io/types/src/space';
|
|
5
|
+
/**
|
|
6
|
+
* Represents various color types that can be used in the application.
|
|
7
|
+
*
|
|
8
|
+
* This type can be one of the following:
|
|
9
|
+
* - `DefaultColorTypes`: A predefined set of color types.
|
|
10
|
+
* - An object representing an RGBA color with properties:
|
|
11
|
+
* - `r`: Red component, can be a number or string.
|
|
12
|
+
* - `g`: Green component, can be a number or string.
|
|
13
|
+
* - `b`: Blue component, can be a number or string.
|
|
14
|
+
* - `a` (optional): Alpha component, can be a number or string.
|
|
15
|
+
* - An object representing an HSLA color with properties:
|
|
16
|
+
* - `h`: Hue component, can be a number or string.
|
|
17
|
+
* - `s`: Saturation component, can be a number or string.
|
|
18
|
+
* - `l`: Lightness component, can be a number or string.
|
|
19
|
+
* - `a` (optional): Alpha component, can be a number or string.
|
|
20
|
+
* - An object representing an HSVA color with properties:
|
|
21
|
+
* - `h`: Hue component, can be a number or string.
|
|
22
|
+
* - `s`: Saturation component, can be a number or string.
|
|
23
|
+
* - `v`: Value component, can be a number or string.
|
|
24
|
+
* - `a` (optional): Alpha component, can be a number or string.
|
|
25
|
+
*/
|
|
26
|
+
type ColorTypes = DefaultColorTypes | {
|
|
27
|
+
r: number | string;
|
|
28
|
+
g: number | string;
|
|
29
|
+
b: number | string;
|
|
30
|
+
a?: number | string;
|
|
31
|
+
} | {
|
|
32
|
+
h: number | string;
|
|
33
|
+
s: number | string;
|
|
34
|
+
l: number | string;
|
|
35
|
+
a?: number | string;
|
|
36
|
+
} | {
|
|
37
|
+
h: number | string;
|
|
38
|
+
s: number | string;
|
|
39
|
+
v: number | string;
|
|
40
|
+
a?: number | string;
|
|
41
|
+
};
|
|
42
|
+
export type { Color, ColorTypes };
|
|
43
|
+
type ColorValidationResult = {
|
|
44
|
+
spaceId: string | null;
|
|
45
|
+
coords: number[];
|
|
46
|
+
isValid: boolean;
|
|
47
|
+
alpha: number;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* The `ColorController` class is responsible for managing and validating color values
|
|
51
|
+
* in various color spaces (RGB, HSL, HSV, Hex). It provides methods to set, get, and
|
|
52
|
+
* validate colors, as well as convert between different color formats.
|
|
53
|
+
*
|
|
54
|
+
* @class
|
|
55
|
+
* @property {Color} color - Gets or sets the current color value.
|
|
56
|
+
* @property {ColorTypes} colorValue - Gets the color value in various formats based on the original color input.
|
|
57
|
+
* @property {number} hue - Gets or sets the hue value of the current color.
|
|
58
|
+
*
|
|
59
|
+
* @method validateColorString(color: string): ColorValidationResult - Validates a color string and returns the validation result.
|
|
60
|
+
* @method getColor(format: string | ColorSpace): ColorObject - Converts the current color to the specified format.
|
|
61
|
+
* @method getHslString(): string - Returns the current color in HSL string format.
|
|
62
|
+
* @method savePreviousColor(): void - Saves the current color as the previous color.
|
|
63
|
+
* @method restorePreviousColor(): void - Restores the previous color.
|
|
64
|
+
*
|
|
65
|
+
* @constructor
|
|
66
|
+
* @param {ReactiveElement} host - The host element that uses this controller.
|
|
67
|
+
* @param {Object} [options] - Optional configuration options.
|
|
68
|
+
* @param {string} [options.manageAs] - Specifies the color space to manage the color as.
|
|
69
|
+
*/
|
|
70
|
+
export declare class ColorController {
|
|
71
|
+
get color(): Color;
|
|
72
|
+
/**
|
|
73
|
+
* Validates a color string and returns a result indicating the color space,
|
|
74
|
+
* coordinates, alpha value, and whether the color is valid.
|
|
75
|
+
*
|
|
76
|
+
* @param color - The color string to validate. Supported formats include:
|
|
77
|
+
* - RGB: `rgb(r, g, b)`, `rgba(r, g, b, a)`, `rgb r g b`, `rgba r g b a`
|
|
78
|
+
* - HSL: `hsl(h, s, l)`, `hsla(h, s, l, a)`, `hsl h s l`, `hsla h s l a`
|
|
79
|
+
* - HSV: `hsv(h, s, v)`, `hsva(h, s, v, a)`, `hsv h s v`, `hsva h s v a`
|
|
80
|
+
* - HEX: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`
|
|
81
|
+
*
|
|
82
|
+
* @returns An object containing the following properties:
|
|
83
|
+
* - `spaceId`: The color space identifier (`'srgb'`, `'hsl'`, or `'hsv'`).
|
|
84
|
+
* - `coords`: An array of numeric values representing the color coordinates.
|
|
85
|
+
* - `alpha`: The alpha value of the color (0 to 1).
|
|
86
|
+
* - `isValid`: A boolean indicating whether the color string is valid.
|
|
87
|
+
*/
|
|
88
|
+
validateColorString(color: string): ColorValidationResult;
|
|
89
|
+
/**
|
|
90
|
+
* Represents the color state of the component.
|
|
91
|
+
* Initialized with an HSV color model with hue 0, saturation 100, and value 100, and an alpha value of 1.
|
|
92
|
+
*
|
|
93
|
+
* @private
|
|
94
|
+
* @type {Color}
|
|
95
|
+
*/
|
|
96
|
+
private _color;
|
|
97
|
+
/**
|
|
98
|
+
* Represents the original color value provided by the user.
|
|
99
|
+
*
|
|
100
|
+
* @private
|
|
101
|
+
* @type {ColorTypes}
|
|
102
|
+
*/
|
|
103
|
+
private _colorOrigin;
|
|
104
|
+
/**
|
|
105
|
+
* Gets the original color value provided by the user.
|
|
106
|
+
*
|
|
107
|
+
* @returns {ColorTypes} The original color value.
|
|
108
|
+
*/
|
|
109
|
+
get colorOrigin(): ColorTypes;
|
|
110
|
+
/**
|
|
111
|
+
* Sets the original color value provided by the user.
|
|
112
|
+
*
|
|
113
|
+
* @param {ColorTypes} colorOrigin - The original color value to set.
|
|
114
|
+
*/
|
|
115
|
+
set colorOrigin(colorOrigin: ColorTypes);
|
|
116
|
+
/**
|
|
117
|
+
* An optional string property that specifies how the color should be managed(its value is the name of color space in which color object will be managed).
|
|
118
|
+
* This property can be used to define a specific management strategy or identifier.
|
|
119
|
+
*/
|
|
120
|
+
private manageAs?;
|
|
121
|
+
/**
|
|
122
|
+
* Stores the previous color value.
|
|
123
|
+
* This is used to keep track of the color before any changes are made.
|
|
124
|
+
*
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
127
|
+
private _previousColor;
|
|
128
|
+
/**
|
|
129
|
+
* Sets the color value for the controller. The color can be provided in various formats:
|
|
130
|
+
* - A string representing a color name, hex code, or other color format.
|
|
131
|
+
* - An instance of the `Color` class.
|
|
132
|
+
* - An object containing color properties such as `h`, `s`, `l`, `v`, `r`, `g`, `b`, and optionally `a`.
|
|
133
|
+
*
|
|
134
|
+
* The method validates and parses the input color, converting it to a `Color` instance.
|
|
135
|
+
* If the color is invalid, it attempts to parse it as a hex code or returns without setting a new color.
|
|
136
|
+
*
|
|
137
|
+
* @param {ColorTypes} color - The color value to set. It can be a string, an instance of `Color`, or an object with color properties.
|
|
138
|
+
*/
|
|
139
|
+
set color(color: ColorTypes);
|
|
140
|
+
/**
|
|
141
|
+
* Gets the color value in various formats based on the original color input.
|
|
142
|
+
*
|
|
143
|
+
* The method determines the color space of the original color input and converts
|
|
144
|
+
* the color to the appropriate format. The supported color spaces are:
|
|
145
|
+
* - HSV (Hue, Saturation, Value)
|
|
146
|
+
* - HSL (Hue, Saturation, Lightness)
|
|
147
|
+
* - Hexadecimal (with or without alpha)
|
|
148
|
+
* - RGB (Red, Green, Blue) with optional alpha
|
|
149
|
+
*
|
|
150
|
+
* @returns {ColorTypes} The color value in the appropriate format.
|
|
151
|
+
*
|
|
152
|
+
* The method handles the following cases:
|
|
153
|
+
* - If the original color input is a string, it checks the prefix to determine the color space.
|
|
154
|
+
* - If the original color input is an object, it checks the properties to determine the color space.
|
|
155
|
+
* - If the original color input is not provided, it defaults to the current color space of the color object.
|
|
156
|
+
*
|
|
157
|
+
* The returned color value can be in one of the following formats:
|
|
158
|
+
* - `hsv(h, s%, v%)` or `hsva(h, s%, v%, a)`
|
|
159
|
+
* - `hsl(h, s%, l%)` or `hsla(h, s%, l%, a)`
|
|
160
|
+
* - `#rrggbb` or `#rrggbbaa`
|
|
161
|
+
* - `rgb(r, g, b)` or `rgba(r, g, b, a)`
|
|
162
|
+
* - `{ h, s, v, a }` for HSV object
|
|
163
|
+
* - `{ h, s, l, a }` for HSL object
|
|
164
|
+
* - `{ r, g, b, a }` for RGB object
|
|
165
|
+
*/
|
|
166
|
+
get colorValue(): ColorTypes;
|
|
167
|
+
protected host: ReactiveElement;
|
|
168
|
+
/**
|
|
169
|
+
* Gets the hue value of the current color in HSL format.
|
|
170
|
+
*
|
|
171
|
+
* @returns {number} The hue value as a number.
|
|
172
|
+
*/
|
|
173
|
+
get hue(): number;
|
|
174
|
+
/**
|
|
175
|
+
* Sets the hue value of the color and requests an update from the host.
|
|
176
|
+
*
|
|
177
|
+
* @param hue - The hue value to set, represented as a number.
|
|
178
|
+
*/
|
|
179
|
+
set hue(hue: number);
|
|
180
|
+
/**
|
|
181
|
+
* Creates an instance of ColorController.
|
|
182
|
+
*
|
|
183
|
+
* @param host - The ReactiveElement that this controller is associated with.
|
|
184
|
+
* @param options - An object containing optional parameters.
|
|
185
|
+
* @param options.manageAs - A string to manage the controller as a specific type.
|
|
186
|
+
*/
|
|
187
|
+
constructor(host: ReactiveElement, { manageAs, }?: {
|
|
188
|
+
manageAs?: string;
|
|
189
|
+
});
|
|
190
|
+
/**
|
|
191
|
+
* Converts the current color to the specified format.
|
|
192
|
+
*
|
|
193
|
+
* @param format - The desired color format. It can be a string representing one of the valid formats
|
|
194
|
+
* ('srgb', 'hsva', 'hsv', 'hsl', 'hsla') or a ColorSpace object.
|
|
195
|
+
* @returns The color object in the specified format.
|
|
196
|
+
* @throws Will throw an error if the provided format is not a valid string format.
|
|
197
|
+
*/
|
|
198
|
+
getColor(format: string | ColorSpace): ColorObject;
|
|
199
|
+
/**
|
|
200
|
+
* Converts the current color to an HSL string representation.
|
|
201
|
+
*
|
|
202
|
+
* @returns {string} The HSL string representation of the current color.
|
|
203
|
+
*/
|
|
204
|
+
getHslString(): string;
|
|
205
|
+
/**
|
|
206
|
+
* Saves the current color state by cloning the current color and storing it
|
|
207
|
+
* as the previous color. This allows for the ability to revert to the previous
|
|
208
|
+
* color state if needed.
|
|
209
|
+
*
|
|
210
|
+
* @returns {void}
|
|
211
|
+
*/
|
|
212
|
+
savePreviousColor(): void;
|
|
213
|
+
/**
|
|
214
|
+
* Restores the color to the previously saved color value.
|
|
215
|
+
*
|
|
216
|
+
* This method sets the current color (`_color`) to the previously stored color (`_previousColor`).
|
|
217
|
+
*/
|
|
218
|
+
restorePreviousColor(): void;
|
|
219
|
+
}
|