@phila/phila-ui-core 1.0.4 → 1.0.5

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.
@@ -1,2740 +0,0 @@
1
- import { reactive as ut, computed as M, watch as A, onMounted as nt, ref as b, onBeforeMount as ft, isRef as kt, onUnmounted as mt, readonly as gt, defineComponent as _t, toRef as R, h as vt } from "vue";
2
- const D = ut({
3
- isMobile: !1,
4
- isTablet: !1,
5
- isDesktop: !1,
6
- isWideScreen: !1
7
- }), Et = (u) => {
8
- D.isMobile = u.matchMedia("(max-width: 767px)").matches, D.isTablet = u.matchMedia("(min-width: 768px) and (max-width: 1023px)").matches, D.isDesktop = u.matchMedia("(min-width: 1024px)").matches, D.isWideScreen = u.matchMedia("(min-width: 1152px)").matches;
9
- }, Ct = () => Math.random().toString(36).substring(2, 9), At = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
10
- __proto__: null,
11
- randomID: Ct
12
- }, Symbol.toStringTag, { value: "Module" })), Ft = (u, t) => {
13
- const e = M(() => t.errors instanceof Array ? t.errors[0] : t.errors), s = () => {
14
- var l;
15
- e.value && ((l = u == null ? void 0 : u.parent) == null || l.emit("hasError", {
16
- [t.id]: e.value != ""
17
- }));
18
- }, i = M(() => {
19
- const l = [], o = {};
20
- let d = "";
21
- const f = t.options;
22
- return Object.keys(t.options).forEach((m) => {
23
- f && (Array.isArray(f[m]) ? (d = "array", l.push(f[m])) : (d = "object", Object.assign(o, f[m])));
24
- }), d === "array" ? l : o;
25
- }), a = (l) => typeof l == "object" ? l[t.textKey] : l, n = (l, o) => {
26
- const { optgroup: d, valueKey: f } = t;
27
- let { options: m } = t;
28
- return d && (m = i.value), Array.isArray(m) ? typeof l == "object" ? l[f] : l : o;
29
- }, r = M(() => {
30
- const l = [];
31
- return u != null && u.attrs.required && l.push("is-required"), e.value && l.push("has-error"), u != null && u.props.innerLabel && l.push("inner-label"), u != null && u.props.forceInputBoxSize && l.push("input-width"), l.join(" ");
32
- });
33
- return A(e, () => {
34
- s();
35
- }), nt(() => {
36
- s();
37
- }), {
38
- error: e,
39
- classes: r,
40
- hasError: s,
41
- optionText: a,
42
- optionValue: n
43
- };
44
- }, xt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
45
- __proto__: null,
46
- useInputComposable: Ft
47
- }, Symbol.toStringTag, { value: "Module" })), yt = (u, t) => {
48
- const e = M(() => {
49
- const a = [];
50
- return t.isLoading && a.push("is-loading"), t.icon && a.push("has-icons-right"), a.join(" ");
51
- }), s = M(() => {
52
- let a = t.placeholder;
53
- return !a && (t.innerLabel == !0 || t.innerLabel == null) && (a = "Insert placeholder here"), a;
54
- });
55
- return {
56
- inputModifierClasses: e,
57
- defaultPlaceholder: s,
58
- onInput: (a) => {
59
- u("update:modelValue", a.target.value), u("input", a);
60
- }
61
- };
62
- }, St = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
63
- __proto__: null,
64
- useTextboxComposable: yt
65
- }, Symbol.toStringTag, { value: "Module" })), Bt = (u, t) => {
66
- const e = b(""), s = ut({
67
- mask: "",
68
- lazy: !1
69
- });
70
- return A(
71
- () => u == null ? void 0 : u.props.modelValue,
72
- (l) => {
73
- e.value = l;
74
- }
75
- ), ft(() => {
76
- e.value = u == null ? void 0 : u.props.modelValue;
77
- }), {
78
- localValue: e,
79
- mask: s,
80
- acceptEvent: (l) => {
81
- const o = l.detail;
82
- t("update:modelValue", o._value), t("input", o._value), t("unmasked-input", o._unmaskedValue);
83
- },
84
- completeEvent: (l) => {
85
- const o = l.detail;
86
- t("update:modelValue", o._value), t("complete", o._value);
87
- },
88
- onFocus: () => {
89
- e.value || (s.lazy = !1);
90
- },
91
- onBlur: (l) => {
92
- var o;
93
- (o = l.target.maskRef) != null && o._unmaskedValue || (s.lazy = !0);
94
- }
95
- };
96
- }, bt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
97
- __proto__: null,
98
- useMaskedInputComposable: Bt
99
- }, Symbol.toStringTag, { value: "Module" }));
100
- function S(u) {
101
- return typeof u == "string" || u instanceof String;
102
- }
103
- function tt(u) {
104
- var t;
105
- return typeof u == "object" && u != null && (u == null || (t = u.constructor) == null ? void 0 : t.name) === "Object";
106
- }
107
- function rt(u, t) {
108
- return Array.isArray(t) ? rt(u, (e, s) => t.includes(s)) : Object.entries(u).reduce((e, s) => {
109
- let [i, a] = s;
110
- return t(a, i) && (e[i] = a), e;
111
- }, {});
112
- }
113
- const h = {
114
- NONE: "NONE",
115
- LEFT: "LEFT",
116
- FORCE_LEFT: "FORCE_LEFT",
117
- RIGHT: "RIGHT",
118
- FORCE_RIGHT: "FORCE_RIGHT"
119
- };
120
- function Vt(u) {
121
- switch (u) {
122
- case h.LEFT:
123
- return h.FORCE_LEFT;
124
- case h.RIGHT:
125
- return h.FORCE_RIGHT;
126
- default:
127
- return u;
128
- }
129
- }
130
- function G(u) {
131
- return u.replace(/([.*+?^=!:${}()|[\]/\\])/g, "\\$1");
132
- }
133
- function L(u, t) {
134
- if (t === u)
135
- return !0;
136
- const e = Array.isArray(t), s = Array.isArray(u);
137
- let i;
138
- if (e && s) {
139
- if (t.length != u.length)
140
- return !1;
141
- for (i = 0; i < t.length; i++)
142
- if (!L(t[i], u[i]))
143
- return !1;
144
- return !0;
145
- }
146
- if (e != s)
147
- return !1;
148
- if (t && u && typeof t == "object" && typeof u == "object") {
149
- const a = t instanceof Date, n = u instanceof Date;
150
- if (a && n)
151
- return t.getTime() == u.getTime();
152
- if (a != n)
153
- return !1;
154
- const r = t instanceof RegExp, l = u instanceof RegExp;
155
- if (r && l)
156
- return t.toString() == u.toString();
157
- if (r != l)
158
- return !1;
159
- const o = Object.keys(t);
160
- for (i = 0; i < o.length; i++)
161
- if (!Object.prototype.hasOwnProperty.call(u, o[i]))
162
- return !1;
163
- for (i = 0; i < o.length; i++)
164
- if (!L(u[o[i]], t[o[i]]))
165
- return !1;
166
- return !0;
167
- } else if (t && u && typeof t == "function" && typeof u == "function")
168
- return t.toString() === u.toString();
169
- return !1;
170
- }
171
- class It {
172
- /** Current input value */
173
- /** Current cursor position */
174
- /** Old input value */
175
- /** Old selection */
176
- constructor(t) {
177
- for (Object.assign(this, t); this.value.slice(0, this.startChangePos) !== this.oldValue.slice(0, this.startChangePos); )
178
- --this.oldSelection.start;
179
- if (this.insertedCount)
180
- for (; this.value.slice(this.cursorPos) !== this.oldValue.slice(this.oldSelection.end); )
181
- this.value.length - this.cursorPos < this.oldValue.length - this.oldSelection.end ? ++this.oldSelection.end : ++this.cursorPos;
182
- }
183
- /** Start changing position */
184
- get startChangePos() {
185
- return Math.min(this.cursorPos, this.oldSelection.start);
186
- }
187
- /** Inserted symbols count */
188
- get insertedCount() {
189
- return this.cursorPos - this.startChangePos;
190
- }
191
- /** Inserted symbols */
192
- get inserted() {
193
- return this.value.substr(this.startChangePos, this.insertedCount);
194
- }
195
- /** Removed symbols count */
196
- get removedCount() {
197
- return Math.max(this.oldSelection.end - this.startChangePos || // for Delete
198
- this.oldValue.length - this.value.length, 0);
199
- }
200
- /** Removed symbols */
201
- get removed() {
202
- return this.oldValue.substr(this.startChangePos, this.removedCount);
203
- }
204
- /** Unchanged head symbols */
205
- get head() {
206
- return this.value.substring(0, this.startChangePos);
207
- }
208
- /** Unchanged tail symbols */
209
- get tail() {
210
- return this.value.substring(this.startChangePos + this.insertedCount);
211
- }
212
- /** Remove direction */
213
- get removeDirection() {
214
- return !this.removedCount || this.insertedCount ? h.NONE : (this.oldSelection.end === this.cursorPos || this.oldSelection.start === this.cursorPos) && // if not range removed (event with backspace)
215
- this.oldSelection.end === this.oldSelection.start ? h.RIGHT : h.LEFT;
216
- }
217
- }
218
- function p(u, t) {
219
- return new p.InputMask(u, t);
220
- }
221
- function lt(u) {
222
- if (u == null)
223
- throw new Error("mask property should be defined");
224
- return u instanceof RegExp ? p.MaskedRegExp : S(u) ? p.MaskedPattern : u === Date ? p.MaskedDate : u === Number ? p.MaskedNumber : Array.isArray(u) || u === Array ? p.MaskedDynamic : p.Masked && u.prototype instanceof p.Masked ? u : p.Masked && u instanceof p.Masked ? u.constructor : u instanceof Function ? p.MaskedFunction : (console.warn("Mask not found for mask", u), p.Masked);
225
- }
226
- function w(u) {
227
- if (!u)
228
- throw new Error("Options in not defined");
229
- if (p.Masked) {
230
- if (u.prototype instanceof p.Masked)
231
- return {
232
- mask: u
233
- };
234
- const {
235
- mask: t = void 0,
236
- ...e
237
- } = u instanceof p.Masked ? {
238
- mask: u
239
- } : tt(u) && u.mask instanceof p.Masked ? u : {};
240
- if (t) {
241
- const s = t.mask;
242
- return {
243
- ...rt(t, (i, a) => !a.startsWith("_")),
244
- mask: t.constructor,
245
- _mask: s,
246
- ...e
247
- };
248
- }
249
- }
250
- return tt(u) ? {
251
- ...u
252
- } : {
253
- mask: u
254
- };
255
- }
256
- function y(u) {
257
- if (p.Masked && u instanceof p.Masked)
258
- return u;
259
- const t = w(u), e = lt(t.mask);
260
- if (!e)
261
- throw new Error("Masked class is not found for provided mask " + t.mask + ", appropriate module needs to be imported manually before creating mask.");
262
- return t.mask === e && delete t.mask, t._mask && (t.mask = t._mask, delete t._mask), new e(t);
263
- }
264
- p.createMask = y;
265
- class Y {
266
- /** */
267
- /** */
268
- /** */
269
- /** Safely returns selection start */
270
- get selectionStart() {
271
- let t;
272
- try {
273
- t = this._unsafeSelectionStart;
274
- } catch {
275
- }
276
- return t ?? this.value.length;
277
- }
278
- /** Safely returns selection end */
279
- get selectionEnd() {
280
- let t;
281
- try {
282
- t = this._unsafeSelectionEnd;
283
- } catch {
284
- }
285
- return t ?? this.value.length;
286
- }
287
- /** Safely sets element selection */
288
- select(t, e) {
289
- if (!(t == null || e == null || t === this.selectionStart && e === this.selectionEnd))
290
- try {
291
- this._unsafeSelect(t, e);
292
- } catch {
293
- }
294
- }
295
- /** */
296
- get isActive() {
297
- return !1;
298
- }
299
- /** */
300
- /** */
301
- /** */
302
- }
303
- p.MaskElement = Y;
304
- const et = 90, Dt = 89;
305
- class U extends Y {
306
- /** HTMLElement to use mask on */
307
- constructor(t) {
308
- super(), this.input = t, this._onKeydown = this._onKeydown.bind(this), this._onInput = this._onInput.bind(this), this._onBeforeinput = this._onBeforeinput.bind(this), this._onCompositionEnd = this._onCompositionEnd.bind(this);
309
- }
310
- get rootElement() {
311
- var t, e, s;
312
- return (t = (e = (s = this.input).getRootNode) == null ? void 0 : e.call(s)) != null ? t : document;
313
- }
314
- /** Is element in focus */
315
- get isActive() {
316
- return this.input === this.rootElement.activeElement;
317
- }
318
- /** Binds HTMLElement events to mask internal events */
319
- bindEvents(t) {
320
- 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", t.drop), this.input.addEventListener("click", t.click), this.input.addEventListener("focus", t.focus), this.input.addEventListener("blur", t.commit), this._handlers = t;
321
- }
322
- _onKeydown(t) {
323
- if (this._handlers.redo && (t.keyCode === et && t.shiftKey && (t.metaKey || t.ctrlKey) || t.keyCode === Dt && t.ctrlKey))
324
- return t.preventDefault(), this._handlers.redo(t);
325
- if (this._handlers.undo && t.keyCode === et && (t.metaKey || t.ctrlKey))
326
- return t.preventDefault(), this._handlers.undo(t);
327
- t.isComposing || this._handlers.selectionChange(t);
328
- }
329
- _onBeforeinput(t) {
330
- if (t.inputType === "historyUndo" && this._handlers.undo)
331
- return t.preventDefault(), this._handlers.undo(t);
332
- if (t.inputType === "historyRedo" && this._handlers.redo)
333
- return t.preventDefault(), this._handlers.redo(t);
334
- }
335
- _onCompositionEnd(t) {
336
- this._handlers.input(t);
337
- }
338
- _onInput(t) {
339
- t.isComposing || this._handlers.input(t);
340
- }
341
- /** Unbinds HTMLElement events to mask internal events */
342
- unbindEvents() {
343
- 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 = {};
344
- }
345
- }
346
- p.HTMLMaskElement = U;
347
- class Mt extends U {
348
- /** InputElement to use mask on */
349
- constructor(t) {
350
- super(t), this.input = t;
351
- }
352
- /** Returns InputElement selection start */
353
- get _unsafeSelectionStart() {
354
- return this.input.selectionStart != null ? this.input.selectionStart : this.value.length;
355
- }
356
- /** Returns InputElement selection end */
357
- get _unsafeSelectionEnd() {
358
- return this.input.selectionEnd;
359
- }
360
- /** Sets InputElement selection */
361
- _unsafeSelect(t, e) {
362
- this.input.setSelectionRange(t, e);
363
- }
364
- get value() {
365
- return this.input.value;
366
- }
367
- set value(t) {
368
- this.input.value = t;
369
- }
370
- }
371
- p.HTMLMaskElement = U;
372
- class ot extends U {
373
- /** Returns HTMLElement selection start */
374
- get _unsafeSelectionStart() {
375
- const t = this.rootElement, e = t.getSelection && t.getSelection(), s = e && e.anchorOffset, i = e && e.focusOffset;
376
- return i == null || s == null || s < i ? s : i;
377
- }
378
- /** Returns HTMLElement selection end */
379
- get _unsafeSelectionEnd() {
380
- const t = this.rootElement, e = t.getSelection && t.getSelection(), s = e && e.anchorOffset, i = e && e.focusOffset;
381
- return i == null || s == null || s > i ? s : i;
382
- }
383
- /** Sets HTMLElement selection */
384
- _unsafeSelect(t, e) {
385
- if (!this.rootElement.createRange)
386
- return;
387
- const s = this.rootElement.createRange();
388
- s.setStart(this.input.firstChild || this.input, t), s.setEnd(this.input.lastChild || this.input, e);
389
- const i = this.rootElement, a = i.getSelection && i.getSelection();
390
- a && (a.removeAllRanges(), a.addRange(s));
391
- }
392
- /** HTMLElement value */
393
- get value() {
394
- return this.input.textContent || "";
395
- }
396
- set value(t) {
397
- this.input.textContent = t;
398
- }
399
- }
400
- p.HTMLContenteditableMaskElement = ot;
401
- class j {
402
- constructor() {
403
- this.states = [], this.currentIndex = 0;
404
- }
405
- get currentState() {
406
- return this.states[this.currentIndex];
407
- }
408
- get isEmpty() {
409
- return this.states.length === 0;
410
- }
411
- push(t) {
412
- this.currentIndex < this.states.length - 1 && (this.states.length = this.currentIndex + 1), this.states.push(t), this.states.length > j.MAX_LENGTH && this.states.shift(), this.currentIndex = this.states.length - 1;
413
- }
414
- go(t) {
415
- return this.currentIndex = Math.min(Math.max(this.currentIndex + t, 0), this.states.length - 1), this.currentState;
416
- }
417
- undo() {
418
- return this.go(-1);
419
- }
420
- redo() {
421
- return this.go(1);
422
- }
423
- clear() {
424
- this.states.length = 0, this.currentIndex = 0;
425
- }
426
- }
427
- j.MAX_LENGTH = 100;
428
- class wt {
429
- /**
430
- View element
431
- */
432
- /** Internal {@link Masked} model */
433
- constructor(t, e) {
434
- this.el = t instanceof Y ? t : t.isContentEditable && t.tagName !== "INPUT" && t.tagName !== "TEXTAREA" ? new ot(t) : new Mt(t), this.masked = y(e), this._listeners = {}, this._value = "", this._unmaskedValue = "", this._rawInputValue = "", this.history = new j(), 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._onChange();
435
- }
436
- maskEquals(t) {
437
- var e;
438
- return t == null || ((e = this.masked) == null ? void 0 : e.maskEquals(t));
439
- }
440
- /** Masked */
441
- get mask() {
442
- return this.masked.mask;
443
- }
444
- set mask(t) {
445
- if (this.maskEquals(t))
446
- return;
447
- if (!(t instanceof p.Masked) && this.masked.constructor === lt(t)) {
448
- this.masked.updateOptions({
449
- mask: t
450
- });
451
- return;
452
- }
453
- const e = t instanceof p.Masked ? t : y({
454
- mask: t
455
- });
456
- e.unmaskedValue = this.masked.unmaskedValue, this.masked = e;
457
- }
458
- /** Raw value */
459
- get value() {
460
- return this._value;
461
- }
462
- set value(t) {
463
- this.value !== t && (this.masked.value = t, this.updateControl("auto"));
464
- }
465
- /** Unmasked value */
466
- get unmaskedValue() {
467
- return this._unmaskedValue;
468
- }
469
- set unmaskedValue(t) {
470
- this.unmaskedValue !== t && (this.masked.unmaskedValue = t, this.updateControl("auto"));
471
- }
472
- /** Raw input value */
473
- get rawInputValue() {
474
- return this._rawInputValue;
475
- }
476
- set rawInputValue(t) {
477
- this.rawInputValue !== t && (this.masked.rawInputValue = t, this.updateControl(), this.alignCursor());
478
- }
479
- /** Typed unmasked value */
480
- get typedValue() {
481
- return this.masked.typedValue;
482
- }
483
- set typedValue(t) {
484
- this.masked.typedValueEquals(t) || (this.masked.typedValue = t, this.updateControl("auto"));
485
- }
486
- /** Display value */
487
- get displayValue() {
488
- return this.masked.displayValue;
489
- }
490
- /** Starts listening to element events */
491
- _bindEvents() {
492
- this.el.bindEvents({
493
- selectionChange: this._saveSelection,
494
- input: this._onInput,
495
- drop: this._onDrop,
496
- click: this._onClick,
497
- focus: this._onFocus,
498
- commit: this._onChange,
499
- undo: this._onUndo,
500
- redo: this._onRedo
501
- });
502
- }
503
- /** Stops listening to element events */
504
- _unbindEvents() {
505
- this.el && this.el.unbindEvents();
506
- }
507
- /** Fires custom event */
508
- _fireEvent(t, e) {
509
- const s = this._listeners[t];
510
- s && s.forEach((i) => i(e));
511
- }
512
- /** Current selection start */
513
- get selectionStart() {
514
- return this._cursorChanging ? this._changingCursorPos : this.el.selectionStart;
515
- }
516
- /** Current cursor position */
517
- get cursorPos() {
518
- return this._cursorChanging ? this._changingCursorPos : this.el.selectionEnd;
519
- }
520
- set cursorPos(t) {
521
- !this.el || !this.el.isActive || (this.el.select(t, t), this._saveSelection());
522
- }
523
- /** Stores current selection */
524
- _saveSelection() {
525
- this.displayValue !== this.el.value && console.warn("Element value was changed outside of mask. Syncronize mask using `mask.updateValue()` to work properly."), this._selection = {
526
- start: this.selectionStart,
527
- end: this.cursorPos
528
- };
529
- }
530
- /** Syncronizes model value from view */
531
- updateValue() {
532
- this.masked.value = this.el.value, this._value = this.masked.value, this._unmaskedValue = this.masked.unmaskedValue, this._rawInputValue = this.masked.rawInputValue;
533
- }
534
- /** Syncronizes view from model value, fires change events */
535
- updateControl(t) {
536
- const e = this.masked.unmaskedValue, s = this.masked.value, i = this.masked.rawInputValue, a = this.displayValue, n = this.unmaskedValue !== e || this.value !== s || this._rawInputValue !== i;
537
- this._unmaskedValue = e, this._value = s, this._rawInputValue = i, this.el.value !== a && (this.el.value = a), t === "auto" ? this.alignCursor() : t != null && (this.cursorPos = t), n && this._fireChangeEvents(), !this._historyChanging && (n || this.history.isEmpty) && this.history.push({
538
- unmaskedValue: e,
539
- selection: {
540
- start: this.selectionStart,
541
- end: this.cursorPos
542
- }
543
- });
544
- }
545
- /** Updates options with deep equal check, recreates {@link Masked} model if mask type changes */
546
- updateOptions(t) {
547
- const {
548
- mask: e,
549
- ...s
550
- } = t, i = !this.maskEquals(e), a = this.masked.optionsIsChanged(s);
551
- i && (this.mask = e), a && this.masked.updateOptions(s), (i || a) && this.updateControl();
552
- }
553
- /** Updates cursor */
554
- updateCursor(t) {
555
- t != null && (this.cursorPos = t, this._delayUpdateCursor(t));
556
- }
557
- /** Delays cursor update to support mobile browsers */
558
- _delayUpdateCursor(t) {
559
- this._abortUpdateCursor(), this._changingCursorPos = t, this._cursorChanging = setTimeout(() => {
560
- this.el && (this.cursorPos = this._changingCursorPos, this._abortUpdateCursor());
561
- }, 10);
562
- }
563
- /** Fires custom events */
564
- _fireChangeEvents() {
565
- this._fireEvent("accept", this._inputEvent), this.masked.isComplete && this._fireEvent("complete", this._inputEvent);
566
- }
567
- /** Aborts delayed cursor update */
568
- _abortUpdateCursor() {
569
- this._cursorChanging && (clearTimeout(this._cursorChanging), delete this._cursorChanging);
570
- }
571
- /** Aligns cursor to nearest available position */
572
- alignCursor() {
573
- this.cursorPos = this.masked.nearestInputPos(this.masked.nearestInputPos(this.cursorPos, h.LEFT));
574
- }
575
- /** Aligns cursor only if selection is empty */
576
- alignCursorFriendly() {
577
- this.selectionStart === this.cursorPos && this.alignCursor();
578
- }
579
- /** Adds listener on custom event */
580
- on(t, e) {
581
- return this._listeners[t] || (this._listeners[t] = []), this._listeners[t].push(e), this;
582
- }
583
- /** Removes custom event listener */
584
- off(t, e) {
585
- if (!this._listeners[t])
586
- return this;
587
- if (!e)
588
- return delete this._listeners[t], this;
589
- const s = this._listeners[t].indexOf(e);
590
- return s >= 0 && this._listeners[t].splice(s, 1), this;
591
- }
592
- /** Handles view input event */
593
- _onInput(t) {
594
- this._inputEvent = t, this._abortUpdateCursor();
595
- const e = new It({
596
- // new state
597
- value: this.el.value,
598
- cursorPos: this.cursorPos,
599
- // old state
600
- oldValue: this.displayValue,
601
- oldSelection: this._selection
602
- }), s = this.masked.rawInputValue, i = this.masked.splice(e.startChangePos, e.removed.length, e.inserted, e.removeDirection, {
603
- input: !0,
604
- raw: !0
605
- }).offset, a = s === this.masked.rawInputValue ? e.removeDirection : h.NONE;
606
- let n = this.masked.nearestInputPos(e.startChangePos + i, a);
607
- a !== h.NONE && (n = this.masked.nearestInputPos(n, h.NONE)), this.updateControl(n), delete this._inputEvent;
608
- }
609
- /** Handles view change event and commits model value */
610
- _onChange() {
611
- this.displayValue !== this.el.value && this.updateValue(), this.masked.doCommit(), this.updateControl(), this._saveSelection();
612
- }
613
- /** Handles view drop event, prevents by default */
614
- _onDrop(t) {
615
- t.preventDefault(), t.stopPropagation();
616
- }
617
- /** Restore last selection on focus */
618
- _onFocus(t) {
619
- this.alignCursorFriendly();
620
- }
621
- /** Restore last selection on focus */
622
- _onClick(t) {
623
- this.alignCursorFriendly();
624
- }
625
- _onUndo() {
626
- this._applyHistoryState(this.history.undo());
627
- }
628
- _onRedo() {
629
- this._applyHistoryState(this.history.redo());
630
- }
631
- _applyHistoryState(t) {
632
- t && (this._historyChanging = !0, this.unmaskedValue = t.unmaskedValue, this.el.select(t.selection.start, t.selection.end), this._saveSelection(), this._historyChanging = !1);
633
- }
634
- /** Unbind view events and removes element reference */
635
- destroy() {
636
- this._unbindEvents(), this._listeners.length = 0, delete this.el;
637
- }
638
- }
639
- p.InputMask = wt;
640
- class c {
641
- /** Inserted symbols */
642
- /** Additional offset if any changes occurred before tail */
643
- /** Raw inserted is used by dynamic mask */
644
- /** Can skip chars */
645
- static normalize(t) {
646
- return Array.isArray(t) ? t : [t, new c()];
647
- }
648
- constructor(t) {
649
- Object.assign(this, {
650
- inserted: "",
651
- rawInserted: "",
652
- tailShift: 0,
653
- skip: !1
654
- }, t);
655
- }
656
- /** Aggregate changes */
657
- aggregate(t) {
658
- return this.inserted += t.inserted, this.rawInserted += t.rawInserted, this.tailShift += t.tailShift, this.skip = this.skip || t.skip, this;
659
- }
660
- /** Total offset considering all changes */
661
- get offset() {
662
- return this.tailShift + this.inserted.length;
663
- }
664
- get consumed() {
665
- return !!this.rawInserted || this.skip;
666
- }
667
- equals(t) {
668
- return this.inserted === t.inserted && this.tailShift === t.tailShift && this.rawInserted === t.rawInserted && this.skip === t.skip;
669
- }
670
- }
671
- p.ChangeDetails = c;
672
- class F {
673
- /** Tail value as string */
674
- /** Tail start position */
675
- /** Start position */
676
- constructor(t, e, s) {
677
- t === void 0 && (t = ""), e === void 0 && (e = 0), this.value = t, this.from = e, this.stop = s;
678
- }
679
- toString() {
680
- return this.value;
681
- }
682
- extend(t) {
683
- this.value += String(t);
684
- }
685
- appendTo(t) {
686
- return t.append(this.toString(), {
687
- tail: !0
688
- }).aggregate(t._appendPlaceholder());
689
- }
690
- get state() {
691
- return {
692
- value: this.value,
693
- from: this.from,
694
- stop: this.stop
695
- };
696
- }
697
- set state(t) {
698
- Object.assign(this, t);
699
- }
700
- unshift(t) {
701
- if (!this.value.length || t != null && this.from >= t)
702
- return "";
703
- const e = this.value[0];
704
- return this.value = this.value.slice(1), e;
705
- }
706
- shift() {
707
- if (!this.value.length)
708
- return "";
709
- const t = this.value[this.value.length - 1];
710
- return this.value = this.value.slice(0, -1), t;
711
- }
712
- }
713
- class _ {
714
- /** */
715
- /** */
716
- /** Transforms value before mask processing */
717
- /** Transforms each char before mask processing */
718
- /** Validates if value is acceptable */
719
- /** Does additional processing at the end of editing */
720
- /** Format typed value to string */
721
- /** Parse string to get typed value */
722
- /** Enable characters overwriting */
723
- /** */
724
- /** */
725
- /** */
726
- /** */
727
- constructor(t) {
728
- this._value = "", this._update({
729
- ..._.DEFAULTS,
730
- ...t
731
- }), this._initialized = !0;
732
- }
733
- /** Sets and applies new options */
734
- updateOptions(t) {
735
- this.optionsIsChanged(t) && this.withValueRefresh(this._update.bind(this, t));
736
- }
737
- /** Sets new options */
738
- _update(t) {
739
- Object.assign(this, t);
740
- }
741
- /** Mask state */
742
- get state() {
743
- return {
744
- _value: this.value,
745
- _rawInputValue: this.rawInputValue
746
- };
747
- }
748
- set state(t) {
749
- this._value = t._value;
750
- }
751
- /** Resets value */
752
- reset() {
753
- this._value = "";
754
- }
755
- get value() {
756
- return this._value;
757
- }
758
- set value(t) {
759
- this.resolve(t, {
760
- input: !0
761
- });
762
- }
763
- /** Resolve new value */
764
- resolve(t, e) {
765
- e === void 0 && (e = {
766
- input: !0
767
- }), this.reset(), this.append(t, e, ""), this.doCommit();
768
- }
769
- get unmaskedValue() {
770
- return this.value;
771
- }
772
- set unmaskedValue(t) {
773
- this.resolve(t, {});
774
- }
775
- get typedValue() {
776
- return this.parse ? this.parse(this.value, this) : this.unmaskedValue;
777
- }
778
- set typedValue(t) {
779
- this.format ? this.value = this.format(t, this) : this.unmaskedValue = String(t);
780
- }
781
- /** Value that includes raw user input */
782
- get rawInputValue() {
783
- return this.extractInput(0, this.displayValue.length, {
784
- raw: !0
785
- });
786
- }
787
- set rawInputValue(t) {
788
- this.resolve(t, {
789
- raw: !0
790
- });
791
- }
792
- get displayValue() {
793
- return this.value;
794
- }
795
- get isComplete() {
796
- return !0;
797
- }
798
- get isFilled() {
799
- return this.isComplete;
800
- }
801
- /** Finds nearest input position in direction */
802
- nearestInputPos(t, e) {
803
- return t;
804
- }
805
- totalInputPositions(t, e) {
806
- return t === void 0 && (t = 0), e === void 0 && (e = this.displayValue.length), Math.min(this.displayValue.length, e - t);
807
- }
808
- /** Extracts value in range considering flags */
809
- extractInput(t, e, s) {
810
- return t === void 0 && (t = 0), e === void 0 && (e = this.displayValue.length), this.displayValue.slice(t, e);
811
- }
812
- /** Extracts tail in range */
813
- extractTail(t, e) {
814
- return t === void 0 && (t = 0), e === void 0 && (e = this.displayValue.length), new F(this.extractInput(t, e), t);
815
- }
816
- /** Appends tail */
817
- appendTail(t) {
818
- return S(t) && (t = new F(String(t))), t.appendTo(this);
819
- }
820
- /** Appends char */
821
- _appendCharRaw(t, e) {
822
- return t ? (this._value += t, new c({
823
- inserted: t,
824
- rawInserted: t
825
- })) : new c();
826
- }
827
- /** Appends char */
828
- _appendChar(t, e, s) {
829
- e === void 0 && (e = {});
830
- const i = this.state;
831
- let a;
832
- if ([t, a] = this.doPrepareChar(t, e), t && (a = a.aggregate(this._appendCharRaw(t, e)), !a.rawInserted && this.autofix === "pad")) {
833
- const n = this.state;
834
- this.state = i;
835
- let r = this.pad(e);
836
- const l = this._appendCharRaw(t, e);
837
- r = r.aggregate(l), l.rawInserted || r.equals(a) ? a = r : this.state = n;
838
- }
839
- if (a.inserted) {
840
- let n, r = this.doValidate(e) !== !1;
841
- if (r && s != null) {
842
- const l = this.state;
843
- if (this.overwrite === !0) {
844
- n = s.state;
845
- for (let d = 0; d < a.rawInserted.length; ++d)
846
- s.unshift(this.displayValue.length - a.tailShift);
847
- }
848
- let o = this.appendTail(s);
849
- if (r = o.rawInserted.length === s.toString().length, !(r && o.inserted) && this.overwrite === "shift") {
850
- this.state = l, n = s.state;
851
- for (let d = 0; d < a.rawInserted.length; ++d)
852
- s.shift();
853
- o = this.appendTail(s), r = o.rawInserted.length === s.toString().length;
854
- }
855
- r && o.inserted && (this.state = l);
856
- }
857
- r || (a = new c(), this.state = i, s && n && (s.state = n));
858
- }
859
- return a;
860
- }
861
- /** Appends optional placeholder at the end */
862
- _appendPlaceholder() {
863
- return new c();
864
- }
865
- /** Appends optional eager placeholder at the end */
866
- _appendEager() {
867
- return new c();
868
- }
869
- /** Appends symbols considering flags */
870
- append(t, e, s) {
871
- if (!S(t))
872
- throw new Error("value should be string");
873
- const i = S(s) ? new F(String(s)) : s;
874
- e != null && e.tail && (e._beforeTailState = this.state);
875
- let a;
876
- [t, a] = this.doPrepare(t, e);
877
- for (let n = 0; n < t.length; ++n) {
878
- const r = this._appendChar(t[n], e, i);
879
- if (!r.rawInserted && !this.doSkipInvalid(t[n], e, i))
880
- break;
881
- a.aggregate(r);
882
- }
883
- return (this.eager === !0 || this.eager === "append") && e != null && e.input && t && a.aggregate(this._appendEager()), i != null && (a.tailShift += this.appendTail(i).tailShift), a;
884
- }
885
- remove(t, e) {
886
- return t === void 0 && (t = 0), e === void 0 && (e = this.displayValue.length), this._value = this.displayValue.slice(0, t) + this.displayValue.slice(e), new c();
887
- }
888
- /** Calls function and reapplies current value */
889
- withValueRefresh(t) {
890
- if (this._refreshing || !this._initialized)
891
- return t();
892
- this._refreshing = !0;
893
- const e = this.rawInputValue, s = this.value, i = t();
894
- return this.rawInputValue = e, this.value && this.value !== s && s.indexOf(this.value) === 0 && (this.append(s.slice(this.displayValue.length), {}, ""), this.doCommit()), delete this._refreshing, i;
895
- }
896
- runIsolated(t) {
897
- if (this._isolated || !this._initialized)
898
- return t(this);
899
- this._isolated = !0;
900
- const e = this.state, s = t(this);
901
- return this.state = e, delete this._isolated, s;
902
- }
903
- doSkipInvalid(t, e, s) {
904
- return !!this.skipInvalid;
905
- }
906
- /** Prepares string before mask processing */
907
- doPrepare(t, e) {
908
- return e === void 0 && (e = {}), c.normalize(this.prepare ? this.prepare(t, this, e) : t);
909
- }
910
- /** Prepares each char before mask processing */
911
- doPrepareChar(t, e) {
912
- return e === void 0 && (e = {}), c.normalize(this.prepareChar ? this.prepareChar(t, this, e) : t);
913
- }
914
- /** Validates if value is acceptable */
915
- doValidate(t) {
916
- return (!this.validate || this.validate(this.value, this, t)) && (!this.parent || this.parent.doValidate(t));
917
- }
918
- /** Does additional processing at the end of editing */
919
- doCommit() {
920
- this.commit && this.commit(this.value, this);
921
- }
922
- splice(t, e, s, i, a) {
923
- s === void 0 && (s = ""), i === void 0 && (i = h.NONE), a === void 0 && (a = {
924
- input: !0
925
- });
926
- const n = t + e, r = this.extractTail(n), l = this.eager === !0 || this.eager === "remove";
927
- let o;
928
- l && (i = Vt(i), o = this.extractInput(0, n, {
929
- raw: !0
930
- }));
931
- let d = t;
932
- const f = new c();
933
- if (i !== h.NONE && (d = this.nearestInputPos(t, e > 1 && t !== 0 && !l ? h.NONE : i), f.tailShift = d - t), f.aggregate(this.remove(d)), l && i !== h.NONE && o === this.rawInputValue)
934
- if (i === h.FORCE_LEFT) {
935
- let m;
936
- for (; o === this.rawInputValue && (m = this.displayValue.length); )
937
- f.aggregate(new c({
938
- tailShift: -1
939
- })).aggregate(this.remove(m - 1));
940
- } else
941
- i === h.FORCE_RIGHT && r.unshift();
942
- return f.aggregate(this.append(s, a, r));
943
- }
944
- maskEquals(t) {
945
- return this.mask === t;
946
- }
947
- optionsIsChanged(t) {
948
- return !L(this, t);
949
- }
950
- typedValueEquals(t) {
951
- const e = this.typedValue;
952
- return t === e || _.EMPTY_VALUES.includes(t) && _.EMPTY_VALUES.includes(e) || (this.format ? this.format(t, this) === this.format(this.typedValue, this) : !1);
953
- }
954
- pad(t) {
955
- return new c();
956
- }
957
- }
958
- _.DEFAULTS = {
959
- skipInvalid: !0
960
- };
961
- _.EMPTY_VALUES = [void 0, null, ""];
962
- p.Masked = _;
963
- class V {
964
- /** */
965
- constructor(t, e) {
966
- t === void 0 && (t = []), e === void 0 && (e = 0), this.chunks = t, this.from = e;
967
- }
968
- toString() {
969
- return this.chunks.map(String).join("");
970
- }
971
- extend(t) {
972
- if (!String(t))
973
- return;
974
- t = S(t) ? new F(String(t)) : t;
975
- const e = this.chunks[this.chunks.length - 1], s = e && // if stops are same or tail has no stop
976
- (e.stop === t.stop || t.stop == null) && // if tail chunk goes just after last chunk
977
- t.from === e.from + e.toString().length;
978
- if (t instanceof F)
979
- s ? e.extend(t.toString()) : this.chunks.push(t);
980
- else if (t instanceof V) {
981
- if (t.stop == null) {
982
- let i;
983
- for (; t.chunks.length && t.chunks[0].stop == null; )
984
- i = t.chunks.shift(), i.from += t.from, this.extend(i);
985
- }
986
- t.toString() && (t.stop = t.blockIndex, this.chunks.push(t));
987
- }
988
- }
989
- appendTo(t) {
990
- if (!(t instanceof p.MaskedPattern))
991
- return new F(this.toString()).appendTo(t);
992
- const e = new c();
993
- for (let s = 0; s < this.chunks.length; ++s) {
994
- const i = this.chunks[s], a = t._mapPosToBlock(t.displayValue.length), n = i.stop;
995
- let r;
996
- if (n != null && // if block not found or stop is behind lastBlock
997
- (!a || a.index <= n) && ((i instanceof V || // for continuous block also check if stop is exist
998
- t._stops.indexOf(n) >= 0) && e.aggregate(t._appendPlaceholder(n)), r = i instanceof V && t._blocks[n]), r) {
999
- const l = r.appendTail(i);
1000
- e.aggregate(l);
1001
- const o = i.toString().slice(l.rawInserted.length);
1002
- o && e.aggregate(t.append(o, {
1003
- tail: !0
1004
- }));
1005
- } else
1006
- e.aggregate(t.append(i.toString(), {
1007
- tail: !0
1008
- }));
1009
- }
1010
- return e;
1011
- }
1012
- get state() {
1013
- return {
1014
- chunks: this.chunks.map((t) => t.state),
1015
- from: this.from,
1016
- stop: this.stop,
1017
- blockIndex: this.blockIndex
1018
- };
1019
- }
1020
- set state(t) {
1021
- const {
1022
- chunks: e,
1023
- ...s
1024
- } = t;
1025
- Object.assign(this, s), this.chunks = e.map((i) => {
1026
- const a = "chunks" in i ? new V() : new F();
1027
- return a.state = i, a;
1028
- });
1029
- }
1030
- unshift(t) {
1031
- if (!this.chunks.length || t != null && this.from >= t)
1032
- return "";
1033
- const e = t != null ? t - this.from : t;
1034
- let s = 0;
1035
- for (; s < this.chunks.length; ) {
1036
- const i = this.chunks[s], a = i.unshift(e);
1037
- if (i.toString()) {
1038
- if (!a)
1039
- break;
1040
- ++s;
1041
- } else
1042
- this.chunks.splice(s, 1);
1043
- if (a)
1044
- return a;
1045
- }
1046
- return "";
1047
- }
1048
- shift() {
1049
- if (!this.chunks.length)
1050
- return "";
1051
- let t = this.chunks.length - 1;
1052
- for (; 0 <= t; ) {
1053
- const e = this.chunks[t], s = e.shift();
1054
- if (e.toString()) {
1055
- if (!s)
1056
- break;
1057
- --t;
1058
- } else
1059
- this.chunks.splice(t, 1);
1060
- if (s)
1061
- return s;
1062
- }
1063
- return "";
1064
- }
1065
- }
1066
- class Tt {
1067
- constructor(t, e) {
1068
- this.masked = t, this._log = [];
1069
- const {
1070
- offset: s,
1071
- index: i
1072
- } = t._mapPosToBlock(e) || (e < 0 ? (
1073
- // first
1074
- {
1075
- index: 0,
1076
- offset: 0
1077
- }
1078
- ) : (
1079
- // last
1080
- {
1081
- index: this.masked._blocks.length,
1082
- offset: 0
1083
- }
1084
- ));
1085
- this.offset = s, this.index = i, this.ok = !1;
1086
- }
1087
- get block() {
1088
- return this.masked._blocks[this.index];
1089
- }
1090
- get pos() {
1091
- return this.masked._blockStartPos(this.index) + this.offset;
1092
- }
1093
- get state() {
1094
- return {
1095
- index: this.index,
1096
- offset: this.offset,
1097
- ok: this.ok
1098
- };
1099
- }
1100
- set state(t) {
1101
- Object.assign(this, t);
1102
- }
1103
- pushState() {
1104
- this._log.push(this.state);
1105
- }
1106
- popState() {
1107
- const t = this._log.pop();
1108
- return t && (this.state = t), t;
1109
- }
1110
- bindBlock() {
1111
- this.block || (this.index < 0 && (this.index = 0, this.offset = 0), this.index >= this.masked._blocks.length && (this.index = this.masked._blocks.length - 1, this.offset = this.block.displayValue.length));
1112
- }
1113
- _pushLeft(t) {
1114
- for (this.pushState(), this.bindBlock(); 0 <= this.index; --this.index, this.offset = ((e = this.block) == null ? void 0 : e.displayValue.length) || 0) {
1115
- var e;
1116
- if (t())
1117
- return this.ok = !0;
1118
- }
1119
- return this.ok = !1;
1120
- }
1121
- _pushRight(t) {
1122
- for (this.pushState(), this.bindBlock(); this.index < this.masked._blocks.length; ++this.index, this.offset = 0)
1123
- if (t())
1124
- return this.ok = !0;
1125
- return this.ok = !1;
1126
- }
1127
- pushLeftBeforeFilled() {
1128
- return this._pushLeft(() => {
1129
- if (!(this.block.isFixed || !this.block.value) && (this.offset = this.block.nearestInputPos(this.offset, h.FORCE_LEFT), this.offset !== 0))
1130
- return !0;
1131
- });
1132
- }
1133
- pushLeftBeforeInput() {
1134
- return this._pushLeft(() => {
1135
- if (!this.block.isFixed)
1136
- return this.offset = this.block.nearestInputPos(this.offset, h.LEFT), !0;
1137
- });
1138
- }
1139
- pushLeftBeforeRequired() {
1140
- return this._pushLeft(() => {
1141
- if (!(this.block.isFixed || this.block.isOptional && !this.block.value))
1142
- return this.offset = this.block.nearestInputPos(this.offset, h.LEFT), !0;
1143
- });
1144
- }
1145
- pushRightBeforeFilled() {
1146
- return this._pushRight(() => {
1147
- if (!(this.block.isFixed || !this.block.value) && (this.offset = this.block.nearestInputPos(this.offset, h.FORCE_RIGHT), this.offset !== this.block.value.length))
1148
- return !0;
1149
- });
1150
- }
1151
- pushRightBeforeInput() {
1152
- return this._pushRight(() => {
1153
- if (!this.block.isFixed)
1154
- return this.offset = this.block.nearestInputPos(this.offset, h.NONE), !0;
1155
- });
1156
- }
1157
- pushRightBeforeRequired() {
1158
- return this._pushRight(() => {
1159
- if (!(this.block.isFixed || this.block.isOptional && !this.block.value))
1160
- return this.offset = this.block.nearestInputPos(this.offset, h.NONE), !0;
1161
- });
1162
- }
1163
- }
1164
- class ht {
1165
- /** */
1166
- /** */
1167
- /** */
1168
- /** */
1169
- /** */
1170
- /** */
1171
- constructor(t) {
1172
- Object.assign(this, t), this._value = "", this.isFixed = !0;
1173
- }
1174
- get value() {
1175
- return this._value;
1176
- }
1177
- get unmaskedValue() {
1178
- return this.isUnmasking ? this.value : "";
1179
- }
1180
- get rawInputValue() {
1181
- return this._isRawInput ? this.value : "";
1182
- }
1183
- get displayValue() {
1184
- return this.value;
1185
- }
1186
- reset() {
1187
- this._isRawInput = !1, this._value = "";
1188
- }
1189
- remove(t, e) {
1190
- return t === void 0 && (t = 0), e === void 0 && (e = this._value.length), this._value = this._value.slice(0, t) + this._value.slice(e), this._value || (this._isRawInput = !1), new c();
1191
- }
1192
- nearestInputPos(t, e) {
1193
- e === void 0 && (e = h.NONE);
1194
- const s = 0, i = this._value.length;
1195
- switch (e) {
1196
- case h.LEFT:
1197
- case h.FORCE_LEFT:
1198
- return s;
1199
- case h.NONE:
1200
- case h.RIGHT:
1201
- case h.FORCE_RIGHT:
1202
- default:
1203
- return i;
1204
- }
1205
- }
1206
- totalInputPositions(t, e) {
1207
- return t === void 0 && (t = 0), e === void 0 && (e = this._value.length), this._isRawInput ? e - t : 0;
1208
- }
1209
- extractInput(t, e, s) {
1210
- return t === void 0 && (t = 0), e === void 0 && (e = this._value.length), s === void 0 && (s = {}), s.raw && this._isRawInput && this._value.slice(t, e) || "";
1211
- }
1212
- get isComplete() {
1213
- return !0;
1214
- }
1215
- get isFilled() {
1216
- return !!this._value;
1217
- }
1218
- _appendChar(t, e) {
1219
- if (e === void 0 && (e = {}), this.isFilled)
1220
- return new c();
1221
- const s = this.eager === !0 || this.eager === "append", a = this.char === t && (this.isUnmasking || e.input || e.raw) && (!e.raw || !s) && !e.tail, n = new c({
1222
- inserted: this.char,
1223
- rawInserted: a ? this.char : ""
1224
- });
1225
- return this._value = this.char, this._isRawInput = a && (e.raw || e.input), n;
1226
- }
1227
- _appendEager() {
1228
- return this._appendChar(this.char, {
1229
- tail: !0
1230
- });
1231
- }
1232
- _appendPlaceholder() {
1233
- const t = new c();
1234
- return this.isFilled || (this._value = t.inserted = this.char), t;
1235
- }
1236
- extractTail() {
1237
- return new F("");
1238
- }
1239
- appendTail(t) {
1240
- return S(t) && (t = new F(String(t))), t.appendTo(this);
1241
- }
1242
- append(t, e, s) {
1243
- const i = this._appendChar(t[0], e);
1244
- return s != null && (i.tailShift += this.appendTail(s).tailShift), i;
1245
- }
1246
- doCommit() {
1247
- }
1248
- get state() {
1249
- return {
1250
- _value: this._value,
1251
- _rawInputValue: this.rawInputValue
1252
- };
1253
- }
1254
- set state(t) {
1255
- this._value = t._value, this._isRawInput = !!t._rawInputValue;
1256
- }
1257
- pad(t) {
1258
- return this._appendPlaceholder();
1259
- }
1260
- }
1261
- class N {
1262
- /** */
1263
- /** */
1264
- /** */
1265
- /** */
1266
- /** */
1267
- /** */
1268
- /** */
1269
- /** */
1270
- constructor(t) {
1271
- const {
1272
- parent: e,
1273
- isOptional: s,
1274
- placeholderChar: i,
1275
- displayChar: a,
1276
- lazy: n,
1277
- eager: r,
1278
- ...l
1279
- } = t;
1280
- this.masked = y(l), Object.assign(this, {
1281
- parent: e,
1282
- isOptional: s,
1283
- placeholderChar: i,
1284
- displayChar: a,
1285
- lazy: n,
1286
- eager: r
1287
- });
1288
- }
1289
- reset() {
1290
- this.isFilled = !1, this.masked.reset();
1291
- }
1292
- remove(t, e) {
1293
- return t === void 0 && (t = 0), e === void 0 && (e = this.value.length), t === 0 && e >= 1 ? (this.isFilled = !1, this.masked.remove(t, e)) : new c();
1294
- }
1295
- get value() {
1296
- return this.masked.value || (this.isFilled && !this.isOptional ? this.placeholderChar : "");
1297
- }
1298
- get unmaskedValue() {
1299
- return this.masked.unmaskedValue;
1300
- }
1301
- get rawInputValue() {
1302
- return this.masked.rawInputValue;
1303
- }
1304
- get displayValue() {
1305
- return this.masked.value && this.displayChar || this.value;
1306
- }
1307
- get isComplete() {
1308
- return !!this.masked.value || this.isOptional;
1309
- }
1310
- _appendChar(t, e) {
1311
- if (e === void 0 && (e = {}), this.isFilled)
1312
- return new c();
1313
- const s = this.masked.state;
1314
- let i = this.masked._appendChar(t, this.currentMaskFlags(e));
1315
- return i.inserted && this.doValidate(e) === !1 && (i = new c(), this.masked.state = s), !i.inserted && !this.isOptional && !this.lazy && !e.input && (i.inserted = this.placeholderChar), i.skip = !i.inserted && !this.isOptional, this.isFilled = !!i.inserted, i;
1316
- }
1317
- append(t, e, s) {
1318
- return this.masked.append(t, this.currentMaskFlags(e), s);
1319
- }
1320
- _appendPlaceholder() {
1321
- return this.isFilled || this.isOptional ? new c() : (this.isFilled = !0, new c({
1322
- inserted: this.placeholderChar
1323
- }));
1324
- }
1325
- _appendEager() {
1326
- return new c();
1327
- }
1328
- extractTail(t, e) {
1329
- return this.masked.extractTail(t, e);
1330
- }
1331
- appendTail(t) {
1332
- return this.masked.appendTail(t);
1333
- }
1334
- extractInput(t, e, s) {
1335
- return t === void 0 && (t = 0), e === void 0 && (e = this.value.length), this.masked.extractInput(t, e, s);
1336
- }
1337
- nearestInputPos(t, e) {
1338
- e === void 0 && (e = h.NONE);
1339
- const s = 0, i = this.value.length, a = Math.min(Math.max(t, s), i);
1340
- switch (e) {
1341
- case h.LEFT:
1342
- case h.FORCE_LEFT:
1343
- return this.isComplete ? a : s;
1344
- case h.RIGHT:
1345
- case h.FORCE_RIGHT:
1346
- return this.isComplete ? a : i;
1347
- case h.NONE:
1348
- default:
1349
- return a;
1350
- }
1351
- }
1352
- totalInputPositions(t, e) {
1353
- return t === void 0 && (t = 0), e === void 0 && (e = this.value.length), this.value.slice(t, e).length;
1354
- }
1355
- doValidate(t) {
1356
- return this.masked.doValidate(this.currentMaskFlags(t)) && (!this.parent || this.parent.doValidate(this.currentMaskFlags(t)));
1357
- }
1358
- doCommit() {
1359
- this.masked.doCommit();
1360
- }
1361
- get state() {
1362
- return {
1363
- _value: this.value,
1364
- _rawInputValue: this.rawInputValue,
1365
- masked: this.masked.state,
1366
- isFilled: this.isFilled
1367
- };
1368
- }
1369
- set state(t) {
1370
- this.masked.state = t.masked, this.isFilled = t.isFilled;
1371
- }
1372
- currentMaskFlags(t) {
1373
- var e;
1374
- return {
1375
- ...t,
1376
- _beforeTailState: (t == null || (e = t._beforeTailState) == null ? void 0 : e.masked) || (t == null ? void 0 : t._beforeTailState)
1377
- };
1378
- }
1379
- pad(t) {
1380
- return new c();
1381
- }
1382
- }
1383
- N.DEFAULT_DEFINITIONS = {
1384
- 0: /\d/,
1385
- a: /[\u0041-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]/,
1386
- // http://stackoverflow.com/a/22075070
1387
- "*": /./
1388
- };
1389
- class Rt extends _ {
1390
- /** */
1391
- /** Enable characters overwriting */
1392
- /** */
1393
- /** */
1394
- /** */
1395
- updateOptions(t) {
1396
- super.updateOptions(t);
1397
- }
1398
- _update(t) {
1399
- const e = t.mask;
1400
- e && (t.validate = (s) => s.search(e) >= 0), super._update(t);
1401
- }
1402
- }
1403
- p.MaskedRegExp = Rt;
1404
- class v extends _ {
1405
- /** */
1406
- /** */
1407
- /** Single char for empty input */
1408
- /** Single char for filled input */
1409
- /** Show placeholder only when needed */
1410
- /** Enable characters overwriting */
1411
- /** */
1412
- /** */
1413
- /** */
1414
- constructor(t) {
1415
- super({
1416
- ...v.DEFAULTS,
1417
- ...t,
1418
- definitions: Object.assign({}, N.DEFAULT_DEFINITIONS, t == null ? void 0 : t.definitions)
1419
- });
1420
- }
1421
- updateOptions(t) {
1422
- super.updateOptions(t);
1423
- }
1424
- _update(t) {
1425
- t.definitions = Object.assign({}, this.definitions, t.definitions), super._update(t), this._rebuildMask();
1426
- }
1427
- _rebuildMask() {
1428
- const t = this.definitions;
1429
- this._blocks = [], this.exposeBlock = void 0, this._stops = [], this._maskedBlocks = {};
1430
- const e = this.mask;
1431
- if (!e || !t)
1432
- return;
1433
- let s = !1, i = !1;
1434
- for (let a = 0; a < e.length; ++a) {
1435
- if (this.blocks) {
1436
- const o = e.slice(a), d = Object.keys(this.blocks).filter((m) => o.indexOf(m) === 0);
1437
- d.sort((m, k) => k.length - m.length);
1438
- const f = d[0];
1439
- if (f) {
1440
- const {
1441
- expose: m,
1442
- repeat: k,
1443
- ...E
1444
- } = w(this.blocks[f]), I = {
1445
- lazy: this.lazy,
1446
- eager: this.eager,
1447
- placeholderChar: this.placeholderChar,
1448
- displayChar: this.displayChar,
1449
- overwrite: this.overwrite,
1450
- autofix: this.autofix,
1451
- ...E,
1452
- repeat: k,
1453
- parent: this
1454
- }, B = k != null ? new p.RepeatBlock(
1455
- I
1456
- /* TODO */
1457
- ) : y(I);
1458
- B && (this._blocks.push(B), m && (this.exposeBlock = B), this._maskedBlocks[f] || (this._maskedBlocks[f] = []), this._maskedBlocks[f].push(this._blocks.length - 1)), a += f.length - 1;
1459
- continue;
1460
- }
1461
- }
1462
- let n = e[a], r = n in t;
1463
- if (n === v.STOP_CHAR) {
1464
- this._stops.push(this._blocks.length);
1465
- continue;
1466
- }
1467
- if (n === "{" || n === "}") {
1468
- s = !s;
1469
- continue;
1470
- }
1471
- if (n === "[" || n === "]") {
1472
- i = !i;
1473
- continue;
1474
- }
1475
- if (n === v.ESCAPE_CHAR) {
1476
- if (++a, n = e[a], !n)
1477
- break;
1478
- r = !1;
1479
- }
1480
- const l = r ? new N({
1481
- isOptional: i,
1482
- lazy: this.lazy,
1483
- eager: this.eager,
1484
- placeholderChar: this.placeholderChar,
1485
- displayChar: this.displayChar,
1486
- ...w(t[n]),
1487
- parent: this
1488
- }) : new ht({
1489
- char: n,
1490
- eager: this.eager,
1491
- isUnmasking: s
1492
- });
1493
- this._blocks.push(l);
1494
- }
1495
- }
1496
- get state() {
1497
- return {
1498
- ...super.state,
1499
- _blocks: this._blocks.map((t) => t.state)
1500
- };
1501
- }
1502
- set state(t) {
1503
- if (!t) {
1504
- this.reset();
1505
- return;
1506
- }
1507
- const {
1508
- _blocks: e,
1509
- ...s
1510
- } = t;
1511
- this._blocks.forEach((i, a) => i.state = e[a]), super.state = s;
1512
- }
1513
- reset() {
1514
- super.reset(), this._blocks.forEach((t) => t.reset());
1515
- }
1516
- get isComplete() {
1517
- return this.exposeBlock ? this.exposeBlock.isComplete : this._blocks.every((t) => t.isComplete);
1518
- }
1519
- get isFilled() {
1520
- return this._blocks.every((t) => t.isFilled);
1521
- }
1522
- get isFixed() {
1523
- return this._blocks.every((t) => t.isFixed);
1524
- }
1525
- get isOptional() {
1526
- return this._blocks.every((t) => t.isOptional);
1527
- }
1528
- doCommit() {
1529
- this._blocks.forEach((t) => t.doCommit()), super.doCommit();
1530
- }
1531
- get unmaskedValue() {
1532
- return this.exposeBlock ? this.exposeBlock.unmaskedValue : this._blocks.reduce((t, e) => t += e.unmaskedValue, "");
1533
- }
1534
- set unmaskedValue(t) {
1535
- if (this.exposeBlock) {
1536
- const e = this.extractTail(this._blockStartPos(this._blocks.indexOf(this.exposeBlock)) + this.exposeBlock.displayValue.length);
1537
- this.exposeBlock.unmaskedValue = t, this.appendTail(e), this.doCommit();
1538
- } else
1539
- super.unmaskedValue = t;
1540
- }
1541
- get value() {
1542
- return this.exposeBlock ? this.exposeBlock.value : (
1543
- // TODO return _value when not in change?
1544
- this._blocks.reduce((t, e) => t += e.value, "")
1545
- );
1546
- }
1547
- set value(t) {
1548
- if (this.exposeBlock) {
1549
- const e = this.extractTail(this._blockStartPos(this._blocks.indexOf(this.exposeBlock)) + this.exposeBlock.displayValue.length);
1550
- this.exposeBlock.value = t, this.appendTail(e), this.doCommit();
1551
- } else
1552
- super.value = t;
1553
- }
1554
- get typedValue() {
1555
- return this.exposeBlock ? this.exposeBlock.typedValue : super.typedValue;
1556
- }
1557
- set typedValue(t) {
1558
- if (this.exposeBlock) {
1559
- const e = this.extractTail(this._blockStartPos(this._blocks.indexOf(this.exposeBlock)) + this.exposeBlock.displayValue.length);
1560
- this.exposeBlock.typedValue = t, this.appendTail(e), this.doCommit();
1561
- } else
1562
- super.typedValue = t;
1563
- }
1564
- get displayValue() {
1565
- return this._blocks.reduce((t, e) => t += e.displayValue, "");
1566
- }
1567
- appendTail(t) {
1568
- return super.appendTail(t).aggregate(this._appendPlaceholder());
1569
- }
1570
- _appendEager() {
1571
- var t;
1572
- const e = new c();
1573
- let s = (t = this._mapPosToBlock(this.displayValue.length)) == null ? void 0 : t.index;
1574
- if (s == null)
1575
- return e;
1576
- this._blocks[s].isFilled && ++s;
1577
- for (let i = s; i < this._blocks.length; ++i) {
1578
- const a = this._blocks[i]._appendEager();
1579
- if (!a.inserted)
1580
- break;
1581
- e.aggregate(a);
1582
- }
1583
- return e;
1584
- }
1585
- _appendCharRaw(t, e) {
1586
- e === void 0 && (e = {});
1587
- const s = this._mapPosToBlock(this.displayValue.length), i = new c();
1588
- if (!s)
1589
- return i;
1590
- for (let n = s.index, r; r = this._blocks[n]; ++n) {
1591
- var a;
1592
- const l = r._appendChar(t, {
1593
- ...e,
1594
- _beforeTailState: (a = e._beforeTailState) == null || (a = a._blocks) == null ? void 0 : a[n]
1595
- });
1596
- if (i.aggregate(l), l.consumed)
1597
- break;
1598
- }
1599
- return i;
1600
- }
1601
- extractTail(t, e) {
1602
- t === void 0 && (t = 0), e === void 0 && (e = this.displayValue.length);
1603
- const s = new V();
1604
- return t === e || this._forEachBlocksInRange(t, e, (i, a, n, r) => {
1605
- const l = i.extractTail(n, r);
1606
- l.stop = this._findStopBefore(a), l.from = this._blockStartPos(a), l instanceof V && (l.blockIndex = a), s.extend(l);
1607
- }), s;
1608
- }
1609
- extractInput(t, e, s) {
1610
- if (t === void 0 && (t = 0), e === void 0 && (e = this.displayValue.length), s === void 0 && (s = {}), t === e)
1611
- return "";
1612
- let i = "";
1613
- return this._forEachBlocksInRange(t, e, (a, n, r, l) => {
1614
- i += a.extractInput(r, l, s);
1615
- }), i;
1616
- }
1617
- _findStopBefore(t) {
1618
- let e;
1619
- for (let s = 0; s < this._stops.length; ++s) {
1620
- const i = this._stops[s];
1621
- if (i <= t)
1622
- e = i;
1623
- else
1624
- break;
1625
- }
1626
- return e;
1627
- }
1628
- /** Appends placeholder depending on laziness */
1629
- _appendPlaceholder(t) {
1630
- const e = new c();
1631
- if (this.lazy && t == null)
1632
- return e;
1633
- const s = this._mapPosToBlock(this.displayValue.length);
1634
- if (!s)
1635
- return e;
1636
- const i = s.index, a = t ?? this._blocks.length;
1637
- return this._blocks.slice(i, a).forEach((n) => {
1638
- if (!n.lazy || t != null) {
1639
- var r;
1640
- e.aggregate(n._appendPlaceholder((r = n._blocks) == null ? void 0 : r.length));
1641
- }
1642
- }), e;
1643
- }
1644
- /** Finds block in pos */
1645
- _mapPosToBlock(t) {
1646
- let e = "";
1647
- for (let s = 0; s < this._blocks.length; ++s) {
1648
- const i = this._blocks[s], a = e.length;
1649
- if (e += i.displayValue, t <= e.length)
1650
- return {
1651
- index: s,
1652
- offset: t - a
1653
- };
1654
- }
1655
- }
1656
- _blockStartPos(t) {
1657
- return this._blocks.slice(0, t).reduce((e, s) => e += s.displayValue.length, 0);
1658
- }
1659
- _forEachBlocksInRange(t, e, s) {
1660
- e === void 0 && (e = this.displayValue.length);
1661
- const i = this._mapPosToBlock(t);
1662
- if (i) {
1663
- const a = this._mapPosToBlock(e), n = a && i.index === a.index, r = i.offset, l = a && n ? a.offset : this._blocks[i.index].displayValue.length;
1664
- if (s(this._blocks[i.index], i.index, r, l), a && !n) {
1665
- for (let o = i.index + 1; o < a.index; ++o)
1666
- s(this._blocks[o], o, 0, this._blocks[o].displayValue.length);
1667
- s(this._blocks[a.index], a.index, 0, a.offset);
1668
- }
1669
- }
1670
- }
1671
- remove(t, e) {
1672
- t === void 0 && (t = 0), e === void 0 && (e = this.displayValue.length);
1673
- const s = super.remove(t, e);
1674
- return this._forEachBlocksInRange(t, e, (i, a, n, r) => {
1675
- s.aggregate(i.remove(n, r));
1676
- }), s;
1677
- }
1678
- nearestInputPos(t, e) {
1679
- if (e === void 0 && (e = h.NONE), !this._blocks.length)
1680
- return 0;
1681
- const s = new Tt(this, t);
1682
- if (e === h.NONE)
1683
- return s.pushRightBeforeInput() || (s.popState(), s.pushLeftBeforeInput()) ? s.pos : this.displayValue.length;
1684
- if (e === h.LEFT || e === h.FORCE_LEFT) {
1685
- if (e === h.LEFT) {
1686
- if (s.pushRightBeforeFilled(), s.ok && s.pos === t)
1687
- return t;
1688
- s.popState();
1689
- }
1690
- if (s.pushLeftBeforeInput(), s.pushLeftBeforeRequired(), s.pushLeftBeforeFilled(), e === h.LEFT) {
1691
- if (s.pushRightBeforeInput(), s.pushRightBeforeRequired(), s.ok && s.pos <= t || (s.popState(), s.ok && s.pos <= t))
1692
- return s.pos;
1693
- s.popState();
1694
- }
1695
- return s.ok ? s.pos : e === h.FORCE_LEFT ? 0 : (s.popState(), s.ok || (s.popState(), s.ok) ? s.pos : 0);
1696
- }
1697
- return e === h.RIGHT || e === h.FORCE_RIGHT ? (s.pushRightBeforeInput(), s.pushRightBeforeRequired(), s.pushRightBeforeFilled() ? s.pos : e === h.FORCE_RIGHT ? this.displayValue.length : (s.popState(), s.ok || (s.popState(), s.ok) ? s.pos : this.nearestInputPos(t, h.LEFT))) : t;
1698
- }
1699
- totalInputPositions(t, e) {
1700
- t === void 0 && (t = 0), e === void 0 && (e = this.displayValue.length);
1701
- let s = 0;
1702
- return this._forEachBlocksInRange(t, e, (i, a, n, r) => {
1703
- s += i.totalInputPositions(n, r);
1704
- }), s;
1705
- }
1706
- /** Get block by name */
1707
- maskedBlock(t) {
1708
- return this.maskedBlocks(t)[0];
1709
- }
1710
- /** Get all blocks by name */
1711
- maskedBlocks(t) {
1712
- const e = this._maskedBlocks[t];
1713
- return e ? e.map((s) => this._blocks[s]) : [];
1714
- }
1715
- pad(t) {
1716
- const e = new c();
1717
- return this._forEachBlocksInRange(0, this.displayValue.length, (s) => e.aggregate(s.pad(t))), e;
1718
- }
1719
- }
1720
- v.DEFAULTS = {
1721
- ..._.DEFAULTS,
1722
- lazy: !0,
1723
- placeholderChar: "_"
1724
- };
1725
- v.STOP_CHAR = "`";
1726
- v.ESCAPE_CHAR = "\\";
1727
- v.InputDefinition = N;
1728
- v.FixedDefinition = ht;
1729
- p.MaskedPattern = v;
1730
- class O extends v {
1731
- /**
1732
- Optionally sets max length of pattern.
1733
- Used when pattern length is longer then `to` param length. Pads zeros at start in this case.
1734
- */
1735
- /** Min bound */
1736
- /** Max bound */
1737
- get _matchFrom() {
1738
- return this.maxLength - String(this.from).length;
1739
- }
1740
- constructor(t) {
1741
- super(t);
1742
- }
1743
- updateOptions(t) {
1744
- super.updateOptions(t);
1745
- }
1746
- _update(t) {
1747
- const {
1748
- to: e = this.to || 0,
1749
- from: s = this.from || 0,
1750
- maxLength: i = this.maxLength || 0,
1751
- autofix: a = this.autofix,
1752
- ...n
1753
- } = t;
1754
- this.to = e, this.from = s, this.maxLength = Math.max(String(e).length, i), this.autofix = a;
1755
- const r = String(this.from).padStart(this.maxLength, "0"), l = String(this.to).padStart(this.maxLength, "0");
1756
- let o = 0;
1757
- for (; o < l.length && l[o] === r[o]; )
1758
- ++o;
1759
- n.mask = l.slice(0, o).replace(/0/g, "\\0") + "0".repeat(this.maxLength - o), super._update(n);
1760
- }
1761
- get isComplete() {
1762
- return super.isComplete && !!this.value;
1763
- }
1764
- boundaries(t) {
1765
- let e = "", s = "";
1766
- const [, i, a] = t.match(/^(\D*)(\d*)(\D*)/) || [];
1767
- return a && (e = "0".repeat(i.length) + a, s = "9".repeat(i.length) + a), e = e.padEnd(this.maxLength, "0"), s = s.padEnd(this.maxLength, "9"), [e, s];
1768
- }
1769
- doPrepareChar(t, e) {
1770
- e === void 0 && (e = {});
1771
- let s;
1772
- return [t, s] = super.doPrepareChar(t.replace(/\D/g, ""), e), t || (s.skip = !this.isComplete), [t, s];
1773
- }
1774
- _appendCharRaw(t, e) {
1775
- if (e === void 0 && (e = {}), !this.autofix || this.value.length + 1 > this.maxLength)
1776
- return super._appendCharRaw(t, e);
1777
- const s = String(this.from).padStart(this.maxLength, "0"), i = String(this.to).padStart(this.maxLength, "0"), [a, n] = this.boundaries(this.value + t);
1778
- return Number(n) < this.from ? super._appendCharRaw(s[this.value.length], e) : Number(a) > this.to ? !e.tail && this.autofix === "pad" && this.value.length + 1 < this.maxLength ? super._appendCharRaw(s[this.value.length], e).aggregate(this._appendCharRaw(t, e)) : super._appendCharRaw(i[this.value.length], e) : super._appendCharRaw(t, e);
1779
- }
1780
- doValidate(t) {
1781
- const e = this.value;
1782
- if (e.search(/[^0]/) === -1 && e.length <= this._matchFrom)
1783
- return !0;
1784
- const [i, a] = this.boundaries(e);
1785
- return this.from <= Number(a) && Number(i) <= this.to && super.doValidate(t);
1786
- }
1787
- pad(t) {
1788
- const e = new c();
1789
- if (this.value.length === this.maxLength)
1790
- return e;
1791
- const s = this.value, i = this.maxLength - this.value.length;
1792
- if (i) {
1793
- this.reset();
1794
- for (let a = 0; a < i; ++a)
1795
- e.aggregate(super._appendCharRaw("0", t));
1796
- s.split("").forEach((a) => this._appendCharRaw(a));
1797
- }
1798
- return e;
1799
- }
1800
- }
1801
- p.MaskedRange = O;
1802
- class x extends v {
1803
- static extractPatternOptions(t) {
1804
- const {
1805
- mask: e,
1806
- pattern: s,
1807
- ...i
1808
- } = t;
1809
- return {
1810
- ...i,
1811
- mask: S(e) ? e : s
1812
- };
1813
- }
1814
- /** Pattern mask for date according to {@link MaskedDate#format} */
1815
- /** Start date */
1816
- /** End date */
1817
- /** Format typed value to string */
1818
- /** Parse string to get typed value */
1819
- constructor(t) {
1820
- super(x.extractPatternOptions({
1821
- ...x.DEFAULTS,
1822
- ...t
1823
- }));
1824
- }
1825
- updateOptions(t) {
1826
- super.updateOptions(t);
1827
- }
1828
- _update(t) {
1829
- const {
1830
- mask: e,
1831
- pattern: s,
1832
- blocks: i,
1833
- ...a
1834
- } = {
1835
- ...x.DEFAULTS,
1836
- ...t
1837
- }, n = Object.assign({}, x.GET_DEFAULT_BLOCKS());
1838
- t.min && (n.Y.from = t.min.getFullYear()), t.max && (n.Y.to = t.max.getFullYear()), t.min && t.max && n.Y.from === n.Y.to && (n.m.from = t.min.getMonth() + 1, n.m.to = t.max.getMonth() + 1, n.m.from === n.m.to && (n.d.from = t.min.getDate(), n.d.to = t.max.getDate())), Object.assign(n, this.blocks, i), super._update({
1839
- ...a,
1840
- mask: S(e) ? e : s,
1841
- blocks: n
1842
- });
1843
- }
1844
- doValidate(t) {
1845
- const e = this.date;
1846
- return super.doValidate(t) && (!this.isComplete || this.isDateExist(this.value) && e != null && (this.min == null || this.min <= e) && (this.max == null || e <= this.max));
1847
- }
1848
- /** Checks if date is exists */
1849
- isDateExist(t) {
1850
- return this.format(this.parse(t, this), this).indexOf(t) >= 0;
1851
- }
1852
- /** Parsed Date */
1853
- get date() {
1854
- return this.typedValue;
1855
- }
1856
- set date(t) {
1857
- this.typedValue = t;
1858
- }
1859
- get typedValue() {
1860
- return this.isComplete ? super.typedValue : null;
1861
- }
1862
- set typedValue(t) {
1863
- super.typedValue = t;
1864
- }
1865
- maskEquals(t) {
1866
- return t === Date || super.maskEquals(t);
1867
- }
1868
- optionsIsChanged(t) {
1869
- return super.optionsIsChanged(x.extractPatternOptions(t));
1870
- }
1871
- }
1872
- x.GET_DEFAULT_BLOCKS = () => ({
1873
- d: {
1874
- mask: O,
1875
- from: 1,
1876
- to: 31,
1877
- maxLength: 2
1878
- },
1879
- m: {
1880
- mask: O,
1881
- from: 1,
1882
- to: 12,
1883
- maxLength: 2
1884
- },
1885
- Y: {
1886
- mask: O,
1887
- from: 1900,
1888
- to: 9999
1889
- }
1890
- });
1891
- x.DEFAULTS = {
1892
- ...v.DEFAULTS,
1893
- mask: Date,
1894
- pattern: "d{.}`m{.}`Y",
1895
- format: (u, t) => {
1896
- if (!u)
1897
- return "";
1898
- const e = String(u.getDate()).padStart(2, "0"), s = String(u.getMonth() + 1).padStart(2, "0"), i = u.getFullYear();
1899
- return [e, s, i].join(".");
1900
- },
1901
- parse: (u, t) => {
1902
- const [e, s, i] = u.split(".").map(Number);
1903
- return new Date(i, s - 1, e);
1904
- }
1905
- };
1906
- p.MaskedDate = x;
1907
- class P extends _ {
1908
- constructor(t) {
1909
- super({
1910
- ...P.DEFAULTS,
1911
- ...t
1912
- }), this.currentMask = void 0;
1913
- }
1914
- updateOptions(t) {
1915
- super.updateOptions(t);
1916
- }
1917
- _update(t) {
1918
- super._update(t), "mask" in t && (this.exposeMask = void 0, this.compiledMasks = Array.isArray(t.mask) ? t.mask.map((e) => {
1919
- const {
1920
- expose: s,
1921
- ...i
1922
- } = w(e), a = y({
1923
- overwrite: this._overwrite,
1924
- eager: this._eager,
1925
- skipInvalid: this._skipInvalid,
1926
- ...i
1927
- });
1928
- return s && (this.exposeMask = a), a;
1929
- }) : []);
1930
- }
1931
- _appendCharRaw(t, e) {
1932
- e === void 0 && (e = {});
1933
- const s = this._applyDispatch(t, e);
1934
- return this.currentMask && s.aggregate(this.currentMask._appendChar(t, this.currentMaskFlags(e))), s;
1935
- }
1936
- _applyDispatch(t, e, s) {
1937
- t === void 0 && (t = ""), e === void 0 && (e = {}), s === void 0 && (s = "");
1938
- const i = e.tail && e._beforeTailState != null ? e._beforeTailState._value : this.value, a = this.rawInputValue, n = e.tail && e._beforeTailState != null ? e._beforeTailState._rawInputValue : a, r = a.slice(n.length), l = this.currentMask, o = new c(), d = l == null ? void 0 : l.state;
1939
- return this.currentMask = this.doDispatch(t, {
1940
- ...e
1941
- }, s), this.currentMask && (this.currentMask !== l ? (this.currentMask.reset(), n && (this.currentMask.append(n, {
1942
- raw: !0
1943
- }), o.tailShift = this.currentMask.value.length - i.length), r && (o.tailShift += this.currentMask.append(r, {
1944
- raw: !0,
1945
- tail: !0
1946
- }).tailShift)) : d && (this.currentMask.state = d)), o;
1947
- }
1948
- _appendPlaceholder() {
1949
- const t = this._applyDispatch();
1950
- return this.currentMask && t.aggregate(this.currentMask._appendPlaceholder()), t;
1951
- }
1952
- _appendEager() {
1953
- const t = this._applyDispatch();
1954
- return this.currentMask && t.aggregate(this.currentMask._appendEager()), t;
1955
- }
1956
- appendTail(t) {
1957
- const e = new c();
1958
- return t && e.aggregate(this._applyDispatch("", {}, t)), e.aggregate(this.currentMask ? this.currentMask.appendTail(t) : super.appendTail(t));
1959
- }
1960
- currentMaskFlags(t) {
1961
- var e, s;
1962
- return {
1963
- ...t,
1964
- _beforeTailState: ((e = t._beforeTailState) == null ? void 0 : e.currentMaskRef) === this.currentMask && ((s = t._beforeTailState) == null ? void 0 : s.currentMask) || t._beforeTailState
1965
- };
1966
- }
1967
- doDispatch(t, e, s) {
1968
- return e === void 0 && (e = {}), s === void 0 && (s = ""), this.dispatch(t, this, e, s);
1969
- }
1970
- doValidate(t) {
1971
- return super.doValidate(t) && (!this.currentMask || this.currentMask.doValidate(this.currentMaskFlags(t)));
1972
- }
1973
- doPrepare(t, e) {
1974
- e === void 0 && (e = {});
1975
- let [s, i] = super.doPrepare(t, e);
1976
- if (this.currentMask) {
1977
- let a;
1978
- [s, a] = super.doPrepare(s, this.currentMaskFlags(e)), i = i.aggregate(a);
1979
- }
1980
- return [s, i];
1981
- }
1982
- doPrepareChar(t, e) {
1983
- e === void 0 && (e = {});
1984
- let [s, i] = super.doPrepareChar(t, e);
1985
- if (this.currentMask) {
1986
- let a;
1987
- [s, a] = super.doPrepareChar(s, this.currentMaskFlags(e)), i = i.aggregate(a);
1988
- }
1989
- return [s, i];
1990
- }
1991
- reset() {
1992
- var t;
1993
- (t = this.currentMask) == null || t.reset(), this.compiledMasks.forEach((e) => e.reset());
1994
- }
1995
- get value() {
1996
- return this.exposeMask ? this.exposeMask.value : this.currentMask ? this.currentMask.value : "";
1997
- }
1998
- set value(t) {
1999
- this.exposeMask ? (this.exposeMask.value = t, this.currentMask = this.exposeMask, this._applyDispatch()) : super.value = t;
2000
- }
2001
- get unmaskedValue() {
2002
- return this.exposeMask ? this.exposeMask.unmaskedValue : this.currentMask ? this.currentMask.unmaskedValue : "";
2003
- }
2004
- set unmaskedValue(t) {
2005
- this.exposeMask ? (this.exposeMask.unmaskedValue = t, this.currentMask = this.exposeMask, this._applyDispatch()) : super.unmaskedValue = t;
2006
- }
2007
- get typedValue() {
2008
- return this.exposeMask ? this.exposeMask.typedValue : this.currentMask ? this.currentMask.typedValue : "";
2009
- }
2010
- set typedValue(t) {
2011
- if (this.exposeMask) {
2012
- this.exposeMask.typedValue = t, this.currentMask = this.exposeMask, this._applyDispatch();
2013
- return;
2014
- }
2015
- let e = String(t);
2016
- this.currentMask && (this.currentMask.typedValue = t, e = this.currentMask.unmaskedValue), this.unmaskedValue = e;
2017
- }
2018
- get displayValue() {
2019
- return this.currentMask ? this.currentMask.displayValue : "";
2020
- }
2021
- get isComplete() {
2022
- var t;
2023
- return !!((t = this.currentMask) != null && t.isComplete);
2024
- }
2025
- get isFilled() {
2026
- var t;
2027
- return !!((t = this.currentMask) != null && t.isFilled);
2028
- }
2029
- remove(t, e) {
2030
- const s = new c();
2031
- return this.currentMask && s.aggregate(this.currentMask.remove(t, e)).aggregate(this._applyDispatch()), s;
2032
- }
2033
- get state() {
2034
- var t;
2035
- return {
2036
- ...super.state,
2037
- _rawInputValue: this.rawInputValue,
2038
- compiledMasks: this.compiledMasks.map((e) => e.state),
2039
- currentMaskRef: this.currentMask,
2040
- currentMask: (t = this.currentMask) == null ? void 0 : t.state
2041
- };
2042
- }
2043
- set state(t) {
2044
- const {
2045
- compiledMasks: e,
2046
- currentMaskRef: s,
2047
- currentMask: i,
2048
- ...a
2049
- } = t;
2050
- e && this.compiledMasks.forEach((n, r) => n.state = e[r]), s != null && (this.currentMask = s, this.currentMask.state = i), super.state = a;
2051
- }
2052
- extractInput(t, e, s) {
2053
- return this.currentMask ? this.currentMask.extractInput(t, e, s) : "";
2054
- }
2055
- extractTail(t, e) {
2056
- return this.currentMask ? this.currentMask.extractTail(t, e) : super.extractTail(t, e);
2057
- }
2058
- doCommit() {
2059
- this.currentMask && this.currentMask.doCommit(), super.doCommit();
2060
- }
2061
- nearestInputPos(t, e) {
2062
- return this.currentMask ? this.currentMask.nearestInputPos(t, e) : super.nearestInputPos(t, e);
2063
- }
2064
- get overwrite() {
2065
- return this.currentMask ? this.currentMask.overwrite : this._overwrite;
2066
- }
2067
- set overwrite(t) {
2068
- this._overwrite = t;
2069
- }
2070
- get eager() {
2071
- return this.currentMask ? this.currentMask.eager : this._eager;
2072
- }
2073
- set eager(t) {
2074
- this._eager = t;
2075
- }
2076
- get skipInvalid() {
2077
- return this.currentMask ? this.currentMask.skipInvalid : this._skipInvalid;
2078
- }
2079
- set skipInvalid(t) {
2080
- this._skipInvalid = t;
2081
- }
2082
- get autofix() {
2083
- return this.currentMask ? this.currentMask.autofix : this._autofix;
2084
- }
2085
- set autofix(t) {
2086
- this._autofix = t;
2087
- }
2088
- maskEquals(t) {
2089
- return Array.isArray(t) ? this.compiledMasks.every((e, s) => {
2090
- if (!t[s])
2091
- return;
2092
- const {
2093
- mask: i,
2094
- ...a
2095
- } = t[s];
2096
- return L(e, a) && e.maskEquals(i);
2097
- }) : super.maskEquals(t);
2098
- }
2099
- typedValueEquals(t) {
2100
- var e;
2101
- return !!((e = this.currentMask) != null && e.typedValueEquals(t));
2102
- }
2103
- }
2104
- P.DEFAULTS = {
2105
- ..._.DEFAULTS,
2106
- dispatch: (u, t, e, s) => {
2107
- if (!t.compiledMasks.length)
2108
- return;
2109
- const i = t.rawInputValue, a = t.compiledMasks.map((n, r) => {
2110
- const l = t.currentMask === n, o = l ? n.displayValue.length : n.nearestInputPos(n.displayValue.length, h.FORCE_LEFT);
2111
- return n.rawInputValue !== i ? (n.reset(), n.append(i, {
2112
- raw: !0
2113
- })) : l || n.remove(o), n.append(u, t.currentMaskFlags(e)), n.appendTail(s), {
2114
- index: r,
2115
- weight: n.rawInputValue.length,
2116
- totalInputPositions: n.totalInputPositions(0, Math.max(o, n.nearestInputPos(n.displayValue.length, h.FORCE_LEFT)))
2117
- };
2118
- });
2119
- return a.sort((n, r) => r.weight - n.weight || r.totalInputPositions - n.totalInputPositions), t.compiledMasks[a[0].index];
2120
- }
2121
- };
2122
- p.MaskedDynamic = P;
2123
- class H extends v {
2124
- constructor(t) {
2125
- super({
2126
- ...H.DEFAULTS,
2127
- ...t
2128
- });
2129
- }
2130
- updateOptions(t) {
2131
- super.updateOptions(t);
2132
- }
2133
- _update(t) {
2134
- const {
2135
- enum: e,
2136
- ...s
2137
- } = t;
2138
- if (e) {
2139
- const i = e.map((r) => r.length), a = Math.min(...i), n = Math.max(...i) - a;
2140
- s.mask = "*".repeat(a), n && (s.mask += "[" + "*".repeat(n) + "]"), this.enum = e;
2141
- }
2142
- super._update(s);
2143
- }
2144
- _appendCharRaw(t, e) {
2145
- e === void 0 && (e = {});
2146
- const s = Math.min(this.nearestInputPos(0, h.FORCE_RIGHT), this.value.length), i = this.enum.filter((a) => this.matchValue(a, this.unmaskedValue + t, s));
2147
- if (i.length) {
2148
- i.length === 1 && this._forEachBlocksInRange(0, this.value.length, (n, r) => {
2149
- const l = i[0][r];
2150
- r >= this.value.length || l === n.value || (n.reset(), n._appendChar(l, e));
2151
- });
2152
- const a = super._appendCharRaw(i[0][this.value.length], e);
2153
- return i.length === 1 && i[0].slice(this.unmaskedValue.length).split("").forEach((n) => a.aggregate(super._appendCharRaw(n))), a;
2154
- }
2155
- return new c({
2156
- skip: !this.isComplete
2157
- });
2158
- }
2159
- extractTail(t, e) {
2160
- return t === void 0 && (t = 0), e === void 0 && (e = this.displayValue.length), new F("", t);
2161
- }
2162
- remove(t, e) {
2163
- if (t === void 0 && (t = 0), e === void 0 && (e = this.displayValue.length), t === e)
2164
- return new c();
2165
- const s = Math.min(super.nearestInputPos(0, h.FORCE_RIGHT), this.value.length);
2166
- let i;
2167
- for (i = t; i >= 0 && !(this.enum.filter((r) => this.matchValue(r, this.value.slice(s, i), s)).length > 1); --i)
2168
- ;
2169
- const a = super.remove(i, e);
2170
- return a.tailShift += i - t, a;
2171
- }
2172
- get isComplete() {
2173
- return this.enum.indexOf(this.value) >= 0;
2174
- }
2175
- }
2176
- H.DEFAULTS = {
2177
- ...v.DEFAULTS,
2178
- matchValue: (u, t, e) => u.indexOf(t, e) === e
2179
- };
2180
- p.MaskedEnum = H;
2181
- class Ot extends _ {
2182
- /** */
2183
- /** Enable characters overwriting */
2184
- /** */
2185
- /** */
2186
- /** */
2187
- updateOptions(t) {
2188
- super.updateOptions(t);
2189
- }
2190
- _update(t) {
2191
- super._update({
2192
- ...t,
2193
- validate: t.mask
2194
- });
2195
- }
2196
- }
2197
- p.MaskedFunction = Ot;
2198
- var dt;
2199
- class C extends _ {
2200
- /** Single char */
2201
- /** Single char */
2202
- /** Array of single chars */
2203
- /** */
2204
- /** */
2205
- /** Digits after point */
2206
- /** Flag to remove leading and trailing zeros in the end of editing */
2207
- /** Flag to pad trailing zeros after point in the end of editing */
2208
- /** Enable characters overwriting */
2209
- /** */
2210
- /** */
2211
- /** */
2212
- /** Format typed value to string */
2213
- /** Parse string to get typed value */
2214
- constructor(t) {
2215
- super({
2216
- ...C.DEFAULTS,
2217
- ...t
2218
- });
2219
- }
2220
- updateOptions(t) {
2221
- super.updateOptions(t);
2222
- }
2223
- _update(t) {
2224
- super._update(t), this._updateRegExps();
2225
- }
2226
- _updateRegExps() {
2227
- const t = "^" + (this.allowNegative ? "[+|\\-]?" : ""), e = "\\d*", s = (this.scale ? "(" + G(this.radix) + "\\d{0," + this.scale + "})?" : "") + "$";
2228
- this._numberRegExp = new RegExp(t + e + s), this._mapToRadixRegExp = new RegExp("[" + this.mapToRadix.map(G).join("") + "]", "g"), this._thousandsSeparatorRegExp = new RegExp(G(this.thousandsSeparator), "g");
2229
- }
2230
- _removeThousandsSeparators(t) {
2231
- return t.replace(this._thousandsSeparatorRegExp, "");
2232
- }
2233
- _insertThousandsSeparators(t) {
2234
- const e = t.split(this.radix);
2235
- return e[0] = e[0].replace(/\B(?=(\d{3})+(?!\d))/g, this.thousandsSeparator), e.join(this.radix);
2236
- }
2237
- doPrepareChar(t, e) {
2238
- e === void 0 && (e = {});
2239
- const [s, i] = super.doPrepareChar(this._removeThousandsSeparators(this.scale && this.mapToRadix.length && /*
2240
- radix should be mapped when
2241
- 1) input is done from keyboard = flags.input && flags.raw
2242
- 2) unmasked value is set = !flags.input && !flags.raw
2243
- and should not be mapped when
2244
- 1) value is set = flags.input && !flags.raw
2245
- 2) raw value is set = !flags.input && flags.raw
2246
- */
2247
- (e.input && e.raw || !e.input && !e.raw) ? t.replace(this._mapToRadixRegExp, this.radix) : t), e);
2248
- return t && !s && (i.skip = !0), s && !this.allowPositive && !this.value && s !== "-" && i.aggregate(this._appendChar("-")), [s, i];
2249
- }
2250
- _separatorsCount(t, e) {
2251
- e === void 0 && (e = !1);
2252
- let s = 0;
2253
- for (let i = 0; i < t; ++i)
2254
- this._value.indexOf(this.thousandsSeparator, i) === i && (++s, e && (t += this.thousandsSeparator.length));
2255
- return s;
2256
- }
2257
- _separatorsCountFromSlice(t) {
2258
- return t === void 0 && (t = this._value), this._separatorsCount(this._removeThousandsSeparators(t).length, !0);
2259
- }
2260
- extractInput(t, e, s) {
2261
- return t === void 0 && (t = 0), e === void 0 && (e = this.displayValue.length), [t, e] = this._adjustRangeWithSeparators(t, e), this._removeThousandsSeparators(super.extractInput(t, e, s));
2262
- }
2263
- _appendCharRaw(t, e) {
2264
- e === void 0 && (e = {});
2265
- const s = e.tail && e._beforeTailState ? e._beforeTailState._value : this._value, i = this._separatorsCountFromSlice(s);
2266
- this._value = this._removeThousandsSeparators(this.value);
2267
- const a = this._value;
2268
- this._value += t;
2269
- const n = this.number;
2270
- let r = !isNaN(n), l = !1;
2271
- if (r) {
2272
- let m;
2273
- this.min != null && this.min < 0 && this.number < this.min && (m = this.min), this.max != null && this.max > 0 && this.number > this.max && (m = this.max), m != null && (this.autofix ? (this._value = this.format(m, this).replace(C.UNMASKED_RADIX, this.radix), l || (l = a === this._value && !e.tail)) : r = !1), r && (r = !!this._value.match(this._numberRegExp));
2274
- }
2275
- let o;
2276
- r ? o = new c({
2277
- inserted: this._value.slice(a.length),
2278
- rawInserted: l ? "" : t,
2279
- skip: l
2280
- }) : (this._value = a, o = new c()), this._value = this._insertThousandsSeparators(this._value);
2281
- const d = e.tail && e._beforeTailState ? e._beforeTailState._value : this._value, f = this._separatorsCountFromSlice(d);
2282
- return o.tailShift += (f - i) * this.thousandsSeparator.length, o;
2283
- }
2284
- _findSeparatorAround(t) {
2285
- if (this.thousandsSeparator) {
2286
- const e = t - this.thousandsSeparator.length + 1, s = this.value.indexOf(this.thousandsSeparator, e);
2287
- if (s <= t)
2288
- return s;
2289
- }
2290
- return -1;
2291
- }
2292
- _adjustRangeWithSeparators(t, e) {
2293
- const s = this._findSeparatorAround(t);
2294
- s >= 0 && (t = s);
2295
- const i = this._findSeparatorAround(e);
2296
- return i >= 0 && (e = i + this.thousandsSeparator.length), [t, e];
2297
- }
2298
- remove(t, e) {
2299
- t === void 0 && (t = 0), e === void 0 && (e = this.displayValue.length), [t, e] = this._adjustRangeWithSeparators(t, e);
2300
- const s = this.value.slice(0, t), i = this.value.slice(e), a = this._separatorsCount(s.length);
2301
- this._value = this._insertThousandsSeparators(this._removeThousandsSeparators(s + i));
2302
- const n = this._separatorsCountFromSlice(s);
2303
- return new c({
2304
- tailShift: (n - a) * this.thousandsSeparator.length
2305
- });
2306
- }
2307
- nearestInputPos(t, e) {
2308
- if (!this.thousandsSeparator)
2309
- return t;
2310
- switch (e) {
2311
- case h.NONE:
2312
- case h.LEFT:
2313
- case h.FORCE_LEFT: {
2314
- const s = this._findSeparatorAround(t - 1);
2315
- if (s >= 0) {
2316
- const i = s + this.thousandsSeparator.length;
2317
- if (t < i || this.value.length <= i || e === h.FORCE_LEFT)
2318
- return s;
2319
- }
2320
- break;
2321
- }
2322
- case h.RIGHT:
2323
- case h.FORCE_RIGHT: {
2324
- const s = this._findSeparatorAround(t);
2325
- if (s >= 0)
2326
- return s + this.thousandsSeparator.length;
2327
- }
2328
- }
2329
- return t;
2330
- }
2331
- doCommit() {
2332
- if (this.value) {
2333
- const t = this.number;
2334
- let e = t;
2335
- this.min != null && (e = Math.max(e, this.min)), this.max != null && (e = Math.min(e, this.max)), e !== t && (this.unmaskedValue = this.format(e, this));
2336
- let s = this.value;
2337
- this.normalizeZeros && (s = this._normalizeZeros(s)), this.padFractionalZeros && this.scale > 0 && (s = this._padFractionalZeros(s)), this._value = s;
2338
- }
2339
- super.doCommit();
2340
- }
2341
- _normalizeZeros(t) {
2342
- const e = this._removeThousandsSeparators(t).split(this.radix);
2343
- return e[0] = e[0].replace(/^(\D*)(0*)(\d*)/, (s, i, a, n) => i + n), t.length && !/\d$/.test(e[0]) && (e[0] = e[0] + "0"), e.length > 1 && (e[1] = e[1].replace(/0*$/, ""), e[1].length || (e.length = 1)), this._insertThousandsSeparators(e.join(this.radix));
2344
- }
2345
- _padFractionalZeros(t) {
2346
- if (!t)
2347
- return t;
2348
- const e = t.split(this.radix);
2349
- return e.length < 2 && e.push(""), e[1] = e[1].padEnd(this.scale, "0"), e.join(this.radix);
2350
- }
2351
- doSkipInvalid(t, e, s) {
2352
- e === void 0 && (e = {});
2353
- const i = this.scale === 0 && t !== this.thousandsSeparator && (t === this.radix || t === C.UNMASKED_RADIX || this.mapToRadix.includes(t));
2354
- return super.doSkipInvalid(t, e, s) && !i;
2355
- }
2356
- get unmaskedValue() {
2357
- return this._removeThousandsSeparators(this._normalizeZeros(this.value)).replace(this.radix, C.UNMASKED_RADIX);
2358
- }
2359
- set unmaskedValue(t) {
2360
- super.unmaskedValue = t;
2361
- }
2362
- get typedValue() {
2363
- return this.parse(this.unmaskedValue, this);
2364
- }
2365
- set typedValue(t) {
2366
- this.rawInputValue = this.format(t, this).replace(C.UNMASKED_RADIX, this.radix);
2367
- }
2368
- /** Parsed Number */
2369
- get number() {
2370
- return this.typedValue;
2371
- }
2372
- set number(t) {
2373
- this.typedValue = t;
2374
- }
2375
- get allowNegative() {
2376
- return this.min != null && this.min < 0 || this.max != null && this.max < 0;
2377
- }
2378
- get allowPositive() {
2379
- return this.min != null && this.min > 0 || this.max != null && this.max > 0;
2380
- }
2381
- typedValueEquals(t) {
2382
- return (super.typedValueEquals(t) || C.EMPTY_VALUES.includes(t) && C.EMPTY_VALUES.includes(this.typedValue)) && !(t === 0 && this.value === "");
2383
- }
2384
- }
2385
- dt = C;
2386
- C.UNMASKED_RADIX = ".";
2387
- C.EMPTY_VALUES = [..._.EMPTY_VALUES, 0];
2388
- C.DEFAULTS = {
2389
- ..._.DEFAULTS,
2390
- mask: Number,
2391
- radix: ",",
2392
- thousandsSeparator: "",
2393
- mapToRadix: [dt.UNMASKED_RADIX],
2394
- min: Number.MIN_SAFE_INTEGER,
2395
- max: Number.MAX_SAFE_INTEGER,
2396
- scale: 2,
2397
- normalizeZeros: !0,
2398
- padFractionalZeros: !1,
2399
- parse: Number,
2400
- format: (u) => u.toLocaleString("en-US", {
2401
- useGrouping: !1,
2402
- maximumFractionDigits: 20
2403
- })
2404
- };
2405
- p.MaskedNumber = C;
2406
- const K = {
2407
- MASKED: "value",
2408
- UNMASKED: "unmaskedValue",
2409
- TYPED: "typedValue"
2410
- };
2411
- function pt(u, t, e) {
2412
- t === void 0 && (t = K.MASKED), e === void 0 && (e = K.MASKED);
2413
- const s = y(u);
2414
- return (i) => s.runIsolated((a) => (a[t] = i, a[e]));
2415
- }
2416
- function Lt(u, t, e, s) {
2417
- return pt(t, e, s)(u);
2418
- }
2419
- p.PIPE_TYPE = K;
2420
- p.createPipe = pt;
2421
- p.pipe = Lt;
2422
- class Nt extends v {
2423
- get repeatFrom() {
2424
- var t;
2425
- return (t = Array.isArray(this.repeat) ? this.repeat[0] : this.repeat === 1 / 0 ? 0 : this.repeat) != null ? t : 0;
2426
- }
2427
- get repeatTo() {
2428
- var t;
2429
- return (t = Array.isArray(this.repeat) ? this.repeat[1] : this.repeat) != null ? t : 1 / 0;
2430
- }
2431
- constructor(t) {
2432
- super(t);
2433
- }
2434
- updateOptions(t) {
2435
- super.updateOptions(t);
2436
- }
2437
- _update(t) {
2438
- var e, s, i;
2439
- const {
2440
- repeat: a,
2441
- ...n
2442
- } = w(t);
2443
- this._blockOpts = Object.assign({}, this._blockOpts, n);
2444
- const r = y(this._blockOpts);
2445
- this.repeat = (e = (s = a ?? r.repeat) != null ? s : this.repeat) != null ? e : 1 / 0, super._update({
2446
- mask: "m".repeat(Math.max(this.repeatTo === 1 / 0 && ((i = this._blocks) == null ? void 0 : i.length) || 0, this.repeatFrom)),
2447
- blocks: {
2448
- m: r
2449
- },
2450
- eager: r.eager,
2451
- overwrite: r.overwrite,
2452
- skipInvalid: r.skipInvalid,
2453
- lazy: r.lazy,
2454
- placeholderChar: r.placeholderChar,
2455
- displayChar: r.displayChar
2456
- });
2457
- }
2458
- _allocateBlock(t) {
2459
- if (t < this._blocks.length)
2460
- return this._blocks[t];
2461
- if (this.repeatTo === 1 / 0 || this._blocks.length < this.repeatTo)
2462
- return this._blocks.push(y(this._blockOpts)), this.mask += "m", this._blocks[this._blocks.length - 1];
2463
- }
2464
- _appendCharRaw(t, e) {
2465
- e === void 0 && (e = {});
2466
- const s = new c();
2467
- for (
2468
- let l = (i = (a = this._mapPosToBlock(this.displayValue.length)) == null ? void 0 : a.index) != null ? i : Math.max(this._blocks.length - 1, 0), o, d;
2469
- // try to get a block or
2470
- // try to allocate a new block if not allocated already
2471
- o = (n = this._blocks[l]) != null ? n : d = !d && this._allocateBlock(l);
2472
- ++l
2473
- ) {
2474
- var i, a, n, r;
2475
- const f = o._appendChar(t, {
2476
- ...e,
2477
- _beforeTailState: (r = e._beforeTailState) == null || (r = r._blocks) == null ? void 0 : r[l]
2478
- });
2479
- if (f.skip && d) {
2480
- this._blocks.pop(), this.mask = this.mask.slice(1);
2481
- break;
2482
- }
2483
- if (s.aggregate(f), f.consumed)
2484
- break;
2485
- }
2486
- return s;
2487
- }
2488
- _trimEmptyTail(t, e) {
2489
- var s, i;
2490
- t === void 0 && (t = 0);
2491
- const a = Math.max(((s = this._mapPosToBlock(t)) == null ? void 0 : s.index) || 0, this.repeatFrom, 0);
2492
- let n;
2493
- e != null && (n = (i = this._mapPosToBlock(e)) == null ? void 0 : i.index), n == null && (n = this._blocks.length - 1);
2494
- let r = 0;
2495
- for (let l = n; a <= l && !this._blocks[l].unmaskedValue; --l, ++r)
2496
- ;
2497
- r && (this._blocks.splice(n - r + 1, r), this.mask = this.mask.slice(r));
2498
- }
2499
- reset() {
2500
- super.reset(), this._trimEmptyTail();
2501
- }
2502
- remove(t, e) {
2503
- t === void 0 && (t = 0), e === void 0 && (e = this.displayValue.length);
2504
- const s = super.remove(t, e);
2505
- return this._trimEmptyTail(t, e), s;
2506
- }
2507
- totalInputPositions(t, e) {
2508
- return t === void 0 && (t = 0), e == null && this.repeatTo === 1 / 0 ? 1 / 0 : super.totalInputPositions(t, e);
2509
- }
2510
- get state() {
2511
- return super.state;
2512
- }
2513
- set state(t) {
2514
- this._blocks.length = t._blocks.length, this.mask = this.mask.slice(0, this._blocks.length), super.state = t;
2515
- }
2516
- }
2517
- p.RepeatBlock = Nt;
2518
- try {
2519
- globalThis.IMask = p;
2520
- } catch {
2521
- }
2522
- var Ut = {
2523
- // common
2524
- mask: void 0,
2525
- prepare: Function,
2526
- prepareChar: Function,
2527
- validate: Function,
2528
- commit: Function,
2529
- overwrite: {
2530
- type: Boolean,
2531
- required: !1,
2532
- default: void 0
2533
- },
2534
- eager: {
2535
- required: !1,
2536
- default: void 0,
2537
- validator: (u) => ["append", "remove"].includes(u) || typeof u == "boolean"
2538
- },
2539
- skipInvalid: {
2540
- type: Boolean,
2541
- required: !1,
2542
- default: void 0
2543
- },
2544
- // pattern
2545
- placeholderChar: String,
2546
- displayChar: String,
2547
- lazy: {
2548
- type: Boolean,
2549
- required: !1,
2550
- default: void 0
2551
- },
2552
- definitions: Object,
2553
- blocks: Object,
2554
- // enum
2555
- enum: Array,
2556
- // range
2557
- maxLength: Number,
2558
- from: Number,
2559
- to: Number,
2560
- // date
2561
- pattern: String,
2562
- format: Function,
2563
- parse: Function,
2564
- autofix: {
2565
- required: !1,
2566
- default: void 0,
2567
- validator: (u) => u === "pad" || typeof u == "boolean"
2568
- },
2569
- // number
2570
- radix: String,
2571
- thousandsSeparator: String,
2572
- mapToRadix: Array,
2573
- scale: Number,
2574
- normalizeZeros: {
2575
- type: Boolean,
2576
- required: !1,
2577
- default: void 0
2578
- },
2579
- padFractionalZeros: {
2580
- type: Boolean,
2581
- required: !1,
2582
- default: void 0
2583
- },
2584
- min: [Number, Date],
2585
- max: [Number, Date],
2586
- // dynamic
2587
- dispatch: Function
2588
- };
2589
- function jt(u, t) {
2590
- let {
2591
- emit: e,
2592
- onAccept: s,
2593
- onComplete: i,
2594
- defaultValue: a,
2595
- defaultUnmaskedValue: n,
2596
- defaultTypedValue: r
2597
- } = t === void 0 ? {} : t;
2598
- const l = kt(u) ? u : b(u), o = b(), d = b(), f = b(""), m = b(""), k = b();
2599
- let E, I = f.value, B = m.value, z = k.value;
2600
- function $() {
2601
- z = k.value = d.value.typedValue, B = m.value = d.value.unmaskedValue, I = f.value = d.value.value;
2602
- }
2603
- function T(g) {
2604
- $(), e && (e("accept", f.value, g), e("accept:masked", f.value, g), e("accept:typed", k.value, g), e("accept:unmasked", m.value, g)), s == null || s(g);
2605
- }
2606
- function ct(g) {
2607
- e && (e("complete", d.value.value, g), e("complete:masked", d.value.value, g), e("complete:typed", d.value.typedValue, g), e("complete:unmasked", d.value.unmaskedValue, g)), i == null || i(g);
2608
- }
2609
- const Z = () => {
2610
- !d.value || m.value === void 0 || (B !== m.value && (d.value.unmaskedValue = m.value, d.value.unmaskedValue !== m.value && T()), B = void 0);
2611
- };
2612
- A(m, Z);
2613
- const X = () => {
2614
- !d.value || f.value === void 0 || (I !== f.value && (d.value.value = f.value, d.value.value !== f.value && T()), I = void 0);
2615
- };
2616
- A(f, X);
2617
- const W = () => {
2618
- !d.value || k.value === void 0 || (z !== k.value && (d.value.typedValue = k.value, d.value.masked.typedValueEquals(k.value) || T()), z = void 0);
2619
- };
2620
- A(k, W);
2621
- function J() {
2622
- E = o.value;
2623
- const g = l.value;
2624
- !E || !(g != null && g.mask) || (d.value = p(E, g), a !== void 0 && (f.value = a), n !== void 0 && (m.value = n), r !== void 0 && (k.value = r), Z(), X(), W(), $(), d.value.on("accept", T).on("complete", ct));
2625
- }
2626
- function Q() {
2627
- var g;
2628
- (g = d.value) == null || g.destroy(), d.value = void 0;
2629
- }
2630
- return nt(J), mt(Q), A([o, l], () => {
2631
- const g = o.value, q = l.value;
2632
- (!(q != null && q.mask) || g !== E) && Q(), g && (d.value ? d.value.updateOptions(q) : J());
2633
- }), {
2634
- el: o,
2635
- mask: gt(d),
2636
- masked: f,
2637
- unmasked: m,
2638
- typed: k
2639
- };
2640
- }
2641
- function Pt(u, t) {
2642
- return u = {
2643
- ...u
2644
- }, Object.keys(u).forEach((e) => {
2645
- (u[e] === void 0 || t.includes(e)) && delete u[e];
2646
- }), u;
2647
- }
2648
- const Ht = ["typed", "unmasked", "value", "modelValue"];
2649
- _t({
2650
- name: "imask-input",
2651
- inheritAttrs: !1,
2652
- props: {
2653
- // plugin
2654
- modelValue: String,
2655
- value: String,
2656
- unmasked: String,
2657
- typed: {
2658
- validator: () => !0
2659
- },
2660
- ...Ut
2661
- },
2662
- emits: ["update:modelValue", "update:masked", "update:value", "update:unmasked", "update:typed", "accept", "accept:value", "accept:masked", "accept:unmasked", "accept:typed", "complete", "complete:value", "complete:masked", "complete:unmasked", "complete:typed"],
2663
- setup(u, t) {
2664
- let {
2665
- attrs: e,
2666
- emit: s
2667
- } = t;
2668
- const {
2669
- el: i,
2670
- mask: a,
2671
- masked: n,
2672
- unmasked: r,
2673
- typed: l
2674
- } = jt(Pt(u, Ht), {
2675
- emit: s,
2676
- onAccept: (k) => {
2677
- const E = n.value;
2678
- s("accept:value", E, k), s("update:value", E, k), s("update:masked", E, k), s("update:modelValue", E, k), s("update:unmasked", r.value, k), s("update:typed", l.value, k);
2679
- },
2680
- onComplete: (k) => {
2681
- s("complete:value", n.value, k);
2682
- }
2683
- }), o = R(u, "value"), d = R(u, "modelValue"), f = R(u, "unmasked"), m = R(u, "typed");
2684
- return n.value = d.value || o.value || "", r.value = f.value || "", l.value = m.value, A(o, (k) => n.value = k), A(d, (k) => n.value = k), A(f, (k) => r.value = k), A(m, (k) => l.value = k), () => {
2685
- const k = {
2686
- ...e,
2687
- value: u.value != null ? u.value : u.modelValue != null ? u.modelValue : a.value ? a.value.displayValue : "",
2688
- ref: i
2689
- };
2690
- return u.mask || (k.onInput = (E) => {
2691
- s("update:modelValue", E.target.value), s("update:value", E.target.value);
2692
- }), vt("input", k);
2693
- };
2694
- }
2695
- });
2696
- var zt = {
2697
- name: "imask",
2698
- beforeMount: (u, t) => {
2699
- let {
2700
- value: e
2701
- } = t;
2702
- e && it(u, e);
2703
- },
2704
- updated: (u, t) => {
2705
- let {
2706
- value: e
2707
- } = t;
2708
- e ? u.maskRef ? (u.maskRef.updateOptions(e), u.value !== u.maskRef.value && u.maskRef._onChange()) : it(u, e) : at(u);
2709
- },
2710
- unmounted: (u) => {
2711
- at(u);
2712
- }
2713
- };
2714
- function st(u, t, e) {
2715
- const s = document.createEvent("CustomEvent");
2716
- s.initCustomEvent(t, !0, !0, e), u.dispatchEvent(s);
2717
- }
2718
- function it(u, t) {
2719
- u.maskRef = p(u, t).on("accept", () => st(u, "accept", u.maskRef)).on("complete", () => st(u, "complete", u.maskRef));
2720
- }
2721
- function at(u) {
2722
- u.maskRef && (u.maskRef.destroy(), delete u.maskRef);
2723
- }
2724
- const Gt = {
2725
- formHelpers: {
2726
- ...At,
2727
- useInput: xt,
2728
- useTextbox: St,
2729
- useMaskedInput: bt
2730
- },
2731
- install: (u) => {
2732
- u.directive("imask", zt), u.provide("responsiveHelpers", {
2733
- responsiveState: D,
2734
- updateResponsiveState: Et
2735
- });
2736
- }
2737
- };
2738
- export {
2739
- Gt as default
2740
- };