@10x-media/fields 0.1.0-beta.0 → 0.1.0-beta.10

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 (320) hide show
  1. package/CHANGELOG.md +173 -0
  2. package/README.md +8 -4
  3. package/dist/exports/client.d.ts +10 -1
  4. package/dist/exports/client.js +9 -1
  5. package/dist/exports/color-utils.d.ts +4 -2
  6. package/dist/exports/color-utils.js +3 -1
  7. package/dist/exports/color.d.ts +5 -2
  8. package/dist/exports/color.js +4 -1
  9. package/dist/exports/encrypted.d.ts +7 -4
  10. package/dist/exports/encrypted.js +6 -3
  11. package/dist/exports/icon-adapters/radix.d.ts +2 -2
  12. package/dist/exports/icon-adapters/radix.js +2 -2
  13. package/dist/exports/icon-react.d.ts +2 -2
  14. package/dist/exports/icon.d.ts +6 -2
  15. package/dist/exports/icon.js +6 -2
  16. package/dist/exports/measurement-utils.d.ts +9 -0
  17. package/dist/exports/measurement-utils.js +8 -0
  18. package/dist/exports/measurement.d.ts +11 -0
  19. package/dist/exports/measurement.js +10 -0
  20. package/dist/exports/phone-utils.d.ts +4 -0
  21. package/dist/exports/phone-utils.js +4 -0
  22. package/dist/exports/phone.d.ts +6 -0
  23. package/dist/exports/phone.js +3 -0
  24. package/dist/exports/rsc.d.ts +5 -1
  25. package/dist/exports/rsc.js +5 -1
  26. package/dist/exports/types.d.ts +3 -2
  27. package/dist/fields/color/client/ColorField.d.ts +2 -0
  28. package/dist/fields/color/client/ColorField.js +35 -288
  29. package/dist/fields/color/client/ColorField.js.map +1 -1
  30. package/dist/fields/color/client/ColorInput.d.ts +44 -0
  31. package/dist/fields/color/client/ColorInput.js +374 -0
  32. package/dist/fields/color/client/ColorInput.js.map +1 -0
  33. package/dist/fields/color/client/ColorPickerPanel.d.ts +3 -1
  34. package/dist/fields/color/client/ColorPickerPanel.js +31 -5
  35. package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
  36. package/dist/fields/color/client/colorField.css +30 -0
  37. package/dist/fields/color/colorField.d.ts +9 -2
  38. package/dist/fields/color/colorField.js +68 -15
  39. package/dist/fields/color/colorField.js.map +1 -1
  40. package/dist/fields/color/engine/index.d.ts +2 -1
  41. package/dist/fields/color/engine/scheme.d.ts +13 -0
  42. package/dist/fields/color/engine/scheme.js +12 -0
  43. package/dist/fields/color/engine/scheme.js.map +1 -0
  44. package/dist/fields/color/options.d.ts +5 -4
  45. package/dist/fields/color/options.js.map +1 -1
  46. package/dist/fields/color/paths.d.ts +1 -0
  47. package/dist/fields/color/paths.js +32 -0
  48. package/dist/fields/color/paths.js.map +1 -0
  49. package/dist/fields/color/presetChip.js +10 -9
  50. package/dist/fields/color/presetChip.js.map +1 -1
  51. package/dist/fields/color/presetReference.d.ts +13 -0
  52. package/dist/fields/color/presetReference.js +94 -0
  53. package/dist/fields/color/presetReference.js.map +1 -0
  54. package/dist/fields/color/presetsFromArray.d.ts +30 -0
  55. package/dist/fields/color/presetsFromArray.js +58 -0
  56. package/dist/fields/color/presetsFromArray.js.map +1 -0
  57. package/dist/fields/color/presetsFromDoc.js +1 -23
  58. package/dist/fields/color/presetsFromDoc.js.map +1 -1
  59. package/dist/fields/color/resolvePresets.d.ts +2 -2
  60. package/dist/fields/color/resolvePresets.js +38 -8
  61. package/dist/fields/color/resolvePresets.js.map +1 -1
  62. package/dist/fields/color/schemeValue.js +30 -0
  63. package/dist/fields/color/schemeValue.js.map +1 -0
  64. package/dist/fields/color/server/ColorCell.js +9 -3
  65. package/dist/fields/color/server/ColorCell.js.map +1 -1
  66. package/dist/fields/color/server/colorCell.css +5 -0
  67. package/dist/fields/color/valueIssue.js +23 -0
  68. package/dist/fields/color/valueIssue.js.map +1 -0
  69. package/dist/fields/encrypted/boot.js +2 -1
  70. package/dist/fields/encrypted/boot.js.map +1 -1
  71. package/dist/fields/encrypted/components/EncryptedInput.js +4 -1
  72. package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -1
  73. package/dist/fields/encrypted/components/EncryptedTextarea.js +6 -2
  74. package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -1
  75. package/dist/fields/encrypted/components/ProtectedCell.d.ts +15 -6
  76. package/dist/fields/encrypted/components/ProtectedCell.js +37 -8
  77. package/dist/fields/encrypted/components/ProtectedCell.js.map +1 -1
  78. package/dist/fields/encrypted/components/ProtectedField.css +134 -39
  79. package/dist/fields/encrypted/components/ProtectedField.d.ts +3 -0
  80. package/dist/fields/encrypted/components/ProtectedField.js +14 -0
  81. package/dist/fields/encrypted/components/ProtectedField.js.map +1 -1
  82. package/dist/fields/encrypted/components/WriteOnlyActions.js +65 -0
  83. package/dist/fields/encrypted/components/WriteOnlyActions.js.map +1 -0
  84. package/dist/fields/encrypted/components/WriteOnlyField.js +286 -0
  85. package/dist/fields/encrypted/components/WriteOnlyField.js.map +1 -0
  86. package/dist/fields/encrypted/components/writeOnlyIntent.js +69 -0
  87. package/dist/fields/encrypted/components/writeOnlyIntent.js.map +1 -0
  88. package/dist/fields/encrypted/crypto/wire.d.ts +10 -1
  89. package/dist/fields/encrypted/crypto/wire.js +1 -1
  90. package/dist/fields/encrypted/encryptedField.js +63 -6
  91. package/dist/fields/encrypted/encryptedField.js.map +1 -1
  92. package/dist/fields/encrypted/generateSecret.d.ts +10 -0
  93. package/dist/fields/encrypted/generateSecret.js +41 -0
  94. package/dist/fields/encrypted/generateSecret.js.map +1 -0
  95. package/dist/fields/encrypted/hint.js +67 -0
  96. package/dist/fields/encrypted/hint.js.map +1 -0
  97. package/dist/fields/encrypted/hooks.js +59 -31
  98. package/dist/fields/encrypted/hooks.js.map +1 -1
  99. package/dist/fields/encrypted/queryRewrite.d.ts +10 -2
  100. package/dist/fields/encrypted/queryRewrite.js +34 -8
  101. package/dist/fields/encrypted/queryRewrite.js.map +1 -1
  102. package/dist/fields/encrypted/rawRead.d.ts +24 -0
  103. package/dist/fields/encrypted/rawRead.js +40 -0
  104. package/dist/fields/encrypted/rawRead.js.map +1 -0
  105. package/dist/fields/encrypted/scan.js +21 -4
  106. package/dist/fields/encrypted/scan.js.map +1 -1
  107. package/dist/fields/encrypted/types.d.ts +67 -2
  108. package/dist/fields/encrypted/types.js +8 -1
  109. package/dist/fields/encrypted/types.js.map +1 -1
  110. package/dist/fields/encrypted/utils/decryptAllData.js +2 -2
  111. package/dist/fields/encrypted/utils/decryptAllData.js.map +1 -1
  112. package/dist/fields/encrypted/utils/decryptFieldValue.d.ts +30 -0
  113. package/dist/fields/encrypted/utils/decryptFieldValue.js +56 -0
  114. package/dist/fields/encrypted/utils/decryptFieldValue.js.map +1 -0
  115. package/dist/fields/encrypted/utils/readEncryptedField.d.ts +51 -0
  116. package/dist/fields/encrypted/utils/readEncryptedField.js +96 -0
  117. package/dist/fields/encrypted/utils/readEncryptedField.js.map +1 -0
  118. package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -1
  119. package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -1
  120. package/dist/fields/icon/adapters/radix/adapter.js +7 -0
  121. package/dist/fields/icon/adapters/radix/adapter.js.map +1 -1
  122. package/dist/fields/icon/adapters/radix/client.d.ts +3 -2
  123. package/dist/fields/icon/adapters/radix/client.js +3 -2
  124. package/dist/fields/icon/adapters/radix/client.js.map +1 -1
  125. package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -1
  126. package/dist/fields/icon/adapters/radix/generated/nodes.js +3625 -0
  127. package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -0
  128. package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -1
  129. package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
  130. package/dist/fields/icon/client/DrawerGlyph.js +34 -17
  131. package/dist/fields/icon/client/DrawerGlyph.js.map +1 -1
  132. package/dist/fields/icon/client/IconDrawerContent.js +9 -45
  133. package/dist/fields/icon/client/IconDrawerContent.js.map +1 -1
  134. package/dist/fields/icon/client/IconFieldClient.d.ts +7 -0
  135. package/dist/fields/icon/client/IconFieldClient.js +15 -7
  136. package/dist/fields/icon/client/IconFieldClient.js.map +1 -1
  137. package/dist/fields/icon/client/IconGridCell.js +67 -0
  138. package/dist/fields/icon/client/IconGridCell.js.map +1 -0
  139. package/dist/fields/icon/client/icon-field.css +12 -2
  140. package/dist/fields/icon/codegen/emit.js +5 -4
  141. package/dist/fields/icon/codegen/emit.js.map +1 -1
  142. package/dist/fields/icon/codegen/generate.js +32 -6
  143. package/dist/fields/icon/codegen/generate.js.map +1 -1
  144. package/dist/fields/icon/layers/coalesce.js +41 -0
  145. package/dist/fields/icon/layers/coalesce.js.map +1 -0
  146. package/dist/fields/icon/layers/manifestCache.d.ts +6 -0
  147. package/dist/fields/icon/layers/manifestCache.js +49 -0
  148. package/dist/fields/icon/layers/manifestCache.js.map +1 -0
  149. package/dist/fields/icon/layers/resolve.d.ts +20 -0
  150. package/dist/fields/icon/layers/resolve.js +63 -0
  151. package/dist/fields/icon/layers/resolve.js.map +1 -0
  152. package/dist/fields/icon/layers/upload.d.ts +52 -0
  153. package/dist/fields/icon/layers/upload.js +116 -0
  154. package/dist/fields/icon/layers/upload.js.map +1 -0
  155. package/dist/fields/icon/plugin.js +24 -0
  156. package/dist/fields/icon/plugin.js.map +1 -1
  157. package/dist/fields/icon/react/createIcon.d.ts +5 -0
  158. package/dist/fields/icon/react/createIcon.js +22 -4
  159. package/dist/fields/icon/react/createIcon.js.map +1 -1
  160. package/dist/fields/icon/react/createRscIcon.js +22 -1
  161. package/dist/fields/icon/react/createRscIcon.js.map +1 -1
  162. package/dist/fields/icon/react/resolveRendered.js +21 -0
  163. package/dist/fields/icon/react/resolveRendered.js.map +1 -0
  164. package/dist/fields/icon/react/types.d.ts +15 -1
  165. package/dist/fields/icon/rsc/IconCell.d.ts +2 -2
  166. package/dist/fields/icon/rsc/IconCell.js +12 -5
  167. package/dist/fields/icon/rsc/IconCell.js.map +1 -1
  168. package/dist/fields/icon/rsc/IconFieldServer.js +16 -2
  169. package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -1
  170. package/dist/fields/icon/rsc/IconLibrarySelectServer.js +1 -1
  171. package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -1
  172. package/dist/fields/icon/server/endpoint.d.ts +12 -0
  173. package/dist/fields/icon/server/endpoint.js +52 -0
  174. package/dist/fields/icon/server/endpoint.js.map +1 -0
  175. package/dist/fields/icon/server/manifestCache.js +9 -4
  176. package/dist/fields/icon/server/manifestCache.js.map +1 -1
  177. package/dist/fields/icon/server/resolveIconMeta.js +31 -0
  178. package/dist/fields/icon/server/resolveIconMeta.js.map +1 -0
  179. package/dist/fields/icon/server/validate.js +5 -2
  180. package/dist/fields/icon/server/validate.js.map +1 -1
  181. package/dist/fields/icon/shared/adapterComponents.d.ts +3 -2
  182. package/dist/fields/icon/shared/iconLabel.js +26 -0
  183. package/dist/fields/icon/shared/iconLabel.js.map +1 -0
  184. package/dist/fields/measurement/client/MeasurementCell.d.ts +18 -0
  185. package/dist/fields/measurement/client/MeasurementCell.js +47 -0
  186. package/dist/fields/measurement/client/MeasurementCell.js.map +1 -0
  187. package/dist/fields/measurement/client/MeasurementField.d.ts +13 -0
  188. package/dist/fields/measurement/client/MeasurementField.js +70 -0
  189. package/dist/fields/measurement/client/MeasurementField.js.map +1 -0
  190. package/dist/fields/measurement/client/MeasurementInput.d.ts +42 -0
  191. package/dist/fields/measurement/client/MeasurementInput.js +327 -0
  192. package/dist/fields/measurement/client/MeasurementInput.js.map +1 -0
  193. package/dist/fields/measurement/client/MeasurementUnitsProvider.d.ts +24 -0
  194. package/dist/fields/measurement/client/MeasurementUnitsProvider.js +61 -0
  195. package/dist/fields/measurement/client/MeasurementUnitsProvider.js.map +1 -0
  196. package/dist/fields/measurement/client/editModel.js +124 -0
  197. package/dist/fields/measurement/client/editModel.js.map +1 -0
  198. package/dist/fields/measurement/client/measurementCell.css +4 -0
  199. package/dist/fields/measurement/client/measurementField.css +215 -0
  200. package/dist/fields/measurement/client/useMeasurementModel.d.ts +19 -0
  201. package/dist/fields/measurement/client/useMeasurementModel.js +85 -0
  202. package/dist/fields/measurement/client/useMeasurementModel.js.map +1 -0
  203. package/dist/fields/measurement/engine/convert.d.ts +8 -0
  204. package/dist/fields/measurement/engine/convert.js +21 -0
  205. package/dist/fields/measurement/engine/convert.js.map +1 -0
  206. package/dist/fields/measurement/engine/format.d.ts +37 -0
  207. package/dist/fields/measurement/engine/format.js +156 -0
  208. package/dist/fields/measurement/engine/format.js.map +1 -0
  209. package/dist/fields/measurement/engine/locale.d.ts +25 -0
  210. package/dist/fields/measurement/engine/locale.js +79 -0
  211. package/dist/fields/measurement/engine/locale.js.map +1 -0
  212. package/dist/fields/measurement/engine/precision.d.ts +34 -0
  213. package/dist/fields/measurement/engine/precision.js +63 -0
  214. package/dist/fields/measurement/engine/precision.js.map +1 -0
  215. package/dist/fields/measurement/engine/registry.d.ts +55 -0
  216. package/dist/fields/measurement/engine/registry.js +117 -0
  217. package/dist/fields/measurement/engine/registry.js.map +1 -0
  218. package/dist/fields/measurement/engine/units.d.ts +178 -0
  219. package/dist/fields/measurement/engine/units.js +198 -0
  220. package/dist/fields/measurement/engine/units.js.map +1 -0
  221. package/dist/fields/measurement/measurementField.d.ts +17 -0
  222. package/dist/fields/measurement/measurementField.js +139 -0
  223. package/dist/fields/measurement/measurementField.js.map +1 -0
  224. package/dist/fields/measurement/options.d.ts +76 -0
  225. package/dist/fields/measurement/options.js +9 -0
  226. package/dist/fields/measurement/options.js.map +1 -0
  227. package/dist/fields/measurement/presets.d.ts +117 -0
  228. package/dist/fields/measurement/presets.js +136 -0
  229. package/dist/fields/measurement/presets.js.map +1 -0
  230. package/dist/fields/measurement/server/MeasurementCellServer.d.ts +21 -0
  231. package/dist/fields/measurement/server/MeasurementCellServer.js +53 -0
  232. package/dist/fields/measurement/server/MeasurementCellServer.js.map +1 -0
  233. package/dist/fields/measurement/server/MeasurementFieldServer.d.ts +16 -0
  234. package/dist/fields/measurement/server/MeasurementFieldServer.js +45 -0
  235. package/dist/fields/measurement/server/MeasurementFieldServer.js.map +1 -0
  236. package/dist/fields/measurement/server/getUserUnits.js +39 -0
  237. package/dist/fields/measurement/server/getUserUnits.js.map +1 -0
  238. package/dist/fields/measurement/server/resolvePrecisionSafe.js +24 -0
  239. package/dist/fields/measurement/server/resolvePrecisionSafe.js.map +1 -0
  240. package/dist/fields/measurement/server/resolveRegistryDefault.js +26 -0
  241. package/dist/fields/measurement/server/resolveRegistryDefault.js.map +1 -0
  242. package/dist/fields/phoneNumber/client/CountryFlag.d.ts +16 -0
  243. package/dist/fields/phoneNumber/client/CountryFlag.js +40 -0
  244. package/dist/fields/phoneNumber/client/CountryFlag.js.map +1 -0
  245. package/dist/fields/phoneNumber/client/CountryPicker.d.ts +21 -0
  246. package/dist/fields/phoneNumber/client/CountryPicker.js +255 -0
  247. package/dist/fields/phoneNumber/client/CountryPicker.js.map +1 -0
  248. package/dist/fields/phoneNumber/client/PhoneNumberField.d.ts +26 -0
  249. package/dist/fields/phoneNumber/client/PhoneNumberField.js +318 -0
  250. package/dist/fields/phoneNumber/client/PhoneNumberField.js.map +1 -0
  251. package/dist/fields/phoneNumber/client/editModel.js +86 -0
  252. package/dist/fields/phoneNumber/client/editModel.js.map +1 -0
  253. package/dist/fields/phoneNumber/client/phoneNumberField.css +305 -0
  254. package/dist/fields/phoneNumber/engine/countries.d.ts +36 -0
  255. package/dist/fields/phoneNumber/engine/countries.js +68 -0
  256. package/dist/fields/phoneNumber/engine/countries.js.map +1 -0
  257. package/dist/fields/phoneNumber/engine/draft.d.ts +13 -0
  258. package/dist/fields/phoneNumber/engine/draft.js +72 -0
  259. package/dist/fields/phoneNumber/engine/draft.js.map +1 -0
  260. package/dist/fields/phoneNumber/engine/metadata.d.ts +11 -0
  261. package/dist/fields/phoneNumber/engine/metadata.js +32 -0
  262. package/dist/fields/phoneNumber/engine/metadata.js.map +1 -0
  263. package/dist/fields/phoneNumber/engine/phone.d.ts +37 -0
  264. package/dist/fields/phoneNumber/engine/phone.js +59 -0
  265. package/dist/fields/phoneNumber/engine/phone.js.map +1 -0
  266. package/dist/fields/phoneNumber/options.d.ts +72 -0
  267. package/dist/fields/phoneNumber/options.js +37 -0
  268. package/dist/fields/phoneNumber/options.js.map +1 -0
  269. package/dist/fields/phoneNumber/phoneNumberField.d.ts +14 -0
  270. package/dist/fields/phoneNumber/phoneNumberField.js +167 -0
  271. package/dist/fields/phoneNumber/phoneNumberField.js.map +1 -0
  272. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.d.ts +19 -0
  273. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js +73 -0
  274. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js.map +1 -0
  275. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.d.ts +16 -0
  276. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js +57 -0
  277. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js.map +1 -0
  278. package/dist/fields/phoneNumber/server/flagsEndpoint.js +51 -0
  279. package/dist/fields/phoneNumber/server/flagsEndpoint.js.map +1 -0
  280. package/dist/fields/phoneNumber/server/readPhoneOptions.js +18 -0
  281. package/dist/fields/phoneNumber/server/readPhoneOptions.js.map +1 -0
  282. package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js +33 -0
  283. package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js.map +1 -0
  284. package/dist/index.d.ts +5 -3
  285. package/dist/index.js +35 -1
  286. package/dist/index.js.map +1 -1
  287. package/dist/translations/ar.js +62 -0
  288. package/dist/translations/ar.js.map +1 -0
  289. package/dist/translations/de.js +19 -1
  290. package/dist/translations/de.js.map +1 -1
  291. package/dist/translations/en.js +19 -1
  292. package/dist/translations/en.js.map +1 -1
  293. package/dist/translations/es.js +62 -0
  294. package/dist/translations/es.js.map +1 -0
  295. package/dist/translations/fr.js +62 -0
  296. package/dist/translations/fr.js.map +1 -0
  297. package/dist/translations/id.js +62 -0
  298. package/dist/translations/id.js.map +1 -0
  299. package/dist/translations/index.d.ts +10 -1
  300. package/dist/translations/index.js +19 -1
  301. package/dist/translations/index.js.map +1 -1
  302. package/dist/translations/keys.d.ts +19 -1
  303. package/dist/translations/keys.js +20 -2
  304. package/dist/translations/keys.js.map +1 -1
  305. package/dist/translations/ko.js +62 -0
  306. package/dist/translations/ko.js.map +1 -0
  307. package/dist/translations/pt.js +62 -0
  308. package/dist/translations/pt.js.map +1 -0
  309. package/dist/translations/ru.js +62 -0
  310. package/dist/translations/ru.js.map +1 -0
  311. package/dist/translations/uk.js +62 -0
  312. package/dist/translations/uk.js.map +1 -0
  313. package/dist/translations/zh.js +62 -0
  314. package/dist/translations/zh.js.map +1 -0
  315. package/dist/types.d.ts +165 -8
  316. package/dist/utils/resolveStaticLabel.js +13 -0
  317. package/dist/utils/resolveStaticLabel.js.map +1 -0
  318. package/package.json +31 -7
  319. package/dist/fields/icon/rsc/resolveStaticLabel.js +0 -16
  320. package/dist/fields/icon/rsc/resolveStaticLabel.js.map +0 -1
