@verdocs/web-sdk 5.0.47 → 5.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/verdocs-kba-dialog_2.cjs.entry.js +3688 -2
  3. package/dist/cjs/verdocs-kba-dialog_2.cjs.entry.js.map +1 -1
  4. package/dist/cjs/verdocs-web-sdk.cjs.js +1 -1
  5. package/dist/collection/components/dialogs/verdocs-kba-dialog/verdocs-kba-dialog.js +91 -2
  6. package/dist/collection/components/dialogs/verdocs-kba-dialog/verdocs-kba-dialog.js.map +1 -1
  7. package/dist/components/p-c5fc58ab.js +3835 -0
  8. package/dist/components/p-c5fc58ab.js.map +1 -0
  9. package/dist/components/verdocs-kba-dialog.js +1 -1
  10. package/dist/components/verdocs-sign.js +22 -16
  11. package/dist/components/verdocs-sign.js.map +1 -1
  12. package/dist/custom-elements.json +2231 -0
  13. package/dist/esm/loader.js +1 -1
  14. package/dist/esm/verdocs-kba-dialog_2.entry.js +3688 -2
  15. package/dist/esm/verdocs-kba-dialog_2.entry.js.map +1 -1
  16. package/dist/esm/verdocs-web-sdk.js +1 -1
  17. package/dist/esm-es5/loader.js +1 -1
  18. package/dist/esm-es5/verdocs-kba-dialog_2.entry.js +1 -1
  19. package/dist/esm-es5/verdocs-kba-dialog_2.entry.js.map +1 -1
  20. package/dist/esm-es5/verdocs-web-sdk.js +1 -1
  21. package/dist/types/components/dialogs/verdocs-kba-dialog/verdocs-kba-dialog.d.ts +2 -2
  22. package/dist/verdocs-web-sdk/p-0c1898f6.system.js +1 -1
  23. package/dist/verdocs-web-sdk/p-b17b12c5.entry.js +2 -0
  24. package/dist/verdocs-web-sdk/p-b17b12c5.entry.js.map +1 -0
  25. package/dist/verdocs-web-sdk/p-b198c703.system.entry.js +2 -0
  26. package/dist/verdocs-web-sdk/p-b198c703.system.entry.js.map +1 -0
  27. package/dist/verdocs-web-sdk/verdocs-web-sdk.esm.js +1 -1
  28. package/package.json +2 -1
  29. package/dist/components/p-78b63448.js +0 -143
  30. package/dist/components/p-78b63448.js.map +0 -1
  31. package/dist/verdocs-web-sdk/p-8cdf8b44.entry.js +0 -2
  32. package/dist/verdocs-web-sdk/p-8cdf8b44.entry.js.map +0 -1
  33. package/dist/verdocs-web-sdk/p-c0331d52.system.entry.js +0 -2
  34. package/dist/verdocs-web-sdk/p-c0331d52.system.entry.js.map +0 -1
@@ -11,11 +11,3671 @@ require('./_commonjsHelpers-e6ff1d6e.js');
11
11
  require('./Types-7a726ff3.js');
12
12
  require('./format-dc0f3757.js');
13
13
 
