@threadlabs/looma 0.50.2 → 0.51.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 (373) hide show
  1. package/components/shared/binding-inputs.js +5 -0
  2. package/components/shared/calendar-model.js +84 -0
  3. package/components/shared/date-input-segments.js +25 -0
  4. package/components/shared/date-navigation.js +35 -0
  5. package/components/shared/date-picker.js +38 -0
  6. package/components/shared/date-range.js +61 -0
  7. package/components/shared/date-time.js +273 -0
  8. package/components/shared/external-value.js +12 -0
  9. package/components/shared/form-reset.js +1 -1
  10. package/components/shared/icons.js +2 -0
  11. package/components/shared/initial-field-value.js +14 -0
  12. package/components/shared/input-segments.js +190 -0
  13. package/components/shared/prepared-module.js +19 -0
  14. package/components/ui-button/ui-button.html +31 -10
  15. package/components/ui-calendar/calendar-source.js +34 -0
  16. package/components/ui-calendar/ui-calendar.html +221 -0
  17. package/components/ui-calendar/ui-calendar.js +185 -0
  18. package/components/ui-cluster/ui-cluster.html +5 -2
  19. package/components/ui-date-field/ui-date-field.html +143 -0
  20. package/components/ui-date-field/ui-date-field.js +258 -0
  21. package/components/ui-date-picker/ui-date-picker.html +213 -0
  22. package/components/ui-date-picker/ui-date-picker.js +153 -0
  23. package/components/ui-date-range-picker/ui-date-range-picker.html +202 -0
  24. package/components/ui-date-range-picker/ui-date-range-picker.js +224 -0
  25. package/components/ui-file-input/files.js +15 -0
  26. package/components/ui-file-input/ui-file-input.html +79 -0
  27. package/components/ui-file-input/ui-file-input.js +108 -0
  28. package/components/ui-form-field/ui-form-field.js +2 -2
  29. package/components/ui-grid/ui-grid.html +68 -5
  30. package/components/ui-icon/ui-icon.html +8 -0
  31. package/components/ui-icon-button/ui-icon-button.html +22 -7
  32. package/components/ui-input/ui-input.html +10 -1
  33. package/components/ui-input/ui-input.js +11 -5
  34. package/components/ui-input-group/ui-input-group.html +2 -2
  35. package/components/ui-input-group/ui-input-group.js +6 -5
  36. package/components/ui-popover/ui-popover.html +2 -0
  37. package/components/ui-popover/ui-popover.js +5 -1
  38. package/components/ui-select/ui-select.html +8 -3
  39. package/components/ui-time-field/ui-time-field.html +62 -0
  40. package/components/ui-time-field/ui-time-field.js +21 -0
  41. package/components/ui-time-picker/time-options.js +25 -0
  42. package/components/ui-time-picker/ui-time-picker.html +160 -0
  43. package/components/ui-time-picker/ui-time-picker.js +132 -0
  44. package/dist/index.js +68 -61
  45. package/docs/README.md +2 -2
  46. package/docs/catalog.json +14225 -6225
  47. package/docs/documentation.css +1 -1
  48. package/docs/framework-examples.mjs +13 -2
  49. package/docs/site.mjs +1 -1
  50. package/editor/components.css +62 -29
  51. package/editor/icons.d.ts +2 -0
  52. package/editor/index.js +602 -141
  53. package/package.json +6 -4
  54. package/styles/ui-action-bar.css +1 -1
  55. package/styles/ui-affordance-scope.css +1 -1
  56. package/styles/ui-avatar-group.css +1 -1
  57. package/styles/ui-avatar.css +1 -1
  58. package/styles/ui-badge.css +1 -1
  59. package/styles/ui-breadcrumb-item.css +1 -1
  60. package/styles/ui-breadcrumbs.css +1 -1
  61. package/styles/ui-button.css +19 -7
  62. package/styles/ui-calendar.css +1 -0
  63. package/styles/ui-callout.css +1 -1
  64. package/styles/ui-card-group.css +1 -1
  65. package/styles/ui-card.css +1 -1
  66. package/styles/ui-checkbox.css +1 -1
  67. package/styles/ui-cluster.css +4 -1
  68. package/styles/ui-color-picker.css +1 -1
  69. package/styles/ui-combobox.css +1 -1
  70. package/styles/ui-compact-content.css +1 -1
  71. package/styles/ui-compact-editor.css +1 -1
  72. package/styles/ui-compact-mark.css +1 -1
  73. package/styles/ui-compact-node.css +1 -1
  74. package/styles/ui-container.css +1 -1
  75. package/styles/ui-context-menu.css +1 -1
  76. package/styles/ui-cover.css +1 -1
  77. package/styles/ui-curve-editor.css +1 -1
  78. package/styles/ui-cycle-button.css +1 -1
  79. package/styles/ui-date-field.css +1 -0
  80. package/styles/ui-date-picker.css +1 -0
  81. package/styles/ui-date-range-picker.css +1 -0
  82. package/styles/ui-description-item.css +1 -1
  83. package/styles/ui-description-list.css +1 -1
  84. package/styles/ui-dialog.css +1 -1
  85. package/styles/ui-disclosure.css +1 -1
  86. package/styles/ui-editable.css +1 -1
  87. package/styles/ui-editor-block-actions.css +1 -1
  88. package/styles/ui-editor-chip-editor.css +1 -1
  89. package/styles/ui-editor-code-language.css +1 -1
  90. package/styles/ui-editor-footnote-editor.css +1 -1
  91. package/styles/ui-editor-formatting-tools.css +1 -1
  92. package/styles/ui-editor-image-toolbar.css +1 -1
  93. package/styles/ui-editor-insert-table-grid.css +1 -1
  94. package/styles/ui-editor-link-card.css +1 -1
  95. package/styles/ui-editor-link-form.css +1 -1
  96. package/styles/ui-editor-mention-menu-item.css +1 -1
  97. package/styles/ui-editor-mention-menu.css +1 -1
  98. package/styles/ui-editor-slash-menu-group.css +1 -1
  99. package/styles/ui-editor-slash-menu-item.css +1 -1
  100. package/styles/ui-editor-slash-menu.css +1 -1
  101. package/styles/ui-editor-surface.css +1 -1
  102. package/styles/ui-editor-table-context-menu.css +1 -1
  103. package/styles/ui-editor-table-overlay.css +1 -1
  104. package/styles/ui-editor-table-toolbar.css +1 -1
  105. package/styles/ui-editor-toolbar.css +1 -1
  106. package/styles/ui-editor.css +1 -1
  107. package/styles/ui-file-input.css +1 -0
  108. package/styles/ui-floating-action-button.css +1 -1
  109. package/styles/ui-form-field.css +1 -1
  110. package/styles/ui-grid.css +38 -1
  111. package/styles/ui-icon-button.css +19 -5
  112. package/styles/ui-icon.css +5 -1
  113. package/styles/ui-image.css +1 -1
  114. package/styles/ui-input-group.css +3 -3
  115. package/styles/ui-input.css +1 -1
  116. package/styles/ui-light-editor.css +1 -1
  117. package/styles/ui-list-item.css +1 -1
  118. package/styles/ui-list.css +1 -1
  119. package/styles/ui-listbox.css +1 -1
  120. package/styles/ui-menu-group.css +1 -1
  121. package/styles/ui-menu-item.css +1 -1
  122. package/styles/ui-menu.css +1 -1
  123. package/styles/ui-meter.css +1 -1
  124. package/styles/ui-nav-item.css +1 -1
  125. package/styles/ui-number-input.css +1 -1
  126. package/styles/ui-page-header.css +1 -1
  127. package/styles/ui-pagination.css +1 -1
  128. package/styles/ui-popover.css +1 -1
  129. package/styles/ui-radio-group.css +1 -1
  130. package/styles/ui-radio.css +1 -1
  131. package/styles/ui-reel.css +1 -1
  132. package/styles/ui-scroll-area.css +1 -1
  133. package/styles/ui-search-result-row.css +1 -1
  134. package/styles/ui-search-shell.css +1 -1
  135. package/styles/ui-section.css +1 -1
  136. package/styles/ui-select.css +9 -4
  137. package/styles/ui-separator.css +1 -1
  138. package/styles/ui-sidebar.css +1 -1
  139. package/styles/ui-site-header.css +19 -19
  140. package/styles/ui-skeleton.css +1 -1
  141. package/styles/ui-slider.css +1 -1
  142. package/styles/ui-spinner.css +1 -1
  143. package/styles/ui-stack.css +1 -1
  144. package/styles/ui-status-message.css +1 -1
  145. package/styles/ui-swatch.css +1 -1
  146. package/styles/ui-switch.css +1 -1
  147. package/styles/ui-switcher.css +1 -1
  148. package/styles/ui-table.css +1 -1
  149. package/styles/ui-tabs.css +1 -1
  150. package/styles/ui-text.css +1 -1
  151. package/styles/ui-textarea.css +1 -1
  152. package/styles/ui-time-field.css +1 -0
  153. package/styles/ui-time-picker.css +1 -0
  154. package/styles/ui-toast-region.css +1 -1
  155. package/styles/ui-toast.css +1 -1
  156. package/styles/ui-tooltip.css +1 -1
  157. package/styles/ui-top-bar.css +1 -1
  158. package/styles/ui-tree-item.css +1 -1
  159. package/styles/ui-tree.css +1 -1
  160. package/tokens.css +4 -0
  161. package/vanilla/UiActionBar.d.ts +1 -1
  162. package/vanilla/UiActionBar.js +1 -1
  163. package/vanilla/UiAffordanceScope.d.ts +1 -1
  164. package/vanilla/UiAffordanceScope.js +1 -1
  165. package/vanilla/UiAvatar.d.ts +1 -1
  166. package/vanilla/UiAvatar.js +1 -1
  167. package/vanilla/UiAvatarGroup.d.ts +1 -1
  168. package/vanilla/UiAvatarGroup.js +1 -1
  169. package/vanilla/UiBadge.d.ts +1 -1
  170. package/vanilla/UiBadge.js +1 -1
  171. package/vanilla/UiBreadcrumbItem.d.ts +1 -1
  172. package/vanilla/UiBreadcrumbItem.js +1 -1
  173. package/vanilla/UiBreadcrumbs.d.ts +1 -1
  174. package/vanilla/UiBreadcrumbs.js +1 -1
  175. package/vanilla/UiButton.d.ts +2 -1
  176. package/vanilla/UiButton.js +128 -108
  177. package/vanilla/UiCalendar.d.ts +50 -0
  178. package/vanilla/UiCalendar.js +477 -0
  179. package/vanilla/UiCallout.d.ts +1 -1
  180. package/vanilla/UiCallout.js +1 -1
  181. package/vanilla/UiCard.d.ts +1 -1
  182. package/vanilla/UiCard.js +1 -1
  183. package/vanilla/UiCardGroup.d.ts +1 -1
  184. package/vanilla/UiCardGroup.js +1 -1
  185. package/vanilla/UiCheckbox.d.ts +1 -1
  186. package/vanilla/UiCheckbox.js +1 -1
  187. package/vanilla/UiCluster.d.ts +2 -2
  188. package/vanilla/UiCluster.js +2 -2
  189. package/vanilla/UiColorPicker.d.ts +1 -1
  190. package/vanilla/UiColorPicker.js +1 -1
  191. package/vanilla/UiCombobox.d.ts +1 -1
  192. package/vanilla/UiCombobox.js +1 -1
  193. package/vanilla/UiCompactContent.d.ts +1 -1
  194. package/vanilla/UiCompactContent.js +1 -1
  195. package/vanilla/UiCompactEditor.d.ts +1 -1
  196. package/vanilla/UiCompactEditor.js +1 -1
  197. package/vanilla/UiCompactMark.d.ts +1 -1
  198. package/vanilla/UiCompactMark.js +1 -1
  199. package/vanilla/UiCompactNode.d.ts +1 -1
  200. package/vanilla/UiCompactNode.js +1 -1
  201. package/vanilla/UiContainer.d.ts +1 -1
  202. package/vanilla/UiContainer.js +1 -1
  203. package/vanilla/UiContextMenu.d.ts +1 -1
  204. package/vanilla/UiContextMenu.js +1 -1
  205. package/vanilla/UiCover.d.ts +1 -1
  206. package/vanilla/UiCover.js +1 -1
  207. package/vanilla/UiCurveEditor.d.ts +1 -1
  208. package/vanilla/UiCurveEditor.js +1 -1
  209. package/vanilla/UiCycleButton.d.ts +1 -1
  210. package/vanilla/UiCycleButton.js +1 -1
  211. package/vanilla/UiDateField.d.ts +52 -0
  212. package/vanilla/UiDateField.js +208 -0
  213. package/vanilla/UiDatePicker.d.ts +63 -0
  214. package/vanilla/UiDatePicker.js +360 -0
  215. package/vanilla/UiDateRangePicker.d.ts +60 -0
  216. package/vanilla/UiDateRangePicker.js +418 -0
  217. package/vanilla/UiDescriptionItem.d.ts +1 -1
  218. package/vanilla/UiDescriptionItem.js +1 -1
  219. package/vanilla/UiDescriptionList.d.ts +1 -1
  220. package/vanilla/UiDescriptionList.js +1 -1
  221. package/vanilla/UiDialog.d.ts +1 -1
  222. package/vanilla/UiDialog.js +1 -1
  223. package/vanilla/UiDisclosure.d.ts +1 -1
  224. package/vanilla/UiDisclosure.js +1 -1
  225. package/vanilla/UiEditable.d.ts +1 -1
  226. package/vanilla/UiEditable.js +1 -1
  227. package/vanilla/UiEditor.d.ts +1 -1
  228. package/vanilla/UiEditor.js +1 -1
  229. package/vanilla/UiEditorBlockActions.d.ts +1 -1
  230. package/vanilla/UiEditorBlockActions.js +1 -1
  231. package/vanilla/UiEditorChipEditor.d.ts +1 -1
  232. package/vanilla/UiEditorChipEditor.js +1 -1
  233. package/vanilla/UiEditorCodeLanguage.d.ts +1 -1
  234. package/vanilla/UiEditorCodeLanguage.js +1 -1
  235. package/vanilla/UiEditorFootnoteEditor.d.ts +1 -1
  236. package/vanilla/UiEditorFootnoteEditor.js +1 -1
  237. package/vanilla/UiEditorFormattingTools.d.ts +1 -1
  238. package/vanilla/UiEditorFormattingTools.js +1 -1
  239. package/vanilla/UiEditorImageToolbar.d.ts +1 -1
  240. package/vanilla/UiEditorImageToolbar.js +1 -1
  241. package/vanilla/UiEditorInsertTableGrid.d.ts +1 -1
  242. package/vanilla/UiEditorInsertTableGrid.js +1 -1
  243. package/vanilla/UiEditorLinkCard.d.ts +1 -1
  244. package/vanilla/UiEditorLinkCard.js +1 -1
  245. package/vanilla/UiEditorLinkForm.d.ts +1 -1
  246. package/vanilla/UiEditorLinkForm.js +1 -1
  247. package/vanilla/UiEditorMentionMenu.d.ts +1 -1
  248. package/vanilla/UiEditorMentionMenu.js +1 -1
  249. package/vanilla/UiEditorMentionMenuItem.d.ts +1 -1
  250. package/vanilla/UiEditorMentionMenuItem.js +1 -1
  251. package/vanilla/UiEditorSlashMenu.d.ts +1 -1
  252. package/vanilla/UiEditorSlashMenu.js +1 -1
  253. package/vanilla/UiEditorSlashMenuGroup.d.ts +1 -1
  254. package/vanilla/UiEditorSlashMenuGroup.js +1 -1
  255. package/vanilla/UiEditorSlashMenuItem.d.ts +1 -1
  256. package/vanilla/UiEditorSlashMenuItem.js +1 -1
  257. package/vanilla/UiEditorSurface.d.ts +1 -1
  258. package/vanilla/UiEditorSurface.js +1 -1
  259. package/vanilla/UiEditorTableContextMenu.d.ts +1 -1
  260. package/vanilla/UiEditorTableContextMenu.js +1 -1
  261. package/vanilla/UiEditorTableOverlay.d.ts +1 -1
  262. package/vanilla/UiEditorTableOverlay.js +1 -1
  263. package/vanilla/UiEditorTableToolbar.d.ts +1 -1
  264. package/vanilla/UiEditorTableToolbar.js +1 -1
  265. package/vanilla/UiEditorToolbar.d.ts +1 -1
  266. package/vanilla/UiEditorToolbar.js +1 -1
  267. package/vanilla/UiFileInput.d.ts +36 -0
  268. package/vanilla/UiFileInput.js +209 -0
  269. package/vanilla/UiFloatingActionButton.d.ts +1 -1
  270. package/vanilla/UiFloatingActionButton.js +1 -1
  271. package/vanilla/UiFormField.d.ts +1 -1
  272. package/vanilla/UiFormField.js +1 -1
  273. package/vanilla/UiGrid.d.ts +7 -2
  274. package/vanilla/UiGrid.js +85 -19
  275. package/vanilla/UiIcon.d.ts +2 -1
  276. package/vanilla/UiIcon.js +10 -10
  277. package/vanilla/UiIconButton.d.ts +2 -2
  278. package/vanilla/UiIconButton.js +2 -2
  279. package/vanilla/UiImage.d.ts +1 -1
  280. package/vanilla/UiImage.js +1 -1
  281. package/vanilla/UiInput.d.ts +2 -1
  282. package/vanilla/UiInput.js +11 -11
  283. package/vanilla/UiInputGroup.d.ts +1 -1
  284. package/vanilla/UiInputGroup.js +1 -1
  285. package/vanilla/UiLightEditor.d.ts +1 -1
  286. package/vanilla/UiLightEditor.js +1 -1
  287. package/vanilla/UiList.d.ts +1 -1
  288. package/vanilla/UiList.js +1 -1
  289. package/vanilla/UiListItem.d.ts +1 -1
  290. package/vanilla/UiListItem.js +1 -1
  291. package/vanilla/UiListbox.d.ts +1 -1
  292. package/vanilla/UiListbox.js +1 -1
  293. package/vanilla/UiMenu.d.ts +1 -1
  294. package/vanilla/UiMenu.js +1 -1
  295. package/vanilla/UiMenuGroup.d.ts +1 -1
  296. package/vanilla/UiMenuGroup.js +1 -1
  297. package/vanilla/UiMenuItem.d.ts +1 -1
  298. package/vanilla/UiMenuItem.js +1 -1
  299. package/vanilla/UiMeter.d.ts +1 -1
  300. package/vanilla/UiMeter.js +1 -1
  301. package/vanilla/UiNavItem.d.ts +1 -1
  302. package/vanilla/UiNavItem.js +1 -1
  303. package/vanilla/UiNumberInput.d.ts +1 -1
  304. package/vanilla/UiNumberInput.js +1 -1
  305. package/vanilla/UiPageHeader.d.ts +1 -1
  306. package/vanilla/UiPageHeader.js +1 -1
  307. package/vanilla/UiPagination.d.ts +1 -1
  308. package/vanilla/UiPagination.js +1 -1
  309. package/vanilla/UiPopover.d.ts +2 -1
  310. package/vanilla/UiPopover.js +4 -4
  311. package/vanilla/UiRadio.d.ts +1 -1
  312. package/vanilla/UiRadio.js +1 -1
  313. package/vanilla/UiRadioGroup.d.ts +1 -1
  314. package/vanilla/UiRadioGroup.js +1 -1
  315. package/vanilla/UiReel.d.ts +1 -1
  316. package/vanilla/UiReel.js +1 -1
  317. package/vanilla/UiScrollArea.d.ts +1 -1
  318. package/vanilla/UiScrollArea.js +1 -1
  319. package/vanilla/UiSearchResultRow.d.ts +1 -1
  320. package/vanilla/UiSearchResultRow.js +1 -1
  321. package/vanilla/UiSearchShell.d.ts +1 -1
  322. package/vanilla/UiSearchShell.js +1 -1
  323. package/vanilla/UiSection.d.ts +1 -1
  324. package/vanilla/UiSection.js +1 -1
  325. package/vanilla/UiSelect.d.ts +1 -1
  326. package/vanilla/UiSelect.js +1 -1
  327. package/vanilla/UiSeparator.d.ts +1 -1
  328. package/vanilla/UiSeparator.js +1 -1
  329. package/vanilla/UiSidebar.d.ts +1 -1
  330. package/vanilla/UiSidebar.js +1 -1
  331. package/vanilla/UiSiteHeader.d.ts +1 -1
  332. package/vanilla/UiSiteHeader.js +1 -1
  333. package/vanilla/UiSkeleton.d.ts +1 -1
  334. package/vanilla/UiSkeleton.js +1 -1
  335. package/vanilla/UiSlider.d.ts +1 -1
  336. package/vanilla/UiSlider.js +1 -1
  337. package/vanilla/UiSpinner.d.ts +1 -1
  338. package/vanilla/UiSpinner.js +1 -1
  339. package/vanilla/UiStack.d.ts +1 -1
  340. package/vanilla/UiStack.js +1 -1
  341. package/vanilla/UiStatusMessage.d.ts +1 -1
  342. package/vanilla/UiStatusMessage.js +1 -1
  343. package/vanilla/UiSwatch.d.ts +1 -1
  344. package/vanilla/UiSwatch.js +1 -1
  345. package/vanilla/UiSwitch.d.ts +1 -1
  346. package/vanilla/UiSwitch.js +1 -1
  347. package/vanilla/UiSwitcher.d.ts +1 -1
  348. package/vanilla/UiSwitcher.js +1 -1
  349. package/vanilla/UiTable.d.ts +1 -1
  350. package/vanilla/UiTable.js +1 -1
  351. package/vanilla/UiTabs.d.ts +1 -1
  352. package/vanilla/UiTabs.js +1 -1
  353. package/vanilla/UiText.d.ts +1 -1
  354. package/vanilla/UiText.js +1 -1
  355. package/vanilla/UiTextarea.d.ts +1 -1
  356. package/vanilla/UiTextarea.js +1 -1
  357. package/vanilla/UiTimeField.d.ts +42 -0
  358. package/vanilla/UiTimeField.js +112 -0
  359. package/vanilla/UiTimePicker.d.ts +48 -0
  360. package/vanilla/UiTimePicker.js +372 -0
  361. package/vanilla/UiToast.d.ts +1 -1
  362. package/vanilla/UiToast.js +1 -1
  363. package/vanilla/UiToastRegion.d.ts +1 -1
  364. package/vanilla/UiToastRegion.js +1 -1
  365. package/vanilla/UiTooltip.d.ts +1 -1
  366. package/vanilla/UiTooltip.js +1 -1
  367. package/vanilla/UiTopBar.d.ts +1 -1
  368. package/vanilla/UiTopBar.js +1 -1
  369. package/vanilla/UiTree.d.ts +1 -1
  370. package/vanilla/UiTree.js +1 -1
  371. package/vanilla/UiTreeItem.d.ts +1 -1
  372. package/vanilla/UiTreeItem.js +1 -1
  373. package/vanilla/index.js +7 -0
