@electrovir/color 1.6.0 → 1.6.2
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,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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';
|
|
2
3
|
import { virColorPickerBookPage } from '../elements/vir-color-picker.element.book.js';
|
|
3
4
|
import { colorExamplesPage } from './color-examples.book.js';
|
|
4
5
|
import { elementsBookPage, examplesBookPage } from './top-level-pages.js';
|
|
@@ -6,6 +7,7 @@ export const allBookPages = [
|
|
|
6
7
|
elementsBookPage,
|
|
7
8
|
examplesBookPage,
|
|
8
9
|
colorExamplesPage,
|
|
9
|
-
|
|
10
|
+
virAllSpacesColorPickerBookPage,
|
|
11
|
+
virColorPairContrastSummaryBookPage,
|
|
10
12
|
virColorPickerBookPage,
|
|
11
13
|
];
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/* node:coverage disable */
|
|
2
|
-
import {
|
|
2
|
+
import { check } from '@augment-vir/assert';
|
|
3
|
+
import { getObjectTypedEntries, mapObject } from '@augment-vir/common';
|
|
3
4
|
import { css, defineElement, defineElementEvent, html, listen } from 'element-vir';
|
|
4
5
|
import { defineTable, noNativeSpacing, viraFontCssVars, ViraInput } from 'vira';
|
|
6
|
+
import { ColorSyntaxName } from '../data/color-class/color-formats.js';
|
|
5
7
|
import { Color } from '../data/color-class/color.js';
|
|
6
8
|
import { VirColorSwatch } from './vir-color-swatch.element.js';
|
|
9
|
+
const omittedColors = [
|
|
10
|
+
ColorSyntaxName.hex,
|
|
11
|
+
ColorSyntaxName.name,
|
|
12
|
+
];
|
|
7
13
|
/**
|
|
8
14
|
* A color swatch alongside the color in all of its different supported formats.
|
|
9
15
|
*
|
|
@@ -59,7 +65,21 @@ export const VirColorDetails = defineElement()({
|
|
|
59
65
|
},
|
|
60
66
|
render({ inputs, dispatch, events, state, updateState }) {
|
|
61
67
|
const color = new Color(inputs.color);
|
|
62
|
-
const colorStrings =
|
|
68
|
+
const colorStrings = mapObject(color.toFormattedStrings(), (key, value) => {
|
|
69
|
+
if (check.hasValue(omittedColors, key)) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
else if (key === 'hexString') {
|
|
73
|
+
return {
|
|
74
|
+
key: 'hex',
|
|
75
|
+
value,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
key,
|
|
80
|
+
value,
|
|
81
|
+
};
|
|
82
|
+
});
|
|
63
83
|
if (state.inputColorString == undefined) {
|
|
64
84
|
updateState({
|
|
65
85
|
inputColorString: inputs.color,
|
|
@@ -128,8 +128,8 @@ export const VirColorPairContrastSummary = defineElement()({
|
|
|
128
128
|
key: 'colorValue',
|
|
129
129
|
},
|
|
130
130
|
], getObjectTypedEntries({
|
|
131
|
-
'Foreground:': new Color(inputs.foregroundColor).
|
|
132
|
-
'Background:': new Color(inputs.backgroundColor).
|
|
131
|
+
'Foreground:': new Color(inputs.foregroundColor).toFormattedStrings().hexString,
|
|
132
|
+
'Background:': new Color(inputs.backgroundColor).toFormattedStrings().hexString,
|
|
133
133
|
'Contrast:': `${contrast.contrast} Lc`.padEnd(9, ' '),
|
|
134
134
|
}), ([colorLayer, value,]) => {
|
|
135
135
|
return {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* node:coverage disable */
|
|
2
|
-
import { assertWrap } from '@augment-vir/assert';
|
|
2
|
+
import { assert, assertWrap } from '@augment-vir/assert';
|
|
3
3
|
import { createArray } from '@augment-vir/common';
|
|
4
4
|
import { extractEventTarget } from '@augment-vir/web';
|
|
5
|
-
import { css, defineElement, defineElementEvent, html, listen, unsafeCSS } from 'element-vir';
|
|
5
|
+
import { css, defineElement, defineElementEvent, html, listen, onDomRendered, unsafeCSS, } from 'element-vir';
|
|
6
6
|
import { viraFontCssVars, ViraInput } from 'vira';
|
|
7
7
|
import { colorFormats, } from '../data/color-class/color-formats.js';
|
|
8
8
|
import { Color } from '../data/color-class/color.js';
|
|
@@ -78,10 +78,18 @@ export const VirColorSlider = defineElement()({
|
|
|
78
78
|
style=${css `
|
|
79
79
|
${cssVars['vir-color-slider-gradient'].name}: ${gradient};
|
|
80
80
|
`}
|
|
81
|
-
min=${coordinateDefinition.min}
|
|
82
|
-
max=${coordinateDefinition.max}
|
|
83
|
-
.value=${String(coordinateValue)}
|
|
84
81
|
step=${Math.pow(10, coordinateDefinition.digits ? -coordinateDefinition.digits : 0)}
|
|
82
|
+
${onDomRendered((element) => {
|
|
83
|
+
/**
|
|
84
|
+
* We must set these imperatively to force the input element to match the
|
|
85
|
+
* inputs, otherwise when swapping color formats these color sliders don't
|
|
86
|
+
* update correctly.
|
|
87
|
+
*/
|
|
88
|
+
assert.instanceOf(element, HTMLInputElement);
|
|
89
|
+
element.min = String(coordinateDefinition.min);
|
|
90
|
+
element.max = String(coordinateDefinition.max);
|
|
91
|
+
element.value = String(coordinateValue);
|
|
92
|
+
})}
|
|
85
93
|
${listen('input', (event) => {
|
|
86
94
|
const element = extractEventTarget(event, HTMLInputElement);
|
|
87
95
|
const newValue = Number(element.value);
|