14
+ /** Checks if value is string */
15
+ function isString(str) {
16
+ return typeof str === 'string' || str instanceof String;
17
+ }
18
+
19
+ /** Checks if value is object */
20
+ function isObject(obj) {
21
+ var _obj$constructor;
22
+ return typeof obj === 'object' && obj != null && (obj == null || (_obj$constructor = obj.constructor) == null ? void 0 : _obj$constructor.name) === 'Object';
23
+ }
24
+ function pick(obj, keys) {
25
+ if (Array.isArray(keys)) return pick(obj, (_, k) => keys.includes(k));
26
+ return Object.entries(obj).reduce((acc, _ref) => {
27
+ let [k, v] = _ref;
28
+ if (keys(v, k)) acc[k] = v;
29
+ return acc;
30
+ }, {});
31
+ }
32
+
33
+ /** Direction */
34
+ const DIRECTION = {
35
+ NONE: 'NONE',
36
+ LEFT: 'LEFT',
37
+ FORCE_LEFT: 'FORCE_LEFT',
38
+ RIGHT: 'RIGHT',
39
+ FORCE_RIGHT: 'FORCE_RIGHT'
40
+ };
41
+
42
+ /** Direction */
43
+
44
+ function forceDirection(direction) {
45
+ switch (direction) {
46
+ case DIRECTION.LEFT:
47
+ return DIRECTION.FORCE_LEFT;
48
+ case DIRECTION.RIGHT:
49
+ return DIRECTION.FORCE_RIGHT;
50
+ default:
51
+ return direction;
52
+ }
53
+ }
54
+
55
+ /** Escapes regular expression control chars */
56
+ function escapeRegExp(str) {
57
+ return str.replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1');
58
+ }
59
+
60
+ // cloned from https://github.com/epoberezkin/fast-deep-equal with small changes
61
+ function objectIncludes(b, a) {
62
+ if (a === b) return true;
63
+ const arrA = Array.isArray(a),
64
+ arrB = Array.isArray(b);
65
+ let i;
66
+ if (arrA && arrB) {
67
+ if (a.length != b.length) return false;
68
+ for (i = 0; i < a.length; i++) if (!objectIncludes(a[i], b[i])) return false;
69
+ return true;
70
+ }
71
+ if (arrA != arrB) return false;
72
+ if (a && b && typeof a === 'object' && typeof b === 'object') {
73
+ const dateA = a instanceof Date,
74
+ dateB = b instanceof Date;
75
+ if (dateA && dateB) return a.getTime() == b.getTime();
76
+ if (dateA != dateB) return false;
77
+ const regexpA = a instanceof RegExp,
78
+ regexpB = b instanceof RegExp;
79
+ if (regexpA && regexpB) return a.toString() == b.toString();
80
+ if (regexpA != regexpB) return false;
81
+ const keys = Object.keys(a);
82
+ // if (keys.length !== Object.keys(b).length) return false;
83
+
84
+ for (i = 0; i < keys.length; i++) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
85
+ for (i = 0; i < keys.length; i++) if (!objectIncludes(b[keys[i]], a[keys[i]])) return false;
86
+ return true;
87
+ } else if (a && b && typeof a === 'function' && typeof b === 'function') {
88
+ return a.toString() === b.toString();
89
+ }
90
+ return false;
91
+ }
92
+
93
+ /** Provides details of changing input */
94
+ class ActionDetails {
95
+ /** Current input value */
96
+
97
+ /** Current cursor position */
98
+
99
+ /** Old input value */
100
+
101
+ /** Old selection */
102
+
103
+ constructor(opts) {
104
+ Object.assign(this, opts);
105
+
106
+ // double check if left part was changed (autofilling, other non-standard input triggers)
107
+ while (this.value.slice(0, this.startChangePos) !== this.oldValue.slice(0, this.startChangePos)) {
108
+ --this.oldSelection.start;
109
+ }
110
+ if (this.insertedCount) {
111
+ // double check right part
112
+ while (this.value.slice(this.cursorPos) !== this.oldValue.slice(this.oldSelection.end)) {
113
+ if (this.value.length - this.cursorPos < this.oldValue.length - this.oldSelection.end) ++this.oldSelection.end;else ++this.cursorPos;
114
+ }
115
+ }
116
+ }
117
+
118
+ /** Start changing position */
119
+ get startChangePos() {
120
+ return Math.min(this.cursorPos, this.oldSelection.start);
121
+ }
122
+
123
+ /** Inserted symbols count */
124
+ get insertedCount() {
125
+ return this.cursorPos - this.startChangePos;
126
+ }
127
+
128
+ /** Inserted symbols */
129
+ get inserted() {
130
+ return this.value.substr(this.startChangePos, this.insertedCount);
131
+ }
132
+
133
+ /** Removed symbols count */
134
+ get removedCount() {
135
+ // Math.max for opposite operation
136
+ return Math.max(this.oldSelection.end - this.startChangePos ||
137
+ // for Delete
138
+ this.oldValue.length - this.value.length, 0);
139
+ }
140
+
141
+ /** Removed symbols */
142
+ get removed() {
143
+ return this.oldValue.substr(this.startChangePos, this.removedCount);
144
+ }
145
+
146
+ /** Unchanged head symbols */
147
+ get head() {
148
+ return this.value.substring(0, this.startChangePos);
149
+ }
150
+
151
+ /** Unchanged tail symbols */
152
+ get tail() {
153
+ return this.value.substring(this.startChangePos + this.insertedCount);
154
+ }
155
+
156
+ /** Remove direction */
157
+ get removeDirection() {
158
+ if (!this.removedCount || this.insertedCount) return DIRECTION.NONE;
159
+
160
+ // align right if delete at right
161
+ return (this.oldSelection.end === this.cursorPos || this.oldSelection.start === this.cursorPos) &&
162
+ // if not range removed (event with backspace)
163
+ this.oldSelection.end === this.oldSelection.start ? DIRECTION.RIGHT : DIRECTION.LEFT;
164
+ }
165
+ }
166
+
167
+ /** Applies mask on element */
168
+ function IMask(el, opts) {
169
+ // currently available only for input-like elements
170
+ return new IMask.InputMask(el, opts);
171
+ }
172
+
173
+ // TODO can't use overloads here because of https://github.com/microsoft/TypeScript/issues/50754
174
+ // export function maskedClass(mask: string): typeof MaskedPattern;
175
+ // export function maskedClass(mask: DateConstructor): typeof MaskedDate;
176
+ // export function maskedClass(mask: NumberConstructor): typeof MaskedNumber;
177
+ // export function maskedClass(mask: Array<any> | ArrayConstructor): typeof MaskedDynamic;
178
+ // export function maskedClass(mask: MaskedDate): typeof MaskedDate;
179
+ // export function maskedClass(mask: MaskedNumber): typeof MaskedNumber;
180
+ // export function maskedClass(mask: MaskedEnum): typeof MaskedEnum;
181
+ // export function maskedClass(mask: MaskedRange): typeof MaskedRange;
182
+ // export function maskedClass(mask: MaskedRegExp): typeof MaskedRegExp;
183
+ // export function maskedClass(mask: MaskedFunction): typeof MaskedFunction;
184
+ // export function maskedClass(mask: MaskedPattern): typeof MaskedPattern;
185
+ // export function maskedClass(mask: MaskedDynamic): typeof MaskedDynamic;
186
+ // export function maskedClass(mask: Masked): typeof Masked;
187
+ // export function maskedClass(mask: typeof Masked): typeof Masked;
188
+ // export function maskedClass(mask: typeof MaskedDate): typeof MaskedDate;
189
+ // export function maskedClass(mask: typeof MaskedNumber): typeof MaskedNumber;
190
+ // export function maskedClass(mask: typeof MaskedEnum): typeof MaskedEnum;
191
+ // export function maskedClass(mask: typeof MaskedRange): typeof MaskedRange;
192
+ // export function maskedClass(mask: typeof MaskedRegExp): typeof MaskedRegExp;
193
+ // export function maskedClass(mask: typeof MaskedFunction): typeof MaskedFunction;
194
+ // export function maskedClass(mask: typeof MaskedPattern): typeof MaskedPattern;
195
+ // export function maskedClass(mask: typeof MaskedDynamic): typeof MaskedDynamic;
196
+ // export function maskedClass<Mask extends typeof Masked> (mask: Mask): Mask;
197
+ // export function maskedClass(mask: RegExp): typeof MaskedRegExp;
198
+ // export function maskedClass(mask: (value: string, ...args: any[]) => boolean): typeof MaskedFunction;
199
+
200
+ /** Get Masked class by mask type */
201
+ function maskedClass(mask) /* TODO */{
202
+ if (mask == null) throw new Error('mask property should be defined');
203
+ if (mask instanceof RegExp) return IMask.MaskedRegExp;
204
+ if (isString(mask)) return IMask.MaskedPattern;
205
+ if (mask === Date) return IMask.MaskedDate;
206
+ if (mask === Number) return IMask.MaskedNumber;
207
+ if (Array.isArray(mask) || mask === Array) return IMask.MaskedDynamic;
208
+ if (IMask.Masked && mask.prototype instanceof IMask.Masked) return mask;
209
+ if (IMask.Masked && mask instanceof IMask.Masked) return mask.constructor;
210
+ if (mask instanceof Function) return IMask.MaskedFunction;
211
+ console.warn('Mask not found for mask', mask); // eslint-disable-line no-console
212
+ return IMask.Masked;
213
+ }
214
+ function normalizeOpts(opts) {
215
+ if (!opts) throw new Error('Options in not defined');
216
+ if (IMask.Masked) {
217
+ if (opts.prototype instanceof IMask.Masked) return {
218
+ mask: opts
219
+ };
220
+
221
+ /*
222
+ handle cases like:
223
+ 1) opts = Masked
224
+ 2) opts = { mask: Masked, ...instanceOpts }
225
+ */
226
+ const {
227
+ mask = undefined,
228
+ ...instanceOpts
229
+ } = opts instanceof IMask.Masked ? {
230
+ mask: opts
231
+ } : isObject(opts) && opts.mask instanceof IMask.Masked ? opts : {};
232
+ if (mask) {
233
+ const _mask = mask.mask;
234
+ return {
235
+ ...pick(mask, (_, k) => !k.startsWith('_')),
236
+ mask: mask.constructor,
237
+ _mask,
238
+ ...instanceOpts
239
+ };
240
+ }
241
+ }
242
+ if (!isObject(opts)) return {
243
+ mask: opts
244
+ };
245
+ return {
246
+ ...opts
247
+ };
248
+ }
249
+
250
+ // TODO can't use overloads here because of https://github.com/microsoft/TypeScript/issues/50754
251
+
252
+ // From masked
253
+ // export default function createMask<Opts extends Masked, ReturnMasked=Opts> (opts: Opts): ReturnMasked;
254
+ // // From masked class
255
+ // export default function createMask<Opts extends MaskedOptions<typeof Masked>, ReturnMasked extends Masked=InstanceType<Opts['mask']>> (opts: Opts): ReturnMasked;
256
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedDate>, ReturnMasked extends MaskedDate=MaskedDate<Opts['parent']>> (opts: Opts): ReturnMasked;
257
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedNumber>, ReturnMasked extends MaskedNumber=MaskedNumber<Opts['parent']>> (opts: Opts): ReturnMasked;
258
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedEnum>, ReturnMasked extends MaskedEnum=MaskedEnum<Opts['parent']>> (opts: Opts): ReturnMasked;
259
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedRange>, ReturnMasked extends MaskedRange=MaskedRange<Opts['parent']>> (opts: Opts): ReturnMasked;
260
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedRegExp>, ReturnMasked extends MaskedRegExp=MaskedRegExp<Opts['parent']>> (opts: Opts): ReturnMasked;
261
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedFunction>, ReturnMasked extends MaskedFunction=MaskedFunction<Opts['parent']>> (opts: Opts): ReturnMasked;
262
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedPattern>, ReturnMasked extends MaskedPattern=MaskedPattern<Opts['parent']>> (opts: Opts): ReturnMasked;
263
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedDynamic>, ReturnMasked extends MaskedDynamic=MaskedDynamic<Opts['parent']>> (opts: Opts): ReturnMasked;
264
+ // // From mask opts
265
+ // export default function createMask<Opts extends MaskedOptions<Masked>, ReturnMasked=Opts extends MaskedOptions<infer M> ? M : never> (opts: Opts): ReturnMasked;
266
+ // export default function createMask<Opts extends MaskedNumberOptions, ReturnMasked extends MaskedNumber=MaskedNumber<Opts['parent']>> (opts: Opts): ReturnMasked;
267
+ // export default function createMask<Opts extends MaskedDateFactoryOptions, ReturnMasked extends MaskedDate=MaskedDate<Opts['parent']>> (opts: Opts): ReturnMasked;
268
+ // export default function createMask<Opts extends MaskedEnumOptions, ReturnMasked extends MaskedEnum=MaskedEnum<Opts['parent']>> (opts: Opts): ReturnMasked;
269
+ // export default function createMask<Opts extends MaskedRangeOptions, ReturnMasked extends MaskedRange=MaskedRange<Opts['parent']>> (opts: Opts): ReturnMasked;
270
+ // export default function createMask<Opts extends MaskedPatternOptions, ReturnMasked extends MaskedPattern=MaskedPattern<Opts['parent']>> (opts: Opts): ReturnMasked;
271
+ // export default function createMask<Opts extends MaskedDynamicOptions, ReturnMasked extends MaskedDynamic=MaskedDynamic<Opts['parent']>> (opts: Opts): ReturnMasked;
272
+ // export default function createMask<Opts extends MaskedOptions<RegExp>, ReturnMasked extends MaskedRegExp=MaskedRegExp<Opts['parent']>> (opts: Opts): ReturnMasked;
273
+ // export default function createMask<Opts extends MaskedOptions<Function>, ReturnMasked extends MaskedFunction=MaskedFunction<Opts['parent']>> (opts: Opts): ReturnMasked;
274
+
275
+ /** Creates new {@link Masked} depending on mask type */
276
+ function createMask(opts) {
277
+ if (IMask.Masked && opts instanceof IMask.Masked) return opts;
278
+ const nOpts = normalizeOpts(opts);
279
+ const MaskedClass = maskedClass(nOpts.mask);
280
+ if (!MaskedClass) throw new Error("Masked class is not found for provided mask " + nOpts.mask + ", appropriate module needs to be imported manually before creating mask.");
281
+ if (nOpts.mask === MaskedClass) delete nOpts.mask;
282
+ if (nOpts._mask) {
283
+ nOpts.mask = nOpts._mask;
284
+ delete nOpts._mask;
285
+ }
286
+ return new MaskedClass(nOpts);
287
+ }
288
+ IMask.createMask = createMask;
289
+
290
+ /** Generic element API to use with mask */
291
+ class MaskElement {
292
+ /** */
293
+
294
+ /** */
295
+
296
+ /** */
297
+
298
+ /** Safely returns selection start */
299
+ get selectionStart() {
300
+ let start;
301
+ try {
302
+ start = this._unsafeSelectionStart;
303
+ } catch {}
304
+ return start != null ? start : this.value.length;
305
+ }
306
+
307
+ /** Safely returns selection end */
308
+ get selectionEnd() {
309
+ let end;
310
+ try {
311
+ end = this._unsafeSelectionEnd;
312
+ } catch {}
313
+ return end != null ? end : this.value.length;
314
+ }
315
+
316
+ /** Safely sets element selection */
317
+ select(start, end) {
318
+ if (start == null || end == null || start === this.selectionStart && end === this.selectionEnd) return;
319
+ try {
320
+ this._unsafeSelect(start, end);
321
+ } catch {}
322
+ }
323
+
324
+ /** */
325
+ get isActive() {
326
+ return false;
327
+ }
328
+ /** */
329
+
330
+ /** */
331
+
332
+ /** */
333
+ }
334
+ IMask.MaskElement = MaskElement;
335
+
336
+ const KEY_Z = 90;
337
+ const KEY_Y = 89;
338
+
339
+ /** Bridge between HTMLElement and {@link Masked} */
340
+ class HTMLMaskElement extends MaskElement {
341
+ /** HTMLElement to use mask on */
342
+
343
+ constructor(input) {
344
+ super();
345
+ this.input = input;
346
+ this._onKeydown = this._onKeydown.bind(this);
347
+ this._onInput = this._onInput.bind(this);
348
+ this._onBeforeinput = this._onBeforeinput.bind(this);
349
+ this._onCompositionEnd = this._onCompositionEnd.bind(this);
350
+ }
351
+ get rootElement() {
352
+ var _this$input$getRootNo, _this$input$getRootNo2, _this$input;
353
+ return (_this$input$getRootNo = (_this$input$getRootNo2 = (_this$input = this.input).getRootNode) == null ? void 0 : _this$input$getRootNo2.call(_this$input)) != null ? _this$input$getRootNo : document;
354
+ }
355
+
356
+ /** Is element in focus */
357
+ get isActive() {
358
+ return this.input === this.rootElement.activeElement;
359
+ }
360
+
361
+ /** Binds HTMLElement events to mask internal events */
362
+ bindEvents(handlers) {
363
+ this.input.addEventListener('keydown', this._onKeydown);
364
+ this.input.addEventListener('input', this._onInput);
365
+ this.input.addEventListener('beforeinput', this._onBeforeinput);
366
+ this.input.addEventListener('compositionend', this._onCompositionEnd);
367
+ this.input.addEventListener('drop', handlers.drop);
368
+ this.input.addEventListener('click', handlers.click);
369
+ this.input.addEventListener('focus', handlers.focus);
370
+ this.input.addEventListener('blur', handlers.commit);
371
+ this._handlers = handlers;
372
+ }
373
+ _onKeydown(e) {
374
+ if (this._handlers.redo && (e.keyCode === KEY_Z && e.shiftKey && (e.metaKey || e.ctrlKey) || e.keyCode === KEY_Y && e.ctrlKey)) {
375
+ e.preventDefault();
376
+ return this._handlers.redo(e);
377
+ }
378
+ if (this._handlers.undo && e.keyCode === KEY_Z && (e.metaKey || e.ctrlKey)) {
379
+ e.preventDefault();
380
+ return this._handlers.undo(e);
381
+ }
382
+ if (!e.isComposing) this._handlers.selectionChange(e);
383
+ }
384
+ _onBeforeinput(e) {
385
+ if (e.inputType === 'historyUndo' && this._handlers.undo) {
386
+ e.preventDefault();
387
+ return this._handlers.undo(e);
388
+ }
389
+ if (e.inputType === 'historyRedo' && this._handlers.redo) {
390
+ e.preventDefault();
391
+ return this._handlers.redo(e);
392
+ }
393
+ }
394
+ _onCompositionEnd(e) {
395
+ this._handlers.input(e);
396
+ }
397
+ _onInput(e) {
398
+ if (!e.isComposing) this._handlers.input(e);
399
+ }
400
+
401
+ /** Unbinds HTMLElement events to mask internal events */
402
+ unbindEvents() {
403
+ this.input.removeEventListener('keydown', this._onKeydown);
404
+ this.input.removeEventListener('input', this._onInput);
405
+ this.input.removeEventListener('beforeinput', this._onBeforeinput);
406
+ this.input.removeEventListener('compositionend', this._onCompositionEnd);
407
+ this.input.removeEventListener('drop', this._handlers.drop);
408
+ this.input.removeEventListener('click', this._handlers.click);
409
+ this.input.removeEventListener('focus', this._handlers.focus);
410
+ this.input.removeEventListener('blur', this._handlers.commit);
411
+ this._handlers = {};
412
+ }
413
+ }
414
+ IMask.HTMLMaskElement = HTMLMaskElement;
415
+
416
+ /** Bridge between InputElement and {@link Masked} */
417
+ class HTMLInputMaskElement extends HTMLMaskElement {
418
+ /** InputElement to use mask on */
419
+
420
+ constructor(input) {
421
+ super(input);
422
+ this.input = input;
423
+ }
424
+
425
+ /** Returns InputElement selection start */
426
+ get _unsafeSelectionStart() {
427
+ return this.input.selectionStart != null ? this.input.selectionStart : this.value.length;
428
+ }
429
+
430
+ /** Returns InputElement selection end */
431
+ get _unsafeSelectionEnd() {
432
+ return this.input.selectionEnd;
433
+ }
434
+
435
+ /** Sets InputElement selection */
436
+ _unsafeSelect(start, end) {
437
+ this.input.setSelectionRange(start, end);
438
+ }
439
+ get value() {
440
+ return this.input.value;
441
+ }
442
+ set value(value) {
443
+ this.input.value = value;
444
+ }
445
+ }
446
+ IMask.HTMLMaskElement = HTMLMaskElement;
447
+
448
+ class HTMLContenteditableMaskElement extends HTMLMaskElement {
449
+ /** Returns HTMLElement selection start */
450
+ get _unsafeSelectionStart() {
451
+ const root = this.rootElement;
452
+ const selection = root.getSelection && root.getSelection();
453
+ const anchorOffset = selection && selection.anchorOffset;
454
+ const focusOffset = selection && selection.focusOffset;
455
+ if (focusOffset == null || anchorOffset == null || anchorOffset < focusOffset) {
456
+ return anchorOffset;
457
+ }
458
+ return focusOffset;
459
+ }
460
+
461
+ /** Returns HTMLElement selection end */
462
+ get _unsafeSelectionEnd() {
463
+ const root = this.rootElement;
464
+ const selection = root.getSelection && root.getSelection();
465
+ const anchorOffset = selection && selection.anchorOffset;
466
+ const focusOffset = selection && selection.focusOffset;
467
+ if (focusOffset == null || anchorOffset == null || anchorOffset > focusOffset) {
468
+ return anchorOffset;
469
+ }
470
+ return focusOffset;
471
+ }
472
+
473
+ /** Sets HTMLElement selection */
474
+ _unsafeSelect(start, end) {
475
+ if (!this.rootElement.createRange) return;
476
+ const range = this.rootElement.createRange();
477
+ range.setStart(this.input.firstChild || this.input, start);
478
+ range.setEnd(this.input.lastChild || this.input, end);
479
+ const root = this.rootElement;
480
+ const selection = root.getSelection && root.getSelection();
481
+ if (selection) {
482
+ selection.removeAllRanges();
483
+ selection.addRange(range);
484
+ }
485
+ }
486
+
487
+ /** HTMLElement value */
488
+ get value() {
489
+ return this.input.textContent || '';
490
+ }
491
+ set value(value) {
492
+ this.input.textContent = value;
493
+ }
494
+ }
495
+ IMask.HTMLContenteditableMaskElement = HTMLContenteditableMaskElement;
496
+
497
+ class InputHistory {
498
+ constructor() {
499
+ this.states = [];
500
+ this.currentIndex = 0;
501
+ }
502
+ get currentState() {
503
+ return this.states[this.currentIndex];
504
+ }
505
+ get isEmpty() {
506
+ return this.states.length === 0;
507
+ }
508
+ push(state) {
509
+ // if current index points before the last element then remove the future
510
+ if (this.currentIndex < this.states.length - 1) this.states.length = this.currentIndex + 1;
511
+ this.states.push(state);
512
+ if (this.states.length > InputHistory.MAX_LENGTH) this.states.shift();
513
+ this.currentIndex = this.states.length - 1;
514
+ }
515
+ go(steps) {
516
+ this.currentIndex = Math.min(Math.max(this.currentIndex + steps, 0), this.states.length - 1);
517
+ return this.currentState;
518
+ }
519
+ undo() {
520
+ return this.go(-1);
521
+ }
522
+ redo() {
523
+ return this.go(+1);
524
+ }
525
+ clear() {
526
+ this.states.length = 0;
527
+ this.currentIndex = 0;
528
+ }
529
+ }
530
+ InputHistory.MAX_LENGTH = 100;
531
+
532
+ /** Listens to element events and controls changes between element and {@link Masked} */
533
+ class InputMask {
534
+ /**
535
+ View element
536
+ */
537
+
538
+ /** Internal {@link Masked} model */
539
+
540
+ constructor(el, opts) {
541
+ this.el = el instanceof MaskElement ? el : el.isContentEditable && el.tagName !== 'INPUT' && el.tagName !== 'TEXTAREA' ? new HTMLContenteditableMaskElement(el) : new HTMLInputMaskElement(el);
542
+ this.masked = createMask(opts);
543
+ this._listeners = {};
544
+ this._value = '';
545
+ this._unmaskedValue = '';
546
+ this._rawInputValue = '';
547
+ this.history = new InputHistory();
548
+ this._saveSelection = this._saveSelection.bind(this);
549
+ this._onInput = this._onInput.bind(this);
550
+ this._onChange = this._onChange.bind(this);
551
+ this._onDrop = this._onDrop.bind(this);
552
+ this._onFocus = this._onFocus.bind(this);
553
+ this._onClick = this._onClick.bind(this);
554
+ this._onUndo = this._onUndo.bind(this);
555
+ this._onRedo = this._onRedo.bind(this);
556
+ this.alignCursor = this.alignCursor.bind(this);
557
+ this.alignCursorFriendly = this.alignCursorFriendly.bind(this);
558
+ this._bindEvents();
559
+
560
+ // refresh
561
+ this.updateValue();
562
+ this._onChange();
563
+ }
564
+ maskEquals(mask) {
565
+ var _this$masked;
566
+ return mask == null || ((_this$masked = this.masked) == null ? void 0 : _this$masked.maskEquals(mask));
567
+ }
568
+
569
+ /** Masked */
570
+ get mask() {
571
+ return this.masked.mask;
572
+ }
573
+ set mask(mask) {
574
+ if (this.maskEquals(mask)) return;
575
+ if (!(mask instanceof IMask.Masked) && this.masked.constructor === maskedClass(mask)) {
576
+ // TODO "any" no idea
577
+ this.masked.updateOptions({
578
+ mask
579
+ });
580
+ return;
581
+ }
582
+ const masked = mask instanceof IMask.Masked ? mask : createMask({
583
+ mask
584
+ });
585
+ masked.unmaskedValue = this.masked.unmaskedValue;
586
+ this.masked = masked;
587
+ }
588
+
589
+ /** Raw value */
590
+ get value() {
591
+ return this._value;
592
+ }
593
+ set value(str) {
594
+ if (this.value === str) return;
595
+ this.masked.value = str;
596
+ this.updateControl('auto');
597
+ }
598
+
599
+ /** Unmasked value */
600
+ get unmaskedValue() {
601
+ return this._unmaskedValue;
602
+ }
603
+ set unmaskedValue(str) {
604
+ if (this.unmaskedValue === str) return;
605
+ this.masked.unmaskedValue = str;
606
+ this.updateControl('auto');
607
+ }
608
+
609
+ /** Raw input value */
610
+ get rawInputValue() {
611
+ return this._rawInputValue;
612
+ }
613
+ set rawInputValue(str) {
614
+ if (this.rawInputValue === str) return;
615
+ this.masked.rawInputValue = str;
616
+ this.updateControl();
617
+ this.alignCursor();
618
+ }
619
+
620
+ /** Typed unmasked value */
621
+ get typedValue() {
622
+ return this.masked.typedValue;
623
+ }
624
+ set typedValue(val) {
625
+ if (this.masked.typedValueEquals(val)) return;
626
+ this.masked.typedValue = val;
627
+ this.updateControl('auto');
628
+ }
629
+
630
+ /** Display value */
631
+ get displayValue() {
632
+ return this.masked.displayValue;
633
+ }
634
+
635
+ /** Starts listening to element events */
636
+ _bindEvents() {
637
+ this.el.bindEvents({
638
+ selectionChange: this._saveSelection,
639
+ input: this._onInput,
640
+ drop: this._onDrop,
641
+ click: this._onClick,
642
+ focus: this._onFocus,
643
+ commit: this._onChange,
644
+ undo: this._onUndo,
645
+ redo: this._onRedo
646
+ });
647
+ }
648
+
649
+ /** Stops listening to element events */
650
+ _unbindEvents() {
651
+ if (this.el) this.el.unbindEvents();
652
+ }
653
+
654
+ /** Fires custom event */
655
+ _fireEvent(ev, e) {
656
+ const listeners = this._listeners[ev];
657
+ if (!listeners) return;
658
+ listeners.forEach(l => l(e));
659
+ }
660
+
661
+ /** Current selection start */
662
+ get selectionStart() {
663
+ return this._cursorChanging ? this._changingCursorPos : this.el.selectionStart;
664
+ }
665
+
666
+ /** Current cursor position */
667
+ get cursorPos() {
668
+ return this._cursorChanging ? this._changingCursorPos : this.el.selectionEnd;
669
+ }
670
+ set cursorPos(pos) {
671
+ if (!this.el || !this.el.isActive) return;
672
+ this.el.select(pos, pos);
673
+ this._saveSelection();
674
+ }
675
+
676
+ /** Stores current selection */
677
+ _saveSelection( /* ev */
678
+ ) {
679
+ if (this.displayValue !== this.el.value) {
680
+ console.warn('Element value was changed outside of mask. Syncronize mask using `mask.updateValue()` to work properly.'); // eslint-disable-line no-console
681
+ }
682
+ this._selection = {
683
+ start: this.selectionStart,
684
+ end: this.cursorPos
685
+ };
686
+ }
687
+
688
+ /** Syncronizes model value from view */
689
+ updateValue() {
690
+ this.masked.value = this.el.value;
691
+ this._value = this.masked.value;
692
+ this._unmaskedValue = this.masked.unmaskedValue;
693
+ this._rawInputValue = this.masked.rawInputValue;
694
+ }
695
+
696
+ /** Syncronizes view from model value, fires change events */
697
+ updateControl(cursorPos) {
698
+ const newUnmaskedValue = this.masked.unmaskedValue;
699
+ const newValue = this.masked.value;
700
+ const newRawInputValue = this.masked.rawInputValue;
701
+ const newDisplayValue = this.displayValue;
702
+ const isChanged = this.unmaskedValue !== newUnmaskedValue || this.value !== newValue || this._rawInputValue !== newRawInputValue;
703
+ this._unmaskedValue = newUnmaskedValue;
704
+ this._value = newValue;
705
+ this._rawInputValue = newRawInputValue;
706
+ if (this.el.value !== newDisplayValue) this.el.value = newDisplayValue;
707
+ if (cursorPos === 'auto') this.alignCursor();else if (cursorPos != null) this.cursorPos = cursorPos;
708
+ if (isChanged) this._fireChangeEvents();
709
+ if (!this._historyChanging && (isChanged || this.history.isEmpty)) this.history.push({
710
+ unmaskedValue: newUnmaskedValue,
711
+ selection: {
712
+ start: this.selectionStart,
713
+ end: this.cursorPos
714
+ }
715
+ });
716
+ }
717
+
718
+ /** Updates options with deep equal check, recreates {@link Masked} model if mask type changes */
719
+ updateOptions(opts) {
720
+ const {
721
+ mask,
722
+ ...restOpts
723
+ } = opts; // TODO types, yes, mask is optional
724
+
725
+ const updateMask = !this.maskEquals(mask);
726
+ const updateOpts = this.masked.optionsIsChanged(restOpts);
727
+ if (updateMask) this.mask = mask;
728
+ if (updateOpts) this.masked.updateOptions(restOpts); // TODO
729
+
730
+ if (updateMask || updateOpts) this.updateControl();
731
+ }
732
+
733
+ /** Updates cursor */
734
+ updateCursor(cursorPos) {
735
+ if (cursorPos == null) return;
736
+ this.cursorPos = cursorPos;
737
+
738
+ // also queue change cursor for mobile browsers
739
+ this._delayUpdateCursor(cursorPos);
740
+ }
741
+
742
+ /** Delays cursor update to support mobile browsers */
743
+ _delayUpdateCursor(cursorPos) {
744
+ this._abortUpdateCursor();
745
+ this._changingCursorPos = cursorPos;
746
+ this._cursorChanging = setTimeout(() => {
747
+ if (!this.el) return; // if was destroyed
748
+ this.cursorPos = this._changingCursorPos;
749
+ this._abortUpdateCursor();
750
+ }, 10);
751
+ }
752
+
753
+ /** Fires custom events */
754
+ _fireChangeEvents() {
755
+ this._fireEvent('accept', this._inputEvent);
756
+ if (this.masked.isComplete) this._fireEvent('complete', this._inputEvent);
757
+ }
758
+
759
+ /** Aborts delayed cursor update */
760
+ _abortUpdateCursor() {
761
+ if (this._cursorChanging) {
762
+ clearTimeout(this._cursorChanging);
763
+ delete this._cursorChanging;
764
+ }
765
+ }
766
+
767
+ /** Aligns cursor to nearest available position */
768
+ alignCursor() {
769
+ this.cursorPos = this.masked.nearestInputPos(this.masked.nearestInputPos(this.cursorPos, DIRECTION.LEFT));
770
+ }
771
+
772
+ /** Aligns cursor only if selection is empty */
773
+ alignCursorFriendly() {
774
+ if (this.selectionStart !== this.cursorPos) return; // skip if range is selected
775
+ this.alignCursor();
776
+ }
777
+
778
+ /** Adds listener on custom event */
779
+ on(ev, handler) {
780
+ if (!this._listeners[ev]) this._listeners[ev] = [];
781
+ this._listeners[ev].push(handler);
782
+ return this;
783
+ }
784
+
785
+ /** Removes custom event listener */
786
+ off(ev, handler) {
787
+ if (!this._listeners[ev]) return this;
788
+ if (!handler) {
789
+ delete this._listeners[ev];
790
+ return this;
791
+ }
792
+ const hIndex = this._listeners[ev].indexOf(handler);
793
+ if (hIndex >= 0) this._listeners[ev].splice(hIndex, 1);
794
+ return this;
795
+ }
796
+
797
+ /** Handles view input event */
798
+ _onInput(e) {
799
+ this._inputEvent = e;
800
+ this._abortUpdateCursor();
801
+ const details = new ActionDetails({
802
+ // new state
803
+ value: this.el.value,
804
+ cursorPos: this.cursorPos,
805
+ // old state
806
+ oldValue: this.displayValue,
807
+ oldSelection: this._selection
808
+ });
809
+ const oldRawValue = this.masked.rawInputValue;
810
+ const offset = this.masked.splice(details.startChangePos, details.removed.length, details.inserted, details.removeDirection, {
811
+ input: true,
812
+ raw: true
813
+ }).offset;
814
+
815
+ // force align in remove direction only if no input chars were removed
816
+ // otherwise we still need to align with NONE (to get out from fixed symbols for instance)
817
+ const removeDirection = oldRawValue === this.masked.rawInputValue ? details.removeDirection : DIRECTION.NONE;
818
+ let cursorPos = this.masked.nearestInputPos(details.startChangePos + offset, removeDirection);
819
+ if (removeDirection !== DIRECTION.NONE) cursorPos = this.masked.nearestInputPos(cursorPos, DIRECTION.NONE);
820
+ this.updateControl(cursorPos);
821
+ delete this._inputEvent;
822
+ }
823
+
824
+ /** Handles view change event and commits model value */
825
+ _onChange() {
826
+ if (this.displayValue !== this.el.value) this.updateValue();
827
+ this.masked.doCommit();
828
+ this.updateControl();
829
+ this._saveSelection();
830
+ }
831
+
832
+ /** Handles view drop event, prevents by default */
833
+ _onDrop(ev) {
834
+ ev.preventDefault();
835
+ ev.stopPropagation();
836
+ }
837
+
838
+ /** Restore last selection on focus */
839
+ _onFocus(ev) {
840
+ this.alignCursorFriendly();
841
+ }
842
+
843
+ /** Restore last selection on focus */
844
+ _onClick(ev) {
845
+ this.alignCursorFriendly();
846
+ }
847
+ _onUndo() {
848
+ this._applyHistoryState(this.history.undo());
849
+ }
850
+ _onRedo() {
851
+ this._applyHistoryState(this.history.redo());
852
+ }
853
+ _applyHistoryState(state) {
854
+ if (!state) return;
855
+ this._historyChanging = true;
856
+ this.unmaskedValue = state.unmaskedValue;
857
+ this.el.select(state.selection.start, state.selection.end);
858
+ this._saveSelection();
859
+ this._historyChanging = false;
860
+ }
861
+
862
+ /** Unbind view events and removes element reference */
863
+ destroy() {
864
+ this._unbindEvents();
865
+ this._listeners.length = 0;
866
+ delete this.el;
867
+ }
868
+ }
869
+ IMask.InputMask = InputMask;
870
+
871
+ /** Provides details of changing model value */
872
+ class ChangeDetails {
873
+ /** Inserted symbols */
874
+
875
+ /** Additional offset if any changes occurred before tail */
876
+
877
+ /** Raw inserted is used by dynamic mask */
878
+
879
+ /** Can skip chars */
880
+
881
+ static normalize(prep) {
882
+ return Array.isArray(prep) ? prep : [prep, new ChangeDetails()];
883
+ }
884
+ constructor(details) {
885
+ Object.assign(this, {
886
+ inserted: '',
887
+ rawInserted: '',
888
+ tailShift: 0,
889
+ skip: false
890
+ }, details);
891
+ }
892
+
893
+ /** Aggregate changes */
894
+ aggregate(details) {
895
+ this.inserted += details.inserted;
896
+ this.rawInserted += details.rawInserted;
897
+ this.tailShift += details.tailShift;
898
+ this.skip = this.skip || details.skip;
899
+ return this;
900
+ }
901
+
902
+ /** Total offset considering all changes */
903
+ get offset() {
904
+ return this.tailShift + this.inserted.length;
905
+ }
906
+ get consumed() {
907
+ return Boolean(this.rawInserted) || this.skip;
908
+ }
909
+ equals(details) {
910
+ return this.inserted === details.inserted && this.tailShift === details.tailShift && this.rawInserted === details.rawInserted && this.skip === details.skip;
911
+ }
912
+ }
913
+ IMask.ChangeDetails = ChangeDetails;
914
+
915
+ /** Provides details of continuous extracted tail */
916
+ class ContinuousTailDetails {
917
+ /** Tail value as string */
918
+
919
+ /** Tail start position */
920
+
921
+ /** Start position */
922
+
923
+ constructor(value, from, stop) {
924
+ if (value === void 0) {
925
+ value = '';
926
+ }
927
+ if (from === void 0) {
928
+ from = 0;
929
+ }
930
+ this.value = value;
931
+ this.from = from;
932
+ this.stop = stop;
933
+ }
934
+ toString() {
935
+ return this.value;
936
+ }
937
+ extend(tail) {
938
+ this.value += String(tail);
939
+ }
940
+ appendTo(masked) {
941
+ return masked.append(this.toString(), {
942
+ tail: true
943
+ }).aggregate(masked._appendPlaceholder());
944
+ }
945
+ get state() {
946
+ return {
947
+ value: this.value,
948
+ from: this.from,
949
+ stop: this.stop
950
+ };
951
+ }
952
+ set state(state) {
953
+ Object.assign(this, state);
954
+ }
955
+ unshift(beforePos) {
956
+ if (!this.value.length || beforePos != null && this.from >= beforePos) return '';
957
+ const shiftChar = this.value[0];
958
+ this.value = this.value.slice(1);
959
+ return shiftChar;
960
+ }
961
+ shift() {
962
+ if (!this.value.length) return '';
963
+ const shiftChar = this.value[this.value.length - 1];
964
+ this.value = this.value.slice(0, -1);
965
+ return shiftChar;
966
+ }
967
+ }
968
+
969
+ /** Append flags */
970
+
971
+ /** Extract flags */
972
+
973
+ // see https://github.com/microsoft/TypeScript/issues/6223
974
+
975
+ /** Provides common masking stuff */
976
+ class Masked {
977
+ /** */
978
+
979
+ /** */
980
+
981
+ /** Transforms value before mask processing */
982
+
983
+ /** Transforms each char before mask processing */
984
+
985
+ /** Validates if value is acceptable */
986
+
987
+ /** Does additional processing at the end of editing */
988
+
989
+ /** Format typed value to string */
990
+
991
+ /** Parse string to get typed value */
992
+
993
+ /** Enable characters overwriting */
994
+
995
+ /** */
996
+
997
+ /** */
998
+
999
+ /** */
1000
+
1001
+ /** */
1002
+
1003
+ constructor(opts) {
1004
+ this._value = '';
1005
+ this._update({
1006
+ ...Masked.DEFAULTS,
1007
+ ...opts
1008
+ });
1009
+ this._initialized = true;
1010
+ }
1011
+
1012
+ /** Sets and applies new options */
1013
+ updateOptions(opts) {
1014
+ if (!this.optionsIsChanged(opts)) return;
1015
+ this.withValueRefresh(this._update.bind(this, opts));
1016
+ }
1017
+
1018
+ /** Sets new options */
1019
+ _update(opts) {
1020
+ Object.assign(this, opts);
1021
+ }
1022
+
1023
+ /** Mask state */
1024
+ get state() {
1025
+ return {
1026
+ _value: this.value,
1027
+ _rawInputValue: this.rawInputValue
1028
+ };
1029
+ }
1030
+ set state(state) {
1031
+ this._value = state._value;
1032
+ }
1033
+
1034
+ /** Resets value */
1035
+ reset() {
1036
+ this._value = '';
1037
+ }
1038
+ get value() {
1039
+ return this._value;
1040
+ }
1041
+ set value(value) {
1042
+ this.resolve(value, {
1043
+ input: true
1044
+ });
1045
+ }
1046
+
1047
+ /** Resolve new value */
1048
+ resolve(value, flags) {
1049
+ if (flags === void 0) {
1050
+ flags = {
1051
+ input: true
1052
+ };
1053
+ }
1054
+ this.reset();
1055
+ this.append(value, flags, '');
1056
+ this.doCommit();
1057
+ }
1058
+ get unmaskedValue() {
1059
+ return this.value;
1060
+ }
1061
+ set unmaskedValue(value) {
1062
+ this.resolve(value, {});
1063
+ }
1064
+ get typedValue() {
1065
+ return this.parse ? this.parse(this.value, this) : this.unmaskedValue;
1066
+ }
1067
+ set typedValue(value) {
1068
+ if (this.format) {
1069
+ this.value = this.format(value, this);
1070
+ } else {
1071
+ this.unmaskedValue = String(value);
1072
+ }
1073
+ }
1074
+
1075
+ /** Value that includes raw user input */
1076
+ get rawInputValue() {
1077
+ return this.extractInput(0, this.displayValue.length, {
1078
+ raw: true
1079
+ });
1080
+ }
1081
+ set rawInputValue(value) {
1082
+ this.resolve(value, {
1083
+ raw: true
1084
+ });
1085
+ }
1086
+ get displayValue() {
1087
+ return this.value;
1088
+ }
1089
+ get isComplete() {
1090
+ return true;
1091
+ }
1092
+ get isFilled() {
1093
+ return this.isComplete;
1094
+ }
1095
+
1096
+ /** Finds nearest input position in direction */
1097
+ nearestInputPos(cursorPos, direction) {
1098
+ return cursorPos;
1099
+ }
1100
+ totalInputPositions(fromPos, toPos) {
1101
+ if (fromPos === void 0) {
1102
+ fromPos = 0;
1103
+ }
1104
+ if (toPos === void 0) {
1105
+ toPos = this.displayValue.length;
1106
+ }
1107
+ return Math.min(this.displayValue.length, toPos - fromPos);
1108
+ }
1109
+
1110
+ /** Extracts value in range considering flags */
1111
+ extractInput(fromPos, toPos, flags) {
1112
+ if (fromPos === void 0) {
1113
+ fromPos = 0;
1114
+ }
1115
+ if (toPos === void 0) {
1116
+ toPos = this.displayValue.length;
1117
+ }
1118
+ return this.displayValue.slice(fromPos, toPos);
1119
+ }
1120
+
1121
+ /** Extracts tail in range */
1122
+ extractTail(fromPos, toPos) {
1123
+ if (fromPos === void 0) {
1124
+ fromPos = 0;
1125
+ }
1126
+ if (toPos === void 0) {
1127
+ toPos = this.displayValue.length;
1128
+ }
1129
+ return new ContinuousTailDetails(this.extractInput(fromPos, toPos), fromPos);
1130
+ }
1131
+
1132
+ /** Appends tail */
1133
+ appendTail(tail) {
1134
+ if (isString(tail)) tail = new ContinuousTailDetails(String(tail));
1135
+ return tail.appendTo(this);
1136
+ }
1137
+
1138
+ /** Appends char */
1139
+ _appendCharRaw(ch, flags) {
1140
+ if (!ch) return new ChangeDetails();
1141
+ this._value += ch;
1142
+ return new ChangeDetails({
1143
+ inserted: ch,
1144
+ rawInserted: ch
1145
+ });
1146
+ }
1147
+
1148
+ /** Appends char */
1149
+ _appendChar(ch, flags, checkTail) {
1150
+ if (flags === void 0) {
1151
+ flags = {};
1152
+ }
1153
+ const consistentState = this.state;
1154
+ let details;
1155
+ [ch, details] = this.doPrepareChar(ch, flags);
1156
+ if (ch) {
1157
+ details = details.aggregate(this._appendCharRaw(ch, flags));
1158
+
1159
+ // TODO handle `skip`?
1160
+
1161
+ // try `autofix` lookahead
1162
+ if (!details.rawInserted && this.autofix === 'pad') {
1163
+ const noFixState = this.state;
1164
+ this.state = consistentState;
1165
+ let fixDetails = this.pad(flags);
1166
+ const chDetails = this._appendCharRaw(ch, flags);
1167
+ fixDetails = fixDetails.aggregate(chDetails);
1168
+
1169
+ // if fix was applied or
1170
+ // if details are equal use skip restoring state optimization
1171
+ if (chDetails.rawInserted || fixDetails.equals(details)) {
1172
+ details = fixDetails;
1173
+ } else {
1174
+ this.state = noFixState;
1175
+ }
1176
+ }
1177
+ }
1178
+ if (details.inserted) {
1179
+ let consistentTail;
1180
+ let appended = this.doValidate(flags) !== false;
1181
+ if (appended && checkTail != null) {
1182
+ // validation ok, check tail
1183
+ const beforeTailState = this.state;
1184
+ if (this.overwrite === true) {
1185
+ consistentTail = checkTail.state;
1186
+ for (let i = 0; i < details.rawInserted.length; ++i) {
1187
+ checkTail.unshift(this.displayValue.length - details.tailShift);
1188
+ }
1189
+ }
1190
+ let tailDetails = this.appendTail(checkTail);
1191
+ appended = tailDetails.rawInserted.length === checkTail.toString().length;
1192
+
1193
+ // not ok, try shift
1194
+ if (!(appended && tailDetails.inserted) && this.overwrite === 'shift') {
1195
+ this.state = beforeTailState;
1196
+ consistentTail = checkTail.state;
1197
+ for (let i = 0; i < details.rawInserted.length; ++i) {
1198
+ checkTail.shift();
1199
+ }
1200
+ tailDetails = this.appendTail(checkTail);
1201
+ appended = tailDetails.rawInserted.length === checkTail.toString().length;
1202
+ }
1203
+
1204
+ // if ok, rollback state after tail
1205
+ if (appended && tailDetails.inserted) this.state = beforeTailState;
1206
+ }
1207
+
1208
+ // revert all if something went wrong
1209
+ if (!appended) {
1210
+ details = new ChangeDetails();
1211
+ this.state = consistentState;
1212
+ if (checkTail && consistentTail) checkTail.state = consistentTail;
1213
+ }
1214
+ }
1215
+ return details;
1216
+ }
1217
+
1218
+ /** Appends optional placeholder at the end */
1219
+ _appendPlaceholder() {
1220
+ return new ChangeDetails();
1221
+ }
1222
+
1223
+ /** Appends optional eager placeholder at the end */
1224
+ _appendEager() {
1225
+ return new ChangeDetails();
1226
+ }
1227
+
1228
+ /** Appends symbols considering flags */
1229
+ append(str, flags, tail) {
1230
+ if (!isString(str)) throw new Error('value should be string');
1231
+ const checkTail = isString(tail) ? new ContinuousTailDetails(String(tail)) : tail;
1232
+ if (flags != null && flags.tail) flags._beforeTailState = this.state;
1233
+ let details;
1234
+ [str, details] = this.doPrepare(str, flags);
1235
+ for (let ci = 0; ci < str.length; ++ci) {
1236
+ const d = this._appendChar(str[ci], flags, checkTail);
1237
+ if (!d.rawInserted && !this.doSkipInvalid(str[ci], flags, checkTail)) break;
1238
+ details.aggregate(d);
1239
+ }
1240
+ if ((this.eager === true || this.eager === 'append') && flags != null && flags.input && str) {
1241
+ details.aggregate(this._appendEager());
1242
+ }
1243
+
1244
+ // append tail but aggregate only tailShift
1245
+ if (checkTail != null) {
1246
+ details.tailShift += this.appendTail(checkTail).tailShift;
1247
+ // TODO it's a good idea to clear state after appending ends
1248
+ // but it causes bugs when one append calls another (when dynamic dispatch set rawInputValue)
1249
+ // this._resetBeforeTailState();
1250
+ }
1251
+ return details;
1252
+ }
1253
+ remove(fromPos, toPos) {
1254
+ if (fromPos === void 0) {
1255
+ fromPos = 0;
1256
+ }
1257
+ if (toPos === void 0) {
1258
+ toPos = this.displayValue.length;
1259
+ }
1260
+ this._value = this.displayValue.slice(0, fromPos) + this.displayValue.slice(toPos);
1261
+ return new ChangeDetails();
1262
+ }
1263
+
1264
+ /** Calls function and reapplies current value */
1265
+ withValueRefresh(fn) {
1266
+ if (this._refreshing || !this._initialized) return fn();
1267
+ this._refreshing = true;
1268
+ const rawInput = this.rawInputValue;
1269
+ const value = this.value;
1270
+ const ret = fn();
1271
+ this.rawInputValue = rawInput;
1272
+ // append lost trailing chars at the end
1273
+ if (this.value && this.value !== value && value.indexOf(this.value) === 0) {
1274
+ this.append(value.slice(this.displayValue.length), {}, '');
1275
+ this.doCommit();
1276
+ }
1277
+ delete this._refreshing;
1278
+ return ret;
1279
+ }
1280
+ runIsolated(fn) {
1281
+ if (this._isolated || !this._initialized) return fn(this);
1282
+ this._isolated = true;
1283
+ const state = this.state;
1284
+ const ret = fn(this);
1285
+ this.state = state;
1286
+ delete this._isolated;
1287
+ return ret;
1288
+ }
1289
+ doSkipInvalid(ch, flags, checkTail) {
1290
+ return Boolean(this.skipInvalid);
1291
+ }
1292
+
1293
+ /** Prepares string before mask processing */
1294
+ doPrepare(str, flags) {
1295
+ if (flags === void 0) {
1296
+ flags = {};
1297
+ }
1298
+ return ChangeDetails.normalize(this.prepare ? this.prepare(str, this, flags) : str);
1299
+ }
1300
+
1301
+ /** Prepares each char before mask processing */
1302
+ doPrepareChar(str, flags) {
1303
+ if (flags === void 0) {
1304
+ flags = {};
1305
+ }
1306
+ return ChangeDetails.normalize(this.prepareChar ? this.prepareChar(str, this, flags) : str);
1307
+ }
1308
+
1309
+ /** Validates if value is acceptable */
1310
+ doValidate(flags) {
1311
+ return (!this.validate || this.validate(this.value, this, flags)) && (!this.parent || this.parent.doValidate(flags));
1312
+ }
1313
+
1314
+ /** Does additional processing at the end of editing */
1315
+ doCommit() {
1316
+ if (this.commit) this.commit(this.value, this);
1317
+ }
1318
+ splice(start, deleteCount, inserted, removeDirection, flags) {
1319
+ if (inserted === void 0) {
1320
+ inserted = '';
1321
+ }
1322
+ if (removeDirection === void 0) {
1323
+ removeDirection = DIRECTION.NONE;
1324
+ }
1325
+ if (flags === void 0) {
1326
+ flags = {
1327
+ input: true
1328
+ };
1329
+ }
1330
+ const tailPos = start + deleteCount;
1331
+ const tail = this.extractTail(tailPos);
1332
+ const eagerRemove = this.eager === true || this.eager === 'remove';
1333
+ let oldRawValue;
1334
+ if (eagerRemove) {
1335
+ removeDirection = forceDirection(removeDirection);
1336
+ oldRawValue = this.extractInput(0, tailPos, {
1337
+ raw: true
1338
+ });
1339
+ }
1340
+ let startChangePos = start;
1341
+ const details = new ChangeDetails();
1342
+
1343
+ // if it is just deletion without insertion
1344
+ if (removeDirection !== DIRECTION.NONE) {
1345
+ startChangePos = this.nearestInputPos(start, deleteCount > 1 && start !== 0 && !eagerRemove ? DIRECTION.NONE : removeDirection);
1346
+
1347
+ // adjust tailShift if start was aligned
1348
+ details.tailShift = startChangePos - start;
1349
+ }
1350
+ details.aggregate(this.remove(startChangePos));
1351
+ if (eagerRemove && removeDirection !== DIRECTION.NONE && oldRawValue === this.rawInputValue) {
1352
+ if (removeDirection === DIRECTION.FORCE_LEFT) {
1353
+ let valLength;
1354
+ while (oldRawValue === this.rawInputValue && (valLength = this.displayValue.length)) {
1355
+ details.aggregate(new ChangeDetails({
1356
+ tailShift: -1
1357
+ })).aggregate(this.remove(valLength - 1));
1358
+ }
1359
+ } else if (removeDirection === DIRECTION.FORCE_RIGHT) {
1360
+ tail.unshift();
1361
+ }
1362
+ }
1363
+ return details.aggregate(this.append(inserted, flags, tail));
1364
+ }
1365
+ maskEquals(mask) {
1366
+ return this.mask === mask;
1367
+ }
1368
+ optionsIsChanged(opts) {
1369
+ return !objectIncludes(this, opts);
1370
+ }
1371
+ typedValueEquals(value) {
1372
+ const tval = this.typedValue;
1373
+ return value === tval || Masked.EMPTY_VALUES.includes(value) && Masked.EMPTY_VALUES.includes(tval) || (this.format ? this.format(value, this) === this.format(this.typedValue, this) : false);
1374
+ }
1375
+ pad(flags) {
1376
+ return new ChangeDetails();
1377
+ }
1378
+ }
1379
+ Masked.DEFAULTS = {
1380
+ skipInvalid: true
1381
+ };
1382
+ Masked.EMPTY_VALUES = [undefined, null, ''];
1383
+ IMask.Masked = Masked;
1384
+
1385
+ class ChunksTailDetails {
1386
+ /** */
1387
+
1388
+ constructor(chunks, from) {
1389
+ if (chunks === void 0) {
1390
+ chunks = [];
1391
+ }
1392
+ if (from === void 0) {
1393
+ from = 0;
1394
+ }
1395
+ this.chunks = chunks;
1396
+ this.from = from;
1397
+ }
1398
+ toString() {
1399
+ return this.chunks.map(String).join('');
1400
+ }
1401
+ extend(tailChunk) {
1402
+ if (!String(tailChunk)) return;
1403
+ tailChunk = isString(tailChunk) ? new ContinuousTailDetails(String(tailChunk)) : tailChunk;
1404
+ const lastChunk = this.chunks[this.chunks.length - 1];
1405
+ const extendLast = lastChunk && (
1406
+ // if stops are same or tail has no stop
1407
+ lastChunk.stop === tailChunk.stop || tailChunk.stop == null) &&
1408
+ // if tail chunk goes just after last chunk
1409
+ tailChunk.from === lastChunk.from + lastChunk.toString().length;
1410
+ if (tailChunk instanceof ContinuousTailDetails) {
1411
+ // check the ability to extend previous chunk
1412
+ if (extendLast) {
1413
+ // extend previous chunk
1414
+ lastChunk.extend(tailChunk.toString());
1415
+ } else {
1416
+ // append new chunk
1417
+ this.chunks.push(tailChunk);
1418
+ }
1419
+ } else if (tailChunk instanceof ChunksTailDetails) {
1420
+ if (tailChunk.stop == null) {
1421
+ // unwrap floating chunks to parent, keeping `from` pos
1422
+ let firstTailChunk;
1423
+ while (tailChunk.chunks.length && tailChunk.chunks[0].stop == null) {
1424
+ firstTailChunk = tailChunk.chunks.shift(); // not possible to be `undefined` because length was checked above
1425
+ firstTailChunk.from += tailChunk.from;
1426
+ this.extend(firstTailChunk);
1427
+ }
1428
+ }
1429
+
1430
+ // if tail chunk still has value
1431
+ if (tailChunk.toString()) {
1432
+ // if chunks contains stops, then popup stop to container
1433
+ tailChunk.stop = tailChunk.blockIndex;
1434
+ this.chunks.push(tailChunk);
1435
+ }
1436
+ }
1437
+ }
1438
+ appendTo(masked) {
1439
+ if (!(masked instanceof IMask.MaskedPattern)) {
1440
+ const tail = new ContinuousTailDetails(this.toString());
1441
+ return tail.appendTo(masked);
1442
+ }
1443
+ const details = new ChangeDetails();
1444
+ for (let ci = 0; ci < this.chunks.length; ++ci) {
1445
+ const chunk = this.chunks[ci];
1446
+ const lastBlockIter = masked._mapPosToBlock(masked.displayValue.length);
1447
+ const stop = chunk.stop;
1448
+ let chunkBlock;
1449
+ if (stop != null && (
1450
+ // if block not found or stop is behind lastBlock
1451
+ !lastBlockIter || lastBlockIter.index <= stop)) {
1452
+ if (chunk instanceof ChunksTailDetails ||
1453
+ // for continuous block also check if stop is exist
1454
+ masked._stops.indexOf(stop) >= 0) {
1455
+ details.aggregate(masked._appendPlaceholder(stop));
1456
+ }
1457
+ chunkBlock = chunk instanceof ChunksTailDetails && masked._blocks[stop];
1458
+ }
1459
+ if (chunkBlock) {
1460
+ const tailDetails = chunkBlock.appendTail(chunk);
1461
+ details.aggregate(tailDetails);
1462
+
1463
+ // get not inserted chars
1464
+ const remainChars = chunk.toString().slice(tailDetails.rawInserted.length);
1465
+ if (remainChars) details.aggregate(masked.append(remainChars, {
1466
+ tail: true
1467
+ }));
1468
+ } else {
1469
+ details.aggregate(masked.append(chunk.toString(), {
1470
+ tail: true
1471
+ }));
1472
+ }
1473
+ }
1474
+ return details;
1475
+ }
1476
+ get state() {
1477
+ return {
1478
+ chunks: this.chunks.map(c => c.state),
1479
+ from: this.from,
1480
+ stop: this.stop,
1481
+ blockIndex: this.blockIndex
1482
+ };
1483
+ }
1484
+ set state(state) {
1485
+ const {
1486
+ chunks,
1487
+ ...props
1488
+ } = state;
1489
+ Object.assign(this, props);
1490
+ this.chunks = chunks.map(cstate => {
1491
+ const chunk = "chunks" in cstate ? new ChunksTailDetails() : new ContinuousTailDetails();
1492
+ chunk.state = cstate;
1493
+ return chunk;
1494
+ });
1495
+ }
1496
+ unshift(beforePos) {
1497
+ if (!this.chunks.length || beforePos != null && this.from >= beforePos) return '';
1498
+ const chunkShiftPos = beforePos != null ? beforePos - this.from : beforePos;
1499
+ let ci = 0;
1500
+ while (ci < this.chunks.length) {
1501
+ const chunk = this.chunks[ci];
1502
+ const shiftChar = chunk.unshift(chunkShiftPos);
1503
+ if (chunk.toString()) {
1504
+ // chunk still contains value
1505
+ // but not shifted - means no more available chars to shift
1506
+ if (!shiftChar) break;
1507
+ ++ci;
1508
+ } else {
1509
+ // clean if chunk has no value
1510
+ this.chunks.splice(ci, 1);
1511
+ }
1512
+ if (shiftChar) return shiftChar;
1513
+ }
1514
+ return '';
1515
+ }
1516
+ shift() {
1517
+ if (!this.chunks.length) return '';
1518
+ let ci = this.chunks.length - 1;
1519
+ while (0 <= ci) {
1520
+ const chunk = this.chunks[ci];
1521
+ const shiftChar = chunk.shift();
1522
+ if (chunk.toString()) {
1523
+ // chunk still contains value
1524
+ // but not shifted - means no more available chars to shift
1525
+ if (!shiftChar) break;
1526
+ --ci;
1527
+ } else {
1528
+ // clean if chunk has no value
1529
+ this.chunks.splice(ci, 1);
1530
+ }
1531
+ if (shiftChar) return shiftChar;
1532
+ }
1533
+ return '';
1534
+ }
1535
+ }
1536
+
1537
+ class PatternCursor {
1538
+ constructor(masked, pos) {
1539
+ this.masked = masked;
1540
+ this._log = [];
1541
+ const {
1542
+ offset,
1543
+ index
1544
+ } = masked._mapPosToBlock(pos) || (pos < 0 ?
1545
+ // first
1546
+ {
1547
+ index: 0,
1548
+ offset: 0
1549
+ } :
1550
+ // last
1551
+ {
1552
+ index: this.masked._blocks.length,
1553
+ offset: 0
1554
+ });
1555
+ this.offset = offset;
1556
+ this.index = index;
1557
+ this.ok = false;
1558
+ }
1559
+ get block() {
1560
+ return this.masked._blocks[this.index];
1561
+ }
1562
+ get pos() {
1563
+ return this.masked._blockStartPos(this.index) + this.offset;
1564
+ }
1565
+ get state() {
1566
+ return {
1567
+ index: this.index,
1568
+ offset: this.offset,
1569
+ ok: this.ok
1570
+ };
1571
+ }
1572
+ set state(s) {
1573
+ Object.assign(this, s);
1574
+ }
1575
+ pushState() {
1576
+ this._log.push(this.state);
1577
+ }
1578
+ popState() {
1579
+ const s = this._log.pop();
1580
+ if (s) this.state = s;
1581
+ return s;
1582
+ }
1583
+ bindBlock() {
1584
+ if (this.block) return;
1585
+ if (this.index < 0) {
1586
+ this.index = 0;
1587
+ this.offset = 0;
1588
+ }
1589
+ if (this.index >= this.masked._blocks.length) {
1590
+ this.index = this.masked._blocks.length - 1;
1591
+ this.offset = this.block.displayValue.length; // TODO this is stupid type error, `block` depends on index that was changed above
1592
+ }
1593
+ }
1594
+ _pushLeft(fn) {
1595
+ this.pushState();
1596
+ for (this.bindBlock(); 0 <= this.index; --this.index, this.offset = ((_this$block = this.block) == null ? void 0 : _this$block.displayValue.length) || 0) {
1597
+ var _this$block;
1598
+ if (fn()) return this.ok = true;
1599
+ }
1600
+ return this.ok = false;
1601
+ }
1602
+ _pushRight(fn) {
1603
+ this.pushState();
1604
+ for (this.bindBlock(); this.index < this.masked._blocks.length; ++this.index, this.offset = 0) {
1605
+ if (fn()) return this.ok = true;
1606
+ }
1607
+ return this.ok = false;
1608
+ }
1609
+ pushLeftBeforeFilled() {
1610
+ return this._pushLeft(() => {
1611
+ if (this.block.isFixed || !this.block.value) return;
1612
+ this.offset = this.block.nearestInputPos(this.offset, DIRECTION.FORCE_LEFT);
1613
+ if (this.offset !== 0) return true;
1614
+ });
1615
+ }
1616
+ pushLeftBeforeInput() {
1617
+ // cases:
1618
+ // filled input: 00|
1619
+ // optional empty input: 00[]|
1620
+ // nested block: XX<[]>|
1621
+ return this._pushLeft(() => {
1622
+ if (this.block.isFixed) return;
1623
+ this.offset = this.block.nearestInputPos(this.offset, DIRECTION.LEFT);
1624
+ return true;
1625
+ });
1626
+ }
1627
+ pushLeftBeforeRequired() {
1628
+ return this._pushLeft(() => {
1629
+ if (this.block.isFixed || this.block.isOptional && !this.block.value) return;
1630
+ this.offset = this.block.nearestInputPos(this.offset, DIRECTION.LEFT);
1631
+ return true;
1632
+ });
1633
+ }
1634
+ pushRightBeforeFilled() {
1635
+ return this._pushRight(() => {
1636
+ if (this.block.isFixed || !this.block.value) return;
1637
+ this.offset = this.block.nearestInputPos(this.offset, DIRECTION.FORCE_RIGHT);
1638
+ if (this.offset !== this.block.value.length) return true;
1639
+ });
1640
+ }
1641
+ pushRightBeforeInput() {
1642
+ return this._pushRight(() => {
1643
+ if (this.block.isFixed) return;
1644
+
1645
+ // const o = this.offset;
1646
+ this.offset = this.block.nearestInputPos(this.offset, DIRECTION.NONE);
1647
+ // HACK cases like (STILL DOES NOT WORK FOR NESTED)
1648
+ // aa|X
1649
+ // aa<X|[]>X_ - this will not work
1650
+ // if (o && o === this.offset && this.block instanceof PatternInputDefinition) continue;
1651
+ return true;
1652
+ });
1653
+ }
1654
+ pushRightBeforeRequired() {
1655
+ return this._pushRight(() => {
1656
+ if (this.block.isFixed || this.block.isOptional && !this.block.value) return;
1657
+
1658
+ // TODO check |[*]XX_
1659
+ this.offset = this.block.nearestInputPos(this.offset, DIRECTION.NONE);
1660
+ return true;
1661
+ });
1662
+ }
1663
+ }
1664
+
1665
+ class PatternFixedDefinition {
1666
+ /** */
1667
+
1668
+ /** */
1669
+
1670
+ /** */
1671
+
1672
+ /** */
1673
+
1674
+ /** */
1675
+
1676
+ /** */
1677
+
1678
+ constructor(opts) {
1679
+ Object.assign(this, opts);
1680
+ this._value = '';
1681
+ this.isFixed = true;
1682
+ }
1683
+ get value() {
1684
+ return this._value;
1685
+ }
1686
+ get unmaskedValue() {
1687
+ return this.isUnmasking ? this.value : '';
1688
+ }
1689
+ get rawInputValue() {
1690
+ return this._isRawInput ? this.value : '';
1691
+ }
1692
+ get displayValue() {
1693
+ return this.value;
1694
+ }
1695
+ reset() {
1696
+ this._isRawInput = false;
1697
+ this._value = '';
1698
+ }
1699
+ remove(fromPos, toPos) {
1700
+ if (fromPos === void 0) {
1701
+ fromPos = 0;
1702
+ }
1703
+ if (toPos === void 0) {
1704
+ toPos = this._value.length;
1705
+ }
1706
+ this._value = this._value.slice(0, fromPos) + this._value.slice(toPos);
1707
+ if (!this._value) this._isRawInput = false;
1708
+ return new ChangeDetails();
1709
+ }
1710
+ nearestInputPos(cursorPos, direction) {
1711
+ if (direction === void 0) {
1712
+ direction = DIRECTION.NONE;
1713
+ }
1714
+ const minPos = 0;
1715
+ const maxPos = this._value.length;
1716
+ switch (direction) {
1717
+ case DIRECTION.LEFT:
1718
+ case DIRECTION.FORCE_LEFT:
1719
+ return minPos;
1720
+ case DIRECTION.NONE:
1721
+ case DIRECTION.RIGHT:
1722
+ case DIRECTION.FORCE_RIGHT:
1723
+ default:
1724
+ return maxPos;
1725
+ }
1726
+ }
1727
+ totalInputPositions(fromPos, toPos) {
1728
+ if (fromPos === void 0) {
1729
+ fromPos = 0;
1730
+ }
1731
+ if (toPos === void 0) {
1732
+ toPos = this._value.length;
1733
+ }
1734
+ return this._isRawInput ? toPos - fromPos : 0;
1735
+ }
1736
+ extractInput(fromPos, toPos, flags) {
1737
+ if (fromPos === void 0) {
1738
+ fromPos = 0;
1739
+ }
1740
+ if (toPos === void 0) {
1741
+ toPos = this._value.length;
1742
+ }
1743
+ if (flags === void 0) {
1744
+ flags = {};
1745
+ }
1746
+ return flags.raw && this._isRawInput && this._value.slice(fromPos, toPos) || '';
1747
+ }
1748
+ get isComplete() {
1749
+ return true;
1750
+ }
1751
+ get isFilled() {
1752
+ return Boolean(this._value);
1753
+ }
1754
+ _appendChar(ch, flags) {
1755
+ if (flags === void 0) {
1756
+ flags = {};
1757
+ }
1758
+ if (this.isFilled) return new ChangeDetails();
1759
+ const appendEager = this.eager === true || this.eager === 'append';
1760
+ const appended = this.char === ch;
1761
+ const isResolved = appended && (this.isUnmasking || flags.input || flags.raw) && (!flags.raw || !appendEager) && !flags.tail;
1762
+ const details = new ChangeDetails({
1763
+ inserted: this.char,
1764
+ rawInserted: isResolved ? this.char : ''
1765
+ });
1766
+ this._value = this.char;
1767
+ this._isRawInput = isResolved && (flags.raw || flags.input);
1768
+ return details;
1769
+ }
1770
+ _appendEager() {
1771
+ return this._appendChar(this.char, {
1772
+ tail: true
1773
+ });
1774
+ }
1775
+ _appendPlaceholder() {
1776
+ const details = new ChangeDetails();
1777
+ if (this.isFilled) return details;
1778
+ this._value = details.inserted = this.char;
1779
+ return details;
1780
+ }
1781
+ extractTail() {
1782
+ return new ContinuousTailDetails('');
1783
+ }
1784
+ appendTail(tail) {
1785
+ if (isString(tail)) tail = new ContinuousTailDetails(String(tail));
1786
+ return tail.appendTo(this);
1787
+ }
1788
+ append(str, flags, tail) {
1789
+ const details = this._appendChar(str[0], flags);
1790
+ if (tail != null) {
1791
+ details.tailShift += this.appendTail(tail).tailShift;
1792
+ }
1793
+ return details;
1794
+ }
1795
+ doCommit() {}
1796
+ get state() {
1797
+ return {
1798
+ _value: this._value,
1799
+ _rawInputValue: this.rawInputValue
1800
+ };
1801
+ }
1802
+ set state(state) {
1803
+ this._value = state._value;
1804
+ this._isRawInput = Boolean(state._rawInputValue);
1805
+ }
1806
+ pad(flags) {
1807
+ return this._appendPlaceholder();
1808
+ }
1809
+ }
1810
+
1811
+ class PatternInputDefinition {
1812
+ /** */
1813
+
1814
+ /** */
1815
+
1816
+ /** */
1817
+
1818
+ /** */
1819
+
1820
+ /** */
1821
+
1822
+ /** */
1823
+
1824
+ /** */
1825
+
1826
+ /** */
1827
+
1828
+ constructor(opts) {
1829
+ const {
1830
+ parent,
1831
+ isOptional,
1832
+ placeholderChar,
1833
+ displayChar,
1834
+ lazy,
1835
+ eager,
1836
+ ...maskOpts
1837
+ } = opts;
1838
+ this.masked = createMask(maskOpts);
1839
+ Object.assign(this, {
1840
+ parent,
1841
+ isOptional,
1842
+ placeholderChar,
1843
+ displayChar,
1844
+ lazy,
1845
+ eager
1846
+ });
1847
+ }
1848
+ reset() {
1849
+ this.isFilled = false;
1850
+ this.masked.reset();
1851
+ }
1852
+ remove(fromPos, toPos) {
1853
+ if (fromPos === void 0) {
1854
+ fromPos = 0;
1855
+ }
1856
+ if (toPos === void 0) {
1857
+ toPos = this.value.length;
1858
+ }
1859
+ if (fromPos === 0 && toPos >= 1) {
1860
+ this.isFilled = false;
1861
+ return this.masked.remove(fromPos, toPos);
1862
+ }
1863
+ return new ChangeDetails();
1864
+ }
1865
+ get value() {
1866
+ return this.masked.value || (this.isFilled && !this.isOptional ? this.placeholderChar : '');
1867
+ }
1868
+ get unmaskedValue() {
1869
+ return this.masked.unmaskedValue;
1870
+ }
1871
+ get rawInputValue() {
1872
+ return this.masked.rawInputValue;
1873
+ }
1874
+ get displayValue() {
1875
+ return this.masked.value && this.displayChar || this.value;
1876
+ }
1877
+ get isComplete() {
1878
+ return Boolean(this.masked.value) || this.isOptional;
1879
+ }
1880
+ _appendChar(ch, flags) {
1881
+ if (flags === void 0) {
1882
+ flags = {};
1883
+ }
1884
+ if (this.isFilled) return new ChangeDetails();
1885
+ const state = this.masked.state;
1886
+ // simulate input
1887
+ let details = this.masked._appendChar(ch, this.currentMaskFlags(flags));
1888
+ if (details.inserted && this.doValidate(flags) === false) {
1889
+ details = new ChangeDetails();
1890
+ this.masked.state = state;
1891
+ }
1892
+ if (!details.inserted && !this.isOptional && !this.lazy && !flags.input) {
1893
+ details.inserted = this.placeholderChar;
1894
+ }
1895
+ details.skip = !details.inserted && !this.isOptional;
1896
+ this.isFilled = Boolean(details.inserted);
1897
+ return details;
1898
+ }
1899
+ append(str, flags, tail) {
1900
+ // TODO probably should be done via _appendChar
1901
+ return this.masked.append(str, this.currentMaskFlags(flags), tail);
1902
+ }
1903
+ _appendPlaceholder() {
1904
+ if (this.isFilled || this.isOptional) return new ChangeDetails();
1905
+ this.isFilled = true;
1906
+ return new ChangeDetails({
1907
+ inserted: this.placeholderChar
1908
+ });
1909
+ }
1910
+ _appendEager() {
1911
+ return new ChangeDetails();
1912
+ }
1913
+ extractTail(fromPos, toPos) {
1914
+ return this.masked.extractTail(fromPos, toPos);
1915
+ }
1916
+ appendTail(tail) {
1917
+ return this.masked.appendTail(tail);
1918
+ }
1919
+ extractInput(fromPos, toPos, flags) {
1920
+ if (fromPos === void 0) {
1921
+ fromPos = 0;
1922
+ }
1923
+ if (toPos === void 0) {
1924
+ toPos = this.value.length;
1925
+ }
1926
+ return this.masked.extractInput(fromPos, toPos, flags);
1927
+ }
1928
+ nearestInputPos(cursorPos, direction) {
1929
+ if (direction === void 0) {
1930
+ direction = DIRECTION.NONE;
1931
+ }
1932
+ const minPos = 0;
1933
+ const maxPos = this.value.length;
1934
+ const boundPos = Math.min(Math.max(cursorPos, minPos), maxPos);
1935
+ switch (direction) {
1936
+ case DIRECTION.LEFT:
1937
+ case DIRECTION.FORCE_LEFT:
1938
+ return this.isComplete ? boundPos : minPos;
1939
+ case DIRECTION.RIGHT:
1940
+ case DIRECTION.FORCE_RIGHT:
1941
+ return this.isComplete ? boundPos : maxPos;
1942
+ case DIRECTION.NONE:
1943
+ default:
1944
+ return boundPos;
1945
+ }
1946
+ }
1947
+ totalInputPositions(fromPos, toPos) {
1948
+ if (fromPos === void 0) {
1949
+ fromPos = 0;
1950
+ }
1951
+ if (toPos === void 0) {
1952
+ toPos = this.value.length;
1953
+ }
1954
+ return this.value.slice(fromPos, toPos).length;
1955
+ }
1956
+ doValidate(flags) {
1957
+ return this.masked.doValidate(this.currentMaskFlags(flags)) && (!this.parent || this.parent.doValidate(this.currentMaskFlags(flags)));
1958
+ }
1959
+ doCommit() {
1960
+ this.masked.doCommit();
1961
+ }
1962
+ get state() {
1963
+ return {
1964
+ _value: this.value,
1965
+ _rawInputValue: this.rawInputValue,
1966
+ masked: this.masked.state,
1967
+ isFilled: this.isFilled
1968
+ };
1969
+ }
1970
+ set state(state) {
1971
+ this.masked.state = state.masked;
1972
+ this.isFilled = state.isFilled;
1973
+ }
1974
+ currentMaskFlags(flags) {
1975
+ var _flags$_beforeTailSta;
1976
+ return {
1977
+ ...flags,
1978
+ _beforeTailState: (flags == null || (_flags$_beforeTailSta = flags._beforeTailState) == null ? void 0 : _flags$_beforeTailSta.masked) || (flags == null ? void 0 : flags._beforeTailState)
1979
+ };
1980
+ }
1981
+ pad(flags) {
1982
+ return new ChangeDetails();
1983
+ }
1984
+ }
1985
+ PatternInputDefinition.DEFAULT_DEFINITIONS = {
1986
+ '0': /\d/,
1987
+ '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]/,
1988
+ // http://stackoverflow.com/a/22075070
1989
+ '*': /./
1990
+ };
1991
+
1992
+ /** Masking by RegExp */
1993
+ class MaskedRegExp extends Masked {
1994
+ /** */
1995
+
1996
+ /** Enable characters overwriting */
1997
+
1998
+ /** */
1999
+
2000
+ /** */
2001
+
2002
+ /** */
2003
+
2004
+ updateOptions(opts) {
2005
+ super.updateOptions(opts);
2006
+ }
2007
+ _update(opts) {
2008
+ const mask = opts.mask;
2009
+ if (mask) opts.validate = value => value.search(mask) >= 0;
2010
+ super._update(opts);
2011
+ }
2012
+ }
2013
+ IMask.MaskedRegExp = MaskedRegExp;
2014
+
2015
+ /** Pattern mask */
2016
+ class MaskedPattern extends Masked {
2017
+ /** */
2018
+
2019
+ /** */
2020
+
2021
+ /** Single char for empty input */
2022
+
2023
+ /** Single char for filled input */
2024
+
2025
+ /** Show placeholder only when needed */
2026
+
2027
+ /** Enable characters overwriting */
2028
+
2029
+ /** */
2030
+
2031
+ /** */
2032
+
2033
+ /** */
2034
+
2035
+ constructor(opts) {
2036
+ super({
2037
+ ...MaskedPattern.DEFAULTS,
2038
+ ...opts,
2039
+ definitions: Object.assign({}, PatternInputDefinition.DEFAULT_DEFINITIONS, opts == null ? void 0 : opts.definitions)
2040
+ });
2041
+ }
2042
+ updateOptions(opts) {
2043
+ super.updateOptions(opts);
2044
+ }
2045
+ _update(opts) {
2046
+ opts.definitions = Object.assign({}, this.definitions, opts.definitions);
2047
+ super._update(opts);
2048
+ this._rebuildMask();
2049
+ }
2050
+ _rebuildMask() {
2051
+ const defs = this.definitions;
2052
+ this._blocks = [];
2053
+ this.exposeBlock = undefined;
2054
+ this._stops = [];
2055
+ this._maskedBlocks = {};
2056
+ const pattern = this.mask;
2057
+ if (!pattern || !defs) return;
2058
+ let unmaskingBlock = false;
2059
+ let optionalBlock = false;
2060
+ for (let i = 0; i < pattern.length; ++i) {
2061
+ if (this.blocks) {
2062
+ const p = pattern.slice(i);
2063
+ const bNames = Object.keys(this.blocks).filter(bName => p.indexOf(bName) === 0);
2064
+ // order by key length
2065
+ bNames.sort((a, b) => b.length - a.length);
2066
+ // use block name with max length
2067
+ const bName = bNames[0];
2068
+ if (bName) {
2069
+ const {
2070
+ expose,
2071
+ repeat,
2072
+ ...bOpts
2073
+ } = normalizeOpts(this.blocks[bName]); // TODO type Opts<Arg & Extra>
2074
+ const blockOpts = {
2075
+ lazy: this.lazy,
2076
+ eager: this.eager,
2077
+ placeholderChar: this.placeholderChar,
2078
+ displayChar: this.displayChar,
2079
+ overwrite: this.overwrite,
2080
+ autofix: this.autofix,
2081
+ ...bOpts,
2082
+ repeat,
2083
+ parent: this
2084
+ };
2085
+ const maskedBlock = repeat != null ? new IMask.RepeatBlock(blockOpts /* TODO */) : createMask(blockOpts);
2086
+ if (maskedBlock) {
2087
+ this._blocks.push(maskedBlock);
2088
+ if (expose) this.exposeBlock = maskedBlock;
2089
+
2090
+ // store block index
2091
+ if (!this._maskedBlocks[bName]) this._maskedBlocks[bName] = [];
2092
+ this._maskedBlocks[bName].push(this._blocks.length - 1);
2093
+ }
2094
+ i += bName.length - 1;
2095
+ continue;
2096
+ }
2097
+ }
2098
+ let char = pattern[i];
2099
+ let isInput = (char in defs);
2100
+ if (char === MaskedPattern.STOP_CHAR) {
2101
+ this._stops.push(this._blocks.length);
2102
+ continue;
2103
+ }
2104
+ if (char === '{' || char === '}') {
2105
+ unmaskingBlock = !unmaskingBlock;
2106
+ continue;
2107
+ }
2108
+ if (char === '[' || char === ']') {
2109
+ optionalBlock = !optionalBlock;
2110
+ continue;
2111
+ }
2112
+ if (char === MaskedPattern.ESCAPE_CHAR) {
2113
+ ++i;
2114
+ char = pattern[i];
2115
+ if (!char) break;
2116
+ isInput = false;
2117
+ }
2118
+ const def = isInput ? new PatternInputDefinition({
2119
+ isOptional: optionalBlock,
2120
+ lazy: this.lazy,
2121
+ eager: this.eager,
2122
+ placeholderChar: this.placeholderChar,
2123
+ displayChar: this.displayChar,
2124
+ ...normalizeOpts(defs[char]),
2125
+ parent: this
2126
+ }) : new PatternFixedDefinition({
2127
+ char,
2128
+ eager: this.eager,
2129
+ isUnmasking: unmaskingBlock
2130
+ });
2131
+ this._blocks.push(def);
2132
+ }
2133
+ }
2134
+ get state() {
2135
+ return {
2136
+ ...super.state,
2137
+ _blocks: this._blocks.map(b => b.state)
2138
+ };
2139
+ }
2140
+ set state(state) {
2141
+ if (!state) {
2142
+ this.reset();
2143
+ return;
2144
+ }
2145
+ const {
2146
+ _blocks,
2147
+ ...maskedState
2148
+ } = state;
2149
+ this._blocks.forEach((b, bi) => b.state = _blocks[bi]);
2150
+ super.state = maskedState;
2151
+ }
2152
+ reset() {
2153
+ super.reset();
2154
+ this._blocks.forEach(b => b.reset());
2155
+ }
2156
+ get isComplete() {
2157
+ return this.exposeBlock ? this.exposeBlock.isComplete : this._blocks.every(b => b.isComplete);
2158
+ }
2159
+ get isFilled() {
2160
+ return this._blocks.every(b => b.isFilled);
2161
+ }
2162
+ get isFixed() {
2163
+ return this._blocks.every(b => b.isFixed);
2164
+ }
2165
+ get isOptional() {
2166
+ return this._blocks.every(b => b.isOptional);
2167
+ }
2168
+ doCommit() {
2169
+ this._blocks.forEach(b => b.doCommit());
2170
+ super.doCommit();
2171
+ }
2172
+ get unmaskedValue() {
2173
+ return this.exposeBlock ? this.exposeBlock.unmaskedValue : this._blocks.reduce((str, b) => str += b.unmaskedValue, '');
2174
+ }
2175
+ set unmaskedValue(unmaskedValue) {
2176
+ if (this.exposeBlock) {
2177
+ const tail = this.extractTail(this._blockStartPos(this._blocks.indexOf(this.exposeBlock)) + this.exposeBlock.displayValue.length);
2178
+ this.exposeBlock.unmaskedValue = unmaskedValue;
2179
+ this.appendTail(tail);
2180
+ this.doCommit();
2181
+ } else super.unmaskedValue = unmaskedValue;
2182
+ }
2183
+ get value() {
2184
+ return this.exposeBlock ? this.exposeBlock.value :
2185
+ // TODO return _value when not in change?
2186
+ this._blocks.reduce((str, b) => str += b.value, '');
2187
+ }
2188
+ set value(value) {
2189
+ if (this.exposeBlock) {
2190
+ const tail = this.extractTail(this._blockStartPos(this._blocks.indexOf(this.exposeBlock)) + this.exposeBlock.displayValue.length);
2191
+ this.exposeBlock.value = value;
2192
+ this.appendTail(tail);
2193
+ this.doCommit();
2194
+ } else super.value = value;
2195
+ }
2196
+ get typedValue() {
2197
+ return this.exposeBlock ? this.exposeBlock.typedValue : super.typedValue;
2198
+ }
2199
+ set typedValue(value) {
2200
+ if (this.exposeBlock) {
2201
+ const tail = this.extractTail(this._blockStartPos(this._blocks.indexOf(this.exposeBlock)) + this.exposeBlock.displayValue.length);
2202
+ this.exposeBlock.typedValue = value;
2203
+ this.appendTail(tail);
2204
+ this.doCommit();
2205
+ } else super.typedValue = value;
2206
+ }
2207
+ get displayValue() {
2208
+ return this._blocks.reduce((str, b) => str += b.displayValue, '');
2209
+ }
2210
+ appendTail(tail) {
2211
+ return super.appendTail(tail).aggregate(this._appendPlaceholder());
2212
+ }
2213
+ _appendEager() {
2214
+ var _this$_mapPosToBlock;
2215
+ const details = new ChangeDetails();
2216
+ let startBlockIndex = (_this$_mapPosToBlock = this._mapPosToBlock(this.displayValue.length)) == null ? void 0 : _this$_mapPosToBlock.index;
2217
+ if (startBlockIndex == null) return details;
2218
+
2219
+ // TODO test if it works for nested pattern masks
2220
+ if (this._blocks[startBlockIndex].isFilled) ++startBlockIndex;
2221
+ for (let bi = startBlockIndex; bi < this._blocks.length; ++bi) {
2222
+ const d = this._blocks[bi]._appendEager();
2223
+ if (!d.inserted) break;
2224
+ details.aggregate(d);
2225
+ }
2226
+ return details;
2227
+ }
2228
+ _appendCharRaw(ch, flags) {
2229
+ if (flags === void 0) {
2230
+ flags = {};
2231
+ }
2232
+ const blockIter = this._mapPosToBlock(this.displayValue.length);
2233
+ const details = new ChangeDetails();
2234
+ if (!blockIter) return details;
2235
+ for (let bi = blockIter.index, block; block = this._blocks[bi]; ++bi) {
2236
+ var _flags$_beforeTailSta;
2237
+ const blockDetails = block._appendChar(ch, {
2238
+ ...flags,
2239
+ _beforeTailState: (_flags$_beforeTailSta = flags._beforeTailState) == null || (_flags$_beforeTailSta = _flags$_beforeTailSta._blocks) == null ? void 0 : _flags$_beforeTailSta[bi]
2240
+ });
2241
+ details.aggregate(blockDetails);
2242
+ if (blockDetails.consumed) break; // go next char
2243
+ }
2244
+ return details;
2245
+ }
2246
+ extractTail(fromPos, toPos) {
2247
+ if (fromPos === void 0) {
2248
+ fromPos = 0;
2249
+ }
2250
+ if (toPos === void 0) {
2251
+ toPos = this.displayValue.length;
2252
+ }
2253
+ const chunkTail = new ChunksTailDetails();
2254
+ if (fromPos === toPos) return chunkTail;
2255
+ this._forEachBlocksInRange(fromPos, toPos, (b, bi, bFromPos, bToPos) => {
2256
+ const blockChunk = b.extractTail(bFromPos, bToPos);
2257
+ blockChunk.stop = this._findStopBefore(bi);
2258
+ blockChunk.from = this._blockStartPos(bi);
2259
+ if (blockChunk instanceof ChunksTailDetails) blockChunk.blockIndex = bi;
2260
+ chunkTail.extend(blockChunk);
2261
+ });
2262
+ return chunkTail;
2263
+ }
2264
+ extractInput(fromPos, toPos, flags) {
2265
+ if (fromPos === void 0) {
2266
+ fromPos = 0;
2267
+ }
2268
+ if (toPos === void 0) {
2269
+ toPos = this.displayValue.length;
2270
+ }
2271
+ if (flags === void 0) {
2272
+ flags = {};
2273
+ }
2274
+ if (fromPos === toPos) return '';
2275
+ let input = '';
2276
+ this._forEachBlocksInRange(fromPos, toPos, (b, _, fromPos, toPos) => {
2277
+ input += b.extractInput(fromPos, toPos, flags);
2278
+ });
2279
+ return input;
2280
+ }
2281
+ _findStopBefore(blockIndex) {
2282
+ let stopBefore;
2283
+ for (let si = 0; si < this._stops.length; ++si) {
2284
+ const stop = this._stops[si];
2285
+ if (stop <= blockIndex) stopBefore = stop;else break;
2286
+ }
2287
+ return stopBefore;
2288
+ }
2289
+
2290
+ /** Appends placeholder depending on laziness */
2291
+ _appendPlaceholder(toBlockIndex) {
2292
+ const details = new ChangeDetails();
2293
+ if (this.lazy && toBlockIndex == null) return details;
2294
+ const startBlockIter = this._mapPosToBlock(this.displayValue.length);
2295
+ if (!startBlockIter) return details;
2296
+ const startBlockIndex = startBlockIter.index;
2297
+ const endBlockIndex = toBlockIndex != null ? toBlockIndex : this._blocks.length;
2298
+ this._blocks.slice(startBlockIndex, endBlockIndex).forEach(b => {
2299
+ if (!b.lazy || toBlockIndex != null) {
2300
+ var _blocks2;
2301
+ details.aggregate(b._appendPlaceholder((_blocks2 = b._blocks) == null ? void 0 : _blocks2.length));
2302
+ }
2303
+ });
2304
+ return details;
2305
+ }
2306
+
2307
+ /** Finds block in pos */
2308
+ _mapPosToBlock(pos) {
2309
+ let accVal = '';
2310
+ for (let bi = 0; bi < this._blocks.length; ++bi) {
2311
+ const block = this._blocks[bi];
2312
+ const blockStartPos = accVal.length;
2313
+ accVal += block.displayValue;
2314
+ if (pos <= accVal.length) {
2315
+ return {
2316
+ index: bi,
2317
+ offset: pos - blockStartPos
2318
+ };
2319
+ }
2320
+ }
2321
+ }
2322
+ _blockStartPos(blockIndex) {
2323
+ return this._blocks.slice(0, blockIndex).reduce((pos, b) => pos += b.displayValue.length, 0);
2324
+ }
2325
+ _forEachBlocksInRange(fromPos, toPos, fn) {
2326
+ if (toPos === void 0) {
2327
+ toPos = this.displayValue.length;
2328
+ }
2329
+ const fromBlockIter = this._mapPosToBlock(fromPos);
2330
+ if (fromBlockIter) {
2331
+ const toBlockIter = this._mapPosToBlock(toPos);
2332
+ // process first block
2333
+ const isSameBlock = toBlockIter && fromBlockIter.index === toBlockIter.index;
2334
+ const fromBlockStartPos = fromBlockIter.offset;
2335
+ const fromBlockEndPos = toBlockIter && isSameBlock ? toBlockIter.offset : this._blocks[fromBlockIter.index].displayValue.length;
2336
+ fn(this._blocks[fromBlockIter.index], fromBlockIter.index, fromBlockStartPos, fromBlockEndPos);
2337
+ if (toBlockIter && !isSameBlock) {
2338
+ // process intermediate blocks
2339
+ for (let bi = fromBlockIter.index + 1; bi < toBlockIter.index; ++bi) {
2340
+ fn(this._blocks[bi], bi, 0, this._blocks[bi].displayValue.length);
2341
+ }
2342
+
2343
+ // process last block
2344
+ fn(this._blocks[toBlockIter.index], toBlockIter.index, 0, toBlockIter.offset);
2345
+ }
2346
+ }
2347
+ }
2348
+ remove(fromPos, toPos) {
2349
+ if (fromPos === void 0) {
2350
+ fromPos = 0;
2351
+ }
2352
+ if (toPos === void 0) {
2353
+ toPos = this.displayValue.length;
2354
+ }
2355
+ const removeDetails = super.remove(fromPos, toPos);
2356
+ this._forEachBlocksInRange(fromPos, toPos, (b, _, bFromPos, bToPos) => {
2357
+ removeDetails.aggregate(b.remove(bFromPos, bToPos));
2358
+ });
2359
+ return removeDetails;
2360
+ }
2361
+ nearestInputPos(cursorPos, direction) {
2362
+ if (direction === void 0) {
2363
+ direction = DIRECTION.NONE;
2364
+ }
2365
+ if (!this._blocks.length) return 0;
2366
+ const cursor = new PatternCursor(this, cursorPos);
2367
+ if (direction === DIRECTION.NONE) {
2368
+ // -------------------------------------------------
2369
+ // NONE should only go out from fixed to the right!
2370
+ // -------------------------------------------------
2371
+ if (cursor.pushRightBeforeInput()) return cursor.pos;
2372
+ cursor.popState();
2373
+ if (cursor.pushLeftBeforeInput()) return cursor.pos;
2374
+ return this.displayValue.length;
2375
+ }
2376
+
2377
+ // FORCE is only about a|* otherwise is 0
2378
+ if (direction === DIRECTION.LEFT || direction === DIRECTION.FORCE_LEFT) {
2379
+ // try to break fast when *|a
2380
+ if (direction === DIRECTION.LEFT) {
2381
+ cursor.pushRightBeforeFilled();
2382
+ if (cursor.ok && cursor.pos === cursorPos) return cursorPos;
2383
+ cursor.popState();
2384
+ }
2385
+
2386
+ // forward flow
2387
+ cursor.pushLeftBeforeInput();
2388
+ cursor.pushLeftBeforeRequired();
2389
+ cursor.pushLeftBeforeFilled();
2390
+
2391
+ // backward flow
2392
+ if (direction === DIRECTION.LEFT) {
2393
+ cursor.pushRightBeforeInput();
2394
+ cursor.pushRightBeforeRequired();
2395
+ if (cursor.ok && cursor.pos <= cursorPos) return cursor.pos;
2396
+ cursor.popState();
2397
+ if (cursor.ok && cursor.pos <= cursorPos) return cursor.pos;
2398
+ cursor.popState();
2399
+ }
2400
+ if (cursor.ok) return cursor.pos;
2401
+ if (direction === DIRECTION.FORCE_LEFT) return 0;
2402
+ cursor.popState();
2403
+ if (cursor.ok) return cursor.pos;
2404
+ cursor.popState();
2405
+ if (cursor.ok) return cursor.pos;
2406
+ return 0;
2407
+ }
2408
+ if (direction === DIRECTION.RIGHT || direction === DIRECTION.FORCE_RIGHT) {
2409
+ // forward flow
2410
+ cursor.pushRightBeforeInput();
2411
+ cursor.pushRightBeforeRequired();
2412
+ if (cursor.pushRightBeforeFilled()) return cursor.pos;
2413
+ if (direction === DIRECTION.FORCE_RIGHT) return this.displayValue.length;
2414
+
2415
+ // backward flow
2416
+ cursor.popState();
2417
+ if (cursor.ok) return cursor.pos;
2418
+ cursor.popState();
2419
+ if (cursor.ok) return cursor.pos;
2420
+ return this.nearestInputPos(cursorPos, DIRECTION.LEFT);
2421
+ }
2422
+ return cursorPos;
2423
+ }
2424
+ totalInputPositions(fromPos, toPos) {
2425
+ if (fromPos === void 0) {
2426
+ fromPos = 0;
2427
+ }
2428
+ if (toPos === void 0) {
2429
+ toPos = this.displayValue.length;
2430
+ }
2431
+ let total = 0;
2432
+ this._forEachBlocksInRange(fromPos, toPos, (b, _, bFromPos, bToPos) => {
2433
+ total += b.totalInputPositions(bFromPos, bToPos);
2434
+ });
2435
+ return total;
2436
+ }
2437
+
2438
+ /** Get block by name */
2439
+ maskedBlock(name) {
2440
+ return this.maskedBlocks(name)[0];
2441
+ }
2442
+
2443
+ /** Get all blocks by name */
2444
+ maskedBlocks(name) {
2445
+ const indices = this._maskedBlocks[name];
2446
+ if (!indices) return [];
2447
+ return indices.map(gi => this._blocks[gi]);
2448
+ }
2449
+ pad(flags) {
2450
+ const details = new ChangeDetails();
2451
+ this._forEachBlocksInRange(0, this.displayValue.length, b => details.aggregate(b.pad(flags)));
2452
+ return details;
2453
+ }
2454
+ }
2455
+ MaskedPattern.DEFAULTS = {
2456
+ ...Masked.DEFAULTS,
2457
+ lazy: true,
2458
+ placeholderChar: '_'
2459
+ };
2460
+ MaskedPattern.STOP_CHAR = '`';
2461
+ MaskedPattern.ESCAPE_CHAR = '\\';
2462
+ MaskedPattern.InputDefinition = PatternInputDefinition;
2463
+ MaskedPattern.FixedDefinition = PatternFixedDefinition;
2464
+ IMask.MaskedPattern = MaskedPattern;
2465
+
2466
+ /** Pattern which accepts ranges */
2467
+ class MaskedRange extends MaskedPattern {
2468
+ /**
2469
+ Optionally sets max length of pattern.
2470
+ Used when pattern length is longer then `to` param length. Pads zeros at start in this case.
2471
+ */
2472
+
2473
+ /** Min bound */
2474
+
2475
+ /** Max bound */
2476
+
2477
+ get _matchFrom() {
2478
+ return this.maxLength - String(this.from).length;
2479
+ }
2480
+ constructor(opts) {
2481
+ super(opts); // mask will be created in _update
2482
+ }
2483
+ updateOptions(opts) {
2484
+ super.updateOptions(opts);
2485
+ }
2486
+ _update(opts) {
2487
+ const {
2488
+ to = this.to || 0,
2489
+ from = this.from || 0,
2490
+ maxLength = this.maxLength || 0,
2491
+ autofix = this.autofix,
2492
+ ...patternOpts
2493
+ } = opts;
2494
+ this.to = to;
2495
+ this.from = from;
2496
+ this.maxLength = Math.max(String(to).length, maxLength);
2497
+ this.autofix = autofix;
2498
+ const fromStr = String(this.from).padStart(this.maxLength, '0');
2499
+ const toStr = String(this.to).padStart(this.maxLength, '0');
2500
+ let sameCharsCount = 0;
2501
+ while (sameCharsCount < toStr.length && toStr[sameCharsCount] === fromStr[sameCharsCount]) ++sameCharsCount;
2502
+ patternOpts.mask = toStr.slice(0, sameCharsCount).replace(/0/g, '\\0') + '0'.repeat(this.maxLength - sameCharsCount);
2503
+ super._update(patternOpts);
2504
+ }
2505
+ get isComplete() {
2506
+ return super.isComplete && Boolean(this.value);
2507
+ }
2508
+ boundaries(str) {
2509
+ let minstr = '';
2510
+ let maxstr = '';
2511
+ const [, placeholder, num] = str.match(/^(\D*)(\d*)(\D*)/) || [];
2512
+ if (num) {
2513
+ minstr = '0'.repeat(placeholder.length) + num;
2514
+ maxstr = '9'.repeat(placeholder.length) + num;
2515
+ }
2516
+ minstr = minstr.padEnd(this.maxLength, '0');
2517
+ maxstr = maxstr.padEnd(this.maxLength, '9');
2518
+ return [minstr, maxstr];
2519
+ }
2520
+ doPrepareChar(ch, flags) {
2521
+ if (flags === void 0) {
2522
+ flags = {};
2523
+ }
2524
+ let details;
2525
+ [ch, details] = super.doPrepareChar(ch.replace(/\D/g, ''), flags);
2526
+ if (!ch) details.skip = !this.isComplete;
2527
+ return [ch, details];
2528
+ }
2529
+ _appendCharRaw(ch, flags) {
2530
+ if (flags === void 0) {
2531
+ flags = {};
2532
+ }
2533
+ if (!this.autofix || this.value.length + 1 > this.maxLength) return super._appendCharRaw(ch, flags);
2534
+ const fromStr = String(this.from).padStart(this.maxLength, '0');
2535
+ const toStr = String(this.to).padStart(this.maxLength, '0');
2536
+ const [minstr, maxstr] = this.boundaries(this.value + ch);
2537
+ if (Number(maxstr) < this.from) return super._appendCharRaw(fromStr[this.value.length], flags);
2538
+ if (Number(minstr) > this.to) {
2539
+ if (!flags.tail && this.autofix === 'pad' && this.value.length + 1 < this.maxLength) {
2540
+ return super._appendCharRaw(fromStr[this.value.length], flags).aggregate(this._appendCharRaw(ch, flags));
2541
+ }
2542
+ return super._appendCharRaw(toStr[this.value.length], flags);
2543
+ }
2544
+ return super._appendCharRaw(ch, flags);
2545
+ }
2546
+ doValidate(flags) {
2547
+ const str = this.value;
2548
+ const firstNonZero = str.search(/[^0]/);
2549
+ if (firstNonZero === -1 && str.length <= this._matchFrom) return true;
2550
+ const [minstr, maxstr] = this.boundaries(str);
2551
+ return this.from <= Number(maxstr) && Number(minstr) <= this.to && super.doValidate(flags);
2552
+ }
2553
+ pad(flags) {
2554
+ const details = new ChangeDetails();
2555
+ if (this.value.length === this.maxLength) return details;
2556
+ const value = this.value;
2557
+ const padLength = this.maxLength - this.value.length;
2558
+ if (padLength) {
2559
+ this.reset();
2560
+ for (let i = 0; i < padLength; ++i) {
2561
+ details.aggregate(super._appendCharRaw('0', flags));
2562
+ }
2563
+
2564
+ // append tail
2565
+ value.split('').forEach(ch => this._appendCharRaw(ch));
2566
+ }
2567
+ return details;
2568
+ }
2569
+ }
2570
+ IMask.MaskedRange = MaskedRange;
2571
+
2572
+ const DefaultPattern = 'd{.}`m{.}`Y';
2573
+
2574
+ // Make format and parse required when pattern is provided
2575
+
2576
+ /** Date mask */
2577
+ class MaskedDate extends MaskedPattern {
2578
+ static extractPatternOptions(opts) {
2579
+ const {
2580
+ mask,
2581
+ pattern,
2582
+ ...patternOpts
2583
+ } = opts;
2584
+ return {
2585
+ ...patternOpts,
2586
+ mask: isString(mask) ? mask : pattern
2587
+ };
2588
+ }
2589
+
2590
+ /** Pattern mask for date according to {@link MaskedDate#format} */
2591
+
2592
+ /** Start date */
2593
+
2594
+ /** End date */
2595
+
2596
+ /** Format typed value to string */
2597
+
2598
+ /** Parse string to get typed value */
2599
+
2600
+ constructor(opts) {
2601
+ super(MaskedDate.extractPatternOptions({
2602
+ ...MaskedDate.DEFAULTS,
2603
+ ...opts
2604
+ }));
2605
+ }
2606
+ updateOptions(opts) {
2607
+ super.updateOptions(opts);
2608
+ }
2609
+ _update(opts) {
2610
+ const {
2611
+ mask,
2612
+ pattern,
2613
+ blocks,
2614
+ ...patternOpts
2615
+ } = {
2616
+ ...MaskedDate.DEFAULTS,
2617
+ ...opts
2618
+ };
2619
+ const patternBlocks = Object.assign({}, MaskedDate.GET_DEFAULT_BLOCKS());
2620
+ // adjust year block
2621
+ if (opts.min) patternBlocks.Y.from = opts.min.getFullYear();
2622
+ if (opts.max) patternBlocks.Y.to = opts.max.getFullYear();
2623
+ if (opts.min && opts.max && patternBlocks.Y.from === patternBlocks.Y.to) {
2624
+ patternBlocks.m.from = opts.min.getMonth() + 1;
2625
+ patternBlocks.m.to = opts.max.getMonth() + 1;
2626
+ if (patternBlocks.m.from === patternBlocks.m.to) {
2627
+ patternBlocks.d.from = opts.min.getDate();
2628
+ patternBlocks.d.to = opts.max.getDate();
2629
+ }
2630
+ }
2631
+ Object.assign(patternBlocks, this.blocks, blocks);
2632
+ super._update({
2633
+ ...patternOpts,
2634
+ mask: isString(mask) ? mask : pattern,
2635
+ blocks: patternBlocks
2636
+ });
2637
+ }
2638
+ doValidate(flags) {
2639
+ const date = this.date;
2640
+ return super.doValidate(flags) && (!this.isComplete || this.isDateExist(this.value) && date != null && (this.min == null || this.min <= date) && (this.max == null || date <= this.max));
2641
+ }
2642
+
2643
+ /** Checks if date is exists */
2644
+ isDateExist(str) {
2645
+ return this.format(this.parse(str, this), this).indexOf(str) >= 0;
2646
+ }
2647
+
2648
+ /** Parsed Date */
2649
+ get date() {
2650
+ return this.typedValue;
2651
+ }
2652
+ set date(date) {
2653
+ this.typedValue = date;
2654
+ }
2655
+ get typedValue() {
2656
+ return this.isComplete ? super.typedValue : null;
2657
+ }
2658
+ set typedValue(value) {
2659
+ super.typedValue = value;
2660
+ }
2661
+ maskEquals(mask) {
2662
+ return mask === Date || super.maskEquals(mask);
2663
+ }
2664
+ optionsIsChanged(opts) {
2665
+ return super.optionsIsChanged(MaskedDate.extractPatternOptions(opts));
2666
+ }
2667
+ }
2668
+ MaskedDate.GET_DEFAULT_BLOCKS = () => ({
2669
+ d: {
2670
+ mask: MaskedRange,
2671
+ from: 1,
2672
+ to: 31,
2673
+ maxLength: 2
2674
+ },
2675
+ m: {
2676
+ mask: MaskedRange,
2677
+ from: 1,
2678
+ to: 12,
2679
+ maxLength: 2
2680
+ },
2681
+ Y: {
2682
+ mask: MaskedRange,
2683
+ from: 1900,
2684
+ to: 9999
2685
+ }
2686
+ });
2687
+ MaskedDate.DEFAULTS = {
2688
+ ...MaskedPattern.DEFAULTS,
2689
+ mask: Date,
2690
+ pattern: DefaultPattern,
2691
+ format: (date, masked) => {
2692
+ if (!date) return '';
2693
+ const day = String(date.getDate()).padStart(2, '0');
2694
+ const month = String(date.getMonth() + 1).padStart(2, '0');
2695
+ const year = date.getFullYear();
2696
+ return [day, month, year].join('.');
2697
+ },
2698
+ parse: (str, masked) => {
2699
+ const [day, month, year] = str.split('.').map(Number);
2700
+ return new Date(year, month - 1, day);
2701
+ }
2702
+ };
2703
+ IMask.MaskedDate = MaskedDate;
2704
+
2705
+ /** Dynamic mask for choosing appropriate mask in run-time */
2706
+ class MaskedDynamic extends Masked {
2707
+ constructor(opts) {
2708
+ super({
2709
+ ...MaskedDynamic.DEFAULTS,
2710
+ ...opts
2711
+ });
2712
+ this.currentMask = undefined;
2713
+ }
2714
+ updateOptions(opts) {
2715
+ super.updateOptions(opts);
2716
+ }
2717
+ _update(opts) {
2718
+ super._update(opts);
2719
+ if ('mask' in opts) {
2720
+ this.exposeMask = undefined;
2721
+ // mask could be totally dynamic with only `dispatch` option
2722
+ this.compiledMasks = Array.isArray(opts.mask) ? opts.mask.map(m => {
2723
+ const {
2724
+ expose,
2725
+ ...maskOpts
2726
+ } = normalizeOpts(m);
2727
+ const masked = createMask({
2728
+ overwrite: this._overwrite,
2729
+ eager: this._eager,
2730
+ skipInvalid: this._skipInvalid,
2731
+ ...maskOpts
2732
+ });
2733
+ if (expose) this.exposeMask = masked;
2734
+ return masked;
2735
+ }) : [];
2736
+
2737
+ // this.currentMask = this.doDispatch(''); // probably not needed but lets see
2738
+ }
2739
+ }
2740
+ _appendCharRaw(ch, flags) {
2741
+ if (flags === void 0) {
2742
+ flags = {};
2743
+ }
2744
+ const details = this._applyDispatch(ch, flags);
2745
+ if (this.currentMask) {
2746
+ details.aggregate(this.currentMask._appendChar(ch, this.currentMaskFlags(flags)));
2747
+ }
2748
+ return details;
2749
+ }
2750
+ _applyDispatch(appended, flags, tail) {
2751
+ if (appended === void 0) {
2752
+ appended = '';
2753
+ }
2754
+ if (flags === void 0) {
2755
+ flags = {};
2756
+ }
2757
+ if (tail === void 0) {
2758
+ tail = '';
2759
+ }
2760
+ const prevValueBeforeTail = flags.tail && flags._beforeTailState != null ? flags._beforeTailState._value : this.value;
2761
+ const inputValue = this.rawInputValue;
2762
+ const insertValue = flags.tail && flags._beforeTailState != null ? flags._beforeTailState._rawInputValue : inputValue;
2763
+ const tailValue = inputValue.slice(insertValue.length);
2764
+ const prevMask = this.currentMask;
2765
+ const details = new ChangeDetails();
2766
+ const prevMaskState = prevMask == null ? void 0 : prevMask.state;
2767
+
2768
+ // clone flags to prevent overwriting `_beforeTailState`
2769
+ this.currentMask = this.doDispatch(appended, {
2770
+ ...flags
2771
+ }, tail);
2772
+
2773
+ // restore state after dispatch
2774
+ if (this.currentMask) {
2775
+ if (this.currentMask !== prevMask) {
2776
+ // if mask changed reapply input
2777
+ this.currentMask.reset();
2778
+ if (insertValue) {
2779
+ this.currentMask.append(insertValue, {
2780
+ raw: true
2781
+ });
2782
+ details.tailShift = this.currentMask.value.length - prevValueBeforeTail.length;
2783
+ }
2784
+ if (tailValue) {
2785
+ details.tailShift += this.currentMask.append(tailValue, {
2786
+ raw: true,
2787
+ tail: true
2788
+ }).tailShift;
2789
+ }
2790
+ } else if (prevMaskState) {
2791
+ // Dispatch can do something bad with state, so
2792
+ // restore prev mask state
2793
+ this.currentMask.state = prevMaskState;
2794
+ }
2795
+ }
2796
+ return details;
2797
+ }
2798
+ _appendPlaceholder() {
2799
+ const details = this._applyDispatch();
2800
+ if (this.currentMask) {
2801
+ details.aggregate(this.currentMask._appendPlaceholder());
2802
+ }
2803
+ return details;
2804
+ }
2805
+ _appendEager() {
2806
+ const details = this._applyDispatch();
2807
+ if (this.currentMask) {
2808
+ details.aggregate(this.currentMask._appendEager());
2809
+ }
2810
+ return details;
2811
+ }
2812
+ appendTail(tail) {
2813
+ const details = new ChangeDetails();
2814
+ if (tail) details.aggregate(this._applyDispatch('', {}, tail));
2815
+ return details.aggregate(this.currentMask ? this.currentMask.appendTail(tail) : super.appendTail(tail));
2816
+ }
2817
+ currentMaskFlags(flags) {
2818
+ var _flags$_beforeTailSta, _flags$_beforeTailSta2;
2819
+ return {
2820
+ ...flags,
2821
+ _beforeTailState: ((_flags$_beforeTailSta = flags._beforeTailState) == null ? void 0 : _flags$_beforeTailSta.currentMaskRef) === this.currentMask && ((_flags$_beforeTailSta2 = flags._beforeTailState) == null ? void 0 : _flags$_beforeTailSta2.currentMask) || flags._beforeTailState
2822
+ };
2823
+ }
2824
+ doDispatch(appended, flags, tail) {
2825
+ if (flags === void 0) {
2826
+ flags = {};
2827
+ }
2828
+ if (tail === void 0) {
2829
+ tail = '';
2830
+ }
2831
+ return this.dispatch(appended, this, flags, tail);
2832
+ }
2833
+ doValidate(flags) {
2834
+ return super.doValidate(flags) && (!this.currentMask || this.currentMask.doValidate(this.currentMaskFlags(flags)));
2835
+ }
2836
+ doPrepare(str, flags) {
2837
+ if (flags === void 0) {
2838
+ flags = {};
2839
+ }
2840
+ let [s, details] = super.doPrepare(str, flags);
2841
+ if (this.currentMask) {
2842
+ let currentDetails;
2843
+ [s, currentDetails] = super.doPrepare(s, this.currentMaskFlags(flags));
2844
+ details = details.aggregate(currentDetails);
2845
+ }
2846
+ return [s, details];
2847
+ }
2848
+ doPrepareChar(str, flags) {
2849
+ if (flags === void 0) {
2850
+ flags = {};
2851
+ }
2852
+ let [s, details] = super.doPrepareChar(str, flags);
2853
+ if (this.currentMask) {
2854
+ let currentDetails;
2855
+ [s, currentDetails] = super.doPrepareChar(s, this.currentMaskFlags(flags));
2856
+ details = details.aggregate(currentDetails);
2857
+ }
2858
+ return [s, details];
2859
+ }
2860
+ reset() {
2861
+ var _this$currentMask;
2862
+ (_this$currentMask = this.currentMask) == null || _this$currentMask.reset();
2863
+ this.compiledMasks.forEach(m => m.reset());
2864
+ }
2865
+ get value() {
2866
+ return this.exposeMask ? this.exposeMask.value : this.currentMask ? this.currentMask.value : '';
2867
+ }
2868
+ set value(value) {
2869
+ if (this.exposeMask) {
2870
+ this.exposeMask.value = value;
2871
+ this.currentMask = this.exposeMask;
2872
+ this._applyDispatch();
2873
+ } else super.value = value;
2874
+ }
2875
+ get unmaskedValue() {
2876
+ return this.exposeMask ? this.exposeMask.unmaskedValue : this.currentMask ? this.currentMask.unmaskedValue : '';
2877
+ }
2878
+ set unmaskedValue(unmaskedValue) {
2879
+ if (this.exposeMask) {
2880
+ this.exposeMask.unmaskedValue = unmaskedValue;
2881
+ this.currentMask = this.exposeMask;
2882
+ this._applyDispatch();
2883
+ } else super.unmaskedValue = unmaskedValue;
2884
+ }
2885
+ get typedValue() {
2886
+ return this.exposeMask ? this.exposeMask.typedValue : this.currentMask ? this.currentMask.typedValue : '';
2887
+ }
2888
+ set typedValue(typedValue) {
2889
+ if (this.exposeMask) {
2890
+ this.exposeMask.typedValue = typedValue;
2891
+ this.currentMask = this.exposeMask;
2892
+ this._applyDispatch();
2893
+ return;
2894
+ }
2895
+ let unmaskedValue = String(typedValue);
2896
+
2897
+ // double check it
2898
+ if (this.currentMask) {
2899
+ this.currentMask.typedValue = typedValue;
2900
+ unmaskedValue = this.currentMask.unmaskedValue;
2901
+ }
2902
+ this.unmaskedValue = unmaskedValue;
2903
+ }
2904
+ get displayValue() {
2905
+ return this.currentMask ? this.currentMask.displayValue : '';
2906
+ }
2907
+ get isComplete() {
2908
+ var _this$currentMask2;
2909
+ return Boolean((_this$currentMask2 = this.currentMask) == null ? void 0 : _this$currentMask2.isComplete);
2910
+ }
2911
+ get isFilled() {
2912
+ var _this$currentMask3;
2913
+ return Boolean((_this$currentMask3 = this.currentMask) == null ? void 0 : _this$currentMask3.isFilled);
2914
+ }
2915
+ remove(fromPos, toPos) {
2916
+ const details = new ChangeDetails();
2917
+ if (this.currentMask) {
2918
+ details.aggregate(this.currentMask.remove(fromPos, toPos))
2919
+ // update with dispatch
2920
+ .aggregate(this._applyDispatch());
2921
+ }
2922
+ return details;
2923
+ }
2924
+ get state() {
2925
+ var _this$currentMask4;
2926
+ return {
2927
+ ...super.state,
2928
+ _rawInputValue: this.rawInputValue,
2929
+ compiledMasks: this.compiledMasks.map(m => m.state),
2930
+ currentMaskRef: this.currentMask,
2931
+ currentMask: (_this$currentMask4 = this.currentMask) == null ? void 0 : _this$currentMask4.state
2932
+ };
2933
+ }
2934
+ set state(state) {
2935
+ const {
2936
+ compiledMasks,
2937
+ currentMaskRef,
2938
+ currentMask,
2939
+ ...maskedState
2940
+ } = state;
2941
+ if (compiledMasks) this.compiledMasks.forEach((m, mi) => m.state = compiledMasks[mi]);
2942
+ if (currentMaskRef != null) {
2943
+ this.currentMask = currentMaskRef;
2944
+ this.currentMask.state = currentMask;
2945
+ }
2946
+ super.state = maskedState;
2947
+ }
2948
+ extractInput(fromPos, toPos, flags) {
2949
+ return this.currentMask ? this.currentMask.extractInput(fromPos, toPos, flags) : '';
2950
+ }
2951
+ extractTail(fromPos, toPos) {
2952
+ return this.currentMask ? this.currentMask.extractTail(fromPos, toPos) : super.extractTail(fromPos, toPos);
2953
+ }
2954
+ doCommit() {
2955
+ if (this.currentMask) this.currentMask.doCommit();
2956
+ super.doCommit();
2957
+ }
2958
+ nearestInputPos(cursorPos, direction) {
2959
+ return this.currentMask ? this.currentMask.nearestInputPos(cursorPos, direction) : super.nearestInputPos(cursorPos, direction);
2960
+ }
2961
+ get overwrite() {
2962
+ return this.currentMask ? this.currentMask.overwrite : this._overwrite;
2963
+ }
2964
+ set overwrite(overwrite) {
2965
+ this._overwrite = overwrite;
2966
+ }
2967
+ get eager() {
2968
+ return this.currentMask ? this.currentMask.eager : this._eager;
2969
+ }
2970
+ set eager(eager) {
2971
+ this._eager = eager;
2972
+ }
2973
+ get skipInvalid() {
2974
+ return this.currentMask ? this.currentMask.skipInvalid : this._skipInvalid;
2975
+ }
2976
+ set skipInvalid(skipInvalid) {
2977
+ this._skipInvalid = skipInvalid;
2978
+ }
2979
+ get autofix() {
2980
+ return this.currentMask ? this.currentMask.autofix : this._autofix;
2981
+ }
2982
+ set autofix(autofix) {
2983
+ this._autofix = autofix;
2984
+ }
2985
+ maskEquals(mask) {
2986
+ return Array.isArray(mask) ? this.compiledMasks.every((m, mi) => {
2987
+ if (!mask[mi]) return;
2988
+ const {
2989
+ mask: oldMask,
2990
+ ...restOpts
2991
+ } = mask[mi];
2992
+ return objectIncludes(m, restOpts) && m.maskEquals(oldMask);
2993
+ }) : super.maskEquals(mask);
2994
+ }
2995
+ typedValueEquals(value) {
2996
+ var _this$currentMask5;
2997
+ return Boolean((_this$currentMask5 = this.currentMask) == null ? void 0 : _this$currentMask5.typedValueEquals(value));
2998
+ }
2999
+ }
3000
+ /** Currently chosen mask */
3001
+ /** Currently chosen mask */
3002
+ /** Compliled {@link Masked} options */
3003
+ /** Chooses {@link Masked} depending on input value */
3004
+ MaskedDynamic.DEFAULTS = {
3005
+ ...Masked.DEFAULTS,
3006
+ dispatch: (appended, masked, flags, tail) => {
3007
+ if (!masked.compiledMasks.length) return;
3008
+ const inputValue = masked.rawInputValue;
3009
+
3010
+ // simulate input
3011
+ const inputs = masked.compiledMasks.map((m, index) => {
3012
+ const isCurrent = masked.currentMask === m;
3013
+ const startInputPos = isCurrent ? m.displayValue.length : m.nearestInputPos(m.displayValue.length, DIRECTION.FORCE_LEFT);
3014
+ if (m.rawInputValue !== inputValue) {
3015
+ m.reset();
3016
+ m.append(inputValue, {
3017
+ raw: true
3018
+ });
3019
+ } else if (!isCurrent) {
3020
+ m.remove(startInputPos);
3021
+ }
3022
+ m.append(appended, masked.currentMaskFlags(flags));
3023
+ m.appendTail(tail);
3024
+ return {
3025
+ index,
3026
+ weight: m.rawInputValue.length,
3027
+ totalInputPositions: m.totalInputPositions(0, Math.max(startInputPos, m.nearestInputPos(m.displayValue.length, DIRECTION.FORCE_LEFT)))
3028
+ };
3029
+ });
3030
+
3031
+ // pop masks with longer values first
3032
+ inputs.sort((i1, i2) => i2.weight - i1.weight || i2.totalInputPositions - i1.totalInputPositions);
3033
+ return masked.compiledMasks[inputs[0].index];
3034
+ }
3035
+ };
3036
+ IMask.MaskedDynamic = MaskedDynamic;
3037
+
3038
+ /** Pattern which validates enum values */
3039
+ class MaskedEnum extends MaskedPattern {
3040
+ constructor(opts) {
3041
+ super({
3042
+ ...MaskedEnum.DEFAULTS,
3043
+ ...opts
3044
+ }); // mask will be created in _update
3045
+ }
3046
+ updateOptions(opts) {
3047
+ super.updateOptions(opts);
3048
+ }
3049
+ _update(opts) {
3050
+ const {
3051
+ enum: enum_,
3052
+ ...eopts
3053
+ } = opts;
3054
+ if (enum_) {
3055
+ const lengths = enum_.map(e => e.length);
3056
+ const requiredLength = Math.min(...lengths);
3057
+ const optionalLength = Math.max(...lengths) - requiredLength;
3058
+ eopts.mask = '*'.repeat(requiredLength);
3059
+ if (optionalLength) eopts.mask += '[' + '*'.repeat(optionalLength) + ']';
3060
+ this.enum = enum_;
3061
+ }
3062
+ super._update(eopts);
3063
+ }
3064
+ _appendCharRaw(ch, flags) {
3065
+ if (flags === void 0) {
3066
+ flags = {};
3067
+ }
3068
+ const matchFrom = Math.min(this.nearestInputPos(0, DIRECTION.FORCE_RIGHT), this.value.length);
3069
+ const matches = this.enum.filter(e => this.matchValue(e, this.unmaskedValue + ch, matchFrom));
3070
+ if (matches.length) {
3071
+ if (matches.length === 1) {
3072
+ this._forEachBlocksInRange(0, this.value.length, (b, bi) => {
3073
+ const mch = matches[0][bi];
3074
+ if (bi >= this.value.length || mch === b.value) return;
3075
+ b.reset();
3076
+ b._appendChar(mch, flags);
3077
+ });
3078
+ }
3079
+ const d = super._appendCharRaw(matches[0][this.value.length], flags);
3080
+ if (matches.length === 1) {
3081
+ matches[0].slice(this.unmaskedValue.length).split('').forEach(mch => d.aggregate(super._appendCharRaw(mch)));
3082
+ }
3083
+ return d;
3084
+ }
3085
+ return new ChangeDetails({
3086
+ skip: !this.isComplete
3087
+ });
3088
+ }
3089
+ extractTail(fromPos, toPos) {
3090
+ if (fromPos === void 0) {
3091
+ fromPos = 0;
3092
+ }
3093
+ // just drop tail
3094
+ return new ContinuousTailDetails('', fromPos);
3095
+ }
3096
+ remove(fromPos, toPos) {
3097
+ if (fromPos === void 0) {
3098
+ fromPos = 0;
3099
+ }
3100
+ if (toPos === void 0) {
3101
+ toPos = this.displayValue.length;
3102
+ }
3103
+ if (fromPos === toPos) return new ChangeDetails();
3104
+ const matchFrom = Math.min(super.nearestInputPos(0, DIRECTION.FORCE_RIGHT), this.value.length);
3105
+ let pos;
3106
+ for (pos = fromPos; pos >= 0; --pos) {
3107
+ const matches = this.enum.filter(e => this.matchValue(e, this.value.slice(matchFrom, pos), matchFrom));
3108
+ if (matches.length > 1) break;
3109
+ }
3110
+ const details = super.remove(pos, toPos);
3111
+ details.tailShift += pos - fromPos;
3112
+ return details;
3113
+ }
3114
+ get isComplete() {
3115
+ return this.enum.indexOf(this.value) >= 0;
3116
+ }
3117
+ }
3118
+ /** Match enum value */
3119
+ MaskedEnum.DEFAULTS = {
3120
+ ...MaskedPattern.DEFAULTS,
3121
+ matchValue: (estr, istr, matchFrom) => estr.indexOf(istr, matchFrom) === matchFrom
3122
+ };
3123
+ IMask.MaskedEnum = MaskedEnum;
3124
+
3125
+ /** Masking by custom Function */
3126
+ class MaskedFunction extends Masked {
3127
+ /** */
3128
+
3129
+ /** Enable characters overwriting */
3130
+
3131
+ /** */
3132
+
3133
+ /** */
3134
+
3135
+ /** */
3136
+
3137
+ updateOptions(opts) {
3138
+ super.updateOptions(opts);
3139
+ }
3140
+ _update(opts) {
3141
+ super._update({
3142
+ ...opts,
3143
+ validate: opts.mask
3144
+ });
3145
+ }
3146
+ }
3147
+ IMask.MaskedFunction = MaskedFunction;
3148
+
3149
+ var _MaskedNumber;
3150
+ /** Number mask */
3151
+ class MaskedNumber extends Masked {
3152
+ /** Single char */
3153
+
3154
+ /** Single char */
3155
+
3156
+ /** Array of single chars */
3157
+
3158
+ /** */
3159
+
3160
+ /** */
3161
+
3162
+ /** Digits after point */
3163
+
3164
+ /** Flag to remove leading and trailing zeros in the end of editing */
3165
+
3166
+ /** Flag to pad trailing zeros after point in the end of editing */
3167
+
3168
+ /** Enable characters overwriting */
3169
+
3170
+ /** */
3171
+
3172
+ /** */
3173
+
3174
+ /** */
3175
+
3176
+ /** Format typed value to string */
3177
+
3178
+ /** Parse string to get typed value */
3179
+
3180
+ constructor(opts) {
3181
+ super({
3182
+ ...MaskedNumber.DEFAULTS,
3183
+ ...opts
3184
+ });
3185
+ }
3186
+ updateOptions(opts) {
3187
+ super.updateOptions(opts);
3188
+ }
3189
+ _update(opts) {
3190
+ super._update(opts);
3191
+ this._updateRegExps();
3192
+ }
3193
+ _updateRegExps() {
3194
+ const start = '^' + (this.allowNegative ? '[+|\\-]?' : '');
3195
+ const mid = '\\d*';
3196
+ const end = (this.scale ? "(" + escapeRegExp(this.radix) + "\\d{0," + this.scale + "})?" : '') + '$';
3197
+ this._numberRegExp = new RegExp(start + mid + end);
3198
+ this._mapToRadixRegExp = new RegExp("[" + this.mapToRadix.map(escapeRegExp).join('') + "]", 'g');
3199
+ this._thousandsSeparatorRegExp = new RegExp(escapeRegExp(this.thousandsSeparator), 'g');
3200
+ }
3201
+ _removeThousandsSeparators(value) {
3202
+ return value.replace(this._thousandsSeparatorRegExp, '');
3203
+ }
3204
+ _insertThousandsSeparators(value) {
3205
+ // https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript
3206
+ const parts = value.split(this.radix);
3207
+ parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, this.thousandsSeparator);
3208
+ return parts.join(this.radix);
3209
+ }
3210
+ doPrepareChar(ch, flags) {
3211
+ if (flags === void 0) {
3212
+ flags = {};
3213
+ }
3214
+ const [prepCh, details] = super.doPrepareChar(this._removeThousandsSeparators(this.scale && this.mapToRadix.length && (
3215
+ /*
3216
+ radix should be mapped when
3217
+ 1) input is done from keyboard = flags.input && flags.raw
3218
+ 2) unmasked value is set = !flags.input && !flags.raw
3219
+ and should not be mapped when
3220
+ 1) value is set = flags.input && !flags.raw
3221
+ 2) raw value is set = !flags.input && flags.raw
3222
+ */
3223
+ flags.input && flags.raw || !flags.input && !flags.raw) ? ch.replace(this._mapToRadixRegExp, this.radix) : ch), flags);
3224
+ if (ch && !prepCh) details.skip = true;
3225
+ if (prepCh && !this.allowPositive && !this.value && prepCh !== '-') details.aggregate(this._appendChar('-'));
3226
+ return [prepCh, details];
3227
+ }
3228
+ _separatorsCount(to, extendOnSeparators) {
3229
+ if (extendOnSeparators === void 0) {
3230
+ extendOnSeparators = false;
3231
+ }
3232
+ let count = 0;
3233
+ for (let pos = 0; pos < to; ++pos) {
3234
+ if (this._value.indexOf(this.thousandsSeparator, pos) === pos) {
3235
+ ++count;
3236
+ if (extendOnSeparators) to += this.thousandsSeparator.length;
3237
+ }
3238
+ }
3239
+ return count;
3240
+ }
3241
+ _separatorsCountFromSlice(slice) {
3242
+ if (slice === void 0) {
3243
+ slice = this._value;
3244
+ }
3245
+ return this._separatorsCount(this._removeThousandsSeparators(slice).length, true);
3246
+ }
3247
+ extractInput(fromPos, toPos, flags) {
3248
+ if (fromPos === void 0) {
3249
+ fromPos = 0;
3250
+ }
3251
+ if (toPos === void 0) {
3252
+ toPos = this.displayValue.length;
3253
+ }
3254
+ [fromPos, toPos] = this._adjustRangeWithSeparators(fromPos, toPos);
3255
+ return this._removeThousandsSeparators(super.extractInput(fromPos, toPos, flags));
3256
+ }
3257
+ _appendCharRaw(ch, flags) {
3258
+ if (flags === void 0) {
3259
+ flags = {};
3260
+ }
3261
+ const prevBeforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value;
3262
+ const prevBeforeTailSeparatorsCount = this._separatorsCountFromSlice(prevBeforeTailValue);
3263
+ this._value = this._removeThousandsSeparators(this.value);
3264
+ const oldValue = this._value;
3265
+ this._value += ch;
3266
+ const num = this.number;
3267
+ let accepted = !isNaN(num);
3268
+ let skip = false;
3269
+ if (accepted) {
3270
+ let fixedNum;
3271
+ if (this.min != null && this.min < 0 && this.number < this.min) fixedNum = this.min;
3272
+ if (this.max != null && this.max > 0 && this.number > this.max) fixedNum = this.max;
3273
+ if (fixedNum != null) {
3274
+ if (this.autofix) {
3275
+ this._value = this.format(fixedNum, this).replace(MaskedNumber.UNMASKED_RADIX, this.radix);
3276
+ skip || (skip = oldValue === this._value && !flags.tail); // if not changed on tail it's still ok to proceed
3277
+ } else {
3278
+ accepted = false;
3279
+ }
3280
+ }
3281
+ accepted && (accepted = Boolean(this._value.match(this._numberRegExp)));
3282
+ }
3283
+ let appendDetails;
3284
+ if (!accepted) {
3285
+ this._value = oldValue;
3286
+ appendDetails = new ChangeDetails();
3287
+ } else {
3288
+ appendDetails = new ChangeDetails({
3289
+ inserted: this._value.slice(oldValue.length),
3290
+ rawInserted: skip ? '' : ch,
3291
+ skip
3292
+ });
3293
+ }
3294
+ this._value = this._insertThousandsSeparators(this._value);
3295
+ const beforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value;
3296
+ const beforeTailSeparatorsCount = this._separatorsCountFromSlice(beforeTailValue);
3297
+ appendDetails.tailShift += (beforeTailSeparatorsCount - prevBeforeTailSeparatorsCount) * this.thousandsSeparator.length;
3298
+ return appendDetails;
3299
+ }
3300
+ _findSeparatorAround(pos) {
3301
+ if (this.thousandsSeparator) {
3302
+ const searchFrom = pos - this.thousandsSeparator.length + 1;
3303
+ const separatorPos = this.value.indexOf(this.thousandsSeparator, searchFrom);
3304
+ if (separatorPos <= pos) return separatorPos;
3305
+ }
3306
+ return -1;
3307
+ }
3308
+ _adjustRangeWithSeparators(from, to) {
3309
+ const separatorAroundFromPos = this._findSeparatorAround(from);
3310
+ if (separatorAroundFromPos >= 0) from = separatorAroundFromPos;
3311
+ const separatorAroundToPos = this._findSeparatorAround(to);
3312
+ if (separatorAroundToPos >= 0) to = separatorAroundToPos + this.thousandsSeparator.length;
3313
+ return [from, to];
3314
+ }
3315
+ remove(fromPos, toPos) {
3316
+ if (fromPos === void 0) {
3317
+ fromPos = 0;
3318
+ }
3319
+ if (toPos === void 0) {
3320
+ toPos = this.displayValue.length;
3321
+ }
3322
+ [fromPos, toPos] = this._adjustRangeWithSeparators(fromPos, toPos);
3323
+ const valueBeforePos = this.value.slice(0, fromPos);
3324
+ const valueAfterPos = this.value.slice(toPos);
3325
+ const prevBeforeTailSeparatorsCount = this._separatorsCount(valueBeforePos.length);
3326
+ this._value = this._insertThousandsSeparators(this._removeThousandsSeparators(valueBeforePos + valueAfterPos));
3327
+ const beforeTailSeparatorsCount = this._separatorsCountFromSlice(valueBeforePos);
3328
+ return new ChangeDetails({
3329
+ tailShift: (beforeTailSeparatorsCount - prevBeforeTailSeparatorsCount) * this.thousandsSeparator.length
3330
+ });
3331
+ }
3332
+ nearestInputPos(cursorPos, direction) {
3333
+ if (!this.thousandsSeparator) return cursorPos;
3334
+ switch (direction) {
3335
+ case DIRECTION.NONE:
3336
+ case DIRECTION.LEFT:
3337
+ case DIRECTION.FORCE_LEFT:
3338
+ {
3339
+ const separatorAtLeftPos = this._findSeparatorAround(cursorPos - 1);
3340
+ if (separatorAtLeftPos >= 0) {
3341
+ const separatorAtLeftEndPos = separatorAtLeftPos + this.thousandsSeparator.length;
3342
+ if (cursorPos < separatorAtLeftEndPos || this.value.length <= separatorAtLeftEndPos || direction === DIRECTION.FORCE_LEFT) {
3343
+ return separatorAtLeftPos;
3344
+ }
3345
+ }
3346
+ break;
3347
+ }
3348
+ case DIRECTION.RIGHT:
3349
+ case DIRECTION.FORCE_RIGHT:
3350
+ {
3351
+ const separatorAtRightPos = this._findSeparatorAround(cursorPos);
3352
+ if (separatorAtRightPos >= 0) {
3353
+ return separatorAtRightPos + this.thousandsSeparator.length;
3354
+ }
3355
+ }
3356
+ }
3357
+ return cursorPos;
3358
+ }
3359
+ doCommit() {
3360
+ if (this.value) {
3361
+ const number = this.number;
3362
+ let validnum = number;
3363
+
3364
+ // check bounds
3365
+ if (this.min != null) validnum = Math.max(validnum, this.min);
3366
+ if (this.max != null) validnum = Math.min(validnum, this.max);
3367
+ if (validnum !== number) this.unmaskedValue = this.format(validnum, this);
3368
+ let formatted = this.value;
3369
+ if (this.normalizeZeros) formatted = this._normalizeZeros(formatted);
3370
+ if (this.padFractionalZeros && this.scale > 0) formatted = this._padFractionalZeros(formatted);
3371
+ this._value = formatted;
3372
+ }
3373
+ super.doCommit();
3374
+ }
3375
+ _normalizeZeros(value) {
3376
+ const parts = this._removeThousandsSeparators(value).split(this.radix);
3377
+
3378
+ // remove leading zeros
3379
+ parts[0] = parts[0].replace(/^(\D*)(0*)(\d*)/, (match, sign, zeros, num) => sign + num);
3380
+ // add leading zero
3381
+ if (value.length && !/\d$/.test(parts[0])) parts[0] = parts[0] + '0';
3382
+ if (parts.length > 1) {
3383
+ parts[1] = parts[1].replace(/0*$/, ''); // remove trailing zeros
3384
+ if (!parts[1].length) parts.length = 1; // remove fractional
3385
+ }
3386
+ return this._insertThousandsSeparators(parts.join(this.radix));
3387
+ }
3388
+ _padFractionalZeros(value) {
3389
+ if (!value) return value;
3390
+ const parts = value.split(this.radix);
3391
+ if (parts.length < 2) parts.push('');
3392
+ parts[1] = parts[1].padEnd(this.scale, '0');
3393
+ return parts.join(this.radix);
3394
+ }
3395
+ doSkipInvalid(ch, flags, checkTail) {
3396
+ if (flags === void 0) {
3397
+ flags = {};
3398
+ }
3399
+ const dropFractional = this.scale === 0 && ch !== this.thousandsSeparator && (ch === this.radix || ch === MaskedNumber.UNMASKED_RADIX || this.mapToRadix.includes(ch));
3400
+ return super.doSkipInvalid(ch, flags, checkTail) && !dropFractional;
3401
+ }
3402
+ get unmaskedValue() {
3403
+ return this._removeThousandsSeparators(this._normalizeZeros(this.value)).replace(this.radix, MaskedNumber.UNMASKED_RADIX);
3404
+ }
3405
+ set unmaskedValue(unmaskedValue) {
3406
+ super.unmaskedValue = unmaskedValue;
3407
+ }
3408
+ get typedValue() {
3409
+ return this.parse(this.unmaskedValue, this);
3410
+ }
3411
+ set typedValue(n) {
3412
+ this.rawInputValue = this.format(n, this).replace(MaskedNumber.UNMASKED_RADIX, this.radix);
3413
+ }
3414
+
3415
+ /** Parsed Number */
3416
+ get number() {
3417
+ return this.typedValue;
3418
+ }
3419
+ set number(number) {
3420
+ this.typedValue = number;
3421
+ }
3422
+ get allowNegative() {
3423
+ return this.min != null && this.min < 0 || this.max != null && this.max < 0;
3424
+ }
3425
+ get allowPositive() {
3426
+ return this.min != null && this.min > 0 || this.max != null && this.max > 0;
3427
+ }
3428
+ typedValueEquals(value) {
3429
+ // handle 0 -> '' case (typed = 0 even if value = '')
3430
+ // for details see https://github.com/uNmAnNeR/imaskjs/issues/134
3431
+ return (super.typedValueEquals(value) || MaskedNumber.EMPTY_VALUES.includes(value) && MaskedNumber.EMPTY_VALUES.includes(this.typedValue)) && !(value === 0 && this.value === '');
3432
+ }
3433
+ }
3434
+ _MaskedNumber = MaskedNumber;
3435
+ MaskedNumber.UNMASKED_RADIX = '.';
3436
+ MaskedNumber.EMPTY_VALUES = [...Masked.EMPTY_VALUES, 0];
3437
+ MaskedNumber.DEFAULTS = {
3438
+ ...Masked.DEFAULTS,
3439
+ mask: Number,
3440
+ radix: ',',
3441
+ thousandsSeparator: '',
3442
+ mapToRadix: [_MaskedNumber.UNMASKED_RADIX],
3443
+ min: Number.MIN_SAFE_INTEGER,
3444
+ max: Number.MAX_SAFE_INTEGER,
3445
+ scale: 2,
3446
+ normalizeZeros: true,
3447
+ padFractionalZeros: false,
3448
+ parse: Number,
3449
+ format: n => n.toLocaleString('en-US', {
3450
+ useGrouping: false,
3451
+ maximumFractionDigits: 20
3452
+ })
3453
+ };
3454
+ IMask.MaskedNumber = MaskedNumber;
3455
+
3456
+ /** Mask pipe source and destination types */
3457
+ const PIPE_TYPE = {
3458
+ MASKED: 'value',
3459
+ UNMASKED: 'unmaskedValue',
3460
+ TYPED: 'typedValue'
3461
+ };
3462
+ /** Creates new pipe function depending on mask type, source and destination options */
3463
+ function createPipe(arg, from, to) {
3464
+ if (from === void 0) {
3465
+ from = PIPE_TYPE.MASKED;
3466
+ }
3467
+ if (to === void 0) {
3468
+ to = PIPE_TYPE.MASKED;
3469
+ }
3470
+ const masked = createMask(arg);
3471
+ return value => masked.runIsolated(m => {
3472
+ m[from] = value;
3473
+ return m[to];
3474
+ });
3475
+ }
3476
+
3477
+ /** Pipes value through mask depending on mask type, source and destination options */
3478
+ function pipe(value, mask, from, to) {
3479
+ return createPipe(mask, from, to)(value);
3480
+ }
3481
+ IMask.PIPE_TYPE = PIPE_TYPE;
3482
+ IMask.createPipe = createPipe;
3483
+ IMask.pipe = pipe;
3484
+
3485
+ /** Pattern mask */
3486
+ class RepeatBlock extends MaskedPattern {
3487
+ get repeatFrom() {
3488
+ var _ref;
3489
+ return (_ref = Array.isArray(this.repeat) ? this.repeat[0] : this.repeat === Infinity ? 0 : this.repeat) != null ? _ref : 0;
3490
+ }
3491
+ get repeatTo() {
3492
+ var _ref2;
3493
+ return (_ref2 = Array.isArray(this.repeat) ? this.repeat[1] : this.repeat) != null ? _ref2 : Infinity;
3494
+ }
3495
+ constructor(opts) {
3496
+ super(opts);
3497
+ }
3498
+ updateOptions(opts) {
3499
+ super.updateOptions(opts);
3500
+ }
3501
+ _update(opts) {
3502
+ var _ref3, _ref4, _this$_blocks;
3503
+ const {
3504
+ repeat,
3505
+ ...blockOpts
3506
+ } = normalizeOpts(opts); // TODO type
3507
+ this._blockOpts = Object.assign({}, this._blockOpts, blockOpts);
3508
+ const block = createMask(this._blockOpts);
3509
+ this.repeat = (_ref3 = (_ref4 = repeat != null ? repeat : block.repeat) != null ? _ref4 : this.repeat) != null ? _ref3 : Infinity; // TODO type
3510
+
3511
+ super._update({
3512
+ mask: 'm'.repeat(Math.max(this.repeatTo === Infinity && ((_this$_blocks = this._blocks) == null ? void 0 : _this$_blocks.length) || 0, this.repeatFrom)),
3513
+ blocks: {
3514
+ m: block
3515
+ },
3516
+ eager: block.eager,
3517
+ overwrite: block.overwrite,
3518
+ skipInvalid: block.skipInvalid,
3519
+ lazy: block.lazy,
3520
+ placeholderChar: block.placeholderChar,
3521
+ displayChar: block.displayChar
3522
+ });
3523
+ }
3524
+ _allocateBlock(bi) {
3525
+ if (bi < this._blocks.length) return this._blocks[bi];
3526
+ if (this.repeatTo === Infinity || this._blocks.length < this.repeatTo) {
3527
+ this._blocks.push(createMask(this._blockOpts));
3528
+ this.mask += 'm';
3529
+ return this._blocks[this._blocks.length - 1];
3530
+ }
3531
+ }
3532
+ _appendCharRaw(ch, flags) {
3533
+ if (flags === void 0) {
3534
+ flags = {};
3535
+ }
3536
+ const details = new ChangeDetails();
3537
+ for (let bi = (_this$_mapPosToBlock$ = (_this$_mapPosToBlock = this._mapPosToBlock(this.displayValue.length)) == null ? void 0 : _this$_mapPosToBlock.index) != null ? _this$_mapPosToBlock$ : Math.max(this._blocks.length - 1, 0), block, allocated;
3538
+ // try to get a block or
3539
+ // try to allocate a new block if not allocated already
3540
+ block = (_this$_blocks$bi = this._blocks[bi]) != null ? _this$_blocks$bi : allocated = !allocated && this._allocateBlock(bi); ++bi) {
3541
+ var _this$_mapPosToBlock$, _this$_mapPosToBlock, _this$_blocks$bi, _flags$_beforeTailSta;
3542
+ const blockDetails = block._appendChar(ch, {
3543
+ ...flags,
3544
+ _beforeTailState: (_flags$_beforeTailSta = flags._beforeTailState) == null || (_flags$_beforeTailSta = _flags$_beforeTailSta._blocks) == null ? void 0 : _flags$_beforeTailSta[bi]
3545
+ });
3546
+ if (blockDetails.skip && allocated) {
3547
+ // remove the last allocated block and break
3548
+ this._blocks.pop();
3549
+ this.mask = this.mask.slice(1);
3550
+ break;
3551
+ }
3552
+ details.aggregate(blockDetails);
3553
+ if (blockDetails.consumed) break; // go next char
3554
+ }
3555
+ return details;
3556
+ }
3557
+ _trimEmptyTail(fromPos, toPos) {
3558
+ var _this$_mapPosToBlock2, _this$_mapPosToBlock3;
3559
+ if (fromPos === void 0) {
3560
+ fromPos = 0;
3561
+ }
3562
+ const firstBlockIndex = Math.max(((_this$_mapPosToBlock2 = this._mapPosToBlock(fromPos)) == null ? void 0 : _this$_mapPosToBlock2.index) || 0, this.repeatFrom, 0);
3563
+ let lastBlockIndex;
3564
+ if (toPos != null) lastBlockIndex = (_this$_mapPosToBlock3 = this._mapPosToBlock(toPos)) == null ? void 0 : _this$_mapPosToBlock3.index;
3565
+ if (lastBlockIndex == null) lastBlockIndex = this._blocks.length - 1;
3566
+ let removeCount = 0;
3567
+ for (let blockIndex = lastBlockIndex; firstBlockIndex <= blockIndex; --blockIndex, ++removeCount) {
3568
+ if (this._blocks[blockIndex].unmaskedValue) break;
3569
+ }
3570
+ if (removeCount) {
3571
+ this._blocks.splice(lastBlockIndex - removeCount + 1, removeCount);
3572
+ this.mask = this.mask.slice(removeCount);
3573
+ }
3574
+ }
3575
+ reset() {
3576
+ super.reset();
3577
+ this._trimEmptyTail();
3578
+ }
3579
+ remove(fromPos, toPos) {
3580
+ if (fromPos === void 0) {
3581
+ fromPos = 0;
3582
+ }
3583
+ if (toPos === void 0) {
3584
+ toPos = this.displayValue.length;
3585
+ }
3586
+ const removeDetails = super.remove(fromPos, toPos);
3587
+ this._trimEmptyTail(fromPos, toPos);
3588
+ return removeDetails;
3589
+ }
3590
+ totalInputPositions(fromPos, toPos) {
3591
+ if (fromPos === void 0) {
3592
+ fromPos = 0;
3593
+ }
3594
+ if (toPos == null && this.repeatTo === Infinity) return Infinity;
3595
+ return super.totalInputPositions(fromPos, toPos);
3596
+ }
3597
+ get state() {
3598
+ return super.state;
3599
+ }
3600
+ set state(state) {
3601
+ this._blocks.length = state._blocks.length;
3602
+ this.mask = this.mask.slice(0, this._blocks.length);
3603
+ super.state = state;
3604
+ }
3605
+ }
3606
+ IMask.RepeatBlock = RepeatBlock;
3607
+
3608
+ try {
3609
+ globalThis.IMask = IMask;
3610
+ } catch {}
3611
+
14
3612
  const verdocsKbaDialogCss = "@-webkit-keyframes verdocs-field-pulse{0%{background-color:rgba(0, 0, 0, 0.35)}50%{background-color:rgba(0, 0, 0, 0)}100%{background-color:rgba(0, 0, 0, 0.35)}}@keyframes verdocs-field-pulse{0%{background-color:rgba(0, 0, 0, 0.35)}50%{background-color:rgba(0, 0, 0, 0)}100%{background-color:rgba(0, 0, 0, 0.35)}}verdocs-kba-dialog{font-family:\"Inter\", \"Barlow\", sans-serif;-webkit-box-sizing:border-box;box-sizing:border-box}verdocs-kba-dialog div{-webkit-box-sizing:border-box;box-sizing:border-box}verdocs-kba-dialog .background-overlay{position:fixed;z-index:10000;top:0;left:0;right:0;bottom:0;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;background:rgba(0, 0, 0, 0.4980392157)}verdocs-kba-dialog .dialog{width:440px;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;border-radius:4px;overflow:hidden;background:#fff;padding:16px;gap:10px;-webkit-box-shadow:3px 3px 5px 1px rgba(40, 40, 40, 0.4);box-shadow:3px 3px 5px 1px rgba(40, 40, 40, 0.4)}verdocs-kba-dialog .heading{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;font-size:20px;font-weight:500}verdocs-kba-dialog .step{margin-left:6px;color:#666}verdocs-kba-dialog .help-box{background-color:#707ae5;display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;padding:14px;-ms-flex-align:center;align-items:center;color:white}verdocs-kba-dialog .help-details{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;margin-left:15px;font-size:14px}verdocs-kba-dialog .help-icon{width:40px;height:40px}verdocs-kba-dialog .help-title{font-weight:600;margin-bottom:4px}verdocs-kba-dialog .help-text{font-weight:400}verdocs-kba-dialog .input{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;gap:10px;-ms-flex-align:center;align-items:center;margin:16px 0 32px}verdocs-kba-dialog .input label{-ms-flex:0;flex:0;line-height:10px;font-weight:500;white-space:nowrap}verdocs-kba-dialog .input input{-ms-flex:1;flex:1;padding:5px 8px;border-radius:3px;border:1px solid #cccccc}verdocs-kba-dialog .field{gap:10px;margin:0;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-direction:row;flex-direction:row;max-width:100%}verdocs-kba-dialog .field .required{color:red;position:relative;top:-0.5em;font-size:80%}verdocs-kba-dialog .field label{-ms-flex:0 0 120px;flex:0 0 120px;font-weight:500;line-height:10px;text-align:right;white-space:nowrap}verdocs-kba-dialog .field verdocs-date-input{width:40%;-ms-flex-positive:1;flex-grow:1}verdocs-kba-dialog .field verdocs-date-input input{width:100%;-webkit-box-sizing:border-box;box-sizing:border-box}verdocs-kba-dialog .field input{width:40%;-ms-flex-positive:1;flex-grow:1;padding:5px 8px;border-radius:3px;border:1px solid #cccccc}verdocs-kba-dialog .choices{display:grid;gap:15px;grid-template-columns:repeat(auto-fill, minmax(100px, 1fr));margin:0 0 15px 0}verdocs-kba-dialog .choice{border:1px solid #707ae5;border-radius:5px;display:-ms-flexbox;display:flex;height:60px;font-size:14px;padding:0 5px;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;text-align:center;color:#5c6575;cursor:pointer}verdocs-kba-dialog .choice.selected{background-color:#707ae5;color:#ffffff}verdocs-kba-dialog .buttons{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-direction:row;flex-direction:row;-ms-flex-pack:end;justify-content:flex-end}verdocs-kba-dialog .buttons verdocs-button{margin-left:16px}";
