@witchcraft/ui 0.0.1 → 0.1.1

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 (224) hide show
  1. package/README.md +18 -28
  2. package/dist/module.d.mts +3 -1
  3. package/dist/module.json +3 -3
  4. package/dist/module.mjs +21 -12
  5. package/dist/runtime/assets/base.css +1 -1
  6. package/dist/runtime/assets/locales/en.json +2 -2
  7. package/dist/runtime/assets/tailwind.css +1 -1
  8. package/dist/runtime/assets/utils.css +1 -0
  9. package/dist/runtime/build/WitchcraftUiResolver.js +1 -1
  10. package/dist/runtime/components/Aria/Aria.vue +5 -9
  11. package/dist/runtime/components/Aria/Aria.vue.d.ts +5 -0
  12. package/dist/runtime/components/Icon/Icon.vue +12 -28
  13. package/dist/runtime/components/Icon/Icon.vue.d.ts +21 -0
  14. package/dist/runtime/components/LibButton/LibButton.vue +93 -117
  15. package/dist/runtime/components/LibButton/LibButton.vue.d.ts +36 -0
  16. package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +53 -76
  17. package/dist/runtime/components/LibCheckbox/LibCheckbox.vue.d.ts +42 -0
  18. package/dist/runtime/components/LibColorInput/LibColorInput.vue +131 -101
  19. package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +63 -0
  20. package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +326 -296
  21. package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +61 -0
  22. package/dist/runtime/components/LibColorPicker/utils/safeConvertToHsva.d.ts +2 -0
  23. package/dist/runtime/components/LibColorPicker/utils/safeConvertToHsva.js +18 -0
  24. package/dist/runtime/components/LibColorPicker/utils/safeConvertToRgba.d.ts +2 -0
  25. package/dist/runtime/components/LibColorPicker/utils/safeConvertToRgba.js +17 -0
  26. package/dist/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.d.ts +2 -0
  27. package/dist/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.js +8 -0
  28. package/dist/runtime/components/LibColorPicker/utils/truncate.d.ts +1 -0
  29. package/dist/runtime/components/LibColorPicker/utils/truncate.js +5 -0
  30. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +42 -64
  31. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue.d.ts +22 -0
  32. package/dist/runtime/components/LibDatePicker/LibDatePicker.vue +20 -54
  33. package/dist/runtime/components/LibDatePicker/LibDatePicker.vue.d.ts +40 -0
  34. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +205 -173
  35. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue.d.ts +34 -0
  36. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +215 -164
  37. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue.d.ts +34 -0
  38. package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue +9 -10
  39. package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue.d.ts +22 -0
  40. package/dist/runtime/components/LibDebug/LibDebug.vue +47 -65
  41. package/dist/runtime/components/LibDebug/LibDebug.vue.d.ts +32 -0
  42. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +19 -34
  43. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue.d.ts +22 -0
  44. package/dist/runtime/components/LibFileInput/LibFileInput.vue +155 -173
  45. package/dist/runtime/components/LibFileInput/LibFileInput.vue.d.ts +43 -0
  46. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +352 -0
  47. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue.d.ts +165 -0
  48. package/dist/runtime/components/LibLabel/LibLabel.vue +30 -46
  49. package/dist/runtime/components/LibLabel/LibLabel.vue.d.ts +27 -0
  50. package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +50 -66
  51. package/dist/runtime/components/LibMultiValues/LibMultiValues.vue.d.ts +29 -0
  52. package/dist/runtime/components/LibNotifications/LibNotification.vue +48 -56
  53. package/dist/runtime/components/LibNotifications/LibNotification.vue.d.ts +17 -0
  54. package/dist/runtime/components/LibNotifications/LibNotifications.vue +71 -83
  55. package/dist/runtime/components/LibNotifications/LibNotifications.vue.d.ts +13 -0
  56. package/dist/runtime/components/LibPagination/LibPagination.vue +86 -131
  57. package/dist/runtime/components/LibPagination/LibPagination.vue.d.ts +104 -0
  58. package/dist/runtime/components/LibPalette/LibPalette.vue +23 -26
  59. package/dist/runtime/components/LibPalette/LibPalette.vue.d.ts +14 -0
  60. package/dist/runtime/components/LibPopup/LibPopup.vue +326 -400
  61. package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +46 -0
  62. package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +73 -93
  63. package/dist/runtime/components/LibProgressBar/LibProgressBar.vue.d.ts +41 -0
  64. package/dist/runtime/components/LibRecorder/LibRecorder.vue +134 -179
  65. package/dist/runtime/components/LibRecorder/LibRecorder.vue.d.ts +77 -0
  66. package/dist/runtime/components/LibRoot/LibRoot.vue +75 -89
  67. package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +41 -0
  68. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +51 -82
  69. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue.d.ts +35 -0
  70. package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +147 -164
  71. package/dist/runtime/components/LibSuggestions/LibSuggestions.vue.d.ts +94 -0
  72. package/dist/runtime/components/LibTable/LibTable.vue +69 -106
  73. package/dist/runtime/components/LibTable/LibTable.vue.d.ts +45 -0
  74. package/dist/runtime/components/Template/NAME.vue +15 -36
  75. package/dist/runtime/components/Template/NAME.vue.d.ts +17 -0
  76. package/dist/runtime/components/TestControls/TestControls.vue +7 -10
  77. package/dist/runtime/components/TestControls/TestControls.vue.d.ts +5 -0
  78. package/dist/runtime/components/index.d.ts +12 -11
  79. package/dist/runtime/components/index.js +12 -11
  80. package/dist/runtime/components/shared/props.d.ts +81 -16
  81. package/dist/runtime/components/shared/storyHelpers/playInput.js +5 -5
  82. package/dist/runtime/components/shared/storyHelpers/playSuggestions.js +15 -11
  83. package/dist/runtime/composables/index.d.ts +5 -0
  84. package/dist/runtime/composables/index.js +5 -0
  85. package/dist/runtime/composables/useDivideAttrs.js +1 -0
  86. package/dist/runtime/composables/useDragWithThreshold.d.ts +71 -0
  87. package/dist/runtime/composables/useDragWithThreshold.js +40 -0
  88. package/dist/runtime/composables/usePreHydrationValue.d.ts +12 -0
  89. package/dist/runtime/composables/usePreHydrationValue.js +15 -0
  90. package/dist/runtime/composables/useSetupI18n.d.ts +2 -0
  91. package/dist/runtime/composables/useSetupI18n.js +5 -1
  92. package/dist/runtime/composables/useSuggestions.d.ts +7 -5
  93. package/dist/runtime/composables/useSuggestions.js +94 -57
  94. package/dist/runtime/directives/vResizableCols.js +92 -84
  95. package/dist/runtime/helpers/NotificationHandler.d.ts +5 -0
  96. package/dist/runtime/helpers/index.d.ts +3 -1
  97. package/dist/runtime/helpers/index.js +3 -1
  98. package/dist/runtime/types/index.d.ts +6 -0
  99. package/dist/runtime/utils/notifyIfError.d.ts +14 -0
  100. package/dist/runtime/utils/notifyIfError.js +29 -0
  101. package/dist/types.d.mts +2 -6
  102. package/package.json +27 -29
  103. package/src/module.ts +31 -12
  104. package/src/runtime/assets/base.css +10 -1
  105. package/src/runtime/assets/locales/en.json +2 -2
  106. package/src/runtime/assets/tailwind.css +1 -1
  107. package/src/runtime/assets/{style.css → utils.css} +86 -4
  108. package/src/runtime/build/WitchcraftUiResolver.ts +1 -1
  109. package/src/runtime/components/Focus.stories.ts +3 -2
  110. package/src/runtime/components/Icon/Icon.vue +10 -6
  111. package/src/runtime/components/LibButton/LibButton.vue +41 -47
  112. package/src/runtime/components/LibCheckbox/LibCheckbox.vue +7 -4
  113. package/src/runtime/components/LibColorInput/LibColorInput.vue +111 -37
  114. package/src/runtime/components/LibColorPicker/LibColorPicker.stories.ts +25 -4
  115. package/src/runtime/components/LibColorPicker/LibColorPicker.vue +242 -131
  116. package/src/runtime/components/LibColorPicker/utils/safeConvertToHsva.ts +24 -0
  117. package/src/runtime/components/LibColorPicker/utils/safeConvertToRgba.ts +23 -0
  118. package/src/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.ts +13 -0
  119. package/src/runtime/components/LibColorPicker/utils/truncate.ts +6 -0
  120. package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.ts +1 -1
  121. package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +11 -9
  122. package/src/runtime/components/LibDatePicker/LibDatePicker.vue +4 -17
  123. package/src/runtime/components/LibDatePicker/LibRangeDatePicker.vue +192 -131
  124. package/src/runtime/components/LibDatePicker/LibSingleDatePicker.vue +183 -115
  125. package/src/runtime/components/LibDatePicker/LibTimeZonePicker.vue +3 -3
  126. package/src/runtime/components/LibDebug/LibDebug.vue +15 -5
  127. package/src/runtime/components/LibDevOnly/LibDevOnly.vue +1 -3
  128. package/src/runtime/components/LibFileInput/LibFileInput.vue +54 -29
  129. package/src/runtime/components/{LibInput/LibInput.stories.ts → LibInputDeprecated/LibInputDeprecated.stories.ts} +64 -19
  130. package/{dist/runtime/components/LibInput/LibInput.vue → src/runtime/components/LibInputDeprecated/LibInputDeprecated.vue} +40 -34
  131. package/src/runtime/components/LibLabel/LibLabel.vue +2 -2
  132. package/src/runtime/components/LibMultiValues/LibMultiValues.stories.ts +5 -4
  133. package/src/runtime/components/LibMultiValues/LibMultiValues.vue +11 -13
  134. package/src/runtime/components/LibNotifications/LibNotification.vue +19 -11
  135. package/src/runtime/components/LibNotifications/LibNotifications.stories.ts +2 -2
  136. package/src/runtime/components/LibNotifications/LibNotifications.vue +20 -12
  137. package/src/runtime/components/LibPagination/LibPagination.stories.ts +2 -2
  138. package/src/runtime/components/LibPagination/LibPagination.vue +19 -20
  139. package/src/runtime/components/LibPalette/LibPalette.vue +3 -3
  140. package/src/runtime/components/LibPopup/LibPopup.stories.ts +2 -2
  141. package/src/runtime/components/LibPopup/LibPopup.vue +30 -67
  142. package/src/runtime/components/LibProgressBar/LibProgressBar.vue +3 -2
  143. package/src/runtime/components/LibRecorder/LibRecorder.vue +2 -3
  144. package/src/runtime/components/LibRoot/LibRoot.vue +14 -1
  145. package/src/runtime/components/LibSimpleInput/LibSimpleInput.stories.ts +1 -1
  146. package/src/runtime/components/LibSimpleInput/LibSimpleInput.vue +5 -8
  147. package/src/runtime/components/LibSuggestions/LibSuggestions.vue +42 -26
  148. package/src/runtime/components/LibTable/LibTable.vue +8 -9
  149. package/src/runtime/components/Scrolling.stories.ts +58 -0
  150. package/src/runtime/components/Template/NAME.vue +1 -1
  151. package/src/runtime/components/TestControls/TestControls.vue +1 -1
  152. package/src/runtime/components/index.ts +12 -12
  153. package/src/runtime/components/shared/props.ts +82 -19
  154. package/src/runtime/components/shared/storyHelpers/playInput.ts +6 -5
  155. package/src/runtime/components/shared/storyHelpers/playSuggestions.ts +25 -11
  156. package/src/runtime/composables/index.ts +5 -0
  157. package/src/runtime/composables/useDarkMode.ts +2 -2
  158. package/src/runtime/composables/useDivideAttrs.ts +1 -0
  159. package/src/runtime/composables/useDragWithThreshold.ts +108 -0
  160. package/src/runtime/composables/usePreHydrationValue.ts +30 -0
  161. package/src/runtime/composables/useSetupI18n.ts +8 -2
  162. package/src/runtime/composables/useSuggestions.ts +92 -45
  163. package/src/runtime/directives/vResizableCols.ts +82 -74
  164. package/src/runtime/helpers/NotificationHandler.ts +5 -0
  165. package/src/runtime/helpers/index.ts +3 -1
  166. package/src/runtime/types/index.ts +5 -0
  167. package/src/runtime/utils/notifyIfError.ts +45 -0
  168. package/dist/module.cjs +0 -5
  169. package/dist/module.d.ts +0 -34
  170. package/dist/runtime/assets/style.css +0 -1
  171. package/dist/runtime/components/Focus.stories.d.ts +0 -11
  172. package/dist/runtime/components/Focus.stories.js +0 -53
  173. package/dist/runtime/components/LibButton/LibButton.stories.d.ts +0 -12
  174. package/dist/runtime/components/LibButton/LibButton.stories.js +0 -94
  175. package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.d.ts +0 -14
  176. package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.js +0 -29
  177. package/dist/runtime/components/LibColorInput/LibColorInput.stories.d.ts +0 -7
  178. package/dist/runtime/components/LibColorInput/LibColorInput.stories.js +0 -58
  179. package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.d.ts +0 -7
  180. package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.js +0 -51
  181. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.d.ts +0 -7
  182. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.js +0 -36
  183. package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.d.ts +0 -11
  184. package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.js +0 -98
  185. package/dist/runtime/components/LibDebug/LibDebug.stories.d.ts +0 -9
  186. package/dist/runtime/components/LibDebug/LibDebug.stories.js +0 -46
  187. package/dist/runtime/components/LibFileInput/LibFileInput.stories.d.ts +0 -10
  188. package/dist/runtime/components/LibFileInput/LibFileInput.stories.js +0 -63
  189. package/dist/runtime/components/LibInput/LibInput.stories.d.ts +0 -33
  190. package/dist/runtime/components/LibInput/LibInput.stories.js +0 -339
  191. package/dist/runtime/components/LibLabel/LibLabel.stories.d.ts +0 -6
  192. package/dist/runtime/components/LibLabel/LibLabel.stories.js +0 -25
  193. package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.d.ts +0 -23
  194. package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.js +0 -60
  195. package/dist/runtime/components/LibNotifications/LibNotification.stories.d.ts +0 -15
  196. package/dist/runtime/components/LibNotifications/LibNotification.stories.js +0 -126
  197. package/dist/runtime/components/LibNotifications/LibNotifications.stories.d.ts +0 -6
  198. package/dist/runtime/components/LibNotifications/LibNotifications.stories.js +0 -109
  199. package/dist/runtime/components/LibPagination/LibPagination.stories.d.ts +0 -6
  200. package/dist/runtime/components/LibPagination/LibPagination.stories.js +0 -40
  201. package/dist/runtime/components/LibPalette/LibPalette.stories.d.ts +0 -6
  202. package/dist/runtime/components/LibPalette/LibPalette.stories.js +0 -20
  203. package/dist/runtime/components/LibPopup/LibPopup.stories.d.ts +0 -14
  204. package/dist/runtime/components/LibPopup/LibPopup.stories.js +0 -147
  205. package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.d.ts +0 -10
  206. package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.js +0 -81
  207. package/dist/runtime/components/LibRecorder/LibRecorder.stories.d.ts +0 -19
  208. package/dist/runtime/components/LibRecorder/LibRecorder.stories.js +0 -63
  209. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.d.ts +0 -26
  210. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.js +0 -78
  211. package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.d.ts +0 -27
  212. package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.js +0 -112
  213. package/dist/runtime/components/LibTable/LibTable.stories.d.ts +0 -16
  214. package/dist/runtime/components/LibTable/LibTable.stories.js +0 -156
  215. package/dist/runtime/components/reset.stories.d.ts +0 -5
  216. package/dist/runtime/components/reset.stories.js +0 -19
  217. package/dist/runtime/composables/useScrollNearContainerEdges.stories.d.ts +0 -7
  218. package/dist/runtime/composables/useScrollNearContainerEdges.stories.js +0 -85
  219. package/dist/runtime/helpers/addValue.d.ts +0 -1
  220. package/dist/runtime/helpers/addValue.js +0 -8
  221. package/dist/types.d.ts +0 -7
  222. package/src/runtime/components/LibInput/LibInput.vue +0 -372
  223. package/src/runtime/helpers/addValue.ts +0 -10
  224. /package/src/runtime/components/{reset.stories.ts → Reset.stories.ts} +0 -0
