@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,37 @@
1
+ import { type PropertyDeclarations } from 'lit';
2
+ import { PmElement } from '../base.js';
3
+ /**
4
+ * Formatted number: locale-aware decimal, currency, percent or compact ("1.2K") output, with an optional count-up
5
+ * when it scrolls into view (skipped when the user prefers reduced motion).
6
+ *
7
+ * Screen readers always get the final value.
8
+ * @tag pm-format-number
9
+ * @example <pm-format-number value="48210" format="currency" currency="USD" count-up></pm-format-number>
10
+ */
11
+ export declare class PmFormatNumber extends PmElement {
12
+ #private;
13
+ static componentName: string;
14
+ static styles: import("lit").CSSResult[];
15
+ static properties: PropertyDeclarations;
16
+ value: number;
17
+ /** decimal (default), currency, percent (0.42 → 42%) or compact (1200 → 1.2K). */
18
+ format?: 'decimal' | 'currency' | 'percent' | 'compact';
19
+ /** ISO currency code for `format="currency"` (default USD). */
20
+ currency?: string;
21
+ /** Fixed number of fraction digits. */
22
+ digits?: number;
23
+ /** BCP 47 locale; defaults to the nearest `lang` attribute, then the browser's. */
24
+ locale?: string;
25
+ /** Count up from zero when first visible, and between values afterwards. */
26
+ countUp?: boolean;
27
+ /** Animation length in ms (default 900). */
28
+ duration?: number;
29
+ _shown: number;
30
+ constructor();
31
+ /** The formatted final value. */
32
+ get text(): string;
33
+ connectedCallback(): void;
34
+ disconnectedCallback(): void;
35
+ protected willUpdate(changed: Map<PropertyKey, unknown>): void;
36
+ render(): import("lit").TemplateResult<1>;
37
+ }
@@ -0,0 +1,86 @@
1
+ import { css, html } from 'lit';
2
+ import { PmElement, defineElement } from '../base.js';
3
+ import helpersCss from '../styles/helpers.js';
4
+ /**
5
+ * Formatted number: locale-aware decimal, currency, percent or compact ("1.2K") output, with an optional count-up
6
+ * when it scrolls into view (skipped when the user prefers reduced motion).
7
+ *
8
+ * Screen readers always get the final value.
9
+ * @tag pm-format-number
10
+ * @example <pm-format-number value="48210" format="currency" currency="USD" count-up></pm-format-number>
11
+ */
12
+ export class PmFormatNumber extends PmElement {
13
+ static { this.componentName = 'format-number'; }
14
+ static { this.styles = [...PmElement.styles, helpersCss, css `:host { display: inline; }`]; }
15
+ static { this.properties = {
16
+ value: { type: Number }, format: {}, currency: {}, digits: { type: Number }, locale: {}, countUp: { type: Boolean, attribute: 'count-up' }, duration: { type: Number }, _shown: { state: true },
17
+ }; }
18
+ #raf = 0;
19
+ #seen = false;
20
+ #io;
21
+ constructor() { super(); this.value = 0; this._shown = 0; }
22
+ /** The formatted final value. */
23
+ get text() { return this.#fmt(this.value); }
24
+ #fmt(n) {
25
+ const o = this.format === 'currency' ? { style: 'currency', currency: this.currency ?? 'USD' }
26
+ : this.format === 'percent' ? { style: 'percent' } : this.format === 'compact' ? { notation: 'compact', maximumFractionDigits: 1 } : {};
27
+ if (this.digits !== undefined) {
28
+ o.minimumFractionDigits = this.digits;
29
+ o.maximumFractionDigits = this.digits;
30
+ }
31
+ else if (this.format === 'currency' && Number.isInteger(this.value))
32
+ o.maximumFractionDigits = 0;
33
+ try {
34
+ return new Intl.NumberFormat(this.locale || this.closest('[lang]')?.getAttribute('lang') || undefined, o).format(n);
35
+ }
36
+ catch {
37
+ return String(n);
38
+ }
39
+ }
40
+ #run(from, to) {
41
+ cancelAnimationFrame(this.#raf);
42
+ if (!this.countUp || matchMedia('(prefers-reduced-motion: reduce)').matches) {
43
+ this._shown = to;
44
+ return;
45
+ }
46
+ const start = performance.now();
47
+ const ms = this.duration ?? 900;
48
+ const tick = (now) => {
49
+ const t = Math.min(1, (now - start) / ms);
50
+ const eased = 1 - (1 - t) ** 3;
51
+ const v = from + (to - from) * eased;
52
+ this._shown = t === 1 ? to : Number.isInteger(to) && Number.isInteger(from) ? Math.round(v) : v;
53
+ if (t < 1)
54
+ this.#raf = requestAnimationFrame(tick);
55
+ };
56
+ this.#raf = requestAnimationFrame(tick);
57
+ }
58
+ connectedCallback() {
59
+ super.connectedCallback();
60
+ if (!this.countUp || typeof IntersectionObserver === 'undefined') {
61
+ this.#seen = true;
62
+ this._shown = this.value;
63
+ return;
64
+ }
65
+ this.#io = new IntersectionObserver((entries) => {
66
+ if (!entries.some((e) => e.isIntersecting) || this.#seen)
67
+ return;
68
+ this.#seen = true;
69
+ this.#io?.disconnect();
70
+ this.#run(0, this.value);
71
+ });
72
+ this.#io.observe(this);
73
+ }
74
+ disconnectedCallback() { super.disconnectedCallback(); this.#io?.disconnect(); cancelAnimationFrame(this.#raf); }
75
+ willUpdate(changed) {
76
+ super.willUpdate(changed);
77
+ if (changed.has('value') && this.#seen && this.hasUpdated)
78
+ this.#run(this._shown, this.value);
79
+ else if (changed.has('value') && !this.countUp)
80
+ this._shown = this.value;
81
+ }
82
+ render() {
83
+ return html `<span class="pm-format-number" part="base"><span aria-hidden="true">${this.#fmt(this.#seen ? this._shown : this.countUp ? 0 : this.value)}</span><span class="pm-visually-hidden">${this.text}</span></span>`;
84
+ }
85
+ }
86
+ defineElement('pm-format-number', PmFormatNumber);
@@ -0,0 +1,34 @@
1
+ import { type PropertyDeclarations } from 'lit';
2
+ import { PmElement } from '../base.js';
3
+ /** `{ name, body }` — the shape exported by `@prismora/icons` (no runtime dependency on it). */
4
+ export interface IconDefinition {
5
+ readonly name: string;
6
+ readonly body: string;
7
+ }
8
+ /**
9
+ * Make icons available to `<pm-icon name="…">`. Register only what you use (tree-shakable):
10
+ * `registerIcons([check, trash])` with icons from `@prismora/icons`, or your own `{ name, body }` (24×24 viewBox).
11
+ */
12
+ export declare function registerIcons(icons: Iterable<IconDefinition> | Record<string, IconDefinition>): void;
13
+ /**
14
+ * Icon. Renders a registered stroke icon; decorative unless `label` is set.
15
+ * @tag pm-icon
16
+ * @csspart svg - The SVG element.
17
+ * @example <pm-icon name="check" label="Done"></pm-icon>
18
+ */
19
+ export declare class PmIcon extends PmElement {
20
+ #private;
21
+ static componentName: string;
22
+ static styles: import("lit").CSSResult[];
23
+ static properties: PropertyDeclarations;
24
+ /** Registered icon name (see `registerIcons`). */
25
+ name?: string;
26
+ /** Accessible name. Omit for decorative icons. */
27
+ label?: string;
28
+ size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
29
+ /** Stroke width (default `--pm-icon-stroke`, 2). */
30
+ strokeWidth?: number;
31
+ connectedCallback(): void;
32
+ disconnectedCallback(): void;
33
+ render(): import("lit").TemplateResult<1>;
34
+ }
@@ -0,0 +1,47 @@
1
+ import { css, html, nothing } from 'lit';
2
+ import { unsafeSVG } from 'lit/directives/unsafe-svg.js';
3
+ import { PmElement, defineElement } from '../base.js';
4
+ import iconCss from '../styles/icon.js';
5
+ const REGISTRY = new Map();
6
+ const listeners = new Set();
7
+ /**
8
+ * Make icons available to `<pm-icon name="…">`. Register only what you use (tree-shakable):
9
+ * `registerIcons([check, trash])` with icons from `@prismora/icons`, or your own `{ name, body }` (24×24 viewBox).
10
+ */
11
+ export function registerIcons(icons) {
12
+ const list = Symbol.iterator in Object(icons) ? icons : Object.values(icons);
13
+ for (const i of list)
14
+ REGISTRY.set(i.name, i.body);
15
+ for (const l of listeners)
16
+ l();
17
+ }
18
+ /**
19
+ * Icon. Renders a registered stroke icon; decorative unless `label` is set.
20
+ * @tag pm-icon
21
+ * @csspart svg - The SVG element.
22
+ * @example <pm-icon name="check" label="Done"></pm-icon>
23
+ */
24
+ export class PmIcon extends PmElement {
25
+ static { this.componentName = 'icon'; }
26
+ static { this.styles = [...PmElement.styles, iconCss, css `:host { display: inline-flex; vertical-align: -0.125em; line-height: 1; } :host([hidden]) { display: none; }`]; }
27
+ static { this.properties = {
28
+ name: { reflect: true },
29
+ label: {},
30
+ size: { reflect: true },
31
+ strokeWidth: { type: Number, attribute: 'stroke-width' },
32
+ }; }
33
+ #rerender = () => this.requestUpdate();
34
+ connectedCallback() { super.connectedCallback(); listeners.add(this.#rerender); }
35
+ disconnectedCallback() { super.disconnectedCallback(); listeners.delete(this.#rerender); }
36
+ render() {
37
+ const body = this.name ? REGISTRY.get(this.name) : undefined;
38
+ return html `<span class="pm-icon" data-size=${this.size ?? nothing} role=${this.label ? 'img' : nothing}
39
+ aria-label=${this.label ?? nothing} aria-hidden=${this.label ? nothing : 'true'}>
40
+ ${body
41
+ ? html `<svg part="svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"
42
+ style="stroke-width: ${this.strokeWidth ?? 'var(--pm-icon-stroke, 2)'}">${unsafeSVG(body)}</svg>`
43
+ : nothing}
44
+ </span>`;
45
+ }
46
+ }
47
+ defineElement('pm-icon', PmIcon);
@@ -0,0 +1,44 @@
1
+ import { type PropertyDeclarations } from 'lit';
2
+ import { PmElement } from '../base.js';
3
+ /**
4
+ * Image with a fixed ratio (no layout shift), a placeholder while it loads, a fallback when it fails, and optional
5
+ * click-to-zoom.
6
+ *
7
+ * Lazy by default; set `loading="eager"` for images visible on first paint.
8
+ * @tag pm-image
9
+ * @slot fallback - Shown when the image cannot load (default: the alt text).
10
+ * @fires pm-load - The image loaded.
11
+ * @fires pm-error - The image failed to load.
12
+ * @example <pm-image src="/photos/desk.jpg" alt="A desk with a laptop" ratio="16/9" zoomable></pm-image>
13
+ */
14
+ export declare class PmImage extends PmElement {
15
+ #private;
16
+ static componentName: string;
17
+ static styles: import("lit").CSSResult[];
18
+ static properties: PropertyDeclarations;
19
+ /** Image address. */
20
+ src?: string;
21
+ /** Describe the image; leave empty (`alt=""`) for decoration. */
22
+ alt?: string;
23
+ /** Width / height, e.g. "16/9", "1/1", "4/3". Without it the image keeps its own ratio. */
24
+ ratio?: string;
25
+ /** cover (default: fill and crop) or contain (show everything). */
26
+ fit?: 'cover' | 'contain';
27
+ /** lazy (default) or eager. */
28
+ loading?: 'lazy' | 'eager';
29
+ /** Candidate images for different screen densities and widths (as on `<img>`). */
30
+ srcset?: string;
31
+ /** Layout width hints for `srcset` (as on `<img>`). */
32
+ sizes?: string;
33
+ /** Intrinsic width in pixels; with `height` it reserves space when no `ratio` is set. */
34
+ width?: string;
35
+ /** Intrinsic height in pixels. */
36
+ height?: string;
37
+ /** Click or press Enter to view the image full screen. */
38
+ zoomable?: boolean;
39
+ _state: 'loading' | 'loaded' | 'error';
40
+ constructor();
41
+ protected willUpdate(changed: Map<PropertyKey, unknown>): void;
42
+ protected firstUpdated(): void;
43
+ render(): import("lit").TemplateResult<1>;
44
+ }
@@ -0,0 +1,53 @@
1
+ import { css, html, nothing } from 'lit';
2
+ import { ifDefined } from 'lit/directives/if-defined.js';
3
+ import { PmElement, defineElement } from '../base.js';
4
+ import buttonCss from '../styles/button.js';
5
+ import imageCss from '../styles/image.js';
6
+ /**
7
+ * Image with a fixed ratio (no layout shift), a placeholder while it loads, a fallback when it fails, and optional
8
+ * click-to-zoom.
9
+ *
10
+ * Lazy by default; set `loading="eager"` for images visible on first paint.
11
+ * @tag pm-image
12
+ * @slot fallback - Shown when the image cannot load (default: the alt text).
13
+ * @fires pm-load - The image loaded.
14
+ * @fires pm-error - The image failed to load.
15
+ * @example <pm-image src="/photos/desk.jpg" alt="A desk with a laptop" ratio="16/9" zoomable></pm-image>
16
+ */
17
+ export class PmImage extends PmElement {
18
+ static { this.componentName = 'image'; }
19
+ static { this.styles = [...PmElement.styles, buttonCss, imageCss, css `:host { display: block; min-inline-size: 0; } :host([hidden]) { display: none; }`]; }
20
+ static { this.properties = {
21
+ src: {}, alt: {}, ratio: { reflect: true }, fit: { reflect: true }, loading: {}, srcset: {}, sizes: {}, width: {}, height: {},
22
+ zoomable: { type: Boolean }, _state: { state: true },
23
+ }; }
24
+ constructor() { super(); this._state = 'loading'; }
25
+ willUpdate(changed) {
26
+ super.willUpdate(changed);
27
+ if (changed.has('src') && this.hasUpdated)
28
+ this._state = 'loading';
29
+ }
30
+ firstUpdated() {
31
+ // Cached images can finish before the listeners attach.
32
+ const img = this.renderRoot.querySelector('img');
33
+ if (img?.complete && img.naturalWidth)
34
+ this._state = 'loaded';
35
+ }
36
+ #zoom() { this.renderRoot.querySelector('dialog')?.showModal(); }
37
+ render() {
38
+ const style = `${this.ratio ? `--pm-ratio:${this.ratio.replace(':', '/')};` : ''}${this.fit ? `--pm-image-fit:${this.fit};` : ''}`;
39
+ return html `<div class="pm-image" part="base" data-state=${this._state} style=${style || nothing}>
40
+ ${this._state === 'error'
41
+ ? html `<div class="pm-image-fallback" part="fallback" role=${this.alt ? 'img' : nothing} aria-label=${this.alt || nothing}><slot name="fallback">${this.alt ?? ''}</slot></div>`
42
+ : html `<img part="img" src=${ifDefined(this.src)} alt=${this.alt ?? ''} loading=${this.loading ?? 'lazy'} decoding="async" srcset=${ifDefined(this.srcset)} sizes=${ifDefined(this.sizes)}
43
+ width=${ifDefined(this.width)} height=${ifDefined(this.height)}
44
+ @load=${() => { this._state = 'loaded'; this.emit('pm-load'); }} @error=${() => { this._state = 'error'; this.emit('pm-error'); }} />`}
45
+ ${this.zoomable && this._state === 'loaded' ? html `<button type="button" class="pm-image-zoom" part="zoom" aria-label=${`View larger: ${this.alt || 'image'}`} @click=${this.#zoom}></button>
46
+ <dialog class="pm-lightbox" aria-label=${this.alt || 'Image'} @click=${(e) => e.currentTarget.close()}>
47
+ <img src=${ifDefined(this.src)} alt=${this.alt ?? ''} />
48
+ <button type="button" class="pm-button pm-lightbox-close" data-variant="ghost" data-icon aria-label="Close">✕</button>
49
+ </dialog>` : nothing}
50
+ </div>`;
51
+ }
52
+ }
53
+ defineElement('pm-image', PmImage);
@@ -0,0 +1,41 @@
1
+ import { type PropertyDeclarations, type PropertyValues } from 'lit';
2
+ import { PmElement } from '../base.js';
3
+ /**
4
+ * Count or dot on the corner of an icon, button or avatar: unread notifications, messages, cart items, status.
5
+ *
6
+ * Wraps one element. `count` shows a number (`max` caps it: 120 → "99+"); `dot` shows a dot instead. Nothing shows
7
+ * at 0 unless `show-zero`. The badge is visual; its meaning reaches screen readers as the wrapped control's
8
+ * description, from `label` (`{count}` is filled in), e.g. "Notifications, 3 unread". `live` also announces changes.
9
+ * @tag pm-indicator
10
+ * @slot - The element to decorate (one).
11
+ * @csspart badge - The count or dot.
12
+ * @example <pm-indicator count="3" label="{count} unread"><pm-button variant="ghost" icon icon-start="bell" label="Notifications"></pm-button></pm-indicator>
13
+ */
14
+ export declare class PmIndicator extends PmElement {
15
+ #private;
16
+ static componentName: string;
17
+ static styles: import("lit").CSSResult[];
18
+ static properties: PropertyDeclarations;
19
+ /** Number to show. */
20
+ count?: number;
21
+ /** Highest number shown before "+" (default 99; 0 = no cap). */
22
+ max: number;
23
+ /** Show a dot instead of a number (with or without `count`). */
24
+ dot: boolean;
25
+ /** Keep showing the badge when `count` is 0. */
26
+ showZero: boolean;
27
+ /** Corner: top-end (default), top-start, bottom-end or bottom-start. */
28
+ placement?: 'top-end' | 'top-start' | 'bottom-end' | 'bottom-start';
29
+ /** Screen reader description; `{count}` is filled in (default "{count} new", or "New" for a dot). */
30
+ label?: string;
31
+ /** Pulse to draw attention (off when the user prefers reduced motion). */
32
+ pulse: boolean;
33
+ /** Announce count changes politely to screen readers. */
34
+ live: boolean;
35
+ /** Badge size. */
36
+ size?: 'sm' | 'md' | 'lg';
37
+ constructor();
38
+ disconnectedCallback(): void;
39
+ protected updated(changed: PropertyValues<this>): void;
40
+ render(): import("lit").TemplateResult<1>;
41
+ }
@@ -0,0 +1,65 @@
1
+ import { css, html, nothing } from 'lit';
2
+ import { PmElement, defineElement } from '../base.js';
3
+ import { countLabel, formatCount } from '../count.js';
4
+ import indicatorCss from '../styles/indicator.js';
5
+ /**
6
+ * Count or dot on the corner of an icon, button or avatar: unread notifications, messages, cart items, status.
7
+ *
8
+ * Wraps one element. `count` shows a number (`max` caps it: 120 → "99+"); `dot` shows a dot instead. Nothing shows
9
+ * at 0 unless `show-zero`. The badge is visual; its meaning reaches screen readers as the wrapped control's
10
+ * description, from `label` (`{count}` is filled in), e.g. "Notifications, 3 unread". `live` also announces changes.
11
+ * @tag pm-indicator
12
+ * @slot - The element to decorate (one).
13
+ * @csspart badge - The count or dot.
14
+ * @example <pm-indicator count="3" label="{count} unread"><pm-button variant="ghost" icon icon-start="bell" label="Notifications"></pm-button></pm-indicator>
15
+ */
16
+ export class PmIndicator extends PmElement {
17
+ static { this.componentName = 'indicator'; }
18
+ static { this.styles = [...PmElement.styles, indicatorCss, css `:host { display: inline-flex; vertical-align: middle; } :host([hidden]) { display: none; }`]; }
19
+ static { this.properties = {
20
+ count: { type: Number, reflect: true }, max: { type: Number }, dot: { type: Boolean, reflect: true }, showZero: { type: Boolean, attribute: 'show-zero' },
21
+ placement: { reflect: true }, label: {}, pulse: { type: Boolean, reflect: true }, live: { type: Boolean }, size: { reflect: true },
22
+ }; }
23
+ #target;
24
+ #announced = '';
25
+ constructor() { super(); this.max = 99; this.dot = false; this.showZero = false; this.pulse = false; this.live = false; }
26
+ get #visible() { return this.dot ? this.count === undefined || this.count > 0 || this.showZero : this.count !== undefined && (this.count > 0 || this.showZero); }
27
+ get #description() {
28
+ if (!this.#visible)
29
+ return '';
30
+ return countLabel(this.label ?? (this.dot && this.count === undefined ? 'New' : '{count} new'), this.count, this.max);
31
+ }
32
+ /** The element that receives focus: a component's inner control (shadow DOM), or the slotted element itself. */
33
+ async #describe() {
34
+ const el = this.querySelector(':scope > *');
35
+ if (!el)
36
+ return;
37
+ await el.updateComplete;
38
+ const target = el.shadowRoot?.querySelector('button, a[href], input, [tabindex]:not([tabindex="-1"])') ?? el;
39
+ if (this.#target && this.#target !== target)
40
+ this.#target.removeAttribute('aria-description');
41
+ this.#target = target;
42
+ const d = this.#description;
43
+ if (d)
44
+ target.setAttribute('aria-description', d);
45
+ else
46
+ target.removeAttribute('aria-description');
47
+ }
48
+ disconnectedCallback() { super.disconnectedCallback(); this.#target?.removeAttribute('aria-description'); this.#target = undefined; }
49
+ updated(changed) {
50
+ super.updated(changed);
51
+ void this.#describe();
52
+ }
53
+ render() {
54
+ const text = this.dot ? '' : formatCount(this.count, this.max);
55
+ const desc = this.#description;
56
+ const announce = this.live && this.hasUpdated && desc !== this.#announced ? desc : '';
57
+ this.#announced = desc;
58
+ return html `<span class="pm-indicator" data-placement=${this.placement ?? nothing}>
59
+ <slot @slotchange=${() => void this.#describe()}></slot>
60
+ <span class="pm-indicator-badge" part="badge" aria-hidden="true" data-tone=${this.tone ?? 'danger'} data-size=${this.size ?? nothing}
61
+ ?data-dot=${this.dot} ?data-pulse=${this.pulse} ?hidden=${!this.#visible}>${text}</span>
62
+ </span>${this.live ? html `<span class="pm-visually-hidden" role="status">${announce}</span>` : nothing}`;
63
+ }
64
+ }
65
+ defineElement('pm-indicator', PmIndicator);
@@ -0,0 +1,45 @@
1
+ import { type PropertyDeclarations } from 'lit';
2
+ import { PmElement } from '../base.js';
3
+ /**
4
+ * Inline edit: text that turns into an input in place, for renaming a project, a title or a table cell.
5
+ *
6
+ * Click the text or its pencil button (or focus it and press Enter) to edit. Enter or the tick saves, Escape or the
7
+ * cross cancels, and leaving the field saves. Empty values are refused when `required` is set. Your code stores the
8
+ * value: listen for `pm-change`.
9
+ * @tag pm-inline-edit
10
+ * @fires pm-change - A new value was saved. detail: { value, previous }
11
+ * @fires pm-cancel - Editing was cancelled. detail: { value }
12
+ * @csspart base - The text shown while not editing.
13
+ * @csspart input - The input shown while editing.
14
+ * @example <pm-inline-edit label="Project name" value="Website redesign"></pm-inline-edit>
15
+ */
16
+ export declare class PmInlineEdit extends PmElement {
17
+ #private;
18
+ static componentName: string;
19
+ static styles: import("lit").CSSResult[];
20
+ static properties: PropertyDeclarations;
21
+ /** The current text. */
22
+ value: string;
23
+ /** Accessible name, e.g. "Project name" (required for accessibility). */
24
+ label: string;
25
+ /** Shown while the value is empty. */
26
+ placeholder?: string;
27
+ /** Refuse to save an empty value. */
28
+ required: boolean;
29
+ /** Not editable. */
30
+ disabled: boolean;
31
+ /** Longest allowed value, in characters. */
32
+ maxlength?: number;
33
+ _editing: boolean;
34
+ _error: string;
35
+ constructor();
36
+ /** True while the input is shown. */
37
+ get editing(): boolean;
38
+ /** Show the input and select its text. */
39
+ edit(): Promise<void>;
40
+ /** Save what was typed. Returns false when the value is refused. */
41
+ save(): boolean;
42
+ /** Leave the input without saving. */
43
+ cancel(): void;
44
+ render(): import("lit").TemplateResult<1>;
45
+ }
@@ -0,0 +1,129 @@
1
+ import { css, html, nothing } from 'lit';
2
+ import { PmElement, defineElement } from '../base.js';
3
+ import buttonCss from '../styles/button.js';
4
+ import inputCss from '../styles/input.js';
5
+ /**
6
+ * Inline edit: text that turns into an input in place, for renaming a project, a title or a table cell.
7
+ *
8
+ * Click the text or its pencil button (or focus it and press Enter) to edit. Enter or the tick saves, Escape or the
9
+ * cross cancels, and leaving the field saves. Empty values are refused when `required` is set. Your code stores the
10
+ * value: listen for `pm-change`.
11
+ * @tag pm-inline-edit
12
+ * @fires pm-change - A new value was saved. detail: { value, previous }
13
+ * @fires pm-cancel - Editing was cancelled. detail: { value }
14
+ * @csspart base - The text shown while not editing.
15
+ * @csspart input - The input shown while editing.
16
+ * @example <pm-inline-edit label="Project name" value="Website redesign"></pm-inline-edit>
17
+ */
18
+ export class PmInlineEdit extends PmElement {
19
+ static { this.componentName = 'inline-edit'; }
20
+ static { this.styles = [...PmElement.styles, buttonCss, inputCss, css `
21
+ :host { display: inline-flex; max-inline-size: 100%; vertical-align: middle; }
22
+ .view { display: inline-flex; align-items: center; gap: var(--pm-space-1); max-inline-size: 100%; }
23
+ .text {
24
+ min-inline-size: 2ch; padding: 0.15em 0.35em; margin-inline: -0.35em; border-radius: var(--pm-radius-sm); cursor: text;
25
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
26
+ }
27
+ .text:hover { background: var(--pm-color-bg-hover); }
28
+ .text[data-empty] { color: var(--pm-color-fg-muted); font-style: italic; }
29
+ .pencil { opacity: 0; }
30
+ .view:hover .pencil, .pencil:focus-visible { opacity: 1; }
31
+ @media (hover: none) { .pencil { opacity: 1; } }
32
+ .edit { display: inline-flex; align-items: center; gap: var(--pm-space-1); max-inline-size: 100%; }
33
+ .edit .pm-input { inline-size: var(--pm-inline-edit-width, 16rem); max-inline-size: 100%; font: inherit; }
34
+ .err { color: var(--pm-color-danger-text); font-size: var(--pm-font-size-xs); }
35
+ `]; }
36
+ static { this.properties = {
37
+ value: {}, label: {}, placeholder: {}, required: { type: Boolean }, disabled: { type: Boolean, reflect: true }, maxlength: { type: Number },
38
+ _editing: { state: true }, _error: { state: true },
39
+ }; }
40
+ #draft = '';
41
+ constructor() { super(); this.value = ''; this.label = 'Text'; this.required = false; this.disabled = false; this._editing = false; this._error = ''; }
42
+ /** True while the input is shown. */
43
+ get editing() { return this._editing; }
44
+ /** Show the input and select its text. */
45
+ async edit() {
46
+ if (this.disabled || this._editing)
47
+ return;
48
+ this.#draft = this.value;
49
+ this._error = '';
50
+ this._editing = true;
51
+ await this.updateComplete;
52
+ const input = this.renderRoot.querySelector('input');
53
+ input?.focus();
54
+ input?.select();
55
+ }
56
+ /** Save what was typed. Returns false when the value is refused. */
57
+ save() {
58
+ if (!this._editing)
59
+ return true;
60
+ const next = this.#draft.trim();
61
+ if (this.required && !next) {
62
+ this._error = `${this.label} cannot be empty.`;
63
+ return false;
64
+ }
65
+ const previous = this.value;
66
+ this._editing = false;
67
+ this._error = '';
68
+ if (next !== previous) {
69
+ this.value = next;
70
+ this.emit('pm-change', { value: next, previous });
71
+ }
72
+ this.#refocus();
73
+ return true;
74
+ }
75
+ /** Leave the input without saving. */
76
+ cancel() {
77
+ if (!this._editing)
78
+ return;
79
+ this._editing = false;
80
+ this._error = '';
81
+ this.emit('pm-cancel', { value: this.value });
82
+ this.#refocus();
83
+ }
84
+ #refocus() { this.updateComplete.then(() => this.renderRoot.querySelector('.text')?.focus()); }
85
+ #onKey(e) {
86
+ if (e.key === 'Enter') {
87
+ e.preventDefault();
88
+ this.save();
89
+ }
90
+ else if (e.key === 'Escape') {
91
+ e.preventDefault();
92
+ e.stopPropagation();
93
+ this.cancel();
94
+ }
95
+ }
96
+ #onBlur(e) {
97
+ // Moving to the tick or cross is not leaving.
98
+ if (this.renderRoot.contains(e.relatedTarget))
99
+ return;
100
+ if (!this.save())
101
+ this.cancel();
102
+ }
103
+ render() {
104
+ const icon = (d) => html `<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"><path d=${d}/></svg>`;
105
+ if (this._editing) {
106
+ return html `<span class="edit">
107
+ <input class="pm-input" part="input" data-size="sm" .value=${this.#draft} aria-label=${this.label} placeholder=${this.placeholder ?? nothing}
108
+ maxlength=${this.maxlength ?? nothing} aria-invalid=${this._error ? 'true' : nothing} aria-describedby=${this._error ? 'err' : nothing}
109
+ @input=${(e) => { this.#draft = e.target.value; if (this._error)
110
+ this._error = ''; }}
111
+ @keydown=${this.#onKey} @blur=${this.#onBlur}>
112
+ <button type="button" class="pm-button" data-variant="soft" data-size="sm" data-icon aria-label="Save" @click=${() => this.save()}>${icon('M5 12.5l4.5 4.5L19 7.5')}</button>
113
+ <button type="button" class="pm-button" data-variant="ghost" data-tone="neutral" data-size="sm" data-icon aria-label="Cancel" @click=${() => this.cancel()}>${icon('M6 6l12 12M18 6L6 18')}</button>
114
+ ${this._error ? html `<span class="err" id="err" role="alert">${this._error}</span>` : nothing}
115
+ </span>`;
116
+ }
117
+ const empty = !this.value;
118
+ return html `<span class="view">
119
+ <span class="text" part="base" role="button" tabindex=${this.disabled ? -1 : 0} aria-label="${this.label}: ${empty ? (this.placeholder ?? 'Empty') : this.value}. Edit"
120
+ aria-disabled=${this.disabled ? 'true' : nothing} ?data-empty=${empty} @click=${() => this.edit()}
121
+ @keydown=${(e) => { if (e.key === 'Enter' || e.key === ' ' || e.key === 'F2') {
122
+ e.preventDefault();
123
+ this.edit();
124
+ } }}>${empty ? (this.placeholder ?? 'Empty') : this.value}</span>
125
+ ${this.disabled ? nothing : html `<button type="button" class="pm-button pencil" data-variant="ghost" data-tone="neutral" data-size="xs" data-icon tabindex="-1" aria-hidden="true" @click=${() => this.edit()}>${icon('M4 20h4L18.5 9.5a2.1 2.1 0 0 0-3-3L5 17v3zM14 7l3 3')}</button>`}
126
+ </span>`;
127
+ }
128
+ }
129
+ defineElement('pm-inline-edit', PmInlineEdit);
@@ -0,0 +1,55 @@
1
+ import { type PropertyDeclarations, type PropertyValues } from 'lit';
2
+ import { PmFormControl } from './form-control.js';
3
+ /**
4
+ * Single-line text field for text, email, numbers, passwords, search and more.
5
+ * @tag pm-input
6
+ * @slot end - Trailing adornment.
7
+ * @slot start - Leading adornment (icon or text such as "https://").
8
+ * @csspart control - The native input.
9
+ * @csspart counter - Character counter (with `show-count`).
10
+ * @fires pm-clear - The clear button was pressed.
11
+ * @example <pm-input label="Email" type="email" name="email" required></pm-input>
12
+ */
13
+ export declare class PmInput extends PmFormControl {
14
+ #private;
15
+ static styles: import("lit").CSSResult[];
16
+ static componentName: string;
17
+ static properties: PropertyDeclarations;
18
+ /** Registered icon name shown before the content (see `registerIcons`); a `start` slot overrides it. */
19
+ iconStart?: string;
20
+ /** Registered icon name shown after the content (see `registerIcons`); an `end` slot overrides it. */
21
+ iconEnd?: string;
22
+ /** Shows a clear (✕) button when there is a value. */
23
+ clearable: boolean;
24
+ /** For `type="password"`: a button to show/hide the password. */
25
+ passwordToggle: boolean;
26
+ /** Shows "n / maxlength" (or "n" without maxlength) under the input. */
27
+ showCount: boolean;
28
+ _revealed: boolean;
29
+ type: string;
30
+ placeholder?: string;
31
+ autocomplete?: string;
32
+ /** Virtual keyboard to show on touch devices (the HTML `inputmode`). */
33
+ inputmode?: string;
34
+ /** Regular expression the value must match. */
35
+ pattern?: string;
36
+ minlength?: number;
37
+ maxlength?: number;
38
+ min?: string;
39
+ max?: string;
40
+ step?: string;
41
+ /** Input mask: `9` a digit, `a` a letter, `*` either; other characters are typed for the user. E.g. `mask="(999) 999-9999"`, `mask="99/99"`, `mask="aa-9999"`. */
42
+ mask?: string;
43
+ /** Show a strength bar under a password field (length and character variety; a guide, not a security check). */
44
+ strength: boolean;
45
+ constructor();
46
+ protected onInput(e: Event): void;
47
+ protected firstUpdated(changed: PropertyValues<this>): void;
48
+ disconnectedCallback(): void;
49
+ protected updated(changed: PropertyValues<this>): void;
50
+ render(): import("lit").TemplateResult<1>;
51
+ }
52
+ /** Fit `raw` to a mask: `9` digit, `a` letter, `*` letter or digit; literals are inserted. Stops at the first missing character. */
53
+ export declare function applyMask(raw: string, mask: string): string;
54
+ /** Rough password strength, 0 (too short) to 4 (strong), from length and character variety. */
55
+ export declare function passwordStrength(value: string): 0 | 1 | 2 | 3 | 4;