@oscarpalmer/oui 0.39.0 → 0.41.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.
Files changed (227) hide show
  1. package/README.md +1 -1
  2. package/dist/css/color-picker.css +80 -69
  3. package/dist/css/listbox.css +169 -0
  4. package/dist/js/color-picker/color-picker.constants.d.mts +2 -0
  5. package/dist/js/color-picker/{constants.color-picker.mjs → color-picker.constants.mjs} +7 -4
  6. package/dist/js/color-picker/{dom.color-picker.d.mts → color-picker.dom.d.mts} +2 -2
  7. package/dist/js/color-picker/{dom.color-picker.mjs → color-picker.dom.mjs} +33 -16
  8. package/dist/js/color-picker/{event.color-picker.d.mts → color-picker.event.d.mts} +3 -3
  9. package/dist/js/color-picker/color-picker.event.mjs +233 -0
  10. package/dist/js/color-picker/{form.color-picker.d.mts → color-picker.form.d.mts} +2 -2
  11. package/dist/js/color-picker/{form.color-picker.mjs → color-picker.form.mjs} +9 -8
  12. package/dist/js/color-picker/color-picker.misc.d.mts +2 -0
  13. package/dist/js/color-picker/color-picker.misc.mjs +104 -0
  14. package/dist/js/color-picker/color-picker.model.d.mts +2 -0
  15. package/dist/js/color-picker/{models.color-picker.mjs → color-picker.model.mjs} +1 -1
  16. package/dist/js/color-picker/{output.color-picker.d.mts → color-picker.output.d.mts} +2 -2
  17. package/dist/js/color-picker/{output.color-picker.mjs → color-picker.output.mjs} +19 -18
  18. package/dist/js/color-picker/color-picker.state.d.mts +8 -0
  19. package/dist/js/color-picker/color-picker.state.mjs +168 -0
  20. package/dist/js/color-picker/index.d.mts +172 -2
  21. package/dist/js/color-picker/index.mjs +66 -59
  22. package/dist/js/color-picker.constants-BZgXQr5o.d.mts +177 -0
  23. package/dist/js/color-picker.misc-BIS3R6jk.d.mts +31 -0
  24. package/dist/js/combobox/combobox.constants.d.mts +2 -0
  25. package/dist/js/combobox/{constants.combobox.mjs → combobox.constants.mjs} +21 -21
  26. package/dist/js/combobox/combobox.dom.d.mts +25 -0
  27. package/dist/js/combobox/{dom.combobox.mjs → combobox.dom.mjs} +51 -49
  28. package/dist/js/combobox/{event.combobox.d.mts → combobox.event.d.mts} +9 -9
  29. package/dist/js/combobox/{event.combobox.mjs → combobox.event.mjs} +1 -1
  30. package/dist/js/combobox/combobox.misc.d.mts +2 -0
  31. package/dist/js/combobox/combobox.misc.mjs +2 -0
  32. package/dist/js/combobox/combobox.model.d.mts +2 -0
  33. package/dist/js/combobox/combobox.state.d.mts +9 -0
  34. package/dist/js/combobox/combobox.state.mjs +2 -0
  35. package/dist/js/combobox/index.d.mts +152 -2
  36. package/dist/js/combobox/index.mjs +54 -55
  37. package/dist/js/combobox.constants-Hb3bqqQJ.d.mts +19 -0
  38. package/dist/js/combobox.misc-DRDFk6X8.d.mts +26 -0
  39. package/dist/js/combobox.model-gjEI2VqZ.d.mts +46 -0
  40. package/dist/js/{state.combobox-BWDFHwoi.mjs → combobox.state-AstCICiH.mjs} +109 -106
  41. package/dist/js/dialog/dialog.model.d.mts +2 -0
  42. package/dist/js/dialog/dialog.model.mjs +11 -0
  43. package/dist/js/dialog/index.d.mts +12 -0
  44. package/dist/js/dialog/index.mjs +123 -0
  45. package/dist/js/dialog.model-HVzYWoDo.d.mts +45 -0
  46. package/dist/js/floatable/floatable.embedded.d.mts +2 -2
  47. package/dist/js/floatable/floatable.embedded.mjs +64 -92
  48. package/dist/js/floatable/floatable.model.d.mts +2 -0
  49. package/dist/js/floatable/floatable.model.mjs +23 -0
  50. package/dist/js/floatable/floatable.standalone.d.mts +2 -1
  51. package/dist/js/floatable.embedded-ncshL3Sa.d.mts +17 -0
  52. package/dist/js/{floatable.embedded-DQYkXt8X.d.mts → floatable.model-DXsQgoU7.d.mts} +13 -20
  53. package/dist/js/focus-trap/focus-trap.embedded.d.mts +2 -2
  54. package/dist/js/focus-trap/focus-trap.embedded.mjs +117 -138
  55. package/dist/js/focus-trap/focus-trap.model.d.mts +2 -0
  56. package/dist/js/focus-trap/focus-trap.model.mjs +15 -0
  57. package/dist/js/focus-trap/focus-trap.standalone.d.mts +2 -1
  58. package/dist/js/focus-trap.embedded-DpcPkP7c.d.mts +13 -0
  59. package/dist/js/{focus-trap.embedded-CjyFQYow.d.mts → focus-trap.model-CpltX5B5.d.mts} +16 -18
  60. package/dist/js/index.d.mts +26 -14
  61. package/dist/js/index.mjs +18 -17
  62. package/dist/js/internal/attributable.d.mts +1 -1
  63. package/dist/js/internal/attributable.mjs +3 -2
  64. package/dist/js/internal/draggable/draggable.model.d.mts +2 -0
  65. package/dist/js/internal/draggable/draggable.model.mjs +37 -0
  66. package/dist/js/internal/draggable/index.d.mts +13 -0
  67. package/dist/js/internal/draggable/index.mjs +243 -0
  68. package/dist/js/internal/l10n/index.d.mts +5 -0
  69. package/dist/js/internal/l10n/index.mjs +147 -0
  70. package/dist/js/internal/l10n/l10n.model.d.mts +2 -0
  71. package/dist/js/internal/l10n/l10n.model.mjs +12 -0
  72. package/dist/js/internal/misc.d.mts +3 -2
  73. package/dist/js/internal/misc.mjs +4 -6
  74. package/dist/js/internal/navigable/index.d.mts +6 -0
  75. package/dist/js/internal/navigable/index.mjs +125 -0
  76. package/dist/js/internal/navigable/navigable.model.d.mts +2 -0
  77. package/dist/js/internal/navigable/navigable.model.mjs +18 -0
  78. package/dist/js/internal/option-list/option-list.constants.d.mts +8 -0
  79. package/dist/js/internal/option-list/option-list.constants.mjs +22 -0
  80. package/dist/js/internal/option-list/option-list.data.d.mts +21 -0
  81. package/dist/js/internal/option-list/option-list.data.mjs +2 -0
  82. package/dist/js/internal/option-list/option-list.dom.d.mts +18 -0
  83. package/dist/js/internal/option-list/option-list.dom.mjs +2 -0
  84. package/dist/js/internal/option-list/option-list.event.d.mts +6 -0
  85. package/dist/js/internal/option-list/option-list.event.mjs +66 -0
  86. package/dist/js/internal/option-list/option-list.form.d.mts +7 -0
  87. package/dist/js/internal/option-list/option-list.form.mjs +53 -0
  88. package/dist/js/internal/option-list/option-list.misc.d.mts +13 -0
  89. package/dist/js/internal/option-list/option-list.misc.mjs +2 -0
  90. package/dist/js/internal/option-list/option-list.model.d.mts +2 -0
  91. package/dist/js/internal/option-list/option-list.state.d.mts +8 -0
  92. package/dist/js/internal/option-list/option-list.state.mjs +39 -0
  93. package/dist/js/l10n/index.d.mts +3 -0
  94. package/dist/js/l10n/index.mjs +2 -0
  95. package/dist/js/l10n.model-D1E1u35L.d.mts +54 -0
  96. package/dist/js/listbox/index.d.mts +9 -18
  97. package/dist/js/listbox/index.mjs +49 -52
  98. package/dist/js/listbox/listbox.constants.d.mts +2 -0
  99. package/dist/js/listbox/{constants.listbox.mjs → listbox.constants.mjs} +11 -15
  100. package/dist/js/listbox/listbox.dom.d.mts +5 -0
  101. package/dist/js/listbox/listbox.dom.mjs +2 -0
  102. package/dist/js/listbox/listbox.event.d.mts +9 -0
  103. package/dist/js/listbox/listbox.event.mjs +2 -0
  104. package/dist/js/listbox/listbox.misc.d.mts +2 -0
  105. package/dist/js/listbox/listbox.misc.mjs +2 -0
  106. package/dist/js/listbox/listbox.model.d.mts +2 -0
  107. package/dist/js/listbox/listbox.model.mjs +1 -0
  108. package/dist/js/listbox/listbox.state.d.mts +9 -0
  109. package/dist/js/listbox/listbox.state.mjs +2 -0
  110. package/dist/js/listbox.constants-DOBMwKup.d.mts +9 -0
  111. package/dist/js/listbox.misc-DwfB4Mu_.d.mts +24 -0
  112. package/dist/js/listbox.model-C0MYWXZe.d.mts +20 -0
  113. package/dist/js/listbox.state-BrN296BM.mjs +240 -0
  114. package/dist/js/menu/index.mjs +171 -0
  115. package/dist/js/menu/menu.model.d.mts +33 -0
  116. package/dist/js/menu/menu.model.mjs +15 -0
  117. package/dist/js/movable/movable.embedded.d.mts +2 -2
  118. package/dist/js/movable/movable.embedded.mjs +77 -86
  119. package/dist/js/movable/movable.model.d.mts +2 -0
  120. package/dist/js/movable/movable.model.mjs +12 -0
  121. package/dist/js/movable/movable.standalone.d.mts +2 -1
  122. package/dist/js/movable.embedded-C1bDTLGs.d.mts +11 -0
  123. package/dist/js/movable.model-D9nnPWKk.d.mts +186 -0
  124. package/dist/js/navigable.model-BqoR6iBv.d.mts +44 -0
  125. package/dist/js/option-list.data-CgMyUwPc.mjs +441 -0
  126. package/dist/js/option-list.model-CCPUlPeX.d.mts +169 -0
  127. package/dist/js/popover/index.d.mts +12 -0
  128. package/dist/js/{popover.mjs → popover/index.mjs} +41 -51
  129. package/dist/js/popover/popover.model.d.mts +2 -0
  130. package/dist/js/popover/popover.model.mjs +12 -0
  131. package/dist/js/popover.model-DiLdz0Hc.d.mts +38 -0
  132. package/dist/js/resizable/resizable.embedded.d.mts +2 -2
  133. package/dist/js/resizable/resizable.embedded.mjs +43 -58
  134. package/dist/js/resizable/resizable.model.d.mts +2 -0
  135. package/dist/js/resizable/resizable.model.mjs +21 -0
  136. package/dist/js/resizable/resizable.standalone.d.mts +2 -1
  137. package/dist/js/resizable.embedded-BemH-7Re.d.mts +11 -0
  138. package/dist/js/resizable.model-YEtcC9li.d.mts +46 -0
  139. package/dist/js/sortable/sortable.embedded.d.mts +2 -2
  140. package/dist/js/sortable/sortable.embedded.mjs +111 -116
  141. package/dist/js/sortable/sortable.model.d.mts +2 -0
  142. package/dist/js/sortable/sortable.model.mjs +24 -0
  143. package/dist/js/sortable/sortable.standalone.d.mts +2 -1
  144. package/dist/js/sortable.embedded-CrEGff9k.d.mts +11 -0
  145. package/dist/js/{splitter.d.mts → splitter/index.d.mts} +6 -4
  146. package/dist/js/{splitter.mjs → splitter/index.mjs} +90 -128
  147. package/dist/js/splitter/splitter.model.d.mts +2 -0
  148. package/dist/js/splitter/splitter.model.mjs +37 -0
  149. package/dist/js/splitter.model-C24W6eZ7.d.mts +57 -0
  150. package/dist/js/{tabs.d.mts → tabs/index.d.mts} +8 -8
  151. package/dist/js/{tabs.mjs → tabs/index.mjs} +58 -58
  152. package/dist/js/tabs/tabs.model.d.mts +2 -0
  153. package/dist/js/tabs/tabs.model.mjs +18 -0
  154. package/dist/js/tabs.model-BHPy7fPo.d.mts +40 -0
  155. package/dist/js/toolbar/index.mjs +27 -0
  156. package/dist/js/toolbar/toolbar.model.d.mts +11 -0
  157. package/dist/js/toolbar/toolbar.model.mjs +7 -0
  158. package/dist/js/tooltip/index.d.mts +19 -0
  159. package/dist/js/{tooltip.mjs → tooltip/index.mjs} +61 -86
  160. package/dist/js/tooltip/tooltip.model.d.mts +2 -0
  161. package/dist/js/tooltip/tooltip.model.mjs +15 -0
  162. package/dist/js/tooltip.model-BpNStw5z.d.mts +37 -0
  163. package/package.json +30 -24
  164. package/dist/js/color-picker/constants.color-picker.d.mts +0 -2
  165. package/dist/js/color-picker/event.color-picker.mjs +0 -2
  166. package/dist/js/color-picker/misc.color-picker.d.mts +0 -2
  167. package/dist/js/color-picker/misc.color-picker.mjs +0 -2
  168. package/dist/js/color-picker/models.color-picker.d.mts +0 -2
  169. package/dist/js/color-picker/state.color-picker.d.mts +0 -8
  170. package/dist/js/color-picker/state.color-picker.mjs +0 -2
  171. package/dist/js/combobox/constants.combobox.d.mts +0 -2
  172. package/dist/js/combobox/dom.combobox.d.mts +0 -26
  173. package/dist/js/combobox/misc.combobox.d.mts +0 -2
  174. package/dist/js/combobox/misc.combobox.mjs +0 -2
  175. package/dist/js/combobox/models.combobox.d.mts +0 -43
  176. package/dist/js/combobox/state.combobox.d.mts +0 -11
  177. package/dist/js/combobox/state.combobox.mjs +0 -2
  178. package/dist/js/constants.color-picker-B-gFjL8m.d.mts +0 -364
  179. package/dist/js/constants.combobox-8EMRmv09.d.mts +0 -18
  180. package/dist/js/constants.listbox-DGnX32kv.d.mts +0 -8
  181. package/dist/js/dialog.d.mts +0 -47
  182. package/dist/js/dialog.mjs +0 -131
  183. package/dist/js/draggable-B5-70SZm.d.mts +0 -155
  184. package/dist/js/event.color-picker-BEpq0Adu.mjs +0 -485
  185. package/dist/js/index-C5D3-oiI.d.mts +0 -177
  186. package/dist/js/internal/draggable.d.mts +0 -2
  187. package/dist/js/internal/draggable.mjs +0 -265
  188. package/dist/js/internal/listbox/listbox.constants.d.mts +0 -8
  189. package/dist/js/internal/listbox/listbox.constants.mjs +0 -22
  190. package/dist/js/internal/listbox/listbox.data.d.mts +0 -19
  191. package/dist/js/internal/listbox/listbox.data.mjs +0 -2
  192. package/dist/js/internal/listbox/listbox.dom.d.mts +0 -65
  193. package/dist/js/internal/listbox/listbox.dom.mjs +0 -2
  194. package/dist/js/internal/listbox/listbox.event.d.mts +0 -4
  195. package/dist/js/internal/listbox/listbox.event.mjs +0 -63
  196. package/dist/js/internal/listbox/listbox.form.d.mts +0 -5
  197. package/dist/js/internal/listbox/listbox.form.mjs +0 -53
  198. package/dist/js/internal/listbox/listbox.misc.d.mts +0 -11
  199. package/dist/js/internal/listbox/listbox.misc.mjs +0 -2
  200. package/dist/js/internal/listbox/listbox.model.d.mts +0 -2
  201. package/dist/js/internal/listbox/listbox.state.d.mts +0 -6
  202. package/dist/js/internal/listbox/listbox.state.mjs +0 -40
  203. package/dist/js/internal/navigable.d.mts +0 -36
  204. package/dist/js/internal/navigable.mjs +0 -135
  205. package/dist/js/l10n-Bn-7RcwR.d.mts +0 -20
  206. package/dist/js/l10n.d.mts +0 -2
  207. package/dist/js/l10n.mjs +0 -80
  208. package/dist/js/listbox/constants.listbox.d.mts +0 -2
  209. package/dist/js/listbox/event.listbox.d.mts +0 -7
  210. package/dist/js/listbox/event.listbox.mjs +0 -2
  211. package/dist/js/listbox/misc.listbox.d.mts +0 -2
  212. package/dist/js/listbox/misc.listbox.mjs +0 -2
  213. package/dist/js/listbox/state.listbox.d.mts +0 -10
  214. package/dist/js/listbox/state.listbox.mjs +0 -2
  215. package/dist/js/listbox.data-DQ7-x2uY.mjs +0 -425
  216. package/dist/js/listbox.model-BHPA7GM4.d.mts +0 -125
  217. package/dist/js/menu.mjs +0 -172
  218. package/dist/js/misc.listbox-DKB-j0UK.mjs +0 -196
  219. package/dist/js/misc.listbox-mZMuYOxg.d.mts +0 -20
  220. package/dist/js/popover.d.mts +0 -38
  221. package/dist/js/resizable.embedded-dvhdfQgt.d.mts +0 -34
  222. package/dist/js/toolbar.mjs +0 -31
  223. package/dist/js/tooltip.d.mts +0 -45
  224. /package/dist/js/combobox/{models.combobox.mjs → combobox.model.mjs} +0 -0
  225. /package/dist/js/internal/{listbox/listbox.model.mjs → option-list/option-list.model.mjs} +0 -0
  226. /package/dist/js/{menu.d.mts → menu/index.d.mts} +0 -0
  227. /package/dist/js/{toolbar.d.mts → toolbar/index.d.mts} +0 -0
