@prismora/elements 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (393) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +21 -2
  3. package/components.json +15600 -0
  4. package/custom-elements.json +56320 -0
  5. package/dist/base.d.ts +42 -0
  6. package/dist/base.js +62 -0
  7. package/dist/catalog.d.ts +33 -0
  8. package/dist/catalog.js +803 -0
  9. package/dist/components/accordion.d.ts +31 -0
  10. package/dist/components/accordion.js +63 -0
  11. package/dist/components/alert.d.ts +27 -0
  12. package/dist/components/alert.js +40 -0
  13. package/dist/components/avatar-group.d.ts +23 -0
  14. package/dist/components/avatar-group.js +43 -0
  15. package/dist/components/avatar.d.ts +24 -0
  16. package/dist/components/avatar.js +43 -0
  17. package/dist/components/back-to-top.d.ts +32 -0
  18. package/dist/components/back-to-top.js +50 -0
  19. package/dist/components/badge.d.ts +17 -0
  20. package/dist/components/badge.js +20 -0
  21. package/dist/components/banner.d.ts +34 -0
  22. package/dist/components/banner.js +54 -0
  23. package/dist/components/breadcrumb.d.ts +42 -0
  24. package/dist/components/breadcrumb.js +63 -0
  25. package/dist/components/button-group.d.ts +14 -0
  26. package/dist/components/button-group.js +28 -0
  27. package/dist/components/button.d.ts +59 -0
  28. package/dist/components/button.js +162 -0
  29. package/dist/components/calendar.d.ts +48 -0
  30. package/dist/components/calendar.js +296 -0
  31. package/dist/components/card.d.ts +23 -0
  32. package/dist/components/card.js +44 -0
  33. package/dist/components/carousel.d.ts +41 -0
  34. package/dist/components/carousel.js +156 -0
  35. package/dist/components/cascader.d.ts +70 -0
  36. package/dist/components/cascader.js +220 -0
  37. package/dist/components/chart.d.ts +59 -0
  38. package/dist/components/chart.js +267 -0
  39. package/dist/components/chat.d.ts +98 -0
  40. package/dist/components/chat.js +134 -0
  41. package/dist/components/checkbox-group.d.ts +48 -0
  42. package/dist/components/checkbox-group.js +111 -0
  43. package/dist/components/checkbox.d.ts +23 -0
  44. package/dist/components/checkbox.js +70 -0
  45. package/dist/components/code-block.d.ts +46 -0
  46. package/dist/components/code-block.js +86 -0
  47. package/dist/components/color-picker.d.ts +46 -0
  48. package/dist/components/color-picker.js +292 -0
  49. package/dist/components/combobox.d.ts +89 -0
  50. package/dist/components/combobox.js +384 -0
  51. package/dist/components/command.d.ts +96 -0
  52. package/dist/components/command.js +289 -0
  53. package/dist/components/context-menu.d.ts +23 -0
  54. package/dist/components/context-menu.js +110 -0
  55. package/dist/components/copy-button.d.ts +33 -0
  56. package/dist/components/copy-button.js +62 -0
  57. package/dist/components/countdown.d.ts +36 -0
  58. package/dist/components/countdown.js +56 -0
  59. package/dist/components/data-table.d.ts +180 -0
  60. package/dist/components/data-table.js +1060 -0
  61. package/dist/components/date-picker.d.ts +47 -0
  62. package/dist/components/date-picker.js +267 -0
  63. package/dist/components/description-list.d.ts +38 -0
  64. package/dist/components/description-list.js +41 -0
  65. package/dist/components/dialog.d.ts +47 -0
  66. package/dist/components/dialog.js +189 -0
  67. package/dist/components/divider.d.ts +16 -0
  68. package/dist/components/divider.js +23 -0
  69. package/dist/components/drawer.d.ts +19 -0
  70. package/dist/components/drawer.js +27 -0
  71. package/dist/components/editor.d.ts +50 -0
  72. package/dist/components/editor.js +474 -0
  73. package/dist/components/empty-state.d.ts +24 -0
  74. package/dist/components/empty-state.js +27 -0
  75. package/dist/components/file-upload.d.ts +56 -0
  76. package/dist/components/file-upload.js +176 -0
  77. package/dist/components/form-control.d.ts +69 -0
  78. package/dist/components/form-control.js +134 -0
  79. package/dist/components/form.d.ts +38 -0
  80. package/dist/components/form.js +161 -0
  81. package/dist/components/format-number.d.ts +37 -0
  82. package/dist/components/format-number.js +86 -0
  83. package/dist/components/icon.d.ts +34 -0
  84. package/dist/components/icon.js +47 -0
  85. package/dist/components/image.d.ts +44 -0
  86. package/dist/components/image.js +53 -0
  87. package/dist/components/indicator.d.ts +41 -0
  88. package/dist/components/indicator.js +65 -0
  89. package/dist/components/inline-edit.d.ts +45 -0
  90. package/dist/components/inline-edit.js +129 -0
  91. package/dist/components/input.d.ts +55 -0
  92. package/dist/components/input.js +186 -0
  93. package/dist/components/kbd.d.ts +15 -0
  94. package/dist/components/kbd.js +18 -0
  95. package/dist/components/list.d.ts +68 -0
  96. package/dist/components/list.js +180 -0
  97. package/dist/components/menu.d.ts +22 -0
  98. package/dist/components/menu.js +182 -0
  99. package/dist/components/menubar.d.ts +20 -0
  100. package/dist/components/menubar.js +120 -0
  101. package/dist/components/meter.d.ts +38 -0
  102. package/dist/components/meter.js +48 -0
  103. package/dist/components/nav.d.ts +91 -0
  104. package/dist/components/nav.js +228 -0
  105. package/dist/components/number-input.d.ts +26 -0
  106. package/dist/components/number-input.js +70 -0
  107. package/dist/components/pagination.d.ts +44 -0
  108. package/dist/components/pagination.js +94 -0
  109. package/dist/components/pin-input.d.ts +25 -0
  110. package/dist/components/pin-input.js +128 -0
  111. package/dist/components/popover.d.ts +23 -0
  112. package/dist/components/popover.js +140 -0
  113. package/dist/components/progress.d.ts +26 -0
  114. package/dist/components/progress.js +66 -0
  115. package/dist/components/pull-refresh.d.ts +41 -0
  116. package/dist/components/pull-refresh.js +101 -0
  117. package/dist/components/qr-code.d.ts +33 -0
  118. package/dist/components/qr-code.js +54 -0
  119. package/dist/components/radio-group.d.ts +37 -0
  120. package/dist/components/radio-group.js +82 -0
  121. package/dist/components/range-slider.d.ts +46 -0
  122. package/dist/components/range-slider.js +95 -0
  123. package/dist/components/rating.d.ts +38 -0
  124. package/dist/components/rating.js +80 -0
  125. package/dist/components/relative-time.d.ts +31 -0
  126. package/dist/components/relative-time.js +51 -0
  127. package/dist/components/scheduler.d.ts +84 -0
  128. package/dist/components/scheduler.js +187 -0
  129. package/dist/components/segmented.d.ts +58 -0
  130. package/dist/components/segmented.js +129 -0
  131. package/dist/components/select.d.ts +62 -0
  132. package/dist/components/select.js +140 -0
  133. package/dist/components/share-button.d.ts +37 -0
  134. package/dist/components/share-button.js +60 -0
  135. package/dist/components/signature.d.ts +54 -0
  136. package/dist/components/signature.js +152 -0
  137. package/dist/components/skeleton.d.ts +21 -0
  138. package/dist/components/skeleton.js +26 -0
  139. package/dist/components/slider.d.ts +31 -0
  140. package/dist/components/slider.js +80 -0
  141. package/dist/components/sortable.d.ts +22 -0
  142. package/dist/components/sortable.js +196 -0
  143. package/dist/components/sparkline.d.ts +28 -0
  144. package/dist/components/sparkline.js +46 -0
  145. package/dist/components/spinner.d.ts +16 -0
  146. package/dist/components/spinner.js +22 -0
  147. package/dist/components/splitter.d.ts +28 -0
  148. package/dist/components/splitter.js +89 -0
  149. package/dist/components/stat.d.ts +28 -0
  150. package/dist/components/stat.js +33 -0
  151. package/dist/components/steps.d.ts +53 -0
  152. package/dist/components/steps.js +91 -0
  153. package/dist/components/switch.d.ts +12 -0
  154. package/dist/components/switch.js +18 -0
  155. package/dist/components/table.d.ts +58 -0
  156. package/dist/components/table.js +96 -0
  157. package/dist/components/tabs.d.ts +62 -0
  158. package/dist/components/tabs.js +310 -0
  159. package/dist/components/tag.d.ts +32 -0
  160. package/dist/components/tag.js +58 -0
  161. package/dist/components/textarea.d.ts +25 -0
  162. package/dist/components/textarea.js +56 -0
  163. package/dist/components/theme-switch.d.ts +51 -0
  164. package/dist/components/theme-switch.js +85 -0
  165. package/dist/components/time-picker.d.ts +39 -0
  166. package/dist/components/time-picker.js +257 -0
  167. package/dist/components/timeline.d.ts +38 -0
  168. package/dist/components/timeline.js +56 -0
  169. package/dist/components/toaster.d.ts +25 -0
  170. package/dist/components/toaster.js +44 -0
  171. package/dist/components/toggle-group.d.ts +70 -0
  172. package/dist/components/toggle-group.js +172 -0
  173. package/dist/components/toolbar.d.ts +23 -0
  174. package/dist/components/toolbar.js +81 -0
  175. package/dist/components/tooltip.d.ts +18 -0
  176. package/dist/components/tooltip.js +92 -0
  177. package/dist/components/tour.d.ts +41 -0
  178. package/dist/components/tour.js +197 -0
  179. package/dist/components/transfer.d.ts +57 -0
  180. package/dist/components/transfer.js +161 -0
  181. package/dist/components/tree-select.d.ts +66 -0
  182. package/dist/components/tree-select.js +282 -0
  183. package/dist/components/tree.d.ts +129 -0
  184. package/dist/components/tree.js +427 -0
  185. package/dist/components/virtual-list.d.ts +41 -0
  186. package/dist/components/virtual-list.js +77 -0
  187. package/dist/confirm.d.ts +21 -0
  188. package/dist/confirm.js +69 -0
  189. package/dist/count.d.ts +5 -0
  190. package/dist/count.js +12 -0
  191. package/dist/data-table/icons.d.ts +8 -0
  192. package/dist/data-table/icons.js +10 -0
  193. package/dist/data-table/logic.d.ts +33 -0
  194. package/dist/data-table/logic.js +141 -0
  195. package/dist/data-table/strings.d.ts +37 -0
  196. package/dist/data-table/strings.js +36 -0
  197. package/dist/data-table/types.d.ts +76 -0
  198. package/dist/data-table/types.js +1 -0
  199. package/dist/define.d.ts +2 -0
  200. package/dist/define.js +2 -0
  201. package/dist/field-validity.d.ts +42 -0
  202. package/dist/field-validity.js +58 -0
  203. package/dist/floating.d.ts +13 -0
  204. package/dist/floating.js +65 -0
  205. package/dist/highlight.d.ts +11 -0
  206. package/dist/highlight.js +103 -0
  207. package/dist/id.d.ts +2 -0
  208. package/dist/id.js +3 -0
  209. package/dist/index.d.ts +102 -0
  210. package/dist/index.js +102 -0
  211. package/dist/manifest.d.ts +51 -0
  212. package/dist/manifest.js +11 -0
  213. package/dist/named-icon.d.ts +8 -0
  214. package/dist/named-icon.js +8 -0
  215. package/dist/patterns/account.d.ts +6 -0
  216. package/dist/patterns/account.js +137 -0
  217. package/dist/patterns/app.d.ts +7 -0
  218. package/dist/patterns/app.js +351 -0
  219. package/dist/patterns/commerce.d.ts +4 -0
  220. package/dist/patterns/commerce.js +200 -0
  221. package/dist/patterns/flows.d.ts +3 -0
  222. package/dist/patterns/flows.js +100 -0
  223. package/dist/patterns/index.d.ts +9 -0
  224. package/dist/patterns/index.js +29 -0
  225. package/dist/patterns/marketing.d.ts +4 -0
  226. package/dist/patterns/marketing.js +173 -0
  227. package/dist/patterns/more.d.ts +15 -0
  228. package/dist/patterns/more.js +581 -0
  229. package/dist/patterns/shell.d.ts +9 -0
  230. package/dist/patterns/shell.js +48 -0
  231. package/dist/patterns/types.d.ts +19 -0
  232. package/dist/patterns/types.js +1 -0
  233. package/dist/position.d.ts +2 -0
  234. package/dist/position.js +33 -0
  235. package/dist/prismora.standalone.js +5222 -0
  236. package/dist/prismora.standalone.js.map +199 -0
  237. package/dist/qr.d.ts +14 -0
  238. package/dist/qr.js +258 -0
  239. package/dist/register.d.ts +8 -0
  240. package/dist/register.js +21 -0
  241. package/dist/registry.d.ts +203 -0
  242. package/dist/registry.js +203 -0
  243. package/dist/remote.d.ts +58 -0
  244. package/dist/remote.js +130 -0
  245. package/dist/sheet.d.ts +34 -0
  246. package/dist/sheet.js +153 -0
  247. package/dist/styles/accordion.d.ts +2 -0
  248. package/dist/styles/accordion.js +3 -0
  249. package/dist/styles/alert.d.ts +2 -0
  250. package/dist/styles/alert.js +3 -0
  251. package/dist/styles/avatar.d.ts +2 -0
  252. package/dist/styles/avatar.js +3 -0
  253. package/dist/styles/badge.d.ts +2 -0
  254. package/dist/styles/badge.js +3 -0
  255. package/dist/styles/banner.d.ts +2 -0
  256. package/dist/styles/banner.js +3 -0
  257. package/dist/styles/breadcrumb.d.ts +2 -0
  258. package/dist/styles/breadcrumb.js +3 -0
  259. package/dist/styles/button.d.ts +2 -0
  260. package/dist/styles/button.js +3 -0
  261. package/dist/styles/calendar.d.ts +2 -0
  262. package/dist/styles/calendar.js +3 -0
  263. package/dist/styles/card.d.ts +2 -0
  264. package/dist/styles/card.js +3 -0
  265. package/dist/styles/carousel.d.ts +2 -0
  266. package/dist/styles/carousel.js +3 -0
  267. package/dist/styles/chart.d.ts +2 -0
  268. package/dist/styles/chart.js +3 -0
  269. package/dist/styles/chat.d.ts +2 -0
  270. package/dist/styles/chat.js +3 -0
  271. package/dist/styles/checkbox.d.ts +2 -0
  272. package/dist/styles/checkbox.js +3 -0
  273. package/dist/styles/color-picker.d.ts +2 -0
  274. package/dist/styles/color-picker.js +3 -0
  275. package/dist/styles/combobox.d.ts +2 -0
  276. package/dist/styles/combobox.js +3 -0
  277. package/dist/styles/command.d.ts +2 -0
  278. package/dist/styles/command.js +3 -0
  279. package/dist/styles/data-table.d.ts +2 -0
  280. package/dist/styles/data-table.js +3 -0
  281. package/dist/styles/description-list.d.ts +2 -0
  282. package/dist/styles/description-list.js +3 -0
  283. package/dist/styles/dialog.d.ts +2 -0
  284. package/dist/styles/dialog.js +3 -0
  285. package/dist/styles/drawer.d.ts +2 -0
  286. package/dist/styles/drawer.js +3 -0
  287. package/dist/styles/editor.d.ts +2 -0
  288. package/dist/styles/editor.js +3 -0
  289. package/dist/styles/empty-state.d.ts +2 -0
  290. package/dist/styles/empty-state.js +3 -0
  291. package/dist/styles/extras.d.ts +2 -0
  292. package/dist/styles/extras.js +3 -0
  293. package/dist/styles/field.d.ts +2 -0
  294. package/dist/styles/field.js +3 -0
  295. package/dist/styles/file-upload.d.ts +2 -0
  296. package/dist/styles/file-upload.js +3 -0
  297. package/dist/styles/foundation.d.ts +2 -0
  298. package/dist/styles/foundation.js +3 -0
  299. package/dist/styles/helpers.d.ts +2 -0
  300. package/dist/styles/helpers.js +3 -0
  301. package/dist/styles/icon.d.ts +2 -0
  302. package/dist/styles/icon.js +3 -0
  303. package/dist/styles/image.d.ts +2 -0
  304. package/dist/styles/image.js +3 -0
  305. package/dist/styles/indicator.d.ts +2 -0
  306. package/dist/styles/indicator.js +3 -0
  307. package/dist/styles/input.d.ts +2 -0
  308. package/dist/styles/input.js +3 -0
  309. package/dist/styles/kbd.d.ts +2 -0
  310. package/dist/styles/kbd.js +3 -0
  311. package/dist/styles/list.d.ts +2 -0
  312. package/dist/styles/list.js +3 -0
  313. package/dist/styles/listbox.d.ts +2 -0
  314. package/dist/styles/listbox.js +3 -0
  315. package/dist/styles/meter.d.ts +2 -0
  316. package/dist/styles/meter.js +3 -0
  317. package/dist/styles/nav.d.ts +2 -0
  318. package/dist/styles/nav.js +3 -0
  319. package/dist/styles/number-input.d.ts +2 -0
  320. package/dist/styles/number-input.js +3 -0
  321. package/dist/styles/overlay.d.ts +2 -0
  322. package/dist/styles/overlay.js +3 -0
  323. package/dist/styles/pagination.d.ts +2 -0
  324. package/dist/styles/pagination.js +3 -0
  325. package/dist/styles/pickers.d.ts +2 -0
  326. package/dist/styles/pickers.js +3 -0
  327. package/dist/styles/pin-input.d.ts +2 -0
  328. package/dist/styles/pin-input.js +3 -0
  329. package/dist/styles/popover.d.ts +2 -0
  330. package/dist/styles/popover.js +3 -0
  331. package/dist/styles/progress.d.ts +2 -0
  332. package/dist/styles/progress.js +3 -0
  333. package/dist/styles/pull-refresh.d.ts +2 -0
  334. package/dist/styles/pull-refresh.js +3 -0
  335. package/dist/styles/range-slider.d.ts +2 -0
  336. package/dist/styles/range-slider.js +3 -0
  337. package/dist/styles/rating.d.ts +2 -0
  338. package/dist/styles/rating.js +3 -0
  339. package/dist/styles/scheduler.d.ts +2 -0
  340. package/dist/styles/scheduler.js +3 -0
  341. package/dist/styles/segmented.d.ts +2 -0
  342. package/dist/styles/segmented.js +3 -0
  343. package/dist/styles/select.d.ts +2 -0
  344. package/dist/styles/select.js +3 -0
  345. package/dist/styles/separator.d.ts +2 -0
  346. package/dist/styles/separator.js +3 -0
  347. package/dist/styles/sheet.d.ts +2 -0
  348. package/dist/styles/sheet.js +3 -0
  349. package/dist/styles/skeleton.d.ts +2 -0
  350. package/dist/styles/skeleton.js +3 -0
  351. package/dist/styles/slider.d.ts +2 -0
  352. package/dist/styles/slider.js +3 -0
  353. package/dist/styles/sortable.d.ts +2 -0
  354. package/dist/styles/sortable.js +3 -0
  355. package/dist/styles/spinner.d.ts +2 -0
  356. package/dist/styles/spinner.js +3 -0
  357. package/dist/styles/splitter.d.ts +2 -0
  358. package/dist/styles/splitter.js +3 -0
  359. package/dist/styles/stat.d.ts +2 -0
  360. package/dist/styles/stat.js +3 -0
  361. package/dist/styles/steps.d.ts +2 -0
  362. package/dist/styles/steps.js +3 -0
  363. package/dist/styles/surface.d.ts +2 -0
  364. package/dist/styles/surface.js +3 -0
  365. package/dist/styles/switch.d.ts +2 -0
  366. package/dist/styles/switch.js +3 -0
  367. package/dist/styles/table.d.ts +2 -0
  368. package/dist/styles/table.js +3 -0
  369. package/dist/styles/tabs.d.ts +2 -0
  370. package/dist/styles/tabs.js +3 -0
  371. package/dist/styles/tag.d.ts +2 -0
  372. package/dist/styles/tag.js +3 -0
  373. package/dist/styles/time-picker.d.ts +2 -0
  374. package/dist/styles/time-picker.js +3 -0
  375. package/dist/styles/timeline.d.ts +2 -0
  376. package/dist/styles/timeline.js +3 -0
  377. package/dist/styles/toast.d.ts +2 -0
  378. package/dist/styles/toast.js +3 -0
  379. package/dist/styles/toggle.d.ts +2 -0
  380. package/dist/styles/toggle.js +3 -0
  381. package/dist/styles/toolbar.d.ts +2 -0
  382. package/dist/styles/toolbar.js +3 -0
  383. package/dist/styles/tooltip.d.ts +2 -0
  384. package/dist/styles/tooltip.js +3 -0
  385. package/dist/styles/tree.d.ts +2 -0
  386. package/dist/styles/tree.js +3 -0
  387. package/dist/table-core.d.ts +75 -0
  388. package/dist/table-core.js +205 -0
  389. package/dist/toast.d.ts +42 -0
  390. package/dist/toast.js +206 -0
  391. package/dist/top-layer.d.ts +4 -0
  392. package/dist/top-layer.js +33 -0
  393. package/package.json +101 -4