@@ -1,7 +1,9 @@
1
1
  <template>
2
- <div :id="id ?? fallbackId"
2
+ <div
3
+ :id="id ?? fallbackId"
3
4
  :aria-label="t('color-picker.aria')"
4
- :class="twMerge(`color-picker
5
+ :class="twMerge(
6
+ `color-picker
5
7
  [--slider-size:calc(var(--spacing)_*_4)]
6
8
  [--contrast-dark:var(--color-neutral-100)]
7
9
  [--contrast-light:var(--color-neutral-800)]
@@ -14,17 +16,18 @@
14
16
  gap-3
15
17
  p-3
16
18
  `,
17
- invertColors && `
19
+ invertColors && `
18
20
  [--fg:rgb(var(--contrast-light))]
19
21
  [--bg:rgb(var(--contrast-dark))]
20
22
  `,
21
- border && `
23
+ border && `
22
24
  border rounded-sm border-neutral-600
23
- `
24
- )"
25
+ `,
26
+ $attrs?.class
27
+ )"
25
28
  >
26
29
  <div
27
- :class="`picker
30
+ :class="`color-picker--all-picker
28
31
  no-touch-action
29
32
  w-full
30
33
  aspect-square
@@ -33,7 +36,7 @@
33
36
  rounded-sm