@@ -0,0 +1,233 @@
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_INPUT, 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, COLOR_PICKER_SELECTOR_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
233
+ export { colorPickerMovement, onColorPickerHue, onColorPickerInput, onColorPickerOpacity, onColorPickerOutputFormat, onColorPickerOutputValue };
@@ -1,5 +1,5 @@
1
- import { L as OuiColorPickerState } from "../constants.color-picker-B-gFjL8m.mjs";
2
- //#region src/js/color-picker/form.color-picker.d.ts
1
+ import { B as OuiColorPickerState } from "../color-picker.constants-BZgXQr5o.mjs";
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;
5
5
  //#endregion
@@ -1,22 +1,23 @@
1
- import { getLocalization, localize } from "../l10n.mjs";
2
- import { OuiColorPickerEvent } from "./models.color-picker.mjs";
1
+ import { OuiColorPickerEvent } from "./color-picker.model.mjs";
3
2
  import { dispatch } from "@oscarpalmer/toretto/event";
4
- //#region src/js/color-picker/form.color-picker.ts
3
+ //#region src/js/color-picker/color-picker.form.ts
5
4
  function updateColorPickerForm(state, valid) {
6
- const { color, host, internals, value } = state;
7
- internals.setFormValue(valid ? value.current : "");
5
+ const { component, form } = state;
6
+ const { color, host, value } = component;
7
+ form.internals.setFormValue(valid ? value.current : "");
8
8
  updateColorPickerValidity(state, valid);
9
9
  dispatch(host, new OuiColorPickerEvent("oui:change", color.value, valid));
10
10
  }
