@oscarpalmer/oui 0.40.0 → 0.42.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/css/color-picker.css +80 -69
- package/dist/css/listbox.css +169 -0
- package/dist/js/color-picker/color-picker.constants.d.mts +2 -2
- package/dist/js/color-picker/color-picker.constants.mjs +5 -3
- package/dist/js/color-picker/color-picker.dom.d.mts +1 -1
- package/dist/js/color-picker/color-picker.dom.mjs +31 -14
- package/dist/js/color-picker/color-picker.event.d.mts +2 -2
- package/dist/js/color-picker/color-picker.event.mjs +232 -1
- package/dist/js/color-picker/color-picker.form.d.mts +1 -1
- package/dist/js/color-picker/color-picker.form.mjs +1 -3
- package/dist/js/color-picker/color-picker.misc.d.mts +2 -2
- package/dist/js/color-picker/color-picker.misc.mjs +104 -2
- package/dist/js/color-picker/color-picker.model.d.mts +2 -2
- package/dist/js/color-picker/color-picker.output.d.mts +1 -1
- package/dist/js/color-picker/color-picker.output.mjs +7 -8
- package/dist/js/color-picker/color-picker.state.d.mts +1 -1
- package/dist/js/color-picker/color-picker.state.mjs +167 -1
- package/dist/js/color-picker/index.d.mts +7 -15
- package/dist/js/color-picker/index.mjs +11 -6
- package/dist/js/{color-picker.constants-D1mxw_Le.d.mts → color-picker.constants-BZgXQr5o.d.mts} +6 -8
- package/dist/js/{color-picker.misc-CtsXGrOe.d.mts → color-picker.misc-BIS3R6jk.d.mts} +8 -4
- package/dist/js/combobox/combobox.constants.d.mts +1 -1
- package/dist/js/combobox/combobox.dom.d.mts +14 -14
- package/dist/js/combobox/combobox.dom.mjs +15 -17
- package/dist/js/combobox/combobox.event.d.mts +8 -8
- package/dist/js/combobox/combobox.event.mjs +1 -2
- package/dist/js/combobox/combobox.misc.d.mts +2 -2
- package/dist/js/combobox/combobox.misc.mjs +1 -2
- package/dist/js/combobox/combobox.model.d.mts +2 -2
- package/dist/js/combobox/combobox.state.d.mts +3 -4
- package/dist/js/combobox/combobox.state.mjs +1 -2
- package/dist/js/combobox/index.d.mts +8 -19
- package/dist/js/combobox/index.mjs +21 -23
- package/dist/js/{combobox.constants-DZVkMP5g.d.mts → combobox.constants-Hb3bqqQJ.d.mts} +3 -3
- package/dist/js/combobox.misc-DRDFk6X8.d.mts +26 -0
- package/dist/js/combobox.model-gjEI2VqZ.d.mts +46 -0
- package/dist/js/{combobox.state-BfJ3Hxg8.mjs → combobox.state-AstCICiH.mjs} +30 -41
- package/dist/js/dialog/dialog.model.d.mts +1 -1
- package/dist/js/dialog/index.d.mts +1 -1
- package/dist/js/{dialog.model-DX2mndMh.d.mts → dialog.model-Dv_h9Kns.d.mts} +3 -3
- package/dist/js/floatable/floatable.embedded.d.mts +1 -1
- package/dist/js/floatable/floatable.embedded.mjs +2 -2
- package/dist/js/floatable/floatable.standalone.d.mts +1 -1
- package/dist/js/floatable/floatable.standalone.mjs +1 -2
- package/dist/js/{floatable.embedded-MeTyXjFn.d.mts → floatable.embedded-ncshL3Sa.d.mts} +3 -3
- package/dist/js/focus-trap/focus-trap.embedded.d.mts +1 -1
- package/dist/js/focus-trap/focus-trap.embedded.mjs +10 -9
- package/dist/js/focus-trap/focus-trap.model.d.mts +1 -1
- package/dist/js/focus-trap/focus-trap.standalone.d.mts +2 -2
- package/dist/js/focus-trap/focus-trap.standalone.mjs +1 -2
- package/dist/js/{focus-trap.embedded-DIU05m1z.d.mts → focus-trap.embedded-DpcPkP7c.d.mts} +3 -3
- package/dist/js/{focus-trap.model-BeX6UYlw.d.mts → focus-trap.model-CpltX5B5.d.mts} +1 -1
- package/dist/js/index.d.mts +16 -16
- package/dist/js/index.mjs +3 -3
- package/dist/js/internal/attributable.d.mts +1 -1
- package/dist/js/internal/draggable/draggable.model.d.mts +1 -1
- package/dist/js/internal/draggable/index.d.mts +8 -8
- package/dist/js/internal/draggable/index.mjs +27 -18
- package/dist/js/internal/l10n/index.d.mts +5 -0
- package/dist/js/internal/l10n/index.mjs +147 -0
- package/dist/js/internal/l10n/l10n.model.d.mts +2 -0
- package/dist/js/{l10n → internal/l10n}/l10n.model.mjs +5 -2
- package/dist/js/internal/misc.d.mts +2 -2
- package/dist/js/internal/navigable/index.d.mts +3 -3
- package/dist/js/internal/navigable/index.mjs +1 -1
- package/dist/js/internal/navigable/navigable.model.d.mts +1 -1
- package/dist/js/internal/option-list/option-list.constants.d.mts +8 -0
- package/dist/js/internal/option-list/option-list.constants.mjs +22 -0
- package/dist/js/internal/option-list/option-list.data.d.mts +22 -0
- package/dist/js/internal/option-list/option-list.data.mjs +1 -0
- package/dist/js/internal/option-list/option-list.dom.d.mts +18 -0
- package/dist/js/internal/option-list/option-list.dom.mjs +1 -0
- package/dist/js/internal/option-list/option-list.event.d.mts +6 -0
- package/dist/js/internal/{listbox/listbox.event.mjs → option-list/option-list.event.mjs} +7 -7
- package/dist/js/internal/option-list/option-list.form.d.mts +7 -0
- package/dist/js/internal/{listbox/listbox.form.mjs → option-list/option-list.form.mjs} +10 -13
- package/dist/js/internal/option-list/option-list.misc.d.mts +13 -0
- package/dist/js/internal/option-list/option-list.misc.mjs +1 -0
- package/dist/js/internal/option-list/option-list.model.d.mts +2 -0
- package/dist/js/internal/option-list/option-list.state.d.mts +8 -0
- package/dist/js/internal/option-list/option-list.state.mjs +39 -0
- package/dist/js/l10n/index.d.mts +3 -9
- package/dist/js/l10n/index.mjs +1 -107
- package/dist/js/l10n.model-D1E1u35L.d.mts +54 -0
- package/dist/js/listbox/index.d.mts +6 -17
- package/dist/js/listbox/index.mjs +22 -23
- package/dist/js/listbox/{constants.listbox.d.mts → listbox.constants.d.mts} +1 -1
- package/dist/js/listbox/{constants.listbox.mjs → listbox.constants.mjs} +1 -1
- package/dist/js/listbox/listbox.dom.d.mts +5 -0
- package/dist/js/listbox/listbox.dom.mjs +1 -0
- package/dist/js/listbox/listbox.event.d.mts +9 -0
- package/dist/js/listbox/listbox.event.mjs +1 -0
- package/dist/js/listbox/listbox.misc.d.mts +2 -0
- package/dist/js/listbox/listbox.misc.mjs +1 -0
- package/dist/js/listbox/listbox.model.d.mts +2 -0
- package/dist/js/listbox/listbox.model.mjs +1 -0
- package/dist/js/listbox/listbox.state.d.mts +9 -0
- package/dist/js/listbox/listbox.state.mjs +1 -0
- package/dist/js/{constants.listbox-C5Ap6Ag_.d.mts → listbox.constants-DOBMwKup.d.mts} +3 -3
- package/dist/js/listbox.misc-DwfB4Mu_.d.mts +24 -0
- package/dist/js/listbox.model-C0MYWXZe.d.mts +20 -0
- package/dist/js/listbox.state-BrN296BM.mjs +240 -0
- package/dist/js/menu/index.mjs +10 -6
- package/dist/js/menu/menu.model.d.mts +7 -7
- package/dist/js/movable/movable.embedded.d.mts +1 -1
- package/dist/js/movable/movable.embedded.mjs +21 -18
- package/dist/js/movable/movable.model.d.mts +1 -1
- package/dist/js/movable/movable.standalone.d.mts +2 -2
- package/dist/js/movable/movable.standalone.mjs +1 -2
- package/dist/js/{movable.embedded-DoyXLegc.d.mts → movable.embedded-C1bDTLGs.d.mts} +2 -2
- package/dist/js/{movable.model-BHaK_mKw.d.mts → movable.model-D9nnPWKk.d.mts} +41 -41
- package/dist/js/{navigable.model-BPOM8DZk.d.mts → navigable.model-BqoR6iBv.d.mts} +1 -1
- package/dist/js/{listbox.data-BQyZGKgr.mjs → option-list.data-CgMyUwPc.mjs} +70 -71
- package/dist/js/option-list.model-CCPUlPeX.d.mts +169 -0
- package/dist/js/popover/index.d.mts +2 -2
- package/dist/js/popover/index.mjs +1 -1
- package/dist/js/popover/popover.model.d.mts +1 -1
- package/dist/js/{popover.model-ubKNG612.d.mts → popover.model-DiLdz0Hc.d.mts} +4 -4
- package/dist/js/resizable/resizable.embedded.d.mts +1 -1
- package/dist/js/resizable/resizable.embedded.mjs +16 -7
- package/dist/js/resizable/resizable.model.d.mts +2 -2
- package/dist/js/resizable/resizable.model.mjs +4 -1
- package/dist/js/resizable/resizable.standalone.d.mts +2 -2
- package/dist/js/resizable/resizable.standalone.mjs +1 -2
- package/dist/js/{resizable.embedded-Bf1qBUdt.d.mts → resizable.embedded-D9mb-Wm_.d.mts} +2 -2
- package/dist/js/{resizable.model-BwzJcTVJ.d.mts → resizable.model-vCxaFdOA.d.mts} +10 -4
- package/dist/js/sortable/sortable.embedded.d.mts +1 -1
- package/dist/js/sortable/sortable.embedded.mjs +46 -38
- package/dist/js/sortable/sortable.model.d.mts +1 -1
- package/dist/js/sortable/sortable.standalone.d.mts +2 -2
- package/dist/js/sortable/sortable.standalone.mjs +1 -2
- package/dist/js/{sortable.embedded-DzBKAwSG.d.mts → sortable.embedded-CrEGff9k.d.mts} +2 -2
- package/dist/js/splitter/index.d.mts +1 -1
- package/dist/js/splitter/index.mjs +1 -1
- package/dist/js/splitter/splitter.model.d.mts +1 -1
- package/dist/js/{splitter.model-DOLNjLVS.d.mts → splitter.model-C24W6eZ7.d.mts} +2 -2
- package/dist/js/tabs/index.d.mts +2 -2
- package/dist/js/tabs/index.mjs +1 -1
- package/dist/js/tabs/tabs.model.d.mts +1 -1
- package/dist/js/{tabs.model-DRBX_JtI.d.mts → tabs.model-BHPy7fPo.d.mts} +1 -1
- package/dist/js/toolbar/toolbar.model.d.mts +2 -2
- package/dist/js/tooltip/index.d.mts +2 -2
- package/dist/js/tooltip/index.mjs +1 -1
- package/dist/js/tooltip/tooltip.model.d.mts +1 -1
- package/dist/js/{tooltip.model-DRkY_BsL.d.mts → tooltip.model-BpNStw5z.d.mts} +3 -3
- package/package.json +3 -3
- package/dist/js/color-picker.event-Cksj5TvS.mjs +0 -500
- package/dist/js/combobox.misc-C1tPZZDi.d.mts +0 -22
- package/dist/js/combobox.model-oDV06XCN.d.mts +0 -44
- package/dist/js/internal/listbox/listbox.constants.d.mts +0 -8
- package/dist/js/internal/listbox/listbox.constants.mjs +0 -22
- package/dist/js/internal/listbox/listbox.data.d.mts +0 -19
- package/dist/js/internal/listbox/listbox.data.mjs +0 -2
- package/dist/js/internal/listbox/listbox.dom.d.mts +0 -65
- package/dist/js/internal/listbox/listbox.dom.mjs +0 -2
- package/dist/js/internal/listbox/listbox.event.d.mts +0 -4
- package/dist/js/internal/listbox/listbox.form.d.mts +0 -5
- package/dist/js/internal/listbox/listbox.misc.d.mts +0 -11
- package/dist/js/internal/listbox/listbox.misc.mjs +0 -2
- package/dist/js/internal/listbox/listbox.model.d.mts +0 -2
- package/dist/js/internal/listbox/listbox.state.d.mts +0 -6
- package/dist/js/internal/listbox/listbox.state.mjs +0 -39
- package/dist/js/l10n/l10n.model.d.mts +0 -2
- package/dist/js/l10n.model-D6a9frgl.d.mts +0 -26
- package/dist/js/listbox/event.listbox.d.mts +0 -7
- package/dist/js/listbox/event.listbox.mjs +0 -48
- package/dist/js/listbox/misc.listbox.d.mts +0 -2
- package/dist/js/listbox/misc.listbox.mjs +0 -2
- package/dist/js/listbox/state.listbox.d.mts +0 -9
- package/dist/js/listbox/state.listbox.mjs +0 -2
- package/dist/js/listbox.model-CuBOj4qe.d.mts +0 -129
- package/dist/js/misc.listbox-CjfBUbHD.mjs +0 -154
- package/dist/js/misc.listbox-CtoGvXQo.d.mts +0 -20
- /package/dist/js/internal/{listbox/listbox.model.mjs → option-list/option-list.model.mjs} +0 -0
|
@@ -1,2 +1,233 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { COLOR_PICKER_ATTRIBUTE_COPY_ERROR, COLOR_PICKER_ATTRIBUTE_COPY_SUCCESS, COLOR_PICKER_EXPRESSION_HEX_PREFIX, COLOR_PICKER_KEYS, COLOR_PICKER_SELECTOR_COPY, COLOR_PICKER_SELECTOR_OUTPUT_INPUT, COLOR_PICKER_SELECTOR_WELL, COLOR_PICKER_SELECTOR_WELL_KNOB, COLOR_PICKER_SYMBOL, COLOR_PICKER_TAGNAME } from "./color-picker.constants.mjs";
|
|
2
|
+
import { copyValue } from "../internal/misc.mjs";
|
|
3
|
+
import { OuiColorPickerEvent } from "./color-picker.model.mjs";
|
|
4
|
+
import { getColorPickerOutputFormat, updateColorPickerOutputCopyLabel } from "./color-picker.output.mjs";
|
|
5
|
+
import { setColorPickerValues } from "./color-picker.misc.mjs";
|
|
6
|
+
import { setAttribute, setAttributes } from "@oscarpalmer/toretto/attribute";
|
|
7
|
+
import { dispatch, getEventPosition, on } from "@oscarpalmer/toretto/event";
|
|
8
|
+
import { findAncestor } from "@oscarpalmer/toretto/find";
|
|
9
|
+
import { toggleStyles } from "@oscarpalmer/toretto/style";
|
|
10
|
+
import { clamp } from "@oscarpalmer/atoms/number";
|
|
11
|
+
import { supportsTouch } from "@oscarpalmer/toretto/touch";
|
|
12
|
+
import { isHexColor } from "@oscarpalmer/atoms/color";
|
|
13
|
+
//#region src/js/color-picker/color-picker.event.ts
|
|
14
|
+
function cancelMove(parameters) {
|
|
15
|
+
parameters.state.component.color.value.hexa = parameters.value;
|
|
16
|
+
setColorPickerValues(parameters.state, true);
|
|
17
|
+
colorPickerMovement.parameters = void 0;
|
|
18
|
+
styleToggler.remove();
|
|
19
|
+
}
|
|
20
|
+
function onClick(event) {
|
|
21
|
+
const button = findAncestor(event, COLOR_PICKER_SELECTOR_COPY);
|
|
22
|
+
if (!(button instanceof HTMLButtonElement)) return;
|
|
23
|
+
setAttributes(button, {
|
|
24
|
+
[COLOR_PICKER_ATTRIBUTE_COPY_ERROR]: void 0,
|
|
25
|
+
[COLOR_PICKER_ATTRIBUTE_COPY_SUCCESS]: void 0
|
|
26
|
+
});
|
|
27
|
+
const state = findAncestor(event, COLOR_PICKER_TAGNAME)?.[COLOR_PICKER_SYMBOL];
|
|
28
|
+
if (state == null || state.component.disabled) return;
|
|
29
|
+
const { component } = state;
|
|
30
|
+
const copy = button.dataset.color == null ? component.content.output?.copy : component.anchor.copy;
|
|
31
|
+
if (copy == null) return;
|
|
32
|
+
if (copy.timer != null) {
|
|
33
|
+
clearTimeout(copy.timer);
|
|
34
|
+
copy.timer = void 0;
|
|
35
|
+
}
|
|
36
|
+
const color = button.dataset.color ?? getColorPickerOutputFormat(state);
|
|
37
|
+
if (color == null) return;
|
|
38
|
+
let value;
|
|
39
|
+
switch (color) {
|
|
40
|
+
case "hex":
|
|
41
|
+
value = component.color.value.toHexString(component.alpha);
|
|
42
|
+
break;
|
|
43
|
+
case "hsl":
|
|
44
|
+
value = component.color.value.toHslString(component.alpha);
|
|
45
|
+
break;
|
|
46
|
+
case "hwb":
|
|
47
|
+
value = component.color.value.toHwbString(component.alpha);
|
|
48
|
+
break;
|
|
49
|
+
case "rgb": value = component.color.value.toRgbString(component.alpha);
|
|
50
|
+
}
|
|
51
|
+
if (value != null) copyValue(value, () => {
|
|
52
|
+
updateColorPickerCopy(copy, COLOR_PICKER_ATTRIBUTE_COPY_SUCCESS);
|
|
53
|
+
}, () => {
|
|
54
|
+
updateColorPickerCopy(copy, COLOR_PICKER_ATTRIBUTE_COPY_ERROR);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function onColorPickerHue(state) {
|
|
58
|
+
const { component } = state;
|
|
59
|
+
const hue = component.content.hue.input.valueAsNumber;
|
|
60
|
+
component.color.value.hsla = {
|
|
61
|
+
...component.color.value.hsla,
|
|
62
|
+
hue
|
|
63
|
+
};
|
|
64
|
+
setColorPickerValues(state, false);
|
|
65
|
+
}
|
|
66
|
+
function onColorPickerInput(state) {
|
|
67
|
+
const { component } = state;
|
|
68
|
+
const { alpha, anchor, color, host } = component;
|
|
69
|
+
const value = anchor.input.value.replace(COLOR_PICKER_EXPRESSION_HEX_PREFIX, "");
|
|
70
|
+
if (value.toLowerCase() === (alpha ? color.value.hexa : color.value.hex).toLowerCase()) return;
|
|
71
|
+
component.value.current = anchor.input.value;
|
|
72
|
+
const { length } = value;
|
|
73
|
+
let valid;
|
|
74
|
+
if (alpha) valid = isHexColor(value, true) && (length === 4 || length === 8);
|
|
75
|
+
else valid = isHexColor(value) && (length === 3 || length === 6);
|
|
76
|
+
if (valid) {
|
|
77
|
+
if (length === 3 || length === 6) color.value.hex = value;
|
|
78
|
+
else color.value.hexa = value;
|
|
79
|
+
}
|
|
80
|
+
setColorPickerValues(state, false, anchor.input.value);
|
|
81
|
+
dispatch(host, new OuiColorPickerEvent("oui:input", color.value, valid));
|
|
82
|
+
}
|
|
83
|
+
function onColorPickerOpacity(state, input) {
|
|
84
|
+
state.component.color.value.alpha = input.valueAsNumber;
|
|
85
|
+
setColorPickerValues(state, false);
|
|
86
|
+
}
|
|
87
|
+
function onColorPickerOutputFormat(state) {
|
|
88
|
+
const { content } = state.component;
|
|
89
|
+
const { items, toggle } = content.output ?? {};
|
|
90
|
+
if (items == null || toggle == null) return;
|
|
91
|
+
const attribute = `${COLOR_PICKER_TAGNAME}-output-${toggle.value}`;
|
|
92
|
+
for (const item of items) item.hidden = !item.hasAttribute(attribute);
|
|
93
|
+
if (content.output?.copy != null) updateColorPickerOutputCopyLabel(state, content.output.copy.button);
|
|
94
|
+
}
|
|
95
|
+
function onColorPickerOutputValue(event, state) {
|
|
96
|
+
const input = findAncestor(event, COLOR_PICKER_SELECTOR_OUTPUT_INPUT);
|
|
97
|
+
if (!(input instanceof HTMLInputElement)) return;
|
|
98
|
+
const color = input.dataset.color;
|
|
99
|
+
const property = input.dataset.property;
|
|
100
|
+
if (color == null || property == null) return;
|
|
101
|
+
if (outputTimer != null) clearTimeout(outputTimer);
|
|
102
|
+
outputTimer = setTimeout(() => {
|
|
103
|
+
outputTimer = void 0;
|
|
104
|
+
state.component.color.value[color] = {
|
|
105
|
+
...state.component.color.value[color],
|
|
106
|
+
[property]: input.valueAsNumber
|
|
107
|
+
};
|
|
108
|
+
setColorPickerValues(state, false);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function onEnter(state) {
|
|
112
|
+
const { component, form } = state;
|
|
113
|
+
const { alpha, anchor, color } = component;
|
|
114
|
+
const input = anchor.input.value.replace(COLOR_PICKER_EXPRESSION_HEX_PREFIX, "");
|
|
115
|
+
const short = alpha ? input.length === 4 : input.length === 3;
|
|
116
|
+
if (isHexColor(input, alpha) && short) anchor.input.value = color.value.toHexString(alpha);
|
|
117
|
+
form.internals.form?.requestSubmit();
|
|
118
|
+
}
|
|
119
|
+
function onKeydown(event) {
|
|
120
|
+
if (colorPickerMovement.parameters != null && event.key === "Escape") {
|
|
121
|
+
cancelMove(colorPickerMovement.parameters);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const knob = findAncestor(event, COLOR_PICKER_SELECTOR_WELL_KNOB);
|
|
125
|
+
if (!(event.key === "Enter" && findAncestor(event, "[oui-color-picker-input]") != null || COLOR_PICKER_KEYS.has(event.key) && knob != null)) return;
|
|
126
|
+
const state = findAncestor(event, COLOR_PICKER_TAGNAME)?.[COLOR_PICKER_SYMBOL];
|
|
127
|
+
if (state == null || state.component.disabled || state.component.readonly) return;
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
const { component } = state;
|
|
130
|
+
if (event.key === "Enter") {
|
|
131
|
+
onEnter(state);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (knob == null) return;
|
|
135
|
+
const modifier = event.shiftKey ? 10 : 1;
|
|
136
|
+
let { lightness, saturation } = component.color.value.hsl;
|
|
137
|
+
switch (event.key) {
|
|
138
|
+
case "ArrowDown":
|
|
139
|
+
lightness -= 1 * modifier;
|
|
140
|
+
break;
|
|
141
|
+
case "ArrowLeft":
|
|
142
|
+
saturation -= 1 * modifier;
|
|
143
|
+
break;
|
|
144
|
+
case "ArrowRight":
|
|
145
|
+
saturation += 1 * modifier;
|
|
146
|
+
break;
|
|
147
|
+
case "ArrowUp":
|
|
148
|
+
lightness += 1 * modifier;
|
|
149
|
+
break;
|
|
150
|
+
case "End":
|
|
151
|
+
lightness = 0;
|
|
152
|
+
break;
|
|
153
|
+
case "Home":
|
|
154
|
+
lightness = 100;
|
|
155
|
+
break;
|
|
156
|
+
case "PageDown":
|
|
157
|
+
lightness -= 10;
|
|
158
|
+
break;
|
|
159
|
+
case "PageUp": lightness += 10;
|
|
160
|
+
}
|
|
161
|
+
component.color.value.hsl = {
|
|
162
|
+
...state.component.color.value.hsl,
|
|
163
|
+
lightness: clamp(lightness, 0, 100),
|
|
164
|
+
saturation: clamp(saturation, 0, 100)
|
|
165
|
+
};
|
|
166
|
+
setColorPickerValues(state, false);
|
|
167
|
+
}
|
|
168
|
+
function onPointerdown(event) {
|
|
169
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || (supportsTouch.value ? event.type === "mousedown" : event.type === "touchstart" || event.button !== 0)) return;
|
|
170
|
+
const well = findAncestor(event, COLOR_PICKER_SELECTOR_WELL);
|
|
171
|
+
if (well == null) return;
|
|
172
|
+
const element = findAncestor(event, COLOR_PICKER_TAGNAME);
|
|
173
|
+
if (element == null) return;
|
|
174
|
+
if (supportsTouch.value) event.preventDefault();
|
|
175
|
+
if (getEventPosition(event) == null) return;
|
|
176
|
+
const state = element?.[COLOR_PICKER_SYMBOL];
|
|
177
|
+
if (state == null || state.component.disabled || state.component.readonly) return;
|
|
178
|
+
colorPickerMovement.parameters = {
|
|
179
|
+
state,
|
|
180
|
+
rectangle: well.getBoundingClientRect(),
|
|
181
|
+
value: state.component.color.value.hexa
|
|
182
|
+
};
|
|
183
|
+
styleToggler.set();
|
|
184
|
+
}
|
|
185
|
+
function onPointermove(event) {
|
|
186
|
+
if (colorPickerMovement.parameters == null) return;
|
|
187
|
+
const position = getEventPosition(event);
|
|
188
|
+
if (position != null) updateColorPickerValues(colorPickerMovement.parameters, position);
|
|
189
|
+
}
|
|
190
|
+
function onPointerup(event) {
|
|
191
|
+
if (colorPickerMovement.parameters == null) return;
|
|
192
|
+
const position = getEventPosition(event);
|
|
193
|
+
if (position != null) updateColorPickerValues(colorPickerMovement.parameters, position);
|
|
194
|
+
colorPickerMovement.parameters = void 0;
|
|
195
|
+
styleToggler.remove();
|
|
196
|
+
}
|
|
197
|
+
function updateColorPickerCopy(copy, attribute) {
|
|
198
|
+
const { button } = copy;
|
|
199
|
+
setAttribute(button, attribute, "");
|
|
200
|
+
copy.timer = setTimeout(() => {
|
|
201
|
+
copy.timer = void 0;
|
|
202
|
+
setAttribute(button, attribute, void 0);
|
|
203
|
+
}, styleTime);
|
|
204
|
+
}
|
|
205
|
+
function updateColorPickerValues(parameters, position) {
|
|
206
|
+
const { rectangle, state } = parameters;
|
|
207
|
+
const { x, y } = position;
|
|
208
|
+
const top = clamp((y - rectangle.top) / rectangle.height, 0, 1);
|
|
209
|
+
const left = clamp((x - rectangle.left) / rectangle.width, 0, 1);
|
|
210
|
+
state.component.color.value.hsl = {
|
|
211
|
+
...state.component.color.value.hsl,
|
|
212
|
+
lightness: (1 - top) * 100,
|
|
213
|
+
saturation: left * 100
|
|
214
|
+
};
|
|
215
|
+
setColorPickerValues(state, true);
|
|
216
|
+
}
|
|
217
|
+
const styleToggler = toggleStyles(document.body, {
|
|
218
|
+
touchAction: "none",
|
|
219
|
+
userSelect: "none",
|
|
220
|
+
webkitUserSelect: "none"
|
|
221
|
+
});
|
|
222
|
+
const colorPickerMovement = {};
|
|
223
|
+
const styleTime = 2500;
|
|
224
|
+
let outputTimer;
|
|
225
|
+
on(document, "click", onClick);
|
|
226
|
+
on(document, "keydown", onKeydown, { passive: false });
|
|
227
|
+
on(document, "mousedown", onPointerdown);
|
|
228
|
+
on(document, "pointermove", onPointermove);
|
|
229
|
+
on(document, "pointerup", onPointerup);
|
|
230
|
+
on(document, "touchcancel", onPointerup);
|
|
231
|
+
on(document, "touchstart", onPointerdown, { passive: false });
|
|
232
|
+
//#endregion
|
|
2
233
|
export { colorPickerMovement, onColorPickerHue, onColorPickerInput, onColorPickerOpacity, onColorPickerOutputFormat, onColorPickerOutputValue };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as OuiColorPickerState } from "../color-picker.constants-BZgXQr5o.mjs";
|
|
2
2
|
//#region src/js/color-picker/color-picker.form.d.ts
|
|
3
3
|
export declare function updateColorPickerForm(state: OuiColorPickerState, valid: boolean): void;
|
|
4
4
|
export declare function updateColorPickerValidity(state: OuiColorPickerState, valid: boolean): void;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getLocalization, localize } from "../l10n/index.mjs";
|
|
2
1
|
import { OuiColorPickerEvent } from "./color-picker.model.mjs";
|
|
3
2
|
import { dispatch } from "@oscarpalmer/toretto/event";
|
|
4
3
|
//#region src/js/color-picker/color-picker.form.ts
|
|
@@ -18,8 +17,7 @@ function updateColorPickerValidity(state, valid) {
|
|
|
18
17
|
internals.checkValidity();
|
|
19
18
|
return;
|
|
20
19
|
}
|
|
21
|
-
const
|
|
22
|
-
const message = localization == null ? void 0 : localize(localization, {}, []);
|
|
20
|
+
const message = localizations.localize("invalid", { element: host });
|
|
23
21
|
internals.setValidity({ typeMismatch: true }, message, anchor.input);
|
|
24
22
|
internals.checkValidity();
|
|
25
23
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as setColorPickerLocalizations, c as setColorPickerValues, i as setColorPickerDisabled, l as updateColorPickerLabels, n as getColorPickerOutput, o as setColorPickerRequired, r as getColorPickerValueType, s as setColorPickerValue, t as getColorPickerId
|
|
2
|
-
export { getColorPickerId, getColorPickerOutput, getColorPickerValueType, setColorPickerDisabled, setColorPickerLocalizations, setColorPickerRequired, setColorPickerValue, setColorPickerValues, updateColorPickerLabels
|
|
1
|
+
import { a as setColorPickerLocalizations, c as setColorPickerValues, i as setColorPickerDisabled, l as updateColorPickerLabels, n as getColorPickerOutput, o as setColorPickerRequired, r as getColorPickerValueType, s as setColorPickerValue, t as getColorPickerId } from "../color-picker.misc-BIS3R6jk.mjs";
|
|
2
|
+
export { getColorPickerId, getColorPickerOutput, getColorPickerValueType, setColorPickerDisabled, setColorPickerLocalizations, setColorPickerRequired, setColorPickerValue, setColorPickerValues, updateColorPickerLabels };
|
|
@@ -1,2 +1,104 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { COLOR_PICKER_OUTPUTS, colorPickerLocalizations } from "./color-picker.constants.mjs";
|
|
2
|
+
import { updateColorPickerForm, updateColorPickerValidity } from "./color-picker.form.mjs";
|
|
3
|
+
import { updateColorPickerOutputInputs, updateColorPickerOutputLabels } from "./color-picker.output.mjs";
|
|
4
|
+
import { setAria } from "@oscarpalmer/toretto/aria";
|
|
5
|
+
import { getAttribute } from "@oscarpalmer/toretto/attribute";
|
|
6
|
+
import { getForegroundColor, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isRgbColor, isRgbaColor } from "@oscarpalmer/atoms/color";
|
|
7
|
+
import { setProperty } from "@oscarpalmer/toretto/property";
|
|
8
|
+
//#region src/js/color-picker/color-picker.misc.ts
|
|
9
|
+
function getColorPickerId() {
|
|
10
|
+
index += 1;
|
|
11
|
+
return `oui_color_picker_${index}`;
|
|
12
|
+
}
|
|
13
|
+
function getColorPickerOutput(element) {
|
|
14
|
+
const attribute = getAttribute(element, "output");
|
|
15
|
+
return COLOR_PICKER_OUTPUTS.has(attribute) ? attribute : "none";
|
|
16
|
+
}
|
|
17
|
+
function getColorPickerValueType(state, value) {
|
|
18
|
+
const { alpha } = state.component;
|
|
19
|
+
switch (true) {
|
|
20
|
+
case isHexColor(value, alpha): return alpha ? "hexa" : "hex";
|
|
21
|
+
case isHslColor(value): return "hsl";
|
|
22
|
+
case isHslaColor(value): return "hsla";
|
|
23
|
+
case isHwbColor(value): return "hwb";
|
|
24
|
+
case isHwbaColor(value): return "hwba";
|
|
25
|
+
case isRgbColor(value): return "rgb";
|
|
26
|
+
case isRgbaColor(value): return "rgba";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function setColorPickerLocalizations(first, second) {
|
|
30
|
+
if (second === true) colorPickerLocalizations.setDefaults(first);
|
|
31
|
+
else colorPickerLocalizations.setLanguages(first, second);
|
|
32
|
+
}
|
|
33
|
+
function setColorPickerDisabled(state, type, value) {
|
|
34
|
+
const { component } = state;
|
|
35
|
+
component[type] = value;
|
|
36
|
+
setAria(component.host, type, value);
|
|
37
|
+
component.anchor.input.readOnly = value;
|
|
38
|
+
setAria(component.anchor.input, type, value);
|
|
39
|
+
setProperty(component.content.hue.input, "disabled", component.disabled || component.readonly);
|
|
40
|
+
if (component.anchor.toggle != null) setAria(component.anchor.toggle, "disabled", component.disabled);
|
|
41
|
+
if (component.content.opacity != null) setProperty(component.content.opacity.input, "disabled", component.disabled || component.readonly);
|
|
42
|
+
}
|
|
43
|
+
function setColorPickerRequired(state, value) {
|
|
44
|
+
const { component } = state;
|
|
45
|
+
component.required = value;
|
|
46
|
+
setAria(component.host, "required", value);
|
|
47
|
+
setAria(component.anchor.input, "required", value);
|
|
48
|
+
updateColorPickerValidity(state, isHexColor(component.value.current, component.alpha));
|
|
49
|
+
}
|
|
50
|
+
function setColorPickerValue(state, value, type) {
|
|
51
|
+
if (state == null) return;
|
|
52
|
+
const actual = type ?? getColorPickerValueType(state, value);
|
|
53
|
+
if (actual == null || type != null && type !== actual) return;
|
|
54
|
+
state.component.color.value[actual] = value;
|
|
55
|
+
setColorPickerValues(state, true);
|
|
56
|
+
}
|
|
57
|
+
function setColorPickerValues(state, focus, input) {
|
|
58
|
+
const { component } = state;
|
|
59
|
+
const { anchor, color, content, host, style } = component;
|
|
60
|
+
color.foreground = getForegroundColor(color.value).hex;
|
|
61
|
+
const { alpha, hex, hsl, rgb } = color.value;
|
|
62
|
+
const { hue, lightness, saturation } = hsl;
|
|
63
|
+
const { blue, green, red } = rgb;
|
|
64
|
+
const value = input ?? color.value.toHexString(component.alpha);
|
|
65
|
+
anchor.input.value = value;
|
|
66
|
+
content.hue.input.valueAsNumber = hue;
|
|
67
|
+
if (content.opacity != null) content.opacity.input.valueAsNumber = alpha;
|
|
68
|
+
component.value.current = value;
|
|
69
|
+
style.textContent = `#${host.id} {
|
|
70
|
+
--oui-color-picker-alpha: ${alpha};
|
|
71
|
+
--oui-color-picker-blue: ${blue};
|
|
72
|
+
--oui-color-picker-green: ${green};
|
|
73
|
+
--oui-color-picker-foreground: #${color.foreground};
|
|
74
|
+
--oui-color-picker-hex: #${hex};
|
|
75
|
+
--oui-color-picker-hue: ${hue};
|
|
76
|
+
--oui-color-picker-lightness: ${lightness};
|
|
77
|
+
--oui-color-picker-red: ${red};
|
|
78
|
+
--oui-color-picker-saturation: ${saturation};
|
|
79
|
+
}`;
|
|
80
|
+
updateColorPickerForm(state, isHexColor(component.value.current, component.alpha));
|
|
81
|
+
updateColorPickerOutputInputs(state);
|
|
82
|
+
updateColorPickerWell(state);
|
|
83
|
+
if (focus) content.well.knob.focus();
|
|
84
|
+
}
|
|
85
|
+
function updateColorPickerLabels(state) {
|
|
86
|
+
const { anchor, content, host, localizations } = state.component;
|
|
87
|
+
if (anchor.toggle != null) setAria(anchor.toggle, "label", localizations.localize("toggle", { element: host }));
|
|
88
|
+
content.hue.label.textContent = localizations.localize("hue", { element: host });
|
|
89
|
+
content.well.label.textContent = localizations.localize("wellLabel", { element: host });
|
|
90
|
+
updateColorPickerOutputLabels(state);
|
|
91
|
+
updateColorPickerWell(state);
|
|
92
|
+
if (content.opacity != null) content.opacity.label.textContent = localizations.localize("opacity", { element: host });
|
|
93
|
+
}
|
|
94
|
+
function updateColorPickerWell(state) {
|
|
95
|
+
const { color, content, host, localizations } = state.component;
|
|
96
|
+
const { lightness, saturation } = color.value.hsl;
|
|
97
|
+
setAria(content.well.knob, "valuetext", localizations.localize("wellValue", {
|
|
98
|
+
arguments: [lightness, saturation],
|
|
99
|
+
element: host
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
let index = 0;
|
|
103
|
+
//#endregion
|
|
104
|
+
export { getColorPickerId, getColorPickerOutput, getColorPickerValueType, setColorPickerDisabled, setColorPickerLocalizations, setColorPickerRequired, setColorPickerValue, setColorPickerValues, updateColorPickerLabels };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { GenericOuiColorPickerElement, OuiColorPickerAnchor, OuiColorPickerColor, OuiColorPickerContent, OuiColorPickerContentHue, OuiColorPickerContentOpacity, OuiColorPickerContentOutput, OuiColorPickerContentWell, OuiColorPickerCopy, OuiColorPickerCreateParameters, OuiColorPickerEvent, OuiColorPickerLocalizations, OuiColorPickerMovement, OuiColorPickerMovementParameters, OuiColorPickerOutputColor, OuiColorPickerOutputColorProperty, OuiColorPickerOutputType, OuiColorPickerState, OuiColorPickerStateComponent,
|
|
1
|
+
import { A as OuiColorPickerContentWell, B as OuiColorPickerState, C as GenericOuiColorPickerElement, D as OuiColorPickerContentHue, E as OuiColorPickerContent, F as OuiColorPickerMovement, H as OuiColorPickerValueType, I as OuiColorPickerMovementParameters, L as OuiColorPickerOutputColor, M as OuiColorPickerCreateParameters, N as OuiColorPickerEvent, O as OuiColorPickerContentOpacity, P as OuiColorPickerLocalizations, R as OuiColorPickerOutputColorProperty, T as OuiColorPickerColor, V as OuiColorPickerStateComponent, j as OuiColorPickerCopy, k as OuiColorPickerContentOutput, w as OuiColorPickerAnchor, z as OuiColorPickerOutputType } from "../color-picker.constants-BZgXQr5o.mjs";
|
|
2
|
+
export { GenericOuiColorPickerElement, OuiColorPickerAnchor, OuiColorPickerColor, OuiColorPickerContent, OuiColorPickerContentHue, OuiColorPickerContentOpacity, OuiColorPickerContentOutput, OuiColorPickerContentWell, OuiColorPickerCopy, OuiColorPickerCreateParameters, OuiColorPickerEvent, OuiColorPickerLocalizations, OuiColorPickerMovement, OuiColorPickerMovementParameters, OuiColorPickerOutputColor, OuiColorPickerOutputColorProperty, OuiColorPickerOutputType, OuiColorPickerState, OuiColorPickerStateComponent, OuiColorPickerValueType };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as OuiColorPickerState, L as OuiColorPickerOutputColor, M as OuiColorPickerCreateParameters, j as OuiColorPickerCopy, k as OuiColorPickerContentOutput } from "../color-picker.constants-BZgXQr5o.mjs";
|
|
2
2
|
//#region src/js/color-picker/color-picker.output.d.ts
|
|
3
3
|
export declare function createColorPickerOutput(parameters: OuiColorPickerCreateParameters, copy: OuiColorPickerCopy | undefined): OuiColorPickerContentOutput | undefined;
|
|
4
4
|
export declare function getColorPickerOutputFormat(state: OuiColorPickerState): OuiColorPickerOutputColor | undefined;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getLocalization, localize } from "../l10n/index.mjs";
|
|
2
1
|
import { COLOR_PICKER_ATTRIBUTE_OUTPUT_INPUT, COLOR_PICKER_TAGNAME, colorPickerLocalizations } from "./color-picker.constants.mjs";
|
|
3
2
|
import { setAria } from "@oscarpalmer/toretto/aria";
|
|
4
3
|
import { createElement } from "@oscarpalmer/toretto/create";
|
|
@@ -41,7 +40,7 @@ function createOutputFormat(parameters, copy) {
|
|
|
41
40
|
},
|
|
42
41
|
property: {
|
|
43
42
|
htmlFor: id,
|
|
44
|
-
textContent: colorPickerLocalizations.defaults.output
|
|
43
|
+
textContent: colorPickerLocalizations.values.defaults.output
|
|
45
44
|
}
|
|
46
45
|
});
|
|
47
46
|
const select = createElement("select", {
|
|
@@ -52,7 +51,7 @@ function createOutputFormat(parameters, copy) {
|
|
|
52
51
|
property: { id }
|
|
53
52
|
});
|
|
54
53
|
select.append(...colors.map((color) => createElement("option", { property: {
|
|
55
|
-
textContent: colorPickerLocalizations.defaults[color],
|
|
54
|
+
textContent: colorPickerLocalizations.values.defaults[color],
|
|
56
55
|
value: color
|
|
57
56
|
} })));
|
|
58
57
|
toggle.append(label, select);
|
|
@@ -71,7 +70,7 @@ function createOutputInput(color, property, value, parameters) {
|
|
|
71
70
|
data: { label: property },
|
|
72
71
|
property: {
|
|
73
72
|
htmlFor: id,
|
|
74
|
-
textContent: colorPickerLocalizations.defaults[property]
|
|
73
|
+
textContent: colorPickerLocalizations.values.defaults[property]
|
|
75
74
|
}
|
|
76
75
|
});
|
|
77
76
|
const input = createElement("input", {
|
|
@@ -101,7 +100,7 @@ function createOutputInput(color, property, value, parameters) {
|
|
|
101
100
|
}
|
|
102
101
|
function createOutputItem(color, parameters, copy, single, hidden) {
|
|
103
102
|
const item = createElement("div", {
|
|
104
|
-
aria: { label: colorPickerLocalizations.defaults[color] },
|
|
103
|
+
aria: { label: colorPickerLocalizations.values.defaults[color] },
|
|
105
104
|
data: { label: color },
|
|
106
105
|
attribute: {
|
|
107
106
|
[`${COLOR_PICKER_TAGNAME}-output-item`]: "",
|
|
@@ -146,11 +145,11 @@ function getColorPickerOutputFormat(state) {
|
|
|
146
145
|
}
|
|
147
146
|
function updateColorPickerOutputCopyLabel(state, button) {
|
|
148
147
|
const { host, localizations } = state.component;
|
|
149
|
-
const prefix = localize(
|
|
148
|
+
const prefix = localizations.localize("copy", { element: host });
|
|
150
149
|
const color = getColorPickerOutputFormat(state);
|
|
151
150
|
let content;
|
|
152
151
|
if (color == null) content = prefix;
|
|
153
|
-
else content = `${prefix} ${localize(
|
|
152
|
+
else content = `${prefix} ${localizations.localize(color, { element: host })}`;
|
|
154
153
|
setAria(button, "label", content);
|
|
155
154
|
button.textContent = prefix;
|
|
156
155
|
}
|
|
@@ -176,7 +175,7 @@ function updateColorPickerOutputLabels(state) {
|
|
|
176
175
|
const elements = [...content.element.querySelectorAll(`[data-label="${label}"]`)];
|
|
177
176
|
const elementsLength = elements.length;
|
|
178
177
|
if (elementsLength === 0) return;
|
|
179
|
-
const textContent = localize(
|
|
178
|
+
const textContent = localizations.localize(label, { element: host });
|
|
180
179
|
for (let elementsIndex = 0; elementsIndex < elementsLength; elementsIndex += 1) {
|
|
181
180
|
const element = elements[elementsIndex];
|
|
182
181
|
if (element instanceof HTMLLabelElement) element.textContent = textContent;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as
|
|
1
|
+
import { B as OuiColorPickerState, C as GenericOuiColorPickerElement, V as OuiColorPickerStateComponent } from "../color-picker.constants-BZgXQr5o.mjs";
|
|
2
2
|
//#region src/js/color-picker/color-picker.state.d.ts
|
|
3
3
|
export declare function attachColorPicker(state: OuiColorPickerState): void;
|
|
4
4
|
export declare function detachColorPicker(state: OuiColorPickerState): void;
|
|
@@ -1,2 +1,168 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createEmbeddedFloatable } from "../floatable/floatable.embedded.mjs";
|
|
2
|
+
import { createLocalizations } from "../internal/l10n/index.mjs";
|
|
3
|
+
import { COLOR_PICKER_INPUT_TYPES, COLOR_PICKER_MESSAGE_INPUT, COLOR_PICKER_MESSAGE_LABEL, COLOR_PICKER_SYMBOL, colorPickerLocalizations } from "./color-picker.constants.mjs";
|
|
4
|
+
import { updateColorPickerValidity } from "./color-picker.form.mjs";
|
|
5
|
+
import { getColorPickerId, getColorPickerOutput, setColorPickerDisabled, setColorPickerRequired, setColorPickerValues, updateColorPickerLabels } from "./color-picker.misc.mjs";
|
|
6
|
+
import { colorPickerMovement, onColorPickerHue, onColorPickerInput, onColorPickerOpacity, onColorPickerOutputFormat, onColorPickerOutputValue } from "./color-picker.event.mjs";
|
|
7
|
+
import { createColorPickerAnchor, createColorPickerContent } from "./color-picker.dom.mjs";
|
|
8
|
+
import { getAria, setAria } from "@oscarpalmer/toretto/aria";
|
|
9
|
+
import { setAttributes } from "@oscarpalmer/toretto/attribute";
|
|
10
|
+
import { on } from "@oscarpalmer/toretto/event";
|
|
11
|
+
import { createElement } from "@oscarpalmer/toretto/create";
|
|
12
|
+
import { getColor, isHexColor } from "@oscarpalmer/atoms/color";
|
|
13
|
+
//#region src/js/color-picker/color-picker.state.ts
|
|
14
|
+
function attachColorPicker(state) {
|
|
15
|
+
const { component } = state;
|
|
16
|
+
const { anchor, content, host, id, inline, input, label, listeners, style } = state.component;
|
|
17
|
+
if (!inline) {
|
|
18
|
+
component.floatable = createEmbeddedFloatable(anchor.container ?? anchor.container, content.element, {
|
|
19
|
+
position: "below-start",
|
|
20
|
+
reusable: false
|
|
21
|
+
});
|
|
22
|
+
component.floatable.update();
|
|
23
|
+
}
|
|
24
|
+
const labelId = `${id}_label`;
|
|
25
|
+
setAria(host, {
|
|
26
|
+
describedby: getAria(input, "describedby"),
|
|
27
|
+
labelledby: labelId
|
|
28
|
+
});
|
|
29
|
+
setAttributes(host, { name: input.name === "" ? input.id : input.name });
|
|
30
|
+
label.element.htmlFor = anchor.input.id;
|
|
31
|
+
label.element.id = labelId;
|
|
32
|
+
if (anchor.toggle != null) setAria(anchor.toggle, "expanded", false);
|
|
33
|
+
input.before(style, anchor.container, content.element);
|
|
34
|
+
input.remove();
|
|
35
|
+
listeners.push(on(host, "focusout", () => {
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
if (colorPickerMovement.parameters == null && !host.contains(document.activeElement)) component.floatable?.hide();
|
|
38
|
+
});
|
|
39
|
+
}), on(anchor.input, "change", () => {
|
|
40
|
+
onColorPickerInput(state);
|
|
41
|
+
}), on(anchor.input, "input", () => {
|
|
42
|
+
onColorPickerInput(state);
|
|
43
|
+
}), on(content.element, "beforetoggle", (event) => {
|
|
44
|
+
if (component.disabled) event.preventDefault();
|
|
45
|
+
}, { passive: false }), on(content.element, "toggle", (event) => {
|
|
46
|
+
const open = event.newState === "open";
|
|
47
|
+
if (anchor.toggle != null) setAria(anchor.toggle, "expanded", open);
|
|
48
|
+
if (open) content.well.knob.focus();
|
|
49
|
+
}), on(content.hue.input, "input", () => {
|
|
50
|
+
onColorPickerHue(state);
|
|
51
|
+
}));
|
|
52
|
+
if (content.opacity != null) listeners.push(on(content.opacity.input, "input", () => {
|
|
53
|
+
onColorPickerOpacity(state, content.opacity.input);
|
|
54
|
+
}), on(content.opacity.range, "input", () => {
|
|
55
|
+
onColorPickerOpacity(state, content.opacity.range);
|
|
56
|
+
}));
|
|
57
|
+
if (content.output?.toggle != null) listeners.push(on(content.element, "change", (event) => {
|
|
58
|
+
onColorPickerOutputValue(event, state);
|
|
59
|
+
}), on(content.element, "input", (event) => {
|
|
60
|
+
onColorPickerOutputValue(event, state);
|
|
61
|
+
}), on(content.output.toggle, "change", () => {
|
|
62
|
+
onColorPickerOutputFormat(state);
|
|
63
|
+
}));
|
|
64
|
+
colorPickers.add(state);
|
|
65
|
+
}
|
|
66
|
+
function detachColorPicker(state) {
|
|
67
|
+
const { component } = state;
|
|
68
|
+
const { anchor, content, floatable, host, input, label, style } = component;
|
|
69
|
+
floatable?.destroy();
|
|
70
|
+
setAria(host, {
|
|
71
|
+
describedby: void 0,
|
|
72
|
+
labelledby: void 0
|
|
73
|
+
});
|
|
74
|
+
setAttributes(host, { name: void 0 });
|
|
75
|
+
label.element.htmlFor = input.id;
|
|
76
|
+
label.element.id = label.id;
|
|
77
|
+
anchor.container.before(input);
|
|
78
|
+
anchor.container.remove();
|
|
79
|
+
content.element.remove();
|
|
80
|
+
style.remove();
|
|
81
|
+
const listeners = component.listeners.splice(0);
|
|
82
|
+
const { length } = listeners;
|
|
83
|
+
for (let index = 0; index < length; index += 1) listeners[index]();
|
|
84
|
+
colorPickers.delete(state);
|
|
85
|
+
}
|
|
86
|
+
function initializeColorPicker(colorPicker) {
|
|
87
|
+
const state = colorPicker[COLOR_PICKER_SYMBOL];
|
|
88
|
+
colorPicker[COLOR_PICKER_SYMBOL].component = initializeColorPickerComponent(colorPicker, state);
|
|
89
|
+
if (state.form.restored != null) {
|
|
90
|
+
colorPicker.value = state.form.restored;
|
|
91
|
+
state.form.restored = void 0;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function initializeColorPickerComponent(element, state) {
|
|
95
|
+
const input = element.querySelector("input");
|
|
96
|
+
if (input == null || !COLOR_PICKER_INPUT_TYPES.has(input.type)) throw new Error(COLOR_PICKER_MESSAGE_INPUT);
|
|
97
|
+
const label = element.querySelector(`label[for="${input.id}"]`);
|
|
98
|
+
if (!(label instanceof HTMLLabelElement)) throw new Error(COLOR_PICKER_MESSAGE_LABEL);
|
|
99
|
+
element.id = input.id;
|
|
100
|
+
const id = getColorPickerId();
|
|
101
|
+
const labelId = label.id;
|
|
102
|
+
const alpha = element.hasAttribute("alpha");
|
|
103
|
+
const color = getColor(input.value);
|
|
104
|
+
const copy = element.hasAttribute("copy");
|
|
105
|
+
const disabled = element.hasAttribute("disabled") || input.disabled;
|
|
106
|
+
const inline = element.hasAttribute("inline");
|
|
107
|
+
const output = getColorPickerOutput(element);
|
|
108
|
+
const readonly = element.hasAttribute("readonly") || input.readOnly;
|
|
109
|
+
const required = element.hasAttribute("required") || input.required;
|
|
110
|
+
const parameters = {
|
|
111
|
+
alpha,
|
|
112
|
+
color,
|
|
113
|
+
copy,
|
|
114
|
+
id,
|
|
115
|
+
inline,
|
|
116
|
+
input,
|
|
117
|
+
output
|
|
118
|
+
};
|
|
119
|
+
const anchor = createColorPickerAnchor(parameters);
|
|
120
|
+
const content = createColorPickerContent(parameters);
|
|
121
|
+
const formatted = color.toHexString(alpha);
|
|
122
|
+
state.component = {
|
|
123
|
+
alpha,
|
|
124
|
+
anchor,
|
|
125
|
+
content,
|
|
126
|
+
copy,
|
|
127
|
+
disabled,
|
|
128
|
+
id,
|
|
129
|
+
inline,
|
|
130
|
+
input,
|
|
131
|
+
output,
|
|
132
|
+
readonly,
|
|
133
|
+
required,
|
|
134
|
+
color: {
|
|
135
|
+
foreground: "",
|
|
136
|
+
value: color
|
|
137
|
+
},
|
|
138
|
+
host: element,
|
|
139
|
+
label: {
|
|
140
|
+
element: label,
|
|
141
|
+
id: labelId
|
|
142
|
+
},
|
|
143
|
+
listeners: [],
|
|
144
|
+
localizations: createLocalizations(colorPickerLocalizations),
|
|
145
|
+
style: createElement("style"),
|
|
146
|
+
value: {
|
|
147
|
+
current: formatted,
|
|
148
|
+
initial: formatted
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
attachColorPicker(state);
|
|
152
|
+
setAttributes(element, {
|
|
153
|
+
output,
|
|
154
|
+
alpha: alpha ? "" : void 0,
|
|
155
|
+
copy: copy ? "" : void 0,
|
|
156
|
+
inline: inline ? "" : void 0
|
|
157
|
+
});
|
|
158
|
+
setColorPickerDisabled(state, "disabled", disabled);
|
|
159
|
+
setColorPickerDisabled(state, "readonly", readonly);
|
|
160
|
+
setColorPickerRequired(state, required);
|
|
161
|
+
setColorPickerValues(state, false);
|
|
162
|
+
updateColorPickerLabels(state);
|
|
163
|
+
updateColorPickerValidity(state, isHexColor(state.component.value.current, alpha));
|
|
164
|
+
return state.component;
|
|
165
|
+
}
|
|
166
|
+
const colorPickers = /* @__PURE__ */ new Set();
|
|
167
|
+
//#endregion
|
|
2
168
|
export { attachColorPicker, colorPickers, detachColorPicker, initializeColorPicker, initializeColorPickerComponent };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { p as OuiLocalizations } from "../l10n.model-D1E1u35L.mjs";
|
|
2
|
+
import { B as OuiColorPickerState, N as OuiColorPickerEvent, P as OuiColorPickerLocalizations, b as COLOR_PICKER_SYMBOL, x as COLOR_PICKER_TAGNAME } from "../color-picker.constants-BZgXQr5o.mjs";
|
|
3
|
+
import { a as setColorPickerLocalizations } from "../color-picker.misc-BIS3R6jk.mjs";
|
|
3
4
|
import { HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "@oscarpalmer/atoms/color";
|
|
4
5
|
//#region src/js/color-picker/index.d.ts
|
|
5
6
|
declare global {
|
|
@@ -81,6 +82,10 @@ export declare class OuiColorPickerElement extends HTMLElement {
|
|
|
81
82
|
* Label elements associated with the color picker
|
|
82
83
|
*/
|
|
83
84
|
get labels(): NodeList;
|
|
85
|
+
/**
|
|
86
|
+
* Localization information for the color picker
|
|
87
|
+
*/
|
|
88
|
+
get localizations(): OuiLocalizations<OuiColorPickerLocalizations>;
|
|
84
89
|
/**
|
|
85
90
|
* Is the color picker readonly?
|
|
86
91
|
*/
|
|
@@ -162,19 +167,6 @@ export declare class OuiColorPickerElement extends HTMLElement {
|
|
|
162
167
|
* @param message Validation message
|
|
163
168
|
*/
|
|
164
169
|
setCustomValidity(message: string): void;
|
|
165
|
-
/**
|
|
166
|
-
* Set localizations for a specific language
|
|
167
|
-
*
|
|
168
|
-
* @param language Language code
|
|
169
|
-
* @param localizations Localizations for language
|
|
170
|
-
*/
|
|
171
|
-
setLocalizations(language: string, localizations: Partial<OuiColorPickerLocalizations>): void;
|
|
172
|
-
/**
|
|
173
|
-
* Set localizations for one or more languages
|
|
174
|
-
*
|
|
175
|
-
* @param localizations Localizations for one or more languages
|
|
176
|
-
*/
|
|
177
|
-
setLocalizations(localizations: Record<string, Partial<OuiColorPickerLocalizations>>): void;
|
|
178
170
|
}
|
|
179
171
|
//#endregion
|
|
180
172
|
export { OuiColorPickerEvent, setColorPickerLocalizations };
|