@electrovir/color 1.6.1 → 1.6.3

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 { virAllColorSpaceSlidersBookPage } from '../elements/vir-all-color-space-sliders.element.book.js';
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
- virAllColorSpaceSlidersBookPage,
10
+ virAllSpacesColorPickerBookPage,
11
+ virColorPairContrastSummaryBookPage,
10
12
  virColorPickerBookPage,
11
13
  ];
@@ -1,9 +1,15 @@
1
1
  /* node:coverage disable */
2
- import { getObjectTypedEntries, omitObjectKeys } from '@augment-vir/common';
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 = omitObjectKeys(color.toFormattedStrings(), ['name']);
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).toCss().hex,
132
- 'Background:': new Color(inputs.backgroundColor).toCss().hex,
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,7 +1,7 @@
1
1
  /* node:coverage disable */
2
2
  import { checkWrap } from '@augment-vir/assert';
3
3
  import { getObjectTypedValues } from '@augment-vir/common';
4
- import { css, defineElement, defineElementEvent, html, listen, nothing } from 'element-vir';
4
+ import { css, defineElement, defineElementEvent, html, listen, nothing, onDomCreated, } from 'element-vir';
5
5
  import { Copy24Icon, noNativeFormStyles, viraFontCssVars, viraFormCssVars, ViraIcon, ViraInput, ViraPopUpTrigger, ViraSelect, viraShadows, } from 'vira';
6
6
  import { ColorFormatName, colorFormats } from '../data/color-class/color-formats.js';
7
7
  import { Color } from '../data/color-class/color.js';
@@ -108,6 +108,7 @@ export const VirColorPicker = defineElement()({
108
108
  }
109
109
 
110
110
  .raw-input-wrapper {
111
+ text-align: left;
111
112
  display: flex;
112
113
  align-items: center;
113
114
  justify-content: center;
@@ -140,8 +141,9 @@ export const VirColorPicker = defineElement()({
140
141
  value: rawInput,
141
142
  })}
142
143
  ${listen(ViraInput.events.valueChange, (event) => {
144
+ const rawInput = event.detail;
143
145
  updateState({
144
- rawInput: event.detail,
146
+ rawInput,
145
147
  });
146
148
  if (Color.isValidColorString(rawInput)) {
147
149
  dispatch(new events.colorChange(rawInput));
@@ -188,6 +190,14 @@ export const VirColorPicker = defineElement()({
188
190
  <${ViraSelect.assign({
189
191
  options: colorFormatOptions,
190
192
  value: state.selectedFormatName,
193
+ })}
194
+ ${onDomCreated(() => {
195
+ const storedFormat = colorLocalStorageClient.get.lastFormat();
196
+ if (storedFormat) {
197
+ updateState({
198
+ selectedFormatName: storedFormat,
199
+ });
200
+ }
191
201
  })}
192
202
  ${listen(ViraSelect.events.valueChange, (event) => {
193
203
  const selectedFormat = checkWrap.isEnumValue(event.detail, ColorFormatName);
@@ -232,15 +242,17 @@ export const VirColorPicker = defineElement()({
232
242
  }
233
243
  },
234
244
  });
235
- CSS.registerProperty({
236
- name: String(VirColorPicker.cssVars['vir-color-picker-swatch-width'].name),
237
- syntax: '<length>',
238
- inherits: true,
239
- initialValue: VirColorPicker.cssVars['vir-color-picker-swatch-width'].default,
240
- });
241
- CSS.registerProperty({
242
- name: String(VirColorPicker.cssVars['vir-color-picker-swatch-height'].name),
243
- syntax: '<length>',
244
- inherits: true,
245
- initialValue: VirColorPicker.cssVars['vir-color-picker-swatch-height'].default,
246
- });
245
+ if ('CSS' in globalThis) {
246
+ globalThis.CSS.registerProperty({
247
+ name: String(VirColorPicker.cssVars['vir-color-picker-swatch-width'].name),
248
+ syntax: '<length>',
249
+ inherits: true,
250
+ initialValue: VirColorPicker.cssVars['vir-color-picker-swatch-width'].default,
251
+ });
252
+ globalThis.CSS.registerProperty({
253
+ name: String(VirColorPicker.cssVars['vir-color-picker-swatch-height'].name),
254
+ syntax: '<length>',
255
+ inherits: true,
256
+ initialValue: VirColorPicker.cssVars['vir-color-picker-swatch-height'].default,
257
+ });
258
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@electrovir/color",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "A wrapper for culori with an extremely simple API.",
5
5
  "keywords": [
6
6
  "color",
@@ -53,7 +53,7 @@
53
53
  "@augment-vir/assert": "^31.57.5",
54
54
  "@augment-vir/common": "^31.57.5",
55
55
  "@augment-vir/web": "^31.57.5",
56
- "@electrovir/local-storage-client": "^0.0.1",
56
+ "@electrovir/local-storage-client": "^0.0.2",
57
57
  "apca-w3": "^0.1.9",
58
58
  "color-name": "^2.1.0",
59
59
  "culori": "^4.0.2",
@@ -64,7 +64,7 @@
64
64
  "@augment-vir/test": "^31.57.5",
65
65
  "@eslint/eslintrc": "^3.3.3",
66
66
  "@eslint/js": "^9.39.2",
67
- "@stylistic/eslint-plugin": "^5.6.1",
67
+ "@stylistic/eslint-plugin": "^5.7.0",
68
68
  "@stylistic/eslint-plugin-ts": "^4.4.1",
69
69
  "@types/color-name": "^2.0.0",
70
70
  "@types/culori": "^4.0.1",
@@ -81,9 +81,9 @@
81
81
  "esbuild": "^0.27.2",
82
82
  "eslint": "^9.39.2",
83
83
  "eslint-config-prettier": "^10.1.8",
84
- "eslint-plugin-jsdoc": "^61.5.0",
84
+ "eslint-plugin-jsdoc": "^62.0.0",
85
85
  "eslint-plugin-monorepo-cop": "^1.0.2",
86
- "eslint-plugin-playwright": "^2.4.0",
86
+ "eslint-plugin-playwright": "^2.4.1",
87
87
  "eslint-plugin-prettier": "^5.5.4",
88
88
  "eslint-plugin-require-extensions": "^0.1.3",
89
89
  "eslint-plugin-sonarjs": "^3.0.5",
@@ -105,7 +105,7 @@
105
105
  "typedoc": "^0.28.15",
106
106
  "typescript": "^5.9.3",
107
107
  "typescript-eslint": "^8.52.0",
108
- "vira": "^28.19.0",
108
+ "vira": "^28.19.2",
109
109
  "virmator": "^14.4.2",
110
110
  "vite": "^7.3.1"
111
111
  },