34
37
  focus:border-accent-500
35
38
  `"
36
- @pointerdown="slider.pointerdown($event, 'picker')"
39
+ @pointerdown="slider.pointerdown($event, 'all')"
37
40
  @pointerleave="slider.pointerleave($event)"
38
41
  >
39
42
  <canvas
@@ -43,8 +46,10 @@
43
46
  <div
44
47
  aria-live="assertive"
45
48
  :aria-description="ariaDescription"
49
+ :aria-label="`${t('color-picker.aria.saturation')}: ${localColor.percent.s}, ${t('color-picker.aria.value')}: ${localColor.percent.s}`"
46
50
  :class="`
47
- handle ${handleClasses}
51
+ color-picker--all-handle
52
+ ${handleClasses}
48
53
  border-[var(--fg)]
49
54
  hover:shadow-black
50
55
  active:shadow-black
@@ -53,15 +58,13 @@
53
58
  :style="`
54
59
  left: calc(${localColor.percent.s}% - var(--slider-size)/2);
55
60
  top: calc(${localColor.percent.v}% - var(--slider-size)/2);
56
- background: ${localColorStringOpaque};
61
+ background: ${asRgbaString};
57
62
  `"
58
- @keydown="slider.keydown($event, 'picker')"
59
- >
60
- <aria :value="`${t('color-picker.aria.saturation')}: ${localColor.percent.s}, ${t('color-picker.aria.value')}: ${localColor.percent.s}`"/>
61
- </div>
63
+ @keydown="slider.keydown($event, 'all')"
64
+ />
62
65
  </div>
63
66
  <div
64
- :class="`hue-slider ${sliderClasses}`"
67
+ :class="`color-picker--hue-slider ${sliderClasses}`"
65
68
  @pointerdown="slider.pointerdown($event, 'hue')"
66
69
  >
67
70
  <canvas
@@ -76,7 +79,10 @@
76
79
  :aria-label="t('color-picker.aria.hue')"
77
80
  :aria-description="ariaDescription"
78
81
  tabindex="0"
79
- :class="`handle ${handleClasses} bg-neutral-50`"
82
+ :class="`
83
+ color-picker--hue-handle
84
+ ${handleClasses}
85
+ `"
80
86
  :style="`left: calc(${localColor.percent.h}% - var(--slider-size)/2)`"
81
87
  @keydown="slider.keydown($event, 'hue')"
82
88
  />
@@ -84,8 +90,10 @@
84
90
  <div
85
91
  v-if="allowAlpha"
86
92
 
87
- :class="`alpha-slider ${sliderClasses}`"
88
- @keydown="slider.keydown($event, 'alpha')"
93
+ :class="`
94
+ color-picker--alpha-slider
95
+ ${sliderClasses}
96
+ `"
89
97
  @pointerdown="slider.pointerdown($event, 'alpha')"
90
98
  >
91
99
  <canvas
@@ -100,12 +108,13 @@
100
108
  :aria-valuemax="100"
101
109
  :aria-description="ariaDescription"
102
110
  tabindex="0"
103
- :class="`handle ${handleClasses} bg-neutral-50`"
111
+ :class="`color-picker--alpha-handle ${handleClasses}`"
104
112
  :style="`left: calc(${localColor.percent.a}% - var(--slider-size)/2)`"
113
+ @keydown="slider.keydown($event, 'alpha')"
105
114
  />
106
115
  </div>
107
- <div class="color-group flex w-full flex-1 gap-2">
108
- <div class=" color-wrapper
116
+ <div class="color-picker--footer flex w-full flex-1 gap-2">
117
+ <div class=" color-picker--preview-wrapper
109
118
  bg-transparency-squares
110
119
  relative
111
120
  aspect-square
@@ -114,63 +123,75 @@
114
123
  shadow-xs
115
124
  "
116
125
  >
117
- <!-- <input class="color-input" :value="localColorString" @input="parseInput"> -->
118
- <div class="color
126
+ <div class="
127
+ color-picker--footer--preview
119
128
  size-full
120
129
  rounded-full
121
130
  border-2
122
131
  border-neutral-600
123
132
  dark:border-neutral-300
124
133
  "
125
- :style="`background:${localColorString}`"
134
+ :style="`background: ${asRgbaString}`"
126
135
  />
127
136
  </div>
128
- <div class="color-controls flex flex-1 items-center gap-2">
137
+ <div class="color-picker--input-group flex flex-1 items-center gap-2">
129
138
  <slot name="input">
130
139
  <lib-simple-input
131
- class="w-full"
140
+ :valid="valid"
141
+ class="color-picker--input w-full"
132
142
  :aria-label="label"
133
- :model-value="localColorString"
143
+ v-model="localInputString"
134
144
  @input="parseInput"
145
+ @blur="onBlurFixInvalidValue"
135
146
  />
136
- <lib-button :aria-label="t('copy')" @click="copy()">
147
+ <lib-button class="color-picker--copy-button" :aria-label="t('copy')" @click="copy(copyTransform?.(localColor.val, localColorString) ?? localColorString)">
137
148
  <icon><i-fa6-regular-copy/></icon>
138
149
  </lib-button>
139
150
  </slot>
140
151
  </div>
141
- <!-- <lib-button @click="emits('update:modelValue', localColor.val)">Save</lib-button> -->
142
152
  </div>
143
153
  <slot name="buttons">
144
- <div class="save-cancel-group flex w-full items-center justify-center gap-2">
145
- <lib-button @click="save()">{{ t("save") }}</lib-button>
146
- <lib-button @click="emits('cancel')">{{ t("cancel") }}</lib-button>
154
+ <div class="color-picker--save-cancel-group flex w-full items-center justify-center gap-2">
155
+ <lib-button
156
+ class="color-picker--save-button"
157
+ @click="save()"
158
+ >
159
+ {{ t("save") }}
160
+ </lib-button>
161
+ <lib-button
162
+ class="color-picker--cancel-button"
163
+ @click="emits('cancel')"
164
+ >
165
+ {{ t("cancel") }}
166
+ </lib-button>
147
167
  </div>
148
168
  </slot>
149
169
  </div>
150
170
  </template>
151
171
 
152
- <script setup lang="ts">
153
- /* todo change to colorjsio for less dependencies */
154
- import { castType } from "@alanscodelog/utils/castType.js"
155
- import { isArray } from "@alanscodelog/utils/isArray.js"
156
- import { colord } from "colord"
157
- import { computed, onMounted, type PropType, reactive, type Ref, ref, type UnwrapRef,watch } from "vue"
158
-
159
- import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
160
- import type { HsvaColor, RgbaColor } from "../../types/index.js"
161
- import { twMerge } from "../../utils/twMerge.js"
162
- import aria from "../Aria/Aria.vue"
163
- import Icon from "../Icon/Icon.vue"
164
- import LibButton from "../LibButton/LibButton.vue"
165
- import LibSimpleInput from "../LibSimpleInput/LibSimpleInput.vue"
166
- import { getFallbackId, type LabelProps , type LinkableByIdProps } from "../shared/props.js"
167
-
172
+ <script setup>
173
+ import { castType } from "@alanscodelog/utils/castType.js";
174
+ import { clampNumber } from "@alanscodelog/utils/clampNumber.js";
175
+ import { isArray } from "@alanscodelog/utils/isArray.js";
176
+ import { unreachable } from "@alanscodelog/utils/unreachable.js";
177
+ import Color from "colorjs.io";
178
+ import { computed, onMounted, reactive, ref, useAttrs, watch } from "vue";
179
+ import { safeConvertToHsva } from "./utils/safeConvertToHsva.js";
180
+ import { safeConvertToRgba } from "./utils/safeConvertToRgba.js";
181
+ import { toLowPrecisionRgbaString } from "./utils/toLowPrecisionRgbaString.js";
182
+ import { useInjectedI18n } from "../../composables/useInjectedI18n.js";
183
+ import { copy } from "../../helpers/copy.js";
184
+ import { twMerge } from "../../utils/twMerge.js";
185
+ import aria from "../Aria/Aria.vue";
186
+ import Icon from "../Icon/Icon.vue";
187
+ import LibButton from "../LibButton/LibButton.vue";
188
+ import LibSimpleInput from "../LibSimpleInput/LibSimpleInput.vue";
189
+ import { getFallbackId } from "../shared/props.js";
168
190
  defineOptions({
169
- name: "lib-color-picker",
170
- })
171
-
172
- const t = useInjectedI18n()
173
-
191
+ name: "lib-color-picker"
192
+ });
193
+ const $attrs = useAttrs();
194
+ const t = useInjectedI18n();
174
195
  const sliderClasses = `