@@ -0,0 +1,374 @@
1
+ "use client";
2
+ import { keys } from "../../../translations/keys.js";
3
+ import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
4
+ import { rgbToHsv, toRgb } from "../engine/convert.js";
5
+ import { parseColor } from "../engine/parse.js";
6
+ import { formatColor } from "../engine/format.js";
7
+ import { salvageColor } from "../engine/salvage.js";
8
+ import { isColorSchemeValue } from "../engine/scheme.js";
9
+ import { PRESET_PREFIX } from "../options.js";
10
+ import { applyReferenceAlpha, formatPresetReference, parsePresetReference, presetReferenceParts } from "../presetReference.js";
11
+ import { colorValueIssue } from "../valueIssue.js";
12
+ import { resolveCommitValue } from "../commitValue.js";
13
+ import { derivePresetChip } from "../presetChip.js";
14
+ import { flatValue, swatchBackground } from "../schemeValue.js";
15
+ import { ColorPickerPanel } from "./ColorPickerPanel.js";
16
+ import { FieldDescription, FieldError, FieldLabel, Popup, RenderCustomComponent, XIcon, fieldBaseClass } from "@payloadcms/ui";
17
+ import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
18
+ import { jsx, jsxs } from "react/jsx-runtime";
19
+ import "./colorField.css";
20
+ //#region src/fields/color/client/ColorInput.tsx
21
+ const baseClass = "fields-color";
22
+ const DEFAULT_OPTIONS = {
23
+ alpha: true,
24
+ enableEyedropper: true,
25
+ format: "hex",
26
+ isClearable: true,
27
+ linked: false,
28
+ linkedFallback: null
29
+ };
30
+ const NO_PRESETS = [];
31
+ /**
32
+ * The color field's row, picker, preset chip and commit pipeline with no form behind
33
+ * it, for custom admin views and components. `ColorField` is this plus `useField`.
34
+ */
35
+ const ColorInput = (props) => {
36
+ const { AfterInput, BeforeInput, className, Description, description, Error: ErrorComponent, error, Label, label, localized, onChange, options, path, placeholder, presets: resolvedPresets = NO_PRESETS, presetsLabel, readOnly, required, showError: showErrorFromProps, style, value } = props;
37
+ const { alpha, enableEyedropper, format, isClearable, linked, linkedFallback } = {
38
+ ...DEFAULT_OPTIONS,
39
+ ...options
40
+ };
41
+ const { t } = useTranslation$1();
42
+ const isReadOnly = Boolean(readOnly);
43
+ const stringValue = typeof value === "string" ? value : "";
44
+ const ownIssue = showErrorFromProps === void 0 && error === void 0 ? colorValueIssue(stringValue, {
45
+ linked,
46
+ presets: resolvedPresets
47
+ }) : null;
48
+ const errorMessage = error ?? (ownIssue ? t(keys[ownIssue]) : void 0);
49
+ const showError = showErrorFromProps ?? errorMessage !== void 0;
50
+ const reference = linked ? parsePresetReference(stringValue) : null;
51
+ const presetKey = reference?.key ?? null;
52
+ const referenceAlpha = alpha ? reference?.alpha ?? 100 : 100;
53
+ const activePreset = presetKey !== null ? resolvedPresets.find((preset) => preset.key === presetKey) : void 0;
54
+ const presetMissing = presetKey !== null && !activePreset;
55
+ const rawValue = presetKey !== null ? activePreset?.value ?? linkedFallback : stringValue || null;
56
+ const cssValue = flatValue(rawValue);
57
+ const parsed = useMemo(() => cssValue ? parseColor(cssValue) : null, [cssValue]);
58
+ const [displayFormat, setDisplayFormat] = useState(format);
59
+ const displayValue = useMemo(() => {
60
+ if (presetKey !== null || !parsed || displayFormat === format) return stringValue;
61
+ return formatColor(parsed, displayFormat, { alpha });
62
+ }, [
63
+ alpha,
64
+ displayFormat,
65
+ format,
66
+ parsed,
67
+ presetKey,
68
+ stringValue
69
+ ]);
70
+ const [draft, setDraft] = useState(displayValue);
71
+ const editingRef = useRef(false);
72
+ useEffect(() => {
73
+ if (!editingRef.current) setDraft(displayValue);
74
+ }, [displayValue]);
75
+ const [chipDismissed, setChipDismissed] = useState(false);
76
+ const chip = useMemo(() => derivePresetChip({
77
+ editing: chipDismissed,
78
+ linked,
79
+ presets: resolvedPresets,
80
+ value: stringValue
81
+ }), [
82
+ chipDismissed,
83
+ linked,
84
+ resolvedPresets,
85
+ stringValue
86
+ ]);
87
+ const debounceRef = useRef(null);
88
+ useEffect(() => () => {
89
+ if (debounceRef.current) clearTimeout(debounceRef.current);
90
+ }, []);
91
+ const onChangeRef = useRef(onChange);
92
+ onChangeRef.current = onChange;
93
+ const setValue = useCallback((next) => onChangeRef.current(next), []);
94
+ const lastValidRef = useRef(null);
95
+ useEffect(() => {
96
+ if (stringValue === "") return;
97
+ if (presetKey ? true : parseColor(stringValue) !== null) lastValidRef.current = stringValue;
98
+ }, [presetKey, stringValue]);
99
+ const commitText = useCallback((raw) => {
100
+ let normalized = null;
101
+ if (linked && raw.startsWith("preset:")) {
102
+ const parts = presetReferenceParts(raw);
103
+ if (parts) normalized = formatPresetReference(parts.key, alpha ? parts.alpha : 100);
104
+ else if (raw.length > 7) normalized = raw;
105
+ } else {
106
+ const parsedRaw = parseColor(raw);
107
+ if (parsedRaw) normalized = formatColor(parsedRaw, format, { alpha });
108
+ }
109
+ const resolution = resolveCommitValue({
110
+ draft: raw,
111
+ isClearable,
112
+ lastValid: lastValidRef.current,
113
+ parsed: normalized
114
+ });
115
+ lastValidRef.current = resolution.lastValid;
116
+ setValue(resolution.value);
117
+ return resolution.reverted;
118
+ }, [
119
+ alpha,
120
+ format,
121
+ isClearable,
122
+ linked,
123
+ setValue
124
+ ]);
125
+ const onTextChange = useCallback((event) => {
126
+ const raw = event.target.value;
127
+ editingRef.current = true;
128
+ setChipDismissed(true);
129
+ setDraft(raw);
130
+ if (debounceRef.current) clearTimeout(debounceRef.current);
131
+ debounceRef.current = setTimeout(() => commitText(raw), 250);
132
+ }, [commitText]);
133
+ const onTextBlur = useCallback(() => {
134
+ if (debounceRef.current) {
135
+ clearTimeout(debounceRef.current);
136
+ debounceRef.current = null;
137
+ }
138
+ if (editingRef.current) {
139
+ editingRef.current = false;
140
+ const salvaged = !(linked && draft.startsWith("preset:")) && draft.trim() !== "" && !parseColor(draft) ? salvageColor(draft) : null;
141
+ if (commitText(salvaged ?? draft)) setDraft(displayValue);
142
+ else if (salvaged !== null) {
143
+ const parsedSalvaged = parseColor(salvaged);
144
+ setDraft(parsedSalvaged ? formatColor(parsedSalvaged, displayFormat, { alpha }) : salvaged);
145
+ }
146
+ }
147
+ setChipDismissed(false);
148
+ }, [
149
+ alpha,
150
+ commitText,
151
+ displayFormat,
152
+ displayValue,
153
+ draft,
154
+ linked
155
+ ]);
156
+ const onTextKeyDown = useCallback((event) => {
157
+ if (!chip || isReadOnly) return;
158
+ if (event.key === "Backspace" || event.key === "Delete") {
159
+ event.preventDefault();
160
+ setDraft("");
161
+ if (isClearable) setValue(null);
162
+ else {
163
+ editingRef.current = true;
164
+ setChipDismissed(true);
165
+ }
166
+ }
167
+ }, [
168
+ chip,
169
+ isClearable,
170
+ isReadOnly,
171
+ setValue
172
+ ]);
173
+ const commitCss = useCallback((css) => {
174
+ const parsedCss = parseColor(css);
175
+ if (parsedCss) setValue(formatColor(parsedCss, format, { alpha }));
176
+ }, [
177
+ alpha,
178
+ format,
179
+ setValue
180
+ ]);
181
+ const initialHsva = useMemo(() => {
182
+ if (!parsed) return null;
183
+ const rgb = toRgb(parsed);
184
+ const hsv = rgbToHsv(rgb);
185
+ return {
186
+ a: presetKey !== null ? referenceAlpha / 100 : rgb.alpha,
187
+ h: hsv.h,
188
+ s: hsv.s,
189
+ v: hsv.v
190
+ };
191
+ }, [
192
+ parsed,
193
+ presetKey,
194
+ referenceAlpha
195
+ ]);
196
+ const commitReferenceAlpha = useCallback((alpha100) => {
197
+ if (presetKey === null) return;
198
+ setValue(formatPresetReference(presetKey, alpha100));
199
+ }, [presetKey, setValue]);
200
+ const contentRef = useRef(null);
201
+ const [contentClipped, setContentClipped] = useState(false);
202
+ const measureClip = useCallback(() => {
203
+ const el = contentRef.current;
204
+ if (el) setContentClipped(el.scrollWidth > el.clientWidth + 1);
205
+ }, []);
206
+ useEffect(measureClip);
207
+ useEffect(() => {
208
+ const el = contentRef.current;
209
+ if (!el) return;
210
+ const observer = new ResizeObserver(measureClip);
211
+ observer.observe(el);
212
+ return () => observer.disconnect();
213
+ }, [measureClip]);
214
+ const generatedId = useId();
215
+ const inputId = path ? `field-${path.replace(/\./g, "__")}` : generatedId;
216
+ const swatchCss = swatchBackground(referenceAlpha !== 100 && (typeof rawValue === "string" || isColorSchemeValue(rawValue)) ? applyReferenceAlpha(rawValue, referenceAlpha, "rgb") : rawValue);
217
+ const swatch = /* @__PURE__ */ jsxs("span", {
218
+ className: `${baseClass}__swatch ${baseClass}__checker`,
219
+ children: [
220
+ swatchCss ? /* @__PURE__ */ jsx("span", {
221
+ className: `${baseClass}__swatch-color`,
222
+ style: { background: swatchCss }
223
+ }) : null,
224
+ presetMissing && !swatchCss ? /* @__PURE__ */ jsx("span", {
225
+ className: `${baseClass}__swatch-color`,
226
+ "data-missing": "true"
227
+ }) : null,
228
+ isReadOnly ? null : /* @__PURE__ */ jsx("span", {
229
+ className: `${baseClass}__sr-only`,
230
+ children: t(keys.pickColor)
231
+ })
232
+ ]
233
+ });
234
+ return /* @__PURE__ */ jsxs("div", {
235
+ className: [
236
+ fieldBaseClass,
237
+ baseClass,
238
+ className,
239
+ showError && "error",
240
+ isReadOnly && "read-only"
241
+ ].filter(Boolean).join(" "),
242
+ style,
243
+ children: [/* @__PURE__ */ jsx(RenderCustomComponent, {
244
+ CustomComponent: Label,
245
+ Fallback: /* @__PURE__ */ jsx(FieldLabel, {
246
+ htmlFor: path ? void 0 : inputId,
247
+ label,
248
+ localized,
249
+ path,
250
+ required
251
+ })
252
+ }), /* @__PURE__ */ jsxs("div", {
253
+ className: `${fieldBaseClass}__wrap`,
254
+ children: [
255
+ /* @__PURE__ */ jsx(RenderCustomComponent, {
256
+ CustomComponent: ErrorComponent,
257
+ Fallback: /* @__PURE__ */ jsx(FieldError, {
258
+ message: errorMessage,
259
+ path,
260
+ showError
261
+ })
262
+ }),
263
+ BeforeInput,
264
+ /* @__PURE__ */ jsxs("div", {
265
+ className: `${baseClass}__container`,
266
+ children: [
267
+ isReadOnly ? /* @__PURE__ */ jsx("span", {
268
+ className: `${baseClass}__swatch-button ${baseClass}__swatch-button--static`,
269
+ children: swatch
270
+ }) : /* @__PURE__ */ jsx(Popup, {
271
+ button: swatch,
272
+ buttonClassName: `${baseClass}__swatch-button`,
273
+ buttonType: "custom",
274
+ caret: false,
275
+ className: `${baseClass}__popup`,
276
+ horizontalAlign: "left",
277
+ render: ({ close }) => /* @__PURE__ */ jsx(ColorPickerPanel, {
278
+ activeReference: reference,
279
+ alphaEnabled: alpha,
280
+ close,
281
+ displayFormat,
282
+ enableEyedropper,
283
+ initial: initialHsva,
284
+ onPickAlpha: commitReferenceAlpha,
285
+ onPickCss: commitCss,
286
+ onPickPreset: (preset) => {
287
+ if (linked) setValue(`${PRESET_PREFIX}${preset.key}`);
288
+ else {
289
+ const flat = flatValue(preset.value);
290
+ if (flat) commitCss(flat);
291
+ }
292
+ },
293
+ presetMissing,
294
+ presets: resolvedPresets,
295
+ presetsLabel: presetsLabel ?? t(keys.presets),
296
+ setDisplayFormat
297
+ }),
298
+ size: "fit-content",
299
+ verticalAlign: "bottom"
300
+ }),
301
+ /* @__PURE__ */ jsxs("div", {
302
+ className: [`${baseClass}__content`, contentClipped && `${baseClass}__content--fade`].filter(Boolean).join(" "),
303
+ ref: contentRef,
304
+ children: [
305
+ chip ? /* @__PURE__ */ jsxs("span", {
306
+ className: `${baseClass}__chip`,
307
+ children: [
308
+ /* @__PURE__ */ jsxs("span", {
309
+ className: `${baseClass}__chip-swatch ${baseClass}__checker`,
310
+ children: [swatchCss ? /* @__PURE__ */ jsx("span", {
311
+ className: `${baseClass}__chip-color`,
312
+ style: { background: swatchCss }
313
+ }) : null, chip.missing && !swatchCss ? /* @__PURE__ */ jsx("span", {
314
+ className: `${baseClass}__chip-color`,
315
+ "data-missing": "true"
316
+ }) : null]
317
+ }),
318
+ /* @__PURE__ */ jsx("span", {
319
+ className: `${baseClass}__chip-label`,
320
+ children: chip.label
321
+ }),
322
+ alpha && chip.alpha !== 100 ? /* @__PURE__ */ jsxs("span", {
323
+ className: `${baseClass}__chip-alpha`,
324
+ children: [chip.alpha, "%"]
325
+ }) : null
326
+ ]
327
+ }) : null,
328
+ /* @__PURE__ */ jsx("input", {
329
+ className: `${baseClass}__input`,
330
+ id: inputId,
331
+ name: path,
332
+ onBlur: onTextBlur,
333
+ onChange: onTextChange,
334
+ onKeyDown: onTextKeyDown,
335
+ placeholder: chip ? void 0 : placeholder,
336
+ readOnly: isReadOnly,
337
+ type: "text",
338
+ value: chip ? "" : draft
339
+ }),
340
+ /* @__PURE__ */ jsx("span", {
341
+ "aria-hidden": "true",
342
+ className: `${baseClass}__badge`,
343
+ children: chip ? t(keys.preset) : displayFormat
344
+ })
345
+ ]
346
+ }),
347
+ isClearable && !required && !isReadOnly && stringValue !== "" ? /* @__PURE__ */ jsx("button", {
348
+ "aria-label": t(keys.clearColor),
349
+ className: `${baseClass}__clear`,
350
+ onClick: () => {
351
+ setDraft("");
352
+ setValue(null);
353
+ },
354
+ type: "button",
355
+ children: /* @__PURE__ */ jsx(XIcon, {})
356
+ }) : null
357
+ ]
358
+ }),
359
+ AfterInput,
360
+ /* @__PURE__ */ jsx(RenderCustomComponent, {
361
+ CustomComponent: Description,
362
+ Fallback: /* @__PURE__ */ jsx(FieldDescription, {
363
+ description,
364
+ path: path ?? ""
365
+ })
366
+ })
367
+ ]
368
+ })]
369
+ });
370
+ };
371
+ //#endregion
372
+ export { ColorInput };
373
+
374
+ //# sourceMappingURL=ColorInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColorInput.js","names":["useTranslation"],"sources":["../../../../src/fields/color/client/ColorInput.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tPopup,\n\tRenderCustomComponent,\n\tXIcon,\n} from '@payloadcms/ui'\nimport type { StaticDescription, StaticLabel } from 'payload'\nimport type React from 'react'\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { ColorFormat } from '../../../types'\nimport { resolveCommitValue } from '../commitValue'\nimport {\n\tformatColor,\n\tisColorSchemeValue,\n\tparseColor,\n\trgbToHsv,\n\tsalvageColor,\n\ttoRgb,\n} from '../engine'\nimport { type ColorFieldClientOptions, PRESET_PREFIX, type ResolvedColorPreset } from '../options'\nimport { derivePresetChip } from '../presetChip'\nimport {\n\tapplyReferenceAlpha,\n\tformatPresetReference,\n\tparsePresetReference,\n\tpresetReferenceParts,\n} from '../presetReference'\nimport { flatValue, swatchBackground } from '../schemeValue'\nimport { colorValueIssue } from '../valueIssue'\nimport { ColorPickerPanel, type Hsva } from './ColorPickerPanel'\nimport './colorField.css'\n\nconst baseClass = 'fields-color'\n\nconst DEFAULT_OPTIONS: ColorFieldClientOptions = {\n\talpha: true,\n\tenableEyedropper: true,\n\tformat: 'hex',\n\tisClearable: true,\n\tlinked: false,\n\tlinkedFallback: null,\n}\n\nconst NO_PRESETS: ResolvedColorPreset[] = []\n\n/**\n * Props for the form-free color input. `value` and `onChange` carry the stored string\n * exactly as `colorField` would persist it: normalized to `options.format` on commit,\n * or a `preset:<key>` reference when `options.linked` is on.\n */\nexport type ColorInputProps = {\n\tvalue: null | string | undefined\n\t/** Fires at commit boundaries (debounced typing, blur, picker, preset, clear), never per keystroke. */\n\tonChange: (value: null | string) => void\n\t/** Any option left out takes `colorField`'s default (hex, alpha on, clearable, eyedropper, unlinked). */\n\toptions?: Partial<ColorFieldClientOptions>\n\t/** Already resolved presets; labels are plain strings in the viewer's language. */\n\tpresets?: ResolvedColorPreset[]\n\tpresetsLabel?: string\n\t/** Names the input (`id`, `name`, label `htmlFor`), as on a native field. */\n\tpath?: string\n\tlabel?: StaticLabel\n\tdescription?: StaticDescription\n\tplaceholder?: string\n\trequired?: boolean\n\tlocalized?: boolean\n\treadOnly?: boolean\n\t/**\n\t * Message shown in the error tooltip. Left unset, the input reports its own\n\t * malformed-color and missing-preset errors.\n\t */\n\terror?: string\n\t/** Forces the error state on or off. Left unset, it follows `error` and the input's own check. */\n\tshowError?: boolean\n\tclassName?: string\n\tstyle?: React.CSSProperties\n\tLabel?: React.ReactNode\n\tError?: React.ReactNode\n\tDescription?: React.ReactNode\n\tBeforeInput?: React.ReactNode\n\tAfterInput?: React.ReactNode\n}\n\n/**\n * The color field's row, picker, preset chip and commit pipeline with no form behind\n * it, for custom admin views and components. `ColorField` is this plus `useField`.\n */\nexport const ColorInput: React.FC<ColorInputProps> = (props) => {\n\tconst {\n\t\tAfterInput,\n\t\tBeforeInput,\n\t\tclassName,\n\t\tDescription,\n\t\tdescription,\n\t\tError: ErrorComponent,\n\t\terror,\n\t\tLabel,\n\t\tlabel,\n\t\tlocalized,\n\t\tonChange,\n\t\toptions,\n\t\tpath,\n\t\tplaceholder,\n\t\tpresets: resolvedPresets = NO_PRESETS,\n\t\tpresetsLabel,\n\t\treadOnly,\n\t\trequired,\n\t\tshowError: showErrorFromProps,\n\t\tstyle,\n\t\tvalue,\n\t} = props\n\tconst { alpha, enableEyedropper, format, isClearable, linked, linkedFallback } = {\n\t\t...DEFAULT_OPTIONS,\n\t\t...options,\n\t}\n\tconst { t } = useTranslation()\n\tconst isReadOnly = Boolean(readOnly)\n\n\tconst stringValue = typeof value === 'string' ? value : ''\n\tconst ownIssue =\n\t\tshowErrorFromProps === undefined && error === undefined\n\t\t\t? colorValueIssue(stringValue, { linked, presets: resolvedPresets })\n\t\t\t: null\n\tconst errorMessage = error ?? (ownIssue ? t(keys[ownIssue]) : undefined)\n\tconst showError = showErrorFromProps ?? errorMessage !== undefined\n\n\tconst reference = linked ? parsePresetReference(stringValue) : null\n\tconst presetKey = reference?.key ?? null\n\t// With alpha disabled a stored suffix still parses, but renders at full\n\t// opacity so the field matches server resolution until commit strips it\n\tconst referenceAlpha = alpha ? (reference?.alpha ?? 100) : 100\n\tconst activePreset =\n\t\tpresetKey !== null ? resolvedPresets.find((preset) => preset.key === presetKey) : undefined\n\tconst presetMissing = presetKey !== null && !activePreset\n\tconst rawValue: unknown =\n\t\tpresetKey !== null ? (activePreset?.value ?? linkedFallback) : stringValue || null\n\tconst cssValue = flatValue(rawValue)\n\tconst parsed = useMemo(() => (cssValue ? parseColor(cssValue) : null), [cssValue])\n\n\tconst [displayFormat, setDisplayFormat] = useState<ColorFormat>(format)\n\tconst displayValue = useMemo(() => {\n\t\tif (presetKey !== null || !parsed || displayFormat === format) return stringValue\n\t\treturn formatColor(parsed, displayFormat, { alpha })\n\t}, [alpha, displayFormat, format, parsed, presetKey, stringValue])\n\n\tconst [draft, setDraft] = useState(displayValue)\n\tconst editingRef = useRef(false)\n\tuseEffect(() => {\n\t\tif (!editingRef.current) setDraft(displayValue)\n\t}, [displayValue])\n\n\t// Typing dismisses the chip into plain text entry; blur re-derives it from the committed value\n\tconst [chipDismissed, setChipDismissed] = useState(false)\n\tconst chip = useMemo(\n\t\t() =>\n\t\t\tderivePresetChip({\n\t\t\t\tediting: chipDismissed,\n\t\t\t\tlinked,\n\t\t\t\tpresets: resolvedPresets,\n\t\t\t\tvalue: stringValue,\n\t\t\t}),\n\t\t[chipDismissed, linked, resolvedPresets, stringValue]\n\t)\n\n\tconst debounceRef = useRef<null | ReturnType<typeof setTimeout>>(null)\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\t},\n\t\t[]\n\t)\n\n\t// The commit callbacks below read onChange through a ref, so a caller passing an\n\t// inline arrow does not re-create them (and with them the debounce) every render\n\tconst onChangeRef = useRef(onChange)\n\tonChangeRef.current = onChange\n\tconst setValue = useCallback((next: null | string) => onChangeRef.current(next), [])\n\n\t// Revert target for non-clearable commits; tracked from committed values so\n\t// picker commits, preset picks, and the initially loaded value all count\n\tconst lastValidRef = useRef<null | string>(null)\n\tuseEffect(() => {\n\t\tif (stringValue === '') return\n\t\tif (presetKey ? true : parseColor(stringValue) !== null) lastValidRef.current = stringValue\n\t}, [presetKey, stringValue])\n\n\t// Commits without touching editingRef: the debounced path must not let the draft resync mid-typing.\n\t// Returns true when a non-clearable empty or unparseable draft was reverted to the last valid value.\n\tconst commitText = useCallback(\n\t\t(raw: string): boolean => {\n\t\t\tlet normalized: null | string = null\n\t\t\tif (linked && raw.startsWith(PRESET_PREFIX)) {\n\t\t\t\tconst parts = presetReferenceParts(raw)\n\t\t\t\t// Canonical form: /100 collapses to the bare reference, and a disabled\n\t\t\t\t// alpha channel strips any hand-typed suffix. Empty keys commit raw so\n\t\t\t\t// validation surfaces the missing-preset error.\n\t\t\t\tif (parts) normalized = formatPresetReference(parts.key, alpha ? parts.alpha : 100)\n\t\t\t\telse if (raw.length > PRESET_PREFIX.length) normalized = raw\n\t\t\t} else {\n\t\t\t\tconst parsedRaw = parseColor(raw)\n\t\t\t\t// Unparseable input commits raw so validation surfaces the error\n\t\t\t\tif (parsedRaw) normalized = formatColor(parsedRaw, format, { alpha })\n\t\t\t}\n\t\t\tconst resolution = resolveCommitValue({\n\t\t\t\tdraft: raw,\n\t\t\t\tisClearable,\n\t\t\t\tlastValid: lastValidRef.current,\n\t\t\t\tparsed: normalized,\n\t\t\t})\n\t\t\tlastValidRef.current = resolution.lastValid\n\t\t\tsetValue(resolution.value)\n\t\t\treturn resolution.reverted\n\t\t},\n\t\t[alpha, format, isClearable, linked, setValue]\n\t)\n\n\tconst onTextChange = useCallback(\n\t\t(event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\tconst raw = event.target.value\n\t\t\teditingRef.current = true\n\t\t\tsetChipDismissed(true)\n\t\t\tsetDraft(raw)\n\t\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\t\tdebounceRef.current = setTimeout(() => commitText(raw), 250)\n\t\t},\n\t\t[commitText]\n\t)\n\n\tconst onTextBlur = useCallback(() => {\n\t\tif (debounceRef.current) {\n\t\t\tclearTimeout(debounceRef.current)\n\t\t\tdebounceRef.current = null\n\t\t}\n\t\tif (editingRef.current) {\n\t\t\teditingRef.current = false\n\t\t\t// Blur-only salvage: recover the first valid color from dirty input\n\t\t\t// (double pastes, stray junk) before the normal commit pipeline\n\t\t\tconst isPresetDraft = linked && draft.startsWith(PRESET_PREFIX)\n\t\t\tconst salvaged =\n\t\t\t\t!isPresetDraft && draft.trim() !== '' && !parseColor(draft) ? salvageColor(draft) : null\n\t\t\tif (commitText(salvaged ?? draft)) {\n\t\t\t\t// A reverted commit usually leaves the value unchanged, so the\n\t\t\t\t// displayValue resync effect never fires; restore the draft here\n\t\t\t\tsetDraft(displayValue)\n\t\t\t} else if (salvaged !== null) {\n\t\t\t\t// A salvaged commit can store the same value as before (double paste of\n\t\t\t\t// the current color), which also skips the resync; clean the draft here\n\t\t\t\tconst parsedSalvaged = parseColor(salvaged)\n\t\t\t\tsetDraft(parsedSalvaged ? formatColor(parsedSalvaged, displayFormat, { alpha }) : salvaged)\n\t\t\t}\n\t\t}\n\t\tsetChipDismissed(false)\n\t}, [alpha, commitText, displayFormat, displayValue, draft, linked])\n\n\t// Backspace/Delete on the empty chip input never fires a change event, so clear here\n\tconst onTextKeyDown = useCallback(\n\t\t(event: React.KeyboardEvent<HTMLInputElement>) => {\n\t\t\tif (!chip || isReadOnly) return\n\t\t\tif (event.key === 'Backspace' || event.key === 'Delete') {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tsetDraft('')\n\t\t\t\tif (isClearable) {\n\t\t\t\t\tsetValue(null)\n\t\t\t\t} else {\n\t\t\t\t\t// Keep the stored ref; the emptied draft reverts or gets replaced at commit\n\t\t\t\t\teditingRef.current = true\n\t\t\t\t\tsetChipDismissed(true)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[chip, isClearable, isReadOnly, setValue]\n\t)\n\n\tconst commitCss = useCallback(\n\t\t(css: string) => {\n\t\t\tconst parsedCss = parseColor(css)\n\t\t\tif (parsedCss) setValue(formatColor(parsedCss, format, { alpha }))\n\t\t},\n\t\t[alpha, format, setValue]\n\t)\n\n\t// With a reference active the slider represents the reference alpha, not the\n\t// resolved color's own channel, so returning it to 100 restores the bare ref\n\tconst initialHsva = useMemo<Hsva | null>(() => {\n\t\tif (!parsed) return null\n\t\tconst rgb = toRgb(parsed)\n\t\tconst hsv = rgbToHsv(rgb)\n\t\treturn {\n\t\t\ta: presetKey !== null ? referenceAlpha / 100 : rgb.alpha,\n\t\t\th: hsv.h,\n\t\t\ts: hsv.s,\n\t\t\tv: hsv.v,\n\t\t}\n\t}, [parsed, presetKey, referenceAlpha])\n\n\tconst commitReferenceAlpha = useCallback(\n\t\t(alpha100: number) => {\n\t\t\tif (presetKey === null) return\n\t\t\tsetValue(formatPresetReference(presetKey, alpha100))\n\t\t},\n\t\t[presetKey, setValue]\n\t)\n\n\t// The fade must track real overflow, not chip presence: the badge always hugs\n\t// the content run's right edge (the input's flex-grow pushes it there), so an\n\t// unconditional mask would fade it even in a full-width field with room to spare\n\tconst contentRef = useRef<HTMLDivElement>(null)\n\tconst [contentClipped, setContentClipped] = useState(false)\n\tconst measureClip = useCallback(() => {\n\t\tconst el = contentRef.current\n\t\t// +1 absorbs subpixel rounding between scrollWidth (int) and clientWidth\n\t\tif (el) setContentClipped(el.scrollWidth > el.clientWidth + 1)\n\t}, [])\n\t// No dependency array on purpose: chip mount and label changes alter\n\t// scrollWidth without resizing the observed box, so re-measure every render\n\tuseEffect(measureClip)\n\tuseEffect(() => {\n\t\tconst el = contentRef.current\n\t\tif (!el) return\n\t\tconst observer = new ResizeObserver(measureClip)\n\t\tobserver.observe(el)\n\t\treturn () => observer.disconnect()\n\t}, [measureClip])\n\n\t// Without a path there is no field id to derive, so the label pairs with a generated one\n\tconst generatedId = useId()\n\tconst inputId = path ? `field-${path.replace(/\\./g, '__')}` : generatedId\n\n\tconst swatchValue =\n\t\treferenceAlpha !== 100 && (typeof rawValue === 'string' || isColorSchemeValue(rawValue))\n\t\t\t? applyReferenceAlpha(rawValue, referenceAlpha, 'rgb')\n\t\t\t: rawValue\n\tconst swatchCss = swatchBackground(swatchValue)\n\n\tconst swatch = (\n\t\t<span className={`${baseClass}__swatch ${baseClass}__checker`}>\n\t\t\t{swatchCss ? (\n\t\t\t\t<span className={`${baseClass}__swatch-color`} style={{ background: swatchCss }} />\n\t\t\t) : null}\n\t\t\t{presetMissing && !swatchCss ? (\n\t\t\t\t<span className={`${baseClass}__swatch-color`} data-missing=\"true\" />\n\t\t\t) : null}\n\t\t\t{isReadOnly ? null : <span className={`${baseClass}__sr-only`}>{t(keys.pickColor)}</span>}\n\t\t</span>\n\t)\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\tfieldBaseClass,\n\t\t\t\tbaseClass,\n\t\t\t\tclassName,\n\t\t\t\tshowError && 'error',\n\t\t\t\tisReadOnly && 'read-only',\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' ')}\n\t\t\tstyle={style}\n\t\t>\n\t\t\t<RenderCustomComponent\n\t\t\t\tCustomComponent={Label}\n\t\t\t\tFallback={\n\t\t\t\t\t<FieldLabel\n\t\t\t\t\t\thtmlFor={path ? undefined : inputId}\n\t\t\t\t\t\tlabel={label}\n\t\t\t\t\t\tlocalized={localized}\n\t\t\t\t\t\tpath={path}\n\t\t\t\t\t\trequired={required}\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className={`${fieldBaseClass}__wrap`}>\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={ErrorComponent}\n\t\t\t\t\tFallback={<FieldError message={errorMessage} path={path} showError={showError} />}\n\t\t\t\t/>\n\t\t\t\t{BeforeInput}\n\t\t\t\t<div className={`${baseClass}__container`}>\n\t\t\t\t\t{isReadOnly ? (\n\t\t\t\t\t\t<span className={`${baseClass}__swatch-button ${baseClass}__swatch-button--static`}>\n\t\t\t\t\t\t\t{swatch}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<Popup\n\t\t\t\t\t\t\tbutton={swatch}\n\t\t\t\t\t\t\tbuttonClassName={`${baseClass}__swatch-button`}\n\t\t\t\t\t\t\tbuttonType=\"custom\"\n\t\t\t\t\t\t\tcaret={false}\n\t\t\t\t\t\t\tclassName={`${baseClass}__popup`}\n\t\t\t\t\t\t\thorizontalAlign=\"left\"\n\t\t\t\t\t\t\trender={({ close }) => (\n\t\t\t\t\t\t\t\t<ColorPickerPanel\n\t\t\t\t\t\t\t\t\tactiveReference={reference}\n\t\t\t\t\t\t\t\t\talphaEnabled={alpha}\n\t\t\t\t\t\t\t\t\tclose={close}\n\t\t\t\t\t\t\t\t\tdisplayFormat={displayFormat}\n\t\t\t\t\t\t\t\t\tenableEyedropper={enableEyedropper}\n\t\t\t\t\t\t\t\t\tinitial={initialHsva}\n\t\t\t\t\t\t\t\t\tonPickAlpha={commitReferenceAlpha}\n\t\t\t\t\t\t\t\t\tonPickCss={commitCss}\n\t\t\t\t\t\t\t\t\tonPickPreset={(preset) => {\n\t\t\t\t\t\t\t\t\t\tif (linked) setValue(`${PRESET_PREFIX}${preset.key}`)\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t// A text column holds one color, so a scheme preset stores its light member\n\t\t\t\t\t\t\t\t\t\t\tconst flat = flatValue(preset.value)\n\t\t\t\t\t\t\t\t\t\t\tif (flat) commitCss(flat)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\tpresetMissing={presetMissing}\n\t\t\t\t\t\t\t\t\tpresets={resolvedPresets}\n\t\t\t\t\t\t\t\t\tpresetsLabel={presetsLabel ?? t(keys.presets)}\n\t\t\t\t\t\t\t\t\tsetDisplayFormat={setDisplayFormat}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\tsize=\"fit-content\"\n\t\t\t\t\t\t\tverticalAlign=\"bottom\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={[`${baseClass}__content`, contentClipped && `${baseClass}__content--fade`]\n\t\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t\t.join(' ')}\n\t\t\t\t\t\tref={contentRef}\n\t\t\t\t\t>\n\t\t\t\t\t\t{chip ? (\n\t\t\t\t\t\t\t<span className={`${baseClass}__chip`}>\n\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-swatch ${baseClass}__checker`}>\n\t\t\t\t\t\t\t\t\t{swatchCss ? (\n\t\t\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__chip-color`}\n\t\t\t\t\t\t\t\t\t\t\tstyle={{ background: swatchCss }}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t\t{chip.missing && !swatchCss ? (\n\t\t\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-color`} data-missing=\"true\" />\n\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-label`}>{chip.label}</span>\n\t\t\t\t\t\t\t\t{alpha && chip.alpha !== 100 ? (\n\t\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-alpha`}>{chip.alpha}%</span>\n\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\t\tid={inputId}\n\t\t\t\t\t\t\tname={path}\n\t\t\t\t\t\t\tonBlur={onTextBlur}\n\t\t\t\t\t\t\tonChange={onTextChange}\n\t\t\t\t\t\t\tonKeyDown={onTextKeyDown}\n\t\t\t\t\t\t\tplaceholder={chip ? undefined : placeholder}\n\t\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\tvalue={chip ? '' : draft}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<span aria-hidden=\"true\" className={`${baseClass}__badge`}>\n\t\t\t\t\t\t\t{chip ? t(keys.preset) : displayFormat}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t{isClearable && !required && !isReadOnly && stringValue !== '' ? (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-label={t(keys.clearColor)}\n\t\t\t\t\t\t\tclassName={`${baseClass}__clear`}\n\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\tsetDraft('')\n\t\t\t\t\t\t\t\tsetValue(null)\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<XIcon />\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) : null}\n\t\t\t\t</div>\n\t\t\t\t{AfterInput}\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={Description}\n\t\t\t\t\tFallback={<FieldDescription description={description} path={path ?? ''} />}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsCA,MAAM,YAAY;AAElB,MAAM,kBAA2C;CAChD,OAAO;CACP,kBAAkB;CA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,oBAAC,OAAD,CAAQ,CAAA;MACD,CAAA,IACL;KACA;;IACJ;IACD,oBAAC,uBAAD;KACC,iBAAiB;KACjB,UAAU,oBAAC,kBAAD;MAA+B;MAAa,MAAM,QAAQ;KAAK,CAAA;IACzE,CAAA;GACG;IACD;;AAEP"}
@@ -1,5 +1,6 @@
1
1
  import { ColorFormat } from "../../../types.js";
