@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,257 @@
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 inputCss from '../styles/input.js';
9
+ import listboxCss from '../styles/listbox.js';
10
+ import timePickerCss from '../styles/time-picker.js';
11
+ import { PmFormControl } from './form-control.js';
12
+ const pad = (n) => String(n).padStart(2, '0');
13
+ /** Parse "14:30", "2:30 pm", "1430", "9" into "HH:MM" (24 h), or undefined. */
14
+ export function parseTime(text) {
15
+ const t = text.trim().toLowerCase().replace(/\./g, '');
16
+ const m = t.match(/^(\d{1,2})(?::?(\d{2}))?\s*([ap])?m?$/);
17
+ if (!m)
18
+ return undefined;
19
+ let h = +m[1];
20
+ const min = m[2] ? +m[2] : 0;
21
+ if (m[3]) {
22
+ if (h < 1 || h > 12)
23
+ return undefined;
24
+ h = (h % 12) + (m[3] === 'p' ? 12 : 0);
25
+ }
26
+ if (h > 23 || min > 59)
27
+ return undefined;
28
+ return `${pad(h)}:${pad(min)}`;
29
+ }
30
+ /**
31
+ * Time picker: type a time ("14:30", "2:30 pm") or pick hours and minutes from a popup.
32
+ *
33
+ * 12/24-hour display follows the locale (override with `hour-cycle`).
34
+ * Value is always "HH:MM" (24 h) and is submitted with forms. Columns are listboxes: ↑/↓ move, Enter picks, ←/→
35
+ * switch column, Esc closes.
36
+ * @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).
37
+ * @tag pm-time-picker
38
+ * @example <pm-time-picker label="Start time" value="09:30" step="15"></pm-time-picker>
39
+ */
40
+ export class PmTimePicker extends PmFormControl {
41
+ static { this.componentName = 'time-picker'; }
42
+ static { this.styles = [...PmFormControl.styles, inputCss, listboxCss, sheetCss, timePickerCss, css `
43
+ .pm-input-group > .pm-input { padding-inline-end: var(--pm-control-height-md); }
44
+ .trigger { position: absolute; inset-inline-end: var(--pm-space-1); }
45
+ .popup { padding: var(--pm-space-2); }
46
+ .popup[data-sheet] { padding: 1.75rem var(--pm-space-4) max(var(--pm-space-4), var(--pm-safe-bottom, 0px)); }
47
+ .popup[data-sheet]:popover-open { display: grid; justify-items: center; }
48
+ `]; }
49
+ static { this.properties = {
50
+ min: {}, max: {}, step: { type: Number }, locale: {}, hourCycle: { attribute: 'hour-cycle' }, placeholder: {},
51
+ _open: { state: true }, _text: { state: true },
52
+ }; }
53
+ #detach;
54
+ constructor() { super(); this.step = 5; this._open = false; }
55
+ get #locale() { return this.locale || this.closest('[lang]')?.getAttribute('lang') || navigator.language || 'en-US'; }
56
+ get #h12() {
57
+ if (this.hourCycle)
58
+ return this.hourCycle === '12';
59
+ return new Intl.DateTimeFormat(this.#locale, { hour: 'numeric' }).resolvedOptions().hour12 ?? false;
60
+ }
61
+ #fmt(v) {
62
+ if (!v || !parseTime(v))
63
+ return '';
64
+ const [h, m] = v.split(':').map(Number);
65
+ return new Intl.DateTimeFormat(this.#locale, { hour: 'numeric', minute: '2-digit', hour12: this.#h12, timeZone: 'UTC' }).format(new Date(Date.UTC(2000, 0, 1, h, m)));
66
+ }
67
+ #out(v) { return (!!this.min && v < this.min) || (!!this.max && v > this.max); }
68
+ syncValidity() {
69
+ const c = this.control;
70
+ if (!c)
71
+ return;
72
+ let msg = '';
73
+ if (this.error)
74
+ msg = this.error;
75
+ else if (this._text !== undefined && this._text.trim() && !parseTime(this._text))
76
+ msg = 'Enter a valid time.';
77
+ else if (this.value && this.#out(this.value))
78
+ msg = `Choose a time between ${this.#fmt(this.min) || '…'} and ${this.#fmt(this.max) || '…'}.`;
79
+ if (msg)
80
+ this.internals.setValidity({ customError: true }, msg, c);
81
+ else if (this.required && !this.value)
82
+ this.internals.setValidity({ valueMissing: true }, 'Please choose a time.', c);
83
+ else
84
+ this.internals.setValidity({});
85
+ }
86
+ #set(v) {
87
+ this._text = undefined;
88
+ if (v !== this.value) {
89
+ this.value = v;
90
+ this.emit('pm-change', { value: v });
91
+ }
92
+ }
93
+ #commitText() {
94
+ if (this._text === undefined)
95
+ return;
96
+ const t = this._text.trim();
97
+ if (!t) {
98
+ this._text = undefined;
99
+ if (this.value)
100
+ this.#set('');
101
+ return;
102
+ }
103
+ const v = parseTime(t);
104
+ if (v)
105
+ this.#set(v);
106
+ }
107
+ open() { if (!this.disabled && !this.readonly)
108
+ this._open = true; }
109
+ close(focus = false) { this._open = false; if (focus)
110
+ this.control?.focus(); }
111
+ updated(changed) {
112
+ super.updated(changed);
113
+ const popup = this.renderRoot.querySelector('.popup');
114
+ const anchor = this.renderRoot.querySelector('.pm-input-group');
115
+ if (!popup || !anchor)
116
+ return;
117
+ if (this._open) {
118
+ showPopup(popup);
119
+ if (!this.#detach) {
120
+ const off = attachBelow(popup, anchor, { matchWidth: false, sheet: true });
121
+ const drag = enableSheetDrag(popup, () => this.close(true));
122
+ this.#detach = () => { off(); drag(); };
123
+ }
124
+ if (changed.has('_open'))
125
+ this.updateComplete.then(() => {
126
+ for (const col of this.renderRoot.querySelectorAll('.pm-time-col'))
127
+ col.querySelector('[aria-selected="true"]')?.scrollIntoView({ block: 'center' });
128
+ this.renderRoot.querySelector('.pm-time-col [tabindex="0"]')?.focus({ preventScroll: true });
129
+ });
130
+ }
131
+ else {
132
+ this.#detach?.();
133
+ this.#detach = undefined;
134
+ hidePopup(popup);
135
+ }
136
+ }
137
+ disconnectedCallback() { super.disconnectedCallback(); this.#detach?.(); }
138
+ /** Current parts, defaulting to now rounded to the step. */
139
+ #parts() {
140
+ let v = this.value;
141
+ if (!parseTime(v)) {
142
+ const n = new Date();
143
+ v = `${pad(n.getHours())}:${pad(Math.floor(n.getMinutes() / this.step) * this.step % 60)}`;
144
+ }
145
+ const [h, m] = v.split(':').map(Number);
146
+ return { h, m };
147
+ }
148
+ #pick(kind, n) {
149
+ const { h, m } = this.#parts();
150
+ let nh = h;
151
+ let nm = m;
152
+ if (kind === 'h')
153
+ nh = this.#h12 ? (n % 12) + (h >= 12 ? 12 : 0) : n;
154
+ else if (kind === 'm')
155
+ nm = n;
156
+ else
157
+ nh = (h % 12) + (n ? 12 : 0);
158
+ this.#set(`${pad(nh)}:${pad(nm)}`);
159
+ }
160
+ #colKey(e) {
161
+ const col = e.currentTarget;
162
+ const opts = [...col.querySelectorAll('[role="option"]:not([aria-disabled="true"])')];
163
+ const i = opts.indexOf(this.renderRoot.activeElement ?? e.target);
164
+ const cols = [...this.renderRoot.querySelectorAll('.pm-time-col')];
165
+ const ci = cols.indexOf(col);
166
+ const rtl = getComputedStyle(this).direction === 'rtl';
167
+ const focusIn = (el) => { if (!el)
168
+ return; for (const o of col.querySelectorAll('[role="option"]'))
169
+ o.tabIndex = -1; el.tabIndex = 0; el.focus(); el.scrollIntoView({ block: 'nearest' }); };
170
+ if (e.key === 'ArrowDown') {
171
+ e.preventDefault();
172
+ focusIn(opts[Math.min(opts.length - 1, i + 1)]);
173
+ }
174
+ else if (e.key === 'ArrowUp') {
175
+ e.preventDefault();
176
+ focusIn(opts[Math.max(0, i - 1)]);
177
+ }
178
+ else if (e.key === 'Home') {
179
+ e.preventDefault();
180
+ focusIn(opts[0]);
181
+ }
182
+ else if (e.key === 'End') {
183
+ e.preventDefault();
184
+ focusIn(opts[opts.length - 1]);
185
+ }
186
+ else if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
187
+ e.preventDefault();
188
+ const next = cols[ci + ((e.key === 'ArrowRight') !== rtl ? 1 : -1)];
189
+ (next?.querySelector('[tabindex="0"]') ?? next?.querySelector('[role="option"]'))?.focus();
190
+ }
191
+ else if (e.key === 'Enter' || e.key === ' ') {
192
+ e.preventDefault();
193
+ e.target.click();
194
+ if (e.key === 'Enter')
195
+ this.close(true);
196
+ }
197
+ }
198
+ #popup() {
199
+ const { h, m } = this.#parts();
200
+ const h12 = this.#h12;
201
+ const hours = h12 ? [12, ...Array.from({ length: 11 }, (_, i) => i + 1)] : Array.from({ length: 24 }, (_, i) => i);
202
+ const step = Math.min(60, Math.max(1, Math.floor(this.step) || 5));
203
+ const mins = Array.from({ length: Math.ceil(60 / step) }, (_, i) => i * step);
204
+ if (!mins.includes(m)) {
205
+ mins.push(m);
206
+ mins.sort((a, b) => a - b);
207
+ }
208
+ const pm = h >= 12;
209
+ const selH = h12 ? (h % 12 || 12) : h;
210
+ const toH24 = (hh) => (h12 ? (hh % 12) + (pm ? 12 : 0) : hh);
211
+ const hourDisabled = (hh) => { const H = toH24(hh); return (!!this.min && `${pad(H)}:59` < this.min) || (!!this.max && `${pad(H)}:00` > this.max); };
212
+ const minDisabled = (mm) => this.#out(`${pad(h)}:${pad(mm)}`);
213
+ const dp = new Intl.DateTimeFormat(this.#locale, { hour: 'numeric', hour12: true, timeZone: 'UTC' });
214
+ const dayPeriod = (H) => dp.formatToParts(new Date(Date.UTC(2000, 0, 1, H))).find((p) => p.type === 'dayPeriod')?.value ?? (H < 12 ? 'AM' : 'PM');
215
+ const col = (label, items, kind) => html `<div class="pm-time-col" role="listbox" aria-label=${label} @keydown=${this.#colKey}>
216
+ ${items.map((it) => html `<div role="option" class="pm-option" tabindex=${it.sel ? 0 : -1} aria-selected=${it.sel ? 'true' : 'false'} aria-disabled=${it.dis ? 'true' : nothing}
217
+ @click=${() => { if (!it.dis)
218
+ this.#pick(kind, it.n); }}>${it.text}</div>`)}
219
+ </div>`;
220
+ return html `<div class="pm-time-cols">
221
+ ${col('Hours', hours.map((hh) => ({ n: hh, text: h12 ? String(hh) : pad(hh), sel: hh === selH, dis: hourDisabled(hh) })), 'h')}
222
+ ${col('Minutes', mins.map((mm) => ({ n: mm, text: pad(mm), sel: mm === m, dis: minDisabled(mm) })), 'm')}
223
+ ${h12 ? col('AM or PM', [0, 1].map((p) => ({ n: p, text: dayPeriod(p ? 13 : 1), sel: p === (pm ? 1 : 0), dis: false })), 'p') : nothing}
224
+ </div>`;
225
+ }
226
+ render() {
227
+ return this.field(html `<div class="pm-input-group">
228
+ <input data-control part="control" class="pm-input" id=${this.controlId} type="text" autocomplete="off" inputmode="numeric"
229
+ .value=${live(this._text ?? this.#fmt(this.value))} placeholder=${ifDefined(this.placeholder ?? (this.#h12 ? 'h:mm AM' : 'hh:mm'))}
230
+ data-size=${ifDefined(this.size)} ?required=${this.required} ?disabled=${this.disabled} ?readonly=${this.readonly}
231
+ aria-invalid=${this.showInvalid ? 'true' : nothing} aria-describedby=${ifDefined(this.describedBy())} role="combobox" aria-haspopup="listbox" aria-expanded=${this._open ? 'true' : 'false'}
232
+ @input=${(e) => { this._text = e.target.value; }} @change=${() => this.#commitText()} @blur=${() => { this.#commitText(); this.onBlur(); }}
233
+ @keydown=${(e) => { if (e.key === 'ArrowDown' && e.altKey) {
234
+ e.preventDefault();
235
+ this.open();
236
+ }
237
+ else if (e.key === 'Enter')
238
+ this.#commitText(); }} />
239
+ <button type="button" class="pm-input-action trigger" part="trigger" aria-label="Choose time" ?disabled=${this.disabled || this.readonly}
240
+ @click=${() => (this._open ? this.close() : this.open())}>
241
+ <svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>
242
+ </button>
243
+ </div>
244
+ <div class="pm-listbox-popup popup" popover="manual" part="popup" role="dialog" aria-label=${this.label ? `Choose ${this.label}` : 'Choose time'}
245
+ @keydown=${(e) => { if (e.key === 'Escape') {
246
+ e.preventDefault();
247
+ e.stopPropagation();
248
+ this.close(true);
249
+ } }}
250
+ @focusout=${(e) => { const t = e.relatedTarget; if (t && (this.renderRoot.contains(t) || this.contains(t)))
251
+ return; requestAnimationFrame(() => { if (this.getRootNode().activeElement !== this)
252
+ this.close(); }); }}>
253
+ ${this._open ? this.#popup() : nothing}
254
+ </div>`);
255
+ }
256
+ }
257
+ defineElement('pm-time-picker', PmTimePicker);
@@ -0,0 +1,38 @@
1
+ import { type PropertyDeclarations } from 'lit';
2
+ import { PmElement } from '../base.js';
3
+ /**
4
+ * Vertical timeline (activity feeds, order history, changelogs).
5
+ * @tag pm-timeline
6
+ * @slot - `pm-timeline-item` elements.
7
+ * @example <pm-timeline><pm-timeline-item heading="Order placed" time="09:12" tone="success"></pm-timeline-item><pm-timeline-item heading="Shipped" time="14:30">Tracking number sent by email.</pm-timeline-item></pm-timeline>
8
+ */
9
+ export declare class PmTimeline extends PmElement {
10
+ static componentName: string;
11
+ static styles: import("lit").CSSResult[];
12
+ static properties: PropertyDeclarations;
13
+ label?: string;
14
+ connectedCallback(): void;
15
+ updated(changed: Map<PropertyKey, unknown>): void;
16
+ render(): import("lit").TemplateResult<1>;
17
+ }
18
+ /**
19
+ * One entry in a `<pm-timeline>`: a heading, time and details.
20
+ * @tag pm-timeline-item
21
+ * @slot - Details.
22
+ * @slot icon - Icon inside the dot.
23
+ * @example <pm-timeline-item heading="Deployed" time="2 min ago" tone="success">Production is live.</pm-timeline-item>
24
+ */
25
+ export declare class PmTimelineItem extends PmElement {
26
+ static componentName: string;
27
+ static styles: import("lit").CSSResult[];
28
+ static properties: PropertyDeclarations;
29
+ /** Registered icon name (see `registerIcons`); an `icon` slot overrides it. */
30
+ icon?: string;
31
+ heading?: string;
32
+ /** Display time, e.g. "2 min ago". */
33
+ time?: string;
34
+ /** Machine-readable time for `<time datetime>`. */
35
+ datetime?: string;
36
+ connectedCallback(): void;
37
+ render(): import("lit").TemplateResult<1>;
38
+ }
@@ -0,0 +1,56 @@
1
+ import { css, html, nothing } from 'lit';
2
+ import { PmElement, defineElement } from '../base.js';
3
+ import timelineCss from '../styles/timeline.js';
4
+ import { namedIcon } from '../named-icon.js';
5
+ /**
6
+ * Vertical timeline (activity feeds, order history, changelogs).
7
+ * @tag pm-timeline
8
+ * @slot - `pm-timeline-item` elements.
9
+ * @example <pm-timeline><pm-timeline-item heading="Order placed" time="09:12" tone="success"></pm-timeline-item><pm-timeline-item heading="Shipped" time="14:30">Tracking number sent by email.</pm-timeline-item></pm-timeline>
10
+ */
11
+ export class PmTimeline extends PmElement {
12
+ static { this.componentName = 'timeline'; }
13
+ static { this.styles = [...PmElement.styles, timelineCss, css `:host { display: block; } [part='base'] { display: grid; margin: 0; padding: 0; }`]; }
14
+ static { this.properties = { label: {} }; }
15
+ connectedCallback() { super.connectedCallback(); this.setAttribute('role', 'list'); }
16
+ // The list's name belongs on the element with role="list" (an inner named element would sit between list and items).
17
+ updated(changed) {
18
+ super.updated?.(changed);
19
+ if (changed.has('label')) {
20
+ if (this.label)
21
+ this.setAttribute('aria-label', this.label);
22
+ else if (changed.get('label'))
23
+ this.removeAttribute('aria-label');
24
+ }
25
+ }
26
+ render() {
27
+ return html `<div part="base"><slot></slot></div>`;
28
+ }
29
+ }
30
+ /**
31
+ * One entry in a `<pm-timeline>`: a heading, time and details.
32
+ * @tag pm-timeline-item
33
+ * @slot - Details.
34
+ * @slot icon - Icon inside the dot.
35
+ * @example <pm-timeline-item heading="Deployed" time="2 min ago" tone="success">Production is live.</pm-timeline-item>
36
+ */
37
+ export class PmTimelineItem extends PmElement {
38
+ static { this.componentName = 'timeline-item'; }
39
+ static { this.styles = [...PmElement.styles, timelineCss, css `:host { display: block; } .pm-timeline-item { padding-block-end: var(--pm-space-5); } .pm-timeline-item::before { display: block; } :host(:last-of-type) .pm-timeline-item { padding-block-end: 0; } :host(:last-of-type) .pm-timeline-item::before { display: none; }`]; }
40
+ static { this.properties = { icon: { reflect: true }, heading: {}, time: {}, datetime: {} }; }
41
+ connectedCallback() { super.connectedCallback(); this.setAttribute('role', 'listitem'); }
42
+ render() {
43
+ return html `<div class="pm-timeline-item" part="base">
44
+ <span class="pm-timeline-dot" part="dot" ?data-empty=${!this.icon && !this.querySelector(':scope > [slot="icon"]')}><slot name="icon" @slotchange=${() => this.requestUpdate()}>${namedIcon(this.icon)}</slot></span>
45
+ <div class="pm-timeline-body">
46
+ <div class="pm-timeline-head">
47
+ <span part="heading">${this.heading}</span>
48
+ ${this.time ? html `<time datetime=${this.datetime ?? nothing}>${this.time}</time>` : nothing}
49
+ </div>
50
+ <div class="pm-timeline-content" part="content"><slot></slot></div>
51
+ </div>
52
+ </div>`;
53
+ }
54
+ }
55
+ defineElement('pm-timeline', PmTimeline);
56
+ defineElement('pm-timeline-item', PmTimelineItem);
@@ -0,0 +1,25 @@
1
+ import { SafeHTMLElement } from '../base.js';
2
+ import { type ToastOptions } from '../toast.js';
3
+ /**
4
+ * Where toasts appear and how many stack. Optional: `toast()` works without it.
5
+ *
6
+ * Optional: `toast()` creates a region on demand; add `<pm-toaster>` once to choose where toasts appear and how many
7
+ * stack. Any element with `data-toast` shows a toast when clicked (no JS needed): `data-toast="Saved"` or
8
+ * `data-toast='{"title":"Saved","tone":"success"}'`. In JS use `toast()`, `toast.success()`, `toast.error()`,
9
+ * `toast.promise()` and `toast.dismiss()` from `@prismora/elements/toast`. On phones toasts are centred and full
10
+ * width (top or bottom, following `position`) unless `keep-position` is set.
11
+ * @tag pm-toaster
12
+ * @attr {'top-start' | 'top-center' | 'top-end' | 'bottom-start' | 'bottom-center' | 'bottom-end'} position - Where toasts stack (default bottom-end).
13
+ * @attr {number} max - Most toasts shown at once; older ones leave first (default 4).
14
+ * @attr {boolean} keep-position - Keep `position` on phones instead of centring.
15
+ * @attr {string} label - Accessible name of the region (default "Notifications").
16
+ * @example <pm-toaster position="top-center" max="3"></pm-toaster>
17
+ * <pm-button data-toast='{"title":"Saved","tone":"success"}'>Save</pm-button>
18
+ */
19
+ export declare class PmToaster extends SafeHTMLElement {
20
+ #private;
21
+ connectedCallback(): void;
22
+ disconnectedCallback(): void;
23
+ /** Show a toast (same as the `toast()` function). */
24
+ show(opts: ToastOptions | string): () => void;
25
+ }
@@ -0,0 +1,44 @@
1
+ import { SafeHTMLElement, defineElement } from '../base.js';
2
+ import { toast } from '../toast.js';
3
+ /**
4
+ * Where toasts appear and how many stack. Optional: `toast()` works without it.
5
+ *
6
+ * Optional: `toast()` creates a region on demand; add `<pm-toaster>` once to choose where toasts appear and how many
7
+ * stack. Any element with `data-toast` shows a toast when clicked (no JS needed): `data-toast="Saved"` or
8
+ * `data-toast='{"title":"Saved","tone":"success"}'`. In JS use `toast()`, `toast.success()`, `toast.error()`,
9
+ * `toast.promise()` and `toast.dismiss()` from `@prismora/elements/toast`. On phones toasts are centred and full
10
+ * width (top or bottom, following `position`) unless `keep-position` is set.
11
+ * @tag pm-toaster
12
+ * @attr {'top-start' | 'top-center' | 'top-end' | 'bottom-start' | 'bottom-center' | 'bottom-end'} position - Where toasts stack (default bottom-end).
13
+ * @attr {number} max - Most toasts shown at once; older ones leave first (default 4).
14
+ * @attr {boolean} keep-position - Keep `position` on phones instead of centring.
15
+ * @attr {string} label - Accessible name of the region (default "Notifications").
16
+ * @example <pm-toaster position="top-center" max="3"></pm-toaster>
17
+ * <pm-button data-toast='{"title":"Saved","tone":"success"}'>Save</pm-button>
18
+ */
19
+ export class PmToaster extends SafeHTMLElement {
20
+ connectedCallback() {
21
+ this.setAttribute('role', 'region');
22
+ if (!this.hasAttribute('aria-label'))
23
+ this.setAttribute('aria-label', this.getAttribute('label') ?? 'Notifications');
24
+ document.addEventListener('click', this.#onClick);
25
+ }
26
+ disconnectedCallback() { document.removeEventListener('click', this.#onClick); }
27
+ #onClick = (e) => {
28
+ const t = e.target?.closest?.('[data-toast]');
29
+ if (!t)
30
+ return;
31
+ const raw = t.getAttribute('data-toast') ?? '';
32
+ let opts = raw;
33
+ if (raw.trim().startsWith('{')) {
34
+ try {
35
+ opts = JSON.parse(raw);
36
+ }
37
+ catch { /* plain text */ }
38
+ }
39
+ toast(opts);
40
+ };
41
+ /** Show a toast (same as the `toast()` function). */
42
+ show(opts) { return toast(opts); }
43
+ }
44
+ defineElement('pm-toaster', PmToaster);
@@ -0,0 +1,70 @@
1
+ import { type PropertyDeclarations } from 'lit';
2
+ import { PmElement } from '../base.js';
3
+ /**
4
+ * Toggle button group (text formatting, filters, view options).
5
+ *
6
+ * Single selection by default (click again to clear); `multiple` allows several. Value is the pressed toggles'
7
+ * values, comma-separated with `multiple`. Arrow keys move between toggles (roving tabindex), Space/Enter toggles.
8
+ * Form-associated.
9
+ * @tag pm-toggle-group
10
+ * @slot - `pm-toggle` elements.
11
+ * @fires pm-change - Pressed toggles changed. detail: { value, values }
12
+ * @example <pm-toggle-group label="Text style" multiple value="bold"><pm-toggle value="bold">B</pm-toggle><pm-toggle value="italic">I</pm-toggle></pm-toggle-group>
13
+ */
14
+ export declare class PmToggleGroup extends PmElement {
15
+ #private;
16
+ static componentName: string;
17
+ static formAssociated: boolean;
18
+ static styles: import("lit").CSSResult[];
19
+ static properties: PropertyDeclarations;
20
+ /** Pressed value(s); comma-separated with `multiple`. */
21
+ value: string;
22
+ name?: string;
23
+ /** Accessible name of the group. */
24
+ label?: string;
25
+ multiple: boolean;
26
+ /** Single mode: keep one toggle pressed (cannot clear). */
27
+ required: boolean;
28
+ size?: 'sm' | 'md' | 'lg';
29
+ variant?: 'outline' | 'ghost' | 'soft';
30
+ orientation?: 'horizontal' | 'vertical';
31
+ disabled: boolean;
32
+ /** Help text under the field, linked to it for screen readers. */
33
+ hint?: string;
34
+ /** Custom error message. Setting it marks the field invalid. */
35
+ error?: string;
36
+ constructor();
37
+ get values(): string[];
38
+ connectedCallback(): void;
39
+ formResetCallback(): void;
40
+ formStateRestoreCallback(v: string): void;
41
+ formDisabledCallback(d: boolean): void;
42
+ render(): import("lit").TemplateResult<1>;
43
+ protected updated(): void;
44
+ }
45
+ /**
46
+ * One toggle button (aria-pressed). Use inside `pm-toggle-group`, or standalone as an on/off button.
47
+ * @tag pm-toggle
48
+ * @slot - Label (text and/or icon). Icon-only toggles need `label`.
49
+ * @fires pm-change - Standalone toggle changed. detail: { pressed }
50
+ * @example <pm-toggle label="Bold"><pm-icon name="bold"></pm-icon></pm-toggle>
51
+ */
52
+ export declare class PmToggle extends PmElement {
53
+ #private;
54
+ static componentName: string;
55
+ static styles: import("lit").CSSResult[];
56
+ static properties: PropertyDeclarations;
57
+ value: string;
58
+ /** Accessible name for icon-only toggles. */
59
+ label?: string;
60
+ /** Whether the toggle is on. */
61
+ pressed: boolean;
62
+ disabled: boolean;
63
+ size?: 'sm' | 'md' | 'lg';
64
+ variant?: 'outline' | 'ghost' | 'soft';
65
+ groupDisabled: boolean;
66
+ constructor();
67
+ connectedCallback(): void;
68
+ protected updated(): void;
69
+ render(): import("lit").TemplateResult<1>;
70
+ }
@@ -0,0 +1,172 @@
1
+ import { css, html, nothing } from 'lit';
2
+ import { PmElement, defineElement } from '../base.js';
3
+ import { FieldValidity } from '../field-validity.js';
4
+ import fieldCss from '../styles/field.js';
5
+ import toggleCss from '../styles/toggle.js';
6
+ /**
7
+ * Toggle button group (text formatting, filters, view options).
8
+ *
9
+ * Single selection by default (click again to clear); `multiple` allows several. Value is the pressed toggles'
10
+ * values, comma-separated with `multiple`. Arrow keys move between toggles (roving tabindex), Space/Enter toggles.
11
+ * Form-associated.
12
+ * @tag pm-toggle-group
13
+ * @slot - `pm-toggle` elements.
14
+ * @fires pm-change - Pressed toggles changed. detail: { value, values }
15
+ * @example <pm-toggle-group label="Text style" multiple value="bold"><pm-toggle value="bold">B</pm-toggle><pm-toggle value="italic">I</pm-toggle></pm-toggle-group>
16
+ */
17
+ export class PmToggleGroup extends PmElement {
18
+ static { this.componentName = 'toggle-group'; }
19
+ static { this.formAssociated = true; }
20
+ static { this.styles = [...PmElement.styles, fieldCss, toggleCss, css `:host { display: inline-flex; } .pm-field { justify-items: start; }`]; }
21
+ static { this.properties = { hint: {}, error: {},
22
+ value: { reflect: true }, name: { reflect: true }, label: {}, multiple: { type: Boolean }, required: { type: Boolean },
23
+ size: { reflect: true }, variant: { reflect: true }, orientation: { reflect: true }, disabled: { type: Boolean, reflect: true },
24
+ }; }
25
+ #internals = this.attachInternals();
26
+ #field = new FieldValidity(this, this.#internals, {
27
+ hint: () => this.hint, error: () => this.error, missing: () => this.required && !this.values.length && !this.disabled,
28
+ missingMessage: 'Please choose an option.', anchor: () => this.#toggles().find((t) => t.tabIndex === 0),
29
+ });
30
+ #default = '';
31
+ constructor() { super(); this.value = ''; this.multiple = false; this.required = false; this.disabled = false; }
32
+ get values() { return this.value.split(',').map((v) => v.trim()).filter(Boolean); }
33
+ connectedCallback() {
34
+ super.connectedCallback();
35
+ this.#default = this.getAttribute('value') ?? '';
36
+ this.addEventListener('keydown', this.#onKey);
37
+ this.addEventListener('click', this.#onClick);
38
+ }
39
+ formResetCallback() { this.value = this.#default; this.#field.reset(); }
40
+ formStateRestoreCallback(v) { this.value = v; }
41
+ formDisabledCallback(d) { this.disabled = d; }
42
+ #toggles() { return [...this.querySelectorAll(':scope > pm-toggle')]; }
43
+ render() {
44
+ const group = html `<div class="pm-toggle-group" part="base" role="group" aria-label=${this.label ?? nothing} data-size=${this.size ?? nothing}
45
+ aria-describedby=${this.#field.describedBy ?? nothing}
46
+ data-variant=${this.variant ?? nothing} data-orientation=${this.orientation ?? nothing}><slot @slotchange=${this.#sync}></slot></div>`;
47
+ return this.hint || this.#field.message ? html `<div class="pm-field" part="field">${group}${this.#field.messages()}</div>` : group;
48
+ }
49
+ updated() {
50
+ this.#sync();
51
+ if (this.multiple && this.name) {
52
+ const fd = new FormData();
53
+ for (const v of this.values)
54
+ fd.append(this.name, v);
55
+ this.#internals.setFormValue(fd);
56
+ }
57
+ else
58
+ this.#internals.setFormValue(this.value || null);
59
+ }
60
+ #sync = () => {
61
+ const vals = this.values;
62
+ const ts = this.#toggles();
63
+ const focusable = ts.find((t) => vals.includes(t.value) && !t.disabled) ?? ts.find((t) => !t.disabled);
64
+ for (const t of ts) {
65
+ t.pressed = vals.includes(t.value);
66
+ t.groupDisabled = this.disabled;
67
+ t.tabIndex = t === focusable && !this.disabled ? 0 : -1;
68
+ }
69
+ };
70
+ #toggle(t) {
71
+ if (t.disabled || this.disabled)
72
+ return;
73
+ const vals = this.values;
74
+ let next;
75
+ if (this.multiple)
76
+ next = vals.includes(t.value) ? vals.filter((v) => v !== t.value) : [...vals, t.value];
77
+ else
78
+ next = vals.includes(t.value) ? (this.required ? vals : []) : [t.value];
79
+ const order = this.#toggles().map((x) => x.value);
80
+ next.sort((a, b) => order.indexOf(a) - order.indexOf(b));
81
+ const value = next.join(',');
82
+ if (value === this.value)
83
+ return;
84
+ this.value = value;
85
+ this.#field.touch();
86
+ this.emit('pm-change', { value, values: next });
87
+ }
88
+ #onClick = (e) => {
89
+ const t = e.target.closest?.('pm-toggle');
90
+ if (t instanceof PmToggle && t.parentElement === this)
91
+ this.#toggle(t);
92
+ };
93
+ #onKey = (e) => {
94
+ const ts = this.#toggles().filter((t) => !t.disabled);
95
+ const cur = e.target.closest?.('pm-toggle');
96
+ const i = cur ? ts.indexOf(cur) : -1;
97
+ const rtl = getComputedStyle(this).direction === 'rtl';
98
+ const step = { ArrowRight: rtl ? -1 : 1, ArrowDown: 1, ArrowLeft: rtl ? 1 : -1, ArrowUp: -1 }[e.key];
99
+ let next;
100
+ if (step)
101
+ next = ts[(i + step + ts.length) % ts.length];
102
+ else if (e.key === 'Home')
103
+ next = ts[0];
104
+ else if (e.key === 'End')
105
+ next = ts[ts.length - 1];
106
+ else if ((e.key === ' ' || e.key === 'Enter') && cur) {
107
+ e.preventDefault();
108
+ this.#toggle(cur);
109
+ return;
110
+ }
111
+ if (!next)
112
+ return;
113
+ e.preventDefault();
114
+ for (const t of ts)
115
+ t.tabIndex = t === next ? 0 : -1;
116
+ next.focus();
117
+ };
118
+ }
119
+ /**
120
+ * One toggle button (aria-pressed). Use inside `pm-toggle-group`, or standalone as an on/off button.
121
+ * @tag pm-toggle
122
+ * @slot - Label (text and/or icon). Icon-only toggles need `label`.
123
+ * @fires pm-change - Standalone toggle changed. detail: { pressed }
124
+ * @example <pm-toggle label="Bold"><pm-icon name="bold"></pm-icon></pm-toggle>
125
+ */
126
+ export class PmToggle extends PmElement {
127
+ static { this.componentName = 'toggle'; }
128
+ static { this.styles = [...PmElement.styles, toggleCss, css `:host { display: inline-flex; border-radius: var(--pm-radius-control, var(--pm-radius-md)); outline: none; }
129
+ :host(:focus-visible) .pm-toggle { outline: 2px solid var(--pm-color-ring); outline-offset: 2px; } .pm-toggle { inline-size: 100%; }`]; }
130
+ static { this.properties = {
131
+ value: { reflect: true }, label: {}, pressed: { type: Boolean, reflect: true }, disabled: { type: Boolean, reflect: true },
132
+ size: { reflect: true }, variant: { reflect: true }, groupDisabled: { attribute: false },
133
+ }; }
134
+ constructor() { super(); this.value = ''; this.pressed = false; this.disabled = false; this.groupDisabled = false; }
135
+ get #standalone() { return !(this.parentElement instanceof PmToggleGroup); }
136
+ connectedCallback() {
137
+ super.connectedCallback();
138
+ this.setAttribute('role', 'button');
139
+ if (!this.hasAttribute('tabindex'))
140
+ this.tabIndex = 0;
141
+ this.addEventListener('click', this.#onClick);
142
+ this.addEventListener('keydown', this.#onKey);
143
+ }
144
+ #onClick = () => {
145
+ if (!this.#standalone || this.disabled)
146
+ return;
147
+ this.pressed = !this.pressed;
148
+ this.emit('pm-change', { pressed: this.pressed });
149
+ };
150
+ #onKey = (e) => {
151
+ if (this.#standalone && (e.key === ' ' || e.key === 'Enter')) {
152
+ e.preventDefault();
153
+ this.click();
154
+ }
155
+ };
156
+ updated() {
157
+ this.setAttribute('aria-pressed', String(this.pressed));
158
+ if (this.label)
159
+ this.setAttribute('aria-label', this.label);
160
+ if (this.disabled || this.groupDisabled)
161
+ this.setAttribute('aria-disabled', 'true');
162
+ else
163
+ this.removeAttribute('aria-disabled');
164
+ }
165
+ render() {
166
+ const group = this.parentElement instanceof PmToggleGroup ? this.parentElement : undefined;
167
+ return html `<span class="pm-toggle" part="base" data-size=${this.size ?? group?.size ?? nothing} data-variant=${this.variant ?? group?.variant ?? nothing}
168
+ ?data-pressed=${this.pressed} ?data-disabled=${this.disabled || this.groupDisabled}><slot></slot></span>`;
169
+ }
170
+ }
171
+ defineElement('pm-toggle-group', PmToggleGroup);
172
+ defineElement('pm-toggle', PmToggle);