15
3613
  const VerdocsKbaDialogStyle0 = verdocsKbaDialogCss;
16
3614
 
17
3615
  // import AirDatepicker from 'air-datepicker';
18
3616
  // import localeEn from 'air-datepicker/locale/en';
3617
+ const States = {
3618
+ AL: 'Alabama',
3619
+ AK: 'Alaska',
3620
+ AS: 'American Samoa',
3621
+ AZ: 'Arizona',
3622
+ AR: 'Arkansas',
3623
+ CA: 'California',
3624
+ CO: 'Colorado',
3625
+ CT: 'Connecticut',
3626
+ DE: 'Delaware',
3627
+ DC: 'District Of Columbia',
3628
+ FM: 'Federated States Of Micronesia',
3629
+ FL: 'Florida',
3630
+ GA: 'Georgia',
3631
+ GU: 'Guam',
3632
+ HI: 'Hawaii',
3633
+ ID: 'Idaho',
3634
+ IL: 'Illinois',
3635
+ IN: 'Indiana',
3636
+ IA: 'Iowa',
3637
+ KS: 'Kansas',
3638
+ KY: 'Kentucky',
3639
+ LA: 'Louisiana',
3640
+ ME: 'Maine',
3641
+ MH: 'Marshall Islands',
3642
+ MD: 'Maryland',
3643
+ MA: 'Massachusetts',
3644
+ MI: 'Michigan',
3645
+ MN: 'Minnesota',
3646
+ MS: 'Mississippi',
3647
+ MO: 'Missouri',
3648
+ MT: 'Montana',
3649
+ NE: 'Nebraska',
3650
+ NV: 'Nevada',
3651
+ NH: 'New Hampshire',
3652
+ NJ: 'New Jersey',
3653
+ NM: 'New Mexico',
3654
+ NY: 'New York',
3655
+ NC: 'North Carolina',
3656
+ ND: 'North Dakota',
3657
+ MP: 'Northern Mariana Islands',
3658
+ OH: 'Ohio',
3659
+ OK: 'Oklahoma',
3660
+ OR: 'Oregon',
3661
+ PW: 'Palau',
3662
+ PA: 'Pennsylvania',
3663
+ PR: 'Puerto Rico',
3664
+ RI: 'Rhode Island',
3665
+ SC: 'South Carolina',
3666
+ SD: 'South Dakota',
3667
+ TN: 'Tennessee',
3668
+ TX: 'Texas',
3669
+ UT: 'Utah',
3670
+ VT: 'Vermont',
3671
+ VI: 'Virgin Islands',
3672
+ VA: 'Virginia',
3673
+ WA: 'Washington',
3674
+ WV: 'West Virginia',
3675
+ WI: 'Wisconsin',
3676
+ WY: 'Wyoming',
3677
+ };
3678
+ const STATE_OPTIONS = Object.entries(States).map(([abbr, name]) => ({ value: abbr, label: name }));
19
3679
  const QuestionIcon = `<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M20 0C8.95313 0 0 8.95313 0 20C0 31.0469 8.95313 40 20 40C31.0469 40 40 31.0469 40 20C40 8.95313 31.0469 0 20 0ZM20 36.25C11.0391 36.25 3.75 28.9602 3.75 20C3.75 11.0398 11.0391 3.75 20 3.75C28.9609 3.75 36.25 11.0398 36.25 20C36.25 28.9602 28.9609 36.25 20 36.25Z" fill="white"/><path d="M20 26.25C18.5938 26.25 17.5 27.3438 17.5 28.75C17.5 30.1562 18.5234 31.25 20 31.25C21.3359 31.25 22.5 30.1562 22.5 28.75C22.5 27.3438 21.3359 26.25 20 26.25ZM22.5859 10H18.5938C15.5469 10 13.125 12.4219 13.125 15.4688C13.125 16.4844 13.9844 17.3438 15 17.3438C16.0156 17.3438 16.875 16.4844 16.875 15.4688C16.875 14.5312 17.5859 13.75 18.5234 13.75H22.5156C23.5234 13.75 24.375 14.5312 24.375 15.4688C24.375 16.0938 24.0625 16.5703 23.5156 16.8828L19.0625 19.6094C18.4375 20 18.125 20.625 18.125 21.25V22.5C18.125 23.5156 18.9844 24.375 20 24.375C21.0156 24.375 21.875 23.5156 21.875 22.5V22.3438L25.3984 20.1562C27.0391 19.1406 28.0547 17.3438 28.0547 15.4688C28.125 12.4219 25.7031 10 22.5859 10Z" fill="#E7E7E7"/></svg>`;
