@epilot/spark-ui 0.28.2 → 0.30.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.
- package/dist/calendar-lists-CTby2kR5.d.cts +27 -0
- package/dist/calendar-lists-DoloqsCN.d.ts +27 -0
- package/dist/components/accordion.cjs +1 -1
- package/dist/components/accordion.js +1 -1
- package/dist/components/attachment.cjs +1 -1
- package/dist/components/attachment.js +1 -1
- package/dist/components/autocomplete.cjs +1 -0
- package/dist/components/autocomplete.cjs.map +1 -1
- package/dist/components/autocomplete.js +1 -0
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/avatar.d.cts +1 -1
- package/dist/components/avatar.d.ts +1 -1
- package/dist/components/badge.cjs +1 -1
- package/dist/components/badge.d.cts +1 -1
- package/dist/components/badge.d.ts +1 -1
- package/dist/components/badge.js +1 -1
- package/dist/components/banner.cjs +1 -1
- package/dist/components/banner.d.cts +1 -1
- package/dist/components/banner.js +1 -1
- package/dist/components/box.d.cts +1 -1
- package/dist/components/box.d.ts +1 -1
- package/dist/components/box.js +1 -1
- package/dist/components/breadcrumbs.cjs +1 -1
- package/dist/components/breadcrumbs.js +1 -1
- package/dist/components/bubble.cjs +1 -1
- package/dist/components/bubble.d.cts +1 -1
- package/dist/components/bubble.d.ts +1 -1
- package/dist/components/bubble.js +1 -1
- package/dist/components/button-group.cjs +1 -1
- package/dist/components/button-group.d.cts +1 -1
- package/dist/components/button-group.d.ts +1 -1
- package/dist/components/button-group.js +1 -1
- package/dist/components/button.cjs +17 -17
- package/dist/components/button.cjs.map +1 -1
- package/dist/components/button.d.cts +3 -3
- package/dist/components/button.d.ts +3 -3
- package/dist/components/button.js +17 -17
- package/dist/components/button.js.map +1 -1
- package/dist/components/calendar.cjs +23 -4
- package/dist/components/calendar.cjs.map +1 -1
- package/dist/components/calendar.d.cts +11 -2
- package/dist/components/calendar.d.ts +11 -2
- package/dist/components/calendar.js +23 -4
- package/dist/components/calendar.js.map +1 -1
- package/dist/components/callout.cjs +1 -1
- package/dist/components/callout.d.cts +1 -1
- package/dist/components/callout.d.ts +1 -1
- package/dist/components/callout.js +1 -1
- package/dist/components/card.cjs +1 -1
- package/dist/components/card.d.cts +1 -1
- package/dist/components/card.d.ts +1 -1
- package/dist/components/card.js +2 -2
- package/dist/components/checkbox-group.d.cts +1 -1
- package/dist/components/checkbox-group.d.ts +1 -1
- package/dist/components/checkbox.d.cts +1 -1
- package/dist/components/checkbox.d.ts +1 -1
- package/dist/components/combobox.cjs +45 -15
- package/dist/components/combobox.cjs.map +1 -1
- package/dist/components/combobox.d.cts +3 -1
- package/dist/components/combobox.d.ts +3 -1
- package/dist/components/combobox.js +46 -16
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/drawer.cjs +1 -1
- package/dist/components/drawer.js +1 -1
- package/dist/components/empty-state.cjs +1 -1
- package/dist/components/empty-state.js +1 -1
- package/dist/components/entity-card.cjs +1 -1
- package/dist/components/entity-card.js +1 -1
- package/dist/components/field.cjs +58 -17
- package/dist/components/field.cjs.map +1 -1
- package/dist/components/field.d.cts +8 -4
- package/dist/components/field.d.ts +8 -4
- package/dist/components/field.js +58 -17
- package/dist/components/field.js.map +1 -1
- package/dist/components/hero-metric.cjs +1 -1
- package/dist/components/hero-metric.js +1 -1
- package/dist/components/info-block.cjs +1 -1
- package/dist/components/info-block.js +1 -1
- package/dist/components/input-date-time.cjs +212 -0
- package/dist/components/input-date-time.cjs.map +1 -0
- package/dist/components/input-date-time.d.cts +38 -0
- package/dist/components/input-date-time.d.ts +38 -0
- package/dist/components/input-date-time.js +205 -0
- package/dist/components/input-date-time.js.map +1 -0
- package/dist/components/input-group.cjs +72 -4
- package/dist/components/input-group.cjs.map +1 -1
- package/dist/components/input-group.d.cts +6 -1
- package/dist/components/input-group.d.ts +6 -1
- package/dist/components/input-group.js +72 -5
- package/dist/components/input-group.js.map +1 -1
- package/dist/components/input-otp.cjs +1 -1
- package/dist/components/input-otp.js +1 -1
- package/dist/components/input.cjs +7 -4
- package/dist/components/input.cjs.map +1 -1
- package/dist/components/input.d.cts +1 -1
- package/dist/components/input.d.ts +1 -1
- package/dist/components/input.js +8 -5
- package/dist/components/input.js.map +1 -1
- package/dist/components/list.cjs +1 -1
- package/dist/components/list.d.cts +1 -1
- package/dist/components/list.d.ts +1 -1
- package/dist/components/list.js +1 -1
- package/dist/components/marker.cjs +1 -1
- package/dist/components/marker.d.cts +1 -1
- package/dist/components/marker.d.ts +1 -1
- package/dist/components/marker.js +1 -1
- package/dist/components/message-scroller.cjs +1 -1
- package/dist/components/message-scroller.js +1 -1
- package/dist/components/page-header.cjs +1 -1
- package/dist/components/page-header.js +1 -1
- package/dist/components/pill.d.cts +1 -1
- package/dist/components/pill.d.ts +1 -1
- package/dist/components/popover.cjs +1 -1
- package/dist/components/popover.js +1 -1
- package/dist/components/radio.d.cts +1 -1
- package/dist/components/radio.d.ts +1 -1
- package/dist/components/segmented-control.d.cts +1 -1
- package/dist/components/segmented-control.d.ts +1 -1
- package/dist/components/select.cjs +4 -2
- package/dist/components/select.cjs.map +1 -1
- package/dist/components/select.d.cts +1 -1
- package/dist/components/select.d.ts +1 -1
- package/dist/components/select.js +4 -2
- package/dist/components/select.js.map +1 -1
- package/dist/components/separator.cjs +15 -18
- package/dist/components/separator.cjs.map +1 -1
- package/dist/components/separator.d.cts +3 -0
- package/dist/components/separator.d.ts +3 -0
- package/dist/components/separator.js +16 -19
- package/dist/components/separator.js.map +1 -1
- package/dist/components/skeleton.cjs +20 -5
- package/dist/components/skeleton.cjs.map +1 -1
- package/dist/components/skeleton.d.cts +9 -5
- package/dist/components/skeleton.d.ts +9 -5
- package/dist/components/skeleton.js +19 -6
- package/dist/components/skeleton.js.map +1 -1
- package/dist/components/spinner.cjs +8 -81
- package/dist/components/spinner.cjs.map +1 -1
- package/dist/components/spinner.js +8 -81
- package/dist/components/spinner.js.map +1 -1
- package/dist/components/switch-group.d.cts +1 -1
- package/dist/components/switch-group.d.ts +1 -1
- package/dist/components/switch.d.cts +1 -1
- package/dist/components/switch.d.ts +1 -1
- package/dist/components/textarea.cjs +7 -4
- package/dist/components/textarea.cjs.map +1 -1
- package/dist/components/textarea.d.cts +1 -1
- package/dist/components/textarea.d.ts +1 -1
- package/dist/components/textarea.js +7 -4
- package/dist/components/textarea.js.map +1 -1
- package/dist/components/theme.cjs +1 -1
- package/dist/components/theme.d.cts +1 -1
- package/dist/components/theme.d.ts +1 -1
- package/dist/components/theme.js +1 -1
- package/dist/components/toggle-group.d.cts +1 -1
- package/dist/components/toggle-group.d.ts +1 -1
- package/dist/components/toggle.cjs +1 -1
- package/dist/components/toggle.d.cts +1 -1
- package/dist/components/toggle.d.ts +1 -1
- package/dist/components/toggle.js +1 -1
- package/dist/components/tooltip.cjs +29 -25
- package/dist/components/tooltip.cjs.map +1 -1
- package/dist/components/tooltip.d.cts +4 -2
- package/dist/components/tooltip.d.ts +4 -2
- package/dist/components/tooltip.js +29 -25
- package/dist/components/tooltip.js.map +1 -1
- package/dist/lib/accent-theme.cjs +75 -17
- package/dist/lib/accent-theme.cjs.map +1 -1
- package/dist/lib/accent-theme.d.cts +15 -2
- package/dist/lib/accent-theme.d.ts +15 -2
- package/dist/lib/accent-theme.js +74 -18
- package/dist/lib/accent-theme.js.map +1 -1
- package/dist/lib/calendar-lists.cjs +222 -0
- package/dist/lib/calendar-lists.cjs.map +1 -0
- package/dist/lib/calendar-lists.d.cts +4 -0
- package/dist/lib/calendar-lists.d.ts +4 -0
- package/dist/lib/calendar-lists.js +217 -0
- package/dist/lib/calendar-lists.js.map +1 -0
- package/dist/lib/container-chrome.d.cts +1 -1
- package/dist/lib/container-chrome.d.ts +1 -1
- package/dist/lib/control-glyphs.cjs +37 -0
- package/dist/lib/control-glyphs.cjs.map +1 -0
- package/dist/lib/control-glyphs.d.cts +11 -0
- package/dist/lib/control-glyphs.d.ts +11 -0
- package/dist/lib/control-glyphs.js +35 -0
- package/dist/lib/control-glyphs.js.map +1 -0
- package/dist/lib/date-time-mask.cjs +155 -0
- package/dist/lib/date-time-mask.cjs.map +1 -0
- package/dist/lib/date-time-mask.d.cts +56 -0
- package/dist/lib/date-time-mask.d.ts +56 -0
- package/dist/lib/date-time-mask.js +147 -0
- package/dist/lib/date-time-mask.js.map +1 -0
- package/dist/lib/input-box-variants.cjs +11 -0
- package/dist/lib/input-box-variants.cjs.map +1 -1
- package/dist/lib/input-box-variants.d.cts +6 -2
- package/dist/lib/input-box-variants.d.ts +6 -2
- package/dist/lib/input-box-variants.js +8 -1
- package/dist/lib/input-box-variants.js.map +1 -1
- package/dist/lib/input-date-parts.cjs +154 -0
- package/dist/lib/input-date-parts.cjs.map +1 -0
- package/dist/lib/input-date-parts.d.cts +53 -0
- package/dist/lib/input-date-parts.d.ts +53 -0
- package/dist/lib/input-date-parts.js +147 -0
- package/dist/lib/input-date-parts.js.map +1 -0
- package/dist/lib/selection-list.d.cts +1 -1
- package/dist/lib/selection-list.d.ts +1 -1
- package/dist/lib/theme-types.cjs.map +1 -1
- package/dist/lib/theme-types.d.cts +1 -1
- package/dist/lib/theme-types.d.ts +1 -1
- package/dist/lib/theme-types.js.map +1 -1
- package/dist/lib/toggle-group-context.d.cts +1 -1
- package/dist/lib/toggle-group-context.d.ts +1 -1
- package/dist/styles/spark-default.css +369 -25
- package/dist/styles/theme.css +18 -98
- package/dist/{theme-types-Dlge0s3s.d.ts → theme-types-CHl-L2F-.d.cts} +2 -2
- package/dist/{theme-types-Dlge0s3s.d.cts → theme-types-CHl-L2F-.d.ts} +2 -2
- package/package.json +3 -2
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
let ictus = require("ictus");
|
|
4
|
+
let ictus_time = require("ictus/time");
|
|
5
|
+
//#region src/lib/date-time-mask.ts
|
|
6
|
+
const DATE_LENGTH = 10;
|
|
7
|
+
const JOIN = ", ";
|
|
8
|
+
const TIME_START = 12;
|
|
9
|
+
const splitValue = (value) => ({
|
|
10
|
+
date: value.slice(0, DATE_LENGTH),
|
|
11
|
+
time: value.length > DATE_LENGTH ? value.slice(TIME_START) : ""
|
|
12
|
+
});
|
|
13
|
+
const join = (date, time) => time ? `${date}${JOIN}${time}` : date;
|
|
14
|
+
/** Keys the mask consumes; any other printable key is ignored. */
|
|
15
|
+
function isDateTimeMaskKey(key, withTime = false) {
|
|
16
|
+
return (0, ictus.isDateMaskKey)(key) || withTime && (0, ictus_time.isTimeMaskKey)(key);
|
|
17
|
+
}
|
|
18
|
+
function stepOverSeparators(value, caret, key) {
|
|
19
|
+
const isSeparator = (char) => char !== void 0 && !/\d/.test(char);
|
|
20
|
+
let at = caret;
|
|
21
|
+
if (key === "Backspace") while (at > 0 && isSeparator(value[at - 1])) at--;
|
|
22
|
+
if (key === "Delete") while (at < value.length && isSeparator(value[at])) at++;
|
|
23
|
+
return at;
|
|
24
|
+
}
|
|
25
|
+
function applyDate(value, caret, key, separator, selectionEnd) {
|
|
26
|
+
if (selectionEnd !== void 0 && selectionEnd !== caret) return (0, ictus.apply)({
|
|
27
|
+
value,
|
|
28
|
+
caret,
|
|
29
|
+
selectionEnd,
|
|
30
|
+
key,
|
|
31
|
+
separator
|
|
32
|
+
});
|
|
33
|
+
return (0, ictus.apply)({
|
|
34
|
+
value,
|
|
35
|
+
caret: stepOverSeparators(value, caret, key),
|
|
36
|
+
key,
|
|
37
|
+
separator
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** One keystroke through the date (and time) mask: the next value and caret. */
|
|
41
|
+
function applyDateTimeMask({ caret, key, selectionEnd, separator, value, withTime = false }) {
|
|
42
|
+
if (!withTime) return applyDate(value, caret, key, separator, selectionEnd);
|
|
43
|
+
const { date, time } = splitValue(value);
|
|
44
|
+
const end = selectionEnd ?? caret;
|
|
45
|
+
const dateComplete = date.length === DATE_LENGTH;
|
|
46
|
+
if (end !== caret && caret < DATE_LENGTH && end > DATE_LENGTH) return applyDate(date, caret, key, separator, DATE_LENGTH);
|
|
47
|
+
if (!(caret > DATE_LENGTH || caret === DATE_LENGTH && dateComplete && key !== "Backspace")) {
|
|
48
|
+
const next = applyDate(date, caret, key, separator, end !== caret ? end : void 0);
|
|
49
|
+
return {
|
|
50
|
+
value: join(next.value, time),
|
|
51
|
+
caret: next.caret
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return applyTimePart({
|
|
55
|
+
caret,
|
|
56
|
+
date,
|
|
57
|
+
end,
|
|
58
|
+
key,
|
|
59
|
+
separator,
|
|
60
|
+
time,
|
|
61
|
+
value
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function applyTimePart({ caret, date, end, key, separator, time, value }) {
|
|
65
|
+
if (!(0, ictus_time.isTimeMaskKey)(key)) return {
|
|
66
|
+
value,
|
|
67
|
+
caret
|
|
68
|
+
};
|
|
69
|
+
const timeCaret = Math.max(0, caret - TIME_START);
|
|
70
|
+
const timeEnd = Math.max(0, end - TIME_START);
|
|
71
|
+
const hasSelection = timeEnd !== timeCaret;
|
|
72
|
+
if (key === "Backspace" && !hasSelection && timeCaret === 0) {
|
|
73
|
+
const next = applyDate(date, DATE_LENGTH, key, separator);
|
|
74
|
+
return {
|
|
75
|
+
value: join(next.value, time),
|
|
76
|
+
caret: next.caret
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const next = (0, ictus_time.applyTime)({
|
|
80
|
+
value: time,
|
|
81
|
+
caret: hasSelection ? timeCaret : stepOverSeparators(time, timeCaret, key),
|
|
82
|
+
selectionEnd: hasSelection ? timeEnd : void 0,
|
|
83
|
+
key
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
value: join(date, next.value),
|
|
87
|
+
caret: TIME_START + next.caret
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** Pasted text through the mask, e.g. `24.11.2026 14:30` or `24/11/2026`. */
|
|
91
|
+
function applyDateTimePaste({ caret, pasted, selectionEnd, separator, value, withTime = false }) {
|
|
92
|
+
const [datePart = "", timePart = ""] = pasted.trim().split(/[,\sT]+/);
|
|
93
|
+
if (!withTime || !timePart) return (0, ictus.applyPaste)({
|
|
94
|
+
value,
|
|
95
|
+
caret,
|
|
96
|
+
selectionEnd,
|
|
97
|
+
pasted: datePart,
|
|
98
|
+
separator
|
|
99
|
+
});
|
|
100
|
+
const date = (0, ictus.applyPaste)({
|
|
101
|
+
value: "",
|
|
102
|
+
caret: 0,
|
|
103
|
+
pasted: datePart,
|
|
104
|
+
separator
|
|
105
|
+
}).value;
|
|
106
|
+
const time = (0, ictus_time.applyTimePaste)({
|
|
107
|
+
value: "",
|
|
108
|
+
caret: 0,
|
|
109
|
+
pasted: timePart
|
|
110
|
+
}).value;
|
|
111
|
+
const next = join(date, time);
|
|
112
|
+
return {
|
|
113
|
+
value: next,
|
|
114
|
+
caret: next.length
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** `empty`, `incomplete`, `invalid` or `valid`, for the date and, with `withTime`, the time. */
|
|
118
|
+
function dateTimeStatus(text, withTime = false) {
|
|
119
|
+
const { date, time } = splitValue(text);
|
|
120
|
+
const dateState = (0, ictus.dateStatus)(date);
|
|
121
|
+
if (!withTime || dateState === "empty" || dateState === "invalid") return dateState;
|
|
122
|
+
if (dateState === "incomplete") return "incomplete";
|
|
123
|
+
const timeState = time ? (0, ictus_time.timeStatus)(time) : "incomplete";
|
|
124
|
+
return timeState === "empty" ? "incomplete" : timeState;
|
|
125
|
+
}
|
|
126
|
+
/** The date in the text, with its time when `withTime`; undefined until it is complete and real. */
|
|
127
|
+
function parseDateTime(text, withTime = false) {
|
|
128
|
+
if (dateTimeStatus(text, withTime) !== "valid") return void 0;
|
|
129
|
+
const { date, time } = splitValue(text);
|
|
130
|
+
const day = (0, ictus.parseDate)(date);
|
|
131
|
+
if (!day || !withTime) return day;
|
|
132
|
+
const clock = (0, ictus_time.parseTime)(time);
|
|
133
|
+
if (!clock) return void 0;
|
|
134
|
+
day.setHours(clock.hours, clock.minutes, 0, 0);
|
|
135
|
+
return day;
|
|
136
|
+
}
|
|
137
|
+
/** The day in the text, even while its time is still being typed. */
|
|
138
|
+
function parseDatePart(text) {
|
|
139
|
+
return (0, ictus.parseDate)(splitValue(text).date);
|
|
140
|
+
}
|
|
141
|
+
/** The masked text for a date: `24.11.2026` or `24.11.2026, 14:30`. */
|
|
142
|
+
function formatDateTime(date, separator, withTime = false) {
|
|
143
|
+
return join((0, ictus.formatDate)(date, separator), withTime ? (0, ictus_time.formatTime)(date) : "");
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
exports.applyDateTimeMask = applyDateTimeMask;
|
|
147
|
+
exports.applyDateTimePaste = applyDateTimePaste;
|
|
148
|
+
exports.dateTimeStatus = dateTimeStatus;
|
|
149
|
+
exports.formatDateTime = formatDateTime;
|
|
150
|
+
exports.formatTime = ictus_time.formatTime;
|
|
151
|
+
exports.isDateTimeMaskKey = isDateTimeMaskKey;
|
|
152
|
+
exports.parseDatePart = parseDatePart;
|
|
153
|
+
exports.parseDateTime = parseDateTime;
|
|
154
|
+
|
|
155
|
+
//# sourceMappingURL=date-time-mask.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-time-mask.cjs","names":[],"sources":["../../src/lib/date-time-mask.ts"],"sourcesContent":["import {\n apply,\n applyPaste,\n dateStatus,\n formatDate,\n isDateMaskKey,\n parseDate,\n} from 'ictus'\nimport {\n applyTime,\n applyTimePaste,\n formatTime,\n isTimeMaskKey,\n parseTime,\n timeStatus,\n} from 'ictus/time'\n\n// Fixed positions: `DD.MM.YYYY` then `, HH:MM`, i.e. day-month-year with a one-character\n// separator, the only layout Input Date Time types\nconst DATE_LENGTH = 10\nconst JOIN = ', '\nconst TIME_START = DATE_LENGTH + JOIN.length\n\ntype MaskOptions = { separator: string; withTime?: boolean }\n\nexport type DateTimeMaskInput = MaskOptions & {\n caret: number\n key: string\n selectionEnd?: number\n value: string\n}\n\nexport type DateTimeMaskResult = { caret: number; value: string }\n\nexport type DateTimeStatus = 'empty' | 'incomplete' | 'invalid' | 'valid'\n\nconst splitValue = (value: string) => ({\n date: value.slice(0, DATE_LENGTH),\n time: value.length > DATE_LENGTH ? value.slice(TIME_START) : '',\n})\n\nconst join = (date: string, time: string) =>\n time ? `${date}${JOIN}${time}` : date\n\n/** Keys the mask consumes; any other printable key is ignored. */\nexport function isDateTimeMaskKey(key: string, withTime = false) {\n return isDateMaskKey(key) || (withTime && isTimeMaskKey(key))\n}\n\n// Backspace right after a separator deletes the digit before it, Delete right before one the digit after\nfunction stepOverSeparators(value: string, caret: number, key: string) {\n const isSeparator = (char: string | undefined) =>\n char !== undefined && !/\\d/.test(char)\n let at = caret\n if (key === 'Backspace') while (at > 0 && isSeparator(value[at - 1])) at--\n if (key === 'Delete') while (at < value.length && isSeparator(value[at])) at++\n return at\n}\n\nfunction applyDate(\n value: string,\n caret: number,\n key: string,\n separator: string,\n selectionEnd?: number,\n): DateTimeMaskResult {\n if (selectionEnd !== undefined && selectionEnd !== caret)\n return apply({ value, caret, selectionEnd, key, separator })\n return apply({\n value,\n caret: stepOverSeparators(value, caret, key),\n key,\n separator,\n })\n}\n\n/** One keystroke through the date (and time) mask: the next value and caret. */\nexport function applyDateTimeMask({\n caret,\n key,\n selectionEnd,\n separator,\n value,\n withTime = false,\n}: DateTimeMaskInput): DateTimeMaskResult {\n if (!withTime) return applyDate(value, caret, key, separator, selectionEnd)\n\n const { date, time } = splitValue(value)\n const end = selectionEnd ?? caret\n const dateComplete = date.length === DATE_LENGTH\n\n // A selection reaching into the time drops the time; one inside it edits the time only\n if (end !== caret && caret < DATE_LENGTH && end > DATE_LENGTH)\n return applyDate(date, caret, key, separator, DATE_LENGTH)\n\n const inTime =\n caret > DATE_LENGTH ||\n (caret === DATE_LENGTH && dateComplete && key !== 'Backspace')\n if (!inTime) {\n const next = applyDate(\n date,\n caret,\n key,\n separator,\n end !== caret ? end : undefined,\n )\n return { value: join(next.value, time), caret: next.caret }\n }\n\n return applyTimePart({ caret, date, end, key, separator, time, value })\n}\n\nfunction applyTimePart({\n caret,\n date,\n end,\n key,\n separator,\n time,\n value,\n}: {\n caret: number\n date: string\n end: number\n key: string\n separator: string\n time: string\n value: string\n}): DateTimeMaskResult {\n if (!isTimeMaskKey(key)) return { value, caret }\n const timeCaret = Math.max(0, caret - TIME_START)\n const timeEnd = Math.max(0, end - TIME_START)\n const hasSelection = timeEnd !== timeCaret\n\n // Backspace at the start of the time steps back into the year\n if (key === 'Backspace' && !hasSelection && timeCaret === 0) {\n const next = applyDate(date, DATE_LENGTH, key, separator)\n return { value: join(next.value, time), caret: next.caret }\n }\n\n const next = applyTime({\n value: time,\n caret: hasSelection ? timeCaret : stepOverSeparators(time, timeCaret, key),\n selectionEnd: hasSelection ? timeEnd : undefined,\n key,\n })\n return { value: join(date, next.value), caret: TIME_START + next.caret }\n}\n\n/** Pasted text through the mask, e.g. `24.11.2026 14:30` or `24/11/2026`. */\nexport function applyDateTimePaste({\n caret,\n pasted,\n selectionEnd,\n separator,\n value,\n withTime = false,\n}: MaskOptions & {\n caret: number\n pasted: string\n selectionEnd?: number\n value: string\n}): DateTimeMaskResult {\n const [datePart = '', timePart = ''] = pasted.trim().split(/[,\\sT]+/)\n if (!withTime || !timePart)\n return applyPaste({\n value,\n caret,\n selectionEnd,\n pasted: datePart,\n separator,\n })\n\n const date = applyPaste({\n value: '',\n caret: 0,\n pasted: datePart,\n separator,\n }).value\n const time = applyTimePaste({ value: '', caret: 0, pasted: timePart }).value\n const next = join(date, time)\n return { value: next, caret: next.length }\n}\n\n/** `empty`, `incomplete`, `invalid` or `valid`, for the date and, with `withTime`, the time. */\nexport function dateTimeStatus(text: string, withTime = false): DateTimeStatus {\n const { date, time } = splitValue(text)\n const dateState = dateStatus(date)\n if (!withTime || dateState === 'empty' || dateState === 'invalid')\n return dateState\n if (dateState === 'incomplete') return 'incomplete'\n const timeState = time ? timeStatus(time) : 'incomplete'\n return timeState === 'empty' ? 'incomplete' : timeState\n}\n\n/** The date in the text, with its time when `withTime`; undefined until it is complete and real. */\nexport function parseDateTime(\n text: string,\n withTime = false,\n): Date | undefined {\n if (dateTimeStatus(text, withTime) !== 'valid') return undefined\n const { date, time } = splitValue(text)\n const day = parseDate(date)\n if (!day || !withTime) return day\n const clock = parseTime(time)\n if (!clock) return undefined\n day.setHours(clock.hours, clock.minutes, 0, 0)\n return day\n}\n\n/** The day in the text, even while its time is still being typed. */\nexport function parseDatePart(text: string) {\n return parseDate(splitValue(text).date)\n}\n\n/** The masked text for a date: `24.11.2026` or `24.11.2026, 14:30`. */\nexport function formatDateTime(\n date: Date,\n separator: string,\n withTime = false,\n) {\n return join(formatDate(date, separator), withTime ? formatTime(date) : '')\n}\n\nexport { formatTime }\n"],"mappings":";;;;;AAmBA,MAAM,cAAc;AACpB,MAAM,OAAO;AACb,MAAM,aAAa;AAenB,MAAM,cAAc,WAAmB;CACrC,MAAM,MAAM,MAAM,GAAG,WAAW;CAChC,MAAM,MAAM,SAAS,cAAc,MAAM,MAAM,UAAU,IAAI;AAC/D;AAEA,MAAM,QAAQ,MAAc,SAC1B,OAAO,GAAG,OAAO,OAAO,SAAS;;AAGnC,SAAgB,kBAAkB,KAAa,WAAW,OAAO;CAC/D,QAAA,GAAA,MAAA,eAAqB,GAAG,KAAM,aAAA,GAAA,WAAA,eAA0B,GAAG;AAC7D;AAGA,SAAS,mBAAmB,OAAe,OAAe,KAAa;CACrE,MAAM,eAAe,SACnB,SAAS,KAAA,KAAa,CAAC,KAAK,KAAK,IAAI;CACvC,IAAI,KAAK;CACT,IAAI,QAAQ,aAAa,OAAO,KAAK,KAAK,YAAY,MAAM,KAAK,EAAE,GAAG;CACtE,IAAI,QAAQ,UAAU,OAAO,KAAK,MAAM,UAAU,YAAY,MAAM,GAAG,GAAG;CAC1E,OAAO;AACT;AAEA,SAAS,UACP,OACA,OACA,KACA,WACA,cACoB;CACpB,IAAI,iBAAiB,KAAA,KAAa,iBAAiB,OACjD,Q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,CAAC,OAAO,CAAC,UAAU,OAAO;CAC9B,MAAM,SAAA,GAAA,WAAA,WAAkB,IAAI;CAC5B,IAAI,CAAC,OAAO,OAAO,KAAA;CACnB,IAAI,SAAS,MAAM,OAAO,MAAM,SAAS,GAAG,CAAC;CAC7C,OAAO;AACT;;AAGA,SAAgB,cAAc,MAAc;CAC1C,QAAA,GAAA,MAAA,WAAiB,WAAW,IAAI,EAAE,IAAI;AACxC;;AAGA,SAAgB,eACd,MACA,WACA,WAAW,OACX;CACA,OAAO,MAAA,GAAA,MAAA,YAAgB,MAAM,SAAS,GAAG,YAAA,GAAA,WAAA,YAAsB,IAAI,IAAI,EAAE;AAC3E"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { formatTime } from "ictus/time";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/date-time-mask.d.ts
|
|
6
|
+
type MaskOptions = {
|
|
7
|
+
separator: string;
|
|
8
|
+
withTime?: boolean;
|
|
9
|
+
};
|
|
10
|
+
type DateTimeMaskInput = MaskOptions & {
|
|
11
|
+
caret: number;
|
|
12
|
+
key: string;
|
|
13
|
+
selectionEnd?: number;
|
|
14
|
+
value: string;
|
|
15
|
+
};
|
|
16
|
+
type DateTimeMaskResult = {
|
|
17
|
+
caret: number;
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
type DateTimeStatus = 'empty' | 'incomplete' | 'invalid' | 'valid';
|
|
21
|
+
/** Keys the mask consumes; any other printable key is ignored. */
|
|
22
|
+
declare function isDateTimeMaskKey(key: string, withTime?: boolean): boolean;
|
|
23
|
+
/** One keystroke through the date (and time) mask: the next value and caret. */
|
|
24
|
+
declare function applyDateTimeMask({
|
|
25
|
+
caret,
|
|
26
|
+
key,
|
|
27
|
+
selectionEnd,
|
|
28
|
+
separator,
|
|
29
|
+
value,
|
|
30
|
+
withTime
|
|
31
|
+
}: DateTimeMaskInput): DateTimeMaskResult;
|
|
32
|
+
/** Pasted text through the mask, e.g. `24.11.2026 14:30` or `24/11/2026`. */
|
|
33
|
+
declare function applyDateTimePaste({
|
|
34
|
+
caret,
|
|
35
|
+
pasted,
|
|
36
|
+
selectionEnd,
|
|
37
|
+
separator,
|
|
38
|
+
value,
|
|
39
|
+
withTime
|
|
40
|
+
}: MaskOptions & {
|
|
41
|
+
caret: number;
|
|
42
|
+
pasted: string;
|
|
43
|
+
selectionEnd?: number;
|
|
44
|
+
value: string;
|
|
45
|
+
}): DateTimeMaskResult;
|
|
46
|
+
/** `empty`, `incomplete`, `invalid` or `valid`, for the date and, with `withTime`, the time. */
|
|
47
|
+
declare function dateTimeStatus(text: string, withTime?: boolean): DateTimeStatus;
|
|
48
|
+
/** The date in the text, with its time when `withTime`; undefined until it is complete and real. */
|
|
49
|
+
declare function parseDateTime(text: string, withTime?: boolean): Date | undefined;
|
|
50
|
+
/** The day in the text, even while its time is still being typed. */
|
|
51
|
+
declare function parseDatePart(text: string): Date | undefined;
|
|
52
|
+
/** The masked text for a date: `24.11.2026` or `24.11.2026, 14:30`. */
|
|
53
|
+
declare function formatDateTime(date: Date, separator: string, withTime?: boolean): string;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { DateTimeMaskInput, DateTimeMaskResult, DateTimeStatus, applyDateTimeMask, applyDateTimePaste, dateTimeStatus, formatDateTime, formatTime, isDateTimeMaskKey, parseDatePart, parseDateTime };
|
|
56
|
+
//# sourceMappingURL=date-time-mask.d.cts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { formatTime } from "ictus/time";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/date-time-mask.d.ts
|
|
6
|
+
type MaskOptions = {
|
|
7
|
+
separator: string;
|
|
8
|
+
withTime?: boolean;
|
|
9
|
+
};
|
|
10
|
+
type DateTimeMaskInput = MaskOptions & {
|
|
11
|
+
caret: number;
|
|
12
|
+
key: string;
|
|
13
|
+
selectionEnd?: number;
|
|
14
|
+
value: string;
|
|
15
|
+
};
|
|
16
|
+
type DateTimeMaskResult = {
|
|
17
|
+
caret: number;
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
type DateTimeStatus = 'empty' | 'incomplete' | 'invalid' | 'valid';
|
|
21
|
+
/** Keys the mask consumes; any other printable key is ignored. */
|
|
22
|
+
declare function isDateTimeMaskKey(key: string, withTime?: boolean): boolean;
|
|
23
|
+
/** One keystroke through the date (and time) mask: the next value and caret. */
|
|
24
|
+
declare function applyDateTimeMask({
|
|
25
|
+
caret,
|
|
26
|
+
key,
|
|
27
|
+
selectionEnd,
|
|
28
|
+
separator,
|
|
29
|
+
value,
|
|
30
|
+
withTime
|
|
31
|
+
}: DateTimeMaskInput): DateTimeMaskResult;
|
|
32
|
+
/** Pasted text through the mask, e.g. `24.11.2026 14:30` or `24/11/2026`. */
|
|
33
|
+
declare function applyDateTimePaste({
|
|
34
|
+
caret,
|
|
35
|
+
pasted,
|
|
36
|
+
selectionEnd,
|
|
37
|
+
separator,
|
|
38
|
+
value,
|
|
39
|
+
withTime
|
|
40
|
+
}: MaskOptions & {
|
|
41
|
+
caret: number;
|
|
42
|
+
pasted: string;
|
|
43
|
+
selectionEnd?: number;
|
|
44
|
+
value: string;
|
|
45
|
+
}): DateTimeMaskResult;
|
|
46
|
+
/** `empty`, `incomplete`, `invalid` or `valid`, for the date and, with `withTime`, the time. */
|
|
47
|
+
declare function dateTimeStatus(text: string, withTime?: boolean): DateTimeStatus;
|
|
48
|
+
/** The date in the text, with its time when `withTime`; undefined until it is complete and real. */
|
|
49
|
+
declare function parseDateTime(text: string, withTime?: boolean): Date | undefined;
|
|
50
|
+
/** The day in the text, even while its time is still being typed. */
|
|
51
|
+
declare function parseDatePart(text: string): Date | undefined;
|
|
52
|
+
/** The masked text for a date: `24.11.2026` or `24.11.2026, 14:30`. */
|
|
53
|
+
declare function formatDateTime(date: Date, separator: string, withTime?: boolean): string;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { DateTimeMaskInput, DateTimeMaskResult, DateTimeStatus, applyDateTimeMask, applyDateTimePaste, dateTimeStatus, formatDateTime, formatTime, isDateTimeMaskKey, parseDatePart, parseDateTime };
|
|
56
|
+
//# sourceMappingURL=date-time-mask.d.ts.map
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { apply, applyPaste, dateStatus, formatDate, isDateMaskKey, parseDate } from "ictus";
|
|
3
|
+
import { applyTime, applyTimePaste, formatTime, isTimeMaskKey, parseTime, timeStatus } from "ictus/time";
|
|
4
|
+
//#region src/lib/date-time-mask.ts
|
|
5
|
+
const DATE_LENGTH = 10;
|
|
6
|
+
const JOIN = ", ";
|
|
7
|
+
const TIME_START = 12;
|
|
8
|
+
const splitValue = (value) => ({
|
|
9
|
+
date: value.slice(0, DATE_LENGTH),
|
|
10
|
+
time: value.length > DATE_LENGTH ? value.slice(TIME_START) : ""
|
|
11
|
+
});
|
|
12
|
+
const join = (date, time) => time ? `${date}${JOIN}${time}` : date;
|
|
13
|
+
/** Keys the mask consumes; any other printable key is ignored. */
|
|
14
|
+
function isDateTimeMaskKey(key, withTime = false) {
|
|
15
|
+
return isDateMaskKey(key) || withTime && isTimeMaskKey(key);
|
|
16
|
+
}
|
|
17
|
+
function stepOverSeparators(value, caret, key) {
|
|
18
|
+
const isSeparator = (char) => char !== void 0 && !/\d/.test(char);
|
|
19
|
+
let at = caret;
|
|
20
|
+
if (key === "Backspace") while (at > 0 && isSeparator(value[at - 1])) at--;
|
|
21
|
+
if (key === "Delete") while (at < value.length && isSeparator(value[at])) at++;
|
|
22
|
+
return at;
|
|
23
|
+
}
|
|
24
|
+
function applyDate(value, caret, key, separator, selectionEnd) {
|
|
25
|
+
if (selectionEnd !== void 0 && selectionEnd !== caret) return apply({
|
|
26
|
+
value,
|
|
27
|
+
caret,
|
|
28
|
+
selectionEnd,
|
|
29
|
+
key,
|
|
30
|
+
separator
|
|
31
|
+
});
|
|
32
|
+
return apply({
|
|
33
|
+
value,
|
|
34
|
+
caret: stepOverSeparators(value, caret, key),
|
|
35
|
+
key,
|
|
36
|
+
separator
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** One keystroke through the date (and time) mask: the next value and caret. */
|
|
40
|
+
function applyDateTimeMask({ caret, key, selectionEnd, separator, value, withTime = false }) {
|
|
41
|
+
if (!withTime) return applyDate(value, caret, key, separator, selectionEnd);
|
|
42
|
+
const { date, time } = splitValue(value);
|
|
43
|
+
const end = selectionEnd ?? caret;
|
|
44
|
+
const dateComplete = date.length === DATE_LENGTH;
|
|
45
|
+
if (end !== caret && caret < DATE_LENGTH && end > DATE_LENGTH) return applyDate(date, caret, key, separator, DATE_LENGTH);
|
|
46
|
+
if (!(caret > DATE_LENGTH || caret === DATE_LENGTH && dateComplete && key !== "Backspace")) {
|
|
47
|
+
const next = applyDate(date, caret, key, separator, end !== caret ? end : void 0);
|
|
48
|
+
return {
|
|
49
|
+
value: join(next.value, time),
|
|
50
|
+
caret: next.caret
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return applyTimePart({
|
|
54
|
+
caret,
|
|
55
|
+
date,
|
|
56
|
+
end,
|
|
57
|
+
key,
|
|
58
|
+
separator,
|
|
59
|
+
time,
|
|
60
|
+
value
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function applyTimePart({ caret, date, end, key, separator, time, value }) {
|
|
64
|
+
if (!isTimeMaskKey(key)) return {
|
|
65
|
+
value,
|
|
66
|
+
caret
|
|
67
|
+
};
|
|
68
|
+
const timeCaret = Math.max(0, caret - TIME_START);
|
|
69
|
+
const timeEnd = Math.max(0, end - TIME_START);
|
|
70
|
+
const hasSelection = timeEnd !== timeCaret;
|
|
71
|
+
if (key === "Backspace" && !hasSelection && timeCaret === 0) {
|
|
72
|
+
const next = applyDate(date, DATE_LENGTH, key, separator);
|
|
73
|
+
return {
|
|
74
|
+
value: join(next.value, time),
|
|
75
|
+
caret: next.caret
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const next = applyTime({
|
|
79
|
+
value: time,
|
|
80
|
+
caret: hasSelection ? timeCaret : stepOverSeparators(time, timeCaret, key),
|
|
81
|
+
selectionEnd: hasSelection ? timeEnd : void 0,
|
|
82
|
+
key
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
value: join(date, next.value),
|
|
86
|
+
caret: TIME_START + next.caret
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Pasted text through the mask, e.g. `24.11.2026 14:30` or `24/11/2026`. */
|
|
90
|
+
function applyDateTimePaste({ caret, pasted, selectionEnd, separator, value, withTime = false }) {
|
|
91
|
+
const [datePart = "", timePart = ""] = pasted.trim().split(/[,\sT]+/);
|
|
92
|
+
if (!withTime || !timePart) return applyPaste({
|
|
93
|
+
value,
|
|
94
|
+
caret,
|
|
95
|
+
selectionEnd,
|
|
96
|
+
pasted: datePart,
|
|
97
|
+
separator
|
|
98
|
+
});
|
|
99
|
+
const date = applyPaste({
|
|
100
|
+
value: "",
|
|
101
|
+
caret: 0,
|
|
102
|
+
pasted: datePart,
|
|
103
|
+
separator
|
|
104
|
+
}).value;
|
|
105
|
+
const time = applyTimePaste({
|
|
106
|
+
value: "",
|
|
107
|
+
caret: 0,
|
|
108
|
+
pasted: timePart
|
|
109
|
+
}).value;
|
|
110
|
+
const next = join(date, time);
|
|
111
|
+
return {
|
|
112
|
+
value: next,
|
|
113
|
+
caret: next.length
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** `empty`, `incomplete`, `invalid` or `valid`, for the date and, with `withTime`, the time. */
|
|
117
|
+
function dateTimeStatus(text, withTime = false) {
|
|
118
|
+
const { date, time } = splitValue(text);
|
|
119
|
+
const dateState = dateStatus(date);
|
|
120
|
+
if (!withTime || dateState === "empty" || dateState === "invalid") return dateState;
|
|
121
|
+
if (dateState === "incomplete") return "incomplete";
|
|
122
|
+
const timeState = time ? timeStatus(time) : "incomplete";
|
|
123
|
+
return timeState === "empty" ? "incomplete" : timeState;
|
|
124
|
+
}
|
|
125
|
+
/** The date in the text, with its time when `withTime`; undefined until it is complete and real. */
|
|
126
|
+
function parseDateTime(text, withTime = false) {
|
|
127
|
+
if (dateTimeStatus(text, withTime) !== "valid") return void 0;
|
|
128
|
+
const { date, time } = splitValue(text);
|
|
129
|
+
const day = parseDate(date);
|
|
130
|
+
if (!day || !withTime) return day;
|
|
131
|
+
const clock = parseTime(time);
|
|
132
|
+
if (!clock) return void 0;
|
|
133
|
+
day.setHours(clock.hours, clock.minutes, 0, 0);
|
|
134
|
+
return day;
|
|
135
|
+
}
|
|
136
|
+
/** The day in the text, even while its time is still being typed. */
|
|
137
|
+
function parseDatePart(text) {
|
|
138
|
+
return parseDate(splitValue(text).date);
|
|
139
|
+
}
|
|
140
|
+
/** The masked text for a date: `24.11.2026` or `24.11.2026, 14:30`. */
|
|
141
|
+
function formatDateTime(date, separator, withTime = false) {
|
|
142
|
+
return join(formatDate(date, separator), withTime ? formatTime(date) : "");
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
export { applyDateTimeMask, applyDateTimePaste, dateTimeStatus, formatDateTime, formatTime, isDateTimeMaskKey, parseDatePart, parseDateTime };
|
|
146
|
+
|
|
147
|
+
//# sourceMappingURL=date-time-mask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-time-mask.js","names":[],"sources":["../../src/lib/date-time-mask.ts"],"sourcesContent":["import {\n apply,\n applyPaste,\n dateStatus,\n formatDate,\n isDateMaskKey,\n parseDate,\n} from 'ictus'\nimport {\n applyTime,\n applyTimePaste,\n formatTime,\n isTimeMaskKey,\n parseTime,\n timeStatus,\n} from 'ictus/time'\n\n// Fixed positions: `DD.MM.YYYY` then `, HH:MM`, i.e. day-month-year with a one-character\n// separator, the only layout Input Date Time types\nconst DATE_LENGTH = 10\nconst JOIN = ', '\nconst TIME_START = DATE_LENGTH + JOIN.length\n\ntype MaskOptions = { separator: string; withTime?: boolean }\n\nexport type DateTimeMaskInput = MaskOptions & {\n caret: number\n key: string\n selectionEnd?: number\n value: string\n}\n\nexport type DateTimeMaskResult = { caret: number; value: string }\n\nexport type DateTimeStatus = 'empty' | 'incomplete' | 'invalid' | 'valid'\n\nconst splitValue = (value: string) => ({\n date: value.slice(0, DATE_LENGTH),\n time: value.length > DATE_LENGTH ? value.slice(TIME_START) : '',\n})\n\nconst join = (date: string, time: string) =>\n time ? `${date}${JOIN}${time}` : date\n\n/** Keys the mask consumes; any other printable key is ignored. */\nexport function isDateTimeMaskKey(key: string, withTime = false) {\n return isDateMaskKey(key) || (withTime && isTimeMaskKey(key))\n}\n\n// Backspace right after a separator deletes the digit before it, Delete right before one the digit after\nfunction stepOverSeparators(value: string, caret: number, key: string) {\n const isSeparator = (char: string | undefined) =>\n char !== undefined && !/\\d/.test(char)\n let at = caret\n if (key === 'Backspace') while (at > 0 && isSeparator(value[at - 1])) at--\n if (key === 'Delete') while (at < value.length && isSeparator(value[at])) at++\n return at\n}\n\nfunction applyDate(\n value: string,\n caret: number,\n key: string,\n separator: string,\n selectionEnd?: number,\n): DateTimeMaskResult {\n if (selectionEnd !== undefined && selectionEnd !== caret)\n return apply({ value, caret, selectionEnd, key, separator })\n return apply({\n value,\n caret: stepOverSeparators(value, caret, key),\n key,\n separator,\n })\n}\n\n/** One keystroke through the date (and time) mask: the next value and caret. */\nexport function applyDateTimeMask({\n caret,\n key,\n selectionEnd,\n separator,\n value,\n withTime = false,\n}: DateTimeMaskInput): DateTimeMaskResult {\n if (!withTime) return applyDate(value, caret, key, separator, selectionEnd)\n\n const { date, time } = splitValue(value)\n const end = selectionEnd ?? caret\n const dateComplete = date.length === DATE_LENGTH\n\n // A selection reaching into the time drops the time; one inside it edits the time only\n if (end !== caret && caret < DATE_LENGTH && end > DATE_LENGTH)\n return applyDate(date, caret, key, separator, DATE_LENGTH)\n\n const inTime =\n caret > DATE_LENGTH ||\n (caret === DATE_LENGTH && dateComplete && key !== 'Backspace')\n if (!inTime) {\n const next = applyDate(\n date,\n caret,\n key,\n separator,\n end !== caret ? end : undefined,\n )\n return { value: join(next.value, time), caret: next.caret }\n }\n\n return applyTimePart({ caret, date, end, key, separator, time, value })\n}\n\nfunction applyTimePart({\n caret,\n date,\n end,\n key,\n separator,\n time,\n value,\n}: {\n caret: number\n date: string\n end: number\n key: string\n separator: string\n time: string\n value: string\n}): DateTimeMaskResult {\n if (!isTimeMaskKey(key)) return { value, caret }\n const timeCaret = Math.max(0, caret - TIME_START)\n const timeEnd = Math.max(0, end - TIME_START)\n const hasSelection = timeEnd !== timeCaret\n\n // Backspace at the start of the time steps back into the year\n if (key === 'Backspace' && !hasSelection && timeCaret === 0) {\n const next = applyDate(date, DATE_LENGTH, key, separator)\n return { value: join(next.value, time), caret: next.caret }\n }\n\n const next = applyTime({\n value: time,\n caret: hasSelection ? timeCaret : stepOverSeparators(time, timeCaret, key),\n selectionEnd: hasSelection ? timeEnd : undefined,\n key,\n })\n return { value: join(date, next.value), caret: TIME_START + next.caret }\n}\n\n/** Pasted text through the mask, e.g. `24.11.2026 14:30` or `24/11/2026`. */\nexport function applyDateTimePaste({\n caret,\n pasted,\n selectionEnd,\n separator,\n value,\n withTime = false,\n}: MaskOptions & {\n caret: number\n pasted: string\n selectionEnd?: number\n value: string\n}): DateTimeMaskResult {\n const [datePart = '', timePart = ''] = pasted.trim().split(/[,\\sT]+/)\n if (!withTime || !timePart)\n return applyPaste({\n value,\n caret,\n selectionEnd,\n pasted: datePart,\n separator,\n })\n\n const date = applyPaste({\n value: '',\n caret: 0,\n pasted: datePart,\n separator,\n }).value\n const time = applyTimePaste({ value: '', caret: 0, pasted: timePart }).value\n const next = join(date, time)\n return { value: next, caret: next.length }\n}\n\n/** `empty`, `incomplete`, `invalid` or `valid`, for the date and, with `withTime`, the time. */\nexport function dateTimeStatus(text: string, withTime = false): DateTimeStatus {\n const { date, time } = splitValue(text)\n const dateState = dateStatus(date)\n if (!withTime || dateState === 'empty' || dateState === 'invalid')\n return dateState\n if (dateState === 'incomplete') return 'incomplete'\n const timeState = time ? timeStatus(time) : 'incomplete'\n return timeState === 'empty' ? 'incomplete' : timeState\n}\n\n/** The date in the text, with its time when `withTime`; undefined until it is complete and real. */\nexport function parseDateTime(\n text: string,\n withTime = false,\n): Date | undefined {\n if (dateTimeStatus(text, withTime) !== 'valid') return undefined\n const { date, time } = splitValue(text)\n const day = parseDate(date)\n if (!day || !withTime) return day\n const clock = parseTime(time)\n if (!clock) return undefined\n day.setHours(clock.hours, clock.minutes, 0, 0)\n return day\n}\n\n/** The day in the text, even while its time is still being typed. */\nexport function parseDatePart(text: string) {\n return parseDate(splitValue(text).date)\n}\n\n/** The masked text for a date: `24.11.2026` or `24.11.2026, 14:30`. */\nexport function formatDateTime(\n date: Date,\n separator: string,\n withTime = false,\n) {\n return join(formatDate(date, separator), withTime ? formatTime(date) : '')\n}\n\nexport { formatTime }\n"],"mappings":";;;;AAmBA,MAAM,cAAc;AACpB,MAAM,OAAO;AACb,MAAM,aAAa;AAenB,MAAM,cAAc,WAAmB;CACrC,MAAM,MAAM,MAAM,GAAG,WAAW;CAChC,MAAM,MAAM,SAAS,cAAc,MAAM,MAAM,UAAU,IAAI;AAC/D;AAEA,MAAM,QAAQ,MAAc,SAC1B,OAAO,GAAG,OAAO,OAAO,SAAS;;AAGnC,SAAgB,kBAAkB,KAAa,WAAW,OAAO;CAC/D,OAAO,cAAc,GAAG,KAAM,YAAY,cAAc,GAAG;AAC7D;AAGA,SAAS,mBAAmB,OAAe,OAAe,KAAa;CACrE,MAAM,eAAe,SACnB,SAAS,KAAA,KAAa,CAAC,KAAK,KAAK,IAAI;CACvC,IAAI,KAAK;CACT,IAAI,QAAQ,aAAa,OAAO,KAAK,KAAK,YAAY,MAAM,KAAK,EAAE,GAAG;CACtE,IAAI,QAAQ,UAAU,OAAO,KAAK,MAAM,UAAU,YAAY,MAAM,GAAG,GAAG;CAC1E,OAAO;AACT;AAEA,SAAS,UACP,OACA,OACA,KACA,WAC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AI,CAAC,OAAO,OAAO,KAAA;CACnB,IAAI,SAAS,MAAM,OAAO,MAAM,SAAS,GAAG,CAAC;CAC7C,OAAO;AACT;;AAGA,SAAgB,cAAc,MAAc;CAC1C,OAAO,UAAU,WAAW,IAAI,EAAE,IAAI;AACxC;;AAGA,SAAgB,eACd,MACA,WACA,WAAW,OACX;CACA,OAAO,KAAK,WAAW,MAAM,SAAS,GAAG,WAAW,WAAW,IAAI,IAAI,EAAE;AAC3E"}
|
|
@@ -24,9 +24,20 @@ const boxChrome = {
|
|
|
24
24
|
gray: (0, cn.cn)(GHOST_UNDERLINE, "border-b-input-gray")
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
+
const FLOATING_PLACEHOLDER = " ";
|
|
28
|
+
const FLOATING_SURFACE_FOCUS = "focus-visible:outline-offset-[-2px]!";
|
|
29
|
+
const FLOATING_ADORNMENT_SHIFT = "transition-[translate] duration-200 ease-[cubic-bezier(0,0,0.2,1)] field-floated:translate-y-2 motion-reduce:transition-none";
|
|
30
|
+
function floatingChrome(inputStyle) {
|
|
31
|
+
if (inputStyle === "outlined") return "h-12 border-0! px-3 py-0 focus-visible:outline-hidden!";
|
|
32
|
+
return (0, cn.cn)("h-12 pt-5 pb-1", inputStyle === "surface" && "focus-visible:outline-offset-[-2px]!");
|
|
33
|
+
}
|
|
27
34
|
//#endregion
|
|
35
|
+
exports.FLOATING_ADORNMENT_SHIFT = FLOATING_ADORNMENT_SHIFT;
|
|
36
|
+
exports.FLOATING_PLACEHOLDER = FLOATING_PLACEHOLDER;
|
|
37
|
+
exports.FLOATING_SURFACE_FOCUS = FLOATING_SURFACE_FOCUS;
|
|
28
38
|
exports.GHOST_UNDERLINE = GHOST_UNDERLINE;
|
|
29
39
|
exports.INSET_UNDERLINE = INSET_UNDERLINE;
|
|
30
40
|
exports.boxChrome = boxChrome;
|
|
41
|
+
exports.floatingChrome = floatingChrome;
|
|
31
42
|
|
|
32
43
|
//# sourceMappingURL=input-box-variants.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-box-variants.cjs","names":[],"sources":["../../src/lib/input-box-variants.ts"],"sourcesContent":["import { cn } from '../utils/cn'\nimport type { SparkInputColor, SparkInputStyle } from './theme-types'\n\nexport const GHOST_UNDERLINE =\n 'h-10 rounded-none border-0 border-b-2 px-0 py-2 text-base focus:border-b-input-active focus-visible:border-b-input-active user-valid:border-b-input-active user-invalid:border-b-input-invalid user-invalid:text-error user-invalid:focus:border-b-(--color-error-active)! user-invalid:focus-visible:border-b-(--color-error-active)! aria-invalid:border-b-input-invalid aria-invalid:text-error aria-invalid:focus:border-b-(--color-error-active)! aria-invalid:focus-visible:border-b-(--color-error-active)! group-data-[invalid=true]/field:border-b-input-invalid! group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:focus:border-b-(--color-error-active)! group-data-[invalid=true]/field:focus-visible:border-b-(--color-error-active)! user-invalid:focus-visible:outline-(--color-error-active) aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active) disabled:border-b-input-disabled'\n\n// inside an inset Field the shell draws the outline (field.tsx)\nexport const INSET_UNDERLINE = cn(\n GHOST_UNDERLINE,\n 'focus-visible:outline-hidden',\n)\n\nconst SOFT_BASE =\n 'user-invalid:bg-base-error-soft user-invalid:text-error user-invalid:not-disabled:hover:bg-red-a4 user-invalid:focus-visible:outline-(--color-error-active) disabled:bg-base-gray-soft disabled:opacity-50 aria-invalid:bg-base-error-soft aria-invalid:text-error aria-invalid:not-disabled:hover:bg-red-a4 aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:bg-base-error-soft group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:not-disabled:hover:bg-red-a4 group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active)'\n\nconst BORDERED =\n 'border user-invalid:border-input-invalid user-invalid:text-error user-invalid:focus-visible:border-input-invalid! user-invalid:focus-visible:outline-(--color-error-active) disabled:border-input-disabled disabled:opacity-50 aria-invalid:border-input-invalid aria-invalid:text-error aria-invalid:focus-visible:border-input-invalid! aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:border-input-invalid group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:focus-visible:border-input-invalid! group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active)'\nexport const boxChrome: Record<\n SparkInputStyle,\n Record<SparkInputColor, string>\n> = {\n soft: {\n brand: cn(\n SOFT_BASE,\n 'bg-input-base not-disabled:hover:bg-input-base-hover',\n ),\n gray: cn(SOFT_BASE, 'bg-base-gray-soft not-disabled:hover:bg-gray-a4'),\n },\n surface: {\n brand: cn(\n BORDERED,\n 'border-input bg-base-accent-surface focus-visible:border-input-active',\n ),\n gray: cn(\n BORDERED,\n 'border-input-gray bg-base-gray-surface focus-visible:border-gray-a8',\n ),\n },\n outlined: {\n brand: cn(BORDERED, 'border-input focus-visible:border-input-active'),\n gray: cn(BORDERED, 'border-input-gray focus-visible:border-gray-a8'),\n },\n ghost: {\n brand: cn(GHOST_UNDERLINE, 'border-b-input'),\n gray: cn(GHOST_UNDERLINE, 'border-b-input-gray'),\n },\n}\n"],"mappings":";;;;AAGA,MAAa,kBACX;AAGF,MAAa,mBAAA,GAAA,GAAA,IACX,iBACA,8BACF;AAEA,MAAM,YACJ;AAEF,MAAM,WACJ;AACF,MAAa,YAGT;CACF,MAAM;EACJ,QAAA,GAAA,GAAA,IACE,WACA,sDACF;EACA,OAAA,GAAA,GAAA,IAAS,WAAW,iDAAiD;CACvE;CACA,SAAS;EACP,QAAA,GAAA,GAAA,IACE,UACA,uEACF;EACA,OAAA,GAAA,GAAA,IACE,UACA,qEACF;CACF;CACA,UAAU;EACR,QAAA,GAAA,GAAA,IAAU,UAAU,gDAAgD;EACpE,OAAA,GAAA,GAAA,IAAS,UAAU,gDAAgD;CACrE;CACA,OAAO;EACL,QAAA,GAAA,GAAA,IAAU,iBAAiB,gBAAgB;EAC3C,OAAA,GAAA,GAAA,IAAS,iBAAiB,qBAAqB;CACjD;AACF"}
|
|
1
|
+
{"version":3,"file":"input-box-variants.cjs","names":[],"sources":["../../src/lib/input-box-variants.ts"],"sourcesContent":["import { cn } from '../utils/cn'\nimport type { SparkInputColor, SparkInputStyle } from './theme-types'\n\nexport const GHOST_UNDERLINE =\n 'h-10 rounded-none border-0 border-b-2 px-0 py-2 text-base focus:border-b-input-active focus-visible:border-b-input-active user-valid:border-b-input-active user-invalid:border-b-input-invalid user-invalid:text-error user-invalid:focus:border-b-(--color-error-active)! user-invalid:focus-visible:border-b-(--color-error-active)! aria-invalid:border-b-input-invalid aria-invalid:text-error aria-invalid:focus:border-b-(--color-error-active)! aria-invalid:focus-visible:border-b-(--color-error-active)! group-data-[invalid=true]/field:border-b-input-invalid! group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:focus:border-b-(--color-error-active)! group-data-[invalid=true]/field:focus-visible:border-b-(--color-error-active)! user-invalid:focus-visible:outline-(--color-error-active) aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active) disabled:border-b-input-disabled'\n\n// inside an inset Field the shell draws the outline (field.tsx)\nexport const INSET_UNDERLINE = cn(\n GHOST_UNDERLINE,\n 'focus-visible:outline-hidden',\n)\n\nconst SOFT_BASE =\n 'user-invalid:bg-base-error-soft user-invalid:text-error user-invalid:not-disabled:hover:bg-red-a4 user-invalid:focus-visible:outline-(--color-error-active) disabled:bg-base-gray-soft disabled:opacity-50 aria-invalid:bg-base-error-soft aria-invalid:text-error aria-invalid:not-disabled:hover:bg-red-a4 aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:bg-base-error-soft group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:not-disabled:hover:bg-red-a4 group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active)'\n\nconst BORDERED =\n 'border user-invalid:border-input-invalid user-invalid:text-error user-invalid:focus-visible:border-input-invalid! user-invalid:focus-visible:outline-(--color-error-active) disabled:border-input-disabled disabled:opacity-50 aria-invalid:border-input-invalid aria-invalid:text-error aria-invalid:focus-visible:border-input-invalid! aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:border-input-invalid group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:focus-visible:border-input-invalid! group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active)'\nexport const boxChrome: Record<\n SparkInputStyle,\n Record<SparkInputColor, string>\n> = {\n soft: {\n brand: cn(\n SOFT_BASE,\n 'bg-input-base not-disabled:hover:bg-input-base-hover',\n ),\n gray: cn(SOFT_BASE, 'bg-base-gray-soft not-disabled:hover:bg-gray-a4'),\n },\n surface: {\n brand: cn(\n BORDERED,\n 'border-input bg-base-accent-surface focus-visible:border-input-active',\n ),\n gray: cn(\n BORDERED,\n 'border-input-gray bg-base-gray-surface focus-visible:border-gray-a8',\n ),\n },\n outlined: {\n brand: cn(BORDERED, 'border-input focus-visible:border-input-active'),\n gray: cn(BORDERED, 'border-input-gray focus-visible:border-gray-a8'),\n },\n ghost: {\n brand: cn(GHOST_UNDERLINE, 'border-b-input'),\n gray: cn(GHOST_UNDERLINE, 'border-b-input-gray'),\n },\n}\n\nexport const FLOATING_PLACEHOLDER = ' '\n\nexport const FLOATING_SURFACE_FOCUS = 'focus-visible:outline-offset-[-2px]!'\n\nexport const FLOATING_ADORNMENT_SHIFT =\n 'transition-[translate] duration-200 ease-[cubic-bezier(0,0,0.2,1)] field-floated:translate-y-2 motion-reduce:transition-none'\n\nexport function floatingChrome(inputStyle: SparkInputStyle) {\n if (inputStyle === 'outlined')\n return 'h-12 border-0! px-3 py-0 focus-visible:outline-hidden!'\n return cn(\n 'h-12 pt-5 pb-1',\n inputStyle === 'surface' && FLOATING_SURFACE_FOCUS,\n )\n}\n"],"mappings":";;;;AAGA,MAAa,kBACX;AAGF,MAAa,mBAAA,GAAA,GAAA,IACX,iBACA,8BACF;AAEA,MAAM,YACJ;AAEF,MAAM,WACJ;AACF,MAAa,YAGT;CACF,MAAM;EACJ,QAAA,GAAA,GAAA,IACE,WACA,sDACF;EACA,OAAA,GAAA,GAAA,IAAS,WAAW,iDAAiD;CACvE;CACA,SAAS;EACP,QAAA,GAAA,GAAA,IACE,UACA,uEACF;EACA,OAAA,GAAA,GAAA,IACE,UACA,qEACF;CACF;CACA,UAAU;EACR,QAAA,GAAA,GAAA,IAAU,UAAU,gDAAgD;EACpE,OAAA,GAAA,GAAA,IAAS,UAAU,gDAAgD;CACrE;CACA,OAAO;EACL,QAAA,GAAA,GAAA,IAAU,iBAAiB,gBAAgB;EAC3C,OAAA,GAAA,GAAA,IAAS,iBAAiB,qBAAqB;CACjD;AACF;AAEA,MAAa,uBAAuB;AAEpC,MAAa,yBAAyB;AAEtC,MAAa,2BACX;AAEF,SAAgB,eAAe,YAA6B;CAC1D,IAAI,eAAe,YACjB,OAAO;CACT,QAAA,GAAA,GAAA,IACE,kBACA,eAAe,aAAA,sCACjB;AACF"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { d as SparkInputStyle, u as SparkInputColor } from "../theme-types-
|
|
3
|
+
import { d as SparkInputStyle, u as SparkInputColor } from "../theme-types-CHl-L2F-.cjs";
|
|
4
4
|
|
|
5
5
|
//#region src/lib/input-box-variants.d.ts
|
|
6
6
|
declare const GHOST_UNDERLINE = "h-10 rounded-none border-0 border-b-2 px-0 py-2 text-base focus:border-b-input-active focus-visible:border-b-input-active user-valid:border-b-input-active user-invalid:border-b-input-invalid user-invalid:text-error user-invalid:focus:border-b-(--color-error-active)! user-invalid:focus-visible:border-b-(--color-error-active)! aria-invalid:border-b-input-invalid aria-invalid:text-error aria-invalid:focus:border-b-(--color-error-active)! aria-invalid:focus-visible:border-b-(--color-error-active)! group-data-[invalid=true]/field:border-b-input-invalid! group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:focus:border-b-(--color-error-active)! group-data-[invalid=true]/field:focus-visible:border-b-(--color-error-active)! user-invalid:focus-visible:outline-(--color-error-active) aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active) disabled:border-b-input-disabled";
|
|
7
7
|
declare const INSET_UNDERLINE: string;
|
|
8
8
|
declare const boxChrome: Record<SparkInputStyle, Record<SparkInputColor, string>>;
|
|
9
|
+
declare const FLOATING_PLACEHOLDER = " ";
|
|
10
|
+
declare const FLOATING_SURFACE_FOCUS = "focus-visible:outline-offset-[-2px]!";
|
|
11
|
+
declare const FLOATING_ADORNMENT_SHIFT = "transition-[translate] duration-200 ease-[cubic-bezier(0,0,0.2,1)] field-floated:translate-y-2 motion-reduce:transition-none";
|
|
12
|
+
declare function floatingChrome(inputStyle: SparkInputStyle): string;
|
|
9
13
|
//#endregion
|
|
10
|
-
export { GHOST_UNDERLINE, INSET_UNDERLINE, boxChrome };
|
|
14
|
+
export { FLOATING_ADORNMENT_SHIFT, FLOATING_PLACEHOLDER, FLOATING_SURFACE_FOCUS, GHOST_UNDERLINE, INSET_UNDERLINE, boxChrome, floatingChrome };
|
|
11
15
|
//# sourceMappingURL=input-box-variants.d.cts.map
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { d as SparkInputStyle, u as SparkInputColor } from "../theme-types-
|
|
3
|
+
import { d as SparkInputStyle, u as SparkInputColor } from "../theme-types-CHl-L2F-.js";
|
|
4
4
|
|
|
5
5
|
//#region src/lib/input-box-variants.d.ts
|
|
6
6
|
declare const GHOST_UNDERLINE = "h-10 rounded-none border-0 border-b-2 px-0 py-2 text-base focus:border-b-input-active focus-visible:border-b-input-active user-valid:border-b-input-active user-invalid:border-b-input-invalid user-invalid:text-error user-invalid:focus:border-b-(--color-error-active)! user-invalid:focus-visible:border-b-(--color-error-active)! aria-invalid:border-b-input-invalid aria-invalid:text-error aria-invalid:focus:border-b-(--color-error-active)! aria-invalid:focus-visible:border-b-(--color-error-active)! group-data-[invalid=true]/field:border-b-input-invalid! group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:focus:border-b-(--color-error-active)! group-data-[invalid=true]/field:focus-visible:border-b-(--color-error-active)! user-invalid:focus-visible:outline-(--color-error-active) aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active) disabled:border-b-input-disabled";
|
|
7
7
|
declare const INSET_UNDERLINE: string;
|
|
8
8
|
declare const boxChrome: Record<SparkInputStyle, Record<SparkInputColor, string>>;
|
|
9
|
+
declare const FLOATING_PLACEHOLDER = " ";
|
|
10
|
+
declare const FLOATING_SURFACE_FOCUS = "focus-visible:outline-offset-[-2px]!";
|
|
11
|
+
declare const FLOATING_ADORNMENT_SHIFT = "transition-[translate] duration-200 ease-[cubic-bezier(0,0,0.2,1)] field-floated:translate-y-2 motion-reduce:transition-none";
|
|
12
|
+
declare function floatingChrome(inputStyle: SparkInputStyle): string;
|
|
9
13
|
//#endregion
|
|
10
|
-
export { GHOST_UNDERLINE, INSET_UNDERLINE, boxChrome };
|
|
14
|
+
export { FLOATING_ADORNMENT_SHIFT, FLOATING_PLACEHOLDER, FLOATING_SURFACE_FOCUS, GHOST_UNDERLINE, INSET_UNDERLINE, boxChrome, floatingChrome };
|
|
11
15
|
//# sourceMappingURL=input-box-variants.d.ts.map
|
|
@@ -23,7 +23,14 @@ const boxChrome = {
|
|
|
23
23
|
gray: cn(GHOST_UNDERLINE, "border-b-input-gray")
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
+
const FLOATING_PLACEHOLDER = " ";
|
|
27
|
+
const FLOATING_SURFACE_FOCUS = "focus-visible:outline-offset-[-2px]!";
|
|
28
|
+
const FLOATING_ADORNMENT_SHIFT = "transition-[translate] duration-200 ease-[cubic-bezier(0,0,0.2,1)] field-floated:translate-y-2 motion-reduce:transition-none";
|
|
29
|
+
function floatingChrome(inputStyle) {
|
|
30
|
+
if (inputStyle === "outlined") return "h-12 border-0! px-3 py-0 focus-visible:outline-hidden!";
|
|
31
|
+
return cn("h-12 pt-5 pb-1", inputStyle === "surface" && "focus-visible:outline-offset-[-2px]!");
|
|
32
|
+
}
|
|
26
33
|
//#endregion
|
|
27
|
-
export { GHOST_UNDERLINE, INSET_UNDERLINE, boxChrome };
|
|
34
|
+
export { FLOATING_ADORNMENT_SHIFT, FLOATING_PLACEHOLDER, FLOATING_SURFACE_FOCUS, GHOST_UNDERLINE, INSET_UNDERLINE, boxChrome, floatingChrome };
|
|
28
35
|
|
|
29
36
|
//# sourceMappingURL=input-box-variants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-box-variants.js","names":[],"sources":["../../src/lib/input-box-variants.ts"],"sourcesContent":["import { cn } from '../utils/cn'\nimport type { SparkInputColor, SparkInputStyle } from './theme-types'\n\nexport const GHOST_UNDERLINE =\n 'h-10 rounded-none border-0 border-b-2 px-0 py-2 text-base focus:border-b-input-active focus-visible:border-b-input-active user-valid:border-b-input-active user-invalid:border-b-input-invalid user-invalid:text-error user-invalid:focus:border-b-(--color-error-active)! user-invalid:focus-visible:border-b-(--color-error-active)! aria-invalid:border-b-input-invalid aria-invalid:text-error aria-invalid:focus:border-b-(--color-error-active)! aria-invalid:focus-visible:border-b-(--color-error-active)! group-data-[invalid=true]/field:border-b-input-invalid! group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:focus:border-b-(--color-error-active)! group-data-[invalid=true]/field:focus-visible:border-b-(--color-error-active)! user-invalid:focus-visible:outline-(--color-error-active) aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active) disabled:border-b-input-disabled'\n\n// inside an inset Field the shell draws the outline (field.tsx)\nexport const INSET_UNDERLINE = cn(\n GHOST_UNDERLINE,\n 'focus-visible:outline-hidden',\n)\n\nconst SOFT_BASE =\n 'user-invalid:bg-base-error-soft user-invalid:text-error user-invalid:not-disabled:hover:bg-red-a4 user-invalid:focus-visible:outline-(--color-error-active) disabled:bg-base-gray-soft disabled:opacity-50 aria-invalid:bg-base-error-soft aria-invalid:text-error aria-invalid:not-disabled:hover:bg-red-a4 aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:bg-base-error-soft group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:not-disabled:hover:bg-red-a4 group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active)'\n\nconst BORDERED =\n 'border user-invalid:border-input-invalid user-invalid:text-error user-invalid:focus-visible:border-input-invalid! user-invalid:focus-visible:outline-(--color-error-active) disabled:border-input-disabled disabled:opacity-50 aria-invalid:border-input-invalid aria-invalid:text-error aria-invalid:focus-visible:border-input-invalid! aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:border-input-invalid group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:focus-visible:border-input-invalid! group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active)'\nexport const boxChrome: Record<\n SparkInputStyle,\n Record<SparkInputColor, string>\n> = {\n soft: {\n brand: cn(\n SOFT_BASE,\n 'bg-input-base not-disabled:hover:bg-input-base-hover',\n ),\n gray: cn(SOFT_BASE, 'bg-base-gray-soft not-disabled:hover:bg-gray-a4'),\n },\n surface: {\n brand: cn(\n BORDERED,\n 'border-input bg-base-accent-surface focus-visible:border-input-active',\n ),\n gray: cn(\n BORDERED,\n 'border-input-gray bg-base-gray-surface focus-visible:border-gray-a8',\n ),\n },\n outlined: {\n brand: cn(BORDERED, 'border-input focus-visible:border-input-active'),\n gray: cn(BORDERED, 'border-input-gray focus-visible:border-gray-a8'),\n },\n ghost: {\n brand: cn(GHOST_UNDERLINE, 'border-b-input'),\n gray: cn(GHOST_UNDERLINE, 'border-b-input-gray'),\n },\n}\n"],"mappings":";;;AAGA,MAAa,kBACX;AAGF,MAAa,kBAAkB,GAC7B,iBACA,8BACF;AAEA,MAAM,YACJ;AAEF,MAAM,WACJ;AACF,MAAa,YAGT;CACF,MAAM;EACJ,OAAO,GACL,WACA,sDACF;EACA,MAAM,GAAG,WAAW,iDAAiD;CACvE;CACA,SAAS;EACP,OAAO,GACL,UACA,uEACF;EACA,MAAM,GACJ,UACA,qEACF;CACF;CACA,UAAU;EACR,OAAO,GAAG,UAAU,gDAAgD;EACpE,MAAM,GAAG,UAAU,gDAAgD;CACrE;CACA,OAAO;EACL,OAAO,GAAG,iBAAiB,gBAAgB;EAC3C,MAAM,GAAG,iBAAiB,qBAAqB;CACjD;AACF"}
|
|
1
|
+
{"version":3,"file":"input-box-variants.js","names":[],"sources":["../../src/lib/input-box-variants.ts"],"sourcesContent":["import { cn } from '../utils/cn'\nimport type { SparkInputColor, SparkInputStyle } from './theme-types'\n\nexport const GHOST_UNDERLINE =\n 'h-10 rounded-none border-0 border-b-2 px-0 py-2 text-base focus:border-b-input-active focus-visible:border-b-input-active user-valid:border-b-input-active user-invalid:border-b-input-invalid user-invalid:text-error user-invalid:focus:border-b-(--color-error-active)! user-invalid:focus-visible:border-b-(--color-error-active)! aria-invalid:border-b-input-invalid aria-invalid:text-error aria-invalid:focus:border-b-(--color-error-active)! aria-invalid:focus-visible:border-b-(--color-error-active)! group-data-[invalid=true]/field:border-b-input-invalid! group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:focus:border-b-(--color-error-active)! group-data-[invalid=true]/field:focus-visible:border-b-(--color-error-active)! user-invalid:focus-visible:outline-(--color-error-active) aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active) disabled:border-b-input-disabled'\n\n// inside an inset Field the shell draws the outline (field.tsx)\nexport const INSET_UNDERLINE = cn(\n GHOST_UNDERLINE,\n 'focus-visible:outline-hidden',\n)\n\nconst SOFT_BASE =\n 'user-invalid:bg-base-error-soft user-invalid:text-error user-invalid:not-disabled:hover:bg-red-a4 user-invalid:focus-visible:outline-(--color-error-active) disabled:bg-base-gray-soft disabled:opacity-50 aria-invalid:bg-base-error-soft aria-invalid:text-error aria-invalid:not-disabled:hover:bg-red-a4 aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:bg-base-error-soft group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:not-disabled:hover:bg-red-a4 group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active)'\n\nconst BORDERED =\n 'border user-invalid:border-input-invalid user-invalid:text-error user-invalid:focus-visible:border-input-invalid! user-invalid:focus-visible:outline-(--color-error-active) disabled:border-input-disabled disabled:opacity-50 aria-invalid:border-input-invalid aria-invalid:text-error aria-invalid:focus-visible:border-input-invalid! aria-invalid:focus-visible:outline-(--color-error-active) group-data-[invalid=true]/field:border-input-invalid group-data-[invalid=true]/field:text-error group-data-[invalid=true]/field:focus-visible:border-input-invalid! group-data-[invalid=true]/field:focus-visible:outline-(--color-error-active)'\nexport const boxChrome: Record<\n SparkInputStyle,\n Record<SparkInputColor, string>\n> = {\n soft: {\n brand: cn(\n SOFT_BASE,\n 'bg-input-base not-disabled:hover:bg-input-base-hover',\n ),\n gray: cn(SOFT_BASE, 'bg-base-gray-soft not-disabled:hover:bg-gray-a4'),\n },\n surface: {\n brand: cn(\n BORDERED,\n 'border-input bg-base-accent-surface focus-visible:border-input-active',\n ),\n gray: cn(\n BORDERED,\n 'border-input-gray bg-base-gray-surface focus-visible:border-gray-a8',\n ),\n },\n outlined: {\n brand: cn(BORDERED, 'border-input focus-visible:border-input-active'),\n gray: cn(BORDERED, 'border-input-gray focus-visible:border-gray-a8'),\n },\n ghost: {\n brand: cn(GHOST_UNDERLINE, 'border-b-input'),\n gray: cn(GHOST_UNDERLINE, 'border-b-input-gray'),\n },\n}\n\nexport const FLOATING_PLACEHOLDER = ' '\n\nexport const FLOATING_SURFACE_FOCUS = 'focus-visible:outline-offset-[-2px]!'\n\nexport const FLOATING_ADORNMENT_SHIFT =\n 'transition-[translate] duration-200 ease-[cubic-bezier(0,0,0.2,1)] field-floated:translate-y-2 motion-reduce:transition-none'\n\nexport function floatingChrome(inputStyle: SparkInputStyle) {\n if (inputStyle === 'outlined')\n return 'h-12 border-0! px-3 py-0 focus-visible:outline-hidden!'\n return cn(\n 'h-12 pt-5 pb-1',\n inputStyle === 'surface' && FLOATING_SURFACE_FOCUS,\n )\n}\n"],"mappings":";;;AAGA,MAAa,kBACX;AAGF,MAAa,kBAAkB,GAC7B,iBACA,8BACF;AAEA,MAAM,YACJ;AAEF,MAAM,WACJ;AACF,MAAa,YAGT;CACF,MAAM;EACJ,OAAO,GACL,WACA,sDACF;EACA,MAAM,GAAG,WAAW,iDAAiD;CACvE;CACA,SAAS;EACP,OAAO,GACL,UACA,uEACF;EACA,MAAM,GACJ,UACA,qEACF;CACF;CACA,UAAU;EACR,OAAO,GAAG,UAAU,gDAAgD;EACpE,MAAM,GAAG,UAAU,gDAAgD;CACrE;CACA,OAAO;EACL,OAAO,GAAG,iBAAiB,gBAAgB;EAC3C,MAAM,GAAG,iBAAiB,qBAAqB;CACjD;AACF;AAEA,MAAa,uBAAuB;AAEpC,MAAa,yBAAyB;AAEtC,MAAa,2BACX;AAEF,SAAgB,eAAe,YAA6B;CAC1D,IAAI,eAAe,YACjB,OAAO;CACT,OAAO,GACL,kBACA,eAAe,aAAA,sCACjB;AACF"}
|