@@ -0,0 +1,5 @@
1
+ /** Omitted optional inputs have no prerequisite; supplied or producing inputs retain readiness. */
2
+ export function readOptionalInput(inputs, props, name) {
3
+ const status = inputs.status(name);
4
+ return inputs.supplied(name) || status.ready || status.pending || status.error ? props[name] : undefined;
5
+ }
@@ -0,0 +1,84 @@
1
+ import { Temporal, calendarWeekStart, compileDateRules, isDateAllowed, monthGrid } from "./date-time.js";
2
+ import { availableDate } from "./date-navigation.js";
3
+
4
+ const compare = Temporal.PlainDate.compare;
5
+ const inRange = (value, start, end) => Boolean(start && end && compare(value, start) >= 0 && compare(value, end) <= 0);
6
+
7
+ /** Server-safe calendar data. The caller supplies the visible month and today's civil date. */
8
+ export function calendarModel(options) {
9
+ const { month, locale = "en-US", value = "", start = "", end = "", today = "" } = options;
10
+ if (!/^\d{4}-\d{2}$/.test(month)) throw new RangeError("The visible month must use YYYY-MM.");
11
+ const first = Temporal.PlainYearMonth.from(month).toPlainDate({ day: 1 });
12
+ if (first.year < 1) throw new RangeError("Calendar years use 0001–9999, matching native date fields.");
13
+ const rules = compileDateRules(options);
14
+ const weekStartsOn = calendarWeekStart(locale, options.weekStartsOn);
15
+ for (const date of [value, start, end, today, options.focusedDate].filter(Boolean)) Temporal.PlainDate.from(date);
16
+ if (start && end && compare(start, end) > 0) throw new RangeError("Calendar range endpoints must be ordered.");
17
+ const rows = monthGrid(month, { locale, weekStartsOn }).map(row => row.map(cell => ({
18
+ ...cell,
19
+ disabled: !/^\d{4}-/.test(cell.value) || cell.value.startsWith("0000-") || !isDateAllowed(cell.value, rules),
20
+ selected: cell.value === value,
21
+ today: cell.value === today,
22
+ rangeStart: cell.value === start,
23
+ rangeEnd: cell.value === end,
24
+ inRange: inRange(cell.value, start, end),
25
+ tabIndex: -1,
26
+ })));
27
+ const cells = rows.flat();
28
+ const candidates = cells.filter(cell => !cell.outside && !cell.disabled);
29
+ const focus = [options.focusedDate, value, start, today].map(date => candidates.find(cell => cell.value === date)).find(Boolean) ?? candidates[0];
30
+ if (focus) focus.tabIndex = 0;
31
+ const number = new Intl.NumberFormat(locale, { useGrouping: false });
32
+ const english = new Intl.Locale(locale).language === "en";
33
+ const outsideBounds = (beginning, ending) => Boolean(rules.min && compare(ending, rules.min) < 0 || rules.max && compare(beginning, rules.max) > 0);
34
+ const hasDates = (beginning, ending) => {
35
+ const next = availableDate(beginning.toString(), 1, rules);
36
+ return Boolean(next && compare(next, ending) <= 0);
37
+ };
38
+ const monthChoice = date => ({
39
+ value: date.toString().slice(0, 7),
40
+ label: date.toLocaleString(locale, { month: "short", calendar: "gregory" }),
41
+ fullLabel: date.toLocaleString(locale, { month: "long", calendar: "gregory" }),
42
+ current: date.month === first.month,
43
+ outsideBounds: outsideBounds(date, date.with({ day: date.daysInMonth })),
44
+ disabled: !hasDates(date, date.with({ day: date.daysInMonth })),
45
+ });
46
+ const yearPageStart = options.yearPageStart ?? Math.floor((first.year - 1) / 12) * 12 + 1;
47
+ if (!Number.isInteger(yearPageStart) || yearPageStart < 1 || yearPageStart > 9999) throw new RangeError("The year page must start within 0001–9999.");
48
+ const years = Array.from({ length: Math.min(12, 10000 - yearPageStart) }, (_, offset) => {
49
+ const year = yearPageStart + offset;
50
+ return {
51
+ value: year,
52
+ label: number.format(year),
53
+ current: year === first.year,
54
+ outsideBounds: outsideBounds(first.with({ year, month: 1 }), first.with({ year, month: 12, day: 31 })),
55
+ disabled: !hasDates(first.with({ year, month: 1 }), first.with({ year, month: 12, day: 31 })),
56
+ };
57
+ });
58
+ return {
59
+ month,
60
+ title: first.toLocaleString(locale, { year: "numeric", month: "long", calendar: "gregory" }),
61
+ monthLabel: first.toLocaleString(locale, { month: "long", calendar: "gregory" }),
62
+ yearLabel: number.format(first.year),
63
+ weekStartsOn,
64
+ weekendColumns: rows[0].flatMap((cell, index) => [6, 7].includes(Temporal.PlainDate.from(cell.value).dayOfWeek) ? [index + 1] : []),
65
+ weekdays: rows[0].map(cell => ({
66
+ day: Temporal.PlainDate.from(cell.value).dayOfWeek,
67
+ label: english ? ["M", "T", "W", "Th", "F", "S", "Su"][Temporal.PlainDate.from(cell.value).dayOfWeek - 1] : Temporal.PlainDate.from(cell.value).toLocaleString(locale, { weekday: "narrow", calendar: "gregory" }),
68
+ fullLabel: Temporal.PlainDate.from(cell.value).toLocaleString(locale, { weekday: "long", calendar: "gregory" }),
69
+ })),
70
+ rows,
71
+ rangeBands: rows.map(row => {
72
+ const columns = row.flatMap((cell, index) => cell.inRange ? [index + 1] : []);
73
+ return { start: columns[0] ?? 0, end: columns.at(-1) ?? 0 };
74
+ }),
75
+ focusDate: focus?.value ?? "",
76
+ empty: !focus,
77
+ previousMonth: month === "0001-01" ? "" : first.subtract({ months: 1 }).toString().slice(0, 7),
78
+ nextMonth: month === "9999-12" ? "" : first.add({ months: 1 }).toString().slice(0, 7),
79
+ months: Array.from({ length: 12 }, (_, offset) => monthChoice(first.with({ month: offset + 1 }))),
80
+ years,
81
+ yearPageStart,
82
+ yearPageLabel: `${number.format(yearPageStart)}–${number.format(yearPageStart + years.length - 1)}`,
83
+ };
84
+ }
@@ -0,0 +1,25 @@
1
+ import { formatInput } from "./date-time.js";
2
+
3
+ const digit = "[0-9\\p{Decimal_Number}]";
4
+ const escapedClass = text => text.replace(/[\\\]\[\-^]/g, "\\$&");
5
+
6
+ /** Describe the numeric editing representation using the same Intl locale and precision as the field. */
7
+ export function dateInputSegments(value, options = {}) {
8
+ const type = options.type ?? "date";
9
+ const date = type !== "time";
10
+ const order = date ? new Intl.DateTimeFormat(options.locale, { year: "numeric", month: "2-digit", day: "2-digit", calendar: "gregory", timeZone: "UTC" })
11
+ .formatToParts(new Date("2006-11-22T12:00Z")).filter(part => ["year", "month", "day"].includes(part.type)).map(part => ({ year: "yyyy", month: "mm", day: "dd" })[part.type]) : [];
12
+ const seed = type === "date" ? "2006-11-22" : type === "time" ? "13:45" : "2006-11-22T13:45";
13
+ let text;
14
+ try { text = formatInput(value || seed, value ? options : { ...options, type: date && type !== "date" ? "datetime-local" : type }); }
15
+ catch { return []; }
16
+ const labels = [...order, "hh", "mm", "ss"];
17
+ let index = 0;
18
+ const periods = [1, 13].map(hour => new Intl.DateTimeFormat(options.locale, { hour: "numeric", hour12: true, timeZone: "UTC" })
19
+ .formatToParts(new Date(`2000-01-01T${String(hour).padStart(2, "0")}:00Z`)).find(part => part.type === "dayPeriod")?.value ?? "");
20
+ return [...text.matchAll(/[\p{Decimal_Number}]+|[\p{Letter}]+|[^\p{Decimal_Number}\p{Letter}]+/gu)].map(([part]) => {
21
+ if (/\p{Decimal_Number}/u.test(part)) return { placeholder: labels[index++] ?? "s".repeat([...part].length), pattern: digit };
22
+ if (/\p{Letter}/u.test(part)) return { placeholder: "a".repeat(Math.max(...periods.map(period => [...period].length), [...part].length)), pattern: `[${escapedClass(periods.join("") + periods.join("").toLocaleLowerCase(options.locale))}]` };
23
+ return { literal: part };
24
+ });
25
+ }
@@ -0,0 +1,35 @@
1
+ import { Temporal, compileDateRules } from "./date-time.js";
2
+
3
+ const compare = Temporal.PlainDate.compare;
4
+ const later = (a, b) => compare(a, b) > 0 ? a : b;
5
+ const earlier = (a, b) => compare(a, b) < 0 ? a : b;
6
+
7
+ /** Find an available civil day without walking disabled years or inventing a navigation limit. */
8
+ export function availableDate(value, direction, rules = compileDateRules()) {
9
+ if (direction !== 1 && direction !== -1) throw new RangeError("Date navigation direction must be 1 or -1.");
10
+ if (rules.weekdays.length === 7) return null;
11
+ const lower = Temporal.PlainDate.from(rules.min ?? "0001-01-01");
12
+ const upper = Temporal.PlainDate.from(rules.max ?? "9999-12-31");
13
+ const target = Temporal.PlainDate.from(value);
14
+ const segments = rules.allowed ?? [{ start: lower.toString(), end: upper.toString() }];
15
+ const ordered = direction === 1 ? segments : segments.toReversed();
16
+ for (const segment of ordered) {
17
+ const start = later(lower, Temporal.PlainDate.from(segment.start));
18
+ const end = earlier(upper, Temporal.PlainDate.from(segment.end));
19
+ if (compare(start, end) > 0) continue;
20
+ let date = direction === 1 ? later(target, start) : earlier(target, end);
21
+ while (compare(date, start) >= 0 && compare(date, end) <= 0) {
22
+ const iso = date.toString();
23
+ // Rules contain merged, sorted positive four-digit dates, so lexical order
24
+ // is chronological. Binary search skips an entire unavailable interval.
25
+ let lo = 0; let hi = rules.disabled.length;
26
+ while (lo < hi) { const mid = (lo + hi) >>> 1; if (rules.disabled[mid].start <= iso) lo = mid + 1; else hi = mid; }
27
+ const block = rules.disabled[lo - 1];
28
+ if (block && block.end >= iso) {
29
+ date = Temporal.PlainDate.from(direction === 1 ? block.end : block.start).add({ days: direction });
30
+ } else if (rules.weekdays.includes(date.dayOfWeek)) date = date.add({ days: direction });
31
+ else return iso;
32
+ }
33
+ }
34
+ return null;
35
+ }
@@ -0,0 +1,38 @@
1
+ import { Temporal, canonicalValue } from "./date-time.js";
2
+
3
+ /** Project the editable civil parts without treating a plain date as an instant. */
4
+ export function pickerParts(value, options = {}) {
5
+ const type = options.type ?? "date";
6
+ if (!value) return { date: "", time: "" };
7
+ const canonical = canonicalValue(value, options);
8
+ if (type === "date") return { date: canonical, time: "" };
9
+ let local;
10
+ if (type === "datetime-local") local = Temporal.PlainDateTime.from(canonical.replace(" ", "T"));
11
+ else if (type === "instant") {
12
+ if (!options.timeZone) throw new RangeError("An explicit time zone is required to edit an exact time.");
13
+ local = Temporal.Instant.from(canonical).toZonedDateTimeISO(options.timeZone).toPlainDateTime();
14
+ } else if (type === "zoned") {
15
+ const zoned = Temporal.ZonedDateTime.from(canonical);
16
+ local = (options.timeZone ? zoned.withTimeZone(options.timeZone) : zoned).toPlainDateTime();
17
+ } else throw new RangeError("Date Picker requires a date-bearing value.");
18
+ return { date: local.toPlainDate().toString(), time: canonicalValue(local.toPlainTime().toString(), { type: "time" }) };
19
+ }
20
+
21
+ /** Replace civil parts while retaining precision and a bound zone, resolving DST explicitly. */
22
+ export function replacePickerParts(value, date, time, options = {}) {
23
+ date = canonicalValue(date);
24
+ if (!date) throw new RangeError("Choose a complete date.");
25
+ const type = options.type ?? "date";
26
+ if (type === "date") return date;
27
+ const previous = pickerParts(value, options);
28
+ const clock = canonicalValue(time ?? (previous.time || "00:00"), { type: "time" });
29
+ if (!clock) throw new RangeError("Enter a complete time.");
30
+ if (value && date === previous.date && clock === previous.time) return canonicalValue(value, options);
31
+ const local = Temporal.PlainDate.from(date).toPlainDateTime(Temporal.PlainTime.from(clock));
32
+ if (type === "datetime-local") return canonicalValue(local.toString(), options);
33
+ const boundZone = type === "zoned" && value ? Temporal.ZonedDateTime.from(value).timeZoneId : options.timeZone;
34
+ const editingZone = options.timeZone || boundZone;
35
+ if (!editingZone) throw new RangeError("An explicit time zone is required to edit an exact time.");
36
+ const zoned = local.toZonedDateTime(editingZone, { disambiguation: options.disambiguation ?? "reject" });
37
+ return canonicalValue(type === "instant" ? zoned.toInstant().toString() : zoned.withTimeZone(boundZone).toString(), options);
38
+ }
@@ -0,0 +1,61 @@
1
+ import { Temporal, canonicalValue, compileDateRules, isDateAllowed } from "./date-time.js";
2
+
3
+ const compare = Temporal.PlainDate.compare;
4
+ const first = "0001-01-01";
5
+ const last = "9999-12-31";
6
+ const later = (a, b) => compare(a, b) > 0 ? a : b;
7
+ const earlier = (a, b) => compare(a, b) < 0 ? a : b;
8
+ const add = (date, days) => Temporal.PlainDate.from(date).add({ days }).toString();
9
+
10
+ function intersect(ranges, lower, upper) {
11
+ return ranges.map(range => ({ start: later(range.start, lower), end: earlier(range.end, upper) }))
12
+ .filter(range => compare(range.start, range.end) <= 0);
13
+ }
14
+
15
+ /** Find the contiguous selectable interval around an endpoint without walking disabled years. */
16
+ function contiguous(anchor, rules, base) {
17
+ if (!isDateAllowed(anchor, rules)) return null;
18
+ const segment = base.find(range => compare(range.start, anchor) <= 0 && compare(anchor, range.end) <= 0);
19
+ if (!segment) return null;
20
+ let { start, end } = segment;
21
+ for (const block of rules.disabled) {
22
+ if (compare(block.end, anchor) < 0) start = later(start, add(block.end, 1));
23
+ else if (compare(block.start, anchor) > 0) { end = earlier(end, add(block.start, -1)); break; }
24
+ }
25
+ if (rules.weekdays.length) {
26
+ for (const direction of [-1, 1]) {
27
+ // Every excluded weekday occurs within one ISO week of an available anchor.
28
+ for (let distance = 1; distance <= 7; distance += 1) {
29
+ const date = Temporal.PlainDate.from(anchor).add({ days: distance * direction });
30
+ if (!rules.weekdays.includes(date.dayOfWeek)) continue;
31
+ if (direction < 0) start = later(start, date.add({ days: 1 }).toString());
32
+ else end = earlier(end, date.subtract({ days: 1 }).toString());
33
+ break;
34
+ }
35
+ }
36
+ }
37
+ return { start, end };
38
+ }
39
+
40
+ /** Project endpoint and two-click availability through the same whole-range validator's rules. */
41
+ export function rangeAvailability(range, { rules = compileDateRules(), mode = "range", anchor = "", allowUnavailableWithinRange = false } = {}) {
42
+ const lower = rules.min || first;
43
+ const upper = rules.max || last;
44
+ const base = intersect(rules.allowed ?? [{ start: lower, end: upper }], lower, upper);
45
+ const endpoint = name => {
46
+ const opposite = range[name === "start" ? "end" : "start"];
47
+ if (!opposite || allowUnavailableWithinRange) return base;
48
+ try { canonicalValue(opposite); } catch { return base; }
49
+ const segment = contiguous(opposite, rules, base);
50
+ if (!segment) return intersect(base, name === "start" ? later(lower, add(opposite, 1)) : lower, name === "end" ? earlier(upper, add(opposite, -1)) : upper);
51
+ return intersect(base, name === "start" ? segment.start : lower, name === "end" ? segment.end : upper);
52
+ };
53
+ const startRanges = endpoint("start");
54
+ const endRanges = endpoint("end");
55
+ let calendarRanges = mode === "start" ? startRanges : mode === "end" ? endRanges : base;
56
+ if (mode === "range" && anchor && !allowUnavailableWithinRange) {
57
+ const segment = contiguous(anchor, rules, base);
58
+ calendarRanges = segment ? intersect(base, segment.start, segment.end) : [];
59
+ }
60
+ return { startRanges, endRanges, calendarRanges };
61
+ }
@@ -0,0 +1,273 @@
1
+ import { Temporal as TemporalFallback } from "@js-temporal/polyfill";
2
+
3
+ // Keep native Temporal when present without modifying globals in consumers or SSR.
4
+ export const Temporal = globalThis.Temporal ?? TemporalFallback;
5
+ const DATE = /^\d{4}-\d{2}-\d{2}$/;
6
+ const TIME = /^\d{2}:\d{2}(?::[0-5]\d(?:\.\d{1,9})?)?$/;
7
+ const LOCAL = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::[0-5]\d(?:\.\d{1,9})?)?$/;
8
+ const clean = text => String(text).replace(/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g, "").trim();
9
+ const compare = (left, right) => Temporal.PlainDate.compare(left, right);
10
+
11
+ /** Civil values never acquire an implicit zone; exact values retain all their precision. */
12
+ function readValue(value, type = "date") {
13
+ if (typeof value !== "string") throw new RangeError("A date/time value must be a string.");
14
+ if (type === "date" && DATE.test(value) && !value.startsWith("0000-")) return Temporal.PlainDate.from(value);
15
+ if (type === "time" && TIME.test(value)) return Temporal.PlainTime.from(value);
16
+ if (type === "datetime-local" && LOCAL.test(value) && !value.startsWith("0000-")) return Temporal.PlainDateTime.from(value);
17
+ if (type === "instant") return Temporal.Instant.from(value);
18
+ if (type === "zoned") return Temporal.ZonedDateTime.from(value);
19
+ throw new RangeError(`Invalid ${type} value.`);
20
+ }
21
+
22
+ function serialized(value, options = {}) {
23
+ const precision = "second" in value && value.second === 0 && value.millisecond === 0 && value.microsecond === 0 && value.nanosecond === 0
24
+ ? { smallestUnit: "minute" } : {};
25
+ const text = value.toString({ calendarName: "never", ...precision });
26
+ return options.valueFormat === "space" && options.type === "datetime-local" ? text.replace("T", " ") : text;
27
+ }
28
+
29
+ /** Validate a machine binding without interpreting localized text or discarding a timestamp's zone. */
30
+ export function canonicalValue(value, options = {}) {
31
+ return value === "" ? "" : serialized(readValue(value, options.type), options);
32
+ }
33
+
34
+ /** Normalize localized numeric entry without changing the canonical value grammar. */
35
+ export function asciiDigits(text, locale) {
36
+ const formatter = new Intl.NumberFormat(locale, { useGrouping: false });
37
+ let result = clean(text);
38
+ for (let digit = 0; digit <= 9; digit++) result = result.replaceAll(clean(formatter.format(digit)), String(digit));
39
+ // CLDR versions differ on whether Arabic locales default to Latin digits.
40
+ // Arabic and Persian numeric paste must work with either default.
41
+ result = result.replace(/[\u0660-\u0669\u06f0-\u06f9]/g, digit => String(digit.codePointAt(0) % 16)).replaceAll("\u066b", ".");
42
+ const decimal = new Intl.NumberFormat(locale).formatToParts(1.1).find(part => part.type === "decimal")?.value;
43
+ if (decimal) result = result.replaceAll(decimal, ".");
44
+ return result;
45
+ }
46
+
47
+ function dateOrder(locale) {
48
+ return new Intl.DateTimeFormat(locale, { year: "numeric", month: "2-digit", day: "2-digit", calendar: "gregory", timeZone: "UTC" })
49
+ .formatToParts(new Date("2006-11-22T12:00Z")).filter(part => ["year", "month", "day"].includes(part.type)).map(part => part.type);
50
+ }
51
+
52
+ function numericDate(date, locale) {
53
+ // Intl's numeric year drops leading zeros. A four-digit editing grammar must
54
+ // keep them; this UTC Date is only an Intl formatting bridge, never arithmetic.
55
+ const instant = new Date(`${date.toString()}T12:00:00Z`);
56
+ const year = new Intl.NumberFormat(locale, { useGrouping: false, minimumIntegerDigits: 4 }).format(date.year);
57
+ return new Intl.DateTimeFormat(locale, { year: "numeric", month: "2-digit", day: "2-digit", calendar: "gregory", timeZone: "UTC" })
58
+ .formatToParts(instant).map(part => part.type === "year" ? year : part.value).join("");
59
+ }
60
+
61
+ function dateInput(text, locale) {
62
+ if (DATE.test(text)) return readValue(text);
63
+ const fields = text.match(/^(\d{1,4})[\s/.\-]+(\d{1,2})[\s/.\-]+(\d{1,4})$/);
64
+ if (!fields) throw new RangeError("Enter a complete date using the displayed date order or YYYY-MM-DD.");
65
+ const order = dateOrder(locale);
66
+ const parts = Object.fromEntries(order.map((name, index) => [name, fields[index + 1]]));
67
+ if (parts.year.length !== 4 || Number(parts.year) < 1) throw new RangeError("Enter a four-digit year from 0001 to 9999.");
68
+ return Temporal.PlainDate.from({ year: Number(parts.year), month: Number(parts.month), day: Number(parts.day) }, { overflow: "reject" });
69
+ }
70
+
71
+ function timeInput(text, locale, hourCycle) {
72
+ const cycle = hourCycle ?? new Intl.DateTimeFormat(locale, { hour: "numeric" }).resolvedOptions().hourCycle;
73
+ if (cycle === "h24") text = text.replace(/^24:/, "00:");
74
+ if (TIME.test(text)) return readValue(text, "time");
75
+ const periods = new Map([["am", "am"], ["pm", "pm"]]);
76
+ for (const [hour, period] of [[3, "am"], [15, "pm"]]) {
77
+ const label = new Intl.DateTimeFormat(locale, { hour: "numeric", hour12: true, timeZone: "UTC" })
78
+ .formatToParts(new Date(`2000-01-01T${String(hour).padStart(2, "0")}:00Z`)).find(part => part.type === "dayPeriod")?.value;
79
+ if (label) periods.set(clean(label).toLocaleLowerCase(locale), period);
80
+ }
81
+ const match = text.match(/^(\d{1,2}):(\d{2})(?::(\d{2})([.,]\d{1,9})?)?\s*(.*?)$/u);
82
+ if (!match) throw new RangeError("Enter a complete time, such as 14:30 or 2:30 PM.");
83
+ let hour = Number(match[1]);
84
+ if (match[5]) {
85
+ const period = periods.get(match[5].toLocaleLowerCase(locale));
86
+ if (!period || hour < (cycle === "h11" ? 0 : 1) || hour > (cycle === "h11" ? 11 : 12)) throw new RangeError("Enter a valid 12-hour time and AM or PM.");
87
+ hour = hour % 12 + (period === "pm" ? 12 : 0);
88
+ }
89
+ return readValue(`${String(hour).padStart(2, "0")}:${match[2]}${match[3] ? `:${match[3]}${(match[4] ?? "").replace(",", ".")}` : ""}`, "time");
90
+ }
91
+
92
+ function localInput(text, locale, hourCycle) {
93
+ if (LOCAL.test(text)) return readValue(text, "datetime-local");
94
+ const match = text.match(/^(.+?)[,\sT]+(\d{1,2}:\d{2}.*)$/u);
95
+ if (!match) throw new RangeError("Enter a complete date and time.");
96
+ return dateInput(match[1], locale).toPlainDateTime(timeInput(match[2], locale, hourCycle));
97
+ }
98
+
99
+ /** Parse only ISO or the declared locale's numeric order; never guess between competing locales. */
100
+ export function parseInput(text, options = {}) {
101
+ text = asciiDigits(text, options.locale);
102
+ if (!text) return "";
103
+ const type = options.type ?? "date";
104
+ let value;
105
+ if (type === "date") value = dateInput(text, options.locale);
106
+ else if (type === "time") value = timeInput(text, options.locale, options.hourCycle);
107
+ else if (type === "datetime-local") value = localInput(text, options.locale, options.hourCycle);
108
+ else if (type === "instant" || type === "zoned") {
109
+ // ISO timestamps carry their own offset; an editable wall-clock draft needs an explicit zone.
110
+ if (/\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})(?:\[.*\])?$/i.test(text)) value = readValue(text, type);
111
+ else {
112
+ if (!options.timeZone) throw new RangeError("An explicit time zone is required to edit an exact time.");
113
+ const zoned = localInput(text, options.locale, options.hourCycle).toZonedDateTime(options.timeZone, { disambiguation: options.disambiguation ?? "reject" });
114
+ // A field can show an existing zoned value through another editing zone.
115
+ // Local typing preserves its saved zone; an explicit zoned ISO paste above
116
+ // carries an intentional replacement zone of its own.
117
+ value = type === "instant" ? zoned.toInstant() : options.boundTimeZone ? zoned.withTimeZone(options.boundTimeZone) : zoned;
118
+ }
119
+ } else throw new RangeError("Unknown date/time type.");
120
+ return serialized(value, options);
121
+ }
122
+
123
+ /** Editable localized text keeps four-digit years and all nonzero sub-minute precision. */
124
+ export function formatInput(value, options = {}) {
125
+ if (!value) return "";
126
+ const type = options.type ?? "date";
127
+ let parsed = readValue(value, type);
128
+ if (type === "instant") {
129
+ if (!options.timeZone) throw new RangeError("An explicit time zone is required to display an exact time.");
130
+ parsed = parsed.toZonedDateTimeISO(options.timeZone).toPlainDateTime();
131
+ } else if (type === "zoned") parsed = (options.timeZone ? parsed.withTimeZone(options.timeZone) : parsed).toPlainDateTime();
132
+ const date = type === "date" ? parsed : type !== "time" ? parsed.toPlainDate() : null;
133
+ const time = type === "time" ? parsed : type !== "date" ? parsed.toPlainTime() : null;
134
+ const dateText = date ? numericDate(date, options.locale) : null;
135
+ let timeText;
136
+ if (time) {
137
+ const settings = { hour: "numeric", minute: "2-digit", ...(options.hourCycle ? { hourCycle: options.hourCycle } : {}) };
138
+ if (time.second || time.millisecond || time.microsecond || time.nanosecond || options.granularity === "second") settings.second = "2-digit";
139
+ // Native Intl supports only milliseconds. Keep finer precision as ISO editable text.
140
+ if (time.microsecond || time.nanosecond) timeText = serialized(time);
141
+ else {
142
+ if (time.millisecond) settings.fractionalSecondDigits = 3;
143
+ timeText = time.toLocaleString(options.locale, settings);
144
+ }
145
+ }
146
+ return dateText && timeText ? `${dateText} ${timeText}` : dateText ?? timeText;
147
+ }
148
+
149
+ /** Display formatting is independent of the numeric editing grammar and canonical binding. */
150
+ export function formatDisplay(value, options = {}) {
151
+ if (!value || !options.displayOptions || !Object.keys(options.displayOptions).length) return formatInput(value, options);
152
+ let parsed = readValue(value, options.type);
153
+ if (options.type === "instant") {
154
+ if (!options.timeZone) throw new RangeError("An explicit time zone is required to display an exact time.");
155
+ parsed = parsed.toZonedDateTimeISO(options.timeZone);
156
+ } else if (options.type === "zoned" && options.timeZone) parsed = parsed.withTimeZone(options.timeZone);
157
+ return parsed.toLocaleString(options.locale, { ...options.displayOptions, calendar: "gregory" });
158
+ }
159
+
160
+ /** Typed bounds compare values of the same kind; date availability then applies in the editing zone. */
161
+ export function isValueAllowed(value, options = {}) {
162
+ if (!value) return true;
163
+ const type = options.type ?? "date";
164
+ const parsed = readValue(value, type);
165
+ const comparator = { date: Temporal.PlainDate, time: Temporal.PlainTime, "datetime-local": Temporal.PlainDateTime, instant: Temporal.Instant, zoned: Temporal.ZonedDateTime }[type];
166
+ const min = options.min ? readValue(options.min, type) : null;
167
+ const max = options.max ? readValue(options.max, type) : null;
168
+ if (min && max && comparator.compare(min, max) > 0) {
169
+ // Native time inputs have a periodic domain, so bounds may wrap midnight.
170
+ if (type === "time") return comparator.compare(parsed, min) >= 0 || comparator.compare(parsed, max) <= 0;
171
+ throw new RangeError("The minimum must not exceed the maximum.");
172
+ }
173
+ if (min && comparator.compare(parsed, min) < 0 || max && comparator.compare(parsed, max) > 0) return false;
174
+ if (type === "time") return true;
175
+ let date = parsed;
176
+ if (type === "instant") {
177
+ if (!options.timeZone) throw new RangeError("An explicit time zone is required to validate an exact time's date.");
178
+ date = parsed.toZonedDateTimeISO(options.timeZone).toPlainDate();
179
+ } else if (type === "zoned") date = (options.timeZone ? parsed.withTimeZone(options.timeZone) : parsed).toPlainDate();
180
+ else if (type === "datetime-local") date = parsed.toPlainDate();
181
+ return isDateAllowed(date.toString(), compileDateRules({ ...options, min: undefined, max: undefined }));
182
+ }
183
+
184
+ function intervals(ranges = [], dates = []) {
185
+ const result = [...(ranges ?? []).map(range => ({ start: canonicalValue(range.start), end: canonicalValue(range.end) })), ...(dates ?? []).map(date => ({ start: canonicalValue(date), end: canonicalValue(date) }))];
186
+ for (const range of result) if (!range.start || !range.end || compare(range.start, range.end) > 0) throw new RangeError("A date interval needs ordered, complete endpoints.");
187
+ result.sort((left, right) => compare(left.start, right.start));
188
+ const merged = [];
189
+ for (const range of result) {
190
+ const previous = merged.at(-1);
191
+ if (previous && compare(range.start, Temporal.PlainDate.from(previous.end).add({ days: 1 })) <= 0) {
192
+ if (compare(range.end, previous.end) > 0) previous.end = range.end;
193
+ } else merged.push({ ...range });
194
+ }
195
+ return merged;
196
+ }
197
+
198
+ /** Normalize declarative restrictions once; allowed entries union, then disabled entries subtract. */
199
+ export function compileDateRules(options = {}) {
200
+ const min = options.min ? canonicalValue(options.min) : null;
201
+ const max = options.max ? canonicalValue(options.max) : null;
202
+ if (min && max && compare(min, max) > 0) throw new RangeError("The minimum date must not exceed the maximum date.");
203
+ const weekdays = [...new Set(options.disabledWeekdays ?? [])];
204
+ if (weekdays.some(day => !Number.isInteger(day) || day < 1 || day > 7)) throw new RangeError("Weekdays use ISO numbers 1 (Monday) to 7 (Sunday).");
205
+ return {
206
+ min, max, weekdays,
207
+ allowed: options.allowedDates != null || options.allowedRanges != null ? intervals(options.allowedRanges, options.allowedDates) : null,
208
+ disabled: intervals(options.disabledRanges, options.disabledDates),
209
+ };
210
+ }
211
+
212
+ /** Availability applies equally to typed values and calendar choices, with inclusive boundaries. */
213
+ export function isDateAllowed(value, rules = compileDateRules()) {
214
+ const date = readValue(value);
215
+ return !(rules.min && compare(value, rules.min) < 0 || rules.max && compare(value, rules.max) > 0 || rules.weekdays.includes(date.dayOfWeek))
216
+ && (rules.allowed === null || rules.allowed.some(range => compare(value, range.start) >= 0 && compare(value, range.end) <= 0))
217
+ && !rules.disabled.some(range => compare(value, range.start) >= 0 && compare(value, range.end) <= 0);
218
+ }
219
+
220
+ /** Validate whole intervals without walking years of calendar days. Endpoints must always be available. */
221
+ export function isRangeAllowed(range, rules = compileDateRules(), allowUnavailableWithinRange = false) {
222
+ const { start, end } = range;
223
+ if (!start || !end || compare(start, end) > 0 || !isDateAllowed(start, rules) || !isDateAllowed(end, rules)) return false;
224
+ if (allowUnavailableWithinRange) return true;
225
+ if (rules.allowed !== null && !rules.allowed.some(interval => compare(start, interval.start) >= 0 && compare(end, interval.end) <= 0)) return false;
226
+ if (rules.disabled.some(interval => compare(start, interval.end) <= 0 && compare(end, interval.start) >= 0)) return false;
227
+ if (rules.weekdays.length) {
228
+ const first = readValue(start);
229
+ const days = first.until(readValue(end)).days;
230
+ if (days >= 6) return false;
231
+ for (let offset = 1; offset < days; offset++) if (rules.weekdays.includes((first.dayOfWeek - 1 + offset) % 7 + 1)) return false;
232
+ }
233
+ return true;
234
+ }
235
+
236
+ /** A fresh two-click selection uses both dates in chronological order. */
237
+ export function rangeFromSelection(first, second) {
238
+ const anchor = canonicalValue(first);
239
+ const value = canonicalValue(second);
240
+ if (!anchor || !value) throw new RangeError("Choose two complete dates.");
241
+ return compare(anchor, value) <= 0 ? { start: anchor, end: value } : { start: value, end: anchor };
242
+ }
243
+
244
+ /** A start edit preserves the chosen end unless it crosses it; never shift to preserve duration. */
245
+ export function updateRangeStart(range, value) {
246
+ const start = canonicalValue(value);
247
+ return { start, end: start && range.end && compare(start, range.end) > 0 ? start : range.end };
248
+ }
249
+
250
+ /** An end edit preserves the chosen start unless it crosses it, matching the start-edit rule. */
251
+ export function updateRangeEnd(range, value) {
252
+ const end = canonicalValue(value);
253
+ return { start: end && range.start && compare(end, range.start) < 0 ? end : range.start, end };
254
+ }
255
+
256
+ /** Explicit week order wins; locale data supplies the default, with Sunday as the fallback. */
257
+ export function calendarWeekStart(locale = "en-US", override) {
258
+ const preference = typeof Intl.Locale === "function" ? new Intl.Locale(locale) : null;
259
+ const first = override ?? (preference?.getWeekInfo?.() ?? preference?.weekInfo)?.firstDay ?? 7;
260
+ if (!Number.isInteger(first) || first < 1 || first > 7) throw new RangeError("Week starts use ISO weekdays 1 (Monday) through 7 (Sunday).");
261
+ return first;
262
+ }
263
+
264
+ /** Six stable calendar rows preserve geometry across months; locale affects labels and default week order. */
265
+ export function monthGrid(month, options = {}) {
266
+ const first = Temporal.PlainYearMonth.from(month).toPlainDate({ day: 1 });
267
+ const weekStartsOn = calendarWeekStart(options.locale, options.weekStartsOn);
268
+ const start = first.subtract({ days: (first.dayOfWeek - weekStartsOn + 7) % 7 });
269
+ return Array.from({ length: 6 }, (_, week) => Array.from({ length: 7 }, (_, weekday) => {
270
+ const date = start.add({ days: week * 7 + weekday });
271
+ return { value: date.toString(), day: date.day, outside: date.month !== first.month, label: date.toLocaleString(options.locale, { dateStyle: "full", calendar: "gregory" }) };
272
+ }));
273
+ }
@@ -0,0 +1,12 @@
1
+ const observed = new WeakMap();
2
+
3
+ /** Compare external inputs across connections; live edits remain in the renderer's state. */
4
+ export function externalValueTracker(instance, options = {}) {
5
+ if (!observed.has(instance) && Object.hasOwn(options, "initialValue")) observed.set(instance, options.initialValue);
6
+ return value => {
7
+ const known = observed.has(instance);
8
+ const previous = observed.get(instance);
9
+ observed.set(instance, value);
10
+ return !known || !Object.is(previous, value);
11
+ };
12
+ }
@@ -11,7 +11,7 @@ export function afterFormReset(control, callback) {
11
11
  const document = control.ownerDocument;
12
12
  let timer;
13
13
  const onReset = (event) => {
14
- if (event.target === control.form) timer = setTimeout(callback);
14
+ if (event.target === control.form) timer = setTimeout(() => { if (!event.defaultPrevented) callback(); });
15
15
  };
16
16
  document.addEventListener("reset", onReset);
17
17
  return () => {
@@ -9,6 +9,7 @@ export const icons = {
9
9
  "book-user": [["path",{"d":"M15 13a3 3 0 1 0-6 0"}],["path",{"d":"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20"}],["circle",{"cx":"12","cy":"8","r":"2"}]],
10
10
  "braces": [["path",{"d":"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1"}],["path",{"d":"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1"}]],
11
11
  "calculator": [["rect",{"width":"16","height":"20","x":"4","y":"2","rx":"2"}],["line",{"x1":"8","x2":"16","y1":"6","y2":"6"}],["line",{"x1":"16","x2":"16","y1":"14","y2":"18"}],["path",{"d":"M16 10h.01"}],["path",{"d":"M12 10h.01"}],["path",{"d":"M8 10h.01"}],["path",{"d":"M12 14h.01"}],["path",{"d":"M8 14h.01"}],["path",{"d":"M12 18h.01"}],["path",{"d":"M8 18h.01"}]],
12
+ "calendar": [["path",{"d":"M8 2v4"}],["path",{"d":"M16 2v4"}],["rect",{"width":"18","height":"18","x":"3","y":"4","rx":"2"}],["path",{"d":"M3 10h18"}],["path",{"d":"M8 14h.01"}],["path",{"d":"M12 14h.01"}],["path",{"d":"M16 14h.01"}],["path",{"d":"M8 18h.01"}],["path",{"d":"M12 18h.01"}],["path",{"d":"M16 18h.01"}]],
12
13
  "check": [["path",{"d":"M20 6 9 17l-5-5"}]],
13
14
  "chevron-down": [["path",{"d":"m6 9 6 6 6-6"}]],
14
15
  "chevron-left": [["path",{"d":"m15 18-6-6 6-6"}]],
@@ -16,6 +17,7 @@ export const icons = {
16
17
  "circle-check": [["circle",{"cx":"12","cy":"12","r":"10"}],["path",{"d":"m9 12 2 2 4-4"}]],
17
18
  "circle-dot": [["circle",{"cx":"12","cy":"12","r":"10"}],["circle",{"cx":"12","cy":"12","r":"1"}]],
18
19
  "circle-x": [["circle",{"cx":"12","cy":"12","r":"10"}],["path",{"d":"m15 9-6 6"}],["path",{"d":"m9 9 6 6"}]],
20
+ "clock": [["path",{"d":"M12 6v6l4 2"}],["circle",{"cx":"12","cy":"12","r":"10"}]],
19
21
  "code-xml": [["path",{"d":"m18 16 4-4-4-4"}],["path",{"d":"m6 8-4 4 4 4"}],["path",{"d":"m14.5 4-5 16"}]],
20
22
  "columns": [["rect",{"width":"18","height":"18","x":"3","y":"3","rx":"2"}],["path",{"d":"M9 3v18"}],["path",{"d":"M15 3v18"}]],
21
23
  "compass": [["path",{"d":"m16.24 7.76-1.804 5.411a2 2 0 0 1-1.265 1.265L7.76 16.24l1.804-5.411a2 2 0 0 1 1.265-1.265z"}],["circle",{"cx":"12","cy":"12","r":"10"}]],
@@ -0,0 +1,14 @@
1
+ import { canonicalValue, parseInput } from "./date-time.js";
2
+
3
+ /** Read an enhanced field's canonical submission, or the usable native draft awaiting enhancement. */
4
+ export function initialFieldValue(field, options) {
5
+ const editor = field.querySelector("[data-date-editor]");
6
+ const fallback = field.querySelector("[data-date-fallback]");
7
+ if (!editor.hidden && editor.value !== "") return field.querySelector("[data-date-value]").value;
8
+ const control = editor.hidden ? fallback : editor;
9
+ if (control.validity.badInput) return undefined;
10
+ try {
11
+ if (control.value === "") canonicalValue(field.querySelector("[data-date-value]").value, options);
12
+ return parseInput(control.value, options);
13
+ } catch { return undefined; }
14
+ }