20
3680
  const VerdocsKbaDialog = class {
21
3681
  constructor(hostRef) {
@@ -67,7 +3727,32 @@ const VerdocsKbaDialog = class {
67
3727
  componentWillLoad() {
68
3728
  this.updatedRecipient = { ...(this.recipient || {}) };
69
3729
  }
70
- componentDidLoad() {
3730
+ // NOTE: This gets called again on every input, maybe do it on willUpdate?
3731
+ componentDidRender() {
3732
+ // TODO: Review min/max settings
3733
+ IMask(document.getElementById(this.dobContainerId), {
3734
+ mask: Date,
3735
+ min: new Date(1920, 0, 1),
3736
+ max: new Date(2007, 12, 31), // 18 years old
3737
+ lazy: false,
3738
+ pattern: 'm/d/Y',
3739
+ // See https://github.com/uNmAnNeR/imaskjs/issues/739
3740
+ format: function (date) {
3741
+ var day = date.getDate();
3742
+ var month = date.getMonth() + 1;
3743
+ var year = date.getFullYear();
3744
+ if (day < 10)
3745
+ day = '0' + day;
3746
+ if (month < 10)
3747
+ month = '0' + month;
3748
+ return [month, day, year].join('/');
3749
+ },
3750
+ // define str -> date convertion
3751
+ parse: function (str) {
3752
+ var yearMonthDay = str.split('/');
3753
+ return new Date(yearMonthDay[2], yearMonthDay[0] - 1, yearMonthDay[1]);
3754
+ },
3755
+ });
71
3756
  // this.picker = new AirDatepicker<HTMLElement>(`#${this.dobContainerId}`, {
72
3757
  // locale: localeEn,
73
3758
  // isMobile: true,
@@ -94,6 +3779,7 @@ const VerdocsKbaDialog = class {
94
3779
  this.response = '';
95
3780
  }
96
3781
  handleConfirmID() {
3782
+ console.log('Confirm ID', this.updatedRecipient);
97
3783
  this.next.emit(this.updatedRecipient);
98
3784
  }
99
3785
  render() {
@@ -105,7 +3791,7 @@ const VerdocsKbaDialog = class {
105
3791
  } }, choice)))), index.h("div", { class: "buttons" }, index.h("verdocs-button", { label: "Cancel", variant: "outline", onClick: () => this.handleCancel() }), index.h("verdocs-button", { label: this.step < this.steps ? 'Next' : 'Submit', onClick: () => this.handleDone(), disabled: !this.response }))))));