@@ -0,0 +1,292 @@
1
+ import { css, html, nothing } from 'lit';
2
+ import { ifDefined } from 'lit/directives/if-defined.js';
3
+ import { live } from 'lit/directives/live.js';
4
+ import { defineElement } from '../base.js';
5
+ import { attachBelow, hidePopup, showPopup } from '../floating.js';
6
+ import { enableSheetDrag } from '../sheet.js';
7
+ import sheetCss from '../styles/sheet.js';
8
+ import colorPickerCss from '../styles/color-picker.js';
9
+ import inputCss from '../styles/input.js';
10
+ import listboxCss from '../styles/listbox.js';
11
+ import { PmFormControl } from './form-control.js';
12
+ const clamp = (n, lo = 0, hi = 1) => Math.min(hi, Math.max(lo, n));
13
+ const hex2 = (n) => Math.round(clamp(n, 0, 255)).toString(16).padStart(2, '0');
14
+ /** Parse #rgb, #rgba, #rrggbb, #rrggbbaa, rgb()/rgba() into HSVA (0–360, 0–1). */
15
+ export function parseColor(input) {
16
+ let t = input.trim().toLowerCase();
17
+ let r, g, b, a = 1;
18
+ const m = t.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+%?))?\s*\)$/);
19
+ if (m) {
20
+ [r, g, b] = [+m[1], +m[2], +m[3]];
21
+ if (m[4])
22
+ a = m[4].endsWith('%') ? parseFloat(m[4]) / 100 : +m[4];
23
+ }
24
+ else {
25
+ if (!t.startsWith('#'))
26
+ t = `#${t}`;
27
+ if (!/^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/.test(t))
28
+ return undefined;
29
+ let h = t.slice(1);
30
+ if (h.length <= 4)
31
+ h = [...h].map((c) => c + c).join('');
32
+ [r, g, b] = [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
33
+ if (h.length === 8)
34
+ a = parseInt(h.slice(6, 8), 16) / 255;
35
+ }
36
+ r /= 255;
37
+ g /= 255;
38
+ b /= 255;
39
+ const max = Math.max(r, g, b);
40
+ const d = max - Math.min(r, g, b);
41
+ let hue = 0;
42
+ if (d)
43
+ hue = max === r ? ((g - b) / d) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
44
+ return { h: (hue * 60 + 360) % 360, s: max ? d / max : 0, v: max, a: clamp(a) };
45
+ }
46
+ export function hsvaToRgb({ h, s, v }) {
47
+ const f = (n) => { const k = (n + h / 60) % 6; return v - v * s * Math.max(0, Math.min(k, 4 - k, 1)); };
48
+ return [f(5) * 255, f(3) * 255, f(1) * 255];
49
+ }
50
+ /** "#rrggbb", or "#rrggbbaa" when alpha < 1. */
51
+ export function toHex(c) {
52
+ const [r, g, b] = hsvaToRgb(c);
53
+ return `#${hex2(r)}${hex2(g)}${hex2(b)}${c.a < 1 ? hex2(c.a * 255) : ''}`;
54
+ }
55
+ /**
56
+ * Colour picker: a swatch + hex field with a popup (or `inline` panel) holding a saturation/brightness area, hue and
57
+ * optional `alpha` sliders, preset `swatches` and the EyeDropper where supported.
58
+ *
59
+ * Value is "#rrggbb" ("#rrggbbaa" with alpha) and is submitted with forms. Keys on the area: arrows ±1%, Shift ±10%.
60
+ * @attr {boolean} mobile - Native mobile pattern on phones: opens as a swipeable bottom sheet (inherits from ancestors such as `<html mobile>`; `mobile="false"` opts out).
61
+ * @tag pm-color-picker
62
+ * @example <pm-color-picker label="Brand colour" value="#7c5cff" swatches="#7c5cff,#0ea5e9,#22c55e,#f59e0b,#ef4444"></pm-color-picker>
63
+ */
64
+ export class PmColorPicker extends PmFormControl {
65
+ static { this.componentName = 'color-picker'; }
66
+ static { this.styles = [...PmFormControl.styles, inputCss, listboxCss, sheetCss, colorPickerCss, css `
67
+ .pm-input-group > .pm-input { padding-inline-start: 2.75rem; font-family: var(--pm-font-mono); text-transform: lowercase; }
68
+ .swatch-btn { position: absolute; inset-inline-start: .375rem; }
69
+ .popup { padding: var(--pm-space-3); }
70
+ .popup[data-sheet] { padding: 1.75rem var(--pm-space-4) max(var(--pm-space-4), var(--pm-safe-bottom, 0px)); }
71
+ .popup[data-sheet]:popover-open { display: grid; justify-items: center; }
72
+ `]; }
73
+ static { this.properties = {
74
+ alpha: { type: Boolean }, inline: { type: Boolean, reflect: true }, swatches: {}, placeholder: {},
75
+ _open: { state: true }, _hsva: { state: true }, _text: { state: true },
76
+ }; }
77
+ #detach;
78
+ #dragging = false;
79
+ constructor() { super(); this.alpha = false; this.inline = false; this._open = false; this._hsva = { h: 0, s: 0, v: 0, a: 1 }; }
80
+ get #swatchList() {
81
+ const s = this.swatches;
82
+ if (!s)
83
+ return [];
84
+ if (Array.isArray(s))
85
+ return s;
86
+ try {
87
+ const j = JSON.parse(s);
88
+ if (Array.isArray(j))
89
+ return j;
90
+ }
91
+ catch { /* comma list */ }
92
+ return s.split(',').map((x) => x.trim()).filter(Boolean);
93
+ }
94
+ willUpdate(changed) {
95
+ super.willUpdate(changed);
96
+ if (changed.has('value') && !this.#dragging) {
97
+ const c = parseColor(this.value);
98
+ if (c && toHex(c) !== toHex(this._hsva))
99
+ this._hsva = this.alpha ? c : { ...c, a: 1 };
100
+ }
101
+ }
102
+ syncValidity() {
103
+ const c = this.control;
104
+ if (!c)
105
+ return;
106
+ if (this.error)
107
+ this.internals.setValidity({ customError: true }, this.error, c);
108
+ else if (this._text !== undefined && this._text.trim() && !parseColor(this._text))
109
+ this.internals.setValidity({ customError: true }, 'Enter a colour like #7c5cff.', c);
110
+ else if (this.required && !this.value)
111
+ this.internals.setValidity({ valueMissing: true }, 'Please choose a colour.', c);
112
+ else
113
+ this.internals.setValidity({});
114
+ }
115
+ #set(c, commit) {
116
+ this._hsva = c;
117
+ const hex = toHex(this.alpha ? c : { ...c, a: 1 });
118
+ this._text = undefined;
119
+ if (hex !== this.value) {
120
+ this.value = hex;
121
+ this.emit('pm-input', { value: hex });
122
+ }
123
+ if (commit)
124
+ this.emit('pm-change', { value: this.value });
125
+ }
126
+ #commitText() {
127
+ if (this._text === undefined)
128
+ return;
129
+ const c = parseColor(this._text);
130
+ if (c)
131
+ this.#set(this.alpha ? c : { ...c, a: 1 }, true);
132
+ else if (!this._text.trim() && this.value) {
133
+ this.value = '';
134
+ this._text = undefined;
135
+ this.emit('pm-change', { value: '' });
136
+ }
137
+ }
138
+ open() { if (!this.disabled && !this.readonly && !this.inline)
139
+ this._open = true; }
140
+ close(focus = false) { this._open = false; if (focus)
141
+ this.control?.focus(); }
142
+ updated(changed) {
143
+ super.updated(changed);
144
+ if (this.inline)
145
+ return;
146
+ const popup = this.renderRoot.querySelector('.popup');
147
+ const anchor = this.renderRoot.querySelector('.pm-input-group');
148
+ if (!popup || !anchor)
149
+ return;
150
+ if (this._open) {
151
+ showPopup(popup);
152
+ if (!this.#detach) {
153
+ const off = attachBelow(popup, anchor, { matchWidth: false, sheet: true });
154
+ const drag = enableSheetDrag(popup, () => this.close(true));
155
+ this.#detach = () => { off(); drag(); };
156
+ }
157
+ if (changed.has('_open'))
158
+ this.updateComplete.then(() => this.renderRoot.querySelector('.pm-color-area-thumb')?.focus());
159
+ }
160
+ else {
161
+ this.#detach?.();
162
+ this.#detach = undefined;
163
+ hidePopup(popup);
164
+ }
165
+ }
166
+ disconnectedCallback() { super.disconnectedCallback(); this.#detach?.(); }
167
+ #areaPointer(e) {
168
+ if (this.disabled || this.readonly)
169
+ return;
170
+ const area = e.currentTarget;
171
+ const move = (ev) => {
172
+ const r = area.getBoundingClientRect();
173
+ this.#set({ ...this._hsva, s: clamp((ev.clientX - r.left) / r.width), v: clamp(1 - (ev.clientY - r.top) / r.height) }, false);
174
+ };
175
+ area.setPointerCapture(e.pointerId);
176
+ this.#dragging = true;
177
+ move(e);
178
+ const up = () => {
179
+ this.#dragging = false;
180
+ area.removeEventListener('pointermove', move);
181
+ area.removeEventListener('pointerup', up);
182
+ area.removeEventListener('pointercancel', up);
183
+ this.emit('pm-change', { value: this.value });
184
+ };
185
+ area.addEventListener('pointermove', move);
186
+ area.addEventListener('pointerup', up);
187
+ area.addEventListener('pointercancel', up);
188
+ area.querySelector('.pm-color-area-thumb')?.focus();
189
+ }
190
+ #areaKey(e) {
191
+ const step = e.shiftKey ? 0.1 : 0.01;
192
+ const rtl = getComputedStyle(this).direction === 'rtl';
193
+ const c = { ...this._hsva };
194
+ if (e.key === 'ArrowRight')
195
+ c.s = clamp(c.s + (rtl ? -step : step));
196
+ else if (e.key === 'ArrowLeft')
197
+ c.s = clamp(c.s - (rtl ? -step : step));
198
+ else if (e.key === 'ArrowUp')
199
+ c.v = clamp(c.v + step);
200
+ else if (e.key === 'ArrowDown')
201
+ c.v = clamp(c.v - step);
202
+ else if (e.key === 'Enter' && !this.inline) {
203
+ e.preventDefault();
204
+ this.close(true);
205
+ return;
206
+ }
207
+ else
208
+ return;
209
+ e.preventDefault();
210
+ this.#set(c, true);
211
+ }
212
+ async #eyedrop() {
213
+ const ED = globalThis.EyeDropper;
214
+ if (!ED)
215
+ return;
216
+ try {
217
+ const r = await new ED().open();
218
+ const c = parseColor(r.sRGBHex);
219
+ if (c)
220
+ this.#set({ ...c, a: this._hsva.a }, true);
221
+ }
222
+ catch { /* cancelled */ }
223
+ }
224
+ #panel() {
225
+ const c = this._hsva;
226
+ const [r, g, b] = hsvaToRgb(c);
227
+ const solid = `rgb(${Math.round(r)} ${Math.round(g)} ${Math.round(b)})`;
228
+ const hasEye = typeof globalThis.EyeDropper === 'function';
229
+ const sw = this.#swatchList;
230
+ const dis = this.disabled || this.readonly;
231
+ return html `<div class="pm-color-panel" part="panel">
232
+ <div class="pm-color-area" part="area" style=${`--_hue: ${Math.round(c.h)}`} @pointerdown=${this.#areaPointer}>
233
+ <span class="pm-color-area-thumb" role="slider" tabindex=${dis ? -1 : 0} aria-label="Saturation and brightness"
234
+ aria-valuetext=${`Saturation ${Math.round(c.s * 100)}%, brightness ${Math.round(c.v * 100)}%`}
235
+ aria-valuenow=${Math.round(c.s * 100)} aria-valuemin="0" aria-valuemax="100" aria-disabled=${dis ? 'true' : nothing}
236
+ style=${`left: ${c.s * 100}%; top: ${(1 - c.v) * 100}%; background: ${solid}`} @keydown=${this.#areaKey}></span>
237
+ </div>
238
+ <div class="pm-color-sliders">
239
+ ${hasEye ? html `<button type="button" class="pm-input-action" aria-label="Pick a colour from the screen" ?disabled=${dis} @click=${this.#eyedrop}>
240
+ <svg viewBox="0 0 24 24" width="1.1em" height="1.1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m2 22 1-1h3l9-9M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3l.4.4Z"/></svg></button>` : nothing}
241
+ <div class="pm-color-tracks">
242
+ <input type="range" class="pm-color-hue" aria-label="Hue" min="0" max="360" step="1" .value=${live(String(Math.round(c.h)))} ?disabled=${dis}
243
+ @input=${(e) => this.#set({ ...this._hsva, h: +e.target.value }, false)}
244
+ @change=${() => this.emit('pm-change', { value: this.value })} />
245
+ ${this.alpha ? html `<input type="range" class="pm-color-alpha" aria-label="Opacity" min="0" max="100" step="1" style=${`--_solid: ${solid}`}
246
+ .value=${live(String(Math.round(c.a * 100)))} ?disabled=${dis} aria-valuetext=${`${Math.round(c.a * 100)}%`}
247
+ @input=${(e) => this.#set({ ...this._hsva, a: +e.target.value / 100 }, false)}
248
+ @change=${() => this.emit('pm-change', { value: this.value })} />` : nothing}
249
+ </div>
250
+ <span class="pm-color-preview" style=${`--_c: ${this.value || 'transparent'}`} aria-hidden="true"></span>
251
+ </div>
252
+ ${sw.length ? html `<div class="pm-color-swatches" role="group" aria-label="Preset colours">${sw.map((s) => html `<button type="button" class="pm-color-swatch"
253
+ style=${`--_c: ${s}`} aria-label=${s} aria-pressed=${s.toLowerCase() === this.value.toLowerCase() ? 'true' : 'false'} ?disabled=${dis}
254
+ @click=${() => { const p = parseColor(s); if (p)
255
+ this.#set(this.alpha ? p : { ...p, a: 1 }, true); }}></button>`)}</div>` : nothing}
256
+ </div>`;
257
+ }
258
+ render() {
259
+ const field = html `<div class="pm-input-group">
260
+ <button type="button" class="pm-color-swatch swatch-btn" part="trigger" style=${`--_c: ${this.value || 'transparent'}`}
261
+ aria-label=${this.inline ? 'Current colour' : 'Open colour picker'} aria-haspopup=${this.inline ? nothing : 'dialog'} aria-expanded=${this.inline ? nothing : this._open ? 'true' : 'false'}
262
+ ?disabled=${this.disabled || this.readonly} tabindex=${this.inline ? -1 : 0} @click=${() => (this._open ? this.close() : this.open())}></button>
263
+ <input data-control part="control" class="pm-input" id=${this.controlId} type="text" autocomplete="off" spellcheck="false"
264
+ .value=${live(this._text ?? this.value)} placeholder=${ifDefined(this.placeholder ?? '#000000')} maxlength="32"
265
+ data-size=${ifDefined(this.size)} ?required=${this.required} ?disabled=${this.disabled} ?readonly=${this.readonly}
266
+ aria-invalid=${this.showInvalid ? 'true' : nothing} aria-describedby=${ifDefined(this.describedBy())}
267
+ @input=${(e) => { this._text = e.target.value; }} @change=${() => this.#commitText()}
268
+ @blur=${() => { this.#commitText(); this.onBlur(); }}
269
+ @keydown=${(e) => { if (e.key === 'Enter')
270
+ this.#commitText();
271
+ else if (e.key === 'ArrowDown' && e.altKey) {
272
+ e.preventDefault();
273
+ this.open();
274
+ } }} />
275
+ </div>`;
276
+ if (this.inline)
277
+ return this.field(html `${this.#panel()}${field}`);
278
+ return this.field(html `${field}
279
+ <div class="pm-listbox-popup popup" popover="manual" part="popup" role="dialog" aria-label=${this.label ? `Choose ${this.label}` : 'Choose colour'}
280
+ @keydown=${(e) => { if (e.key === 'Escape') {
281
+ e.preventDefault();
282
+ e.stopPropagation();
283
+ this.close(true);
284
+ } }}
285
+ @focusout=${(e) => { const t = e.relatedTarget; if (t && (this.renderRoot.contains(t) || this.contains(t)))
286
+ return; requestAnimationFrame(() => { if (this.getRootNode().activeElement !== this)
287
+ this.close(); }); }}>
288
+ ${this._open ? this.#panel() : nothing}
289
+ </div>`);
290
+ }
291
+ }
292
+ defineElement('pm-color-picker', PmColorPicker);
@@ -0,0 +1,89 @@
1
+ import { type PropertyDeclarations, type PropertyValues } from 'lit';
2
+ import { type Loader } from '../remote.js';
3
+ import { PmFormControl } from './form-control.js';
4
+ export interface ComboboxOption {
5
+ value: string;
6
+ label: string;
7
+ /** Secondary text shown at the end of the row. */
8
+ description?: string;
9
+ /** Group heading. */
10
+ group?: string;
11
+ disabled?: boolean;
12
+ }
13
+ /** Loader for server-side search: return options, or raw items that `mapOption` / the `*-key` attributes turn into options. */
14
+ export type ComboboxLoader = Loader<string, unknown>;
15
+ /**
16
+ * Combobox / autocomplete: a searchable select.
17
+ *
18
+ * Single or `multiple` (selections become tags), `creatable` entries, `clearable` and grouped options. Options come
19
+ * from child `<option>` / `<optgroup>` elements or the `options` property. Keyboard: ↓/↑ move, Enter selects, Esc
20
+ * closes, Backspace removes the last tag.
21
+ *
22
+ * Server-side search: set `src` to a URL template (`src="/api/users?q={query}"`) and say where the list is in the
23
+ * JSON (`options-path="data"`) and which fields to use (`value-key="id" label-key="name"`), or set the `loader`
24
+ * property to your own `async (query, { signal }) => items` and optionally `mapOption` to format each item.
25
+ * Requests are debounced (`debounce`, default 250 ms), start after `min-chars` characters, cancel when superseded,
26
+ * and show loading, empty and error (with Retry) states. Selected values keep their labels across searches.
27
+ * Without either, you can still filter yourself: `filter="none"`, listen for `pm-search` and set `options`.
28
+ * @tag pm-combobox
29
+ * @fires pm-search - The query changed. detail: { query }
30
+ * @fires pm-create - A new entry was created (with `creatable`). detail: { value }
31
+ * @fires pm-load - Server results arrived. detail: { query, options }
32
+ * @fires pm-load-error - A server search failed. detail: { query, error }
33
+ * @example <pm-combobox label="Country" placeholder="Search…"><option value="de">Germany</option><option value="fr">France</option><option value="jp">Japan</option></pm-combobox>
34
+ */
35
+ export declare class PmCombobox extends PmFormControl {
36
+ #private;
37
+ static componentName: string;
38
+ static styles: import("lit").CSSResult[];
39
+ static properties: PropertyDeclarations;
40
+ /** Options (alternative to child `<option>` elements). */
41
+ options: ComboboxOption[];
42
+ /** Selected values with `multiple`. */
43
+ values: string[];
44
+ multiple: boolean;
45
+ placeholder?: string;
46
+ /** Offer "Create …" for queries that match nothing. */
47
+ creatable: boolean;
48
+ /** Show a button that clears the value. */
49
+ clearable: boolean;
50
+ /** `contains` (default), `starts-with`, or `none` (you filter, e.g. server-side on pm-search). */
51
+ filter: 'contains' | 'starts-with' | 'none';
52
+ /** Show a loading row (async search). */
53
+ loading: boolean;
54
+ emptyText: string;
55
+ /** Search URL; `{query}` is replaced with the URL-encoded text (e.g. `/api/users?q={query}`). Response: JSON. */
56
+ src?: string;
57
+ /** Your own search function (takes precedence over `src`): `async (query, { signal }) => items`. */
58
+ loader?: ComboboxLoader;
59
+ /** Turn one server item into an option (default: read the `*-key` fields; strings become value and label). */
60
+ mapOption?: (item: unknown) => ComboboxOption;
61
+ /** Where the list is in the response, as a dotted path (e.g. `data.items`); empty = the response itself. */
62
+ optionsPath?: string;
63
+ /** Item field for the value (default `value`, then `id`). */
64
+ valueKey?: string;
65
+ /** Item field for the label (default `label`, then `name`, then `title`). */
66
+ labelKey?: string;
67
+ /** Item field for the secondary text (default `description`). */
68
+ descriptionKey?: string;
69
+ /** Item field for the group heading (default `group`). */
70
+ groupKey?: string;
71
+ /** Milliseconds to wait after typing before searching the server. */
72
+ debounce: number;
73
+ /** Characters needed before searching the server (0 = load as soon as it opens). */
74
+ minChars: number;
75
+ _open: boolean;
76
+ _query: string;
77
+ _active: number;
78
+ _typing: boolean;
79
+ /** Search the server now (e.g. after changing `src`). */
80
+ search(query?: string): void;
81
+ constructor();
82
+ connectedCallback(): void;
83
+ disconnectedCallback(): void;
84
+ formResetCallback(): void;
85
+ protected syncFormValue(): void;
86
+ protected syncValidity(): void;
87
+ protected updated(changed: PropertyValues<this>): void;
88
+ render(): import("lit").TemplateResult<1>;
89
+ }