@sprawlify/primitives 0.1.10 → 0.1.12

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 (107) hide show
  1. package/dist/{collection-BBgC8xCb.cjs → collection-D0Abtxc0.cjs} +68 -0
  2. package/dist/{collection-DgzidRvr.mjs → collection-GSpaYJ2f.mjs} +45 -1
  3. package/dist/collection.cjs +5 -1
  4. package/dist/collection.d.cts +49 -3
  5. package/dist/collection.d.mts +49 -3
  6. package/dist/collection.mjs +2 -2
  7. package/dist/{focus-trap-BewqTQFt.cjs → focus-trap-BbU9QXMe.cjs} +1 -1
  8. package/dist/{focus-trap-Do8IUXYh.mjs → focus-trap-CzhQ01j4.mjs} +1 -1
  9. package/dist/focus-trap.cjs +1 -1
  10. package/dist/focus-trap.mjs +1 -1
  11. package/dist/{list-collection-B_8BN0XB.d.cts → list-collection-Cjgbx_9l.d.cts} +1 -1
  12. package/dist/{list-collection-DkRA5LOq.d.mts → list-collection-IF510iNl.d.mts} +1 -1
  13. package/dist/machines/accordion/index.d.cts +1 -1
  14. package/dist/machines/accordion/index.d.mts +1 -1
  15. package/dist/machines/angle-slider/index.d.cts +1 -1
  16. package/dist/machines/angle-slider/index.d.mts +1 -1
  17. package/dist/machines/cascade-select/index.cjs +1 -1
  18. package/dist/machines/cascade-select/index.d.cts +2 -2
  19. package/dist/machines/cascade-select/index.d.mts +2 -2
  20. package/dist/machines/cascade-select/index.mjs +1 -1
  21. package/dist/machines/clipboard/index.d.cts +1 -1
  22. package/dist/machines/clipboard/index.d.mts +1 -1
  23. package/dist/machines/collapsible/index.d.cts +1 -1
  24. package/dist/machines/collapsible/index.d.mts +1 -1
  25. package/dist/machines/color-picker/index.d.cts +1 -1
  26. package/dist/machines/color-picker/index.d.mts +1 -1
  27. package/dist/machines/combobox/index.cjs +279 -355
  28. package/dist/machines/combobox/index.d.cts +5 -4
  29. package/dist/machines/combobox/index.d.mts +5 -4
  30. package/dist/machines/combobox/index.mjs +279 -355
  31. package/dist/machines/date-input/index.cjs +1830 -0
  32. package/dist/machines/date-input/index.d.cts +223 -0
  33. package/dist/machines/date-input/index.d.mts +223 -0
  34. package/dist/machines/date-input/index.mjs +1813 -0
  35. package/dist/machines/date-picker/index.d.cts +1 -1
  36. package/dist/machines/date-picker/index.d.mts +1 -1
  37. package/dist/machines/dialog/index.cjs +1 -1
  38. package/dist/machines/dialog/index.d.cts +1 -1
  39. package/dist/machines/dialog/index.d.mts +1 -1
  40. package/dist/machines/dialog/index.mjs +1 -1
  41. package/dist/machines/drawer/index.cjs +1 -1
  42. package/dist/machines/drawer/index.d.cts +1 -1
  43. package/dist/machines/drawer/index.d.mts +1 -1
  44. package/dist/machines/drawer/index.mjs +1 -1
  45. package/dist/machines/dropdown-menu/index.d.cts +1 -1
  46. package/dist/machines/dropdown-menu/index.d.mts +1 -1
  47. package/dist/machines/editable/index.d.cts +1 -1
  48. package/dist/machines/editable/index.d.mts +1 -1
  49. package/dist/machines/file-upload/index.d.cts +1 -1
  50. package/dist/machines/file-upload/index.d.mts +1 -1
  51. package/dist/machines/floating-panel/index.d.cts +1 -1
  52. package/dist/machines/floating-panel/index.d.mts +1 -1
  53. package/dist/machines/hover-card/index.d.cts +1 -1
  54. package/dist/machines/hover-card/index.d.mts +1 -1
  55. package/dist/machines/listbox/index.cjs +41 -16
  56. package/dist/machines/listbox/index.d.cts +5 -4
  57. package/dist/machines/listbox/index.d.mts +5 -4
  58. package/dist/machines/listbox/index.mjs +42 -17
  59. package/dist/machines/marquee/index.d.cts +2 -2
  60. package/dist/machines/marquee/index.d.mts +2 -2
  61. package/dist/machines/navigation-menu/index.d.cts +1 -1
  62. package/dist/machines/navigation-menu/index.d.mts +1 -1
  63. package/dist/machines/number-input/index.d.cts +1 -1
  64. package/dist/machines/number-input/index.d.mts +1 -1
  65. package/dist/machines/password-input/index.d.cts +1 -1
  66. package/dist/machines/password-input/index.d.mts +1 -1
  67. package/dist/machines/pin-input/index.d.cts +1 -1
  68. package/dist/machines/pin-input/index.d.mts +1 -1
  69. package/dist/machines/popover/index.cjs +1 -1
  70. package/dist/machines/popover/index.d.cts +1 -1
  71. package/dist/machines/popover/index.d.mts +1 -1
  72. package/dist/machines/popover/index.mjs +1 -1
  73. package/dist/machines/progress/index.d.cts +1 -1
  74. package/dist/machines/progress/index.d.mts +1 -1
  75. package/dist/machines/select/index.cjs +47 -18
  76. package/dist/machines/select/index.d.cts +4 -3
  77. package/dist/machines/select/index.d.mts +4 -3
  78. package/dist/machines/select/index.mjs +48 -19
  79. package/dist/machines/signature-pad/index.d.cts +1 -1
  80. package/dist/machines/signature-pad/index.d.mts +1 -1
  81. package/dist/machines/slider/index.d.cts +1 -1
  82. package/dist/machines/slider/index.d.mts +1 -1
  83. package/dist/machines/steps/index.d.cts +1 -1
  84. package/dist/machines/steps/index.d.mts +1 -1
  85. package/dist/machines/switch/index.d.cts +1 -1
  86. package/dist/machines/switch/index.d.mts +1 -1
  87. package/dist/machines/tabs/index.d.cts +1 -1
  88. package/dist/machines/tabs/index.d.mts +1 -1
  89. package/dist/machines/tags-input/index.d.cts +1 -1
  90. package/dist/machines/tags-input/index.d.mts +1 -1
  91. package/dist/machines/timer/index.d.cts +1 -1
  92. package/dist/machines/timer/index.d.mts +1 -1
  93. package/dist/machines/toast/index.d.cts +1 -1
  94. package/dist/machines/toast/index.d.mts +1 -1
  95. package/dist/machines/tooltip/index.d.cts +1 -1
  96. package/dist/machines/tooltip/index.d.mts +1 -1
  97. package/dist/machines/tour/index.cjs +1 -1
  98. package/dist/machines/tour/index.d.cts +1 -1
  99. package/dist/machines/tour/index.d.mts +1 -1
  100. package/dist/machines/tour/index.mjs +1 -1
  101. package/dist/machines/tree-view/index.cjs +1 -1
  102. package/dist/machines/tree-view/index.d.cts +1 -1
  103. package/dist/machines/tree-view/index.d.mts +1 -1
  104. package/dist/machines/tree-view/index.mjs +1 -1
  105. package/dist/{selection-DdNvrKbj.d.mts → selection-6urf-c8j.d.mts} +1 -1
  106. package/dist/{selection-Bb_ZSVxe.d.cts → selection-BmS2RDMq.d.cts} +1 -1
  107. package/package.json +13 -1