175
196
  slider
176
197
  no-touch-action
@@ -178,9 +199,9 @@ const sliderClasses = `
178
199
  w-full
179
200
  relative
180
201
  flex
181
- `
182
-
202
+ `;
183
203
  const handleClasses = `
204
+ handle
184
205
  h-[var(--slider-size)]
185
206
  w-[var(--slider-size)]
186
207
  shadow-xs
@@ -193,256 +214,265 @@ const handleClasses = `
193
214
  focus:border-accent-500
194
215
  active:border-accent-500
195
216
  hover:border-accent-500
196
- `
197
-
198
-
199
- const ariaDescription = t("color-picker.aria.description")
200
-
201
- const $value = defineModel<RgbaColor>({ required: false, default: () => ({ r: 0, g: 0, b: 0 }) })
202
-
203
- const fallbackId = getFallbackId()
204
- const props = withDefaults(defineProps<
205
- & LabelProps
206
- & LinkableByIdProps
207
- & {
208
- allowAlpha?: boolean
209
- border?: boolean
210
- copyTransform?: (val: HsvaColor, stringVal: string) => any
211
- }>(), {
212
- allowAlpha: true,
213
- border: true,
214
- copyTransform: (_val: HsvaColor, stringVal: string) => stringVal,
215
- })
216
-
217
-
218
- const emits = defineEmits<{
219
- (e: "save", val: RgbaColor): void
220
- (e: "cancel"): void
221
- }>()
222
-
223
- const pickerEl = ref<HTMLCanvasElement | null>(null)
224
- const hueSliderEl = ref<HTMLCanvasElement | null>(null)
225
- const alphaSliderEl = ref<HTMLCanvasElement | null>(null)
226
-
227
- type Config = Record<string, { el: Ref<HTMLCanvasElement>, xKey?: keyof HsvaColor, yKey?: keyof HsvaColor, xSteps?: number, ySteps?: number }>
228
- const config: Config = {
229
- hue: {
230
- el: hueSliderEl as Ref<HTMLCanvasElement>,
231
- xKey: "h",
232
- xSteps: 360,
233
- },
234
- alpha: {
235
- el: alphaSliderEl as Ref<HTMLCanvasElement>,
236
- xSteps: 1,
237
- xKey: "a",
238
- },
239
- picker: {
240
- el: pickerEl as Ref<HTMLCanvasElement>,
241
- xSteps: 100,
242
- ySteps: 100,
243
- xKey: "s",
244
- yKey: "v",
245
- },
217
+ `;
218
+ const emits = defineEmits(["save", "cancel"]);
219
+ const props = defineProps({
220
+ label: { type: String, required: false },
221
+ id: { type: String, required: false },
222
+ allowAlpha: { type: Boolean, required: false, default: true },
223
+ stringPrecision: { type: Number, required: false, default: 3 },
224
+ customRepresentation: { type: Object, required: false, default: void 0 },
225
+ border: { type: Boolean, required: false, default: true },
226
+ copyTransform: { type: Function, required: false, default: (_val, stringVal) => stringVal },
227
+ valid: { type: Boolean, required: false, default: true }
228
+ });
229
+ const ariaDescription = t("color-picker.aria.description");
230
+ const fallbackId = getFallbackId();
231
+ const $value = defineModel({ type: Object, ...{ required: false, default: () => ({ r: 0, g: 0, b: 0 }) } });
232
+ const $tempValue = defineModel("tempValue", { type: null, ...{ required: false, default: () => void 0 } });
233
+ const pickerEl = ref(null);
234
+ const hueSliderEl = ref(null);
235
+ const alphaSliderEl = ref(null);
236
+ const config = {
237
+ hue: {
238
+ el: hueSliderEl,
239
+ xKey: "h",
240
+ xSteps: 360
241
+ },
242
+ alpha: {
243
+ el: alphaSliderEl,
244
+ xSteps: 1,
245
+ xKey: "a"
246
+ },
247
+ all: {
248
+ el: pickerEl,
249
+ xSteps: 100,
250
+ ySteps: 100,
251
+ xKey: "s",
252
+ yKey: "v"
253
+ }
254
+ };
255
+ const localColor = reactive({
256
+ percent: {
257
+ h: 0,
258
+ s: 0,
259
+ v: 0,
260
+ a: 0
261
+ },
262
+ val: {
263
+ h: 0,
264
+ s: 0,
265
+ v: 0,
266
+ a: 0
267
+ }
268
+ });
269
+ const asRgba = computed(() => {
270
+ const rgba = safeConvertToRgba(localColor.val, props.allowAlpha);
271
+ if (!rgba) unreachable();
272
+ return rgba;
273
+ });
274
+ const asRgbaString = computed(() => {
275
+ const rgba = asRgba.value;
276
+ if (!rgba) unreachable();
277
+ return `rgba(${rgba.r}, ${rgba.g}, ${rgba.b}, ${rgba.a})`;
278
+ });
279
+ const localColorString = computed(() => {
280
+ if (props.customRepresentation) {
281
+ return props.customRepresentation.fromHsvaToString({ ...localColor.val }, props.allowAlpha);
282
+ }
283
+ return toLowPrecisionRgbaString(asRgba.value, props.allowAlpha, props.stringPrecision);
284
+ });
285
+ const localInputString = ref(localColorString.value);
286
+ function onBlurFixInvalidValue() {
287
+ if (localInputString.value !== localColorString.value) {
288
+ localInputString.value = localColorString.value;
289
+ }
246
290
  }
247
- const localColor = reactive<Record<"percent" | "val", HsvaColor>>({
248
- percent: {
249
- h: 0, s: 0, v: 0, a: 0,
250
- },
251
- val: {
252
- h: 0, s: 0, v: 0, a: 0,
253
- },
254
- })
255
-
256
- const localColorString = computed(() =>
257
- colord(localColor.val).toRgbString(),
258
- )
259
- const localColorStringOpaque = computed(() =>
260
- colord({ ...localColor.val, a: 1 }).toRgbString(),
261
- )
262
-
263
-
264
- const copy = (): void => {
265
- if (navigator.clipboard) {
266
- const text = props.copyTransform?.(localColor.val, localColorString.value)
267
-
268
- navigator.clipboard.writeText(text).catch(() => { })
269
- }
291
+ function updatePicker(el, hue) {
292
+ const ctx = el.getContext("2d");
293
+ const { height, width } = el;
294
+ ctx.clearRect(0, 0, width, height);
295
+ const gradient = ctx.createLinearGradient(0, 0, 0, height);
296
+ gradient.addColorStop(0, "white");
297
+ gradient.addColorStop(1, "black");
298
+ const gradientColor = ctx.createLinearGradient(0, 0, width, 0);
299
+ gradientColor.addColorStop(0, `hsla(${hue} 100% 50% / 0)`);
300
+ gradientColor.addColorStop(1, `hsla(${hue} 100% 50% /1)`);
301
+ ctx.fillStyle = gradient;
302
+ ctx.fillRect(0, 0, width, height);
303
+ ctx.fillStyle = gradientColor;
304
+ ctx.globalCompositeOperation = "multiply";
305
+ ctx.fillRect(0, 0, width, height);
306
+ ctx.globalCompositeOperation = "source-over";
270
307
  }
271
-
272
- const updatePicker = (el: HTMLCanvasElement, hue: number): void => {
273
- const ctx = el.getContext("2d")!
274
- const { height, width } = el
275
- ctx.clearRect(0, 0, width, height)
276
-
277
- const gradient = ctx.createLinearGradient(0, 0, 0, height)
278
- gradient.addColorStop(0, "white")
279
- gradient.addColorStop(1, "black")
280
- const gradientColor = ctx.createLinearGradient(0, 0, width, 0)
281
- gradientColor.addColorStop(0, `hsla(${hue} 100% 50% / 0)`)
282
- gradientColor.addColorStop(1, `hsla(${hue} 100% 50% /1)`)
283
-
284
-
285
- ctx.fillStyle = gradient
286
- ctx.fillRect(0, 0, width, height)
287
- ctx.fillStyle = gradientColor
288
- ctx.globalCompositeOperation = "multiply"
289
- ctx.fillRect(0, 0, width, height)
290
- ctx.globalCompositeOperation = "source-over"
291
- }
292
-
293
- const updateSlider = (el: HTMLCanvasElement, stops: ((i: number) => string) | string[], length: number = 360): void => {
294
- const ctx = el.getContext("2d")!
295
- const { height, width } = el// .getBoundingClientRect()
296
- ctx.clearRect(0, 0, width, height)
297
-
298
- const end = isArray(stops) ? stops.length - 1 : length
299
-
300
- const gradient = ctx.createLinearGradient(0, 0, width, 0)
301
-
302
- for (let i = 0; i < end + 1; i++) {
303
- const stop = stops instanceof Function ? stops(i) : stops[i]
304
- gradient.addColorStop(i / end, stop)
305
- }
306
-
307
- ctx.fillStyle = gradient
308
- ctx.fillRect(0, 0, width, height)
308
+ function updateSlider(el, stops, length = 360) {
309
+ const ctx = el.getContext("2d");
310
+ const { height, width } = el;
311
+ ctx.clearRect(0, 0, width, height);
312
+ const end = isArray(stops) ? stops.length - 1 : length;
313
+ const gradient = ctx.createLinearGradient(0, 0, width, 0);
314
+ for (let i = 0; i < end + 1; i++) {
315
+ const stop = stops instanceof Function ? stops(i) : stops[i];
316
+ if (stop === void 0) unreachable();
317
+ gradient.addColorStop(i / end, stop);
318
+ }
319
+ ctx.fillStyle = gradient;
320
+ ctx.fillRect(0, 0, width, height);
309
321
  }
310
-
311
-
312
- const getVal = (x: number, width: number, steps: number = 100, accuracy: number = 100, reverse = false): { val: number, percent: number } => {
313
- // const stepWidth = width / (steps * accuracy)
314
- const percent = (x / width)
315
- const unrounded = percent * steps
316
-
317
- const val = Math.round(unrounded * accuracy) / accuracy
318
- const percentVal = steps === accuracy ? val : Math.round(percent * 100 * accuracy) / accuracy
319
- const res = { val, percent: percentVal }
320
- if (reverse) res.val = steps - val
321
- return res
322
+ function getVal(x, width, steps = 100, accuracy = 100, reverse = false) {
323
+ const percent = x / width;
324
+ const unrounded = percent * steps;
325
+ const val = Math.round(unrounded * accuracy) / accuracy;
326
+ const percentVal = steps === accuracy ? val : Math.round(percent * 100 * accuracy) / accuracy;
327
+ const res = { val, percent: percentVal };
328
+ if (reverse) res.val = steps - val;
329
+ return res;
322
330
  }
323
- type Types = keyof UnwrapRef<Config>
324
- const elDragging = ref<Types | "">("")
325
- let dragging = false
326
-
327
- const moveHandle = (e: { clientX: number, clientY: number }, type: string) => {
328
- const el = config[type].el.value
329
- const { x, y, width, height } = el.getBoundingClientRect()
330
-
331
- const info = config[type]
332
- if (info.xKey !== undefined) {
333
- let newPosX = e.clientX - x
334
- newPosX = newPosX < 0 ? 0 : newPosX > width ? width : newPosX
335
- const newX = getVal(newPosX, width, info.xSteps ?? 100)
336
-
337
- localColor.percent[info.xKey] = newX.percent
338
- localColor.val[info.xKey] = newX.val
339
- }
340
-
341
- if (info.yKey !== undefined) {
342
- let newPosY = e.clientY - y
343
- newPosY = newPosY < 0 ? 0 : newPosY > height ? height : newPosY
344
- const newY = getVal(newPosY, height, info.ySteps ?? 100, 100, true)
345
-
346
- localColor.percent[info.yKey] = newY.percent
347
- localColor.val[info.yKey] = newY.val
348
- }
331
+ const elDragging = ref("");
332
+ let dragging = false;
333
+ function moveHandle(e, type) {
334
+ requestAnimationFrame(() => {
335
+ if (type === "") return;
336
+ const el = config[type]?.el.value;
337
+ if (!el || !config[type]) return;
338
+ const { x, y, width, height } = el.getBoundingClientRect();
339
+ const info = config[type];
340
+ if (info.xKey !== void 0) {
341
+ let newPosX = e.clientX - x;
342
+ newPosX = newPosX < 0 ? 0 : newPosX > width ? width : newPosX;
343
+ const newX = getVal(newPosX, width, info.xSteps ?? 100);
344
+ localColor.percent[info.xKey] = newX.percent;
345
+ localColor.val[info.xKey] = newX.val;
346
+ }
347
+ if (info.yKey !== void 0) {
348
+ let newPosY = e.clientY - y;
349
+ newPosY = newPosY < 0 ? 0 : newPosY > height ? height : newPosY;
350
+ const newY = getVal(newPosY, height, info.ySteps ?? 100, 100, true);
351
+ localColor.percent[info.yKey] = newY.percent;
352
+ localColor.val[info.yKey] = newY.val;
353
+ }
354
+ });
349
355
  }
350
356
  const slider = {
351
- keydown: (e: KeyboardEvent, type: Types) => {
352
- castType<HTMLElement | undefined>(e.target)
353
- if (e.target?.getBoundingClientRect && ["ArrowRight", "ArrowLeft", "ArrowUp", "ArrowDown"].includes(e.key)) {
354
- e.preventDefault()
355
- const { x, y, width, height } = e.target.getBoundingClientRect()
356
- let xDiff = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0
357
- let yDiff = e.key === "ArrowUp" ? -1 : e.key === "ArrowDown" ? 1 : 0
358
- if (e.shiftKey) {xDiff *= 10}
359
- if (e.shiftKey) {yDiff *= 10}
360
- moveHandle({ clientX: x + (width / 2) + xDiff, clientY: y + (height / 2) + yDiff }, type)
361
- }
362
- },
363
- pointerdown: (e: PointerEvent, type: Types) => {
364
- if (dragging) return
365
- e.preventDefault()
366
- elDragging.value = type
367
- dragging = true
368
- document.addEventListener("pointermove", slider.pointermove)
369
- document.addEventListener("pointerup", slider.pointerup)
370
- },
371
- pointerleave: (e: PointerEvent) => {
372
- if (dragging) {
373
- e.preventDefault()
374
- }
375
- },
376
- pointermove: (e: PointerEvent) => {
377
- if (dragging) {
378
- e.preventDefault()
379
- requestAnimationFrame(() => {
380
- const type = elDragging.value
381
- moveHandle(e, type)
382
- })
383
- }
384
- },
385
- pointerup: (e: PointerEvent) => {
386
- e.preventDefault()
387
- elDragging.value = ""
388
- dragging = false
389
- document.removeEventListener("pointermove", slider.pointermove)
390
- document.removeEventListener("pointerup", slider.pointerup)
391
- },
357
+ keydown: (e, type) => {
358
+ castType(e.target);
359
+ if (e.target?.getBoundingClientRect) {
360
+ if (["ArrowRight", "ArrowLeft", "ArrowUp", "ArrowDown"].includes(e.key)) {
361
+ e.preventDefault();
362
+ const { x, y, width, height } = e.target.getBoundingClientRect();
363
+ let xDiff = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0;
364
+ let yDiff = e.key === "ArrowUp" ? -1 : e.key === "ArrowDown" ? 1 : 0;
365
+ if (e.shiftKey) {
366
+ xDiff *= 10;
367
+ }
368
+ if (e.shiftKey) {
369
+ yDiff *= 10;
370
+ }
371
+ moveHandle({ clientX: x + width / 2 + xDiff, clientY: y + height / 2 + yDiff }, type);
372
+ }
373
+ if (e.key === "Enter") {
374
+ e.preventDefault();
375
+ save();
376
+ }
377
+ }
378
+ },
379
+ pointerdown: (e, type) => {
380
+ const focusTargetClass = `#${props.id ?? fallbackId} .color-picker--${type}-handle`;
381
+ const focusTarget = document.querySelector(focusTargetClass);
382
+ if (focusTarget instanceof HTMLElement) focusTarget.focus();
383
+ if (dragging) return;
384
+ e.preventDefault();
385
+ elDragging.value = type;
386
+ dragging = true;
387
+ document.addEventListener("pointermove", slider.pointermove);
388
+ document.addEventListener("pointerup", slider.pointerup);
389
+ moveHandle(e, elDragging.value);
390
+ },
391
+ pointerleave: (e) => {
392
+ if (dragging) {
393
+ e.preventDefault();
394
+ }
395
+ },
396
+ pointermove: (e) => {
397
+ e.preventDefault();
398
+ moveHandle(e, elDragging.value);
399
+ },
400
+ pointerup: (e) => {
401
+ e.preventDefault();
402
+ dragging = false;
403
+ elDragging.value = "";
404
+ document.removeEventListener("pointermove", slider.pointermove);
405
+ document.removeEventListener("pointerup", slider.pointerup);
406
+ }
407
+ };
408
+ function updateSliders(_) {
409
+ if (alphaSliderEl.value) {
410
+ const color = new Color("hsv", [_.h, _.s, _.v], _.a).to("hsl");
411
+ const hsl0 = color.clone();
412
+ hsl0.alpha = 0;
413
+ const hsl1 = color.clone();
414
+ hsl1.alpha = 1;
415
+ updateSlider(alphaSliderEl.value, [hsl0.toString(), hsl1.toString()]);
416
+ }
417
+ updateSlider(hueSliderEl.value, (i) => `hsl(${i} 100% 50%)`);
418
+ updatePicker(pickerEl.value, _.h);
392
419
  }