11
11
  function updateColorPickerValidity(state, valid) {
12
- const { anchor, host, internals, localizations } = state;
12
+ const { component, form } = state;
13
+ const { anchor, host, localizations } = component;
14
+ const { internals } = form;
13
15
  if (valid) {
14
16
  internals.setValidity({});
15
17
  internals.checkValidity();
16
18
  return;
17
19
  }
18
- const localization = getLocalization(localizations.global, host, "invalid", localizations.component);
19
- const message = localization == null ? void 0 : localize(localization, {}, []);
20
+ const message = localizations.localize("invalid", { element: host });
20
21
  internals.setValidity({ typeMismatch: true }, message, anchor.input);
21
22
  internals.checkValidity();
22
23
  }
@@ -0,0 +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 } from "../color-picker.misc-BIS3R6jk.mjs";
2
+ export { getColorPickerId, getColorPickerOutput, getColorPickerValueType, setColorPickerDisabled, setColorPickerLocalizations, setColorPickerRequired, setColorPickerValue, setColorPickerValues, updateColorPickerLabels };
@@ -0,0 +1,104 @@
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 };
@@ -0,0 +1,2 @@
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
- //#region src/js/color-picker/models.color-picker.ts
1
+ //#region src/js/color-picker/color-picker.model.ts
2
2
  var OuiColorPickerEvent = class extends Event {
3
3
  valid;
4
4
  value;
@@ -1,5 +1,5 @@
1
- import { E as OuiColorPickerContentOutput, L as OuiColorPickerState, O as OuiColorPickerCopy, P as OuiColorPickerOutputColor, k as OuiColorPickerCreateParameters } from "../constants.color-picker-B-gFjL8m.mjs";
2
- //#region src/js/color-picker/output.color-picker.d.ts
1
+ import { B as OuiColorPickerState, L as OuiColorPickerOutputColor, M as OuiColorPickerCreateParameters, j as OuiColorPickerCopy, k as OuiColorPickerContentOutput } from "../color-picker.constants-BZgXQr5o.mjs";
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;
5
5
  export declare function updateColorPickerOutputCopyLabel(state: OuiColorPickerState, button: HTMLButtonElement): void;
@@ -1,9 +1,8 @@
1
- import { getLocalization, localize } from "../l10n.mjs";
2
- import { COLOR_PICKER_ATTRIBUTE_OUTPUT_INPUT, COLOR_PICKER_TAGNAME, colorPickerLocalizations } from "./constants.color-picker.mjs";
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
- import { round } from "@oscarpalmer/atoms/math";
5
3
  import { createElement } from "@oscarpalmer/toretto/create";
6
- //#region src/js/color-picker/output.color-picker.ts
4
+ import { round } from "@oscarpalmer/atoms/math";
5
+ //#region src/js/color-picker/color-picker.output.ts
7
6
  function createColorPickerOutput(parameters, copy) {
8
7
  if (parameters.output === "none") return;
9
8
  const container = createElement("div", { attribute: { [`${COLOR_PICKER_TAGNAME}-output`]: "" } });
@@ -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`]: "",
@@ -137,24 +136,26 @@ function createOutputItems(parameters, copy) {
137
136
  ];
138
137
  }
139
138
  function getColorPickerOutputFormat(state) {
140
- if (state.output === "none") return;
139
+ const { component } = state;
140
+ if (component.output === "none") return;
141
141
  let color;
142
- if (state.output === "all") color = state.content.output?.toggle?.value;
143
- else color = state.output;
142
+ if (component.output === "all") color = component.content.output?.toggle?.value;
143
+ else color = component.output;
144
144
  return color;
145
145
  }
146
146
  function updateColorPickerOutputCopyLabel(state, button) {
147
- const { host, localizations } = state;
148
- const prefix = localize(getLocalization(localizations.global, host, "copy", localizations.component), {}, []);
147
+ const { host, localizations } = state.component;
148
+ const prefix = localizations.localize("copy", { element: host });
149
149
  const color = getColorPickerOutputFormat(state);
150
150
  let content;
151
151
  if (color == null) content = prefix;
152
- else content = `${prefix} ${localize(getLocalization(localizations.global, host, color, localizations.component), {}, [])}`;
152
+ else content = `${prefix} ${localizations.localize(color, { element: host })}`;
153
153
  setAria(button, "label", content);
154
154
  button.textContent = prefix;
155
155
  }
156
156
  function updateColorPickerOutputInputs(state) {
157
- const { content } = state;
157
+ const { component } = state;
158
+ const { content } = component;
158
159
  if (content.output?.inputs == null) return;
159
160
  const inputs = content.output.inputs;
160
161
  const { length } = inputs;
@@ -162,11 +163,11 @@ function updateColorPickerOutputInputs(state) {
162
163
  const input = inputs[index];
163
164
  const color = input.dataset.color;
164
165
  const property = input.dataset.property;
165
- if (color != null && property != null) input.valueAsNumber = color in state.color.value && property in state.color.value[color] ? round(state.color.value[color][property]) : 0;
166
+ if (color != null && property != null) input.valueAsNumber = color in component.color.value && property in component.color.value[color] ? round(component.color.value[color][property]) : 0;
166
167
  }
167
168
  }
168
169
  function updateColorPickerOutputLabels(state) {
169
- const { content, host, localizations } = state;
170
+ const { content, host, localizations } = state.component;
170
171
  if (content.output == null) return;
171
172
  if (content.output.copy?.button != null) updateColorPickerOutputCopyLabel(state, content.output.copy.button);
172
173
  for (let labelsIndex = 0; labelsIndex < labelsLength; labelsIndex += 1) {
@@ -174,7 +175,7 @@ function updateColorPickerOutputLabels(state) {
174
175
  const elements = [...content.element.querySelectorAll(`[data-label="${label}"]`)];
175
176
  const elementsLength = elements.length;
176
177
  if (elementsLength === 0) return;
177
- const textContent = localize(getLocalization(localizations.global, host, label, localizations.component), {}, []);
178
+ const textContent = localizations.localize(label, { element: host });
178
179
  for (let elementsIndex = 0; elementsIndex < elementsLength; elementsIndex += 1) {
179
180
  const element = elements[elementsIndex];
180
181
  if (element instanceof HTMLLabelElement) element.textContent = textContent;
@@ -0,0 +1,8 @@
1
+ import { B as OuiColorPickerState, C as GenericOuiColorPickerElement, V as OuiColorPickerStateComponent } from "../color-picker.constants-BZgXQr5o.mjs";
2
+ //#region src/js/color-picker/color-picker.state.d.ts
3
+ export declare function attachColorPicker(state: OuiColorPickerState): void;
4
+ export declare function detachColorPicker(state: OuiColorPickerState): void;
5
+ export declare function initializeColorPicker(colorPicker: GenericOuiColorPickerElement): void;
6
+ export declare function initializeColorPickerComponent(element: GenericOuiColorPickerElement, state: OuiColorPickerState): OuiColorPickerStateComponent;
7
+ export declare const colorPickers: Set<OuiColorPickerState>;
8
+ //#endregion