@@ -0,0 +1,1813 @@
1
+ import { t as createAnatomy } from "../../create-anatomy-Dr0evdYy.mjs";
2
+ import { C as queryAll, W as raf, a as visuallyHiddenStyle, bn as ariaAttr, ft as getEventKey, gt as getNativeEvent, xn as dataAttr } from "../../dom-query-BFuRs3l4.mjs";
3
+ import { t as _defineProperty } from "../../defineProperty-D5oW_HU_.mjs";
4
+ import { u as createSplitProps } from "../../utils-VVoZ_v29.mjs";
5
+ import { a as createMachine, h as memo } from "../../core-CTtbW9qh.mjs";
6
+ import { F as isDateEqual, K as constrainValue, p as getTodayDate } from "../../date-utils-BdeeOQRI.mjs";
7
+ import { t as createLiveRegion } from "../../live-region-TgEDzvS4.mjs";
8
+ import { t as createProps } from "../../create-props-DFW8DUsC.mjs";
9
+ import { CalendarDate, DateFormatter, parseDate, toCalendarDateTime } from "@internationalized/date";
10
+ //#region src/machines/date-input/date-input.anatomy.ts
11
+ const anatomy = createAnatomy("date-input").parts("root", "label", "control", "segmentGroup", "segment", "hiddenInput");
12
+ const parts = anatomy.build();
13
+ //#endregion
14
+ //#region src/machines/date-input/date-input.dom.ts
15
+ const getRootId = (ctx) => ctx.ids?.root ?? `date-input:${ctx.id}`;
16
+ const getLabelId = (ctx, index) => ctx.ids?.label?.(index) ?? `date-input:${ctx.id}:label:${index}`;
17
+ const getControlId = (ctx) => ctx.ids?.control ?? `date-input:${ctx.id}:control`;
18
+ const getSegmentGroupId = (ctx, index) => ctx.ids?.segmentGroup?.(index) ?? `date-input:${ctx.id}:segment-group:${index}`;
19
+ const getHiddenInputId = (ctx, index) => ctx.ids?.hiddenInput?.(index) ?? `date-input:${ctx.id}:hidden-input:${index}`;
20
+ const getControlEl = (ctx) => ctx.getById(getControlId(ctx));
21
+ const getSegmentEls = (ctx) => queryAll(getControlEl(ctx), `[data-part=segment]`);
22
+ //#endregion
23
+ //#region src/machines/date-input/utils/locale.ts
24
+ const isValidCharacter = (char, separator) => {
25
+ if (!char) return true;
26
+ return /\d/.test(char) || char === separator || char.length !== 1;
27
+ };
28
+ function getLocaleSeparator(locale) {
29
+ const literalPart = new Intl.DateTimeFormat(locale).formatToParts(/* @__PURE__ */ new Date()).find((part) => part.type === "literal");
30
+ return literalPart ? literalPart.value : "/";
31
+ }
32
+ //#endregion
33
+ //#region src/machines/date-input/utils/segments.ts
34
+ const EDITABLE_SEGMENTS = {
35
+ year: true,
36
+ month: true,
37
+ day: true,
38
+ hour: true,
39
+ minute: true,
40
+ second: true,
41
+ dayPeriod: true,
42
+ era: true,
43
+ literal: false,
44
+ timeZoneName: false,
45
+ weekday: false,
46
+ unknown: false,
47
+ fractionalSecond: false
48
+ };
49
+ const PAGE_STEP = {
50
+ year: 5,
51
+ month: 2,
52
+ day: 7,
53
+ hour: 2,
54
+ minute: 15,
55
+ second: 15,
56
+ dayPeriod: void 0,
57
+ era: void 0,
58
+ literal: void 0,
59
+ timeZoneName: void 0,
60
+ weekday: void 0,
61
+ unknown: void 0,
62
+ fractionalSecond: void 0
63
+ };
64
+ const SEGMENT_LABELS = {
65
+ era: "Era",
66
+ year: "Year",
67
+ month: "Month",
68
+ day: "Day",
69
+ hour: "Hour",
70
+ minute: "Minute",
71
+ second: "Second",
72
+ dayPeriod: "AM/PM",
73
+ timeZoneName: "Time zone"
74
+ };
75
+ function getSegmentLabel(type) {
76
+ return SEGMENT_LABELS[type] ?? type;
77
+ }
78
+ const TYPE_MAPPING = {
79
+ dayperiod: "dayPeriod",
80
+ relatedYear: "year",
81
+ yearName: "literal",
82
+ unknown: "literal"
83
+ };
84
+ function getSafeType(type) {
85
+ return TYPE_MAPPING[type] ?? type;
86
+ }
87
+ function getPlaceholder(type, translations, locale) {
88
+ return translations.placeholder(locale)[type];
89
+ }
90
+ function isEditableSegment(type) {
91
+ return EDITABLE_SEGMENTS[type] === true;
92
+ }
93
+ function getSafeFormatParts(formatter, dateValue, displayValue) {
94
+ try {
95
+ return formatter.formatToParts(dateValue);
96
+ } catch {
97
+ return formatter.formatToParts(/* @__PURE__ */ new Date()).map((part) => {
98
+ switch (part.type) {
99
+ case "year":
100
+ case "relatedYear": return {
101
+ ...part,
102
+ value: String(displayValue.year ?? 0)
103
+ };
104
+ case "month": return {
105
+ ...part,
106
+ value: String(displayValue.month ?? 0)
107
+ };
108
+ case "day": return {
109
+ ...part,
110
+ value: String(displayValue.day ?? 0)
111
+ };
112
+ }
113
+ return part;
114
+ });
115
+ }
116
+ }
117
+ function processSegments({ dateValue, displayValue, formatter, locale, translations, granularity }) {
118
+ const timeValue = [
119
+ "hour",
120
+ "minute",
121
+ "second"
122
+ ];
123
+ const segments = getSafeFormatParts(formatter, dateValue, displayValue);
124
+ const processedSegments = [];
125
+ for (const segment of segments) {
126
+ const type = getSafeType(segment.type);
127
+ let isEditable = isEditableSegment(type);
128
+ if (type === "era" && displayValue.calendar.getEras().length === 1) isEditable = false;
129
+ const isPlaceholder = isEditable && displayValue[type] == null;
130
+ let placeholder = isEditableSegment(type) ? getPlaceholder(type, translations, locale) : null;
131
+ if ((type === "dayPeriod" || type === "era") && segment.value) placeholder = segment.value;
132
+ const dateSegment = {
133
+ type,
134
+ text: isPlaceholder ? placeholder : segment.value,
135
+ ...displayValue.getSegmentLimits(type) ?? {},
136
+ isPlaceholder,
137
+ placeholder,
138
+ isEditable
139
+ };
140
+ if (type === "hour") {
141
+ processedSegments.push({
142
+ type: "literal",
143
+ text: "⁦",
144
+ isPlaceholder: false,
145
+ placeholder: "",
146
+ isEditable: false
147
+ });
148
+ processedSegments.push(dateSegment);
149
+ if (type === granularity) processedSegments.push({
150
+ type: "literal",
151
+ text: "⁩",
152
+ isPlaceholder: false,
153
+ placeholder: "",
154
+ isEditable: false
155
+ });
156
+ } else if (timeValue.includes(type) && type === granularity) {
157
+ processedSegments.push(dateSegment);
158
+ processedSegments.push({
159
+ type: "literal",
160
+ text: "⁩",
161
+ isPlaceholder: false,
162
+ placeholder: "",
163
+ isEditable: false
164
+ });
165
+ } else processedSegments.push(dateSegment);
166
+ }
167
+ return processedSegments;
168
+ }
169
+ //#endregion
170
+ //#region src/machines/date-input/utils/validity.ts
171
+ function getGroupOffset(allSegments, index) {
172
+ return allSegments.slice(0, index).reduce((acc, segs) => acc + segs.length, 0);
173
+ }
174
+ function resolveActiveSegment(ctx) {
175
+ const { context, computed } = ctx;
176
+ const index = context.get("activeIndex");
177
+ const activeSegmentIndex = context.get("activeSegmentIndex");
178
+ const allSegments = computed("segments");
179
+ const offset = getGroupOffset(allSegments, index);
180
+ return {
181
+ allSegments,
182
+ segments: allSegments[index],
183
+ offset,
184
+ localIndex: activeSegmentIndex - offset
185
+ };
186
+ }
187
+ function getActiveSegment(ctx) {
188
+ const { allSegments, localIndex } = resolveActiveSegment(ctx);
189
+ return allSegments[ctx.context.get("activeIndex")]?.[localIndex];
190
+ }
191
+ function advanceToNextSegment(ctx) {
192
+ const { context } = ctx;
193
+ const index = context.get("activeIndex");
194
+ const { allSegments, segments, offset, localIndex } = resolveActiveSegment(ctx);
195
+ const nextLocalIndex = segments.findIndex((s, i) => i > localIndex && s.isEditable);
196
+ if (nextLocalIndex !== -1) {
197
+ context.set("activeSegmentIndex", offset + nextLocalIndex);
198
+ return;
199
+ }
200
+ const nextGroupSegments = allSegments[index + 1];
201
+ if (!nextGroupSegments) return;
202
+ const firstNextGroupEditableLocalIndex = nextGroupSegments.findIndex((s) => s.isEditable);
203
+ if (firstNextGroupEditableLocalIndex === -1) return;
204
+ context.set("activeIndex", index + 1);
205
+ context.set("activeSegmentIndex", offset + segments.length + firstNextGroupEditableLocalIndex);
206
+ }
207
+ function getActiveDisplayValue(ctx) {
208
+ const index = ctx.context.get("activeIndex");
209
+ return ctx.context.get("displayValues")[index];
210
+ }
211
+ function setDisplayValue(ctx, index, dv) {
212
+ const displayValues = [...ctx.context.get("displayValues")];
213
+ displayValues[index] = dv;
214
+ ctx.context.set("displayValues", displayValues);
215
+ }
216
+ //#endregion
217
+ //#region src/machines/date-input/date-input.connect.ts
218
+ function connect(service, normalize) {
219
+ const { state, context, prop, send, computed, scope } = service;
220
+ const disabled = Boolean(prop("disabled"));
221
+ const readOnly = Boolean(prop("readOnly"));
222
+ const invalid = Boolean(prop("invalid"));
223
+ const focused = state.matches("focused");
224
+ const separator = getLocaleSeparator(prop("locale"));
225
+ function getSegmentState(props) {
226
+ const { segment } = props;
227
+ return { editable: !disabled && !readOnly && segment.isEditable };
228
+ }
229
+ return {
230
+ focused,
231
+ disabled,
232
+ invalid,
233
+ groupCount: computed("segments").length,
234
+ value: context.get("value"),
235
+ valueAsDate: context.get("value").filter((date) => date != null).map((date) => date.toDate(prop("timeZone"))),
236
+ valueAsString: computed("valueAsString"),
237
+ placeholderValue: context.get("placeholderValue"),
238
+ displayValues: context.get("displayValues"),
239
+ setValue(values) {
240
+ send({
241
+ type: "VALUE.SET",
242
+ value: values
243
+ });
244
+ },
245
+ clearValue() {
246
+ send({ type: "VALUE.CLEAR" });
247
+ },
248
+ getSegments(props = {}) {
249
+ const { index = 0 } = props;
250
+ const allSegments = computed("segments");
251
+ const segments = allSegments[index] ?? [];
252
+ const enteredKeys = context.get("enteredKeys");
253
+ const activeIndex = context.get("activeIndex");
254
+ const activeSegmentIndex = context.get("activeSegmentIndex");
255
+ if (focused && enteredKeys && index === activeIndex && activeSegmentIndex >= 0) {
256
+ const localActiveSegmentIndex = activeSegmentIndex - getGroupOffset(allSegments, index);
257
+ return segments.map((seg, i) => {
258
+ if (i !== localActiveSegmentIndex) return seg;
259
+ return {
260
+ ...seg,
261
+ text: enteredKeys,
262
+ isPlaceholder: false
263
+ };
264
+ });
265
+ }
266
+ return segments;
267
+ },
268
+ getSegmentState,
269
+ getRootProps() {
270
+ return normalize.element({
271
+ ...parts.root.attrs,
272
+ dir: prop("dir"),
273
+ id: getRootId(scope),
274
+ "data-disabled": dataAttr(disabled),
275
+ "data-readonly": dataAttr(readOnly),
276
+ "data-invalid": dataAttr(invalid)
277
+ });
278
+ },
279
+ getLabelProps(props = {}) {
280
+ const { index = 0 } = props;
281
+ return normalize.label({
282
+ ...parts.label.attrs,
283
+ id: getLabelId(scope, index),
284
+ dir: prop("dir"),
285
+ htmlFor: getSegmentGroupId(scope, index),
286
+ "data-disabled": dataAttr(disabled),
287
+ "data-readonly": dataAttr(readOnly),
288
+ "data-invalid": dataAttr(invalid)
289
+ });
290
+ },
291
+ getControlProps() {
292
+ return normalize.element({
293
+ ...parts.control.attrs,
294
+ dir: prop("dir"),
295
+ id: getControlId(scope),
296
+ "data-disabled": dataAttr(disabled),
297
+ "data-readonly": dataAttr(readOnly),
298
+ "data-invalid": dataAttr(invalid),
299
+ "data-focus": dataAttr(focused)
300
+ });
301
+ },
302
+ getSegmentGroupProps(props = {}) {
303
+ const { index = 0 } = props;
304
+ return normalize.element({
305
+ ...parts.segmentGroup.attrs,
306
+ id: getSegmentGroupId(scope, index),
307
+ dir: prop("dir"),
308
+ role: "group",
309
+ "aria-labelledby": getLabelId(scope, index),
310
+ "data-disabled": dataAttr(disabled),
311
+ "data-readonly": dataAttr(readOnly),
312
+ "data-invalid": dataAttr(invalid),
313
+ "data-focus": dataAttr(focused),
314
+ style: { unicodeBidi: "isolate" }
315
+ });
316
+ },
317
+ getSegmentProps(props) {
318
+ const { segment, index = 0 } = props;
319
+ const segmentState = getSegmentState(props);
320
+ if (segment.type === "literal") return normalize.element({
321
+ ...parts.segment.attrs,
322
+ dir: prop("dir"),
323
+ "aria-hidden": true,
324
+ "data-type": segment.type,
325
+ "data-readonly": dataAttr(true),
326
+ "data-disabled": dataAttr(true)
327
+ });
328
+ return normalize.element({
329
+ ...parts.segment.attrs,
330
+ dir: prop("dir"),
331
+ role: "spinbutton",
332
+ tabIndex: disabled ? void 0 : 0,
333
+ autoComplete: "off",
334
+ spellCheck: segmentState.editable ? "false" : void 0,
335
+ autoCorrect: segmentState.editable ? "off" : void 0,
336
+ contentEditable: segmentState.editable,
337
+ suppressContentEditableWarning: segmentState.editable,
338
+ inputMode: disabled || segment.type === "dayPeriod" || segment.type === "era" || !segmentState.editable ? void 0 : "numeric",
339
+ enterKeyHint: "next",
340
+ "aria-label": getSegmentLabel(segment.type),
341
+ "aria-valuenow": segment.isPlaceholder ? void 0 : segment.value,
342
+ "aria-valuetext": segment.isPlaceholder ? segment.placeholder : segment.text,
343
+ "aria-valuemin": segment.minValue,
344
+ "aria-valuemax": segment.maxValue,
345
+ "aria-invalid": ariaAttr(invalid),
346
+ "aria-readonly": ariaAttr(!segment.isEditable || readOnly),
347
+ "aria-disabled": ariaAttr(disabled),
348
+ "data-value": segment.value,
349
+ "data-type": segment.type,
350
+ "data-readonly": dataAttr(!segment.isEditable || readOnly),
351
+ "data-disabled": dataAttr(disabled),
352
+ "data-editable": dataAttr(segment.isEditable && !readOnly && !disabled),
353
+ "data-placeholder": dataAttr(segment.isPlaceholder),
354
+ style: { caretColor: "transparent" },
355
+ onFocus(event) {
356
+ send({
357
+ type: "SEGMENT.FOCUS",
358
+ dateIndex: index,
359
+ segmentIndex: getSegmentEls(scope).indexOf(event.currentTarget)
360
+ });
361
+ const selection = event.currentTarget?.ownerDocument?.getSelection?.();
362
+ if (selection && event.currentTarget) selection.collapse(event.currentTarget);
363
+ },
364
+ onBlur() {
365
+ send({
366
+ type: "SEGMENT.BLUR",
367
+ index: -1
368
+ });
369
+ },
370
+ onKeyDown(event) {
371
+ if (event.defaultPrevented || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey || readOnly || event.nativeEvent.isComposing) return;
372
+ const exec = {
373
+ ArrowLeft() {
374
+ send({ type: "SEGMENT.ARROW_LEFT" });
375
+ },
376
+ ArrowRight() {
377
+ send({ type: "SEGMENT.ARROW_RIGHT" });
378
+ },
379
+ ArrowUp() {
380
+ send({
381
+ type: "SEGMENT.ADJUST",
382
+ segment,
383
+ amount: 1
384
+ });
385
+ },
386
+ ArrowDown() {
387
+ send({
388
+ type: "SEGMENT.ADJUST",
389
+ segment,
390
+ amount: -1
391
+ });
392
+ },
393
+ PageUp() {
394
+ send({
395
+ type: "SEGMENT.ADJUST",
396
+ segment,
397
+ amount: PAGE_STEP[segment.type] ?? 1
398
+ });
399
+ },
400
+ PageDown() {
401
+ send({
402
+ type: "SEGMENT.ADJUST",
403
+ segment,
404
+ amount: -(PAGE_STEP[segment.type] ?? 1)
405
+ });
406
+ },
407
+ Backspace() {
408
+ send({
409
+ type: "SEGMENT.BACKSPACE",
410
+ segment
411
+ });
412
+ },
413
+ Delete() {
414
+ send({
415
+ type: "SEGMENT.BACKSPACE",
416
+ segment
417
+ });
418
+ },
419
+ Home() {
420
+ send({
421
+ type: "SEGMENT.HOME",
422
+ segment
423
+ });
424
+ },
425
+ End() {
426
+ send({
427
+ type: "SEGMENT.END",
428
+ segment
429
+ });
430
+ }
431
+ }[getEventKey(event, { dir: prop("dir") })];
432
+ if (exec) {
433
+ exec(event);
434
+ event.preventDefault();
435
+ event.stopPropagation();
436
+ }
437
+ },
438
+ onPointerDown(event) {
439
+ event.stopPropagation();
440
+ },
441
+ onMouseDown(event) {
442
+ event.stopPropagation();
443
+ },
444
+ onBeforeInput(event) {
445
+ const { data, inputType } = getNativeEvent(event);
446
+ if ([
447
+ "deleteContentBackward",
448
+ "deleteContentForward",
449
+ "deleteByCut",
450
+ "deleteByDrag"
451
+ ].includes(inputType)) {
452
+ event.preventDefault();
453
+ return;
454
+ }
455
+ if (inputType === "insertFromPaste") {
456
+ event.preventDefault();
457
+ return;
458
+ }
459
+ if (inputType === "insertCompositionText") {
460
+ if (event.currentTarget || event.target) {
461
+ event.preventDefault();
462
+ if (data != null) send({
463
+ type: "SEGMENT.INPUT",
464
+ segment,
465
+ input: data
466
+ });
467
+ }
468
+ return;
469
+ }
470
+ const isTextSegment = segment.type === "dayPeriod" || segment.type === "era";
471
+ if (data && (isTextSegment || isValidCharacter(data, separator))) {
472
+ event.preventDefault();
473
+ send({
474
+ type: "SEGMENT.INPUT",
475
+ segment,
476
+ input: data
477
+ });
478
+ } else event.preventDefault();
479
+ },
480
+ onPaste(event) {
481
+ event.preventDefault();
482
+ }
483
+ });
484
+ },
485
+ getHiddenInputProps(props = {}) {
486
+ const { index = 0, name } = props;
487
+ const value = context.get("value");
488
+ const inputName = name || prop("name");
489
+ return normalize.input({
490
+ ...parts.hiddenInput.attrs,
491
+ type: "hidden",
492
+ id: getHiddenInputId(scope, index),
493
+ name: inputName ? value.length > 1 ? `${inputName}[${index}]` : inputName : void 0,
494
+ form: prop("form"),
495
+ required: prop("required"),
496
+ disabled,
497
+ readOnly,
498
+ value: computed("valueAsString")[index] ?? "",
499
+ style: visuallyHiddenStyle
500
+ });
501
+ }
502
+ };
503
+ }
504
+ //#endregion
505
+ //#region src/machines/date-input/utils/incomplete-date.ts
506
+ var IncompleteDate = class IncompleteDate {
507
+ constructor(calendar, hourCycle, dateValue) {
508
+ _defineProperty(this, "calendar", void 0);
509
+ _defineProperty(this, "era", void 0);
510
+ _defineProperty(this, "year", void 0);
511
+ _defineProperty(this, "month", void 0);
512
+ _defineProperty(this, "day", void 0);
513
+ _defineProperty(this, "hour", void 0);
514
+ _defineProperty(this, "hourCycle", void 0);
515
+ _defineProperty(this, "dayPeriod", void 0);
516
+ _defineProperty(this, "minute", void 0);
517
+ _defineProperty(this, "second", void 0);
518
+ _defineProperty(this, "millisecond", void 0);
519
+ _defineProperty(this, "offset", void 0);
520
+ this.era = dateValue?.era ?? null;
521
+ this.calendar = calendar;
522
+ this.year = dateValue?.year ?? null;
523
+ this.month = dateValue?.month ?? null;
524
+ this.day = dateValue?.day ?? null;
525
+ this.hour = dateValue?.hour ?? null;
526
+ this.hourCycle = hourCycle;
527
+ this.dayPeriod = null;
528
+ this.minute = dateValue?.minute ?? null;
529
+ this.second = dateValue?.second ?? null;
530
+ this.millisecond = dateValue?.millisecond ?? null;
531
+ this.offset = "offset" in (dateValue ?? {}) ? dateValue.offset : null;
532
+ if (this.hour != null) {
533
+ const [dayPeriod, hour] = toHourCycle(this.hour, hourCycle);
534
+ this.dayPeriod = dayPeriod;
535
+ this.hour = hour;
536
+ }
537
+ }
538
+ copy() {
539
+ const res = new IncompleteDate(this.calendar, this.hourCycle);
540
+ res.era = this.era;
541
+ res.year = this.year;
542
+ res.month = this.month;
543
+ res.day = this.day;
544
+ res.hour = this.hour;
545
+ res.dayPeriod = this.dayPeriod;
546
+ res.minute = this.minute;
547
+ res.second = this.second;
548
+ res.millisecond = this.millisecond;
549
+ res.offset = this.offset;
550
+ return res;
551
+ }
552
+ isComplete(segments) {
553
+ return segments.every((segment) => this[segment] != null);
554
+ }
555
+ isCleared(segments) {
556
+ return segments.every((segment) => this[segment] === null);
557
+ }
558
+ set(field, value, placeholder) {
559
+ const result = this.copy();
560
+ result[field] = value;
561
+ if (field === "hour" && result.dayPeriod == null && "hour" in placeholder) result.dayPeriod = toHourCycle(placeholder.hour, this.hourCycle)[0];
562
+ if (field === "year" && result.era == null) result.era = placeholder.era;
563
+ if (field !== "second" && field !== "literal" && field !== "timeZoneName") result.offset = null;
564
+ return result;
565
+ }
566
+ clear(field) {
567
+ const result = this.copy();
568
+ result[field] = null;
569
+ if (field === "year") result.era = null;
570
+ result.offset = null;
571
+ return result;
572
+ }
573
+ cycle(field, amount, placeholder, displaySegments) {
574
+ const res = this.copy();
575
+ if (res[field] == null && field !== "dayPeriod" && field !== "era") {
576
+ if (field === "hour" && "hour" in placeholder) {
577
+ const [dayPeriod, hour] = toHourCycle(placeholder.hour, this.hourCycle);
578
+ res.dayPeriod = dayPeriod;
579
+ res.hour = hour;
580
+ } else res[field] = placeholder[field];
581
+ if (field === "year" && res.era == null) res.era = placeholder.era;
582
+ return res;
583
+ }
584
+ switch (field) {
585
+ case "era": {
586
+ const eras = this.calendar.getEras();
587
+ let index = eras.indexOf(res.era);
588
+ index = cycleValue(index, amount, 0, eras.length - 1);
589
+ res.era = eras[index];
590
+ break;
591
+ }
592
+ case "year": {
593
+ let date = new CalendarDate(this.calendar, this.era ?? placeholder.era, this.year ?? placeholder.year, this.month ?? 1, this.day ?? 1);
594
+ date = date.cycle(field, amount, { round: field === "year" });
595
+ res.era = date.era;
596
+ res.year = date.year;
597
+ break;
598
+ }
599
+ case "month":
600
+ res.month = cycleValue(res.month ?? 1, amount, 1, this.calendar.getMaximumMonthsInYear());
601
+ break;
602
+ case "day":
603
+ res.day = cycleValue(res.day ?? 1, amount, 1, this.calendar.getMaximumDaysInMonth());
604
+ break;
605
+ case "hour": {
606
+ const hasDateSegments = displaySegments.some((s) => [
607
+ "year",
608
+ "month",
609
+ "day"
610
+ ].includes(s));
611
+ if ("timeZone" in placeholder && (!hasDateSegments || res.year != null && res.month != null && res.day != null)) {
612
+ let date = this.toValue(placeholder);
613
+ date = date.cycle("hour", amount, {
614
+ hourCycle: this.hourCycle === "h12" ? 12 : 24,
615
+ round: false
616
+ });
617
+ const [dayPeriod, adjustedHour] = toHourCycle(date.hour, this.hourCycle);
618
+ res.hour = adjustedHour;
619
+ res.dayPeriod = dayPeriod;
620
+ res.offset = date.offset;
621
+ } else {
622
+ const hours = res.hour ?? 0;
623
+ const limits = this.getSegmentLimits("hour");
624
+ res.hour = cycleValue(hours, amount, limits.minValue, limits.maxValue);
625
+ if (res.dayPeriod == null && "hour" in placeholder) res.dayPeriod = toHourCycle(placeholder.hour, this.hourCycle)[0];
626
+ }
627
+ break;
628
+ }
629
+ case "dayPeriod":
630
+ res.dayPeriod = cycleValue(res.dayPeriod ?? 0, amount, 0, 1);
631
+ break;
632
+ case "minute":
633
+ res.minute = cycleValue(res.minute ?? 0, amount, 0, 59, true);
634
+ break;
635
+ case "second":
636
+ res.second = cycleValue(res.second ?? 0, amount, 0, 59, true);
637
+ break;
638
+ }
639
+ return res;
640
+ }
641
+ toValue(value) {
642
+ if ("hour" in value) {
643
+ let hour = this.hour;
644
+ if (hour != null) hour = fromHourCycle(hour, this.dayPeriod ?? 0, this.hourCycle);
645
+ else if (this.hourCycle === "h12" || this.hourCycle === "h11") hour = this.dayPeriod === 1 ? 12 : 0;
646
+ const res = value.set({
647
+ era: this.era ?? value.era,
648
+ year: this.year ?? value.year,
649
+ month: this.month ?? value.month,
650
+ day: this.day ?? value.day,
651
+ hour: hour ?? value.hour,
652
+ minute: this.minute ?? value.minute,
653
+ second: this.second ?? value.second,
654
+ millisecond: this.millisecond ?? value.millisecond
655
+ });
656
+ if ("offset" in res && this.offset != null && res.offset !== this.offset) return res.add({ milliseconds: res.offset - this.offset });
657
+ return res;
658
+ } else return value.set({
659
+ era: this.era ?? value.era,
660
+ year: this.year ?? value.year,
661
+ month: this.month ?? value.month,
662
+ day: this.day ?? value.day
663
+ });
664
+ }
665
+ getSegmentLimits(type) {
666
+ switch (type) {
667
+ case "era": {
668
+ const eras = this.calendar.getEras();
669
+ return {
670
+ value: this.era != null ? eras.indexOf(this.era) : eras.length - 1,
671
+ minValue: 0,
672
+ maxValue: eras.length - 1
673
+ };
674
+ }
675
+ case "year": return {
676
+ value: this.year,
677
+ minValue: 1,
678
+ maxValue: 9999
679
+ };
680
+ case "month": return {
681
+ value: this.month,
682
+ minValue: 1,
683
+ maxValue: this.calendar.getMaximumMonthsInYear()
684
+ };
685
+ case "day": return {
686
+ value: this.day,
687
+ minValue: 1,
688
+ maxValue: this.calendar.getMaximumDaysInMonth()
689
+ };
690
+ case "dayPeriod": return {
691
+ value: this.dayPeriod,
692
+ minValue: 0,
693
+ maxValue: 1
694
+ };
695
+ case "hour": {
696
+ let minValue = 0;
697
+ let maxValue = 23;
698
+ if (this.hourCycle === "h12") {
699
+ minValue = 1;
700
+ maxValue = 12;
701
+ } else if (this.hourCycle === "h11") {
702
+ minValue = 0;
703
+ maxValue = 11;
704
+ }
705
+ return {
706
+ value: this.hour,
707
+ minValue,
708
+ maxValue
709
+ };
710
+ }
711
+ case "minute": return {
712
+ value: this.minute,
713
+ minValue: 0,
714
+ maxValue: 59
715
+ };
716
+ case "second": return {
717
+ value: this.second,
718
+ minValue: 0,
719
+ maxValue: 59
720
+ };
721
+ }
722
+ }
723
+ toString() {
724
+ const fields = {
725
+ era: this.era,
726
+ year: this.year,
727
+ month: this.month,
728
+ day: this.day,
729
+ hour: this.hour,
730
+ dayPeriod: this.dayPeriod,
731
+ minute: this.minute,
732
+ second: this.second
733
+ };
734
+ const parts = Object.entries(fields).filter(([, v]) => v != null).map(([k, v]) => `${k}=${v}`);
735
+ return parts.length > 0 ? parts.join(",") : "-";
736
+ }
737
+ };
738
+ function cycleValue(value, amount, min, max, round = false) {
739
+ if (round) {
740
+ value += Math.sign(amount);
741
+ if (value < min) value = max;
742
+ const div = Math.abs(amount);
743
+ if (amount > 0) value = Math.ceil(value / div) * div;
744
+ else value = Math.floor(value / div) * div;
745
+ if (value > max) value = min;
746
+ } else {
747
+ value += amount;
748
+ if (value < min) value = max - (min - value - 1);
749
+ else if (value > max) value = min + (value - max - 1);
750
+ }
751
+ return value;
752
+ }
753
+ function toHourCycle(hour, hourCycle) {
754
+ let dayPeriod = hour >= 12 ? 1 : 0;
755
+ switch (hourCycle) {
756
+ case "h11":
757
+ if (hour >= 12) hour -= 12;
758
+ break;
759
+ case "h12":
760
+ if (hour === 0) hour = 12;
761
+ else if (hour > 12) hour -= 12;
762
+ break;
763
+ case "h23":
764
+ dayPeriod = null;
765
+ break;
766
+ case "h24":
767
+ hour += 1;
768
+ dayPeriod = null;
769
+ }
770
+ return [dayPeriod, hour];
771
+ }
772
+ function fromHourCycle(hour, dayPeriod, hourCycle) {
773
+ switch (hourCycle) {
774
+ case "h11":
775
+ if (dayPeriod === 1) hour += 12;
776
+ break;
777
+ case "h12":
778
+ if (hour === 12) hour = 0;
779
+ if (dayPeriod === 1) hour += 12;
780
+ break;
781
+ case "h24":
782
+ hour -= 1;
783
+ break;
784
+ }
785
+ return hour;
786
+ }
787
+ //#endregion
788
+ //#region src/machines/date-input/utils/input.ts
789
+ function isNumberString(value) {
790
+ return !Number.isNaN(Number.parseInt(value));
791
+ }
792
+ function updateSegmentValue(ctx, segment, input) {
793
+ const { context, prop } = ctx;
794
+ const type = segment.type;
795
+ const index = context.get("activeIndex");
796
+ const formatter = prop("formatter");
797
+ const enteredKeys = context.get("enteredKeys");
798
+ const placeholderValue = context.get("placeholderValue");
799
+ let dv = getActiveDisplayValue(ctx);
800
+ switch (type) {
801
+ case "dayPeriod": {
802
+ if (!("hour" in dv.toValue(placeholderValue))) return;
803
+ const amPmFormatter = new DateFormatter(prop("locale"), {
804
+ hour: "numeric",
805
+ hour12: true
806
+ });
807
+ const amDate = /* @__PURE__ */ new Date();
808
+ amDate.setHours(0);
809
+ const pmDate = /* @__PURE__ */ new Date();
810
+ pmDate.setHours(12);
811
+ const am = amPmFormatter.formatToParts(amDate).find((p) => p.type === "dayPeriod")?.value || "AM";
812
+ const pm = amPmFormatter.formatToParts(pmDate).find((p) => p.type === "dayPeriod")?.value || "PM";
813
+ const lowerInput = input.toLowerCase();
814
+ if (am.toLowerCase().startsWith(lowerInput)) setDisplayValue(ctx, index, dv.set("dayPeriod", 0, placeholderValue));
815
+ else if (pm.toLowerCase().startsWith(lowerInput)) setDisplayValue(ctx, index, dv.set("dayPeriod", 12, placeholderValue));
816
+ else break;
817
+ advanceToNextSegment(ctx);
818
+ break;
819
+ }
820
+ case "era": {
821
+ const eras = dv.calendar.getEras();
822
+ const eraFormatter = new DateFormatter(prop("locale"), { era: "short" });
823
+ const lowerInput = input.toLowerCase();
824
+ for (let i = 0; i < eras.length; i++) {
825
+ const eraDate = dv.toValue(placeholderValue).set({ year: 1 }).toDate(prop("timeZone"));
826
+ const formattedEra = eraFormatter.formatToParts(eraDate).find((p) => p.type === "era")?.value;
827
+ if (formattedEra && formattedEra.toLowerCase().startsWith(lowerInput)) {
828
+ setDisplayValue(ctx, index, dv.set("era", eras[i], placeholderValue));
829
+ advanceToNextSegment(ctx);
830
+ break;
831
+ }
832
+ }
833
+ break;
834
+ }
835
+ case "day":
836
+ case "hour":
837
+ case "minute":
838
+ case "second":
839
+ case "month":
840
+ case "year": {
841
+ let newValue = enteredKeys + input;
842
+ let numberValue = Number.parseInt(newValue);
843
+ let segmentValue = numberValue;
844
+ let allowsZero = segment.minValue === 0;
845
+ if (!isNumberString(input)) return;
846
+ if (segment.type === "hour" && formatter.resolvedOptions().hour12) {
847
+ switch (formatter.resolvedOptions().hourCycle) {
848
+ case "h11":
849
+ if (numberValue > 11) segmentValue = Number.parseInt(input);
850
+ break;
851
+ case "h12":
852
+ allowsZero = false;
853
+ if (numberValue > 12) segmentValue = Number.parseInt(input);
854
+ break;
855
+ }
856
+ if (segment.value !== void 0 && segment.value >= 12 && numberValue > 1) numberValue += 12;
857
+ } else if (segment.maxValue !== void 0 && numberValue > segment.maxValue) segmentValue = Number.parseInt(input);
858
+ if (isNaN(numberValue)) return;
859
+ const shouldSetValue = segmentValue !== 0 || allowsZero;
860
+ if (shouldSetValue) {
861
+ dv = dv.set(type, segmentValue, placeholderValue);
862
+ setDisplayValue(ctx, index, dv);
863
+ }
864
+ if (segment.maxValue !== void 0 && (Number(numberValue + "0") > segment.maxValue || newValue.length >= String(segment.maxValue).length)) {
865
+ context.set("enteredKeys", "");
866
+ if (shouldSetValue) advanceToNextSegment(ctx);
867
+ } else context.set("enteredKeys", newValue);
868
+ break;
869
+ }
870
+ }
871
+ }
872
+ //#endregion
873
+ //#region src/machines/date-input/utils/placeholders.ts
874
+ const LOCALE_PLACEHOLDERS = {
875
+ ach: {
876
+ year: "mwaka",
877
+ month: "dwe",
878
+ day: "nino"
879
+ },
880
+ af: {
881
+ year: "jjjj",
882
+ month: "mm",
883
+ day: "dd"
884
+ },
885
+ am: {
886
+ year: "ዓዓዓዓ",
887
+ month: "ሚሜ",
888
+ day: "ቀቀ"
889
+ },
890
+ an: {
891
+ year: "aaaa",
892
+ month: "mm",
893
+ day: "dd"
894
+ },
895
+ ar: {
896
+ year: "سنة",
897
+ month: "شهر",
898
+ day: "يوم"
899
+ },
900
+ ast: {
901
+ year: "aaaa",
902
+ month: "mm",
903
+ day: "dd"
904
+ },
905
+ az: {
906
+ year: "iiii",
907
+ month: "aa",
908
+ day: "gg"
909
+ },
910
+ be: {
911
+ year: "гггг",
912
+ month: "мм",
913
+ day: "дд"
914
+ },
915
+ bg: {
916
+ year: "гггг",
917
+ month: "мм",
918
+ day: "дд"
919
+ },
920
+ bn: {
921
+ year: "yyyy",
922
+ month: "মিমি",
923
+ day: "dd"
924
+ },
925
+ br: {
926
+ year: "bbbb",
927
+ month: "mm",
928
+ day: "dd"
929
+ },
930
+ bs: {
931
+ year: "gggg",
932
+ month: "mm",
933
+ day: "dd"
934
+ },
935
+ ca: {
936
+ year: "aaaa",
937
+ month: "mm",
938
+ day: "dd"
939
+ },
940
+ cak: {
941
+ year: "jjjj",
942
+ month: "ii",
943
+ day: "q'q'"
944
+ },
945
+ ckb: {
946
+ year: "ساڵ",
947
+ month: "مانگ",
948
+ day: "ڕۆژ"
949
+ },
950
+ cs: {
951
+ year: "rrrr",
952
+ month: "mm",
953
+ day: "dd"
954
+ },
955
+ cy: {
956
+ year: "bbbb",
957
+ month: "mm",
958
+ day: "dd"
959
+ },
960
+ da: {
961
+ year: "åååå",
962
+ month: "mm",
963
+ day: "dd"
964
+ },
965
+ de: {
966
+ year: "jjjj",
967
+ month: "mm",
968
+ day: "tt"
969
+ },
970
+ dsb: {
971
+ year: "llll",
972
+ month: "mm",
973
+ day: "źź"
974
+ },
975
+ el: {
976
+ year: "εεεε",
977
+ month: "μμ",
978
+ day: "ηη"
979
+ },
980
+ en: {
981
+ year: "yyyy",
982
+ month: "mm",
983
+ day: "dd"
984
+ },
985
+ eo: {
986
+ year: "jjjj",
987
+ month: "mm",
988
+ day: "tt"
989
+ },
990
+ es: {
991
+ year: "aaaa",
992
+ month: "mm",
993
+ day: "dd"
994
+ },
995
+ et: {
996
+ year: "aaaa",
997
+ month: "kk",
998
+ day: "pp"
999
+ },
1000
+ eu: {
1001
+ year: "uuuu",
1002
+ month: "hh",
1003
+ day: "ee"
1004
+ },
1005
+ fa: {
1006
+ year: "سال",
1007
+ month: "ماه",
1008
+ day: "روز"
1009
+ },
1010
+ ff: {
1011
+ year: "hhhh",
1012
+ month: "ll",
1013
+ day: "ññ"
1014
+ },
1015
+ fi: {
1016
+ year: "vvvv",
1017
+ month: "kk",
1018
+ day: "pp"
1019
+ },
1020
+ fr: {
1021
+ year: "aaaa",
1022
+ month: "mm",
1023
+ day: "jj"
1024
+ },
1025
+ fy: {
1026
+ year: "jjjj",
1027
+ month: "mm",
1028
+ day: "dd"
1029
+ },
1030
+ ga: {
1031
+ year: "bbbb",
1032
+ month: "mm",
1033
+ day: "ll"
1034
+ },
1035
+ gd: {
1036
+ year: "bbbb",
1037
+ month: "mm",
1038
+ day: "ll"
1039
+ },
1040
+ gl: {
1041
+ year: "aaaa",
1042
+ month: "mm",
1043
+ day: "dd"
1044
+ },
1045
+ he: {
1046
+ year: "שנה",
1047
+ month: "חודש",
1048
+ day: "יום"
1049
+ },
1050
+ hr: {
1051
+ year: "gggg",
1052
+ month: "mm",
1053
+ day: "dd"
1054
+ },
1055
+ hsb: {
1056
+ year: "llll",
1057
+ month: "mm",
1058
+ day: "dd"
1059
+ },
1060
+ hu: {
1061
+ year: "éééé",
1062
+ month: "hh",
1063
+ day: "nn"
1064
+ },
1065
+ ia: {
1066
+ year: "aaaa",
1067
+ month: "mm",
1068
+ day: "dd"
1069
+ },
1070
+ id: {
1071
+ year: "tttt",
1072
+ month: "bb",
1073
+ day: "hh"
1074
+ },
1075
+ it: {
1076
+ year: "aaaa",
1077
+ month: "mm",
1078
+ day: "gg"
1079
+ },
1080
+ ja: {
1081
+ year: "年",
1082
+ month: "月",
1083
+ day: "日"
1084
+ },
1085
+ ka: {
1086
+ year: "წწწწ",
1087
+ month: "თთ",
1088
+ day: "რრ"
1089
+ },
1090
+ kk: {
1091
+ year: "жжжж",
1092
+ month: "аа",
1093
+ day: "кк"
1094
+ },
1095
+ kn: {
1096
+ year: "ವವವವ",
1097
+ month: "ಮಿಮೀ",
1098
+ day: "ದಿದಿ"
1099
+ },
1100
+ ko: {
1101
+ year: "연도",
1102
+ month: "월",
1103
+ day: "일"
1104
+ },
1105
+ lb: {
1106
+ year: "jjjj",
1107
+ month: "mm",
1108
+ day: "dd"
1109
+ },
1110
+ lo: {
1111
+ year: "ປປປປ",
1112
+ month: "ດດ",
1113
+ day: "ວວ"
1114
+ },
1115
+ lt: {
1116
+ year: "mmmm",
1117
+ month: "mm",
1118
+ day: "dd"
1119
+ },
1120
+ lv: {
1121
+ year: "gggg",
1122
+ month: "mm",
1123
+ day: "dd"
1124
+ },
1125
+ meh: {
1126
+ year: "aaaa",
1127
+ month: "mm",
1128
+ day: "dd"
1129
+ },
1130
+ ml: {
1131
+ year: "വർഷം",
1132
+ month: "മാസം",
1133
+ day: "തീയതി"
1134
+ },
1135
+ ms: {
1136
+ year: "tttt",
1137
+ month: "mm",
1138
+ day: "hh"
1139
+ },
1140
+ nl: {
1141
+ year: "jjjj",
1142
+ month: "mm",
1143
+ day: "dd"
1144
+ },
1145
+ nn: {
1146
+ year: "åååå",
1147
+ month: "mm",
1148
+ day: "dd"
1149
+ },
1150
+ no: {
1151
+ year: "åååå",
1152
+ month: "mm",
1153
+ day: "dd"
1154
+ },
1155
+ oc: {
1156
+ year: "aaaa",
1157
+ month: "mm",
1158
+ day: "jj"
1159
+ },
1160
+ pl: {
1161
+ year: "rrrr",
1162
+ month: "mm",
1163
+ day: "dd"
1164
+ },
1165
+ pt: {
1166
+ year: "aaaa",
1167
+ month: "mm",
1168
+ day: "dd"
1169
+ },
1170
+ rm: {
1171
+ year: "oooo",
1172
+ month: "mm",
1173
+ day: "dd"
1174
+ },
1175
+ ro: {
1176
+ year: "aaaa",
1177
+ month: "ll",
1178
+ day: "zz"
1179
+ },
1180
+ ru: {
1181
+ year: "гггг",
1182
+ month: "мм",
1183
+ day: "дд"
1184
+ },
1185
+ sc: {
1186
+ year: "aaaa",
1187
+ month: "mm",
1188
+ day: "dd"
1189
+ },
1190
+ scn: {
1191
+ year: "aaaa",
1192
+ month: "mm",
1193
+ day: "jj"
1194
+ },
1195
+ sk: {
1196
+ year: "rrrr",
1197
+ month: "mm",
1198
+ day: "dd"
1199
+ },
1200
+ sl: {
1201
+ year: "llll",
1202
+ month: "mm",
1203
+ day: "dd"
1204
+ },
1205
+ sr: {
1206
+ year: "гггг",
1207
+ month: "мм",
1208
+ day: "дд"
1209
+ },
1210
+ sv: {
1211
+ year: "åååå",
1212
+ month: "mm",
1213
+ day: "dd"
1214
+ },
1215
+ szl: {
1216
+ year: "rrrr",
1217
+ month: "mm",
1218
+ day: "dd"
1219
+ },
1220
+ tg: {
1221
+ year: "сссс",
1222
+ month: "мм",
1223
+ day: "рр"
1224
+ },
1225
+ th: {
1226
+ year: "ปปปป",
1227
+ month: "ดด",
1228
+ day: "วว"
1229
+ },
1230
+ tr: {
1231
+ year: "yyyy",
1232
+ month: "aa",
1233
+ day: "gg"
1234
+ },
1235
+ uk: {
1236
+ year: "рррр",
1237
+ month: "мм",
1238
+ day: "дд"
1239
+ },
1240
+ "zh-CN": {
1241
+ year: "年",
1242
+ month: "月",
1243
+ day: "日"
1244
+ },
1245
+ "zh-TW": {
1246
+ year: "年",
1247
+ month: "月",
1248
+ day: "日"
1249
+ }
1250
+ };
1251
+ function getLocaleLanguage(locale) {
1252
+ if (typeof Intl !== "undefined" && Intl.Locale) return new Intl.Locale(locale).language;
1253
+ return locale.split("-")[0];
1254
+ }
1255
+ function getLocalePlaceholders(locale) {
1256
+ if (locale in LOCALE_PLACEHOLDERS) return LOCALE_PLACEHOLDERS[locale];
1257
+ const lang = getLocaleLanguage(locale);
1258
+ if (lang in LOCALE_PLACEHOLDERS) return LOCALE_PLACEHOLDERS[lang];
1259
+ return LOCALE_PLACEHOLDERS.en;
1260
+ }
1261
+ const defaultTranslations = { placeholder(locale) {
1262
+ const localized = getLocalePlaceholders(locale);
1263
+ return {
1264
+ day: localized.day,
1265
+ month: localized.month,
1266
+ year: localized.year,
1267
+ hour: "––",
1268
+ minute: "––",
1269
+ second: "––",
1270
+ dayPeriod: "AM/PM",
1271
+ era: "era",
1272
+ timeZoneName: "timeZone",
1273
+ weekday: "weekday",
1274
+ unknown: "unknown",
1275
+ fractionalSecond: "ff"
1276
+ };
1277
+ } };
1278
+ //#endregion
1279
+ //#region src/machines/date-input/utils/formatting.ts
1280
+ function getValueAsString(value, prop) {
1281
+ return value.map((date) => {
1282
+ if (date == null) return "";
1283
+ try {
1284
+ return prop("format")(date, {
1285
+ locale: prop("locale"),
1286
+ timeZone: prop("timeZone")
1287
+ });
1288
+ } catch {
1289
+ return "";
1290
+ }
1291
+ });
1292
+ }
1293
+ //#endregion
1294
+ //#region src/machines/date-input/date-input.machine.ts
1295
+ function resolvedHourCycle(formatter) {
1296
+ const hc = formatter.resolvedOptions().hourCycle;
1297
+ if (hc === "h11" || hc === "h12" || hc === "h23" || hc === "h24") return hc;
1298
+ return "h23";
1299
+ }
1300
+ function initDisplayValues(value, placeholderValue, hourCycle, count) {
1301
+ const calendar = placeholderValue.calendar;
1302
+ if (value?.length) return Array.from({ length: count }, (_, i) => value[i] ? new IncompleteDate(calendar, hourCycle, value[i]) : new IncompleteDate(calendar, hourCycle));
1303
+ return Array.from({ length: count }, () => new IncompleteDate(calendar, hourCycle));
1304
+ }
1305
+ function incompleteDateHash(dv) {
1306
+ return `${dv.year}|${dv.month}|${dv.day}|${dv.hour}|${dv.dayPeriod}|${dv.minute}|${dv.second}|${dv.era}`;
1307
+ }
1308
+ function incompleteDateEqual(a, b) {
1309
+ return incompleteDateHash(a) === incompleteDateHash(b);
1310
+ }
1311
+ const machine = createMachine({
1312
+ props({ props }) {
1313
+ const locale = props.locale || "en-US";
1314
+ const timeZone = props.timeZone || "UTC";
1315
+ const selectionMode = props.selectionMode || "single";
1316
+ const granularity = props.granularity || "day";
1317
+ const translations = {
1318
+ ...defaultTranslations,
1319
+ ...props.translations
1320
+ };
1321
+ const defaultValue = props.defaultValue ? props.defaultValue.map((date) => constrainValue(date, props.min, props.max)) : void 0;
1322
+ const value = props.value ? props.value.map((date) => constrainValue(date, props.min, props.max)) : void 0;
1323
+ let placeholderValue = props.placeholderValue || props.defaultPlaceholderValue || value?.[0] || defaultValue?.[0] || getTodayDate(timeZone);
1324
+ placeholderValue = constrainValue(placeholderValue, props.min, props.max);
1325
+ if ((granularity === "hour" || granularity === "minute" || granularity === "second") && !("hour" in placeholderValue)) placeholderValue = toCalendarDateTime(placeholderValue);
1326
+ const hourCycle = props.hourCycle === 12 ? "h12" : props.hourCycle === 24 ? "h23" : void 0;
1327
+ const shouldForceLeadingZeros = props.shouldForceLeadingZeros ?? false;
1328
+ const digitStyle = shouldForceLeadingZeros ? "2-digit" : "numeric";
1329
+ const formatterOptions = {
1330
+ timeZone,
1331
+ day: digitStyle,
1332
+ month: digitStyle,
1333
+ year: "numeric",
1334
+ hourCycle
1335
+ };
1336
+ if (granularity === "hour" || granularity === "minute" || granularity === "second") formatterOptions.hour = digitStyle;
1337
+ if (granularity === "minute" || granularity === "second") formatterOptions.minute = "2-digit";
1338
+ if (granularity === "second") formatterOptions.second = "2-digit";
1339
+ const formatter = props.formatter ?? new DateFormatter(locale, formatterOptions);
1340
+ const allSegments = props.allSegments ?? (() => {
1341
+ const segs = formatter.formatToParts(/* @__PURE__ */ new Date()).filter((seg) => EDITABLE_SEGMENTS[seg.type]).reduce((p, seg) => {
1342
+ const key = TYPE_MAPPING[seg.type] || seg.type;
1343
+ p[key] = true;
1344
+ return p;
1345
+ }, {});
1346
+ segs.era = true;
1347
+ return segs;
1348
+ })();
1349
+ return {
1350
+ locale,
1351
+ timeZone,
1352
+ selectionMode,
1353
+ format(date, { timeZone }) {
1354
+ const jsd = date.toDate(timeZone);
1355
+ if (date.calendar?.identifier === "gregory" && date.era === "BC") {
1356
+ const prolYear = jsd.getUTCFullYear();
1357
+ const safeDate = new Date(Date.UTC(2e3, jsd.getUTCMonth(), jsd.getUTCDate()));
1358
+ return formatter.formatToParts(safeDate).map((p) => p.type === "year" ? String(prolYear) : p.value).join("");
1359
+ }
1360
+ return formatter.format(jsd);
1361
+ },
1362
+ ...props,
1363
+ translations,
1364
+ value,
1365
+ defaultValue: defaultValue ?? [],
1366
+ granularity,
1367
+ shouldForceLeadingZeros,
1368
+ formatter,
1369
+ placeholderValue: typeof props.placeholderValue === "undefined" ? void 0 : placeholderValue,
1370
+ defaultPlaceholderValue: placeholderValue,
1371
+ allSegments
1372
+ };
1373
+ },
1374
+ initialState() {
1375
+ return "idle";
1376
+ },
1377
+ refs() {
1378
+ return {
1379
+ announcer: null,
1380
+ segmentToAnnounceIndex: null
1381
+ };
1382
+ },
1383
+ effects: ["setupLiveRegion"],
1384
+ context({ prop, bindable }) {
1385
+ const hc = resolvedHourCycle(prop("formatter"));
1386
+ const placeholderValue = prop("defaultPlaceholderValue");
1387
+ const groupCount = prop("selectionMode") === "range" ? 2 : 1;
1388
+ const initialValue = prop("value") || prop("defaultValue");
1389
+ return {
1390
+ value: bindable(() => ({
1391
+ defaultValue: prop("defaultValue"),
1392
+ value: prop("value"),
1393
+ isEqual(a, b) {
1394
+ if (a?.length !== b?.length) return false;
1395
+ const len = Math.max(a.length, b.length);
1396
+ for (let i = 0; i < len; i++) if (!isDateEqual(a[i], b[i])) return false;
1397
+ return true;
1398
+ },
1399
+ hash: (v) => v.map((date) => date?.toString() ?? "").join(","),
1400
+ onChange(value) {
1401
+ const valueAsString = getValueAsString(value, prop);
1402
+ prop("onValueChange")?.({
1403
+ value,
1404
+ valueAsString
1405
+ });
1406
+ }
1407
+ })),
1408
+ activeIndex: bindable(() => ({
1409
+ defaultValue: 0,
1410
+ sync: true
1411
+ })),
1412
+ activeSegmentIndex: bindable(() => ({
1413
+ defaultValue: -1,
1414
+ sync: true
1415
+ })),
1416
+ placeholderValue: bindable(() => ({
1417
+ defaultValue: prop("defaultPlaceholderValue"),
1418
+ isEqual: isDateEqual,
1419
+ hash: (v) => v.toString(),
1420
+ onChange(placeholderValue) {
1421
+ prop("onPlaceholderChange")?.({
1422
+ value: prop("value") ?? [],
1423
+ valueAsString: [],
1424
+ placeholderValue
1425
+ });
1426
+ }
1427
+ })),
1428
+ displayValues: bindable(() => ({
1429
+ defaultValue: initDisplayValues(initialValue, placeholderValue ?? getTodayDate(prop("timeZone")), hc, groupCount),
1430
+ isEqual: (a, b) => b != null && a.length === b.length && a.every((d, i) => incompleteDateEqual(d, b[i])),
1431
+ hash: (v) => v.map(incompleteDateHash).join("||")
1432
+ })),
1433
+ enteredKeys: bindable(() => ({
1434
+ defaultValue: "",
1435
+ sync: true
1436
+ }))
1437
+ };
1438
+ },
1439
+ computed: {
1440
+ isInteractive: ({ prop }) => !prop("disabled") && !prop("readOnly"),
1441
+ valueAsString: ({ context, prop }) => getValueAsString(context.get("value"), prop),
1442
+ segments: memo(({ context, prop }) => [
1443
+ context.hash("value"),
1444
+ prop("selectionMode"),
1445
+ context.hash("placeholderValue"),
1446
+ context.hash("displayValues"),
1447
+ prop("allSegments"),
1448
+ prop("timeZone"),
1449
+ prop("translations"),
1450
+ prop("granularity"),
1451
+ prop("formatter"),
1452
+ prop("locale")
1453
+ ], (_deps, { context, prop }) => {
1454
+ const value = context.get("value");
1455
+ const selectionMode = prop("selectionMode");
1456
+ const placeholderValue = context.get("placeholderValue");
1457
+ const displayValues = context.get("displayValues");
1458
+ const allSegments = prop("allSegments");
1459
+ const timeZone = prop("timeZone");
1460
+ const translations = prop("translations") || defaultTranslations;
1461
+ const granularity = prop("granularity");
1462
+ const formatter = prop("formatter");
1463
+ const locale = prop("locale");
1464
+ const allSegmentTypes = Object.keys(allSegments);
1465
+ const groupCount = selectionMode === "range" ? 2 : 1;
1466
+ return Array.from({ length: groupCount }, (_, i) => {
1467
+ const dv = displayValues[i] ?? new IncompleteDate(placeholderValue.calendar, resolvedHourCycle(formatter));
1468
+ const committedValue = value?.[i];
1469
+ const displayDate = committedValue && dv.isComplete(allSegmentTypes) ? committedValue : dv.toValue(placeholderValue);
1470
+ const segmentFormatter = dv.era === "BC" && dv.calendar.identifier === "gregory" ? new DateFormatter(locale, {
1471
+ ...formatter.resolvedOptions(),
1472
+ era: "short"
1473
+ }) : formatter;
1474
+ return processSegments({
1475
+ dateValue: displayDate.toDate(timeZone),
1476
+ displayValue: dv,
1477
+ formatter: segmentFormatter,
1478
+ locale,
1479
+ translations,
1480
+ granularity
1481
+ });
1482
+ });
1483
+ })
1484
+ },
1485
+ watch({ track, context, prop, action }) {
1486
+ track([() => context.hash("value")], () => {
1487
+ action(["syncDisplayValues"]);
1488
+ });
1489
+ track([() => context.get("activeSegmentIndex")], () => {
1490
+ action(["focusActiveSegment"]);
1491
+ });
1492
+ track([() => prop("placeholderValue")?.toString()], () => {
1493
+ action(["syncPlaceholderProp"]);
1494
+ });
1495
+ },
1496
+ on: {
1497
+ "VALUE.SET": { actions: ["setDateValue"] },
1498
+ "VALUE.CLEAR": { actions: [
1499
+ "clearDateValue",
1500
+ "clearDisplayValues",
1501
+ "clearEnteredKeys"
1502
+ ] }
1503
+ },
1504
+ states: {
1505
+ idle: { on: { "SEGMENT.FOCUS": {
1506
+ target: "focused",
1507
+ actions: ["setActiveSegmentIndex", "invokeOnFocus"]
1508
+ } } },
1509
+ focused: { on: {
1510
+ "SEGMENT.FOCUS": { actions: ["setActiveSegmentIndex", "clearEnteredKeys"] },
1511
+ "SEGMENT.BLUR": {
1512
+ target: "idle",
1513
+ actions: [
1514
+ "confirmPlaceholder",
1515
+ "clearEnteredKeys",
1516
+ "invokeOnBlur"
1517
+ ]
1518
+ },
1519
+ "SEGMENT.INPUT": { actions: ["setSegmentValue", "announceSegmentValue"] },
1520
+ "SEGMENT.ADJUST": { actions: [
1521
+ "invokeOnSegmentAdjust",
1522
+ "clearEnteredKeys",
1523
+ "announceSegmentValue"
1524
+ ] },
1525
+ "SEGMENT.ARROW_LEFT": { actions: ["setPreviousActiveSegmentIndex", "clearEnteredKeys"] },
1526
+ "SEGMENT.ARROW_RIGHT": { actions: ["setNextActiveSegmentIndex", "clearEnteredKeys"] },
1527
+ "SEGMENT.BACKSPACE": [{
1528
+ guard: "isActiveSegmentPlaceholder",
1529
+ actions: ["setPreviousActiveSegmentIndex", "clearEnteredKeys"]
1530
+ }, { actions: [
1531
+ "clearSegmentValue",
1532
+ "clearEnteredKeys",
1533
+ "announceSegmentValue"
1534
+ ] }],
1535
+ "SEGMENT.HOME": { actions: [
1536
+ "setSegmentToLowestValue",
1537
+ "clearEnteredKeys",
1538
+ "announceSegmentValue"
1539
+ ] },
1540
+ "SEGMENT.END": { actions: [
1541
+ "setSegmentToHighestValue",
1542
+ "clearEnteredKeys",
1543
+ "announceSegmentValue"
1544
+ ] }
1545
+ } }
1546
+ },
1547
+ implementations: {
1548
+ effects: { setupLiveRegion({ scope, refs }) {
1549
+ const liveRegion = createLiveRegion({
1550
+ level: "assertive",
1551
+ document: scope.getDoc()
1552
+ });
1553
+ refs.set("announcer", liveRegion);
1554
+ return () => liveRegion.destroy();
1555
+ } },
1556
+ guards: { isActiveSegmentPlaceholder: (ctx) => {
1557
+ if (ctx.context.get("enteredKeys") !== "") return false;
1558
+ return getActiveSegment(ctx)?.isPlaceholder === true;
1559
+ } },
1560
+ actions: {
1561
+ invokeOnFocus({ prop }) {
1562
+ prop("onFocusChange")?.({ focused: true });
1563
+ },
1564
+ invokeOnBlur({ prop }) {
1565
+ prop("onFocusChange")?.({ focused: false });
1566
+ },
1567
+ setActiveSegmentIndex({ context, event }) {
1568
+ if (event.dateIndex != null) context.set("activeIndex", event.dateIndex);
1569
+ context.set("activeSegmentIndex", event.segmentIndex);
1570
+ },
1571
+ clearDisplayValues({ context, prop }) {
1572
+ const hc = resolvedHourCycle(prop("formatter"));
1573
+ const placeholderValue = context.get("placeholderValue");
1574
+ const count = prop("selectionMode") === "range" ? 2 : 1;
1575
+ context.set("displayValues", Array.from({ length: count }, () => new IncompleteDate(placeholderValue.calendar, hc)));
1576
+ },
1577
+ clearEnteredKeys({ context }) {
1578
+ context.set("enteredKeys", "");
1579
+ },
1580
+ setPreviousActiveSegmentIndex(ctx) {
1581
+ const { context } = ctx;
1582
+ const index = context.get("activeIndex");
1583
+ const { allSegments, segments, offset, localIndex } = resolveActiveSegment(ctx);
1584
+ const prevLocalIndex = segments.findLastIndex((segment, i) => i < localIndex && segment.isEditable);
1585
+ if (prevLocalIndex !== -1) {
1586
+ context.set("activeSegmentIndex", offset + prevLocalIndex);
1587
+ return;
1588
+ }
1589
+ const prevGroupIndex = index - 1;
1590
+ if (prevGroupIndex < 0) return;
1591
+ const prevGroupSegments = allSegments[prevGroupIndex];
1592
+ if (!prevGroupSegments) return;
1593
+ const lastPrevGroupEditableLocalIndex = prevGroupSegments.findLastIndex((s) => s.isEditable);
1594
+ if (lastPrevGroupEditableLocalIndex === -1) return;
1595
+ context.set("activeIndex", prevGroupIndex);
1596
+ context.set("activeSegmentIndex", getGroupOffset(allSegments, prevGroupIndex) + lastPrevGroupEditableLocalIndex);
1597
+ },
1598
+ setNextActiveSegmentIndex(ctx) {
1599
+ const { context } = ctx;
1600
+ const { segments, offset, localIndex } = resolveActiveSegment(ctx);
1601
+ const nextLocalIndex = segments.findIndex((segment, i) => i > localIndex && segment.isEditable);
1602
+ if (nextLocalIndex === -1) return;
1603
+ context.set("activeSegmentIndex", offset + nextLocalIndex);
1604
+ },
1605
+ focusActiveSegment({ scope, context }) {
1606
+ raf(() => {
1607
+ getSegmentEls(scope)[context.get("activeSegmentIndex")]?.focus({ preventScroll: true });
1608
+ });
1609
+ },
1610
+ clearSegmentValue(params) {
1611
+ const { context, prop, event } = params;
1612
+ const index = context.get("activeIndex");
1613
+ const allSegments = prop("allSegments");
1614
+ const allSegmentTypes = Object.keys(allSegments);
1615
+ const placeholderValue = context.get("placeholderValue");
1616
+ const segment = getActiveSegment(params) ?? event.segment;
1617
+ const type = segment.type;
1618
+ let dv = getActiveDisplayValue(params);
1619
+ if (type === "dayPeriod") {
1620
+ const cleared = dv.clear(type);
1621
+ setDisplayValue(params, index, cleared);
1622
+ if (cleared.isCleared(allSegmentTypes)) commitClear(params, index);
1623
+ return;
1624
+ }
1625
+ if (type === "hour") {
1626
+ const cleared = dv.clear(type);
1627
+ setDisplayValue(params, index, cleared);
1628
+ if (cleared.isCleared(allSegmentTypes)) commitClear(params, index);
1629
+ return;
1630
+ }
1631
+ const enteredKeys = context.get("enteredKeys");
1632
+ const newValue = (enteredKeys !== "" ? enteredKeys : segment.text).slice(0, -1);
1633
+ if (newValue === "" || newValue === "0") {
1634
+ const cleared = dv.clear(type);
1635
+ setDisplayValue(params, index, cleared);
1636
+ if (cleared.isCleared(allSegmentTypes)) commitClear(params, index);
1637
+ } else {
1638
+ dv = dv.set(type, Number(newValue), placeholderValue);
1639
+ setDisplayValue(params, index, dv);
1640
+ if (dv.isComplete(allSegmentTypes)) commitValue(params, index, dv);
1641
+ }
1642
+ },
1643
+ invokeOnSegmentAdjust(params) {
1644
+ const { context, prop, event } = params;
1645
+ const { segment, amount } = event;
1646
+ const type = segment.type;
1647
+ const index = context.get("activeIndex");
1648
+ const allSegments = prop("allSegments");
1649
+ const allSegmentTypes = Object.keys(allSegments);
1650
+ const placeholderValue = context.get("placeholderValue");
1651
+ const displaySegmentTypes = allSegmentTypes;
1652
+ const next = getActiveDisplayValue(params).cycle(type, amount, placeholderValue, displaySegmentTypes);
1653
+ setDisplayValue(params, index, next);
1654
+ if (next.isComplete(allSegmentTypes)) commitValue(params, index, next);
1655
+ },
1656
+ setSegmentValue(params) {
1657
+ const { event, context, refs } = params;
1658
+ const { segment, input } = event;
1659
+ refs.set("segmentToAnnounceIndex", context.get("activeSegmentIndex"));
1660
+ const index = context.get("activeIndex");
1661
+ updateSegmentValue(params, segment, input);
1662
+ const allSegmentTypes = Object.keys(params.prop("allSegments"));
1663
+ const dv = context.get("displayValues")[index];
1664
+ if (dv && dv.isComplete(allSegmentTypes)) commitValue(params, index, dv);
1665
+ },
1666
+ setSegmentToLowestValue(params) {
1667
+ const { event, context, prop } = params;
1668
+ const { segment } = event;
1669
+ const index = context.get("activeIndex");
1670
+ const allSegmentTypes = Object.keys(prop("allSegments"));
1671
+ const placeholderValue = context.get("placeholderValue");
1672
+ if (segment.minValue == null) return;
1673
+ const dv = getActiveDisplayValue(params).set(segment.type, segment.minValue, placeholderValue);
1674
+ setDisplayValue(params, index, dv);
1675
+ if (dv.isComplete(allSegmentTypes)) commitValue(params, index, dv);
1676
+ },
1677
+ setSegmentToHighestValue(params) {
1678
+ const { event, context, prop } = params;
1679
+ const { segment } = event;
1680
+ const index = context.get("activeIndex");
1681
+ const allSegmentTypes = Object.keys(prop("allSegments"));
1682
+ const placeholderValue = context.get("placeholderValue");
1683
+ if (segment.maxValue == null) return;
1684
+ const dv = getActiveDisplayValue(params).set(segment.type, segment.maxValue, placeholderValue);
1685
+ setDisplayValue(params, index, dv);
1686
+ if (dv.isComplete(allSegmentTypes)) commitValue(params, index, dv);
1687
+ },
1688
+ setDateValue({ context, event, prop }) {
1689
+ if (!Array.isArray(event.value)) return;
1690
+ const value = event.value.map((date) => constrainValue(date, prop("min"), prop("max")));
1691
+ context.set("value", value);
1692
+ },
1693
+ clearDateValue({ context }) {
1694
+ context.set("value", []);
1695
+ },
1696
+ syncDisplayValues({ context, prop }) {
1697
+ const value = context.get("value");
1698
+ const hc = resolvedHourCycle(prop("formatter"));
1699
+ const placeholderValue = context.get("placeholderValue");
1700
+ const count = prop("selectionMode") === "range" ? 2 : 1;
1701
+ context.set("displayValues", initDisplayValues(value?.length ? value : void 0, placeholderValue, hc, count));
1702
+ },
1703
+ syncPlaceholderProp({ prop, context }) {
1704
+ const propValue = prop("placeholderValue");
1705
+ if (propValue) {
1706
+ context.set("placeholderValue", propValue);
1707
+ const value = context.get("value");
1708
+ if (value?.length) {
1709
+ const hc = resolvedHourCycle(prop("formatter"));
1710
+ const count = prop("selectionMode") === "range" ? 2 : 1;
1711
+ context.set("displayValues", initDisplayValues(value, propValue, hc, count));
1712
+ }
1713
+ }
1714
+ },
1715
+ announceSegmentValue({ refs, computed, context }) {
1716
+ const announcer = refs.get("announcer");
1717
+ if (!announcer) return;
1718
+ const index = context.get("activeIndex");
1719
+ const activeSegmentIndex = context.get("activeSegmentIndex");
1720
+ const segmentIndexToUse = refs.get("segmentToAnnounceIndex") ?? activeSegmentIndex;
1721
+ refs.set("segmentToAnnounceIndex", null);
1722
+ const allSegments = computed("segments");
1723
+ const segment = allSegments[index]?.[segmentIndexToUse - getGroupOffset(allSegments, index)];
1724
+ if (!segment || segment.type === "literal") return;
1725
+ const valueText = segment.isPlaceholder ? "Empty" : segment.text;
1726
+ announcer.announce(`${getSegmentLabel(segment.type)}, ${valueText}`);
1727
+ },
1728
+ confirmPlaceholder(params) {
1729
+ const { context, prop } = params;
1730
+ const allSegments = prop("allSegments");
1731
+ const allSegmentTypes = Object.keys(allSegments);
1732
+ const dateCount = prop("selectionMode") === "range" ? 2 : 1;
1733
+ const placeholderValue = context.get("placeholderValue");
1734
+ for (let i = 0; i < dateCount; i++) {
1735
+ const dv = context.get("displayValues")[i];
1736
+ if (!dv) continue;
1737
+ const allExceptDayPeriod = allSegmentTypes.filter((s) => s !== "dayPeriod");
1738
+ if (allSegments.dayPeriod && dv.isComplete(allExceptDayPeriod) && dv.dayPeriod == null) {
1739
+ const filled = dv.set("dayPeriod", placeholderValue && "hour" in placeholderValue ? placeholderValue.hour >= 12 ? 1 : 0 : 0, placeholderValue);
1740
+ setDisplayValue(params, i, filled);
1741
+ commitValue(params, i, filled);
1742
+ }
1743
+ }
1744
+ }
1745
+ }
1746
+ }
1747
+ });
1748
+ function commitValue(params, index, dv) {
1749
+ const { context, prop } = params;
1750
+ const placeholderValue = context.get("placeholderValue");
1751
+ const date = constrainValue(dv.toValue(placeholderValue), prop("min"), prop("max"));
1752
+ const values = Array.from(context.get("value"));
1753
+ values[index] = date;
1754
+ context.set("value", values);
1755
+ }
1756
+ function commitClear(params, index) {
1757
+ const { context } = params;
1758
+ const values = context.get("value");
1759
+ if (index < values.length) context.set("value", values.slice(0, index));
1760
+ }
1761
+ //#endregion
1762
+ //#region src/machines/date-input/date-input.parse.ts
1763
+ function parse(value) {
1764
+ if (Array.isArray(value)) return value.map((v) => parse(v));
1765
+ if (value instanceof Date) return new CalendarDate(value.getFullYear(), value.getMonth() + 1, value.getDate());
1766
+ return parseDate(value);
1767
+ }
1768
+ //#endregion
1769
+ //#region src/machines/date-input/date-input.props.ts
1770
+ const props = createProps()([
1771
+ "dir",
1772
+ "disabled",
1773
+ "getRootNode",
1774
+ "id",
1775
+ "ids",
1776
+ "invalid",
1777
+ "locale",
1778
+ "max",
1779
+ "min",
1780
+ "name",
1781
+ "form",
1782
+ "onFocusChange",
1783
+ "onPlaceholderChange",
1784
+ "onValueChange",
1785
+ "readOnly",
1786
+ "required",
1787
+ "selectionMode",
1788
+ "timeZone",
1789
+ "translations",
1790
+ "value",
1791
+ "defaultValue",
1792
+ "hourCycle",
1793
+ "granularity",
1794
+ "shouldForceLeadingZeros",
1795
+ "allSegments",
1796
+ "formatter",
1797
+ "placeholderValue",
1798
+ "defaultPlaceholderValue",
1799
+ "format"
1800
+ ]);
1801
+ const splitProps = createSplitProps(props);
1802
+ const segmentProps = createProps()(["segment", "index"]);
1803
+ const splitSegmentProps = createSplitProps(segmentProps);
1804
+ const segmentGroupProps = createProps()(["index"]);
1805
+ const splitSegmentGroupProps = createSplitProps(segmentGroupProps);
1806
+ const segmentsProps = createProps()(["index"]);
1807
+ const splitSegmentsProps = createSplitProps(segmentsProps);
1808
+ const labelProps = createProps()(["index"]);
1809
+ const splitLabelProps = createSplitProps(labelProps);
1810
+ const hiddenInputProps = createProps()(["index", "name"]);
1811
+ const splitHiddenInputProps = createSplitProps(hiddenInputProps);
1812
+ //#endregion
1813
+ export { anatomy, connect, hiddenInputProps, labelProps, machine, parse, props, segmentGroupProps, segmentProps, segmentsProps, splitHiddenInputProps, splitLabelProps, splitProps, splitSegmentGroupProps, splitSegmentProps, splitSegmentsProps };