@electrovir/color 1.7.11 → 2.0.0-beta.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/dist/data/color-class/color.d.ts +2 -1
- package/dist/data/color-class/color.js +9 -9
- package/dist/data/contrast/contrast.js +6 -4
- package/dist/demo/all-book-pages.js +1 -10
- package/dist/demo/top-level-pages.d.ts +0 -1
- package/dist/demo/top-level-pages.js +0 -4
- package/dist/demo/vir-demo.element.js +5 -3
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -10
- package/package.json +27 -29
- package/dist/data/local-storage.client.d.ts +0 -4
- package/dist/data/local-storage.client.js +0 -6
- package/dist/elements/vir-all-color-space-sliders.element.d.ts +0 -11
- package/dist/elements/vir-all-color-space-sliders.element.js +0 -53
- package/dist/elements/vir-all-spaces-color-picker.element.d.ts +0 -15
- package/dist/elements/vir-all-spaces-color-picker.element.js +0 -69
- package/dist/elements/vir-color-details.element.d.ts +0 -14
- package/dist/elements/vir-color-details.element.js +0 -151
- package/dist/elements/vir-color-format-sliders.element.d.ts +0 -14
- package/dist/elements/vir-color-format-sliders.element.js +0 -58
- package/dist/elements/vir-color-pair-contrast-summary.element.d.ts +0 -9
- package/dist/elements/vir-color-pair-contrast-summary.element.js +0 -307
- package/dist/elements/vir-color-pair.element.d.ts +0 -17
- package/dist/elements/vir-color-pair.element.js +0 -197
- package/dist/elements/vir-color-picker.element.d.ts +0 -20
- package/dist/elements/vir-color-picker.element.js +0 -270
- package/dist/elements/vir-color-slider.element.d.ts +0 -14
- package/dist/elements/vir-color-slider.element.js +0 -118
- package/dist/elements/vir-color-swatch.element.d.ts +0 -20
- package/dist/elements/vir-color-swatch.element.js +0 -48
- package/dist/elements/vir-contrast-indicator.element.d.ts +0 -10
- package/dist/elements/vir-contrast-indicator.element.js +0 -96
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type PartialWithUndefined, type RequireExactlyOne } from '@augment-vir/common';
|
|
2
|
+
import { type Color as CuloriColor } from 'culori';
|
|
2
3
|
import { ColorFormatName, ColorSyntaxName, type ColorCoordsByFormat, type ColorValue, type HexColor } from './color-formats.js';
|
|
3
4
|
/**
|
|
4
5
|
* An update to an existing {@link Color} instance. Used in {@link Color.set}.
|
|
@@ -42,7 +43,6 @@ export type SerializedColor = AllColorsValues & {
|
|
|
42
43
|
* @category Color
|
|
43
44
|
*/
|
|
44
45
|
export declare class Color {
|
|
45
|
-
#private;
|
|
46
46
|
constructor(
|
|
47
47
|
/** Any valid CSS color string or an object of color coordinate values. */
|
|
48
48
|
initValue: string | Readonly<ColorUpdate>);
|
|
@@ -66,6 +66,7 @@ export declare class Color {
|
|
|
66
66
|
toString(): string;
|
|
67
67
|
/** The color syntax the this color was set with. */
|
|
68
68
|
protected originalColorSyntax: ColorSyntaxName;
|
|
69
|
+
protected internalColor: CuloriColor;
|
|
69
70
|
/** All current color values. These are updated whenever {@link Color.set} is called. */
|
|
70
71
|
protected readonly _allColors: {
|
|
71
72
|
names: string[];
|
|
@@ -42,7 +42,7 @@ export class Color {
|
|
|
42
42
|
*/
|
|
43
43
|
static deserialize(input) {
|
|
44
44
|
const parsed = JSON.parse(input);
|
|
45
|
-
const newColor = new Color(
|
|
45
|
+
const newColor = new Color(parsed.hexString);
|
|
46
46
|
getObjectTypedEntries(parsed).forEach(([key, value,]) => {
|
|
47
47
|
if (key === 'originalColorSyntax') {
|
|
48
48
|
newColor.originalColorSyntax = assertWrap.isEnumValue(value, ColorSyntaxName, 'Cannot deserialize: invalid color syntax.');
|
|
@@ -55,7 +55,7 @@ export class Color {
|
|
|
55
55
|
}
|
|
56
56
|
/** Get the distance from this Color class instance to the given CSS color string. */
|
|
57
57
|
getRgbDistance(distanceFrom) {
|
|
58
|
-
return distanceRgb(this
|
|
58
|
+
return distanceRgb(this.internalColor, distanceFrom);
|
|
59
59
|
}
|
|
60
60
|
/** Get the closest named CSS color to this Color class instance's current color. */
|
|
61
61
|
getClosestNamedColor() {
|
|
@@ -84,7 +84,7 @@ export class Color {
|
|
|
84
84
|
}
|
|
85
85
|
/** The color syntax the this color was set with. */
|
|
86
86
|
originalColorSyntax = ColorSyntaxName.hex;
|
|
87
|
-
|
|
87
|
+
internalColor = assertWrap.isDefined(parse('black'));
|
|
88
88
|
/** All current color values. These are updated whenever {@link Color.set} is called. */
|
|
89
89
|
_allColors = {
|
|
90
90
|
names: ['black'],
|
|
@@ -146,7 +146,7 @@ export class Color {
|
|
|
146
146
|
throw new Error(`Unable to parse invalid color string: '${cssColorString}'`);
|
|
147
147
|
}
|
|
148
148
|
this.originalColorSyntax = getColorSyntaxFromCssString(cssColorString);
|
|
149
|
-
this
|
|
149
|
+
this.internalColor = newColor;
|
|
150
150
|
this.pullFromInternalColor();
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
@@ -186,15 +186,15 @@ export class Color {
|
|
|
186
186
|
getEnumValues(ColorFormatName).forEach((colorFormatName) => {
|
|
187
187
|
const colorFormatDefinition = colorFormats[colorFormatName];
|
|
188
188
|
const mappedColorFormatName = colorFormatDefinition.conversionFormat;
|
|
189
|
-
const originalColorDefinition = check.isKeyOf(this
|
|
190
|
-
? colorFormats[this
|
|
189
|
+
const originalColorDefinition = check.isKeyOf(this.internalColor.mode, colorFormats)
|
|
190
|
+
? colorFormats[this.internalColor.mode]
|
|
191
191
|
: undefined;
|
|
192
192
|
const converted = clampGamut(colorFormatDefinition.colorSpace === originalColorDefinition?.colorSpace
|
|
193
193
|
? mappedColorFormatName
|
|
194
|
-
: 'rgb')(converter(mappedColorFormatName)(this
|
|
194
|
+
: 'rgb')(converter(mappedColorFormatName)(this.internalColor));
|
|
195
195
|
/* node:coverage ignore next 5: technically this shouldn't happen, idk how to manually trigger it. */
|
|
196
196
|
if (!converted) {
|
|
197
|
-
assert.never(`Failed to convert color '${JSON.stringify(this
|
|
197
|
+
assert.never(`Failed to convert color '${JSON.stringify(this.internalColor)}' to '${colorFormatName}'.`);
|
|
198
198
|
}
|
|
199
199
|
getObjectTypedKeys(this[colorFormatName]).forEach((coordName) => {
|
|
200
200
|
const coordValue = converted[coordName];
|
|
@@ -206,7 +206,7 @@ export class Color {
|
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
208
|
});
|
|
209
|
-
this._allColors.hexString = formatHex(this
|
|
209
|
+
this._allColors.hexString = formatHex(this.internalColor);
|
|
210
210
|
this._allColors.names = findMatchingColorNames(this.rgb);
|
|
211
211
|
this._allColors[ColorSyntaxName.name] = this._allColors.names[0] || '';
|
|
212
212
|
}
|
|
@@ -30,10 +30,12 @@ export const FontWeightName = mapObjectValues(fontWeightByName, (key) => key);
|
|
|
30
30
|
*
|
|
31
31
|
* @category Internal
|
|
32
32
|
*/
|
|
33
|
-
export const fontWeightToName = Object.fromEntries(Object.entries(fontWeightByName).map(([key, value,]) =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
export const fontWeightToName = Object.fromEntries(Object.entries(fontWeightByName).map(([key, value,]) => {
|
|
34
|
+
return [
|
|
35
|
+
value,
|
|
36
|
+
key,
|
|
37
|
+
];
|
|
38
|
+
}));
|
|
37
39
|
/** Cache for contrast calculations to avoid redundant computation. */
|
|
38
40
|
const contrastCache = new Map();
|
|
39
41
|
/**
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import { virAllSpacesColorPickerBookPage } from '../elements/vir-all-spaces-color-picker.element.book.js';
|
|
2
|
-
import { virColorPairContrastSummaryBookPage } from '../elements/vir-color-pair-contrast-summary.element.book.js';
|
|
3
|
-
import { virColorPairBookPage } from '../elements/vir-color-pair.element.book.js';
|
|
4
|
-
import { virColorPickerBookPage } from '../elements/vir-color-picker.element.book.js';
|
|
5
1
|
import { colorExamplesPage } from './color-examples.book.js';
|
|
6
|
-
import {
|
|
2
|
+
import { examplesBookPage } from './top-level-pages.js';
|
|
7
3
|
export const allBookPages = [
|
|
8
|
-
elementsBookPage,
|
|
9
4
|
examplesBookPage,
|
|
10
5
|
colorExamplesPage,
|
|
11
|
-
virAllSpacesColorPickerBookPage,
|
|
12
|
-
virColorPairBookPage,
|
|
13
|
-
virColorPairContrastSummaryBookPage,
|
|
14
|
-
virColorPickerBookPage,
|
|
15
6
|
];
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* node:coverage disable */
|
|
2
2
|
import { ElementBookApp } from 'element-book';
|
|
3
3
|
import { css, defineElement, html } from 'element-vir';
|
|
4
|
-
import { noNativeSpacing } from 'vira/dist/styles/native-styles.js';
|
|
5
4
|
import { allBookPages } from './all-book-pages.js';
|
|
6
5
|
export const VirDemo = defineElement()({
|
|
7
6
|
tagName: 'vir-demo',
|
|
@@ -21,7 +20,8 @@ export const VirDemo = defineElement()({
|
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
h1 {
|
|
24
|
-
|
|
23
|
+
padding: 0;
|
|
24
|
+
margin: 0;
|
|
25
25
|
font-size: 16px;
|
|
26
26
|
margin-bottom: 16px;
|
|
27
27
|
text-align: center;
|
|
@@ -36,7 +36,9 @@ export const VirDemo = defineElement()({
|
|
|
36
36
|
basePath: 'color',
|
|
37
37
|
},
|
|
38
38
|
})}>
|
|
39
|
-
<h1 slot=${ElementBookApp.slotNames
|
|
39
|
+
<h1 slot=${ElementBookApp.slotNames['element-book-app-nav-header']}>
|
|
40
|
+
@electrovir/color
|
|
41
|
+
</h1>
|
|
40
42
|
</${ElementBookApp}>
|
|
41
43
|
`;
|
|
42
44
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -3,13 +3,3 @@ export * from './data/color-class/color-name-length.js';
|
|
|
3
3
|
export * from './data/color-class/color.js';
|
|
4
4
|
export * from './data/color-css.js';
|
|
5
5
|
export * from './data/contrast/contrast.js';
|
|
6
|
-
export * from './elements/vir-all-color-space-sliders.element.js';
|
|
7
|
-
export * from './elements/vir-all-spaces-color-picker.element.js';
|
|
8
|
-
export * from './elements/vir-color-details.element.js';
|
|
9
|
-
export * from './elements/vir-color-format-sliders.element.js';
|
|
10
|
-
export * from './elements/vir-color-pair-contrast-summary.element.js';
|
|
11
|
-
export * from './elements/vir-color-pair.element.js';
|
|
12
|
-
export * from './elements/vir-color-picker.element.js';
|
|
13
|
-
export * from './elements/vir-color-slider.element.js';
|
|
14
|
-
export * from './elements/vir-color-swatch.element.js';
|
|
15
|
-
export * from './elements/vir-contrast-indicator.element.js';
|
package/dist/index.js
CHANGED
|
@@ -3,13 +3,3 @@ export * from './data/color-class/color-name-length.js';
|
|
|
3
3
|
export * from './data/color-class/color.js';
|
|
4
4
|
export * from './data/color-css.js';
|
|
5
5
|
export * from './data/contrast/contrast.js';
|
|
6
|
-
export * from './elements/vir-all-color-space-sliders.element.js';
|
|
7
|
-
export * from './elements/vir-all-spaces-color-picker.element.js';
|
|
8
|
-
export * from './elements/vir-color-details.element.js';
|
|
9
|
-
export * from './elements/vir-color-format-sliders.element.js';
|
|
10
|
-
export * from './elements/vir-color-pair-contrast-summary.element.js';
|
|
11
|
-
export * from './elements/vir-color-pair.element.js';
|
|
12
|
-
export * from './elements/vir-color-picker.element.js';
|
|
13
|
-
export * from './elements/vir-color-slider.element.js';
|
|
14
|
-
export * from './elements/vir-color-swatch.element.js';
|
|
15
|
-
export * from './elements/vir-contrast-indicator.element.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@electrovir/color",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
4
|
"description": "A wrapper for culori with an extremely simple API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"color",
|
|
@@ -53,52 +53,52 @@
|
|
|
53
53
|
"@electrovir/color": "file:./"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@augment-vir/assert": "^32.
|
|
57
|
-
"@augment-vir/common": "^32.
|
|
58
|
-
"@augment-vir/web": "^32.
|
|
59
|
-
"@electrovir/local-storage-client": "^0.1.
|
|
56
|
+
"@augment-vir/assert": "^32.3.0-beta.0",
|
|
57
|
+
"@augment-vir/common": "^32.3.0-beta.0",
|
|
58
|
+
"@augment-vir/web": "^32.3.0-beta.0",
|
|
59
|
+
"@electrovir/local-storage-client": "^0.1.1",
|
|
60
60
|
"apca-w3": "^0.1.9",
|
|
61
61
|
"color-name": "^2.1.1",
|
|
62
62
|
"culori": "^4.0.2",
|
|
63
|
-
"object-shape-tester": "^6.
|
|
63
|
+
"object-shape-tester": "^6.15.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@augment-vir/test": "^32.
|
|
67
|
-
"@eslint/eslintrc": "^3.3.
|
|
66
|
+
"@augment-vir/test": "^32.3.0-beta.0",
|
|
67
|
+
"@eslint/eslintrc": "^3.3.7",
|
|
68
68
|
"@eslint/js": "10.0.1",
|
|
69
69
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
70
70
|
"@stylistic/eslint-plugin-ts": "^4.4.1",
|
|
71
71
|
"@types/color-name": "^2.0.0",
|
|
72
72
|
"@types/culori": "^4.0.1",
|
|
73
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
73
|
+
"@typescript-eslint/eslint-plugin": "^8.69.0",
|
|
74
74
|
"@web/dev-server-esbuild": "^2.0.0",
|
|
75
75
|
"@web/test-runner": "^1.0.0",
|
|
76
76
|
"@web/test-runner-commands": "^1.0.1",
|
|
77
77
|
"@web/test-runner-playwright": "^1.0.0",
|
|
78
78
|
"@web/test-runner-visual-regression": "^1.0.1",
|
|
79
|
-
"cspell": "^10.0
|
|
80
|
-
"dependency-cruiser": "^18.
|
|
81
|
-
"element-book": "^
|
|
82
|
-
"element-vir": "
|
|
83
|
-
"esbuild": "^0.28.
|
|
84
|
-
"eslint": "^10.
|
|
79
|
+
"cspell": "^10.2.0",
|
|
80
|
+
"dependency-cruiser": "^18.2.0",
|
|
81
|
+
"element-book": "^27.0.0-beta.1",
|
|
82
|
+
"element-vir": "27.0.0-beta.3",
|
|
83
|
+
"esbuild": "^0.28.2",
|
|
84
|
+
"eslint": "^10.9.1",
|
|
85
85
|
"eslint-config-prettier": "^10.1.8",
|
|
86
|
-
"eslint-plugin-jsdoc": "^
|
|
86
|
+
"eslint-plugin-jsdoc": "^64.3.4",
|
|
87
87
|
"eslint-plugin-monorepo-cop": "^1.0.2",
|
|
88
|
-
"eslint-plugin-playwright": "^2.
|
|
88
|
+
"eslint-plugin-playwright": "^2.11.0",
|
|
89
89
|
"eslint-plugin-prettier": "^5.5.6",
|
|
90
90
|
"eslint-plugin-require-extensions": "^0.1.3",
|
|
91
91
|
"eslint-plugin-sonarjs": "^4.2.0",
|
|
92
|
-
"eslint-plugin-unicorn": "^
|
|
93
|
-
"execute-in-browser": "^1.0.
|
|
92
|
+
"eslint-plugin-unicorn": "^74.0.0",
|
|
93
|
+
"execute-in-browser": "^1.0.10",
|
|
94
94
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
95
95
|
"lit-css-vars": "^3.6.3",
|
|
96
96
|
"markdown-code-example-inserter": "^3.0.6",
|
|
97
|
-
"npm-check-updates": "^
|
|
97
|
+
"npm-check-updates": "^23.1.0",
|
|
98
98
|
"prettier": "~3.3.3",
|
|
99
|
-
"prettier-plugin-interpolated-html-tags": "^2.0.
|
|
99
|
+
"prettier-plugin-interpolated-html-tags": "^2.0.2",
|
|
100
100
|
"prettier-plugin-jsdoc": "^1.8.1",
|
|
101
|
-
"prettier-plugin-multiline-arrays": "^4.1.
|
|
101
|
+
"prettier-plugin-multiline-arrays": "^4.1.11",
|
|
102
102
|
"prettier-plugin-organize-imports": "^4.3.0",
|
|
103
103
|
"prettier-plugin-packagejson": "^3.0.2",
|
|
104
104
|
"prettier-plugin-sort-json": "^4.2.0",
|
|
@@ -106,15 +106,13 @@
|
|
|
106
106
|
"runstorm": "^1.0.6",
|
|
107
107
|
"typedoc": "^0.28.20",
|
|
108
108
|
"typescript": "^6.0.3",
|
|
109
|
-
"typescript-eslint": "^8.
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"vite": "^8.1.5"
|
|
109
|
+
"typescript-eslint": "^8.69.0",
|
|
110
|
+
"virmator": "^14.34.0",
|
|
111
|
+
"vite": "^8.2.2"
|
|
113
112
|
},
|
|
114
113
|
"peerDependencies": {
|
|
115
|
-
"element-vir": "
|
|
116
|
-
"lit-css-vars": ">=3"
|
|
117
|
-
"vira": ">=28"
|
|
114
|
+
"element-vir": "^27.0.0-beta.3",
|
|
115
|
+
"lit-css-vars": ">=3"
|
|
118
116
|
},
|
|
119
117
|
"engines": {
|
|
120
118
|
"node": ">=22"
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { LocalStorageClient } from '@electrovir/local-storage-client';
|
|
2
|
-
export declare const colorLocalStorageClient: LocalStorageClient<{
|
|
3
|
-
lastFormat: import("object-shape-tester").Shape<import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TLiteral<"hsl"> | import("@sinclair/typebox").TLiteral<"hwb"> | import("@sinclair/typebox").TLiteral<"lab"> | import("@sinclair/typebox").TLiteral<"lch"> | import("@sinclair/typebox").TLiteral<"oklab"> | import("@sinclair/typebox").TLiteral<"oklch"> | import("@sinclair/typebox").TLiteral<"rgb"> | import("@sinclair/typebox").TLiteral<"hex">)[]>>;
|
|
4
|
-
}>;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { LocalStorageClient } from '@electrovir/local-storage-client';
|
|
2
|
-
import { enumShape } from 'object-shape-tester';
|
|
3
|
-
import { ColorFormatName } from './color-class/color-formats.js';
|
|
4
|
-
export const colorLocalStorageClient = new LocalStorageClient({
|
|
5
|
-
lastFormat: enumShape(ColorFormatName),
|
|
6
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type Color } from '../data/color-class/color.js';
|
|
2
|
-
/**
|
|
3
|
-
* Color sliders for all color spaces.
|
|
4
|
-
*
|
|
5
|
-
* @category Elements
|
|
6
|
-
*/
|
|
7
|
-
export declare const VirAllColorSpaceSliders: import("element-vir").DeclarativeElementDefinition<"vir-all-color-space-sliders", {
|
|
8
|
-
color: Readonly<Color>;
|
|
9
|
-
}, {}, {
|
|
10
|
-
colorChange: import("element-vir").DefineEvent<string>;
|
|
11
|
-
}, "vir-all-color-space-sliders-", "vir-all-color-space-sliders-", readonly [], readonly []>;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/* node:coverage disable */
|
|
2
|
-
import { getObjectTypedKeys, getObjectTypedValues } from '@augment-vir/common';
|
|
3
|
-
import { css, defineElement, defineElementEvent, html, listen } from 'element-vir';
|
|
4
|
-
import { colorFormatsBySpace } from '../data/color-class/color-formats.js';
|
|
5
|
-
import { VirColorFormatSliders } from './vir-color-format-sliders.element.js';
|
|
6
|
-
/**
|
|
7
|
-
* Color sliders for all color spaces.
|
|
8
|
-
*
|
|
9
|
-
* @category Elements
|
|
10
|
-
*/
|
|
11
|
-
export const VirAllColorSpaceSliders = defineElement()({
|
|
12
|
-
tagName: 'vir-all-color-space-sliders',
|
|
13
|
-
styles: css `
|
|
14
|
-
:host {
|
|
15
|
-
display: flex;
|
|
16
|
-
flex-direction: column;
|
|
17
|
-
gap: 16px;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.color-space {
|
|
21
|
-
display: flex;
|
|
22
|
-
flex-wrap: wrap;
|
|
23
|
-
column-gap: 32px;
|
|
24
|
-
row-gap: 8px;
|
|
25
|
-
}
|
|
26
|
-
`,
|
|
27
|
-
events: {
|
|
28
|
-
colorChange: defineElementEvent(),
|
|
29
|
-
},
|
|
30
|
-
render({ inputs, dispatch, events }) {
|
|
31
|
-
const colorSpaceTemplates = getObjectTypedValues(colorFormatsBySpace).map((colorSpaceFormats) => {
|
|
32
|
-
const formatTemplates = getObjectTypedKeys(colorSpaceFormats).map((colorFormatName) => {
|
|
33
|
-
return html `
|
|
34
|
-
<${VirColorFormatSliders.assign({
|
|
35
|
-
color: inputs.color,
|
|
36
|
-
colorFormatName,
|
|
37
|
-
showFormatName: true,
|
|
38
|
-
})}
|
|
39
|
-
${listen(VirColorFormatSliders.events.colorChange, (event) => {
|
|
40
|
-
dispatch(new events.colorChange(event.detail));
|
|
41
|
-
})}
|
|
42
|
-
></${VirColorFormatSliders}>
|
|
43
|
-
`;
|
|
44
|
-
});
|
|
45
|
-
return html `
|
|
46
|
-
<section class="color-space">${formatTemplates}</section>
|
|
47
|
-
`;
|
|
48
|
-
});
|
|
49
|
-
return html `
|
|
50
|
-
${colorSpaceTemplates}
|
|
51
|
-
`;
|
|
52
|
-
},
|
|
53
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type ColorSyntaxName } from '../data/color-class/color-formats.js';
|
|
2
|
-
/**
|
|
3
|
-
* A color picker element that shows sliders for all supported color spaces at once, as well as all
|
|
4
|
-
* the values for all supported color spaces in a table.
|
|
5
|
-
*
|
|
6
|
-
* @category Elements
|
|
7
|
-
*/
|
|
8
|
-
export declare const VirAllSpacesColorPicker: import("element-vir").DeclarativeElementDefinition<"vir-all-spaces-color-picker", {
|
|
9
|
-
color: string;
|
|
10
|
-
}, {
|
|
11
|
-
inputColorString: undefined | string;
|
|
12
|
-
overrideInputColor: undefined | ColorSyntaxName;
|
|
13
|
-
}, {
|
|
14
|
-
colorChange: import("element-vir").DefineEvent<string>;
|
|
15
|
-
}, "vir-all-spaces-color-picker-", "vir-all-spaces-color-picker-", readonly [], readonly []>;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/* node:coverage disable */
|
|
2
|
-
import { css, defineElement, defineElementEvent, html, listen } from 'element-vir';
|
|
3
|
-
import { getColorSyntaxFromCssString, } from '../data/color-class/color-formats.js';
|
|
4
|
-
import { Color } from '../data/color-class/color.js';
|
|
5
|
-
import { VirAllColorSpaceSliders } from './vir-all-color-space-sliders.element.js';
|
|
6
|
-
import { VirColorDetails } from './vir-color-details.element.js';
|
|
7
|
-
/**
|
|
8
|
-
* A color picker element that shows sliders for all supported color spaces at once, as well as all
|
|
9
|
-
* the values for all supported color spaces in a table.
|
|
10
|
-
*
|
|
11
|
-
* @category Elements
|
|
12
|
-
*/
|
|
13
|
-
export const VirAllSpacesColorPicker = defineElement()({
|
|
14
|
-
tagName: 'vir-all-spaces-color-picker',
|
|
15
|
-
styles: css `
|
|
16
|
-
:host {
|
|
17
|
-
display: flex;
|
|
18
|
-
flex-direction: column;
|
|
19
|
-
gap: 16px;
|
|
20
|
-
}
|
|
21
|
-
`,
|
|
22
|
-
events: {
|
|
23
|
-
colorChange: defineElementEvent(),
|
|
24
|
-
},
|
|
25
|
-
state() {
|
|
26
|
-
return {
|
|
27
|
-
inputColorString: undefined,
|
|
28
|
-
overrideInputColor: undefined,
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
render({ inputs, dispatch, events, state, updateState }) {
|
|
32
|
-
const color = new Color(inputs.color);
|
|
33
|
-
if (state.overrideInputColor) {
|
|
34
|
-
updateState({
|
|
35
|
-
inputColorString: color.toCss()[state.overrideInputColor],
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if (state.inputColorString == undefined) {
|
|
39
|
-
updateState({
|
|
40
|
-
inputColorString: inputs.color,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return html `
|
|
44
|
-
<${VirColorDetails.assign({
|
|
45
|
-
color: inputs.color,
|
|
46
|
-
showInput: true,
|
|
47
|
-
})}
|
|
48
|
-
${listen(VirColorDetails.events.colorChange, (event) => {
|
|
49
|
-
updateState({
|
|
50
|
-
inputColorString: event.detail,
|
|
51
|
-
overrideInputColor: undefined,
|
|
52
|
-
});
|
|
53
|
-
dispatch(new events.colorChange(event.detail));
|
|
54
|
-
})}
|
|
55
|
-
></${VirColorDetails}>
|
|
56
|
-
<${VirAllColorSpaceSliders.assign({
|
|
57
|
-
color,
|
|
58
|
-
})}
|
|
59
|
-
${listen(VirAllColorSpaceSliders.events.colorChange, (event) => {
|
|
60
|
-
const colorSyntax = getColorSyntaxFromCssString(state.inputColorString || '#');
|
|
61
|
-
updateState({
|
|
62
|
-
overrideInputColor: colorSyntax,
|
|
63
|
-
});
|
|
64
|
-
dispatch(new events.colorChange(event.detail));
|
|
65
|
-
})}
|
|
66
|
-
></${VirAllColorSpaceSliders}>
|
|
67
|
-
`;
|
|
68
|
-
},
|
|
69
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A color swatch alongside the color in all of its different supported formats.
|
|
3
|
-
*
|
|
4
|
-
* @category Internal
|
|
5
|
-
*/
|
|
6
|
-
export declare const VirColorDetails: import("element-vir").DeclarativeElementDefinition<"vir-color-details", {
|
|
7
|
-
color: string;
|
|
8
|
-
/** Show a text input that triggers an event when it is edited, for changing the color. */
|
|
9
|
-
showInput: boolean;
|
|
10
|
-
}, {
|
|
11
|
-
inputColorString: undefined | string;
|
|
12
|
-
}, {
|
|
13
|
-
colorChange: import("element-vir").DefineEvent<string>;
|
|
14
|
-
}, "vir-color-details-", "vir-color-details-", readonly [], readonly []>;
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/* node:coverage disable */
|
|
2
|
-
import { check } from '@augment-vir/assert';
|
|
3
|
-
import { getObjectTypedEntries, mapObject } from '@augment-vir/common';
|
|
4
|
-
import { css, defineElement, defineElementEvent, html, listen } from 'element-vir';
|
|
5
|
-
import { ViraInput } from 'vira/dist/elements/vira-input.element.js';
|
|
6
|
-
import { viraFontCssVars } from 'vira/dist/styles/font.js';
|
|
7
|
-
import { noNativeSpacing } from 'vira/dist/styles/native-styles.js';
|
|
8
|
-
import { defineTable } from 'vira/dist/util/define-table.js';
|
|
9
|
-
import { ColorSyntaxName } from '../data/color-class/color-formats.js';
|
|
10
|
-
import { Color } from '../data/color-class/color.js';
|
|
11
|
-
import { VirColorSwatch } from './vir-color-swatch.element.js';
|
|
12
|
-
const omittedColors = [
|
|
13
|
-
ColorSyntaxName.hex,
|
|
14
|
-
ColorSyntaxName.name,
|
|
15
|
-
];
|
|
16
|
-
/**
|
|
17
|
-
* A color swatch alongside the color in all of its different supported formats.
|
|
18
|
-
*
|
|
19
|
-
* @category Internal
|
|
20
|
-
*/
|
|
21
|
-
export const VirColorDetails = defineElement()({
|
|
22
|
-
tagName: 'vir-color-details',
|
|
23
|
-
styles: css `
|
|
24
|
-
:host {
|
|
25
|
-
display: flex;
|
|
26
|
-
gap: 16px;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
${VirColorSwatch} {
|
|
30
|
-
height: 200px;
|
|
31
|
-
width: 200px;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.swatch {
|
|
35
|
-
display: flex;
|
|
36
|
-
flex-direction: column;
|
|
37
|
-
gap: 8px;
|
|
38
|
-
align-items: center;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
${ViraInput} {
|
|
42
|
-
font-size: 14px;
|
|
43
|
-
font-family: ${viraFontCssVars['vira-monospace'].value};
|
|
44
|
-
max-width: 200px;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
td {
|
|
48
|
-
font-weight: bold;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
th {
|
|
52
|
-
padding: 4px 8px;
|
|
53
|
-
font-weight: normal;
|
|
54
|
-
text-align: right;
|
|
55
|
-
}
|
|
56
|
-
pre {
|
|
57
|
-
${noNativeSpacing};
|
|
58
|
-
font-family: ${viraFontCssVars['vira-monospace'].value};
|
|
59
|
-
}
|
|
60
|
-
`,
|
|
61
|
-
events: {
|
|
62
|
-
colorChange: defineElementEvent(),
|
|
63
|
-
},
|
|
64
|
-
state() {
|
|
65
|
-
return {
|
|
66
|
-
inputColorString: undefined,
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
render({ inputs, dispatch, events, state, updateState }) {
|
|
70
|
-
const color = new Color(inputs.color);
|
|
71
|
-
const colorStrings = mapObject(color.toFormattedStrings(), (key, value) => {
|
|
72
|
-
if (check.hasValue(omittedColors, key)) {
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
else if (key === 'hexString') {
|
|
76
|
-
return {
|
|
77
|
-
key: 'hex',
|
|
78
|
-
value,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
return {
|
|
83
|
-
key,
|
|
84
|
-
value,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
if (state.inputColorString == undefined) {
|
|
89
|
-
updateState({
|
|
90
|
-
inputColorString: inputs.color,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
const { rows } = defineTable({
|
|
94
|
-
headers: [
|
|
95
|
-
{
|
|
96
|
-
key: 'colorFormat',
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
key: 'formattedString',
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
originalData: getObjectTypedEntries(colorStrings),
|
|
103
|
-
dataMap: ([colorFormat, value,]) => {
|
|
104
|
-
return {
|
|
105
|
-
colorFormat: `${colorFormat}:`,
|
|
106
|
-
formattedString: html `
|
|
107
|
-
<pre>${value}</pre>
|
|
108
|
-
`,
|
|
109
|
-
};
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
const inputTemplate = inputs.showInput
|
|
113
|
-
? html `
|
|
114
|
-
<${ViraInput.assign({
|
|
115
|
-
value: state.inputColorString || '',
|
|
116
|
-
fitText: true,
|
|
117
|
-
})}
|
|
118
|
-
${listen(ViraInput.events.valueChange, (event) => {
|
|
119
|
-
updateState({
|
|
120
|
-
inputColorString: event.detail,
|
|
121
|
-
});
|
|
122
|
-
dispatch(new events.colorChange(event.detail));
|
|
123
|
-
})}
|
|
124
|
-
></${ViraInput}>
|
|
125
|
-
`
|
|
126
|
-
: '';
|
|
127
|
-
return html `
|
|
128
|
-
<div class="swatch">
|
|
129
|
-
<${VirColorSwatch.assign({
|
|
130
|
-
backgroundColor: inputs.color,
|
|
131
|
-
})}></${VirColorSwatch}>
|
|
132
|
-
${inputTemplate}
|
|
133
|
-
</div>
|
|
134
|
-
<table>
|
|
135
|
-
<tbody>
|
|
136
|
-
${rows.map((row) => {
|
|
137
|
-
const cells = row.cells.map((cell, index) => {
|
|
138
|
-
const element = index ? 'td' : 'th';
|
|
139
|
-
return html `
|
|
140
|
-
<${element}>${cell.content}</${element}>
|
|
141
|
-
`;
|
|
142
|
-
});
|
|
143
|
-
return html `
|
|
144
|
-
<tr>${cells}</tr>
|
|
145
|
-
`;
|
|
146
|
-
})}
|
|
147
|
-
</tbody>
|
|
148
|
-
</table>
|
|
149
|
-
`;
|
|
150
|
-
},
|
|
151
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type ColorFormatName } from '../data/color-class/color-formats.js';
|
|
2
|
-
import { type Color } from '../data/color-class/color.js';
|
|
3
|
-
/**
|
|
4
|
-
* Color sliders for all coordinates within a specific color format.
|
|
5
|
-
*
|
|
6
|
-
* @category Elements
|
|
7
|
-
*/
|
|
8
|
-
export declare const VirColorFormatSliders: import("element-vir").DeclarativeElementDefinition<"vir-color-format-sliders", {
|
|
9
|
-
color: Readonly<Color>;
|
|
10
|
-
colorFormatName: ColorFormatName;
|
|
11
|
-
showFormatName: boolean;
|
|
12
|
-
}, {}, {
|
|
13
|
-
colorChange: import("element-vir").DefineEvent<string>;
|
|
14
|
-
}, "vir-color-format-sliders-", "vir-color-format-sliders-", readonly [], readonly []>;
|