393
- const update = (_: HsvaColor, { updatePosition = true, updateValue = true }: { updatePosition?: boolean, updateValue?: boolean } = {}): void => {
394
- if (alphaSliderEl.value) {
395
- const hsl = colord(_)
396
- const hsl0 = hsl.alpha(0).toHslString()
397
- const hsl1 = hsl.alpha(1).toHslString()
398
- updateSlider(alphaSliderEl.value, [hsl0, hsl1])
399
- }
400
- updateSlider(hueSliderEl.value!, i => `hsl(${i} 100% 50%)`)
401
- updatePicker(pickerEl.value!, _.h)
402
- if (updatePosition) {
403
- localColor.percent.h = Math.round((_.h / 360) * 10000) / 100
404
- localColor.percent.s = _.s
405
- localColor.percent.v = 100 - _.v
406
- localColor.percent.a =
407
- props.allowAlpha
408
- ? _.a !== undefined
409
- ? _.a * 100
410
- : 1
411
- : 1
412
- }
413
- if (updateValue) {
414
- localColor.val = { ..._, a: props.allowAlpha ? _.a : 1 }
415
- }
420
+ function updateValueAndPosition(_) {
421
+ localColor.percent.h = Math.round(_.h / 360 * 1e4) / 100;
422
+ localColor.percent.s = _.s;
423
+ localColor.percent.v = 100 - _.v;
424
+ localColor.percent.a = props.allowAlpha ? _.a !== void 0 ? _.a * 100 : 1 : 1;
425
+ localColor.val = { ..._, a: props.allowAlpha ? _.a : 1 };
416
426
  }
417
-
418
- const parseInput = (e: Event): void => {
419
- const val = (e.target as HTMLInputElement)?.value
420
- if (val) {
421
- const color = colord(val)
422
- if (!color.isValid()) return
423
- update(color.toHsv())
424
- }
427
+ function convertAndUpdateAll(rgba) {
428
+ const hsva = safeConvertToHsva(rgba, props.allowAlpha);
429
+ if (!hsva) return;
430
+ updateSliders(hsva);
431
+ updateValueAndPosition(hsva);
425
432
  }
426
-
433
+ function save() {
434
+ const rgba = safeConvertToRgba(localColor.val, props.allowAlpha);
435
+ if (!rgba) return;
436
+ $value.value = rgba;
437
+ $tempValue.value = void 0;
438
+ emits("save", rgba);
439
+ }
440
+ function parseInput(e) {
441
+ const val = e.target?.value;
442
+ const converted = props.customRepresentation?.fromStringToHsva ? props.customRepresentation.fromStringToHsva(val) : safeConvertToHsva(val, props.allowAlpha);
443
+ if (converted) {
444
+ updateSliders(converted);
445
+ updateValueAndPosition(converted);
446
+ }
447
+ }
448
+ let disableUpdateTempValue = false;
427
449
  onMounted(() => {
428
- const color = colord($value.value)
429
- update(color.toHsv())
430
- })
431
- watch(props, () => {
432
- const color = colord($value.value)
433
- update(color.toHsv())
434
- })
435
-
450
+ convertAndUpdateAll($value.value);
451
+ if ($tempValue.value !== void 0) {
452
+ convertAndUpdateAll($tempValue.value);
453
+ }
454
+ const handle = document.querySelector(`#${props.id ?? fallbackId} .color-picker--all-handle`);
455
+ if (handle instanceof HTMLElement) handle.focus();
456
+ });
457
+ watch($value, () => {
458
+ convertAndUpdateAll($value.value);
459
+ });
460
+ watch($tempValue, () => {
461
+ if ($tempValue.value !== void 0) {
462
+ disableUpdateTempValue = true;
463
+ convertAndUpdateAll($tempValue.value);
464
+ setTimeout(() => {
465
+ disableUpdateTempValue = false;
466
+ }, 0);
467
+ }
468
+ });
436
469
  watch(localColor, () => {
437
- update(localColor.val, { updatePosition: false, updateValue: false })
438
- })
439
-
440
- const save = (): void => {
441
- const color = colord(localColor.val).toRgb()
442
- update(localColor.val, { updatePosition: false, updateValue: false })
443
- $value.value = color
444
- emits("save", color)
445
- }
446
-
447
- const invertColors = computed(() => !!(localColor.percent.v < 50 || (localColor.val.a === undefined || localColor.val.a < 0.5)))
470
+ updateSliders(localColor.val);
471
+ localInputString.value = localColorString.value;
472
+ if (disableUpdateTempValue) return;
473
+ const rgba = safeConvertToRgba(localColor.val, props.allowAlpha);
474
+ if (!rgba) return;
475
+ $tempValue.value = rgba;
476
+ });
477
+ const invertColors = computed(() => !!(localColor.percent.v < 50 || (localColor.val.a === void 0 || localColor.val.a < 0.5)));
448
478
  </script>