vira 31.31.7 → 32.0.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/elements/color/vira-all-color-space-sliders.element.d.ts +11 -0
- package/dist/elements/color/vira-all-color-space-sliders.element.js +55 -0
- package/dist/elements/color/vira-all-spaces-color-picker.element.d.ts +15 -0
- package/dist/elements/color/vira-all-spaces-color-picker.element.js +73 -0
- package/dist/elements/color/vira-color-details.element.d.ts +14 -0
- package/dist/elements/color/vira-color-details.element.js +153 -0
- package/dist/elements/color/vira-color-format-sliders.element.d.ts +14 -0
- package/dist/elements/color/vira-color-format-sliders.element.js +60 -0
- package/dist/elements/color/vira-color-pair-contrast-summary.element.d.ts +9 -0
- package/dist/elements/color/vira-color-pair-contrast-summary.element.js +308 -0
- package/dist/elements/color/vira-color-pair.element.d.ts +17 -0
- package/dist/elements/color/vira-color-pair.element.js +201 -0
- package/dist/elements/color/vira-color-picker.element.d.ts +20 -0
- package/dist/elements/color/vira-color-picker.element.js +278 -0
- package/dist/elements/color/vira-color-slider.element.d.ts +14 -0
- package/dist/elements/color/vira-color-slider.element.js +124 -0
- package/dist/elements/color/vira-color-swatch.element.d.ts +20 -0
- package/dist/elements/color/vira-color-swatch.element.js +48 -0
- package/dist/elements/color/vira-contrast-indicator.element.d.ts +10 -0
- package/dist/elements/color/vira-contrast-indicator.element.js +96 -0
- package/dist/elements/index.d.ts +10 -0
- package/dist/elements/index.js +10 -0
- package/dist/elements/pop-up/vira-menu-item.element.d.ts +1 -1
- package/dist/elements/pop-up/vira-menu-item.element.js +20 -8
- package/dist/elements/pop-up/vira-menu-trigger.element.d.ts +1 -1
- package/dist/elements/pop-up/vira-menu-trigger.element.js +3 -1
- package/dist/elements/pop-up/vira-menu.element.js +10 -4
- package/dist/elements/pop-up/vira-pop-up-trigger.element.d.ts +3 -3
- package/dist/elements/pop-up/vira-pop-up-trigger.element.js +24 -10
- package/dist/elements/vira-bold-text.element.js +4 -2
- package/dist/elements/vira-button.element.d.ts +1 -8
- package/dist/elements/vira-button.element.js +28 -37
- package/dist/elements/vira-card.element.js +7 -3
- package/dist/elements/vira-checkbox.element.d.ts +1 -1
- package/dist/elements/vira-checkbox.element.js +13 -5
- package/dist/elements/vira-collapsible-card.element.d.ts +1 -1
- package/dist/elements/vira-collapsible-card.element.js +13 -5
- package/dist/elements/vira-collapsible-wrapper.element.d.ts +1 -1
- package/dist/elements/vira-collapsible-wrapper.element.js +7 -3
- package/dist/elements/vira-date-input.element.d.ts +1 -1
- package/dist/elements/vira-date-input.element.js +10 -4
- package/dist/elements/vira-drawer.element.d.ts +1 -1
- package/dist/elements/vira-drawer.element.js +14 -6
- package/dist/elements/vira-dropdown.element.d.ts +2 -8
- package/dist/elements/vira-dropdown.element.js +6 -10
- package/dist/elements/vira-error.element.js +1 -1
- package/dist/elements/vira-form.element.d.ts +2 -2
- package/dist/elements/vira-form.element.js +36 -22
- package/dist/elements/vira-icon.element.js +4 -2
- package/dist/elements/vira-image.element.d.ts +2 -2
- package/dist/elements/vira-image.element.js +7 -3
- package/dist/elements/vira-input.element.d.ts +2 -2
- package/dist/elements/vira-input.element.js +23 -9
- package/dist/elements/vira-json-form.element.d.ts +1 -1
- package/dist/elements/vira-json-form.element.js +18 -8
- package/dist/elements/vira-link.element.js +5 -3
- package/dist/elements/vira-modal.element.d.ts +1 -1
- package/dist/elements/vira-modal.element.js +14 -6
- package/dist/elements/vira-progress.element.js +1 -1
- package/dist/elements/vira-select.element.d.ts +1 -1
- package/dist/elements/vira-select.element.js +20 -8
- package/dist/elements/vira-tabs.element.d.ts +2 -2
- package/dist/elements/vira-tabs.element.js +35 -21
- package/dist/elements/vira-tag.element.d.ts +3 -3
- package/dist/elements/vira-tag.element.js +46 -18
- package/dist/elements/vira-text-area.element.d.ts +2 -2
- package/dist/elements/vira-text-area.element.js +16 -6
- package/dist/util/color-local-storage.client.d.ts +4 -0
- package/dist/util/color-local-storage.client.js +6 -0
- package/dist/util/define-vira-element.js +1 -1
- package/dist/util/vira-json-schema.js +9 -9
- package/package.json +11 -11
- package/dist/icons/icon-color.test-helper.d.ts +0 -6
- package/dist/icons/icon-color.test-helper.js +0 -9
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/* node:coverage disable */
|
|
2
|
+
import { checkWrap } from '@augment-vir/assert';
|
|
3
|
+
import { getObjectTypedValues } from '@augment-vir/common';
|
|
4
|
+
import { ColorFormatName, colorFormats, } from '@electrovir/color/dist/data/color-class/color-formats.js';
|
|
5
|
+
import { Color } from '@electrovir/color/dist/data/color-class/color.js';
|
|
6
|
+
import { css, defineElement, defineElementEvent, html, listen, nothing } from 'element-vir';
|
|
7
|
+
import { CssVarSyntaxName } from 'lit-css-vars';
|
|
8
|
+
import { Copy24Icon } from '../../icons/icon-svgs/24/copy-24.icon.js';
|
|
9
|
+
import { viraFontCssVars } from '../../styles/font.js';
|
|
10
|
+
import { viraFormCssVars } from '../../styles/form-styles.js';
|
|
11
|
+
import { noNativeFormStyles } from '../../styles/native-styles.js';
|
|
12
|
+
import { viraShadows } from '../../styles/shadows.js';
|
|
13
|
+
import { colorLocalStorageClient } from '../../util/color-local-storage.client.js';
|
|
14
|
+
import { ViraPopUpTrigger } from '../pop-up/vira-pop-up-trigger.element.js';
|
|
15
|
+
import { ViraIcon } from '../vira-icon.element.js';
|
|
16
|
+
import { ViraInput } from '../vira-input.element.js';
|
|
17
|
+
import { ViraSelect } from '../vira-select.element.js';
|
|
18
|
+
import { ViraColorFormatSliders } from './vira-color-format-sliders.element.js';
|
|
19
|
+
import { ViraColorSwatch } from './vira-color-swatch.element.js';
|
|
20
|
+
const colorFormatOptions = getObjectTypedValues(ColorFormatName).map((formatName) => {
|
|
21
|
+
return {
|
|
22
|
+
value: formatName,
|
|
23
|
+
label: formatName.toUpperCase(),
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* A color picker element with a swatch that opens a popup with color format sliders.
|
|
28
|
+
*
|
|
29
|
+
* Set the width and height of the swatch using the provided CSS variables.
|
|
30
|
+
*
|
|
31
|
+
* @category Elements
|
|
32
|
+
*/
|
|
33
|
+
export const ViraColorPicker = defineElement()({
|
|
34
|
+
tagName: 'vira-color-picker',
|
|
35
|
+
cssVars: {
|
|
36
|
+
'vira-color-picker-swatch-width': {
|
|
37
|
+
default: '100px',
|
|
38
|
+
syntax: CssVarSyntaxName.Length,
|
|
39
|
+
},
|
|
40
|
+
'vira-color-picker-swatch-height': {
|
|
41
|
+
default: '100px',
|
|
42
|
+
syntax: CssVarSyntaxName.Length,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
state() {
|
|
46
|
+
return {
|
|
47
|
+
selectedFormatName: colorLocalStorageClient.get.lastFormat() || ColorFormatName.rgb,
|
|
48
|
+
rawInput: undefined,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
hostClasses: {
|
|
52
|
+
'vira-color-picker-always-show'({ inputs }) {
|
|
53
|
+
return !!inputs.alwaysShowPicker;
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
styles({ cssVars, hostClasses }) {
|
|
57
|
+
return css `
|
|
58
|
+
:host {
|
|
59
|
+
display: inline-flex;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
${hostClasses['vira-color-picker-always-show'].selector} {
|
|
63
|
+
flex-direction: column;
|
|
64
|
+
align-items: center;
|
|
65
|
+
gap: 4px;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
button {
|
|
69
|
+
${noNativeFormStyles}
|
|
70
|
+
cursor: pointer;
|
|
71
|
+
display: flex;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
${ViraPopUpTrigger} {
|
|
75
|
+
width: 100%;
|
|
76
|
+
height: 100%;
|
|
77
|
+
box-sizing: border-box;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.swatch-wrapper {
|
|
81
|
+
display: flex;
|
|
82
|
+
flex-direction: column;
|
|
83
|
+
gap: 4px;
|
|
84
|
+
align-items: center;
|
|
85
|
+
|
|
86
|
+
& ${ViraColorSwatch} {
|
|
87
|
+
width: ${cssVars['vira-color-picker-swatch-width'].value};
|
|
88
|
+
height: ${cssVars['vira-color-picker-swatch-height'].value};
|
|
89
|
+
box-sizing: border-box;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.code-button {
|
|
94
|
+
font-family: ${viraFontCssVars['vira-monospace'].value};
|
|
95
|
+
font-size: 12px;
|
|
96
|
+
color: #666;
|
|
97
|
+
display: flex;
|
|
98
|
+
justify-content: center;
|
|
99
|
+
gap: 2px;
|
|
100
|
+
align-items: center;
|
|
101
|
+
|
|
102
|
+
& ${ViraIcon} {
|
|
103
|
+
width: 18px;
|
|
104
|
+
aspect-ratio: 1;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
&:hover {
|
|
108
|
+
color: #000;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
&:active {
|
|
112
|
+
color: dodgerblue;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.picker {
|
|
117
|
+
display: flex;
|
|
118
|
+
flex-direction: column;
|
|
119
|
+
gap: 4px;
|
|
120
|
+
padding: 16px;
|
|
121
|
+
background: white;
|
|
122
|
+
border: 1px solid #ccc;
|
|
123
|
+
border-radius: 8px;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.pop-up .picker {
|
|
127
|
+
${viraShadows.menuShadow}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.raw-input-wrapper {
|
|
131
|
+
text-align: left;
|
|
132
|
+
display: flex;
|
|
133
|
+
align-items: center;
|
|
134
|
+
justify-content: center;
|
|
135
|
+
gap: 8px;
|
|
136
|
+
font-size: 12px;
|
|
137
|
+
${viraFormCssVars['vira-form-border-color'].name}: #ddd;
|
|
138
|
+
color: #666;
|
|
139
|
+
|
|
140
|
+
& ${ViraInput} {
|
|
141
|
+
flex-grow: 1;
|
|
142
|
+
width: unset;
|
|
143
|
+
color: inherit;
|
|
144
|
+
height: 20px;
|
|
145
|
+
border: none;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
`;
|
|
149
|
+
},
|
|
150
|
+
events: {
|
|
151
|
+
colorChange: defineElementEvent(),
|
|
152
|
+
},
|
|
153
|
+
render({ inputs, dispatch, events, state, updateState }) {
|
|
154
|
+
const color = Color.isColor(inputs.color)
|
|
155
|
+
? inputs.color
|
|
156
|
+
: new Color(inputs.color || 'black');
|
|
157
|
+
const formatDefinition = colorFormats[state.selectedFormatName];
|
|
158
|
+
const rawInput = state.rawInput ?? color.toCss()[formatDefinition.rawSyntax];
|
|
159
|
+
const rawInputTemplate = html `
|
|
160
|
+
<div class="raw-input-wrapper">
|
|
161
|
+
<${ViraInput.assign({
|
|
162
|
+
value: rawInput,
|
|
163
|
+
})}
|
|
164
|
+
${listen(ViraInput.events.valueChange, (event) => {
|
|
165
|
+
const rawInput = event.detail;
|
|
166
|
+
updateState({
|
|
167
|
+
rawInput,
|
|
168
|
+
});
|
|
169
|
+
if (Color.isValidColorString(rawInput)) {
|
|
170
|
+
dispatch(new events.colorChange({
|
|
171
|
+
detail: rawInput,
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
})}
|
|
175
|
+
></${ViraInput}>
|
|
176
|
+
<button
|
|
177
|
+
class="code-button"
|
|
178
|
+
${listen('click', async () => {
|
|
179
|
+
await globalThis.navigator.clipboard.writeText(rawInput);
|
|
180
|
+
})}
|
|
181
|
+
>
|
|
182
|
+
<${ViraIcon.assign({
|
|
183
|
+
icon: Copy24Icon,
|
|
184
|
+
fitContainer: true,
|
|
185
|
+
})}></${ViraIcon}>
|
|
186
|
+
</button>
|
|
187
|
+
</div>
|
|
188
|
+
`;
|
|
189
|
+
const hexValueTemplate = html `
|
|
190
|
+
<button
|
|
191
|
+
class="code-button"
|
|
192
|
+
${listen('click', async () => {
|
|
193
|
+
await globalThis.navigator.clipboard.writeText(color.hexString);
|
|
194
|
+
})}
|
|
195
|
+
>
|
|
196
|
+
<span>${color.hexString}</span>
|
|
197
|
+
<${ViraIcon.assign({
|
|
198
|
+
icon: Copy24Icon,
|
|
199
|
+
fitContainer: true,
|
|
200
|
+
})}></${ViraIcon}>
|
|
201
|
+
</button>
|
|
202
|
+
`;
|
|
203
|
+
const swatchTemplate = html `
|
|
204
|
+
<div class="swatch-wrapper">
|
|
205
|
+
<${ViraColorSwatch.assign({
|
|
206
|
+
backgroundColor: color,
|
|
207
|
+
})}></${ViraColorSwatch}>
|
|
208
|
+
${inputs.showHexValue ? hexValueTemplate : nothing}
|
|
209
|
+
</div>
|
|
210
|
+
`;
|
|
211
|
+
const pickerTemplate = html `
|
|
212
|
+
<div class="picker">
|
|
213
|
+
<${ViraSelect.assign({
|
|
214
|
+
options: colorFormatOptions,
|
|
215
|
+
value: state.selectedFormatName,
|
|
216
|
+
})}
|
|
217
|
+
${listen(ViraSelect.events.valueChange, (event) => {
|
|
218
|
+
const selectedFormat = checkWrap.isEnumValue(event.detail, ColorFormatName);
|
|
219
|
+
if (selectedFormat) {
|
|
220
|
+
updateState({
|
|
221
|
+
selectedFormatName: selectedFormat,
|
|
222
|
+
});
|
|
223
|
+
colorLocalStorageClient.set.lastFormat(selectedFormat);
|
|
224
|
+
}
|
|
225
|
+
})}
|
|
226
|
+
></${ViraSelect}>
|
|
227
|
+
${rawInputTemplate}
|
|
228
|
+
<${ViraColorFormatSliders.assign({
|
|
229
|
+
color,
|
|
230
|
+
colorFormatName: state.selectedFormatName,
|
|
231
|
+
showFormatName: false,
|
|
232
|
+
})}
|
|
233
|
+
${listen(ViraColorFormatSliders.events.colorChange, (event) => {
|
|
234
|
+
dispatch(new events.colorChange({
|
|
235
|
+
detail: event.detail,
|
|
236
|
+
}));
|
|
237
|
+
updateState({
|
|
238
|
+
rawInput: undefined,
|
|
239
|
+
});
|
|
240
|
+
})}
|
|
241
|
+
></${ViraColorFormatSliders}>
|
|
242
|
+
</div>
|
|
243
|
+
`;
|
|
244
|
+
if (inputs.alwaysShowPicker) {
|
|
245
|
+
return html `
|
|
246
|
+
${swatchTemplate} ${pickerTemplate}
|
|
247
|
+
`;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
return html `
|
|
251
|
+
<${ViraPopUpTrigger.assign({
|
|
252
|
+
keepOpenAfterInteraction: true,
|
|
253
|
+
})}>
|
|
254
|
+
<button
|
|
255
|
+
class="trigger"
|
|
256
|
+
slot=${ViraPopUpTrigger.slotNames['vira-pop-up-trigger-trigger']}
|
|
257
|
+
${listen('mousedown', () => {
|
|
258
|
+
const storedFormat = colorLocalStorageClient.get.lastFormat();
|
|
259
|
+
if (storedFormat) {
|
|
260
|
+
updateState({
|
|
261
|
+
selectedFormatName: storedFormat,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
})}
|
|
265
|
+
>
|
|
266
|
+
${swatchTemplate}
|
|
267
|
+
</button>
|
|
268
|
+
<div
|
|
269
|
+
class="pop-up"
|
|
270
|
+
slot=${ViraPopUpTrigger.slotNames['vira-pop-up-trigger-pop-up']}
|
|
271
|
+
>
|
|
272
|
+
${pickerTemplate}
|
|
273
|
+
</div>
|
|
274
|
+
</${ViraPopUpTrigger}>
|
|
275
|
+
`;
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ColorCoordinateName, type ColorFormatName } from '@electrovir/color/dist/data/color-class/color-formats.js';
|
|
2
|
+
import { Color } from '@electrovir/color/dist/data/color-class/color.js';
|
|
3
|
+
/**
|
|
4
|
+
* A slider for a specific color coordinate in a specific color space in a specific color.
|
|
5
|
+
*
|
|
6
|
+
* @category Elements
|
|
7
|
+
*/
|
|
8
|
+
export declare const ViraColorSlider: import("element-vir").DeclarativeElementDefinition<"vira-color-slider", {
|
|
9
|
+
color: Readonly<Color>;
|
|
10
|
+
colorFormatName: ColorFormatName;
|
|
11
|
+
colorCoordinateName: ColorCoordinateName;
|
|
12
|
+
}, {}, {
|
|
13
|
+
valueChange: import("element-vir").DefineElementEvent<number>;
|
|
14
|
+
}, "vira-color-slider-", "vira-color-slider-gradient", readonly [], readonly []>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/* node:coverage disable */
|
|
2
|
+
import { assert, assertWrap } from '@augment-vir/assert';
|
|
3
|
+
import { createArray } from '@augment-vir/common';
|
|
4
|
+
import { extractEventTarget } from '@augment-vir/web';
|
|
5
|
+
import { colorFormats, } from '@electrovir/color/dist/data/color-class/color-formats.js';
|
|
6
|
+
import { Color } from '@electrovir/color/dist/data/color-class/color.js';
|
|
7
|
+
import { css, defineElement, defineElementEvent, html, listen, onDomRendered, unsafeCSS, } from 'element-vir';
|
|
8
|
+
import { viraFontCssVars } from '../../styles/font.js';
|
|
9
|
+
import { ViraInput } from '../vira-input.element.js';
|
|
10
|
+
/**
|
|
11
|
+
* A slider for a specific color coordinate in a specific color space in a specific color.
|
|
12
|
+
*
|
|
13
|
+
* @category Elements
|
|
14
|
+
*/
|
|
15
|
+
export const ViraColorSlider = defineElement()({
|
|
16
|
+
tagName: 'vira-color-slider',
|
|
17
|
+
cssVars: {
|
|
18
|
+
'vira-color-slider-gradient': 'black',
|
|
19
|
+
},
|
|
20
|
+
styles({ cssVars }) {
|
|
21
|
+
return css `
|
|
22
|
+
:host {
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
font-family: ${viraFontCssVars['vira-monospace'].value};
|
|
26
|
+
gap: 2px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
input[type='range'] {
|
|
30
|
+
flex-grow: 1;
|
|
31
|
+
appearance: none;
|
|
32
|
+
background: ${cssVars['vira-color-slider-gradient'].value};
|
|
33
|
+
height: 9px;
|
|
34
|
+
border-radius: 4px;
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
${ViraInput} {
|
|
39
|
+
width: 76px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.coordinate {
|
|
43
|
+
font-size: 18px;
|
|
44
|
+
margin-top: -4px;
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
},
|
|
48
|
+
events: {
|
|
49
|
+
valueChange: defineElementEvent(),
|
|
50
|
+
},
|
|
51
|
+
render({ inputs, events, dispatch, cssVars }) {
|
|
52
|
+
const formatDefinition = colorFormats[inputs.colorFormatName];
|
|
53
|
+
const coordinateDefinition = formatDefinition.coords[inputs.colorCoordinateName];
|
|
54
|
+
if (!coordinateDefinition) {
|
|
55
|
+
throw new Error(`Invalid color coordinate '${inputs.colorCoordinateName}' for color format '${inputs.colorFormatName}'`);
|
|
56
|
+
}
|
|
57
|
+
const totalStops = 10;
|
|
58
|
+
const colorStops = createArray(totalStops, (index) => {
|
|
59
|
+
const value = coordinateDefinition.min +
|
|
60
|
+
(coordinateDefinition.max - coordinateDefinition.min) * (index / totalStops);
|
|
61
|
+
const stopColor = new Color({
|
|
62
|
+
[inputs.colorFormatName]: {
|
|
63
|
+
...inputs.color[inputs.colorFormatName],
|
|
64
|
+
[inputs.colorCoordinateName]: value,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
return stopColor.toCss()[formatDefinition.conversionFormat];
|
|
68
|
+
});
|
|
69
|
+
const gradient = css `linear-gradient(to right, ${unsafeCSS(colorStops.join(','))})`;
|
|
70
|
+
const coordinateValue = assertWrap.isNumber(inputs.color[inputs.colorFormatName][inputs.colorCoordinateName]);
|
|
71
|
+
const displayValue = coordinateDefinition.radix
|
|
72
|
+
? Math.round(coordinateValue)
|
|
73
|
+
.toString(coordinateDefinition.radix)
|
|
74
|
+
.toUpperCase()
|
|
75
|
+
.padStart(coordinateDefinition.radixPad || 0, '0')
|
|
76
|
+
: String(coordinateValue);
|
|
77
|
+
return html `
|
|
78
|
+
<span class="coordinate">${inputs.colorCoordinateName.toUpperCase()}</span>
|
|
79
|
+
<input
|
|
80
|
+
type="range"
|
|
81
|
+
style=${css `
|
|
82
|
+
${cssVars['vira-color-slider-gradient'].name}: ${gradient};
|
|
83
|
+
`}
|
|
84
|
+
step=${Math.pow(10, coordinateDefinition.digits ? -coordinateDefinition.digits : 0)}
|
|
85
|
+
${onDomRendered((element) => {
|
|
86
|
+
/**
|
|
87
|
+
* We must set these imperatively to force the input element to match the
|
|
88
|
+
* inputs, otherwise when swapping color formats these color sliders don't
|
|
89
|
+
* update correctly.
|
|
90
|
+
*/
|
|
91
|
+
assert.instanceOf(element, HTMLInputElement);
|
|
92
|
+
element.min = String(coordinateDefinition.min);
|
|
93
|
+
element.max = String(coordinateDefinition.max);
|
|
94
|
+
element.value = String(coordinateValue);
|
|
95
|
+
})}
|
|
96
|
+
${listen('input', (event) => {
|
|
97
|
+
const element = extractEventTarget(event, HTMLInputElement);
|
|
98
|
+
const newValue = Number(element.value);
|
|
99
|
+
if (isNaN(newValue)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
dispatch(new events.valueChange({
|
|
103
|
+
detail: newValue,
|
|
104
|
+
}));
|
|
105
|
+
})}
|
|
106
|
+
/>
|
|
107
|
+
<${ViraInput.assign({
|
|
108
|
+
value: displayValue,
|
|
109
|
+
})}
|
|
110
|
+
${listen(ViraInput.events.valueChange, (event) => {
|
|
111
|
+
const newValue = coordinateDefinition.radix
|
|
112
|
+
? parseInt(event.detail, coordinateDefinition.radix)
|
|
113
|
+
: Number(event.detail);
|
|
114
|
+
if (isNaN(newValue)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
dispatch(new events.valueChange({
|
|
118
|
+
detail: newValue,
|
|
119
|
+
}));
|
|
120
|
+
})}
|
|
121
|
+
></${ViraInput}>
|
|
122
|
+
`;
|
|
123
|
+
},
|
|
124
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Color } from '@electrovir/color/dist/data/color-class/color.js';
|
|
2
|
+
/**
|
|
3
|
+
* Show a background and/or foreground color. Note that if a foreground color is provided that it is
|
|
4
|
+
* not actually applied to anything, you must provide a child element for it to be applied to.
|
|
5
|
+
*
|
|
6
|
+
* @category Elements
|
|
7
|
+
*/
|
|
8
|
+
export declare const ViraColorSwatch: import("element-vir").DeclarativeElementDefinition<"vira-color-swatch", ((Required<Pick<{
|
|
9
|
+
foregroundColor: string | Readonly<Color>;
|
|
10
|
+
backgroundColor: string | Readonly<Color>;
|
|
11
|
+
}, "foregroundColor">> & Partial<Pick<{
|
|
12
|
+
foregroundColor: string | Readonly<Color>;
|
|
13
|
+
backgroundColor: string | Readonly<Color>;
|
|
14
|
+
}, "backgroundColor">>) | (Required<Pick<{
|
|
15
|
+
foregroundColor: string | Readonly<Color>;
|
|
16
|
+
backgroundColor: string | Readonly<Color>;
|
|
17
|
+
}, "backgroundColor">> & Partial<Pick<{
|
|
18
|
+
foregroundColor: string | Readonly<Color>;
|
|
19
|
+
backgroundColor: string | Readonly<Color>;
|
|
20
|
+
}, "foregroundColor">>)) & {}, {}, {}, "vira-color-swatch-", "vira-color-swatch-", readonly [], readonly []>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* node:coverage disable */
|
|
2
|
+
import { css, defineElement, html, unsafeCSS } from 'element-vir';
|
|
3
|
+
/**
|
|
4
|
+
* Show a background and/or foreground color. Note that if a foreground color is provided that it is
|
|
5
|
+
* not actually applied to anything, you must provide a child element for it to be applied to.
|
|
6
|
+
*
|
|
7
|
+
* @category Elements
|
|
8
|
+
*/
|
|
9
|
+
export const ViraColorSwatch = defineElement()({
|
|
10
|
+
tagName: 'vira-color-swatch',
|
|
11
|
+
styles: css `
|
|
12
|
+
:host {
|
|
13
|
+
display: flex;
|
|
14
|
+
height: 400px;
|
|
15
|
+
width: 400px;
|
|
16
|
+
border: 1px solid black;
|
|
17
|
+
max-height: 100%;
|
|
18
|
+
max-width: 100%;
|
|
19
|
+
container-type: size;
|
|
20
|
+
overflow: hidden;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
div {
|
|
24
|
+
flex-grow: 1;
|
|
25
|
+
height: 100%;
|
|
26
|
+
max-height: 100%;
|
|
27
|
+
width: 100%;
|
|
28
|
+
max-width: 100%;
|
|
29
|
+
display: flex;
|
|
30
|
+
justify-content: center;
|
|
31
|
+
align-items: center;
|
|
32
|
+
}
|
|
33
|
+
`,
|
|
34
|
+
render({ inputs }) {
|
|
35
|
+
const backgroundColor = inputs.backgroundColor || inputs.foregroundColor;
|
|
36
|
+
const foregroundColor = inputs.foregroundColor || 'transparent';
|
|
37
|
+
return html `
|
|
38
|
+
<div
|
|
39
|
+
style=${css `
|
|
40
|
+
background-color: ${unsafeCSS(backgroundColor)};
|
|
41
|
+
color: ${unsafeCSS(foregroundColor)};
|
|
42
|
+
`}
|
|
43
|
+
>
|
|
44
|
+
<slot></slot>
|
|
45
|
+
</div>
|
|
46
|
+
`;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CalculatedContrast, type FontWeight } from '@electrovir/color/dist/data/contrast/contrast.js';
|
|
2
|
+
/**
|
|
3
|
+
* Show contrast details for a calculated contrast.
|
|
4
|
+
*
|
|
5
|
+
* @category Elements
|
|
6
|
+
*/
|
|
7
|
+
export declare const ViraContrastIndicator: import("element-vir").DeclarativeElementDefinition<"vira-contrast-indicator", {
|
|
8
|
+
contrast: Readonly<CalculatedContrast>;
|
|
9
|
+
fontWeight: FontWeight;
|
|
10
|
+
}, {}, {}, "vira-contrast-indicator-", "vira-contrast-indicator-", readonly [], readonly []>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/* node:coverage disable */
|
|
2
|
+
import { contrastLevelLabel, ContrastLevelName, contrastLevels, } from '@electrovir/color/dist/data/contrast/contrast.js';
|
|
3
|
+
import { classMap, css, defineElement, html, unsafeCSS } from 'element-vir';
|
|
4
|
+
/**
|
|
5
|
+
* Show contrast details for a calculated contrast.
|
|
6
|
+
*
|
|
7
|
+
* @category Elements
|
|
8
|
+
*/
|
|
9
|
+
export const ViraContrastIndicator = defineElement()({
|
|
10
|
+
tagName: 'vira-contrast-indicator',
|
|
11
|
+
styles: css `
|
|
12
|
+
:host {
|
|
13
|
+
display: inline-flex;
|
|
14
|
+
max-width: 100%;
|
|
15
|
+
font-size: 12px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.wrapper {
|
|
19
|
+
text-align: center;
|
|
20
|
+
flex-grow: 1;
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
max-width: 100%;
|
|
24
|
+
color: #aaa;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.${unsafeCSS(ContrastLevelName.Invisible)} {
|
|
28
|
+
color: red;
|
|
29
|
+
}
|
|
30
|
+
.${unsafeCSS(ContrastLevelName.Decoration)} {
|
|
31
|
+
color: #ff6600;
|
|
32
|
+
}
|
|
33
|
+
.${unsafeCSS(ContrastLevelName.Placeholder)} {
|
|
34
|
+
color: #a5a520;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.gauge {
|
|
38
|
+
align-self: center;
|
|
39
|
+
background-color: currentColor;
|
|
40
|
+
display: flex;
|
|
41
|
+
padding: 1px;
|
|
42
|
+
gap: 1px;
|
|
43
|
+
margin-bottom: 2px;
|
|
44
|
+
/* Sure sure if I actually want to keep this. */
|
|
45
|
+
display: none;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.gauge-level {
|
|
49
|
+
width: 10px;
|
|
50
|
+
height: 2px;
|
|
51
|
+
|
|
52
|
+
&.active {
|
|
53
|
+
background-color: white;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.gauge-text + .gauge-text {
|
|
58
|
+
border-left: 1px solid #ccc;
|
|
59
|
+
padding-left: 1ex;
|
|
60
|
+
}
|
|
61
|
+
`,
|
|
62
|
+
render({ inputs }) {
|
|
63
|
+
const gaugeLevels = contrastLevels
|
|
64
|
+
.toReversed()
|
|
65
|
+
.slice(1)
|
|
66
|
+
.map((level) => {
|
|
67
|
+
return html `
|
|
68
|
+
<div
|
|
69
|
+
class="gauge-level ${classMap({
|
|
70
|
+
active: level.min <= Math.abs(inputs.contrast.contrast),
|
|
71
|
+
})}"
|
|
72
|
+
></div>
|
|
73
|
+
`;
|
|
74
|
+
});
|
|
75
|
+
const title = [
|
|
76
|
+
inputs.contrast.contrastLevel.description,
|
|
77
|
+
'\nFont weights to font sizes:',
|
|
78
|
+
JSON.stringify(inputs.contrast.fontSizes, null, 4),
|
|
79
|
+
].join('\n');
|
|
80
|
+
const fontSize = inputs.contrast.fontSizes[inputs.fontWeight] > 150
|
|
81
|
+
? '-'
|
|
82
|
+
: `${inputs.contrast.fontSizes[inputs.fontWeight]}px`;
|
|
83
|
+
return html `
|
|
84
|
+
<div title=${title} class="wrapper ${inputs.contrast.contrastLevel.name}">
|
|
85
|
+
<div class="gauge">${gaugeLevels}</div>
|
|
86
|
+
<span>
|
|
87
|
+
<span class="gauge-text">${Math.round(inputs.contrast.contrast)} Lc</span>
|
|
88
|
+
<span class="gauge-text">
|
|
89
|
+
${contrastLevelLabel[inputs.contrast.contrastLevel.name]}
|
|
90
|
+
</span>
|
|
91
|
+
<span class="gauge-text">${fontSize}</span>
|
|
92
|
+
</span>
|
|
93
|
+
</div>
|
|
94
|
+
`;
|
|
95
|
+
},
|
|
96
|
+
});
|
package/dist/elements/index.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
export * from './color/vira-all-color-space-sliders.element.js';
|
|
2
|
+
export * from './color/vira-all-spaces-color-picker.element.js';
|
|
3
|
+
export * from './color/vira-color-details.element.js';
|
|
4
|
+
export * from './color/vira-color-format-sliders.element.js';
|
|
5
|
+
export * from './color/vira-color-pair-contrast-summary.element.js';
|
|
6
|
+
export * from './color/vira-color-pair.element.js';
|
|
7
|
+
export * from './color/vira-color-picker.element.js';
|
|
8
|
+
export * from './color/vira-color-slider.element.js';
|
|
9
|
+
export * from './color/vira-color-swatch.element.js';
|
|
10
|
+
export * from './color/vira-contrast-indicator.element.js';
|
|
1
11
|
export * from './pop-up/vira-menu-item.element.js';
|
|
2
12
|
export * from './pop-up/vira-menu-trigger.element.js';
|
|
3
13
|
export * from './pop-up/vira-menu.element.js';
|
package/dist/elements/index.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
export * from './color/vira-all-color-space-sliders.element.js';
|
|
2
|
+
export * from './color/vira-all-spaces-color-picker.element.js';
|
|
3
|
+
export * from './color/vira-color-details.element.js';
|
|
4
|
+
export * from './color/vira-color-format-sliders.element.js';
|
|
5
|
+
export * from './color/vira-color-pair-contrast-summary.element.js';
|
|
6
|
+
export * from './color/vira-color-pair.element.js';
|
|
7
|
+
export * from './color/vira-color-picker.element.js';
|
|
8
|
+
export * from './color/vira-color-slider.element.js';
|
|
9
|
+
export * from './color/vira-color-swatch.element.js';
|
|
10
|
+
export * from './color/vira-contrast-indicator.element.js';
|
|
1
11
|
export * from './pop-up/vira-menu-item.element.js';
|
|
2
12
|
export * from './pop-up/vira-menu-trigger.element.js';
|
|
3
13
|
export * from './pop-up/vira-menu.element.js';
|
|
@@ -34,5 +34,5 @@ export declare const ViraMenuItem: import("element-vir").DeclarativeElementDefin
|
|
|
34
34
|
* containers (e.g. `ViraPopUpTrigger`) listen to this to close the pop-up on selection,
|
|
35
35
|
* gated by `keepOpenAfterInteraction`.
|
|
36
36
|
*/
|
|
37
|
-
activate: import("element-vir").
|
|
37
|
+
activate: import("element-vir").DefineElementEvent<undefined>;
|
|
38
38
|
}, "vira-menu-item-selected" | "vira-menu-item-disabled" | "vira-menu-item-enabled" | "vira-menu-item-default-icon" | "vira-menu-item-default-styles", "vira-menu-item-icon-gap" | "vira-menu-item-padding" | "vira-menu-item-border-radius", readonly [], readonly []>;
|