@boichikpro/vue3-date-time-picker
Version:
Date & time picker for vue3
1,692 lines • 285 kB
JavaScript
import { isRef as $s, ref as V, watch as K, onMounted as $e, onUnmounted as En, readonly as Ws, defineComponent as Q, toRef as an, h as Us, onBeforeUnmount as Vt, withDirectives as Oe, createElementBlock as R, openBlock as F, vModelText as Xs, createElementVNode as H, inject as J, computed as T, normalizeClass as We, createVNode as z, createCommentVNode as oe, Fragment as ge, renderSlot as Ve, createBlock as se, unref as ue, withCtx as we, createTextVNode as xa, toDisplayString as Me, resolveDynamicComponent as Bt, renderList as qe, vShow as Ye, mergeModels as $r, useModel as gt, mergeProps as In, toHandlers as Rn, useId as js, nextTick as zs, Teleport as qs, normalizeStyle as Wr, useTemplateRef as Ur, reactive as Gs, provide as Fe, useSlots as Xr } from "vue";
import { parse as Xn, isValid as Aa, getDaysInMonth as sa, startOfWeek as Zs, addDays as pn, startOfMonth as Ks, endOfMonth as Qs, getDay as Js, subDays as ei, eachDayOfInterval as ti, isSameDay as Xt, set as ni, addMonths as Mn, isSameMonth as jn, setYear as jr, setMonth as ai, isSameYear as zn, addYears as ia, subMonths as la, subYears as oa, format as vn, isBefore as je, isAfter as ua, getDefaultOptions as ri, parseISO as Ea, isDate as Tt, isEqual as si, setHours as kt, setMinutes as Ln, setSeconds as Ma } from "date-fns";
import { useI18n as ii } from "vue-i18n";
/* empty css */
const li = {
lessThanXSeconds: {
one: "less than a second",
other: "less than {{count}} seconds"
},
xSeconds: {
one: "1 second",
other: "{{count}} seconds"
},
halfAMinute: "half a minute",
lessThanXMinutes: {
one: "less than a minute",
other: "less than {{count}} minutes"
},
xMinutes: {
one: "1 minute",
other: "{{count}} minutes"
},
aboutXHours: {
one: "about 1 hour",
other: "about {{count}} hours"
},
xHours: {
one: "1 hour",
other: "{{count}} hours"
},
xDays: {
one: "1 day",
other: "{{count}} days"
},
aboutXWeeks: {
one: "about 1 week",
other: "about {{count}} weeks"
},
xWeeks: {
one: "1 week",
other: "{{count}} weeks"
},
aboutXMonths: {
one: "about 1 month",
other: "about {{count}} months"
},
xMonths: {
one: "1 month",
other: "{{count}} months"
},
aboutXYears: {
one: "about 1 year",
other: "about {{count}} years"
},
xYears: {
one: "1 year",
other: "{{count}} years"
},
overXYears: {
one: "over 1 year",
other: "over {{count}} years"
},
almostXYears: {
one: "almost 1 year",
other: "almost {{count}} years"
}
}, oi = (n, e, t) => {
let a;
const r = li[n];
return typeof r == "string" ? a = r : e === 1 ? a = r.one : a = r.other.replace("{{count}}", e.toString()), t != null && t.addSuffix ? t.comparison && t.comparison > 0 ? "in " + a : a + " ago" : a;
};
function Yn(n) {
return (e = {}) => {
const t = e.width ? String(e.width) : n.defaultWidth;
return n.formats[t] || n.formats[n.defaultWidth];
};
}
const ui = {
full: "EEEE, MMMM do, y",
long: "MMMM do, y",
medium: "MMM d, y",
short: "MM/dd/yyyy"
}, ci = {
full: "h:mm:ss a zzzz",
long: "h:mm:ss a z",
medium: "h:mm:ss a",
short: "h:mm a"
}, di = {
full: "{{date}} 'at' {{time}}",
long: "{{date}} 'at' {{time}}",
medium: "{{date}}, {{time}}",
short: "{{date}}, {{time}}"
}, hi = {
date: Yn({
formats: ui,
defaultWidth: "full"
}),
time: Yn({
formats: ci,
defaultWidth: "full"
}),
dateTime: Yn({
formats: di,
defaultWidth: "full"
})
}, fi = {
lastWeek: "'last' eeee 'at' p",
yesterday: "'yesterday at' p",
today: "'today at' p",
tomorrow: "'tomorrow at' p",
nextWeek: "eeee 'at' p",
other: "P"
}, pi = (n, e, t, a) => fi[n];
function $t(n) {
return (e, t) => {
const a = t != null && t.context ? String(t.context) : "standalone";
let r;
if (a === "formatting" && n.formattingValues) {
const i = n.defaultFormattingWidth || n.defaultWidth, l = t != null && t.width ? String(t.width) : i;
r = n.formattingValues[l] || n.formattingValues[i];
} else {
const i = n.defaultWidth, l = t != null && t.width ? String(t.width) : n.defaultWidth;
r = n.values[l] || n.values[i];
}
const s = n.argumentCallback ? n.argumentCallback(e) : e;
return r[s];
};
}
const vi = {
narrow: ["B", "A"],
abbreviated: ["BC", "AD"],
wide: ["Before Christ", "Anno Domini"]
}, mi = {
narrow: ["1", "2", "3", "4"],
abbreviated: ["Q1", "Q2", "Q3", "Q4"],
wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"]
}, gi = {
narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
abbreviated: [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
],
wide: [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
}, yi = {
narrow: ["S", "M", "T", "W", "T", "F", "S"],
short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
wide: [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
]
}, bi = {
narrow: {
am: "a",
pm: "p",
midnight: "mi",
noon: "n",
morning: "morning",
afternoon: "afternoon",
evening: "evening",
night: "night"
},
abbreviated: {
am: "AM",
pm: "PM",
midnight: "midnight",
noon: "noon",
morning: "morning",
afternoon: "afternoon",
evening: "evening",
night: "night"
},
wide: {
am: "a.m.",
pm: "p.m.",
midnight: "midnight",
noon: "noon",
morning: "morning",
afternoon: "afternoon",
evening: "evening",
night: "night"
}
}, _i = {
narrow: {
am: "a",
pm: "p",
midnight: "mi",
noon: "n",
morning: "in the morning",
afternoon: "in the afternoon",
evening: "in the evening",
night: "at night"
},
abbreviated: {
am: "AM",
pm: "PM",
midnight: "midnight",
noon: "noon",
morning: "in the morning",
afternoon: "in the afternoon",
evening: "in the evening",
night: "at night"
},
wide: {
am: "a.m.",
pm: "p.m.",
midnight: "midnight",
noon: "noon",
morning: "in the morning",
afternoon: "in the afternoon",
evening: "in the evening",
night: "at night"
}
}, ki = (n, e) => {
const t = Number(n), a = t % 100;
if (a > 20 || a < 10)
switch (a % 10) {
case 1:
return t + "st";
case 2:
return t + "nd";
case 3:
return t + "rd";
}
return t + "th";
}, wi = {
ordinalNumber: ki,
era: $t({
values: vi,
defaultWidth: "wide"
}),
quarter: $t({
values: mi,
defaultWidth: "wide",
argumentCallback: (n) => n - 1
}),
month: $t({
values: gi,
defaultWidth: "wide"
}),
day: $t({
values: yi,
defaultWidth: "wide"
}),
dayPeriod: $t({
values: bi,
defaultWidth: "wide",
formattingValues: _i,
defaultFormattingWidth: "wide"
})
};
function Wt(n) {
return (e, t = {}) => {
const a = t.width, r = a && n.matchPatterns[a] || n.matchPatterns[n.defaultMatchWidth], s = e.match(r);
if (!s)
return null;
const i = s[0], l = a && n.parsePatterns[a] || n.parsePatterns[n.defaultParseWidth], o = Array.isArray(l) ? Ai(l, (d) => d.test(i)) : (
// [TODO] -- I challenge you to fix the type
xi(l, (d) => d.test(i))
);
let c;
c = n.valueCallback ? n.valueCallback(o) : o, c = t.valueCallback ? (
// [TODO] -- I challenge you to fix the type
t.valueCallback(c)
) : c;
const u = e.slice(i.length);
return { value: c, rest: u };
};
}
function xi(n, e) {
for (const t in n)
if (Object.prototype.hasOwnProperty.call(n, t) && e(n[t]))
return t;
}
function Ai(n, e) {
for (let t = 0; t < n.length; t++)
if (e(n[t]))
return t;
}
function Ei(n) {
return (e, t = {}) => {
const a = e.match(n.matchPattern);
if (!a) return null;
const r = a[0], s = e.match(n.parsePattern);
if (!s) return null;
let i = n.valueCallback ? n.valueCallback(s[0]) : s[0];
i = t.valueCallback ? t.valueCallback(i) : i;
const l = e.slice(r.length);
return { value: i, rest: l };
};
}
const Mi = /^(\d+)(th|st|nd|rd)?/i, Ti = /\d+/i, Di = {
narrow: /^(b|a)/i,
abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
wide: /^(before christ|before common era|anno domini|common era)/i
}, Si = {
any: [/^b/i, /^(a|c)/i]
}, Fi = {
narrow: /^[1234]/i,
abbreviated: /^q[1234]/i,
wide: /^[1234](th|st|nd|rd)? quarter/i
}, Ci = {
any: [/1/i, /2/i, /3/i, /4/i]
}, Oi = {
narrow: /^[jfmasond]/i,
abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
}, Vi = {
narrow: [
/^j/i,
/^f/i,
/^m/i,
/^a/i,
/^m/i,
/^j/i,
/^j/i,
/^a/i,
/^s/i,
/^o/i,
/^n/i,
/^d/i
],
any: [
/^ja/i,
/^f/i,
/^mar/i,
/^ap/i,
/^may/i,
/^jun/i,
/^jul/i,
/^au/i,
/^s/i,
/^o/i,
/^n/i,
/^d/i
]
}, Bi = {
narrow: /^[smtwf]/i,
short: /^(su|mo|tu|we|th|fr|sa)/i,
abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
}, Ii = {
narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
}, Ri = {
narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
}, Li = {
any: {
am: /^a/i,
pm: /^p/i,
midnight: /^mi/i,
noon: /^no/i,
morning: /morning/i,
afternoon: /afternoon/i,
evening: /evening/i,
night: /night/i
}
}, Yi = {
ordinalNumber: Ei({
matchPattern: Mi,
parsePattern: Ti,
valueCallback: (n) => parseInt(n, 10)
}),
era: Wt({
matchPatterns: Di,
defaultMatchWidth: "wide",
parsePatterns: Si,
defaultParseWidth: "any"
}),
quarter: Wt({
matchPatterns: Fi,
defaultMatchWidth: "wide",
parsePatterns: Ci,
defaultParseWidth: "any",
valueCallback: (n) => n + 1
}),
month: Wt({
matchPatterns: Oi,
defaultMatchWidth: "wide",
parsePatterns: Vi,
defaultParseWidth: "any"
}),
day: Wt({
matchPatterns: Bi,
defaultMatchWidth: "wide",
parsePatterns: Ii,
defaultParseWidth: "any"
}),
dayPeriod: Wt({
matchPatterns: Ri,
defaultMatchWidth: "any",
parsePatterns: Li,
defaultParseWidth: "any"
})
}, Ni = {
code: "en-US",
formatDistance: oi,
formatLong: hi,
formatRelative: pi,
localize: wi,
match: Yi,
options: {
weekStartsOn: 0,
firstWeekContainsDate: 1
}
};
let Pi = {};
function Tn() {
return Pi;
}
const zr = 6048e5, Hi = 864e5, Ta = Symbol.for("constructDateFrom");
function it(n, e) {
return typeof n == "function" ? n(e) : n && typeof n == "object" && Ta in n ? n[Ta](e) : n instanceof Date ? new n.constructor(e) : new Date(e);
}
function Be(n, e) {
return it(e || n, n);
}
function Da(n) {
const e = Be(n), t = new Date(
Date.UTC(
e.getFullYear(),
e.getMonth(),
e.getDate(),
e.getHours(),
e.getMinutes(),
e.getSeconds(),
e.getMilliseconds()
)
);
return t.setUTCFullYear(e.getFullYear()), +n - +t;
}
function $i(n, ...e) {
const t = it.bind(
null,
e.find((a) => typeof a == "object")
);
return e.map(t);
}
function Sa(n, e) {
const t = Be(n, e == null ? void 0 : e.in);
return t.setHours(0, 0, 0, 0), t;
}
function Wi(n, e, t) {
const [a, r] = $i(
t == null ? void 0 : t.in,
n,
e
), s = Sa(a), i = Sa(r), l = +s - Da(s), o = +i - Da(i);
return Math.round((l - o) / Hi);
}
function Ui(n, e) {
const t = Be(n, e == null ? void 0 : e.in);
return t.setFullYear(t.getFullYear(), 0, 1), t.setHours(0, 0, 0, 0), t;
}
function Xi(n, e) {
const t = Be(n, e == null ? void 0 : e.in);
return Wi(t, Ui(t)) + 1;
}
function qt(n, e) {
var l, o, c, u;
const t = Tn(), a = (e == null ? void 0 : e.weekStartsOn) ?? ((o = (l = e == null ? void 0 : e.locale) == null ? void 0 : l.options) == null ? void 0 : o.weekStartsOn) ?? t.weekStartsOn ?? ((u = (c = t.locale) == null ? void 0 : c.options) == null ? void 0 : u.weekStartsOn) ?? 0, r = Be(n, e == null ? void 0 : e.in), s = r.getDay(), i = (s < a ? 7 : 0) + s - a;
return r.setDate(r.getDate() - i), r.setHours(0, 0, 0, 0), r;
}
function mn(n, e) {
return qt(n, { ...e, weekStartsOn: 1 });
}
function qr(n, e) {
const t = Be(n, e == null ? void 0 : e.in), a = t.getFullYear(), r = it(t, 0);
r.setFullYear(a + 1, 0, 4), r.setHours(0, 0, 0, 0);
const s = mn(r), i = it(t, 0);
i.setFullYear(a, 0, 4), i.setHours(0, 0, 0, 0);
const l = mn(i);
return t.getTime() >= s.getTime() ? a + 1 : t.getTime() >= l.getTime() ? a : a - 1;
}
function ji(n, e) {
const t = qr(n, e), a = it(n, 0);
return a.setFullYear(t, 0, 4), a.setHours(0, 0, 0, 0), mn(a);
}
function zi(n, e) {
const t = Be(n, e == null ? void 0 : e.in), a = +mn(t) - +ji(t);
return Math.round(a / zr) + 1;
}
function Gr(n, e) {
var u, d, p, f;
const t = Be(n, e == null ? void 0 : e.in), a = t.getFullYear(), r = Tn(), s = (e == null ? void 0 : e.firstWeekContainsDate) ?? ((d = (u = e == null ? void 0 : e.locale) == null ? void 0 : u.options) == null ? void 0 : d.firstWeekContainsDate) ?? r.firstWeekContainsDate ?? ((f = (p = r.locale) == null ? void 0 : p.options) == null ? void 0 : f.firstWeekContainsDate) ?? 1, i = it((e == null ? void 0 : e.in) || n, 0);
i.setFullYear(a + 1, 0, s), i.setHours(0, 0, 0, 0);
const l = qt(i, e), o = it((e == null ? void 0 : e.in) || n, 0);
o.setFullYear(a, 0, s), o.setHours(0, 0, 0, 0);
const c = qt(o, e);
return +t >= +l ? a + 1 : +t >= +c ? a : a - 1;
}
function qi(n, e) {
var l, o, c, u;
const t = Tn(), a = (e == null ? void 0 : e.firstWeekContainsDate) ?? ((o = (l = e == null ? void 0 : e.locale) == null ? void 0 : l.options) == null ? void 0 : o.firstWeekContainsDate) ?? t.firstWeekContainsDate ?? ((u = (c = t.locale) == null ? void 0 : c.options) == null ? void 0 : u.firstWeekContainsDate) ?? 1, r = Gr(n, e), s = it((e == null ? void 0 : e.in) || n, 0);
return s.setFullYear(r, 0, a), s.setHours(0, 0, 0, 0), qt(s, e);
}
function Gi(n, e) {
const t = Be(n, e == null ? void 0 : e.in), a = +qt(t, e) - +qi(t, e);
return Math.round(a / zr) + 1;
}
function G(n, e) {
const t = n < 0 ? "-" : "", a = Math.abs(n).toString().padStart(e, "0");
return t + a;
}
const at = {
// Year
y(n, e) {
const t = n.getFullYear(), a = t > 0 ? t : 1 - t;
return G(e === "yy" ? a % 100 : a, e.length);
},
// Month
M(n, e) {
const t = n.getMonth();
return e === "M" ? String(t + 1) : G(t + 1, 2);
},
// Day of the month
d(n, e) {
return G(n.getDate(), e.length);
},
// AM or PM
a(n, e) {
const t = n.getHours() / 12 >= 1 ? "pm" : "am";
switch (e) {
case "a":
case "aa":
return t.toUpperCase();
case "aaa":
return t;
case "aaaaa":
return t[0];
case "aaaa":
default:
return t === "am" ? "a.m." : "p.m.";
}
},
// Hour [1-12]
h(n, e) {
return G(n.getHours() % 12 || 12, e.length);
},
// Hour [0-23]
H(n, e) {
return G(n.getHours(), e.length);
},
// Minute
m(n, e) {
return G(n.getMinutes(), e.length);
},
// Second
s(n, e) {
return G(n.getSeconds(), e.length);
},
// Fraction of second
S(n, e) {
const t = e.length, a = n.getMilliseconds(), r = Math.trunc(
a * Math.pow(10, t - 3)
);
return G(r, e.length);
}
}, wt = {
midnight: "midnight",
noon: "noon",
morning: "morning",
afternoon: "afternoon",
evening: "evening",
night: "night"
}, Fa = {
// Era
G: function(n, e, t) {
const a = n.getFullYear() > 0 ? 1 : 0;
switch (e) {
case "G":
case "GG":
case "GGG":
return t.era(a, { width: "abbreviated" });
case "GGGGG":
return t.era(a, { width: "narrow" });
case "GGGG":
default:
return t.era(a, { width: "wide" });
}
},
// Year
y: function(n, e, t) {
if (e === "yo") {
const a = n.getFullYear(), r = a > 0 ? a : 1 - a;
return t.ordinalNumber(r, { unit: "year" });
}
return at.y(n, e);
},
// Local week-numbering year
Y: function(n, e, t, a) {
const r = Gr(n, a), s = r > 0 ? r : 1 - r;
if (e === "YY") {
const i = s % 100;
return G(i, 2);
}
return e === "Yo" ? t.ordinalNumber(s, { unit: "year" }) : G(s, e.length);
},
// ISO week-numbering year
R: function(n, e) {
const t = qr(n);
return G(t, e.length);
},
// Extended year. This is a single number designating the year of this calendar system.
// The main difference between `y` and `u` localizers are B.C. years:
// | Year | `y` | `u` |
// |------|-----|-----|
// | AC 1 | 1 | 1 |
// | BC 1 | 1 | 0 |
// | BC 2 | 2 | -1 |
// Also `yy` always returns the last two digits of a year,
// while `uu` pads single digit years to 2 characters and returns other years unchanged.
u: function(n, e) {
const t = n.getFullYear();
return G(t, e.length);
},
// Quarter
Q: function(n, e, t) {
const a = Math.ceil((n.getMonth() + 1) / 3);
switch (e) {
case "Q":
return String(a);
case "QQ":
return G(a, 2);
case "Qo":
return t.ordinalNumber(a, { unit: "quarter" });
case "QQQ":
return t.quarter(a, {
width: "abbreviated",
context: "formatting"
});
case "QQQQQ":
return t.quarter(a, {
width: "narrow",
context: "formatting"
});
case "QQQQ":
default:
return t.quarter(a, {
width: "wide",
context: "formatting"
});
}
},
// Stand-alone quarter
q: function(n, e, t) {
const a = Math.ceil((n.getMonth() + 1) / 3);
switch (e) {
case "q":
return String(a);
case "qq":
return G(a, 2);
case "qo":
return t.ordinalNumber(a, { unit: "quarter" });
case "qqq":
return t.quarter(a, {
width: "abbreviated",
context: "standalone"
});
case "qqqqq":
return t.quarter(a, {
width: "narrow",
context: "standalone"
});
case "qqqq":
default:
return t.quarter(a, {
width: "wide",
context: "standalone"
});
}
},
// Month
M: function(n, e, t) {
const a = n.getMonth();
switch (e) {
case "M":
case "MM":
return at.M(n, e);
case "Mo":
return t.ordinalNumber(a + 1, { unit: "month" });
case "MMM":
return t.month(a, {
width: "abbreviated",
context: "formatting"
});
case "MMMMM":
return t.month(a, {
width: "narrow",
context: "formatting"
});
case "MMMM":
default:
return t.month(a, { width: "wide", context: "formatting" });
}
},
// Stand-alone month
L: function(n, e, t) {
const a = n.getMonth();
switch (e) {
case "L":
return String(a + 1);
case "LL":
return G(a + 1, 2);
case "Lo":
return t.ordinalNumber(a + 1, { unit: "month" });
case "LLL":
return t.month(a, {
width: "abbreviated",
context: "standalone"
});
case "LLLLL":
return t.month(a, {
width: "narrow",
context: "standalone"
});
case "LLLL":
default:
return t.month(a, { width: "wide", context: "standalone" });
}
},
// Local week of year
w: function(n, e, t, a) {
const r = Gi(n, a);
return e === "wo" ? t.ordinalNumber(r, { unit: "week" }) : G(r, e.length);
},
// ISO week of year
I: function(n, e, t) {
const a = zi(n);
return e === "Io" ? t.ordinalNumber(a, { unit: "week" }) : G(a, e.length);
},
// Day of the month
d: function(n, e, t) {
return e === "do" ? t.ordinalNumber(n.getDate(), { unit: "date" }) : at.d(n, e);
},
// Day of year
D: function(n, e, t) {
const a = Xi(n);
return e === "Do" ? t.ordinalNumber(a, { unit: "dayOfYear" }) : G(a, e.length);
},
// Day of week
E: function(n, e, t) {
const a = n.getDay();
switch (e) {
case "E":
case "EE":
case "EEE":
return t.day(a, {
width: "abbreviated",
context: "formatting"
});
case "EEEEE":
return t.day(a, {
width: "narrow",
context: "formatting"
});
case "EEEEEE":
return t.day(a, {
width: "short",
context: "formatting"
});
case "EEEE":
default:
return t.day(a, {
width: "wide",
context: "formatting"
});
}
},
// Local day of week
e: function(n, e, t, a) {
const r = n.getDay(), s = (r - a.weekStartsOn + 8) % 7 || 7;
switch (e) {
case "e":
return String(s);
case "ee":
return G(s, 2);
case "eo":
return t.ordinalNumber(s, { unit: "day" });
case "eee":
return t.day(r, {
width: "abbreviated",
context: "formatting"
});
case "eeeee":
return t.day(r, {
width: "narrow",
context: "formatting"
});
case "eeeeee":
return t.day(r, {
width: "short",
context: "formatting"
});
case "eeee":
default:
return t.day(r, {
width: "wide",
context: "formatting"
});
}
},
// Stand-alone local day of week
c: function(n, e, t, a) {
const r = n.getDay(), s = (r - a.weekStartsOn + 8) % 7 || 7;
switch (e) {
case "c":
return String(s);
case "cc":
return G(s, e.length);
case "co":
return t.ordinalNumber(s, { unit: "day" });
case "ccc":
return t.day(r, {
width: "abbreviated",
context: "standalone"
});
case "ccccc":
return t.day(r, {
width: "narrow",
context: "standalone"
});
case "cccccc":
return t.day(r, {
width: "short",
context: "standalone"
});
case "cccc":
default:
return t.day(r, {
width: "wide",
context: "standalone"
});
}
},
// ISO day of week
i: function(n, e, t) {
const a = n.getDay(), r = a === 0 ? 7 : a;
switch (e) {
case "i":
return String(r);
case "ii":
return G(r, e.length);
case "io":
return t.ordinalNumber(r, { unit: "day" });
case "iii":
return t.day(a, {
width: "abbreviated",
context: "formatting"
});
case "iiiii":
return t.day(a, {
width: "narrow",
context: "formatting"
});
case "iiiiii":
return t.day(a, {
width: "short",
context: "formatting"
});
case "iiii":
default:
return t.day(a, {
width: "wide",
context: "formatting"
});
}
},
// AM or PM
a: function(n, e, t) {
const r = n.getHours() / 12 >= 1 ? "pm" : "am";
switch (e) {
case "a":
case "aa":
return t.dayPeriod(r, {
width: "abbreviated",
context: "formatting"
});
case "aaa":
return t.dayPeriod(r, {
width: "abbreviated",
context: "formatting"
}).toLowerCase();
case "aaaaa":
return t.dayPeriod(r, {
width: "narrow",
context: "formatting"
});
case "aaaa":
default:
return t.dayPeriod(r, {
width: "wide",
context: "formatting"
});
}
},
// AM, PM, midnight, noon
b: function(n, e, t) {
const a = n.getHours();
let r;
switch (a === 12 ? r = wt.noon : a === 0 ? r = wt.midnight : r = a / 12 >= 1 ? "pm" : "am", e) {
case "b":
case "bb":
return t.dayPeriod(r, {
width: "abbreviated",
context: "formatting"
});
case "bbb":
return t.dayPeriod(r, {
width: "abbreviated",
context: "formatting"
}).toLowerCase();
case "bbbbb":
return t.dayPeriod(r, {
width: "narrow",
context: "formatting"
});
case "bbbb":
default:
return t.dayPeriod(r, {
width: "wide",
context: "formatting"
});
}
},
// in the morning, in the afternoon, in the evening, at night
B: function(n, e, t) {
const a = n.getHours();
let r;
switch (a >= 17 ? r = wt.evening : a >= 12 ? r = wt.afternoon : a >= 4 ? r = wt.morning : r = wt.night, e) {
case "B":
case "BB":
case "BBB":
return t.dayPeriod(r, {
width: "abbreviated",
context: "formatting"
});
case "BBBBB":
return t.dayPeriod(r, {
width: "narrow",
context: "formatting"
});
case "BBBB":
default:
return t.dayPeriod(r, {
width: "wide",
context: "formatting"
});
}
},
// Hour [1-12]
h: function(n, e, t) {
if (e === "ho") {
let a = n.getHours() % 12;
return a === 0 && (a = 12), t.ordinalNumber(a, { unit: "hour" });
}
return at.h(n, e);
},
// Hour [0-23]
H: function(n, e, t) {
return e === "Ho" ? t.ordinalNumber(n.getHours(), { unit: "hour" }) : at.H(n, e);
},
// Hour [0-11]
K: function(n, e, t) {
const a = n.getHours() % 12;
return e === "Ko" ? t.ordinalNumber(a, { unit: "hour" }) : G(a, e.length);
},
// Hour [1-24]
k: function(n, e, t) {
let a = n.getHours();
return a === 0 && (a = 24), e === "ko" ? t.ordinalNumber(a, { unit: "hour" }) : G(a, e.length);
},
// Minute
m: function(n, e, t) {
return e === "mo" ? t.ordinalNumber(n.getMinutes(), { unit: "minute" }) : at.m(n, e);
},
// Second
s: function(n, e, t) {
return e === "so" ? t.ordinalNumber(n.getSeconds(), { unit: "second" }) : at.s(n, e);
},
// Fraction of second
S: function(n, e) {
return at.S(n, e);
},
// Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
X: function(n, e, t) {
const a = n.getTimezoneOffset();
if (a === 0)
return "Z";
switch (e) {
case "X":
return Oa(a);
case "XXXX":
case "XX":
return dt(a);
case "XXXXX":
case "XXX":
default:
return dt(a, ":");
}
},
// Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
x: function(n, e, t) {
const a = n.getTimezoneOffset();
switch (e) {
case "x":
return Oa(a);
case "xxxx":
case "xx":
return dt(a);
case "xxxxx":
case "xxx":
default:
return dt(a, ":");
}
},
// Timezone (GMT)
O: function(n, e, t) {
const a = n.getTimezoneOffset();
switch (e) {
case "O":
case "OO":
case "OOO":
return "GMT" + Ca(a, ":");
case "OOOO":
default:
return "GMT" + dt(a, ":");
}
},
// Timezone (specific non-location)
z: function(n, e, t) {
const a = n.getTimezoneOffset();
switch (e) {
case "z":
case "zz":
case "zzz":
return "GMT" + Ca(a, ":");
case "zzzz":
default:
return "GMT" + dt(a, ":");
}
},
// Seconds timestamp
t: function(n, e, t) {
const a = Math.trunc(+n / 1e3);
return G(a, e.length);
},
// Milliseconds timestamp
T: function(n, e, t) {
return G(+n, e.length);
}
};
function Ca(n, e = "") {
const t = n > 0 ? "-" : "+", a = Math.abs(n), r = Math.trunc(a / 60), s = a % 60;
return s === 0 ? t + String(r) : t + String(r) + e + G(s, 2);
}
function Oa(n, e) {
return n % 60 === 0 ? (n > 0 ? "-" : "+") + G(Math.abs(n) / 60, 2) : dt(n, e);
}
function dt(n, e = "") {
const t = n > 0 ? "-" : "+", a = Math.abs(n), r = G(Math.trunc(a / 60), 2), s = G(a % 60, 2);
return t + r + e + s;
}
const Va = (n, e) => {
switch (n) {
case "P":
return e.date({ width: "short" });
case "PP":
return e.date({ width: "medium" });
case "PPP":
return e.date({ width: "long" });
case "PPPP":
default:
return e.date({ width: "full" });
}
}, Zr = (n, e) => {
switch (n) {
case "p":
return e.time({ width: "short" });
case "pp":
return e.time({ width: "medium" });
case "ppp":
return e.time({ width: "long" });
case "pppp":
default:
return e.time({ width: "full" });
}
}, Zi = (n, e) => {
const t = n.match(/(P+)(p+)?/) || [], a = t[1], r = t[2];
if (!r)
return Va(n, e);
let s;
switch (a) {
case "P":
s = e.dateTime({ width: "short" });
break;
case "PP":
s = e.dateTime({ width: "medium" });
break;
case "PPP":
s = e.dateTime({ width: "long" });
break;
case "PPPP":
default:
s = e.dateTime({ width: "full" });
break;
}
return s.replace("{{date}}", Va(a, e)).replace("{{time}}", Zr(r, e));
}, Ki = {
p: Zr,
P: Zi
}, Qi = /^D+$/, Ji = /^Y+$/, el = ["D", "DD", "YY", "YYYY"];
function tl(n) {
return Qi.test(n);
}
function nl(n) {
return Ji.test(n);
}
function al(n, e, t) {
const a = rl(n, e, t);
if (console.warn(a), el.includes(n)) throw new RangeError(a);
}
function rl(n, e, t) {
const a = n[0] === "Y" ? "years" : "days of the month";
return `Use \`${n.toLowerCase()}\` instead of \`${n}\` (in \`${e}\`) for formatting ${a} to the input \`${t}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
}
function sl(n) {
return n instanceof Date || typeof n == "object" && Object.prototype.toString.call(n) === "[object Date]";
}
function il(n) {
return !(!sl(n) && typeof n != "number" || isNaN(+Be(n)));
}
const ll = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g, ol = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g, ul = /^'([^]*?)'?$/, cl = /''/g, dl = /[a-zA-Z]/;
function Kr(n, e, t) {
var u, d, p, f, y, w, k, D;
const a = Tn(), r = (t == null ? void 0 : t.locale) ?? a.locale ?? Ni, s = (t == null ? void 0 : t.firstWeekContainsDate) ?? ((d = (u = t == null ? void 0 : t.locale) == null ? void 0 : u.options) == null ? void 0 : d.firstWeekContainsDate) ?? a.firstWeekContainsDate ?? ((f = (p = a.locale) == null ? void 0 : p.options) == null ? void 0 : f.firstWeekContainsDate) ?? 1, i = (t == null ? void 0 : t.weekStartsOn) ?? ((w = (y = t == null ? void 0 : t.locale) == null ? void 0 : y.options) == null ? void 0 : w.weekStartsOn) ?? a.weekStartsOn ?? ((D = (k = a.locale) == null ? void 0 : k.options) == null ? void 0 : D.weekStartsOn) ?? 0, l = Be(n, t == null ? void 0 : t.in);
if (!il(l))
throw new RangeError("Invalid time value");
let o = e.match(ol).map((g) => {
const m = g[0];
if (m === "p" || m === "P") {
const x = Ki[m];
return x(g, r.formatLong);
}
return g;
}).join("").match(ll).map((g) => {
if (g === "''")
return { isToken: !1, value: "'" };
const m = g[0];
if (m === "'")
return { isToken: !1, value: hl(g) };
if (Fa[m])
return { isToken: !0, value: g };
if (m.match(dl))
throw new RangeError(
"Format string contains an unescaped latin alphabet character `" + m + "`"
);
return { isToken: !1, value: g };
});
r.localize.preprocessor && (o = r.localize.preprocessor(l, o));
const c = {
firstWeekContainsDate: s,
weekStartsOn: i,
locale: r
};
return o.map((g) => {
if (!g.isToken) return g.value;
const m = g.value;
(!(t != null && t.useAdditionalWeekYearTokens) && nl(m) || !(t != null && t.useAdditionalDayOfYearTokens) && tl(m)) && al(m, e, String(n));
const x = Fa[m[0]];
return x(l, m, r.localize, c);
}).join("");
}
function hl(n) {
const e = n.match(ul);
return e ? e[1].replace(cl, "'") : n;
}
const ae = (n) => !!n && n instanceof Date && !Number.isNaN(new Date(n).valueOf());
function st(n) {
return typeof n == "string" || n instanceof String;
}
function Ba(n) {
var e;
return typeof n == "object" && n != null && (n == null || (e = n.constructor) == null ? void 0 : e.name) === "Object";
}
function Qr(n, e) {
return Array.isArray(e) ? Qr(n, (t, a) => e.includes(a)) : Object.entries(n).reduce((t, a) => {
let [r, s] = a;
return e(s, r) && (t[r] = s), t;
}, {});
}
const N = {
NONE: "NONE",
LEFT: "LEFT",
FORCE_LEFT: "FORCE_LEFT",
RIGHT: "RIGHT",
FORCE_RIGHT: "FORCE_RIGHT"
};
function fl(n) {
switch (n) {
case N.LEFT:
return N.FORCE_LEFT;
case N.RIGHT:
return N.FORCE_RIGHT;
default:
return n;
}
}
function Nn(n) {
return n.replace(/([.*+?^=!:${}()|[\]/\\])/g, "\\$1");
}
function gn(n, e) {
if (e === n) return !0;
const t = Array.isArray(e), a = Array.isArray(n);
let r;
if (t && a) {
if (e.length != n.length) return !1;
for (r = 0; r < e.length; r++) if (!gn(e[r], n[r])) return !1;
return !0;
}
if (t != a) return !1;
if (e && n && typeof e == "object" && typeof n == "object") {
const s = e instanceof Date, i = n instanceof Date;
if (s && i) return e.getTime() == n.getTime();
if (s != i) return !1;
const l = e instanceof RegExp, o = n instanceof RegExp;
if (l && o) return e.toString() == n.toString();
if (l != o) return !1;
const c = Object.keys(e);
for (r = 0; r < c.length; r++) if (!Object.prototype.hasOwnProperty.call(n, c[r])) return !1;
for (r = 0; r < c.length; r++) if (!gn(n[c[r]], e[c[r]])) return !1;
return !0;
} else if (e && n && typeof e == "function" && typeof n == "function")
return e.toString() === n.toString();
return !1;
}
class pl {
/** Current input value */
/** Current cursor position */
/** Old input value */
/** Old selection */
constructor(e) {
for (Object.assign(this, e); this.value.slice(0, this.startChangePos) !== this.oldValue.slice(0, this.startChangePos); )
--this.oldSelection.start;
if (this.insertedCount)
for (; this.value.slice(this.cursorPos) !== this.oldValue.slice(this.oldSelection.end); )
this.value.length - this.cursorPos < this.oldValue.length - this.oldSelection.end ? ++this.oldSelection.end : ++this.cursorPos;
}
/** Start changing position */
get startChangePos() {
return Math.min(this.cursorPos, this.oldSelection.start);
}
/** Inserted symbols count */
get insertedCount() {
return this.cursorPos - this.startChangePos;
}
/** Inserted symbols */
get inserted() {
return this.value.substr(this.startChangePos, this.insertedCount);
}
/** Removed symbols count */
get removedCount() {
return Math.max(this.oldSelection.end - this.startChangePos || // for Delete
this.oldValue.length - this.value.length, 0);
}
/** Removed symbols */
get removed() {
return this.oldValue.substr(this.startChangePos, this.removedCount);
}
/** Unchanged head symbols */
get head() {
return this.value.substring(0, this.startChangePos);
}
/** Unchanged tail symbols */
get tail() {
return this.value.substring(this.startChangePos + this.insertedCount);
}
/** Remove direction */
get removeDirection() {
return !this.removedCount || this.insertedCount ? N.NONE : (this.oldSelection.end === this.cursorPos || this.oldSelection.start === this.cursorPos) && // if not range removed (event with backspace)
this.oldSelection.end === this.oldSelection.start ? N.RIGHT : N.LEFT;
}
}
function B(n, e) {
return new B.InputMask(n, e);
}
function Jr(n) {
if (n == null) throw new Error("mask property should be defined");
return n instanceof RegExp ? B.MaskedRegExp : st(n) ? B.MaskedPattern : n === Date ? B.MaskedDate : n === Number ? B.MaskedNumber : Array.isArray(n) || n === Array ? B.MaskedDynamic : B.Masked && n.prototype instanceof B.Masked ? n : B.Masked && n instanceof B.Masked ? n.constructor : n instanceof Function ? B.MaskedFunction : (console.warn("Mask not found for mask", n), B.Masked);
}
function Gt(n) {
if (!n) throw new Error("Options in not defined");
if (B.Masked) {
if (n.prototype instanceof B.Masked) return {
mask: n
};
const {
mask: e = void 0,
...t
} = n instanceof B.Masked ? {
mask: n
} : Ba(n) && n.mask instanceof B.Masked ? n : {};
if (e) {
const a = e.mask;
return {
...Qr(e, (r, s) => !s.startsWith("_")),
mask: e.constructor,
_mask: a,
...t
};
}
}
return Ba(n) ? {
...n
} : {
mask: n
};
}
function Ge(n) {
if (B.Masked && n instanceof B.Masked) return n;
const e = Gt(n), t = Jr(e.mask);
if (!t) throw new Error("Masked class is not found for provided mask " + e.mask + ", appropriate module needs to be imported manually before creating mask.");
return e.mask === t && delete e.mask, e._mask && (e.mask = e._mask, delete e._mask), new t(e);
}
B.createMask = Ge;
class ca {
/** */
/** */
/** */
/** Safely returns selection start */
get selectionStart() {
let e;
try {
e = this._unsafeSelectionStart;
} catch {
}
return e ?? this.value.length;
}
/** Safely returns selection end */
get selectionEnd() {
let e;
try {
e = this._unsafeSelectionEnd;
} catch {
}
return e ?? this.value.length;
}
/** Safely sets element selection */
select(e, t) {
if (!(e == null || t == null || e === this.selectionStart && t === this.selectionEnd))
try {
this._unsafeSelect(e, t);
} catch {
}
}
/** */
get isActive() {
return !1;
}
/** */
/** */
/** */
}
B.MaskElement = ca;
const Ia = 90, vl = 89;
class Dn extends ca {
/** HTMLElement to use mask on */
constructor(e) {
super(), this.input = e, this._onKeydown = this._onKeydown.bind(this), this._onInput = this._onInput.bind(this), this._onBeforeinput = this._onBeforeinput.bind(this), this._onCompositionEnd = this._onCompositionEnd.bind(this);
}
get rootElement() {
var e, t, a;
return (e = (t = (a = this.input).getRootNode) == null ? void 0 : t.call(a)) != null ? e : document;
}
/** Is element in focus */
get isActive() {
return this.input === this.rootElement.activeElement;
}
/** Binds HTMLElement events to mask internal events */
bindEvents(e) {
this.input.addEventListener("keydown", this._onKeydown), this.input.addEventListener("input", this._onInput), this.input.addEventListener("beforeinput", this._onBeforeinput), this.input.addEventListener("compositionend", this._onCompositionEnd), this.input.addEventListener("drop", e.drop), this.input.addEventListener("click", e.click), this.input.addEventListener("focus", e.focus), this.input.addEventListener("blur", e.commit), this._handlers = e;
}
_onKeydown(e) {
if (this._handlers.redo && (e.keyCode === Ia && e.shiftKey && (e.metaKey || e.ctrlKey) || e.keyCode === vl && e.ctrlKey))
return e.preventDefault(), this._handlers.redo(e);
if (this._handlers.undo && e.keyCode === Ia && (e.metaKey || e.ctrlKey))
return e.preventDefault(), this._handlers.undo(e);
e.isComposing || this._handlers.selectionChange(e);
}
_onBeforeinput(e) {
if (e.inputType === "historyUndo" && this._handlers.undo)
return e.preventDefault(), this._handlers.undo(e);
if (e.inputType === "historyRedo" && this._handlers.redo)
return e.preventDefault(), this._handlers.redo(e);
}
_onCompositionEnd(e) {
this._handlers.input(e);
}
_onInput(e) {
e.isComposing || this._handlers.input(e);
}
/** Unbinds HTMLElement events to mask internal events */
unbindEvents() {
this.input.removeEventListener("keydown", this._onKeydown), this.input.removeEventListener("input", this._onInput), this.input.removeEventListener("beforeinput", this._onBeforeinput), this.input.removeEventListener("compositionend", this._onCompositionEnd), this.input.removeEventListener("drop", this._handlers.drop), this.input.removeEventListener("click", this._handlers.click), this.input.removeEventListener("focus", this._handlers.focus), this.input.removeEventListener("blur", this._handlers.commit), this._handlers = {};
}
}
B.HTMLMaskElement = Dn;
class ml extends Dn {
/** InputElement to use mask on */
constructor(e) {
super(e), this.input = e;
}
/** Returns InputElement selection start */
get _unsafeSelectionStart() {
return this.input.selectionStart != null ? this.input.selectionStart : this.value.length;
}
/** Returns InputElement selection end */
get _unsafeSelectionEnd() {
return this.input.selectionEnd;
}
/** Sets InputElement selection */
_unsafeSelect(e, t) {
this.input.setSelectionRange(e, t);
}
get value() {
return this.input.value;
}
set value(e) {
this.input.value = e;
}
}
B.HTMLMaskElement = Dn;
class es extends Dn {
/** Returns HTMLElement selection start */
get _unsafeSelectionStart() {
const e = this.rootElement, t = e.getSelection && e.getSelection(), a = t && t.anchorOffset, r = t && t.focusOffset;
return r == null || a == null || a < r ? a : r;
}
/** Returns HTMLElement selection end */
get _unsafeSelectionEnd() {
const e = this.rootElement, t = e.getSelection && e.getSelection(), a = t && t.anchorOffset, r = t && t.focusOffset;
return r == null || a == null || a > r ? a : r;
}
/** Sets HTMLElement selection */
_unsafeSelect(e, t) {
if (!this.rootElement.createRange) return;
const a = this.rootElement.createRange();
a.setStart(this.input.firstChild || this.input, e), a.setEnd(this.input.lastChild || this.input, t);
const r = this.rootElement, s = r.getSelection && r.getSelection();
s && (s.removeAllRanges(), s.addRange(a));
}
/** HTMLElement value */
get value() {
return this.input.textContent || "";
}
set value(e) {
this.input.textContent = e;
}
}
B.HTMLContenteditableMaskElement = es;
class Sn {
constructor() {
this.states = [], this.currentIndex = 0;
}
get currentState() {
return this.states[this.currentIndex];
}
get isEmpty() {
return this.states.length === 0;
}
push(e) {
this.currentIndex < this.states.length - 1 && (this.states.length = this.currentIndex + 1), this.states.push(e), this.states.length > Sn.MAX_LENGTH && this.states.shift(), this.currentIndex = this.states.length - 1;
}
go(e) {
return this.currentIndex = Math.min(Math.max(this.currentIndex + e, 0), this.states.length - 1), this.currentState;
}
undo() {
return this.go(-1);
}
redo() {
return this.go(1);
}
clear() {
this.states.length = 0, this.currentIndex = 0;
}
}
Sn.MAX_LENGTH = 100;
class gl {
/**
View element
*/
/** Internal {@link Masked} model */
constructor(e, t) {
this.el = e instanceof ca ? e : e.isContentEditable && e.tagName !== "INPUT" && e.tagName !== "TEXTAREA" ? new es(e) : new ml(e), this.masked = Ge(t), this._listeners = {}, this._value = "", this._unmaskedValue = "", this._rawInputValue = "", this.history = new Sn(), this._saveSelection = this._saveSelection.bind(this), this._onInput = this._onInput.bind(this), this._onChange = this._onChange.bind(this), this._onDrop = this._onDrop.bind(this), this._onFocus = this._onFocus.bind(this), this._onClick = this._onClick.bind(this), this._onUndo = this._onUndo.bind(this), this._onRedo = this._onRedo.bind(this), this.alignCursor = this.alignCursor.bind(this), this.alignCursorFriendly = this.alignCursorFriendly.bind(this), this._bindEvents(), this.updateValue(), this._onChange();
}
maskEquals(e) {
var t;
return e == null || ((t = this.masked) == null ? void 0 : t.maskEquals(e));
}
/** Masked */
get mask() {
return this.masked.mask;
}
set mask(e) {
if (this.maskEquals(e)) return;
if (!(e instanceof B.Masked) && this.masked.constructor === Jr(e)) {
this.masked.updateOptions({
mask: e
});
return;
}
const t = e instanceof B.Masked ? e : Ge({
mask: e
});
t.unmaskedValue = this.masked.unmaskedValue, this.masked = t;
}
/** Raw value */
get value() {
return this._value;
}
set value(e) {
this.value !== e && (this.masked.value = e, this.updateControl("auto"));
}
/** Unmasked value */
get unmaskedValue() {
return this._unmaskedValue;
}
set unmaskedValue(e) {
this.unmaskedValue !== e && (this.masked.unmaskedValue = e, this.updateControl("auto"));
}
/** Raw input value */
get rawInputValue() {
return this._rawInputValue;
}
set rawInputValue(e) {
this.rawInputValue !== e && (this.masked.rawInputValue = e, this.updateControl(), this.alignCursor());
}
/** Typed unmasked value */
get typedValue() {
return this.masked.typedValue;
}
set typedValue(e) {
this.masked.typedValueEquals(e) || (this.masked.typedValue = e, this.updateControl("auto"));
}
/** Display value */
get displayValue() {
return this.masked.displayValue;
}
/** Starts listening to element events */
_bindEvents() {
this.el.bindEvents({
selectionChange: this._saveSelection,
input: this._onInput,
drop: this._onDrop,
click: this._onClick,
focus: this._onFocus,
commit: this._onChange,
undo: this._onUndo,
redo: this._onRedo
});
}
/** Stops listening to element events */
_unbindEvents() {
this.el && this.el.unbindEvents();
}
/** Fires custom event */
_fireEvent(e, t) {
const a = this._listeners[e];
a && a.forEach((r) => r(t));
}
/** Current selection start */
get selectionStart() {
return this._cursorChanging ? this._changingCursorPos : this.el.selectionStart;
}
/** Current cursor position */
get cursorPos() {
return this._cursorChanging ? this._changingCursorPos : this.el.selectionEnd;
}
set cursorPos(e) {
!this.el || !this.el.isActive || (this.el.select(e, e), this._saveSelection());
}
/** Stores current selection */
_saveSelection() {
this.displayValue !== this.el.value && console.warn("Element value was changed outside of mask. Syncronize mask using `mask.updateValue()` to work properly."), this._selection = {
start: this.selectionStart,
end: this.cursorPos
};
}
/** Syncronizes model value from view */
updateValue() {
this.masked.value = this.el.value, this._value = this.masked.value, this._unmaskedValue = this.masked.unmaskedValue, this._rawInputValue = this.masked.rawInputValue;
}
/** Syncronizes view from model value, fires change events */
updateControl(e) {
const t = this.masked.unmaskedValue, a = this.masked.value, r = this.masked.rawInputValue, s = this.displayValue, i = this.unmaskedValue !== t || this.value !== a || this._rawInputValue !== r;
this._unmaskedValue = t, this._value = a, this._rawInputValue = r, this.el.value !== s && (this.el.value = s), e === "auto" ? this.alignCursor() : e != null && (this.cursorPos = e), i && this._fireChangeEvents(), !this._historyChanging && (i || this.history.isEmpty) && this.history.push({
unmaskedValue: t,
selection: {
start: this.selectionStart,
end: this.cursorPos
}
});
}
/** Updates options with deep equal check, recreates {@link Masked} model if mask type changes */
updateOptions(e) {
const {
mask: t,
...a
} = e, r = !this.maskEquals(t), s = this.masked.optionsIsChanged(a);
r && (this.mask = t), s && this.masked.updateOptions(a), (r || s) && this.updateControl();
}
/** Updates cursor */
updateCursor(e) {
e != null && (this.cursorPos = e, this._delayUpdateCursor(e));
}
/** Delays cursor update to support mobile browsers */
_delayUpdateCursor(e) {
this._abortUpdateCursor(), this._changingCursorPos = e, this._cursorChanging = setTimeout(() => {
this.el && (this.cursorPos = this._changingCursorPos, this._abortUpdateCursor());
}, 10);
}
/** Fires custom events */
_fireChangeEvents() {
this._fireEvent("accept", this._inputEvent), this.masked.isComplete && this._fireEvent("complete", this._inputEvent);
}
/** Aborts delayed cursor update */
_abortUpdateCursor() {
this._cursorChanging && (clearTimeout(this._cursorChanging), delete this._cursorChanging);
}
/** Aligns cursor to nearest available position */
alignCursor() {
this.cursorPos = this.masked.nearestInputPos(this.masked.nearestInputPos(this.cursorPos, N.LEFT));
}
/** Aligns cursor only if selection is empty */
alignCursorFriendly() {
this.selectionStart === this.cursorPos && this.alignCursor();
}
/** Adds listener on custom event */
on(e, t) {
return this._listeners[e] || (this._listeners[e] = []), this._listeners[e].push(t), this;
}
/** Removes custom event listener */
off(e, t) {
if (!this._listeners[e]) return this;
if (!t)
return delete this._listeners[e], this;
const a = this._listeners[e].indexOf(t);
return a >= 0 && this._listeners[e].splice(a, 1), this;
}
/** Handles view input event */
_onInput(e) {
this._inputEvent = e, this._abortUpdateCursor();
const t = new pl({
// new state
value: this.el.value,
cursorPos: this.cursorPos,
// old state
oldValue: this.displayValue,
oldSelection: this._selection
}), a = this.masked.rawInputValue, r = this.masked.splice(t.startChangePos, t.removed.length, t.inserted, t.removeDirection, {
input: !0,
raw: !0
}).offset, s = a === this.masked.rawInputVa