2
2
  import { ResolvedColorPreset } from "../options.js";
3
+ import { PresetReference } from "../presetReference.js";
3
4
  import React from "react";
4
5
 
5
6
  //#region src/fields/color/client/ColorPickerPanel.d.ts
@@ -10,12 +11,13 @@ type Hsva = {
10
11
  v: number;
11
12
  };
12
13
  type ColorPickerPanelProps = {
13
- activePresetKey: null | string;
14
+ /** The stored preset reference when one is active; alpha edits then keep the reference. */activeReference: null | PresetReference;
14
15
  alphaEnabled: boolean;
15
16
  close: () => void;
16
17
  displayFormat: ColorFormat;
17
18
  enableEyedropper: boolean;
18
19
  initial: Hsva | null;
20
+ onPickAlpha: (alpha: number) => void;
19
21
  onPickCss: (css: string) => void;
20
22
  onPickPreset: (preset: ResolvedColorPreset) => void;
21
23
  presetMissing: boolean;
@@ -3,6 +3,7 @@ import { keys } from "../../../translations/keys.js";
3
3
  import { useTranslation } from "../../../translations/useTranslation.js";
4
4
  import { hsvToRgb } from "../engine/convert.js";
5
5
  import { formatColor } from "../engine/format.js";
6
+ import { swatchBackground } from "../schemeValue.js";
6
7
  import { EyedropperIcon } from "./icons.js";
7
8
  import { useCallback, useEffect, useRef, useState } from "react";
8
9
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -20,10 +21,10 @@ const getEyeDropper = () => {
20
21
  };
21
22
  const clamp01 = (value) => Math.min(1, Math.max(0, value));
22
23
  const ColorPickerPanel = (props) => {
23
- const { activePresetKey, alphaEnabled, close, displayFormat, enableEyedropper, initial, onPickCss, onPickPreset, presetMissing, presets, presetsLabel, setDisplayFormat } = props;
24
+ const { activeReference, alphaEnabled, close, displayFormat, enableEyedropper, initial, onPickAlpha, onPickCss, onPickPreset, presetMissing, presets, presetsLabel, setDisplayFormat } = props;
24
25
  const { t } = useTranslation();
25
26
  const [hsva, setHsva] = useState(initial ?? {
26
- a: 1,
27
+ a: activeReference ? activeReference.alpha / 100 : 1,
27
28
  h: 0,
28
29
  s: 1,
29
30
  v: 1
@@ -50,8 +51,11 @@ const ColorPickerPanel = (props) => {
50
51
  if (skip) return;
51
52
  setHsva(initial);
52
53
  }, [initial ? `${initial.h}|${initial.s}|${initial.v}|${initial.a}` : ""]);
54
+ const alphaRafRef = useRef(null);
55
+ const pendingAlphaRef = useRef(100);
53
56
  useEffect(() => () => {
54
57
  if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);
58
+ if (alphaRafRef.current !== null) cancelAnimationFrame(alphaRafRef.current);
55
59
  }, []);
56
60
  const commit = useCallback((next) => {
57
61
  pendingRef.current = next;
@@ -80,6 +84,21 @@ const ColorPickerPanel = (props) => {
80
84
  setHsva(next);
81
85
  commit(next);
82
86
  }, [commit]);
87
+ const commitReferenceAlpha = useCallback((next) => {
88
+ setHsva(next);
89
+ pendingAlphaRef.current = Math.round(next.a * 100);
90
+ if (alphaRafRef.current !== null) return;
91
+ alphaRafRef.current = requestAnimationFrame(() => {
92
+ alphaRafRef.current = null;
93
+ const current = hsvaRef.current;
94
+ lastEmittedRef.current = formatColor(hsvToRgb({
95
+ h: current.h,
96
+ s: current.s,
97
+ v: current.v
98
+ }, 1), "rgb");
99
+ onPickAlpha(pendingAlphaRef.current);
100
+ });
101
+ }, [onPickAlpha]);
83
102
  const svPointer = useCallback((event) => {
84
103
  const rect = svRef.current?.getBoundingClientRect();
85
104
  if (!rect) return;
@@ -162,7 +181,14 @@ const ColorPickerPanel = (props) => {
162
181
  className: `${baseClass}__slider ${baseClass}__slider--alpha`,
163
182
  max: 100,
164
183
  min: 0,
165
- onChange: (event) => applyPartial({ a: Number(event.target.value) / 100 }),
184
+ onChange: (event) => {
185
+ const a = Number(event.target.value) / 100;
186
+ if (activeReference) commitReferenceAlpha({
187
+ ...hsvaRef.current,
188
+ a
189
+ });
190
+ else applyPartial({ a });
191
+ },
166
192
  onKeyDown: stopArrowKeys,
167
193
  onLostPointerCapture: endDrag,
168
194
  step: 1,
@@ -211,7 +237,7 @@ const ColorPickerPanel = (props) => {
211
237
  className: `${baseClass}__presets-grid`,
212
238
  children: presets.map((preset) => /* @__PURE__ */ jsx("button", {
213
239
  "aria-label": preset.label,
214
- "aria-pressed": preset.key === activePresetKey,
240
+ "aria-pressed": preset.key === activeReference?.key,
215
241
  className: `${baseClass}__preset ${baseClass}__checker`,
216
242
  onClick: () => {
217
243
  onPickPreset(preset);
@@ -219,7 +245,7 @@ const ColorPickerPanel = (props) => {
219
245
  },
220
246
  title: preset.label,
221
247
  type: "button",
222
- children: /* @__PURE__ */ jsx("span", { style: { background: preset.value } })
248
+ children: /* @__PURE__ */ jsx("span", { style: { background: swatchBackground(preset.value) ?? void 0 } })
223
249
  }, preset.key))
224
250
  })
225
251
  ]
@@ -1 +1 @@
1
- {"version":3,"file":"ColorPickerPanel.js","names":[],"sources":["../../../../src/fields/color/client/ColorPickerPanel.tsx"],"sourcesContent":["'use client'\nimport type React from 'react'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { ColorFormat } from '../../../types'\nimport { formatColor, hsvToRgb } from '../engine'\nimport type { ResolvedColorPreset } from '../options'\nimport { EyedropperIcon } from './icons'\n\nconst baseClass = 'fields-color'\nconst FORMATS: ColorFormat[] = ['hex', 'rgb', 'hsl', 'oklch']\n\nexport type Hsva = { a: number; h: number; s: number; v: number }\n\ntype EyeDropperConstructor = new () => { open: () => Promise<{ sRGBHex: string }> }\n\nconst getEyeDropper = (): EyeDropperConstructor | null => {\n\tif (typeof window === 'undefined') return null\n\treturn (window as Window & { EyeDropper?: EyeDropperConstructor }).EyeDropper ?? null\n}\n\nconst clamp01 = (value: number): number => Math.min(1, Math.max(0, value))\n\nexport type ColorPickerPanelProps = {\n\tactivePresetKey: null | string\n\talphaEnabled: boolean\n\tclose: () => void\n\tdisplayFormat: ColorFormat\n\tenableEyedropper: boolean\n\tinitial: Hsva | null\n\tonPickCss: (css: string) => void\n\tonPickPreset: (preset: ResolvedColorPreset) => void\n\tpresetMissing: boolean\n\tpresets: ResolvedColorPreset[]\n\tpresetsLabel: string\n\tsetDisplayFormat: (format: ColorFormat) => void\n}\n\nexport const ColorPickerPanel: React.FC<ColorPickerPanelProps> = (props) => {\n\tconst {\n\t\tactivePresetKey,\n\t\talphaEnabled,\n\t\tclose,\n\t\tdisplayFormat,\n\t\tenableEyedropper,\n\t\tinitial,\n\t\tonPickCss,\n\t\tonPickPreset,\n\t\tpresetMissing,\n\t\tpresets,\n\t\tpresetsLabel,\n\t\tsetDisplayFormat,\n\t} = props\n\tconst { t } = useTranslation()\n\n\tconst [hsva, setHsva] = useState<Hsva>(initial ?? { a: 1, h: 0, s: 1, v: 1 })\n\tconst hsvaRef = useRef(hsva)\n\thsvaRef.current = hsva\n\tconst draggingRef = useRef(false)\n\tconst svRef = useRef<HTMLDivElement>(null)\n\tconst rafRef = useRef<null | number>(null)\n\tconst pendingRef = useRef<Hsva | null>(null)\n\tconst lastEmittedRef = useRef<null | string>(null)\n\n\tconst initialKey = initial ? `${initial.h}|${initial.s}|${initial.v}|${initial.a}` : ''\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: resync only when the committed color changes, not on every initial object identity change\n\tuseEffect(() => {\n\t\tif (!initial) {\n\t\t\tlastEmittedRef.current = null\n\t\t\treturn\n\t\t}\n\t\tif (draggingRef.current) return\n\t\t// Skip echoes of our own commit: achromatic values round-trip with h/s zeroed and would clobber the local hue/saturation.\n\t\t// Compared opaque (alpha quantizes through hex storage) and one-shot (a stale ref must not suppress a later genuine match)\n\t\tconst incomingCss = formatColor(\n\t\t\thsvToRgb({ h: initial.h, s: initial.s, v: initial.v }, 1),\n\t\t\t'rgb'\n\t\t)\n\t\tconst skip = incomingCss === lastEmittedRef.current\n\t\tlastEmittedRef.current = null\n\t\tif (skip) return\n\t\tsetHsva(initial)\n\t}, [initialKey])\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (rafRef.current !== null) cancelAnimationFrame(rafRef.current)\n\t\t},\n\t\t[]\n\t)\n\n\t// Commits are rAF-throttled: pointermove floods would otherwise dispatch a form update per event\n\tconst commit = useCallback(\n\t\t(next: Hsva) => {\n\t\t\tpendingRef.current = next\n\t\t\tif (rafRef.current !== null) return\n\t\t\trafRef.current = requestAnimationFrame(() => {\n\t\t\t\trafRef.current = null\n\t\t\t\tconst pending = pendingRef.current\n\t\t\t\tif (!pending) return\n\t\t\t\tlastEmittedRef.current = formatColor(\n\t\t\t\t\thsvToRgb({ h: pending.h, s: pending.s, v: pending.v }, 1),\n\t\t\t\t\t'rgb'\n\t\t\t\t)\n\t\t\t\tonPickCss(\n\t\t\t\t\tformatColor(\n\t\t\t\t\t\thsvToRgb({ h: pending.h, s: pending.s, v: pending.v }, alphaEnabled ? pending.a : 1),\n\t\t\t\t\t\t'rgb'\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t})\n\t\t},\n\t\t[alphaEnabled, onPickCss]\n\t)\n\n\tconst applyPartial = useCallback(\n\t\t(patch: Partial<Hsva>) => {\n\t\t\tconst next = { ...hsvaRef.current, ...patch }\n\t\t\tsetHsva(next)\n\t\t\tcommit(next)\n\t\t},\n\t\t[commit]\n\t)\n\n\tconst svPointer = useCallback(\n\t\t(event: React.PointerEvent<HTMLDivElement>) => {\n\t\t\tconst rect = svRef.current?.getBoundingClientRect()\n\t\t\tif (!rect) return\n\t\t\tapplyPartial({\n\t\t\t\ts: clamp01((event.clientX - rect.left) / rect.width),\n\t\t\t\tv: clamp01(1 - (event.clientY - rect.top) / rect.height),\n\t\t\t})\n\t\t},\n\t\t[applyPartial]\n\t)\n\n\tconst onSvKeyDown = useCallback(\n\t\t(event: React.KeyboardEvent<HTMLDivElement>) => {\n\t\t\tif (!event.key.startsWith('Arrow')) return\n\t\t\t// Popup preventDefaults ArrowUp/ArrowDown at document level for focus cycling; consume first\n\t\t\tevent.stopPropagation()\n\t\t\tevent.preventDefault()\n\t\t\tconst step = event.shiftKey ? 0.1 : 0.01\n\t\t\tconst current = hsvaRef.current\n\t\t\tif (event.key === 'ArrowLeft') applyPartial({ s: clamp01(current.s - step) })\n\t\t\tif (event.key === 'ArrowRight') applyPartial({ s: clamp01(current.s + step) })\n\t\t\tif (event.key === 'ArrowUp') applyPartial({ v: clamp01(current.v + step) })\n\t\t\tif (event.key === 'ArrowDown') applyPartial({ v: clamp01(current.v - step) })\n\t\t},\n\t\t[applyPartial]\n\t)\n\n\t// Without this the Popup's document keydown handler preventDefaults native range stepping\n\tconst stopArrowKeys = useCallback((event: React.KeyboardEvent) => {\n\t\tif (event.key.startsWith('Arrow')) event.stopPropagation()\n\t}, [])\n\n\t// Fires after pointerup AND pointercancel, so an interrupted drag never leaves draggingRef stuck\n\tconst endDrag = useCallback(() => {\n\t\tdraggingRef.current = false\n\t}, [])\n\n\tconst opaqueCss = formatColor(hsvToRgb({ h: hsva.h, s: hsva.s, v: hsva.v }, 1), 'rgb')\n\tconst eyeDropperCtor = enableEyedropper ? getEyeDropper() : null\n\n\treturn (\n\t\t<div className={`${baseClass}__panel`} data-popup-prevent-close>\n\t\t\t<div\n\t\t\t\taria-label={t(keys.saturationBrightness)}\n\t\t\t\taria-valuemax={100}\n\t\t\t\taria-valuemin={0}\n\t\t\t\taria-valuenow={Math.round(hsva.v * 100)}\n\t\t\t\taria-valuetext={`${Math.round(hsva.s * 100)}% / ${Math.round(hsva.v * 100)}%`}\n\t\t\t\tclassName={`${baseClass}__sv`}\n\t\t\t\tonKeyDown={onSvKeyDown}\n\t\t\t\tonPointerDown={(event) => {\n\t\t\t\t\tdraggingRef.current = true\n\t\t\t\t\tevent.currentTarget.setPointerCapture(event.pointerId)\n\t\t\t\t\tsvPointer(event)\n\t\t\t\t}}\n\t\t\t\tonLostPointerCapture={endDrag}\n\t\t\t\tonPointerMove={(event) => {\n\t\t\t\t\tif (draggingRef.current) svPointer(event)\n\t\t\t\t}}\n\t\t\t\tonPointerUp={endDrag}\n\t\t\t\tref={svRef}\n\t\t\t\trole=\"slider\"\n\t\t\t\tstyle={{ backgroundColor: `hsl(${Math.round(hsva.h)} 100% 50%)` }}\n\t\t\t\ttabIndex={0}\n\t\t\t>\n\t\t\t\t<span\n\t\t\t\t\tclassName={`${baseClass}__sv-thumb`}\n\t\t\t\t\tstyle={{ left: `${hsva.s * 100}%`, top: `${(1 - hsva.v) * 100}%` }}\n\t\t\t\t/>\n\t\t\t</div>\n\n\t\t\t<input\n\t\t\t\taria-label={t(keys.hue)}\n\t\t\t\tclassName={`${baseClass}__slider ${baseClass}__slider--hue`}\n\t\t\t\tmax={360}\n\t\t\t\tmin={0}\n\t\t\t\tonChange={(event) => applyPartial({ h: Number(event.target.value) })}\n\t\t\t\tonKeyDown={stopArrowKeys}\n\t\t\t\tonLostPointerCapture={endDrag}\n\t\t\t\tstep={1}\n\t\t\t\ttype=\"range\"\n\t\t\t\tvalue={Math.round(hsva.h)}\n\t\t\t/>\n\n\t\t\t{alphaEnabled ? (\n\t\t\t\t<input\n\t\t\t\t\taria-label={t(keys.opacity)}\n\t\t\t\t\tclassName={`${baseClass}__slider ${baseClass}__slider--alpha`}\n\t\t\t\t\tmax={100}\n\t\t\t\t\tmin={0}\n\t\t\t\t\tonChange={(event) => applyPartial({ a: Number(event.target.value) / 100 })}\n\t\t\t\t\tonKeyDown={stopArrowKeys}\n\t\t\t\t\tonLostPointerCapture={endDrag}\n\t\t\t\t\tstep={1}\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\tbackgroundImage: `linear-gradient(to right, transparent, ${opaqueCss}), conic-gradient(var(--theme-elevation-150) 0 25%, transparent 0 50%, var(--theme-elevation-150) 0 75%, transparent 0)`,\n\t\t\t\t\t\tbackgroundSize: '100% 100%, 8px 8px',\n\t\t\t\t\t}}\n\t\t\t\t\ttype=\"range\"\n\t\t\t\t\tvalue={Math.round(hsva.a * 100)}\n\t\t\t\t/>\n\t\t\t) : null}\n\n\t\t\t<div className={`${baseClass}__controls`}>\n\t\t\t\t{/* biome-ignore lint/a11y/useSemanticElements: fieldset breaks flex layout in Safari; this is a toggle-button group, not a form fieldset */}\n\t\t\t\t<div aria-label={t(keys.format)} className={`${baseClass}__formats`} role=\"group\">\n\t\t\t\t\t{FORMATS.map((entry) => (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-pressed={entry === displayFormat}\n\t\t\t\t\t\t\tclassName={`${baseClass}__format`}\n\t\t\t\t\t\t\tkey={entry}\n\t\t\t\t\t\t\tonClick={() => setDisplayFormat(entry)}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{entry}\n\t\t\t\t\t\t</button>\n\t\t\t\t\t))}\n\t\t\t\t</div>\n\t\t\t\t{eyeDropperCtor ? (\n\t\t\t\t\t<button\n\t\t\t\t\t\taria-label={t(keys.eyedropperPick)}\n\t\t\t\t\t\tclassName={`${baseClass}__eyedropper`}\n\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\tvoid new eyeDropperCtor().open().then(\n\t\t\t\t\t\t\t\t(result) => onPickCss(result.sRGBHex),\n\t\t\t\t\t\t\t\t// open() rejects when the user presses Escape; nothing to do\n\t\t\t\t\t\t\t\t() => undefined\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<EyedropperIcon />\n\t\t\t\t\t</button>\n\t\t\t\t) : null}\n\t\t\t</div>\n\n\t\t\t{presets.length > 0 ? (\n\t\t\t\t<div className={`${baseClass}__presets`}>\n\t\t\t\t\t<div className={`${baseClass}__presets-label`}>{presetsLabel}</div>\n\t\t\t\t\t{presetMissing ? (\n\t\t\t\t\t\t<p className={`${baseClass}__missing`}>{t(keys.missingPresetHint)}</p>\n\t\t\t\t\t) : null}\n\t\t\t\t\t<div className={`${baseClass}__presets-grid`}>\n\t\t\t\t\t\t{presets.map((preset) => (\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\taria-label={preset.label}\n\t\t\t\t\t\t\t\taria-pressed={preset.key === activePresetKey}\n\t\t\t\t\t\t\t\tclassName={`${baseClass}__preset ${baseClass}__checker`}\n\t\t\t\t\t\t\t\tkey={preset.key}\n\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\tonPickPreset(preset)\n\t\t\t\t\t\t\t\t\tclose()\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\ttitle={preset.label}\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<span style={{ background: preset.value }} />\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t) : null}\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,YAAY;AAClB,MAAM,UAAyB;CAAC;CAAO;CAAO;CAAO;AAAO;AAM5D,MAAM,sBAAoD;CACzD,IAAI,OAAO,WAAW,aAAa,OAAO;CAC1C,OAAQ,OAA2D,cAAc;AAClF;AAEA,MAAM,WAAW,UAA0B,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,CAAC;AAiBzE,MAAa,oBAAqD,UAAU;CAC3E,MAAM,EACL,iBACA,cACA,OACA,eACA,kBACA,SACA,WACA,cACA,eACA,SACA,cACA,qBACG;CACJ,MAAM,EAAE,MAAM,eAAe;CAE7B,MAAM,CAAC,MAAM,WAAW,SAAe,WAAW;EAAE,GAAG;EAAG,GAAG;EAAG,GAAG;EAAG,GAAG;CAAE,CAAC;CAC5E,MAAM,UAAU,OAAO,IAAI;CAC3B,QAAQ,UAAU;CAClB,MAAM,cAAc,OAAO,KAAK;CAChC,MAAM,QAAQ,OAAuB,IAA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.js","names":[],"sources":["../../../../src/fields/color/client/ColorPickerPanel.tsx"],"sourcesContent":["'use client'\nimport type React from 'react'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { ColorFormat } from '../../../types'\nimport { formatColor, hsvToRgb } from '../engine'\nimport type { ResolvedColorPreset } from '../options'\nimport type { PresetReference } from '../presetReference'\nimport { swatchBackground } from '../schemeValue'\nimport { EyedropperIcon } from './icons'\n\nconst baseClass = 'fields-color'\nconst FORMATS: ColorFormat[] = ['hex', 'rgb', 'hsl', 'oklch']\n\nexport type Hsva = { a: number; h: number; s: number; v: number }\n\ntype EyeDropperConstructor = new () => { open: () => Promise<{ sRGBHex: string }> }\n\nconst getEyeDropper = (): EyeDropperConstructor | null => {\n\tif (typeof window === 'undefined') return null\n\treturn (window as Window & { EyeDropper?: EyeDropperConstructor }).EyeDropper ?? null\n}\n\nconst clamp01 = (value: number): number => Math.min(1, Math.max(0, value))\n\nexport type ColorPickerPanelProps = {\n\t/** The stored preset reference when one is active; alpha edits then keep the reference. */\n\tactiveReference: null | PresetReference\n\talphaEnabled: boolean\n\tclose: () => void\n\tdisplayFormat: ColorFormat\n\tenableEyedropper: boolean\n\tinitial: Hsva | null\n\tonPickAlpha: (alpha: number) => void\n\tonPickCss: (css: string) => void\n\tonPickPreset: (preset: ResolvedColorPreset) => void\n\tpresetMissing: boolean\n\tpresets: ResolvedColorPreset[]\n\tpresetsLabel: string\n\tsetDisplayFormat: (format: ColorFormat) => void\n}\n\nexport const ColorPickerPanel: React.FC<ColorPickerPanelProps> = (props) => {\n\tconst {\n\t\tactiveReference,\n\t\talphaEnabled,\n\t\tclose,\n\t\tdisplayFormat,\n\t\tenableEyedropper,\n\t\tinitial,\n\t\tonPickAlpha,\n\t\tonPickCss,\n\t\tonPickPreset,\n\t\tpresetMissing,\n\t\tpresets,\n\t\tpresetsLabel,\n\t\tsetDisplayFormat,\n\t} = props\n\tconst { t } = useTranslation()\n\n\t// A missing preset resolves no color (initial is null) but its stored alpha\n\t// must still seed the slider so dragging it edits the reference in place\n\tconst [hsva, setHsva] = useState<Hsva>(\n\t\tinitial ?? { a: activeReference ? activeReference.alpha / 100 : 1, h: 0, s: 1, v: 1 }\n\t)\n\tconst hsvaRef = useRef(hsva)\n\thsvaRef.current = hsva\n\tconst draggingRef = useRef(false)\n\tconst svRef = useRef<HTMLDivElement>(null)\n\tconst rafRef = useRef<null | number>(null)\n\tconst pendingRef = useRef<Hsva | null>(null)\n\tconst lastEmittedRef = useRef<null | string>(null)\n\n\tconst initialKey = initial ? `${initial.h}|${initial.s}|${initial.v}|${initial.a}` : ''\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: resync only when the committed color changes, not on every initial object identity change\n\tuseEffect(() => {\n\t\tif (!initial) {\n\t\t\tlastEmittedRef.current = null\n\t\t\treturn\n\t\t}\n\t\tif (draggingRef.current) return\n\t\t// Skip echoes of our own commit: achromatic values round-trip with h/s zeroed and would clobber the local hue/saturation.\n\t\t// Compared opaque (alpha quantizes through hex storage) and one-shot (a stale ref must not suppress a later genuine match)\n\t\tconst incomingCss = formatColor(\n\t\t\thsvToRgb({ h: initial.h, s: initial.s, v: initial.v }, 1),\n\t\t\t'rgb'\n\t\t)\n\t\tconst skip = incomingCss === lastEmittedRef.current\n\t\tlastEmittedRef.current = null\n\t\tif (skip) return\n\t\tsetHsva(initial)\n\t}, [initialKey])\n\n\tconst alphaRafRef = useRef<null | number>(null)\n\tconst pendingAlphaRef = useRef(100)\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (rafRef.current !== null) cancelAnimationFrame(rafRef.current)\n\t\t\tif (alphaRafRef.current !== null) cancelAnimationFrame(alphaRafRef.current)\n\t\t},\n\t\t[]\n\t)\n\n\t// Commits are rAF-throttled: pointermove floods would otherwise dispatch a form update per event\n\tconst commit = useCallback(\n\t\t(next: Hsva) => {\n\t\t\tpendingRef.current = next\n\t\t\tif (rafRef.current !== null) return\n\t\t\trafRef.current = requestAnimationFrame(() => {\n\t\t\t\trafRef.current = null\n\t\t\t\tconst pending = pendingRef.current\n\t\t\t\tif (!pending) return\n\t\t\t\tlastEmittedRef.current = formatColor(\n\t\t\t\t\thsvToRgb({ h: pending.h, s: pending.s, v: pending.v }, 1),\n\t\t\t\t\t'rgb'\n\t\t\t\t)\n\t\t\t\tonPickCss(\n\t\t\t\t\tformatColor(\n\t\t\t\t\t\thsvToRgb({ h: pending.h, s: pending.s, v: pending.v }, alphaEnabled ? pending.a : 1),\n\t\t\t\t\t\t'rgb'\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t})\n\t\t},\n\t\t[alphaEnabled, onPickCss]\n\t)\n\n\tconst applyPartial = useCallback(\n\t\t(patch: Partial<Hsva>) => {\n\t\t\tconst next = { ...hsvaRef.current, ...patch }\n\t\t\tsetHsva(next)\n\t\t\tcommit(next)\n\t\t},\n\t\t[commit]\n\t)\n\n\t// Reference-preserving alpha path: while a preset is active, the slider\n\t// rewrites the stored `/<alpha>` suffix instead of committing a concrete\n\t// color. Same rAF throttling and echo suppression as the concrete path\n\t// (the opaque css is unchanged by alpha, so the resync effect skips it).\n\tconst commitReferenceAlpha = useCallback(\n\t\t(next: Hsva) => {\n\t\t\tsetHsva(next)\n\t\t\tpendingAlphaRef.current = Math.round(next.a * 100)\n\t\t\tif (alphaRafRef.current !== null) return\n\t\t\talphaRafRef.current = requestAnimationFrame(() => {\n\t\t\t\talphaRafRef.current = null\n\t\t\t\tconst current = hsvaRef.current\n\t\t\t\tlastEmittedRef.current = formatColor(\n\t\t\t\t\thsvToRgb({ h: current.h, s: current.s, v: current.v }, 1),\n\t\t\t\t\t'rgb'\n\t\t\t\t)\n\t\t\t\tonPickAlpha(pendingAlphaRef.current)\n\t\t\t})\n\t\t},\n\t\t[onPickAlpha]\n\t)\n\n\tconst svPointer = useCallback(\n\t\t(event: React.PointerEvent<HTMLDivElement>) => {\n\t\t\tconst rect = svRef.current?.getBoundingClientRect()\n\t\t\tif (!rect) return\n\t\t\tapplyPartial({\n\t\t\t\ts: clamp01((event.clientX - rect.left) / rect.width),\n\t\t\t\tv: clamp01(1 - (event.clientY - rect.top) / rect.height),\n\t\t\t})\n\t\t},\n\t\t[applyPartial]\n\t)\n\n\tconst onSvKeyDown = useCallback(\n\t\t(event: React.KeyboardEvent<HTMLDivElement>) => {\n\t\t\tif (!event.key.startsWith('Arrow')) return\n\t\t\t// Popup preventDefaults ArrowUp/ArrowDown at document level for focus cycling; consume first\n\t\t\tevent.stopPropagation()\n\t\t\tevent.preventDefault()\n\t\t\tconst step = event.shiftKey ? 0.1 : 0.01\n\t\t\tconst current = hsvaRef.current\n\t\t\tif (event.key === 'ArrowLeft') applyPartial({ s: clamp01(current.s - step) })\n\t\t\tif (event.key === 'ArrowRight') applyPartial({ s: clamp01(current.s + step) })\n\t\t\tif (event.key === 'ArrowUp') applyPartial({ v: clamp01(current.v + step) })\n\t\t\tif (event.key === 'ArrowDown') applyPartial({ v: clamp01(current.v - step) })\n\t\t},\n\t\t[applyPartial]\n\t)\n\n\t// Without this the Popup's document keydown handler preventDefaults native range stepping\n\tconst stopArrowKeys = useCallback((event: React.KeyboardEvent) => {\n\t\tif (event.key.startsWith('Arrow')) event.stopPropagation()\n\t}, [])\n\n\t// Fires after pointerup AND pointercancel, so an interrupted drag never leaves draggingRef stuck\n\tconst endDrag = useCallback(() => {\n\t\tdraggingRef.current = false\n\t}, [])\n\n\tconst opaqueCss = formatColor(hsvToRgb({ h: hsva.h, s: hsva.s, v: hsva.v }, 1), 'rgb')\n\tconst eyeDropperCtor = enableEyedropper ? getEyeDropper() : null\n\n\treturn (\n\t\t<div className={`${baseClass}__panel`} data-popup-prevent-close>\n\t\t\t<div\n\t\t\t\taria-label={t(keys.saturationBrightness)}\n\t\t\t\taria-valuemax={100}\n\t\t\t\taria-valuemin={0}\n\t\t\t\taria-valuenow={Math.round(hsva.v * 100)}\n\t\t\t\taria-valuetext={`${Math.round(hsva.s * 100)}% / ${Math.round(hsva.v * 100)}%`}\n\t\t\t\tclassName={`${baseClass}__sv`}\n\t\t\t\tonKeyDown={onSvKeyDown}\n\t\t\t\tonPointerDown={(event) => {\n\t\t\t\t\tdraggingRef.current = true\n\t\t\t\t\tevent.currentTarget.setPointerCapture(event.pointerId)\n\t\t\t\t\tsvPointer(event)\n\t\t\t\t}}\n\t\t\t\tonLostPointerCapture={endDrag}\n\t\t\t\tonPointerMove={(event) => {\n\t\t\t\t\tif (draggingRef.current) svPointer(event)\n\t\t\t\t}}\n\t\t\t\tonPointerUp={endDrag}\n\t\t\t\tref={svRef}\n\t\t\t\trole=\"slider\"\n\t\t\t\tstyle={{ backgroundColor: `hsl(${Math.round(hsva.h)} 100% 50%)` }}\n\t\t\t\ttabIndex={0}\n\t\t\t>\n\t\t\t\t<span\n\t\t\t\t\tclassName={`${baseClass}__sv-thumb`}\n\t\t\t\t\tstyle={{ left: `${hsva.s * 100}%`, top: `${(1 - hsva.v) * 100}%` }}\n\t\t\t\t/>\n\t\t\t</div>\n\n\t\t\t<input\n\t\t\t\taria-label={t(keys.hue)}\n\t\t\t\tclassName={`${baseClass}__slider ${baseClass}__slider--hue`}\n\t\t\t\tmax={360}\n\t\t\t\tmin={0}\n\t\t\t\tonChange={(event) => applyPartial({ h: Number(event.target.value) })}\n\t\t\t\tonKeyDown={stopArrowKeys}\n\t\t\t\tonLostPointerCapture={endDrag}\n\t\t\t\tstep={1}\n\t\t\t\ttype=\"range\"\n\t\t\t\tvalue={Math.round(hsva.h)}\n\t\t\t/>\n\n\t\t\t{alphaEnabled ? (\n\t\t\t\t<input\n\t\t\t\t\taria-label={t(keys.opacity)}\n\t\t\t\t\tclassName={`${baseClass}__slider ${baseClass}__slider--alpha`}\n\t\t\t\t\tmax={100}\n\t\t\t\t\tmin={0}\n\t\t\t\t\tonChange={(event) => {\n\t\t\t\t\t\tconst a = Number(event.target.value) / 100\n\t\t\t\t\t\tif (activeReference) commitReferenceAlpha({ ...hsvaRef.current, a })\n\t\t\t\t\t\telse applyPartial({ a })\n\t\t\t\t\t}}\n\t\t\t\t\tonKeyDown={stopArrowKeys}\n\t\t\t\t\tonLostPointerCapture={endDrag}\n\t\t\t\t\tstep={1}\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\tbackgroundImage: `linear-gradient(to right, transparent, ${opaqueCss}), conic-gradient(var(--theme-elevation-150) 0 25%, transparent 0 50%, var(--theme-elevation-150) 0 75%, transparent 0)`,\n\t\t\t\t\t\tbackgroundSize: '100% 100%, 8px 8px',\n\t\t\t\t\t}}\n\t\t\t\t\ttype=\"range\"\n\t\t\t\t\tvalue={Math.round(hsva.a * 100)}\n\t\t\t\t/>\n\t\t\t) : null}\n\n\t\t\t<div className={`${baseClass}__controls`}>\n\t\t\t\t{/* biome-ignore lint/a11y/useSemanticElements: fieldset breaks flex layout in Safari; this is a toggle-button group, not a form fieldset */}\n\t\t\t\t<div aria-label={t(keys.format)} className={`${baseClass}__formats`} role=\"group\">\n\t\t\t\t\t{FORMATS.map((entry) => (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-pressed={entry === displayFormat}\n\t\t\t\t\t\t\tclassName={`${baseClass}__format`}\n\t\t\t\t\t\t\tkey={entry}\n\t\t\t\t\t\t\tonClick={() => setDisplayFormat(entry)}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{entry}\n\t\t\t\t\t\t</button>\n\t\t\t\t\t))}\n\t\t\t\t</div>\n\t\t\t\t{eyeDropperCtor ? (\n\t\t\t\t\t<button\n\t\t\t\t\t\taria-label={t(keys.eyedropperPick)}\n\t\t\t\t\t\tclassName={`${baseClass}__eyedropper`}\n\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\tvoid new eyeDropperCtor().open().then(\n\t\t\t\t\t\t\t\t(result) => onPickCss(result.sRGBHex),\n\t\t\t\t\t\t\t\t// open() rejects when the user presses Escape; nothing to do\n\t\t\t\t\t\t\t\t() => undefined\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<EyedropperIcon />\n\t\t\t\t\t</button>\n\t\t\t\t) : null}\n\t\t\t</div>\n\n\t\t\t{presets.length > 0 ? (\n\t\t\t\t<div className={`${baseClass}__presets`}>\n\t\t\t\t\t<div className={`${baseClass}__presets-label`}>{presetsLabel}</div>\n\t\t\t\t\t{presetMissing ? (\n\t\t\t\t\t\t<p className={`${baseClass}__missing`}>{t(keys.missingPresetHint)}</p>\n\t\t\t\t\t) : null}\n\t\t\t\t\t<div className={`${baseClass}__presets-grid`}>\n\t\t\t\t\t\t{presets.map((preset) => (\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\taria-label={preset.label}\n\t\t\t\t\t\t\t\taria-pressed={preset.key === activeReference?.key}\n\t\t\t\t\t\t\t\tclassName={`${baseClass}__preset ${baseClass}__checker`}\n\t\t\t\t\t\t\t\tkey={preset.key}\n\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\tonPickPreset(preset)\n\t\t\t\t\t\t\t\t\tclose()\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\ttitle={preset.label}\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<span style={{ background: swatchBackground(preset.value) ?? undefined }} />\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t) : null}\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,YAAY;AAClB,MAAM,UAAyB;CAAC;CAAO;CAAO;CAAO;AAAO;AAM5D,MAAM,sBAAoD;CACzD,IAAI,OAAO,WAAW,aAAa,OAAO;CAC1C,OAAQ,OAA2D,cAAc;AAClF;AAEA,MAAM,WAAW,UAA0B,KAAK,IAAI,GAAG,KAAK,IAAI,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D;MACC,gBAAc,UAAU;MACxB,WAAW,GAAG,UAAU;MAExB,eAAe,iBAAiB,KAAK;MACrC,MAAK;gBAEJ;KACM,GALF,KAKE,CACR;IACG,CAAA,GACJ,iBACA,oBAAC,UAAD;KACC,cAAY,EAAE,KAAK,cAAc;KACjC,WAAW,GAAG,UAAU;KACxB,eAAe;MACd,IAAS,eAAe,EAAE,KAAK,EAAE,MAC/B,WAAW,UAAU,OAAO,OAAO,SAE9B,KAAA,CACP;KACD;KACA,MAAK;eAEL,oBAAC,gBAAD,CAAiB,CAAA;IACV,CAAA,IACL,IACA;;GAEJ,QAAQ,SAAS,IACjB,qBAAC,OAAD;IAAK,WAAW,GAAG,UAAU;cAA7B;KACC,oBAAC,OAAD;MAAK,WAAW,GAAG,UAAU;gBAAmB;KAAkB,CAAA;KACjE,gBACA,oBAAC,KAAD;MAAG,WAAW,GAAG,UAAU;gBAAa,EAAE,KAAK,iBAAiB;KAAK,CAAA,IAClE;KACJ,oBAAC,OAAD;MAAK,WAAW,GAAG,UAAU;gBAC3B,QAAQ,KAAK,WACb,oBAAC,UAAD;OACC,cAAY,OAAO;OACnB,gBAAc,OAAO,QAAQ,iBAAiB;OAC9C,WAAW,GAAG,UAAU,WAAW,UAAU;OAE7C,eAAe;QACd,aAAa,MAAM;QACnB,MAAM;OACP;OACA,OAAO,OAAO;OACd,MAAK;iBAEL,oBAAC,QAAD,EAAM,OAAO,EAAE,YAAY,iBAAiB,OAAO,KAAK,KAAK,KAAA,EAAU,EAAI,CAAA;MACpE,GATF,OAAO,GASL,CACR;KACG,CAAA;IACD;QACF;EACA;;AAEP"}
@@ -131,6 +131,29 @@ html[data-theme="dark"] .fields-color.error .fields-color__container:hover {
131
131
  filter: none;
132
132
  }
133
133
 
134
+ /* Clips the chip/input/badge run so fixed-size flex items can never escape the
135
+ container at narrow widths; the swatch and clear button stay outside it, so
136
+ the clear control keeps its place at the right edge. The fade is a mask, not
137
+ a background-colored gradient overlay, so it stays correct over every
138
+ container background (error, read-only, hover transitions, both themes).
139
+ The modifier is toggled from a measured scrollWidth overflow, never applied
140
+ statically: the badge always sits at the run's right edge, so a static mask
141
+ would fade it even with room to spare. */
142
+ .fields-color__content {
143
+ display: flex;
144
+ flex: 1 1 auto;
145
+ min-width: 0;
146
+ align-items: center;
147
+ gap: 7px;
148
+ height: 100%;
149
+ overflow: hidden;
150
+ }
151
+
152
+ .fields-color__content--fade {
153
+ -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
154
+ mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
155
+ }
156
+
134
157
  /* The sibling input's width: 100% basis would otherwise squeeze the chip to nothing;
135
158
  the max-width keeps runaway labels ellipsizing instead of overflowing */
136
159
  .fields-color__chip {
@@ -173,6 +196,13 @@ html[data-theme="dark"] .fields-color.error .fields-color__container:hover {
173
196
  text-overflow: ellipsis;
174
197
  }
175
198
 
199
+ .fields-color__chip-alpha {
200
+ flex-shrink: 0;
201
+ color: var(--theme-elevation-500);
202
+ font-size: 0.75rem;
203
+ line-height: 1;
204
+ }
205
+
176
206
  .fields-color__input {
177
207
  flex: 1 1 auto;
178
208
  width: 100%;