106
3792
  }
107
3793
  if (this.mode === 'identity') {
108
- return (index.h(index.Host, null, index.h("div", { class: "background-overlay", onClick: e => this.handleDismiss(e) }, index.h("div", { class: "dialog" }, index.h("div", { class: "heading" }, "Confirm Your Identity"), !!this.helptitle && (index.h("div", { class: "help-box" }, index.h("div", { class: "help-icon", innerHTML: QuestionIcon }), index.h("div", { class: "help-details" }, index.h("div", { class: "help-title" }, "Identity verification is required"), index.h("div", { class: "help-text" }, "NOTE: Only four fields are required, but providing more details will allow us to complete the verification process more quickly.")))), index.h("div", { class: "field" }, index.h("label", { htmlFor: "verdocs-kba-first" }, "Your Name:", index.h("span", { class: "required" }, "*")), index.h("input", { required: true, type: "text", id: "verdocs-kba-first", name: "verdocs-kba-first", placeholder: "First name...", value: (_a = this.updatedRecipient) === null || _a === void 0 ? void 0 : _a.first_name, onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, first_name: e.target.value }) }), index.h("input", { type: "text", id: "verdocs-kba-last", name: "verdocs-kba-last", placeholder: "Last name...", required: true, value: (_b = this.updatedRecipient) === null || _b === void 0 ? void 0 : _b.last_name, onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, last_name: e.target.value }) })), index.h("div", { class: "field" }, index.h("label", { htmlFor: "verdocs-kba-address" }, "Address:", index.h("span", { class: "required" }, "*")), index.h("input", { type: "text", id: "verdocs-kba-address", name: "verdocs-kba-address", placeholder: "Address...", value: (_c = this.updatedRecipient) === null || _c === void 0 ? void 0 : _c.address, onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, address: e.target.value }) })), index.h("div", { class: "field" }, index.h("label", { htmlFor: "verdocs-kba-city" }, "City:"), index.h("input", { type: "text", id: "verdocs-kba-city", name: "verdocs-kba-city", placeholder: "City...", value: (_d = this.updatedRecipient) === null || _d === void 0 ? void 0 : _d.city, onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, city: e.target.value }) })), index.h("div", { class: "field" }, index.h("label", { htmlFor: "verdocs-kba-state" }, "State:"), index.h("input", { type: "text", id: "verdocs-kba-state", name: "verdocs-kba-state", placeholder: "State...", value: (_e = this.updatedRecipient) === null || _e === void 0 ? void 0 : _e.state, onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, state: e.target.value }) })), index.h("div", { class: "field" }, index.h("label", { htmlFor: "verdocs-kba-zip" }, "Zip Code:", index.h("span", { class: "required" }, "*")), index.h("input", { type: "text", id: "verdocs-kba-zip", name: "verdocs-kba-zip", placeholder: "Zip Code...", required: true, value: (_f = this.updatedRecipient) === null || _f === void 0 ? void 0 : _f.zip, onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, zip: e.target.value }) })), index.h("div", { class: "field" }, index.h("label", { htmlFor: this.dobContainerId }, "Date of Birth:", index.h("span", { class: "required" }, "*")), index.h("input", { type: "text", value: ((_g = this.updatedRecipient) === null || _g === void 0 ? void 0 : _g.dob) || '', id: this.dobContainerId, placeholder: "DOB...", onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, dob: e.target.value }) })), index.h("div", { class: "buttons" }, index.h("verdocs-button", { label: "Submit", onClick: () => this.handleConfirmID(), disabled: !((_h = this.updatedRecipient) === null || _h === void 0 ? void 0 : _h.first_name) ||
3794
+ return (index.h(index.Host, null, index.h("div", { class: "background-overlay", onClick: e => this.handleDismiss(e) }, index.h("div", { class: "dialog" }, index.h("div", { class: "heading" }, "Confirm Your Identity"), !!this.helptitle && (index.h("div", { class: "help-box" }, index.h("div", { class: "help-icon", innerHTML: QuestionIcon }), index.h("div", { class: "help-details" }, index.h("div", { class: "help-title" }, "Identity verification is required"), index.h("div", { class: "help-text" }, "NOTE: Only four fields are required, but providing more details will allow us to complete the verification process more quickly.")))), index.h("div", { class: "field" }, index.h("label", { htmlFor: "verdocs-kba-first" }, "Your Name:", index.h("span", { class: "required" }, "*")), index.h("input", { required: true, type: "text", id: "verdocs-kba-first", name: "verdocs-kba-first", placeholder: "First name...", value: (_a = this.updatedRecipient) === null || _a === void 0 ? void 0 : _a.first_name, onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, first_name: e.target.value }) }), index.h("input", { type: "text", id: "verdocs-kba-last", name: "verdocs-kba-last", placeholder: "Last name...", required: true, value: (_b = this.updatedRecipient) === null || _b === void 0 ? void 0 : _b.last_name, onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, last_name: e.target.value }) })), index.h("div", { class: "field" }, index.h("label", { htmlFor: "verdocs-kba-address" }, "Address:", index.h("span", { class: "required" }, "*")), index.h("input", { type: "text", id: "verdocs-kba-address", name: "verdocs-kba-address", placeholder: "Address...", value: (_c = this.updatedRecipient) === null || _c === void 0 ? void 0 : _c.address, onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, address: e.target.value }) })), index.h("div", { class: "field" }, index.h("label", { htmlFor: "verdocs-kba-city" }, "City:"), index.h("input", { type: "text", id: "verdocs-kba-city", name: "verdocs-kba-city", placeholder: "City...", value: (_d = this.updatedRecipient) === null || _d === void 0 ? void 0 : _d.city, onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, city: e.target.value }) })), index.h("div", { class: "field" }, index.h("label", { htmlFor: "verdocs-kba-state" }, "State:"), index.h("verdocs-select-input", { options: STATE_OPTIONS, value: (_e = this.updatedRecipient) === null || _e === void 0 ? void 0 : _e.state, onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, state: e.target.value }) })), index.h("div", { class: "field" }, index.h("label", { htmlFor: "verdocs-kba-zip" }, "Zip Code:", index.h("span", { class: "required" }, "*")), index.h("input", { type: "text", id: "verdocs-kba-zip", name: "verdocs-kba-zip", placeholder: "Zip Code...", required: true, value: (_f = this.updatedRecipient) === null || _f === void 0 ? void 0 : _f.zip, onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, zip: e.target.value }) })), index.h("div", { class: "field" }, index.h("label", { htmlFor: this.dobContainerId }, "Date of Birth:", index.h("span", { class: "required" }, "*")), index.h("input", { type: "text", value: ((_g = this.updatedRecipient) === null || _g === void 0 ? void 0 : _g.dob) || '', id: this.dobContainerId, placeholder: "DOB...", onInput: (e) => (this.updatedRecipient = { ...this.updatedRecipient, dob: e.target.value }) })), index.h("div", { class: "buttons" }, index.h("verdocs-button", { label: "Submit", onClick: () => this.handleConfirmID(), disabled: !((_h = this.updatedRecipient) === null || _h === void 0 ? void 0 : _h.first_name) ||
109
3795
  !((_j = this.updatedRecipient) === null || _j === void 0 ? void 0 : _j.last_name) ||
110
3796
  !((_k = this.updatedRecipient) === null || _k === void 0 ? void 0 : _k.address) ||
111
3797
  !((_l = this.updatedRecipient) === null || _l === void 0 ? void 0 : _l.zip) ||